@cartanova/qgrid-cli 2.19.2 → 2.20.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.
Files changed (42) hide show
  1. package/bundle/dist/application/qgrid/qgrid.frame.js +20 -9
  2. package/bundle/dist/application/qgrid/qgrid.types.js +84 -2
  3. package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +29 -53
  4. package/bundle/dist/utils/providers/openai/openai-voice-client.js +4 -3
  5. package/bundle/src/application/qgrid/qgrid.frame.test.ts +36 -0
  6. package/bundle/src/application/qgrid/qgrid.frame.ts +24 -5
  7. package/bundle/src/application/qgrid/qgrid.types.ts +90 -0
  8. package/bundle/src/application/sonamu.generated.http +6 -0
  9. package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +64 -56
  10. package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +27 -2
  11. package/bundle/src/utils/providers/openai/openai-voice-client.ts +8 -1
  12. package/bundle/web-dist/client/assets/TimedPlayer-UGSsgTKj.js +1 -0
  13. package/bundle/web-dist/client/assets/{index-hUNCpC11.css → index-BITKCBxB.css} +1 -1
  14. package/bundle/web-dist/client/assets/{index-BeceW0U9.js → index-DjrhMvkM.js} +14 -14
  15. package/bundle/web-dist/client/assets/{logs-jMJnTwZn.js → logs-DN5BhglL.js} +1 -1
  16. package/bundle/web-dist/client/assets/{monit-B1xRKwua.js → monit-DZPRb015.js} +1 -1
  17. package/bundle/web-dist/client/assets/{routes-fsiyivXx.js → routes-DJAp0zIh.js} +1 -1
  18. package/bundle/web-dist/client/assets/{settings-CHX44roa.js → settings-WY3p1iSx.js} +1 -1
  19. package/bundle/web-dist/client/assets/show-DykCwUpU.js +2 -0
  20. package/bundle/web-dist/client/assets/{tokens-zGl36OfE.js → tokens-DSdQ7R5O.js} +1 -1
  21. package/bundle/web-dist/client/assets/{use-oauth-login-flow-DYWj4645.js → use-oauth-login-flow-gc2fKVxE.js} +1 -1
  22. package/bundle/web-dist/client/assets/{use-update-token-mutation-BRXXrEf5.js → use-update-token-mutation-BGVP43e8.js} +1 -1
  23. package/bundle/web-dist/client/assets/voice-DRzMbzHH.js +4 -0
  24. package/bundle/web-dist/client/index.html +2 -2
  25. package/bundle/web-dist/server/assets/TimedPlayer-CcClBzGi.js +193 -0
  26. package/bundle/web-dist/server/assets/{logs-HPho1SkC.js → logs-CxAwuDKc.js} +1 -1
  27. package/bundle/web-dist/server/assets/{routes-BNHCX4VI.js → routes-W-pd1Hps.js} +1 -1
  28. package/bundle/web-dist/server/assets/{settings-NJUyaSrJ.js → settings-CFdTg1_f.js} +1 -1
  29. package/bundle/web-dist/server/assets/{show-Dz5QGL7l.js → show-DVEIHsXh.js} +35 -157
  30. package/bundle/web-dist/server/assets/{tokens-BPQvjIGq.js → tokens-BO1hyBuB.js} +1 -1
  31. package/bundle/web-dist/server/assets/voice-BCF-Pkzo.js +1115 -0
  32. package/bundle/web-dist/server/entry-server.generated.js +90 -8
  33. package/package.json +1 -1
  34. package/skills/qgrid/references/ai-sdk-provider-contract.md +4 -0
  35. package/skills/qgrid/references/openai-codex-runtime.md +3 -1
  36. package/skills/qgrid/references/request-log-run-lifecycle.md +1 -1
  37. package/skills/qgrid/references/sonamu-api-web-flow.md +2 -2
  38. package/bundle/web-dist/client/assets/TimedPlayer-cuEgYA3Q.js +0 -1
  39. package/bundle/web-dist/client/assets/show-BDMwKfEY.js +0 -2
  40. package/bundle/web-dist/client/assets/voice-Bwcp-KAu.js +0 -1
  41. package/bundle/web-dist/server/assets/TimedPlayer-COqaTQSl.js +0 -54
  42. package/bundle/web-dist/server/assets/voice-V-E3tRqD.js +0 -967
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
 
3
+ import { OPENAI_LIVE_VOICES, OPENAI_SPEECH_VOICES } from "../../../application/qgrid/qgrid.types";
3
4
  import { CODEX_CLI_ORIGINATOR, codexCliUserAgent, type JsonValue } from "./openai-backend-protocol";
