integer('id')->description('主数据 ID。')->required() ->integer('limit')->description('最多返回多少行明细,默认 50。'); } public function handle(array $arguments): ToolResult { $id = (int) ($arguments['id'] ?? 0); $limit = (int) ($arguments['limit'] ?? 50); $detail = $this->bomService->getBomDetail($id); if ($detail === false) { return ToolResult::error("主数据不存在或无权访问:{$id}"); } $bom = $detail['bom'] ?? []; $columns = $detail['columns'] ?? []; $items = $detail['items'] ?? []; $result = [ 'id' => (int) ($bom['id'] ?? 0), 'type' => (string) ($bom['type'] ?? 'bom'), 'bomNo' => (string) ($bom['bomNo'] ?? ''), 'productName' => Str::sanitizeForLLM((string) ($bom['productName'] ?? '')), 'version' => (string) ($bom['version'] ?? ''), 'columns' => array_map(fn ($c) => [ 'key' => (string) $c['key'], 'label' => (string) ($c['label'] ?? $c['key']), ], $columns), 'itemCount' => count($items), 'items' => array_slice(array_map(function ($it) { $row = []; foreach ($it as $k => $v) { if (is_scalar($v)) { $row[$k] = Str::sanitizeForLLM((string) $v); } } return $row; }, $items), 0, $limit), ]; return ToolResult::json($result); } }