@cartanova/qgrid-cli 2.15.5 → 2.16.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.frame.js +31 -11
- package/bundle/dist/application/qgrid/qgrid.types.js +8 -2
- package/bundle/dist/utils/providers/grok/grok-types.js +3 -2
- package/bundle/dist/utils/providers/grok/grok-voice-client.js +35 -2
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +25 -0
- package/bundle/src/application/qgrid/qgrid.frame.ts +52 -13
- package/bundle/src/application/qgrid/qgrid.types.ts +12 -0
- package/bundle/src/application/sonamu.generated.http +3 -1
- package/bundle/src/utils/providers/grok/grok-types.ts +14 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.test.ts +30 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.ts +54 -0
- package/bundle/web-dist/client/assets/{index-Wi8Wxte6.js → index-SGfYBzGT.js} +3 -3
- package/bundle/web-dist/client/assets/{logs-Bdg3wJV2.js → logs-DrTz38re.js} +1 -1
- package/bundle/web-dist/client/assets/{monit-DcwHRAKu.js → monit-klIY-HEI.js} +1 -1
- package/bundle/web-dist/client/assets/{routes-lxVC1DDJ.js → routes-bGN3y2NW.js} +1 -1
- package/bundle/web-dist/client/assets/{settings-C0VCdd1C.js → settings-BHwEvAZL.js} +1 -1
- package/bundle/web-dist/client/assets/{show-B7QRPxsY.js → show-BiJkyrfB.js} +1 -1
- package/bundle/web-dist/client/assets/{tokens-CNRSm9sc.js → tokens-DMWMG9O5.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-eQnMzp8A.js → use-oauth-login-flow-D1v4h9zA.js} +1 -1
- package/bundle/web-dist/client/assets/{use-update-token-mutation-KnwyYQjb.js → use-update-token-mutation-BVBUlqBN.js} +1 -1
- package/bundle/web-dist/client/assets/{voice-BydIuS0A.js → voice-CwD3asSF.js} +1 -1
- package/bundle/web-dist/client/index.html +1 -1
- package/bundle/web-dist/server/entry-server.generated.js +1 -1
- package/package.json +1 -1
- package/skills/qgrid/references/ai-sdk-provider-contract.md +2 -0
- package/skills/qgrid/references/grok-runtime.md +2 -0
- package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
|
@@ -2202,6 +2202,10 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2202
2202
|
77,
|
|
2203
2203
|
expect.objectContaining({ status: "succeeded", response: "hello there", cost_usd: null, cost_source: null }),
|
|
2204
2204
|
);
|
|
2205
|
+
// The input audio is kept playable in the user prompt, as TTS output is in the response.
|
|
2206
|
+
expect(requestLogCreateRunMock).toHaveBeenCalledWith(
|
|
2207
|
+
expect.objectContaining({ user_prompt: `<audio src="data:audio/wav;base64,${audio}"></audio>`, media_kind: "stt" }),
|
|
2208
|
+
);
|
|
2205
2209
|
});
|
|
2206
2210
|
|
|
2207
2211
|
it("transcribe rejects non-base64 and non-audio input before dispatch", async () => {
|
|
@@ -2255,6 +2259,27 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2255
2259
|
);
|
|
2256
2260
|
});
|
|
2257
2261
|
|
|
2262
|
+
it("speak passes withTimestamps to Grok and returns the character timing", async () => {
|
|
2263
|
+
const audioTimestamps = { graphChars: ["h", "i"], graphTimes: [[0, 0.1], [0.1, 0.3]] as Array<[number, number]> };
|
|
2264
|
+
grok.speak!.mockResolvedValueOnce({
|
|
2265
|
+
result: { audio: new Uint8Array([1, 2]), mediaType: "audio/mpeg", audioTimestamps, durationSec: 0.3 },
|
|
2266
|
+
tokenId: 3,
|
|
2267
|
+
tokenName: "grok/a",
|
|
2268
|
+
});
|
|
2269
|
+
|
|
2270
|
+
const out = await QgridFrame.speak({ text: "hi", withTimestamps: true });
|
|
2271
|
+
|
|
2272
|
+
expect(grok.speak).toHaveBeenCalledWith(expect.objectContaining({ with_timestamps: true }));
|
|
2273
|
+
expect(out).toMatchObject({ audioTimestamps, durationSec: 0.3 });
|
|
2274
|
+
});
|
|
2275
|
+
|
|
2276
|
+
it("speak rejects withTimestamps for OpenAI before any log or dispatch", async () => {
|
|
2277
|
+
await expect(
|
|
2278
|
+
QgridFrame.speak({ model: "openai/gpt-realtime-2.1-mini", text: "hi", withTimestamps: true }),
|
|
2279
|
+
).rejects.toThrow("withTimestamps is available only for grok/");
|
|
2280
|
+
expect(requestLogCreateRunMock).not.toHaveBeenCalled();
|
|
2281
|
+
});
|
|
2282
|
+
|
|
2258
2283
|
it("speak keeps the byte-count placeholder for audio a browser cannot play", async () => {
|
|
2259
2284
|
grok.speak!.mockResolvedValueOnce({
|
|
2260
2285
|
result: { audio: new Uint8Array(6), mediaType: "audio/pcm" },
|
|
@@ -829,13 +829,26 @@ type MediaLogSuccess = {
|
|
|
829
829
|
ttftMs?: number;
|
|
830
830
|
};
|
|
831
831
|
|
|
832
|
-
//
|
|
833
|
-
//
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
832
|
+
// Voice rows embed browser-playable audio (TTS output in the response, STT input in the user
|
|
833
|
+
// prompt) so the request-log detail page can play it, as image rows embed their images. Other
|
|
834
|
+
// formats (raw PCM, mu-law, A-law) keep the byte-count placeholder.
|
|
835
|
+
const LOG_PLAYABLE_AUDIO = new Set([
|
|
836
|
+
"audio/wav",
|
|
837
|
+
"audio/x-wav",
|
|
838
|
+
"audio/wave",
|
|
839
|
+
"audio/mpeg",
|
|
840
|
+
"audio/mp3",
|
|
841
|
+
"audio/mp4",
|
|
842
|
+
"audio/ogg",
|
|
843
|
+
"audio/webm",
|
|
844
|
+
"audio/flac",
|
|
845
|
+
]);
|
|
846
|
+
|
|
847
|
+
function audioForLog(b64: string, mimeType: string, byteLength: number): string {
|
|
848
|
+
const base = mimeType.split(";")[0]!.trim().toLowerCase();
|
|
849
|
+
|
|
850
|
+
return LOG_PLAYABLE_AUDIO.has(base)
|
|
851
|
+
? `<audio src="data:${base};base64,${b64}"></audio>`
|
|
839
852
|
: `[audio ${mimeType} ${byteLength} bytes]`;
|
|
840
853
|
}
|
|
841
854
|
|
|
@@ -1097,7 +1110,7 @@ async function transcribeOpenAI(input: TranscribeInput): Promise<TranscribeOutpu
|
|
|
1097
1110
|
const start = {
|
|
1098
1111
|
kind: "stt",
|
|
1099
1112
|
model: route,
|
|
1100
|
-
prompt:
|
|
1113
|
+
prompt: audioForLog(input.audio, input.mediaType, audio.byteLength),
|
|
1101
1114
|
projectName: input.projectName,
|
|
1102
1115
|
logger: input.logger,
|
|
1103
1116
|
} as const;
|
|
@@ -1210,7 +1223,7 @@ async function speakOpenAI(input: SpeakInput): Promise<SpeakOutput> {
|
|
|
1210
1223
|
|
|
1211
1224
|
const log: MediaRunLog = {
|
|
1212
1225
|
tokenName: output.tokenName,
|
|
1213
|
-
response:
|
|
1226
|
+
response: audioForLog(logAudio, "audio/wav", audio.byteLength),
|
|
1214
1227
|
firstOutputAt: firstAudioAt,
|
|
1215
1228
|
steps: [
|
|
1216
1229
|
{
|
|
@@ -2199,7 +2212,7 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2199
2212
|
const start = {
|
|
2200
2213
|
kind: "stt",
|
|
2201
2214
|
model: route,
|
|
2202
|
-
prompt:
|
|
2215
|
+
prompt: audioForLog(input.audio, input.mediaType, audio.byteLength),
|
|
2203
2216
|
projectName: input.projectName,
|
|
2204
2217
|
logger: input.logger,
|
|
2205
2218
|
} as const;
|
|
@@ -2256,7 +2269,18 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2256
2269
|
async speak(params: SpeakInput): Promise<SpeakOutput> {
|
|
2257
2270
|
const input = parseMediaInput(SpeakInput, params);
|
|
2258
2271
|
|
|
2259
|
-
if (voiceProvider(input.model) === "openai")
|
|
2272
|
+
if (voiceProvider(input.model) === "openai") {
|
|
2273
|
+
if (input.withTimestamps) {
|
|
2274
|
+
throw new BadRequestException(
|
|
2275
|
+
SD("qgrid.openaiVoiceInvalidRequest")(
|
|
2276
|
+
"withTimestamps is available only for grok/ speech; OpenAI realtime has no timing data",
|
|
2277
|
+
),
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
return speakOpenAI(input);
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2260
2284
|
const voice = grokVoice();
|
|
2261
2285
|
const selection = await resolveGrokTokenSelection(input.tokenName);
|
|
2262
2286
|
const route = input.model ?? GROK_TTS_LOG_MODEL;
|
|
@@ -2266,6 +2290,7 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2266
2290
|
voice: input.voice ?? GROK_TTS_DEFAULT_VOICE,
|
|
2267
2291
|
language: input.language ?? GROK_TTS_DEFAULT_LANGUAGE,
|
|
2268
2292
|
format: input.format ?? GROK_TTS_DEFAULT_FORMAT,
|
|
2293
|
+
...(input.withTimestamps === true && { with_timestamps: true }),
|
|
2269
2294
|
};
|
|
2270
2295
|
|
|
2271
2296
|
const start = {
|
|
@@ -2288,9 +2313,17 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2288
2313
|
|
|
2289
2314
|
if (requestLogId !== undefined) output.requestLogId = requestLogId;
|
|
2290
2315
|
|
|
2316
|
+
if (dispatched.result.audioTimestamps) {
|
|
2317
|
+
output.audioTimestamps = dispatched.result.audioTimestamps;
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
if (dispatched.result.durationSec !== undefined) {
|
|
2321
|
+
output.durationSec = dispatched.result.durationSec;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2291
2324
|
const log: MediaRunLog = {
|
|
2292
2325
|
tokenName: output.tokenName,
|
|
2293
|
-
response:
|
|
2326
|
+
response: audioForLog(output.audio, output.mimeType, audioBytes),
|
|
2294
2327
|
firstOutputAt: dispatched.result.firstByteAt,
|
|
2295
2328
|
steps: [
|
|
2296
2329
|
{
|
|
@@ -2301,9 +2334,15 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2301
2334
|
voice: request.voice,
|
|
2302
2335
|
language: request.language,
|
|
2303
2336
|
format: request.format,
|
|
2337
|
+
withTimestamps: input.withTimestamps,
|
|
2304
2338
|
characters: input.text.length,
|
|
2305
2339
|
},
|
|
2306
|
-
result: JSON.stringify({
|
|
2340
|
+
result: JSON.stringify({
|
|
2341
|
+
mimeType: output.mimeType,
|
|
2342
|
+
audioBytes,
|
|
2343
|
+
durationSec: output.durationSec,
|
|
2344
|
+
timedCharacters: output.audioTimestamps?.graphChars.length,
|
|
2345
|
+
}),
|
|
2307
2346
|
},
|
|
2308
2347
|
],
|
|
2309
2348
|
};
|
|
@@ -549,6 +549,9 @@ export const SpeakInput = z.object({
|
|
|
549
549
|
format: z.enum(["mp3", "wav", "pcm", "mulaw", "alaw"]).optional(),
|
|
550
550
|
// OpenAI realtime speech only: style guidance appended to the verbatim-repeat instruction.
|
|
551
551
|
instructions: z.string().min(1).max(2_000).optional(),
|
|
552
|
+
// Grok speech only: per-character timing in the output (`audioTimestamps`). OpenAI realtime has
|
|
553
|
+
// no timing data and rejects it with 400.
|
|
554
|
+
withTimestamps: z.boolean().optional(),
|
|
552
555
|
...MediaCallOptions,
|
|
553
556
|
});
|
|
554
557
|
|
|
@@ -560,6 +563,15 @@ export const SpeakOutput = z.object({
|
|
|
560
563
|
mimeType: z.string(),
|
|
561
564
|
tokenName: z.string(),
|
|
562
565
|
requestLogId: z.number().optional(),
|
|
566
|
+
// Only with `withTimestamps`: input characters (spaces, punctuation, tags included) and the
|
|
567
|
+
// `[start, end]` seconds of each, index-aligned; named as @ai-sdk/xai exposes them.
|
|
568
|
+
audioTimestamps: z
|
|
569
|
+
.object({
|
|
570
|
+
graphChars: z.array(z.string()),
|
|
571
|
+
graphTimes: z.array(z.tuple([z.number(), z.number()])),
|
|
572
|
+
})
|
|
573
|
+
.optional(),
|
|
574
|
+
durationSec: z.number().optional(),
|
|
563
575
|
});
|
|
564
576
|
|
|
565
577
|
export type SpeakOutput = z.infer<typeof SpeakOutput>;
|
|
@@ -236,7 +236,8 @@ Content-Type: application/json
|
|
|
236
236
|
"response_json_ok": null,
|
|
237
237
|
"tool_call_count": 0,
|
|
238
238
|
"is_image_generation": false,
|
|
239
|
-
"is_structured": false
|
|
239
|
+
"is_structured": false,
|
|
240
|
+
"media_kind": null
|
|
240
241
|
}
|
|
241
242
|
]
|
|
242
243
|
}
|
|
@@ -722,6 +723,7 @@ Content-Type: application/json
|
|
|
722
723
|
"language": "LANGUAGE",
|
|
723
724
|
"format": "mp3",
|
|
724
725
|
"instructions": "INSTRUCTIONS",
|
|
726
|
+
"withTimestamps": false,
|
|
725
727
|
"tokenName": "TOKENNAME",
|
|
726
728
|
"projectName": "PROJECTNAME",
|
|
727
729
|
"logger": false
|
|
@@ -284,6 +284,9 @@ export const GrokTtsRequest = z.object({
|
|
|
284
284
|
voice: z.string().min(1),
|
|
285
285
|
language: z.string().min(1),
|
|
286
286
|
format: z.string().min(1),
|
|
287
|
+
// true switches /tts to a JSON envelope with per-character timing (verified on the subscription
|
|
288
|
+
// token 2026-11-09).
|
|
289
|
+
with_timestamps: z.boolean().optional(),
|
|
287
290
|
});
|
|
288
291
|
|
|
289
292
|
export type GrokTtsRequest = z.infer<typeof GrokTtsRequest>;
|
|
@@ -361,9 +364,20 @@ export interface GrokTranscribeRequest {
|
|
|
361
364
|
signal?: AbortSignal;
|
|
362
365
|
}
|
|
363
366
|
|
|
367
|
+
/** Per-character timing of the spoken text, named as `@ai-sdk/xai` exposes it. */
|
|
368
|
+
export interface GrokAudioTimestamps {
|
|
369
|
+
/** Input characters, including spaces, punctuation and speech tags. */
|
|
370
|
+
graphChars: string[];
|
|
371
|
+
/** `[start, end]` seconds for the character at the same index. */
|
|
372
|
+
graphTimes: Array<[number, number]>;
|
|
373
|
+
}
|
|
374
|
+
|
|
364
375
|
export interface GrokSpeechResult {
|
|
365
376
|
audio: Uint8Array;
|
|
366
377
|
mediaType: string;
|
|
378
|
+
/** Only with `with_timestamps`. */
|
|
379
|
+
audioTimestamps?: GrokAudioTimestamps;
|
|
380
|
+
durationSec?: number;
|
|
367
381
|
/** Epoch ms when the response headers arrived; /tts is not streamed, so this is first byte. */
|
|
368
382
|
firstByteAt?: number;
|
|
369
383
|
}
|
|
@@ -228,6 +228,36 @@ describe("GrokVoiceClient.speak", () => {
|
|
|
228
228
|
});
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
+
it("asks for timestamps and decodes the JSON envelope into audio plus character timing", async () => {
|
|
232
|
+
const fake = fakeFetch(
|
|
233
|
+
() =>
|
|
234
|
+
new Response(
|
|
235
|
+
JSON.stringify({
|
|
236
|
+
audio: Buffer.from(mp3).toString("base64"),
|
|
237
|
+
content_type: "audio/mpeg",
|
|
238
|
+
duration: 0.5,
|
|
239
|
+
audio_timestamps: { graph_chars: ["H", "i"], graph_times: [[0.08, 0.2], [0.2, 0.5]] },
|
|
240
|
+
}),
|
|
241
|
+
{ status: 200, headers: { "content-type": "application/json" } },
|
|
242
|
+
),
|
|
243
|
+
);
|
|
244
|
+
const client = new GrokVoiceClient({ fetch: fake.impl });
|
|
245
|
+
const result = await client.speak("tok", { text: "Hi", with_timestamps: true });
|
|
246
|
+
|
|
247
|
+
const body = fake.calls[0]!.init.body;
|
|
248
|
+
expect(typeof body === "string" && JSON.parse(body)).toMatchObject({ with_timestamps: true });
|
|
249
|
+
expect(result.audio).toEqual(mp3);
|
|
250
|
+
expect(result.mediaType).toBe("audio/mpeg");
|
|
251
|
+
expect(result.durationSec).toBe(0.5);
|
|
252
|
+
expect(result.audioTimestamps).toEqual({
|
|
253
|
+
graphChars: ["H", "i"],
|
|
254
|
+
graphTimes: [
|
|
255
|
+
[0.08, 0.2],
|
|
256
|
+
[0.2, 0.5],
|
|
257
|
+
],
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
231
261
|
it("falls back to the format's media type when content-type is missing", async () => {
|
|
232
262
|
const client = new GrokVoiceClient({
|
|
233
263
|
fetch: fakeFetch(() => {
|
|
@@ -118,6 +118,19 @@ function transportError(message: string, afterSend: boolean, cause: unknown): Gr
|
|
|
118
118
|
return new GrokHttpError(classification, "", {}, { cause });
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
// `with_timestamps: true` envelope; every field nullable like @ai-sdk/xai's parser.
|
|
122
|
+
const GrokTtsTimestampsResponse = z.object({
|
|
123
|
+
audio: z.string().nullish(),
|
|
124
|
+
content_type: z.string().nullish(),
|
|
125
|
+
duration: z.number().nullish(),
|
|
126
|
+
audio_timestamps: z
|
|
127
|
+
.object({
|
|
128
|
+
graph_chars: z.array(z.string()),
|
|
129
|
+
graph_times: z.array(z.tuple([z.number(), z.number()])),
|
|
130
|
+
})
|
|
131
|
+
.nullish(),
|
|
132
|
+
});
|
|
133
|
+
|
|
121
134
|
function invalidBodyError(response: Response, message: string, cause?: unknown): GrokHttpError {
|
|
122
135
|
return new GrokHttpError(
|
|
123
136
|
{ ...classifyGrokHttpError(502, "", response.headers), message, shouldRetry: false },
|
|
@@ -127,6 +140,44 @@ function invalidBodyError(response: Response, message: string, cause?: unknown):
|
|
|
127
140
|
);
|
|
128
141
|
}
|
|
129
142
|
|
|
143
|
+
/** Decodes the `with_timestamps` JSON envelope into audio bytes plus per-character timing. */
|
|
144
|
+
async function readTimestampsBody(
|
|
145
|
+
response: Response,
|
|
146
|
+
format: string,
|
|
147
|
+
firstByteAt: number,
|
|
148
|
+
): Promise<GrokSpeechResult> {
|
|
149
|
+
let parsed: z.infer<typeof GrokTtsTimestampsResponse>;
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
parsed = GrokTtsTimestampsResponse.parse(await response.json());
|
|
153
|
+
} catch (error) {
|
|
154
|
+
throw invalidBodyError(response, "invalid timestamped TTS response", error);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const audio = new Uint8Array(Buffer.from(parsed.audio ?? "", "base64"));
|
|
158
|
+
|
|
159
|
+
if (audio.byteLength === 0) throw invalidBodyError(response, "empty audio body");
|
|
160
|
+
|
|
161
|
+
const result: GrokSpeechResult = {
|
|
162
|
+
audio,
|
|
163
|
+
mediaType:
|
|
164
|
+
parsed.content_type ?? MEDIA_TYPE_BY_FORMAT.get(format) ?? "application/octet-stream",
|
|
165
|
+
firstByteAt,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
if (parsed.audio_timestamps) {
|
|
169
|
+
result.audioTimestamps = {
|
|
170
|
+
graphChars: parsed.audio_timestamps.graph_chars,
|
|
171
|
+
graphTimes: parsed.audio_timestamps.graph_times,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (parsed.duration !== null && parsed.duration !== undefined)
|
|
176
|
+
result.durationSec = parsed.duration;
|
|
177
|
+
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
130
181
|
function audioExtension(mediaType: string): string {
|
|
131
182
|
const subtype = mediaType.toLowerCase().split(";")[0]?.split("/")[1]?.trim() ?? "";
|
|
132
183
|
|
|
@@ -203,6 +254,7 @@ export class GrokVoiceClient implements GrokVoicePort {
|
|
|
203
254
|
voice: request.voice ?? GROK_TTS_DEFAULT_VOICE,
|
|
204
255
|
language: request.language ?? GROK_TTS_DEFAULT_LANGUAGE,
|
|
205
256
|
format: request.format ?? GROK_TTS_DEFAULT_FORMAT,
|
|
257
|
+
...(request.with_timestamps === true && { with_timestamps: true }),
|
|
206
258
|
});
|
|
207
259
|
|
|
208
260
|
const headers = {
|
|
@@ -214,6 +266,8 @@ export class GrokVoiceClient implements GrokVoicePort {
|
|
|
214
266
|
const firstByteAt = Date.now();
|
|
215
267
|
const mediaType = contentMediaType(response);
|
|
216
268
|
|
|
269
|
+
if (body.with_timestamps) return readTimestampsBody(response, body.format, firstByteAt);
|
|
270
|
+
|
|
217
271
|
if (mediaType === "application/json" || mediaType?.startsWith("text/"))
|
|
218
272
|
throw invalidBodyError(response, `expected audio, got ${mediaType}`);
|
|
219
273
|
let audio: Uint8Array;
|