@theokit/sdk 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +187 -0
- package/dist/a2a/agent-mailbox.d.cts +27 -0
- package/dist/a2a/agent-mailbox.d.ts +27 -0
- package/dist/a2a/index.cjs +16850 -0
- package/dist/a2a/index.cjs.map +1 -0
- package/dist/a2a/index.d.cts +9 -0
- package/dist/a2a/index.d.ts +9 -0
- package/dist/a2a/index.js +16844 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/a2a/message-bus.d.cts +27 -0
- package/dist/a2a/message-bus.d.ts +27 -0
- package/dist/a2a/subagent.d.cts +25 -0
- package/dist/a2a/subagent.d.ts +25 -0
- package/dist/a2a/types.d.cts +12 -0
- package/dist/a2a/types.d.ts +12 -0
- package/dist/agent.d.ts +1 -1
- package/dist/client/index.cjs +73 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +7 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +71 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/theokit-client.d.cts +18 -0
- package/dist/client/theokit-client.d.ts +18 -0
- package/dist/client/types.d.cts +19 -0
- package/dist/client/types.d.ts +19 -0
- package/dist/{run-DkCD5DeO.d.cts → cron-BnywDYLq.d.cts} +496 -910
- package/dist/{run-DkCD5DeO.d.ts → cron-CtZvJD9J.d.ts} +496 -910
- package/dist/cron.cjs +4285 -2893
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -3
- package/dist/cron.d.ts +2 -71
- package/dist/cron.js +4289 -2897
- package/dist/cron.js.map +1 -1
- package/dist/{errors-CvAeEWgE.d.ts → errors-ChqOmFH1.d.cts} +52 -6
- package/dist/{errors-CK8brCJ1.d.cts → errors-DV9e0rcp.d.ts} +52 -6
- package/dist/errors.cjs +218 -3
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -3
- package/dist/errors.d.ts +50 -4
- package/dist/errors.js +217 -4
- package/dist/errors.js.map +1 -1
- package/dist/eval.cjs +4285 -2893
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +35 -0
- package/dist/eval.js +4289 -2897
- package/dist/eval.js.map +1 -1
- package/dist/event-bus.d.ts +23 -0
- package/dist/index.cjs +5132 -4200
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +298 -278
- package/dist/index.d.ts +1898 -24
- package/dist/index.js +6441 -5509
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-loop/loop-context-init.d.ts +2 -0
- package/dist/internal/agent-loop/tool-dispatch.d.ts +22 -1
- package/dist/internal/auth/api-key-validator.d.ts +46 -0
- package/dist/internal/llm/anthropic-shared.d.ts +8 -1
- package/dist/internal/llm/retry.d.ts +22 -0
- package/dist/internal/llm/types.d.ts +47 -1
- package/dist/internal/memory/active-memory-cache.d.ts +3 -3
- package/dist/internal/memory/active-memory-types.d.ts +8 -0
- package/dist/internal/memory/active-memory.d.ts +24 -20
- package/dist/internal/memory/adapters/azure-openai-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/cohere-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/gemini-embedding.d.ts +2 -0
- package/dist/internal/memory/adapters/jina-embedding.d.ts +2 -0
- package/dist/internal/memory/index-manager-contract.d.ts +26 -0
- package/dist/internal/memory/index-manager-dispatch.d.ts +1 -1
- package/dist/internal/memory/index-manager.d.ts +8 -26
- package/dist/internal/memory/{chunk-markdown.d.ts → storage/chunk-markdown.d.ts} +1 -1
- package/dist/internal/memory/{markdown-store.d.ts → storage/markdown-store.d.ts} +1 -1
- package/dist/internal/memory/{reader.d.ts → storage/reader.d.ts} +1 -1
- package/dist/internal/observability/context.d.cts +23 -0
- package/dist/internal/observability/context.d.ts +23 -0
- package/dist/internal/observability/index.cjs +38 -0
- package/dist/internal/observability/index.cjs.map +1 -0
- package/dist/internal/observability/index.d.cts +8 -0
- package/dist/internal/observability/index.d.ts +8 -0
- package/dist/internal/observability/index.js +33 -0
- package/dist/internal/observability/index.js.map +1 -0
- package/dist/internal/observability/tracer-loader.d.cts +20 -0
- package/dist/internal/persistence/conversation-storage-fs.d.cts +37 -0
- package/dist/internal/persistence/conversation-storage-memory.d.cts +24 -0
- package/dist/internal/persistence/credential-pool-store.d.cts +32 -0
- package/dist/internal/persistence/credential-pool-store.d.ts +32 -0
- package/dist/internal/persistence/cwd-mutex.d.cts +1 -0
- package/dist/internal/persistence/exclusive-create.d.cts +22 -0
- package/dist/internal/persistence/exclusive-create.d.ts +22 -0
- package/dist/internal/persistence/file-lock.d.cts +14 -0
- package/dist/internal/persistence/fts5-sanitize.d.cts +16 -0
- package/dist/internal/persistence/index.cjs +359 -0
- package/dist/internal/persistence/index.cjs.map +1 -0
- package/dist/internal/persistence/index.d.cts +20 -0
- package/dist/internal/persistence/index.d.ts +20 -0
- package/dist/internal/persistence/index.js +341 -0
- package/dist/internal/persistence/index.js.map +1 -0
- package/dist/internal/persistence/markdown-config-loader.d.cts +35 -0
- package/dist/internal/persistence/paths.d.cts +19 -0
- package/dist/internal/persistence/persistence-schema.d.cts +21 -0
- package/dist/internal/persistence/persistence-schema.d.ts +4 -0
- package/dist/internal/persistence/schema-version.d.cts +13 -0
- package/dist/internal/persistence/sqlite-cas.d.cts +25 -0
- package/dist/internal/persistence/sqlite-cas.d.ts +25 -0
- package/dist/internal/persistence/sqlite-wal.d.cts +10 -0
- package/dist/internal/plugins/context.d.cts +31 -0
- package/dist/internal/plugins/index.cjs +228 -0
- package/dist/internal/plugins/index.cjs.map +1 -0
- package/dist/internal/plugins/index.d.cts +8 -0
- package/dist/internal/plugins/index.d.ts +8 -0
- package/dist/internal/plugins/index.js +222 -0
- package/dist/internal/plugins/index.js.map +1 -0
- package/dist/internal/plugins/lifecycle.d.cts +14 -0
- package/dist/internal/plugins/lifecycle.d.ts +14 -0
- package/dist/internal/plugins/manager.d.cts +37 -0
- package/dist/internal/plugins/types.d.cts +102 -0
- package/dist/internal/providers/catalog-loader.d.ts +39 -0
- package/dist/internal/runtime/agent-session-store.d.ts +1 -1
- package/dist/internal/runtime/agent-session.d.ts +1 -0
- package/dist/internal/runtime/budget-tracker.d.ts +73 -0
- package/dist/internal/runtime/{context-manager.d.ts → context/context-manager.d.ts} +1 -1
- package/dist/internal/runtime/{fixture-events.d.ts → fixtures/fixture-events.d.ts} +1 -1
- package/dist/internal/runtime/{fixture-run-base.d.ts → fixtures/fixture-run-base.d.ts} +4 -4
- package/dist/internal/runtime/{fixture-scripts.d.ts → fixtures/fixture-scripts.d.ts} +1 -1
- package/dist/internal/runtime/local-agent-bootstrap.d.ts +2 -2
- package/dist/internal/runtime/local-agent-memory-provider.d.ts +57 -0
- package/dist/internal/runtime/memory-path-selector.d.ts +73 -0
- package/dist/internal/runtime/memory-provider.d.ts +165 -0
- package/dist/internal/runtime/{agent-registry.d.ts → registry/agent-registry-contract.d.ts} +15 -9
- package/dist/internal/runtime/registry/agent-registry.d.ts +7 -0
- package/dist/internal/runtime/{live-agent-registry.d.ts → registry/live-agent-registry.d.ts} +1 -1
- package/dist/internal/runtime/{run-registry.d.ts → registry/run-registry.d.ts} +1 -1
- package/dist/internal/runtime/session-types.d.ts +35 -0
- package/dist/internal/runtime/system-prompt/sources/skills-provider.d.ts +1 -0
- package/dist/internal/runtime/validate-response.d.ts +18 -0
- package/dist/internal/security/index.cjs +361 -0
- package/dist/internal/security/index.cjs.map +1 -0
- package/dist/internal/security/index.d.cts +11 -0
- package/dist/internal/security/index.js +350 -0
- package/dist/internal/security/index.js.map +1 -0
- package/dist/internal/security/path-guard.d.cts +59 -0
- package/dist/internal/security/path-guard.d.ts +3 -0
- package/dist/internal/security/redact.d.cts +21 -0
- package/dist/internal/security/secret-redactor.d.cts +1 -0
- package/dist/internal/security/secret-redactor.d.ts +1 -0
- package/dist/internal/security/test-reset.d.cts +10 -0
- package/dist/internal/security/test-reset.d.ts +10 -0
- package/dist/internal/telemetry/adapters/arize.d.ts +2 -0
- package/dist/internal/telemetry/adapters/braintrust.d.ts +2 -0
- package/dist/internal/telemetry/adapters/datadog.d.ts +2 -0
- package/dist/internal/telemetry/adapters/langsmith.d.ts +2 -0
- package/dist/internal/telemetry/span-names.d.ts +6 -0
- package/dist/internal/telemetry/tracer.d.ts +1 -0
- package/dist/internal/workflow/evented-executor.d.ts +42 -0
- package/dist/internal/workflow/scheduler.d.ts +23 -0
- package/dist/internal/zod/to-json-schema.d.ts +5 -15
- package/dist/job-queue.d.ts +28 -0
- package/dist/path-safety.cjs +67 -6
- package/dist/path-safety.cjs.map +1 -1
- package/dist/path-safety.d.cts +15 -0
- package/dist/path-safety.d.ts +1 -1
- package/dist/path-safety.js +67 -7
- package/dist/path-safety.js.map +1 -1
- package/dist/permission-engine.d.ts +21 -0
- package/dist/provider-catalog.json +702 -0
- package/dist/rag/index.cjs +136 -0
- package/dist/rag/index.cjs.map +1 -0
- package/dist/rag/index.d.cts +11 -0
- package/dist/rag/index.d.ts +11 -0
- package/dist/rag/index.js +129 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/reranker.d.cts +26 -0
- package/dist/rag/reranker.d.ts +26 -0
- package/dist/rag/retriever.d.cts +25 -0
- package/dist/rag/retriever.d.ts +25 -0
- package/dist/rag/text-splitter.d.cts +12 -0
- package/dist/rag/text-splitter.d.ts +12 -0
- package/dist/rag/types.d.cts +37 -0
- package/dist/rag/types.d.ts +37 -0
- package/dist/run-DrwUpFxZ.d.cts +823 -0
- package/dist/run-DrwUpFxZ.d.ts +823 -0
- package/dist/sandbox/index.cjs +133 -0
- package/dist/sandbox/index.cjs.map +1 -0
- package/dist/sandbox/index.d.cts +2 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/sandbox/index.js +128 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/local-sandbox.d.cts +17 -0
- package/dist/sandbox/local-sandbox.d.ts +17 -0
- package/dist/sandbox/types.d.cts +44 -0
- package/dist/sandbox/types.d.ts +44 -0
- package/dist/server/adapter/express.d.cts +9 -0
- package/dist/server/adapter/express.d.ts +9 -0
- package/dist/server/adapter/fastify.d.cts +9 -0
- package/dist/server/adapter/fastify.d.ts +9 -0
- package/dist/server/adapter/hono.d.cts +9 -0
- package/dist/server/adapter/hono.d.ts +9 -0
- package/dist/server/adapter/index.d.cts +8 -0
- package/dist/server/adapter/index.d.ts +8 -0
- package/dist/server/adapter/shared-handler.d.cts +9 -0
- package/dist/server/adapter/shared-handler.d.ts +9 -0
- package/dist/server/adapter/types.d.cts +33 -0
- package/dist/server/adapter/types.d.ts +33 -0
- package/dist/server/auth/errors.d.cts +53 -0
- package/dist/server/auth/errors.d.ts +53 -0
- package/dist/server/auth/index.cjs +48 -42
- package/dist/server/auth/index.cjs.map +1 -1
- package/dist/server/auth/index.d.cts +11 -172
- package/dist/server/auth/index.d.ts +11 -172
- package/dist/server/auth/index.js +49 -43
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/auth/oauth-transaction-store.d.cts +39 -0
- package/dist/server/auth/oauth-transaction-store.d.ts +39 -0
- package/dist/server/auth/orchestrator.d.cts +8 -0
- package/dist/server/auth/orchestrator.d.ts +8 -0
- package/dist/server/auth/types.d.cts +91 -0
- package/dist/server/auth/types.d.ts +91 -0
- package/dist/server/auth/validate-return-to.d.cts +17 -0
- package/dist/server/auth/validate-return-to.d.ts +17 -0
- package/dist/server/errors-envelope.cjs +409 -0
- package/dist/server/errors-envelope.cjs.map +1 -0
- package/dist/server/errors-envelope.d.cts +61 -0
- package/dist/server/errors-envelope.d.ts +61 -0
- package/dist/server/errors-envelope.js +405 -0
- package/dist/server/errors-envelope.js.map +1 -0
- package/dist/subscription/define-subscription.d.cts +63 -0
- package/dist/subscription/define-subscription.d.ts +63 -0
- package/dist/subscription/index.cjs +402 -0
- package/dist/subscription/index.cjs.map +1 -0
- package/dist/subscription/index.d.cts +18 -0
- package/dist/subscription/index.d.ts +18 -0
- package/dist/subscription/index.js +394 -0
- package/dist/subscription/index.js.map +1 -0
- package/dist/subscription/internal/adapter-types.d.cts +11 -0
- package/dist/subscription/internal/adapter-types.d.ts +11 -0
- package/dist/subscription/internal/backpressure.d.cts +24 -0
- package/dist/subscription/internal/backpressure.d.ts +24 -0
- package/dist/subscription/internal/server-integration.d.cts +17 -0
- package/dist/subscription/internal/server-integration.d.ts +17 -0
- package/dist/subscription/internal/sse-encoder.d.cts +13 -0
- package/dist/subscription/internal/sse-encoder.d.ts +13 -0
- package/dist/subscription/internal/sse-parser.d.cts +15 -0
- package/dist/subscription/internal/sse-parser.d.ts +15 -0
- package/dist/subscription/internal/subscription-runtime.d.cts +9 -0
- package/dist/subscription/internal/subscription-runtime.d.ts +9 -0
- package/dist/subscription/internal/ws-adapter-node.d.cts +10 -0
- package/dist/subscription/internal/ws-adapter-node.d.ts +10 -0
- package/dist/subscription/theokit-subscribe.d.cts +41 -0
- package/dist/subscription/theokit-subscribe.d.ts +41 -0
- package/dist/subscription/types.d.cts +140 -0
- package/dist/subscription/types.d.ts +140 -0
- package/dist/task-store.cjs +30 -2
- package/dist/task-store.cjs.map +1 -1
- package/dist/task-store.d.cts +8 -0
- package/dist/task-store.js +31 -3
- package/dist/task-store.js.map +1 -1
- package/dist/types/agent-prims.d.ts +61 -0
- package/dist/types/agent.d.ts +48 -53
- package/dist/types/conversation.d.ts +20 -8
- package/dist/types/index.d.ts +0 -2
- package/dist/types/messages-base.d.ts +20 -0
- package/dist/types/messages.d.ts +1 -1
- package/dist/types/run.d.ts +1 -1
- package/dist/types/updates.d.ts +1 -1
- package/dist/voice/index.d.ts +7 -0
- package/dist/voice/openai-realtime.d.ts +21 -0
- package/dist/voice/types.d.ts +35 -0
- package/dist/workflow.cjs +179 -88
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +97 -0
- package/dist/workflow.js +180 -89
- package/dist/workflow.js.map +1 -1
- package/package.json +126 -25
- package/dist/budget.d.ts +0 -48
- package/dist/cache.d.ts +0 -74
- package/dist/cron-1yxL3K2S.d.cts +0 -221
- package/dist/cron-BYVdYzob.d.ts +0 -221
- package/dist/handoff.d.ts +0 -55
- package/dist/internal/budget/calendar-window.d.ts +0 -19
- package/dist/internal/budget/enforcement.d.ts +0 -32
- package/dist/internal/budget/ledger.d.ts +0 -25
- package/dist/internal/budget/normalize-usage.d.ts +0 -27
- package/dist/internal/budget/registry.d.ts +0 -16
- package/dist/internal/cache/cosine.d.ts +0 -14
- package/dist/internal/cache/embed-helper.d.ts +0 -15
- package/dist/internal/cache/key.d.ts +0 -15
- package/dist/internal/cache/lookup.d.ts +0 -28
- package/dist/internal/cache/store-handler.d.ts +0 -24
- package/dist/internal/cache/store-json.d.ts +0 -48
- package/dist/internal/cache/store.d.ts +0 -54
- package/dist/internal/cache/telemetry.d.ts +0 -20
- package/dist/internal/cache/ttl.d.ts +0 -11
- package/dist/internal/catalog/fixtures.d.ts +0 -16
- package/dist/internal/catalog/local-models.d.ts +0 -24
- package/dist/internal/handoff/dispatcher.d.ts +0 -29
- package/dist/internal/handoff/registry.d.ts +0 -23
- package/dist/internal/handoff/telemetry.d.ts +0 -18
- package/dist/internal/handoff/tool-injector.d.ts +0 -34
- package/dist/internal/memory/atomic-write.d.ts +0 -7
- package/dist/internal/memory/dreaming/diary.d.ts +0 -4
- package/dist/internal/memory/dreaming/phases.d.ts +0 -15
- package/dist/internal/memory/dreaming/run.d.ts +0 -10
- package/dist/internal/memory/migrate-sqlite-to-lance.d.ts +0 -15
- package/dist/memory-adapter-helpers.d.ts +0 -28
- package/dist/memory.d.ts +0 -123
- package/dist/migrate.d.ts +0 -33
- package/dist/security.d.ts +0 -67
- package/dist/task.d.ts +0 -87
- package/dist/theokit.d.ts +0 -84
- package/dist/tools/_path-scope.d.ts +0 -8
- package/dist/tools/_subprocess.d.ts +0 -28
- package/dist/tools/git-diff.d.ts +0 -22
- package/dist/tools/index.d.ts +0 -29
- package/dist/tools/list-dir.d.ts +0 -26
- package/dist/tools/read-file.d.ts +0 -31
- package/dist/tools/run-vitest.d.ts +0 -46
- package/dist/tools/search-text.d.ts +0 -32
- package/dist/tools.cjs +0 -690
- package/dist/tools.cjs.map +0 -1
- package/dist/tools.js +0 -683
- package/dist/tools.js.map +0 -1
- package/dist/trajectory-helpers.d.ts +0 -31
- package/dist/types/cache.d.ts +0 -76
- package/dist/types/handoff.d.ts +0 -135
- /package/dist/{internal/cron/run-job.d.ts → agent-helpers.d.ts} +0 -0
- /package/dist/internal/{cron/scheduler.d.ts → agent-loop/loop-llm-stream.d.ts} +0 -0
- /package/dist/internal/{cron/store.d.ts → agent-loop/tool-executors.d.ts} +0 -0
- /package/dist/internal/{cron/validate.d.ts → memory/index-manager-helpers.d.ts} +0 -0
- /package/dist/internal/memory/{session-loader.d.ts → storage/session-loader.d.ts} +0 -0
- /package/dist/internal/memory/{session-summary-writer.d.ts → storage/session-summary-writer.d.ts} +0 -0
- /package/dist/internal/memory/{transcript-store.d.ts → storage/transcript-store.d.ts} +0 -0
- /package/dist/internal/memory/{wiki-loader.d.ts → storage/wiki-loader.d.ts} +0 -0
- /package/dist/internal/{memory/cwd-mutex.d.ts → persistence/atomic-write.d.cts} +0 -0
- /package/dist/internal/runtime/{context-aggregator.d.ts → context/context-aggregator.d.ts} +0 -0
- /package/dist/internal/runtime/{context-discovery-runner.d.ts → context/context-discovery-runner.d.ts} +0 -0
- /package/dist/internal/runtime/{context-discovery.d.ts → context/context-discovery.d.ts} +0 -0
- /package/dist/internal/runtime/{context-frontmatter.d.ts → context/context-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{context-import-resolver.d.ts → context/context-import-resolver.d.ts} +0 -0
- /package/dist/internal/runtime/{context-loaders.d.ts → context/context-loaders.d.ts} +0 -0
- /package/dist/internal/runtime/{context-mdc-parser.d.ts → context/context-mdc-parser.d.ts} +0 -0
- /package/dist/internal/runtime/{fixture-responder.d.ts → fixtures/fixture-responder.d.ts} +0 -0
- /package/dist/internal/runtime/{fixture-types.d.ts → fixtures/fixture-types.d.ts} +0 -0
- /package/dist/internal/runtime/{plugins-manager.d.ts → local-agent-send.d.ts} +0 -0
- /package/dist/internal/runtime/{plugin-frontmatter.d.ts → plugins/plugin-frontmatter.d.ts} +0 -0
- /package/dist/internal/runtime/{system-prompt/providers/active-memory-provider.d.ts → plugins/plugins-manager.d.ts} +0 -0
- /package/dist/internal/runtime/{agent-factory-registry.d.ts → registry/agent-factory-registry.d.ts} +0 -0
- /package/dist/internal/runtime/{agent-registry-store.d.ts → registry/agent-registry-store.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/base-provider.d.ts → sources/active-memory-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/context-provider.d.ts → sources/base-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/memory-provider.d.ts → sources/context-provider.d.ts} +0 -0
- /package/dist/internal/runtime/system-prompt/{providers/skills-provider.d.ts → sources/memory-provider.d.ts} +0 -0
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import type { SDKMessage } from "../../types/messages.js";
|
|
2
2
|
import type { LlmContentPart, LlmToolCallPart } from "../llm/types.js";
|
|
3
|
-
import type { AgentLoopInputs } from "./loop-types.js";
|
|
3
|
+
import type { AgentLoopInputs, ResolvedTool } from "./loop-types.js";
|
|
4
|
+
export type { ResolvedTool } from "./loop-types.js";
|
|
5
|
+
/**
|
|
6
|
+
* T2.4 — Parallel tool dispatch with bounded concurrency (DR2 finding #4).
|
|
7
|
+
*
|
|
8
|
+
* Pre-T2.4 this was a serial `for...of` loop — each tool call awaited
|
|
9
|
+
* before the next. With N independent tools each taking Tms, total
|
|
10
|
+
* wall-clock was N×Tms. T2.4 switches to `Promise.all` with bounded
|
|
11
|
+
* concurrency via an inline semaphore (ADR D135 — in-house, no
|
|
12
|
+
* `p-limit` dep). Default cap is 4 concurrent tools; consumer
|
|
13
|
+
* overrides via `AgentLoopInputs.maxConcurrentTools`.
|
|
14
|
+
*
|
|
15
|
+
* Order preservation: `Promise.all` preserves input order in the
|
|
16
|
+
* resolved array regardless of which promise settles first — the
|
|
17
|
+
* LLM expects tool results in call order and this contract holds.
|
|
18
|
+
*
|
|
19
|
+
* Event array safety: `events` is append-only. In single-threaded
|
|
20
|
+
* JS (Node event loop), concurrent `.push()` calls from different
|
|
21
|
+
* microtask continuations do NOT interleave — each push is atomic.
|
|
22
|
+
* The order of events across tools becomes non-deterministic, but
|
|
23
|
+
* each individual tool's events are internally ordered.
|
|
24
|
+
*/
|
|
4
25
|
export declare function dispatchTools(inputs: AgentLoopInputs, tools: ResolvedTool[], toolCalls: LlmToolCallPart[], events: SDKMessage[]): Promise<LlmContentPart[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T1.3 — API key boundary validation.
|
|
3
|
+
*
|
|
4
|
+
* `validateApiKeyShape(key, provider?)` runs at the create-agent boundary
|
|
5
|
+
* and rejects malformed inputs early (whitespace-only strings, sub-16-char
|
|
6
|
+
* fragments, embedded whitespace, missing-prefix shapes for providers that
|
|
7
|
+
* stamp a known prefix). The check is shape-only — it does NOT make a
|
|
8
|
+
* round-trip to the provider; live validation still happens at the first
|
|
9
|
+
* `fetch` against the provider URL.
|
|
10
|
+
*
|
|
11
|
+
* Exempted from shape validation:
|
|
12
|
+
* - fixture keys (prefix `theo_test_`) — used by SDK consumers' fixture-mode tests.
|
|
13
|
+
* - local-runtime mock key `"local"` — used by Ollama / LMStudio / llama.cpp
|
|
14
|
+
* sibling profiles (ADRs D182/D188/D189) whose `authType` is `"none"`.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export interface ApiKeyValidationFailure {
|
|
19
|
+
readonly malformed: true;
|
|
20
|
+
readonly reason: "empty" | "whitespace_only" | "too_short" | "embedded_whitespace" | "missing_known_prefix";
|
|
21
|
+
readonly message: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ApiKeyValidationOk {
|
|
24
|
+
readonly malformed: false;
|
|
25
|
+
}
|
|
26
|
+
export type ApiKeyValidationResult = ApiKeyValidationOk | ApiKeyValidationFailure;
|
|
27
|
+
export interface ValidateApiKeyOptions {
|
|
28
|
+
/** Provider name (lowercase) for prefix sanity check. */
|
|
29
|
+
provider?: string;
|
|
30
|
+
/**
|
|
31
|
+
* When `false`, only OBVIOUSLY-malformed inputs (empty, whitespace-only,
|
|
32
|
+
* < 4 chars) are rejected. Set when the caller knows the value is just an
|
|
33
|
+
* identifier (e.g., `shouldUseRealLocalRuntime` mode where the real HTTP
|
|
34
|
+
* call uses an env credential instead of this `apiKey`).
|
|
35
|
+
*
|
|
36
|
+
* When `true` (default), the full shape check applies: 16-char minimum,
|
|
37
|
+
* provider-prefix sanity, no embedded whitespace.
|
|
38
|
+
*/
|
|
39
|
+
strict?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate the shape of an API key. Returns a discriminated result; the
|
|
43
|
+
* boundary caller (`agent.ts createLocalAgent` / `createCloudAgent`) throws
|
|
44
|
+
* `AuthenticationError({code:"malformed_api_key"})` on failure.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateApiKeyShape(key: string | undefined, options?: ValidateApiKeyOptions | string): ApiKeyValidationResult;
|
|
@@ -76,10 +76,17 @@ export declare function consumeAnthropicResponse(response: Response): Promise<{
|
|
|
76
76
|
outputTokens?: number;
|
|
77
77
|
}>;
|
|
78
78
|
export declare function parseHttpErrorBody(response: Response): Promise<unknown>;
|
|
79
|
+
export interface AnthropicTextBlock {
|
|
80
|
+
type: "text";
|
|
81
|
+
text: string;
|
|
82
|
+
cache_control?: {
|
|
83
|
+
type: "ephemeral";
|
|
84
|
+
};
|
|
85
|
+
}
|
|
79
86
|
export declare function buildAnthropicCommonBody(request: LlmRequest): {
|
|
80
87
|
max_tokens: number;
|
|
81
88
|
messages: Array<Record<string, unknown>>;
|
|
82
|
-
system?: string;
|
|
89
|
+
system?: string | AnthropicTextBlock[];
|
|
83
90
|
temperature?: number;
|
|
84
91
|
tools?: Array<{
|
|
85
92
|
name: string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T3.4 — exponential backoff with full jitter for credential-pool retry.
|
|
3
|
+
*
|
|
4
|
+
* Why we need this: pre-T3.4 `pool-aware-client.ts:79-83` retried the
|
|
5
|
+
* SAME credential immediately on the first 429 without any wait. When
|
|
6
|
+
* every credential in the pool returned 429 (thundering herd against a
|
|
7
|
+
* shared quota), the client burned through all 5 retry attempts in <1ms,
|
|
8
|
+
* tripped `CredentialPoolExhaustedError`, and surfaced to the agent loop
|
|
9
|
+
* as a hard failure. The user-visible symptom was "all my keys are
|
|
10
|
+
* exhausted!" when in reality a 1-2s wait would have cleared the rate
|
|
11
|
+
* limit.
|
|
12
|
+
*
|
|
13
|
+
* AWS Architecture Blog "Exponential Backoff And Jitter" (Marc Brooker,
|
|
14
|
+
* 2015) demonstrates full jitter as the canonical pattern: `sleep =
|
|
15
|
+
* random_between(0, base * 2^attempt)`. We extend it with a hard cap
|
|
16
|
+
* (so a 32s sleep never blocks an interactive agent) and honor the
|
|
17
|
+
* provider's `Retry-After` hint when present — the hint always wins over
|
|
18
|
+
* the computed value when it falls within `[base, cap]`.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export {};
|
|
@@ -27,13 +27,59 @@ export interface LlmMessage {
|
|
|
27
27
|
role: "system" | "user" | "assistant";
|
|
28
28
|
content: LlmContentPart[];
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* T3.5 — a single system-prompt block. Used by `LlmRequest.system` when the
|
|
32
|
+
* caller wants to opt into Anthropic prompt caching: each block whose
|
|
33
|
+
* `cacheable` is `true` gets the `cache_control: {type: 'ephemeral'}`
|
|
34
|
+
* annotation in the Anthropic wire body, which lets Anthropic bill
|
|
35
|
+
* subsequent same-content requests at the cache-read rate (1-3x discount).
|
|
36
|
+
*
|
|
37
|
+
* For providers that don't support prompt caching (OpenAI, OpenRouter, etc),
|
|
38
|
+
* the array is joined into a single string at the wire boundary so the
|
|
39
|
+
* upstream contract stays unchanged. Back-compat: `LlmRequest.system` still
|
|
40
|
+
* accepts a plain `string` (pre-T3.5 callers compile unchanged).
|
|
41
|
+
*/
|
|
42
|
+
export interface LlmSystemBlock {
|
|
43
|
+
text: string;
|
|
44
|
+
/** When `true`, ask the provider to cache this block (Anthropic only). */
|
|
45
|
+
cacheable?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* T3.6 — `LlmRequest.responseFormat` opt-in for OpenAI native structured
|
|
49
|
+
* outputs. When set, providers that support it emit the response strictly
|
|
50
|
+
* matching the schema (no parse retries; lower latency than the
|
|
51
|
+
* synthetic-tool fallback path).
|
|
52
|
+
*
|
|
53
|
+
* Two shapes:
|
|
54
|
+
* - `{ type: "json_schema", jsonSchema: { name, schema, strict? } }` —
|
|
55
|
+
* the canonical structured-outputs shape (`gpt-4o-2024-08-06+`).
|
|
56
|
+
* `strict` defaults to `true` (provider guarantees match).
|
|
57
|
+
* - `{ type: "json_object" }` — the legacy "JSON mode" hint (older
|
|
58
|
+
* OpenAI models). Returns JSON but does NOT guarantee schema match.
|
|
59
|
+
*
|
|
60
|
+
* Providers that don't support the field (Anthropic, Ollama) silently
|
|
61
|
+
* ignore it at the wire layer (`buildAnthropicCommonBody`,
|
|
62
|
+
* `buildOllamaChatBody`).
|
|
63
|
+
*/
|
|
64
|
+
export type LlmResponseFormat = {
|
|
65
|
+
type: "json_object";
|
|
66
|
+
} | {
|
|
67
|
+
type: "json_schema";
|
|
68
|
+
jsonSchema: {
|
|
69
|
+
name: string;
|
|
70
|
+
schema: Record<string, unknown>;
|
|
71
|
+
strict?: boolean;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
30
74
|
export interface LlmRequest {
|
|
31
75
|
model: string;
|
|
32
|
-
system?: string;
|
|
76
|
+
system?: string | LlmSystemBlock[];
|
|
33
77
|
messages: LlmMessage[];
|
|
34
78
|
tools?: LlmTool[];
|
|
35
79
|
maxTokens?: number;
|
|
36
80
|
temperature?: number;
|
|
81
|
+
/** T3.6 — opt into native structured outputs (OpenAI-compat providers). */
|
|
82
|
+
responseFormat?: LlmResponseFormat;
|
|
37
83
|
}
|
|
38
84
|
export type LlmEvent = {
|
|
39
85
|
type: "text_delta";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ActiveMemoryResult } from "./active-memory.js";
|
|
1
|
+
import type { ActiveMemoryResult } from "./active-memory-types.js";
|
|
2
2
|
export declare class ActiveMemoryCache {
|
|
3
3
|
private readonly opts;
|
|
4
4
|
private readonly map;
|
|
5
5
|
constructor(opts?: ActiveMemoryCacheOptions);
|
|
6
|
-
get(userText: string, queryMode: string): ActiveMemoryResult | undefined;
|
|
7
|
-
set(userText: string, queryMode: string, result: ActiveMemoryResult): void;
|
|
6
|
+
get(userText: string, queryMode: string, tenantCtx?: TenantContext): ActiveMemoryResult | undefined;
|
|
7
|
+
set(userText: string, queryMode: string, result: ActiveMemoryResult, tenantCtx?: TenantContext): void;
|
|
8
8
|
size(): number;
|
|
9
9
|
private now;
|
|
10
10
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MemorySearchHit } from "./index-manager-contract.js";
|
|
2
|
+
export type ActiveMemoryStatus = "ok" | "timeout" | "skipped" | "no-recall" | "error";
|
|
3
|
+
export interface ActiveMemoryResult {
|
|
4
|
+
summary: string | undefined;
|
|
5
|
+
durationMs: number;
|
|
6
|
+
status: ActiveMemoryStatus;
|
|
7
|
+
hits: ReadonlyArray<MemorySearchHit>;
|
|
8
|
+
}
|
|
@@ -1,26 +1,9 @@
|
|
|
1
|
+
import { type TelemetryHandle } from "../telemetry/tracer.js";
|
|
1
2
|
import type { ActiveMemoryCache } from "./active-memory-cache.js";
|
|
3
|
+
import type { ActiveMemoryQueryMode, ActiveMemoryResult, ActiveMemoryStatus } from "./active-memory-types.js";
|
|
2
4
|
import type { CircuitBreaker } from "./circuit-breaker.js";
|
|
3
|
-
import type { MemorySearchHit } from "./index-manager.js";
|
|
4
5
|
import type { MemoryIndex } from "./memory-index.js";
|
|
5
|
-
export type
|
|
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
|
-
}
|
|
6
|
+
export type { ActiveMemoryQueryMode, ActiveMemoryResult, ActiveMemoryStatus };
|
|
24
7
|
export interface RunActiveMemoryArgs {
|
|
25
8
|
userText: string;
|
|
26
9
|
priorMessages: ReadonlyArray<{
|
|
@@ -41,5 +24,26 @@ export interface RunActiveMemoryArgs {
|
|
|
41
24
|
agentKey?: string;
|
|
42
25
|
/** Run id for transcript file naming. */
|
|
43
26
|
runId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* T0.1 — optional telemetry handle. When provided AND telemetry is enabled,
|
|
29
|
+
* `memory.recall` span is emitted with `{ userId, namespace, scope, queryMode,
|
|
30
|
+
* hits, status }` attrs and `theokit_memory_recall_duration_ms` histogram is
|
|
31
|
+
* recorded with the same dimension keys. T4.9 will pin `userId/namespace/scope`
|
|
32
|
+
* to the cache-key invariant (cross-tenant leak fix).
|
|
33
|
+
*/
|
|
34
|
+
telemetry?: TelemetryHandle;
|
|
35
|
+
/** User id surfaced as a memory.recall span attr for cross-tenant tracing. */
|
|
36
|
+
userId?: string;
|
|
37
|
+
/** Memory namespace (e.g. `default`, `<orgId>`) for span/histogram dimensions. */
|
|
38
|
+
namespace?: string;
|
|
39
|
+
/** Memory scope (`session` / `user` / `global`) for span/histogram dimensions. */
|
|
40
|
+
scope?: string;
|
|
41
|
+
/**
|
|
42
|
+
* T4.7 — AbortSignal propagation. When the caller's signal aborts,
|
|
43
|
+
* the active-memory recall exits early with `status: "skipped"` and
|
|
44
|
+
* summary `undefined`. Prevents long-running embedding calls from
|
|
45
|
+
* blocking agent.dispose() or user-initiated cancellation.
|
|
46
|
+
*/
|
|
47
|
+
signal?: AbortSignal;
|
|
44
48
|
}
|
|
45
49
|
export declare function runActiveMemory(args: RunActiveMemoryArgs): Promise<ActiveMemoryResult>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
|
+
export interface IndexStatus {
|
|
3
|
+
backend: "fts-only" | "hybrid";
|
|
4
|
+
filesIndexed: number;
|
|
5
|
+
chunksIndexed: number;
|
|
6
|
+
lastSyncMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SearchOptions {
|
|
9
|
+
maxResults?: number;
|
|
10
|
+
minScore?: number;
|
|
11
|
+
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
12
|
+
/** 0..1 — vector vs text weight in hybrid scoring (D4). Default 0.6. */
|
|
13
|
+
vectorWeight?: number;
|
|
14
|
+
/** 0..1 — text weight in hybrid scoring. Default 0.4. */
|
|
15
|
+
textWeight?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Vector backend selector. SQLite default; Lance opt-in (ADR D43). */
|
|
18
|
+
export type MemoryBackend = "sqlite-vec" | "lance";
|
|
19
|
+
export interface OpenIndexOptions {
|
|
20
|
+
cwd: string;
|
|
21
|
+
filePath?: string;
|
|
22
|
+
/** When provided, vector index is enabled in hybrid mode. */
|
|
23
|
+
embedding?: EmbeddingRuntime;
|
|
24
|
+
/** Vector backend. Default and only value today: `"sqlite-vec"`. */
|
|
25
|
+
backend?: MemoryBackend;
|
|
26
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
import type { MemoryBackend, OpenIndexOptions } from "./index-manager.js";
|
|
7
|
+
import type { MemoryBackend, OpenIndexOptions } from "./index-manager-contract.js";
|
|
8
8
|
import type { MemoryIndex } from "./memory-index.js";
|
|
9
9
|
/** Valid backend identifiers — runtime guard against TS-narrowing escapes (EC-1). */
|
|
10
10
|
export declare const VALID_BACKENDS: readonly MemoryBackend[];
|
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
import type { EmbeddingRuntime } from "./embedding-adapter.js";
|
|
2
1
|
import { type MemoryIndex } from "./memory-index.js";
|
|
3
|
-
|
|
4
|
-
backend: "fts-only" | "hybrid";
|
|
5
|
-
filesIndexed: number;
|
|
6
|
-
chunksIndexed: number;
|
|
7
|
-
lastSyncMs?: number;
|
|
8
|
-
}
|
|
9
|
-
export interface SearchOptions {
|
|
10
|
-
maxResults?: number;
|
|
11
|
-
minScore?: number;
|
|
12
|
-
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
13
|
-
/** 0..1 — vector vs text weight in hybrid scoring (D4). Default 0.6. */
|
|
14
|
-
vectorWeight?: number;
|
|
15
|
-
/** 0..1 — text weight in hybrid scoring. Default 0.4. */
|
|
16
|
-
textWeight?: number;
|
|
17
|
-
}
|
|
18
|
-
/** Vector backend selector. SQLite default; Lance opt-in (ADR D43). */
|
|
19
|
-
export type MemoryBackend = "sqlite-vec" | "lance";
|
|
20
|
-
export interface OpenIndexOptions {
|
|
21
|
-
cwd: string;
|
|
22
|
-
filePath?: string;
|
|
23
|
-
/** When provided, vector index is enabled in hybrid mode. */
|
|
24
|
-
embedding?: EmbeddingRuntime;
|
|
25
|
-
/** Vector backend. Default and only value today: `"sqlite-vec"`. */
|
|
26
|
-
backend?: MemoryBackend;
|
|
27
|
-
}
|
|
2
|
+
import type { IndexStatus, MemorySearchHit, OpenIndexOptions, SearchOptions } from "./index-manager-contract.js";
|
|
28
3
|
export declare class IndexManager implements MemoryIndex {
|
|
29
4
|
private readonly cwd;
|
|
30
5
|
private readonly db;
|
|
@@ -56,6 +31,13 @@ export declare class IndexManager implements MemoryIndex {
|
|
|
56
31
|
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
57
32
|
status(): IndexStatus;
|
|
58
33
|
private ftsSearch;
|
|
34
|
+
/**
|
|
35
|
+
* T4.8 — LIKE-based fallback for CJK and other scripts that FTS5's
|
|
36
|
+
* default tokenizer cannot segment. Slower than FTS5 (full table scan)
|
|
37
|
+
* but correct for any Unicode input. Returns the same shape as
|
|
38
|
+
* `ftsSearch` so callers are unaware of the fallback.
|
|
39
|
+
*/
|
|
40
|
+
private likeSearchFallback;
|
|
59
41
|
private vectorSearchById;
|
|
60
42
|
private combineHybridScores;
|
|
61
43
|
private mergeHits;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MemoryChunk } from "
|
|
1
|
+
import type { MemoryChunk } from "../types.js";
|
|
2
2
|
export declare function chunkMarkdown(text: string, options?: ChunkMarkdownOptions): MemoryChunk[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MemoryConfig, type MemoryFact } from "
|
|
1
|
+
import { type MemoryConfig, type MemoryFact } from "../types.js";
|
|
2
2
|
export declare function memoryDir(cwd: string): string;
|
|
3
3
|
export declare function memoryMdPath(cwd: string): string;
|
|
4
4
|
export declare function notesDir(cwd: string): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObservabilityContext — public type for structured observability
|
|
3
|
+
* across agent runtime, memory, and tool dispatch (T10.2, ADR D449).
|
|
4
|
+
*
|
|
5
|
+
* Consumers use this type to thread tracing/logging context through
|
|
6
|
+
* custom tools and plugins.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface ObservabilityContext {
|
|
11
|
+
/** Current trace ID (W3C Trace Context format). */
|
|
12
|
+
traceId: string;
|
|
13
|
+
/** Current span ID. */
|
|
14
|
+
spanId: string;
|
|
15
|
+
/** Parent span ID (undefined for root spans). */
|
|
16
|
+
parentSpanId?: string;
|
|
17
|
+
/** Structured log emitter. */
|
|
18
|
+
log: (level: "debug" | "info" | "warn" | "error", message: string, attrs?: Record<string, unknown>) => void;
|
|
19
|
+
/** Record a counter metric. */
|
|
20
|
+
counter: (name: string, value?: number, attrs?: Record<string, unknown>) => void;
|
|
21
|
+
/** Record a histogram metric. */
|
|
22
|
+
histogram: (name: string, value: number, attrs?: Record<string, unknown>) => void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObservabilityContext — public type for structured observability
|
|
3
|
+
* across agent runtime, memory, and tool dispatch (T10.2, ADR D449).
|
|
4
|
+
*
|
|
5
|
+
* Consumers use this type to thread tracing/logging context through
|
|
6
|
+
* custom tools and plugins.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface ObservabilityContext {
|
|
11
|
+
/** Current trace ID (W3C Trace Context format). */
|
|
12
|
+
traceId: string;
|
|
13
|
+
/** Current span ID. */
|
|
14
|
+
spanId: string;
|
|
15
|
+
/** Parent span ID (undefined for root spans). */
|
|
16
|
+
parentSpanId?: string;
|
|
17
|
+
/** Structured log emitter. */
|
|
18
|
+
log: (level: "debug" | "info" | "warn" | "error", message: string, attrs?: Record<string, unknown>) => void;
|
|
19
|
+
/** Record a counter metric. */
|
|
20
|
+
counter: (name: string, value?: number, attrs?: Record<string, unknown>) => void;
|
|
21
|
+
/** Record a histogram metric. */
|
|
22
|
+
histogram: (name: string, value: number, attrs?: Record<string, unknown>) => void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var module$1 = require('module');
|
|
4
|
+
|
|
5
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
6
|
+
// src/internal/observability/tracer-loader.ts
|
|
7
|
+
var noopSpan = {
|
|
8
|
+
setAttribute: () => noopSpan,
|
|
9
|
+
end: () => void 0
|
|
10
|
+
};
|
|
11
|
+
var tracerCache = /* @__PURE__ */ new Map();
|
|
12
|
+
function getTracer(name, version = "1.0.0") {
|
|
13
|
+
const cached = tracerCache.get(name);
|
|
14
|
+
if (cached !== void 0) return cached.tracer ?? void 0;
|
|
15
|
+
try {
|
|
16
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
17
|
+
const otel = r("@opentelemetry/api");
|
|
18
|
+
if (otel.trace?.getTracer === void 0) {
|
|
19
|
+
tracerCache.set(name, { tracer: null });
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
const tracer = otel.trace.getTracer(name, version);
|
|
23
|
+
tracerCache.set(name, { tracer });
|
|
24
|
+
return tracer;
|
|
25
|
+
} catch {
|
|
26
|
+
tracerCache.set(name, { tracer: null });
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function resetTracerCacheForTests() {
|
|
31
|
+
tracerCache.clear();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.getTracer = getTracer;
|
|
35
|
+
exports.noopSpan = noopSpan;
|
|
36
|
+
exports.resetTracerCacheForTests = resetTracerCacheForTests;
|
|
37
|
+
//# sourceMappingURL=index.cjs.map
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/observability/tracer-loader.ts"],"names":["createRequire"],"mappings":";;;;;;AAgBO,IAAM,QAAA,GAAqB;AAAA,EAChC,cAAc,MAAM,QAAA;AAAA,EACpB,KAAK,MAAM;AACb;AAaA,IAAM,WAAA,uBAAkB,GAAA,EAAwB;AAEzC,SAAS,SAAA,CAAU,IAAA,EAAc,OAAA,GAAU,OAAA,EAAiC;AACjF,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,IAAI,CAAA;AACnC,EAAA,IAAI,MAAA,KAAW,MAAA,EAAW,OAAO,MAAA,CAAO,MAAA,IAAU,MAAA;AAClD,EAAA,IAAI;AACF,IAAA,MAAM,CAAA,GAAIA,sBAAA,CAAc,2PAAe,CAAA;AACvC,IAAA,MAAM,IAAA,GAAO,EAAE,oBAAoB,CAAA;AAGnC,IAAA,IAAI,IAAA,CAAK,KAAA,EAAO,SAAA,KAAc,KAAA,CAAA,EAAW;AACvC,MAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,MAAA,EAAQ,MAAM,CAAA;AACtC,MAAA,OAAO,KAAA,CAAA;AAAA,IACT;AACA,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAM,OAAO,CAAA;AACjD,IAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,MAAA,EAAQ,CAAA;AAChC,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,MAAA,EAAQ,MAAM,CAAA;AACtC,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAEO,SAAS,wBAAA,GAAiC;AAC/C,EAAA,WAAA,CAAY,KAAA,EAAM;AACpB","file":"index.cjs","sourcesContent":["/**\n * Shared OTel tracer loader (extracted to eliminate cross-module clones —\n * was previously inlined in cache/, workflow/, eval/, handoff/ telemetry\n * modules). Lazy-loads `@opentelemetry/api` via `createRequire`; users\n * without OTel installed pay zero cost.\n *\n * @internal\n */\n\nimport { createRequire } from \"node:module\";\n\nexport interface SpanLike {\n setAttribute(key: string, value: string | number | boolean): SpanLike;\n end(): void;\n}\n\nexport const noopSpan: SpanLike = {\n setAttribute: () => noopSpan,\n end: () => undefined,\n};\n\nexport interface TracerLike {\n startSpan(\n name: string,\n options?: { attributes?: Record<string, string | number | boolean> },\n ): SpanLike;\n}\n\ninterface CacheEntry {\n tracer: TracerLike | null;\n}\n\nconst tracerCache = new Map<string, CacheEntry>();\n\nexport function getTracer(name: string, version = \"1.0.0\"): TracerLike | undefined {\n const cached = tracerCache.get(name);\n if (cached !== undefined) return cached.tracer ?? undefined;\n try {\n const r = createRequire(import.meta.url);\n const otel = r(\"@opentelemetry/api\") as {\n trace?: { getTracer: (n: string, v?: string) => TracerLike };\n };\n if (otel.trace?.getTracer === undefined) {\n tracerCache.set(name, { tracer: null });\n return undefined;\n }\n const tracer = otel.trace.getTracer(name, version);\n tracerCache.set(name, { tracer });\n return tracer;\n } catch {\n tracerCache.set(name, { tracer: null });\n return undefined;\n }\n}\n\nexport function resetTracerCacheForTests(): void {\n tracerCache.clear();\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for observability primitives shared across subsystems
|
|
3
|
+
* (cache, memory, etc.) — exposed via `@theokit/sdk/internal/observability`
|
|
4
|
+
* sub-path (SDK 2.0 Phase 3 prep).
|
|
5
|
+
*
|
|
6
|
+
* @internal — semver-exempt; surface may change in patch releases.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./tracer-loader.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel for observability primitives shared across subsystems
|
|
3
|
+
* (cache, memory, etc.) — exposed via `@theokit/sdk/internal/observability`
|
|
4
|
+
* sub-path (SDK 2.0 Phase 3 prep).
|
|
5
|
+
*
|
|
6
|
+
* @internal — semver-exempt; surface may change in patch releases.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./tracer-loader.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
|
|
3
|
+
// src/internal/observability/tracer-loader.ts
|
|
4
|
+
var noopSpan = {
|
|
5
|
+
setAttribute: () => noopSpan,
|
|
6
|
+
end: () => void 0
|
|
7
|
+
};
|
|
8
|
+
var tracerCache = /* @__PURE__ */ new Map();
|
|
9
|
+
function getTracer(name, version = "1.0.0") {
|
|
10
|
+
const cached = tracerCache.get(name);
|
|
11
|
+
if (cached !== void 0) return cached.tracer ?? void 0;
|
|
12
|
+
try {
|
|
13
|
+
const r = createRequire(import.meta.url);
|
|
14
|
+
const otel = r("@opentelemetry/api");
|
|
15
|
+
if (otel.trace?.getTracer === void 0) {
|
|
16
|
+
tracerCache.set(name, { tracer: null });
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
const tracer = otel.trace.getTracer(name, version);
|
|
20
|
+
tracerCache.set(name, { tracer });
|
|
21
|
+
return tracer;
|
|
22
|
+
} catch {
|
|
23
|
+
tracerCache.set(name, { tracer: null });
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function resetTracerCacheForTests() {
|
|
28
|
+
tracerCache.clear();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { getTracer, noopSpan, resetTracerCacheForTests };
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/observability/tracer-loader.ts"],"names":[],"mappings":";;;AAgBO,IAAM,QAAA,GAAqB;AAAA,EAChC,cAAc,MAAM,QAAA;AAAA,EACpB,KAAK,MAAM;AACb;AAaA,IAAM,WAAA,uBAAkB,GAAA,EAAwB;AAEzC,SAAS,SAAA,CAAU,IAAA,EAAc,OAAA,GAAU,OAAA,EAAiC;AACjF,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,GAAA,CAAI,IAAI,CAAA;AACnC,EAAA,IAAI,MAAA,KAAW,MAAA,EAAW,OAAO,MAAA,CAAO,MAAA,IAAU,MAAA;AAClD,EAAA,IAAI;AACF,IAAA,MAAM,CAAA,GAAI,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AACvC,IAAA,MAAM,IAAA,GAAO,EAAE,oBAAoB,CAAA;AAGnC,IAAA,IAAI,IAAA,CAAK,KAAA,EAAO,SAAA,KAAc,KAAA,CAAA,EAAW;AACvC,MAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,MAAA,EAAQ,MAAM,CAAA;AACtC,MAAA,OAAO,KAAA,CAAA;AAAA,IACT;AACA,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAM,OAAO,CAAA;AACjD,IAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,MAAA,EAAQ,CAAA;AAChC,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,EAAE,MAAA,EAAQ,MAAM,CAAA;AACtC,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAEO,SAAS,wBAAA,GAAiC;AAC/C,EAAA,WAAA,CAAY,KAAA,EAAM;AACpB","file":"index.js","sourcesContent":["/**\n * Shared OTel tracer loader (extracted to eliminate cross-module clones —\n * was previously inlined in cache/, workflow/, eval/, handoff/ telemetry\n * modules). Lazy-loads `@opentelemetry/api` via `createRequire`; users\n * without OTel installed pay zero cost.\n *\n * @internal\n */\n\nimport { createRequire } from \"node:module\";\n\nexport interface SpanLike {\n setAttribute(key: string, value: string | number | boolean): SpanLike;\n end(): void;\n}\n\nexport const noopSpan: SpanLike = {\n setAttribute: () => noopSpan,\n end: () => undefined,\n};\n\nexport interface TracerLike {\n startSpan(\n name: string,\n options?: { attributes?: Record<string, string | number | boolean> },\n ): SpanLike;\n}\n\ninterface CacheEntry {\n tracer: TracerLike | null;\n}\n\nconst tracerCache = new Map<string, CacheEntry>();\n\nexport function getTracer(name: string, version = \"1.0.0\"): TracerLike | undefined {\n const cached = tracerCache.get(name);\n if (cached !== undefined) return cached.tracer ?? undefined;\n try {\n const r = createRequire(import.meta.url);\n const otel = r(\"@opentelemetry/api\") as {\n trace?: { getTracer: (n: string, v?: string) => TracerLike };\n };\n if (otel.trace?.getTracer === undefined) {\n tracerCache.set(name, { tracer: null });\n return undefined;\n }\n const tracer = otel.trace.getTracer(name, version);\n tracerCache.set(name, { tracer });\n return tracer;\n } catch {\n tracerCache.set(name, { tracer: null });\n return undefined;\n }\n}\n\nexport function resetTracerCacheForTests(): void {\n tracerCache.clear();\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OTel tracer loader (extracted to eliminate cross-module clones —
|
|
3
|
+
* was previously inlined in cache/, workflow/, eval/, handoff/ telemetry
|
|
4
|
+
* modules). Lazy-loads `@opentelemetry/api` via `createRequire`; users
|
|
5
|
+
* without OTel installed pay zero cost.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface SpanLike {
|
|
10
|
+
setAttribute(key: string, value: string | number | boolean): SpanLike;
|
|
11
|
+
end(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const noopSpan: SpanLike;
|
|
14
|
+
export interface TracerLike {
|
|
15
|
+
startSpan(name: string, options?: {
|
|
16
|
+
attributes?: Record<string, string | number | boolean>;
|
|
17
|
+
}): SpanLike;
|
|
18
|
+
}
|
|
19
|
+
export declare function getTracer(name: string, version?: string): TracerLike | undefined;
|
|
20
|
+
export declare function resetTracerCacheForTests(): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem-backed implementation of {@link ConversationStorageAdapter}
|
|
3
|
+
* (Production-Readiness #1, ADR D304).
|
|
4
|
+
*
|
|
5
|
+
* Default adapter when `AgentOptions.conversationStorage` is not provided.
|
|
6
|
+
* Writes append-only JSONL to `<root>/.theokit/agents/<safeId>/messages.jsonl`,
|
|
7
|
+
* preserving the pre-D303 byte-identical behavior (redaction D68 + JSONL
|
|
8
|
+
* line granularity).
|
|
9
|
+
*
|
|
10
|
+
* Path safety: every conversationId flows through `sanitizeIdentifier` +
|
|
11
|
+
* `safePathJoin` before touching disk. `deleteConversation` re-applies the
|
|
12
|
+
* guard (EC-1) — without this the new `rm -rf` would escape via traversal.
|
|
13
|
+
*
|
|
14
|
+
* Listing: `listConversationIds` catches ENOENT (EC-2) so first-run deploys
|
|
15
|
+
* without any `.theokit/agents/` directory return `[]` instead of crashing.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
import type { ConversationStorageAdapter, StoredMessage } from "../../types/conversation-storage.js";
|
|
20
|
+
export interface FileSystemConversationStorageOptions {
|
|
21
|
+
/** Root directory under which `.theokit/agents/<id>/` lives. Defaults to `process.cwd()`. */
|
|
22
|
+
root?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class FileSystemConversationStorage implements ConversationStorageAdapter {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(opts?: FileSystemConversationStorageOptions);
|
|
27
|
+
/** Exposed for tests + diagnostics. The path is sanitized at use sites. */
|
|
28
|
+
get root(): string;
|
|
29
|
+
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
30
|
+
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
31
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
32
|
+
listConversationIds(opts?: {
|
|
33
|
+
limit?: number;
|
|
34
|
+
}): Promise<readonly string[]>;
|
|
35
|
+
compact(conversationId: string, maxTurns: number): Promise<void>;
|
|
36
|
+
dispose(): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory implementation of {@link ConversationStorageAdapter} (Production-Readiness #1, ADR D304).
|
|
3
|
+
*
|
|
4
|
+
* Intended for tests + ephemeral single-process dev/CLI usage. Holds messages
|
|
5
|
+
* in a `Map<conversationId, StoredMessage[]>`. JavaScript's single-threaded
|
|
6
|
+
* runtime makes per-conversation appends naturally atomic; no external mutex
|
|
7
|
+
* needed.
|
|
8
|
+
*
|
|
9
|
+
* The adapter returns defensive copies from `getMessages` so callers cannot
|
|
10
|
+
* mutate internal state by holding a reference to the returned array.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
import type { ConversationStorageAdapter, StoredMessage } from "../../types/conversation-storage.js";
|
|
15
|
+
export declare class InMemoryConversationStorage implements ConversationStorageAdapter {
|
|
16
|
+
#private;
|
|
17
|
+
getMessages(conversationId: string): Promise<readonly StoredMessage[]>;
|
|
18
|
+
appendMessage(conversationId: string, message: StoredMessage): Promise<void>;
|
|
19
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
20
|
+
listConversationIds(opts?: {
|
|
21
|
+
limit?: number;
|
|
22
|
+
}): Promise<readonly string[]>;
|
|
23
|
+
dispose(): Promise<void>;
|
|
24
|
+
}
|