@theokit/sdk 4.29.0 → 4.31.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/{agent-LBCEK6VH.cjs → agent-6GQBOHHA.cjs} +8 -8
  3. package/dist/{agent-LBCEK6VH.cjs.map → agent-6GQBOHHA.cjs.map} +1 -1
  4. package/dist/{agent-CdjSCbYz.d.cts → agent-Bzg2_uGr.d.cts} +55 -1
  5. package/dist/{agent-FBTLZI6V.js → agent-DY5LGZ5E.js} +7 -7
  6. package/dist/{agent-FBTLZI6V.js.map → agent-DY5LGZ5E.js.map} +1 -1
  7. package/dist/{agent-BZz4X8ZM.d.ts → agent-Ekv8y7_c.d.ts} +55 -1
  8. package/dist/agent.d.ts +15 -2
  9. package/dist/{chunk-EULKRTB5.js → chunk-4JWZRASX.js} +3 -3
  10. package/dist/{chunk-EULKRTB5.js.map → chunk-4JWZRASX.js.map} +1 -1
  11. package/dist/{chunk-YQAPEYUV.cjs → chunk-CYTAM3E6.cjs} +81 -43
  12. package/dist/chunk-CYTAM3E6.cjs.map +1 -0
  13. package/dist/{chunk-54YLX4Q6.cjs → chunk-FDGRQQWX.cjs} +5 -5
  14. package/dist/{chunk-54YLX4Q6.cjs.map → chunk-FDGRQQWX.cjs.map} +1 -1
  15. package/dist/{chunk-VUJ3NVDC.js → chunk-FZ75EZR5.js} +52 -14
  16. package/dist/chunk-FZ75EZR5.js.map +1 -0
  17. package/dist/chunk-ICSCKB3N.js +140 -0
  18. package/dist/chunk-ICSCKB3N.js.map +1 -0
  19. package/dist/{chunk-U6QGZHPN.js → chunk-PORDVVJS.js} +5 -6
  20. package/dist/chunk-PORDVVJS.js.map +1 -0
  21. package/dist/{chunk-NRSH7RJY.js → chunk-TLG444A6.js} +61 -13
  22. package/dist/chunk-TLG444A6.js.map +1 -0
  23. package/dist/{chunk-2HRYBRD7.cjs → chunk-U447MTG4.cjs} +5 -6
  24. package/dist/chunk-U447MTG4.cjs.map +1 -0
  25. package/dist/{chunk-2MF3IE2D.cjs → chunk-UKNMWCPZ.cjs} +63 -15
  26. package/dist/chunk-UKNMWCPZ.cjs.map +1 -0
  27. package/dist/{chunk-SQLZ7ONU.js → chunk-VUXLNVX7.js} +3 -3
  28. package/dist/{chunk-SQLZ7ONU.js.map → chunk-VUXLNVX7.js.map} +1 -1
  29. package/dist/{chunk-HK7ZHSAX.cjs → chunk-WQEQCJTZ.cjs} +64 -3
  30. package/dist/chunk-WQEQCJTZ.cjs.map +1 -0
  31. package/dist/{chunk-YU6KON2I.cjs → chunk-XJT5VACT.cjs} +3 -3
  32. package/dist/{chunk-YU6KON2I.cjs.map → chunk-XJT5VACT.cjs.map} +1 -1
  33. package/dist/{compact-session-OO7NVWPB.cjs → compact-session-2BFNMENR.cjs} +11 -11
  34. package/dist/{compact-session-OO7NVWPB.cjs.map → compact-session-2BFNMENR.cjs.map} +1 -1
  35. package/dist/{compact-session-OO2GD76G.js → compact-session-2JONXHLR.js} +3 -3
  36. package/dist/{compact-session-OO2GD76G.js.map → compact-session-2JONXHLR.js.map} +1 -1
  37. package/dist/{cron-CIIshMs3.d.cts → cron-CjzvXGT2.d.cts} +1 -1
  38. package/dist/{cron-dElBjDaL.d.ts → cron-D0Z29gI-.d.ts} +1 -1
  39. package/dist/cron.cjs +7 -7
  40. package/dist/cron.d.cts +2 -2
  41. package/dist/cron.d.ts +2 -2
  42. package/dist/cron.js +6 -6
  43. package/dist/eval.cjs +10 -11
  44. package/dist/eval.cjs.map +1 -1
  45. package/dist/eval.js +6 -7
  46. package/dist/eval.js.map +1 -1
  47. package/dist/fs-session-store-26WVVMC4.cjs +17 -0
  48. package/dist/{fs-session-store-KAUQYSGI.cjs.map → fs-session-store-26WVVMC4.cjs.map} +1 -1
  49. package/dist/fs-session-store-7AEI4STY.js +8 -0
  50. package/dist/{fs-session-store-ZKB5NN37.js.map → fs-session-store-7AEI4STY.js.map} +1 -1
  51. package/dist/index.cjs +28 -28
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +19 -6
  54. package/dist/index.d.ts +19 -6
  55. package/dist/index.js +8 -8
  56. package/dist/index.js.map +1 -1
  57. package/dist/{inject-session-6MJUSGZP.cjs → inject-session-MIFEKATN.cjs} +4 -4
  58. package/dist/{inject-session-6MJUSGZP.cjs.map → inject-session-MIFEKATN.cjs.map} +1 -1
  59. package/dist/{inject-session-KOFHS5K3.js → inject-session-NNSCCIVP.js} +3 -3
  60. package/dist/{inject-session-KOFHS5K3.js.map → inject-session-NNSCCIVP.js.map} +1 -1
  61. package/dist/internal/llm/retrying-client.d.ts +29 -0
  62. package/dist/internal/persistence/index.cjs +18 -19
  63. package/dist/internal/persistence/index.cjs.map +1 -1
  64. package/dist/internal/persistence/index.js +1 -2
  65. package/dist/internal/persistence/index.js.map +1 -1
  66. package/dist/internal/plugins/types.d.cts +1 -1
  67. package/dist/internal/plugins/types.d.ts +1 -1
  68. package/dist/persistence.cjs +10 -11
  69. package/dist/persistence.cjs.map +1 -1
  70. package/dist/persistence.js +1 -2
  71. package/dist/persistence.js.map +1 -1
  72. package/dist/subagents-loader.d.cts +1 -1
  73. package/dist/subagents-loader.d.ts +1 -1
  74. package/dist/types/plugin.d.ts +32 -0
  75. package/package.json +1 -1
  76. package/dist/chunk-2HRYBRD7.cjs.map +0 -1
  77. package/dist/chunk-2MF3IE2D.cjs.map +0 -1
  78. package/dist/chunk-C7PICHRF.cjs +0 -68
  79. package/dist/chunk-C7PICHRF.cjs.map +0 -1
  80. package/dist/chunk-HK7ZHSAX.cjs.map +0 -1
  81. package/dist/chunk-HZQEDNF6.js +0 -66
  82. package/dist/chunk-HZQEDNF6.js.map +0 -1
  83. package/dist/chunk-NRSH7RJY.js.map +0 -1
  84. package/dist/chunk-R6ZP6KNB.js +0 -80
  85. package/dist/chunk-R6ZP6KNB.js.map +0 -1
  86. package/dist/chunk-U6QGZHPN.js.map +0 -1
  87. package/dist/chunk-VUJ3NVDC.js.map +0 -1
  88. package/dist/chunk-YQAPEYUV.cjs.map +0 -1
  89. package/dist/fs-session-store-KAUQYSGI.cjs +0 -17
  90. package/dist/fs-session-store-ZKB5NN37.js +0 -8
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkC7PICHRF_cjs = require('./chunk-C7PICHRF.cjs');
3
+ var chunkWQEQCJTZ_cjs = require('./chunk-WQEQCJTZ.cjs');
4
4
  var chunk4SXHEZIV_cjs = require('./chunk-4SXHEZIV.cjs');
