@cartanova/qgrid-cli 2.22.2 → 2.23.1

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 (77) hide show
  1. package/bundle/dist/application/qgrid/model-catalog.js +62 -0
  2. package/bundle/dist/application/qgrid/openai-compat.js +127 -0
  3. package/bundle/dist/application/qgrid/qgrid-run-lifecycle.js +2 -2
  4. package/bundle/dist/application/qgrid/qgrid.frame.js +204 -8
  5. package/bundle/dist/application/qgrid/qgrid.types.js +82 -2
  6. package/bundle/dist/application/qgrid/transcribe-stream.js +282 -0
  7. package/bundle/dist/application/queries.generated.js +2 -1
  8. package/bundle/dist/application/request-log/request-log.model.js +5 -4
  9. package/bundle/dist/server-error-handler.js +6 -3
  10. package/bundle/dist/sonamu.config.js +5 -2
  11. package/bundle/dist/utils/providers/anthropic/anthropic-constants.js +8 -2
  12. package/bundle/dist/utils/providers/anthropic/anthropic-quota.js +1 -1
  13. package/bundle/dist/utils/providers/common/model-cost.js +29 -2
  14. package/bundle/dist/utils/providers/openai/openai-dispatcher.js +9 -1
  15. package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +38 -6
  16. package/bundle/dist/utils/providers/openai/openai-voice-client.js +131 -3
  17. package/bundle/src/application/qgrid/model-catalog.test.ts +37 -0
  18. package/bundle/src/application/qgrid/model-catalog.ts +85 -0
  19. package/bundle/src/application/qgrid/openai-compat.test.ts +99 -0
  20. package/bundle/src/application/qgrid/openai-compat.ts +157 -0
  21. package/bundle/src/application/qgrid/qgrid-run-lifecycle.test.ts +1 -1
  22. package/bundle/src/application/qgrid/qgrid-run-lifecycle.ts +1 -1
  23. package/bundle/src/application/qgrid/qgrid.frame.test.ts +5 -0
  24. package/bundle/src/application/qgrid/qgrid.frame.ts +294 -0
  25. package/bundle/src/application/qgrid/qgrid.types.ts +134 -0
  26. package/bundle/src/application/qgrid/transcribe-stream.test.ts +165 -0
  27. package/bundle/src/application/qgrid/transcribe-stream.ts +381 -0
  28. package/bundle/src/application/queries.generated.ts +3 -0
  29. package/bundle/src/application/request-log/request-log.model.test.ts +4 -3
  30. package/bundle/src/application/request-log/request-log.model.ts +4 -3
  31. package/bundle/src/application/sonamu.generated.http +12 -0
  32. package/bundle/src/server-error-handler.ts +10 -7
  33. package/bundle/src/sonamu.config.ts +4 -0
  34. package/bundle/src/utils/providers/anthropic/anthropic-constants.test.ts +3 -0
  35. package/bundle/src/utils/providers/anthropic/anthropic-constants.ts +3 -1
  36. package/bundle/src/utils/providers/anthropic/anthropic-quota.ts +1 -1
  37. package/bundle/src/utils/providers/common/effort.test.ts +2 -0
  38. package/bundle/src/utils/providers/common/model-cost.test.ts +11 -0
  39. package/bundle/src/utils/providers/common/model-cost.ts +43 -5
  40. package/bundle/src/utils/providers/openai/openai-dispatcher.ts +15 -0
  41. package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +46 -5
  42. package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +89 -2
  43. package/bundle/src/utils/providers/openai/openai-voice-client.ts +188 -0
  44. package/bundle/web-dist/client/assets/index-CtkfXtee.js +104 -0
  45. package/bundle/web-dist/client/assets/logs-C_U9lGtE.js +1 -0
  46. package/bundle/web-dist/client/assets/{monit-0qjGcPcD.js → monit-CNQyE4bk.js} +1 -1
  47. package/bundle/web-dist/client/assets/{routes-D53FyOOp.js → routes-72N6ogd2.js} +2 -2
  48. package/bundle/web-dist/client/assets/{settings-Cbz57odO.js → settings-DbwnDBrc.js} +1 -1
  49. package/bundle/web-dist/client/assets/{show-Boi25Rbi.js → show-BPkKGDnC.js} +2 -2
  50. package/bundle/web-dist/client/assets/tokens-2ig4rFfF.js +1 -0
  51. package/bundle/web-dist/client/assets/{use-oauth-login-flow-CjFv4NI0.js → use-oauth-login-flow-CvjEVH_T.js} +1 -1
  52. package/bundle/web-dist/client/assets/use-update-token-mutation-C8viUPmK.js +1 -0
  53. package/bundle/web-dist/client/assets/{voice-BDO8X2H0.js → voice-D2RSPjn9.js} +2 -2
  54. package/bundle/web-dist/client/index.html +1 -1
  55. package/bundle/web-dist/server/assets/{TimedPlayer-mpJpP5tQ.js → TimedPlayer-B9ds1sqM.js} +1 -1
  56. package/bundle/web-dist/server/assets/{logs-CFa_xamY.js → logs-JziKvWBp.js} +3 -3
  57. package/bundle/web-dist/server/assets/{monit-BF6osfj5.js → monit-CzjNOowb.js} +2 -2
  58. package/bundle/web-dist/server/assets/{plus-DwQFfeid.js → plus-BrRDgdaN.js} +1 -1
  59. package/bundle/web-dist/server/assets/{refresh-cw-Bj-Jxeb6.js → refresh-cw-wU5-wVTi.js} +1 -1
  60. package/bundle/web-dist/server/assets/{request-model-D_iYrudl.js → request-model-D07WSRKx.js} +1 -1
  61. package/bundle/web-dist/server/assets/{routes-B6be8sJP.js → routes-C1tDj0QN.js} +3 -3
  62. package/bundle/web-dist/server/assets/{services.generated-D0995hJr.js → services.generated-rlOX8J2n.js} +201 -0
  63. package/bundle/web-dist/server/assets/{settings-DAle7AgI.js → settings-DJQUI8bU.js} +3 -3
  64. package/bundle/web-dist/server/assets/{show-BTSdMDoM.js → show-BElTj6MG.js} +3 -3
  65. package/bundle/web-dist/server/assets/{tokens-Bc9flfLz.js → tokens-CRpUPv-5.js} +4 -4
  66. package/bundle/web-dist/server/assets/{use-oauth-login-flow-C7c0gCjf.js → use-oauth-login-flow-DLRPNhNE.js} +1 -1
  67. package/bundle/web-dist/server/assets/{use-update-token-mutation-DLJDGdxu.js → use-update-token-mutation-DJkct-j8.js} +1 -1
  68. package/bundle/web-dist/server/assets/{voice-CEQT57xZ.js → voice-BZBlBBpn.js} +4 -10
  69. package/bundle/web-dist/server/entry-server.generated.js +118 -26
  70. package/package.json +1 -1
  71. package/skills/qgrid/references/anthropic-claude-code-runtime.md +4 -3
  72. package/skills/qgrid/references/openai-codex-runtime.md +29 -10
  73. package/skills/qgrid/references/sonamu-api-web-flow.md +1 -1
  74. package/bundle/web-dist/client/assets/index-CiSsWsVT.js +0 -104
  75. package/bundle/web-dist/client/assets/logs-Bir9gDzp.js +0 -1
  76. package/bundle/web-dist/client/assets/tokens-BuK8BpAd.js +0 -1
  77. package/bundle/web-dist/client/assets/use-update-token-mutation-BKufO9oe.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n}from"./vendor-react-8xo7RSum.js";import{u as r}from"./vendor-tanstack-DMgmqjm4.js";import{A as i,C as a,E as o,T as s,_ as c,b as l,g as u,h as d,j as f,m as p,n as m,p as h,s as g}from"./index-CiSsWsVT.js";import{n as _,t as v}from"./TimedPlayer-UGSsgTKj.js";var y=e(t()),b=n(),x=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 3h6v6m-11 5L21 3m-3 10v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`})]})),S=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M21 12a9 9 0 1 1-6.219-8.56`})]})),C=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsxs)(`g`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,children:[(0,b.jsx)(`path`,{d:`M12 19v3m7-12v2a7 7 0 0 1-14 0v-2`}),(0,b.jsx)(`rect`,{width:6,height:13,x:9,y:2,rx:3})]})]})),w=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`})]})),T=24e3;function E(e,t=T){let n=new Uint8Array(44+e.length*2),r=new DataView(n.buffer),i=(e,t)=>{for(let n=0;n<t.length;n++)r.setUint8(e+n,t.charCodeAt(n))};return i(0,`RIFF`),r.setUint32(4,36+e.length*2,!0),i(8,`WAVE`),i(12,`fmt `),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,`data`),r.setUint32(40,e.length*2,!0),e.forEach((e,t)=>{let n=Math.max(-1,Math.min(1,e));r.setInt16(44+t*2,n<0?n*32768:n*32767,!0)}),n}function D(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}async function O(e){let t=new AudioContext({sampleRate:T});try{let n=await t.decodeAudioData(await e.arrayBuffer()),r=new Float32Array(n.length);for(let e=0;e<n.numberOfChannels;e++){let t=n.getChannelData(e);for(let e=0;e<t.length;e++)r[e]+=t[e]/n.numberOfChannels}return D(E(r))}finally{await t.close()}}var k=e=>JSON.stringify(e),A=(...e)=>`import { ${[`qgrid`,...e.map(e=>`type ${e}`)].join(`, `)} } from "@cartanova/qgrid-ai-sdk";`;function j(e){let t=e.model.startsWith(`openai/`),n=t?`QgridOpenAISpeechVoice`:`QgridGrokVoice`,r=[` model: qgrid.speech(${k(e.model)}),`,` text: ${k(e.text)},`,` voice: ${k(e.voice)} satisfies ${n},`];return e.instructions&&r.push(` instructions: ${k(e.instructions)},`),e.speed!==void 0&&r.push(` speed: ${e.speed},`),r.push(` outputFormat: ${k(t?`wav`:`mp3`)},`),e.withTimestamps&&r.push(` providerOptions: { qgrid: { withTimestamps: true } },`),[`import { generateSpeech } from "ai";`,A(n),``,`const speech = await generateSpeech({`,...r,`});`].join(`
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n}from"./vendor-react-8xo7RSum.js";import{u as r}from"./vendor-tanstack-DMgmqjm4.js";import{A as i,C as a,E as o,T as s,_ as c,b as l,c as u,g as d,h as f,j as p,m,n as h,o as g}from"./index-CtkfXtee.js";import{n as _,t as v}from"./TimedPlayer-UGSsgTKj.js";var y=e(t()),b=n(),x=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 3h6v6m-11 5L21 3m-3 10v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`})]})),S=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M21 12a9 9 0 1 1-6.219-8.56`})]})),C=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsxs)(`g`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,children:[(0,b.jsx)(`path`,{d:`M12 19v3m7-12v2a7 7 0 0 1-14 0v-2`}),(0,b.jsx)(`rect`,{width:6,height:13,x:9,y:2,rx:3})]})]})),w=(0,y.forwardRef)(({title:e,titleId:t,...n},r)=>(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`1.2em`,height:`1.2em`,ref:r,"aria-labelledby":t,...n,children:[e?(0,b.jsx)(`title`,{id:t,children:e}):null,(0,b.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`})]})),T=24e3;function E(e,t=T){let n=new Uint8Array(44+e.length*2),r=new DataView(n.buffer),i=(e,t)=>{for(let n=0;n<t.length;n++)r.setUint8(e+n,t.charCodeAt(n))};return i(0,`RIFF`),r.setUint32(4,36+e.length*2,!0),i(8,`WAVE`),i(12,`fmt `),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,`data`),r.setUint32(40,e.length*2,!0),e.forEach((e,t)=>{let n=Math.max(-1,Math.min(1,e));r.setInt16(44+t*2,n<0?n*32768:n*32767,!0)}),n}function D(e){let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}async function O(e){let t=new AudioContext({sampleRate:T});try{let n=await t.decodeAudioData(await e.arrayBuffer()),r=new Float32Array(n.length);for(let e=0;e<n.numberOfChannels;e++){let t=n.getChannelData(e);for(let e=0;e<t.length;e++)r[e]+=t[e]/n.numberOfChannels}return D(E(r))}finally{await t.close()}}var k=e=>JSON.stringify(e),A=(...e)=>`import { ${[`qgrid`,...e.map(e=>`type ${e}`)].join(`, `)} } from "@cartanova/qgrid-ai-sdk";`;function j(e){let t=e.model.startsWith(`openai/`),n=t?`QgridOpenAISpeechVoice`:`QgridGrokVoice`,r=[` model: qgrid.speech(${k(e.model)}),`,` text: ${k(e.text)},`,` voice: ${k(e.voice)} satisfies ${n},`];return e.instructions&&r.push(` instructions: ${k(e.instructions)},`),e.speed!==void 0&&r.push(` speed: ${e.speed},`),r.push(` outputFormat: ${k(t?`wav`:`mp3`)},`),e.withTimestamps&&r.push(` providerOptions: { qgrid: { withTimestamps: true } },`),[`import { generateSpeech } from "ai";`,A(n),``,`const speech = await generateSpeech({`,...r,`});`].join(`
2
2
  `)}function M(e){let t=e.model.startsWith(`openai/`),n=[` model: qgrid.transcription(${k(e.model)}),`,...t?[` // OpenAI takes PCM16 WAV or raw PCM.`,` audio: await readFile("recording.wav"),`]:[` audio: await readFile("recording.mp3"),`]];return e.prompt&&n.push(` providerOptions: { openai: { prompt: ${k(e.prompt)} } },`),[`import { readFile } from "node:fs/promises";`,`import { transcribe } from "ai";`,A(),``,`const transcript = await transcribe({`,...n,`});`].join(`
3
3
  `)}function N(e){let t=[`voice: ${k(e.voice)} satisfies QgridLiveVoice`];e.instructions&&t.push(`instructions: ${k(e.instructions)}`);let{model:n,effort:r,webSearch:i}=e.delegation,a=[` delegation: {`,` model: ${k(n)},`,` effort: ${k(r)},`,` webSearch: ${i},`,` },`];return e.logged||a.push(` logger: false,`),e.continues&&a.push(` history, // earlier turns, at most 128`),[`// Browser`,`import { createQgridRealtime } from "@cartanova/qgrid-ai-sdk/realtime";`,`import { experimental_useRealtime } from "@ai-sdk/react";`,``,`// Module scope: the hook starts a new session whenever it gets a new model object.`,`const model = createQgridRealtime("openai/gpt-live-1");`,``,`const realtime = experimental_useRealtime({`,` model,`,` api: { session: "/api/live" },`,`});`,``,`// Server: POST /api/live`,A(`QgridLiveVoice`),``,`const answer = await qgrid.realtime("openai/gpt-live-1").doCreateWebRTCSession({`,` sdp,`,` // Voice and instructions are set here, on the server.`,` sessionConfig: {`,...t.map(e=>` ${e},`),` providerOptions: {`,` qgrid: {`,...a,` },`,` },`,` },`,`});`].join(`
4
- `)}var P=`qgrid_voice_playground`,F=[`grok/grok-tts`,`openai/gpt-realtime-2.1-mini`,`openai/gpt-realtime-2.1`],I=[`openai/gpt-transcribe`,`grok/grok-voice-transcribe-2.0`],L=[{label:`Female`,voices:p.female},{label:`Male`,voices:p.male}],R=[{label:``,voices:u}],z={provider:`timing from Grok TTS`,aligned:`timing from qgrid aligner`},B=e=>e.startsWith(`openai/`),V=`w-full rounded-lg border border-sand-200/80 bg-white px-2.5 py-1.5 text-[12px] text-sand-800 placeholder:text-sand-400 focus:outline-none focus:border-sienna-300 disabled:opacity-50`,H=`${V} h-8`,U=`px-3.5 py-1.5 text-[12px] font-medium rounded-lg bg-sienna-500 text-white hover:bg-sienna-600 disabled:opacity-50 transition-all duration-150 active:scale-[0.97] inline-flex items-center gap-1.5 shadow-sm`;function W({label:e,children:t}){return(0,b.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,b.jsx)(`span`,{className:`text-[11px] font-medium text-sand-500`,children:e}),t]})}var G=e=>e.slice(e.indexOf(`/`)+1);function K({title:e,meta:t,requestLogId:n,onRemove:i,children:a}){return(0,b.jsxs)(`li`,{className:`flex flex-col gap-1.5 px-4 py-3`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-[12px]`,children:[(0,b.jsx)(`span`,{className:`font-medium text-sand-800`,children:e}),(0,b.jsx)(`span`,{className:`tabular-nums text-sand-400`,children:t}),(0,b.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[n!==void 0&&(0,b.jsxs)(r,{to:`/requests/show`,search:{id:n},target:`_blank`,className:`inline-flex items-center gap-1 tabular-nums text-sand-500 hover:text-sienna-500`,children:[`request log #`,n,(0,b.jsx)(x,{className:`size-3`})]}),(0,b.jsx)(`button`,{type:`button`,onClick:i,title:`Remove from history`,className:`text-sand-300 hover:text-sand-600`,children:(0,b.jsx)(s,{className:`size-3.5`})})]})]}),a]})}function q({code:e,note:t,children:n}){return(0,b.jsxs)(`div`,{className:`flex flex-col xl:flex-row gap-4 items-stretch xl:items-start`,children:[(0,b.jsx)(`div`,{className:`panel overflow-hidden flex-1 min-w-0`,children:n}),(0,b.jsx)(`div`,{className:`min-w-0 xl:w-[32rem] xl:shrink-0 xl:sticky xl:top-4`,children:(0,b.jsx)(_,{title:`AI SDK`,code:e,scroll:!1,actions:t&&(0,b.jsx)(`span`,{className:`text-[11px] text-sand-400`,children:t})})})]})}function J({empty:e,children:t}){return t.length===0?(0,b.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-sand-400`,children:e}):(0,b.jsx)(`ul`,{className:`divide-y divide-sand-100`,children:t})}function Y(e){if(!e)return;let t=[],n;return e.graphChars.forEach((r,i)=>{let[a,o]=e.graphTimes[i];/\s/.test(r)?n=void 0:n?(n.text+=r,n.end=o):(n={text:r,start:a,end:o},t.push(n))}),t}function X(){let[e,t]=(0,y.useState)(F[0]),[n,r]=(0,y.useState)(p.female[0]),[i,a]=(0,y.useState)(``),[s,c]=(0,y.useState)(`Hi! What did you do this weekend?`),[l,d]=(0,y.useState)([]),[f,m]=(0,y.useState)(!0),[h,_]=(0,y.useState)(1),x=(0,y.useRef)(0),C=g.useSpeakMutation(),T=B(e),E=e=>{B(e)!==T&&r(B(e)?u[0]:p.female[0]),t(e)},D=T&&i.trim()?i.trim():void 0,O=t=>{let n=performance.now(),r={model:e,text:s,voice:t,projectName:P};D&&(r.instructions=D),f&&(r.withTimestamps=!0),!T&&h!==1&&(r.speed=h),C.mutate({params:r},{onSuccess:i=>{let a={key:x.current++,src:`data:${i.mimeType};base64,${i.audio}`,model:e,voice:t,instructions:r.instructions,speed:r.speed,text:s,elapsedMs:performance.now()-n,requestLogId:i.requestLogId,words:Y(i.audioTimestamps),timing:i.timestampsError?`timing failed: ${i.timestampsError}`:i.timestampsSource&&z[i.timestampsSource]};d(e=>[a,...e])}})},k=(0,y.useRef)(null),[A,M]=(0,y.useState)();(0,y.useEffect)(()=>()=>k.current?.pause(),[]);let N=e=>{if(r(e),k.current?.pause(),A===e){M(void 0);return}let t=new Audio(`/voice-samples/${T?`openai`:`grok`}/${e}.mp3`);t.addEventListener(`ended`,()=>M(t=>t===e?void 0:t),{once:!0}),k.current=t,M(e),t.play()},I=j({model:e,text:s,voice:n,instructions:D,speed:!T&&h!==1?h:void 0,withTimestamps:f});return(0,b.jsxs)(q,{code:I,children:[(0,b.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,b.jsx)(W,{label:`Model`,children:(0,b.jsx)(`select`,{value:e,onChange:e=>E(e.target.value),className:H,children:F.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),T?(0,b.jsx)(W,{label:`Style instructions (OpenAI only)`,children:(0,b.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`e.g. Speak with a gentle Irish accent.`,className:H})}):(0,b.jsx)(W,{label:`Speed (Grok only) — ${h.toFixed(2)}×`,children:(0,b.jsx)(`input`,{type:`range`,min:.7,max:1.5,step:.05,value:h,onChange:e=>_(Number(e.target.value)),className:`h-8 accent-sienna-500`})})]}),(0,b.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,b.jsx)(`span`,{className:`text-[11px] font-medium text-sand-500`,children:`Voice — ▶ plays a short self-introduction sample, a name selects it`}),(T?R:L).map(e=>(0,b.jsxs)(`div`,{className:`flex items-start gap-2`,children:[e.label&&(0,b.jsx)(`span`,{className:`w-12 shrink-0 pt-1 text-[11px] text-sand-400`,children:e.label}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.voices.map(e=>(0,b.jsxs)(`span`,{className:`inline-flex items-center overflow-hidden rounded-full border text-[12px] ${n===e?`border-sienna-400 bg-sienna-50 text-sienna-700`:`border-sand-200/80 bg-white text-sand-700`}`,children:[(0,b.jsx)(`button`,{type:`button`,onClick:()=>r(e),"aria-pressed":n===e,className:`py-0.5 pl-2.5 pr-1 hover:text-sienna-600`,children:e}),(0,b.jsx)(`button`,{type:`button`,onClick:()=>N(e),title:A===e?`Stop "${e}"`:`Play a "${e}" sample`,className:`py-1 pl-1 pr-2 hover:text-sienna-500 ${A===e?`text-sienna-500`:`text-sand-400`}`,children:A===e?(0,b.jsx)(o,{className:`size-3`}):(0,b.jsx)(w,{className:`size-3`})})]},e))})]},e.label))]}),(0,b.jsx)(W,{label:`Text`,children:(0,b.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:3,className:`${V} resize-y`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(`button`,{type:`button`,onClick:()=>O(n),disabled:C.isPending||!s.trim(),className:U,children:[C.isPending&&(0,b.jsx)(S,{className:`size-3.5 animate-spin`}),`Generate with `,n]}),(0,b.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px] text-sand-600`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>m(e.target.checked),className:`accent-sienna-500`}),`Word timing`]}),C.isError&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:C.error?.message})]})]}),(0,b.jsx)(`div`,{className:`border-t border-sand-100`,children:(0,b.jsx)(J,{empty:`Generated clips stack here, newest first, so voices can be compared side by side.`,children:l.map(e=>(0,b.jsxs)(K,{title:[e.voice,G(e.model),e.speed&&`${e.speed}×`].filter(Boolean).join(` · `),meta:[`${(e.elapsedMs/1e3).toFixed(1)}s`,e.timing].filter(Boolean).join(` · `),requestLogId:e.requestLogId,onRemove:()=>d(t=>t.filter(t=>t.key!==e.key)),children:[(!e.words||e.instructions)&&(0,b.jsxs)(`p`,{className:`truncate text-[12px] text-sand-600`,title:e.text,children:[!e.words&&e.text,e.instructions&&(0,b.jsxs)(`span`,{className:`text-sand-400`,children:[` — `,e.instructions]})]}),(0,b.jsx)(v,{src:e.src,words:e.words,autoPlay:!0})]},e.key))})})]})}function Z(){let[e,t]=(0,y.useState)(I[0]),[n,r]=(0,y.useState)(``),[i,a]=(0,y.useState)(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(),[d,f]=(0,y.useState)([]),p=(0,y.useRef)(null),m=(0,y.useRef)([]),h=(0,y.useRef)(0),_=g.useTranscribeMutation(),x=B(e);(0,y.useEffect)(()=>()=>{p.current?.stream.getTracks().forEach(e=>e.stop()),m.current.forEach(e=>URL.revokeObjectURL(e))},[]);let w=e=>{let t=URL.createObjectURL(e);m.current.push(t),a({blob:e,url:t,clip:m.current.length})},T=async()=>{if(s)p.current?.stop(),c(!1);else{u(void 0);try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e),n=[];t.ondataavailable=e=>n.push(e.data),t.onstop=()=>{e.getTracks().forEach(e=>e.stop()),w(new Blob(n,{type:t.mimeType}))},t.start(),p.current=t,c(!0)}catch(e){u(e instanceof Error?e.message:String(e))}}},E=async()=>{if(!i)return;u(void 0);let t=i.blob.type.split(`;`)[0],r;try{r=!x&&t.startsWith(`audio/`)?{audio:D(new Uint8Array(await i.blob.arrayBuffer())),mediaType:t}:{audio:await O(i.blob),mediaType:`audio/wav`}}catch(e){u(`could not decode audio: ${e instanceof Error?e.message:String(e)}`);return}let a={model:e,...r,projectName:P};x&&n.trim()&&(a.prompt=n.trim());let o=performance.now();_.mutate({params:a},{onSuccess:t=>{let n={key:h.current++,clip:i.clip,clipUrl:i.url,model:e,prompt:a.prompt,text:t.text,elapsedMs:performance.now()-o,durationSec:t.durationSec,requestLogId:t.requestLogId,words:t.words};f(e=>[n,...e])}})},k=M({model:e,prompt:x&&n.trim()?n.trim():void 0});return(0,b.jsxs)(q,{code:k,children:[(0,b.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,b.jsx)(W,{label:`Model`,children:(0,b.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:H,children:I.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),x&&(0,b.jsx)(W,{label:`Prompt (OpenAI only)`,children:(0,b.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`domain words, e.g. qgrid, Kuma`,className:H})})]}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,b.jsxs)(`button`,{type:`button`,onClick:T,className:`${U} ${s?`bg-danger-500 hover:bg-danger-500`:``}`,children:[s?(0,b.jsx)(o,{className:`size-3.5`}):(0,b.jsx)(C,{className:`size-3.5`}),s?`Stop`:`Record`]}),(0,b.jsxs)(`label`,{className:`text-[12px] text-sand-600 cursor-pointer hover:text-sienna-500`,children:[`or upload a file`,(0,b.jsx)(`input`,{type:`file`,accept:`audio/*`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&w(t)}})]}),l&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:l})]}),i&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(`span`,{className:`shrink-0 text-[11px] font-medium text-sand-500`,children:[`clip `,i.clip]}),(0,b.jsx)(`audio`,{controls:!0,src:i.url,className:`h-8 w-full`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(`button`,{type:`button`,onClick:E,disabled:!i||s||_.isPending,className:U,children:[_.isPending&&(0,b.jsx)(S,{className:`size-3.5 animate-spin`}),`Transcribe`]}),_.isError&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:_.error?.message})]})]}),(0,b.jsx)(`div`,{className:`border-t border-sand-100`,children:(0,b.jsx)(J,{empty:`Transcripts stack here, newest first; run one clip through several models to compare.`,children:d.map(e=>(0,b.jsx)(K,{title:`clip ${e.clip} · ${G(e.model)}`,meta:[`${(e.elapsedMs/1e3).toFixed(1)}s`,e.durationSec===void 0?``:`${e.durationSec.toFixed(1)}s audio`,e.prompt?`prompt: ${e.prompt}`:``].filter(Boolean).join(` · `),requestLogId:e.requestLogId,onRemove:()=>f(t=>t.filter(t=>t.key!==e.key)),children:e.words&&e.words.length>0?(0,b.jsx)(v,{src:e.clipUrl,words:e.words}):(0,b.jsx)(`p`,{className:`rounded-lg bg-sand-50 px-3 py-2 text-[13px] text-sand-800 whitespace-pre-wrap`,children:e.text||`(empty transcript)`})},e.key))})})]})}var Q=`openai/gpt-6-luna`,ee=l({type:a(),turn:l({id:a(),role:a(),transcript:a()}).optional(),turn_id:a().optional(),delta:a().optional()}),te=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`;function $({pc:e,channel:t,mic:n}){t.readyState===`open`&&t.send(JSON.stringify({type:`session.close`})),n.getTracks().forEach(e=>e.stop()),setTimeout(()=>e.close(),500)}function ne(){let[e,t]=(0,y.useState)(d[0]),[n,i]=(0,y.useState)(``),[a,s]=(0,y.useState)(Q),[l,u]=(0,y.useState)(`low`),[f,p]=(0,y.useState)(!1),[m,_]=(0,y.useState)(!0),[v,w]=(0,y.useState)([]),T=!a.startsWith(`anthropic/`),[E,D]=(0,y.useState)(`idle`),[O,k]=(0,y.useState)(),[A,j]=(0,y.useState)([]),[M,F]=(0,y.useState)(),[I,L]=(0,y.useState)(0),R=(0,y.useRef)(null),z=(0,y.useRef)(null),B=g.useLiveCallMutation();(0,y.useEffect)(()=>()=>{R.current&&$(R.current)},[]),(0,y.useEffect)(()=>{if(E!==`live`)return;let e=Date.now(),t=setInterval(()=>L(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[E]);let V=()=>{R.current&&$(R.current),R.current=null,D(`idle`)},G=e=>{let t;try{t=ee.safeParse(JSON.parse(e)).data}catch{return}if(!t)return;let{type:n,turn:r,turn_id:i,delta:a}=t;if(n===`session.closed`)V();else if(r&&(n===`turn.created`||n===`turn.done`)){let e={id:r.id,role:r.role,text:r.transcript};j(t=>t.some(e=>e.id===r.id)?t.map(t=>t.id===r.id?e:t):[...t,e])}else n===`turn.delta`&&i&&a&&j(e=>e.map(e=>e.id===i?{...e,text:e.text+a}:e))},K=async t=>{let r=t?[...v,...A.flatMap(e=>e.text.trim()?[{role:e.role===`assistant`?`assistant`:`user`,text:e.text.trim()}]:[])].slice(-128):[];w(r),k(void 0),j([]),F(void 0),L(0),D(`connecting`);let i,o;try{i=await navigator.mediaDevices.getUserMedia({audio:!0});let t=new RTCPeerConnection;o=t,i.getTracks().forEach(e=>t.addTrack(e)),t.addEventListener(`track`,e=>{z.current&&(z.current.srcObject=new MediaStream([e.track]))});let s=t.createDataChannel(`oai-events`);s.addEventListener(`message`,e=>G(String(e.data)));let c=await t.createOffer();await t.setLocalDescription(c);let u={sdp:c.sdp??``,voice:e,delegation:{model:a,effort:l,webSearch:T&&f},projectName:P};n.trim()&&(u.instructions=n.trim()),r.length&&(u.history=r),m||(u.logger=!1);let d=await B.mutateAsync({params:u});await t.setRemoteDescription({type:`answer`,sdp:d.sdp}),R.current={pc:t,channel:s,mic:i},F(d.requestLogId),D(`live`)}catch(e){i?.getTracks().forEach(e=>e.stop()),o?.close(),k(e instanceof Error?e.message:String(e)),D(`idle`)}},J=N({voice:e,instructions:n.trim()||void 0,delegation:{model:a,effort:l,webSearch:T&&f},logged:m,continues:v.length>0});return(0,b.jsx)(q,{code:J,note:`SDK 2.20.0+, experimental`,children:(0,b.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,b.jsx)(W,{label:`Voice`,children:(0,b.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),disabled:E!==`idle`,className:H,children:d.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),(0,b.jsx)(W,{label:`Instructions`,children:(0,b.jsx)(`input`,{value:n,onChange:e=>i(e.target.value),disabled:E!==`idle`,placeholder:`e.g. You are a friendly English tutor. Keep answers short.`,className:H})}),(0,b.jsx)(W,{label:`Delegation model (answers lookups and reasoning)`,children:(0,b.jsx)(`select`,{value:a,onChange:e=>s(e.target.value),disabled:E!==`idle`,className:H,children:c.map(e=>(0,b.jsx)(`optgroup`,{label:e.label,children:e.models.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))},e.label))})}),(0,b.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,b.jsx)(W,{label:`Effort`,children:(0,b.jsx)(`select`,{value:l,onChange:e=>u(h.options.find(t=>t===e.target.value)??`low`),disabled:E!==`idle`,className:H,children:h.options.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),(0,b.jsxs)(`label`,{className:`flex h-8 items-center gap-1.5 text-[12px] text-sand-600`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:T&&f,onChange:e=>p(e.target.checked),disabled:E!==`idle`||!T,className:`accent-sienna-500`}),`Web search`]}),(0,b.jsxs)(`label`,{className:`flex h-8 items-center gap-1.5 text-[12px] text-sand-600`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>_(e.target.checked),disabled:E!==`idle`,className:`accent-sienna-500`}),`Request log`]})]})]}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[E===`idle`?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`button`,{type:`button`,onClick:()=>K(!1),className:U,children:[(0,b.jsx)(C,{className:`size-3.5`}),`Start conversation`]}),A.length>0&&(0,b.jsx)(`button`,{type:`button`,onClick:()=>K(!0),className:`text-[12px] font-medium text-sienna-600 hover:text-sienna-700`,children:`Continue this conversation`})]}):(0,b.jsxs)(`button`,{type:`button`,onClick:V,disabled:E===`connecting`,className:`${U} bg-danger-500 hover:bg-danger-500`,children:[E===`connecting`?(0,b.jsx)(S,{className:`size-3.5 animate-spin`}):(0,b.jsx)(o,{className:`size-3.5`}),E===`connecting`?`Connecting`:`End`]}),E===`live`&&(0,b.jsxs)(`span`,{className:`tabular-nums text-[12px] text-sand-500`,children:[te(I),` · openai/gpt-live-1 · speak any time (ends by itself after 2 h)`]}),M!==void 0&&(0,b.jsxs)(r,{to:`/requests/show`,search:{id:M},target:`_blank`,className:`inline-flex items-center gap-1 text-[12px] tabular-nums text-sand-500 hover:text-sienna-500`,children:[`request log #`,M,(0,b.jsx)(x,{className:`size-3`})]}),O&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:O})]}),(0,b.jsx)(`audio`,{ref:z,autoPlay:!0}),v.length===0&&A.length===0?(0,b.jsx)(`p`,{className:`py-6 text-center text-[12px] text-sand-400`,children:`Start a conversation and talk; both sides of the transcript appear here.`}):(0,b.jsxs)(`ul`,{className:`flex flex-col gap-1.5`,children:[v.map((e,t)=>(0,b.jsxs)(`li`,{className:`rounded-lg bg-sand-50/60 px-3 py-2 text-[13px] text-sand-500`,children:[(0,b.jsx)(`span`,{className:`mr-2 text-[10px] font-medium uppercase tracking-wider text-sand-400`,children:e.role}),e.text]},`earlier-${t}`)),A.map(e=>(0,b.jsxs)(`li`,{className:`rounded-lg px-3 py-2 text-[13px] text-sand-800 ${e.role===`assistant`?`bg-sage-50`:`bg-sand-50`}`,children:[(0,b.jsx)(`span`,{className:`mr-2 text-[10px] font-medium uppercase tracking-wider text-sand-500`,children:e.role}),e.text.trim()]},e.id))]})]})})}function re({tab:e}){return(0,b.jsxs)(`section`,{children:[(0,b.jsx)(`div`,{role:`tablist`,className:`panel mb-4 flex gap-1 px-3 pt-2 md:hidden`,children:i.map(t=>(0,b.jsx)(r,{to:`/voice`,search:{tab:t},role:`tab`,"aria-selected":e===t,className:`-mb-px border-b-2 px-3 py-2 text-[13px] no-underline transition-colors duration-150 ${e===t?`border-sienna-500 font-medium text-sand-800`:`border-transparent text-sand-500 hover:text-sand-700`}`,children:f[t]},t))}),(0,b.jsx)(`div`,{role:`tabpanel`,hidden:e!==`tts`,children:(0,b.jsx)(X,{})}),(0,b.jsx)(`div`,{role:`tabpanel`,hidden:e!==`stt`,children:(0,b.jsx)(Z,{})}),(0,b.jsx)(`div`,{role:`tabpanel`,hidden:e!==`live`,children:(0,b.jsx)(ne,{})})]})}function ie(){let{tab:e=`tts`}=m.useSearch();return(0,b.jsx)(`div`,{className:`max-w-3xl mx-auto xl:max-w-6xl`,children:(0,b.jsx)(re,{tab:e})})}export{ie as component};
4
+ `)}var P=`qgrid_voice_playground`,F=[`grok/grok-tts`,`openai/gpt-realtime-2.1-mini`,`openai/gpt-realtime-2.1`],I=[`openai/gpt-transcribe`,`grok/grok-voice-transcribe-2.0`],L=[{label:`Female`,voices:f.female},{label:`Male`,voices:f.male}],R=[{label:``,voices:c}],z={provider:`timing from Grok TTS`,aligned:`timing from qgrid aligner`},B=e=>e.startsWith(`openai/`),V=`w-full rounded-lg border border-sand-200/80 bg-white px-2.5 py-1.5 text-[12px] text-sand-800 placeholder:text-sand-400 focus:outline-none focus:border-sienna-300 disabled:opacity-50`,H=`${V} h-8`,U=`px-3.5 py-1.5 text-[12px] font-medium rounded-lg bg-sienna-500 text-white hover:bg-sienna-600 disabled:opacity-50 transition-all duration-150 active:scale-[0.97] inline-flex items-center gap-1.5 shadow-sm`;function W({label:e,children:t}){return(0,b.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,b.jsx)(`span`,{className:`text-[11px] font-medium text-sand-500`,children:e}),t]})}var G=e=>e.slice(e.indexOf(`/`)+1);function K({title:e,meta:t,requestLogId:n,onRemove:i,children:a}){return(0,b.jsxs)(`li`,{className:`flex flex-col gap-1.5 px-4 py-3`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-[12px]`,children:[(0,b.jsx)(`span`,{className:`font-medium text-sand-800`,children:e}),(0,b.jsx)(`span`,{className:`tabular-nums text-sand-400`,children:t}),(0,b.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[n!==void 0&&(0,b.jsxs)(r,{to:`/requests/show`,search:{id:n},target:`_blank`,className:`inline-flex items-center gap-1 tabular-nums text-sand-500 hover:text-sienna-500`,children:[`request log #`,n,(0,b.jsx)(x,{className:`size-3`})]}),(0,b.jsx)(`button`,{type:`button`,onClick:i,title:`Remove from history`,className:`text-sand-300 hover:text-sand-600`,children:(0,b.jsx)(s,{className:`size-3.5`})})]})]}),a]})}function q({code:e,note:t,children:n}){return(0,b.jsxs)(`div`,{className:`flex flex-col xl:flex-row gap-4 items-stretch xl:items-start`,children:[(0,b.jsx)(`div`,{className:`panel overflow-hidden flex-1 min-w-0`,children:n}),(0,b.jsx)(`div`,{className:`min-w-0 xl:w-[32rem] xl:shrink-0 xl:sticky xl:top-4`,children:(0,b.jsx)(_,{title:`AI SDK`,code:e,scroll:!1,actions:t&&(0,b.jsx)(`span`,{className:`text-[11px] text-sand-400`,children:t})})})]})}function J({empty:e,children:t}){return t.length===0?(0,b.jsx)(`p`,{className:`px-4 py-6 text-center text-[12px] text-sand-400`,children:e}):(0,b.jsx)(`ul`,{className:`divide-y divide-sand-100`,children:t})}function Y(e){if(!e)return;let t=[],n;return e.graphChars.forEach((r,i)=>{let[a,o]=e.graphTimes[i];/\s/.test(r)?n=void 0:n?(n.text+=r,n.end=o):(n={text:r,start:a,end:o},t.push(n))}),t}function X(){let[e,t]=(0,y.useState)(F[0]),[n,r]=(0,y.useState)(f.female[0]),[i,a]=(0,y.useState)(``),[s,l]=(0,y.useState)(`Hi! What did you do this weekend?`),[d,p]=(0,y.useState)([]),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(1),x=(0,y.useRef)(0),C=u.useSpeakMutation(),T=B(e),E=e=>{B(e)!==T&&r(B(e)?c[0]:f.female[0]),t(e)},D=T&&i.trim()?i.trim():void 0,O=t=>{let n=performance.now(),r={model:e,text:s,voice:t,projectName:P};D&&(r.instructions=D),m&&(r.withTimestamps=!0),!T&&g!==1&&(r.speed=g),C.mutate({params:r},{onSuccess:i=>{let a={key:x.current++,src:`data:${i.mimeType};base64,${i.audio}`,model:e,voice:t,instructions:r.instructions,speed:r.speed,text:s,elapsedMs:performance.now()-n,requestLogId:i.requestLogId,words:Y(i.audioTimestamps),timing:i.timestampsError?`timing failed: ${i.timestampsError}`:i.timestampsSource&&z[i.timestampsSource]};p(e=>[a,...e])}})},k=(0,y.useRef)(null),[A,M]=(0,y.useState)();(0,y.useEffect)(()=>()=>k.current?.pause(),[]);let N=e=>{if(r(e),k.current?.pause(),A===e){M(void 0);return}let t=new Audio(`/voice-samples/${T?`openai`:`grok`}/${e}.mp3`);t.addEventListener(`ended`,()=>M(t=>t===e?void 0:t),{once:!0}),k.current=t,M(e),t.play()},I=j({model:e,text:s,voice:n,instructions:D,speed:!T&&g!==1?g:void 0,withTimestamps:m});return(0,b.jsxs)(q,{code:I,children:[(0,b.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,b.jsx)(W,{label:`Model`,children:(0,b.jsx)(`select`,{value:e,onChange:e=>E(e.target.value),className:H,children:F.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),T?(0,b.jsx)(W,{label:`Style instructions (OpenAI only)`,children:(0,b.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`e.g. Speak with a gentle Irish accent.`,className:H})}):(0,b.jsx)(W,{label:`Speed (Grok only) — ${g.toFixed(2)}×`,children:(0,b.jsx)(`input`,{type:`range`,min:.7,max:1.5,step:.05,value:g,onChange:e=>_(Number(e.target.value)),className:`h-8 accent-sienna-500`})})]}),(0,b.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,b.jsx)(`span`,{className:`text-[11px] font-medium text-sand-500`,children:`Voice — ▶ plays a short self-introduction sample, a name selects it`}),(T?R:L).map(e=>(0,b.jsxs)(`div`,{className:`flex items-start gap-2`,children:[e.label&&(0,b.jsx)(`span`,{className:`w-12 shrink-0 pt-1 text-[11px] text-sand-400`,children:e.label}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.voices.map(e=>(0,b.jsxs)(`span`,{className:`inline-flex items-center overflow-hidden rounded-full border text-[12px] ${n===e?`border-sienna-400 bg-sienna-50 text-sienna-700`:`border-sand-200/80 bg-white text-sand-700`}`,children:[(0,b.jsx)(`button`,{type:`button`,onClick:()=>r(e),"aria-pressed":n===e,className:`py-0.5 pl-2.5 pr-1 hover:text-sienna-600`,children:e}),(0,b.jsx)(`button`,{type:`button`,onClick:()=>N(e),title:A===e?`Stop "${e}"`:`Play a "${e}" sample`,className:`py-1 pl-1 pr-2 hover:text-sienna-500 ${A===e?`text-sienna-500`:`text-sand-400`}`,children:A===e?(0,b.jsx)(o,{className:`size-3`}):(0,b.jsx)(w,{className:`size-3`})})]},e))})]},e.label))]}),(0,b.jsx)(W,{label:`Text`,children:(0,b.jsx)(`textarea`,{value:s,onChange:e=>l(e.target.value),rows:3,className:`${V} resize-y`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(`button`,{type:`button`,onClick:()=>O(n),disabled:C.isPending||!s.trim(),className:U,children:[C.isPending&&(0,b.jsx)(S,{className:`size-3.5 animate-spin`}),`Generate with `,n]}),(0,b.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px] text-sand-600`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`accent-sienna-500`}),`Word timing`]}),C.isError&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:C.error?.message})]})]}),(0,b.jsx)(`div`,{className:`border-t border-sand-100`,children:(0,b.jsx)(J,{empty:`Generated clips stack here, newest first, so voices can be compared side by side.`,children:d.map(e=>(0,b.jsxs)(K,{title:[e.voice,G(e.model),e.speed&&`${e.speed}×`].filter(Boolean).join(` · `),meta:[`${(e.elapsedMs/1e3).toFixed(1)}s`,e.timing].filter(Boolean).join(` · `),requestLogId:e.requestLogId,onRemove:()=>p(t=>t.filter(t=>t.key!==e.key)),children:[(!e.words||e.instructions)&&(0,b.jsxs)(`p`,{className:`truncate text-[12px] text-sand-600`,title:e.text,children:[!e.words&&e.text,e.instructions&&(0,b.jsxs)(`span`,{className:`text-sand-400`,children:[` — `,e.instructions]})]}),(0,b.jsx)(v,{src:e.src,words:e.words,autoPlay:!0})]},e.key))})})]})}function Z(){let[e,t]=(0,y.useState)(I[0]),[n,r]=(0,y.useState)(``),[i,a]=(0,y.useState)(),[s,c]=(0,y.useState)(!1),[l,d]=(0,y.useState)(),[f,p]=(0,y.useState)([]),m=(0,y.useRef)(null),h=(0,y.useRef)([]),g=(0,y.useRef)(0),_=u.useTranscribeMutation(),x=B(e);(0,y.useEffect)(()=>()=>{m.current?.stream.getTracks().forEach(e=>e.stop()),h.current.forEach(e=>URL.revokeObjectURL(e))},[]);let w=e=>{let t=URL.createObjectURL(e);h.current.push(t),a({blob:e,url:t,clip:h.current.length})},T=async()=>{if(s)m.current?.stop(),c(!1);else{d(void 0);try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e),n=[];t.ondataavailable=e=>n.push(e.data),t.onstop=()=>{e.getTracks().forEach(e=>e.stop()),w(new Blob(n,{type:t.mimeType}))},t.start(),m.current=t,c(!0)}catch(e){d(e instanceof Error?e.message:String(e))}}},E=async()=>{if(!i)return;d(void 0);let t=i.blob.type.split(`;`)[0],r;try{r=!x&&t.startsWith(`audio/`)?{audio:D(new Uint8Array(await i.blob.arrayBuffer())),mediaType:t}:{audio:await O(i.blob),mediaType:`audio/wav`}}catch(e){d(`could not decode audio: ${e instanceof Error?e.message:String(e)}`);return}let a={model:e,...r,projectName:P};x&&n.trim()&&(a.prompt=n.trim());let o=performance.now();_.mutate({params:a},{onSuccess:t=>{let n={key:g.current++,clip:i.clip,clipUrl:i.url,model:e,prompt:a.prompt,text:t.text,elapsedMs:performance.now()-o,durationSec:t.durationSec,requestLogId:t.requestLogId,words:t.words};p(e=>[n,...e])}})},k=M({model:e,prompt:x&&n.trim()?n.trim():void 0});return(0,b.jsxs)(q,{code:k,children:[(0,b.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,b.jsx)(W,{label:`Model`,children:(0,b.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:H,children:I.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),x&&(0,b.jsx)(W,{label:`Prompt (OpenAI only)`,children:(0,b.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`domain words, e.g. qgrid, Kuma`,className:H})})]}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,b.jsxs)(`button`,{type:`button`,onClick:T,className:`${U} ${s?`bg-danger-500 hover:bg-danger-500`:``}`,children:[s?(0,b.jsx)(o,{className:`size-3.5`}):(0,b.jsx)(C,{className:`size-3.5`}),s?`Stop`:`Record`]}),(0,b.jsxs)(`label`,{className:`text-[12px] text-sand-600 cursor-pointer hover:text-sienna-500`,children:[`or upload a file`,(0,b.jsx)(`input`,{type:`file`,accept:`audio/*`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&w(t)}})]}),l&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:l})]}),i&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(`span`,{className:`shrink-0 text-[11px] font-medium text-sand-500`,children:[`clip `,i.clip]}),(0,b.jsx)(`audio`,{controls:!0,src:i.url,className:`h-8 w-full`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(`button`,{type:`button`,onClick:E,disabled:!i||s||_.isPending,className:U,children:[_.isPending&&(0,b.jsx)(S,{className:`size-3.5 animate-spin`}),`Transcribe`]}),_.isError&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:_.error?.message})]})]}),(0,b.jsx)(`div`,{className:`border-t border-sand-100`,children:(0,b.jsx)(J,{empty:`Transcripts stack here, newest first; run one clip through several models to compare.`,children:f.map(e=>(0,b.jsx)(K,{title:`clip ${e.clip} · ${G(e.model)}`,meta:[`${(e.elapsedMs/1e3).toFixed(1)}s`,e.durationSec===void 0?``:`${e.durationSec.toFixed(1)}s audio`,e.prompt?`prompt: ${e.prompt}`:``].filter(Boolean).join(` · `),requestLogId:e.requestLogId,onRemove:()=>p(t=>t.filter(t=>t.key!==e.key)),children:e.words&&e.words.length>0?(0,b.jsx)(v,{src:e.clipUrl,words:e.words}):(0,b.jsx)(`p`,{className:`rounded-lg bg-sand-50 px-3 py-2 text-[13px] text-sand-800 whitespace-pre-wrap`,children:e.text||`(empty transcript)`})},e.key))})})]})}var Q=`openai/gpt-6-luna`,ee=l({type:a(),turn:l({id:a(),role:a(),transcript:a()}).optional(),turn_id:a().optional(),delta:a().optional()}),te=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`;function $({pc:e,channel:t,mic:n}){t.readyState===`open`&&t.send(JSON.stringify({type:`session.close`})),n.getTracks().forEach(e=>e.stop()),setTimeout(()=>e.close(),500)}function ne(){let[e,t]=(0,y.useState)(d[0]),[n,i]=(0,y.useState)(``),[a,s]=(0,y.useState)(Q),[c,l]=(0,y.useState)(`low`),[f,p]=(0,y.useState)(!1),[h,_]=(0,y.useState)(!0),[v,w]=(0,y.useState)([]),T=!a.startsWith(`anthropic/`),[E,D]=(0,y.useState)(`idle`),[O,k]=(0,y.useState)(),[A,j]=(0,y.useState)([]),[M,F]=(0,y.useState)(),[I,L]=(0,y.useState)(0),R=(0,y.useRef)(null),z=(0,y.useRef)(null),B=u.useLiveCallMutation();(0,y.useEffect)(()=>()=>{R.current&&$(R.current)},[]),(0,y.useEffect)(()=>{if(E!==`live`)return;let e=Date.now(),t=setInterval(()=>L(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[E]);let V=()=>{R.current&&$(R.current),R.current=null,D(`idle`)},G=e=>{let t;try{t=ee.safeParse(JSON.parse(e)).data}catch{return}if(!t)return;let{type:n,turn:r,turn_id:i,delta:a}=t;if(n===`session.closed`)V();else if(r&&(n===`turn.created`||n===`turn.done`)){let e={id:r.id,role:r.role,text:r.transcript};j(t=>t.some(e=>e.id===r.id)?t.map(t=>t.id===r.id?e:t):[...t,e])}else n===`turn.delta`&&i&&a&&j(e=>e.map(e=>e.id===i?{...e,text:e.text+a}:e))},K=async t=>{let r=t?[...v,...A.flatMap(e=>e.text.trim()?[{role:e.role===`assistant`?`assistant`:`user`,text:e.text.trim()}]:[])].slice(-128):[];w(r),k(void 0),j([]),F(void 0),L(0),D(`connecting`);let i,o;try{i=await navigator.mediaDevices.getUserMedia({audio:!0});let t=new RTCPeerConnection;o=t,i.getTracks().forEach(e=>t.addTrack(e)),t.addEventListener(`track`,e=>{z.current&&(z.current.srcObject=new MediaStream([e.track]))});let s=t.createDataChannel(`oai-events`);s.addEventListener(`message`,e=>G(String(e.data)));let l=await t.createOffer();await t.setLocalDescription(l);let u={sdp:l.sdp??``,voice:e,delegation:{model:a,effort:c,webSearch:T&&f},projectName:P};n.trim()&&(u.instructions=n.trim()),r.length&&(u.history=r),h||(u.logger=!1);let d=await B.mutateAsync({params:u});await t.setRemoteDescription({type:`answer`,sdp:d.sdp}),R.current={pc:t,channel:s,mic:i},F(d.requestLogId),D(`live`)}catch(e){i?.getTracks().forEach(e=>e.stop()),o?.close(),k(e instanceof Error?e.message:String(e)),D(`idle`)}},J=N({voice:e,instructions:n.trim()||void 0,delegation:{model:a,effort:c,webSearch:T&&f},logged:h,continues:v.length>0});return(0,b.jsx)(q,{code:J,note:`SDK 2.20.0+, experimental`,children:(0,b.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,b.jsx)(W,{label:`Voice`,children:(0,b.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),disabled:E!==`idle`,className:H,children:d.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),(0,b.jsx)(W,{label:`Instructions`,children:(0,b.jsx)(`input`,{value:n,onChange:e=>i(e.target.value),disabled:E!==`idle`,placeholder:`e.g. You are a friendly English tutor. Keep answers short.`,className:H})}),(0,b.jsx)(W,{label:`Delegation model (answers lookups and reasoning)`,children:(0,b.jsx)(`select`,{value:a,onChange:e=>s(e.target.value),disabled:E!==`idle`,className:H,children:(0,b.jsx)(g,{selected:a})})}),(0,b.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,b.jsx)(W,{label:`Effort`,children:(0,b.jsx)(`select`,{value:c,onChange:e=>l(m.options.find(t=>t===e.target.value)??`low`),disabled:E!==`idle`,className:H,children:m.options.map(e=>(0,b.jsx)(`option`,{value:e,children:e},e))})}),(0,b.jsxs)(`label`,{className:`flex h-8 items-center gap-1.5 text-[12px] text-sand-600`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:T&&f,onChange:e=>p(e.target.checked),disabled:E!==`idle`||!T,className:`accent-sienna-500`}),`Web search`]}),(0,b.jsxs)(`label`,{className:`flex h-8 items-center gap-1.5 text-[12px] text-sand-600`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>_(e.target.checked),disabled:E!==`idle`,className:`accent-sienna-500`}),`Request log`]})]})]}),(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[E===`idle`?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`button`,{type:`button`,onClick:()=>K(!1),className:U,children:[(0,b.jsx)(C,{className:`size-3.5`}),`Start conversation`]}),A.length>0&&(0,b.jsx)(`button`,{type:`button`,onClick:()=>K(!0),className:`text-[12px] font-medium text-sienna-600 hover:text-sienna-700`,children:`Continue this conversation`})]}):(0,b.jsxs)(`button`,{type:`button`,onClick:V,disabled:E===`connecting`,className:`${U} bg-danger-500 hover:bg-danger-500`,children:[E===`connecting`?(0,b.jsx)(S,{className:`size-3.5 animate-spin`}):(0,b.jsx)(o,{className:`size-3.5`}),E===`connecting`?`Connecting`:`End`]}),E===`live`&&(0,b.jsxs)(`span`,{className:`tabular-nums text-[12px] text-sand-500`,children:[te(I),` · openai/gpt-live-1 · speak any time (ends by itself after 2 h)`]}),M!==void 0&&(0,b.jsxs)(r,{to:`/requests/show`,search:{id:M},target:`_blank`,className:`inline-flex items-center gap-1 text-[12px] tabular-nums text-sand-500 hover:text-sienna-500`,children:[`request log #`,M,(0,b.jsx)(x,{className:`size-3`})]}),O&&(0,b.jsx)(`p`,{className:`text-[12px] text-danger-500 break-words`,children:O})]}),(0,b.jsx)(`audio`,{ref:z,autoPlay:!0}),v.length===0&&A.length===0?(0,b.jsx)(`p`,{className:`py-6 text-center text-[12px] text-sand-400`,children:`Start a conversation and talk; both sides of the transcript appear here.`}):(0,b.jsxs)(`ul`,{className:`flex flex-col gap-1.5`,children:[v.map((e,t)=>(0,b.jsxs)(`li`,{className:`rounded-lg bg-sand-50/60 px-3 py-2 text-[13px] text-sand-500`,children:[(0,b.jsx)(`span`,{className:`mr-2 text-[10px] font-medium uppercase tracking-wider text-sand-400`,children:e.role}),e.text]},`earlier-${t}`)),A.map(e=>(0,b.jsxs)(`li`,{className:`rounded-lg px-3 py-2 text-[13px] text-sand-800 ${e.role===`assistant`?`bg-sage-50`:`bg-sand-50`}`,children:[(0,b.jsx)(`span`,{className:`mr-2 text-[10px] font-medium uppercase tracking-wider text-sand-500`,children:e.role}),e.text.trim()]},e.id))]})]})})}function re({tab:e}){return(0,b.jsxs)(`section`,{children:[(0,b.jsx)(`div`,{role:`tablist`,className:`panel mb-4 flex gap-1 px-3 pt-2 md:hidden`,children:i.map(t=>(0,b.jsx)(r,{to:`/voice`,search:{tab:t},role:`tab`,"aria-selected":e===t,className:`-mb-px border-b-2 px-3 py-2 text-[13px] no-underline transition-colors duration-150 ${e===t?`border-sienna-500 font-medium text-sand-800`:`border-transparent text-sand-500 hover:text-sand-700`}`,children:p[t]},t))}),(0,b.jsx)(`div`,{role:`tabpanel`,hidden:e!==`tts`,children:(0,b.jsx)(X,{})}),(0,b.jsx)(`div`,{role:`tabpanel`,hidden:e!==`stt`,children:(0,b.jsx)(Z,{})}),(0,b.jsx)(`div`,{role:`tabpanel`,hidden:e!==`live`,children:(0,b.jsx)(ne,{})})]})}function ie(){let{tab:e=`tts`}=h.useSearch();return(0,b.jsx)(`div`,{className:`max-w-3xl mx-auto xl:max-w-6xl`,children:(0,b.jsx)(re,{tab:e})})}export{ie as component};
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/sonamu.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Qgrid</title>
8
- <script type="module" crossorigin src="/assets/index-CiSsWsVT.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-CtkfXtee.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-8xo7RSum.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/vendor-tanstack-DMgmqjm4.js">
@@ -1,4 +1,4 @@
1
- import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-rlOX8J2n.js";
2
2
  //#region ~icons/lucide/check.jsx
3
3
  var import_react = /* @__PURE__ */ __toESM(require_react());
4
4
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,8 +1,8 @@
1
- import { Q as require_react, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService, r as RequestLogService } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService, r as RequestLogService } from "./services.generated-rlOX8J2n.js";
2
2
  import { a as RequestLogOrderBy, b as Link, i as Route, x as useNavigate } from "../entry-server.generated.js";
3
3
  import { i as formatUsd, r as formatRequestCost, t as cacheHitRate } from "./cost-oNK0T4Jo.js";
4
- import { t as ForwardRef$2 } from "./refresh-cw-Bj-Jxeb6.js";
5
- import { n as ForwardRef$3, t as requestModelDisplay } from "./request-model-D_iYrudl.js";
4
+ import { t as ForwardRef$2 } from "./refresh-cw-wU5-wVTi.js";
5
+ import { n as ForwardRef$3, t as requestModelDisplay } from "./request-model-D07WSRKx.js";
6
6
  //#region ~icons/lucide/chevron-left.jsx
7
7
  var import_react = /* @__PURE__ */ __toESM(require_react());
8
8
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,8 +1,8 @@
1
- import { N as useQuery, Q as require_react, Z as require_jsx_runtime, nt as __toESM, t as MonitService } from "./services.generated-D0995hJr.js";
1
+ import { N as useQuery, Q as require_react, Z as require_jsx_runtime, nt as __toESM, t as MonitService } from "./services.generated-rlOX8J2n.js";
2
2
  import { t as clsx } from "./clsx-DgIEfj3H.js";
3
3
  import { r as Route } from "../entry-server.generated.js";
4
4
  import { t as cacheHitRate } from "./cost-oNK0T4Jo.js";
5
- import { t as ForwardRef } from "./refresh-cw-Bj-Jxeb6.js";
5
+ import { t as ForwardRef } from "./refresh-cw-wU5-wVTi.js";
6
6
  //#region src/components/qgrid/MonitConsole.tsx
7
7
  var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
8
8
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,4 +1,4 @@
1
- import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-rlOX8J2n.js";
2
2
  //#region ~icons/lucide/plus.jsx
3
3
  var import_react = /* @__PURE__ */ __toESM(require_react());
4
4
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,4 +1,4 @@
1
- import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-rlOX8J2n.js";
2
2
  //#region ~icons/lucide/refresh-cw.jsx
3
3
  var import_react = /* @__PURE__ */ __toESM(require_react());
4
4
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,4 +1,4 @@
1
- import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, Z as require_jsx_runtime, nt as __toESM } from "./services.generated-rlOX8J2n.js";
2
2
  //#region ~icons/lucide/zap.jsx
3
3
  var import_react = /* @__PURE__ */ __toESM(require_react());
4
4
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,8 +1,8 @@
1
- import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService } from "./services.generated-D0995hJr.js";
2
- import { i as o, n as useOAuthLoginFlow, r as OAuthCodeEntry, t as isOAuthProvider } from "./use-oauth-login-flow-C7c0gCjf.js";
1
+ import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService } from "./services.generated-rlOX8J2n.js";
2
+ import { i as o, n as useOAuthLoginFlow, r as OAuthCodeEntry, t as isOAuthProvider } from "./use-oauth-login-flow-DLRPNhNE.js";
3
3
  import { y as require_react_dom } from "../entry-server.generated.js";
