@theokit/sdk 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +187 -0
- package/dist/a2a/agent-mailbox.d.cts +27 -0
- package/dist/a2a/agent-mailbox.d.ts +27 -0
- package/dist/a2a/index.cjs +16850 -0
- package/dist/a2a/index.cjs.map +1 -0
- package/dist/a2a/index.d.cts +9 -0
- package/dist/a2a/index.d.ts +9 -0
- package/dist/a2a/index.js +16844 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/a2a/message-bus.d.cts +27 -0
- package/dist/a2a/message-bus.d.ts +27 -0
- package/dist/a2a/subagent.d.cts +25 -0
- package/dist/a2a/subagent.d.ts +25 -0
- package/dist/a2a/types.d.cts +12 -0
- package/dist/a2a/types.d.ts +12 -0
- package/dist/agent.d.ts +1 -1
- package/dist/client/index.cjs +73 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +7 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +71 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/theokit-client.d.cts +18 -0
- package/dist/client/theokit-client.d.ts +18 -0
- package/dist/client/types.d.cts +19 -0
- package/dist/client/types.d.ts +19 -0
- package/dist/{run-DkCD5DeO.d.cts → cron-BnywDYLq.d.cts} +496 -910
- package/dist/{run-DkCD5DeO.d.ts → cron-CtZvJD9J.d.ts} +496 -910
- package/dist/cron.cjs +4285 -2893
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -3
- package/dist/cron.d.ts +2 -71
- package/dist/cron.js +4289 -2897
- package/dist/cron.js.map +1 -1
- package/dist/{errors-CvAeEWgE.d.ts → errors-ChqOmFH1.d.cts} +52 -6
- package/dist/{errors-CK8brCJ1.d.cts → errors-DV9e0rcp.d.ts} +52 -6
- package/dist/errors.cjs +218 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -3
- package/dist/errors.d.ts +50 -4
- package/dist/errors.js +217 -4
- package/dist/errors.js.map +1 -1
- package/dist/eval.cjs +4285 -2893
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +35 -0
- package/dist/eval.js +4289 -2897
- package/dist/eval.js.map +1 -1
- package/dist/event-bus.d.ts +23 -0
- package/dist/index.cjs +5132 -4200
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +298 -278
- package/dist/index.d.ts +1898 -24
- package/dist/index.js +6441 -5509
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +22 -1
- package/dist/internal/auth/api-key-validator.d.ts +46 -0
- package/dist/internal/llm/anthropic-shared.d.ts +8 -1
- package/dist/internal/llm/retry.d.ts +22 -0
- package/dist/internal/llm/types.d.ts +47 -1
- package/dist/internal/memory/active-memory-cache.d.ts +3 -3
- package/dist/internal/memory/active-memory-types.d.ts +8 -0
- package/dist/internal/memory/active-memory.d.ts +24 -20
- package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
- package/dist/internal/memory/index-manager-contract.d.ts +26 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +1 -1
- package/dist/internal/memory/index-manager.d.ts +8 -26
- package/dist/internal/memory/{chunk-markdown.d.ts → storage/chunk-markdown.d.ts} +1 -1
- package/dist/internal/memory/{markdown-store.d.ts → storage/markdown-store.d.ts} +1 -1
- package/dist/internal/memory/{reader.d.ts → storage/reader.d.ts} +1 -1
- package/dist/internal/observability/context.d.cts +23 -0
- package/dist/internal/observability/context.d.ts +23 -0
- package/dist/internal/observability/index.cjs +38 -0
- package/dist/internal/observability/index.cjs.map +1 -0
- package/dist/internal/observability/index.d.cts +8 -0
- package/dist/internal/observability/index.d.ts +8 -0
- package/dist/internal/observability/index.js +33 -0
- package/dist/internal/observability/index.js.map +1 -0
- package/dist/internal/observability/tracer-loader.d.cts +20 -0
- package/dist/internal/persistence/conversation-storage-fs.d.cts +37 -0
- package/dist/internal/persistence/conversation-storage-memory.d.cts +24 -0
- package/dist/internal/persistence/credential-pool-store.d.cts +32 -0
- package/dist/internal/persistence/credential-pool-store.d.ts +32 -0
- package/dist/internal/persistence/cwd-mutex.d.cts +1 -0
- package/dist/internal/persistence/exclusive-create.d.cts +22 -0
- package/dist/internal/persistence/exclusive-create.d.ts +22 -0
- package/dist/internal/persistence/file-lock.d.cts +14 -0
- package/dist/internal/persistence/fts5-sanitize.d.cts +16 -0
- package/dist/internal/persistence/index.cjs +359 -0
- package/dist/internal/persistence/index.cjs.map +1 -0
- package/dist/internal/persistence/index.d.cts +20 -0
- package/dist/internal/persistence/index.d.ts +20 -0
- package/dist/internal/persistence/index.js +341 -0
- package/dist/internal/persistence/index.js.map +1 -0
- package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
- package/dist/internal/persistence/paths.d.cts +19 -0
- package/dist/internal/persistence/persistence-schema.d.cts +21 -0
- package/dist/internal/persistence/persistence-schema.d.ts +4 -0
- package/dist/internal/persistence/schema-version.d.cts +13 -0
- package/dist/internal/persistence/sqlite-cas.d.cts +25 -0
- package/dist/internal/persistence/sqlite-cas.d.ts +25 -0
- package/dist/internal/persistence/sqlite-wal.d.cts +10 -0
- package/dist/internal/plugins/context.d.cts +31 -0
- package/dist/internal/plugins/index.cjs +228 -0
- package/dist/internal/plugins/index.cjs.map +1 -0
- package/dist/internal/plugins/index.d.cts +8 -0
- package/dist/internal/plugins/index.d.ts +8 -0
- package/dist/internal/plugins/index.js +222 -0
- package/dist/internal/plugins/index.js.map +1 -0
- package/dist/internal/plugins/lifecycle.d.cts +14 -0
- package/dist/internal/plugins/lifecycle.d.ts +14 -0
- package/dist/internal/plugins/manager.d.cts +37 -0
- package/dist/internal/plugins/types.d.cts +102 -0
- package/dist/internal/providers/catalog-loader.d.ts +39 -0
- package/dist/internal/runtime/agent-session-store.d.ts +1 -1
- package/dist/internal/runtime/agent-session.d.ts +1 -0
- package/dist/internal/runtime/budget-tracker.d.ts +73 -0
- package/dist/internal/runtime/{context-manager.d.ts → context/context-manager.d.ts} +1 -1
- package/dist/internal/runtime/{fixture-events.d.ts → fixtures/fixture-events.d.ts} +1 -1
- package/dist/internal/runtime/{fixture-run-base.d.ts → fixtures/fixture-run-base.d.ts} +4 -4
- package/dist/internal/runtime/{fixture-scripts.d.ts → fixtures/fixture-scripts.d.ts} +1 -1
- package/dist/internal/runtime/local-agent-bootstrap.d.ts +2 -2
- package/dist/internal/runtime/local-agent-memory-provider.d.ts +57 -0
- package/dist/internal/runtime/memory-path-selector.d.ts +73 -0
- package/dist/internal/runtime/memory-provider.d.ts +165 -0
- package/dist/internal/runtime/{agent-registry.d.ts → registry/agent-registry-contract.d.ts} +15 -9
- package/dist/internal/runtime/registry/agent-registry.d.ts +7 -0
- package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts} +1 -1
- package/dist/internal/runtime/{run-registry.d.ts → registry/run-registry.d.ts} +1 -1
- package/dist/internal/runtime/session-types.d.ts +35 -0
- package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/validate-response.d.ts +18 -0
- package/dist/internal/security/index.cjs +361 -0
- package/dist/internal/security/index.cjs.map +1 -0
- package/dist/internal/security/index.d.cts +11 -0
- package/dist/internal/security/index.js +350 -0
- package/dist/internal/security/index.js.map +1 -0
- package/dist/internal/security/path-guard.d.cts +59 -0
- package/dist/internal/security/path-guard.d.ts +3 -0
- package/dist/internal/security/redact.d.cts +21 -0
- package/dist/internal/security/secret-redactor.d.cts +1 -0
- package/dist/internal/security/secret-redactor.d.ts +1 -0
- package/dist/internal/security/test-reset.d.cts +10 -0
- package/dist/internal/security/test-reset.d.ts +10 -0
- package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
- package/dist/internal/telemetry/adapters/braintrust.d.ts +2 -0
- package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langsmith.d.ts +2 -0
- package/dist/internal/telemetry/span-names.d.ts +6 -0
- package/dist/internal/telemetry/tracer.d.ts +1 -0
- package/dist/internal/workflow/evented-executor.d.ts +42 -0
- package/dist/internal/workflow/scheduler.d.ts +23 -0
- package/dist/internal/zod/to-json-schema.d.ts +5 -15
- package/dist/job-queue.d.ts +28 -0
- package/dist/path-safety.cjs +67 -6
- package/dist/path-safety.cjs.map +1 -1
- package/dist/path-safety.d.cts +15 -0
- package/dist/path-safety.d.ts +1 -1
- package/dist/path-safety.js +67 -7
- package/dist/path-safety.js.map +1 -1
- package/dist/permission-engine.d.ts +21 -0
- package/dist/provider-catalog.json +702 -0
- package/dist/rag/index.cjs +136 -0
- package/dist/rag/index.cjs.map +1 -0
- package/dist/rag/index.d.cts +11 -0
- package/dist/rag/index.d.ts +11 -0
- package/dist/rag/index.js +129 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/reranker.d.cts +26 -0
- package/dist/rag/reranker.d.ts +26 -0
- package/dist/rag/retriever.d.cts +25 -0
- package/dist/rag/retriever.d.ts +25 -0
- package/dist/rag/text-splitter.d.cts +12 -0
- package/dist/rag/text-splitter.d.ts +12 -0
- package/dist/rag/types.d.cts +37 -0
- package/dist/rag/types.d.ts +37 -0
- package/dist/run-DrwUpFxZ.d.cts +823 -0
- package/dist/run-DrwUpFxZ.d.ts +823 -0
- package/dist/sandbox/index.cjs +133 -0
- package/dist/sandbox/index.cjs.map +1 -0
- package/dist/sandbox/index.d.cts +2 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/sandbox/index.js +128 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/local-sandbox.d.cts +17 -0
- package/dist/sandbox/local-sandbox.d.ts +17 -0
- package/dist/sandbox/types.d.cts +44 -0
- package/dist/sandbox/types.d.ts +44 -0
- package/dist/server/adapter/express.d.cts +9 -0
- package/dist/server/adapter/express.d.ts +9 -0
- package/dist/server/adapter/fastify.d.cts +9 -0
- package/dist/server/adapter/fastify.d.ts +9 -0
- package/dist/server/adapter/hono.d.cts +9 -0
- package/dist/server/adapter/hono.d.ts +9 -0
- package/dist/server/adapter/index.d.cts +8 -0
- package/dist/server/adapter/index.d.ts +8 -0
- package/dist/server/adapter/shared-handler.d.cts +9 -0
- package/dist/server/adapter/shared-handler.d.ts +9 -0
- package/dist/server/adapter/types.d.cts +33 -0
- package/dist/server/adapter/types.d.ts +33 -0
- package/dist/server/auth/errors.d.cts +53 -0
- package/dist/server/auth/errors.d.ts +53 -0
- package/dist/server/auth/index.cjs +38 -41
- package/dist/server/auth/index.cjs.map +1 -1
- package/dist/server/auth/index.d.cts +11 -172
- package/dist/server/auth/index.d.ts +11 -172
- package/dist/server/auth/index.js +39 -42
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/oauth-transaction-store.d.cts +39 -0
- package/dist/server/auth/oauth-transaction-store.d.ts +39 -0
- package/dist/server/auth/orchestrator.d.cts +8 -0
- package/dist/server/auth/orchestrator.d.ts +8 -0
- package/dist/server/auth/types.d.cts +91 -0
- package/dist/server/auth/types.d.ts +91 -0
- package/dist/server/auth/validate-return-to.d.cts +17 -0
- package/dist/server/auth/validate-return-to.d.ts +17 -0
- package/dist/server/errors-envelope.cjs +409 -0
- package/dist/server/errors-envelope.cjs.map +1 -0
- package/dist/server/errors-envelope.d.cts +61 -0
- package/dist/server/errors-envelope.d.ts +61 -0
- package/dist/server/errors-envelope.js +405 -0
- package/dist/server/errors-envelope.js.map +1 -0
- package/dist/subscription/define-subscription.d.cts +63 -0
- package/dist/subscription/define-subscription.d.ts +63 -0
- package/dist/subscription/index.cjs +402 -0
- package/dist/subscription/index.cjs.map +1 -0
- package/dist/subscription/index.d.cts +18 -0
- package/dist/subscription/index.d.ts +18 -0
- package/dist/subscription/index.js +394 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/internal/adapter-types.d.cts +11 -0
- package/dist/subscription/internal/adapter-types.d.ts +11 -0
- package/dist/subscription/internal/backpressure.d.cts +24 -0
- package/dist/subscription/internal/backpressure.d.ts +24 -0
- package/dist/subscription/internal/server-integration.d.cts +17 -0
- package/dist/subscription/internal/server-integration.d.ts +17 -0
- package/dist/subscription/internal/sse-encoder.d.cts +13 -0
- package/dist/subscription/internal/sse-encoder.d.ts +13 -0
- package/dist/subscription/internal/sse-parser.d.cts +15 -0
- package/dist/subscription/internal/sse-parser.d.ts +15 -0
- package/dist/subscription/internal/subscription-runtime.d.cts +9 -0
- package/dist/subscription/internal/subscription-runtime.d.ts +9 -0
- package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
- package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
- package/dist/subscription/theokit-subscribe.d.cts +41 -0
- package/dist/subscription/theokit-subscribe.d.ts +41 -0
- package/dist/subscription/types.d.cts +140 -0
- package/dist/subscription/types.d.ts +140 -0
- package/dist/task-store.cjs +30 -2
- package/dist/task-store.cjs.map +1 -1
- package/dist/task-store.d.cts +8 -0
- package/dist/task-store.js +31 -3
- package/dist/task-store.js.map +1 -1
- package/dist/types/agent-prims.d.ts +61 -0
- package/dist/types/agent.d.ts +48 -53
- package/dist/types/conversation.d.ts +20 -8
- package/dist/types/index.d.ts +0 -2
- package/dist/types/messages-base.d.ts +20 -0
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/run.d.ts +1 -1
- package/dist/types/updates.d.ts +1 -1
- package/dist/voice/index.d.ts +7 -0
- package/dist/voice/openai-realtime.d.ts +21 -0
- package/dist/voice/types.d.ts +35 -0
- package/dist/workflow.cjs +179 -88
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +97 -0
- package/dist/workflow.js +180 -89
- package/dist/workflow.js.map +1 -1
- package/package.json +126 -25
- package/dist/budget.d.ts +0 -48
- package/dist/cache.d.ts +0 -74
- package/dist/cron-1yxL3K2S.d.cts +0 -221
- package/dist/cron-BYVdYzob.d.ts +0 -221
- package/dist/handoff.d.ts +0 -55
- package/dist/internal/budget/calendar-window.d.ts +0 -19
- package/dist/internal/budget/enforcement.d.ts +0 -32
- package/dist/internal/budget/ledger.d.ts +0 -25
- package/dist/internal/budget/normalize-usage.d.ts +0 -27
- package/dist/internal/budget/registry.d.ts +0 -16
- package/dist/internal/cache/cosine.d.ts +0 -14
- package/dist/internal/cache/embed-helper.d.ts +0 -15
- package/dist/internal/cache/key.d.ts +0 -15
- package/dist/internal/cache/lookup.d.ts +0 -28
- package/dist/internal/cache/store-handler.d.ts +0 -24
- package/dist/internal/cache/store-json.d.ts +0 -48
- package/dist/internal/cache/store.d.ts +0 -54
- package/dist/internal/cache/telemetry.d.ts +0 -20
- package/dist/internal/cache/ttl.d.ts +0 -11
- package/dist/internal/catalog/fixtures.d.ts +0 -16
- package/dist/internal/catalog/local-models.d.ts +0 -24
- package/dist/internal/handoff/dispatcher.d.ts +0 -29
- package/dist/internal/handoff/registry.d.ts +0 -23
- package/dist/internal/handoff/telemetry.d.ts +0 -18
- package/dist/internal/handoff/tool-injector.d.ts +0 -34
- package/dist/internal/memory/atomic-write.d.ts +0 -7
- package/dist/internal/memory/dreaming/diary.d.ts +0 -4
- package/dist/internal/memory/dreaming/phases.d.ts +0 -15
- package/dist/internal/memory/dreaming/run.d.ts +0 -10
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +0 -15
- package/dist/memory-adapter-helpers.d.ts +0 -28
- package/dist/memory.d.ts +0 -123
- package/dist/migrate.d.ts +0 -33
- package/dist/security.d.ts +0 -67
- package/dist/task.d.ts +0 -87
- package/dist/theokit.d.ts +0 -84
- package/dist/tools/_path-scope.d.ts +0 -8
- package/dist/tools/_subprocess.d.ts +0 -28
- package/dist/tools/git-diff.d.ts +0 -22
- package/dist/tools/index.d.ts +0 -29
- package/dist/tools/list-dir.d.ts +0 -26
- package/dist/tools/read-file.d.ts +0 -31
- package/dist/tools/run-vitest.d.ts +0 -46
- package/dist/tools/search-text.d.ts +0 -32
- package/dist/tools.cjs +0 -690
- package/dist/tools.cjs.map +0 -1
- package/dist/tools.js +0 -683
- package/dist/tools.js.map +0 -1
- package/dist/trajectory-helpers.d.ts +0 -31
- package/dist/types/cache.d.ts +0 -76
- package/dist/types/handoff.d.ts +0 -135
- /package/dist/{internal/cron/run-job.d.ts → agent-helpers.d.ts} +0 -0
- /package/dist/internal/{cron/scheduler.d.ts → agent-loop/loop-llm-stream.d.ts} +0 -0
- /package/dist/internal/{cron/store.d.ts → agent-loop/tool-executors.d.ts} +0 -0
- /package/dist/internal/{cron/validate.d.ts → memory/index-manager-helpers.d.ts} +0 -0
- /package/dist/internal/memory/{session-loader.d.ts → storage/session-loader.d.ts} +0 -0
- /package/dist/internal/memory/{session-summary-writer.d.ts → storage/session-summary-writer.d.ts} +0 -0
- /package/dist/internal/memory/{transcript-store.d.ts → storage/transcript-store.d.ts} +0 -0
- /package/dist/internal/memory/{wiki-loader.d.ts → storage/wiki-loader.d.ts} +0 -0
- /package/dist/internal/{memory/cwd-mutex.d.ts → persistence/atomic-write.d.cts} +0 -0
- /package/dist/internal/runtime/{context-aggregator.d.ts → context/context-aggregator.d.ts} +0 -0
- /package/dist/internal/runtime/{context-discovery-runner.d.ts → context/context-discovery-runner.d.ts} +0 -0
- /package/dist/internal/runtime/{context-discovery.d.ts → context/context-discovery.d.ts} +0 -0
- /package/dist/internal/runtime/{context-frontmatter.d.ts → context/context-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{context-import-resolver.d.ts → context/context-import-resolver.d.ts} +0 -0
- /package/dist/internal/runtime/{context-loaders.d.ts → context/context-loaders.d.ts} +0 -0
- /package/dist/internal/runtime/{context-mdc-parser.d.ts → context/context-mdc-parser.d.ts} +0 -0
- /package/dist/internal/runtime/{fixture-responder.d.ts → fixtures/fixture-responder.d.ts} +0 -0
- /package/dist/internal/runtime/{fixture-types.d.ts → fixtures/fixture-types.d.ts} +0 -0
- /package/dist/internal/runtime/{plugins-manager.d.ts → local-agent-send.d.ts} +0 -0
- /package/dist/internal/runtime/{plugin-frontmatter.d.ts → plugins/plugin-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{system-prompt/providers/active-memory-provider.d.ts → plugins/plugins-manager.d.ts} +0 -0
- /package/dist/internal/runtime/{agent-factory-registry.d.ts → registry/agent-factory-registry.d.ts} +0 -0
- /package/dist/internal/runtime/{agent-registry-store.d.ts → registry/agent-registry-store.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/base-provider.d.ts → sources/active-memory-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/context-provider.d.ts → sources/base-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/memory-provider.d.ts → sources/context-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/skills-provider.d.ts → sources/memory-provider.d.ts} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin contract types (T1.1, ADRs D97-D101).
|
|
3
|
+
*
|
|
4
|
+
* Discriminated union by `kind`:
|
|
5
|
+
* - `"general"` — registers tools/hooks/commands via `register(ctx)`.
|
|
6
|
+
* - `"model-provider"` — declares a `ProviderProfile` consumed by router.
|
|
7
|
+
* - `"memory"` — supplies a memory provider factory.
|
|
8
|
+
*
|
|
9
|
+
* Hooks are a fixed enum (D100) to prevent sprawl; `pre_tool_call` supports
|
|
10
|
+
* veto via `{ block: true, message }` (D101) so plugins can implement safety
|
|
11
|
+
* guards without crashing the agent loop.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
import type { CustomTool } from "../../types/agent.js";
|
|
16
|
+
import type { ProviderProfile } from "../providers/types.js";
|
|
17
|
+
export type HookName = "pre_tool_call" | "post_tool_call" | "pre_llm_call" | "post_llm_call" | "on_session_start" | "on_session_end" | "transform_tool_result" | "transform_llm_output" | "pre_user_send" | "post_assistant_reply";
|
|
18
|
+
export interface PreToolCallContext {
|
|
19
|
+
name: string;
|
|
20
|
+
args: Record<string, unknown>;
|
|
21
|
+
agentId: string;
|
|
22
|
+
runId: string;
|
|
23
|
+
}
|
|
24
|
+
export interface PreToolCallDecision {
|
|
25
|
+
block: true;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Context passed to `pre_user_send` hook handlers (ADR D145).
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface PreUserSendContext {
|
|
34
|
+
prompt: string;
|
|
35
|
+
agentId: string;
|
|
36
|
+
runId: string;
|
|
37
|
+
/** Caller-supplied memory context, flowing through from `AgentOptions.memoryContext`. */
|
|
38
|
+
memoryContext?: import("../../types/memory-adapter.js").MemoryContext;
|
|
39
|
+
/** Forwarded `AbortSignal` so adapter recall HTTP can be cancelled mid-flight (EC-H). */
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Optional result returned by `pre_user_send` handlers. The agent loop
|
|
44
|
+
* concatenates `recalledContext` from all handlers and injects it as a
|
|
45
|
+
* `<memory-context>...</memory-context>` block before the user prompt.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface PreUserSendResult {
|
|
50
|
+
recalledContext?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Context passed to `post_assistant_reply` hook handlers (ADR D145).
|
|
54
|
+
* Fire-and-forget — exceptions are caught and surfaced to stderr; the
|
|
55
|
+
* caller's `wait()` never blocks on this dispatch.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export interface PostAssistantReplyContext {
|
|
60
|
+
prompt: string;
|
|
61
|
+
reply: string;
|
|
62
|
+
agentId: string;
|
|
63
|
+
runId: string;
|
|
64
|
+
memoryContext?: import("../../types/memory-adapter.js").MemoryContext;
|
|
65
|
+
}
|
|
66
|
+
export type HookHandler = (ctx: unknown) => unknown | Promise<unknown>;
|
|
67
|
+
export type CommandHandler = (args: Record<string, unknown>) => Promise<string> | string;
|
|
68
|
+
export interface CommandOptions {
|
|
69
|
+
description?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface PluginContext {
|
|
72
|
+
/** Register a custom tool. Equivalent to passing in `AgentOptions.tools`. */
|
|
73
|
+
registerTool(tool: CustomTool): void;
|
|
74
|
+
/** Register a slash-command-style handler. Consumed by CLI/bot wrappers; NOT used by the agent loop. */
|
|
75
|
+
registerCommand(name: string, handler: CommandHandler, opts?: CommandOptions): void;
|
|
76
|
+
/** Attach a hook handler. `pre_tool_call` supports veto via `PreToolCallDecision`. */
|
|
77
|
+
on(hook: HookName, handler: HookHandler): void;
|
|
78
|
+
/** Inject a user/system message into the next agent turn. v1 supports only `on_session_start` context. */
|
|
79
|
+
injectMessage(content: string, role?: "user" | "system"): void;
|
|
80
|
+
}
|
|
81
|
+
interface BasePlugin {
|
|
82
|
+
name: string;
|
|
83
|
+
version: string;
|
|
84
|
+
}
|
|
85
|
+
export type Plugin = (BasePlugin & {
|
|
86
|
+
kind: "general";
|
|
87
|
+
register: (ctx: PluginContext) => void | Promise<void>;
|
|
88
|
+
}) | (BasePlugin & {
|
|
89
|
+
kind: "model-provider";
|
|
90
|
+
profile: ProviderProfile;
|
|
91
|
+
}) | (BasePlugin & {
|
|
92
|
+
kind: "memory";
|
|
93
|
+
createProvider: MemoryProviderFactory;
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Identity helper for plugin authors. TS-only convenience — preserves
|
|
97
|
+
* inferred type without forcing manual `Plugin` annotation.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
export declare function definePlugin<P extends Plugin>(p: P): P;
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic provider catalog loader (T10.1, ADR D447).
|
|
3
|
+
*
|
|
4
|
+
* Loads provider metadata from `provider-catalog.json` at runtime.
|
|
5
|
+
* Malformed entries are skipped with WARN (EC-1) — never crash.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import type { ApiMode, AuthType } from "./types.js";
|
|
10
|
+
export interface ProviderCapabilities {
|
|
11
|
+
supportsToolUse: boolean;
|
|
12
|
+
supportsVision: boolean;
|
|
13
|
+
supportsStructuredOutput: boolean;
|
|
14
|
+
supportsStreaming: boolean;
|
|
15
|
+
supportsCacheControl: boolean;
|
|
16
|
+
maxContextTokens?: number;
|
|
17
|
+
maxOutputTokens?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface CatalogEntry {
|
|
20
|
+
id: string;
|
|
21
|
+
displayName: string;
|
|
22
|
+
apiMode: ApiMode;
|
|
23
|
+
authType: AuthType;
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
envVars: string[];
|
|
26
|
+
fallbackModels: string[];
|
|
27
|
+
capabilities: ProviderCapabilities;
|
|
28
|
+
aliases?: string[];
|
|
29
|
+
modelsUrl?: string;
|
|
30
|
+
hostname?: string;
|
|
31
|
+
extraHeaders?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
interface LoadOptions {
|
|
34
|
+
_testInjectMalformed?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare function loadProviderCatalog(opts?: LoadOptions): Record<string, CatalogEntry>;
|
|
37
|
+
export declare function getCatalogCapabilities(providerId: string): ProviderCapabilities | undefined;
|
|
38
|
+
export declare function registerCatalogProviders(opts?: LoadOptions): void;
|
|
39
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { SessionMessage } from "./
|
|
1
|
+
import type { SessionMessage } from "./session-types.js";
|
|
2
2
|
export declare function sessionFilePath(cwd: string, agentId: string): string;
|
|
3
3
|
export declare function readSessionFile(cwd: string, agentId: string): Promise<SessionMessage[]>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `BudgetTracker` — runtime contract for budget/usage tracking in the
|
|
3
|
+
* agent loop (SDK 2.0 Phase 2 / T2.1 — ADR D1 interface inversion).
|
|
4
|
+
*
|
|
5
|
+
* This interface is the FOUNDATION for the eventual extraction of the
|
|
6
|
+
* Budget subsystem to `@theokit/sdk-budget`. The kernel depends on this
|
|
7
|
+
* contract (not on `UsageAccumulator` / `IterationBudget` concrete classes)
|
|
8
|
+
* so the implementation can move to a separate package without circular
|
|
9
|
+
* imports.
|
|
10
|
+
*
|
|
11
|
+
* Until Phase 2 completes, the legacy `UsageAccumulator` + `IterationBudget`
|
|
12
|
+
* remain wired in `internal/agent-loop/loop.ts` as the default impl. Future
|
|
13
|
+
* iterations:
|
|
14
|
+
* - Refactor `Agent.create` to accept `budgetTracker?: BudgetTracker`.
|
|
15
|
+
* - When provided, agent-loop uses it; when absent, falls back to the
|
|
16
|
+
* internal default for back-compat.
|
|
17
|
+
* - Move the default impl to `@theokit/sdk-budget` (extracted package).
|
|
18
|
+
* - Phase 6 cohort: drop the internal default, require explicit tracker.
|
|
19
|
+
*
|
|
20
|
+
* @public — surface-level interface; impl is internal-but-replaceable.
|
|
21
|
+
*/
|
|
22
|
+
/** Single usage event recorded during one LLM call. */
|
|
23
|
+
export interface BudgetUsageEvent {
|
|
24
|
+
/** Token count for this event. */
|
|
25
|
+
readonly tokens: number;
|
|
26
|
+
/** Provider/model identifier (e.g., `"openai/gpt-4o-mini"`). */
|
|
27
|
+
readonly model: string;
|
|
28
|
+
/** Whether this is an input (prompt) or output (completion) measurement. */
|
|
29
|
+
readonly type: "input" | "output";
|
|
30
|
+
/** Optional ISO 8601 timestamp; defaults to now() if omitted. */
|
|
31
|
+
readonly at?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Decision the tracker returns on each iteration / pre-flight check. */
|
|
34
|
+
export interface BudgetCheck {
|
|
35
|
+
/** Whether the agent loop is allowed to proceed. */
|
|
36
|
+
readonly allowed: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* When `allowed` is false, names the reason in a stable, codemod-friendly
|
|
39
|
+
* form. Consumers map this to retry / surface to user / abort behavior.
|
|
40
|
+
*/
|
|
41
|
+
readonly reason?: "budget_exceeded" | "iteration_limit" | "cost_limit" | "token_limit" | "custom";
|
|
42
|
+
/** Free-form details for logs / diagnostics. */
|
|
43
|
+
readonly detail?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Aggregate snapshot of usage so far. */
|
|
46
|
+
export interface BudgetTotal {
|
|
47
|
+
/** Sum of all input + output tokens. */
|
|
48
|
+
readonly tokens: number;
|
|
49
|
+
/** USD cost when pricing data is available; `undefined` otherwise. */
|
|
50
|
+
readonly costUsd?: number;
|
|
51
|
+
/** Iteration count if the impl tracks it. */
|
|
52
|
+
readonly iterations?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The kernel-facing contract. Implementations live OUTSIDE the agent loop
|
|
56
|
+
* (in `@theokit/sdk-budget` after Phase 2 / in `internal/budget/` until then).
|
|
57
|
+
*
|
|
58
|
+
* Implementations MUST be:
|
|
59
|
+
* - **Synchronous** — every method returns a value, never a Promise.
|
|
60
|
+
* `track()` is on the hot path (called on every iteration); async would
|
|
61
|
+
* bloat the loop with floating promises and force every call site to
|
|
62
|
+
* await.
|
|
63
|
+
* - **Non-throwing in track()** — record-only semantics. Validation
|
|
64
|
+
* failures bubble up via `check()` instead.
|
|
65
|
+
*/
|
|
66
|
+
export interface BudgetTracker {
|
|
67
|
+
/** Record a single usage event. MUST be synchronous and non-throwing. */
|
|
68
|
+
track(event: BudgetUsageEvent): void;
|
|
69
|
+
/** Pre-flight check before the next iteration. */
|
|
70
|
+
check(): BudgetCheck;
|
|
71
|
+
/** Snapshot of accumulated totals (for telemetry / final reporting). */
|
|
72
|
+
getTotal(): BudgetTotal;
|
|
73
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextSettings, ContextSnapshot, SDKContextManager } from "
|
|
1
|
+
import type { ContextSettings, ContextSnapshot, SDKContextManager } from "../../../types/context.js";
|
|
2
2
|
export declare class FileContextManager implements SDKContextManager {
|
|
3
3
|
private readonly cwd;
|
|
4
4
|
private readonly settings;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SDKAssistantMessage, SDKRequestMessage, SDKStatusMessage, SDKSystemMessage, SDKTaskMessage, SDKThinkingMessage, SDKToolUseMessage, SDKUserMessageEvent } from "
|
|
1
|
+
import type { SDKAssistantMessage, SDKRequestMessage, SDKStatusMessage, SDKSystemMessage, SDKTaskMessage, SDKThinkingMessage, SDKToolUseMessage, SDKUserMessageEvent } from "../../../types/messages.js";
|
|
2
2
|
import type { FixtureRequest } from "./fixture-types.js";
|
|
3
3
|
export declare function systemEvent(request: FixtureRequest, tools: string[]): SDKSystemMessage;
|
|
4
4
|
export declare function userEvent(request: FixtureRequest): SDKUserMessageEvent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ModelSelection } from "
|
|
2
|
-
import type { ConversationTurn } from "
|
|
3
|
-
import type { SDKMessage } from "
|
|
4
|
-
import type { Run, RunOperation, RunResult, RunStatus } from "
|
|
1
|
+
import type { ModelSelection } from "../../../types/agent.js";
|
|
2
|
+
import type { ConversationTurn } from "../../../types/conversation.js";
|
|
3
|
+
import type { SDKMessage } from "../../../types/messages.js";
|
|
4
|
+
import type { Run, RunOperation, RunResult, RunStatus } from "../../../types/run.js";
|
|
5
5
|
import type { FixtureScript } from "./fixture-types.js";
|
|
6
6
|
export declare abstract class FixtureRunBase implements Run {
|
|
7
7
|
readonly id: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FixtureRequest, FixtureScript } from "./fixture-types.js";
|
|
2
|
-
export { extractMemoryFact, isMemoryWritePrompt } from "
|
|
2
|
+
export { extractMemoryFact, isMemoryWritePrompt } from "../memory-store.js";
|
|
3
3
|
export declare function isMemoryRecallPrompt(message: string, request: FixtureRequest): boolean;
|
|
4
4
|
export declare function memoryWriteScript(request: FixtureRequest): FixtureScript;
|
|
5
5
|
export declare function memoryRecallScript(request: FixtureRequest): FixtureScript;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
import { FileContextManager } from "./context-manager.js";
|
|
11
|
-
import { type PluginMetadata, PluginsManager } from "./plugins-manager.js";
|
|
10
|
+
import { FileContextManager } from "./context/context-manager.js";
|
|
11
|
+
import { type PluginMetadata, PluginsManager } from "./plugins/plugins-manager.js";
|
|
12
12
|
import { ProvidersManagerImpl } from "./providers-manager.js";
|
|
13
13
|
import { type SkillMetadata, SkillsManager } from "./skills-manager.js";
|
|
14
14
|
export declare function registerLocalAgent(args: {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createLocalAgentMemoryProvider` — bridges the legacy LocalAgentMemory
|
|
3
|
+
* rich impl (sdk-core's internal/memory/* subsystem) to the
|
|
4
|
+
* MemoryProvider port (SDK 2.0 Phase 1 physical Stage 2a — iter 19+).
|
|
5
|
+
*
|
|
6
|
+
* Goal: ONE memory path inside the kernel. Today there are TWO:
|
|
7
|
+
* 1. Legacy via `LocalAgentMemory` (when consumer didn't pass memoryProvider)
|
|
8
|
+
* 2. Port via `MemoryProvider` (when consumer passed memoryProvider in T1.3)
|
|
9
|
+
*
|
|
10
|
+
* This adapter wraps path 1 as a MemoryProvider, so the kernel can use
|
|
11
|
+
* the port uniformly. Stage 2b will refactor LocalAgent.send() to use
|
|
12
|
+
* the port + this adapter as default. Stage 3 will move the internal/
|
|
13
|
+
* memory/* sources to sdk-memory + ship a richer LanceDB-backed
|
|
14
|
+
* provider replacing this adapter.
|
|
15
|
+
*
|
|
16
|
+
* Why a separate file (not modifying LocalAgentMemory):
|
|
17
|
+
* - Preserves LocalAgentMemory's existing public API for callers that
|
|
18
|
+
* haven't migrated to the port yet.
|
|
19
|
+
* - Adapter pattern: the rich logic stays where it is; the adapter
|
|
20
|
+
* translates between LocalAgentMemory's signature and the port's.
|
|
21
|
+
* - Allows incremental migration: kernel call sites move one at a
|
|
22
|
+
* time from `memoryGlue.X()` direct calls to `provider.X(handle)`
|
|
23
|
+
* calls.
|
|
24
|
+
*
|
|
25
|
+
* @internal — sdk-core's bridging glue. Replaced by sdk-memory rich impl
|
|
26
|
+
* in Stage 3.
|
|
27
|
+
*/
|
|
28
|
+
import type { TelemetryHandle } from "../telemetry/tracer.js";
|
|
29
|
+
import type { MemoryProvider } from "./memory-provider.js";
|
|
30
|
+
/**
|
|
31
|
+
* Options for `createLocalAgentMemoryProvider`. Mirrors what
|
|
32
|
+
* `LocalAgentMemory`'s constructor needs.
|
|
33
|
+
*/
|
|
34
|
+
export interface LocalAgentMemoryProviderOptions {
|
|
35
|
+
/** AgentOptions slice — required for memory subsystem config (cfg.memory). */
|
|
36
|
+
readonly agentOptions: AgentOptions;
|
|
37
|
+
/** Workspace cwd — used for `.theokit/memory/` paths. */
|
|
38
|
+
readonly workspaceCwd: string;
|
|
39
|
+
/** Agent id — required for per-agent cache + telemetry. */
|
|
40
|
+
readonly agentId: string;
|
|
41
|
+
/** Telemetry handle (optional) — forwarded to active-memory recall. */
|
|
42
|
+
readonly telemetry?: TelemetryHandle;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build a `MemoryProvider` whose lifecycle methods delegate to an
|
|
46
|
+
* underlying `LocalAgentMemory` instance.
|
|
47
|
+
*
|
|
48
|
+
* Mapping:
|
|
49
|
+
* - `init()` → constructs LocalAgentMemory + warms tool cache via ensureTools()
|
|
50
|
+
* - `buildTools()` → wraps ensureTools() result, renaming `execute` to `handler`
|
|
51
|
+
* - `runActivePass()` → calls runActiveMemoryIfEnabled() with synthesized args;
|
|
52
|
+
* returns the summary as `systemPromptAdditions`
|
|
53
|
+
* - `sync()` → calls syncIfReady()
|
|
54
|
+
* - `dispose()` → no-op (LocalAgentMemory's caches are per-agent + GC'd
|
|
55
|
+
* when the agent is GC'd)
|
|
56
|
+
*/
|
|
57
|
+
export declare function createLocalAgentMemoryProvider(opts: LocalAgentMemoryProviderOptions): MemoryProvider;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory path selector (SDK 2.0 Phase 1 physical Stage 2b — iter 22).
|
|
3
|
+
*
|
|
4
|
+
* Pure helpers the future kernel flip will use to choose between
|
|
5
|
+
* legacy direct-call path and new MemoryProvider port path. Shipped
|
|
6
|
+
* in isolation so the helpers are tested + frozen BEFORE the actual
|
|
7
|
+
* `LocalAgent.send()` refactor wires them.
|
|
8
|
+
*
|
|
9
|
+
* Gate semantics (option A from the progress doc):
|
|
10
|
+
* - Default: legacy path (zero behavior change).
|
|
11
|
+
* - `THEOKIT_PORT_MEMORY_PATH=1` (env var): port path active.
|
|
12
|
+
*
|
|
13
|
+
* Why env var (vs option flag):
|
|
14
|
+
* - Easy to flip on/off at runtime without rebuild.
|
|
15
|
+
* - No public API surface added (the env var is internal-only;
|
|
16
|
+
* consumers don't see it in their TypeScript types).
|
|
17
|
+
* - Future iter can remove the env var once port path is the
|
|
18
|
+
* unconditional default — no deprecation cycle on the public API.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
import type { MemoryToolSpec } from "../agent-loop/loop-types.js";
|
|
23
|
+
import type { MemoryProvider } from "./memory-provider.js";
|
|
24
|
+
/** Env var name — internal, not in public docs yet. */
|
|
25
|
+
export declare const PORT_MEMORY_PATH_ENV_VAR = "THEOKIT_PORT_MEMORY_PATH";
|
|
26
|
+
/**
|
|
27
|
+
* Returns true when the port-memory-path should be active for this send.
|
|
28
|
+
*
|
|
29
|
+
* Checks both `process.env` (Node) and `globalThis.process?.env`
|
|
30
|
+
* (defensive — some test environments stub process differently).
|
|
31
|
+
*/
|
|
32
|
+
export declare function shouldUsePortMemoryPath(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Pick which `MemoryProvider` (if any) gets passed to the agent loop.
|
|
35
|
+
*
|
|
36
|
+
* Semantics:
|
|
37
|
+
* - When consumer-supplied `options.memoryProvider` is set: ALWAYS
|
|
38
|
+
* honor it (regardless of env flag). The flag only affects the
|
|
39
|
+
* fall-back default.
|
|
40
|
+
* - When consumer didn't supply AND port path enabled: return the
|
|
41
|
+
* auto-installed `defaultMemoryProviderForLoop` (the adapter).
|
|
42
|
+
* - When consumer didn't supply AND port path disabled: return
|
|
43
|
+
* `undefined` (legacy path; agent-loop sees no provider).
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveMemoryProviderForLoop(consumerSupplied: MemoryProvider | undefined, defaultAdapter: MemoryProvider, portPathEnabled: boolean): MemoryProvider | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Pick which `memoryTools` (if any) get passed to the agent loop's
|
|
48
|
+
* `inputs.memoryTools` field.
|
|
49
|
+
*
|
|
50
|
+
* Semantics:
|
|
51
|
+
* - When port path active: return `undefined` (tools surface via
|
|
52
|
+
* `provider.buildTools()` inside agent-loop instead — iter 18 T1.5.2).
|
|
53
|
+
* - When port path inactive: return the legacy tools (from
|
|
54
|
+
* `memoryGlue.ensureTools()`).
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveMemoryToolsForLoop(legacyTools: ReadonlyArray<MemoryToolSpec> | undefined, portPathEnabled: boolean): ReadonlyArray<MemoryToolSpec> | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Pick the `activeMemorySummary` value to fold into the system-prompt
|
|
59
|
+
* assembly.
|
|
60
|
+
*
|
|
61
|
+
* Semantics:
|
|
62
|
+
* - When port path active: return `undefined` (additions surface via
|
|
63
|
+
* `provider.runActivePass()` inside agent-loop instead — iter 18 T1.5.3).
|
|
64
|
+
* - When port path inactive: return the legacy summary (from
|
|
65
|
+
* `memoryGlue.runActiveMemoryIfEnabled(...)`).
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveActiveMemorySummaryForSend(legacySummary: string | undefined, portPathEnabled: boolean): string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Type-only re-export for downstream consumers of the helpers.
|
|
70
|
+
* `CustomTool` is the port's tool shape; future iter may need it
|
|
71
|
+
* when assembling memoryTools via the port path.
|
|
72
|
+
*/
|
|
73
|
+
export type { CustomTool };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `MemoryProvider` — kernel-facing port for the memory subsystem
|
|
3
|
+
* (SDK 2.0 Phase 1 / T1.1 — Hexagonal Architecture / Ports & Adapters,
|
|
4
|
+
* SOLID Dependency Inversion).
|
|
5
|
+
*
|
|
6
|
+
* The agent loop kernel depends on THIS CONTRACT — not on the concrete
|
|
7
|
+
* `internal/memory/*` modules. Default adapter ships with `@theokit/sdk`
|
|
8
|
+
* (no-op for back-compat); rich impl ships in `@theokit/sdk-memory`.
|
|
9
|
+
* Consumers opt-in via `Agent.create({ memoryProvider: ... })` (wiring
|
|
10
|
+
* lands in subsequent iteration).
|
|
11
|
+
*
|
|
12
|
+
* Design rationale (ADR-001 + ADR-003 in
|
|
13
|
+
* `sdk-2-0-phase-1-2-adr.md`):
|
|
14
|
+
* - Memory subsystem is deeply integrated with the agent loop (active
|
|
15
|
+
* memory pass, LLM tool injection, lifecycle ownership) — cannot
|
|
16
|
+
* extract via plugin-protocol alone like Cache / Handoff.
|
|
17
|
+
* - Interface inversion is the canonical FAANG-style answer: the kernel
|
|
18
|
+
* defines what it NEEDS; impls satisfy the contract; package boundary
|
|
19
|
+
* is the seam.
|
|
20
|
+
* - Mirrors the `BudgetTracker` interface inversion (iter 10-16): same
|
|
21
|
+
* pattern, different subsystem.
|
|
22
|
+
*
|
|
23
|
+
* Layered model (mirrors Budget):
|
|
24
|
+
* - `MemoryAdapter` (existing in `types/memory-adapter.ts`) — LOW-LEVEL
|
|
25
|
+
* data port: write / recall / delete primitives.
|
|
26
|
+
* - `MemoryProvider` (THIS FILE) — HIGH-LEVEL lifecycle port: init,
|
|
27
|
+
* tool factories, active memory pass, embedding runtime selection.
|
|
28
|
+
*
|
|
29
|
+
* @public — surface-level interface; impls are internal-but-replaceable.
|
|
30
|
+
*/
|
|
31
|
+
import type { CustomTool, SDKAgent } from "../../types/agent.js";
|
|
32
|
+
import type { MemoryAdapter, MemoryFact } from "../../types/memory-adapter.js";
|
|
33
|
+
/** Result of `MemoryProvider.runActivePass(...)` — what the kernel injects into the LLM call. */
|
|
34
|
+
export interface ActiveMemoryPassResult {
|
|
35
|
+
/** Compressed memory facts to seed the LLM's context window for this turn. */
|
|
36
|
+
readonly facts: ReadonlyArray<MemoryFact>;
|
|
37
|
+
/** Optional system-prompt enrichment derived from the recalled facts. */
|
|
38
|
+
readonly systemPromptAdditions?: string;
|
|
39
|
+
/** Whether the active-memory circuit breaker tripped (degraded mode). */
|
|
40
|
+
readonly breakerTripped?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Arguments for `MemoryProvider.runActivePass(...)`. */
|
|
43
|
+
export interface ActiveMemoryPassArgs {
|
|
44
|
+
/** The current user message — used as the recall query. */
|
|
45
|
+
readonly userMessage: string;
|
|
46
|
+
/** Conversation history (most recent first). */
|
|
47
|
+
readonly history: ReadonlyArray<{
|
|
48
|
+
role: "user" | "assistant";
|
|
49
|
+
content: string;
|
|
50
|
+
}>;
|
|
51
|
+
/** Agent identity for scope. */
|
|
52
|
+
readonly agentId: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Arguments for `MemoryProvider.recordSessionSummary(...)`
|
|
56
|
+
* (SDK 2.0 Phase 1 physical Stage 3 prep — iter 27).
|
|
57
|
+
*
|
|
58
|
+
* The "session summary" is the markdown that gets written to disk
|
|
59
|
+
* after a finished run + indexed under `corpus="sessions"`. This
|
|
60
|
+
* port method lets sdk-core's `post-run-lifecycle.ts` delegate the
|
|
61
|
+
* write to the provider instead of importing
|
|
62
|
+
* `internal/memory/storage/session-summary-writer.ts` directly.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export interface RecordSessionSummaryArgs {
|
|
67
|
+
/**
|
|
68
|
+
* Workspace cwd where on-disk artefacts live. Included on the args
|
|
69
|
+
* (not on a handle) because `recordSessionSummary` is STATELESS — it
|
|
70
|
+
* runs AFTER `runAgentLoop`'s `dispose()` releases the per-run handle.
|
|
71
|
+
* The kernel passes its own `workspaceCwd`; the impl uses it to
|
|
72
|
+
* compute the markdown file path.
|
|
73
|
+
*/
|
|
74
|
+
readonly cwd: string;
|
|
75
|
+
/** Run id used as the filename key. */
|
|
76
|
+
readonly runId: string;
|
|
77
|
+
/** Agent identity for scope (foldering). */
|
|
78
|
+
readonly agentId: string;
|
|
79
|
+
/** Verbatim user message that started the run. */
|
|
80
|
+
readonly userText: string;
|
|
81
|
+
/** Final assistant text the run produced. */
|
|
82
|
+
readonly assistantText: string;
|
|
83
|
+
/** Final run status (only "finished" is recorded today). */
|
|
84
|
+
readonly status: "finished" | "error" | "cancelled";
|
|
85
|
+
/** Wall-clock ms at write time. */
|
|
86
|
+
readonly at: number;
|
|
87
|
+
}
|
|
88
|
+
/** Options for `MemoryProvider.init(...)`. */
|
|
89
|
+
export interface MemoryProviderInitOptions {
|
|
90
|
+
/** Workspace cwd where on-disk artefacts live (`.theokit/memory/...`). */
|
|
91
|
+
readonly cwd: string;
|
|
92
|
+
/** Embedding-provider id (`"openai" | "ollama" | ...`); when omitted the impl picks a default. */
|
|
93
|
+
readonly embeddingProviderId?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Opaque handle returned by `init()`. Carried back into other methods so
|
|
97
|
+
* the impl can stash per-agent state (index, breaker, cache, …) without
|
|
98
|
+
* exposing it to the kernel.
|
|
99
|
+
*/
|
|
100
|
+
export interface MemoryProviderHandle {
|
|
101
|
+
/** Adapter interface for direct read/write — matches existing `MemoryAdapter` shape. */
|
|
102
|
+
readonly adapter: MemoryAdapter;
|
|
103
|
+
/** Implementation-defined opaque field (private state pointer / index handle). */
|
|
104
|
+
readonly [implState: symbol]: unknown;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The kernel-facing contract. Implementations live OUTSIDE the agent loop
|
|
108
|
+
* (in `@theokit/sdk-memory` after Phase 1; in `internal/memory/` until then).
|
|
109
|
+
*
|
|
110
|
+
* Implementations MUST be:
|
|
111
|
+
* - **Lazy** — `init()` may be called once per agent; subsequent calls
|
|
112
|
+
* return the same handle (impl decides via cache). Heavy work
|
|
113
|
+
* (loading the index, opening SQLite) deferred until first use.
|
|
114
|
+
* - **Non-throwing on the hot path** — `runActivePass()` returns an
|
|
115
|
+
* empty `facts: []` on degradation rather than throwing. Errors
|
|
116
|
+
* surface via the breakerTripped flag + telemetry.
|
|
117
|
+
*/
|
|
118
|
+
export interface MemoryProvider {
|
|
119
|
+
/** Construct or fetch the per-agent handle. Lazy + idempotent. */
|
|
120
|
+
init(opts: MemoryProviderInitOptions): Promise<MemoryProviderHandle>;
|
|
121
|
+
/** Build the LLM-facing tool catalog (memory_search, memory_get, …). */
|
|
122
|
+
buildTools(handle: MemoryProviderHandle, agent: SDKAgent): ReadonlyArray<CustomTool>;
|
|
123
|
+
/** Run the active-memory pre-LLM pass — recall + compress + format. */
|
|
124
|
+
runActivePass(handle: MemoryProviderHandle, args: ActiveMemoryPassArgs): Promise<ActiveMemoryPassResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Optional post-run hook (SDK 2.0 Phase 1 physical Stage 1 — iter 19).
|
|
127
|
+
* Called by the agent loop AFTER a successful send so the impl can
|
|
128
|
+
* incorporate the session summary into its index (e.g., re-index the
|
|
129
|
+
* `sessions` corpus so the next recall sees it).
|
|
130
|
+
*
|
|
131
|
+
* Fire-and-forget at the call site; impl MUST be idempotent +
|
|
132
|
+
* non-throwing. Optional so existing impls (createNoopMemoryProvider,
|
|
133
|
+
* sdk-memory@0.1.0) keep working without modification.
|
|
134
|
+
*
|
|
135
|
+
* Mirrors the role of `LocalAgentMemory.syncIfReady()` in sdk-core's
|
|
136
|
+
* legacy memory path — exposing it via the port is the seam that
|
|
137
|
+
* unblocks moving LocalAgentMemory's logic out to sdk-memory.
|
|
138
|
+
*/
|
|
139
|
+
sync?(handle: MemoryProviderHandle): Promise<void> | void;
|
|
140
|
+
/**
|
|
141
|
+
* Optional session-summary write hook (SDK 2.0 Phase 1 physical
|
|
142
|
+
* Stage 3 prep — iter 27, refined iter 28).
|
|
143
|
+
*
|
|
144
|
+
* Called by `post-run-lifecycle.ts` AFTER a finished run to persist
|
|
145
|
+
* the run's session-summary markdown under `corpus="sessions"`. When
|
|
146
|
+
* defined, the kernel delegates the write to the provider; when
|
|
147
|
+
* undefined, post-run-lifecycle falls back to the direct
|
|
148
|
+
* `writeSessionSummary` import (legacy path, until Stage 3 source
|
|
149
|
+
* move drops that import entirely).
|
|
150
|
+
*
|
|
151
|
+
* STATELESS — does NOT take a `MemoryProviderHandle` because post-run-
|
|
152
|
+
* lifecycle runs AFTER `runAgentLoop` disposed the per-run handle.
|
|
153
|
+
* `cwd` lives on `args` instead. Impls that need per-agent state can
|
|
154
|
+
* cache it via closure inside the provider factory.
|
|
155
|
+
*
|
|
156
|
+
* Impl MUST be non-throwing on the hot path. The kernel swallows
|
|
157
|
+
* any throw + emits a stderr warning.
|
|
158
|
+
*
|
|
159
|
+
* Optional so existing impls (createNoopMemoryProvider,
|
|
160
|
+
* createInMemoryMarkdownProvider) keep working without modification.
|
|
161
|
+
*/
|
|
162
|
+
recordSessionSummary?(args: RecordSessionSummaryArgs): Promise<void> | void;
|
|
163
|
+
/** Release the handle (close index, flush caches). Idempotent + non-throwing. */
|
|
164
|
+
dispose(handle: MemoryProviderHandle): Promise<void> | void;
|
|
165
|
+
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Whether an agent runs in the local or cloud runtime. Drives storage routing,
|
|
3
|
+
* fork semantics, and the cross-runtime UnsupportedRunOperationError contract
|
|
4
|
+
* (ADR D122).
|
|
5
|
+
*/
|
|
6
|
+
export type AgentRuntime = "local" | "cloud";
|
|
7
|
+
/**
|
|
8
|
+
* In-memory agent registry record. Persisted via the
|
|
9
|
+
* `agent-registry-store.ts` serialization layer (which strips secrets per
|
|
10
|
+
* ADR D17 + D68 — see `stripSecretsFromOptions`).
|
|
11
|
+
*/
|
|
2
12
|
export interface RegisteredAgent {
|
|
3
13
|
agentId: string;
|
|
4
14
|
runtime: AgentRuntime;
|
|
@@ -9,8 +19,10 @@ export interface RegisteredAgent {
|
|
|
9
19
|
lastModified: number;
|
|
10
20
|
archived: boolean;
|
|
11
21
|
options: AgentOptions;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
22
|
+
/**
|
|
23
|
+
* Local workspace cwd; only set when runtime is local. Also used as the
|
|
24
|
+
* persistence routing key (cloud agents default to `process.cwd()`).
|
|
25
|
+
*/
|
|
14
26
|
cwd?: string;
|
|
15
27
|
/** Cloud repo URLs; only set when runtime is cloud. */
|
|
16
28
|
repos?: string[];
|
|
@@ -26,9 +38,3 @@ export interface RegisteredAgent {
|
|
|
26
38
|
*/
|
|
27
39
|
requiresCustomStorage?: boolean;
|
|
28
40
|
}
|
|
29
|
-
export declare function registerAgent(agent: RegisteredAgent): void;
|
|
30
|
-
export declare function getRegisteredAgent(agentId: string): RegisteredAgent | undefined;
|
|
31
|
-
export declare function listRegisteredAgents(runtime?: AgentRuntime): RegisteredAgent[];
|
|
32
|
-
export declare function updateRegisteredAgent(agentId: string, update: Partial<RegisteredAgent>): RegisteredAgent | undefined;
|
|
33
|
-
export declare function removeRegisteredAgent(agentId: string): boolean;
|
|
34
|
-
export declare function clearAgentRegistry(): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentRuntime, RegisteredAgent } from "./agent-registry-contract.js";
|
|
2
|
+
export declare function registerAgent(agent: RegisteredAgent): void;
|
|
3
|
+
export declare function getRegisteredAgent(agentId: string): RegisteredAgent | undefined;
|
|
4
|
+
export declare function listRegisteredAgents(runtime?: AgentRuntime): RegisteredAgent[];
|
|
5
|
+
export declare function updateRegisteredAgent(agentId: string, update: Partial<RegisteredAgent>): RegisteredAgent | undefined;
|
|
6
|
+
export declare function removeRegisteredAgent(agentId: string): boolean;
|
|
7
|
+
export declare function clearAgentRegistry(): void;
|
package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts}
RENAMED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @public (singleton exposed via `Agent.registry`)
|
|
19
19
|
*/
|
|
20
|
-
import type { SDKAgent } from "
|
|
20
|
+
import type { SDKAgent } from "../../../types/agent.js";
|
|
21
21
|
export type EvictReason = "lru" | "idle" | "explicit";
|
|
22
22
|
export interface AgentRegistryOptions {
|
|
23
23
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Run } from "
|
|
1
|
+
import type { Run } from "../../../types/run.js";
|
|
2
2
|
export declare function registerRun(run: Run): void;
|
|
3
3
|
export declare function getRun(runId: string): Run | undefined;
|
|
4
4
|
export declare function listRunsByAgent(agentId: string): Run[];
|