@alexkroman1/aai 0.5.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.
- package/dist/cli.js +193 -214
- package/dist/sdk/_internal_types.d.ts +73 -0
- package/dist/sdk/_internal_types.d.ts.map +1 -0
- package/dist/sdk/_internal_types.js +24 -0
- package/dist/sdk/_internal_types.js.map +1 -0
- package/dist/sdk/_mock_ws.d.ts +105 -0
- package/dist/sdk/_mock_ws.d.ts.map +1 -0
- package/dist/sdk/_mock_ws.js +154 -0
- package/dist/sdk/_mock_ws.js.map +1 -0
- package/dist/sdk/_timeout.d.ts +14 -0
- package/dist/sdk/_timeout.d.ts.map +1 -0
- package/{sdk/_timeout.ts → dist/sdk/_timeout.js} +9 -9
- package/dist/sdk/_timeout.js.map +1 -0
- package/dist/sdk/builtin_tools.d.ts +33 -0
- package/dist/sdk/builtin_tools.d.ts.map +1 -0
- package/dist/sdk/builtin_tools.js +263 -0
- package/dist/sdk/builtin_tools.js.map +1 -0
- package/dist/sdk/capnweb.d.ts +69 -0
- package/dist/sdk/capnweb.d.ts.map +1 -0
- package/dist/sdk/capnweb.js +291 -0
- package/dist/sdk/capnweb.js.map +1 -0
- package/dist/sdk/define_agent.d.ts +36 -0
- package/dist/sdk/define_agent.d.ts.map +1 -0
- package/dist/sdk/define_agent.js +63 -0
- package/dist/sdk/define_agent.js.map +1 -0
- package/dist/sdk/direct_executor.d.ts +42 -0
- package/dist/sdk/direct_executor.d.ts.map +1 -0
- package/dist/sdk/direct_executor.js +143 -0
- package/dist/sdk/direct_executor.js.map +1 -0
- package/dist/sdk/kv.d.ts +123 -0
- package/dist/sdk/kv.d.ts.map +1 -0
- package/dist/sdk/kv.js +91 -0
- package/dist/sdk/kv.js.map +1 -0
- package/{sdk/mod.ts → dist/sdk/mod.d.ts} +2 -11
- package/dist/sdk/mod.d.ts.map +1 -0
- package/dist/sdk/mod.js +26 -0
- package/dist/sdk/mod.js.map +1 -0
- package/dist/sdk/protocol.d.ts +218 -0
- package/dist/sdk/protocol.d.ts.map +1 -0
- package/dist/sdk/protocol.js +140 -0
- package/dist/sdk/protocol.js.map +1 -0
- package/dist/sdk/runtime.d.ts +35 -0
- package/dist/sdk/runtime.d.ts.map +1 -0
- package/dist/sdk/runtime.js +46 -0
- package/dist/sdk/runtime.js.map +1 -0
- package/dist/sdk/s2s.d.ts +60 -0
- package/dist/sdk/s2s.d.ts.map +1 -0
- package/dist/sdk/s2s.js +171 -0
- package/dist/sdk/s2s.js.map +1 -0
- package/dist/sdk/server.d.ts +51 -0
- package/dist/sdk/server.d.ts.map +1 -0
- package/dist/sdk/server.js +145 -0
- package/dist/sdk/server.js.map +1 -0
- package/dist/sdk/session.d.ts +66 -0
- package/dist/sdk/session.d.ts.map +1 -0
- package/dist/sdk/session.js +324 -0
- package/dist/sdk/session.js.map +1 -0
- package/dist/sdk/system_prompt.d.ts +6 -0
- package/dist/sdk/system_prompt.d.ts.map +1 -0
- package/dist/sdk/system_prompt.js +35 -0
- package/dist/sdk/system_prompt.js.map +1 -0
- package/dist/sdk/types.d.ts +326 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +38 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/sdk/vector.d.ts +90 -0
- package/dist/sdk/vector.d.ts.map +1 -0
- package/dist/sdk/vector.js +61 -0
- package/dist/sdk/vector.js.map +1 -0
- package/dist/sdk/winterc_server.d.ts +53 -0
- package/dist/sdk/winterc_server.d.ts.map +1 -0
- package/dist/sdk/winterc_server.js +82 -0
- package/dist/sdk/winterc_server.js.map +1 -0
- package/dist/sdk/worker_entry.d.ts +48 -0
- package/dist/sdk/worker_entry.d.ts.map +1 -0
- package/dist/sdk/worker_entry.js +67 -0
- package/dist/sdk/worker_entry.js.map +1 -0
- package/dist/sdk/worker_shim.d.ts +20 -0
- package/dist/sdk/worker_shim.d.ts.map +1 -0
- package/dist/sdk/worker_shim.js +132 -0
- package/dist/sdk/worker_shim.js.map +1 -0
- package/dist/sdk/ws_handler.d.ts +50 -0
- package/dist/sdk/ws_handler.d.ts.map +1 -0
- package/dist/sdk/ws_handler.js +156 -0
- package/dist/sdk/ws_handler.js.map +1 -0
- package/dist/ui/_components/app.d.ts +3 -0
- package/dist/ui/_components/app.d.ts.map +1 -0
- package/dist/ui/_components/app.js +14 -0
- package/dist/ui/_components/app.js.map +1 -0
- package/dist/ui/_components/chat_view.d.ts +3 -0
- package/dist/ui/_components/chat_view.d.ts.map +1 -0
- package/dist/ui/_components/chat_view.js +14 -0
- package/dist/ui/_components/chat_view.js.map +1 -0
- package/dist/ui/_components/controls.d.ts +2 -0
- package/dist/ui/_components/controls.d.ts.map +1 -0
- package/dist/ui/_components/controls.js +11 -0
- package/dist/ui/_components/controls.js.map +1 -0
- package/dist/ui/_components/error_banner.d.ts +7 -0
- package/dist/ui/_components/error_banner.d.ts.map +1 -0
- package/dist/ui/_components/error_banner.js +7 -0
- package/dist/ui/_components/error_banner.js.map +1 -0
- package/dist/ui/_components/message_bubble.d.ts +6 -0
- package/dist/ui/_components/message_bubble.d.ts.map +1 -0
- package/dist/ui/_components/message_bubble.js +9 -0
- package/dist/ui/_components/message_bubble.js.map +1 -0
- package/dist/ui/_components/message_list.d.ts +2 -0
- package/dist/ui/_components/message_list.d.ts.map +1 -0
- package/dist/ui/_components/message_list.js +48 -0
- package/dist/ui/_components/message_list.js.map +1 -0
- package/dist/ui/_components/state_indicator.d.ts +7 -0
- package/dist/ui/_components/state_indicator.d.ts.map +1 -0
- package/dist/ui/_components/state_indicator.js +5 -0
- package/dist/ui/_components/state_indicator.js.map +1 -0
- package/dist/ui/_components/thinking_indicator.d.ts +3 -0
- package/dist/ui/_components/thinking_indicator.d.ts.map +1 -0
- package/dist/ui/_components/thinking_indicator.js +8 -0
- package/dist/ui/_components/thinking_indicator.js.map +1 -0
- package/dist/ui/_components/tool_call_block.d.ts +6 -0
- package/dist/ui/_components/tool_call_block.d.ts.map +1 -0
- package/dist/ui/_components/tool_call_block.js +58 -0
- package/dist/ui/_components/tool_call_block.js.map +1 -0
- package/dist/ui/_components/tool_icons.d.ts +18 -0
- package/dist/ui/_components/tool_icons.d.ts.map +1 -0
- package/dist/ui/_components/tool_icons.js +26 -0
- package/dist/ui/_components/tool_icons.js.map +1 -0
- package/dist/ui/_components/transcript.d.ts +6 -0
- package/dist/ui/_components/transcript.d.ts.map +1 -0
- package/dist/ui/_components/transcript.js +8 -0
- package/dist/ui/_components/transcript.js.map +1 -0
- package/dist/ui/_dom_shim.d.ts +7 -0
- package/dist/ui/_dom_shim.d.ts.map +1 -0
- package/dist/ui/_dom_shim.js +21 -0
- package/dist/ui/_dom_shim.js.map +1 -0
- package/dist/ui/_test_utils.js +272 -0
- package/dist/ui/_test_utils.js.map +1 -0
- package/dist/ui/audio.d.ts +46 -0
- package/dist/ui/audio.d.ts.map +1 -0
- package/dist/ui/audio.js +130 -0
- package/dist/ui/audio.js.map +1 -0
- package/dist/ui/components.d.ts +36 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js +32 -0
- package/dist/ui/components.js.map +1 -0
- package/{ui/components_mod.ts → dist/ui/components_mod.d.ts} +3 -18
- package/dist/ui/components_mod.d.ts.map +1 -0
- package/dist/ui/components_mod.js +20 -0
- package/dist/ui/components_mod.js.map +1 -0
- package/dist/ui/mod.d.ts +21 -0
- package/dist/ui/mod.d.ts.map +1 -0
- package/{ui/mod.ts → dist/ui/mod.js} +3 -29
- package/dist/ui/mod.js.map +1 -0
- package/dist/ui/mount.d.ts +56 -0
- package/dist/ui/mount.d.ts.map +1 -0
- package/dist/ui/mount.js +60 -0
- package/dist/ui/mount.js.map +1 -0
- package/dist/ui/mount_context.d.ts +10 -0
- package/dist/ui/mount_context.d.ts.map +1 -0
- package/dist/ui/mount_context.js +10 -0
- package/dist/ui/mount_context.js.map +1 -0
- package/dist/ui/session.d.ts +91 -0
- package/dist/ui/session.d.ts.map +1 -0
- package/dist/ui/session.js +366 -0
- package/dist/ui/session.js.map +1 -0
- package/{ui/session_mod.ts → dist/ui/session_mod.d.ts} +2 -10
- package/dist/ui/session_mod.d.ts.map +1 -0
- package/dist/ui/session_mod.js +18 -0
- package/dist/ui/session_mod.js.map +1 -0
- package/dist/ui/signals.d.ts +61 -0
- package/dist/ui/signals.d.ts.map +1 -0
- package/dist/ui/signals.js +74 -0
- package/dist/ui/signals.js.map +1 -0
- package/dist/ui/types.d.ts +36 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/types.js +4 -0
- package/dist/ui/types.js.map +1 -0
- package/package.json +102 -26
- package/sdk/_internal_types.ts +0 -89
- package/sdk/_mock_ws.ts +0 -172
- package/sdk/builtin_tools.ts +0 -309
- package/sdk/capnweb.ts +0 -341
- package/sdk/define_agent.ts +0 -70
- package/sdk/direct_executor.ts +0 -195
- package/sdk/kv.ts +0 -183
- package/sdk/protocol.ts +0 -313
- package/sdk/runtime.ts +0 -65
- package/sdk/s2s.ts +0 -271
- package/sdk/server.ts +0 -198
- package/sdk/session.ts +0 -431
- package/sdk/system_prompt.ts +0 -47
- package/sdk/types.ts +0 -406
- package/sdk/vector.ts +0 -133
- package/sdk/winterc_server.ts +0 -141
- package/sdk/worker_entry.ts +0 -99
- package/sdk/worker_shim.ts +0 -170
- package/sdk/ws_handler.ts +0 -197
- package/templates/_shared/.env.example +0 -5
- package/templates/_shared/package.json +0 -17
- package/templates/code-interpreter/agent.ts +0 -27
- package/templates/code-interpreter/client.tsx +0 -2
- package/templates/dispatch-center/agent.ts +0 -1536
- package/templates/dispatch-center/client.tsx +0 -504
- package/templates/embedded-assets/agent.ts +0 -49
- package/templates/embedded-assets/client.tsx +0 -2
- package/templates/embedded-assets/knowledge.json +0 -20
- package/templates/health-assistant/agent.ts +0 -160
- package/templates/health-assistant/client.tsx +0 -2
- package/templates/infocom-adventure/agent.ts +0 -164
- package/templates/infocom-adventure/client.tsx +0 -299
- package/templates/math-buddy/agent.ts +0 -21
- package/templates/math-buddy/client.tsx +0 -2
- package/templates/memory-agent/agent.ts +0 -74
- package/templates/memory-agent/client.tsx +0 -2
- package/templates/night-owl/agent.ts +0 -98
- package/templates/night-owl/client.tsx +0 -28
- package/templates/personal-finance/agent.ts +0 -26
- package/templates/personal-finance/client.tsx +0 -2
- package/templates/simple/agent.ts +0 -6
- package/templates/simple/client.tsx +0 -2
- package/templates/smart-research/agent.ts +0 -164
- package/templates/smart-research/client.tsx +0 -2
- package/templates/support/README.md +0 -62
- package/templates/support/agent.ts +0 -19
- package/templates/support/client.tsx +0 -2
- package/templates/travel-concierge/agent.ts +0 -29
- package/templates/travel-concierge/client.tsx +0 -2
- package/templates/web-researcher/agent.ts +0 -17
- package/templates/web-researcher/client.tsx +0 -2
- package/ui/_components/app.tsx +0 -37
- package/ui/_components/chat_view.tsx +0 -36
- package/ui/_components/controls.tsx +0 -32
- package/ui/_components/error_banner.tsx +0 -18
- package/ui/_components/message_bubble.tsx +0 -21
- package/ui/_components/message_list.tsx +0 -61
- package/ui/_components/state_indicator.tsx +0 -17
- package/ui/_components/thinking_indicator.tsx +0 -19
- package/ui/_components/tool_call_block.tsx +0 -110
- package/ui/_components/tool_icons.tsx +0 -101
- package/ui/_components/transcript.tsx +0 -20
- package/ui/audio.ts +0 -170
- package/ui/components.ts +0 -49
- package/ui/mount.tsx +0 -112
- package/ui/mount_context.ts +0 -19
- package/ui/session.ts +0 -456
- package/ui/signals.ts +0 -111
- package/ui/types.ts +0 -50
- package/ui/worklets/capture-processor.js +0 -62
- package/ui/worklets/playback-processor.js +0 -110
package/dist/cli.js
CHANGED
|
@@ -58,26 +58,6 @@ var init_output = __esm({
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
// sdk/types.ts
|
|
62
|
-
var DEFAULT_INSTRUCTIONS, DEFAULT_GREETING;
|
|
63
|
-
var init_types = __esm({
|
|
64
|
-
"sdk/types.ts"() {
|
|
65
|
-
"use strict";
|
|
66
|
-
DEFAULT_INSTRUCTIONS = `You are AAI, a helpful AI assistant.
|
|
67
|
-
|
|
68
|
-
Voice-First Rules:
|
|
69
|
-
- Optimize for natural speech. Avoid jargon unless central to the answer. Use short, punchy sentences.
|
|
70
|
-
- Never mention "search results," "sources," or "the provided text." Speak as if the knowledge is your own.
|
|
71
|
-
- No visual formatting. Do not say "bullet point," "bold," or "bracketed one." If you need to list items, say "First," "Next," and "Finally."
|
|
72
|
-
- Start with the most important information. No introductory filler.
|
|
73
|
-
- Be concise. Keep answers to 1-3 sentences. For complex topics, provide a high-level summary.
|
|
74
|
-
- Be confident. Avoid hedging phrases like "It seems that" or "I believe."
|
|
75
|
-
- If you don't have enough information, say so directly rather than guessing.
|
|
76
|
-
- Never use exclamation points. Keep your tone calm and conversational.`;
|
|
77
|
-
DEFAULT_GREETING = "Hey there. I'm a voice assistant. What can I help you with?";
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
61
|
// cli/_new.ts
|
|
82
62
|
var new_exports = {};
|
|
83
63
|
__export(new_exports, {
|
|
@@ -174,11 +154,11 @@ var init_new = __esm({
|
|
|
174
154
|
}
|
|
175
155
|
});
|
|
176
156
|
|
|
177
|
-
// sdk/protocol.
|
|
157
|
+
// dist/sdk/protocol.js
|
|
178
158
|
import { z } from "zod";
|
|
179
159
|
var PROTOCOL_VERSION, DEFAULT_TTS_SAMPLE_RATE, AUDIO_FORMAT, _bitsPerSample, _channels, AudioFrameSpec, KvRequestBaseSchema, HOOK_TIMEOUT_MS, SessionErrorCodeSchema, TranscriptEventSchema, ClientEventSchema, ClientMessageSchema;
|
|
180
160
|
var init_protocol = __esm({
|
|
181
|
-
"sdk/protocol.
|
|
161
|
+
"dist/sdk/protocol.js"() {
|
|
182
162
|
"use strict";
|
|
183
163
|
PROTOCOL_VERSION = 1;
|
|
184
164
|
DEFAULT_TTS_SAMPLE_RATE = 24e3;
|
|
@@ -266,39 +246,45 @@ var init_protocol = __esm({
|
|
|
266
246
|
z.object({ type: z.literal("reset") }),
|
|
267
247
|
z.object({
|
|
268
248
|
type: z.literal("history"),
|
|
269
|
-
messages: z.array(
|
|
270
|
-
z.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
})
|
|
274
|
-
).max(200)
|
|
249
|
+
messages: z.array(z.object({
|
|
250
|
+
role: z.enum(["user", "assistant"]),
|
|
251
|
+
text: z.string().max(1e5)
|
|
252
|
+
})).max(200)
|
|
275
253
|
})
|
|
276
254
|
]);
|
|
277
255
|
}
|
|
278
256
|
});
|
|
279
257
|
|
|
280
|
-
// sdk/runtime.
|
|
258
|
+
// dist/sdk/runtime.js
|
|
281
259
|
var consoleLogger, noopMetrics, DEFAULT_S2S_CONFIG;
|
|
282
260
|
var init_runtime = __esm({
|
|
283
|
-
"sdk/runtime.
|
|
261
|
+
"dist/sdk/runtime.js"() {
|
|
284
262
|
"use strict";
|
|
285
263
|
init_protocol();
|
|
286
264
|
consoleLogger = {
|
|
287
265
|
info(msg, ctx) {
|
|
288
|
-
if (ctx)
|
|
289
|
-
|
|
266
|
+
if (ctx)
|
|
267
|
+
console.log(msg, ctx);
|
|
268
|
+
else
|
|
269
|
+
console.log(msg);
|
|
290
270
|
},
|
|
291
271
|
warn(msg, ctx) {
|
|
292
|
-
if (ctx)
|
|
293
|
-
|
|
272
|
+
if (ctx)
|
|
273
|
+
console.warn(msg, ctx);
|
|
274
|
+
else
|
|
275
|
+
console.warn(msg);
|
|
294
276
|
},
|
|
295
277
|
error(msg, ctx) {
|
|
296
|
-
if (ctx)
|
|
297
|
-
|
|
278
|
+
if (ctx)
|
|
279
|
+
console.error(msg, ctx);
|
|
280
|
+
else
|
|
281
|
+
console.error(msg);
|
|
298
282
|
},
|
|
299
283
|
debug(msg, ctx) {
|
|
300
|
-
if (ctx)
|
|
301
|
-
|
|
284
|
+
if (ctx)
|
|
285
|
+
console.debug(msg, ctx);
|
|
286
|
+
else
|
|
287
|
+
console.debug(msg);
|
|
302
288
|
}
|
|
303
289
|
};
|
|
304
290
|
noopMetrics = {
|
|
@@ -316,7 +302,7 @@ var init_runtime = __esm({
|
|
|
316
302
|
}
|
|
317
303
|
});
|
|
318
304
|
|
|
319
|
-
// sdk/_internal_types.
|
|
305
|
+
// dist/sdk/_internal_types.js
|
|
320
306
|
import { z as z2 } from "zod";
|
|
321
307
|
function agentToolsToSchemas(tools) {
|
|
322
308
|
return Object.entries(tools).map(([name, def]) => ({
|
|
@@ -327,13 +313,13 @@ function agentToolsToSchemas(tools) {
|
|
|
327
313
|
}
|
|
328
314
|
var EMPTY_PARAMS;
|
|
329
315
|
var init_internal_types = __esm({
|
|
330
|
-
"sdk/_internal_types.
|
|
316
|
+
"dist/sdk/_internal_types.js"() {
|
|
331
317
|
"use strict";
|
|
332
318
|
EMPTY_PARAMS = z2.object({});
|
|
333
319
|
}
|
|
334
320
|
});
|
|
335
321
|
|
|
336
|
-
// sdk/builtin_tools.
|
|
322
|
+
// dist/sdk/builtin_tools.js
|
|
337
323
|
import { z as z3 } from "zod";
|
|
338
324
|
function htmlToText(html) {
|
|
339
325
|
return html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<(br|hr)\s*\/?>/gi, "\n").replace(/<\/(p|div|li|h[1-6]|tr|blockquote)>/gi, "\n").replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/[ \t]+/g, " ").replace(/\n /g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
@@ -357,10 +343,12 @@ function createWebSearch() {
|
|
|
357
343
|
headers: { "X-Subscription-Token": apiKey },
|
|
358
344
|
signal: ctx.abortSignal ?? AbortSignal.timeout(15e3)
|
|
359
345
|
});
|
|
360
|
-
if (!resp.ok)
|
|
346
|
+
if (!resp.ok)
|
|
347
|
+
return [];
|
|
361
348
|
const raw = await resp.json();
|
|
362
349
|
const data = BraveSearchResponseSchema.safeParse(raw);
|
|
363
|
-
if (!data.success)
|
|
350
|
+
if (!data.success)
|
|
351
|
+
return [];
|
|
364
352
|
return (data.data.web?.results ?? []).slice(0, maxResults).map((r) => ({
|
|
365
353
|
title: r.title,
|
|
366
354
|
url: r.url,
|
|
@@ -488,7 +476,8 @@ function getBuiltinToolDefs(names, opts) {
|
|
|
488
476
|
function getBuiltinToolSchemas(names) {
|
|
489
477
|
return names.flatMap((name) => {
|
|
490
478
|
const creator = TOOL_CREATORS[name];
|
|
491
|
-
if (!creator)
|
|
479
|
+
if (!creator)
|
|
480
|
+
return [];
|
|
492
481
|
const def = creator();
|
|
493
482
|
return [
|
|
494
483
|
{
|
|
@@ -501,7 +490,7 @@ function getBuiltinToolSchemas(names) {
|
|
|
501
490
|
}
|
|
502
491
|
var EMPTY_PARAMS2, webSearchParams, BRAVE_SEARCH_URL, BraveSearchResponseSchema, MAX_PAGE_CHARS, MAX_HTML_BYTES, visitWebpageParams, fetchJsonParams, runCodeParams, vectorSearchParams, TOOL_CREATORS;
|
|
503
492
|
var init_builtin_tools = __esm({
|
|
504
|
-
"sdk/builtin_tools.
|
|
493
|
+
"dist/sdk/builtin_tools.js"() {
|
|
505
494
|
"use strict";
|
|
506
495
|
EMPTY_PARAMS2 = z3.object({});
|
|
507
496
|
webSearchParams = z3.object({
|
|
@@ -511,13 +500,11 @@ var init_builtin_tools = __esm({
|
|
|
511
500
|
BRAVE_SEARCH_URL = "https://api.search.brave.com/res/v1/web/search";
|
|
512
501
|
BraveSearchResponseSchema = z3.object({
|
|
513
502
|
web: z3.object({
|
|
514
|
-
results: z3.array(
|
|
515
|
-
z3.
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
})
|
|
520
|
-
)
|
|
503
|
+
results: z3.array(z3.object({
|
|
504
|
+
title: z3.string(),
|
|
505
|
+
url: z3.string(),
|
|
506
|
+
description: z3.string()
|
|
507
|
+
}))
|
|
521
508
|
}).optional()
|
|
522
509
|
});
|
|
523
510
|
MAX_PAGE_CHARS = 1e4;
|
|
@@ -533,9 +520,7 @@ var init_builtin_tools = __esm({
|
|
|
533
520
|
code: z3.string().describe("JavaScript code to execute. Use console.log() for output.")
|
|
534
521
|
});
|
|
535
522
|
vectorSearchParams = z3.object({
|
|
536
|
-
query: z3.string().describe(
|
|
537
|
-
'Short keyword query to search the knowledge base. Use specific topic terms, not full sentences. Do NOT include the company or product name since all documents are from the same source. For example, if the user asks "how much does Acme cost", search for "pricing plans rates".'
|
|
538
|
-
),
|
|
523
|
+
query: z3.string().describe('Short keyword query to search the knowledge base. Use specific topic terms, not full sentences. Do NOT include the company or product name since all documents are from the same source. For example, if the user asks "how much does Acme cost", search for "pricing plans rates".'),
|
|
539
524
|
topK: z3.number().describe("Maximum results to return (default: 5)").optional()
|
|
540
525
|
});
|
|
541
526
|
TOOL_CREATORS = {
|
|
@@ -549,10 +534,11 @@ var init_builtin_tools = __esm({
|
|
|
549
534
|
}
|
|
550
535
|
});
|
|
551
536
|
|
|
552
|
-
// sdk/kv.
|
|
537
|
+
// dist/sdk/kv.js
|
|
553
538
|
function sortAndPaginate(entries, options) {
|
|
554
539
|
entries.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
555
|
-
if (options?.reverse)
|
|
540
|
+
if (options?.reverse)
|
|
541
|
+
entries.reverse();
|
|
556
542
|
if (options?.limit && options.limit > 0) {
|
|
557
543
|
entries.length = Math.min(entries.length, options.limit);
|
|
558
544
|
}
|
|
@@ -567,7 +553,8 @@ function createMemoryKv() {
|
|
|
567
553
|
get(key) {
|
|
568
554
|
const entry = store.get(key);
|
|
569
555
|
if (!entry || isExpired(entry)) {
|
|
570
|
-
if (entry)
|
|
556
|
+
if (entry)
|
|
557
|
+
store.delete(key);
|
|
571
558
|
return Promise.resolve(null);
|
|
572
559
|
}
|
|
573
560
|
return Promise.resolve(JSON.parse(entry.raw));
|
|
@@ -607,13 +594,13 @@ function createMemoryKv() {
|
|
|
607
594
|
}
|
|
608
595
|
var MAX_VALUE_SIZE;
|
|
609
596
|
var init_kv = __esm({
|
|
610
|
-
"sdk/kv.
|
|
597
|
+
"dist/sdk/kv.js"() {
|
|
611
598
|
"use strict";
|
|
612
599
|
MAX_VALUE_SIZE = 65536;
|
|
613
600
|
}
|
|
614
601
|
});
|
|
615
602
|
|
|
616
|
-
// sdk/s2s.
|
|
603
|
+
// dist/sdk/s2s.js
|
|
617
604
|
function uint8ToBase64(bytes) {
|
|
618
605
|
const CHUNK = 32768;
|
|
619
606
|
const parts = [];
|
|
@@ -640,7 +627,8 @@ function connectS2s(opts) {
|
|
|
640
627
|
const target = new EventTarget();
|
|
641
628
|
let opened = false;
|
|
642
629
|
function send(msg) {
|
|
643
|
-
if (ws.readyState !== WS_OPEN)
|
|
630
|
+
if (ws.readyState !== WS_OPEN)
|
|
631
|
+
return;
|
|
644
632
|
const type = msg.type;
|
|
645
633
|
if (type !== "input.audio") {
|
|
646
634
|
log.info(`S2S >> ${JSON.stringify(msg)}`);
|
|
@@ -683,11 +671,9 @@ function connectS2s(opts) {
|
|
|
683
671
|
}
|
|
684
672
|
switch (type) {
|
|
685
673
|
case "session.ready":
|
|
686
|
-
target.dispatchEvent(
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
})
|
|
690
|
-
);
|
|
674
|
+
target.dispatchEvent(new CustomEvent("ready", {
|
|
675
|
+
detail: { session_id: msg.session_id }
|
|
676
|
+
}));
|
|
691
677
|
break;
|
|
692
678
|
case "session.updated":
|
|
693
679
|
target.dispatchEvent(new CustomEvent("session_updated", { detail: msg }));
|
|
@@ -699,28 +685,22 @@ function connectS2s(opts) {
|
|
|
699
685
|
target.dispatchEvent(new CustomEvent("speech_stopped"));
|
|
700
686
|
break;
|
|
701
687
|
case "transcript.user.delta":
|
|
702
|
-
target.dispatchEvent(
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
})
|
|
706
|
-
);
|
|
688
|
+
target.dispatchEvent(new CustomEvent("user_transcript_delta", {
|
|
689
|
+
detail: { text: msg.text }
|
|
690
|
+
}));
|
|
707
691
|
break;
|
|
708
692
|
case "transcript.user":
|
|
709
|
-
target.dispatchEvent(
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
})
|
|
716
|
-
);
|
|
693
|
+
target.dispatchEvent(new CustomEvent("user_transcript", {
|
|
694
|
+
detail: {
|
|
695
|
+
item_id: msg.item_id,
|
|
696
|
+
text: msg.text
|
|
697
|
+
}
|
|
698
|
+
}));
|
|
717
699
|
break;
|
|
718
700
|
case "reply.started":
|
|
719
|
-
target.dispatchEvent(
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
})
|
|
723
|
-
);
|
|
701
|
+
target.dispatchEvent(new CustomEvent("reply_started", {
|
|
702
|
+
detail: { reply_id: msg.reply_id }
|
|
703
|
+
}));
|
|
724
704
|
break;
|
|
725
705
|
case "reply.audio": {
|
|
726
706
|
const audioBytes = base64ToUint8(msg.data);
|
|
@@ -728,38 +708,30 @@ function connectS2s(opts) {
|
|
|
728
708
|
break;
|
|
729
709
|
}
|
|
730
710
|
case "transcript.agent":
|
|
731
|
-
target.dispatchEvent(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
})
|
|
735
|
-
);
|
|
711
|
+
target.dispatchEvent(new CustomEvent("agent_transcript", {
|
|
712
|
+
detail: { text: msg.text }
|
|
713
|
+
}));
|
|
736
714
|
break;
|
|
737
715
|
case "tool.call":
|
|
738
|
-
target.dispatchEvent(
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
})
|
|
746
|
-
);
|
|
716
|
+
target.dispatchEvent(new CustomEvent("tool_call", {
|
|
717
|
+
detail: {
|
|
718
|
+
call_id: msg.call_id,
|
|
719
|
+
name: msg.name,
|
|
720
|
+
args: msg.args ?? {}
|
|
721
|
+
}
|
|
722
|
+
}));
|
|
747
723
|
break;
|
|
748
724
|
case "reply.done":
|
|
749
|
-
target.dispatchEvent(
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
})
|
|
753
|
-
);
|
|
725
|
+
target.dispatchEvent(new CustomEvent("reply_done", {
|
|
726
|
+
detail: { status: msg.status ?? void 0 }
|
|
727
|
+
}));
|
|
754
728
|
break;
|
|
755
729
|
case "session.error": {
|
|
756
730
|
const code = msg.code;
|
|
757
731
|
const isExpired = code === "session_not_found" || code === "session_forbidden";
|
|
758
|
-
target.dispatchEvent(
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
})
|
|
762
|
-
);
|
|
732
|
+
target.dispatchEvent(new CustomEvent(isExpired ? "session_expired" : "error", {
|
|
733
|
+
detail: { code, message: msg.message }
|
|
734
|
+
}));
|
|
763
735
|
break;
|
|
764
736
|
}
|
|
765
737
|
}
|
|
@@ -777,25 +749,42 @@ function connectS2s(opts) {
|
|
|
777
749
|
if (!opened) {
|
|
778
750
|
reject(errObj);
|
|
779
751
|
} else {
|
|
780
|
-
target.dispatchEvent(
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
})
|
|
784
|
-
);
|
|
752
|
+
target.dispatchEvent(new CustomEvent("error", {
|
|
753
|
+
detail: { code: "ws_error", message: errObj.message }
|
|
754
|
+
}));
|
|
785
755
|
}
|
|
786
756
|
});
|
|
787
757
|
});
|
|
788
758
|
}
|
|
789
759
|
var WS_OPEN;
|
|
790
760
|
var init_s2s = __esm({
|
|
791
|
-
"sdk/s2s.
|
|
761
|
+
"dist/sdk/s2s.js"() {
|
|
792
762
|
"use strict";
|
|
793
763
|
init_runtime();
|
|
794
764
|
WS_OPEN = 1;
|
|
795
765
|
}
|
|
796
766
|
});
|
|
797
767
|
|
|
798
|
-
// sdk/
|
|
768
|
+
// dist/sdk/types.js
|
|
769
|
+
var DEFAULT_INSTRUCTIONS2;
|
|
770
|
+
var init_types = __esm({
|
|
771
|
+
"dist/sdk/types.js"() {
|
|
772
|
+
"use strict";
|
|
773
|
+
DEFAULT_INSTRUCTIONS2 = `You are AAI, a helpful AI assistant.
|
|
774
|
+
|
|
775
|
+
Voice-First Rules:
|
|
776
|
+
- Optimize for natural speech. Avoid jargon unless central to the answer. Use short, punchy sentences.
|
|
777
|
+
- Never mention "search results," "sources," or "the provided text." Speak as if the knowledge is your own.
|
|
778
|
+
- No visual formatting. Do not say "bullet point," "bold," or "bracketed one." If you need to list items, say "First," "Next," and "Finally."
|
|
779
|
+
- Start with the most important information. No introductory filler.
|
|
780
|
+
- Be concise. Keep answers to 1-3 sentences. For complex topics, provide a high-level summary.
|
|
781
|
+
- Be confident. Avoid hedging phrases like "It seems that" or "I believe."
|
|
782
|
+
- If you don't have enough information, say so directly rather than guessing.
|
|
783
|
+
- Never use exclamation points. Keep your tone calm and conversational.`;
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
// dist/sdk/system_prompt.js
|
|
799
788
|
function buildSystemPrompt(config, opts) {
|
|
800
789
|
const { hasTools } = opts;
|
|
801
790
|
const agentInstructions = config.instructions ? `
|
|
@@ -809,34 +798,22 @@ ${config.instructions}` : "";
|
|
|
809
798
|
month: "long",
|
|
810
799
|
day: "numeric"
|
|
811
800
|
});
|
|
812
|
-
return
|
|
801
|
+
return DEFAULT_INSTRUCTIONS2 + `
|
|
813
802
|
|
|
814
803
|
Today's date is ${today}.` + agentInstructions + toolPreamble + (opts?.voice ? VOICE_RULES : "");
|
|
815
804
|
}
|
|
816
805
|
var VOICE_RULES;
|
|
817
806
|
var init_system_prompt = __esm({
|
|
818
|
-
"sdk/system_prompt.
|
|
807
|
+
"dist/sdk/system_prompt.js"() {
|
|
819
808
|
"use strict";
|
|
820
809
|
init_types();
|
|
821
810
|
VOICE_RULES = '\n\nCRITICAL OUTPUT RULES \u2014 you MUST follow these for EVERY response:\nYour response will be spoken aloud by a TTS system and displayed as plain text.\n- NEVER use markdown: no **, no *, no _, no #, no `, no [](), no ---\n- NEVER use bullet points (-, *, \u2022) or numbered lists (1., 2.)\n- NEVER use code blocks or inline code\n- NEVER mention tools, search, APIs, or technical failures to the user. If a tool returns no results, just answer naturally without explaining why.\n- Write exactly as you would say it out loud to a friend\n- Use short conversational sentences. To list things, say "First," "Next," "Finally,"\n- Keep responses concise \u2014 1 to 3 sentences max';
|
|
822
811
|
}
|
|
823
812
|
});
|
|
824
813
|
|
|
825
|
-
// sdk/session.
|
|
814
|
+
// dist/sdk/session.js
|
|
826
815
|
function createS2sSession(opts) {
|
|
827
|
-
const {
|
|
828
|
-
id,
|
|
829
|
-
agent,
|
|
830
|
-
client,
|
|
831
|
-
toolSchemas,
|
|
832
|
-
apiKey,
|
|
833
|
-
s2sConfig,
|
|
834
|
-
executeTool,
|
|
835
|
-
createWebSocket,
|
|
836
|
-
hookInvoker,
|
|
837
|
-
logger: log = consoleLogger,
|
|
838
|
-
metrics = noopMetrics
|
|
839
|
-
} = opts;
|
|
816
|
+
const { id, agent, client, toolSchemas, apiKey, s2sConfig, executeTool, createWebSocket, hookInvoker, logger: log = consoleLogger, metrics = noopMetrics } = opts;
|
|
840
817
|
const agentLabel = { agent };
|
|
841
818
|
const agentConfig = opts.skipGreeting ? { ...opts.agentConfig, greeting: "" } : opts.agentConfig;
|
|
842
819
|
const hasTools = toolSchemas.length > 0 || (agentConfig.builtinTools?.length ?? 0) > 0;
|
|
@@ -859,7 +836,8 @@ function createS2sSession(opts) {
|
|
|
859
836
|
let s2sSessionId = null;
|
|
860
837
|
let pendingTools = [];
|
|
861
838
|
async function resolveTurnConfig() {
|
|
862
|
-
if (!hookInvoker)
|
|
839
|
+
if (!hookInvoker)
|
|
840
|
+
return null;
|
|
863
841
|
try {
|
|
864
842
|
return await hookInvoker.resolveTurnConfig(id, HOOK_TIMEOUT_MS);
|
|
865
843
|
} catch {
|
|
@@ -867,7 +845,8 @@ function createS2sSession(opts) {
|
|
|
867
845
|
}
|
|
868
846
|
}
|
|
869
847
|
async function invokeHook(hook, ...args) {
|
|
870
|
-
if (!hookInvoker)
|
|
848
|
+
if (!hookInvoker)
|
|
849
|
+
return;
|
|
871
850
|
try {
|
|
872
851
|
switch (hook) {
|
|
873
852
|
case "onConnect":
|
|
@@ -1075,10 +1054,12 @@ function createS2sSession(opts) {
|
|
|
1075
1054
|
await connectAndSetup();
|
|
1076
1055
|
},
|
|
1077
1056
|
async stop() {
|
|
1078
|
-
if (sessionAbort.signal.aborted)
|
|
1057
|
+
if (sessionAbort.signal.aborted)
|
|
1058
|
+
return;
|
|
1079
1059
|
sessionAbort.abort();
|
|
1080
1060
|
metrics.sessionsActive.dec(agentLabel);
|
|
1081
|
-
if (turnPromise)
|
|
1061
|
+
if (turnPromise)
|
|
1062
|
+
await turnPromise;
|
|
1082
1063
|
s2s?.close();
|
|
1083
1064
|
invokeHook("onDisconnect");
|
|
1084
1065
|
},
|
|
@@ -1086,7 +1067,8 @@ function createS2sSession(opts) {
|
|
|
1086
1067
|
s2s?.sendAudio(data);
|
|
1087
1068
|
},
|
|
1088
1069
|
onAudioReady() {
|
|
1089
|
-
if (audioReady)
|
|
1070
|
+
if (audioReady)
|
|
1071
|
+
return;
|
|
1090
1072
|
audioReady = true;
|
|
1091
1073
|
},
|
|
1092
1074
|
onCancel() {
|
|
@@ -1112,7 +1094,7 @@ function createS2sSession(opts) {
|
|
|
1112
1094
|
}
|
|
1113
1095
|
var _internals3;
|
|
1114
1096
|
var init_session = __esm({
|
|
1115
|
-
"sdk/session.
|
|
1097
|
+
"dist/sdk/session.js"() {
|
|
1116
1098
|
"use strict";
|
|
1117
1099
|
init_protocol();
|
|
1118
1100
|
init_runtime();
|
|
@@ -1124,7 +1106,7 @@ var init_session = __esm({
|
|
|
1124
1106
|
}
|
|
1125
1107
|
});
|
|
1126
1108
|
|
|
1127
|
-
// sdk/worker_entry.
|
|
1109
|
+
// dist/sdk/worker_entry.js
|
|
1128
1110
|
import { z as z4 } from "zod";
|
|
1129
1111
|
async function executeToolCall(name, args, options) {
|
|
1130
1112
|
const { tool, env, sessionId, state, kv, messages } = options;
|
|
@@ -1143,13 +1125,15 @@ async function executeToolCall(name, args, options) {
|
|
|
1143
1125
|
abortSignal,
|
|
1144
1126
|
state: state ?? {},
|
|
1145
1127
|
get kv() {
|
|
1146
|
-
if (!kv)
|
|
1128
|
+
if (!kv)
|
|
1129
|
+
throw new Error("KV not available");
|
|
1147
1130
|
return kv;
|
|
1148
1131
|
},
|
|
1149
1132
|
messages: messages ?? []
|
|
1150
1133
|
};
|
|
1151
1134
|
const result = await Promise.resolve(tool.execute(parsed.data, ctx));
|
|
1152
|
-
if (result == null)
|
|
1135
|
+
if (result == null)
|
|
1136
|
+
return "null";
|
|
1153
1137
|
return typeof result === "string" ? result : JSON.stringify(result);
|
|
1154
1138
|
} catch (err) {
|
|
1155
1139
|
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
@@ -1162,13 +1146,13 @@ async function executeToolCall(name, args, options) {
|
|
|
1162
1146
|
}
|
|
1163
1147
|
var TOOL_HANDLER_TIMEOUT;
|
|
1164
1148
|
var init_worker_entry = __esm({
|
|
1165
|
-
"sdk/worker_entry.
|
|
1149
|
+
"dist/sdk/worker_entry.js"() {
|
|
1166
1150
|
"use strict";
|
|
1167
1151
|
TOOL_HANDLER_TIMEOUT = 3e4;
|
|
1168
1152
|
}
|
|
1169
1153
|
});
|
|
1170
1154
|
|
|
1171
|
-
// sdk/direct_executor.
|
|
1155
|
+
// dist/sdk/direct_executor.js
|
|
1172
1156
|
function buildAgentConfig(agent) {
|
|
1173
1157
|
const config = {
|
|
1174
1158
|
name: agent.name,
|
|
@@ -1176,29 +1160,22 @@ function buildAgentConfig(agent) {
|
|
|
1176
1160
|
greeting: agent.greeting,
|
|
1177
1161
|
voice: agent.voice
|
|
1178
1162
|
};
|
|
1179
|
-
if (agent.sttPrompt !== void 0)
|
|
1180
|
-
|
|
1181
|
-
if (agent.
|
|
1182
|
-
|
|
1183
|
-
if (agent.
|
|
1163
|
+
if (agent.sttPrompt !== void 0)
|
|
1164
|
+
config.sttPrompt = agent.sttPrompt;
|
|
1165
|
+
if (typeof agent.maxSteps !== "function")
|
|
1166
|
+
config.maxSteps = agent.maxSteps;
|
|
1167
|
+
if (agent.toolChoice !== void 0)
|
|
1168
|
+
config.toolChoice = agent.toolChoice;
|
|
1169
|
+
if (agent.builtinTools)
|
|
1170
|
+
config.builtinTools = [...agent.builtinTools];
|
|
1171
|
+
if (agent.activeTools)
|
|
1172
|
+
config.activeTools = [...agent.activeTools];
|
|
1184
1173
|
return config;
|
|
1185
1174
|
}
|
|
1186
1175
|
function createDirectExecutor(opts) {
|
|
1187
|
-
const {
|
|
1188
|
-
agent,
|
|
1189
|
-
env,
|
|
1190
|
-
kv = createMemoryKv(),
|
|
1191
|
-
vectorSearch,
|
|
1192
|
-
createWebSocket,
|
|
1193
|
-
logger = consoleLogger,
|
|
1194
|
-
metrics = noopMetrics,
|
|
1195
|
-
s2sConfig = DEFAULT_S2S_CONFIG
|
|
1196
|
-
} = opts;
|
|
1176
|
+
const { agent, env, kv = createMemoryKv(), vectorSearch, createWebSocket, logger = consoleLogger, metrics = noopMetrics, s2sConfig = DEFAULT_S2S_CONFIG } = opts;
|
|
1197
1177
|
const agentConfig = buildAgentConfig(agent);
|
|
1198
|
-
const builtinDefs = getBuiltinToolDefs(
|
|
1199
|
-
agent.builtinTools ?? [],
|
|
1200
|
-
vectorSearch ? { vectorSearch } : void 0
|
|
1201
|
-
);
|
|
1178
|
+
const builtinDefs = getBuiltinToolDefs(agent.builtinTools ?? [], vectorSearch ? { vectorSearch } : void 0);
|
|
1202
1179
|
const allTools = {
|
|
1203
1180
|
...builtinDefs,
|
|
1204
1181
|
...agent.tools
|
|
@@ -1226,7 +1203,8 @@ function createDirectExecutor(opts) {
|
|
|
1226
1203
|
}
|
|
1227
1204
|
const executeTool = async (name, args, sessionId, messages) => {
|
|
1228
1205
|
const tool = allTools[name];
|
|
1229
|
-
if (!tool)
|
|
1206
|
+
if (!tool)
|
|
1207
|
+
return JSON.stringify({ error: `Unknown tool: ${name}` });
|
|
1230
1208
|
return executeToolCall(name, args, {
|
|
1231
1209
|
tool,
|
|
1232
1210
|
env: frozenEnv,
|
|
@@ -1264,10 +1242,13 @@ function createDirectExecutor(opts) {
|
|
|
1264
1242
|
const result = await agent.onBeforeStep(0, ctx);
|
|
1265
1243
|
activeTools = result?.activeTools;
|
|
1266
1244
|
}
|
|
1267
|
-
if (maxSteps === void 0 && activeTools === void 0)
|
|
1245
|
+
if (maxSteps === void 0 && activeTools === void 0)
|
|
1246
|
+
return null;
|
|
1268
1247
|
const config = {};
|
|
1269
|
-
if (maxSteps !== void 0)
|
|
1270
|
-
|
|
1248
|
+
if (maxSteps !== void 0)
|
|
1249
|
+
config.maxSteps = maxSteps;
|
|
1250
|
+
if (activeTools !== void 0)
|
|
1251
|
+
config.activeTools = activeTools;
|
|
1271
1252
|
return config;
|
|
1272
1253
|
}
|
|
1273
1254
|
};
|
|
@@ -1295,7 +1276,7 @@ function createDirectExecutor(opts) {
|
|
|
1295
1276
|
return { executeTool, hookInvoker, toolSchemas, createSession };
|
|
1296
1277
|
}
|
|
1297
1278
|
var init_direct_executor = __esm({
|
|
1298
|
-
"sdk/direct_executor.
|
|
1279
|
+
"dist/sdk/direct_executor.js"() {
|
|
1299
1280
|
"use strict";
|
|
1300
1281
|
init_internal_types();
|
|
1301
1282
|
init_builtin_tools();
|
|
@@ -1306,7 +1287,7 @@ var init_direct_executor = __esm({
|
|
|
1306
1287
|
}
|
|
1307
1288
|
});
|
|
1308
1289
|
|
|
1309
|
-
// sdk/ws_handler.
|
|
1290
|
+
// dist/sdk/ws_handler.js
|
|
1310
1291
|
function isValidAudioChunk(data) {
|
|
1311
1292
|
return data.byteLength > 0 && data.byteLength <= MAX_AUDIO_CHUNK_BYTES && data.byteLength % 2 === 0;
|
|
1312
1293
|
}
|
|
@@ -1354,11 +1335,13 @@ function wireSessionSocket(ws, opts) {
|
|
|
1354
1335
|
ws.addEventListener("open", onOpen);
|
|
1355
1336
|
}
|
|
1356
1337
|
ws.addEventListener("message", (event) => {
|
|
1357
|
-
if (!session)
|
|
1338
|
+
if (!session)
|
|
1339
|
+
return;
|
|
1358
1340
|
const msgEvent = event;
|
|
1359
1341
|
const { data } = msgEvent;
|
|
1360
|
-
|
|
1361
|
-
|
|
1342
|
+
const isBinary = globalThis.Buffer?.isBuffer(data) || data instanceof ArrayBuffer || data instanceof Uint8Array;
|
|
1343
|
+
if (isBinary) {
|
|
1344
|
+
const chunk = data instanceof Uint8Array ? data : new Uint8Array(data.buffer ?? data, data.byteOffset ?? 0, data.byteLength ?? data.byteLength);
|
|
1362
1345
|
if (!isValidAudioChunk(chunk)) {
|
|
1363
1346
|
log.warn("Invalid audio chunk, dropping", {
|
|
1364
1347
|
...ctx,
|
|
@@ -1371,7 +1354,8 @@ function wireSessionSocket(ws, opts) {
|
|
|
1371
1354
|
session.onAudio(chunk);
|
|
1372
1355
|
return;
|
|
1373
1356
|
}
|
|
1374
|
-
if (typeof data !== "string")
|
|
1357
|
+
if (typeof data !== "string")
|
|
1358
|
+
return;
|
|
1375
1359
|
let json;
|
|
1376
1360
|
try {
|
|
1377
1361
|
json = JSON.parse(data);
|
|
@@ -1420,7 +1404,7 @@ function wireSessionSocket(ws, opts) {
|
|
|
1420
1404
|
}
|
|
1421
1405
|
var MAX_AUDIO_CHUNK_BYTES;
|
|
1422
1406
|
var init_ws_handler = __esm({
|
|
1423
|
-
"sdk/ws_handler.
|
|
1407
|
+
"dist/sdk/ws_handler.js"() {
|
|
1424
1408
|
"use strict";
|
|
1425
1409
|
init_protocol();
|
|
1426
1410
|
init_runtime();
|
|
@@ -1428,18 +1412,9 @@ var init_ws_handler = __esm({
|
|
|
1428
1412
|
}
|
|
1429
1413
|
});
|
|
1430
1414
|
|
|
1431
|
-
// sdk/winterc_server.
|
|
1415
|
+
// dist/sdk/winterc_server.js
|
|
1432
1416
|
function createWintercServer(options) {
|
|
1433
|
-
const {
|
|
1434
|
-
agent,
|
|
1435
|
-
env,
|
|
1436
|
-
kv = createMemoryKv(),
|
|
1437
|
-
vectorSearch,
|
|
1438
|
-
clientHtml,
|
|
1439
|
-
logger = consoleLogger,
|
|
1440
|
-
metrics = noopMetrics,
|
|
1441
|
-
s2sConfig = DEFAULT_S2S_CONFIG
|
|
1442
|
-
} = options;
|
|
1417
|
+
const { agent, env, kv = createMemoryKv(), vectorSearch, clientHtml, logger = consoleLogger, metrics = noopMetrics, s2sConfig = DEFAULT_S2S_CONFIG } = options;
|
|
1443
1418
|
const executor = createDirectExecutor({
|
|
1444
1419
|
agent,
|
|
1445
1420
|
env,
|
|
@@ -1472,10 +1447,7 @@ function createWintercServer(options) {
|
|
|
1472
1447
|
});
|
|
1473
1448
|
}
|
|
1474
1449
|
if (url.pathname === "/") {
|
|
1475
|
-
return new Response(
|
|
1476
|
-
`<!DOCTYPE html><html><body><h1>${agent.name}</h1><p>Agent server running.</p></body></html>`,
|
|
1477
|
-
{ headers: { "Content-Type": "text/html" } }
|
|
1478
|
-
);
|
|
1450
|
+
return new Response(`<!DOCTYPE html><html><body><h1>${agent.name}</h1><p>Agent server running.</p></body></html>`, { headers: { "Content-Type": "text/html" } });
|
|
1479
1451
|
}
|
|
1480
1452
|
return new Response("Not Found", { status: 404 });
|
|
1481
1453
|
},
|
|
@@ -1501,7 +1473,7 @@ function createWintercServer(options) {
|
|
|
1501
1473
|
};
|
|
1502
1474
|
}
|
|
1503
1475
|
var init_winterc_server = __esm({
|
|
1504
|
-
"sdk/winterc_server.
|
|
1476
|
+
"dist/sdk/winterc_server.js"() {
|
|
1505
1477
|
"use strict";
|
|
1506
1478
|
init_direct_executor();
|
|
1507
1479
|
init_kv();
|
|
@@ -1511,7 +1483,7 @@ var init_winterc_server = __esm({
|
|
|
1511
1483
|
}
|
|
1512
1484
|
});
|
|
1513
1485
|
|
|
1514
|
-
// sdk/server.
|
|
1486
|
+
// dist/sdk/server.js
|
|
1515
1487
|
var server_exports = {};
|
|
1516
1488
|
__export(server_exports, {
|
|
1517
1489
|
createServer: () => createServer
|
|
@@ -1522,23 +1494,20 @@ async function loadWsFactory() {
|
|
|
1522
1494
|
const WS = mod.default ?? mod;
|
|
1523
1495
|
return (url, opts) => new WS(url, { headers: opts.headers });
|
|
1524
1496
|
} catch {
|
|
1525
|
-
throw new Error(
|
|
1526
|
-
"WebSocket factory not provided and `ws` package not found. Install `ws` (`npm install ws`) or pass `createWebSocket` option."
|
|
1527
|
-
);
|
|
1497
|
+
throw new Error("WebSocket factory not provided and `ws` package not found. Install `ws` (`npm install ws`) or pass `createWebSocket` option.");
|
|
1528
1498
|
}
|
|
1529
1499
|
}
|
|
1530
1500
|
function resolveEnv(env) {
|
|
1531
1501
|
const resolved = {};
|
|
1532
1502
|
for (const [key, value] of Object.entries(env)) {
|
|
1533
|
-
if (value !== void 0)
|
|
1503
|
+
if (value !== void 0)
|
|
1504
|
+
resolved[key] = value;
|
|
1534
1505
|
}
|
|
1535
1506
|
return resolved;
|
|
1536
1507
|
}
|
|
1537
1508
|
function createServer(options) {
|
|
1538
1509
|
const { agent, kv, clientHtml, logger = consoleLogger, s2sConfig = DEFAULT_S2S_CONFIG } = options;
|
|
1539
|
-
const env = resolveEnv(
|
|
1540
|
-
options.env ?? (typeof process !== "undefined" ? process.env : {})
|
|
1541
|
-
);
|
|
1510
|
+
const env = resolveEnv(options.env ?? (typeof process !== "undefined" ? process.env : {}));
|
|
1542
1511
|
let wsFactory = options.createWebSocket ?? null;
|
|
1543
1512
|
async function getWsFactory() {
|
|
1544
1513
|
if (!wsFactory) {
|
|
@@ -1554,7 +1523,7 @@ function createServer(options) {
|
|
|
1554
1523
|
env,
|
|
1555
1524
|
...kv ? { kv } : {},
|
|
1556
1525
|
createWebSocket: wsFactory,
|
|
1557
|
-
clientHtml,
|
|
1526
|
+
...clientHtml !== void 0 ? { clientHtml } : {},
|
|
1558
1527
|
logger,
|
|
1559
1528
|
s2sConfig
|
|
1560
1529
|
});
|
|
@@ -1576,7 +1545,8 @@ function createServer(options) {
|
|
|
1576
1545
|
const url = new URL(req.url ?? "/", `${protocol}://${host}`);
|
|
1577
1546
|
const headers = new Headers();
|
|
1578
1547
|
for (const [key, val] of Object.entries(req.headers)) {
|
|
1579
|
-
if (val)
|
|
1548
|
+
if (val)
|
|
1549
|
+
headers.set(key, Array.isArray(val) ? val[0] : val);
|
|
1580
1550
|
}
|
|
1581
1551
|
const request = new Request(url, {
|
|
1582
1552
|
method: req.method ?? "GET",
|
|
@@ -1593,23 +1563,17 @@ function createServer(options) {
|
|
|
1593
1563
|
});
|
|
1594
1564
|
try {
|
|
1595
1565
|
const wsMod = await import("ws");
|
|
1596
|
-
const WSServer = wsMod.WebSocketServer
|
|
1566
|
+
const WSServer = wsMod.WebSocketServer;
|
|
1597
1567
|
if (WSServer) {
|
|
1598
1568
|
const wss = new WSServer({ noServer: true });
|
|
1599
1569
|
nodeServer.on("upgrade", (req, socket, head) => {
|
|
1600
|
-
wss.handleUpgrade(
|
|
1601
|
-
req,
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
`http://localhost:${port}`
|
|
1608
|
-
);
|
|
1609
|
-
const resume = reqUrl.searchParams.has("resume");
|
|
1610
|
-
getWinterc().handleWebSocket(ws, { skipGreeting: resume });
|
|
1611
|
-
}
|
|
1612
|
-
);
|
|
1570
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
1571
|
+
const reqUrl = new URL(req.url ?? "/", `http://localhost:${port}`);
|
|
1572
|
+
const resume = reqUrl.searchParams.has("resume");
|
|
1573
|
+
getWinterc().handleWebSocket(ws, {
|
|
1574
|
+
skipGreeting: resume
|
|
1575
|
+
});
|
|
1576
|
+
});
|
|
1613
1577
|
});
|
|
1614
1578
|
}
|
|
1615
1579
|
} catch {
|
|
@@ -1636,7 +1600,7 @@ function createServer(options) {
|
|
|
1636
1600
|
};
|
|
1637
1601
|
}
|
|
1638
1602
|
var init_server = __esm({
|
|
1639
|
-
"sdk/server.
|
|
1603
|
+
"dist/sdk/server.js"() {
|
|
1640
1604
|
init_runtime();
|
|
1641
1605
|
init_winterc_server();
|
|
1642
1606
|
}
|
|
@@ -2126,12 +2090,27 @@ import { build } from "vite";
|
|
|
2126
2090
|
import { viteSingleFile } from "vite-plugin-singlefile";
|
|
2127
2091
|
|
|
2128
2092
|
// cli/_static_config.ts
|
|
2129
|
-
init_types();
|
|
2130
2093
|
import fs2 from "node:fs/promises";
|
|
2131
2094
|
import {
|
|
2132
2095
|
Project,
|
|
2133
2096
|
SyntaxKind
|
|
2134
2097
|
} from "ts-morph";
|
|
2098
|
+
|
|
2099
|
+
// sdk/types.ts
|
|
2100
|
+
var DEFAULT_INSTRUCTIONS = `You are AAI, a helpful AI assistant.
|
|
2101
|
+
|
|
2102
|
+
Voice-First Rules:
|
|
2103
|
+
- Optimize for natural speech. Avoid jargon unless central to the answer. Use short, punchy sentences.
|
|
2104
|
+
- Never mention "search results," "sources," or "the provided text." Speak as if the knowledge is your own.
|
|
2105
|
+
- No visual formatting. Do not say "bullet point," "bold," or "bracketed one." If you need to list items, say "First," "Next," and "Finally."
|
|
2106
|
+
- Start with the most important information. No introductory filler.
|
|
2107
|
+
- Be concise. Keep answers to 1-3 sentences. For complex topics, provide a high-level summary.
|
|
2108
|
+
- Be confident. Avoid hedging phrases like "It seems that" or "I believe."
|
|
2109
|
+
- If you don't have enough information, say so directly rather than guessing.
|
|
2110
|
+
- Never use exclamation points. Keep your tone calm and conversational.`;
|
|
2111
|
+
var DEFAULT_GREETING = "Hey there. I'm a voice assistant. What can I help you with?";
|
|
2112
|
+
|
|
2113
|
+
// cli/_static_config.ts
|
|
2135
2114
|
var project = new Project({ useInMemoryFileSystem: true });
|
|
2136
2115
|
async function extractStaticConfig(agentPath) {
|
|
2137
2116
|
const source = await fs2.readFile(agentPath, "utf-8");
|