4
4
  import { i as formatUsd } from "./cost-oNK0T4Jo.js";
5
- import { t as useUpdateTokenMutation } from "./use-update-token-mutation-DLJDGdxu.js";
5
+ import { t as useUpdateTokenMutation } from "./use-update-token-mutation-DJkct-j8.js";
6
6
  //#region ../../node_modules/.pnpm/@dnd-kit+utilities@3.2.2_react@19.3.1/node_modules/@dnd-kit/utilities/dist/utilities.esm.js
7
7
  var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom());
8
8
  var import_react = /* @__PURE__ */ __toESM(require_react());
@@ -29452,6 +29452,188 @@ function useSSEStream(url, params, handlers, options = {}) {
29452
29452
  ]);
29453
29453
  return state;
29454
29454
  }
29455
+ function useWebSocketChannel(url, params, handlers, options = {}) {
29456
+ const { enabled = true, retry = 3, retryInterval = 3e3, protocols } = options;
29457
+ const [state, setState] = (0, import_react.useState)({
29458
+ isConnected: false,
29459
+ error: null,
29460
+ retryCount: 0,
29461
+ readyState: 3
29462
+ });
29463
+ const socketRef = (0, import_react.useRef)(null);
29464
+ const retryTimeoutRef = (0, import_react.useRef)(null);
29465
+ const handlersRef = (0, import_react.useRef)(handlers);
29466
+ const manualCloseRef = (0, import_react.useRef)(false);
29467
+ const connectionIdRef = (0, import_react.useRef)(0);
29468
+ (0, import_react.useEffect)(() => {
29469
+ handlersRef.current = handlers;
29470
+ }, [handlers]);
29471
+ const close = (code, reason) => {
29472
+ manualCloseRef.current = true;
29473
+ if (retryTimeoutRef.current) {
29474
+ clearTimeout(retryTimeoutRef.current);
29475
+ retryTimeoutRef.current = null;
29476
+ }
29477
+ if (socketRef.current) socketRef.current.close(code, reason);
29478
+ };
29479
+ const send = (event, data) => {
29480
+ const socket = socketRef.current;
29481
+ if (!socket || socket.readyState !== WebSocket.OPEN) {
29482
+ setState((prev) => ({
29483
+ ...prev,
29484
+ error: "WebSocket is not connected"
29485
+ }));
29486
+ return;
29487
+ }
29488
+ socket.send(JSON.stringify({
29489
+ event,
29490
+ data
29491
+ }));
29492
+ };
29493
+ const connect = () => {
29494
+ if (!enabled) return;
29495
+ const connectionId = ++connectionIdRef.current;
29496
+ manualCloseRef.current = false;
29497
+ if (socketRef.current) {
29498
+ socketRef.current.close();
29499
+ socketRef.current = null;
29500
+ }
29501
+ if (retryTimeoutRef.current) {
29502
+ clearTimeout(retryTimeoutRef.current);
29503
+ retryTimeoutRef.current = null;
29504
+ }
29505
+ const fullUrl = resolveWebSocketUrl(url, params);
29506
+ const socket = new WebSocket(fullUrl, protocols);
29507
+ socketRef.current = socket;
29508
+ setState((prev) => ({
29509
+ ...prev,
29510
+ isConnected: false,
29511
+ error: null,
29512
+ readyState: socket.readyState
29513
+ }));
29514
+ socket.addEventListener("open", () => {
29515
+ if (socketRef.current !== socket) return;
29516
+ setState((prev) => ({
29517
+ ...prev,
29518
+ isConnected: true,
29519
+ error: null,
29520
+ retryCount: 0,
29521
+ readyState: socket.readyState
29522
+ }));
29523
+ });
29524
+ socket.addEventListener("message", (event) => {
29525
+ if (socketRef.current !== socket) return;
29526
+ try {
29527
+ const payload = JSON.parse(event.data, dateReviver);
29528
+ const handler = handlersRef.current[payload.event];
29529
+ if (handler) handler(payload.data);
29530
+ } catch (error) {
29531
+ console.error("Failed to parse WebSocket message:", error);
29532
+ }
29533
+ });
29534
+ socket.addEventListener("error", () => {
29535
+ if (socketRef.current !== socket) return;
29536
+ setState((prev) => ({
29537
+ ...prev,
29538
+ isConnected: false,
29539
+ error: "WebSocket connection failed",
29540
+ readyState: socket.readyState
29541
+ }));
29542
+ });
29543
+ socket.addEventListener("close", (event) => {
29544
+ if (socketRef.current !== socket) return;
29545
+ socketRef.current = null;
29546
+ setState((prev) => ({
29547
+ ...prev,
29548
+ isConnected: false,
29549
+ readyState: socket.readyState
29550
+ }));
29551
+ if (manualCloseRef.current || connectionIdRef.current !== connectionId) return;
29552
+ if (!isRetryableWebSocketCloseCode(event.code)) {
29553
+ setState((prev) => ({
29554
+ ...prev,
29555
+ error: event.code === 1008 || event.code === 1009 ? `WebSocket rejected by server (code: ${event.code})` : `WebSocket closed (code: ${event.code})`
29556
+ }));
29557
+ return;
29558
+ }
29559
+ setState((prev) => {
29560
+ if (prev.retryCount >= retry) return {
29561
+ ...prev,
29562
+ error: `Connection failed after ${retry} attempts`
29563
+ };
29564
+ retryTimeoutRef.current = setTimeout(() => {
29565
+ if (connectionIdRef.current !== connectionId) return;
29566
+ setState((inner) => ({
29567
+ ...inner,
29568
+ retryCount: inner.retryCount + 1
29569
+ }));
29570
+ connect();
29571
+ }, retryInterval);
29572
+ return prev;
29573
+ });
29574
+ });
29575
+ };
29576
+ (0, import_react.useEffect)(() => {
29577
+ if (enabled) {
29578
+ setState({
29579
+ isConnected: false,
29580
+ error: null,
29581
+ retryCount: 0,
29582
+ readyState: 3
29583
+ });
29584
+ connect();
29585
+ }
29586
+ return () => {
29587
+ connectionIdRef.current += 1;
29588
+ manualCloseRef.current = true;
29589
+ if (socketRef.current) {
29590
+ socketRef.current.close();
29591
+ socketRef.current = null;
29592
+ }
29593
+ if (retryTimeoutRef.current) {
29594
+ clearTimeout(retryTimeoutRef.current);
29595
+ retryTimeoutRef.current = null;
29596
+ }
29597
+ };
29598
+ }, [
29599
+ url,
29600
+ JSON.stringify(params),
29601
+ enabled,
29602
+ JSON.stringify(protocols)
29603
+ ]);
29604
+ return {
29605
+ ...state,
29606
+ send,
29607
+ close
29608
+ };
29609
+ }
29610
+ function isRetryableWebSocketCloseCode(code) {
29611
+ if (code === 1e3) return false;
29612
+ return ![
29613
+ 1002,
29614
+ 1003,
29615
+ 1007,
29616
+ 1008,
29617
+ 1009
29618
+ ].includes(code);
29619
+ }
29620
+ function resolveWebSocketUrl(url, params) {
29621
+ const queryString = import_lib.default.stringify(params);
29622
+ const withQuery = queryString ? `${url}?${queryString}` : url;
29623
+ if (withQuery.startsWith("ws://") || withQuery.startsWith("wss://")) return withQuery;
29624
+ const baseUrl = resolveWebSocketBaseUrl();
29625
+ return new URL(withQuery, baseUrl).toString();
29626
+ }
29627
+ function resolveWebSocketBaseUrl() {
29628
+ const configuredBaseUrl = axios.defaults.baseURL;
29629
+ if (configuredBaseUrl) return toWebSocketBaseUrl(typeof window !== "undefined" ? new URL(configuredBaseUrl, window.location.origin).toString() : configuredBaseUrl);
29630
+ if (typeof window !== "undefined") return toWebSocketBaseUrl(window.location.origin);
29631
+ return toWebSocketBaseUrl("http://localhost:44900");
29632
+ }
29633
+ function toWebSocketBaseUrl(baseUrl) {
29634
+ if (baseUrl.startsWith("ws://") || baseUrl.startsWith("wss://")) return baseUrl;
29635
+ return baseUrl.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
29636
+ }
29455
29637
  function plural(n, forms) {
29456
29638
  const form = n === 0 && forms.zero || n === 1 && forms.one || forms.other;
29457
29639
  return typeof form === "function" ? form(n) : form ?? n.toString();
@@ -30208,6 +30390,10 @@ var QgridService;
30208
30390
  }
