theorum 0.1.4 → 0.1.5

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.
Files changed (188) hide show
  1. package/esm/_dnt.polyfills.d.ts +110 -0
  2. package/esm/_dnt.polyfills.js +144 -0
  3. package/esm/_dnt.shims.d.ts +5 -0
  4. package/esm/_dnt.shims.js +61 -0
  5. package/{mod.ts → esm/mod.d.ts} +17 -57
  6. package/esm/mod.js +50 -0
  7. package/esm/package.json +3 -0
  8. package/esm/src/cli/commands/profile.d.ts +2 -0
  9. package/esm/src/cli/commands/profile.js +53 -0
  10. package/esm/src/cli/commands/run.d.ts +10 -0
  11. package/esm/src/cli/commands/run.js +55 -0
  12. package/esm/src/cli/commands/test.d.ts +15 -0
  13. package/esm/src/cli/commands/test.js +140 -0
  14. package/esm/src/cli/index.d.ts +4 -0
  15. package/esm/src/cli/index.js +148 -0
  16. package/esm/src/cli/matrix/fixtures.d.ts +13 -0
  17. package/esm/src/cli/matrix/fixtures.js +77 -0
  18. package/esm/src/cli/matrix/synthesizer.d.ts +29 -0
  19. package/esm/src/cli/matrix/synthesizer.js +187 -0
  20. package/esm/src/guardrails/error.d.ts +45 -0
  21. package/esm/src/guardrails/error.js +149 -0
  22. package/esm/src/guardrails/injection.d.ts +12 -0
  23. package/esm/src/guardrails/injection.js +220 -0
  24. package/esm/src/guardrails/mod.d.ts +16 -0
  25. package/esm/src/guardrails/mod.js +15 -0
  26. package/esm/src/guardrails/quota.d.ts +10 -0
  27. package/esm/src/guardrails/quota.js +64 -0
  28. package/esm/src/guardrails/sanitize.d.ts +22 -0
  29. package/esm/src/guardrails/sanitize.js +133 -0
  30. package/esm/src/guardrails/sensitive.d.ts +12 -0
  31. package/esm/src/guardrails/sensitive.js +88 -0
  32. package/esm/src/host/mint-trace.d.ts +27 -0
  33. package/esm/src/host/mint-trace.js +33 -0
  34. package/esm/src/host/mod.d.ts +13 -0
  35. package/{src/host/mod.ts → esm/src/host/mod.js} +3 -11
  36. package/esm/src/host/reply.d.ts +14 -0
  37. package/esm/src/host/reply.js +27 -0
  38. package/esm/src/kernel/engine/boundary.d.ts +10 -0
  39. package/esm/src/kernel/engine/boundary.js +55 -0
  40. package/esm/src/kernel/engine/delta.d.ts +8 -0
  41. package/esm/src/kernel/engine/delta.js +389 -0
  42. package/esm/src/kernel/engine/hash.d.ts +1 -0
  43. package/esm/src/kernel/engine/hash.js +9 -0
  44. package/esm/src/kernel/engine/record.d.ts +2 -0
  45. package/esm/src/kernel/engine/record.js +7 -0
  46. package/esm/src/kernel/engine/repair.d.ts +7 -0
  47. package/esm/src/kernel/engine/repair.js +38 -0
  48. package/esm/src/kernel/engine/runner/gates.d.ts +4 -0
  49. package/esm/src/kernel/engine/runner/gates.js +203 -0
  50. package/esm/src/kernel/engine/runner/mod.d.ts +14 -0
  51. package/esm/src/kernel/engine/runner/mod.js +109 -0
  52. package/esm/src/kernel/engine/runner/state.d.ts +16 -0
  53. package/esm/src/kernel/engine/runner/state.js +8 -0
  54. package/esm/src/kernel/engine/runner/steps.d.ts +15 -0
  55. package/esm/src/kernel/engine/runner/steps.js +119 -0
  56. package/esm/src/kernel/engine/runner/stream.d.ts +11 -0
  57. package/esm/src/kernel/engine/runner/stream.js +70 -0
  58. package/esm/src/kernel/engine/runner/tokens.d.ts +3 -0
  59. package/esm/src/kernel/engine/runner/tokens.js +38 -0
  60. package/esm/src/kernel/engine/runner/tools.d.ts +13 -0
  61. package/esm/src/kernel/engine/runner/tools.js +192 -0
  62. package/{src/kernel/engine/runner.ts → esm/src/kernel/engine/runner.d.ts} +1 -2
  63. package/esm/src/kernel/engine/runner.js +6 -0
  64. package/esm/src/kernel/engine/tree.d.ts +2 -0
  65. package/esm/src/kernel/engine/tree.js +17 -0
  66. package/esm/src/kernel/mod.d.ts +18 -0
  67. package/esm/src/kernel/mod.js +16 -0
  68. package/esm/src/kernel/registry/attachments.d.ts +16 -0
  69. package/esm/src/kernel/registry/attachments.js +156 -0
  70. package/esm/src/kernel/registry/catalog.d.ts +31 -0
  71. package/esm/src/kernel/registry/catalog.js +135 -0
  72. package/esm/src/kernel/registry/ingress.d.ts +13 -0
  73. package/esm/src/kernel/registry/ingress.js +163 -0
  74. package/esm/src/kernel/registry/profiles.d.ts +34 -0
  75. package/esm/src/kernel/registry/profiles.js +120 -0
  76. package/esm/src/kernel/registry/provider-request.d.ts +4 -0
  77. package/esm/src/kernel/registry/provider-request.js +25 -0
  78. package/esm/src/kernel/registry/resolve.d.ts +19 -0
  79. package/esm/src/kernel/registry/resolve.js +217 -0
  80. package/esm/src/kernel/registry/schemas.d.ts +14 -0
  81. package/esm/src/kernel/registry/schemas.js +23 -0
  82. package/esm/src/kernel/registry/tools.d.ts +12 -0
  83. package/esm/src/kernel/registry/tools.js +36 -0
  84. package/{src/kernel/registry/vault.ts → esm/src/kernel/registry/vault.d.ts} +2 -17
  85. package/esm/src/kernel/registry/vault.js +18 -0
  86. package/esm/src/kernel/types.d.ts +524 -0
  87. package/esm/src/kernel/types.js +10 -0
  88. package/esm/src/observability/mod.d.ts +12 -0
  89. package/{src/observability/mod.ts → esm/src/observability/mod.js} +2 -11
  90. package/esm/src/observability/spans.d.ts +16 -0
  91. package/esm/src/observability/spans.js +56 -0
  92. package/esm/src/observability/trace-attach.d.ts +16 -0
  93. package/esm/src/observability/trace-attach.js +67 -0
  94. package/esm/src/observability/trace-record.d.ts +113 -0
  95. package/esm/src/observability/trace-record.js +143 -0
  96. package/esm/src/observability/trace-usage.d.ts +3 -0
  97. package/esm/src/observability/trace-usage.js +32 -0
  98. package/esm/src/observability/trace.d.ts +23 -0
  99. package/esm/src/observability/trace.js +121 -0
  100. package/esm/src/presets/google.d.ts +50 -0
  101. package/esm/src/presets/google.js +96 -0
  102. package/esm/src/presets/mod.d.ts +11 -0
  103. package/esm/src/presets/mod.js +10 -0
  104. package/esm/src/providers/create-provider.d.ts +29 -0
  105. package/esm/src/providers/create-provider.js +38 -0
  106. package/esm/src/providers/gemini-tape.d.ts +2 -0
  107. package/esm/src/providers/gemini-tape.js +46 -0
  108. package/esm/src/providers/google-tap.d.ts +3 -0
  109. package/esm/src/providers/google-tap.js +48 -0
  110. package/esm/src/providers/interactions.d.ts +5 -0
  111. package/esm/src/providers/interactions.js +153 -0
  112. package/esm/src/providers/keys.d.ts +19 -0
  113. package/esm/src/providers/keys.js +129 -0
  114. package/esm/src/providers/mod.d.ts +12 -0
  115. package/{src/providers/mod.ts → esm/src/providers/mod.js} +2 -4
  116. package/esm/src/providers/openrouter-mod.d.ts +13 -0
  117. package/{src/providers/openrouter-mod.ts → esm/src/providers/openrouter-mod.js} +3 -7
  118. package/esm/src/providers/openrouter-payload.d.ts +32 -0
  119. package/esm/src/providers/openrouter-payload.js +179 -0
  120. package/esm/src/providers/openrouter.d.ts +15 -0
  121. package/esm/src/providers/openrouter.js +589 -0
  122. package/esm/src/providers/pcm.d.ts +7 -0
  123. package/esm/src/providers/pcm.js +35 -0
  124. package/esm/src/providers/provider.d.ts +15 -0
  125. package/esm/src/providers/provider.js +160 -0
  126. package/esm/src/providers/speech.d.ts +23 -0
  127. package/esm/src/providers/speech.js +125 -0
  128. package/esm/src/providers/sse.d.ts +7 -0
  129. package/esm/src/providers/sse.js +53 -0
  130. package/package.json +45 -36
  131. package/deno.json +0 -57
  132. package/deno.lock +0 -469
  133. package/src/cli/commands/profile.ts +0 -57
  134. package/src/cli/commands/run.ts +0 -66
  135. package/src/cli/commands/test.ts +0 -195
  136. package/src/cli/index.ts +0 -161
  137. package/src/cli/matrix/fixtures.ts +0 -96
  138. package/src/cli/matrix/synthesizer.ts +0 -240
  139. package/src/guardrails/error.ts +0 -142
  140. package/src/guardrails/injection.ts +0 -254
  141. package/src/guardrails/mod.ts +0 -40
  142. package/src/guardrails/quota.ts +0 -87
  143. package/src/guardrails/sanitize.ts +0 -165
  144. package/src/guardrails/sensitive.ts +0 -96
  145. package/src/host/mint-trace.ts +0 -54
  146. package/src/host/reply.ts +0 -32
  147. package/src/kernel/engine/assert.ts +0 -29
  148. package/src/kernel/engine/boundary.ts +0 -75
  149. package/src/kernel/engine/delta.ts +0 -440
  150. package/src/kernel/engine/hash.ts +0 -11
  151. package/src/kernel/engine/record.ts +0 -8
  152. package/src/kernel/engine/repair.ts +0 -56
  153. package/src/kernel/engine/runner/gates.ts +0 -338
  154. package/src/kernel/engine/runner/mod.ts +0 -135
  155. package/src/kernel/engine/runner/state.ts +0 -31
  156. package/src/kernel/engine/runner/steps.ts +0 -183
  157. package/src/kernel/engine/runner/stream.ts +0 -83
  158. package/src/kernel/engine/runner/tokens.ts +0 -47
  159. package/src/kernel/engine/runner/tools.ts +0 -266
  160. package/src/kernel/engine/tree.ts +0 -18
  161. package/src/kernel/mod.ts +0 -39
  162. package/src/kernel/registry/attachments.ts +0 -195
  163. package/src/kernel/registry/catalog.ts +0 -181
  164. package/src/kernel/registry/ingress.ts +0 -223
  165. package/src/kernel/registry/profiles.ts +0 -165
  166. package/src/kernel/registry/provider-request.ts +0 -31
  167. package/src/kernel/registry/resolve.ts +0 -290
  168. package/src/kernel/registry/schemas.ts +0 -29
  169. package/src/kernel/registry/tools.ts +0 -45
  170. package/src/kernel/types.ts +0 -576
  171. package/src/observability/spans.ts +0 -70
  172. package/src/observability/trace-attach.ts +0 -96
  173. package/src/observability/trace-record.ts +0 -254
  174. package/src/observability/trace-usage.ts +0 -36
  175. package/src/observability/trace.ts +0 -143
  176. package/src/presets/google.ts +0 -147
  177. package/src/presets/mod.ts +0 -24
  178. package/src/providers/create-provider.ts +0 -64
  179. package/src/providers/gemini-tape.ts +0 -59
  180. package/src/providers/google-tap.ts +0 -57
  181. package/src/providers/interactions.ts +0 -182
  182. package/src/providers/keys.ts +0 -182
  183. package/src/providers/openrouter-payload.ts +0 -232
  184. package/src/providers/openrouter.ts +0 -758
  185. package/src/providers/pcm.ts +0 -37
  186. package/src/providers/provider.ts +0 -206
  187. package/src/providers/speech.ts +0 -180
  188. package/src/providers/sse.ts +0 -59
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Google Interactions provider adapter.
3
+ *
4
+ * This adapter converts THEORUM's provider-neutral request into the Google
5
+ * Interactions wire format and streams normalized `TurnEvent` objects.
6
+ * Speech-role turns use `response_format: audio` + `speech_config` (same
7
+ * transport as chat/image).
8
+ *
9
+ * @module
10
+ */
11
+ import { TheorumError, toErrorEvent } from '../guardrails/error.js';
12
+ import { eventsFromComplete, eventsFromDelta, extractTokenEvent, groundingFromEvent, tryStructured, } from '../kernel/engine/delta.js';
13
+ import { tapFetch } from './google-tap.js';
14
+ import { toInteractionsBody } from './interactions.js';
15
+ import { fetchGemini } from './keys.js';
16
+ import { wrapPcmAsWav } from './pcm.js';
17
+ import { INTERACTIONS_URL, takeSsePayloads } from './sse.js';
18
+ const HTTP_OK = 200;
19
+ function base64ToBytes(data) {
20
+ const bin = atob(data);
21
+ const out = new Uint8Array(bin.length);
22
+ for (let i = 0; i < bin.length; i++)
23
+ out[i] = bin.charCodeAt(i);
24
+ return out;
25
+ }
26
+ function bytesToBase64(bytes) {
27
+ let bin = '';
28
+ for (let i = 0; i < bytes.length; i++)
29
+ bin += String.fromCharCode(bytes[i]);
30
+ return btoa(bin);
31
+ }
32
+ function isRawPcmMime(mime) {
33
+ const lower = mime.toLowerCase();
34
+ return lower === 'audio/pcm' || lower === 'audio/l16' || lower === 'audio/raw';
35
+ }
36
+ /** Google TTS returns raw PCM; wrap as WAV for hosts (matches OpenRouter pcm path). */
37
+ function normalizeSpeechMedia(event, speech) {
38
+ if (!(speech && event.type === 'media' && event.media)) {
39
+ return event;
40
+ }
41
+ const { mimeType, data } = event.media;
42
+ if (!isRawPcmMime(mimeType)) {
43
+ return event;
44
+ }
45
+ const wav = wrapPcmAsWav(base64ToBytes(data));
46
+ return {
47
+ type: 'media',
48
+ media: { mimeType: 'audio/wav', data: bytesToBase64(wav) },
49
+ };
50
+ }
51
+ async function* readSseRecords(res) {
52
+ if (!res.body) {
53
+ throw new TheorumError('empty Gemini stream');
54
+ }
55
+ const reader = res.body.getReader();
56
+ const decoder = new TextDecoder();
57
+ yield* pumpSse(reader, decoder, '', '');
58
+ }
59
+ async function* pumpSse(reader, decoder, buffer, pendingEvent) {
60
+ const { done, value } = await reader.read();
61
+ if (done) {
62
+ return;
63
+ }
64
+ const next = buffer + decoder.decode(value, { stream: true });
65
+ const taken = takeSsePayloads(next, pendingEvent);
66
+ for (const payload of taken.payloads) {
67
+ yield payload;
68
+ }
69
+ yield* pumpSse(reader, decoder, taken.rest, taken.pendingEvent);
70
+ }
71
+ function eventType(event) {
72
+ return String(event.event_type ?? event.type ?? '');
73
+ }
74
+ function isDeltaEvent(kind) {
75
+ return kind === 'content.delta' || kind === 'step.delta';
76
+ }
77
+ function isCompleteEvent(kind) {
78
+ return (kind === 'interaction.complete' ||
79
+ kind === 'interaction.completed' ||
80
+ kind.startsWith('interaction.'));
81
+ }
82
+ function foldDeltaPayload(event, acc) {
83
+ const deltaEvents = eventsFromDelta(event.delta);
84
+ for (const item of deltaEvents) {
85
+ if (item.type === 'text' && item.text) {
86
+ acc.text += item.text;
87
+ }
88
+ }
89
+ return deltaEvents;
90
+ }
91
+ function foldPayload(event, acc) {
92
+ const kind = eventType(event);
93
+ const events = [];
94
+ if (isDeltaEvent(kind)) {
95
+ events.push(...foldDeltaPayload(event, acc));
96
+ }
97
+ else if (isCompleteEvent(kind)) {
98
+ events.push(...eventsFromComplete(event, acc.text.length > 0));
99
+ }
100
+ // Also check if usage was included on the event directly
101
+ if (!events.some((e) => e.type === 'tokens')) {
102
+ const tokenEvent = extractTokenEvent(event);
103
+ if (tokenEvent) {
104
+ events.push(tokenEvent);
105
+ }
106
+ }
107
+ const groundingEvent = groundingFromEvent(event);
108
+ if (groundingEvent && !events.some((e) => e.type === 'grounding')) {
109
+ events.push(groundingEvent);
110
+ }
111
+ return events;
112
+ }
113
+ function withTap(req, transport) {
114
+ return {
115
+ ...transport,
116
+ fetch: tapFetch(req.tapGemini, transport.fetch),
117
+ };
118
+ }
119
+ async function* streamComplete(req, transport) {
120
+ if (!req.geminiBucket) {
121
+ yield toErrorEvent('missing Gemini vault bucket for Interactions');
122
+ return;
123
+ }
124
+ const res = await fetchGemini(INTERACTIONS_URL, { method: 'POST', body: JSON.stringify(toInteractionsBody(req)) }, req.geminiBucket, withTap(req, transport));
125
+ if (res.status !== HTTP_OK) {
126
+ const errorBody = await res.text().catch(() => '');
127
+ yield toErrorEvent(`Gemini HTTP ${String(res.status)}: ${errorBody}`);
128
+ return;
129
+ }
130
+ const acc = { text: '' };
131
+ const speech = Boolean(req.speech);
132
+ for await (const payload of readSseRecords(res)) {
133
+ req.tapGemini?.(payload);
134
+ const events = foldPayload(payload, acc);
135
+ for (const event of events) {
136
+ yield normalizeSpeechMedia(event, speech);
137
+ }
138
+ }
139
+ if (req.structured && acc.text) {
140
+ const structured = tryStructured(acc.text);
141
+ if (structured) {
142
+ yield structured;
143
+ }
144
+ }
145
+ }
146
+ async function* streamGuarded(req, transport) {
147
+ try {
148
+ yield* streamComplete(req, transport);
149
+ }
150
+ catch (err) {
151
+ yield toErrorEvent(err);
152
+ }
153
+ }
154
+ /** Create a `ModelProvider` backed by Google Interactions streaming. */
155
+ function createInteractionsProvider(transport) {
156
+ return {
157
+ complete: (req) => streamGuarded(req, transport),
158
+ };
159
+ }
160
+ export { createInteractionsProvider };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * OpenAI-compatible `/audio/speech` transport (internal).
3
+ *
4
+ * Hosts use `createProvider(profile, { openRouter })` — this module is selected
5
+ * when the profile is an openAi speech role. Not a separate public door.
6
+ *
7
+ * @module
8
+ */
9
+ import type { ModelProvider, ProviderCompleteRequest, TurnEvent } from '../kernel/types.js';
10
+ /** Credentials for the openAi speech path (same shape as OpenRouter chat config + voice). */
11
+ export interface SpeechProviderConfig {
12
+ apiKey?: string;
13
+ /** Fallback TTS voice when the profile does not pin `outputs.speech.voice`. */
14
+ voice?: string;
15
+ baseUrl?: string;
16
+ siteUrl?: string;
17
+ siteName?: string;
18
+ fetch?: typeof fetch;
19
+ }
20
+ declare function streamSpeech(req: ProviderCompleteRequest, config?: SpeechProviderConfig): AsyncGenerator<TurnEvent>;
21
+ /** Internal ModelProvider for openAi speech roles. */
22
+ declare function createSpeechProvider(config?: SpeechProviderConfig): ModelProvider;
23
+ export { createSpeechProvider, streamSpeech };
@@ -0,0 +1,125 @@
1
+ /**
2
+ * OpenAI-compatible `/audio/speech` transport (internal).
3
+ *
4
+ * Hosts use `createProvider(profile, { openRouter })` — this module is selected
5
+ * when the profile is an openAi speech role. Not a separate public door.
6
+ *
7
+ * @module
8
+ */
9
+ import { toErrorEvent } from '../guardrails/error.js';
10
+ import { wrapPcmAsWav } from './pcm.js';
11
+ const HTTP_OK = 200;
12
+ function bytesToBase64(bytes) {
13
+ let bin = '';
14
+ for (let i = 0; i < bytes.length; i++)
15
+ bin += String.fromCharCode(bytes[i]);
16
+ return btoa(bin);
17
+ }
18
+ function extractInputText(input) {
19
+ return input
20
+ .filter((p) => p.type === 'text')
21
+ .map((p) => (p.type === 'text' ? p.text : ''))
22
+ .join(' ')
23
+ .trim();
24
+ }
25
+ function resolveSpeechWireModel(req) {
26
+ if (req.openRouterId) {
27
+ return req.openRouterId;
28
+ }
29
+ if (req.apiId.includes('/')) {
30
+ return req.apiId;
31
+ }
32
+ if (req.apiId) {
33
+ return `google/${req.apiId}`;
34
+ }
35
+ return String(req.model);
36
+ }
37
+ function buildHeaders(apiKey, config) {
38
+ const headers = {
39
+ Authorization: `Bearer ${apiKey}`,
40
+ 'Content-Type': 'application/json',
41
+ };
42
+ if (config.siteUrl) {
43
+ headers['HTTP-Referer'] = config.siteUrl;
44
+ }
45
+ if (config.siteName) {
46
+ headers['X-Title'] = config.siteName;
47
+ }
48
+ return headers;
49
+ }
50
+ function buildPayload(req, text, speech, configVoice) {
51
+ const voice = speech?.voice ?? configVoice;
52
+ const format = speech?.format ?? 'pcm';
53
+ const payload = {
54
+ model: resolveSpeechWireModel(req),
55
+ input: text,
56
+ response_format: format,
57
+ };
58
+ if (voice) {
59
+ payload.voice = voice;
60
+ }
61
+ return payload;
62
+ }
63
+ async function requestSpeech(apiKey, text, req, config) {
64
+ const fetchFn = config.fetch ?? fetch;
65
+ const baseUrl = config.baseUrl?.replace(/\/+$/, '') ?? 'https://openrouter.ai/api/v1';
66
+ const url = `${baseUrl}/audio/speech`;
67
+ return await fetchFn(url, {
68
+ method: 'POST',
69
+ headers: buildHeaders(apiKey, config),
70
+ body: JSON.stringify(buildPayload(req, text, req.speech, config.voice)),
71
+ });
72
+ }
73
+ function* yieldSpeechSuccess(rawBytes, text, format) {
74
+ let mediaMime = 'audio/mpeg';
75
+ let mediaBytes = rawBytes;
76
+ if (format === 'pcm') {
77
+ mediaMime = 'audio/wav';
78
+ mediaBytes = wrapPcmAsWav(rawBytes);
79
+ }
80
+ yield {
81
+ type: 'media',
82
+ media: { mimeType: mediaMime, data: bytesToBase64(mediaBytes) },
83
+ };
84
+ const inputTokens = Math.max(1, Math.round(text.length / 4));
85
+ const outputTokens = Math.max(1, Math.round(rawBytes.length / 100));
86
+ yield {
87
+ type: 'tokens',
88
+ tokens: { input: inputTokens, output: outputTokens, total: inputTokens + outputTokens },
89
+ };
90
+ yield { type: 'done' };
91
+ }
92
+ async function* streamSpeech(req, config = {}) {
93
+ const apiKey = config.apiKey?.trim() || undefined;
94
+ if (!apiKey) {
95
+ yield toErrorEvent('missing API key for speech');
96
+ return;
97
+ }
98
+ const text = extractInputText(req.input);
99
+ if (!text) {
100
+ yield toErrorEvent('empty text for speech');
101
+ return;
102
+ }
103
+ const res = await requestSpeech(apiKey, text, req, config);
104
+ if (res.status !== HTTP_OK) {
105
+ yield toErrorEvent(`Speech HTTP ${String(res.status)}`);
106
+ return;
107
+ }
108
+ const arrayBuffer = await res.arrayBuffer();
109
+ const rawBytes = new Uint8Array(arrayBuffer);
110
+ if (rawBytes.length === 0) {
111
+ yield toErrorEvent('no audio returned from speech');
112
+ return;
113
+ }
114
+ const format = req.speech?.format ?? 'pcm';
115
+ for (const ev of yieldSpeechSuccess(rawBytes, text, format)) {
116
+ yield ev;
117
+ }
118
+ }
119
+ /** Internal ModelProvider for openAi speech roles. */
120
+ function createSpeechProvider(config = {}) {
121
+ return {
122
+ complete: (req) => streamSpeech(req, config),
123
+ };
124
+ }
125
+ export { createSpeechProvider, streamSpeech };
@@ -0,0 +1,7 @@
1
+ declare const INTERACTIONS_URL = "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse";
2
+ declare function takeSsePayloads(buffer: string, pendingEvent?: string): {
3
+ rest: string;
4
+ payloads: Record<string, unknown>[];
5
+ pendingEvent: string;
6
+ };
7
+ export { INTERACTIONS_URL, takeSsePayloads };
@@ -0,0 +1,53 @@
1
+ const INTERACTIONS_URL = 'https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse';
2
+ const DATA_PREFIX = 'data: ';
3
+ const EVENT_PREFIX = 'event: ';
4
+ const DONE = '[DONE]';
5
+ function asObject(parsed) {
6
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
7
+ return parsed;
8
+ }
9
+ return undefined;
10
+ }
11
+ function dataRecord(raw, sseEvent) {
12
+ const data = raw.slice(DATA_PREFIX.length).trim();
13
+ const row = {};
14
+ if (sseEvent) {
15
+ row.sseEvent = sseEvent;
16
+ }
17
+ if (!data || data === DONE) {
18
+ row.eventType = 'sse_done';
19
+ return row;
20
+ }
21
+ try {
22
+ const parsed = JSON.parse(data);
23
+ const obj = asObject(parsed);
24
+ if (obj) {
25
+ return { ...obj, ...row };
26
+ }
27
+ row.eventType = 'sse_unparsed';
28
+ row.data = parsed;
29
+ return row;
30
+ }
31
+ catch {
32
+ row.eventType = 'sse_unparsed';
33
+ row.data = data;
34
+ return row;
35
+ }
36
+ }
37
+ function takeSsePayloads(buffer, pendingEvent = '') {
38
+ const payloads = [];
39
+ const chunks = buffer.split('\n');
40
+ const rest = chunks.pop() ?? '';
41
+ let sseEvent = pendingEvent;
42
+ for (const line of chunks) {
43
+ if (line.startsWith(EVENT_PREFIX)) {
44
+ sseEvent = line.slice(EVENT_PREFIX.length).trim();
45
+ }
46
+ else if (line.startsWith(DATA_PREFIX)) {
47
+ payloads.push(dataRecord(line, sseEvent));
48
+ sseEvent = '';
49
+ }
50
+ }
51
+ return { rest, payloads, pendingEvent: sseEvent };
52
+ }
53
+ export { INTERACTIONS_URL, takeSsePayloads };
package/package.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "name": "theorum",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, dynamic tools, provider adapters, guardrails, and host-injected traces.",
5
- "license": "MIT",
6
- "type": "module",
7
5
  "keywords": [
8
6
  "agent",
9
7
  "ai",
@@ -15,42 +13,53 @@
15
13
  "openrouter",
16
14
  "gemini"
17
15
  ],
