OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
87
app/Domain/Comments/Tools/AddCommentTool.php
Normal file
87
app/Domain/Comments/Tools/AddCommentTool.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Comments\Tools;
|
||||
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Comments\Services\Comments;
|
||||
use Leantime\Domain\Goalcanvas\Services\Goalcanvas;
|
||||
use Leantime\Domain\Projects\Services\Projects;
|
||||
use Leantime\Domain\Tickets\Services\Tickets;
|
||||
|
||||
/**
|
||||
* Add a new comment to a specific entity.
|
||||
*/
|
||||
class AddCommentTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Comments $commentsService,
|
||||
private Projects $projectService,
|
||||
private Tickets $ticketService,
|
||||
private Goalcanvas $goalcanvasService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->string('text')->description('Comment text.')
|
||||
->required()
|
||||
->string('module')->description('Module type (ticket, project, goal, etc.).')
|
||||
->required()
|
||||
->integer('entityId')->description('ID of the entity to add comment to.')
|
||||
->required()
|
||||
->string('status')->description('Status indicator for project updates (green, yellow, red). Only used for project comments.');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'addComment';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Adds a new comment to a specific entity.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$module = $arguments['module'];
|
||||
$entityId = (int) ($arguments['entityId'] ?? 0);
|
||||
|
||||
$entity = $this->getEntity($module, $entityId);
|
||||
if (! $entity) {
|
||||
return ToolResult::error("Entity not found: {$module} ID {$entityId}");
|
||||
}
|
||||
|
||||
$values = [
|
||||
'text' => $arguments['text'],
|
||||
'father' => 0,
|
||||
'status' => ($arguments['status'] ?? ''),
|
||||
];
|
||||
|
||||
$result = $this->commentsService->addComment($values, $module, $entityId, $entity);
|
||||
|
||||
if ($result) {
|
||||
return ToolResult::text("Comment added successfully to {$module} #{$entityId}");
|
||||
}
|
||||
|
||||
return ToolResult::error('Failed to add comment. Please check the provided information.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get an entity based on module type and ID.
|
||||
*/
|
||||
private function getEntity(string $module, int $entityId): mixed
|
||||
{
|
||||
return match ($module) {
|
||||
'ticket' => $this->ticketService->getTicket($entityId),
|
||||
'project' => $this->projectService->getProject($entityId),
|
||||
'goal', 'goalcanvas', 'goalcanvasitem' => $this->goalcanvasService->getSingleCanvas($entityId),
|
||||
default => ['id' => $entityId],
|
||||
};
|
||||
}
|
||||
}
|
||||
74
app/Domain/Comments/Tools/AddProjectStatusUpdateTool.php
Normal file
74
app/Domain/Comments/Tools/AddProjectStatusUpdateTool.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Comments\Tools;
|
||||
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||||
use Leantime\Domain\Comments\Services\Comments;
|
||||
use Leantime\Domain\Projects\Services\Projects;
|
||||
|
||||
/**
|
||||
* Add a project status update with a red/yellow/green indicator.
|
||||
*/
|
||||
class AddProjectStatusUpdateTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Comments $commentsService,
|
||||
private Projects $projectService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('projectId')->description('Project ID to add status update to.')
|
||||
->required()
|
||||
->string('text')->description('Status update text.')
|
||||
->required()
|
||||
->string('status')
|
||||
->description('Status indicator (green, yellow, red).')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'addProjectStatusUpdate';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Adds a new status update to a project with a red/yellow/green indicator.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$projectId = (int) ($arguments['projectId'] ?? 0);
|
||||
$status = $arguments['status'];
|
||||
|
||||
if (! in_array($status, ['green', 'yellow', 'red'])) {
|
||||
return ToolResult::error("Invalid status value. Must be 'green', 'yellow', or 'red'.");
|
||||
}
|
||||
|
||||
$project = $this->projectService->getProject($projectId);
|
||||
if (! $project) {
|
||||
return ToolResult::error("Project not found: ID {$projectId}");
|
||||
}
|
||||
|
||||
$values = [
|
||||
'text' => $arguments['text'],
|
||||
'father' => 0,
|
||||
'status' => $status,
|
||||
];
|
||||
|
||||
$result = $this->commentsService->addComment($values, 'project', $projectId, $project);
|
||||
|
||||
if ($result) {
|
||||
return ToolResult::text("Project status update added successfully with status: {$status}");
|
||||
}
|
||||
|
||||
return ToolResult::error('Failed to add status update. Please check the provided information.');
|
||||
}
|
||||
}
|
||||
72
app/Domain/Comments/Tools/GetAllProjectCommentsTool.php
Normal file
72
app/Domain/Comments/Tools/GetAllProjectCommentsTool.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Comments\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\Comments\Services\Comments;
|
||||
|
||||
/**
|
||||
* Get all project status updates (comments) for a specific project.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetAllProjectCommentsTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Comments $commentsService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('projectId')->description('Project ID to get status updates for.')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getAllProjectComments';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets all project status updates for a specific project.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$projectId = (int) ($arguments['projectId'] ?? 0);
|
||||
$comments = $this->commentsService->getComments('project', $projectId);
|
||||
|
||||
if (empty($comments)) {
|
||||
return ToolResult::text("No status updates found for project ID: {$projectId}");
|
||||
}
|
||||
|
||||
$response = "## Project Status Updates\n";
|
||||
foreach ($comments as $comment) {
|
||||
$statusIndicator = match ($comment['status']) {
|
||||
'green' => '🟢 ',
|
||||
'yellow' => '🟡 ',
|
||||
'red' => '🔴 ',
|
||||
default => '',
|
||||
};
|
||||
|
||||
$result = [
|
||||
'id' => $comment['id'],
|
||||
'status' => $statusIndicator.($comment['status'] ?: 'None'),
|
||||
'text' => Str::sanitizeForLLM($comment['text']),
|
||||
'date' => $comment['date'],
|
||||
'author' => $comment['firstname'].' '.$comment['lastname'],
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
72
app/Domain/Comments/Tools/GetCommentsTool.php
Normal file
72
app/Domain/Comments/Tools/GetCommentsTool.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Comments\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\Comments\Services\Comments;
|
||||
|
||||
/**
|
||||
* Get all comments for a specific entity.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class GetCommentsTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Comments $commentsService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->string('module')->description('Module type (ticket, project, goal, etc.).')
|
||||
->required()
|
||||
->integer('entityId')->description('ID of the entity to get comments for.')
|
||||
->required()
|
||||
->integer('commentOrder')->description('Order of comments (0 = newest first, 1 = oldest first).');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'getComments';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Gets all comments for a specific entity.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$module = $arguments['module'];
|
||||
$entityId = (int) ($arguments['entityId'] ?? 0);
|
||||
$commentOrder = (int) ($arguments['commentOrder'] ?? 0);
|
||||
|
||||
$comments = $this->commentsService->getComments($module, $entityId, $commentOrder);
|
||||
|
||||
if (empty($comments)) {
|
||||
return ToolResult::text("No comments found for {$module} ID: {$entityId}");
|
||||
}
|
||||
|
||||
$response = "## Comments for {$module} #{$entityId}\n";
|
||||
foreach ($comments as $comment) {
|
||||
$result = [
|
||||
'id' => $comment['id'],
|
||||
'text' => Str::sanitizeForLLM($comment['text']),
|
||||
'date' => $comment['date'],
|
||||
'userId' => $comment['userId'],
|
||||
'author' => $comment['firstname'].' '.$comment['lastname'],
|
||||
'status' => $comment['status'] ?: 'None',
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
79
app/Domain/Comments/Tools/PollCommentsTool.php
Normal file
79
app/Domain/Comments/Tools/PollCommentsTool.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Comments\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\Comments\Services\Comments;
|
||||
|
||||
/**
|
||||
* Poll for all comments across the account.
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class PollCommentsTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Comments $commentsService,
|
||||
) {}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('projectId')->description('Project ID to filter comments by.')
|
||||
->integer('moduleId')->description('Module ID to filter comments by.');
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'pollComments';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Polls for all comments across the account.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$projectId = ($arguments['projectId'] ?? null);
|
||||
$moduleId = ($arguments['moduleId'] ?? null);
|
||||
|
||||
$comments = $this->commentsService->pollComments($projectId, $moduleId);
|
||||
|
||||
if (empty($comments)) {
|
||||
return ToolResult::text('No comments found');
|
||||
}
|
||||
|
||||
$response = "## Comments\n";
|
||||
foreach ($comments as $comment) {
|
||||
$statusIndicator = '';
|
||||
if (isset($comment['status'])) {
|
||||
$statusIndicator = match ($comment['status']) {
|
||||
'green' => '🟢 ',
|
||||
'yellow' => '🟡 ',
|
||||
'red' => '🔴 ',
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
$result = [
|
||||
'id' => $comment['id'],
|
||||
'module' => $comment['module'],
|
||||
'moduleId' => $comment['moduleId'],
|
||||
'status' => $comment['status'] ? $statusIndicator.$comment['status'] : 'None',
|
||||
'text' => Str::sanitizeForLLM($comment['text']),
|
||||
'date' => $comment['date'],
|
||||
'projectId' => $comment['projectId'],
|
||||
];
|
||||
$response .= Str::toMarkdown($result)."\n";
|
||||
}
|
||||
|
||||
return ToolResult::text($response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user