30209
30391
  _QgridService.liveCall = liveCall;
30210
30392
  _QgridService.useLiveCallMutation = () => useMutation({ mutationFn: (params) => QgridService.liveCall(params.params) });
30393
+ function useTranscribeStream(params, handlers, options = {}) {
30394
+ return useWebSocketChannel(`/api/qgrid/transcribeStream`, params, handlers, options);
30395
+ }
30396
+ _QgridService.useTranscribeStream = useTranscribeStream;
30211
30397
  async function usage(tokenId) {
30212
30398
  return fetch$1({
30213
30399
  method: "GET",
@@ -30242,6 +30428,21 @@ var QgridService;
30242
30428
  ...healthQueryOptions(),
30243
30429
  ...options
30244
30430
  }));
30431
+ async function models() {
30432
+ return fetch$1({
30433
+ method: "GET",
30434
+ url: `/api/qgrid/models`
30435
+ });
30436
+ }
30437
+ _QgridService.models = models;
30438
+ const modelsQueryOptions = _QgridService.modelsQueryOptions = () => queryOptions({
30439
+ queryKey: ["Qgrid", "models"],
30440
+ queryFn: () => models()
30441
+ });
30442
+ _QgridService.useModels = (options) => useRefreshable(useQuery({
30443
+ ...modelsQueryOptions(),
30444
+ ...options
30445
+ }));
30245
30446
  })(QgridService || (QgridService = {}));