4
5
 
5
6
  // Wire contract for OpenAI realtime audio on a ChatGPT subscription, mirroring Codex
@@ -24,8 +25,14 @@ export const OPENAI_REALTIME_WS_URL = "wss://api.openai.com/v1/realtime" as cons
24
25
  /** realtime_websocket/methods_common.rs:26 */
25
26
  export const OPENAI_REALTIME_SAMPLE_RATE = 24_000;
26
27
 
27
- /** realtime_websocket/methods_v2.rs:37 */
28
- export const OPENAI_REALTIME_DEFAULT_TRANSCRIPTION_MODEL = "gpt-4o-mini-transcribe";
28
+ /**
29
+ * Fallback id inside the OpenAI voice client (a transcribe request without `model` routes to Grok)
30
+ * and the input transcription model of the speech session. Codex's own default (methods_v2.rs:37)
31
+ * is gpt-4o-mini-transcribe, which shuts down 2027-02-26. On the 2026-11-10 bench (SON-593)
32
+ * gpt-transcribe transcribed 60 s and 229 s clips in full, returned nothing for silence and
33
+ * noise, and was more accurate than gpt-live-transcribe.
34
+ */
35
+ export const OPENAI_REALTIME_DEFAULT_TRANSCRIPTION_MODEL = "gpt-transcribe";
29
36
 
30
37
  /** qgrid default; Codex's own default is gpt-realtime-1.5 (core/src/realtime_conversation.rs:112). */
31
38
  export const OPENAI_REALTIME_DEFAULT_SPEECH_MODEL = "gpt-realtime-2.1-mini";
@@ -33,24 +40,10 @@ export const OPENAI_REALTIME_DEFAULT_SPEECH_MODEL = "gpt-realtime-2.1-mini";
33
40
  /** protocol/src/protocol.rs:408 (RealtimeVoicesList::builtin default_v2) */
34
41
  export const OPENAI_REALTIME_DEFAULT_VOICE = "marin";
35
42
 
36
- /** protocol/src/protocol.rs:368-379 (v2 voice list) */
37
- export const OPENAI_REALTIME_VOICES = [
38
- "alloy",
39
- "ash",
40
- "ballad",
41
- "coral",
42
- "echo",
43
- "sage",
44
- "shimmer",
45
- "verse",
46
- "marin",
47
- "cedar",
48
- ] as const;
49
-
50
- export type OpenAIRealtimeVoice = (typeof OPENAI_REALTIME_VOICES)[number];
43
+ export type OpenAIRealtimeVoice = (typeof OPENAI_SPEECH_VOICES)[number];
51
44
 
52
45
  export function isOpenAIRealtimeVoice(value: string): value is OpenAIRealtimeVoice {
53
- return OPENAI_REALTIME_VOICES.some((voice) => voice === value);
46
+ return OPENAI_SPEECH_VOICES.some((voice) => voice === value);
54
47
  }
55
48
 
56
49
  /**
@@ -58,7 +51,9 @@ export function isOpenAIRealtimeVoice(value: string): value is OpenAIRealtimeVoi
58
51
  * docs/diagnosis/2026-10-17-openai-realtime-audio-probe.md). Known limits, kept as documentation
59
52
  * rather than exclusions (user decision): gpt-live-transcribe and gpt-realtime-whisper returned
60
53
  * about half of a 60 s clip; gpt-realtime-whisper rejects `prompt` (server `invalid_value`);
61
- * whisper-1 accepts but ignores `prompt`.
54
+ * whisper-1 accepts but ignores `prompt`. gpt-live-transcribe still cut clips short on 2026-11-10
55
+ * (51 of 126 words on 60 s). OpenAI shuts down gpt-4o-mini-transcribe, gpt-4o-transcribe and
56
+ * whisper-1 on 2027-02-26; remove them here, from the SDK union and from the READMEs then.
62
57
  */
