@cartanova/qgrid-cli 2.19.3 → 2.21.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/bundle/dist/application/qgrid/qgrid.types.js +75 -2
- package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +19 -51
- package/bundle/dist/utils/providers/openai/openai-voice-client.js +1 -1
- package/bundle/src/application/qgrid/qgrid.types.ts +72 -0
- package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +26 -53
- package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +6 -2
- package/bundle/web-dist/client/assets/TimedPlayer-UGSsgTKj.js +1 -0
- package/bundle/web-dist/client/assets/{index-CpOwNalw.css → index-BITKCBxB.css} +1 -1
- package/bundle/web-dist/client/assets/{index-B5yorZqv.js → index-NGqKa5_C.js} +14 -14
- package/bundle/web-dist/client/assets/{logs-Bx_jXEDZ.js → logs-BLhlxqoB.js} +1 -1
- package/bundle/web-dist/client/assets/{monit-CPQ18s_m.js → monit-C3stGFEK.js} +1 -1
- package/bundle/web-dist/client/assets/{routes-S4D5Ld4L.js → routes-Dgh-_yS5.js} +1 -1
- package/bundle/web-dist/client/assets/{settings-M4h_UV87.js → settings-DiOZwvRj.js} +1 -1
- package/bundle/web-dist/client/assets/show-DucEoTrr.js +2 -0
- package/bundle/web-dist/client/assets/{tokens-BgBD07ru.js → tokens-DvCT1bbk.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-D_wI9MzM.js → use-oauth-login-flow-DazQfaBL.js} +1 -1
- package/bundle/web-dist/client/assets/{use-update-token-mutation-IvuH3Qje.js → use-update-token-mutation-CfGbUel6.js} +1 -1
- package/bundle/web-dist/client/assets/voice-zPre2iO8.js +4 -0
- package/bundle/web-dist/client/index.html +2 -2
- package/bundle/web-dist/server/assets/TimedPlayer-CcClBzGi.js +193 -0
- package/bundle/web-dist/server/assets/{logs-HPho1SkC.js → logs-CxAwuDKc.js} +1 -1
- package/bundle/web-dist/server/assets/{routes-BNHCX4VI.js → routes-W-pd1Hps.js} +1 -1
- package/bundle/web-dist/server/assets/{settings-NJUyaSrJ.js → settings-CFdTg1_f.js} +1 -1
- package/bundle/web-dist/server/assets/{show-Dz5QGL7l.js → show-DVEIHsXh.js} +35 -157
- package/bundle/web-dist/server/assets/{tokens-BPQvjIGq.js → tokens-BO1hyBuB.js} +1 -1
- package/bundle/web-dist/server/assets/voice-BCF-Pkzo.js +1115 -0
- package/bundle/web-dist/server/entry-server.generated.js +81 -8
- package/package.json +1 -1
- package/skills/qgrid/references/ai-sdk-provider-contract.md +4 -0
- package/skills/qgrid/references/openai-codex-runtime.md +1 -0
- package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
- package/bundle/web-dist/client/assets/TimedPlayer-cuEgYA3Q.js +0 -1
- package/bundle/web-dist/client/assets/show-BchF-T1a.js +0 -2
- package/bundle/web-dist/client/assets/voice-CnIiQMbo.js +0 -1
- package/bundle/web-dist/server/assets/TimedPlayer-COqaTQSl.js +0 -54
- package/bundle/web-dist/server/assets/voice-xFFT4zqK.js +0 -985
|
@@ -1,985 +0,0 @@
|
|
|
1
|
-
import { C as looseObject, D as string, X as require_jsx_runtime, Z as require_react, n as QgridService, tt as __toESM } from "./services.generated-C3b31_vt.js";
|
|
2
|
-
import { _ as Link, c as ForwardRef$4, l as ForwardRef$5, m as VOICE_TAB_TITLES, n as Route, o as Effort, p as VOICE_TAB_IDS, s as QGRID_MODEL_GROUPS } from "../entry-server.generated.js";
|
|
3
|
-
import { t as TimedPlayer } from "./TimedPlayer-COqaTQSl.js";
|
|
4
|
-
//#region ~icons/lucide/external-link.jsx
|
|
5
|
-
var import_react = /* @__PURE__ */ __toESM(require_react());
|
|
6
|
-
var import_jsx_runtime = require_jsx_runtime();
|
|
7
|
-
var lucideExternalLink = ({ title, titleId, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
|
|
8
|
-
viewBox: "0 0 24 24",
|
|
9
|
-
width: "1.2em",
|
|
10
|
-
height: "1.2em",
|
|
11
|
-
ref,
|
|
12
|
-
"aria-labelledby": titleId,
|
|
13
|
-
...props,
|
|
14
|
-
children: [title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", {
|
|
15
|
-
id: titleId,
|
|
16
|
-
children: title
|
|
17
|
-
}) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
|
|
18
|
-
fill: "none",
|
|
19
|
-
stroke: "currentColor",
|
|
20
|
-
strokeLinecap: "round",
|
|
21
|
-
strokeLinejoin: "round",
|
|
22
|
-
strokeWidth: 2,
|
|
23
|
-
d: "M15 3h6v6m-11 5L21 3m-3 10v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
|
|
24
|
-
})]
|
|
25
|
-
});
|
|
26
|
-
var ForwardRef$3 = (0, import_react.forwardRef)(lucideExternalLink);
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region ~icons/lucide/loader-circle.jsx
|
|
29
|
-
var lucideLoaderCircle = ({ title, titleId, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
|
|
30
|
-
viewBox: "0 0 24 24",
|
|
31
|
-
width: "1.2em",
|
|
32
|
-
height: "1.2em",
|
|
33
|
-
ref,
|
|
34
|
-
"aria-labelledby": titleId,
|
|
35
|
-
...props,
|
|
36
|
-
children: [title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", {
|
|
37
|
-
id: titleId,
|
|
38
|
-
children: title
|
|
39
|
-
}) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
|
|
40
|
-
fill: "none",
|
|
41
|
-
stroke: "currentColor",
|
|
42
|
-
strokeLinecap: "round",
|
|
43
|
-
strokeLinejoin: "round",
|
|
44
|
-
strokeWidth: 2,
|
|
45
|
-
d: "M21 12a9 9 0 1 1-6.219-8.56"
|
|
46
|
-
})]
|
|
47
|
-
});
|
|
48
|
-
var ForwardRef$2 = (0, import_react.forwardRef)(lucideLoaderCircle);
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region ~icons/lucide/mic.jsx
|
|
51
|
-
var lucideMic = ({ title, titleId, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
|
|
52
|
-
viewBox: "0 0 24 24",
|
|
53
|
-
width: "1.2em",
|
|
54
|
-
height: "1.2em",
|
|
55
|
-
ref,
|
|
56
|
-
"aria-labelledby": titleId,
|
|
57
|
-
...props,
|
|
58
|
-
children: [title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", {
|
|
59
|
-
id: titleId,
|
|
60
|
-
children: title
|
|
61
|
-
}) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", {
|
|
62
|
-
fill: "none",
|
|
63
|
-
stroke: "currentColor",
|
|
64
|
-
strokeLinecap: "round",
|
|
65
|
-
strokeLinejoin: "round",
|
|
66
|
-
strokeWidth: 2,
|
|
67
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 19v3m7-12v2a7 7 0 0 1-14 0v-2" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", {
|
|
68
|
-
width: 6,
|
|
69
|
-
height: 13,
|
|
70
|
-
x: 9,
|
|
71
|
-
y: 2,
|
|
72
|
-
rx: 3
|
|
73
|
-
})]
|
|
74
|
-
})]
|
|
75
|
-
});
|
|
76
|
-
var ForwardRef$1 = (0, import_react.forwardRef)(lucideMic);
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region ~icons/lucide/play.jsx
|
|
79
|
-
var lucidePlay = ({ title, titleId, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", {
|
|
80
|
-
viewBox: "0 0 24 24",
|
|
81
|
-
width: "1.2em",
|
|
82
|
-
height: "1.2em",
|
|
83
|
-
ref,
|
|
84
|
-
"aria-labelledby": titleId,
|
|
85
|
-
...props,
|
|
86
|
-
children: [title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", {
|
|
87
|
-
id: titleId,
|
|
88
|
-
children: title
|
|
89
|
-
}) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
|
|
90
|
-
fill: "none",
|
|
91
|
-
stroke: "currentColor",
|
|
92
|
-
strokeLinecap: "round",
|
|
93
|
-
strokeLinejoin: "round",
|
|
94
|
-
strokeWidth: 2,
|
|
95
|
-
d: "M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"
|
|
96
|
-
})]
|
|
97
|
-
});
|
|
98
|
-
var ForwardRef = (0, import_react.forwardRef)(lucidePlay);
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/components/qgrid/voice-audio.ts
|
|
101
|
-
var VOICE_SAMPLE_RATE = 24e3;
|
|
102
|
-
/** Mono PCM16 WAV from float samples in [-1, 1]; out-of-range samples are clipped. */
|
|
103
|
-
function encodeWav(samples, sampleRate = VOICE_SAMPLE_RATE) {
|
|
104
|
-
const out = new Uint8Array(44 + samples.length * 2);
|
|
105
|
-
const view = new DataView(out.buffer);
|
|
106
|
-
const ascii = (offset, text) => {
|
|
107
|
-
for (let i = 0; i < text.length; i++) view.setUint8(offset + i, text.charCodeAt(i));
|
|
108
|
-
};
|
|
109
|
-
ascii(0, "RIFF");
|
|
110
|
-
view.setUint32(4, 36 + samples.length * 2, true);
|
|
111
|
-
ascii(8, "WAVE");
|
|
112
|
-
ascii(12, "fmt ");
|
|
113
|
-
view.setUint32(16, 16, true);
|
|
114
|
-
view.setUint16(20, 1, true);
|
|
115
|
-
view.setUint16(22, 1, true);
|
|
116
|
-
view.setUint32(24, sampleRate, true);
|
|
117
|
-
view.setUint32(28, sampleRate * 2, true);
|
|
118
|
-
view.setUint16(32, 2, true);
|
|
119
|
-
view.setUint16(34, 16, true);
|
|
120
|
-
ascii(36, "data");
|
|
121
|
-
view.setUint32(40, samples.length * 2, true);
|
|
122
|
-
samples.forEach((sample, i) => {
|
|
123
|
-
const clipped = Math.max(-1, Math.min(1, sample));
|
|
124
|
-
view.setInt16(44 + i * 2, clipped < 0 ? clipped * 32768 : clipped * 32767, true);
|
|
125
|
-
});
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
function bytesToBase64(bytes) {
|
|
129
|
-
let binary = "";
|
|
130
|
-
for (let i = 0; i < bytes.length; i += 32768) binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
131
|
-
return btoa(binary);
|
|
132
|
-
}
|
|
133
|
-
/** Decodes any browser-playable audio, mixes it to mono at 24 kHz, and returns base64 WAV. */
|
|
134
|
-
async function audioToWavBase64(blob) {
|
|
135
|
-
const context = new AudioContext({ sampleRate: VOICE_SAMPLE_RATE });
|
|
136
|
-
try {
|
|
137
|
-
const buffer = await context.decodeAudioData(await blob.arrayBuffer());
|
|
138
|
-
const mono = new Float32Array(buffer.length);
|
|
139
|
-
for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
|
|
140
|
-
const data = buffer.getChannelData(channel);
|
|
141
|
-
for (let i = 0; i < data.length; i++) mono[i] += data[i] / buffer.numberOfChannels;
|
|
142
|
-
}
|
|
143
|
-
return bytesToBase64(encodeWav(mono));
|
|
144
|
-
} finally {
|
|
145
|
-
await context.close();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region src/components/qgrid/VoicePlayground.tsx
|
|
150
|
-
var PROJECT_NAME = "qgrid_voice_playground";
|
|
151
|
-
var TTS_MODELS = [
|
|
152
|
-
"grok/grok-tts",
|
|
153
|
-
"openai/gpt-realtime-2.1-mini",
|
|
154
|
-
"openai/gpt-realtime-2.1"
|
|
155
|
-
];
|
|
156
|
-
var STT_MODELS = [
|
|
157
|
-
"openai/gpt-4o-transcribe",
|
|
158
|
-
"openai/gpt-4o-mini-transcribe",
|
|
159
|
-
"grok/grok-voice-transcribe-2.0"
|
|
160
|
-
];
|
|
161
|
-
var OPENAI_VOICES = "marin cedar alloy ash ballad coral echo sage shimmer verse".split(" ");
|
|
162
|
-
var GROK_VOICE_GROUPS = [{
|
|
163
|
-
label: "Female",
|
|
164
|
-
voices: "ara aurora carina celeste eve iris liora luna ursa".split(" ")
|
|
165
|
-
}, {
|
|
166
|
-
label: "Male",
|
|
167
|
-
voices: "altair atlas castor cosmo helios helix kepler leo lumen lux naksh orion perseus rex rigel sal sirius zagan zenith".split(" ")
|
|
168
|
-
}];
|
|
169
|
-
var OPENAI_VOICE_GROUPS = [{
|
|
170
|
-
label: "",
|
|
171
|
-
voices: OPENAI_VOICES
|
|
172
|
-
}];
|
|
173
|
-
var TIMING_SOURCE = {
|
|
174
|
-
provider: "timing from Grok TTS",
|
|
175
|
-
aligned: "timing from qgrid aligner"
|
|
176
|
-
};
|
|
177
|
-
var isOpenAI = (model) => model.startsWith("openai/");
|
|
178
|
-
var FIELD = "w-full rounded-lg border border-sand-200/80 bg-white px-2.5 py-1.5 text-[12px] text-sand-800 placeholder:text-sand-400 focus:outline-none focus:border-sienna-300 disabled:opacity-50";
|
|
179
|
-
var CONTROL = `${FIELD} h-8`;
|
|
180
|
-
var BUTTON = "px-3.5 py-1.5 text-[12px] font-medium rounded-lg bg-sienna-500 text-white hover:bg-sienna-600 disabled:opacity-50 transition-all duration-150 active:scale-[0.97] inline-flex items-center gap-1.5 shadow-sm";
|
|
181
|
-
function Field({ label, children }) {
|
|
182
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
183
|
-
className: "flex flex-col gap-1",
|
|
184
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
185
|
-
className: "text-[11px] font-medium text-sand-500",
|
|
186
|
-
children: label
|
|
187
|
-
}), children]
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
var shortModel = (model) => model.slice(model.indexOf("/") + 1);
|
|
191
|
-
/**
|
|
192
|
-
* One past result. The request-log link opens a new tab so leaving the playground does not drop
|
|
193
|
-
* the in-memory history.
|
|
194
|
-
*/
|
|
195
|
-
function HistoryRow({ title, meta, requestLogId, onRemove, children }) {
|
|
196
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
|
|
197
|
-
className: "flex flex-col gap-1.5 px-4 py-3",
|
|
198
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
199
|
-
className: "flex items-center gap-2 text-[12px]",
|
|
200
|
-
children: [
|
|
201
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
202
|
-
className: "font-medium text-sand-800",
|
|
203
|
-
children: title
|
|
204
|
-
}),
|
|
205
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
206
|
-
className: "tabular-nums text-sand-400",
|
|
207
|
-
children: meta
|
|
208
|
-
}),
|
|
209
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
210
|
-
className: "ml-auto flex items-center gap-2",
|
|
211
|
-
children: [requestLogId !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
|
|
212
|
-
to: "/requests/show",
|
|
213
|
-
search: { id: requestLogId },
|
|
214
|
-
target: "_blank",
|
|
215
|
-
className: "inline-flex items-center gap-1 tabular-nums text-sand-500 hover:text-sienna-500",
|
|
216
|
-
children: [
|
|
217
|
-
"request log #",
|
|
218
|
-
requestLogId,
|
|
219
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$3, { className: "size-3" })
|
|
220
|
-
]
|
|
221
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
222
|
-
type: "button",
|
|
223
|
-
onClick: onRemove,
|
|
224
|
-
title: "Remove from history",
|
|
225
|
-
className: "text-sand-300 hover:text-sand-600",
|
|
226
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$4, { className: "size-3.5" })
|
|
227
|
-
})]
|
|
228
|
-
})
|
|
229
|
-
]
|
|
230
|
-
}), children]
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
function History({ empty, children }) {
|
|
234
|
-
return children.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
235
|
-
className: "px-4 py-6 text-center text-[12px] text-sand-400",
|
|
236
|
-
children: empty
|
|
237
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
|
|
238
|
-
className: "divide-y divide-sand-100",
|
|
239
|
-
children
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
/** Words from per-character timing (Grok TTS shape): each run of non-space characters is a word. */
|
|
243
|
-
function wordsFromCharTimes(timestamps) {
|
|
244
|
-
if (!timestamps) return void 0;
|
|
245
|
-
const words = [];
|
|
246
|
-
let current;
|
|
247
|
-
timestamps.graphChars.forEach((char, i) => {
|
|
248
|
-
const [start, end] = timestamps.graphTimes[i];
|
|
249
|
-
if (/\s/.test(char)) {
|
|
250
|
-
current = void 0;
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
if (current) {
|
|
254
|
-
current.text += char;
|
|
255
|
-
current.end = end;
|
|
256
|
-
} else {
|
|
257
|
-
current = {
|
|
258
|
-
text: char,
|
|
259
|
-
start,
|
|
260
|
-
end
|
|
261
|
-
};
|
|
262
|
-
words.push(current);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
return words;
|
|
266
|
-
}
|
|
267
|
-
function TtsPanel() {
|
|
268
|
-
const [model, setModel] = (0, import_react.useState)(TTS_MODELS[0]);
|
|
269
|
-
const [voice, setVoice] = (0, import_react.useState)("ara");
|
|
270
|
-
const [instructions, setInstructions] = (0, import_react.useState)("");
|
|
271
|
-
const [text, setText] = (0, import_react.useState)("Hi! What did you do this weekend?");
|
|
272
|
-
const [history, setHistory] = (0, import_react.useState)([]);
|
|
273
|
-
const [withTimestamps, setWithTimestamps] = (0, import_react.useState)(true);
|
|
274
|
-
const [speed, setSpeed] = (0, import_react.useState)(1);
|
|
275
|
-
const nextKey = (0, import_react.useRef)(0);
|
|
276
|
-
const speak = QgridService.useSpeakMutation();
|
|
277
|
-
const openai = isOpenAI(model);
|
|
278
|
-
const changeModel = (next) => {
|
|
279
|
-
if (isOpenAI(next) !== openai) setVoice(isOpenAI(next) ? OPENAI_VOICES[0] : "ara");
|
|
280
|
-
setModel(next);
|
|
281
|
-
};
|
|
282
|
-
const style = openai && instructions.trim() ? instructions.trim() : void 0;
|
|
283
|
-
const generate = (voiceId) => {
|
|
284
|
-
const startedAt = performance.now();
|
|
285
|
-
const params = {
|
|
286
|
-
model,
|
|
287
|
-
text,
|
|
288
|
-
voice: voiceId,
|
|
289
|
-
projectName: PROJECT_NAME
|
|
290
|
-
};
|
|
291
|
-
if (style) params.instructions = style;
|
|
292
|
-
if (withTimestamps) params.withTimestamps = true;
|
|
293
|
-
if (!openai && speed !== 1) params.speed = speed;
|
|
294
|
-
speak.mutate({ params }, { onSuccess: (out) => {
|
|
295
|
-
const item = {
|
|
296
|
-
key: nextKey.current++,
|
|
297
|
-
src: `data:${out.mimeType};base64,${out.audio}`,
|
|
298
|
-
model,
|
|
299
|
-
voice: voiceId,
|
|
300
|
-
instructions: params.instructions,
|
|
301
|
-
speed: params.speed,
|
|
302
|
-
text,
|
|
303
|
-
elapsedMs: performance.now() - startedAt,
|
|
304
|
-
requestLogId: out.requestLogId,
|
|
305
|
-
words: wordsFromCharTimes(out.audioTimestamps),
|
|
306
|
-
timing: out.timestampsError ? `timing failed: ${out.timestampsError}` : out.timestampsSource && TIMING_SOURCE[out.timestampsSource]
|
|
307
|
-
};
|
|
308
|
-
setHistory((items) => [item, ...items]);
|
|
309
|
-
} });
|
|
310
|
-
};
|
|
311
|
-
const sampleRef = (0, import_react.useRef)(null);
|
|
312
|
-
const [playing, setPlaying] = (0, import_react.useState)();
|
|
313
|
-
(0, import_react.useEffect)(() => () => sampleRef.current?.pause(), []);
|
|
314
|
-
const playSample = (voiceId) => {
|
|
315
|
-
setVoice(voiceId);
|
|
316
|
-
sampleRef.current?.pause();
|
|
317
|
-
if (playing === voiceId) {
|
|
318
|
-
setPlaying(void 0);
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const audio = new Audio(`/voice-samples/${openai ? "openai" : "grok"}/${voiceId}.mp3`);
|
|
322
|
-
audio.addEventListener("ended", () => setPlaying((current) => current === voiceId ? void 0 : current), { once: true });
|
|
323
|
-
sampleRef.current = audio;
|
|
324
|
-
setPlaying(voiceId);
|
|
325
|
-
audio.play();
|
|
326
|
-
};
|
|
327
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
328
|
-
className: "flex flex-col gap-3 p-4",
|
|
329
|
-
children: [
|
|
330
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
331
|
-
className: "grid grid-cols-2 gap-2",
|
|
332
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
333
|
-
label: "Model",
|
|
334
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
|
|
335
|
-
value: model,
|
|
336
|
-
onChange: (e) => changeModel(e.target.value),
|
|
337
|
-
className: CONTROL,
|
|
338
|
-
children: TTS_MODELS.map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
339
|
-
value: m,
|
|
340
|
-
children: m
|
|
341
|
-
}, m))
|
|
342
|
-
})
|
|
343
|
-
}), openai ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
344
|
-
label: "Style instructions (OpenAI only)",
|
|
345
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
346
|
-
value: instructions,
|
|
347
|
-
onChange: (e) => setInstructions(e.target.value),
|
|
348
|
-
placeholder: "e.g. Speak with a gentle Irish accent.",
|
|
349
|
-
className: CONTROL
|
|
350
|
-
})
|
|
351
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
352
|
-
label: `Speed (Grok only) — ${speed.toFixed(2)}×`,
|
|
353
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
354
|
-
type: "range",
|
|
355
|
-
min: .7,
|
|
356
|
-
max: 1.5,
|
|
357
|
-
step: .05,
|
|
358
|
-
value: speed,
|
|
359
|
-
onChange: (e) => setSpeed(Number(e.target.value)),
|
|
360
|
-
className: "h-8 accent-sienna-500"
|
|
361
|
-
})
|
|
362
|
-
})]
|
|
363
|
-
}),
|
|
364
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
365
|
-
className: "flex flex-col gap-1.5",
|
|
366
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
367
|
-
className: "text-[11px] font-medium text-sand-500",
|
|
368
|
-
children: "Voice — ▶ plays a short self-introduction sample, a name selects it"
|
|
369
|
-
}), (openai ? OPENAI_VOICE_GROUPS : GROK_VOICE_GROUPS).map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
370
|
-
className: "flex items-start gap-2",
|
|
371
|
-
children: [group.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
372
|
-
className: "w-12 shrink-0 pt-1 text-[11px] text-sand-400",
|
|
373
|
-
children: group.label
|
|
374
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
375
|
-
className: "flex flex-wrap gap-1.5",
|
|
376
|
-
children: group.voices.map((v) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
377
|
-
className: `inline-flex items-center overflow-hidden rounded-full border text-[12px] ${voice === v ? "border-sienna-400 bg-sienna-50 text-sienna-700" : "border-sand-200/80 bg-white text-sand-700"}`,
|
|
378
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
379
|
-
type: "button",
|
|
380
|
-
onClick: () => setVoice(v),
|
|
381
|
-
"aria-pressed": voice === v,
|
|
382
|
-
className: "py-0.5 pl-2.5 pr-1 hover:text-sienna-600",
|
|
383
|
-
children: v
|
|
384
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
385
|
-
type: "button",
|
|
386
|
-
onClick: () => playSample(v),
|
|
387
|
-
title: playing === v ? `Stop "${v}"` : `Play a "${v}" sample`,
|
|
388
|
-
className: `py-1 pl-1 pr-2 hover:text-sienna-500 ${playing === v ? "text-sienna-500" : "text-sand-400"}`,
|
|
389
|
-
children: playing === v ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$5, { className: "size-3" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef, { className: "size-3" })
|
|
390
|
-
})]
|
|
391
|
-
}, v))
|
|
392
|
-
})]
|
|
393
|
-
}, group.label))]
|
|
394
|
-
}),
|
|
395
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
396
|
-
label: "Text",
|
|
397
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
|
|
398
|
-
value: text,
|
|
399
|
-
onChange: (e) => setText(e.target.value),
|
|
400
|
-
rows: 3,
|
|
401
|
-
className: `${FIELD} resize-y`
|
|
402
|
-
})
|
|
403
|
-
}),
|
|
404
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
405
|
-
className: "flex items-center gap-3",
|
|
406
|
-
children: [
|
|
407
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
408
|
-
type: "button",
|
|
409
|
-
onClick: () => generate(voice),
|
|
410
|
-
disabled: speak.isPending || !text.trim(),
|
|
411
|
-
className: BUTTON,
|
|
412
|
-
children: [
|
|
413
|
-
speak.isPending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$2, { className: "size-3.5 animate-spin" }),
|
|
414
|
-
"Generate with ",
|
|
415
|
-
voice
|
|
416
|
-
]
|
|
417
|
-
}),
|
|
418
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
419
|
-
className: "flex items-center gap-1.5 text-[12px] text-sand-600",
|
|
420
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
421
|
-
type: "checkbox",
|
|
422
|
-
checked: withTimestamps,
|
|
423
|
-
onChange: (e) => setWithTimestamps(e.target.checked),
|
|
424
|
-
className: "accent-sienna-500"
|
|
425
|
-
}), "Word timing"]
|
|
426
|
-
}),
|
|
427
|
-
speak.isError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
428
|
-
className: "text-[12px] text-danger-500 break-words",
|
|
429
|
-
children: speak.error?.message
|
|
430
|
-
})
|
|
431
|
-
]
|
|
432
|
-
})
|
|
433
|
-
]
|
|
434
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
435
|
-
className: "border-t border-sand-100",
|
|
436
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, {
|
|
437
|
-
empty: "Generated clips stack here, newest first, so voices can be compared side by side.",
|
|
438
|
-
children: history.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(HistoryRow, {
|
|
439
|
-
title: [
|
|
440
|
-
item.voice,
|
|
441
|
-
shortModel(item.model),
|
|
442
|
-
item.speed && `${item.speed}×`
|
|
443
|
-
].filter(Boolean).join(" · "),
|
|
444
|
-
meta: [`${(item.elapsedMs / 1e3).toFixed(1)}s`, item.timing].filter(Boolean).join(" · "),
|
|
445
|
-
requestLogId: item.requestLogId,
|
|
446
|
-
onRemove: () => setHistory((items) => items.filter((i) => i.key !== item.key)),
|
|
447
|
-
children: [(!item.words || item.instructions) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
|
|
448
|
-
className: "truncate text-[12px] text-sand-600",
|
|
449
|
-
title: item.text,
|
|
450
|
-
children: [!item.words && item.text, item.instructions && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
451
|
-
className: "text-sand-400",
|
|
452
|
-
children: [" — ", item.instructions]
|
|
453
|
-
})]
|
|
454
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TimedPlayer, {
|
|
455
|
-
src: item.src,
|
|
456
|
-
words: item.words,
|
|
457
|
-
autoPlay: true
|
|
458
|
-
})]
|
|
459
|
-
}, item.key))
|
|
460
|
-
})
|
|
461
|
-
})] });
|
|
462
|
-
}
|
|
463
|
-
function SttPanel() {
|
|
464
|
-
const [model, setModel] = (0, import_react.useState)(STT_MODELS[0]);
|
|
465
|
-
const [prompt, setPrompt] = (0, import_react.useState)("");
|
|
466
|
-
const [audio, setAudio] = (0, import_react.useState)();
|
|
467
|
-
const [recording, setRecording] = (0, import_react.useState)(false);
|
|
468
|
-
const [audioError, setAudioError] = (0, import_react.useState)();
|
|
469
|
-
const [history, setHistory] = (0, import_react.useState)([]);
|
|
470
|
-
const recorderRef = (0, import_react.useRef)(null);
|
|
471
|
-
const clipUrls = (0, import_react.useRef)([]);
|
|
472
|
-
const nextKey = (0, import_react.useRef)(0);
|
|
473
|
-
const transcribe = QgridService.useTranscribeMutation();
|
|
474
|
-
const openai = isOpenAI(model);
|
|
475
|
-
(0, import_react.useEffect)(() => () => {
|
|
476
|
-
recorderRef.current?.stream.getTracks().forEach((track) => track.stop());
|
|
477
|
-
clipUrls.current.forEach((url) => URL.revokeObjectURL(url));
|
|
478
|
-
}, []);
|
|
479
|
-
const takeAudio = (blob) => {
|
|
480
|
-
const url = URL.createObjectURL(blob);
|
|
481
|
-
clipUrls.current.push(url);
|
|
482
|
-
setAudio({
|
|
483
|
-
blob,
|
|
484
|
-
url,
|
|
485
|
-
clip: clipUrls.current.length
|
|
486
|
-
});
|
|
487
|
-
};
|
|
488
|
-
const toggleRecording = async () => {
|
|
489
|
-
if (recording) {
|
|
490
|
-
recorderRef.current?.stop();
|
|
491
|
-
setRecording(false);
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
setAudioError(void 0);
|
|
495
|
-
try {
|
|
496
|
-
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
497
|
-
const recorder = new MediaRecorder(stream);
|
|
498
|
-
const chunks = [];
|
|
499
|
-
recorder.ondataavailable = (e) => chunks.push(e.data);
|
|
500
|
-
recorder.onstop = () => {
|
|
501
|
-
stream.getTracks().forEach((track) => track.stop());
|
|
502
|
-
takeAudio(new Blob(chunks, { type: recorder.mimeType }));
|
|
503
|
-
};
|
|
504
|
-
recorder.start();
|
|
505
|
-
recorderRef.current = recorder;
|
|
506
|
-
setRecording(true);
|
|
507
|
-
} catch (error) {
|
|
508
|
-
setAudioError(error instanceof Error ? error.message : String(error));
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
const submit = async () => {
|
|
512
|
-
if (!audio) return;
|
|
513
|
-
setAudioError(void 0);
|
|
514
|
-
const originalType = audio.blob.type.split(";")[0];
|
|
515
|
-
let clip;
|
|
516
|
-
try {
|
|
517
|
-
clip = !openai && originalType.startsWith("audio/") ? {
|
|
518
|
-
audio: bytesToBase64(new Uint8Array(await audio.blob.arrayBuffer())),
|
|
519
|
-
mediaType: originalType
|
|
520
|
-
} : {
|
|
521
|
-
audio: await audioToWavBase64(audio.blob),
|
|
522
|
-
mediaType: "audio/wav"
|
|
523
|
-
};
|
|
524
|
-
} catch (error) {
|
|
525
|
-
setAudioError(`could not decode audio: ${error instanceof Error ? error.message : String(error)}`);
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
const params = {
|
|
529
|
-
model,
|
|
530
|
-
...clip,
|
|
531
|
-
projectName: PROJECT_NAME
|
|
532
|
-
};
|
|
533
|
-
if (openai && prompt.trim()) params.prompt = prompt.trim();
|
|
534
|
-
const startedAt = performance.now();
|
|
535
|
-
transcribe.mutate({ params }, { onSuccess: (out) => {
|
|
536
|
-
const item = {
|
|
537
|
-
key: nextKey.current++,
|
|
538
|
-
clip: audio.clip,
|
|
539
|
-
clipUrl: audio.url,
|
|
540
|
-
model,
|
|
541
|
-
prompt: params.prompt,
|
|
542
|
-
text: out.text,
|
|
543
|
-
elapsedMs: performance.now() - startedAt,
|
|
544
|
-
durationSec: out.durationSec,
|
|
545
|
-
requestLogId: out.requestLogId,
|
|
546
|
-
words: out.words
|
|
547
|
-
};
|
|
548
|
-
setHistory((items) => [item, ...items]);
|
|
549
|
-
} });
|
|
550
|
-
};
|
|
551
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
552
|
-
className: "flex flex-col gap-3 p-4",
|
|
553
|
-
children: [
|
|
554
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
555
|
-
className: "grid grid-cols-2 gap-2",
|
|
556
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
557
|
-
label: "Model",
|
|
558
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
|
|
559
|
-
value: model,
|
|
560
|
-
onChange: (e) => setModel(e.target.value),
|
|
561
|
-
className: CONTROL,
|
|
562
|
-
children: STT_MODELS.map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
563
|
-
value: m,
|
|
564
|
-
children: m
|
|
565
|
-
}, m))
|
|
566
|
-
})
|
|
567
|
-
}), openai && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
568
|
-
label: "Prompt (OpenAI only)",
|
|
569
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
570
|
-
value: prompt,
|
|
571
|
-
onChange: (e) => setPrompt(e.target.value),
|
|
572
|
-
placeholder: "domain words, e.g. qgrid, Kuma",
|
|
573
|
-
className: CONTROL
|
|
574
|
-
})
|
|
575
|
-
})]
|
|
576
|
-
}),
|
|
577
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
578
|
-
className: "flex flex-wrap items-center gap-2",
|
|
579
|
-
children: [
|
|
580
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
581
|
-
type: "button",
|
|
582
|
-
onClick: toggleRecording,
|
|
583
|
-
className: `${BUTTON} ${recording ? "bg-danger-500 hover:bg-danger-500" : ""}`,
|
|
584
|
-
children: [recording ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$5, { className: "size-3.5" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$1, { className: "size-3.5" }), recording ? "Stop" : "Record"]
|
|
585
|
-
}),
|
|
586
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
587
|
-
className: "text-[12px] text-sand-600 cursor-pointer hover:text-sienna-500",
|
|
588
|
-
children: ["or upload a file", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
589
|
-
type: "file",
|
|
590
|
-
accept: "audio/*",
|
|
591
|
-
className: "hidden",
|
|
592
|
-
onChange: (e) => {
|
|
593
|
-
const file = e.target.files?.[0];
|
|
594
|
-
if (file) takeAudio(file);
|
|
595
|
-
}
|
|
596
|
-
})]
|
|
597
|
-
}),
|
|
598
|
-
audioError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
599
|
-
className: "text-[12px] text-danger-500 break-words",
|
|
600
|
-
children: audioError
|
|
601
|
-
})
|
|
602
|
-
]
|
|
603
|
-
}),
|
|
604
|
-
audio && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
605
|
-
className: "flex items-center gap-2",
|
|
606
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
607
|
-
className: "shrink-0 text-[11px] font-medium text-sand-500",
|
|
608
|
-
children: ["clip ", audio.clip]
|
|
609
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("audio", {
|
|
610
|
-
controls: true,
|
|
611
|
-
src: audio.url,
|
|
612
|
-
className: "h-8 w-full"
|
|
613
|
-
})]
|
|
614
|
-
}),
|
|
615
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
616
|
-
className: "flex items-center gap-3",
|
|
617
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
618
|
-
type: "button",
|
|
619
|
-
onClick: submit,
|
|
620
|
-
disabled: !audio || recording || transcribe.isPending,
|
|
621
|
-
className: BUTTON,
|
|
622
|
-
children: [transcribe.isPending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$2, { className: "size-3.5 animate-spin" }), "Transcribe"]
|
|
623
|
-
}), transcribe.isError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
624
|
-
className: "text-[12px] text-danger-500 break-words",
|
|
625
|
-
children: transcribe.error?.message
|
|
626
|
-
})]
|
|
627
|
-
})
|
|
628
|
-
]
|
|
629
|
-
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
630
|
-
className: "border-t border-sand-100",
|
|
631
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(History, {
|
|
632
|
-
empty: "Transcripts stack here, newest first; run one clip through several models to compare.",
|
|
633
|
-
children: history.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HistoryRow, {
|
|
634
|
-
title: `clip ${item.clip} · ${shortModel(item.model)}`,
|
|
635
|
-
meta: [
|
|
636
|
-
`${(item.elapsedMs / 1e3).toFixed(1)}s`,
|
|
637
|
-
item.durationSec !== void 0 ? `${item.durationSec.toFixed(1)}s audio` : "",
|
|
638
|
-
item.prompt ? `prompt: ${item.prompt}` : ""
|
|
639
|
-
].filter(Boolean).join(" · "),
|
|
640
|
-
requestLogId: item.requestLogId,
|
|
641
|
-
onRemove: () => setHistory((items) => items.filter((i) => i.key !== item.key)),
|
|
642
|
-
children: item.words && item.words.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TimedPlayer, {
|
|
643
|
-
src: item.clipUrl,
|
|
644
|
-
words: item.words
|
|
645
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
646
|
-
className: "rounded-lg bg-sand-50 px-3 py-2 text-[13px] text-sand-800 whitespace-pre-wrap",
|
|
647
|
-
children: item.text || "(empty transcript)"
|
|
648
|
-
})
|
|
649
|
-
}, item.key))
|
|
650
|
-
})
|
|
651
|
-
})] });
|
|
652
|
-
}
|
|
653
|
-
var LIVE_VOICES = "cove juniper maple spruce ember vale breeze arbor sol aube bubbie haetsal hanul himari leher miko neer porto rindo rio rivage selva sonna tinta viola".split(" ");
|
|
654
|
-
var DEFAULT_DELEGATION_MODEL = "openai/gpt-6-luna";
|
|
655
|
-
var LiveEvent = looseObject({
|
|
656
|
-
type: string(),
|
|
657
|
-
turn: looseObject({
|
|
658
|
-
id: string(),
|
|
659
|
-
role: string(),
|
|
660
|
-
transcript: string()
|
|
661
|
-
}).optional(),
|
|
662
|
-
turn_id: string().optional(),
|
|
663
|
-
delta: string().optional()
|
|
664
|
-
});
|
|
665
|
-
var clock = (sec) => `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, "0")}`;
|
|
666
|
-
/** Ends the session at once; a peer that only disconnects keeps it (and its billed time) ~30 s. */
|
|
667
|
-
function endLiveSession({ pc, channel, mic }) {
|
|
668
|
-
if (channel.readyState === "open") channel.send(JSON.stringify({ type: "session.close" }));
|
|
669
|
-
mic.getTracks().forEach((track) => track.stop());
|
|
670
|
-
setTimeout(() => pc.close(), 500);
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* A GPT-Live conversation. The browser's own WebRTC peer talks to OpenAI; qgrid only exchanges the
|
|
674
|
-
* SDP offer with the subscription token and logs the transcript when the session ends.
|
|
675
|
-
*/
|
|
676
|
-
function LivePanel() {
|
|
677
|
-
const [voice, setVoice] = (0, import_react.useState)(LIVE_VOICES[0]);
|
|
678
|
-
const [instructions, setInstructions] = (0, import_react.useState)("");
|
|
679
|
-
const [delegateModel, setDelegateModel] = (0, import_react.useState)(DEFAULT_DELEGATION_MODEL);
|
|
680
|
-
const [effort, setEffort] = (0, import_react.useState)("low");
|
|
681
|
-
const [webSearch, setWebSearch] = (0, import_react.useState)(false);
|
|
682
|
-
const [logged, setLogged] = (0, import_react.useState)(true);
|
|
683
|
-
const [earlier, setEarlier] = (0, import_react.useState)([]);
|
|
684
|
-
const searchable = !delegateModel.startsWith("anthropic/");
|
|
685
|
-
const [status, setStatus] = (0, import_react.useState)("idle");
|
|
686
|
-
const [error, setError] = (0, import_react.useState)();
|
|
687
|
-
const [turns, setTurns] = (0, import_react.useState)([]);
|
|
688
|
-
const [requestLogId, setRequestLogId] = (0, import_react.useState)();
|
|
689
|
-
const [elapsedSec, setElapsedSec] = (0, import_react.useState)(0);
|
|
690
|
-
const session = (0, import_react.useRef)(null);
|
|
691
|
-
const audioRef = (0, import_react.useRef)(null);
|
|
692
|
-
const liveCall = QgridService.useLiveCallMutation();
|
|
693
|
-
(0, import_react.useEffect)(() => () => {
|
|
694
|
-
if (session.current) endLiveSession(session.current);
|
|
695
|
-
}, []);
|
|
696
|
-
(0, import_react.useEffect)(() => {
|
|
697
|
-
if (status !== "live") return;
|
|
698
|
-
const startedAt = Date.now();
|
|
699
|
-
const timer = setInterval(() => setElapsedSec(Math.floor((Date.now() - startedAt) / 1e3)), 1e3);
|
|
700
|
-
return () => clearInterval(timer);
|
|
701
|
-
}, [status]);
|
|
702
|
-
const stop = () => {
|
|
703
|
-
if (session.current) endLiveSession(session.current);
|
|
704
|
-
session.current = null;
|
|
705
|
-
setStatus("idle");
|
|
706
|
-
};
|
|
707
|
-
const onEvent = (raw) => {
|
|
708
|
-
let json;
|
|
709
|
-
try {
|
|
710
|
-
json = LiveEvent.safeParse(JSON.parse(raw)).data;
|
|
711
|
-
} catch {
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
if (!json) return;
|
|
715
|
-
const { type, turn, turn_id: turnId, delta } = json;
|
|
716
|
-
if (type === "session.closed") {
|
|
717
|
-
stop();
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
if (turn && (type === "turn.created" || type === "turn.done")) {
|
|
721
|
-
const next = {
|
|
722
|
-
id: turn.id,
|
|
723
|
-
role: turn.role,
|
|
724
|
-
text: turn.transcript
|
|
725
|
-
};
|
|
726
|
-
setTurns((items) => items.some((item) => item.id === turn.id) ? items.map((item) => item.id === turn.id ? next : item) : [...items, next]);
|
|
727
|
-
} else if (type === "turn.delta" && turnId && delta) setTurns((items) => items.map((item) => item.id === turnId ? {
|
|
728
|
-
...item,
|
|
729
|
-
text: item.text + delta
|
|
730
|
-
} : item));
|
|
731
|
-
};
|
|
732
|
-
const start = async (continueConversation) => {
|
|
733
|
-
const history = continueConversation ? [...earlier, ...turns.flatMap((turn) => turn.text.trim() ? [{
|
|
734
|
-
role: turn.role === "assistant" ? "assistant" : "user",
|
|
735
|
-
text: turn.text.trim()
|
|
736
|
-
}] : [])].slice(-128) : [];
|
|
737
|
-
setEarlier(history);
|
|
738
|
-
setError(void 0);
|
|
739
|
-
setTurns([]);
|
|
740
|
-
setRequestLogId(void 0);
|
|
741
|
-
setElapsedSec(0);
|
|
742
|
-
setStatus("connecting");
|
|
743
|
-
let mic;
|
|
744
|
-
let pc;
|
|
745
|
-
try {
|
|
746
|
-
mic = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
747
|
-
const peer = new RTCPeerConnection();
|
|
748
|
-
pc = peer;
|
|
749
|
-
mic.getTracks().forEach((track) => peer.addTrack(track));
|
|
750
|
-
peer.addEventListener("track", (event) => {
|
|
751
|
-
if (audioRef.current) audioRef.current.srcObject = new MediaStream([event.track]);
|
|
752
|
-
});
|
|
753
|
-
const channel = peer.createDataChannel("oai-events");
|
|
754
|
-
channel.addEventListener("message", (event) => onEvent(String(event.data)));
|
|
755
|
-
const offer = await peer.createOffer();
|
|
756
|
-
await peer.setLocalDescription(offer);
|
|
757
|
-
const params = {
|
|
758
|
-
sdp: offer.sdp ?? "",
|
|
759
|
-
voice,
|
|
760
|
-
delegation: {
|
|
761
|
-
model: delegateModel,
|
|
762
|
-
effort,
|
|
763
|
-
webSearch: searchable && webSearch
|
|
764
|
-
},
|
|
765
|
-
projectName: PROJECT_NAME
|
|
766
|
-
};
|
|
767
|
-
if (instructions.trim()) params.instructions = instructions.trim();
|
|
768
|
-
if (history.length) params.history = history;
|
|
769
|
-
if (!logged) params.logger = false;
|
|
770
|
-
const out = await liveCall.mutateAsync({ params });
|
|
771
|
-
await peer.setRemoteDescription({
|
|
772
|
-
type: "answer",
|
|
773
|
-
sdp: out.sdp
|
|
774
|
-
});
|
|
775
|
-
session.current = {
|
|
776
|
-
pc: peer,
|
|
777
|
-
channel,
|
|
778
|
-
mic
|
|
779
|
-
};
|
|
780
|
-
setRequestLogId(out.requestLogId);
|
|
781
|
-
setStatus("live");
|
|
782
|
-
} catch (e) {
|
|
783
|
-
mic?.getTracks().forEach((track) => track.stop());
|
|
784
|
-
pc?.close();
|
|
785
|
-
setError(e instanceof Error ? e.message : String(e));
|
|
786
|
-
setStatus("idle");
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
790
|
-
className: "flex flex-col gap-3 p-4",
|
|
791
|
-
children: [
|
|
792
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
793
|
-
className: "grid grid-cols-2 gap-2",
|
|
794
|
-
children: [
|
|
795
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
796
|
-
label: "Voice",
|
|
797
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
|
|
798
|
-
value: voice,
|
|
799
|
-
onChange: (e) => setVoice(e.target.value),
|
|
800
|
-
disabled: status !== "idle",
|
|
801
|
-
className: CONTROL,
|
|
802
|
-
children: LIVE_VOICES.map((v) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
803
|
-
value: v,
|
|
804
|
-
children: v
|
|
805
|
-
}, v))
|
|
806
|
-
})
|
|
807
|
-
}),
|
|
808
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
809
|
-
label: "Instructions",
|
|
810
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
811
|
-
value: instructions,
|
|
812
|
-
onChange: (e) => setInstructions(e.target.value),
|
|
813
|
-
disabled: status !== "idle",
|
|
814
|
-
placeholder: "e.g. You are a friendly English tutor. Keep answers short.",
|
|
815
|
-
className: CONTROL
|
|
816
|
-
})
|
|
817
|
-
}),
|
|
818
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
819
|
-
label: "Delegation model (answers lookups and reasoning)",
|
|
820
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
|
|
821
|
-
value: delegateModel,
|
|
822
|
-
onChange: (e) => setDelegateModel(e.target.value),
|
|
823
|
-
disabled: status !== "idle",
|
|
824
|
-
className: CONTROL,
|
|
825
|
-
children: QGRID_MODEL_GROUPS.map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("optgroup", {
|
|
826
|
-
label: group.label,
|
|
827
|
-
children: group.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
828
|
-
value: m,
|
|
829
|
-
children: m
|
|
830
|
-
}, m))
|
|
831
|
-
}, group.label))
|
|
832
|
-
})
|
|
833
|
-
}),
|
|
834
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
835
|
-
className: "flex items-end gap-3",
|
|
836
|
-
children: [
|
|
837
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
|
|
838
|
-
label: "Effort",
|
|
839
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
|
|
840
|
-
value: effort,
|
|
841
|
-
onChange: (e) => setEffort(Effort.options.find((v) => v === e.target.value) ?? "low"),
|
|
842
|
-
disabled: status !== "idle",
|
|
843
|
-
className: CONTROL,
|
|
844
|
-
children: Effort.options.map((v) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
845
|
-
value: v,
|
|
846
|
-
children: v
|
|
847
|
-
}, v))
|
|
848
|
-
})
|
|
849
|
-
}),
|
|
850
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
851
|
-
className: "flex h-8 items-center gap-1.5 text-[12px] text-sand-600",
|
|
852
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
853
|
-
type: "checkbox",
|
|
854
|
-
checked: searchable && webSearch,
|
|
855
|
-
onChange: (e) => setWebSearch(e.target.checked),
|
|
856
|
-
disabled: status !== "idle" || !searchable,
|
|
857
|
-
className: "accent-sienna-500"
|
|
858
|
-
}), "Web search"]
|
|
859
|
-
}),
|
|
860
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
861
|
-
className: "flex h-8 items-center gap-1.5 text-[12px] text-sand-600",
|
|
862
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
863
|
-
type: "checkbox",
|
|
864
|
-
checked: logged,
|
|
865
|
-
onChange: (e) => setLogged(e.target.checked),
|
|
866
|
-
disabled: status !== "idle",
|
|
867
|
-
className: "accent-sienna-500"
|
|
868
|
-
}), "Request log"]
|
|
869
|
-
})
|
|
870
|
-
]
|
|
871
|
-
})
|
|
872
|
-
]
|
|
873
|
-
}),
|
|
874
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
875
|
-
className: "flex flex-wrap items-center gap-3",
|
|
876
|
-
children: [
|
|
877
|
-
status === "idle" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
878
|
-
type: "button",
|
|
879
|
-
onClick: () => start(false),
|
|
880
|
-
className: BUTTON,
|
|
881
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$1, { className: "size-3.5" }), "Start conversation"]
|
|
882
|
-
}), turns.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
883
|
-
type: "button",
|
|
884
|
-
onClick: () => start(true),
|
|
885
|
-
className: "text-[12px] font-medium text-sienna-600 hover:text-sienna-700",
|
|
886
|
-
children: "Continue this conversation"
|
|
887
|
-
})] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
888
|
-
type: "button",
|
|
889
|
-
onClick: stop,
|
|
890
|
-
disabled: status === "connecting",
|
|
891
|
-
className: `${BUTTON} bg-danger-500 hover:bg-danger-500`,
|
|
892
|
-
children: [status === "connecting" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$2, { className: "size-3.5 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$5, { className: "size-3.5" }), status === "connecting" ? "Connecting" : "End"]
|
|
893
|
-
}),
|
|
894
|
-
status === "live" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
895
|
-
className: "tabular-nums text-[12px] text-sand-500",
|
|
896
|
-
children: [clock(elapsedSec), " · openai/gpt-live-1 · speak any time (ends by itself after 2 h)"]
|
|
897
|
-
}),
|
|
898
|
-
requestLogId !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
|
|
899
|
-
to: "/requests/show",
|
|
900
|
-
search: { id: requestLogId },
|
|
901
|
-
target: "_blank",
|
|
902
|
-
className: "inline-flex items-center gap-1 text-[12px] tabular-nums text-sand-500 hover:text-sienna-500",
|
|
903
|
-
children: [
|
|
904
|
-
"request log #",
|
|
905
|
-
requestLogId,
|
|
906
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ForwardRef$3, { className: "size-3" })
|
|
907
|
-
]
|
|
908
|
-
}),
|
|
909
|
-
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
910
|
-
className: "text-[12px] text-danger-500 break-words",
|
|
911
|
-
children: error
|
|
912
|
-
})
|
|
913
|
-
]
|
|
914
|
-
}),
|
|
915
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("audio", {
|
|
916
|
-
ref: audioRef,
|
|
917
|
-
autoPlay: true
|
|
918
|
-
}),
|
|
919
|
-
earlier.length === 0 && turns.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
920
|
-
className: "py-6 text-center text-[12px] text-sand-400",
|
|
921
|
-
children: "Start a conversation and talk; both sides of the transcript appear here."
|
|
922
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", {
|
|
923
|
-
className: "flex flex-col gap-1.5",
|
|
924
|
-
children: [earlier.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
|
|
925
|
-
className: "rounded-lg bg-sand-50/60 px-3 py-2 text-[13px] text-sand-500",
|
|
926
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
927
|
-
className: "mr-2 text-[10px] font-medium uppercase tracking-wider text-sand-400",
|
|
928
|
-
children: item.role
|
|
929
|
-
}), item.text]
|
|
930
|
-
}, `earlier-${index}`)), turns.map((turn) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
|
|
931
|
-
className: `rounded-lg px-3 py-2 text-[13px] text-sand-800 ${turn.role === "assistant" ? "bg-sage-50" : "bg-sand-50"}`,
|
|
932
|
-
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
933
|
-
className: "mr-2 text-[10px] font-medium uppercase tracking-wider text-sand-500",
|
|
934
|
-
children: turn.role
|
|
935
|
-
}), turn.text.trim()]
|
|
936
|
-
}, turn.id))]
|
|
937
|
-
})
|
|
938
|
-
]
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
function VoicePlayground({ tab }) {
|
|
942
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
|
|
943
|
-
className: "rounded-xl border border-sand-200/70 bg-white overflow-hidden",
|
|
944
|
-
children: [
|
|
945
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
946
|
-
role: "tablist",
|
|
947
|
-
className: "flex gap-1 border-b border-sand-100 px-3 pt-2 md:hidden",
|
|
948
|
-
children: VOICE_TAB_IDS.map((id) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
|
|
949
|
-
to: "/voice",
|
|
950
|
-
search: { tab: id },
|
|
951
|
-
role: "tab",
|
|
952
|
-
"aria-selected": tab === id,
|
|
953
|
-
className: `-mb-px border-b-2 px-3 py-2 text-[13px] no-underline transition-colors duration-150 ${tab === id ? "border-sienna-500 font-medium text-sand-800" : "border-transparent text-sand-500 hover:text-sand-700"}`,
|
|
954
|
-
children: VOICE_TAB_TITLES[id]
|
|
955
|
-
}, id))
|
|
956
|
-
}),
|
|
957
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
958
|
-
role: "tabpanel",
|
|
959
|
-
hidden: tab !== "tts",
|
|
960
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TtsPanel, {})
|
|
961
|
-
}),
|
|
962
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
963
|
-
role: "tabpanel",
|
|
964
|
-
hidden: tab !== "stt",
|
|
965
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SttPanel, {})
|
|
966
|
-
}),
|
|
967
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
968
|
-
role: "tabpanel",
|
|
969
|
-
hidden: tab !== "live",
|
|
970
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LivePanel, {})
|
|
971
|
-
})
|
|
972
|
-
]
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
//#endregion
|
|
976
|
-
//#region src/routes/voice.tsx?tsr-split=component
|
|
977
|
-
function VoicePage() {
|
|
978
|
-
const { tab = "tts" } = Route.useSearch();
|
|
979
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
980
|
-
className: "max-w-3xl mx-auto",
|
|
981
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VoicePlayground, { tab })
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
//#endregion
|
|
985
|
-
export { VoicePage as component };
|