theokit 0.24.0 → 0.26.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.
Files changed (30) hide show
  1. package/dist/{agent-7474NDZD.js → agent-GXJNFW6N.js} +2 -2
  2. package/dist/{build-CVWAK4UE.js → build-WD2PT5TA.js} +2 -2
  3. package/dist/{chunk-FARW5PH6.js → chunk-2JNG3P4Y.js} +267 -21
  4. package/dist/chunk-2JNG3P4Y.js.map +1 -0
  5. package/dist/{chunk-IEA4O6ZN.js → chunk-GG6H76GC.js} +5 -3
  6. package/dist/chunk-GG6H76GC.js.map +1 -0
  7. package/dist/{chunk-ZGKGXXZG.js → chunk-LVGDYTU2.js} +2 -2
  8. package/dist/{chunk-VK553I55.js → chunk-S7L6H3KP.js} +264 -20
  9. package/dist/chunk-S7L6H3KP.js.map +1 -0
  10. package/dist/cli/index.js +5 -5
  11. package/dist/{dev-FSTYMPPF.js → dev-63UNEUF6.js} +3 -3
  12. package/dist/index.js +1 -1
  13. package/dist/{mcp-TOYHKCB6.js → mcp-MIZFVNCL.js} +2 -2
  14. package/dist/server/index.d.ts +10 -5
  15. package/dist/server/index.js +31 -7
  16. package/dist/server/index.js.map +1 -1
  17. package/dist/{start-LEDGWJF2.js → start-IFTLTEPZ.js} +5 -3
  18. package/dist/{start-LEDGWJF2.js.map → start-IFTLTEPZ.js.map} +1 -1
  19. package/dist/vite-plugin/index.js +1 -1
  20. package/dist/{vite-plugin-HSOWPMK4.js → vite-plugin-ST4JZQRJ.js} +3 -3
  21. package/package.json +1 -1
  22. package/dist/chunk-FARW5PH6.js.map +0 -1
  23. package/dist/chunk-IEA4O6ZN.js.map +0 -1
  24. package/dist/chunk-VK553I55.js.map +0 -1
  25. /package/dist/{agent-7474NDZD.js.map → agent-GXJNFW6N.js.map} +0 -0
  26. /package/dist/{build-CVWAK4UE.js.map → build-WD2PT5TA.js.map} +0 -0
  27. /package/dist/{chunk-ZGKGXXZG.js.map → chunk-LVGDYTU2.js.map} +0 -0
  28. /package/dist/{dev-FSTYMPPF.js.map → dev-63UNEUF6.js.map} +0 -0
  29. /package/dist/{mcp-TOYHKCB6.js.map → mcp-MIZFVNCL.js.map} +0 -0
  30. /package/dist/{vite-plugin-HSOWPMK4.js.map → vite-plugin-ST4JZQRJ.js.map} +0 -0
@@ -823,11 +823,16 @@ declare class CodeModePermissionDeniedError extends Error {
823
823
  constructor(tool: string, reason?: string);
824
824
  }
825
825
  /**
826
- * Build a code-mode `CustomTool`. Fails fast if `onPermissionRequest` or `sandbox` is missing
827
- * (security by default). The returned tool takes `{ code }`, assembles the permission-gated restricted
828
- * API from `tools`, runs the code in the injected sandbox, and returns the code's result.
829
- */
830
- declare function createCodeMode(config: CodeModeConfig): CustomTool;
826
+ * Build a code-mode tool + its generated model instructions (M40 / ADR-0049). Fails fast if
827
+ * `onPermissionRequest` or `sandbox` is missing (security by default). `tool` takes `{ code }`,
828
+ * assembles the permission-gated restricted API from `tools`, runs the code in the injected sandbox,
829
+ * and returns the code's result. `instructions` (add it to the agent's system prompt) teaches the
830
+ * model the sandboxed-code contract + the available `api.<name>(input)` calls.
831
+ */
832
+ declare function createCodeMode(config: CodeModeConfig): {
833
+ tool: CustomTool;
834
+ instructions: string;
835
+ };
831
836
 
832
837
  /**
833
838
  * M27 (ADR-0041) — channel webhook routes: `POST /api/agents/<name>/channels/<platform>/webhook`.
@@ -1223,6 +1223,23 @@ var CodeModePermissionDeniedError = class extends Error {
1223
1223
  this.name = "CodeModePermissionDeniedError";
1224
1224
  }
1225
1225
  };
1226
+ function describeToolInput(inputSchema) {
1227
+ const props = inputSchema.properties ?? {};
1228
+ const required = new Set(inputSchema.required ?? []);
1229
+ const entries = Object.entries(props).map(([key, spec]) => {
1230
+ const type = typeof spec.type === "string" ? spec.type : "unknown";
1231
+ return `${key}${required.has(key) ? "" : "?"}: ${type}`;
1232
+ });
1233
+ return entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
1234
+ }
1235
+ function generateCodeModeInstructions(tools, toolName) {
1236
+ const calls = tools.map((t) => `- \`await api.${t.name}(${describeToolInput(t.inputSchema)})\` \u2014 ${t.description}`).join("\n");
1237
+ return [
1238
+ `The \`${toolName}\` tool runs your code in a sandbox. Your code may call ONLY these functions (each bridges to a real, validated tool on the host):`,
1239
+ calls,
1240
+ "Write an async function body that composes these calls and return exactly ONE structured result. Prefer `Promise.all` for independent calls; do arithmetic and aggregation in code, not in prose."
1241
+ ].join("\n\n");
1242
+ }
1226
1243
  function createCodeMode(config) {
1227
1244
  if (typeof config.onPermissionRequest !== "function") {
1228
1245
  throw new Error(
@@ -1235,16 +1252,22 @@ function createCodeMode(config) {
1235
1252
  "createCodeMode requires an injected `sandbox` with a run() method (a vetted isolation boundary \u2014 never node:vm)."
1236
1253
  );
1237
1254
  }
1255
+ if (config.tools.length === 0) {
1256
+ throw new Error(
1257
+ "createCodeMode requires a non-empty tools[] \u2014 the restricted API would be empty."
1258
+ );
1259
+ }
1238
1260
  const api = {};
1239
- for (const tool2 of config.tools) {
1240
- api[tool2.name] = async (args) => {
1241
- const decision = await config.onPermissionRequest({ tool: tool2.name, args });
1242
- if (!decision.granted) throw new CodeModePermissionDeniedError(tool2.name, decision.reason);
1243
- return tool2.handler(args);
1261
+ for (const tool3 of config.tools) {
1262
+ api[tool3.name] = async (args) => {
1263
+ const decision = await config.onPermissionRequest({ tool: tool3.name, args });
1264
+ if (!decision.granted) throw new CodeModePermissionDeniedError(tool3.name, decision.reason);
1265
+ return tool3.handler(args);
1244
1266
  };
1245
1267
  }
1246
- return {
1247
- name: config.name ?? "run_code",
1268
+ const name = config.name ?? "run_code";
1269
+ const tool2 = {
1270
+ name,
1248
1271
  description: config.description ?? "Run code that composes the available tools. Only the declared tools are callable.",
1249
1272
  inputSchema: {
1250
1273
  type: "object",
@@ -1257,6 +1280,7 @@ function createCodeMode(config) {
1257
1280
  return typeof result === "string" ? result : JSON.stringify(result);
1258
1281
  }
1259
1282
  };
1283
+ return { tool: tool2, instructions: generateCodeModeInstructions(config.tools, name) };
1260
1284
  }
1261
1285
 
1262
1286
  // src/server/agent/channel-webhook.ts