@theokit/sdk 4.39.0 → 4.39.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 (38) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/{agent-KKZYLY5D.js → agent-6ULDAQT7.js} +5 -5
  3. package/dist/{agent-KKZYLY5D.js.map → agent-6ULDAQT7.js.map} +1 -1
  4. package/dist/{agent-I3EZZR6S.cjs → agent-PVUKI3BB.cjs} +6 -6
  5. package/dist/{agent-I3EZZR6S.cjs.map → agent-PVUKI3BB.cjs.map} +1 -1
  6. package/dist/{chunk-E2FFG33C.js → chunk-7YSRCQDE.js} +3 -3
  7. package/dist/{chunk-E2FFG33C.js.map → chunk-7YSRCQDE.js.map} +1 -1
  8. package/dist/{chunk-INSFS5GT.cjs → chunk-CAFV7WPQ.cjs} +43 -43
  9. package/dist/{chunk-INSFS5GT.cjs.map → chunk-CAFV7WPQ.cjs.map} +1 -1
  10. package/dist/{chunk-BPN5ONSW.cjs → chunk-DAXEQELR.cjs} +8 -4
  11. package/dist/chunk-DAXEQELR.cjs.map +1 -0
  12. package/dist/{chunk-FRUBE44B.cjs → chunk-FOZC5H7V.cjs} +5 -5
  13. package/dist/{chunk-FRUBE44B.cjs.map → chunk-FOZC5H7V.cjs.map} +1 -1
  14. package/dist/{chunk-KWUNN5J2.js → chunk-GTVJIGAH.js} +3 -3
  15. package/dist/{chunk-KWUNN5J2.js.map → chunk-GTVJIGAH.js.map} +1 -1
  16. package/dist/{chunk-GIRD3RWH.js → chunk-H3BOKK42.js} +6 -6
  17. package/dist/{chunk-GIRD3RWH.js.map → chunk-H3BOKK42.js.map} +1 -1
  18. package/dist/{chunk-ZYB6B7QJ.js → chunk-HSPVMV6T.js} +6 -2
  19. package/dist/chunk-HSPVMV6T.js.map +1 -0
  20. package/dist/{chunk-DCXRHCZJ.cjs → chunk-VWI3CDEW.cjs} +3 -3
  21. package/dist/{chunk-DCXRHCZJ.cjs.map → chunk-VWI3CDEW.cjs.map} +1 -1
  22. package/dist/{compact-session-PYEC3NZV.js → compact-session-GKA7GFVT.js} +3 -3
  23. package/dist/{compact-session-PYEC3NZV.js.map → compact-session-GKA7GFVT.js.map} +1 -1
  24. package/dist/{compact-session-VVT6IBJG.cjs → compact-session-XMP6OGY3.cjs} +11 -11
  25. package/dist/{compact-session-VVT6IBJG.cjs.map → compact-session-XMP6OGY3.cjs.map} +1 -1
  26. package/dist/cron.cjs +5 -5
  27. package/dist/cron.js +4 -4
  28. package/dist/eval.cjs +4 -4
  29. package/dist/eval.js +3 -3
  30. package/dist/index.cjs +27 -27
  31. package/dist/index.js +6 -6
  32. package/dist/{inject-session-GQMTDZUN.js → inject-session-7P4CZGDT.js} +3 -3
  33. package/dist/{inject-session-GQMTDZUN.js.map → inject-session-7P4CZGDT.js.map} +1 -1
  34. package/dist/{inject-session-LFCYVSLJ.cjs → inject-session-CC4KBYF6.cjs} +4 -4
  35. package/dist/{inject-session-LFCYVSLJ.cjs.map → inject-session-CC4KBYF6.cjs.map} +1 -1
  36. package/package.json +1 -1
  37. package/dist/chunk-BPN5ONSW.cjs.map +0 -1
  38. package/dist/chunk-ZYB6B7QJ.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.39.1
4
+
5
+ ### Patch Changes
6
+
7
+ - A retry no longer runs silently: each attempt announces itself through the diagnostics channel.
8
+
9
+ Every attempt now emits its number and ceiling, the backoff it is about to wait, the error class, and
10
+ the provider's `Retry-After` when one arrived. Nothing is written unless a host installs a sink
11
+ (`setDiagnosticsSink`), so the default stays silent — a library does not own the host's terminal.
12
+
13
+ The bug this closes is not a missing retry. `RetryingLlmClient` already wraps every arm of the
14
+ router, and `RateLimitError` is already retryable with a ceiling of 3. The defect was that the retry
15
+ was _unobservable_: the backoff is full-jitter, so three attempts can complete inside milliseconds
16
+ and disappear into the response latency. Issue #165 is the cost, measured — a 429 was investigated on
17
+ the wrong hypothesis for hours, because the available evidence could not distinguish "retried three
18
+ times and failed" from "never retried".
19
+
20
+ ```ts
21
+ import { setDiagnosticsSink } from "@theokit/sdk";
22
+ setDiagnosticsSink((m) => process.stderr.write(m + "\n"));
23
+ ```
24
+
3
25
  ## 4.39.0
4
26
 
5
27
  ### Minor Changes
@@ -237,6 +259,32 @@
237
259
  what the loop consumes — previously it was produced and read by nobody, the same dead-channel shape
238
260
  this release deletes elsewhere.
239
261
 