16
+ "license": "MIT",
17
+ "module": "./esm/mod.js",
18
18
  "exports": {
19
- ".": "./mod.ts",
20
- "./kernel": "./src/kernel/mod.ts",
21
- "./providers": "./src/providers/mod.ts",
22
- "./openrouter": "./src/providers/openrouter-mod.ts",
23
- "./guardrails": "./src/guardrails/mod.ts",
24
- "./observability": "./src/observability/mod.ts",
25
- "./host": "./src/host/mod.ts",
26
- "./cli": "./src/cli/index.ts",
27
- "./presets": "./src/presets/mod.ts",
28
- "./presets/google": "./src/presets/google.ts"
19
+ ".": {
20
+ "import": "./esm/mod.js"
21
+ },
22
+ "./kernel": {
23
+ "import": "./esm/src/kernel/mod.js"
24
+ },
25
+ "./providers": {
26
+ "import": "./esm/src/providers/mod.js"
27
+ },
28
+ "./openrouter": {
29
+ "import": "./esm/src/providers/openrouter-mod.js"
30
+ },
31
+ "./guardrails": {
32
+ "import": "./esm/src/guardrails/mod.js"
33
+ },
34
+ "./observability": {
35
+ "import": "./esm/src/observability/mod.js"
36
+ },
37
+ "./host": {
38
+ "import": "./esm/src/host/mod.js"
39
+ },
40
+ "./cli": {
41
+ "import": "./esm/src/cli/index.js"
42
+ },
43
+ "./presets": {
44
+ "import": "./esm/src/presets/mod.js"
45
+ },
46
+ "./presets/google": {
47
+ "import": "./esm/src/presets/google.js"
48
+ }
29
49
  },
