@alexkroman1/aai 0.8.8 → 0.9.1
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/{sdk/_internal_types.d.ts → _internal-types.d.ts} +0 -3
- package/dist/_internal-types.js +19 -0
- package/dist/{sdk/_mock_ws.d.ts → _mock-ws.d.ts} +16 -5
- package/dist/_mock-ws.js +158 -0
- package/dist/{sdk/_utils.d.ts → _utils.d.ts} +1 -2
- package/dist/_utils.js +8 -0
- package/dist/{sdk/builtin_tools.d.ts → builtin-tools.d.ts} +5 -8
- package/dist/builtin-tools.js +270 -0
- package/dist/{sdk/direct_executor.d.ts → direct-executor.d.ts} +3 -7
- package/dist/direct-executor.js +125 -0
- package/dist/{sdk/mod.d.ts → index.d.ts} +0 -4
- package/dist/index.js +2 -0
- package/dist/{sdk/kv.d.ts → kv.d.ts} +23 -20
- package/dist/kv.js +99 -0
- package/dist/{sdk/protocol.d.ts → protocol.d.ts} +65 -29
- package/dist/protocol.js +142 -0
- package/dist/runtime.d.ts +18 -0
- package/dist/runtime.js +16 -0
- package/dist/s2s.d.ts +110 -0
- package/dist/s2s.js +242 -0
- package/dist/{sdk/server.d.ts → server.d.ts} +3 -23
- package/dist/server.js +105 -0
- package/dist/{sdk/session.d.ts → session.d.ts} +4 -11
- package/dist/session.js +312 -0
- package/dist/tsdown.config.d.ts +2 -0
- package/dist/{sdk/types.d.ts → types.d.ts} +41 -25
- package/dist/types.js +139 -0
- package/dist/{sdk/vector.d.ts → vector.d.ts} +14 -15
- package/dist/vector.js +56 -0
- package/dist/{sdk/worker_entry.d.ts → worker-entry.d.ts} +2 -5
- package/dist/worker-entry.js +59 -0
- package/dist/{sdk/ws_handler.d.ts → ws-handler.d.ts} +10 -8
- package/dist/ws-handler.js +155 -0
- package/package.json +66 -149
- package/README.md +0 -34
- package/dist/aai.js +0 -3
- package/dist/cli/tsconfig.tsbuildinfo +0 -1
- package/dist/cli.js +0 -2811
- package/dist/sdk/_internal_types.d.ts.map +0 -1
- package/dist/sdk/_internal_types.js +0 -25
- package/dist/sdk/_internal_types.js.map +0 -1
- package/dist/sdk/_mock_ws.d.ts.map +0 -1
- package/dist/sdk/_mock_ws.js +0 -154
- package/dist/sdk/_mock_ws.js.map +0 -1
- package/dist/sdk/_render_check.d.ts +0 -10
- package/dist/sdk/_render_check.d.ts.map +0 -1
- package/dist/sdk/_render_check.js +0 -72
- package/dist/sdk/_render_check.js.map +0 -1
- package/dist/sdk/_utils.d.ts.map +0 -1
- package/dist/sdk/_utils.js +0 -7
- package/dist/sdk/_utils.js.map +0 -1
- package/dist/sdk/builtin_tools.d.ts.map +0 -1
- package/dist/sdk/builtin_tools.js +0 -309
- package/dist/sdk/builtin_tools.js.map +0 -1
- package/dist/sdk/capnweb.d.ts +0 -102
- package/dist/sdk/capnweb.d.ts.map +0 -1
- package/dist/sdk/capnweb.js +0 -219
- package/dist/sdk/capnweb.js.map +0 -1
- package/dist/sdk/define_agent.d.ts +0 -36
- package/dist/sdk/define_agent.d.ts.map +0 -1
- package/dist/sdk/define_agent.js +0 -71
- package/dist/sdk/define_agent.js.map +0 -1
- package/dist/sdk/direct_executor.d.ts.map +0 -1
- package/dist/sdk/direct_executor.js +0 -145
- package/dist/sdk/direct_executor.js.map +0 -1
- package/dist/sdk/host.d.ts +0 -59
- package/dist/sdk/host.d.ts.map +0 -1
- package/dist/sdk/host.js +0 -131
- package/dist/sdk/host.js.map +0 -1
- package/dist/sdk/kv.d.ts.map +0 -1
- package/dist/sdk/kv.js +0 -94
- package/dist/sdk/kv.js.map +0 -1
- package/dist/sdk/memory_tools.d.ts +0 -38
- package/dist/sdk/memory_tools.d.ts.map +0 -1
- package/dist/sdk/memory_tools.js +0 -77
- package/dist/sdk/memory_tools.js.map +0 -1
- package/dist/sdk/mod.d.ts.map +0 -1
- package/dist/sdk/mod.js +0 -27
- package/dist/sdk/mod.js.map +0 -1
- package/dist/sdk/protocol.d.ts.map +0 -1
- package/dist/sdk/protocol.js +0 -133
- package/dist/sdk/protocol.js.map +0 -1
- package/dist/sdk/runtime.d.ts +0 -36
- package/dist/sdk/runtime.d.ts.map +0 -1
- package/dist/sdk/runtime.js +0 -27
- package/dist/sdk/runtime.js.map +0 -1
- package/dist/sdk/s2s.d.ts +0 -74
- package/dist/sdk/s2s.d.ts.map +0 -1
- package/dist/sdk/s2s.js +0 -218
- package/dist/sdk/s2s.js.map +0 -1
- package/dist/sdk/server.d.ts.map +0 -1
- package/dist/sdk/server.js +0 -144
- package/dist/sdk/server.js.map +0 -1
- package/dist/sdk/session.d.ts.map +0 -1
- package/dist/sdk/session.js +0 -303
- package/dist/sdk/session.js.map +0 -1
- package/dist/sdk/system_prompt.d.ts +0 -6
- package/dist/sdk/system_prompt.d.ts.map +0 -1
- package/dist/sdk/system_prompt.js +0 -35
- package/dist/sdk/system_prompt.js.map +0 -1
- package/dist/sdk/tsconfig.tsbuildinfo +0 -1
- package/dist/sdk/types.d.ts.map +0 -1
- package/dist/sdk/types.js +0 -96
- package/dist/sdk/types.js.map +0 -1
- package/dist/sdk/vector.d.ts.map +0 -1
- package/dist/sdk/vector.js +0 -63
- package/dist/sdk/vector.js.map +0 -1
- package/dist/sdk/winterc_server.d.ts +0 -56
- package/dist/sdk/winterc_server.d.ts.map +0 -1
- package/dist/sdk/winterc_server.js +0 -77
- package/dist/sdk/winterc_server.js.map +0 -1
- package/dist/sdk/worker_entry.d.ts.map +0 -1
- package/dist/sdk/worker_entry.js +0 -68
- package/dist/sdk/worker_entry.js.map +0 -1
- package/dist/sdk/worker_shim.d.ts +0 -19
- package/dist/sdk/worker_shim.d.ts.map +0 -1
- package/dist/sdk/worker_shim.js +0 -141
- package/dist/sdk/worker_shim.js.map +0 -1
- package/dist/sdk/ws_handler.d.ts.map +0 -1
- package/dist/sdk/ws_handler.js +0 -158
- package/dist/sdk/ws_handler.js.map +0 -1
- package/dist/ui/_cn.d.ts +0 -5
- package/dist/ui/_cn.d.ts.map +0 -1
- package/dist/ui/_cn.js +0 -22
- package/dist/ui/_cn.js.map +0 -1
- package/dist/ui/_components/app.d.ts +0 -5
- package/dist/ui/_components/app.d.ts.map +0 -1
- package/dist/ui/_components/app.js +0 -12
- package/dist/ui/_components/app.js.map +0 -1
- package/dist/ui/_components/button.d.ts +0 -11
- package/dist/ui/_components/button.d.ts.map +0 -1
- package/dist/ui/_components/button.js +0 -17
- package/dist/ui/_components/button.js.map +0 -1
- package/dist/ui/_components/chat_view.d.ts +0 -5
- package/dist/ui/_components/chat_view.d.ts.map +0 -1
- package/dist/ui/_components/chat_view.js +0 -15
- package/dist/ui/_components/chat_view.js.map +0 -1
- package/dist/ui/_components/controls.d.ts +0 -4
- package/dist/ui/_components/controls.d.ts.map +0 -1
- package/dist/ui/_components/controls.js +0 -10
- package/dist/ui/_components/controls.js.map +0 -1
- package/dist/ui/_components/error_banner.d.ts +0 -8
- package/dist/ui/_components/error_banner.d.ts.map +0 -1
- package/dist/ui/_components/error_banner.js +0 -8
- package/dist/ui/_components/error_banner.js.map +0 -1
- package/dist/ui/_components/message_bubble.d.ts +0 -7
- package/dist/ui/_components/message_bubble.d.ts.map +0 -1
- package/dist/ui/_components/message_bubble.js +0 -11
- package/dist/ui/_components/message_bubble.js.map +0 -1
- package/dist/ui/_components/message_list.d.ts +0 -4
- package/dist/ui/_components/message_list.d.ts.map +0 -1
- package/dist/ui/_components/message_list.js +0 -45
- package/dist/ui/_components/message_list.js.map +0 -1
- package/dist/ui/_components/sidebar_layout.d.ts +0 -20
- package/dist/ui/_components/sidebar_layout.d.ts.map +0 -1
- package/dist/ui/_components/sidebar_layout.js +0 -19
- package/dist/ui/_components/sidebar_layout.js.map +0 -1
- package/dist/ui/_components/start_screen.d.ts +0 -25
- package/dist/ui/_components/start_screen.d.ts.map +0 -1
- package/dist/ui/_components/start_screen.js +0 -28
- package/dist/ui/_components/start_screen.js.map +0 -1
- package/dist/ui/_components/state_indicator.d.ts +0 -8
- package/dist/ui/_components/state_indicator.d.ts.map +0 -1
- package/dist/ui/_components/state_indicator.js +0 -6
- package/dist/ui/_components/state_indicator.js.map +0 -1
- package/dist/ui/_components/thinking_indicator.d.ts +0 -5
- package/dist/ui/_components/thinking_indicator.d.ts.map +0 -1
- package/dist/ui/_components/thinking_indicator.js +0 -10
- package/dist/ui/_components/thinking_indicator.js.map +0 -1
- package/dist/ui/_components/tool_call_block.d.ts +0 -7
- package/dist/ui/_components/tool_call_block.d.ts.map +0 -1
- package/dist/ui/_components/tool_call_block.js +0 -46
- package/dist/ui/_components/tool_call_block.js.map +0 -1
- package/dist/ui/_components/tool_icons.d.ts +0 -18
- package/dist/ui/_components/tool_icons.d.ts.map +0 -1
- package/dist/ui/_components/tool_icons.js +0 -26
- package/dist/ui/_components/tool_icons.js.map +0 -1
- package/dist/ui/_components/transcript.d.ts +0 -7
- package/dist/ui/_components/transcript.d.ts.map +0 -1
- package/dist/ui/_components/transcript.js +0 -9
- package/dist/ui/_components/transcript.js.map +0 -1
- package/dist/ui/_dom_shim.d.ts +0 -7
- package/dist/ui/_dom_shim.d.ts.map +0 -1
- package/dist/ui/_dom_shim.js +0 -21
- package/dist/ui/_dom_shim.js.map +0 -1
- package/dist/ui/_hooks.d.ts +0 -21
- package/dist/ui/_hooks.d.ts.map +0 -1
- package/dist/ui/_hooks.js +0 -35
- package/dist/ui/_hooks.js.map +0 -1
- package/dist/ui/_jsdom_setup.d.ts +0 -1
- package/dist/ui/_jsdom_setup.d.ts.map +0 -1
- package/dist/ui/_jsdom_setup.js +0 -6
- package/dist/ui/_jsdom_setup.js.map +0 -1
- package/dist/ui/_render_check.d.ts +0 -10
- package/dist/ui/_render_check.d.ts.map +0 -1
- package/dist/ui/_render_check.js +0 -72
- package/dist/ui/_render_check.js.map +0 -1
- package/dist/ui/_test_utils.js +0 -272
- package/dist/ui/_test_utils.js.map +0 -1
- package/dist/ui/audio.d.ts +0 -46
- package/dist/ui/audio.d.ts.map +0 -1
- package/dist/ui/audio.js +0 -130
- package/dist/ui/audio.js.map +0 -1
- package/dist/ui/components.d.ts +0 -14
- package/dist/ui/components.d.ts.map +0 -1
- package/dist/ui/components.js +0 -15
- package/dist/ui/components.js.map +0 -1
- package/dist/ui/components_mod.d.ts +0 -34
- package/dist/ui/components_mod.d.ts.map +0 -1
- package/dist/ui/components_mod.js +0 -32
- package/dist/ui/components_mod.js.map +0 -1
- package/dist/ui/mod.d.ts +0 -23
- package/dist/ui/mod.d.ts.map +0 -1
- package/dist/ui/mod.js +0 -22
- package/dist/ui/mod.js.map +0 -1
- package/dist/ui/mount.d.ts +0 -44
- package/dist/ui/mount.d.ts.map +0 -1
- package/dist/ui/mount.js +0 -61
- package/dist/ui/mount.js.map +0 -1
- package/dist/ui/mount_context.d.ts +0 -22
- package/dist/ui/mount_context.d.ts.map +0 -1
- package/dist/ui/mount_context.js +0 -10
- package/dist/ui/mount_context.js.map +0 -1
- package/dist/ui/session.d.ts +0 -96
- package/dist/ui/session.d.ts.map +0 -1
- package/dist/ui/session.js +0 -379
- package/dist/ui/session.js.map +0 -1
- package/dist/ui/session_mod.d.ts +0 -19
- package/dist/ui/session_mod.d.ts.map +0 -1
- package/dist/ui/session_mod.js +0 -18
- package/dist/ui/session_mod.js.map +0 -1
- package/dist/ui/signals.d.ts +0 -80
- package/dist/ui/signals.d.ts.map +0 -1
- package/dist/ui/signals.js +0 -137
- package/dist/ui/signals.js.map +0 -1
- package/dist/ui/tsconfig.tsbuildinfo +0 -1
- package/dist/ui/types.d.ts +0 -36
- package/dist/ui/types.d.ts.map +0 -1
- package/dist/ui/types.js +0 -4
- package/dist/ui/types.js.map +0 -1
- package/dist/ui/worklets/capture-processor.d.ts +0 -3
- package/dist/ui/worklets/capture-processor.d.ts.map +0 -1
- package/dist/ui/worklets/capture-processor.js +0 -61
- package/dist/ui/worklets/capture-processor.js.map +0 -1
- package/dist/ui/worklets/playback-processor.d.ts +0 -3
- package/dist/ui/worklets/playback-processor.d.ts.map +0 -1
- package/dist/ui/worklets/playback-processor.js +0 -109
- package/dist/ui/worklets/playback-processor.js.map +0 -1
- package/templates/.env +0 -1
- package/templates/_shared/.env.example +0 -5
- package/templates/_shared/CLAUDE.md +0 -1073
- package/templates/_shared/biome.json +0 -32
- package/templates/_shared/global.d.ts +0 -1
- package/templates/_shared/index.html +0 -16
- package/templates/_shared/package.json +0 -22
- package/templates/_shared/tsconfig.json +0 -16
- package/templates/code-interpreter/agent.ts +0 -27
- package/templates/code-interpreter/client.tsx +0 -3
- package/templates/dispatch-center/agent.ts +0 -1223
- package/templates/dispatch-center/client.tsx +0 -505
- package/templates/embedded-assets/agent.ts +0 -48
- package/templates/embedded-assets/client.tsx +0 -3
- package/templates/embedded-assets/knowledge.json +0 -20
- package/templates/health-assistant/agent.ts +0 -160
- package/templates/health-assistant/client.tsx +0 -3
- package/templates/infocom-adventure/agent.ts +0 -164
- package/templates/infocom-adventure/client.tsx +0 -300
- package/templates/math-buddy/agent.ts +0 -21
- package/templates/math-buddy/client.tsx +0 -3
- package/templates/memory-agent/agent.ts +0 -20
- package/templates/memory-agent/client.tsx +0 -3
- package/templates/night-owl/agent.ts +0 -98
- package/templates/night-owl/client.tsx +0 -12
- package/templates/personal-finance/agent.ts +0 -26
- package/templates/personal-finance/client.tsx +0 -3
- package/templates/pizza-ordering/agent.ts +0 -214
- package/templates/pizza-ordering/client.tsx +0 -264
- package/templates/simple/agent.ts +0 -6
- package/templates/simple/client.tsx +0 -3
- package/templates/smart-research/agent.ts +0 -164
- package/templates/smart-research/client.tsx +0 -3
- package/templates/solo-rpg/agent.ts +0 -1240
- package/templates/solo-rpg/client.tsx +0 -698
- package/templates/support/README.md +0 -62
- package/templates/support/agent.ts +0 -19
- package/templates/support/client.tsx +0 -3
- package/templates/travel-concierge/agent.ts +0 -29
- package/templates/travel-concierge/client.tsx +0 -3
- package/templates/tsconfig.json +0 -1
- package/templates/web-researcher/agent.ts +0 -17
- package/templates/web-researcher/client.tsx +0 -3
- package/ui/styles.css +0 -74
package/dist/sdk/session.js
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
-
/**
|
|
3
|
-
* S2S session — relays audio between the client and AssemblyAI's
|
|
4
|
-
* Speech-to-Speech API, intercepting only tool calls for local execution.
|
|
5
|
-
*
|
|
6
|
-
* Cross-runtime: accepts Logger, Metrics, and a WebSocket factory via
|
|
7
|
-
* dependency injection.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
import { errorMessage } from "./_utils.js";
|
|
12
|
-
import { HOOK_TIMEOUT_MS } from "./protocol.js";
|
|
13
|
-
import { consoleLogger, noopMetrics } from "./runtime.js";
|
|
14
|
-
import { connectS2s, } from "./s2s.js";
|
|
15
|
-
import { DEFAULT_INSTRUCTIONS } from "./types.js";
|
|
16
|
-
export const _internals = {
|
|
17
|
-
connectS2s,
|
|
18
|
-
};
|
|
19
|
-
/** Create an S2S-backed session with the same interface as the STT+LLM+TTS session. */
|
|
20
|
-
export function createS2sSession(opts) {
|
|
21
|
-
const { id, agent, client, toolSchemas, apiKey, s2sConfig, executeTool, createWebSocket, hookInvoker, logger: log = consoleLogger, metrics = noopMetrics, } = opts;
|
|
22
|
-
const agentLabel = { agent };
|
|
23
|
-
const agentConfig = opts.skipGreeting ? { ...opts.agentConfig, greeting: "" } : opts.agentConfig;
|
|
24
|
-
// Build system prompt
|
|
25
|
-
const hasTools = toolSchemas.length > 0 || (agentConfig.builtinTools?.length ?? 0) > 0;
|
|
26
|
-
const systemPrompt = buildSystemPrompt(agentConfig, {
|
|
27
|
-
hasTools,
|
|
28
|
-
voice: true,
|
|
29
|
-
});
|
|
30
|
-
// toolSchemas already includes both agent-defined and builtin tools
|
|
31
|
-
const s2sTools = toolSchemas.map((ts) => ({
|
|
32
|
-
type: "function",
|
|
33
|
-
name: ts.name,
|
|
34
|
-
description: ts.description,
|
|
35
|
-
parameters: ts.parameters,
|
|
36
|
-
}));
|
|
37
|
-
let s2s = null;
|
|
38
|
-
const sessionAbort = new AbortController();
|
|
39
|
-
let toolCallCount = 0;
|
|
40
|
-
let turnPromise = null;
|
|
41
|
-
let conversationMessages = [];
|
|
42
|
-
let pendingTools = [];
|
|
43
|
-
async function resolveTurnConfig() {
|
|
44
|
-
if (!hookInvoker)
|
|
45
|
-
return null;
|
|
46
|
-
try {
|
|
47
|
-
return await hookInvoker.resolveTurnConfig(id, HOOK_TIMEOUT_MS);
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
log.warn("resolveTurnConfig hook failed", { err: errorMessage(err) });
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function invokeHook(hook, arg) {
|
|
55
|
-
if (!hookInvoker)
|
|
56
|
-
return;
|
|
57
|
-
try {
|
|
58
|
-
// biome-ignore lint/complexity/noBannedTypes: dynamic hook dispatch
|
|
59
|
-
const h = hookInvoker[hook];
|
|
60
|
-
Promise.resolve(h.call(hookInvoker, id, arg, HOOK_TIMEOUT_MS)).catch((err) => {
|
|
61
|
-
log.warn(`${hook} hook failed`, { err: errorMessage(err) });
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
log.warn(`${hook} hook failed`, { err: errorMessage(err) });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/** Check if a tool call should be refused due to turn config limits. Returns a result string to short-circuit, or null. */
|
|
69
|
-
function checkTurnLimits(turnConfig, name) {
|
|
70
|
-
const maxSteps = turnConfig?.maxSteps ?? agentConfig.maxSteps;
|
|
71
|
-
toolCallCount++;
|
|
72
|
-
if (maxSteps !== undefined && toolCallCount > maxSteps) {
|
|
73
|
-
log.info("maxSteps exceeded, refusing tool call", { toolCallCount, maxSteps });
|
|
74
|
-
return "Maximum tool steps reached. Please respond to the user now.";
|
|
75
|
-
}
|
|
76
|
-
if (turnConfig?.activeTools && !turnConfig.activeTools.includes(name)) {
|
|
77
|
-
log.info("Tool filtered by activeTools", { name });
|
|
78
|
-
return JSON.stringify({ error: `Tool "${name}" is not available at this step.` });
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
async function handleToolCall(detail) {
|
|
83
|
-
const { call_id, name, args: parsedArgs } = detail;
|
|
84
|
-
// Emit tool_call_start to client
|
|
85
|
-
client.event({
|
|
86
|
-
type: "tool_call_start",
|
|
87
|
-
toolCallId: call_id,
|
|
88
|
-
toolName: name,
|
|
89
|
-
args: parsedArgs,
|
|
90
|
-
});
|
|
91
|
-
// Resolve turn config for maxSteps / activeTools
|
|
92
|
-
const turnConfig = await resolveTurnConfig();
|
|
93
|
-
const refused = checkTurnLimits(turnConfig, name);
|
|
94
|
-
if (refused !== null) {
|
|
95
|
-
pendingTools.push({ call_id, result: refused });
|
|
96
|
-
client.event({ type: "tool_call_done", toolCallId: call_id, result: refused });
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
// Fire onStep hook
|
|
100
|
-
invokeHook("onStep", {
|
|
101
|
-
stepNumber: toolCallCount - 1,
|
|
102
|
-
toolCalls: [{ toolName: name, args: parsedArgs }],
|
|
103
|
-
text: "",
|
|
104
|
-
});
|
|
105
|
-
log.info("S2S tool call", { tool: name, call_id, args: parsedArgs, agent });
|
|
106
|
-
// Execute — all tools (custom + builtin) run via the executor
|
|
107
|
-
let result;
|
|
108
|
-
try {
|
|
109
|
-
result = await executeTool(name, parsedArgs, id, conversationMessages);
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
const msg = errorMessage(err);
|
|
113
|
-
log.error("Tool execution failed", { tool: name, error: msg });
|
|
114
|
-
result = JSON.stringify({ error: msg });
|
|
115
|
-
}
|
|
116
|
-
log.info("S2S tool result", {
|
|
117
|
-
tool: name,
|
|
118
|
-
call_id,
|
|
119
|
-
resultLength: result.length,
|
|
120
|
-
});
|
|
121
|
-
// Accumulate — don't send yet. Results are sent after reply.done.
|
|
122
|
-
pendingTools.push({ call_id, result });
|
|
123
|
-
client.event({ type: "tool_call_done", toolCallId: call_id, result });
|
|
124
|
-
}
|
|
125
|
-
/** Register a typed CustomEvent listener, consolidating the EventListener cast. */
|
|
126
|
-
function on(target, event, handler) {
|
|
127
|
-
target.addEventListener(event, handler);
|
|
128
|
-
}
|
|
129
|
-
/** Wire all S2S events to the client sink, hooks, and session state. */
|
|
130
|
-
function setupListeners(handle) {
|
|
131
|
-
on(handle, "ready", (e) => {
|
|
132
|
-
log.info("S2S session ready", { session_id: e.detail.session_id });
|
|
133
|
-
});
|
|
134
|
-
on(handle, "session_expired", () => {
|
|
135
|
-
log.info("S2S session expired");
|
|
136
|
-
handle.close();
|
|
137
|
-
});
|
|
138
|
-
// Simple event forwarding
|
|
139
|
-
for (const type of ["speech_started", "speech_stopped"]) {
|
|
140
|
-
handle.addEventListener(type, () => client.event({ type }));
|
|
141
|
-
}
|
|
142
|
-
on(handle, "user_transcript_delta", (e) => {
|
|
143
|
-
client.event({ type: "transcript", text: e.detail.text, isFinal: false });
|
|
144
|
-
});
|
|
145
|
-
on(handle, "user_transcript", (e) => {
|
|
146
|
-
const { text } = e.detail;
|
|
147
|
-
log.info("S2S user transcript", { text });
|
|
148
|
-
client.event({ type: "transcript", text, isFinal: true });
|
|
149
|
-
client.event({ type: "turn", text });
|
|
150
|
-
conversationMessages.push({ role: "user", content: text });
|
|
151
|
-
invokeHook("onTurn", text);
|
|
152
|
-
});
|
|
153
|
-
handle.addEventListener("reply_started", () => {
|
|
154
|
-
toolCallCount = 0;
|
|
155
|
-
});
|
|
156
|
-
on(handle, "audio", (e) => {
|
|
157
|
-
client.playAudioChunk(e.detail.audio);
|
|
158
|
-
});
|
|
159
|
-
on(handle, "agent_transcript_delta", (e) => {
|
|
160
|
-
client.event({ type: "chat_delta", text: e.detail.text });
|
|
161
|
-
});
|
|
162
|
-
on(handle, "agent_transcript", (e) => {
|
|
163
|
-
const { text } = e.detail;
|
|
164
|
-
client.event({ type: "chat", text });
|
|
165
|
-
conversationMessages.push({ role: "assistant", content: text });
|
|
166
|
-
});
|
|
167
|
-
on(handle, "tool_call", (e) => {
|
|
168
|
-
const p = handleToolCall(e.detail).catch((err) => {
|
|
169
|
-
log.error("Tool call handler failed", { err: errorMessage(err) });
|
|
170
|
-
});
|
|
171
|
-
turnPromise = (turnPromise ?? Promise.resolve()).then(() => p);
|
|
172
|
-
});
|
|
173
|
-
on(handle, "reply_done", (e) => {
|
|
174
|
-
if (e.detail.status === "interrupted") {
|
|
175
|
-
log.info("S2S reply interrupted (barge-in)");
|
|
176
|
-
pendingTools = [];
|
|
177
|
-
client.event({ type: "cancelled" });
|
|
178
|
-
}
|
|
179
|
-
else if (pendingTools.length > 0) {
|
|
180
|
-
for (const tool of pendingTools)
|
|
181
|
-
s2s?.sendToolResult(tool.call_id, tool.result);
|
|
182
|
-
pendingTools = [];
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
client.playAudioDone();
|
|
186
|
-
client.event({ type: "tts_done" });
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
on(handle, "error", (e) => {
|
|
190
|
-
log.error("S2S error", { code: e.detail.code, message: e.detail.message });
|
|
191
|
-
client.event({ type: "error", code: "internal", message: e.detail.message });
|
|
192
|
-
handle.close();
|
|
193
|
-
});
|
|
194
|
-
handle.addEventListener("close", () => {
|
|
195
|
-
log.info("S2S closed");
|
|
196
|
-
s2s = null;
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async function connectAndSetup() {
|
|
200
|
-
try {
|
|
201
|
-
const handle = await _internals.connectS2s({
|
|
202
|
-
apiKey,
|
|
203
|
-
config: s2sConfig,
|
|
204
|
-
createWebSocket,
|
|
205
|
-
logger: log,
|
|
206
|
-
});
|
|
207
|
-
// Register all listeners BEFORE sending messages to avoid races.
|
|
208
|
-
setupListeners(handle);
|
|
209
|
-
handle.updateSession({
|
|
210
|
-
system_prompt: systemPrompt,
|
|
211
|
-
tools: s2sTools,
|
|
212
|
-
...(agentConfig.greeting ? { greeting: agentConfig.greeting } : {}),
|
|
213
|
-
});
|
|
214
|
-
s2s = handle;
|
|
215
|
-
}
|
|
216
|
-
catch (err) {
|
|
217
|
-
const msg = errorMessage(err);
|
|
218
|
-
log.error("S2S connect failed", { error: msg });
|
|
219
|
-
client.event({ type: "error", code: "internal", message: msg });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return {
|
|
223
|
-
async start() {
|
|
224
|
-
metrics.sessionsTotal.inc(agentLabel);
|
|
225
|
-
metrics.sessionsActive.inc(agentLabel);
|
|
226
|
-
invokeHook("onConnect");
|
|
227
|
-
await connectAndSetup();
|
|
228
|
-
},
|
|
229
|
-
async stop() {
|
|
230
|
-
if (sessionAbort.signal.aborted)
|
|
231
|
-
return;
|
|
232
|
-
sessionAbort.abort();
|
|
233
|
-
metrics.sessionsActive.dec(agentLabel);
|
|
234
|
-
if (turnPromise)
|
|
235
|
-
await turnPromise;
|
|
236
|
-
s2s?.close();
|
|
237
|
-
invokeHook("onDisconnect");
|
|
238
|
-
},
|
|
239
|
-
onAudio(data) {
|
|
240
|
-
s2s?.sendAudio(data);
|
|
241
|
-
},
|
|
242
|
-
onAudioReady() {
|
|
243
|
-
// S2S mode: greeting audio comes from S2S automatically. No-op.
|
|
244
|
-
},
|
|
245
|
-
onCancel() {
|
|
246
|
-
// S2S handles barge-in natively.
|
|
247
|
-
client.event({ type: "cancelled" });
|
|
248
|
-
},
|
|
249
|
-
onReset() {
|
|
250
|
-
conversationMessages = [];
|
|
251
|
-
toolCallCount = 0;
|
|
252
|
-
turnPromise = null;
|
|
253
|
-
pendingTools = [];
|
|
254
|
-
s2s?.close();
|
|
255
|
-
client.event({ type: "reset" });
|
|
256
|
-
connectAndSetup().catch((err) => {
|
|
257
|
-
log.error("S2S reset reconnect failed", { error: errorMessage(err) });
|
|
258
|
-
});
|
|
259
|
-
},
|
|
260
|
-
onHistory(incoming) {
|
|
261
|
-
for (const msg of incoming) {
|
|
262
|
-
conversationMessages.push({ role: msg.role, content: msg.text });
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
waitForTurn() {
|
|
266
|
-
return turnPromise ?? Promise.resolve();
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
// ─── System prompt builder ──────────────────────────────────────────────────
|
|
271
|
-
const VOICE_RULES = "\n\nCRITICAL OUTPUT RULES — you MUST follow these for EVERY response:\n" +
|
|
272
|
-
"Your response will be spoken aloud by a TTS system and displayed as plain text.\n" +
|
|
273
|
-
"- NEVER use markdown: no **, no *, no _, no #, no `, no [](), no ---\n" +
|
|
274
|
-
"- NEVER use bullet points (-, *, •) or numbered lists (1., 2.)\n" +
|
|
275
|
-
"- NEVER use code blocks or inline code\n" +
|
|
276
|
-
"- NEVER mention tools, search, APIs, or technical failures to the user. " +
|
|
277
|
-
"If a tool returns no results, just answer naturally without explaining why.\n" +
|
|
278
|
-
"- Write exactly as you would say it out loud to a friend\n" +
|
|
279
|
-
'- Use short conversational sentences. To list things, say "First," "Next," "Finally,"\n' +
|
|
280
|
-
"- Keep responses concise — 1 to 3 sentences max";
|
|
281
|
-
export function buildSystemPrompt(config, opts) {
|
|
282
|
-
const { hasTools } = opts;
|
|
283
|
-
const agentInstructions = config.instructions && config.instructions !== DEFAULT_INSTRUCTIONS
|
|
284
|
-
? `\n\nAgent-Specific Instructions:\n${config.instructions}`
|
|
285
|
-
: "";
|
|
286
|
-
const toolPreamble = hasTools
|
|
287
|
-
? "\n\nWhen you decide to use a tool, ALWAYS say a brief natural phrase BEFORE the tool call " +
|
|
288
|
-
'(e.g. "Let me look that up" or "One moment while I check"). ' +
|
|
289
|
-
"This fills silence while the tool executes. Keep preambles to one short sentence."
|
|
290
|
-
: "";
|
|
291
|
-
const today = new Date().toLocaleDateString("en-US", {
|
|
292
|
-
weekday: "long",
|
|
293
|
-
year: "numeric",
|
|
294
|
-
month: "long",
|
|
295
|
-
day: "numeric",
|
|
296
|
-
});
|
|
297
|
-
return (DEFAULT_INSTRUCTIONS +
|
|
298
|
-
`\n\nToday's date is ${today}.` +
|
|
299
|
-
agentInstructions +
|
|
300
|
-
toolPreamble +
|
|
301
|
-
(opts.voice ? VOICE_RULES : ""));
|
|
302
|
-
}
|
|
303
|
-
//# sourceMappingURL=session.js.map
|
package/dist/sdk/session.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../sdk/session.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;;;;;;;;GAQG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAEL,UAAU,GAIX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAA+B,MAAM,YAAY,CAAC;AA8C/E,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,UAAU;CACX,CAAC;AAEF,uFAAuF;AACvF,MAAM,UAAU,gBAAgB,CAAC,IAAoB;IACnD,MAAM,EACJ,EAAE,EACF,KAAK,EACL,MAAM,EACN,WAAW,EACX,MAAM,EACN,SAAS,EACT,WAAW,EACX,eAAe,EACf,WAAW,EACX,MAAM,EAAE,GAAG,GAAG,aAAa,EAC3B,OAAO,GAAG,WAAW,GACtB,GAAG,IAAI,CAAC;IAET,MAAM,UAAU,GAAG,EAAE,KAAK,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;IAEjG,sBAAsB;IACtB,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CA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AM,YAAY,GAAG,QAAQ;QAC3B,CAAC,CAAC,4FAA4F;YAC5F,8DAA8D;YAC9D,mFAAmF;QACrF,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE;QACnD,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,MAAM;QACb,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IAEH,OAAO,CACL,oBAAoB;QACpB,uBAAuB,KAAK,GAAG;QAC/B,iBAAiB;QACjB,YAAY;QACZ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAChC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"system_prompt.d.ts","sourceRoot":"","sources":["../../sdk/system_prompt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAexD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3C,MAAM,CA2BR"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
-
import { DEFAULT_INSTRUCTIONS } from "./types.js";
|
|
3
|
-
const VOICE_RULES = "\n\nCRITICAL OUTPUT RULES — you MUST follow these for EVERY response:\n" +
|
|
4
|
-
"Your response will be spoken aloud by a TTS system and displayed as plain text.\n" +
|
|
5
|
-
"- NEVER use markdown: no **, no *, no _, no #, no `, no [](), no ---\n" +
|
|
6
|
-
"- NEVER use bullet points (-, *, •) or numbered lists (1., 2.)\n" +
|
|
7
|
-
"- NEVER use code blocks or inline code\n" +
|
|
8
|
-
"- NEVER mention tools, search, APIs, or technical failures to the user. " +
|
|
9
|
-
"If a tool returns no results, just answer naturally without explaining why.\n" +
|
|
10
|
-
"- Write exactly as you would say it out loud to a friend\n" +
|
|
11
|
-
'- Use short conversational sentences. To list things, say "First," "Next," "Finally,"\n' +
|
|
12
|
-
"- Keep responses concise — 1 to 3 sentences max";
|
|
13
|
-
export function buildSystemPrompt(config, opts) {
|
|
14
|
-
const { hasTools } = opts;
|
|
15
|
-
const agentInstructions = config.instructions && config.instructions !== DEFAULT_INSTRUCTIONS
|
|
16
|
-
? `\n\nAgent-Specific Instructions:\n${config.instructions}`
|
|
17
|
-
: "";
|
|
18
|
-
const toolPreamble = hasTools
|
|
19
|
-
? "\n\nWhen you decide to use a tool, ALWAYS say a brief natural phrase BEFORE the tool call " +
|
|
20
|
-
'(e.g. "Let me look that up" or "One moment while I check"). ' +
|
|
21
|
-
"This fills silence while the tool executes. Keep preambles to one short sentence."
|
|
22
|
-
: "";
|
|
23
|
-
const today = new Date().toLocaleDateString("en-US", {
|
|
24
|
-
weekday: "long",
|
|
25
|
-
year: "numeric",
|
|
26
|
-
month: "long",
|
|
27
|
-
day: "numeric",
|
|
28
|
-
});
|
|
29
|
-
return (DEFAULT_INSTRUCTIONS +
|
|
30
|
-
`\n\nToday's date is ${today}.` +
|
|
31
|
-
agentInstructions +
|
|
32
|
-
toolPreamble +
|
|
33
|
-
(opts?.voice ? VOICE_RULES : ""));
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=system_prompt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"system_prompt.js","sourceRoot":"","sources":["../../sdk/system_prompt.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAG/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,GACf,yEAAyE;IACzE,mFAAmF;IACnF,wEAAwE;IACxE,kEAAkE;IAClE,0CAA0C;IAC1C,0EAA0E;IAC1E,+EAA+E;IAC/E,4DAA4D;IAC5D,yFAAyF;IACzF,iDAAiD,CAAC;AAEpD,MAAM,UAAU,iBAAiB,CAC/B,MAAmB,EACnB,IAA4C;IAE5C,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC1B,MAAM,iBAAiB,GACrB,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,KAAK,oBAAoB;QACjE,CAAC,CAAC,qCAAqC,MAAM,CAAC,YAAY,EAAE;QAC5D,CAAC,CAAC,EAAE,CAAC;IAET,MAAM,YAAY,GAAG,QAAQ;QAC3B,CAAC,CAAC,4FAA4F;YAC5F,8DAA8D;YAC9D,mFAAmF;QACrF,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE;QACnD,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,MAAM;QACb,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IAEH,OAAO,CACL,oBAAoB;QACpB,uBAAuB,KAAK,GAAG;QAC/B,iBAAiB;QACjB,YAAY;QACZ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CACjC,CAAC;AACJ,CAAC"}
|