@bastani/atomic 0.9.35-alpha.3 → 0.9.35-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/builtin/intercom/package.json +2 -2
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/package.json +3 -3
  5. package/dist/builtin/web-access/package.json +2 -2
  6. package/dist/builtin/workflows/package.json +2 -2
  7. package/dist/codemode-worker.js +222 -78
  8. package/dist/config.d.ts +1 -0
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/config.js +1 -0
  11. package/dist/config.js.map +1 -1
  12. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  13. package/dist/core/extensions/loader-virtual-modules.js +2 -0
  14. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  15. package/dist/core/model-runtime.d.ts.map +1 -1
  16. package/dist/core/model-runtime.js +11 -6
  17. package/dist/core/model-runtime.js.map +1 -1
  18. package/dist/core/remote-catalog-provider.d.ts +12 -1
  19. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  20. package/dist/core/remote-catalog-provider.js +85 -24
  21. package/dist/core/remote-catalog-provider.js.map +1 -1
  22. package/dist/core/tools/bash.d.ts +2 -6
  23. package/dist/core/tools/bash.d.ts.map +1 -1
  24. package/dist/core/tools/bash.js +9 -39
  25. package/dist/core/tools/bash.js.map +1 -1
  26. package/dist/core/tools/powershell.d.ts +2 -10
  27. package/dist/core/tools/powershell.d.ts.map +1 -1
  28. package/dist/core/tools/render-utils.d.ts +15 -0
  29. package/dist/core/tools/render-utils.d.ts.map +1 -1
  30. package/dist/core/tools/render-utils.js +46 -0
  31. package/dist/core/tools/render-utils.js.map +1 -1
  32. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  33. package/dist/extensions/codemode/execute.js +2 -0
  34. package/dist/extensions/codemode/execute.js.map +1 -1
  35. package/dist/extensions/codemode/renderer.d.ts +7 -1
  36. package/dist/extensions/codemode/renderer.d.ts.map +1 -1
  37. package/dist/extensions/codemode/renderer.js +12 -1
  38. package/dist/extensions/codemode/renderer.js.map +1 -1
  39. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  40. package/dist/extensions/codemode/tool.js +25 -12
  41. package/dist/extensions/codemode/tool.js.map +1 -1
  42. package/dist/extensions/mcp/tools.d.ts +2 -3
  43. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  44. package/dist/extensions/mcp/tools.js +62 -6
  45. package/dist/extensions/mcp/tools.js.map +1 -1
  46. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  47. package/dist/modes/interactive/components/custom-editor.js +2 -2
  48. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  49. package/dist/modes/interactive/components/settings-selector-items.js +1 -1
  50. package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
  51. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  52. package/dist/modes/interactive/components/tool-execution.js +1 -0
  53. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  54. package/dist/utils/clipboard.d.ts.map +1 -1
  55. package/dist/utils/clipboard.js +10 -1
  56. package/dist/utils/clipboard.js.map +1 -1
  57. package/docs/codemode.md +2 -2
  58. package/docs/environment-variables.md +1 -0
  59. package/docs/getting-started/installation.md +1 -1
  60. package/docs/keybindings.md +1 -1
  61. package/docs/providers.md +20 -0
  62. package/docs/sdk.md +2 -6
  63. package/docs/settings.md +1 -1
  64. package/docs/tui/reference.md +5 -3
  65. package/examples/extensions/overlay-test.ts +2 -2
  66. package/npm-shrinkwrap.json +53 -550
  67. package/package.json +6 -12
  68. package/dist/client/index.d.ts +0 -2
  69. package/dist/client/index.d.ts.map +0 -1
  70. package/dist/client/index.js +0 -2
  71. package/dist/client/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/extensions/codemode/execute.ts"],"names":[],"mappings":"AAWA,O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CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;KACvC,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAnyModel,\n\tClassifierContext,\n\tImageContent,\n\tImagesContext,\n\tModelType,\n\tModelTypeMap,\n\tTextContent,\n\tUsage,\n} from \"@bastani/pi-ai\";\nimport type { AgentTool, AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype CodemodeOutputItem,\n\ttype CodemodeResult,\n\tCodemodeSandbox,\n\ttype CodemodeTool,\n\tloadQuickJSWasm,\n\tparseCodemodeSource,\n\trenderToolSample,\n\ttoCodemodeIdentifier,\n} from \"@earendil-works/pi-codemode\";\nimport { getCodemodeWorkerUrl, getQuickJSWasmPath } from \"../../config.js\";\nimport type { ExtensionToolContext } from \"../../core/extensions/context-types.ts\";\nimport type { ToolNamespace } from \"../../core/extensions/tool-types.ts\";\nimport type { SessionEntry } from \"../../core/session-manager.ts\";\nimport { formatSize } from \"../../core/tools/truncate.ts\";\nimport { combineUsage } from \"../../core/usage-totals.ts\";\nimport { writeOutputFile } from \"../../utils/output-files.js\";\nimport { Bm25Ranker, createToolSearchDocument, DEFAULT_TOOL_SEARCH_LIMIT } from \"../tool-search/tool.js\";\nimport {\n\tCODEMODE_DOCS_PATH,\n\tCODEMODE_STORE_ENTRY_TYPE,\n\tCODEMODE_TOOL_NAME,\n\ttype CodemodeNestedCall,\n\ttype CodemodeToolDetails,\n\ttype CodemodeToolInput,\n\ttype CodemodeToolOptions,\n\tgetCodemodeCallableTools,\n\ttoCodemodeDeclaration,\n} from \"./tool.js\";\n\nconst IMAGE_EXTENSIONS: Record<string, string> = {\n\t\"image/png\": \".png\",\n\t\"image/jpeg\": \".jpg\",\n\t\"image/gif\": \".gif\",\n\t\"image/webp\": \".webp\",\n};\n\nasync function saveImages(items: (TextContent | ImageContent)[]): Promise<(TextContent | ImageContent)[]> {\n\tconst labels = new Map<string, Promise<string>>();\n\tconst label = async ({ data, mimeType }: ImageContent): Promise<string> => {\n\t\tconst bytes = Buffer.from(data, \"base64\");\n\t\tconst kind = `${mimeType}, ${formatSize(bytes.length)}`;\n\t\tconst extension = IMAGE_EXTENSIONS[mimeType];\n\t\tif (!extension) throw new Error(`No file extension for image type ${mimeType}`);\n\t\ttry {\n\t\t\tconst path = await writeOutputFile(\"atomic-codemode\", extension, bytes);\n\t\t\treturn `[Image saved to ${path} (${kind})]`;\n\t\t} catch (error) {\n\t\t\treturn `[Image (${kind}) could not be saved: ${error instanceof Error ? error.message : String(error)}]`;\n\t\t}\n\t};\n\tconst result = await Promise.all(\n\t\titems.map(async (item): Promise<(TextContent | ImageContent)[]> => {\n\t\t\tif (item.type !== \"image\") return [item];\n\t\t\tlet pending = labels.get(item.data);\n\t\t\tif (!pending) {\n\t\t\t\tpending = label(item);\n\t\t\t\tlabels.set(item.data, pending);\n\t\t\t}\n\t\t\treturn [{ type: \"text\", text: await pending }, item];\n\t\t}),\n\t);\n\treturn result.flat();\n}\n\nexport function readCodemodeStore(branch: readonly SessionEntry[]): Record<string, unknown> {\n\tconst store = new Map<string, unknown>();\n\tfor (const entry of branch) {\n\t\tif (\n\t\t\tentry.type !== \"custom\" ||\n\t\t\tentry.customType !== CODEMODE_STORE_ENTRY_TYPE ||\n\t\t\ttypeof entry.data !== \"object\" ||\n\t\t\tentry.data === null\n\t\t)\n\t\t\tcontinue;\n\t\tconst data = entry.data as { set?: Record<string, unknown>; delete?: string[] };\n\t\tif (\n\t\t\t!data.set ||\n\t\t\ttypeof data.set !== \"object\" ||\n\t\t\t!Array.isArray(data.delete) ||\n\t\t\t!data.delete.every((key) => typeof key === \"string\")\n\t\t)\n\t\t\tcontinue;\n\t\tfor (const key of data.delete) store.delete(key);\n\t\tfor (const [key, value] of Object.entries(data.set)) store.set(key, value);\n\t}\n\treturn Object.fromEntries(store);\n}\nfunction textOf(result: AgentToolResult<unknown>): string {\n\treturn result.content\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n}\n/** Explicit public catalog fields. Provider configuration and credential-bearing URLs never cross into the VM. */\nexport function toCodemodeModelInfo(model: AnyModel): Record<string, unknown> {\n\treturn {\n\t\ttype: model.type,\n\t\tprovider: model.provider,\n\t\tid: model.id,\n\t\tname: model.name,\n\t\tapi: model.api,\n\t\tinput: model.input,\n\t\t...(\"reasoning\" in model ? { reasoning: model.reasoning } : {}),\n\t\t...(\"contextWindow\" in model ? { contextWindow: model.contextWindow } : {}),\n\t\t...(\"maxTokens\" in model ? { maxTokens: model.maxTokens } : {}),\n\t\tcost: model.cost,\n\t};\n}\n/** Separate text items and collect console calls after the script's other output. */\nfunction formatOutput(output: readonly CodemodeOutputItem[]): (TextContent | ImageContent)[] {\n\tconst total = output.filter((item) => item.type === \"text\" && !item.console).length;\n\tconst items: (TextContent | ImageContent)[] = [];\n\tconst consoleLines: string[] = [];\n\tlet index = 0;\n\tfor (const item of output) {\n\t\tif (item.type === \"image\") items.push(item);\n\t\telse if (item.console) consoleLines.push(item.text);\n\t\telse {\n\t\t\tindex++;\n\t\t\titems.push({ type: \"text\", text: total > 1 ? `==> text ${index}/${total} <==\\n${item.text}` : item.text });\n\t\t}\n\t}\n\tif (consoleLines.length > 0)\n\t\titems.push({ type: \"text\", text: `<console_output>\\n${consoleLines.join(\"\\n\")}\\n</console_output>` });\n\treturn items;\n}\n\n/** Providers may concatenate adjacent text blocks without a separator. */\nfunction joinAdjacentText(items: (TextContent | ImageContent)[]): (TextContent | ImageContent)[] {\n\tconst joined: (TextContent | ImageContent)[] = [];\n\tlet parts: string[] = [];\n\tlet lastPart = \"\";\n\tconst flush = () => {\n\t\tif (parts.length > 0) joined.push({ type: \"text\", text: parts.join(\"\") });\n\t\tparts = [];\n\t\tlastPart = \"\";\n\t};\n\tfor (const item of items) {\n\t\tif (item.type !== \"text\") {\n\t\t\tflush();\n\t\t\tjoined.push(item);\n\t\t\tcontinue;\n\t\t}\n\t\tif (lastPart !== \"\" && !lastPart.endsWith(\"\\n\")) {\n\t\t\tparts.push(\"\\n\");\n\t\t\tlastPart = \"\\n\";\n\t\t}\n\t\tparts.push(item.text);\n\t\tif (item.text !== \"\") lastPart = item.text;\n\t}\n\tflush();\n\treturn joined;\n}\n\nconst MODEL_TYPES = [\"chat\", \"image\", \"classifier\"] as const;\nfunction modelType(value: unknown): ModelType {\n\tif (value === \"chat\" || value === \"image\" || value === \"classifier\") return value;\n\tthrow new Error('Model type must be \"chat\", \"image\", or \"classifier\"');\n}\nfunction withArticle(word: string): string {\n\treturn `${/^[aeiou]/.test(word) ? \"an\" : \"a\"} ${word}`;\n}\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction describeValue(value: unknown): string {\n\tif (value === undefined || value === null) return String(value);\n\tif (Array.isArray(value)) return value.length === 0 ? \"an empty array\" : \"an array\";\n\tif (typeof value === \"object\") {\n\t\tconst keys = Object.keys(value);\n\t\tif (keys.length === 0) return \"{}\";\n\t\treturn `{ ${keys.slice(0, 6).join(\", \")}${keys.length > 6 ? \", ...\" : \"\"} }`;\n\t}\n\treturn typeof value === \"string\" ? \"a string\" : `a ${typeof value}`;\n}\nconst CLASSIFIER_CONTEXT_SHAPE =\n\t'{ state: { ... }, images?: [{ type: \"image\", data: <base64>, mimeType }], questions: { <id>: { type: \"choice\", instructions, criteria: { <label>: <meaning> } } | { type: \"score\", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: \"bool\", instructions, criteria: { true: <meaning>, false: <meaning> } } } }';\nfunction checkClassifierContext(context: unknown): ClassifierContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(\n\t\t\t`models.classify() ${problem}. Expected context: ${CLASSIFIER_CONTEXT_SHAPE}. See \"Classify\" in ${CODEMODE_DOCS_PATH}.`,\n\t\t);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tif (!isRecord(context.state)) throw fail(`context.state must be an object, got ${describeValue(context.state)}`);\n\tconst { images } = context;\n\tif (images !== undefined) {\n\t\tif (!Array.isArray(images)) throw fail(`context.images must be an array, got ${describeValue(images)}`);\n\t\timages.forEach((image, index) => {\n\t\t\tif (\n\t\t\t\t!isRecord(image) ||\n\t\t\t\timage.type !== \"image\" ||\n\t\t\t\ttypeof image.data !== \"string\" ||\n\t\t\t\ttypeof image.mimeType !== \"string\"\n\t\t\t) {\n\t\t\t\tthrow fail(`context.images[${index}] must be an image block, got ${describeValue(image)}`);\n\t\t\t}\n\t\t});\n\t}\n\tconst { questions } = context;\n\tif (!isRecord(questions) || Object.keys(questions).length === 0)\n\t\tthrow fail(`context.questions must map question IDs to questions, got ${describeValue(questions)}`);\n\tconst isStrings = (values: unknown[]) => values.length > 0 && values.every((value) => typeof value === \"string\");\n\tfor (const [questionId, question] of Object.entries(questions)) {\n\t\tconst at = `context.questions.${questionId}`;\n\t\tif (!isRecord(question)) throw fail(`${at} must be a question object, got ${describeValue(question)}`);\n\t\tif (typeof question.instructions !== \"string\") throw fail(`${at}.instructions must be a string`);\n\t\tconst { criteria } = question;\n\t\tif (question.type === \"choice\") {\n\t\t\tif (!isRecord(criteria) || !isStrings(Object.values(criteria)))\n\t\t\t\tthrow fail(`${at} is a \"choice\" question, so criteria must map each label to its meaning`);\n\t\t} else if (question.type === \"score\") {\n\t\t\tif (!Array.isArray(criteria) || !isStrings(criteria))\n\t\t\t\tthrow fail(`${at} is a \"score\" question, so criteria must list the levels as strings, lowest first`);\n\t\t} else if (question.type === \"bool\") {\n\t\t\tif (!isRecord(criteria) || typeof criteria.true !== \"string\" || typeof criteria.false !== \"string\")\n\t\t\t\tthrow fail(`${at} is a \"bool\" question, so criteria must be { true: string, false: string }`);\n\t\t} else {\n\t\t\tthrow fail(`${at}.type must be \"choice\", \"score\", or \"bool\", got ${JSON.stringify(question.type)}`);\n\t\t}\n\t}\n\treturn context as unknown as ClassifierContext;\n}\nfunction checkImagesContext(context: unknown): ImagesContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(\n\t\t\t`models.generateImages() ${problem}. Expected context: { input: [{ type: \"text\", text: <prompt> }, ...optional { type: \"image\", data: <base64>, mimeType } references] }. See \"Generate images\" in ${CODEMODE_DOCS_PATH}.`,\n\t\t);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tconst { input } = context;\n\tif (!Array.isArray(input) || input.length === 0)\n\t\tthrow fail(`context.input must be a non-empty array of blocks, got ${describeValue(input)}`);\n\tinput.forEach((block: unknown, index) => {\n\t\tif (isRecord(block) && block.type === \"text\" && typeof block.text === \"string\") return;\n\t\tif (\n\t\t\tisRecord(block) &&\n\t\t\tblock.type === \"image\" &&\n\t\t\ttypeof block.data === \"string\" &&\n\t\t\ttypeof block.mimeType === \"string\"\n\t\t)\n\t\t\treturn;\n\t\tthrow fail(`context.input[${index}] must be a text or image block, got ${describeValue(block)}`);\n\t});\n\treturn context as unknown as ImagesContext;\n}\nfunction provider(value: unknown): string | undefined {\n\tif (value === undefined || value === null) return undefined;\n\tif (typeof value === \"string\") return value;\n\tthrow new Error(\"provider must be a string\");\n}\nfunction preview(args: unknown): string {\n\ttry {\n\t\treturn (JSON.stringify(args) ?? \"\").slice(0, 200);\n\t} catch {\n\t\treturn \"\";\n\t}\n}\ninterface ModelCallResult {\n\tstopReason: \"stop\" | \"error\" | \"aborted\";\n\terrorMessage?: string;\n\tusage?: Usage;\n}\nfunction createLimiter(limit: number) {\n\tlet active = 0;\n\tconst waiting: (() => void)[] = [];\n\treturn async <T>(run: () => Promise<T>): Promise<T> => {\n\t\tif (active >= limit) await new Promise<void>((resolve) => waiting.push(resolve));\n\t\tactive++;\n\t\ttry {\n\t\t\treturn await run();\n\t\t} finally {\n\t\t\tactive--;\n\t\t\twaiting.shift()?.();\n\t\t}\n\t};\n}\nfunction discoveryGlobals(\n\ttools: readonly AgentTool[],\n\tsamples: ReadonlyMap<string, string>,\n\toptions: CodemodeToolOptions,\n): CodemodeTool[] {\n\tconst entry = (name: string) => ({ name: toCodemodeIdentifier(name), description: samples.get(name) ?? \"\" });\n\tconst modelOnly = (query: string) => {\n\t\tconst wanted = query.trim().toLowerCase();\n\t\tconst name = options\n\t\t\t.getModelOnlyTools?.()\n\t\t\t.find(\n\t\t\t\t(name) =>\n\t\t\t\t\tname !== CODEMODE_TOOL_NAME &&\n\t\t\t\t\t[name, toCodemodeIdentifier(name)].some((candidate) => candidate.toLowerCase() === wanted),\n\t\t\t);\n\t\treturn name\n\t\t\t? { name, description: `\\`${name}\\` is model-only: call it directly, not from a script.` }\n\t\t\t: undefined;\n\t};\n\treturn [\n\t\t{\n\t\t\tname: \"searchTools\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [query, config] = args as [unknown, { limit?: unknown; namespace?: unknown } | undefined];\n\t\t\t\tif (typeof query !== \"string\") throw new Error(\"searchTools() expects a query string\");\n\t\t\t\tconst limit = config?.limit ?? DEFAULT_TOOL_SEARCH_LIMIT;\n\t\t\t\tif (typeof limit !== \"number\" || !Number.isInteger(limit) || limit <= 0)\n\t\t\t\t\tthrow new Error(\"searchTools() limit must be a positive integer\");\n\t\t\t\tif (config?.namespace !== undefined && typeof config.namespace !== \"string\")\n\t\t\t\t\tthrow new Error(\"searchTools() namespace must be a string\");\n\t\t\t\tconst docs = tools.flatMap((tool) => {\n\t\t\t\t\tconst namespace = options.getToolNamespace?.(tool.name);\n\t\t\t\t\treturn config?.namespace && namespace?.name !== config.namespace\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: [createToolSearchDocument(tool, namespace)];\n\t\t\t\t});\n\t\t\t\tconst hint = config?.namespace ? undefined : modelOnly(query);\n\t\t\t\tconst matches = new Bm25Ranker().rank(query, docs, limit).map((match) => entry(match.name));\n\t\t\t\treturn hint ? [hint, ...matches].slice(0, limit) : matches;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"describeTool\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [name] = args as unknown[];\n\t\t\t\tif (typeof name !== \"string\") throw new Error(\"describeTool() expects a tool name\");\n\t\t\t\tconst tool = tools.find((tool) => tool.name === name || toCodemodeIdentifier(tool.name) === name);\n\t\t\t\treturn tool ? samples.get(tool.name) : modelOnly(name)?.description;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"describeNamespace\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [name] = args as unknown[];\n\t\t\t\tif (typeof name !== \"string\") throw new Error(\"describeNamespace() expects a namespace name\");\n\t\t\t\tlet namespace: ToolNamespace | undefined;\n\t\t\t\tconst names: string[] = [];\n\t\t\t\tfor (const tool of tools) {\n\t\t\t\t\tconst toolNamespace = options.getToolNamespace?.(tool.name);\n\t\t\t\t\tif (toolNamespace?.name !== name) continue;\n\t\t\t\t\tnamespace ??= toolNamespace;\n\t\t\t\t\tnames.push(toCodemodeIdentifier(tool.name));\n\t\t\t\t}\n\t\t\t\tif (!namespace) return undefined;\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\t...(namespace.description ? { description: namespace.description } : {}),\n\t\t\t\t\t...(namespace.instructions ? { instructions: namespace.instructions } : {}),\n\t\t\t\t\ttools: names,\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t];\n}\nfunction modelGlobals(\n\tctx: ExtensionToolContext,\n\tid: string,\n\tcalls: CodemodeNestedCall[],\n\tpublish: () => void,\n\taddUsage: (usage: Usage) => void,\n\taddGeneratedImages: (count: number) => void,\n): CodemodeTool[] {\n\tconst models = ctx.modelRegistry;\n\tconst limit = createLimiter(4);\n\tlet count = 0;\n\tconst runModelCall = async <TType extends \"classifier\" | \"image\", TContext, TResult extends ModelCallResult>(\n\t\tname: string,\n\t\ttype: TType,\n\t\t[ref, context]: unknown[],\n\t\tcheckContext: (context: unknown) => TContext,\n\t\trun: (model: ModelTypeMap[TType], context: TContext) => Promise<TResult>,\n\t): Promise<TResult> => {\n\t\tconst listHint = `List the ${type} models you can use with models.getAvailableOfType(\"${type}\").`;\n\t\tif (!isRecord(ref) || typeof ref.provider !== \"string\" || typeof ref.id !== \"string\") {\n\t\t\tconst undefinedHint =\n\t\t\t\tref === undefined || ref === null\n\t\t\t\t\t? \" models.getModelOfType() returns undefined for an unknown provider or id.\"\n\t\t\t\t\t: \"\";\n\t\t\tthrow new Error(\n\t\t\t\t`${name}() expects ${withArticle(type)} model as its first argument, got ${describeValue(ref)}.${undefinedHint} ${listHint}`,\n\t\t\t);\n\t\t}\n\t\tconst { provider: providerId, id: modelId } = ref;\n\t\tconst model = models.getModelOfType(type, providerId, modelId);\n\t\tif (!model) {\n\t\t\tconst actualType = MODEL_TYPES.find(\n\t\t\t\t(other) => other !== type && models.getModelOfType(other, providerId, modelId) !== undefined,\n\t\t\t);\n\t\t\tthrow new Error(\n\t\t\t\tactualType\n\t\t\t\t\t? `\"${providerId}/${modelId}\" is ${withArticle(actualType)} model, not ${withArticle(type)} model. ${listHint}`\n\t\t\t\t\t: `Unknown ${type} model \"${providerId}/${modelId}\". ${listHint}`,\n\t\t\t);\n\t\t}\n\t\tconst checked = checkContext(context);\n\t\tconst record: CodemodeNestedCall = {\n\t\t\tid: `${id}/${name}/${++count}`,\n\t\t\tname,\n\t\t\targs: `${model.provider}/${model.id}`,\n\t\t\tstatus: \"running\",\n\t\t};\n\t\tcalls.push(record);\n\t\tpublish();\n\t\tconst start = performance.now();\n\t\tconst result = await limit(() => run(model, checked));\n\t\trecord.durationMs = performance.now() - start;\n\t\trecord.status = result.stopReason === \"stop\" ? \"ok\" : result.stopReason === \"aborted\" ? \"cancelled\" : \"error\";\n\t\tif (result.errorMessage) record.error = result.errorMessage.slice(0, 500);\n\t\tif (result.usage) {\n\t\t\trecord.cost = result.usage.cost.total;\n\t\t\taddUsage(result.usage);\n\t\t}\n\t\tpublish();\n\t\treturn result;\n\t};\n\treturn [\n\t\t{\n\t\t\tname: \"models.getModelsOfType\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [type, source] = args as unknown[];\n\t\t\t\treturn models.getModelsOfType(modelType(type), provider(source)).map(toCodemodeModelInfo);\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"models.getAvailableOfType\",\n\t\t\tspread: true,\n\t\t\texecute: async (args, { signal }) => {\n\t\t\t\tconst [type, source] = args as unknown[];\n\t\t\t\treturn (await models.getAvailableOfType(modelType(type), provider(source), { signal })).map(\n\t\t\t\t\ttoCodemodeModelInfo,\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"models.getModelOfType\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [type, source, modelId] = args as unknown[];\n\t\t\t\tif (typeof source !== \"string\" || typeof modelId !== \"string\")\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`models.getModelOfType(type, provider, id) expects three strings, got (${(args as unknown[]).map(describeValue).join(\", \")}). The provider and the id are separate arguments, for example models.getModelOfType(\"classifier\", \"typesafe\", \"jev-latest\").`,\n\t\t\t\t\t);\n\t\t\t\tconst model = models.getModelOfType(modelType(type), source, modelId);\n\t\t\t\treturn model ? toCodemodeModelInfo(model) : undefined;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"models.classify\",\n\t\t\tspread: true,\n\t\t\texecute: (args, { signal }) =>\n\t\t\t\trunModelCall(\"models.classify\", \"classifier\", args as unknown[], checkClassifierContext, (model, context) =>\n\t\t\t\t\tmodels.classify(model, context, { signal }),\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\tname: \"models.generateImages\",\n\t\t\tspread: true,\n\t\t\texecute: (args, { signal }) =>\n\t\t\t\trunModelCall(\n\t\t\t\t\t\"models.generateImages\",\n\t\t\t\t\t\"image\",\n\t\t\t\t\targs as unknown[],\n\t\t\t\t\tcheckImagesContext,\n\t\t\t\t\tasync (model, context) => {\n\t\t\t\t\t\tconst result = await models.generateImages(model, context, { signal });\n\t\t\t\t\t\taddGeneratedImages(result.output.filter((block) => block.type === \"image\").length);\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t},\n\t];\n}\n\nexport async function executeCodemode(\n\tid: string,\n\tinput: CodemodeToolInput,\n\tsignal: AbortSignal | undefined,\n\tupdate: ((result: AgentToolResult<CodemodeToolDetails>) => void) | undefined,\n\tctx: ExtensionToolContext | undefined,\n\toptions: CodemodeToolOptions = {},\n): Promise<AgentToolResult<CodemodeToolDetails>> {\n\tconst start = performance.now();\n\tconst { code, options: source } = parseCodemodeSource(input.code);\n\tconst calls: CodemodeNestedCall[] = [];\n\tlet usage: Usage | undefined;\n\tlet generatedImages = 0;\n\tconst snapshot = (): CodemodeToolDetails => ({ calls: calls.map((call) => ({ ...call })) });\n\tconst publish = () => update?.({ content: [], details: snapshot() });\n\tconst callable = ctx ? getCodemodeCallableTools(ctx.tools) : [];\n\tconst guidelines = options.getToolGuidelines?.();\n\tconst samples = new Map(\n\t\tcallable.map((tool) => [tool.name, renderToolSample(toCodemodeDeclaration(tool, guidelines?.get(tool.name)))]),\n\t);\n\tconst sandbox = new CodemodeSandbox({\n\t\ttools: callable.map((tool) => ({\n\t\t\tname: tool.name,\n\t\t\tdescription: samples.get(tool.name),\n\t\t\texecute: async (args, { signal: callSignal }) => {\n\t\t\t\tconst record: CodemodeNestedCall = {\n\t\t\t\t\tid: `${id}/?`,\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\targs: preview(args),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t};\n\t\t\t\tcalls.push(record);\n\t\t\t\tpublish();\n\t\t\t\tconst started = performance.now();\n\t\t\t\tif (!ctx) throw new Error(\"Tool calls need a session\");\n\t\t\t\tconst outcome = await ctx.executeTool(tool.name, args, { signal: callSignal });\n\t\t\t\trecord.id = outcome.toolCall.id;\n\t\t\t\trecord.durationMs = performance.now() - started;\n\t\t\t\trecord.status = outcome.isError ? (callSignal.aborted ? \"cancelled\" : \"error\") : \"ok\";\n\t\t\t\tconst text = textOf(outcome.result);\n\t\t\t\tif (outcome.isError) record.error = (text || `Tool ${tool.name} failed`).slice(0, 500);\n\t\t\t\tpublish();\n\t\t\t\tif (tool.outputSchema && outcome.result.structuredContent !== undefined)\n\t\t\t\t\treturn outcome.result.structuredContent;\n\t\t\t\tif (outcome.isError) throw new Error(text || `Tool ${tool.name} failed`);\n\t\t\t\treturn text;\n\t\t\t},\n\t\t})),\n\t\tglobals: [\n\t\t\t...discoveryGlobals(callable, samples, options),\n\t\t\t...(options.models && ctx\n\t\t\t\t? modelGlobals(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcalls,\n\t\t\t\t\t\tpublish,\n\t\t\t\t\t\t(extra) => {\n\t\t\t\t\t\t\tusage = usage ? combineUsage(usage, extra) : extra;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t(count) => {\n\t\t\t\t\t\t\tgeneratedImages += count;\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t: []),\n\t\t],\n\t\ttimeoutMs: source.timeoutMs ?? Number.POSITIVE_INFINITY,\n\t\tmemoryLimitBytes: 256 * 1024 * 1024,\n\t\twasm: loadQuickJSWasm(getQuickJSWasmPath()),\n\t\tworkerUrl: getCodemodeWorkerUrl(),\n\t});\n\tlet result: CodemodeResult;\n\ttry {\n\t\tresult = await sandbox.execute(code, {\n\t\t\tsignal,\n\t\t\tstore: ctx ? readCodemodeStore(ctx.sessionManager.getBranch()) : {},\n\t\t});\n\t} finally {\n\t\tawait sandbox.close();\n\t}\n\tfor (const call of calls) if (call.status === \"running\") call.status = \"cancelled\";\n\tconst scriptOutput = [...result.output];\n\tif (result.ok) {\n\t\tif (Object.keys(result.storeWrites.set).length || result.storeWrites.delete.length)\n\t\t\toptions.appendEntry?.(CODEMODE_STORE_ENTRY_TYPE, result.storeWrites);\n\t\tif (result.value !== undefined)\n\t\t\tscriptOutput.push({\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext:\n\t\t\t\t\ttypeof result.value === \"string\" ? result.value : (JSON.stringify(result.value) ?? String(result.value)),\n\t\t\t});\n\t}\n\tlet content = formatOutput(scriptOutput);\n\tif (!result.ok)\n\t\tcontent.push({\n\t\t\ttype: \"text\",\n\t\t\ttext: `Script error:\\n${result.error.stack ?? result.error.message}\\n\\nTool calls made before the failure (they are not undone): ${calls.map((call) => `${call.name} (${call.status})`).join(\", \") || \"none\"}`,\n\t\t});\n\tif (generatedImages > 0 && !content.some((block) => block.type === \"image\"))\n\t\tcontent.push({\n\t\t\ttype: \"text\",\n\t\t\ttext: `Note: models.generateImages() returned ${generatedImages} image${generatedImages === 1 ? \"\" : \"s\"} that the script did not show. Show each image block of result.output with image(block).`,\n\t\t});\n\tcontent = joinAdjacentText(content);\n\tconst text = content\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n\tconst budget = (source.maxOutputTokens ?? 10_000) * 4;\n\tconst details = snapshot();\n\tif (text.length > budget) {\n\t\tlet path: string;\n\t\tlet notice: string;\n\t\ttry {\n\t\t\tpath = await writeOutputFile(\"atomic-codemode\", \".txt\", text);\n\t\t\tdetails.fullOutputPath = path;\n\t\t\tnotice = `Full output: ${path}`;\n\t\t} catch (error) {\n\t\t\tnotice = `Could not save full output: ${error instanceof Error ? error.message : String(error)}`;\n\t\t}\n\t\tconst head = Math.floor(budget / 2);\n\t\tconst tail = budget - head;\n\t\tcontent = [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `Warning: truncated output (original token count: ${Math.ceil(text.length / 4)})\\n${text.slice(0, head)}\\n... output truncated ...\\n${tail ? text.slice(-tail) : \"\"}\\n${notice}`,\n\t\t\t},\n\t\t\t...content.filter((block) => block.type === \"image\"),\n\t\t];\n\t}\n\t// Save after truncation so labels cannot be cut or separated from their images.\n\tcontent = joinAdjacentText(await saveImages(content));\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `${result.ok ? \"Script completed\" : \"Script failed\"}\\nWall time ${((performance.now() - start) / 1000).toFixed(1)} seconds\\nOutput:\\n`,\n\t\t\t},\n\t\t\t...content,\n\t\t],\n\t\tdetails,\n\t\t...(usage ? { usage } : {}),\n\t\t...(result.ok ? {} : { isError: true }),\n\t};\n}\n"]}
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/extensions/codemode/execute.ts"],"names":[],"mappings":"AAWA,OAAO,EAGN,eAAe,EAEf,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAI3E,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EACN,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAKlB,wBAAwB,EACxB,qBAAqB,GACrB,MAAM,WAAW,CAAC;AAEnB,MAAM,gBAAgB,GAA2B;IAChD,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,OAAO;CACrB,CAAC;AAEF,KAAK,UAAU,UAAU,CAAC,KAAqC;IAC9D,MAAM,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;IAClD,MAAM,KAAK,GAAG,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAgB,EAAmB,EAAE;QACzE,MAAM,KAAK,GAAG,MAAM,CAAC,IAA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AAU,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,OAAO;QACN,OAAO,EAAE;YACR;gBACC,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,eAAe,eAAe,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB;aAC5I;YACD,GAAG,OAAO;SACV;QACD,OAAO;QACP,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;KACvC,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAnyModel,\n\tClassifierContext,\n\tImageContent,\n\tImagesContext,\n\tModelType,\n\tModelTypeMap,\n\tTextContent,\n\tUsage,\n} from \"@bastani/pi-ai\";\nimport type { AgentTool, AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype CodemodeOutputItem,\n\ttype CodemodeResult,\n\tCodemodeSandbox,\n\ttype CodemodeTool,\n\tloadQuickJSWasm,\n\tparseCodemodeSource,\n\trenderToolSample,\n\ttoCodemodeIdentifier,\n} from \"@earendil-works/pi-codemode\";\nimport { getCodemodeWorkerUrl, getQuickJSWasmPath } from \"../../config.js\";\nimport type { ExtensionToolContext } from \"../../core/extensions/context-types.ts\";\nimport type { ToolNamespace } from \"../../core/extensions/tool-types.ts\";\nimport type { SessionEntry } from \"../../core/session-manager.ts\";\nimport { formatSize } from \"../../core/tools/truncate.ts\";\nimport { combineUsage } from \"../../core/usage-totals.ts\";\nimport { writeOutputFile } from \"../../utils/output-files.js\";\nimport { Bm25Ranker, createToolSearchDocument, DEFAULT_TOOL_SEARCH_LIMIT } from \"../tool-search/tool.js\";\nimport {\n\tCODEMODE_DOCS_PATH,\n\tCODEMODE_STORE_ENTRY_TYPE,\n\tCODEMODE_TOOL_NAME,\n\ttype CodemodeNestedCall,\n\ttype CodemodeToolDetails,\n\ttype CodemodeToolInput,\n\ttype CodemodeToolOptions,\n\tgetCodemodeCallableTools,\n\ttoCodemodeDeclaration,\n} from \"./tool.js\";\n\nconst IMAGE_EXTENSIONS: Record<string, string> = {\n\t\"image/png\": \".png\",\n\t\"image/jpeg\": \".jpg\",\n\t\"image/gif\": \".gif\",\n\t\"image/webp\": \".webp\",\n};\n\nasync function saveImages(items: (TextContent | ImageContent)[]): Promise<(TextContent | ImageContent)[]> {\n\tconst labels = new Map<string, Promise<string>>();\n\tconst label = async ({ data, mimeType }: ImageContent): Promise<string> => {\n\t\tconst bytes = Buffer.from(data, \"base64\");\n\t\tconst kind = `${mimeType}, ${formatSize(bytes.length)}`;\n\t\tconst extension = IMAGE_EXTENSIONS[mimeType];\n\t\tif (!extension) throw new Error(`No file extension for image type ${mimeType}`);\n\t\ttry {\n\t\t\tconst path = await writeOutputFile(\"atomic-codemode\", extension, bytes);\n\t\t\treturn `[Image saved to ${path} (${kind})]`;\n\t\t} catch (error) {\n\t\t\treturn `[Image (${kind}) could not be saved: ${error instanceof Error ? error.message : String(error)}]`;\n\t\t}\n\t};\n\tconst result = await Promise.all(\n\t\titems.map(async (item): Promise<(TextContent | ImageContent)[]> => {\n\t\t\tif (item.type !== \"image\") return [item];\n\t\t\tlet pending = labels.get(item.data);\n\t\t\tif (!pending) {\n\t\t\t\tpending = label(item);\n\t\t\t\tlabels.set(item.data, pending);\n\t\t\t}\n\t\t\treturn [{ type: \"text\", text: await pending }, item];\n\t\t}),\n\t);\n\treturn result.flat();\n}\n\nexport function readCodemodeStore(branch: readonly SessionEntry[]): Record<string, unknown> {\n\tconst store = new Map<string, unknown>();\n\tfor (const entry of branch) {\n\t\tif (\n\t\t\tentry.type !== \"custom\" ||\n\t\t\tentry.customType !== CODEMODE_STORE_ENTRY_TYPE ||\n\t\t\ttypeof entry.data !== \"object\" ||\n\t\t\tentry.data === null\n\t\t)\n\t\t\tcontinue;\n\t\tconst data = entry.data as { set?: Record<string, unknown>; delete?: string[] };\n\t\tif (\n\t\t\t!data.set ||\n\t\t\ttypeof data.set !== \"object\" ||\n\t\t\t!Array.isArray(data.delete) ||\n\t\t\t!data.delete.every((key) => typeof key === \"string\")\n\t\t)\n\t\t\tcontinue;\n\t\tfor (const key of data.delete) store.delete(key);\n\t\tfor (const [key, value] of Object.entries(data.set)) store.set(key, value);\n\t}\n\treturn Object.fromEntries(store);\n}\nfunction textOf(result: AgentToolResult<unknown>): string {\n\treturn result.content\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n}\n/** Explicit public catalog fields. Provider configuration and credential-bearing URLs never cross into the VM. */\nexport function toCodemodeModelInfo(model: AnyModel): Record<string, unknown> {\n\treturn {\n\t\ttype: model.type,\n\t\tprovider: model.provider,\n\t\tid: model.id,\n\t\tname: model.name,\n\t\tapi: model.api,\n\t\tinput: model.input,\n\t\t...(\"reasoning\" in model ? { reasoning: model.reasoning } : {}),\n\t\t...(\"contextWindow\" in model ? { contextWindow: model.contextWindow } : {}),\n\t\t...(\"maxTokens\" in model ? { maxTokens: model.maxTokens } : {}),\n\t\tcost: model.cost,\n\t};\n}\n/** Separate text items and collect console calls after the script's other output. */\nfunction formatOutput(output: readonly CodemodeOutputItem[]): (TextContent | ImageContent)[] {\n\tconst total = output.filter((item) => item.type === \"text\" && !item.console).length;\n\tconst items: (TextContent | ImageContent)[] = [];\n\tconst consoleLines: string[] = [];\n\tlet index = 0;\n\tfor (const item of output) {\n\t\tif (item.type === \"image\") items.push(item);\n\t\telse if (item.console) consoleLines.push(item.text);\n\t\telse {\n\t\t\tindex++;\n\t\t\titems.push({ type: \"text\", text: total > 1 ? `==> text ${index}/${total} <==\\n${item.text}` : item.text });\n\t\t}\n\t}\n\tif (consoleLines.length > 0)\n\t\titems.push({ type: \"text\", text: `<console_output>\\n${consoleLines.join(\"\\n\")}\\n</console_output>` });\n\treturn items;\n}\n\n/** Providers may concatenate adjacent text blocks without a separator. */\nfunction joinAdjacentText(items: (TextContent | ImageContent)[]): (TextContent | ImageContent)[] {\n\tconst joined: (TextContent | ImageContent)[] = [];\n\tlet parts: string[] = [];\n\tlet lastPart = \"\";\n\tconst flush = () => {\n\t\tif (parts.length > 0) joined.push({ type: \"text\", text: parts.join(\"\") });\n\t\tparts = [];\n\t\tlastPart = \"\";\n\t};\n\tfor (const item of items) {\n\t\tif (item.type !== \"text\") {\n\t\t\tflush();\n\t\t\tjoined.push(item);\n\t\t\tcontinue;\n\t\t}\n\t\tif (lastPart !== \"\" && !lastPart.endsWith(\"\\n\")) {\n\t\t\tparts.push(\"\\n\");\n\t\t\tlastPart = \"\\n\";\n\t\t}\n\t\tparts.push(item.text);\n\t\tif (item.text !== \"\") lastPart = item.text;\n\t}\n\tflush();\n\treturn joined;\n}\n\nconst MODEL_TYPES = [\"chat\", \"image\", \"classifier\"] as const;\nfunction modelType(value: unknown): ModelType {\n\tif (value === \"chat\" || value === \"image\" || value === \"classifier\") return value;\n\tthrow new Error('Model type must be \"chat\", \"image\", or \"classifier\"');\n}\nfunction withArticle(word: string): string {\n\treturn `${/^[aeiou]/.test(word) ? \"an\" : \"a\"} ${word}`;\n}\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction describeValue(value: unknown): string {\n\tif (value === undefined || value === null) return String(value);\n\tif (Array.isArray(value)) return value.length === 0 ? \"an empty array\" : \"an array\";\n\tif (typeof value === \"object\") {\n\t\tconst keys = Object.keys(value);\n\t\tif (keys.length === 0) return \"{}\";\n\t\treturn `{ ${keys.slice(0, 6).join(\", \")}${keys.length > 6 ? \", ...\" : \"\"} }`;\n\t}\n\treturn typeof value === \"string\" ? \"a string\" : `a ${typeof value}`;\n}\nconst CLASSIFIER_CONTEXT_SHAPE =\n\t'{ state: { ... }, images?: [{ type: \"image\", data: <base64>, mimeType }], questions: { <id>: { type: \"choice\", instructions, criteria: { <label>: <meaning> } } | { type: \"score\", instructions, criteria: [<lowest level>, ..., <highest level>] } | { type: \"bool\", instructions, criteria: { true: <meaning>, false: <meaning> } } } }';\nfunction checkClassifierContext(context: unknown): ClassifierContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(\n\t\t\t`models.classify() ${problem}. Expected context: ${CLASSIFIER_CONTEXT_SHAPE}. See \"Classify\" in ${CODEMODE_DOCS_PATH}.`,\n\t\t);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tif (!isRecord(context.state)) throw fail(`context.state must be an object, got ${describeValue(context.state)}`);\n\tconst { images } = context;\n\tif (images !== undefined) {\n\t\tif (!Array.isArray(images)) throw fail(`context.images must be an array, got ${describeValue(images)}`);\n\t\timages.forEach((image, index) => {\n\t\t\tif (\n\t\t\t\t!isRecord(image) ||\n\t\t\t\timage.type !== \"image\" ||\n\t\t\t\ttypeof image.data !== \"string\" ||\n\t\t\t\ttypeof image.mimeType !== \"string\"\n\t\t\t) {\n\t\t\t\tthrow fail(`context.images[${index}] must be an image block, got ${describeValue(image)}`);\n\t\t\t}\n\t\t});\n\t}\n\tconst { questions } = context;\n\tif (!isRecord(questions) || Object.keys(questions).length === 0)\n\t\tthrow fail(`context.questions must map question IDs to questions, got ${describeValue(questions)}`);\n\tconst isStrings = (values: unknown[]) => values.length > 0 && values.every((value) => typeof value === \"string\");\n\tfor (const [questionId, question] of Object.entries(questions)) {\n\t\tconst at = `context.questions.${questionId}`;\n\t\tif (!isRecord(question)) throw fail(`${at} must be a question object, got ${describeValue(question)}`);\n\t\tif (typeof question.instructions !== \"string\") throw fail(`${at}.instructions must be a string`);\n\t\tconst { criteria } = question;\n\t\tif (question.type === \"choice\") {\n\t\t\tif (!isRecord(criteria) || !isStrings(Object.values(criteria)))\n\t\t\t\tthrow fail(`${at} is a \"choice\" question, so criteria must map each label to its meaning`);\n\t\t} else if (question.type === \"score\") {\n\t\t\tif (!Array.isArray(criteria) || !isStrings(criteria))\n\t\t\t\tthrow fail(`${at} is a \"score\" question, so criteria must list the levels as strings, lowest first`);\n\t\t} else if (question.type === \"bool\") {\n\t\t\tif (!isRecord(criteria) || typeof criteria.true !== \"string\" || typeof criteria.false !== \"string\")\n\t\t\t\tthrow fail(`${at} is a \"bool\" question, so criteria must be { true: string, false: string }`);\n\t\t} else {\n\t\t\tthrow fail(`${at}.type must be \"choice\", \"score\", or \"bool\", got ${JSON.stringify(question.type)}`);\n\t\t}\n\t}\n\treturn context as unknown as ClassifierContext;\n}\nfunction checkImagesContext(context: unknown): ImagesContext {\n\tconst fail = (problem: string) =>\n\t\tnew Error(\n\t\t\t`models.generateImages() ${problem}. Expected context: { input: [{ type: \"text\", text: <prompt> }, ...optional { type: \"image\", data: <base64>, mimeType } references] }. See \"Generate images\" in ${CODEMODE_DOCS_PATH}.`,\n\t\t);\n\tif (!isRecord(context)) throw fail(`expects a context object as its second argument, got ${describeValue(context)}`);\n\tconst { input } = context;\n\tif (!Array.isArray(input) || input.length === 0)\n\t\tthrow fail(`context.input must be a non-empty array of blocks, got ${describeValue(input)}`);\n\tinput.forEach((block: unknown, index) => {\n\t\tif (isRecord(block) && block.type === \"text\" && typeof block.text === \"string\") return;\n\t\tif (\n\t\t\tisRecord(block) &&\n\t\t\tblock.type === \"image\" &&\n\t\t\ttypeof block.data === \"string\" &&\n\t\t\ttypeof block.mimeType === \"string\"\n\t\t)\n\t\t\treturn;\n\t\tthrow fail(`context.input[${index}] must be a text or image block, got ${describeValue(block)}`);\n\t});\n\treturn context as unknown as ImagesContext;\n}\nfunction provider(value: unknown): string | undefined {\n\tif (value === undefined || value === null) return undefined;\n\tif (typeof value === \"string\") return value;\n\tthrow new Error(\"provider must be a string\");\n}\nfunction preview(args: unknown): string {\n\ttry {\n\t\treturn (JSON.stringify(args) ?? \"\").slice(0, 200);\n\t} catch {\n\t\treturn \"\";\n\t}\n}\ninterface ModelCallResult {\n\tstopReason: \"stop\" | \"error\" | \"aborted\";\n\terrorMessage?: string;\n\tusage?: Usage;\n}\nfunction createLimiter(limit: number) {\n\tlet active = 0;\n\tconst waiting: (() => void)[] = [];\n\treturn async <T>(run: () => Promise<T>): Promise<T> => {\n\t\tif (active >= limit) await new Promise<void>((resolve) => waiting.push(resolve));\n\t\tactive++;\n\t\ttry {\n\t\t\treturn await run();\n\t\t} finally {\n\t\t\tactive--;\n\t\t\twaiting.shift()?.();\n\t\t}\n\t};\n}\nfunction discoveryGlobals(\n\ttools: readonly AgentTool[],\n\tsamples: ReadonlyMap<string, string>,\n\toptions: CodemodeToolOptions,\n): CodemodeTool[] {\n\tconst entry = (name: string) => ({ name: toCodemodeIdentifier(name), description: samples.get(name) ?? \"\" });\n\tconst modelOnly = (query: string) => {\n\t\tconst wanted = query.trim().toLowerCase();\n\t\tconst name = options\n\t\t\t.getModelOnlyTools?.()\n\t\t\t.find(\n\t\t\t\t(name) =>\n\t\t\t\t\tname !== CODEMODE_TOOL_NAME &&\n\t\t\t\t\t[name, toCodemodeIdentifier(name)].some((candidate) => candidate.toLowerCase() === wanted),\n\t\t\t);\n\t\treturn name\n\t\t\t? { name, description: `\\`${name}\\` is model-only: call it directly, not from a script.` }\n\t\t\t: undefined;\n\t};\n\treturn [\n\t\t{\n\t\t\tname: \"searchTools\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [query, config] = args as [unknown, { limit?: unknown; namespace?: unknown } | undefined];\n\t\t\t\tif (typeof query !== \"string\") throw new Error(\"searchTools() expects a query string\");\n\t\t\t\tconst limit = config?.limit ?? DEFAULT_TOOL_SEARCH_LIMIT;\n\t\t\t\tif (typeof limit !== \"number\" || !Number.isInteger(limit) || limit <= 0)\n\t\t\t\t\tthrow new Error(\"searchTools() limit must be a positive integer\");\n\t\t\t\tif (config?.namespace !== undefined && typeof config.namespace !== \"string\")\n\t\t\t\t\tthrow new Error(\"searchTools() namespace must be a string\");\n\t\t\t\tconst docs = tools.flatMap((tool) => {\n\t\t\t\t\tconst namespace = options.getToolNamespace?.(tool.name);\n\t\t\t\t\treturn config?.namespace && namespace?.name !== config.namespace\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: [createToolSearchDocument(tool, namespace)];\n\t\t\t\t});\n\t\t\t\tconst hint = config?.namespace ? undefined : modelOnly(query);\n\t\t\t\tconst matches = new Bm25Ranker().rank(query, docs, limit).map((match) => entry(match.name));\n\t\t\t\treturn hint ? [hint, ...matches].slice(0, limit) : matches;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"describeTool\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [name] = args as unknown[];\n\t\t\t\tif (typeof name !== \"string\") throw new Error(\"describeTool() expects a tool name\");\n\t\t\t\tconst tool = tools.find((tool) => tool.name === name || toCodemodeIdentifier(tool.name) === name);\n\t\t\t\treturn tool ? samples.get(tool.name) : modelOnly(name)?.description;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"describeNamespace\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [name] = args as unknown[];\n\t\t\t\tif (typeof name !== \"string\") throw new Error(\"describeNamespace() expects a namespace name\");\n\t\t\t\tlet namespace: ToolNamespace | undefined;\n\t\t\t\tconst names: string[] = [];\n\t\t\t\tfor (const tool of tools) {\n\t\t\t\t\tconst toolNamespace = options.getToolNamespace?.(tool.name);\n\t\t\t\t\tif (toolNamespace?.name !== name) continue;\n\t\t\t\t\tnamespace ??= toolNamespace;\n\t\t\t\t\tnames.push(toCodemodeIdentifier(tool.name));\n\t\t\t\t}\n\t\t\t\tif (!namespace) return undefined;\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\t...(namespace.description ? { description: namespace.description } : {}),\n\t\t\t\t\t...(namespace.instructions ? { instructions: namespace.instructions } : {}),\n\t\t\t\t\ttools: names,\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t];\n}\nfunction modelGlobals(\n\tctx: ExtensionToolContext,\n\tid: string,\n\tcalls: CodemodeNestedCall[],\n\tpublish: () => void,\n\taddUsage: (usage: Usage) => void,\n\taddGeneratedImages: (count: number) => void,\n): CodemodeTool[] {\n\tconst models = ctx.modelRegistry;\n\tconst limit = createLimiter(4);\n\tlet count = 0;\n\tconst runModelCall = async <TType extends \"classifier\" | \"image\", TContext, TResult extends ModelCallResult>(\n\t\tname: string,\n\t\ttype: TType,\n\t\t[ref, context]: unknown[],\n\t\tcheckContext: (context: unknown) => TContext,\n\t\trun: (model: ModelTypeMap[TType], context: TContext) => Promise<TResult>,\n\t): Promise<TResult> => {\n\t\tconst listHint = `List the ${type} models you can use with models.getAvailableOfType(\"${type}\").`;\n\t\tif (!isRecord(ref) || typeof ref.provider !== \"string\" || typeof ref.id !== \"string\") {\n\t\t\tconst undefinedHint =\n\t\t\t\tref === undefined || ref === null\n\t\t\t\t\t? \" models.getModelOfType() returns undefined for an unknown provider or id.\"\n\t\t\t\t\t: \"\";\n\t\t\tthrow new Error(\n\t\t\t\t`${name}() expects ${withArticle(type)} model as its first argument, got ${describeValue(ref)}.${undefinedHint} ${listHint}`,\n\t\t\t);\n\t\t}\n\t\tconst { provider: providerId, id: modelId } = ref;\n\t\tconst model = models.getModelOfType(type, providerId, modelId);\n\t\tif (!model) {\n\t\t\tconst actualType = MODEL_TYPES.find(\n\t\t\t\t(other) => other !== type && models.getModelOfType(other, providerId, modelId) !== undefined,\n\t\t\t);\n\t\t\tthrow new Error(\n\t\t\t\tactualType\n\t\t\t\t\t? `\"${providerId}/${modelId}\" is ${withArticle(actualType)} model, not ${withArticle(type)} model. ${listHint}`\n\t\t\t\t\t: `Unknown ${type} model \"${providerId}/${modelId}\". ${listHint}`,\n\t\t\t);\n\t\t}\n\t\tconst checked = checkContext(context);\n\t\tconst record: CodemodeNestedCall = {\n\t\t\tid: `${id}/${name}/${++count}`,\n\t\t\tname,\n\t\t\targs: `${model.provider}/${model.id}`,\n\t\t\tstatus: \"running\",\n\t\t};\n\t\tcalls.push(record);\n\t\tpublish();\n\t\tconst start = performance.now();\n\t\tconst result = await limit(() => run(model, checked));\n\t\trecord.durationMs = performance.now() - start;\n\t\trecord.status = result.stopReason === \"stop\" ? \"ok\" : result.stopReason === \"aborted\" ? \"cancelled\" : \"error\";\n\t\tif (result.errorMessage) record.error = result.errorMessage.slice(0, 500);\n\t\tif (result.usage) {\n\t\t\trecord.cost = result.usage.cost.total;\n\t\t\taddUsage(result.usage);\n\t\t}\n\t\tpublish();\n\t\treturn result;\n\t};\n\treturn [\n\t\t{\n\t\t\tname: \"models.getModelsOfType\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [type, source] = args as unknown[];\n\t\t\t\treturn models.getModelsOfType(modelType(type), provider(source)).map(toCodemodeModelInfo);\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"models.getAvailableOfType\",\n\t\t\tspread: true,\n\t\t\texecute: async (args, { signal }) => {\n\t\t\t\tconst [type, source] = args as unknown[];\n\t\t\t\treturn (await models.getAvailableOfType(modelType(type), provider(source), { signal })).map(\n\t\t\t\t\ttoCodemodeModelInfo,\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"models.getModelOfType\",\n\t\t\tspread: true,\n\t\t\texecute: (args) => {\n\t\t\t\tconst [type, source, modelId] = args as unknown[];\n\t\t\t\tif (typeof source !== \"string\" || typeof modelId !== \"string\")\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`models.getModelOfType(type, provider, id) expects three strings, got (${(args as unknown[]).map(describeValue).join(\", \")}). The provider and the id are separate arguments, for example models.getModelOfType(\"classifier\", \"typesafe\", \"jev-latest\").`,\n\t\t\t\t\t);\n\t\t\t\tconst model = models.getModelOfType(modelType(type), source, modelId);\n\t\t\t\treturn model ? toCodemodeModelInfo(model) : undefined;\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"models.classify\",\n\t\t\tspread: true,\n\t\t\texecute: (args, { signal }) =>\n\t\t\t\trunModelCall(\"models.classify\", \"classifier\", args as unknown[], checkClassifierContext, (model, context) =>\n\t\t\t\t\tmodels.classify(model, context, { signal }),\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\tname: \"models.generateImages\",\n\t\t\tspread: true,\n\t\t\texecute: (args, { signal }) =>\n\t\t\t\trunModelCall(\n\t\t\t\t\t\"models.generateImages\",\n\t\t\t\t\t\"image\",\n\t\t\t\t\targs as unknown[],\n\t\t\t\t\tcheckImagesContext,\n\t\t\t\t\tasync (model, context) => {\n\t\t\t\t\t\tconst result = await models.generateImages(model, context, { signal });\n\t\t\t\t\t\taddGeneratedImages(result.output.filter((block) => block.type === \"image\").length);\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t},\n\t];\n}\n\nexport async function executeCodemode(\n\tid: string,\n\tinput: CodemodeToolInput,\n\tsignal: AbortSignal | undefined,\n\tupdate: ((result: AgentToolResult<CodemodeToolDetails>) => void) | undefined,\n\tctx: ExtensionToolContext | undefined,\n\toptions: CodemodeToolOptions = {},\n): Promise<AgentToolResult<CodemodeToolDetails>> {\n\tconst start = performance.now();\n\tconst { code, options: source } = parseCodemodeSource(input.code);\n\tconst calls: CodemodeNestedCall[] = [];\n\tlet usage: Usage | undefined;\n\tlet generatedImages = 0;\n\tconst snapshot = (): CodemodeToolDetails => ({ calls: calls.map((call) => ({ ...call })) });\n\tconst publish = () => update?.({ content: [], details: snapshot() });\n\t// Show the script as running before its first nested call, so the row's timer starts.\n\tpublish();\n\tconst callable = ctx ? getCodemodeCallableTools(ctx.tools) : [];\n\tconst guidelines = options.getToolGuidelines?.();\n\tconst samples = new Map(\n\t\tcallable.map((tool) => [tool.name, renderToolSample(toCodemodeDeclaration(tool, guidelines?.get(tool.name)))]),\n\t);\n\tconst sandbox = new CodemodeSandbox({\n\t\ttools: callable.map((tool) => ({\n\t\t\tname: tool.name,\n\t\t\tdescription: samples.get(tool.name),\n\t\t\texecute: async (args, { signal: callSignal }) => {\n\t\t\t\tconst record: CodemodeNestedCall = {\n\t\t\t\t\tid: `${id}/?`,\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\targs: preview(args),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t};\n\t\t\t\tcalls.push(record);\n\t\t\t\tpublish();\n\t\t\t\tconst started = performance.now();\n\t\t\t\tif (!ctx) throw new Error(\"Tool calls need a session\");\n\t\t\t\tconst outcome = await ctx.executeTool(tool.name, args, { signal: callSignal });\n\t\t\t\trecord.id = outcome.toolCall.id;\n\t\t\t\trecord.durationMs = performance.now() - started;\n\t\t\t\trecord.status = outcome.isError ? (callSignal.aborted ? \"cancelled\" : \"error\") : \"ok\";\n\t\t\t\tconst text = textOf(outcome.result);\n\t\t\t\tif (outcome.isError) record.error = (text || `Tool ${tool.name} failed`).slice(0, 500);\n\t\t\t\tpublish();\n\t\t\t\tif (tool.outputSchema && outcome.result.structuredContent !== undefined)\n\t\t\t\t\treturn outcome.result.structuredContent;\n\t\t\t\tif (outcome.isError) throw new Error(text || `Tool ${tool.name} failed`);\n\t\t\t\treturn text;\n\t\t\t},\n\t\t})),\n\t\tglobals: [\n\t\t\t...discoveryGlobals(callable, samples, options),\n\t\t\t...(options.models && ctx\n\t\t\t\t? modelGlobals(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tcalls,\n\t\t\t\t\t\tpublish,\n\t\t\t\t\t\t(extra) => {\n\t\t\t\t\t\t\tusage = usage ? combineUsage(usage, extra) : extra;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t(count) => {\n\t\t\t\t\t\t\tgeneratedImages += count;\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t: []),\n\t\t],\n\t\ttimeoutMs: source.timeoutMs ?? Number.POSITIVE_INFINITY,\n\t\tmemoryLimitBytes: 256 * 1024 * 1024,\n\t\twasm: loadQuickJSWasm(getQuickJSWasmPath()),\n\t\tworkerUrl: getCodemodeWorkerUrl(),\n\t});\n\tlet result: CodemodeResult;\n\ttry {\n\t\tresult = await sandbox.execute(code, {\n\t\t\tsignal,\n\t\t\tstore: ctx ? readCodemodeStore(ctx.sessionManager.getBranch()) : {},\n\t\t});\n\t} finally {\n\t\tawait sandbox.close();\n\t}\n\tfor (const call of calls) if (call.status === \"running\") call.status = \"cancelled\";\n\tconst scriptOutput = [...result.output];\n\tif (result.ok) {\n\t\tif (Object.keys(result.storeWrites.set).length || result.storeWrites.delete.length)\n\t\t\toptions.appendEntry?.(CODEMODE_STORE_ENTRY_TYPE, result.storeWrites);\n\t\tif (result.value !== undefined)\n\t\t\tscriptOutput.push({\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext:\n\t\t\t\t\ttypeof result.value === \"string\" ? result.value : (JSON.stringify(result.value) ?? String(result.value)),\n\t\t\t});\n\t}\n\tlet content = formatOutput(scriptOutput);\n\tif (!result.ok)\n\t\tcontent.push({\n\t\t\ttype: \"text\",\n\t\t\ttext: `Script error:\\n${result.error.stack ?? result.error.message}\\n\\nTool calls made before the failure (they are not undone): ${calls.map((call) => `${call.name} (${call.status})`).join(\", \") || \"none\"}`,\n\t\t});\n\tif (generatedImages > 0 && !content.some((block) => block.type === \"image\"))\n\t\tcontent.push({\n\t\t\ttype: \"text\",\n\t\t\ttext: `Note: models.generateImages() returned ${generatedImages} image${generatedImages === 1 ? \"\" : \"s\"} that the script did not show. Show each image block of result.output with image(block).`,\n\t\t});\n\tcontent = joinAdjacentText(content);\n\tconst text = content\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n\tconst budget = (source.maxOutputTokens ?? 10_000) * 4;\n\tconst details = snapshot();\n\tif (text.length > budget) {\n\t\tlet path: string;\n\t\tlet notice: string;\n\t\ttry {\n\t\t\tpath = await writeOutputFile(\"atomic-codemode\", \".txt\", text);\n\t\t\tdetails.fullOutputPath = path;\n\t\t\tnotice = `Full output: ${path}`;\n\t\t} catch (error) {\n\t\t\tnotice = `Could not save full output: ${error instanceof Error ? error.message : String(error)}`;\n\t\t}\n\t\tconst head = Math.floor(budget / 2);\n\t\tconst tail = budget - head;\n\t\tcontent = [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `Warning: truncated output (original token count: ${Math.ceil(text.length / 4)})\\n${text.slice(0, head)}\\n... output truncated ...\\n${tail ? text.slice(-tail) : \"\"}\\n${notice}`,\n\t\t\t},\n\t\t\t...content.filter((block) => block.type === \"image\"),\n\t\t];\n\t}\n\t// Save after truncation so labels cannot be cut or separated from their images.\n\tcontent = joinAdjacentText(await saveImages(content));\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `${result.ok ? \"Script completed\" : \"Script failed\"}\\nWall time ${((performance.now() - start) / 1000).toFixed(1)} seconds\\nOutput:\\n`,\n\t\t\t},\n\t\t\t...content,\n\t\t],\n\t\tdetails,\n\t\t...(usage ? { usage } : {}),\n\t\t...(result.ok ? {} : { isError: true }),\n\t};\n}\n"]}
@@ -1,4 +1,10 @@
1
1
  import type { ToolDefinition } from "../../core/extensions/types.ts";
