theorum 0.1.13 → 0.1.15
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 +83 -4
- package/docs/cli.md +97 -0
- package/docs/guardrails.md +178 -0
- package/docs/host.md +97 -0
- package/docs/kernel.md +404 -0
- package/docs/observability.md +105 -0
- package/docs/openrouter.md +125 -0
- package/docs/presets-google.md +91 -0
- package/docs/presets.md +88 -0
- package/docs/providers.md +202 -0
- package/docs/streaming.md +96 -0
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/src/kernel/engine/delta.js +92 -0
- package/esm/src/kernel/mod.d.ts +1 -1
- package/esm/src/kernel/mod.js +1 -1
- package/esm/src/kernel/registry/catalog.d.ts +3 -3
- package/esm/src/kernel/registry/catalog.js +5 -5
- package/esm/src/kernel/registry/ingress.js +6 -6
- package/esm/src/kernel/types.d.ts +3 -3
- package/esm/src/providers/local.d.ts +1 -1
- package/esm/src/providers/local.js +1 -1
- package/esm/src/providers/provider.js +26 -0
- package/package.json +1 -1
- package/docs/COMPACTION.md +0 -227
- package/docs/SECRETS.md +0 -65
- package/docs/STOP.md +0 -85
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Google preset (`theorum/presets/google`)
|
|
2
|
+
|
|
3
|
+
Google / Gemini convenience pack: grounding builtins plus typed vocabularies
|
|
4
|
+
for image and speech-adjacent profile fields.
|
|
5
|
+
|
|
6
|
+
## Export
|
|
7
|
+
|
|
8
|
+
| Field | Value |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| Import | `theorum/presets/google` / `jsr:@theorum/core/presets/google` |
|
|
11
|
+
| Module | `src/presets/google.ts` |
|
|
12
|
+
|
|
13
|
+
## Ownership
|
|
14
|
+
|
|
15
|
+
| Path | Role |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `src/presets/google.ts` | Google builtins + vocabularies |
|
|
18
|
+
|
|
19
|
+
## Builtins
|
|
20
|
+
|
|
21
|
+
`registerGooglePreset()` registers:
|
|
22
|
+
|
|
23
|
+
| Id | Notes |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `googleSearch` | Interactions `google_search`; OpenRouter plugin `web` |
|
|
26
|
+
| `googleMaps` | Interactions `google_maps`; conflicts with `googleSearch` and `urlContext` |
|
|
27
|
+
| `urlContext` | Interactions `url_context` |
|
|
28
|
+
|
|
29
|
+
All are `kind: 'builtin'` with `ui: true`. Profiles must allowlist ids they use;
|
|
30
|
+
`conflictsWith` drops maps when search/urlContext are also requested.
|
|
31
|
+
|
|
32
|
+
## Vocabularies
|
|
33
|
+
|
|
34
|
+
Constants (and matching types) for host profile authoring:
|
|
35
|
+
|
|
36
|
+
| Constant | Purpose |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `GOOGLE_IMAGE_INPUT_MIMES` | png / jpeg / webp / heic / heif |
|
|
39
|
+
| `GOOGLE_VOICE_INPUT_MIMES` | webm / wav / mpeg / mp4 |
|
|
40
|
+
| `GOOGLE_IMAGE_ASPECT_RATIOS` / `GOOGLE_IMAGE_SIZES` | Image output pins |
|
|
41
|
+
| `GOOGLE_SPEECH_VOICES` | TTS voice names for `outputs.speech.voice` |
|
|
42
|
+
| `GoogleImageAspectRatio`, `GoogleImageInputMime`, `GoogleImageSize`, `GoogleVoiceInputMime` | Typed vocabulary unions |
|
|
43
|
+
| `GoogleImagePins`, `GoogleSpeechPins`, `GoogleSpeechVoice` | Typed pins assignable to kernel specs |
|
|
44
|
+
|
|
45
|
+
Kernel types stay stringly; these packs make Google hosts typed when they opt in.
|
|
46
|
+
|
|
47
|
+
## Exported API
|
|
48
|
+
|
|
49
|
+
| Export | Role |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `registerGooglePreset` | Register builtins into catalog |
|
|
52
|
+
| `GOOGLE_BUILTIN_TOOLS` | Static catalog entries |
|
|
53
|
+
| `GOOGLE_IMAGE_ASPECT_RATIOS`, `GOOGLE_IMAGE_INPUT_MIMES`, `GOOGLE_IMAGE_SIZES`, `GOOGLE_VOICE_INPUT_MIMES`, `GOOGLE_SPEECH_VOICES` | Typed profile authoring constants |
|
|
54
|
+
| `GoogleImageAspectRatio`, `GoogleImageInputMime`, `GoogleImageSize`, `GoogleVoiceInputMime`, `GoogleImagePins`, `GoogleSpeechPins`, `GoogleSpeechVoice` | Typed pins and vocabularies |
|
|
55
|
+
|
|
56
|
+
```theorum-evidence
|
|
57
|
+
{
|
|
58
|
+
"sections": {
|
|
59
|
+
"Export": {
|
|
60
|
+
"supports": [
|
|
61
|
+
{ "kind": "source", "path": "src/presets/google.ts" },
|
|
62
|
+
{ "kind": "config", "path": "package.json" }
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"Ownership": {
|
|
66
|
+
"supports": [
|
|
67
|
+
{ "kind": "source", "path": "src/presets/google.ts" },
|
|
68
|
+
{ "kind": "graph", "path": "docs/_map.mjs" }
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"Builtins": {
|
|
72
|
+
"supports": [
|
|
73
|
+
{ "kind": "source", "path": "src/presets/google.ts" },
|
|
74
|
+
{ "kind": "contract_test", "path": "tests/kernel/theorum.test.ts" }
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"Vocabularies": {
|
|
78
|
+
"supports": [
|
|
79
|
+
{ "kind": "source", "path": "src/presets/google.ts" },
|
|
80
|
+
{ "kind": "contract_test", "path": "tests/kernel/theorum.test.ts" }
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
"Exported API": {
|
|
84
|
+
"supports": [
|
|
85
|
+
{ "kind": "source", "path": "src/presets/google.ts" },
|
|
86
|
+
{ "kind": "source", "path": "src/presets/mod.ts" }
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
package/docs/presets.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Presets (`theorum/presets`)
|
|
2
|
+
|
|
3
|
+
Optional convenience packs. Presets register host-convenience catalogs
|
|
4
|
+
(provider builtins, media vocabularies) without baking product opinions into the
|
|
5
|
+
kernel.
|
|
6
|
+
|
|
7
|
+
## Export
|
|
8
|
+
|
|
9
|
+
| Field | Value |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Import | `theorum/presets` / `jsr:@theorum/core/presets` |
|
|
12
|
+
| Module | `src/presets/mod.ts` |
|
|
13
|
+
|
|
14
|
+
## Ownership
|
|
15
|
+
|
|
16
|
+
| Path | Role |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `src/presets/mod.ts` | Barrel re-exporting the Google pack |
|
|
19
|
+
| `src/presets/google.ts` | Documented in [`GOOGLE.md`](./GOOGLE.md) |
|
|
20
|
+
|
|
21
|
+
## Role in the package
|
|
22
|
+
|
|
23
|
+
| Concern | Kernel | Preset |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| Tool ids | `string` allowlist | Registers `googleSearch`, `googleMaps`, `urlContext` |
|
|
26
|
+
| Image/speech pins | Open `string` fields | Typed constants (`GOOGLE_IMAGE_SIZES`, voices, …) |
|
|
27
|
+
| Registration | `registerTools` API | `registerGooglePreset()` at host startup |
|
|
28
|
+
|
|
29
|
+
Call preset registration **before** registering profiles that allowlist preset
|
|
30
|
+
builtins. Import `theorum/presets/google` when you only need the Google pack.
|
|
31
|
+
|
|
32
|
+
Presets are optional — the kernel runs without them when hosts register their
|
|
33
|
+
own tools and vocabularies directly via `registerTools`.
|
|
34
|
+
|
|
35
|
+
## When to use
|
|
36
|
+
|
|
37
|
+
| Use preset | Skip preset |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| Google Gemini hosts wanting typed pins + search/maps/url builtins | Custom tool catalog entirely host-owned |
|
|
40
|
+
| Quick start matching Google Interactions wire types | Non-Google providers only |
|
|
41
|
+
|
|
42
|
+
## Exported API
|
|
43
|
+
|
|
44
|
+
This barrel re-exports the Google pack:
|
|
45
|
+
|
|
46
|
+
| Export | Role |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `registerGooglePreset` | Register Google builtins into `CATALOG` |
|
|
49
|
+
| `GOOGLE_BUILTIN_TOOLS` | Catalog entries |
|
|
50
|
+
| `GOOGLE_IMAGE_ASPECT_RATIOS`, `GOOGLE_IMAGE_INPUT_MIMES`, `GOOGLE_IMAGE_SIZES`, `GOOGLE_VOICE_INPUT_MIMES` | Profile authoring constants |
|
|
51
|
+
| `GoogleImageAspectRatio`, `GoogleImageInputMime`, `GoogleImagePins`, `GoogleImageSize`, `GoogleVoiceInputMime` | Typed pins and vocabularies |
|
|
52
|
+
|
|
53
|
+
```theorum-evidence
|
|
54
|
+
{
|
|
55
|
+
"sections": {
|
|
56
|
+
"Export": {
|
|
57
|
+
"supports": [
|
|
58
|
+
{ "kind": "source", "path": "src/presets/mod.ts" },
|
|
59
|
+
{ "kind": "config", "path": "package.json" }
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"Ownership": {
|
|
63
|
+
"supports": [
|
|
64
|
+
{ "kind": "source", "path": "src/presets/mod.ts" },
|
|
65
|
+
{ "kind": "graph", "path": "docs/_map.mjs" }
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"Role in the package": {
|
|
69
|
+
"supports": [
|
|
70
|
+
{ "kind": "source", "path": "src/presets/mod.ts" },
|
|
71
|
+
{ "kind": "contract_test", "path": "tests/kernel/theorum.test.ts" }
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"When to use": {
|
|
75
|
+
"supports": [
|
|
76
|
+
{ "kind": "source", "path": "src/presets/google.ts" },
|
|
77
|
+
{ "kind": "contract_test", "path": "tests/kernel/theorum.test.ts" }
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"Exported API": {
|
|
81
|
+
"supports": [
|
|
82
|
+
{ "kind": "source", "path": "src/presets/mod.ts" },
|
|
83
|
+
{ "kind": "doc", "path": "src/presets/GOOGLE.md" }
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Providers (`theorum/providers`)
|
|
2
|
+
|
|
3
|
+
Single door for constructing a `ModelProvider` bound to a profile. Credentials
|
|
4
|
+
and runtime endpoints are always host-supplied arguments — THEORUM does not read
|
|
5
|
+
environment variables and does not ship `.env` files.
|
|
6
|
+
|
|
7
|
+
## Export
|
|
8
|
+
|
|
9
|
+
| Field | Value |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Import | `theorum/providers` / `jsr:@theorum/core/providers` |
|
|
12
|
+
| Module | `src/providers/mod.ts` |
|
|
13
|
+
| Also on | Root `theorum` re-exports `createProvider` |
|
|
14
|
+
|
|
15
|
+
## Ownership
|
|
16
|
+
|
|
17
|
+
Owns every module under `src/providers/` **except** OpenRouter-specific modules
|
|
18
|
+
in [`OPENROUTER.md`](./OPENROUTER.md).
|
|
19
|
+
|
|
20
|
+
| Module | Role (internal) |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `create-provider.ts` | Public factory + lazy OpenRouter chat wrapper |
|
|
23
|
+
| `provider.ts` | Google Interactions streaming adapter |
|
|
24
|
+
| `interactions.ts` | Interactions payload / step wiring |
|
|
25
|
+
| `speech.ts` | OpenRouter `/audio/speech` + Interactions audio paths |
|
|
26
|
+
| `local.ts` | OpenAI-compat SSE for Ollama / llama.cpp / vLLM / LM Studio |
|
|
27
|
+
| `keys.ts` | Gemini vault transport types |
|
|
28
|
+
| `sse.ts` | Shared SSE line parser |
|
|
29
|
+
| `pcm.ts` | PCM → WAV for Interactions speech output |
|
|
30
|
+
| `gemini-tape.ts` / `google-tap.ts` | Test / tap hooks (not public exports) |
|
|
31
|
+
| `expose-for-tests.ts` | `THEORUM_TEST_INTERNALS=1` gated test surface |
|
|
32
|
+
|
|
33
|
+
## Package boundary
|
|
34
|
+
|
|
35
|
+
| Rule | Detail |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| No `.env` in repo | Hosts pass credentials explicitly |
|
|
38
|
+
| No ambient env reads | `OLLAMA_HOST` resolved by host → `local.baseUrl` |
|
|
39
|
+
| No key templates | Business apps own secret storage |
|
|
40
|
+
| Traces | Host-injected on `runTurn`, not here |
|
|
41
|
+
|
|
42
|
+
## createProvider
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const provider = createProvider(profile, {
|
|
46
|
+
gemini: { vault: { freeA, freeB, freeC, paid }, fetch? },
|
|
47
|
+
openRouter: { apiKey, baseUrl?, siteUrl?, siteName?, fetch?, modelMap?, voice? },
|
|
48
|
+
local: { baseUrl?, fetch? },
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Routing table:
|
|
53
|
+
|
|
54
|
+
| protocol | provider | Requires | Transport |
|
|
55
|
+
| --- | --- | --- | --- |
|
|
56
|
+
| `geminiInteractions` | `google` | `options.gemini` | Interactions API (chat / image / speech) |
|
|
57
|
+
| `openAi` | `openrouter` | `options.openRouter` | Lazy chat adapter or `speech.ts` when `outputs.speech` |
|
|
58
|
+
| `openAi` | `local` | optional `options.local` | `POST /v1/chat/completions` SSE |
|
|
59
|
+
|
|
60
|
+
Errors:
|
|
61
|
+
|
|
62
|
+
- Missing credential block → `TheorumError` naming the required option.
|
|
63
|
+
- Unsupported pair → `TheorumError` with protocol/provider in the message.
|
|
64
|
+
|
|
65
|
+
OpenRouter Vercel AI SDK loads **only** on first `complete` for `openAi` +
|
|
66
|
+
`openrouter` chat. Google and local never import it.
|
|
67
|
+
|
|
68
|
+
## Google Interactions
|
|
69
|
+
|
|
70
|
+
`createInteractionsProvider(geminiTransport)` streams normalized `TurnEvent`s.
|
|
71
|
+
|
|
72
|
+
| Concern | Behavior |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| History | `user_input` / `model_output` steps |
|
|
75
|
+
| Multimodal | `image` / `audio` / `video` / `document` parts |
|
|
76
|
+
| Structured | `responseFormat` JSON schema when enforced |
|
|
77
|
+
| Output modes | Image / speech / structured are mutually exclusive |
|
|
78
|
+
| Tools | Catalog `interactionsType` + plugins |
|
|
79
|
+
| Grounding | Classic `grounding_metadata` **and** Interactions `google_search_result` / maps tool payloads (`search_suggestions` chips, annotations). Emits `grounding` (normalized) plus `evidence` with the raw tool payload so hosts can decide what to surface. |
|
|
80
|
+
| Stop | `turnStopFromInteractionStatus` on terminal status |
|
|
81
|
+
|
|
82
|
+
## Local provider
|
|
83
|
+
|
|
84
|
+
`createLocalProvider` / `DEFAULT_LOCAL_BASE_URL` (`http://127.0.0.1:11434`). Hosts
|
|
85
|
+
resolve `OLLAMA_HOST` (or similar) themselves and pass `baseUrl` here — THEORUM
|
|
86
|
+
does not read environment variables for local endpoints (see module header in
|
|
87
|
+
`local.ts`, not `docs/SECRETS.md`).
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
local: {
|
|
91
|
+
baseUrl: "http://127.0.0.1:11434", // no trailing slash
|
|
92
|
+
fetch: customFetch,
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- Raw `fetch` + `sse.ts` — no SDK.
|
|
97
|
+
- Accumulates streaming tool calls; maps `finish_reason` through
|
|
98
|
+
`turnStopFromOpenRouter`.
|
|
99
|
+
- Supports multimodal user content when the server accepts OpenAI-style parts.
|
|
100
|
+
|
|
101
|
+
## Speech roles
|
|
102
|
+
|
|
103
|
+
When `profile.outputs.speech` is defined and protocol/provider is OpenRouter
|
|
104
|
+
OpenAI, `createProvider` returns `createSpeechProvider`:
|
|
105
|
+
|
|
106
|
+
| Transport | Path | Notes |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| OpenAI | `/audio/speech` | `mp3` allowed via `response_format` |
|
|
109
|
+
| Interactions | audio `responseFormat` | PCM → WAV; `mp3` rejected at resolve |
|
|
110
|
+
|
|
111
|
+
Fallback `openRouter.voice` when `outputs.speech.voice` omitted.
|
|
112
|
+
|
|
113
|
+
## Gemini transport
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
createProvider(profile, {
|
|
117
|
+
gemini: { vault: { freeA, freeB, freeC, paid } },
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| Piece | Role |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `GeminiTransport` | Vault + optional `fetch` |
|
|
124
|
+
| Buckets | `freeA`, `freeB`, `freeC`, `paid` |
|
|
125
|
+
| Selection | `model.key` / `ModelSpec.key` / `keyBuiltins` |
|
|
126
|
+
|
|
127
|
+
Overflow to `paid` is host policy, not inferred here.
|
|
128
|
+
|
|
129
|
+
## Exported API
|
|
130
|
+
|
|
131
|
+
From `src/providers/mod.ts` only:
|
|
132
|
+
|
|
133
|
+
| Export | Kind |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| `createProvider` | function |
|
|
136
|
+
| `CreateProviderOptions` | type |
|
|
137
|
+
| `GeminiTransport`, `GeminiVault` | types |
|
|
138
|
+
| `createLocalProvider` | function |
|
|
139
|
+
| `LocalProviderConfig` | type |
|
|
140
|
+
| `DEFAULT_LOCAL_BASE_URL` | const |
|
|
141
|
+
|
|
142
|
+
```theorum-evidence
|
|
143
|
+
{
|
|
144
|
+
"sections": {
|
|
145
|
+
"Export": {
|
|
146
|
+
"supports": [
|
|
147
|
+
{ "kind": "source", "path": "src/providers/mod.ts" },
|
|
148
|
+
{ "kind": "config", "path": "package.json" }
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
"Ownership": {
|
|
152
|
+
"supports": [
|
|
153
|
+
{ "kind": "source", "path": "src/providers/mod.ts" },
|
|
154
|
+
{ "kind": "graph", "path": "docs/_map.mjs" }
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
"Package boundary": {
|
|
158
|
+
"supports": [
|
|
159
|
+
{ "kind": "source", "path": "src/providers/create-provider.ts" },
|
|
160
|
+
{ "kind": "contract_test", "path": "tests/providers/create-provider.test.ts" }
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
"createProvider": {
|
|
164
|
+
"supports": [
|
|
165
|
+
{ "kind": "source", "path": "src/providers/create-provider.ts" },
|
|
166
|
+
{ "kind": "contract_test", "path": "tests/providers/create-provider.test.ts" }
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
"Google Interactions": {
|
|
170
|
+
"supports": [
|
|
171
|
+
{ "kind": "source", "path": "src/providers/provider.ts" },
|
|
172
|
+
{ "kind": "source", "path": "src/providers/interactions.ts" },
|
|
173
|
+
{ "kind": "contract_test", "path": "tests/providers/interactions.test.ts" }
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
"Local provider": {
|
|
177
|
+
"supports": [
|
|
178
|
+
{ "kind": "source", "path": "src/providers/local.ts" },
|
|
179
|
+
{ "kind": "contract_test", "path": "tests/providers/local.test.ts" }
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
"Speech roles": {
|
|
183
|
+
"supports": [
|
|
184
|
+
{ "kind": "source", "path": "src/providers/speech.ts" },
|
|
185
|
+
{ "kind": "contract_test", "path": "tests/providers/speech.test.ts" }
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
"Gemini transport": {
|
|
189
|
+
"supports": [
|
|
190
|
+
{ "kind": "source", "path": "src/providers/keys.ts" },
|
|
191
|
+
{ "kind": "contract_test", "path": "tests/providers/keys.test.ts" }
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
"Exported API": {
|
|
195
|
+
"supports": [
|
|
196
|
+
{ "kind": "source", "path": "src/providers/mod.ts" },
|
|
197
|
+
{ "kind": "contract_test", "path": "tests/providers/create-provider.test.ts" }
|
|
198
|
+
]
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Streaming (`theorum/streaming`)
|
|
2
|
+
|
|
3
|
+
Structured-output streaming helpers and turn-stop classification re-exports for
|
|
4
|
+
hosts that want a narrow import without taking the full kernel barrel.
|
|
5
|
+
|
|
6
|
+
## Export
|
|
7
|
+
|
|
8
|
+
| Field | Value |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| Import | `theorum/streaming` / `jsr:@theorum/core/streaming` |
|
|
11
|
+
| Module | `src/streaming/mod.ts` |
|
|
12
|
+
|
|
13
|
+
## Ownership
|
|
14
|
+
|
|
15
|
+
| Path | Role |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `src/streaming/readStreamingJsonStringField.ts` | Incomplete JSON string preview |
|
|
18
|
+
| `src/streaming/mod.ts` | Barrel + stop re-exports |
|
|
19
|
+
|
|
20
|
+
Stop source of truth: [`../kernel/CONTRACT.md`](../kernel/CONTRACT.md)
|
|
21
|
+
(`src/kernel/stop.ts`).
|
|
22
|
+
|
|
23
|
+
## Streaming JSON preview
|
|
24
|
+
|
|
25
|
+
`readStreamingJsonStringField(jsonText, key)` reads one string field from
|
|
26
|
+
**incomplete** JSON while structured output streams as text deltas.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const preview = readStreamingJsonStringField(buffer, "mermaid");
|
|
30
|
+
// returns decoded prefix even before closing quote
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| Behavior | Detail |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| Locator | `"key": "` pattern |
|
|
36
|
+
| Escapes | `\n`, `\t`, `\uXXXX`, … |
|
|
37
|
+
| Incomplete buffer | Returns prefix for live UI preview |
|
|
38
|
+
| Missing key | `null` |
|
|
39
|
+
|
|
40
|
+
Does not validate full JSON documents.
|
|
41
|
+
|
|
42
|
+
## Stop re-exports
|
|
43
|
+
|
|
44
|
+
| Category | Exports |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Types | `TurnStop`, `TurnStopKind`, `TurnContinueFrom`, `ProfileResumeSpec` |
|
|
47
|
+
| Constants | `CONTINUE_INSTRUCTION`, `DEFAULT_AUTO_CONTINUE`, `AUTO_CONTINUE_DELAY_MS` |
|
|
48
|
+
| Helpers | `isResumeableStop`, `shouldAutoContinue`, `isUserCancelledStop`, mappers |
|
|
49
|
+
| Errors | `GenerationStopError`, `isGenerationStopError` |
|
|
50
|
+
|
|
51
|
+
Behavioral contract: kernel **Stop and resume** section.
|
|
52
|
+
|
|
53
|
+
## Exported API
|
|
54
|
+
|
|
55
|
+
| Group | Symbols |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| Streaming JSON | `readStreamingJsonStringField` |
|
|
58
|
+
| Stop / resume (re-export from `kernel/stop.ts`) | `ProfileResumeSpec`, `TurnContinueFrom`, `TurnStop`, `TurnStopKind`, `AUTO_CONTINUE_DELAY_MS`, `CONTINUE_INSTRUCTION`, `DEFAULT_AUTO_CONTINUE`, `GenerationStopError`, `isGenerationStopError`, `isResumeableStop`, `isUserCancelledStop`, `shouldAutoContinue`, `turnStopFromClientStreamEnd`, `turnStopFromInteractionStatus`, `turnStopFromOpenRouter` |
|
|
59
|
+
|
|
60
|
+
```theorum-evidence
|
|
61
|
+
{
|
|
62
|
+
"sections": {
|
|
63
|
+
"Export": {
|
|
64
|
+
"supports": [
|
|
65
|
+
{ "kind": "source", "path": "src/streaming/mod.ts" },
|
|
66
|
+
{ "kind": "config", "path": "package.json" }
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"Ownership": {
|
|
70
|
+
"supports": [
|
|
71
|
+
{ "kind": "source", "path": "src/streaming/mod.ts" },
|
|
72
|
+
{ "kind": "graph", "path": "docs/_map.mjs" }
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"Streaming JSON preview": {
|
|
76
|
+
"supports": [
|
|
77
|
+
{ "kind": "source", "path": "src/streaming/readStreamingJsonStringField.ts" },
|
|
78
|
+
{ "kind": "contract_test", "path": "tests/streaming/readStreamingJsonStringField.test.ts" }
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
"Stop re-exports": {
|
|
82
|
+
"supports": [
|
|
83
|
+
{ "kind": "source", "path": "src/streaming/mod.ts" },
|
|
84
|
+
{ "kind": "source", "path": "src/kernel/stop.ts" },
|
|
85
|
+
{ "kind": "contract_test", "path": "tests/streaming/turnStop.test.ts" }
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"Exported API": {
|
|
89
|
+
"supports": [
|
|
90
|
+
{ "kind": "source", "path": "src/streaming/mod.ts" },
|
|
91
|
+
{ "kind": "contract_test", "path": "tests/streaming/readStreamingJsonStringField.test.ts" }
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
package/esm/mod.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, }
|
|
|
44
44
|
export type { CompactionSplit, CompactionTokens } from './src/kernel/engine/compaction.js';
|
|
45
45
|
export { compactionMeter, compactionNeeded, estimateHistoryTokens, HISTORY_MEDIA_TOKENS, HISTORY_TEXT_ENCODING, resolveCompactionTokens, resolveHistoryTokens, shouldCompact, splitForCompaction, } from './src/kernel/engine/compaction.js';
|
|
46
46
|
export { runTurn } from './src/kernel/engine/runner.js';
|
|
47
|
-
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId,
|
|
47
|
+
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './src/kernel/registry/catalog.js';
|
|
48
48
|
export type { ProfileDefinition } from './src/kernel/registry/profiles.js';
|
|
49
49
|
export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './src/kernel/registry/profiles.js';
|
|
50
50
|
export { projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
|
package/esm/mod.js
CHANGED
|
@@ -42,7 +42,7 @@ export { clientIp, quotaMessage, releaseSlot, resetSlots, skipQuota, takeSlot, }
|
|
|
42
42
|
export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, } from './src/guardrails/sanitize.js';
|
|
43
43
|
export { compactionMeter, compactionNeeded, estimateHistoryTokens, HISTORY_MEDIA_TOKENS, HISTORY_TEXT_ENCODING, resolveCompactionTokens, resolveHistoryTokens, shouldCompact, splitForCompaction, } from './src/kernel/engine/compaction.js';
|
|
44
44
|
export { runTurn } from './src/kernel/engine/runner.js';
|
|
45
|
-
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId,
|
|
45
|
+
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './src/kernel/registry/catalog.js';
|
|
46
46
|
export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './src/kernel/registry/profiles.js';
|
|
47
47
|
export { projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
|
|
48
48
|
export { getStructured, registerStructured } from './src/kernel/registry/schemas.js';
|
|
@@ -168,6 +168,96 @@ function searchHtml(metadata) {
|
|
|
168
168
|
}
|
|
169
169
|
return undefined;
|
|
170
170
|
}
|
|
171
|
+
function nonEmptyString(value) {
|
|
172
|
+
if (typeof value === 'string' && value.trim()) {
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
function searchSuggestionsFromRecord(record) {
|
|
178
|
+
return nonEmptyString(record.search_suggestions ?? record.searchSuggestions);
|
|
179
|
+
}
|
|
180
|
+
function firstSearchSuggestions(items) {
|
|
181
|
+
if (!Array.isArray(items)) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
for (const item of items) {
|
|
185
|
+
const record = asRecord(item);
|
|
186
|
+
if (!record) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const html = searchSuggestionsFromRecord(record);
|
|
190
|
+
if (html) {
|
|
191
|
+
return html;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
/** Interactions streams search chips as `search_suggestions` HTML, not classic entry points. */
|
|
197
|
+
function searchSuggestionsHtml(step) {
|
|
198
|
+
return (searchSuggestionsFromRecord(step) ??
|
|
199
|
+
firstSearchSuggestions(step.result) ??
|
|
200
|
+
firstSearchSuggestions(step.content));
|
|
201
|
+
}
|
|
202
|
+
function sourceFromAnnotation(ann) {
|
|
203
|
+
const record = asRecord(ann);
|
|
204
|
+
if (!record) {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
const uri = nonEmptyString(record.url ?? record.uri);
|
|
208
|
+
if (!uri) {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
const kind = String(record.type ?? '');
|
|
212
|
+
const title = nonEmptyString(record.title ?? record.name) ?? uri;
|
|
213
|
+
if (kind === 'place_citation') {
|
|
214
|
+
return { type: 'maps', uri, title };
|
|
215
|
+
}
|
|
216
|
+
if (kind === 'url_citation' || kind === 'citation' || !kind) {
|
|
217
|
+
return { type: 'web', uri, title };
|
|
218
|
+
}
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
function appendAnnotationSources(into, annotations) {
|
|
222
|
+
for (const source of sourcesFromAnnotations(annotations)) {
|
|
223
|
+
pushUniqueSource(into, source);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function sourcesFromAnnotations(annotations) {
|
|
227
|
+
if (!Array.isArray(annotations)) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
const sources = [];
|
|
231
|
+
for (const ann of annotations) {
|
|
232
|
+
pushUniqueSource(sources, sourceFromAnnotation(ann));
|
|
233
|
+
}
|
|
234
|
+
return sources;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Wrap Interactions tool-result steps (google_search_result, maps, etc.) into grounding.
|
|
238
|
+
* Preserves the raw step on `metadata` so hosts can inspect everything Gemini returned.
|
|
239
|
+
*/
|
|
240
|
+
function groundingFromInteractionsTool(step) {
|
|
241
|
+
const sources = [];
|
|
242
|
+
appendAnnotationSources(sources, step.annotations);
|
|
243
|
+
if (Array.isArray(step.content)) {
|
|
244
|
+
for (const block of step.content) {
|
|
245
|
+
const record = asRecord(block);
|
|
246
|
+
if (record) {
|
|
247
|
+
appendAnnotationSources(sources, record.annotations);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const html = searchSuggestionsHtml(step);
|
|
252
|
+
if (!html && sources.length === 0) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
metadata: step,
|
|
257
|
+
...(html ? { searchHtml: html } : {}),
|
|
258
|
+
sources,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
171
261
|
function sourcesFromChunks(chunks) {
|
|
172
262
|
const sources = [];
|
|
173
263
|
for (const chunk of chunks) {
|
|
@@ -238,6 +328,8 @@ function groundingFromStep(stepValue) {
|
|
|
238
328
|
grounding = mergeGrounding(grounding, groundingFromMetadata(groundingMetadataFromRecord(asRecord(block) ?? {})));
|
|
239
329
|
}
|
|
240
330
|
}
|
|
331
|
+
// Interactions search/maps tool results: chips + citations live on the step/delta itself.
|
|
332
|
+
grounding = mergeGrounding(grounding, groundingFromInteractionsTool(step));
|
|
241
333
|
return grounding;
|
|
242
334
|
}
|
|
243
335
|
function groundingFromEvent(event) {
|
package/esm/src/kernel/mod.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import "../../_dnt.polyfills.js";
|
|
|
11
11
|
export type { CompactionSplit, CompactionTokens } from './engine/compaction.js';
|
|
12
12
|
export { compactionMeter, compactionNeeded, estimateHistoryTokens, HISTORY_MEDIA_TOKENS, HISTORY_TEXT_ENCODING, resolveCompactionTokens, resolveHistoryTokens, shouldCompact, splitForCompaction, } from './engine/compaction.js';
|
|
13
13
|
export { runTurn } from './engine/runner.js';
|
|
14
|
-
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId,
|
|
14
|
+
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './registry/catalog.js';
|
|
15
15
|
export type { ProfileDefinition } from './registry/profiles.js';
|
|
16
16
|
export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './registry/profiles.js';
|
|
17
17
|
export { projectProfile, resolveTurn } from './registry/resolve.js';
|
package/esm/src/kernel/mod.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import "../../_dnt.polyfills.js";
|
|
11
11
|
export { compactionMeter, compactionNeeded, estimateHistoryTokens, HISTORY_MEDIA_TOKENS, HISTORY_TEXT_ENCODING, resolveCompactionTokens, resolveHistoryTokens, shouldCompact, splitForCompaction, } from './engine/compaction.js';
|
|
12
12
|
export { runTurn } from './engine/runner.js';
|
|
13
|
-
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId,
|
|
13
|
+
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './registry/catalog.js';
|
|
14
14
|
export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './registry/profiles.js';
|
|
15
15
|
export { projectProfile, resolveTurn } from './registry/resolve.js';
|
|
16
16
|
export { getStructured, registerStructured } from './registry/schemas.js';
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
-
import type { BuiltinToolId, Catalog,
|
|
9
|
+
import type { BuiltinToolId, Catalog, MediaInputKind, ModelId, ModelSpec, Profile, ThinkingLevel, ToolCatalogEntry, ToolId } from '../types.js';
|
|
10
10
|
/** Live tool catalog. Starts with harness tools; presets/hosts register more. */
|
|
11
11
|
declare const CATALOG: Catalog;
|
|
12
12
|
/** Register or replace tool descriptors (idempotent per id). */
|
|
@@ -19,7 +19,7 @@ declare function listBuiltinIds(): BuiltinToolId[];
|
|
|
19
19
|
declare function resetTools(): void;
|
|
20
20
|
declare function mimeEssence(mime: string): string;
|
|
21
21
|
declare function mimeAllowed(accept: string[], mime: string): boolean;
|
|
22
|
-
declare function
|
|
22
|
+
declare function mediaKindForMime(mime: string): MediaInputKind | undefined;
|
|
23
23
|
/** Require a host-declared model spec for an allowed profile model id. */
|
|
24
24
|
declare function requireModelSpec(profile: Profile, modelId: ModelId): ModelSpec;
|
|
25
25
|
/** Clamp a requested thinking level to what the model spec accepts. */
|
|
@@ -28,4 +28,4 @@ declare function clampThinkingLevel(spec: ModelSpec, level: ThinkingLevel): Thin
|
|
|
28
28
|
declare function modelEntryByApiId(specs: Record<string, ModelSpec>, apiId: string): ModelSpec | undefined;
|
|
29
29
|
/** Clamp thinking level using a provider-native API id within a host specs map. */
|
|
30
30
|
declare function clampThinkingLevelForApiId(specs: Record<string, ModelSpec>, apiId: string, level: ThinkingLevel): ThinkingLevel;
|
|
31
|
-
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId,
|
|
31
|
+
export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, };
|