@cartanova/qgrid-cli 2.15.3 → 2.15.5
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 +168 -12
- package/bundle/dist/application/qgrid/qgrid.types.js +6 -3
- package/bundle/dist/application/request-log/request-log.model.js +4 -3
- package/bundle/dist/application/sonamu.generated.js +20 -5
- package/bundle/dist/application/sonamu.generated.sso.js +5 -3
- package/bundle/dist/i18n/en.js +2 -1
- package/bundle/dist/i18n/ko.js +2 -1
- package/bundle/dist/i18n/sd.generated.js +6 -1
- package/bundle/dist/migrations/20261109110340_alter_request_logs_add1_alter1.js +15 -0
- package/bundle/dist/utils/providers/grok/grok-types.js +1 -1
- package/bundle/dist/utils/providers/grok/grok-voice-client.js +4 -2
- 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 +460 -0
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +43 -6
- package/bundle/src/application/qgrid/qgrid.frame.ts +246 -14
- package/bundle/src/application/qgrid/qgrid.types.ts +14 -2
- package/bundle/src/application/request-log/request-log.entity.json +17 -2
- package/bundle/src/application/request-log/request-log.model.test.ts +17 -0
- package/bundle/src/application/request-log/request-log.model.ts +11 -3
- package/bundle/src/application/sonamu.generated.http +2 -0
- package/bundle/src/application/sonamu.generated.sso.ts +2 -0
- package/bundle/src/application/sonamu.generated.ts +14 -0
- package/bundle/src/i18n/en.ts +1 -0
- package/bundle/src/i18n/ko.ts +1 -0
- package/bundle/src/i18n/sd.generated.ts +6 -0
- package/bundle/src/migrations/20261109110340_alter_request_logs_add1_alter1.ts +15 -0
- package/bundle/src/utils/providers/grok/grok-types.ts +2 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.test.ts +2 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.ts +2 -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 +582 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.ts +744 -0
- package/bundle/web-dist/client/assets/index-DyrPRt6O.css +1 -0
- package/bundle/web-dist/client/assets/index-Wi8Wxte6.js +104 -0
- package/bundle/web-dist/client/assets/{logs-Dw-GrMuH.js → logs-Bdg3wJV2.js} +1 -1
- package/bundle/web-dist/client/assets/{monit-BaFFiVKs.js → monit-DcwHRAKu.js} +1 -1
- package/bundle/web-dist/client/assets/{routes-R1xBZYVT.js → routes-lxVC1DDJ.js} +1 -1
- package/bundle/web-dist/client/assets/{settings-Bw_NXAx8.js → settings-C0VCdd1C.js} +1 -1
- package/bundle/web-dist/client/assets/{show-BH7nfFtF.js → show-B7QRPxsY.js} +2 -2
- package/bundle/web-dist/client/assets/{tokens-BPmRr7mD.js → tokens-CNRSm9sc.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-B_MGbC3a.js → use-oauth-login-flow-eQnMzp8A.js} +1 -1
- package/bundle/web-dist/client/assets/{use-update-token-mutation-Dcq7Yv2R.js → use-update-token-mutation-KnwyYQjb.js} +1 -1
- package/bundle/web-dist/client/assets/voice-BydIuS0A.js +1 -0
- package/bundle/web-dist/client/index.html +2 -2
- package/bundle/web-dist/client/voice-samples/grok/altair.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/ara.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/atlas.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/aurora.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/carina.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/castor.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/celeste.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/cosmo.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/eve.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/helios.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/helix.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/iris.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/kepler.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/leo.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/liora.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/lumen.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/luna.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/lux.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/naksh.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/orion.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/perseus.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/rex.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/rigel.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/sal.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/sirius.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/ursa.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/zagan.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/zenith.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/alloy.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/ash.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/ballad.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/cedar.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/coral.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/echo.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/marin.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/sage.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/shimmer.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/verse.mp3 +0 -0
- package/bundle/web-dist/server/assets/link-DrdV092C.js +4919 -0
- package/bundle/web-dist/server/assets/{logs-6289J29J.js → logs-BmBpBe-j.js} +13 -6
- package/bundle/web-dist/server/assets/{monit-YVvwJuAF.js → monit-Db1WrIls.js} +2 -2
- package/bundle/web-dist/server/assets/{plus-z5Hy__3C.js → plus-CW9y_K7l.js} +1 -1
- package/bundle/web-dist/server/assets/{refresh-cw-CNm0CERy.js → refresh-cw-CRgcH5bT.js} +1 -1
- package/bundle/web-dist/server/assets/{request-model-DIuPZZwu.js → request-model-DRF7hmJC.js} +1 -1
- package/bundle/web-dist/server/assets/{routes-DVWRvqn0.js → routes-CARZj7or.js} +4 -4
- package/bundle/web-dist/server/assets/{services.generated-CqS8DCjT.js → services.generated-B6QpnL_N.js} +7 -0
- package/bundle/web-dist/server/assets/{settings-CXwnKiMG.js → settings-B4jdpP5N.js} +4 -4
- package/bundle/web-dist/server/assets/{show-G1t8dOEh.js → show-D8r2sVK0.js} +17 -9
- package/bundle/web-dist/server/assets/{tokens-Di1vDwm5.js → tokens-TDQguTdh.js} +5 -5
- package/bundle/web-dist/server/assets/{use-oauth-login-flow-BUAcW_pK.js → use-oauth-login-flow-du7pOh_H.js} +1 -1
- package/bundle/web-dist/server/assets/{use-update-token-mutation-oH0O0n-g.js → use-update-token-mutation-DA6HiiWS.js} +1 -1
- package/bundle/web-dist/server/assets/voice-C2HfwkGp.js +668 -0
- package/bundle/web-dist/server/entry-server.generated.js +125 -4989
- package/bundle/web-dist/server/voice-samples/grok/altair.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/ara.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/atlas.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/aurora.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/carina.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/castor.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/celeste.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/cosmo.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/eve.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/helios.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/helix.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/iris.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/kepler.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/leo.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/liora.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/lumen.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/luna.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/lux.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/naksh.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/orion.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/perseus.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/rex.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/rigel.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/sal.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/sirius.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/ursa.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/zagan.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/zenith.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/alloy.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/ash.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/ballad.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/cedar.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/coral.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/echo.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/marin.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/sage.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/shimmer.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/verse.mp3 +0 -0
- 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 +7 -2
- package/skills/qgrid/references/sonamu-api-web-flow.md +6 -2
- package/skills/qgrid/references/verification-and-debugging.md +3 -3
- package/bundle/web-dist/client/assets/index-BakMhnHZ.js +0 -104
- package/bundle/web-dist/client/assets/index-DLo1QCw7.css +0 -1
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { getLogger } from "@logtape/logtape";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
type ImageGenerationMetadata,
|
|
6
|
-
QuotaThresholdExceededError,
|
|
7
|
-
} from "../../../application/qgrid/qgrid.types";
|
|
4
|
+
import { QuotaThresholdExceededError } from "../../../application/qgrid/qgrid.types";
|
|
8
5
|
import { TokenModel } from "../../../application/token/token.model";
|
|
9
6
|
import { type OpenAICredentials } from "../../../application/token/token.types";
|
|
10
7
|
import { isOpenAICredentials } from "../common/credentials";
|
|
@@ -26,10 +23,22 @@ import {
|
|
|
26
23
|
type OpenAIResponseItem,
|
|
27
24
|
type OpenAIResponsesOptions,
|
|
28
25
|
} from "./openai-backend-protocol";
|
|
29
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
OpenAIDirectClient,
|
|
28
|
+
type OpenAIDirectClientOptions,
|
|
29
|
+
type OpenAIDirectCredentials,
|
|
30
|
+
} from "./openai-direct-client";
|
|
30
31
|
import { readOpenAIQuotaUsage, type OpenAIRateLimitsWithMeta } from "./openai-quota";
|
|
31
32
|
import { handleChatgptAuthTokensRefresh } from "./openai-refresh";
|
|
32
33
|
import { type OpenAITransportKind, resolveOpenAITransportKind } from "./openai-transport-config";
|
|
34
|
+
import {
|
|
35
|
+
isUnauthorizedRealtimeError,
|
|
36
|
+
type OpenAISpeakRequest,
|
|
37
|
+
type OpenAISpeechResult,
|
|
38
|
+
type OpenAITranscribeRequest,
|
|
39
|
+
type OpenAITranscription,
|
|
40
|
+
OpenAIVoiceClient,
|
|
41
|
+
} from "./openai-voice-client";
|
|
33
42
|
|
|
34
43
|
const logger = getLogger(["qgrid", "openai-dispatcher"]);
|
|
35
44
|
|
|
@@ -115,6 +124,19 @@ type ClientEntry = {
|
|
|
115
124
|
export interface OpenAIDispatcherDependencies {
|
|
116
125
|
clientFactory?: OpenAIDirectClientFactory;
|
|
117
126
|
fetch?: typeof fetch;
|
|
127
|
+
voiceClient?: OpenAIVoiceClient;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Realtime voice call with the media-endpoint token selection contract. */
|
|
131
|
+
export type OpenAIVoiceSelection = {
|
|
132
|
+
preferredTokenId?: number;
|
|
133
|
+
requirePreferredToken?: boolean;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export interface OpenAIVoiceDispatchResult<T> {
|
|
137
|
+
result: T;
|
|
138
|
+
tokenId: number;
|
|
139
|
+
tokenName: string;
|
|
118
140
|
}
|
|
119
141
|
|
|
120
142
|
function abortError(signal: AbortSignal): Error {
|
|
@@ -293,6 +315,7 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
293
315
|
readonly selector = new SmoothWeightedRoundRobin();
|
|
294
316
|
readonly clientFactory: OpenAIDirectClientFactory;
|
|
295
317
|
readonly fetchImpl: typeof fetch;
|
|
318
|
+
readonly voiceClient: OpenAIVoiceClient;
|
|
296
319
|
readonly quotaBlocked = new Set<number>();
|
|
297
320
|
inFlight = 0;
|
|
298
321
|
|
|
@@ -304,6 +327,75 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
304
327
|
this.clientFactory =
|
|
305
328
|
dependencies.clientFactory ?? ((options) => new OpenAIDirectClient(options));
|
|
306
329
|
this.fetchImpl = dependencies.fetch ?? fetch;
|
|
330
|
+
this.voiceClient = dependencies.voiceClient ?? new OpenAIVoiceClient({ fetch: this.fetchImpl });
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ---- Realtime voice (speech-to-text, text-to-speech) ----------------------
|
|
334
|
+
|
|
335
|
+
async transcribe(
|
|
336
|
+
request: OpenAITranscribeRequest & OpenAIVoiceSelection,
|
|
337
|
+
): Promise<OpenAIVoiceDispatchResult<OpenAITranscription>> {
|
|
338
|
+
const { preferredTokenId, requirePreferredToken, ...voiceRequest } = request;
|
|
339
|
+
|
|
340
|
+
return this.runVoice(
|
|
341
|
+
{ preferredTokenId, requirePreferredToken },
|
|
342
|
+
request.signal,
|
|
343
|
+
(credentials) => this.voiceClient.transcribe(credentials, voiceRequest),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async speak(
|
|
348
|
+
request: OpenAISpeakRequest & OpenAIVoiceSelection,
|
|
349
|
+
): Promise<OpenAIVoiceDispatchResult<OpenAISpeechResult>> {
|
|
350
|
+
const { preferredTokenId, requirePreferredToken, ...voiceRequest } = request;
|
|
351
|
+
|
|
352
|
+
return this.runVoice(
|
|
353
|
+
{ preferredTokenId, requirePreferredToken },
|
|
354
|
+
request.signal,
|
|
355
|
+
(credentials) => this.voiceClient.speak(credentials, voiceRequest),
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Selects a token, runs the realtime call, and on one 401 refreshes that token's credentials and
|
|
361
|
+
* retries once (as the Responses transports do). Any other failure propagates: a realtime
|
|
362
|
+
* session that failed may already have consumed audio tokens.
|
|
363
|
+
*/
|
|
364
|
+
async runVoice<T>(
|
|
365
|
+
selection: OpenAIVoiceSelection,
|
|
366
|
+
signal: AbortSignal | undefined,
|
|
367
|
+
call: (credentials: OpenAIDirectCredentials) => Promise<T>,
|
|
368
|
+
): Promise<OpenAIVoiceDispatchResult<T>> {
|
|
369
|
+
const active = signal ?? new AbortController().signal;
|
|
370
|
+
|
|
371
|
+
const selected = await this.selectToken(
|
|
372
|
+
selection.preferredTokenId,
|
|
373
|
+
selection.requirePreferredToken ?? false,
|
|
374
|
+
active,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const { tokenId, metadata } = selected;
|
|
378
|
+
|
|
379
|
+
let credentials: OpenAIDirectCredentials = {
|
|
380
|
+
accessToken: metadata.credentials.accessToken,
|
|
381
|
+
accountId: metadata.credentials.accountId,
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
for (let attempt = 0; ; attempt++) {
|
|
385
|
+
try {
|
|
386
|
+
const result = await call(credentials);
|
|
387
|
+
this.invalidateRateLimitsCache(tokenId);
|
|
388
|
+
|
|
389
|
+
return { result, tokenId, tokenName: metadata.name };
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (attempt === 0 && error instanceof Error && isUnauthorizedRealtimeError(error)) {
|
|
392
|
+
credentials = await this.refreshCredentials(tokenId);
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
307
399
|
}
|
|
308
400
|
|
|
309
401
|
async start(): Promise<void> {
|
|
@@ -578,14 +670,9 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
578
670
|
streamedMessageIds.add(itemId);
|
|
579
671
|
}
|
|
580
672
|
} else if (event.type === "image") {
|
|
581
|
-
if (auto)
|
|
582
|
-
throw new ImageGenerationError("incomplete", "Unexpected hosted image generation");
|
|
673
|
+
if (auto) throw new ImageGenerationError("incomplete", "Unexpected image output");
|
|
583
674
|
imageAttempted = true;
|
|
584
675
|
images.push(generatedImageFrom(event));
|
|
585
|
-
} else if (event.type === "output-item" && event.item.type === "image_generation_call") {
|
|
586
|
-
if (auto)
|
|
587
|
-
throw new ImageGenerationError("incomplete", "Unexpected hosted image generation");
|
|
588
|
-
imageAttempted = true;
|
|
589
676
|
} else if (auto && event.type === "output-item" && event.item.type === "function_call") {
|
|
590
677
|
if (event.item.name !== IMAGE_TOOL) {
|
|
591
678
|
throw new ImageGenerationError("incomplete", "Unexpected automatic image tool call");
|
|
@@ -632,17 +719,6 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
632
719
|
num_last_images_to_include: args.num_last_images_to_include,
|
|
633
720
|
});
|
|
634
721
|
} else if (event.type === "completed") {
|
|
635
|
-
const imageUsage = event.imageGeneration?.usage;
|
|
636
|
-
|
|
637
|
-
// The backend also reports all-zero image usage for text-only responses.
|
|
638
|
-
if (
|
|
639
|
-
auto &&
|
|
640
|
-
imageUsage &&
|
|
641
|
-
(imageUsage.input_tokens > 0 ||
|
|
642
|
-
imageUsage.output_tokens > 0 ||
|
|
643
|
-
imageUsage.total_tokens > 0)
|
|
644
|
-
)
|
|
645
|
-
throw new ImageGenerationError("incomplete", "Unexpected hosted image generation");
|
|
646
722
|
driverCompleted = true;
|
|
647
723
|
servingModel = event.model ?? servingModel;
|
|
648
724
|
|
|
@@ -655,31 +731,6 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
655
731
|
reasoningOutputTokens: event.usage.reasoningTokens,
|
|
656
732
|
};
|
|
657
733
|
}
|
|
658
|
-
|
|
659
|
-
if (event.imageGeneration) {
|
|
660
|
-
const hostedImages = images.filter(
|
|
661
|
-
(image) => image.generation?.route === "codex-responses",
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
for (const [index, image] of hostedImages.entries()) {
|
|
665
|
-
const generation: ImageGenerationMetadata = {
|
|
666
|
-
route: "codex-responses",
|
|
667
|
-
...image.generation,
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
// The image's own model wins; the response-level model only fills a gap.
|
|
671
|
-
if (generation.model === undefined && event.imageGeneration.model) {
|
|
672
|
-
generation.model = event.imageGeneration.model;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
// Tool usage covers the whole response, not each returned image.
|
|
676
|
-
if (index === 0 && event.imageGeneration.usage) {
|
|
677
|
-
generation.usage = event.imageGeneration.usage;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
image.generation = generation;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
734
|
} else if (event.type === "error") {
|
|
684
735
|
if (req.imageGeneration)
|
|
685
736
|
throw new ImageGenerationError("incomplete", event.error.message);
|
|
@@ -152,9 +152,11 @@ describe("standalone transparent images", () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
describe("standalone image model", () => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
// Chat models use the same route: hosted Responses images reject driver reasoning effort.
|
|
156
|
+
it.each(["gpt-image-2", "gpt-6-luna"].flatMap((model) =>
|
|
157
|
+
[true, { background: "opaque" }, { background: "auto" }].map((imageGeneration) => [model, imageGeneration] as const)))(
|
|
158
|
+
"generates ordinary PNGs for %s directly without the Responses transport (%j)",
|
|
159
|
+
async (model, imageGeneration) => {
|
|
158
160
|
const stream = vi.fn();
|
|
159
161
|
const fetchMock = vi.fn<typeof fetch>(async () => Response.json({
|
|
160
162
|
data: [{ b64_json: png([255, 255]) }],
|
|
@@ -165,7 +167,7 @@ describe("standalone image model", () => {
|
|
|
165
167
|
transport: { stream },
|
|
166
168
|
});
|
|
167
169
|
const events = await Array.fromAsync(client.responses({
|
|
168
|
-
...options, model: "
|
|
170
|
+
...options, model, imageGeneration, reasoning: { effort: "high" },
|
|
169
171
|
}));
|
|
170
172
|
expect(stream).not.toHaveBeenCalled();
|
|
171
173
|
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
@@ -44,12 +44,6 @@ export function buildStandaloneImageRequest(options: OpenAIResponsesOptions) {
|
|
|
44
44
|
|
|
45
45
|
const controls = options.imageGeneration === true ? {} : options.imageGeneration;
|
|
46
46
|
|
|
47
|
-
if (options.model !== "gpt-image-2" && controls.background !== "transparent") {
|
|
48
|
-
throw new OpenAIProtocolError(
|
|
49
|
-
"Standalone images require an explicit transparent background request",
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
47
|
if (controls.output_format && controls.output_format !== "png") {
|
|
54
48
|
throw new OpenAIProtocolError("Standalone image generation only supports PNG output");
|
|
55
49
|
}
|