30
- "files": [
31
- "README.md",
32
- "deno.json",
33
- "deno.lock",
34
- "docs/",
35
- "mod.ts",
36
- "src/"
37
- ],
50
+ "scripts": {},
51
+ "bin": {
52
+ "theorum": "./esm/src/cli/index.js"
53
+ },
54
+ "type": "module",
55
+ "sideEffects": false,
38
56
  "dependencies": {
39
57
  "@openrouter/ai-sdk-provider": "1.5.4",
40
- "ai": "5.0.244"
41
- },
42
- "scripts": {
43
- "build:npm": "deno run --allow-read --allow-write --allow-env --allow-net --allow-run=npm scripts/build-npm.ts",
44
- "test": "deno test --allow-read --allow-write --allow-net",
45
- "coverage": "rm -rf coverage && deno test --allow-read --allow-write --allow-net --coverage=coverage tests/ && deno coverage coverage --lcov --output=coverage/lcov.info && node scripts/lcov-to-istanbul.mjs",
46
- "lint:biome": "biome check .",
47
- "lint:ast-grep": "ast-grep scan",
48
- "lint:fallow": "npm run coverage && fallow audit && fallow health && fallow dupes && fallow dead-code",
49
- "lint": "npm run lint:biome && npm run lint:ast-grep && npm run lint:fallow"
58
+ "ai": "5.0.244",
59
+ "@deno/shim-deno": "~0.18.0"
50
60
  },
