@urun-sh/openai 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ResponsesClient-BYx3YLGo.d.ts → ResponsesClient-CSSrOYD8.d.ts} +7 -1
- package/dist/{ResponsesClient-Dft3bg3b.d.cts → ResponsesClient-_OZERUjH.d.cts} +11 -1
- package/dist/chunk-3JWYIKHM.js +2 -0
- package/dist/chunk-45FJ5GTP.js +7 -0
- package/dist/chunk-6M5JK4YC.js +1 -0
- package/dist/chunk-QTVTCMJU.js +1 -0
- package/dist/chunk-TDRZZGUK.js +1 -0
- package/dist/chunk-TPH77ZOW.js +58 -0
- package/dist/chunk-WCMX5VOF.js +4 -0
- package/dist/chunk-YXK42SKC.js +1 -0
- package/dist/gemini-live.cjs +2 -2
- package/dist/gemini-live.d.cts +79 -7
- package/dist/gemini-live.d.ts +32 -7
- package/dist/gemini-live.js +1 -1
- package/dist/hosted/bin.cjs +43 -27
- package/dist/hosted/bin.js +4 -4
- package/dist/hosted/index.cjs +41 -26
- package/dist/hosted/index.d.cts +710 -17
- package/dist/hosted/index.d.ts +171 -6
- package/dist/hosted/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/{models-NYMZrklp.d.cts → models-DUdx_Y6X.d.cts} +1 -1
- package/dist/pi-extension/index.cjs +7 -7
- package/dist/pi-extension/index.d.cts +2 -2
- package/dist/pi-extension/index.d.ts +2 -2
- package/dist/pi-extension/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +53 -53
- package/dist/proxy/cli.cjs +55 -43
- package/dist/proxy/cli.js +14 -13
- package/dist/proxy/index.cjs +31 -28
- package/dist/proxy/index.d.cts +132 -18
- package/dist/proxy/index.d.ts +28 -11
- package/dist/proxy/index.js +1 -6
- package/dist/responses-turn-BfdBbey8.d.cts +2394 -0
- package/dist/responses-turn-CdhIre_a.d.ts +652 -0
- package/dist/{translator-CcDBEfvm.d.cts → translator-CO8W_hmJ.d.cts} +3 -3
- package/dist/{translator-C9uPKypK.d.ts → translator-Ddd65sXR.d.ts} +1 -1
- package/dist/{types-lsVTbNcH.d.cts → types-CHPtJx6d.d.cts} +13 -0
- package/dist/{types-lsVTbNcH.d.ts → types-CHPtJx6d.d.ts} +4 -0
- package/dist/{video-out-D20UuJ8G.d.cts → video-out-BsuLqlID.d.cts} +6 -6
- package/dist/{video-out-CWesbk12.d.ts → video-out-Cawtm7SF.d.ts} +1 -1
- package/package.json +14 -11
- package/dist/chunk-5BZCM3RS.js +0 -4
- package/dist/chunk-5NXM4IO3.js +0 -2
- package/dist/chunk-CWJRDBDC.js +0 -1
- package/dist/chunk-DMD5UENK.js +0 -1
- package/dist/chunk-GBBY3PCZ.js +0 -1
- package/dist/chunk-I2Q3B3OG.js +0 -6
- package/dist/chunk-OI2OY32M.js +0 -1
- package/dist/chunk-QVF7NF7G.js +0 -44
- package/dist/responses-turn-KOAoIqZ-.d.ts +0 -200
- package/dist/responses-turn-OrO4euEN.d.cts +0 -513
- /package/dist/{models-NYMZrklp.d.ts → models-DUdx_Y6X.d.ts} +0 -0
package/dist/gemini-live.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var he=Object.create;var E=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var Ae=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ke(t))!Oe.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(o=be(t,r))||o.enumerable});return e};var $=(e,t,n)=>(n=e!=null?he(_e(e)):{},F(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),ve=e=>F(E({},"__esModule",{value:!0}),e);var Pe={};Ae(Pe,{AudioBridge:()=>A,CLOSE_PROTOCOL:()=>B,CLOSE_SESSION_GONE:()=>ne,CLOSE_UNKNOWN_MODEL:()=>te,CLOSE_UPSTREAM:()=>U,GEMINI_AUDIO_IN_RATE:()=>_,GEMINI_AUDIO_OUT_MIME:()=>H,GEMINI_AUDIO_OUT_RATE:()=>V,GEMINI_LIVE_PATH:()=>ee,GeminiLiveError:()=>s,NATIVE_AUDIO_SAMPLE_RATE:()=>I,OUTBOUND_AUDIO_FLUSH_B64:()=>le,RT_VIDEO_IN_STREAM:()=>S,RT_VIDEO_OUT_STREAM:()=>k,SdkTransport:()=>M,VIDEO_FRAME_MESSAGE_BUDGET:()=>R,VIDEO_OUT_DEFAULT_CODEC:()=>T,VIDEO_OUT_FRAMING:()=>P,VIDEO_OUT_SETUP_KEY:()=>b,VIDEO_OUT_WS_FRAMING:()=>C,consumeVideoOut:()=>X,decodeResponsesLane:()=>v,decodeVideoOutRecord:()=>x,enableSessionAudio:()=>W,enableSessionVideo:()=>G,encodeVideoOutRecord:()=>K,goAwayMsg:()=>de,negotiateSessionVideoOutQuic:()=>Q,nodeAudioBackend:()=>q,openSessionVideoOutLane:()=>z,parseClientMessage:()=>oe,resamplePcm16:()=>j,responseCreateToEnvelope:()=>D,responsesCreateToEnvelope:()=>N,serverContentOfAudio:()=>ge,serverContentOfDelta:()=>me,sessionResumptionUpdateMsg:()=>ue,translateClientContent:()=>ce,translateRealtimeInput:()=>fe,translateSetup:()=>ae,translateToolResponse:()=>pe,turnEndOfCompleted:()=>ye,videoOutAck:()=>ie,videoOutChunkMsg:()=>se,weriftAudioBackend:()=>J});module.exports=ve(Pe);var I=24e3,A=class{constructor(t,n){this.backend=t;this.opts=n}backend;opts;source=null;sink=null;outHandlers=new Set;async startOutbound(){return this.source=this.backend.createSource(),this.source.track}appendInputAudio(t){if(!this.source)throw new Error("startOutbound() not called");let n=Buffer.from(t,"base64"),o=Math.floor(n.byteLength/2),r=new Int16Array(o);for(let i=0;i<o;i++)r[i]=n.readInt16LE(i*2);this.source.onData(r)}async startInbound(t){if(t==null)throw new Error('startInbound: no downstream audio track \u2014 the runtime audio producer has not been consumed yet (session.stream("rt-audio-out").track is null)');this.sink=this.backend.createSink(t),this.sink.onframe=n=>{let o=Buffer.from(n.samples.buffer,n.samples.byteOffset,n.samples.byteLength).toString("base64");for(let r of this.outHandlers)r(o)}}onOutputAudio(t){return this.outHandlers.add(t),()=>this.outHandlers.delete(t)}};async function W(e,t,n=1e4){let o=new A(t,{sampleRate:24e3}),r=await o.startOutbound();await e.stream("rt-audio-in").attach(r);let i=await Ee(e,n);return await o.startInbound(i),o}function Ee(e,t){let n=e.stream("rt-audio-out");return n.track!=null?Promise.resolve(n.track):new Promise((o,r)=>{let i,a=setTimeout(()=>{i?.(),r(new Error(`enableSessionAudio: no downstream audio track within ${t}ms (runtime produced no voice OUT / SFU audio consumer never attached)`))},t),c=d=>{d!=null&&(clearTimeout(a),i?.(),o(d))};i=n.on?.("track",c),n.track!=null&&c(n.track)})}var S="rt-video-in",R=256e3;function G(e){let t=e.stream(S),n=t.emit;if(typeof n!="function")throw new Error(`enableSessionVideo: session.stream('${S}') has no emit() \u2014 the named-DATA stream produce seam (@urun-sh/core SessionStream.emit, contract \xA75) is required for the video frame lane`);return{sendInputFrame:async o=>{if(o.byteLength===0)throw new Error("enableSessionVideo: refusing to send an empty video frame");if(o.byteLength>R)throw new Error(`enableSessionVideo: frame is ${o.byteLength} bytes \u2014 over the ${R}-byte data-channel budget (the SFU's 262144-byte SCTP ceiling drops oversize messages SILENTLY; send smaller/lower-quality frames)`);await n.call(t,o)}}}var Se=24e3,O=480,Re=111;async function Ie(){let e=await import("opusscript"),t=e.default??e;return new t(Se,1,2048)}async function J(){let e=await import("werift"),t=await Ie();return{createSource:()=>{let n=new e.MediaStreamTrack({kind:"audio"}),o=Math.random()*4294967295>>>0,r=Math.random()*65535&65535,i=Math.random()*4294967295>>>0,a=new Int16Array(0);return{track:n,onData:c=>{let d=new Int16Array(a.length+c.length);d.set(a,0),d.set(c,a.length);let u=0;for(;d.length-u>=O;){let l=d.subarray(u,u+O);u+=O;let f=Buffer.from(l.buffer,l.byteOffset,l.byteLength),p=t.encode(f,O);r=r+1&65535,i=i+O>>>0;let g=new e.RtpHeader({version:2,payloadType:Re,sequenceNumber:r,timestamp:i,ssrc:o,marker:!1}),w=new e.RtpPacket(g,p);n.writeRtp(w)}a=d.slice(u)}}},createSink:n=>{let o={onframe:null};return n.onReceiveRtp.subscribe(i=>{let a;try{a=t.decode(i.payload)}catch{return}let c=new Int16Array(a.length/2);for(let d=0;d<c.length;d++)c[d]=a.readInt16LE(d*2);o.onframe?.({samples:c})}),o}}}async function q(){let e=await import("@roamhq/wrtc");return{createSource:()=>{let t=new e.nonstandard.RTCAudioSource;return{track:t.createTrack(),onData:o=>t.onData({samples:o,sampleRate:24e3})}},createSink:t=>{let n={onframe:null},o=new e.nonstandard.RTCAudioSink(t);return o.ondata=r=>{n.onframe?.(r)},n}}}var y=require("@urun-sh/core"),k="rt-video-out",P="urun.videoOut.v1",T="h264";function Y(e,t){if(!Number.isInteger(e.seq)||e.seq<0)throw new Error(`${t}: header seq must be a non-negative integer (got ${e.seq})`);if(!Number.isInteger(e.ptsUs))throw new Error(`${t}: header ptsUs must be an integer microsecond timestamp (got ${e.ptsUs})`);if(typeof e.codec!="string"||e.codec.length===0)throw new Error(`${t}: header codec must be a non-empty string`);if(typeof e.key!="boolean")throw new Error(`${t}: header key must be a boolean`)}function K(e,t){if(Y(e,"encodeVideoOutRecord"),t.byteLength===0)throw new Error("encodeVideoOutRecord: refusing to encode an empty access unit");let n=new TextEncoder().encode(JSON.stringify({v:1,seq:e.seq,ptsUs:e.ptsUs,codec:e.codec,key:e.key}));if(n.byteLength>65535)throw new Error(`encodeVideoOutRecord: header JSON is ${n.byteLength} bytes \u2014 over the u16 length prefix`);let o=new Uint8Array(2+n.byteLength+t.byteLength);return o[0]=n.byteLength&255,o[1]=n.byteLength>>8,o.set(n,2),o.set(t,2+n.byteLength),o}function x(e){if(e.byteLength<2)throw new Error(`decodeVideoOutRecord: truncated record (${e.byteLength} byte(s), no header length)`);let t=e[0]|e[1]<<8;if(e.byteLength<2+t)throw new Error(`decodeVideoOutRecord: truncated record (header says ${t} bytes, ${e.byteLength-2} present)`);let n;try{n=JSON.parse(new TextDecoder().decode(e.subarray(2,2+t)))}catch(a){throw new Error(`decodeVideoOutRecord: header is not valid JSON (${String(a)})`)}let o=n;if(o===null||typeof o!="object"||o.v!==1)throw new Error(`decodeVideoOutRecord: header is not spec v1 (v=${JSON.stringify(o?.v)}) \u2014 a newer producer must be met with a newer consumer, never silently misread`);let r=o;Y(r,"decodeVideoOutRecord");let i=e.subarray(2+t);if(i.byteLength===0)throw new Error("decodeVideoOutRecord: empty access unit \u2014 a record with no AU bytes is a producer bug");return{header:r,au:i.slice()}}async function Q(e){let t=e.wtDataEndpoint;if(typeof t!="function")throw new Error("negotiateSessionVideoOutQuic: the core session exposes no wtDataEndpoint() \u2014 the \xA75-over-QUIC dial seam (urun-infra#1608 TransportOfferResponse.webtransport, offered with wtData: true) is required for the video OUT lane; there is no WS fallback");let n=await t.call(e),o=n.sessionId??e.sessionId;if(typeof o!="string"||o.length===0)throw new Error("negotiateSessionVideoOutQuic: no session id \u2014 the WT hello requires one and neither the negotiated endpoint nor the core session carries it");return{transport:"webtransport",url:n.url,certHashes:n.certHashes,token:n.token,sessionId:o,stream:k,codec:T,framing:P}}var C="urun.videoOut.v2-ws";function z(e){let t=e.stream(k);if(typeof t.messages!="function")throw new Error(`openSessionVideoOutLane: session.stream('${k}') has no messages() \u2014 the named-DATA stream consume seam (@urun-sh/core SessionStream.messages, contract \xA75) is required for the video OUT lane`);let n=new Set,o=new Set,r=new Set,i=d=>{for(let u of o)u(d)},a=!1,c=async()=>{for await(let d of t.messages()){if(!(d instanceof Uint8Array)){i(new Error(`openSessionVideoOutLane: "${k}" delivered a non-BINARY \xA75 payload (${typeof d}) \u2014 spec v1 records ride BINARY envelopes only`));continue}let u;try{u=x(d)}catch(l){i(l instanceof Error?l:new Error(String(l)));continue}for(let l of n)l(u)}for(let d of r)d()};return{codec:T,onOutputFrame:d=>(n.add(d),a||(a=!0,c().catch(u=>i(u instanceof Error?u:new Error(String(u))))),()=>n.delete(d)),onLaneError:d=>(o.add(d),()=>o.delete(d)),onEnd:d=>(r.add(d),()=>r.delete(d))}}function Te(e){if(e.length%2!==0||/[^0-9a-fA-F]/.test(e))throw new Error(`consumeVideoOut: certHashes entry is not hex sha-256 (${JSON.stringify(e)})`);let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}async function X(e,t,n){let o=n??(typeof globalThis.WebTransport=="function"?(u,l)=>new globalThis.WebTransport(u,l):void 0);if(!o)throw new Error("consumeVideoOut: no WebTransport implementation \u2014 this platform has no globalThis.WebTransport; inject a connect factory (the third argument)");let r=o(e.url,{serverCertificateHashes:e.certHashes.map(u=>({algorithm:"sha-256",value:Te(u)}))});await r.ready;let i=await r.createBidirectionalStream();await i.writable.getWriter().write((0,y.encodeWtControlFrame)({t:"hello",token:e.token,sessionId:e.sessionId}));let a=i.readable.getReader(),c=new y.WtControlDecoder,d=!1;for(;!d;){let{value:u,done:l}=await a.read();if(l)throw new Error("consumeVideoOut: gateway closed the control stream before hello-ack");if(u)for(let f of c.push(u)){if(f.t==="hello-ack"){d=!0;break}throw new Error(`consumeVideoOut: gateway rejected hello (got ${JSON.stringify(f.t)} before hello-ack)`)}}await(0,y.consumeWtDataStreams)(r.incomingUnidirectionalStreams,{onData:(u,l)=>{if(u===e.stream){if(l===y.STREAM_END){t.onEnd?.();return}if(!(l instanceof Uint8Array)){t.onLaneError(new Error(`consumeVideoOut: "${e.stream}" delivered a non-BINARY \xA75 payload (${typeof l}) \u2014 spec v1 records ride BINARY envelopes only`));return}try{t.onFrame(x(l))}catch(f){t.onLaneError(f instanceof Error?f:new Error(String(f)))}}},onLaneError:u=>t.onLaneError(u)})}var ee="/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent",B=1007,te=1008,U=1011,ne=1008,s=class extends Error{constructor(n,o=B){super(n);this.closeCode=o}closeCode},m=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null,L=["setup","clientContent","realtimeInput","toolResponse"];function oe(e){let t;try{t=JSON.parse(e)}catch{throw new s("client message is not valid JSON")}let n=m(t);if(!n)throw new s("client message must be a JSON object");let o=L.filter(c=>n[c]!==void 0),r=Object.keys(n).filter(c=>!L.includes(c));if(r.length>0)throw new s(`unknown client message field(s) ${JSON.stringify(r)} \u2014 expected exactly one of ${L.join(", ")}`);if(o.length!==1)throw new s(`client message must contain exactly one of ${L.join(", ")} (got ${o.length})`);let i=o[0],a=m(n[i]);if(!a)throw new s(`"${i}" must be a JSON object`);return{kind:i,[i]:a}}function re(e,t){if(typeof e=="string")return e;let n=m(e),o=n?n.parts:void 0;if(!Array.isArray(o))throw new s(`${t}: expected a Content with a parts array`);let r=[];for(let i of o){let a=m(i);if(a&&typeof a.text=="string"){r.push(a.text);continue}throw a&&(a.inlineData!==void 0||a.fileData!==void 0)?new s(`${t}: media parts (inlineData/fileData) are a declared follow-up slice (audio/video lanes over the proxy transport AudioBridge) \u2014 only text parts are supported in this slice`):a&&(a.functionCall!==void 0||a.functionResponse!==void 0)?new s(`${t}: functionCall/functionResponse parts are not valid here \u2014 the Live API exchanges tool traffic via the dedicated toolCall/toolResponse messages`):new s(`${t}: unsupported part ${JSON.stringify(i)}`)}return r.join(`
|
|
2
|
-
`)}var xe={manualActivity:!1,activityHandling:"START_OF_ACTIVITY_INTERRUPTS"},b="urun.videoOut";function ie(e){return{framing:C,codec:e}}function se(e){let{seq:t,ptsUs:n,codec:o,key:r}=e.header;return{[b]:{v:1,seq:t,ptsUs:n,codec:o,key:r,data:Buffer.from(e.au).toString("base64")}}}var Ce={inputAudioTranscription:"setup.inputAudioTranscription is part of the declared audio follow-up slice",outputAudioTranscription:"setup.outputAudioTranscription is part of the declared audio follow-up slice"},Le=["model","generationConfig","systemInstruction","tools","realtimeInputConfig","sessionResumption",b],Z=["START_OF_ACTIVITY_INTERRUPTS","NO_INTERRUPTION"];function Ue(e){let t=m(e);if(!t)throw new s("setup.realtimeInputConfig must be an object");for(let r of Object.keys(t))if(!(r==="automaticActivityDetection"||r==="activityHandling"))throw new s(r==="turnCoverage"?"realtimeInputConfig.turnCoverage is part of the declared audio follow-up slice":`unsupported realtimeInputConfig field "${r}"`);let n=m(t.automaticActivityDetection);if(t.automaticActivityDetection!==void 0&&!n)throw new s("realtimeInputConfig.automaticActivityDetection must be an object");for(let r of Object.keys(n??{}))if(r!=="disabled")throw new s(`automaticActivityDetection.${r} tunes AUTOMATIC (server-side) activity detection \u2014 the declared platform follow-up (serve turn_detection events over the session stream lane); only "disabled: true" (manual activity mode) is supported in this slice`);if(n?.disabled!==!0)throw new s("automatic (server-side) activity detection is the declared platform follow-up (serve turn_detection turn_start/turn_end events over the session stream lane, not proxy DSP) \u2014 set realtimeInputConfig.automaticActivityDetection.disabled: true for manual activity mode");let o="START_OF_ACTIVITY_INTERRUPTS";if(t.activityHandling!==void 0){if(!Z.includes(t.activityHandling))throw new s(`unsupported activityHandling ${JSON.stringify(t.activityHandling)} \u2014 expected one of ${Z.join(", ")}`);o=t.activityHandling}return{manualActivity:!0,activityHandling:o}}var Ve=["temperature","maxOutputTokens","responseModalities"];function ae(e){for(let[f,p]of Object.entries(Ce))if(e[f]!==void 0)throw new s(p);for(let f of Object.keys(e))if(!Le.includes(f))throw new s(`unsupported setup field "${f}"`);if(typeof e.model!="string"||e.model.length===0)throw new s('setup.model is required (format "models/{model}")');let t=e.model.replace(/^models\//,""),n,o,r=!1,i=m(e.generationConfig);if(e.generationConfig!==void 0&&!i)throw new s("setup.generationConfig must be an object");if(i){for(let f of Object.keys(i))if(!Ve.includes(f))throw new s(`unsupported generationConfig field "${f}"`);if(i.temperature!==void 0){if(typeof i.temperature!="number")throw new s("generationConfig.temperature must be a number");n=i.temperature}if(i.maxOutputTokens!==void 0){if(typeof i.maxOutputTokens!="number")throw new s("generationConfig.maxOutputTokens must be a number");o=i.maxOutputTokens}if(i.responseModalities!==void 0){let f=Array.isArray(i.responseModalities)?i.responseModalities:[i.responseModalities];for(let p of f){let g=String(p).toUpperCase();if(g==="AUDIO"){r=!0;continue}if(g!=="TEXT")throw new s(`responseModalities ${JSON.stringify(p)} is not supported \u2014 this surface speaks TEXT and AUDIO (audio-out rides the native AudioBridge rt-audio-out lane)`)}}}let a=[];e.systemInstruction!==void 0&&a.push({role:"system",content:re(e.systemInstruction,"setup.systemInstruction")});let c;if(e.tools!==void 0){if(!Array.isArray(e.tools))throw new s("setup.tools must be an array");c=[];for(let f of e.tools){let p=m(f);if(!p)throw new s("setup.tools entries must be objects");for(let g of Object.keys(p))if(g!=="functionDeclarations")throw new s(`unsupported tool "${g}" \u2014 this slice translates functionDeclarations only (no googleSearch/codeExecution)`);if(!Array.isArray(p.functionDeclarations))throw new s("tool.functionDeclarations must be an array");for(let g of p.functionDeclarations){let w=m(g);if(!w||typeof w.name!="string")throw new s("functionDeclarations entries require a string name");c.push({type:"function",name:w.name,description:w.description,parameters:w.parameters})}}c.length===0&&(c=void 0)}let d={enabled:!1,handle:null};if(e.sessionResumption!==void 0){let f=m(e.sessionResumption);if(!f)throw new s("setup.sessionResumption must be an object (SessionResumptionConfig)");for(let p of Object.keys(f))if(p!=="handle")throw new s(`unsupported sessionResumption field "${p}" \u2014 this lane implements SessionResumptionConfig.handle only`);if(f.handle!==void 0&&(typeof f.handle!="string"||f.handle.length===0))throw new s("sessionResumption.handle must be a non-empty string when present");d={enabled:!0,handle:typeof f.handle=="string"?f.handle:null}}let u=e.realtimeInputConfig===void 0?xe:Ue(e.realtimeInputConfig),l=!1;if(e[b]!==void 0){if(!m(e[b]))throw new s(`setup["${b}"] must be an object (the v1 opt-in is {})`);l=!0}return{model:t,systemItems:a,tools:c,temperature:n,maxOutputTokens:o,audioModality:r,activity:u,sessionResumption:d,videoOut:l}}function ue(e){return{sessionResumptionUpdate:{newHandle:e,resumable:!0}}}function de(e){let t=Math.max(0,e??0)/1e3;return{goAway:{timeLeft:`${Math.round(t*1e3)/1e3}s`}}}function ce(e){for(let o of Object.keys(e))if(o!=="turns"&&o!=="turnComplete")throw new s(`unsupported clientContent field "${o}"`);let t=e.turns===void 0?[]:e.turns;if(!Array.isArray(t))throw new s("clientContent.turns must be an array");let n=[];for(let o of t){let r=m(o);if(!r)throw new s("clientContent.turns entries must be Content objects");let i=r.role===void 0?"user":String(r.role).toLowerCase();if(i!=="user"&&i!=="model")throw new s(`clientContent turn role must be "user" or "model" (got ${JSON.stringify(r.role)})`);n.push({role:i==="model"?"assistant":"user",content:re(r,"clientContent.turns")})}return{items:n,turnComplete:e.turnComplete===!0}}var _=16e3,V=24e3,H=`audio/pcm;rate=${V}`,le=Buffer.alloc(960).toString("base64");function j(e,t,n){if(t===n)return e;let o=Math.floor(e.length*n/t),r=new Int16Array(o),i=t/n,a=e.length-1;for(let c=0;c<o;c++){let d=c*i,u=Math.floor(d);if(u>=a){r[c]=e[a];continue}let l=d-u;r[c]=Math.round(e[u]+(e[u+1]-e[u])*l)}return r}function De(e){let t=m(e);if(!t)throw new s("realtimeInput.video must be a Blob object {mimeType, data}");if(typeof t.mimeType!="string"||!/^image\/jpeg\s*(;|$)/.test(t.mimeType))throw new s(`realtimeInput.video.mimeType must be image/jpeg (the Live video input stream is individual JPEG frames), got ${JSON.stringify(t.mimeType)}`);if(typeof t.data!="string"||t.data.length===0)throw new s("realtimeInput.video.data must be non-empty base64");let n=Buffer.from(t.data,"base64");if(n.length<3||n[0]!==255||n[1]!==216)throw new s("realtimeInput.video.data does not decode to a JPEG frame (missing FF D8 SOI marker)");return new Uint8Array(n)}function Ne(e){let t=m(e);if(!t)throw new s("realtimeInput.audio must be a Blob object {mimeType, data}");if(typeof t.mimeType!="string"||!/^audio\/pcm\s*(;|$)/.test(t.mimeType))throw new s(`realtimeInput.audio.mimeType must be audio/pcm (16-bit LE PCM @16kHz mono per the Live spec), got ${JSON.stringify(t.mimeType)}`);let n=/;\s*rate=(\d+)/.exec(t.mimeType);if(n&&Number(n[1])!==_)throw new s(`realtimeInput.audio.mimeType declares rate=${n[1]} \u2014 the Live spec input format is ${_} Hz (audio/pcm;rate=${_})`);if(typeof t.data!="string"||t.data.length===0)throw new s("realtimeInput.audio.data must be non-empty base64");let o=Buffer.from(t.data,"base64");if(o.length===0||o.length%2!==0)throw new s(`realtimeInput.audio.data must decode to whole 16-bit samples (got ${o.length} bytes \u2014 not even)`);let r=new Int16Array(o.length/2);for(let a=0;a<r.length;a++)r[a]=o.readInt16LE(a*2);let i=j(r,_,V);return Buffer.from(i.buffer,i.byteOffset,i.byteLength).toString("base64")}function fe(e){if(e.mediaChunks!==void 0)throw new s('realtimeInput.mediaChunks is deprecated by the Live API \u2014 send the audio stream via realtimeInput.audio ({mimeType:"audio/pcm;rate=16000", data}) instead');if(e.activityStart!==void 0||e.activityEnd!==void 0){if(Object.keys(e).length!==1||e.activityStart!==void 0&&e.activityEnd!==void 0)throw new s("realtimeInput must carry exactly one field when signaling activity (activityStart XOR activityEnd, nothing else)");let r=e.activityStart!==void 0?"activityStart":"activityEnd",i=m(e[r]);if(!i||Object.keys(i).length!==0)throw new s(`realtimeInput.${r} must be an empty object (ActivityStart/ActivityEnd are bare markers)`);return{kind:r}}let t=["text","audio","audioStreamEnd","video"];for(let o of Object.keys(e))if(!t.includes(o))throw new s(`unsupported realtimeInput field "${o}"`);let n=t.filter(o=>e[o]!==void 0);if(n.length!==1)throw new s(`realtimeInput must carry exactly one of ${t.join(", ")} (got ${n.length})`);if(e.audio!==void 0)return{kind:"audio",base64Pcm24k:Ne(e.audio)};if(e.video!==void 0)return{kind:"video",jpegFrame:De(e.video)};if(e.audioStreamEnd!==void 0){if(e.audioStreamEnd!==!0)throw new s("realtimeInput.audioStreamEnd must be true when present");return{kind:"audioStreamEnd"}}if(typeof e.text!="string"||e.text.length===0)throw new s("realtimeInput.text must be a non-empty string");return{kind:"text",text:e.text}}function pe(e){for(let t of Object.keys(e))if(t!=="functionResponses")throw new s(`unsupported toolResponse field "${t}"`);if(!Array.isArray(e.functionResponses)||e.functionResponses.length===0)throw new s("toolResponse.functionResponses must be a non-empty array");return e.functionResponses.map(t=>{let n=m(t);if(!n||typeof n.id!="string"||n.id.length===0)throw new s("functionResponses entries require the string id matched from the toolCall");return{type:"function_call_output",call_id:n.id,output:JSON.stringify(n.response??null)}})}function me(e){return e.type!=="response.output_text.delta"||typeof e.delta!="string"?null:{serverContent:{modelTurn:{role:"model",parts:[{text:e.delta}]}}}}function ge(e){return{serverContent:{modelTurn:{role:"model",parts:[{inlineData:{mimeType:H,data:e}}]}}}}function ye(e){let t=m(e)??{},n=Array.isArray(t.output)?t.output:[],o=[],r=[],i=typeof t.output_text=="string"?t.output_text:"";if(!i)for(let u of n){let l=m(u);if(!(l?.type!=="message"||!Array.isArray(l.content)))for(let f of l.content){let p=m(f);p?.type==="output_text"&&typeof p.text=="string"&&(i+=p.text)}}i&&r.push({role:"assistant",content:i});for(let u of n){let l=m(u);if(l?.type!=="function_call")continue;if(typeof l.call_id!="string"||typeof l.name!="string")throw new s(`upstream function_call item is missing call_id/name: ${JSON.stringify(u)}`,U);let f=typeof l.arguments=="string"&&l.arguments.length>0?l.arguments:"{}",p;try{p=JSON.parse(f)}catch{throw new s(`upstream function_call arguments are not valid JSON: ${f}`,U)}o.push({id:l.call_id,name:l.name,args:p}),r.push({type:"function_call",call_id:l.call_id,name:l.name,arguments:f})}let a=[];o.length>0&&a.push({toolCall:{functionCalls:o}}),a.push({serverContent:{generationComplete:!0}});let c=m(t.usage),d={serverContent:{turnComplete:!0}};if(c){let u={};typeof c.input_tokens=="number"&&(u.promptTokenCount=c.input_tokens),typeof c.output_tokens=="number"&&(u.responseTokenCount=c.output_tokens),typeof c.total_tokens=="number"&&(u.totalTokenCount=c.total_tokens),Object.keys(u).length>0&&(d.usageMetadata=u)}return a.push(d),{messages:a,assistantItems:r}}function D(e,t,n,o){let r=e.response??{},i={request_id:n,consumer_id:o,stream:!0,kind:"chat",messages:t};return typeof r.instructions=="string"&&(i.instructions=r.instructions),Array.isArray(r.modalities)&&(i.modalities=r.modalities),typeof r.temperature=="number"&&(i.temperature=r.temperature),typeof r.max_output_tokens=="number"&&(i.max_output_tokens=r.max_output_tokens),r.tools!==void 0&&(i.tools=r.tools),i}function N(e,t,n){let o={request_id:t,consumer_id:n,stream:!!e.stream,kind:"responses",input:e.input};return e.model&&(o.model=e.model),e.tools!==void 0&&(o.tools=e.tools),e.tool_choice!==void 0&&(o.tool_choice=e.tool_choice),typeof e.temperature=="number"&&(o.temperature=e.temperature),typeof e.max_output_tokens=="number"&&(o.max_output_tokens=e.max_output_tokens),typeof e.top_p=="number"&&(o.top_p=e.top_p),Array.isArray(e.stop)&&e.stop.length>0&&(o.stop=e.stop),typeof e.reasoning_effort=="string"&&(o.reasoning_effort=e.reasoning_effort),e.chat_template_kwargs!==void 0&&(o.chat_template_kwargs=e.chat_template_kwargs),o}function we(e){if(e instanceof Error)return{type:"error",error:{type:"urun_error",code:e.name||null,message:e.message}};if(e&&typeof e=="object"&&e.t==="error"){let t=e,n=t.body??{};return{type:"error",error:{type:"urun_error",code:t.code??null,message:n.message??"unknown error"}}}return{type:"error",error:{type:"urun_error",code:null,message:String(e)}}}var Me="llm-resp";async function*v(e,t){let n=`${Me}:${t}`,o=`resp_${t}`;yield{type:"response.created",response:{id:o,status:"in_progress"}};let r=new Map;for await(let i of e.stream(n).messages()){let a=i;if(a.t==="delta"){if(typeof a.delta=="string"&&(yield{type:"response.output_text.delta",item_id:o,delta:a.delta}),typeof a.reasoning=="string"&&(yield{type:"response.reasoning_text.delta",item_id:o,delta:a.reasoning}),Array.isArray(a.tool_calls))for(let c of a.tool_calls){let d=typeof c.index=="number"?c.index:0,u=r.get(d)??{};c.id&&(u.id=c.id),c.function?.name&&(u.name=c.function.name),r.set(d,u),yield{type:"response.function_call_arguments.delta",item_id:`fc_${t}_${d}`,tool_index:d,call_id:u.id,name:u.name,delta:c.function?.arguments??""}}}else if(a.t==="response"){yield{type:"response.completed",response:{id:o,status:"completed",...a.body}};return}else if(a.t==="error"){yield we(a);return}}}var $e="llm",M=class{constructor(t){this.session=t;this.sessionTag=t.sessionId??globalThis.crypto.randomUUID()}session;sessionTag;get consumerId(){return this.session.consumerId}write(t){t.session_tag=this.sessionTag,this.session.doc($e).set({requests:{[t.request_id]:{payload:t,consumer_id:t.consumer_id,stream:t.stream}}})}sendResponses(t,n){let o=N(t,n,this.consumerId);return this.write(o),v(this.session,n)}sendResponseCreate(t,n,o){let r=D(t,n,o,this.consumerId);return this.write(r),v(this.session,o)}};0&&(module.exports={AudioBridge,CLOSE_PROTOCOL,CLOSE_SESSION_GONE,CLOSE_UNKNOWN_MODEL,CLOSE_UPSTREAM,GEMINI_AUDIO_IN_RATE,GEMINI_AUDIO_OUT_MIME,GEMINI_AUDIO_OUT_RATE,GEMINI_LIVE_PATH,GeminiLiveError,NATIVE_AUDIO_SAMPLE_RATE,OUTBOUND_AUDIO_FLUSH_B64,RT_VIDEO_IN_STREAM,RT_VIDEO_OUT_STREAM,SdkTransport,VIDEO_FRAME_MESSAGE_BUDGET,VIDEO_OUT_DEFAULT_CODEC,VIDEO_OUT_FRAMING,VIDEO_OUT_SETUP_KEY,VIDEO_OUT_WS_FRAMING,consumeVideoOut,decodeResponsesLane,decodeVideoOutRecord,enableSessionAudio,enableSessionVideo,encodeVideoOutRecord,goAwayMsg,negotiateSessionVideoOutQuic,nodeAudioBackend,openSessionVideoOutLane,parseClientMessage,resamplePcm16,responseCreateToEnvelope,responsesCreateToEnvelope,serverContentOfAudio,serverContentOfDelta,sessionResumptionUpdateMsg,translateClientContent,translateRealtimeInput,translateSetup,translateToolResponse,turnEndOfCompleted,videoOutAck,videoOutChunkMsg,weriftAudioBackend});
|
|
1
|
+
"use strict";var _e=Object.create;var E=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var Oe=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},W=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ve(t))!Ae.call(e,r)&&r!==n&&E(e,r,{get:()=>t[r],enumerable:!(o=be(t,r))||o.enumerable});return e};var $=(e,t,n)=>(n=e!=null?_e(Oe(e)):{},W(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),Se=e=>W(E({},"__esModule",{value:!0}),e);var Be={};Ee(Be,{AudioBridge:()=>O,CLOSE_PROTOCOL:()=>H,CLOSE_SESSION_GONE:()=>re,CLOSE_UNKNOWN_MODEL:()=>oe,CLOSE_UPSTREAM:()=>U,GEMINI_AUDIO_IN_RATE:()=>b,GEMINI_AUDIO_OUT_MIME:()=>F,GEMINI_AUDIO_OUT_RATE:()=>D,GEMINI_LIVE_PATH:()=>ne,GeminiLiveError:()=>s,NATIVE_AUDIO_SAMPLE_RATE:()=>R,OUTBOUND_AUDIO_FLUSH_B64:()=>pe,RT_VIDEO_IN_STREAM:()=>S,RT_VIDEO_OUT_STREAM:()=>_,SdkTransport:()=>P,VIDEO_FRAME_MESSAGE_BUDGET:()=>T,VIDEO_OUT_DEFAULT_CODEC:()=>I,VIDEO_OUT_FRAMING:()=>B,VIDEO_OUT_SETUP_KEY:()=>k,VIDEO_OUT_WS_FRAMING:()=>C,consumeVideoOut:()=>ee,decodeResponsesLane:()=>A,decodeVideoOutRecord:()=>x,enableSessionAudio:()=>J,enableSessionVideo:()=>q,encodeVideoOutRecord:()=>z,goAwayMsg:()=>le,negotiateSessionVideoOutQuic:()=>X,nodeAudioBackend:()=>K,openSessionVideoOutLane:()=>Z,parseClientMessage:()=>ie,resamplePcm16:()=>j,responseCreateToEnvelope:()=>V,responsesCreateToEnvelope:()=>M,serverContentOfAudio:()=>we,serverContentOfDelta:()=>ye,sessionResumptionUpdateMsg:()=>ce,translateClientContent:()=>fe,translateRealtimeInput:()=>me,translateSetup:()=>de,translateToolResponse:()=>ge,turnEndOfCompleted:()=>he,videoOutAck:()=>ae,videoOutChunkMsg:()=>ue,weriftAudioBackend:()=>Y});module.exports=Se(Be);var R=24e3,G="audio",O=class{constructor(t,n){this.backend=t;this.opts=n}backend;opts;source=null;sink=null;outHandlers=new Set;async startOutbound(){return this.source=this.backend.createSource(),this.source.track}appendInputAudio(t){if(!this.source)throw new Error("startOutbound() not called");let n=Buffer.from(t,"base64"),o=Math.floor(n.byteLength/2),r=new Int16Array(o);for(let i=0;i<o;i++)r[i]=n.readInt16LE(i*2);this.source.onData(r)}async startInbound(t){if(t==null)throw new Error('startInbound: no downstream audio track \u2014 the runtime audio producer has not been consumed yet (session.stream("audio").track is null)');this.sink=this.backend.createSink(t),this.sink.onframe=n=>{let o=Buffer.from(n.samples.buffer,n.samples.byteOffset,n.samples.byteLength).toString("base64");for(let r of this.outHandlers)r(o)}}onOutputAudio(t){return this.outHandlers.add(t),()=>this.outHandlers.delete(t)}};async function J(e,t,n=1e4){let o=new O(t,{sampleRate:24e3}),r=await o.startOutbound();await e.stream(G).attach(r);let i=await Te(e,n);return await o.startInbound(i),o}function Te(e,t){let n=e.stream(G);return n.track!=null?Promise.resolve(n.track):new Promise((o,r)=>{let i,a=setTimeout(()=>{i?.(),r(new Error(`enableSessionAudio: no downstream audio track within ${t}ms (runtime produced no voice OUT / SFU audio consumer never attached)`))},t),c=d=>{d!=null&&(clearTimeout(a),i?.(),o(d))};i=n.on?.("track",c),n.track!=null&&c(n.track)})}var S="rt-video-in",T=256e3;function q(e){let t=e.stream(S),n=t.emit;if(typeof n!="function")throw new Error(`enableSessionVideo: session.stream('${S}') has no emit() \u2014 the named-DATA stream produce seam (@urun-sh/core SessionStream.emit, contract \xA75) is required for the video frame lane`);return{sendInputFrame:async o=>{if(o.byteLength===0)throw new Error("enableSessionVideo: refusing to send an empty video frame");if(o.byteLength>T)throw new Error(`enableSessionVideo: frame is ${o.byteLength} bytes \u2014 over the ${T}-byte data-channel budget (the SFU's 262144-byte SCTP ceiling drops oversize messages SILENTLY; send smaller/lower-quality frames)`);await n.call(t,o)}}}var Re=24e3,v=480,Ie=111;async function xe(){let e=await import("opusscript"),t=e.default??e;return new t(Re,1,2048)}async function Y(){let e=await import("werift"),t=await xe();return{createSource:()=>{let n=new e.MediaStreamTrack({kind:"audio"}),o=Math.random()*4294967295>>>0,r=Math.random()*65535&65535,i=Math.random()*4294967295>>>0,a=new Int16Array(0);return{track:n,onData:c=>{let d=new Int16Array(a.length+c.length);d.set(a,0),d.set(c,a.length);let u=0;for(;d.length-u>=v;){let l=d.subarray(u,u+v);u+=v;let f=Buffer.from(l.buffer,l.byteOffset,l.byteLength),p=t.encode(f,v);r=r+1&65535,i=i+v>>>0;let g=new e.RtpHeader({version:2,payloadType:Ie,sequenceNumber:r,timestamp:i,ssrc:o,marker:!1}),h=new e.RtpPacket(g,p);n.writeRtp(h)}a=d.slice(u)}}},createSink:n=>{let o={onframe:null};return n.onReceiveRtp.subscribe(i=>{let a;try{a=t.decode(i.payload)}catch{return}let c=new Int16Array(a.length/2);for(let d=0;d<c.length;d++)c[d]=a.readInt16LE(d*2);o.onframe?.({samples:c})}),o}}}async function K(){let e=await import("@roamhq/wrtc");return{createSource:()=>{let t=new e.nonstandard.RTCAudioSource;return{track:t.createTrack(),onData:o=>t.onData({samples:o,sampleRate:24e3})}},createSink:t=>{let n={onframe:null},o=new e.nonstandard.RTCAudioSink(t);return o.ondata=r=>{n.onframe?.(r)},n}}}var w=require("@urun-sh/core"),_="rt-video-out",B="urun.videoOut.v1",I="h264";function Q(e,t){if(!Number.isInteger(e.seq)||e.seq<0)throw new Error(`${t}: header seq must be a non-negative integer (got ${e.seq})`);if(!Number.isInteger(e.ptsUs))throw new Error(`${t}: header ptsUs must be an integer microsecond timestamp (got ${e.ptsUs})`);if(typeof e.codec!="string"||e.codec.length===0)throw new Error(`${t}: header codec must be a non-empty string`);if(typeof e.key!="boolean")throw new Error(`${t}: header key must be a boolean`)}function z(e,t){if(Q(e,"encodeVideoOutRecord"),t.byteLength===0)throw new Error("encodeVideoOutRecord: refusing to encode an empty access unit");let n=new TextEncoder().encode(JSON.stringify({v:1,seq:e.seq,ptsUs:e.ptsUs,codec:e.codec,key:e.key}));if(n.byteLength>65535)throw new Error(`encodeVideoOutRecord: header JSON is ${n.byteLength} bytes \u2014 over the u16 length prefix`);let o=new Uint8Array(2+n.byteLength+t.byteLength);return o[0]=n.byteLength&255,o[1]=n.byteLength>>8,o.set(n,2),o.set(t,2+n.byteLength),o}function x(e){if(e.byteLength<2)throw new Error(`decodeVideoOutRecord: truncated record (${e.byteLength} byte(s), no header length)`);let t=e[0]|e[1]<<8;if(e.byteLength<2+t)throw new Error(`decodeVideoOutRecord: truncated record (header says ${t} bytes, ${e.byteLength-2} present)`);let n;try{n=JSON.parse(new TextDecoder().decode(e.subarray(2,2+t)))}catch(a){throw new Error(`decodeVideoOutRecord: header is not valid JSON (${String(a)})`)}let o=n;if(o===null||typeof o!="object"||o.v!==1)throw new Error(`decodeVideoOutRecord: header is not spec v1 (v=${JSON.stringify(o?.v)}) \u2014 a newer producer must be met with a newer consumer, never silently misread`);let r=o;Q(r,"decodeVideoOutRecord");let i=e.subarray(2+t);if(i.byteLength===0)throw new Error("decodeVideoOutRecord: empty access unit \u2014 a record with no AU bytes is a producer bug");return{header:r,au:i.slice()}}async function X(e){let t=e.wtDataEndpoint;if(typeof t!="function")throw new Error("negotiateSessionVideoOutQuic: the core session exposes no wtDataEndpoint() \u2014 the \xA75-over-QUIC dial seam (urun-infra#1608 TransportOfferResponse.webtransport, offered with wtData: true) is required for the video OUT lane; there is no WS fallback");let n=await t.call(e),o=n.sessionId??e.sessionId;if(typeof o!="string"||o.length===0)throw new Error("negotiateSessionVideoOutQuic: no session id \u2014 the WT hello requires one and neither the negotiated endpoint nor the core session carries it");return{transport:"webtransport",url:n.url,certHashes:n.certHashes,token:n.token,sessionId:o,stream:_,codec:I,framing:B}}var C="urun.videoOut.v2-ws";function Z(e){let t=e.stream(_);if(typeof t.messages!="function")throw new Error(`openSessionVideoOutLane: session.stream('${_}') has no messages() \u2014 the named-DATA stream consume seam (@urun-sh/core SessionStream.messages, contract \xA75) is required for the video OUT lane`);let n=new Set,o=new Set,r=new Set,i=d=>{for(let u of o)u(d)},a=!1,c=async()=>{for await(let d of t.messages()){if(!(d instanceof Uint8Array)){i(new Error(`openSessionVideoOutLane: "${_}" delivered a non-BINARY \xA75 payload (${typeof d}) \u2014 spec v1 records ride BINARY envelopes only`));continue}let u;try{u=x(d)}catch(l){i(l instanceof Error?l:new Error(String(l)));continue}for(let l of n)l(u)}for(let d of r)d()};return{codec:I,onOutputFrame:d=>(n.add(d),a||(a=!0,c().catch(u=>i(u instanceof Error?u:new Error(String(u))))),()=>n.delete(d)),onLaneError:d=>(o.add(d),()=>o.delete(d)),onEnd:d=>(r.add(d),()=>r.delete(d))}}function Ce(e){if(e.length%2!==0||/[^0-9a-fA-F]/.test(e))throw new Error(`consumeVideoOut: certHashes entry is not hex sha-256 (${JSON.stringify(e)})`);let t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}async function ee(e,t,n){let o=n??(typeof globalThis.WebTransport=="function"?(u,l)=>new globalThis.WebTransport(u,l):void 0);if(!o)throw new Error("consumeVideoOut: no WebTransport implementation \u2014 this platform has no globalThis.WebTransport; inject a connect factory (the third argument)");let r=o(e.url,{serverCertificateHashes:e.certHashes.map(u=>({algorithm:"sha-256",value:Ce(u)}))});await r.ready;let i=await r.createBidirectionalStream();await i.writable.getWriter().write((0,w.encodeWtControlFrame)({t:"hello",token:e.token,sessionId:e.sessionId}));let a=i.readable.getReader(),c=new w.WtControlDecoder,d=!1;for(;!d;){let{value:u,done:l}=await a.read();if(l)throw new Error("consumeVideoOut: gateway closed the control stream before hello-ack");if(u)for(let f of c.push(u)){if(f.t==="hello-ack"){d=!0;break}throw new Error(`consumeVideoOut: gateway rejected hello (got ${JSON.stringify(f.t)} before hello-ack)`)}}await(0,w.consumeWtDataStreams)(r.incomingUnidirectionalStreams,{onData:(u,l)=>{if(u===e.stream){if(l===w.STREAM_END){t.onEnd?.();return}if(!(l instanceof Uint8Array)){t.onLaneError(new Error(`consumeVideoOut: "${e.stream}" delivered a non-BINARY \xA75 payload (${typeof l}) \u2014 spec v1 records ride BINARY envelopes only`));return}try{t.onFrame(x(l))}catch(f){t.onLaneError(f instanceof Error?f:new Error(String(f)))}}},onLaneError:u=>t.onLaneError(u)})}var ne="/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent",H=1007,oe=1008,U=1011,re=1008,s=class extends Error{constructor(n,o=H){super(n);this.closeCode=o}closeCode},m=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null,L=["setup","clientContent","realtimeInput","toolResponse"];function ie(e){let t;try{t=JSON.parse(e)}catch{throw new s("client message is not valid JSON")}let n=m(t);if(!n)throw new s("client message must be a JSON object");let o=L.filter(c=>n[c]!==void 0),r=Object.keys(n).filter(c=>!L.includes(c));if(r.length>0)throw new s(`unknown client message field(s) ${JSON.stringify(r)} \u2014 expected exactly one of ${L.join(", ")}`);if(o.length!==1)throw new s(`client message must contain exactly one of ${L.join(", ")} (got ${o.length})`);let i=o[0],a=m(n[i]);if(!a)throw new s(`"${i}" must be a JSON object`);return{kind:i,[i]:a}}function se(e,t){if(typeof e=="string")return e;let n=m(e),o=n?n.parts:void 0;if(!Array.isArray(o))throw new s(`${t}: expected a Content with a parts array`);let r=[];for(let i of o){let a=m(i);if(a&&typeof a.text=="string"){r.push(a.text);continue}throw a&&(a.inlineData!==void 0||a.fileData!==void 0)?new s(`${t}: media parts (inlineData/fileData) are a declared follow-up slice (audio/video lanes over the proxy transport AudioBridge) \u2014 only text parts are supported in this slice`):a&&(a.functionCall!==void 0||a.functionResponse!==void 0)?new s(`${t}: functionCall/functionResponse parts are not valid here \u2014 the Live API exchanges tool traffic via the dedicated toolCall/toolResponse messages`):new s(`${t}: unsupported part ${JSON.stringify(i)}`)}return r.join(`
|
|
2
|
+
`)}var Le={manualActivity:!1,activityHandling:"START_OF_ACTIVITY_INTERRUPTS"},k="urun.videoOut";function ae(e){return{framing:C,codec:e}}function ue(e){let{seq:t,ptsUs:n,codec:o,key:r}=e.header;return{[k]:{v:1,seq:t,ptsUs:n,codec:o,key:r,data:Buffer.from(e.au).toString("base64")}}}var Ue={inputAudioTranscription:"setup.inputAudioTranscription is part of the declared audio follow-up slice",outputAudioTranscription:"setup.outputAudioTranscription is part of the declared audio follow-up slice"},De=["model","generationConfig","systemInstruction","tools","realtimeInputConfig","sessionResumption",k],te=["START_OF_ACTIVITY_INTERRUPTS","NO_INTERRUPTION"];function Ve(e){let t=m(e);if(!t)throw new s("setup.realtimeInputConfig must be an object");for(let r of Object.keys(t))if(!(r==="automaticActivityDetection"||r==="activityHandling"))throw new s(r==="turnCoverage"?"realtimeInputConfig.turnCoverage is part of the declared audio follow-up slice":`unsupported realtimeInputConfig field "${r}"`);let n=m(t.automaticActivityDetection);if(t.automaticActivityDetection!==void 0&&!n)throw new s("realtimeInputConfig.automaticActivityDetection must be an object");for(let r of Object.keys(n??{}))if(r!=="disabled")throw new s(`automaticActivityDetection.${r} tunes AUTOMATIC (server-side) activity detection \u2014 the declared platform follow-up (serve turn_detection events over the session stream lane); only "disabled: true" (manual activity mode) is supported in this slice`);if(n?.disabled!==!0)throw new s("automatic (server-side) activity detection is the declared platform follow-up (serve turn_detection turn_start/turn_end events over the session stream lane, not proxy DSP) \u2014 set realtimeInputConfig.automaticActivityDetection.disabled: true for manual activity mode");let o="START_OF_ACTIVITY_INTERRUPTS";if(t.activityHandling!==void 0){if(!te.includes(t.activityHandling))throw new s(`unsupported activityHandling ${JSON.stringify(t.activityHandling)} \u2014 expected one of ${te.join(", ")}`);o=t.activityHandling}return{manualActivity:!0,activityHandling:o}}var Me=["temperature","maxOutputTokens","responseModalities"];function de(e){for(let[f,p]of Object.entries(Ue))if(e[f]!==void 0)throw new s(p);for(let f of Object.keys(e))if(!De.includes(f))throw new s(`unsupported setup field "${f}"`);if(typeof e.model!="string"||e.model.length===0)throw new s('setup.model is required (format "models/{model}")');let t=e.model.replace(/^models\//,""),n,o,r=!1,i=m(e.generationConfig);if(e.generationConfig!==void 0&&!i)throw new s("setup.generationConfig must be an object");if(i){for(let f of Object.keys(i))if(!Me.includes(f))throw new s(`unsupported generationConfig field "${f}"`);if(i.temperature!==void 0){if(typeof i.temperature!="number")throw new s("generationConfig.temperature must be a number");n=i.temperature}if(i.maxOutputTokens!==void 0){if(typeof i.maxOutputTokens!="number")throw new s("generationConfig.maxOutputTokens must be a number");o=i.maxOutputTokens}if(i.responseModalities!==void 0){let f=Array.isArray(i.responseModalities)?i.responseModalities:[i.responseModalities];for(let p of f){let g=String(p).toUpperCase();if(g==="AUDIO"){r=!0;continue}if(g!=="TEXT")throw new s(`responseModalities ${JSON.stringify(p)} is not supported \u2014 this surface speaks TEXT and AUDIO (audio-out rides the native AudioBridge 'audio' lane)`)}}}let a=[];e.systemInstruction!==void 0&&a.push({role:"system",content:se(e.systemInstruction,"setup.systemInstruction")});let c;if(e.tools!==void 0){if(!Array.isArray(e.tools))throw new s("setup.tools must be an array");c=[];for(let f of e.tools){let p=m(f);if(!p)throw new s("setup.tools entries must be objects");for(let g of Object.keys(p))if(g!=="functionDeclarations")throw new s(`unsupported tool "${g}" \u2014 this slice translates functionDeclarations only (no googleSearch/codeExecution)`);if(!Array.isArray(p.functionDeclarations))throw new s("tool.functionDeclarations must be an array");for(let g of p.functionDeclarations){let h=m(g);if(!h||typeof h.name!="string")throw new s("functionDeclarations entries require a string name");c.push({type:"function",name:h.name,description:h.description,parameters:h.parameters})}}c.length===0&&(c=void 0)}let d={enabled:!1,handle:null};if(e.sessionResumption!==void 0){let f=m(e.sessionResumption);if(!f)throw new s("setup.sessionResumption must be an object (SessionResumptionConfig)");for(let p of Object.keys(f))if(p!=="handle")throw new s(`unsupported sessionResumption field "${p}" \u2014 this lane implements SessionResumptionConfig.handle only`);if(f.handle!==void 0&&(typeof f.handle!="string"||f.handle.length===0))throw new s("sessionResumption.handle must be a non-empty string when present");d={enabled:!0,handle:typeof f.handle=="string"?f.handle:null}}let u=e.realtimeInputConfig===void 0?Le:Ve(e.realtimeInputConfig),l=!1;if(e[k]!==void 0){if(!m(e[k]))throw new s(`setup["${k}"] must be an object (the v1 opt-in is {})`);l=!0}return{model:t,systemItems:a,tools:c,temperature:n,maxOutputTokens:o,audioModality:r,activity:u,sessionResumption:d,videoOut:l}}function ce(e){return{sessionResumptionUpdate:{newHandle:e,resumable:!0}}}function le(e){let t=Math.max(0,e??0)/1e3;return{goAway:{timeLeft:`${Math.round(t*1e3)/1e3}s`}}}function fe(e){for(let o of Object.keys(e))if(o!=="turns"&&o!=="turnComplete")throw new s(`unsupported clientContent field "${o}"`);let t=e.turns===void 0?[]:e.turns;if(!Array.isArray(t))throw new s("clientContent.turns must be an array");let n=[];for(let o of t){let r=m(o);if(!r)throw new s("clientContent.turns entries must be Content objects");let i=r.role===void 0?"user":String(r.role).toLowerCase();if(i!=="user"&&i!=="model")throw new s(`clientContent turn role must be "user" or "model" (got ${JSON.stringify(r.role)})`);n.push({role:i==="model"?"assistant":"user",content:se(r,"clientContent.turns")})}return{items:n,turnComplete:e.turnComplete===!0}}var b=16e3,D=24e3,F=`audio/pcm;rate=${D}`,pe=Buffer.alloc(960).toString("base64");function j(e,t,n){if(t===n)return e;let o=Math.floor(e.length*n/t),r=new Int16Array(o),i=t/n,a=e.length-1;for(let c=0;c<o;c++){let d=c*i,u=Math.floor(d);if(u>=a){r[c]=e[a];continue}let l=d-u;r[c]=Math.round(e[u]+(e[u+1]-e[u])*l)}return r}function Ne(e){let t=m(e);if(!t)throw new s("realtimeInput.video must be a Blob object {mimeType, data}");if(typeof t.mimeType!="string"||!/^image\/jpeg\s*(;|$)/.test(t.mimeType))throw new s(`realtimeInput.video.mimeType must be image/jpeg (the Live video input stream is individual JPEG frames), got ${JSON.stringify(t.mimeType)}`);if(typeof t.data!="string"||t.data.length===0)throw new s("realtimeInput.video.data must be non-empty base64");let n=Buffer.from(t.data,"base64");if(n.length<3||n[0]!==255||n[1]!==216)throw new s("realtimeInput.video.data does not decode to a JPEG frame (missing FF D8 SOI marker)");return new Uint8Array(n)}function Pe(e){let t=m(e);if(!t)throw new s("realtimeInput.audio must be a Blob object {mimeType, data}");if(typeof t.mimeType!="string"||!/^audio\/pcm\s*(;|$)/.test(t.mimeType))throw new s(`realtimeInput.audio.mimeType must be audio/pcm (16-bit LE PCM @16kHz mono per the Live spec), got ${JSON.stringify(t.mimeType)}`);let n=/;\s*rate=(\d+)/.exec(t.mimeType);if(n&&Number(n[1])!==b)throw new s(`realtimeInput.audio.mimeType declares rate=${n[1]} \u2014 the Live spec input format is ${b} Hz (audio/pcm;rate=${b})`);if(typeof t.data!="string"||t.data.length===0)throw new s("realtimeInput.audio.data must be non-empty base64");let o=Buffer.from(t.data,"base64");if(o.length===0||o.length%2!==0)throw new s(`realtimeInput.audio.data must decode to whole 16-bit samples (got ${o.length} bytes \u2014 not even)`);let r=new Int16Array(o.length/2);for(let a=0;a<r.length;a++)r[a]=o.readInt16LE(a*2);let i=j(r,b,D);return Buffer.from(i.buffer,i.byteOffset,i.byteLength).toString("base64")}function me(e){if(e.mediaChunks!==void 0)throw new s('realtimeInput.mediaChunks is deprecated by the Live API \u2014 send the audio stream via realtimeInput.audio ({mimeType:"audio/pcm;rate=16000", data}) instead');if(e.activityStart!==void 0||e.activityEnd!==void 0){if(Object.keys(e).length!==1||e.activityStart!==void 0&&e.activityEnd!==void 0)throw new s("realtimeInput must carry exactly one field when signaling activity (activityStart XOR activityEnd, nothing else)");let r=e.activityStart!==void 0?"activityStart":"activityEnd",i=m(e[r]);if(!i||Object.keys(i).length!==0)throw new s(`realtimeInput.${r} must be an empty object (ActivityStart/ActivityEnd are bare markers)`);return{kind:r}}let t=["text","audio","audioStreamEnd","video"];for(let o of Object.keys(e))if(!t.includes(o))throw new s(`unsupported realtimeInput field "${o}"`);let n=t.filter(o=>e[o]!==void 0);if(n.length!==1)throw new s(`realtimeInput must carry exactly one of ${t.join(", ")} (got ${n.length})`);if(e.audio!==void 0)return{kind:"audio",base64Pcm24k:Pe(e.audio)};if(e.video!==void 0)return{kind:"video",jpegFrame:Ne(e.video)};if(e.audioStreamEnd!==void 0){if(e.audioStreamEnd!==!0)throw new s("realtimeInput.audioStreamEnd must be true when present");return{kind:"audioStreamEnd"}}if(typeof e.text!="string"||e.text.length===0)throw new s("realtimeInput.text must be a non-empty string");return{kind:"text",text:e.text}}function ge(e){for(let t of Object.keys(e))if(t!=="functionResponses")throw new s(`unsupported toolResponse field "${t}"`);if(!Array.isArray(e.functionResponses)||e.functionResponses.length===0)throw new s("toolResponse.functionResponses must be a non-empty array");return e.functionResponses.map(t=>{let n=m(t);if(!n||typeof n.id!="string"||n.id.length===0)throw new s("functionResponses entries require the string id matched from the toolCall");return{type:"function_call_output",call_id:n.id,output:JSON.stringify(n.response??null)}})}function ye(e){return e.type!=="response.output_text.delta"||typeof e.delta!="string"?null:{serverContent:{modelTurn:{role:"model",parts:[{text:e.delta}]}}}}function we(e){return{serverContent:{modelTurn:{role:"model",parts:[{inlineData:{mimeType:F,data:e}}]}}}}function he(e){let t=m(e)??{},n=Array.isArray(t.output)?t.output:[],o=[],r=[],i=typeof t.output_text=="string"?t.output_text:"";if(!i)for(let u of n){let l=m(u);if(!(l?.type!=="message"||!Array.isArray(l.content)))for(let f of l.content){let p=m(f);p?.type==="output_text"&&typeof p.text=="string"&&(i+=p.text)}}i&&r.push({role:"assistant",content:i});for(let u of n){let l=m(u);if(l?.type!=="function_call")continue;if(typeof l.call_id!="string"||typeof l.name!="string")throw new s(`upstream function_call item is missing call_id/name: ${JSON.stringify(u)}`,U);let f=typeof l.arguments=="string"&&l.arguments.length>0?l.arguments:"{}",p;try{p=JSON.parse(f)}catch{throw new s(`upstream function_call arguments are not valid JSON: ${f}`,U)}o.push({id:l.call_id,name:l.name,args:p}),r.push({type:"function_call",call_id:l.call_id,name:l.name,arguments:f})}let a=[];o.length>0&&a.push({toolCall:{functionCalls:o}}),a.push({serverContent:{generationComplete:!0}});let c=m(t.usage),d={serverContent:{turnComplete:!0}};if(c){let u={};typeof c.input_tokens=="number"&&(u.promptTokenCount=c.input_tokens),typeof c.output_tokens=="number"&&(u.responseTokenCount=c.output_tokens),typeof c.total_tokens=="number"&&(u.totalTokenCount=c.total_tokens),Object.keys(u).length>0&&(d.usageMetadata=u)}return a.push(d),{messages:a,assistantItems:r}}function V(e,t,n,o){let r=e.response??{},i={request_id:n,consumer_id:o,stream:!0,kind:"chat",messages:t};return typeof r.instructions=="string"&&(i.instructions=r.instructions),Array.isArray(r.modalities)&&(i.modalities=r.modalities),typeof r.temperature=="number"&&(i.temperature=r.temperature),typeof r.max_output_tokens=="number"&&(i.max_output_tokens=r.max_output_tokens),r.tools!==void 0&&(i.tools=r.tools),i}function M(e,t,n){let o={request_id:t,consumer_id:n,stream:!!e.stream,kind:"responses",input:e.input};return e.model&&(o.model=e.model),e.tools!==void 0&&(o.tools=e.tools),e.tool_choice!==void 0&&(o.tool_choice=e.tool_choice),typeof e.temperature=="number"&&(o.temperature=e.temperature),typeof e.max_output_tokens=="number"&&(o.max_output_tokens=e.max_output_tokens),typeof e.top_p=="number"&&(o.top_p=e.top_p),Array.isArray(e.stop)&&e.stop.length>0&&(o.stop=e.stop),typeof e.reasoning_effort=="string"&&(o.reasoning_effort=e.reasoning_effort),typeof e.instructions=="string"&&(o.instructions=e.instructions),e.chat_template_kwargs!==void 0&&(o.chat_template_kwargs=e.chat_template_kwargs),e.response_format!==void 0&&(o.response_format=e.response_format),typeof e.voice=="string"&&(o.voice=e.voice),o}function ke(e){if(e instanceof Error)return{type:"error",error:{type:"urun_error",code:e.name||null,message:e.message}};if(e&&typeof e=="object"&&e.t==="error"){let t=e,n=t.body??{},o=n.error,r=o?.message??n.message??`unreadable serve error body: ${JSON.stringify(t.body??null)}`;return{type:"error",error:{type:o?.type??"urun_error",code:t.code??o?.code??null,message:r}}}return{type:"error",error:{type:"urun_error",code:null,message:String(e)}}}var $e="llm-resp";async function*A(e,t){let n=`${$e}:${t}`,o=`resp_${t}`;yield{type:"response.created",response:{id:o,status:"in_progress"}};let r=new Map;try{for await(let i of e.stream(n).messages()){let a=i;if(a.t==="delta"){if(typeof a.delta=="string"&&(yield{type:"response.output_text.delta",item_id:o,delta:a.delta}),typeof a.reasoning=="string"&&(yield{type:"response.reasoning_text.delta",item_id:o,delta:a.reasoning}),Array.isArray(a.tool_calls))for(let c of a.tool_calls){let d=typeof c.index=="number"?c.index:0,u=r.get(d)??{};c.id&&(u.id=c.id),c.function?.name&&(u.name=c.function.name),r.set(d,u),yield{type:"response.function_call_arguments.delta",item_id:`fc_${t}_${d}`,tool_index:d,call_id:u.id,name:u.name,delta:c.function?.arguments??""}}}else if(a.t==="response"){yield{type:"response.completed",response:{id:o,status:"completed",...a.body}};return}else if(a.t==="error"){yield ke(a);return}}}finally{try{e.doc("llm").set({requests:{[t]:null}})}catch{}}}var P=class e{constructor(t,n=e.DEFAULT_DOC_SYNC_GATE_TIMEOUT_MS){this.session=t;this.docSyncTimeoutMs=n;this.sessionTag=t.sessionId??globalThis.crypto.randomUUID()}session;docSyncTimeoutMs;sessionTag;static DEFAULT_DOC_SYNC_GATE_TIMEOUT_MS=15e3;get consumerId(){return this.session.consumerId}async ensureDocSynced(){let t=this.session.doc("llm");if(t.synced===!0||typeof t.onSynced!="function")return;let n;await new Promise((r,i)=>{let a=t.onSynced(()=>{clearTimeout(n),r()});n=setTimeout(()=>{a(),i(new Error(`[urun] llm doc plane never synced within ${this.docSyncTimeoutMs}ms \u2014 the request envelope write is withheld rather than raced into a possibly-lost pre-sync write (resumed-attach first-write-lost, prod-usw2 2026-09-23)`))},this.docSyncTimeoutMs)})}write(t){t.session_tag=this.sessionTag,this.session.doc("llm").set({requests:{[t.request_id]:{payload:t,consumer_id:t.consumer_id,stream:t.stream}}})}sendResponses(t,n){return this.writeGated(n,()=>{let o=M(t,n,this.consumerId);return this.write(o),A(this.session,n)})}sendResponseCreate(t,n,o){return this.writeGated(o,()=>{let r=V(t,n,o,this.consumerId);return this.write(r),A(this.session,o)})}async writeGated(t,n){try{await this.ensureDocSynced()}catch(o){throw new Error(`[urun] responses dial ${t} aborted before its envelope write: ${o instanceof Error?o.message:String(o)}`)}return n()}};0&&(module.exports={AudioBridge,CLOSE_PROTOCOL,CLOSE_SESSION_GONE,CLOSE_UNKNOWN_MODEL,CLOSE_UPSTREAM,GEMINI_AUDIO_IN_RATE,GEMINI_AUDIO_OUT_MIME,GEMINI_AUDIO_OUT_RATE,GEMINI_LIVE_PATH,GeminiLiveError,NATIVE_AUDIO_SAMPLE_RATE,OUTBOUND_AUDIO_FLUSH_B64,RT_VIDEO_IN_STREAM,RT_VIDEO_OUT_STREAM,SdkTransport,VIDEO_FRAME_MESSAGE_BUDGET,VIDEO_OUT_DEFAULT_CODEC,VIDEO_OUT_FRAMING,VIDEO_OUT_SETUP_KEY,VIDEO_OUT_WS_FRAMING,consumeVideoOut,decodeResponsesLane,decodeVideoOutRecord,enableSessionAudio,enableSessionVideo,encodeVideoOutRecord,goAwayMsg,negotiateSessionVideoOutQuic,nodeAudioBackend,openSessionVideoOutLane,parseClientMessage,resamplePcm16,responseCreateToEnvelope,responsesCreateToEnvelope,serverContentOfAudio,serverContentOfDelta,sessionResumptionUpdateMsg,translateClientContent,translateRealtimeInput,translateSetup,translateToolResponse,turnEndOfCompleted,videoOutAck,videoOutChunkMsg,weriftAudioBackend});
|
package/dist/gemini-live.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export { A as ActivityConfig, a as ActivityHandling, C as CLOSE_PROTOCOL, b as CLOSE_SESSION_GONE, c as CLOSE_UNKNOWN_MODEL, d as CLOSE_UPSTREAM, e as ClientMessage, G as GEMINI_AUDIO_IN_RATE, f as GEMINI_AUDIO_OUT_MIME, g as GEMINI_AUDIO_OUT_RATE, h as GEMINI_LIVE_PATH, i as GeminiLiveError, L as LiveSessionConfig, O as OUTBOUND_AUDIO_FLUSH_B64, R as RealtimeInputAction, T as TurnEnd, V as VIDEO_OUT_SETUP_KEY, j as goAwayMsg, p as parseClientMessage, r as resamplePcm16, s as serverContentOfAudio, k as serverContentOfDelta, l as sessionResumptionUpdateMsg, t as translateClientContent, m as translateRealtimeInput, n as translateSetup, o as translateToolResponse, q as turnEndOfCompleted, v as videoOutAck, u as videoOutChunkMsg } from './translator-
|
|
2
|
-
import { b as UrunSessionLike } from './types-
|
|
3
|
-
export { L as LaneMessage, a as LaneToolCallDelta, U as UrunDocLike, c as UrunStreamLike } from './types-
|
|
4
|
-
export { A as AudioBackend, a as AudioBridge, b as AudioSink, c as AudioSource, N as NATIVE_AUDIO_SAMPLE_RATE, R as RT_VIDEO_IN_STREAM, d as RT_VIDEO_OUT_STREAM, V as VIDEO_FRAME_MESSAGE_BUDGET, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, h as VideoFrameLane, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutTransportSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, r as enableSessionAudio, s as enableSessionVideo, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-
|
|
1
|
+
export { A as ActivityConfig, a as ActivityHandling, C as CLOSE_PROTOCOL, b as CLOSE_SESSION_GONE, c as CLOSE_UNKNOWN_MODEL, d as CLOSE_UPSTREAM, e as ClientMessage, G as GEMINI_AUDIO_IN_RATE, f as GEMINI_AUDIO_OUT_MIME, g as GEMINI_AUDIO_OUT_RATE, h as GEMINI_LIVE_PATH, i as GeminiLiveError, L as LiveSessionConfig, O as OUTBOUND_AUDIO_FLUSH_B64, R as RealtimeInputAction, T as TurnEnd, V as VIDEO_OUT_SETUP_KEY, j as goAwayMsg, p as parseClientMessage, r as resamplePcm16, s as serverContentOfAudio, k as serverContentOfDelta, l as sessionResumptionUpdateMsg, t as translateClientContent, m as translateRealtimeInput, n as translateSetup, o as translateToolResponse, q as turnEndOfCompleted, v as videoOutAck, u as videoOutChunkMsg } from './translator-CO8W_hmJ.cjs';
|
|
2
|
+
import { b as UrunSessionLike } from './types-CHPtJx6d.cjs';
|
|
3
|
+
export { L as LaneMessage, a as LaneToolCallDelta, U as UrunDocLike, c as UrunStreamLike } from './types-CHPtJx6d.cjs';
|
|
4
|
+
export { A as AudioBackend, a as AudioBridge, b as AudioSink, c as AudioSource, N as NATIVE_AUDIO_SAMPLE_RATE, R as RT_VIDEO_IN_STREAM, d as RT_VIDEO_OUT_STREAM, V as VIDEO_FRAME_MESSAGE_BUDGET, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, h as VideoFrameLane, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutTransportSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, r as enableSessionAudio, s as enableSessionVideo, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-BsuLqlID.cjs';
|
|
5
5
|
|
|
6
6
|
declare class SdkTransport {
|
|
7
7
|
private readonly session;
|
|
8
|
+
/** Test seam for the gate deadline; never an env knob or config surface. */
|
|
9
|
+
private readonly docSyncTimeoutMs;
|
|
8
10
|
/**
|
|
9
11
|
* Session-affinity tag (urun-python #1556): every envelope this transport
|
|
10
12
|
* writes carries the SAME stable tag, so the serve engine adapter can
|
|
@@ -14,13 +16,43 @@ declare class SdkTransport {
|
|
|
14
16
|
* persistent session, so a per-transport tag identifies the session too.
|
|
15
17
|
*/
|
|
16
18
|
private readonly sessionTag;
|
|
17
|
-
|
|
19
|
+
/** The shipped gate deadline — the only production value (test seam overrides it). */
|
|
20
|
+
private static readonly DEFAULT_DOC_SYNC_GATE_TIMEOUT_MS;
|
|
21
|
+
constructor(session: UrunSessionLike,
|
|
22
|
+
/** Test seam for the gate deadline; never an env knob or config surface. */
|
|
23
|
+
docSyncTimeoutMs?: number);
|
|
18
24
|
get consumerId(): string;
|
|
25
|
+
/**
|
|
26
|
+
* THE FIRST-WRITE-LOST GATE (resumed-attach, prod-usw2 2026-09-23): a turn's
|
|
27
|
+
* request envelope is the llm doc's FIRST write after a cold (re-)attach, and
|
|
28
|
+
* the dial's `whenLive` gate resolves off the SIGNALING status frame — which
|
|
29
|
+
* routinely lands while the yjs doc provider is still dialing its room. A
|
|
30
|
+
* local write applied while the provider has no socket is relayed ONLY through
|
|
31
|
+
* the initial-sync diff exchange, and on a resumed session that exchange races
|
|
32
|
+
* the session-server's S3 hydration barrier. Observed live (local proxy against
|
|
33
|
+
* prod, dial resumed the long-parked shared-org session): the 396-byte envelope
|
|
34
|
+
* applied at `wsconnected=false synced=false` NEVER reached the room — the
|
|
35
|
+
* serve runtime drained the doc for the caller's whole timeout budget and
|
|
36
|
+
* never saw the request (`drain: 2 in doc, 0 pending`, no change events), while
|
|
37
|
+
* the client's provider reported `synced`. The write is silently stranded.
|
|
38
|
+
*
|
|
39
|
+
* So every request-envelope write first holds for the doc plane's OWN
|
|
40
|
+
* readiness — `synced`, the provider's level-triggered initial-sync bar.
|
|
41
|
+
* Post-sync writes ride the connected socket directly and are delivered.
|
|
42
|
+
* Bounded and loud on deadline: the caller (rehome's one re-dial, then the
|
|
43
|
+
* lane's loud 502) owns the verdict — never a silent loss. A session double
|
|
44
|
+
* that exposes no `onSynced` surface cannot be gated and is skipped honestly
|
|
45
|
+
* (same structural-seam contract as `onConnectionState`).
|
|
46
|
+
*/
|
|
47
|
+
/** Hold until the llm doc plane has completed its first sync (bounded, loud). */
|
|
48
|
+
private ensureDocSynced;
|
|
19
49
|
private write;
|
|
20
50
|
sendResponses(params: {
|
|
21
51
|
model?: string;
|
|
22
52
|
input: unknown;
|
|
23
53
|
stream?: boolean;
|
|
54
|
+
/** Per-request system instructions — forwarded verbatim to the serve envelope. */
|
|
55
|
+
instructions?: string;
|
|
24
56
|
tools?: unknown;
|
|
25
57
|
tool_choice?: unknown;
|
|
26
58
|
temperature?: number;
|
|
@@ -29,14 +61,29 @@ declare class SdkTransport {
|
|
|
29
61
|
max_output_tokens?: number;
|
|
30
62
|
reasoning_effort?: string;
|
|
31
63
|
chat_template_kwargs?: Record<string, unknown>;
|
|
32
|
-
|
|
64
|
+
/** ENG-310 structured output: forwarded verbatim; the serve runtime validates. */
|
|
65
|
+
response_format?: unknown;
|
|
66
|
+
/**
|
|
67
|
+
* ENG-331 speech lane: the per-request TTS voice, forwarded verbatim
|
|
68
|
+
* on the serve envelope (encode.ts `ServeEnvelope.voice`); absent →
|
|
69
|
+
* key absent — the engine's catalog-configured default voice applies.
|
|
70
|
+
*/
|
|
71
|
+
voice?: string;
|
|
72
|
+
}, requestId: string): Promise<AsyncIterable<unknown>>;
|
|
33
73
|
sendResponseCreate(ev: {
|
|
34
74
|
type: 'response.create';
|
|
35
75
|
response?: Record<string, unknown>;
|
|
36
76
|
}, conversation: Array<{
|
|
37
77
|
role: string;
|
|
38
78
|
content: unknown;
|
|
39
|
-
}>, requestId: string): AsyncIterable<unknown
|
|
79
|
+
}>, requestId: string): Promise<AsyncIterable<unknown>>;
|
|
80
|
+
/**
|
|
81
|
+
* Run the turn's write + lane subscribe behind {@link ensureDocSynced}. The
|
|
82
|
+
* gate is per-turn: the doc plane may have re-dialed since the last turn
|
|
83
|
+
* (resume / pod move), so every turn re-checks — `synced` is true the moment
|
|
84
|
+
* the provider is warm, so the steady-state turn pays only a property read.
|
|
85
|
+
*/
|
|
86
|
+
private writeGated;
|
|
40
87
|
}
|
|
41
88
|
|
|
42
89
|
/**
|
|
@@ -90,6 +137,18 @@ interface ServeEnvelope {
|
|
|
90
137
|
*/
|
|
91
138
|
reasoning_effort?: string;
|
|
92
139
|
chat_template_kwargs?: Record<string, unknown>;
|
|
140
|
+
/**
|
|
141
|
+
* OpenAI `response_format` — STRUCTURED OUTPUT (ENG-310). Forwarded VERBATIM
|
|
142
|
+
* to the serve envelope, where it becomes engine-native CONSTRAINED DECODING
|
|
143
|
+
* (vLLM `structured_outputs`, SGLang `json_schema`) — never a prompt-level
|
|
144
|
+
* "answer in JSON" hint. `unknown` on purpose: the serve runtime's
|
|
145
|
+
* `parse_request` is the ONE validator (it accepts both the Chat-Completions
|
|
146
|
+
* nested `json_schema` spelling and the Responses flat one, and rejects
|
|
147
|
+
* everything else with a typed 400), so the proxy passes the caller's value
|
|
148
|
+
* through instead of growing a second, drifting copy of those rules.
|
|
149
|
+
* Absent -> key absent: today's unconstrained request, byte for byte.
|
|
150
|
+
*/
|
|
151
|
+
response_format?: unknown;
|
|
93
152
|
/**
|
|
94
153
|
* Session-affinity tag (urun-python #1556, additive like `tools` in the
|
|
95
154
|
* #1557 lane pair): the stable identity of THIS persistent uRun session.
|
|
@@ -99,6 +158,15 @@ interface ServeEnvelope {
|
|
|
99
158
|
* absent -> the server treats the request as stateless, today's behavior.
|
|
100
159
|
*/
|
|
101
160
|
session_tag?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The speech lane's per-request TTS voice (ENG-331, additive like
|
|
163
|
+
* `instructions`): the speaker id a `tts`-task engine synthesizes under
|
|
164
|
+
* (qwen3 CustomVoice timbre, e.g. "Ryan"), applied through the engine's
|
|
165
|
+
* own per-speak-session override seam (`SpeakSessionConfig.voice` ->
|
|
166
|
+
* `set_voice`, urun-python tts_engine.py). Absent -> key absent: the
|
|
167
|
+
* engine's catalog-configured default voice, today's behavior.
|
|
168
|
+
*/
|
|
169
|
+
voice?: string;
|
|
102
170
|
}
|
|
103
171
|
/** Realtime: a response.create + the accumulated conversation turns → envelope. */
|
|
104
172
|
declare function responseCreateToEnvelope(ev: {
|
|
@@ -121,6 +189,10 @@ declare function responsesCreateToEnvelope(params: {
|
|
|
121
189
|
max_output_tokens?: number;
|
|
122
190
|
reasoning_effort?: string;
|
|
123
191
|
chat_template_kwargs?: Record<string, unknown>;
|
|
192
|
+
response_format?: unknown;
|
|
193
|
+
voice?: string;
|
|
194
|
+
/** Per-request system instructions (the realtime standing schema's only path to the serve envelope). */
|
|
195
|
+
instructions?: string;
|
|
124
196
|
}, requestId: string, consumerId: string): ServeEnvelope;
|
|
125
197
|
|
|
126
198
|
export { SdkTransport, type ServeEnvelope, UrunSessionLike, decodeResponsesLane, responseCreateToEnvelope, responsesCreateToEnvelope };
|
package/dist/gemini-live.d.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
export { A as ActivityConfig, a as ActivityHandling, C as CLOSE_PROTOCOL, b as CLOSE_SESSION_GONE, c as CLOSE_UNKNOWN_MODEL, d as CLOSE_UPSTREAM, e as ClientMessage, G as GEMINI_AUDIO_IN_RATE, f as GEMINI_AUDIO_OUT_MIME, g as GEMINI_AUDIO_OUT_RATE, h as GEMINI_LIVE_PATH, i as GeminiLiveError, L as LiveSessionConfig, O as OUTBOUND_AUDIO_FLUSH_B64, R as RealtimeInputAction, T as TurnEnd, V as VIDEO_OUT_SETUP_KEY, j as goAwayMsg, p as parseClientMessage, r as resamplePcm16, s as serverContentOfAudio, k as serverContentOfDelta, l as sessionResumptionUpdateMsg, t as translateClientContent, m as translateRealtimeInput, n as translateSetup, o as translateToolResponse, q as turnEndOfCompleted, v as videoOutAck, u as videoOutChunkMsg } from './translator-
|
|
2
|
-
import { b as UrunSessionLike } from './types-
|
|
3
|
-
export { L as LaneMessage, a as LaneToolCallDelta, U as UrunDocLike, c as UrunStreamLike } from './types-
|
|
4
|
-
export { A as AudioBackend, a as AudioBridge, b as AudioSink, c as AudioSource, N as NATIVE_AUDIO_SAMPLE_RATE, R as RT_VIDEO_IN_STREAM, d as RT_VIDEO_OUT_STREAM, V as VIDEO_FRAME_MESSAGE_BUDGET, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, h as VideoFrameLane, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutTransportSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, r as enableSessionAudio, s as enableSessionVideo, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-
|
|
1
|
+
export { A as ActivityConfig, a as ActivityHandling, C as CLOSE_PROTOCOL, b as CLOSE_SESSION_GONE, c as CLOSE_UNKNOWN_MODEL, d as CLOSE_UPSTREAM, e as ClientMessage, G as GEMINI_AUDIO_IN_RATE, f as GEMINI_AUDIO_OUT_MIME, g as GEMINI_AUDIO_OUT_RATE, h as GEMINI_LIVE_PATH, i as GeminiLiveError, L as LiveSessionConfig, O as OUTBOUND_AUDIO_FLUSH_B64, R as RealtimeInputAction, T as TurnEnd, V as VIDEO_OUT_SETUP_KEY, j as goAwayMsg, p as parseClientMessage, r as resamplePcm16, s as serverContentOfAudio, k as serverContentOfDelta, l as sessionResumptionUpdateMsg, t as translateClientContent, m as translateRealtimeInput, n as translateSetup, o as translateToolResponse, q as turnEndOfCompleted, v as videoOutAck, u as videoOutChunkMsg } from './translator-Ddd65sXR.js';
|
|
2
|
+
import { b as UrunSessionLike } from './types-CHPtJx6d.js';
|
|
3
|
+
export { L as LaneMessage, a as LaneToolCallDelta, U as UrunDocLike, c as UrunStreamLike } from './types-CHPtJx6d.js';
|
|
4
|
+
export { A as AudioBackend, a as AudioBridge, b as AudioSink, c as AudioSource, N as NATIVE_AUDIO_SAMPLE_RATE, R as RT_VIDEO_IN_STREAM, d as RT_VIDEO_OUT_STREAM, V as VIDEO_FRAME_MESSAGE_BUDGET, e as VIDEO_OUT_DEFAULT_CODEC, f as VIDEO_OUT_FRAMING, g as VIDEO_OUT_WS_FRAMING, h as VideoFrameLane, i as VideoOutEndpoint, j as VideoOutLane, k as VideoOutRecord, l as VideoOutRecordHeader, m as VideoOutTransportSink, n as VideoOutWtConnect, o as VideoOutWtSession, p as consumeVideoOut, q as decodeVideoOutRecord, r as enableSessionAudio, s as enableSessionVideo, t as encodeVideoOutRecord, u as negotiateSessionVideoOutQuic, v as nodeAudioBackend, w as openSessionVideoOutLane, x as weriftAudioBackend } from './video-out-Cawtm7SF.js';
|
|
5
5
|
|
|
6
6
|
declare class SdkTransport {
|
|
7
7
|
private readonly session;
|
|
8
8
|
|
|
9
|
+
private readonly docSyncTimeoutMs;
|
|
10
|
+
|
|
9
11
|
private readonly sessionTag;
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
private static readonly DEFAULT_DOC_SYNC_GATE_TIMEOUT_MS;
|
|
14
|
+
constructor(session: UrunSessionLike,
|
|
15
|
+
|
|
16
|
+
docSyncTimeoutMs?: number);
|
|
11
17
|
get consumerId(): string;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
private ensureDocSynced;
|
|
12
21
|
private write;
|
|
13
22
|
sendResponses(params: {
|
|
14
23
|
model?: string;
|
|
15
24
|
input: unknown;
|
|
16
25
|
stream?: boolean;
|
|
26
|
+
|
|
27
|
+
instructions?: string;
|
|
17
28
|
tools?: unknown;
|
|
18
29
|
tool_choice?: unknown;
|
|
19
30
|
temperature?: number;
|
|
@@ -22,14 +33,20 @@ declare class SdkTransport {
|
|
|
22
33
|
max_output_tokens?: number;
|
|
23
34
|
reasoning_effort?: string;
|
|
24
35
|
chat_template_kwargs?: Record<string, unknown>;
|
|
25
|
-
|
|
36
|
+
|
|
37
|
+
response_format?: unknown;
|
|
38
|
+
|
|
39
|
+
voice?: string;
|
|
40
|
+
}, requestId: string): Promise<AsyncIterable<unknown>>;
|
|
26
41
|
sendResponseCreate(ev: {
|
|
27
42
|
type: 'response.create';
|
|
28
43
|
response?: Record<string, unknown>;
|
|
29
44
|
}, conversation: Array<{
|
|
30
45
|
role: string;
|
|
31
46
|
content: unknown;
|
|
32
|
-
}>, requestId: string): AsyncIterable<unknown
|
|
47
|
+
}>, requestId: string): Promise<AsyncIterable<unknown>>;
|
|
48
|
+
|
|
49
|
+
private writeGated;
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
declare function decodeResponsesLane(session: UrunSessionLike, requestId: string): AsyncIterable<unknown>;
|
|
@@ -57,7 +74,11 @@ interface ServeEnvelope {
|
|
|
57
74
|
reasoning_effort?: string;
|
|
58
75
|
chat_template_kwargs?: Record<string, unknown>;
|
|
59
76
|
|
|
77
|
+
response_format?: unknown;
|
|
78
|
+
|
|
60
79
|
session_tag?: string;
|
|
80
|
+
|
|
81
|
+
voice?: string;
|
|
61
82
|
}
|
|
62
83
|
|
|
63
84
|
declare function responseCreateToEnvelope(ev: {
|
|
@@ -80,6 +101,10 @@ declare function responsesCreateToEnvelope(params: {
|
|
|
80
101
|
max_output_tokens?: number;
|
|
81
102
|
reasoning_effort?: string;
|
|
82
103
|
chat_template_kwargs?: Record<string, unknown>;
|
|
104
|
+
response_format?: unknown;
|
|
105
|
+
voice?: string;
|
|
106
|
+
|
|
107
|
+
instructions?: string;
|
|
83
108
|
}, requestId: string, consumerId: string): ServeEnvelope;
|
|
84
109
|
|
|
85
110
|
export { SdkTransport, type ServeEnvelope, UrunSessionLike, decodeResponsesLane, responseCreateToEnvelope, responsesCreateToEnvelope };
|
package/dist/gemini-live.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as c,b as C,c as L,d as M,e as R,f as D,g as f,h as N,i as v,j as g,k as x,l as k,m as y,n as G,o as B,p as F,q as P,r as H,s as W,t as b,u as w,v as K,w as h,x as Q}from"./chunk-
|
|
1
|
+
import{a as c,b as C,c as L,d as M,e as R,f as D,g as f,h as N,i as v,j as g,k as x,l as k,m as y,n as G,o as B,p as F,q as P,r as H,s as W,t as b,u as w,v as K,w as h,x as Q}from"./chunk-3JWYIKHM.js";import{a as i,b as s,c as O,d,e as a,f as E,g as _,h as p,i as u,j as A,k as S,l as I,m as T,n as l,o as m,p as U,q as V}from"./chunk-6M5JK4YC.js";import{a as o,b as t,d as n,e as r}from"./chunk-QTVTCMJU.js";import{c as e}from"./chunk-YSFSRI3D.js";e();export{s as AudioBridge,C as CLOSE_PROTOCOL,R as CLOSE_SESSION_GONE,L as CLOSE_UNKNOWN_MODEL,M as CLOSE_UPSTREAM,B as GEMINI_AUDIO_IN_RATE,P as GEMINI_AUDIO_OUT_MIME,F as GEMINI_AUDIO_OUT_RATE,c as GEMINI_LIVE_PATH,D as GeminiLiveError,i as NATIVE_AUDIO_SAMPLE_RATE,H as OUTBOUND_AUDIO_FLUSH_B64,d as RT_VIDEO_IN_STREAM,u as RT_VIDEO_OUT_STREAM,r as SdkTransport,a as VIDEO_FRAME_MESSAGE_BUDGET,S as VIDEO_OUT_DEFAULT_CODEC,A as VIDEO_OUT_FRAMING,N as VIDEO_OUT_SETUP_KEY,m as VIDEO_OUT_WS_FRAMING,V as consumeVideoOut,n as decodeResponsesLane,T as decodeVideoOutRecord,O as enableSessionAudio,E as enableSessionVideo,I as encodeVideoOutRecord,y as goAwayMsg,l as negotiateSessionVideoOutQuic,p as nodeAudioBackend,U as openSessionVideoOutLane,f as parseClientMessage,W as resamplePcm16,o as responseCreateToEnvelope,t as responsesCreateToEnvelope,h as serverContentOfAudio,K as serverContentOfDelta,k as sessionResumptionUpdateMsg,G as translateClientContent,b as translateRealtimeInput,x as translateSetup,w as translateToolResponse,Q as turnEndOfCompleted,v as videoOutAck,g as videoOutChunkMsg,_ as weriftAudioBackend};
|