@theokit/sdk 5.10.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 (71) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/dist/{agent-XTLAVVYC.js → agent-DFV52V6E.js} +8 -7
  3. package/dist/{agent-XTLAVVYC.js.map → agent-DFV52V6E.js.map} +1 -1
  4. package/dist/{agent-TLRURB7W.cjs → agent-OKP4LHG2.cjs} +9 -8
  5. package/dist/{agent-TLRURB7W.cjs.map → agent-OKP4LHG2.cjs.map} +1 -1
  6. package/dist/{chunk-CVEQ5366.cjs → chunk-35KBC4BX.cjs} +177 -119
  7. package/dist/chunk-35KBC4BX.cjs.map +1 -0
  8. package/dist/{chunk-FR6COQXZ.cjs → chunk-3JANYJYS.cjs} +3 -3
  9. package/dist/{chunk-FR6COQXZ.cjs.map → chunk-3JANYJYS.cjs.map} +1 -1
  10. package/dist/{chunk-523O5UYB.js → chunk-6G4IRQUD.js} +3 -3
  11. package/dist/{chunk-523O5UYB.js.map → chunk-6G4IRQUD.js.map} +1 -1
  12. package/dist/{chunk-EVH3OUMY.js → chunk-BBJ77S62.js} +190 -44
  13. package/dist/chunk-BBJ77S62.js.map +1 -0
  14. package/dist/{chunk-PCLRIQPX.cjs → chunk-EQ5NCH2Y.cjs} +4 -4
  15. package/dist/{chunk-PCLRIQPX.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-LZJXEPEQ.js +58 -0
  21. package/dist/chunk-LZJXEPEQ.js.map +1 -0
  22. package/dist/{chunk-RTE2DD4S.js → chunk-MHIBYKWA.js} +127 -69
  23. package/dist/chunk-MHIBYKWA.js.map +1 -0
  24. package/dist/{chunk-WPO3VCY4.cjs → chunk-N7KS3TIR.cjs} +47 -17
  25. package/dist/chunk-N7KS3TIR.cjs.map +1 -0
  26. package/dist/chunk-NWS2CS3Y.cjs +61 -0
  27. package/dist/chunk-NWS2CS3Y.cjs.map +1 -0
  28. package/dist/{chunk-QY3CIMUV.cjs → chunk-P5N3Q2NH.cjs} +210 -62
  29. package/dist/chunk-P5N3Q2NH.cjs.map +1 -0
  30. package/dist/{chunk-EXI7EHDN.js → chunk-Q34EBNYG.js} +3 -3
  31. package/dist/{chunk-EXI7EHDN.js.map → chunk-Q34EBNYG.js.map} +1 -1
  32. package/dist/{chunk-HI3W37FY.js → chunk-U27XHOEF.js} +3 -3
  33. package/dist/{chunk-HI3W37FY.js.map → chunk-U27XHOEF.js.map} +1 -1
  34. package/dist/{compact-session-PVAWTKKL.js → compact-session-4HAUP3HK.js} +4 -4
  35. package/dist/{compact-session-PVAWTKKL.js.map → compact-session-4HAUP3HK.js.map} +1 -1
  36. package/dist/{compact-session-4QHBBGEY.cjs → compact-session-Y56D3S57.cjs} +13 -13
  37. package/dist/{compact-session-4QHBBGEY.cjs.map → compact-session-Y56D3S57.cjs.map} +1 -1
  38. package/dist/cron.cjs +8 -7
  39. package/dist/cron.js +7 -6
  40. package/dist/eval.cjs +7 -6
  41. package/dist/eval.cjs.map +1 -1
  42. package/dist/eval.js +6 -5
  43. package/dist/eval.js.map +1 -1
  44. package/dist/index.cjs +40 -130
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.js +11 -106
  47. package/dist/index.js.map +1 -1
  48. package/dist/{inject-session-O24XGRR6.js → inject-session-LJX5JGV5.js} +3 -3
  49. package/dist/{inject-session-O24XGRR6.js.map → inject-session-LJX5JGV5.js.map} +1 -1
  50. package/dist/{inject-session-OMLFL2V3.cjs → inject-session-R73PRM7B.cjs} +4 -4
  51. package/dist/{inject-session-OMLFL2V3.cjs.map → inject-session-R73PRM7B.cjs.map} +1 -1
  52. package/dist/internal/budget/normalize-usage.d.ts +81 -0
  53. package/dist/internal/error-mappers/openai-compatible.d.ts +3 -1
  54. package/dist/internal/llm/anthropic-shared.d.ts +6 -0
  55. package/dist/internal/llm/openai.d.ts +3 -5
  56. package/dist/internal/llm/openrouter-system.d.ts +1 -0
  57. package/dist/internal/llm/types.d.ts +10 -5
  58. package/dist/internal/memory/adapters/index.cjs +3 -3
  59. package/dist/internal/memory/adapters/index.js +2 -2
  60. package/dist/models.cjs +5 -50
  61. package/dist/models.cjs.map +1 -1
  62. package/dist/models.js +3 -51
  63. package/dist/models.js.map +1 -1
  64. package/docs/error-codes.md +8 -4
  65. package/package.json +1 -1
  66. package/dist/chunk-CVEQ5366.cjs.map +0 -1
  67. package/dist/chunk-EVH3OUMY.js.map +0 -1
  68. package/dist/chunk-QY3CIMUV.cjs.map +0 -1
  69. package/dist/chunk-RTE2DD4S.js.map +0 -1
  70. package/dist/chunk-TE6XVTOA.js.map +0 -1
  71. package/dist/chunk-WPO3VCY4.cjs.map +0 -1
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkJ6GXS5A2_cjs = require('./chunk-J6GXS5A2.cjs');
4
- var chunkFR6COQXZ_cjs = require('./chunk-FR6COQXZ.cjs');
4
+ var chunk3JANYJYS_cjs = require('./chunk-3JANYJYS.cjs');
5
5
  var chunkL3C6CCBG_cjs = require('./chunk-L3C6CCBG.cjs');
6
6
  var chunkKIKKTW5O_cjs = require('./chunk-KIKKTW5O.cjs');
7
7
  var chunkBV2MWEMV_cjs = require('./chunk-BV2MWEMV.cjs');
8
- var chunkYEHQ3SIC_cjs = require('./chunk-YEHQ3SIC.cjs');
8
+ var chunkJV7JA7BM_cjs = require('./chunk-JV7JA7BM.cjs');
9
9
  var chunkTMKTSYDS_cjs = require('./chunk-TMKTSYDS.cjs');
10
10
  var chunkZD66GFH5_cjs = require('./chunk-ZD66GFH5.cjs');
11
11
  var chunkNQVWSSX2_cjs = require('./chunk-NQVWSSX2.cjs');
12
- var chunkQY3CIMUV_cjs = require('./chunk-QY3CIMUV.cjs');
12
+ var chunkP5N3Q2NH_cjs = require('./chunk-P5N3Q2NH.cjs');
13
13
  var chunk2ZPEDVLM_cjs = require('./chunk-2ZPEDVLM.cjs');
14
14
  var chunkXKZFIP7Z_cjs = require('./chunk-XKZFIP7Z.cjs');
15
15
  var chunkN6OEX5TN_cjs = require('./chunk-N6OEX5TN.cjs');
@@ -31,6 +31,7 @@ var chunkC7GKRGKN_cjs = require('./chunk-C7GKRGKN.cjs');
31
31
  var chunkTY56BKSK_cjs = require('./chunk-TY56BKSK.cjs');
32
32
  var chunkMPR2ISL2_cjs = require('./chunk-MPR2ISL2.cjs');
33
33
  var chunkJ5623RIV_cjs = require('./chunk-J5623RIV.cjs');
34
+ var chunkNWS2CS3Y_cjs = require('./chunk-NWS2CS3Y.cjs');
34
35
  var chunk3EE6LVWT_cjs = require('./chunk-3EE6LVWT.cjs');
35
36
  var chunkSGC7LSHF_cjs = require('./chunk-SGC7LSHF.cjs');
36
37
  var chunkHU666T3Q_cjs = require('./chunk-HU666T3Q.cjs');
@@ -1566,7 +1567,7 @@ function createRealCloudRun(options) {
1566
1567
  conversation: []
1567
1568
  };
1568
1569
  const apiKey = chunk6LHQPOMI_cjs.resolveApiKey(options.agentOptions.apiKey);
1569
- const baseUrl = chunkQY3CIMUV_cjs.getConfiguredBaseUrl();
1570
+ const baseUrl = chunkP5N3Q2NH_cjs.getConfiguredBaseUrl();
1570
1571
  const handle = new RealCloudRun(
1571
1572
  {
1572
1573
  id,
@@ -1649,7 +1650,7 @@ var RealCloudRun = class extends FixtureRunBase {
1649
1650
  async consumeStream(response) {
1650
1651
  let finalStatus = "finished";
1651
1652
  let finalText = "";
1652
- for await (const record of chunkQY3CIMUV_cjs.parseSseStream(response.body, this.controller.signal)) {
1653
+ for await (const record of chunkP5N3Q2NH_cjs.parseSseStream(response.body, this.controller.signal)) {
1653
1654
  const parsed = safeParse(record.data);
1654
1655
  if (parsed === void 0) continue;
1655
1656
  const update = this.applyRecord(record.event, parsed);
@@ -1816,7 +1817,7 @@ var CloudAgent = class _CloudAgent {
1816
1817
  */
1817
1818
  isFixtureMode() {
1818
1819
  const apiKey = chunk6LHQPOMI_cjs.resolveApiKey(this.options.apiKey);
1819
- return chunkQY3CIMUV_cjs.isFixtureApiKey(apiKey) && chunkQY3CIMUV_cjs.getConfiguredBaseUrl() === void 0;
1820
+ return chunkP5N3Q2NH_cjs.isFixtureApiKey(apiKey) && chunkP5N3Q2NH_cjs.getConfiguredBaseUrl() === void 0;
1820
1821
  }
1821
1822
  // SE9 — integrated structured output; delegates to the shared helper.
1822
1823
  generate(message, options) {
@@ -1868,7 +1869,7 @@ var CloudAgent = class _CloudAgent {
1868
1869
  const userText = typeof message === "string" ? message : message.text;
1869
1870
  const systemPrompt = await this.resolveSystemPromptForSend(userText, options);
1870
1871
  const apiKey = chunk6LHQPOMI_cjs.resolveApiKey(this.options.apiKey);
1871
- const useRealRuntime = apiKey !== void 0 && !chunkQY3CIMUV_cjs.isFixtureApiKey(apiKey) && chunkQY3CIMUV_cjs.getConfiguredBaseUrl() !== void 0;
1872
+ const useRealRuntime = apiKey !== void 0 && !chunkP5N3Q2NH_cjs.isFixtureApiKey(apiKey) && chunkP5N3Q2NH_cjs.getConfiguredBaseUrl() !== void 0;
1872
1873
  return useRealRuntime ? createRealCloudRun({
1873
1874
  agentId: this.agentId,
1874
1875
  model: this.model ?? { id: DEFAULT_AGENTIC_MODEL_ID },
@@ -2933,7 +2934,7 @@ async function runPostRunLifecycle(inputs) {
2933
2934
  try {
2934
2935
  const partial = await safeConversation(run);
2935
2936
  if (partial !== void 0) {
2936
- chunkFR6COQXZ_cjs.persistTurnToTranscript(sessionStore, { cwd: workspaceCwd, agentId, model }, agentId, {
2937
+ chunk3JANYJYS_cjs.persistTurnToTranscript(sessionStore, { cwd: workspaceCwd, agentId, model }, agentId, {
2937
2938
  userText,
2938
2939
  conversation: partial
2939
2940
  });
@@ -2943,11 +2944,11 @@ async function runPostRunLifecycle(inputs) {
2943
2944
  chunk6LHQPOMI_cjs.diag(`[theokit-sdk] partial transcript write failed (${agentId}): ${msg}
2944
2945
  `);
2945
2946
  }
2946
- await chunkFR6COQXZ_cjs.flushSessionWrites();
2947
+ await chunk3JANYJYS_cjs.flushSessionWrites();
2947
2948
  return;
2948
2949
  }
2949
2950
  if (result.result !== void 0) {
2950
- chunkFR6COQXZ_cjs.appendSessionMessage(agentId, { role: "assistant", text: result.result });
2951
+ chunk3JANYJYS_cjs.appendSessionMessage(agentId, { role: "assistant", text: result.result });
2951
2952
  }
2952
2953
  const conversation = await safeConversation(run);
2953
2954
  const resolvedWindow = resolveWindowForRun(model, contextWindow);
@@ -2958,7 +2959,7 @@ async function runPostRunLifecycle(inputs) {
2958
2959
  }
2959
2960
  const lastRequestUsage = result.usage?.requests?.at(-1)?.totalTokens;
2960
2961
  const usageForTrigger = lastRequestUsage ?? result.usage?.totalTokens;
2961
- chunkFR6COQXZ_cjs.persistTurnToTranscript(
2962
+ chunk3JANYJYS_cjs.persistTurnToTranscript(
2962
2963
  sessionStore,
2963
2964
  { cwd: workspaceCwd, agentId, model },
2964
2965
  agentId,
@@ -2970,7 +2971,7 @@ async function runPostRunLifecycle(inputs) {
2970
2971
  // The EFFECTIVE window (after override, clamp and margin) — not the declared one. Swapping for
2971
2972
  // `contextWindow` here would budget against a number the clamp already rejected.
2972
2973
  contextWindow: effectiveWindow,
2973
- summarize: chunkQY3CIMUV_cjs.buildDefaultSummarizer({
2974
+ summarize: chunkP5N3Q2NH_cjs.buildDefaultSummarizer({
2974
2975
  agentModel: model,
2975
2976
  ...inputs.apiKey !== void 0 ? { apiKey: inputs.apiKey } : {}
2976
2977
  })
@@ -3012,7 +3013,7 @@ async function runPostRunLifecycle(inputs) {
3012
3013
  agentId,
3013
3014
  runId: result.id
3014
3015
  });
3015
- await chunkFR6COQXZ_cjs.flushSessionWrites();
3016
+ await chunk3JANYJYS_cjs.flushSessionWrites();
3016
3017
  }
3017
3018
  async function safeConversation(run) {
3018
3019
  try {
@@ -3643,7 +3644,7 @@ var HISTOGRAM_NAMES = {
3643
3644
  };
3644
3645
  function safeRequire(moduleName) {
3645
3646
  try {
3646
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-CVEQ5366.cjs', document.baseURI).href)));
3647
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-35KBC4BX.cjs', document.baseURI).href)));
3647
3648
  return r(moduleName);
3648
3649
  } catch {
3649
3650
  return void 0;
@@ -3886,7 +3887,7 @@ var cachedOtel;
3886
3887
  function loadOtel() {
3887
3888
  if (cachedOtel === void 0) {
3888
3889
  try {
3889
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-CVEQ5366.cjs', document.baseURI).href)));
3890
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-35KBC4BX.cjs', document.baseURI).href)));
3890
3891
  const mod = r("@opentelemetry/api");
3891
3892
  cachedOtel = mod;
3892
3893
  } catch {
@@ -5807,14 +5808,27 @@ function stripThinkBlocks(content) {
5807
5808
  // src/internal/agent-loop/loop-llm-stream.ts
5808
5809
  function resolveSystemPromptWithMemoryAdditions(systemPrompt, additions) {
5809
5810
  if (additions === void 0 || additions.length === 0) return systemPrompt;
5810
- const block = `<active-memory>
5811
- ${chunkHG5LKFG7_cjs.escapeBlockBody(additions)}
5812
- </active-memory>`;
5811
+ const block = activeMemoryBlock(additions);
5813
5812
  if (systemPrompt === void 0 || systemPrompt.length === 0) return block;
5814
5813
  return `${block}
5815
5814
 
5816
5815
  ${systemPrompt}`;
5817
5816
  }
5817
+ function activeMemoryBlock(additions) {
5818
+ return `<active-memory>
5819
+ ${chunkHG5LKFG7_cjs.escapeBlockBody(additions)}
5820
+ </active-memory>`;
5821
+ }
5822
+ function buildLoopSystem(systemPrompt, additions, modelId) {
5823
+ if (!chunkNWS2CS3Y_cjs.isAnthropicFamilyModel(modelId) || systemPrompt === void 0 || systemPrompt.length === 0) {
5824
+ return resolveSystemPromptWithMemoryAdditions(systemPrompt, additions);
5825
+ }
5826
+ const blocks = [{ text: systemPrompt, cacheable: true }];
5827
+ if (additions !== void 0 && additions.length > 0) {
5828
+ blocks.push({ text: activeMemoryBlock(additions) });
5829
+ }
5830
+ return blocks;
5831
+ }
5818
5832
  function toLlmTool(tool) {
5819
5833
  return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema };
5820
5834
  }
@@ -5853,9 +5867,10 @@ async function streamLlmTurn(inputs, ctx) {
5853
5867
  {
5854
5868
  model: inputs.model.id ?? "auto",
5855
5869
  ...(() => {
5856
- const effective = resolveSystemPromptWithMemoryAdditions(
5870
+ const effective = buildLoopSystem(
5857
5871
  inputs.systemPrompt,
5858
- ctx.memorySystemPromptAdditions
5872
+ ctx.memorySystemPromptAdditions,
5873
+ inputs.model.id
5859
5874
  );
5860
5875
  return effective !== void 0 ? { system: effective } : {};
5861
5876
  })(),
@@ -5958,6 +5973,7 @@ function registerLoopError(ctx, cause) {
5958
5973
  async function consumeStreamEvent(inputs, reasoning, event) {
5959
5974
  if (event.type === "text_delta") {
5960
5975
  const text = event.text ?? "";
5976
+ if (text.length > 0) await closeReasoningOnce(inputs, reasoning);
5961
5977
  await emitTextDeltaCallback(inputs, text);
5962
5978
  return text;
5963
5979
  }
@@ -5970,7 +5986,14 @@ async function consumeStreamEvent(inputs, reasoning, event) {
5970
5986
  return "";
5971
5987
  }
5972
5988
  async function runCollectorLoop(generator, inputs, ctx, partial) {
5973
- const reasoning = { text: "", startedAt: void 0, signature: void 0 };
5989
+ const reasoning = {
5990
+ text: "",
5991
+ startedAt: void 0,
5992
+ lastAt: void 0,
5993
+ signature: void 0,
5994
+ closed: false,
5995
+ durationMs: 0
5996
+ };
5974
5997
  let errored = false;
5975
5998
  let finishValue;
5976
5999
  let thinking;
@@ -5999,17 +6022,24 @@ async function consumeReasoningDelta(inputs, reasoning, delta) {
5999
6022
  await accumulateReasoning(inputs, reasoning, delta.text);
6000
6023
  }
6001
6024
  async function accumulateReasoning(inputs, reasoning, text) {
6002
- if (reasoning.startedAt === void 0) reasoning.startedAt = Date.now();
6025
+ const now = Date.now();
6026
+ if (reasoning.startedAt === void 0) reasoning.startedAt = now;
6027
+ if (!reasoning.closed) reasoning.lastAt = now;
6003
6028
  reasoning.text += text;
6004
6029
  await emitReasoningDeltaCallback(inputs, text);
6005
6030
  }
6031
+ async function closeReasoningOnce(inputs, reasoning) {
6032
+ if (reasoning.closed || reasoning.text.length === 0) return;
6033
+ reasoning.closed = true;
6034
+ reasoning.durationMs = (reasoning.lastAt ?? 0) - (reasoning.startedAt ?? 0);
6035
+ await emitThinkingCompletedCallback(inputs, reasoning.durationMs);
6036
+ }
6006
6037
  async function finalizeReasoning(inputs, ctx, reasoning) {
6007
6038
  if (reasoning.text.length === 0) return void 0;
6008
- const thinkingDurationMs = reasoning.startedAt === void 0 ? 0 : Date.now() - reasoning.startedAt;
6039
+ await closeReasoningOnce(inputs, reasoning);
6009
6040
  ctx.events.push(
6010
- buildThinkingEvent(inputs, reasoning.text, thinkingDurationMs, reasoning.signature)
6041
+ buildThinkingEvent(inputs, reasoning.text, reasoning.durationMs, reasoning.signature)
6011
6042
  );
6012
- await emitThinkingCompletedCallback(inputs, thinkingDurationMs);
6013
6043
  return {
6014
6044
  type: "thinking",
6015
6045
  text: reasoning.text,
@@ -6654,7 +6684,7 @@ function applyToolResultGuard(parts, opts) {
6654
6684
  (p) => (
6655
6685
  // SE7 — guard the TEXT of a tool result (string or the text blocks of a
6656
6686
  // structured content); image blocks pass through untouched.
6657
- p.type === "tool_result" ? { ...p, content: chunkQY3CIMUV_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
6687
+ p.type === "tool_result" ? { ...p, content: chunkP5N3Q2NH_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
6658
6688
  )
6659
6689
  );
6660
6690
  }
@@ -6842,29 +6872,32 @@ async function runIteration(inputs, ctx) {
6842
6872
  const llmOutput = await streamLlmTurn(inputs, ctx);
6843
6873
  await inputs.pluginManager?.runPostLlmCallHooks(hookCtx);
6844
6874
  accumulateUsage(ctx.usage, llmOutput);
6845
- if (inputs.budgetTracker !== void 0) {
6846
- const modelId = inputs.model.id ?? "auto";
6847
- const inputT = llmOutput.inputTokens ?? 0;
6848
- const outputT = llmOutput.outputTokens ?? 0;
6849
- try {
6850
- if (inputT > 0) {
6851
- inputs.budgetTracker.track({
6852
- tokens: inputT,
6853
- model: modelId,
6854
- type: "input"
6855
- });
6856
- }
6857
- if (outputT > 0) {
6858
- inputs.budgetTracker.track({
6859
- tokens: outputT,
6860
- model: modelId,
6861
- type: "output"
6862
- });
6863
- }
6864
- } catch {
6875
+ trackTurnUsage(inputs, llmOutput);
6876
+ return continueOrTerminate(inputs, ctx, llmOutput);
6877
+ }
6878
+ function trackTurnUsage(inputs, llmOutput) {
6879
+ const tracker = inputs.budgetTracker;
6880
+ if (tracker === void 0) return;
6881
+ const modelId = inputs.model.id ?? "auto";
6882
+ const inputT = (llmOutput.inputTokens ?? 0) + (llmOutput.cacheReadTokens ?? 0) + (llmOutput.cacheWriteTokens ?? 0);
6883
+ const outputT = llmOutput.outputTokens ?? 0;
6884
+ try {
6885
+ if (inputT > 0) {
6886
+ tracker.track({
6887
+ tokens: inputT,
6888
+ model: modelId,
6889
+ type: "input"
6890
+ });
6891
+ }
6892
+ if (outputT > 0) {
6893
+ tracker.track({
6894
+ tokens: outputT,
6895
+ model: modelId,
6896
+ type: "output"
6897
+ });
6865
6898
  }
6899
+ } catch {
6866
6900
  }
6867
- return continueOrTerminate(inputs, ctx, llmOutput);
6868
6901
  }
6869
6902
  async function transformLlmOutputText(inputs, text, ctx) {
6870
6903
  return inputs.pluginManager !== void 0 ? inputs.pluginManager.runTransformLlmOutputHooks(text, ctx) : text;
@@ -6936,6 +6969,32 @@ async function inspectDoomLoop(inputs, ctx, toolCalls) {
6936
6969
  return "continue";
6937
6970
  }
6938
6971
 
6972
+ // src/internal/concurrency/abort-utils.ts
6973
+ function anySignal(signals) {
6974
+ const filtered = signals.filter((s) => s !== void 0);
6975
+ if (filtered.length === 0) {
6976
+ return new AbortController().signal;
6977
+ }
6978
+ if (filtered.length === 1) {
6979
+ return filtered[0];
6980
+ }
6981
+ if (typeof AbortSignal.any === "function") {
6982
+ return AbortSignal.any(filtered);
6983
+ }
6984
+ return ponyfillAny(filtered);
6985
+ }
6986
+ function ponyfillAny(signals) {
6987
+ const ctrl = new AbortController();
6988
+ for (const s of signals) {
6989
+ if (s.aborted) {
6990
+ ctrl.abort(s.reason);
6991
+ return ctrl.signal;
6992
+ }
6993
+ s.addEventListener("abort", () => ctrl.abort(s.reason), { once: true });
6994
+ }
6995
+ return ctrl.signal;
6996
+ }
6997
+
6939
6998
  // src/internal/llm/fallback-client.ts
6940
6999
  var FallbackLlmClient = class {
6941
7000
  constructor(clients) {
@@ -6946,13 +7005,13 @@ var FallbackLlmClient = class {
6946
7005
  async *stream(request, signal) {
6947
7006
  let lastError;
6948
7007
  for (const client of this.clients) {
6949
- if (signal.aborted) throw chunkQY3CIMUV_cjs.abortError(signal);
6950
- const attempt = await chunkQY3CIMUV_cjs.tryFirstEvent(client, request, signal, true);
7008
+ if (signal.aborted) throw chunkP5N3Q2NH_cjs.abortError(signal);
7009
+ const attempt = await chunkP5N3Q2NH_cjs.tryFirstEvent(client, request, signal, true);
6951
7010
  if (attempt.kind === "handshake_error") {
6952
7011
  lastError = attempt.error;
6953
7012
  continue;
6954
7013
  }
6955
- return yield* chunkQY3CIMUV_cjs.relayStream(attempt.generator, attempt.firstResult);
7014
+ return yield* chunkP5N3Q2NH_cjs.relayStream(attempt.generator, attempt.firstResult);
6956
7015
  }
6957
7016
  if (lastError !== void 0) throw lastError;
6958
7017
  throw new chunkUNFBHV46_cjs.NetworkError("FallbackLlmClient has no providers configured", {
@@ -7588,9 +7647,9 @@ function buildLoopInputs(options, runId, userText, userImages) {
7588
7647
  { code: "invalid_max_iterations" }
7589
7648
  );
7590
7649
  }
7591
- const { primary, effectiveModelId } = chunkQY3CIMUV_cjs.resolveRunProvider(options);
7650
+ const { primary, effectiveModelId } = chunkP5N3Q2NH_cjs.resolveRunProvider(options);
7592
7651
  const fallback = options.agentOptions.providers?.fallback;
7593
- const apiKeys = chunkQY3CIMUV_cjs.mergeExplicitApiKey(
7652
+ const apiKeys = chunkP5N3Q2NH_cjs.mergeExplicitApiKey(
7594
7653
  options.agentOptions.providers?.apiKeys,
7595
7654
  primary,
7596
7655
  options.agentOptions.apiKey
@@ -7599,7 +7658,7 @@ function buildLoopInputs(options, runId, userText, userImages) {
7599
7658
  const extractToolCallsFromContent = options.agentOptions.providers?.routes?.[0]?.extractToolCallsFromContent;
7600
7659
  const rateLimitSink = options.sendOptions.onRunEvent;
7601
7660
  const modelBaseUrl = options.model?.url;
7602
- const chain = chunkQY3CIMUV_cjs.resolveProviderChain({
7661
+ const chain = chunkP5N3Q2NH_cjs.resolveProviderChain({
7603
7662
  primary,
7604
7663
  ...modelBaseUrl !== void 0 ? { baseUrl: modelBaseUrl } : {},
7605
7664
  ...fallback !== void 0 ? { fallback } : {},
@@ -7690,6 +7749,13 @@ var RealLocalRun = class extends FixtureRunBase {
7690
7749
  ownsMcpClients;
7691
7750
  /** theokit#148 — what a delegated child inherits from this parent, scoped to the loop. */
7692
7751
  inheritedCredentials;
7752
+ /**
7753
+ * B-495 — the run's own abort, composed into the signal the loop hands to the LLM fetch and the
7754
+ * tool executors, so `cancel()` stops the request and not only the status. A TypeScript `private`
7755
+ * field, never a JS `#private` one: the run wrappers are Proxies that call `cancel()` with `this`
7756
+ * bound to the Proxy, where reading a `#private` field throws.
7757
+ */
7758
+ cancelController = new AbortController();
7693
7759
  constructor(options, buildInputs, ownsMcpClients, inheritedCredentials) {
7694
7760
  super(options);
7695
7761
  this.buildInputs = buildInputs;
@@ -7701,6 +7767,11 @@ var RealLocalRun = class extends FixtureRunBase {
7701
7767
  void this.driveLoop();
7702
7768
  }, 0);
7703
7769
  }
7770
+ cancel() {
7771
+ if (this.terminated) return Promise.resolve();
7772
+ this.cancelController.abort();
7773
+ return super.cancel();
7774
+ }
7704
7775
  notifyImmediately() {
7705
7776
  return true;
7706
7777
  }
@@ -7744,7 +7815,9 @@ var RealLocalRun = class extends FixtureRunBase {
7744
7815
  liveDelivered = /* @__PURE__ */ new Set();
7745
7816
  async executeAgentLoop(inputs) {
7746
7817
  let textStreamedSinceLastMessage = false;
7818
+ inputs.signal = anySignal([inputs.signal, this.cancelController.signal]);
7747
7819
  inputs.onLoopEvent = (event) => {
7820
+ if (this.terminated) return;
7748
7821
  this.liveDelivered.add(event);
7749
7822
  this.script.events.push(event);
7750
7823
  const carriesText = event.type === "assistant" && event.message.content.some((b) => b.type === "text");
@@ -7760,11 +7833,13 @@ var RealLocalRun = class extends FixtureRunBase {
7760
7833
  };
7761
7834
  const callerOnDelta = inputs.onDelta;
7762
7835
  inputs.onDelta = (delta) => {
7836
+ if (this.terminated) return;
7763
7837
  callerOnDelta?.(delta);
7764
7838
  if (delta.update.type === "text-delta") textStreamedSinceLastMessage = true;
7765
7839
  this.pushTimeline({ kind: "delta", update: delta.update });
7766
7840
  };
7767
7841
  try {
7842
+ if (this.terminated) return;
7768
7843
  const runLoop = () => inputs.activeTools !== void 0 ? chunkIJ7M6GOG_cjs.withToolWhitelist(new Set(inputs.activeTools), () => runAgentLoop(inputs)) : runAgentLoop(inputs);
7769
7844
  const output = await chunkJW3GVLM6_cjs.withInheritedSubAgentCredentials(this.inheritedCredentials, runLoop);
7770
7845
  this.applyAgentLoopOutput(output);
@@ -7773,11 +7848,7 @@ var RealLocalRun = class extends FixtureRunBase {
7773
7848
  this.emitErrorEvent(cause, "Agent loop failed", "", "agent_loop_failed");
7774
7849
  this.transitionTo("error");
7775
7850
  } finally {
7776
- if (this.ownsMcpClients) {
7777
- for (const client of inputs.mcp.values()) {
7778
- await client.close().catch(() => void 0);
7779
- }
7780
- }
7851
+ if (this.ownsMcpClients) await closeOwnedMcpClients(inputs);
7781
7852
  }
7782
7853
  }
7783
7854
  /**
@@ -7789,6 +7860,7 @@ var RealLocalRun = class extends FixtureRunBase {
7789
7860
  * Finding-B fix (sdk-error-packaging v1.1): set-once errorDetail copy.
7790
7861
  */
7791
7862
  applyAgentLoopOutput(output) {
7863
+ if (this.terminated) return;
7792
7864
  this.deliverUndeliveredEvents(output.events);
7793
7865
  this.script.conversation.push(...output.conversation);
7794
7866
  if (output.result.length > 0) this.script.result = output.result;
@@ -7836,6 +7908,18 @@ var RealLocalRun = class extends FixtureRunBase {
7836
7908
  this.notifyNewEvents();
7837
7909
  }
7838
7910
  };
7911
+ async function closeOwnedMcpClients(inputs) {
7912
+ for (const [name, client] of inputs.mcp.entries()) {
7913
+ try {
7914
+ await client.close();
7915
+ } catch (cause) {
7916
+ const why = cause instanceof Error ? cause.message : String(cause);
7917
+ chunk6LHQPOMI_cjs.diagFailure(
7918
+ `[theokit-sdk] MCP server ${name} failed to close; its process may still be running: ${why}`
7919
+ );
7920
+ }
7921
+ }
7922
+ }
7839
7923
 
7840
7924
  // src/internal/local-agent/local-agent-dispatch.ts
7841
7925
  function buildRealRunOptions(args) {
@@ -7859,7 +7943,7 @@ function buildRealRunOptions(args) {
7859
7943
  };
7860
7944
  }
7861
7945
  async function createFixtureRunHelper(args) {
7862
- const sessionMessages = chunkFR6COQXZ_cjs.getSessionMessages(args.inputs.agentId);
7946
+ const sessionMessages = chunk3JANYJYS_cjs.getSessionMessages(args.inputs.agentId);
7863
7947
  const projectMcpServers = args.inputs.settingSourcesIncludeProject ? await readProjectMcpServers(args.inputs.workspaceCwd) : {};
7864
7948
  return createLocalRun({
7865
7949
  agentId: args.inputs.agentId,
@@ -7878,7 +7962,7 @@ async function createFixtureRunHelper(args) {
7878
7962
  }
7879
7963
  async function dispatchLocalRun(args) {
7880
7964
  const apiKey = chunk6LHQPOMI_cjs.resolveApiKey(args.inputs.options.apiKey);
7881
- if (chunkQY3CIMUV_cjs.shouldUseRealLocalRuntime(apiKey)) {
7965
+ if (chunkP5N3Q2NH_cjs.shouldUseRealLocalRuntime(apiKey)) {
7882
7966
  return createRealLocalRun(
7883
7967
  buildRealRunOptions({
7884
7968
  inputs: args.inputs,
@@ -8134,10 +8218,10 @@ async function disposeLocalAgentSession(agent) {
8134
8218
  agent.lifecycleAbortController.abort();
8135
8219
  await chunkZF2LDKQQ_cjs.withCwdMutex(`agent-send:${agent.agentId}`, () => Promise.resolve());
8136
8220
  disposeSessionMcpClients(agent.agentId);
8137
- await chunkFR6COQXZ_cjs.flushSessionWrites();
8221
+ await chunk3JANYJYS_cjs.flushSessionWrites();
8138
8222
  await flushRegistrySaves(agent.workspaceCwd);
8139
8223
  await disposeSessionStore(agent.sessionStore);
8140
- chunkFR6COQXZ_cjs.discardSession(agent.workspaceCwd, agent.agentId);
8224
+ chunk3JANYJYS_cjs.discardSession(agent.workspaceCwd, agent.agentId);
8141
8225
  }
8142
8226
  async function reloadLocalAgent(agent) {
8143
8227
  if (agent.context !== void 0) await agent.context.refresh();
@@ -8492,7 +8576,7 @@ var openAiMemoryEmbeddingProviderAdapter = {
8492
8576
  transport: "remote",
8493
8577
  authProviderId: "openai",
8494
8578
  autoSelectPriority: 20,
8495
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8579
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8496
8580
  {
8497
8581
  id: "openai",
8498
8582
  defaultBaseUrl: "https://api.openai.com",
@@ -8514,7 +8598,7 @@ var azureOpenAiMemoryEmbeddingProviderAdapter = {
8514
8598
  transport: "remote",
8515
8599
  authProviderId: "azure-openai",
8516
8600
  autoSelectPriority: 25,
8517
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8601
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8518
8602
  {
8519
8603
  id: "azure-openai",
8520
8604
  defaultBaseUrl: "https://your-resource.openai.azure.com",
@@ -8550,7 +8634,7 @@ var cohereMemoryEmbeddingProviderAdapter = {
8550
8634
  transport: "remote",
8551
8635
  authProviderId: "cohere",
8552
8636
  autoSelectPriority: 30,
8553
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8637
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8554
8638
  {
8555
8639
  id: "cohere",
8556
8640
  defaultBaseUrl: "https://api.cohere.com",
@@ -8596,7 +8680,7 @@ var deepinfraMemoryEmbeddingProviderAdapter = {
8596
8680
  transport: "remote",
8597
8681
  authProviderId: "deepinfra",
8598
8682
  autoSelectPriority: 13,
8599
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8683
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8600
8684
  {
8601
8685
  id: "deepinfra",
8602
8686
  defaultBaseUrl: "https://api.deepinfra.com",
@@ -8622,7 +8706,7 @@ var geminiMemoryEmbeddingProviderAdapter = {
8622
8706
  transport: "remote",
8623
8707
  authProviderId: "gemini",
8624
8708
  autoSelectPriority: 30,
8625
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8709
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8626
8710
  {
8627
8711
  id: "gemini",
8628
8712
  defaultBaseUrl: "https://generativelanguage.googleapis.com",
@@ -8650,7 +8734,7 @@ var jinaMemoryEmbeddingProviderAdapter = {
8650
8734
  transport: "remote",
8651
8735
  authProviderId: "jina",
8652
8736
  autoSelectPriority: 35,
8653
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8737
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8654
8738
  {
8655
8739
  id: "jina",
8656
8740
  defaultBaseUrl: "https://api.jina.ai",
@@ -8673,7 +8757,7 @@ var mistralMemoryEmbeddingProviderAdapter = {
8673
8757
  transport: "remote",
8674
8758
  authProviderId: "mistral",
8675
8759
  autoSelectPriority: 18,
8676
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8760
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8677
8761
  {
8678
8762
  id: "mistral",
8679
8763
  defaultBaseUrl: "https://api.mistral.ai",
@@ -8715,7 +8799,7 @@ var ollamaMemoryEmbeddingProviderAdapter = {
8715
8799
  autoSelectPriority: 10,
8716
8800
  create: (options) => {
8717
8801
  const apiKey = options.apiKey ?? process.env.OLLAMA_API_KEY ?? OLLAMA_LOCAL_SENTINEL_KEY;
8718
- return chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8802
+ return chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8719
8803
  {
8720
8804
  id: "ollama",
8721
8805
  defaultBaseUrl: "http://localhost:11434",
@@ -8743,7 +8827,7 @@ var openRouterMemoryEmbeddingProviderAdapter = {
8743
8827
  transport: "remote",
8744
8828
  authProviderId: "openrouter",
8745
8829
  autoSelectPriority: 15,
8746
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8830
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8747
8831
  {
8748
8832
  id: "openrouter",
8749
8833
  defaultBaseUrl: "https://openrouter.ai/api",
@@ -8771,7 +8855,7 @@ var voyageMemoryEmbeddingProviderAdapter = {
8771
8855
  transport: "remote",
8772
8856
  authProviderId: "voyage",
8773
8857
  autoSelectPriority: 14,
8774
- create: (options) => chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime(
8858
+ create: (options) => chunkJV7JA7BM_cjs.createOpenAiCompatibleRuntime(
8775
8859
  {
8776
8860
  id: "voyage",
8777
8861
  defaultBaseUrl: "https://api.voyageai.com",
@@ -9001,7 +9085,7 @@ var LocalAgentMemory = class {
9001
9085
  async runActiveMemoryIfEnabled(userText, priorMessages, telemetry) {
9002
9086
  const cfg = this.options.memory?.activeRecall;
9003
9087
  if (cfg?.enabled !== true || this.index === void 0) return void 0;
9004
- if (this.breaker === void 0) this.breaker = new chunkQY3CIMUV_cjs.CircuitBreaker();
9088
+ if (this.breaker === void 0) this.breaker = new chunkP5N3Q2NH_cjs.CircuitBreaker();
9005
9089
  if (this.cache === void 0) this.cache = new ActiveMemoryCache();
9006
9090
  const result = await runActiveMemory({
9007
9091
  userText,
@@ -9316,8 +9400,8 @@ async function localAgentUsePersonality(agent, name, opts) {
9316
9400
  registry,
9317
9401
  store: agent.personalityStore,
9318
9402
  invalidateCache: (reason) => agent.invalidateCache(reason),
9319
- appendSessionMessage: (msg) => chunkFR6COQXZ_cjs.appendSessionMessage(agent.agentId, msg),
9320
- clearSession: () => chunkFR6COQXZ_cjs.clearSession(agent.agentId),
9403
+ appendSessionMessage: (msg) => chunk3JANYJYS_cjs.appendSessionMessage(agent.agentId, msg),
9404
+ clearSession: () => chunk3JANYJYS_cjs.clearSession(agent.agentId),
9321
9405
  opts: opts ?? {}
9322
9406
  })
9323
9407
  );
@@ -9390,32 +9474,6 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
9390
9474
  }
9391
9475
  }
9392
9476
 
9393
- // src/internal/concurrency/abort-utils.ts
9394
- function anySignal(signals) {
9395
- const filtered = signals.filter((s) => s !== void 0);
9396
- if (filtered.length === 0) {
9397
- return new AbortController().signal;
9398
- }
9399
- if (filtered.length === 1) {
9400
- return filtered[0];
9401
- }
9402
- if (typeof AbortSignal.any === "function") {
9403
- return AbortSignal.any(filtered);
9404
- }
9405
- return ponyfillAny(filtered);
9406
- }
9407
- function ponyfillAny(signals) {
9408
- const ctrl = new AbortController();
9409
- for (const s of signals) {
9410
- if (s.aborted) {
9411
- ctrl.abort(s.reason);
9412
- return ctrl.signal;
9413
- }
9414
- s.addEventListener("abort", () => ctrl.abort(s.reason), { once: true });
9415
- }
9416
- return ctrl.signal;
9417
- }
9418
-
9419
9477
  // src/internal/runtime/lifecycle/wrap-completion-check-run.ts
9420
9478
  function wrapRunWithCompletionCheck(args) {
9421
9479
  const check = args.completionCheck;
@@ -9871,7 +9929,7 @@ async function executeSendLocked(inputs, message, options) {
9871
9929
  if (inputs.options.onBeforeSend !== void 0) {
9872
9930
  await inputs.options.onBeforeSend({
9873
9931
  conversationId: inputs.agentId,
9874
- previousMessageCount: chunkFR6COQXZ_cjs.getSessionMessages(inputs.agentId).length
9932
+ previousMessageCount: chunk3JANYJYS_cjs.getSessionMessages(inputs.agentId).length
9875
9933
  });
9876
9934
  }
9877
9935
  await inputs.runPreHook(userText);
@@ -9883,8 +9941,8 @@ async function executeSendLocked(inputs, message, options) {
9883
9941
  userText,
9884
9942
  sendOptions: options
9885
9943
  });
9886
- const priorMessages = [...chunkFR6COQXZ_cjs.getSessionMessages(inputs.agentId)];
9887
- chunkFR6COQXZ_cjs.appendSessionMessage(inputs.agentId, { role: "user", text: userText });
9944
+ const priorMessages = [...chunk3JANYJYS_cjs.getSessionMessages(inputs.agentId)];
9945
+ chunk3JANYJYS_cjs.appendSessionMessage(inputs.agentId, { role: "user", text: userText });
9888
9946
  await persistMemoryFactIfWritePrompt(inputs.workspaceCwd, inputs.options.memory, userText);
9889
9947
  const memoryFacts = await readMemoryForSend(inputs.workspaceCwd, inputs.options.memory, userText);
9890
9948
  const memoryTools = void 0;
@@ -10190,7 +10248,7 @@ var LocalAgent = class {
10190
10248
  );
10191
10249
  await acquireLeaseIfPossible(this.sessionStore, this.agentId);
10192
10250
  try {
10193
- await chunkFR6COQXZ_cjs.hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
10251
+ await chunk3JANYJYS_cjs.hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
10194
10252
  await this.personalityStore.hydrate(this.agentId);
10195
10253
  } catch (err) {
10196
10254
  await releaseLeaseIfPossible(this.sessionStore, this.agentId);
@@ -10531,15 +10589,15 @@ async function maybeInjectHandoffTools(options) {
10531
10589
  };
10532
10590
  }
10533
10591
  function keyWillFlowToProvider(apiKey, provider) {
10534
- if (chunkQY3CIMUV_cjs.isFixtureApiKey(apiKey)) return false;
10535
- if (chunkQY3CIMUV_cjs.getConfiguredBaseUrl() !== void 0) return false;
10592
+ if (chunkP5N3Q2NH_cjs.isFixtureApiKey(apiKey)) return false;
10593
+ if (chunkP5N3Q2NH_cjs.getConfiguredBaseUrl() !== void 0) return false;
10536
10594
  if (provider === void 0) return false;
10537
10595
  const profile = chunkSGC7LSHF_cjs.getProviderProfile(provider);
10538
10596
  if (profile === void 0) return false;
10539
10597
  return profile.authType !== "none";
10540
10598
  }
10541
10599
  function missingApiKeyMessage() {
10542
- const present = chunkQY3CIMUV_cjs.presentProviderCredentialEnvVars();
10600
+ const present = chunkP5N3Q2NH_cjs.presentProviderCredentialEnvVars();
10543
10601
  const base = `Missing API key \u2014 set ${chunk6LHQPOMI_cjs.API_KEY_ENV_VAR}, or pass \`apiKey\` to Agent.create()`;
10544
10602
  if (present.length === 0) return `${base}.`;
10545
10603
  return `${base}. ${present.join(" and ")} ${present.length === 1 ? "is" : "are"} set, but a provider credential is not read from the environment automatically \u2014 pass it explicitly, e.g. \`Agent.create({ apiKey: process.env.${present[0]}, ... })\`.`;
@@ -10559,7 +10617,7 @@ async function createLocalAgent(options) {
10559
10617
  }
10560
10618
  } else {
10561
10619
  const willFlowToProvider = keyWillFlowToProvider(apiKey, provider);
10562
- const shape = chunkQY3CIMUV_cjs.validateApiKeyShape(apiKey, {
10620
+ const shape = chunkP5N3Q2NH_cjs.validateApiKeyShape(apiKey, {
10563
10621
  strict: willFlowToProvider,
10564
10622
  ...willFlowToProvider ? { provider } : {}
10565
10623
  });
@@ -10578,15 +10636,15 @@ async function createCloudAgent(options) {
10578
10636
  code: "missing_api_key"
10579
10637
  });
10580
10638
  }
10581
- const shape = chunkQY3CIMUV_cjs.validateApiKeyShape(apiKey);
10639
+ const shape = chunkP5N3Q2NH_cjs.validateApiKeyShape(apiKey);
10582
10640
  if (shape.malformed) {
10583
10641
  throw new chunkUNFBHV46_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
10584
10642
  }
10585
- const baseUrl = chunkQY3CIMUV_cjs.getConfiguredBaseUrl();
10643
+ const baseUrl = chunkP5N3Q2NH_cjs.getConfiguredBaseUrl();
10586
10644
  if (baseUrl === void 0) {
10587
10645
  return new CloudAgent(options);
10588
10646
  }
10589
- const response = await chunkQY3CIMUV_cjs.httpRequest("/v1/agents", {
10647
+ const response = await chunkP5N3Q2NH_cjs.httpRequest("/v1/agents", {
10590
10648
  apiKey,
10591
10649
  method: "POST",
10592
10650
  body: {
@@ -10611,7 +10669,7 @@ function resolveAgentPersistenceCwd(options) {
10611
10669
  return process.cwd();
10612
10670
  }
10613
10671
  async function rehydrateExistingAgent(agentId, existing, options) {
10614
- await chunkQY3CIMUV_cjs.discoverProviderPlugins();
10672
+ await chunkP5N3Q2NH_cjs.discoverProviderPlugins();
10615
10673
  await validateRehydratedAgent(agentId, existing);
10616
10674
  const mergedLocal = options.local !== void 0 && existing.options.local !== void 0 ? { ...existing.options.local, ...options.local } : options.local ?? existing.options.local;
10617
10675
  const mergedMemory = mergeResumedMemory(existing.options.memory, options.memory);
@@ -10771,7 +10829,7 @@ var Agent = class _Agent {
10771
10829
  pluginCount: enabledPluginNames(options.plugins).length
10772
10830
  });
10773
10831
  try {
10774
- await chunkQY3CIMUV_cjs.discoverProviderPlugins();
10832
+ await chunkP5N3Q2NH_cjs.discoverProviderPlugins();
10775
10833
  const agent = await runCreateUnderSpan(options, span);
10776
10834
  return agent;
10777
10835
  } catch (err) {
@@ -11069,9 +11127,9 @@ var Agent = class _Agent {
11069
11127
  */
11070
11128
  static async compact(agentId, options = {}) {
11071
11129
  const reg = await requireLocalAgent(agentId, "compact");
11072
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-4QHBBGEY.cjs');
11130
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-Y56D3S57.cjs');
11073
11131
  const { cwd, model, store } = await openLocalStore(reg);
11074
- return chunkFR6COQXZ_cjs.enqueueSessionWrite(
11132
+ return chunk3JANYJYS_cjs.enqueueSessionWrite(
11075
11133
  cwd,
11076
11134
  agentId,
11077
11135
  () => compactSessionTranscript({
@@ -11099,7 +11157,7 @@ var Agent = class _Agent {
11099
11157
  */
11100
11158
  static async injectSessionTurn(agentId, turn) {
11101
11159
  const reg = await requireLocalAgent(agentId, "injectSessionTurn");
11102
- const { injectSessionTurn } = await import('./inject-session-OMLFL2V3.cjs');
11160
+ const { injectSessionTurn } = await import('./inject-session-R73PRM7B.cjs');
11103
11161
  const { cwd, model, store } = await openLocalStore(reg);
11104
11162
  await injectSessionTurn({
11105
11163
  store,
@@ -11270,5 +11328,5 @@ exports.managedSettingsPathFor = managedSettingsPathFor;
11270
11328
  exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
11271
11329
  exports.readManagedSettings = readManagedSettings;
11272
11330
  exports.resolveSessionDir = resolveSessionDir;
11273
- //# sourceMappingURL=chunk-CVEQ5366.cjs.map
11274
- //# sourceMappingURL=chunk-CVEQ5366.cjs.map
11331
+ //# sourceMappingURL=chunk-35KBC4BX.cjs.map
11332
+ //# sourceMappingURL=chunk-35KBC4BX.cjs.map