@fractaal/pi-codemode 1.4.1 → 1.6.0
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/README.md +2 -2
- package/dist/declarations.d.ts +5 -0
- package/dist/declarations.d.ts.map +1 -1
- package/dist/declarations.js +15 -3
- package/dist/declarations.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -275,7 +275,7 @@ import {
|
|
|
275
275
|
type CodemodeTool,
|
|
276
276
|
renderDeclarations,
|
|
277
277
|
} from "@earendil-works/pi-codemode";
|
|
278
|
-
import {
|
|
278
|
+
import { obj, str } from "@earendil-works/pi-schema";
|
|
279
279
|
|
|
280
280
|
const sandboxTools: CodemodeTool[] = agentTools.map((tool) => ({
|
|
281
281
|
name: tool.name,
|
|
@@ -293,7 +293,7 @@ const codemodeTool: AgentTool = {
|
|
|
293
293
|
name: "codemode",
|
|
294
294
|
label: "Codemode",
|
|
295
295
|
description: `Run JavaScript that calls tools as \`await tools.<name>(args)\`. Output with text() or return.\n\n${renderDeclarations({ tools: sandboxTools })}`,
|
|
296
|
-
parameters:
|
|
296
|
+
parameters: obj({ code: str() }),
|
|
297
297
|
execute: async (_toolCallId, { code }, signal) => {
|
|
298
298
|
const sandbox = new CodemodeSandbox({ tools: sandboxTools });
|
|
299
299
|
try {
|
package/dist/declarations.d.ts
CHANGED
|
@@ -40,4 +40,9 @@ export declare function renderToolOutputType(schema: CodemodeJsonSchema | undefi
|
|
|
40
40
|
export declare function schemaToType(schema: CodemodeJsonSchema, options?: {
|
|
41
41
|
maxChars?: number;
|
|
42
42
|
}): string;
|
|
43
|
+
/**
|
|
44
|
+
* The subschema a local `$ref` (`#`, `#/$defs/Item`) names in `root`, or undefined for remote references and
|
|
45
|
+
* references that name nothing. Pointer segments are URI-decoded and JSON Pointer unescaped (`~1` is `/`, `~0` is `~`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveSchemaRef(ref: string, root: unknown): CodemodeJsonSchema | undefined;
|
|
43
48
|
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAInE,+EAA+E;AAC/E,eAAO,MAAM,8BAA8B,QAAS,CAAC;AAyBrD,MAAM,WAAW,yBAAyB;IACzC,KAAK,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAyB7E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,CAAC,EACjE,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAO,GACtC,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,cAAc,CAAC,EACjF,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAO,GACtC,MAAM,CAGR;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,MAAM,CAEnF;AA6BD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO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ACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,kBAAkB,GAAG,SAAS,CAqB3F"}
|
package/dist/declarations.js
CHANGED
|
@@ -121,12 +121,24 @@ export function schemaToType(schema, options = {}) {
|
|
|
121
121
|
const untagged = render(false);
|
|
122
122
|
return untagged.length <= options.maxChars ? untagged : "unknown";
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The subschema a local `$ref` (`#`, `#/$defs/Item`) names in `root`, or undefined for remote references and
|
|
126
|
+
* references that name nothing. Pointer segments are URI-decoded and JSON Pointer unescaped (`~1` is `/`, `~0` is `~`).
|
|
127
|
+
*/
|
|
128
|
+
export function resolveSchemaRef(ref, root) {
|
|
125
129
|
if (ref !== "#" && !ref.startsWith("#/"))
|
|
126
130
|
return undefined;
|
|
127
131
|
let current = root;
|
|
128
132
|
for (const segment of ref.slice(2).split("/").filter(Boolean)) {
|
|
129
|
-
|
|
133
|
+
let decoded;
|
|
134
|
+
try {
|
|
135
|
+
decoded = decodeURIComponent(segment);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Schemas come from tools and MCP servers: a malformed escape names nothing instead of failing the caller.
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const key = decoded.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
130
142
|
if (typeof current !== "object" || current === null || Array.isArray(current) || !(key in current)) {
|
|
131
143
|
return undefined;
|
|
132
144
|
}
|
|
@@ -149,7 +161,7 @@ function toType(schema, context) {
|
|
|
149
161
|
const ref = schema.$ref;
|
|
150
162
|
if (context.resolving.has(ref) || context.expansions >= MAX_REF_EXPANSIONS)
|
|
151
163
|
return "unknown";
|
|
152
|
-
const target =
|
|
164
|
+
const target = resolveSchemaRef(ref, context.root);
|
|
153
165
|
if (target === undefined)
|
|
154
166
|
return "unknown";
|
|
155
167
|
context.expansions++;
|
package/dist/declarations.js.map
CHANGED
|
@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nimport type { CodemodeJsonSchema, CodemodeTool } from \"./types.ts\";\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\nconst INDENT = \" \";\n/** Largest rendered input type, in characters, before it becomes `unknown`. */\nexport const DEFAULT_INPUT_SCHEMA_MAX_CHARS = 16_000;\n/** Local `$ref` expansions per rendered schema, so shared definitions cannot blow up the output. */\nconst MAX_REF_EXPANSIONS = 32;\n/** JSON Schema keywords with a number or string value shown as `@keyword value` property tags. */\nconst TAG_KEYWORDS = [\n\t\"minimum\",\n\t\"exclusiveMinimum\",\n\t\"maximum\",\n\t\"exclusiveMaximum\",\n\t\"multipleOf\",\n\t\"minLength\",\n\t\"maxLength\",\n\t\"pattern\",\n\t\"format\",\n\t\"minItems\",\n\t\"maxItems\",\n];\n/** Tag keywords whose values all hold at once, so only the largest (lower) or smallest (upper) matters. */\nconst LOWER_BOUNDS = new Set([\"minimum\", \"exclusiveMinimum\", \"minLength\", \"minItems\"]);\nconst UPPER_BOUNDS = new Set([\"maximum\", \"exclusiveMaximum\", \"maxLength\", \"maxItems\"]);\n/** Longest property tag; longer ones (large defaults, long patterns) are left out. */\nconst MAX_TAG_CHARS = 80;\n/** Characters that end a `//` comment. */\nconst LINE_TERMINATORS = /[\\r\\n\\u2028\\u2029]/g;\n\nexport interface RenderDeclarationsOptions {\n\ttools?: readonly CodemodeTool[];\n\tglobals?: readonly CodemodeTool[];\n}\n\n/**\n * Render TypeScript declarations for the script-visible API. Tools become members of\n * `declare const tools`, globals become `declare function` statements, and `ns.member` globals\n * members of `declare const ns`. Descriptions become doc comments; schemas become types.\n */\nexport function renderDeclarations(options: RenderDeclarationsOptions): string {\n\tconst sections: string[] = [];\n\tconst tools = options.tools ?? [];\n\tif (tools.length > 0) {\n\t\tconst members = tools.map(\n\t\t\t(tool) => `${docComment(tool.description, INDENT)}${INDENT}${renderToolSignature(tool)}`,\n\t\t);\n\t\tsections.push(`declare const tools: {\\n${members.join(\"\\n\")}\\n};`);\n\t}\n\tconst namespaces = new Map<string, string[]>();\n\tfor (const global of options.globals ?? []) {\n\t\tconst dot = global.name.indexOf(\".\");\n\t\tif (dot === -1) {\n\t\t\tsections.push(renderGlobal(`declare function ${global.name}`, global, \"\"));\n\t\t\tcontinue;\n\t\t}\n\t\tconst namespace = global.name.slice(0, dot);\n\t\tconst members = namespaces.get(namespace) ?? [];\n\t\tif (members.length === 0) namespaces.set(namespace, members);\n\t\tmembers.push(renderGlobal(global.name.slice(dot + 1), global, INDENT));\n\t}\n\tfor (const [namespace, members] of namespaces) {\n\t\tsections.push(`declare const ${namespace}: {\\n${members.join(\"\\n\")}\\n};`);\n\t}\n\treturn sections.join(\"\\n\\n\");\n}\n\n/**\n * One tool as a member of the `tools` object: `name(args: T): Promise<R>;` with the\n * name as the identifier scripts use. Input types longer than `inputMaxChars` render as `unknown`.\n */\nexport function renderToolSignature(\n\ttool: Pick<CodemodeTool, \"name\" | \"inputSchema\" | \"outputSchema\">,\n\toptions: { inputMaxChars?: number } = {},\n): string {\n\tconst input =\n\t\ttool.inputSchema === undefined\n\t\t\t? \"unknown\"\n\t\t\t: schemaToType(tool.inputSchema, { maxChars: options.inputMaxChars ?? DEFAULT_INPUT_SCHEMA_MAX_CHARS });\n\treturn `${toCodemodeIdentifier(tool.name)}(args: ${input}): Promise<${renderToolOutputType(tool.outputSchema)}>;`;\n}\n\n/**\n * A tool's sample: the description followed by the tool's declaration. Used for tool\n * listings and `ALL_TOOLS` entries.\n */\nexport function renderToolSample(\n\ttool: Pick<CodemodeTool, \"name\" | \"description\" | \"inputSchema\" | \"outputSchema\">,\n\toptions: { inputMaxChars?: number } = {},\n): string {\n\tconst declaration = `declare const tools: { ${renderToolSignature(tool, options)} };`;\n\treturn `${tool.description?.trim() ?? \"\"}\\n\\ncodemode tool declaration:\\n\\`\\`\\`ts\\n${declaration}\\n\\`\\`\\``;\n}\n\n/** The type a tool call resolves to: the output schema's type, and `unknown` without a schema. */\nexport function renderToolOutputType(schema: CodemodeJsonSchema | undefined): string {\n\treturn schema === undefined ? \"unknown\" : schemaToType(schema);\n}\n\nfunction renderGlobal(head: string, global: CodemodeTool, indent: string): string {\n\tif (global.signature !== undefined) {\n\t\treturn `${docComment(global.description, indent)}${indent}${head}${global.signature};`;\n\t}\n\tconst input = global.inputSchema === undefined ? \"unknown\" : schemaToType(global.inputSchema);\n\tconst output = global.outputSchema === undefined ? \"unknown\" : schemaToType(global.outputSchema);\n\treturn `${docComment(global.description, indent)}${indent}${head}(args: ${input}): Promise<${output}>;`;\n}\n\nfunction docComment(description: string | undefined, indent: string): string {\n\tconst text = description?.trim();\n\tif (!text) return \"\";\n\tconst lines = text.replaceAll(\"*/\", \"*\\\\/\").split(/\\r?\\n/);\n\tif (lines.length === 1) return `${indent}/** ${lines[0]} */\\n`;\n\treturn `${indent}/**\\n${lines.map((line) => `${indent} *${line ? ` ${line}` : \"\"}`).join(\"\\n\")}\\n${indent} */\\n`;\n}\n\nfunction propertyKey(name: string): string {\n\treturn IDENTIFIER.test(name) ? name : JSON.stringify(name);\n}\n\nfunction union(types: string[]): string {\n\tconst unique = [...new Set(types)];\n\tif (unique.includes(\"unknown\")) return \"unknown\";\n\treturn unique.length === 0 ? \"never\" : unique.join(\" | \");\n}\n\n/**\n * Convert a JSON Schema to a TypeScript type expression: objects on one line (`{ a: string; b?: number; }`) with properties sorted by name,\n * or one property per line with `//` comments when a property has a description or constraints the\n * type cannot express (`// @integer @minimum 1 @default 20`); `Array<T>` for arrays. Local references\n * (`#/$defs/...`, `#/definitions/...`) resolve against `schema`; recursive and remote references\n * render as `unknown`. A result longer than `maxChars` is rendered again without the constraint tags,\n * and renders as `unknown` if it is still too long.\n */\nexport function schemaToType(schema: CodemodeJsonSchema, options: { maxChars?: number } = {}): string {\n\tconst render = (tags: boolean) => toType(schema, { root: schema, resolving: new Set(), expansions: 0, tags });\n\tconst type = render(true);\n\tif (options.maxChars === undefined || type.length <= options.maxChars) return type;\n\tconst untagged = render(false);\n\treturn untagged.length <= options.maxChars ? untagged : \"unknown\";\n}\n\ninterface SchemaContext {\n\troot: CodemodeJsonSchema;\n\t/** References being expanded on the current path, to stop at recursive types. */\n\tresolving: Set<string>;\n\texpansions: number;\n\t/** Whether property comments include constraint tags. */\n\ttags: boolean;\n}\n\nfunction resolveRef(ref: string, root: CodemodeJsonSchema): CodemodeJsonSchema | undefined {\n\tif (ref !== \"#\" && !ref.startsWith(\"#/\")) return undefined;\n\tlet current: unknown = root;\n\tfor (const segment of ref.slice(2).split(\"/\").filter(Boolean)) {\n\t\tconst key = decodeURIComponent(segment).replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n\t\tif (typeof current !== \"object\" || current === null || Array.isArray(current) || !(key in current)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrent = (current as Record<string, unknown>)[key];\n\t}\n\tif (typeof current === \"boolean\") return current;\n\treturn typeof current === \"object\" && current !== null && !Array.isArray(current)\n\t\t? (current as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction toType(schema: CodemodeJsonSchema, context: SchemaContext): string {\n\tif (schema === true) return \"unknown\";\n\tif (schema === false) return \"never\";\n\tif (typeof schema !== \"object\" || schema === null || Array.isArray(schema)) return \"unknown\";\n\tif (typeof schema.$ref === \"string\") {\n\t\tconst ref = schema.$ref;\n\t\tif (context.resolving.has(ref) || context.expansions >= MAX_REF_EXPANSIONS) return \"unknown\";\n\t\tconst target = resolveRef(ref, context.root);\n\t\tif (target === undefined) return \"unknown\";\n\t\tcontext.expansions++;\n\t\tcontext.resolving.add(ref);\n\t\ttry {\n\t\t\treturn toType(target, context);\n\t\t} finally {\n\t\t\tcontext.resolving.delete(ref);\n\t\t}\n\t}\n\n\tif (\"const\" in schema) return JSON.stringify(schema.const) ?? \"unknown\";\n\tif (Array.isArray(schema.enum)) return union(schema.enum.map((value) => JSON.stringify(value) ?? \"unknown\"));\n\n\tconst variants = Array.isArray(schema.anyOf) ? schema.anyOf : Array.isArray(schema.oneOf) ? schema.oneOf : undefined;\n\tif (variants) return union(variants.map((variant) => toType(variant as CodemodeJsonSchema, context)));\n\tif (Array.isArray(schema.allOf)) {\n\t\tconst parts = schema.allOf\n\t\t\t.map((part) => toType(part as CodemodeJsonSchema, context))\n\t\t\t.filter((part) => part !== \"unknown\");\n\t\treturn parts.length === 0\n\t\t\t? \"unknown\"\n\t\t\t: parts.map((part) => (part.includes(\" | \") ? `(${part})` : part)).join(\" & \");\n\t}\n\n\tconst type = schema.type;\n\tif (Array.isArray(type)) return union(type.map((entry) => toType({ ...schema, type: entry }, context)));\n\tswitch (type) {\n\t\tcase \"string\":\n\t\t\treturn \"string\";\n\t\tcase \"number\":\n\t\tcase \"integer\":\n\t\t\treturn \"number\";\n\t\tcase \"boolean\":\n\t\t\treturn \"boolean\";\n\t\tcase \"null\":\n\t\t\treturn \"null\";\n\t\tcase \"array\":\n\t\t\treturn arrayType(schema, context);\n\t\tcase \"object\":\n\t\t\treturn objectType(schema, context);\n\t\tcase undefined:\n\t\t\tif (\"properties\" in schema || \"additionalProperties\" in schema || \"required\" in schema) {\n\t\t\t\treturn objectType(schema, context);\n\t\t\t}\n\t\t\tif (\"items\" in schema || \"prefixItems\" in schema) return arrayType(schema, context);\n\t\t\treturn \"unknown\";\n\t\tdefault:\n\t\t\treturn \"unknown\";\n\t}\n}\n\nfunction arrayType(schema: Record<string, unknown>, context: SchemaContext): string {\n\tif (schema.items !== undefined && !Array.isArray(schema.items)) {\n\t\treturn `Array<${toType(schema.items as CodemodeJsonSchema, context)}>`;\n\t}\n\tconst tuple = Array.isArray(schema.prefixItems)\n\t\t? schema.prefixItems\n\t\t: Array.isArray(schema.items)\n\t\t\t? schema.items\n\t\t\t: [];\n\tif (tuple.length > 0) return `[${tuple.map((item) => toType(item as CodemodeJsonSchema, context)).join(\", \")}]`;\n\treturn \"unknown[]\";\n}\n\nfunction descriptionOf(property: unknown): string {\n\tconst description = (property as { description?: unknown } | null | undefined)?.description;\n\treturn typeof description === \"string\" ? description.trim() : \"\";\n}\n\n/**\n * Constraints of a property that its TypeScript type cannot express, as JSDoc-style tags:\n * `@integer @minimum 1 @maximum 100 @default 20`. Empty when there are none.\n */\nfunction constraintTags(schema: unknown): string {\n\tif (typeof schema !== \"object\" || schema === null || Array.isArray(schema)) return \"\";\n\tconst property = schema as Record<string, unknown>;\n\t// Optional fields such as Pydantic's `int | None` keep their constraints in the non-null branch.\n\t// The branch's constraints apply together with the property's, so both are read.\n\tconst variants = Array.isArray(property.anyOf) ? property.anyOf : property.oneOf;\n\tconst nonNull: unknown[] = Array.isArray(variants)\n\t\t? variants.filter((variant) => (variant as { type?: unknown } | null)?.type !== \"null\")\n\t\t: [];\n\tconst branch = nonNull.length === 1 ? nonNull[0] : undefined;\n\tconst branches =\n\t\ttypeof branch === \"object\" && branch !== null && !Array.isArray(branch)\n\t\t\t? [property, branch as Record<string, unknown>]\n\t\t\t: [property];\n\t// Draft-04 and OpenAPI 3.0 make `minimum`/`maximum` exclusive with a boolean `exclusiveMinimum`/`exclusiveMaximum`.\n\tconst schemas = branches.map(\n\t\t(schema): Record<string, unknown> => ({\n\t\t\t...schema,\n\t\t\t...(schema.exclusiveMinimum === true ? { minimum: undefined, exclusiveMinimum: schema.minimum } : {}),\n\t\t\t...(schema.exclusiveMaximum === true ? { maximum: undefined, exclusiveMaximum: schema.maximum } : {}),\n\t\t}),\n\t);\n\n\tconst tags: string[] = [];\n\tconst isInteger = (type: unknown) => type === \"integer\" || (Array.isArray(type) && type.includes(\"integer\"));\n\tif (schemas.some((schema) => isInteger(schema.type))) tags.push(\"@integer\");\n\tfor (const keyword of TAG_KEYWORDS) {\n\t\tconst values = schemas.map((schema) => schema[keyword]);\n\t\tif (LOWER_BOUNDS.has(keyword) || UPPER_BOUNDS.has(keyword)) {\n\t\t\tconst numbers = values.filter((value) => typeof value === \"number\");\n\t\t\tif (numbers.length === 0) continue;\n\t\t\ttags.push(`@${keyword} ${LOWER_BOUNDS.has(keyword) ? Math.max(...numbers) : Math.min(...numbers)}`);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const value of new Set(values)) {\n\t\t\tif (typeof value === \"number\" || typeof value === \"string\") tags.push(`@${keyword} ${value}`);\n\t\t}\n\t}\n\tif (schemas.some((schema) => schema.uniqueItems === true)) tags.push(\"@uniqueItems\");\n\t// Annotations, unlike constraints, come from the property itself.\n\tif (property.default !== undefined && property.default !== null) {\n\t\ttags.push(`@default ${JSON.stringify(property.default)}`);\n\t}\n\tif (property.deprecated === true) tags.push(\"@deprecated\");\n\treturn tags\n\t\t.filter((tag) => tag.length <= MAX_TAG_CHARS)\n\t\t.map((tag) => tag.replace(LINE_TERMINATORS, (char) => `\\\\u${char.charCodeAt(0).toString(16).padStart(4, \"0\")}`))\n\t\t.join(\" \");\n}\n\nfunction objectType(schema: Record<string, unknown>, context: SchemaContext): string {\n\tconst properties =\n\t\ttypeof schema.properties === \"object\" && schema.properties !== null && !Array.isArray(schema.properties)\n\t\t\t? (schema.properties as Record<string, unknown>)\n\t\t\t: {};\n\tconst required = new Set(Array.isArray(schema.required) ? schema.required : []);\n\tconst names = Object.keys(properties).sort();\n\tconst members = names.map((name) => {\n\t\tconst optional = required.has(name) ? \"\" : \"?\";\n\t\treturn `${propertyKey(name)}${optional}: ${toType(properties[name] as CodemodeJsonSchema, context)};`;\n\t});\n\tconst additional = schema.additionalProperties;\n\tif (additional !== undefined && additional !== false) {\n\t\tconst type = additional === true ? \"unknown\" : toType(additional as CodemodeJsonSchema, context);\n\t\tmembers.push(`[key: string]: ${type};`);\n\t} else if (additional === undefined && names.length === 0) {\n\t\tmembers.push(\"[key: string]: unknown;\");\n\t}\n\tif (members.length === 0) return \"{}\";\n\tconst comments = names.map((name) => {\n\t\tconst lines = descriptionOf(properties[name])\n\t\t\t.split(LINE_TERMINATORS)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(Boolean);\n\t\tconst tags = context.tags ? constraintTags(properties[name]) : \"\";\n\t\treturn tags ? [...lines, tags] : lines;\n\t});\n\tif (!comments.some((comment) => comment.length > 0)) return `{ ${members.join(\" \")} }`;\n\n\tconst lines = [\"{\"];\n\tcomments.forEach((comment, index) => {\n\t\tfor (const line of comment) lines.push(`${INDENT}// ${line}`);\n\t\tlines.push(`${INDENT}${members[index].replaceAll(\"\\n\", `\\n${INDENT}`)}`);\n\t});\n\tfor (const member of members.slice(names.length)) lines.push(`${INDENT}${member}`);\n\tlines.push(\"}\");\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAIhC,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAChD,MAAM,MAAM,GAAG,IAAI,CAAC;AACpB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAC;AACrD,oGAAoG;AACpG,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,kGAAkG;AAClG,MAAM,YAAY,GAAG;IACpB,SAAS;IACT,kBAAkB;IAClB,SAAS;IACT,kBAAkB;IAClB,YAAY;IACZ,WAAW;IACX,WAAW;IACX,SAAS;IACT,QAAQ;IACR,UAAU;IACV,UAAU;CACV,CAAC;AACF,2GAA2G;AAC3G,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AACvF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AACvF,sFAAsF;AACtF,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,0CAA0C;AAC1C,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAO/C;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACpE,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AAC,KAAK,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IACH,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACnF,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { toCodemodeIdentifier } from \"./identifier.ts\";\n\nexport { toCodemodeIdentifier };\n\nimport type { CodemodeJsonSchema, CodemodeTool } from \"./types.ts\";\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\nconst INDENT = \" \";\n/** Largest rendered input type, in characters, before it becomes `unknown`. */\nexport const DEFAULT_INPUT_SCHEMA_MAX_CHARS = 16_000;\n/** Local `$ref` expansions per rendered schema, so shared definitions cannot blow up the output. */\nconst MAX_REF_EXPANSIONS = 32;\n/** JSON Schema keywords with a number or string value shown as `@keyword value` property tags. */\nconst TAG_KEYWORDS = [\n\t\"minimum\",\n\t\"exclusiveMinimum\",\n\t\"maximum\",\n\t\"exclusiveMaximum\",\n\t\"multipleOf\",\n\t\"minLength\",\n\t\"maxLength\",\n\t\"pattern\",\n\t\"format\",\n\t\"minItems\",\n\t\"maxItems\",\n];\n/** Tag keywords whose values all hold at once, so only the largest (lower) or smallest (upper) matters. */\nconst LOWER_BOUNDS = new Set([\"minimum\", \"exclusiveMinimum\", \"minLength\", \"minItems\"]);\nconst UPPER_BOUNDS = new Set([\"maximum\", \"exclusiveMaximum\", \"maxLength\", \"maxItems\"]);\n/** Longest property tag; longer ones (large defaults, long patterns) are left out. */\nconst MAX_TAG_CHARS = 80;\n/** Characters that end a `//` comment. */\nconst LINE_TERMINATORS = /[\\r\\n\\u2028\\u2029]/g;\n\nexport interface RenderDeclarationsOptions {\n\ttools?: readonly CodemodeTool[];\n\tglobals?: readonly CodemodeTool[];\n}\n\n/**\n * Render TypeScript declarations for the script-visible API. Tools become members of\n * `declare const tools`, globals become `declare function` statements, and `ns.member` globals\n * members of `declare const ns`. Descriptions become doc comments; schemas become types.\n */\nexport function renderDeclarations(options: RenderDeclarationsOptions): string {\n\tconst sections: string[] = [];\n\tconst tools = options.tools ?? [];\n\tif (tools.length > 0) {\n\t\tconst members = tools.map(\n\t\t\t(tool) => `${docComment(tool.description, INDENT)}${INDENT}${renderToolSignature(tool)}`,\n\t\t);\n\t\tsections.push(`declare const tools: {\\n${members.join(\"\\n\")}\\n};`);\n\t}\n\tconst namespaces = new Map<string, string[]>();\n\tfor (const global of options.globals ?? []) {\n\t\tconst dot = global.name.indexOf(\".\");\n\t\tif (dot === -1) {\n\t\t\tsections.push(renderGlobal(`declare function ${global.name}`, global, \"\"));\n\t\t\tcontinue;\n\t\t}\n\t\tconst namespace = global.name.slice(0, dot);\n\t\tconst members = namespaces.get(namespace) ?? [];\n\t\tif (members.length === 0) namespaces.set(namespace, members);\n\t\tmembers.push(renderGlobal(global.name.slice(dot + 1), global, INDENT));\n\t}\n\tfor (const [namespace, members] of namespaces) {\n\t\tsections.push(`declare const ${namespace}: {\\n${members.join(\"\\n\")}\\n};`);\n\t}\n\treturn sections.join(\"\\n\\n\");\n}\n\n/**\n * One tool as a member of the `tools` object: `name(args: T): Promise<R>;` with the\n * name as the identifier scripts use. Input types longer than `inputMaxChars` render as `unknown`.\n */\nexport function renderToolSignature(\n\ttool: Pick<CodemodeTool, \"name\" | \"inputSchema\" | \"outputSchema\">,\n\toptions: { inputMaxChars?: number } = {},\n): string {\n\tconst input =\n\t\ttool.inputSchema === undefined\n\t\t\t? \"unknown\"\n\t\t\t: schemaToType(tool.inputSchema, { maxChars: options.inputMaxChars ?? DEFAULT_INPUT_SCHEMA_MAX_CHARS });\n\treturn `${toCodemodeIdentifier(tool.name)}(args: ${input}): Promise<${renderToolOutputType(tool.outputSchema)}>;`;\n}\n\n/**\n * A tool's sample: the description followed by the tool's declaration. Used for tool\n * listings and `ALL_TOOLS` entries.\n */\nexport function renderToolSample(\n\ttool: Pick<CodemodeTool, \"name\" | \"description\" | \"inputSchema\" | \"outputSchema\">,\n\toptions: { inputMaxChars?: number } = {},\n): string {\n\tconst declaration = `declare const tools: { ${renderToolSignature(tool, options)} };`;\n\treturn `${tool.description?.trim() ?? \"\"}\\n\\ncodemode tool declaration:\\n\\`\\`\\`ts\\n${declaration}\\n\\`\\`\\``;\n}\n\n/** The type a tool call resolves to: the output schema's type, and `unknown` without a schema. */\nexport function renderToolOutputType(schema: CodemodeJsonSchema | undefined): string {\n\treturn schema === undefined ? \"unknown\" : schemaToType(schema);\n}\n\nfunction renderGlobal(head: string, global: CodemodeTool, indent: string): string {\n\tif (global.signature !== undefined) {\n\t\treturn `${docComment(global.description, indent)}${indent}${head}${global.signature};`;\n\t}\n\tconst input = global.inputSchema === undefined ? \"unknown\" : schemaToType(global.inputSchema);\n\tconst output = global.outputSchema === undefined ? \"unknown\" : schemaToType(global.outputSchema);\n\treturn `${docComment(global.description, indent)}${indent}${head}(args: ${input}): Promise<${output}>;`;\n}\n\nfunction docComment(description: string | undefined, indent: string): string {\n\tconst text = description?.trim();\n\tif (!text) return \"\";\n\tconst lines = text.replaceAll(\"*/\", \"*\\\\/\").split(/\\r?\\n/);\n\tif (lines.length === 1) return `${indent}/** ${lines[0]} */\\n`;\n\treturn `${indent}/**\\n${lines.map((line) => `${indent} *${line ? ` ${line}` : \"\"}`).join(\"\\n\")}\\n${indent} */\\n`;\n}\n\nfunction propertyKey(name: string): string {\n\treturn IDENTIFIER.test(name) ? name : JSON.stringify(name);\n}\n\nfunction union(types: string[]): string {\n\tconst unique = [...new Set(types)];\n\tif (unique.includes(\"unknown\")) return \"unknown\";\n\treturn unique.length === 0 ? \"never\" : unique.join(\" | \");\n}\n\n/**\n * Convert a JSON Schema to a TypeScript type expression: objects on one line (`{ a: string; b?: number; }`) with properties sorted by name,\n * or one property per line with `//` comments when a property has a description or constraints the\n * type cannot express (`// @integer @minimum 1 @default 20`); `Array<T>` for arrays. Local references\n * (`#/$defs/...`, `#/definitions/...`) resolve against `schema`; recursive and remote references\n * render as `unknown`. A result longer than `maxChars` is rendered again without the constraint tags,\n * and renders as `unknown` if it is still too long.\n */\nexport function schemaToType(schema: CodemodeJsonSchema, options: { maxChars?: number } = {}): string {\n\tconst render = (tags: boolean) => toType(schema, { root: schema, resolving: new Set(), expansions: 0, tags });\n\tconst type = render(true);\n\tif (options.maxChars === undefined || type.length <= options.maxChars) return type;\n\tconst untagged = render(false);\n\treturn untagged.length <= options.maxChars ? untagged : \"unknown\";\n}\n\ninterface SchemaContext {\n\troot: CodemodeJsonSchema;\n\t/** References being expanded on the current path, to stop at recursive types. */\n\tresolving: Set<string>;\n\texpansions: number;\n\t/** Whether property comments include constraint tags. */\n\ttags: boolean;\n}\n\n/**\n * The subschema a local `$ref` (`#`, `#/$defs/Item`) names in `root`, or undefined for remote references and\n * references that name nothing. Pointer segments are URI-decoded and JSON Pointer unescaped (`~1` is `/`, `~0` is `~`).\n */\nexport function resolveSchemaRef(ref: string, root: unknown): CodemodeJsonSchema | undefined {\n\tif (ref !== \"#\" && !ref.startsWith(\"#/\")) return undefined;\n\tlet current: unknown = root;\n\tfor (const segment of ref.slice(2).split(\"/\").filter(Boolean)) {\n\t\tlet decoded: string;\n\t\ttry {\n\t\t\tdecoded = decodeURIComponent(segment);\n\t\t} catch {\n\t\t\t// Schemas come from tools and MCP servers: a malformed escape names nothing instead of failing the caller.\n\t\t\treturn undefined;\n\t\t}\n\t\tconst key = decoded.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n\t\tif (typeof current !== \"object\" || current === null || Array.isArray(current) || !(key in current)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrent = (current as Record<string, unknown>)[key];\n\t}\n\tif (typeof current === \"boolean\") return current;\n\treturn typeof current === \"object\" && current !== null && !Array.isArray(current)\n\t\t? (current as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction toType(schema: CodemodeJsonSchema, context: SchemaContext): string {\n\tif (schema === true) return \"unknown\";\n\tif (schema === false) return \"never\";\n\tif (typeof schema !== \"object\" || schema === null || Array.isArray(schema)) return \"unknown\";\n\tif (typeof schema.$ref === \"string\") {\n\t\tconst ref = schema.$ref;\n\t\tif (context.resolving.has(ref) || context.expansions >= MAX_REF_EXPANSIONS) return \"unknown\";\n\t\tconst target = resolveSchemaRef(ref, context.root);\n\t\tif (target === undefined) return \"unknown\";\n\t\tcontext.expansions++;\n\t\tcontext.resolving.add(ref);\n\t\ttry {\n\t\t\treturn toType(target, context);\n\t\t} finally {\n\t\t\tcontext.resolving.delete(ref);\n\t\t}\n\t}\n\n\tif (\"const\" in schema) return JSON.stringify(schema.const) ?? \"unknown\";\n\tif (Array.isArray(schema.enum)) return union(schema.enum.map((value) => JSON.stringify(value) ?? \"unknown\"));\n\n\tconst variants = Array.isArray(schema.anyOf) ? schema.anyOf : Array.isArray(schema.oneOf) ? schema.oneOf : undefined;\n\tif (variants) return union(variants.map((variant) => toType(variant as CodemodeJsonSchema, context)));\n\tif (Array.isArray(schema.allOf)) {\n\t\tconst parts = schema.allOf\n\t\t\t.map((part) => toType(part as CodemodeJsonSchema, context))\n\t\t\t.filter((part) => part !== \"unknown\");\n\t\treturn parts.length === 0\n\t\t\t? \"unknown\"\n\t\t\t: parts.map((part) => (part.includes(\" | \") ? `(${part})` : part)).join(\" & \");\n\t}\n\n\tconst type = schema.type;\n\tif (Array.isArray(type)) return union(type.map((entry) => toType({ ...schema, type: entry }, context)));\n\tswitch (type) {\n\t\tcase \"string\":\n\t\t\treturn \"string\";\n\t\tcase \"number\":\n\t\tcase \"integer\":\n\t\t\treturn \"number\";\n\t\tcase \"boolean\":\n\t\t\treturn \"boolean\";\n\t\tcase \"null\":\n\t\t\treturn \"null\";\n\t\tcase \"array\":\n\t\t\treturn arrayType(schema, context);\n\t\tcase \"object\":\n\t\t\treturn objectType(schema, context);\n\t\tcase undefined:\n\t\t\tif (\"properties\" in schema || \"additionalProperties\" in schema || \"required\" in schema) {\n\t\t\t\treturn objectType(schema, context);\n\t\t\t}\n\t\t\tif (\"items\" in schema || \"prefixItems\" in schema) return arrayType(schema, context);\n\t\t\treturn \"unknown\";\n\t\tdefault:\n\t\t\treturn \"unknown\";\n\t}\n}\n\nfunction arrayType(schema: Record<string, unknown>, context: SchemaContext): string {\n\tif (schema.items !== undefined && !Array.isArray(schema.items)) {\n\t\treturn `Array<${toType(schema.items as CodemodeJsonSchema, context)}>`;\n\t}\n\tconst tuple = Array.isArray(schema.prefixItems)\n\t\t? schema.prefixItems\n\t\t: Array.isArray(schema.items)\n\t\t\t? schema.items\n\t\t\t: [];\n\tif (tuple.length > 0) return `[${tuple.map((item) => toType(item as CodemodeJsonSchema, context)).join(\", \")}]`;\n\treturn \"unknown[]\";\n}\n\nfunction descriptionOf(property: unknown): string {\n\tconst description = (property as { description?: unknown } | null | undefined)?.description;\n\treturn typeof description === \"string\" ? description.trim() : \"\";\n}\n\n/**\n * Constraints of a property that its TypeScript type cannot express, as JSDoc-style tags:\n * `@integer @minimum 1 @maximum 100 @default 20`. Empty when there are none.\n */\nfunction constraintTags(schema: unknown): string {\n\tif (typeof schema !== \"object\" || schema === null || Array.isArray(schema)) return \"\";\n\tconst property = schema as Record<string, unknown>;\n\t// Optional fields such as Pydantic's `int | None` keep their constraints in the non-null branch.\n\t// The branch's constraints apply together with the property's, so both are read.\n\tconst variants = Array.isArray(property.anyOf) ? property.anyOf : property.oneOf;\n\tconst nonNull: unknown[] = Array.isArray(variants)\n\t\t? variants.filter((variant) => (variant as { type?: unknown } | null)?.type !== \"null\")\n\t\t: [];\n\tconst branch = nonNull.length === 1 ? nonNull[0] : undefined;\n\tconst branches =\n\t\ttypeof branch === \"object\" && branch !== null && !Array.isArray(branch)\n\t\t\t? [property, branch as Record<string, unknown>]\n\t\t\t: [property];\n\t// Draft-04 and OpenAPI 3.0 make `minimum`/`maximum` exclusive with a boolean `exclusiveMinimum`/`exclusiveMaximum`.\n\tconst schemas = branches.map(\n\t\t(schema): Record<string, unknown> => ({\n\t\t\t...schema,\n\t\t\t...(schema.exclusiveMinimum === true ? { minimum: undefined, exclusiveMinimum: schema.minimum } : {}),\n\t\t\t...(schema.exclusiveMaximum === true ? { maximum: undefined, exclusiveMaximum: schema.maximum } : {}),\n\t\t}),\n\t);\n\n\tconst tags: string[] = [];\n\tconst isInteger = (type: unknown) => type === \"integer\" || (Array.isArray(type) && type.includes(\"integer\"));\n\tif (schemas.some((schema) => isInteger(schema.type))) tags.push(\"@integer\");\n\tfor (const keyword of TAG_KEYWORDS) {\n\t\tconst values = schemas.map((schema) => schema[keyword]);\n\t\tif (LOWER_BOUNDS.has(keyword) || UPPER_BOUNDS.has(keyword)) {\n\t\t\tconst numbers = values.filter((value) => typeof value === \"number\");\n\t\t\tif (numbers.length === 0) continue;\n\t\t\ttags.push(`@${keyword} ${LOWER_BOUNDS.has(keyword) ? Math.max(...numbers) : Math.min(...numbers)}`);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const value of new Set(values)) {\n\t\t\tif (typeof value === \"number\" || typeof value === \"string\") tags.push(`@${keyword} ${value}`);\n\t\t}\n\t}\n\tif (schemas.some((schema) => schema.uniqueItems === true)) tags.push(\"@uniqueItems\");\n\t// Annotations, unlike constraints, come from the property itself.\n\tif (property.default !== undefined && property.default !== null) {\n\t\ttags.push(`@default ${JSON.stringify(property.default)}`);\n\t}\n\tif (property.deprecated === true) tags.push(\"@deprecated\");\n\treturn tags\n\t\t.filter((tag) => tag.length <= MAX_TAG_CHARS)\n\t\t.map((tag) => tag.replace(LINE_TERMINATORS, (char) => `\\\\u${char.charCodeAt(0).toString(16).padStart(4, \"0\")}`))\n\t\t.join(\" \");\n}\n\nfunction objectType(schema: Record<string, unknown>, context: SchemaContext): string {\n\tconst properties =\n\t\ttypeof schema.properties === \"object\" && schema.properties !== null && !Array.isArray(schema.properties)\n\t\t\t? (schema.properties as Record<string, unknown>)\n\t\t\t: {};\n\tconst required = new Set(Array.isArray(schema.required) ? schema.required : []);\n\tconst names = Object.keys(properties).sort();\n\tconst members = names.map((name) => {\n\t\tconst optional = required.has(name) ? \"\" : \"?\";\n\t\treturn `${propertyKey(name)}${optional}: ${toType(properties[name] as CodemodeJsonSchema, context)};`;\n\t});\n\tconst additional = schema.additionalProperties;\n\tif (additional !== undefined && additional !== false) {\n\t\tconst type = additional === true ? \"unknown\" : toType(additional as CodemodeJsonSchema, context);\n\t\tmembers.push(`[key: string]: ${type};`);\n\t} else if (additional === undefined && names.length === 0) {\n\t\tmembers.push(\"[key: string]: unknown;\");\n\t}\n\tif (members.length === 0) return \"{}\";\n\tconst comments = names.map((name) => {\n\t\tconst lines = descriptionOf(properties[name])\n\t\t\t.split(LINE_TERMINATORS)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(Boolean);\n\t\tconst tags = context.tags ? constraintTags(properties[name]) : \"\";\n\t\treturn tags ? [...lines, tags] : lines;\n\t});\n\tif (!comments.some((comment) => comment.length > 0)) return `{ ${members.join(\" \")} }`;\n\n\tconst lines = [\"{\"];\n\tcomments.forEach((comment, index) => {\n\t\tfor (const line of comment) lines.push(`${INDENT}// ${line}`);\n\t\tlines.push(`${INDENT}${members[index].replaceAll(\"\\n\", `\\n${INDENT}`)}`);\n\t});\n\tfor (const member of members.slice(names.length)) lines.push(`${INDENT}${member}`);\n\tlines.push(\"}\");\n\treturn lines.join(\"\\n\");\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_INPUT_SCHEMA_MAX_CHARS, type RenderDeclarationsOptions, renderDeclarations, renderToolOutputType, renderToolSample, renderToolSignature, schemaToType, } from "./declarations.ts";
|
|
1
|
+
export { DEFAULT_INPUT_SCHEMA_MAX_CHARS, type RenderDeclarationsOptions, renderDeclarations, renderToolOutputType, renderToolSample, renderToolSignature, resolveSchemaRef, schemaToType, } from "./declarations.ts";
|
|
2
2
|
export { toCodemodeIdentifier } from "./identifier.ts";
|
|
3
3
|
export { CodemodeSandboxBase } from "./runtime/execution.ts";
|
|
4
4
|
export { CodemodeSandbox } from "./runtime/host.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,8BAA8B,EAC9B,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,KAAK,4BAA4B,GACjC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,qBAAqB,EACrB,KAAK,4BAA4B,EACjC,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc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YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,kBAAkB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DEFAULT_INPUT_SCHEMA_MAX_CHARS, renderDeclarations, renderToolOutputType, renderToolSample, renderToolSignature, schemaToType, } from "./declarations.js";
|
|
1
|
+
export { DEFAULT_INPUT_SCHEMA_MAX_CHARS, renderDeclarations, renderToolOutputType, renderToolSample, renderToolSignature, resolveSchemaRef, schemaToType, } from "./declarations.js";
|
|
2
2
|
export { toCodemodeIdentifier } from "./identifier.js";
|
|
3
3
|
export { CodemodeSandboxBase } from "./runtime/execution.js";
|
|
4
4
|
export { CodemodeSandbox } from "./runtime/host.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,8BAA8B,EAE9B,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,wBAAwB,EACxB,qBAAqB,GAErB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAON,qBAAqB,EAErB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EAGnB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAuBrB,OAAO,EAA2B,eAAe,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export {\n\tDEFAULT_INPUT_SCHEMA_MAX_CHARS,\n\ttype RenderDeclarationsOptions,\n\trenderDeclarations,\n\trenderToolOutputType,\n\trenderToolSample,\n\trenderToolSignature,\n\tschemaToType,\n} from \"./declarations.ts\";\nexport { toCodemodeIdentifier } from \"./identifier.ts\";\nexport { CodemodeSandboxBase } from \"./runtime/execution.ts\";\nexport { CodemodeSandbox } from \"./runtime/host.ts\";\nexport {\n\tDEFAULT_INTERRUPT_BUDGET,\n\tInlineCodemodeSandbox,\n\ttype InlineCodemodeSandboxOptions,\n} from \"./runtime/inline.ts\";\nexport {\n\tMAX_OUTPUT_CHARS,\n\tMAX_OUTPUT_ITEMS,\n\tMAX_STORE_TOTAL_CHARS,\n\tMAX_STORE_VALUE_CHARS,\n} from \"./runtime/prelude-source.ts\";\nexport {\n\ttype CodemodeRemote,\n\ttype CodemodeRemoteExchange,\n\ttype CodemodeRemoteMessage,\n\ttype CodemodeRemoteReply,\n\ttype CodemodeRemoteRequest,\n\ttype CodemodeServeOptions,\n\tRemoteCodemodeSandbox,\n\ttype RemoteCodemodeSandboxOptions,\n\tserveCodemodeRemote,\n} from \"./runtime/remote.ts\";\nexport {\n\tCODEMODE_OPTIONS_PREFIX,\n\tCODEMODE_SOURCE_GRAMMAR,\n\tCodemodeSourceError,\n\ttype CodemodeSourceOptions,\n\ttype ParsedCodemodeSource,\n\tparseCodemodeSource,\n} from \"./source.ts\";\nexport type {\n\tCodemodeCall,\n\tCodemodeCallStatus,\n\tCodemodeDeclaredGlobal,\n\tCodemodeDeclaredTool,\n\tCodemodeDuring,\n\tCodemodeError,\n\tCodemodeErrorKind,\n\tCodemodeExecuteOptions,\n\tCodemodeHostCall,\n\tCodemodeJsonSchema,\n\tCodemodeOutcome,\n\tCodemodeOutputItem,\n\tCodemodeResult,\n\tCodemodeRun,\n\tCodemodeRunOptions,\n\tCodemodeSandboxBaseOptions,\n\tCodemodeSandboxOptions,\n\tCodemodeStoreWrites,\n\tCodemodeTool,\n\tCodemodeToolContext,\n} from \"./types.ts\";\nexport { type CodemodeWasmModule, loadQuickJSWasm } from \"./wasm.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,8BAA8B,EAE9B,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,wBAAwB,EACxB,qBAAqB,GAErB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAON,qBAAqB,EAErB,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EAGnB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAuBrB,OAAO,EAA2B,eAAe,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export {\n\tDEFAULT_INPUT_SCHEMA_MAX_CHARS,\n\ttype RenderDeclarationsOptions,\n\trenderDeclarations,\n\trenderToolOutputType,\n\trenderToolSample,\n\trenderToolSignature,\n\tresolveSchemaRef,\n\tschemaToType,\n} from \"./declarations.ts\";\nexport { toCodemodeIdentifier } from \"./identifier.ts\";\nexport { CodemodeSandboxBase } from \"./runtime/execution.ts\";\nexport { CodemodeSandbox } from \"./runtime/host.ts\";\nexport {\n\tDEFAULT_INTERRUPT_BUDGET,\n\tInlineCodemodeSandbox,\n\ttype InlineCodemodeSandboxOptions,\n} from \"./runtime/inline.ts\";\nexport {\n\tMAX_OUTPUT_CHARS,\n\tMAX_OUTPUT_ITEMS,\n\tMAX_STORE_TOTAL_CHARS,\n\tMAX_STORE_VALUE_CHARS,\n} from \"./runtime/prelude-source.ts\";\nexport {\n\ttype CodemodeRemote,\n\ttype CodemodeRemoteExchange,\n\ttype CodemodeRemoteMessage,\n\ttype CodemodeRemoteReply,\n\ttype CodemodeRemoteRequest,\n\ttype CodemodeServeOptions,\n\tRemoteCodemodeSandbox,\n\ttype RemoteCodemodeSandboxOptions,\n\tserveCodemodeRemote,\n} from \"./runtime/remote.ts\";\nexport {\n\tCODEMODE_OPTIONS_PREFIX,\n\tCODEMODE_SOURCE_GRAMMAR,\n\tCodemodeSourceError,\n\ttype CodemodeSourceOptions,\n\ttype ParsedCodemodeSource,\n\tparseCodemodeSource,\n} from \"./source.ts\";\nexport type {\n\tCodemodeCall,\n\tCodemodeCallStatus,\n\tCodemodeDeclaredGlobal,\n\tCodemodeDeclaredTool,\n\tCodemodeDuring,\n\tCodemodeError,\n\tCodemodeErrorKind,\n\tCodemodeExecuteOptions,\n\tCodemodeHostCall,\n\tCodemodeJsonSchema,\n\tCodemodeOutcome,\n\tCodemodeOutputItem,\n\tCodemodeResult,\n\tCodemodeRun,\n\tCodemodeRunOptions,\n\tCodemodeSandboxBaseOptions,\n\tCodemodeSandboxOptions,\n\tCodemodeStoreWrites,\n\tCodemodeTool,\n\tCodemodeToolContext,\n} from \"./types.ts\";\nexport { type CodemodeWasmModule, loadQuickJSWasm } from \"./wasm.ts\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fractaal/pi-codemode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Sandboxed JavaScript execution where the only capability is calling injected tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"README.md"
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
|
-
"clean": "
|
|
45
|
+
"clean": "node ../../scripts/package-files.mjs clean dist",
|
|
46
46
|
"build": "tsc -p tsconfig.build.json",
|
|
47
47
|
"test": "vitest --run",
|
|
48
48
|
"prepublishOnly": "npm run clean && npm run build"
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"quickjs-wasi": "3.6.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"shx": "0.3.4",
|
|
74
73
|
"vitest": "4.1.12"
|
|
75
74
|
},
|
|
76
75
|
"homepage": "https://github.com/fractaal/pi",
|