@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,823 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-leaf — primitives shared between `agent.ts`, `run.ts`, and
|
|
3
|
+
* `messages.ts`. Extracted to break LOW type-only cycles #5 and #7
|
|
4
|
+
* (audit `architecture-output/final_report.md`) per plan
|
|
5
|
+
* arch-review-fixes-2026-06-06 § Phase 4 / T4.1 (D438).
|
|
6
|
+
*
|
|
7
|
+
* Public surface unchanged — `types/agent.ts` re-exports these from this
|
|
8
|
+
* leaf so `import type { ModelSelection, CustomTool } from "@theokit/sdk"`
|
|
9
|
+
* keeps resolving.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* One slot in a {@link ModelSelection.params} array.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface ModelParameterValue {
|
|
19
|
+
id: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Identifies a model plus optional per-model parameters (e.g. reasoning effort).
|
|
24
|
+
*
|
|
25
|
+
* Use `Theokit.models.list()` to discover valid ids and parameter definitions.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
interface ModelSelection {
|
|
30
|
+
id: string;
|
|
31
|
+
params?: ModelParameterValue[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Local function tool declared per-agent via {@link AgentOptions.tools}. The
|
|
35
|
+
* handler runs in-process; no MCP server is involved. The SDK serializes
|
|
36
|
+
* `name`, `description`, and `inputSchema` into the model's tool catalog.
|
|
37
|
+
*
|
|
38
|
+
* Handlers MUST be re-passed on `Agent.resume()` because closures cannot be
|
|
39
|
+
* persisted. The tool catalog (name + description + schema) is NOT serialized.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
interface CustomTool {
|
|
44
|
+
/**
|
|
45
|
+
* Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`
|
|
46
|
+
* and must not collide with `shell`, `memory_search`, `memory_get`, or any
|
|
47
|
+
* `mcp_*` prefix (reserved for the SDK's built-in tools).
|
|
48
|
+
*/
|
|
49
|
+
name: string;
|
|
50
|
+
/** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
|
|
51
|
+
description: string;
|
|
52
|
+
/** JSON Schema (Draft-7 subset) describing the `input` argument. Must be `type: "object"`. */
|
|
53
|
+
inputSchema: Record<string, unknown>;
|
|
54
|
+
/**
|
|
55
|
+
* Local handler invoked when the model emits `tool_use` for this tool.
|
|
56
|
+
* Returns a string (becomes the `tool_result.content` surfaced back to the
|
|
57
|
+
* model). Throws → SDK converts to `tool_result` with `isError: true` and
|
|
58
|
+
* the error `message` as content.
|
|
59
|
+
*/
|
|
60
|
+
handler: (input: Record<string, unknown>) => string | Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Type-leaf — base message types shared between `conversation.ts` and
|
|
65
|
+
* `updates.ts`. Extracted to break LOW type-only cycle #6 (audit
|
|
66
|
+
* `architecture-output/final_report.md`) per plan arch-review-fixes-2026-06-06
|
|
67
|
+
* § Phase 4 / T4.1 (D438).
|
|
68
|
+
*
|
|
69
|
+
* Public surface unchanged — `types/conversation.ts` re-exports `UserMessage`
|
|
70
|
+
* from this leaf so `import type { UserMessage } from "@theokit/sdk"` keeps
|
|
71
|
+
* resolving.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* User-authored message in a conversation history.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
interface UserMessage {
|
|
81
|
+
text: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Single tool call event. The internal `args` and `result` shapes are NOT stable.
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
interface ToolCall {
|
|
90
|
+
callId: string;
|
|
91
|
+
name: string;
|
|
92
|
+
args?: unknown;
|
|
93
|
+
result?: unknown;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Incremental text token from the assistant.
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
interface TextDeltaUpdate {
|
|
101
|
+
type: "text-delta";
|
|
102
|
+
text: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Incremental reasoning token.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
interface ThinkingDeltaUpdate {
|
|
110
|
+
type: "thinking-delta";
|
|
111
|
+
text: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Emitted when a reasoning block completes.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
interface ThinkingCompletedUpdate {
|
|
119
|
+
type: "thinking-completed";
|
|
120
|
+
thinkingDurationMs: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Tool call started — args committed.
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
interface ToolCallStartedUpdate {
|
|
128
|
+
type: "tool-call-started";
|
|
129
|
+
callId: string;
|
|
130
|
+
toolCall: ToolCall;
|
|
131
|
+
modelCallId: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Tool call arguments streaming in incrementally.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
interface PartialToolCallUpdate {
|
|
139
|
+
type: "partial-tool-call";
|
|
140
|
+
callId: string;
|
|
141
|
+
toolCall: ToolCall;
|
|
142
|
+
modelCallId: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Tool call completed.
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
interface ToolCallCompletedUpdate {
|
|
150
|
+
type: "tool-call-completed";
|
|
151
|
+
callId: string;
|
|
152
|
+
toolCall: ToolCall;
|
|
153
|
+
modelCallId: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Token count delta for usage tracking.
|
|
157
|
+
*
|
|
158
|
+
* @public
|
|
159
|
+
*/
|
|
160
|
+
interface TokenDeltaUpdate {
|
|
161
|
+
type: "token-delta";
|
|
162
|
+
tokens: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Conversation step started.
|
|
166
|
+
*
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
interface StepStartedUpdate {
|
|
170
|
+
type: "step-started";
|
|
171
|
+
stepId: number;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Conversation step completed.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
interface StepCompletedUpdate {
|
|
179
|
+
type: "step-completed";
|
|
180
|
+
stepId: number;
|
|
181
|
+
stepDurationMs: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Turn ended with usage summary.
|
|
185
|
+
*
|
|
186
|
+
* @public
|
|
187
|
+
*/
|
|
188
|
+
interface TurnEndedUpdate {
|
|
189
|
+
type: "turn-ended";
|
|
190
|
+
usage?: {
|
|
191
|
+
inputTokens: number;
|
|
192
|
+
outputTokens: number;
|
|
193
|
+
cacheReadTokens: number;
|
|
194
|
+
cacheWriteTokens: number;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* User message appended to the conversation.
|
|
199
|
+
*
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
interface UserMessageAppendedUpdate {
|
|
203
|
+
type: "user-message-appended";
|
|
204
|
+
userMessage: UserMessage;
|
|
205
|
+
}
|
|
206
|
+
/** @public */
|
|
207
|
+
interface SummaryUpdate {
|
|
208
|
+
type: "summary";
|
|
209
|
+
summary: string;
|
|
210
|
+
}
|
|
211
|
+
/** @public */
|
|
212
|
+
interface SummaryStartedUpdate {
|
|
213
|
+
type: "summary-started";
|
|
214
|
+
}
|
|
215
|
+
/** @public */
|
|
216
|
+
interface SummaryCompletedUpdate {
|
|
217
|
+
type: "summary-completed";
|
|
218
|
+
}
|
|
219
|
+
/** @public */
|
|
220
|
+
interface ShellOutputDeltaUpdate {
|
|
221
|
+
type: "shell-output-delta";
|
|
222
|
+
event: Record<string, unknown>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Lowest-level raw update from a run. Pass `onDelta` to `agent.send()` to
|
|
226
|
+
* consume these. Finer-grained than `SDKMessage` events.
|
|
227
|
+
*
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
type InteractionUpdate = TextDeltaUpdate | ThinkingDeltaUpdate | ThinkingCompletedUpdate | ToolCallStartedUpdate | ToolCallCompletedUpdate | PartialToolCallUpdate | TokenDeltaUpdate | StepStartedUpdate | StepCompletedUpdate | TurnEndedUpdate | UserMessageAppendedUpdate | SummaryUpdate | SummaryStartedUpdate | SummaryCompletedUpdate | ShellOutputDeltaUpdate;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Plain assistant message in a conversation history.
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
interface AssistantMessage {
|
|
238
|
+
text: string;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Reasoning step in a conversation history.
|
|
242
|
+
*
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
interface ThinkingMessage {
|
|
246
|
+
text: string;
|
|
247
|
+
thinkingDurationMs?: number;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Shell command executed during a run.
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
interface ShellCommand {
|
|
255
|
+
command: string;
|
|
256
|
+
workingDirectory?: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Output of a shell command.
|
|
260
|
+
*
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
interface ShellOutput {
|
|
264
|
+
stdout: string;
|
|
265
|
+
stderr: string;
|
|
266
|
+
exitCode: number;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Single step inside an agent turn.
|
|
270
|
+
*
|
|
271
|
+
* @public
|
|
272
|
+
*/
|
|
273
|
+
/**
|
|
274
|
+
* Result of a tool invocation. Pairs with the preceding `toolCall` step
|
|
275
|
+
* by `callId`. `isError: true` when the tool returned a failure result.
|
|
276
|
+
*
|
|
277
|
+
* T2.3 — added so `Run.conversation()` surfaces the full interaction
|
|
278
|
+
* including tool results (parity with OpenAI Agents `RunResult.new_items`).
|
|
279
|
+
*
|
|
280
|
+
* @public
|
|
281
|
+
*/
|
|
282
|
+
interface ToolResult {
|
|
283
|
+
callId: string;
|
|
284
|
+
name: string;
|
|
285
|
+
result: string;
|
|
286
|
+
isError: boolean;
|
|
287
|
+
}
|
|
288
|
+
type ConversationStep = {
|
|
289
|
+
type: "assistantMessage";
|
|
290
|
+
message: AssistantMessage;
|
|
291
|
+
} | {
|
|
292
|
+
type: "toolCall";
|
|
293
|
+
message: ToolCall;
|
|
294
|
+
} | {
|
|
295
|
+
type: "toolResult";
|
|
296
|
+
message: ToolResult;
|
|
297
|
+
} | {
|
|
298
|
+
type: "thinkingMessage";
|
|
299
|
+
message: ThinkingMessage;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Agent turn: user message + assistant/tool/thinking steps.
|
|
303
|
+
*
|
|
304
|
+
* @public
|
|
305
|
+
*/
|
|
306
|
+
interface AgentConversationTurn {
|
|
307
|
+
userMessage?: UserMessage;
|
|
308
|
+
steps: ConversationStep[];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Shell turn: a command and its output.
|
|
312
|
+
*
|
|
313
|
+
* @public
|
|
314
|
+
*/
|
|
315
|
+
interface ShellConversationTurn {
|
|
316
|
+
shellCommand?: ShellCommand;
|
|
317
|
+
shellOutput?: ShellOutput;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Structured per-turn view of a run.
|
|
321
|
+
*
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
type ConversationTurn = {
|
|
325
|
+
type: "agentConversationTurn";
|
|
326
|
+
turn: AgentConversationTurn;
|
|
327
|
+
} | {
|
|
328
|
+
type: "shellConversationTurn";
|
|
329
|
+
turn: ShellConversationTurn;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* MCP server configuration accepted by `Agent.create()` and `agent.send()`.
|
|
334
|
+
*
|
|
335
|
+
* @public
|
|
336
|
+
*/
|
|
337
|
+
type McpStdioServerConfig = {
|
|
338
|
+
type?: "stdio";
|
|
339
|
+
command: string;
|
|
340
|
+
args?: string[];
|
|
341
|
+
env?: Record<string, string>;
|
|
342
|
+
/** Local agents only. Cloud rejects this field. */
|
|
343
|
+
cwd?: string;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* OAuth-style auth bundle for HTTP/SSE MCP servers.
|
|
347
|
+
*
|
|
348
|
+
* @public
|
|
349
|
+
*/
|
|
350
|
+
interface McpAuthConfig {
|
|
351
|
+
CLIENT_ID: string;
|
|
352
|
+
CLIENT_SECRET?: string;
|
|
353
|
+
scopes?: string[];
|
|
354
|
+
/**
|
|
355
|
+
* OAuth 2.1 PKCE flow configuration (ADR D41, v1.2+). When present, the
|
|
356
|
+
* SDK runs the PKCE flow on first use and stores tokens via keychain or
|
|
357
|
+
* file. Without this, the SDK relies on `CLIENT_SECRET` + manual headers.
|
|
358
|
+
*/
|
|
359
|
+
oauth?: McpOAuthConfig;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* OAuth 2.1 PKCE flow descriptor. See ADR D41.
|
|
363
|
+
*
|
|
364
|
+
* @public
|
|
365
|
+
*/
|
|
366
|
+
interface McpOAuthConfig {
|
|
367
|
+
/** Authorization endpoint (e.g. https://api.notion.com/v1/oauth/authorize). */
|
|
368
|
+
authorizationEndpoint: string;
|
|
369
|
+
/** Token endpoint (e.g. https://api.notion.com/v1/oauth/token). */
|
|
370
|
+
tokenEndpoint: string;
|
|
371
|
+
/** Where the OAuth `code` is received. */
|
|
372
|
+
redirectMode: "manual" | "localhost";
|
|
373
|
+
/** Localhost callback port (0 = random free port, default). */
|
|
374
|
+
localhostPort?: number;
|
|
375
|
+
/** Flow timeout in ms (default 300_000 = 5min). */
|
|
376
|
+
timeoutMs?: number;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* HTTP or SSE MCP server.
|
|
380
|
+
*
|
|
381
|
+
* @public
|
|
382
|
+
*/
|
|
383
|
+
type McpHttpServerConfig = {
|
|
384
|
+
type?: "http" | "sse";
|
|
385
|
+
url: string;
|
|
386
|
+
/** Passed through. `Authorization` works here. */
|
|
387
|
+
headers?: Record<string, string>;
|
|
388
|
+
auth?: McpAuthConfig;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Union of MCP server configs. See `docs.md` for the full reference.
|
|
392
|
+
*
|
|
393
|
+
* @public
|
|
394
|
+
*/
|
|
395
|
+
type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Plain text content block emitted by the assistant or user.
|
|
399
|
+
*
|
|
400
|
+
* @public
|
|
401
|
+
*/
|
|
402
|
+
interface TextBlock {
|
|
403
|
+
type: "text";
|
|
404
|
+
text: string;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Tool invocation block emitted by the assistant.
|
|
408
|
+
*
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
411
|
+
interface ToolUseBlock {
|
|
412
|
+
type: "tool_use";
|
|
413
|
+
id: string;
|
|
414
|
+
name: string;
|
|
415
|
+
/** Tool args are not part of the stable schema. Treat as unknown and parse defensively. */
|
|
416
|
+
input: unknown;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Init metadata. Emitted once at the start of a run.
|
|
420
|
+
*
|
|
421
|
+
* @public
|
|
422
|
+
*/
|
|
423
|
+
interface SDKSystemMessage {
|
|
424
|
+
type: "system";
|
|
425
|
+
subtype?: "init";
|
|
426
|
+
agent_id: string;
|
|
427
|
+
run_id: string;
|
|
428
|
+
model?: ModelSelection;
|
|
429
|
+
tools?: string[];
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Echo of the user prompt for this run.
|
|
433
|
+
*
|
|
434
|
+
* @public
|
|
435
|
+
*/
|
|
436
|
+
interface SDKUserMessageEvent {
|
|
437
|
+
type: "user";
|
|
438
|
+
agent_id: string;
|
|
439
|
+
run_id: string;
|
|
440
|
+
message: {
|
|
441
|
+
role: "user";
|
|
442
|
+
content: TextBlock[];
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Model text output for this run.
|
|
447
|
+
*
|
|
448
|
+
* @public
|
|
449
|
+
*/
|
|
450
|
+
interface SDKAssistantMessage {
|
|
451
|
+
type: "assistant";
|
|
452
|
+
agent_id: string;
|
|
453
|
+
run_id: string;
|
|
454
|
+
message: {
|
|
455
|
+
role: "assistant";
|
|
456
|
+
content: Array<TextBlock | ToolUseBlock>;
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Reasoning content.
|
|
461
|
+
*
|
|
462
|
+
* @public
|
|
463
|
+
*/
|
|
464
|
+
interface SDKThinkingMessage {
|
|
465
|
+
type: "thinking";
|
|
466
|
+
agent_id: string;
|
|
467
|
+
run_id: string;
|
|
468
|
+
text: string;
|
|
469
|
+
thinking_duration_ms?: number;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Tool invocation lifecycle event. Emitted at start with `args`, then again on
|
|
473
|
+
* completion with `result`.
|
|
474
|
+
*
|
|
475
|
+
* Tool `args` and `result` are NOT part of the stable schema — treat as unknown.
|
|
476
|
+
*
|
|
477
|
+
* @public
|
|
478
|
+
*/
|
|
479
|
+
interface SDKToolUseMessage {
|
|
480
|
+
type: "tool_call";
|
|
481
|
+
agent_id: string;
|
|
482
|
+
run_id: string;
|
|
483
|
+
call_id: string;
|
|
484
|
+
name: string;
|
|
485
|
+
status: "running" | "completed" | "error";
|
|
486
|
+
args?: unknown;
|
|
487
|
+
result?: unknown;
|
|
488
|
+
truncated?: {
|
|
489
|
+
args?: boolean;
|
|
490
|
+
result?: boolean;
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Cloud run lifecycle transitions.
|
|
495
|
+
*
|
|
496
|
+
* @public
|
|
497
|
+
*/
|
|
498
|
+
interface SDKStatusMessage {
|
|
499
|
+
type: "status";
|
|
500
|
+
agent_id: string;
|
|
501
|
+
run_id: string;
|
|
502
|
+
status: "CREATING" | "RUNNING" | "FINISHED" | "ERROR" | "CANCELLED" | "EXPIRED";
|
|
503
|
+
message?: string;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Task-level milestones and summaries.
|
|
507
|
+
*
|
|
508
|
+
* @public
|
|
509
|
+
*/
|
|
510
|
+
interface SDKTaskMessage {
|
|
511
|
+
type: "task";
|
|
512
|
+
agent_id: string;
|
|
513
|
+
run_id: string;
|
|
514
|
+
status?: string;
|
|
515
|
+
text?: string;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Awaiting user input or approval.
|
|
519
|
+
*
|
|
520
|
+
* @public
|
|
521
|
+
*/
|
|
522
|
+
interface SDKRequestMessage {
|
|
523
|
+
type: "request";
|
|
524
|
+
agent_id: string;
|
|
525
|
+
run_id: string;
|
|
526
|
+
request_id: string;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Partial object emitted during `Agent.streamObject<T>` streaming (ADR D45).
|
|
530
|
+
* `partial` is `DeepPartial<z.infer<T>>` at the typed iterator level but
|
|
531
|
+
* erased to `unknown` here because SDKMessage union is non-generic.
|
|
532
|
+
*
|
|
533
|
+
* @public
|
|
534
|
+
*/
|
|
535
|
+
interface SDKObjectDelta {
|
|
536
|
+
type: "object_delta";
|
|
537
|
+
agent_id: string;
|
|
538
|
+
run_id: string;
|
|
539
|
+
partial: unknown;
|
|
540
|
+
attempt: number;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Discriminated union of all stream events. Discriminate on `type`.
|
|
544
|
+
*
|
|
545
|
+
* All events include `agent_id` and `run_id`.
|
|
546
|
+
*
|
|
547
|
+
* @public
|
|
548
|
+
*/
|
|
549
|
+
type SDKMessage = SDKSystemMessage | SDKUserMessageEvent | SDKAssistantMessage | SDKThinkingMessage | SDKToolUseMessage | SDKStatusMessage | SDKTaskMessage | SDKRequestMessage | SDKObjectDelta;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Public type contract for token usage + cost tracking (ADRs D376-D379).
|
|
553
|
+
*
|
|
554
|
+
* Surfaces via `RunResult.usage` + `RunResult.cost` after every Run.
|
|
555
|
+
* Re-exported through the package barrel; consumers import from
|
|
556
|
+
* `@theokit/sdk`.
|
|
557
|
+
*
|
|
558
|
+
* @public
|
|
559
|
+
*/
|
|
560
|
+
/**
|
|
561
|
+
* Token usage observed during a Run. 5 closed buckets (D376) cover
|
|
562
|
+
* 100% of providers in 2026: OpenAI Chat / OpenAI Responses (o-series
|
|
563
|
+
* with reasoning) / Anthropic Messages (with prompt caching).
|
|
564
|
+
*
|
|
565
|
+
* `totalTokens` is derived (`inputTokens + outputTokens`); EC-10
|
|
566
|
+
* invariant: SDK must never emit `totalTokens !== inputTokens + outputTokens`.
|
|
567
|
+
*
|
|
568
|
+
* `requests[]` is the per-request breakdown (mirror openai-agents-python)
|
|
569
|
+
* — populated only when the run made > 1 LLM call.
|
|
570
|
+
*/
|
|
571
|
+
interface TokenUsage {
|
|
572
|
+
readonly inputTokens: number;
|
|
573
|
+
readonly outputTokens: number;
|
|
574
|
+
readonly cacheReadTokens?: number;
|
|
575
|
+
readonly cacheWriteTokens?: number;
|
|
576
|
+
readonly reasoningTokens?: number;
|
|
577
|
+
readonly totalTokens: number;
|
|
578
|
+
/** Per-request breakdown; absent when the run made a single LLM call. */
|
|
579
|
+
readonly requests?: ReadonlyArray<Omit<TokenUsage, "requests">>;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Cost confidence level (D377).
|
|
583
|
+
* - `actual`: returned by a provider billing API (e.g. OpenRouter `/generation`).
|
|
584
|
+
* - `estimated`: computed from bundled pricing snapshot.
|
|
585
|
+
* - `included`: subscription-included route (Codex CLI, Claude Pro).
|
|
586
|
+
* - `unknown`: pricing data unavailable; `amountUsd` is undefined.
|
|
587
|
+
*/
|
|
588
|
+
type CostStatus = "actual" | "estimated" | "included" | "unknown";
|
|
589
|
+
/** Source of the cost figure for caller-side audit. */
|
|
590
|
+
type CostSource = "openrouter_api" | "litellm_snapshot" | "user_override" | "subscription_included" | "unknown";
|
|
591
|
+
/**
|
|
592
|
+
* Cost breakdown attached to `RunResult.cost`. When `status === "unknown"`,
|
|
593
|
+
* `amountUsd` is `undefined` — DO NOT default to 0 (mentira). UI exibe
|
|
594
|
+
* `n/a` para unknown, `~$1.23` para estimated, `$1.23` para actual.
|
|
595
|
+
*/
|
|
596
|
+
interface CostBreakdown {
|
|
597
|
+
readonly amountUsd: number | undefined;
|
|
598
|
+
readonly status: CostStatus;
|
|
599
|
+
readonly currency: "USD";
|
|
600
|
+
readonly source: CostSource;
|
|
601
|
+
readonly pricingVersion: string | undefined;
|
|
602
|
+
readonly notes?: ReadonlyArray<string>;
|
|
603
|
+
/** Per-bucket detail (in USD) for caller analytics. */
|
|
604
|
+
readonly detail?: {
|
|
605
|
+
readonly input?: number;
|
|
606
|
+
readonly output?: number;
|
|
607
|
+
readonly cacheRead?: number;
|
|
608
|
+
readonly cacheWrite?: number;
|
|
609
|
+
readonly reasoning?: number;
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Lifecycle status of a {@link Run}.
|
|
615
|
+
*
|
|
616
|
+
* @public
|
|
617
|
+
*/
|
|
618
|
+
type RunStatus = "running" | "finished" | "error" | "cancelled";
|
|
619
|
+
/**
|
|
620
|
+
* Operations that may or may not be supported on a given {@link Run}, or on
|
|
621
|
+
* its parent agent.
|
|
622
|
+
*
|
|
623
|
+
* Runtime-specific availability — query at runtime with `run.supports(op)` and
|
|
624
|
+
* read the human reason via `run.unsupportedReason(op)`.
|
|
625
|
+
*
|
|
626
|
+
* @public
|
|
627
|
+
*/
|
|
628
|
+
type RunOperation = "stream" | "wait" | "cancel" | "conversation" | "listArtifacts" | "downloadArtifact" | "runUntil" | "fork" | "usePersonality" | "workflow";
|
|
629
|
+
/**
|
|
630
|
+
* Git metadata attached to cloud runs.
|
|
631
|
+
*
|
|
632
|
+
* @public
|
|
633
|
+
*/
|
|
634
|
+
interface RunGitInfo {
|
|
635
|
+
branches: Array<{
|
|
636
|
+
repoUrl: string;
|
|
637
|
+
branch?: string;
|
|
638
|
+
prUrl?: string;
|
|
639
|
+
}>;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Terminal result of a {@link Run}.
|
|
643
|
+
*
|
|
644
|
+
* @public
|
|
645
|
+
*/
|
|
646
|
+
interface RunResult {
|
|
647
|
+
id: string;
|
|
648
|
+
status: "finished" | "error" | "cancelled";
|
|
649
|
+
result?: string;
|
|
650
|
+
model?: ModelSelection;
|
|
651
|
+
durationMs?: number;
|
|
652
|
+
git?: RunGitInfo;
|
|
653
|
+
/**
|
|
654
|
+
* Structured error detail, populated when `status === "error"`. Surfaces
|
|
655
|
+
* the diagnostic that emit-error-event pushes into the stream so callers
|
|
656
|
+
* that don't drain `run.stream()` still get the cause via `run.wait()`.
|
|
657
|
+
*
|
|
658
|
+
* For successful runs (`status: "finished"`) this is undefined.
|
|
659
|
+
*
|
|
660
|
+
* @public
|
|
661
|
+
*/
|
|
662
|
+
error?: RunErrorDetail;
|
|
663
|
+
/**
|
|
664
|
+
* Token usage observed for this run (ADR D376). Populated in every
|
|
665
|
+
* status where ≥1 LLM call completed — including partial-failure
|
|
666
|
+
* runs (EC-5). `undefined` only when zero LLM calls executed (e.g.,
|
|
667
|
+
* abort before send).
|
|
668
|
+
*
|
|
669
|
+
* @public
|
|
670
|
+
*/
|
|
671
|
+
usage?: TokenUsage;
|
|
672
|
+
/**
|
|
673
|
+
* Estimated/actual USD cost for this run (ADR D377). Always paired
|
|
674
|
+
* with `usage` when populated. `cost.status` tells caller how to
|
|
675
|
+
* trust the figure.
|
|
676
|
+
*
|
|
677
|
+
* @public
|
|
678
|
+
*/
|
|
679
|
+
cost?: CostBreakdown;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Structured error attached to a {@link RunResult} when the underlying run
|
|
683
|
+
* transitioned to `"error"` status. `message` is always present; `code` is
|
|
684
|
+
* a stable identifier suitable for branching (e.g. `"llm_4xx"`,
|
|
685
|
+
* `"tool_dispatch_failed"`, `"mcp_init_failed"`); `cause` is the raw error
|
|
686
|
+
* for further inspection when available.
|
|
687
|
+
*
|
|
688
|
+
* @public
|
|
689
|
+
*/
|
|
690
|
+
interface RunErrorDetail {
|
|
691
|
+
message: string;
|
|
692
|
+
code?: string;
|
|
693
|
+
cause?: unknown;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Dimensions of an inline image attachment.
|
|
697
|
+
*
|
|
698
|
+
* @public
|
|
699
|
+
*/
|
|
700
|
+
interface SDKImageDimension {
|
|
701
|
+
width: number;
|
|
702
|
+
height: number;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Either a remote URL or inline base64 payload.
|
|
706
|
+
*
|
|
707
|
+
* @public
|
|
708
|
+
*/
|
|
709
|
+
type SDKImage = {
|
|
710
|
+
url: string;
|
|
711
|
+
dimension?: SDKImageDimension;
|
|
712
|
+
} | {
|
|
713
|
+
data: string;
|
|
714
|
+
mimeType: string;
|
|
715
|
+
dimension?: SDKImageDimension;
|
|
716
|
+
};
|
|
717
|
+
/**
|
|
718
|
+
* Structured form of `agent.send()`'s message argument. Use it to send images
|
|
719
|
+
* alongside text.
|
|
720
|
+
*
|
|
721
|
+
* @public
|
|
722
|
+
*/
|
|
723
|
+
interface SDKUserMessage {
|
|
724
|
+
text: string;
|
|
725
|
+
images?: SDKImage[];
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Per-send overrides and callbacks.
|
|
729
|
+
*
|
|
730
|
+
* @public
|
|
731
|
+
*/
|
|
732
|
+
interface SendOptions {
|
|
733
|
+
model?: ModelSelection;
|
|
734
|
+
/**
|
|
735
|
+
* Per-call system prompt override. Wins over `AgentOptions.systemPrompt`.
|
|
736
|
+
* String only — for dynamic resolvers, configure on `AgentOptions`. An
|
|
737
|
+
* empty string is honoured (it explicitly clears the system context).
|
|
738
|
+
*/
|
|
739
|
+
systemPrompt?: string;
|
|
740
|
+
/** Fully replaces creation-time servers for this run (not merged). */
|
|
741
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
742
|
+
/**
|
|
743
|
+
* Per-call inline custom tools. Fully replaces `AgentOptions.tools` for
|
|
744
|
+
* this run (not merged). Local runtime only — cloud agents reject any
|
|
745
|
+
* non-empty per-call tools array with the same error code as creation
|
|
746
|
+
* (`cloud_custom_tools_rejected`). Semantics:
|
|
747
|
+
* - `undefined` → fall back to `AgentOptions.tools`
|
|
748
|
+
* - `[]` → explicitly clear (no custom tools for this run)
|
|
749
|
+
* - `[t1, t2]` → use exactly these tools for this run
|
|
750
|
+
*/
|
|
751
|
+
tools?: CustomTool[];
|
|
752
|
+
onStep?: (args: {
|
|
753
|
+
step: ConversationStep;
|
|
754
|
+
}) => void | Promise<void>;
|
|
755
|
+
onDelta?: (args: {
|
|
756
|
+
update: InteractionUpdate;
|
|
757
|
+
}) => void | Promise<void>;
|
|
758
|
+
/** Local agents only. Expire a stuck active run before starting this message. */
|
|
759
|
+
local?: {
|
|
760
|
+
force?: boolean;
|
|
761
|
+
};
|
|
762
|
+
/**
|
|
763
|
+
* Optional `AbortSignal` propagated to memory adapter `pre_user_send`
|
|
764
|
+
* hooks (EC-H). Note: the LLM HTTP call itself is NOT cancellable
|
|
765
|
+
* mid-stream — same constraint as `Agent.batch` (ADR D140).
|
|
766
|
+
*
|
|
767
|
+
* @public
|
|
768
|
+
*/
|
|
769
|
+
signal?: AbortSignal;
|
|
770
|
+
/**
|
|
771
|
+
* Opt-in task wrapping (ADRs D363, D374). When truthy, the entire
|
|
772
|
+
* run is registered as a `Task` in the SDK's observable registry —
|
|
773
|
+
* caller can list / inspect / cancel / subscribe via the `Task`
|
|
774
|
+
* namespace. Default behavior (no `task` option) is byte-identical
|
|
775
|
+
* to v1.1 (no Task overhead).
|
|
776
|
+
*
|
|
777
|
+
* Accepts:
|
|
778
|
+
* - `true` — auto-generate task id; no extra metadata.
|
|
779
|
+
* - `{ id, meta }` — user-supplied id (D368 grammar enforced) and/or
|
|
780
|
+
* metadata attached to the handle's `meta` field.
|
|
781
|
+
*
|
|
782
|
+
* The work-fn `signal` is **merged** with `options.signal` (whichever
|
|
783
|
+
* aborts first wins). Local agents only — CloudAgent throws
|
|
784
|
+
* `UnsupportedTaskOperationError` (D370).
|
|
785
|
+
*
|
|
786
|
+
* @public
|
|
787
|
+
*/
|
|
788
|
+
task?: true | {
|
|
789
|
+
id?: string;
|
|
790
|
+
meta?: Record<string, unknown>;
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Handle to a single prompt submission.
|
|
795
|
+
*
|
|
796
|
+
* @public
|
|
797
|
+
*/
|
|
798
|
+
interface Run {
|
|
799
|
+
readonly id: string;
|
|
800
|
+
readonly agentId: string;
|
|
801
|
+
readonly status: RunStatus;
|
|
802
|
+
readonly result?: string;
|
|
803
|
+
readonly model?: ModelSelection;
|
|
804
|
+
readonly durationMs?: number;
|
|
805
|
+
readonly git?: RunGitInfo;
|
|
806
|
+
readonly createdAt?: number;
|
|
807
|
+
/** AsyncGenerator of normalized stream events. Discriminate on `event.type`. */
|
|
808
|
+
stream(): AsyncGenerator<SDKMessage, void>;
|
|
809
|
+
/** Resolves to the terminal {@link RunResult}. */
|
|
810
|
+
wait(): Promise<RunResult>;
|
|
811
|
+
/** Move status to `"cancelled"`, abort the stream, stop in-flight tool calls. */
|
|
812
|
+
cancel(): Promise<void>;
|
|
813
|
+
/** Structured per-turn view of the conversation. */
|
|
814
|
+
conversation(): Promise<ConversationTurn[]>;
|
|
815
|
+
/** Whether the given operation is available on this run's runtime. */
|
|
816
|
+
supports(operation: RunOperation): boolean;
|
|
817
|
+
/** Human-readable reason that `supports(operation)` returned `false`. */
|
|
818
|
+
unsupportedReason(operation: RunOperation): string | undefined;
|
|
819
|
+
/** Subscribe to status changes. Returns an unsubscribe function. */
|
|
820
|
+
onDidChangeStatus(listener: (status: RunStatus) => void): () => void;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
export type { ToolCall as $, AgentConversationTurn as A, SDKToolUseMessage as B, CustomTool as C, SDKUserMessage as D, SDKUserMessageEvent as E, SendOptions as F, ShellCommand as G, ShellConversationTurn as H, InteractionUpdate as I, ShellOutput as J, ShellOutputDeltaUpdate as K, StepCompletedUpdate as L, ModelSelection as M, StepStartedUpdate as N, SummaryCompletedUpdate as O, PartialToolCallUpdate as P, SummaryStartedUpdate as Q, RunResult as R, SDKMessage as S, SummaryUpdate as T, TextBlock as U, TextDeltaUpdate as V, ThinkingCompletedUpdate as W, ThinkingDeltaUpdate as X, ThinkingMessage as Y, TokenDeltaUpdate as Z, TokenUsage as _, McpServerConfig as a, ToolCallCompletedUpdate as a0, ToolCallStartedUpdate as a1, ToolResult as a2, ToolUseBlock as a3, TurnEndedUpdate as a4, UserMessage as a5, UserMessageAppendedUpdate as a6, Run as b, AssistantMessage as c, ConversationStep as d, ConversationTurn as e, CostBreakdown as f, CostSource as g, CostStatus as h, McpAuthConfig as i, McpHttpServerConfig as j, McpOAuthConfig as k, McpStdioServerConfig as l, ModelParameterValue as m, RunErrorDetail as n, RunGitInfo as o, RunOperation as p, RunStatus as q, SDKAssistantMessage as r, SDKImage as s, SDKImageDimension as t, SDKObjectDelta as u, SDKRequestMessage as v, SDKStatusMessage as w, SDKSystemMessage as x, SDKTaskMessage as y, SDKThinkingMessage as z };
|