theorum 0.1.9 → 0.1.11

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 (41) hide show
  1. package/esm/src/cli/commands/bench.d.ts +20 -0
  2. package/esm/src/cli/commands/bench.js +454 -0
  3. package/esm/src/cli/commands/fuzz-guardrails.d.ts +9 -0
  4. package/esm/src/cli/commands/fuzz-guardrails.js +440 -0
  5. package/esm/src/cli/index.js +20 -1
  6. package/esm/src/guardrails/injection.d.ts +0 -1
  7. package/esm/src/guardrails/injection.js +105 -12
  8. package/esm/src/guardrails/normalize.d.ts +11 -0
  9. package/esm/src/guardrails/normalize.js +110 -0
  10. package/esm/src/guardrails/sanitize.d.ts +10 -2
  11. package/esm/src/guardrails/sanitize.js +27 -1
  12. package/esm/src/guardrails/sensitive.js +5 -3
  13. package/esm/src/kernel/engine/boundary.js +10 -10
  14. package/esm/src/kernel/engine/runner/mod.js +4 -1
  15. package/esm/src/kernel/engine/runner/tools.js +11 -5
  16. package/esm/src/kernel/types.d.ts +1 -1
  17. package/esm/src/observability/trace-record.d.ts +1 -0
  18. package/esm/src/observability/trace-record.js +4 -4
  19. package/esm/src/providers/create-provider.d.ts +0 -7
  20. package/esm/src/providers/create-provider.js +2 -2
  21. package/esm/src/providers/expose-for-tests.d.ts +1 -0
  22. package/esm/src/providers/expose-for-tests.js +21 -0
  23. package/esm/src/providers/gemini-tape.d.ts +0 -14
  24. package/esm/src/providers/gemini-tape.js +3 -3
  25. package/esm/src/providers/google-tap.d.ts +0 -10
  26. package/esm/src/providers/google-tap.js +2 -2
  27. package/esm/src/providers/interactions.d.ts +1 -37
  28. package/esm/src/providers/interactions.js +3 -3
  29. package/esm/src/providers/keys.d.ts +0 -19
  30. package/esm/src/providers/keys.js +3 -3
  31. package/esm/src/providers/openrouter.d.ts +1 -118
  32. package/esm/src/providers/openrouter.js +3 -3
  33. package/esm/src/providers/pcm.d.ts +0 -7
  34. package/esm/src/providers/pcm.js +2 -2
  35. package/esm/src/providers/provider.d.ts +1 -29
  36. package/esm/src/providers/provider.js +3 -3
  37. package/esm/src/providers/speech.d.ts +1 -18
  38. package/esm/src/providers/speech.js +3 -3
  39. package/esm/src/providers/sse.d.ts +0 -8
  40. package/esm/src/providers/sse.js +2 -2
  41. package/package.json +3 -3
@@ -1,6 +1,7 @@
1
1
  import { OMIT_CANARY } from '../kernel/engine/boundary.js';
2
2
  import { sha256 } from '../kernel/engine/hash.js';
3
3
  import { mapStrings } from '../kernel/engine/tree.js';