2
+ import { type ToolTimerState } from "../../core/tools/render-utils.ts";
2
3
  import type { CodemodeToolDetails, codemodeSchema } from "./tool.js";
3
- export declare const codemodeRenderers: Pick<ToolDefinition<typeof codemodeSchema, CodemodeToolDetails>, "renderCall" | "renderResult">;
4
+ /**
5
+ * The result lists the nested tool calls with their status as they run and the cost of its model calls,
6
+ * followed by the script output without the "Script completed" header, and the time the script has been
7
+ * running (`Elapsed`) or took (`Took`), like bash rows.
8
+ */
9
+ export declare const codemodeRenderers: Pick<ToolDefinition<typeof codemodeSchema, CodemodeToolDetails, ToolTimerState>, "renderCall" | "renderResult">;
4
10
  //# sourceMappingURL=renderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../src/extensions/codemode/renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKrE,OAAO,KAAK,EAAsB,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AA0BzF,eAAO,MAAM,iBAAiB,EAAE,IAAI,CACnC,cAAc,CAAC,OAAO,cAAc,EAAE,mBAAmB,CAAC,EAC1D,YAAY,GAAG,cAAc,CAmE7B,CAAC"}
1
+ {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../src/extensions/codemode/renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAKN,KAAK,cAAc,EAEnB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,KAAK,EAAsB,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AA0BzF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,IAAI,CACnC,cAAc,CAAC,OAAO,cAAc,EAAE,mBAAmB,EAAE,cAAc,CAAC,EAC1E,YAAY,GAAG,cAAc,CAyE7B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Container, Spacer, Text } from "@earendil-works/pi-tui";
2
- import { getTextOutput, replaceTabs, str } from "../../core/tools/render-utils.js";
2
+ import { getTextOutput, replaceTabs, startToolTimer, str, toolTimerText, } from "../../core/tools/render-utils.js";
3
3
  import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
