@cloudflare/codemode 0.5.6 → 0.5.7
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.js +3 -3
- package/dist/{base-BqhlNCSH.js → base-B_Zc64P1.js} +2 -2
- package/dist/{base-BqhlNCSH.js.map → base-B_Zc64P1.js.map} +1 -1
- package/dist/browser.js +2 -2
- package/dist/index.d.ts +8 -4
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/{json-schema-types-D_m9tVnI.js → json-schema-types-CtFHxrML.js} +110 -63
- package/dist/json-schema-types-CtFHxrML.js.map +1 -0
- package/dist/mcp.js +2 -2
- package/dist/mcp.js.map +1 -1
- package/dist/{run-code-Q3Jh6Dcu.js → run-code-DUD_uzEK.js} +2 -2
- package/dist/{run-code-Q3Jh6Dcu.js.map → run-code-DUD_uzEK.js.map} +1 -1
- package/dist/tanstack-ai.js +2 -2
- package/package.json +1 -1
- package/dist/json-schema-types-D_m9tVnI.js.map +0 -1
package/dist/ai.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as sanitizeToolName, i as escapeJsDoc, o as toPascalCase, r as jsonSchemaToTypeString } from "./json-schema-types-
|
|
2
|
-
import { t as runCode } from "./run-code-
|
|
1
|
+
import { a as sanitizeToolName, i as escapeJsDoc, o as toPascalCase, r as jsonSchemaToTypeString } from "./json-schema-types-CtFHxrML.js";
|
|
2
|
+
import { t as runCode } from "./run-code-DUD_uzEK.js";
|
|
3
3
|
import { n as filterTools } from "./resolve-34dC47Il.js";
|
|
4
|
-
import { t as CodemodeConnector } from "./base-
|
|
4
|
+
import { t as CodemodeConnector } from "./base-B_Zc64P1.js";
|
|
5
5
|
import { n as normalizeProviders, t as DEFAULT_DESCRIPTION } from "./shared-SMjV5yN4.js";
|
|
6
6
|
import { asSchema, tool } from "ai";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as generateTypesFromJsonSchema } from "./json-schema-types-
|
|
1
|
+
import { t as generateTypesFromJsonSchema } from "./json-schema-types-CtFHxrML.js";
|
|
2
2
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
3
3
|
//#region src/connectors/base.ts
|
|
4
4
|
function toolInputSchema(t) {
|
|
@@ -153,4 +153,4 @@ var CodemodeConnector = class extends WorkerEntrypoint {
|
|
|
153
153
|
//#endregion
|
|
154
154
|
export { CodemodeConnector as t };
|
|
155
155
|
|
|
156
|
-
//# sourceMappingURL=base-
|
|
156
|
+
//# sourceMappingURL=base-B_Zc64P1.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-BqhlNCSH.js","names":["#toolsPromise"],"sources":["../src/connectors/base.ts"],"sourcesContent":["import { WorkerEntrypoint } from \"cloudflare:workers\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport {\n generateTypesFromJsonSchema,\n type JsonSchemaToolDescriptors\n} from \"../json-schema-types\";\nimport type {\n ConnectorDescription,\n ExecutionEndStatus,\n PassEndStatus,\n ToolAnnotations,\n ToolExecuteContext\n} from \"./types\";\n\n/**\n * A single connector tool — everything about it in one place: docs, schema,\n * approval requirement, execution, and (optionally) how to undo it.\n *\n * AI SDK tools are shape-compatible: a `ToolSet` can be returned from\n * `tools()` directly.\n */\nexport type ConnectorTool = {\n description?: string;\n /** JSON Schema for the tool input. Defaults to an open object. */\n inputSchema?: JSONSchema7;\n outputSchema?: JSONSchema7;\n /** Pause for user approval before executing. Omit to execute immediately. */\n requiresApproval?: boolean;\n /**\n * Replay policy for the durable log. `\"reexecute\"` marks the call ephemeral:\n * its result is never stored durably, and a replay re-executes the call\n * instead of replaying a recorded result. Use it for idempotent reads whose\n * results are large (file contents, directory listings) — they'd otherwise\n * bloat the replay log. Incompatible with `requiresApproval` (an approved\n * side effect must be logged, never re-executed). Defaults to `\"log\"`.\n */\n replay?: \"log\" | \"reexecute\";\n execute: (\n args: unknown,\n ctx?: ToolExecuteContext\n ) => Promise<unknown> | unknown;\n /** Optional compensation for rollback: undo an applied call. */\n revert?: (\n args: unknown,\n result: unknown,\n ctx?: ToolExecuteContext\n ) => Promise<void> | void;\n};\n\nexport type ConnectorTools = Record<string, ConnectorTool>;\n\n// AI SDK v4 tools carry the schema as `parameters`; v5 as `inputSchema`\n// (possibly a zod schema rather than JSON Schema). Use whichever looks like\n// JSON Schema; fall back to an open object.\nfunction toolInputSchema(t: ConnectorTool): JSONSchema7 {\n const loose = t as { inputSchema?: unknown; parameters?: unknown };\n for (const candidate of [loose.inputSchema, loose.parameters]) {\n if (\n candidate &&\n typeof candidate === \"object\" &&\n (\"type\" in candidate || \"properties\" in candidate || \"$ref\" in candidate)\n ) {\n return candidate as JSONSchema7;\n }\n }\n return { type: \"object\" };\n}\n\n/**\n * Base class for codemode connectors.\n *\n * A connector answers three questions: what global name does the model use\n * (`name`), what guidance does the model get (`instructions`), and what tools\n * exist (`tools` — each tool carries its own docs, schema, approval\n * requirement, execution, and optional revert).\n *\n * The RPC surface (`describe`, `executeTool`, `revertAction`,\n * `getTypeScriptTypes`) is wire plumbing derived from the tools record — the\n * proxy tool calls it; connector authors don't implement it.\n */\nexport abstract class CodemodeConnector<\n Env = unknown,\n Props = unknown\n> extends WorkerEntrypoint<Env, Props> {\n /**\n * Connectors are used in-process by the runtime (their `name()`, `describe()`,\n * and `executeTool()` are called directly), so they're constructed with `new`\n * — typically from inside an Agent / Durable Object.\n *\n * Inside a Durable Object `this.ctx` is a `DurableObjectState`, not an\n * `ExecutionContext`. The base `WorkerEntrypoint` constructor only stores it,\n * so we widen the parameter to accept either — pass `this.ctx` directly with\n * no cast:\n *\n * ```ts\n * const github = new GithubConnector(this.ctx, this.env, conn);\n * ```\n */\n constructor(ctx: DurableObjectState | ExecutionContext, env: Env) {\n super(ctx as ExecutionContext, env);\n }\n\n abstract name(): string;\n\n protected instructions(): string | undefined {\n return undefined;\n }\n\n /**\n * The single authoring surface: one record, one entry per tool.\n * Derived connectors (MCP, OpenAPI) generate this for you.\n */\n protected abstract tools(): ConnectorTools | Promise<ConnectorTools>;\n\n /**\n * Decoration hook, called once per tool. Override to adjust tools you\n * didn't author inline — e.g. mark a derived MCP tool as requiring\n * approval, or attach a revert:\n *\n * ```ts\n * protected tool(name: string, t: ConnectorTool): ConnectorTool {\n * if (name === \"create_issue\") {\n * return { ...t, requiresApproval: true };\n * }\n * return t;\n * }\n * ```\n */\n protected tool(_name: string, t: ConnectorTool): ConnectorTool {\n return t;\n }\n\n #toolsPromise?: Promise<ConnectorTools>;\n\n protected resolvedTools(): Promise<ConnectorTools> {\n return (this.#toolsPromise ??= (async () => {\n const tools = await this.tools();\n const out: ConnectorTools = {};\n for (const [name, t] of Object.entries(tools)) {\n if (!t || typeof t !== \"object\") continue;\n out[name] = this.tool(name, t);\n }\n return out;\n })());\n }\n\n // -------------------------------------------------------------------------\n // RPC surface — derived from the tools record, called by the proxy tool.\n // -------------------------------------------------------------------------\n\n async describe(): Promise<ConnectorDescription> {\n const tools = await this.resolvedTools();\n const descriptors: JsonSchemaToolDescriptors = {};\n const annotations: Record<string, ToolAnnotations> = {};\n for (const [name, t] of Object.entries(tools)) {\n if (t.requiresApproval && t.replay === \"reexecute\") {\n // An approved action is a side effect; replaying it by re-executing\n // would re-apply the side effect on every later resume of the run.\n throw new Error(\n `Connector \"${this.name()}\" tool \"${name}\" cannot combine ` +\n `requiresApproval with replay: \"reexecute\" — approved actions ` +\n `must be logged, not re-executed.`\n );\n }\n descriptors[name] = {\n description: t.description,\n inputSchema: toolInputSchema(t),\n outputSchema: t.outputSchema\n };\n if (t.requiresApproval || t.replay === \"reexecute\") {\n annotations[name] = {\n ...(t.requiresApproval ? { requiresApproval: true } : {}),\n ...(t.replay === \"reexecute\" ? { replay: \"reexecute\" as const } : {})\n };\n }\n }\n return {\n name: this.name(),\n instructions: this.instructions(),\n descriptors,\n annotations\n };\n }\n\n async executeTool(\n method: string,\n args: unknown,\n ctx?: ToolExecuteContext\n ): Promise<unknown> {\n const tool = (await this.resolvedTools())[method];\n if (!tool) throw new Error(`Tool \"${method}\" not found on ${this.name()}`);\n // `return await` (not `return`) so a synchronously-rejected promise gets\n // its handler attached in the same tick — workerd otherwise reports a\n // false-positive unhandled rejection during promise adoption.\n return await tool.execute(args, ctx);\n }\n\n /**\n * Revert an applied action. Returns whether a revert actually ran — reads and\n * tools without a `revert` are a no-op and return `false`, so the runtime can\n * mark only the entries it truly reverted.\n */\n async revertAction(\n method: string,\n args: unknown,\n result: unknown,\n ctx?: ToolExecuteContext\n ): Promise<boolean> {\n const tool = (await this.resolvedTools())[method];\n if (!tool?.revert) return false;\n await tool.revert(args, result, ctx);\n return true;\n }\n\n /**\n * Called at the end of every execution *pass* — including a pass that ends\n * in a pause awaiting approval, where `disposeExecution` deliberately does\n * NOT fire. Override to release per-pass resources: an open socket, a lease,\n * an in-memory cache entry. Per-execution resources (e.g. a browser session\n * that must survive the pause for the resume) belong in `disposeExecution`.\n *\n * On a terminal pass, `onPassEnd` fires first, then `disposeExecution`.\n *\n * Contract for implementers: be idempotent, don't rely on instance memory\n * (a resume may run on a fresh instance), and don't throw — the runtime\n * ignores rejections from this hook.\n */\n async onPassEnd(\n _executionId: string,\n _status: PassEndStatus\n ): Promise<void> {}\n\n /**\n * Called once when a codemode execution reaches a terminal state — completed,\n * errored, rejected, or rolled back — and will not resume. Override to tear\n * down any per-execution resource this connector opened for that run, keyed\n * by `executionId` (e.g. close a browser/CDP session).\n *\n * It is deliberately *not* called when a run pauses for approval: a paused\n * run may resume later, possibly in a fresh Worker invocation, so a resource\n * scoped to the whole run must outlive a pause. This hook is the single point\n * where teardown is safe.\n *\n * Contract for implementers:\n * - Be idempotent. It may fire more than once for the same execution (a\n * completed run that is later rolled back) and a no-op is expected the\n * second time.\n * - Don't rely on instance memory. It may run on a different connector\n * instance than the one that opened the resource (the host can reconstruct\n * connectors per request, and the opening pass may have hibernated), so\n * read what you need from durable storage keyed by `executionId`.\n * - Don't throw. Teardown failures must not turn a finished run into a\n * failure; the runtime ignores rejections from this hook.\n *\n * The default is a no-op, so connectors that own no per-execution state\n * don't implement it.\n */\n async disposeExecution(\n _executionId: string,\n _status: ExecutionEndStatus\n ): Promise<void> {}\n\n async getTypeScriptTypes(): Promise<string> {\n const { descriptors } = await this.describe();\n return generateTypesFromJsonSchema(descriptors).replace(\n \"declare const codemode\",\n `declare const ${this.name()}`\n );\n }\n}\n"],"mappings":";;;AAsDA,SAAS,gBAAgB,GAA+B;CACtD,MAAM,QAAQ;CACd,KAAK,MAAM,aAAa,CAAC,MAAM,aAAa,MAAM,UAAU,GAC1D,IACE,aACA,OAAO,cAAc,aACpB,UAAU,aAAa,gBAAgB,aAAa,UAAU,YAE/D,OAAO;CAGX,OAAO,EAAE,MAAM,SAAS;AAC1B;;;;;;;;;;;;;AAcA,IAAsB,oBAAtB,cAGU,iBAA6B;;;;;;;;;;;;;;;CAerC,YAAY,KAA4C,KAAU;EAChE,MAAM,KAAyB,GAAG;CACpC;CAIA,eAA6C,CAE7C;;;;;;;;;;;;;;;CAsBA,KAAe,OAAe,GAAiC;EAC7D,OAAO;CACT;CAEA;CAEA,gBAAmD;EACjD,OAAQ,KAAKA,mBAAmB,YAAY;GAC1C,MAAM,QAAQ,MAAM,KAAK,MAAM;GAC/B,MAAM,MAAsB,CAAC;GAC7B,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAAG;IAC7C,IAAI,CAAC,KAAK,OAAO,MAAM,UAAU;IACjC,IAAI,QAAQ,KAAK,KAAK,MAAM,CAAC;GAC/B;GACA,OAAO;EACT,EAAA,CAAG;CACL;CAMA,MAAM,WAA0C;EAC9C,MAAM,QAAQ,MAAM,KAAK,cAAc;EACvC,MAAM,cAAyC,CAAC;EAChD,MAAM,cAA+C,CAAC;EACtD,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAAG;GAC7C,IAAI,EAAE,oBAAoB,EAAE,WAAW,aAGrC,MAAM,IAAI,MACR,cAAc,KAAK,KAAK,EAAE,UAAU,KAAK,+GAG3C;GAEF,YAAY,QAAQ;IAClB,aAAa,EAAE;IACf,aAAa,gBAAgB,CAAC;IAC9B,cAAc,EAAE;GAClB;GACA,IAAI,EAAE,oBAAoB,EAAE,WAAW,aACrC,YAAY,QAAQ;IAClB,GAAI,EAAE,mBAAmB,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACvD,GAAI,EAAE,WAAW,cAAc,EAAE,QAAQ,YAAqB,IAAI,CAAC;GACrE;EAEJ;EACA,OAAO;GACL,MAAM,KAAK,KAAK;GAChB,cAAc,KAAK,aAAa;GAChC;GACA;EACF;CACF;CAEA,MAAM,YACJ,QACA,MACA,KACkB;EAClB,MAAM,QAAQ,MAAM,KAAK,cAAc,EAAA,CAAG;EAC1C,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,SAAS,OAAO,iBAAiB,KAAK,KAAK,GAAG;EAIzE,OAAO,MAAM,KAAK,QAAQ,MAAM,GAAG;CACrC;;;;;;CAOA,MAAM,aACJ,QACA,MACA,QACA,KACkB;EAClB,MAAM,QAAQ,MAAM,KAAK,cAAc,EAAA,CAAG;EAC1C,IAAI,CAAC,MAAM,QAAQ,OAAO;EAC1B,MAAM,KAAK,OAAO,MAAM,QAAQ,GAAG;EACnC,OAAO;CACT;;;;;;;;;;;;;;CAeA,MAAM,UACJ,cACA,SACe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlB,MAAM,iBACJ,cACA,SACe,CAAC;CAElB,MAAM,qBAAsC;EAC1C,MAAM,EAAE,gBAAgB,MAAM,KAAK,SAAS;EAC5C,OAAO,4BAA4B,WAAW,CAAC,CAAC,QAC9C,0BACA,iBAAiB,KAAK,KAAK,GAC7B;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"base-B_Zc64P1.js","names":["#toolsPromise"],"sources":["../src/connectors/base.ts"],"sourcesContent":["import { WorkerEntrypoint } from \"cloudflare:workers\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport {\n generateTypesFromJsonSchema,\n type JsonSchemaToolDescriptors\n} from \"../json-schema-types\";\nimport type {\n ConnectorDescription,\n ExecutionEndStatus,\n PassEndStatus,\n ToolAnnotations,\n ToolExecuteContext\n} from \"./types\";\n\n/**\n * A single connector tool — everything about it in one place: docs, schema,\n * approval requirement, execution, and (optionally) how to undo it.\n *\n * AI SDK tools are shape-compatible: a `ToolSet` can be returned from\n * `tools()` directly.\n */\nexport type ConnectorTool = {\n description?: string;\n /** JSON Schema for the tool input. Defaults to an open object. */\n inputSchema?: JSONSchema7;\n outputSchema?: JSONSchema7;\n /** Pause for user approval before executing. Omit to execute immediately. */\n requiresApproval?: boolean;\n /**\n * Replay policy for the durable log. `\"reexecute\"` marks the call ephemeral:\n * its result is never stored durably, and a replay re-executes the call\n * instead of replaying a recorded result. Use it for idempotent reads whose\n * results are large (file contents, directory listings) — they'd otherwise\n * bloat the replay log. Incompatible with `requiresApproval` (an approved\n * side effect must be logged, never re-executed). Defaults to `\"log\"`.\n */\n replay?: \"log\" | \"reexecute\";\n execute: (\n args: unknown,\n ctx?: ToolExecuteContext\n ) => Promise<unknown> | unknown;\n /** Optional compensation for rollback: undo an applied call. */\n revert?: (\n args: unknown,\n result: unknown,\n ctx?: ToolExecuteContext\n ) => Promise<void> | void;\n};\n\nexport type ConnectorTools = Record<string, ConnectorTool>;\n\n// AI SDK v4 tools carry the schema as `parameters`; v5 as `inputSchema`\n// (possibly a zod schema rather than JSON Schema). Use whichever looks like\n// JSON Schema; fall back to an open object.\nfunction toolInputSchema(t: ConnectorTool): JSONSchema7 {\n const loose = t as { inputSchema?: unknown; parameters?: unknown };\n for (const candidate of [loose.inputSchema, loose.parameters]) {\n if (\n candidate &&\n typeof candidate === \"object\" &&\n (\"type\" in candidate || \"properties\" in candidate || \"$ref\" in candidate)\n ) {\n return candidate as JSONSchema7;\n }\n }\n return { type: \"object\" };\n}\n\n/**\n * Base class for codemode connectors.\n *\n * A connector answers three questions: what global name does the model use\n * (`name`), what guidance does the model get (`instructions`), and what tools\n * exist (`tools` — each tool carries its own docs, schema, approval\n * requirement, execution, and optional revert).\n *\n * The RPC surface (`describe`, `executeTool`, `revertAction`,\n * `getTypeScriptTypes`) is wire plumbing derived from the tools record — the\n * proxy tool calls it; connector authors don't implement it.\n */\nexport abstract class CodemodeConnector<\n Env = unknown,\n Props = unknown\n> extends WorkerEntrypoint<Env, Props> {\n /**\n * Connectors are used in-process by the runtime (their `name()`, `describe()`,\n * and `executeTool()` are called directly), so they're constructed with `new`\n * — typically from inside an Agent / Durable Object.\n *\n * Inside a Durable Object `this.ctx` is a `DurableObjectState`, not an\n * `ExecutionContext`. The base `WorkerEntrypoint` constructor only stores it,\n * so we widen the parameter to accept either — pass `this.ctx` directly with\n * no cast:\n *\n * ```ts\n * const github = new GithubConnector(this.ctx, this.env, conn);\n * ```\n */\n constructor(ctx: DurableObjectState | ExecutionContext, env: Env) {\n super(ctx as ExecutionContext, env);\n }\n\n abstract name(): string;\n\n protected instructions(): string | undefined {\n return undefined;\n }\n\n /**\n * The single authoring surface: one record, one entry per tool.\n * Derived connectors (MCP, OpenAPI) generate this for you.\n */\n protected abstract tools(): ConnectorTools | Promise<ConnectorTools>;\n\n /**\n * Decoration hook, called once per tool. Override to adjust tools you\n * didn't author inline — e.g. mark a derived MCP tool as requiring\n * approval, or attach a revert:\n *\n * ```ts\n * protected tool(name: string, t: ConnectorTool): ConnectorTool {\n * if (name === \"create_issue\") {\n * return { ...t, requiresApproval: true };\n * }\n * return t;\n * }\n * ```\n */\n protected tool(_name: string, t: ConnectorTool): ConnectorTool {\n return t;\n }\n\n #toolsPromise?: Promise<ConnectorTools>;\n\n protected resolvedTools(): Promise<ConnectorTools> {\n return (this.#toolsPromise ??= (async () => {\n const tools = await this.tools();\n const out: ConnectorTools = {};\n for (const [name, t] of Object.entries(tools)) {\n if (!t || typeof t !== \"object\") continue;\n out[name] = this.tool(name, t);\n }\n return out;\n })());\n }\n\n // -------------------------------------------------------------------------\n // RPC surface — derived from the tools record, called by the proxy tool.\n // -------------------------------------------------------------------------\n\n async describe(): Promise<ConnectorDescription> {\n const tools = await this.resolvedTools();\n const descriptors: JsonSchemaToolDescriptors = {};\n const annotations: Record<string, ToolAnnotations> = {};\n for (const [name, t] of Object.entries(tools)) {\n if (t.requiresApproval && t.replay === \"reexecute\") {\n // An approved action is a side effect; replaying it by re-executing\n // would re-apply the side effect on every later resume of the run.\n throw new Error(\n `Connector \"${this.name()}\" tool \"${name}\" cannot combine ` +\n `requiresApproval with replay: \"reexecute\" — approved actions ` +\n `must be logged, not re-executed.`\n );\n }\n descriptors[name] = {\n description: t.description,\n inputSchema: toolInputSchema(t),\n outputSchema: t.outputSchema\n };\n if (t.requiresApproval || t.replay === \"reexecute\") {\n annotations[name] = {\n ...(t.requiresApproval ? { requiresApproval: true } : {}),\n ...(t.replay === \"reexecute\" ? { replay: \"reexecute\" as const } : {})\n };\n }\n }\n return {\n name: this.name(),\n instructions: this.instructions(),\n descriptors,\n annotations\n };\n }\n\n async executeTool(\n method: string,\n args: unknown,\n ctx?: ToolExecuteContext\n ): Promise<unknown> {\n const tool = (await this.resolvedTools())[method];\n if (!tool) throw new Error(`Tool \"${method}\" not found on ${this.name()}`);\n // `return await` (not `return`) so a synchronously-rejected promise gets\n // its handler attached in the same tick — workerd otherwise reports a\n // false-positive unhandled rejection during promise adoption.\n return await tool.execute(args, ctx);\n }\n\n /**\n * Revert an applied action. Returns whether a revert actually ran — reads and\n * tools without a `revert` are a no-op and return `false`, so the runtime can\n * mark only the entries it truly reverted.\n */\n async revertAction(\n method: string,\n args: unknown,\n result: unknown,\n ctx?: ToolExecuteContext\n ): Promise<boolean> {\n const tool = (await this.resolvedTools())[method];\n if (!tool?.revert) return false;\n await tool.revert(args, result, ctx);\n return true;\n }\n\n /**\n * Called at the end of every execution *pass* — including a pass that ends\n * in a pause awaiting approval, where `disposeExecution` deliberately does\n * NOT fire. Override to release per-pass resources: an open socket, a lease,\n * an in-memory cache entry. Per-execution resources (e.g. a browser session\n * that must survive the pause for the resume) belong in `disposeExecution`.\n *\n * On a terminal pass, `onPassEnd` fires first, then `disposeExecution`.\n *\n * Contract for implementers: be idempotent, don't rely on instance memory\n * (a resume may run on a fresh instance), and don't throw — the runtime\n * ignores rejections from this hook.\n */\n async onPassEnd(\n _executionId: string,\n _status: PassEndStatus\n ): Promise<void> {}\n\n /**\n * Called once when a codemode execution reaches a terminal state — completed,\n * errored, rejected, or rolled back — and will not resume. Override to tear\n * down any per-execution resource this connector opened for that run, keyed\n * by `executionId` (e.g. close a browser/CDP session).\n *\n * It is deliberately *not* called when a run pauses for approval: a paused\n * run may resume later, possibly in a fresh Worker invocation, so a resource\n * scoped to the whole run must outlive a pause. This hook is the single point\n * where teardown is safe.\n *\n * Contract for implementers:\n * - Be idempotent. It may fire more than once for the same execution (a\n * completed run that is later rolled back) and a no-op is expected the\n * second time.\n * - Don't rely on instance memory. It may run on a different connector\n * instance than the one that opened the resource (the host can reconstruct\n * connectors per request, and the opening pass may have hibernated), so\n * read what you need from durable storage keyed by `executionId`.\n * - Don't throw. Teardown failures must not turn a finished run into a\n * failure; the runtime ignores rejections from this hook.\n *\n * The default is a no-op, so connectors that own no per-execution state\n * don't implement it.\n */\n async disposeExecution(\n _executionId: string,\n _status: ExecutionEndStatus\n ): Promise<void> {}\n\n async getTypeScriptTypes(): Promise<string> {\n const { descriptors } = await this.describe();\n return generateTypesFromJsonSchema(descriptors).replace(\n \"declare const codemode\",\n `declare const ${this.name()}`\n );\n }\n}\n"],"mappings":";;;AAsDA,SAAS,gBAAgB,GAA+B;CACtD,MAAM,QAAQ;CACd,KAAK,MAAM,aAAa,CAAC,MAAM,aAAa,MAAM,UAAU,GAC1D,IACE,aACA,OAAO,cAAc,aACpB,UAAU,aAAa,gBAAgB,aAAa,UAAU,YAE/D,OAAO;CAGX,OAAO,EAAE,MAAM,SAAS;AAC1B;;;;;;;;;;;;;AAcA,IAAsB,oBAAtB,cAGU,iBAA6B;;;;;;;;;;;;;;;CAerC,YAAY,KAA4C,KAAU;EAChE,MAAM,KAAyB,GAAG;CACpC;CAIA,eAA6C,CAE7C;;;;;;;;;;;;;;;CAsBA,KAAe,OAAe,GAAiC;EAC7D,OAAO;CACT;CAEA;CAEA,gBAAmD;EACjD,OAAQ,KAAKA,mBAAmB,YAAY;GAC1C,MAAM,QAAQ,MAAM,KAAK,MAAM;GAC/B,MAAM,MAAsB,CAAC;GAC7B,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAAG;IAC7C,IAAI,CAAC,KAAK,OAAO,MAAM,UAAU;IACjC,IAAI,QAAQ,KAAK,KAAK,MAAM,CAAC;GAC/B;GACA,OAAO;EACT,EAAA,CAAG;CACL;CAMA,MAAM,WAA0C;EAC9C,MAAM,QAAQ,MAAM,KAAK,cAAc;EACvC,MAAM,cAAyC,CAAC;EAChD,MAAM,cAA+C,CAAC;EACtD,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAAQ,KAAK,GAAG;GAC7C,IAAI,EAAE,oBAAoB,EAAE,WAAW,aAGrC,MAAM,IAAI,MACR,cAAc,KAAK,KAAK,EAAE,UAAU,KAAK,+GAG3C;GAEF,YAAY,QAAQ;IAClB,aAAa,EAAE;IACf,aAAa,gBAAgB,CAAC;IAC9B,cAAc,EAAE;GAClB;GACA,IAAI,EAAE,oBAAoB,EAAE,WAAW,aACrC,YAAY,QAAQ;IAClB,GAAI,EAAE,mBAAmB,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACvD,GAAI,EAAE,WAAW,cAAc,EAAE,QAAQ,YAAqB,IAAI,CAAC;GACrE;EAEJ;EACA,OAAO;GACL,MAAM,KAAK,KAAK;GAChB,cAAc,KAAK,aAAa;GAChC;GACA;EACF;CACF;CAEA,MAAM,YACJ,QACA,MACA,KACkB;EAClB,MAAM,QAAQ,MAAM,KAAK,cAAc,EAAA,CAAG;EAC1C,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,SAAS,OAAO,iBAAiB,KAAK,KAAK,GAAG;EAIzE,OAAO,MAAM,KAAK,QAAQ,MAAM,GAAG;CACrC;;;;;;CAOA,MAAM,aACJ,QACA,MACA,QACA,KACkB;EAClB,MAAM,QAAQ,MAAM,KAAK,cAAc,EAAA,CAAG;EAC1C,IAAI,CAAC,MAAM,QAAQ,OAAO;EAC1B,MAAM,KAAK,OAAO,MAAM,QAAQ,GAAG;EACnC,OAAO;CACT;;;;;;;;;;;;;;CAeA,MAAM,UACJ,cACA,SACe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlB,MAAM,iBACJ,cACA,SACe,CAAC;CAElB,MAAM,qBAAsC;EAC1C,MAAM,EAAE,gBAAgB,MAAM,KAAK,SAAS;EAC5C,OAAO,4BAA4B,WAAW,CAAC,CAAC,QAC9C,0BACA,iBAAiB,KAAK,KAAK,GAC7B;CACF;AACF"}
|
package/dist/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as sanitizeToolName, s as normalizeCode, t as generateTypesFromJsonSchema } from "./json-schema-types-
|
|
2
|
-
import { t as runCode } from "./run-code-
|
|
1
|
+
import { a as sanitizeToolName, s as normalizeCode, t as generateTypesFromJsonSchema } from "./json-schema-types-CtFHxrML.js";
|
|
2
|
+
import { t as runCode } from "./run-code-DUD_uzEK.js";
|
|
3
3
|
//#region src/messages.ts
|
|
4
4
|
function isRecord(value) {
|
|
5
5
|
return typeof value === "object" && value !== null;
|
package/dist/index.d.ts
CHANGED
|
@@ -223,10 +223,14 @@ type BeginOptions = {
|
|
|
223
223
|
declare const DEFAULT_MAX_EXECUTIONS = 50;
|
|
224
224
|
/**
|
|
225
225
|
* Cap for any single serialized value stored in the durable log (args, a
|
|
226
|
-
* recorded result, the final result)
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
226
|
+
* recorded result, the final result), counted in UTF-16 code units. A Durable
|
|
227
|
+
* Object's SQLite row holds 8 MiB in production but about 2.2 MB in older
|
|
228
|
+
* local workerd and the vitest pool (measured). ASCII values under the cap fit
|
|
229
|
+
* every runtime; a value of 3-byte characters can reach 3 MB of UTF-8, which
|
|
230
|
+
* fits production only. Truncating args or recorded results is never an
|
|
231
|
+
* option (replay would feed resumed code corrupted data), so a breach fails
|
|
232
|
+
* the run with a model-actionable error. A final result over the cap is
|
|
233
|
+
* replaced by a note, since replay never needs it (see `complete`).
|
|
230
234
|
*/
|
|
231
235
|
declare const MAX_DURABLE_VALUE_BYTES = 1000000;
|
|
232
236
|
/** Default age after which a paused (awaiting-approval) run can be expired. */
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as sanitizeToolName, n as jsonSchemaToType, s as normalizeCode, t as generateTypesFromJsonSchema } from "./json-schema-types-
|
|
2
|
-
import { t as runCode } from "./run-code-
|
|
1
|
+
import { a as sanitizeToolName, n as jsonSchemaToType, s as normalizeCode, t as generateTypesFromJsonSchema } from "./json-schema-types-CtFHxrML.js";
|
|
2
|
+
import { t as runCode } from "./run-code-DUD_uzEK.js";
|
|
3
3
|
import { r as resolveProvider } from "./resolve-34dC47Il.js";
|
|
4
4
|
import { n as truncateResult, t as truncateResponse } from "./truncate-Dd-VZZYQ.js";
|
|
5
|
-
import { t as CodemodeConnector } from "./base-
|
|
5
|
+
import { t as CodemodeConnector } from "./base-B_Zc64P1.js";
|
|
6
6
|
import { DurableObject, RpcTarget } from "cloudflare:workers";
|
|
7
7
|
//#region src/codec.ts
|
|
8
8
|
/**
|
|
@@ -104,7 +104,7 @@ const PAUSE_SENTINEL_LITERAL = "__CODEMODE_PAUSE__";
|
|
|
104
104
|
* Dynamically-loaded Workers and the RPC `Fetcher` stubs returned by
|
|
105
105
|
* `getEntrypoint()` own native handles. Left to GC, they can be finalized
|
|
106
106
|
* after the isolate's destruction queue has closed — under the
|
|
107
|
-
* `@cloudflare/vitest-
|
|
107
|
+
* `@cloudflare/vitest-plugin` teardown matrix this trips a fatal
|
|
108
108
|
* workerd assertion ("tried to defer destruction during isolate shutdown")
|
|
109
109
|
* that kills the worker. Disposing them eagerly releases the handle while the
|
|
110
110
|
* isolate is still alive. Disposal must never mask the execution result, so
|
|
@@ -483,10 +483,14 @@ const STEP_CONNECTOR = "__step";
|
|
|
483
483
|
const DEFAULT_MAX_EXECUTIONS = 50;
|
|
484
484
|
/**
|
|
485
485
|
* Cap for any single serialized value stored in the durable log (args, a
|
|
486
|
-
* recorded result, the final result)
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
486
|
+
* recorded result, the final result), counted in UTF-16 code units. A Durable
|
|
487
|
+
* Object's SQLite row holds 8 MiB in production but about 2.2 MB in older
|
|
488
|
+
* local workerd and the vitest pool (measured). ASCII values under the cap fit
|
|
489
|
+
* every runtime; a value of 3-byte characters can reach 3 MB of UTF-8, which
|
|
490
|
+
* fits production only. Truncating args or recorded results is never an
|
|
491
|
+
* option (replay would feed resumed code corrupted data), so a breach fails
|
|
492
|
+
* the run with a model-actionable error. A final result over the cap is
|
|
493
|
+
* replaced by a note, since replay never needs it (see `complete`).
|
|
490
494
|
*/
|
|
491
495
|
const MAX_DURABLE_VALUE_BYTES = 1e6;
|
|
492
496
|
/** Default age after which a paused (awaiting-approval) run can be expired. */
|