@theokit/sdk 5.15.0 → 5.15.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 (49) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{agent-DRDGUU6T.js → agent-66U5QCPF.js} +5 -5
  3. package/dist/{agent-DRDGUU6T.js.map → agent-66U5QCPF.js.map} +1 -1
  4. package/dist/{agent-B6FQad6P.d.cts → agent-BL4kxgwq.d.cts} +7 -1
  5. package/dist/{agent-B6C9i_qu.d.ts → agent-ByDx7K30.d.ts} +7 -1
  6. package/dist/{agent-VI2HITPT.cjs → agent-CB27KF6O.cjs} +6 -6
  7. package/dist/{agent-VI2HITPT.cjs.map → agent-CB27KF6O.cjs.map} +1 -1
  8. package/dist/{chunk-IOBHFP2E.js → chunk-26GI3OYA.js} +71 -4
  9. package/dist/chunk-26GI3OYA.js.map +1 -0
  10. package/dist/{chunk-64ECM3XM.cjs → chunk-26UQG242.cjs} +49 -49
  11. package/dist/{chunk-64ECM3XM.cjs.map → chunk-26UQG242.cjs.map} +1 -1
  12. package/dist/{chunk-DJKGDLYZ.cjs → chunk-3E3VSMB6.cjs} +73 -6
  13. package/dist/{chunk-DJKGDLYZ.cjs.map → chunk-3E3VSMB6.cjs.map} +1 -1
  14. package/dist/{chunk-U7PRI3XM.cjs → chunk-FBIDOOJM.cjs} +3 -3
  15. package/dist/{chunk-U7PRI3XM.cjs.map → chunk-FBIDOOJM.cjs.map} +1 -1
  16. package/dist/{chunk-ARC2V7NY.js → chunk-O2RCS3SJ.js} +3 -3
  17. package/dist/{chunk-ARC2V7NY.js.map → chunk-O2RCS3SJ.js.map} +1 -1
  18. package/dist/{chunk-KMFBNKCT.cjs → chunk-TRPRTZEH.cjs} +4 -4
  19. package/dist/{chunk-KMFBNKCT.cjs.map → chunk-TRPRTZEH.cjs.map} +1 -1
  20. package/dist/{chunk-23SS4ID4.js → chunk-VNRNZ3WI.js} +3 -3
  21. package/dist/{chunk-23SS4ID4.js.map → chunk-VNRNZ3WI.js.map} +1 -1
  22. package/dist/{chunk-5M5GQYBM.js → chunk-ZQWRUJHE.js} +6 -6
  23. package/dist/{chunk-5M5GQYBM.js.map → chunk-ZQWRUJHE.js.map} +1 -1
  24. package/dist/{compact-session-NX7HUNTB.cjs → compact-session-CHBJOYWP.cjs} +12 -12
  25. package/dist/{compact-session-NX7HUNTB.cjs.map → compact-session-CHBJOYWP.cjs.map} +1 -1
  26. package/dist/{compact-session-Q5IGNFPW.js → compact-session-F3J3FMEU.js} +3 -3
  27. package/dist/{compact-session-Q5IGNFPW.js.map → compact-session-F3J3FMEU.js.map} +1 -1
  28. package/dist/{cron-Bh3aWgQ2.d.cts → cron-B7KH9sHW.d.cts} +1 -1
  29. package/dist/{cron-CCDxeeFZ.d.ts → cron-FEO7UAQF.d.ts} +1 -1
  30. package/dist/cron.cjs +5 -5
  31. package/dist/cron.d.cts +2 -2
  32. package/dist/cron.d.ts +2 -2
  33. package/dist/cron.js +4 -4
  34. package/dist/eval.cjs +4 -4
  35. package/dist/eval.js +3 -3
  36. package/dist/index.cjs +31 -31
  37. package/dist/index.d.cts +3 -3
  38. package/dist/index.d.ts +3 -3
  39. package/dist/index.js +7 -7
  40. package/dist/{inject-session-4ROYLZHY.js → inject-session-LC2TROHM.js} +3 -3
  41. package/dist/{inject-session-4ROYLZHY.js.map → inject-session-LC2TROHM.js.map} +1 -1
  42. package/dist/{inject-session-AWKDCGHV.cjs → inject-session-T4RXANG3.cjs} +4 -4
  43. package/dist/{inject-session-AWKDCGHV.cjs.map → inject-session-T4RXANG3.cjs.map} +1 -1
  44. package/dist/internal/llm/hermes-tool-extract.d.ts +2 -0
  45. package/dist/subagents-loader.d.cts +1 -1
  46. package/dist/subagents-loader.d.ts +1 -1
  47. package/dist/types/hooks.d.ts +7 -1
  48. package/package.json +1 -1
  49. package/dist/chunk-IOBHFP2E.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#956](https://github.com/usetheokit/theokit-sdk/pull/956) [`2604fa9`](https://github.com/usetheokit/theokit-sdk/commit/2604fa9e54454ac8b50dfbfb8dcd02dfc57d0d01) Thanks [@aifactory-paulohenriquevn](https://github.com/apps/aifactory-paulohenriquevn)! - llm: recover several `print(default_api.<tool>(…))` calls under one Gemini `<ctrl42>call` marker (calls to undeclared tools stay text), and name the recovered format in the diagnostic.