4
4
  import { VisualLinePreview } from "../../modes/interactive/components/visual-truncate.js";
5
5
  import { highlightCode } from "../../modes/interactive/theme/theme.js";
@@ -28,8 +28,14 @@ function formatCall(call, theme, expanded) {
28
28
  text += `\n ${theme.fg("error", call.error.split("\n").join("\n "))}`;
29
29
  return text;
30
30
  }
31
+ /**
32
+ * The result lists the nested tool calls with their status as they run and the cost of its model calls,
33
+ * followed by the script output without the "Script completed" header, and the time the script has been
34
+ * running (`Elapsed`) or took (`Took`), like bash rows.
35
+ */
31
36
  export const codemodeRenderers = {
32
37
  renderCall(args, theme, context) {
38
+ startToolTimer(context);
33
39
  const code = str(args?.code);
34
40
  const title = theme.fg("toolTitle", theme.bold("codemode"));
35
41
  const component = context.lastComponent ?? new Container();
@@ -53,6 +59,7 @@ export const codemodeRenderers = {
53
59
  return component;
54
60
  },
55
61
  renderResult(result, options, theme, context) {
62
+ const timerText = toolTimerText(context, options.isPartial);
56
63
  const component = context.lastComponent ?? new Container();
57
64
  component.clear();
58
65
  const calls = result.details?.calls ?? [];
@@ -87,6 +94,10 @@ export const codemodeRenderers = {
87
94
  if (result.details?.fullOutputPath && !options.expanded)
88
95
  component.addChild(new Text(theme.fg("muted", `Full output: ${result.details.fullOutputPath}`), 0, 0));
89
96
  }
97
+ if (timerText) {
98
+ component.addChild(new Spacer(1));
99
+ component.addChild(new Text(theme.fg("muted", timerText), 0, 0));
100
+ }
90
101
  return component;
91
102
  },
92
103
  };
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../../src/extensions/codemode/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uDAAuD,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAc,MAAM,wCAAwC,CAAC;AAGnF,MAAM,aAAa,GAAG,kEAAkE,CAAC;AACzF,SAAS,IAAI,CAAC,KAAY,EAAE,KAAa,EAAE,IAAY;IACtD,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,IAA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spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { ToolDefinition } from \"../../core/extensions/types.ts\";\nimport { getTextOutput, replaceTabs, str } from \"../../core/tools/render-utils.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { VisualLinePreview } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, type Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { CodemodeNestedCall, CodemodeToolDetails, codemodeSchema } from \"./tool.js\";\n\nconst SCRIPT_HEADER = /^Script (completed|failed)\\nWall time [\\d.]+ seconds\\nOutput:\\n$/;\nfunction hint(theme: Theme, count: number, noun: string): string {\n\treturn `${theme.fg(\"muted\", `... (${count} more ${noun},`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n}\nfunction cost(value: number): string {\n\treturn `$${value >= 0.01 ? value.toFixed(2) : value.toPrecision(2)}`;\n}\nfunction formatCall(call: CodemodeNestedCall, theme: Theme, expanded: boolean): string {\n\tconst icon =\n\t\tcall.status === \"running\"\n\t\t\t? theme.fg(\"warning\", \"…\")\n\t\t\t: call.status === \"ok\"\n\t\t\t\t? theme.fg(\"success\", \"✓\")\n\t\t\t\t: call.status === \"error\"\n\t\t\t\t\t? theme.fg(\"error\", \"✗\")\n\t\t\t\t\t: theme.fg(\"muted\", \"⊘\");\n\tconst args = !expanded && call.args.length > 80 ? `${call.args.slice(0, 77)}...` : call.args;\n\tlet text = `${icon} ${theme.fg(\"toolTitle\", call.name)}${args ? ` ${theme.fg(\"muted\", args)}` : \"\"}`;\n\tif (call.durationMs !== undefined)\n\t\ttext += ` ${theme.fg(\"dim\", call.durationMs < 1000 ? `${Math.round(call.durationMs)}ms` : `${(call.durationMs / 1000).toFixed(1)}s`)}`;\n\tif (call.cost) text += ` ${theme.fg(\"dim\", cost(call.cost))}`;\n\tif (expanded && call.error) text += `\\n ${theme.fg(\"error\", call.error.split(\"\\n\").join(\"\\n \"))}`;\n\treturn text;\n}\nexport const codemodeRenderers: Pick<\n\tToolDefinition<typeof codemodeSchema, CodemodeToolDetails>,\n\t\"renderCall\" | \"renderResult\"\n> = {\n\trenderCall(args, theme, context) {\n\t\tconst code = str(args?.code);\n\t\tconst title = theme.fg(\"toolTitle\", theme.bold(\"codemode\"));\n\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\tcomponent.clear();\n\t\tif (code === null) {\n\t\t\tcomponent.addChild(new Text(`${title} ${theme.fg(\"error\", \"[invalid arg]\")}`, 0, 0));\n\t\t\treturn component;\n\t\t}\n\t\tcomponent.addChild(new Text(title, 0, 0));\n\t\tif (code) {\n\t\t\tconst highlighted = highlightCode(replaceTabs(code.replace(/\\r/g, \"\").trimEnd()), \"javascript\").join(\"\\n\");\n\t\t\tcomponent.addChild(\n\t\t\t\tcontext.expanded\n\t\t\t\t\t? new Text(highlighted, 0, 0)\n\t\t\t\t\t: new VisualLinePreview({\n\t\t\t\t\t\t\ttext: highlighted,\n\t\t\t\t\t\t\tmaxVisualLines: 10,\n\t\t\t\t\t\t\tkeep: \"start\",\n\t\t\t\t\t\t\tformatHint: (hidden) => hint(theme, hidden, \"lines\"),\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn component;\n\t},\n\trenderResult(result, options, theme, context) {\n\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\tcomponent.clear();\n\t\tconst calls = result.details?.calls ?? [];\n\t\tif (calls.length) {\n\t\t\tconst shown = options.expanded ? calls : calls.slice(-8);\n\t\t\tconst lines = shown.map((call) => formatCall(call, theme, options.expanded));\n\t\t\tif (shown.length < calls.length) lines.unshift(hint(theme, calls.length - shown.length, \"earlier calls\"));\n\t\t\tconst priced = calls.filter((call) => call.cost);\n\t\t\tif (priced.length > 1)\n\t\t\t\tlines.push(\n\t\t\t\t\ttheme.fg(\"muted\", `Model calls: ${cost(priced.reduce((sum, call) => sum + (call.cost ?? 0), 0))}`),\n\t\t\t\t);\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(lines.join(\"\\n\"), 0, 0));\n\t\t}\n\t\tconst [first, ...rest] = result.content;\n\t\tconst content = first?.type === \"text\" && SCRIPT_HEADER.test(first.text) ? rest : result.content;\n\t\tconst output = options.isPartial ? \"\" : getTextOutput({ ...result, content }, context.showImages).trim();\n\t\tif (output) {\n\t\t\tconst styled = replaceTabs(output)\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => theme.fg(context.isError ? \"error\" : \"toolOutput\", line))\n\t\t\t\t.join(\"\\n\");\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(\n\t\t\t\toptions.expanded\n\t\t\t\t\t? new Text(styled, 0, 0)\n\t\t\t\t\t: new VisualLinePreview({\n\t\t\t\t\t\t\ttext: styled,\n\t\t\t\t\t\t\tmaxVisualLines: 5,\n\t\t\t\t\t\t\tkeep: \"start\",\n\t\t\t\t\t\t\tformatHint: (hidden) => hint(theme, hidden, \"lines\"),\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (result.details?.fullOutputPath && !options.expanded)\n\t\t\t\tcomponent.addChild(new Text(theme.fg(\"muted\", `Full output: ${result.details.fullOutputPath}`), 0, 0));\n\t\t}\n\t\treturn component;\n\t},\n};\n"]}
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../../src/extensions/codemode/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EACN,aAAa,EACb,WAAW,EACX,cAAc,EACd,GAAG,EAEH,aAAa,GACb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uDAAuD,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAc,MAAM,wCAAwC,CAAC;AAGnF,MAAM,aAAa,GAAG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AE,cAAc,IAAI,CAAC,OAAO,CAAC,QAAQ;gBACtD,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzG,CAAC;QACD,IAAI,SAAS,EAAE,CAAC;YACf,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD,CAAC","sourcesContent":["import { Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { ToolDefinition } from \"../../core/extensions/types.ts\";\nimport {\n\tgetTextOutput,\n\treplaceTabs,\n\tstartToolTimer,\n\tstr,\n\ttype ToolTimerState,\n\ttoolTimerText,\n} from \"../../core/tools/render-utils.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { VisualLinePreview } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, type Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { CodemodeNestedCall, CodemodeToolDetails, codemodeSchema } from \"./tool.js\";\n\nconst SCRIPT_HEADER = /^Script (completed|failed)\\nWall time [\\d.]+ seconds\\nOutput:\\n$/;\nfunction hint(theme: Theme, count: number, noun: string): string {\n\treturn `${theme.fg(\"muted\", `... (${count} more ${noun},`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n}\nfunction cost(value: number): string {\n\treturn `$${value >= 0.01 ? value.toFixed(2) : value.toPrecision(2)}`;\n}\nfunction formatCall(call: CodemodeNestedCall, theme: Theme, expanded: boolean): string {\n\tconst icon =\n\t\tcall.status === \"running\"\n\t\t\t? theme.fg(\"warning\", \"…\")\n\t\t\t: call.status === \"ok\"\n\t\t\t\t? theme.fg(\"success\", \"✓\")\n\t\t\t\t: call.status === \"error\"\n\t\t\t\t\t? theme.fg(\"error\", \"✗\")\n\t\t\t\t\t: theme.fg(\"muted\", \"⊘\");\n\tconst args = !expanded && call.args.length > 80 ? `${call.args.slice(0, 77)}...` : call.args;\n\tlet text = `${icon} ${theme.fg(\"toolTitle\", call.name)}${args ? ` ${theme.fg(\"muted\", args)}` : \"\"}`;\n\tif (call.durationMs !== undefined)\n\t\ttext += ` ${theme.fg(\"dim\", call.durationMs < 1000 ? `${Math.round(call.durationMs)}ms` : `${(call.durationMs / 1000).toFixed(1)}s`)}`;\n\tif (call.cost) text += ` ${theme.fg(\"dim\", cost(call.cost))}`;\n\tif (expanded && call.error) text += `\\n ${theme.fg(\"error\", call.error.split(\"\\n\").join(\"\\n \"))}`;\n\treturn text;\n}\n/**\n * The result lists the nested tool calls with their status as they run and the cost of its model calls,\n * followed by the script output without the \"Script completed\" header, and the time the script has been\n * running (`Elapsed`) or took (`Took`), like bash rows.\n */\nexport const codemodeRenderers: Pick<\n\tToolDefinition<typeof codemodeSchema, CodemodeToolDetails, ToolTimerState>,\n\t\"renderCall\" | \"renderResult\"\n> = {\n\trenderCall(args, theme, context) {\n\t\tstartToolTimer(context);\n\t\tconst code = str(args?.code);\n\t\tconst title = theme.fg(\"toolTitle\", theme.bold(\"codemode\"));\n\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\tcomponent.clear();\n\t\tif (code === null) {\n\t\t\tcomponent.addChild(new Text(`${title} ${theme.fg(\"error\", \"[invalid arg]\")}`, 0, 0));\n\t\t\treturn component;\n\t\t}\n\t\tcomponent.addChild(new Text(title, 0, 0));\n\t\tif (code) {\n\t\t\tconst highlighted = highlightCode(replaceTabs(code.replace(/\\r/g, \"\").trimEnd()), \"javascript\").join(\"\\n\");\n\t\t\tcomponent.addChild(\n\t\t\t\tcontext.expanded\n\t\t\t\t\t? new Text(highlighted, 0, 0)\n\t\t\t\t\t: new VisualLinePreview({\n\t\t\t\t\t\t\ttext: highlighted,\n\t\t\t\t\t\t\tmaxVisualLines: 10,\n\t\t\t\t\t\t\tkeep: \"start\",\n\t\t\t\t\t\t\tformatHint: (hidden) => hint(theme, hidden, \"lines\"),\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn component;\n\t},\n\trenderResult(result, options, theme, context) {\n\t\tconst timerText = toolTimerText(context, options.isPartial);\n\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\tcomponent.clear();\n\t\tconst calls = result.details?.calls ?? [];\n\t\tif (calls.length) {\n\t\t\tconst shown = options.expanded ? calls : calls.slice(-8);\n\t\t\tconst lines = shown.map((call) => formatCall(call, theme, options.expanded));\n\t\t\tif (shown.length < calls.length) lines.unshift(hint(theme, calls.length - shown.length, \"earlier calls\"));\n\t\t\tconst priced = calls.filter((call) => call.cost);\n\t\t\tif (priced.length > 1)\n\t\t\t\tlines.push(\n\t\t\t\t\ttheme.fg(\"muted\", `Model calls: ${cost(priced.reduce((sum, call) => sum + (call.cost ?? 0), 0))}`),\n\t\t\t\t);\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(lines.join(\"\\n\"), 0, 0));\n\t\t}\n\t\tconst [first, ...rest] = result.content;\n\t\tconst content = first?.type === \"text\" && SCRIPT_HEADER.test(first.text) ? rest : result.content;\n\t\tconst output = options.isPartial ? \"\" : getTextOutput({ ...result, content }, context.showImages).trim();\n\t\tif (output) {\n\t\t\tconst styled = replaceTabs(output)\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => theme.fg(context.isError ? \"error\" : \"toolOutput\", line))\n\t\t\t\t.join(\"\\n\");\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(\n\t\t\t\toptions.expanded\n\t\t\t\t\t? new Text(styled, 0, 0)\n\t\t\t\t\t: new VisualLinePreview({\n\t\t\t\t\t\t\ttext: styled,\n\t\t\t\t\t\t\tmaxVisualLines: 5,\n\t\t\t\t\t\t\tkeep: \"start\",\n\t\t\t\t\t\t\tformatHint: (hidden) => hint(theme, hidden, \"lines\"),\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (result.details?.fullOutputPath && !options.expanded)\n\t\t\t\tcomponent.addChild(new Text(theme.fg(\"muted\", `Full output: ${result.details.fullOutputPath}`), 0, 0));\n\t\t}\n\t\tif (timerText) {\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(theme.fg(\"muted\", timerText), 0, 0));\n\t\t}\n\t\treturn component;\n\t},\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/extensions/codemode/tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAQpF,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAe,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC3G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAInE,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,eAAO,MAAM,kBAAkB,QAAqC,CAAC;AACrE,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAC1D,eAAO,MAAM,8BAA8B,EAAE,MAAgD,CAAC;AAC9F,MAAM,WAAW,sBAAsB;IACtC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;CAC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AO,EAChC,OAAO,GAAE,mBAAwB,GAC/B,SAAS,CAAC,OAAO,cAAc,CAAC,CAKlC"}
@@ -1,5 +1,5 @@
1
1
  import { join } from "node:path";
