@ai-sdk/code-mode 1.0.79 → 1.0.81

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.
@@ -1,468 +1,330 @@
1
1
  import { asSchema } from "ai";
2
+ //#region src/tool-prompt.ts
2
3
  const MAX_SCHEMA_DEPTH = 8;
3
4
  const MAX_COMPACT_OBJECT_TYPE_LENGTH = 120;
4
5
  function buildCodeModeToolDescription(tools, toolDiscovery = "description") {
5
- const sections = [
6
- "Execute code-mode TypeScript in an isolated sandbox.",
7
- "",
8
- "Put the full program in `js`; top-level `await`/`return` work. Return a JSON-serializable result.",
9
- "Call host tools only as async `tools.name(input)`; await each or use `Promise.all` for independent calls.",
10
- toolDiscovery === "description" ? "Use exact names/types below. `JSON.parse`/`JSON.stringify` are available." : "Use exact names/types from the latest capability update. `JSON.parse`/`JSON.stringify` are available.",
11
- "Fetch: `fetch` is not available."
12
- ];
13
- if (toolDiscovery === "conversation") {
14
- sections.push(
15
- "",
16
- "Tools:",
17
- 'The current host-tool API is provided in "Code mode capability update" user messages. Follow the latest catalog and ignore earlier catalogs.'
18
- );
19
- return sections.join("\n");
20
- }
21
- const { typeBlock, exampleBlock } = renderToolCatalog(tools);
22
- sections.push("", "Tools:", typeBlock);
23
- if (exampleBlock.length > 0) {
24
- sections.push(exampleBlock);
25
- }
26
- return sections.join("\n");
6
+ const sections = [
7
+ "Execute code-mode TypeScript in an isolated sandbox.",
8
+ "",
9
+ "Put the full program in `js`; top-level `await`/`return` work. Return a JSON-serializable result.",
10
+ "Call host tools only as async `tools.name(input)`; await each or use `Promise.all` for independent calls.",
11
+ toolDiscovery === "description" ? "Use exact names/types below. `JSON.parse`/`JSON.stringify` are available." : "Use exact names/types from the latest capability update. `JSON.parse`/`JSON.stringify` are available.",
12
+ "Fetch: `fetch` is not available."
13
+ ];
14
+ if (toolDiscovery === "conversation") {
15
+ sections.push("", "Tools:", "The current host-tool API is provided in \"Code mode capability update\" user messages. Follow the latest catalog and ignore earlier catalogs.");
16
+ return sections.join("\n");
17
+ }
18
+ const { typeBlock, exampleBlock } = renderToolCatalog(tools);
19
+ sections.push("", "Tools:", typeBlock);
20
+ if (exampleBlock.length > 0) sections.push(exampleBlock);
21
+ return sections.join("\n");
27
22
  }
28
23
  function buildCodeModeToolCatalogMessage(tools) {
29
- const { typeBlock, exampleBlock } = renderToolCatalog(tools);
30
- const sections = [
31
- "Code mode capability update.",
32
- "",
33
- "This catalog replaces all previous code mode capability catalogs. Only the tools listed below are currently available through `tools`.",
34
- "",
35
- "Tools:",
36
- typeBlock
37
- ];
38
- if (exampleBlock.length > 0) {
39
- sections.push(exampleBlock);
40
- }
41
- return sections.join("\n");
24
+ const { typeBlock, exampleBlock } = renderToolCatalog(tools);
25
+ const sections = [
26
+ "Code mode capability update.",
27
+ "",
28
+ "This catalog replaces all previous code mode capability catalogs. Only the tools listed below are currently available through `tools`.",
29
+ "",
30
+ "Tools:",
31
+ typeBlock
32
+ ];
33
+ if (exampleBlock.length > 0) sections.push(exampleBlock);
34
+ return sections.join("\n");
42
35
  }
