@theokit/sdk 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/a2a/index.cjs +154 -148
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +154 -148
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/{cron-Ci_NUkUj.d.ts → cron-Bj8-Aq1O.d.ts} +1 -1
  7. package/dist/{cron-Bse1MbaE.d.cts → cron-DFG9-W17.d.cts} +1 -1
  8. package/dist/cron.cjs +135 -128
  9. package/dist/cron.cjs.map +1 -1
  10. package/dist/cron.d.cts +1 -1
  11. package/dist/cron.d.ts +1 -1
  12. package/dist/cron.js +138 -131
  13. package/dist/cron.js.map +1 -1
  14. package/dist/eval.cjs +134 -124
  15. package/dist/eval.cjs.map +1 -1
  16. package/dist/eval.d.cts +1 -0
  17. package/dist/eval.d.ts +1 -0
  18. package/dist/eval.js +137 -127
  19. package/dist/eval.js.map +1 -1
  20. package/dist/index.cjs +113 -106
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +113 -106
  25. package/dist/index.js.map +1 -1
  26. package/dist/internal/runtime/{fork-agent.d.ts → lifecycle/fork-agent.d.ts} +1 -1
  27. package/dist/internal/runtime/{run-until.d.ts → lifecycle/run-until.d.ts} +3 -3
  28. package/dist/internal/runtime/local-agent/local-agent-bootstrap.d.ts +1 -1
  29. package/dist/internal/runtime/registry/agent-factory-registry.d.ts +12 -9
  30. package/dist/internal/scorers/llm-judge.d.ts +4 -4
  31. package/dist/internal/security/index.d.cts +1 -1
  32. package/dist/internal/security/index.d.ts +1 -1
  33. package/dist/types/fork.d.ts +1 -1
  34. package/dist/workflow.cjs +2 -2
  35. package/dist/workflow.cjs.map +1 -1
  36. package/dist/workflow.js +2 -2
  37. package/dist/workflow.js.map +1 -1
  38. package/package.json +6 -2
  39. /package/dist/internal/{errors/mappers → error-mappers}/anthropic.d.ts +0 -0
  40. /package/dist/internal/{errors/mappers → error-mappers}/bedrock.d.ts +0 -0
  41. /package/dist/internal/{errors/mappers → error-mappers}/ollama.d.ts +0 -0
  42. /package/dist/internal/{errors/mappers → error-mappers}/openai-compatible.d.ts +0 -0
  43. /package/dist/internal/{errors/mappers → error-mappers}/shared.d.ts +0 -0
  44. /package/dist/internal/{errors/mappers → error-mappers}/vertex.d.ts +0 -0
  45. /package/dist/internal/runtime/{abort-utils.d.ts → concurrency/abort-utils.d.ts} +0 -0
  46. /package/dist/internal/runtime/{async-local-storage.d.ts → concurrency/async-local-storage.d.ts} +0 -0
  47. /package/dist/internal/runtime/{async-semaphore.d.ts → concurrency/async-semaphore.d.ts} +0 -0
  48. /package/dist/internal/runtime/{default-model.d.ts → config/default-model.d.ts} +0 -0
  49. /package/dist/internal/runtime/{providers-manager.d.ts → config/providers-manager.d.ts} +0 -0
  50. /package/dist/internal/runtime/{workspace-dir.d.ts → config/workspace-dir.d.ts} +0 -0
  51. /package/dist/internal/runtime/{yaml-frontmatter.d.ts → context/yaml-frontmatter.d.ts} +0 -0
  52. /package/dist/internal/runtime/{post-run-lifecycle.d.ts → lifecycle/post-run-lifecycle.d.ts} +0 -0
  53. /package/dist/internal/runtime/{spawn-collect.d.ts → lifecycle/spawn-collect.d.ts} +0 -0
  54. /package/dist/internal/runtime/{system-prompt.d.ts → system-prompt/system-prompt.d.ts} +0 -0
  55. /package/dist/internal/runtime/{shell-tool.d.ts → tools/shell-tool.d.ts} +0 -0
  56. /package/dist/internal/runtime/{validate-agent-options.d.ts → validation/validate-agent-options.d.ts} +0 -0
  57. /package/dist/internal/runtime/{validate-response.d.ts → validation/validate-response.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - aac62bc: Internal architecture cleanup (arch-review Groups A–D) — no public API or behavior change.
8
+
9
+ - **Group A:** widen the internal `agent-factory-registry` inversion seam from `create()` to a full `AgentFacadePort` (`create`/`prompt`/`get`/`resume`/`batch`); route `internal/{eval,scorers,cron}` through `getAgentFacade()` instead of importing the public `Agent` facade upward. A `internal-must-not-import-facade` dependency-cruiser rule now enforces the boundary. `cron.ts`/`eval.ts` gained an `import "./agent.js"` bootstrap (kept out of tree-shaking via the `sideEffects` allowlist) so the `@theokit/sdk/cron` and `@theokit/sdk/eval` sub-path entries still register the facade at load time.
10
+ - **Group B:** relocated the 17 loose `internal/runtime/*.ts` modules into cohesive sub-folders (`lifecycle/`, `validation/`, `concurrency/`, `tools/`, `config/`, plus folding `system-prompt.ts`/`yaml-frontmatter.ts` into existing dirs); removed the dead `internal/runtime/mcp-tools.ts`.
11
+ - **Group C:** removed the cargo-cult `TheoKitContainer` (was `@public` but never exported; `run()` discarded registered tools/workflows); the `multi-agent` template now uses `Agent.create()`.
12
+ - **Group D:** renamed `internal/errors/` → `internal/error-mappers/` (the directory holds only provider error-mappers, no error classes).
13
+
14
+ All changes are internal-only and behavior-preserving (full suite GREEN, `madge --circular` unchanged, depcruise clean). Consumers see no API or behavior difference.
15
+
3
16
  ## 2.0.0
4
17
 
5
18
  ### Major Changes
@@ -32,10 +45,15 @@
32
45
 
33
46
  ### Fixed
34
47
 
48
+ - The Agent-facade bootstrap added in Group A (`import "./agent.js"` in `cron.ts`/`eval.ts`) was tree-shaken out of the built `cron.js`/`eval.js` bundles under `package.json "sideEffects": false` + tsup `treeshake: true`. SDK-source tests passed but real **dist** consumers (e.g. `@theokit/cli` via `@theokit/sdk/eval`) hit `internal: Agent facade not registered` at runtime. Declared `agent.{ts,js,cjs}` in the `sideEffects` allowlist so the bootstrap survives bundling while the rest of the package stays tree-shakeable. Bundle size unchanged from the pre-Group-A baseline. (arch-review Group A follow-up; caught by `pnpm validate`)
35
49
  - `Agent.batch` now validates its inputs at the boundary (fail-fast). Invalid `concurrency` (not a positive integer) throws `ConfigurationError(code: "invalid_concurrency")` with a user-facing message, and an empty/non-string prompt item throws `ConfigurationError(code: "invalid_batch_item")` — both BEFORE any credential pool is built or Task is registered. Previously invalid `concurrency` surfaced only deep inside the semaphore with a leaky "permits" message AND after task registration (a dangling Task could be registered with `task: true`), and empty-string prompts flowed silently to `agent.send`. New `validateBatchInput` pre-flight; whitespace-only prompts are intentionally still accepted (non-empty strings; the validator does not judge content). (arch-review cross-validation Gap 3)
36
50
 
37
51
  ### Changed
38
52
 
53
+ - Renamed `src/internal/errors/` → `src/internal/error-mappers/`, collapsing the redundant `mappers/` nesting (arch-review Group D). The directory held only provider error-mapper implementations (anthropic, bedrock, ollama, openai-compatible, vertex, shared) and zero error classes — those live in `src/errors.ts` — so `errors/` was a misnomer. Pure rename + import-path fixups across importers, tests (moved to `tests/internal/error-mappers/`), and `docs/error-codes.md`; no API/behavior change.
54
+ - Removed the cargo-cult `TheoKitContainer` (`src/theokit-container.ts`, arch-review Group C). It was `@public`-annotated but never exported from `index.ts` — no consumer could import it, so removal has zero real breaking impact — and its `run()` rebuilt a fresh `Agent.create` from only `model`/`apiKey`/`systemPrompt`, silently discarding the registered `tools`/`workflows` (dead, misleading surface that contradicts ADR D431's "factory functions are canonical; no in-SDK IoC container"). The `multi-agent` template + README now coordinate specialists via `Agent.create()`. The container's e2e error-propagation test was re-expressed as genuine coverage of the REAL `AgentDisposedError` thrown by `local-agent-send.ts` (the container had faked it with a string) — a net coverage gain. Deleted `tests/theokit-container.test.ts` + `tests/e2e/container-multi-agent.e2e.test.ts` (pure container bookkeeping, no Agent-level coverage).
55
+ - Completed the `internal/runtime/` root cleanup (arch-review Group B). The flat root previously held 18 loose modules (down from 62 after M4); relocated the remaining 17 into cohesive sub-folders — `lifecycle/` (run-until, fork-agent, post-run-lifecycle, spawn-collect, auto-summarize), `validation/` (validate-agent-options, validate-response), `concurrency/` (async-local-storage, async-semaphore, abort-utils), `tools/` (shell-tool, hitl-middleware), `config/` (default-model, workspace-dir, providers-manager) — plus folding `system-prompt.ts` into the existing `system-prompt/` dir and `yaml-frontmatter.ts` into `context/`. `internal/runtime/` root now holds zero loose `.ts`. Removed the dead `internal/runtime/mcp-tools.ts` (`buildToolList` had zero callers; survived prior gates because orphan detection excludes `internal/`). Pure `git mv` + import-path fixups (39 importer files), one dead-code deletion; no API/behavior change. Full suite GREEN (2616 pass); `madge --circular` unchanged (1 type-only cycle); depcruise clean.
56
+ - Closed the last 3 wrong-direction imports where `internal/{eval,scorers,cron}` imported the public `Agent` facade directly (arch-review Group A). The `agent-factory-registry` inversion seam was widened from a single `create()` to a full `AgentFacadePort` (`create`/`prompt`/`get`/`resume`/`batch`); `eval/runner` (batch), `scorers/llm-judge` (prompt), and `cron/run-job` (get/resume/create) now resolve the facade via `getAgentFacade()` instead of inverting the public-api → internal dependency direction. A new `internal-must-not-import-facade` dependency-cruiser rule permanently enforces the boundary. The `cron.ts`/`eval.ts` facades gained an explicit `import "./agent.js"` bootstrap so the `@theokit/sdk/cron` and `@theokit/sdk/eval` sub-path entries still register the facade at load time (preserving the side effect the removed direct imports used to provide). Fully internal — no API/behavior change; full suite GREEN, `madge --circular` unchanged (1 intentional type-only cycle), depcruise clean.
39
57
  - Reorganized the flat 62-file `src/internal/runtime/` god folder into sub-concern folders (arch-review M4): `local-agent/` (15), `cloud/` (6), `compression/` (6), `hooks/` (4), `budget/` (3), `memory/` (4), `session/` (3), `skills/` (3) — alongside the pre-existing `registry/`, `system-prompt/`, `context/`, `fixtures/`, `plugins/`. 18 cross-cutting singletons (abort-utils, async-_, default-model, fork-agent, run-until, system-prompt, validate-_, etc.) remain at the `runtime/` root (down from 62). Pure file moves + import-path updates (44 files moved, ~100 import sites rewritten incl. 2 lint-allowlist path updates); `internal/runtime` is not an exported subpath and has no tsup entry, so the change is fully internal — no API/behavior change. Full SDK suite GREEN (2629 tests); `madge --circular` unchanged (1 intentional type-only `memory/memory-provider` cycle).
40
58
  - Broke 2 of 3 type-only dependency cycles in the public type barrel (arch-review ADR 0001). `ForkOptions`/`ForkResult` moved to a leaf `types/fork.ts`, so `types/agent.ts` no longer imports the `internal/runtime/fork-agent.ts` implementation (`fork-agent.ts` re-exports them for back-compat). Eliminates the `types/agent.ts → fork-agent.ts → {plugins/types,(self)}` cycles. No behavior/API change; `madge --circular` drops from 3 to 1 (the remaining `memory-provider` cycle is a genuine bidirectional type relationship, runtime-safe, left intentionally).
41
59
 
@@ -1043,10 +1043,10 @@ var init_path_guard = __esm({
1043
1043
  }
1044
1044
  });
1045
1045
 
1046
- // src/internal/runtime/default-model.ts
1046
+ // src/internal/runtime/config/default-model.ts
1047
1047
  var DEFAULT_AGENTIC_MODEL_ID;
1048
1048
  var init_default_model = __esm({
1049
- "src/internal/runtime/default-model.ts"() {
1049
+ "src/internal/runtime/config/default-model.ts"() {
1050
1050
  DEFAULT_AGENTIC_MODEL_ID = "google/gemini-2.0-flash-001";
1051
1051
  }
1052
1052
  });
@@ -1442,7 +1442,7 @@ var init_agent_registry = __esm({
1442
1442
  }
1443
1443
  });
1444
1444
 
1445
- // src/internal/runtime/system-prompt.ts
1445
+ // src/internal/runtime/system-prompt/system-prompt.ts
1446
1446
  async function resolveSystemPrompt(agent, override, ctx) {
1447
1447
  if (override !== void 0) return override;
1448
1448
  if (agent === void 0) return void 0;
@@ -1460,7 +1460,7 @@ async function resolveSystemPromptForSend(agent, override, buildCtx) {
1460
1460
  return resolveSystemPrompt(agent, override, ctx);
1461
1461
  }
1462
1462
  var init_system_prompt = __esm({
1463
- "src/internal/runtime/system-prompt.ts"() {
1463
+ "src/internal/runtime/system-prompt/system-prompt.ts"() {
1464
1464
  }
1465
1465
  });
1466
1466
 
@@ -3114,7 +3114,7 @@ var init_paths = __esm({
3114
3114
  }
3115
3115
  });
3116
3116
 
3117
- // src/internal/runtime/yaml-frontmatter.ts
3117
+ // src/internal/runtime/context/yaml-frontmatter.ts
3118
3118
  function parseSimpleYaml(text) {
3119
3119
  const fields = {};
3120
3120
  for (const line of text.split(/\r?\n/)) {
@@ -3138,7 +3138,7 @@ function coerce(raw) {
3138
3138
  return raw;
3139
3139
  }
3140
3140
  var init_yaml_frontmatter = __esm({
3141
- "src/internal/runtime/yaml-frontmatter.ts"() {
3141
+ "src/internal/runtime/context/yaml-frontmatter.ts"() {
3142
3142
  }
3143
3143
  });
3144
3144
  async function loadMarkdownEntities(opts) {
@@ -4142,7 +4142,7 @@ function spawnAndCollect(options) {
4142
4142
  });
4143
4143
  }
4144
4144
  var init_spawn_collect = __esm({
4145
- "src/internal/runtime/spawn-collect.ts"() {
4145
+ "src/internal/runtime/lifecycle/spawn-collect.ts"() {
4146
4146
  }
4147
4147
  });
4148
4148
 
@@ -4239,33 +4239,6 @@ var init_hooks_executor = __esm({
4239
4239
  };
4240
4240
  }
4241
4241
  });
4242
-
4243
- // src/internal/runtime/memory/memory-path-selector.ts
4244
- function shouldUsePortMemoryPath() {
4245
- const env = globalThis.process?.env;
4246
- if (env === void 0) return false;
4247
- const val = env[PORT_MEMORY_PATH_ENV_VAR];
4248
- return val === "1" || val === "true";
4249
- }
4250
- function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
4251
- if (consumerSupplied !== void 0) return consumerSupplied;
4252
- if (portPathEnabled) return defaultAdapter;
4253
- return void 0;
4254
- }
4255
- function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
4256
- if (portPathEnabled) return void 0;
4257
- return legacyTools;
4258
- }
4259
- function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
4260
- if (portPathEnabled) return void 0;
4261
- return legacySummary;
4262
- }
4263
- var PORT_MEMORY_PATH_ENV_VAR;
4264
- var init_memory_path_selector = __esm({
4265
- "src/internal/runtime/memory/memory-path-selector.ts"() {
4266
- PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
4267
- }
4268
- });
4269
4242
  function sessionsDir(cwd) {
4270
4243
  return path.join(memoryDir(cwd), "sessions");
4271
4244
  }
