@theokit/sdk 5.11.0 → 5.11.1

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 (52) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/{agent-GWKRARAL.js → agent-DFV52V6E.js} +7 -7
  3. package/dist/{agent-GWKRARAL.js.map → agent-DFV52V6E.js.map} +1 -1
  4. package/dist/{agent-5DOR5T3E.cjs → agent-OKP4LHG2.cjs} +8 -8
  5. package/dist/{agent-5DOR5T3E.cjs.map → agent-OKP4LHG2.cjs.map} +1 -1
  6. package/dist/{chunk-5OHB5HJF.cjs → chunk-35KBC4BX.cjs} +133 -93
  7. package/dist/chunk-35KBC4BX.cjs.map +1 -0
  8. package/dist/{chunk-N7ZIPW2N.cjs → chunk-3JANYJYS.cjs} +3 -3
  9. package/dist/{chunk-N7ZIPW2N.cjs.map → chunk-3JANYJYS.cjs.map} +1 -1
  10. package/dist/{chunk-Z5BAFHPU.js → chunk-6G4IRQUD.js} +3 -3
  11. package/dist/{chunk-Z5BAFHPU.js.map → chunk-6G4IRQUD.js.map} +1 -1
  12. package/dist/{chunk-74OA5DIM.js → chunk-BBJ77S62.js} +3 -3
  13. package/dist/{chunk-74OA5DIM.js.map → chunk-BBJ77S62.js.map} +1 -1
  14. package/dist/{chunk-5H2GJXGC.cjs → chunk-EQ5NCH2Y.cjs} +4 -4
  15. package/dist/{chunk-5H2GJXGC.cjs.map → chunk-EQ5NCH2Y.cjs.map} +1 -1
  16. package/dist/{chunk-TE6XVTOA.js → chunk-JLIRFWUG.js} +47 -17
  17. package/dist/chunk-JLIRFWUG.js.map +1 -0
  18. package/dist/{chunk-YEHQ3SIC.cjs → chunk-JV7JA7BM.cjs} +5 -5
  19. package/dist/{chunk-YEHQ3SIC.cjs.map → chunk-JV7JA7BM.cjs.map} +1 -1
  20. package/dist/{chunk-4PHSVR2R.js → chunk-MHIBYKWA.js} +83 -43
  21. package/dist/chunk-MHIBYKWA.js.map +1 -0
  22. package/dist/{chunk-WPO3VCY4.cjs → chunk-N7KS3TIR.cjs} +47 -17
  23. package/dist/chunk-N7KS3TIR.cjs.map +1 -0
  24. package/dist/{chunk-BZKF7TXX.cjs → chunk-P5N3Q2NH.cjs} +22 -22
  25. package/dist/{chunk-BZKF7TXX.cjs.map → chunk-P5N3Q2NH.cjs.map} +1 -1
  26. package/dist/{chunk-7Y23B7XX.js → chunk-Q34EBNYG.js} +3 -3
  27. package/dist/{chunk-7Y23B7XX.js.map → chunk-Q34EBNYG.js.map} +1 -1
  28. package/dist/{chunk-HI3W37FY.js → chunk-U27XHOEF.js} +3 -3
  29. package/dist/{chunk-HI3W37FY.js.map → chunk-U27XHOEF.js.map} +1 -1
  30. package/dist/{compact-session-F2UDGZCN.js → compact-session-4HAUP3HK.js} +4 -4
  31. package/dist/{compact-session-F2UDGZCN.js.map → compact-session-4HAUP3HK.js.map} +1 -1
  32. package/dist/{compact-session-2AETONOS.cjs → compact-session-Y56D3S57.cjs} +13 -13
  33. package/dist/{compact-session-2AETONOS.cjs.map → compact-session-Y56D3S57.cjs.map} +1 -1
  34. package/dist/cron.cjs +7 -7
  35. package/dist/cron.js +6 -6
  36. package/dist/eval.cjs +6 -6
  37. package/dist/eval.js +5 -5
  38. package/dist/index.cjs +33 -33
  39. package/dist/index.js +9 -9
  40. package/dist/{inject-session-E5UDFVLI.js → inject-session-LJX5JGV5.js} +3 -3
  41. package/dist/{inject-session-E5UDFVLI.js.map → inject-session-LJX5JGV5.js.map} +1 -1
  42. package/dist/{inject-session-W4UKACYJ.cjs → inject-session-R73PRM7B.cjs} +4 -4
  43. package/dist/{inject-session-W4UKACYJ.cjs.map → inject-session-R73PRM7B.cjs.map} +1 -1
  44. package/dist/internal/error-mappers/openai-compatible.d.ts +3 -1
  45. package/dist/internal/memory/adapters/index.cjs +3 -3
  46. package/dist/internal/memory/adapters/index.js +2 -2
  47. package/docs/error-codes.md +6 -3
  48. package/package.json +1 -1
  49. package/dist/chunk-4PHSVR2R.js.map +0 -1
  50. package/dist/chunk-5OHB5HJF.cjs.map +0 -1
  51. package/dist/chunk-TE6XVTOA.js.map +0 -1
  52. package/dist/chunk-WPO3VCY4.cjs.map +0 -1