43
36
  function renderToolCatalog(tools) {
44
- const toolEntries = Object.entries(tools);
45
- const typeBlock = toolEntries.length === 0 ? "No host tools. Do not call `tools.*`." : [
46
- "```ts",
47
- "declare const tools: {",
48
- ...toolEntries.flatMap(renderToolType),
49
- "};",
50
- "```"
51
- ].join("\n");
52
- const exampleBlock = toolEntries.length === 0 ? "" : [
53
- "",
54
- "Tool call examples:",
55
- "```ts",
56
- ...renderToolExamples(toolEntries),
57
- "```"
58
- ].join("\n");
59
- return { typeBlock, exampleBlock };
37
+ const toolEntries = Object.entries(tools);
38
+ return {
39
+ typeBlock: toolEntries.length === 0 ? "No host tools. Do not call `tools.*`." : [
40
+ "```ts",
41
+ "declare const tools: {",
42
+ ...toolEntries.flatMap(renderToolType),
43
+ "};",
44
+ "```"
45
+ ].join("\n"),
46
+ exampleBlock: toolEntries.length === 0 ? "" : [
47
+ "",
48
+ "Tool call examples:",
49
+ "```ts",
50
+ ...renderToolExamples(toolEntries),
51
+ "```"
52
+ ].join("\n")
53
+ };
60
54
  }
61
55
  function renderToolType([toolName, tool]) {
62
- const schema = resolveInputSchema(tool);
63
- const inputType = schema === void 0 ? "unknown" : schemaToType(schema, schema);
64
- const outputSchema = resolveOutputSchema(tool);
65
- const outputType = outputSchema === void 0 ? "unknown" : schemaToType(outputSchema, outputSchema);
66
- const description = firstString(tool.description, tool.title);
67
- const lines = [];
68
- if (description !== void 0) {
69
- lines.push(` /** ${toComment(description)} */`);
70
- }
71
- lines.push(
72
- ` ${formatObjectKey(toolName)}: (input: ${indentType(inputType, 2)}) => Promise<${indentType(outputType, 2)}>;`
73
- );
74
- return lines;
56
+ const schema = resolveInputSchema(tool);
57
+ const inputType = schema === void 0 ? "unknown" : schemaToType(schema, schema);
58
+ const outputSchema = resolveOutputSchema(tool);
59
+ const outputType = outputSchema === void 0 ? "unknown" : schemaToType(outputSchema, outputSchema);
60
+ const description = firstString(tool.description, tool.title);
61
+ const lines = [];
62
+ if (description !== void 0) lines.push(` /** ${toComment(description)} */`);
63
+ lines.push(` ${formatObjectKey(toolName)}: (input: ${indentType(inputType, 2)}) => Promise<${indentType(outputType, 2)}>;`);
64
+ return lines;
75
65
  }
76
66
  function renderToolExamples(toolEntries) {
77
- if (toolEntries.length === 1) {
78
- const toolEntry = toolEntries[0];
79
- const projection = renderToolProjection("result", toolEntry[1]);
80
- return [
81
- `const result = await ${renderToolExampleCall(toolEntry)};`,
82
- `return ${projection};`
83
- ];
84
- }
85
- const variableNames = uniqueToolVariableNames(
86
- toolEntries.map(([toolName]) => toolName)
87
- );
88
- const calls = toolEntries.map(
89
- (toolEntry) => ` ${renderToolExampleCall(toolEntry)},`
90
- );
91
- return [
92
- `const [${variableNames.join(", ")}] = await Promise.all([`,
93
- ...calls,
94
- "]);",
95
- "return {",
96
- ...toolEntries.map(([toolName, tool], index) => {
97
- const projection = renderToolProjection(variableNames[index], tool);
98
- return ` ${formatObjectKey(toolName)}: ${projection},`;
99
- }),
100
- "};"
101
- ];
67
+ if (toolEntries.length === 1) {
68
+ const toolEntry = toolEntries[0];
69
+ const projection = renderToolProjection("result", toolEntry[1]);
70
+ return [`const result = await ${renderToolExampleCall(toolEntry)};`, `return ${projection};`];
71
+ }
72
+ const variableNames = uniqueToolVariableNames(toolEntries.map(([toolName]) => toolName));
73
+ const calls = toolEntries.map((toolEntry) => ` ${renderToolExampleCall(toolEntry)},`);
74
+ return [
75
+ `const [${variableNames.join(", ")}] = await Promise.all([`,
76
+ ...calls,
77
+ "]);",
78
+ "return {",
79
+ ...toolEntries.map(([toolName, tool], index) => {
80
+ const projection = renderToolProjection(variableNames[index], tool);
81
+ return ` ${formatObjectKey(toolName)}: ${projection},`;
82
+ }),
83
+ "};"
84
+ ];
102
85
  }