262
+ ## 4.38.0
263
+
264
+ ### Minor Changes
265
+
266
+ - New `run.events()` — every event of a run in true order, from a single source (theokit#140).
267
+
268
+ A consumer that wanted both structural messages and live token granularity had to fuse two
269
+ incomplete views by hand: `stream()` carries no token deltas, and `SendOptions.onDelta` carries no
270
+ `run_started` / `system`. Reconciling them in the consumer is what produced the ordering and
271
+ duplication bugs this replaces.
272
+
273
+ `events()` returns an `AsyncGenerator<RunTimelineEvent>`, a discriminated union of
274
+ `{ kind: "message" }` and `{ kind: "delta" }` — not a widened `SDKMessage`, because a token delta
275
+ is not a message and pretending otherwise would force every consumer to guess which of the two it
276
+ is holding.
277
+
278
+ Minor rather than major: `stream()` is untouched and remains the SDKMessage-only view, `onDelta` is
279
+ wrapped rather than replaced, and every existing consumer observes no change.
280
+
281
+ `RunTimelineEvent` is exported from the package barrel.
282
+
283
+ > Entry reconstructed on 2026-08-05. The 4.38.0 release was cut by a hand-written version bump
284
+ > (`8beb61da6`) that changed `package.json` alone — no changeset, so this section never existed and
285
+ > the published version shipped without notes. The facts here come from the release commit and the
286
+ > exported type contract, not from a recovered changeset.
287
+
240
288
  ## 4.37.2
241
289
 
242
290
  ### Patch Changes
@@ -1,10 +1,10 @@
1
- export { Agent } from './chunk-GIRD3RWH.js';
1
+ export { Agent } from './chunk-H3BOKK42.js';
2
2
  import './chunk-2SFBB54R.js';
3
3
  import './chunk-LJX2SQV2.js';
4
4
  import './chunk-K2BQQ445.js';
5
- import './chunk-E2FFG33C.js';
5
+ import './chunk-7YSRCQDE.js';
6
6
  import './chunk-KGRIHEDT.js';
7
- import './chunk-ZYB6B7QJ.js';
7
+ import './chunk-HSPVMV6T.js';
8
8
  import './chunk-HWNVAUK4.js';
9
9
  import './chunk-5KOW3GLE.js';
10
10
  import './chunk-3I4B3OIX.js';
@@ -42,5 +42,5 @@ import './chunk-J3UK2GMN.js';
42
42
  import './chunk-AR5MQZ3J.js';
43
43
  import './chunk-SG5ZWT6C.js';
44
44
  import './chunk-IVSD7L22.js';
45
- //# sourceMappingURL=agent-KKZYLY5D.js.map
46
- //# sourceMappingURL=agent-KKZYLY5D.js.map
45
+ //# sourceMappingURL=agent-6ULDAQT7.js.map
46
+ //# sourceMappingURL=agent-6ULDAQT7.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-KKZYLY5D.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-6ULDAQT7.js"}
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkINSFS5GT_cjs = require('./chunk-INSFS5GT.cjs');
3
+ var chunkCAFV7WPQ_cjs = require('./chunk-CAFV7WPQ.cjs');
4
4
  require('./chunk-BV2MWEMV.cjs');
5
5
  require('./chunk-N475ETD6.cjs');
6
6
  require('./chunk-BUUUWQMB.cjs');
7
- require('./chunk-DCXRHCZJ.cjs');
7
+ require('./chunk-VWI3CDEW.cjs');
8
8
  require('./chunk-74D7KSBP.cjs');
9
- require('./chunk-BPN5ONSW.cjs');
9
+ require('./chunk-DAXEQELR.cjs');
10
10
  require('./chunk-ECW2MLEW.cjs');
11
11
  require('./chunk-BURYFNOM.cjs');
12
12
  require('./chunk-XYOHKCYG.cjs');
@@ -49,7 +49,7 @@ require('./chunk-BCQ3E2ZG.cjs');
49
49
 
50
50
  Object.defineProperty(exports, "Agent", {
51
51
  enumerable: true,
52
- get: function () { return chunkINSFS5GT_cjs.Agent; }
52
+ get: function () { return chunkCAFV7WPQ_cjs.Agent; }
53
53
  });
54
- //# sourceMappingURL=agent-I3EZZR6S.cjs.map
55
- //# sourceMappingURL=agent-I3EZZR6S.cjs.map
54
+ //# sourceMappingURL=agent-PVUKI3BB.cjs.map
55
+ //# sourceMappingURL=agent-PVUKI3BB.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-I3EZZR6S.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-PVUKI3BB.cjs"}
@@ -46,7 +46,7 @@ function persistTurnToTranscript(store, loc, sessionId, turn, onCompact) {
46
46
  const count = (recordCounts.get(key) ?? 0) + 1;
47
47
  recordCounts.set(key, count);
48
48
  if (turn.autoCompact !== void 0) {
49
- const { autoCompactIfNeeded } = await import('./compact-session-PYEC3NZV.js');
49
+ const { autoCompactIfNeeded } = await import('./compact-session-GKA7GFVT.js');
50
50
  const fired = await autoCompactIfNeeded({
51
51
  store,
52
52
  loc,
@@ -105,5 +105,5 @@ function enqueueSessionWrite(cwd, agentId, fn) {
105
105
  }
106
106
 
107
107
  export { appendSessionMessage, clearSession, discardSession, enqueueSessionWrite, flushSessionWrites, getSessionMessages, hydrateSession, persistTurnToTranscript };
108
- //# sourceMappingURL=chunk-E2FFG33C.js.map
109
- //# sourceMappingURL=chunk-E2FFG33C.js.map
108
+ //# sourceMappingURL=chunk-7YSRCQDE.js.map
109
+ //# sourceMappingURL=chunk-7YSRCQDE.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/internal/session/agent-session.ts"],"names":[],"mappings":";;;;;AAwCA,IAAM,aAAA,uBAAoB,GAAA,EAA2B;AACrD,IAAM,YAAA,uBAAmB,GAAA,EAAoB;AAStC,SAAS,oBAAA,CAAqB,SAAiB,OAAA,EAA+B;AACnF,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,GAAA,CAAI,OAAO,KAAK,EAAC;AAC3C,EAAA,QAAA,CAAS,KAAK,OAAO,CAAA;AAIrB,EAAA,QAAA,CAAS,OAAO,OAAO,CAAA;AACvB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,EACA,OAAA,EACA,EAAA,EACY;AACZ,EAAA,MAAM,GAAA,GAAM,aAAA,CAAc,GAAA,EAAK,OAAO,CAAA;AACtC,EAAA,MAAM,QAAQ,aAAA,CAAc,GAAA,CAAI,GAAG,CAAA,IAAK,QAAQ,OAAA,EAAQ;AACxD,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,IAAA,CAAK,EAAE,CAAA;AAC5B,EAAA,aAAA,CAAc,GAAA;AAAA,IACZ,GAAA;AAAA,IACA,MAAA,CAAO,IAAA;AAAA,MACL,MAAM,MAAA;AAAA,MACN,MAAM;AAAA;AACR,GACF;AACA,EAAA,OAAO,MAAA;AACT","file":"chunk-E2FFG33C.js","sourcesContent":["import type { SessionStore } from \"../../types/session-store.js\";\nimport {\n type PersistTurnInput,\n persistTurn,\n readSessionMessages,\n type TranscriptLocation,\n} from \"./agent-session-store.js\";\n\n/**\n * Per-agent conversation history kept across runs (and across `Agent.resume()`\n * within the same process). Lets the fixture responder recall prior facts when\n * the user asks a follow-up question.\n *\n * SE40 — disk persistence IS the native Claude-shaped `.jsonl` transcript. The\n * in-memory cache holds the narrowed `SessionMessage[]` (user/assistant text) so\n * a send can read `priorMessages` synchronously; the whole rich turn (user +\n * assistant + tool blocks) lands on disk once per send via {@link persistTurnToTranscript}\n * (fed by `run.conversation()`). Hydration on resume reconstructs the session by\n * walking the transcript DAG (`readSessionMessages`).\n *\n * @internal\n */\n\n// `SessionMessage` lives in `./session-types.ts` (leaf types file). Re-exported\n// for back-compat with downstream importers that pulled it from here.\nexport type { SessionMessage } from \"./session-types.js\";\n\nimport type { SessionMessage } from \"./session-types.js\";\n\n// M75 — the cache lives in a leaf; see session-cache.ts for the reason (cycle broken by extraction).\nexport {\n hydratedKeys,\n invalidateSessionCache,\n sessions,\n transcriptKey,\n} from \"./session-cache.js\";\n\nimport { diag } from \"../diagnostics.js\";\nimport { hydratedKeys, sessions, transcriptKey } from \"./session-cache.js\";\n\nconst pendingWrites = new Map<string, Promise<void>>();\nconst recordCounts = new Map<string, number>();\n\n/**\n * Append a session message to the in-memory cache only. Disk persistence for the\n * whole turn happens once per send via {@link persistTurnToTranscript}; the cache\n * feeds `priorMessages` / `onBeforeSend.previousMessageCount` synchronously.\n *\n * @internal\n */\nexport function appendSessionMessage(agentId: string, message: SessionMessage): void {\n const existing = sessions.get(agentId) ?? [];\n existing.push(message);\n // `delete` + `set` reinserts at the END: a JS `Map` preserves insertion order, so the first key\n // is always the least recently touched. That is the entire LRU, with no new structure (parsimony\n // rungs 2/5 — the ordering we need is already a language guarantee).\n sessions.delete(agentId);\n sessions.set(agentId, existing);\n enforceCeiling();\n}\n\n/**\n * Ceiling on sessions kept in memory.\n *\n * The runtime only reads the **active** session; the rest is pure cache, rebuildable from the\n * on-disk transcript. 32 is deliberately generous — the primary removal path is the explicit\n * `discardSession()` at the end of the agent's life, and this ceiling is a safety net against a\n * long-lived process running hundreds of sessions (plan risk #2: a tight ceiling could evict a\n * session still referenced by an in-flight async path).\n */\nexport const MAX_CACHED_SESSIONS = 32;\n\nfunction enforceCeiling(): void {\n while (sessions.size > MAX_CACHED_SESSIONS) {\n const maisAntiga = sessions.keys().next().value;\n if (maisAntiga === undefined) return;\n sessions.delete(maisAntiga);\n esquecerEscrituracao(maisAntiga);\n }\n}\n\n/**\n * Erases the bookkeeping for an `agentId` across EVERY `cwd` it appears in.\n *\n * The three maps are keyed by `transcriptKey(cwd, agentId)`; `sessions` is the only one keyed by the\n * raw `agentId`. The ceiling's first version deleted from all three using `sessions`' key — that is,\n * deleted nothing — and left `hydratedKeys` **orphaned**. Since `hydrateSession` returns early when\n * the marker is present, an evicted session came back **empty** instead of rehydrating from disk:\n * silent amnesia, and a regression new to M95, because before it nothing evicted.\n *\n * The ceiling only knows the `agentId`, not the `cwd`, so it scans by suffix — which is the format\n * `transcriptKey` produces. A scan rather than an index because these maps hold tens of entries, not\n * thousands: a reverse index here would be new structure for a problem that does not exist.\n */\nfunction esquecerEscrituracao(agentId: string): void {\n const sufixo = transcriptKey(\"\", agentId).slice(0 - agentId.length - 2);\n for (const k of [...hydratedKeys]) if (k.endsWith(sufixo)) hydratedKeys.delete(k);\n for (const k of [...pendingWrites.keys()]) if (k.endsWith(sufixo)) pendingWrites.delete(k);\n for (const k of [...recordCounts.keys()]) if (k.endsWith(sufixo)) recordCounts.delete(k);\n}\n\n/**\n * Erases the agent's module bookkeeping and returns how many entries were removed.\n *\n * M95 — `invalidateSessionCache` limpava **dois** dos quatro mapas (`sessions`, `hydratedKeys`);\n * `pendingWrites` and `recordCounts` were never touched by id, so they grew for the life of the\n * process. Neither is large per entry — the leak is in count, not volume — but a cache with no owner\n * for removal is a cache that only grows.\n *\n * Returns the count so the caller can prove the removal; a second discard returns 0, which is what\n * makes the idempotency test possible without exposing the maps.\n */\nexport function discardSession(cwd: string, agentId: string): number {\n const key = transcriptKey(cwd, agentId);\n let removed = 0;\n // `sessions` is NOT erased here — and the distinction is measured, not aesthetic. It holds the\n // readable conversation, and there is a legitimate reader AFTER dispose: the golden\n // `two-concurrent-sends-serialize` calls `getSessionMessages(agentId)` after `agent.dispose()`.\n // Erasing it here returned an empty list and broke two goldens. What bounds it is the LRU ceiling\n // above; the three below are pure bookkeeping, with no post-dispose reader.\n //\n // The key is `transcriptKey(cwd, agentId)` in ALL THREE — not the raw `agentId`. The first version\n // erased two of them by `agentId` and therefore **never erased anything**; the test did not catch\n // it because it only asserted that the SECOND call returns 0, which is true either way.\n if (hydratedKeys.delete(key)) removed++;\n if (pendingWrites.delete(key)) removed++;\n if (recordCounts.delete(key)) removed++;\n return removed;\n}\n\nexport function getSessionMessages(agentId: string): SessionMessage[] {\n return sessions.get(agentId) ?? [];\n}\n\n/**\n * Persist a full conversation turn (user + assistant + tool blocks) to the native\n * transcript. Chained per-(agent, transcript) so on-disk order matches send order,\n * and fire-and-forget so `send()` is not blocked by disk I/O. Every\n * M50 — when the caller supplies `turn.autoCompact`, size-driven auto-compaction (usage real vs\n * the model's context window) runs in this same chain, surfaced via the optional `onCompact` observer.\n *\n * @internal\n */\nexport function persistTurnToTranscript(\n store: SessionStore,\n loc: TranscriptLocation,\n sessionId: string,\n turn: PersistTurnInput,\n onCompact?: () => void,\n): void {\n const key = transcriptKey(loc.cwd, loc.agentId);\n // PRE-EXISTING debt, exposed when M75 fixed the Biome config that used to abort before\n // sweeping these files (a nested root under refactor/). It is not new code and was not touched\n // by M75; refactoring SDK internals without review would trade a visible problem for a diff\n // arriscado. Rastreado em usetheodev/theokit-sdk#151.\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: see the reason just above\n const chained = (pendingWrites.get(key) ?? Promise.resolve()).then(async () => {\n try {\n await persistTurn(store, loc, sessionId, turn);\n const count = (recordCounts.get(key) ?? 0) + 1;\n recordCounts.set(key, count);\n // M50 — the 50-turn no-summary boundary stub is GONE (it silently amnesia'd the session).\n // Auto-compaction is now size-driven with a real summary: see `maybeAutoCompact` below,\n // invoked in this same write chain by the post-run lifecycle when usage is known.\n if (turn.autoCompact !== undefined) {\n const { autoCompactIfNeeded } = await import(\"./compact-session.js\");\n const fired = await autoCompactIfNeeded({\n store,\n loc,\n sessionId,\n usageTotal: turn.autoCompact.usageTotal,\n contextWindow: turn.autoCompact.contextWindow,\n turnCount: count,\n summarize: turn.autoCompact.summarize,\n });\n if (fired) onCompact?.();\n }\n } catch (cause) {\n const msg = cause instanceof Error ? cause.message : String(cause);\n diag(`[theokit-sdk] session transcript write failed (${loc.agentId}): ${msg}\\n`);\n }\n });\n pendingWrites.set(\n key,\n chained.then(\n () => undefined,\n () => undefined,\n ),\n );\n}\n\n/**\n * Load the persisted transcript into the in-memory cache. Idempotent per\n * (baseDir, cwd, agentId). Call once per agent lifecycle before the first read.\n *\n * @internal\n */\nexport async function hydrateSession(\n agentId: string,\n loc: { store: SessionStore; cwd: string },\n): Promise<void> {\n const key = transcriptKey(loc.cwd, agentId);\n if (hydratedKeys.has(key)) return;\n hydratedKeys.add(key);\n\n const persisted = await readSessionMessages(loc.store, agentId);\n if (persisted.length === 0) return;\n // M51 review F4 — the DISK is the source of truth at hydration time: after an invalidation\n // (compact/inject), an in-flight turn may have repopulated the cache with a SINGLE message before\n // this hydrate ran; the old \"skip when non-empty\" guard then pinned the parent to a 1-message\n // context (history + injected pair lost until restart). The persist chain serializes writes, so\n // the disk already contains that in-flight turn — replacing is always correct.\n sessions.set(agentId, persisted);\n}\n\n/**\n * Wait for all pending transcript writes to settle. Used by tests and by the\n * agent dispose path so on-disk state matches in-memory before the caller proceeds.\n *\n * @internal\n */\nexport async function flushSessionWrites(): Promise<void> {\n while (pendingWrites.size > 0) {\n const all = Array.from(pendingWrites.values());\n pendingWrites.clear();\n await Promise.all(all);\n }\n}\n\nexport function clearSession(agentId: string): void {\n sessions.delete(agentId);\n}\n\n/**\n * M50 review F1 — drop BOTH the message cache and the hydration marker so the NEXT send re-hydrates\n * from disk. Without this, a compaction only helps after a process restart: the live process keeps\n * sending the full pre-compact history (the cache is read synchronously by every send).\n */\n/**\n * M50 review F5 — run `fn` serialized on the SAME per-(cwd,agentId) write chain the per-turn\n * persistence uses, so a manual `Agent.compact` can never interleave with an in-flight turn's\n * writes (boundary landing mid-turn would orphan the turn from the replay).\n */\nexport function enqueueSessionWrite<T>(\n cwd: string,\n agentId: string,\n fn: () => Promise<T>,\n): Promise<T> {\n const key = transcriptKey(cwd, agentId);\n const prior = pendingWrites.get(key) ?? Promise.resolve();\n const result = prior.then(fn);\n pendingWrites.set(\n key,\n result.then(\n () => undefined,\n () => undefined,\n ),\n );\n return result;\n}\n\n/** Test-only: drop every cached session and hydration marker. @internal */\nexport function clearAllSessions(): void {\n sessions.clear();\n hydratedKeys.clear();\n recordCounts.clear();\n // M50 review F11 — the auto-compact attempt marks live on globalThis; tests reset them here.\n const g = globalThis as unknown as Record<symbol, Map<string, number>>;\n const sym = Symbol.for(\"theokit-sdk.session.auto-compact-attempts\");\n g[sym]?.clear();\n}\n"]}
1
+ {"version":3,"sources":["../src/internal/session/agent-session.ts"],"names":[],"mappings":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AAG;AAC7B,IAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,aAAA,CAAc,QAAQ,CAAA;AAC7C,IAAA,aAAA,CAAc,KAAA,EAAM;AACpB,IAAA,MAAM,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,EACvB;AACF;AAEO,SAAS,aAAa,OAAA,EAAuB;AAClD,EAAA,QAAA,CAAS,OAAO,OAAO,CAAA;AACzB;AAYO,SAAS,mBAAA,CACd,GAAA,EACA,OAAA,EACA,EAAA,EACY;AACZ,EAAA,MAAM,GAAA,GAAM,aAAA,CAAc,GAAA,EAAK,OAAO,CAAA;AACtC,EAAA,MAAM,QAAQ,aAAA,CAAc,GAAA,CAAI,GAAG,CAAA,IAAK,QAAQ,OAAA,EAAQ;AACxD,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,IAAA,CAAK,EAAE,CAAA;AAC5B,EAAA,aAAA,CAAc,GAAA;AAAA,IACZ,GAAA;AAAA,IACA,MAAA,CAAO,IAAA;AAAA,MACL,MAAM,MAAA;AAAA,MACN,MAAM;AAAA;AACR,GACF;AACA,EAAA,OAAO,MAAA;AACT","file":"chunk-7YSRCQDE.js","sourcesContent":["import type { SessionStore } from \"../../types/session-store.js\";\nimport {\n type PersistTurnInput,\n persistTurn,\n readSessionMessages,\n type TranscriptLocation,\n} from \"./agent-session-store.js\";\n\n/**\n * Per-agent conversation history kept across runs (and across `Agent.resume()`\n * within the same process). Lets the fixture responder recall prior facts when\n * the user asks a follow-up question.\n *\n * SE40 — disk persistence IS the native Claude-shaped `.jsonl` transcript. The\n * in-memory cache holds the narrowed `SessionMessage[]` (user/assistant text) so\n * a send can read `priorMessages` synchronously; the whole rich turn (user +\n * assistant + tool blocks) lands on disk once per send via {@link persistTurnToTranscript}\n * (fed by `run.conversation()`). Hydration on resume reconstructs the session by\n * walking the transcript DAG (`readSessionMessages`).\n *\n * @internal\n */\n\n// `SessionMessage` lives in `./session-types.ts` (leaf types file). Re-exported\n// for back-compat with downstream importers that pulled it from here.\nexport type { SessionMessage } from \"./session-types.js\";\n\nimport type { SessionMessage } from \"./session-types.js\";\n\n// M75 — the cache lives in a leaf; see session-cache.ts for the reason (cycle broken by extraction).\nexport {\n hydratedKeys,\n invalidateSessionCache,\n sessions,\n transcriptKey,\n} from \"./session-cache.js\";\n\nimport { diag } from \"../diagnostics.js\";\nimport { hydratedKeys, sessions, transcriptKey } from \"./session-cache.js\";\n\nconst pendingWrites = new Map<string, Promise<void>>();\nconst recordCounts = new Map<string, number>();\n\n/**\n * Append a session message to the in-memory cache only. Disk persistence for the\n * whole turn happens once per send via {@link persistTurnToTranscript}; the cache\n * feeds `priorMessages` / `onBeforeSend.previousMessageCount` synchronously.\n *\n * @internal\n */\nexport function appendSessionMessage(agentId: string, message: SessionMessage): void {\n const existing = sessions.get(agentId) ?? [];\n existing.push(message);\n // `delete` + `set` reinserts at the END: a JS `Map` preserves insertion order, so the first key\n // is always the least recently touched. That is the entire LRU, with no new structure (parsimony\n // rungs 2/5 — the ordering we need is already a language guarantee).\n sessions.delete(agentId);\n sessions.set(agentId, existing);\n enforceCeiling();\n}\n\n/**\n * Ceiling on sessions kept in memory.\n *\n * The runtime only reads the **active** session; the rest is pure cache, rebuildable from the\n * on-disk transcript. 32 is deliberately generous — the primary removal path is the explicit\n * `discardSession()` at the end of the agent's life, and this ceiling is a safety net against a\n * long-lived process running hundreds of sessions (plan risk #2: a tight ceiling could evict a\n * session still referenced by an in-flight async path).\n */\nexport const MAX_CACHED_SESSIONS = 32;\n\nfunction enforceCeiling(): void {\n while (sessions.size > MAX_CACHED_SESSIONS) {\n const maisAntiga = sessions.keys().next().value;\n if (maisAntiga === undefined) return;\n sessions.delete(maisAntiga);\n esquecerEscrituracao(maisAntiga);\n }\n}\n\n/**\n * Erases the bookkeeping for an `agentId` across EVERY `cwd` it appears in.\n *\n * The three maps are keyed by `transcriptKey(cwd, agentId)`; `sessions` is the only one keyed by the\n * raw `agentId`. The ceiling's first version deleted from all three using `sessions`' key — that is,\n * deleted nothing — and left `hydratedKeys` **orphaned**. Since `hydrateSession` returns early when\n * the marker is present, an evicted session came back **empty** instead of rehydrating from disk:\n * silent amnesia, and a regression new to M95, because before it nothing evicted.\n *\n * The ceiling only knows the `agentId`, not the `cwd`, so it scans by suffix — which is the format\n * `transcriptKey` produces. A scan rather than an index because these maps hold tens of entries, not\n * thousands: a reverse index here would be new structure for a problem that does not exist.\n */\nfunction esquecerEscrituracao(agentId: string): void {\n const sufixo = transcriptKey(\"\", agentId).slice(0 - agentId.length - 2);\n for (const k of [...hydratedKeys]) if (k.endsWith(sufixo)) hydratedKeys.delete(k);\n for (const k of [...pendingWrites.keys()]) if (k.endsWith(sufixo)) pendingWrites.delete(k);\n for (const k of [...recordCounts.keys()]) if (k.endsWith(sufixo)) recordCounts.delete(k);\n}\n\n/**\n * Erases the agent's module bookkeeping and returns how many entries were removed.\n *\n * M95 — `invalidateSessionCache` limpava **dois** dos quatro mapas (`sessions`, `hydratedKeys`);\n * `pendingWrites` and `recordCounts` were never touched by id, so they grew for the life of the\n * process. Neither is large per entry — the leak is in count, not volume — but a cache with no owner\n * for removal is a cache that only grows.\n *\n * Returns the count so the caller can prove the removal; a second discard returns 0, which is what\n * makes the idempotency test possible without exposing the maps.\n */\nexport function discardSession(cwd: string, agentId: string): number {\n const key = transcriptKey(cwd, agentId);\n let removed = 0;\n // `sessions` is NOT erased here — and the distinction is measured, not aesthetic. It holds the\n // readable conversation, and there is a legitimate reader AFTER dispose: the golden\n // `two-concurrent-sends-serialize` calls `getSessionMessages(agentId)` after `agent.dispose()`.\n // Erasing it here returned an empty list and broke two goldens. What bounds it is the LRU ceiling\n // above; the three below are pure bookkeeping, with no post-dispose reader.\n //\n // The key is `transcriptKey(cwd, agentId)` in ALL THREE — not the raw `agentId`. The first version\n // erased two of them by `agentId` and therefore **never erased anything**; the test did not catch\n // it because it only asserted that the SECOND call returns 0, which is true either way.\n if (hydratedKeys.delete(key)) removed++;\n if (pendingWrites.delete(key)) removed++;\n if (recordCounts.delete(key)) removed++;\n return removed;\n}\n\nexport function getSessionMessages(agentId: string): SessionMessage[] {\n return sessions.get(agentId) ?? [];\n}\n\n/**\n * Persist a full conversation turn (user + assistant + tool blocks) to the native\n * transcript. Chained per-(agent, transcript) so on-disk order matches send order,\n * and fire-and-forget so `send()` is not blocked by disk I/O. Every\n * M50 — when the caller supplies `turn.autoCompact`, size-driven auto-compaction (usage real vs\n * the model's context window) runs in this same chain, surfaced via the optional `onCompact` observer.\n *\n * @internal\n */\nexport function persistTurnToTranscript(\n store: SessionStore,\n loc: TranscriptLocation,\n sessionId: string,\n turn: PersistTurnInput,\n onCompact?: () => void,\n): void {\n const key = transcriptKey(loc.cwd, loc.agentId);\n // PRE-EXISTING debt, exposed when M75 fixed the Biome config that used to abort before\n // sweeping these files (a nested root under refactor/). It is not new code and was not touched\n // by M75; refactoring SDK internals without review would trade a visible problem for a diff\n // arriscado. Rastreado em usetheodev/theokit-sdk#151.\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: see the reason just above\n const chained = (pendingWrites.get(key) ?? Promise.resolve()).then(async () => {\n try {\n await persistTurn(store, loc, sessionId, turn);\n const count = (recordCounts.get(key) ?? 0) + 1;\n recordCounts.set(key, count);\n // M50 — the 50-turn no-summary boundary stub is GONE (it silently amnesia'd the session).\n // Auto-compaction is now size-driven with a real summary: see `maybeAutoCompact` below,\n // invoked in this same write chain by the post-run lifecycle when usage is known.\n if (turn.autoCompact !== undefined) {\n const { autoCompactIfNeeded } = await import(\"./compact-session.js\");\n const fired = await autoCompactIfNeeded({\n store,\n loc,\n sessionId,\n usageTotal: turn.autoCompact.usageTotal,\n contextWindow: turn.autoCompact.contextWindow,\n turnCount: count,\n summarize: turn.autoCompact.summarize,\n });\n if (fired) onCompact?.();\n }\n } catch (cause) {\n const msg = cause instanceof Error ? cause.message : String(cause);\n diag(`[theokit-sdk] session transcript write failed (${loc.agentId}): ${msg}\\n`);\n }\n });\n pendingWrites.set(\n key,\n chained.then(\n () => undefined,\n () => undefined,\n ),\n );\n}\n\n/**\n * Load the persisted transcript into the in-memory cache. Idempotent per\n * (baseDir, cwd, agentId). Call once per agent lifecycle before the first read.\n *\n * @internal\n */\nexport async function hydrateSession(\n agentId: string,\n loc: { store: SessionStore; cwd: string },\n): Promise<void> {\n const key = transcriptKey(loc.cwd, agentId);\n if (hydratedKeys.has(key)) return;\n hydratedKeys.add(key);\n\n const persisted = await readSessionMessages(loc.store, agentId);\n if (persisted.length === 0) return;\n // M51 review F4 — the DISK is the source of truth at hydration time: after an invalidation\n // (compact/inject), an in-flight turn may have repopulated the cache with a SINGLE message before\n // this hydrate ran; the old \"skip when non-empty\" guard then pinned the parent to a 1-message\n // context (history + injected pair lost until restart). The persist chain serializes writes, so\n // the disk already contains that in-flight turn — replacing is always correct.\n sessions.set(agentId, persisted);\n}\n\n/**\n * Wait for all pending transcript writes to settle. Used by tests and by the\n * agent dispose path so on-disk state matches in-memory before the caller proceeds.\n *\n * @internal\n */\nexport async function flushSessionWrites(): Promise<void> {\n while (pendingWrites.size > 0) {\n const all = Array.from(pendingWrites.values());\n pendingWrites.clear();\n await Promise.all(all);\n }\n}\n\nexport function clearSession(agentId: string): void {\n sessions.delete(agentId);\n}\n\n/**\n * M50 review F1 — drop BOTH the message cache and the hydration marker so the NEXT send re-hydrates\n * from disk. Without this, a compaction only helps after a process restart: the live process keeps\n * sending the full pre-compact history (the cache is read synchronously by every send).\n */\n/**\n * M50 review F5 — run `fn` serialized on the SAME per-(cwd,agentId) write chain the per-turn\n * persistence uses, so a manual `Agent.compact` can never interleave with an in-flight turn's\n * writes (boundary landing mid-turn would orphan the turn from the replay).\n */\nexport function enqueueSessionWrite<T>(\n cwd: string,\n agentId: string,\n fn: () => Promise<T>,\n): Promise<T> {\n const key = transcriptKey(cwd, agentId);\n const prior = pendingWrites.get(key) ?? Promise.resolve();\n const result = prior.then(fn);\n pendingWrites.set(\n key,\n result.then(\n () => undefined,\n () => undefined,\n ),\n );\n return result;\n}\n\n/** Test-only: drop every cached session and hydration marker. @internal */\nexport function clearAllSessions(): void {\n sessions.clear();\n hydratedKeys.clear();\n recordCounts.clear();\n // M50 review F11 — the auto-compact attempt marks live on globalThis; tests reset them here.\n const g = globalThis as unknown as Record<symbol, Map<string, number>>;\n const sym = Symbol.for(\"theokit-sdk.session.auto-compact-attempts\");\n g[sym]?.clear();\n}\n"]}
@@ -2,9 +2,9 @@
2
2
 
3
3
  var chunkBV2MWEMV_cjs = require('./chunk-BV2MWEMV.cjs');
4
4
  var chunkN475ETD6_cjs = require('./chunk-N475ETD6.cjs');
5
- var chunkDCXRHCZJ_cjs = require('./chunk-DCXRHCZJ.cjs');
5
+ var chunkVWI3CDEW_cjs = require('./chunk-VWI3CDEW.cjs');
6
6
  var chunk74D7KSBP_cjs = require('./chunk-74D7KSBP.cjs');
7
- var chunkBPN5ONSW_cjs = require('./chunk-BPN5ONSW.cjs');
7
+ var chunkDAXEQELR_cjs = require('./chunk-DAXEQELR.cjs');
8
8
  var chunkCN6UX5EV_cjs = require('./chunk-CN6UX5EV.cjs');
9
9
  var chunk6LGQECT7_cjs = require('./chunk-6LGQECT7.cjs');
10
10
  var chunkWPZTYOUX_cjs = require('./chunk-WPZTYOUX.cjs');
@@ -1616,7 +1616,7 @@ function createRealCloudRun(options) {
1616
1616
  conversation: []
1617
1617
  };
1618
1618
  const apiKey = resolveApiKey(options.agentOptions.apiKey);
1619
- const baseUrl = chunkBPN5ONSW_cjs.getConfiguredBaseUrl();
1619
+ const baseUrl = chunkDAXEQELR_cjs.getConfiguredBaseUrl();
1620
1620
  const handle = new RealCloudRun(
1621
1621
  {
1622
1622
  id,
@@ -1699,7 +1699,7 @@ var RealCloudRun = class extends FixtureRunBase {
1699
1699
  async consumeStream(response) {
1700
1700
  let finalStatus = "finished";
1701
1701
  let finalText = "";
1702
- for await (const record of chunkBPN5ONSW_cjs.parseSseStream(response.body, this.controller.signal)) {
1702
+ for await (const record of chunkDAXEQELR_cjs.parseSseStream(response.body, this.controller.signal)) {
1703
1703
  const parsed = safeParse(record.data);
1704
1704
  if (parsed === void 0) continue;
1705
1705
  const update = this.applyRecord(record.event, parsed);
@@ -1808,7 +1808,7 @@ var CloudAgent = class {
1808
1808
  */
1809
1809
  isFixtureMode() {
1810
1810
  const apiKey = resolveApiKey(this.options.apiKey);
1811
- return chunkBPN5ONSW_cjs.isFixtureApiKey(apiKey) && chunkBPN5ONSW_cjs.getConfiguredBaseUrl() === void 0;
1811
+ return chunkDAXEQELR_cjs.isFixtureApiKey(apiKey) && chunkDAXEQELR_cjs.getConfiguredBaseUrl() === void 0;
1812
1812
  }
1813
1813
  // SE9 — integrated structured output; delegates to the shared helper.
1814
1814
  generate(message, options) {
@@ -1859,7 +1859,7 @@ var CloudAgent = class {
1859
1859
  const userText = typeof message === "string" ? message : message.text;
1860
1860
  const systemPrompt = await this.resolveSystemPromptForSend(userText, options);
1861
1861
  const apiKey = resolveApiKey(this.options.apiKey);
1862
- const useRealRuntime = apiKey !== void 0 && !chunkBPN5ONSW_cjs.isFixtureApiKey(apiKey) && chunkBPN5ONSW_cjs.getConfiguredBaseUrl() !== void 0;
1862
+ const useRealRuntime = apiKey !== void 0 && !chunkDAXEQELR_cjs.isFixtureApiKey(apiKey) && chunkDAXEQELR_cjs.getConfiguredBaseUrl() !== void 0;
1863
1863
  return useRealRuntime ? createRealCloudRun({
1864
1864
  agentId: this.agentId,
1865
1865
  model: this.model ?? { id: DEFAULT_AGENTIC_MODEL_ID },
@@ -2679,7 +2679,7 @@ async function runPostRunLifecycle(inputs) {
2679
2679
  try {
2680
2680
  const parcial = await safeConversation(run);
2681
2681
  if (parcial !== void 0) {
2682
- chunkDCXRHCZJ_cjs.persistTurnToTranscript(sessionStore, { cwd: workspaceCwd, agentId, model }, agentId, {
2682
+ chunkVWI3CDEW_cjs.persistTurnToTranscript(sessionStore, { cwd: workspaceCwd, agentId, model }, agentId, {
2683
2683
  userText,
2684
2684
  conversation: parcial
2685
2685
  });
@@ -2689,11 +2689,11 @@ async function runPostRunLifecycle(inputs) {
2689
2689
  chunkBCQ3E2ZG_cjs.diag(`[theokit-sdk] partial transcript write failed (${agentId}): ${msg}
2690
2690
  `);
2691
2691
  }
2692
- await chunkDCXRHCZJ_cjs.flushSessionWrites();
2692
+ await chunkVWI3CDEW_cjs.flushSessionWrites();
2693
2693
  return;
2694
2694
  }
2695
2695
  if (result.result !== void 0) {
2696
- chunkDCXRHCZJ_cjs.appendSessionMessage(agentId, { role: "assistant", text: result.result });
2696
+ chunkVWI3CDEW_cjs.appendSessionMessage(agentId, { role: "assistant", text: result.result });
2697
2697
  }
2698
2698
  const conversation = await safeConversation(run);
2699
2699
  const resolvedWindow = resolveWindowForRun(model, contextWindow);
@@ -2704,7 +2704,7 @@ async function runPostRunLifecycle(inputs) {
2704
2704
  }
2705
2705
  const lastRequestUsage = result.usage?.requests?.at(-1)?.totalTokens;
2706
2706
  const usageForTrigger = lastRequestUsage ?? result.usage?.totalTokens;
2707
- chunkDCXRHCZJ_cjs.persistTurnToTranscript(
2707
+ chunkVWI3CDEW_cjs.persistTurnToTranscript(
2708
2708
  sessionStore,
2709
2709
  { cwd: workspaceCwd, agentId, model },
2710
2710
  agentId,
@@ -2716,7 +2716,7 @@ async function runPostRunLifecycle(inputs) {
2716
2716
  // The EFFECTIVE window (after override, clamp and margin) — not the declared one. Swapping for
2717
2717
  // `contextWindow` here would budget against a number the clamp already rejected.
2718
2718
  contextWindow: effectiveWindow,
2719
- summarize: chunkBPN5ONSW_cjs.buildDefaultSummarizer({
2719
+ summarize: chunkDAXEQELR_cjs.buildDefaultSummarizer({
2720
2720
  agentModel: model,
2721
2721
  ...inputs.apiKey !== void 0 ? { apiKey: inputs.apiKey } : {}
2722
2722
  })
@@ -2758,7 +2758,7 @@ async function runPostRunLifecycle(inputs) {
2758
2758
  agentId,
2759
2759
  runId: result.id
2760
2760
  });
2761
- await chunkDCXRHCZJ_cjs.flushSessionWrites();
2761
+ await chunkVWI3CDEW_cjs.flushSessionWrites();
2762
2762
  }
2763
2763
  async function safeConversation(run) {
2764
2764
  try {
@@ -3345,7 +3345,7 @@ var HISTOGRAM_NAMES = {
3345
3345
  };
3346
3346
  function safeRequire(moduleName) {
3347
3347
  try {
3348
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-INSFS5GT.cjs', document.baseURI).href)));
3348
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-CAFV7WPQ.cjs', document.baseURI).href)));
3349
3349
  return r(moduleName);
3350
3350
  } catch {
3351
3351
  return void 0;
@@ -3570,7 +3570,7 @@ var cachedOtel;
3570
3570
  function loadOtel() {
3571
3571
  if (cachedOtel === void 0) {
3572
3572
  try {
3573
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-INSFS5GT.cjs', document.baseURI).href)));
3573
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-CAFV7WPQ.cjs', document.baseURI).href)));
3574
3574
  const mod = r("@opentelemetry/api");
3575
3575
  cachedOtel = mod;
3576
3576
  } catch {
@@ -6078,7 +6078,7 @@ function applyToolResultGuard(parts, opts) {
6078
6078
  (p) => (
6079
6079
  // SE7 — guard the TEXT of a tool result (string or the text blocks of a
6080
6080
  // structured content); image blocks pass through untouched.
6081
- p.type === "tool_result" ? { ...p, content: chunkBPN5ONSW_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
6081
+ p.type === "tool_result" ? { ...p, content: chunkDAXEQELR_cjs.renderToolResultContentText(p.content, (t) => guardText(t, opts)) } : p
6082
6082
  )
6083
6083
  );
6084
6084
  }
@@ -6738,12 +6738,12 @@ var FallbackLlmClient = class {
6738
6738
  let lastError;
6739
6739
  for (const client of this.clients) {
6740
6740
  if (signal.aborted) throw abortError(signal);
6741
- const attempt = await chunkBPN5ONSW_cjs.tryFirstEvent(client, request, signal, true);
6741
+ const attempt = await chunkDAXEQELR_cjs.tryFirstEvent(client, request, signal, true);
6742
6742
  if (attempt.kind === "handshake_error") {
6743
6743
  lastError = attempt.error;
6744
6744
  continue;
6745
6745
  }
6746
- return yield* chunkBPN5ONSW_cjs.relayStream(attempt.generator, attempt.firstResult);
6746
+ return yield* chunkDAXEQELR_cjs.relayStream(attempt.generator, attempt.firstResult);
6747
6747
  }
6748
6748
  if (lastError !== void 0) throw lastError;
6749
6749
  throw new chunkIHFNRNTJ_cjs.NetworkError("FallbackLlmClient has no providers configured", {
@@ -7324,14 +7324,14 @@ function resolveRunProvider(options) {
7324
7324
  }
7325
7325
  const parsedModel = chunkVYHJZVL5_cjs.parseModelId(options.model?.id);
7326
7326
  const modelInferredProvider = parsedModel.provider !== void 0 && chunkG4XUXSRN_cjs.getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
7327
- const keyInferredProvider = chunkBPN5ONSW_cjs.inferProviderFromApiKey(options.agentOptions.apiKey);
7328
- const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? keyInferredProvider ?? modelInferredProvider ?? chunkBPN5ONSW_cjs.detectPrimaryProvider();
7327
+ const keyInferredProvider = chunkDAXEQELR_cjs.inferProviderFromApiKey(options.agentOptions.apiKey);
7328
+ const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? keyInferredProvider ?? modelInferredProvider ?? chunkDAXEQELR_cjs.detectPrimaryProvider();
7329
7329
  const effectiveModelId = modelInferredProvider !== void 0 && modelInferredProvider === primary ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
7330
7330
  return { primary, effectiveModelId };
7331
7331
  }
7332
7332
  function mergeExplicitApiKey(pools, primary, apiKey) {
7333
7333
  if (apiKey === void 0 || apiKey.length === 0) return pools;
7334
- if (chunkBPN5ONSW_cjs.isFixtureApiKey(apiKey) || apiKey === LOCAL_RUNTIME_MOCK_KEY) return pools;
7334
+ if (chunkDAXEQELR_cjs.isFixtureApiKey(apiKey) || apiKey === LOCAL_RUNTIME_MOCK_KEY) return pools;
7335
7335
  const existing = pools?.[primary];
7336
7336
  if (existing !== void 0 && existing.length > 0) return pools;
7337
7337
  return { ...pools ?? {}, [primary]: [apiKey] };
@@ -7354,7 +7354,7 @@ function buildLoopInputs(options, runId, userText, userImages) {
7354
7354
  const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
7355
7355
  const extractToolCallsFromContent = options.agentOptions.providers?.routes?.[0]?.extractToolCallsFromContent;
7356
7356
  const rateLimitSink = options.sendOptions.onRunEvent;
7357
- const chain = chunkBPN5ONSW_cjs.resolveProviderChain({
7357
+ const chain = chunkDAXEQELR_cjs.resolveProviderChain({
7358
7358
  primary,
7359
7359
  ...fallback !== void 0 ? { fallback } : {},
7360
7360
  ...apiKeys !== void 0 ? { apiKeys } : {},
@@ -7626,7 +7626,7 @@ function buildRealRunOptions(args) {
7626
7626
  };
7627
7627
  }
7628
7628
  async function createFixtureRunHelper(args) {
7629
- const sessionMessages = chunkDCXRHCZJ_cjs.getSessionMessages(args.inputs.agentId);
7629
+ const sessionMessages = chunkVWI3CDEW_cjs.getSessionMessages(args.inputs.agentId);
7630
7630
  const projectMcpServers = args.inputs.settingSourcesIncludeProject ? await readProjectMcpServers(args.inputs.workspaceCwd) : {};
7631
7631
  return createLocalRun({
7632
7632
  agentId: args.inputs.agentId,
@@ -7645,7 +7645,7 @@ async function createFixtureRunHelper(args) {
7645
7645
  }
7646
7646
  async function dispatchLocalRun(args) {
7647
7647
  const apiKey = resolveApiKey(args.inputs.options.apiKey);
7648
- if (chunkBPN5ONSW_cjs.shouldUseRealLocalRuntime(apiKey)) {
7648
+ if (chunkDAXEQELR_cjs.shouldUseRealLocalRuntime(apiKey)) {
7649
7649
  return createRealLocalRun(
7650
7650
  buildRealRunOptions({
7651
7651
  inputs: args.inputs,
@@ -7901,10 +7901,10 @@ async function disposeLocalAgentSession(agent) {
7901
7901
  agent.lifecycleAbortController.abort();
7902
7902
  await chunkYLQQX5W2_cjs.withCwdMutex(`agent-send:${agent.agentId}`, () => Promise.resolve());
7903
7903
  disposeSessionMcpClients(agent.agentId);
7904
- await chunkDCXRHCZJ_cjs.flushSessionWrites();
7904
+ await chunkVWI3CDEW_cjs.flushSessionWrites();
7905
7905
  await flushRegistrySaves(agent.workspaceCwd);
7906
7906
  await disposeSessionStore(agent.sessionStore);
7907
- chunkDCXRHCZJ_cjs.discardSession(agent.workspaceCwd, agent.agentId);
7907
+ chunkVWI3CDEW_cjs.discardSession(agent.workspaceCwd, agent.agentId);
7908
7908
  }
7909
7909
  async function reloadLocalAgent(agent) {
7910
7910
  if (agent.context !== void 0) await agent.context.refresh();
@@ -8679,7 +8679,7 @@ var LocalAgentMemory = class {
8679
8679
  async runActiveMemoryIfEnabled(userText, priorMessages, telemetry) {
8680
8680
  const cfg = this.options.memory?.activeRecall;
8681
8681
  if (cfg?.enabled !== true || this.index === void 0) return void 0;
8682
- if (this.breaker === void 0) this.breaker = new chunkBPN5ONSW_cjs.CircuitBreaker();
8682
+ if (this.breaker === void 0) this.breaker = new chunkDAXEQELR_cjs.CircuitBreaker();
8683
8683
  if (this.cache === void 0) this.cache = new ActiveMemoryCache();
8684
8684
  const result = await runActiveMemory({
8685
8685
  userText,
@@ -9081,8 +9081,8 @@ async function localAgentUsePersonality(args) {
9081
9081
  registry,
9082
9082
  store: args.personalityStore,
9083
9083
  invalidateCache: (reason) => args.invalidateCache(reason),
9084
- appendSessionMessage: (msg) => chunkDCXRHCZJ_cjs.appendSessionMessage(args.agentId, msg),
9085
- clearSession: () => chunkDCXRHCZJ_cjs.clearSession(args.agentId),
9084
+ appendSessionMessage: (msg) => chunkVWI3CDEW_cjs.appendSessionMessage(args.agentId, msg),
9085
+ clearSession: () => chunkVWI3CDEW_cjs.clearSession(args.agentId),
9086
9086
  opts: args.opts ?? {}
9087
9087
  })
9088
9088
  );
@@ -9436,7 +9436,7 @@ async function executeSendLocked(inputs, message, options) {
9436
9436
  if (inputs.options.onBeforeSend !== void 0) {
9437
9437
  await inputs.options.onBeforeSend({
9438
9438
  conversationId: inputs.agentId,
9439
- previousMessageCount: chunkDCXRHCZJ_cjs.getSessionMessages(inputs.agentId).length
9439
+ previousMessageCount: chunkVWI3CDEW_cjs.getSessionMessages(inputs.agentId).length
9440
9440
  });
9441
9441
  }
9442
9442
  await inputs.runPreHook(userText);
@@ -9448,8 +9448,8 @@ async function executeSendLocked(inputs, message, options) {
9448
9448
  userText,
9449
9449
  sendOptions: options
9450
9450
  });
9451
- const priorMessages = [...chunkDCXRHCZJ_cjs.getSessionMessages(inputs.agentId)];
9452
- chunkDCXRHCZJ_cjs.appendSessionMessage(inputs.agentId, { role: "user", text: userText });
9451
+ const priorMessages = [...chunkVWI3CDEW_cjs.getSessionMessages(inputs.agentId)];
9452
+ chunkVWI3CDEW_cjs.appendSessionMessage(inputs.agentId, { role: "user", text: userText });
9453
9453
  await persistMemoryFactIfWritePrompt(inputs.workspaceCwd, inputs.options.memory, userText);
9454
9454
  const memoryFacts = await readMemoryForSend(inputs.workspaceCwd, inputs.options.memory);
9455
9455
  const portPathActive = shouldUsePortMemoryPath();
@@ -9661,7 +9661,7 @@ var LocalAgent = class {
9661
9661
  );
9662
9662
  await acquireLeaseIfPossible(this.sessionStore, this.agentId);
9663
9663
  try {
9664
- await chunkDCXRHCZJ_cjs.hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
9664
+ await chunkVWI3CDEW_cjs.hydrateSession(this.agentId, { store: this.sessionStore, cwd: this.workspaceCwd });
9665
9665
  await this.personalityStore.hydrate(this.agentId);
9666
9666
  } catch (err) {
9667
9667
  await releaseLeaseIfPossible(this.sessionStore, this.agentId);
@@ -9994,7 +9994,7 @@ async function createLocalAgent(options) {
9994
9994
  if (apiKey === void 0) {
9995
9995
  throw new chunkIHFNRNTJ_cjs.AuthenticationError("Missing API key", { code: "missing_api_key" });
9996
9996
  }
9997
- const willFlowToProvider = !chunkBPN5ONSW_cjs.isFixtureApiKey(apiKey) && !chunkBPN5ONSW_cjs.shouldUseRealLocalRuntime(apiKey);
9997
+ const willFlowToProvider = !chunkDAXEQELR_cjs.isFixtureApiKey(apiKey) && !chunkDAXEQELR_cjs.shouldUseRealLocalRuntime(apiKey);
9998
9998
  const shape = validateApiKeyShape(apiKey, {
9999
9999
  strict: willFlowToProvider,
10000
10000
  // `options.model` is already normalized by `runCreateUnderSpan`; `normalizeModel`
@@ -10005,7 +10005,7 @@ async function createLocalAgent(options) {
10005
10005
  if (shape.malformed) {
10006
10006
  throw new chunkIHFNRNTJ_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
10007
10007
  }
10008
- if (!chunkBPN5ONSW_cjs.isFixtureApiKey(apiKey) && chunkBPN5ONSW_cjs.getConfiguredBaseUrl() === void 0 && !chunkBPN5ONSW_cjs.shouldUseRealLocalRuntime(apiKey)) {
10008
+ if (!chunkDAXEQELR_cjs.isFixtureApiKey(apiKey) && chunkDAXEQELR_cjs.getConfiguredBaseUrl() === void 0 && !chunkDAXEQELR_cjs.shouldUseRealLocalRuntime(apiKey)) {
10009
10009
  throw new chunkIHFNRNTJ_cjs.AuthenticationError("Invalid API key", {
10010
10010
  code: "authentication_error"
10011
10011
  });
@@ -10025,11 +10025,11 @@ async function createCloudAgent(options) {
10025
10025
  if (shape.malformed) {
10026
10026
  throw new chunkIHFNRNTJ_cjs.AuthenticationError(shape.message, { code: "malformed_api_key" });
10027
10027
  }
10028
- const baseUrl = chunkBPN5ONSW_cjs.getConfiguredBaseUrl();
10028
+ const baseUrl = chunkDAXEQELR_cjs.getConfiguredBaseUrl();
10029
10029
  if (baseUrl === void 0) {
10030
10030
  return new CloudAgent(options);
10031
10031
  }
10032
- const response = await chunkBPN5ONSW_cjs.httpRequest("/v1/agents", {
10032
+ const response = await chunkDAXEQELR_cjs.httpRequest("/v1/agents", {
10033
10033
  apiKey,
10034
10034
  method: "POST",
10035
10035
  body: {
@@ -10054,7 +10054,7 @@ function resolveAgentPersistenceCwd(options) {
10054
10054
  return process.cwd();
10055
10055
  }
10056
10056
  async function rehydrateExistingAgent(agentId, existing, options) {
10057
- await chunkBPN5ONSW_cjs.discoverProviderPlugins();
10057
+ await chunkDAXEQELR_cjs.discoverProviderPlugins();
10058
10058
  await validateRehydratedAgent(agentId, existing);
10059
10059
  const mergedLocal = options.local !== void 0 && existing.options.local !== void 0 ? { ...existing.options.local, ...options.local } : options.local ?? existing.options.local;
10060
10060
  const mergedOptions = {
@@ -10182,7 +10182,7 @@ var Agent = class _Agent {
10182
10182
  pluginCount: enabledPluginNames(options.plugins).length
10183
10183
  });
10184
10184
  try {
10185
- await chunkBPN5ONSW_cjs.discoverProviderPlugins();
10185
+ await chunkDAXEQELR_cjs.discoverProviderPlugins();
10186
10186
  const agent = await runCreateUnderSpan(options, span);
10187
10187
  return agent;
10188
10188
  } catch (err) {
@@ -10451,9 +10451,9 @@ var Agent = class _Agent {
10451
10451
  `No local agent "${agentId}" registered \u2014 compact targets local sessions.`
10452
10452
  );
10453
10453
  }
10454
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-VVT6IBJG.cjs');
10454
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-XMP6OGY3.cjs');
10455
10455
  const { cwd, model, store } = await openLocalStore(reg);
10456
- return chunkDCXRHCZJ_cjs.enqueueSessionWrite(
10456
+ return chunkVWI3CDEW_cjs.enqueueSessionWrite(
10457
10457
  cwd,
10458
10458
  agentId,
10459
10459
  () => compactSessionTranscript({
@@ -10487,7 +10487,7 @@ var Agent = class _Agent {
10487
10487
  `No local agent "${agentId}" registered \u2014 injectSessionTurn targets local sessions.`
10488
10488
  );
10489
10489
  }
10490
- const { injectSessionTurn } = await import('./inject-session-LFCYVSLJ.cjs');
10490
+ const { injectSessionTurn } = await import('./inject-session-CC4KBYF6.cjs');
10491
10491
  const { cwd, model, store } = await openLocalStore(reg);
10492
10492
  await injectSessionTurn({
10493
10493
  store,
@@ -10632,5 +10632,5 @@ exports.generateCronId = generateCronId;
10632
10632
  exports.getPricingEntry = getPricingEntry;
10633
10633
  exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
10634
10634
  exports.resolveApiKey = resolveApiKey;
10635
- //# sourceMappingURL=chunk-INSFS5GT.cjs.map
10636
- //# sourceMappingURL=chunk-INSFS5GT.cjs.map
10635
+ //# sourceMappingURL=chunk-CAFV7WPQ.cjs.map
10636
+ //# sourceMappingURL=chunk-CAFV7WPQ.cjs.map