@theokit/sdk 2.18.1 → 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.
@@ -22,6 +22,7 @@ export interface DefineToolSpec<T extends ZodType> {
22
22
  */
23
23
  handler: (input: ZodNamespace.infer<T>, ctx?: {
24
24
  signal?: AbortSignal;
25
+ context?: unknown;
25
26
  }) => string | Promise<string>;
26
27
  /**
27
28
  * Sanitize the raw model-emitted args BEFORE schema validation (`@theokit/sdk/sanitize`).
@@ -1,4 +1,4 @@
1
- import { p as RunOperation } from './run-pE-34AAo.js';
1
+ import { p as RunOperation } from './run-BgfBWX-z.js';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
@@ -1,4 +1,4 @@
1
- import { p as RunOperation } from './run-pE-34AAo.cjs';
1
+ import { p as RunOperation } from './run-BgfBWX-z.cjs';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
package/dist/errors.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-1tVcX3Fq.cjs';
2
- import './run-pE-34AAo.cjs';
1
+ export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-CE-lMBi2.cjs';
2
+ import './run-BgfBWX-z.cjs';
package/dist/eval.cjs CHANGED
@@ -2255,6 +2255,19 @@ __export(generate_object_exports, {
2255
2255
  GenerateObjectError: () => GenerateObjectError,
2256
2256
  generateObjectImpl: () => generateObjectImpl
2257
2257
  });
2258
+ function salvagePartial(schema, raw) {
2259
+ if (typeof raw !== "object" || raw === null) return raw;
2260
+ const shape = schema.shape;
2261
+ if (shape === void 0 || typeof shape !== "object") return raw;
2262
+ const rawObj = raw;
2263
+ const out = {};
2264
+ for (const [key, fieldSchema] of Object.entries(shape)) {
2265
+ if (typeof fieldSchema?.safeParse !== "function") continue;
2266
+ const parsed = fieldSchema.safeParse(rawObj[key]);
2267
+ if (parsed.success) out[key] = parsed.data;
2268
+ }
2269
+ return out;
2270
+ }
2258
2271
  async function generateObjectImpl(options, deps) {
2259
2272
  const { jsonSchema, maxRetries, initialUsage } = setupStructuredOutput(
2260
2273
  options.schema,
@@ -2321,6 +2334,22 @@ async function generateObjectImpl(options, deps) {
2321
2334
  }
2322
2335
  lastParseError = parsed.error;
2323
2336
  }
2337
+ if (options.errorStrategy === "return-raw") {
2338
+ return {
2339
+ object: capturedRaw,
2340
+ raw: capturedRaw,
2341
+ usage: lastUsage,
2342
+ finishReason: "tool_use"
2343
+ };
2344
+ }
2345
+ if (options.errorStrategy === "return-partial") {
2346
+ return {
2347
+ object: salvagePartial(options.schema, capturedRaw),
2348
+ raw: capturedRaw,
2349
+ usage: lastUsage,
2350
+ finishReason: "tool_use"
2351
+ };
2352
+ }
2324
2353
  throw new GenerateObjectError(
2325
2354
  "parse_failed",
2326
2355
  "Schema parse failed after all retries.",
@@ -9215,22 +9244,23 @@ async function executeTool(inputs, resolved, call) {
9215
9244
  return { stdout: "", stderr: `Unknown tool ${call.name}`, exitCode: 127 };
9216
9245
  }
9217
9246
  if (resolved.origin === "shell") return runShellTool(inputs, call);
9218
- if (resolved.origin === "memory") return runMemoryTool(resolved, call);
9219
- if (resolved.origin === "custom") return runCustomTool(resolved, call, inputs.signal);
9247
+ if (resolved.origin === "memory") return runMemoryTool(resolved, call, inputs.context);
9248
+ if (resolved.origin === "custom")
9249
+ return runCustomTool(resolved, call, inputs.signal, inputs.context);
9220
9250
  return runMcpTool(inputs, resolved, call);
9221
9251
  }
9222
- async function runMemoryTool(resolved, call) {
9223
- return runHandlerTool("memory", resolved.memoryHandler, call);
9252
+ async function runMemoryTool(resolved, call, context) {
9253
+ return runHandlerTool("memory", resolved.memoryHandler, call, void 0, context);
9224
9254
  }
9225
- async function runCustomTool(resolved, call, signal) {
9226
- return runHandlerTool("custom", resolved.customHandler, call, signal);
9255
+ async function runCustomTool(resolved, call, signal, context) {
9256
+ return runHandlerTool("custom", resolved.customHandler, call, signal, context);
9227
9257
  }
9228
- async function runHandlerTool(kind, handler, call, signal) {
9258
+ async function runHandlerTool(kind, handler, call, signal, context) {
9229
9259
  if (handler === void 0) {
9230
9260
  return { stdout: "", stderr: `${kind} tool ${call.name} has no handler`, exitCode: 127 };
9231
9261
  }
9232
9262
  try {
9233
- const stdout = await handler(call.input, { signal });
9263
+ const stdout = await handler(call.input, { signal, context });
9234
9264
  return { stdout, stderr: "", exitCode: 0 };
9235
9265
  } catch (cause) {
9236
9266
  const message = cause instanceof Error ? cause.message : String(cause);
@@ -13113,6 +13143,9 @@ function buildLoopInputs(options, runId, userText) {
13113
13143
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
13114
13144
  // can attach it to the LLM `fetch({ signal })` call.
13115
13145
  ...options.sendOptions.signal !== void 0 ? { signal: options.sendOptions.signal } : {},
13146
+ // M7 — forward SendOptions.context to the loop so every tool handler receives
13147
+ // it on `ctx.context` (shared run config set once, e.g. projectRoot).
13148
+ ...options.sendOptions.context !== void 0 ? { context: options.sendOptions.context } : {},
13116
13149
  // #58 / #57 — forward the per-tool timeout + tool-result guard so a consumer
13117
13150
  // can enable them via SendOptions (not only internal AgentLoopInputs).
13118
13151
  ...options.sendOptions.perToolTimeoutMs !== void 0 ? { perToolTimeoutMs: options.sendOptions.perToolTimeoutMs } : {},