@@ -1,13 +1,13 @@
1
1
  import { submit, emitRunEvent } from './chunk-XKMVJ443.js';
2
- import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, discardSession, clearSession } from './chunk-7Y23B7XX.js';
2
+ import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, discardSession, clearSession } from './chunk-Q34EBNYG.js';
3
3
  import { IndexManager } from './chunk-DPY2M74T.js';
4
4
  import { currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-ZHWKT2NI.js';
5
5
  import { extractCodePlugins } from './chunk-2SFBB54R.js';
6
- import { createOpenAiCompatibleRuntime } from './chunk-HI3W37FY.js';
6
+ import { createOpenAiCompatibleRuntime } from './chunk-U27XHOEF.js';
7
7
  import { persistActiveMemoryTranscript } from './chunk-OR6XIWLB.js';
8
8
  import { resolveMaxFacts, writeSessionSummary, resolveMemoryRoot, MEMORY_KINDS, appendFact, readFacts, legacyMemoryJsonPath, memoryMdPath, appendFactToMarkdown } from './chunk-X3LOJJMO.js';
9
9
  import { FsSessionStore } from './chunk-IZDDSLL2.js';
10
- import { discoverProviderPlugins, validateApiKeyShape, getConfiguredBaseUrl, httpRequest, isFixtureApiKey, presentProviderCredentialEnvVars, buildDefaultSummarizer, shouldUseRealLocalRuntime, parseSseStream, CircuitBreaker, resolveRunProvider, mergeExplicitApiKey, resolveProviderChain, abortError, tryFirstEvent, relayStream, renderToolResultContentText } from './chunk-74OA5DIM.js';
10
+ import { discoverProviderPlugins, validateApiKeyShape, getConfiguredBaseUrl, httpRequest, isFixtureApiKey, presentProviderCredentialEnvVars, buildDefaultSummarizer, shouldUseRealLocalRuntime, parseSseStream, CircuitBreaker, resolveRunProvider, mergeExplicitApiKey, resolveProviderChain, abortError, tryFirstEvent, relayStream, renderToolResultContentText } from './chunk-BBJ77S62.js';
11
11
  import { resolveChildEnv } from './chunk-HKCKOAIO.js';
12
12
  import { DEFAULT_MAX_BYTES_PER_FILE, runDiscovery, truncateWithMarker } from './chunk-7QJYKVP6.js';
13
13
  import { warnFailureOnce, loadHookConfig, warnOnce } from './chunk-OPAKPEPG.js';
@@ -5970,6 +5970,7 @@ function registerLoopError(ctx, cause) {
5970
5970
  async function consumeStreamEvent(inputs, reasoning, event) {
5971
5971
  if (event.type === "text_delta") {
5972
5972
  const text = event.text ?? "";
5973
+ if (text.length > 0) await closeReasoningOnce(inputs, reasoning);
5973
5974
  await emitTextDeltaCallback(inputs, text);
5974
5975
  return text;
5975
5976
  }
@@ -5982,7 +5983,14 @@ async function consumeStreamEvent(inputs, reasoning, event) {
5982
5983
  return "";
5983
5984
  }
5984
5985
  async function runCollectorLoop(generator, inputs, ctx, partial) {
5985
- const reasoning = { text: "", startedAt: void 0, signature: void 0 };
5986
+ const reasoning = {
5987
+ text: "",
5988
+ startedAt: void 0,
5989
+ lastAt: void 0,
5990
+ signature: void 0,
5991
+ closed: false,
5992
+ durationMs: 0
5993
+ };
5986
5994
  let errored = false;
5987
5995
  let finishValue;
5988
5996
  let thinking;
@@ -6011,17 +6019,24 @@ async function consumeReasoningDelta(inputs, reasoning, delta) {
6011
6019
  await accumulateReasoning(inputs, reasoning, delta.text);
6012
6020
  }
6013
6021
  async function accumulateReasoning(inputs, reasoning, text) {
6014
- if (reasoning.startedAt === void 0) reasoning.startedAt = Date.now();
6022
+ const now = Date.now();
6023
+ if (reasoning.startedAt === void 0) reasoning.startedAt = now;
6024
+ if (!reasoning.closed) reasoning.lastAt = now;
6015
6025
  reasoning.text += text;
6016
6026
  await emitReasoningDeltaCallback(inputs, text);
6017
6027
  }
6028
+ async function closeReasoningOnce(inputs, reasoning) {
6029
+ if (reasoning.closed || reasoning.text.length === 0) return;
6030
+ reasoning.closed = true;
6031
+ reasoning.durationMs = (reasoning.lastAt ?? 0) - (reasoning.startedAt ?? 0);
6032
+ await emitThinkingCompletedCallback(inputs, reasoning.durationMs);
6033
+ }
6018
6034
  async function finalizeReasoning(inputs, ctx, reasoning) {
6019
6035
  if (reasoning.text.length === 0) return void 0;
6020
- const thinkingDurationMs = reasoning.startedAt === void 0 ? 0 : Date.now() - reasoning.startedAt;
6036
+ await closeReasoningOnce(inputs, reasoning);
6021
6037
  ctx.events.push(
6022
- buildThinkingEvent(inputs, reasoning.text, thinkingDurationMs, reasoning.signature)
6038
+ buildThinkingEvent(inputs, reasoning.text, reasoning.durationMs, reasoning.signature)
6023
6039
  );
6024
- await emitThinkingCompletedCallback(inputs, thinkingDurationMs);
6025
6040
  return {
6026
6041
  type: "thinking",
6027
6042
  text: reasoning.text,
@@ -6951,6 +6966,32 @@ async function inspectDoomLoop(inputs, ctx, toolCalls) {
6951
6966
  return "continue";
6952
6967
  }
6953
6968
 
6969
+ // src/internal/concurrency/abort-utils.ts
6970
+ function anySignal(signals) {
6971
+ const filtered = signals.filter((s) => s !== void 0);
6972
+ if (filtered.length === 0) {
6973
+ return new AbortController().signal;
6974
+ }
6975
+ if (filtered.length === 1) {
6976
+ return filtered[0];
6977
+ }
6978
+ if (typeof AbortSignal.any === "function") {
6979
+ return AbortSignal.any(filtered);
6980
+ }
6981
+ return ponyfillAny(filtered);
6982
+ }
6983
+ function ponyfillAny(signals) {
6984
+ const ctrl = new AbortController();
6985
+ for (const s of signals) {
6986
+ if (s.aborted) {
6987
+ ctrl.abort(s.reason);
6988
+ return ctrl.signal;
6989
+ }
6990
+ s.addEventListener("abort", () => ctrl.abort(s.reason), { once: true });
6991
+ }
6992
+ return ctrl.signal;
6993
+ }
6994
+
6954
6995
  // src/internal/llm/fallback-client.ts
6955
6996
  var FallbackLlmClient = class {
6956
6997
  constructor(clients) {
@@ -7705,6 +7746,13 @@ var RealLocalRun = class extends FixtureRunBase {
7705
7746
  ownsMcpClients;
7706
7747
  /** theokit#148 — what a delegated child inherits from this parent, scoped to the loop. */
7707
7748
  inheritedCredentials;
7749
+ /**
7750
+ * B-495 — the run's own abort, composed into the signal the loop hands to the LLM fetch and the
7751
+ * tool executors, so `cancel()` stops the request and not only the status. A TypeScript `private`
7752
+ * field, never a JS `#private` one: the run wrappers are Proxies that call `cancel()` with `this`
7753
+ * bound to the Proxy, where reading a `#private` field throws.
7754
+ */
7755
+ cancelController = new AbortController();
7708
7756
  constructor(options, buildInputs, ownsMcpClients, inheritedCredentials) {
7709
7757
  super(options);
7710
7758
  this.buildInputs = buildInputs;
@@ -7716,6 +7764,11 @@ var RealLocalRun = class extends FixtureRunBase {
7716
7764
  void this.driveLoop();
7717
7765
  }, 0);
7718
7766
  }
7767
+ cancel() {
7768
+ if (this.terminated) return Promise.resolve();
7769
+ this.cancelController.abort();
7770
+ return super.cancel();
7771
+ }
7719
7772
  notifyImmediately() {
7720
7773
  return true;
7721
7774
  }
@@ -7759,7 +7812,9 @@ var RealLocalRun = class extends FixtureRunBase {
7759
7812
  liveDelivered = /* @__PURE__ */ new Set();
7760
7813
  async executeAgentLoop(inputs) {
7761
7814
  let textStreamedSinceLastMessage = false;
7815
+ inputs.signal = anySignal([inputs.signal, this.cancelController.signal]);
7762
7816
  inputs.onLoopEvent = (event) => {
7817
+ if (this.terminated) return;
7763
7818
  this.liveDelivered.add(event);
7764
7819
  this.script.events.push(event);
7765
7820
  const carriesText = event.type === "assistant" && event.message.content.some((b) => b.type === "text");
@@ -7775,11 +7830,13 @@ var RealLocalRun = class extends FixtureRunBase {
7775
7830
  };
7776
7831
  const callerOnDelta = inputs.onDelta;
7777
7832
  inputs.onDelta = (delta) => {
7833
+ if (this.terminated) return;
7778
7834
  callerOnDelta?.(delta);
7779
7835
  if (delta.update.type === "text-delta") textStreamedSinceLastMessage = true;
7780
7836
  this.pushTimeline({ kind: "delta", update: delta.update });
7781
7837
  };
7782
7838
  try {
7839
+ if (this.terminated) return;
7783
7840
  const runLoop = () => inputs.activeTools !== void 0 ? withToolWhitelist(new Set(inputs.activeTools), () => runAgentLoop(inputs)) : runAgentLoop(inputs);
7784
7841
  const output = await withInheritedSubAgentCredentials(this.inheritedCredentials, runLoop);
7785
7842
  this.applyAgentLoopOutput(output);
@@ -7788,11 +7845,7 @@ var RealLocalRun = class extends FixtureRunBase {
7788
7845
  this.emitErrorEvent(cause, "Agent loop failed", "", "agent_loop_failed");
7789
7846
  this.transitionTo("error");
7790
7847
  } finally {
7791
- if (this.ownsMcpClients) {
7792
- for (const client of inputs.mcp.values()) {
7793
- await client.close().catch(() => void 0);
7794
- }
7795
- }
7848
+ if (this.ownsMcpClients) await closeOwnedMcpClients(inputs);
7796
7849
  }
7797
7850
  }
7798
7851
  /**
@@ -7804,6 +7857,7 @@ var RealLocalRun = class extends FixtureRunBase {
7804
7857
  * Finding-B fix (sdk-error-packaging v1.1): set-once errorDetail copy.
7805
7858
  */
7806
7859
  applyAgentLoopOutput(output) {
7860
+ if (this.terminated) return;
7807
7861
  this.deliverUndeliveredEvents(output.events);
7808
7862
  this.script.conversation.push(...output.conversation);
7809
7863
  if (output.result.length > 0) this.script.result = output.result;
@@ -7851,6 +7905,18 @@ var RealLocalRun = class extends FixtureRunBase {
7851
7905
  this.notifyNewEvents();
7852
7906
  }
7853
7907
  };
7908
+ async function closeOwnedMcpClients(inputs) {
7909
+ for (const [name, client] of inputs.mcp.entries()) {
7910
+ try {
7911
+ await client.close();
7912
+ } catch (cause) {
7913
+ const why = cause instanceof Error ? cause.message : String(cause);
7914
+ diagFailure(
7915
+ `[theokit-sdk] MCP server ${name} failed to close; its process may still be running: ${why}`
7916
+ );
7917
+ }
7918
+ }
7919
+ }
7854
7920
 
7855
7921
  // src/internal/local-agent/local-agent-dispatch.ts
7856
7922
  function buildRealRunOptions(args) {
@@ -9405,32 +9471,6 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
9405
9471
  }
9406
9472
  }
9407
9473
 
9408
- // src/internal/concurrency/abort-utils.ts
9409
- function anySignal(signals) {
9410
- const filtered = signals.filter((s) => s !== void 0);
9411
- if (filtered.length === 0) {
9412
- return new AbortController().signal;
9413
- }
9414
- if (filtered.length === 1) {
9415
- return filtered[0];
9416
- }
9417
- if (typeof AbortSignal.any === "function") {
9418
- return AbortSignal.any(filtered);
9419
- }
9420
- return ponyfillAny(filtered);
9421
- }
9422
- function ponyfillAny(signals) {
9423
- const ctrl = new AbortController();
9424
- for (const s of signals) {
9425
- if (s.aborted) {
9426
- ctrl.abort(s.reason);
9427
- return ctrl.signal;
9428
- }
9429
- s.addEventListener("abort", () => ctrl.abort(s.reason), { once: true });
9430
- }
9431
- return ctrl.signal;
9432
- }
9433
-
9434
9474
  // src/internal/runtime/lifecycle/wrap-completion-check-run.ts
9435
9475
  function wrapRunWithCompletionCheck(args) {
9436
9476
  const check = args.completionCheck;
@@ -11084,7 +11124,7 @@ var Agent = class _Agent {
11084
11124
  */
11085
11125
  static async compact(agentId, options = {}) {
11086
11126
  const reg = await requireLocalAgent(agentId, "compact");
11087
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-F2UDGZCN.js');
11127
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-4HAUP3HK.js');
11088
11128
  const { cwd, model, store } = await openLocalStore(reg);
11089
11129
  return enqueueSessionWrite(
11090
11130
  cwd,
@@ -11114,7 +11154,7 @@ var Agent = class _Agent {
11114
11154
  */
11115
11155
  static async injectSessionTurn(agentId, turn) {
11116
11156
  const reg = await requireLocalAgent(agentId, "injectSessionTurn");
11117
- const { injectSessionTurn } = await import('./inject-session-E5UDFVLI.js');
11157
+ const { injectSessionTurn } = await import('./inject-session-LJX5JGV5.js');
11118
11158
  const { cwd, model, store } = await openLocalStore(reg);
11119
11159
  await injectSessionTurn({
11120
11160
  store,
@@ -11272,5 +11312,5 @@ async function openLocalStore(reg) {
11272
11312
  }
11273
11313
 
11274
11314
  export { Agent, AgentBuilder, DEFAULT_AGENTIC_MODEL_ID, MEMORY_EMBEDDING_ADAPTERS, Tool, ToolError, UsageAccumulator, computeCost, generateCronId, getPricingEntry, managedSettingsPathFor, openRouterMemoryEmbeddingProviderAdapter, readManagedSettings, resolveSessionDir };
11275
- //# sourceMappingURL=chunk-4PHSVR2R.js.map
11276
- //# sourceMappingURL=chunk-4PHSVR2R.js.map
11315
+ //# sourceMappingURL=chunk-MHIBYKWA.js.map
11316
+ //# sourceMappingURL=chunk-MHIBYKWA.js.map