| @@ -76,11 +76,7 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 75 unmodified lines |
| 76 | ); | 76 | ); |
| 77 | } | 77 | } |
| 78 | | 78 | |
| 79 | const payload = (input && typeof input === "object" && !Array.isArray(input)) | 79 | const payload = input && typeof input === "object" ? (input as Record<string, unknown>) : {}; |
| 80 | ? (input as Record<string, unknown>) | | |
| 81 | : (typeof input === "string") | | |
| 82 | ? ({ query: input } satisfies Record<string, unknown>) | | |
| 83 | : {}; | | |
| 84 | const isAllowed = (path: string, approval: ToolDefinition["approval"]) => | 80 | const isAllowed = (path: string, approval: ToolDefinition["approval"]) => |
| 85 | getDecisionForContext( | 81 | getDecisionForContext( |
| 86 | { path, approval, description: "", run: async () => null } as ToolDefinition, | 82 | { path, approval, description: "", run: async () => null } as ToolDefinition, |
| @@ -88,22 +84,9 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 1 unmodified line |
| 88 | typedPolicies, | 84 | typedPolicies, |
| 89 | ) !== "deny"; | 85 | ) !== "deny"; |
| 90 | | 86 | |
| 91 | const formatSignature = (inputHint: string | undefined, outputHint: string | undefined) => { | 87 | const normalizeHint = (value: unknown, fallback: string) => { |
| 92 | const args = (inputHint && inputHint.trim().length > 0) ? inputHint.trim() : "{}"; | 88 | const str = typeof value === "string" ? value.trim() : ""; |
| 93 | const out = (outputHint && outputHint.trim().length > 0) ? outputHint.trim() : "unknown"; | 89 | return str.length > 0 ? str : fallback; |
| 94 | return `(input: ${args}): Promise<${out}>`; | | |
| 95 | }; | | |
| 96 | | | |
| 97 | const buildExampleCall = (path: string, previewKeys?: string[]) => { | | |
| 98 | const keys = Array.isArray(previewKeys) ? previewKeys : []; | | |
| 99 | if (keys.length === 0) { | | |
| 100 | return `await tools.${path}({});`; | | |
| 101 | } | | |
| 102 | const snippet = keys | | |
| 103 | .slice(0, 5) | | |
| 104 | .map((key) => `${key}: ...`) | | |
| 105 | .join(", "); | | |
| 106 | return `await tools.${path}({ ${snippet} });`; | | |
| 107 | }; | 90 | }; |
| 108 | | 91 | |
| 109 | if (toolPath === "catalog.namespaces") { | 92 | if (toolPath === "catalog.namespaces") { |
| @@ -145,19 +128,12 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 35 unmodified lines |
| 145 | const preferredPath = entry.preferredPath ?? entry.path; | 128 | const preferredPath = entry.preferredPath ?? entry.path; |
| 146 | return { | 129 | return { |
| 147 | path: preferredPath, | 130 | path: preferredPath, |
| 148 | aliases: entry.aliases ?? [], | | |
| 149 | source: entry.source, | 131 | source: entry.source, |
| 150 | approval: entry.approval, | 132 | approval: entry.approval, |
| 151 | description: entry.description, | 133 | description: entry.description, |
| 152 | signatureInfo: { | 134 | input: normalizeHint(entry.displayInput, "{}"), |
| 153 | input: entry.displayInput, | 135 | output: normalizeHint(entry.displayOutput, "unknown"), |
| 154 | output: entry.displayOutput, | 136 | requiredKeys: entry.requiredInputKeys ?? [], |
| 155 | requiredKeys: entry.requiredInputKeys ?? [], | | |
| 156 | previewKeys: entry.previewInputKeys ?? [], | | |
| 157 | }, | | |
| 158 | signatureText: formatSignature(entry.displayInput, entry.displayOutput), | | |
| 159 | canonicalSignature: formatSignature(entry.displayInput, entry.displayOutput), | | |
| 160 | exampleCall: buildExampleCall(preferredPath, entry.previewInputKeys), | | |
| 161 | }; | 137 | }; |
| 162 | }); | 138 | }); |
| 163 | | 139 | |
| @@ -184,19 +160,12 @@ export async function invokeTool(ctx: ActionCtx, task: TaskRecord, call: ToolCal · 20 unmodified lines |
| 184 | const description = compact ? String(entry.description ?? "").split("\n")[0] : entry.description; | 160 | const description = compact ? String(entry.description ?? "").split("\n")[0] : entry.description; |
| 185 | return { | 161 | return { |
| 186 | path: preferredPath, | 162 | path: preferredPath, |
| 187 | aliases: entry.aliases ?? [], | | |
| 188 | source: entry.source, | 163 | source: entry.source, |
| 189 | approval: entry.approval, | 164 | approval: entry.approval, |
| 190 | description, | 165 | description, |
| 191 | signature: formatSignature(entry.displayInput, entry.displayOutput), | 166 | input: normalizeHint(entry.displayInput, "{}"), |
| 192 | canonicalSignature: formatSignature(entry.displayInput, entry.displayOutput), | 167 | output: normalizeHint(entry.displayOutput, "unknown"), |
| 193 | signatureInfo: { | 168 | requiredKeys: entry.requiredInputKeys ?? [], |
| 194 | input: entry.displayInput, | | |
| 195 | output: entry.displayOutput, | | |
| 196 | requiredKeys: entry.requiredInputKeys ?? [], | | |
| 197 | previewKeys: entry.previewInputKeys ?? [], | | |
| 198 | }, | | |
| 199 | exampleCall: buildExampleCall(preferredPath, entry.previewInputKeys), | | |
| 200 | }; | 169 | }; |
| 201 | }); | 170 | }); |
| 202 | | 171 | |