|
8 | 8 | v2AgentMcpServerAdvancedSchema, |
9 | 9 | v2AgentMcpToolSchema, |
10 | 10 | } from '@/lib/api/contracts/v2/workflows' |
| 11 | +import { createMcpToolId } from '@/lib/mcp/shared' |
11 | 12 |
|
12 | 13 | /** Attachment identity comes from its definition, never an author-supplied alias. */ |
13 | 14 | const identityFields = ['title', 'name', 'toolId', 'functionName'] as const |
@@ -60,6 +61,23 @@ export function getToolBindingAuthoringSchema(blockType: string) { |
60 | 61 | return undefined |
61 | 62 | } |
62 | 63 |
|
| 64 | +type IdentityField = (typeof identityFields)[number] |
| 65 | + |
| 66 | +/** |
| 67 | + * The labels the editor's tool picker derives from a binding's own definition (tool-input.tsx): a |
| 68 | + * child workflow tool's fixed title and tool id, and an MCP tool's name and the id built from it. |
| 69 | + * They name nothing the binding does not, so writing them is not an override. |
| 70 | + */ |
| 71 | +function definitionLabels(tool: Record<string, unknown>): Partial<Record<IdentityField, string>> { |
| 72 | + if (tool.type === 'workflow_input') return { title: 'Workflow', toolId: 'workflow_executor' } |
| 73 | + const params = isPlainRecord(tool.params) ? tool.params : {} |
| 74 | + const { serverId, toolName } = params |
| 75 | + if (tool.type === 'mcp' && typeof serverId === 'string' && typeof toolName === 'string') { |
| 76 | + return { title: toolName, toolId: createMcpToolId(serverId, toolName) } |
| 77 | + } |
| 78 | + return {} |
| 79 | +} |
| 80 | + |
63 | 81 | function bindingIdentity(tool: Record<string, unknown>): unknown[] { |
64 | 82 | const params = isPlainRecord(tool.params) ? tool.params : {} |
65 | 83 | return [tool.type, tool.operation, tool.customToolId, params.serverId, params.toolName] |
@@ -92,8 +110,11 @@ export function validateToolBindingAuthoring( |
92 | 110 | ) |
93 | 111 | const saved = savedIndex === -1 ? undefined : remaining.splice(savedIndex, 1)[0] |
94 | 112 | const isInline = tool.type === 'custom-tool' && !tool.customToolId |
| 113 | + const derived = definitionLabels(tool) |
95 | 114 | const carried = identityFields.filter( |
96 | | - (key) => saved && tool[key] === saved[key] && !(isInline && key === 'title') |
| 115 | + (key) => |
| 116 | + (tool[key] !== undefined && tool[key] === derived[key]) || |
| 117 | + (saved && tool[key] === saved[key] && !(isInline && key === 'title')) |
97 | 118 | ) |
98 | 119 | const candidate = omit(tool, carried) |
99 | 120 | if ( |
|
0 commit comments