@theokit/sdk 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1571 -0
- package/LICENSE +201 -0
- package/README.md +80 -0
- package/bin/theokit-migrate-config.mjs +269 -0
- package/bin/theokit-migrate-memory.mjs +116 -0
- package/dist/agent-builder.d.ts +52 -0
- package/dist/agent-factory.d.ts +39 -0
- package/dist/agent.d.ts +175 -0
- package/dist/batch.d.ts +11 -0
- package/dist/budget.d.ts +48 -0
- package/dist/cache.d.ts +74 -0
- package/dist/cron-1yxL3K2S.d.cts +221 -0
- package/dist/cron-BYVdYzob.d.ts +221 -0
- package/dist/cron.cjs +14655 -0
- package/dist/cron.cjs.map +1 -0
- package/dist/cron.d.cts +3 -0
- package/dist/cron.d.ts +71 -0
- package/dist/cron.js +14652 -0
- package/dist/cron.js.map +1 -0
- package/dist/define-tool.d.ts +35 -0
- package/dist/errors-CK8brCJ1.d.cts +448 -0
- package/dist/errors-CvAeEWgE.d.ts +448 -0
- package/dist/errors.cjs +255 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +3 -0
- package/dist/errors.d.ts +356 -0
- package/dist/errors.js +238 -0
- package/dist/errors.js.map +1 -0
- package/dist/eval.cjs +14826 -0
- package/dist/eval.cjs.map +1 -0
- package/dist/eval.d.cts +35 -0
- package/dist/eval.d.ts +35 -0
- package/dist/eval.js +14821 -0
- package/dist/eval.js.map +1 -0
- package/dist/generate-object.d.ts +67 -0
- package/dist/handoff.d.ts +55 -0
- package/dist/index.cjs +17127 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1878 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +17095 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/agent-loop/loop-types.d.ts +29 -0
- package/dist/internal/agent-loop/loop.d.ts +2 -0
- package/dist/internal/agent-loop/message-builders.d.ts +6 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +4 -0
- package/dist/internal/agent-loop/usage-and-cost.d.ts +25 -0
- package/dist/internal/budget/calendar-window.d.ts +19 -0
- package/dist/internal/budget/compute-cost.d.ts +28 -0
- package/dist/internal/budget/enforcement.d.ts +32 -0
- package/dist/internal/budget/ledger.d.ts +25 -0
- package/dist/internal/budget/normalize-usage.d.ts +27 -0
- package/dist/internal/budget/pricing-registry.d.ts +36 -0
- package/dist/internal/budget/registry.d.ts +16 -0
- package/dist/internal/budget/usage-accumulator.d.ts +31 -0
- package/dist/internal/cache/cosine.d.ts +14 -0
- package/dist/internal/cache/embed-helper.d.ts +15 -0
- package/dist/internal/cache/key.d.ts +15 -0
- package/dist/internal/cache/lookup.d.ts +28 -0
- package/dist/internal/cache/store-handler.d.ts +24 -0
- package/dist/internal/cache/store-json.d.ts +48 -0
- package/dist/internal/cache/store.d.ts +54 -0
- package/dist/internal/cache/telemetry.d.ts +20 -0
- package/dist/internal/cache/ttl.d.ts +11 -0
- package/dist/internal/catalog/fixtures.d.ts +16 -0
- package/dist/internal/catalog/local-models.d.ts +24 -0
- package/dist/internal/cron/run-job.d.ts +1 -0
- package/dist/internal/cron/scheduler.d.ts +1 -0
- package/dist/internal/cron/store.d.ts +1 -0
- package/dist/internal/cron/validate.d.ts +1 -0
- package/dist/internal/env.d.ts +1 -0
- package/dist/internal/errors/mappers/anthropic.d.ts +30 -0
- package/dist/internal/errors/mappers/bedrock.d.ts +16 -0
- package/dist/internal/errors/mappers/ollama.d.ts +41 -0
- package/dist/internal/errors/mappers/openai-compatible.d.ts +25 -0
- package/dist/internal/errors/mappers/shared.d.ts +10 -0
- package/dist/internal/errors/mappers/vertex.d.ts +15 -0
- package/dist/internal/eval/aggregate.d.ts +9 -0
- package/dist/internal/eval/dataset-iter.d.ts +9 -0
- package/dist/internal/eval/runner.d.ts +9 -0
- package/dist/internal/eval/single-flight.d.ts +16 -0
- package/dist/internal/eval/telemetry.d.ts +23 -0
- package/dist/internal/fixture-mode.d.ts +16 -0
- package/dist/internal/handoff/dispatcher.d.ts +29 -0
- package/dist/internal/handoff/registry.d.ts +23 -0
- package/dist/internal/handoff/telemetry.d.ts +18 -0
- package/dist/internal/handoff/tool-injector.d.ts +34 -0
- package/dist/internal/http.d.ts +1 -0
- package/dist/internal/ids.d.ts +1 -0
- package/dist/internal/judge/judge-call.d.ts +35 -0
- package/dist/internal/judge/parse-verdict.d.ts +11 -0
- package/dist/internal/judge/types.d.ts +17 -0
- package/dist/internal/llm/anthropic-shared.d.ts +89 -0
- package/dist/internal/llm/anthropic.d.ts +9 -0
- package/dist/internal/llm/bedrock-anthropic.d.ts +36 -0
- package/dist/internal/llm/bedrock-token-cache.d.ts +18 -0
- package/dist/internal/llm/credential-pool-context.d.ts +11 -0
- package/dist/internal/llm/credential-pool-types.d.ts +22 -0
- package/dist/internal/llm/credential-pool.d.ts +18 -0
- package/dist/internal/llm/fallback-client.d.ts +1 -0
- package/dist/internal/llm/fault-injection.d.ts +50 -0
- package/dist/internal/llm/finish.d.ts +1 -0
- package/dist/internal/llm/model-identifier.d.ts +24 -0
- package/dist/internal/llm/ollama-native.d.ts +27 -0
- package/dist/internal/llm/openai.d.ts +9 -0
- package/dist/internal/llm/pool-aware-client.d.ts +16 -0
- package/dist/internal/llm/router.d.ts +17 -0
- package/dist/internal/llm/sse.d.ts +9 -0
- package/dist/internal/llm/stream-relay.d.ts +17 -0
- package/dist/internal/llm/types.d.ts +70 -0
- package/dist/internal/llm/vertex-anthropic.d.ts +40 -0
- package/dist/internal/llm/vertex-auth.d.ts +30 -0
- package/dist/internal/llm/vertex-gemini.d.ts +28 -0
- package/dist/internal/llm/vertex-router.d.ts +21 -0
- package/dist/internal/mcp/client.d.ts +16 -0
- package/dist/internal/memory/active-memory-cache.d.ts +10 -0
- package/dist/internal/memory/active-memory.d.ts +45 -0
- package/dist/internal/memory/adapters/catalog.d.ts +1 -0
- package/dist/internal/memory/adapters/deepinfra-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/mistral-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/ollama-embedding.d.ts +34 -0
- package/dist/internal/memory/adapters/openai-compatible.d.ts +23 -0
- package/dist/internal/memory/adapters/openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/openrouter-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/voyage-embedding.d.ts +2 -0
- package/dist/internal/memory/atomic-write.d.ts +7 -0
- package/dist/internal/memory/chunk-markdown.d.ts +2 -0
- package/dist/internal/memory/circuit-breaker.d.ts +22 -0
- package/dist/internal/memory/cwd-mutex.d.ts +1 -0
- package/dist/internal/memory/dreaming/diary.d.ts +4 -0
- package/dist/internal/memory/dreaming/phases.d.ts +15 -0
- package/dist/internal/memory/dreaming/run.d.ts +10 -0
- package/dist/internal/memory/embedding-adapter.d.ts +42 -0
- package/dist/internal/memory/embedding-cache.d.ts +1 -0
- package/dist/internal/memory/index-db.d.ts +10 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +23 -0
- package/dist/internal/memory/index-manager.d.ts +68 -0
- package/dist/internal/memory/index-schema.d.ts +21 -0
- package/dist/internal/memory/lance-index.d.ts +32 -0
- package/dist/internal/memory/lance-memory-adapter.d.ts +43 -0
- package/dist/internal/memory/markdown-store.d.ts +16 -0
- package/dist/internal/memory/memory-index.d.ts +52 -0
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +15 -0
- package/dist/internal/memory/migration.d.ts +9 -0
- package/dist/internal/memory/reader.d.ts +8 -0
- package/dist/internal/memory/session-loader.d.ts +1 -0
- package/dist/internal/memory/session-summary-writer.d.ts +2 -0
- package/dist/internal/memory/sqlite-vec-loader.d.ts +3 -0
- package/dist/internal/memory/tools.d.ts +14 -0
- package/dist/internal/memory/transcript-store.d.ts +1 -0
- package/dist/internal/memory/types.d.ts +17 -0
- package/dist/internal/memory/vec-index.d.ts +28 -0
- package/dist/internal/memory/wiki-loader.d.ts +2 -0
- package/dist/internal/observability/tracer-loader.d.ts +20 -0
- package/dist/internal/persistence/atomic-write.d.ts +1 -0
- package/dist/internal/persistence/conversation-storage-fs.d.ts +37 -0
- package/dist/internal/persistence/conversation-storage-memory.d.ts +24 -0
- package/dist/internal/persistence/cwd-mutex.d.ts +1 -0
- package/dist/internal/persistence/file-lock.d.ts +14 -0
- package/dist/internal/persistence/fts5-sanitize.d.ts +16 -0
- package/dist/internal/persistence/markdown-config-loader.d.ts +35 -0
- package/dist/internal/persistence/paths.d.ts +19 -0
- package/dist/internal/persistence/persistence-schema.d.ts +17 -0
- package/dist/internal/persistence/schema-version.d.ts +13 -0
- package/dist/internal/persistence/sqlite-wal.d.ts +10 -0
- package/dist/internal/personality/context.d.ts +17 -0
- package/dist/internal/personality/registry.d.ts +17 -0
- package/dist/internal/personality/store.d.ts +27 -0
- package/dist/internal/personality/switch.d.ts +36 -0
- package/dist/internal/personality/types.d.ts +18 -0
- package/dist/internal/plugins/context.d.ts +31 -0
- package/dist/internal/plugins/manager.d.ts +37 -0
- package/dist/internal/plugins/types.d.ts +102 -0
- package/dist/internal/providers/builtin/anthropic.d.ts +2 -0
- package/dist/internal/providers/builtin/bedrock.d.ts +25 -0
- package/dist/internal/providers/builtin/gemini.d.ts +10 -0
- package/dist/internal/providers/builtin/index.d.ts +19 -0
- package/dist/internal/providers/builtin/llamacpp.d.ts +1 -0
- package/dist/internal/providers/builtin/lmstudio.d.ts +1 -0
- package/dist/internal/providers/builtin/ollama.d.ts +17 -0
- package/dist/internal/providers/builtin/openai.d.ts +2 -0
- package/dist/internal/providers/builtin/openrouter.d.ts +2 -0
- package/dist/internal/providers/builtin/vertex.d.ts +27 -0
- package/dist/internal/providers/discovery.d.ts +14 -0
- package/dist/internal/providers/index.d.ts +8 -0
- package/dist/internal/providers/registry.d.ts +12 -0
- package/dist/internal/providers/types.d.ts +27 -0
- package/dist/internal/runtime/abort-utils.d.ts +21 -0
- package/dist/internal/runtime/agent-factory-registry.d.ts +16 -0
- package/dist/internal/runtime/agent-registry-store.d.ts +61 -0
- package/dist/internal/runtime/agent-registry.d.ts +34 -0
- package/dist/internal/runtime/agent-session-store.d.ts +3 -0
- package/dist/internal/runtime/agent-session.d.ts +2 -0
- package/dist/internal/runtime/async-local-storage.d.ts +20 -0
- package/dist/internal/runtime/async-semaphore.d.ts +24 -0
- package/dist/internal/runtime/budget.d.ts +36 -0
- package/dist/internal/runtime/cloud-agent.d.ts +1 -0
- package/dist/internal/runtime/cloud-config-serializer.d.ts +3 -0
- package/dist/internal/runtime/cloud-payload-types.d.ts +56 -0
- package/dist/internal/runtime/cloud-run.d.ts +1 -0
- package/dist/internal/runtime/cloud-tool-parity.d.ts +1 -0
- package/dist/internal/runtime/context-aggregator.d.ts +26 -0
- package/dist/internal/runtime/context-discovery-runner.d.ts +27 -0
- package/dist/internal/runtime/context-discovery.d.ts +21 -0
- package/dist/internal/runtime/context-frontmatter.d.ts +16 -0
- package/dist/internal/runtime/context-import-resolver.d.ts +24 -0
- package/dist/internal/runtime/context-loaders.d.ts +42 -0
- package/dist/internal/runtime/context-manager.d.ts +11 -0
- package/dist/internal/runtime/context-mdc-parser.d.ts +24 -0
- package/dist/internal/runtime/default-model.d.ts +1 -0
- package/dist/internal/runtime/fixture-events.d.ts +12 -0
- package/dist/internal/runtime/fixture-responder.d.ts +1 -0
- package/dist/internal/runtime/fixture-run-base.d.ts +45 -0
- package/dist/internal/runtime/fixture-scripts.d.ts +21 -0
- package/dist/internal/runtime/fixture-types.d.ts +1 -0
- package/dist/internal/runtime/fork-agent.d.ts +15 -0
- package/dist/internal/runtime/hooks-executor.d.ts +35 -0
- package/dist/internal/runtime/hooks-frontmatter.d.ts +26 -0
- package/dist/internal/runtime/hooks-source.d.ts +22 -0
- package/dist/internal/runtime/live-agent-registry.d.ts +87 -0
- package/dist/internal/runtime/local-agent-bootstrap.d.ts +37 -0
- package/dist/internal/runtime/local-agent-dispatch.d.ts +57 -0
- package/dist/internal/runtime/local-agent-invalidate.d.ts +8 -0
- package/dist/internal/runtime/local-agent-memory-direct.d.ts +12 -0
- package/dist/internal/runtime/local-agent-memory-hooks.d.ts +41 -0
- package/dist/internal/runtime/local-agent-memory.d.ts +1 -0
- package/dist/internal/runtime/local-agent-personality-extensions.d.ts +19 -0
- package/dist/internal/runtime/local-agent-plugins.d.ts +13 -0
- package/dist/internal/runtime/local-agent-runtime-extensions.d.ts +13 -0
- package/dist/internal/runtime/local-agent-task-wrap.d.ts +11 -0
- package/dist/internal/runtime/local-agent.d.ts +1 -0
- package/dist/internal/runtime/local-run.d.ts +1 -0
- package/dist/internal/runtime/memory-store.d.ts +4 -0
- package/dist/internal/runtime/plugin-frontmatter.d.ts +17 -0
- package/dist/internal/runtime/plugins-manager.d.ts +1 -0
- package/dist/internal/runtime/post-run-lifecycle.d.ts +1 -0
- package/dist/internal/runtime/providers-manager.d.ts +1 -0
- package/dist/internal/runtime/real-cloud-run.d.ts +2 -0
- package/dist/internal/runtime/real-local-run.d.ts +2 -0
- package/dist/internal/runtime/run-registry.d.ts +5 -0
- package/dist/internal/runtime/run-until.d.ts +22 -0
- package/dist/internal/runtime/shell-tool.d.ts +7 -0
- package/dist/internal/runtime/skill-frontmatter.d.ts +1 -0
- package/dist/internal/runtime/skills-manager.d.ts +1 -0
- package/dist/internal/runtime/spawn-collect.d.ts +8 -0
- package/dist/internal/runtime/subagents-loader.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/escape.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/local-assembly.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/pipeline.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/active-memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/base-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/context-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/memory-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/providers/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/safe-call.d.ts +1 -0
- package/dist/internal/runtime/system-prompt/types.d.ts +5 -0
- package/dist/internal/runtime/system-prompt.d.ts +1 -0
- package/dist/internal/runtime/validate-agent-options.d.ts +1 -0
- package/dist/internal/runtime/workspace-dir.d.ts +9 -0
- package/dist/internal/runtime/yaml-frontmatter.d.ts +20 -0
- package/dist/internal/scorers/llm-judge.d.ts +24 -0
- package/dist/internal/security/index.d.ts +11 -0
- package/dist/internal/security/path-guard.d.ts +56 -0
- package/dist/internal/security/redact.d.ts +21 -0
- package/dist/internal/structured-output-helpers.d.ts +54 -0
- package/dist/internal/task/registry.d.ts +61 -0
- package/dist/internal/task/ring-buffer.d.ts +10 -0
- package/dist/internal/task/store.d.ts +59 -0
- package/dist/internal/task/subscribe.d.ts +15 -0
- package/dist/internal/task/telemetry.d.ts +27 -0
- package/dist/internal/telemetry/adapter-registry.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langfuse.d.ts +2 -0
- package/dist/internal/telemetry/adapters/posthog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/sentry.d.ts +2 -0
- package/dist/internal/telemetry/safe-require.d.ts +1 -0
- package/dist/internal/telemetry/tracer.d.ts +18 -0
- package/dist/internal/tool-dispatch/repair-middleware.d.ts +34 -0
- package/dist/internal/tool-dispatch/strip-think.d.ts +22 -0
- package/dist/internal/tool-registry/personality-filter.d.ts +37 -0
- package/dist/internal/workflow/ctx.d.ts +19 -0
- package/dist/internal/workflow/error-shape.d.ts +7 -0
- package/dist/internal/workflow/executor.d.ts +15 -0
- package/dist/internal/workflow/index.d.ts +12 -0
- package/dist/internal/workflow/retry-policy.d.ts +14 -0
- package/dist/internal/workflow/run-id.d.ts +9 -0
- package/dist/internal/workflow/single-flight.d.ts +18 -0
- package/dist/internal/workflow/snapshot-store.d.ts +23 -0
- package/dist/internal/workflow/step-agent.d.ts +12 -0
- package/dist/internal/workflow/step-branch.d.ts +10 -0
- package/dist/internal/workflow/step-dowhile.d.ts +8 -0
- package/dist/internal/workflow/step-fn.d.ts +10 -0
- package/dist/internal/workflow/step-foreach.d.ts +11 -0
- package/dist/internal/workflow/step-parallel.d.ts +17 -0
- package/dist/internal/workflow/step-sleep.d.ts +7 -0
- package/dist/internal/workflow/telemetry.d.ts +23 -0
- package/dist/internal/zod/to-json-schema.d.ts +21 -0
- package/dist/memory-adapter-helpers.d.ts +28 -0
- package/dist/memory.d.ts +123 -0
- package/dist/migrate.d.ts +33 -0
- package/dist/path-safety.cjs +126 -0
- package/dist/path-safety.cjs.map +1 -0
- package/dist/path-safety.d.cts +15 -0
- package/dist/path-safety.d.ts +15 -0
- package/dist/path-safety.js +120 -0
- package/dist/path-safety.js.map +1 -0
- package/dist/run-DkCD5DeO.d.cts +2181 -0
- package/dist/run-DkCD5DeO.d.ts +2181 -0
- package/dist/scorers.d.ts +75 -0
- package/dist/security.d.ts +67 -0
- package/dist/stream-object.d.ts +74 -0
- package/dist/task-store.cjs +237 -0
- package/dist/task-store.cjs.map +1 -0
- package/dist/task-store.d.cts +8 -0
- package/dist/task-store.d.ts +8 -0
- package/dist/task-store.js +233 -0
- package/dist/task-store.js.map +1 -0
- package/dist/task.d.ts +87 -0
- package/dist/theokit.d.ts +84 -0
- package/dist/tools/_path-scope.d.cts +8 -0
- package/dist/tools/_path-scope.d.ts +8 -0
- package/dist/tools/_subprocess.d.cts +28 -0
- package/dist/tools/_subprocess.d.ts +28 -0
- package/dist/tools/git-diff.d.cts +22 -0
- package/dist/tools/git-diff.d.ts +22 -0
- package/dist/tools/index.d.cts +29 -0
- package/dist/tools/index.d.ts +29 -0
- package/dist/tools/list-dir.d.cts +26 -0
- package/dist/tools/list-dir.d.ts +26 -0
- package/dist/tools/read-file.d.cts +31 -0
- package/dist/tools/read-file.d.ts +31 -0
- package/dist/tools/run-vitest.d.cts +46 -0
- package/dist/tools/run-vitest.d.ts +46 -0
- package/dist/tools/search-text.d.cts +32 -0
- package/dist/tools/search-text.d.ts +32 -0
- package/dist/tools.cjs +690 -0
- package/dist/tools.cjs.map +1 -0
- package/dist/tools.js +683 -0
- package/dist/tools.js.map +1 -0
- package/dist/trajectory-helpers.d.ts +31 -0
- package/dist/types/agent.d.ts +771 -0
- package/dist/types/batch.d.ts +112 -0
- package/dist/types/budget.d.ts +88 -0
- package/dist/types/cache.d.ts +76 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/conversation-storage.d.ts +76 -0
- package/dist/types/conversation.d.ts +90 -0
- package/dist/types/cron.d.ts +150 -0
- package/dist/types/eval.d.ts +132 -0
- package/dist/types/goal-events.d.ts +95 -0
- package/dist/types/handoff.d.ts +135 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/mcp.d.ts +64 -0
- package/dist/types/memory-adapter.d.ts +175 -0
- package/dist/types/messages.d.ts +154 -0
- package/dist/types/providers.d.ts +102 -0
- package/dist/types/run.d.ts +215 -0
- package/dist/types/task.d.ts +131 -0
- package/dist/types/theokit.d.ts +61 -0
- package/dist/types/trajectory.d.ts +49 -0
- package/dist/types/updates.d.ts +148 -0
- package/dist/types/usage.d.ts +61 -0
- package/dist/types/workflow.d.ts +217 -0
- package/dist/workflow.cjs +2405 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.d.cts +97 -0
- package/dist/workflow.d.ts +97 -0
- package/dist/workflow.js +2398 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +183 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `Agent.batch` (ADRs D134-D140).
|
|
3
|
+
*
|
|
4
|
+
* Run N prompts in parallel with bounded concurrency. Each prompt gets
|
|
5
|
+
* a fresh agent (create → send → wait → dispose). Failures isolated
|
|
6
|
+
* per-prompt; the batch never aborts on a single failure.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
import type { TheokitAgentError } from "../errors.js";
|
|
11
|
+
import type { AgentOptions } from "./agent.js";
|
|
12
|
+
import type { RunResult } from "./run.js";
|
|
13
|
+
/**
|
|
14
|
+
* Single prompt in a batch. Plain string is shorthand for `{ prompt }`.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface BatchItem {
|
|
19
|
+
/** Prompt text sent to the agent. */
|
|
20
|
+
prompt: string;
|
|
21
|
+
/** Per-prompt system prompt override (wins over `BatchOptions.systemPrompt`). */
|
|
22
|
+
systemPrompt?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Caller-supplied metadata, round-tripped to `BatchResult.metadata`.
|
|
25
|
+
* Passed by reference — do NOT mutate while the batch is in-flight (EC-I).
|
|
26
|
+
*/
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options accepted by `Agent.batch`. Extends `AgentOptions` — every
|
|
31
|
+
* prompt gets an agent created with these options (ADR D138 isolation),
|
|
32
|
+
* plus the batch-specific knobs below.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export interface BatchOptions extends AgentOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Maximum parallel agents. Default 4 (ADR D136). Must be a positive
|
|
39
|
+
* integer. Capped to `prompts.length` to avoid spinning idle workers.
|
|
40
|
+
*/
|
|
41
|
+
concurrency?: number;
|
|
42
|
+
/** Optional filter applied post-collection. Return `false` to discard. */
|
|
43
|
+
filter?: (result: BatchResult) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Streaming callback fired once per completed prompt (success OR failure).
|
|
46
|
+
* Caller exceptions are caught + logged to stderr without poisoning
|
|
47
|
+
* the batch (EC-5).
|
|
48
|
+
*/
|
|
49
|
+
onResult?: (result: BatchResult) => void | Promise<void>;
|
|
50
|
+
/** Progress callback fired after each result. */
|
|
51
|
+
onProgress?: (progress: BatchProgress) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Cancel pending prompts (ADR D140). In-flight prompts continue to
|
|
54
|
+
* completion (Node `AbortSignal` semantics). When `signal.reason` is
|
|
55
|
+
* an Error, it propagates to `BatchResult.error`; otherwise a generic
|
|
56
|
+
* "aborted" error is used.
|
|
57
|
+
*/
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
/**
|
|
60
|
+
* Opt-in Task wrapping (ADRs D363, D374). When set, the batch is
|
|
61
|
+
* registered as a `Task` (kind="batch") in the SDK's observable
|
|
62
|
+
* registry. The parent task transitions `finished` when every
|
|
63
|
+
* prompt is resolved (success OR failure).
|
|
64
|
+
*
|
|
65
|
+
* Use cases: surfacing a long-running batch in the `theokit tasks
|
|
66
|
+
* list` CLI, programmatic `Task.cancel(id)` aborting the batch, or
|
|
67
|
+
* binding a user-facing job dashboard. v1 does NOT yet emit one
|
|
68
|
+
* task PER prompt (single parent only); per-prompt tasks land in
|
|
69
|
+
* v0.2.
|
|
70
|
+
*
|
|
71
|
+
* Auto-generated id uses the `b-` reserved prefix (D368, EC-5).
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
task?: true | {
|
|
76
|
+
id?: string;
|
|
77
|
+
meta?: Record<string, unknown>;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Per-prompt outcome. Discriminated union — check `ok` before reading
|
|
82
|
+
* `result` or `error`.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export type BatchResult = {
|
|
87
|
+
ok: true;
|
|
88
|
+
index: number;
|
|
89
|
+
prompt: string;
|
|
90
|
+
result: RunResult;
|
|
91
|
+
metadata?: Record<string, unknown>;
|
|
92
|
+
durationMs: number;
|
|
93
|
+
} | {
|
|
94
|
+
ok: false;
|
|
95
|
+
index: number;
|
|
96
|
+
prompt: string;
|
|
97
|
+
error: TheokitAgentError;
|
|
98
|
+
metadata?: Record<string, unknown>;
|
|
99
|
+
durationMs: number;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Live progress snapshot delivered to `onProgress`.
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export interface BatchProgress {
|
|
107
|
+
total: number;
|
|
108
|
+
completed: number;
|
|
109
|
+
failed: number;
|
|
110
|
+
pending: number;
|
|
111
|
+
inFlight: number;
|
|
112
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type contract for the Budget enforcement primitive
|
|
3
|
+
* (ADRs D375, D382-D387). The runtime facade lives in `budget.ts`.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Scope of a budget — where the charge is attributed. v1 supports
|
|
9
|
+
* `process` (shared global) only; `agent` and `call` reserved for
|
|
10
|
+
* v0.2 multi-tenant scenarios.
|
|
11
|
+
*/
|
|
12
|
+
export type BudgetScope = "agent" | "call" | "process";
|
|
13
|
+
/**
|
|
14
|
+
* Time window for a budget limit (D382 — UTC calendar-aligned).
|
|
15
|
+
* - `1h` is relative (last 60 minutes).
|
|
16
|
+
* - `1d` / `1w` / `30d` / `365d` are aligned to UTC calendar
|
|
17
|
+
* boundaries (UTC midnight / monday 00:00 UTC / 1st 00:00 UTC).
|
|
18
|
+
*/
|
|
19
|
+
export type BudgetWindow = "1h" | "1d" | "1w" | "30d" | "365d";
|
|
20
|
+
/**
|
|
21
|
+
* Enforcement mode (D383).
|
|
22
|
+
* - `audit`: log only, never throw, never block.
|
|
23
|
+
* - `warn`: callbacks fire at 80/95/100% thresholds; no throw.
|
|
24
|
+
* - `block`: preflightCheck throws `BudgetExceededError` BEFORE LLM call
|
|
25
|
+
* when would-exceed.
|
|
26
|
+
*/
|
|
27
|
+
export type BudgetMode = "audit" | "warn" | "block";
|
|
28
|
+
/** A single limit; stacked in an array (D384, ANY exceeded blocks). */
|
|
29
|
+
export interface BudgetLimit {
|
|
30
|
+
readonly window: BudgetWindow;
|
|
31
|
+
readonly limitUsd: number;
|
|
32
|
+
}
|
|
33
|
+
/** Threshold event emitted at 80% and 95% in `warn` and `block` modes. */
|
|
34
|
+
export interface BudgetThresholdEvent {
|
|
35
|
+
readonly budgetName: string;
|
|
36
|
+
readonly window: BudgetWindow;
|
|
37
|
+
readonly threshold: 0.8 | 0.95;
|
|
38
|
+
readonly spentUsd: number;
|
|
39
|
+
readonly limitUsd: number;
|
|
40
|
+
}
|
|
41
|
+
/** Exceed event emitted at 100% across all modes. */
|
|
42
|
+
export interface BudgetExceedEvent {
|
|
43
|
+
readonly budgetName: string;
|
|
44
|
+
readonly window: BudgetWindow;
|
|
45
|
+
readonly spentUsd: number;
|
|
46
|
+
readonly limitUsd: number;
|
|
47
|
+
readonly mode: BudgetMode;
|
|
48
|
+
}
|
|
49
|
+
/** Options for `Budget.create`. */
|
|
50
|
+
export interface BudgetOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Identifier. Must match grammar `^[a-z0-9][a-z0-9_-]*$` (EC-7);
|
|
53
|
+
* empty/invalid → `ConfigurationError({ code: "invalid_budget_name" })`.
|
|
54
|
+
*/
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly scope: BudgetScope;
|
|
57
|
+
/**
|
|
58
|
+
* Stacked limits — at least one is expected for `warn`/`block`. Empty
|
|
59
|
+
* array (EC-19) is allowed → registry-only tracking, callbacks never
|
|
60
|
+
* fire.
|
|
61
|
+
*/
|
|
62
|
+
readonly limits: ReadonlyArray<BudgetLimit>;
|
|
63
|
+
/** Default `warn` (D383). */
|
|
64
|
+
readonly mode?: BudgetMode;
|
|
65
|
+
/** Fires at 80% and 95% of any limit. Caller throws are isolated (EC-8). */
|
|
66
|
+
readonly onThreshold?: (event: BudgetThresholdEvent) => void | Promise<void>;
|
|
67
|
+
/** Fires at 100%. Caller throws are isolated (EC-8). */
|
|
68
|
+
readonly onExceed?: (event: BudgetExceedEvent) => void | Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/** Returned by `Budget.create` and `Budget.get` — read-only view. */
|
|
71
|
+
export interface BudgetHandle {
|
|
72
|
+
readonly name: string;
|
|
73
|
+
readonly mode: BudgetMode;
|
|
74
|
+
readonly scope: BudgetScope;
|
|
75
|
+
readonly limits: ReadonlyArray<BudgetLimit>;
|
|
76
|
+
/** Snapshot spend for the given window. */
|
|
77
|
+
spentIn(window: BudgetWindow): number;
|
|
78
|
+
/** Remaining USD before the given window's limit is reached. */
|
|
79
|
+
remainingIn(window: BudgetWindow): number;
|
|
80
|
+
}
|
|
81
|
+
/** Per-window snapshot returned by `Budget.snapshot()`. */
|
|
82
|
+
export interface BudgetSnapshot {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly window: BudgetWindow;
|
|
85
|
+
readonly spentUsd: number;
|
|
86
|
+
readonly limitUsd: number;
|
|
87
|
+
readonly ratio: number;
|
|
88
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type contract for `Cache.semantic / .asPlugin / .stats / .clear`
|
|
3
|
+
* (Adoption Roadmap #6; ADRs D249-D266).
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface CacheTTLConfig {
|
|
8
|
+
/** Default TTL applied to all entries. Format: `"1h" | "30m" | 86400 (seconds)`. */
|
|
9
|
+
readonly default: string | number;
|
|
10
|
+
/** Regex marking queries that must NEVER be cached (e.g. /weather|today|now/i). */
|
|
11
|
+
readonly exclude?: RegExp;
|
|
12
|
+
}
|
|
13
|
+
export interface CachePersistenceOptions {
|
|
14
|
+
readonly backend: "memory" | "json";
|
|
15
|
+
/** Required when backend = "json". */
|
|
16
|
+
readonly dir?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Embedder runtime shape — minimal subset of `EmbeddingRuntime` (D11) the
|
|
20
|
+
* Cache actually uses. Lets tests inject fake embedders without pulling
|
|
21
|
+
* the full memory subsystem.
|
|
22
|
+
*/
|
|
23
|
+
export interface CacheEmbedderRuntime {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly model: string;
|
|
26
|
+
readonly dimension: number;
|
|
27
|
+
embed(texts: ReadonlyArray<string>): Promise<number[][]>;
|
|
28
|
+
}
|
|
29
|
+
export interface CacheSemanticOptions {
|
|
30
|
+
/** Embedder instance. REQUIRED in v1 — no autoselect (avoids surprise API calls). */
|
|
31
|
+
readonly embedder: CacheEmbedderRuntime;
|
|
32
|
+
/** Cosine distance threshold (0..2). Default 0.85; lower = stricter. */
|
|
33
|
+
readonly threshold?: number;
|
|
34
|
+
/** TTL config. Default `{ default: "1h" }`. */
|
|
35
|
+
readonly ttl?: CacheTTLConfig;
|
|
36
|
+
/** Multi-tenant namespace. Default `"global"`. */
|
|
37
|
+
readonly namespace?: string;
|
|
38
|
+
/** Default modelId attached to entries when caller doesn't override. */
|
|
39
|
+
readonly modelId?: string;
|
|
40
|
+
/** Max entries (LRU eviction). Default 1000. */
|
|
41
|
+
readonly maxEntries?: number;
|
|
42
|
+
/** Persistence backend. Default in-memory. */
|
|
43
|
+
readonly persistence?: CachePersistenceOptions;
|
|
44
|
+
}
|
|
45
|
+
export interface CacheEntry {
|
|
46
|
+
readonly key: string;
|
|
47
|
+
readonly namespace: string;
|
|
48
|
+
readonly embedderId: string;
|
|
49
|
+
readonly modelId: string;
|
|
50
|
+
readonly prompt: string;
|
|
51
|
+
readonly response: string;
|
|
52
|
+
readonly vector: ReadonlyArray<number>;
|
|
53
|
+
readonly createdAt: number;
|
|
54
|
+
readonly expiresAt: number;
|
|
55
|
+
readonly accessedAt: number;
|
|
56
|
+
readonly accessCount: number;
|
|
57
|
+
}
|
|
58
|
+
export interface CacheStats {
|
|
59
|
+
readonly entries: number;
|
|
60
|
+
readonly kvHits: number;
|
|
61
|
+
readonly semanticHits: number;
|
|
62
|
+
readonly misses: number;
|
|
63
|
+
readonly excluded: number;
|
|
64
|
+
readonly evicted: number;
|
|
65
|
+
readonly embedderFailures: number;
|
|
66
|
+
}
|
|
67
|
+
export declare class CacheEmbedderError extends Error {
|
|
68
|
+
readonly name = "CacheEmbedderError";
|
|
69
|
+
readonly cause?: Error;
|
|
70
|
+
constructor(message: string, cause?: Error);
|
|
71
|
+
}
|
|
72
|
+
export declare class CacheInvalidTtlError extends Error {
|
|
73
|
+
readonly input: string | number;
|
|
74
|
+
readonly name = "CacheInvalidTtlError";
|
|
75
|
+
constructor(input: string | number);
|
|
76
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context manager backend.
|
|
3
|
+
*
|
|
4
|
+
* - `"file"` — Read `.theokit/context.json` from the workspace (local) or the
|
|
5
|
+
* cloned repo (cloud).
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type ContextManagerKind = "file";
|
|
10
|
+
/**
|
|
11
|
+
* Context configuration accepted by `Agent.create()` via {@link AgentOptions.context}.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export interface ContextSettings {
|
|
16
|
+
/** Which backend reads context. Defaults to `"file"`. */
|
|
17
|
+
manager?: ContextManagerKind;
|
|
18
|
+
/** Hard cap on tokens emitted into the agent's system prompt. */
|
|
19
|
+
maxTokens?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Per-file truncation cap in characters. Default 40_000 (~10k tokens).
|
|
22
|
+
* Larger files are truncated with 70%/20% head/tail + marker (ADR D155).
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
maxBytesPerFile?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Aggregate cap across all context files in characters. Default 120_000.
|
|
29
|
+
* When total exceeds this, lower-priority sources are dropped (ADR D155).
|
|
30
|
+
*
|
|
31
|
+
* Note: context snapshot is **refresh-time** (EC-T); modifying context
|
|
32
|
+
* files mid-flight does not auto-update. Call `agent.reload()` to pick
|
|
33
|
+
* up changes.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
maxBytesTotal?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Inclusion state of a single context source in a {@link ContextSnapshot}.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export type ContextSourceStatus = "included" | "excluded" | "summarized";
|
|
45
|
+
/**
|
|
46
|
+
* A single context source resolved by the context manager.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export interface ContextSource {
|
|
51
|
+
/** Stable identifier — usually the filename without extension. */
|
|
52
|
+
name: string;
|
|
53
|
+
/** Path relative to the workspace root, when applicable. */
|
|
54
|
+
path?: string;
|
|
55
|
+
/** Whether the source was included, dropped, or summarized to fit the budget. */
|
|
56
|
+
status: ContextSourceStatus;
|
|
57
|
+
/** Free-text reason when `status !== "included"`. */
|
|
58
|
+
reason?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Token budget used by the context manager for a single agent.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export interface ContextBudget {
|
|
66
|
+
maxTokens?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Either a token count or a list of token strings extracted from source
|
|
69
|
+
* content. Normalized to `<tokens>` in golden comparisons.
|
|
70
|
+
*/
|
|
71
|
+
usedTokens?: number | string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Result of `agent.context.snapshot()`. Public and secret-free by design — safe
|
|
75
|
+
* to log and persist. Raw secrets, local absolute paths, and exact token values
|
|
76
|
+
* are never present.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export interface ContextSnapshot {
|
|
81
|
+
runtime: "local" | "cloud";
|
|
82
|
+
sources: ContextSource[];
|
|
83
|
+
budget?: ContextBudget;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Public context manager handle exposed as `agent.context`.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export interface SDKContextManager {
|
|
91
|
+
/** Inspect what the context manager actually loaded for the agent. */
|
|
92
|
+
snapshot(): Promise<ContextSnapshot>;
|
|
93
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable persistence for conversation history (Production-Readiness #1, ADRs D303-D306).
|
|
3
|
+
*
|
|
4
|
+
* The default {@link FileSystemConversationStorage} writes append-only JSONL
|
|
5
|
+
* to `<cwd>/.theokit/agents/<id>/messages.jsonl`. Custom adapters back the
|
|
6
|
+
* SDK against Postgres, Redis, Durable Objects, or any other store — required
|
|
7
|
+
* for serverless deploys (Vercel, Cloudflare Workers) and multi-host setups
|
|
8
|
+
* (K8s replicas, TheoCloud) where the filesystem is ephemeral or not shared.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Persisted message envelope used by {@link ConversationStorageAdapter}.
|
|
14
|
+
*
|
|
15
|
+
* The shape is deliberately narrower than the full {@link SDKMessage} variant
|
|
16
|
+
* tree — only durable content survives. `role` covers all message origins the
|
|
17
|
+
* SDK persists today (user/assistant) plus the forward-compat slots for
|
|
18
|
+
* tool-shaped messages (ADR D310 / EC-10).
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export interface StoredMessage {
|
|
23
|
+
/** Origin of the message. `tool_call` / `tool_result` reserved for forward compat. */
|
|
24
|
+
role: "user" | "assistant" | "system" | "tool_call" | "tool_result";
|
|
25
|
+
/** UTF-8 payload. May be empty string (e.g., a tool with no return value). */
|
|
26
|
+
content: string;
|
|
27
|
+
/** Optional epoch-ms timestamp. Implementations MAY default to `Date.now()` on append. */
|
|
28
|
+
at?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Pluggable conversation persistence contract.
|
|
32
|
+
*
|
|
33
|
+
* Implementations MUST be safe under concurrent append from a single process
|
|
34
|
+
* — the SDK runtime serializes per-(agent,cwd) but adapters serving multiple
|
|
35
|
+
* processes are responsible for their own atomicity.
|
|
36
|
+
*
|
|
37
|
+
* All methods return `Promise<>` even for synchronous backends (in-memory).
|
|
38
|
+
* Polymorphism uniformity beats the ~1μs microtask cost (ADR D306).
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export interface ConversationStorageAdapter {
|
|
43
|
+
/**
|
|
44
|
+
* Return the full message history for a conversation, in insertion order.
|
|
45
|
+
* MUST return `[]` (not throw) when the conversation does not exist.
|
|
46
|
+
*/
|
|
47
|
+
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Append a single message to the conversation.
|
|
50
|
+
* MUST be atomic — concurrent appends MUST NOT corrupt the log.
|
|
51
|
+
* MUST create the conversation lazily if it does not exist.
|
|
52
|
+
*/
|
|
53
|
+
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Delete the entire conversation. MUST be idempotent (delete-of-missing = ok).
|
|
56
|
+
*/
|
|
57
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Optional: list conversation ids. Used by housekeeping flows.
|
|
60
|
+
* Implementations that cannot enumerate (e.g., wildcards too expensive on
|
|
61
|
+
* production Redis) MAY return `undefined` to signal "not supported".
|
|
62
|
+
*/
|
|
63
|
+
listConversationIds?(opts?: {
|
|
64
|
+
limit?: number;
|
|
65
|
+
}): Promise<readonly string[] | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* Optional FS-specific compaction trigger (ADR D304). The default FS adapter
|
|
68
|
+
* trims old turns past a soft cap; other backends typically no-op.
|
|
69
|
+
*/
|
|
70
|
+
compact?(conversationId: string, maxTurns: number): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Optional: dispose underlying handles (close DB pool, etc.).
|
|
73
|
+
* MUST be safe to call multiple times.
|
|
74
|
+
*/
|
|
75
|
+
dispose?(): Promise<void>;
|
|
76
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ToolCall } from "./updates.js";
|
|
2
|
+
/**
|
|
3
|
+
* Plain assistant message in a conversation history.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface AssistantMessage {
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reasoning step in a conversation history.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export interface ThinkingMessage {
|
|
16
|
+
text: string;
|
|
17
|
+
thinkingDurationMs?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* User-authored message in a conversation history.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface UserMessage {
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Shell command executed during a run.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export interface ShellCommand {
|
|
33
|
+
command: string;
|
|
34
|
+
workingDirectory?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Output of a shell command.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export interface ShellOutput {
|
|
42
|
+
stdout: string;
|
|
43
|
+
stderr: string;
|
|
44
|
+
exitCode: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Single step inside an agent turn.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export type ConversationStep = {
|
|
52
|
+
type: "assistantMessage";
|
|
53
|
+
message: AssistantMessage;
|
|
54
|
+
} | {
|
|
55
|
+
type: "toolCall";
|
|
56
|
+
message: ToolCall;
|
|
57
|
+
} | {
|
|
58
|
+
type: "thinkingMessage";
|
|
59
|
+
message: ThinkingMessage;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Agent turn: user message + assistant/tool/thinking steps.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export interface AgentConversationTurn {
|
|
67
|
+
userMessage?: UserMessage;
|
|
68
|
+
steps: ConversationStep[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Shell turn: a command and its output.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export interface ShellConversationTurn {
|
|
76
|
+
shellCommand?: ShellCommand;
|
|
77
|
+
shellOutput?: ShellOutput;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Structured per-turn view of a run.
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export type ConversationTurn = {
|
|
85
|
+
type: "agentConversationTurn";
|
|
86
|
+
turn: AgentConversationTurn;
|
|
87
|
+
} | {
|
|
88
|
+
type: "shellConversationTurn";
|
|
89
|
+
turn: ShellConversationTurn;
|
|
90
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { AgentOptions } from "./agent.js";
|
|
2
|
+
import type { SDKUserMessage } from "./run.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runtime hosting a cron job. Mirrors the agent runtime split.
|
|
5
|
+
*
|
|
6
|
+
* - `local` — the in-process scheduler activated via `Cron.start()` fires the
|
|
7
|
+
* job while the host process is alive.
|
|
8
|
+
* - `cloud` — Theo PaaS schedules the job server-side; fires independent of
|
|
9
|
+
* any SDK process.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export type CronRuntime = "local" | "cloud";
|
|
14
|
+
/**
|
|
15
|
+
* Lifecycle state reported by `Cron.list()` / `Cron.get()`.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export type CronJobStatus = "scheduled" | "running" | "paused" | "errored";
|
|
20
|
+
/**
|
|
21
|
+
* Persistent cron-scheduled invocation of the Theo agent.
|
|
22
|
+
*
|
|
23
|
+
* Exactly one of {@link CronJob.agent} (ephemeral agent created on each fire)
|
|
24
|
+
* or {@link CronJob.agentId} (bound to an existing agent for context
|
|
25
|
+
* continuity) is set.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export interface CronJob {
|
|
30
|
+
id: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
/** Standard 5-field POSIX cron expression or shorthand (`@hourly`, `@daily`, ...). */
|
|
33
|
+
cron: string;
|
|
34
|
+
/** IANA timezone identifier. Defaults to `"UTC"`. */
|
|
35
|
+
timezone?: string;
|
|
36
|
+
/** Message sent to the agent on each fire. */
|
|
37
|
+
message: string | SDKUserMessage;
|
|
38
|
+
/** Ephemeral agent options. Mutually exclusive with `agentId`. */
|
|
39
|
+
agent?: AgentOptions;
|
|
40
|
+
/** ID of an existing agent to reuse for context continuity. Mutually exclusive with `agent`. */
|
|
41
|
+
agentId?: string;
|
|
42
|
+
/** Whether the scheduler will fire this job on schedule. */
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/** Current status. */
|
|
45
|
+
status: CronJobStatus;
|
|
46
|
+
/** Runtime that hosts this job. Inferred from `agent`/`agentId` at create time. */
|
|
47
|
+
runtime: CronRuntime;
|
|
48
|
+
/** Unix ms of the last successful fire, if any. */
|
|
49
|
+
lastRunAt?: number;
|
|
50
|
+
/** Unix ms of the next scheduled fire, computed by the scheduler. */
|
|
51
|
+
nextRunAt?: number;
|
|
52
|
+
/** Unix ms when the job was created. */
|
|
53
|
+
createdAt: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Options for `Cron.create()`.
|
|
57
|
+
*
|
|
58
|
+
* Pass `agent` for an ephemeral agent created fresh on each fire, OR
|
|
59
|
+
* `agentId` to reuse an existing agent (preserves conversation context across
|
|
60
|
+
* fires). Setting both is a `ConfigurationError`.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export interface CronCreateOptions {
|
|
65
|
+
cron: string;
|
|
66
|
+
message: string | SDKUserMessage;
|
|
67
|
+
agent?: AgentOptions;
|
|
68
|
+
agentId?: string;
|
|
69
|
+
name?: string;
|
|
70
|
+
timezone?: string;
|
|
71
|
+
/** Defaults to `true`. */
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
/** Falls back to `THEOKIT_API_KEY`. */
|
|
74
|
+
apiKey?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Options for `Cron.list()`.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export type CronListOptions = {
|
|
82
|
+
limit?: number;
|
|
83
|
+
cursor?: string;
|
|
84
|
+
} & ({
|
|
85
|
+
runtime?: undefined;
|
|
86
|
+
} | {
|
|
87
|
+
runtime: "local";
|
|
88
|
+
cwd?: string;
|
|
89
|
+
} | {
|
|
90
|
+
runtime: "cloud";
|
|
91
|
+
apiKey?: string;
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Options for `Cron.get()`.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export interface CronGetOptions {
|
|
99
|
+
cwd?: string;
|
|
100
|
+
apiKey?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Options for `Cron.delete()` / `Cron.enable()` / `Cron.disable()`.
|
|
104
|
+
*
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
export interface CronOperationOptions {
|
|
108
|
+
cwd?: string;
|
|
109
|
+
apiKey?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Options for `Cron.run()` — manually trigger a job off-schedule.
|
|
113
|
+
*
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
export interface CronRunOptions {
|
|
117
|
+
cwd?: string;
|
|
118
|
+
apiKey?: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Options for `Cron.start()` — activates the in-process scheduler for local
|
|
122
|
+
* jobs.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export interface CronStartOptions {
|
|
127
|
+
/** Local workspace whose `.theokit/cron/jobs.json` to load. Defaults to `process.cwd()`. */
|
|
128
|
+
cwd?: string;
|
|
129
|
+
/** Override the env API key. */
|
|
130
|
+
apiKey?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Snapshot of the local scheduler returned by `Cron.status()`.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
export interface CronSchedulerStatus {
|
|
138
|
+
/** Whether the in-process scheduler is currently running. */
|
|
139
|
+
running: boolean;
|
|
140
|
+
/** Number of jobs loaded into the scheduler. */
|
|
141
|
+
jobCount: number;
|
|
142
|
+
/** Unix ms of the next scheduled fire across all jobs, if any. */
|
|
143
|
+
nextFireAt?: number;
|
|
144
|
+
/** Last error observed in the scheduler, if any. */
|
|
145
|
+
lastError?: {
|
|
146
|
+
jobId: string;
|
|
147
|
+
message: string;
|
|
148
|
+
at: number;
|
|
149
|
+
};
|
|
150
|
+
}
|