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.
Files changed (41) hide show
  1. package/docs/AGENT_PROFILE_CONTRACT.md +1 -0
  2. package/esm/mod.d.ts +1 -1
  3. package/esm/mod.js +1 -1
  4. package/esm/src/guardrails/error.d.ts +7 -1
  5. package/esm/src/guardrails/error.js +31 -1
  6. package/esm/src/guardrails/mod.d.ts +1 -1
  7. package/esm/src/guardrails/mod.js +1 -1
  8. package/esm/src/kernel/engine/runner/gates.js +2 -1
  9. package/esm/src/kernel/engine/runner/mod.js +2 -0
  10. package/esm/src/kernel/engine/runner/steps.js +5 -2
  11. package/esm/src/kernel/engine/runner/stream.d.ts +1 -0
  12. package/esm/src/kernel/engine/runner/stream.js +5 -2
  13. package/esm/src/kernel/types.d.ts +7 -0
  14. package/esm/src/observability/trace-record.js +4 -3
  15. package/esm/src/providers/create-provider.d.ts +7 -0
  16. package/esm/src/providers/create-provider.js +2 -0
  17. package/esm/src/providers/gemini-tape.d.ts +14 -0
  18. package/esm/src/providers/gemini-tape.js +9 -0
  19. package/esm/src/providers/google-tap.d.ts +10 -0
  20. package/esm/src/providers/google-tap.js +2 -0
  21. package/esm/src/providers/interactions.d.ts +37 -1
  22. package/esm/src/providers/interactions.js +16 -0
  23. package/esm/src/providers/keys.d.ts +19 -0
  24. package/esm/src/providers/keys.js +24 -3
  25. package/esm/src/providers/openrouter-payload.d.ts +9 -2
  26. package/esm/src/providers/openrouter-payload.js +23 -7
  27. package/esm/src/providers/openrouter.d.ts +118 -1
  28. package/esm/src/providers/openrouter.js +106 -141
  29. package/esm/src/providers/pcm.d.ts +7 -0
  30. package/esm/src/providers/pcm.js +2 -0
  31. package/esm/src/providers/provider.d.ts +29 -1
  32. package/esm/src/providers/provider.js +18 -2
  33. package/esm/src/providers/speech.d.ts +18 -1
  34. package/esm/src/providers/speech.js +11 -0
  35. package/esm/src/providers/sse.d.ts +8 -0
  36. package/esm/src/providers/sse.js +2 -0
  37. package/esm/src/streaming/mod.d.ts +7 -0
  38. package/esm/src/streaming/mod.js +7 -0
  39. package/esm/src/streaming/readStreamingJsonStringField.d.ts +6 -0
  40. package/esm/src/streaming/readStreamingJsonStringField.js +55 -0
  41. 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
+ };
@@ -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,7 @@
1
+ /**
2
+ * Structured-output streaming helpers (incomplete JSON text buffers).
3
+ *
4
+ * @module
5
+ */
6
+ import "../../_dnt.polyfills.js";
7
+ export { readStreamingJsonStringField } from './readStreamingJsonStringField.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Structured-output streaming helpers (incomplete JSON text buffers).
3
+ *
4
+ * @module
5
+ */
6
+ import "../../_dnt.polyfills.js";
7
+ export { readStreamingJsonStringField } from './readStreamingJsonStringField.js';
@@ -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.6",
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": "1.5.4",
58
- "ai": "5.0.244",
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": {