@alexkroman1/aai 1.7.1 → 1.8.0

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 (133) hide show
  1. package/.turbo/turbo-build.log +11 -9
  2. package/CHANGELOG.md +10 -0
  3. package/dist/{_internal-types-CrnTi9Ew.js → _internal-types-CfOAbK6V.js} +22 -35
  4. package/dist/constants-y68COEGj.js +29 -0
  5. package/dist/host/_base64.d.ts +2 -0
  6. package/dist/host/_mock-ws.d.ts +0 -61
  7. package/dist/host/_pipeline-test-fakes.d.ts +7 -4
  8. package/dist/host/_run-code.d.ts +0 -25
  9. package/dist/host/_runtime-conformance.d.ts +3 -34
  10. package/dist/host/memory-vector.d.ts +0 -11
  11. package/dist/host/providers/resolve-kv.d.ts +0 -7
  12. package/dist/host/providers/resolve-vector.d.ts +0 -8
  13. package/dist/host/providers/stt/assemblyai.d.ts +0 -14
  14. package/dist/host/providers/stt/deepgram.d.ts +2 -14
  15. package/dist/host/providers/stt/soniox.d.ts +0 -22
  16. package/dist/host/providers/tts/rime.d.ts +10 -31
  17. package/dist/host/runtime-barrel.js +619 -630
  18. package/dist/host/runtime-config.d.ts +9 -6
  19. package/dist/host/runtime.d.ts +3 -0
  20. package/dist/host/to-vercel-tools.d.ts +3 -33
  21. package/dist/host/transports/openai-realtime-transport.d.ts +43 -0
  22. package/dist/host/unstorage-kv.d.ts +0 -26
  23. package/dist/index.js +3 -3
  24. package/dist/openai-realtime-cjPAHMMx.js +10 -0
  25. package/dist/sdk/_internal-types.d.ts +6 -55
  26. package/dist/sdk/allowed-hosts.d.ts +4 -3
  27. package/dist/sdk/constants.d.ts +4 -29
  28. package/dist/sdk/define.d.ts +7 -4
  29. package/dist/sdk/kv.d.ts +13 -37
  30. package/dist/sdk/manifest-barrel.js +1 -1
  31. package/dist/sdk/manifest.d.ts +8 -2
  32. package/dist/sdk/protocol.js +1 -1
  33. package/dist/sdk/providers/s2s/openai-realtime.d.ts +17 -0
  34. package/dist/sdk/providers/s2s-barrel.d.ts +9 -0
  35. package/dist/sdk/providers/s2s-barrel.js +2 -0
  36. package/dist/sdk/providers/tts/rime.d.ts +1 -1
  37. package/dist/sdk/providers.d.ts +6 -2
  38. package/dist/sdk/types.d.ts +7 -1
  39. package/dist/{types-KUgezM6u.js → types-DOWVZhb9.js} +1 -7
  40. package/dist/{ws-upgrade-BeOQ7fXL.js → ws-upgrade-CG8-by1n.js} +2 -3
  41. package/host/_base64.ts +9 -0
  42. package/host/_mock-ws.ts +0 -65
  43. package/host/_pipeline-test-fakes.ts +19 -31
  44. package/host/_run-code.ts +10 -53
  45. package/host/_runtime-conformance.ts +3 -44
  46. package/host/_test-utils.ts +20 -42
  47. package/host/builtin-tools.test.ts +127 -222
  48. package/host/builtin-tools.ts +6 -10
  49. package/host/cleanup.test.ts +30 -73
  50. package/host/integration/pipeline-reference.integration.test.ts +12 -17
  51. package/host/integration.test.ts +0 -7
  52. package/host/memory-vector.test.ts +3 -1
  53. package/host/memory-vector.ts +16 -21
  54. package/host/pinecone-vector.test.ts +14 -17
  55. package/host/pinecone-vector.ts +10 -19
  56. package/host/providers/providers.test-d.ts +5 -3
  57. package/host/providers/resolve-kv.ts +23 -41
  58. package/host/providers/resolve-vector.ts +3 -12
  59. package/host/providers/resolve.test.ts +15 -28
  60. package/host/providers/resolve.ts +24 -24
  61. package/host/providers/stt/assemblyai.test.ts +2 -14
  62. package/host/providers/stt/assemblyai.ts +12 -35
  63. package/host/providers/stt/deepgram.test.ts +23 -83
  64. package/host/providers/stt/deepgram.ts +15 -40
  65. package/host/providers/stt/elevenlabs.test.ts +26 -38
  66. package/host/providers/stt/elevenlabs.ts +10 -9
  67. package/host/providers/stt/soniox.test.ts +35 -85
  68. package/host/providers/stt/soniox.ts +8 -53
  69. package/host/providers/tts/cartesia.test.ts +19 -58
  70. package/host/providers/tts/cartesia.ts +36 -66
  71. package/host/providers/tts/rime.test.ts +12 -38
  72. package/host/providers/tts/rime.ts +23 -86
  73. package/host/runtime-config.test.ts +9 -9
  74. package/host/runtime-config.ts +16 -22
  75. package/host/runtime.test.ts +111 -73
  76. package/host/runtime.ts +138 -86
  77. package/host/s2s.test.ts +92 -191
  78. package/host/s2s.ts +55 -49
  79. package/host/server-shutdown.test.ts +9 -30
  80. package/host/server.test.ts +2 -13
  81. package/host/server.ts +85 -100
  82. package/host/session-core.test.ts +15 -30
  83. package/host/session-core.ts +10 -13
  84. package/host/session-prompt.test.ts +1 -5
  85. package/host/to-vercel-tools.test.ts +53 -72
  86. package/host/to-vercel-tools.ts +9 -39
  87. package/host/tool-executor.test.ts +25 -51
  88. package/host/tool-executor.ts +18 -12
  89. package/host/transports/openai-realtime-transport.test.ts +371 -0
  90. package/host/transports/openai-realtime-transport.ts +319 -0
  91. package/host/transports/pipeline-transport.test.ts +125 -298
  92. package/host/transports/pipeline-transport.ts +20 -68
  93. package/host/transports/s2s-transport-fixtures.test.ts +31 -92
  94. package/host/transports/s2s-transport.test.ts +65 -134
  95. package/host/transports/s2s-transport.ts +15 -43
  96. package/host/transports/types.test.ts +4 -8
  97. package/host/unstorage-kv.test.ts +3 -2
  98. package/host/unstorage-kv.ts +5 -35
  99. package/host/ws-handler.test.ts +72 -176
  100. package/host/ws-handler.ts +6 -12
  101. package/package.json +6 -1
  102. package/sdk/__snapshots__/exports.test.ts.snap +7 -0
  103. package/sdk/__snapshots__/schema-shapes.test.ts.snap +1 -0
  104. package/sdk/_internal-types.test.ts +6 -9
  105. package/sdk/_internal-types.ts +16 -57
  106. package/sdk/_test-matchers.ts +25 -15
  107. package/sdk/allowed-hosts.test.ts +50 -114
  108. package/sdk/allowed-hosts.ts +8 -14
  109. package/sdk/constants.ts +5 -52
  110. package/sdk/define.test.ts +7 -6
  111. package/sdk/define.ts +7 -3
  112. package/sdk/exports.test.ts +6 -1
  113. package/sdk/kv.ts +13 -37
  114. package/sdk/manifest.test-d.ts +5 -0
  115. package/sdk/manifest.test.ts +61 -9
  116. package/sdk/manifest.ts +11 -11
  117. package/sdk/protocol-compat.test.ts +66 -98
  118. package/sdk/protocol-snapshot.test.ts +2 -16
  119. package/sdk/protocol.test.ts +13 -22
  120. package/sdk/providers/s2s/openai-realtime.ts +36 -0
  121. package/sdk/providers/s2s-barrel.ts +12 -0
  122. package/sdk/providers/tts/rime.ts +1 -1
  123. package/sdk/providers.ts +24 -5
  124. package/sdk/schema-alignment.test.ts +25 -73
  125. package/sdk/schema-shapes.test.ts +1 -29
  126. package/sdk/system-prompt.test.ts +0 -1
  127. package/sdk/system-prompt.ts +17 -19
  128. package/sdk/types-inference.test.ts +10 -36
  129. package/sdk/types.ts +7 -0
  130. package/sdk/ws-upgrade.test.ts +24 -23
  131. package/sdk/ws-upgrade.ts +2 -3
  132. package/tsdown.config.ts +8 -11
  133. package/dist/constants-C2nirZUI.js +0 -54
