@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,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model identifier parsing (T1.2 follow-up, ADR D182 zero-config UX).
|
|
3
|
+
*
|
|
4
|
+
* SDK callers pass model strings like:
|
|
5
|
+
* - `"ollama/llama3.2:3b"` → provider="ollama", name="llama3.2:3b"
|
|
6
|
+
* - `"anthropic/claude-3-5-sonnet"` → provider="anthropic", name="claude-3-5-sonnet"
|
|
7
|
+
* - `"openrouter/meta-llama/llama-3"` → provider="openrouter", name="meta-llama/llama-3"
|
|
8
|
+
* - `"claude-sonnet-4-6"` → provider=undefined, name="claude-sonnet-4-6"
|
|
9
|
+
*
|
|
10
|
+
* The first `/` separates the provider from the rest. Models with embedded
|
|
11
|
+
* slashes (e.g. OpenRouter routing) keep the remainder intact. Tag suffixes
|
|
12
|
+
* (`:latest`, `:3b`) are preserved as part of the name — Ollama expects them.
|
|
13
|
+
*
|
|
14
|
+
* **Returns `undefined` provider** when no `/` is present so callers can
|
|
15
|
+
* fall back to env-var detection. Empty/whitespace components are treated
|
|
16
|
+
* as no-prefix.
|
|
17
|
+
*
|
|
18
|
+
* Aligned with OpenClaw `extensions/ollama/src/discovery-shared.ts`
|
|
19
|
+
* (`OLLAMA_PROVIDER_ID = "ollama"`) and Hermes `hermes_cli/providers.py`
|
|
20
|
+
* (ALIASES table, `normalize_provider`).
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseModelId(modelId: string | undefined): ParsedModelId;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama native API client (T8.1 follow-up, ADR D191).
|
|
3
|
+
*
|
|
4
|
+
* Targets Ollama's native `/api/chat` endpoint with NDJSON streaming.
|
|
5
|
+
* Critical for **tool calling** — per OpenClaw upstream warning, the
|
|
6
|
+
* OpenAI-compat `/v1/chat/completions` endpoint BREAKS tool calling in
|
|
7
|
+
* Ollama (models emit raw tool JSON as text instead of structured
|
|
8
|
+
* `tool_calls` blocks). Mirrors OpenClaw `extensions/ollama/src/stream.ts`.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
13
|
+
export interface OllamaNativeClientOptions {
|
|
14
|
+
/** Optional API key for Ollama Cloud / reverse-proxy. Local Ollama ignores `Authorization`. */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** Base URL. Default `http://localhost:11434`. `/v1` suffix is stripped automatically. */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
}
|
|
20
|
+
export declare class OllamaNativeClient implements LlmClient {
|
|
21
|
+
private readonly options;
|
|
22
|
+
readonly name = "ollama";
|
|
23
|
+
private readonly baseUrl;
|
|
24
|
+
private readonly fetchImpl;
|
|
25
|
+
constructor(options: OllamaNativeClientOptions);
|
|
26
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
2
|
+
export declare class OpenAIClient implements LlmClient {
|
|
3
|
+
private readonly options;
|
|
4
|
+
readonly name = "openai";
|
|
5
|
+
private readonly baseUrl;
|
|
6
|
+
private readonly fetchImpl;
|
|
7
|
+
constructor(options: OpenAIClientOptions);
|
|
8
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `LlmClient` wrapper that pools multiple API keys for the same
|
|
3
|
+
* provider and rotates on HTTP 429/402/401 (ADRs D123-D133).
|
|
4
|
+
*
|
|
5
|
+
* Composition wrapper (D127) — wraps a builder that produces a real
|
|
6
|
+
* `LlmClient` for a given API key. The wrapper picks a key via the
|
|
7
|
+
* pool, instantiates the real client, attempts the stream, and on a
|
|
8
|
+
* pre-stream error decides retry-vs-rotate per the decision matrix.
|
|
9
|
+
*
|
|
10
|
+
* Once `yield*` starts (first event received), rotation is impossible —
|
|
11
|
+
* partial output would corrupt the stream. Same contract as
|
|
12
|
+
* `FallbackLlmClient` (D2).
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CredentialPoolStrategy } from "./credential-pool-types.js";
|
|
2
|
+
import type { LlmClient } from "./types.js";
|
|
3
|
+
export interface ProviderRouterOptions {
|
|
4
|
+
primary: ProviderName;
|
|
5
|
+
fallback?: ProviderName[];
|
|
6
|
+
/** Credential pools per provider (ADRs D123-D133). Optional. */
|
|
7
|
+
apiKeys?: Record<string, string[]>;
|
|
8
|
+
/** Pool rotation strategy per provider. Optional; default `"fill_first"`. */
|
|
9
|
+
credentialPoolStrategy?: Record<string, CredentialPoolStrategy>;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveProviderChainAsync(options: ProviderRouterOptions): Promise<LlmClient[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Sync variant. Kept for backward compat with existing callers that
|
|
14
|
+
* already invoked discovery upfront (e.g., via Agent.create initialization).
|
|
15
|
+
* Builtins are still eagerly registered.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveProviderChain(options: ProviderRouterOptions): LlmClient[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Server-Sent-Events parser. Consumes a fetch `Response` body
|
|
3
|
+
* stream and yields `{ event, data }` records as they arrive. Used by
|
|
4
|
+
* both the Anthropic and OpenAI streaming clients — neither vendor sends
|
|
5
|
+
* binary SSE so a simple text decoder is enough.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseSseStream(body: ReadableStream<Uint8Array> | null, signal: AbortSignal): AsyncGenerator<SseRecord, void, void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared streaming helpers for `LlmClient` wrappers
|
|
3
|
+
* (`FallbackLlmClient`, `PoolAwareLlmClient`).
|
|
4
|
+
*
|
|
5
|
+
* `tryFirstEvent` probes the first chunk of a stream to decide
|
|
6
|
+
* whether the handshake succeeded. If it raises an
|
|
7
|
+
* `AuthenticationError`/`RateLimitError`/`NetworkError`, the wrapper
|
|
8
|
+
* captures the typed error for routing (rotate vs fallback) WITHOUT
|
|
9
|
+
* starting the actual yield. Once the first event lands, the stream
|
|
10
|
+
* is committed and partial-output cannot be reverted.
|
|
11
|
+
*
|
|
12
|
+
* `relay` yields the prefetched first chunk and then forwards the
|
|
13
|
+
* remaining generator output verbatim.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-agnostic LLM types used by the real agent loop. Each concrete
|
|
3
|
+
* provider client (`anthropic.ts`, `openai.ts`) accepts an `LlmRequest`
|
|
4
|
+
* and yields a stream of `LlmEvent`s plus a final `LlmFinish` shape that
|
|
5
|
+
* the agent loop converts into our `SDKMessage` events.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface LlmTextPart {
|
|
10
|
+
type: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface LlmToolCallPart {
|
|
14
|
+
type: "tool_use";
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
input: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface LlmToolResultPart {
|
|
20
|
+
type: "tool_result";
|
|
21
|
+
toolUseId: string;
|
|
22
|
+
content: string;
|
|
23
|
+
isError?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type LlmContentPart = LlmTextPart | LlmToolCallPart | LlmToolResultPart;
|
|
26
|
+
export interface LlmMessage {
|
|
27
|
+
role: "system" | "user" | "assistant";
|
|
28
|
+
content: LlmContentPart[];
|
|
29
|
+
}
|
|
30
|
+
export interface LlmRequest {
|
|
31
|
+
model: string;
|
|
32
|
+
system?: string;
|
|
33
|
+
messages: LlmMessage[];
|
|
34
|
+
tools?: LlmTool[];
|
|
35
|
+
maxTokens?: number;
|
|
36
|
+
temperature?: number;
|
|
37
|
+
}
|
|
38
|
+
export type LlmEvent = {
|
|
39
|
+
type: "text_delta";
|
|
40
|
+
text: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: "tool_use";
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
input: Record<string, unknown>;
|
|
46
|
+
} | {
|
|
47
|
+
type: "stop";
|
|
48
|
+
reason: LlmStopReason;
|
|
49
|
+
} | {
|
|
50
|
+
type: "error";
|
|
51
|
+
message: string;
|
|
52
|
+
};
|
|
53
|
+
export type LlmStopReason = "end_turn" | "tool_use" | "max_tokens" | "stop_sequence" | "error";
|
|
54
|
+
export interface LlmFinish {
|
|
55
|
+
stopReason: LlmStopReason;
|
|
56
|
+
text: string;
|
|
57
|
+
toolCalls: LlmToolCallPart[];
|
|
58
|
+
inputTokens?: number;
|
|
59
|
+
outputTokens?: number;
|
|
60
|
+
/** Cache read tokens (Anthropic prompt caching / OpenAI cached). ADR D376. */
|
|
61
|
+
cacheReadTokens?: number;
|
|
62
|
+
/** Cache creation tokens (Anthropic only). ADR D376. */
|
|
63
|
+
cacheWriteTokens?: number;
|
|
64
|
+
/** Reasoning tokens (OpenAI o-series). ADR D376. */
|
|
65
|
+
reasoningTokens?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface LlmClient {
|
|
68
|
+
readonly name: string;
|
|
69
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCP Vertex AI client for Anthropic Messages (Adoption Roadmap #8; ADRs
|
|
3
|
+
* D292, D293).
|
|
4
|
+
*
|
|
5
|
+
* v1 uses `:rawPredict` (non-streaming). Streaming via `:streamRawPredict`
|
|
6
|
+
* with SSE follows the same shape but is gated behind a future iteration —
|
|
7
|
+
* v1 returns the full response as a single delta to keep the streaming
|
|
8
|
+
* interface contract.
|
|
9
|
+
*
|
|
10
|
+
* Body massage (D292):
|
|
11
|
+
* - inject `anthropic_version: "vertex-2023-10-16"`
|
|
12
|
+
* - strip `model` from body (goes in URL)
|
|
13
|
+
* - strip `stream` from body
|
|
14
|
+
*
|
|
15
|
+
* Uses native `fetch` only — no `@anthropic-ai/vertex-sdk` (D294).
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
20
|
+
export interface VertexAnthropicClientOptions {
|
|
21
|
+
/** When undefined, resolved lazily via `resolveVertexProjectId()`. */
|
|
22
|
+
projectId?: string;
|
|
23
|
+
/** When undefined, resolved lazily via `resolveVertexLocation()`. */
|
|
24
|
+
location?: string;
|
|
25
|
+
/**
|
|
26
|
+
* OAuth access token. When provided, used as-is. When empty/undefined,
|
|
27
|
+
* resolved lazily per request via `resolveVertexAccessToken()` (D288).
|
|
28
|
+
*/
|
|
29
|
+
apiKey?: string;
|
|
30
|
+
fetch?: typeof fetch;
|
|
31
|
+
}
|
|
32
|
+
export declare class VertexAnthropicClient implements LlmClient {
|
|
33
|
+
private readonly options;
|
|
34
|
+
readonly name = "vertex_anthropic";
|
|
35
|
+
private readonly fetchImpl;
|
|
36
|
+
constructor(options: VertexAnthropicClientOptions);
|
|
37
|
+
private resolveProjectOrThrow;
|
|
38
|
+
private resolveTokenOrThrow;
|
|
39
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vertex AI access token + config resolution (ADRs D288, D295).
|
|
3
|
+
*
|
|
4
|
+
* Uses `google-auth-library` (required peer dep) for ADC discovery:
|
|
5
|
+
* 1. `GOOGLE_APPLICATION_CREDENTIALS` env (path to Service Account JSON)
|
|
6
|
+
* 2. `gcloud auth application-default login` cached credentials
|
|
7
|
+
* 3. Metadata server (GCE/GKE/Cloud Run/Cloud Functions)
|
|
8
|
+
* 4. Workload Identity Federation (WIF; configured via Service Account JSON)
|
|
9
|
+
*
|
|
10
|
+
* EC-3 absorbed: differentiate "peer dep missing" (throws ConfigurationError
|
|
11
|
+
* with install hint) from "no credentials in ADC chain" (returns undefined
|
|
12
|
+
* so caller can throw a clearer downstream error).
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
interface GoogleAuthClient {
|
|
17
|
+
getAccessToken: () => Promise<{
|
|
18
|
+
token: string | null;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export declare function resolveVertexAccessToken(): Promise<string | undefined>;
|
|
22
|
+
/** Resolve project id via env vars (env-only in v1). */
|
|
23
|
+
export declare function resolveVertexProjectId(): string | undefined;
|
|
24
|
+
/** Resolve Vertex location (region) from env; defaults to `us-central1`. */
|
|
25
|
+
export declare function resolveVertexLocation(): string;
|
|
26
|
+
/** Test seam — reset cached auth client. */
|
|
27
|
+
export declare function __resetVertexAuth(): void;
|
|
28
|
+
/** Test seam — inject a custom client for unit tests. */
|
|
29
|
+
export declare function __setVertexAuthClientForTests(client: GoogleAuthClient | undefined): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCP Vertex AI Gemini client (Adoption Roadmap #8; ADR D291).
|
|
3
|
+
*
|
|
4
|
+
* Uses the **OpenAI-compat** endpoint:
|
|
5
|
+
* POST https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{P}/locations/{L}/endpoints/openapi/chat/completions
|
|
6
|
+
*
|
|
7
|
+
* Wraps `OpenAIClient` with the Vertex baseUrl + lazy OAuth token from
|
|
8
|
+
* `google-auth-library` (D288). Limitation: Vertex silently drops
|
|
9
|
+
* unsupported OpenAI params (D264-style trade-off, documented in docs.md).
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
14
|
+
export interface VertexGeminiClientOptions {
|
|
15
|
+
/** When undefined, resolved lazily via `resolveVertexProjectId()`. */
|
|
16
|
+
projectId?: string;
|
|
17
|
+
/** When undefined, resolved lazily via `resolveVertexLocation()`. */
|
|
18
|
+
location?: string;
|
|
19
|
+
/** When non-empty, used as-is. Otherwise resolved lazily via ADC. */
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
fetch?: typeof fetch;
|
|
22
|
+
}
|
|
23
|
+
export declare class VertexGeminiClient implements LlmClient {
|
|
24
|
+
private readonly options;
|
|
25
|
+
readonly name = "vertex_gemini";
|
|
26
|
+
constructor(options: VertexGeminiClientOptions);
|
|
27
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vertex AI dispatcher (Adoption Roadmap #8; ADRs D291, D292, D301).
|
|
3
|
+
*
|
|
4
|
+
* `selectTransport` doesn't see the model id (the credential resolution
|
|
5
|
+
* happens before request dispatch). This client inspects `request.model`
|
|
6
|
+
* at stream time and delegates to either `VertexGeminiClient` (OpenAI-compat
|
|
7
|
+
* for Gemini) or `VertexAnthropicClient` (`:rawPredict` for Claude).
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
import type { LlmClient, LlmEvent, LlmFinish, LlmRequest } from "./types.js";
|
|
12
|
+
export interface VertexRouterClientOptions {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
}
|
|
16
|
+
export declare class VertexRouterClient implements LlmClient {
|
|
17
|
+
private readonly options;
|
|
18
|
+
readonly name = "vertex";
|
|
19
|
+
constructor(options: VertexRouterClientOptions);
|
|
20
|
+
stream(request: LlmRequest, signal: AbortSignal): AsyncGenerator<LlmEvent, LlmFinish, void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { McpServerConfig } from "../../types/mcp.js";
|
|
2
|
+
export interface McpToolCallResult {
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
}>;
|
|
7
|
+
isError?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface McpClient {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
listTools(): Promise<McpTool[]>;
|
|
13
|
+
callTool(name: string, args: Record<string, unknown>): Promise<McpToolCallResult>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createMcpClient(name: string, config: McpServerConfig): McpClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ActiveMemoryResult } from "./active-memory.js";
|
|
2
|
+
export declare class ActiveMemoryCache {
|
|
3
|
+
private readonly opts;
|
|
4
|
+
private readonly map;
|
|
5
|
+
constructor(opts?: ActiveMemoryCacheOptions);
|
|
6
|
+
get(userText: string, queryMode: string): ActiveMemoryResult | undefined;
|
|
7
|
+
set(userText: string, queryMode: string, result: ActiveMemoryResult): void;
|
|
8
|
+
size(): number;
|
|
9
|
+
private now;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ActiveMemoryCache } from "./active-memory-cache.js";
|
|
2
|
+
import type { CircuitBreaker } from "./circuit-breaker.js";
|
|
3
|
+
import type { MemorySearchHit } from "./index-manager.js";
|
|
4
|
+
import type { MemoryIndex } from "./memory-index.js";
|
|
5
|
+
export type ActiveMemoryStatus = "ok" | "timeout" | "skipped" | "no-recall" | "error";
|
|
6
|
+
export interface ActiveMemoryResult {
|
|
7
|
+
summary: string | undefined;
|
|
8
|
+
durationMs: number;
|
|
9
|
+
status: ActiveMemoryStatus;
|
|
10
|
+
hits: ReadonlyArray<MemorySearchHit>;
|
|
11
|
+
}
|
|
12
|
+
export interface ActiveMemoryOptions {
|
|
13
|
+
/** Whether active recall is enabled. Default `false`. */
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
/** Query construction strategy. Default `"recent"`. */
|
|
16
|
+
queryMode?: ActiveMemoryQueryMode;
|
|
17
|
+
/** Hard timeout in ms. Default `15000`. */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/** Max chars in the summary. Default `220`. */
|
|
20
|
+
maxSummaryChars?: number;
|
|
21
|
+
/** Number of recent user turns to include in `queryMode === "recent"`. Default `2`. */
|
|
22
|
+
recentUserTurns?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface RunActiveMemoryArgs {
|
|
25
|
+
userText: string;
|
|
26
|
+
priorMessages: ReadonlyArray<{
|
|
27
|
+
role: "user" | "assistant";
|
|
28
|
+
text: string;
|
|
29
|
+
}>;
|
|
30
|
+
index: MemoryIndex | undefined;
|
|
31
|
+
options: ActiveMemoryOptions;
|
|
32
|
+
/** Per-agent circuit breaker (Phase 8). */
|
|
33
|
+
breaker?: CircuitBreaker;
|
|
34
|
+
/** Per-agent result cache (Phase 8). */
|
|
35
|
+
cache?: ActiveMemoryCache;
|
|
36
|
+
/** Workspace root for transcript persistence. */
|
|
37
|
+
cwd?: string;
|
|
38
|
+
/** When true, write transcript JSON under .theokit/memory/transcripts/active-memory/. */
|
|
39
|
+
persistTranscripts?: boolean;
|
|
40
|
+
/** Stable key the breaker + cache key by (default `default`). */
|
|
41
|
+
agentKey?: string;
|
|
42
|
+
/** Run id for transcript file naming. */
|
|
43
|
+
runId?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare function runActiveMemory(args: RunActiveMemoryArgs): Promise<ActiveMemoryResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama embedding adapter (T3.1, ADR D183).
|
|
3
|
+
*
|
|
4
|
+
* Targets Ollama's OpenAI-compatible `/v1/embeddings` endpoint and reuses
|
|
5
|
+
* the shared `createOpenAiCompatibleRuntime` factory. The differentiating
|
|
6
|
+
* bits:
|
|
7
|
+
*
|
|
8
|
+
* - `authType: "none"` — Ollama local ignores `Authorization`. Sentinel
|
|
9
|
+
* `"ollama-local"` is passed as apiKey to satisfy the factory contract
|
|
10
|
+
* (mirrors OpenClaw `OLLAMA_DEFAULT_API_KEY = "ollama-local"`).
|
|
11
|
+
* - `OLLAMA_HOST` overrides the default `http://localhost:11434`.
|
|
12
|
+
* - `OLLAMA_API_KEY` (optional) overrides the sentinel for Ollama Cloud
|
|
13
|
+
* or reverse-proxy auth setups.
|
|
14
|
+
* - Default model: `nomic-embed-text` (768 dim, ~274MB). User can opt
|
|
15
|
+
* into `all-minilm` (384 dim, ~45MB) or any other locally-installed
|
|
16
|
+
* embedding model.
|
|
17
|
+
*
|
|
18
|
+
* EC-B MUST FIX (edge-case review 2026-05-21): empty text is rejected
|
|
19
|
+
* upstream in the shared factory (`classifyEntry` short-circuits to a
|
|
20
|
+
* zero vector). That behavior is acceptable here because the zero
|
|
21
|
+
* vector is identical for any empty input — downstream similarity
|
|
22
|
+
* calcs ignore zero-norm vectors via the existing `cosineSimilarity`
|
|
23
|
+
* guard. No additional fail-fast needed.
|
|
24
|
+
*
|
|
25
|
+
* EC-A MUST FIX (edge-case review 2026-05-21): dimension is locked
|
|
26
|
+
* by the `DIMENSION_BY_MODEL` table; an unknown model id throws
|
|
27
|
+
* `ConfigurationError(code: "embedding_unknown_model")` per the
|
|
28
|
+
* factory's EC-4 contract. Future model versions with different
|
|
29
|
+
* dimensions are added to the table here without breaking changes.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_OLLAMA_EMBEDDING_MODEL = "nomic-embed-text";
|
|
34
|
+
export declare const ollamaMemoryEmbeddingProviderAdapter: MemoryEmbeddingProviderAdapter;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CreateAdapterOptions, EmbeddingRuntime } from "../embedding-adapter.js";
|
|
2
|
+
export interface OpenAiCompatibleConfig {
|
|
3
|
+
id: string;
|
|
4
|
+
defaultBaseUrl: string;
|
|
5
|
+
apiKeyEnv: string;
|
|
6
|
+
baseUrlEnv?: string;
|
|
7
|
+
defaultModel: string;
|
|
8
|
+
/**
|
|
9
|
+
* Dimension hint by model id. The chosen model MUST be in this table —
|
|
10
|
+
* unknown models throw `ConfigurationError(code: "embedding_unknown_model")`
|
|
11
|
+
* (EC-4 fix). This prevents vec0 virtual-table dimension mismatches that
|
|
12
|
+
* surface as cryptic errors downstream.
|
|
13
|
+
*/
|
|
14
|
+
dimensionByModel: Record<string, number>;
|
|
15
|
+
/**
|
|
16
|
+
* Path component appended to `baseUrl` for the embeddings endpoint.
|
|
17
|
+
* Default `"/v1/embeddings"` (OpenAI canonical). REPLACES the default —
|
|
18
|
+
* does NOT concatenate. Used by DeepInfra (`"/v1/openai/embeddings"`),
|
|
19
|
+
* etc. (EC-2 fix).
|
|
20
|
+
*/
|
|
21
|
+
embeddingsPath?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function createOpenAiCompatibleRuntime(cfg: OpenAiCompatibleConfig, options: CreateAdapterOptions): Promise<EmbeddingRuntime>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consecutive-timeout circuit breaker for Active Memory recall.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors OpenClaw's `circuitBreakerMaxTimeouts` + `circuitBreakerCooldownMs`
|
|
5
|
+
* config: after N consecutive timeouts the breaker trips and `shouldSkip`
|
|
6
|
+
* returns `true` until `cooldownMs` has elapsed. A successful recall resets
|
|
7
|
+
* the counter immediately.
|
|
8
|
+
*
|
|
9
|
+
* Per-key isolation so two agents in the same process don't share a counter.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare class CircuitBreaker {
|
|
14
|
+
private readonly opts;
|
|
15
|
+
private readonly states;
|
|
16
|
+
constructor(opts?: CircuitBreakerOptions);
|
|
17
|
+
/** @returns true when the breaker is open and the call should be skipped. */
|
|
18
|
+
shouldSkip(key: string): boolean;
|
|
19
|
+
recordSuccess(key: string): void;
|
|
20
|
+
recordTimeout(key: string): void;
|
|
21
|
+
private now;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function diaryPath(cwd: string): string;
|
|
2
|
+
export declare function renderDiaryEntry(entry: DiaryEntry): string;
|
|
3
|
+
export declare function appendDiaryEntry(cwd: string, entry: DiaryEntry): Promise<void>;
|
|
4
|
+
export declare function entryHash(entry: DiaryEntry): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "../embedding-adapter.js";
|
|
2
|
+
import type { MemoryFact } from "../types.js";
|
|
3
|
+
export interface Cluster {
|
|
4
|
+
representativeText: string;
|
|
5
|
+
members: ReadonlyArray<MemoryFact>;
|
|
6
|
+
}
|
|
7
|
+
export interface ClusterResult {
|
|
8
|
+
clusters: Cluster[];
|
|
9
|
+
}
|
|
10
|
+
/** Light phase — drop facts whose embedding is too similar to one already kept. */
|
|
11
|
+
export declare function lightPhase(facts: ReadonlyArray<MemoryFact>, embedding: EmbeddingRuntime, threshold?: number): Promise<DedupResult>;
|
|
12
|
+
/** REM phase — single-link agglomerative clustering by cosine similarity. */
|
|
13
|
+
export declare function remPhase(facts: ReadonlyArray<MemoryFact>, embedding: EmbeddingRuntime, threshold?: number): Promise<ClusterResult>;
|
|
14
|
+
/** Deep phase — render consolidated markdown for the dreamed note. */
|
|
15
|
+
export declare function deepPhase(clusters: ReadonlyArray<Cluster>, timestampMs: number): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface DreamingResult {
|
|
2
|
+
status: "ok" | "skipped" | "error";
|
|
3
|
+
factsBefore: number;
|
|
4
|
+
factsAfter: number;
|
|
5
|
+
duplicatesRemoved: number;
|
|
6
|
+
clustersCreated: number;
|
|
7
|
+
notesWritten: number;
|
|
8
|
+
diaryEntryHash: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function runDreamingSweep(options: DreamingOptions): Promise<DreamingResult>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory embedding provider adapter contract (ADR D3 of memory-system-openclaw-parity).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors OpenClaw's `MemoryEmbeddingProviderAdapter` from
|
|
5
|
+
* `referencia/openclaw/extensions/openai/memory-embedding-adapter.ts` so
|
|
6
|
+
* adding a new provider becomes one new file under `adapters/`.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export interface CreateAdapterOptions {
|
|
11
|
+
/** Override the adapter's `defaultModel`. */
|
|
12
|
+
model?: string;
|
|
13
|
+
/** Override the API key (else resolved from env). */
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/** Override the HTTP base URL (else provider default). */
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
/** Inject a fetch implementation (tests use this to stub HTTP). */
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
/** Optional cache instance (else a default LRU is created). */
|
|
20
|
+
cache?: EmbeddingCache;
|
|
21
|
+
}
|
|
22
|
+
export interface EmbeddingRuntime {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly model: string;
|
|
25
|
+
readonly dimension: number;
|
|
26
|
+
/** Embed N texts → N vectors of length `dimension`. Handles batching internally. */
|
|
27
|
+
embed(texts: ReadonlyArray<string>): Promise<number[][]>;
|
|
28
|
+
/** Observability — cache hit/miss + call counts. */
|
|
29
|
+
stats(): EmbeddingRuntimeStats;
|
|
30
|
+
}
|
|
31
|
+
export interface EmbeddingRuntimeStats {
|
|
32
|
+
cacheHits: number;
|
|
33
|
+
cacheMisses: number;
|
|
34
|
+
httpCalls: number;
|
|
35
|
+
retries: number;
|
|
36
|
+
}
|
|
37
|
+
export interface EmbeddingCache {
|
|
38
|
+
get(key: string): number[] | undefined;
|
|
39
|
+
set(key: string, value: number[]): void;
|
|
40
|
+
/** Total entries currently held. */
|
|
41
|
+
size(): number;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface OpenDbOptions {
|
|
2
|
+
filePath: string;
|
|
3
|
+
/**
|
|
4
|
+
* When true and opening fails with a corruption error, rename the file aside
|
|
5
|
+
* and create a fresh DB. Default true.
|
|
6
|
+
*/
|
|
7
|
+
recoverCorrupt?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function openMemoryDb(opts: OpenDbOptions): Promise<MemoryDb>;
|
|
10
|
+
export declare function defaultIndexPath(cwd: string): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch helpers for `IndexManager.open`. Extracted to keep
|
|
3
|
+
* `index-manager.ts` under the G8 400-LoC budget (lancedb-backend-ship-v1-1).
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
import type { MemoryBackend, OpenIndexOptions } from "./index-manager.js";
|
|
8
|
+
import type { MemoryIndex } from "./memory-index.js";
|
|
9
|
+
/** Valid backend identifiers — runtime guard against TS-narrowing escapes (EC-1). */
|
|
10
|
+
export declare const VALID_BACKENDS: readonly MemoryBackend[];
|
|
11
|
+
/**
|
|
12
|
+
* EC-1: runtime guard for `opts.backend`. TS union is compile-time only;
|
|
13
|
+
* consumers passing JS `as any` typos must hit a typed error, not silent
|
|
14
|
+
* SQLite fallback.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertValidBackend(backend: string): asserts backend is MemoryBackend;
|
|
17
|
+
/**
|
|
18
|
+
* Lance-path open. Throws `lance_requires_embedding` when no embedding
|
|
19
|
+
* runtime is provided (Lance is vector-only — no FTS fallback).
|
|
20
|
+
* Surfaces `lance_backend_unavailable` from LanceIndex.open when peer
|
|
21
|
+
* dep is absent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function openLanceIndex(opts: OpenIndexOptions): Promise<MemoryIndex>;
|