@runappsai/sdk 0.6.10 → 0.7.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/README.md +36 -2
- package/dist/audio.d.ts +7 -1
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +6 -0
- package/dist/audio.js.map +1 -1
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +4 -0
- package/dist/client.js.map +1 -1
- package/dist/events.d.ts +2 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/realtime.d.ts +144 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +364 -0
- package/dist/realtime.js.map +1 -0
- package/dist/sdk.umd.js +3 -3
- package/dist/sdk.umd.js.map +1 -1
- package/dist/transport.d.ts +2 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -0
- package/dist/transport.js.map +1 -1
- package/package.json +1 -1
- package/src/audio.ts +12 -1
- package/src/client.ts +4 -0
- package/src/events.ts +2 -0
- package/src/index.ts +17 -0
- package/src/realtime.ts +457 -0
- package/src/transport.ts +5 -0
package/dist/transport.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export declare class Transport {
|
|
|
42
42
|
constructor(opts: TransportOptions);
|
|
43
43
|
/** Resolve the bearer token for the next request. */
|
|
44
44
|
private resolveToken;
|
|
45
|
+
/** The current bearer token, for connections fetch can't make (WebSocket). */
|
|
46
|
+
bearerToken(): Promise<string>;
|
|
45
47
|
/**
|
|
46
48
|
* Wrap a fetch call with single-attempt 401 retry. `build` produces a
|
|
47
49
|
* fresh RequestInit each call (so headers can re-resolve a fresh token,
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":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();
|
|
28
28
|
return this.apiKey ?? "";
|
|
29
29
|
}
|
|
30
|
+
/** The current bearer token, for connections fetch can't make (WebSocket). */
|
|
31
|
+
bearerToken() {
|
|
32
|
+
return this.resolveToken();
|
|
33
|
+
}
|
|
30
34
|
/**
|
|
31
35
|
* Wrap a fetch call with single-attempt 401 retry. `build` produces a
|
|
32
36
|
* fresh RequestInit each call (so headers can re-resolve a fresh token,
|
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAsCvC,MAAM,OAAO,SAAS;IACX,OAAO,CAAS;IACR,MAAM,CAAqB;IAC3B,cAAc,CAA+C;IAC7D,cAAc,CAA2C;IACzD,SAAS,CAAe;IAEzC,YAAY,IAAsB;QAChC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,6DAA6D;QAC7D,6DAA6D;QAC7D,wDAAwD;QACxD,yDAAyD;QACzD,kEAAkE;QAClE,uCAAuC;QACvC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5D,CAAC;IAED,qDAAqD;IAC7C,KAAK,CAAC,YAAY;QACxB,IAAI,IAAI,CAAC,cAAc;YA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CAAC"}
|
package/package.json
CHANGED
package/src/audio.ts
CHANGED
|
@@ -82,7 +82,13 @@ export interface AudioFileInput {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export interface TranscribeParams {
|
|
85
|
-
|
|
85
|
+
/** The audio to transcribe. Either this or `url`. */
|
|
86
|
+
file?: AudioFileInput;
|
|
87
|
+
/**
|
|
88
|
+
* A public URL of the audio, instead of uploading it — for models that
|
|
89
|
+
* fetch audio themselves (e.g. "Doubao ASR 2.0"); no upload size limit.
|
|
90
|
+
*/
|
|
91
|
+
url?: string;
|
|
86
92
|
language?: string;
|
|
87
93
|
prompt?: string;
|
|
88
94
|
response_format?: string;
|
|
@@ -409,6 +415,11 @@ function buildTranscribeForm(model: string, params: TranscribeParams): FormData
|
|
|
409
415
|
}
|
|
410
416
|
if (params.user) form.set("user", params.user);
|
|
411
417
|
|
|
418
|
+
if (!params.file) {
|
|
419
|
+
if (!params.url) throw new Error("runapps: transcribe needs `file` or `url`");
|
|
420
|
+
form.set("url", params.url);
|
|
421
|
+
return form;
|
|
422
|
+
}
|
|
412
423
|
const ct = params.file.contentType ?? guessAudioMime(params.file.filename);
|
|
413
424
|
const blob =
|
|
414
425
|
params.file.data instanceof Blob
|
package/src/client.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ChatService } from "./chat.js";
|
|
|
3
3
|
import { ModelsService } from "./models.js";
|
|
4
4
|
import { ImageService } from "./image.js";
|
|
5
5
|
import { AudioService } from "./audio.js";
|
|
6
|
+
import { RealtimeService } from "./realtime.js";
|
|
6
7
|
import { VideoService } from "./video.js";
|
|
7
8
|
import { ComputerService } from "./computer.js";
|
|
8
9
|
import { FilesService } from "./files.js";
|
|
@@ -140,6 +141,8 @@ export class RunApps {
|
|
|
140
141
|
readonly computer: ComputerService;
|
|
141
142
|
readonly files: FilesService;
|
|
142
143
|
readonly embeddings: EmbeddingsService;
|
|
144
|
+
/** Realtime voice sessions over WebSocket — see `RealtimeService.connect`. */
|
|
145
|
+
readonly realtime: RealtimeService;
|
|
143
146
|
|
|
144
147
|
/**
|
|
145
148
|
* Browser auth helper, populated only when `authProvider: "runapps"`.
|
|
@@ -250,6 +253,7 @@ export class RunApps {
|
|
|
250
253
|
// legacy unscoped /v1/files/... paths.
|
|
251
254
|
this.files = new FilesService(transport, options.project, this.events);
|
|
252
255
|
this.embeddings = new EmbeddingsService(transport, this.events);
|
|
256
|
+
this.realtime = new RealtimeService(transport, this.events);
|
|
253
257
|
|
|
254
258
|
// Sync: an app on RunApps gets it unless it says no. It
|
|
255
259
|
// stores under the signed-in user, so only browser sign-in mode has
|
package/src/events.ts
CHANGED
|
@@ -33,6 +33,8 @@ export type SDKCapability =
|
|
|
33
33
|
| "speech_to_text"
|
|
34
34
|
| "video_generation"
|
|
35
35
|
| "computer_use"
|
|
36
|
+
/** A realtime voice session (`client.realtime`). */
|
|
37
|
+
| "realtime"
|
|
36
38
|
/** A file-space call (`client.files`). Shown on the badge while in
|
|
37
39
|
* flight and on failure, but not listed or charged per call. */
|
|
38
40
|
| "files";
|
package/src/index.ts
CHANGED
|
@@ -126,6 +126,23 @@ export type {
|
|
|
126
126
|
AudioFileInput,
|
|
127
127
|
} from "./audio.js";
|
|
128
128
|
|
|
129
|
+
// Realtime voice
|
|
130
|
+
export type {
|
|
131
|
+
RealtimeEvent,
|
|
132
|
+
RealtimeUsage,
|
|
133
|
+
RealtimeCloseInfo,
|
|
134
|
+
RealtimeConnectOptions,
|
|
135
|
+
WebSocketLike,
|
|
136
|
+
WebSocketConstructor,
|
|
137
|
+
} from "./realtime.js";
|
|
138
|
+
export {
|
|
139
|
+
RealtimeSession,
|
|
140
|
+
pcm16FromFloat32,
|
|
141
|
+
float32FromPCM16,
|
|
142
|
+
bytesToBase64,
|
|
143
|
+
base64ToBytes,
|
|
144
|
+
} from "./realtime.js";
|
|
145
|
+
|
|
129
146
|
// Video
|
|
130
147
|
export type {
|
|
131
148
|
VideoGenerateParams,
|
package/src/realtime.ts
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { newRequestId, type SDKEvents } from "./events.js";
|
|
2
|
+
import type { Transport } from "./transport.js";
|
|
3
|
+
|
|
4
|
+
/* ------------------------------------------------------------------ */
|
|
5
|
+
/* Realtime voice */
|
|
6
|
+
/* ------------------------------------------------------------------ */
|
|
7
|
+
/*
|
|
8
|
+
* `client.realtime.connect()` opens a full-duplex voice session over a
|
|
9
|
+
* WebSocket to `/v1/realtime`: stream microphone audio up, get the
|
|
10
|
+
* model's transcripts, text and spoken reply back as they happen, and
|
|
11
|
+
* interrupt it mid-sentence.
|
|
12
|
+
*
|
|
13
|
+
* The wire protocol is the realtime model's own. For the Doubao realtime
|
|
14
|
+
* model it is Realtime-style JSON events, one per frame:
|
|
15
|
+
*
|
|
16
|
+
* → session.create / session.update (connect() sends the first one)
|
|
17
|
+
* → input_audio_buffer.append {audio: base64 PCM16, 16 kHz mono}
|
|
18
|
+
* → speech_text_buffer.commit {text} — have the model say this
|
|
19
|
+
* → response.cancel interrupt the reply
|
|
20
|
+
* → session.close (close() sends it)
|
|
21
|
+
* ← session.created
|
|
22
|
+
* ← conversation.item.input_audio_transcription.delta / .completed (what the user said)
|
|
23
|
+
* ← response.output_text.delta / .done (what the model says)
|
|
24
|
+
* ← response.output_audio.delta {delta: base64 PCM16, 24 kHz mono by default}
|
|
25
|
+
* ← response.done one turn finished, with token usage
|
|
26
|
+
* ← error
|
|
27
|
+
* ← session.closed
|
|
28
|
+
* ← gateway.usage the session's cost, just before the socket closes
|
|
29
|
+
*
|
|
30
|
+
* Audio input must arrive at real-time pace (send ~20 ms chunks as they
|
|
31
|
+
* are captured); the model also expects a steady stream, so keep sending
|
|
32
|
+
* silence — or `mute()` — while the microphone is off.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** One protocol event. `type` names it; the rest depends on the event. */
|
|
36
|
+
export interface RealtimeEvent {
|
|
37
|
+
type: string;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What a realtime session cost, from the closing `gateway.usage` event. */
|
|
42
|
+
export interface RealtimeUsage {
|
|
43
|
+
input_tokens?: number;
|
|
44
|
+
output_tokens?: number;
|
|
45
|
+
/** Session length in seconds. */
|
|
46
|
+
seconds?: number;
|
|
47
|
+
/** USD. */
|
|
48
|
+
total_cost?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** How a session ended. */
|
|
52
|
+
export interface RealtimeCloseInfo {
|
|
53
|
+
/** WebSocket close code: 1000 when the session completed; 4402 when the
|
|
54
|
+
* spending cap was reached (`maxCost`, or the account's balance); 4000+N
|
|
55
|
+
* for an upstream HTTP error N (e.g. 4429); 4408 idle or over-long session. */
|
|
56
|
+
code: number;
|
|
57
|
+
reason: string;
|
|
58
|
+
/** Null when the session ended before the cost could be reported. */
|
|
59
|
+
usage: RealtimeUsage | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The subset of the WHATWG WebSocket the SDK uses (also what `ws` provides). */
|
|
63
|
+
export interface WebSocketLike {
|
|
64
|
+
readonly readyState: number;
|
|
65
|
+
send(data: string): void;
|
|
66
|
+
close(code?: number, reason?: string): void;
|
|
67
|
+
addEventListener(type: string, listener: (ev: any) => void): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type WebSocketConstructor = new (url: string, protocols?: string | string[]) => WebSocketLike;
|
|
71
|
+
|
|
72
|
+
export interface RealtimeConnectOptions {
|
|
73
|
+
/** Realtime model name (e.g. "Doubao Realtime Voice"); omit for the platform default. */
|
|
74
|
+
model?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Session settings sent in the opening `session.create`, e.g.
|
|
77
|
+
* `{ instructions: "...", audio: { output: { voice: "zh_female_vv_jupiter_bigtts" } } }`.
|
|
78
|
+
*/
|
|
79
|
+
session?: Record<string, unknown>;
|
|
80
|
+
/** Model-specific extension block (Doubao: `{ asr, tts, dialog }`). */
|
|
81
|
+
extension?: Record<string, unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* End the session (close code 4402) once it has cost this many USD. The
|
|
84
|
+
* account's remaining balance always caps a session; this sets a lower
|
|
85
|
+
* cap. Checked after each turn, so the last turn may go slightly over.
|
|
86
|
+
*/
|
|
87
|
+
maxCost?: number;
|
|
88
|
+
/** Extra query parameters for the handshake. */
|
|
89
|
+
query?: Record<string, string>;
|
|
90
|
+
/**
|
|
91
|
+
* WebSocket implementation. Defaults to the global `WebSocket` (browsers,
|
|
92
|
+
* Node 22+, Deno, Bun); on older Node pass the `ws` package's export.
|
|
93
|
+
*/
|
|
94
|
+
WebSocket?: WebSocketConstructor;
|
|
95
|
+
/** Give up if the session isn't open within this long (default 15 s). */
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type Handler = (event: RealtimeEvent) => void;
|
|
101
|
+
|
|
102
|
+
const OPEN = 1;
|
|
103
|
+
const CLOSE_TIMEOUT_MS = 10_000;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A live realtime session. Listen with `on(type, handler)` (or iterate
|
|
107
|
+
* it with `for await`), talk with `appendAudio()` / `say()`, and end it
|
|
108
|
+
* with `close()`.
|
|
109
|
+
*/
|
|
110
|
+
export class RealtimeSession {
|
|
111
|
+
/** The upstream session id (from `session.created`); pass it as
|
|
112
|
+
* `session.id` to a later session to continue the conversation. */
|
|
113
|
+
sessionId = "";
|
|
114
|
+
/** Settles when the socket closes, however that happens. */
|
|
115
|
+
readonly closed: Promise<RealtimeCloseInfo>;
|
|
116
|
+
|
|
117
|
+
private readonly handlers = new Map<string, Set<Handler>>();
|
|
118
|
+
private usage: RealtimeUsage | null = null;
|
|
119
|
+
private resolveClosed!: (info: RealtimeCloseInfo) => void;
|
|
120
|
+
private isClosed = false;
|
|
121
|
+
private queue: RealtimeEvent[] = [];
|
|
122
|
+
private waiters: ((r: IteratorResult<RealtimeEvent>) => void)[] = [];
|
|
123
|
+
private iterating = false;
|
|
124
|
+
|
|
125
|
+
/** @internal */
|
|
126
|
+
constructor(private readonly ws: WebSocketLike) {
|
|
127
|
+
this.closed = new Promise((resolve) => {
|
|
128
|
+
this.resolveClosed = resolve;
|
|
129
|
+
});
|
|
130
|
+
ws.addEventListener("message", (ev: { data: unknown }) => {
|
|
131
|
+
if (typeof ev.data !== "string") return;
|
|
132
|
+
let event: RealtimeEvent;
|
|
133
|
+
try {
|
|
134
|
+
event = JSON.parse(ev.data) as RealtimeEvent;
|
|
135
|
+
} catch {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!event || typeof event.type !== "string") return;
|
|
139
|
+
if (event.type === "session.created") {
|
|
140
|
+
const id = (event.session as { id?: unknown } | undefined)?.id;
|
|
141
|
+
if (typeof id === "string") this.sessionId = id;
|
|
142
|
+
} else if (event.type === "gateway.usage") {
|
|
143
|
+
this.usage = (event.usage as RealtimeUsage) ?? null;
|
|
144
|
+
}
|
|
145
|
+
this.dispatch(event);
|
|
146
|
+
});
|
|
147
|
+
ws.addEventListener("close", (ev: { code?: number; reason?: string }) => {
|
|
148
|
+
if (this.isClosed) return;
|
|
149
|
+
this.isClosed = true;
|
|
150
|
+
for (const w of this.waiters.splice(0)) w({ value: undefined, done: true });
|
|
151
|
+
this.resolveClosed({ code: ev.code ?? 1006, reason: ev.reason ?? "", usage: this.usage });
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Subscribe to events of one type, or `"*"` for all of them. Returns
|
|
157
|
+
* the unsubscribe function.
|
|
158
|
+
*/
|
|
159
|
+
on(type: string, handler: Handler): () => void {
|
|
160
|
+
let set = this.handlers.get(type);
|
|
161
|
+
if (!set) {
|
|
162
|
+
set = new Set();
|
|
163
|
+
this.handlers.set(type, set);
|
|
164
|
+
}
|
|
165
|
+
set.add(handler);
|
|
166
|
+
return () => set!.delete(handler);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Send a raw protocol event. */
|
|
170
|
+
send(event: RealtimeEvent): void {
|
|
171
|
+
if (this.ws.readyState !== OPEN) throw new Error("runapps: realtime session is closed");
|
|
172
|
+
this.ws.send(JSON.stringify(event));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Stream a chunk of microphone audio: 16-bit little-endian PCM, 16 kHz
|
|
177
|
+
* mono (`pcm16FromFloat32` converts Web Audio samples). Send ~20 ms
|
|
178
|
+
* (640 bytes) at a time, as it is captured.
|
|
179
|
+
*/
|
|
180
|
+
appendAudio(pcm16: Int16Array | Uint8Array | ArrayBuffer): void {
|
|
181
|
+
this.send({ type: "input_audio_buffer.append", audio: bytesToBase64(asBytes(pcm16)) });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Tell the model the user has finished speaking (skips end-of-speech detection). */
|
|
185
|
+
commitAudio(): void {
|
|
186
|
+
this.send({ type: "input_audio_buffer.commit" });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The microphone is off: stops the model waiting on audio. */
|
|
190
|
+
mute(): void {
|
|
191
|
+
this.send({ type: "input_audio_mute.commit" });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The microphone is back on. */
|
|
195
|
+
unmute(): void {
|
|
196
|
+
this.send({ type: "input_audio_unmute.commit" });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Have the model speak `text` (a greeting, or a scripted line). */
|
|
200
|
+
say(text: string): void {
|
|
201
|
+
this.send({ type: "speech_text_buffer.commit", text });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Interrupt the model's current reply. */
|
|
205
|
+
cancelResponse(): void {
|
|
206
|
+
this.send({ type: "response.cancel" });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Change session settings mid-session (instructions, voice, tools, …). */
|
|
210
|
+
update(session: Record<string, unknown>): void {
|
|
211
|
+
this.send({ type: "session.update", session });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Answer a `response.function_call_arguments.done` tool call. */
|
|
215
|
+
sendFunctionResult(callId: string, output: string): void {
|
|
216
|
+
this.send({
|
|
217
|
+
type: "conversation.item.create",
|
|
218
|
+
items: [{ call_id: callId, role: "tool", content: [{ type: "input_text", text: output }] }],
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* End the session: asks the model to close, waits for the server to
|
|
224
|
+
* hang up (so the closing `gateway.usage` arrives), and resolves with
|
|
225
|
+
* how it ended, including the cost.
|
|
226
|
+
*/
|
|
227
|
+
async close(): Promise<RealtimeCloseInfo> {
|
|
228
|
+
if (!this.isClosed && this.ws.readyState === OPEN) {
|
|
229
|
+
try {
|
|
230
|
+
this.send({ type: "session.close" });
|
|
231
|
+
} catch {
|
|
232
|
+
// already closing
|
|
233
|
+
}
|
|
234
|
+
const timer = setTimeout(() => this.ws.close(1000, "client timeout"), CLOSE_TIMEOUT_MS);
|
|
235
|
+
try {
|
|
236
|
+
return await this.closed;
|
|
237
|
+
} finally {
|
|
238
|
+
clearTimeout(timer);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!this.isClosed) this.ws.close(1000);
|
|
242
|
+
return this.closed;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Iterate events until the session closes. */
|
|
246
|
+
[Symbol.asyncIterator](): AsyncIterator<RealtimeEvent> {
|
|
247
|
+
this.iterating = true;
|
|
248
|
+
return {
|
|
249
|
+
next: () => {
|
|
250
|
+
const event = this.queue.shift();
|
|
251
|
+
if (event) return Promise.resolve({ value: event, done: false });
|
|
252
|
+
if (this.isClosed) return Promise.resolve({ value: undefined, done: true });
|
|
253
|
+
return new Promise((resolve) => this.waiters.push(resolve));
|
|
254
|
+
},
|
|
255
|
+
return: () => {
|
|
256
|
+
this.iterating = false;
|
|
257
|
+
this.queue = [];
|
|
258
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private dispatch(event: RealtimeEvent): void {
|
|
264
|
+
for (const type of [event.type, "*"]) {
|
|
265
|
+
const set = this.handlers.get(type);
|
|
266
|
+
if (!set) continue;
|
|
267
|
+
for (const h of [...set]) {
|
|
268
|
+
try {
|
|
269
|
+
h(event);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
// A broken handler must not stop the others or the session.
|
|
272
|
+
setTimeout(() => {
|
|
273
|
+
throw err;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (this.iterating) {
|
|
279
|
+
const w = this.waiters.shift();
|
|
280
|
+
if (w) w({ value: event, done: false });
|
|
281
|
+
else this.queue.push(event);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export class RealtimeService {
|
|
287
|
+
constructor(
|
|
288
|
+
private readonly transport: Transport,
|
|
289
|
+
private readonly events: SDKEvents,
|
|
290
|
+
) {}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Open a realtime voice session. Resolves once the model has accepted
|
|
294
|
+
* it (`session.created`); rejects if the connection fails first.
|
|
295
|
+
*/
|
|
296
|
+
async connect(options: RealtimeConnectOptions = {}): Promise<RealtimeSession> {
|
|
297
|
+
const WS = options.WebSocket ?? (globalThis as { WebSocket?: WebSocketConstructor }).WebSocket;
|
|
298
|
+
if (!WS) {
|
|
299
|
+
throw new Error("runapps: no WebSocket available — pass `WebSocket` (e.g. from the `ws` package) on Node < 22");
|
|
300
|
+
}
|
|
301
|
+
const token = await this.transport.bearerToken();
|
|
302
|
+
const ws = new WS(realtimeURL(this.transport.baseURL, options), ["realtime", "runapps-key." + token]);
|
|
303
|
+
const session = new RealtimeSession(ws);
|
|
304
|
+
const model = options.model ?? "";
|
|
305
|
+
const id = newRequestId();
|
|
306
|
+
const startedAt = Date.now();
|
|
307
|
+
this.events.emit("request:start", { id, model, capability: "realtime", startedAt, streaming: true });
|
|
308
|
+
|
|
309
|
+
try {
|
|
310
|
+
await new Promise<void>((resolve, reject) => {
|
|
311
|
+
const timer = setTimeout(() => {
|
|
312
|
+
fail(new Error("runapps: realtime session did not open in time"));
|
|
313
|
+
ws.close(1000, "open timeout");
|
|
314
|
+
}, options.timeoutMs ?? 15_000);
|
|
315
|
+
const onAbort = () => {
|
|
316
|
+
fail(new Error("runapps: realtime connect aborted"));
|
|
317
|
+
ws.close(1000, "aborted");
|
|
318
|
+
};
|
|
319
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
320
|
+
let settled = false;
|
|
321
|
+
function fail(err: Error) {
|
|
322
|
+
if (settled) return;
|
|
323
|
+
settled = true;
|
|
324
|
+
clearTimeout(timer);
|
|
325
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
326
|
+
reject(err);
|
|
327
|
+
}
|
|
328
|
+
const offCreated = session.on("session.created", () => {
|
|
329
|
+
if (settled) return;
|
|
330
|
+
settled = true;
|
|
331
|
+
clearTimeout(timer);
|
|
332
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
333
|
+
offCreated();
|
|
334
|
+
offError();
|
|
335
|
+
resolve();
|
|
336
|
+
});
|
|
337
|
+
// An error before the session opens is fatal to connect().
|
|
338
|
+
const offError = session.on("error", (ev) => {
|
|
339
|
+
const e = (ev.error ?? {}) as { message?: string; code?: unknown };
|
|
340
|
+
fail(new Error(`runapps: realtime error: ${e.message ?? JSON.stringify(ev)}`));
|
|
341
|
+
});
|
|
342
|
+
ws.addEventListener("open", () => {
|
|
343
|
+
ws.send(JSON.stringify(openingEvent(options)));
|
|
344
|
+
});
|
|
345
|
+
void session.closed.then((info) => {
|
|
346
|
+
// A refused handshake (bad key, unknown model, low balance) reaches
|
|
347
|
+
// a WebSocket client only as 1006 — the HTTP status is hidden.
|
|
348
|
+
const hint = info.code === 1006 ? " — check the API key, the model name and the account balance" : "";
|
|
349
|
+
fail(new Error(`runapps: realtime connection closed (${info.code}${info.reason ? " " + info.reason : ""})${hint}`));
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
} catch (err) {
|
|
353
|
+
try {
|
|
354
|
+
ws.close(1000, "connect failed");
|
|
355
|
+
} catch {
|
|
356
|
+
// already closed
|
|
357
|
+
}
|
|
358
|
+
this.events.emit("request:error", {
|
|
359
|
+
id,
|
|
360
|
+
model,
|
|
361
|
+
capability: "realtime",
|
|
362
|
+
latencyMs: Date.now() - startedAt,
|
|
363
|
+
error: err as Error,
|
|
364
|
+
});
|
|
365
|
+
throw err;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
void session.closed.then((info) => {
|
|
369
|
+
this.events.emit("request:end", {
|
|
370
|
+
id,
|
|
371
|
+
model,
|
|
372
|
+
capability: "realtime",
|
|
373
|
+
latencyMs: Date.now() - startedAt,
|
|
374
|
+
totalTokens: info.usage?.output_tokens ?? 0,
|
|
375
|
+
...(info.usage?.total_cost !== undefined && { costUSD: info.usage.total_cost }),
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
return session;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function openingEvent(options: RealtimeConnectOptions): RealtimeEvent {
|
|
383
|
+
const event: RealtimeEvent = { type: "session.create", session: options.session ?? {} };
|
|
384
|
+
if (options.extension) event.extension = options.extension;
|
|
385
|
+
return event;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function realtimeURL(baseURL: string, options: RealtimeConnectOptions): string {
|
|
389
|
+
const u = new URL(baseURL.replace(/\/+$/, "") + "/v1/realtime");
|
|
390
|
+
u.protocol = u.protocol === "http:" ? "ws:" : "wss:";
|
|
391
|
+
for (const [k, v] of Object.entries(options.query ?? {})) u.searchParams.set(k, v);
|
|
392
|
+
if (options.model) u.searchParams.set("model", options.model);
|
|
393
|
+
if (options.maxCost !== undefined && options.maxCost > 0) u.searchParams.set("max_cost", String(options.maxCost));
|
|
394
|
+
return u.toString();
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* ------------------------------------------------------------------ */
|
|
398
|
+
/* PCM helpers */
|
|
399
|
+
/* ------------------------------------------------------------------ */
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Convert Web Audio samples (Float32, -1…1) at `sampleRate` to 16-bit PCM
|
|
403
|
+
* at `targetRate` (16 kHz, what realtime input expects), resampling
|
|
404
|
+
* linearly when the rates differ.
|
|
405
|
+
*/
|
|
406
|
+
export function pcm16FromFloat32(samples: Float32Array, sampleRate: number, targetRate = 16000): Int16Array {
|
|
407
|
+
const ratio = sampleRate / targetRate;
|
|
408
|
+
const n = ratio === 1 ? samples.length : Math.floor(samples.length / ratio);
|
|
409
|
+
const out = new Int16Array(n);
|
|
410
|
+
for (let i = 0; i < n; i++) {
|
|
411
|
+
let s: number;
|
|
412
|
+
if (ratio === 1) {
|
|
413
|
+
s = samples[i]!;
|
|
414
|
+
} else {
|
|
415
|
+
const pos = i * ratio;
|
|
416
|
+
const j = Math.floor(pos);
|
|
417
|
+
const frac = pos - j;
|
|
418
|
+
const a = samples[j]!;
|
|
419
|
+
const b = samples[Math.min(j + 1, samples.length - 1)]!;
|
|
420
|
+
s = a + (b - a) * frac;
|
|
421
|
+
}
|
|
422
|
+
s = Math.max(-1, Math.min(1, s));
|
|
423
|
+
out[i] = s < 0 ? s * 0x8000 : s * 0x7fff;
|
|
424
|
+
}
|
|
425
|
+
return out;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** Convert 16-bit little-endian PCM bytes (e.g. a decoded audio delta) to Float32 samples for Web Audio. */
|
|
429
|
+
export function float32FromPCM16(bytes: Uint8Array): Float32Array {
|
|
430
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
431
|
+
const out = new Float32Array(bytes.byteLength >> 1);
|
|
432
|
+
for (let i = 0; i < out.length; i++) out[i] = view.getInt16(i * 2, true) / 0x8000;
|
|
433
|
+
return out;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Base64-encode bytes (audio for `input_audio_buffer.append`). */
|
|
437
|
+
export function bytesToBase64(bytes: Uint8Array): string {
|
|
438
|
+
let bin = "";
|
|
439
|
+
for (let i = 0; i < bytes.length; i += 0x8000) {
|
|
440
|
+
bin += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
441
|
+
}
|
|
442
|
+
return btoa(bin);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Decode base64 (e.g. `response.output_audio.delta`'s `delta`) to bytes. */
|
|
446
|
+
export function base64ToBytes(b64: string): Uint8Array {
|
|
447
|
+
const bin = atob(b64);
|
|
448
|
+
const out = new Uint8Array(bin.length);
|
|
449
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
450
|
+
return out;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function asBytes(v: Int16Array | Uint8Array | ArrayBuffer): Uint8Array {
|
|
454
|
+
if (v instanceof Uint8Array) return v;
|
|
455
|
+
if (v instanceof ArrayBuffer) return new Uint8Array(v);
|
|
456
|
+
return new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
|
|
457
|
+
}
|
package/src/transport.ts
CHANGED
|
@@ -68,6 +68,11 @@ export class Transport {
|
|
|
68
68
|
return this.apiKey ?? "";
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/** The current bearer token, for connections fetch can't make (WebSocket). */
|
|
72
|
+
bearerToken(): Promise<string> {
|
|
73
|
+
return this.resolveToken();
|
|
74
|
+
}
|
|
75
|
+
|
|
71
76
|
/**
|
|
72
77
|
* Wrap a fetch call with single-attempt 401 retry. `build` produces a
|
|
73
78
|
* fresh RequestInit each call (so headers can re-resolve a fresh token,
|