@@ -4314,6 +4287,33 @@ var init_session_summary_writer = __esm({
4314
4287
  MAX_TURN_CHARS = 2e3;
4315
4288
  }
4316
4289
  });
4290
+
4291
+ // src/internal/runtime/memory/memory-path-selector.ts
4292
+ function shouldUsePortMemoryPath() {
4293
+ const env = globalThis.process?.env;
4294
+ if (env === void 0) return false;
4295
+ const val = env[PORT_MEMORY_PATH_ENV_VAR];
4296
+ return val === "1" || val === "true";
4297
+ }
4298
+ function resolveMemoryProviderForLoop(consumerSupplied, defaultAdapter, portPathEnabled) {
4299
+ if (consumerSupplied !== void 0) return consumerSupplied;
4300
+ if (portPathEnabled) return defaultAdapter;
4301
+ return void 0;
4302
+ }
4303
+ function resolveMemoryToolsForLoop(legacyTools, portPathEnabled) {
4304
+ if (portPathEnabled) return void 0;
4305
+ return legacyTools;
4306
+ }
4307
+ function resolveActiveMemorySummaryForSend(legacySummary, portPathEnabled) {
4308
+ if (portPathEnabled) return void 0;
4309
+ return legacySummary;
4310
+ }
4311
+ var PORT_MEMORY_PATH_ENV_VAR;
4312
+ var init_memory_path_selector = __esm({
4313
+ "src/internal/runtime/memory/memory-path-selector.ts"() {
4314
+ PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
4315
+ }
4316
+ });
4317
4317
  function sessionFilePath(cwd, agentId) {
4318
4318
  const safe2 = sanitizeIdentifier(agentId, { maxLen: 128 });
4319
4319
  return safePathJoin(cwd, ".theokit", "agents", safe2, "messages.jsonl");
@@ -4587,7 +4587,7 @@ var init_agent_session = __esm({
4587
4587
  }
4588
4588
  });
