@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.
- package/README.md +0 -6
- package/dist/aai.js +3 -0
- package/dist/cli.js +244 -245
- 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 +103 -28
- 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 -438
- 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 -190
- 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":
|
|
@@ -966,7 +945,8 @@ function createS2sSession(opts) {
|
|
|
966
945
|
}
|
|
967
946
|
handle.updateSession({
|
|
968
947
|
system_prompt: systemPrompt,
|
|
969
|
-
tools: s2sTools
|
|
948
|
+
tools: s2sTools,
|
|
949
|
+
...agentConfig.greeting ? { greeting: agentConfig.greeting } : {}
|
|
970
950
|
});
|
|
971
951
|
handle.addEventListener("ready", ((e) => {
|
|
972
952
|
s2sSessionId = e.detail.session_id;
|
|
@@ -1074,10 +1054,12 @@ function createS2sSession(opts) {
|
|
|
1074
1054
|
await connectAndSetup();
|
|
1075
1055
|
},
|
|
1076
1056
|
async stop() {
|
|
1077
|
-
if (sessionAbort.signal.aborted)
|
|
1057
|
+
if (sessionAbort.signal.aborted)
|
|
1058
|
+
return;
|
|
1078
1059
|
sessionAbort.abort();
|
|
1079
1060
|
metrics.sessionsActive.dec(agentLabel);
|
|
1080
|
-
if (turnPromise)
|
|
1061
|
+
if (turnPromise)
|
|
1062
|
+
await turnPromise;
|
|
1081
1063
|
s2s?.close();
|
|
1082
1064
|
invokeHook("onDisconnect");
|
|
1083
1065
|
},
|
|
@@ -1085,15 +1067,9 @@ function createS2sSession(opts) {
|
|
|
1085
1067
|
s2s?.sendAudio(data);
|
|
1086
1068
|
},
|
|
1087
1069
|
onAudioReady() {
|
|
1088
|
-
if (audioReady)
|
|
1070
|
+
if (audioReady)
|
|
1071
|
+
return;
|
|
1089
1072
|
audioReady = true;
|
|
1090
|
-
if (agentConfig.greeting && s2s) {
|
|
1091
|
-
s2s.updateSession({
|
|
1092
|
-
system_prompt: systemPrompt,
|
|
1093
|
-
tools: s2sTools,
|
|
1094
|
-
greeting: agentConfig.greeting
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
1073
|
},
|
|
1098
1074
|
onCancel() {
|
|
1099
1075
|
client.event({ type: "cancelled" });
|
|
@@ -1118,7 +1094,7 @@ function createS2sSession(opts) {
|
|
|
1118
1094
|
}
|
|
1119
1095
|
var _internals3;
|
|
1120
1096
|
var init_session = __esm({
|
|
1121
|
-
"sdk/session.
|
|
1097
|
+
"dist/sdk/session.js"() {
|
|
1122
1098
|
"use strict";
|
|
1123
1099
|
init_protocol();
|
|
1124
1100
|
init_runtime();
|
|
@@ -1130,7 +1106,7 @@ var init_session = __esm({
|
|
|
1130
1106
|
}
|
|
1131
1107
|
});
|
|
1132
1108
|
|
|
1133
|
-
// sdk/worker_entry.
|
|
1109
|
+
// dist/sdk/worker_entry.js
|
|
1134
1110
|
import { z as z4 } from "zod";
|
|
1135
1111
|
async function executeToolCall(name, args, options) {
|
|
1136
1112
|
const { tool, env, sessionId, state, kv, messages } = options;
|
|
@@ -1149,13 +1125,15 @@ async function executeToolCall(name, args, options) {
|
|
|
1149
1125
|
abortSignal,
|
|
1150
1126
|
state: state ?? {},
|
|
1151
1127
|
get kv() {
|
|
1152
|
-
if (!kv)
|
|
1128
|
+
if (!kv)
|
|
1129
|
+
throw new Error("KV not available");
|
|
1153
1130
|
return kv;
|
|
1154
1131
|
},
|
|
1155
1132
|
messages: messages ?? []
|
|
1156
1133
|
};
|
|
1157
1134
|
const result = await Promise.resolve(tool.execute(parsed.data, ctx));
|
|
1158
|
-
if (result == null)
|
|
1135
|
+
if (result == null)
|
|
1136
|
+
return "null";
|
|
1159
1137
|
return typeof result === "string" ? result : JSON.stringify(result);
|
|
1160
1138
|
} catch (err) {
|
|
1161
1139
|
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
@@ -1168,13 +1146,13 @@ async function executeToolCall(name, args, options) {
|
|
|
1168
1146
|
}
|
|
1169
1147
|
var TOOL_HANDLER_TIMEOUT;
|
|
1170
1148
|
var init_worker_entry = __esm({
|
|
1171
|
-
"sdk/worker_entry.
|
|
1149
|
+
"dist/sdk/worker_entry.js"() {
|
|
1172
1150
|
"use strict";
|
|
1173
1151
|
TOOL_HANDLER_TIMEOUT = 3e4;
|
|
1174
1152
|
}
|
|
1175
1153
|
});
|
|
1176
1154
|
|
|
1177
|
-
// sdk/direct_executor.
|
|
1155
|
+
// dist/sdk/direct_executor.js
|
|
1178
1156
|
function buildAgentConfig(agent) {
|
|
1179
1157
|
const config = {
|
|
1180
1158
|
name: agent.name,
|
|
@@ -1182,29 +1160,22 @@ function buildAgentConfig(agent) {
|
|
|
1182
1160
|
greeting: agent.greeting,
|
|
1183
1161
|
voice: agent.voice
|
|
1184
1162
|
};
|
|
1185
|
-
if (agent.sttPrompt !== void 0)
|
|
1186
|
-
|
|
1187
|
-
if (agent.
|
|
1188
|
-
|
|
1189
|
-
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];
|
|
1190
1173
|
return config;
|
|
1191
1174
|
}
|
|
1192
1175
|
function createDirectExecutor(opts) {
|
|
1193
|
-
const {
|
|
1194
|
-
agent,
|
|
1195
|
-
env,
|
|
1196
|
-
kv = createMemoryKv(),
|
|
1197
|
-
vectorSearch,
|
|
1198
|
-
createWebSocket,
|
|
1199
|
-
logger = consoleLogger,
|
|
1200
|
-
metrics = noopMetrics,
|
|
1201
|
-
s2sConfig = DEFAULT_S2S_CONFIG
|
|
1202
|
-
} = opts;
|
|
1176
|
+
const { agent, env, kv = createMemoryKv(), vectorSearch, createWebSocket, logger = consoleLogger, metrics = noopMetrics, s2sConfig = DEFAULT_S2S_CONFIG } = opts;
|
|
1203
1177
|
const agentConfig = buildAgentConfig(agent);
|
|
1204
|
-
const builtinDefs = getBuiltinToolDefs(
|
|
1205
|
-
agent.builtinTools ?? [],
|
|
1206
|
-
vectorSearch ? { vectorSearch } : void 0
|
|
1207
|
-
);
|
|
1178
|
+
const builtinDefs = getBuiltinToolDefs(agent.builtinTools ?? [], vectorSearch ? { vectorSearch } : void 0);
|
|
1208
1179
|
const allTools = {
|
|
1209
1180
|
...builtinDefs,
|
|
1210
1181
|
...agent.tools
|
|
@@ -1232,7 +1203,8 @@ function createDirectExecutor(opts) {
|
|
|
1232
1203
|
}
|
|
1233
1204
|
const executeTool = async (name, args, sessionId, messages) => {
|
|
1234
1205
|
const tool = allTools[name];
|
|
1235
|
-
if (!tool)
|
|
1206
|
+
if (!tool)
|
|
1207
|
+
return JSON.stringify({ error: `Unknown tool: ${name}` });
|
|
1236
1208
|
return executeToolCall(name, args, {
|
|
1237
1209
|
tool,
|
|
1238
1210
|
env: frozenEnv,
|
|
@@ -1270,10 +1242,13 @@ function createDirectExecutor(opts) {
|
|
|
1270
1242
|
const result = await agent.onBeforeStep(0, ctx);
|
|
1271
1243
|
activeTools = result?.activeTools;
|
|
1272
1244
|
}
|
|
1273
|
-
if (maxSteps === void 0 && activeTools === void 0)
|
|
1245
|
+
if (maxSteps === void 0 && activeTools === void 0)
|
|
1246
|
+
return null;
|
|
1274
1247
|
const config = {};
|
|
1275
|
-
if (maxSteps !== void 0)
|
|
1276
|
-
|
|
1248
|
+
if (maxSteps !== void 0)
|
|
1249
|
+
config.maxSteps = maxSteps;
|
|
1250
|
+
if (activeTools !== void 0)
|
|
1251
|
+
config.activeTools = activeTools;
|
|
1277
1252
|
return config;
|
|
1278
1253
|
}
|
|
1279
1254
|
};
|
|
@@ -1301,7 +1276,7 @@ function createDirectExecutor(opts) {
|
|
|
1301
1276
|
return { executeTool, hookInvoker, toolSchemas, createSession };
|
|
1302
1277
|
}
|
|
1303
1278
|
var init_direct_executor = __esm({
|
|
1304
|
-
"sdk/direct_executor.
|
|
1279
|
+
"dist/sdk/direct_executor.js"() {
|
|
1305
1280
|
"use strict";
|
|
1306
1281
|
init_internal_types();
|
|
1307
1282
|
init_builtin_tools();
|
|
@@ -1312,7 +1287,7 @@ var init_direct_executor = __esm({
|
|
|
1312
1287
|
}
|
|
1313
1288
|
});
|
|
1314
1289
|
|
|
1315
|
-
// sdk/ws_handler.
|
|
1290
|
+
// dist/sdk/ws_handler.js
|
|
1316
1291
|
function isValidAudioChunk(data) {
|
|
1317
1292
|
return data.byteLength > 0 && data.byteLength <= MAX_AUDIO_CHUNK_BYTES && data.byteLength % 2 === 0;
|
|
1318
1293
|
}
|
|
@@ -1344,7 +1319,7 @@ function wireSessionSocket(ws, opts) {
|
|
|
1344
1319
|
const sid = sessionId.slice(0, 8);
|
|
1345
1320
|
const ctx = opts.logContext ?? {};
|
|
1346
1321
|
let session = null;
|
|
1347
|
-
|
|
1322
|
+
function onOpen() {
|
|
1348
1323
|
opts.onOpen?.();
|
|
1349
1324
|
log.info("Session connected", { ...ctx, sid });
|
|
1350
1325
|
const client = createClientSink(ws);
|
|
@@ -1353,13 +1328,20 @@ function wireSessionSocket(ws, opts) {
|
|
|
1353
1328
|
ws.send(JSON.stringify({ type: "config", ...opts.readyConfig }));
|
|
1354
1329
|
void session.start();
|
|
1355
1330
|
log.info("Session ready", { ...ctx, sid });
|
|
1356
|
-
}
|
|
1331
|
+
}
|
|
1332
|
+
if (ws.readyState === 1) {
|
|
1333
|
+
onOpen();
|
|
1334
|
+
} else {
|
|
1335
|
+
ws.addEventListener("open", onOpen);
|
|
1336
|
+
}
|
|
1357
1337
|
ws.addEventListener("message", (event) => {
|
|
1358
|
-
if (!session)
|
|
1338
|
+
if (!session)
|
|
1339
|
+
return;
|
|
1359
1340
|
const msgEvent = event;
|
|
1360
1341
|
const { data } = msgEvent;
|
|
1361
|
-
|
|
1362
|
-
|
|
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);
|
|
1363
1345
|
if (!isValidAudioChunk(chunk)) {
|
|
1364
1346
|
log.warn("Invalid audio chunk, dropping", {
|
|
1365
1347
|
...ctx,
|
|
@@ -1372,7 +1354,8 @@ function wireSessionSocket(ws, opts) {
|
|
|
1372
1354
|
session.onAudio(chunk);
|
|
1373
1355
|
return;
|
|
1374
1356
|
}
|
|
1375
|
-
if (typeof data !== "string")
|
|
1357
|
+
if (typeof data !== "string")
|
|
1358
|
+
return;
|
|
1376
1359
|
let json;
|
|
1377
1360
|
try {
|
|
1378
1361
|
json = JSON.parse(data);
|
|
@@ -1421,7 +1404,7 @@ function wireSessionSocket(ws, opts) {
|
|
|
1421
1404
|
}
|
|
1422
1405
|
var MAX_AUDIO_CHUNK_BYTES;
|
|
1423
1406
|
var init_ws_handler = __esm({
|
|
1424
|
-
"sdk/ws_handler.
|
|
1407
|
+
"dist/sdk/ws_handler.js"() {
|
|
1425
1408
|
"use strict";
|
|
1426
1409
|
init_protocol();
|
|
1427
1410
|
init_runtime();
|
|
@@ -1429,18 +1412,9 @@ var init_ws_handler = __esm({
|
|
|
1429
1412
|
}
|
|
1430
1413
|
});
|
|
1431
1414
|
|
|
1432
|
-
// sdk/winterc_server.
|
|
1415
|
+
// dist/sdk/winterc_server.js
|
|
1433
1416
|
function createWintercServer(options) {
|
|
1434
|
-
const {
|
|
1435
|
-
agent,
|
|
1436
|
-
env,
|
|
1437
|
-
kv = createMemoryKv(),
|
|
1438
|
-
vectorSearch,
|
|
1439
|
-
clientHtml,
|
|
1440
|
-
logger = consoleLogger,
|
|
1441
|
-
metrics = noopMetrics,
|
|
1442
|
-
s2sConfig = DEFAULT_S2S_CONFIG
|
|
1443
|
-
} = options;
|
|
1417
|
+
const { agent, env, kv = createMemoryKv(), vectorSearch, clientHtml, logger = consoleLogger, metrics = noopMetrics, s2sConfig = DEFAULT_S2S_CONFIG } = options;
|
|
1444
1418
|
const executor = createDirectExecutor({
|
|
1445
1419
|
agent,
|
|
1446
1420
|
env,
|
|
@@ -1473,10 +1447,7 @@ function createWintercServer(options) {
|
|
|
1473
1447
|
});
|
|
1474
1448
|
}
|
|
1475
1449
|
if (url.pathname === "/") {
|
|
1476
|
-
return new Response(
|
|
1477
|
-
`<!DOCTYPE html><html><body><h1>${agent.name}</h1><p>Agent server running.</p></body></html>`,
|
|
1478
|
-
{ headers: { "Content-Type": "text/html" } }
|
|
1479
|
-
);
|
|
1450
|
+
return new Response(`<!DOCTYPE html><html><body><h1>${agent.name}</h1><p>Agent server running.</p></body></html>`, { headers: { "Content-Type": "text/html" } });
|
|
1480
1451
|
}
|
|
1481
1452
|
return new Response("Not Found", { status: 404 });
|
|
1482
1453
|
},
|
|
@@ -1502,7 +1473,7 @@ function createWintercServer(options) {
|
|
|
1502
1473
|
};
|
|
1503
1474
|
}
|
|
1504
1475
|
var init_winterc_server = __esm({
|
|
1505
|
-
"sdk/winterc_server.
|
|
1476
|
+
"dist/sdk/winterc_server.js"() {
|
|
1506
1477
|
"use strict";
|
|
1507
1478
|
init_direct_executor();
|
|
1508
1479
|
init_kv();
|
|
@@ -1512,7 +1483,7 @@ var init_winterc_server = __esm({
|
|
|
1512
1483
|
}
|
|
1513
1484
|
});
|
|
1514
1485
|
|
|
1515
|
-
// sdk/server.
|
|
1486
|
+
// dist/sdk/server.js
|
|
1516
1487
|
var server_exports = {};
|
|
1517
1488
|
__export(server_exports, {
|
|
1518
1489
|
createServer: () => createServer
|
|
@@ -1523,23 +1494,20 @@ async function loadWsFactory() {
|
|
|
1523
1494
|
const WS = mod.default ?? mod;
|
|
1524
1495
|
return (url, opts) => new WS(url, { headers: opts.headers });
|
|
1525
1496
|
} catch {
|
|
1526
|
-
throw new Error(
|
|
1527
|
-
"WebSocket factory not provided and `ws` package not found. Install `ws` (`npm install ws`) or pass `createWebSocket` option."
|
|
1528
|
-
);
|
|
1497
|
+
throw new Error("WebSocket factory not provided and `ws` package not found. Install `ws` (`npm install ws`) or pass `createWebSocket` option.");
|
|
1529
1498
|
}
|
|
1530
1499
|
}
|
|
1531
1500
|
function resolveEnv(env) {
|
|
1532
1501
|
const resolved = {};
|
|
1533
1502
|
for (const [key, value] of Object.entries(env)) {
|
|
1534
|
-
if (value !== void 0)
|
|
1503
|
+
if (value !== void 0)
|
|
1504
|
+
resolved[key] = value;
|
|
1535
1505
|
}
|
|
1536
1506
|
return resolved;
|
|
1537
1507
|
}
|
|
1538
1508
|
function createServer(options) {
|
|
1539
1509
|
const { agent, kv, clientHtml, logger = consoleLogger, s2sConfig = DEFAULT_S2S_CONFIG } = options;
|
|
1540
|
-
const env = resolveEnv(
|
|
1541
|
-
options.env ?? (typeof process !== "undefined" ? process.env : {})
|
|
1542
|
-
);
|
|
1510
|
+
const env = resolveEnv(options.env ?? (typeof process !== "undefined" ? process.env : {}));
|
|
1543
1511
|
let wsFactory = options.createWebSocket ?? null;
|
|
1544
1512
|
async function getWsFactory() {
|
|
1545
1513
|
if (!wsFactory) {
|
|
@@ -1555,7 +1523,7 @@ function createServer(options) {
|
|
|
1555
1523
|
env,
|
|
1556
1524
|
...kv ? { kv } : {},
|
|
1557
1525
|
createWebSocket: wsFactory,
|
|
1558
|
-
clientHtml,
|
|
1526
|
+
...clientHtml !== void 0 ? { clientHtml } : {},
|
|
1559
1527
|
logger,
|
|
1560
1528
|
s2sConfig
|
|
1561
1529
|
});
|
|
@@ -1577,7 +1545,8 @@ function createServer(options) {
|
|
|
1577
1545
|
const url = new URL(req.url ?? "/", `${protocol}://${host}`);
|
|
1578
1546
|
const headers = new Headers();
|
|
1579
1547
|
for (const [key, val] of Object.entries(req.headers)) {
|
|
1580
|
-
if (val)
|
|
1548
|
+
if (val)
|
|
1549
|
+
headers.set(key, Array.isArray(val) ? val[0] : val);
|
|
1581
1550
|
}
|
|
1582
1551
|
const request = new Request(url, {
|
|
1583
1552
|
method: req.method ?? "GET",
|
|
@@ -1594,23 +1563,17 @@ function createServer(options) {
|
|
|
1594
1563
|
});
|
|
1595
1564
|
try {
|
|
1596
1565
|
const wsMod = await import("ws");
|
|
1597
|
-
const WSServer = wsMod.WebSocketServer
|
|
1566
|
+
const WSServer = wsMod.WebSocketServer;
|
|
1598
1567
|
if (WSServer) {
|
|
1599
1568
|
const wss = new WSServer({ noServer: true });
|
|
1600
1569
|
nodeServer.on("upgrade", (req, socket, head) => {
|
|
1601
|
-
wss.handleUpgrade(
|
|
1602
|
-
req,
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
`http://localhost:${port}`
|
|
1609
|
-
);
|
|
1610
|
-
const resume = reqUrl.searchParams.has("resume");
|
|
1611
|
-
getWinterc().handleWebSocket(ws, { skipGreeting: resume });
|
|
1612
|
-
}
|
|
1613
|
-
);
|
|
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
|
+
});
|
|
1614
1577
|
});
|
|
1615
1578
|
}
|
|
1616
1579
|
} catch {
|
|
@@ -1637,7 +1600,7 @@ function createServer(options) {
|
|
|
1637
1600
|
};
|
|
1638
1601
|
}
|
|
1639
1602
|
var init_server = __esm({
|
|
1640
|
-
"sdk/server.
|
|
1603
|
+
"dist/sdk/server.js"() {
|
|
1641
1604
|
init_runtime();
|
|
1642
1605
|
init_winterc_server();
|
|
1643
1606
|
}
|
|
@@ -1794,6 +1757,7 @@ async function askSelect(message, choices) {
|
|
|
1794
1757
|
Select,
|
|
1795
1758
|
{
|
|
1796
1759
|
options: choices,
|
|
1760
|
+
visibleOptionCount: choices.length,
|
|
1797
1761
|
onChange: (value) => {
|
|
1798
1762
|
resolve(value);
|
|
1799
1763
|
app.unmount();
|
|
@@ -1807,7 +1771,8 @@ async function askSelect(message, choices) {
|
|
|
1807
1771
|
|
|
1808
1772
|
// cli/_discover.ts
|
|
1809
1773
|
function isDevMode() {
|
|
1810
|
-
|
|
1774
|
+
const script = process.argv[1] ?? "";
|
|
1775
|
+
return script.endsWith(".ts") || script.endsWith(".tsx");
|
|
1811
1776
|
}
|
|
1812
1777
|
function generateSlug() {
|
|
1813
1778
|
return humanId({ separator: "-", capitalize: false });
|
|
@@ -2072,7 +2037,10 @@ function CommandRunner({
|
|
|
2072
2037
|
const { items, log } = useStepLog();
|
|
2073
2038
|
const [spinning, setSpinning] = useState(true);
|
|
2074
2039
|
const [err, setErr] = useState(null);
|
|
2040
|
+
const started = useRef(false);
|
|
2075
2041
|
React.useEffect(() => {
|
|
2042
|
+
if (started.current) return;
|
|
2043
|
+
started.current = true;
|
|
2076
2044
|
(async () => {
|
|
2077
2045
|
try {
|
|
2078
2046
|
await run(log);
|
|
@@ -2084,7 +2052,7 @@ function CommandRunner({
|
|
|
2084
2052
|
setSpinning(false);
|
|
2085
2053
|
exit();
|
|
2086
2054
|
})();
|
|
2087
|
-
}
|
|
2055
|
+
});
|
|
2088
2056
|
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
2089
2057
|
/* @__PURE__ */ jsx2(StepLog, { items }),
|
|
2090
2058
|
err && /* @__PURE__ */ jsx2(ErrorLine, { msg: err }),
|
|
@@ -2122,12 +2090,27 @@ import { build } from "vite";
|
|
|
2122
2090
|
import { viteSingleFile } from "vite-plugin-singlefile";
|
|
2123
2091
|
|
|
2124
2092
|
// cli/_static_config.ts
|
|
2125
|
-
init_types();
|
|
2126
2093
|
import fs2 from "node:fs/promises";
|
|
2127
2094
|
import {
|
|
2128
2095
|
Project,
|
|
2129
2096
|
SyntaxKind
|
|
2130
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
|
|
2131
2114
|
var project = new Project({ useInMemoryFileSystem: true });
|
|
2132
2115
|
async function extractStaticConfig(agentPath) {
|
|
2133
2116
|
const source = await fs2.readFile(agentPath, "utf-8");
|
|
@@ -2485,6 +2468,7 @@ var DEFAULT_STYLES_CSS = `@import url("https://fonts.googleapis.com/css2?family=
|
|
|
2485
2468
|
@import "tailwindcss";
|
|
2486
2469
|
@source "./";
|
|
2487
2470
|
@source "./components/";
|
|
2471
|
+
@source "./node_modules/@alexkroman1/aai/ui/";
|
|
2488
2472
|
|
|
2489
2473
|
@theme {
|
|
2490
2474
|
--color-aai-bg: #101010;
|
|
@@ -2562,7 +2546,7 @@ var INDEX_HTML = `<!DOCTYPE html>
|
|
|
2562
2546
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
|
2563
2547
|
/>
|
|
2564
2548
|
<title>aai</title>
|
|
2565
|
-
<link rel="icon" href="
|
|
2549
|
+
<link rel="icon" href="data:," />
|
|
2566
2550
|
<link rel="stylesheet" href="../styles.css" />
|
|
2567
2551
|
</head>
|
|
2568
2552
|
<body>
|
|
@@ -2863,15 +2847,25 @@ init_output();
|
|
|
2863
2847
|
|
|
2864
2848
|
// cli/_server_common.ts
|
|
2865
2849
|
import path7 from "node:path";
|
|
2850
|
+
import { createServer as createViteServer } from "vite";
|
|
2866
2851
|
init_output();
|
|
2867
2852
|
async function loadAgentDef(cwd) {
|
|
2868
2853
|
const agentPath = path7.resolve(cwd, "agent.ts");
|
|
2869
|
-
const
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2854
|
+
const vite = await createViteServer({
|
|
2855
|
+
root: cwd,
|
|
2856
|
+
logLevel: "silent",
|
|
2857
|
+
server: { middlewareMode: true }
|
|
2858
|
+
});
|
|
2859
|
+
try {
|
|
2860
|
+
const agentModule = await vite.ssrLoadModule(agentPath);
|
|
2861
|
+
const agentDef = agentModule.default;
|
|
2862
|
+
if (!agentDef || typeof agentDef !== "object" || !agentDef.name) {
|
|
2863
|
+
throw new Error("agent.ts must export a default agent definition (from defineAgent())");
|
|
2864
|
+
}
|
|
2865
|
+
return agentDef;
|
|
2866
|
+
} finally {
|
|
2867
|
+
await vite.close();
|
|
2873
2868
|
}
|
|
2874
|
-
return agentDef;
|
|
2875
2869
|
}
|
|
2876
2870
|
async function resolveServerEnv() {
|
|
2877
2871
|
const env = { ...process.env };
|
|
@@ -2885,13 +2879,21 @@ async function resolveServerEnv() {
|
|
|
2885
2879
|
}
|
|
2886
2880
|
return env;
|
|
2887
2881
|
}
|
|
2888
|
-
async function
|
|
2882
|
+
async function loadWsFromProject(cwd) {
|
|
2883
|
+
const wsPath = path7.resolve(cwd, "node_modules", "ws", "index.js");
|
|
2884
|
+
const mod = await import(wsPath);
|
|
2885
|
+
const WS = mod.default ?? mod;
|
|
2886
|
+
return (url, opts) => new WS(url, { headers: opts.headers });
|
|
2887
|
+
}
|
|
2888
|
+
async function bootServer(agentDef, html, env, port, cwd) {
|
|
2889
2889
|
step("Start", `http://localhost:${port}`);
|
|
2890
|
+
const createWebSocket = await loadWsFromProject(cwd);
|
|
2890
2891
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2891
2892
|
const server = createServer2({
|
|
2892
2893
|
agent: agentDef,
|
|
2893
2894
|
clientHtml: html,
|
|
2894
|
-
env
|
|
2895
|
+
env,
|
|
2896
|
+
createWebSocket
|
|
2895
2897
|
});
|
|
2896
2898
|
await server.listen(port);
|
|
2897
2899
|
step("Ready", `http://localhost:${port}`);
|
|
@@ -2901,7 +2903,7 @@ async function bootServer(agentDef, html, env, port) {
|
|
|
2901
2903
|
async function _startDevServer(cwd, port) {
|
|
2902
2904
|
const agent = await loadAgent(cwd);
|
|
2903
2905
|
if (!agent) {
|
|
2904
|
-
throw new Error("No agent found \u2014 run `aai
|
|
2906
|
+
throw new Error("No agent found \u2014 run `aai init` first");
|
|
2905
2907
|
}
|
|
2906
2908
|
step("Bundle", agent.slug);
|
|
2907
2909
|
let html;
|
|
@@ -2918,7 +2920,7 @@ async function _startDevServer(cwd, port) {
|
|
|
2918
2920
|
step("Load", "agent.ts");
|
|
2919
2921
|
const agentDef = await loadAgentDef(cwd);
|
|
2920
2922
|
const env = await resolveServerEnv();
|
|
2921
|
-
await bootServer(agentDef, html, env, port);
|
|
2923
|
+
await bootServer(agentDef, html, env, port, cwd);
|
|
2922
2924
|
}
|
|
2923
2925
|
|
|
2924
2926
|
// cli/dev.tsx
|
|
@@ -3332,7 +3334,7 @@ async function _startProductionServer(cwd, port) {
|
|
|
3332
3334
|
step("Load", "agent");
|
|
3333
3335
|
const agentDef = await loadAgentDef(cwd);
|
|
3334
3336
|
const env = await resolveServerEnv();
|
|
3335
|
-
await bootServer(agentDef, html, env, port);
|
|
3337
|
+
await bootServer(agentDef, html, env, port, cwd);
|
|
3336
3338
|
}
|
|
3337
3339
|
|
|
3338
3340
|
// cli/start.tsx
|
|
@@ -3422,14 +3424,11 @@ async function main(args) {
|
|
|
3422
3424
|
process.exit(1);
|
|
3423
3425
|
}
|
|
3424
3426
|
}
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
error2(err instanceof Error ? err.message : String(err));
|
|
3431
|
-
process.exit(1);
|
|
3432
|
-
}
|
|
3427
|
+
try {
|
|
3428
|
+
await main(process.argv.slice(2));
|
|
3429
|
+
} catch (err) {
|
|
3430
|
+
error2(err instanceof Error ? err.message : String(err));
|
|
3431
|
+
process.exit(1);
|
|
3433
3432
|
}
|
|
3434
3433
|
export {
|
|
3435
3434
|
main
|