103
86
  function renderToolExampleCall([toolName, tool]) {
104
- const schema = resolveInputSchema(tool);
105
- const input = firstInputExample(tool) ?? (schema === void 0 ? {} : sampleFromSchema(schema, schema));
106
- return `tools${formatPropertyAccess(toolName)}(${JSON.stringify(input)})`;
87
+ const schema = resolveInputSchema(tool);
88
+ const input = firstInputExample(tool) ?? (schema === void 0 ? {} : sampleFromSchema(schema, schema));
89
+ return `tools${formatPropertyAccess(toolName)}(${JSON.stringify(input)})`;
107
90
  }
108
91
  function renderToolProjection(variableName, tool) {
109
- const field = firstObjectProperty(resolveOutputSchema(tool));
110
- if (field === void 0) {
111
- return variableName;
112
- }
113
- return `{ ${formatObjectKey(field)}: ${variableName}${formatPropertyAccess(field)} }`;
92
+ const field = firstObjectProperty(resolveOutputSchema(tool));
93
+ if (field === void 0) return variableName;
94
+ return `{ ${formatObjectKey(field)}: ${variableName}${formatPropertyAccess(field)} }`;
114
95
  }
115
96
  function firstObjectProperty(schema) {
116
- if (schema === void 0 || !isRecord(schema.properties)) {
117
- return void 0;
118
- }
119
- return Object.entries(schema.properties).find(
120
- (entry) => isRecord(entry[1])
121
- )?.[0];
97
+ if (schema === void 0 || !isRecord(schema.properties)) return;
98
+ return Object.entries(schema.properties).find((entry) => isRecord(entry[1]))?.[0];
122
99
  }
123
100
  function resolveInputSchema(tool) {
124
- try {
125
- const jsonSchema = asSchema(tool.inputSchema).jsonSchema;
126
- if (isPromiseLike(jsonSchema) || !isRecord(jsonSchema)) {
127
- return void 0;
128
- }
129
- return jsonSchema;
130
- } catch {
131
- return void 0;
132
- }
101
+ try {
102
+ const jsonSchema = asSchema(tool.inputSchema).jsonSchema;
103
+ if (isPromiseLike(jsonSchema) || !isRecord(jsonSchema)) return;
104
+ return jsonSchema;
105
+ } catch {
106
+ return;
107
+ }
133
108
  }
134
109
  function resolveOutputSchema(tool) {
135
- try {
136
- const outputSchema = tool.outputSchema;
137
- if (outputSchema === void 0) {
138
- return void 0;
139
- }
140
- const jsonSchema = asSchema(outputSchema).jsonSchema;
141
- if (isPromiseLike(jsonSchema) || !isRecord(jsonSchema)) {
142
- return void 0;
143
- }
144
- return jsonSchema;
145
- } catch {
146
- return void 0;
147
- }
110
+ try {
111
+ const outputSchema = tool.outputSchema;
112
+ if (outputSchema === void 0) return;
113
+ const jsonSchema = asSchema(outputSchema).jsonSchema;
114
+ if (isPromiseLike(jsonSchema) || !isRecord(jsonSchema)) return;
115
+ return jsonSchema;
116
+ } catch {
117
+ return;
118
+ }
148
119
  }
149
120
  function schemaToType(schema, root) {
150
- return schemaToTypeInner(schema, {
151
- root,
152
- seenRefs: /* @__PURE__ */ new Set(),
153
- depth: 0
154
- });
121
+ return schemaToTypeInner(schema, {
122
+ root,
123
+ seenRefs: /* @__PURE__ */ new Set(),
124
+ depth: 0
125
+ });
155
126
  }
