@theokit/sdk 2.0.0 → 2.1.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 (107) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/a2a/index.cjs +384 -317
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +384 -317
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/concurrency.cjs +86 -0
  7. package/dist/concurrency.cjs.map +1 -0
  8. package/dist/concurrency.d.cts +13 -0
  9. package/dist/concurrency.d.ts +13 -0
  10. package/dist/concurrency.js +83 -0
  11. package/dist/concurrency.js.map +1 -0
  12. package/dist/{cron-Bse1MbaE.d.cts → cron-CSTqNZp9.d.cts} +2 -2
  13. package/dist/{cron-Ci_NUkUj.d.ts → cron-Da6vF_2y.d.ts} +2 -2
  14. package/dist/cron.cjs +346 -295
  15. package/dist/cron.cjs.map +1 -1
  16. package/dist/cron.d.cts +1 -1
  17. package/dist/cron.d.ts +1 -1
  18. package/dist/cron.js +349 -298
  19. package/dist/cron.js.map +1 -1
  20. package/dist/{errors-DV9e0rcp.d.ts → errors--VP2qrGc.d.ts} +23 -1
  21. package/dist/{errors-ChqOmFH1.d.cts → errors-C9xkhNEF.d.cts} +23 -1
  22. package/dist/errors.cjs +17 -11
  23. package/dist/errors.cjs.map +1 -1
  24. package/dist/errors.d.cts +1 -1
  25. package/dist/errors.d.ts +22 -0
  26. package/dist/errors.js +17 -12
  27. package/dist/errors.js.map +1 -1
  28. package/dist/eval.cjs +345 -291
  29. package/dist/eval.cjs.map +1 -1
  30. package/dist/eval.d.cts +1 -0
  31. package/dist/eval.d.ts +1 -0
  32. package/dist/eval.js +348 -294
  33. package/dist/eval.js.map +1 -1
  34. package/dist/index.cjs +342 -275
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +161 -119
  37. package/dist/index.d.ts +161 -119
  38. package/dist/index.js +342 -277
  39. package/dist/index.js.map +1 -1
  40. package/dist/internal/persistence/index.cjs +75 -0
  41. package/dist/internal/persistence/index.cjs.map +1 -1
  42. package/dist/internal/persistence/index.d.cts +2 -0
  43. package/dist/internal/persistence/index.d.ts +2 -0
  44. package/dist/internal/persistence/index.js +74 -1
  45. package/dist/internal/persistence/index.js.map +1 -1
  46. package/dist/internal/persistence/sqlite-open.d.cts +47 -0
  47. package/dist/internal/persistence/sqlite-open.d.ts +47 -0
  48. package/dist/internal/providers/register-plugin-providers.d.ts +22 -0
  49. package/dist/internal/runtime/concurrency/map-with-concurrency.d.ts +28 -0
  50. package/dist/internal/runtime/{fork-agent.d.ts → lifecycle/fork-agent.d.ts} +1 -1
  51. package/dist/internal/runtime/{run-until.d.ts → lifecycle/run-until.d.ts} +3 -3
  52. package/dist/internal/runtime/local-agent/local-agent-bootstrap.d.ts +1 -1
  53. package/dist/internal/runtime/registry/agent-factory-registry.d.ts +12 -9
  54. package/dist/internal/runtime/retry/with-retry.d.ts +40 -0
  55. package/dist/internal/runtime/validation/validate-agent-options.d.ts +1 -0
  56. package/dist/internal/scorers/llm-judge.d.ts +4 -4
  57. package/dist/internal/security/index.cjs +1 -0
  58. package/dist/internal/security/index.cjs.map +1 -1
  59. package/dist/internal/security/index.d.cts +1 -1
  60. package/dist/internal/security/index.d.ts +1 -1
  61. package/dist/internal/security/index.js +1 -0
  62. package/dist/internal/security/index.js.map +1 -1
  63. package/dist/path-safety.cjs +15 -0
  64. package/dist/path-safety.cjs.map +1 -1
  65. package/dist/path-safety.d.cts +1 -1
  66. package/dist/path-safety.d.ts +1 -1
  67. package/dist/path-safety.js +15 -1
  68. package/dist/path-safety.js.map +1 -1
  69. package/dist/retry.cjs +85 -0
  70. package/dist/retry.cjs.map +1 -0
  71. package/dist/retry.d.cts +9 -0
  72. package/dist/retry.d.ts +9 -0
  73. package/dist/retry.js +83 -0
  74. package/dist/retry.js.map +1 -0
  75. package/dist/server/errors-envelope.cjs +14 -12
  76. package/dist/server/errors-envelope.cjs.map +1 -1
  77. package/dist/server/errors-envelope.js +14 -12
  78. package/dist/server/errors-envelope.js.map +1 -1
  79. package/dist/subscription/index.cjs.map +1 -1
  80. package/dist/subscription/index.js.map +1 -1
  81. package/dist/task-store.cjs.map +1 -1
  82. package/dist/task-store.js.map +1 -1
  83. package/dist/types/fork.d.ts +1 -1
  84. package/dist/workflow.cjs +2 -2
  85. package/dist/workflow.cjs.map +1 -1
  86. package/dist/workflow.js +2 -2
  87. package/dist/workflow.js.map +1 -1
  88. package/package.json +26 -2
  89. /package/dist/internal/{runtime/default-model.d.ts → default-retriable.d.ts} +0 -0
  90. /package/dist/internal/{errors/mappers → error-mappers}/anthropic.d.ts +0 -0
  91. /package/dist/internal/{errors/mappers → error-mappers}/bedrock.d.ts +0 -0
  92. /package/dist/internal/{errors/mappers → error-mappers}/ollama.d.ts +0 -0
  93. /package/dist/internal/{errors/mappers → error-mappers}/openai-compatible.d.ts +0 -0
  94. /package/dist/internal/{errors/mappers → error-mappers}/shared.d.ts +0 -0
  95. /package/dist/internal/{errors/mappers → error-mappers}/vertex.d.ts +0 -0
  96. /package/dist/internal/runtime/{abort-utils.d.ts → concurrency/abort-utils.d.ts} +0 -0
  97. /package/dist/internal/runtime/{async-local-storage.d.ts → concurrency/async-local-storage.d.ts} +0 -0
  98. /package/dist/internal/runtime/{async-semaphore.d.ts → concurrency/async-semaphore.d.ts} +0 -0
  99. /package/dist/internal/runtime/{post-run-lifecycle.d.ts → config/default-model.d.ts} +0 -0
  100. /package/dist/internal/runtime/{providers-manager.d.ts → config/providers-manager.d.ts} +0 -0
  101. /package/dist/internal/runtime/{workspace-dir.d.ts → config/workspace-dir.d.ts} +0 -0
  102. /package/dist/internal/runtime/{yaml-frontmatter.d.ts → context/yaml-frontmatter.d.ts} +0 -0
  103. /package/dist/internal/runtime/{system-prompt.d.ts → lifecycle/post-run-lifecycle.d.ts} +0 -0
  104. /package/dist/internal/runtime/{spawn-collect.d.ts → lifecycle/spawn-collect.d.ts} +0 -0
  105. /package/dist/internal/runtime/{validate-agent-options.d.ts → system-prompt/system-prompt.d.ts} +0 -0
  106. /package/dist/internal/runtime/{shell-tool.d.ts → tools/shell-tool.d.ts} +0 -0
  107. /package/dist/internal/runtime/{validate-response.d.ts → validation/validate-response.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
+ import { createHash, randomUUID, randomBytes } from 'crypto';
1
2
  import { existsSync, rmSync, mkdirSync, renameSync, readFileSync, realpathSync, lstatSync, readlinkSync, readdirSync } from 'fs';
2
3
  import { join, dirname, relative, resolve, sep, isAbsolute } from 'path';
3
- import { createHash, randomUUID, randomBytes } from 'crypto';
4
- import { readFile, stat, rm, readdir, mkdir, appendFile, rename, open, unlink, statfs, access } from 'fs/promises';
4
+ import { readFile, stat, rm, readdir, mkdir, appendFile, open, rename, unlink, statfs, access } from 'fs/promises';
5
5
  import { z, toJSONSchema } from 'zod';
6
6
  import { AsyncLocalStorage } from 'async_hooks';
7
7
  import { createRequire } from 'module';
@@ -20,6 +20,24 @@ var __export = (target, all) => {
20
20
  __defProp(target, name, { get: all[name], enumerable: true });
21
21
  };
22
22
 
23
+ // src/internal/default-retriable.ts
24
+ function defaultRetriableForCode(code) {
25
+ switch (code) {
26
+ case "rate_limit":
27
+ case "timeout":
28
+ case "server_error":
29
+ case "network":
30
+ case "provider_unreachable":
31
+ return true;
32
+ default:
33
+ return false;
34
+ }
35
+ }
36
+ var init_default_retriable = __esm({
37
+ "src/internal/default-retriable.ts"() {
38
+ }
39
+ });
40
+
23
41
  // src/internal/security/redact.ts
24
42
  function readEnvOnce() {
25
43
  const raw = process.env.THEOKIT_REDACT_SECRETS;
@@ -176,7 +194,8 @@ __export(errors_exports, {
176
194
  UnsupportedBudgetOperationError: () => UnsupportedBudgetOperationError,
177
195
  UnsupportedRunOperationError: () => UnsupportedRunOperationError,
178
196
  UnsupportedTaskOperationError: () => UnsupportedTaskOperationError,
179
- coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode
197
+ coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode,
198
+ isTransientError: () => isTransientError
180
199
  });
181
200
  function coerceToKnownAgentRunErrorCode(code) {
182
201
  if (code !== void 0 && KNOWN_AGENT_RUN_ERROR_CODES.has(code)) {
@@ -208,21 +227,13 @@ function safeStringify(value) {
208
227
  return String(value);
209
228
  }
210
229
  }
211
- function defaultRetriableForCode(code) {
212
- switch (code) {
213
- case "rate_limit":
214
- case "timeout":
215
- case "server_error":
216
- case "network":
217
- case "provider_unreachable":
218
- return true;
219
- default:
220
- return false;
221
- }
230
+ function isTransientError(err) {
231
+ return err instanceof TheokitAgentError && err.isRetryable === true;
222
232
  }
223
233
  var KNOWN_AGENT_RUN_ERROR_CODES, TheokitAgentError, AuthenticationError, RateLimitError, ConfigurationError, IntegrationNotConnectedError, NetworkError, UnknownAgentError, AgentRunError, UnsupportedRunOperationError, CredentialPoolExhaustedError, MemoryAdapterError, InvalidTaskIdError, TaskNotFoundError, UnsupportedTaskOperationError, BudgetExceededError, AgentDisposedError, UnsupportedBudgetOperationError;
224
234
  var init_errors = __esm({
225
235
  "src/errors.ts"() {
236
+ init_default_retriable();
226
237
  init_redact();
227
238
  KNOWN_AGENT_RUN_ERROR_CODES = /* @__PURE__ */ new Set([
228
239
  "rate_limit",
@@ -646,6 +657,19 @@ function sanitizeIdentifier(input, options) {
646
657
  }
647
658
  return input.toLowerCase();
648
659
  }
660
+ function safeFilenameForId(id, options) {
661
+ if (id.length === 0) {
662
+ throw new ConfigurationError("Filename id must be a non-empty string", {
663
+ code: "invalid_filename_id"
664
+ });
665
+ }
666
+ const maxLen = options?.maxLen;
667
+ const lower = id.toLowerCase();
668
+ if (lower.length <= maxLen && IDENTIFIER_PATTERN.test(lower)) {
669
+ return lower;
670
+ }
671
+ return `h-${createHash("sha256").update(id).digest("hex").slice(0, 16)}`;
672
+ }
649
673
  var PathTraversalError, IDENTIFIER_PATTERN;
650
674
  var init_path_guard = __esm({
651
675
  "src/internal/security/path-guard.ts"() {
@@ -836,7 +860,7 @@ var init_markdown_store = __esm({
836
860
  }
837
861
  });
838
862
 
839
- // src/internal/runtime/yaml-frontmatter.ts
863
+ // src/internal/runtime/context/yaml-frontmatter.ts
840
864
  function parseSimpleYaml(text) {
841
865
  const fields = {};
842
866
  for (const line of text.split(/\r?\n/)) {
@@ -860,7 +884,7 @@ function coerce(raw) {
860
884
  return raw;
861
885
  }
862
886
  var init_yaml_frontmatter = __esm({
863
- "src/internal/runtime/yaml-frontmatter.ts"() {
887
+ "src/internal/runtime/context/yaml-frontmatter.ts"() {
864
888
  }
865
889
  });
866
890
  async function loadMarkdownEntities(opts) {
@@ -1048,10 +1072,7 @@ function sessionsDir(cwd) {
1048
1072
  return join(memoryDir(cwd), "sessions");
1049
1073
  }
1050
1074
  function sessionSummaryPath(cwd, runId) {
1051
- return join(sessionsDir(cwd), `${sanitizeRunId(runId)}.md`);
1052
- }
1053
- function sanitizeRunId(runId) {
1054
- return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
1075
+ return join(sessionsDir(cwd), `${safeFilenameForId(runId, { maxLen: 128 })}.md`);
1055
1076
  }
1056
1077
  function truncate(text) {
1057
1078
  if (text.length <= MAX_TURN_CHARS) return text;
@@ -1087,6 +1108,7 @@ var MAX_TURN_CHARS;
1087
1108
  var init_session_summary_writer = __esm({
1088
1109
  "src/internal/memory/storage/session-summary-writer.ts"() {
1089
1110
  init_atomic_write();
1111
+ init_path_guard();
1090
1112
  init_types();
1091
1113
  init_markdown_store();
1092
1114
  MAX_TURN_CHARS = 2e3;
@@ -1111,11 +1133,54 @@ function checkToolWhitelist(toolName) {
1111
1133
  }
1112
1134
  var toolWhitelistStore;
1113
1135
  var init_async_local_storage = __esm({
1114
- "src/internal/runtime/async-local-storage.ts"() {
1136
+ "src/internal/runtime/concurrency/async-local-storage.ts"() {
1115
1137
  toolWhitelistStore = new AsyncLocalStorage();
1116
1138
  }
1117
1139
  });
1118
1140
 
1141
+ // src/internal/runtime/concurrency/async-semaphore.ts
1142
+ function createSemaphore(permits) {
1143
+ if (!Number.isInteger(permits) || permits < 1) {
1144
+ throw new ConfigurationError(
1145
+ `async-semaphore: permits must be a positive integer, got ${permits}`,
1146
+ { code: "invalid_concurrency" }
1147
+ );
1148
+ }
1149
+ let active = 0;
1150
+ const queue = [];
1151
+ function tryGrant() {
1152
+ if (active < permits && queue.length > 0) {
1153
+ const resolve3 = queue.shift();
1154
+ if (resolve3 !== void 0) {
1155
+ active += 1;
1156
+ resolve3();
1157
+ }
1158
+ }
1159
+ }
1160
+ return {
1161
+ inFlight: () => active,
1162
+ pending: () => queue.length + active,
1163
+ async acquire() {
1164
+ await new Promise((resolve3) => {
1165
+ queue.push(resolve3);
1166
+ tryGrant();
1167
+ });
1168
+ let released = false;
1169
+ return () => {
1170
+ if (released) return;
1171
+ released = true;
1172
+ active -= 1;
1173
+ tryGrant();
1174
+ };
1175
+ }
1176
+ };
1177
+ }
1178
+ var init_async_semaphore = __esm({
1179
+ "src/internal/runtime/concurrency/async-semaphore.ts"() {
1180
+ init_errors();
1181
+ }
1182
+ });
1183
+
1119
1184
  // src/internal/llm/credential-pool-types.ts
1120
1185
  var COOLDOWN_MS, DEFAULT_COOLDOWN_MS;
1121
1186
  var init_credential_pool_types = __esm({
@@ -1497,6 +1562,61 @@ var init_sqlite_wal = __esm({
1497
1562
  warnedLabels = /* @__PURE__ */ new Set();
1498
1563
  }
1499
1564
  });
1565
+ async function openSqliteResilient(options) {
1566
+ await mkdir(dirname(options.filePath), { recursive: true });
1567
+ try {
1568
+ return await openConcrete(options);
1569
+ } catch (cause) {
1570
+ if (options.recoverCorrupt !== false && isCorruptionError(cause)) {
1571
+ await renameAside(options.filePath, options.label ?? "sqlite");
1572
+ return await openConcrete(options);
1573
+ }
1574
+ throw cause;
1575
+ }
1576
+ }
1577
+ async function openConcrete(options) {
1578
+ const db = await loadDriver(options.filePath);
1579
+ applyWalWithFallback(db, options.label ?? "sqlite");
1580
+ await options.onOpen?.(db);
1581
+ return db;
1582
+ }
1583
+ async function loadDriver(filePath) {
1584
+ try {
1585
+ const mod = await import('better-sqlite3');
1586
+ const Ctor = mod.default ?? mod;
1587
+ if (typeof Ctor !== "function") {
1588
+ throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
1589
+ }
1590
+ return new Ctor(filePath);
1591
+ } catch (cause) {
1592
+ const message = cause instanceof Error ? cause.message : String(cause);
1593
+ throw new ConfigurationError(
1594
+ `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
1595
+ { code: "sqlite_driver_unavailable", cause }
1596
+ );
1597
+ }
1598
+ }
1599
+ function isCorruptionError(cause) {
1600
+ if (!(cause instanceof Error)) return false;
1601
+ const msg = cause.message.toLowerCase();
1602
+ return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
1603
+ }
1604
+ async function renameAside(filePath, label) {
1605
+ const asidePath = `${filePath}.corrupt-${Date.now()}`;
1606
+ await rename(filePath, asidePath).catch(() => void 0);
1607
+ await rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
1608
+ await rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
1609
+ process.stderr.write(
1610
+ `[theokit-sdk] ${label} database corrupt; renamed aside to ${asidePath} and rebuilt schema
1611
+ `
1612
+ );
1613
+ }
1614
+ var init_sqlite_open = __esm({
1615
+ "src/internal/persistence/sqlite-open.ts"() {
1616
+ init_errors();
1617
+ init_sqlite_wal();
1618
+ }
1619
+ });
1500
1620
 
1501
1621
  // src/internal/memory/index-schema.ts
1502
1622
  var SCHEMA_STATEMENTS, PRAGMA_STATEMENTS;
@@ -1544,60 +1664,22 @@ var init_index_schema = __esm({
1544
1664
  }
1545
1665
  });
1546
1666
  async function openMemoryDb(opts) {
1547
- await mkdir(dirname(opts.filePath), { recursive: true });
1548
- try {
1549
- return await openConcrete(opts.filePath);
1550
- } catch (cause) {
1551
- if (opts.recoverCorrupt !== false && isCorruptionError(cause)) {
1552
- await renameAside(opts.filePath);
1553
- return await openConcrete(opts.filePath);
1667
+ return openSqliteResilient({
1668
+ filePath: opts.filePath,
1669
+ label: "memory-index",
1670
+ recoverCorrupt: opts.recoverCorrupt,
1671
+ onOpen: (db) => {
1672
+ for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
1673
+ for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
1554
1674
  }
1555
- throw cause;
1556
- }
1557
- }
1558
- async function openConcrete(filePath) {
1559
- const db = await loadDriver(filePath);
1560
- applyWalWithFallback(db, "memory-index");
1561
- for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
1562
- for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
1563
- return db;
1564
- }
1565
- async function loadDriver(filePath) {
1566
- try {
1567
- const mod = await import('better-sqlite3');
1568
- const Ctor = mod.default ?? mod;
1569
- const db = new Ctor(filePath);
1570
- return db;
1571
- } catch (cause) {
1572
- const message = cause instanceof Error ? cause.message : String(cause);
1573
- throw new ConfigurationError(
1574
- `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
1575
- { code: "sqlite_driver_unavailable", cause }
1576
- );
1577
- }
1578
- }
1579
- function isCorruptionError(cause) {
1580
- if (!(cause instanceof Error)) return false;
1581
- const msg = cause.message.toLowerCase();
1582
- return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
1583
- }
1584
- async function renameAside(filePath) {
1585
- const asidePath = `${filePath}.corrupt-${Date.now()}`;
1586
- await rename(filePath, asidePath).catch(() => void 0);
1587
- await rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
1588
- await rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
1589
- process.stderr.write(
1590
- `[theokit-sdk] memory index corrupt; renamed aside to ${asidePath} and rebuilt schema
1591
- `
1592
- );
1675
+ });
1593
1676
  }
1594
1677
  function defaultIndexPath(cwd) {
1595
1678
  return join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
1596
1679
  }
1597
1680
  var init_index_db = __esm({
1598
1681
  "src/internal/memory/index-db.ts"() {
1599
- init_errors();
1600
- init_sqlite_wal();
1682
+ init_sqlite_open();
1601
1683
  init_index_schema();
1602
1684
  }
1603
1685
  });
@@ -2490,7 +2572,7 @@ var init_local_agent_plugins = __esm({
2490
2572
  }
2491
2573
  });
2492
2574
 
2493
- // src/internal/runtime/run-until.ts
2575
+ // src/internal/runtime/lifecycle/run-until.ts
2494
2576
  var run_until_exports = {};
2495
2577
  __export(run_until_exports, {
2496
2578
  composeContinuation: () => composeContinuation,
@@ -2583,7 +2665,7 @@ Your last response was:
2583
2665
  ${lastResponse.slice(0, 1e3)}`;
2584
2666
  }
2585
2667
  var init_run_until = __esm({
2586
- "src/internal/runtime/run-until.ts"() {
2668
+ "src/internal/runtime/lifecycle/run-until.ts"() {
2587
2669
  }
2588
2670
  });
2589
2671
 
@@ -2694,16 +2776,16 @@ var init_judge_call = __esm({
2694
2776
  // src/internal/runtime/registry/agent-factory-registry.ts
2695
2777
  var agent_factory_registry_exports = {};
2696
2778
  __export(agent_factory_registry_exports, {
2697
- getAgentCreate: () => getAgentCreate,
2698
- setAgentCreate: () => setAgentCreate
2779
+ getAgentFacade: () => getAgentFacade,
2780
+ setAgentFacade: () => setAgentFacade
2699
2781
  });
2700
- function setAgentCreate(fn) {
2701
- registered3 = fn;
2782
+ function setAgentFacade(facade) {
2783
+ registered3 = facade;
2702
2784
  }
2703
- function getAgentCreate() {
2785
+ function getAgentFacade() {
2704
2786
  if (registered3 === void 0) {
2705
2787
  throw new Error(
2706
- "internal: Agent.create not registered. The `agent.ts` module must be loaded before LocalAgent.runUntil/fork are invoked."
2788
+ "internal: Agent facade not registered. The `agent.ts` module must be loaded before internal subsystems (LocalAgent.runUntil/fork, eval, scorers, cron) invoke it."
2707
2789
  );
2708
2790
  }
2709
2791
  return registered3;
@@ -2714,7 +2796,7 @@ var init_agent_factory_registry = __esm({
2714
2796
  }
2715
2797
  });
2716
2798
 
2717
- // src/internal/runtime/fork-agent.ts
2799
+ // src/internal/runtime/lifecycle/fork-agent.ts
2718
2800
  var fork_agent_exports = {};
2719
2801
  __export(fork_agent_exports, {
2720
2802
  filterMemoryPlugins: () => filterMemoryPlugins,
@@ -2774,7 +2856,7 @@ function extractUsage(result) {
2774
2856
  };
2775
2857
  }
2776
2858
  var init_fork_agent = __esm({
2777
- "src/internal/runtime/fork-agent.ts"() {
2859
+ "src/internal/runtime/lifecycle/fork-agent.ts"() {
2778
2860
  init_async_local_storage();
2779
2861
  init_local_agent_plugins();
2780
2862
  }
@@ -2797,49 +2879,6 @@ var init_task = __esm({
2797
2879
  }
2798
2880
  });
2799
2881
 
2800
- // src/internal/runtime/async-semaphore.ts
2801
- function createSemaphore(permits) {
2802
- if (!Number.isInteger(permits) || permits < 1) {
2803
- throw new ConfigurationError(
2804
- `async-semaphore: permits must be a positive integer, got ${permits}`,
2805
- { code: "invalid_concurrency" }
2806
- );
2807
- }
2808
- let active = 0;
2809
- const queue = [];
2810
- function tryGrant() {
2811
- if (active < permits && queue.length > 0) {
2812
- const resolve3 = queue.shift();
2813
- if (resolve3 !== void 0) {
2814
- active += 1;
2815
- resolve3();
2816
- }
2817
- }
2818
- }
2819
- return {
2820
- inFlight: () => active,
2821
- pending: () => queue.length + active,
2822
- async acquire() {
2823
- await new Promise((resolve3) => {
2824
- queue.push(resolve3);
2825
- tryGrant();
2826
- });
2827
- let released = false;
2828
- return () => {
2829
- if (released) return;
2830
- released = true;
2831
- active -= 1;
2832
- tryGrant();
2833
- };
2834
- }
2835
- };
2836
- }
2837
- var init_async_semaphore = __esm({
2838
- "src/internal/runtime/async-semaphore.ts"() {
2839
- init_errors();
2840
- }
2841
- });
2842
-
2843
2882
  // src/internal/task/ring-buffer.ts
2844
2883
  var RingBuffer;
2845
2884
  var init_ring_buffer = __esm({
@@ -5648,7 +5687,7 @@ init_errors();
5648
5687
  init_cwd_mutex();
5649
5688
  init_path_guard();
5650
5689
 
5651
- // src/internal/runtime/default-model.ts
5690
+ // src/internal/runtime/config/default-model.ts
5652
5691
  var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
5653
5692
 
5654
5693
  // src/internal/runtime/registry/agent-registry-store.ts
@@ -5969,7 +6008,7 @@ async function flushRegistrySaves(cwd) {
5969
6008
  }
5970
6009
  }
5971
6010
 
5972
- // src/internal/runtime/system-prompt.ts
6011
+ // src/internal/runtime/system-prompt/system-prompt.ts
5973
6012
  async function resolveSystemPrompt(agent, override, ctx) {
5974
6013
  if (override !== void 0) return override;
5975
6014
  if (agent === void 0) return void 0;
@@ -8264,6 +8303,9 @@ function parseDecisionFromStdout(stdout) {
8264
8303
  return { decision: "allow" };
8265
8304
  }
8266
8305
 
8306
+ // src/internal/runtime/lifecycle/post-run-lifecycle.ts
8307
+ init_session_summary_writer();
8308
+
8267
8309
  // src/internal/runtime/memory/memory-path-selector.ts
8268
8310
  var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
8269
8311
  function shouldUsePortMemoryPath() {
@@ -8286,9 +8328,6 @@ function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
8286
8328
  return legacySummary;
8287
8329
  }
8288
8330
 
8289
- // src/internal/runtime/post-run-lifecycle.ts
8290
- init_session_summary_writer();
8291
-
8292
8331
  // src/internal/runtime/session/agent-session-store.ts
8293
8332
  init_atomic_write();
8294
8333
  init_security();
@@ -8547,7 +8586,7 @@ function clearSession(agentId) {
8547
8586
  sessions.delete(agentId);
8548
8587
  }
8549
8588
 
8550
- // src/internal/runtime/post-run-lifecycle.ts
8589
+ // src/internal/runtime/lifecycle/post-run-lifecycle.ts
8551
8590
  async function runPostRunLifecycle(inputs) {
8552
8591
  const {
8553
8592
  run,
@@ -8779,7 +8818,7 @@ var liveAgentRegistry = new LiveAgentRegistry();
8779
8818
  // src/internal/runtime/skills/subagents-loader.ts
8780
8819
  init_errors();
8781
8820
 
8782
- // src/internal/runtime/workspace-dir.ts
8821
+ // src/internal/runtime/config/workspace-dir.ts
8783
8822
  init_errors();
8784
8823
  async function readWorkspaceDir(root, errorCode, describe) {
8785
8824
  try {
@@ -9065,7 +9104,7 @@ var SystemPromptPipeline = class _SystemPromptPipeline {
9065
9104
  }
9066
9105
  };
9067
9106
 
9068
- // src/internal/runtime/validate-agent-options.ts
9107
+ // src/internal/runtime/validation/validate-agent-options.ts
9069
9108
  init_errors();
9070
9109
  function validateAgentOptions(options) {
9071
9110
  rejectProgrammaticHooks(options);
@@ -9260,6 +9299,71 @@ function validateMemory(options) {
9260
9299
  }
9261
9300
  }
9262
9301
 
9302
+ // src/internal/runtime/config/providers-manager.ts
9303
+ var ProvidersManagerImpl = class {
9304
+ constructor(model, providers, plugins) {
9305
+ this.model = model;
9306
+ this.providers = providers;
9307
+ this.plugins = plugins;
9308
+ }
9309
+ model;
9310
+ providers;
9311
+ plugins;
9312
+ routes() {
9313
+ const resolved = [];
9314
+ const modelProvider = providerFromModel(this.model);
9315
+ const seen = /* @__PURE__ */ new Set();
9316
+ if (this.providers?.routes !== void 0) {
9317
+ for (const route of this.providers.routes) {
9318
+ const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
9319
+ if (!seen.has(route.capability)) {
9320
+ seen.add(route.capability);
9321
+ resolved.push(resolvedRoute);
9322
+ }
9323
+ }
9324
+ }
9325
+ return Promise.resolve(resolved);
9326
+ }
9327
+ };
9328
+ function providerFromModel(model) {
9329
+ if (model === void 0) return void 0;
9330
+ const id = model.id;
9331
+ if (id.includes(":")) return id.split(":")[0];
9332
+ return void 0;
9333
+ }
9334
+ function resolveRoute(route, modelProvider, plugins) {
9335
+ if (route.capability === "chat" && modelProvider === route.provider) {
9336
+ const modelName = extractModelName(modelProvider, route);
9337
+ const base = {
9338
+ capability: route.capability,
9339
+ provider: route.provider,
9340
+ reason: "explicit-model-provider"
9341
+ };
9342
+ if (modelName !== void 0) base.model = modelName;
9343
+ return base;
9344
+ }
9345
+ if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
9346
+ return {
9347
+ capability: route.capability,
9348
+ provider: route.provider,
9349
+ reason: "first-available-plugin-provider"
9350
+ };
9351
+ }
9352
+ return {
9353
+ capability: route.capability,
9354
+ provider: route.provider,
9355
+ reason: "explicit-route"
9356
+ };
9357
+ }
9358
+ function extractModelName(prefix, route) {
9359
+ if (route.model !== void 0) return route.model;
9360
+ return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
9361
+ }
9362
+ function defaultModelForProvider(provider) {
9363
+ if (provider === "anthropic") return "claude-3-7-sonnet";
9364
+ return void 0;
9365
+ }
9366
+
9263
9367
  // src/internal/runtime/context/context-manager.ts
9264
9368
  init_errors();
9265
9369
  init_markdown_config_loader();
@@ -10057,71 +10161,6 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
10057
10161
  return metadata;
10058
10162
  }
10059
10163
 
10060
- // src/internal/runtime/providers-manager.ts
10061
- var ProvidersManagerImpl = class {
10062
- constructor(model, providers, plugins) {
10063
- this.model = model;
10064
- this.providers = providers;
10065
- this.plugins = plugins;
10066
- }
10067
- model;
10068
- providers;
10069
- plugins;
10070
- routes() {
10071
- const resolved = [];
10072
- const modelProvider = providerFromModel(this.model);
10073
- const seen = /* @__PURE__ */ new Set();
10074
- if (this.providers?.routes !== void 0) {
10075
- for (const route of this.providers.routes) {
10076
- const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
10077
- if (!seen.has(route.capability)) {
10078
- seen.add(route.capability);
10079
- resolved.push(resolvedRoute);
10080
- }
10081
- }
10082
- }
10083
- return Promise.resolve(resolved);
10084
- }
10085
- };
10086
- function providerFromModel(model) {
10087
- if (model === void 0) return void 0;
10088
- const id = model.id;
10089
- if (id.includes(":")) return id.split(":")[0];
10090
- return void 0;
10091
- }
10092
- function resolveRoute(route, modelProvider, plugins) {
10093
- if (route.capability === "chat" && modelProvider === route.provider) {
10094
- const modelName = extractModelName(modelProvider, route);
10095
- const base = {
10096
- capability: route.capability,
10097
- provider: route.provider,
10098
- reason: "explicit-model-provider"
10099
- };
10100
- if (modelName !== void 0) base.model = modelName;
10101
- return base;
10102
- }
10103
- if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
10104
- return {
10105
- capability: route.capability,
10106
- provider: route.provider,
10107
- reason: "first-available-plugin-provider"
10108
- };
10109
- }
10110
- return {
10111
- capability: route.capability,
10112
- provider: route.provider,
10113
- reason: "explicit-route"
10114
- };
10115
- }
10116
- function extractModelName(prefix, route) {
10117
- if (route.model !== void 0) return route.model;
10118
- return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
10119
- }
10120
- function defaultModelForProvider(provider) {
10121
- if (provider === "anthropic") return "claude-3-7-sonnet";
10122
- return void 0;
10123
- }
10124
-
10125
10164
  // src/internal/runtime/skills/skills-manager.ts
10126
10165
  init_errors();
10127
10166
  init_path_guard();
@@ -10469,7 +10508,7 @@ var IterationBudget = class {
10469
10508
  }
10470
10509
  };
10471
10510
 
10472
- // src/internal/runtime/validate-response.ts
10511
+ // src/internal/runtime/validation/validate-response.ts
10473
10512
  function validateResponse(response) {
10474
10513
  const trimmed = response.content.trim();
10475
10514
  const toolCallsArr = Array.isArray(response.toolCalls) ? response.toolCalls : [];
@@ -10855,6 +10894,27 @@ async function emitTextDeltaCallback(inputs, text) {
10855
10894
  // src/internal/agent-loop/tool-dispatch.ts
10856
10895
  init_async_local_storage();
10857
10896
 
10897
+ // src/internal/runtime/concurrency/map-with-concurrency.ts
10898
+ init_async_semaphore();
10899
+ var NEVER_ABORT = new AbortController().signal;
10900
+ async function mapWithConcurrency(items, concurrency, fn, options) {
10901
+ const semaphore = createSemaphore(concurrency);
10902
+ const signal = NEVER_ABORT;
10903
+ return Promise.all(
10904
+ items.map(async (item, index) => {
10905
+ const release = await semaphore.acquire();
10906
+ try {
10907
+ if (signal.aborted) {
10908
+ throw signal.reason instanceof Error ? signal.reason : new Error("mapWithConcurrency: aborted");
10909
+ }
10910
+ return await fn(item, index, signal);
10911
+ } finally {
10912
+ release();
10913
+ }
10914
+ })
10915
+ );
10916
+ }
10917
+
10858
10918
  // src/internal/tool-dispatch/repair-middleware.ts
10859
10919
  var DECIMAL_RE = /^-?\d+(\.\d+)?$/;
10860
10920
  function repairToolCall(raw, registry3) {
@@ -10928,7 +10988,7 @@ function coerceArgsToSchema(args, schema) {
10928
10988
  return { value: out, changed };
10929
10989
  }
10930
10990
 
10931
- // src/internal/runtime/shell-tool.ts
10991
+ // src/internal/runtime/tools/shell-tool.ts
10932
10992
  async function runShell(options) {
10933
10993
  if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
10934
10994
  return {
@@ -11029,38 +11089,12 @@ ${result.stderr}`.trim();
11029
11089
  // src/internal/agent-loop/tool-dispatch.ts
11030
11090
  async function dispatchTools(inputs, tools, toolCalls, events) {
11031
11091
  const maxConcurrent = inputs.maxConcurrentTools ?? 4;
11032
- return boundedParallel(
11033
- maxConcurrent,
11092
+ return mapWithConcurrency(
11034
11093
  toolCalls,
11094
+ maxConcurrent,
11035
11095
  (call) => dispatchSingleCall(inputs, tools, call, events)
11036
11096
  );
11037
11097
  }
11038
- async function boundedParallel(max, items, fn) {
11039
- let running = 0;
11040
- const queue = [];
11041
- async function acquire() {
11042
- if (running < max) {
11043
- running++;
11044
- return;
11045
- }
11046
- await new Promise((resolve3) => queue.push(resolve3));
11047
- running++;
11048
- }
11049
- function release() {
11050
- running--;
11051
- if (queue.length > 0) queue.shift()();
11052
- }
11053
- return Promise.all(
11054
- items.map(async (item) => {
11055
- await acquire();
11056
- try {
11057
- return await fn(item);
11058
- } finally {
11059
- release();
11060
- }
11061
- })
11062
- );
11063
- }
11064
11098
  async function dispatchSingleCall(inputs, tools, call, events) {
11065
11099
  const { call: workingCall, repairs } = applyRepairAndExtractCall(tools, call);
11066
11100
  const callId = generateCallId();
@@ -12143,10 +12177,10 @@ function registerBuiltins() {
12143
12177
  registerCatalogProviders();
12144
12178
  }
12145
12179
 
12146
- // src/internal/errors/mappers/anthropic.ts
12180
+ // src/internal/error-mappers/anthropic.ts
12147
12181
  init_errors();
12148
12182
 
12149
- // src/internal/errors/mappers/shared.ts
12183
+ // src/internal/error-mappers/shared.ts
12150
12184
  init_security();
12151
12185
  var RAW_MAX_BYTES = 2048;
12152
12186
  function parseRetryAfter(headers) {
@@ -12176,7 +12210,7 @@ function buildErrorMetadata(args) {
12176
12210
  };
12177
12211
  }
12178
12212
 
12179
- // src/internal/errors/mappers/anthropic.ts
12213
+ // src/internal/error-mappers/anthropic.ts
12180
12214
  function mapAnthropicError(args) {
12181
12215
  const { status, body, headers, endpoint } = args;
12182
12216
  const code = mapAnthropicStatusToCode(status, body);
@@ -12516,7 +12550,7 @@ function buildAnthropicBody(request) {
12516
12550
  // src/internal/llm/bedrock-anthropic.ts
12517
12551
  init_errors();
12518
12552
 
12519
- // src/internal/errors/mappers/bedrock.ts
12553
+ // src/internal/error-mappers/bedrock.ts
12520
12554
  init_errors();
12521
12555
  function classifyBedrockError(args, awsType, message) {
12522
12556
  if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
@@ -12653,7 +12687,7 @@ function buildBedrockBody(request) {
12653
12687
  init_credential_pool();
12654
12688
  init_credential_pool_context();
12655
12689
 
12656
- // src/internal/errors/mappers/openai-compatible.ts
12690
+ // src/internal/error-mappers/openai-compatible.ts
12657
12691
  init_errors();
12658
12692
  function mapOpenAICompatibleError(args) {
12659
12693
  const { providerId, status, body, headers, endpoint } = args;
@@ -12817,7 +12851,7 @@ function readOpenAiContent(body) {
12817
12851
  return void 0;
12818
12852
  }
12819
12853
 
12820
- // src/internal/errors/mappers/ollama.ts
12854
+ // src/internal/error-mappers/ollama.ts
12821
12855
  init_errors();
12822
12856
  function mapOllamaTransportError(args) {
12823
12857
  if (args.providerId !== "ollama") return void 0;
@@ -13467,7 +13501,7 @@ function abortError2(signal) {
13467
13501
  // src/internal/llm/vertex-anthropic.ts
13468
13502
  init_errors();
13469
13503
 
13470
- // src/internal/errors/mappers/vertex.ts
13504
+ // src/internal/error-mappers/vertex.ts
13471
13505
  init_errors();
13472
13506
  var VERTEX_RULES = [
13473
13507
  { test: (s, e) => s === 429 || e === "RESOURCE_EXHAUSTED", code: "rate_limit" },
@@ -14010,6 +14044,16 @@ function resolveMcpCwd(configCwd) {
14010
14044
  return safePathJoin(process.cwd(), configCwd);
14011
14045
  }
14012
14046
 
14047
+ // src/internal/providers/register-plugin-providers.ts
14048
+ function registerPluginProviderProfiles(entries) {
14049
+ let registered4 = 0;
14050
+ for (const entry of entries) {
14051
+ registerProvider(entry.profile);
14052
+ registered4 += 1;
14053
+ }
14054
+ return registered4;
14055
+ }
14056
+
14013
14057
  // src/internal/tool-registry/personality-filter.ts
14014
14058
  init_hooks_source();
14015
14059
  function applyPersonalityFilter(exposedTools, whitelist, opts) {
@@ -14086,12 +14130,27 @@ function createRealLocalRun(options) {
14086
14130
  registerRun(handle);
14087
14131
  return handle;
14088
14132
  }
14089
- function buildLoopInputs(options, runId, userText) {
14133
+ var pluginProvidersAnnounced = false;
14134
+ function resolveRunProvider(options) {
14090
14135
  registerBuiltins();
14136
+ const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
14137
+ const registered4 = registerPluginProviderProfiles(profiles);
14138
+ if (registered4 > 0 && !pluginProvidersAnnounced) {
14139
+ pluginProvidersAnnounced = true;
14140
+ const names = profiles.map((e) => e.profile.name).join(", ");
14141
+ process.stderr.write(
14142
+ `[theokit-sdk] registered ${registered4} plugin provider profile(s): ${names}
14143
+ `
14144
+ );
14145
+ }
14091
14146
  const parsedModel = parseModelId(options.model?.id);
14092
14147
  const inferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
14093
14148
  const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? inferredProvider ?? detectPrimaryProvider();
14094
14149
  const effectiveModelId = inferredProvider !== void 0 ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
14150
+ return { primary, effectiveModelId };
14151
+ }
14152
+ function buildLoopInputs(options, runId, userText) {
14153
+ const { primary, effectiveModelId } = resolveRunProvider(options);
14095
14154
  const fallback = options.agentOptions.providers?.fallback;
14096
14155
  const apiKeys = options.agentOptions.providers?.apiKeys;
14097
14156
  const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
@@ -14681,7 +14740,7 @@ async function embedTexts(input) {
14681
14740
  pending
14682
14741
  });
14683
14742
  }
14684
- await runBatches(input, pending, results);
14743
+ await embedInBoundedBatches(input, pending, results);
14685
14744
  return results.map((v) => v ?? new Array(dimension).fill(0));
14686
14745
  }
14687
14746
  function classifyEntry(args) {
@@ -14700,45 +14759,34 @@ function classifyEntry(args) {
14700
14759
  args.pending.push({ index: args.index, text: args.text, key: key2 });
14701
14760
  }
14702
14761
  var MAX_CONCURRENT_BATCHES = 3;
14703
- async function runBatches(input, pending, results) {
14762
+ async function embedInBoundedBatches(input, pending, results) {
14704
14763
  const batches = [];
14705
14764
  for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
14706
14765
  batches.push(pending.slice(offset, offset + MAX_BATCH));
14707
14766
  }
14708
- let running = 0;
14709
- const queue = [];
14710
- await Promise.all(batches.map((batch) => processBatch(input, batch, results, acquire, release)));
14711
- async function acquire() {
14712
- if (running >= MAX_CONCURRENT_BATCHES) await new Promise((r) => queue.push(r));
14713
- running++;
14714
- }
14715
- function release() {
14716
- running--;
14717
- if (queue.length > 0) queue.shift()();
14718
- }
14767
+ await mapWithConcurrency(
14768
+ batches,
14769
+ MAX_CONCURRENT_BATCHES,
14770
+ (batch) => processBatch(input, batch, results)
14771
+ );
14719
14772
  }
14720
- async function processBatch(input, batch, results, acquire, release) {
14721
- await acquire();
14722
- try {
14723
- const vectors = await embedBatch({
14724
- apiKey: input.apiKey,
14725
- baseUrl: input.baseUrl,
14726
- embeddingsPath: input.embeddingsPath,
14727
- model: input.model,
14728
- inputs: batch.map((b) => b.text),
14729
- fetchImpl: input.fetchImpl,
14730
- stats: input.stats,
14731
- providerId: input.providerId
14732
- });
14733
- for (let j = 0; j < batch.length; j++) {
14734
- const slot = batch[j];
14735
- const vector = vectors[j];
14736
- if (slot === void 0 || vector === void 0) continue;
14737
- results[slot.index] = vector;
14738
- input.cache.set(slot.key, vector);
14739
- }
14740
- } finally {
14741
- release();
14773
+ async function processBatch(input, batch, results) {
14774
+ const vectors = await embedBatch({
14775
+ apiKey: input.apiKey,
14776
+ baseUrl: input.baseUrl,
14777
+ embeddingsPath: input.embeddingsPath,
14778
+ model: input.model,
14779
+ inputs: batch.map((b) => b.text),
14780
+ fetchImpl: input.fetchImpl,
14781
+ stats: input.stats,
14782
+ providerId: input.providerId
14783
+ });
14784
+ for (let j = 0; j < batch.length; j++) {
14785
+ const slot = batch[j];
14786
+ const vector = vectors[j];
14787
+ if (slot === void 0 || vector === void 0) continue;
14788
+ results[slot.index] = vector;
14789
+ input.cache.set(slot.key, vector);
14742
14790
  }
14743
14791
  }
14744
14792
  async function embedBatch(opts) {
@@ -15784,8 +15832,8 @@ function localAgentRunUntil(agent, goal, options) {
15784
15832
  async function* wrap() {
15785
15833
  const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
15786
15834
  const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
15787
- const { getAgentCreate: getAgentCreate2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
15788
- const create = getAgentCreate2();
15835
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
15836
+ const create = getAgentFacade2().create;
15789
15837
  const deps = {
15790
15838
  judge: async (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
15791
15839
  };
@@ -15795,9 +15843,9 @@ function localAgentRunUntil(agent, goal, options) {
15795
15843
  }
15796
15844
  async function localAgentFork(parent, options) {
15797
15845
  const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
15798
- const { getAgentCreate: getAgentCreate2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
15846
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
15799
15847
  const { withPersonalityContext: withPersonalityContext2 } = await Promise.resolve().then(() => (init_context(), context_exports));
15800
- const create = getAgentCreate2();
15848
+ const create = getAgentFacade2().create;
15801
15849
  return withPersonalityContext2(
15802
15850
  { slug: parent.personalitySlugSnapshot, isFork: true },
15803
15851
  () => forkAgentImpl2(parent, options, { create })
@@ -15818,7 +15866,7 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
15818
15866
  // src/internal/runtime/local-agent/local-agent-send.ts
15819
15867
  init_errors();
15820
15868
 
15821
- // src/internal/runtime/abort-utils.ts
15869
+ // src/internal/runtime/concurrency/abort-utils.ts
15822
15870
  function anySignal(signals) {
15823
15871
  const filtered = signals.filter((s) => s !== void 0);
15824
15872
  if (filtered.length === 0) {
@@ -16847,7 +16895,13 @@ async function getOrCreateUncached(agentId, options) {
16847
16895
  throw err;
16848
16896
  }
16849
16897
  }
16850
- setAgentCreate((options) => Agent.create(options));
16898
+ setAgentFacade({
16899
+ create: (options) => Agent.create(options),
16900
+ prompt: (message, options) => Agent.prompt(message, options),
16901
+ get: (agentId) => Agent.get(agentId),
16902
+ resume: (agentId, options) => Agent.resume(agentId, options),
16903
+ batch: (prompts, options) => Agent.batch(prompts, options)
16904
+ });
16851
16905
 
16852
16906
  // src/agent-factory.ts
16853
16907
  function createAgentFactory(common) {
@@ -17285,6 +17339,7 @@ init_errors();
17285
17339
 
17286
17340
  // src/internal/cron/run-job.ts
17287
17341
  init_errors();
17342
+ init_agent_factory_registry();
17288
17343
  async function runCronJob(job) {
17289
17344
  if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, job.message);
17290
17345
  if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, job.message);
@@ -17293,18 +17348,18 @@ async function runCronJob(job) {
17293
17348
  });
17294
17349
  }
17295
17350
  async function runWithExistingAgent(agentId, message) {
17296
- const info = await Agent.get(agentId).catch(() => void 0);
17351
+ const info = await getAgentFacade().get(agentId).catch(() => void 0);
17297
17352
  if (info === void 0) {
17298
17353
  throw new UnknownAgentError(
17299
17354
  `Cron job references agentId "${agentId}" but no such agent is registered. The agent may have been disposed or the process restarted without persisting the agent registry.`,
17300
17355
  { code: "agent_not_registered" }
17301
17356
  );
17302
17357
  }
17303
- const agent = await Agent.resume(agentId);
17358
+ const agent = await getAgentFacade().resume(agentId);
17304
17359
  return agent.send(message);
17305
17360
  }
17306
17361
  async function runWithEphemeralAgent(baseOptions, message) {
17307
- const agent = await Agent.create(baseOptions);
17362
+ const agent = await getAgentFacade().create(baseOptions);
17308
17363
  return agent.send(message);
17309
17364
  }
17310
17365
 
@@ -17692,6 +17747,16 @@ async function updateJobStatus(jobId, enabled) {
17692
17747
  return updated;
17693
17748
  }
17694
17749
 
17750
+ // src/define-provider.ts
17751
+ function defineProvider(profile, opts) {
17752
+ return {
17753
+ name: profile.name,
17754
+ version: opts?.version ?? "1.0.0",
17755
+ kind: "model-provider",
17756
+ profile
17757
+ };
17758
+ }
17759
+
17695
17760
  // src/define-tool.ts
17696
17761
  init_to_json_schema();
17697
17762
  function defineTool(spec) {
@@ -19201,6 +19266,6 @@ function safeStringify2(v) {
19201
19266
  }
19202
19267
  }
19203
19268
 
19204
- export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineTool, extractRawId, getPricingEntry, inferApiMode, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
19269
+ export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createSquad, definePlugin, defineProvider, defineTool, extractRawId, getPricingEntry, inferApiMode, isTransientError, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeUsage, preflightCheck, toShareGptTrajectory, withCwdMutex };
19205
19270
  //# sourceMappingURL=index.js.map
19206
19271
  //# sourceMappingURL=index.js.map