@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/a2a/index.js CHANGED
@@ -7860,22 +7860,23 @@ async function executeTool(inputs, resolved, call) {
7860
7860
  return { stdout: "", stderr: `Unknown tool ${call.name}`, exitCode: 127 };
7861
7861
  }
7862
7862
  if (resolved.origin === "shell") return runShellTool(inputs, call);
7863
- if (resolved.origin === "memory") return runMemoryTool(resolved, call);
7864
- if (resolved.origin === "custom") return runCustomTool(resolved, call, inputs.signal);
7863
+ if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
7864
+ if (resolved.origin === "custom")
7865
+ return runCustomTool(resolved, call, inputs.signal, inputs.context);
7865
7866
  return runMcpTool(inputs, resolved, call);
7866
7867
  }
7867
- async function runMemoryTool(resolved, call) {
7868
- return runHandlerTool("memory", resolved.memoryHandler, call);
7868
+ async function runMemoryTool(resolved, call, context) {
7869
+ return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
7869
7870
  }
7870
- async function runCustomTool(resolved, call, signal) {
7871
- return runHandlerTool("custom", resolved.customHandler, call, signal);
7871
+ async function runCustomTool(resolved, call, signal, context) {
7872
+ return runHandlerTool("custom", resolved.customHandler, call, signal, context);
7872
7873
  }
7873
- async function runHandlerTool(kind, handler, call, signal) {
7874
+ async function runHandlerTool(kind, handler, call, signal, context) {
7874
7875
  if (handler === void 0) {
7875
7876
  return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
7876
7877
  }
7877
7878
  try {
7878
- const stdout = await handler(call.input, { signal });
7879
+ const stdout = await handler(call.input, { signal, context });
7879
7880
  return { stdout, stderr: "", exitCode: 0 };
7880
7881
  } catch (cause) {
7881
7882
  const message = cause instanceof Error ? cause.message : String(cause);
@@ -12380,6 +12381,9 @@ function buildLoopInputs(options, runId, userText) {
12380
12381
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
12381
12382
  // can attach it to the LLM `fetch({ signal })` call.
12382
12383
  ...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
12384
+ // M7 — forward SendOptions.context to the loop so every tool handler receives
12385
+ // it on `ctx.context` (shared run config set once, e.g. projectRoot).
12386
+ ...options.sendOptions.context !== void 0 ? { context: options.sendOptions.context } : {},
12383
12387
  // #58 / #57 — forward the per-tool timeout + tool-result guard so a consumer
12384
12388
  // can enable them via SendOptions (not only internal AgentLoopInputs).
12385
12389
  ...options.sendOptions.perToolTimeoutMs !== void 0 ? { perToolTimeoutMs: options.sendOptions.perToolTimeoutMs } : {},
@@ -17150,6 +17154,19 @@ __export(generate_object_exports, {
17150
17154
  GenerateObjectError: () => GenerateObjectError,
17151
17155
  generateObjectImpl: () => generateObjectImpl
17152
17156
  });
17157
+ function salvagePartial(schema, raw) {
17158
+ if (typeof raw !== "object" || raw === null) return raw;
17159
+ const shape = schema.shape;
17160
+ if (shape === void 0 || typeof shape !== "object") return raw;
17161
+ const rawObj = raw;
17162
+ const out = {};
17163
+ for (const [key, fieldSchema] of Object.entries(shape)) {
17164
+ if (typeof fieldSchema?.safeParse !== "function") continue;
17165
+ const parsed = fieldSchema.safeParse(rawObj[key]);
17166
+ if (parsed.success) out[key] = parsed.data;
17167
+ }
17168
+ return out;
17169
+ }
17153
17170
  async function generateObjectImpl(options, deps) {
17154
17171
  const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
17155
17172
  options.schema,
@@ -17216,6 +17233,22 @@ async function generateObjectImpl(options, deps) {
17216
17233
  }
17217
17234
  lastParseError = parsed.error;
17218
17235
  }
17236
+ if (options.errorStrategy === "return-raw") {
17237
+ return {
17238
+ object: capturedRaw,
17239
+ raw: capturedRaw,
17240
+ usage: lastUsage,
17241
+ finishReason: "tool_use"
17242
+ };
17243
+ }
17244
+ if (options.errorStrategy === "return-partial") {
17245
+ return {
17246
+ object: salvagePartial(options.schema, capturedRaw),
17247
+ raw: capturedRaw,
17248
+ usage: lastUsage,
17249
+ finishReason: "tool_use"
17250
+ };
17251
+ }
17219
17252
  throw new GenerateObjectError(
17220
17253
  "parse_failed",
17221
17254
  "Schema parse failed after all retries.",