@cartanova/qgrid-cli 2.17.0 → 2.18.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 +18 -3
- package/bundle/dist/application/qgrid/qgrid.types.js +2 -1
- package/bundle/dist/utils/providers/common/model-cost.js +40 -2
- package/bundle/dist/utils/providers/grok/grok-types.js +3 -2
- package/bundle/dist/utils/providers/grok/grok-voice-client.js +3 -2
- package/bundle/dist/utils/providers/openai/openai-dispatcher.js +3 -2
- package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +4 -8
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +29 -4
- package/bundle/src/application/qgrid/qgrid.frame.ts +36 -3
- package/bundle/src/application/qgrid/qgrid.types.ts +2 -0
- package/bundle/src/application/sonamu.generated.http +1 -0
- package/bundle/src/utils/providers/common/model-cost.test.ts +14 -0
- package/bundle/src/utils/providers/common/model-cost.ts +56 -0
- package/bundle/src/utils/providers/grok/grok-types.ts +1 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.test.ts +3 -1
- package/bundle/src/utils/providers/grok/grok-voice-client.ts +1 -0
- package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +18 -0
- package/bundle/src/utils/providers/openai/openai-dispatcher.ts +6 -1
- package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +3 -7
- package/bundle/web-dist/client/assets/{index-Cb14ZYfq.js → index-CbElySnT.js} +3 -3
- package/bundle/web-dist/client/assets/{logs-CSL1j0RN.js → logs-BJZmjJan.js} +1 -1
- package/bundle/web-dist/client/assets/{monit-J69xfniH.js → monit-CO4TQDhe.js} +1 -1
- package/bundle/web-dist/client/assets/{routes-CdWdhivH.js → routes-D_pSsIQS.js} +1 -1
- package/bundle/web-dist/client/assets/{settings-BGa41_nL.js → settings-LKaZCi07.js} +1 -1
- package/bundle/web-dist/client/assets/{show-CSpPVL8-.js → show-BvATehjq.js} +2 -2
- package/bundle/web-dist/client/assets/{tokens-B9FeVPJk.js → tokens-D5KX_VAe.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-Tmy4lKYv.js → use-oauth-login-flow-DcqeDFdp.js} +1 -1
- package/bundle/web-dist/client/assets/{use-update-token-mutation-CGwI6TU8.js → use-update-token-mutation-IqmKULKf.js} +1 -1
- package/bundle/web-dist/client/assets/voice-BvjMZbB5.js +1 -0
- package/bundle/web-dist/client/index.html +1 -1
- package/bundle/web-dist/server/assets/{show-hBbPOUZD.js → show-B_l5dOcT.js} +2 -2
- package/bundle/web-dist/server/assets/{voice-CHoPEIfo.js → voice-BhVkiSJl.js} +20 -2
- package/bundle/web-dist/server/entry-server.generated.js +3 -3
- package/package.json +1 -1
- package/skills/qgrid/references/ai-sdk-provider-contract.md +1 -1
- package/skills/qgrid/references/grok-runtime.md +2 -0
- package/skills/qgrid/references/openai-codex-runtime.md +1 -1
- package/skills/qgrid/references/request-log-run-lifecycle.md +2 -0
- package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
- package/bundle/web-dist/client/assets/voice-BNcGUdUd.js +0 -1
|
@@ -2211,9 +2211,10 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2211
2211
|
const request = grok.transcribe!.mock.calls[0]![0] as { audio: Uint8Array; mediaType: string; model: string };
|
|
2212
2212
|
expect(Buffer.from(request.audio).toString()).toBe("RIFFfakewav");
|
|
2213
2213
|
expect(request).toMatchObject({ mediaType: "audio/wav", model: "grok-voice-transcribe-2.0" });
|
|
2214
|
+
// Priced at the Grok STT list price: $0.10/hour × 1.5 s ≈ 42 micro-USD.
|
|
2214
2215
|
expect(requestLogFinishRunMock).toHaveBeenCalledWith(
|
|
2215
2216
|
77,
|
|
2216
|
-
expect.objectContaining({ status: "succeeded", response: "hello there", cost_usd:
|
|
2217
|
+
expect.objectContaining({ status: "succeeded", response: "hello there", cost_usd: 42, cost_source: "pricing_table" }),
|
|
2217
2218
|
);
|
|
2218
2219
|
// The input audio is kept playable in the user prompt, as TTS output is in the response.
|
|
2219
2220
|
expect(requestLogCreateRunMock).toHaveBeenCalledWith(
|
|
@@ -2243,10 +2244,10 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2243
2244
|
requestLogId: 77,
|
|
2244
2245
|
});
|
|
2245
2246
|
expect(Buffer.from(out.audio, "base64")).toEqual(Buffer.from(bytes));
|
|
2246
|
-
//
|
|
2247
|
+
// Priced at the Grok TTS list price: $15 per 1M characters × 2 characters = 30 micro-USD.
|
|
2247
2248
|
expect(requestLogFinishRunMock).toHaveBeenCalledWith(
|
|
2248
2249
|
77,
|
|
2249
|
-
expect.objectContaining({ status: "succeeded", cost_usd:
|
|
2250
|
+
expect.objectContaining({ status: "succeeded", cost_usd: 30, cost_source: "pricing_table" }),
|
|
2250
2251
|
);
|
|
2251
2252
|
});
|
|
2252
2253
|
|
|
@@ -2309,8 +2310,15 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2309
2310
|
tokenName: "grok/a",
|
|
2310
2311
|
});
|
|
2311
2312
|
|
|
2312
|
-
const out = await QgridFrame.speak({
|
|
2313
|
+
const out = await QgridFrame.speak({
|
|
2314
|
+
model: "openai/gpt-realtime-2.1-mini",
|
|
2315
|
+
text: "Hi there.",
|
|
2316
|
+
instructions: "Speak warmly.",
|
|
2317
|
+
withTimestamps: true,
|
|
2318
|
+
});
|
|
2313
2319
|
|
|
2320
|
+
// The style instructions are kept as the run's system prompt for the request log.
|
|
2321
|
+
expect(requestLogCreateRunMock).toHaveBeenCalledWith(expect.objectContaining({ system_prompt: "Speak warmly." }));
|
|
2314
2322
|
expect(grok.transcribe).toHaveBeenCalledWith(expect.objectContaining({ mediaType: "audio/wav", model: "grok-voice-transcribe-2.0" }));
|
|
2315
2323
|
expect(out).toMatchObject({ timestampsSource: "aligned", durationSec: 0.5 });
|
|
2316
2324
|
expect(out.audioTimestamps?.graphChars.join("")).toBe("Hi there.");
|
|
@@ -2319,6 +2327,23 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2319
2327
|
expect(end).toBeCloseTo(0.15);
|
|
2320
2328
|
});
|
|
2321
2329
|
|
|
2330
|
+
it("keeps the OpenAI STT prompt as the run's system prompt", async () => {
|
|
2331
|
+
const transcribe = vi.fn().mockResolvedValue({
|
|
2332
|
+
result: { text: "hi", durationSec: 0.5, callId: "c", transport: "realtime-calls" },
|
|
2333
|
+
tokenName: "openai/a",
|
|
2334
|
+
});
|
|
2335
|
+
Object.assign(QgridDispatcher, { openaiDispatcher: { speak: openaiSpeak, transcribe } });
|
|
2336
|
+
|
|
2337
|
+
await QgridFrame.transcribe({
|
|
2338
|
+
model: "openai/gpt-4o-transcribe",
|
|
2339
|
+
audio: Buffer.from(wav).toString("base64"),
|
|
2340
|
+
mediaType: "audio/wav",
|
|
2341
|
+
prompt: "qgrid, Kuma",
|
|
2342
|
+
});
|
|
2343
|
+
|
|
2344
|
+
expect(requestLogCreateRunMock).toHaveBeenCalledWith(expect.objectContaining({ system_prompt: "qgrid, Kuma", media_kind: "stt" }));
|
|
2345
|
+
});
|
|
2346
|
+
|
|
2322
2347
|
it("still returns the audio when the timing step fails", async () => {
|
|
2323
2348
|
grok.transcribe!.mockRejectedValueOnce(new Error("grok down"));
|
|
2324
2349
|
|
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
type GrokMediaCost,
|
|
28
28
|
grokImageCost,
|
|
29
29
|
grokReportedCost,
|
|
30
|
+
grokSpeechCost,
|
|
31
|
+
openaiSpeechCost,
|
|
32
|
+
sttCost,
|
|
33
|
+
type VoiceCost,
|
|
30
34
|
} from "../../utils/providers/common/model-cost";
|
|
31
35
|
import {
|
|
32
36
|
type MediaDispatcher,
|
|
@@ -773,7 +777,14 @@ function imageTagForLog(b64: string, mimeType: string, alt: string | undefined):
|
|
|
773
777
|
return `<img src="data:${mimeType};base64,${b64}" alt="${safeAlt}" />`;
|
|
774
778
|
}
|
|
775
779
|
|
|
776
|
-
type MediaLogStart = {
|
|
780
|
+
type MediaLogStart = {
|
|
781
|
+
kind: MediaKind;
|
|
782
|
+
model: string;
|
|
783
|
+
prompt: string;
|
|
784
|
+
projectName?: string;
|
|
785
|
+
/** OpenAI speech style instructions or STT prompt, shown as the run's system prompt. */
|
|
786
|
+
systemPrompt?: string;
|
|
787
|
+
};
|
|
777
788
|
|
|
778
789
|
// Creating the running row is a precondition of a logged provider call, as for query.
|
|
779
790
|
async function startMediaRun(
|
|
@@ -784,6 +795,7 @@ async function startMediaRun(
|
|
|
784
795
|
|
|
785
796
|
return RequestLogModel.createRun({
|
|
786
797
|
user_prompt: start.prompt,
|
|
798
|
+
system_prompt: start.systemPrompt,
|
|
787
799
|
requested_model_name: start.model,
|
|
788
800
|
project_name: start.projectName,
|
|
789
801
|
is_image_generation: start.kind === "image",
|
|
@@ -826,7 +838,7 @@ type MediaLogSuccess = {
|
|
|
826
838
|
durationMs: number;
|
|
827
839
|
response: string;
|
|
828
840
|
steps: MediaLogSteps;
|
|
829
|
-
cost?: GrokMediaCost;
|
|
841
|
+
cost?: GrokMediaCost | VoiceCost;
|
|
830
842
|
/** Speech only: time to the first audio byte, measured from the same start as `durationMs`. */
|
|
831
843
|
ttftMs?: number;
|
|
832
844
|
};
|
|
@@ -874,7 +886,7 @@ type MediaCostFields = Pick<FinishRunParams, "cost_usd" | "cost_source"> &
|
|
|
874
886
|
function mediaCostFields(
|
|
875
887
|
kind: MediaKind,
|
|
876
888
|
model: string,
|
|
877
|
-
cost: GrokMediaCost | undefined,
|
|
889
|
+
cost: GrokMediaCost | VoiceCost | undefined,
|
|
878
890
|
): MediaCostFields {
|
|
879
891
|
if (kind === "image") {
|
|
880
892
|
return {
|
|
@@ -1103,6 +1115,7 @@ async function transcribeOpenAI(input: TranscribeInput): Promise<TranscribeOutpu
|
|
|
1103
1115
|
kind: "stt",
|
|
1104
1116
|
model: route,
|
|
1105
1117
|
prompt: audioForLog(input.audio, input.mediaType, audio.byteLength),
|
|
1118
|
+
systemPrompt: input.prompt,
|
|
1106
1119
|
projectName: input.projectName,
|
|
1107
1120
|
logger: input.logger,
|
|
1108
1121
|
} as const;
|
|
@@ -1134,6 +1147,7 @@ async function transcribeOpenAI(input: TranscribeInput): Promise<TranscribeOutpu
|
|
|
1134
1147
|
const log: MediaRunLog = {
|
|
1135
1148
|
tokenName: output.tokenName,
|
|
1136
1149
|
response: output.text,
|
|
1150
|
+
cost: sttCost(route, durationSec),
|
|
1137
1151
|
steps: [
|
|
1138
1152
|
{
|
|
1139
1153
|
toolCallId: "transcription:0",
|
|
@@ -1208,6 +1222,12 @@ async function speakOpenAI(input: SpeakInput): Promise<SpeakOutput> {
|
|
|
1208
1222
|
);
|
|
1209
1223
|
}
|
|
1210
1224
|
|
|
1225
|
+
if (input.speed !== undefined) {
|
|
1226
|
+
throw new BadRequestException(
|
|
1227
|
+
SD("qgrid.openaiVoiceInvalidRequest")("speed is available only on Grok speech"),
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1211
1231
|
const request = {
|
|
1212
1232
|
text: input.text,
|
|
1213
1233
|
model: id,
|
|
@@ -1220,6 +1240,7 @@ async function speakOpenAI(input: SpeakInput): Promise<SpeakOutput> {
|
|
|
1220
1240
|
kind: "tts",
|
|
1221
1241
|
model: route,
|
|
1222
1242
|
prompt: input.text,
|
|
1243
|
+
systemPrompt: input.instructions,
|
|
1223
1244
|
projectName: input.projectName,
|
|
1224
1245
|
logger: input.logger,
|
|
1225
1246
|
} as const;
|
|
@@ -1253,10 +1274,18 @@ async function speakOpenAI(input: SpeakInput): Promise<SpeakOutput> {
|
|
|
1253
1274
|
}
|
|
1254
1275
|
}
|
|
1255
1276
|
|
|
1277
|
+
const speechCost = openaiSpeechCost(id, usage);
|
|
1278
|
+
|
|
1279
|
+
// The alignment pass is a Grok STT call over the same audio, priced with the speech.
|
|
1280
|
+
const alignCost = alignment
|
|
1281
|
+
? (sttCost(`grok/${GROK_STT_DEFAULT_MODEL}`, alignment.durationSec)?.costUsd ?? 0)
|
|
1282
|
+
: 0;
|
|
1283
|
+
|
|
1256
1284
|
const log: MediaRunLog = {
|
|
1257
1285
|
tokenName: output.tokenName,
|
|
1258
1286
|
response: audioForLog(logAudio, "audio/wav", audio.byteLength),
|
|
1259
1287
|
firstOutputAt: firstAudioAt,
|
|
1288
|
+
cost: speechCost && { ...speechCost, costUsd: speechCost.costUsd + alignCost },
|
|
1260
1289
|
steps: [
|
|
1261
1290
|
{
|
|
1262
1291
|
toolCallId: "speech:0",
|
|
@@ -2283,6 +2312,7 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2283
2312
|
const log: MediaRunLog = {
|
|
2284
2313
|
tokenName: output.tokenName,
|
|
2285
2314
|
response: output.text,
|
|
2315
|
+
cost: sttCost(route, output.durationSec),
|
|
2286
2316
|
steps: [
|
|
2287
2317
|
{
|
|
2288
2318
|
toolCallId: "transcription:0",
|
|
@@ -2326,6 +2356,7 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2326
2356
|
language: input.language ?? GROK_TTS_DEFAULT_LANGUAGE,
|
|
2327
2357
|
format: input.format ?? GROK_TTS_DEFAULT_FORMAT,
|
|
2328
2358
|
with_timestamps: input.withTimestamps,
|
|
2359
|
+
speed: input.speed,
|
|
2329
2360
|
};
|
|
2330
2361
|
|
|
2331
2362
|
const start = {
|
|
@@ -2361,6 +2392,7 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2361
2392
|
tokenName: output.tokenName,
|
|
2362
2393
|
response: audioForLog(output.audio, output.mimeType, audioBytes),
|
|
2363
2394
|
firstOutputAt: dispatched.result.firstByteAt,
|
|
2395
|
+
cost: grokSpeechCost(input.text.length),
|
|
2364
2396
|
steps: [
|
|
2365
2397
|
{
|
|
2366
2398
|
toolCallId: "speech:0",
|
|
@@ -2371,6 +2403,7 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2371
2403
|
language: request.language,
|
|
2372
2404
|
format: request.format,
|
|
2373
2405
|
withTimestamps: input.withTimestamps,
|
|
2406
|
+
speed: input.speed,
|
|
2374
2407
|
characters: input.text.length,
|
|
2375
2408
|
},
|
|
2376
2409
|
result: JSON.stringify({
|
|
@@ -558,6 +558,8 @@ export const SpeakInput = z.object({
|
|
|
558
558
|
format: z.enum(["mp3", "wav", "pcm", "mulaw", "alaw"]).optional(),
|
|
559
559
|
// OpenAI realtime speech only: style guidance appended to the verbatim-repeat instruction.
|
|
560
560
|
instructions: z.string().min(1).max(2_000).optional(),
|
|
561
|
+
// Grok only: speaking rate, xAI's documented 0.7–1.5 (1 = normal).
|
|
562
|
+
speed: z.number().min(0.7).max(1.5).optional(),
|
|
561
563
|
// Per-character timing in the output (`audioTimestamps`). Grok returns it natively; for OpenAI
|
|
562
564
|
// realtime (no timing data) qgrid transcribes the generated audio with Grok STT and aligns the
|
|
563
565
|
// heard words to the text (`timestampsSource: "aligned"`).
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
getModelCosts,
|
|
6
6
|
grokImageCost,
|
|
7
7
|
grokReportedCost,
|
|
8
|
+
openaiSpeechCost,
|
|
9
|
+
sttCost,
|
|
8
10
|
usdFromGrokTicks,
|
|
9
11
|
} from "./model-cost";
|
|
10
12
|
|
|
@@ -407,3 +409,15 @@ describe("calculateCostUsd", () => {
|
|
|
407
409
|
);
|
|
408
410
|
});
|
|
409
411
|
});
|
|
412
|
+
|
|
413
|
+
describe("voice cost", () => {
|
|
414
|
+
it("prices OpenAI speech by token type and transcription by minute; unknown models stay unpriced", () => {
|
|
415
|
+
// The 6-second ballad clip: 226 text in, 66 text out, 131 audio out on gpt-realtime-2.1-mini.
|
|
416
|
+
const usage = { inputTokens: 226, textTokens: 66, audioTokens: 131 };
|
|
417
|
+
|
|
418
|
+
expect(openaiSpeechCost("gpt-realtime-2.1-mini", usage)?.costUsd).toBeCloseTo(0.0029, 4);
|
|
419
|
+
expect(openaiSpeechCost("gpt-realtime-9", usage)).toBeUndefined();
|
|
420
|
+
expect(sttCost("openai/gpt-4o-transcribe", 30)?.costUsd).toBeCloseTo(0.003, 6);
|
|
421
|
+
expect(sttCost("openai/gpt-4o-transcribe", undefined)).toBeUndefined();
|
|
422
|
+
});
|
|
423
|
+
});
|
|
@@ -455,3 +455,59 @@ export function calculateCostUsd(
|
|
|
455
455
|
(serviceTier === "fast" ? (OPENAI_FAST_MULTIPLIERS.get(normalizedModel) ?? 1) : 1)
|
|
456
456
|
);
|
|
457
457
|
}
|
|
458
|
+
|
|
459
|
+
/** A voice call priced from the public API list price; subscription calls have no per-call bill. */
|
|
460
|
+
export type VoiceCost = { costUsd: number; costSource: "pricing_table"; ticks?: undefined };
|
|
461
|
+
|
|
462
|
+
// Public API list prices, checked 2026-11-09. OpenAI realtime speech: USD per 1M tokens (the usage
|
|
463
|
+
// does not split cached input, so all input is charged as uncached text).
|
|
464
|
+
const OPENAI_SPEECH_PRICES = new Map([
|
|
465
|
+
["gpt-realtime-2.1", { textIn: 4, textOut: 24, audioOut: 64 }],
|
|
466
|
+
["gpt-realtime-2.1-mini", { textIn: 0.6, textOut: 2.4, audioOut: 20 }],
|
|
467
|
+
]);
|
|
468
|
+
|
|
469
|
+
// Transcription, USD per minute of audio (OpenAI's published per-minute estimates; Grok $0.10/hour).
|
|
470
|
+
const STT_USD_PER_MINUTE = new Map([
|
|
471
|
+
["openai/gpt-4o-transcribe", 0.006],
|
|
472
|
+
["openai/gpt-4o-mini-transcribe", 0.003],
|
|
473
|
+
["openai/gpt-transcribe", 0.0045],
|
|
474
|
+
["openai/gpt-live-transcribe", 0.017],
|
|
475
|
+
["openai/gpt-realtime-whisper", 0.017],
|
|
476
|
+
["openai/whisper-1", 0.006],
|
|
477
|
+
["grok/grok-voice-transcribe-2.0", 0.1 / 60],
|
|
478
|
+
]);
|
|
479
|
+
|
|
480
|
+
const GROK_TTS_USD_PER_CHARACTER = 15 / 1_000_000;
|
|
481
|
+
|
|
482
|
+
const priced = (costUsd: number): VoiceCost => ({ costUsd, costSource: "pricing_table" });
|
|
483
|
+
|
|
484
|
+
/** OpenAI realtime speech from its response usage; unknown models stay unpriced. */
|
|
485
|
+
export function openaiSpeechCost(
|
|
486
|
+
model: string,
|
|
487
|
+
usage: { inputTokens: number; textTokens: number; audioTokens: number },
|
|
488
|
+
): VoiceCost | undefined {
|
|
489
|
+
const price = OPENAI_SPEECH_PRICES.get(model);
|
|
490
|
+
|
|
491
|
+
if (!price) return undefined;
|
|
492
|
+
|
|
493
|
+
return priced(
|
|
494
|
+
(usage.inputTokens * price.textIn +
|
|
495
|
+
usage.textTokens * price.textOut +
|
|
496
|
+
usage.audioTokens * price.audioOut) /
|
|
497
|
+
1_000_000,
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** Transcription by audio length; unknown models or a missing duration stay unpriced. */
|
|
502
|
+
export function sttCost(route: string, durationSec: number | undefined): VoiceCost | undefined {
|
|
503
|
+
const perMinute = STT_USD_PER_MINUTE.get(route);
|
|
504
|
+
|
|
505
|
+
return perMinute === undefined || durationSec === undefined
|
|
506
|
+
? undefined
|
|
507
|
+
: priced((perMinute * durationSec) / 60);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** Grok `/tts` by input characters. */
|
|
511
|
+
export function grokSpeechCost(characters: number): VoiceCost {
|
|
512
|
+
return priced(characters * GROK_TTS_USD_PER_CHARACTER);
|
|
513
|
+
}
|
|
@@ -300,6 +300,7 @@ export const GrokTtsRequest = z.object({
|
|
|
300
300
|
// true switches /tts to a JSON envelope with per-character timing (verified on the subscription
|
|
301
301
|
// token 2026-11-09).
|
|
302
302
|
with_timestamps: z.boolean().optional(),
|
|
303
|
+
speed: z.number().optional(),
|
|
303
304
|
});
|
|
304
305
|
|
|
305
306
|
export type GrokTtsRequest = z.infer<typeof GrokTtsRequest>;
|
|
@@ -208,7 +208,7 @@ describe("GrokVoiceClient.speak", () => {
|
|
|
208
208
|
});
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
-
it("passes explicit language and
|
|
211
|
+
it("passes explicit language, format and speed and strips content-type parameters", async () => {
|
|
212
212
|
const fake = fakeFetch(
|
|
213
213
|
() =>
|
|
214
214
|
new Response(mp3, { status: 200, headers: { "content-type": "audio/wav; codecs=1" } }),
|
|
@@ -219,12 +219,14 @@ describe("GrokVoiceClient.speak", () => {
|
|
|
219
219
|
voice: "eve",
|
|
220
220
|
language: "fr",
|
|
221
221
|
format: "wav",
|
|
222
|
+
speed: 0.8,
|
|
222
223
|
});
|
|
223
224
|
expect(result.mediaType).toBe("audio/wav");
|
|
224
225
|
const body = fake.calls[0]!.init.body;
|
|
225
226
|
expect(typeof body === "string" && JSON.parse(body)).toMatchObject({
|
|
226
227
|
language: "fr",
|
|
227
228
|
format: "wav",
|
|
229
|
+
speed: 0.8,
|
|
228
230
|
});
|
|
229
231
|
});
|
|
230
232
|
|
|
@@ -255,6 +255,7 @@ export class GrokVoiceClient implements GrokVoicePort {
|
|
|
255
255
|
language: request.language ?? GROK_TTS_DEFAULT_LANGUAGE,
|
|
256
256
|
format: request.format ?? GROK_TTS_DEFAULT_FORMAT,
|
|
257
257
|
with_timestamps: request.with_timestamps,
|
|
258
|
+
speed: request.speed,
|
|
258
259
|
});
|
|
259
260
|
|
|
260
261
|
const headers = {
|
|
@@ -251,6 +251,24 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
251
251
|
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
+
it("re-judges a token updated during its quota lookup instead of reporting it over quota", async () => {
|
|
255
|
+
let finishOld!: (value: Response) => void;
|
|
256
|
+
const quota = (percent: number) => new Response(JSON.stringify({
|
|
257
|
+
rate_limits: { primary_window: { used_percent: percent } },
|
|
258
|
+
}));
|
|
259
|
+
const fetchMock = vi.fn()
|
|
260
|
+
.mockImplementationOnce(() => new Promise((resolve) => { finishOld = resolve; }))
|
|
261
|
+
.mockResolvedValueOnce(quota(65));
|
|
262
|
+
const d = new OpenAIDispatcher(config(), { fetch: fetchMock });
|
|
263
|
+
await d.onTokenAdded(1, "one", credentials, 100);
|
|
264
|
+
const selection = d.selectToken(1, true, new AbortController().signal);
|
|
265
|
+
await vi.waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(1));
|
|
266
|
+
await d.onTokenUpdated(1, "one", { ...credentials, accessToken: "refreshed" }, 100);
|
|
267
|
+
finishOld(quota(65));
|
|
268
|
+
await expect(selection).resolves.toMatchObject({ tokenId: 1 });
|
|
269
|
+
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
270
|
+
});
|
|
271
|
+
|
|
254
272
|
it("rejects unsupported image backgrounds", () => {
|
|
255
273
|
expect(QueryInput.safeParse({
|
|
256
274
|
prompt: "a circle", imageGeneration: true,
|
|
@@ -1075,8 +1075,13 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
1075
1075
|
if (token.quotaThreshold === null || token.quotaThreshold === undefined) return true;
|
|
1076
1076
|
const generation = token.generation;
|
|
1077
1077
|
const result = await readOpenAIQuotaUsage(async () => this.getRateLimitsByTokenId(id, signal));
|
|
1078
|
+
const current = this.tokenMetadata.get(id);
|
|
1078
1079
|
|
|
1079
|
-
|
|
1080
|
+
// A token update (credential refresh, sync) landed mid-lookup: judge the updated token
|
|
1081
|
+
// instead of reporting it over quota.
|
|
1082
|
+
if (current !== token || token.generation !== generation) {
|
|
1083
|
+
return current?.active ? this.isQuotaEligible(id, current, signal) : false;
|
|
1084
|
+
}
|
|
1080
1085
|
|
|
1081
1086
|
if (result.kind === "lookup_failed") {
|
|
1082
1087
|
this.quotaBlocked.delete(id);
|
|
@@ -76,14 +76,10 @@ export const OPENAI_TRANSCRIPTION_MODELS_WITHOUT_PROMPT: ReadonlySet<string> = n
|
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Text-to-speech (realtime conversational) ids. Verbatim fidelity on the 2026-10-17 matrix:
|
|
79
|
-
* gpt-realtime-2.1-mini 13/13, gpt-realtime-2.1 12/13 (one paraphrase)
|
|
80
|
-
*
|
|
79
|
+
* gpt-realtime-2.1-mini 13/13, gpt-realtime-2.1 12/13 (one paraphrase). Default stays 2.1-mini.
|
|
80
|
+
* gpt-realtime-1.5 was removed on 2026-11-09: it answered the text instead of repeating it (6/13).
|
|
81
81
|
*/
|
|
82
|
-
export const OPENAI_SPEECH_MODELS = [
|
|
83
|
-
"gpt-realtime-2.1-mini",
|
|
84
|
-
"gpt-realtime-2.1",
|
|
85
|
-
"gpt-realtime-1.5",
|
|
86
|
-
] as const;
|
|
82
|
+
export const OPENAI_SPEECH_MODELS = ["gpt-realtime-2.1-mini", "gpt-realtime-2.1"] as const;
|
|
87
83
|
|
|
88
84
|
/**
|
|
89
85
|
* A minimal Opus-only SDP offer. Codex sends a real WebRTC offer; qgrid has no RTP peer and only
|