@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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTel telemetry for the Task registry (ADR D371).
|
|
3
|
+
*
|
|
4
|
+
* Spans:
|
|
5
|
+
* - `task.submit` — short-lived span around the submit + insert.
|
|
6
|
+
* - `task.transition` — per state transition (attrs: from / to).
|
|
7
|
+
* - `task.cancel` — invoked from `Task.cancel` or via cancelRequested honor.
|
|
8
|
+
*
|
|
9
|
+
* Uses the existing tracer seam (D34); when OTel is absent, every helper
|
|
10
|
+
* returns the shared no-op span. No new peer deps.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function startTaskSubmitSpan(info: {
|
|
15
|
+
taskId: string;
|
|
16
|
+
kind: string;
|
|
17
|
+
}): SpanLike;
|
|
18
|
+
export declare function startTaskTransitionSpan(info: {
|
|
19
|
+
taskId: string;
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
}): SpanLike;
|
|
23
|
+
export declare function startTaskCancelSpan(info: {
|
|
24
|
+
taskId: string;
|
|
25
|
+
reason?: string;
|
|
26
|
+
via: "api" | "cancelRequested";
|
|
27
|
+
}): SpanLike;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface OTelSpan {
|
|
2
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
3
|
+
setAttributes(attrs: Record<string, string | number | boolean | undefined>): void;
|
|
4
|
+
addEvent(name: string, attrs?: Record<string, string | number | boolean>): void;
|
|
5
|
+
setStatus(status: {
|
|
6
|
+
code: number;
|
|
7
|
+
message?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
recordException(err: unknown): void;
|
|
10
|
+
end(endTime?: number): void;
|
|
11
|
+
spanContext(): {
|
|
12
|
+
traceId: string;
|
|
13
|
+
spanId: string;
|
|
14
|
+
};
|
|
15
|
+
isRecording(): boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Exported for tests — resets the OTel cache and the warning-once latch. */
|
|
18
|
+
export declare function _resetTelemetryCacheForTests(): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-call repair middleware (T1.1, ADR D87).
|
|
3
|
+
*
|
|
4
|
+
* Applies 3 idempotent repairs sequentially before tool dispatch:
|
|
5
|
+
* 1. Case-insensitive name match (ADR D88 — no fuzzy match)
|
|
6
|
+
* 2. JSON-string args → object parse
|
|
7
|
+
* 3. Type coercion against JSON Schema (string → number/integer/boolean/object)
|
|
8
|
+
*
|
|
9
|
+
* Fixes 10+ provider-specific failure modes catalogued in
|
|
10
|
+
* `.claude/knowledge-base/sdk-references/tool-call-failure-recovery.md`:
|
|
11
|
+
* Hermes v0.2 #444 (DeepSeek JSON), v0.3 #1300 (parallel calls),
|
|
12
|
+
* v0.8 #5265 (type coerce), and similar.
|
|
13
|
+
*
|
|
14
|
+
* NOTE on coerce limits (EC-9): regex `^-?\d+(\.\d+)?$` accepts decimal
|
|
15
|
+
* notation only — scientific (`1e5`), hex (`0xFF`), and `Infinity` are
|
|
16
|
+
* preserved as strings and rejected by downstream schema validation. KISS:
|
|
17
|
+
* 99% of provider-emitted tool args use plain decimal.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export interface RepairableTool {
|
|
22
|
+
name: string;
|
|
23
|
+
/** JSON Schema for the tool's input. `properties` map drives coercion. */
|
|
24
|
+
inputSchema: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface RepairResult {
|
|
27
|
+
call: ToolCall;
|
|
28
|
+
/** Human-readable log of repairs applied (empty when no-op). */
|
|
29
|
+
repairs: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface CoerceResult {
|
|
32
|
+
value: Record<string, unknown>;
|
|
33
|
+
changed: string[];
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip `<think>...</think>` chain-of-thought blocks (T1.2, ADR D96).
|
|
3
|
+
*
|
|
4
|
+
* DeepSeek-R1, Qwen-QwQ, and similar reasoning models emit visible
|
|
5
|
+
* `<think>` blocks in the `content` field. Without stripping, they enter
|
|
6
|
+
* the message history; each turn accumulates 5k+ thinking tokens, and
|
|
7
|
+
* prompt caching invalidates every turn (Hermes v0.2 #174, ~10x cost
|
|
8
|
+
* regression).
|
|
9
|
+
*
|
|
10
|
+
* NOTE on `<think>` in legitimate prose (EC-10): a user/assistant message
|
|
11
|
+
* that deliberately contains the `<think>` token will lose it. This is
|
|
12
|
+
* provider-convention scope — `<think>` is reserved for CoT, never plain
|
|
13
|
+
* content.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface ThinkStripResult {
|
|
18
|
+
/** Content with `<think>` blocks removed. */
|
|
19
|
+
visible: string;
|
|
20
|
+
/** Combined thinking text (without `<think>` tags), or null if none. */
|
|
21
|
+
thinking: string | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* applyPersonalityFilter — additive narrowing of exposed tools by an
|
|
3
|
+
* active personality preset's `tools` whitelist (T4.1, ADRs D102+D167).
|
|
4
|
+
*
|
|
5
|
+
* Contract:
|
|
6
|
+
*
|
|
7
|
+
* - `whitelist === undefined` → return `exposedTools` unchanged (no
|
|
8
|
+
* active personality OR personality has no tool restriction).
|
|
9
|
+
* - `whitelist === []` → return empty array (explicit "no tools for
|
|
10
|
+
* this persona").
|
|
11
|
+
* - Otherwise → return the subset of `exposedTools` whose `name` is
|
|
12
|
+
* present in `whitelist`. Missing entries emit a one-shot stderr
|
|
13
|
+
* warning per `(agentId, personalityName, missingTool)` combo
|
|
14
|
+
* (advisory only — D167 says missing tools must NOT crash).
|
|
15
|
+
*
|
|
16
|
+
* **EC-I:** MCP-style names like `mcp__server__tool` are matched as
|
|
17
|
+
* exact strings (no regex semantics) — the registry already produces
|
|
18
|
+
* the verbatim name.
|
|
19
|
+
*
|
|
20
|
+
* **EC-15:** Duplicate entries in `whitelist` are deduped silently.
|
|
21
|
+
*
|
|
22
|
+
* **EC-17:** Missing names within Levenshtein distance ≤2 of an exposed
|
|
23
|
+
* tool emit a "did you mean: X" hint inside the warning.
|
|
24
|
+
*
|
|
25
|
+
* The function is **pure**: it never mutates the input array.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export interface ToolNamed {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ApplyPersonalityFilterOptions {
|
|
33
|
+
/** Used in the dedup key + warning prefix so logs are traceable. */
|
|
34
|
+
agentId?: string;
|
|
35
|
+
/** Active personality slug — used in the dedup key + warning. */
|
|
36
|
+
personalityName?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the `StepContext` passed to every step.fn. The `suspend` method
|
|
3
|
+
* throws a `WorkflowSuspendedSentinel` (defined here) that the executor
|
|
4
|
+
* catches to persist a snapshot (D236).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
/** Sentinel thrown by `ctx.suspend()`; only the executor catches it. */
|
|
9
|
+
export declare class WorkflowSuspendedSentinel extends Error {
|
|
10
|
+
readonly payload?: unknown | undefined;
|
|
11
|
+
readonly name = "WorkflowSuspendedSentinel";
|
|
12
|
+
constructor(payload?: unknown | undefined);
|
|
13
|
+
}
|
|
14
|
+
export declare function makeStepContext(runId: string, signal: AbortSignal): StepContext;
|
|
15
|
+
/**
|
|
16
|
+
* Combine the caller-supplied signal with the flight signal so abort on
|
|
17
|
+
* either side cancels the workflow run.
|
|
18
|
+
*/
|
|
19
|
+
export declare function combineSignals(...signals: ReadonlyArray<AbortSignal | undefined>): AbortSignal;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow executor (ADRs D230-D248).
|
|
3
|
+
*
|
|
4
|
+
* Walks `steps[]` sequentially, dispatching to per-kind handlers. Handles
|
|
5
|
+
* suspend (sentinel pattern; D236), single-flight (D242), abort signal
|
|
6
|
+
* boundaries (D245), and snapshot persistence opt-in (D235).
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function executeWorkflow<TInput, TOutput>(options: WorkflowOptions, steps: ReadonlyArray<Step>, input: TInput, runOpts?: WorkflowRunOptions): Promise<WorkflowRun<TOutput>>;
|
|
11
|
+
/**
|
|
12
|
+
* Dispatch single step to the right handler. Exhaustive over `step.kind`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function dispatchStep(step: Step, input: unknown, ctx: StepContext, options: WorkflowOptions, prevStepResults: ReadonlyArray<StepResult>): Promise<StepResult>;
|
|
15
|
+
export declare function resumeWorkflow<TO>(opts: WorkflowResumeOptions): Promise<WorkflowRun<TO>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal barrel for the workflow executor + helpers. Public API lives
|
|
3
|
+
* in `../../workflow.ts`.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export { dispatchStep, executeWorkflow, resumeWorkflow } from "./executor.js";
|
|
8
|
+
export { mintRunId } from "./run-id.js";
|
|
9
|
+
export { acquireSingleFlight } from "./single-flight.js";
|
|
10
|
+
export type { WorkflowSnapshotStore } from "./snapshot-store.js";
|
|
11
|
+
export { __resetSnapshotStoresForTests, getSnapshotStoreFor } from "./snapshot-store.js";
|
|
12
|
+
export { __resetTelemetryCacheForTests, startWorkflowRunSpan, startWorkflowStepSpan, } from "./telemetry.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry wrapper with exponential backoff (ADR D237).
|
|
3
|
+
*
|
|
4
|
+
* `withRetry(fn, policy, signal)` retries on throw until success or
|
|
5
|
+
* `maxAttempts` reached. Aborts mid-backoff when signal fires.
|
|
6
|
+
* Non-retryable errors (by name) propagate immediately.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function withRetry<T>(fn: () => Promise<T>, policy: RetryPolicy, signal: AbortSignal): Promise<{
|
|
11
|
+
value: T;
|
|
12
|
+
attempts: number;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function abortableSleep(ms: number, signal: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-flight registry for in-flight workflow runs (ADR D242).
|
|
3
|
+
*
|
|
4
|
+
* Key = `${workflowId}:${runId}`. Throws `WorkflowAlreadyRunningError` on
|
|
5
|
+
* duplicate. Process crash auto-releases (in-memory map). Pattern mirrors
|
|
6
|
+
* `internal/eval/single-flight.ts` (D213).
|
|
7
|
+
*
|
|
8
|
+
* EC-5 absorbed: lock uses `workflowId` (minted at `.commit()`), not the
|
|
9
|
+
* user-supplied `name`, so two `Workflow` instances sharing a name don't
|
|
10
|
+
* collide on each other's locks.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export interface AcquiredFlight {
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
release: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function acquireSingleFlight(workflowId: string, runId: string, workflowName: string): AcquiredFlight;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot store interface + InMemory and JsonFile backends (ADR D235).
|
|
3
|
+
*
|
|
4
|
+
* EC-4 absorbed: serialization happens here. `JSON.stringify` failure raises
|
|
5
|
+
* `WorkflowNotSerializableError` instead of letting the underlying `TypeError`
|
|
6
|
+
* leak.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
import { type WorkflowOptions, type WorkflowSnapshot } from "../../types/workflow.js";
|
|
11
|
+
export interface WorkflowSnapshotStore {
|
|
12
|
+
save(snapshot: WorkflowSnapshot): Promise<void>;
|
|
13
|
+
load(runId: string): Promise<WorkflowSnapshot | undefined>;
|
|
14
|
+
delete(runId: string): Promise<void>;
|
|
15
|
+
list(workflowName?: string): Promise<ReadonlyArray<{
|
|
16
|
+
runId: string;
|
|
17
|
+
workflowName: string;
|
|
18
|
+
suspendedAt: number;
|
|
19
|
+
}>>;
|
|
20
|
+
}
|
|
21
|
+
export declare function getSnapshotStoreFor(options: WorkflowOptions): WorkflowSnapshotStore;
|
|
22
|
+
/** Test seam — clear in-memory store between tests. */
|
|
23
|
+
export declare function __resetSnapshotStoresForTests(): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute an `AgentStep` — render the prompt template, call `agent.send`,
|
|
3
|
+
* wait for completion, return the result text as step output (ADR D244,
|
|
4
|
+
* D245).
|
|
5
|
+
*
|
|
6
|
+
* Cloud guard: agents marked as `CloudAgent` throw `UnsupportedRunOperationError`
|
|
7
|
+
* (workflows are local-only in v1).
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentStep, StepContext, StepResult } from "../../types/workflow.js";
|
|
12
|
+
export declare function runAgentStep(step: AgentStep, input: unknown, ctx: StepContext): Promise<StepResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a `BranchStep` — first-match-wins predicates + optional fallback.
|
|
3
|
+
*
|
|
4
|
+
* EC-2 absorbed: predicates that THROW are treated as "no match" + stderr
|
|
5
|
+
* warn — user-code bugs in predicates don't take down the whole workflow.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import type { DispatchFn } from "./step-parallel.js";
|
|
10
|
+
export declare function runBranchStep(step: BranchStep, input: unknown, ctx: StepContext, options: WorkflowOptions, prevStepResults: ReadonlyArray<StepResult>, dispatch: DispatchFn): Promise<StepResult>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a `DowhileStep` — loop the inner step until `condFn` returns
|
|
3
|
+
* false or `maxIterations` is reached (default 100).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
import type { DispatchFn } from "./step-parallel.js";
|
|
8
|
+
export declare function runDowhileStep(step: DowhileStep, input: unknown, ctx: StepContext, options: WorkflowOptions, prevStepResults: ReadonlyArray<StepResult>, dispatch: DispatchFn): Promise<StepResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a `FnStep` — call the user-supplied function with `input` + `ctx`.
|
|
3
|
+
* Wraps in `withRetry` if a retry policy is set (D237).
|
|
4
|
+
*
|
|
5
|
+
* Validates input/output via Zod when schemas are supplied. EC-4 / D229
|
|
6
|
+
* pattern: empty/undefined input parses as `{}` only when schema is defined.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function runFnStep(step: FnStep, input: unknown, ctx: StepContext): Promise<StepResult>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a `ForeachStep` — map a step over the output of an upstream step.
|
|
3
|
+
*
|
|
4
|
+
* EC-7 absorbed: `iterableFrom` MUST reference a top-level step (one of
|
|
5
|
+
* `prevStepResults`). Inner steps from inside `.parallel` / `.branch` /
|
|
6
|
+
* `.foreach` are not reachable.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
import type { DispatchFn } from "./step-parallel.js";
|
|
11
|
+
export declare function runForeachStep(step: ForeachStep, _input: unknown, ctx: StepContext, options: WorkflowOptions, prevStepResults: ReadonlyArray<StepResult>, dispatch: DispatchFn): Promise<StepResult>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a `ParallelStep` — run N branches concurrently.
|
|
3
|
+
*
|
|
4
|
+
* - `errorPolicy: "fail-fast"` (default): first branch error aborts the rest
|
|
5
|
+
* via a derived AbortSignal; `WorkflowParallelError` aggregates failures.
|
|
6
|
+
* - `errorPolicy: "collect"`: all branches complete; output is array of
|
|
7
|
+
* `{ ok: true, value } | { ok: false, error }`.
|
|
8
|
+
*
|
|
9
|
+
* Concurrency: bounded by `step.concurrency ?? branches.length` (D240). All
|
|
10
|
+
* branches run inside the same `AsyncSemaphore`.
|
|
11
|
+
*
|
|
12
|
+
* EC-6 absorbed: empty `branches[]` returns `output: []` without error.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export type DispatchFn = (step: Step, input: unknown, ctx: StepContext, options: WorkflowOptions, prevStepResults: ReadonlyArray<StepResult>) => Promise<StepResult>;
|
|
17
|
+
export declare function runParallelStep(step: ParallelStep, input: unknown, ctx: StepContext, options: WorkflowOptions, _prevStepResults: ReadonlyArray<StepResult>, dispatch: DispatchFn): Promise<StepResult>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTel telemetry for workflows (ADR D241).
|
|
3
|
+
*
|
|
4
|
+
* Spans:
|
|
5
|
+
* - `workflow.run` — root span per `Workflow.run` invocation
|
|
6
|
+
* - `workflow.step.<id>` — child span per step (retry attempts share the kind)
|
|
7
|
+
*
|
|
8
|
+
* Attributes:
|
|
9
|
+
* - `workflow.name`, `workflow.run_id`, `step.kind`, `step.status`, `step.attempts`
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function startWorkflowRunSpan(info: {
|
|
14
|
+
workflowName: string;
|
|
15
|
+
runId: string;
|
|
16
|
+
}): SpanLike;
|
|
17
|
+
export declare function startWorkflowStepSpan(info: {
|
|
18
|
+
stepId: string;
|
|
19
|
+
kind: string;
|
|
20
|
+
attempt: number;
|
|
21
|
+
}): SpanLike;
|
|
22
|
+
/** Test seam — reset tracer cache so a fresh require attempt happens. */
|
|
23
|
+
export declare function __resetTelemetryCacheForTests(): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod → JSON Schema universal adapter (FAANG-grade, supports Zod 3 + Zod 4).
|
|
3
|
+
*
|
|
4
|
+
* The SDK declares `zod: "^3.25.0 || ^4.0.0"` as optional peer. Implementation
|
|
5
|
+
* MUST work on both versions or the peer-range claim is false.
|
|
6
|
+
*
|
|
7
|
+
* Strategy:
|
|
8
|
+
* 1. Feature-detect Zod 4's native `z.toJSONSchema` (preferred — zero extra
|
|
9
|
+
* dep, ships with Zod 4 core).
|
|
10
|
+
* 2. Fall back to the universal `zod-to-json-schema` library (works for both
|
|
11
|
+
* v3 and v4; ~5KB gzipped, optional peer dep).
|
|
12
|
+
* 3. If neither path resolves, throw an actionable error explaining the
|
|
13
|
+
* install command for the user's Zod major.
|
|
14
|
+
*
|
|
15
|
+
* Output shape is identical across paths: a `Record<string, unknown>` JSON
|
|
16
|
+
* Schema document with `type: "object"` root that the LLM tool-use spec
|
|
17
|
+
* accepts unchanged.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime helpers for `MemoryAdapter` (T1.1, ADR D141).
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from `types/memory-adapter.ts` so the types module
|
|
5
|
+
* stays import-free of runtime code (dep-cruise rule
|
|
6
|
+
* `types-dont-import-runtime`). Adapter authors call `mkMemoryId` to
|
|
7
|
+
* construct a branded id and `extractRawId` to unwrap with cross-adapter
|
|
8
|
+
* safety (EC-B).
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
import type { MemoryId } from "./types/memory-adapter.js";
|
|
13
|
+
/**
|
|
14
|
+
* Construct a branded `MemoryId` for an adapter. Embeds the adapter
|
|
15
|
+
* identifier so `extractRawId` can reject ids minted by other adapters.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare function mkMemoryId(adapterId: string, rawId: string): MemoryId;
|
|
20
|
+
/**
|
|
21
|
+
* Extract the raw provider id from a `MemoryId`, enforcing that the
|
|
22
|
+
* prefix matches `expectedAdapterId`. Throws `MemoryAdapterError(code:
|
|
23
|
+
* "invalid_input")` on mismatch — prevents `mem0.delete(supermemoryId)`
|
|
24
|
+
* from accidentally deleting unrelated data (EC-B).
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractRawId(id: MemoryId, expectedAdapterId: string): string;
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public handle to an open memory index. Mirrors the internal `MemoryIndex`
|
|
3
|
+
* contract structurally; defined here (NOT re-exported from internal/) so
|
|
4
|
+
* the public DTS surface does not pull the internal/runtime cycle that
|
|
5
|
+
* trips rollup-plugin-dts.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface MemoryIndexHandle {
|
|
10
|
+
sync(): Promise<{
|
|
11
|
+
filesScanned: number;
|
|
12
|
+
filesUpdated: number;
|
|
13
|
+
chunksWritten: number;
|
|
14
|
+
chunksEmbedded: number;
|
|
15
|
+
}>;
|
|
16
|
+
search(query: string, options?: {
|
|
17
|
+
maxResults?: number;
|
|
18
|
+
minScore?: number;
|
|
19
|
+
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
20
|
+
}): Promise<ReadonlyArray<{
|
|
21
|
+
path: string;
|
|
22
|
+
startLine: number;
|
|
23
|
+
endLine: number;
|
|
24
|
+
score: number;
|
|
25
|
+
textScore: number;
|
|
26
|
+
vectorScore?: number;
|
|
27
|
+
snippet: string;
|
|
28
|
+
source: "memory" | "sessions" | "wiki";
|
|
29
|
+
citation: string;
|
|
30
|
+
}>>;
|
|
31
|
+
status(): {
|
|
32
|
+
backend: "fts-only" | "hybrid";
|
|
33
|
+
filesIndexed: number;
|
|
34
|
+
chunksIndexed: number;
|
|
35
|
+
lastSyncMs?: number;
|
|
36
|
+
};
|
|
37
|
+
close(): Promise<void> | void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Public `Memory` namespace.
|
|
41
|
+
*
|
|
42
|
+
* Exposes operations users can run outside of `agent.send()` — most notably
|
|
43
|
+
* the dreaming sweep (consolidation of facts via dedup + clustering).
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export interface DreamingSweepOptions {
|
|
48
|
+
/** Workspace cwd holding `.theokit/memory/`. */
|
|
49
|
+
cwd: string;
|
|
50
|
+
/**
|
|
51
|
+
* Embedding provider for semantic dedup + clustering. Required — dreaming
|
|
52
|
+
* relies on real embeddings to score cosine similarity. Supported providers:
|
|
53
|
+
* `"openai"`, `"mistral"`, `"openrouter"`, `"voyage"`, `"deepinfra"`,
|
|
54
|
+
* `"ollama"` (local, ADR D183).
|
|
55
|
+
*/
|
|
56
|
+
embedding: {
|
|
57
|
+
provider: "openai" | "mistral" | "openrouter" | "voyage" | "deepinfra" | "ollama";
|
|
58
|
+
model?: string;
|
|
59
|
+
};
|
|
60
|
+
/** Cosine-similarity threshold for the dedup phase. Default `0.95`. */
|
|
61
|
+
dedupThreshold?: number;
|
|
62
|
+
/** Cosine-similarity threshold for the clustering phase. Default `0.75`. */
|
|
63
|
+
clusterThreshold?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface DreamingSweepResult {
|
|
66
|
+
status: "ok" | "skipped" | "error";
|
|
67
|
+
factsBefore: number;
|
|
68
|
+
factsAfter: number;
|
|
69
|
+
duplicatesRemoved: number;
|
|
70
|
+
clustersCreated: number;
|
|
71
|
+
notesWritten: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Options for `Memory.openIndex`. Mirrors the internal `OpenIndexOptions`
|
|
75
|
+
* but using only public types from the SDK surface.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export interface OpenMemoryIndexOptions {
|
|
80
|
+
/** Workspace cwd holding `.theokit/memory/`. */
|
|
81
|
+
cwd: string;
|
|
82
|
+
/** Override storage file path (SQLite) OR storage directory (Lance). */
|
|
83
|
+
filePath?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Embedding runtime — REQUIRED for `backend: "lance"`, optional for
|
|
86
|
+
* `"sqlite-vec"` (when omitted, SQLite runs FTS-only without vector
|
|
87
|
+
* recall).
|
|
88
|
+
*/
|
|
89
|
+
embedding?: {
|
|
90
|
+
provider: "openai" | "mistral" | "openrouter" | "voyage" | "deepinfra" | "ollama";
|
|
91
|
+
model?: string;
|
|
92
|
+
};
|
|
93
|
+
/** Default `"sqlite-vec"`. Set to `"lance"` to opt into LanceDB (peer dep). */
|
|
94
|
+
backend?: "sqlite-vec" | "lance";
|
|
95
|
+
}
|
|
96
|
+
export declare const Memory: {
|
|
97
|
+
/**
|
|
98
|
+
* Open a memory index. Dispatches to SQLite-vec (default, zero deps) or
|
|
99
|
+
* LanceDB (opt-in via `backend: "lance"`, requires `@lancedb/lancedb`
|
|
100
|
+
* peer dep + an embedding runtime).
|
|
101
|
+
*
|
|
102
|
+
* Returns a `MemoryIndex` with `sync()`, `search(query, opts?)`,
|
|
103
|
+
* `status()`, and `close()`. Use this when you want a direct index
|
|
104
|
+
* handle outside of `Agent.create({ memory: ... })`.
|
|
105
|
+
*
|
|
106
|
+
* @throws ConfigurationError({code:"invalid_memory_backend"}) for typos
|
|
107
|
+
* like `"lancedb"`.
|
|
108
|
+
* @throws ConfigurationError({code:"lance_requires_embedding"}) when
|
|
109
|
+
* `backend: "lance"` is requested without `embedding`.
|
|
110
|
+
* @throws ConfigurationError({code:"lance_backend_unavailable"}) when
|
|
111
|
+
* `backend: "lance"` is requested but the peer dep is absent.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
openIndex(opts: OpenMemoryIndexOptions): Promise<MemoryIndexHandle>;
|
|
116
|
+
/**
|
|
117
|
+
* Run a dreaming sweep: dedup near-duplicate facts, cluster thematically
|
|
118
|
+
* related ones, and write a consolidated note + diary entry.
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
runDreamingSweep(opts: DreamingSweepOptions): Promise<DreamingSweepResult>;
|
|
123
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link migrateSqliteToLance}.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface MigrateOptions {
|
|
7
|
+
cwd: string;
|
|
8
|
+
dryRun?: boolean;
|
|
9
|
+
batchSize?: number;
|
|
10
|
+
logger?: (msg: string) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Outcome of {@link migrateSqliteToLance}.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface MigrateResult {
|
|
18
|
+
countSqlite: number;
|
|
19
|
+
countLance: number;
|
|
20
|
+
validated: boolean;
|
|
21
|
+
sampleComparisons: ReadonlyArray<{
|
|
22
|
+
id: string;
|
|
23
|
+
match: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
lancePath: string;
|
|
26
|
+
committed: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Migrate the Memory index from SQLite to LanceDB. ADR D44.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare function migrateSqliteToLance(options: MigrateOptions): Promise<MigrateResult>;
|