5
5
  var promises = require('fs/promises');
6
6
  var path = require('path');
@@ -19,13 +19,12 @@ var FsSessionStore = class {
19
19
  if (records.length === 0) return;
20
20
  const path$1 = chunk4SXHEZIV_cjs.transcriptPath(this.#baseDir, this.#cwd, agentId);
21
21
  await promises.mkdir(path.dirname(path$1), { recursive: true });
22
- await chunkC7PICHRF_cjs.withFileLock(path$1, async () => {
23
- const prior = await chunk4SXHEZIV_cjs.readTranscript(path$1);
24
- await chunk4SXHEZIV_cjs.writeTranscript(path$1, [...prior, ...records]);
22
+ await chunkWQEQCJTZ_cjs.withFileLock(path$1, async () => {
23
+ for (const record of records) chunkWQEQCJTZ_cjs.appendJsonl(path$1, record);
25
24
  });
26
25
  }
27
26
  };
28
27
 
29
28
  exports.FsSessionStore = FsSessionStore;
30
- //# sourceMappingURL=chunk-2HRYBRD7.cjs.map
31
- //# sourceMappingURL=chunk-2HRYBRD7.cjs.map
29
+ //# sourceMappingURL=chunk-U447MTG4.cjs.map
30
+ //# sourceMappingURL=chunk-U447MTG4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/persistence/fs-session-store.ts"],"names":["readTranscript","transcriptPath","path","mkdir","dirname","withFileLock","appendJsonl"],"mappings":";;;;;;;AA6CO,IAAM,iBAAN,MAA6C;AAAA,EACzC,QAAA;AAAA,EACA,IAAA;AAAA,EAET,YAAY,OAAA,EAAgC;AAC1C,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,OAAA;AACxB,IAAA,IAAA,CAAK,OAAO,OAAA,CAAQ,GAAA;AAAA,EACtB;AAAA,EAEA,MAAM,YAAY,OAAA,EAA2C;AAC3D,IAAA,OAAOA,iCAAeC,gCAAA,CAAe,IAAA,CAAK,UAAU,IAAA,CAAK,IAAA,EAAM,OAAO,CAAC,CAAA;AAAA,EACzE;AAAA,EAEA,MAAM,aAAA,CAAc,OAAA,EAAiB,OAAA,EAAkD;AAErF,IAAA,IAAI,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC1B,IAAA,MAAMC,SAAOD,gCAAA,CAAe,IAAA,CAAK,QAAA,EAAU,IAAA,CAAK,MAAM,OAAO,CAAA;AAE7D,IAAA,MAAME,eAAMC,YAAA,CAAQF,MAAI,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AAC9C,IAAA,MAAMG,8BAAA,CAAaH,QAAM,YAAY;AAgBnC,MAAA,KAAA,MAAW,MAAA,IAAU,OAAA,EAASI,6BAAA,CAAYJ,MAAA,EAAM,MAAM,CAAA;AAAA,IACxD,CAAC,CAAA;AAAA,EACH;AACF","file":"chunk-U447MTG4.cjs","sourcesContent":["/**\n * SE41 — `FsSessionStore`, the DEFAULT reference implementation of the pluggable\n * {@link SessionStore} seam. It reads and append-writes the native Claude-shaped\n * `.jsonl` transcript at `<baseDir>/projects/<encoded-cwd>/<agentId>.jsonl` — the\n * exact on-disk format SE40 introduced (the file the Claude Code CLI can\n * `--continue`). Omitting `local.sessionStore` resolves to this store, so the\n * default persistence path is byte-identical to SE40 behavior.\n *\n * `readRecords` is `readTranscript(transcriptPath(...))` (a missing session →\n * `[]`, not an error — a fresh agent has no history). `appendRecords` is a TRUE\n * append: it reads the prior records, concatenates the new-turn delta, and\n * rewrites the whole line set atomically under the SE40 cross-process file lock\n * (`writeTranscript` never shrinks — the native format is an append-only\n * `parentUuid` DAG). The parent dir is created BEFORE acquiring the lock because\n * the lock's companion `<path>.lock` file needs an existing parent dir (the SE40\n * `mkdir(dirname)`-before-lock fix).\n *\n * @internal\n */\n\nimport { mkdir } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\n\nimport type { SessionStore } from \"../../types/session-store.js\";\nimport { withFileLock } from \"./file-lock.js\";\nimport { appendJsonl } from \"./jsonl.js\";\nimport {\n readTranscript,\n type SessionRecord,\n transcriptPath,\n} from \"./session-transcript.js\";\n\n/** Options identifying the on-disk transcript location for the FS default store. */\nexport interface FsSessionStoreOptions {\n /** Transcript base dir (`~/.theokit` default, `~/.claude` for CLI interop) — already `~`-expanded. */\n baseDir: string;\n /** The workspace cwd whose encoded form is the transcript project dir. */\n cwd: string;\n}\n\n/**\n * The default `SessionStore` — reads/append-writes the native `.jsonl` transcript.\n *\n * @internal\n */\nexport class FsSessionStore implements SessionStore {\n readonly #baseDir: string;\n readonly #cwd: string;\n\n constructor(options: FsSessionStoreOptions) {\n this.#baseDir = options.baseDir;\n this.#cwd = options.cwd;\n }\n\n async readRecords(agentId: string): Promise<SessionRecord[]> {\n return readTranscript(transcriptPath(this.#baseDir, this.#cwd, agentId));\n }\n\n async appendRecords(agentId: string, records: readonly SessionRecord[]): Promise<void> {\n // Empty delta → nothing to persist (avoids an unnecessary lock + rewrite).\n if (records.length === 0) return;\n const path = transcriptPath(this.#baseDir, this.#cwd, agentId);\n // mkdir BEFORE the lock: withFileLock's companion `<path>.lock` needs the parent dir.\n await mkdir(dirname(path), { recursive: true });\n await withFileLock(path, async () => {\n // M93 — acrescenta o DELTA em vez de reescrever o arquivo inteiro.\n //\n // Antes: `readTranscript` + `writeTranscript` de tudo, por turno. O(n) de I/O **e** de parse a\n // cada turno, O(n²) por sessão — a nota do consumidor em `agents/lib/session/backtrack.ts`\n // registra 1,4 MB / 3000 linhas em 200 turnos.\n //\n // Correto porque o formato **já é append-only**: o DAG de `parentUuid` não depende da ordem de\n // linha, e cada registro carrega o próprio pai. `appendJsonl` **já existia no pacote** e tinha um\n // único chamador (`eval/runner.ts`) — a primitiva estava lá, o store é que a ignorava (rung 4).\n //\n // O `withFileLock` **permanece**: ele é o que serializa dois `appendRecords` concorrentes, e\n // trocar a operação não pode afrouxar a serialização.\n //\n // `writeTranscript` continua existindo para **compactação**, a única operação que legitimamente\n // reescreve o arquivo.\n for (const record of records) appendJsonl(path, record);\n });\n }\n}\n"]}
@@ -705,7 +705,7 @@ async function resolveBedrockToken(region) {
705
705
  return cachedToken.value;
706
706
  }
707
707
  try {
708
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-2MF3IE2D.cjs', document.baseURI).href)));
708
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-UKNMWCPZ.cjs', document.baseURI).href)));
709
709
  const gen = r("@aws/bedrock-token-generator");
710
710
  if (typeof gen.getToken !== "function") return void 0;
711
711
  const providers = r("@aws-sdk/credential-providers");
@@ -1926,6 +1926,60 @@ function abortError(signal) {
1926
1926
  return new Error("AbortError");
1927
1927
  }
1928
1928
 
1929
+ // src/internal/llm/retrying-client.ts
1930
+ var MAX_TENTATIVAS = 3;
1931
+ function ehTransitorio(err) {
1932
+ if (err instanceof chunkA44COQJJ_cjs.AuthenticationError) return false;
1933
+ if (err instanceof chunkA44COQJJ_cjs.RateLimitError) {
1934
+ const status = err.metadata?.statusCode ?? 429;
1935
+ return status !== 402;
1936
+ }
1937
+ return err instanceof Error && !/\b4\d\d\b/.test(err.message);
1938
+ }
1939
+ function dicaDeRetryAfterMs(err) {
1940
+ if (!(err instanceof chunkA44COQJJ_cjs.RateLimitError)) return void 0;
1941
+ const segundos = err.metadata?.retryAfter;
1942
+ return typeof segundos === "number" && segundos > 0 ? segundos * 1e3 : void 0;
1943
+ }
1944
+ var RetryingLlmClient = class {
1945
+ #inner;
1946
+ #rng;
1947
+ constructor(inner, opts) {
1948
+ this.#inner = inner;
1949
+ this.#rng = opts?.rng;
1950
+ }
1951
+ get name() {
1952
+ return this.#inner.name;
1953
+ }
1954
+ async *stream(request, signal) {
1955
+ let ultimoErro;
1956
+ for (let tentativa = 0; tentativa < MAX_TENTATIVAS; tentativa++) {
1957
+ if (signal.aborted) throw ultimoErro ?? new Error("aborted");
1958
+ try {
1959
+ const gen = this.#inner.stream(request, signal);
1960
+ let passo = await gen.next();
1961
+ while (passo.done !== true) {
1962
+ yield passo.value;
1963
+ passo = await gen.next();
1964
+ }
1965
+ return passo.value;
1966
+ } catch (err) {
1967
+ ultimoErro = err;
1968
+ const ultima = tentativa === MAX_TENTATIVAS - 1;
1969
+ if (ultima || !ehTransitorio(err)) throw err;
1970
+ const dica = dicaDeRetryAfterMs(err);
1971
+ const ms = chunkLUSXDZPV_cjs.computeBackoffMs({
1972
+ attempt: tentativa,
1973
+ ...dica !== void 0 ? { retryAfterMs: dica } : {},
1974
+ ...this.#rng !== void 0 ? { rng: this.#rng } : {}
1975
+ });
1976
+ await chunkLUSXDZPV_cjs.sleepWithAbort(ms, signal);
1977
+ }
1978
+ }
1979
+ throw ultimoErro ?? new Error("retry esgotado sem erro registrado");
1980
+ }
1981
+ };
1982
+
1929
1983
  // src/internal/llm/responses.ts
1930
1984
  function messageToInputItems(message) {
1931
1985
  const items = [];
@@ -2202,7 +2256,7 @@ async function resolveVertexAccessToken() {
2202
2256
  async function getAuthClientOrThrow() {
2203
2257
  let mod;
2204
2258
  try {
2205
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-2MF3IE2D.cjs', document.baseURI).href)));
2259
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-UKNMWCPZ.cjs', document.baseURI).href)));
2206
2260
  mod = r("google-auth-library");
2207
2261
  } catch (err) {
2208
2262
  const isModuleMissing = err instanceof Error && (err.message.includes("Cannot find module") || err.code === "MODULE_NOT_FOUND");
@@ -2382,11 +2436,8 @@ function buildClient(name, routerOptions) {
2382
2436
  const resilience = routerOptions.onRateLimit !== void 0 ? { onRateLimit: routerOptions.onRateLimit } : {};
2383
2437
  const ambient = chunkLUSXDZPV_cjs.currentCredentialPool(name);
2384
2438
  if (ambient !== void 0) {
2385
- return new PoolAwareLlmClient(
2386
- ambient,
2387
- (apiKey) => selectTransport(profile, apiKey),
2388
- void 0,
2389
- resilience
2439
+ return new RetryingLlmClient(
2440
+ new PoolAwareLlmClient(ambient, (apiKey) => selectTransport(profile, apiKey), void 0, resilience)
2390
2441
  );
2391
2442
  }
2392
2443
  const poolKeys = filterPoolKeys(routerOptions.apiKeys?.[name]);
@@ -2412,16 +2463,13 @@ function buildPoolOrSingle(args) {
2412
2463
  );
2413
2464
  const pool = new chunkLUSXDZPV_cjs.CredentialPool(name, entries, strategy);
2414
2465
  const resilience = routerOptions.onRateLimit !== void 0 ? { onRateLimit: routerOptions.onRateLimit } : {};
2415
- return new PoolAwareLlmClient(
2416
- pool,
2417
- (apiKey2) => selectTransport(profile, apiKey2),
2418
- void 0,
2419
- resilience
2466
+ return new RetryingLlmClient(
2467
+ new PoolAwareLlmClient(pool, (apiKey2) => selectTransport(profile, apiKey2), void 0, resilience)
2420
2468
  );
2421
2469
  }
2422
2470
  const apiKey = poolKeys?.[0] ?? resolveApiKey(profile.envVars) ?? sentinelForNoAuth(profile) ?? sentinelForLazyAuth(profile);
2423
2471
  if (apiKey === void 0) return void 0;
2424
- return selectTransport(profile, apiKey);
2472
+ return new RetryingLlmClient(selectTransport(profile, apiKey));
2425
2473
  }
2426
2474
  function resolveBaseUrlEnvOverride(providerName) {
2427
2475
  switch (providerName) {
@@ -2859,5 +2907,5 @@ exports.resolveProviderChain = resolveProviderChain;
2859
2907
  exports.resolveSummarizerRoute = resolveSummarizerRoute;
2860
2908
  exports.shouldAutoCompact = shouldAutoCompact;
2861
2909
  exports.tryFirstEvent = tryFirstEvent;
2862
- //# sourceMappingURL=chunk-2MF3IE2D.cjs.map
2863
- //# sourceMappingURL=chunk-2MF3IE2D.cjs.map
2910
+ //# sourceMappingURL=chunk-UKNMWCPZ.cjs.map
2911
+ //# sourceMappingURL=chunk-UKNMWCPZ.cjs.map