8
+
9
+ - [#954](https://github.com/usetheokit/theokit-sdk/pull/954) [`c5c236a`](https://github.com/usetheokit/theokit-sdk/commit/c5c236abd0815b6e4ce9929e4ebd89e36bb04ddd) Thanks [@aifactory-paulohenriquevn](https://github.com/apps/aifactory-paulohenriquevn)! - Streaming no longer emits Gemini's `<ctrl42>call print(default_api.<tool>(...))` text as `text_delta` for a declared tool; the call is recovered when the stream ends.
10
+
11
+ - [#948](https://github.com/usetheokit/theokit-sdk/pull/948) [`f4f87f0`](https://github.com/usetheokit/theokit-sdk/commit/f4f87f0382796e539a2a4e682ac3c2c567e653cc) Thanks [@aifactory-paulohenriquevn](https://github.com/apps/aifactory-paulohenriquevn)! - Documentation: the `postRun` hook fires on a failed run, but it is internal-only. `.theokit/hooks.json` cannot register it (Claude Code has no per-run event), and `Stop` fires only on a finished run. `HookEvent` now says so.
12
+
13
+ - [#952](https://github.com/usetheokit/theokit-sdk/pull/952) [`3be74fb`](https://github.com/usetheokit/theokit-sdk/commit/3be74fb098206f7b6a15da826ff464eff588d044) Thanks [@aifactory-paulohenriquevn](https://github.com/apps/aifactory-paulohenriquevn)! - README "Failed runs" states that under `throwOnError` the canonical error code is `err.metadata?.code ?? err.code`, since a provider-mapped `err.code` can be prefixed.
14
+
3
15
  ## 5.15.0
4
16
 
5
17
  ### Minor Changes
@@ -1,6 +1,6 @@
1
- export { Agent } from './chunk-5M5GQYBM.js';
1
+ export { Agent } from './chunk-ZQWRUJHE.js';
2
2
  import './chunk-HWMGR3HA.js';
3
- import './chunk-23SS4ID4.js';
3
+ import './chunk-VNRNZ3WI.js';
4
4
  import './chunk-K2BQQ445.js';
5
5
  import './chunk-3BBTHFGJ.js';
6
6
  import './chunk-HJ2LV464.js';
@@ -10,7 +10,7 @@ import './chunk-H73MEMQB.js';
10
10
  import './chunk-QK2ERTO3.js';
11
11
  import './chunk-LCCT5ZXJ.js';
12
12
  import './chunk-RGVMJU57.js';
13
- import './chunk-IOBHFP2E.js';
13
+ import './chunk-26GI3OYA.js';
14
14
  import './chunk-NK5EOTDY.js';
15
15
  import './chunk-2XC6KDJM.js';
16
16
  import './chunk-7ACS6P5Z.js';
@@ -59,5 +59,5 @@ import './chunk-5IUDICRK.js';
59
59
  import './chunk-Q7GYMXVC.js';
60
60
  import './chunk-TNFOU6SB.js';
61
61
  import './chunk-3OY6H3I7.js';
62
- //# sourceMappingURL=agent-DRDGUU6T.js.map
63
- //# sourceMappingURL=agent-DRDGUU6T.js.map
62
+ //# sourceMappingURL=agent-66U5QCPF.js.map
63
+ //# sourceMappingURL=agent-66U5QCPF.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-DRDGUU6T.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-66U5QCPF.js"}
@@ -171,7 +171,13 @@ interface BudgetTracker {
171
171
  *
172
172
  * @public
173
173
  */
174
- /** The five lifecycle events the runtime actually fires. */
174
+ /**
175
+ * The five lifecycle events the runtime actually fires.
176
+ *
177
+ * `postRun` (once per run, including a failed run) is internal-only: it is reachable from the
178
+ * SDK's own hook config and spies, but `.theokit/hooks.json` (Claude Code event names) cannot
179
+ * register it, because no Claude Code event means "end of a run". `Stop` fires only on a finished run.
180
+ */
175
181
  type HookEvent = "preRun" | "postRun" | "preToolUse" | "postToolUse" | "stop";
176
182
  /**
177
183
  * #631 — what the consumer is shown when asked to approve a hook.
@@ -171,7 +171,13 @@ interface BudgetTracker {
171
171
  *
172
172
  * @public
173
173
  */
174
- /** The five lifecycle events the runtime actually fires. */
174
+ /**
175
+ * The five lifecycle events the runtime actually fires.
176
+ *
177
+ * `postRun` (once per run, including a failed run) is internal-only: it is reachable from the
178
+ * SDK's own hook config and spies, but `.theokit/hooks.json` (Claude Code event names) cannot
179
+ * register it, because no Claude Code event means "end of a run". `Stop` fires only on a finished run.
180
+ */
175
181
  type HookEvent = "preRun" | "postRun" | "preToolUse" | "postToolUse" | "stop";
176
182
  /**
177
183
  * #631 — what the consumer is shown when asked to approve a hook.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk64ECM3XM_cjs = require('./chunk-64ECM3XM.cjs');
3
+ var chunk26UQG242_cjs = require('./chunk-26UQG242.cjs');
4
4
  require('./chunk-L7JPXZ2C.cjs');
5
- require('./chunk-U7PRI3XM.cjs');
5
+ require('./chunk-FBIDOOJM.cjs');
6
6
  require('./chunk-BUUUWQMB.cjs');
7
7
  require('./chunk-NEH3BPFD.cjs');
8
8
  require('./chunk-7YUPSBDV.cjs');
@@ -12,7 +12,7 @@ require('./chunk-GHX4P3V2.cjs');
12
12
  require('./chunk-RS7YQR4X.cjs');
13
13
  require('./chunk-VWYFGE27.cjs');
14
14
  require('./chunk-FTXY4D44.cjs');
15
- require('./chunk-DJKGDLYZ.cjs');
15
+ require('./chunk-3E3VSMB6.cjs');
16
16
  require('./chunk-55LLQFHW.cjs');
17
17
  require('./chunk-YJNYDJ2T.cjs');
18
18
  require('./chunk-3F53FLQ7.cjs');
@@ -66,7 +66,7 @@ require('./chunk-RNXXYF22.cjs');
66
66
 
67
67
  Object.defineProperty(exports, "Agent", {
68
68
  enumerable: true,
69
- get: function () { return chunk64ECM3XM_cjs.Agent; }
69
+ get: function () { return chunk26UQG242_cjs.Agent; }
70
70
  });
71
- //# sourceMappingURL=agent-VI2HITPT.cjs.map
72
- //# sourceMappingURL=agent-VI2HITPT.cjs.map
71
+ //# sourceMappingURL=agent-CB27KF6O.cjs.map
72
+ //# sourceMappingURL=agent-CB27KF6O.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-VI2HITPT.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-CB27KF6O.cjs"}
@@ -1539,16 +1539,38 @@ function pickString(record, key) {
1539
1539
  // src/internal/llm/hermes-tool-extract.ts
1540
1540
  var HERMES_BLOCK = /<function=\s*([^>\s]+)\s*>([\s\S]*?)<\/tool_call>/g;
1541
1541
  var HERMES_PARAM = /<parameter=\s*([^>\s]+)\s*>([\s\S]*?)<\/parameter>/g;
1542
+ var CTRL_CALL_SRC = String.raw`print\(\s*default_api\.([A-Za-z_]\w*)\(([\s\S]*?)\)\s*\)(?=\s*(?:print\(\s*default_api\.|<ctrl\d+>|$))`;
1543
+ var CTRL_BLOCK = new RegExp(`<ctrl42>call\\s*((?:${CTRL_CALL_SRC}\\s*)+)(?=<ctrl\\d+>|$)`, "g");
1544
+ var CTRL_MARKER = "<ctrl42>call";
1545
+ var CTRL_PREFIX = "print(default_api.";
1542
1546
  function extractHermesToolCalls(content, makeId, allowedToolNames) {
1543
1547
  const isPromoted = (name) => name.length > 0 && (allowedToolNames === void 0 || allowedToolNames.has(name));
1544
1548
  const toolCalls = [];
1545
1549
  const droppedNames = [];
1550
+ const formats = /* @__PURE__ */ new Set();
1551
+ for (const block of content.matchAll(CTRL_BLOCK)) {
1552
+ for (const call of (block[1] ?? "").matchAll(new RegExp(CTRL_CALL_SRC, "g"))) {
1553
+ const name = call[1] ?? "";
1554
+ if (!isPromoted(name)) {
1555
+ if (allowedToolNames !== void 0) droppedNames.push(name);
1556
+ continue;
1557
+ }
1558
+ toolCalls.push({
1559
+ type: "tool_use",
1560
+ id: makeId(),
1561
+ name,
1562
+ input: parseCtrlArgs(call[2] ?? "")
1563
+ });
1564
+ formats.add("gemini-ctrl42");
1565
+ }
1566
+ }
1546
1567
  for (const block of content.matchAll(HERMES_BLOCK)) {
1547
1568
  const name = (block[1] ?? "").trim();
1548
1569
  if (!isPromoted(name)) {
1549
1570
  if (name.length > 0 && allowedToolNames !== void 0) droppedNames.push(name);
1550
1571
  continue;
1551
1572
  }
1573
+ formats.add("hermes");
1552
1574
  toolCalls.push({
1553
1575
  type: "tool_use",
1554
1576
  id: makeId(),
@@ -1557,10 +1579,37 @@ function extractHermesToolCalls(content, makeId, allowedToolNames) {
1557
1579
  });
1558
1580
  }
1559
1581
  const residualText = toolCalls.length === 0 ? content : content.replace(
1582
+ CTRL_BLOCK,
1583
+ (_full, calls) => keepUnpromotedCtrl(calls, isPromoted)
1584
+ ).replace(
1560
1585
  HERMES_BLOCK,
1561
1586
  (full, rawName) => isPromoted((rawName ?? "").trim()) ? "" : full
1562
1587
  ).trim();
1563
- return { toolCalls, residualText, droppedNames };
1588
+ return { toolCalls, residualText, droppedNames, formats: [...formats] };
1589
+ }
1590
+ function keepUnpromotedCtrl(calls, isPromoted) {
1591
+ const kept = [...calls.matchAll(new RegExp(CTRL_CALL_SRC, "g"))].filter((c) => !isPromoted(c[1] ?? "")).map((c) => c[0]);
1592
+ return kept.length === 0 ? "" : `<ctrl42>call
1593
+ ${kept.join("\n")}`;
1594
+ }
1595
+ var CTRL_ARG = /\s*([A-Za-z_]\w*)\s*=\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^,]+)\s*(?:,|$)/y;
1596
+ function parseCtrlArgs(raw) {
1597
+ const input = {};
1598
+ CTRL_ARG.lastIndex = 0;
1599
+ for (let m = CTRL_ARG.exec(raw); m !== null; m = CTRL_ARG.exec(raw)) {
1600
+ input[m[1]] = parseCtrlValue(m[2].trim());
1601
+ }
1602
+ return sanitizeToolInput(input, { trim: true }).value;
1603
+ }
1604
+ function parseCtrlValue(v) {
1605
+ const q = v[0];
1606
+ if ((q === '"' || q === "'") && v.length >= 2 && v.endsWith(q)) {
1607
+ return v.slice(1, -1).replace(/\\(.)/g, (_, c) => c === "n" ? "\n" : c === "t" ? " " : c);
1608
+ }
1609
+ if (v === "True") return true;
1610
+ if (v === "False") return false;
1611
+ if (v === "None") return null;
1612
+ return /^-?\d+(\.\d+)?$/.test(v) ? Number(v) : v;
1564
1613
  }
1565
1614
  function parseHermesParams(inner) {
1566
1615
  const input = {};
@@ -1578,6 +1627,10 @@ var isStreamWs = (c) => c === " " || c === " " || c === "\n" || c === "\r";
1578
1627
  function streamToolCallBufferState(held, allowedToolNames, cap = DEFAULT_STREAM_BUFFER_CAP) {
1579
1628
  if (allowedToolNames.size === 0) return "impossible";
1580
1629
  const t = held.trimStart();
1630
+ if (t.startsWith("<c")) return ctrlState(t, held.length, allowedToolNames, cap);
1631
+ return functionMarkerState(held, t, allowedToolNames, cap);
1632
+ }
1633
+ function functionMarkerState(held, t, allowedToolNames, cap) {
1581
1634
  if (t.length < STREAM_MARKER.length) {
1582
1635
  return STREAM_MARKER.startsWith(t) ? "possible" : "impossible";
1583
1636
  }
@@ -1589,6 +1642,20 @@ function streamToolCallBufferState(held, allowedToolNames, cap = DEFAULT_STREAM_
1589
1642
  if (!nameOk) return "impossible";
1590
1643
  return held.length > cap ? "impossible" : "possible";
1591
1644
  }
1645
+ function ctrlState(t, heldLength, allowedToolNames, cap) {
1646
+ if (t.length < CTRL_MARKER.length) return CTRL_MARKER.startsWith(t) ? "possible" : "impossible";
1647
+ if (!t.startsWith(CTRL_MARKER)) return "impossible";
1648
+ const rest = t.slice(CTRL_MARKER.length).trimStart();
1649
+ if (rest.length <= CTRL_PREFIX.length)
1650
+ return CTRL_PREFIX.startsWith(rest) ? "possible" : "impossible";
1651
+ if (!rest.startsWith(CTRL_PREFIX)) return "impossible";
1652
+ const afterPrefix = rest.slice(CTRL_PREFIX.length);
1653
+ const paren = afterPrefix.indexOf("(");
1654
+ const name = paren === -1 ? afterPrefix : afterPrefix.slice(0, paren);
1655
+ if (!/^\w*$/.test(name)) return "impossible";
1656
+ const nameOk = paren === -1 ? someToolNameStartsWith(allowedToolNames, name) : allowedToolNames.has(name);
1657
+ return nameOk && heldLength <= cap ? "possible" : "impossible";
1658
+ }
1592
1659
  function parseStreamMarkerName(t) {
1593
1660
  let cursor = STREAM_MARKER.length;
1594
1661
  while (cursor < t.length && isStreamWs(t[cursor])) cursor += 1;
@@ -1944,7 +2011,7 @@ var OpenAIStreamAccumulator = class {
1944
2011
  text = recovered.residualText;
1945
2012
  stopReason = "tool_use";
1946
2013
  diag(
1947
- `[theokit-sdk] recovered ${recovered.toolCalls.length} leaked tool call(s) from assistant content (provider="${this.providerName}", names=${recovered.toolCalls.map((c) => c.name).join(",")})
2014
+ `[theokit-sdk] recovered ${recovered.toolCalls.length} leaked tool call(s) from assistant content (provider="${this.providerName}", format=${recovered.formats.join(",") || "hermes"}, names=${recovered.toolCalls.map((c) => c.name).join(",")})
1948
2015
  `
1949
2016
  );
1950
2017
  }
@@ -3526,5 +3593,5 @@ async function autoCompactIfNeeded(opts) {
3526
3593
  }
3527
3594
 
3528
3595
  export { COMPACT_SUMMARY_MARKER, COMPACT_USER_MESSAGE_MAX_TOKENS, CircuitBreaker, DEFAULT_PRE_COMPACT_TIMEOUT_MS, abortError, autoCompactIfNeeded, buildDefaultSummarizer, compactSessionTranscript, discoverProviderPlugins, getConfiguredBaseUrl, httpRequest, inferApiMode, isCompactSummary, isFixtureApiKey, mapOllamaHttpError, mapOllamaTransportError, mergeExplicitApiKey, normalizeUsage, parseSseStream, presentProviderCredentialEnvVars, readErrorResponseBody, readTrustArray, relayStream, renderToolResultContentText, resolveProviderChain, resolveRunProvider, resolveSummarizerRoute, shouldAutoCompact, shouldUseFixtureMode, shouldUseRealLocalRuntime, trustFilePath, tryFirstEvent, validateApiKeyShape };
3529
- //# sourceMappingURL=chunk-IOBHFP2E.js.map
3530
- //# sourceMappingURL=chunk-IOBHFP2E.js.map
3596
+ //# sourceMappingURL=chunk-26GI3OYA.js.map
3597
+ //# sourceMappingURL=chunk-26GI3OYA.js.map