@theokit/sdk 2.18.0 → 2.19.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/dist/eval.js CHANGED
@@ -2252,6 +2252,19 @@ __export(generate_object_exports, {
2252
2252
  GenerateObjectError: () => GenerateObjectError,
2253
2253
  generateObjectImpl: () => generateObjectImpl
2254
2254
  });
2255
+ function salvagePartial(schema, raw) {
2256
+ if (typeof raw !== "object" || raw === null) return raw;
2257
+ const shape = schema.shape;
2258
+ if (shape === void 0 || typeof shape !== "object") return raw;
2259
+ const rawObj = raw;
2260
+ const out = {};
2261
+ for (const [key, fieldSchema] of Object.entries(shape)) {
2262
+ if (typeof fieldSchema?.safeParse !== "function") continue;
2263
+ const parsed = fieldSchema.safeParse(rawObj[key]);
2264
+ if (parsed.success) out[key] = parsed.data;
2265
+ }
2266
+ return out;
2267
+ }
2255
2268
  async function generateObjectImpl(options, deps) {
2256
2269
  const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
2257
2270
  options.schema,
@@ -2318,6 +2331,22 @@ async function generateObjectImpl(options, deps) {
2318
2331
  }
2319
2332
  lastParseError = parsed.error;
2320
2333
  }
2334
+ if (options.errorStrategy === "return-raw") {
2335
+ return {
2336
+ object: capturedRaw,
2337
+ raw: capturedRaw,
2338
+ usage: lastUsage,
2339
+ finishReason: "tool_use"
2340
+ };
2341
+ }
2342
+ if (options.errorStrategy === "return-partial") {
2343
+ return {
2344
+ object: salvagePartial(options.schema, capturedRaw),
2345
+ raw: capturedRaw,
2346
+ usage: lastUsage,
2347
+ finishReason: "tool_use"
2348
+ };
2349
+ }
2321
2350
  throw new GenerateObjectError(
2322
2351
  "parse_failed",
2323
2352
  "Schema parse failed after all retries.",
@@ -9212,22 +9241,23 @@ async function executeTool(inputs, resolved, call) {
9212
9241
  return { stdout: "", stderr: `Unknown tool ${call.name}`, exitCode: 127 };
9213
9242
  }
9214
9243
  if (resolved.origin === "shell") return runShellTool(inputs, call);
9215
- if (resolved.origin === "memory") return runMemoryTool(resolved, call);
9216
- if (resolved.origin === "custom") return runCustomTool(resolved, call, inputs.signal);
9244
+ if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
9245
+ if (resolved.origin === "custom")
9246
+ return runCustomTool(resolved, call, inputs.signal, inputs.context);
9217
9247
  return runMcpTool(inputs, resolved, call);
9218
9248
  }
9219
- async function runMemoryTool(resolved, call) {
9220
- return runHandlerTool("memory", resolved.memoryHandler, call);
9249
+ async function runMemoryTool(resolved, call, context) {
9250
+ return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
9221
9251
  }
9222
- async function runCustomTool(resolved, call, signal) {
9223
- return runHandlerTool("custom", resolved.customHandler, call, signal);
9252
+ async function runCustomTool(resolved, call, signal, context) {
9253
+ return runHandlerTool("custom", resolved.customHandler, call, signal, context);
9224
9254
  }
9225
- async function runHandlerTool(kind, handler, call, signal) {
9255
+ async function runHandlerTool(kind, handler, call, signal, context) {
9226
9256
  if (handler === void 0) {
9227
9257
  return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
9228
9258
  }
9229
9259
  try {
9230
- const stdout = await handler(call.input, { signal });
9260
+ const stdout = await handler(call.input, { signal, context });
9231
9261
  return { stdout, stderr: "", exitCode: 0 };
9232
9262
  } catch (cause) {
9233
9263
  const message = cause instanceof Error ? cause.message : String(cause);
@@ -13110,6 +13140,9 @@ function buildLoopInputs(options, runId, userText) {
13110
13140
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
13111
13141
  // can attach it to the LLM `fetch({ signal })` call.
13112
13142
  ...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
13143
+ // M7 — forward SendOptions.context to the loop so every tool handler receives
13144
+ // it on `ctx.context` (shared run config set once, e.g. projectRoot).
13145
+ ...options.sendOptions.context !== void 0 ? { context: options.sendOptions.context } : {},
13113
13146
  // #58 / #57 — forward the per-tool timeout + tool-result guard so a consumer
13114
13147
  // can enable them via SendOptions (not only internal AgentLoopInputs).
13115
13148
  ...options.sendOptions.perToolTimeoutMs !== void 0 ? { perToolTimeoutMs: options.sendOptions.perToolTimeoutMs } : {},