30246
30447
  var MonitService;
30247
30448
  (function(_MonitService) {
@@ -1,7 +1,7 @@
1
- import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, a as SettingService, nt as __toESM, o as TokenService } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, a as SettingService, nt as __toESM, o as TokenService } from "./services.generated-rlOX8J2n.js";
2
2
  import { p as ForwardRef$3 } from "../entry-server.generated.js";
3
- import { t as useUpdateTokenMutation } from "./use-update-token-mutation-DLJDGdxu.js";
4
- import { t as ForwardRef$4 } from "./plus-DwQFfeid.js";
3
+ import { t as useUpdateTokenMutation } from "./use-update-token-mutation-DJkct-j8.js";
4
+ import { t as ForwardRef$4 } from "./plus-BrRDgdaN.js";
5
5
  //#region ~icons/lucide/eye.jsx
6
6
  var import_react = /* @__PURE__ */ __toESM(require_react());
7
7
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,8 +1,8 @@
1
- import { $ as __commonJSMin, A as union, C as looseObject, E as object, N as useQuery, O as string, Q as require_react, T as number, Z as require_jsx_runtime, h as array, i as RequestLogStepService, l as isSonamuError, nt as __toESM, r as RequestLogService, x as json } from "./services.generated-D0995hJr.js";
1
+ import { $ as __commonJSMin, A as union, C as looseObject, E as object, N as useQuery, O as string, Q as require_react, T as number, Z as require_jsx_runtime, h as array, i as RequestLogStepService, l as isSonamuError, nt as __toESM, r as RequestLogService, x as json } from "./services.generated-rlOX8J2n.js";
2
2
  import { b as Link, d as ForwardRef$2, h as Markdown, m as remarkGfm, t as Route } from "../entry-server.generated.js";