63
58
  export const OPENAI_TRANSCRIPTION_MODELS = [
64
59
  "gpt-4o-mini-transcribe",
@@ -108,52 +103,55 @@ export const OPENAI_LIVE_MODEL = "gpt-live-1";
108
103
  */
109
104
  const OPENAI_LIVE_WIRE_MODEL = "gpt-live-1-codex";
110
105
 
111
- /**
112
- * protocol/src/protocol.rs RealtimeVoicesList::builtin v3; Codex's live default is cove. Any other
113
- * voice still gets a 201 from /calls, but the session never starts (sideband 404).
114
- */
115
- export const OPENAI_LIVE_VOICES = [
116
- "cove",
117
- "juniper",
118
- "maple",
119
- "spruce",
120
- "ember",
121
- "vale",
122
- "breeze",
123
- "arbor",
124
- "sol",
125
- "aube",
126
- "bubbie",
127
- "haetsal",
128
- "hanul",
129
- "himari",
130
- "leher",
131
- "miko",
132
- "neer",
133
- "porto",
134
- "rindo",
135
- "rio",
136
- "rivage",
137
- "selva",
138
- "sonna",
139
- "tinta",
140
- "viola",
141
- ] as const;
142
-
143
106
  export const OPENAI_LIVE_DEFAULT_VOICE = "cove";
144
107
 
145
108
  export function isOpenAILiveVoice(value: string): boolean {
146
109
  return OPENAI_LIVE_VOICES.some((voice) => voice === value);
147
110
  }
148
111
 
149
- /** codex-api methods_frameless_bidi.rs session_json, without initial items or handoffs. */
150
- export function buildLiveSession(options: { voice: string; instructions?: string }): JsonValue {
151
- return {
112
+ /** A message the session starts from; user and developer text is input, assistant text output. */
113
+ export interface LiveHistoryMessage {
114
+ role: "user" | "assistant" | "developer";
115
+ text: string;
116
+ }
117
+
118
+ type LiveInitialItem = {
119
+ type: "message";
120
+ role: LiveHistoryMessage["role"];
121
+ content: Array<{ type: "input_text" | "output_text"; text: string }>;
122
+ };
123
+
124
+ /** The session sent with the call: codex-api methods_frameless_bidi.rs session_json. */
125
+ export type LiveSessionPayload = {
126
+ model: string;
127
+ instructions: string;
128
+ audio: { output: { voice: string } };
129
+ delegation: { type: "client" };
130
+ /** The history, as Codex's initial items. */
131
+ initial_items?: LiveInitialItem[];
132
+ };
133
+
134
+ export function buildLiveSession(options: {
135
+ voice: string;
136
+ instructions?: string;
137
+ history?: readonly LiveHistoryMessage[];
138
+ }): LiveSessionPayload {
139
+ const session: LiveSessionPayload = {
152
140
  model: OPENAI_LIVE_WIRE_MODEL,
153
141
  instructions: options.instructions ?? "",
154
142
  audio: { output: { voice: options.voice } },
155
143
  delegation: { type: "client" },
156
144
  };
145
+
146
+ if (options.history?.length) {
147
+ session.initial_items = options.history.map(({ role, text }) => ({
148
+ type: "message",
149
+ role,
150
+ content: [{ type: role === "assistant" ? "output_text" : "input_text", text }],
151
+ }));
152
+ }
153
+
154
+ return session;
157
155
  }
158
156
 
159
157
  /** One finished turn; the sideband also mirrors both audio streams, which qgrid skips. */
@@ -292,7 +290,12 @@ export function buildOpenAIRealtimeHeaders(
292
290
 
293
291
  const pcmFormat = { type: "audio/pcm", rate: OPENAI_REALTIME_SAMPLE_RATE } as const;
294
292
 
295
- type TranscriptionConfig = { model: string; language?: string; prompt?: string };
293
+ type TranscriptionConfig = {
294
+ model: string;
295
+ language?: string;
296
+ languages?: string[];
297
+ prompt?: string;
298
+ };
296
299
 
297
300
  type TranscriptionInput = {
298
301
  format: typeof pcmFormat;
@@ -318,7 +321,12 @@ export interface OpenAITranscriptionSessionOptions {
318
321
  export function buildTranscriptionSession(options: OpenAITranscriptionSessionOptions): JsonValue {
319
322
  const transcription: TranscriptionConfig = { model: options.model };
320
323
 
321
- if (options.language !== undefined) transcription.language = options.language;
324
+ // gpt-transcribe takes the list `languages` (sending `language` too is an `invalid_value` error);
325
+ // the gpt-4o family rejects `languages`. Subscription probe, 2026-11-10.
326
+ if (options.language !== undefined) {
327
+ if (options.model === "gpt-transcribe") transcription.languages = [options.language];
328
+ else transcription.language = options.language;
329
+ }
322
330
 
323
331
  if (options.prompt !== undefined) transcription.prompt = options.prompt;
324
332
  const input: TranscriptionInput = { format: pcmFormat, transcription };
@@ -159,11 +159,15 @@ describe("openai realtime protocol", () => {
159
159
  audio: {
160
160
  input: {
161
161
  format: { type: "audio/pcm", rate: 24000 },
162
- transcription: { model: "gpt-transcribe", language: "en", prompt: "qgrid" },
162
+ transcription: { model: "gpt-transcribe", languages: ["en"], prompt: "qgrid" },
163
163
  turn_detection: null,
164
164
  },
165
165
  },
166
166
  });
167
+
168
+ expect(buildTranscriptionSession({ model: "gpt-4o-transcribe", language: "ko" })).toMatchObject({
169
+ audio: { input: { transcription: { model: "gpt-4o-transcribe", language: "ko" } } },
170
+ });
167
171
  });
168
172
 
169
173
  it("serializes the conversational session with Codex's audio block and no tools", () => {
@@ -177,7 +181,7 @@ describe("openai realtime protocol", () => {
177
181
  input: {
178
182
  format: { type: "audio/pcm", rate: 24000 },
179
183
  noise_reduction: { type: "near_field" },
180
- transcription: { model: "gpt-4o-mini-transcribe" },
184
+ transcription: { model: "gpt-transcribe" },
181
185
  turn_detection: {
182
186
  type: "server_vad",
183
187
  interrupt_response: true,
@@ -712,6 +716,27 @@ describe("OpenAIVoiceClient.createLiveCall", () => {
712
716
  ]);
713
717
  });
714
718
 
719
+ it("seeds the session with history as Codex's initial_items", async () => {
720
+ const fetchMock = vi.fn(async () => callsResponse("rtc_live"));
721
+ const client = new OpenAIVoiceClient({ fetch: fetchMock as unknown as typeof fetch });
722
+
723
+ await client.createLiveCall(credentials, {
724
+ sdp: "v=0",
725
+ history: [
726
+ { role: "developer", text: "Stay in character as Kuma." },
727
+ { role: "user", text: "My name is Dongseon." },
728
+ { role: "assistant", text: "Nice to meet you!" },
729
+ ],
730
+ });
731
+
732
+ const [, init] = fetchMock.mock.calls[0] as unknown as [string, RequestInit];
733
+ expect(JSON.parse(String(init.body)).session.initial_items).toEqual([
734
+ { type: "message", role: "developer", content: [{ type: "input_text", text: "Stay in character as Kuma." }] },
735
+ { type: "message", role: "user", content: [{ type: "input_text", text: "My name is Dongseon." }] },
736
+ { type: "message", role: "assistant", content: [{ type: "output_text", text: "Nice to meet you!" }] },
737
+ ]);
738
+ });
739
+
715
740
  it("ends at a bare sideband close with the last reported usage", async () => {
716
741
  const ws = mockedWebSocket();
717
742
 
@@ -20,6 +20,7 @@ import {
20
20
  liveDelegationCreatedEvent,
21
21
  liveSessionClosedEvent,
22
22
  liveTurnDoneEvent,
23
+ type LiveHistoryMessage,
23
24
  liveUsageUpdatedEvent,
24
25
  OPENAI_LIVE_ALPHA_HEADER,
25
26
  OPENAI_LIVE_CALLS_QUERY,
@@ -148,6 +149,8 @@ export interface OpenAILiveCallRequest {
148
149
  sdp: string;
149
150
  voice?: string;
150
151
  instructions?: string;
152
+ /** An earlier conversation the session starts from. */
153
+ history?: readonly LiveHistoryMessage[];
151
154
  signal?: AbortSignal;
152
155
  /** Called with the conversation so far after each finished turn; must not throw. */
153
156
  onTurn?: (turns: readonly OpenAILiveTurn[]) => void;
@@ -687,7 +690,11 @@ export class OpenAIVoiceClient {
687
690
  headers: { ...headers, "Content-Type": "application/json" },
688
691
  body: JSON.stringify({
689
692
  sdp: request.sdp,
690
- session: buildLiveSession({ voice, instructions: request.instructions }),
693
+ session: buildLiveSession({
694
+ voice,
695
+ instructions: request.instructions,
696
+ history: request.history,
697
+ }),
691
698
  }),
692
699
  signal,
693
700
  });
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n}from"./vendor-react-8xo7RSum.js";var r=e(t()),i=n(),a=(0,r.forwardRef)(({title:e,titleId:t,...n},r)=>(0,i.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,i.jsx)(`title`,{id:t,children:e}):null,(0,i.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 6L9 17l-5-5`})]})),o=(0,r.forwardRef)(({title:e,titleId:t,...n},r)=>(0,i.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,i.jsx)(`title`,{id:t,children:e}):null,(0,i.jsxs)(`g`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,children:[(0,i.jsx)(`rect`,{width:14,height:14,x:8,y:8,rx:2,ry:2}),(0,i.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]})]}));function s({text:e,dark:t}){let[n,s]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>s(!1),1500);return()=>clearTimeout(e)},[n]),(0,i.jsx)(`button`,{type:`button`,className:`absolute top-2 right-2 p-1 rounded transition-colors ${t?`text-sand-500 hover:text-sand-300`:`text-sand-400 hover:text-sand-600`}`,onClick:()=>{navigator.clipboard.writeText(e),s(!0)},children:n?(0,i.jsx)(a,{className:`size-3.5 text-sage-500`}):(0,i.jsx)(o,{className:`size-3.5`})})}var c=/((?:^|(?<=\s))\/\/[^\n]*)|("(?:[^"\\]|\\.)*")|(\b\d+(?:\.\d+)?\b)|(\btype\b|\bz\b(?=\.)|\b(?:import|from|const|await|return|satisfies)\b(?!\??:))|(\b(?:string|number|boolean|null|unknown|Record|true|false)\b)|([{}[\]()<>|?:,.=;])|([A-Za-z_$][\w$]*)|(\s+|.)/gm;function l(e){let t=[],n=!1;for(let r of e.matchAll(c)){let[e,a,o,s,c,l,u,d]=r,f=`${r.index}-${e}`;a?t.push((0,i.jsx)(`span`,{className:`text-sand-500`,children:e},f)):o||s?t.push((0,i.jsx)(`span`,{className:`text-sage-400`,children:e},f)):c?(n=e===`type`,t.push((0,i.jsx)(`span`,{className:`text-sienna-400`,children:e},f))):l?t.push((0,i.jsx)(`span`,{className:`text-blue-300`,children:e},f)):u?t.push((0,i.jsx)(`span`,{className:`text-sand-500`,children:e},f)):d&&n?(n=!1,t.push((0,i.jsx)(`span`,{className:`font-semibold text-sand-50`,children:e},f))):t.push(e)}return t}function u({title:e,code:t,actions:n,scroll:a=!0}){let o=(0,r.useMemo)(()=>l(t),[t]);return(0,i.jsxs)(`div`,{className:`panel overflow-hidden`,children:[(0,i.jsxs)(`div`,{className:`panel-header flex items-center px-4 py-2`,children:[(0,i.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-sand-500 font-medium`,children:e}),n&&(0,i.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:n})]}),(0,i.jsxs)(`div`,{className:`relative`,children:[(0,i.jsx)(s,{text:t,dark:!0}),(0,i.jsx)(`pre`,{className:`bg-sand-900 px-4 py-3 text-[12px] text-sand-200 whitespace-pre-wrap wrap-break-word font-mono leading-relaxed ${a?`max-h-64 overflow-auto`:``}`,children:o})]})]})}function d({src:e,words:t,autoPlay:n,className:a=`h-8 w-full`}){let o=(0,r.useRef)(null),s=(0,r.useRef)(0),[c,l]=(0,r.useState)(-1),u=()=>{l(o.current?.currentTime??-1),s.current=requestAnimationFrame(u)},d=()=>cancelAnimationFrame(s.current);return(0,r.useEffect)(()=>()=>cancelAnimationFrame(s.current),[]),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`audio`,{ref:o,controls:!0,autoPlay:n,src:e,className:a,onPlay:()=>{d(),u()},onPause:d,onTimeUpdate:e=>l(e.currentTarget.currentTime),onEnded:()=>{d(),l(-1)}}),t&&t.length>0&&(0,i.jsx)(`p`,{className:`flex flex-wrap gap-x-0.5 gap-y-1 text-[13px] leading-relaxed`,children:t.map((e,t)=>(0,i.jsx)(`button`,{type:`button`,onClick:()=>{let t=o.current;t&&(t.currentTime=e.start,l(e.start),t.play())},title:`${e.start.toFixed(2)}–${e.end.toFixed(2)}s · play from here`,className:`rounded px-1 transition-colors duration-75 ${c>=e.start&&c<e.end?`bg-sienna-500 text-white`:`text-sand-700 hover:bg-sand-100`}`,children:e.text},t))})]})}export{l as i,u as n,s as r,d as t};