4589
4589
 
4590
- // src/internal/runtime/post-run-lifecycle.ts
4590
+ // src/internal/runtime/lifecycle/post-run-lifecycle.ts
4591
4591
  async function runPostRunLifecycle(inputs) {
4592
4592
  const {
4593
4593
  run,
@@ -4648,7 +4648,7 @@ async function runPostRunLifecycle(inputs) {
4648
4648
  await flushSessionWrites();
4649
4649
  }
4650
4650
  var init_post_run_lifecycle = __esm({
4651
- "src/internal/runtime/post-run-lifecycle.ts"() {
4651
+ "src/internal/runtime/lifecycle/post-run-lifecycle.ts"() {
4652
4652
  init_session_summary_writer();
4653
4653
  init_memory_path_selector();
4654
4654
  init_agent_session();
@@ -4840,7 +4840,7 @@ async function readWorkspaceDir(root, errorCode, describe) {
4840
4840
  }
4841
4841
  }
4842
4842
  var init_workspace_dir = __esm({
4843
- "src/internal/runtime/workspace-dir.ts"() {
4843
+ "src/internal/runtime/config/workspace-dir.ts"() {
4844
4844
  init_errors();
4845
4845
  }
4846
4846
  });
@@ -5171,7 +5171,7 @@ var init_pipeline = __esm({
5171
5171
  }
5172
5172
  });
5173
5173
 
5174
- // src/internal/runtime/validate-agent-options.ts
5174
+ // src/internal/runtime/validation/validate-agent-options.ts
5175
5175
  function validateAgentOptions(options) {
5176
5176
  rejectProgrammaticHooks(options);
5177
5177
  ensureRuntimeShape(options);
@@ -5364,12 +5364,82 @@ function validateMemory(options) {
5364
5364
  }
5365
5365
  var TOOL_NAME_PATTERN, RESERVED_TOOL_NAMES;
5366
5366
  var init_validate_agent_options = __esm({
5367
- "src/internal/runtime/validate-agent-options.ts"() {
5367
+ "src/internal/runtime/validation/validate-agent-options.ts"() {
5368
5368
  init_errors();
5369
5369
  TOOL_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;
5370
5370
  RESERVED_TOOL_NAMES = /* @__PURE__ */ new Set(["shell", "memory_search", "memory_get"]);
5371
5371
  }
5372
5372
  });
5373
+
5374
+ // src/internal/runtime/config/providers-manager.ts
5375
+ function providerFromModel(model) {
5376
+ if (model === void 0) return void 0;
5377
+ const id = model.id;
5378
+ if (id.includes(":")) return id.split(":")[0];
5379
+ return void 0;
5380
+ }
5381
+ function resolveRoute(route, modelProvider, plugins) {
5382
+ if (route.capability === "chat" && modelProvider === route.provider) {
5383
+ const modelName = extractModelName(modelProvider, route);
5384
+ const base = {
5385
+ capability: route.capability,
5386
+ provider: route.provider,
5387
+ reason: "explicit-model-provider"
5388
+ };
5389
+ if (modelName !== void 0) base.model = modelName;
5390
+ return base;
5391
+ }
5392
+ if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
5393
+ return {
5394
+ capability: route.capability,
5395
+ provider: route.provider,
5396
+ reason: "first-available-plugin-provider"
5397
+ };
5398
+ }
5399
+ return {
5400
+ capability: route.capability,
5401
+ provider: route.provider,
5402
+ reason: "explicit-route"
5403
+ };
5404
+ }
5405
+ function extractModelName(prefix, route) {
5406
+ if (route.model !== void 0) return route.model;
5407
+ return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
5408
+ }
5409
+ function defaultModelForProvider(provider) {
5410
+ if (provider === "anthropic") return "claude-3-7-sonnet";
5411
+ return void 0;
5412
+ }
5413
+ var ProvidersManagerImpl;
5414
+ var init_providers_manager = __esm({
5415
+ "src/internal/runtime/config/providers-manager.ts"() {
5416
+ ProvidersManagerImpl = class {
5417
+ constructor(model, providers, plugins) {
5418
+ this.model = model;
5419
+ this.providers = providers;
5420
+ this.plugins = plugins;
5421
+ }
5422
+ model;
5423
+ providers;
5424
+ plugins;
5425
+ routes() {
5426
+ const resolved = [];
5427
+ const modelProvider = providerFromModel(this.model);
5428
+ const seen = /* @__PURE__ */ new Set();
5429
+ if (this.providers?.routes !== void 0) {
5430
+ for (const route of this.providers.routes) {
5431
+ const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
5432
+ if (!seen.has(route.capability)) {
5433
+ seen.add(route.capability);
5434
+ resolved.push(resolvedRoute);
5435
+ }
5436
+ }
5437
+ }
5438
+ return Promise.resolve(resolved);
5439
+ }
5440
+ };
5441
+ }
5442
+ });
5373
5443
  function truncateWithMarker(content, max) {
5374
5444
  if (content.length <= max) {
5375
5445
  return { truncated: false, finalContent: content };
@@ -6135,8 +6205,8 @@ var init_plugins_manager = __esm({
6135
6205
  init_errors();
6136
6206
  init_markdown_config_loader();
6137
6207
  init_path_guard();
6138
- init_hooks_source();
6139
6208
  init_workspace_dir();
6209
+ init_hooks_source();
6140
6210
  init_plugin_frontmatter();
6141
6211
  PluginsManager = class {
6142
6212
  constructor(cwd, enabled, settingSourcesIncludePlugins, cloud, localPaths) {
@@ -6219,76 +6289,6 @@ var init_plugins_manager = __esm({
6219
6289
  }
6220
6290
  });
6221
6291
 
6222
- // src/internal/runtime/providers-manager.ts
6223
- function providerFromModel(model) {
6224
- if (model === void 0) return void 0;
6225
- const id = model.id;
6226
- if (id.includes(":")) return id.split(":")[0];
6227
- return void 0;
6228
- }
6229
- function resolveRoute(route, modelProvider, plugins) {
6230
- if (route.capability === "chat" && modelProvider === route.provider) {
6231
- const modelName = extractModelName(modelProvider, route);
6232
- const base = {
6233
- capability: route.capability,
6234
- provider: route.provider,
6235
- reason: "explicit-model-provider"
6236
- };
6237
- if (modelName !== void 0) base.model = modelName;
6238
- return base;
6239
- }
6240
- if (plugins?.enabled !== void 0 && plugins.enabled.length > 0) {
6241
- return {
6242
- capability: route.capability,
6243
- provider: route.provider,
6244
- reason: "first-available-plugin-provider"
6245
- };
6246
- }
6247
- return {
6248
- capability: route.capability,
6249
- provider: route.provider,
6250
- reason: "explicit-route"
6251
- };
6252
- }
6253
- function extractModelName(prefix, route) {
6254
- if (route.model !== void 0) return route.model;
6255
- return prefix === route.provider ? defaultModelForProvider(prefix) : void 0;
6256
- }
6257
- function defaultModelForProvider(provider) {
6258
- if (provider === "anthropic") return "claude-3-7-sonnet";
6259
- return void 0;
6260
- }
6261
- var ProvidersManagerImpl;
6262
- var init_providers_manager = __esm({
6263
- "src/internal/runtime/providers-manager.ts"() {
6264
- ProvidersManagerImpl = class {
6265
- constructor(model, providers, plugins) {
6266
- this.model = model;
6267
- this.providers = providers;
6268
- this.plugins = plugins;
6269
- }
6270
- model;
6271
- providers;
6272
- plugins;
6273
- routes() {
6274
- const resolved = [];
6275
- const modelProvider = providerFromModel(this.model);
6276
- const seen = /* @__PURE__ */ new Set();
6277
- if (this.providers?.routes !== void 0) {
6278
- for (const route of this.providers.routes) {
6279
- const resolvedRoute = resolveRoute(route, modelProvider, this.plugins);
6280
- if (!seen.has(route.capability)) {
6281
- seen.add(route.capability);
6282
- resolved.push(resolvedRoute);
6283
- }
6284
- }
6285
- }
6286
- return Promise.resolve(resolved);
6287
- }
6288
- };
6289
- }
6290
- });
6291
-
6292
6292
  // src/internal/runtime/skills/skill-frontmatter.ts
6293
6293
  function asString(v) {
6294
6294
  return typeof v === "string" ? v : void 0;
@@ -6495,9 +6495,9 @@ function bootstrapSubmanagers(args) {
6495
6495
  }
6496
6496
  var init_local_agent_bootstrap = __esm({
6497
6497
  "src/internal/runtime/local-agent/local-agent-bootstrap.ts"() {
6498
+ init_providers_manager();
6498
6499
  init_context_manager();
6499
6500
  init_plugins_manager();
6500
- init_providers_manager();
6501
6501
  init_agent_registry();
6502
6502
  init_skills_manager();
6503
6503
  }
@@ -6671,7 +6671,7 @@ var init_budget = __esm({
6671
6671
  }
6672
6672
  });
6673
6673
 
6674
- // src/internal/runtime/validate-response.ts
6674
+ // src/internal/runtime/validation/validate-response.ts
6675
6675
  function validateResponse(response) {
6676
6676
  const trimmed = response.content.trim();
6677
6677
  const toolCallsArr = Array.isArray(response.toolCalls) ? response.toolCalls : [];
@@ -6684,7 +6684,7 @@ function validateResponse(response) {
6684
6684
  return { ok: true };
6685
6685
  }
6686
6686
  var init_validate_response = __esm({
6687
- "src/internal/runtime/validate-response.ts"() {
6687
+ "src/internal/runtime/validation/validate-response.ts"() {
6688
6688
  }
6689
6689
  });
6690
6690
 
@@ -7107,7 +7107,7 @@ function checkToolWhitelist(toolName) {
7107
7107
  }
7108
7108
  var toolWhitelistStore;
7109
7109
  var init_async_local_storage = __esm({
7110
- "src/internal/runtime/async-local-storage.ts"() {
7110
+ "src/internal/runtime/concurrency/async-local-storage.ts"() {
7111
7111
  toolWhitelistStore = new async_hooks.AsyncLocalStorage();
7112
7112
  }
7113
7113
  });
@@ -7190,7 +7190,7 @@ var init_repair_middleware = __esm({
7190
7190
  }
7191
7191
  });
7192
7192
 
7193
- // src/internal/runtime/shell-tool.ts
7193
+ // src/internal/runtime/tools/shell-tool.ts
7194
7194
  async function runShell(options) {
7195
7195
  if (options.sandbox === true && isObviouslyUnsafe(options.command)) {
7196
7196
  return {
@@ -7221,7 +7221,7 @@ function isObviouslyUnsafe(command) {
7221
7221
  return false;
7222
7222
  }
7223
7223
  var init_shell_tool = __esm({
7224
- "src/internal/runtime/shell-tool.ts"() {
7224
+ "src/internal/runtime/tools/shell-tool.ts"() {
7225
7225
  init_spawn_collect();
7226
7226
  }
7227
7227
  });
@@ -8538,7 +8538,7 @@ var init_providers = __esm({
8538
8538
  }
8539
8539
  });
8540
8540
 
8541
- // src/internal/errors/mappers/shared.ts
8541
+ // src/internal/error-mappers/shared.ts
8542
8542
  function parseRetryAfter(headers) {
8543
8543
  if (headers === void 0) return void 0;
8544
8544
  const raw = headers.get("retry-after");
@@ -8567,13 +8567,13 @@ function buildErrorMetadata(args) {
8567
8567
  }
8568
8568
  var RAW_MAX_BYTES;
8569
8569
  var init_shared = __esm({
8570
- "src/internal/errors/mappers/shared.ts"() {
8570
+ "src/internal/error-mappers/shared.ts"() {
8571
8571
  init_security();
8572
8572
  RAW_MAX_BYTES = 2048;
8573
8573
  }
8574
8574
  });
8575
8575
 
8576
- // src/internal/errors/mappers/anthropic.ts
8576
+ // src/internal/error-mappers/anthropic.ts
8577
8577
  function mapAnthropicError(args) {
8578
8578
  const { status, body, headers, endpoint } = args;
8579
8579
  const code = mapAnthropicStatusToCode(status, body);
@@ -8627,7 +8627,7 @@ function formatMessage(status, code) {
8627
8627
  return `Anthropic API error: ${code} (HTTP ${status})`;
8628
8628
  }
8629
8629
  var init_anthropic2 = __esm({
8630
- "src/internal/errors/mappers/anthropic.ts"() {
8630
+ "src/internal/error-mappers/anthropic.ts"() {
8631
8631
  init_errors();
8632
8632
  init_shared();
8633
8633
  }
@@ -8934,7 +8934,7 @@ var init_anthropic3 = __esm({
8934
8934
  }
8935
8935
  });
8936
8936
 
8937
- // src/internal/errors/mappers/bedrock.ts
8937
+ // src/internal/error-mappers/bedrock.ts
8938
8938
  function classifyBedrockError(args, awsType, message) {
8939
8939
  if (args.status === 429 || awsType.includes("Throttling") || awsType.includes("TooManyRequests")) {
8940
8940
  return "rate_limit";
@@ -8994,7 +8994,7 @@ function parseBody(body) {
8994
8994
  return {};
8995
8995
  }
8996
8996
  var init_bedrock2 = __esm({
8997
- "src/internal/errors/mappers/bedrock.ts"() {
8997
+ "src/internal/error-mappers/bedrock.ts"() {
8998
8998
  init_errors();
8999
8999
  init_shared();
9000
9000
  }
@@ -9381,7 +9381,7 @@ var init_credential_pool_context = __esm({
9381
9381
  }
9382
9382
  });
9383
9383
 
9384
- // src/internal/errors/mappers/openai-compatible.ts
9384
+ // src/internal/error-mappers/openai-compatible.ts
9385
9385
  function mapOpenAICompatibleError(args) {
9386
9386
  const { providerId, status, body, headers, endpoint } = args;
9387
9387
  const code = mapOpenAiStatusToCode(status, body);
@@ -9444,7 +9444,7 @@ function formatMessage2(providerId, status, code) {
9444
9444
  return `${providerId} API error: ${code} (HTTP ${status})`;
9445
9445
  }
9446
9446
  var init_openai_compatible = __esm({
9447
- "src/internal/errors/mappers/openai-compatible.ts"() {
9447
+ "src/internal/error-mappers/openai-compatible.ts"() {
9448
9448
  init_errors();
9449
9449
  init_shared();
9450
9450
  }
@@ -9556,7 +9556,7 @@ var init_fault_injection = __esm({
9556
9556
  }
9557
9557
  });
9558
9558
 
9559
- // src/internal/errors/mappers/ollama.ts
9559
+ // src/internal/error-mappers/ollama.ts
9560
9560
  function mapOllamaTransportError(args) {
9561
9561
  if (args.providerId !== "ollama") return void 0;
9562
9562
  const causeCode = extractCauseCode(args.cause);
@@ -9629,7 +9629,7 @@ function extractModelName2(errString) {
9629
9629
  return match?.[1];
9630
9630
  }
9631
9631
  var init_ollama2 = __esm({
9632
- "src/internal/errors/mappers/ollama.ts"() {
9632
+ "src/internal/error-mappers/ollama.ts"() {
9633
9633
  init_errors();
9634
9634
  init_shared();
9635
9635
  }
@@ -10230,7 +10230,7 @@ var init_pool_aware_client = __esm({
10230
10230
  }
10231
10231
  });
10232
10232
 
10233
- // src/internal/errors/mappers/vertex.ts
10233
+ // src/internal/error-mappers/vertex.ts
10234
10234
  function classifyVertexError(args, errStatus) {
10235
10235
  for (const rule of VERTEX_RULES) {
10236
10236
  if (rule.test(args.status, errStatus)) return rule.code;
@@ -10267,7 +10267,7 @@ function parseBody2(body) {
10267
10267
  }
10268
10268
  var VERTEX_RULES, VERTEX_ERROR_BUILDERS;
10269
10269
  var init_vertex2 = __esm({
10270
- "src/internal/errors/mappers/vertex.ts"() {
10270
+ "src/internal/error-mappers/vertex.ts"() {
10271
10271
  init_errors();
10272
10272
  init_shared();
10273
10273
  VERTEX_RULES = [
@@ -13836,7 +13836,7 @@ var init_local_agent_plugins = __esm({
13836
13836
  }
13837
13837
  });
13838
13838
 
13839
- // src/internal/runtime/run-until.ts
13839
+ // src/internal/runtime/lifecycle/run-until.ts
13840
13840
  var run_until_exports = {};
13841
13841
  __export(run_until_exports, {
13842
13842
  composeContinuation: () => composeContinuation,
@@ -13929,7 +13929,7 @@ Your last response was:
13929
13929
  ${lastResponse.slice(0, 1e3)}`;
13930
13930
  }
13931
13931
  var init_run_until = __esm({
13932
- "src/internal/runtime/run-until.ts"() {
13932
+ "src/internal/runtime/lifecycle/run-until.ts"() {
13933
13933
  }
13934
13934
  });
13935
13935
 
@@ -14040,16 +14040,16 @@ var init_judge_call = __esm({
14040
14040
  // src/internal/runtime/registry/agent-factory-registry.ts
14041
14041
  var agent_factory_registry_exports = {};
14042
14042
  __export(agent_factory_registry_exports, {
14043
- getAgentCreate: () => getAgentCreate,
14044
- setAgentCreate: () => setAgentCreate
14043
+ getAgentFacade: () => getAgentFacade,
14044
+ setAgentFacade: () => setAgentFacade
14045
14045
  });
14046
- function setAgentCreate(fn) {
14047
- registered3 = fn;
14046
+ function setAgentFacade(facade) {
14047
+ registered3 = facade;
14048
14048
  }
14049
- function getAgentCreate() {
14049
+ function getAgentFacade() {
14050
14050
  if (registered3 === void 0) {
14051
14051
  throw new Error(
14052
- "internal: Agent.create not registered. The `agent.ts` module must be loaded before LocalAgent.runUntil/fork are invoked."
14052
+ "internal: Agent facade not registered. The `agent.ts` module must be loaded before internal subsystems (LocalAgent.runUntil/fork, eval, scorers, cron) invoke it."
14053
14053
  );
14054
14054
  }
14055
14055
  return registered3;
@@ -14060,7 +14060,7 @@ var init_agent_factory_registry = __esm({
14060
14060
  }
14061
14061
  });
14062
14062
 
14063
- // src/internal/runtime/fork-agent.ts
14063
+ // src/internal/runtime/lifecycle/fork-agent.ts
14064
14064
  var fork_agent_exports = {};
14065
14065
  __export(fork_agent_exports, {
14066
14066
  filterMemoryPlugins: () => filterMemoryPlugins,
@@ -14120,7 +14120,7 @@ function extractUsage(result) {
14120
14120
  };
14121
14121
  }
14122
14122
  var init_fork_agent = __esm({
14123
- "src/internal/runtime/fork-agent.ts"() {
14123
+ "src/internal/runtime/lifecycle/fork-agent.ts"() {
14124
14124
  init_async_local_storage();
14125
14125
  init_local_agent_plugins();
14126
14126
  }
@@ -14131,8 +14131,8 @@ function localAgentRunUntil(agent, goal, options) {
14131
14131
  async function* wrap() {
14132
14132
  const { runUntilImpl: runUntilImpl2 } = await Promise.resolve().then(() => (init_run_until(), run_until_exports));
14133
14133
  const { judgeCallImpl: judgeCallImpl2 } = await Promise.resolve().then(() => (init_judge_call(), judge_call_exports));
14134
- const { getAgentCreate: getAgentCreate2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14135
- const create = getAgentCreate2();
14134
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14135
+ const create = getAgentFacade2().create;
14136
14136
  const deps = {
14137
14137
  judge: async (ctx, opts) => judgeCallImpl2(ctx, opts, { create })
14138
14138
  };
@@ -14142,9 +14142,9 @@ function localAgentRunUntil(agent, goal, options) {
14142
14142
  }
14143
14143
  async function localAgentFork(parent, options) {
14144
14144
  const { forkAgentImpl: forkAgentImpl2 } = await Promise.resolve().then(() => (init_fork_agent(), fork_agent_exports));
14145
- const { getAgentCreate: getAgentCreate2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14145
+ const { getAgentFacade: getAgentFacade2 } = await Promise.resolve().then(() => (init_agent_factory_registry(), agent_factory_registry_exports));
14146
14146
  const { withPersonalityContext: withPersonalityContext2 } = await Promise.resolve().then(() => (init_context2(), context_exports));
14147
- const create = getAgentCreate2();
14147
+ const create = getAgentFacade2().create;
14148
14148
  return withPersonalityContext2(
14149
14149
  { slug: parent.personalitySlugSnapshot, isFork: true },
14150
14150
  () => forkAgentImpl2(parent, options, { create })
@@ -14168,7 +14168,7 @@ var init_local_agent_runtime_extensions = __esm({
14168
14168
  }
14169
14169
  });
14170
14170
 
14171
- // src/internal/runtime/abort-utils.ts
14171
+ // src/internal/runtime/concurrency/abort-utils.ts
14172
14172
  function anySignal(signals) {
14173
14173
  const filtered = signals.filter((s) => s !== void 0);
14174
14174
  if (filtered.length === 0) {
@@ -14194,7 +14194,7 @@ function ponyfillAny(signals) {
14194
14194
  return ctrl.signal;
14195
14195
  }
14196
14196
  var init_abort_utils = __esm({
14197
- "src/internal/runtime/abort-utils.ts"() {
14197
+ "src/internal/runtime/concurrency/abort-utils.ts"() {
14198
14198
  }
14199
14199
  });
14200
14200
 
@@ -14347,7 +14347,7 @@ var init_task = __esm({
14347
14347
  }
14348
14348
  });
14349
14349
 
14350
- // src/internal/runtime/async-semaphore.ts
14350
+ // src/internal/runtime/concurrency/async-semaphore.ts
14351
14351
  function createSemaphore(permits) {
14352
14352
  if (!Number.isInteger(permits) || permits < 1) {
14353
14353
  throw new ConfigurationError(
@@ -14385,7 +14385,7 @@ function createSemaphore(permits) {
14385
14385
  };
14386
14386
  }
14387
14387
  var init_async_semaphore = __esm({
14388
- "src/internal/runtime/async-semaphore.ts"() {
14388
+ "src/internal/runtime/concurrency/async-semaphore.ts"() {
14389
14389
  init_errors();
14390
14390
  }
14391
14391
  });
@@ -14952,8 +14952,8 @@ var init_local_agent = __esm({
14952
14952
  init_span_names();
14953
14953
  init_tracer();
14954
14954
  init_hooks_executor();
14955
- init_memory_path_selector();
14956
14955
  init_post_run_lifecycle();
14956
+ init_memory_path_selector();
14957
14957
  init_agent_registry();
14958
14958
  init_live_agent_registry();
14959
14959
  init_agent_session();
@@ -16422,7 +16422,13 @@ var init_agent = __esm({
16422
16422
  await flushRegistrySaves();
16423
16423
  }
16424
16424
  };
16425
- setAgentCreate((options) => Agent.create(options));
16425
+ setAgentFacade({
16426
+ create: (options) => Agent.create(options),
16427
+ prompt: (message, options) => Agent.prompt(message, options),
16428
+ get: (agentId) => Agent.get(agentId),
16429
+ resume: (agentId, options) => Agent.resume(agentId, options),
16430
+ batch: (prompts, options) => Agent.batch(prompts, options)
16431
+ });
16426
16432
  }
16427
16433
  });
16428
16434