@cloudflare/codemode 0.5.2 → 0.5.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.
- package/dist/ai.d.ts +3 -3
- package/dist/ai.js +60 -15
- package/dist/ai.js.map +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/{executor-DkMGH_7-.d.ts → executor-DLwvEPC7.d.ts} +2 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/{resolve-tqDt6Djo.d.ts → resolve-BFB4vzhC.d.ts} +2 -2
- package/dist/{shared-BOF2IKt-.d.ts → shared-B1Rs0ONk.d.ts} +2 -2
- package/dist/tanstack-ai.d.ts +3 -3
- package/docs/index.md +2 -0
- package/package.json +2 -2
package/dist/ai.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
i as ToolProvider,
|
|
5
5
|
p as generateTypes,
|
|
6
6
|
u as ResolvedProvider
|
|
7
|
-
} from "./executor-
|
|
7
|
+
} from "./executor-DLwvEPC7.js";
|
|
8
8
|
import {
|
|
9
9
|
n as CodeOutput,
|
|
10
10
|
r as CreateCodeToolOptions,
|
|
11
11
|
t as CodeInput
|
|
12
|
-
} from "./shared-
|
|
12
|
+
} from "./shared-B1Rs0ONk.js";
|
|
13
13
|
import {
|
|
14
14
|
r as ConnectorTools,
|
|
15
15
|
t as CodemodeConnector
|
|
@@ -58,7 +58,7 @@ declare class ToolSetConnector extends CodemodeConnector {
|
|
|
58
58
|
);
|
|
59
59
|
name(): string;
|
|
60
60
|
protected instructions(): string | undefined;
|
|
61
|
-
protected tools(): ConnectorTools
|
|
61
|
+
protected tools(): Promise<ConnectorTools>;
|
|
62
62
|
/**
|
|
63
63
|
* Generate the sandbox type block from the original AI SDK schemas (Zod or
|
|
64
64
|
* `jsonSchema()` wrappers) rather than the converted JSON Schema, preserving
|
package/dist/ai.js
CHANGED
|
@@ -76,6 +76,14 @@ function extractParamDescriptions(schema) {
|
|
|
76
76
|
const descriptions = extractDescriptions(schema);
|
|
77
77
|
return Object.entries(descriptions).map(([fieldName, desc]) => `@param input.${fieldName} - ${desc}`);
|
|
78
78
|
}
|
|
79
|
+
function jsonSchemaToTypeDecl(jsonSchema, typeName) {
|
|
80
|
+
return `type ${typeName} = ${jsonSchemaToTypeString(jsonSchema, "", {
|
|
81
|
+
root: jsonSchema,
|
|
82
|
+
depth: 0,
|
|
83
|
+
seen: /* @__PURE__ */ new Set(),
|
|
84
|
+
maxDepth: 20
|
|
85
|
+
})}`;
|
|
86
|
+
}
|
|
79
87
|
/**
|
|
80
88
|
* Safely convert a schema to TypeScript type string.
|
|
81
89
|
* Handles Zod schemas (v3/v4) and AI SDK jsonSchema wrappers.
|
|
@@ -84,21 +92,11 @@ function safeSchemaToTs(schema, typeName) {
|
|
|
84
92
|
try {
|
|
85
93
|
if (isZodSchema(schema) || isStandardSchema(schema)) {
|
|
86
94
|
const jsonSchema = asSchema(schema).jsonSchema;
|
|
87
|
-
if (jsonSchema) return
|
|
88
|
-
root: jsonSchema,
|
|
89
|
-
depth: 0,
|
|
90
|
-
seen: /* @__PURE__ */ new Set(),
|
|
91
|
-
maxDepth: 20
|
|
92
|
-
})}`;
|
|
95
|
+
if (jsonSchema) return jsonSchemaToTypeDecl(jsonSchema, typeName);
|
|
93
96
|
}
|
|
94
97
|
if (isJsonSchemaWrapper(schema)) {
|
|
95
98
|
const jsonSchema = extractJsonSchema(schema);
|
|
96
|
-
if (jsonSchema) return
|
|
97
|
-
root: jsonSchema,
|
|
98
|
-
depth: 0,
|
|
99
|
-
seen: /* @__PURE__ */ new Set(),
|
|
100
|
-
maxDepth: 20
|
|
101
|
-
})}`;
|
|
99
|
+
if (jsonSchema) return jsonSchemaToTypeDecl(jsonSchema, typeName);
|
|
102
100
|
}
|
|
103
101
|
return `type ${typeName} = unknown`;
|
|
104
102
|
} catch {
|
|
@@ -106,6 +104,34 @@ function safeSchemaToTs(schema, typeName) {
|
|
|
106
104
|
}
|
|
107
105
|
}
|
|
108
106
|
/**
|
|
107
|
+
* JSON Schema for the value a schema *produces*, from its Standard JSON
|
|
108
|
+
* Schema converter (Zod 4, Valibot, ArkType, ...). AI SDK's `asSchema`
|
|
109
|
+
* always converts the input side, which is wrong for a tool's output:
|
|
110
|
+
* `.default()` fields come out optional and `.pipe()` keeps the pre-pipe
|
|
111
|
+
* type.
|
|
112
|
+
*
|
|
113
|
+
* Returns `undefined` when the schema has no such converter (Zod 3,
|
|
114
|
+
* `jsonSchema()` wrappers, whose input and output are the same). Throws when
|
|
115
|
+
* the output can't be represented in JSON Schema (e.g. `.transform()`);
|
|
116
|
+
* callers treat that as `unknown` rather than falling back to the input type.
|
|
117
|
+
*/
|
|
118
|
+
function standardOutputJsonSchema(schema) {
|
|
119
|
+
if (!isStandardSchema(schema)) return void 0;
|
|
120
|
+
const converter = schema["~standard"].jsonSchema;
|
|
121
|
+
if (typeof converter?.output !== "function") return void 0;
|
|
122
|
+
return converter.output({ target: "draft-07" });
|
|
123
|
+
}
|
|
124
|
+
/** Like `safeSchemaToTs`, but types the value the schema produces. */
|
|
125
|
+
function safeOutputSchemaToTs(schema, typeName) {
|
|
126
|
+
let jsonSchema;
|
|
127
|
+
try {
|
|
128
|
+
jsonSchema = standardOutputJsonSchema(schema);
|
|
129
|
+
} catch {
|
|
130
|
+
return `type ${typeName} = unknown`;
|
|
131
|
+
}
|
|
132
|
+
return jsonSchema ? jsonSchemaToTypeDecl(jsonSchema, typeName) : safeSchemaToTs(schema, typeName);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
109
135
|
* Generate TypeScript type definitions from tool descriptors or an AI SDK ToolSet.
|
|
110
136
|
* These types can be included in tool descriptions to help LLMs write correct code.
|
|
111
137
|
*
|
|
@@ -123,7 +149,7 @@ function generateTypes(tools, namespace = "codemode") {
|
|
|
123
149
|
const outputSchema = "outputSchema" in tool ? tool.outputSchema : void 0;
|
|
124
150
|
const description = tool.description;
|
|
125
151
|
const inputType = safeSchemaToTs(inputSchema, `${typeName}Input`);
|
|
126
|
-
const outputType = outputSchema ?
|
|
152
|
+
const outputType = outputSchema ? safeOutputSchemaToTs(outputSchema, `${typeName}Output`) : `type ${typeName}Output = unknown`;
|
|
127
153
|
availableTypes += `\n${inputType.trim()}`;
|
|
128
154
|
availableTypes += `\n${outputType.trim()}`;
|
|
129
155
|
const paramDescs = (() => {
|
|
@@ -274,7 +300,7 @@ var ToolSetConnector = class extends CodemodeConnector {
|
|
|
274
300
|
instructions() {
|
|
275
301
|
return this.#options.instructions;
|
|
276
302
|
}
|
|
277
|
-
tools() {
|
|
303
|
+
async tools() {
|
|
278
304
|
const out = {};
|
|
279
305
|
const sources = /* @__PURE__ */ new Map();
|
|
280
306
|
for (const [toolName, t] of Object.entries(this.#executableTools())) {
|
|
@@ -285,11 +311,14 @@ var ToolSetConnector = class extends CodemodeConnector {
|
|
|
285
311
|
sources.set(name, toolName);
|
|
286
312
|
const rawSchema = "inputSchema" in t ? t.inputSchema : t.parameters;
|
|
287
313
|
const schema = rawSchema != null ? asSchema(rawSchema) : void 0;
|
|
314
|
+
const inputSchema = schema ? await schema.jsonSchema : void 0;
|
|
315
|
+
const outputSchema = await outputJsonSchema(t.outputSchema);
|
|
288
316
|
const needsApproval = t.needsApproval;
|
|
289
317
|
const requiresApproval = needsApproval !== void 0 && needsApproval !== false;
|
|
290
318
|
out[name] = {
|
|
291
319
|
description: typeof t.description === "function" ? void 0 : t.description,
|
|
292
|
-
inputSchema
|
|
320
|
+
inputSchema,
|
|
321
|
+
...outputSchema ? { outputSchema } : {},
|
|
293
322
|
...requiresApproval ? { requiresApproval: true } : {},
|
|
294
323
|
execute: schema?.validate ? async (args) => {
|
|
295
324
|
const result = await schema.validate(args);
|
|
@@ -311,6 +340,22 @@ var ToolSetConnector = class extends CodemodeConnector {
|
|
|
311
340
|
return generateTypes(this.#executableTools(), this.name());
|
|
312
341
|
}
|
|
313
342
|
};
|
|
343
|
+
/**
|
|
344
|
+
* Convert a tool's output schema to JSON Schema for its descriptor, using
|
|
345
|
+
* the output side of the schema where the library exposes it (see
|
|
346
|
+
* `standardOutputJsonSchema`). The output type is advisory, so a schema that
|
|
347
|
+
* cannot be converted (it throws or its promise rejects) is left out and
|
|
348
|
+
* shows as `unknown`, matching `generateTypes`, instead of failing the whole
|
|
349
|
+
* toolset.
|
|
350
|
+
*/
|
|
351
|
+
async function outputJsonSchema(raw) {
|
|
352
|
+
if (raw == null) return void 0;
|
|
353
|
+
try {
|
|
354
|
+
return standardOutputJsonSchema(raw) ?? await asSchema(raw).jsonSchema;
|
|
355
|
+
} catch {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
314
359
|
/** Convenience constructor mirroring `stateConnector` / `new BrowserConnector`. */
|
|
315
360
|
function toolSetConnector(ctx, options) {
|
|
316
361
|
return new ToolSetConnector(ctx, options);
|
package/dist/ai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.js","names":["#options","#warnedSkipped","#executableTools"],"sources":["../src/tool-types.ts","../src/tool.ts","../src/connectors/toolset.ts"],"sourcesContent":["import { asSchema } from \"ai\";\nimport type { ZodType } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { sanitizeToolName, toPascalCase, escapeJsDoc } from \"./utils\";\nimport {\n jsonSchemaToTypeString,\n type ConversionContext\n} from \"./json-schema-types\";\n\nexport interface ToolDescriptor {\n description?: string;\n inputSchema: ZodType;\n outputSchema?: ZodType;\n execute?: (args: unknown) => Promise<unknown>;\n}\n\nexport type ToolDescriptors = Record<string, ToolDescriptor>;\n\n/**\n * Check if a value is a Zod schema (has _zod property).\n */\nfunction isZodSchema(value: unknown): value is ZodType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"_zod\" in value &&\n (value as { _zod?: unknown })._zod !== undefined\n );\n}\n\n/**\n * Check if a value conforms to the Standard Schema protocol (~standard).\n * This catches Zod v3 schemas (which expose ~standard but not _zod).\n */\nfunction isStandardSchema(value: unknown): boolean {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"~standard\" in value &&\n (value as Record<string, unknown>)[\"~standard\"] !== undefined\n );\n}\n\n/**\n * Check if a value is an AI SDK jsonSchema wrapper.\n * The jsonSchema wrapper has a [Symbol] with jsonSchema property.\n */\nfunction isJsonSchemaWrapper(\n value: unknown\n): value is { jsonSchema: JSONSchema7 } {\n if (value === null || typeof value !== \"object\") return false;\n\n if (\"jsonSchema\" in value) {\n return true;\n }\n\n const symbols = Object.getOwnPropertySymbols(value);\n for (const sym of symbols) {\n const symValue = (value as Record<symbol, unknown>)[sym];\n if (symValue && typeof symValue === \"object\" && \"jsonSchema\" in symValue) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Extract JSON schema from an AI SDK jsonSchema wrapper.\n */\nfunction extractJsonSchema(wrapper: unknown): JSONSchema7 | null {\n if (wrapper === null || typeof wrapper !== \"object\") return null;\n\n if (\"jsonSchema\" in wrapper) {\n return (wrapper as { jsonSchema: JSONSchema7 }).jsonSchema;\n }\n\n const symbols = Object.getOwnPropertySymbols(wrapper);\n for (const sym of symbols) {\n const symValue = (wrapper as Record<symbol, unknown>)[sym];\n if (symValue && typeof symValue === \"object\" && \"jsonSchema\" in symValue) {\n return (symValue as { jsonSchema: JSONSchema7 }).jsonSchema;\n }\n }\n\n return null;\n}\n\n/**\n * Extract field descriptions from a schema.\n * Works with Zod schemas (via .shape) and jsonSchema wrappers (via .properties).\n */\nfunction extractDescriptions(schema: unknown): Record<string, string> {\n const descriptions: Record<string, string> = {};\n\n const shape = (schema as { shape?: Record<string, ZodType> }).shape;\n if (shape && typeof shape === \"object\") {\n for (const [fieldName, fieldSchema] of Object.entries(shape)) {\n let s = fieldSchema as { description?: string; unwrap?: () => unknown };\n while (!s.description && typeof s.unwrap === \"function\") {\n s = s.unwrap() as typeof s;\n }\n if (s.description) {\n descriptions[fieldName] = s.description;\n }\n }\n return descriptions;\n }\n\n if (isJsonSchemaWrapper(schema)) {\n const jsonSchema = extractJsonSchema(schema);\n if (jsonSchema?.properties) {\n for (const [fieldName, propSchema] of Object.entries(\n jsonSchema.properties\n )) {\n if (\n propSchema &&\n typeof propSchema === \"object\" &&\n propSchema.description\n ) {\n descriptions[fieldName] = propSchema.description;\n }\n }\n }\n }\n\n return descriptions;\n}\n\n/**\n * Extract field descriptions from a schema and format as @param lines.\n */\nfunction extractParamDescriptions(schema: unknown): string[] {\n const descriptions = extractDescriptions(schema);\n return Object.entries(descriptions).map(\n ([fieldName, desc]) => `@param input.${fieldName} - ${desc}`\n );\n}\n\n/**\n * Safely convert a schema to TypeScript type string.\n * Handles Zod schemas (v3/v4) and AI SDK jsonSchema wrappers.\n */\nfunction safeSchemaToTs(schema: unknown, typeName: string): string {\n try {\n if (isZodSchema(schema) || isStandardSchema(schema)) {\n const wrapped = asSchema(schema as ZodType);\n const jsonSchema = wrapped.jsonSchema as JSONSchema7;\n if (jsonSchema) {\n const ctx: ConversionContext = {\n root: jsonSchema,\n depth: 0,\n seen: new Set(),\n maxDepth: 20\n };\n const typeBody = jsonSchemaToTypeString(jsonSchema, \"\", ctx);\n return `type ${typeName} = ${typeBody}`;\n }\n }\n\n if (isJsonSchemaWrapper(schema)) {\n const jsonSchema = extractJsonSchema(schema);\n if (jsonSchema) {\n const ctx: ConversionContext = {\n root: jsonSchema,\n depth: 0,\n seen: new Set(),\n maxDepth: 20\n };\n const typeBody = jsonSchemaToTypeString(jsonSchema, \"\", ctx);\n return `type ${typeName} = ${typeBody}`;\n }\n }\n\n return `type ${typeName} = unknown`;\n } catch {\n return `type ${typeName} = unknown`;\n }\n}\n\n/**\n * Generate TypeScript type definitions from tool descriptors or an AI SDK ToolSet.\n * These types can be included in tool descriptions to help LLMs write correct code.\n *\n * Requires the `ai` peer dependency. For a version that works with plain JSON Schema\n * objects (no AI SDK), use `generateTypesFromJsonSchema` from the main entry point.\n */\nexport function generateTypes(\n tools: ToolDescriptors | ToolSet,\n namespace = \"codemode\"\n): string {\n let availableTools = \"\";\n let availableTypes = \"\";\n\n for (const [toolName, tool] of Object.entries(tools)) {\n const safeName = sanitizeToolName(toolName);\n const typeName = toPascalCase(safeName);\n\n try {\n const inputSchema =\n \"inputSchema\" in tool ? tool.inputSchema : tool.parameters;\n const outputSchema =\n \"outputSchema\" in tool ? tool.outputSchema : undefined;\n const description = tool.description;\n\n const inputType = safeSchemaToTs(inputSchema, `${typeName}Input`);\n\n const outputType = outputSchema\n ? safeSchemaToTs(outputSchema, `${typeName}Output`)\n : `type ${typeName}Output = unknown`;\n\n availableTypes += `\\n${inputType.trim()}`;\n availableTypes += `\\n${outputType.trim()}`;\n\n const paramDescs = (() => {\n try {\n return inputSchema ? extractParamDescriptions(inputSchema) : [];\n } catch {\n return [];\n }\n })();\n const jsdocLines: string[] = [];\n if (description?.trim()) {\n jsdocLines.push(escapeJsDoc(description.trim().replace(/\\r?\\n/g, \" \")));\n } else {\n jsdocLines.push(escapeJsDoc(toolName));\n }\n for (const pd of paramDescs) {\n jsdocLines.push(escapeJsDoc(pd.replace(/\\r?\\n/g, \" \")));\n }\n\n const jsdocBody = jsdocLines.map((l) => `\\t * ${l}`).join(\"\\n\");\n availableTools += `\\n\\t/**\\n${jsdocBody}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;\n availableTools += \"\\n\";\n } catch {\n availableTypes += `\\ntype ${typeName}Input = unknown`;\n availableTypes += `\\ntype ${typeName}Output = unknown`;\n\n availableTools += `\\n\\t/**\\n\\t * ${escapeJsDoc(toolName)}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;\n availableTools += \"\\n\";\n }\n }\n\n availableTools = `\\ndeclare const ${namespace}: {${availableTools}}`;\n\n return `\n${availableTypes}\n${availableTools}\n `.trim();\n}\n","import { tool, type Tool, asSchema } from \"ai\";\nimport { z } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport { generateTypes, type ToolDescriptors } from \"./tool-types\";\nimport type {\n ToolProvider,\n ToolProviderTools,\n ResolvedProvider\n} from \"./executor\";\nimport { runCode } from \"./run-code\";\nimport { filterTools } from \"./resolve\";\nimport {\n DEFAULT_DESCRIPTION,\n type CreateCodeToolOptions,\n type CodeInput,\n type CodeOutput,\n normalizeProviders\n} from \"./shared\";\nexport type { CreateCodeToolOptions, CodeInput, CodeOutput } from \"./shared\";\nexport { DEFAULT_DESCRIPTION, normalizeProviders } from \"./shared\";\n\nconst codeSchema = z.object({\n code: z.string().describe(\"JavaScript async arrow function to execute\")\n});\n\n/**\n * Extract execute functions from tools, keyed by name.\n * Wraps each with schema validation via AI SDK's `asSchema` when available.\n */\nfunction extractFns(\n tools: ToolProviderTools\n): Record<string, (...args: unknown[]) => Promise<unknown>> {\n const fns: Record<string, (...args: unknown[]) => Promise<unknown>> = {};\n\n for (const [name, t] of Object.entries(tools)) {\n const execute =\n \"execute\" in t\n ? (t.execute as (args: unknown) => Promise<unknown>)\n : undefined;\n if (execute) {\n const rawSchema =\n \"inputSchema\" in t\n ? t.inputSchema\n : \"parameters\" in t\n ? (t as Record<string, unknown>).parameters\n : undefined;\n\n const schema = rawSchema != null ? asSchema(rawSchema) : undefined;\n\n fns[name] = schema?.validate\n ? async (args: unknown) => {\n const result = await schema.validate!(args);\n if (!result.success) throw result.error;\n return execute(result.value);\n }\n : execute;\n }\n }\n\n return fns;\n}\n\n/**\n * Wrap raw AI SDK tools into a ToolProvider under the default \"codemode\" namespace.\n *\n * @example\n * ```ts\n * createCodeTool({\n * tools: [stateTools(workspace), aiTools(myTools)],\n * executor,\n * });\n * ```\n */\nexport function aiTools(tools: ToolDescriptors | ToolSet): ToolProvider {\n return { tools };\n}\n\n/**\n * Resolve a ToolProvider into a ResolvedProvider ready for execution.\n * Filters out tools with `needsApproval` and validates inputs via AI SDK's `asSchema`.\n */\nexport function resolveProvider(provider: ToolProvider): ResolvedProvider {\n const name = provider.name ?? \"codemode\";\n const filtered = filterTools(provider.tools);\n const resolved: ResolvedProvider = { name, fns: extractFns(filtered) };\n return resolved;\n}\n\nexport function createCodeTool(\n options: CreateCodeToolOptions\n): Tool<CodeInput, CodeOutput> {\n const providers = normalizeProviders(options.tools);\n\n // Build type block and resolved providers for each provider.\n const typeBlocks: string[] = [];\n const resolvedProviders: ResolvedProvider[] = [];\n\n for (const provider of providers) {\n const name = provider.name ?? \"codemode\";\n const filtered = filterTools(provider.tools);\n const types =\n provider.types ?? generateTypes(filtered as ToolDescriptors, name);\n typeBlocks.push(types);\n resolvedProviders.push({ name, fns: extractFns(filtered) });\n }\n\n const typeBlock = typeBlocks.filter(Boolean).join(\"\\n\\n\");\n\n const executor = options.executor;\n\n const description = (options.description ?? DEFAULT_DESCRIPTION).replace(\n \"{{types}}\",\n typeBlock\n );\n\n return tool({\n description,\n inputSchema: codeSchema,\n execute: async ({ code }) =>\n runCode({ code, executor, providers: resolvedProviders })\n });\n}\n","/**\n * ToolSetConnector — adapt an AI SDK `ToolSet` to the connector model.\n *\n * Each tool in the set becomes one connector tool under a single namespace\n * (default `\"tools\"`). Tools with `needsApproval` map to `requiresApproval`:\n * calling one pauses the run durably until the host approves\n * (`runtime.approve()`), then the run resumes where it stopped — the\n * runtime's pause/approve/resume flow, not the AI SDK's per-call approval.\n * A function-valued `needsApproval` cannot be evaluated against sandbox\n * arguments ahead of time, so it conservatively always requires approval.\n *\n * Lives in the `/ai` entry because schema handling (`asSchema`) needs the\n * `ai` peer dependency.\n */\nimport { asSchema } from \"ai\";\nimport type { ToolSet } from \"ai\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { generateTypes } from \"../tool-types\";\nimport { sanitizeToolName } from \"../utils\";\nimport { CodemodeConnector, type ConnectorTools } from \"./base\";\n\nexport interface ToolSetConnectorOptions {\n /**\n * The namespace the sandbox sees, e.g. `\"tools\"` → `tools.getWeather(...)`.\n * Defaults to `\"tools\"`. (`\"codemode\"` is reserved for the platform SDK.)\n */\n name?: string;\n /** Extra model guidance, surfaced with the connector's type block. */\n instructions?: string;\n /** The AI SDK tools to expose. */\n tools: ToolSet;\n}\n\nexport class ToolSetConnector extends CodemodeConnector {\n #options: ToolSetConnectorOptions;\n #warnedSkipped = false;\n\n constructor(\n ctx: DurableObjectState | ExecutionContext,\n options: ToolSetConnectorOptions\n ) {\n super(ctx, {});\n this.#options = options;\n }\n\n /**\n * Only tools with an `execute` function can run inside the sandbox.\n * Execute-less tools (client-side / provider-executed) are excluded from\n * both the runtime bindings and the generated types — advertising a method\n * the sandbox can't call would send the model down a dead end.\n */\n #executableTools(): ToolSet {\n const executable: ToolSet = {};\n const skipped: string[] = [];\n for (const [toolName, t] of Object.entries(this.#options.tools)) {\n if (\"execute\" in t && typeof t.execute === \"function\") {\n executable[toolName] = t;\n } else {\n skipped.push(toolName);\n }\n }\n if (skipped.length > 0 && !this.#warnedSkipped) {\n this.#warnedSkipped = true;\n console.warn(\n `[codemode] ToolSetConnector \"${this.name()}\" skipped tools without ` +\n `an execute function (client-side or provider-executed): ` +\n `${skipped.join(\", \")}. They are not callable from sandboxed code.`\n );\n }\n return executable;\n }\n\n override name(): string {\n return this.#options.name ?? \"tools\";\n }\n\n protected override instructions(): string | undefined {\n return this.#options.instructions;\n }\n\n protected override tools(): ConnectorTools {\n const out: ConnectorTools = {};\n const sources = new Map<string, string>();\n for (const [toolName, t] of Object.entries(this.#executableTools())) {\n const execute = t.execute as (args: unknown) => Promise<unknown>;\n\n const name = sanitizeToolName(toolName);\n const existing = sources.get(name);\n if (existing !== undefined) {\n throw new Error(\n `Tools \"${existing}\" and \"${toolName}\" on ${this.name()} both ` +\n `map to \"${name}\" — rename one of them.`\n );\n }\n sources.set(name, toolName);\n\n const rawSchema =\n \"inputSchema\" in t\n ? t.inputSchema\n : (t as Record<string, unknown>).parameters;\n const schema =\n rawSchema != null\n ? asSchema(rawSchema as Parameters<typeof asSchema>[0])\n : undefined;\n\n // boolean `false` means no approval; `true` or a function (which can't\n // be pre-evaluated against sandbox args) gates the call behind the\n // runtime's durable pause/approve/resume flow.\n const needsApproval = (t as { needsApproval?: unknown }).needsApproval;\n const requiresApproval =\n needsApproval !== undefined && needsApproval !== false;\n\n out[name] = {\n description:\n typeof t.description === \"function\" ? undefined : t.description,\n inputSchema: schema?.jsonSchema as JSONSchema7 | undefined,\n ...(requiresApproval ? { requiresApproval: true } : {}),\n execute: schema?.validate\n ? async (args: unknown) => {\n const result = await schema.validate!(args);\n if (!result.success) throw result.error;\n return execute(result.value);\n }\n : (args: unknown) => execute(args)\n };\n }\n return out;\n }\n\n /**\n * Generate the sandbox type block from the original AI SDK schemas (Zod or\n * `jsonSchema()` wrappers) rather than the converted JSON Schema, preserving\n * field descriptions as `@param` lines. Restricted to the same executable\n * subset that `tools()` exposes, so the types never advertise a method the\n * sandbox can't call.\n */\n override async getTypeScriptTypes(): Promise<string> {\n return generateTypes(this.#executableTools(), this.name());\n }\n}\n\n/** Convenience constructor mirroring `stateConnector` / `new BrowserConnector`. */\nexport function toolSetConnector(\n ctx: DurableObjectState | ExecutionContext,\n options: ToolSetConnectorOptions\n): ToolSetConnector {\n return new ToolSetConnector(ctx, options);\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAS,YAAY,OAAkC;CACrD,OACE,UAAU,QACV,OAAO,UAAU,YACjB,UAAU,SACT,MAA6B,SAAS,KAAA;AAE3C;;;;;AAMA,SAAS,iBAAiB,OAAyB;CACjD,OACE,UAAU,QACV,OAAO,UAAU,YACjB,eAAe,SACd,MAAkC,iBAAiB,KAAA;AAExD;;;;;AAMA,SAAS,oBACP,OACsC;CACtC,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CAExD,IAAI,gBAAgB,OAClB,OAAO;CAGT,MAAM,UAAU,OAAO,sBAAsB,KAAK;CAClD,KAAK,MAAM,OAAO,SAAS;EACzB,MAAM,WAAY,MAAkC;EACpD,IAAI,YAAY,OAAO,aAAa,YAAY,gBAAgB,UAC9D,OA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B;CAClB,OAAO,IAAI,iBAAiB,KAAK,OAAO;AAC1C"}
|
|
1
|
+
{"version":3,"file":"ai.js","names":["#options","#warnedSkipped","#executableTools"],"sources":["../src/tool-types.ts","../src/tool.ts","../src/connectors/toolset.ts"],"sourcesContent":["import { asSchema } from \"ai\";\nimport type { ZodType } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { sanitizeToolName, toPascalCase, escapeJsDoc } from \"./utils\";\nimport {\n jsonSchemaToTypeString,\n type ConversionContext\n} from \"./json-schema-types\";\n\nexport interface ToolDescriptor {\n description?: string;\n inputSchema: ZodType;\n outputSchema?: ZodType;\n execute?: (args: unknown) => Promise<unknown>;\n}\n\nexport type ToolDescriptors = Record<string, ToolDescriptor>;\n\n/**\n * Check if a value is a Zod schema (has _zod property).\n */\nfunction isZodSchema(value: unknown): value is ZodType {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"_zod\" in value &&\n (value as { _zod?: unknown })._zod !== undefined\n );\n}\n\n/**\n * Check if a value conforms to the Standard Schema protocol (~standard).\n * This catches Zod v3 schemas (which expose ~standard but not _zod).\n */\nfunction isStandardSchema(value: unknown): boolean {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"~standard\" in value &&\n (value as Record<string, unknown>)[\"~standard\"] !== undefined\n );\n}\n\n/**\n * Check if a value is an AI SDK jsonSchema wrapper.\n * The jsonSchema wrapper has a [Symbol] with jsonSchema property.\n */\nfunction isJsonSchemaWrapper(\n value: unknown\n): value is { jsonSchema: JSONSchema7 } {\n if (value === null || typeof value !== \"object\") return false;\n\n if (\"jsonSchema\" in value) {\n return true;\n }\n\n const symbols = Object.getOwnPropertySymbols(value);\n for (const sym of symbols) {\n const symValue = (value as Record<symbol, unknown>)[sym];\n if (symValue && typeof symValue === \"object\" && \"jsonSchema\" in symValue) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Extract JSON schema from an AI SDK jsonSchema wrapper.\n */\nfunction extractJsonSchema(wrapper: unknown): JSONSchema7 | null {\n if (wrapper === null || typeof wrapper !== \"object\") return null;\n\n if (\"jsonSchema\" in wrapper) {\n return (wrapper as { jsonSchema: JSONSchema7 }).jsonSchema;\n }\n\n const symbols = Object.getOwnPropertySymbols(wrapper);\n for (const sym of symbols) {\n const symValue = (wrapper as Record<symbol, unknown>)[sym];\n if (symValue && typeof symValue === \"object\" && \"jsonSchema\" in symValue) {\n return (symValue as { jsonSchema: JSONSchema7 }).jsonSchema;\n }\n }\n\n return null;\n}\n\n/**\n * Extract field descriptions from a schema.\n * Works with Zod schemas (via .shape) and jsonSchema wrappers (via .properties).\n */\nfunction extractDescriptions(schema: unknown): Record<string, string> {\n const descriptions: Record<string, string> = {};\n\n const shape = (schema as { shape?: Record<string, ZodType> }).shape;\n if (shape && typeof shape === \"object\") {\n for (const [fieldName, fieldSchema] of Object.entries(shape)) {\n let s = fieldSchema as { description?: string; unwrap?: () => unknown };\n while (!s.description && typeof s.unwrap === \"function\") {\n s = s.unwrap() as typeof s;\n }\n if (s.description) {\n descriptions[fieldName] = s.description;\n }\n }\n return descriptions;\n }\n\n if (isJsonSchemaWrapper(schema)) {\n const jsonSchema = extractJsonSchema(schema);\n if (jsonSchema?.properties) {\n for (const [fieldName, propSchema] of Object.entries(\n jsonSchema.properties\n )) {\n if (\n propSchema &&\n typeof propSchema === \"object\" &&\n propSchema.description\n ) {\n descriptions[fieldName] = propSchema.description;\n }\n }\n }\n }\n\n return descriptions;\n}\n\n/**\n * Extract field descriptions from a schema and format as @param lines.\n */\nfunction extractParamDescriptions(schema: unknown): string[] {\n const descriptions = extractDescriptions(schema);\n return Object.entries(descriptions).map(\n ([fieldName, desc]) => `@param input.${fieldName} - ${desc}`\n );\n}\n\nfunction jsonSchemaToTypeDecl(jsonSchema: JSONSchema7, typeName: string) {\n const ctx: ConversionContext = {\n root: jsonSchema,\n depth: 0,\n seen: new Set(),\n maxDepth: 20\n };\n return `type ${typeName} = ${jsonSchemaToTypeString(jsonSchema, \"\", ctx)}`;\n}\n\n/**\n * Safely convert a schema to TypeScript type string.\n * Handles Zod schemas (v3/v4) and AI SDK jsonSchema wrappers.\n */\nfunction safeSchemaToTs(schema: unknown, typeName: string): string {\n try {\n if (isZodSchema(schema) || isStandardSchema(schema)) {\n const wrapped = asSchema(schema as ZodType);\n const jsonSchema = wrapped.jsonSchema as JSONSchema7;\n if (jsonSchema) return jsonSchemaToTypeDecl(jsonSchema, typeName);\n }\n\n if (isJsonSchemaWrapper(schema)) {\n const jsonSchema = extractJsonSchema(schema);\n if (jsonSchema) return jsonSchemaToTypeDecl(jsonSchema, typeName);\n }\n\n return `type ${typeName} = unknown`;\n } catch {\n return `type ${typeName} = unknown`;\n }\n}\n\ninterface StandardJsonSchemaConverter {\n output?: (options: { target: \"draft-07\" }) => unknown;\n}\n\n/**\n * JSON Schema for the value a schema *produces*, from its Standard JSON\n * Schema converter (Zod 4, Valibot, ArkType, ...). AI SDK's `asSchema`\n * always converts the input side, which is wrong for a tool's output:\n * `.default()` fields come out optional and `.pipe()` keeps the pre-pipe\n * type.\n *\n * Returns `undefined` when the schema has no such converter (Zod 3,\n * `jsonSchema()` wrappers, whose input and output are the same). Throws when\n * the output can't be represented in JSON Schema (e.g. `.transform()`);\n * callers treat that as `unknown` rather than falling back to the input type.\n */\nexport function standardOutputJsonSchema(\n schema: unknown\n): JSONSchema7 | undefined {\n if (!isStandardSchema(schema)) return undefined;\n const converter = (\n schema as { \"~standard\": { jsonSchema?: StandardJsonSchemaConverter } }\n )[\"~standard\"].jsonSchema;\n if (typeof converter?.output !== \"function\") return undefined;\n return converter.output({ target: \"draft-07\" }) as JSONSchema7;\n}\n\n/** Like `safeSchemaToTs`, but types the value the schema produces. */\nfunction safeOutputSchemaToTs(schema: unknown, typeName: string): string {\n let jsonSchema: JSONSchema7 | undefined;\n try {\n jsonSchema = standardOutputJsonSchema(schema);\n } catch {\n return `type ${typeName} = unknown`;\n }\n return jsonSchema\n ? jsonSchemaToTypeDecl(jsonSchema, typeName)\n : safeSchemaToTs(schema, typeName);\n}\n\n/**\n * Generate TypeScript type definitions from tool descriptors or an AI SDK ToolSet.\n * These types can be included in tool descriptions to help LLMs write correct code.\n *\n * Requires the `ai` peer dependency. For a version that works with plain JSON Schema\n * objects (no AI SDK), use `generateTypesFromJsonSchema` from the main entry point.\n */\nexport function generateTypes(\n tools: ToolDescriptors | ToolSet,\n namespace = \"codemode\"\n): string {\n let availableTools = \"\";\n let availableTypes = \"\";\n\n for (const [toolName, tool] of Object.entries(tools)) {\n const safeName = sanitizeToolName(toolName);\n const typeName = toPascalCase(safeName);\n\n try {\n const inputSchema =\n \"inputSchema\" in tool ? tool.inputSchema : tool.parameters;\n const outputSchema =\n \"outputSchema\" in tool ? tool.outputSchema : undefined;\n const description = tool.description;\n\n const inputType = safeSchemaToTs(inputSchema, `${typeName}Input`);\n\n const outputType = outputSchema\n ? safeOutputSchemaToTs(outputSchema, `${typeName}Output`)\n : `type ${typeName}Output = unknown`;\n\n availableTypes += `\\n${inputType.trim()}`;\n availableTypes += `\\n${outputType.trim()}`;\n\n const paramDescs = (() => {\n try {\n return inputSchema ? extractParamDescriptions(inputSchema) : [];\n } catch {\n return [];\n }\n })();\n const jsdocLines: string[] = [];\n if (description?.trim()) {\n jsdocLines.push(escapeJsDoc(description.trim().replace(/\\r?\\n/g, \" \")));\n } else {\n jsdocLines.push(escapeJsDoc(toolName));\n }\n for (const pd of paramDescs) {\n jsdocLines.push(escapeJsDoc(pd.replace(/\\r?\\n/g, \" \")));\n }\n\n const jsdocBody = jsdocLines.map((l) => `\\t * ${l}`).join(\"\\n\");\n availableTools += `\\n\\t/**\\n${jsdocBody}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;\n availableTools += \"\\n\";\n } catch {\n availableTypes += `\\ntype ${typeName}Input = unknown`;\n availableTypes += `\\ntype ${typeName}Output = unknown`;\n\n availableTools += `\\n\\t/**\\n\\t * ${escapeJsDoc(toolName)}\\n\\t */`;\n availableTools += `\\n\\t${safeName}: (input: ${typeName}Input) => Promise<${typeName}Output>;`;\n availableTools += \"\\n\";\n }\n }\n\n availableTools = `\\ndeclare const ${namespace}: {${availableTools}}`;\n\n return `\n${availableTypes}\n${availableTools}\n `.trim();\n}\n","import { tool, type Tool, asSchema } from \"ai\";\nimport { z } from \"zod\";\nimport type { ToolSet } from \"ai\";\nimport { generateTypes, type ToolDescriptors } from \"./tool-types\";\nimport type {\n ToolProvider,\n ToolProviderTools,\n ResolvedProvider\n} from \"./executor\";\nimport { runCode } from \"./run-code\";\nimport { filterTools } from \"./resolve\";\nimport {\n DEFAULT_DESCRIPTION,\n type CreateCodeToolOptions,\n type CodeInput,\n type CodeOutput,\n normalizeProviders\n} from \"./shared\";\nexport type { CreateCodeToolOptions, CodeInput, CodeOutput } from \"./shared\";\nexport { DEFAULT_DESCRIPTION, normalizeProviders } from \"./shared\";\n\nconst codeSchema = z.object({\n code: z.string().describe(\"JavaScript async arrow function to execute\")\n});\n\n/**\n * Extract execute functions from tools, keyed by name.\n * Wraps each with schema validation via AI SDK's `asSchema` when available.\n */\nfunction extractFns(\n tools: ToolProviderTools\n): Record<string, (...args: unknown[]) => Promise<unknown>> {\n const fns: Record<string, (...args: unknown[]) => Promise<unknown>> = {};\n\n for (const [name, t] of Object.entries(tools)) {\n const execute =\n \"execute\" in t\n ? (t.execute as (args: unknown) => Promise<unknown>)\n : undefined;\n if (execute) {\n const rawSchema =\n \"inputSchema\" in t\n ? t.inputSchema\n : \"parameters\" in t\n ? (t as Record<string, unknown>).parameters\n : undefined;\n\n const schema = rawSchema != null ? asSchema(rawSchema) : undefined;\n\n fns[name] = schema?.validate\n ? async (args: unknown) => {\n const result = await schema.validate!(args);\n if (!result.success) throw result.error;\n return execute(result.value);\n }\n : execute;\n }\n }\n\n return fns;\n}\n\n/**\n * Wrap raw AI SDK tools into a ToolProvider under the default \"codemode\" namespace.\n *\n * @example\n * ```ts\n * createCodeTool({\n * tools: [stateTools(workspace), aiTools(myTools)],\n * executor,\n * });\n * ```\n */\nexport function aiTools(tools: ToolDescriptors | ToolSet): ToolProvider {\n return { tools };\n}\n\n/**\n * Resolve a ToolProvider into a ResolvedProvider ready for execution.\n * Filters out tools with `needsApproval` and validates inputs via AI SDK's `asSchema`.\n */\nexport function resolveProvider(provider: ToolProvider): ResolvedProvider {\n const name = provider.name ?? \"codemode\";\n const filtered = filterTools(provider.tools);\n const resolved: ResolvedProvider = { name, fns: extractFns(filtered) };\n return resolved;\n}\n\nexport function createCodeTool(\n options: CreateCodeToolOptions\n): Tool<CodeInput, CodeOutput> {\n const providers = normalizeProviders(options.tools);\n\n // Build type block and resolved providers for each provider.\n const typeBlocks: string[] = [];\n const resolvedProviders: ResolvedProvider[] = [];\n\n for (const provider of providers) {\n const name = provider.name ?? \"codemode\";\n const filtered = filterTools(provider.tools);\n const types =\n provider.types ?? generateTypes(filtered as ToolDescriptors, name);\n typeBlocks.push(types);\n resolvedProviders.push({ name, fns: extractFns(filtered) });\n }\n\n const typeBlock = typeBlocks.filter(Boolean).join(\"\\n\\n\");\n\n const executor = options.executor;\n\n const description = (options.description ?? DEFAULT_DESCRIPTION).replace(\n \"{{types}}\",\n typeBlock\n );\n\n return tool({\n description,\n inputSchema: codeSchema,\n execute: async ({ code }) =>\n runCode({ code, executor, providers: resolvedProviders })\n });\n}\n","/**\n * ToolSetConnector — adapt an AI SDK `ToolSet` to the connector model.\n *\n * Each tool in the set becomes one connector tool under a single namespace\n * (default `\"tools\"`). Tools with `needsApproval` map to `requiresApproval`:\n * calling one pauses the run durably until the host approves\n * (`runtime.approve()`), then the run resumes where it stopped — the\n * runtime's pause/approve/resume flow, not the AI SDK's per-call approval.\n * A function-valued `needsApproval` cannot be evaluated against sandbox\n * arguments ahead of time, so it conservatively always requires approval.\n *\n * Lives in the `/ai` entry because schema handling (`asSchema`) needs the\n * `ai` peer dependency.\n */\nimport { asSchema } from \"ai\";\nimport type { ToolSet } from \"ai\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { generateTypes, standardOutputJsonSchema } from \"../tool-types\";\nimport { sanitizeToolName } from \"../utils\";\nimport { CodemodeConnector, type ConnectorTools } from \"./base\";\n\nexport interface ToolSetConnectorOptions {\n /**\n * The namespace the sandbox sees, e.g. `\"tools\"` → `tools.getWeather(...)`.\n * Defaults to `\"tools\"`. (`\"codemode\"` is reserved for the platform SDK.)\n */\n name?: string;\n /** Extra model guidance, surfaced with the connector's type block. */\n instructions?: string;\n /** The AI SDK tools to expose. */\n tools: ToolSet;\n}\n\nexport class ToolSetConnector extends CodemodeConnector {\n #options: ToolSetConnectorOptions;\n #warnedSkipped = false;\n\n constructor(\n ctx: DurableObjectState | ExecutionContext,\n options: ToolSetConnectorOptions\n ) {\n super(ctx, {});\n this.#options = options;\n }\n\n /**\n * Only tools with an `execute` function can run inside the sandbox.\n * Execute-less tools (client-side / provider-executed) are excluded from\n * both the runtime bindings and the generated types — advertising a method\n * the sandbox can't call would send the model down a dead end.\n */\n #executableTools(): ToolSet {\n const executable: ToolSet = {};\n const skipped: string[] = [];\n for (const [toolName, t] of Object.entries(this.#options.tools)) {\n if (\"execute\" in t && typeof t.execute === \"function\") {\n executable[toolName] = t;\n } else {\n skipped.push(toolName);\n }\n }\n if (skipped.length > 0 && !this.#warnedSkipped) {\n this.#warnedSkipped = true;\n console.warn(\n `[codemode] ToolSetConnector \"${this.name()}\" skipped tools without ` +\n `an execute function (client-side or provider-executed): ` +\n `${skipped.join(\", \")}. They are not callable from sandboxed code.`\n );\n }\n return executable;\n }\n\n override name(): string {\n return this.#options.name ?? \"tools\";\n }\n\n protected override instructions(): string | undefined {\n return this.#options.instructions;\n }\n\n protected override async tools(): Promise<ConnectorTools> {\n const out: ConnectorTools = {};\n const sources = new Map<string, string>();\n for (const [toolName, t] of Object.entries(this.#executableTools())) {\n const execute = t.execute as (args: unknown) => Promise<unknown>;\n\n const name = sanitizeToolName(toolName);\n const existing = sources.get(name);\n if (existing !== undefined) {\n throw new Error(\n `Tools \"${existing}\" and \"${toolName}\" on ${this.name()} both ` +\n `map to \"${name}\" — rename one of them.`\n );\n }\n sources.set(name, toolName);\n\n const rawSchema =\n \"inputSchema\" in t\n ? t.inputSchema\n : (t as Record<string, unknown>).parameters;\n const schema =\n rawSchema != null\n ? asSchema(rawSchema as Parameters<typeof asSchema>[0])\n : undefined;\n // `jsonSchema` may be a promise (`jsonSchema(promise)` or a lazy\n // loader), so await it rather than passing a Promise through as a schema.\n const inputSchema = schema ? await schema.jsonSchema : undefined;\n const outputSchema = await outputJsonSchema(\n (t as { outputSchema?: unknown }).outputSchema\n );\n\n // boolean `false` means no approval; `true` or a function (which can't\n // be pre-evaluated against sandbox args) gates the call behind the\n // runtime's durable pause/approve/resume flow.\n const needsApproval = (t as { needsApproval?: unknown }).needsApproval;\n const requiresApproval =\n needsApproval !== undefined && needsApproval !== false;\n\n out[name] = {\n description:\n typeof t.description === \"function\" ? undefined : t.description,\n inputSchema: inputSchema as JSONSchema7 | undefined,\n ...(outputSchema ? { outputSchema } : {}),\n ...(requiresApproval ? { requiresApproval: true } : {}),\n execute: schema?.validate\n ? async (args: unknown) => {\n const result = await schema.validate!(args);\n if (!result.success) throw result.error;\n return execute(result.value);\n }\n : (args: unknown) => execute(args)\n };\n }\n return out;\n }\n\n /**\n * Generate the sandbox type block from the original AI SDK schemas (Zod or\n * `jsonSchema()` wrappers) rather than the converted JSON Schema, preserving\n * field descriptions as `@param` lines. Restricted to the same executable\n * subset that `tools()` exposes, so the types never advertise a method the\n * sandbox can't call.\n */\n override async getTypeScriptTypes(): Promise<string> {\n return generateTypes(this.#executableTools(), this.name());\n }\n}\n\n/**\n * Convert a tool's output schema to JSON Schema for its descriptor, using\n * the output side of the schema where the library exposes it (see\n * `standardOutputJsonSchema`). The output type is advisory, so a schema that\n * cannot be converted (it throws or its promise rejects) is left out and\n * shows as `unknown`, matching `generateTypes`, instead of failing the whole\n * toolset.\n */\nasync function outputJsonSchema(\n raw: unknown\n): Promise<JSONSchema7 | undefined> {\n if (raw == null) return undefined;\n try {\n return (\n standardOutputJsonSchema(raw) ??\n ((await asSchema(raw as Parameters<typeof asSchema>[0])\n .jsonSchema) as JSONSchema7)\n );\n } catch {\n return undefined;\n }\n}\n\n/** Convenience constructor mirroring `stateConnector` / `new BrowserConnector`. */\nexport function toolSetConnector(\n ctx: DurableObjectState | ExecutionContext,\n options: ToolSetConnectorOptions\n): ToolSetConnector {\n return new ToolSetConnector(ctx, options);\n}\n"],"mappings":";;;;;;;;;;;AAsBA,SAAS,YAAY,OAAkC;CACrD,OACE,UAAU,QACV,OAAO,UAAU,YACjB,UAAU,SACT,MAA6B,SAAS,KAAA;AAE3C;;;;;AAMA,SAAS,iBAAiB,OAAyB;CACjD,OACE,UAAU,QACV,OAAO,UAAU,YACjB,eAAe,SACd,MAAkC,iBAAiB,KAAA;AAExD;;;;;AAMA,SAAS,oBACP,OACsC;CACtC,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CAExD,IAAI,gBAAgB,OAClB,OAAO;CAGT,MAAM,UAAU,OAAO,sBAAsB,KAAK;CAClD,KAAK,MAAM,OAAO,SAAS;EACzB,MAAM,WAAY,MAAkC;EACpD,IAAI,YAAY,OAAO,aAAa,YAAY,gBAAgB,UAC9D,OAAO;CAEX;CAEA,OAAO;AACT;;;;AAKA,SAAS,kBAAkB,SAAsC;CAC/D,IAAI,YAAY,QAAQ,OAAO,YAAY,UAAU,OAAO;CAE5D,IAAI,gBAAgB,SAClB,OAAQ,QAAwC;CAGlD,MAAM,UAAU,OAAO,sBAAsB,OAAO;CACpD,KAAK,MAAM,OAAO,SAAS;EACzB,MAAM,WAAY,QAAoC;EACtD,IAAI,YAAY,OAAO,aAAa,YAAY,gBAAgB,UAC9D,OAAQ,SAAyC;CAErD;CAEA,OAAO;AACT;;;;;AAMA,SAAS,oBAAoB,QAAyC;CACpE,MAAM,eAAuC,CAAC;CAE9C,MAAM,QAAS,OAA+C;CAC9D,IAA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;CASA,MAAe,qBAAsC;EACnD,OAAO,cAAc,KAAKA,iBAAiB,GAAG,KAAK,KAAK,CAAC;CAC3D;AACF;;;;;;;;;AAUA,eAAe,iBACb,KACkC;CAClC,IAAI,OAAO,MAAM,OAAO,KAAA;CACxB,IAAI;EACF,OACE,yBAAyB,GAAG,KAC1B,MAAM,SAAS,GAAqC,CAAC,CACpD;CAEP,QAAQ;EACN;CACF;AACF;;AAGA,SAAgB,iBACd,KACA,SACkB;CAClB,OAAO,IAAI,iBAAiB,KAAK,OAAO;AAC1C"}
|
package/dist/browser.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
c as ExecuteResult,
|
|
3
3
|
l as Executor,
|
|
4
4
|
u as ResolvedProvider
|
|
5
|
-
} from "./executor-
|
|
6
|
-
import { n as CodeOutput, t as CodeInput } from "./shared-
|
|
5
|
+
} from "./executor-DLwvEPC7.js";
|
|
6
|
+
import { n as CodeOutput, t as CodeInput } from "./shared-B1Rs0ONk.js";
|
|
7
7
|
import {
|
|
8
8
|
n as JsonSchemaToolDescriptors,
|
|
9
9
|
t as JsonSchemaToolDescriptor
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RpcTarget } from "cloudflare:workers";
|
|
2
2
|
import { ToolSet } from "ai";
|
|
3
3
|
import { ZodType } from "zod";
|
|
4
|
+
import { JSONSchema7 } from "json-schema";
|
|
4
5
|
|
|
5
6
|
//#region src/tool-types.d.ts
|
|
6
7
|
interface ToolDescriptor {
|
|
@@ -210,4 +211,4 @@ export {
|
|
|
210
211
|
DynamicWorkerExecutor as t,
|
|
211
212
|
ResolvedProvider as u
|
|
212
213
|
};
|
|
213
|
-
//# sourceMappingURL=executor-
|
|
214
|
+
//# sourceMappingURL=executor-DLwvEPC7.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
s as ExecuteOptions,
|
|
9
9
|
t as DynamicWorkerExecutor,
|
|
10
10
|
u as ResolvedProvider
|
|
11
|
-
} from "./executor-
|
|
12
|
-
import { n as CodeOutput } from "./shared-
|
|
11
|
+
} from "./executor-DLwvEPC7.js";
|
|
12
|
+
import { n as CodeOutput } from "./shared-B1Rs0ONk.js";
|
|
13
13
|
import {
|
|
14
14
|
i as jsonSchemaToType,
|
|
15
15
|
n as JsonSchemaToolDescriptors,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
t as CodemodeConnector,
|
|
30
30
|
u as ToolAnnotations
|
|
31
31
|
} from "./base-DiFD41JY.js";
|
|
32
|
-
import { t as resolveProvider } from "./resolve-
|
|
32
|
+
import { t as resolveProvider } from "./resolve-BFB4vzhC.js";
|
|
33
33
|
import { DurableObject } from "cloudflare:workers";
|
|
34
34
|
|
|
35
35
|
//#region src/run-code.d.ts
|
|
@@ -534,7 +534,11 @@ type StandardSchemaIssue = {
|
|
|
534
534
|
type ProxyToolInputSchema = {
|
|
535
535
|
readonly "~standard": {
|
|
536
536
|
readonly version: 1;
|
|
537
|
-
readonly vendor: "@cloudflare/codemode"
|
|
537
|
+
readonly vendor: "@cloudflare/codemode" /** Lets Standard Schema consumers (e.g. TanStack AI) infer `{ code }`. */;
|
|
538
|
+
readonly types?: {
|
|
539
|
+
readonly input: ProxyToolInput;
|
|
540
|
+
readonly output: ProxyToolInput;
|
|
541
|
+
};
|
|
538
542
|
readonly validate: (value: unknown) =>
|
|
539
543
|
| {
|
|
540
544
|
readonly value: ProxyToolInput;
|