@prestyj/voice 4.3.191
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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/bridges/ezboss.cjs +96 -0
- package/dist/bridges/ezboss.cjs.map +1 -0
- package/dist/bridges/ezboss.d.cts +13 -0
- package/dist/bridges/ezboss.d.ts +13 -0
- package/dist/bridges/ezboss.js +70 -0
- package/dist/bridges/ezboss.js.map +1 -0
- package/dist/bridges/ezcoder-rpc.cjs +128 -0
- package/dist/bridges/ezcoder-rpc.cjs.map +1 -0
- package/dist/bridges/ezcoder-rpc.d.cts +18 -0
- package/dist/bridges/ezcoder-rpc.d.ts +18 -0
- package/dist/bridges/ezcoder-rpc.js +101 -0
- package/dist/bridges/ezcoder-rpc.js.map +1 -0
- package/dist/chunk-VJ6MPV2Z.js +225 -0
- package/dist/chunk-VJ6MPV2Z.js.map +1 -0
- package/dist/chunk-YLNKQ7CC.js +234 -0
- package/dist/chunk-YLNKQ7CC.js.map +1 -0
- package/dist/index.cjs +357 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +90 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +109 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/openai-codex-realtime.cjs +362 -0
- package/dist/providers/openai-codex-realtime.cjs.map +1 -0
- package/dist/providers/openai-codex-realtime.d.cts +15 -0
- package/dist/providers/openai-codex-realtime.d.ts +15 -0
- package/dist/providers/openai-codex-realtime.js +31 -0
- package/dist/providers/openai-codex-realtime.js.map +1 -0
- package/dist/providers/openai-realtime.cjs +342 -0
- package/dist/providers/openai-realtime.cjs.map +1 -0
- package/dist/providers/openai-realtime.d.cts +34 -0
- package/dist/providers/openai-realtime.d.ts +34 -0
- package/dist/providers/openai-realtime.js +12 -0
- package/dist/providers/openai-realtime.js.map +1 -0
- package/dist/types-Dc4Q3Z6X.d.cts +257 -0
- package/dist/types-Dc4Q3Z6X.d.ts +257 -0
- package/package.json +63 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
agentToolToVoiceTool: () => agentToolToVoiceTool,
|
|
24
|
+
createInMemoryVoiceProvider: () => createInMemoryVoiceProvider,
|
|
25
|
+
createVoiceSession: () => createVoiceSession,
|
|
26
|
+
executeVoiceToolCall: () => executeVoiceToolCall,
|
|
27
|
+
ggAiToolToRealtimeFunctionTool: () => ggAiToolToRealtimeFunctionTool,
|
|
28
|
+
ggAiToolToVoiceTool: () => ggAiToolToVoiceTool,
|
|
29
|
+
normalizeVoiceProviderError: () => normalizeVoiceProviderError,
|
|
30
|
+
voiceToolToRealtimeFunctionTool: () => voiceToolToRealtimeFunctionTool
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
|
|
34
|
+
// src/session.ts
|
|
35
|
+
function createVoiceSession(options) {
|
|
36
|
+
return new VoiceSessionController(options);
|
|
37
|
+
}
|
|
38
|
+
function normalizeVoiceProviderError(error) {
|
|
39
|
+
if (error instanceof Error) {
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
if (typeof error === "string") {
|
|
43
|
+
return new Error(error);
|
|
44
|
+
}
|
|
45
|
+
return new Error("Voice provider error", { cause: error });
|
|
46
|
+
}
|
|
47
|
+
var VoiceSessionController = class {
|
|
48
|
+
id;
|
|
49
|
+
provider;
|
|
50
|
+
metadata;
|
|
51
|
+
#state = "connected";
|
|
52
|
+
#handlers = /* @__PURE__ */ new Set();
|
|
53
|
+
#unsubscribeTransport;
|
|
54
|
+
#options;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.id = options.id;
|
|
57
|
+
this.provider = options.provider;
|
|
58
|
+
this.metadata = options.metadata ?? { sessionId: options.id, provider: options.provider };
|
|
59
|
+
this.#options = options;
|
|
60
|
+
this.#unsubscribeTransport = options.transport?.onEvent((event) => {
|
|
61
|
+
this.#handleTransportEvent(event);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
get state() {
|
|
65
|
+
return this.#state;
|
|
66
|
+
}
|
|
67
|
+
onEvent(handler) {
|
|
68
|
+
this.#handlers.add(handler);
|
|
69
|
+
return () => {
|
|
70
|
+
this.#handlers.delete(handler);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async sendAudio(chunk, signal) {
|
|
74
|
+
await this.#options.onSendAudio?.(chunk, signal);
|
|
75
|
+
await this.#options.transport?.send({ type: "audio", chunk }, signal);
|
|
76
|
+
}
|
|
77
|
+
async sendText(text, signal) {
|
|
78
|
+
await this.#options.onSendText?.(text, signal);
|
|
79
|
+
await this.#options.transport?.send({ type: "text", text }, signal);
|
|
80
|
+
}
|
|
81
|
+
async sendToolResult(result, signal) {
|
|
82
|
+
await this.#options.onSendToolResult?.(result, signal);
|
|
83
|
+
await this.#options.transport?.send({ type: "tool_result", result }, signal);
|
|
84
|
+
this.#emit({ type: "tool_result_sent", result });
|
|
85
|
+
}
|
|
86
|
+
async updateConfig(config, signal) {
|
|
87
|
+
await this.#options.onUpdateConfig?.(config, signal);
|
|
88
|
+
await this.#options.transport?.send({ type: "config", config }, signal);
|
|
89
|
+
}
|
|
90
|
+
async close(reason) {
|
|
91
|
+
if (this.#state === "closed" || this.#state === "closing") {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.#state = "closing";
|
|
95
|
+
await this.#options.onClose?.(reason);
|
|
96
|
+
await this.#options.transport?.close(reason);
|
|
97
|
+
this.#unsubscribeTransport?.();
|
|
98
|
+
this.#state = "closed";
|
|
99
|
+
this.#emit({ type: "closed", reason });
|
|
100
|
+
}
|
|
101
|
+
#handleTransportEvent(event) {
|
|
102
|
+
if (event.type === "raw") {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (event.type === "closed") {
|
|
106
|
+
this.#state = "closed";
|
|
107
|
+
}
|
|
108
|
+
this.#emit(event);
|
|
109
|
+
}
|
|
110
|
+
#emit(event) {
|
|
111
|
+
const handlers = [...this.#handlers];
|
|
112
|
+
for (const handler of handlers) {
|
|
113
|
+
handler(event);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/tools.ts
|
|
119
|
+
var import_zod = require("zod");
|
|
120
|
+
function ggAiToolToRealtimeFunctionTool(tool) {
|
|
121
|
+
return {
|
|
122
|
+
type: "function",
|
|
123
|
+
name: tool.name,
|
|
124
|
+
description: tool.description,
|
|
125
|
+
parameters: tool.rawInputSchema ?? zodToJsonSchemaObject(tool.parameters)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function voiceToolToRealtimeFunctionTool(tool) {
|
|
129
|
+
return {
|
|
130
|
+
type: "function",
|
|
131
|
+
name: tool.name,
|
|
132
|
+
description: tool.description,
|
|
133
|
+
parameters: tool.parameters
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function ggAiToolToVoiceTool(tool) {
|
|
137
|
+
return {
|
|
138
|
+
name: tool.name,
|
|
139
|
+
description: tool.description,
|
|
140
|
+
parameters: tool.rawInputSchema ?? zodToJsonSchemaObject(tool.parameters)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function agentToolToVoiceTool(tool) {
|
|
144
|
+
return {
|
|
145
|
+
name: tool.name,
|
|
146
|
+
description: tool.description,
|
|
147
|
+
parameters: tool.rawInputSchema ?? zodToJsonSchemaObject(tool.parameters),
|
|
148
|
+
async execute(args, context) {
|
|
149
|
+
const parsed = tool.parameters.safeParse(args);
|
|
150
|
+
if (!parsed.success) {
|
|
151
|
+
return {
|
|
152
|
+
error: "Invalid tool arguments",
|
|
153
|
+
issues: parsed.error.issues
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const agentContext = {
|
|
157
|
+
signal: context.signal,
|
|
158
|
+
toolCallId: context.toolCallId,
|
|
159
|
+
onUpdate: context.onUpdate
|
|
160
|
+
};
|
|
161
|
+
const result = await tool.execute(parsed.data, agentContext);
|
|
162
|
+
return normalizeAgentToolResult(result);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
async function executeVoiceToolCall(options) {
|
|
167
|
+
const tool = options.tools.find((candidate) => candidate.name === options.call.name);
|
|
168
|
+
if (!tool) {
|
|
169
|
+
return createErrorResult(options.call, {
|
|
170
|
+
type: "tool_not_found",
|
|
171
|
+
message: `Tool not found: ${options.call.name}`
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const confirmation = await resolveConfirmation(tool, options.call, options.confirmation);
|
|
175
|
+
if (!confirmation.approved) {
|
|
176
|
+
return createErrorResult(options.call, {
|
|
177
|
+
type: "tool_confirmation_denied",
|
|
178
|
+
message: confirmation.reason
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (!tool.execute) {
|
|
182
|
+
return createErrorResult(options.call, {
|
|
183
|
+
type: "tool_execution_failed",
|
|
184
|
+
message: `Tool has no executor: ${tool.name}`
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const abortController = new AbortController();
|
|
189
|
+
const signal = options.signal ?? abortController.signal;
|
|
190
|
+
const content = await tool.execute(options.call.args, {
|
|
191
|
+
signal,
|
|
192
|
+
toolCallId: options.call.id,
|
|
193
|
+
confirmation: options.confirmation,
|
|
194
|
+
onUpdate: options.onUpdate
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
toolCallId: options.call.id,
|
|
198
|
+
name: options.call.name,
|
|
199
|
+
content
|
|
200
|
+
};
|
|
201
|
+
} catch (error) {
|
|
202
|
+
return createErrorResult(options.call, {
|
|
203
|
+
type: "tool_execution_failed",
|
|
204
|
+
message: error instanceof Error ? error.message : "Tool execution failed",
|
|
205
|
+
cause: error
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function zodToJsonSchemaObject(schema) {
|
|
210
|
+
const jsonSchema = import_zod.z.toJSONSchema(schema);
|
|
211
|
+
const { $schema: _schema, ...rest } = jsonSchema;
|
|
212
|
+
return rest;
|
|
213
|
+
}
|
|
214
|
+
function normalizeAgentToolResult(result) {
|
|
215
|
+
if (typeof result === "string") {
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
if (typeof result.content === "string") {
|
|
219
|
+
if (result.details === void 0) {
|
|
220
|
+
return result.content;
|
|
221
|
+
}
|
|
222
|
+
return { content: result.content, details: result.details };
|
|
223
|
+
}
|
|
224
|
+
return { content: result.content, details: result.details };
|
|
225
|
+
}
|
|
226
|
+
async function resolveConfirmation(tool, call, confirmation) {
|
|
227
|
+
const policy = tool.confirmation ?? "never";
|
|
228
|
+
if (policy === "never") {
|
|
229
|
+
return { approved: true };
|
|
230
|
+
}
|
|
231
|
+
if (policy === "destructive" && !tool.destructive) {
|
|
232
|
+
return { approved: true };
|
|
233
|
+
}
|
|
234
|
+
if (typeof policy === "function") {
|
|
235
|
+
return policy({ call, tool });
|
|
236
|
+
}
|
|
237
|
+
if (!confirmation) {
|
|
238
|
+
return {
|
|
239
|
+
approved: false,
|
|
240
|
+
reason: `Tool requires confirmation: ${tool.name}`
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return confirmation({ call, tool });
|
|
244
|
+
}
|
|
245
|
+
function createErrorResult(call, error) {
|
|
246
|
+
const content = {
|
|
247
|
+
error: error.message,
|
|
248
|
+
type: error.type
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
toolCallId: call.id,
|
|
252
|
+
name: call.name,
|
|
253
|
+
content,
|
|
254
|
+
isError: true
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/providers/in-memory.ts
|
|
259
|
+
function createInMemoryVoiceProvider(options = {}) {
|
|
260
|
+
const sessions = [];
|
|
261
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
262
|
+
const idFactory = options.idFactory ?? (() => `voice_${sessions.length + 1}`);
|
|
263
|
+
return {
|
|
264
|
+
name: "in-memory",
|
|
265
|
+
get sessions() {
|
|
266
|
+
return sessions;
|
|
267
|
+
},
|
|
268
|
+
async connect(connectOptions) {
|
|
269
|
+
const id = idFactory();
|
|
270
|
+
const session = new InMemorySession(id, connectOptions.session, now);
|
|
271
|
+
sessions.push(session);
|
|
272
|
+
session.emit({
|
|
273
|
+
type: "session_started",
|
|
274
|
+
session: session.metadata
|
|
275
|
+
});
|
|
276
|
+
return session;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
var InMemorySession = class {
|
|
281
|
+
id;
|
|
282
|
+
provider = "in-memory";
|
|
283
|
+
metadata;
|
|
284
|
+
#state = "connected";
|
|
285
|
+
#handlers = /* @__PURE__ */ new Set();
|
|
286
|
+
#sentAudio = [];
|
|
287
|
+
#sentText = [];
|
|
288
|
+
#sentToolResults = [];
|
|
289
|
+
constructor(id, config, now) {
|
|
290
|
+
this.id = id;
|
|
291
|
+
this.metadata = {
|
|
292
|
+
sessionId: id,
|
|
293
|
+
provider: "in-memory",
|
|
294
|
+
model: config.model,
|
|
295
|
+
createdAt: now().toISOString()
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
get state() {
|
|
299
|
+
return this.#state;
|
|
300
|
+
}
|
|
301
|
+
get sentAudio() {
|
|
302
|
+
return this.#sentAudio;
|
|
303
|
+
}
|
|
304
|
+
get sentText() {
|
|
305
|
+
return this.#sentText;
|
|
306
|
+
}
|
|
307
|
+
get sentToolResults() {
|
|
308
|
+
return this.#sentToolResults;
|
|
309
|
+
}
|
|
310
|
+
onEvent(handler) {
|
|
311
|
+
this.#handlers.add(handler);
|
|
312
|
+
return () => {
|
|
313
|
+
this.#handlers.delete(handler);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
async sendAudio(chunk) {
|
|
317
|
+
this.#sentAudio.push(chunk);
|
|
318
|
+
}
|
|
319
|
+
async sendText(text) {
|
|
320
|
+
this.#sentText.push(text);
|
|
321
|
+
this.emit({ type: "input_transcript_done", text });
|
|
322
|
+
}
|
|
323
|
+
async sendToolResult(result) {
|
|
324
|
+
this.#sentToolResults.push(result);
|
|
325
|
+
this.emit({ type: "tool_result_sent", result });
|
|
326
|
+
}
|
|
327
|
+
async updateConfig(_config) {
|
|
328
|
+
}
|
|
329
|
+
async close(reason) {
|
|
330
|
+
if (this.#state === "closed") {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
this.#state = "closed";
|
|
334
|
+
this.emit({ type: "closed", reason });
|
|
335
|
+
}
|
|
336
|
+
emit(event) {
|
|
337
|
+
const handlers = [...this.#handlers];
|
|
338
|
+
for (const handler of handlers) {
|
|
339
|
+
handler(event);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
triggerToolCall(call) {
|
|
343
|
+
this.emit({ type: "tool_call", call });
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
347
|
+
0 && (module.exports = {
|
|
348
|
+
agentToolToVoiceTool,
|
|
349
|
+
createInMemoryVoiceProvider,
|
|
350
|
+
createVoiceSession,
|
|
351
|
+
executeVoiceToolCall,
|
|
352
|
+
ggAiToolToRealtimeFunctionTool,
|
|
353
|
+
ggAiToolToVoiceTool,
|
|
354
|
+
normalizeVoiceProviderError,
|
|
355
|
+
voiceToolToRealtimeFunctionTool
|
|
356
|
+
});
|
|
357
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/session.ts","../src/tools.ts","../src/providers/in-memory.ts"],"sourcesContent":["export type {\n AudioInputChunk,\n AudioOutputChunk,\n JsonObject,\n RealtimeFunctionToolDefinition,\n ToolConfirmationDecision,\n ToolConfirmationPolicy,\n ToolConfirmationRequest,\n ToolConfirmationResolver,\n VoiceAuthConfig,\n VoiceBridgeCommand,\n VoiceBridgeEvent,\n VoiceConnectionState,\n VoiceEvent,\n VoiceEventHandler,\n VoiceProvider,\n VoiceProviderConnectOptions,\n VoiceSession,\n VoiceSessionConfig,\n VoiceSessionMetadata,\n VoiceTool,\n VoiceToolCall,\n VoiceToolContext,\n VoiceToolExecutionError,\n VoiceToolExecutionResult,\n VoiceToolResult,\n VoiceTransport,\n VoiceTransportConnectOptions,\n VoiceTransportEvent,\n VoiceTransportEventHandler,\n VoiceTransportSendEvent,\n} from \"./types.js\";\n\nexport { createVoiceSession, normalizeVoiceProviderError } from \"./session.js\";\nexport type { VoiceSessionControllerOptions } from \"./session.js\";\n\nexport {\n agentToolToVoiceTool,\n executeVoiceToolCall,\n ggAiToolToRealtimeFunctionTool,\n ggAiToolToVoiceTool,\n voiceToolToRealtimeFunctionTool,\n} from \"./tools.js\";\nexport type { ExecuteVoiceToolCallOptions, VoiceToolSource } from \"./tools.js\";\n\nexport { createInMemoryVoiceProvider } from \"./providers/in-memory.js\";\nexport type {\n InMemoryVoiceProvider,\n InMemoryVoiceProviderOptions,\n InMemoryVoiceSession,\n} from \"./providers/in-memory.js\";\n\nexport type {\n OpenUrlRequest,\n PlatformAudioAdapter,\n PlatformNotification,\n PlatformSecureTokenStore,\n PlatformUrlOpener,\n RelayHttpClient,\n RelayRequest,\n RelayResponse,\n} from \"./platform.js\";\n","import type {\n AudioInputChunk,\n JsonObject,\n VoiceConnectionState,\n VoiceEvent,\n VoiceEventHandler,\n VoiceSession,\n VoiceSessionConfig,\n VoiceSessionMetadata,\n VoiceToolResult,\n VoiceTransport,\n VoiceTransportEvent,\n} from \"./types.js\";\n\nexport interface VoiceSessionControllerOptions {\n readonly id: string;\n readonly provider: string;\n readonly transport?: VoiceTransport;\n readonly metadata?: VoiceSessionMetadata;\n readonly onSendToolResult?: (result: VoiceToolResult, signal?: AbortSignal) => Promise<void>;\n readonly onSendAudio?: (chunk: AudioInputChunk, signal?: AbortSignal) => Promise<void>;\n readonly onSendText?: (text: string, signal?: AbortSignal) => Promise<void>;\n readonly onUpdateConfig?: (\n config: Partial<VoiceSessionConfig>,\n signal?: AbortSignal,\n ) => Promise<void>;\n readonly onClose?: (reason?: string) => Promise<void>;\n}\n\nexport function createVoiceSession(options: VoiceSessionControllerOptions): VoiceSession {\n return new VoiceSessionController(options);\n}\n\nexport function normalizeVoiceProviderError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n if (typeof error === \"string\") {\n return new Error(error);\n }\n return new Error(\"Voice provider error\", { cause: error });\n}\n\nclass VoiceSessionController implements VoiceSession {\n readonly id: string;\n readonly provider: string;\n readonly metadata: VoiceSessionMetadata;\n #state: VoiceConnectionState = \"connected\";\n #handlers = new Set<VoiceEventHandler>();\n #unsubscribeTransport?: () => void;\n #options: VoiceSessionControllerOptions;\n\n constructor(options: VoiceSessionControllerOptions) {\n this.id = options.id;\n this.provider = options.provider;\n this.metadata = options.metadata ?? { sessionId: options.id, provider: options.provider };\n this.#options = options;\n this.#unsubscribeTransport = options.transport?.onEvent((event) => {\n this.#handleTransportEvent(event);\n });\n }\n\n get state(): VoiceConnectionState {\n return this.#state;\n }\n\n onEvent(handler: VoiceEventHandler): () => void {\n this.#handlers.add(handler);\n return () => {\n this.#handlers.delete(handler);\n };\n }\n\n async sendAudio(chunk: AudioInputChunk, signal?: AbortSignal): Promise<void> {\n await this.#options.onSendAudio?.(chunk, signal);\n await this.#options.transport?.send({ type: \"audio\", chunk }, signal);\n }\n\n async sendText(text: string, signal?: AbortSignal): Promise<void> {\n await this.#options.onSendText?.(text, signal);\n await this.#options.transport?.send({ type: \"text\", text }, signal);\n }\n\n async sendToolResult(result: VoiceToolResult, signal?: AbortSignal): Promise<void> {\n await this.#options.onSendToolResult?.(result, signal);\n await this.#options.transport?.send({ type: \"tool_result\", result }, signal);\n this.#emit({ type: \"tool_result_sent\", result });\n }\n\n async updateConfig(config: Partial<VoiceSessionConfig>, signal?: AbortSignal): Promise<void> {\n await this.#options.onUpdateConfig?.(config, signal);\n await this.#options.transport?.send({ type: \"config\", config }, signal);\n }\n\n async close(reason?: string): Promise<void> {\n if (this.#state === \"closed\" || this.#state === \"closing\") {\n return;\n }\n this.#state = \"closing\";\n await this.#options.onClose?.(reason);\n await this.#options.transport?.close(reason);\n this.#unsubscribeTransport?.();\n this.#state = \"closed\";\n this.#emit({ type: \"closed\", reason });\n }\n\n #handleTransportEvent(event: VoiceTransportEvent): void {\n if (event.type === \"raw\") {\n return;\n }\n if (event.type === \"closed\") {\n this.#state = \"closed\";\n }\n this.#emit(event);\n }\n\n #emit(event: VoiceEvent): void {\n const handlers = [...this.#handlers];\n for (const handler of handlers) {\n handler(event);\n }\n }\n}\n\nexport function isJsonObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","import type { AgentTool, ToolContext, ToolExecuteResult } from \"@prestyj/agent\";\nimport type { Tool } from \"@prestyj/ai\";\nimport { z } from \"zod\";\nimport type {\n JsonObject,\n RealtimeFunctionToolDefinition,\n ToolConfirmationDecision,\n VoiceTool,\n VoiceToolCall,\n VoiceToolContext,\n VoiceToolExecutionError,\n VoiceToolExecutionResult,\n VoiceToolResult,\n} from \"./types.js\";\n\ntype ZodParseResult = { success: true; data: unknown } | { success: false; error: z.ZodError };\n\nexport type VoiceToolSource = VoiceTool | AgentTool | Tool;\n\nexport interface ExecuteVoiceToolCallOptions {\n readonly tools: readonly VoiceTool[];\n readonly call: VoiceToolCall;\n readonly signal?: AbortSignal;\n readonly confirmation?: VoiceToolContext[\"confirmation\"];\n readonly onUpdate?: VoiceToolContext[\"onUpdate\"];\n}\n\nexport function ggAiToolToRealtimeFunctionTool(tool: Tool): RealtimeFunctionToolDefinition {\n return {\n type: \"function\",\n name: tool.name,\n description: tool.description,\n parameters: tool.rawInputSchema ?? zodToJsonSchemaObject(tool.parameters),\n };\n}\n\nexport function voiceToolToRealtimeFunctionTool(tool: VoiceTool): RealtimeFunctionToolDefinition {\n return {\n type: \"function\",\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters,\n };\n}\n\nexport function ggAiToolToVoiceTool(tool: Tool): VoiceTool {\n return {\n name: tool.name,\n description: tool.description,\n parameters: tool.rawInputSchema ?? zodToJsonSchemaObject(tool.parameters),\n };\n}\n\nexport function agentToolToVoiceTool<T extends z.ZodType>(tool: AgentTool<T>): VoiceTool {\n return {\n name: tool.name,\n description: tool.description,\n parameters: tool.rawInputSchema ?? zodToJsonSchemaObject(tool.parameters),\n async execute(args, context): Promise<VoiceToolExecutionResult> {\n const parsed = tool.parameters.safeParse(args) as ZodParseResult;\n if (!parsed.success) {\n return {\n error: \"Invalid tool arguments\",\n issues: parsed.error.issues,\n };\n }\n\n const agentContext: ToolContext = {\n signal: context.signal,\n toolCallId: context.toolCallId,\n onUpdate: context.onUpdate,\n };\n const result = await tool.execute(parsed.data as z.infer<T>, agentContext);\n return normalizeAgentToolResult(result);\n },\n };\n}\n\nexport async function executeVoiceToolCall(\n options: ExecuteVoiceToolCallOptions,\n): Promise<VoiceToolResult> {\n const tool = options.tools.find((candidate) => candidate.name === options.call.name);\n if (!tool) {\n return createErrorResult(options.call, {\n type: \"tool_not_found\",\n message: `Tool not found: ${options.call.name}`,\n });\n }\n\n const confirmation = await resolveConfirmation(tool, options.call, options.confirmation);\n if (!confirmation.approved) {\n return createErrorResult(options.call, {\n type: \"tool_confirmation_denied\",\n message: confirmation.reason,\n });\n }\n\n if (!tool.execute) {\n return createErrorResult(options.call, {\n type: \"tool_execution_failed\",\n message: `Tool has no executor: ${tool.name}`,\n });\n }\n\n try {\n const abortController = new AbortController();\n const signal = options.signal ?? abortController.signal;\n const content = await tool.execute(options.call.args, {\n signal,\n toolCallId: options.call.id,\n confirmation: options.confirmation,\n onUpdate: options.onUpdate,\n });\n return {\n toolCallId: options.call.id,\n name: options.call.name,\n content,\n };\n } catch (error) {\n return createErrorResult(options.call, {\n type: \"tool_execution_failed\",\n message: error instanceof Error ? error.message : \"Tool execution failed\",\n cause: error,\n });\n }\n}\n\nfunction zodToJsonSchemaObject(schema: z.ZodType): JsonObject {\n const jsonSchema = z.toJSONSchema(schema) as JsonObject;\n const { $schema: _schema, ...rest } = jsonSchema;\n return rest;\n}\n\nfunction normalizeAgentToolResult(result: ToolExecuteResult): VoiceToolExecutionResult {\n if (typeof result === \"string\") {\n return result;\n }\n if (typeof result.content === \"string\") {\n if (result.details === undefined) {\n return result.content;\n }\n return { content: result.content, details: result.details };\n }\n return { content: result.content, details: result.details };\n}\n\nasync function resolveConfirmation(\n tool: VoiceTool,\n call: VoiceToolCall,\n confirmation: VoiceToolContext[\"confirmation\"],\n): Promise<ToolConfirmationDecision> {\n const policy = tool.confirmation ?? \"never\";\n if (policy === \"never\") {\n return { approved: true };\n }\n if (policy === \"destructive\" && !tool.destructive) {\n return { approved: true };\n }\n if (typeof policy === \"function\") {\n return policy({ call, tool });\n }\n if (!confirmation) {\n return {\n approved: false,\n reason: `Tool requires confirmation: ${tool.name}`,\n };\n }\n return confirmation({ call, tool });\n}\n\nfunction createErrorResult(call: VoiceToolCall, error: VoiceToolExecutionError): VoiceToolResult {\n const content: JsonObject = {\n error: error.message,\n type: error.type,\n };\n return {\n toolCallId: call.id,\n name: call.name,\n content,\n isError: true,\n };\n}\n","import type {\n AudioInputChunk,\n VoiceEvent,\n VoiceEventHandler,\n VoiceProvider,\n VoiceProviderConnectOptions,\n VoiceSession,\n VoiceSessionConfig,\n VoiceToolCall,\n VoiceToolResult,\n} from \"../types.js\";\n\nexport interface InMemoryVoiceProviderOptions {\n readonly now?: () => Date;\n readonly idFactory?: () => string;\n}\n\nexport interface InMemoryVoiceProvider extends Omit<VoiceProvider, \"connect\"> {\n readonly sessions: readonly InMemoryVoiceSession[];\n connect(options: VoiceProviderConnectOptions): Promise<InMemoryVoiceSession>;\n}\n\nexport interface InMemoryVoiceSession extends VoiceSession {\n emit(event: VoiceEvent): void;\n readonly sentAudio: readonly AudioInputChunk[];\n readonly sentText: readonly string[];\n readonly sentToolResults: readonly VoiceToolResult[];\n triggerToolCall(call: VoiceToolCall): void;\n}\n\nexport function createInMemoryVoiceProvider(\n options: InMemoryVoiceProviderOptions = {},\n): InMemoryVoiceProvider {\n const sessions: InMemorySession[] = [];\n const now = options.now ?? (() => new Date());\n const idFactory = options.idFactory ?? (() => `voice_${sessions.length + 1}`);\n\n return {\n name: \"in-memory\",\n get sessions() {\n return sessions;\n },\n async connect(connectOptions: VoiceProviderConnectOptions): Promise<InMemoryVoiceSession> {\n const id = idFactory();\n const session = new InMemorySession(id, connectOptions.session, now);\n sessions.push(session);\n session.emit({\n type: \"session_started\",\n session: session.metadata,\n });\n return session;\n },\n };\n}\n\nclass InMemorySession implements InMemoryVoiceSession {\n readonly id: string;\n readonly provider = \"in-memory\";\n readonly metadata;\n #state: VoiceSession[\"state\"] = \"connected\";\n #handlers = new Set<VoiceEventHandler>();\n #sentAudio: AudioInputChunk[] = [];\n #sentText: string[] = [];\n #sentToolResults: VoiceToolResult[] = [];\n\n constructor(id: string, config: VoiceSessionConfig, now: () => Date) {\n this.id = id;\n this.metadata = {\n sessionId: id,\n provider: \"in-memory\",\n model: config.model,\n createdAt: now().toISOString(),\n };\n }\n\n get state(): VoiceSession[\"state\"] {\n return this.#state;\n }\n\n get sentAudio(): readonly AudioInputChunk[] {\n return this.#sentAudio;\n }\n\n get sentText(): readonly string[] {\n return this.#sentText;\n }\n\n get sentToolResults(): readonly VoiceToolResult[] {\n return this.#sentToolResults;\n }\n\n onEvent(handler: VoiceEventHandler): () => void {\n this.#handlers.add(handler);\n return () => {\n this.#handlers.delete(handler);\n };\n }\n\n async sendAudio(chunk: AudioInputChunk): Promise<void> {\n this.#sentAudio.push(chunk);\n }\n\n async sendText(text: string): Promise<void> {\n this.#sentText.push(text);\n this.emit({ type: \"input_transcript_done\", text });\n }\n\n async sendToolResult(result: VoiceToolResult): Promise<void> {\n this.#sentToolResults.push(result);\n this.emit({ type: \"tool_result_sent\", result });\n }\n\n async updateConfig(_config: Partial<VoiceSessionConfig>): Promise<void> {}\n\n async close(reason?: string): Promise<void> {\n if (this.#state === \"closed\") {\n return;\n }\n this.#state = \"closed\";\n this.emit({ type: \"closed\", reason });\n }\n\n emit(event: VoiceEvent): void {\n const handlers = [...this.#handlers];\n for (const handler of handlers) {\n handler(event);\n }\n }\n\n triggerToolCall(call: VoiceToolCall): void {\n this.emit({ type: \"tool_call\", call });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,SAAS,mBAAmB,SAAsD;AACvF,SAAO,IAAI,uBAAuB,OAAO;AAC3C;AAEO,SAAS,4BAA4B,OAAuB;AACjE,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,IAAI,MAAM,KAAK;AAAA,EACxB;AACA,SAAO,IAAI,MAAM,wBAAwB,EAAE,OAAO,MAAM,CAAC;AAC3D;A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EA,IAAI,YAAwC;AAC1C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,WAA8B;AAChC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,kBAA8C;AAChD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,QAAQ,SAAwC;AAC9C,SAAK,UAAU,IAAI,OAAO;AAC1B,WAAO,MAAM;AACX,WAAK,UAAU,OAAO,OAAO;AAAA,IAC/B;AAAA,EACF;AAAA,EAEA,MAAM,UAAU,OAAuC;AACrD,SAAK,WAAW,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEA,MAAM,SAAS,MAA6B;AAC1C,SAAK,UAAU,KAAK,IAAI;AACxB,SAAK,KAAK,EAAE,MAAM,yBAAyB,KAAK,CAAC;AAAA,EACnD;AAAA,EAEA,MAAM,eAAe,QAAwC;AAC3D,SAAK,iBAAiB,KAAK,MAAM;AACjC,SAAK,KAAK,EAAE,MAAM,oBAAoB,OAAO,CAAC;AAAA,EAChD;AAAA,EAEA,MAAM,aAAa,SAAqD;AAAA,EAAC;AAAA,EAEzE,MAAM,MAAM,QAAgC;AAC1C,QAAI,KAAK,WAAW,UAAU;AAC5B;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,KAAK,EAAE,MAAM,UAAU,OAAO,CAAC;AAAA,EACtC;AAAA,EAEA,KAAK,OAAyB;AAC5B,UAAM,WAAW,CAAC,GAAG,KAAK,SAAS;AACnC,eAAW,WAAW,UAAU;AAC9B,cAAQ,KAAK;AAAA,IACf;AAAA,EACF;AAAA,EAEA,gBAAgB,MAA2B;AACzC,SAAK,KAAK,EAAE,MAAM,aAAa,KAAK,CAAC;AAAA,EACvC;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { V as VoiceTransport, a as VoiceSessionMetadata, b as VoiceToolResult, A as AudioInputChunk, c as VoiceSessionConfig, d as VoiceSession, e as VoiceTool, f as VoiceToolCall, g as VoiceToolContext, R as RealtimeFunctionToolDefinition, h as VoiceProvider, i as VoiceEvent, j as VoiceProviderConnectOptions, k as AudioOutputChunk, J as JsonObject } from './types-Dc4Q3Z6X.cjs';
|
|
2
|
+
export { T as ToolConfirmationDecision, l as ToolConfirmationPolicy, m as ToolConfirmationRequest, n as ToolConfirmationResolver, o as VoiceAuthConfig, p as VoiceBridgeCommand, q as VoiceBridgeEvent, r as VoiceConnectionState, s as VoiceEventHandler, t as VoiceToolExecutionError, u as VoiceToolExecutionResult, v as VoiceTransportConnectOptions, w as VoiceTransportEvent, x as VoiceTransportEventHandler, y as VoiceTransportSendEvent } from './types-Dc4Q3Z6X.cjs';
|
|
3
|
+
import { AgentTool } from '@prestyj/agent';
|
|
4
|
+
import { Tool } from '@prestyj/ai';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
interface VoiceSessionControllerOptions {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly provider: string;
|
|
10
|
+
readonly transport?: VoiceTransport;
|
|
11
|
+
readonly metadata?: VoiceSessionMetadata;
|
|
12
|
+
readonly onSendToolResult?: (result: VoiceToolResult, signal?: AbortSignal) => Promise<void>;
|
|
13
|
+
readonly onSendAudio?: (chunk: AudioInputChunk, signal?: AbortSignal) => Promise<void>;
|
|
14
|
+
readonly onSendText?: (text: string, signal?: AbortSignal) => Promise<void>;
|
|
15
|
+
readonly onUpdateConfig?: (config: Partial<VoiceSessionConfig>, signal?: AbortSignal) => Promise<void>;
|
|
16
|
+
readonly onClose?: (reason?: string) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare function createVoiceSession(options: VoiceSessionControllerOptions): VoiceSession;
|
|
19
|
+
declare function normalizeVoiceProviderError(error: unknown): Error;
|
|
20
|
+
|
|
21
|
+
type VoiceToolSource = VoiceTool | AgentTool | Tool;
|
|
22
|
+
interface ExecuteVoiceToolCallOptions {
|
|
23
|
+
readonly tools: readonly VoiceTool[];
|
|
24
|
+
readonly call: VoiceToolCall;
|
|
25
|
+
readonly signal?: AbortSignal;
|
|
26
|
+
readonly confirmation?: VoiceToolContext["confirmation"];
|
|
27
|
+
readonly onUpdate?: VoiceToolContext["onUpdate"];
|
|
28
|
+
}
|
|
29
|
+
declare function ggAiToolToRealtimeFunctionTool(tool: Tool): RealtimeFunctionToolDefinition;
|
|
30
|
+
declare function voiceToolToRealtimeFunctionTool(tool: VoiceTool): RealtimeFunctionToolDefinition;
|
|
31
|
+
declare function ggAiToolToVoiceTool(tool: Tool): VoiceTool;
|
|
32
|
+
declare function agentToolToVoiceTool<T extends z.ZodType>(tool: AgentTool<T>): VoiceTool;
|
|
33
|
+
declare function executeVoiceToolCall(options: ExecuteVoiceToolCallOptions): Promise<VoiceToolResult>;
|
|
34
|
+
|
|
35
|
+
interface InMemoryVoiceProviderOptions {
|
|
36
|
+
readonly now?: () => Date;
|
|
37
|
+
readonly idFactory?: () => string;
|
|
38
|
+
}
|
|
39
|
+
interface InMemoryVoiceProvider extends Omit<VoiceProvider, "connect"> {
|
|
40
|
+
readonly sessions: readonly InMemoryVoiceSession[];
|
|
41
|
+
connect(options: VoiceProviderConnectOptions): Promise<InMemoryVoiceSession>;
|
|
42
|
+
}
|
|
43
|
+
interface InMemoryVoiceSession extends VoiceSession {
|
|
44
|
+
emit(event: VoiceEvent): void;
|
|
45
|
+
readonly sentAudio: readonly AudioInputChunk[];
|
|
46
|
+
readonly sentText: readonly string[];
|
|
47
|
+
readonly sentToolResults: readonly VoiceToolResult[];
|
|
48
|
+
triggerToolCall(call: VoiceToolCall): void;
|
|
49
|
+
}
|
|
50
|
+
declare function createInMemoryVoiceProvider(options?: InMemoryVoiceProviderOptions): InMemoryVoiceProvider;
|
|
51
|
+
|
|
52
|
+
interface PlatformSecureTokenStore {
|
|
53
|
+
getToken(key: string, signal?: AbortSignal): Promise<string | null>;
|
|
54
|
+
setToken(key: string, value: string, signal?: AbortSignal): Promise<void>;
|
|
55
|
+
deleteToken(key: string, signal?: AbortSignal): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
interface OpenUrlRequest {
|
|
58
|
+
readonly url: string;
|
|
59
|
+
readonly fallbackUrl?: string;
|
|
60
|
+
}
|
|
61
|
+
interface PlatformUrlOpener {
|
|
62
|
+
canOpenUrl(url: string, signal?: AbortSignal): Promise<boolean>;
|
|
63
|
+
openUrl(request: OpenUrlRequest, signal?: AbortSignal): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
interface PlatformNotification {
|
|
66
|
+
readonly title: string;
|
|
67
|
+
readonly body?: string;
|
|
68
|
+
readonly data?: JsonObject;
|
|
69
|
+
}
|
|
70
|
+
interface PlatformAudioAdapter {
|
|
71
|
+
startCapture(signal?: AbortSignal): Promise<AsyncIterable<AudioInputChunk>>;
|
|
72
|
+
play(chunk: AudioOutputChunk, signal?: AbortSignal): Promise<void>;
|
|
73
|
+
stop(reason?: string): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
interface RelayRequest {
|
|
76
|
+
readonly path: string;
|
|
77
|
+
readonly method: "GET" | "POST" | "PATCH" | "DELETE";
|
|
78
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
79
|
+
readonly body?: unknown;
|
|
80
|
+
}
|
|
81
|
+
interface RelayResponse {
|
|
82
|
+
readonly status: number;
|
|
83
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
84
|
+
readonly body: unknown;
|
|
85
|
+
}
|
|
86
|
+
interface RelayHttpClient {
|
|
87
|
+
send(request: RelayRequest, signal?: AbortSignal): Promise<RelayResponse>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { AudioInputChunk, AudioOutputChunk, type ExecuteVoiceToolCallOptions, type InMemoryVoiceProvider, type InMemoryVoiceProviderOptions, type InMemoryVoiceSession, JsonObject, type OpenUrlRequest, type PlatformAudioAdapter, type PlatformNotification, type PlatformSecureTokenStore, type PlatformUrlOpener, RealtimeFunctionToolDefinition, type RelayHttpClient, type RelayRequest, type RelayResponse, VoiceEvent, VoiceProvider, VoiceProviderConnectOptions, VoiceSession, VoiceSessionConfig, type VoiceSessionControllerOptions, VoiceSessionMetadata, VoiceTool, VoiceToolCall, VoiceToolContext, VoiceToolResult, type VoiceToolSource, VoiceTransport, agentToolToVoiceTool, createInMemoryVoiceProvider, createVoiceSession, executeVoiceToolCall, ggAiToolToRealtimeFunctionTool, ggAiToolToVoiceTool, normalizeVoiceProviderError, voiceToolToRealtimeFunctionTool };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { V as VoiceTransport, a as VoiceSessionMetadata, b as VoiceToolResult, A as AudioInputChunk, c as VoiceSessionConfig, d as VoiceSession, e as VoiceTool, f as VoiceToolCall, g as VoiceToolContext, R as RealtimeFunctionToolDefinition, h as VoiceProvider, i as VoiceEvent, j as VoiceProviderConnectOptions, k as AudioOutputChunk, J as JsonObject } from './types-Dc4Q3Z6X.js';
|
|
2
|
+
export { T as ToolConfirmationDecision, l as ToolConfirmationPolicy, m as ToolConfirmationRequest, n as ToolConfirmationResolver, o as VoiceAuthConfig, p as VoiceBridgeCommand, q as VoiceBridgeEvent, r as VoiceConnectionState, s as VoiceEventHandler, t as VoiceToolExecutionError, u as VoiceToolExecutionResult, v as VoiceTransportConnectOptions, w as VoiceTransportEvent, x as VoiceTransportEventHandler, y as VoiceTransportSendEvent } from './types-Dc4Q3Z6X.js';
|
|
3
|
+
import { AgentTool } from '@prestyj/agent';
|
|
4
|
+
import { Tool } from '@prestyj/ai';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
interface VoiceSessionControllerOptions {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly provider: string;
|
|
10
|
+
readonly transport?: VoiceTransport;
|
|
11
|
+
readonly metadata?: VoiceSessionMetadata;
|
|
12
|
+
readonly onSendToolResult?: (result: VoiceToolResult, signal?: AbortSignal) => Promise<void>;
|
|
13
|
+
readonly onSendAudio?: (chunk: AudioInputChunk, signal?: AbortSignal) => Promise<void>;
|
|
14
|
+
readonly onSendText?: (text: string, signal?: AbortSignal) => Promise<void>;
|
|
15
|
+
readonly onUpdateConfig?: (config: Partial<VoiceSessionConfig>, signal?: AbortSignal) => Promise<void>;
|
|
16
|
+
readonly onClose?: (reason?: string) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
declare function createVoiceSession(options: VoiceSessionControllerOptions): VoiceSession;
|
|
19
|
+
declare function normalizeVoiceProviderError(error: unknown): Error;
|
|
20
|
+
|
|
21
|
+
type VoiceToolSource = VoiceTool | AgentTool | Tool;
|
|
22
|
+
interface ExecuteVoiceToolCallOptions {
|
|
23
|
+
readonly tools: readonly VoiceTool[];
|
|
24
|
+
readonly call: VoiceToolCall;
|
|
25
|
+
readonly signal?: AbortSignal;
|
|
26
|
+
readonly confirmation?: VoiceToolContext["confirmation"];
|
|
27
|
+
readonly onUpdate?: VoiceToolContext["onUpdate"];
|
|
28
|
+
}
|
|
29
|
+
declare function ggAiToolToRealtimeFunctionTool(tool: Tool): RealtimeFunctionToolDefinition;
|
|
30
|
+
declare function voiceToolToRealtimeFunctionTool(tool: VoiceTool): RealtimeFunctionToolDefinition;
|
|
31
|
+
declare function ggAiToolToVoiceTool(tool: Tool): VoiceTool;
|
|
32
|
+
declare function agentToolToVoiceTool<T extends z.ZodType>(tool: AgentTool<T>): VoiceTool;
|
|
33
|
+
declare function executeVoiceToolCall(options: ExecuteVoiceToolCallOptions): Promise<VoiceToolResult>;
|
|
34
|
+
|
|
35
|
+
interface InMemoryVoiceProviderOptions {
|
|
36
|
+
readonly now?: () => Date;
|
|
37
|
+
readonly idFactory?: () => string;
|
|
38
|
+
}
|
|
39
|
+
interface InMemoryVoiceProvider extends Omit<VoiceProvider, "connect"> {
|
|
40
|
+
readonly sessions: readonly InMemoryVoiceSession[];
|
|
41
|
+
connect(options: VoiceProviderConnectOptions): Promise<InMemoryVoiceSession>;
|
|
42
|
+
}
|
|
43
|
+
interface InMemoryVoiceSession extends VoiceSession {
|
|
44
|
+
emit(event: VoiceEvent): void;
|
|
45
|
+
readonly sentAudio: readonly AudioInputChunk[];
|
|
46
|
+
readonly sentText: readonly string[];
|
|
47
|
+
readonly sentToolResults: readonly VoiceToolResult[];
|
|
48
|
+
triggerToolCall(call: VoiceToolCall): void;
|
|
49
|
+
}
|
|
50
|
+
declare function createInMemoryVoiceProvider(options?: InMemoryVoiceProviderOptions): InMemoryVoiceProvider;
|
|
51
|
+
|
|
52
|
+
interface PlatformSecureTokenStore {
|
|
53
|
+
getToken(key: string, signal?: AbortSignal): Promise<string | null>;
|
|
54
|
+
setToken(key: string, value: string, signal?: AbortSignal): Promise<void>;
|
|
55
|
+
deleteToken(key: string, signal?: AbortSignal): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
interface OpenUrlRequest {
|
|
58
|
+
readonly url: string;
|
|
59
|
+
readonly fallbackUrl?: string;
|
|
60
|
+
}
|
|
61
|
+
interface PlatformUrlOpener {
|
|
62
|
+
canOpenUrl(url: string, signal?: AbortSignal): Promise<boolean>;
|
|
63
|
+
openUrl(request: OpenUrlRequest, signal?: AbortSignal): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
interface PlatformNotification {
|
|
66
|
+
readonly title: string;
|
|
67
|
+
readonly body?: string;
|
|
68
|
+
readonly data?: JsonObject;
|
|
69
|
+
}
|
|
70
|
+
interface PlatformAudioAdapter {
|
|
71
|
+
startCapture(signal?: AbortSignal): Promise<AsyncIterable<AudioInputChunk>>;
|
|
72
|
+
play(chunk: AudioOutputChunk, signal?: AbortSignal): Promise<void>;
|
|
73
|
+
stop(reason?: string): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
interface RelayRequest {
|
|
76
|
+
readonly path: string;
|
|
77
|
+
readonly method: "GET" | "POST" | "PATCH" | "DELETE";
|
|
78
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
79
|
+
readonly body?: unknown;
|
|
80
|
+
}
|
|
81
|
+
interface RelayResponse {
|
|
82
|
+
readonly status: number;
|
|
83
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
84
|
+
readonly body: unknown;
|
|
85
|
+
}
|
|
86
|
+
interface RelayHttpClient {
|
|
87
|
+
send(request: RelayRequest, signal?: AbortSignal): Promise<RelayResponse>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { AudioInputChunk, AudioOutputChunk, type ExecuteVoiceToolCallOptions, type InMemoryVoiceProvider, type InMemoryVoiceProviderOptions, type InMemoryVoiceSession, JsonObject, type OpenUrlRequest, type PlatformAudioAdapter, type PlatformNotification, type PlatformSecureTokenStore, type PlatformUrlOpener, RealtimeFunctionToolDefinition, type RelayHttpClient, type RelayRequest, type RelayResponse, VoiceEvent, VoiceProvider, VoiceProviderConnectOptions, VoiceSession, VoiceSessionConfig, type VoiceSessionControllerOptions, VoiceSessionMetadata, VoiceTool, VoiceToolCall, VoiceToolContext, VoiceToolResult, type VoiceToolSource, VoiceTransport, agentToolToVoiceTool, createInMemoryVoiceProvider, createVoiceSession, executeVoiceToolCall, ggAiToolToRealtimeFunctionTool, ggAiToolToVoiceTool, normalizeVoiceProviderError, voiceToolToRealtimeFunctionTool };
|