@@ -1,14 +1,14 @@
1
1
 
2
- > @alexkroman1/aai@1.7.1 build /home/runner/work/agent/agent/packages/aai
2
+ > @alexkroman1/aai@1.8.0 build /home/runner/work/agent/agent/packages/aai
3
3
  > tsdown && tsc -p tsconfig.build.json
4
4
 
5
5
  ℹ tsdown v0.21.7 powered by rolldown v1.0.0-rc.12
6
6
  ℹ config file: /home/runner/work/agent/agent/packages/aai/tsdown.config.ts
7
- ℹ entry: index.ts, sdk/protocol.ts, host/runtime-barrel.ts, sdk/manifest-barrel.ts, sdk/providers/stt-barrel.ts, sdk/providers/tts-barrel.ts, sdk/providers/llm-barrel.ts, sdk/providers/vector-barrel.ts, sdk/providers/kv-barrel.ts
7
+ ℹ entry: index.ts, sdk/protocol.ts, host/runtime-barrel.ts, sdk/manifest-barrel.ts, sdk/providers/stt-barrel.ts, sdk/providers/tts-barrel.ts, sdk/providers/llm-barrel.ts, sdk/providers/vector-barrel.ts, sdk/providers/kv-barrel.ts, sdk/providers/s2s-barrel.ts
8
8
  ℹ target: node22
9
9
  ℹ tsconfig: tsconfig.json
10
10
  ℹ Build start
11
- ℹ dist/host/runtime-barrel.js 113.03 kB │ gzip: 32.35 kB
11
+ ℹ dist/host/runtime-barrel.js 108.22 kB │ gzip: 29.84 kB
12
12
  ℹ dist/sdk/protocol.js  5.70 kB │ gzip: 1.92 kB
13
13
  ℹ dist/index.js  2.88 kB │ gzip: 1.24 kB
14
14
  ℹ dist/sdk/manifest-barrel.js  0.36 kB │ gzip: 0.20 kB
@@ -17,14 +17,16 @@
17
17
  ℹ dist/sdk/providers/kv-barrel.js  0.26 kB │ gzip: 0.17 kB
18
18
  ℹ dist/sdk/providers/tts-barrel.js  0.25 kB │ gzip: 0.16 kB
19
19
  ℹ dist/sdk/providers/vector-barrel.js  0.22 kB │ gzip: 0.15 kB
20
- ℹ dist/_internal-types-CrnTi9Ew.js  5.93 kB │ gzip: 2.13 kB
21
- ℹ dist/types-KUgezM6u.js  5.64 kB │ gzip: 2.39 kB
22
- ℹ dist/constants-C2nirZUI.js  3.10 kB │ gzip: 1.38 kB
20
+ ℹ dist/sdk/providers/s2s-barrel.js  0.15 kB │ gzip: 0.12 kB
21
+ ℹ dist/_internal-types-CfOAbK6V.js  5.45 kB │ gzip: 1.87 kB
22
+ ℹ dist/types-DOWVZhb9.js  5.39 kB │ gzip: 2.27 kB
23
23
  ℹ dist/soniox-BQdL0mB5.js  2.03 kB │ gzip: 0.54 kB