156
127
  function schemaToTypeInner(schema, context) {
157
- if (context.depth > MAX_SCHEMA_DEPTH) {
158
- return "unknown";
159
- }
160
- const ref = firstString(schema.$ref);
161
- if (ref !== void 0) {
162
- const resolved = resolveRef(ref, context.root, context.seenRefs);
163
- return resolved === void 0 ? "unknown" : schemaToTypeInner(resolved, nextContext(context));
164
- }
165
- const constValue = schema.const;
166
- if (constValue !== void 0) {
167
- return literalType(constValue);
168
- }
169
- const enumValues = asArray(schema.enum);
170
- if (enumValues !== void 0) {
171
- return union(enumValues.map(literalType));
172
- }
173
- const oneOf = schemaArray(schema.oneOf);
174
- if (oneOf !== void 0) {
175
- return union(
176
- oneOf.map((part) => schemaToTypeInner(part, nextContext(context)))
177
- );
178
- }
179
- const anyOf = schemaArray(schema.anyOf);
180
- if (anyOf !== void 0) {
181
- return union(
182
- anyOf.map((part) => schemaToTypeInner(part, nextContext(context)))
183
- );
184
- }
185
- const allOf = schemaArray(schema.allOf);
186
- if (allOf !== void 0) {
187
- return allOf.map((part) => schemaToTypeInner(part, nextContext(context))).join(" & ");
188
- }
189
- const type = schema.type;
190
- if (Array.isArray(type)) {
191
- return union(
192
- type.map((part) => schemaToTypeInner({ ...schema, type: part }, context))
193
- );
194
- }
195
- if (type === "object" || isRecord(schema.properties)) {
196
- return objectType(schema, context);
197
- }
198
- if (type === "array" || schema.items !== void 0) {
199
- return arrayType(schema, context);
200
- }
201
- if (type === "string") {
202
- return "string";
203
- }
204
- if (type === "number" || type === "integer") {
205
- return "number";
206
- }
207
- if (type === "boolean") {
208
- return "boolean";
209
- }
210
- if (type === "null") {
211
- return "null";
212
- }
213
- return "unknown";
128
+ if (context.depth > MAX_SCHEMA_DEPTH) return "unknown";
129
+ const ref = firstString(schema.$ref);
130
+ if (ref !== void 0) {
131
+ const resolved = resolveRef(ref, context.root, context.seenRefs);
132
+ return resolved === void 0 ? "unknown" : schemaToTypeInner(resolved, nextContext(context));
133
+ }
134
+ const constValue = schema.const;
135
+ if (constValue !== void 0) return literalType(constValue);
136
+ const enumValues = asArray(schema.enum);
137
+ if (enumValues !== void 0) return union(enumValues.map(literalType));
138
+ const oneOf = schemaArray(schema.oneOf);
139
+ if (oneOf !== void 0) return union(oneOf.map((part) => schemaToTypeInner(part, nextContext(context))));
140
+ const anyOf = schemaArray(schema.anyOf);
141
+ if (anyOf !== void 0) return union(anyOf.map((part) => schemaToTypeInner(part, nextContext(context))));
142
+ const allOf = schemaArray(schema.allOf);
143
+ if (allOf !== void 0) return allOf.map((part) => schemaToTypeInner(part, nextContext(context))).join(" & ");
144
+ const type = schema.type;
145
+ if (Array.isArray(type)) return union(type.map((part) => schemaToTypeInner({
146
+ ...schema,
147
+ type: part
148
+ }, context)));
149
+ if (type === "object" || isRecord(schema.properties)) return objectType(schema, context);
150
+ if (type === "array" || schema.items !== void 0) return arrayType(schema, context);
151
+ if (type === "string") return "string";
152
+ if (type === "number" || type === "integer") return "number";
153
+ if (type === "boolean") return "boolean";
154
+ if (type === "null") return "null";
155
+ return "unknown";
214
156
  }