3
3
  import { n as formatMicroUsd, t as cacheHitRate } from "./cost-oNK0T4Jo.js";
4
- import { n as ForwardRef$3, t as requestModelDisplay } from "./request-model-D_iYrudl.js";
5
- import { i as highlightCode, n as CodePanel, r as CopyButton, t as TimedPlayer } from "./TimedPlayer-mpJpP5tQ.js";
4
+ import { n as ForwardRef$3, t as requestModelDisplay } from "./request-model-D07WSRKx.js";
5
+ import { i as highlightCode, n as CodePanel, r as CopyButton, t as TimedPlayer } from "./TimedPlayer-B9ds1sqM.js";
6
6
  //#region ../../node_modules/.pnpm/@babel+runtime@7.29.2/node_modules/@babel/runtime/helpers/extends.js
7
7
  var require_extends = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8
8
  function _extends() {
@@ -1,8 +1,8 @@
1
- import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService } from "./services.generated-D0995hJr.js";
2
- import { i as o, n as useOAuthLoginFlow, r as OAuthCodeEntry } from "./use-oauth-login-flow-C7c0gCjf.js";
1
+ import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService } from "./services.generated-rlOX8J2n.js";
2
+ import { i as o, n as useOAuthLoginFlow, r as OAuthCodeEntry } from "./use-oauth-login-flow-DLRPNhNE.js";
3
3
  import { v as ForwardRef$2 } from "../entry-server.generated.js";
