@theokit/sdk 1.6.2 → 1.8.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 +193 -0
- package/bin/init-claude.mjs +34 -0
- package/claude-template/AGENTS.md +139 -0
- package/claude-template/CLAUDE.md +51 -0
- package/claude-template/dot-claude/rules/theokit-conventions.md +33 -0
- package/claude-template/dot-claude/settings.json +16 -0
- package/claude-template/dot-claude/skills/theokit-agent-core/SKILL.md +209 -0
- package/claude-template/dot-claude/skills/theokit-budget/SKILL.md +176 -0
- package/claude-template/dot-claude/skills/theokit-config/SKILL.md +139 -0
- package/claude-template/dot-claude/skills/theokit-cron/SKILL.md +148 -0
- package/claude-template/dot-claude/skills/theokit-di/SKILL.md +233 -0
- package/claude-template/dot-claude/skills/theokit-di-agent/SKILL.md +294 -0
- package/claude-template/dot-claude/skills/theokit-errors/SKILL.md +172 -0
- package/claude-template/dot-claude/skills/theokit-eval/SKILL.md +144 -0
- package/claude-template/dot-claude/skills/theokit-gateways/SKILL.md +209 -0
- package/claude-template/dot-claude/skills/theokit-memory/SKILL.md +176 -0
- package/claude-template/dot-claude/skills/theokit-rag/SKILL.md +226 -0
- package/claude-template/dot-claude/skills/theokit-streaming/SKILL.md +156 -0
- package/claude-template/dot-claude/skills/theokit-subscriptions/SKILL.md +148 -0
- package/claude-template/dot-claude/skills/theokit-tools/SKILL.md +170 -0
- package/claude-template/dot-claude/skills/theokit-workflows/SKILL.md +218 -0
- package/dist/a2a/agent-mailbox.d.cts +27 -0
- package/dist/a2a/agent-mailbox.d.ts +27 -0
- package/dist/a2a/index.cjs +16850 -0
- package/dist/a2a/index.cjs.map +1 -0
- package/dist/a2a/index.d.cts +9 -0
- package/dist/a2a/index.d.ts +9 -0
- package/dist/a2a/index.js +16844 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/a2a/message-bus.d.cts +27 -0
- package/dist/a2a/message-bus.d.ts +27 -0
- package/dist/a2a/subagent.d.cts +25 -0
- package/dist/a2a/subagent.d.ts +25 -0
- package/dist/a2a/types.d.cts +12 -0
- package/dist/a2a/types.d.ts +12 -0
- package/dist/agent.d.ts +1 -1
- package/dist/client/index.cjs +73 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +7 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +71 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/theokit-client.d.cts +18 -0
- package/dist/client/theokit-client.d.ts +18 -0
- package/dist/client/types.d.cts +19 -0
- package/dist/client/types.d.ts +19 -0
- package/dist/{run-DkCD5DeO.d.cts → cron-BnywDYLq.d.cts} +496 -910
- package/dist/{run-DkCD5DeO.d.ts → cron-CtZvJD9J.d.ts} +496 -910
- package/dist/cron.cjs +4285 -2893
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -3
- package/dist/cron.d.ts +2 -71
- package/dist/cron.js +4289 -2897
- package/dist/cron.js.map +1 -1
- package/dist/{errors-CvAeEWgE.d.ts → errors-ChqOmFH1.d.cts} +52 -6
- package/dist/{errors-CK8brCJ1.d.cts → errors-DV9e0rcp.d.ts} +52 -6
- package/dist/errors.cjs +218 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -3
- package/dist/errors.d.ts +50 -4
- package/dist/errors.js +217 -4
- package/dist/errors.js.map +1 -1
- package/dist/eval.cjs +4285 -2893
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +35 -0
- package/dist/eval.js +4289 -2897
- package/dist/eval.js.map +1 -1
- package/dist/event-bus.d.ts +23 -0
- package/dist/index.cjs +5132 -4200
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +298 -278
- package/dist/index.d.ts +1898 -24
- package/dist/index.js +6441 -5509
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +22 -1
- package/dist/internal/auth/api-key-validator.d.ts +46 -0
- package/dist/internal/llm/anthropic-shared.d.ts +8 -1
- package/dist/internal/llm/retry.d.ts +22 -0
- package/dist/internal/llm/types.d.ts +47 -1
- package/dist/internal/memory/active-memory-cache.d.ts +3 -3
- package/dist/internal/memory/active-memory-types.d.ts +8 -0
- package/dist/internal/memory/active-memory.d.ts +24 -20
- package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
- package/dist/internal/memory/index-manager-contract.d.ts +26 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +1 -1
- package/dist/internal/memory/index-manager.d.ts +8 -26
- package/dist/internal/memory/{chunk-markdown.d.ts → storage/chunk-markdown.d.ts} +1 -1
- package/dist/internal/memory/{markdown-store.d.ts → storage/markdown-store.d.ts} +1 -1
- package/dist/internal/memory/{reader.d.ts → storage/reader.d.ts} +1 -1
- package/dist/internal/observability/context.d.cts +23 -0
- package/dist/internal/observability/context.d.ts +23 -0
- package/dist/internal/observability/index.cjs +38 -0
- package/dist/internal/observability/index.cjs.map +1 -0
- package/dist/internal/observability/index.d.cts +8 -0
- package/dist/internal/observability/index.d.ts +8 -0
- package/dist/internal/observability/index.js +33 -0
- package/dist/internal/observability/index.js.map +1 -0
- package/dist/internal/observability/tracer-loader.d.cts +20 -0
- package/dist/internal/persistence/conversation-storage-fs.d.cts +37 -0
- package/dist/internal/persistence/conversation-storage-memory.d.cts +24 -0
- package/dist/internal/persistence/credential-pool-store.d.cts +32 -0
- package/dist/internal/persistence/credential-pool-store.d.ts +32 -0
- package/dist/internal/persistence/cwd-mutex.d.cts +1 -0
- package/dist/internal/persistence/exclusive-create.d.cts +22 -0
- package/dist/internal/persistence/exclusive-create.d.ts +22 -0
- package/dist/internal/persistence/file-lock.d.cts +14 -0
- package/dist/internal/persistence/fts5-sanitize.d.cts +16 -0
- package/dist/internal/persistence/index.cjs +359 -0
- package/dist/internal/persistence/index.cjs.map +1 -0
- package/dist/internal/persistence/index.d.cts +20 -0
- package/dist/internal/persistence/index.d.ts +20 -0
- package/dist/internal/persistence/index.js +341 -0
- package/dist/internal/persistence/index.js.map +1 -0
- package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
- package/dist/internal/persistence/paths.d.cts +19 -0
- package/dist/internal/persistence/persistence-schema.d.cts +21 -0
- package/dist/internal/persistence/persistence-schema.d.ts +4 -0
- package/dist/internal/persistence/schema-version.d.cts +13 -0
- package/dist/internal/persistence/sqlite-cas.d.cts +25 -0
- package/dist/internal/persistence/sqlite-cas.d.ts +25 -0
- package/dist/internal/persistence/sqlite-wal.d.cts +10 -0
- package/dist/internal/plugins/context.d.cts +31 -0
- package/dist/internal/plugins/index.cjs +228 -0
- package/dist/internal/plugins/index.cjs.map +1 -0
- package/dist/internal/plugins/index.d.cts +8 -0
- package/dist/internal/plugins/index.d.ts +8 -0
- package/dist/internal/plugins/index.js +222 -0
- package/dist/internal/plugins/index.js.map +1 -0
- package/dist/internal/plugins/lifecycle.d.cts +14 -0
- package/dist/internal/plugins/lifecycle.d.ts +14 -0
- package/dist/internal/plugins/manager.d.cts +37 -0
- package/dist/internal/plugins/types.d.cts +102 -0
- package/dist/internal/providers/catalog-loader.d.ts +39 -0
- package/dist/internal/runtime/agent-session-store.d.ts +1 -1
- package/dist/internal/runtime/agent-session.d.ts +1 -0
- package/dist/internal/runtime/budget-tracker.d.ts +73 -0
- package/dist/internal/runtime/{context-manager.d.ts → context/context-manager.d.ts} +1 -1
- package/dist/internal/runtime/{fixture-events.d.ts → fixtures/fixture-events.d.ts} +1 -1
- package/dist/internal/runtime/{fixture-run-base.d.ts → fixtures/fixture-run-base.d.ts} +4 -4
- package/dist/internal/runtime/{fixture-scripts.d.ts → fixtures/fixture-scripts.d.ts} +1 -1
- package/dist/internal/runtime/local-agent-bootstrap.d.ts +2 -2
- package/dist/internal/runtime/local-agent-memory-provider.d.ts +57 -0
- package/dist/internal/runtime/memory-path-selector.d.ts +73 -0
- package/dist/internal/runtime/memory-provider.d.ts +165 -0
- package/dist/internal/runtime/{agent-registry.d.ts → registry/agent-registry-contract.d.ts} +15 -9
- package/dist/internal/runtime/registry/agent-registry.d.ts +7 -0
- package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts} +1 -1
- package/dist/internal/runtime/{run-registry.d.ts → registry/run-registry.d.ts} +1 -1
- package/dist/internal/runtime/session-types.d.ts +35 -0
- package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/validate-response.d.ts +18 -0
- package/dist/internal/security/index.cjs +361 -0
- package/dist/internal/security/index.cjs.map +1 -0
- package/dist/internal/security/index.d.cts +11 -0
- package/dist/internal/security/index.js +350 -0
- package/dist/internal/security/index.js.map +1 -0
- package/dist/internal/security/path-guard.d.cts +59 -0
- package/dist/internal/security/path-guard.d.ts +3 -0
- package/dist/internal/security/redact.d.cts +21 -0
- package/dist/internal/security/secret-redactor.d.cts +1 -0
- package/dist/internal/security/secret-redactor.d.ts +1 -0
- package/dist/internal/security/test-reset.d.cts +10 -0
- package/dist/internal/security/test-reset.d.ts +10 -0
- package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
- package/dist/internal/telemetry/adapters/braintrust.d.ts +2 -0
- package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langsmith.d.ts +2 -0
- package/dist/internal/telemetry/span-names.d.ts +6 -0
- package/dist/internal/telemetry/tracer.d.ts +1 -0
- package/dist/internal/workflow/evented-executor.d.ts +42 -0
- package/dist/internal/workflow/scheduler.d.ts +23 -0
- package/dist/internal/zod/to-json-schema.d.ts +5 -15
- package/dist/job-queue.d.ts +28 -0
- package/dist/path-safety.cjs +67 -6
- package/dist/path-safety.cjs.map +1 -1
- package/dist/path-safety.d.cts +15 -0
- package/dist/path-safety.d.ts +1 -1
- package/dist/path-safety.js +67 -7
- package/dist/path-safety.js.map +1 -1
- package/dist/permission-engine.d.ts +21 -0
- package/dist/provider-catalog.json +702 -0
- package/dist/rag/index.cjs +136 -0
- package/dist/rag/index.cjs.map +1 -0
- package/dist/rag/index.d.cts +11 -0
- package/dist/rag/index.d.ts +11 -0
- package/dist/rag/index.js +129 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/reranker.d.cts +26 -0
- package/dist/rag/reranker.d.ts +26 -0
- package/dist/rag/retriever.d.cts +25 -0
- package/dist/rag/retriever.d.ts +25 -0
- package/dist/rag/text-splitter.d.cts +12 -0
- package/dist/rag/text-splitter.d.ts +12 -0
- package/dist/rag/types.d.cts +37 -0
- package/dist/rag/types.d.ts +37 -0
- package/dist/run-DrwUpFxZ.d.cts +823 -0
- package/dist/run-DrwUpFxZ.d.ts +823 -0
- package/dist/sandbox/index.cjs +133 -0
- package/dist/sandbox/index.cjs.map +1 -0
- package/dist/sandbox/index.d.cts +2 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/sandbox/index.js +128 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/local-sandbox.d.cts +17 -0
- package/dist/sandbox/local-sandbox.d.ts +17 -0
- package/dist/sandbox/types.d.cts +44 -0
- package/dist/sandbox/types.d.ts +44 -0
- package/dist/server/adapter/express.d.cts +9 -0
- package/dist/server/adapter/express.d.ts +9 -0
- package/dist/server/adapter/fastify.d.cts +9 -0
- package/dist/server/adapter/fastify.d.ts +9 -0
- package/dist/server/adapter/hono.d.cts +9 -0
- package/dist/server/adapter/hono.d.ts +9 -0
- package/dist/server/adapter/index.d.cts +8 -0
- package/dist/server/adapter/index.d.ts +8 -0
- package/dist/server/adapter/shared-handler.d.cts +9 -0
- package/dist/server/adapter/shared-handler.d.ts +9 -0
- package/dist/server/adapter/types.d.cts +33 -0
- package/dist/server/adapter/types.d.ts +33 -0
- package/dist/server/auth/errors.d.cts +53 -0
- package/dist/server/auth/errors.d.ts +53 -0
- package/dist/server/auth/index.cjs +38 -41
- package/dist/server/auth/index.cjs.map +1 -1
- package/dist/server/auth/index.d.cts +11 -172
- package/dist/server/auth/index.d.ts +11 -172
- package/dist/server/auth/index.js +39 -42
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/oauth-transaction-store.d.cts +39 -0
- package/dist/server/auth/oauth-transaction-store.d.ts +39 -0
- package/dist/server/auth/orchestrator.d.cts +8 -0
- package/dist/server/auth/orchestrator.d.ts +8 -0
- package/dist/server/auth/types.d.cts +91 -0
- package/dist/server/auth/types.d.ts +91 -0
- package/dist/server/auth/validate-return-to.d.cts +17 -0
- package/dist/server/auth/validate-return-to.d.ts +17 -0
- package/dist/server/errors-envelope.cjs +409 -0
- package/dist/server/errors-envelope.cjs.map +1 -0
- package/dist/server/errors-envelope.d.cts +61 -0
- package/dist/server/errors-envelope.d.ts +61 -0
- package/dist/server/errors-envelope.js +405 -0
- package/dist/server/errors-envelope.js.map +1 -0
- package/dist/subscription/define-subscription.d.cts +63 -0
- package/dist/subscription/define-subscription.d.ts +63 -0
- package/dist/subscription/index.cjs +402 -0
- package/dist/subscription/index.cjs.map +1 -0
- package/dist/subscription/index.d.cts +18 -0
- package/dist/subscription/index.d.ts +18 -0
- package/dist/subscription/index.js +394 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/internal/adapter-types.d.cts +11 -0
- package/dist/subscription/internal/adapter-types.d.ts +11 -0
- package/dist/subscription/internal/backpressure.d.cts +24 -0
- package/dist/subscription/internal/backpressure.d.ts +24 -0
- package/dist/subscription/internal/server-integration.d.cts +17 -0
- package/dist/subscription/internal/server-integration.d.ts +17 -0
- package/dist/subscription/internal/sse-encoder.d.cts +13 -0
- package/dist/subscription/internal/sse-encoder.d.ts +13 -0
- package/dist/subscription/internal/sse-parser.d.cts +15 -0
- package/dist/subscription/internal/sse-parser.d.ts +15 -0
- package/dist/subscription/internal/subscription-runtime.d.cts +9 -0
- package/dist/subscription/internal/subscription-runtime.d.ts +9 -0
- package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
- package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
- package/dist/subscription/theokit-subscribe.d.cts +41 -0
- package/dist/subscription/theokit-subscribe.d.ts +41 -0
- package/dist/subscription/types.d.cts +140 -0
- package/dist/subscription/types.d.ts +140 -0
- package/dist/task-store.cjs +30 -2
- package/dist/task-store.cjs.map +1 -1
- package/dist/task-store.d.cts +8 -0
- package/dist/task-store.js +31 -3
- package/dist/task-store.js.map +1 -1
- package/dist/types/agent-prims.d.ts +61 -0
- package/dist/types/agent.d.ts +48 -53
- package/dist/types/conversation.d.ts +20 -8
- package/dist/types/index.d.ts +0 -2
- package/dist/types/messages-base.d.ts +20 -0
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/run.d.ts +1 -1
- package/dist/types/updates.d.ts +1 -1
- package/dist/voice/index.d.ts +7 -0
- package/dist/voice/openai-realtime.d.ts +21 -0
- package/dist/voice/types.d.ts +35 -0
- package/dist/workflow.cjs +179 -88
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +97 -0
- package/dist/workflow.js +180 -89
- package/dist/workflow.js.map +1 -1
- package/package.json +128 -25
- package/dist/budget.d.ts +0 -48
- package/dist/cache.d.ts +0 -74
- package/dist/cron-1yxL3K2S.d.cts +0 -221
- package/dist/cron-BYVdYzob.d.ts +0 -221
- package/dist/handoff.d.ts +0 -55
- package/dist/internal/budget/calendar-window.d.ts +0 -19
- package/dist/internal/budget/enforcement.d.ts +0 -32
- package/dist/internal/budget/ledger.d.ts +0 -25
- package/dist/internal/budget/normalize-usage.d.ts +0 -27
- package/dist/internal/budget/registry.d.ts +0 -16
- package/dist/internal/cache/cosine.d.ts +0 -14
- package/dist/internal/cache/embed-helper.d.ts +0 -15
- package/dist/internal/cache/key.d.ts +0 -15
- package/dist/internal/cache/lookup.d.ts +0 -28
- package/dist/internal/cache/store-handler.d.ts +0 -24
- package/dist/internal/cache/store-json.d.ts +0 -48
- package/dist/internal/cache/store.d.ts +0 -54
- package/dist/internal/cache/telemetry.d.ts +0 -20
- package/dist/internal/cache/ttl.d.ts +0 -11
- package/dist/internal/catalog/fixtures.d.ts +0 -16
- package/dist/internal/catalog/local-models.d.ts +0 -24
- package/dist/internal/handoff/dispatcher.d.ts +0 -29
- package/dist/internal/handoff/registry.d.ts +0 -23
- package/dist/internal/handoff/telemetry.d.ts +0 -18
- package/dist/internal/handoff/tool-injector.d.ts +0 -34
- package/dist/internal/memory/atomic-write.d.ts +0 -7
- package/dist/internal/memory/dreaming/diary.d.ts +0 -4
- package/dist/internal/memory/dreaming/phases.d.ts +0 -15
- package/dist/internal/memory/dreaming/run.d.ts +0 -10
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +0 -15
- package/dist/memory-adapter-helpers.d.ts +0 -28
- package/dist/memory.d.ts +0 -123
- package/dist/migrate.d.ts +0 -33
- package/dist/security.d.ts +0 -67
- package/dist/task.d.ts +0 -87
- package/dist/theokit.d.ts +0 -84
- package/dist/tools/_path-scope.d.ts +0 -8
- package/dist/tools/_subprocess.d.ts +0 -28
- package/dist/tools/git-diff.d.ts +0 -22
- package/dist/tools/index.d.ts +0 -29
- package/dist/tools/list-dir.d.ts +0 -26
- package/dist/tools/read-file.d.ts +0 -31
- package/dist/tools/run-vitest.d.ts +0 -46
- package/dist/tools/search-text.d.ts +0 -32
- package/dist/tools.cjs +0 -690
- package/dist/tools.cjs.map +0 -1
- package/dist/tools.js +0 -683
- package/dist/tools.js.map +0 -1
- package/dist/trajectory-helpers.d.ts +0 -31
- package/dist/types/cache.d.ts +0 -76
- package/dist/types/handoff.d.ts +0 -135
- /package/dist/{internal/cron/run-job.d.ts → agent-helpers.d.ts} +0 -0
- /package/dist/internal/{cron/scheduler.d.ts → agent-loop/loop-llm-stream.d.ts} +0 -0
- /package/dist/internal/{cron/store.d.ts → agent-loop/tool-executors.d.ts} +0 -0
- /package/dist/internal/{cron/validate.d.ts → memory/index-manager-helpers.d.ts} +0 -0
- /package/dist/internal/memory/{session-loader.d.ts → storage/session-loader.d.ts} +0 -0
- /package/dist/internal/memory/{session-summary-writer.d.ts → storage/session-summary-writer.d.ts} +0 -0
- /package/dist/internal/memory/{transcript-store.d.ts → storage/transcript-store.d.ts} +0 -0
- /package/dist/internal/memory/{wiki-loader.d.ts → storage/wiki-loader.d.ts} +0 -0
- /package/dist/internal/{memory/cwd-mutex.d.ts → persistence/atomic-write.d.cts} +0 -0
- /package/dist/internal/runtime/{context-aggregator.d.ts → context/context-aggregator.d.ts} +0 -0
- /package/dist/internal/runtime/{context-discovery-runner.d.ts → context/context-discovery-runner.d.ts} +0 -0
- /package/dist/internal/runtime/{context-discovery.d.ts → context/context-discovery.d.ts} +0 -0
- /package/dist/internal/runtime/{context-frontmatter.d.ts → context/context-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{context-import-resolver.d.ts → context/context-import-resolver.d.ts} +0 -0
- /package/dist/internal/runtime/{context-loaders.d.ts → context/context-loaders.d.ts} +0 -0
- /package/dist/internal/runtime/{context-mdc-parser.d.ts → context/context-mdc-parser.d.ts} +0 -0
- /package/dist/internal/runtime/{fixture-responder.d.ts → fixtures/fixture-responder.d.ts} +0 -0
- /package/dist/internal/runtime/{fixture-types.d.ts → fixtures/fixture-types.d.ts} +0 -0
- /package/dist/internal/runtime/{plugins-manager.d.ts → local-agent-send.d.ts} +0 -0
- /package/dist/internal/runtime/{plugin-frontmatter.d.ts → plugins/plugin-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{system-prompt/providers/active-memory-provider.d.ts → plugins/plugins-manager.d.ts} +0 -0
- /package/dist/internal/runtime/{agent-factory-registry.d.ts → registry/agent-factory-registry.d.ts} +0 -0
- /package/dist/internal/runtime/{agent-registry-store.d.ts → registry/agent-registry-store.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/base-provider.d.ts → sources/active-memory-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/context-provider.d.ts → sources/base-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/memory-provider.d.ts → sources/context-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/skills-provider.d.ts → sources/memory-provider.d.ts} +0 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
---
|
|
2
|
+
user-invocable: false
|
|
3
|
+
description: Dependency injection container, decorators, scopes, and modules for @theokit/di.
|
|
4
|
+
paths:
|
|
5
|
+
- "**/*container*"
|
|
6
|
+
- "**/*inject*"
|
|
7
|
+
- "**/*provider*"
|
|
8
|
+
- "**/*module*"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# TheoKit DI -- Dependency Injection
|
|
12
|
+
|
|
13
|
+
Quick reference for `@theokit/di` -- a TypeScript DI container with decorator metadata.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @theokit/di reflect-metadata
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires `reflect-metadata` polyfill imported once at app entry and `experimentalDecorators` + `emitDecoratorMetadata` in `tsconfig.json`.
|
|
22
|
+
|
|
23
|
+
## Core decorators
|
|
24
|
+
|
|
25
|
+
### @Injectable
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Injectable, Scope } from "@theokit/di";
|
|
29
|
+
|
|
30
|
+
@Injectable()
|
|
31
|
+
class UserRepository {
|
|
32
|
+
findById(id: string) { /* ... */ }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// With options:
|
|
36
|
+
@Injectable({ scope: Scope.REQUEST })
|
|
37
|
+
class RequestScopedService { /* ... */ }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`InjectableOptions`:
|
|
41
|
+
|
|
42
|
+
| Option | Type | Default | Description |
|
|
43
|
+
|---|---|---|---|
|
|
44
|
+
| `scope` | `Scope` | `Scope.SINGLETON` | Lifecycle scope. |
|
|
45
|
+
|
|
46
|
+
### @Inject
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Inject } from "@theokit/di";
|
|
50
|
+
|
|
51
|
+
@Injectable()
|
|
52
|
+
class OrderService {
|
|
53
|
+
constructor(
|
|
54
|
+
@Inject("DATABASE_URL") private readonly dbUrl: string,
|
|
55
|
+
private readonly repo: UserRepository, // auto-resolved by type
|
|
56
|
+
) {}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Use `@Inject(token)` for string/symbol tokens. Constructor parameter types are auto-resolved via `reflect-metadata` when the parameter is a class.
|
|
61
|
+
|
|
62
|
+
### @Optional
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { Optional } from "@theokit/di";
|
|
66
|
+
|
|
67
|
+
@Injectable()
|
|
68
|
+
class NotificationService {
|
|
69
|
+
constructor(
|
|
70
|
+
@Optional() private readonly sms?: SmsGateway,
|
|
71
|
+
) {}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Resolves to `undefined` instead of throwing `TokenNotFoundError` when the dependency is not registered.
|
|
76
|
+
|
|
77
|
+
### @Qualifier
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { Qualifier } from "@theokit/di";
|
|
81
|
+
|
|
82
|
+
@Injectable()
|
|
83
|
+
class PaymentService {
|
|
84
|
+
constructor(
|
|
85
|
+
@Qualifier("stripe") private readonly gateway: PaymentGateway,
|
|
86
|
+
) {}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Disambiguates between multiple providers registered under the same interface token.
|
|
91
|
+
|
|
92
|
+
### @Primary
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { Primary, Injectable } from "@theokit/di";
|
|
96
|
+
|
|
97
|
+
@Injectable()
|
|
98
|
+
@Primary()
|
|
99
|
+
class StripeGateway implements PaymentGateway { /* ... */ }
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Marks a provider as the default when multiple are registered for the same token. Wins over non-primary providers unless `@Qualifier` is used.
|
|
103
|
+
|
|
104
|
+
### @PostConstruct / @PreDestroy
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { PostConstruct, PreDestroy, Injectable } from "@theokit/di";
|
|
108
|
+
|
|
109
|
+
@Injectable()
|
|
110
|
+
class DatabasePool {
|
|
111
|
+
@PostConstruct()
|
|
112
|
+
async init() { /* called after construction */ }
|
|
113
|
+
|
|
114
|
+
@PreDestroy()
|
|
115
|
+
async shutdown() { /* called on container.dispose() */ }
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Container
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { Container } from "@theokit/di";
|
|
123
|
+
|
|
124
|
+
const container = new Container();
|
|
125
|
+
|
|
126
|
+
// Register classes
|
|
127
|
+
container.register(UserRepository);
|
|
128
|
+
container.register(OrderService);
|
|
129
|
+
|
|
130
|
+
// Register value providers
|
|
131
|
+
container.register("DATABASE_URL", { useValue: "postgres://..." });
|
|
132
|
+
|
|
133
|
+
// Register factory providers
|
|
134
|
+
container.register("Logger", {
|
|
135
|
+
useFactory: (ctx) => new Logger(ctx.resolve("DATABASE_URL")),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Register existing (alias)
|
|
139
|
+
container.register("PrimaryRepo", { useExisting: UserRepository });
|
|
140
|
+
|
|
141
|
+
// Resolve
|
|
142
|
+
const service = container.resolve(OrderService);
|
|
143
|
+
const asyncService = await container.resolveAsync(OrderService);
|
|
144
|
+
|
|
145
|
+
// Dispose (calls @PreDestroy hooks)
|
|
146
|
+
await container.dispose();
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### ContainerOptions
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
interface ContainerOptions {
|
|
153
|
+
parent?: Container; // hierarchical containers
|
|
154
|
+
autoRegister?: boolean; // default false
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Provider types
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
type Provider =
|
|
162
|
+
| ClassProvider // { useClass: Constructor, scope? }
|
|
163
|
+
| ValueProvider // { useValue: any }
|
|
164
|
+
| FactoryProvider // { useFactory: (ctx) => any, scope? }
|
|
165
|
+
| ExistingProvider; // { useExisting: Token }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Scopes
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { Scope } from "@theokit/di";
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| Scope | Behavior |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `Scope.SINGLETON` | One instance per container (default). |
|
|
177
|
+
| `Scope.TRANSIENT` | New instance on every resolve. |
|
|
178
|
+
| `Scope.REQUEST` | One instance per request scope (via `container.createScope()`). |
|
|
179
|
+
|
|
180
|
+
Request scope example:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const requestContainer = container.createScope();
|
|
184
|
+
const handler = requestContainer.resolve(RequestHandler);
|
|
185
|
+
// All REQUEST-scoped deps share the same instance within this scope
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## @Module
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { Module } from "@theokit/di";
|
|
192
|
+
|
|
193
|
+
@Module({
|
|
194
|
+
providers: [UserRepository, OrderService],
|
|
195
|
+
imports: [DatabaseModule],
|
|
196
|
+
exports: [UserRepository],
|
|
197
|
+
})
|
|
198
|
+
class UserModule {}
|
|
199
|
+
|
|
200
|
+
// Load module into container
|
|
201
|
+
container.loadModule(UserModule);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`ModuleMetadata`:
|
|
205
|
+
|
|
206
|
+
| Field | Type | Description |
|
|
207
|
+
|---|---|---|
|
|
208
|
+
| `providers` | `Provider[]` | Classes/providers registered in this module. |
|
|
209
|
+
| `imports` | `Module[]` | Other modules whose exports become available. |
|
|
210
|
+
| `exports` | `Token[]` | Tokens visible to importing modules. |
|
|
211
|
+
|
|
212
|
+
## Errors
|
|
213
|
+
|
|
214
|
+
| Error | Cause |
|
|
215
|
+
|---|---|
|
|
216
|
+
| `TokenNotFoundError` | Token not registered and not `@Optional`. |
|
|
217
|
+
| `CyclicDependencyError` | Circular dependency detected in resolution graph. |
|
|
218
|
+
| `MissingInjectableError` | Class used as dependency without `@Injectable`. |
|
|
219
|
+
| `ScopeViolationError` | Singleton depends on transient/request-scoped dep. |
|
|
220
|
+
| `ContainerDisposedError` | Resolve called after `container.dispose()`. |
|
|
221
|
+
| `ContainerFrozenError` | Register called after container is frozen. |
|
|
222
|
+
| `AsyncProviderInSyncResolveError` | Async factory used with `resolve()` instead of `resolveAsync()`. |
|
|
223
|
+
| `ReflectMetadataMissingError` | `reflect-metadata` polyfill not imported. |
|
|
224
|
+
| `CyclicModuleImportError` | Circular module imports detected. |
|
|
225
|
+
| `InvalidModuleError` | Module class missing `@Module` decorator. |
|
|
226
|
+
| `InvalidExportError` | Module exports a token not in its providers. |
|
|
227
|
+
|
|
228
|
+
## Graph analysis
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const graph: DependencyGraph = container.analyzeGraph();
|
|
232
|
+
// Useful for debugging dependency chains and detecting issues
|
|
233
|
+
```
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
---
|
|
2
|
+
user-invocable: false
|
|
3
|
+
description: All 15 agentic decorators from @theokit/di-agent for tools, workflows, evals, cron, and more.
|
|
4
|
+
paths:
|
|
5
|
+
- "**/*decorator*"
|
|
6
|
+
- "**/*Decorator*"
|
|
7
|
+
- "**/di-agent*"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# TheoKit DI-Agent -- Agentic Decorators
|
|
11
|
+
|
|
12
|
+
Quick reference for `@theokit/di-agent` -- 15 decorators that wire agentic capabilities into DI-managed classes.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @theokit/di-agent @theokit/di @theokit/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires `reflect-metadata` and TypeScript decorator support (see `@theokit/di` docs).
|
|
21
|
+
|
|
22
|
+
## createAgentProvider
|
|
23
|
+
|
|
24
|
+
Bridges `@theokit/di` container with `@theokit/sdk` Agent. Reads decorator metadata from all registered classes and wires tools, workflows, evals, cron jobs, etc.
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Container } from "@theokit/di";
|
|
28
|
+
import { createAgentProvider } from "@theokit/di-agent";
|
|
29
|
+
|
|
30
|
+
const container = new Container();
|
|
31
|
+
container.register(MyToolService);
|
|
32
|
+
container.register(MyWorkflowService);
|
|
33
|
+
|
|
34
|
+
const { agent, dispose } = await createAgentProvider(container, {
|
|
35
|
+
apiKey: process.env.THEOKIT_API_KEY!,
|
|
36
|
+
model: { id: "google/gemini-2.0-flash-001" },
|
|
37
|
+
local: { cwd: process.cwd() },
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## @Tool
|
|
42
|
+
|
|
43
|
+
Registers a method as a custom tool exposed to the LLM.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { Injectable } from "@theokit/di";
|
|
47
|
+
import { Tool } from "@theokit/di-agent";
|
|
48
|
+
import { z } from "zod";
|
|
49
|
+
|
|
50
|
+
@Injectable()
|
|
51
|
+
class MathService {
|
|
52
|
+
@Tool({
|
|
53
|
+
name: "calculate",
|
|
54
|
+
description: "Evaluate a math expression.",
|
|
55
|
+
inputSchema: z.object({ expression: z.string() }),
|
|
56
|
+
})
|
|
57
|
+
calculate(input: { expression: string }): string {
|
|
58
|
+
return String(eval(input.expression));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## @Workflow
|
|
64
|
+
|
|
65
|
+
Marks a method as a workflow step definition.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { Workflow } from "@theokit/di-agent";
|
|
69
|
+
|
|
70
|
+
@Injectable()
|
|
71
|
+
class PipelineService {
|
|
72
|
+
@Workflow({ name: "data-pipeline", description: "ETL workflow." })
|
|
73
|
+
async run(input: { source: string }) {
|
|
74
|
+
// workflow implementation
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## @EvalDecorator
|
|
80
|
+
|
|
81
|
+
Registers an eval suite on a method.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { EvalDecorator } from "@theokit/di-agent";
|
|
85
|
+
|
|
86
|
+
@Injectable()
|
|
87
|
+
class QAService {
|
|
88
|
+
@EvalDecorator({
|
|
89
|
+
name: "qa-smoke",
|
|
90
|
+
dataset: [{ input: "Say ok.", expected: "ok" }],
|
|
91
|
+
})
|
|
92
|
+
async evaluate() { /* ... */ }
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## @Cron
|
|
97
|
+
|
|
98
|
+
Registers a cron-scheduled agent task.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { Cron } from "@theokit/di-agent";
|
|
102
|
+
|
|
103
|
+
@Injectable()
|
|
104
|
+
class ReportService {
|
|
105
|
+
@Cron({
|
|
106
|
+
expression: "0 9 * * *",
|
|
107
|
+
timezone: "America/Sao_Paulo",
|
|
108
|
+
message: "Summarize yesterday's commits.",
|
|
109
|
+
})
|
|
110
|
+
async dailyReport() { /* ... */ }
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## @Subscription
|
|
115
|
+
|
|
116
|
+
Marks a method as a real-time subscription handler.
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { Subscription } from "@theokit/di-agent";
|
|
120
|
+
|
|
121
|
+
@Injectable()
|
|
122
|
+
class EventService {
|
|
123
|
+
@Subscription({ topic: "orders.created", description: "Handle new orders." })
|
|
124
|
+
async onOrder(event: unknown) { /* ... */ }
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## @Auth
|
|
129
|
+
|
|
130
|
+
Registers authentication/authorization logic for agent operations.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { Auth } from "@theokit/di-agent";
|
|
134
|
+
|
|
135
|
+
@Injectable()
|
|
136
|
+
class SecurityService {
|
|
137
|
+
@Auth({ strategy: "bearer", description: "JWT validation." })
|
|
138
|
+
async validate(token: string): Promise<boolean> { /* ... */ }
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## @Retriever
|
|
143
|
+
|
|
144
|
+
Registers a retrieval method for RAG pipelines.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { Retriever } from "@theokit/di-agent";
|
|
148
|
+
|
|
149
|
+
@Injectable()
|
|
150
|
+
class SearchService {
|
|
151
|
+
@Retriever({ name: "docs-search", description: "Search documentation." })
|
|
152
|
+
async search(query: string) { /* ... */ }
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## @Reranker
|
|
157
|
+
|
|
158
|
+
Registers a reranking method for RAG pipelines.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { Reranker } from "@theokit/di-agent";
|
|
162
|
+
|
|
163
|
+
@Injectable()
|
|
164
|
+
class RankService {
|
|
165
|
+
@Reranker({ name: "cohere-reranker", model: "rerank-v3.5" })
|
|
166
|
+
async rerank(query: string, docs: unknown[]) { /* ... */ }
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## @TextSplitter
|
|
171
|
+
|
|
172
|
+
Registers a text splitting strategy.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { TextSplitter } from "@theokit/di-agent";
|
|
176
|
+
|
|
177
|
+
@Injectable()
|
|
178
|
+
class SplitterService {
|
|
179
|
+
@TextSplitter({ strategy: "recursive", chunkSize: 1000, overlap: 100 })
|
|
180
|
+
split(text: string) { /* ... */ }
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## @UseSandbox
|
|
185
|
+
|
|
186
|
+
Marks a class or method for sandboxed execution.
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { UseSandbox } from "@theokit/di-agent";
|
|
190
|
+
|
|
191
|
+
@Injectable()
|
|
192
|
+
class CodeRunner {
|
|
193
|
+
@UseSandbox({ enabled: true })
|
|
194
|
+
async execute(code: string) { /* ... */ }
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## @SubAgent
|
|
199
|
+
|
|
200
|
+
Declares a subagent definition on a method.
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { SubAgent } from "@theokit/di-agent";
|
|
204
|
+
|
|
205
|
+
@Injectable()
|
|
206
|
+
class AgentOrchestrator {
|
|
207
|
+
@SubAgent({
|
|
208
|
+
name: "code-reviewer",
|
|
209
|
+
description: "Expert code reviewer.",
|
|
210
|
+
prompt: "Review for bugs and security issues.",
|
|
211
|
+
})
|
|
212
|
+
async review() { /* ... */ }
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## @Hitl (Human-in-the-Loop)
|
|
217
|
+
|
|
218
|
+
Marks a method as requiring human approval before proceeding.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { Hitl } from "@theokit/di-agent";
|
|
222
|
+
|
|
223
|
+
@Injectable()
|
|
224
|
+
class ApprovalService {
|
|
225
|
+
@Hitl({ description: "Requires manager approval.", timeout: 3600_000 })
|
|
226
|
+
async approve(request: unknown) { /* ... */ }
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## @AutoSummarize
|
|
231
|
+
|
|
232
|
+
Enables automatic conversation summarization.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { AutoSummarize } from "@theokit/di-agent";
|
|
236
|
+
|
|
237
|
+
@Injectable()
|
|
238
|
+
class ChatService {
|
|
239
|
+
@AutoSummarize({ maxTurns: 20, strategy: "rolling" })
|
|
240
|
+
async chat() { /* ... */ }
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## @InjectAgent
|
|
245
|
+
|
|
246
|
+
Injects the current `SDKAgent` instance into a class.
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { Injectable } from "@theokit/di";
|
|
250
|
+
import { InjectAgent } from "@theokit/di-agent";
|
|
251
|
+
import type { SDKAgent } from "@theokit/sdk";
|
|
252
|
+
|
|
253
|
+
@Injectable()
|
|
254
|
+
class AgentAwareService {
|
|
255
|
+
constructor(@InjectAgent() private readonly agent: SDKAgent) {}
|
|
256
|
+
|
|
257
|
+
async doWork() {
|
|
258
|
+
const run = await this.agent.send("Do something");
|
|
259
|
+
await run.wait();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## @MemoryScopeDecorator
|
|
265
|
+
|
|
266
|
+
Configures memory scope for a class.
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
import { MemoryScopeDecorator } from "@theokit/di-agent";
|
|
270
|
+
|
|
271
|
+
@Injectable()
|
|
272
|
+
@MemoryScopeDecorator({ namespace: "billing", scope: "user" })
|
|
273
|
+
class BillingService { /* ... */ }
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Reading metadata (for framework authors)
|
|
277
|
+
|
|
278
|
+
Each decorator has a companion reader function:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { readToolMetadata } from "@theokit/di-agent";
|
|
282
|
+
import { readWorkflowMetadata } from "@theokit/di-agent";
|
|
283
|
+
import { readCronMetadata } from "@theokit/di-agent";
|
|
284
|
+
// ... readEvalDecoratorMetadata, readRetrieverMetadata, etc.
|
|
285
|
+
|
|
286
|
+
const tools = readToolMetadata(MyToolService);
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## AGENT_TOKEN
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import { AGENT_TOKEN } from "@theokit/di-agent";
|
|
293
|
+
// Symbol token for agent injection in the DI container
|
|
294
|
+
```
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
---
|
|
2
|
+
user-invocable: false
|
|
3
|
+
paths:
|
|
4
|
+
- "**/*error*"
|
|
5
|
+
- "**/*Error*"
|
|
6
|
+
- "**/*exception*"
|
|
7
|
+
description: TheoKit SDK error hierarchy — TheokitAgentError, error codes, retry patterns
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# TheoKit Error Handling
|
|
11
|
+
|
|
12
|
+
All SDK errors extend `TheokitAgentError`. Use `isRetryable` to drive
|
|
13
|
+
retry/backoff logic without coupling to specific subclasses.
|
|
14
|
+
|
|
15
|
+
## Error hierarchy
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Error
|
|
19
|
+
+-- TheokitAgentError
|
|
20
|
+
| +-- AuthenticationError
|
|
21
|
+
| +-- RateLimitError
|
|
22
|
+
| +-- ConfigurationError
|
|
23
|
+
| | +-- IntegrationNotConnectedError
|
|
24
|
+
| +-- NetworkError
|
|
25
|
+
| +-- UnknownAgentError
|
|
26
|
+
|
|
|
27
|
+
+-- UnsupportedRunOperationError (separate hierarchy)
|
|
28
|
+
+-- AgentRunError (thrown by Agent.prompt with throwOnError)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Error reference
|
|
32
|
+
|
|
33
|
+
| Error | When | `isRetryable` |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `AuthenticationError` | Invalid API key, not logged in, insufficient permissions | `false` |
|
|
36
|
+
| `RateLimitError` | Too many requests or usage limits exceeded | `true` |
|
|
37
|
+
| `ConfigurationError` | Invalid model, bad request parameters, malformed options | `false` |
|
|
38
|
+
| `IntegrationNotConnectedError` | Cloud agent for a repo whose SCM is not connected | `false` |
|
|
39
|
+
| `NetworkError` | Service unavailable, timeout, transport failure | `true` |
|
|
40
|
+
| `UnknownAgentError` | Catch-all for unclassified errors | `false` |
|
|
41
|
+
| `UnsupportedRunOperationError` | Runtime does not support a `Run` operation | n/a |
|
|
42
|
+
| `AgentRunError` | Run finished with error status (only with `throwOnError: true`) | n/a |
|
|
43
|
+
|
|
44
|
+
## `TheokitAgentError` properties
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
class TheokitAgentError extends Error {
|
|
48
|
+
readonly isRetryable: boolean;
|
|
49
|
+
readonly code?: string;
|
|
50
|
+
readonly protoErrorCode?: string;
|
|
51
|
+
readonly cause?: unknown;
|
|
52
|
+
readonly metadata?: ErrorMetadata; // v1.3+ provider HTTP errors
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## `ErrorMetadata` (v1.3+)
|
|
57
|
+
|
|
58
|
+
When an error originates from a provider HTTP call:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
interface ErrorMetadata {
|
|
62
|
+
provider: string; // "anthropic" | "openai" | "openrouter" | ...
|
|
63
|
+
endpoint: string; // "/v1/messages" | "/v1/chat/completions"
|
|
64
|
+
code: ErrorCode;
|
|
65
|
+
statusCode?: number;
|
|
66
|
+
retryAfter?: number; // seconds
|
|
67
|
+
raw?: unknown; // raw response body (truncated ~2KB)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type ErrorCode =
|
|
71
|
+
| "rate_limit" | "auth_failed" | "invalid_request"
|
|
72
|
+
| "timeout" | "server_error" | "context_too_long"
|
|
73
|
+
| "content_filtered" | "model_unavailable"
|
|
74
|
+
| "network" | "unknown";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Retry pattern
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { TheokitAgentError, type Run } from "@theokit/sdk";
|
|
81
|
+
|
|
82
|
+
async function withRetry(send: () => Promise<Run>, attempts = 3): Promise<Run> {
|
|
83
|
+
let lastError: unknown;
|
|
84
|
+
for (let i = 0; i < attempts; i++) {
|
|
85
|
+
try {
|
|
86
|
+
return await send();
|
|
87
|
+
} catch (err) {
|
|
88
|
+
lastError = err;
|
|
89
|
+
if (err instanceof TheokitAgentError && err.isRetryable) {
|
|
90
|
+
await new Promise((r) => setTimeout(r, 2 ** i * 1000));
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw lastError;
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Using metadata for programmatic handling
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
try {
|
|
104
|
+
await agent.send("...");
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof TheokitAgentError && err.metadata) {
|
|
107
|
+
switch (err.metadata.code) {
|
|
108
|
+
case "rate_limit":
|
|
109
|
+
await wait(err.metadata.retryAfter ?? 60);
|
|
110
|
+
return retry();
|
|
111
|
+
case "auth_failed":
|
|
112
|
+
throw new Error(`Check API key for ${err.metadata.provider}`);
|
|
113
|
+
case "context_too_long":
|
|
114
|
+
// trigger prompt compression
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## `IntegrationNotConnectedError`
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { IntegrationNotConnectedError } from "@theokit/sdk/errors";
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
await Agent.create({ /* cloud with disconnected repo */ });
|
|
129
|
+
} catch (err) {
|
|
130
|
+
if (err instanceof IntegrationNotConnectedError) {
|
|
131
|
+
console.error(`Connect ${err.provider} at ${err.helpUrl}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## `UnsupportedRunOperationError`
|
|
137
|
+
|
|
138
|
+
Check before calling runtime-dependent operations:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
if (run.supports("conversation")) {
|
|
142
|
+
const turns = await run.conversation();
|
|
143
|
+
} else {
|
|
144
|
+
console.log(run.unsupportedReason("conversation"));
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Tree-shaking
|
|
149
|
+
|
|
150
|
+
Import error classes from the `/errors` subpath to avoid pulling the full SDK:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { TheokitAgentError, RateLimitError } from "@theokit/sdk/errors";
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## `throwOnError` on `Agent.prompt`
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { Agent, AgentRunError } from "@theokit/sdk";
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const result = await Agent.prompt("hi", {
|
|
163
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
164
|
+
model: { id: "claude-sonnet-4-5-20250929" },
|
|
165
|
+
throwOnError: true,
|
|
166
|
+
});
|
|
167
|
+
} catch (err) {
|
|
168
|
+
if (err instanceof AgentRunError && err.code === "auth_failed") {
|
|
169
|
+
// bad API key
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|