@alexkroman1/aai 0.4.0 → 0.6.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 (249) hide show
  1. package/README.md +0 -6
  2. package/dist/aai.js +3 -0
  3. package/dist/cli.js +244 -245
  4. package/dist/sdk/_internal_types.d.ts +73 -0
  5. package/dist/sdk/_internal_types.d.ts.map +1 -0
  6. package/dist/sdk/_internal_types.js +24 -0
  7. package/dist/sdk/_internal_types.js.map +1 -0
  8. package/dist/sdk/_mock_ws.d.ts +105 -0
  9. package/dist/sdk/_mock_ws.d.ts.map +1 -0
  10. package/dist/sdk/_mock_ws.js +154 -0
  11. package/dist/sdk/_mock_ws.js.map +1 -0
  12. package/dist/sdk/_timeout.d.ts +14 -0
  13. package/dist/sdk/_timeout.d.ts.map +1 -0
  14. package/{sdk/_timeout.ts → dist/sdk/_timeout.js} +9 -9
  15. package/dist/sdk/_timeout.js.map +1 -0
  16. package/dist/sdk/builtin_tools.d.ts +33 -0
  17. package/dist/sdk/builtin_tools.d.ts.map +1 -0
  18. package/dist/sdk/builtin_tools.js +263 -0
  19. package/dist/sdk/builtin_tools.js.map +1 -0
  20. package/dist/sdk/capnweb.d.ts +69 -0
  21. package/dist/sdk/capnweb.d.ts.map +1 -0
  22. package/dist/sdk/capnweb.js +291 -0
  23. package/dist/sdk/capnweb.js.map +1 -0
  24. package/dist/sdk/define_agent.d.ts +36 -0
  25. package/dist/sdk/define_agent.d.ts.map +1 -0
  26. package/dist/sdk/define_agent.js +63 -0
  27. package/dist/sdk/define_agent.js.map +1 -0
  28. package/dist/sdk/direct_executor.d.ts +42 -0
  29. package/dist/sdk/direct_executor.d.ts.map +1 -0
  30. package/dist/sdk/direct_executor.js +143 -0
  31. package/dist/sdk/direct_executor.js.map +1 -0
  32. package/dist/sdk/kv.d.ts +123 -0
  33. package/dist/sdk/kv.d.ts.map +1 -0
  34. package/dist/sdk/kv.js +91 -0
  35. package/dist/sdk/kv.js.map +1 -0
  36. package/{sdk/mod.ts → dist/sdk/mod.d.ts} +2 -11
  37. package/dist/sdk/mod.d.ts.map +1 -0
  38. package/dist/sdk/mod.js +26 -0
  39. package/dist/sdk/mod.js.map +1 -0
  40. package/dist/sdk/protocol.d.ts +218 -0
  41. package/dist/sdk/protocol.d.ts.map +1 -0
  42. package/dist/sdk/protocol.js +140 -0
  43. package/dist/sdk/protocol.js.map +1 -0
  44. package/dist/sdk/runtime.d.ts +35 -0
  45. package/dist/sdk/runtime.d.ts.map +1 -0
  46. package/dist/sdk/runtime.js +46 -0
  47. package/dist/sdk/runtime.js.map +1 -0
  48. package/dist/sdk/s2s.d.ts +60 -0
  49. package/dist/sdk/s2s.d.ts.map +1 -0
  50. package/dist/sdk/s2s.js +171 -0
  51. package/dist/sdk/s2s.js.map +1 -0
  52. package/dist/sdk/server.d.ts +51 -0
  53. package/dist/sdk/server.d.ts.map +1 -0
  54. package/dist/sdk/server.js +145 -0
  55. package/dist/sdk/server.js.map +1 -0
  56. package/dist/sdk/session.d.ts +66 -0
  57. package/dist/sdk/session.d.ts.map +1 -0
  58. package/dist/sdk/session.js +324 -0
  59. package/dist/sdk/session.js.map +1 -0
  60. package/dist/sdk/system_prompt.d.ts +6 -0
  61. package/dist/sdk/system_prompt.d.ts.map +1 -0
  62. package/dist/sdk/system_prompt.js +35 -0
  63. package/dist/sdk/system_prompt.js.map +1 -0
  64. package/dist/sdk/types.d.ts +326 -0
  65. package/dist/sdk/types.d.ts.map +1 -0
  66. package/dist/sdk/types.js +38 -0
  67. package/dist/sdk/types.js.map +1 -0
  68. package/dist/sdk/vector.d.ts +90 -0
  69. package/dist/sdk/vector.d.ts.map +1 -0
  70. package/dist/sdk/vector.js +61 -0
  71. package/dist/sdk/vector.js.map +1 -0
  72. package/dist/sdk/winterc_server.d.ts +53 -0
  73. package/dist/sdk/winterc_server.d.ts.map +1 -0
  74. package/dist/sdk/winterc_server.js +82 -0
  75. package/dist/sdk/winterc_server.js.map +1 -0
  76. package/dist/sdk/worker_entry.d.ts +48 -0
  77. package/dist/sdk/worker_entry.d.ts.map +1 -0
  78. package/dist/sdk/worker_entry.js +67 -0
  79. package/dist/sdk/worker_entry.js.map +1 -0
  80. package/dist/sdk/worker_shim.d.ts +20 -0
  81. package/dist/sdk/worker_shim.d.ts.map +1 -0
  82. package/dist/sdk/worker_shim.js +132 -0
  83. package/dist/sdk/worker_shim.js.map +1 -0
  84. package/dist/sdk/ws_handler.d.ts +50 -0
  85. package/dist/sdk/ws_handler.d.ts.map +1 -0
  86. package/dist/sdk/ws_handler.js +156 -0
  87. package/dist/sdk/ws_handler.js.map +1 -0
  88. package/dist/ui/_components/app.d.ts +3 -0
  89. package/dist/ui/_components/app.d.ts.map +1 -0
  90. package/dist/ui/_components/app.js +14 -0
  91. package/dist/ui/_components/app.js.map +1 -0
  92. package/dist/ui/_components/chat_view.d.ts +3 -0
  93. package/dist/ui/_components/chat_view.d.ts.map +1 -0
  94. package/dist/ui/_components/chat_view.js +14 -0
  95. package/dist/ui/_components/chat_view.js.map +1 -0
  96. package/dist/ui/_components/controls.d.ts +2 -0
  97. package/dist/ui/_components/controls.d.ts.map +1 -0
  98. package/dist/ui/_components/controls.js +11 -0
  99. package/dist/ui/_components/controls.js.map +1 -0
  100. package/dist/ui/_components/error_banner.d.ts +7 -0
  101. package/dist/ui/_components/error_banner.d.ts.map +1 -0
  102. package/dist/ui/_components/error_banner.js +7 -0
  103. package/dist/ui/_components/error_banner.js.map +1 -0
  104. package/dist/ui/_components/message_bubble.d.ts +6 -0
  105. package/dist/ui/_components/message_bubble.d.ts.map +1 -0
  106. package/dist/ui/_components/message_bubble.js +9 -0
  107. package/dist/ui/_components/message_bubble.js.map +1 -0
  108. package/dist/ui/_components/message_list.d.ts +2 -0
  109. package/dist/ui/_components/message_list.d.ts.map +1 -0
  110. package/dist/ui/_components/message_list.js +48 -0
  111. package/dist/ui/_components/message_list.js.map +1 -0
  112. package/dist/ui/_components/state_indicator.d.ts +7 -0
  113. package/dist/ui/_components/state_indicator.d.ts.map +1 -0
  114. package/dist/ui/_components/state_indicator.js +5 -0
  115. package/dist/ui/_components/state_indicator.js.map +1 -0
  116. package/dist/ui/_components/thinking_indicator.d.ts +3 -0
  117. package/dist/ui/_components/thinking_indicator.d.ts.map +1 -0
  118. package/dist/ui/_components/thinking_indicator.js +8 -0
  119. package/dist/ui/_components/thinking_indicator.js.map +1 -0
  120. package/dist/ui/_components/tool_call_block.d.ts +6 -0
  121. package/dist/ui/_components/tool_call_block.d.ts.map +1 -0
  122. package/dist/ui/_components/tool_call_block.js +58 -0
  123. package/dist/ui/_components/tool_call_block.js.map +1 -0
  124. package/dist/ui/_components/tool_icons.d.ts +18 -0
  125. package/dist/ui/_components/tool_icons.d.ts.map +1 -0
  126. package/dist/ui/_components/tool_icons.js +26 -0
  127. package/dist/ui/_components/tool_icons.js.map +1 -0
  128. package/dist/ui/_components/transcript.d.ts +6 -0
  129. package/dist/ui/_components/transcript.d.ts.map +1 -0
  130. package/dist/ui/_components/transcript.js +8 -0
  131. package/dist/ui/_components/transcript.js.map +1 -0
  132. package/dist/ui/_dom_shim.d.ts +7 -0
  133. package/dist/ui/_dom_shim.d.ts.map +1 -0
  134. package/dist/ui/_dom_shim.js +21 -0
  135. package/dist/ui/_dom_shim.js.map +1 -0
  136. package/dist/ui/_test_utils.js +272 -0
  137. package/dist/ui/_test_utils.js.map +1 -0
  138. package/dist/ui/audio.d.ts +46 -0
  139. package/dist/ui/audio.d.ts.map +1 -0
  140. package/dist/ui/audio.js +130 -0
  141. package/dist/ui/audio.js.map +1 -0
  142. package/dist/ui/components.d.ts +36 -0
  143. package/dist/ui/components.d.ts.map +1 -0
  144. package/dist/ui/components.js +32 -0
  145. package/dist/ui/components.js.map +1 -0
  146. package/{ui/components_mod.ts → dist/ui/components_mod.d.ts} +3 -18
  147. package/dist/ui/components_mod.d.ts.map +1 -0
  148. package/dist/ui/components_mod.js +20 -0
  149. package/dist/ui/components_mod.js.map +1 -0
  150. package/dist/ui/mod.d.ts +21 -0
  151. package/dist/ui/mod.d.ts.map +1 -0
  152. package/{ui/mod.ts → dist/ui/mod.js} +3 -29
  153. package/dist/ui/mod.js.map +1 -0
  154. package/dist/ui/mount.d.ts +56 -0
  155. package/dist/ui/mount.d.ts.map +1 -0
  156. package/dist/ui/mount.js +60 -0
  157. package/dist/ui/mount.js.map +1 -0
  158. package/dist/ui/mount_context.d.ts +10 -0
  159. package/dist/ui/mount_context.d.ts.map +1 -0
  160. package/dist/ui/mount_context.js +10 -0
  161. package/dist/ui/mount_context.js.map +1 -0
  162. package/dist/ui/session.d.ts +91 -0
  163. package/dist/ui/session.d.ts.map +1 -0
  164. package/dist/ui/session.js +366 -0
  165. package/dist/ui/session.js.map +1 -0
  166. package/{ui/session_mod.ts → dist/ui/session_mod.d.ts} +2 -10
  167. package/dist/ui/session_mod.d.ts.map +1 -0
  168. package/dist/ui/session_mod.js +18 -0
  169. package/dist/ui/session_mod.js.map +1 -0
  170. package/dist/ui/signals.d.ts +61 -0
  171. package/dist/ui/signals.d.ts.map +1 -0
  172. package/dist/ui/signals.js +74 -0
  173. package/dist/ui/signals.js.map +1 -0
  174. package/dist/ui/types.d.ts +36 -0
  175. package/dist/ui/types.d.ts.map +1 -0
  176. package/dist/ui/types.js +4 -0
  177. package/dist/ui/types.js.map +1 -0
  178. package/package.json +103 -28
  179. package/sdk/_internal_types.ts +0 -89
  180. package/sdk/_mock_ws.ts +0 -172
  181. package/sdk/builtin_tools.ts +0 -309
  182. package/sdk/capnweb.ts +0 -341
  183. package/sdk/define_agent.ts +0 -70
  184. package/sdk/direct_executor.ts +0 -195
  185. package/sdk/kv.ts +0 -183
  186. package/sdk/protocol.ts +0 -313
  187. package/sdk/runtime.ts +0 -65
  188. package/sdk/s2s.ts +0 -271
  189. package/sdk/server.ts +0 -198
  190. package/sdk/session.ts +0 -438
  191. package/sdk/system_prompt.ts +0 -47
  192. package/sdk/types.ts +0 -406
  193. package/sdk/vector.ts +0 -133
  194. package/sdk/winterc_server.ts +0 -141
  195. package/sdk/worker_entry.ts +0 -99
  196. package/sdk/worker_shim.ts +0 -170
  197. package/sdk/ws_handler.ts +0 -190
  198. package/templates/_shared/.env.example +0 -5
  199. package/templates/_shared/package.json +0 -17
  200. package/templates/code-interpreter/agent.ts +0 -27
  201. package/templates/code-interpreter/client.tsx +0 -2
  202. package/templates/dispatch-center/agent.ts +0 -1536
  203. package/templates/dispatch-center/client.tsx +0 -504
  204. package/templates/embedded-assets/agent.ts +0 -49
  205. package/templates/embedded-assets/client.tsx +0 -2
  206. package/templates/embedded-assets/knowledge.json +0 -20
  207. package/templates/health-assistant/agent.ts +0 -160
  208. package/templates/health-assistant/client.tsx +0 -2
  209. package/templates/infocom-adventure/agent.ts +0 -164
  210. package/templates/infocom-adventure/client.tsx +0 -299
  211. package/templates/math-buddy/agent.ts +0 -21
  212. package/templates/math-buddy/client.tsx +0 -2
  213. package/templates/memory-agent/agent.ts +0 -74
  214. package/templates/memory-agent/client.tsx +0 -2
  215. package/templates/night-owl/agent.ts +0 -98
  216. package/templates/night-owl/client.tsx +0 -28
  217. package/templates/personal-finance/agent.ts +0 -26
  218. package/templates/personal-finance/client.tsx +0 -2
  219. package/templates/simple/agent.ts +0 -6
  220. package/templates/simple/client.tsx +0 -2
  221. package/templates/smart-research/agent.ts +0 -164
  222. package/templates/smart-research/client.tsx +0 -2
  223. package/templates/support/README.md +0 -62
  224. package/templates/support/agent.ts +0 -19
  225. package/templates/support/client.tsx +0 -2
  226. package/templates/travel-concierge/agent.ts +0 -29
  227. package/templates/travel-concierge/client.tsx +0 -2
  228. package/templates/web-researcher/agent.ts +0 -17
  229. package/templates/web-researcher/client.tsx +0 -2
  230. package/ui/_components/app.tsx +0 -37
  231. package/ui/_components/chat_view.tsx +0 -36
  232. package/ui/_components/controls.tsx +0 -32
  233. package/ui/_components/error_banner.tsx +0 -18
  234. package/ui/_components/message_bubble.tsx +0 -21
  235. package/ui/_components/message_list.tsx +0 -61
  236. package/ui/_components/state_indicator.tsx +0 -17
  237. package/ui/_components/thinking_indicator.tsx +0 -19
  238. package/ui/_components/tool_call_block.tsx +0 -110
  239. package/ui/_components/tool_icons.tsx +0 -101
  240. package/ui/_components/transcript.tsx +0 -20
  241. package/ui/audio.ts +0 -170
  242. package/ui/components.ts +0 -49
  243. package/ui/mount.tsx +0 -112
  244. package/ui/mount_context.ts +0 -19
  245. package/ui/session.ts +0 -456
  246. package/ui/signals.ts +0 -111
  247. package/ui/types.ts +0 -50
  248. package/ui/worklets/capture-processor.js +0 -62
  249. package/ui/worklets/playback-processor.js +0 -110