24
+ ℹ dist/constants-y68COEGj.js  1.70 kB │ gzip: 0.76 kB
24
25
  ℹ dist/xai-BDI61Y2M.js  1.18 kB │ gzip: 0.35 kB
25
- ℹ dist/ws-upgrade-BeOQ7fXL.js  1.14 kB │ gzip: 0.54 kB
26
26
  ℹ dist/rime-58p9mDR8.js  1.08 kB │ gzip: 0.51 kB
27
+ ℹ dist/ws-upgrade-CG8-by1n.js  1.08 kB │ gzip: 0.52 kB
27
28
  ℹ dist/s3-BtCMvCod.js  0.76 kB │ gzip: 0.29 kB
28
29
  ℹ dist/pinecone-CeJ69aRs.js  0.48 kB │ gzip: 0.24 kB
29
- ℹ 18 files, total: 144.72 kB
30
- ✔ Build complete in 54ms
30
+ ℹ dist/openai-realtime-cjPAHMMx.js  0.27 kB │ gzip: 0.19 kB
31
+ ℹ 20 files, total: 138.16 kB
32
+ ✔ Build complete in 48ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @alexkroman1/aai
2
2
 
3
+ ## 1.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a7384ad: Add OpenAI Realtime API as a pluggable s2s: provider via openaiRealtime() from @alexkroman1/aai/s2s
8
+
9
+ ### Patch Changes
10
+
11
+ - cc013df: Log session.error code+message at warn level (was hidden — only the type was logged), capture session id from session.updated.config.id (the success-path message; session.ready is no longer sent there, leaving resume permanently disabled), and remove the broken time-since-session-ready check from canResumeAfter that prevented resume on any session older than 25s.
12
+
3
13
  ## 1.7.1
4
14
 
5
15
  ### Patch Changes
@@ -1,16 +1,25 @@
1
- import { i as ToolChoiceSchema, o as validateAllowedHostPattern, t as BuiltinToolSchema } from "./types-KUgezM6u.js";
1
+ import { i as ToolChoiceSchema, o as validateAllowedHostPattern, t as BuiltinToolSchema } from "./types-DOWVZhb9.js";
2
2
  import { z } from "zod";
3
3
  //#region sdk/providers.ts
4
4
  /**
5
5
  * Enforce the all-or-nothing provider rule and return the derived mode.
6
6
  *
7
7
  * Pipeline mode requires STT, LLM, and TTS all set; S2S mode requires
8
- * none of them. Anything in-between is a configuration error.
8
+ * none of them. Anything in-between is a configuration error. An optional
9
+ * `s2s` descriptor selects a non-default S2S provider — it must not be
10
+ * combined with any pipeline field.
9
11
  */
