@theokit/sdk 1.5.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.
- package/CHANGELOG.md +1571 -0
- package/LICENSE +201 -0
- package/README.md +80 -0
- package/bin/theokit-migrate-config.mjs +269 -0
- package/bin/theokit-migrate-memory.mjs +116 -0
- package/dist/agent-builder.d.ts +52 -0
- package/dist/agent-factory.d.ts +39 -0
- package/dist/agent.d.ts +175 -0
- package/dist/batch.d.ts +11 -0
- package/dist/budget.d.ts +48 -0
- package/dist/cache.d.ts +74 -0
- package/dist/cron-1yxL3K2S.d.cts +221 -0
- package/dist/cron-BYVdYzob.d.ts +221 -0
- package/dist/cron.cjs +14655 -0
- package/dist/cron.cjs.map +1 -0
- package/dist/cron.d.cts +3 -0
- package/dist/cron.d.ts +71 -0
- package/dist/cron.js +14652 -0
- package/dist/cron.js.map +1 -0
- package/dist/define-tool.d.ts +35 -0
- package/dist/errors-CK8brCJ1.d.cts +448 -0
- package/dist/errors-CvAeEWgE.d.ts +448 -0
- package/dist/errors.cjs +255 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +3 -0
- package/dist/errors.d.ts +356 -0
- package/dist/errors.js +238 -0
- package/dist/errors.js.map +1 -0
- package/dist/eval.cjs +14826 -0
- package/dist/eval.cjs.map +1 -0
- package/dist/eval.d.cts +35 -0
- package/dist/eval.d.ts +35 -0
- package/dist/eval.js +14821 -0
- package/dist/eval.js.map +1 -0
- package/dist/generate-object.d.ts +67 -0
- package/dist/handoff.d.ts +55 -0
- package/dist/index.cjs +17127 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1878 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +17095 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/agent-loop/loop-types.d.ts +29 -0
- package/dist/internal/agent-loop/loop.d.ts +2 -0
- package/dist/internal/agent-loop/message-builders.d.ts +6 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +4 -0
- package/dist/internal/agent-loop/usage-and-cost.d.ts +25 -0
- package/dist/internal/budget/calendar-window.d.ts +19 -0
- package/dist/internal/budget/compute-cost.d.ts +28 -0
- package/dist/internal/budget/enforcement.d.ts +32 -0
- package/dist/internal/budget/ledger.d.ts +25 -0
- package/dist/internal/budget/normalize-usage.d.ts +27 -0
- package/dist/internal/budget/pricing-registry.d.ts +36 -0
- package/dist/internal/budget/registry.d.ts +16 -0
- package/dist/internal/budget/usage-accumulator.d.ts +31 -0
- package/dist/internal/cache/cosine.d.ts +14 -0
- package/dist/internal/cache/embed-helper.d.ts +15 -0
- package/dist/internal/cache/key.d.ts +15 -0
- package/dist/internal/cache/lookup.d.ts +28 -0
- package/dist/internal/cache/store-handler.d.ts +24 -0
- package/dist/internal/cache/store-json.d.ts +48 -0
- package/dist/internal/cache/store.d.ts +54 -0
- package/dist/internal/cache/telemetry.d.ts +20 -0
- package/dist/internal/cache/ttl.d.ts +11 -0
- package/dist/internal/catalog/fixtures.d.ts +16 -0
- package/dist/internal/catalog/local-models.d.ts +24 -0
- package/dist/internal/cron/run-job.d.ts +1 -0
- package/dist/internal/cron/scheduler.d.ts +1 -0
- package/dist/internal/cron/store.d.ts +1 -0
- package/dist/internal/cron/validate.d.ts +1 -0
- package/dist/internal/env.d.ts +1 -0
- package/dist/internal/errors/mappers/anthropic.d.ts +30 -0
- package/dist/internal/errors/mappers/bedrock.d.ts +16 -0
- package/dist/internal/errors/mappers/ollama.d.ts +41 -0
- package/dist/internal/errors/mappers/openai-compatible.d.ts +25 -0
- package/dist/internal/errors/mappers/shared.d.ts +10 -0
- package/dist/internal/errors/mappers/vertex.d.ts +15 -0
- package/dist/internal/eval/aggregate.d.ts +9 -0
- package/dist/internal/eval/dataset-iter.d.ts +9 -0
- package/dist/internal/eval/runner.d.ts +9 -0
- package/dist/internal/eval/single-flight.d.ts +16 -0
- package/dist/internal/eval/telemetry.d.ts +23 -0
- package/dist/internal/fixture-mode.d.ts +16 -0
- package/dist/internal/handoff/dispatcher.d.ts +29 -0
- package/dist/internal/handoff/registry.d.ts +23 -0
- package/dist/internal/handoff/telemetry.d.ts +18 -0
- package/dist/internal/handoff/tool-injector.d.ts +34 -0
- package/dist/internal/http.d.ts +1 -0
- package/dist/internal/ids.d.ts +1 -0
- package/dist/internal/judge/judge-call.d.ts +35 -0
- package/dist/internal/judge/parse-verdict.d.ts +11 -0
- package/dist/internal/judge/types.d.ts +17 -0
- package/dist/internal/llm/anthropic-shared.d.ts +89 -0
- package/dist/internal/llm/anthropic.d.ts +9 -0
- package/dist/internal/llm/bedrock-anthropic.d.ts +36 -0
- package/dist/internal/llm/bedrock-token-cache.d.ts +18 -0
- package/dist/internal/llm/credential-pool-context.d.ts +11 -0
- package/dist/internal/llm/credential-pool-types.d.ts +22 -0
- package/dist/internal/llm/credential-pool.d.ts +18 -0
- package/dist/internal/llm/fallback-client.d.ts +1 -0
- package/dist/internal/llm/fault-injection.d.ts +50 -0
- package/dist/internal/llm/finish.d.ts +1 -0
- package/dist/internal/llm/model-identifier.d.ts +24 -0
- package/dist/internal/llm/ollama-native.d.ts +27 -0
- package/dist/internal/llm/openai.d.ts +9 -0
- package/dist/internal/llm/pool-aware-client.d.ts +16 -0
- package/dist/internal/llm/router.d.ts +17 -0
- package/dist/internal/llm/sse.d.ts +9 -0
- package/dist/internal/llm/stream-relay.d.ts +17 -0
- package/dist/internal/llm/types.d.ts +70 -0
- package/dist/internal/llm/vertex-anthropic.d.ts +40 -0
- package/dist/internal/llm/vertex-auth.d.ts +30 -0
- package/dist/internal/llm/vertex-gemini.d.ts +28 -0
- package/dist/internal/llm/vertex-router.d.ts +21 -0
- package/dist/internal/mcp/client.d.ts +16 -0
- package/dist/internal/memory/active-memory-cache.d.ts +10 -0
- package/dist/internal/memory/active-memory.d.ts +45 -0
- package/dist/internal/memory/adapters/catalog.d.ts +1 -0
- package/dist/internal/memory/adapters/deepinfra-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/mistral-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/ollama-embedding.d.ts +34 -0
- package/dist/internal/memory/adapters/openai-compatible.d.ts +23 -0
- package/dist/internal/memory/adapters/openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/openrouter-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/voyage-embedding.d.ts +2 -0
- package/dist/internal/memory/atomic-write.d.ts +7 -0
- package/dist/internal/memory/chunk-markdown.d.ts +2 -0
- package/dist/internal/memory/circuit-breaker.d.ts +22 -0
- package/dist/internal/memory/cwd-mutex.d.ts +1 -0
- package/dist/internal/memory/dreaming/diary.d.ts +4 -0
- package/dist/internal/memory/dreaming/phases.d.ts +15 -0
- package/dist/internal/memory/dreaming/run.d.ts +10 -0
- package/dist/internal/memory/embedding-adapter.d.ts +42 -0
- package/dist/internal/memory/embedding-cache.d.ts +1 -0
- package/dist/internal/memory/index-db.d.ts +10 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +23 -0
- package/dist/internal/memory/index-manager.d.ts +68 -0
- package/dist/internal/memory/index-schema.d.ts +21 -0
- package/dist/internal/memory/lance-index.d.ts +32 -0
- package/dist/internal/memory/lance-memory-adapter.d.ts +43 -0
- package/dist/internal/memory/markdown-store.d.ts +16 -0
- package/dist/internal/memory/memory-index.d.ts +52 -0
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +15 -0
- package/dist/internal/memory/migration.d.ts +9 -0
- package/dist/internal/memory/reader.d.ts +8 -0
- package/dist/internal/memory/session-loader.d.ts +1 -0
- package/dist/internal/memory/session-summary-writer.d.ts +2 -0
- package/dist/internal/memory/sqlite-vec-loader.d.ts +3 -0
- package/dist/internal/memory/tools.d.ts +14 -0
- package/dist/internal/memory/transcript-store.d.ts +1 -0
- package/dist/internal/memory/types.d.ts +17 -0
- package/dist/internal/memory/vec-index.d.ts +28 -0
- package/dist/internal/memory/wiki-loader.d.ts +2 -0
- package/dist/internal/observability/tracer-loader.d.ts +20 -0
- package/dist/internal/persistence/atomic-write.d.ts +1 -0
- package/dist/internal/persistence/conversation-storage-fs.d.ts +37 -0
- package/dist/internal/persistence/conversation-storage-memory.d.ts +24 -0
- package/dist/internal/persistence/cwd-mutex.d.ts +1 -0
- package/dist/internal/persistence/file-lock.d.ts +14 -0
- package/dist/internal/persistence/fts5-sanitize.d.ts +16 -0
- package/dist/internal/persistence/markdown-config-loader.d.ts +35 -0
- package/dist/internal/persistence/paths.d.ts +19 -0
- package/dist/internal/persistence/persistence-schema.d.ts +17 -0
- package/dist/internal/persistence/schema-version.d.ts +13 -0
- package/dist/internal/persistence/sqlite-wal.d.ts +10 -0
- package/dist/internal/personality/context.d.ts +17 -0
- package/dist/internal/personality/registry.d.ts +17 -0
- package/dist/internal/personality/store.d.ts +27 -0
- package/dist/internal/personality/switch.d.ts +36 -0
- package/dist/internal/personality/types.d.ts +18 -0
- package/dist/internal/plugins/context.d.ts +31 -0
- package/dist/internal/plugins/manager.d.ts +37 -0
- package/dist/internal/plugins/types.d.ts +102 -0
- package/dist/internal/providers/builtin/anthropic.d.ts +2 -0
- package/dist/internal/providers/builtin/bedrock.d.ts +25 -0
- package/dist/internal/providers/builtin/gemini.d.ts +10 -0
- package/dist/internal/providers/builtin/index.d.ts +19 -0
- package/dist/internal/providers/builtin/llamacpp.d.ts +1 -0
- package/dist/internal/providers/builtin/lmstudio.d.ts +1 -0
- package/dist/internal/providers/builtin/ollama.d.ts +17 -0
- package/dist/internal/providers/builtin/openai.d.ts +2 -0
- package/dist/internal/providers/builtin/openrouter.d.ts +2 -0
- package/dist/internal/providers/builtin/vertex.d.ts +27 -0
- package/dist/internal/providers/discovery.d.ts +14 -0
- package/dist/internal/providers/index.d.ts +8 -0
- package/dist/internal/providers/registry.d.ts +12 -0
- package/dist/internal/providers/types.d.ts +27 -0
- package/dist/internal/runtime/abort-utils.d.ts +21 -0
- package/dist/internal/runtime/agent-factory-registry.d.ts +16 -0
- package/dist/internal/runtime/agent-registry-store.d.ts +61 -0
- package/dist/internal/runtime/agent-registry.d.ts +34 -0
- package/dist/internal/runtime/agent-session-store.d.ts +3 -0
- package/dist/internal/runtime/agent-session.d.ts +2 -0
- package/dist/internal/runtime/async-local-storage.d.ts +20 -0
- package/dist/internal/runtime/async-semaphore.d.ts +24 -0
- package/dist/internal/runtime/budget.d.ts +36 -0
- package/dist/internal/runtime/cloud-agent.d.ts +1 -0
- package/dist/internal/runtime/cloud-config-serializer.d.ts +3 -0
- package/dist/internal/runtime/cloud-payload-types.d.ts +56 -0
- package/dist/internal/runtime/cloud-run.d.ts +1 -0
- package/dist/internal/runtime/cloud-tool-parity.d.ts +1 -0
- package/dist/internal/runtime/context-aggregator.d.ts +26 -0
- package/dist/internal/runtime/context-discovery-runner.d.ts +27 -0
- package/dist/internal/runtime/context-discovery.d.ts +21 -0
- package/dist/internal/runtime/context-frontmatter.d.ts +16 -0
- package/dist/internal/runtime/context-import-resolver.d.ts +24 -0
- package/dist/internal/runtime/context-loaders.d.ts +42 -0
- package/dist/internal/runtime/context-manager.d.ts +11 -0
- package/dist/internal/runtime/context-mdc-parser.d.ts +24 -0
- package/dist/internal/runtime/default-model.d.ts +1 -0
- package/dist/internal/runtime/fixture-events.d.ts +12 -0
- package/dist/internal/runtime/fixture-responder.d.ts +1 -0
- package/dist/internal/runtime/fixture-run-base.d.ts +45 -0
- package/dist/internal/runtime/fixture-scripts.d.ts +21 -0
- package/dist/internal/runtime/fixture-types.d.ts +1 -0
- package/dist/internal/runtime/fork-agent.d.ts +15 -0
- package/dist/internal/runtime/hooks-executor.d.ts +35 -0
- package/dist/internal/runtime/hooks-frontmatter.d.ts +26 -0
- package/dist/internal/runtime/hooks-source.d.ts +22 -0
- package/dist/internal/runtime/live-agent-registry.d.ts +87 -0
- package/dist/internal/runtime/local-agent-bootstrap.d.ts +37 -0
- package/dist/internal/runtime/local-agent-dispatch.d.ts +57 -0
- package/dist/internal/runtime/local-agent-invalidate.d.ts +8 -0
- package/dist/internal/runtime/local-agent-memory-direct.d.ts +12 -0
- package/dist/internal/runtime/local-agent-memory-hooks.d.ts +41 -0
- package/dist/internal/runtime/local-agent-memory.d.ts +1 -0
- package/dist/internal/runtime/local-agent-personality-extensions.d.ts +19 -0
- package/dist/internal/runtime/local-agent-plugins.d.ts +13 -0
- package/dist/internal/runtime/local-agent-runtime-extensions.d.ts +13 -0
- package/dist/internal/runtime/local-agent-task-wrap.d.ts +11 -0
- package/dist/internal/runtime/local-agent.d.ts +1 -0
- package/dist/internal/runtime/local-run.d.ts +1 -0
- package/dist/internal/runtime/memory-store.d.ts +4 -0
- package/dist/internal/runtime/plugin-frontmatter.d.ts +17 -0
- package/dist/internal/runtime/plugins-manager.d.ts +1 -0
- package/dist/internal/runtime/post-run-lifecycle.d.ts +1 -0
- package/dist/internal/runtime/providers-manager.d.ts +1 -0
- package/dist/internal/runtime/real-cloud-run.d.ts +2 -0
- package/dist/internal/runtime/real-local-run.d.ts +2 -0
- package/dist/internal/runtime/run-registry.d.ts +5 -0
- package/dist/internal/runtime/run-until.d.ts +22 -0
- package/dist/internal/runtime/shell-tool.d.ts +7 -0
- package/dist/internal/runtime/skill-frontmatter.d.ts +1 -0
- package/dist/internal/runtime/skills-manager.d.ts +1 -0
- package/dist/internal/runtime/spawn-collect.d.ts +8 -0
- package/dist/internal/runtime/subagents-loader.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/escape.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/local-assembly.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/pipeline.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/active-memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/base-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/context-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/safe-call.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/types.d.ts +5 -0
- package/dist/internal/runtime/system-prompt.d.ts +1 -0
- package/dist/internal/runtime/validate-agent-options.d.ts +1 -0
- package/dist/internal/runtime/workspace-dir.d.ts +9 -0
- package/dist/internal/runtime/yaml-frontmatter.d.ts +20 -0
- package/dist/internal/scorers/llm-judge.d.ts +24 -0
- package/dist/internal/security/index.d.ts +11 -0
- package/dist/internal/security/path-guard.d.ts +56 -0
- package/dist/internal/security/redact.d.ts +21 -0
- package/dist/internal/structured-output-helpers.d.ts +54 -0
- package/dist/internal/task/registry.d.ts +61 -0
- package/dist/internal/task/ring-buffer.d.ts +10 -0
- package/dist/internal/task/store.d.ts +59 -0
- package/dist/internal/task/subscribe.d.ts +15 -0
- package/dist/internal/task/telemetry.d.ts +27 -0
- package/dist/internal/telemetry/adapter-registry.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langfuse.d.ts +2 -0
- package/dist/internal/telemetry/adapters/posthog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/sentry.d.ts +2 -0
- package/dist/internal/telemetry/safe-require.d.ts +1 -0
- package/dist/internal/telemetry/tracer.d.ts +18 -0
- package/dist/internal/tool-dispatch/repair-middleware.d.ts +34 -0
- package/dist/internal/tool-dispatch/strip-think.d.ts +22 -0
- package/dist/internal/tool-registry/personality-filter.d.ts +37 -0
- package/dist/internal/workflow/ctx.d.ts +19 -0
- package/dist/internal/workflow/error-shape.d.ts +7 -0
- package/dist/internal/workflow/executor.d.ts +15 -0
- package/dist/internal/workflow/index.d.ts +12 -0
- package/dist/internal/workflow/retry-policy.d.ts +14 -0
- package/dist/internal/workflow/run-id.d.ts +9 -0
- package/dist/internal/workflow/single-flight.d.ts +18 -0
- package/dist/internal/workflow/snapshot-store.d.ts +23 -0
- package/dist/internal/workflow/step-agent.d.ts +12 -0
- package/dist/internal/workflow/step-branch.d.ts +10 -0
- package/dist/internal/workflow/step-dowhile.d.ts +8 -0
- package/dist/internal/workflow/step-fn.d.ts +10 -0
- package/dist/internal/workflow/step-foreach.d.ts +11 -0
- package/dist/internal/workflow/step-parallel.d.ts +17 -0
- package/dist/internal/workflow/step-sleep.d.ts +7 -0
- package/dist/internal/workflow/telemetry.d.ts +23 -0
- package/dist/internal/zod/to-json-schema.d.ts +21 -0
- package/dist/memory-adapter-helpers.d.ts +28 -0
- package/dist/memory.d.ts +123 -0
- package/dist/migrate.d.ts +33 -0
- package/dist/path-safety.cjs +126 -0
- package/dist/path-safety.cjs.map +1 -0
- package/dist/path-safety.d.cts +15 -0
- package/dist/path-safety.d.ts +15 -0
- package/dist/path-safety.js +120 -0
- package/dist/path-safety.js.map +1 -0
- package/dist/run-DkCD5DeO.d.cts +2181 -0
- package/dist/run-DkCD5DeO.d.ts +2181 -0
- package/dist/scorers.d.ts +75 -0
- package/dist/security.d.ts +67 -0
- package/dist/stream-object.d.ts +74 -0
- package/dist/task-store.cjs +237 -0
- package/dist/task-store.cjs.map +1 -0
- package/dist/task-store.d.cts +8 -0
- package/dist/task-store.d.ts +8 -0
- package/dist/task-store.js +233 -0
- package/dist/task-store.js.map +1 -0
- package/dist/task.d.ts +87 -0
- package/dist/theokit.d.ts +84 -0
- package/dist/tools/_path-scope.d.cts +8 -0
- package/dist/tools/_path-scope.d.ts +8 -0
- package/dist/tools/_subprocess.d.cts +28 -0
- package/dist/tools/_subprocess.d.ts +28 -0
- package/dist/tools/git-diff.d.cts +22 -0
- package/dist/tools/git-diff.d.ts +22 -0
- package/dist/tools/index.d.cts +29 -0
- package/dist/tools/index.d.ts +29 -0
- package/dist/tools/list-dir.d.cts +26 -0
- package/dist/tools/list-dir.d.ts +26 -0
- package/dist/tools/read-file.d.cts +31 -0
- package/dist/tools/read-file.d.ts +31 -0
- package/dist/tools/run-vitest.d.cts +46 -0
- package/dist/tools/run-vitest.d.ts +46 -0
- package/dist/tools/search-text.d.cts +32 -0
- package/dist/tools/search-text.d.ts +32 -0
- package/dist/tools.cjs +690 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.js +683 -0
- package/dist/tools.js.map +1 -0
- package/dist/trajectory-helpers.d.ts +31 -0
- package/dist/types/agent.d.ts +771 -0
- package/dist/types/batch.d.ts +112 -0
- package/dist/types/budget.d.ts +88 -0
- package/dist/types/cache.d.ts +76 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/conversation-storage.d.ts +76 -0
- package/dist/types/conversation.d.ts +90 -0
- package/dist/types/cron.d.ts +150 -0
- package/dist/types/eval.d.ts +132 -0
- package/dist/types/goal-events.d.ts +95 -0
- package/dist/types/handoff.d.ts +135 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/mcp.d.ts +64 -0
- package/dist/types/memory-adapter.d.ts +175 -0
- package/dist/types/messages.d.ts +154 -0
- package/dist/types/providers.d.ts +102 -0
- package/dist/types/run.d.ts +215 -0
- package/dist/types/task.d.ts +131 -0
- package/dist/types/theokit.d.ts +61 -0
- package/dist/types/trajectory.d.ts +49 -0
- package/dist/types/updates.d.ts +148 -0
- package/dist/types/usage.d.ts +61 -0
- package/dist/types/workflow.d.ts +217 -0
- package/dist/workflow.cjs +2405 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.d.cts +97 -0
- package/dist/workflow.d.ts +97 -0
- package/dist/workflow.js +2398 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +183 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama-specific HTTP/transport error mapper (T1.1, ADR D185).
|
|
3
|
+
*
|
|
4
|
+
* Sits ABOVE the generic OpenAI-compatible mapper for `providerId: "ollama"`.
|
|
5
|
+
* Returns `undefined` when the error doesn't match an Ollama-specific
|
|
6
|
+
* pattern — caller (OpenAIClient) then falls back to the generic mapper.
|
|
7
|
+
*
|
|
8
|
+
* Surfaces 3 Ollama-specific failure modes with actionable messages
|
|
9
|
+
* targeted at non-technical users (CLAUDE.md primary persona):
|
|
10
|
+
*
|
|
11
|
+
* 1. **Transport-level `ECONNREFUSED` / `ENOTFOUND`** → "Run `ollama serve`"
|
|
12
|
+
* 2. **HTTP 404 with `not found, try pulling`** → "Run `ollama pull <model>`"
|
|
13
|
+
* 3. **HTTP 503 with `model is loading`** → retryable (model warming up)
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
interface MapOllamaTransportArgs {
|
|
18
|
+
providerId: string;
|
|
19
|
+
cause: unknown;
|
|
20
|
+
endpoint: string;
|
|
21
|
+
}
|
|
22
|
+
interface MapOllamaHttpArgs {
|
|
23
|
+
providerId: string;
|
|
24
|
+
status: number;
|
|
25
|
+
body: unknown;
|
|
26
|
+
headers: Headers | undefined;
|
|
27
|
+
endpoint: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Maps fetch-level failures (Node TypeError with `cause.code`). Returns
|
|
31
|
+
* `undefined` for anything that isn't `ECONNREFUSED` / `ENOTFOUND` so
|
|
32
|
+
* the caller can re-throw the original error untouched.
|
|
33
|
+
*/
|
|
34
|
+
export declare function mapOllamaTransportError(args: MapOllamaTransportArgs): TheokitAgentError | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Maps HTTP-level Ollama failures. Returns `undefined` for status codes
|
|
37
|
+
* that aren't Ollama-specific so the caller falls back to the generic
|
|
38
|
+
* OpenAI-compatible mapper.
|
|
39
|
+
*/
|
|
40
|
+
export declare function mapOllamaHttpError(args: MapOllamaHttpArgs): TheokitAgentError | undefined;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible HTTP error mapper (ADR D67).
|
|
3
|
+
*
|
|
4
|
+
* Translates OpenAI-shaped API error responses (covers OpenAI, OpenRouter,
|
|
5
|
+
* DeepSeek, Together, Mistral, Voyage, DeepInfra, etc.) into typed
|
|
6
|
+
* `TheokitAgentError` subclasses with full `ErrorMetadata`.
|
|
7
|
+
*
|
|
8
|
+
* Body inspection: looks at `body.error.code` / `body.error.type` to detect
|
|
9
|
+
* `context_too_long`, `content_filtered`, `model_unavailable` semantics.
|
|
10
|
+
* Falls back to status-based mapping when body doesn't expose `.error`
|
|
11
|
+
* (e.g., HTML server error page, DeepInfra's `{message: "..."}` shape).
|
|
12
|
+
*
|
|
13
|
+
* Never throws — caller is already in an error path.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
interface MapOpenAiErrorArgs {
|
|
18
|
+
providerId: string;
|
|
19
|
+
status: number;
|
|
20
|
+
body: unknown;
|
|
21
|
+
headers: Headers | undefined;
|
|
22
|
+
endpoint: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function mapOpenAICompatibleError(args: MapOpenAiErrorArgs): TheokitAgentError;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers shared between provider HTTP error mappers (ADR D67).
|
|
3
|
+
*
|
|
4
|
+
* Extracted to dedupe identical logic in `anthropic.ts` and
|
|
5
|
+
* `openai-compatible.ts` — retry-after parsing, raw-body truncation,
|
|
6
|
+
* and metadata assembly are dialect-agnostic.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCP Vertex AI HTTP error mapper (ADRs D67, D300).
|
|
3
|
+
*
|
|
4
|
+
* Vertex returns `{ error: { code, status, message, details } }` (Google
|
|
5
|
+
* AIP-193 standard error shape).
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface MapVertexErrorArgs {
|
|
10
|
+
status: number;
|
|
11
|
+
body: unknown;
|
|
12
|
+
headers: Headers | undefined;
|
|
13
|
+
endpoint: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function mapVertexError(args: MapVertexErrorArgs): TheokitAgentError;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D211 — compute `EvalAggregate` from a list of `EvalRowResult`.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions; no IO. p50/p95 computed via sort+index (O(n log n) is
|
|
5
|
+
* fine for v1; eval datasets are bounded by D210 streaming-deferral).
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function computeAggregate(rows: ReadonlyArray<EvalRowResult>): EvalAggregate;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D210 — normalize `Dataset` (array OR factory-of-iterable) into a
|
|
3
|
+
* concrete `AsyncIterable<DatasetEntry>`. Then the runner materializes
|
|
4
|
+
* the list (v1 doesn't stream the aggregate).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeDataset(d: Dataset): AsyncGenerator<DatasetEntry, void, void>;
|
|
9
|
+
export declare function materializeDataset(d: Dataset): Promise<DatasetEntry[]>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D204 — Eval execution engine. Orchestrates dataset materialization,
|
|
3
|
+
* `Agent.batch` fanout, scorer application, aggregate computation, and
|
|
4
|
+
* single-flight lifecycle.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
import type { EvalOptions, EvalRun, EvalRunOptions } from "../../types/eval.js";
|
|
9
|
+
export declare function runEval(options: EvalOptions, runOpts: EvalRunOptions | undefined): Promise<EvalRun>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D213 — single-flight guard for `Eval.run`. Module-level `Set<string>`
|
|
3
|
+
* tracks running names; `acquire` throws on collision; `release` is
|
|
4
|
+
* idempotent.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class EvalAlreadyRunningError extends Error {
|
|
9
|
+
readonly name = "EvalAlreadyRunningError";
|
|
10
|
+
readonly evalName: string;
|
|
11
|
+
constructor(evalName: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function acquireSingleFlight(name: string): void;
|
|
14
|
+
export declare function releaseSingleFlight(name: string): void;
|
|
15
|
+
/** Test-only — clears the running set. NOT exported via barrel. */
|
|
16
|
+
export declare function __resetSingleFlightForTests(): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D206 — minimal OTel piggyback for `Eval.run`. Emits a parent `eval.run`
|
|
3
|
+
* span when available; child `agent.send` spans (existing per D34) nest
|
|
4
|
+
* correctly when OTel context is active.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface EvalTelemetryHandle {
|
|
9
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
10
|
+
end(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Start an `eval.run` span. Returns a handle whose `end()` MUST be called
|
|
14
|
+
* in `finally`. When OTel is unavailable, returns a no-op.
|
|
15
|
+
*/
|
|
16
|
+
export declare function startEvalRunSpan(attrs: {
|
|
17
|
+
name: string;
|
|
18
|
+
id: string;
|
|
19
|
+
rows: number;
|
|
20
|
+
concurrency: number;
|
|
21
|
+
}): EvalTelemetryHandle;
|
|
22
|
+
/** Test-only — clears the tracer cache so a re-load happens. */
|
|
23
|
+
export declare function __resetEvalOtelCacheForTests(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixture-mode detection.
|
|
3
|
+
*
|
|
4
|
+
* When `THEOKIT_API_BASE_URL` is NOT set and the API key matches the
|
|
5
|
+
* `theo_test_*` pattern, the SDK runs in fixture mode — it returns
|
|
6
|
+
* deterministic, baked-in responses that match the golden fixtures under
|
|
7
|
+
* `tests/golden/`. This is documented behavior and part of the contract
|
|
8
|
+
* (analogous to Stripe's test keys), NOT a test-side mock.
|
|
9
|
+
*
|
|
10
|
+
* When `THEOKIT_API_BASE_URL` is set (e.g. pointing at a test HTTP server
|
|
11
|
+
* or a real Theo PaaS instance), the SDK always performs real HTTP
|
|
12
|
+
* requests — fixture mode is short-circuited.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff dispatch orchestration.
|
|
3
|
+
*
|
|
4
|
+
* Pragmatic v1: when a handoff fires, the sender calls `receiver.send()`
|
|
5
|
+
* with the (optionally filtered) history. The receiver's reply is returned
|
|
6
|
+
* to the sender, which captures it as the answer to the user's question.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: this is NOT pure peer-to-peer (the sender stays on the call stack
|
|
9
|
+
* until the receiver returns). Pure intercept-and-swap requires deeper
|
|
10
|
+
* agent-loop refactor; deferred to v2. v1 still validates the user-facing
|
|
11
|
+
* value: "agent A reasoned about routing, agent B answered."
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import type { HandoffDescriptor, HandoffHistory, HandoffResult } from "../../types/handoff.js";
|
|
16
|
+
import { type HandoffChainState } from "./registry.js";
|
|
17
|
+
export declare function dispatchHandoff(args: {
|
|
18
|
+
descriptor: HandoffDescriptor;
|
|
19
|
+
senderAgentId: string;
|
|
20
|
+
chainState: HandoffChainState;
|
|
21
|
+
rawInputJson: unknown;
|
|
22
|
+
/** The conversation so far (history wrapper). v1: just the LAST user message. */
|
|
23
|
+
history: HandoffHistory;
|
|
24
|
+
/** Override the message text sent to the receiver. Used by `Agent.handoffTo` imperative. */
|
|
25
|
+
messageOverride?: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
reply: string;
|
|
28
|
+
result: HandoffResult;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff registry — pure state container per `Agent` instance.
|
|
3
|
+
*
|
|
4
|
+
* Holds the active dispatch chain (for depth + pair tracking) across the
|
|
5
|
+
* lifetime of a single `agent.send()` call. Cleared between calls.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface HandoffChainState {
|
|
10
|
+
/** Ordered chain of agentIds traversed so far (oldest first). */
|
|
11
|
+
readonly chain: string[];
|
|
12
|
+
/** Set of "<sender>-><receiver>" keys for pair-level loop detection (D221). */
|
|
13
|
+
readonly seenPairs: Set<string>;
|
|
14
|
+
/** Caller-supplied max depth (D218). */
|
|
15
|
+
readonly maxDepth: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function createChainState(rootAgentId: string, maxDepth: number): HandoffChainState;
|
|
18
|
+
/**
|
|
19
|
+
* Record a handoff hop. Throws on depth-exceed (D218) or pair-loop (D221).
|
|
20
|
+
* Mutates the state in place.
|
|
21
|
+
*/
|
|
22
|
+
export declare function recordHop(state: HandoffChainState, senderAgentId: string, receiverAgentId: string): void;
|
|
23
|
+
export declare function currentDepth(state: HandoffChainState): number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D220 — Lazy-loaded OTel `handoff.transfer` span emitter.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface HandoffSpanHandle {
|
|
7
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
8
|
+
end(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function startHandoffSpan(attrs: {
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
reason: string;
|
|
14
|
+
depth: number;
|
|
15
|
+
toolName: string;
|
|
16
|
+
}): HandoffSpanHandle;
|
|
17
|
+
/** Test-only — reset cached OTel handle. */
|
|
18
|
+
export declare function __resetHandoffOtelCacheForTests(): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert `handoffs[]` entries into synthetic `transfer_to_<receiver>` tools
|
|
3
|
+
* for injection into the agent's tool registry at construction time.
|
|
4
|
+
*
|
|
5
|
+
* The synthesized tool's handler calls `dispatchHandoff` internally and
|
|
6
|
+
* returns the receiver's reply as `tool_result`. v1 trade-off documented
|
|
7
|
+
* in dispatcher.ts.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
import type { CustomTool, SDKAgent } from "../../types/agent.js";
|
|
12
|
+
import { type HandoffDescriptor } from "../../types/handoff.js";
|
|
13
|
+
interface NormalizedHandoff {
|
|
14
|
+
descriptor: HandoffDescriptor;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Normalize each `handoffs[]` entry to a `HandoffDescriptor`. Raw `SDKAgent`
|
|
18
|
+
* instances are auto-wrapped with default options. Validates:
|
|
19
|
+
* - EC-6: no self-reference (would cause infinite recursion).
|
|
20
|
+
* - D215: resolved tool names must be unique.
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeHandoffs(parentAgentId: string, entries: ReadonlyArray<SDKAgent | HandoffDescriptor>): NormalizedHandoff[];
|
|
23
|
+
/**
|
|
24
|
+
* Build a `CustomTool` for one handoff descriptor. The handler dispatches
|
|
25
|
+
* the handoff using a fresh chain state per `send()`-level invocation.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: this v1 builds a NEW chain state per tool invocation. Pure
|
|
28
|
+
* cross-tool depth tracking within one send() requires per-Agent context
|
|
29
|
+
* — deferred. The single-flight pair guard catches direct ping-pong even
|
|
30
|
+
* without cross-invocation chain (since each call wraps the same depth
|
|
31
|
+
* counter from 1).
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildHandoffTool(parentAgentId: string, descriptor: HandoffDescriptor, maxHandoffDepth: number): CustomTool;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Judge call primitive (T2.2, ADRs D119-D121).
|
|
3
|
+
*
|
|
4
|
+
* Instantiates a short-lived auxiliary agent that evaluates whether a
|
|
5
|
+
* goal is satisfied. The auxiliary judge runs with `tools: []` and a
|
|
6
|
+
* cheap model (default `openai/gpt-4o-mini`) — see ADR D119. The judge
|
|
7
|
+
* model needs only API access; we read `OPENROUTER_API_KEY` directly
|
|
8
|
+
* from the environment (EC-A — single source of truth) and let the
|
|
9
|
+
* caller override via {@link JudgeOptions.apiKey} for Anthropic or
|
|
10
|
+
* direct-OpenAI environments.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: judge aux agents created from inside a `forkAgent` context will
|
|
13
|
+
* inherit the parent fork's whitelist via AsyncLocalStorage (EC-J).
|
|
14
|
+
* `tools: []` keeps this benign today; future callers that add tools to
|
|
15
|
+
* a judge should be aware.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
/** Inputs to the judge — pure data. */
|
|
20
|
+
export interface JudgeContext {
|
|
21
|
+
goal: string;
|
|
22
|
+
lastResponse: string;
|
|
23
|
+
subgoals?: string[];
|
|
24
|
+
}
|
|
25
|
+
/** Caller-supplied tuning knobs for the judge call. */
|
|
26
|
+
export interface JudgeOptions {
|
|
27
|
+
/** Judge model identifier. Default `"openai/gpt-4o-mini"` (ADR D119). */
|
|
28
|
+
judgeModel?: string;
|
|
29
|
+
/** Override env. Default `process.env.OPENROUTER_API_KEY` (EC-A). */
|
|
30
|
+
apiKey?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Dependencies injected so `judge-call.ts` stays free of `Agent` import. */
|
|
33
|
+
export interface JudgeDeps {
|
|
34
|
+
create: (options: AgentOptions) => Promise<SDKAgent>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure verdict parser (T2.1, ADRs D120-D121).
|
|
3
|
+
*
|
|
4
|
+
* Strict prefix matching against `DONE:`, `CONTINUE:`, `SKIPPED:`. Reason
|
|
5
|
+
* is the suffix, trimmed. Anything else is fail-safe: verdict = `continue`,
|
|
6
|
+
* `parseFailed: true` — caller's max-consecutive-failure cap stops the
|
|
7
|
+
* loop after N flakes.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseVerdict(text: string): JudgeResult;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the judge subsystem (T2.1, ADR D120).
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
/** Outcome of {@link parseVerdict} / {@link judgeCallImpl}. */
|
|
7
|
+
export interface JudgeResult {
|
|
8
|
+
verdict: Verdict;
|
|
9
|
+
reason: string;
|
|
10
|
+
/**
|
|
11
|
+
* `true` when the underlying text did not start with one of the three
|
|
12
|
+
* canonical prefixes. The verdict is set to `"continue"` (fail-safe,
|
|
13
|
+
* ADR D121) to avoid stopping prematurely; callers track consecutive
|
|
14
|
+
* failures and bail via `maxConsecutiveJudgeFailures`.
|
|
15
|
+
*/
|
|
16
|
+
parseFailed: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for Anthropic Messages wire format across direct API
|
|
3
|
+
* (anthropic.ts), Vertex (vertex-anthropic.ts), and Bedrock (bedrock-anthropic.ts)
|
|
4
|
+
* clients. Extracted to remove cross-module clones flagged by jscpd.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
import type { LlmMessage, LlmRequest, LlmStopReason, LlmToolCallPart } from "./types.js";
|
|
9
|
+
export interface AnthropicResponseLike {
|
|
10
|
+
content?: Array<{
|
|
11
|
+
type: "text";
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: "tool_use";
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
input: Record<string, unknown>;
|
|
18
|
+
}>;
|
|
19
|
+
stop_reason?: string | null;
|
|
20
|
+
usage?: {
|
|
21
|
+
input_tokens?: number;
|
|
22
|
+
output_tokens?: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function extractAnthropicText(response: AnthropicResponseLike): string;
|
|
26
|
+
export declare function extractAnthropicToolCalls(response: AnthropicResponseLike): LlmToolCallPart[];
|
|
27
|
+
export declare function mapAnthropicStopReason(reason: string | null): LlmStopReason;
|
|
28
|
+
/**
|
|
29
|
+
* Convert an SDK `LlmMessage` to the Anthropic Messages wire shape.
|
|
30
|
+
* Identical across the three Anthropic-compatible clients (D289/D292).
|
|
31
|
+
*/
|
|
32
|
+
export declare function toAnthropicWireMessage(message: LlmMessage): Record<string, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Build the common body shape for Anthropic Messages requests. Caller
|
|
35
|
+
* is responsible for adding wire-specific fields (`anthropic_version`,
|
|
36
|
+
* `model`, `stream`, etc.).
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Issue a POST to an Anthropic-compatible Messages endpoint with the
|
|
40
|
+
* standard auth + content-type headers. Caller maps non-2xx via its own
|
|
41
|
+
* dialect-specific error mapper.
|
|
42
|
+
*/
|
|
43
|
+
export declare function postAnthropicRequest(args: {
|
|
44
|
+
fetchImpl: typeof fetch;
|
|
45
|
+
url: string;
|
|
46
|
+
token: string;
|
|
47
|
+
body: Record<string, unknown>;
|
|
48
|
+
signal: AbortSignal;
|
|
49
|
+
}): Promise<Response>;
|
|
50
|
+
/**
|
|
51
|
+
* Map non-2xx response to a typed error via the dialect mapper; consume
|
|
52
|
+
* 2xx body into the Anthropic-shape result. Shared by Bedrock + Vertex
|
|
53
|
+
* Anthropic clients to remove the ~15-line clone (jscpd).
|
|
54
|
+
*/
|
|
55
|
+
export declare function handleAnthropicResponse(args: {
|
|
56
|
+
response: Response;
|
|
57
|
+
endpoint: string;
|
|
58
|
+
errorMapper: (info: {
|
|
59
|
+
status: number;
|
|
60
|
+
body: unknown;
|
|
61
|
+
headers: Headers;
|
|
62
|
+
endpoint: string;
|
|
63
|
+
}) => Error;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
text: string;
|
|
66
|
+
toolCalls: LlmToolCallPart[];
|
|
67
|
+
stopReason: LlmStopReason;
|
|
68
|
+
inputTokens?: number;
|
|
69
|
+
outputTokens?: number;
|
|
70
|
+
}>;
|
|
71
|
+
export declare function consumeAnthropicResponse(response: Response): Promise<{
|
|
72
|
+
text: string;
|
|
73
|
+
toolCalls: LlmToolCallPart[];
|
|
74
|
+
stopReason: LlmStopReason;
|
|
75
|
+
inputTokens?: number;
|
|
76
|
+
outputTokens?: number;
|
|
77
|
+
}>;
|
|
78
|
+
export declare function parseHttpErrorBody(response: Response): Promise<unknown>;
|
|
79
|
+
export declare function buildAnthropicCommonBody(request: LlmRequest): {
|
|
80
|
+
max_tokens: number;
|
|
81
|
+
messages: Array<Record<string, unknown>>;
|
|
82
|
+
system?: string;
|
|
83
|
+
temperature?: number;
|
|
84
|
+
tools?: Array<{
|
|
85
|
+
name: string;
|
|
86
|
+
description: string;
|
|
87
|
+
input_schema: unknown;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
2
|
+
export declare class AnthropicClient implements LlmClient {
|
|
3
|
+
private readonly options;
|
|
4
|
+
readonly name = "anthropic";
|
|
5
|
+
private readonly baseUrl;
|
|
6
|
+
private readonly fetchImpl;
|
|
7
|
+
constructor(options: AnthropicClientOptions);
|
|
8
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS Bedrock client for Anthropic Messages (Adoption Roadmap #8; ADRs
|
|
3
|
+
* D286-D302).
|
|
4
|
+
*
|
|
5
|
+
* v1: non-streaming only (`POST /model/{id}/invoke`). D302 defers
|
|
6
|
+
* `/invoke-with-response-stream` (AWS Event Stream binary format) to v1.x.
|
|
7
|
+
*
|
|
8
|
+
* Body massage (D289):
|
|
9
|
+
* - inject `anthropic_version: "bedrock-2023-05-31"`
|
|
10
|
+
* - strip `model` from body (goes in URL)
|
|
11
|
+
* - strip `stream` from body (D302 — non-streaming only in v1)
|
|
12
|
+
*
|
|
13
|
+
* Uses native `fetch` only — no `@aws-sdk/client-bedrock-runtime`.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
18
|
+
export interface BedrockAnthropicClientOptions {
|
|
19
|
+
/**
|
|
20
|
+
* AWS Bearer token. When non-empty, used as-is. When empty/undefined,
|
|
21
|
+
* resolved lazily per request via `resolveBedrockToken(region)` (D287).
|
|
22
|
+
*/
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
/** Override the resolved baseUrl (rarely needed; defaults derive from model id). */
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
/** Injected fetch impl for tests. */
|
|
27
|
+
fetch?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
export declare class BedrockAnthropicClient implements LlmClient {
|
|
30
|
+
private readonly options;
|
|
31
|
+
readonly name = "bedrock";
|
|
32
|
+
private readonly fetchImpl;
|
|
33
|
+
constructor(options: BedrockAnthropicClientOptions);
|
|
34
|
+
private resolveTokenOrThrow;
|
|
35
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bedrock Bearer token resolution + cache (ADRs D287, D295).
|
|
3
|
+
*
|
|
4
|
+
* Two paths:
|
|
5
|
+
* 1. Explicit env (`AWS_BEARER_TOKEN_BEDROCK`) wins; no refresh.
|
|
6
|
+
* 2. Optional peer dep `@aws/bedrock-token-generator` (D287) auto-generates
|
|
7
|
+
* short-term tokens from the standard AWS credential chain
|
|
8
|
+
* (`@aws-sdk/credential-providers`). Cached for 1.5h.
|
|
9
|
+
*
|
|
10
|
+
* `resolveBedrockToken` returns `undefined` only when BOTH paths produce no
|
|
11
|
+
* token. Caller (router) is responsible for throwing a helpful error
|
|
12
|
+
* (D279/EC-6) — this module is auth-resolution only.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveBedrockToken(region: string): Promise<string | undefined>;
|
|
17
|
+
/** Test seam — clear cache between tests. */
|
|
18
|
+
export declare function __resetBedrockTokenCache(): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-fork credential-pool inheritance via `AsyncLocalStorage` (ADR D131).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the whitelist context pattern from D111
|
|
5
|
+
* (`runtime/async-local-storage.ts`). Forked sub-agents inherit the
|
|
6
|
+
* parent's pool *by reference* so concurrent rotations all observe
|
|
7
|
+
* the same cooldown state — the desired behavior per Hermes parity.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the credential pool subsystem (ADRs D123-D133).
|
|
3
|
+
*
|
|
4
|
+
* Pool a developer's multiple API keys for the SAME provider so the SDK
|
|
5
|
+
* can rotate transparently on HTTP 429/402/401 instead of jumping
|
|
6
|
+
* straight to a different provider via `FallbackLlmClient`.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
/** Health flag tracked per credential. */
|
|
11
|
+
export type CredentialStatus = "ok" | "exhausted";
|
|
12
|
+
/**
|
|
13
|
+
* Provenance of a credential — where it came from when seeded.
|
|
14
|
+
* Free-form string; conventional prefixes:
|
|
15
|
+
*
|
|
16
|
+
* - `env:<VAR_NAME>` — auto-discovered from environment variable
|
|
17
|
+
* - `manual` — added via explicit `apiKeys` config
|
|
18
|
+
* - `explicit-apikey` — wrapped from `AgentOptions.apiKey` single-key path (D132)
|
|
19
|
+
*/
|
|
20
|
+
export type CredentialSource = string;
|
|
21
|
+
/** Default cooldown when no specific code matches. */
|
|
22
|
+
export declare const DEFAULT_COOLDOWN_MS: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory credential pool with strategy-based rotation (ADRs D123-D133).
|
|
3
|
+
*
|
|
4
|
+
* Pure logic. No I/O — persistence lives in `internal/persistence/
|
|
5
|
+
* credential-pool-store.ts`. The pool is the single source of truth for
|
|
6
|
+
* rotation state within a process; if it diverges from disk (e.g.,
|
|
7
|
+
* process killed mid-rotation per EC-I), the next save heals the
|
|
8
|
+
* inconsistency — at the cost of one extra HTTP 429 per crash.
|
|
9
|
+
*
|
|
10
|
+
* Thread safety: the pool uses an in-process async-aware mutex
|
|
11
|
+
* (`cwd-mutex` D9 keyed by `credential-pool:${provider}`). Cross-process
|
|
12
|
+
* safety happens at the persistence layer via `withFileLock` (D61).
|
|
13
|
+
* Two Node processes sharing the same file may double-pick momentarily
|
|
14
|
+
* (worst case = 1 extra 429 per race) — acceptable per ADR D128.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* D14 — Fault injection via `THEOKIT_TEST_RESPONSE_OVERRIDE` env var.
|
|
3
|
+
*
|
|
4
|
+
* Decorator pattern (D127 inspired): wraps any `LlmClient` and short-circuits
|
|
5
|
+
* the network call when:
|
|
6
|
+
*
|
|
7
|
+
* 1. `process.env.NODE_ENV === "test"` (fail-safe gate — prevents production
|
|
8
|
+
* footgun), AND
|
|
9
|
+
* 2. `process.env.THEOKIT_TEST_RESPONSE_OVERRIDE` is a non-empty JSON string
|
|
10
|
+
* shaped as `{ "status": number, "body": object | string }`.
|
|
11
|
+
*
|
|
12
|
+
* On any other condition (different NODE_ENV, missing env, malformed JSON),
|
|
13
|
+
* the wrapper delegates to the real client — graceful degradation.
|
|
14
|
+
*
|
|
15
|
+
* Use cases (FAANG-grade chaos testing):
|
|
16
|
+
*
|
|
17
|
+
* - `{"status":429,"body":{"error":{"code":"rate_limit_exceeded"}}}` →
|
|
18
|
+
* deterministic RateLimitError without burning real quota
|
|
19
|
+
* - `{"status":500,"body":{"error":{"code":"internal_error"}}}` →
|
|
20
|
+
* deterministic NetworkError for retry/circuit-breaker tests
|
|
21
|
+
* - `{"status":200,"body":{"choices":[{"message":{"content":"fake"}}]}}` →
|
|
22
|
+
* deterministic happy-path text for snapshot tests
|
|
23
|
+
*
|
|
24
|
+
* Compatible with the dogfood-stranger chaos phases (12-15). Replaces the
|
|
25
|
+
* flaky "50 parallel requests to force 429" anti-pattern.
|
|
26
|
+
*
|
|
27
|
+
* Wire format mirrors OpenAI Chat Completions (universal — same shape every
|
|
28
|
+
* provider returns). Error mapping reuses `mapOpenAICompatibleError` so the
|
|
29
|
+
* injected errors are byte-equal to what the real provider would raise.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
34
|
+
/**
|
|
35
|
+
* Wrap an `LlmClient` with the fault-injection decorator. Returns the
|
|
36
|
+
* original client unchanged when the activation gate is not satisfied
|
|
37
|
+
* (cheap noop — no allocation in the hot path of production runtime).
|
|
38
|
+
*/
|
|
39
|
+
export declare function maybeWrapWithFaultInjection(client: LlmClient): LlmClient;
|
|
40
|
+
export declare class FaultInjectingLlmClient implements LlmClient {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
/**
|
|
43
|
+
* Inner (real) client. Exposed so layered transport assertions (router
|
|
44
|
+
* pool-wiring tests, telemetry inspectors) can walk one level deep —
|
|
45
|
+
* same pattern PoolAwareLlmClient uses for its inner transport.
|
|
46
|
+
*/
|
|
47
|
+
readonly inner: LlmClient;
|
|
48
|
+
constructor(inner: LlmClient);
|
|
49
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|