51
61
  "devDependencies": {
52
- "@biomejs/biome": "^2.5.8",
53
- "@ast-grep/cli": "^0.41.0",
54
- "fallow": "3.17.0"
55
- }
56
- }
62
+ "@types/node": "^20.9.0"
63
+ },
64
+ "_generatedBy": "dnt@0.43.2"
65
+ }
package/deno.json DELETED
@@ -1,57 +0,0 @@
1
- {
2
- "name": "@theorum/core",
3
- "version": "0.1.4",
4
- "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, dynamic tools, provider adapters, guardrails, and host-injected traces.",
5
- "license": "MIT",
6
- "keywords": [
7
- "agent",
8
- "ai",
9
- "kernel",
10
- "llm",
11
- "typescript",
12
- "deno",
13
- "node",
14
- "openrouter",
15
- "gemini"
16
- ],
17
- "exports": {
18
- ".": "./mod.ts",
19
- "./kernel": "./src/kernel/mod.ts",
20
- "./providers": "./src/providers/mod.ts",
21
- "./openrouter": "./src/providers/openrouter-mod.ts",
22
- "./guardrails": "./src/guardrails/mod.ts",
23
- "./observability": "./src/observability/mod.ts",
24
- "./host": "./src/host/mod.ts",
25
- "./cli": "./src/cli/index.ts",
26
- "./presets": "./src/presets/mod.ts",
27
- "./presets/google": "./src/presets/google.ts"
28
- },
29
- "publish": {
30
- "exclude": [
31
- ".fallow/",
32
- ".fallowrc.jsonc",
33
- ".github/",
34
- "ast-grep-rules/",
35
- "biome.json",
36
- "coverage/",
37
- "node_modules/",
38
- "npm/",
39
- "package-lock.json",
40
- "scripts/",
41
- "sgconfig.yml",
42
- "tests/"
43
- ]
44
- },
45
- "imports": {
46
- "@openrouter/ai-sdk-provider": "npm:@openrouter/ai-sdk-provider@1.5.4",
47
- "ai": "npm:ai@5.0.244",
48
- "@std/assert": "jsr:@std/assert@^1.0.0"
49
- },
50
- "tasks": {
51
- "theorum": "deno run --allow-read --allow-write --allow-net src/cli/index.ts",
52
- "test": "deno test --allow-read --allow-write --allow-net tests/",
53
- "check": "deno check mod.ts",
54
- "lint": "npm run lint",
55
- "verify:live": "deno run --allow-net scripts/verify-live.ts"
56
- }
57
- }