4
- import { t as useUpdateTokenMutation } from "./use-update-token-mutation-DLJDGdxu.js";
5
- import { t as ForwardRef$3 } from "./plus-DwQFfeid.js";
4
+ import { t as useUpdateTokenMutation } from "./use-update-token-mutation-DJkct-j8.js";
5
+ import { t as ForwardRef$3 } from "./plus-BrRDgdaN.js";
6
6
  //#region src/components/qgrid/DeviceCodeEntry.tsx
7
7
  var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
8
8
  var import_jsx_runtime = require_jsx_runtime();
@@ -1,4 +1,4 @@
1
- import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService } from "./services.generated-D0995hJr.js";
1
+ import { Q as require_react, X as useQueryClient, Z as require_jsx_runtime, n as QgridService, nt as __toESM, o as TokenService } from "./services.generated-rlOX8J2n.js";
2
2
  import { t as clsx } from "./clsx-DgIEfj3H.js";
3
3
  //#region ../../node_modules/.pnpm/tailwind-merge@3.7.0/node_modules/tailwind-merge/dist/bundle-mjs.mjs
4
4
  var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
@@ -1,4 +1,4 @@
1
- import { M as useMutation, n as QgridService } from "./services.generated-D0995hJr.js";
1
+ import { M as useMutation, n as QgridService } from "./services.generated-rlOX8J2n.js";
2
2
  //#region src/services/token/use-update-token-mutation.ts