215
157
  function objectType(schema, context) {
216
- const properties = isRecord(schema.properties) ? schema.properties : {};
217
- const required = new Set(asArray(schema.required)?.filter(isString));
218
- const entries = Object.entries(properties).filter(
219
- (entry) => isRecord(entry[1])
220
- );
221
- if (entries.length === 0) {
222
- const additionalProperties2 = schema.additionalProperties;
223
- if (isRecord(additionalProperties2)) {
224
- return `Record<string, ${schemaToTypeInner(additionalProperties2, nextContext(context))}>`;
225
- }
226
- if (additionalProperties2 === true) {
227
- return "Record<string, unknown>";
228
- }
229
- return "{}";
230
- }
231
- const lines = entries.flatMap(([name, value]) => {
232
- const propertyLines = [];
233
- const description = firstString(value.description);
234
- if (description !== void 0) {
235
- propertyLines.push(` /** ${toComment(description)} */`);
236
- }
237
- propertyLines.push(
238
- ` ${formatObjectKey(name)}${required.has(name) ? "" : "?"}: ${indentType(
239
- schemaToTypeInner(value, nextContext(context)),
240
- 2
241
- )};`
242
- );
243
- return propertyLines;
244
- });
245
- const additionalProperties = schema.additionalProperties;
246
- if (isRecord(additionalProperties)) {
247
- lines.push(
248
- ` [key: string]: ${schemaToTypeInner(additionalProperties, nextContext(context))};`
249
- );
250
- } else if (additionalProperties === true) {
251
- lines.push(" [key: string]: unknown;");
252
- }
253
- const compact = compactObjectType(lines);
254
- if (compact !== void 0) {
255
- return compact;
256
- }
257
- return `{
258
- ${lines.join("\n")}
259
- }`;
158
+ const properties = isRecord(schema.properties) ? schema.properties : {};
159
+ const required = new Set(asArray(schema.required)?.filter(isString));
160
+ const entries = Object.entries(properties).filter((entry) => isRecord(entry[1]));
161
+ if (entries.length === 0) {
162
+ const additionalProperties = schema.additionalProperties;
163
+ if (isRecord(additionalProperties)) return `Record<string, ${schemaToTypeInner(additionalProperties, nextContext(context))}>`;
164
+ if (additionalProperties === true) return "Record<string, unknown>";
165
+ return "{}";
166
+ }
167
+ const lines = entries.flatMap(([name, value]) => {
168
+ const propertyLines = [];
169
+ const description = firstString(value.description);
170
+ if (description !== void 0) propertyLines.push(` /** ${toComment(description)} */`);
171
+ propertyLines.push(` ${formatObjectKey(name)}${required.has(name) ? "" : "?"}: ${indentType(schemaToTypeInner(value, nextContext(context)), 2)};`);
172
+ return propertyLines;
173
+ });
174
+ const additionalProperties = schema.additionalProperties;
175
+ if (isRecord(additionalProperties)) lines.push(` [key: string]: ${schemaToTypeInner(additionalProperties, nextContext(context))};`);
176
+ else if (additionalProperties === true) lines.push(" [key: string]: unknown;");
177
+ const compact = compactObjectType(lines);
178
+ if (compact !== void 0) return compact;
179
+ return `{\n${lines.join("\n")}\n}`;
260
180
  }
261
181
  function arrayType(schema, context) {
262
- const items = schema.items;
263
- if (Array.isArray(items)) {
264
- return `[${items.map(
265
- (item) => isRecord(item) ? schemaToTypeInner(item, nextContext(context)) : "unknown"
266
- ).join(", ")}]`;
267
- }
268
- if (isRecord(items)) {
269
- const itemType = schemaToTypeInner(items, nextContext(context));
270
- return needsParentheses(itemType) || itemType.includes("\n") ? `Array<${itemType}>` : `${itemType}[]`;
271
- }
272
- return "unknown[]";
182
+ const items = schema.items;
183
+ if (Array.isArray(items)) return `[${items.map((item) => isRecord(item) ? schemaToTypeInner(item, nextContext(context)) : "unknown").join(", ")}]`;
184
+ if (isRecord(items)) {
185
+ const itemType = schemaToTypeInner(items, nextContext(context));
186
+ return needsParentheses(itemType) || itemType.includes("\n") ? `Array<${itemType}>` : `${itemType}[]`;
187
+ }
188
+ return "unknown[]";
273
189
  }
