theorum 0.1.15 → 1.1.3
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/README.md +241 -98
- package/esm/mod.d.ts +57 -28
- package/esm/mod.js +43 -23
- package/esm/src/cli/commands/bench.js +18 -18
- package/esm/src/cli/commands/fuzz-canary.d.ts +13 -0
- package/esm/src/cli/commands/fuzz-canary.js +191 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +3 -5
- package/esm/src/cli/commands/fuzz-guardrails.js +4 -581
- package/esm/src/cli/commands/guardrails-eval.d.ts +14 -0
- package/esm/src/cli/commands/guardrails-eval.js +15 -0
- package/esm/src/cli/commands/profile.js +35 -15
- package/esm/src/cli/commands/run.d.ts +3 -0
- package/esm/src/cli/commands/run.js +23 -32
- package/esm/src/cli/commands/test.d.ts +10 -1
- package/esm/src/cli/commands/test.js +34 -34
- package/esm/src/cli/event-log.d.ts +19 -0
- package/esm/src/cli/event-log.js +147 -0
- package/esm/src/cli/index.js +57 -11
- package/esm/src/cli/matrix/synthesizer.d.ts +10 -12
- package/esm/src/cli/matrix/synthesizer.js +45 -118
- package/esm/src/guardrails/canary-gate.d.ts +21 -0
- package/esm/src/guardrails/canary-gate.js +32 -0
- package/esm/src/guardrails/canary.d.ts +34 -0
- package/esm/src/guardrails/canary.js +150 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +17 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +151 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +11 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +213 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +10 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +125 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +20 -0
- package/esm/src/guardrails/corpus/live-attacks.js +231 -0
- package/esm/src/guardrails/corpus/mod.d.ts +14 -0
- package/esm/src/guardrails/corpus/mod.js +11 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +17 -0
- package/esm/src/guardrails/corpus/secrets.js +17 -0
- package/esm/src/guardrails/corpus/strings.d.ts +28 -0
- package/esm/src/guardrails/corpus/strings.js +34 -0
- package/esm/src/guardrails/corpus/types.d.ts +38 -0
- package/esm/src/guardrails/corpus/types.js +6 -0
- package/esm/src/guardrails/egress.d.ts +32 -0
- package/esm/src/guardrails/egress.js +87 -0
- package/esm/src/guardrails/error.d.ts +14 -23
- package/esm/src/guardrails/error.js +87 -76
- package/esm/src/guardrails/eval/corpus.d.ts +108 -0
- package/esm/src/guardrails/eval/corpus.js +978 -0
- package/esm/src/guardrails/eval/mod.d.ts +51 -0
- package/esm/src/guardrails/eval/mod.js +133 -0
- package/esm/src/guardrails/eval/score.d.ts +66 -0
- package/esm/src/guardrails/eval/score.js +114 -0
- package/esm/src/guardrails/events.d.ts +25 -0
- package/esm/src/guardrails/events.js +56 -0
- package/esm/src/guardrails/hits.d.ts +24 -0
- package/esm/src/guardrails/hits.js +45 -0
- package/esm/src/guardrails/injection.js +28 -5
- package/esm/src/guardrails/lexicon.d.ts +39 -0
- package/esm/src/guardrails/lexicon.js +200 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +41 -0
- package/esm/src/guardrails/live-outbound-gate.js +222 -0
- package/esm/src/guardrails/mod.d.ts +30 -6
- package/esm/src/guardrails/mod.js +20 -5
- package/esm/src/guardrails/network.d.ts +19 -0
- package/esm/src/guardrails/network.js +234 -0
- package/esm/src/guardrails/policy.d.ts +35 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +51 -0
- package/esm/src/guardrails/progressive-yield.js +98 -0
- package/esm/src/guardrails/quota.d.ts +17 -3
- package/esm/src/guardrails/quota.js +18 -4
- package/esm/src/guardrails/sanitize.d.ts +45 -19
- package/esm/src/guardrails/sanitize.js +177 -94
- package/esm/src/guardrails/sensitive.js +2 -1
- package/esm/src/guardrails/serialize.d.ts +35 -0
- package/esm/src/guardrails/serialize.js +58 -0
- package/esm/src/guardrails/testing.d.ts +17 -0
- package/esm/src/guardrails/testing.js +13 -0
- package/esm/src/guardrails/theorum-error.d.ts +12 -0
- package/esm/src/guardrails/theorum-error.js +15 -0
- package/esm/src/guardrails/tool-directives.d.ts +48 -0
- package/esm/src/guardrails/tool-directives.js +124 -0
- package/esm/src/guardrails/tool-result.d.ts +93 -0
- package/esm/src/guardrails/tool-result.js +276 -0
- package/esm/src/guardrails/types.d.ts +291 -0
- package/esm/src/guardrails/types.js +72 -0
- package/esm/src/host/client-turn.d.ts +19 -0
- package/esm/src/host/client-turn.js +36 -0
- package/esm/src/host/mint-trace.d.ts +1 -1
- package/esm/src/host/mod.d.ts +5 -3
- package/esm/src/host/mod.js +4 -3
- package/esm/src/kernel/auth/crypto.d.ts +42 -0
- package/esm/src/kernel/auth/crypto.js +106 -0
- package/esm/src/kernel/auth/mod.d.ts +11 -0
- package/esm/src/kernel/auth/mod.js +11 -0
- package/esm/src/kernel/auth/oauth.d.ts +47 -0
- package/esm/src/kernel/auth/oauth.js +278 -0
- package/esm/src/kernel/auth/types.d.ts +133 -0
- package/esm/src/kernel/auth/types.js +13 -0
- package/esm/src/kernel/engine/delta.d.ts +24 -2
- package/esm/src/kernel/engine/delta.js +478 -39
- package/esm/src/kernel/engine/live-inbound.d.ts +21 -0
- package/esm/src/kernel/engine/live-inbound.js +31 -0
- package/esm/src/kernel/engine/live-ingress.d.ts +19 -0
- package/esm/src/kernel/engine/live-ingress.js +47 -0
- package/esm/src/kernel/engine/repair.js +13 -12
- package/esm/src/kernel/engine/runner/gates.d.ts +1 -1
- package/esm/src/kernel/engine/runner/gates.js +130 -43
- package/esm/src/kernel/engine/runner/mod.d.ts +6 -4
- package/esm/src/kernel/engine/runner/mod.js +192 -53
- package/esm/src/kernel/engine/runner/schema-validation.js +3 -3
- package/esm/src/kernel/engine/runner/stages.d.ts +39 -0
- package/esm/src/kernel/engine/runner/stages.js +89 -0
- package/esm/src/kernel/engine/runner/state.d.ts +31 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +1 -1
- package/esm/src/kernel/engine/runner/steps.js +244 -43
- package/esm/src/kernel/engine/runner/stream.d.ts +9 -3
- package/esm/src/kernel/engine/runner/stream.js +140 -44
- package/esm/src/kernel/engine/session/mod.d.ts +25 -0
- package/esm/src/kernel/engine/session/mod.js +557 -0
- package/esm/src/kernel/interaction-parts.d.ts +14 -0
- package/esm/src/kernel/interaction-parts.js +23 -0
- package/esm/src/kernel/mod.d.ts +21 -10
- package/esm/src/kernel/mod.js +11 -8
- package/esm/src/kernel/profile-graph.d.ts +159 -0
- package/esm/src/kernel/profile-graph.js +156 -0
- package/esm/src/kernel/registry/attachments.d.ts +12 -10
- package/esm/src/kernel/registry/attachments.js +33 -27
- package/esm/src/kernel/registry/catalog.d.ts +25 -24
- package/esm/src/kernel/registry/catalog.js +60 -101
- package/esm/src/kernel/registry/ingress.d.ts +9 -4
- package/esm/src/kernel/registry/ingress.js +97 -75
- package/esm/src/kernel/registry/profile-outputs.d.ts +4 -0
- package/esm/src/kernel/registry/profile-outputs.js +8 -0
- package/esm/src/kernel/registry/profiles.d.ts +55 -12
- package/esm/src/kernel/registry/profiles.js +413 -73
- package/esm/src/kernel/registry/provider-request.js +13 -7
- package/esm/src/kernel/registry/resolve.d.ts +8 -8
- package/esm/src/kernel/registry/resolve.js +169 -154
- package/esm/src/kernel/registry/schemas.js +1 -1
- package/esm/src/kernel/registry/sole-model.d.ts +8 -0
- package/esm/src/kernel/registry/sole-model.js +10 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +10 -0
- package/esm/src/kernel/registry/system-prompt.js +40 -0
- package/esm/src/kernel/registry/system-role.d.ts +8 -0
- package/esm/src/kernel/registry/system-role.js +14 -0
- package/esm/src/kernel/registry/vault.d.ts +12 -7
- package/esm/src/kernel/registry/vault.js +32 -10
- package/esm/src/kernel/schema.d.ts +231 -0
- package/esm/src/kernel/schema.js +607 -0
- package/esm/src/kernel/stages.d.ts +175 -0
- package/esm/src/kernel/stages.js +476 -0
- package/esm/src/kernel/stop.d.ts +78 -19
- package/esm/src/kernel/stop.js +51 -16
- package/esm/src/kernel/tools/events.d.ts +41 -0
- package/esm/src/kernel/tools/events.js +71 -0
- package/esm/src/kernel/tools/execute.d.ts +84 -0
- package/esm/src/kernel/tools/execute.js +614 -0
- package/esm/src/kernel/tools/harness.d.ts +8 -0
- package/esm/src/kernel/tools/harness.js +46 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +101 -0
- package/esm/src/kernel/tools/mod.d.ts +13 -0
- package/esm/src/kernel/tools/mod.js +11 -0
- package/esm/src/kernel/tools/permission.d.ts +15 -0
- package/esm/src/kernel/tools/permission.js +47 -0
- package/esm/src/kernel/tools/project.d.ts +12 -0
- package/esm/src/kernel/tools/project.js +36 -0
- package/esm/src/kernel/tools/registry.d.ts +23 -0
- package/esm/src/kernel/tools/registry.js +81 -0
- package/esm/src/kernel/tools/remote.d.ts +94 -0
- package/esm/src/kernel/tools/remote.js +577 -0
- package/esm/src/kernel/tools/resolve.d.ts +39 -0
- package/esm/src/kernel/tools/resolve.js +283 -0
- package/esm/src/kernel/tools/schema.d.ts +15 -0
- package/esm/src/kernel/tools/schema.js +176 -0
- package/esm/src/kernel/tools/stage-run.d.ts +105 -0
- package/esm/src/kernel/tools/stage-run.js +155 -0
- package/esm/src/kernel/tools/types.d.ts +394 -0
- package/esm/src/kernel/tools/types.js +9 -0
- package/esm/src/kernel/types.d.ts +540 -256
- package/esm/src/kernel/util/find-last.d.ts +2 -0
- package/esm/src/kernel/util/find-last.js +10 -0
- package/esm/src/observability/destinations.d.ts +31 -0
- package/esm/src/observability/destinations.js +67 -0
- package/esm/src/observability/mod.d.ts +10 -3
- package/esm/src/observability/mod.js +6 -2
- package/esm/src/observability/policy.d.ts +27 -0
- package/esm/src/observability/policy.js +80 -0
- package/esm/src/observability/resolve-policy.d.ts +16 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/trace-attach.d.ts +8 -4
- package/esm/src/observability/trace-attach.js +50 -29
- package/esm/src/observability/trace-record.d.ts +23 -13
- package/esm/src/observability/trace-record.js +96 -39
- package/esm/src/observability/trace-sink.d.ts +19 -0
- package/esm/src/observability/trace-sink.js +10 -0
- package/esm/src/observability/trace-usage.d.ts +10 -3
- package/esm/src/observability/trace-usage.js +70 -17
- package/esm/src/observability/trace.d.ts +18 -7
- package/esm/src/observability/trace.js +34 -17
- package/esm/src/observability/types.d.ts +113 -0
- package/esm/src/observability/types.js +11 -0
- package/esm/src/presets/google/speech-voices.d.ts +11 -0
- package/esm/src/presets/google/speech-voices.js +41 -0
- package/esm/src/presets/google.d.ts +36 -24
- package/esm/src/presets/google.js +50 -63
- package/esm/src/presets/mod.d.ts +2 -2
- package/esm/src/presets/mod.js +1 -1
- package/esm/src/providers/create-provider.d.ts +20 -17
- package/esm/src/providers/create-provider.js +72 -26
- package/esm/src/providers/google/interactions/framing.d.ts +23 -0
- package/esm/src/providers/google/interactions/framing.js +269 -0
- package/esm/src/providers/google/interactions/mod.d.ts +7 -0
- package/esm/src/providers/google/interactions/mod.js +7 -0
- package/esm/src/providers/google/interactions/stream.d.ts +83 -0
- package/esm/src/providers/google/interactions/stream.js +588 -0
- package/esm/src/providers/google/keys.d.ts +26 -0
- package/esm/src/providers/{keys.js → google/keys.js} +19 -31
- package/esm/src/providers/google/live/framing.d.ts +49 -0
- package/esm/src/providers/google/live/framing.js +552 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +6 -0
- package/esm/src/providers/google/live/openapi-schema.js +46 -0
- package/esm/src/providers/google/live/session.d.ts +25 -0
- package/esm/src/providers/google/live/session.js +134 -0
- package/esm/src/providers/google/live/stream.d.ts +45 -0
- package/esm/src/providers/google/live/stream.js +214 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/local/local.d.ts +30 -0
- package/esm/src/providers/{local.js → local/local.js} +66 -126
- package/esm/src/providers/local/mod.d.ts +9 -0
- package/esm/src/providers/local/mod.js +9 -0
- package/esm/src/providers/mod.d.ts +6 -3
- package/esm/src/providers/mod.js +3 -1
- package/esm/src/providers/openrouter/cache-control.d.ts +24 -0
- package/esm/src/providers/openrouter/cache-control.js +23 -0
- package/esm/src/providers/openrouter/chat.d.ts +107 -0
- package/esm/src/providers/{openrouter.js → openrouter/chat.js} +117 -231
- package/esm/src/providers/openrouter/image.d.ts +34 -0
- package/esm/src/providers/openrouter/image.js +275 -0
- package/esm/src/providers/openrouter/openai/chat-payload.d.ts +24 -0
- package/esm/src/providers/openrouter/openai/chat-payload.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +53 -0
- package/esm/src/providers/openrouter/openai/compat.js +213 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +18 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +90 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +22 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +122 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +9 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +24 -0
- package/esm/src/providers/openrouter/speech.d.ts +23 -0
- package/esm/src/providers/{speech.js → openrouter/speech.js} +32 -55
- package/esm/src/providers/probe.d.ts +1 -0
- package/esm/src/providers/probe.js +22 -0
- package/esm/src/providers/shared/pcm.d.ts +12 -0
- package/esm/src/providers/{pcm.js → shared/pcm.js} +16 -3
- package/esm/src/providers/shared/sse.d.ts +18 -0
- package/esm/src/providers/shared/sse.js +87 -0
- package/esm/src/providers/shared/tool-args.d.ts +17 -0
- package/esm/src/providers/shared/tool-args.js +45 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +5 -0
- package/esm/src/providers/{google-tap.js → shared/upstream-tap.js} +4 -7
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/{gemini-tape.js → shared/upstream-tape.js} +12 -22
- package/esm/src/providers/types.d.ts +27 -0
- package/esm/src/providers/types.js +1 -0
- package/package.json +11 -7
- package/docs/cli.md +0 -97
- package/docs/guardrails.md +0 -178
- package/docs/host.md +0 -97
- package/docs/kernel.md +0 -404
- package/docs/observability.md +0 -105
- package/docs/openrouter.md +0 -125
- package/docs/presets-google.md +0 -91
- package/docs/presets.md +0 -88
- package/docs/providers.md +0 -202
- package/docs/streaming.md +0 -96
- package/esm/src/kernel/engine/boundary.d.ts +0 -10
- package/esm/src/kernel/engine/boundary.js +0 -55
- package/esm/src/kernel/engine/runner/tools.d.ts +0 -13
- package/esm/src/kernel/engine/runner/tools.js +0 -198
- package/esm/src/kernel/registry/tools.d.ts +0 -12
- package/esm/src/kernel/registry/tools.js +0 -36
- package/esm/src/providers/expose-for-tests.d.ts +0 -1
- package/esm/src/providers/expose-for-tests.js +0 -25
- package/esm/src/providers/gemini-tape.d.ts +0 -2
- package/esm/src/providers/google-tap.d.ts +0 -3
- package/esm/src/providers/interactions.d.ts +0 -5
- package/esm/src/providers/interactions.js +0 -169
- package/esm/src/providers/keys.d.ts +0 -19
- package/esm/src/providers/local.d.ts +0 -29
- package/esm/src/providers/openrouter-mod.d.ts +0 -13
- package/esm/src/providers/openrouter-mod.js +0 -12
- package/esm/src/providers/openrouter-payload.d.ts +0 -39
- package/esm/src/providers/openrouter-payload.js +0 -195
- package/esm/src/providers/openrouter.d.ts +0 -15
- package/esm/src/providers/pcm.d.ts +0 -7
- package/esm/src/providers/provider.d.ts +0 -15
- package/esm/src/providers/provider.js +0 -202
- package/esm/src/providers/speech.d.ts +0 -23
- package/esm/src/providers/sse.d.ts +0 -7
- package/esm/src/providers/sse.js +0 -55
- package/esm/src/streaming/mod.d.ts +0 -9
- package/esm/src/streaming/mod.js +0 -8
- /package/esm/src/{streaming → host}/readStreamingJsonStringField.d.ts +0 -0
- /package/esm/src/{streaming → host}/readStreamingJsonStringField.js +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct entry for local OpenAI-compat providers (Ollama, vLLM, etc.).
|
|
3
|
+
* Importing this module loads the local adapter graph — prefer `createProvider`
|
|
4
|
+
* when routing from a profile unless you intentionally bypass the factory.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import "../../../_dnt.polyfills.js";
|
|
9
|
+
export { createLocalProvider, DEFAULT_LOCAL_BASE_URL } from './local.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct entry for local OpenAI-compat providers (Ollama, vLLM, etc.).
|
|
3
|
+
* Importing this module loads the local adapter graph — prefer `createProvider`
|
|
4
|
+
* when routing from a profile unless you intentionally bypass the factory.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import "../../../_dnt.polyfills.js";
|
|
9
|
+
export { createLocalProvider, DEFAULT_LOCAL_BASE_URL } from './local.js';
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* Host apps should use `createProvider(profile, options)` — the single door.
|
|
5
5
|
* Credentials are always supplied by the host application.
|
|
6
6
|
*
|
|
7
|
+
* For direct local adapter access (bypassing the factory), import
|
|
8
|
+
* `@theorum/core/providers/local`.
|
|
9
|
+
*
|
|
7
10
|
* @module
|
|
8
11
|
*/
|
|
9
12
|
import "../../_dnt.polyfills.js";
|
|
13
|
+
export type { KeyVault } from '../kernel/types.js';
|
|
10
14
|
export type { CreateProviderOptions } from './create-provider.js';
|
|
11
15
|
export { createProvider } from './create-provider.js';
|
|
12
|
-
export type { GeminiTransport
|
|
13
|
-
export type { LocalProviderConfig } from './
|
|
14
|
-
export { createLocalProvider, DEFAULT_LOCAL_BASE_URL } from './local.js';
|
|
16
|
+
export type { GeminiTransport } from './google/keys.js';
|
|
17
|
+
export type { LocalProviderConfig, OpenAiGatewayConfig } from './types.js';
|
package/esm/src/providers/mod.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* Host apps should use `createProvider(profile, options)` — the single door.
|
|
5
5
|
* Credentials are always supplied by the host application.
|
|
6
6
|
*
|
|
7
|
+
* For direct local adapter access (bypassing the factory), import
|
|
8
|
+
* `@theorum/core/providers/local`.
|
|
9
|
+
*
|
|
7
10
|
* @module
|
|
8
11
|
*/
|
|
9
12
|
import "../../_dnt.polyfills.js";
|
|
10
13
|
export { createProvider } from './create-provider.js';
|
|
11
|
-
export { createLocalProvider, DEFAULT_LOCAL_BASE_URL } from './local.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OpenRouter `cache_control` directive from a profile CacheSpec.
|
|
3
|
+
*
|
|
4
|
+
* Used by AI SDK `providerOptionsFor` and REST `toOpenAiChatPayload` so both
|
|
5
|
+
* paths share one wire shape.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { CacheTtl } from '../../kernel/schema.js';
|
|
10
|
+
import type { CacheSpec } from '../../kernel/types.js';
|
|
11
|
+
/** Anthropic / OpenRouter ephemeral cache_control object. */
|
|
12
|
+
export interface CacheControlDirective {
|
|
13
|
+
type: 'ephemeral';
|
|
14
|
+
ttl?: CacheTtl;
|
|
15
|
+
}
|
|
16
|
+
/** Map a profile CacheSpec to the upstream cache_control body fragment. */
|
|
17
|
+
export declare function cacheControlFromSpec(spec: CacheSpec): CacheControlDirective;
|
|
18
|
+
/**
|
|
19
|
+
* Plain JSON object for AI SDK `providerOptions` (needs string index signature).
|
|
20
|
+
* Same values as `cacheControlFromSpec`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cacheControlJson(spec: CacheSpec): {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OpenRouter `cache_control` directive from a profile CacheSpec.
|
|
3
|
+
*
|
|
4
|
+
* Used by AI SDK `providerOptionsFor` and REST `toOpenAiChatPayload` so both
|
|
5
|
+
* paths share one wire shape.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Map a profile CacheSpec to the upstream cache_control body fragment. */
|
|
10
|
+
export function cacheControlFromSpec(spec) {
|
|
11
|
+
if (spec.ttl) {
|
|
12
|
+
return { type: 'ephemeral', ttl: spec.ttl };
|
|
13
|
+
}
|
|
14
|
+
return { type: 'ephemeral' };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Plain JSON object for AI SDK `providerOptions` (needs string index signature).
|
|
18
|
+
* Same values as `cacheControlFromSpec`.
|
|
19
|
+
*/
|
|
20
|
+
export function cacheControlJson(spec) {
|
|
21
|
+
const directive = cacheControlFromSpec(spec);
|
|
22
|
+
return directive.ttl ? { type: directive.type, ttl: directive.ttl } : { type: directive.type };
|
|
23
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRouter provider adapter powered by Vercel AI SDK Core.
|
|
3
|
+
*
|
|
4
|
+
* THEORUM keeps the public `ModelProvider` and `TurnEvent` contract; AI SDK
|
|
5
|
+
* owns the OpenRouter call, stream parsing, provider compatibility, and tool
|
|
6
|
+
* call normalization. Message assembly delegates to `openai/sdk-messages.ts`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type ModelMessage, type TextStreamPart, type ToolSet } from 'ai';
|
|
11
|
+
import type { ModelProvider, ProviderCompleteRequest, TurnEvent, TurnTokens, WireFunctionTool } from '../../kernel/types.js';
|
|
12
|
+
import type { OpenAiGatewayConfig } from '../types.js';
|
|
13
|
+
export interface StreamAccumulator {
|
|
14
|
+
text: string;
|
|
15
|
+
evidenceSeen: boolean;
|
|
16
|
+
emittedTokens: boolean;
|
|
17
|
+
errored: boolean;
|
|
18
|
+
finishReason?: string | null;
|
|
19
|
+
nativeFinishReason?: string | null;
|
|
20
|
+
}
|
|
21
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
22
|
+
[key: string]: JsonValue;
|
|
23
|
+
};
|
|
24
|
+
export type ProviderOptions = Record<string, {
|
|
25
|
+
[key: string]: JsonValue;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function trimApiKey(explicitKey?: string): string | undefined;
|
|
28
|
+
export declare function createAccumulator(): StreamAccumulator;
|
|
29
|
+
export declare function sourceEvent(part: {
|
|
30
|
+
sourceType?: string;
|
|
31
|
+
title?: string | null;
|
|
32
|
+
url?: string;
|
|
33
|
+
}): TurnEvent;
|
|
34
|
+
export declare function schemaForTool(decl: WireFunctionTool): Record<string, unknown>;
|
|
35
|
+
export declare function buildTools(wireTools?: WireFunctionTool[]): ToolSet | undefined;
|
|
36
|
+
export declare function tokensFromUsage(usage: {
|
|
37
|
+
inputTokens?: number | null;
|
|
38
|
+
outputTokens?: number | null;
|
|
39
|
+
totalTokens?: number | null;
|
|
40
|
+
inputTokenDetails?: {
|
|
41
|
+
cacheReadTokens?: number | null;
|
|
42
|
+
cacheWriteTokens?: number | null;
|
|
43
|
+
} | null;
|
|
44
|
+
cachedInputTokens?: number | null;
|
|
45
|
+
}): TurnTokens | undefined;
|
|
46
|
+
export declare function rawRecord(value: unknown): Record<string, unknown> | undefined;
|
|
47
|
+
export declare function stringArray(value: unknown): string[] | undefined;
|
|
48
|
+
export declare function metadataRecord(raw: Record<string, unknown>, key: string): Record<string, unknown> | undefined;
|
|
49
|
+
export declare function citationCandidates(raw: Record<string, unknown>): unknown[];
|
|
50
|
+
export declare function nestedCitations(raw: Record<string, unknown>): string[] | undefined;
|
|
51
|
+
export declare function metadataAnnotations(raw: Record<string, unknown>): unknown[] | undefined;
|
|
52
|
+
export declare function evidenceFromMetadata(metadata: unknown, acc: StreamAccumulator): TurnEvent | undefined;
|
|
53
|
+
export declare function toolArguments(input: unknown): Record<string, unknown> | undefined;
|
|
54
|
+
export declare function toolResultData(output: unknown): Record<string, unknown> | undefined;
|
|
55
|
+
export declare function rawThoughtEvent(raw: Record<string, unknown>): TurnEvent | undefined;
|
|
56
|
+
export declare function rawChoiceMessageEvidence(raw: Record<string, unknown>, acc: StreamAccumulator): TurnEvent | undefined;
|
|
57
|
+
export declare function rawEvents(raw: unknown, acc: StreamAccumulator): TurnEvent[];
|
|
58
|
+
export declare function toolCallEvent(part: {
|
|
59
|
+
toolName: string;
|
|
60
|
+
toolCallId: string;
|
|
61
|
+
input?: unknown;
|
|
62
|
+
}): TurnEvent;
|
|
63
|
+
export declare function toolResultEvent(part: {
|
|
64
|
+
toolName: string;
|
|
65
|
+
toolCallId: string;
|
|
66
|
+
input?: unknown;
|
|
67
|
+
output?: unknown;
|
|
68
|
+
}): TurnEvent;
|
|
69
|
+
export declare function tokenEvent(part: {
|
|
70
|
+
totalUsage: {
|
|
71
|
+
inputTokens?: number | null;
|
|
72
|
+
outputTokens?: number | null;
|
|
73
|
+
totalTokens?: number | null;
|
|
74
|
+
inputTokenDetails?: {
|
|
75
|
+
cacheReadTokens?: number | null;
|
|
76
|
+
cacheWriteTokens?: number | null;
|
|
77
|
+
} | null;
|
|
78
|
+
cachedInputTokens?: number | null;
|
|
79
|
+
};
|
|
80
|
+
}): TurnEvent | undefined;
|
|
81
|
+
export declare function providerMetadataEvent(part: TextStreamPart<ToolSet>, acc: StreamAccumulator): TurnEvent | undefined;
|
|
82
|
+
export declare function eventFromPart(part: TextStreamPart<ToolSet>, acc: StreamAccumulator): TurnEvent[];
|
|
83
|
+
export declare function primaryEventFromPart(part: TextStreamPart<ToolSet>, acc: StreamAccumulator): TurnEvent | undefined;
|
|
84
|
+
export declare function finishEvent(part: {
|
|
85
|
+
finishReason?: string | null;
|
|
86
|
+
totalUsage?: {
|
|
87
|
+
inputTokens?: number | null;
|
|
88
|
+
outputTokens?: number | null;
|
|
89
|
+
totalTokens?: number | null;
|
|
90
|
+
inputTokenDetails?: {
|
|
91
|
+
cacheReadTokens?: number | null;
|
|
92
|
+
cacheWriteTokens?: number | null;
|
|
93
|
+
} | null;
|
|
94
|
+
cachedInputTokens?: number | null;
|
|
95
|
+
};
|
|
96
|
+
}, acc: StreamAccumulator): TurnEvent | undefined;
|
|
97
|
+
export declare function finalEvents(req: ProviderCompleteRequest, acc: StreamAccumulator): Generator<TurnEvent>;
|
|
98
|
+
/** System via instructions XOR a cache-marked system message — never both. */
|
|
99
|
+
export declare function systemDelivery(req: ProviderCompleteRequest): {
|
|
100
|
+
instructions?: string;
|
|
101
|
+
systemMessage?: ModelMessage;
|
|
102
|
+
};
|
|
103
|
+
export declare function missingOpenRouterKey(): TurnEvent;
|
|
104
|
+
export declare function providerOptionsFor(req: ProviderCompleteRequest): ProviderOptions | undefined;
|
|
105
|
+
/** Create a `ModelProvider` backed by OpenRouter through AI SDK Core. */
|
|
106
|
+
export declare function createOpenRouterProvider(config?: OpenAiGatewayConfig): ModelProvider;
|
|
107
|
+
export type { OpenAiGatewayConfig };
|