@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
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket wire-format types shared by server and client.
|
|
3
|
+
*
|
|
4
|
+
* Note: this module is for internal use only and should not be used directly.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import type { WorkerConfig } from "./_internal_types.ts";
|
|
10
|
+
import type { Message, StepInfo } from "./types.ts";
|
|
11
|
+
/**
|
|
12
|
+
* Current protocol version for client-server compatibility checks.
|
|
13
|
+
*
|
|
14
|
+
* Increment this when making breaking changes to the wire protocol.
|
|
15
|
+
*/
|
|
16
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Default sample rate for speech-to-text audio in Hz.
|
|
19
|
+
*
|
|
20
|
+
* This is the sample rate expected by the STT provider (AssemblyAI).
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEFAULT_STT_SAMPLE_RATE = 16000;
|
|
23
|
+
/**
|
|
24
|
+
* Default sample rate for text-to-speech audio in Hz.
|
|
25
|
+
*
|
|
26
|
+
* This is the sample rate produced by the TTS provider (Rime).
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_TTS_SAMPLE_RATE = 24000;
|
|
29
|
+
/**
|
|
30
|
+
* Audio codec identifier used in the wire protocol.
|
|
31
|
+
*
|
|
32
|
+
* All audio frames are 16-bit signed PCM, little-endian, mono.
|
|
33
|
+
*/
|
|
34
|
+
export declare const AUDIO_FORMAT: "pcm16";
|
|
35
|
+
/** Specification for binary audio frames exchanged over WebSocket. */
|
|
36
|
+
export declare const AudioFrameSpec: {
|
|
37
|
+
/** Audio codec identifier sent in the `ready` message. */
|
|
38
|
+
readonly format: "pcm16";
|
|
39
|
+
/** Signed 16-bit integer samples. */
|
|
40
|
+
readonly bitsPerSample: 16;
|
|
41
|
+
/** Little-endian byte order. */
|
|
42
|
+
readonly endianness: "little";
|
|
43
|
+
/** Mono audio. */
|
|
44
|
+
readonly channels: 1;
|
|
45
|
+
/** Bytes per sample — derived from bitsPerSample and channels. */
|
|
46
|
+
readonly bytesPerSample: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* KV operation request sent from the worker to the host via postMessage RPC.
|
|
50
|
+
*
|
|
51
|
+
* This is a discriminated union on the `op` field, representing the four
|
|
52
|
+
* key-value store operations available to sandboxed agent workers.
|
|
53
|
+
*/
|
|
54
|
+
export type KvRequest = {
|
|
55
|
+
op: "get";
|
|
56
|
+
key: string;
|
|
57
|
+
} | {
|
|
58
|
+
op: "set";
|
|
59
|
+
key: string;
|
|
60
|
+
value: string;
|
|
61
|
+
ttl?: number | undefined;
|
|
62
|
+
} | {
|
|
63
|
+
op: "del";
|
|
64
|
+
key: string;
|
|
65
|
+
} | {
|
|
66
|
+
op: "list";
|
|
67
|
+
prefix: string;
|
|
68
|
+
limit?: number | undefined;
|
|
69
|
+
reverse?: boolean | undefined;
|
|
70
|
+
};
|
|
71
|
+
/** Zod schema for {@linkcode KvRequest}. */
|
|
72
|
+
export declare const KvRequestBaseSchema: z.ZodType<KvRequest>;
|
|
73
|
+
/** Default timeout for agent lifecycle hooks (onConnect, onTurn, etc). */
|
|
74
|
+
export declare const HOOK_TIMEOUT_MS = 5000;
|
|
75
|
+
/** Default timeout for tool execution in the worker. */
|
|
76
|
+
export declare const TOOL_EXECUTION_TIMEOUT_MS = 30000;
|
|
77
|
+
/** Error codes for categorizing session errors on the wire. */
|
|
78
|
+
export type SessionErrorCode = "stt" | "llm" | "tts" | "tool" | "protocol" | "connection" | "audio" | "internal";
|
|
79
|
+
/** Zod schema for {@linkcode SessionErrorCode}. */
|
|
80
|
+
export declare const SessionErrorCodeSchema: z.ZodType<SessionErrorCode>;
|
|
81
|
+
/**
|
|
82
|
+
* Discriminated union of all server→client session events.
|
|
83
|
+
*
|
|
84
|
+
* Sent via a single `event()` RPC method instead of one method per type.
|
|
85
|
+
*/
|
|
86
|
+
export type ClientEvent = {
|
|
87
|
+
type: "speech_started";
|
|
88
|
+
} | {
|
|
89
|
+
type: "speech_stopped";
|
|
90
|
+
} | {
|
|
91
|
+
type: "transcript";
|
|
92
|
+
text: string;
|
|
93
|
+
isFinal: false;
|
|
94
|
+
} | {
|
|
95
|
+
type: "transcript";
|
|
96
|
+
text: string;
|
|
97
|
+
isFinal: true;
|
|
98
|
+
turnOrder?: number | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
type: "turn";
|
|
101
|
+
text: string;
|
|
102
|
+
turnOrder?: number | undefined;
|
|
103
|
+
} | {
|
|
104
|
+
type: "chat";
|
|
105
|
+
text: string;
|
|
106
|
+
} | {
|
|
107
|
+
type: "tool_call_start";
|
|
108
|
+
toolCallId: string;
|
|
109
|
+
toolName: string;
|
|
110
|
+
args: Record<string, unknown>;
|
|
111
|
+
} | {
|
|
112
|
+
type: "tool_call_done";
|
|
113
|
+
toolCallId: string;
|
|
114
|
+
result: string;
|
|
115
|
+
} | {
|
|
116
|
+
type: "tts_done";
|
|
117
|
+
} | {
|
|
118
|
+
type: "cancelled";
|
|
119
|
+
} | {
|
|
120
|
+
type: "reset";
|
|
121
|
+
} | {
|
|
122
|
+
type: "error";
|
|
123
|
+
code: SessionErrorCode;
|
|
124
|
+
message: string;
|
|
125
|
+
};
|
|
126
|
+
/** Zod schema for {@linkcode ClientEvent}. */
|
|
127
|
+
export declare const ClientEventSchema: z.ZodType<ClientEvent>;
|
|
128
|
+
/**
|
|
129
|
+
* Typed interface for pushing session events to a connected client.
|
|
130
|
+
*
|
|
131
|
+
* For WebSocket sessions this sends JSON text frames and binary audio frames.
|
|
132
|
+
*/
|
|
133
|
+
export interface ClientSink {
|
|
134
|
+
/** Whether the underlying connection is open and accepting calls. */
|
|
135
|
+
readonly open: boolean;
|
|
136
|
+
/** Push a session event to the client. */
|
|
137
|
+
event(e: ClientEvent): void;
|
|
138
|
+
/** Send a single TTS audio chunk to the client. */
|
|
139
|
+
playAudioChunk(chunk: Uint8Array): void;
|
|
140
|
+
/** Signal that TTS audio is complete. */
|
|
141
|
+
playAudioDone(): void;
|
|
142
|
+
}
|
|
143
|
+
/** Supported audio formats for the wire protocol. */
|
|
144
|
+
export type AudioFormatId = "pcm16";
|
|
145
|
+
/** Protocol-level session config returned to the client on connect. */
|
|
146
|
+
export type ReadyConfig = {
|
|
147
|
+
protocolVersion: number;
|
|
148
|
+
audioFormat: AudioFormatId;
|
|
149
|
+
sampleRate: number;
|
|
150
|
+
ttsSampleRate: number;
|
|
151
|
+
mode?: "s2s";
|
|
152
|
+
};
|
|
153
|
+
/** Client→server text messages (binary frames carry raw PCM16 audio). */
|
|
154
|
+
export type ClientMessage = {
|
|
155
|
+
type: "audio_ready";
|
|
156
|
+
} | {
|
|
157
|
+
type: "cancel";
|
|
158
|
+
} | {
|
|
159
|
+
type: "reset";
|
|
160
|
+
} | {
|
|
161
|
+
type: "history";
|
|
162
|
+
messages: readonly {
|
|
163
|
+
role: "user" | "assistant";
|
|
164
|
+
text: string;
|
|
165
|
+
}[];
|
|
166
|
+
};
|
|
167
|
+
/** Server→client text messages (binary frames carry raw PCM16 audio). */
|
|
168
|
+
export type ServerMessage = ({
|
|
169
|
+
type: "config";
|
|
170
|
+
} & ReadyConfig) | {
|
|
171
|
+
type: "audio_done";
|
|
172
|
+
} | ClientEvent;
|
|
173
|
+
/** Zod schema for {@linkcode ClientMessage}. */
|
|
174
|
+
export declare const ClientMessageSchema: z.ZodType<ClientMessage>;
|
|
175
|
+
/**
|
|
176
|
+
* API shape the host process exposes to the sandboxed worker.
|
|
177
|
+
*
|
|
178
|
+
* Since workers run with all permissions denied, they use this interface
|
|
179
|
+
* to proxy network requests and KV operations back to the host.
|
|
180
|
+
*/
|
|
181
|
+
export type HostApi = {
|
|
182
|
+
fetch(req: {
|
|
183
|
+
url: string;
|
|
184
|
+
method: string;
|
|
185
|
+
headers: Readonly<Record<string, string>>;
|
|
186
|
+
body: string | null;
|
|
187
|
+
}): Promise<{
|
|
188
|
+
status: number;
|
|
189
|
+
statusText: string;
|
|
190
|
+
headers: Record<string, string>;
|
|
191
|
+
body: string;
|
|
192
|
+
}>;
|
|
193
|
+
kv(req: KvRequest): Promise<{
|
|
194
|
+
result: unknown;
|
|
195
|
+
}>;
|
|
196
|
+
vectorSearch(req: {
|
|
197
|
+
query: string;
|
|
198
|
+
topK: number;
|
|
199
|
+
}): Promise<string>;
|
|
200
|
+
};
|
|
201
|
+
/** Combined turn configuration resolved from the worker before a turn starts. */
|
|
202
|
+
export type TurnConfig = {
|
|
203
|
+
maxSteps?: number;
|
|
204
|
+
activeTools?: string[];
|
|
205
|
+
};
|
|
206
|
+
/** Worker-side RPC target interface (host calls these methods). */
|
|
207
|
+
export interface WorkerRpcApi {
|
|
208
|
+
withEnv(env: Record<string, string>): WorkerRpcApi;
|
|
209
|
+
getConfig(): Promise<WorkerConfig>;
|
|
210
|
+
executeTool(name: string, args: Readonly<Record<string, unknown>>, sessionId: string | undefined, messages: readonly Message[] | undefined): Promise<string>;
|
|
211
|
+
onConnect(sessionId: string): Promise<void>;
|
|
212
|
+
onDisconnect(sessionId: string): Promise<void>;
|
|
213
|
+
onTurn(sessionId: string, text: string): Promise<void>;
|
|
214
|
+
onError(sessionId: string, error: string): void;
|
|
215
|
+
onStep(sessionId: string, step: StepInfo): Promise<void>;
|
|
216
|
+
resolveTurnConfig(sessionId: string): Promise<TurnConfig | null>;
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../sdk/protocol.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAG,OAAgB,CAAC;AAU7C,sEAAsE;AACtE,eAAO,MAAM,cAAc;IACzB,0DAA0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AAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;CAClE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* WebSocket wire-format types shared by server and client.
|
|
4
|
+
*
|
|
5
|
+
* Note: this module is for internal use only and should not be used directly.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
/**
|
|
11
|
+
* Current protocol version for client-server compatibility checks.
|
|
12
|
+
*
|
|
13
|
+
* Increment this when making breaking changes to the wire protocol.
|
|
14
|
+
*/
|
|
15
|
+
export const PROTOCOL_VERSION = 1;
|
|
16
|
+
/**
|
|
17
|
+
* Default sample rate for speech-to-text audio in Hz.
|
|
18
|
+
*
|
|
19
|
+
* This is the sample rate expected by the STT provider (AssemblyAI).
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_STT_SAMPLE_RATE = 16_000;
|
|
22
|
+
/**
|
|
23
|
+
* Default sample rate for text-to-speech audio in Hz.
|
|
24
|
+
*
|
|
25
|
+
* This is the sample rate produced by the TTS provider (Rime).
|
|
26
|
+
*/
|
|
27
|
+
export const DEFAULT_TTS_SAMPLE_RATE = 24_000;
|
|
28
|
+
/**
|
|
29
|
+
* Audio codec identifier used in the wire protocol.
|
|
30
|
+
*
|
|
31
|
+
* All audio frames are 16-bit signed PCM, little-endian, mono.
|
|
32
|
+
*/
|
|
33
|
+
export const AUDIO_FORMAT = "pcm16";
|
|
34
|
+
/**
|
|
35
|
+
* Binary audio frame specification. All audio exchanged over the WebSocket as
|
|
36
|
+
* binary frames MUST conform to this spec. Any change here is a breaking
|
|
37
|
+
* protocol change.
|
|
38
|
+
*/
|
|
39
|
+
const _bitsPerSample = 16;
|
|
40
|
+
const _channels = 1;
|
|
41
|
+
/** Specification for binary audio frames exchanged over WebSocket. */
|
|
42
|
+
export const AudioFrameSpec = {
|
|
43
|
+
/** Audio codec identifier sent in the `ready` message. */
|
|
44
|
+
format: AUDIO_FORMAT,
|
|
45
|
+
/** Signed 16-bit integer samples. */
|
|
46
|
+
bitsPerSample: _bitsPerSample,
|
|
47
|
+
/** Little-endian byte order. */
|
|
48
|
+
endianness: "little",
|
|
49
|
+
/** Mono audio. */
|
|
50
|
+
channels: _channels,
|
|
51
|
+
/** Bytes per sample — derived from bitsPerSample and channels. */
|
|
52
|
+
bytesPerSample: (_bitsPerSample / 8) * _channels,
|
|
53
|
+
};
|
|
54
|
+
/** Zod schema for {@linkcode KvRequest}. */
|
|
55
|
+
export const KvRequestBaseSchema = z.discriminatedUnion("op", [
|
|
56
|
+
z.object({ op: z.literal("get"), key: z.string().min(1) }),
|
|
57
|
+
z.object({
|
|
58
|
+
op: z.literal("set"),
|
|
59
|
+
key: z.string().min(1),
|
|
60
|
+
value: z.string(),
|
|
61
|
+
ttl: z.number().int().positive().optional(),
|
|
62
|
+
}),
|
|
63
|
+
z.object({ op: z.literal("del"), key: z.string().min(1) }),
|
|
64
|
+
z.object({
|
|
65
|
+
op: z.literal("list"),
|
|
66
|
+
prefix: z.string(),
|
|
67
|
+
limit: z.number().int().positive().optional(),
|
|
68
|
+
reverse: z.boolean().optional(),
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
// ─── Timeout constants ─────────────────────────────────────────────────────
|
|
72
|
+
/** Default timeout for agent lifecycle hooks (onConnect, onTurn, etc). */
|
|
73
|
+
export const HOOK_TIMEOUT_MS = 5_000;
|
|
74
|
+
/** Default timeout for tool execution in the worker. */
|
|
75
|
+
export const TOOL_EXECUTION_TIMEOUT_MS = 30_000;
|
|
76
|
+
/** Zod schema for {@linkcode SessionErrorCode}. */
|
|
77
|
+
export const SessionErrorCodeSchema = z.enum([
|
|
78
|
+
"stt",
|
|
79
|
+
"llm",
|
|
80
|
+
"tts",
|
|
81
|
+
"tool",
|
|
82
|
+
"protocol",
|
|
83
|
+
"connection",
|
|
84
|
+
"audio",
|
|
85
|
+
"internal",
|
|
86
|
+
]);
|
|
87
|
+
/** Zod schema for a transcript event (partial or final). */
|
|
88
|
+
const TranscriptEventSchema = z.object({
|
|
89
|
+
type: z.literal("transcript"),
|
|
90
|
+
text: z.string(),
|
|
91
|
+
isFinal: z.boolean(),
|
|
92
|
+
turnOrder: z.number().int().nonnegative().optional(),
|
|
93
|
+
});
|
|
94
|
+
/** Zod schema for {@linkcode ClientEvent}. */
|
|
95
|
+
export const ClientEventSchema = z.discriminatedUnion("type", [
|
|
96
|
+
z.object({ type: z.literal("speech_started") }),
|
|
97
|
+
z.object({ type: z.literal("speech_stopped") }),
|
|
98
|
+
TranscriptEventSchema,
|
|
99
|
+
z.object({
|
|
100
|
+
type: z.literal("turn"),
|
|
101
|
+
text: z.string(),
|
|
102
|
+
turnOrder: z.number().int().nonnegative().optional(),
|
|
103
|
+
}),
|
|
104
|
+
z.object({ type: z.literal("chat"), text: z.string() }),
|
|
105
|
+
z.object({
|
|
106
|
+
type: z.literal("tool_call_start"),
|
|
107
|
+
toolCallId: z.string(),
|
|
108
|
+
toolName: z.string(),
|
|
109
|
+
args: z.record(z.string(), z.unknown()),
|
|
110
|
+
}),
|
|
111
|
+
z.object({
|
|
112
|
+
type: z.literal("tool_call_done"),
|
|
113
|
+
toolCallId: z.string(),
|
|
114
|
+
result: z.string().max(4000),
|
|
115
|
+
}),
|
|
116
|
+
z.object({ type: z.literal("tts_done") }),
|
|
117
|
+
z.object({ type: z.literal("cancelled") }),
|
|
118
|
+
z.object({ type: z.literal("reset") }),
|
|
119
|
+
z.object({
|
|
120
|
+
type: z.literal("error"),
|
|
121
|
+
code: SessionErrorCodeSchema,
|
|
122
|
+
message: z.string(),
|
|
123
|
+
}),
|
|
124
|
+
]);
|
|
125
|
+
/** Zod schema for {@linkcode ClientMessage}. */
|
|
126
|
+
export const ClientMessageSchema = z.discriminatedUnion("type", [
|
|
127
|
+
z.object({ type: z.literal("audio_ready") }),
|
|
128
|
+
z.object({ type: z.literal("cancel") }),
|
|
129
|
+
z.object({ type: z.literal("reset") }),
|
|
130
|
+
z.object({
|
|
131
|
+
type: z.literal("history"),
|
|
132
|
+
messages: z
|
|
133
|
+
.array(z.object({
|
|
134
|
+
role: z.enum(["user", "assistant"]),
|
|
135
|
+
text: z.string().max(100_000),
|
|
136
|
+
}))
|
|
137
|
+
.max(200),
|
|
138
|
+
}),
|
|
139
|
+
]);
|
|
140
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../sdk/protocol.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,OAAgB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,cAAc,GAAG,EAAW,CAAC;AACnC,MAAM,SAAS,GAAG,CAAU,CAAC;AAE7B,sEAAsE;AACtE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,0DAA0D;IAC1D,MAAM,EAAE,YAAY;IACpB,qCAAqC;IACrC,aAAa,EAAE,cAAc;IAC7B,gCAAgC;IAChC,UAAU,EAAE,QAAiB;IAC7B,kBAAkB;IAClB,QAAQ,EAAE,SAAS;IACnB,kEAAkE;IAClE,cAAc,EAAE,CAAC,cAAc,GAAG,CAAC,CAAC,GAAG,SAAS;CACxC,CAAC;AAmBX,4CAA4C;AAC5C,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AO,CAAC,EAAE,CAAC;IACtC,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,CAAC;aACR,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACnC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;SAC9B,CAAC,CACH;aACA,GAAG,CAAC,GAAG,CAAC;KACZ,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable interfaces for cross-runtime concerns.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Runtime-agnostic structured logger. */
|
|
7
|
+
export type Logger = {
|
|
8
|
+
info(msg: string, ctx?: Record<string, unknown>): void;
|
|
9
|
+
warn(msg: string, ctx?: Record<string, unknown>): void;
|
|
10
|
+
error(msg: string, ctx?: Record<string, unknown>): void;
|
|
11
|
+
debug(msg: string, ctx?: Record<string, unknown>): void;
|
|
12
|
+
};
|
|
13
|
+
/** Runtime-agnostic session metrics. */
|
|
14
|
+
export type Metrics = {
|
|
15
|
+
sessionsTotal: {
|
|
16
|
+
inc(labels: Record<string, string>): void;
|
|
17
|
+
};
|
|
18
|
+
sessionsActive: {
|
|
19
|
+
inc(labels: Record<string, string>): void;
|
|
20
|
+
dec(labels: Record<string, string>): void;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Console-based logger that works in all runtimes. */
|
|
24
|
+
export declare const consoleLogger: Logger;
|
|
25
|
+
/** No-op metrics implementation for environments without monitoring. */
|
|
26
|
+
export declare const noopMetrics: Metrics;
|
|
27
|
+
/** Configuration for the AssemblyAI Speech-to-Speech connection. */
|
|
28
|
+
export type S2SConfig = {
|
|
29
|
+
wssUrl: string;
|
|
30
|
+
inputSampleRate: number;
|
|
31
|
+
outputSampleRate: number;
|
|
32
|
+
};
|
|
33
|
+
/** Default S2S configuration pointing to AssemblyAI's production endpoint. */
|
|
34
|
+
export declare const DEFAULT_S2S_CONFIG: S2SConfig;
|
|
35
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../sdk/runtime.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAIH,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACzD,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,OAAO,GAAG;IACpB,aAAa,EAAE;QAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC;IAC7D,cAAc,EAAE;QACd,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;QAC1C,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;KAC3C,CAAC;CACH,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,aAAa,EAAE,MAiB3B,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,WAAW,EAAE,OAGzB,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,EAAE,SAIhC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2025 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Pluggable interfaces for cross-runtime concerns.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_TTS_SAMPLE_RATE } from "./protocol.js";
|
|
8
|
+
/** Console-based logger that works in all runtimes. */
|
|
9
|
+
export const consoleLogger = {
|
|
10
|
+
info(msg, ctx) {
|
|
11
|
+
if (ctx)
|
|
12
|
+
console.log(msg, ctx);
|
|
13
|
+
else
|
|
14
|
+
console.log(msg);
|
|
15
|
+
},
|
|
16
|
+
warn(msg, ctx) {
|
|
17
|
+
if (ctx)
|
|
18
|
+
console.warn(msg, ctx);
|
|
19
|
+
else
|
|
20
|
+
console.warn(msg);
|
|
21
|
+
},
|
|
22
|
+
error(msg, ctx) {
|
|
23
|
+
if (ctx)
|
|
24
|
+
console.error(msg, ctx);
|
|
25
|
+
else
|
|
26
|
+
console.error(msg);
|
|
27
|
+
},
|
|
28
|
+
debug(msg, ctx) {
|
|
29
|
+
if (ctx)
|
|
30
|
+
console.debug(msg, ctx);
|
|
31
|
+
else
|
|
32
|
+
console.debug(msg);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
/** No-op metrics implementation for environments without monitoring. */
|
|
36
|
+
export const noopMetrics = {
|
|
37
|
+
sessionsTotal: { inc() { } },
|
|
38
|
+
sessionsActive: { inc() { }, dec() { } },
|
|
39
|
+
};
|
|
40
|
+
/** Default S2S configuration pointing to AssemblyAI's production endpoint. */
|
|
41
|
+
export const DEFAULT_S2S_CONFIG = {
|
|
42
|
+
wssUrl: "wss://speech-to-speech.us.assemblyai.com/v1/realtime",
|
|
43
|
+
inputSampleRate: DEFAULT_TTS_SAMPLE_RATE,
|
|
44
|
+
outputSampleRate: DEFAULT_TTS_SAMPLE_RATE,
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../sdk/runtime.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAmBxD,uDAAuD;AACvD,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,IAAI,CAAC,GAAG,EAAE,GAAG;QACX,IAAI,GAAG;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;;YAC1B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,GAAG;QACX,IAAI,GAAG;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;;YAC3B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,KAAK,CAAC,GAAG,EAAE,GAAG;QACZ,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;;YAC5B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IACD,KAAK,CAAC,GAAG,EAAE,GAAG;QACZ,IAAI,GAAG;YAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;;YAC5B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF,CAAC;AAEF,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAY;IAClC,aAAa,EAAE,EAAE,GAAG,KAAI,CAAC,EAAE;IAC3B,cAAc,EAAE,EAAE,GAAG,KAAI,CAAC,EAAE,GAAG,KAAI,CAAC,EAAE;CACvC,CAAC;AASF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAc;IAC3C,MAAM,EAAE,sDAAsD;IAC9D,eAAe,EAAE,uBAAuB;IACxC,gBAAgB,EAAE,uBAAuB;CAC1C,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speech-to-Speech WebSocket client for AssemblyAI's S2S API.
|
|
3
|
+
*
|
|
4
|
+
* Cross-runtime: accepts a WebSocket factory and Logger instead of
|
|
5
|
+
* importing `ws` or `@std/log` directly.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { Logger, S2SConfig } from "./runtime.ts";
|
|
10
|
+
/** Minimal WebSocket interface for the S2S client. */
|
|
11
|
+
export type S2sWebSocket = {
|
|
12
|
+
readonly readyState: number;
|
|
13
|
+
send(data: string): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
16
|
+
};
|
|
17
|
+
/** Factory for creating WebSocket connections (e.g. the `ws` package). */
|
|
18
|
+
export type CreateS2sWebSocket = (url: string, opts: {
|
|
19
|
+
headers: Record<string, string>;
|
|
20
|
+
}) => S2sWebSocket;
|
|
21
|
+
export type S2sSessionConfig = {
|
|
22
|
+
system_prompt: string;
|
|
23
|
+
tools: S2sToolSchema[];
|
|
24
|
+
greeting?: string;
|
|
25
|
+
};
|
|
26
|
+
export type S2sToolSchema = {
|
|
27
|
+
type: "function";
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
parameters: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
export type S2sToolCall = {
|
|
33
|
+
call_id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
args: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
export type S2sHandle = EventTarget & {
|
|
38
|
+
sendAudio(audio: Uint8Array): void;
|
|
39
|
+
sendToolResult(callId: string, result: string): void;
|
|
40
|
+
updateSession(config: S2sSessionConfig): void;
|
|
41
|
+
resumeSession(sessionId: string): void;
|
|
42
|
+
close(): void;
|
|
43
|
+
};
|
|
44
|
+
export type ConnectS2sOptions = {
|
|
45
|
+
apiKey: string;
|
|
46
|
+
config: S2SConfig;
|
|
47
|
+
createWebSocket: CreateS2sWebSocket;
|
|
48
|
+
logger?: Logger;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Connect to AssemblyAI's Speech-to-Speech WebSocket API.
|
|
52
|
+
*
|
|
53
|
+
* Returns an {@linkcode S2sHandle} that extends EventTarget. Consumers
|
|
54
|
+
* listen for events: `ready`, `speech_started`, `speech_stopped`,
|
|
55
|
+
* `user_transcript_delta`, `user_transcript`, `reply_started`,
|
|
56
|
+
* `reply_done`, `audio`, `agent_transcript`, `tool_call`,
|
|
57
|
+
* `session_expired`, `error`, `close`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function connectS2s(opts: ConnectS2sOptions): Promise<S2sHandle>;
|
|
60
|
+
//# sourceMappingURL=s2s.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2s.d.ts","sourceRoot":"","sources":["../../sdk/s2s.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAyBtD,sDAAsD;AACtD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,IAAI,IAAI,CAAC;IACd,EAAE,CAAC,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