274
190
  function sampleFromSchema(schema, root) {
275
- return sampleFromSchemaInner(schema, {
276
- root,
277
- seenRefs: /* @__PURE__ */ new Set(),
278
- depth: 0
279
- });
191
+ return sampleFromSchemaInner(schema, {
192
+ root,
193
+ seenRefs: /* @__PURE__ */ new Set(),
194
+ depth: 0
195
+ });
280
196
  }
281
197
  function sampleFromSchemaInner(schema, context) {
282
- if (context.depth > MAX_SCHEMA_DEPTH) {
283
- return null;
284
- }
285
- if (schema.default !== void 0) {
286
- return schema.default;
287
- }
288
- const ref = firstString(schema.$ref);
289
- if (ref !== void 0) {
290
- const resolved = resolveRef(ref, context.root, context.seenRefs);
291
- return resolved === void 0 ? null : sampleFromSchemaInner(resolved, nextContext(context));
292
- }
293
- if (schema.const !== void 0) {
294
- return schema.const;
295
- }
296
- const enumValues = asArray(schema.enum);
297
- if (enumValues !== void 0) {
298
- return enumValues[0] ?? null;
299
- }
300
- const oneOf = schemaArray(schema.oneOf);
301
- if (oneOf !== void 0) {
302
- return sampleFromSchemaInner(oneOf[0] ?? {}, nextContext(context));
303
- }
304
- const anyOf = schemaArray(schema.anyOf);
305
- if (anyOf !== void 0) {
306
- return sampleFromSchemaInner(anyOf[0] ?? {}, nextContext(context));
307
- }
308
- const type = schema.type;
309
- if (Array.isArray(type)) {
310
- return sampleFromSchemaInner(
311
- { ...schema, type: type.find((part) => part !== "null") ?? type[0] },
312
- context
313
- );
314
- }
315
- if (type === "object" || isRecord(schema.properties)) {
316
- const properties = isRecord(schema.properties) ? schema.properties : {};
317
- return Object.fromEntries(
318
- Object.entries(properties).filter((entry) => isRecord(entry[1])).map(([name, value]) => [
319
- name,
320
- sampleFromSchemaInner(value, nextContext(context))
321
- ])
322
- );
323
- }
324
- if (type === "array" || schema.items !== void 0) {
325
- const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;
326
- return [
327
- isRecord(items) ? sampleFromSchemaInner(items, nextContext(context)) : null
328
- ];
329
- }
330
- if (type === "number" || type === "integer") {
331
- return 1;
332
- }
333
- if (type === "boolean") {
334
- return true;
335
- }
336
- if (type === "null") {
337
- return null;
338
- }
339
- if (type === "string" || type === void 0) {
340
- const examples = asArray(schema.examples);
341
- if (examples?.[0] !== void 0) {
342
- return examples[0];
343
- }
344
- const format = firstString(schema.format);
345
- if (format === "uri" || format === "url") {
346
- return "https://example.com";
347
- }
348
- if (format === "date-time") {
349
- return "2026-01-01T00:00:00.000Z";
350
- }
351
- if (format === "date") {
352
- return "2026-01-01";
353
- }
354
- return "string";
355
- }
356
- return null;
198
+ if (context.depth > MAX_SCHEMA_DEPTH) return null;
199
+ if (schema.default !== void 0) return schema.default;
200
+ const ref = firstString(schema.$ref);
201
+ if (ref !== void 0) {
202
+ const resolved = resolveRef(ref, context.root, context.seenRefs);
203
+ return resolved === void 0 ? null : sampleFromSchemaInner(resolved, nextContext(context));
204
+ }
205
+ if (schema.const !== void 0) return schema.const;
206
+ const enumValues = asArray(schema.enum);
207
+ if (enumValues !== void 0) return enumValues[0] ?? null;
208
+ const oneOf = schemaArray(schema.oneOf);
209
+ if (oneOf !== void 0) return sampleFromSchemaInner(oneOf[0] ?? {}, nextContext(context));
210
+ const anyOf = schemaArray(schema.anyOf);
211
+ if (anyOf !== void 0) return sampleFromSchemaInner(anyOf[0] ?? {}, nextContext(context));
212
+ const type = schema.type;
213
+ if (Array.isArray(type)) return sampleFromSchemaInner({
214
+ ...schema,
215
+ type: type.find((part) => part !== "null") ?? type[0]
216
+ }, context);
217
+ if (type === "object" || isRecord(schema.properties)) {
218
+ const properties = isRecord(schema.properties) ? schema.properties : {};
219
+ return Object.fromEntries(Object.entries(properties).filter((entry) => isRecord(entry[1])).map(([name, value]) => [name, sampleFromSchemaInner(value, nextContext(context))]));
220
+ }
221
+ if (type === "array" || schema.items !== void 0) {
222
+ const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;
223
+ return [isRecord(items) ? sampleFromSchemaInner(items, nextContext(context)) : null];
224
+ }
225
+ if (type === "number" || type === "integer") return 1;
226
+ if (type === "boolean") return true;
227
+ if (type === "null") return null;
228
+ if (type === "string" || type === void 0) {
229
+ const examples = asArray(schema.examples);
230
+ if (examples?.[0] !== void 0) return examples[0];
231
+ const format = firstString(schema.format);
232
+ if (format === "uri" || format === "url") return "https://example.com";
233
+ if (format === "date-time") return "2026-01-01T00:00:00.000Z";
234
+ if (format === "date") return "2026-01-01";
235
+ return "string";
236
+ }
237
+ return null;
357
238
  }