3
3
  function useUpdateTokenMutation() {
4
4
  return useMutation({ mutationFn: ({ id, name, quotaThreshold, weight, keepaliveEnabled }) => QgridService.updateToken(id, name, quotaThreshold, weight, keepaliveEnabled) });
@@ -1,6 +1,6 @@
1
- import { C as looseObject, O as string, Q as require_react, Z as require_jsx_runtime, n as QgridService, nt as __toESM } from "./services.generated-D0995hJr.js";
2
- import { _ as VOICE_TAB_TITLES, b as Link, c as OPENAI_LIVE_VOICES, d as ForwardRef$4, f as ForwardRef$5, g as VOICE_TAB_IDS, l as OPENAI_SPEECH_VOICES, n as Route, o as Effort, s as GROK_TTS_VOICES, u as QGRID_MODEL_GROUPS } from "../entry-server.generated.js";
3
- import { n as CodePanel, t as TimedPlayer } from "./TimedPlayer-mpJpP5tQ.js";
1
+ import { C as looseObject, O as string, Q as require_react, Z as require_jsx_runtime, n as QgridService, nt as __toESM } from "./services.generated-rlOX8J2n.js";
2
+ import { _ as VOICE_TAB_TITLES, b as Link, c as GROK_TTS_VOICES, d as ForwardRef$4, f as ForwardRef$5, g as VOICE_TAB_IDS, l as OPENAI_LIVE_VOICES, n as Route, o as ModelOptions, s as Effort, u as OPENAI_SPEECH_VOICES } from "../entry-server.generated.js";
3
+ import { n as CodePanel, t as TimedPlayer } from "./TimedPlayer-B9ds1sqM.js";
4
4
  //#region ~icons/lucide/external-link.jsx
5
5
  var import_react = /* @__PURE__ */ __toESM(require_react());
6
6
  var import_jsx_runtime = require_jsx_runtime();
@@ -954,13 +954,7 @@ function LivePanel() {
954
954
  onChange: (e) => setDelegateModel(e.target.value),
955
955
  disabled: status !== "idle",
956
956
  className: CONTROL,
957
- children: QGRID_MODEL_GROUPS.map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("optgroup", {
958
- label: group.label,
959
- children: group.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
960
- value: m,
961
- children: m
962
- }, m))
963
- }, group.label))
957
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModelOptions, { selected: delegateModel })
964
958
  })
965
959
  }),
966
960
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {