OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
92
app/Domain/Goalcanvas/Tools/CreateGoalTool.php
Normal file
92
app/Domain/Goalcanvas/Tools/CreateGoalTool.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Create a new goal.
|
||||
*/
|
||||
class CreateGoalTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->string('title')->description('The goal as an outcome statement, e.g. "Increase early-detection screenings". NOT the metric — must differ from description.')
|
||||
->required()
|
||||
->string('description')->description('The metric being tracked, e.g. "Screenings at clinic walk-ins" (shown as "What are you tracking?"). Must differ from the title.')
|
||||
->required()
|
||||
->number('startValue')->description('Starting value for the goal metric.')
|
||||
->required()
|
||||
->number('currentValue')->description('Current value of the goal metric.')
|
||||
->required()
|
||||
->number('endValue')->description('Target value for the goal metric.')
|
||||
->required()
|
||||
->integer('canvasId')->description('Canvas ID this goal belongs to.')
|
||||
->required()
|
||||
->string('startDate')->description('Start date in ISO8601 format.')
|
||||
->string('endDate')->description('End date in ISO8601 format.')
|
||||
->integer('milestoneId')->description('ID of a milestone to attach to this goal.')
|
||||
->string('metricType')->description('Type of metric (e.g., "percent", "currency", "number").')
|
||||
->string('status')->description('Status of the goal (e.g., "status_ontrack", "status_atrisk", "status_miss").');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'createGoal';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Creates a new goal with the specified details.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$values = [
|
||||
'title' => $arguments['title'],
|
||||
'description' => $arguments['description'],
|
||||
'box' => 'goal',
|
||||
'author' => session('userdata.id'),
|
||||
'canvasId' => (int) ($arguments['canvasId'] ?? 0),
|
||||
'startValue' => ($arguments['startValue'] ?? null),
|
||||
'currentValue' => ($arguments['currentValue'] ?? null),
|
||||
'endValue' => ($arguments['endValue'] ?? null),
|
||||
'metricType' => ($arguments['metricType'] ?? 'number'),
|
||||
'status' => ($arguments['status'] ?? 'status_ontrack'),
|
||||
];
|
||||
|
||||
$startDate = ($arguments['startDate'] ?? null);
|
||||
if ($startDate !== null) {
|
||||
$values['startDate'] = $startDate;
|
||||
}
|
||||
|
||||
$endDate = ($arguments['endDate'] ?? null);
|
||||
if ($endDate !== null) {
|
||||
$values['endDate'] = $endDate;
|
||||
}
|
||||
|
||||
$milestoneId = ($arguments['milestoneId'] ?? null);
|
||||
if ($milestoneId !== null) {
|
||||
$values['milestoneId'] = $milestoneId;
|
||||
}
|
||||
|
||||
$goalId = $this->goalcanvasService->createGoal($values);
|
||||
|
||||
if ($goalId) {
|
||||
return ToolResult::text("Goal created successfully with ID: {$goalId}");
|
||||
}
|
||||
|
||||
return ToolResult::error('Failed to create goal. Please check the provided information.');
|
||||
}
|
||||
}
|
||||
59
app/Domain/Goalcanvas/Tools/CreateGoalboardTool.php
Normal file
59
app/Domain/Goalcanvas/Tools/CreateGoalboardTool.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Create a new goal board.
|
||||
*/
|
||||
class CreateGoalboardTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->string('title')->description('Title of the goal board.')
|
||||
->required()
|
||||
->integer('projectId')->description('Project ID this goal board belongs to.')
|
||||
->required()
|
||||
->string('description')->description('Description of the goal board.');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'createGoalboard';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Creates a new goal board for organizing goals within a project.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$values = [
|
||||
'title' => $arguments['title'],
|
||||
'description' => ($arguments['description'] ?? ''),
|
||||
'projectId' => (int) ($arguments['projectId'] ?? 0),
|
||||
'author' => session('userdata.id'),
|
||||
];
|
||||
|
||||
$boardId = $this->goalcanvasService->createGoalboard($values);
|
||||
|
||||
if ($boardId) {
|
||||
return ToolResult::text("Goal board created successfully with ID: {$boardId}");
|
||||
}
|
||||
|
||||
return ToolResult::error('Failed to create goal board. Please check the provided information.');
|
||||
}
|
||||
}
|
||||
88
app/Domain/Goalcanvas/Tools/EditGoalTool.php
Normal file
88
app/Domain/Goalcanvas/Tools/EditGoalTool.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Core\Exceptions\AuthorizationException;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Update an existing goal.
|
||||
*/
|
||||
class EditGoalTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('id')->description('ID of the goal to update.')
|
||||
->required()
|
||||
->string('title')->description('Updated title of the goal.')
|
||||
->string('description')->description('Updated description of what the goal is measuring.')
|
||||
->number('startValue')->description('Updated starting value for the goal metric.')
|
||||
->number('currentValue')->description('Updated current value of the goal metric.')
|
||||
->number('endValue')->description('Updated target value for the goal metric.')
|
||||
->string('startDate')->description('Updated start date in ISO8601 format.')
|
||||
->string('endDate')->description('Updated end date in ISO8601 format.')
|
||||
->integer('milestoneId')->description('Updated ID of a milestone to attach to this goal.')
|
||||
->string('metricType')->description('Updated type of metric (e.g., "percent", "currency", "number").')
|
||||
->string('status')->description('Updated status of the goal (e.g., "status_ontrack", "status_atrisk", "status_miss").');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'editGoal';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Updates an existing goal with the specified details.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$id = (int) ($arguments['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
return ToolResult::error('A valid goal id is required.');
|
||||
}
|
||||
|
||||
$optionalFields = [
|
||||
'title', 'description', 'startValue', 'currentValue', 'endValue',
|
||||
'startDate', 'endDate', 'milestoneId', 'metricType', 'status',
|
||||
];
|
||||
|
||||
$params = [];
|
||||
foreach ($optionalFields as $field) {
|
||||
$value = $arguments[$field] ?? null;
|
||||
if ($value !== null) {
|
||||
$params[$field] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($params === []) {
|
||||
return ToolResult::error('Provide at least one field to update.');
|
||||
}
|
||||
|
||||
try {
|
||||
$updated = $this->goalcanvasService->patchGoalItem($id, $params);
|
||||
} catch (AuthorizationException) {
|
||||
// Unknown, foreign, or unauthorized goal id — one message for all three, so the
|
||||
// response does not leak whether a goal id exists in another project.
|
||||
return ToolResult::error("Goal with ID {$id} not found.");
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
return ToolResult::text('Goal updated successfully.');
|
||||
}
|
||||
|
||||
return ToolResult::error('Failed to update goal.');
|
||||
}
|
||||
}
|
||||
87
app/Domain/Goalcanvas/Tools/GetAllGoalsTool.php
Normal file
87
app/Domain/Goalcanvas/Tools/GetAllGoalsTool.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Get all goals for a project.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetAllGoalsTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('projectId')->description('Project ID to get goals for.')
|
||||
->required()
|
||||
->integer('boardId')->description('Specific goal board ID to filter by.');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getAllGoals';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets all goals for a specific project.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$projectId = (int) ($arguments['projectId'] ?? 0);
|
||||
$boardId = ($arguments['boardId'] ?? null);
|
||||
|
||||
$goals = $this->goalcanvasService->pollGoals($projectId, $boardId);
|
||||
|
||||
if (empty($goals)) {
|
||||
return ToolResult::text("No goals found for project ID: {$projectId}");
|
||||
}
|
||||
|
||||
// Milestone links come from the tracked_by edge model (many-to-many),
|
||||
// hydrated in ONE batched call — the legacy milestoneId column goes
|
||||
// stale after edits and misses every link beyond the first.
|
||||
$milestonesByGoal = $this->goalcanvasService->getMilestonesForGoals(
|
||||
array_map(static fn ($g) => (int) $g['id'], $goals)
|
||||
);
|
||||
|
||||
$response = "## Goals\n";
|
||||
foreach ($goals as $goal) {
|
||||
$milestones = array_map(
|
||||
static fn (array $m) => ($m['headline'] ?? '').' ('.((int) ($m['percentDone'] ?? 0)).'%)',
|
||||
$milestonesByGoal[(int) $goal['id']] ?? []
|
||||
);
|
||||
$result = [
|
||||
'id' => $goal['id'],
|
||||
'title' => Str::sanitizeForLLM($goal['title']),
|
||||
'description' => Str::sanitizeForLLM($goal['description']),
|
||||
'startValue' => $goal['startValue'],
|
||||
'currentValue' => $goal['currentValue'],
|
||||
'endValue' => $goal['endValue'],
|
||||
'metricType' => $goal['metricType'],
|
||||
'canvasId' => $goal['canvasId'],
|
||||
'milestones' => $milestones !== [] ? Str::sanitizeForLLM(implode('; ', $milestones)) : 'None',
|
||||
'startDate' => $goal['startDate'],
|
||||
'endDate' => $goal['endDate'],
|
||||
'status' => $goal['status'],
|
||||
'setting' => $goal['setting'],
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
69
app/Domain/Goalcanvas/Tools/GetChildGoalsTool.php
Normal file
69
app/Domain/Goalcanvas/Tools/GetChildGoalsTool.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Get all child goals associated with a parent goal (KPI).
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetChildGoalsTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('parentId')->description('ID of the parent goal to get children for.')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getChildGoals';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets all child goals associated with a parent goal.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$parentId = (int) ($arguments['parentId'] ?? 0);
|
||||
$childGoals = $this->goalcanvasService->getChildrenbyKPI($parentId);
|
||||
|
||||
if (empty($childGoals)) {
|
||||
return ToolResult::text("No child goals found for parent goal ID: {$parentId}");
|
||||
}
|
||||
|
||||
$response = "## Child Goals for Parent ID: {$parentId}\n";
|
||||
foreach ($childGoals as $goal) {
|
||||
$result = [
|
||||
'id' => $goal['id'],
|
||||
'title' => Str::sanitizeForLLM($goal['title']),
|
||||
'startValue' => $goal['startValue'],
|
||||
'currentValue' => $goal['currentValue'],
|
||||
'endValue' => $goal['endValue'],
|
||||
'metricType' => $goal['metricType'],
|
||||
'boardTitle' => Str::sanitizeForLLM($goal['boardTitle']),
|
||||
'canvasId' => $goal['canvasId'],
|
||||
'projectName' => Str::sanitizeForLLM($goal['projectName']),
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
80
app/Domain/Goalcanvas/Tools/GetGoalTool.php
Normal file
80
app/Domain/Goalcanvas/Tools/GetGoalTool.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Get detailed information about a specific goal.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetGoalTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('goalId')->description('ID of the goal to retrieve.')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getGoal';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets detailed information about a specific goal by its ID.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$goalId = (int) ($arguments['goalId'] ?? 0);
|
||||
$goal = $this->goalcanvasService->getGoalItem($goalId);
|
||||
|
||||
if (! $goal) {
|
||||
return ToolResult::error("Goal with ID {$goalId} not found.");
|
||||
}
|
||||
|
||||
// Milestones come from the tracked_by edge model (many-to-many), not
|
||||
// the frozen legacy milestoneId column — a goal can have several, and
|
||||
// the column goes stale after edits.
|
||||
$milestones = array_map(
|
||||
static fn (array $m) => ($m['headline'] ?? '').' ('.((int) ($m['percentDone'] ?? 0)).'%, '.($m['statusType'] ?? 'NEW').')',
|
||||
$this->goalcanvasService->getGoalMilestones($goalId)['milestones']
|
||||
);
|
||||
|
||||
$response = "## Goal Details\n";
|
||||
$result = [
|
||||
'id' => $goal['id'],
|
||||
'title' => Str::sanitizeForLLM($goal['title']),
|
||||
'description' => Str::sanitizeForLLM($goal['description']),
|
||||
'board' => Str::sanitizeForLLM($goal['boardTitle'] ?? ''),
|
||||
'startValue' => $goal['startValue'],
|
||||
'currentValue' => $goal['currentValue'],
|
||||
'endValue' => $goal['endValue'],
|
||||
'metricType' => $goal['metricType'],
|
||||
'status' => $goal['status'],
|
||||
'startDate' => $goal['startDate'],
|
||||
'endDate' => $goal['endDate'],
|
||||
'milestones' => $milestones !== [] ? Str::sanitizeForLLM(implode('; ', $milestones)) : 'None',
|
||||
'author' => $goal['authorFirstname'].' '.$goal['authorLastname'],
|
||||
'created' => $goal['created'],
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
71
app/Domain/Goalcanvas/Tools/GetGoalsByMilestoneTool.php
Normal file
71
app/Domain/Goalcanvas/Tools/GetGoalsByMilestoneTool.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Get all goals associated with a specific milestone.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetGoalsByMilestoneTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('milestoneId')->description('ID of the milestone to get goals for.')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getGoalsByMilestone';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets all goals associated with a specific milestone.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$milestoneId = (int) ($arguments['milestoneId'] ?? 0);
|
||||
$goals = $this->goalcanvasService->getGoalsByMilestone($milestoneId);
|
||||
|
||||
if (empty($goals)) {
|
||||
return ToolResult::text("No goals found for milestone ID: {$milestoneId}");
|
||||
}
|
||||
|
||||
$response = "## Goals for Milestone ID: {$milestoneId}\n";
|
||||
foreach ($goals as $goal) {
|
||||
$result = [
|
||||
'id' => $goal['id'],
|
||||
'title' => Str::sanitizeForLLM($goal['title']),
|
||||
'description' => Str::sanitizeForLLM($goal['description']),
|
||||
'startValue' => $goal['startValue'],
|
||||
'currentValue' => $goal['currentValue'],
|
||||
'endValue' => $goal['endValue'],
|
||||
'metricType' => $goal['metricType'],
|
||||
'canvasId' => $goal['canvasId'],
|
||||
'startDate' => $goal['startDate'],
|
||||
'endDate' => $goal['endDate'],
|
||||
'status' => $goal['status'],
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
64
app/Domain/Goalcanvas/Tools/GetParentKPIsTool.php
Normal file
64
app/Domain/Goalcanvas/Tools/GetParentKPIsTool.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Goalcanvas\Tools;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
|
||||
/**
|
||||
* Get all available parent KPIs (goals) that can be linked to other goals.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetParentKPIsTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('projectId')->description('Project ID to get parent KPIs for.')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getParentKPIs';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets all available parent KPIs that can be linked to other goals.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$projectId = (int) ($arguments['projectId'] ?? 0);
|
||||
$parentKPIs = $this->goalcanvasService->getParentKPIs($projectId);
|
||||
|
||||
if (empty($parentKPIs)) {
|
||||
return ToolResult::text("No parent KPIs found for project ID: {$projectId}");
|
||||
}
|
||||
|
||||
$response = "## Available Parent KPIs for Project ID: {$projectId}\n";
|
||||
foreach ($parentKPIs as $kpi) {
|
||||
$result = [
|
||||
'id' => $kpi['id'],
|
||||
'description' => Str::sanitizeForLLM($kpi['description']),
|
||||
'project' => Str::sanitizeForLLM($kpi['project']),
|
||||
'board' => Str::sanitizeForLLM($kpi['board']),
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user