@theokit/sdk 4.31.0 → 4.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/{agent-Bzg2_uGr.d.cts → agent-DGv1-d81.d.cts} +52 -2
- package/dist/{agent-6GQBOHHA.cjs → agent-ES57DGAT.cjs} +9 -9
- package/dist/{agent-6GQBOHHA.cjs.map → agent-ES57DGAT.cjs.map} +1 -1
- package/dist/{agent-DY5LGZ5E.js → agent-FBFPSBTX.js} +8 -8
- package/dist/{agent-DY5LGZ5E.js.map → agent-FBFPSBTX.js.map} +1 -1
- package/dist/{agent-Ekv8y7_c.d.ts → agent-SmxntivO.d.ts} +52 -2
- package/dist/{chunk-VUXLNVX7.js → chunk-334WDVFZ.js} +4 -4
- package/dist/{chunk-VUXLNVX7.js.map → chunk-334WDVFZ.js.map} +1 -1
- package/dist/{chunk-WQEQCJTZ.cjs → chunk-CJVMDRQB.cjs} +26 -3
- package/dist/chunk-CJVMDRQB.cjs.map +1 -0
- package/dist/{chunk-UKNMWCPZ.cjs → chunk-CVSNCUBU.cjs} +133 -70
- package/dist/chunk-CVSNCUBU.cjs.map +1 -0
- package/dist/{chunk-4SXHEZIV.cjs → chunk-DQSILMWU.cjs} +9 -3
- package/dist/chunk-DQSILMWU.cjs.map +1 -0
- package/dist/{chunk-PORDVVJS.js → chunk-EIPSZ4GA.js} +4 -4
- package/dist/chunk-EIPSZ4GA.js.map +1 -0
- package/dist/{chunk-4JWZRASX.js → chunk-HBTEK5LK.js} +3 -3
- package/dist/{chunk-4JWZRASX.js.map → chunk-HBTEK5LK.js.map} +1 -1
- package/dist/{chunk-U447MTG4.cjs → chunk-HCXDDR6P.cjs} +8 -8
- package/dist/chunk-HCXDDR6P.cjs.map +1 -0
- package/dist/{chunk-XJT5VACT.cjs → chunk-I4QDIQ45.cjs} +6 -6
- package/dist/{chunk-XJT5VACT.cjs.map → chunk-I4QDIQ45.cjs.map} +1 -1
- package/dist/{chunk-CYTAM3E6.cjs → chunk-JPG7NMNH.cjs} +75 -58
- package/dist/chunk-JPG7NMNH.cjs.map +1 -0
- package/dist/{chunk-FZ75EZR5.js → chunk-NI4PAMJQ.js} +45 -28
- package/dist/chunk-NI4PAMJQ.js.map +1 -0
- package/dist/{chunk-FDGRQQWX.cjs → chunk-OQX2DG36.cjs} +5 -5
- package/dist/{chunk-FDGRQQWX.cjs.map → chunk-OQX2DG36.cjs.map} +1 -1
- package/dist/{chunk-TLG444A6.js → chunk-SQVQH4EK.js} +130 -67
- package/dist/chunk-SQVQH4EK.js.map +1 -0
- package/dist/{chunk-ICSCKB3N.js → chunk-UAYYNWYJ.js} +27 -4
- package/dist/chunk-UAYYNWYJ.js.map +1 -0
- package/dist/{chunk-ZZWTY3RX.js → chunk-WPBTPSKQ.js} +9 -4
- package/dist/chunk-WPBTPSKQ.js.map +1 -0
- package/dist/{compact-session-2BFNMENR.cjs → compact-session-OKXLKJIS.cjs} +12 -12
- package/dist/{compact-session-2BFNMENR.cjs.map → compact-session-OKXLKJIS.cjs.map} +1 -1
- package/dist/{compact-session-2JONXHLR.js → compact-session-UHGMWPMW.js} +4 -4
- package/dist/{compact-session-2JONXHLR.js.map → compact-session-UHGMWPMW.js.map} +1 -1
- package/dist/{cron-CjzvXGT2.d.cts → cron-BiK_aNJI.d.cts} +2 -2
- package/dist/{cron-D0Z29gI-.d.ts → cron-Dx7B-3WB.d.ts} +2 -2
- package/dist/cron.cjs +8 -8
- package/dist/cron.d.cts +3 -3
- package/dist/cron.d.ts +3 -3
- package/dist/cron.js +7 -7
- package/dist/{errors-DHZtSNnj.d.ts → errors-Cua4WC9H.d.ts} +1 -1
- package/dist/{errors-BdL-buYn.d.cts → errors-DyVbXdR4.d.cts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/eval.cjs +11 -11
- package/dist/eval.js +7 -7
- package/dist/fs-session-store-2J5JOXC2.js +8 -0
- package/dist/{fs-session-store-7AEI4STY.js.map → fs-session-store-2J5JOXC2.js.map} +1 -1
- package/dist/fs-session-store-DNAJ6RQG.cjs +17 -0
- package/dist/{fs-session-store-26WVVMC4.cjs.map → fs-session-store-DNAJ6RQG.cjs.map} +1 -1
- package/dist/index.cjs +50 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -8
- package/dist/index.d.ts +23 -8
- package/dist/index.js +30 -10
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-MIFEKATN.cjs → inject-session-24FJ65LP.cjs} +6 -6
- package/dist/{inject-session-MIFEKATN.cjs.map → inject-session-24FJ65LP.cjs.map} +1 -1
- package/dist/{inject-session-NNSCCIVP.js → inject-session-JXQO33T3.js} +4 -4
- package/dist/{inject-session-NNSCCIVP.js.map → inject-session-JXQO33T3.js.map} +1 -1
- package/dist/internal/llm/abort-error.d.ts +1 -0
- package/dist/internal/llm/retrying-client.d.ts +27 -3
- package/dist/internal/llm/transport-error.d.ts +9 -0
- package/dist/internal/persistence/index.cjs +6 -6
- package/dist/internal/persistence/index.js +1 -1
- package/dist/internal/persistence/session-transcript.d.cts +13 -1
- package/dist/internal/persistence/session-transcript.d.ts +13 -1
- package/dist/internal/runtime/lifecycle/post-run-lifecycle.d.ts +1 -1
- package/dist/persistence.cjs +13 -9
- package/dist/persistence.d.cts +2 -1
- package/dist/persistence.d.ts +2 -1
- package/dist/persistence.js +2 -2
- package/dist/{run-OJbGyweZ.d.ts → run-CwEJtLPE.d.cts} +8 -0
- package/dist/{run-OJbGyweZ.d.cts → run-CwEJtLPE.d.ts} +8 -0
- package/dist/server/errors-envelope.d.cts +3 -3
- package/dist/server/errors-envelope.d.ts +3 -3
- package/dist/session-transcript-F5OXXO6G.cjs +50 -0
- package/dist/{session-transcript-LPNZR3YS.cjs.map → session-transcript-F5OXXO6G.cjs.map} +1 -1
- package/dist/{session-transcript-T7LGJUGW.js → session-transcript-QS6CXHHD.js} +3 -3
- package/dist/{session-transcript-T7LGJUGW.js.map → session-transcript-QS6CXHHD.js.map} +1 -1
- package/dist/subagents-loader.d.cts +2 -2
- package/dist/subagents-loader.d.ts +2 -2
- package/dist/types/agent-prims.d.ts +8 -0
- package/dist/types/session-record.d.ts +51 -1
- package/package.json +1 -1
- package/dist/chunk-4SXHEZIV.cjs.map +0 -1
- package/dist/chunk-CYTAM3E6.cjs.map +0 -1
- package/dist/chunk-FZ75EZR5.js.map +0 -1
- package/dist/chunk-ICSCKB3N.js.map +0 -1
- package/dist/chunk-PORDVVJS.js.map +0 -1
- package/dist/chunk-TLG444A6.js.map +0 -1
- package/dist/chunk-U447MTG4.cjs.map +0 -1
- package/dist/chunk-UKNMWCPZ.cjs.map +0 -1
- package/dist/chunk-WQEQCJTZ.cjs.map +0 -1
- package/dist/chunk-ZZWTY3RX.js.map +0 -1
- package/dist/fs-session-store-26WVVMC4.cjs +0 -17
- package/dist/fs-session-store-7AEI4STY.js +0 -8
- package/dist/session-transcript-LPNZR3YS.cjs +0 -46
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkI4QDIQ45_cjs = require('./chunk-I4QDIQ45.cjs');
|
|
4
4
|
var chunkIT3PWBW4_cjs = require('./chunk-IT3PWBW4.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkDQSILMWU_cjs = require('./chunk-DQSILMWU.cjs');
|
|
6
6
|
require('./chunk-TIZ4TS5V.cjs');
|
|
7
7
|
require('./chunk-BEURCLDV.cjs');
|
|
8
8
|
|
|
9
9
|
// src/internal/session/inject-session.ts
|
|
10
10
|
async function injectSessionTurn(opts) {
|
|
11
|
-
await
|
|
11
|
+
await chunkI4QDIQ45_cjs.enqueueSessionWrite(opts.loc.cwd, opts.loc.agentId, async () => {
|
|
12
12
|
const prior = await opts.store.readRecords(opts.loc.agentId);
|
|
13
|
-
const transcript =
|
|
13
|
+
const transcript = chunkDQSILMWU_cjs.SessionTranscript.fromRecords(prior, {
|
|
14
14
|
cwd: opts.loc.cwd,
|
|
15
15
|
sessionId: opts.sessionId,
|
|
16
16
|
model: opts.loc.model ?? "unknown"
|
|
@@ -23,5 +23,5 @@ async function injectSessionTurn(opts) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
exports.injectSessionTurn = injectSessionTurn;
|
|
26
|
-
//# sourceMappingURL=inject-session-
|
|
27
|
-
//# sourceMappingURL=inject-session-
|
|
26
|
+
//# sourceMappingURL=inject-session-24FJ65LP.cjs.map
|
|
27
|
+
//# sourceMappingURL=inject-session-24FJ65LP.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":["enqueueSessionWrite","SessionTranscript","invalidateSessionCache"],"mappings":";;;;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAMA,sCAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAaC,mCAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAAC,wCAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-
|
|
1
|
+
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":["enqueueSessionWrite","SessionTranscript","invalidateSessionCache"],"mappings":";;;;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAMA,sCAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAaC,mCAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAAC,wCAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-24FJ65LP.cjs","sourcesContent":["/**\n * M51 (agent-builder) — inject a SYNTHETIC user+assistant pair into a session's persisted transcript\n * WITHOUT running an LLM turn. This is the Codex review-exit mechanism (`exit_success.xml` appended to\n * the parent thread history so follow-ups like \"fix finding 2\" work): the pair chains onto the DAG\n * leaf (M50 pattern) and the in-memory cache is invalidated so the NEXT send re-hydrates with it.\n */\nimport type { SessionStore } from \"../../types/session-store.js\";\nimport { SessionTranscript } from \"../persistence/session-transcript.js\";\nimport { enqueueSessionWrite, invalidateSessionCache } from \"./agent-session.js\";\nimport type { CompactLocation } from \"./compact-session.js\";\n\nexport async function injectSessionTurn(opts: {\n store: SessionStore;\n loc: CompactLocation;\n sessionId: string;\n userText: string;\n assistantText: string;\n}): Promise<void> {\n await enqueueSessionWrite(opts.loc.cwd, opts.loc.agentId, async () => {\n const prior = await opts.store.readRecords(opts.loc.agentId);\n const transcript = SessionTranscript.fromRecords(prior, {\n cwd: opts.loc.cwd,\n sessionId: opts.sessionId,\n model: opts.loc.model ?? \"unknown\",\n });\n transcript.appendUserTurn(opts.userText);\n transcript.appendAssistantTurn({ text: opts.assistantText });\n await opts.store.appendRecords(opts.loc.agentId, transcript.records().slice(prior.length));\n invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);\n });\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { enqueueSessionWrite } from './chunk-
|
|
1
|
+
import { enqueueSessionWrite } from './chunk-334WDVFZ.js';
|
|
2
2
|
import { invalidateSessionCache } from './chunk-EEZ7CFMM.js';
|
|
3
|
-
import { SessionTranscript } from './chunk-
|
|
3
|
+
import { SessionTranscript } from './chunk-WPBTPSKQ.js';
|
|
4
4
|
import './chunk-S2BBRVQX.js';
|
|
5
5
|
import './chunk-JTFYYKDT.js';
|
|
6
6
|
|
|
@@ -21,5 +21,5 @@ async function injectSessionTurn(opts) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export { injectSessionTurn };
|
|
24
|
-
//# sourceMappingURL=inject-session-
|
|
25
|
-
//# sourceMappingURL=inject-session-
|
|
24
|
+
//# sourceMappingURL=inject-session-JXQO33T3.js.map
|
|
25
|
+
//# sourceMappingURL=inject-session-JXQO33T3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":[],"mappings":";;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAM,oBAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAa,iBAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAA,sBAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-
|
|
1
|
+
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":[],"mappings":";;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAM,oBAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAa,iBAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAA,sBAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-JXQO33T3.js","sourcesContent":["/**\n * M51 (agent-builder) — inject a SYNTHETIC user+assistant pair into a session's persisted transcript\n * WITHOUT running an LLM turn. This is the Codex review-exit mechanism (`exit_success.xml` appended to\n * the parent thread history so follow-ups like \"fix finding 2\" work): the pair chains onto the DAG\n * leaf (M50 pattern) and the in-memory cache is invalidated so the NEXT send re-hydrates with it.\n */\nimport type { SessionStore } from \"../../types/session-store.js\";\nimport { SessionTranscript } from \"../persistence/session-transcript.js\";\nimport { enqueueSessionWrite, invalidateSessionCache } from \"./agent-session.js\";\nimport type { CompactLocation } from \"./compact-session.js\";\n\nexport async function injectSessionTurn(opts: {\n store: SessionStore;\n loc: CompactLocation;\n sessionId: string;\n userText: string;\n assistantText: string;\n}): Promise<void> {\n await enqueueSessionWrite(opts.loc.cwd, opts.loc.agentId, async () => {\n const prior = await opts.store.readRecords(opts.loc.agentId);\n const transcript = SessionTranscript.fromRecords(prior, {\n cwd: opts.loc.cwd,\n sessionId: opts.sessionId,\n model: opts.loc.model ?? \"unknown\",\n });\n transcript.appendUserTurn(opts.userText);\n transcript.appendAssistantTurn({ text: opts.assistantText });\n await opts.store.appendRecords(opts.loc.agentId, transcript.records().slice(prior.length));\n invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,9 +4,26 @@ export declare const MAX_TENTATIVAS = 3;
|
|
|
4
4
|
/**
|
|
5
5
|
* O erro é transitório, isto é: reexecutar pode mudar o resultado?
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* ## Delega para `isTransientError`, e diz o que subtrai
|
|
8
|
+
*
|
|
9
|
+
* O SDK **já** publica `isTransientError` — documentado como "a single source of truth rather than
|
|
10
|
+
* a re-derivation", e com o aviso explícito de que "It never inspects `err.message`". A primeira
|
|
11
|
+
* versão desta função ignorou as duas coisas: derivou de novo, por regex sobre a mensagem
|
|
12
|
+
* (`/\b4\d\d\b/`). A revisão adversarial mediu o custo — `connect ECONNREFUSED 127.0.0.1:443`
|
|
13
|
+
* era classificado como NÃO transitório, porque a **porta** casa a regex. Os erros de rede para os
|
|
14
|
+
* quais o retry existe eram exatamente os excluídos.
|
|
15
|
+
*
|
|
16
|
+
* Reinventar aqui foi violação da rung 4 da parcimônia com a peça pronta à mão. O que sobra desta
|
|
17
|
+
* função são **três subtrações** do veredito do dono, cada uma com razão:
|
|
18
|
+
*
|
|
19
|
+
* | Subtração | Por quê |
|
|
20
|
+
* |---|---|
|
|
21
|
+
* | `CredentialPoolExhaustedError` | o pool já gastou o próprio orçamento de tentativas e rotação; o `nextRetryAt` está em dezenas de segundos. Reexecutar multiplicaria a espera por `MAX_TENTATIVAS` sem chance de sucesso. |
|
|
22
|
+
* | `code === "circuit_open"` | o breaker existe **para** falhar rápido; envolvê-lo num retry desfaz de fora a decisão que ele acabou de tomar. |
|
|
23
|
+
* | `RateLimitError` com 402 | cota de faturamento não se resolve em milissegundos — é por isso que o `classifyAndDecide` do pool rotaciona em vez de esperar. |
|
|
24
|
+
*
|
|
25
|
+
* As duas primeiras vieram da medição da revisão: com elas transitórias, o pool inteiro era
|
|
26
|
+
* reexecutado 3×, e uma espera de 30 s virava ~90 s.
|
|
10
27
|
*/
|
|
11
28
|
export declare function ehTransitorio(err: unknown): boolean;
|
|
12
29
|
/**
|
|
@@ -24,6 +41,13 @@ export declare class RetryingLlmClient implements LlmClient {
|
|
|
24
41
|
constructor(inner: LlmClient, opts?: {
|
|
25
42
|
rng?: () => number;
|
|
26
43
|
});
|
|
44
|
+
/**
|
|
45
|
+
* O cliente decorado. Público pela mesma convenção de `FaultInjectingLlmClient.inner`: os testes
|
|
46
|
+
* de fiação do router afirmam `instanceof PoolAwareLlmClient` e precisam enxergar através dos
|
|
47
|
+
* decorators. Sem isto, adicionar um decorator quebra testes cuja intenção continua válida — que
|
|
48
|
+
* foi exatamente o que o M93 fez com 4 testes pré-existentes.
|
|
49
|
+
*/
|
|
50
|
+
get inner(): LlmClient;
|
|
27
51
|
get name(): string;
|
|
28
52
|
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
29
53
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envolve uma falha de socket num {@link NetworkError}, preservando a causa.
|
|
3
|
+
*
|
|
4
|
+
* Devolve o erro original — sem envolver — quando ele é um abort ou já é um erro do SDK.
|
|
5
|
+
*/
|
|
6
|
+
export declare function wrapTransportError(err: unknown, ctx: {
|
|
7
|
+
providerId: string;
|
|
8
|
+
endpoint: string;
|
|
9
|
+
}): unknown;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkPNVDQL5Y_cjs = require('../../chunk-PNVDQL5Y.cjs');
|
|
4
4
|
var chunkOIYQBUW4_cjs = require('../../chunk-OIYQBUW4.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkCJVMDRQB_cjs = require('../../chunk-CJVMDRQB.cjs');
|
|
6
6
|
var chunkJD74LN7R_cjs = require('../../chunk-JD74LN7R.cjs');
|
|
7
7
|
var chunkYLQQX5W2_cjs = require('../../chunk-YLQQX5W2.cjs');
|
|
8
8
|
var chunkTIZ4TS5V_cjs = require('../../chunk-TIZ4TS5V.cjs');
|
|
@@ -65,23 +65,23 @@ Object.defineProperty(exports, "writeVersionedJson", {
|
|
|
65
65
|
});
|
|
66
66
|
Object.defineProperty(exports, "JsonlParseError", {
|
|
67
67
|
enumerable: true,
|
|
68
|
-
get: function () { return
|
|
68
|
+
get: function () { return chunkCJVMDRQB_cjs.JsonlParseError; }
|
|
69
69
|
});
|
|
70
70
|
Object.defineProperty(exports, "appendJsonl", {
|
|
71
71
|
enumerable: true,
|
|
72
|
-
get: function () { return
|
|
72
|
+
get: function () { return chunkCJVMDRQB_cjs.appendJsonl; }
|
|
73
73
|
});
|
|
74
74
|
Object.defineProperty(exports, "loadJsonl", {
|
|
75
75
|
enumerable: true,
|
|
76
|
-
get: function () { return
|
|
76
|
+
get: function () { return chunkCJVMDRQB_cjs.loadJsonl; }
|
|
77
77
|
});
|
|
78
78
|
Object.defineProperty(exports, "readJsonlIds", {
|
|
79
79
|
enumerable: true,
|
|
80
|
-
get: function () { return
|
|
80
|
+
get: function () { return chunkCJVMDRQB_cjs.readJsonlIds; }
|
|
81
81
|
});
|
|
82
82
|
Object.defineProperty(exports, "withFileLock", {
|
|
83
83
|
enumerable: true,
|
|
84
|
-
get: function () { return
|
|
84
|
+
get: function () { return chunkCJVMDRQB_cjs.withFileLock; }
|
|
85
85
|
});
|
|
86
86
|
Object.defineProperty(exports, "applyWalWithFallback", {
|
|
87
87
|
enumerable: true,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PersistenceSchema } from '../../chunk-CAH3G4IS.js';
|
|
2
2
|
export { displayTheokitHome, getProfilesRoot, getTheokitHome, migrateSchema, readVersionedJson, writeVersionedJson } from '../../chunk-DGRZNMTU.js';
|
|
3
|
-
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from '../../chunk-
|
|
3
|
+
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from '../../chunk-UAYYNWYJ.js';
|
|
4
4
|
export { applyWalWithFallback, containsCjk, isCorruptionError, openSqliteResilient, sanitizeFts5Query } from '../../chunk-77FOZCOT.js';
|
|
5
5
|
export { withCwdMutex } from '../../chunk-2XLKLVVR.js';
|
|
6
6
|
export { atomicWriteJson, atomicWriteText, replaceFileAtomic } from '../../chunk-S2BBRVQX.js';
|
|
@@ -54,7 +54,19 @@ export declare class SessionTranscript {
|
|
|
54
54
|
* Returns them in root→leaf (chronological replay) order.
|
|
55
55
|
*/
|
|
56
56
|
export declare function reconstructMessages(records: readonly SessionRecord[]): LlmMessage[];
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Raiz do estado de transcript.
|
|
59
|
+
*
|
|
60
|
+
* `THEOKIT_HOME` vence; o fallback é `~/.theokit`. Home-ancorado de propósito, e NÃO
|
|
61
|
+
* `getTheokitHome(cwd)` de `paths.ts`: aquele faz fallback para `<cwd>/.theokit`, e trocar
|
|
62
|
+
* por ele moveria o transcript de todo mundo que **não** define a variável. O irmão com a
|
|
63
|
+
* forma certa é `catalog-source-models-dev.ts` (M94 ADR-2).
|
|
64
|
+
*
|
|
65
|
+
* Antes do M94 esta função ignorava a env, então quem a definia tinha o estado partido em
|
|
66
|
+
* dois em silêncio — as sessões continuavam em `~/.theokit` enquanto o resto do SDK migrava.
|
|
67
|
+
*/
|
|
68
|
+
export declare function transcriptRoot(): string;
|
|
69
|
+
/** @deprecated Use {@link transcriptRoot}. Mantido como alias — mesmo valor. */
|
|
58
70
|
export declare function defaultBaseDir(): string;
|
|
59
71
|
/**
|
|
60
72
|
* Expand a leading `~` / `~/` to the user's home dir. `node:path` does NOT expand `~`, so a
|
|
@@ -54,7 +54,19 @@ export declare class SessionTranscript {
|
|
|
54
54
|
* Returns them in root→leaf (chronological replay) order.
|
|
55
55
|
*/
|
|
56
56
|
export declare function reconstructMessages(records: readonly SessionRecord[]): LlmMessage[];
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Raiz do estado de transcript.
|
|
59
|
+
*
|
|
60
|
+
* `THEOKIT_HOME` vence; o fallback é `~/.theokit`. Home-ancorado de propósito, e NÃO
|
|
61
|
+
* `getTheokitHome(cwd)` de `paths.ts`: aquele faz fallback para `<cwd>/.theokit`, e trocar
|
|
62
|
+
* por ele moveria o transcript de todo mundo que **não** define a variável. O irmão com a
|
|
63
|
+
* forma certa é `catalog-source-models-dev.ts` (M94 ADR-2).
|
|
64
|
+
*
|
|
65
|
+
* Antes do M94 esta função ignorava a env, então quem a definia tinha o estado partido em
|
|
66
|
+
* dois em silêncio — as sessões continuavam em `~/.theokit` enquanto o resto do SDK migrava.
|
|
67
|
+
*/
|
|
68
|
+
export declare function transcriptRoot(): string;
|
|
69
|
+
/** @deprecated Use {@link transcriptRoot}. Mantido como alias — mesmo valor. */
|
|
58
70
|
export declare function defaultBaseDir(): string;
|
|
59
71
|
/**
|
|
60
72
|
* Expand a leading `~` / `~/` to the user's home dir. `node:path` does NOT expand `~`, so a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function runPostRunLifecycle(inputs: PostRunLifecycleInputs): Promise<void>;
|
package/dist/persistence.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkPNVDQL5Y_cjs = require('./chunk-PNVDQL5Y.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkCJVMDRQB_cjs = require('./chunk-CJVMDRQB.cjs');
|
|
5
5
|
var chunkJD74LN7R_cjs = require('./chunk-JD74LN7R.cjs');
|
|
6
6
|
var chunkYLQQX5W2_cjs = require('./chunk-YLQQX5W2.cjs');
|
|
7
|
-
var
|
|
7
|
+
var chunkDQSILMWU_cjs = require('./chunk-DQSILMWU.cjs');
|
|
8
8
|
var chunkTIZ4TS5V_cjs = require('./chunk-TIZ4TS5V.cjs');
|
|
9
9
|
var chunkA44COQJJ_cjs = require('./chunk-A44COQJJ.cjs');
|
|
10
10
|
require('./chunk-BEURCLDV.cjs');
|
|
@@ -115,23 +115,23 @@ Object.defineProperty(exports, "PersistenceSchema", {
|
|
|
115
115
|
});
|
|
116
116
|
Object.defineProperty(exports, "JsonlParseError", {
|
|
117
117
|
enumerable: true,
|
|
118
|
-
get: function () { return
|
|
118
|
+
get: function () { return chunkCJVMDRQB_cjs.JsonlParseError; }
|
|
119
119
|
});
|
|
120
120
|
Object.defineProperty(exports, "appendJsonl", {
|
|
121
121
|
enumerable: true,
|
|
122
|
-
get: function () { return
|
|
122
|
+
get: function () { return chunkCJVMDRQB_cjs.appendJsonl; }
|
|
123
123
|
});
|
|
124
124
|
Object.defineProperty(exports, "loadJsonl", {
|
|
125
125
|
enumerable: true,
|
|
126
|
-
get: function () { return
|
|
126
|
+
get: function () { return chunkCJVMDRQB_cjs.loadJsonl; }
|
|
127
127
|
});
|
|
128
128
|
Object.defineProperty(exports, "readJsonlIds", {
|
|
129
129
|
enumerable: true,
|
|
130
|
-
get: function () { return
|
|
130
|
+
get: function () { return chunkCJVMDRQB_cjs.readJsonlIds; }
|
|
131
131
|
});
|
|
132
132
|
Object.defineProperty(exports, "withFileLock", {
|
|
133
133
|
enumerable: true,
|
|
134
|
-
get: function () { return
|
|
134
|
+
get: function () { return chunkCJVMDRQB_cjs.withFileLock; }
|
|
135
135
|
});
|
|
136
136
|
Object.defineProperty(exports, "applyWalWithFallback", {
|
|
137
137
|
enumerable: true,
|
|
@@ -155,11 +155,15 @@ Object.defineProperty(exports, "withCwdMutex", {
|
|
|
155
155
|
});
|
|
156
156
|
Object.defineProperty(exports, "encodeProjectDir", {
|
|
157
157
|
enumerable: true,
|
|
158
|
-
get: function () { return
|
|
158
|
+
get: function () { return chunkDQSILMWU_cjs.encodeProjectDir; }
|
|
159
159
|
});
|
|
160
160
|
Object.defineProperty(exports, "transcriptPath", {
|
|
161
161
|
enumerable: true,
|
|
162
|
-
get: function () { return
|
|
162
|
+
get: function () { return chunkDQSILMWU_cjs.transcriptPath; }
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(exports, "transcriptRoot", {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () { return chunkDQSILMWU_cjs.transcriptRoot; }
|
|
163
167
|
});
|
|
164
168
|
Object.defineProperty(exports, "atomicWriteJson", {
|
|
165
169
|
enumerable: true,
|
package/dist/persistence.d.cts
CHANGED
|
@@ -21,7 +21,8 @@ export { withFileLock } from "./internal/persistence/file-lock.js";
|
|
|
21
21
|
export { sanitizeFts5Query } from "./internal/persistence/fts5-sanitize.js";
|
|
22
22
|
export { appendJsonl, JsonlParseError, loadJsonl, readJsonlIds, } from "./internal/persistence/jsonl.js";
|
|
23
23
|
export { PersistenceSchema } from "./internal/persistence/persistence-schema.js";
|
|
24
|
-
export { encodeProjectDir, transcriptPath, } from "./internal/persistence/session-transcript.js";
|
|
24
|
+
export { encodeProjectDir, transcriptPath, transcriptRoot, } from "./internal/persistence/session-transcript.js";
|
|
25
|
+
export type { TranscriptBlock, TranscriptMessage } from "./types/session-record.js";
|
|
25
26
|
export { acquireSessionWriter, SessionBusyError, type SessionWriterLease, } from "./internal/persistence/session-writer.js";
|
|
26
27
|
export type { OpenSqliteResilientOptions, ResilientSqliteDb, } from "./internal/persistence/sqlite-open.js";
|
|
27
28
|
export { isCorruptionError, openSqliteResilient } from "./internal/persistence/sqlite-open.js";
|
package/dist/persistence.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export { withFileLock } from "./internal/persistence/file-lock.js";
|
|
|
21
21
|
export { sanitizeFts5Query } from "./internal/persistence/fts5-sanitize.js";
|
|
22
22
|
export { appendJsonl, JsonlParseError, loadJsonl, readJsonlIds, } from "./internal/persistence/jsonl.js";
|
|
23
23
|
export { PersistenceSchema } from "./internal/persistence/persistence-schema.js";
|
|
24
|
-
export { encodeProjectDir, transcriptPath, } from "./internal/persistence/session-transcript.js";
|
|
24
|
+
export { encodeProjectDir, transcriptPath, transcriptRoot, } from "./internal/persistence/session-transcript.js";
|
|
25
|
+
export type { TranscriptBlock, TranscriptMessage } from "./types/session-record.js";
|
|
25
26
|
export { acquireSessionWriter, SessionBusyError, type SessionWriterLease, } from "./internal/persistence/session-writer.js";
|
|
26
27
|
export type { OpenSqliteResilientOptions, ResilientSqliteDb, } from "./internal/persistence/sqlite-open.js";
|
|
27
28
|
export { isCorruptionError, openSqliteResilient } from "./internal/persistence/sqlite-open.js";
|
package/dist/persistence.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { PersistenceSchema } from './chunk-CAH3G4IS.js';
|
|
2
|
-
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from './chunk-
|
|
2
|
+
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from './chunk-UAYYNWYJ.js';
|
|
3
3
|
export { applyWalWithFallback, isCorruptionError, openSqliteResilient, sanitizeFts5Query } from './chunk-77FOZCOT.js';
|
|
4
4
|
export { withCwdMutex } from './chunk-2XLKLVVR.js';
|
|
5
|
-
export { encodeProjectDir, transcriptPath } from './chunk-
|
|
5
|
+
export { encodeProjectDir, transcriptPath, transcriptRoot } from './chunk-WPBTPSKQ.js';
|
|
6
6
|
export { atomicWriteJson, atomicWriteText, replaceFileAtomic } from './chunk-S2BBRVQX.js';
|
|
7
7
|
import { TheokitAgentError } from './chunk-WLKFWQSJ.js';
|
|
8
8
|
import './chunk-JTFYYKDT.js';
|
|
@@ -376,6 +376,14 @@ interface ModelParameterValue {
|
|
|
376
376
|
interface ModelSelection {
|
|
377
377
|
id: string;
|
|
378
378
|
params?: ModelParameterValue[];
|
|
379
|
+
/**
|
|
380
|
+
* M94 — janela de contexto do modelo, em tokens. Vira o `override` do resolvedor de janela.
|
|
381
|
+
*
|
|
382
|
+
* Existe para modelos SEM entrada de catálogo: sem ela, um modelo de 400k era orçado contra o
|
|
383
|
+
* piso de 128k e compactava ~3× mais do que precisava. Um valor acima do que o catálogo conhece
|
|
384
|
+
* é clampeado — declarar 10M não estoura o provider.
|
|
385
|
+
*/
|
|
386
|
+
contextWindow?: number;
|
|
379
387
|
}
|
|
380
388
|
/**
|
|
381
389
|
* SE12 — a read-only, text-only projection of one turn of the run's conversation,
|
|
@@ -376,6 +376,14 @@ interface ModelParameterValue {
|
|
|
376
376
|
interface ModelSelection {
|
|
377
377
|
id: string;
|
|
378
378
|
params?: ModelParameterValue[];
|
|
379
|
+
/**
|
|
380
|
+
* M94 — janela de contexto do modelo, em tokens. Vira o `override` do resolvedor de janela.
|
|
381
|
+
*
|
|
382
|
+
* Existe para modelos SEM entrada de catálogo: sem ela, um modelo de 400k era orçado contra o
|
|
383
|
+
* piso de 128k e compactava ~3× mais do que precisava. Um valor acima do que o catálogo conhece
|
|
384
|
+
* é clampeado — declarar 10M não estoura o provider.
|
|
385
|
+
*/
|
|
386
|
+
contextWindow?: number;
|
|
379
387
|
}
|
|
380
388
|
/**
|
|
381
389
|
* SE12 — a read-only, text-only projection of one turn of the run's conversation,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as TheokitAgentError } from '../errors-
|
|
2
|
-
export { M as MemoryAdapterError } from '../errors-
|
|
3
|
-
import '../run-
|
|
1
|
+
import { T as TheokitAgentError } from '../errors-DyVbXdR4.cjs';
|
|
2
|
+
export { M as MemoryAdapterError } from '../errors-DyVbXdR4.cjs';
|
|
3
|
+
import '../run-CwEJtLPE.cjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as TheokitAgentError } from '../errors-
|
|
2
|
-
export { M as MemoryAdapterError } from '../errors-
|
|
3
|
-
import '../run-
|
|
1
|
+
import { T as TheokitAgentError } from '../errors-Cua4WC9H.js';
|
|
2
|
+
export { M as MemoryAdapterError } from '../errors-Cua4WC9H.js';
|
|
3
|
+
import '../run-CwEJtLPE.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkDQSILMWU_cjs = require('./chunk-DQSILMWU.cjs');
|
|
4
|
+
require('./chunk-TIZ4TS5V.cjs');
|
|
5
|
+
require('./chunk-BEURCLDV.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "SessionTranscript", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkDQSILMWU_cjs.SessionTranscript; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "defaultBaseDir", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkDQSILMWU_cjs.defaultBaseDir; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "encodeProjectDir", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunkDQSILMWU_cjs.encodeProjectDir; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "expandTilde", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunkDQSILMWU_cjs.expandTilde; }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "readTranscript", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return chunkDQSILMWU_cjs.readTranscript; }
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "reconstructMessages", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return chunkDQSILMWU_cjs.reconstructMessages; }
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "safeSessionId", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () { return chunkDQSILMWU_cjs.safeSessionId; }
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "transcriptPath", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return chunkDQSILMWU_cjs.transcriptPath; }
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "transcriptRoot", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return chunkDQSILMWU_cjs.transcriptRoot; }
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "writeTranscript", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return chunkDQSILMWU_cjs.writeTranscript; }
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=session-transcript-F5OXXO6G.cjs.map
|
|
50
|
+
//# sourceMappingURL=session-transcript-F5OXXO6G.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"session-transcript-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"session-transcript-F5OXXO6G.cjs"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { SessionTranscript, defaultBaseDir, encodeProjectDir, expandTilde, readTranscript, reconstructMessages, safeSessionId, transcriptPath, writeTranscript } from './chunk-
|
|
1
|
+
export { SessionTranscript, defaultBaseDir, encodeProjectDir, expandTilde, readTranscript, reconstructMessages, safeSessionId, transcriptPath, transcriptRoot, writeTranscript } from './chunk-WPBTPSKQ.js';
|
|
2
2
|
import './chunk-S2BBRVQX.js';
|
|
3
3
|
import './chunk-JTFYYKDT.js';
|
|
4
|
-
//# sourceMappingURL=session-transcript-
|
|
5
|
-
//# sourceMappingURL=session-transcript-
|
|
4
|
+
//# sourceMappingURL=session-transcript-QS6CXHHD.js.map
|
|
5
|
+
//# sourceMappingURL=session-transcript-QS6CXHHD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"session-transcript-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"session-transcript-QS6CXHHD.js"}
|
|
@@ -29,6 +29,14 @@ export interface ModelParameterValue {
|
|
|
29
29
|
export interface ModelSelection {
|
|
30
30
|
id: string;
|
|
31
31
|
params?: ModelParameterValue[];
|
|
32
|
+
/**
|
|
33
|
+
* M94 — janela de contexto do modelo, em tokens. Vira o `override` do resolvedor de janela.
|
|
34
|
+
*
|
|
35
|
+
* Existe para modelos SEM entrada de catálogo: sem ela, um modelo de 400k era orçado contra o
|
|
36
|
+
* piso de 128k e compactava ~3× mais do que precisava. Um valor acima do que o catálogo conhece
|
|
37
|
+
* é clampeado — declarar 10M não estoura o provider.
|
|
38
|
+
*/
|
|
39
|
+
contextWindow?: number;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* SE12 — a read-only, text-only projection of one turn of the run's conversation,
|
|
@@ -13,6 +13,49 @@
|
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
15
|
/** One transcript record (one JSONL line). `message` absent on `system` (compact_boundary) records. */
|
|
16
|
+
/** Um bloco de conteúdo dentro de {@link TranscriptMessage}. */
|
|
17
|
+
export type TranscriptBlock = {
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "thinking";
|
|
22
|
+
thinking?: string;
|
|
23
|
+
signature?: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "tool_use";
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
input: unknown;
|
|
29
|
+
} | {
|
|
30
|
+
type: "tool_result";
|
|
31
|
+
tool_use_id: string;
|
|
32
|
+
content: unknown;
|
|
33
|
+
is_error?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* O corpo de mensagem de um {@link SessionRecord}.
|
|
37
|
+
*
|
|
38
|
+
* **NÃO se chama `SessionMessage`** — esse nome já existe em `internal/session/session-types.ts` com
|
|
39
|
+
* a forma `{role, text}`, incompatível com esta. Repropor um nome exportado com forma nova é
|
|
40
|
+
* precisamente a quebra silenciosa que o M91 custou dois patches para desfazer.
|
|
41
|
+
*
|
|
42
|
+
* O parse do disco continua **tolerante** (`readTranscript` pula linha malformada): o que muda aqui
|
|
43
|
+
* é o **tipo**, não a leniência — registros gravados por versões anteriores continuam legíveis.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export interface TranscriptMessage {
|
|
48
|
+
role: "user" | "assistant";
|
|
49
|
+
content: TranscriptBlock[];
|
|
50
|
+
/**
|
|
51
|
+
* Os três campos abaixo aparecem **só** no registro de assistant, e vêm do escritor
|
|
52
|
+
* (`SessionTranscript.appendAssistant`). Declarados opcionais porque o registro de user não os
|
|
53
|
+
* tem — medido no próprio escritor, não presumido.
|
|
54
|
+
*/
|
|
55
|
+
id?: string;
|
|
56
|
+
type?: "message";
|
|
57
|
+
model?: string;
|
|
58
|
+
}
|
|
16
59
|
export interface SessionRecord {
|
|
17
60
|
type: "user" | "assistant" | "system";
|
|
18
61
|
uuid: string;
|
|
@@ -28,5 +71,12 @@ export interface SessionRecord {
|
|
|
28
71
|
preTokens: number;
|
|
29
72
|
trigger: string;
|
|
30
73
|
};
|
|
31
|
-
|
|
74
|
+
/**
|
|
75
|
+
* O corpo da mensagem, na forma que o escritor de transcript de fato grava.
|
|
76
|
+
*
|
|
77
|
+
* M94 — era `Record<string, unknown>`, e o consumidor recuperava o tipo com cast a cada leitura.
|
|
78
|
+
* A forma **sempre foi fixa** (`SessionTranscript.appendToolResults` / `#push` a produzem); só não
|
|
79
|
+
* estava declarada. Segue opcional porque registros de sistema não carregam mensagem.
|
|
80
|
+
*/
|
|
81
|
+
message?: TranscriptMessage;
|
|
32
82
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/persistence/session-transcript.ts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-Code-compatible on-disk shape, theokit-native names).\n *\n * The theokit session format IS the Claude Code record shape (a `uuid`/`parentUuid` DAG of records with\n * structured `text`/`tool_use`/`tool_result`/`thinking` blocks) — so the ecosystem's read-side tools\n * parse our sessions AND, pointed at `~/.claude`, the Claude Code CLI can `--continue` them. This module\n * is the PURE core: append-per-turn record builders + the DAG reader that rebuilds `LlmMessage[]` for\n * resume. File I/O + loop wiring + append-only compaction live in the FS store.\n *\n * Reader mirrors `claude-code-log` dag.py: leaf = a uuid never used as a parentUuid; walk parentUuid to a\n * root (cycle-break); dedup a uuid across sessions keeping the earliest; a `compact_boundary` root\n * terminates the walk so a resume-after-compaction replays only the post-boundary continuation.\n *\n * referencia: knowledge-base/references/claude-code-log/claude_code_log/dag.py + models.py\n */\nimport { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nimport type { SessionRecord } from \"../../types/session-record.js\";\nimport type { LlmContentPart, LlmMessage, LlmToolResultPart } from \"../llm/types.js\";\nimport { redactSecrets } from \"../security/redact.js\";\nimport { replaceFileAtomic } from \"./atomic-write.js\";\n\n// The `SessionRecord` contract now lives in the domain `types/` layer (SE46 DIP\n// direction). Re-exported here so existing importers of this DAG-core module\n// keep resolving the same name.\nexport type { SessionRecord } from \"../../types/session-record.js\";\n\nexport interface SessionTranscriptOptions {\n cwd: string;\n sessionId: string;\n model: string;\n version?: string;\n}\n\nexport interface AssistantTurn {\n text?: string;\n thinking?: string;\n toolCalls?: Array<{ id: string; name: string; input: Record<string, unknown> }>;\n}\n\n/** Claude Code path convention: cwd with every non-alphanumeric replaced by `-`. */\nexport function encodeProjectDir(cwd: string): string {\n return cwd.replace(/[^a-zA-Z0-9]/g, \"-\");\n}\n\n/** Make a caller-supplied session id safe as a path component (no traversal). */\nexport function safeSessionId(id: string): string {\n return id.replace(/[^a-zA-Z0-9_-]/g, \"-\");\n}\n\nconst red = (s: string): string => redactSecrets(s);\n\n/** Deep-redact a structured value (tool input) preserving object shape. */\nfunction redactValue(value: unknown): unknown {\n try {\n return JSON.parse(redactSecrets(JSON.stringify(value ?? null)));\n } catch {\n return redactSecrets(String(value));\n }\n}\n\ntype Block = Record<string, unknown>;\n\n/**\n * Builds a session transcript append-by-append, maintaining the `parentUuid` chain. Each turn mints a\n * fresh `uuid` and parents on the previous record; `appendCompactBoundary` starts a NEW ROOT.\n */\nexport class SessionTranscript {\n #records: SessionRecord[] = [];\n #last: string | null = null;\n #opts: SessionTranscriptOptions;\n\n constructor(opts: SessionTranscriptOptions) {\n this.#opts = opts;\n }\n\n /**\n * Seed a transcript from records already on disk so a subsequent append parents\n * on the existing DAG leaf (the last record in file order). Prior records are\n * re-emitted verbatim by {@link records}, so the whole file rewrites atomically\n * as one append-only line set — never shrinking (SE40 compaction is append-only).\n */\n static fromRecords(\n prior: readonly SessionRecord[],\n opts: SessionTranscriptOptions,\n ): SessionTranscript {\n const t = new SessionTranscript(opts);\n t.#records = [...prior];\n t.#last = prior.length > 0 ? (prior[prior.length - 1]?.uuid ?? null) : null;\n return t;\n }\n\n #push(\n rec: Omit<SessionRecord, \"uuid\" | \"parentUuid\" | \"sessionId\" | \"timestamp\">,\n ): SessionRecord {\n const full: SessionRecord = {\n ...rec,\n uuid: randomUUID(),\n parentUuid: this.#last,\n sessionId: this.#opts.sessionId,\n timestamp: new Date().toISOString(),\n isSidechain: false,\n userType: \"external\",\n cwd: this.#opts.cwd,\n version: this.#opts.version ?? \"1.0.0-theokit\",\n };\n this.#records.push(full);\n this.#last = full.uuid;\n return full;\n }\n\n appendUserTurn(text: string): SessionRecord {\n return this.#push({\n type: \"user\",\n message: { role: \"user\", content: [{ type: \"text\", text: red(text) }] },\n });\n }\n\n appendAssistantTurn(turn: AssistantTurn): SessionRecord {\n const content: Block[] = [];\n if (turn.thinking) content.push({ type: \"thinking\", thinking: red(turn.thinking) });\n if (turn.text) content.push({ type: \"text\", text: red(turn.text) });\n for (const c of turn.toolCalls ?? []) {\n content.push({ type: \"tool_use\", id: c.id, name: c.name, input: redactValue(c.input) });\n }\n return this.#push({\n type: \"assistant\",\n message: {\n id: randomUUID(),\n type: \"message\",\n role: \"assistant\",\n model: this.#opts.model,\n content,\n },\n });\n }\n\n appendToolResults(\n results: Array<{ toolUseId: string; content: string; isError?: boolean }>,\n ): SessionRecord {\n const content: Block[] = results.map((r) => ({\n type: \"tool_result\",\n tool_use_id: r.toolUseId,\n content: red(r.content),\n is_error: r.isError === true,\n }));\n return this.#push({ type: \"user\", message: { role: \"user\", content } });\n }\n\n /** Append-only compaction: a `compact_boundary` system record becomes a NEW ROOT (parentUuid null). */\n appendCompactBoundary(meta: { preTokens: number; trigger: string }): SessionRecord {\n const rec: SessionRecord = {\n type: \"system\",\n uuid: randomUUID(),\n parentUuid: null,\n sessionId: this.#opts.sessionId,\n timestamp: new Date().toISOString(),\n subtype: \"compact_boundary\",\n compactMetadata: meta,\n isSidechain: false,\n userType: \"external\",\n cwd: this.#opts.cwd,\n version: this.#opts.version ?? \"1.0.0-theokit\",\n };\n this.#records.push(rec);\n this.#last = rec.uuid;\n return rec;\n }\n\n records(): readonly SessionRecord[] {\n return this.#records;\n }\n}\n\n// ─── Reader (DAG → LlmMessage[]) ──────────────────────────────────────────────────────────────────\n\n/** Earliest timestamp seen per session id. */\nfunction sessionFirstTimestamps(records: readonly SessionRecord[]): Map<string, string> {\n const first = new Map<string, string>();\n for (const r of records) {\n const cur = first.get(r.sessionId);\n if (cur === undefined || r.timestamp < cur) first.set(r.sessionId, r.timestamp);\n }\n return first;\n}\n\n/** Dedup a uuid across sessions: keep the record whose session's earliest timestamp is smallest. */\nfunction dedupByUuid(records: readonly SessionRecord[]): Map<string, SessionRecord> {\n const firstTs = sessionFirstTimestamps(records);\n const byUuid = new Map<string, SessionRecord>();\n for (const r of records) {\n const existing = byUuid.get(r.uuid);\n const wins =\n existing === undefined ||\n (firstTs.get(r.sessionId) ?? \"\") < (firstTs.get(existing.sessionId) ?? \"\");\n if (wins) byUuid.set(r.uuid, r);\n }\n return byUuid;\n}\n\n/** Map one structured block to an LlmContentPart (`undefined` for thinking — dropped on read, SE42/#122). */\nfunction blockToPart(b: Block): LlmContentPart | undefined {\n if (b.type === \"text\") return { type: \"text\", text: String(b.text ?? \"\") };\n if (b.type === \"tool_use\") {\n return {\n type: \"tool_use\",\n id: String(b.id),\n name: String(b.name),\n input: (b.input as Record<string, unknown>) ?? {},\n };\n }\n if (b.type === \"tool_result\") {\n const tr: LlmToolResultPart = {\n type: \"tool_result\",\n toolUseId: String(b.tool_use_id),\n content: typeof b.content === \"string\" ? b.content : JSON.stringify(b.content),\n isError: b.is_error === true,\n };\n return tr;\n }\n return undefined;\n}\n\n/** Map one record to an LlmMessage; `undefined` for non-conversational (system) records. */\nfunction recordToMessage(rec: SessionRecord): LlmMessage | undefined {\n if (rec.type !== \"user\" && rec.type !== \"assistant\") return undefined;\n const blocks = (rec.message?.content as Block[] | undefined) ?? [];\n const parts = blocks.map(blockToPart).filter((p): p is LlmContentPart => p !== undefined);\n return { role: rec.type, content: parts };\n}\n\n/** The most-recent leaf: the LAST record (in input order) whose uuid is never used as a parentUuid. */\nfunction findLatestLeaf(\n records: readonly SessionRecord[],\n byUuid: Map<string, SessionRecord>,\n parents: Set<string>,\n): SessionRecord | undefined {\n let leaf: SessionRecord | undefined;\n for (const r of records) {\n if (byUuid.get(r.uuid) === r && !parents.has(r.uuid)) leaf = r;\n }\n return leaf;\n}\n\n/** Walk parentUuid from a leaf to a root (cycle-safe), returning root→leaf order. */\nfunction walkToRoot(leaf: SessionRecord, byUuid: Map<string, SessionRecord>): SessionRecord[] {\n const chain: SessionRecord[] = [];\n const seen = new Set<string>();\n let cur: SessionRecord | undefined = leaf;\n while (cur !== undefined && !seen.has(cur.uuid)) {\n seen.add(cur.uuid);\n chain.push(cur);\n cur = cur.parentUuid !== null ? byUuid.get(cur.parentUuid) : undefined;\n }\n return chain.reverse();\n}\n\n/**\n * Rebuild the resumable `LlmMessage[]` from transcript records: dedup → find the most-recent leaf →\n * walk `parentUuid` to a root (a `compact_boundary` root terminates the walk) → map to LlmMessages.\n * Returns them in root→leaf (chronological replay) order.\n */\nexport function reconstructMessages(records: readonly SessionRecord[]): LlmMessage[] {\n const byUuid = dedupByUuid(records);\n const parents = new Set<string>();\n for (const r of byUuid.values()) if (r.parentUuid) parents.add(r.parentUuid);\n const leaf = findLatestLeaf(records, byUuid, parents);\n if (leaf === undefined) return [];\n\n const msgs: LlmMessage[] = [];\n for (const rec of walkToRoot(leaf, byUuid)) {\n const m = recordToMessage(rec);\n if (m !== undefined) msgs.push(m);\n }\n return msgs;\n}\n\n// ─── File I/O (the on-disk Claude layout) ─────────────────────────────────────────────────────────\n\n/** Default transcript base dir. `~/.theokit` isolates our sessions; set to `~/.claude` for CLI interop. */\nexport function defaultBaseDir(): string {\n return join(homedir(), \".theokit\");\n}\n\n/**\n * Expand a leading `~` / `~/` to the user's home dir. `node:path` does NOT expand `~`, so a\n * `baseDir: \"~/.claude\"` (the documented Claude Code CLI interop path) would otherwise resolve to a\n * literal `./~/.claude` under cwd and the CLI would never find the session. Absolute or relative\n * paths without a leading tilde pass through untouched.\n */\nexport function expandTilde(p: string): string {\n if (p === \"~\") return homedir();\n if (p.startsWith(\"~/\")) return join(homedir(), p.slice(2));\n return p;\n}\n\n/** The `.jsonl` path for a session: `<baseDir>/projects/<encoded-cwd>/<safe-sessionId>.jsonl`. */\nexport function transcriptPath(baseDir: string, cwd: string, sessionId: string): string {\n return join(baseDir, \"projects\", encodeProjectDir(cwd), `${safeSessionId(sessionId)}.jsonl`);\n}\n\n/** Write records as one JSONL line each (atomic; parent dir created). Returns the path. */\nexport async function writeTranscript(\n path: string,\n records: readonly SessionRecord[],\n): Promise<string> {\n await mkdir(dirname(path), { recursive: true });\n const body = records.map((r) => JSON.stringify(r)).join(\"\\n\");\n await replaceFileAtomic(path, records.length > 0 ? `${body}\\n` : \"\");\n return path;\n}\n\n/** Parse one JSONL line to a record; `undefined` for blank/torn/invalid lines (skipped on read). */\nfunction parseRecordLine(line: string): SessionRecord | undefined {\n const trimmed = line.trim();\n if (trimmed.length === 0) return undefined;\n try {\n const rec = JSON.parse(trimmed) as SessionRecord;\n return typeof rec.uuid === \"string\" && typeof rec.type === \"string\" ? rec : undefined;\n } catch {\n return undefined; // a torn last line (crash mid-write) — the rest of the DAG still reconstructs\n }\n}\n\n/** Parse a transcript `.jsonl` into records; a missing file yields `[]`; malformed lines are skipped. */\nexport async function readTranscript(path: string): Promise<SessionRecord[]> {\n let raw: string;\n try {\n raw = await readFile(path, \"utf8\");\n } catch (cause) {\n if ((cause as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n throw cause;\n }\n return raw\n .split(\"\\n\")\n .map(parseRecordLine)\n .filter((r): r is SessionRecord => r !== undefined);\n}\n"]}
|