package/ui/types.ts DELETED
@@ -1,50 +0,0 @@
1
- // Copyright 2025 the AAI authors. MIT license.
2
- /** Microphone buffer duration in seconds before sending to the server. */
3
- export const MIC_BUFFER_SECONDS = 0.1;
4
-
5
- /** Current state of the voice agent session. */
6
- export type AgentState =
7
- | "disconnected"
8
- | "connecting"
9
- | "ready"
10
- | "listening"
11
- | "thinking"
12
- | "speaking"
13
- | "error";
14
-
15
- /** A chat message exchanged between user and assistant. */
16
- export type Message = {
17
- /** The sender of the message. */
18
- role: "user" | "assistant";
19
- /** The text content of the message. */
20
- text: string;
21
- };
22
-
23
- /** Info about a tool call for display in the UI. */
24
- export type ToolCallInfo = {
25
- toolCallId: string;
26
- toolName: string;
27
- args: Record<string, unknown>;
28
- status: "pending" | "done";
29
- result?: string | undefined;
30
- /** Index in the messages array where this tool call should appear. */
31
- afterMessageIndex: number;
32
- };
33
-
34
- import type { SessionErrorCode } from "../sdk/protocol.ts";
35
-
36
- export type { SessionErrorCode };
37
-
38
- /** Error reported by the voice session. */
39
- export type SessionError = {
40
- /** The category of the error. */
41
- readonly code: SessionErrorCode;
42
- /** A human-readable description of the error. */
43
- readonly message: string;
44
- };
45
-
46
- /** Options for creating a voice session. */
47
- export type SessionOptions = {
48
- /** Base URL of the AAI platform server. */
49
- platformUrl: string;
50
- };
@@ -1,62 +0,0 @@
1
- // Capture worklet: captures mic Float32 samples, resamples to STT rate if
2
- // needed, converts to Int16 PCM, and sends chunks to the main thread.
3
-
4
- const CaptureProcessorWorklet = `
5
- class CaptureProcessor extends AudioWorkletProcessor {
6
- constructor(options) {
7
- super();
8
- this.recording = false;
9
- const opts = options.processorOptions || {};
10
- this.fromRate = opts.contextRate || sampleRate;
11
- this.toRate = opts.sttSampleRate || sampleRate;
12
- this.ratio = this.fromRate / this.toRate;
13
- this.needsResample = this.fromRate !== this.toRate;
14
- this.port.onmessage = (e) => {
15
- if (e.data.event === 'start') this.recording = true;
16
- else if (e.data.event === 'stop') this.recording = false;
17
- };
18
- }
19
-
20
- resample(input) {
21
- const ratio = this.ratio;
22
- const outLen = Math.ceil(input.length / ratio);
23
- const out = new Float32Array(outLen);
24
- for (let i = 0; i < outLen; i++) {
25
- const srcIdx = i * ratio;
26
- const idx = srcIdx | 0;
27
- const frac = srcIdx - idx;
28
- const a = input[idx];
29
- const b = idx + 1 < input.length ? input[idx + 1] : a;
30
- out[i] = a + frac * (b - a);
31
- }
32
- return out;
33
- }
34
-
35
- process(inputs) {
36
- const input = inputs[0];
37
- if (!input || !input[0] || !this.recording) return true;
38
-
39
- const raw = input[0];
40
- const samples = this.needsResample ? this.resample(raw) : raw;
41
-
42
- // Convert Float32 -> Int16
43
- const buffer = new ArrayBuffer(samples.length * 2);
44
- const view = new DataView(buffer);
45
- for (let i = 0; i < samples.length; i++) {
46
- const s = Math.max(-1, Math.min(1, samples[i]));
47
- view.setInt16(i * 2, s < 0 ? s * 0x8000 : s * 0x7fff, true);
48
- }
49
-
50
- this.port.postMessage({ event: 'chunk', buffer }, [buffer]);
51
- return true;
52
- }
53
- }
54
-
55
- registerProcessor('capture-processor', CaptureProcessor);
56
- `;
57
-
58
- const script = new Blob([CaptureProcessorWorklet], {
59
- type: "application/javascript",
60
- });
61
- const src = URL.createObjectURL(script);
62
- export default src;
@@ -1,110 +0,0 @@
1
- // Playback worklet: receives raw PCM16 LE bytes, handles byte alignment,
2
- // converts to float32, and plays with a small jitter buffer.
3
-
4
- const PlaybackProcessorWorklet = `
5
- class PlaybackProcessor extends AudioWorkletProcessor {
6
- constructor(options) {
7
- super();
8
- this.interrupted = false;
9
- this.isDone = false;
10
- this.playing = false;
11
- const rate = options.processorOptions?.sampleRate ?? 24000;
12
- // Wait for ~400ms of audio before starting.
13
- // If 'done' arrives first (short utterance), start immediately.
14
- this.jitterSamples = Math.floor(rate * 0.4);
15
- // Carry-over byte for split samples across chunks
16
- this.carry = null;
17
- // Float32 sample buffer — 60s at the context sample rate
18
- this.samples = new Float32Array(rate * 60);
19
- this.writePos = 0;
20
- this.readPos = 0;
21
- // Report playback position every ~50ms for word-level text sync
22
- this.progressInterval = Math.floor(rate * 0.05);
23
- this.samplesSinceProgress = 0;
24
-
25
- this.port.onmessage = (e) => {
26
- const d = e.data;
27
- if (d.event === 'write') {
28
- this.ingestBytes(d.buffer);
29
- } else if (d.event === 'interrupt') {
30
- this.interrupted = true;
31
- } else if (d.event === 'done') {
32
- this.isDone = true;
33
- }
34
- };
35
- }
36
-
37
- ingestBytes(uint8) {
38
- let bytes = uint8;
39
-
40
- if (this.carry !== null) {
41
- const merged = new Uint8Array(1 + bytes.length);
42
- merged[0] = this.carry;
43
- merged.set(bytes, 1);
44
- bytes = merged;
45
- this.carry = null;
46
- }
47
-
48
- if (bytes.length % 2 !== 0) {
49
- this.carry = bytes[bytes.length - 1];
50
- bytes = bytes.subarray(0, bytes.length - 1);
51
- }
52
-
53
- if (bytes.length === 0) return;
54
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
55
- const numSamples = bytes.length / 2;
56
- for (let i = 0; i < numSamples; i++) {
57
- this.samples[this.writePos++] = view.getInt16(i * 2, true) / 0x8000;
58
- }
59
- }
60
-
61
- process(inputs, outputs) {
62
- const out = outputs[0][0];
63
- if (this.interrupted) {
64
- this.port.postMessage({ event: 'stop' });
65
- return false;
66
- }
67
-
68
- const avail = this.writePos - this.readPos;
69
-
70
- // Wait for jitter buffer to fill, unless done (short utterance)
71
- if (!this.playing) {
72
- if (avail >= this.jitterSamples || this.isDone) {
73
- this.playing = true;
74
- } else {
75
- for (let i = 0; i < out.length; i++) out[i] = 0;
76
- return true;
77
- }
78
- }
79
-
80
- if (avail > 0) {
81
- const n = Math.min(avail, out.length);
82
- out.set(this.samples.subarray(this.readPos, this.readPos + n));
83
- this.readPos += n;
84
- this.samplesSinceProgress += n;
85
- if (this.samplesSinceProgress >= this.progressInterval) {
86
- this.port.postMessage({ event: 'progress', readPos: this.readPos });
87
- this.samplesSinceProgress = 0;
88
- }
89
- for (let i = n; i < out.length; i++) out[i] = 0;
90
- return true;
91
- }
92
-
93
- // No data: output silence, stop only when done
94
- for (let i = 0; i < out.length; i++) out[i] = 0;
95
- if (this.isDone) {
96
- this.port.postMessage({ event: 'stop' });
97
- return false;
98
- }
99
- return true;
100
- }
101
- }
102
-
103
- registerProcessor('playback-processor', PlaybackProcessor);
104
- `;
105
-
106
- const script = new Blob([PlaybackProcessorWorklet], {
107
- type: "application/javascript",
108
- });
109
- const src = URL.createObjectURL(script);
110
- export default src;