10
- function assertProviderTriple(stt, llm, tts) {
11
- const count = (stt != null ? 1 : 0) + (llm != null ? 1 : 0) + (tts != null ? 1 : 0);
12
- if (count !== 0 && count !== 3) throw new Error("stt, llm, and tts must be set together");
13
- return count === 3 ? "pipeline" : "s2s";
12
+ function assertProviderTriple(stt, llm, tts, s2s) {
13
+ const hasStt = stt != null;
14
+ const hasLlm = llm != null;
15
+ const hasTts = tts != null;
16
+ const hasS2s = s2s != null;
17
+ const anyPipeline = hasStt || hasLlm || hasTts;
18
+ const allSet = hasStt && hasLlm && hasTts;
19
+ const noneSetPipeline = !anyPipeline;
20
+ if (hasS2s && anyPipeline) throw new Error("s2s and the stt/llm/tts pipeline cannot be set together");
21
+ if (!(allSet || noneSetPipeline)) throw new Error("stt, llm, and tts must be set together");
22
+ return allSet ? "pipeline" : "s2s";
14
23
  }
15
24
  /** Build an {@link SttError} with a typed `code`. Zero-dep helper so both sdk/ and host/ can use it. */
16
25
  function makeSttError(code, message) {
@@ -66,17 +75,12 @@ z.object({
66
75
  stt: ProviderDescriptorSchema.optional(),
67
76
  llm: ProviderDescriptorSchema.optional(),
68
77
  tts: ProviderDescriptorSchema.optional(),
78
+ s2s: ProviderDescriptorSchema.optional(),
69
79
  kv: ProviderDescriptorSchema.optional(),
70
80
  vector: ProviderDescriptorSchema.optional()
71
81
  });
72
82
  //#endregion
73
83
  //#region sdk/_internal-types.ts
74
- /**
75
- * Zod schema for serializable agent configuration sent over the wire.
76
- *
77
- * This is the JSON-safe subset of the agent definition that can be
78
- * transmitted between the worker and the host process via structured clone.
79
- */
80
84
  const AgentConfigSchema = z.object({
81
85
  name: z.string().min(1),
82
86
  systemPrompt: z.string(),
@@ -89,58 +93,41 @@ const AgentConfigSchema = z.object({
89
93
  stt: ProviderDescriptorSchema.optional(),
90
94
  llm: ProviderDescriptorSchema.optional(),
91
95
  tts: ProviderDescriptorSchema.optional(),
96
+ s2s: ProviderDescriptorSchema.optional(),
92
97
  mode: z.enum(["s2s", "pipeline"]).optional(),
93
98
  kv: ProviderDescriptorSchema.optional(),
94
99
  vector: ProviderDescriptorSchema.optional()
95
100
  });
96
- /**
97
- * Extract the serializable {@link AgentConfig} subset from a source object.
98
- *
99
- * When `stt`, `llm`, and `tts` descriptors are present they are all three
100
- * required (or none) — enforced here so the server can trust the config.
101
- * `mode` is derived from their presence.
102
- */
103
101
  function toAgentConfig(src) {
102
+ const mode = assertProviderTriple(src.stt, src.llm, src.tts, src.s2s);
104
103
  const config = {
105
104
  name: src.name,
106
105
  systemPrompt: src.systemPrompt,
107
- greeting: src.greeting
106
+ greeting: src.greeting,
107
+ mode
108
108
  };
109
109
  if (src.sttPrompt !== void 0) config.sttPrompt = src.sttPrompt;
110
110
  if (src.maxSteps !== void 0) config.maxSteps = src.maxSteps;
111
111
  if (src.toolChoice !== void 0) config.toolChoice = src.toolChoice;
112
112
  if (src.builtinTools) config.builtinTools = [...src.builtinTools];
113
113
  if (src.idleTimeoutMs !== void 0) config.idleTimeoutMs = src.idleTimeoutMs;
114
- config.mode = assertProviderTriple(src.stt, src.llm, src.tts);
115
- if (config.mode === "pipeline") {
114
+ if (mode === "pipeline") {
116
115
  config.stt = src.stt;
117
116
  config.llm = src.llm;
118
117
  config.tts = src.tts;
119
118
  }
119
+ if (src.s2s !== void 0) config.s2s = src.s2s;
120
120
  if (src.kv !== void 0) config.kv = src.kv;
121
121
  if (src.vector !== void 0) config.vector = src.vector;
122
122
  return config;
123
123
  }
124
- /**
125
- * Zod schema for serialized tool definitions sent over the wire.
126
- *
127
- * `parameters` must be a valid JSON Schema object (with `type`, `properties`,
128
- * etc.) — the Vercel AI SDK wraps it via `jsonSchema()`.
129
- */
130
124
  const ToolSchemaSchema = z.object({
131
125
  type: z.literal("function"),
132
126
  name: z.string().min(1),
133
127
  description: z.string().min(1),
134
128
  parameters: z.record(z.string(), z.unknown())
135
129
  });
136
- /** Empty Zod object schema used as default when tools have no parameters. */
137
130
  const EMPTY_PARAMS = z.object({});
138
- /**
139
- * Convert agent tool definitions to JSON Schema format for wire transport.
140
- *
141
- * Transforms the Zod-based `parameters` of each tool into a plain JSON Schema
142
- * object suitable for structured clone / JSON serialization.
143
- */
144
131
  function agentToolsToSchemas(tools) {
145
132
  return Object.entries(tools).map(([name, def]) => ({
146
133
  type: "function",
@@ -0,0 +1,29 @@
1
+ //#region sdk/constants.ts
2
+ const DEFAULT_STT_SAMPLE_RATE = 16e3;
3
+ const DEFAULT_TTS_SAMPLE_RATE = 24e3;
4
+ const TOOL_EXECUTION_TIMEOUT_MS = 3e4;
5
+ const DEFAULT_SESSION_START_TIMEOUT_MS = 1e4;
6
+ const DEFAULT_IDLE_TIMEOUT_MS = 3e5;
7
+ const FETCH_TIMEOUT_MS = 15e3;
8
+ const RUN_CODE_TIMEOUT_MS = 5e3;
9
+ const DEFAULT_SHUTDOWN_TIMEOUT_MS = 3e4;
10
+ /**
11
+ * Short relative to `DEFAULT_SHUTDOWN_TIMEOUT_MS` so a stuck TTS provider
12
+ * can't wedge the session — stop() must still reclaim the socket cleanly.
13
+ */
14
+ const PIPELINE_FLUSH_TIMEOUT_MS = 1e4;
15
+ const MAX_TOOL_RESULT_CHARS = 4e3;
16
+ const MAX_PAGE_CHARS = 1e4;
17
+ const MAX_HTML_BYTES = 2e5;
18
+ const MAX_VALUE_SIZE = 65536;
19
+ const DEFAULT_MAX_HISTORY = 200;
20
+ const MAX_WS_PAYLOAD_BYTES = 1 * 1024 * 1024;
21
+ const MAX_MESSAGE_BUFFER_SIZE = 100;
22
+ const WS_OPEN = 1;
23
+ /**
24
+ * Single source of truth — used by `secureHeaders` middleware and
25
+ * per-response CSP headers across self-hosted and platform agent UIs.
26
+ */
27
+ const AGENT_CSP = "default-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src 'self' wss: ws:; img-src 'self' data:; font-src 'self' https://fonts.gstatic.com; object-src 'none'; base-uri 'self'";
28
+ //#endregion
29
+ export { TOOL_EXECUTION_TIMEOUT_MS as _, DEFAULT_SHUTDOWN_TIMEOUT_MS as a, FETCH_TIMEOUT_MS as c, MAX_PAGE_CHARS as d, MAX_TOOL_RESULT_CHARS as f, RUN_CODE_TIMEOUT_MS as g, PIPELINE_FLUSH_TIMEOUT_MS as h, DEFAULT_SESSION_START_TIMEOUT_MS as i, MAX_HTML_BYTES as l, MAX_WS_PAYLOAD_BYTES as m, DEFAULT_IDLE_TIMEOUT_MS as n, DEFAULT_STT_SAMPLE_RATE as o, MAX_VALUE_SIZE as p, DEFAULT_MAX_HISTORY as r, DEFAULT_TTS_SAMPLE_RATE as s, AGENT_CSP as t, MAX_MESSAGE_BUFFER_SIZE as u, WS_OPEN as v };
@@ -0,0 +1,2 @@
1
+ export declare function uint8ToBase64(bytes: Uint8Array): string;
2
+ export declare function base64ToUint8(base64: string): Uint8Array;
@@ -1,19 +1,3 @@
1
- /**
2
- * A mock WebSocket implementation for testing.
3
- *
4
- * Extends `EventTarget` to simulate WebSocket behavior without a real
5
- * network connection. Records all sent messages in the {@link sent}
6
- * array and provides helper methods to simulate incoming messages,
7
- * connection events, and errors.
8
- *
9
- * @example
10
- * ```ts
11
- * const ws = new MockWebSocket("wss://example.com");
12
- * ws.send(JSON.stringify({ type: "ping" }));
13
- * ws.simulateMessage(JSON.stringify({ type: "pong" }));
14
- * assertEquals(ws.sentJson(), [{ type: "ping" }]);
15
- * ```
16
- */
17
1
  export declare class MockWebSocket extends EventTarget {
18
2
  static readonly CONNECTING = 0;
19
3
  static readonly OPEN = 1;
@@ -21,18 +5,8 @@ export declare class MockWebSocket extends EventTarget {
21
5
  static readonly CLOSED = 3;
22
6
  readyState: number;
23
7
  binaryType: string;
24
- /** All messages passed to {@link send}, in order. */
25
8
  sent: (string | ArrayBuffer | Uint8Array)[];
26
9
  url: string;
27
- /**
28
- * Create a new MockWebSocket.
29
- *
30
- * Automatically transitions to `OPEN` state on the next microtask,
31
- * dispatching an `"open"` event.
32
- *
33
- * @param url - The WebSocket URL.
34
- * @param _protocols - Ignored; accepted for API compatibility.
35
- */
36
10
  constructor(url: string | URL, _protocols?: string | string[] | Record<string, unknown>);
37
11
  addEventListener(type: "close" | "open", listener: () => void): void;
38
12
  addEventListener(type: "message", listener: (event: {
@@ -45,47 +19,12 @@ export declare class MockWebSocket extends EventTarget {
45
19
  addEventListener(type: "error", listener: (event: {
46
20
  message?: string;
47
21
  }) => void): void;
48
- /**
49
- * Record a sent message without transmitting it.
50
- *
51
- * @param data - The message data to record.
52
- */
53
22
  send(data: string | ArrayBuffer | Uint8Array): void;
54
- /**
55
- * Transition to `CLOSED` state and dispatch a `"close"` event.
56
- *
57
- * @param code - The close code (defaults to 1000).
58
- * @param _reason - Ignored; accepted for API compatibility.
59
- */
60
23
  close(code?: number, _reason?: string): void;
61
- /**
62
- * Simulate receiving a message from the server.
63
- *
64
- * @param data - The message data (string or binary).
65
- */
66
24
  simulateMessage(data: string | ArrayBuffer): void;
67
- /** Transition to `OPEN` state and dispatch an `"open"` event. */
68
25
  open(): void;
69
- /**
70
- * Shorthand for {@link simulateMessage}.
71
- *
72
- * @param data - The message data to dispatch.
73
- */
74
26
  msg(data: string | ArrayBuffer): void;
75
- /**
76
- * Simulate a connection close from the server.
77
- *
78
- * @param code - The close code (defaults to 1000).
79
- */
80
27
  disconnect(code?: number): void;
81
- /** Dispatch an `"error"` event on this socket. */
82
28
  error(): void;
83
- /**
84
- * Return all sent string messages parsed as JSON objects.
85
- *
86
- * Binary messages are filtered out.
87
- *
88
- * @returns An array of parsed JSON objects from sent string messages.
89
- */
90
29
  sentJson(): Record<string, unknown>[];
91
30
  }
@@ -16,6 +16,7 @@ import type { LanguageModel } from "ai";
16
16
  import { type Emitter } from "nanoevents";
17
17
  import { vi } from "vitest";
18
18
  import type { SttEvents, SttOpener, SttOpenOptions, SttSession, TtsEvents, TtsOpener, TtsOpenOptions, TtsSession } from "../sdk/providers.ts";
19
+ type SttErrorCode = "stt_stream_error" | "stt_connect_failed" | "stt_auth_failed";
19
20
  export type FakeSttSession = SttSession & {
20
21
  readonly emitter: Emitter<SttEvents>;
21
22
  readonly opts: SttOpenOptions;
@@ -25,7 +26,7 @@ export type FakeSttSession = SttSession & {
25
26
  };
26
27
  firePartial(text: string): void;
27
28
  fireFinal(text: string): void;
28
- fireError(code: "stt_stream_error" | "stt_connect_failed" | "stt_auth_failed", message: string): void;
29
+ fireError(code: SttErrorCode, message: string): void;
29
30
  };
30
31
  export type FakeSttProvider = SttOpener & {
31
32
  /** The most recently opened session, or undefined if `open()` hasn't been called. */
@@ -33,6 +34,7 @@ export type FakeSttProvider = SttOpener & {
33
34
  readonly sessions: FakeSttSession[];
34
35
  };
35
36
  export declare function createFakeSttProvider(): FakeSttProvider;
37
+ type TtsErrorCode = "tts_stream_error" | "tts_connect_failed" | "tts_auth_failed";
36
38
  export type FakeTtsSession = TtsSession & {
37
39
  readonly emitter: Emitter<TtsEvents>;
38
40
  readonly opts: TtsOpenOptions;
@@ -44,7 +46,7 @@ export type FakeTtsSession = TtsSession & {
44
46
  readonly flush: ReturnType<typeof vi.fn<() => void>>;
45
47
  readonly cancel: ReturnType<typeof vi.fn<() => void>>;
46
48
  fireAudio(pcm: Int16Array): void;
47
- fireError(code: "tts_stream_error" | "tts_connect_failed" | "tts_auth_failed", message: string): void;
49
+ fireError(code: TtsErrorCode, message: string): void;
48
50
  };
49
51
  export type FakeTtsProvider = TtsOpener & {
50
52
  /** The most recently opened session, or undefined if `open()` hasn't been called. */
@@ -63,12 +65,12 @@ export declare function createFakeTtsProvider(options?: {
63
65
  * Fake STT provider that throws on `open()` with a given error code. Used to
64
66
  * test atomic provider open — TTS should not be opened at all when STT fails.
65
67
  */
66
- export declare function createFailingSttProvider(code: "stt_connect_failed" | "stt_auth_failed" | "stt_stream_error", message: string): SttOpener;
68
+ export declare function createFailingSttProvider(code: SttErrorCode, message: string): SttOpener;
67
69
  /**
68
70
  * Fake TTS provider that throws on `open()` with a given error code. Used to
69
71
  * test atomic provider open — STT should be closed when TTS fails.
70
72
  */
71
- export declare function createFailingTtsProvider(code: "tts_connect_failed" | "tts_auth_failed" | "tts_stream_error", message: string): TtsOpener;
73
+ export declare function createFailingTtsProvider(code: TtsErrorCode, message: string): TtsOpener;
72
74
  /**
73
75
  * A scripted stream part. `text` yields a `text-delta` in the LLM provider's
74
76
  * raw wire format; `tool-call` / `tool-result` emit the corresponding parts
@@ -117,3 +119,4 @@ export declare function createFakeLanguageModel(options: {
117
119
  }): LanguageModel & {
118
120
  readonly calls: readonly Record<string, unknown>[];
119
121
  };
122
+ export {};
@@ -1,36 +1,11 @@
1
- /**
2
- * run_code built-in tool — executes user JavaScript in a fresh `node:vm`
3
- * context with no network, filesystem, or process access.
4
- */
5
1
  import { z } from "zod";
6
2
  import type { ToolDef } from "../sdk/types.ts";
7
3
  declare const runCodeParams: z.ZodObject<{
8
4
  code: z.ZodString;
9
5
  }, z.core.$strip>;
10
- /**
11
- * Execute JavaScript code inside a fresh `node:vm` context.
12
- *
13
- * Each invocation creates a disposable VM context with:
14
- * - No filesystem access (`node:fs` and other built-ins unavailable)
15
- * - No network access (`fetch`, `http` unavailable)
16
- * - No child process spawning
17
- * - No environment variable access (`process` unavailable)
18
- * - Execution timeout (default 5 s)
19
- *
20
- * The context is discarded after execution, so no state leaks between
21
- * invocations or across sessions.
22
- */
23
6
  export declare function createRunCode(): ToolDef<typeof runCodeParams> & {
24
7
  guidance: string;
25
8
  };
26
- /**
27
- * Execute user code in a fresh `node:vm` context.
28
- *
29
- * @remarks
30
- * The VM context only exposes standard ECMAScript globals and a console
31
- * object that captures output. Node.js APIs (`process`, `require`,
32
- * `import()`) are not available inside the sandbox.
33
- */
34
9
  export declare function executeInIsolate(code: string): Promise<string | {
35
10
  error: string;
36
11
  }>;
@@ -6,49 +6,18 @@
6
6
  * reusable test suite that can be wired to either runtime.
7
7
  *
8
8
  * Inspired by Nitro's `testNitro()` pattern: one test fixture, many runtimes.
9
- *
10
- * @example Direct executor (unit test)
11
- * ```ts
12
- * import { testRuntime } from "./_runtime-conformance.ts";
13
- *
14
- * testRuntime("direct", () => {
15
- * const exec = createRuntime({ agent: CONFORMANCE_AGENT, env: { MY_VAR: "test-value" } });
16
- * return { executeTool: exec.executeTool, hooks: exec.hooks };
17
- * });
18
- * ```
19
- *
20
- * @example Sandbox (integration test in aai-server)
21
- * ```ts
22
- * // Internal module — import the .ts source directly from this package.
23
- * import { testRuntime } from "../../aai/host/_runtime-conformance.ts";
24
- *
25
- * testRuntime("sandbox", async () => {
26
- * // ... start isolate with a bundled agent
27
- * return { executeTool: buildExecuteTool(...), hooks: buildHookInvoker(...) };
28
- * });
29
- * ```
30
9
  */
31
10
  import type { ExecuteTool } from "../sdk/_internal-types.ts";
32
11
  import type { AgentDef } from "../sdk/types.ts";
33
- /**
34
- * Minimal runtime surface needed for conformance tests.
35
- *
36
- * Both `Runtime` and `buildExecuteTool`/`buildHookInvoker` from the
37
- * sandbox produce objects that satisfy this interface.
38
- */
39
12
  export type RuntimeTestContext = {
40
13
  executeTool: ExecuteTool;
41
14
  };
42
- /** Agent definition used by the conformance suite (direct executor path). */
43
15
  export declare const CONFORMANCE_AGENT: AgentDef;
44
16
  /**
45
17
  * Run the runtime conformance test suite against a given runtime context.
46
18
  *
47
- * The `getContext` callback is invoked once per test to retrieve the
48
- * current {@link RuntimeTestContext}. This allows the caller to set up
49
- * the runtime in a `beforeAll` and return it lazily.
50
- *
51
- * All tests assume the runtime was created with {@link CONFORMANCE_AGENT}
52
- * (or its bundle equivalent) and `env: { MY_VAR: "test-value" }`.
19
+ * `getContext` is invoked once per test so callers can lazily set up the
20
+ * runtime in a `beforeAll`. All tests assume the runtime was created with
21
+ * {@link CONFORMANCE_AGENT} and `env: { MY_VAR: "test-value" }`.
53
22
  */
54
23
  export declare function testRuntime(label: string, getContext: () => RuntimeTestContext): void;
@@ -1,17 +1,6 @@
1
- /**
2
- * In-memory Vector implementation.
3
- *
4
- * INTENTIONALLY BAD QUALITY. Pseudo-embedding hashes the text into a
5
- * 64-dim Float32Array of values in [-1, ~0.99], then L2-normalizes
6
- * the result. Because both stored and probe vectors are unit-length,
7
- * cosine similarity reduces to a plain dot product — that's what
8
- * `cosine()` computes. Used only for `aai dev` and tests — the goal
9
- * is proving tool wiring, not retrieval ranking.
10
- */
11
1
  import type { Vector } from "../sdk/vector.ts";
12
2
  export type MemoryVectorOptions = {
13
3
  namespace: string;
14
4
  };
15
5
  export declare function createMemoryVector(opts: MemoryVectorOptions): Vector;
16
- /** Test-only: clear all in-memory state. Not exported from the package. */
17
6
  export declare function _resetMemoryVectorForTests(): void;
@@ -1,10 +1,3 @@
1
- /**
2
- * Descriptor → concrete `Kv` resolver. Mirror of `resolveLlm` /
3
- * `resolveVector`. Always wraps the produced unstorage Storage in
4
- * `createUnstorageKv` with the provided per-tenant prefix so namespace
5
- * isolation is enforced regardless of backend choice.
6
- */
7
1
  import type { Kv } from "../../sdk/kv.ts";
8
2
  import type { KvProvider } from "../../sdk/providers.ts";
9
- /** Resolve a {@link KvProvider} descriptor into a {@link Kv}. */
10
3
  export declare function resolveKv(descriptor: KvProvider, env: Record<string, string>, prefix: string): Kv;
@@ -1,11 +1,3 @@
1
- /**
2
- * Descriptor → concrete `Vector` resolver. Mirror of `resolveLlm`.
3
- *
4
- * Pulls API keys from the agent env so descriptors stay
5
- * secret-free. Lazy-loads provider SDKs via `createRequire` so
6
- * unused providers never enter the bundle.
7
- */
8
1
  import type { VectorProvider } from "../../sdk/providers.ts";
9
2
  import type { Vector } from "../../sdk/vector.ts";
10
- /** Resolve a {@link VectorProvider} descriptor into a {@link Vector}. */
11
3
  export declare function resolveVector(descriptor: VectorProvider, env: Record<string, string>, namespace: string): Vector;
@@ -1,22 +1,8 @@
1
- /**
2
- * AssemblyAI Universal-Streaming STT opener (host-only).
3
- *
4
- * The user-facing descriptor factory (`assemblyAI(...)`) lives in
5
- * `sdk/providers/stt/assemblyai.ts`. This module is the host-side
6
- * counterpart: it takes the descriptor options + an API key and
7
- * returns an {@link SttOpener} that the pipeline session drives.
8
- *
9
- * Default model: `"u3pro-rt"` (Universal-3 Pro Real-Time). The adapter
10
- * maps that to the SDK's `"u3-rt-pro"` `speechModel` value; any other
11
- * string is forwarded verbatim.
12
- */
13
1
  import { type StreamingTranscriber } from "assemblyai";
14
2
  import type { AssemblyAIOptions } from "../../../sdk/providers/stt/assemblyai.ts";
15
3
  import { type SttOpener, type SttSession } from "../../../sdk/providers.ts";
16
- /** Internal: SttSession with a test-only handle to the raw SDK transcriber. */
17
4
  export interface AssemblyAISession extends SttSession {
18
5
  /** @internal Test-only: exposes the underlying SDK transcriber for fixture replay. */
19
6
  readonly _transcriber: StreamingTranscriber;
20
7
  }
21
- /** Build an {@link SttOpener} from resolved AssemblyAI descriptor options. */
22
8
  export declare function openAssemblyAI(opts?: AssemblyAIOptions): SttOpener;
@@ -1,28 +1,16 @@
1
1
  /**
2
2
  * Deepgram Nova streaming STT opener (host-only).
3
3
  *
4
- * The user-facing descriptor factory (`deepgram(...)`) lives in
5
- * `sdk/providers/stt/deepgram.ts`. This module is the host-side
6
- * counterpart: it takes the descriptor options + an API key and
7
- * returns an {@link SttOpener} that the pipeline session drives.
8
- *
9
- * Default model: `"nova-3"`. Any string is forwarded verbatim to the SDK.
10
- *
11
- * This adapter targets the Deepgram SDK v5 (`@deepgram/sdk@^5`). The v5
12
- * streaming API is:
13
- * `client.listen.v1.connect(args)` → `Promise<V1Socket>`
14
- * followed by:
15
- * `socket.connect()` + `socket.waitForOpen()` to establish the connection.
4
+ * Targets Deepgram SDK v5: `client.listen.v1.connect(args)` returns a
5
+ * socket; `socket.connect()` + `socket.waitForOpen()` establish it.
16
6
  */
17
7
  import { DeepgramClient } from "@deepgram/sdk";
18
8
  import type { DeepgramOptions } from "../../../sdk/providers/stt/deepgram.ts";
19
9
  import { type SttOpener, type SttSession } from "../../../sdk/providers.ts";
20
10
  type V1Socket = Awaited<ReturnType<InstanceType<typeof DeepgramClient>["listen"]["v1"]["connect"]>>;
21
- /** Internal: SttSession with a test-only handle to the raw SDK socket. */
22
11
  export interface DeepgramSession extends SttSession {
23
12
  /** @internal Test-only: exposes the underlying SDK socket for fixture replay. */
24
13
  readonly _connection: V1Socket;
25
14
  }
26
- /** Build an {@link SttOpener} from resolved Deepgram descriptor options. */
27
15
  export declare function openDeepgram(opts?: DeepgramOptions): SttOpener;
28
16
  export {};
@@ -1,25 +1,3 @@
1
- /**
2
- * Soniox real-time STT opener (host-only).
3
- *
4
- * The user-facing descriptor factory (`soniox(...)`) lives in
5
- * `sdk/providers/stt/soniox.ts`. This module is the host-side
6
- * counterpart: it takes the descriptor options + an API key and
7
- * returns an {@link SttOpener} that the pipeline session drives.
8
- *
9
- * Soniox's published JS client (`@soniox/speech-to-text-web`) is
10
- * browser-only — it depends on `MediaRecorder` and `getUserMedia`. For
11
- * server-side use we talk to the WebSocket directly:
12
- * `wss://stt-rt.soniox.com/transcribe-websocket`
13
- *
14
- * Wire format:
15
- * - First text frame: JSON config with api_key, model, audio_format,
16
- * sample_rate, num_channels (and optional language hints).
17
- * - Subsequent binary frames: 16-bit signed little-endian PCM audio.
18
- * - Server replies: JSON `{ tokens: [{ text, is_final }] }` messages.
19
- * Final tokens accumulate; non-final tokens are a rolling preview.
20
- * - On error: `{ error_code, error_message }`.
21
- */
22
1
  import type { SonioxOptions } from "../../../sdk/providers/stt/soniox.ts";
23
2
  import { type SttOpener } from "../../../sdk/providers.ts";
24
- /** Build an {@link SttOpener} from resolved Soniox descriptor options. */
25
3
  export declare function openSoniox(opts?: SonioxOptions): SttOpener;
@@ -1,44 +1,23 @@
1
1
  /**
2
2
  * Rime TTS opener (host-only).
3
3
  *
4
- * The user-facing descriptor factory (`rime(...)`) lives in
5
- * `sdk/providers/tts/rime.ts`. This module is the host-side
6
- * counterpart: it takes the descriptor options + an API key and
7
- * returns a {@link TtsOpener} that the pipeline session drives.
4
+ * Connects to Rime's `ws2` JSON WebSocket endpoint with one long-lived
5
+ * connection per session. Client server: `{ text }` appends to the
6
+ * synthesis buffer, `{ operation: "clear" }` drops it (barge-in). We never
7
+ * send `eos` since it tears down the WS `flush()` instead sends a
8
+ * trailing `"."` to force synthesis of any text buffered behind missing
9
+ * terminal punctuation while keeping the connection reusable.
8
10
  *
9
- * **Protocol.** Connects to Rime's `ws2` JSON WebSocket endpoint
10
- * (`wss://users-ws.rime.ai/ws2`). Client-to-server messages are JSON:
11
- * - `{ "text": "..." }` append text to the synthesis buffer
12
- * - `{ "operation": "clear" }` drop buffered text (barge-in)
13
- * - `{ "operation": "eos" }` — drain buffer, close connection (NOT used
14
- * during a session: it would tear down the WS, forcing reconnect per
15
- * turn). We force end-of-turn synthesis with a trailing `"."` instead.
16
- * The server responds with JSON frames:
17
- * - `{ type: "chunk", data: <base64 PCM16 LE>, contextId: string | null }`
18
- * - `{ type: "timestamps", ... }` (ignored)
19
- * - `{ type: "error", message: string }` (surfaced as `tts_stream_error`)
20
- *
21
- * **Single long-lived connection per session.** Rime buffers text until it
22
- * sees terminal punctuation (`.`, `?`, `!`), so we use one WebSocket per
23
- * `open()` call and reuse it across turns. `clear` resets the buffer
24
- * between cancellations.
25
- *
26
- * **Done detection.** After `flush()` sends a trailing `"."` to force the
27
- * server to synthesize any half-buffered text, we arm a quiescence timer
28
- * that fires 500 ms after the last received audio chunk. When it fires,
29
- * `done` is emitted.
30
- *
31
- * **Audio format.** The URL requests `audioFormat=pcm` at the negotiated
32
- * `sampleRate`, which returns raw PCM16 little-endian. We decode the base64
33
- * payload and construct a zero-copy `Int16Array` view over the decoded bytes.
11
+ * Server client: `{ type: "chunk", data: <base64 PCM16 LE> }` carries
12
+ * audio; `timestamps` is ignored; `error` surfaces as `tts_stream_error`.
13
+ * The `audioFormat=pcm` query param at the negotiated `sampleRate` returns
14
+ * raw PCM16 LE that we view as a zero-copy `Int16Array`.
34
15
  */
35
16
  import WebSocket from "ws";
36
17
  import { type RimeOptions } from "../../../sdk/providers/tts/rime.ts";
37
18
  import { type TtsOpener, type TtsSession } from "../../../sdk/providers.ts";
38
- /** Internal: TtsSession with a test-only handle to the raw WebSocket. */
39
19
  export interface RimeSession extends TtsSession {
40
20
  /** @internal Test-only: exposes the underlying raw WebSocket. */
41
21
  readonly _ws: WebSocket;
42
22
  }
43
- /** Build a {@link TtsOpener} from resolved Rime descriptor options. */
44
23
  export declare function openRime(opts: RimeOptions): TtsOpener;