theorum 0.1.6 → 0.1.9
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/docs/AGENT_PROFILE_CONTRACT.md +1 -0
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/src/guardrails/error.d.ts +7 -1
- package/esm/src/guardrails/error.js +31 -1
- package/esm/src/guardrails/mod.d.ts +1 -1
- package/esm/src/guardrails/mod.js +1 -1
- package/esm/src/kernel/engine/runner/gates.js +2 -1
- package/esm/src/kernel/engine/runner/mod.js +2 -0
- package/esm/src/kernel/engine/runner/steps.js +5 -2
- package/esm/src/kernel/engine/runner/stream.d.ts +1 -0
- package/esm/src/kernel/engine/runner/stream.js +5 -2
- package/esm/src/kernel/types.d.ts +7 -0
- package/esm/src/observability/trace-record.js +4 -3
- package/esm/src/providers/create-provider.d.ts +7 -0
- package/esm/src/providers/create-provider.js +2 -0
- package/esm/src/providers/gemini-tape.d.ts +14 -0
- package/esm/src/providers/gemini-tape.js +9 -0
- package/esm/src/providers/google-tap.d.ts +10 -0
- package/esm/src/providers/google-tap.js +2 -0
- package/esm/src/providers/interactions.d.ts +37 -1
- package/esm/src/providers/interactions.js +16 -0
- package/esm/src/providers/keys.d.ts +19 -0
- package/esm/src/providers/keys.js +24 -3
- package/esm/src/providers/openrouter-payload.d.ts +9 -2
- package/esm/src/providers/openrouter-payload.js +23 -7
- package/esm/src/providers/openrouter.d.ts +118 -1
- package/esm/src/providers/openrouter.js +106 -141
- package/esm/src/providers/pcm.d.ts +7 -0
- package/esm/src/providers/pcm.js +2 -0
- package/esm/src/providers/provider.d.ts +29 -1
- package/esm/src/providers/provider.js +18 -2
- package/esm/src/providers/speech.d.ts +18 -1
- package/esm/src/providers/speech.js +11 -0
- package/esm/src/providers/sse.d.ts +8 -0
- package/esm/src/providers/sse.js +2 -0
- package/esm/src/streaming/mod.d.ts +7 -0
- package/esm/src/streaming/mod.js +7 -0
- package/esm/src/streaming/readStreamingJsonStringField.d.ts +6 -0
- package/esm/src/streaming/readStreamingJsonStringField.js +55 -0
- package/package.json +6 -3
|
@@ -1,7 +1,15 @@
|
|
|
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>;
|
|
2
4
|
declare function takeSsePayloads(buffer: string, pendingEvent?: string): {
|
|
3
5
|
rest: string;
|
|
4
6
|
payloads: Record<string, unknown>[];
|
|
5
7
|
pendingEvent: string;
|
|
6
8
|
};
|
|
7
9
|
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
|
+
};
|
package/esm/src/providers/sse.js
CHANGED
|
@@ -51,3 +51,5 @@ function takeSsePayloads(buffer, pendingEvent = '') {
|
|
|
51
51
|
return { rest, payloads, pendingEvent: sseEvent };
|
|
52
52
|
}
|
|
53
53
|
export { INTERACTIONS_URL, takeSsePayloads };
|
|
54
|
+
/** @internal Exported for direct unit testing only. */
|
|
55
|
+
export const _internals = { asObject, dataRecord, takeSsePayloads };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read one string field from incomplete JSON while structured output streams as text deltas.
|
|
3
|
+
*
|
|
4
|
+
* The buffer may lack a closing quote; any decoded prefix is returned for live preview.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readStreamingJsonStringField(jsonText: string, key: string): string | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const JSON_ESCAPES = {
|
|
2
|
+
n: '\n',
|
|
3
|
+
t: '\t',
|
|
4
|
+
r: '\r',
|
|
5
|
+
'"': '"',
|
|
6
|
+
'\\': '\\',
|
|
7
|
+
'/': '/',
|
|
8
|
+
};
|
|
9
|
+
function decodeEscapedChar(ch, jsonText, index) {
|
|
10
|
+
if (ch === 'u' && index + 4 < jsonText.length) {
|
|
11
|
+
const hex = jsonText.slice(index + 1, index + 5);
|
|
12
|
+
if (/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
13
|
+
return { text: String.fromCharCode(Number.parseInt(hex, 16)), next: index + 4 };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const mapped = JSON_ESCAPES[ch];
|
|
17
|
+
return { text: mapped ?? ch, next: index };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read one string field from incomplete JSON while structured output streams as text deltas.
|
|
21
|
+
*
|
|
22
|
+
* The buffer may lack a closing quote; any decoded prefix is returned for live preview.
|
|
23
|
+
*/
|
|
24
|
+
export function readStreamingJsonStringField(jsonText, key) {
|
|
25
|
+
const keyPattern = new RegExp(`"${key}"\\s*:\\s*"`);
|
|
26
|
+
const match = keyPattern.exec(jsonText);
|
|
27
|
+
if (!match || match.index === undefined) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
let i = match.index + match[0].length;
|
|
31
|
+
let result = '';
|
|
32
|
+
let escaped = false;
|
|
33
|
+
while (i < jsonText.length) {
|
|
34
|
+
const ch = jsonText[i];
|
|
35
|
+
if (escaped) {
|
|
36
|
+
const decoded = decodeEscapedChar(ch, jsonText, i);
|
|
37
|
+
result += decoded.text;
|
|
38
|
+
i = decoded.next;
|
|
39
|
+
escaped = false;
|
|
40
|
+
i += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (ch === '\\') {
|
|
44
|
+
escaped = true;
|
|
45
|
+
}
|
|
46
|
+
else if (ch === '"') {
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
result += ch;
|
|
51
|
+
}
|
|
52
|
+
i += 1;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theorum",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"./presets/google": {
|
|
47
47
|
"import": "./esm/src/presets/google.js"
|
|
48
|
+
},
|
|
49
|
+
"./streaming": {
|
|
50
|
+
"import": "./esm/src/streaming/mod.js"
|
|
48
51
|
}
|
|
49
52
|
},
|
|
50
53
|
"scripts": {},
|
|
@@ -54,8 +57,8 @@
|
|
|
54
57
|
"type": "module",
|
|
55
58
|
"sideEffects": false,
|
|
56
59
|
"dependencies": {
|
|
57
|
-
"@openrouter/ai-sdk-provider": "
|
|
58
|
-
"ai": "
|
|
60
|
+
"@openrouter/ai-sdk-provider": "^3.0.0",
|
|
61
|
+
"ai": "^7.0.0",
|
|
59
62
|
"@deno/shim-deno": "~0.18.0"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|