OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
65
app/Domain/Bom/Tools/ListMastersTool.php
Normal file
65
app/Domain/Bom/Tools/ListMastersTool.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Bom\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\Bom\Services\Bom;
|
||||
|
||||
/**
|
||||
* 列出全局主数据(BOM / 工艺文件 / 工具清单)。
|
||||
*/
|
||||
#[IsReadOnly]
|
||||
class ListMastersTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Bom $bomService,
|
||||
) {}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'listMasters';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return '列出全局主数据(BOM / 工艺文件 / 工具清单)。主数据是跨项目共享的全局资源,type 取值:bom=物料清单、process=工艺文件、tooling=工具清单。';
|
||||
}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->string('type')->description('主数据类型:bom | process | tooling,默认 bom。');
|
||||
}
|
||||
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$type = (string) ($arguments['type'] ?? 'bom');
|
||||
if (! in_array($type, ['bom', 'process', 'tooling'], true)) {
|
||||
$type = 'bom';
|
||||
}
|
||||
|
||||
$masters = $this->bomService->getMasters($type, 0);
|
||||
|
||||
if (empty($masters)) {
|
||||
return ToolResult::text("无 {$type} 主数据。");
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
foreach ($masters as $m) {
|
||||
$rows[] = [
|
||||
'id' => (int) $m['id'],
|
||||
'type' => (string) ($m['type'] ?? 'bom'),
|
||||
'bomNo' => (string) ($m['bomNo'] ?? ''),
|
||||
'productName' => Str::sanitizeForLLM((string) ($m['productName'] ?? '')),
|
||||
'version' => (string) ($m['version'] ?? ''),
|
||||
'specification' => Str::sanitizeForLLM((string) ($m['specification'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
return ToolResult::json(['type' => $type, 'count' => count($rows), 'items' => $rows]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user