358
239
  function firstInputExample(tool) {
359
- const examples = asArray(tool.inputExamples);
360
- const first = examples?.[0];
361
- return isRecord(first) && "input" in first ? first.input : void 0;
240
+ const first = asArray(tool.inputExamples)?.[0];
241
+ return isRecord(first) && "input" in first ? first.input : void 0;
362
242
  }
363
243
  function resolveRef(ref, root, seenRefs) {
364
- if (!ref.startsWith("#/") || seenRefs.has(ref)) {
365
- return void 0;
366
- }
367
- seenRefs.add(ref);
368
- const value = ref.slice(2).split("/").map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~")).reduce((current, part) => {
369
- if (!isRecord(current)) {
370
- return void 0;
371
- }
372
- return current[part];
373
- }, root);
374
- return isRecord(value) ? value : void 0;
244
+ if (!ref.startsWith("#/") || seenRefs.has(ref)) return;
245
+ seenRefs.add(ref);
246
+ const value = ref.slice(2).split("/").map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~")).reduce((current, part) => {
247
+ if (!isRecord(current)) return;
248
+ return current[part];
249
+ }, root);
250
+ return isRecord(value) ? value : void 0;
375
251
  }
376
252
  function nextContext(context) {
377
- return {
378
- ...context,
379
- depth: context.depth + 1
380
- };
253
+ return {
254
+ ...context,
255
+ depth: context.depth + 1
256
+ };
381
257
  }
382
258
  function union(types) {
383
- const unique = [...new Set(types)];
384
- return unique.length === 0 ? "unknown" : unique.join(" | ");
259
+ const unique = [...new Set(types)];
260
+ return unique.length === 0 ? "unknown" : unique.join(" | ");
385
261
  }
386
262
  function literalType(value) {
387
- if (typeof value === "string") {
388
- return JSON.stringify(value);
389
- }
390
- if (typeof value === "number" || typeof value === "boolean" || value === null) {
391
- return String(value);
392
- }
393
- return "unknown";
263
+ if (typeof value === "string") return JSON.stringify(value);
264
+ if (typeof value === "number" || typeof value === "boolean" || value === null) return String(value);
265
+ return "unknown";
394
266
  }
395
267
  function indentType(type, spaces) {
396
- if (!type.includes("\n")) {
397
- return type;
398
- }
399
- const padding = " ".repeat(spaces);
400
- return type.replaceAll("\n", `
401
- ${padding}`);
268
+ if (!type.includes("\n")) return type;
269
+ const padding = " ".repeat(spaces);
270
+ return type.replaceAll("\n", `\n${padding}`);
402
271
  }
403
272
  function needsParentheses(type) {
404
- return type.includes(" | ") || type.includes(" & ");
273
+ return type.includes(" | ") || type.includes(" & ");
405
274
  }