2
- import { mcpStructuredContentSchema, renderToolOutputType, renderToolSample, toCodemodeIdentifier, } from "@earendil-works/pi-codemode/declarations";
2
+ import { renderToolOutputType, renderToolSample, toCodemodeIdentifier } from "@earendil-works/pi-codemode/declarations";
3
3
  import { CODEMODE_SOURCE_GRAMMAR } from "@earendil-works/pi-codemode/source";
4
4
  import { Type } from "typebox";
5
5
  import { getDocsPath } from "../../config.js";
@@ -102,21 +102,34 @@ export function createCodemodeDescription(tools, options = {}) {
102
102
  }
103
103
  return sections.join("\n\n");
104
104
  }
105
+ /**
106
+ * The field names of an object schema, `{ output, exit_code, full_output_path? }`, with the fields of
107
+ * object-typed fields `depth` levels deep: `{ content, structuredContent?: { results } }`. Undefined
108
+ * for other schemas.
109
+ */
110
+ function describeFields(schema, depth) {
111
+ if (typeof schema !== "object" || schema === null)
112
+ return undefined;
113
+ const { type, properties, required } = schema;
114
+ if (type !== "object" || typeof properties !== "object" || properties === null)
115
+ return undefined;
116
+ const requiredNames = new Set(Array.isArray(required) ? required : []);
117
+ const fields = Object.entries(properties).map(([name, field]) => {
118
+ const nested = depth > 0 ? describeFields(field, depth - 1) : undefined;
119
+ return `${name}${requiredNames.has(name) ? "" : "?"}${nested ? `: ${nested}` : ""}`;
120
+ });
121
+ return `{ ${fields.join(", ")} }`;
122
+ }
123
+ /**
124
+ * What a script call resolves to, in one line: `a string`, the field names of an object (see
125
+ * {@link describeFields}), or the rendered type for anything else.
126
+ */
105
127
  function describeOutput(schema) {
106
128
  const type = renderToolOutputType(schema);
107
129
  if (type === "string")
108
130
  return "a string";
109
- const object = typeof schema === "object" ? schema : undefined;
110
- const properties = object?.properties;
111
- if (object?.type === "object" &&
112
- typeof properties === "object" &&
113
- properties !== null &&
114
- mcpStructuredContentSchema(schema) === undefined) {
115
- const required = new Set(Array.isArray(object.required) ? object.required : []);
116
- const fields = Object.keys(properties).map((name) => (required.has(name) ? name : `${name}?`));
117
- return `\`{ ${fields.join(", ")} }\``;
118
- }
119
- return `\`${type.replace(/\s+/g, " ")}\``;
131
+ const fields = describeFields(schema, 1);
132
+ return `\`${fields ?? type.replace(/\s+/g, " ")}\``;
120
133
  }