4
+ import { exposeForTests } from './expose-for-tests.js';
4
5
  function isImageBlob(rec) {
5
6
  if (rec.type === 'image' || rec.type === 'media') {
6
7
  return true;
@@ -44,12 +45,11 @@ async function tapeGemini(value, canary) {
44
45
  return redactCanaryInTree(await scrubGemini(value), canary);
45
46
  }
46
47
  export { tapeGemini };
47
- /** @internal Exported for direct unit testing only. */
48
- export const _internals = {
48
+ exposeForTests('gemini-tape', {
49
49
  isImageBlob,
50
50
  scrubEntry,
51
51
  scrubRecord,
52
52
  scrubGemini,
53
53
  redactCanaryInTree,
54
54
  tapeGemini,
55
- };
55
+ });
@@ -1,13 +1,3 @@
1
1
  import type { ProviderCompleteRequest } from '../kernel/types.js';
2
- declare function tapeHeaderValue(key: string, value: string): string;
3
- declare function tapeHeaders(headers?: HeadersInit): Record<string, string>;
4
- declare function throwRow(err: unknown): Record<string, unknown>;
5
2
  declare function tapFetch(tap: ProviderCompleteRequest['tapGemini'], send?: typeof fetch): typeof fetch;
6
3
  export { tapFetch };
7
- /** @internal Exported for direct unit testing only. */
8
- export declare const _internals: {
9
- tapeHeaderValue: typeof tapeHeaderValue;
10
- tapeHeaders: typeof tapeHeaders;
11
- throwRow: typeof throwRow;
12
- tapFetch: typeof tapFetch;
13
- };
@@ -1,3 +1,4 @@
1
+ import { exposeForTests } from './expose-for-tests.js';
1
2
  const SECRET_HEADER = /key|auth|cookie|secret|token/i;
2
3
  function tapeHeaderValue(key, value) {
3
4
  if (SECRET_HEADER.test(key)) {
@@ -46,5 +47,4 @@ function tapFetch(tap, send = fetch) {
46
47
  };
47
48
  }
48
49
  export { tapFetch };
49
- /** @internal Exported for direct unit testing only. */
50
- export const _internals = { tapeHeaderValue, tapeHeaders, throwRow, tapFetch };
50
+ exposeForTests('google-tap', { tapeHeaderValue, tapeHeaders, throwRow, tapFetch });
@@ -1,41 +1,5 @@
1
- import type { InteractionPart, ProviderCompleteRequest } from '../kernel/types.js';
1
+ import type { ProviderCompleteRequest } from '../kernel/types.js';
2
2
  declare function camelToSnake(key: string): string;
3
- declare function toGoogleValue(value: unknown): unknown;
4
- declare function wirePart(part: InteractionPart): Record<string, string>;
5
- declare function userInputStep(parts: InteractionPart[]): {
6
- type: string;
7
- content: Record<string, string>[];
8
- };
9
- declare function historyStep(msg: import('../kernel/types.js').TurnHistoryMessage): {
10
- type: string;
11
- content: Record<string, string>[];
12
- };
13
- declare function systemHoldsUserInput(system: string, parts: InteractionPart[]): boolean;
14
- declare function jsonResponseFormat(schema: Record<string, unknown>): unknown[];
15
- declare function attachResponseFormat(req: ProviderCompleteRequest, camel: Record<string, unknown>): void;
16
- declare function attachSpeechConfig(req: ProviderCompleteRequest, generationConfig: Record<string, unknown>): void;
17
- declare function inputStepsFromRequest(req: ProviderCompleteRequest): {
18
- type: string;
19
- content: Record<string, string>[];
20
- }[];
21
- declare function applyOptionalRequestFields(req: ProviderCompleteRequest, camel: Record<string, unknown>): void;
22
- declare function baseInteractionsBody(req: ProviderCompleteRequest): Record<string, unknown>;
23
3
  /** Interactions REST body for one complete() call (Google snake_case keys). */
24
4
  declare function toInteractionsBody(req: ProviderCompleteRequest): Record<string, unknown>;
25
5
  export { camelToSnake, toInteractionsBody };
26
- /** @internal Exported for direct unit testing only. */
27
- export declare const _internals: {
28
- camelToSnake: typeof camelToSnake;
29
- toGoogleValue: typeof toGoogleValue;
30
- wirePart: typeof wirePart;
31
- userInputStep: typeof userInputStep;
32
- historyStep: typeof historyStep;
33
- systemHoldsUserInput: typeof systemHoldsUserInput;
34
- jsonResponseFormat: typeof jsonResponseFormat;
35
- attachResponseFormat: typeof attachResponseFormat;
36
- attachSpeechConfig: typeof attachSpeechConfig;
37
- inputStepsFromRequest: typeof inputStepsFromRequest;
38
- applyOptionalRequestFields: typeof applyOptionalRequestFields;
39
- baseInteractionsBody: typeof baseInteractionsBody;
40
- toInteractionsBody: typeof toInteractionsBody;
41
- };
@@ -1,6 +1,7 @@
1
1
  import { TheorumError } from '../guardrails/error.js';
2
2
  import { getTool } from '../kernel/registry/catalog.js';
3
3
  import { getStructured } from '../kernel/registry/schemas.js';
4
+ import { exposeForTests } from './expose-for-tests.js';
4
5
  function camelToSnake(key) {
5
6
  return key.replaceAll(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`);
6
7
  }
@@ -151,8 +152,7 @@ function toInteractionsBody(req) {
151
152
  return toGoogleValue(camel);
152
153
  }
153
154
  export { camelToSnake, toInteractionsBody };
154
- /** @internal Exported for direct unit testing only. */
155
- export const _internals = {
155
+ exposeForTests('interactions', {
156
156
  camelToSnake,
157
157
  toGoogleValue,
158
158
  wirePart,
@@ -166,4 +166,4 @@ export const _internals = {
166
166
  applyOptionalRequestFields,
167
167
  baseInteractionsBody,
168
168
  toInteractionsBody,
169
- };
169
+ });
@@ -13,26 +13,7 @@ interface GeminiTransport {
13
13
  wait?: (ms: number) => Promise<void>;
14
14
  fetch?: typeof fetch;
15
15
  }
16
- declare function waitDefault(ms: number): Promise<void>;
17
- declare function isQuota(err: unknown): boolean;
18
- declare function isTransientHttp(status: number): boolean;
19
- declare function isTransientThrown(err: unknown): boolean;
20
- declare function requireKey(vault: GeminiVault, bucket: GeminiBucket): string;
21
- declare function backoffMs(attempt: number): number;
22
- declare function canOverflow(bucket: GeminiBucket, vault: GeminiVault, primary: string): string | undefined;
23
16
  declare function withGeminiKey<T>(bucket: GeminiBucket, run: (apiKey: string) => Promise<T>, transport: GeminiTransport): Promise<T>;
24
- declare function withApiKey(init: RequestInit, apiKey: string): RequestInit;
25
17
  declare function fetchGemini(url: string, init: RequestInit, bucket: GeminiBucket, transport: GeminiTransport): Promise<Response>;
26
18
  export type { GeminiTransport, GeminiVault };
27
19
  export { fetchGemini, withGeminiKey };
28
- /** @internal Exported for direct unit testing only. */
29
- export declare const _internals: {
30
- waitDefault: typeof waitDefault;
31
- isQuota: typeof isQuota;
32
- isTransientHttp: typeof isTransientHttp;
33
- isTransientThrown: typeof isTransientThrown;
34
- requireKey: typeof requireKey;
35
- backoffMs: typeof backoffMs;
36
- canOverflow: typeof canOverflow;
37
- withApiKey: typeof withApiKey;
38
- };
@@ -7,6 +7,7 @@
7
7
  * @module
8
8
  */
9
9
  import { isAbortError, TheorumError, UPSTREAM_FAILED } from '../guardrails/error.js';
10
+ import { exposeForTests } from './expose-for-tests.js';
10
11
  const ATTEMPTS = 3;
11
12
  const LAST_ATTEMPT = ATTEMPTS - 1;
12
13
  const BACKOFF_FIRST_MS = 1000;
@@ -137,8 +138,7 @@ async function fetchGemini(url, init, bucket, transport) {
137
138
  return last;
138
139
  }
139
140
  export { fetchGemini, withGeminiKey };
140
- /** @internal Exported for direct unit testing only. */
141
- export const _internals = {
141
+ exposeForTests('keys', {
142
142
  waitDefault,
143
143
  isQuota,
144
144
  isTransientHttp,
@@ -147,4 +147,4 @@ export const _internals = {
147
147
  backoffMs,
148
148
  canOverflow,
149
149
  withApiKey,
150
- };
150
+ });
@@ -7,126 +7,9 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import { createOpenRouter, type OpenRouterChatSettings } from '@openrouter/ai-sdk-provider';
11
- import { type LanguageModelUsage, type ModelMessage, streamText, type TextStreamPart, type ToolSet } from 'ai';
12
- import type { DynamicToolDeclaration, InteractionPart, ModelProvider, ProviderCompleteRequest, TurnEvent, TurnHistoryMessage, TurnTokens } from '../kernel/types.js';
10
+ import type { ModelProvider } from '../kernel/types.js';
13
11
  import { type OpenRouterConfig, resolveOpenRouterModel, toOpenRouterPayload } from './openrouter-payload.js';
14
- interface StreamAccumulator {
15
- text: string;
16
- evidenceSeen: boolean;
17
- emittedTokens: boolean;
18
- errored: boolean;
19
- }
20
- interface OpenRouterStreamContext {
21
- openrouter: ReturnType<typeof createOpenRouter>;
22
- modelName: string;
23
- }
24
- type JsonValue = string | number | boolean | null | JsonValue[] | {
25
- [key: string]: JsonValue;
26
- };
27
- type ProviderOptions = Record<string, {
28
- [key: string]: JsonValue;
29
- }>;
30
- declare function trimApiKey(explicitKey?: string): string | undefined;
31
- declare function createAccumulator(): StreamAccumulator;
32
- declare function mediaPart(part: InteractionPart): Record<string, unknown>;
33
- declare function contentFromParts(parts: InteractionPart[]): string | Array<Record<string, unknown>>;
34
- declare function parseToolInput(raw: string): unknown;
35
- declare function stringDefault(value: string | undefined, fallback: string): string;
36
- declare function fallbackToolCallId(name?: string): string;
37
- declare function toolResultContent(msg: TurnHistoryMessage): ModelMessage;
38
- declare function assistantToolCallContent(msg: TurnHistoryMessage): ModelMessage | null;
39
- declare function historyMessage(msg: TurnHistoryMessage): ModelMessage | null;
40
- declare function contentFromOptionalParts(parts: InteractionPart[] | undefined, text: string | undefined): string | Array<Record<string, unknown>>;
41
- declare function contentHistoryMessage(msg: TurnHistoryMessage): ModelMessage;
42
- declare function sourceEvent(part: Extract<TextStreamPart<ToolSet>, {
43
- type: 'source';
44
- }>): TurnEvent;
45
- declare function buildMessages(req: ProviderCompleteRequest): ModelMessage[];
46
- declare function schemaForTool(decl: DynamicToolDeclaration): Record<string, unknown>;
47
- declare function buildTools(dynamicTools?: DynamicToolDeclaration[]): ToolSet | undefined;
48
- declare function openRouterSettings(req: ProviderCompleteRequest): OpenRouterChatSettings | undefined;
49
- declare function tokensFromUsage(usage: LanguageModelUsage): TurnTokens | undefined;
50
- declare function rawRecord(value: unknown): Record<string, unknown> | undefined;
51
- declare function stringArray(value: unknown): string[] | undefined;
52
- declare function metadataRecord(raw: Record<string, unknown>, key: string): Record<string, unknown> | undefined;
53
- declare function citationCandidates(raw: Record<string, unknown>): unknown[];
54
- declare function nestedCitations(raw: Record<string, unknown>): string[] | undefined;
55
- declare function metadataAnnotations(raw: Record<string, unknown>): unknown[] | undefined;
56
- declare function evidenceFromMetadata(metadata: unknown, acc: StreamAccumulator): TurnEvent | undefined;
57
- declare function toolArguments(input: unknown): Record<string, unknown> | undefined;
58
- declare function toolResultData(output: unknown): Record<string, unknown> | undefined;
59
- declare function rawThoughtEvent(raw: Record<string, unknown>): TurnEvent | undefined;
60
- declare function rawChoiceMessageEvidence(raw: Record<string, unknown>, acc: StreamAccumulator): TurnEvent | undefined;
61
- declare function rawEvents(raw: unknown, acc: StreamAccumulator): TurnEvent[];
62
- declare function toolCallEvent(part: Extract<TextStreamPart<ToolSet>, {
63
- type: 'tool-call';
64
- }>): TurnEvent;
65
- declare function toolResultEvent(part: Extract<TextStreamPart<ToolSet>, {
66
- type: 'tool-result';
67
- }>): TurnEvent;
68
- declare function tokenEvent(part: Extract<TextStreamPart<ToolSet>, {
69
- type: 'finish';
70
- }>): TurnEvent | undefined;
71
- declare function providerMetadataEvent(part: TextStreamPart<ToolSet>, acc: StreamAccumulator): TurnEvent | undefined;
72
- declare function eventFromPart(part: TextStreamPart<ToolSet>, acc: StreamAccumulator): TurnEvent[];
73
- declare function primaryEventFromPart(part: TextStreamPart<ToolSet>, acc: StreamAccumulator): TurnEvent | undefined;
74
- declare function finishEvent(part: Extract<TextStreamPart<ToolSet>, {
75
- type: 'finish';
76
- }>, acc: StreamAccumulator): TurnEvent | undefined;
77
- declare function streamTextOptions(req: ProviderCompleteRequest, context: OpenRouterStreamContext): Parameters<typeof streamText>[0];
78
- declare function missingOpenRouterKey(): TurnEvent;
79
- declare function finalEvents(req: ProviderCompleteRequest, acc: StreamAccumulator): Generator<TurnEvent>;
80
- declare function responseFormatFor(req: ProviderCompleteRequest): Record<string, JsonValue> | undefined;
81
- declare function providerOptionsFor(req: ProviderCompleteRequest): ProviderOptions | undefined;
82
- declare function openRouterHeaders(config: OpenRouterConfig): Record<string, string> | undefined;
83
12
  /** Create a `ModelProvider` backed by OpenRouter through AI SDK Core. */
84
13
  declare function createOpenRouterProvider(config?: OpenRouterConfig): ModelProvider;
85
14
  export type { OpenRouterConfig };
86
15
  export { createOpenRouterProvider, resolveOpenRouterModel, toOpenRouterPayload };
87
- /** @internal Exported for direct unit testing only. */
88
- export declare const _internals: {
89
- trimApiKey: typeof trimApiKey;
90
- createAccumulator: typeof createAccumulator;
91
- mediaPart: typeof mediaPart;
92
- contentFromParts: typeof contentFromParts;
93
- parseToolInput: typeof parseToolInput;
94
- stringDefault: typeof stringDefault;
95
- fallbackToolCallId: typeof fallbackToolCallId;
96
- toolResultContent: typeof toolResultContent;
97
- assistantToolCallContent: typeof assistantToolCallContent;
98
- historyMessage: typeof historyMessage;
99
- contentFromOptionalParts: typeof contentFromOptionalParts;
100
- contentHistoryMessage: typeof contentHistoryMessage;
101
- buildMessages: typeof buildMessages;
102
- schemaForTool: typeof schemaForTool;
103
- buildTools: typeof buildTools;
104
- openRouterSettings: typeof openRouterSettings;
105
- tokensFromUsage: typeof tokensFromUsage;
106
- rawRecord: typeof rawRecord;
107
- stringArray: typeof stringArray;
108
- metadataRecord: typeof metadataRecord;
109
- citationCandidates: typeof citationCandidates;
110
- nestedCitations: typeof nestedCitations;
111
- metadataAnnotations: typeof metadataAnnotations;
112
- evidenceFromMetadata: typeof evidenceFromMetadata;
113
- toolArguments: typeof toolArguments;
114
- toolResultData: typeof toolResultData;
115
- rawThoughtEvent: typeof rawThoughtEvent;
116
- rawChoiceMessageEvidence: typeof rawChoiceMessageEvidence;
117
- rawEvents: typeof rawEvents;
118
- toolCallEvent: typeof toolCallEvent;
119
- toolResultEvent: typeof toolResultEvent;
120
- tokenEvent: typeof tokenEvent;
121
- providerMetadataEvent: typeof providerMetadataEvent;
122
- eventFromPart: typeof eventFromPart;
123
- primaryEventFromPart: typeof primaryEventFromPart;
124
- finishEvent: typeof finishEvent;
125
- sourceEvent: typeof sourceEvent;
126
- finalEvents: typeof finalEvents;
127
- responseFormatFor: typeof responseFormatFor;
128
- providerOptionsFor: typeof providerOptionsFor;
129
- openRouterHeaders: typeof openRouterHeaders;
130
- missingOpenRouterKey: typeof missingOpenRouterKey;
131
- streamTextOptions: typeof streamTextOptions;
132
- };
@@ -13,6 +13,7 @@ import { isAbortError, toErrorEvent } from '../guardrails/error.js';
13
13
  import { tryStructured } from '../kernel/engine/delta.js';
14
14
  import { getStructured } from '../kernel/registry/schemas.js';
15
15
  import { resolveOpenRouterModel, resolveOpenRouterPlugins, toOpenRouterPayload, } from './openrouter-payload.js';
16
+ import { exposeForTests } from './expose-for-tests.js';
16
17
  function trimApiKey(explicitKey) {
17
18
  if (explicitKey?.trim()) {
18
19
  return explicitKey.trim();
@@ -506,8 +507,7 @@ function createOpenRouterProvider(config = {}) {
506
507
  };
507
508
  }
508
509
  export { createOpenRouterProvider, resolveOpenRouterModel, toOpenRouterPayload };
509
- /** @internal Exported for direct unit testing only. */
510
- export const _internals = {
510
+ exposeForTests('openrouter', {
511
511
  trimApiKey,
512
512
  createAccumulator,
513
513
  mediaPart,
@@ -551,4 +551,4 @@ export const _internals = {
551
551
  openRouterHeaders,
552
552
  missingOpenRouterKey,
553
553
  streamTextOptions,
554
- };
554
+ });
@@ -3,12 +3,5 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- declare function writeAscii(view: DataView, offset: number, str: string): void;
7
6
  /** Wrap raw PCM bytes in a RIFF/WAVE container. */
8
7
  export declare function wrapPcmAsWav(pcm: Uint8Array, sampleRate?: number): Uint8Array;
9
- /** @internal Exported for direct unit testing only. */
10
- export declare const _internals: {
11
- writeAscii: typeof writeAscii;
12
- wrapPcmAsWav: typeof wrapPcmAsWav;
13
- };
14
- export {};
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
+ import { exposeForTests } from './expose-for-tests.js';
6
7
  const SAMPLE_RATE = 24000;
7
8
  function writeAscii(view, offset, str) {
8
9
  for (let i = 0; i < str.length; i++)
@@ -33,5 +34,4 @@ export function wrapPcmAsWav(pcm, sampleRate = SAMPLE_RATE) {
33
34
  new Uint8Array(buf, 44).set(pcm);
34
35
  return new Uint8Array(buf);
35
36
  }
36
- /** @internal Exported for direct unit testing only. */
37
- export const _internals = { writeAscii, wrapPcmAsWav };
37
+ exposeForTests('pcm', { writeAscii, wrapPcmAsWav });
@@ -8,36 +8,8 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import type { ModelProvider, ProviderCompleteRequest, TurnEvent } from '../kernel/types.js';
11
+ import type { ModelProvider } from '../kernel/types.js';
12
12
  import { type GeminiTransport } from './keys.js';
13
- declare function base64ToBytes(data: string): Uint8Array;
14
- declare function bytesToBase64(bytes: Uint8Array): string;
15
- declare function isRawPcmMime(mime: string): boolean;
16
- /** Google TTS returns raw PCM; wrap as WAV for hosts (matches OpenRouter pcm path). */
17
- declare function normalizeSpeechMedia(event: TurnEvent, speech: boolean): TurnEvent;
18
- declare function eventType(event: Record<string, unknown>): string;
19
- declare function isDeltaEvent(kind: string): boolean;
20
- declare function isCompleteEvent(kind: string): boolean;
21
- declare function foldDeltaPayload(event: Record<string, unknown>, acc: {
22
- text: string;
23
- }): TurnEvent[];
24
- declare function foldPayload(event: Record<string, unknown>, acc: {
25
- text: string;
26
- }): TurnEvent[];
27
- declare function withTap(req: ProviderCompleteRequest, transport: GeminiTransport): GeminiTransport;
28
13
  /** Create a `ModelProvider` backed by Google Interactions streaming. */
29
14
  declare function createInteractionsProvider(transport: GeminiTransport): ModelProvider;
30
15
  export { createInteractionsProvider };
31
- /** @internal Exported for direct unit testing only. */
32
- export declare const _internals: {
33
- base64ToBytes: typeof base64ToBytes;
34
- bytesToBase64: typeof bytesToBase64;
35
- isRawPcmMime: typeof isRawPcmMime;
36
- normalizeSpeechMedia: typeof normalizeSpeechMedia;
37
- eventType: typeof eventType;
38
- isDeltaEvent: typeof isDeltaEvent;
39
- isCompleteEvent: typeof isCompleteEvent;
40
- foldDeltaPayload: typeof foldDeltaPayload;
41
- foldPayload: typeof foldPayload;
42
- withTap: typeof withTap;
43
- };
@@ -15,6 +15,7 @@ import { toInteractionsBody } from './interactions.js';
15
15
  import { fetchGemini } from './keys.js';
16
16
  import { wrapPcmAsWav } from './pcm.js';
17
17
  import { INTERACTIONS_URL, takeSsePayloads } from './sse.js';
18
+ import { exposeForTests } from './expose-for-tests.js';
18
19
  const HTTP_OK = 200;
19
20
  function base64ToBytes(data) {
20
21
  const bin = atob(data);
@@ -161,8 +162,7 @@ function createInteractionsProvider(transport) {
161
162
  };
162
163
  }
163
164
  export { createInteractionsProvider };
164
- /** @internal Exported for direct unit testing only. */
165
- export const _internals = {
165
+ exposeForTests('provider', {
166
166
  base64ToBytes,
167
167
  bytesToBase64,
168
168
  isRawPcmMime,
@@ -173,4 +173,4 @@ export const _internals = {
173
173
  foldDeltaPayload,
174
174
  foldPayload,
175
175
  withTap,
176
- };
176
+ });
@@ -6,8 +6,7 @@
6
6
  *
7
7
  * @module
8
8
  */
9
- import type { InteractionPart, ModelProvider, ProfileSpeechSpec, ProviderCompleteRequest, SpeechAudioFormat, TurnEvent } from '../kernel/types.js';
10
- declare function bytesToBase64(bytes: Uint8Array): string;
9
+ import type { ModelProvider, ProviderCompleteRequest, TurnEvent } from '../kernel/types.js';
11
10
  /** Credentials for the openAi speech path (same shape as OpenRouter chat config + voice). */
12
11
  export interface SpeechProviderConfig {
13
12
  apiKey?: string;
@@ -18,23 +17,7 @@ export interface SpeechProviderConfig {
18
17
  siteName?: string;
19
18
  fetch?: typeof fetch;
20
19
  }
21
- declare function extractInputText(input: InteractionPart[]): string;
22
- declare function resolveSpeechWireModel(req: ProviderCompleteRequest): string;
23
- declare function buildHeaders(apiKey: string, config: SpeechProviderConfig): Record<string, string>;
24
- declare function buildPayload(req: ProviderCompleteRequest, text: string, speech: ProfileSpeechSpec | undefined, configVoice?: string): Record<string, unknown>;
25
- declare function requestSpeech(apiKey: string, text: string, req: ProviderCompleteRequest, config: SpeechProviderConfig): Promise<Response>;
26
- declare function yieldSpeechSuccess(rawBytes: Uint8Array, text: string, format: SpeechAudioFormat): Generator<TurnEvent>;
27
20
  declare function streamSpeech(req: ProviderCompleteRequest, config?: SpeechProviderConfig): AsyncGenerator<TurnEvent>;
28
21
  /** Internal ModelProvider for openAi speech roles. */
29
22
  declare function createSpeechProvider(config?: SpeechProviderConfig): ModelProvider;
30
23
  export { createSpeechProvider, streamSpeech };
31
- /** @internal Exported for direct unit testing only. */
32
- export declare const _internals: {
33
- bytesToBase64: typeof bytesToBase64;
34
- extractInputText: typeof extractInputText;
35
- resolveSpeechWireModel: typeof resolveSpeechWireModel;
36
- buildHeaders: typeof buildHeaders;
37
- buildPayload: typeof buildPayload;
38
- requestSpeech: typeof requestSpeech;
39
- yieldSpeechSuccess: typeof yieldSpeechSuccess;
40
- };
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { toErrorEvent } from '../guardrails/error.js';
10
10
  import { wrapPcmAsWav } from './pcm.js';
11
+ import { exposeForTests } from './expose-for-tests.js';
11
12
  const HTTP_OK = 200;
12
13
  function bytesToBase64(bytes) {
13
14
  let bin = '';
@@ -124,8 +125,7 @@ function createSpeechProvider(config = {}) {
124
125
  };
125
126
  }
126
127
  export { createSpeechProvider, streamSpeech };
127
- /** @internal Exported for direct unit testing only. */
128
- export const _internals = {
128
+ exposeForTests('speech', {
129
129
  bytesToBase64,
130
130
  extractInputText,
131
131
  resolveSpeechWireModel,
@@ -133,4 +133,4 @@ export const _internals = {
133
133
  buildPayload,
134
134
  requestSpeech,
135
135
  yieldSpeechSuccess,
136
- };
136
+ });
@@ -1,15 +1,7 @@
1
1
  declare const INTERACTIONS_URL = "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse";
2
- declare function asObject(parsed: unknown): Record<string, unknown> | undefined;
3
- declare function dataRecord(raw: string, sseEvent: string): Record<string, unknown>;
4
2
  declare function takeSsePayloads(buffer: string, pendingEvent?: string): {
5
3
  rest: string;
6
4
  payloads: Record<string, unknown>[];
7
5
  pendingEvent: string;
8
6
  };
9
7
  export { INTERACTIONS_URL, takeSsePayloads };
10
- /** @internal Exported for direct unit testing only. */
11
- export declare const _internals: {
12
- asObject: typeof asObject;
13
- dataRecord: typeof dataRecord;
14
- takeSsePayloads: typeof takeSsePayloads;
15
- };
@@ -1,3 +1,4 @@
1
+ import { exposeForTests } from './expose-for-tests.js';
1
2
  const INTERACTIONS_URL = 'https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse';
2
3
  const DATA_PREFIX = 'data: ';
3
4
  const EVENT_PREFIX = 'event: ';
@@ -51,5 +52,4 @@ function takeSsePayloads(buffer, pendingEvent = '') {
51
52
  return { rest, payloads, pendingEvent: sseEvent };
52
53
  }
53
54
  export { INTERACTIONS_URL, takeSsePayloads };
54
- /** @internal Exported for direct unit testing only. */
55
- export const _internals = { asObject, dataRecord, takeSsePayloads };
55
+ exposeForTests('sse', { asObject, dataRecord, takeSsePayloads });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "theorum",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, dynamic tools, provider adapters, guardrails, and host-injected traces.",
5
5
  "keywords": [
6
6
  "agent",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "scripts": {},
54
54
  "bin": {
55
- "theorum": "./esm/src/cli/index.js"
55
+ "theorum": "esm/src/cli/index.js"
56
56
  },
57
57
  "type": "module",
58
58
  "sideEffects": false,
@@ -65,4 +65,4 @@
65
65
  "@types/node": "^20.9.0"
66
66
  },
67
67
  "_generatedBy": "dnt@0.43.2"
68
- }
68
+ }