406
275
  function formatObjectKey(key) {
407
- return isIdentifier(key) ? key : JSON.stringify(key);
276
+ return isIdentifier(key) ? key : JSON.stringify(key);
408
277
  }
409
278
  function formatPropertyAccess(key) {
410
- return isIdentifier(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
279
+ return isIdentifier(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
411
280
  }
412
281
  function uniqueToolVariableNames(toolNames) {
413
- const seen = /* @__PURE__ */ new Map();
414
- return toolNames.map((toolName) => {
415
- const base = toIdentifier(toolName);
416
- const count = seen.get(base) ?? 0;
417
- seen.set(base, count + 1);
418
- return count === 0 ? base : `${base}${count + 1}`;
419
- });
282
+ const seen = /* @__PURE__ */ new Map();
283
+ return toolNames.map((toolName) => {
284
+ const base = toIdentifier(toolName);
285
+ const count = seen.get(base) ?? 0;
286
+ seen.set(base, count + 1);
287
+ return count === 0 ? base : `${base}${count + 1}`;
288
+ });
420
289
  }
421
290
  function toIdentifier(value) {
422
- const identifier = value.replace(/[^A-Za-z0-9_$]/g, "_").replace(/^[^A-Za-z_$]+/, "");
423
- return identifier.length === 0 ? "tool" : identifier;
291
+ const identifier = value.replace(/[^A-Za-z0-9_$]/g, "_").replace(/^[^A-Za-z_$]+/, "");
292
+ return identifier.length === 0 ? "tool" : identifier;
424
293
  }
425
294
  function isIdentifier(value) {
426
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);
295
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);
427
296
  }
428
297
  function compactObjectType(lines) {
429
- if (lines.length === 0 || lines.some((line) => line.includes("/**"))) {
430
- return void 0;
431
- }
432
- const fields = lines.map((line) => line.trim());
433
- if (fields.some((field) => field.includes("\n"))) {
434
- return void 0;
435
- }
436
- const compact = `{ ${fields.join(" ")} }`;
437
- return compact.length <= MAX_COMPACT_OBJECT_TYPE_LENGTH ? compact : void 0;
298
+ if (lines.length === 0 || lines.some((line) => line.includes("/**"))) return;
299
+ const fields = lines.map((line) => line.trim());
300
+ if (fields.some((field) => field.includes("\n"))) return;
301
+ const compact = `{ ${fields.join(" ")} }`;
302
+ return compact.length <= MAX_COMPACT_OBJECT_TYPE_LENGTH ? compact : void 0;
438
303
  }
439
304
  function toComment(value) {
440
- return value.replaceAll("*/", "* /").replace(/\s+/g, " ").trim();
305
+ return value.replaceAll("*/", "* /").replace(/\s+/g, " ").trim();
441
306
  }
442
307
  function firstString(...values) {
443
- return values.find(isString);
308
+ return values.find(isString);
444
309
  }
445
310
  function schemaArray(value) {
446
- const values = asArray(value);
447
- if (values === void 0 || !values.every(isRecord)) {
448
- return void 0;
449
- }
450
- return values;
311
+ const values = asArray(value);
312
+ if (values === void 0 || !values.every(isRecord)) return;
313
+ return values;
451
314
  }
452
315
  function asArray(value) {
453
- return Array.isArray(value) ? value : void 0;
316
+ return Array.isArray(value) ? value : void 0;
454
317
  }
455
318
  function isRecord(value) {
456
- return typeof value === "object" && value !== null && !Array.isArray(value);
319
+ return typeof value === "object" && value !== null && !Array.isArray(value);
457
320
  }
458
321
  function isString(value) {
459
- return typeof value === "string";
322
+ return typeof value === "string";
460
323
  }
461
324
  function isPromiseLike(value) {
462
- return isRecord(value) && typeof value.then === "function";
325
+ return isRecord(value) && typeof value.then === "function";
463
326
  }
464
- export {
465
- buildCodeModeToolCatalogMessage,
466
- buildCodeModeToolDescription
467
- };
327
+ //#endregion
328
+ export { buildCodeModeToolCatalogMessage, buildCodeModeToolDescription };
329
+
468
330
  //# sourceMappingURL=tool-prompt.js.map