121
134
  function describeScriptCall(tool) {
122
135
  return `${tool.description.trim()}\n\nCodemode: \`tools.${toCodemodeIdentifier(tool.name)}(args)\` resolves to ${describeOutput(toCodemodeDeclaration(tool).outputSchema)}.`;
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/codemode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EACN,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,WAAW,EAAE,EAAE,aAAa,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;AAC1D,MAAM,CAAC,MAAM,8BAA8B,GAAW,iBAAiB,CAAC,QAAQ,CAAC,YAAY,CAAC;AAoB9F,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,I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M,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC;QACxF,GAAG,iBAAiB;KACpB,CAAC;AACH,CAAC;AACD,MAAM,UAAU,kBAAkB,CACjC,KAAK,GAAyB,EAAE,EAChC,OAAO,GAAwB,EAAE;IAEjC,OAAO;QACN,GAAG,kBAAkB,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC;QAC5D,WAAW,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC;KACtD,CAAC;AACH,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { CodemodeJsonSchema, CodemodeTool } from \"@earendil-works/pi-codemode\";\nimport {\n\tmcpStructuredContentSchema,\n\trenderToolOutputType,\n\trenderToolSample,\n\ttoCodemodeIdentifier,\n} from \"@earendil-works/pi-codemode/declarations\";\nimport { CODEMODE_SOURCE_GRAMMAR } from \"@earendil-works/pi-codemode/source\";\nimport { type Static, Type } from \"typebox\";\nimport { getDocsPath } from \"../../config.js\";\nimport type { ToolDefinition, ToolInfo, ToolLoadout, ToolNamespace } from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { SETTINGS_DEFAULTS } from \"../../core/settings-defaults.ts\";\nimport type { CodemodeMode } from \"../../core/settings-manager.ts\";\nimport { wrapToolDefinition } from \"../../core/tools/tool-definition-wrapper.ts\";\nimport { codemodeRenderers } from \"./renderer.js\";\n\nexport const CODEMODE_TOOL_NAME = \"codemode\";\nexport const CODEMODE_DOCS_PATH = join(getDocsPath(), \"codemode.md\");\nexport const CODEMODE_STORE_ENTRY_TYPE = \"codemode-store\";\nexport const DEFAULT_CODEMODE_INLINE_BUDGET: number = SETTINGS_DEFAULTS.codemode.inlineBudget;\nexport interface CodemodeStoreEntryData {\n\tset: Record<string, unknown>;\n\tdelete: string[];\n}\nexport type CodemodeModelRuntime = Pick<\n\tModelRegistry,\n\t\"getModelsOfType\" | \"getAvailableOfType\" | \"getModelOfType\" | \"classify\" | \"generateImages\"\n>;\nexport interface CodemodeToolOptions {\n\tgetToolNamespace?: (name: string) => ToolNamespace | undefined;\n\t/** Prompt guidelines shown with tool declarations in describeTool() and ALL_TOOLS. */\n\tgetToolGuidelines?: () => ReadonlyMap<string, readonly string[]>;\n\tmodels?: boolean;\n\tappendEntry?: (type: string, data: CodemodeStoreEntryData) => void;\n\tgetMode?: () => CodemodeMode;\n\tgetInlineBudget?: () => number | undefined;\n\t/** Active model-only tools. Scripts cannot call them, so discovery answers an exact name with a hint. */\n\tgetModelOnlyTools?: () => readonly string[];\n}\nexport const codemodeSchema = Type.Object({\n\tcode: Type.String({\n\t\tdescription:\n\t\t\t'Raw JavaScript source with top-level await and return. Optional first line // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}',\n\t}),\n});\nexport type CodemodeToolInput = Static<typeof codemodeSchema>;\nexport function isCodemodeTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === CODEMODE_TOOL_NAME && tool.parameters === codemodeSchema;\n}\nexport interface CodemodeNestedCall {\n\tid: string;\n\tname: string;\n\targs: string;\n\tstatus: \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\tdurationMs?: number;\n\terror?: string;\n\tcost?: number;\n}\nexport interface CodemodeToolDetails {\n\tcalls: CodemodeNestedCall[];\n\tfullOutputPath?: string;\n}\nexport function toCodemodeDeclaration(\n\ttool: AgentTool,\n\tguidelines: readonly string[] = [],\n): Omit<CodemodeTool, \"execute\"> {\n\tconst bullets = guidelines.flatMap((guideline) => (guideline.trim() ? [`- ${guideline.trim()}`] : []));\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: bullets.length > 0 ? `${tool.description.trim()}\\n\\n${bullets.join(\"\\n\")}` : tool.description,\n\t\tinputSchema: tool.parameters as CodemodeJsonSchema,\n\t\toutputSchema: (tool.outputSchema as CodemodeJsonSchema | undefined) ?? { type: \"string\" },\n\t};\n}\nexport function getCodemodeCallableTools(tools: readonly AgentTool[]): AgentTool[] {\n\treturn tools.filter((tool) => tool.name !== CODEMODE_TOOL_NAME);\n}\nexport interface CodemodeDescriptionOptions {\n\tmodels?: boolean;\n\tnamespaces?: ReadonlyMap<string, ToolNamespace>;\n\tdeferred?: ReadonlySet<string>;\n\tguidelines?: ReadonlyMap<string, readonly string[]>;\n\tinlineBudget?: number;\n}\nconst INTRO = `Run JavaScript that composes tool calls in a fresh QuickJS worker sandbox.\nTop-level await and return work. Use tools.name(args), or tools[\"raw-name\"](args). Tool names normalize to JavaScript identifiers.\nNo Node, filesystem, network, timers, modules or credentials are available directly. Calls go through session validation and permission hooks. They have real side effects and are not undone after script failure.\nTools with output schemas resolve to structuredContent; others resolve to text. Failed or blocked calls throw, except that a tool with an output schema resolves with its structuredContent on failure too when it returned one; check its fields. Scripts have a 256 MB memory limit.\nGlobals: ALL_TOOLS, text(value), image(base64DataUrlOrImageContent), exit(), console.log(...), store(key, value), load(key), await searchTools(query, {limit?, namespace?}), await describeTool(name), await describeNamespace(name).\ntools, ALL_TOOLS and searchTools() matches cover only script-callable tools. Model-only tools such as subagent, workflow, intercom, and ask_user_question are excluded from them, but you can still call them directly. searchTools() and describeTool() answer the exact name of an active model-only tool with a hint to call it directly, not from a script.\nWith several text items, each starts with a ==> text N/M <== line. Console calls follow the other output in one <console_output> block, with one line per call.\nimage() also saves each image to a temp file and the result names its path before the image.\nSuccessful scripts persist store writes on the current session branch; failed scripts discard writes. Unawaited calls are cancelled when the script ends.\nOptional first line: // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}. Output defaults to 10000 tokens; there is no default deadline.`;\n\nexport function createCodemodeDescription(\n\ttools: readonly AgentTool[],\n\toptions: CodemodeDescriptionOptions = {},\n): string {\n\tconst groups = new Map<\n\t\tstring,\n\t\t{ namespace?: ToolNamespace; entries: { name: string; section: string; cost: number }[] }\n\t>();\n\tfor (const tool of getCodemodeCallableTools(tools)) {\n\t\tif (options.deferred?.has(tool.name)) continue;\n\t\tconst namespace = options.namespaces?.get(tool.name);\n\t\tconst key = namespace?.name ?? \"\";\n\t\tlet group = groups.get(key);\n\t\tif (!group) {\n\t\t\tgroup = { namespace, entries: [] };\n\t\t\tgroups.set(key, group);\n\t\t}\n\t\tconst id = toCodemodeIdentifier(tool.name);\n\t\tconst section = `### \\`${id}\\`${id === tool.name ? \"\" : ` (\\`${tool.name}\\`)`}\\n${renderToolSample(toCodemodeDeclaration(tool, options.guidelines?.get(tool.name))).trim()}`;\n\t\tgroup.entries.push({\n\t\t\tname: tool.name,\n\t\t\tsection,\n\t\t\tcost: Math.ceil(section.length / 4),\n\t\t});\n\t}\n\tconst ordered = [...groups.values()].sort((a, b) =>\n\t\ta.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name),\n\t);\n\tconst shown = new Set<string>();\n\tlet remaining = options.inlineBudget ?? Number.POSITIVE_INFINITY;\n\tlet queues = ordered\n\t\t.map((group) => [...group.entries].sort((a, b) => a.cost - b.cost))\n\t\t.filter((queue) => queue.length);\n\twhile (queues.length)\n\t\tqueues = queues.filter((queue) => {\n\t\t\tconst next = queue[0];\n\t\t\tif (next.cost > remaining) return false;\n\t\t\tremaining -= next.cost;\n\t\t\tshown.add(next.name);\n\t\t\tqueue.shift();\n\t\t\treturn queue.length > 0;\n\t\t});\n\tconst sections = [\n\t\tINTRO,\n\t\t\"Some nested tools may be omitted, including deferred tools. They remain available through tools and ALL_TOOLS. Use await searchTools(query), await describeTool(name), or await describeNamespace(name) to discover them.\",\n\t];\n\tif (options.models)\n\t\tsections.push(\n\t\t\t`Model API: \\`models\\` lists and runs classifier and image models with the session's credentials. Read ${CODEMODE_DOCS_PATH} before using it.`,\n\t\t);\n\tif (ordered.length === 0) return sections.join(\"\\n\\n\");\n\tsections.push(\"Nested tools:\");\n\tfor (const group of ordered) {\n\t\tif (group.namespace) {\n\t\t\tconst visible = group.entries.filter((entry) => shown.has(entry.name));\n\t\t\tconst listing =\n\t\t\t\tvisible.length === group.entries.length\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: visible.length === 0\n\t\t\t\t\t\t? \" (tools not listed)\"\n\t\t\t\t\t\t: \" (some tools not listed)\";\n\t\t\tconst description = group.namespace.description?.trim();\n\t\t\tsections.push(`## ${group.namespace.name}${listing}${description ? `\\n${description}` : \"\"}`);\n\t\t}\n\t\tfor (const entry of group.entries) if (shown.has(entry.name)) sections.push(entry.section);\n\t}\n\treturn sections.join(\"\\n\\n\");\n}\nfunction describeOutput(schema: CodemodeJsonSchema | undefined): string {\n\tconst type = renderToolOutputType(schema);\n\tif (type === \"string\") return \"a string\";\n\tconst object = typeof schema === \"object\" ? schema : undefined;\n\tconst properties = object?.properties;\n\tif (\n\t\tobject?.type === \"object\" &&\n\t\ttypeof properties === \"object\" &&\n\t\tproperties !== null &&\n\t\tmcpStructuredContentSchema(schema) === undefined\n\t) {\n\t\tconst required = new Set(Array.isArray(object.required) ? object.required : []);\n\t\tconst fields = Object.keys(properties).map((name) => (required.has(name) ? name : `${name}?`));\n\t\treturn `\\`{ ${fields.join(\", \")} }\\``;\n\t}\n\treturn `\\`${type.replace(/\\s+/g, \" \")}\\``;\n}\nfunction describeScriptCall(tool: AgentTool): string {\n\treturn `${tool.description.trim()}\\n\\nCodemode: \\`tools.${toCodemodeIdentifier(tool.name)}(args)\\` resolves to ${describeOutput(toCodemodeDeclaration(tool).outputSchema)}.`;\n}\nfunction prepareLoadout(loadout: ToolLoadout, options: CodemodeToolOptions) {\n\tconst only = options.getMode?.() === \"only\";\n\tconst callable = getCodemodeCallableTools(loadout.callable);\n\tconst descriptions: Record<string, string> = {};\n\tif (!only)\n\t\tfor (const tool of loadout.declared)\n\t\t\tif (callable.some((candidate) => candidate.name === tool.name))\n\t\t\t\tdescriptions[tool.name] = describeScriptCall(tool);\n\tconst listed = only ? callable : callable.filter((tool) => loadout.getExposure(tool.name) !== \"direct\");\n\tconst namespaces = new Map(\n\t\tlisted.flatMap((tool) => {\n\t\t\tconst namespace = loadout.getNamespace(tool.name);\n\t\t\treturn namespace ? [[tool.name, namespace] as const] : [];\n\t\t}),\n\t);\n\tconst guidelines = new Map(listed.map((tool) => [tool.name, loadout.getPromptGuidelines(tool.name)] as const));\n\tdescriptions[CODEMODE_TOOL_NAME] = createCodemodeDescription(listed, {\n\t\tmodels: options.models,\n\t\tnamespaces,\n\t\tguidelines,\n\t\tdeferred: new Set(\n\t\t\tlisted.filter((tool) => loadout.getExposure(tool.name) === \"deferred\").map((tool) => tool.name),\n\t\t),\n\t\tinlineBudget: options.getInlineBudget?.() ?? DEFAULT_CODEMODE_INLINE_BUDGET,\n\t});\n\treturn {\n\t\tdescriptions,\n\t\thiddenDeclarations: only\n\t\t\t? callable.filter((tool) => loadout.getExposure(tool.name) === \"direct\").map((tool) => tool.name)\n\t\t\t: [],\n\t};\n}\nexport function createCodemodeToolDefinition(\n\toptions: CodemodeToolOptions = {},\n): ToolDefinition<typeof codemodeSchema, CodemodeToolDetails> {\n\treturn {\n\t\tname: CODEMODE_TOOL_NAME,\n\t\tlabel: CODEMODE_TOOL_NAME,\n\t\tdescription: createCodemodeDescription([], options),\n\t\tparameters: codemodeSchema,\n\t\texposure: \"model-only\",\n\t\tconcurrency: \"exclusive\",\n\t\tdefaultActive: false,\n\t\tpromptSnippet: \"Run JavaScript that calls other tools, filters results, or batches independent calls\",\n\t\tprepareLoadout: (loadout) => prepareLoadout(loadout, options),\n\t\tconstrainedSampling: { type: \"grammar\", variants: { openai_lark: CODEMODE_SOURCE_GRAMMAR } },\n\t\texecute: async (id, input, signal, update, ctx) =>\n\t\t\t(await import(\"./execute.js\")).executeCodemode(id, input, signal, update, ctx, options),\n\t\t...codemodeRenderers,\n\t};\n}\nexport function createCodemodeTool(\n\ttools: readonly AgentTool[] = [],\n\toptions: CodemodeToolOptions = {},\n): AgentTool<typeof codemodeSchema> {\n\treturn {\n\t\t...wrapToolDefinition(createCodemodeToolDefinition(options)),\n\t\tdescription: createCodemodeDescription(tools, options),\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/codemode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACxH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,WAAW,EAAE,EAAE,aAAa,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;AAC1D,MAAM,CAAC,MAAM,8BAA8B,GAAW,iBAAiB,CAAC,QAAQ,CAAC,YAAY,CAAC;AAoB9F,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EACV,0IAA0I;KAC3I,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc,CAAC,IAA2C;IACzE,OAAO,IAAI,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC,UAAU,KAAK,cAAc,CAAC;AAC/E,CAAC;AAcD,MAAM,UAAU,qBAAqB,CACpC,IAAe,EACf,UAAU,G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AAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CACjD,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC;QACxF,GAAG,iBAAiB;KACpB,CAAC;AACH,CAAC;AACD,MAAM,UAAU,kBAAkB,CACjC,KAAK,GAAyB,EAAE,EAChC,OAAO,GAAwB,EAAE;IAEjC,OAAO;QACN,GAAG,kBAAkB,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC;QAC5D,WAAW,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC;KACtD,CAAC;AACH,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { CodemodeJsonSchema, CodemodeTool } from \"@earendil-works/pi-codemode\";\nimport { renderToolOutputType, renderToolSample, toCodemodeIdentifier } from \"@earendil-works/pi-codemode/declarations\";\nimport { CODEMODE_SOURCE_GRAMMAR } from \"@earendil-works/pi-codemode/source\";\nimport { type Static, Type } from \"typebox\";\nimport { getDocsPath } from \"../../config.js\";\nimport type { ToolDefinition, ToolInfo, ToolLoadout, ToolNamespace } from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { SETTINGS_DEFAULTS } from \"../../core/settings-defaults.ts\";\nimport type { CodemodeMode } from \"../../core/settings-manager.ts\";\nimport { wrapToolDefinition } from \"../../core/tools/tool-definition-wrapper.ts\";\nimport { codemodeRenderers } from \"./renderer.js\";\n\nexport const CODEMODE_TOOL_NAME = \"codemode\";\nexport const CODEMODE_DOCS_PATH = join(getDocsPath(), \"codemode.md\");\nexport const CODEMODE_STORE_ENTRY_TYPE = \"codemode-store\";\nexport const DEFAULT_CODEMODE_INLINE_BUDGET: number = SETTINGS_DEFAULTS.codemode.inlineBudget;\nexport interface CodemodeStoreEntryData {\n\tset: Record<string, unknown>;\n\tdelete: string[];\n}\nexport type CodemodeModelRuntime = Pick<\n\tModelRegistry,\n\t\"getModelsOfType\" | \"getAvailableOfType\" | \"getModelOfType\" | \"classify\" | \"generateImages\"\n>;\nexport interface CodemodeToolOptions {\n\tgetToolNamespace?: (name: string) => ToolNamespace | undefined;\n\t/** Prompt guidelines shown with tool declarations in describeTool() and ALL_TOOLS. */\n\tgetToolGuidelines?: () => ReadonlyMap<string, readonly string[]>;\n\tmodels?: boolean;\n\tappendEntry?: (type: string, data: CodemodeStoreEntryData) => void;\n\tgetMode?: () => CodemodeMode;\n\tgetInlineBudget?: () => number | undefined;\n\t/** Active model-only tools. Scripts cannot call them, so discovery answers an exact name with a hint. */\n\tgetModelOnlyTools?: () => readonly string[];\n}\nexport const codemodeSchema = Type.Object({\n\tcode: Type.String({\n\t\tdescription:\n\t\t\t'Raw JavaScript source with top-level await and return. Optional first line // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}',\n\t}),\n});\nexport type CodemodeToolInput = Static<typeof codemodeSchema>;\nexport function isCodemodeTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === CODEMODE_TOOL_NAME && tool.parameters === codemodeSchema;\n}\nexport interface CodemodeNestedCall {\n\tid: string;\n\tname: string;\n\targs: string;\n\tstatus: \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\tdurationMs?: number;\n\terror?: string;\n\tcost?: number;\n}\nexport interface CodemodeToolDetails {\n\tcalls: CodemodeNestedCall[];\n\tfullOutputPath?: string;\n}\nexport function toCodemodeDeclaration(\n\ttool: AgentTool,\n\tguidelines: readonly string[] = [],\n): Omit<CodemodeTool, \"execute\"> {\n\tconst bullets = guidelines.flatMap((guideline) => (guideline.trim() ? [`- ${guideline.trim()}`] : []));\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: bullets.length > 0 ? `${tool.description.trim()}\\n\\n${bullets.join(\"\\n\")}` : tool.description,\n\t\tinputSchema: tool.parameters as CodemodeJsonSchema,\n\t\toutputSchema: (tool.outputSchema as CodemodeJsonSchema | undefined) ?? { type: \"string\" },\n\t};\n}\nexport function getCodemodeCallableTools(tools: readonly AgentTool[]): AgentTool[] {\n\treturn tools.filter((tool) => tool.name !== CODEMODE_TOOL_NAME);\n}\nexport interface CodemodeDescriptionOptions {\n\tmodels?: boolean;\n\tnamespaces?: ReadonlyMap<string, ToolNamespace>;\n\tdeferred?: ReadonlySet<string>;\n\tguidelines?: ReadonlyMap<string, readonly string[]>;\n\tinlineBudget?: number;\n}\nconst INTRO = `Run JavaScript that composes tool calls in a fresh QuickJS worker sandbox.\nTop-level await and return work. Use tools.name(args), or tools[\"raw-name\"](args). Tool names normalize to JavaScript identifiers.\nNo Node, filesystem, network, timers, modules or credentials are available directly. Calls go through session validation and permission hooks. They have real side effects and are not undone after script failure.\nTools with output schemas resolve to structuredContent; others resolve to text. Failed or blocked calls throw, except that a tool with an output schema resolves with its structuredContent on failure too when it returned one; check its fields. Scripts have a 256 MB memory limit.\nGlobals: ALL_TOOLS, text(value), image(base64DataUrlOrImageContent), exit(), console.log(...), store(key, value), load(key), await searchTools(query, {limit?, namespace?}), await describeTool(name), await describeNamespace(name).\ntools, ALL_TOOLS and searchTools() matches cover only script-callable tools. Model-only tools such as subagent, workflow, intercom, and ask_user_question are excluded from them, but you can still call them directly. searchTools() and describeTool() answer the exact name of an active model-only tool with a hint to call it directly, not from a script.\nWith several text items, each starts with a ==> text N/M <== line. Console calls follow the other output in one <console_output> block, with one line per call.\nimage() also saves each image to a temp file and the result names its path before the image.\nSuccessful scripts persist store writes on the current session branch; failed scripts discard writes. Unawaited calls are cancelled when the script ends.\nOptional first line: // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}. Output defaults to 10000 tokens; there is no default deadline.`;\n\nexport function createCodemodeDescription(\n\ttools: readonly AgentTool[],\n\toptions: CodemodeDescriptionOptions = {},\n): string {\n\tconst groups = new Map<\n\t\tstring,\n\t\t{ namespace?: ToolNamespace; entries: { name: string; section: string; cost: number }[] }\n\t>();\n\tfor (const tool of getCodemodeCallableTools(tools)) {\n\t\tif (options.deferred?.has(tool.name)) continue;\n\t\tconst namespace = options.namespaces?.get(tool.name);\n\t\tconst key = namespace?.name ?? \"\";\n\t\tlet group = groups.get(key);\n\t\tif (!group) {\n\t\t\tgroup = { namespace, entries: [] };\n\t\t\tgroups.set(key, group);\n\t\t}\n\t\tconst id = toCodemodeIdentifier(tool.name);\n\t\tconst section = `### \\`${id}\\`${id === tool.name ? \"\" : ` (\\`${tool.name}\\`)`}\\n${renderToolSample(toCodemodeDeclaration(tool, options.guidelines?.get(tool.name))).trim()}`;\n\t\tgroup.entries.push({\n\t\t\tname: tool.name,\n\t\t\tsection,\n\t\t\tcost: Math.ceil(section.length / 4),\n\t\t});\n\t}\n\tconst ordered = [...groups.values()].sort((a, b) =>\n\t\ta.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name),\n\t);\n\tconst shown = new Set<string>();\n\tlet remaining = options.inlineBudget ?? Number.POSITIVE_INFINITY;\n\tlet queues = ordered\n\t\t.map((group) => [...group.entries].sort((a, b) => a.cost - b.cost))\n\t\t.filter((queue) => queue.length);\n\twhile (queues.length)\n\t\tqueues = queues.filter((queue) => {\n\t\t\tconst next = queue[0];\n\t\t\tif (next.cost > remaining) return false;\n\t\t\tremaining -= next.cost;\n\t\t\tshown.add(next.name);\n\t\t\tqueue.shift();\n\t\t\treturn queue.length > 0;\n\t\t});\n\tconst sections = [\n\t\tINTRO,\n\t\t\"Some nested tools may be omitted, including deferred tools. They remain available through tools and ALL_TOOLS. Use await searchTools(query), await describeTool(name), or await describeNamespace(name) to discover them.\",\n\t];\n\tif (options.models)\n\t\tsections.push(\n\t\t\t`Model API: \\`models\\` lists and runs classifier and image models with the session's credentials. Read ${CODEMODE_DOCS_PATH} before using it.`,\n\t\t);\n\tif (ordered.length === 0) return sections.join(\"\\n\\n\");\n\tsections.push(\"Nested tools:\");\n\tfor (const group of ordered) {\n\t\tif (group.namespace) {\n\t\t\tconst visible = group.entries.filter((entry) => shown.has(entry.name));\n\t\t\tconst listing =\n\t\t\t\tvisible.length === group.entries.length\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: visible.length === 0\n\t\t\t\t\t\t? \" (tools not listed)\"\n\t\t\t\t\t\t: \" (some tools not listed)\";\n\t\t\tconst description = group.namespace.description?.trim();\n\t\t\tsections.push(`## ${group.namespace.name}${listing}${description ? `\\n${description}` : \"\"}`);\n\t\t}\n\t\tfor (const entry of group.entries) if (shown.has(entry.name)) sections.push(entry.section);\n\t}\n\treturn sections.join(\"\\n\\n\");\n}\n/**\n * The field names of an object schema, `{ output, exit_code, full_output_path? }`, with the fields of\n * object-typed fields `depth` levels deep: `{ content, structuredContent?: { results } }`. Undefined\n * for other schemas.\n */\nfunction describeFields(schema: unknown, depth: number): string | undefined {\n\tif (typeof schema !== \"object\" || schema === null) return undefined;\n\tconst { type, properties, required } = schema as Record<string, unknown>;\n\tif (type !== \"object\" || typeof properties !== \"object\" || properties === null) return undefined;\n\tconst requiredNames = new Set(Array.isArray(required) ? required : []);\n\tconst fields = Object.entries(properties).map(([name, field]) => {\n\t\tconst nested = depth > 0 ? describeFields(field, depth - 1) : undefined;\n\t\treturn `${name}${requiredNames.has(name) ? \"\" : \"?\"}${nested ? `: ${nested}` : \"\"}`;\n\t});\n\treturn `{ ${fields.join(\", \")} }`;\n}\n/**\n * What a script call resolves to, in one line: `a string`, the field names of an object (see\n * {@link describeFields}), or the rendered type for anything else.\n */\nfunction describeOutput(schema: CodemodeJsonSchema | undefined): string {\n\tconst type = renderToolOutputType(schema);\n\tif (type === \"string\") return \"a string\";\n\tconst fields = describeFields(schema, 1);\n\treturn `\\`${fields ?? type.replace(/\\s+/g, \" \")}\\``;\n}\nfunction describeScriptCall(tool: AgentTool): string {\n\treturn `${tool.description.trim()}\\n\\nCodemode: \\`tools.${toCodemodeIdentifier(tool.name)}(args)\\` resolves to ${describeOutput(toCodemodeDeclaration(tool).outputSchema)}.`;\n}\nfunction prepareLoadout(loadout: ToolLoadout, options: CodemodeToolOptions) {\n\tconst only = options.getMode?.() === \"only\";\n\tconst callable = getCodemodeCallableTools(loadout.callable);\n\tconst descriptions: Record<string, string> = {};\n\tif (!only)\n\t\tfor (const tool of loadout.declared)\n\t\t\tif (callable.some((candidate) => candidate.name === tool.name))\n\t\t\t\tdescriptions[tool.name] = describeScriptCall(tool);\n\tconst listed = only ? callable : callable.filter((tool) => loadout.getExposure(tool.name) !== \"direct\");\n\tconst namespaces = new Map(\n\t\tlisted.flatMap((tool) => {\n\t\t\tconst namespace = loadout.getNamespace(tool.name);\n\t\t\treturn namespace ? [[tool.name, namespace] as const] : [];\n\t\t}),\n\t);\n\tconst guidelines = new Map(listed.map((tool) => [tool.name, loadout.getPromptGuidelines(tool.name)] as const));\n\tdescriptions[CODEMODE_TOOL_NAME] = createCodemodeDescription(listed, {\n\t\tmodels: options.models,\n\t\tnamespaces,\n\t\tguidelines,\n\t\tdeferred: new Set(\n\t\t\tlisted.filter((tool) => loadout.getExposure(tool.name) === \"deferred\").map((tool) => tool.name),\n\t\t),\n\t\tinlineBudget: options.getInlineBudget?.() ?? DEFAULT_CODEMODE_INLINE_BUDGET,\n\t});\n\treturn {\n\t\tdescriptions,\n\t\thiddenDeclarations: only\n\t\t\t? callable.filter((tool) => loadout.getExposure(tool.name) === \"direct\").map((tool) => tool.name)\n\t\t\t: [],\n\t};\n}\nexport function createCodemodeToolDefinition(\n\toptions: CodemodeToolOptions = {},\n): ToolDefinition<typeof codemodeSchema, CodemodeToolDetails> {\n\treturn {\n\t\tname: CODEMODE_TOOL_NAME,\n\t\tlabel: CODEMODE_TOOL_NAME,\n\t\tdescription: createCodemodeDescription([], options),\n\t\tparameters: codemodeSchema,\n\t\texposure: \"model-only\",\n\t\tconcurrency: \"exclusive\",\n\t\tdefaultActive: false,\n\t\tpromptSnippet: \"Run JavaScript that calls other tools, filters results, or batches independent calls\",\n\t\tprepareLoadout: (loadout) => prepareLoadout(loadout, options),\n\t\tconstrainedSampling: { type: \"grammar\", variants: { openai_lark: CODEMODE_SOURCE_GRAMMAR } },\n\t\texecute: async (id, input, signal, update, ctx) =>\n\t\t\t(await import(\"./execute.js\")).executeCodemode(id, input, signal, update, ctx, options),\n\t\t...codemodeRenderers,\n\t};\n}\nexport function createCodemodeTool(\n\ttools: readonly AgentTool[] = [],\n\toptions: CodemodeToolOptions = {},\n): AgentTool<typeof codemodeSchema> {\n\treturn {\n\t\t...wrapToolDefinition(createCodemodeToolDefinition(options)),\n\t\tdescription: createCodemodeDescription(tools, options),\n\t};\n}\n"]}
@@ -47,9 +47,8 @@ export interface McpToolCaller {
47
47
  */
48
48
  export declare function createMcpToolName(server: string, tool: string, isTaken?: (name: string) => boolean): string;
49
49
  /**
50
- * Output schema of every MCP tool: the `CallToolResult` scripts receive, with the tool's own output
51
- * schema as `structuredContent`. Codemode detects this shape to render `CallToolResult<T>`
52
- * declarations.
50
+ * Output schema of every MCP tool: the `CallToolResult` scripts receive (without `_meta`, which
51
+ * {@link convertMcpResult} drops), with the tool's own output schema as `structuredContent`.
53
52
  */
54
53
  export declare function createMcpResultSchema(structuredContentSchema: Record<string, unknown> | undefined): TSchema;
55
54
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAa,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAElF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAEX,cAAc,EACd,YAAY,EACZ,aAAa,EACb,aAAa,EACb,MAAM,gCAAgC,CAAC;AAMxC,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,iBAA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