@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/eval.cjs CHANGED
@@ -22,6 +22,24 @@ var __export = (target, all) => {
22
22
  __defProp(target, name, { get: all[name], enumerable: true });
23
23
  };
24
24
 
25
+ // src/internal/default-retriable.ts
26
+ function defaultRetriableForCode(code) {
27
+ switch (code) {
28
+ case "rate_limit":
29
+ case "timeout":
30
+ case "server_error":
31
+ case "network":
32
+ case "provider_unreachable":
33
+ return true;
34
+ default:
35
+ return false;
36
+ }
37
+ }
38
+ var init_default_retriable = __esm({
39
+ "src/internal/default-retriable.ts"() {
40
+ }
41
+ });
42
+
25
43
  // src/internal/security/redact.ts
26
44
  function readEnvOnce() {
27
45
  const raw = process.env.THEOKIT_REDACT_SECRETS;
@@ -172,7 +190,8 @@ __export(errors_exports, {
172
190
  UnsupportedBudgetOperationError: () => UnsupportedBudgetOperationError,
173
191
  UnsupportedRunOperationError: () => UnsupportedRunOperationError,
174
192
  UnsupportedTaskOperationError: () => UnsupportedTaskOperationError,
175
- coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode
193
+ coerceToKnownAgentRunErrorCode: () => coerceToKnownAgentRunErrorCode,
194
+ isTransientError: () => isTransientError
176
195
  });
177
196
  function coerceToKnownAgentRunErrorCode(code) {
178
197
  if (code !== void 0 && KNOWN_AGENT_RUN_ERROR_CODES.has(code)) {
@@ -204,21 +223,13 @@ function safeStringify(value) {
204
223
  return String(value);
205
224
  }
206
225
  }
207
- function defaultRetriableForCode(code) {
208
- switch (code) {
209
- case "rate_limit":
210
- case "timeout":
211
- case "server_error":
212
- case "network":
213
- case "provider_unreachable":
214
- return true;
215
- default:
216
- return false;
217
- }
226
+ function isTransientError(err) {
227
+ return err instanceof TheokitAgentError && err.isRetryable === true;
218
228
  }
219
229
  var KNOWN_AGENT_RUN_ERROR_CODES, TheokitAgentError, AuthenticationError, RateLimitError, ConfigurationError, IntegrationNotConnectedError, NetworkError, UnknownAgentError, AgentRunError, UnsupportedRunOperationError, CredentialPoolExhaustedError, MemoryAdapterError, InvalidTaskIdError, TaskNotFoundError, UnsupportedTaskOperationError, BudgetExceededError, AgentDisposedError, UnsupportedBudgetOperationError;
220
230
  var init_errors = __esm({
221
231
  "src/errors.ts"() {
232
+ init_default_retriable();
222
233
  init_redact();
223
234
  KNOWN_AGENT_RUN_ERROR_CODES = /* @__PURE__ */ new Set([
224
235
  "rate_limit",
@@ -585,7 +596,7 @@ var init_atomic_write = __esm({
585
596
  }
586
597
  });
587
598
 
588
- // src/internal/runtime/yaml-frontmatter.ts
599
+ // src/internal/runtime/context/yaml-frontmatter.ts
589
600
  function parseSimpleYaml(text) {
590
601
  const fields = {};
591
602
  for (const line of text.split(/\r?\n/)) {
@@ -609,7 +620,7 @@ function coerce(raw) {
609
620
  return raw;
610
621
  }
611
622
  var init_yaml_frontmatter = __esm({
612
- "src/internal/runtime/yaml-frontmatter.ts"() {
623
+ "src/internal/runtime/context/yaml-frontmatter.ts"() {
613
624
  }
614
625
  });
615
626
  async function loadMarkdownEntities(opts) {
@@ -812,11 +823,54 @@ function checkToolWhitelist(toolName) {
812
823
  }
813
824
  var toolWhitelistStore;
814
825
  var init_async_local_storage = __esm({
815
- "src/internal/runtime/async-local-storage.ts"() {
826
+ "src/internal/runtime/concurrency/async-local-storage.ts"() {
816
827
  toolWhitelistStore = new async_hooks.AsyncLocalStorage();
817
828
  }
818
829
  });
819
830
 
831
+ // src/internal/runtime/concurrency/async-semaphore.ts
832
+ function createSemaphore(permits) {
833
+ if (!Number.isInteger(permits) || permits < 1) {
834
+ throw new ConfigurationError(
835
+ `async-semaphore: permits must be a positive integer, got ${permits}`,
836
+ { code: "invalid_concurrency" }
837
+ );
838
+ }
839
+ let active = 0;
840
+ const queue = [];
841
+ function tryGrant() {
842
+ if (active < permits && queue.length > 0) {
843
+ const resolve3 = queue.shift();
844
+ if (resolve3 !== void 0) {
845
+ active += 1;
846
+ resolve3();
847
+ }
848
+ }
849
+ }
850
+ return {
851
+ inFlight: () => active,
852
+ pending: () => queue.length + active,
853
+ async acquire() {
854
+ await new Promise((resolve3) => {
855
+ queue.push(resolve3);
856
+ tryGrant();
857
+ });
858
+ let released = false;
859
+ return () => {
860
+ if (released) return;
861
+ released = true;
862
+ active -= 1;
863
+ tryGrant();
864
+ };
865
+ }
866
+ };
867
+ }
868
+ var init_async_semaphore = __esm({
869
+ "src/internal/runtime/concurrency/async-semaphore.ts"() {
870
+ init_errors();
871
+ }
872
+ });
873
+
820
874
  // src/internal/llm/credential-pool-types.ts
821
875
  var COOLDOWN_MS, DEFAULT_COOLDOWN_MS;
822
876
  var init_credential_pool_types = __esm({
@@ -1161,7 +1215,7 @@ var init_local_agent_plugins = __esm({
1161
1215
  }
1162
1216
  });
1163
1217
 
1164
- // src/internal/runtime/run-until.ts
1218
+ // src/internal/runtime/lifecycle/run-until.ts
1165
1219
  var run_until_exports = {};
1166
1220
  __export(run_until_exports, {
1167
1221
  composeContinuation: () => composeContinuation,
@@ -1254,7 +1308,7 @@ Your last response was:
1254
1308
  ${lastResponse.slice(0, 1e3)}`;
1255
1309
  }
1256
1310
  var init_run_until = __esm({
1257
- "src/internal/runtime/run-until.ts"() {
1311
+ "src/internal/runtime/lifecycle/run-until.ts"() {
1258
1312
  }
1259
1313
  });
1260
1314
 
@@ -1365,16 +1419,16 @@ var init_judge_call = __esm({
1365
1419
  // src/internal/runtime/registry/agent-factory-registry.ts
1366
1420
  var agent_factory_registry_exports = {};
1367
1421
  __export(agent_factory_registry_exports, {
1368
- getAgentCreate: () => getAgentCreate,
1369
- setAgentCreate: () => setAgentCreate
1422
+ getAgentFacade: () => getAgentFacade,
1423
+ setAgentFacade: () => setAgentFacade
1370
1424
  });
1371
- function setAgentCreate(fn) {
1372
- registered3 = fn;
1425
+ function setAgentFacade(facade) {
1426
+ registered3 = facade;
1373
1427
  }
1374
- function getAgentCreate() {
1428
+ function getAgentFacade() {
1375
1429
  if (registered3 === void 0) {
1376
1430
  throw new Error(
1377
- "internal: Agent.create not registered. The `agent.ts` module must be loaded before LocalAgent.runUntil/fork are invoked."
1431
+ "internal: Agent facade not registered. The `agent.ts` module must be loaded before internal subsystems (LocalAgent.runUntil/fork, eval, scorers, cron) invoke it."
1378
1432
  );
1379
1433
  }
1380
1434
  return registered3;
@@ -1385,7 +1439,7 @@ var init_agent_factory_registry = __esm({
1385
1439
  }
1386
1440
  });
1387
1441
 
1388
- // src/internal/runtime/fork-agent.ts
1442
+ // src/internal/runtime/lifecycle/fork-agent.ts
1389
1443
  var fork_agent_exports = {};
1390
1444
  __export(fork_agent_exports, {
1391
1445
  filterMemoryPlugins: () => filterMemoryPlugins,
@@ -1445,7 +1499,7 @@ function extractUsage(result) {
1445
1499
  };
1446
1500
  }
1447
1501
  var init_fork_agent = __esm({
1448
- "src/internal/runtime/fork-agent.ts"() {
1502
+ "src/internal/runtime/lifecycle/fork-agent.ts"() {
1449
1503
  init_async_local_storage();
1450
1504
  init_local_agent_plugins();
1451
1505
  }
@@ -1468,49 +1522,6 @@ var init_task = __esm({
1468
1522
  }
1469
1523
  });
1470
1524
 
1471
- // src/internal/runtime/async-semaphore.ts
1472
- function createSemaphore(permits) {
1473
- if (!Number.isInteger(permits) || permits < 1) {
1474
- throw new ConfigurationError(
1475
- `async-semaphore: permits must be a positive integer, got ${permits}`,
1476
- { code: "invalid_concurrency" }
1477
- );
1478
- }
1479
- let active = 0;
1480
- const queue = [];
1481
- function tryGrant() {
1482
- if (active < permits && queue.length > 0) {
1483
- const resolve3 = queue.shift();
1484
- if (resolve3 !== void 0) {
1485
- active += 1;
1486
- resolve3();
1487
- }
1488
- }
1489
- }
1490
- return {
1491
- inFlight: () => active,
1492
- pending: () => queue.length + active,
1493
- async acquire() {
1494
- await new Promise((resolve3) => {
1495
- queue.push(resolve3);
1496
- tryGrant();
1497
- });
1498
- let released = false;
1499
- return () => {
1500
- if (released) return;
1501
- released = true;
1502
- active -= 1;
1503
- tryGrant();
1504
- };
1505
- }
1506
- };
1507
- }
1508
- var init_async_semaphore = __esm({
1509
- "src/internal/runtime/async-semaphore.ts"() {
1510
- init_errors();
1511
- }
1512
- });
1513
-
1514
1525
  // src/internal/task/ring-buffer.ts
1515
1526
  var RingBuffer;
1516
1527
  var init_ring_buffer = __esm({
@@ -3082,8 +3093,21 @@ function sanitizeIdentifier(input, options) {
3082
3093
  }
3083
3094
  return input.toLowerCase();
3084
3095
  }
3096
+ function safeFilenameForId(id, options) {
3097
+ if (id.length === 0) {
3098
+ throw new ConfigurationError("Filename id must be a non-empty string", {
3099
+ code: "invalid_filename_id"
3100
+ });
3101
+ }
3102
+ const maxLen = options?.maxLen;
3103
+ const lower = id.toLowerCase();
3104
+ if (lower.length <= maxLen && IDENTIFIER_PATTERN.test(lower)) {
3105
+ return lower;
3106
+ }
3107
+ return `h-${crypto.createHash("sha256").update(id).digest("hex").slice(0, 16)}`;
3108
+ }
3085
3109
 
3086
- // src/internal/runtime/default-model.ts
3110
+ // src/internal/runtime/config/default-model.ts
3087
3111
  var DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
3088
3112
 
3089
3113
  // src/internal/runtime/registry/agent-registry-store.ts
@@ -3404,7 +3428,7 @@ async function flushRegistrySaves(cwd) {
3404
3428
  }
3405
3429
  }
3406
3430
 
3407
- // src/internal/runtime/system-prompt.ts
3431
+ // src/internal/runtime/system-prompt/system-prompt.ts
3408
3432
  async function resolveSystemPrompt(agent, override, ctx) {
3409
3433
  if (override !== void 0) return override;
3410
3434
  if (agent === void 0) return void 0;
@@ -5787,28 +5811,6 @@ function parseDecisionFromStdout(stdout) {
5787
5811
  return { decision: "allow" };
5788
5812
  }
5789
5813
 
5790
- // src/internal/runtime/memory/memory-path-selector.ts
5791
- var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
5792
- function shouldUsePortMemoryPath() {
5793
- const env = globalThis.process?.env;
5794
- if (env === void 0) return false;
5795
- const val = env[PORT_MEMORY_PATH_ENV_VAR];
5796
- return val === "1" || val === "true";
5797
- }
5798
- function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
5799
- if (consumerSupplied !== void 0) return consumerSupplied;
5800
- if (portPathEnabled) return defaultAdapter;
5801
- return void 0;
5802
- }
5803
- function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
5804
- if (portPathEnabled) return void 0;
5805
- return legacyTools;
5806
- }
5807
- function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
5808
- if (portPathEnabled) return void 0;
5809
- return legacySummary;
5810
- }
5811
-
5812
5814
  // src/internal/memory/storage/session-summary-writer.ts
5813
5815
  init_atomic_write();
5814
5816
  var MAX_TURN_CHARS = 2e3;
@@ -5816,10 +5818,7 @@ function sessionsDir(cwd) {
5816
5818
  return path.join(memoryDir(cwd), "sessions");
5817
5819
  }
5818
5820
  function sessionSummaryPath(cwd, runId) {
5819
- return path.join(sessionsDir(cwd), `${sanitizeRunId(runId)}.md`);
5820
- }
5821
- function sanitizeRunId(runId) {
5822
- return runId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128);
5821
+ return path.join(sessionsDir(cwd), `${safeFilenameForId(runId, { maxLen: 128 })}.md`);
5823
5822
  }
5824
5823
  function truncate(text) {
5825
5824
  if (text.length <= MAX_TURN_CHARS) return text;
@@ -5852,6 +5851,28 @@ async function writeSessionSummary(input) {
5852
5851
  await replaceFileAtomic(path, body);
5853
5852
  }
5854
5853
 
5854
+ // src/internal/runtime/memory/memory-path-selector.ts
5855
+ var PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
5856
+ function shouldUsePortMemoryPath() {
5857
+ const env = globalThis.process?.env;
5858
+ if (env === void 0) return false;
5859
+ const val = env[PORT_MEMORY_PATH_ENV_VAR];
5860
+ return val === "1" || val === "true";
5861
+ }
5862
+ function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
5863
+ if (consumerSupplied !== void 0) return consumerSupplied;
5864
+ if (portPathEnabled) return defaultAdapter;
5865
+ return void 0;
5866
+ }
5867
+ function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
5868
+ if (portPathEnabled) return void 0;
5869
+ return legacyTools;
5870
+ }
5871
+ function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
5872
+ if (portPathEnabled) return void 0;
5873
+ return legacySummary;
5874
+ }
5875
+
5855
5876
  // src/internal/runtime/session/agent-session-store.ts
5856
5877
  init_atomic_write();
5857
5878
  var VALID_ROLES = /* @__PURE__ */ new Set([
@@ -6108,7 +6129,7 @@ function clearSession(agentId) {
6108
6129
  sessions.delete(agentId);
6109
6130
  }
6110
6131
 
6111
- // src/internal/runtime/post-run-lifecycle.ts
6132
+ // src/internal/runtime/lifecycle/post-run-lifecycle.ts
6112
6133
  async function runPostRunLifecycle(inputs) {
6113
6134
  const {
6114
6135
  run,
@@ -6340,7 +6361,7 @@ var liveAgentRegistry = new LiveAgentRegistry();
6340
6361
  // src/internal/runtime/skills/subagents-loader.ts
6341
6362
  init_errors();
6342
6363
 
6343
- // src/internal/runtime/workspace-dir.ts
6364
+ // src/internal/runtime/config/workspace-dir.ts
6344
6365
  init_errors();
6345
6366
  async function readWorkspaceDir(root, errorCode, describe) {
6346
6367
  try {
@@ -6626,7 +6647,7 @@ var SystemPromptPipeline = class _SystemPromptPipeline {
6626
6647
  }
6627
6648
  };
6628
6649
 
6629
- // src/internal/runtime/validate-agent-options.ts
6650
+ // src/internal/runtime/validation/validate-agent-options.ts
6630
6651
  init_errors();
6631
6652
  function validateAgentOptions(options) {
6632
6653
  rejectProgrammaticHooks(options);
@@ -6821,6 +6842,71 @@ function validateMemory(options) {
6821
6842
  }
6822
6843
  }
6823
6844
 
6845
+ // src/internal/runtime/config/providers-manager.ts
6846
+ var ProvidersManagerImpl = class {
6847
+ constructor(model, providers, plugins) {
6848
+ this.model = model;
6849
+ this.providers = providers;
6850
+ this.plugins = plugins;
6851
+ }
6852
+ model;
6853
+ providers;
6854
+ plugins;
6855
+ routes() {
6856
+ const resolved = [];
6857
+ const modelProvider = providerFromModel(this.model);
6858
+ const seen = /* @__PURE__ */ new Set();
6859
+ if (this.providers?.routes !== void 0) {
6860
+ for (const route of this.providers.routes) {
6861
+ const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
6862
+ if (!seen.has(route.capability)) {
6863
+ seen.add(route.capability);
6864
+ resolved.push(resolvedRoute);
6865
+ }
6866
+ }
6867
+ }
6868
+ return Promise.resolve(resolved);
6869
+ }
6870
+ };
6871
+ function providerFromModel(model) {
6872
+ if (model === void 0) return void 0;
6873
+ const id = model.id;
6874
+ if (id.includes(":")) return id.split(":")[0];
6875
+ return void 0;
6876
+ }
6877
+ function resolveRoute(route, modelProvider, plugins) {
6878
+ if (route.capability === "chat" && modelProvider === route.provider) {
6879
+ const modelName = extractModelName(modelProvider, route);
6880
+ const base = {
6881
+ capability: route.capability,
6882
+ provider: route.provider,
6883
+ reason: "explicit-model-provider"
6884
+ };
6885
+ if (modelName !== void 0) base.model = modelName;
6886
+ return base;
6887
+ }
6888
+ if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
6889
+ return {
6890
+ capability: route.capability,
6891
+ provider: route.provider,
6892
+ reason: "first-available-plugin-provider"
6893
+ };
6894
+ }
6895
+ return {
6896
+ capability: route.capability,
6897
+ provider: route.provider,
6898
+ reason: "explicit-route"
6899
+ };
6900
+ }
6901
+ function extractModelName(prefix, route) {
6902
+ if (route.model !== void 0) return route.model;
6903
+ return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
6904
+ }
6905
+ function defaultModelForProvider(provider) {
6906
+ if (provider === "anthropic") return "claude-3-7-sonnet";
6907
+ return void 0;
6908
+ }
6909
+
6824
6910
  // src/internal/runtime/context/context-manager.ts
6825
6911
  init_errors();
6826
6912
  init_markdown_config_loader();
@@ -7617,71 +7703,6 @@ async function loadPluginManifestFromMarkdown(pluginsRoot, folderName) {
7617
7703
  return metadata;
7618
7704
  }
7619
7705
 
7620
- // src/internal/runtime/providers-manager.ts
7621
- var ProvidersManagerImpl = class {
7622
- constructor(model, providers, plugins) {
7623
- this.model = model;
7624
- this.providers = providers;
7625
- this.plugins = plugins;
7626
- }
7627
- model;
7628
- providers;
7629
- plugins;
7630
- routes() {
7631
- const resolved = [];
7632
- const modelProvider = providerFromModel(this.model);
7633
- const seen = /* @__PURE__ */ new Set();
7634
- if (this.providers?.routes !== void 0) {
7635
- for (const route of this.providers.routes) {
7636
- const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
7637
- if (!seen.has(route.capability)) {
7638
- seen.add(route.capability);
7639
- resolved.push(resolvedRoute);
7640
- }
7641
- }
7642
- }
7643
- return Promise.resolve(resolved);
7644
- }
7645
- };
7646
- function providerFromModel(model) {
7647
- if (model === void 0) return void 0;
7648
- const id = model.id;
7649
- if (id.includes(":")) return id.split(":")[0];
7650
- return void 0;
7651
- }
7652
- function resolveRoute(route, modelProvider, plugins) {
7653
- if (route.capability === "chat" && modelProvider === route.provider) {
7654
- const modelName = extractModelName(modelProvider, route);
7655
- const base = {
7656
- capability: route.capability,
7657
- provider: route.provider,
7658
- reason: "explicit-model-provider"
7659
- };
7660
- if (modelName !== void 0) base.model = modelName;
7661
- return base;
7662
- }
7663
- if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
7664
- return {
7665
- capability: route.capability,
7666
- provider: route.provider,
7667
- reason: "first-available-plugin-provider"
7668
- };
7669
- }
7670
- return {
7671
- capability: route.capability,
7672
- provider: route.provider,
7673
- reason: "explicit-route"
7674
- };
7675
- }
7676
- function extractModelName(prefix, route) {
7677
- if (route.model !== void 0) return route.model;
7678
- return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
7679
- }
7680
- function defaultModelForProvider(provider) {
7681
- if (provider === "anthropic") return "claude-3-7-sonnet";
7682
- return void 0;
7683
- }
7684
-
7685
7706
  // src/internal/runtime/skills/skills-manager.ts
7686
7707
  init_errors();
7687
7708
 
@@ -8028,7 +8049,7 @@ var IterationBudget = class {
8028
8049
  }
8029
8050
  };
8030
8051
 
8031
- // src/internal/runtime/validate-response.ts
8052
+ // src/internal/runtime/validation/validate-response.ts
8032
8053
  function validateResponse(response) {
8033
8054
  const trimmed = response.content.trim();
8034
8055
  const toolCallsArr = Array.isArray(response.toolCalls) ? response.toolCalls : [];
@@ -8414,6 +8435,27 @@ async function emitTextDeltaCallback(inputs, text) {
8414
8435
  // src/internal/agent-loop/tool-dispatch.ts
8415
8436
  init_async_local_storage();
8416
8437
 
8438
+ // src/internal/runtime/concurrency/map-with-concurrency.ts
8439
+ init_async_semaphore();
8440
+ var NEVER_ABORT = new AbortController().signal;
8441
+ async function mapWithConcurrency(items, concurrency, fn, options) {
8442
+ const semaphore = createSemaphore(concurrency);
8443
+ const signal = NEVER_ABORT;
8444
+ return Promise.all(
8445
+ items.map(async (item, index) => {
8446
+ const release = await semaphore.acquire();
8447
+ try {
8448
+ if (signal.aborted) {
8449
+ throw signal.reason instanceof Error ? signal.reason : new Error("mapWithConcurrency: aborted");
8450
+ }
8451
+ return await fn(item, index, signal);
8452
+ } finally {
8453
+ release();
8454
+ }
8455
+ })
8456
+ );
8457
+ }
8458
+
8417
8459
  // src/internal/tool-dispatch/repair-middleware.ts
8418
8460
  var DECIMAL_RE = /^-?\d+(\.\d+)?$/;
8419
8461
  function repairToolCall(raw, registry) {
@@ -8487,7 +8529,7 @@ function coerceArgsToSchema(args, schema) {
8487
8529
  return { value: out, changed };
8488
8530
  }
8489
8531
 
8490
- // src/internal/runtime/shell-tool.ts
8532
+ // src/internal/runtime/tools/shell-tool.ts
8491
8533
  async function runShell(options) {
8492
8534
  if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
8493
8535
  return {
@@ -8588,38 +8630,12 @@ ${result.stderr}`.trim();
8588
8630
  // src/internal/agent-loop/tool-dispatch.ts
8589
8631
  async function dispatchTools(inputs, tools, toolCalls, events) {
8590
8632
  const maxConcurrent = inputs.maxConcurrentTools ?? 4;
8591
- return boundedParallel(
8592
- maxConcurrent,
8633
+ return mapWithConcurrency(
8593
8634
  toolCalls,
8635
+ maxConcurrent,
8594
8636
  (call) => dispatchSingleCall(inputs, tools, call, events)
8595
8637
  );
8596
8638
  }
8597
- async function boundedParallel(max, items, fn) {
8598
- let running = 0;
8599
- const queue = [];
8600
- async function acquire() {
8601
- if (running < max) {
8602
- running++;
8603
- return;
8604
- }
8605
- await new Promise((resolve3) => queue.push(resolve3));
8606
- running++;
8607
- }
8608
- function release() {
8609
- running--;
8610
- if (queue.length > 0) queue.shift()();
8611
- }
8612
- return Promise.all(
8613
- items.map(async (item) => {
8614
- await acquire();
8615
- try {
8616
- return await fn(item);
8617
- } finally {
8618
- release();
8619
- }
8620
- })
8621
- );
8622
- }
8623
8639
  async function dispatchSingleCall(inputs, tools, call, events) {
8624
8640
  const { call: workingCall, repairs } = applyRepairAndExtractCall(tools, call);
8625
8641
  const callId = generateCallId();
@@ -9688,10 +9704,10 @@ function registerBuiltins() {
9688
9704
  registerCatalogProviders();
9689
9705
  }
9690
9706
 
9691
- // src/internal/errors/mappers/anthropic.ts
9707
+ // src/internal/error-mappers/anthropic.ts
9692
9708
  init_errors();
9693
9709
 
9694
- // src/internal/errors/mappers/shared.ts
9710
+ // src/internal/error-mappers/shared.ts
9695
9711
  var RAW_MAX_BYTES = 2048;
9696
9712
  function parseRetryAfter(headers) {
9697
9713
  if (headers === void 0) return void 0;
@@ -9720,7 +9736,7 @@ function buildErrorMetadata(args) {
9720
9736
  };
9721
9737
  }
9722
9738
 
9723
- // src/internal/errors/mappers/anthropic.ts
9739
+ // src/internal/error-mappers/anthropic.ts
9724
9740
  function mapAnthropicError(args) {
9725
9741
  const { status, body, headers, endpoint } = args;
9726
9742
  const code = mapAnthropicStatusToCode(status, body);
@@ -10060,7 +10076,7 @@ function buildAnthropicBody(request) {
10060
10076
  // src/internal/llm/bedrock-anthropic.ts
10061
10077
  init_errors();
10062
10078
 
10063
- // src/internal/errors/mappers/bedrock.ts
10079
+ // src/internal/error-mappers/bedrock.ts
10064
10080
  init_errors();
10065
10081
  function classifyBedrockError(args, awsType, message) {
10066
10082
  if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
@@ -10197,7 +10213,7 @@ function buildBedrockBody(request) {
10197
10213
  init_credential_pool();
10198
10214
  init_credential_pool_context();
10199
10215
 
10200
- // src/internal/errors/mappers/openai-compatible.ts
10216
+ // src/internal/error-mappers/openai-compatible.ts
10201
10217
  init_errors();
10202
10218
  function mapOpenAICompatibleError(args) {
10203
10219
  const { providerId, status, body, headers, endpoint } = args;
@@ -10361,7 +10377,7 @@ function readOpenAiContent(body) {
10361
10377
  return void 0;
10362
10378
  }
10363
10379
 
10364
- // src/internal/errors/mappers/ollama.ts
10380
+ // src/internal/error-mappers/ollama.ts
10365
10381
  init_errors();
10366
10382
  function mapOllamaTransportError(args) {
10367
10383
  if (args.providerId !== "ollama") return void 0;
@@ -11011,7 +11027,7 @@ function abortError2(signal) {
11011
11027
  // src/internal/llm/vertex-anthropic.ts
11012
11028
  init_errors();
11013
11029
 
11014
- // src/internal/errors/mappers/vertex.ts
11030
+ // src/internal/error-mappers/vertex.ts
11015
11031
  init_errors();
11016
11032
  var VERTEX_RULES = [
11017
11033
  { test: (s, e) => s === 429 || e === "RESOURCE_EXHAUSTED", code: "rate_limit" },
@@ -11553,6 +11569,16 @@ function resolveMcpCwd(configCwd) {
11553
11569
  return safePathJoin(process.cwd(), configCwd);
11554
11570
  }
11555
11571
 
11572
+ // src/internal/providers/register-plugin-providers.ts
11573
+ function registerPluginProviderProfiles(entries) {
11574
+ let registered4 = 0;
11575
+ for (const entry of entries) {
11576
+ registerProvider(entry.profile);
11577
+ registered4 += 1;
11578
+ }
11579
+ return registered4;
11580
+ }
11581
+
11556
11582
  // src/internal/tool-registry/personality-filter.ts
11557
11583
  init_hooks_source();
11558
11584
  function applyPersonalityFilter(exposedTools, whitelist, opts) {
@@ -11629,12 +11655,27 @@ function createRealLocalRun(options) {
11629
11655
  registerRun(handle);
11630
11656
  return handle;
11631
11657
  }
11632
- function buildLoopInputs(options, runId, userText) {
11658
+ var pluginProvidersAnnounced = false;
11659
+ function resolveRunProvider(options) {
11633
11660
  registerBuiltins();
11661
+ const profiles = options.pluginManager?.aggregated.providerProfiles ?? [];
11662
+ const registered4 = registerPluginProviderProfiles(profiles);
11663
+ if (registered4 > 0 && !pluginProvidersAnnounced) {
11664
+ pluginProvidersAnnounced = true;
11665
+ const names = profiles.map((e) => e.profile.name).join(", ");
11666
+ process.stderr.write(
11667
+ `[theokit-sdk] registered ${registered4} plugin provider profile(s): ${names}
11668
+ `
11669
+ );
11670
+ }
11634
11671
  const parsedModel = parseModelId(options.model?.id);
11635
11672
  const inferredProvider = parsedModel.provider !== void 0 && getProviderProfile(parsedModel.provider) !== void 0 ? parsedModel.provider : void 0;
11636
11673
  const primary = options.agentOptions.providers?.routes?.[0]?.provider ?? inferredProvider ?? detectPrimaryProvider();
11637
11674
  const effectiveModelId = inferredProvider !== void 0 ? parsedModel.name : options.model?.id ?? "claude-sonnet-4-6";
11675
+ return { primary, effectiveModelId };
11676
+ }
11677
+ function buildLoopInputs(options, runId, userText) {
11678
+ const { primary, effectiveModelId } = resolveRunProvider(options);
11638
11679
  const fallback = options.agentOptions.providers?.fallback;
11639
11680
  const apiKeys = options.agentOptions.providers?.apiKeys;
11640
11681
  const credentialPoolStrategy = options.agentOptions.providers?.credentialPoolStrategy;
@@ -12252,7 +12293,7 @@ async function embedTexts(input) {
12252
12293
  pending
12253
12294
  });
12254
12295
  }
12255
- await runBatches(input, pending, results);
12296
+ await embedInBoundedBatches(input, pending, results);
12256
12297
  return results.map((v) => v ?? new Array(dimension).fill(0));
12257
12298
  }
12258
12299
  function classifyEntry(args) {
@@ -12271,45 +12312,34 @@ function classifyEntry(args) {
12271
12312
  args.pending.push({ index: args.index, text: args.text, key });
12272
12313
  }
12273
12314
  var MAX_CONCURRENT_BATCHES = 3;
12274
- async function runBatches(input, pending, results) {
12315
+ async function embedInBoundedBatches(input, pending, results) {
12275
12316
  const batches = [];
12276
12317
  for (let offset = 0; offset < pending.length; offset += MAX_BATCH) {
12277
12318
  batches.push(pending.slice(offset, offset + MAX_BATCH));
12278
12319
  }
12279
- let running = 0;
12280
- const queue = [];
12281
- await Promise.all(batches.map((batch) => processBatch(input, batch, results, acquire, release)));
12282
- async function acquire() {
12283
- if (running >= MAX_CONCURRENT_BATCHES) await new Promise((r) => queue.push(r));
12284
- running++;
12285
- }
12286
- function release() {
12287
- running--;
12288
- if (queue.length > 0) queue.shift()();
12289
- }
12320
+ await mapWithConcurrency(
12321
+ batches,
12322
+ MAX_CONCURRENT_BATCHES,
12323
+ (batch) => processBatch(input, batch, results)
12324
+ );
12290
12325
  }
12291
- async function processBatch(input, batch, results, acquire, release) {
12292
- await acquire();
12293
- try {
12294
- const vectors = await embedBatch({
12295
- apiKey: input.apiKey,
12296
- baseUrl: input.baseUrl,
12297
- embeddingsPath: input.embeddingsPath,
12298
- model: input.model,
12299
- inputs: batch.map((b) => b.text),
12300
- fetchImpl: input.fetchImpl,
12301
- stats: input.stats,
12302
- providerId: input.providerId
12303
- });
12304
- for (let j = 0; j < batch.length; j++) {
12305
- const slot = batch[j];
12306
- const vector = vectors[j];
12307
- if (slot === void 0 || vector === void 0) continue;
12308
- results[slot.index] = vector;
12309
- input.cache.set(slot.key, vector);
12310
- }
12311
- } finally {
12312
- release();
12326
+ async function processBatch(input, batch, results) {
12327
+ const vectors = await embedBatch({
12328
+ apiKey: input.apiKey,
12329
+ baseUrl: input.baseUrl,
12330
+ embeddingsPath: input.embeddingsPath,
12331
+ model: input.model,
12332
+ inputs: batch.map((b) => b.text),
12333
+ fetchImpl: input.fetchImpl,
12334
+ stats: input.stats,
12335
+ providerId: input.providerId
12336
+ });
12337
+ for (let j = 0; j < batch.length; j++) {
12338
+ const slot = batch[j];
12339
+ const vector = vectors[j];
12340
+ if (slot === void 0 || vector === void 0) continue;
12341
+ results[slot.index] = vector;
12342
+ input.cache.set(slot.key, vector);
12313
12343
  }
12314
12344
  }
12315
12345
  async function embedBatch(opts) {
@@ -12742,7 +12772,7 @@ function sanitizeFts5Query(query) {
12742
12772
  return text.trim();
12743
12773
  }
12744
12774
 
12745
- // src/internal/memory/index-db.ts
12775
+ // src/internal/persistence/sqlite-open.ts
12746
12776
  init_errors();
12747
12777
 
12748
12778
  // src/internal/persistence/sqlite-wal.ts
@@ -12770,6 +12800,57 @@ function logFallback(label, reason) {
12770
12800
  );
12771
12801
  }
12772
12802
 
12803
+ // src/internal/persistence/sqlite-open.ts
12804
+ async function openSqliteResilient(options) {
12805
+ await promises.mkdir(path.dirname(options.filePath), { recursive: true });
12806
+ try {
12807
+ return await openConcrete(options);
12808
+ } catch (cause) {
12809
+ if (options.recoverCorrupt !== false && isCorruptionError(cause)) {
12810
+ await renameAside(options.filePath, options.label ?? "sqlite");
12811
+ return await openConcrete(options);
12812
+ }
12813
+ throw cause;
12814
+ }
12815
+ }
12816
+ async function openConcrete(options) {
12817
+ const db = await loadDriver(options.filePath);
12818
+ applyWalWithFallback(db, options.label ?? "sqlite");
12819
+ await options.onOpen?.(db);
12820
+ return db;
12821
+ }
12822
+ async function loadDriver(filePath) {
12823
+ try {
12824
+ const mod = await import('better-sqlite3');
12825
+ const Ctor = mod.default ?? mod;
12826
+ if (typeof Ctor !== "function") {
12827
+ throw new Error(`better-sqlite3 export is not a constructor (got ${typeof Ctor})`);
12828
+ }
12829
+ return new Ctor(filePath);
12830
+ } catch (cause) {
12831
+ const message = cause instanceof Error ? cause.message : String(cause);
12832
+ throw new ConfigurationError(
12833
+ `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
12834
+ { code: "sqlite_driver_unavailable", cause }
12835
+ );
12836
+ }
12837
+ }
12838
+ function isCorruptionError(cause) {
12839
+ if (!(cause instanceof Error)) return false;
12840
+ const msg = cause.message.toLowerCase();
12841
+ return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
12842
+ }
12843
+ async function renameAside(filePath, label) {
12844
+ const asidePath = `${filePath}.corrupt-${Date.now()}`;
12845
+ await promises.rename(filePath, asidePath).catch(() => void 0);
12846
+ await promises.rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
12847
+ await promises.rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
12848
+ process.stderr.write(
12849
+ `[theokit-sdk] ${label} database corrupt; renamed aside to ${asidePath} and rebuilt schema
12850
+ `
12851
+ );
12852
+ }
12853
+
12773
12854
  // src/internal/memory/index-schema.ts
12774
12855
  var SCHEMA_STATEMENTS = [
12775
12856
  `CREATE TABLE IF NOT EXISTS files (
@@ -12813,52 +12894,15 @@ var PRAGMA_STATEMENTS = [
12813
12894
 
12814
12895
  // src/internal/memory/index-db.ts
12815
12896
  async function openMemoryDb(opts) {
12816
- await promises.mkdir(path.dirname(opts.filePath), { recursive: true });
12817
- try {
12818
- return await openConcrete(opts.filePath);
12819
- } catch (cause) {
12820
- if (opts.recoverCorrupt !== false && isCorruptionError(cause)) {
12821
- await renameAside(opts.filePath);
12822
- return await openConcrete(opts.filePath);
12897
+ return openSqliteResilient({
12898
+ filePath: opts.filePath,
12899
+ label: "memory-index",
12900
+ recoverCorrupt: opts.recoverCorrupt,
12901
+ onOpen: (db) => {
12902
+ for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
12903
+ for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
12823
12904
  }
12824
- throw cause;
12825
- }
12826
- }
12827
- async function openConcrete(filePath) {
12828
- const db = await loadDriver(filePath);
12829
- applyWalWithFallback(db, "memory-index");
12830
- for (const pragma of PRAGMA_STATEMENTS) db.exec(pragma);
12831
- for (const stmt of SCHEMA_STATEMENTS) db.exec(stmt);
12832
- return db;
12833
- }
12834
- async function loadDriver(filePath) {
12835
- try {
12836
- const mod = await import('better-sqlite3');
12837
- const Ctor = mod.default ?? mod;
12838
- const db = new Ctor(filePath);
12839
- return db;
12840
- } catch (cause) {
12841
- const message = cause instanceof Error ? cause.message : String(cause);
12842
- throw new ConfigurationError(
12843
- `Failed to load SQLite driver. Install \`better-sqlite3\` or run on Node 22.5+ for built-in \`node:sqlite\`. Cause: ${message}`,
12844
- { code: "sqlite_driver_unavailable", cause }
12845
- );
12846
- }
12847
- }
12848
- function isCorruptionError(cause) {
12849
- if (!(cause instanceof Error)) return false;
12850
- const msg = cause.message.toLowerCase();
12851
- return msg.includes("malformed") || msg.includes("not a database") || msg.includes("encrypted") || msg.includes("disk image is malformed");
12852
- }
12853
- async function renameAside(filePath) {
12854
- const asidePath = `${filePath}.corrupt-${Date.now()}`;
12855
- await promises.rename(filePath, asidePath).catch(() => void 0);
12856
- await promises.rename(`${filePath}-wal`, `${asidePath}-wal`).catch(() => void 0);
12857
- await promises.rename(`${filePath}-shm`, `${asidePath}-shm`).catch(() => void 0);
12858
- process.stderr.write(
12859
- `[theokit-sdk] memory index corrupt; renamed aside to ${asidePath} and rebuilt schema
12860
- `
12861
- );
12905
+ });
12862
12906
  }
12863
12907
  function defaultIndexPath(cwd) {
12864
12908
  return path.join(cwd, ".theokit", "memory", ".index", "memory.sqlite");
@@ -14261,8 +14305,8 @@ function localAgentRunUntil(agent, goal, options) {
14261
14305
  async function* wrap() {
14262
14306
  const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
14263
14307
  const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
14264
- const { getAgentCreate: getAgentCreate2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14265
- const create = getAgentCreate2();
14308
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14309
+ const create = getAgentFacade2().create;
14266
14310
  const deps = {
14267
14311
  judge: async (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
14268
14312
  };
@@ -14272,9 +14316,9 @@ function localAgentRunUntil(agent, goal, options) {
14272
14316
  }
14273
14317
  async function localAgentFork(parent, options) {
14274
14318
  const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
14275
- const { getAgentCreate: getAgentCreate2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14319
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14276
14320
  const { withPersonalityContext: withPersonalityContext2 } = await Promise.resolve().then(() => (init_context(), context_exports));
14277
- const create = getAgentCreate2();
14321
+ const create = getAgentFacade2().create;
14278
14322
  return withPersonalityContext2(
14279
14323
  { slug: parent.personalitySlugSnapshot, isFork: true },
14280
14324
  () => forkAgentImpl2(parent, options, { create })
@@ -14295,7 +14339,7 @@ async function persistMemoryFactIfWritePrompt(workspaceCwd, memoryConfig, userTe
14295
14339
  // src/internal/runtime/local-agent/local-agent-send.ts
14296
14340
  init_errors();
14297
14341
 
14298
- // src/internal/runtime/abort-utils.ts
14342
+ // src/internal/runtime/concurrency/abort-utils.ts
14299
14343
  function anySignal(signals) {
14300
14344
  const filtered = signals.filter((s) => s !== void 0);
14301
14345
  if (filtered.length === 0) {
@@ -15324,7 +15368,16 @@ async function getOrCreateUncached(agentId, options) {
15324
15368
  throw err;
15325
15369
  }
15326
15370
  }
15327
- setAgentCreate((options) => Agent.create(options));
15371
+ setAgentFacade({
15372
+ create: (options) => Agent.create(options),
15373
+ prompt: (message, options) => Agent.prompt(message, options),
15374
+ get: (agentId) => Agent.get(agentId),
15375
+ resume: (agentId, options) => Agent.resume(agentId, options),
15376
+ batch: (prompts, options) => Agent.batch(prompts, options)
15377
+ });
15378
+
15379
+ // src/internal/eval/runner.ts
15380
+ init_agent_factory_registry();
15328
15381
 
15329
15382
  // src/internal/eval/aggregate.ts
15330
15383
  function percentile(sorted, p) {
@@ -15627,7 +15680,7 @@ async function runRowsViaBatch(entries, agentOptions, scorers, concurrency, sign
15627
15680
  concurrency,
15628
15681
  ...signal !== void 0 ? { signal } : {}
15629
15682
  };
15630
- const batchResults = await Agent.batch(prompts, batchOpts);
15683
+ const batchResults = await getAgentFacade().batch(prompts, batchOpts);
15631
15684
  const rows = [];
15632
15685
  for (let i = 0; i < batchResults.length; i += 1) {
15633
15686
  const entry = entries[i];
@@ -15700,6 +15753,7 @@ async function runEval(options, runOpts) {
15700
15753
  }
15701
15754
 
15702
15755
  // src/internal/scorers/llm-judge.ts
15756
+ init_agent_factory_registry();
15703
15757
  function buildPrompt(subject, criteria, rubric, expected) {
15704
15758
  const scoreHint = rubric === "discrete" ? "between 0 and 1 (use 0 for fail, 1 for pass)" : "between 0.0 and 1.0";
15705
15759
  const expectedBlock = expected !== void 0 ? `EXPECTED (reference): ${JSON.stringify(expected)}
@@ -15724,7 +15778,7 @@ function buildPrompt(subject, criteria, rubric, expected) {
15724
15778
  var SCORE_REGEX = /\{\s*"score"\s*:\s*([0-9]*\.?[0-9]+)\s*,\s*"reason"\s*:\s*"([^"]*)"\s*\}/;
15725
15779
  async function callJudge(message, options) {
15726
15780
  try {
15727
- const result = await Agent.prompt(message, {
15781
+ const result = await getAgentFacade().prompt(message, {
15728
15782
  apiKey: options.apiKey,
15729
15783
  model: options.model,
15730
15784
  local: { cwd: process.cwd(), sandboxOptions: { enabled: false } },