@theokit/sdk 1.6.1 → 1.7.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 +187 -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 +48 -42
- 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 +49 -43
- 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 +126 -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as CustomTool, M as ModelSelection, D as SDKUserMessage, F as SendOptions, b as Run, a as McpServerConfig } from './run-DrwUpFxZ.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Public event types emitted by {@link SDKAgent.runUntil} (ADRs D115-D117).
|
|
@@ -96,218 +96,6 @@ interface GoalOptions {
|
|
|
96
96
|
signal?: AbortSignal;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/**
|
|
100
|
-
* Pluggable persistence for conversation history (Production-Readiness #1, ADRs D303-D306).
|
|
101
|
-
*
|
|
102
|
-
* The default {@link FileSystemConversationStorage} writes append-only JSONL
|
|
103
|
-
* to `<cwd>/.theokit/agents/<id>/messages.jsonl`. Custom adapters back the
|
|
104
|
-
* SDK against Postgres, Redis, Durable Objects, or any other store — required
|
|
105
|
-
* for serverless deploys (Vercel, Cloudflare Workers) and multi-host setups
|
|
106
|
-
* (K8s replicas, TheoCloud) where the filesystem is ephemeral or not shared.
|
|
107
|
-
*
|
|
108
|
-
* @public
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* Persisted message envelope used by {@link ConversationStorageAdapter}.
|
|
112
|
-
*
|
|
113
|
-
* The shape is deliberately narrower than the full {@link SDKMessage} variant
|
|
114
|
-
* tree — only durable content survives. `role` covers all message origins the
|
|
115
|
-
* SDK persists today (user/assistant) plus the forward-compat slots for
|
|
116
|
-
* tool-shaped messages (ADR D310 / EC-10).
|
|
117
|
-
*
|
|
118
|
-
* @public
|
|
119
|
-
*/
|
|
120
|
-
interface StoredMessage {
|
|
121
|
-
/** Origin of the message. `tool_call` / `tool_result` reserved for forward compat. */
|
|
122
|
-
role: "user" | "assistant" | "system" | "tool_call" | "tool_result";
|
|
123
|
-
/** UTF-8 payload. May be empty string (e.g., a tool with no return value). */
|
|
124
|
-
content: string;
|
|
125
|
-
/** Optional epoch-ms timestamp. Implementations MAY default to `Date.now()` on append. */
|
|
126
|
-
at?: number;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Pluggable conversation persistence contract.
|
|
130
|
-
*
|
|
131
|
-
* Implementations MUST be safe under concurrent append from a single process
|
|
132
|
-
* — the SDK runtime serializes per-(agent,cwd) but adapters serving multiple
|
|
133
|
-
* processes are responsible for their own atomicity.
|
|
134
|
-
*
|
|
135
|
-
* All methods return `Promise<>` even for synchronous backends (in-memory).
|
|
136
|
-
* Polymorphism uniformity beats the ~1μs microtask cost (ADR D306).
|
|
137
|
-
*
|
|
138
|
-
* @public
|
|
139
|
-
*/
|
|
140
|
-
interface ConversationStorageAdapter {
|
|
141
|
-
/**
|
|
142
|
-
* Return the full message history for a conversation, in insertion order.
|
|
143
|
-
* MUST return `[]` (not throw) when the conversation does not exist.
|
|
144
|
-
*/
|
|
145
|
-
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
146
|
-
/**
|
|
147
|
-
* Append a single message to the conversation.
|
|
148
|
-
* MUST be atomic — concurrent appends MUST NOT corrupt the log.
|
|
149
|
-
* MUST create the conversation lazily if it does not exist.
|
|
150
|
-
*/
|
|
151
|
-
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Delete the entire conversation. MUST be idempotent (delete-of-missing = ok).
|
|
154
|
-
*/
|
|
155
|
-
deleteConversation(conversationId: string): Promise<void>;
|
|
156
|
-
/**
|
|
157
|
-
* Optional: list conversation ids. Used by housekeeping flows.
|
|
158
|
-
* Implementations that cannot enumerate (e.g., wildcards too expensive on
|
|
159
|
-
* production Redis) MAY return `undefined` to signal "not supported".
|
|
160
|
-
*/
|
|
161
|
-
listConversationIds?(opts?: {
|
|
162
|
-
limit?: number;
|
|
163
|
-
}): Promise<readonly string[] | undefined>;
|
|
164
|
-
/**
|
|
165
|
-
* Optional FS-specific compaction trigger (ADR D304). The default FS adapter
|
|
166
|
-
* trims old turns past a soft cap; other backends typically no-op.
|
|
167
|
-
*/
|
|
168
|
-
compact?(conversationId: string, maxTurns: number): Promise<void>;
|
|
169
|
-
/**
|
|
170
|
-
* Optional: dispose underlying handles (close DB pool, etc.).
|
|
171
|
-
* MUST be safe to call multiple times.
|
|
172
|
-
*/
|
|
173
|
-
dispose?(): Promise<void>;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Public types for `Agent.create({ handoffs })` + `Handoff.create()` +
|
|
178
|
-
* `Agent.handoffTo()` (Adoption Roadmap #4; ADRs D214-D229).
|
|
179
|
-
*
|
|
180
|
-
* Pattern: handoff-as-tool. Each handoff destination becomes a synthetic
|
|
181
|
-
* `transfer_to_<receiver>` function tool exposed to the LLM. Runtime
|
|
182
|
-
* intercepts the tool call and routes the next turn to the receiver.
|
|
183
|
-
*
|
|
184
|
-
* @public
|
|
185
|
-
*/
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Context handed to `onHandoff` callbacks and `isEnabled` predicates.
|
|
189
|
-
* Read-only snapshot of the handoff dispatch state.
|
|
190
|
-
*/
|
|
191
|
-
interface HandoffContext {
|
|
192
|
-
readonly senderAgentId: string;
|
|
193
|
-
readonly receiverAgentId: string;
|
|
194
|
-
/** Depth counter AT dispatch time (post-increment; first handoff = 1). */
|
|
195
|
-
readonly currentDepth: number;
|
|
196
|
-
/** Chain of agentIds traversed so far in this send(). Always ends with sender. */
|
|
197
|
-
readonly chain: ReadonlyArray<string>;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* The transcript wrapper passed to `inputFilter`. `messages` is widened to
|
|
201
|
-
* `unknown[]` so this type doesn't import from `messages.ts` (avoids cycle
|
|
202
|
-
* — implementations cast to `SDKMessage[]` internally).
|
|
203
|
-
*/
|
|
204
|
-
interface HandoffHistory {
|
|
205
|
-
readonly messages: ReadonlyArray<unknown>;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Options accepted by `Handoff.create(target, opts?)`.
|
|
209
|
-
*
|
|
210
|
-
* @public
|
|
211
|
-
*/
|
|
212
|
-
interface HandoffOptions<TInput extends ZodType = ZodType> {
|
|
213
|
-
/** Override the default tool name `transfer_to_<receiver.name>` (D215). */
|
|
214
|
-
readonly toolName?: string;
|
|
215
|
-
/** Override the default tool description. */
|
|
216
|
-
readonly toolDescription?: string;
|
|
217
|
-
/**
|
|
218
|
-
* Side-effect callback fired BEFORE the receiver takes over.
|
|
219
|
-
*
|
|
220
|
-
* **Semantics (D227):** throwing aborts the handoff — the synthetic tool
|
|
221
|
-
* returns `tool_error: onHandoff_failed: <message>` so the LLM sees the
|
|
222
|
-
* conflict. Logger-style consumers MUST wrap their own try/catch to
|
|
223
|
-
* swallow exceptions.
|
|
224
|
-
*/
|
|
225
|
-
readonly onHandoff?: (ctx: HandoffContext, parsed: TInput extends ZodType ? unknown : undefined) => void | Promise<void>;
|
|
226
|
-
/**
|
|
227
|
-
* Zod schema for the handoff tool-call arguments (structured payload).
|
|
228
|
-
* When set, LLM-provided args are validated before `onHandoff` fires.
|
|
229
|
-
*
|
|
230
|
-
* **Edge case (D229):** empty/null `inputJson` parses as `{}` before
|
|
231
|
-
* Zod refinements fire — required-field schemas still throw normally.
|
|
232
|
-
*/
|
|
233
|
-
readonly inputType?: TInput;
|
|
234
|
-
/**
|
|
235
|
-
* Filter the history passed to the receiver (D216 default = full; D219).
|
|
236
|
-
*
|
|
237
|
-
* **Resilience (D228):** if this callback throws, the runtime logs once
|
|
238
|
-
* to stderr and falls back to the un-filtered history. Use this for
|
|
239
|
-
* privacy redaction; if you need fatal-on-failure semantics, throw in
|
|
240
|
-
* `onHandoff` instead.
|
|
241
|
-
*/
|
|
242
|
-
readonly inputFilter?: (history: HandoffHistory) => HandoffHistory | Promise<HandoffHistory>;
|
|
243
|
-
/**
|
|
244
|
-
* Restrict the receiver's tools for the post-handoff turn ONLY (D224).
|
|
245
|
-
* Subsequent receiver-internal turns use the receiver's full tool set.
|
|
246
|
-
*/
|
|
247
|
-
readonly tools?: ReadonlyArray<string>;
|
|
248
|
-
/**
|
|
249
|
-
* Dynamically enable/disable this handoff. Bool = static; predicate =
|
|
250
|
-
* called per-`Agent.send()` to evaluate.
|
|
251
|
-
*/
|
|
252
|
-
readonly isEnabled?: boolean | ((ctx: HandoffContext) => boolean | Promise<boolean>);
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Result of a single handoff dispatch (for telemetry / observability).
|
|
256
|
-
*
|
|
257
|
-
* @public
|
|
258
|
-
*/
|
|
259
|
-
interface HandoffResult {
|
|
260
|
-
readonly from: string;
|
|
261
|
-
readonly to: string;
|
|
262
|
-
readonly depth: number;
|
|
263
|
-
readonly toolName: string;
|
|
264
|
-
readonly reasonFromLlm?: string;
|
|
265
|
-
}
|
|
266
|
-
/** Throw when handoff depth exceeds `maxHandoffDepth` (default 5; D218). */
|
|
267
|
-
declare class HandoffLoopError extends Error {
|
|
268
|
-
readonly name = "HandoffLoopError";
|
|
269
|
-
readonly depth: number;
|
|
270
|
-
readonly chain: ReadonlyArray<string>;
|
|
271
|
-
constructor(depth: number, chain: ReadonlyArray<string>);
|
|
272
|
-
}
|
|
273
|
-
/** Throw when the same (sender, receiver) pair invoked twice in one send() (D221). */
|
|
274
|
-
declare class HandoffPairLoopError extends Error {
|
|
275
|
-
readonly name = "HandoffPairLoopError";
|
|
276
|
-
readonly senderAgentId: string;
|
|
277
|
-
readonly receiverAgentId: string;
|
|
278
|
-
constructor(senderAgentId: string, receiverAgentId: string);
|
|
279
|
-
}
|
|
280
|
-
/** Throw when an agent's `handoffs[]` includes a self-reference (EC-6). */
|
|
281
|
-
declare class HandoffSelfReferenceError extends Error {
|
|
282
|
-
readonly name = "HandoffSelfReferenceError";
|
|
283
|
-
readonly agentId: string;
|
|
284
|
-
constructor(agentId: string);
|
|
285
|
-
}
|
|
286
|
-
/** Throw when receiver is disposed at dispatch time (EC-5). */
|
|
287
|
-
declare class HandoffReceiverDisposedError extends Error {
|
|
288
|
-
readonly name = "HandoffReceiverDisposedError";
|
|
289
|
-
readonly receiverAgentId: string;
|
|
290
|
-
constructor(receiverAgentId: string);
|
|
291
|
-
}
|
|
292
|
-
/** Throw when two handoffs in the same parent collide on tool name (D215). */
|
|
293
|
-
declare class HandoffNameCollisionError extends Error {
|
|
294
|
-
readonly name = "HandoffNameCollisionError";
|
|
295
|
-
readonly conflictingName: string;
|
|
296
|
-
constructor(conflictingName: string);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Public `Handoff` shape — what `Handoff.create()` returns. Read-only
|
|
300
|
-
* accessors only; behavior lives in the engine.
|
|
301
|
-
*
|
|
302
|
-
* @public
|
|
303
|
-
*/
|
|
304
|
-
interface HandoffDescriptor<TInput extends ZodType = ZodType> {
|
|
305
|
-
readonly target: SDKAgent;
|
|
306
|
-
readonly options: HandoffOptions<TInput>;
|
|
307
|
-
/** Resolved tool name (after applying toolName override or default `transfer_to_<receiver>`). */
|
|
308
|
-
readonly resolvedToolName: string;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
99
|
/**
|
|
312
100
|
* Public `MemoryAdapter` contract (T1.1, ADRs D141 / D147).
|
|
313
101
|
*
|
|
@@ -484,6 +272,322 @@ interface AgentMemory {
|
|
|
484
272
|
adapter(): MemoryAdapter | null;
|
|
485
273
|
}
|
|
486
274
|
|
|
275
|
+
/**
|
|
276
|
+
* `MemoryProvider` — kernel-facing port for the memory subsystem
|
|
277
|
+
* (SDK 2.0 Phase 1 / T1.1 — Hexagonal Architecture / Ports & Adapters,
|
|
278
|
+
* SOLID Dependency Inversion).
|
|
279
|
+
*
|
|
280
|
+
* The agent loop kernel depends on THIS CONTRACT — not on the concrete
|
|
281
|
+
* `internal/memory/*` modules. Default adapter ships with `@theokit/sdk`
|
|
282
|
+
* (no-op for back-compat); rich impl ships in `@theokit/sdk-memory`.
|
|
283
|
+
* Consumers opt-in via `Agent.create({ memoryProvider: ... })` (wiring
|
|
284
|
+
* lands in subsequent iteration).
|
|
285
|
+
*
|
|
286
|
+
* Design rationale (ADR-001 + ADR-003 in
|
|
287
|
+
* `sdk-2-0-phase-1-2-adr.md`):
|
|
288
|
+
* - Memory subsystem is deeply integrated with the agent loop (active
|
|
289
|
+
* memory pass, LLM tool injection, lifecycle ownership) — cannot
|
|
290
|
+
* extract via plugin-protocol alone like Cache / Handoff.
|
|
291
|
+
* - Interface inversion is the canonical FAANG-style answer: the kernel
|
|
292
|
+
* defines what it NEEDS; impls satisfy the contract; package boundary
|
|
293
|
+
* is the seam.
|
|
294
|
+
* - Mirrors the `BudgetTracker` interface inversion (iter 10-16): same
|
|
295
|
+
* pattern, different subsystem.
|
|
296
|
+
*
|
|
297
|
+
* Layered model (mirrors Budget):
|
|
298
|
+
* - `MemoryAdapter` (existing in `types/memory-adapter.ts`) — LOW-LEVEL
|
|
299
|
+
* data port: write / recall / delete primitives.
|
|
300
|
+
* - `MemoryProvider` (THIS FILE) — HIGH-LEVEL lifecycle port: init,
|
|
301
|
+
* tool factories, active memory pass, embedding runtime selection.
|
|
302
|
+
*
|
|
303
|
+
* @public — surface-level interface; impls are internal-but-replaceable.
|
|
304
|
+
*/
|
|
305
|
+
|
|
306
|
+
/** Result of `MemoryProvider.runActivePass(...)` — what the kernel injects into the LLM call. */
|
|
307
|
+
interface ActiveMemoryPassResult {
|
|
308
|
+
/** Compressed memory facts to seed the LLM's context window for this turn. */
|
|
309
|
+
readonly facts: ReadonlyArray<MemoryFact>;
|
|
310
|
+
/** Optional system-prompt enrichment derived from the recalled facts. */
|
|
311
|
+
readonly systemPromptAdditions?: string;
|
|
312
|
+
/** Whether the active-memory circuit breaker tripped (degraded mode). */
|
|
313
|
+
readonly breakerTripped?: boolean;
|
|
314
|
+
}
|
|
315
|
+
/** Arguments for `MemoryProvider.runActivePass(...)`. */
|
|
316
|
+
interface ActiveMemoryPassArgs {
|
|
317
|
+
/** The current user message — used as the recall query. */
|
|
318
|
+
readonly userMessage: string;
|
|
319
|
+
/** Conversation history (most recent first). */
|
|
320
|
+
readonly history: ReadonlyArray<{
|
|
321
|
+
role: "user" | "assistant";
|
|
322
|
+
content: string;
|
|
323
|
+
}>;
|
|
324
|
+
/** Agent identity for scope. */
|
|
325
|
+
readonly agentId: string;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Arguments for `MemoryProvider.recordSessionSummary(...)`
|
|
329
|
+
* (SDK 2.0 Phase 1 physical Stage 3 prep — iter 27).
|
|
330
|
+
*
|
|
331
|
+
* The "session summary" is the markdown that gets written to disk
|
|
332
|
+
* after a finished run + indexed under `corpus="sessions"`. This
|
|
333
|
+
* port method lets sdk-core's `post-run-lifecycle.ts` delegate the
|
|
334
|
+
* write to the provider instead of importing
|
|
335
|
+
* `internal/memory/storage/session-summary-writer.ts` directly.
|
|
336
|
+
*
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
interface RecordSessionSummaryArgs {
|
|
340
|
+
/**
|
|
341
|
+
* Workspace cwd where on-disk artefacts live. Included on the args
|
|
342
|
+
* (not on a handle) because `recordSessionSummary` is STATELESS — it
|
|
343
|
+
* runs AFTER `runAgentLoop`'s `dispose()` releases the per-run handle.
|
|
344
|
+
* The kernel passes its own `workspaceCwd`; the impl uses it to
|
|
345
|
+
* compute the markdown file path.
|
|
346
|
+
*/
|
|
347
|
+
readonly cwd: string;
|
|
348
|
+
/** Run id used as the filename key. */
|
|
349
|
+
readonly runId: string;
|
|
350
|
+
/** Agent identity for scope (foldering). */
|
|
351
|
+
readonly agentId: string;
|
|
352
|
+
/** Verbatim user message that started the run. */
|
|
353
|
+
readonly userText: string;
|
|
354
|
+
/** Final assistant text the run produced. */
|
|
355
|
+
readonly assistantText: string;
|
|
356
|
+
/** Final run status (only "finished" is recorded today). */
|
|
357
|
+
readonly status: "finished" | "error" | "cancelled";
|
|
358
|
+
/** Wall-clock ms at write time. */
|
|
359
|
+
readonly at: number;
|
|
360
|
+
}
|
|
361
|
+
/** Options for `MemoryProvider.init(...)`. */
|
|
362
|
+
interface MemoryProviderInitOptions {
|
|
363
|
+
/** Workspace cwd where on-disk artefacts live (`.theokit/memory/...`). */
|
|
364
|
+
readonly cwd: string;
|
|
365
|
+
/** Embedding-provider id (`"openai" | "ollama" | ...`); when omitted the impl picks a default. */
|
|
366
|
+
readonly embeddingProviderId?: string;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Opaque handle returned by `init()`. Carried back into other methods so
|
|
370
|
+
* the impl can stash per-agent state (index, breaker, cache, …) without
|
|
371
|
+
* exposing it to the kernel.
|
|
372
|
+
*/
|
|
373
|
+
interface MemoryProviderHandle {
|
|
374
|
+
/** Adapter interface for direct read/write — matches existing `MemoryAdapter` shape. */
|
|
375
|
+
readonly adapter: MemoryAdapter;
|
|
376
|
+
/** Implementation-defined opaque field (private state pointer / index handle). */
|
|
377
|
+
readonly [implState: symbol]: unknown;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* The kernel-facing contract. Implementations live OUTSIDE the agent loop
|
|
381
|
+
* (in `@theokit/sdk-memory` after Phase 1; in `internal/memory/` until then).
|
|
382
|
+
*
|
|
383
|
+
* Implementations MUST be:
|
|
384
|
+
* - **Lazy** — `init()` may be called once per agent; subsequent calls
|
|
385
|
+
* return the same handle (impl decides via cache). Heavy work
|
|
386
|
+
* (loading the index, opening SQLite) deferred until first use.
|
|
387
|
+
* - **Non-throwing on the hot path** — `runActivePass()` returns an
|
|
388
|
+
* empty `facts: []` on degradation rather than throwing. Errors
|
|
389
|
+
* surface via the breakerTripped flag + telemetry.
|
|
390
|
+
*/
|
|
391
|
+
interface MemoryProvider {
|
|
392
|
+
/** Construct or fetch the per-agent handle. Lazy + idempotent. */
|
|
393
|
+
init(opts: MemoryProviderInitOptions): Promise<MemoryProviderHandle>;
|
|
394
|
+
/** Build the LLM-facing tool catalog (memory_search, memory_get, …). */
|
|
395
|
+
buildTools(handle: MemoryProviderHandle, agent: SDKAgent): ReadonlyArray<CustomTool>;
|
|
396
|
+
/** Run the active-memory pre-LLM pass — recall + compress + format. */
|
|
397
|
+
runActivePass(handle: MemoryProviderHandle, args: ActiveMemoryPassArgs): Promise<ActiveMemoryPassResult>;
|
|
398
|
+
/**
|
|
399
|
+
* Optional post-run hook (SDK 2.0 Phase 1 physical Stage 1 — iter 19).
|
|
400
|
+
* Called by the agent loop AFTER a successful send so the impl can
|
|
401
|
+
* incorporate the session summary into its index (e.g., re-index the
|
|
402
|
+
* `sessions` corpus so the next recall sees it).
|
|
403
|
+
*
|
|
404
|
+
* Fire-and-forget at the call site; impl MUST be idempotent +
|
|
405
|
+
* non-throwing. Optional so existing impls (createNoopMemoryProvider,
|
|
406
|
+
* sdk-memory@0.1.0) keep working without modification.
|
|
407
|
+
*
|
|
408
|
+
* Mirrors the role of `LocalAgentMemory.syncIfReady()` in sdk-core's
|
|
409
|
+
* legacy memory path — exposing it via the port is the seam that
|
|
410
|
+
* unblocks moving LocalAgentMemory's logic out to sdk-memory.
|
|
411
|
+
*/
|
|
412
|
+
sync?(handle: MemoryProviderHandle): Promise<void> | void;
|
|
413
|
+
/**
|
|
414
|
+
* Optional session-summary write hook (SDK 2.0 Phase 1 physical
|
|
415
|
+
* Stage 3 prep — iter 27, refined iter 28).
|
|
416
|
+
*
|
|
417
|
+
* Called by `post-run-lifecycle.ts` AFTER a finished run to persist
|
|
418
|
+
* the run's session-summary markdown under `corpus="sessions"`. When
|
|
419
|
+
* defined, the kernel delegates the write to the provider; when
|
|
420
|
+
* undefined, post-run-lifecycle falls back to the direct
|
|
421
|
+
* `writeSessionSummary` import (legacy path, until Stage 3 source
|
|
422
|
+
* move drops that import entirely).
|
|
423
|
+
*
|
|
424
|
+
* STATELESS — does NOT take a `MemoryProviderHandle` because post-run-
|
|
425
|
+
* lifecycle runs AFTER `runAgentLoop` disposed the per-run handle.
|
|
426
|
+
* `cwd` lives on `args` instead. Impls that need per-agent state can
|
|
427
|
+
* cache it via closure inside the provider factory.
|
|
428
|
+
*
|
|
429
|
+
* Impl MUST be non-throwing on the hot path. The kernel swallows
|
|
430
|
+
* any throw + emits a stderr warning.
|
|
431
|
+
*
|
|
432
|
+
* Optional so existing impls (createNoopMemoryProvider,
|
|
433
|
+
* createInMemoryMarkdownProvider) keep working without modification.
|
|
434
|
+
*/
|
|
435
|
+
recordSessionSummary?(args: RecordSessionSummaryArgs): Promise<void> | void;
|
|
436
|
+
/** Release the handle (close index, flush caches). Idempotent + non-throwing. */
|
|
437
|
+
dispose(handle: MemoryProviderHandle): Promise<void> | void;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* `BudgetTracker` — runtime contract for budget/usage tracking in the
|
|
442
|
+
* agent loop (SDK 2.0 Phase 2 / T2.1 — ADR D1 interface inversion).
|
|
443
|
+
*
|
|
444
|
+
* This interface is the FOUNDATION for the eventual extraction of the
|
|
445
|
+
* Budget subsystem to `@theokit/sdk-budget`. The kernel depends on this
|
|
446
|
+
* contract (not on `UsageAccumulator` / `IterationBudget` concrete classes)
|
|
447
|
+
* so the implementation can move to a separate package without circular
|
|
448
|
+
* imports.
|
|
449
|
+
*
|
|
450
|
+
* Until Phase 2 completes, the legacy `UsageAccumulator` + `IterationBudget`
|
|
451
|
+
* remain wired in `internal/agent-loop/loop.ts` as the default impl. Future
|
|
452
|
+
* iterations:
|
|
453
|
+
* - Refactor `Agent.create` to accept `budgetTracker?: BudgetTracker`.
|
|
454
|
+
* - When provided, agent-loop uses it; when absent, falls back to the
|
|
455
|
+
* internal default for back-compat.
|
|
456
|
+
* - Move the default impl to `@theokit/sdk-budget` (extracted package).
|
|
457
|
+
* - Phase 6 cohort: drop the internal default, require explicit tracker.
|
|
458
|
+
*
|
|
459
|
+
* @public — surface-level interface; impl is internal-but-replaceable.
|
|
460
|
+
*/
|
|
461
|
+
/** Single usage event recorded during one LLM call. */
|
|
462
|
+
interface BudgetUsageEvent {
|
|
463
|
+
/** Token count for this event. */
|
|
464
|
+
readonly tokens: number;
|
|
465
|
+
/** Provider/model identifier (e.g., `"openai/gpt-4o-mini"`). */
|
|
466
|
+
readonly model: string;
|
|
467
|
+
/** Whether this is an input (prompt) or output (completion) measurement. */
|
|
468
|
+
readonly type: "input" | "output";
|
|
469
|
+
/** Optional ISO 8601 timestamp; defaults to now() if omitted. */
|
|
470
|
+
readonly at?: string;
|
|
471
|
+
}
|
|
472
|
+
/** Decision the tracker returns on each iteration / pre-flight check. */
|
|
473
|
+
interface BudgetCheck {
|
|
474
|
+
/** Whether the agent loop is allowed to proceed. */
|
|
475
|
+
readonly allowed: boolean;
|
|
476
|
+
/**
|
|
477
|
+
* When `allowed` is false, names the reason in a stable, codemod-friendly
|
|
478
|
+
* form. Consumers map this to retry / surface to user / abort behavior.
|
|
479
|
+
*/
|
|
480
|
+
readonly reason?: "budget_exceeded" | "iteration_limit" | "cost_limit" | "token_limit" | "custom";
|
|
481
|
+
/** Free-form details for logs / diagnostics. */
|
|
482
|
+
readonly detail?: string;
|
|
483
|
+
}
|
|
484
|
+
/** Aggregate snapshot of usage so far. */
|
|
485
|
+
interface BudgetTotal {
|
|
486
|
+
/** Sum of all input + output tokens. */
|
|
487
|
+
readonly tokens: number;
|
|
488
|
+
/** USD cost when pricing data is available; `undefined` otherwise. */
|
|
489
|
+
readonly costUsd?: number;
|
|
490
|
+
/** Iteration count if the impl tracks it. */
|
|
491
|
+
readonly iterations?: number;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* The kernel-facing contract. Implementations live OUTSIDE the agent loop
|
|
495
|
+
* (in `@theokit/sdk-budget` after Phase 2 / in `internal/budget/` until then).
|
|
496
|
+
*
|
|
497
|
+
* Implementations MUST be:
|
|
498
|
+
* - **Synchronous** — every method returns a value, never a Promise.
|
|
499
|
+
* `track()` is on the hot path (called on every iteration); async would
|
|
500
|
+
* bloat the loop with floating promises and force every call site to
|
|
501
|
+
* await.
|
|
502
|
+
* - **Non-throwing in track()** — record-only semantics. Validation
|
|
503
|
+
* failures bubble up via `check()` instead.
|
|
504
|
+
*/
|
|
505
|
+
interface BudgetTracker {
|
|
506
|
+
/** Record a single usage event. MUST be synchronous and non-throwing. */
|
|
507
|
+
track(event: BudgetUsageEvent): void;
|
|
508
|
+
/** Pre-flight check before the next iteration. */
|
|
509
|
+
check(): BudgetCheck;
|
|
510
|
+
/** Snapshot of accumulated totals (for telemetry / final reporting). */
|
|
511
|
+
getTotal(): BudgetTotal;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Pluggable persistence for conversation history (Production-Readiness #1, ADRs D303-D306).
|
|
516
|
+
*
|
|
517
|
+
* The default {@link FileSystemConversationStorage} writes append-only JSONL
|
|
518
|
+
* to `<cwd>/.theokit/agents/<id>/messages.jsonl`. Custom adapters back the
|
|
519
|
+
* SDK against Postgres, Redis, Durable Objects, or any other store — required
|
|
520
|
+
* for serverless deploys (Vercel, Cloudflare Workers) and multi-host setups
|
|
521
|
+
* (K8s replicas, TheoCloud) where the filesystem is ephemeral or not shared.
|
|
522
|
+
*
|
|
523
|
+
* @public
|
|
524
|
+
*/
|
|
525
|
+
/**
|
|
526
|
+
* Persisted message envelope used by {@link ConversationStorageAdapter}.
|
|
527
|
+
*
|
|
528
|
+
* The shape is deliberately narrower than the full {@link SDKMessage} variant
|
|
529
|
+
* tree — only durable content survives. `role` covers all message origins the
|
|
530
|
+
* SDK persists today (user/assistant) plus the forward-compat slots for
|
|
531
|
+
* tool-shaped messages (ADR D310 / EC-10).
|
|
532
|
+
*
|
|
533
|
+
* @public
|
|
534
|
+
*/
|
|
535
|
+
interface StoredMessage {
|
|
536
|
+
/** Origin of the message. `tool_call` / `tool_result` reserved for forward compat. */
|
|
537
|
+
role: "user" | "assistant" | "system" | "tool_call" | "tool_result";
|
|
538
|
+
/** UTF-8 payload. May be empty string (e.g., a tool with no return value). */
|
|
539
|
+
content: string;
|
|
540
|
+
/** Optional epoch-ms timestamp. Implementations MAY default to `Date.now()` on append. */
|
|
541
|
+
at?: number;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Pluggable conversation persistence contract.
|
|
545
|
+
*
|
|
546
|
+
* Implementations MUST be safe under concurrent append from a single process
|
|
547
|
+
* — the SDK runtime serializes per-(agent,cwd) but adapters serving multiple
|
|
548
|
+
* processes are responsible for their own atomicity.
|
|
549
|
+
*
|
|
550
|
+
* All methods return `Promise<>` even for synchronous backends (in-memory).
|
|
551
|
+
* Polymorphism uniformity beats the ~1μs microtask cost (ADR D306).
|
|
552
|
+
*
|
|
553
|
+
* @public
|
|
554
|
+
*/
|
|
555
|
+
interface ConversationStorageAdapter {
|
|
556
|
+
/**
|
|
557
|
+
* Return the full message history for a conversation, in insertion order.
|
|
558
|
+
* MUST return `[]` (not throw) when the conversation does not exist.
|
|
559
|
+
*/
|
|
560
|
+
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
561
|
+
/**
|
|
562
|
+
* Append a single message to the conversation.
|
|
563
|
+
* MUST be atomic — concurrent appends MUST NOT corrupt the log.
|
|
564
|
+
* MUST create the conversation lazily if it does not exist.
|
|
565
|
+
*/
|
|
566
|
+
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
567
|
+
/**
|
|
568
|
+
* Delete the entire conversation. MUST be idempotent (delete-of-missing = ok).
|
|
569
|
+
*/
|
|
570
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
571
|
+
/**
|
|
572
|
+
* Optional: list conversation ids. Used by housekeeping flows.
|
|
573
|
+
* Implementations that cannot enumerate (e.g., wildcards too expensive on
|
|
574
|
+
* production Redis) MAY return `undefined` to signal "not supported".
|
|
575
|
+
*/
|
|
576
|
+
listConversationIds?(opts?: {
|
|
577
|
+
limit?: number;
|
|
578
|
+
}): Promise<readonly string[] | undefined>;
|
|
579
|
+
/**
|
|
580
|
+
* Optional FS-specific compaction trigger (ADR D304). The default FS adapter
|
|
581
|
+
* trims old turns past a soft cap; other backends typically no-op.
|
|
582
|
+
*/
|
|
583
|
+
compact?(conversationId: string, maxTurns: number): Promise<void>;
|
|
584
|
+
/**
|
|
585
|
+
* Optional: dispose underlying handles (close DB pool, etc.).
|
|
586
|
+
* MUST be safe to call multiple times.
|
|
587
|
+
*/
|
|
588
|
+
dispose?(): Promise<void>;
|
|
589
|
+
}
|
|
590
|
+
|
|
487
591
|
/**
|
|
488
592
|
* Context manager backend.
|
|
489
593
|
*
|
|
@@ -578,71 +682,6 @@ interface SDKContextManager {
|
|
|
578
682
|
snapshot(): Promise<ContextSnapshot>;
|
|
579
683
|
}
|
|
580
684
|
|
|
581
|
-
/**
|
|
582
|
-
* MCP server configuration accepted by `Agent.create()` and `agent.send()`.
|
|
583
|
-
*
|
|
584
|
-
* @public
|
|
585
|
-
*/
|
|
586
|
-
type McpStdioServerConfig = {
|
|
587
|
-
type?: "stdio";
|
|
588
|
-
command: string;
|
|
589
|
-
args?: string[];
|
|
590
|
-
env?: Record<string, string>;
|
|
591
|
-
/** Local agents only. Cloud rejects this field. */
|
|
592
|
-
cwd?: string;
|
|
593
|
-
};
|
|
594
|
-
/**
|
|
595
|
-
* OAuth-style auth bundle for HTTP/SSE MCP servers.
|
|
596
|
-
*
|
|
597
|
-
* @public
|
|
598
|
-
*/
|
|
599
|
-
interface McpAuthConfig {
|
|
600
|
-
CLIENT_ID: string;
|
|
601
|
-
CLIENT_SECRET?: string;
|
|
602
|
-
scopes?: string[];
|
|
603
|
-
/**
|
|
604
|
-
* OAuth 2.1 PKCE flow configuration (ADR D41, v1.2+). When present, the
|
|
605
|
-
* SDK runs the PKCE flow on first use and stores tokens via keychain or
|
|
606
|
-
* file. Without this, the SDK relies on `CLIENT_SECRET` + manual headers.
|
|
607
|
-
*/
|
|
608
|
-
oauth?: McpOAuthConfig;
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* OAuth 2.1 PKCE flow descriptor. See ADR D41.
|
|
612
|
-
*
|
|
613
|
-
* @public
|
|
614
|
-
*/
|
|
615
|
-
interface McpOAuthConfig {
|
|
616
|
-
/** Authorization endpoint (e.g. https://api.notion.com/v1/oauth/authorize). */
|
|
617
|
-
authorizationEndpoint: string;
|
|
618
|
-
/** Token endpoint (e.g. https://api.notion.com/v1/oauth/token). */
|
|
619
|
-
tokenEndpoint: string;
|
|
620
|
-
/** Where the OAuth `code` is received. */
|
|
621
|
-
redirectMode: "manual" | "localhost";
|
|
622
|
-
/** Localhost callback port (0 = random free port, default). */
|
|
623
|
-
localhostPort?: number;
|
|
624
|
-
/** Flow timeout in ms (default 300_000 = 5min). */
|
|
625
|
-
timeoutMs?: number;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* HTTP or SSE MCP server.
|
|
629
|
-
*
|
|
630
|
-
* @public
|
|
631
|
-
*/
|
|
632
|
-
type McpHttpServerConfig = {
|
|
633
|
-
type?: "http" | "sse";
|
|
634
|
-
url: string;
|
|
635
|
-
/** Passed through. `Authorization` works here. */
|
|
636
|
-
headers?: Record<string, string>;
|
|
637
|
-
auth?: McpAuthConfig;
|
|
638
|
-
};
|
|
639
|
-
/**
|
|
640
|
-
* Union of MCP server configs. See `docs.md` for the full reference.
|
|
641
|
-
*
|
|
642
|
-
* @public
|
|
643
|
-
*/
|
|
644
|
-
type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
|
|
645
|
-
|
|
646
685
|
/**
|
|
647
686
|
* Capability slot a provider can fulfill.
|
|
648
687
|
*
|
|
@@ -746,26 +785,6 @@ interface SDKProvider {
|
|
|
746
785
|
setupSchema: object;
|
|
747
786
|
}
|
|
748
787
|
|
|
749
|
-
/**
|
|
750
|
-
* One slot in a {@link ModelSelection.params} array.
|
|
751
|
-
*
|
|
752
|
-
* @public
|
|
753
|
-
*/
|
|
754
|
-
interface ModelParameterValue {
|
|
755
|
-
id: string;
|
|
756
|
-
value: string;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Identifies a model plus optional per-model parameters (e.g. reasoning effort).
|
|
760
|
-
*
|
|
761
|
-
* Use `Theokit.models.list()` to discover valid ids and parameter definitions.
|
|
762
|
-
*
|
|
763
|
-
* @public
|
|
764
|
-
*/
|
|
765
|
-
interface ModelSelection {
|
|
766
|
-
id: string;
|
|
767
|
-
params?: ModelParameterValue[];
|
|
768
|
-
}
|
|
769
788
|
/**
|
|
770
789
|
* Which on-disk settings layers a local agent loads.
|
|
771
790
|
*
|
|
@@ -983,38 +1002,6 @@ interface MemorySettings {
|
|
|
983
1002
|
persistTranscripts?: boolean;
|
|
984
1003
|
};
|
|
985
1004
|
}
|
|
986
|
-
/**
|
|
987
|
-
* Inline custom tool — registered with the LLM under the given name + schema
|
|
988
|
-
* and dispatched locally to {@link CustomTool.handler} when the model emits a
|
|
989
|
-
* `tool_use` for it.
|
|
990
|
-
*
|
|
991
|
-
* Local runtime only (SDK v1.0). Cloud agents reject `tools` (handlers cannot
|
|
992
|
-
* cross the wire — use MCP servers or subagents for cloud tool surfaces).
|
|
993
|
-
*
|
|
994
|
-
* Handlers MUST be re-passed on `Agent.resume()` because closures cannot be
|
|
995
|
-
* persisted. The tool catalog (name + description + schema) is NOT serialized.
|
|
996
|
-
*
|
|
997
|
-
* @public
|
|
998
|
-
*/
|
|
999
|
-
interface CustomTool {
|
|
1000
|
-
/**
|
|
1001
|
-
* Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`
|
|
1002
|
-
* and must not collide with `shell`, `memory_search`, `memory_get`, or any
|
|
1003
|
-
* `mcp_*` prefix (reserved for the SDK's built-in tools).
|
|
1004
|
-
*/
|
|
1005
|
-
name: string;
|
|
1006
|
-
/** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
|
|
1007
|
-
description: string;
|
|
1008
|
-
/** JSON Schema (Draft-7 subset) describing the `input` argument. Must be `type: "object"`. */
|
|
1009
|
-
inputSchema: Record<string, unknown>;
|
|
1010
|
-
/**
|
|
1011
|
-
* Local handler invoked when the model emits `tool_use` for this tool.
|
|
1012
|
-
* Returns a string (becomes the `tool_result.content` surfaced back to the
|
|
1013
|
-
* model). Throws → SDK converts to `tool_result` with `isError: true` and
|
|
1014
|
-
* the error `message` as content.
|
|
1015
|
-
*/
|
|
1016
|
-
handler: (input: Record<string, unknown>) => string | Promise<string>;
|
|
1017
|
-
}
|
|
1018
1005
|
/**
|
|
1019
1006
|
* Telemetry configuration for an agent. When `enabled: true`, the SDK emits
|
|
1020
1007
|
* OpenTelemetry spans for `agent.send`, `llm.call`, `tool.call`, and
|
|
@@ -1148,7 +1135,7 @@ interface AgentOptions {
|
|
|
1148
1135
|
*
|
|
1149
1136
|
* @public
|
|
1150
1137
|
*/
|
|
1151
|
-
handoffs?: ReadonlyArray<SDKAgent |
|
|
1138
|
+
handoffs?: ReadonlyArray<SDKAgent | unknown>;
|
|
1152
1139
|
/**
|
|
1153
1140
|
* Maximum chain depth across handoffs per `agent.send()` call (D218).
|
|
1154
1141
|
* Default 5. Exceeding throws `HandoffLoopError`. Set to 0 to disable
|
|
@@ -1251,7 +1238,52 @@ interface AgentOptions {
|
|
|
1251
1238
|
*
|
|
1252
1239
|
* @public
|
|
1253
1240
|
*/
|
|
1254
|
-
conversationStorage?: ConversationStorageAdapter;
|
|
1241
|
+
conversationStorage?: ConversationStorageAdapter;
|
|
1242
|
+
/**
|
|
1243
|
+
* Pluggable budget/usage tracker (SDK 2.0 Phase 2 / T2.1 — ADR D1 interface
|
|
1244
|
+
* inversion). When provided, the agent loop calls `tracker.track(...)`
|
|
1245
|
+
* after each LLM completion and `tracker.check()` before each iteration.
|
|
1246
|
+
*
|
|
1247
|
+
* **Status (Phase 2 incremental):** the option is wired to the type
|
|
1248
|
+
* surface only. Agent-loop runtime wiring is additive and lands in a
|
|
1249
|
+
* subsequent iteration — for now, the kernel still uses the legacy
|
|
1250
|
+
* `UsageAccumulator` + `IterationBudget` from `internal/budget/`.
|
|
1251
|
+
* Consumers passing a custom tracker today get the type guarantee but
|
|
1252
|
+
* NOT runtime enforcement.
|
|
1253
|
+
*
|
|
1254
|
+
* Default impls available today via `@theokit/sdk`:
|
|
1255
|
+
* - `createCounterBudgetTracker({ maxTokens, maxIterations })`
|
|
1256
|
+
*
|
|
1257
|
+
* Future: post-Phase-2, `@theokit/sdk-budget` ships a richer impl with
|
|
1258
|
+
* USD pricing.
|
|
1259
|
+
*
|
|
1260
|
+
* @public
|
|
1261
|
+
*/
|
|
1262
|
+
budgetTracker?: BudgetTracker;
|
|
1263
|
+
/**
|
|
1264
|
+
* Pluggable memory subsystem (SDK 2.0 Phase 1 / T1.3 — Hexagonal
|
|
1265
|
+
* Architecture interface inversion). When provided, the agent loop
|
|
1266
|
+
* calls `provider.init(...)` once per agent, surfaces tools from
|
|
1267
|
+
* `provider.buildTools(...)` to the LLM, runs `provider.runActivePass(...)`
|
|
1268
|
+
* pre-LLM to inject recalled facts, and `provider.dispose(...)` on
|
|
1269
|
+
* Agent shutdown.
|
|
1270
|
+
*
|
|
1271
|
+
* **Status (Phase 1 incremental):** the option is wired to the type
|
|
1272
|
+
* surface only. Agent-loop runtime wiring is additive and lands in
|
|
1273
|
+
* subsequent iterations (T1.4 plumbing, T1.5 runtime hooks). For now,
|
|
1274
|
+
* the kernel still uses the legacy `Memory` class + `internal/memory/*`
|
|
1275
|
+
* runtime files. Consumers passing a custom provider today get the type
|
|
1276
|
+
* guarantee but NOT runtime enforcement.
|
|
1277
|
+
*
|
|
1278
|
+
* Default impls available today via `@theokit/sdk`:
|
|
1279
|
+
* - `createNoopMemoryProvider()` — degenerate fallback / worked example
|
|
1280
|
+
*
|
|
1281
|
+
* Future: post-Phase-1, `@theokit/sdk-memory` ships a rich impl with
|
|
1282
|
+
* LanceDB / embeddings / circuit breaker / active-memory cache.
|
|
1283
|
+
*
|
|
1284
|
+
* @public
|
|
1285
|
+
*/
|
|
1286
|
+
memoryProvider?: MemoryProvider;
|
|
1255
1287
|
}
|
|
1256
1288
|
/**
|
|
1257
1289
|
* Artifact produced inside an agent's workspace. Cloud-only.
|
|
@@ -1515,667 +1547,221 @@ interface ListResult<T> {
|
|
|
1515
1547
|
}
|
|
1516
1548
|
|
|
1517
1549
|
/**
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* @public
|
|
1521
|
-
*/
|
|
1522
|
-
interface ToolCall {
|
|
1523
|
-
callId: string;
|
|
1524
|
-
name: string;
|
|
1525
|
-
args?: unknown;
|
|
1526
|
-
result?: unknown;
|
|
1527
|
-
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Incremental text token from the assistant.
|
|
1530
|
-
*
|
|
1531
|
-
* @public
|
|
1532
|
-
*/
|
|
1533
|
-
interface TextDeltaUpdate {
|
|
1534
|
-
type: "text-delta";
|
|
1535
|
-
text: string;
|
|
1536
|
-
}
|
|
1537
|
-
/**
|
|
1538
|
-
* Incremental reasoning token.
|
|
1539
|
-
*
|
|
1540
|
-
* @public
|
|
1541
|
-
*/
|
|
1542
|
-
interface ThinkingDeltaUpdate {
|
|
1543
|
-
type: "thinking-delta";
|
|
1544
|
-
text: string;
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Emitted when a reasoning block completes.
|
|
1548
|
-
*
|
|
1549
|
-
* @public
|
|
1550
|
-
*/
|
|
1551
|
-
interface ThinkingCompletedUpdate {
|
|
1552
|
-
type: "thinking-completed";
|
|
1553
|
-
thinkingDurationMs: number;
|
|
1554
|
-
}
|
|
1555
|
-
/**
|
|
1556
|
-
* Tool call started — args committed.
|
|
1557
|
-
*
|
|
1558
|
-
* @public
|
|
1559
|
-
*/
|
|
1560
|
-
interface ToolCallStartedUpdate {
|
|
1561
|
-
type: "tool-call-started";
|
|
1562
|
-
callId: string;
|
|
1563
|
-
toolCall: ToolCall;
|
|
1564
|
-
modelCallId: string;
|
|
1565
|
-
}
|
|
1566
|
-
/**
|
|
1567
|
-
* Tool call arguments streaming in incrementally.
|
|
1568
|
-
*
|
|
1569
|
-
* @public
|
|
1570
|
-
*/
|
|
1571
|
-
interface PartialToolCallUpdate {
|
|
1572
|
-
type: "partial-tool-call";
|
|
1573
|
-
callId: string;
|
|
1574
|
-
toolCall: ToolCall;
|
|
1575
|
-
modelCallId: string;
|
|
1576
|
-
}
|
|
1577
|
-
/**
|
|
1578
|
-
* Tool call completed.
|
|
1579
|
-
*
|
|
1580
|
-
* @public
|
|
1581
|
-
*/
|
|
1582
|
-
interface ToolCallCompletedUpdate {
|
|
1583
|
-
type: "tool-call-completed";
|
|
1584
|
-
callId: string;
|
|
1585
|
-
toolCall: ToolCall;
|
|
1586
|
-
modelCallId: string;
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
* Token count delta for usage tracking.
|
|
1590
|
-
*
|
|
1591
|
-
* @public
|
|
1592
|
-
*/
|
|
1593
|
-
interface TokenDeltaUpdate {
|
|
1594
|
-
type: "token-delta";
|
|
1595
|
-
tokens: number;
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Conversation step started.
|
|
1599
|
-
*
|
|
1600
|
-
* @public
|
|
1601
|
-
*/
|
|
1602
|
-
interface StepStartedUpdate {
|
|
1603
|
-
type: "step-started";
|
|
1604
|
-
stepId: number;
|
|
1605
|
-
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Conversation step completed.
|
|
1608
|
-
*
|
|
1609
|
-
* @public
|
|
1610
|
-
*/
|
|
1611
|
-
interface StepCompletedUpdate {
|
|
1612
|
-
type: "step-completed";
|
|
1613
|
-
stepId: number;
|
|
1614
|
-
stepDurationMs: number;
|
|
1615
|
-
}
|
|
1616
|
-
/**
|
|
1617
|
-
* Turn ended with usage summary.
|
|
1618
|
-
*
|
|
1619
|
-
* @public
|
|
1620
|
-
*/
|
|
1621
|
-
interface TurnEndedUpdate {
|
|
1622
|
-
type: "turn-ended";
|
|
1623
|
-
usage?: {
|
|
1624
|
-
inputTokens: number;
|
|
1625
|
-
outputTokens: number;
|
|
1626
|
-
cacheReadTokens: number;
|
|
1627
|
-
cacheWriteTokens: number;
|
|
1628
|
-
};
|
|
1629
|
-
}
|
|
1630
|
-
/**
|
|
1631
|
-
* User message appended to the conversation.
|
|
1550
|
+
* Runtime hosting a cron job. Mirrors the agent runtime split.
|
|
1632
1551
|
*
|
|
1633
|
-
*
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
userMessage: UserMessage;
|
|
1638
|
-
}
|
|
1639
|
-
/** @public */
|
|
1640
|
-
interface SummaryUpdate {
|
|
1641
|
-
type: "summary";
|
|
1642
|
-
summary: string;
|
|
1643
|
-
}
|
|
1644
|
-
/** @public */
|
|
1645
|
-
interface SummaryStartedUpdate {
|
|
1646
|
-
type: "summary-started";
|
|
1647
|
-
}
|
|
1648
|
-
/** @public */
|
|
1649
|
-
interface SummaryCompletedUpdate {
|
|
1650
|
-
type: "summary-completed";
|
|
1651
|
-
}
|
|
1652
|
-
/** @public */
|
|
1653
|
-
interface ShellOutputDeltaUpdate {
|
|
1654
|
-
type: "shell-output-delta";
|
|
1655
|
-
event: Record<string, unknown>;
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* Lowest-level raw update from a run. Pass `onDelta` to `agent.send()` to
|
|
1659
|
-
* consume these. Finer-grained than `SDKMessage` events.
|
|
1552
|
+
* - `local` — the in-process scheduler activated via `Cron.start()` fires the
|
|
1553
|
+
* job while the host process is alive.
|
|
1554
|
+
* - `cloud` — Theo PaaS schedules the job server-side; fires independent of
|
|
1555
|
+
* any SDK process.
|
|
1660
1556
|
*
|
|
1661
1557
|
* @public
|
|
1662
1558
|
*/
|
|
1663
|
-
type
|
|
1664
|
-
|
|
1559
|
+
type CronRuntime = "local" | "cloud";
|
|
1665
1560
|
/**
|
|
1666
|
-
*
|
|
1561
|
+
* Lifecycle state reported by `Cron.list()` / `Cron.get()`.
|
|
1667
1562
|
*
|
|
1668
1563
|
* @public
|
|
1669
1564
|
*/
|
|
1670
|
-
|
|
1671
|
-
text: string;
|
|
1672
|
-
}
|
|
1565
|
+
type CronJobStatus = "scheduled" | "running" | "paused" | "errored";
|
|
1673
1566
|
/**
|
|
1674
|
-
*
|
|
1567
|
+
* Persistent cron-scheduled invocation of the Theo agent.
|
|
1675
1568
|
*
|
|
1676
|
-
* @
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
text: string;
|
|
1680
|
-
thinkingDurationMs?: number;
|
|
1681
|
-
}
|
|
1682
|
-
/**
|
|
1683
|
-
* User-authored message in a conversation history.
|
|
1569
|
+
* Exactly one of {@link CronJob.agent} (ephemeral agent created on each fire)
|
|
1570
|
+
* or {@link CronJob.agentId} (bound to an existing agent for context
|
|
1571
|
+
* continuity) is set.
|
|
1684
1572
|
*
|
|
1685
1573
|
* @public
|
|
1686
1574
|
*/
|
|
1687
|
-
interface
|
|
1688
|
-
|
|
1575
|
+
interface CronJob {
|
|
1576
|
+
id: string;
|
|
1577
|
+
name?: string;
|
|
1578
|
+
/** Standard 5-field POSIX cron expression or shorthand (`@hourly`, `@daily`, ...). */
|
|
1579
|
+
cron: string;
|
|
1580
|
+
/** IANA timezone identifier. Defaults to `"UTC"`. */
|
|
1581
|
+
timezone?: string;
|
|
1582
|
+
/** Message sent to the agent on each fire. */
|
|
1583
|
+
message: string | SDKUserMessage;
|
|
1584
|
+
/** Ephemeral agent options. Mutually exclusive with `agentId`. */
|
|
1585
|
+
agent?: AgentOptions;
|
|
1586
|
+
/** ID of an existing agent to reuse for context continuity. Mutually exclusive with `agent`. */
|
|
1587
|
+
agentId?: string;
|
|
1588
|
+
/** Whether the scheduler will fire this job on schedule. */
|
|
1589
|
+
enabled: boolean;
|
|
1590
|
+
/** Current status. */
|
|
1591
|
+
status: CronJobStatus;
|
|
1592
|
+
/** Runtime that hosts this job. Inferred from `agent`/`agentId` at create time. */
|
|
1593
|
+
runtime: CronRuntime;
|
|
1594
|
+
/** Unix ms of the last successful fire, if any. */
|
|
1595
|
+
lastRunAt?: number;
|
|
1596
|
+
/** Unix ms of the next scheduled fire, computed by the scheduler. */
|
|
1597
|
+
nextRunAt?: number;
|
|
1598
|
+
/** Unix ms when the job was created. */
|
|
1599
|
+
createdAt: number;
|
|
1689
1600
|
}
|
|
1690
1601
|
/**
|
|
1691
|
-
*
|
|
1602
|
+
* Options for `Cron.create()`.
|
|
1692
1603
|
*
|
|
1693
|
-
*
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
command: string;
|
|
1697
|
-
workingDirectory?: string;
|
|
1698
|
-
}
|
|
1699
|
-
/**
|
|
1700
|
-
* Output of a shell command.
|
|
1604
|
+
* Pass `agent` for an ephemeral agent created fresh on each fire, OR
|
|
1605
|
+
* `agentId` to reuse an existing agent (preserves conversation context across
|
|
1606
|
+
* fires). Setting both is a `ConfigurationError`.
|
|
1701
1607
|
*
|
|
1702
1608
|
* @public
|
|
1703
1609
|
*/
|
|
1704
|
-
interface
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1610
|
+
interface CronCreateOptions {
|
|
1611
|
+
cron: string;
|
|
1612
|
+
message: string | SDKUserMessage;
|
|
1613
|
+
agent?: AgentOptions;
|
|
1614
|
+
agentId?: string;
|
|
1615
|
+
name?: string;
|
|
1616
|
+
timezone?: string;
|
|
1617
|
+
/** Defaults to `true`. */
|
|
1618
|
+
enabled?: boolean;
|
|
1619
|
+
/** Falls back to `THEOKIT_API_KEY`. */
|
|
1620
|
+
apiKey?: string;
|
|
1708
1621
|
}
|
|
1709
1622
|
/**
|
|
1710
|
-
*
|
|
1623
|
+
* Options for `Cron.list()`.
|
|
1711
1624
|
*
|
|
1712
1625
|
* @public
|
|
1713
1626
|
*/
|
|
1714
|
-
type
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
message: ToolCall;
|
|
1627
|
+
type CronListOptions = {
|
|
1628
|
+
limit?: number;
|
|
1629
|
+
cursor?: string;
|
|
1630
|
+
} & ({
|
|
1631
|
+
runtime?: undefined;
|
|
1720
1632
|
} | {
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
};
|
|
1724
|
-
/**
|
|
1725
|
-
* Agent turn: user message + assistant/tool/thinking steps.
|
|
1726
|
-
*
|
|
1727
|
-
* @public
|
|
1728
|
-
*/
|
|
1729
|
-
interface AgentConversationTurn {
|
|
1730
|
-
userMessage?: UserMessage;
|
|
1731
|
-
steps: ConversationStep[];
|
|
1732
|
-
}
|
|
1733
|
-
/**
|
|
1734
|
-
* Shell turn: a command and its output.
|
|
1735
|
-
*
|
|
1736
|
-
* @public
|
|
1737
|
-
*/
|
|
1738
|
-
interface ShellConversationTurn {
|
|
1739
|
-
shellCommand?: ShellCommand;
|
|
1740
|
-
shellOutput?: ShellOutput;
|
|
1741
|
-
}
|
|
1742
|
-
/**
|
|
1743
|
-
* Structured per-turn view of a run.
|
|
1744
|
-
*
|
|
1745
|
-
* @public
|
|
1746
|
-
*/
|
|
1747
|
-
type ConversationTurn = {
|
|
1748
|
-
type: "agentConversationTurn";
|
|
1749
|
-
turn: AgentConversationTurn;
|
|
1633
|
+
runtime: "local";
|
|
1634
|
+
cwd?: string;
|
|
1750
1635
|
} | {
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
};
|
|
1754
|
-
|
|
1755
|
-
/**
|
|
1756
|
-
* Plain text content block emitted by the assistant or user.
|
|
1757
|
-
*
|
|
1758
|
-
* @public
|
|
1759
|
-
*/
|
|
1760
|
-
interface TextBlock {
|
|
1761
|
-
type: "text";
|
|
1762
|
-
text: string;
|
|
1763
|
-
}
|
|
1764
|
-
/**
|
|
1765
|
-
* Tool invocation block emitted by the assistant.
|
|
1766
|
-
*
|
|
1767
|
-
* @public
|
|
1768
|
-
*/
|
|
1769
|
-
interface ToolUseBlock {
|
|
1770
|
-
type: "tool_use";
|
|
1771
|
-
id: string;
|
|
1772
|
-
name: string;
|
|
1773
|
-
/** Tool args are not part of the stable schema. Treat as unknown and parse defensively. */
|
|
1774
|
-
input: unknown;
|
|
1775
|
-
}
|
|
1776
|
-
/**
|
|
1777
|
-
* Init metadata. Emitted once at the start of a run.
|
|
1778
|
-
*
|
|
1779
|
-
* @public
|
|
1780
|
-
*/
|
|
1781
|
-
interface SDKSystemMessage {
|
|
1782
|
-
type: "system";
|
|
1783
|
-
subtype?: "init";
|
|
1784
|
-
agent_id: string;
|
|
1785
|
-
run_id: string;
|
|
1786
|
-
model?: ModelSelection;
|
|
1787
|
-
tools?: string[];
|
|
1788
|
-
}
|
|
1789
|
-
/**
|
|
1790
|
-
* Echo of the user prompt for this run.
|
|
1791
|
-
*
|
|
1792
|
-
* @public
|
|
1793
|
-
*/
|
|
1794
|
-
interface SDKUserMessageEvent {
|
|
1795
|
-
type: "user";
|
|
1796
|
-
agent_id: string;
|
|
1797
|
-
run_id: string;
|
|
1798
|
-
message: {
|
|
1799
|
-
role: "user";
|
|
1800
|
-
content: TextBlock[];
|
|
1801
|
-
};
|
|
1802
|
-
}
|
|
1803
|
-
/**
|
|
1804
|
-
* Model text output for this run.
|
|
1805
|
-
*
|
|
1806
|
-
* @public
|
|
1807
|
-
*/
|
|
1808
|
-
interface SDKAssistantMessage {
|
|
1809
|
-
type: "assistant";
|
|
1810
|
-
agent_id: string;
|
|
1811
|
-
run_id: string;
|
|
1812
|
-
message: {
|
|
1813
|
-
role: "assistant";
|
|
1814
|
-
content: Array<TextBlock | ToolUseBlock>;
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
/**
|
|
1818
|
-
* Reasoning content.
|
|
1819
|
-
*
|
|
1820
|
-
* @public
|
|
1821
|
-
*/
|
|
1822
|
-
interface SDKThinkingMessage {
|
|
1823
|
-
type: "thinking";
|
|
1824
|
-
agent_id: string;
|
|
1825
|
-
run_id: string;
|
|
1826
|
-
text: string;
|
|
1827
|
-
thinking_duration_ms?: number;
|
|
1828
|
-
}
|
|
1829
|
-
/**
|
|
1830
|
-
* Tool invocation lifecycle event. Emitted at start with `args`, then again on
|
|
1831
|
-
* completion with `result`.
|
|
1832
|
-
*
|
|
1833
|
-
* Tool `args` and `result` are NOT part of the stable schema — treat as unknown.
|
|
1834
|
-
*
|
|
1835
|
-
* @public
|
|
1836
|
-
*/
|
|
1837
|
-
interface SDKToolUseMessage {
|
|
1838
|
-
type: "tool_call";
|
|
1839
|
-
agent_id: string;
|
|
1840
|
-
run_id: string;
|
|
1841
|
-
call_id: string;
|
|
1842
|
-
name: string;
|
|
1843
|
-
status: "running" | "completed" | "error";
|
|
1844
|
-
args?: unknown;
|
|
1845
|
-
result?: unknown;
|
|
1846
|
-
truncated?: {
|
|
1847
|
-
args?: boolean;
|
|
1848
|
-
result?: boolean;
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1636
|
+
runtime: "cloud";
|
|
1637
|
+
apiKey?: string;
|
|
1638
|
+
});
|
|
1851
1639
|
/**
|
|
1852
|
-
*
|
|
1640
|
+
* Options for `Cron.get()`.
|
|
1853
1641
|
*
|
|
1854
1642
|
* @public
|
|
1855
1643
|
*/
|
|
1856
|
-
interface
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
run_id: string;
|
|
1860
|
-
status: "CREATING" | "RUNNING" | "FINISHED" | "ERROR" | "CANCELLED" | "EXPIRED";
|
|
1861
|
-
message?: string;
|
|
1644
|
+
interface CronGetOptions {
|
|
1645
|
+
cwd?: string;
|
|
1646
|
+
apiKey?: string;
|
|
1862
1647
|
}
|
|
1863
1648
|
/**
|
|
1864
|
-
*
|
|
1649
|
+
* Options for `Cron.delete()` / `Cron.enable()` / `Cron.disable()`.
|
|
1865
1650
|
*
|
|
1866
1651
|
* @public
|
|
1867
1652
|
*/
|
|
1868
|
-
interface
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
run_id: string;
|
|
1872
|
-
status?: string;
|
|
1873
|
-
text?: string;
|
|
1653
|
+
interface CronOperationOptions {
|
|
1654
|
+
cwd?: string;
|
|
1655
|
+
apiKey?: string;
|
|
1874
1656
|
}
|
|
1875
1657
|
/**
|
|
1876
|
-
*
|
|
1658
|
+
* Options for `Cron.run()` — manually trigger a job off-schedule.
|
|
1877
1659
|
*
|
|
1878
1660
|
* @public
|
|
1879
1661
|
*/
|
|
1880
|
-
interface
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
run_id: string;
|
|
1884
|
-
request_id: string;
|
|
1662
|
+
interface CronRunOptions {
|
|
1663
|
+
cwd?: string;
|
|
1664
|
+
apiKey?: string;
|
|
1885
1665
|
}
|
|
1886
1666
|
/**
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
1889
|
-
* erased to `unknown` here because SDKMessage union is non-generic.
|
|
1667
|
+
* Options for `Cron.start()` — activates the in-process scheduler for local
|
|
1668
|
+
* jobs.
|
|
1890
1669
|
*
|
|
1891
1670
|
* @public
|
|
1892
1671
|
*/
|
|
1893
|
-
interface
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
attempt: number;
|
|
1672
|
+
interface CronStartOptions {
|
|
1673
|
+
/** Local workspace whose `.theokit/cron/jobs.json` to load. Defaults to `process.cwd()`. */
|
|
1674
|
+
cwd?: string;
|
|
1675
|
+
/** Override the env API key. */
|
|
1676
|
+
apiKey?: string;
|
|
1899
1677
|
}
|
|
1900
1678
|
/**
|
|
1901
|
-
*
|
|
1902
|
-
*
|
|
1903
|
-
* All events include `agent_id` and `run_id`.
|
|
1904
|
-
*
|
|
1905
|
-
* @public
|
|
1906
|
-
*/
|
|
1907
|
-
type SDKMessage = SDKSystemMessage | SDKUserMessageEvent | SDKAssistantMessage | SDKThinkingMessage | SDKToolUseMessage | SDKStatusMessage | SDKTaskMessage | SDKRequestMessage | SDKObjectDelta;
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* Public type contract for token usage + cost tracking (ADRs D376-D379).
|
|
1911
|
-
*
|
|
1912
|
-
* Surfaces via `RunResult.usage` + `RunResult.cost` after every Run.
|
|
1913
|
-
* Re-exported through the package barrel; consumers import from
|
|
1914
|
-
* `@theokit/sdk`.
|
|
1679
|
+
* Snapshot of the local scheduler returned by `Cron.status()`.
|
|
1915
1680
|
*
|
|
1916
1681
|
* @public
|
|
1917
1682
|
*/
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
readonly inputTokens: number;
|
|
1931
|
-
readonly outputTokens: number;
|
|
1932
|
-
readonly cacheReadTokens?: number;
|
|
1933
|
-
readonly cacheWriteTokens?: number;
|
|
1934
|
-
readonly reasoningTokens?: number;
|
|
1935
|
-
readonly totalTokens: number;
|
|
1936
|
-
/** Per-request breakdown; absent when the run made a single LLM call. */
|
|
1937
|
-
readonly requests?: ReadonlyArray<Omit<TokenUsage, "requests">>;
|
|
1938
|
-
}
|
|
1939
|
-
/**
|
|
1940
|
-
* Cost confidence level (D377).
|
|
1941
|
-
* - `actual`: returned by a provider billing API (e.g. OpenRouter `/generation`).
|
|
1942
|
-
* - `estimated`: computed from bundled pricing snapshot.
|
|
1943
|
-
* - `included`: subscription-included route (Codex CLI, Claude Pro).
|
|
1944
|
-
* - `unknown`: pricing data unavailable; `amountUsd` is undefined.
|
|
1945
|
-
*/
|
|
1946
|
-
type CostStatus = "actual" | "estimated" | "included" | "unknown";
|
|
1947
|
-
/** Source of the cost figure for caller-side audit. */
|
|
1948
|
-
type CostSource = "openrouter_api" | "litellm_snapshot" | "user_override" | "subscription_included" | "unknown";
|
|
1949
|
-
/**
|
|
1950
|
-
* Cost breakdown attached to `RunResult.cost`. When `status === "unknown"`,
|
|
1951
|
-
* `amountUsd` is `undefined` — DO NOT default to 0 (mentira). UI exibe
|
|
1952
|
-
* `n/a` para unknown, `~$1.23` para estimated, `$1.23` para actual.
|
|
1953
|
-
*/
|
|
1954
|
-
interface CostBreakdown {
|
|
1955
|
-
readonly amountUsd: number | undefined;
|
|
1956
|
-
readonly status: CostStatus;
|
|
1957
|
-
readonly currency: "USD";
|
|
1958
|
-
readonly source: CostSource;
|
|
1959
|
-
readonly pricingVersion: string | undefined;
|
|
1960
|
-
readonly notes?: ReadonlyArray<string>;
|
|
1961
|
-
/** Per-bucket detail (in USD) for caller analytics. */
|
|
1962
|
-
readonly detail?: {
|
|
1963
|
-
readonly input?: number;
|
|
1964
|
-
readonly output?: number;
|
|
1965
|
-
readonly cacheRead?: number;
|
|
1966
|
-
readonly cacheWrite?: number;
|
|
1967
|
-
readonly reasoning?: number;
|
|
1683
|
+
interface CronSchedulerStatus {
|
|
1684
|
+
/** Whether the in-process scheduler is currently running. */
|
|
1685
|
+
running: boolean;
|
|
1686
|
+
/** Number of jobs loaded into the scheduler. */
|
|
1687
|
+
jobCount: number;
|
|
1688
|
+
/** Unix ms of the next scheduled fire across all jobs, if any. */
|
|
1689
|
+
nextFireAt?: number;
|
|
1690
|
+
/** Last error observed in the scheduler, if any. */
|
|
1691
|
+
lastError?: {
|
|
1692
|
+
jobId: string;
|
|
1693
|
+
message: string;
|
|
1694
|
+
at: number;
|
|
1968
1695
|
};
|
|
1969
1696
|
}
|
|
1970
1697
|
|
|
1971
1698
|
/**
|
|
1972
|
-
*
|
|
1973
|
-
*
|
|
1974
|
-
* @public
|
|
1975
|
-
*/
|
|
1976
|
-
type RunStatus = "running" | "finished" | "error" | "cancelled";
|
|
1977
|
-
/**
|
|
1978
|
-
* Operations that may or may not be supported on a given {@link Run}, or on
|
|
1979
|
-
* its parent agent.
|
|
1980
|
-
*
|
|
1981
|
-
* Runtime-specific availability — query at runtime with `run.supports(op)` and
|
|
1982
|
-
* read the human reason via `run.unsupportedReason(op)`.
|
|
1983
|
-
*
|
|
1984
|
-
* @public
|
|
1985
|
-
*/
|
|
1986
|
-
type RunOperation = "stream" | "wait" | "cancel" | "conversation" | "listArtifacts" | "downloadArtifact" | "runUntil" | "fork" | "usePersonality" | "workflow";
|
|
1987
|
-
/**
|
|
1988
|
-
* Git metadata attached to cloud runs.
|
|
1699
|
+
* Static façade for scheduling Theo agent runs on a cron expression.
|
|
1989
1700
|
*
|
|
1990
1701
|
* @public
|
|
1991
1702
|
*/
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
repoUrl: string;
|
|
1995
|
-
branch?: string;
|
|
1996
|
-
prUrl?: string;
|
|
1997
|
-
}>;
|
|
1998
|
-
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Terminal result of a {@link Run}.
|
|
2001
|
-
*
|
|
2002
|
-
* @public
|
|
2003
|
-
*/
|
|
2004
|
-
interface RunResult {
|
|
2005
|
-
id: string;
|
|
2006
|
-
status: "finished" | "error" | "cancelled";
|
|
2007
|
-
result?: string;
|
|
2008
|
-
model?: ModelSelection;
|
|
2009
|
-
durationMs?: number;
|
|
2010
|
-
git?: RunGitInfo;
|
|
1703
|
+
declare class Cron {
|
|
1704
|
+
private constructor();
|
|
2011
1705
|
/**
|
|
2012
|
-
*
|
|
2013
|
-
* the diagnostic that emit-error-event pushes into the stream so callers
|
|
2014
|
-
* that don't drain `run.stream()` still get the cause via `run.wait()`.
|
|
1706
|
+
* Create and persist a cron job.
|
|
2015
1707
|
*
|
|
2016
|
-
*
|
|
1708
|
+
* @public
|
|
1709
|
+
*/
|
|
1710
|
+
static create(options: CronCreateOptions): Promise<CronJob>;
|
|
1711
|
+
/**
|
|
1712
|
+
* List cron jobs (local, cloud, or both).
|
|
2017
1713
|
*
|
|
2018
1714
|
* @public
|
|
2019
1715
|
*/
|
|
2020
|
-
|
|
1716
|
+
static list(options?: CronListOptions): Promise<ListResult<CronJob>>;
|
|
2021
1717
|
/**
|
|
2022
|
-
*
|
|
2023
|
-
* status where ≥1 LLM call completed — including partial-failure
|
|
2024
|
-
* runs (EC-5). `undefined` only when zero LLM calls executed (e.g.,
|
|
2025
|
-
* abort before send).
|
|
1718
|
+
* Get a single cron job by ID.
|
|
2026
1719
|
*
|
|
2027
1720
|
* @public
|
|
2028
1721
|
*/
|
|
2029
|
-
|
|
1722
|
+
static get(jobId: string, _options?: CronGetOptions): Promise<CronJob>;
|
|
2030
1723
|
/**
|
|
2031
|
-
*
|
|
2032
|
-
* with `usage` when populated. `cost.status` tells caller how to
|
|
2033
|
-
* trust the figure.
|
|
1724
|
+
* Delete a cron job permanently.
|
|
2034
1725
|
*
|
|
2035
1726
|
* @public
|
|
2036
1727
|
*/
|
|
2037
|
-
|
|
2038
|
-
}
|
|
2039
|
-
/**
|
|
2040
|
-
* Structured error attached to a {@link RunResult} when the underlying run
|
|
2041
|
-
* transitioned to `"error"` status. `message` is always present; `code` is
|
|
2042
|
-
* a stable identifier suitable for branching (e.g. `"llm_4xx"`,
|
|
2043
|
-
* `"tool_dispatch_failed"`, `"mcp_init_failed"`); `cause` is the raw error
|
|
2044
|
-
* for further inspection when available.
|
|
2045
|
-
*
|
|
2046
|
-
* @public
|
|
2047
|
-
*/
|
|
2048
|
-
interface RunErrorDetail {
|
|
2049
|
-
message: string;
|
|
2050
|
-
code?: string;
|
|
2051
|
-
cause?: unknown;
|
|
2052
|
-
}
|
|
2053
|
-
/**
|
|
2054
|
-
* Dimensions of an inline image attachment.
|
|
2055
|
-
*
|
|
2056
|
-
* @public
|
|
2057
|
-
*/
|
|
2058
|
-
interface SDKImageDimension {
|
|
2059
|
-
width: number;
|
|
2060
|
-
height: number;
|
|
2061
|
-
}
|
|
2062
|
-
/**
|
|
2063
|
-
* Either a remote URL or inline base64 payload.
|
|
2064
|
-
*
|
|
2065
|
-
* @public
|
|
2066
|
-
*/
|
|
2067
|
-
type SDKImage = {
|
|
2068
|
-
url: string;
|
|
2069
|
-
dimension?: SDKImageDimension;
|
|
2070
|
-
} | {
|
|
2071
|
-
data: string;
|
|
2072
|
-
mimeType: string;
|
|
2073
|
-
dimension?: SDKImageDimension;
|
|
2074
|
-
};
|
|
2075
|
-
/**
|
|
2076
|
-
* Structured form of `agent.send()`'s message argument. Use it to send images
|
|
2077
|
-
* alongside text.
|
|
2078
|
-
*
|
|
2079
|
-
* @public
|
|
2080
|
-
*/
|
|
2081
|
-
interface SDKUserMessage {
|
|
2082
|
-
text: string;
|
|
2083
|
-
images?: SDKImage[];
|
|
2084
|
-
}
|
|
2085
|
-
/**
|
|
2086
|
-
* Per-send overrides and callbacks.
|
|
2087
|
-
*
|
|
2088
|
-
* @public
|
|
2089
|
-
*/
|
|
2090
|
-
interface SendOptions {
|
|
2091
|
-
model?: ModelSelection;
|
|
1728
|
+
static delete(jobId: string, _options?: CronOperationOptions): Promise<void>;
|
|
2092
1729
|
/**
|
|
2093
|
-
*
|
|
2094
|
-
*
|
|
2095
|
-
*
|
|
1730
|
+
* Re-enable a paused cron job.
|
|
1731
|
+
*
|
|
1732
|
+
* @public
|
|
2096
1733
|
*/
|
|
2097
|
-
|
|
2098
|
-
/** Fully replaces creation-time servers for this run (not merged). */
|
|
2099
|
-
mcpServers?: Record<string, McpServerConfig>;
|
|
1734
|
+
static enable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
|
|
2100
1735
|
/**
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2103
|
-
*
|
|
2104
|
-
* (`cloud_custom_tools_rejected`). Semantics:
|
|
2105
|
-
* - `undefined` → fall back to `AgentOptions.tools`
|
|
2106
|
-
* - `[]` → explicitly clear (no custom tools for this run)
|
|
2107
|
-
* - `[t1, t2]` → use exactly these tools for this run
|
|
1736
|
+
* Pause a cron job without deleting it.
|
|
1737
|
+
*
|
|
1738
|
+
* @public
|
|
2108
1739
|
*/
|
|
2109
|
-
|
|
2110
|
-
onStep?: (args: {
|
|
2111
|
-
step: ConversationStep;
|
|
2112
|
-
}) => void | Promise<void>;
|
|
2113
|
-
onDelta?: (args: {
|
|
2114
|
-
update: InteractionUpdate;
|
|
2115
|
-
}) => void | Promise<void>;
|
|
2116
|
-
/** Local agents only. Expire a stuck active run before starting this message. */
|
|
2117
|
-
local?: {
|
|
2118
|
-
force?: boolean;
|
|
2119
|
-
};
|
|
1740
|
+
static disable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
|
|
2120
1741
|
/**
|
|
2121
|
-
*
|
|
2122
|
-
* hooks (EC-H). Note: the LLM HTTP call itself is NOT cancellable
|
|
2123
|
-
* mid-stream — same constraint as `Agent.batch` (ADR D140).
|
|
1742
|
+
* Manually trigger a cron job off-schedule. Returns the resulting `Run`.
|
|
2124
1743
|
*
|
|
2125
1744
|
* @public
|
|
2126
1745
|
*/
|
|
2127
|
-
|
|
1746
|
+
static run(jobId: string, _options?: CronRunOptions): Promise<Run>;
|
|
2128
1747
|
/**
|
|
2129
|
-
*
|
|
2130
|
-
* run is registered as a `Task` in the SDK's observable registry —
|
|
2131
|
-
* caller can list / inspect / cancel / subscribe via the `Task`
|
|
2132
|
-
* namespace. Default behavior (no `task` option) is byte-identical
|
|
2133
|
-
* to v1.1 (no Task overhead).
|
|
1748
|
+
* Activate the in-process scheduler for local cron jobs.
|
|
2134
1749
|
*
|
|
2135
|
-
*
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
1750
|
+
* @public
|
|
1751
|
+
*/
|
|
1752
|
+
static start(options?: CronStartOptions): Promise<void>;
|
|
1753
|
+
/**
|
|
1754
|
+
* Stop the in-process scheduler. Jobs are preserved.
|
|
2139
1755
|
*
|
|
2140
|
-
*
|
|
2141
|
-
|
|
2142
|
-
|
|
1756
|
+
* @public
|
|
1757
|
+
*/
|
|
1758
|
+
static stop(): Promise<void>;
|
|
1759
|
+
/**
|
|
1760
|
+
* Snapshot of the local scheduler.
|
|
2143
1761
|
*
|
|
2144
1762
|
* @public
|
|
2145
1763
|
*/
|
|
2146
|
-
|
|
2147
|
-
id?: string;
|
|
2148
|
-
meta?: Record<string, unknown>;
|
|
2149
|
-
};
|
|
2150
|
-
}
|
|
2151
|
-
/**
|
|
2152
|
-
* Handle to a single prompt submission.
|
|
2153
|
-
*
|
|
2154
|
-
* @public
|
|
2155
|
-
*/
|
|
2156
|
-
interface Run {
|
|
2157
|
-
readonly id: string;
|
|
2158
|
-
readonly agentId: string;
|
|
2159
|
-
readonly status: RunStatus;
|
|
2160
|
-
readonly result?: string;
|
|
2161
|
-
readonly model?: ModelSelection;
|
|
2162
|
-
readonly durationMs?: number;
|
|
2163
|
-
readonly git?: RunGitInfo;
|
|
2164
|
-
readonly createdAt?: number;
|
|
2165
|
-
/** AsyncGenerator of normalized stream events. Discriminate on `event.type`. */
|
|
2166
|
-
stream(): AsyncGenerator<SDKMessage, void>;
|
|
2167
|
-
/** Resolves to the terminal {@link RunResult}. */
|
|
2168
|
-
wait(): Promise<RunResult>;
|
|
2169
|
-
/** Move status to `"cancelled"`, abort the stream, stop in-flight tool calls. */
|
|
2170
|
-
cancel(): Promise<void>;
|
|
2171
|
-
/** Structured per-turn view of the conversation. */
|
|
2172
|
-
conversation(): Promise<ConversationTurn[]>;
|
|
2173
|
-
/** Whether the given operation is available on this run's runtime. */
|
|
2174
|
-
supports(operation: RunOperation): boolean;
|
|
2175
|
-
/** Human-readable reason that `supports(operation)` returned `false`. */
|
|
2176
|
-
unsupportedReason(operation: RunOperation): string | undefined;
|
|
2177
|
-
/** Subscribe to status changes. Returns an unsubscribe function. */
|
|
2178
|
-
onDidChangeStatus(listener: (status: RunStatus) => void): () => void;
|
|
1764
|
+
static status(_options?: CronStartOptions): Promise<CronSchedulerStatus>;
|
|
2179
1765
|
}
|
|
2180
1766
|
|
|
2181
|
-
export {
|
|
1767
|
+
export { type MemoryAdapter as $, type AgentOptions as A, type BudgetTracker as B, type CloudOptions as C, type ContextManagerKind as D, type ContextSnapshot as E, type ContextSource as F, type GetAgentOptions as G, type ContextSourceStatus as H, Cron as I, type CronCreateOptions as J, type CronGetOptions as K, type LocalOptions as L, type MemorySettings as M, type CronJob as N, type CronJobStatus as O, type ProviderRoutingSettings as P, type CronListOptions as Q, type CronOperationOptions as R, type SystemPromptResolver as S, type CronRunOptions as T, type CronRuntime as U, type CronSchedulerStatus as V, type CronStartOptions as W, type GoalEvent as X, type GoalOptions as Y, type GoalResult as Z, type InvalidateCacheOptions as _, type AgentDefinition as a, type MemoryAdapterCapabilities as a0, type MemoryFact as a1, type MemoryProviderHandle as a2, type MemoryProviderInitOptions as a3, type MemoryRevision as a4, type MemoryToolSchema as a5, type MemoryTurnMessage as a6, type PersonalityPreset as a7, type ProviderCapability as a8, type ProviderRoute as a9, type RecordSessionSummaryArgs as aa, type ResolvedProviderRoute as ab, type RunUntilIterator as ac, type SDKAgentPlugins as ad, type SDKAgentSkills as ae, type SDKArtifact as af, type SDKContextManager as ag, type SDKPluginMetadata as ah, type SDKProvidersManager as ai, type SettingSource as aj, type SystemPromptContext as ak, type SystemPromptMemoryFact as al, type SystemPromptSkillRef as am, type TelemetrySettings as an, type ContextSettings as b, type PluginsSettings as c, type SkillsSettings as d, type SDKAgent as e, type ListAgentsOptions as f, type ListResult as g, type SDKAgentInfo as h, type ListRunsOptions as i, type GetRunOptions as j, type AgentOperationOptions as k, type ConversationStorageAdapter as l, type StoredMessage as m, type MemoryContext as n, type MemoryProvider as o, type MemoryId as p, type SDKProvider as q, type ActiveMemoryPassArgs as r, type ActiveMemoryPassResult as s, type AgentMemory as t, type BudgetCheck as u, type BudgetTotal as v, type BudgetUsageEvent as w, type CloudEnv as x, type CloudRepo as y, type ContextBudget as z };
|