@cartanova/qgrid-cli 2.15.3 → 2.15.4
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 +154 -8
- package/bundle/dist/application/qgrid/qgrid.types.js +6 -3
- package/bundle/dist/i18n/en.js +2 -1
- package/bundle/dist/i18n/ko.js +2 -1
- package/bundle/dist/utils/providers/openai/openai-backend-protocol.js +6 -54
- package/bundle/dist/utils/providers/openai/openai-direct-client.js +2 -2
- package/bundle/dist/utils/providers/openai/openai-dispatcher.js +47 -19
- package/bundle/dist/utils/providers/openai/openai-image-generation.js +1 -2
- package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +389 -0
- package/bundle/dist/utils/providers/openai/openai-voice-client.js +456 -0
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +6 -6
- package/bundle/src/application/qgrid/qgrid.frame.ts +213 -9
- package/bundle/src/application/qgrid/qgrid.types.ts +14 -2
- package/bundle/src/application/sonamu.generated.http +2 -0
- package/bundle/src/i18n/en.ts +1 -0
- package/bundle/src/i18n/ko.ts +1 -0
- package/bundle/src/utils/providers/openai/openai-backend-protocol.test.ts +8 -69
- package/bundle/src/utils/providers/openai/openai-backend-protocol.ts +7 -86
- package/bundle/src/utils/providers/openai/openai-direct-client.test.ts +0 -15
- package/bundle/src/utils/providers/openai/openai-direct-client.ts +3 -1
- package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +19 -93
- package/bundle/src/utils/providers/openai/openai-dispatcher.ts +98 -47
- package/bundle/src/utils/providers/openai/openai-image-generation.test.ts +6 -4
- package/bundle/src/utils/providers/openai/openai-image-generation.ts +0 -6
- package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +550 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +576 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.ts +738 -0
- package/bundle/web-dist/client/assets/{index-BakMhnHZ.js → index-CRdZwZsw.js} +3 -3
- package/bundle/web-dist/client/assets/{logs-Dw-GrMuH.js → logs-DyLC_2Rf.js} +1 -1
- package/bundle/web-dist/client/assets/{monit-BaFFiVKs.js → monit-C0hO3Fy6.js} +1 -1
- package/bundle/web-dist/client/assets/{routes-R1xBZYVT.js → routes-DTw4jsHI.js} +1 -1
- package/bundle/web-dist/client/assets/{settings-Bw_NXAx8.js → settings-Dg-1zSMq.js} +1 -1
- package/bundle/web-dist/client/assets/{show-BH7nfFtF.js → show-BmqUEs1O.js} +1 -1
- package/bundle/web-dist/client/assets/{tokens-BPmRr7mD.js → tokens-FQ82u55y.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-B_MGbC3a.js → use-oauth-login-flow-BXmbUSjc.js} +1 -1
- package/bundle/web-dist/client/assets/{use-update-token-mutation-Dcq7Yv2R.js → use-update-token-mutation-BWlMl3qg.js} +1 -1
- package/bundle/web-dist/client/index.html +1 -1
- package/bundle/web-dist/server/assets/{logs-6289J29J.js → logs-WZMx5ErO.js} +3 -3
- package/bundle/web-dist/server/assets/{monit-YVvwJuAF.js → monit-Bf6U1Xp5.js} +2 -2
- package/bundle/web-dist/server/assets/{plus-z5Hy__3C.js → plus-BwpfWi3W.js} +1 -1
- package/bundle/web-dist/server/assets/{refresh-cw-CNm0CERy.js → refresh-cw-Xk9nLu8E.js} +1 -1
- package/bundle/web-dist/server/assets/{request-model-DIuPZZwu.js → request-model-ByadPBS5.js} +1 -1
- package/bundle/web-dist/server/assets/{routes-DVWRvqn0.js → routes-WFysbWfc.js} +3 -3
- package/bundle/web-dist/server/assets/{services.generated-CqS8DCjT.js → services.generated-Bej_fJ74.js} +2 -0
- package/bundle/web-dist/server/assets/{settings-CXwnKiMG.js → settings-DnAbfheS.js} +3 -3
- package/bundle/web-dist/server/assets/{show-G1t8dOEh.js → show-DvpdOIGn.js} +2 -2
- package/bundle/web-dist/server/assets/{tokens-Di1vDwm5.js → tokens-CAc4t_kZ.js} +4 -4
- package/bundle/web-dist/server/assets/{use-oauth-login-flow-BUAcW_pK.js → use-oauth-login-flow-Cxm_7Qg6.js} +1 -1
- package/bundle/web-dist/server/assets/{use-update-token-mutation-oH0O0n-g.js → use-update-token-mutation-DnxqIThp.js} +1 -1
- package/bundle/web-dist/server/entry-server.generated.js +8 -8
- package/package.json +1 -1
- package/skills/qgrid/SKILL.md +5 -5
- package/skills/qgrid/references/ai-sdk-provider-contract.md +4 -0
- package/skills/qgrid/references/decision-rationale.md +13 -3
- package/skills/qgrid/references/openai-codex-runtime.md +17 -5
- package/skills/qgrid/references/request-log-run-lifecycle.md +2 -2
- package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
- package/skills/qgrid/references/verification-and-debugging.md +3 -3
|
@@ -70,11 +70,18 @@ import {
|
|
|
70
70
|
openAICallbackRedirectUri,
|
|
71
71
|
startOpenAICallbackRelay,
|
|
72
72
|
} from "../../utils/providers/openai/openai-callback-relay";
|
|
73
|
+
import { type OpenAIDispatcher } from "../../utils/providers/openai/openai-dispatcher";
|
|
73
74
|
import {
|
|
74
75
|
buildOpenAIAuthUrl,
|
|
75
76
|
exchangeOpenAICode,
|
|
76
77
|
generateOpenAIPKCE,
|
|
77
78
|
} from "../../utils/providers/openai/openai-oauth";
|
|
79
|
+
import {
|
|
80
|
+
OPENAI_REALTIME_DEFAULT_SPEECH_MODEL,
|
|
81
|
+
OPENAI_REALTIME_DEFAULT_TRANSCRIPTION_MODEL,
|
|
82
|
+
OPENAI_REALTIME_DEFAULT_VOICE,
|
|
83
|
+
} from "../../utils/providers/openai/openai-realtime-protocol";
|
|
84
|
+
import { OpenAIVoiceInputError } from "../../utils/providers/openai/openai-voice-client";
|
|
78
85
|
import {
|
|
79
86
|
type FinishRunParams,
|
|
80
87
|
MICRO_USD,
|
|
@@ -364,8 +371,10 @@ function rejectImageGenerationStream(args: QueryInput): void {
|
|
|
364
371
|
|
|
365
372
|
function rejectInvalidImageQuery(args: QueryInput): void {
|
|
366
373
|
const standalone = args.model === `openai/${CODEX_IMAGE_GENERATION_MODEL}`;
|
|
374
|
+
// OpenAI chat models also run explicit image requests through standalone Images.
|
|
375
|
+
const openaiImage = args.imageGeneration === true && args.model?.startsWith("openai/") === true;
|
|
367
376
|
|
|
368
|
-
if (!standalone && args.imageGeneration !== "auto") return;
|
|
377
|
+
if (!standalone && !openaiImage && args.imageGeneration !== "auto") return;
|
|
369
378
|
|
|
370
379
|
if (standalone && args.imageGeneration !== true) {
|
|
371
380
|
throw new BadRequestException(
|
|
@@ -378,7 +387,7 @@ function rejectInvalidImageQuery(args: QueryInput): void {
|
|
|
378
387
|
if (args.tools?.length || args.jsonSchema !== undefined) {
|
|
379
388
|
throw new BadRequestException(
|
|
380
389
|
SD("error.detail")(
|
|
381
|
-
"qgrid:
|
|
390
|
+
"qgrid: OpenAI and automatic image generation do not support caller tools or structured output.",
|
|
382
391
|
),
|
|
383
392
|
);
|
|
384
393
|
}
|
|
@@ -388,9 +397,7 @@ function rejectInvalidImageQuery(args: QueryInput): void {
|
|
|
388
397
|
args.imageGenerationOptions.outputFormat !== "png"
|
|
389
398
|
) {
|
|
390
399
|
throw new BadRequestException(
|
|
391
|
-
SD("error.detail")(
|
|
392
|
-
"qgrid: automatic and standalone image generation only support PNG output.",
|
|
393
|
-
),
|
|
400
|
+
SD("error.detail")("qgrid: OpenAI and automatic image generation only support PNG output."),
|
|
394
401
|
);
|
|
395
402
|
}
|
|
396
403
|
}
|
|
@@ -542,6 +549,25 @@ function grokVoice(): VoiceDispatcher {
|
|
|
542
549
|
return { transcribe: transcribe.bind(dispatcher), speak: speak.bind(dispatcher) };
|
|
543
550
|
}
|
|
544
551
|
|
|
552
|
+
function openaiVoice(): OpenAIDispatcher {
|
|
553
|
+
const dispatcher = QgridDispatcher.openaiDispatcher;
|
|
554
|
+
|
|
555
|
+
if (!dispatcher) {
|
|
556
|
+
throw QgridDispatcher.startupState.openai === "failed"
|
|
557
|
+
? new InternalServerErrorException(SD("qgrid.dispatcherFailed")("OpenAI"))
|
|
558
|
+
: new ServiceUnavailableException(SD("qgrid.dispatcherStarting")("OpenAI"));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return dispatcher;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
type VoiceProvider = "grok" | "openai";
|
|
565
|
+
|
|
566
|
+
/** Voice endpoints route by model prefix; no model means Grok, the original provider. */
|
|
567
|
+
function voiceProvider(model: string | undefined): VoiceProvider {
|
|
568
|
+
return model?.startsWith("openai/") ? "openai" : "grok";
|
|
569
|
+
}
|
|
570
|
+
|
|
545
571
|
class TooManyRequestsException extends SoException {
|
|
546
572
|
constructor(message: LocalizedString) {
|
|
547
573
|
super(429, message);
|
|
@@ -580,6 +606,10 @@ function throwGrokCallerError(cause: unknown): never {
|
|
|
580
606
|
throw new BadRequestException(SD("qgrid.grokInvalidRequest")(cause.message));
|
|
581
607
|
}
|
|
582
608
|
|
|
609
|
+
if (cause instanceof OpenAIVoiceInputError) {
|
|
610
|
+
throw new BadRequestException(SD("qgrid.openaiVoiceInvalidRequest")(cause.message));
|
|
611
|
+
}
|
|
612
|
+
|
|
583
613
|
if (cause instanceof GrokContentPolicyError) {
|
|
584
614
|
throw new BadRequestException(SD("qgrid.grokContentPolicy")(cause.message));
|
|
585
615
|
}
|
|
@@ -654,16 +684,23 @@ function parseMediaInput<S extends z.ZodType>(schema: S, value: z.input<S>): z.i
|
|
|
654
684
|
|
|
655
685
|
async function resolveGrokTokenSelection(
|
|
656
686
|
tokenName: string | undefined,
|
|
687
|
+
): Promise<MediaTokenSelection> {
|
|
688
|
+
return resolveMediaTokenSelection("grok", tokenName);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
async function resolveMediaTokenSelection(
|
|
692
|
+
provider: VoiceProvider,
|
|
693
|
+
tokenName: string | undefined,
|
|
657
694
|
): Promise<MediaTokenSelection> {
|
|
658
695
|
if (!tokenName) return {};
|
|
659
696
|
|
|
660
|
-
if (!tokenName.startsWith(
|
|
697
|
+
if (!tokenName.startsWith(`${provider}/`)) {
|
|
661
698
|
throw new BadRequestException(
|
|
662
699
|
SD("error.detail")("Token provider does not match model provider"),
|
|
663
700
|
);
|
|
664
701
|
}
|
|
665
702
|
|
|
666
|
-
const token = await TokenModel.findActiveByProviderAndName("A",
|
|
703
|
+
const token = await TokenModel.findActiveByProviderAndName("A", provider, tokenName);
|
|
667
704
|
|
|
668
705
|
if (!token) {
|
|
669
706
|
throw new BadRequestException(SD("error.detail")(`Active token not found: ${tokenName}`));
|
|
@@ -678,9 +715,18 @@ interface RoutedModelId {
|
|
|
678
715
|
}
|
|
679
716
|
|
|
680
717
|
function routeModelId(model: string | undefined, fallback: string): RoutedModelId {
|
|
681
|
-
|
|
718
|
+
return routeProviderModelId("grok", model, fallback);
|
|
719
|
+
}
|
|
682
720
|
|
|
683
|
-
|
|
721
|
+
function routeProviderModelId(
|
|
722
|
+
provider: VoiceProvider,
|
|
723
|
+
model: string | undefined,
|
|
724
|
+
fallback: string,
|
|
725
|
+
): RoutedModelId {
|
|
726
|
+
const prefix = `${provider}/`;
|
|
727
|
+
const id = model ? model.slice(prefix.length) : fallback;
|
|
728
|
+
|
|
729
|
+
return { id, route: `${prefix}${id}` };
|
|
684
730
|
}
|
|
685
731
|
|
|
686
732
|
type GeneratedImage = GenerateImagesOutput["images"][number];
|
|
@@ -1012,6 +1058,159 @@ async function finishVideoRun(
|
|
|
1012
1058
|
|
|
1013
1059
|
const GROK_TTS_LOG_MODEL = "grok/tts";
|
|
1014
1060
|
|
|
1061
|
+
/**
|
|
1062
|
+
* OpenAI realtime transcription (openai/<id>): /realtime/calls + sideband, the Codex shape. The
|
|
1063
|
+
* server reports no language; `durationSec` is computed from the PCM qgrid sent.
|
|
1064
|
+
*/
|
|
1065
|
+
async function transcribeOpenAI(input: TranscribeInput): Promise<TranscribeOutput> {
|
|
1066
|
+
const dispatcher = openaiVoice();
|
|
1067
|
+
const selection = await resolveMediaTokenSelection("openai", input.tokenName);
|
|
1068
|
+
|
|
1069
|
+
const { id, route } = routeProviderModelId(
|
|
1070
|
+
"openai",
|
|
1071
|
+
input.model,
|
|
1072
|
+
OPENAI_REALTIME_DEFAULT_TRANSCRIPTION_MODEL,
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
const audio = new Uint8Array(Buffer.from(input.audio, "base64"));
|
|
1076
|
+
|
|
1077
|
+
const start = {
|
|
1078
|
+
kind: "stt",
|
|
1079
|
+
model: route,
|
|
1080
|
+
prompt: `[audio ${input.mediaType} ${audio.byteLength} bytes]`,
|
|
1081
|
+
projectName: input.projectName,
|
|
1082
|
+
logger: input.logger,
|
|
1083
|
+
} as const;
|
|
1084
|
+
|
|
1085
|
+
return runMediaEndpoint(start, async (signal, requestLogId) => {
|
|
1086
|
+
const dispatched = await dispatcher.transcribe({
|
|
1087
|
+
audio,
|
|
1088
|
+
mediaType: input.mediaType,
|
|
1089
|
+
model: id,
|
|
1090
|
+
language: input.language,
|
|
1091
|
+
prompt: input.prompt,
|
|
1092
|
+
signal,
|
|
1093
|
+
...selection,
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
const { text, durationSec, callId, transport, fallbackReason } = dispatched.result;
|
|
1097
|
+
|
|
1098
|
+
const output: TranscribeOutput = {
|
|
1099
|
+
text,
|
|
1100
|
+
durationSec,
|
|
1101
|
+
model: route,
|
|
1102
|
+
tokenName: dispatched.tokenName,
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
if (input.language) output.language = input.language;
|
|
1106
|
+
|
|
1107
|
+
if (requestLogId !== undefined) output.requestLogId = requestLogId;
|
|
1108
|
+
|
|
1109
|
+
const log: MediaRunLog = {
|
|
1110
|
+
tokenName: output.tokenName,
|
|
1111
|
+
response: output.text,
|
|
1112
|
+
steps: [
|
|
1113
|
+
{
|
|
1114
|
+
toolCallId: "transcription:0",
|
|
1115
|
+
args: {
|
|
1116
|
+
kind: "stt",
|
|
1117
|
+
model: route,
|
|
1118
|
+
transport,
|
|
1119
|
+
fallbackReason,
|
|
1120
|
+
mediaType: input.mediaType,
|
|
1121
|
+
audioBytes: audio.byteLength,
|
|
1122
|
+
language: input.language,
|
|
1123
|
+
prompt: input.prompt,
|
|
1124
|
+
durationSec,
|
|
1125
|
+
},
|
|
1126
|
+
result: JSON.stringify({ text, durationSec, callId }),
|
|
1127
|
+
},
|
|
1128
|
+
],
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
return { output, log };
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* OpenAI realtime speech (openai/<id>): a conversational realtime model repeating the text over
|
|
1137
|
+
* the direct realtime socket. Output is PCM16 24 kHz, wrapped as WAV unless `format` is pcm.
|
|
1138
|
+
*/
|
|
1139
|
+
async function speakOpenAI(input: SpeakInput): Promise<SpeakOutput> {
|
|
1140
|
+
const dispatcher = openaiVoice();
|
|
1141
|
+
const selection = await resolveMediaTokenSelection("openai", input.tokenName);
|
|
1142
|
+
|
|
1143
|
+
const { id, route } = routeProviderModelId(
|
|
1144
|
+
"openai",
|
|
1145
|
+
input.model,
|
|
1146
|
+
OPENAI_REALTIME_DEFAULT_SPEECH_MODEL,
|
|
1147
|
+
);
|
|
1148
|
+
|
|
1149
|
+
if (input.format !== undefined && input.format !== "wav" && input.format !== "pcm") {
|
|
1150
|
+
throw new BadRequestException(
|
|
1151
|
+
SD("qgrid.openaiVoiceInvalidRequest")(
|
|
1152
|
+
`format ${input.format} is not available; realtime speech returns wav or pcm`,
|
|
1153
|
+
),
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
const request = {
|
|
1158
|
+
text: input.text,
|
|
1159
|
+
model: id,
|
|
1160
|
+
voice: input.voice ?? OPENAI_REALTIME_DEFAULT_VOICE,
|
|
1161
|
+
instructions: input.instructions,
|
|
1162
|
+
format: input.format,
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
const start = {
|
|
1166
|
+
kind: "tts",
|
|
1167
|
+
model: route,
|
|
1168
|
+
prompt: input.text,
|
|
1169
|
+
projectName: input.projectName,
|
|
1170
|
+
logger: input.logger,
|
|
1171
|
+
} as const;
|
|
1172
|
+
|
|
1173
|
+
return runMediaEndpoint(start, async (signal, requestLogId) => {
|
|
1174
|
+
const dispatched = await dispatcher.speak({ ...request, signal, ...selection });
|
|
1175
|
+
const { audio, mediaType, transcript, usage } = dispatched.result;
|
|
1176
|
+
|
|
1177
|
+
const output: SpeakOutput = {
|
|
1178
|
+
audio: Buffer.from(audio).toString("base64"),
|
|
1179
|
+
mimeType: mediaType,
|
|
1180
|
+
tokenName: dispatched.tokenName,
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
if (requestLogId !== undefined) output.requestLogId = requestLogId;
|
|
1184
|
+
|
|
1185
|
+
const log: MediaRunLog = {
|
|
1186
|
+
tokenName: output.tokenName,
|
|
1187
|
+
response: `[audio ${mediaType} ${audio.byteLength} bytes]`,
|
|
1188
|
+
steps: [
|
|
1189
|
+
{
|
|
1190
|
+
toolCallId: "speech:0",
|
|
1191
|
+
args: {
|
|
1192
|
+
kind: "tts",
|
|
1193
|
+
model: route,
|
|
1194
|
+
transport: "realtime-ws",
|
|
1195
|
+
voice: request.voice,
|
|
1196
|
+
format: request.format ?? "wav",
|
|
1197
|
+
instructions: input.instructions,
|
|
1198
|
+
characters: input.text.length,
|
|
1199
|
+
},
|
|
1200
|
+
result: JSON.stringify({
|
|
1201
|
+
mimeType: mediaType,
|
|
1202
|
+
audioBytes: audio.byteLength,
|
|
1203
|
+
transcript,
|
|
1204
|
+
usage,
|
|
1205
|
+
}),
|
|
1206
|
+
},
|
|
1207
|
+
],
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
return { output, log };
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1015
1214
|
class QgridFrameClass extends BaseFrameClass {
|
|
1016
1215
|
constructor() {
|
|
1017
1216
|
super("Qgrid");
|
|
@@ -1962,6 +2161,9 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
1962
2161
|
@api({ httpMethod: "POST", clients: ["axios", "tanstack-mutation"] })
|
|
1963
2162
|
async transcribe(params: TranscribeInput): Promise<TranscribeOutput> {
|
|
1964
2163
|
const input = parseMediaInput(TranscribeInput, params);
|
|
2164
|
+
const provider = voiceProvider(input.model);
|
|
2165
|
+
|
|
2166
|
+
if (provider === "openai") return transcribeOpenAI(input);
|
|
1965
2167
|
const voice = grokVoice();
|
|
1966
2168
|
const selection = await resolveGrokTokenSelection(input.tokenName);
|
|
1967
2169
|
const { id, route } = routeModelId(input.model, GROK_STT_DEFAULT_MODEL);
|
|
@@ -2026,6 +2228,8 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2026
2228
|
@api({ httpMethod: "POST", clients: ["axios", "tanstack-mutation"] })
|
|
2027
2229
|
async speak(params: SpeakInput): Promise<SpeakOutput> {
|
|
2028
2230
|
const input = parseMediaInput(SpeakInput, params);
|
|
2231
|
+
|
|
2232
|
+
if (voiceProvider(input.model) === "openai") return speakOpenAI(input);
|
|
2029
2233
|
const voice = grokVoice();
|
|
2030
2234
|
const selection = await resolveGrokTokenSelection(input.tokenName);
|
|
2031
2235
|
const route = input.model ?? GROK_TTS_LOG_MODEL;
|
|
@@ -502,8 +502,13 @@ export const VideoStatusOutput = z.object({
|
|
|
502
502
|
|
|
503
503
|
export type VideoStatusOutput = z.infer<typeof VideoStatusOutput>;
|
|
504
504
|
|
|
505
|
+
// Voice endpoints accept Grok and OpenAI ids; the frame routes by prefix.
|
|
506
|
+
const VoiceModelId = z
|
|
507
|
+
.string()
|
|
508
|
+
.regex(/^(grok|openai)\/[A-Za-z0-9._-]+$/, "model must be grok/<id> or openai/<id>");
|
|
509
|
+
|
|
505
510
|
export const TranscribeInput = z.object({
|
|
506
|
-
model:
|
|
511
|
+
model: VoiceModelId.optional(),
|
|
507
512
|
// Base64 audio bytes (no data: prefix), at most MEDIA_MAX_INLINE_BYTES decoded.
|
|
508
513
|
audio: z
|
|
509
514
|
.string()
|
|
@@ -515,6 +520,11 @@ export const TranscribeInput = z.object({
|
|
|
515
520
|
),
|
|
516
521
|
mediaType: z.string().regex(/^audio\/[A-Za-z0-9.+-]+$/, "mediaType must be audio/*"),
|
|
517
522
|
language: z.string().min(1).max(16).optional(),
|
|
523
|
+
// OpenAI realtime transcription only: domain vocabulary or style hint for the model.
|
|
524
|
+
// Honored by gpt-4o-mini-transcribe, gpt-4o-transcribe, gpt-transcribe, gpt-live-transcribe.
|
|
525
|
+
// gpt-realtime-whisper rejects it (400 before the upstream call); whisper-1 accepts it but the
|
|
526
|
+
// upstream ignores it, so spelling is not steered.
|
|
527
|
+
prompt: z.string().min(1).max(2_000).optional(),
|
|
518
528
|
...MediaCallOptions,
|
|
519
529
|
});
|
|
520
530
|
|
|
@@ -532,11 +542,13 @@ export const TranscribeOutput = z.object({
|
|
|
532
542
|
export type TranscribeOutput = z.infer<typeof TranscribeOutput>;
|
|
533
543
|
|
|
534
544
|
export const SpeakInput = z.object({
|
|
535
|
-
model:
|
|
545
|
+
model: VoiceModelId.optional(),
|
|
536
546
|
text: z.string().min(1).max(15_000),
|
|
537
547
|
voice: z.string().min(1).max(64).optional(),
|
|
538
548
|
language: z.string().min(1).max(16).optional(),
|
|
539
549
|
format: z.enum(["mp3", "wav", "pcm", "mulaw", "alaw"]).optional(),
|
|
550
|
+
// OpenAI realtime speech only: style guidance appended to the verbatim-repeat instruction.
|
|
551
|
+
instructions: z.string().min(1).max(2_000).optional(),
|
|
540
552
|
...MediaCallOptions,
|
|
541
553
|
});
|
|
542
554
|
|
|
@@ -702,6 +702,7 @@ Content-Type: application/json
|
|
|
702
702
|
"audio": "AUDIO",
|
|
703
703
|
"mediaType": "MEDIATYPE",
|
|
704
704
|
"language": "LANGUAGE",
|
|
705
|
+
"prompt": "PROMPT",
|
|
705
706
|
"tokenName": "TOKENNAME",
|
|
706
707
|
"projectName": "PROJECTNAME",
|
|
707
708
|
"logger": false
|
|
@@ -720,6 +721,7 @@ Content-Type: application/json
|
|
|
720
721
|
"voice": "VOICE",
|
|
721
722
|
"language": "LANGUAGE",
|
|
722
723
|
"format": "mp3",
|
|
724
|
+
"instructions": "INSTRUCTIONS",
|
|
723
725
|
"tokenName": "TOKENNAME",
|
|
724
726
|
"projectName": "PROJECTNAME",
|
|
725
727
|
"logger": false
|
package/bundle/src/i18n/en.ts
CHANGED
|
@@ -58,6 +58,7 @@ export default {
|
|
|
58
58
|
"qgrid.grokContentPolicy": (detail: string) =>
|
|
59
59
|
`Grok generation blocked by content policy: ${detail}`,
|
|
60
60
|
"qgrid.grokInvalidRequest": (detail: string) => `Invalid Grok request: ${detail}`,
|
|
61
|
+
"qgrid.openaiVoiceInvalidRequest": (detail: string) => `Invalid OpenAI voice request: ${detail}`,
|
|
61
62
|
"qgrid.grokLoginFailed": (detail: string) => `Grok login failed: ${detail}`,
|
|
62
63
|
"qgrid.grokNotOAuthToken": "Grok login returned credentials that are not an xAI OAuth token",
|
|
63
64
|
"qgrid.grokNoWorkers": (detail: string) => `No Grok token is available: ${detail}`,
|
package/bundle/src/i18n/ko.ts
CHANGED
|
@@ -59,6 +59,7 @@ export default {
|
|
|
59
59
|
"qgrid.grokContentPolicy": (detail: string) =>
|
|
60
60
|
`콘텐츠 정책 위반으로 Grok 생성이 차단되었습니다: ${detail}`,
|
|
61
61
|
"qgrid.grokInvalidRequest": (detail: string) => `잘못된 Grok 요청입니다: ${detail}`,
|
|
62
|
+
"qgrid.openaiVoiceInvalidRequest": (detail: string) => `잘못된 OpenAI 음성 요청입니다: ${detail}`,
|
|
62
63
|
"qgrid.grokLoginFailed": (detail: string) => `Grok 로그인에 실패했습니다: ${detail}`,
|
|
63
64
|
"qgrid.grokNotOAuthToken": "Grok 로그인 결과가 xAI OAuth 토큰이 아닙니다",
|
|
64
65
|
"qgrid.grokNoWorkers": (detail: string) => `사용 가능한 Grok 토큰이 없습니다: ${detail}`,
|
|
@@ -4,54 +4,23 @@ import {
|
|
|
4
4
|
buildCodexIdentityHeaders,
|
|
5
5
|
buildOpenAIResponsesRequest,
|
|
6
6
|
codexCliUserAgent,
|
|
7
|
+
imageMimeType,
|
|
7
8
|
normalizeOpenAIEvent,
|
|
8
9
|
} from "./openai-backend-protocol";
|
|
9
10
|
|
|
10
11
|
describe("OpenAI Codex backend protocol", () => {
|
|
11
|
-
it.each(["png", "jpeg", "webp"])("preserves reported hosted %s generation settings", (output_format) => {
|
|
12
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
13
|
-
type: "image_generation_call", result: "aGVsbG8=", output_format,
|
|
14
|
-
size: "841x1870", quality: "low", background: "opaque",
|
|
15
|
-
} })).toMatchObject({ generation: {
|
|
16
|
-
route: "codex-responses", size: "841x1870", quality: "low", background: "opaque",
|
|
17
|
-
} });
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("reports PNG byte dimensions instead of a conflicting backend size", () => {
|
|
21
|
-
const bytes = Buffer.alloc(24);
|
|
22
|
-
Buffer.from("89504e470d0a1a0a", "hex").copy(bytes);
|
|
23
|
-
bytes.writeUInt32BE(841, 16);
|
|
24
|
-
bytes.writeUInt32BE(1870, 20);
|
|
25
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
26
|
-
type: "image_generation_call", result: bytes.toString("base64"), size: "1152x2560",
|
|
27
|
-
} })).toMatchObject({ generation: { route: "codex-responses", size: "841x1870" } });
|
|
28
|
-
});
|
|
29
12
|
it("distinguishes partial function items from completed arguments", () => {
|
|
30
13
|
const item = { type: "function_call", call_id: "call", name: "generate_image", arguments: "{}" };
|
|
31
14
|
expect(normalizeOpenAIEvent({ type: "response.output_item.added", item })).toEqual({ type: "output-item", item, completed: false });
|
|
32
15
|
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item })).toEqual({ type: "output-item", item, completed: true });
|
|
33
16
|
});
|
|
34
|
-
it("uses returned bytes rather than a mismatched format label", () => {
|
|
35
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
36
|
-
type: "image_generation_call", result: "UklGRgAAAABXRUJQ", output_format: "png",
|
|
37
|
-
} })).toMatchObject({ mimeType: "image/webp" });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("detects JPEG when the format label is absent", () => {
|
|
41
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
42
|
-
type: "image_generation_call", result: "/9j/",
|
|
43
|
-
} })).toMatchObject({ mimeType: "image/jpeg" });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
17
|
it.each([
|
|
47
|
-
["
|
|
48
|
-
["
|
|
49
|
-
["
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
item: { type: "image_generation_call", result, output_format: format },
|
|
54
|
-
})).toMatchObject({ type: "image", mimeType });
|
|
18
|
+
["iVBORw0KGgo=", "jpeg", "image/png"],
|
|
19
|
+
["UklGRgAAAABXRUJQ", "png", "image/webp"],
|
|
20
|
+
["/9j/", undefined, "image/jpeg"],
|
|
21
|
+
["aGVsbG8=", "webp", "image/webp"],
|
|
22
|
+
])("detects history image MIME from bytes before the format label: %s", (base64, format, mimeType) => {
|
|
23
|
+
expect(imageMimeType(base64, format)).toBe(mimeType);
|
|
55
24
|
});
|
|
56
25
|
|
|
57
26
|
it("preserves raw history and pins Responses controls", () => {
|
|
@@ -64,13 +33,11 @@ describe("OpenAI Codex backend protocol", () => {
|
|
|
64
33
|
serviceTier: "priority",
|
|
65
34
|
promptCacheKey: "thread-1",
|
|
66
35
|
outputSchema: { schema: { type: "object", additionalProperties: false } },
|
|
67
|
-
imageGeneration: true,
|
|
68
36
|
});
|
|
69
37
|
|
|
70
38
|
expect(request).toEqual({
|
|
71
39
|
model: "gpt-5.2-codex",
|
|
72
40
|
input: history,
|
|
73
|
-
tools: [{ type: "image_generation" }],
|
|
74
41
|
tool_choice: "auto",
|
|
75
42
|
parallel_tool_calls: true,
|
|
76
43
|
reasoning: { effort: "high", summary: "auto" },
|
|
@@ -122,7 +89,7 @@ describe("OpenAI Codex backend protocol", () => {
|
|
|
122
89
|
});
|
|
123
90
|
});
|
|
124
91
|
|
|
125
|
-
it("normalizes usage
|
|
92
|
+
it("normalizes usage", () => {
|
|
126
93
|
expect(
|
|
127
94
|
normalizeOpenAIEvent({
|
|
128
95
|
type: "response.completed",
|
|
@@ -142,33 +109,5 @@ describe("OpenAI Codex backend protocol", () => {
|
|
|
142
109
|
responseId: "r1",
|
|
143
110
|
usage: { inputTokens: 4, cachedInputTokens: 2, outputTokens: 3, reasoningTokens: 1, totalTokens: 7 },
|
|
144
111
|
});
|
|
145
|
-
expect(
|
|
146
|
-
normalizeOpenAIEvent({
|
|
147
|
-
type: "response.output_item.done",
|
|
148
|
-
item: { type: "image_generation_call", id: "img", result: "aGVsbG8=", revised_prompt: "better" },
|
|
149
|
-
}),
|
|
150
|
-
).toEqual({ type: "image", id: "img", base64: "aGVsbG8=", mimeType: "image/png", revisedPrompt: "better", generation: { route: "codex-responses" } });
|
|
151
112
|
});
|
|
152
|
-
|
|
153
|
-
it("preserves zero image-tool usage without treating it as missing", () => {
|
|
154
|
-
const usage = { input_tokens: 0, output_tokens: 0, total_tokens: 0 };
|
|
155
|
-
expect(normalizeOpenAIEvent({ type: "response.completed", response: {
|
|
156
|
-
id: "r", tool_usage: { image_gen: usage },
|
|
157
|
-
} })).toEqual({
|
|
158
|
-
type: "completed", responseId: "r",
|
|
159
|
-
imageGeneration: { route: "codex-responses", usage },
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it.each([undefined, null, {}, { input_tokens: "4", output_tokens: 1, total_tokens: 5 }, { input_tokens: -1, output_tokens: 1, total_tokens: 0 }])(
|
|
164
|
-
"ignores missing or malformed image-tool usage: %j", (usage) => {
|
|
165
|
-
expect(normalizeOpenAIEvent({ type: "response.completed", response: {
|
|
166
|
-
id: "r", tool_usage: { image_gen: usage },
|
|
167
|
-
tools: [{ type: "image_generation", model: "gpt-image-2-codex", size: "auto", quality: "auto" }],
|
|
168
|
-
} })).toEqual({
|
|
169
|
-
type: "completed", responseId: "r",
|
|
170
|
-
imageGeneration: { route: "codex-responses", model: "gpt-image-2-codex" },
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
113
|
});
|
|
@@ -2,7 +2,7 @@ import os from "node:os";
|
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
-
import { ImageGenerationMetadata } from "../../../application/qgrid/qgrid.types";
|
|
5
|
+
import { type ImageGenerationMetadata } from "../../../application/qgrid/qgrid.types";
|
|
6
6
|
import { type OpenAIEffort } from "../common/effort";
|
|
7
7
|
import {
|
|
8
8
|
isJsonObject,
|
|
@@ -73,6 +73,7 @@ export interface OpenAIResponsesOptions {
|
|
|
73
73
|
serviceTier?: string;
|
|
74
74
|
promptCacheKey?: string;
|
|
75
75
|
outputSchema?: OpenAIOutputSchema;
|
|
76
|
+
/** Sends the request to standalone Images instead of Responses; see `OpenAIDirectClient`. */
|
|
76
77
|
imageGeneration?: boolean | OpenAIResponseItem;
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -107,14 +108,6 @@ export function buildOpenAIResponsesRequest(
|
|
|
107
108
|
): OpenAIResponsesRequest {
|
|
108
109
|
const tools = options.tools ? [...options.tools] : [];
|
|
109
110
|
|
|
110
|
-
if (options.imageGeneration) {
|
|
111
|
-
tools.push(
|
|
112
|
-
options.imageGeneration === true
|
|
113
|
-
? { type: "image_generation" }
|
|
114
|
-
: { type: "image_generation", ...options.imageGeneration },
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
111
|
const request: OpenAIResponsesRequest = {
|
|
119
112
|
model: options.model,
|
|
120
113
|
// Copy the array, not its items: raw items must arrive byte-for-byte equivalent.
|
|
@@ -216,7 +209,6 @@ export type OpenAINormalizedEvent =
|
|
|
216
209
|
responseId: string;
|
|
217
210
|
usage?: OpenAIUsage;
|
|
218
211
|
model?: string;
|
|
219
|
-
imageGeneration?: ImageGenerationMetadata;
|
|
220
212
|
}
|
|
221
213
|
| { type: "error"; error: OpenAIProtocolError };
|
|
222
214
|
|
|
@@ -275,68 +267,9 @@ export function imageMimeType(
|
|
|
275
267
|
throw new OpenAIProtocolError(`Unsupported image output format: ${label}`);
|
|
276
268
|
}
|
|
277
269
|
|
|
278
|
-
type OpenAIImageEvent = Extract<OpenAINormalizedEvent, { type: "image" }>;
|
|
279
|
-
|
|
280
|
-
function imageEvent(item: JsonObject, result: string): OpenAIImageEvent {
|
|
281
|
-
// PNG exposes dimensions in its fixed header. Other formats retain the
|
|
282
|
-
// backend's observed size; never substitute requested image controls.
|
|
283
|
-
const header = Buffer.from(result.slice(0, 32), "base64");
|
|
284
|
-
|
|
285
|
-
const pngSize =
|
|
286
|
-
header.length >= 24 &&
|
|
287
|
-
header.subarray(0, 8).equals(Buffer.from("89504e470d0a1a0a", "hex")) &&
|
|
288
|
-
header.readUInt32BE(16) > 0 &&
|
|
289
|
-
header.readUInt32BE(20) > 0
|
|
290
|
-
? `${header.readUInt32BE(16)}x${header.readUInt32BE(20)}`
|
|
291
|
-
: undefined;
|
|
292
|
-
|
|
293
|
-
const reportedSize = jsonString(item.size);
|
|
294
|
-
|
|
295
|
-
const size =
|
|
296
|
-
pngSize ??
|
|
297
|
-
(reportedSize !== undefined && /^[1-9]\d*x[1-9]\d*$/.test(reportedSize)
|
|
298
|
-
? reportedSize
|
|
299
|
-
: undefined);
|
|
300
|
-
|
|
301
|
-
const id = jsonString(item.id);
|
|
302
|
-
const model = jsonString(item.model);
|
|
303
|
-
const quality = jsonString(item.quality);
|
|
304
|
-
const background = jsonString(item.background);
|
|
305
|
-
const revisedPrompt = jsonString(item.revised_prompt) ?? jsonString(item.revisedPrompt);
|
|
306
|
-
const generation: ImageGenerationMetadata = { route: "codex-responses" };
|
|
307
|
-
|
|
308
|
-
if (size) generation.size = size;
|
|
309
|
-
|
|
310
|
-
if (model !== undefined) generation.model = model;
|
|
311
|
-
|
|
312
|
-
if (quality !== undefined) generation.quality = quality;
|
|
313
|
-
|
|
314
|
-
if (background !== undefined) generation.background = background;
|
|
315
|
-
|
|
316
|
-
const event: OpenAIImageEvent = { type: "image", base64: result, mimeType: "image/png" };
|
|
317
|
-
|
|
318
|
-
if (id !== undefined) event.id = id;
|
|
319
|
-
event.base64 = result;
|
|
320
|
-
event.mimeType = imageMimeType(result, item.output_format);
|
|
321
|
-
event.generation = generation;
|
|
322
|
-
|
|
323
|
-
if (revisedPrompt !== undefined) event.revisedPrompt = revisedPrompt;
|
|
324
|
-
|
|
325
|
-
return event;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
270
|
type OpenAICompletedEvent = Extract<OpenAINormalizedEvent, { type: "completed" }>;
|
|
329
271
|
|
|
330
272
|
function completedEvent(response: JsonObject): OpenAICompletedEvent {
|
|
331
|
-
const toolUsage = jsonObjectOrEmpty(response.tool_usage);
|
|
332
|
-
const parsedImageUsage = ImageGenerationMetadata.shape.usage.safeParse(toolUsage.image_gen);
|
|
333
|
-
const imageUsage = parsedImageUsage.success ? parsedImageUsage.data : undefined;
|
|
334
|
-
|
|
335
|
-
const imageTool = Array.isArray(response.tools)
|
|
336
|
-
? response.tools.find((tool) => isJsonObject(tool) && tool.type === "image_generation")
|
|
337
|
-
: undefined;
|
|
338
|
-
|
|
339
|
-
const imageModel = isJsonObject(imageTool) ? jsonString(imageTool.model) : undefined;
|
|
340
273
|
const model = jsonString(response.model);
|
|
341
274
|
|
|
342
275
|
const event: OpenAICompletedEvent = {
|
|
@@ -348,15 +281,6 @@ function completedEvent(response: JsonObject): OpenAICompletedEvent {
|
|
|
348
281
|
|
|
349
282
|
if (model !== undefined) event.model = model;
|
|
350
283
|
|
|
351
|
-
if (imageUsage || imageModel) {
|
|
352
|
-
const imageGeneration: ImageGenerationMetadata = { route: "codex-responses" };
|
|
353
|
-
|
|
354
|
-
if (imageModel) imageGeneration.model = imageModel;
|
|
355
|
-
|
|
356
|
-
if (imageUsage) imageGeneration.usage = imageUsage;
|
|
357
|
-
event.imageGeneration = imageGeneration;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
284
|
return event;
|
|
361
285
|
}
|
|
362
286
|
|
|
@@ -385,14 +309,11 @@ export function normalizeOpenAIEvent(raw: JsonValue): OpenAINormalizedEvent | un
|
|
|
385
309
|
(type === "response.output_item.added" || type === "response.output_item.done") &&
|
|
386
310
|
isJsonObject(event.item)
|
|
387
311
|
) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return { type: "output-item", item, completed: type === "response.output_item.done" };
|
|
312
|
+
return {
|
|
313
|
+
type: "output-item",
|
|
314
|
+
item: event.item,
|
|
315
|
+
completed: type === "response.output_item.done",
|
|
316
|
+
};
|
|
396
317
|
}
|
|
397
318
|
|
|
398
319
|
if (type === "response.completed") return completedEvent(jsonObjectOrEmpty(event.response));
|
|
@@ -33,21 +33,6 @@ async function collect<T>(iterable: AsyncIterable<T>): Promise<T[]> {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
describe("OpenAI direct HTTPS client", () => {
|
|
36
|
-
it.each([true, { background: "opaque" }])("keeps chat-model images on Responses (%j)", async (imageGeneration) => {
|
|
37
|
-
const fetchMock = vi.fn<typeof fetch>(async () =>
|
|
38
|
-
sse({ type: "response.completed", response: { id: "hosted-image" } }),
|
|
39
|
-
);
|
|
40
|
-
const client = new OpenAIDirectClient({
|
|
41
|
-
credentials: { accessToken: "access", accountId: "acct" }, fetch: fetchMock,
|
|
42
|
-
});
|
|
43
|
-
await collect(client.responses({ model: "gpt-6-luna", history: [], imageGeneration }));
|
|
44
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
45
|
-
expect(fetchMock.mock.calls[0]?.[0]).toBe(CHATGPT_CODEX_RESPONSES_URL);
|
|
46
|
-
expect(JSON.parse(String(fetchMock.mock.calls[0]?.[1]?.body))).toMatchObject({
|
|
47
|
-
model: "gpt-6-luna", tools: [expect.objectContaining({ type: "image_generation" })],
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
36
|
it("posts the pinned body and Codex identity without live calls", async () => {
|
|
52
37
|
const fetchMock = vi.fn<typeof fetch>(async () =>
|
|
53
38
|
sse(
|
|
@@ -535,7 +535,9 @@ export class OpenAIDirectClient {
|
|
|
535
535
|
}
|
|
536
536
|
|
|
537
537
|
responses(options: OpenAIResponsesOptions, signal?: AbortSignal): OpenAIEventStream {
|
|
538
|
-
|
|
538
|
+
// Hosted Responses image tools turn driver reasoning effort into an unsupported
|
|
539
|
+
// `complexity` (2026-11-09 probe), so every image request uses standalone Images.
|
|
540
|
+
if (options.model === "gpt-image-2" || options.imageGeneration) {
|
|
539
541
|
return this.standaloneImages(options, signal);
|
|
540
542
|
}
|
|
541
543
|
|