@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.
@@ -1,4 +1,4 @@
1
- import { C as CustomTool, M as ModelSelection, G as SDKUserMessage, J as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, S as SDKMessage, U as StreamToCompletionResult, a as McpServerConfig } from './run-pE-34AAo.js';
1
+ import { C as CustomTool, M as ModelSelection, G as SDKUserMessage, J as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, S as SDKMessage, U as StreamToCompletionResult, a as McpServerConfig } from './run-BgfBWX-z.js';
2
2
 
3
3
  /**
4
4
  * Fork primitive public type contracts (T1.2, ADRs D110-D114).
@@ -1,4 +1,4 @@
1
- import { C as CustomTool, M as ModelSelection, G as SDKUserMessage, J as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, S as SDKMessage, U as StreamToCompletionResult, a as McpServerConfig } from './run-pE-34AAo.cjs';
1
+ import { C as CustomTool, M as ModelSelection, G as SDKUserMessage, J as SendOptions, b as Run, r as RunToCompletionOptions, s as RunToCompletionResult, S as SDKMessage, U as StreamToCompletionResult, a as McpServerConfig } from './run-BgfBWX-z.cjs';
2
2
 
3
3
  /**
4
4
  * Fork primitive public type contracts (T1.2, ADRs D110-D114).
package/dist/cron.cjs CHANGED
@@ -2256,6 +2256,19 @@ __export(generate_object_exports, {
2256
2256
  GenerateObjectError: () => GenerateObjectError,
2257
2257
  generateObjectImpl: () => generateObjectImpl
2258
2258
  });
2259
+ function salvagePartial(schema, raw) {
2260
+ if (typeof raw !== "object" || raw === null) return raw;
2261
+ const shape = schema.shape;
2262
+ if (shape === void 0 || typeof shape !== "object") return raw;
2263
+ const rawObj = raw;
2264
+ const out = {};
2265
+ for (const [key, fieldSchema] of Object.entries(shape)) {
2266
+ if (typeof fieldSchema?.safeParse !== "function") continue;
2267
+ const parsed = fieldSchema.safeParse(rawObj[key]);
2268
+ if (parsed.success) out[key] = parsed.data;
2269
+ }
2270
+ return out;
2271
+ }
2259
2272
  async function generateObjectImpl(options, deps) {
2260
2273
  const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
2261
2274
  options.schema,
@@ -2322,6 +2335,22 @@ async function generateObjectImpl(options, deps) {
2322
2335
  }
2323
2336
  lastParseError = parsed.error;
2324
2337
  }
2338
+ if (options.errorStrategy === "return-raw") {
2339
+ return {
2340
+ object: capturedRaw,
2341
+ raw: capturedRaw,
2342
+ usage: lastUsage,
2343
+ finishReason: "tool_use"
2344
+ };
2345
+ }
2346
+ if (options.errorStrategy === "return-partial") {
2347
+ return {
2348
+ object: salvagePartial(options.schema, capturedRaw),
2349
+ raw: capturedRaw,
2350
+ usage: lastUsage,
2351
+ finishReason: "tool_use"
2352
+ };
2353
+ }
2325
2354
  throw new GenerateObjectError(
2326
2355
  "parse_failed",
2327
2356
  "Schema parse failed after all retries.",
@@ -9220,22 +9249,23 @@ async function executeTool(inputs, resolved, call) {
9220
9249
  return { stdout: "", stderr: `Unknown tool ${call.name}`, exitCode: 127 };
9221
9250
  }
9222
9251
  if (resolved.origin === "shell") return runShellTool(inputs, call);
9223
- if (resolved.origin === "memory") return runMemoryTool(resolved, call);
9224
- if (resolved.origin === "custom") return runCustomTool(resolved, call, inputs.signal);
9252
+ if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
9253
+ if (resolved.origin === "custom")
9254
+ return runCustomTool(resolved, call, inputs.signal, inputs.context);
9225
9255
  return runMcpTool(inputs, resolved, call);
9226
9256
  }
9227
- async function runMemoryTool(resolved, call) {
9228
- return runHandlerTool("memory", resolved.memoryHandler, call);
9257
+ async function runMemoryTool(resolved, call, context) {
9258
+ return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
9229
9259
  }
9230
- async function runCustomTool(resolved, call, signal) {
9231
- return runHandlerTool("custom", resolved.customHandler, call, signal);
9260
+ async function runCustomTool(resolved, call, signal, context) {
9261
+ return runHandlerTool("custom", resolved.customHandler, call, signal, context);
9232
9262
  }
9233
- async function runHandlerTool(kind, handler, call, signal) {
9263
+ async function runHandlerTool(kind, handler, call, signal, context) {
9234
9264
  if (handler === void 0) {
9235
9265
  return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
9236
9266
  }
9237
9267
  try {
9238
- const stdout = await handler(call.input, { signal });
9268
+ const stdout = await handler(call.input, { signal, context });
9239
9269
  return { stdout, stderr: "", exitCode: 0 };
9240
9270
  } catch (cause) {
9241
9271
  const message = cause instanceof Error ? cause.message : String(cause);
@@ -13118,6 +13148,9 @@ function buildLoopInputs(options, runId, userText) {
13118
13148
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
13119
13149
  // can attach it to the LLM `fetch({ signal })` call.
13120
13150
  ...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
13151
+ // M7 — forward SendOptions.context to the loop so every tool handler receives
13152
+ // it on `ctx.context` (shared run config set once, e.g. projectRoot).
13153
+ ...options.sendOptions.context !== void 0 ? { context: options.sendOptions.context } : {},
13121
13154
  // #58 / #57 — forward the per-tool timeout + tool-result guard so a consumer
13122
13155
  // can enable them via SendOptions (not only internal AgentLoopInputs).
13123
13156
  ...options.sendOptions.perToolTimeoutMs !== void 0 ? { perToolTimeoutMs: options.sendOptions.perToolTimeoutMs } : {},