@staylift-tech/conv-widget 0.0.11 → 0.0.12

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.
@@ -6,7 +6,7 @@ var appGlobals = require('./app-globals-V2Kpy_OQ.js');
6
6
  const defineCustomElements = async (win, options) => {
7
7
  if (typeof window === 'undefined') return undefined;
8
8
  await appGlobals.globalScripts();
9
- return index.bootstrapLazy([["staylift-orb.cjs",[[1,"staylift-orb",{"inputVolume":[2,"input-volume"],"outputVolume":[2,"output-volume"],"isActive":[4,"is-active"],"primaryColor":[1,"primary-color"],"size":[8],"animationFrame":[32]}]]],["staylift-widget.cjs",[[1,"staylift-widget",{"agentId":[1,"agent-id"],"textAgentId":[1,"text-agent-id"],"voiceAgentId":[1,"voice-agent-id"],"positionX":[1,"position-x"],"positionY":[1,"position-y"],"variant":[1],"mode":[1],"primaryColor":[1,"primary-color"],"brandName":[1,"brand-name"],"language":[1],"autoExpand":[4,"auto-expand"],"showBranding":[4,"show-branding"],"onlyText":[4,"only-text"],"avatarUrl":[1,"avatar-url"],"fabPrompt":[1,"fab-prompt"],"fabButtonText":[1,"fab-button-text"],"status":[32],"isExpanded":[32],"termsAccepted":[32],"errorMessage":[32],"inputVolume":[32],"outputVolume":[32],"messages":[32],"inputText":[32],"copiedIndex":[32],"selectedMode":[32],"startConversation":[64],"endConversation":[64],"getStatus":[64],"sendMessage":[64]}]]]], options);
9
+ return index.bootstrapLazy([["staylift-orb.cjs",[[1,"staylift-orb",{"inputVolume":[2,"input-volume"],"outputVolume":[2,"output-volume"],"isActive":[4,"is-active"],"primaryColor":[1,"primary-color"],"size":[8],"animationFrame":[32]}]]],["staylift-widget.cjs",[[1,"staylift-widget",{"agentId":[1,"agent-id"],"textAgentId":[1,"text-agent-id"],"voiceAgentId":[1,"voice-agent-id"],"positionX":[1,"position-x"],"positionY":[1,"position-y"],"variant":[1],"mode":[1],"primaryColor":[1,"primary-color"],"brandName":[1,"brand-name"],"language":[1],"autoExpand":[4,"auto-expand"],"showBranding":[4,"show-branding"],"onlyText":[4,"only-text"],"avatarUrl":[1,"avatar-url"],"fabPrompt":[1,"fab-prompt"],"fabButtonText":[1,"fab-button-text"],"status":[32],"isExpanded":[32],"termsAccepted":[32],"errorMessage":[32],"inputVolume":[32],"outputVolume":[32],"messages":[32],"inputText":[32],"copiedIndex":[32],"selectedMode":[32],"offerIndexes":[32],"pinnedOffers":[32],"startConversation":[64],"endConversation":[64],"getStatus":[64],"sendMessage":[64]}]]]], options);
10
10
  };
11
11
 
12
12
  exports.setNonce = index.setNonce;
@@ -26055,7 +26055,7 @@ _defineProperty(JWSSignatureVerificationFailed, "code", 'ERR_JWS_SIGNATURE_VERIF
26055
26055
 
26056
26056
  function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)({}).hasOwnProperty.call(n,o)&&(e[o]=n[o]);}return e},s.apply(null,arguments)}const i=new Uint8Array(0);class r{static getFullOptions(e){return s({clientTools:{},onConnect:()=>{},onDebug:()=>{},onDisconnect:()=>{},onError:()=>{},onMessage:()=>{},onAudio:()=>{},onModeChange:()=>{},onStatusChange:()=>{},onCanSendFeedbackChange:()=>{},onInterruption:()=>{}},e)}constructor(e,t){var n=this;this.options=void 0,this.connection=void 0,this.lastInterruptTimestamp=0,this.mode="listening",this.status="connecting",this.volume=1,this.currentEventId=1,this.lastFeedbackEventId=0,this.canSendFeedback=false,this.endSessionWithDetails=async function(e){"connected"!==n.status&&"connecting"!==n.status||(n.updateStatus("disconnecting"),await n.handleEndSession(),n.updateStatus("disconnected"),n.options.onDisconnect&&n.options.onDisconnect(e));},this.onMessage=async function(e){switch(e.type){case "interruption":return void n.handleInterruption(e);case "agent_response":return void n.handleAgentResponse(e);case "user_transcript":return void n.handleUserTranscript(e);case "internal_tentative_agent_response":return void n.handleTentativeAgentResponse(e);case "client_tool_call":try{await n.handleClientToolCall(e);}catch(t){n.onError(`Unexpected error in client tool call handling: ${t instanceof Error?t.message:String(t)}`,{clientToolName:e.client_tool_call.tool_name,toolCallId:e.client_tool_call.tool_call_id});}return;case "audio":return void n.handleAudio(e);case "vad_score":return void n.handleVadScore(e);case "ping":return void n.connection.sendMessage({type:"pong",event_id:e.ping_event.event_id});case "mcp_tool_call":return void n.handleMCPToolCall(e);case "mcp_connection_status":return void n.handleMCPConnectionStatus(e);case "agent_tool_request":return void n.handleAgentToolRequest(e);case "agent_tool_response":return void n.handleAgentToolResponse(e);case "conversation_initiation_metadata":return void n.handleConversationMetadata(e);case "asr_initiation_metadata":return void n.handleAsrInitiationMetadata(e);case "agent_chat_response_part":return void n.handleAgentChatResponsePart(e);case "error":return void n.handleErrorEvent(e);default:return void(n.options.onDebug&&n.options.onDebug(e))}},this.setVolume=({volume:e})=>{this.volume=e;},this.options=e,this.connection=t,this.options.onConnect&&this.options.onConnect({conversationId:t.conversationId}),this.connection.onMessage(this.onMessage),this.connection.onDisconnect(this.endSessionWithDetails),this.connection.onModeChange(e=>this.updateMode(e)),this.updateStatus("connected");}endSession(){return this.endSessionWithDetails({reason:"user"})}async handleEndSession(){this.connection.close();}updateMode(e){e!==this.mode&&(this.mode=e,this.options.onModeChange&&this.options.onModeChange({mode:e}));}updateStatus(e){e!==this.status&&(this.status=e,this.options.onStatusChange&&this.options.onStatusChange({status:e}));}updateCanSendFeedback(){const e=this.currentEventId!==this.lastFeedbackEventId;this.canSendFeedback!==e&&(this.canSendFeedback=e,this.options.onCanSendFeedbackChange&&this.options.onCanSendFeedbackChange({canSendFeedback:e}));}handleInterruption(e){e.interruption_event&&(this.lastInterruptTimestamp=e.interruption_event.event_id,this.options.onInterruption&&this.options.onInterruption({event_id:e.interruption_event.event_id}));}handleAgentResponse(e){this.options.onMessage&&this.options.onMessage({source:"ai",role:"agent",message:e.agent_response_event.agent_response});}handleUserTranscript(e){this.options.onMessage&&this.options.onMessage({source:"user",role:"user",message:e.user_transcription_event.user_transcript});}handleTentativeAgentResponse(e){this.options.onDebug&&this.options.onDebug({type:"tentative_agent_response",response:e.tentative_agent_response_internal_event.tentative_agent_response});}handleVadScore(e){this.options.onVadScore&&this.options.onVadScore({vadScore:e.vad_score_event.vad_score});}async handleClientToolCall(e){if(Object.prototype.hasOwnProperty.call(this.options.clientTools,e.client_tool_call.tool_name))try{var t;const n=null!=(t=await this.options.clientTools[e.client_tool_call.tool_name](e.client_tool_call.parameters))?t:"Client tool execution successful.",o="object"==typeof n?JSON.stringify(n):String(n);this.connection.sendMessage({type:"client_tool_result",tool_call_id:e.client_tool_call.tool_call_id,result:o,is_error:false});}catch(t){this.onError(`Client tool execution failed with following error: ${null==t?void 0:t.message}`,{clientToolName:e.client_tool_call.tool_name}),this.connection.sendMessage({type:"client_tool_result",tool_call_id:e.client_tool_call.tool_call_id,result:`Client tool execution failed: ${null==t?void 0:t.message}`,is_error:true});}else {if(this.options.onUnhandledClientToolCall)return void this.options.onUnhandledClientToolCall(e.client_tool_call);this.onError(`Client tool with name ${e.client_tool_call.tool_name} is not defined on client`,{clientToolName:e.client_tool_call.tool_name}),this.connection.sendMessage({type:"client_tool_result",tool_call_id:e.client_tool_call.tool_call_id,result:`Client tool with name ${e.client_tool_call.tool_name} is not defined on client`,is_error:true});}}handleAudio(e){}handleMCPToolCall(e){this.options.onMCPToolCall&&this.options.onMCPToolCall(e.mcp_tool_call);}handleMCPConnectionStatus(e){this.options.onMCPConnectionStatus&&this.options.onMCPConnectionStatus(e.mcp_connection_status);}handleAgentToolRequest(e){this.options.onAgentToolRequest&&this.options.onAgentToolRequest(e.agent_tool_request);}handleAgentToolResponse(e){"end_call"===e.agent_tool_response.tool_name&&this.endSessionWithDetails({reason:"agent",context:new CloseEvent("end_call",{reason:"Agent ended the call"})}),this.options.onAgentToolResponse&&this.options.onAgentToolResponse(e.agent_tool_response);}handleConversationMetadata(e){this.options.onConversationMetadata&&this.options.onConversationMetadata(e.conversation_initiation_metadata_event);}handleAsrInitiationMetadata(e){this.options.onAsrInitiationMetadata&&this.options.onAsrInitiationMetadata(e.asr_initiation_metadata_event);}handleAgentChatResponsePart(e){this.options.onAgentChatResponsePart&&this.options.onAgentChatResponsePart(e.text_response_part);}handleErrorEvent(e){const t=e.error_event.error_type,n=e.error_event.message||e.error_event.reason||"Unknown error";"max_duration_exceeded"!==t?this.onError(`Server error: ${n}`,{errorType:t,code:e.error_event.code,debugMessage:e.error_event.debug_message,details:e.error_event.details}):this.endSessionWithDetails({reason:"error",message:n,context:new Event("max_duration_exceeded")});}onError(e,t){console.error(e,t),this.options.onError&&this.options.onError(e,t);}getId(){return this.connection.conversationId}isOpen(){return "connected"===this.status}setMicMuted(e){this.connection.setMicMuted(e);}getInputByteFrequencyData(){return i}getOutputByteFrequencyData(){return i}getInputVolume(){return 0}getOutputVolume(){return 0}sendFeedback(e){this.canSendFeedback?(this.connection.sendMessage({type:"feedback",score:e?"like":"dislike",event_id:this.currentEventId}),this.lastFeedbackEventId=this.currentEventId,this.updateCanSendFeedback()):console.warn(0===this.lastFeedbackEventId?"Cannot send feedback: the conversation has not started yet.":"Cannot send feedback: feedback has already been sent for the current response.");}sendContextualUpdate(e){this.connection.sendMessage({type:"contextual_update",text:e});}sendUserMessage(e){this.connection.sendMessage({type:"user_message",text:e});}sendUserActivity(){this.connection.sendMessage({type:"user_activity"});}sendMCPToolApprovalResult(e,t){this.connection.sendMessage({type:"mcp_tool_approval_result",tool_call_id:e,is_approved:t});}}class c{constructor(e={}){this.queue=[],this.disconnectionDetails=null,this.onDisconnectCallback=null,this.onMessageCallback=null,this.onModeChangeCallback=null,this.onDebug=void 0,this.onDebug=e.onDebug;}debug(e){this.onDebug&&this.onDebug(e);}onMessage(e){this.onMessageCallback=e;const t=this.queue;this.queue=[],t.length>0&&queueMicrotask(()=>{t.forEach(e);});}onDisconnect(e){this.onDisconnectCallback=e;const t=this.disconnectionDetails;t&&queueMicrotask(()=>{e(t);});}onModeChange(e){this.onModeChangeCallback=e;}updateMode(e){var t;null==(t=this.onModeChangeCallback)||t.call(this,e);}disconnect(e){var t;this.disconnectionDetails||(this.disconnectionDetails=e,null==(t=this.onDisconnectCallback)||t.call(this,e));}handleMessage(e){this.onMessageCallback?this.onMessageCallback(e):this.queue.push(e);}}function l(e){const[t,n]=e.split("_");if(!["pcm","ulaw"].includes(t))throw new Error(`Invalid format: ${e}`);const o=Number.parseInt(n);if(Number.isNaN(o))throw new Error(`Invalid sample rate: ${n}`);return {format:t,sampleRate:o}}const u="0.13.0";function d(e){return !!e.type}const h="conversation_initiation_client_data";function p(e){var t;const n={type:h};var o,a,s,i,r,c,l,u;return e.overrides&&(n.conversation_config_override={agent:{prompt:null==(o=e.overrides.agent)?void 0:o.prompt,first_message:null==(a=e.overrides.agent)?void 0:a.firstMessage,language:null==(s=e.overrides.agent)?void 0:s.language},tts:{voice_id:null==(i=e.overrides.tts)?void 0:i.voiceId,speed:null==(r=e.overrides.tts)?void 0:r.speed,stability:null==(c=e.overrides.tts)?void 0:c.stability,similarity_boost:null==(l=e.overrides.tts)?void 0:l.similarityBoost},conversation:{text_only:null==(u=e.overrides.conversation)?void 0:u.textOnly}}),e.customLlmExtraBody&&(n.custom_llm_extra_body=e.customLlmExtraBody),e.dynamicVariables&&(n.dynamic_variables=e.dynamicVariables),e.userId&&(n.user_id=e.userId),null!=(t=e.overrides)&&t.client&&(n.source_info={source:e.overrides.client.source,version:e.overrides.client.version}),n}class m extends Error{constructor(e,t){super(e),this.closeCode=void 0,this.closeReason=void 0,this.name="SessionConnectionError",this.closeCode=null==t?void 0:t.closeCode,this.closeReason=null==t?void 0:t.closeReason;}}class v extends c{constructor(e,t,n,o){super(),this.socket=void 0,this.conversationId=void 0,this.inputFormat=void 0,this.outputFormat=void 0,this.socket=e,this.conversationId=t,this.inputFormat=n,this.outputFormat=o,this.socket.addEventListener("error",e=>{setTimeout(()=>this.disconnect({reason:"error",message:"The connection was closed due to a socket error.",context:e}),0);}),this.socket.addEventListener("close",e=>{this.disconnect(1e3===e.code?{reason:"agent",context:e,closeCode:e.code,closeReason:e.reason||void 0}:{reason:"error",message:e.reason||"The connection was closed by the server.",context:e,closeCode:e.code,closeReason:e.reason||void 0});}),this.socket.addEventListener("message",e=>{try{const t=JSON.parse(e.data);if(!d(t))return void this.debug({type:"invalid_event",message:"Received invalid socket event",data:e.data});this.handleMessage(t);}catch(t){this.debug({type:"parsing_error",message:"Failed to parse socket message",error:t instanceof Error?t.message:String(t),data:e.data});}});}static async create(e){let t=null;try{var n,o,a;const s=null!=(n=e.origin)?n:"wss://api.elevenlabs.io";let i;const r=(null==(o=e.overrides)||null==(o=o.client)?void 0:o.version)||u,c=(null==(a=e.overrides)||null==(a=a.client)?void 0:a.source)||"js_sdk";if(e.signedUrl){const t=e.signedUrl.includes("?")?"&":"?";i=`${e.signedUrl}${t}source=${c}&version=${r}`;}else i=`${s}/v1/convai/conversation?agent_id=${e.agentId}&source=${c}&version=${r}`;const h=["convai"];e.authorization&&h.push(`bearer.${e.authorization}`),t=new WebSocket(i,h);const g=await new Promise((n,o)=>{t.addEventListener("open",()=>{var n;const o=p(e);null==(n=t)||n.send(JSON.stringify(o));},{once:true}),t.addEventListener("error",e=>{setTimeout(()=>o(new m("The connection was closed due to a socket error.")),0);}),t.addEventListener("close",e=>{o(new m(e.reason||(1e3===e.code?"Connection closed normally before session could be established.":"Connection closed unexpectedly before session could be established."),{closeCode:e.code,closeReason:e.reason||void 0}));}),t.addEventListener("message",e=>{const t=JSON.parse(e.data);d(t)&&("conversation_initiation_metadata"===t.type?n(t.conversation_initiation_metadata_event):console.warn("First received message is not conversation metadata."));},{once:true});}),{conversation_id:f,agent_output_audio_format:_,user_input_audio_format:w}=g,b=l(null!=w?w:"pcm_16000"),S=l(_);return new v(t,f,b,S)}catch(e){var s;throw null==(s=t)||s.close(),e}}close(){this.socket.close(1e3,"User ended conversation");}sendMessage(e){this.socket.send(JSON.stringify(e));}async setMicMuted(e){console.warn(`WebSocket connection setMicMuted called with ${e}, but this is handled by VoiceConversation`);}}function g(e){const t=new Uint8Array(e);return window.btoa(String.fromCharCode(...t))}function f(e){const t=window.atob(e),n=t.length,o=new Uint8Array(n);for(let e=0;e<n;e++)o[e]=t.charCodeAt(e);return o.buffer}const _=new Map;function w(e,t){return async(n,o)=>{const a=_.get(e);if(a)return n.addModule(a);if(o)try{return await n.addModule(o),void _.set(e,o)}catch(t){throw new Error(`Failed to load the ${e} worklet module from path: ${o}. Error: ${t}`)}const s=new Blob([t],{type:"application/javascript"}),i=URL.createObjectURL(s);try{return await n.addModule(i),void _.set(e,i)}catch(e){URL.revokeObjectURL(i);}try{const o=`data:application/javascript;base64,${btoa(t)}`;await n.addModule(o),_.set(e,o);}catch(t){throw new Error(`Failed to load the ${e} worklet module. Make sure the browser supports AudioWorklets. If you are using a strict CSP, you may need to self-host the worklet files.`)}}}const b=w("rawAudioProcessor",'/*\n * ulaw encoding logic taken from the wavefile library\n * https://github.com/rochars/wavefile/blob/master/lib/codecs/mulaw.js\n * USED BY @elevenlabs/client\n */\n\nconst BIAS = 0x84;\nconst CLIP = 32635;\nconst encodeTable = [\n 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,\n 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,\n 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7\n];\n\nfunction encodeSample(sample) {\n let sign;\n let exponent;\n let mantissa;\n let muLawSample;\n sign = (sample >> 8) & 0x80;\n if (sign !== 0) sample = -sample;\n sample = sample + BIAS;\n if (sample > CLIP) sample = CLIP;\n exponent = encodeTable[(sample>>7) & 0xFF];\n mantissa = (sample >> (exponent+3)) & 0x0F;\n muLawSample = ~(sign | (exponent << 4) | mantissa);\n \n return muLawSample;\n}\n\nclass RawAudioProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n \n this.port.onmessage = ({ data }) => {\n switch (data.type) {\n case "setFormat":\n this.isMuted = false;\n this.buffer = []; // Initialize an empty buffer\n this.bufferSize = data.sampleRate / 4;\n this.format = data.format;\n\n if (globalThis.LibSampleRate && sampleRate !== data.sampleRate) {\n globalThis.LibSampleRate.create(1, sampleRate, data.sampleRate).then(resampler => {\n this.resampler = resampler;\n });\n }\n break;\n case "setMuted":\n this.isMuted = data.isMuted;\n break;\n }\n };\n }\n process(inputs) {\n if (!this.buffer) {\n return true;\n }\n \n const input = inputs[0]; // Get the first input node\n if (input.length > 0) {\n let channelData = input[0]; // Get the first channel\'s data\n\n // Resample the audio if necessary\n if (this.resampler) {\n channelData = this.resampler.full(channelData);\n }\n\n // Add channel data to the buffer\n this.buffer.push(...channelData);\n // Get max volume \n let sum = 0.0;\n for (let i = 0; i < channelData.length; i++) {\n sum += channelData[i] * channelData[i];\n }\n const maxVolume = Math.sqrt(sum / channelData.length);\n // Check if buffer size has reached or exceeded the threshold\n if (this.buffer.length >= this.bufferSize) {\n const float32Array = this.isMuted \n ? new Float32Array(this.buffer.length)\n : new Float32Array(this.buffer);\n\n let encodedArray = this.format === "ulaw"\n ? new Uint8Array(float32Array.length)\n : new Int16Array(float32Array.length);\n\n // Iterate through the Float32Array and convert each sample to PCM16\n for (let i = 0; i < float32Array.length; i++) {\n // Clamp the value to the range [-1, 1]\n let sample = Math.max(-1, Math.min(1, float32Array[i]));\n\n // Scale the sample to the range [-32768, 32767]\n let value = sample < 0 ? sample * 32768 : sample * 32767;\n if (this.format === "ulaw") {\n value = encodeSample(Math.round(value));\n }\n\n encodedArray[i] = value;\n }\n\n // Send the buffered data to the main script\n this.port.postMessage([encodedArray, maxVolume]);\n\n // Clear the buffer after sending\n this.buffer = [];\n }\n }\n return true; // Continue processing\n }\n}\nregisterProcessor("rawAudioProcessor", RawAudioProcessor);\n');class S extends c{constructor(e,t,n,o,a={}){super(a),this.conversationId=void 0,this.inputFormat=void 0,this.outputFormat=void 0,this.room=void 0,this.isConnected=false,this.audioEventId=1,this.audioCaptureContext=null,this.audioElements=[],this.outputDeviceId=null,this.outputAnalyser=null,this.outputFrequencyData=null,this.room=e,this.conversationId=t,this.inputFormat=n,this.outputFormat=o,this.setupRoomEventListeners();}static async create(n){let o;if("conversationToken"in n&&n.conversationToken)o=n.conversationToken;else {if(!("agentId"in n)||!n.agentId)throw new Error("Either conversationToken or agentId is required for WebRTC connection");try{var a,s,i;const e=(null==(a=n.overrides)||null==(a=a.client)?void 0:a.version)||u,t=(null==(s=n.overrides)||null==(s=s.client)?void 0:s.source)||"js_sdk",c=`${r=null!=(i=n.origin)?i:"https://api.elevenlabs.io",r.replace(/^wss:\/\//,"https://")}/v1/convai/conversation/token?agent_id=${n.agentId}&source=${t}&version=${e}`,l=await fetch(c);if(!l.ok)throw new Error(`ElevenLabs API returned ${l.status} ${l.statusText}`);if(o=(await l.json()).token,!o)throw new Error("No conversation token received from API")}catch(e){let t=e instanceof Error?e.message:String(e);throw e instanceof Error&&e.message.includes("401")&&(t="Your agent has authentication enabled, but no signed URL or conversation token was provided."),new Error(`Failed to fetch conversation token for agent ${n.agentId}: ${t}`)}}var r;const c=new Room;try{const e=`room_${Date.now()}`,a=l("pcm_48000"),s=l("pcm_48000"),i=new S(c,e,a,s,n),r=n.livekitUrl||"wss://livekit.rtc.elevenlabs.io";var d;await c.connect(r,o),await new Promise(e=>{if(i.isConnected)e();else {const n=()=>{c.off(RoomEvent.Connected,n),e();};c.on(RoomEvent.Connected,n);}}),c.name&&(i.conversationId=(null==(d=c.name.match(/(conv_[a-zA-Z0-9]+)/))?void 0:d[0])||c.name),n.textOnly||await c.localParticipant.setMicrophoneEnabled(true);const u=p(n);return i.debug({type:h,message:u}),await i.sendMessage(u),i}catch(e){throw await c.disconnect(),e}}setupRoomEventListeners(){var e=this;this.room.on(RoomEvent.Connected,async function(){e.isConnected=true,console.info("WebRTC room connected");}),this.room.on(RoomEvent.Disconnected,e=>{this.isConnected=false,this.disconnect({reason:"agent",context:new CloseEvent("close",{reason:null==e?void 0:e.toString()})});}),this.room.on(RoomEvent.ConnectionStateChanged,e=>{e===ConnectionState.Disconnected&&(this.isConnected=false,this.disconnect({reason:"error",message:`LiveKit connection state changed to ${e}`,context:new Event("connection_state_changed")}));}),this.room.on(RoomEvent.DataReceived,(e,t)=>{try{const t=JSON.parse((new TextDecoder).decode(e));if("audio"===t.type)return;d(t)?this.handleMessage(t):console.warn("Invalid socket event received:",t);}catch(t){console.warn("Failed to parse incoming data message:",t),console.warn("Raw payload:",(new TextDecoder).decode(e));}}),this.room.on(RoomEvent.TrackSubscribed,async function(t,n,a){if(t.kind===Track.Kind.Audio&&a.identity.includes("agent")){const n=t,o=n.attach();if(o.autoplay=true,o.controls=false,e.outputDeviceId&&o.setSinkId)try{await o.setSinkId(e.outputDeviceId);}catch(e){console.warn("Failed to set output device for new audio element:",e);}o.style.display="none",document.body.appendChild(o),e.audioElements.push(o),1===e.audioElements.length&&(null==e.onDebug||e.onDebug({type:"audio_element_ready"})),await e.setupAudioCapture(n);}}),this.room.on(RoomEvent.ActiveSpeakersChanged,async function(t){e.updateMode(t.length>0&&t[0].identity.startsWith("agent")?"speaking":"listening");}),this.room.on(RoomEvent.ParticipantDisconnected,e=>{var t;null!=(t=e.identity)&&t.startsWith("agent")&&this.disconnect({reason:"agent",context:new CloseEvent("close",{reason:"agent disconnected"})});});}close(){if(this.isConnected){try{this.room.localParticipant.audioTrackPublications.forEach(e=>{e.track&&e.track.stop();});}catch(e){console.warn("Error stopping local tracks:",e);}this.audioCaptureContext&&(this.audioCaptureContext.close().catch(e=>{console.warn("Error closing audio capture context:",e);}),this.audioCaptureContext=null),this.audioElements.forEach(e=>{e.parentNode&&e.parentNode.removeChild(e);}),this.audioElements=[],this.room.disconnect();}}async sendMessage(e){if(this.isConnected&&this.room.localParticipant){if(!("user_audio_chunk"in e))try{const t=(new TextEncoder).encode(JSON.stringify(e));await this.room.localParticipant.publishData(t,{reliable:true});}catch(t){this.debug({type:"send_message_error",message:{message:e,error:t}}),console.error("Failed to send message via WebRTC:",t);}}else console.warn("Cannot send message: room not connected or no local participant");}getRoom(){return this.room}async setMicMuted(e){if(!this.isConnected||!this.room.localParticipant)return void console.warn("Cannot set microphone muted: room not connected or no local participant");const t=this.room.localParticipant.getTrackPublication(Track.Source.Microphone);if(null!=t&&t.track)try{e?await t.track.mute():await t.track.unmute();}catch(t){await this.room.localParticipant.setMicrophoneEnabled(!e);}else await this.room.localParticipant.setMicrophoneEnabled(!e);}async setupAudioCapture(e){try{const t=new AudioContext;this.audioCaptureContext=t,this.outputAnalyser=t.createAnalyser(),this.outputAnalyser.fftSize=2048,this.outputAnalyser.smoothingTimeConstant=.8;const n=new MediaStream([e.mediaStreamTrack]),o=t.createMediaStreamSource(n);o.connect(this.outputAnalyser),await b(t.audioWorklet);const a=new AudioWorkletNode(t,"rawAudioProcessor");this.outputAnalyser.connect(a),a.port.postMessage({type:"setFormat",format:this.outputFormat.format,sampleRate:this.outputFormat.sampleRate}),a.port.onmessage=e=>{const[t,n]=e.data;if(n>.01){const e=g(t.buffer),n=this.audioEventId++;this.handleMessage({type:"audio",audio_event:{audio_base_64:e,event_id:n}});}},o.connect(a);}catch(e){console.warn("Failed to set up audio capture:",e);}}setAudioVolume(e){this.audioElements.forEach(t=>{t.volume=e;});}async setAudioOutputDevice(e){if(!("setSinkId"in HTMLAudioElement.prototype))throw new Error("setSinkId is not supported in this browser");const t=this.audioElements.map(async function(t){try{await t.setSinkId(e);}catch(e){throw console.error("Failed to set sink ID for audio element:",e),e}});await Promise.all(t),this.outputDeviceId=e;}async setAudioInputDevice(e){if(!this.isConnected||!this.room.localParticipant)throw new Error("Cannot change input device: room not connected or no local participant");try{const t=this.room.localParticipant.getTrackPublication(Track.Source.Microphone);null!=t&&t.track&&(await t.track.stop(),await this.room.localParticipant.unpublishTrack(t.track));const n={deviceId:{exact:e},echoCancellation:true,noiseSuppression:true,autoGainControl:true,channelCount:{ideal:1}},s=await createLocalAudioTrack(n);await this.room.localParticipant.publishTrack(s,{name:"microphone",source:Track.Source.Microphone});}catch(e){console.error("Failed to change input device:",e);try{await this.room.localParticipant.setMicrophoneEnabled(true);}catch(e){console.error("Failed to recover microphone after device switch error:",e);}throw e}}getOutputByteFrequencyData(){return this.outputAnalyser?(null!=this.outputFrequencyData||(this.outputFrequencyData=new Uint8Array(this.outputAnalyser.frequencyBinCount)),this.outputAnalyser.getByteFrequencyData(this.outputFrequencyData),this.outputFrequencyData):null}}async function y(e){const t=function(e){return e.connectionType?e.connectionType:"conversationToken"in e&&e.conversationToken?"webrtc":"websocket"}(e);switch(t){case "websocket":return v.create(e);case "webrtc":return S.create(e);default:throw new Error(`Unknown connection type: ${t}`)}}function k(){return ["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}async function E(e={default:0,android:3e3}){let t=e.default;var n;if(/android/i.test(navigator.userAgent))t=null!=(n=e.android)?n:t;else if(k()){var o;t=null!=(o=e.ios)?o:t;}t>0&&await new Promise(e=>setTimeout(e,t));}class C extends r{static async startSession(e){const t=r.getFullOptions(e);t.onStatusChange&&t.onStatusChange({status:"connecting"}),t.onCanSendFeedbackChange&&t.onCanSendFeedbackChange({canSendFeedback:false}),t.onModeChange&&t.onModeChange({mode:"listening"}),t.onCanSendFeedbackChange&&t.onCanSendFeedbackChange({canSendFeedback:false});let n=null;try{return await E(t.connectionDelay),n=await y(e),new C(t,n)}catch(e){var o;throw t.onStatusChange&&t.onStatusChange({status:"disconnected"}),null==(o=n)||o.close(),e}}}const R={echoCancellation:true,noiseSuppression:true,autoGainControl:true,channelCount:{ideal:1}};class M{static async create({sampleRate:e,format:t,preferHeadphonesForIosDevices:n,inputDeviceId:o,workletPaths:a,libsampleratePath:i}){let r=null,c=null;try{const l=s({sampleRate:{ideal:e}},R);if(k()&&n){const e=(await window.navigator.mediaDevices.enumerateDevices()).find(e=>"audioinput"===e.kind&&["airpod","headphone","earphone"].find(t=>e.label.toLowerCase().includes(t)));e&&(l.deviceId={ideal:e.deviceId});}o&&(l.deviceId=M.getDeviceIdConstraint(o));const u=navigator.mediaDevices.getSupportedConstraints().sampleRate;r=new window.AudioContext(u?{sampleRate:e}:{});const d=r.createAnalyser();if(!u){const e=i||"https://cdn.jsdelivr.net/npm/@alexanderolsen/libsamplerate-js@2.1.2/dist/libsamplerate.worklet.js";await r.audioWorklet.addModule(e);}await b(r.audioWorklet,null==a?void 0:a.rawAudioProcessor);const h=s({voiceIsolation:true},l);c=await navigator.mediaDevices.getUserMedia({audio:h});const p=r.createMediaStreamSource(c),m=new AudioWorkletNode(r,"rawAudioProcessor");return m.port.postMessage({type:"setFormat",format:t,sampleRate:e}),p.connect(d),d.connect(m),await r.resume(),new M(r,d,m,c,p)}catch(e){var l,u;throw null==(l=c)||l.getTracks().forEach(e=>{e.stop();}),null==(u=r)||u.close(),e}}static getDeviceIdConstraint(e){if(e)return k()?{ideal:e}:{exact:e}}constructor(e,t,n,o,a){this.context=void 0,this.analyser=void 0,this.worklet=void 0,this.inputStream=void 0,this.mediaStreamSource=void 0,this.context=e,this.analyser=t,this.worklet=n,this.inputStream=o,this.mediaStreamSource=a;}async close(){this.inputStream.getTracks().forEach(e=>{e.stop();}),this.mediaStreamSource.disconnect(),await this.context.close();}setMuted(e){this.worklet.port.postMessage({type:"setMuted",isMuted:e});}async setInputDevice(e){try{const t=s({},R);e&&(t.deviceId=M.getDeviceIdConstraint(e));const n=s({voiceIsolation:true},t),o=await navigator.mediaDevices.getUserMedia({audio:n});this.inputStream.getTracks().forEach(e=>{e.stop();}),this.mediaStreamSource.disconnect(),this.inputStream=o,this.mediaStreamSource=this.context.createMediaStreamSource(o),this.mediaStreamSource.connect(this.analyser);}catch(e){throw console.error("Failed to switch input device:",e),e}}}const A=w("audioConcatProcessor",'/*\n * ulaw decoding logic taken from the wavefile library\n * https://github.com/rochars/wavefile/blob/master/lib/codecs/mulaw.js\n * USED BY @elevenlabs/client\n */\n\nconst decodeTable = [0,132,396,924,1980,4092,8316,16764];\n\nfunction decodeSample(muLawSample) {\n let sign;\n let exponent;\n let mantissa;\n let sample;\n muLawSample = ~muLawSample;\n sign = (muLawSample & 0x80);\n exponent = (muLawSample >> 4) & 0x07;\n mantissa = muLawSample & 0x0F;\n sample = decodeTable[exponent] + (mantissa << (exponent+3));\n if (sign !== 0) sample = -sample;\n\n return sample;\n}\n\nclass AudioConcatProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n this.buffers = []; // Initialize an empty buffer\n this.cursor = 0;\n this.currentBuffer = null;\n this.wasInterrupted = false;\n this.finished = false;\n \n this.port.onmessage = ({ data }) => {\n switch (data.type) {\n case "setFormat":\n this.format = data.format;\n break;\n case "buffer":\n this.wasInterrupted = false;\n this.buffers.push(\n this.format === "ulaw"\n ? new Uint8Array(data.buffer)\n : new Int16Array(data.buffer)\n );\n break;\n case "interrupt":\n this.wasInterrupted = true;\n break;\n case "clearInterrupted":\n if (this.wasInterrupted) {\n this.wasInterrupted = false;\n this.buffers = [];\n this.currentBuffer = null;\n }\n }\n };\n }\n process(_, outputs) {\n let finished = false;\n const output = outputs[0][0];\n for (let i = 0; i < output.length; i++) {\n if (!this.currentBuffer) {\n if (this.buffers.length === 0) {\n finished = true;\n break;\n }\n this.currentBuffer = this.buffers.shift();\n this.cursor = 0;\n }\n\n let value = this.currentBuffer[this.cursor];\n if (this.format === "ulaw") {\n value = decodeSample(value);\n }\n output[i] = value / 32768;\n this.cursor++;\n\n if (this.cursor >= this.currentBuffer.length) {\n this.currentBuffer = null;\n }\n }\n\n if (this.finished !== finished) {\n this.finished = finished;\n this.port.postMessage({ type: "process", finished });\n }\n\n return true; // Continue processing\n }\n}\n\nregisterProcessor("audioConcatProcessor", AudioConcatProcessor);\n');class I{static async create({sampleRate:e,format:t,outputDeviceId:n,workletPaths:o}){let a=null,s=null;try{a=new AudioContext({sampleRate:e});const i=a.createAnalyser(),r=a.createGain();s=new Audio,s.src="",s.load(),s.autoplay=true,s.style.display="none",document.body.appendChild(s);const c=a.createMediaStreamDestination();s.srcObject=c.stream,r.connect(i),i.connect(c),await A(a.audioWorklet,null==o?void 0:o.audioConcatProcessor);const l=new AudioWorkletNode(a,"audioConcatProcessor");return l.port.postMessage({type:"setFormat",format:t}),l.connect(r),await a.resume(),n&&s.setSinkId&&await s.setSinkId(n),new I(a,i,r,l,s)}catch(e){var i,r;throw null!=(i=s)&&i.parentNode&&s.parentNode.removeChild(s),null==(r=s)||r.pause(),a&&"closed"!==a.state&&await a.close(),e}}constructor(e,t,n,o,a){this.context=void 0,this.analyser=void 0,this.gain=void 0,this.worklet=void 0,this.audioElement=void 0,this.context=e,this.analyser=t,this.gain=n,this.worklet=o,this.audioElement=a;}async setOutputDevice(e){if(!("setSinkId"in HTMLAudioElement.prototype))throw new Error("setSinkId is not supported in this browser");await this.audioElement.setSinkId(e||"");}async close(){this.audioElement.parentNode&&this.audioElement.parentNode.removeChild(this.audioElement),this.audioElement.pause(),await this.context.close();}}class D extends r{static async requestWakeLock(){if("wakeLock"in navigator)try{return await navigator.wakeLock.request("screen")}catch(e){}return null}static async startSession(e){var t;const n=r.getFullOptions(e);n.onStatusChange&&n.onStatusChange({status:"connecting"}),n.onCanSendFeedbackChange&&n.onCanSendFeedbackChange({canSendFeedback:false});let o=null,a=null,i=null,c=null,l=null;(null==(t=e.useWakeLock)||t)&&(l=await D.requestWakeLock());try{var u;return c=await navigator.mediaDevices.getUserMedia({audio:true}),await E(n.connectionDelay),a=await y(e),[o,i]=await Promise.all([M.create(s({},a.inputFormat,{preferHeadphonesForIosDevices:e.preferHeadphonesForIosDevices,inputDeviceId:e.inputDeviceId,workletPaths:e.workletPaths,libsampleratePath:e.libsampleratePath})),I.create(s({},a.outputFormat,{outputDeviceId:e.outputDeviceId,workletPaths:e.workletPaths}))]),null==(u=c)||u.getTracks().forEach(e=>{e.stop();}),c=null,new D(n,a,o,i,l)}catch(e){var d,h,p,m;n.onStatusChange&&n.onStatusChange({status:"disconnected"}),null==(d=c)||d.getTracks().forEach(e=>{e.stop();}),null==(h=a)||h.close(),await(null==(p=o)?void 0:p.close()),await(null==(m=i)?void 0:m.close());try{var v;await(null==(v=l)?void 0:v.release()),l=null;}catch(e){}throw e}}constructor(e,t,n,o,a){super(e,t),this.input=void 0,this.output=void 0,this.wakeLock=void 0,this.inputFrequencyData=void 0,this.outputFrequencyData=void 0,this.visibilityChangeHandler=null,this.onInputWorkletMessage=e=>{"connected"===this.status&&this.connection.sendMessage({user_audio_chunk:g(e.data[0].buffer)});},this.onOutputWorkletMessage=({data:e})=>{"process"===e.type&&this.updateMode(e.finished?"listening":"speaking");},this.addAudioBase64Chunk=e=>{this.output.gain.gain.cancelScheduledValues(this.output.context.currentTime),this.output.gain.gain.value=this.volume,this.output.worklet.port.postMessage({type:"clearInterrupted"}),this.output.worklet.port.postMessage({type:"buffer",buffer:f(e)});},this.fadeOutAudio=()=>{this.updateMode("listening"),this.output.worklet.port.postMessage({type:"interrupt"}),this.output.gain.gain.exponentialRampToValueAtTime(1e-4,this.output.context.currentTime+2),setTimeout(()=>{this.output.gain.gain.value=this.volume,this.output.worklet.port.postMessage({type:"clearInterrupted"});},2e3);},this.calculateVolume=e=>{if(0===e.length)return 0;let t=0;for(let n=0;n<e.length;n++)t+=e[n]/255;return t/=e.length,t<0?0:t>1?1:t},this.setVolume=({volume:e})=>{const t=Number.isFinite(e)?Math.min(1,Math.max(0,e)):1;this.volume=t,this.connection instanceof S?this.connection.setAudioVolume(t):this.output.gain.gain.value=t;},this.input=n,this.output=o,this.wakeLock=a,this.input.worklet.port.onmessage=this.onInputWorkletMessage,this.output.worklet.port.onmessage=this.onOutputWorkletMessage,a&&(this.visibilityChangeHandler=()=>{var e;"visible"===document.visibilityState&&null!=(e=this.wakeLock)&&e.released&&D.requestWakeLock().then(e=>{this.wakeLock=e;});},document.addEventListener("visibilitychange",this.visibilityChangeHandler));}async handleEndSession(){await super.handleEndSession(),this.visibilityChangeHandler&&document.removeEventListener("visibilitychange",this.visibilityChangeHandler);try{var e;await(null==(e=this.wakeLock)?void 0:e.release()),this.wakeLock=null;}catch(e){}await this.input.close(),await this.output.close();}handleInterruption(e){super.handleInterruption(e),this.fadeOutAudio();}handleAudio(e){var t,n;super.handleAudio(e),e.audio_event.alignment&&this.options.onAudioAlignment&&this.options.onAudioAlignment(e.audio_event.alignment),this.lastInterruptTimestamp<=e.audio_event.event_id&&(e.audio_event.audio_base_64&&(null==(t=(n=this.options).onAudio)||t.call(n,e.audio_event.audio_base_64),this.connection instanceof S||this.addAudioBase64Chunk(e.audio_event.audio_base_64)),this.currentEventId=e.audio_event.event_id,this.updateCanSendFeedback(),this.updateMode("speaking"));}setMicMuted(e){this.connection instanceof S?this.connection.setMicMuted(e):this.input.setMuted(e);}getInputByteFrequencyData(){return null!=this.inputFrequencyData||(this.inputFrequencyData=new Uint8Array(this.input.analyser.frequencyBinCount)),this.input.analyser.getByteFrequencyData(this.inputFrequencyData),this.inputFrequencyData}getOutputByteFrequencyData(){return this.connection instanceof S?this.connection.getOutputByteFrequencyData()||new Uint8Array(1024):(null!=this.outputFrequencyData||(this.outputFrequencyData=new Uint8Array(this.output.analyser.frequencyBinCount)),this.output.analyser.getByteFrequencyData(this.outputFrequencyData),this.outputFrequencyData)}getInputVolume(){return this.calculateVolume(this.getInputByteFrequencyData())}getOutputVolume(){return this.calculateVolume(this.getOutputByteFrequencyData())}async changeInputDevice({sampleRate:e,format:t,preferHeadphonesForIosDevices:n,inputDeviceId:o}){try{if(this.connection instanceof v)try{return await this.input.setInputDevice(o),this.input}catch(e){console.warn("Failed to change device on existing input, recreating:",e);}this.connection instanceof S&&await this.connection.setAudioInputDevice(o||""),await this.input.close();const a=await M.create({sampleRate:null!=e?e:this.connection.inputFormat.sampleRate,format:null!=t?t:this.connection.inputFormat.format,preferHeadphonesForIosDevices:n,inputDeviceId:o,workletPaths:this.options.workletPaths,libsampleratePath:this.options.libsampleratePath});return this.input=a,this.input.worklet.port.onmessage=this.onInputWorkletMessage,this.input}catch(e){throw console.error("Error changing input device",e),e}}async changeOutputDevice({sampleRate:e,format:t,outputDeviceId:n}){try{if(this.connection instanceof v)try{return await this.output.setOutputDevice(n),this.output}catch(e){console.warn("Failed to change device on existing output, recreating:",e);}this.connection instanceof S&&await this.connection.setAudioOutputDevice(n||""),await this.output.close();const o=await I.create({sampleRate:null!=e?e:this.connection.outputFormat.sampleRate,format:null!=t?t:this.connection.outputFormat.format,outputDeviceId:n,workletPaths:this.options.workletPaths});return this.output=o,this.output}catch(e){throw console.error("Error changing output device",e),e}}}var P;!function(e){e.SESSION_STARTED="session_started",e.PARTIAL_TRANSCRIPT="partial_transcript",e.COMMITTED_TRANSCRIPT="committed_transcript",e.COMMITTED_TRANSCRIPT_WITH_TIMESTAMPS="committed_transcript_with_timestamps",e.AUTH_ERROR="auth_error",e.ERROR="error",e.OPEN="open",e.CLOSE="close",e.QUOTA_EXCEEDED="quota_exceeded",e.COMMIT_THROTTLED="commit_throttled",e.TRANSCRIBER_ERROR="transcriber_error",e.UNACCEPTED_TERMS="unaccepted_terms",e.RATE_LIMITED="rate_limited",e.INPUT_ERROR="input_error",e.QUEUE_OVERFLOW="queue_overflow",e.RESOURCE_EXHAUSTED="resource_exhausted",e.SESSION_TIME_LIMIT_EXCEEDED="session_time_limit_exceeded",e.CHUNK_SIZE_EXCEEDED="chunk_size_exceeded",e.INSUFFICIENT_AUDIO_ACTIVITY="insufficient_audio_activity";}(P||(P={}));var U,L;!function(e){e.PCM_8000="pcm_8000",e.PCM_16000="pcm_16000",e.PCM_22050="pcm_22050",e.PCM_24000="pcm_24000",e.PCM_44100="pcm_44100",e.PCM_48000="pcm_48000",e.ULAW_8000="ulaw_8000";}(U||(U={})),function(e){e.MANUAL="manual",e.VAD="vad";}(L||(L={}));
26057
26057
 
26058
- const stayliftWidgetCss = () => `:host{--sl-primary:#6366f1;--sl-bg:#18181b;--sl-text:#ffffff;--sl-muted:#a1a1aa;--sl-border:#27272a;--sl-surface:#27272a;--sl-success:#22c55e;--sl-danger:#ef4444;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;font-size:14px;line-height:1.5;color:var(--sl-text)}.sl-widget *{box-sizing:border-box}.sl-floating{position:fixed;z-index:999999}.sl-x-left{left:40px;right:auto}.sl-x-center{left:50%;right:auto;transform:translateX(-50%)}.sl-x-right{right:40px;left:auto}.sl-y-top{top:40px;bottom:auto}.sl-y-bottom{bottom:40px;top:auto}.sl-fab{width:64px;height:64px;border-radius:50%;border:1px solid var(--sl-border);background:var(--sl-bg);cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 8px 32px rgba(0, 0, 0, 0.4);transition:transform 0.2s, box-shadow 0.2s;padding:8px}.sl-fab:hover{transform:scale(1.05);box-shadow:0 12px 40px rgba(0, 0, 0, 0.5)}.sl-fab-pill{display:flex;align-items:center;gap:16px;padding:12px 16px 12px 12px;background:var(--sl-bg);border:1px solid var(--sl-border);border-radius:32px;box-shadow:0 8px 32px rgba(0, 0, 0, 0.4);animation:sl-fade-in 0.2s ease}.sl-fab-avatar{width:48px;height:48px;border-radius:50%;overflow:hidden;flex-shrink:0;border:1px solid var(--sl-border)}.sl-fab-avatar-img{width:100%;height:100%;object-fit:cover}.sl-fab-content{display:flex;flex-direction:column;gap:8px}.sl-fab-prompt{font-size:14px;font-weight:500;color:var(--sl-text);white-space:nowrap}.sl-fab-btn{display:flex;align-items:center;gap:6px;padding:8px 20px;border:none;border-radius:20px;background:var(--sl-primary);color:white;font-size:13px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-fab-btn:hover{filter:brightness(1.1);transform:translateY(-1px)}.sl-card{width:440px;height:440px;max-height:calc(100vh - 100px);background:var(--sl-bg);border-radius:16px;border:1px solid var(--sl-border);box-shadow:0 20px 60px rgba(0, 0, 0, 0.5);display:flex;flex-direction:column;overflow:hidden;animation:sl-fade-in 0.2s ease}.sl-inline{width:100%;max-width:540px;height:440px;background:var(--sl-bg);border-radius:16px;border:1px solid var(--sl-border);display:flex;flex-direction:column;overflow:hidden}@keyframes sl-fade-in{from{opacity:0;transform:translateY(10px) scale(0.98)}to{opacity:1;transform:translateY(0) scale(1)}}.sl-header{display:flex;align-items:center;justify-content:space-between;padding:16px;flex-shrink:0;border-bottom:1px solid var(--sl-border)}.sl-header-left{display:flex;align-items:center;gap:16px}.sl-orb-ring{width:40px;height:40px;border-radius:50%;border:1px solid var(--sl-border);overflow:hidden;flex-shrink:0;display:flex;align-items:center;justify-content:center}.sl-header-avatar-img{width:100%;height:100%;object-fit:cover;object-position:center center;display:block}.sl-header-text{display:flex;flex-direction:column;gap:2px}.sl-title{font-size:14px;font-weight:500;color:var(--sl-text);line-height:1.2}.sl-subtitle{font-size:12px;color:var(--sl-muted);line-height:1.2}.sl-error{color:var(--sl-danger)}.sl-connected{color:var(--sl-success)}.sl-shimmer{background:linear-gradient(90deg, var(--sl-muted) 0%, var(--sl-text) 50%, var(--sl-muted) 100%);background-size:200% 100%;-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;animation:sl-shimmer 1.5s infinite;text-transform:capitalize}@keyframes sl-shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}.sl-header-right{display:flex;align-items:center;gap:12px}.sl-dot{width:8px;height:8px;border-radius:50%;background:var(--sl-muted);opacity:0.4;transition:all 0.3s}.sl-dot--active{background:var(--sl-success);opacity:1;box-shadow:0 0 8px rgba(34, 197, 94, 0.5)}.sl-dot--pulse{background:var(--sl-text);opacity:0.4;animation:sl-pulse 1s infinite}@keyframes sl-pulse{0%,100%{opacity:0.4}50%{opacity:0.8}}.sl-close{width:32px;height:32px;border-radius:50%;border:none;background:transparent;color:var(--sl-muted);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s}.sl-close:hover{background:var(--sl-surface);color:var(--sl-text)}.sl-content{flex:1;overflow-y:auto;padding:12px 24px 24px;display:flex;flex-direction:column;gap:8px}.sl-empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:12px}.sl-empty-avatar{width:64px;height:64px;border-radius:50%;object-fit:cover;border:1px solid var(--sl-border)}.sl-empty-title{margin:0;font-size:15px;font-weight:500;color:var(--sl-text)}.sl-empty-desc{margin:0;font-size:13px;color:var(--sl-muted)}.sl-mode-toggle{display:flex;gap:8px;margin-bottom:12px;padding:4px;background:var(--sl-surface);border-radius:10px}.sl-mode-btn{display:flex;align-items:center;gap:6px;padding:8px 16px;border:none;border-radius:8px;background:transparent;color:var(--sl-muted);font-size:13px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-mode-btn:hover{color:var(--sl-text)}.sl-mode-btn--active{background:var(--sl-bg);color:var(--sl-text);box-shadow:0 1px 3px rgba(0, 0, 0, 0.2)}.sl-voice-controls{display:flex;justify-content:center}.sl-voice-btn{display:flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:14px 24px;border:none;border-radius:12px;background:var(--sl-primary);color:white;font-size:14px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-voice-btn:hover:not(:disabled){filter:brightness(1.1);transform:translateY(-1px)}.sl-voice-btn:disabled{opacity:0.6;cursor:not-allowed}.sl-voice-btn--end{background:var(--sl-danger)}.sl-voice-btn--end:hover:not(:disabled){filter:brightness(1.1)}.sl-msg{display:flex;flex-direction:column;gap:4px}.sl-msg-row{display:flex;align-items:flex-end;gap:8px}.sl-msg--user .sl-msg-row{justify-content:flex-end}.sl-msg--assistant .sl-msg-row{justify-content:flex-start}.sl-msg-bubble{max-width:85%;padding:10px 14px;border-radius:12px;font-size:14px;line-height:1.5;white-space:pre-wrap;word-wrap:break-word}.sl-msg--user .sl-msg-bubble{background:var(--sl-primary);color:white;border-bottom-right-radius:4px}.sl-msg--assistant .sl-msg-bubble{background:var(--sl-surface);color:var(--sl-text);border-bottom-left-radius:4px}.sl-msg-actions{display:flex;gap:4px;padding-left:32px}.sl-action{width:28px;height:28px;border-radius:6px;border:none;background:transparent;color:var(--sl-muted);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s}.sl-action:hover{background:var(--sl-surface);color:var(--sl-text)}.sl-footer{padding:16px;border-top:1px solid var(--sl-border);flex-shrink:0}.sl-branding{text-align:center;margin-top:8px;padding-top:8px}.sl-branding a{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--sl-muted);text-decoration:none;opacity:0.6;transition:opacity 0.2s}.sl-branding a:hover{opacity:1}.sl-branding-logo{width:16px;height:16px;border-radius:3px;object-fit:cover}.sl-input-row{display:flex;align-items:center;gap:8px}.sl-input{flex:1;height:36px;padding:0 12px;border:none;border-radius:8px;background:transparent;color:var(--sl-text);font-size:14px;outline:none}.sl-input::placeholder{color:var(--sl-muted)}.sl-input:disabled{opacity:0.5;cursor:not-allowed}.sl-btn{width:36px;height:36px;border-radius:50%;border:none;background:transparent;color:var(--sl-muted);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s;flex-shrink:0}.sl-btn:hover:not(:disabled){background:var(--sl-surface);color:var(--sl-text)}.sl-btn:disabled{opacity:0.3;cursor:not-allowed}.sl-btn--end{background:var(--sl-surface);color:var(--sl-text)}.sl-btn--end:hover:not(:disabled){background:var(--sl-danger);color:white}.sl-terms{display:flex;flex-direction:column;height:100%;padding:24px}.sl-terms-content{flex:1;display:flex;flex-direction:column;justify-content:center;gap:16px}.sl-terms-title{margin:0;font-size:18px;font-weight:600;color:var(--sl-text)}.sl-terms-text{margin:0;font-size:14px;line-height:1.6;color:var(--sl-text)}.sl-terms-warning{margin:0;font-size:13px;line-height:1.5;color:var(--sl-muted);font-style:italic}.sl-terms-actions{display:flex;gap:12px;padding-top:16px;border-top:1px solid var(--sl-border)}.sl-terms-btn{flex:1;padding:12px 20px;border:none;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-terms-btn--decline{background:var(--sl-surface);color:var(--sl-muted)}.sl-terms-btn--decline:hover{background:var(--sl-border);color:var(--sl-text)}.sl-terms-btn--agree{background:var(--sl-primary);color:white}.sl-terms-btn--agree:hover{filter:brightness(1.1)}@media (max-width: 480px){.sl-card{width:calc(100vw - 32px);max-width:400px}.sl-floating.sl-x-left,.sl-floating.sl-x-right{left:16px;right:16px}.sl-floating.sl-x-center{left:16px;right:16px;transform:none}.sl-floating.sl-y-bottom{bottom:16px}.sl-floating.sl-y-top{top:16px}}`;
26058
+ const stayliftWidgetCss = () => `:host{--sl-primary:#6366f1;--sl-bg:#18181b;--sl-text:#ffffff;--sl-muted:#a1a1aa;--sl-border:#27272a;--sl-surface:#27272a;--sl-success:#22c55e;--sl-danger:#ef4444;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;font-size:14px;line-height:1.5;color:var(--sl-text)}.sl-widget *{box-sizing:border-box}.sl-floating{position:fixed;z-index:999999}.sl-x-left{left:40px;right:auto}.sl-x-center{left:50%;right:auto;transform:translateX(-50%)}.sl-x-right{right:40px;left:auto}.sl-y-top{top:40px;bottom:auto}.sl-y-bottom{bottom:40px;top:auto}.sl-fab{width:64px;height:64px;border-radius:50%;border:1px solid var(--sl-border);background:var(--sl-bg);cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 8px 32px rgba(0, 0, 0, 0.4);transition:transform 0.2s, box-shadow 0.2s;padding:8px}.sl-fab:hover{transform:scale(1.05);box-shadow:0 12px 40px rgba(0, 0, 0, 0.5)}.sl-fab-pill{display:flex;align-items:center;gap:16px;padding:12px 16px 12px 12px;background:var(--sl-bg);border:1px solid var(--sl-border);border-radius:32px;box-shadow:0 8px 32px rgba(0, 0, 0, 0.4);animation:sl-fade-in 0.2s ease}.sl-fab-avatar{width:48px;height:48px;border-radius:50%;overflow:hidden;flex-shrink:0;border:1px solid var(--sl-border)}.sl-fab-avatar-img{width:100%;height:100%;object-fit:cover}.sl-fab-content{display:flex;flex-direction:column;gap:8px}.sl-fab-prompt{font-size:14px;font-weight:500;color:var(--sl-text);white-space:nowrap}.sl-fab-btn{display:flex;align-items:center;gap:6px;padding:8px 20px;border:none;border-radius:20px;background:var(--sl-primary);color:white;font-size:13px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-fab-btn:hover{filter:brightness(1.1);transform:translateY(-1px)}.sl-card{width:440px;height:440px;max-height:calc(100vh - 100px);background:var(--sl-bg);border-radius:16px;border:1px solid var(--sl-border);box-shadow:0 20px 60px rgba(0, 0, 0, 0.5);display:flex;flex-direction:column;overflow:hidden;animation:sl-fade-in 0.2s ease}.sl-inline{width:100%;max-width:540px;height:440px;background:var(--sl-bg);border-radius:16px;border:1px solid var(--sl-border);display:flex;flex-direction:column;overflow:hidden}@keyframes sl-fade-in{from{opacity:0;transform:translateY(10px) scale(0.98)}to{opacity:1;transform:translateY(0) scale(1)}}.sl-header{display:flex;align-items:center;justify-content:space-between;padding:16px;flex-shrink:0;border-bottom:1px solid var(--sl-border)}.sl-header-left{display:flex;align-items:center;gap:16px}.sl-orb-ring{width:40px;height:40px;border-radius:50%;border:1px solid var(--sl-border);overflow:hidden;flex-shrink:0;display:flex;align-items:center;justify-content:center}.sl-header-avatar-img{width:100%;height:100%;object-fit:cover;object-position:center center;display:block}.sl-header-text{display:flex;flex-direction:column;gap:2px}.sl-title{font-size:14px;font-weight:500;color:var(--sl-text);line-height:1.2}.sl-subtitle{font-size:12px;color:var(--sl-muted);line-height:1.2}.sl-error{color:var(--sl-danger)}.sl-connected{color:var(--sl-success)}.sl-shimmer{background:linear-gradient(90deg, var(--sl-muted) 0%, var(--sl-text) 50%, var(--sl-muted) 100%);background-size:200% 100%;-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;animation:sl-shimmer 1.5s infinite;text-transform:capitalize}@keyframes sl-shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}.sl-header-right{display:flex;align-items:center;gap:12px}.sl-dot{width:8px;height:8px;border-radius:50%;background:var(--sl-muted);opacity:0.4;transition:all 0.3s}.sl-dot--active{background:var(--sl-success);opacity:1;box-shadow:0 0 8px rgba(34, 197, 94, 0.5)}.sl-dot--pulse{background:var(--sl-text);opacity:0.4;animation:sl-pulse 1s infinite}@keyframes sl-pulse{0%,100%{opacity:0.4}50%{opacity:0.8}}.sl-close{width:32px;height:32px;border-radius:50%;border:none;background:transparent;color:var(--sl-muted);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s}.sl-close:hover{background:var(--sl-surface);color:var(--sl-text)}.sl-content{flex:1;overflow-y:auto;padding:12px 24px 24px;display:flex;flex-direction:column;gap:8px}.sl-empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:12px}.sl-empty-avatar{width:64px;height:64px;border-radius:50%;object-fit:cover;border:1px solid var(--sl-border)}.sl-empty-title{margin:0;font-size:15px;font-weight:500;color:var(--sl-text)}.sl-empty-desc{margin:0;font-size:13px;color:var(--sl-muted)}.sl-mode-toggle{display:flex;gap:8px;margin-bottom:12px;padding:4px;background:var(--sl-surface);border-radius:10px}.sl-mode-btn{display:flex;align-items:center;gap:6px;padding:8px 16px;border:none;border-radius:8px;background:transparent;color:var(--sl-muted);font-size:13px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-mode-btn:hover{color:var(--sl-text)}.sl-mode-btn--active{background:var(--sl-bg);color:var(--sl-text);box-shadow:0 1px 3px rgba(0, 0, 0, 0.2)}.sl-voice-controls{display:flex;justify-content:center}.sl-voice-btn{display:flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:14px 24px;border:none;border-radius:12px;background:var(--sl-primary);color:white;font-size:14px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-voice-btn:hover:not(:disabled){filter:brightness(1.1);transform:translateY(-1px)}.sl-voice-btn:disabled{opacity:0.6;cursor:not-allowed}.sl-voice-btn--end{background:var(--sl-danger)}.sl-voice-btn--end:hover:not(:disabled){filter:brightness(1.1)}.sl-msg{display:flex;flex-direction:column;gap:4px}.sl-msg-row{display:flex;align-items:flex-end;gap:8px}.sl-msg--user .sl-msg-row{justify-content:flex-end}.sl-msg--assistant .sl-msg-row{justify-content:flex-start}.sl-msg-bubble{max-width:85%;padding:10px 14px;border-radius:12px;font-size:14px;line-height:1.5;white-space:pre-wrap;word-wrap:break-word}.sl-msg--user .sl-msg-bubble{background:var(--sl-primary);color:white;border-bottom-right-radius:4px}.sl-msg--assistant .sl-msg-bubble{background:var(--sl-surface);color:var(--sl-text);border-bottom-left-radius:4px}.sl-msg-actions{display:flex;gap:4px;padding-left:32px}.sl-action{width:28px;height:28px;border-radius:6px;border:none;background:transparent;color:var(--sl-muted);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s}.sl-action:hover{background:var(--sl-surface);color:var(--sl-text)}.sl-offer-card{display:flex;flex-direction:row;gap:0;border-radius:12px;overflow:hidden;border:1px solid var(--sl-border);background:var(--sl-surface);text-decoration:none;color:inherit;cursor:pointer;transition:border-color 0.2s, box-shadow 0.2s}.sl-offer-card:hover{border-color:var(--sl-primary);box-shadow:0 2px 8px rgba(0,0,0,0.12)}.sl-offer-img{width:80px;height:80px;object-fit:cover;flex-shrink:0}.sl-offer-body{display:flex;flex-direction:column;gap:2px;padding:8px 12px;min-width:0;justify-content:center}.sl-offer-title{font-size:13px;font-weight:600;color:var(--sl-text);line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sl-offer-desc{font-size:12px;color:var(--sl-muted);line-height:1.3;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}.sl-offer-link{display:inline-flex;align-items:center;gap:4px;font-size:12px;font-weight:500;color:var(--sl-primary);margin-top:2px}.sl-offers-carousel{display:flex;flex-direction:column;gap:6px;max-width:85%}.sl-offers-nav{display:flex;align-items:center;justify-content:center;gap:8px}.sl-offers-nav-btn{width:28px;height:28px;border-radius:50%;border:1px solid var(--sl-border);background:var(--sl-surface);color:var(--sl-text);cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0;transition:all 0.2s}.sl-offers-nav-btn:hover:not(:disabled){border-color:var(--sl-primary);color:var(--sl-primary)}.sl-offers-nav-btn:disabled{opacity:0.3;cursor:default}.sl-offers-counter{font-size:12px;color:var(--sl-muted);min-width:40px;text-align:center}.sl-footer{padding:16px;border-top:1px solid var(--sl-border);flex-shrink:0}.sl-branding{text-align:center;margin-top:8px;padding-top:8px}.sl-branding a{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--sl-muted);text-decoration:none;opacity:0.6;transition:opacity 0.2s}.sl-branding a:hover{opacity:1}.sl-branding-logo{width:16px;height:16px;border-radius:3px;object-fit:cover}.sl-input-row{display:flex;align-items:center;gap:8px}.sl-input{flex:1;height:36px;padding:0 12px;border:none;border-radius:8px;background:transparent;color:var(--sl-text);font-size:14px;outline:none}.sl-input::placeholder{color:var(--sl-muted)}.sl-input:disabled{opacity:0.5;cursor:not-allowed}.sl-btn{width:36px;height:36px;border-radius:50%;border:none;background:transparent;color:var(--sl-muted);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all 0.2s;flex-shrink:0}.sl-btn:hover:not(:disabled){background:var(--sl-surface);color:var(--sl-text)}.sl-btn:disabled{opacity:0.3;cursor:not-allowed}.sl-btn--end{background:var(--sl-surface);color:var(--sl-text)}.sl-btn--end:hover:not(:disabled){background:var(--sl-danger);color:white}.sl-terms{display:flex;flex-direction:column;height:100%;padding:24px}.sl-terms-content{flex:1;display:flex;flex-direction:column;justify-content:center;gap:16px}.sl-terms-title{margin:0;font-size:18px;font-weight:600;color:var(--sl-text)}.sl-terms-text{margin:0;font-size:14px;line-height:1.6;color:var(--sl-text)}.sl-terms-warning{margin:0;font-size:13px;line-height:1.5;color:var(--sl-muted);font-style:italic}.sl-terms-actions{display:flex;gap:12px;padding-top:16px;border-top:1px solid var(--sl-border)}.sl-terms-btn{flex:1;padding:12px 20px;border:none;border-radius:8px;font-size:14px;font-weight:500;cursor:pointer;transition:all 0.2s}.sl-terms-btn--decline{background:var(--sl-surface);color:var(--sl-muted)}.sl-terms-btn--decline:hover{background:var(--sl-border);color:var(--sl-text)}.sl-terms-btn--agree{background:var(--sl-primary);color:white}.sl-terms-btn--agree:hover{filter:brightness(1.1)}@media (max-width: 480px){.sl-card{width:calc(100vw - 32px);max-width:400px}.sl-floating.sl-x-left,.sl-floating.sl-x-right{left:16px;right:16px}.sl-floating.sl-x-center{left:16px;right:16px;transform:none}.sl-floating.sl-y-bottom{bottom:16px}.sl-floating.sl-y-top{top:16px}}`;
26059
26059
 
26060
26060
  // Blocked agent IDs (unpaid/inactive subscriptions)
26061
26061
  const BLOCKED_AGENT_IDS = [
@@ -26094,6 +26094,10 @@ const StayliftWidget = class {
26094
26094
  this.inputText = '';
26095
26095
  this.copiedIndex = null;
26096
26096
  this.selectedMode = 'text';
26097
+ this.offerIndexes = {};
26098
+ this.pinnedOffers = null;
26099
+ this.pinnedOfferIndex = 0;
26100
+ this.pinnedMessagesRemaining = 0;
26097
26101
  // ============ PRIVATE ============
26098
26102
  this.conversation = null;
26099
26103
  this.volumeInterval = null;
@@ -26208,6 +26212,27 @@ const StayliftWidget = class {
26208
26212
  this.conversation = await ConversationClass.startSession({
26209
26213
  agentId: effectiveAgentId,
26210
26214
  connectionType: textOnly ? 'websocket' : 'webrtc',
26215
+ clientTools: {
26216
+ showOffers: async (parameters) => {
26217
+ console.log('[Staylift] showOffers client tool called with:', parameters);
26218
+ const rawOffers = parameters.offers;
26219
+ if (!rawOffers || !Array.isArray(rawOffers)) {
26220
+ console.warn('[Staylift] showOffers: no offers array provided');
26221
+ return 'No offers to display';
26222
+ }
26223
+ const offers = rawOffers.map(o => ({
26224
+ url: String(o.url || ''),
26225
+ photoUrl: o.photo_url ? String(o.photo_url) : undefined,
26226
+ title: o.title ? String(o.title) : undefined,
26227
+ description: o.description ? String(o.description) : undefined,
26228
+ }));
26229
+ this.pinnedOfferIndex = 0;
26230
+ this.pinnedMessagesRemaining = 1;
26231
+ this.pinnedOffers = offers;
26232
+ this.scrollToBottom();
26233
+ return `${offers.length} offer(s) displayed to user`;
26234
+ },
26235
+ },
26211
26236
  overrides: {
26212
26237
  conversation: {
26213
26238
  textOnly,
@@ -26249,7 +26274,27 @@ const StayliftWidget = class {
26249
26274
  role: messageRole === 'user' ? 'user' : 'assistant',
26250
26275
  content: message.message,
26251
26276
  };
26252
- this.messages = [...this.messages, chatMessage];
26277
+ if (this.pinnedOffers) {
26278
+ if (this.pinnedMessagesRemaining > 0) {
26279
+ // Still pinned — message goes above the carousel
26280
+ this.messages = [...this.messages, chatMessage];
26281
+ this.pinnedMessagesRemaining--;
26282
+ }
26283
+ else {
26284
+ // Unpin — flush offers into messages, then add new message below
26285
+ const offersMessage = {
26286
+ role: 'assistant',
26287
+ content: '',
26288
+ offers: this.pinnedOffers,
26289
+ };
26290
+ this.messages = [...this.messages, offersMessage, chatMessage];
26291
+ this.pinnedOffers = null;
26292
+ this.pinnedOfferIndex = 0;
26293
+ }
26294
+ }
26295
+ else {
26296
+ this.messages = [...this.messages, chatMessage];
26297
+ }
26253
26298
  this.messageReceived.emit(chatMessage);
26254
26299
  this.scrollToBottom();
26255
26300
  }
@@ -26402,6 +26447,7 @@ const StayliftWidget = class {
26402
26447
  endVoice: 'End Call',
26403
26448
  startText: 'Start Text Chat',
26404
26449
  endText: 'End Chat',
26450
+ viewOffer: 'View offer',
26405
26451
  },
26406
26452
  pl: {
26407
26453
  microphoneError: 'Proszę włączyć uprawnienia mikrofonu.',
@@ -26428,6 +26474,7 @@ const StayliftWidget = class {
26428
26474
  endVoice: 'Zakończ',
26429
26475
  startText: 'Rozpocznij czat',
26430
26476
  endText: 'Zakończ czat',
26477
+ viewOffer: 'Zobacz ofertę',
26431
26478
  },
26432
26479
  de: {
26433
26480
  microphoneError: 'Bitte aktivieren Sie die Mikrofonberechtigung in Ihrem Browser.',
@@ -26453,6 +26500,7 @@ const StayliftWidget = class {
26453
26500
  startVoice: 'Sprachanruf starten',
26454
26501
  endVoice: 'Beenden',
26455
26502
  startText: 'Text-Chat starten',
26503
+ viewOffer: 'Angebot ansehen',
26456
26504
  endText: 'Chat beenden',
26457
26505
  },
26458
26506
  };
@@ -26516,10 +26564,19 @@ const StayliftWidget = class {
26516
26564
  renderHeader(isTransitioning) {
26517
26565
  return (index.h("div", { class: "sl-header" }, index.h("div", { class: "sl-header-left" }, index.h("div", { class: "sl-orb-ring" }, this.avatarUrl ? (index.h("img", { src: this.avatarUrl, alt: "", class: "sl-header-avatar-img" })) : (index.h("staylift-orb", { size: 40, primaryColor: this.primaryColor, inputVolume: this.inputVolume, outputVolume: this.outputVolume, isActive: this.status === 'connected' && !this.isTextOnlyMode }))), index.h("div", { class: "sl-header-text" }, index.h("span", { class: "sl-title" }, this.brandName), index.h("span", { class: "sl-subtitle" }, this.errorMessage ? (index.h("span", { class: "sl-error" }, this.errorMessage)) : this.status === 'disconnected' ? (this.t('tapToStart')) : this.status === 'connected' ? (index.h("span", { class: "sl-connected" }, this.t('connected'))) : isTransitioning ? (index.h("span", { class: "sl-shimmer" }, this.status)) : null))), index.h("div", { class: "sl-header-right" }, index.h("div", { class: `sl-dot ${this.status === 'connected' ? 'sl-dot--active' : ''} ${isTransitioning ? 'sl-dot--pulse' : ''}` }), this.variant === 'floating' && (index.h("button", { class: "sl-close", onClick: this.handleToggleExpand }, index.h("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("path", { d: "M18 6L6 18M6 6l12 12" })))))));
26518
26566
  }
26567
+ renderOffersCarousel(offers, key, currentIdx, onChangeIdx) {
26568
+ const offer = offers[currentIdx];
26569
+ const total = offers.length;
26570
+ return (index.h("div", { class: "sl-offers-carousel", key: key }, index.h("a", { class: "sl-offer-card", href: offer.url, target: "_blank", rel: "noopener noreferrer" }, offer.photoUrl && (index.h("img", { class: "sl-offer-img", src: offer.photoUrl, alt: offer.title || '' })), index.h("div", { class: "sl-offer-body" }, offer.title && index.h("span", { class: "sl-offer-title" }, offer.title), offer.description && index.h("span", { class: "sl-offer-desc" }, offer.description), index.h("span", { class: "sl-offer-link" }, index.h("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }), index.h("polyline", { points: "15 3 21 3 21 9" }), index.h("line", { x1: "10", y1: "14", x2: "21", y2: "3" })), this.t('viewOffer')))), total > 1 && (index.h("div", { class: "sl-offers-nav" }, index.h("button", { class: "sl-offers-nav-btn", disabled: currentIdx === 0, onClick: (e) => { e.stopPropagation(); onChangeIdx(currentIdx - 1); } }, index.h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("polyline", { points: "15 18 9 12 15 6" }))), index.h("span", { class: "sl-offers-counter" }, currentIdx + 1, " / ", total), index.h("button", { class: "sl-offers-nav-btn", disabled: currentIdx === total - 1, onClick: (e) => { e.stopPropagation(); onChangeIdx(currentIdx + 1); } }, index.h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("polyline", { points: "9 18 15 12 9 6" })))))));
26571
+ }
26519
26572
  renderContent() {
26520
26573
  const isConnecting = this.status === 'connecting';
26521
26574
  const isConnected = this.status === 'connected';
26522
- return (index.h("div", { class: "sl-content", ref: (el) => this.messagesContainer = el ?? null }, this.messages.length === 0 ? (index.h("div", { class: "sl-empty" }, this.avatarUrl ? (index.h("img", { src: this.avatarUrl, alt: "", class: "sl-empty-avatar" })) : (index.h("staylift-orb", { size: 48, primaryColor: this.primaryColor, isActive: false })), index.h("h3", { class: "sl-empty-title" }, isConnecting ? this.t('starting') : isConnected ? this.t('talkOrType') : this.t('emptyTitle')), index.h("p", { class: "sl-empty-desc" }, isConnecting ? this.t('connecting') : isConnected ? this.t('ready') : this.t(this.onlyText ? 'emptyDescTextOnly' : 'emptyDesc')))) : (this.messages.map((message, index$1) => (index.h("div", { class: `sl-msg sl-msg--${message.role}`, key: index$1 }, index.h("div", { class: "sl-msg-row" }, index.h("div", { class: "sl-msg-bubble" }, message.content)), message.role === 'assistant' && (index.h("div", { class: "sl-msg-actions" }, index.h("button", { class: "sl-action", onClick: () => this.copyToClipboard(message.content, index$1) }, this.copiedIndex === index$1 ? (index.h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("polyline", { points: "20 6 9 17 4 12" }))) : (index.h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }), index.h("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }))))))))))));
26575
+ return (index.h("div", { class: "sl-content", ref: (el) => this.messagesContainer = el ?? null }, this.messages.length === 0 && !this.pinnedOffers ? (index.h("div", { class: "sl-empty" }, this.avatarUrl ? (index.h("img", { src: this.avatarUrl, alt: "", class: "sl-empty-avatar" })) : (index.h("staylift-orb", { size: 48, primaryColor: this.primaryColor, isActive: false })), index.h("h3", { class: "sl-empty-title" }, isConnecting ? this.t('starting') : isConnected ? this.t('talkOrType') : this.t('emptyTitle')), index.h("p", { class: "sl-empty-desc" }, isConnecting ? this.t('connecting') : isConnected ? this.t('ready') : this.t(this.onlyText ? 'emptyDescTextOnly' : 'emptyDesc')))) : [
26576
+ this.messages.map((message, index$1) => (index.h("div", { class: `sl-msg sl-msg--${message.role}`, key: index$1 }, message.offers && message.offers.length > 0 ? (this.renderOffersCarousel(message.offers, `msg-offers-${index$1}`, this.offerIndexes[index$1] || 0, (idx) => { this.offerIndexes = { ...this.offerIndexes, [index$1]: idx }; })) : (index.h("div", { class: "sl-msg-row" }, index.h("div", { class: "sl-msg-bubble" }, message.content))), message.role === 'assistant' && !message.offers && (index.h("div", { class: "sl-msg-actions" }, index.h("button", { class: "sl-action", onClick: () => this.copyToClipboard(message.content, index$1) }, this.copiedIndex === index$1 ? (index.h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("polyline", { points: "20 6 9 17 4 12" }))) : (index.h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, index.h("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }), index.h("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }))))))))),
26577
+ // Pinned offers — always rendered at the bottom
26578
+ this.pinnedOffers && (index.h("div", { class: "sl-msg sl-msg--assistant sl-pinned-offers", key: "pinned" }, this.renderOffersCarousel(this.pinnedOffers, 'pinned-offers', this.pinnedOfferIndex, (idx) => { this.pinnedOfferIndex = idx; this.pinnedOffers = [...this.pinnedOffers]; }))),
26579
+ ]));
26523
26580
  }
26524
26581
  renderFooter(isTransitioning) {
26525
26582
  const isDisconnected = this.status === 'disconnected';
@@ -19,7 +19,7 @@ var patchBrowser = () => {
19
19
 
20
20
  patchBrowser().then(async (options) => {
21
21
  await appGlobals.globalScripts();
22
- return index.bootstrapLazy([["staylift-orb.cjs",[[1,"staylift-orb",{"inputVolume":[2,"input-volume"],"outputVolume":[2,"output-volume"],"isActive":[4,"is-active"],"primaryColor":[1,"primary-color"],"size":[8],"animationFrame":[32]}]]],["staylift-widget.cjs",[[1,"staylift-widget",{"agentId":[1,"agent-id"],"textAgentId":[1,"text-agent-id"],"voiceAgentId":[1,"voice-agent-id"],"positionX":[1,"position-x"],"positionY":[1,"position-y"],"variant":[1],"mode":[1],"primaryColor":[1,"primary-color"],"brandName":[1,"brand-name"],"language":[1],"autoExpand":[4,"auto-expand"],"showBranding":[4,"show-branding"],"onlyText":[4,"only-text"],"avatarUrl":[1,"avatar-url"],"fabPrompt":[1,"fab-prompt"],"fabButtonText":[1,"fab-button-text"],"status":[32],"isExpanded":[32],"termsAccepted":[32],"errorMessage":[32],"inputVolume":[32],"outputVolume":[32],"messages":[32],"inputText":[32],"copiedIndex":[32],"selectedMode":[32],"startConversation":[64],"endConversation":[64],"getStatus":[64],"sendMessage":[64]}]]]], options);
22
+ return index.bootstrapLazy([["staylift-orb.cjs",[[1,"staylift-orb",{"inputVolume":[2,"input-volume"],"outputVolume":[2,"output-volume"],"isActive":[4,"is-active"],"primaryColor":[1,"primary-color"],"size":[8],"animationFrame":[32]}]]],["staylift-widget.cjs",[[1,"staylift-widget",{"agentId":[1,"agent-id"],"textAgentId":[1,"text-agent-id"],"voiceAgentId":[1,"voice-agent-id"],"positionX":[1,"position-x"],"positionY":[1,"position-y"],"variant":[1],"mode":[1],"primaryColor":[1,"primary-color"],"brandName":[1,"brand-name"],"language":[1],"autoExpand":[4,"auto-expand"],"showBranding":[4,"show-branding"],"onlyText":[4,"only-text"],"avatarUrl":[1,"avatar-url"],"fabPrompt":[1,"fab-prompt"],"fabButtonText":[1,"fab-button-text"],"status":[32],"isExpanded":[32],"termsAccepted":[32],"errorMessage":[32],"inputVolume":[32],"outputVolume":[32],"messages":[32],"inputText":[32],"copiedIndex":[32],"selectedMode":[32],"offerIndexes":[32],"pinnedOffers":[32],"startConversation":[64],"endConversation":[64],"getStatus":[64],"sendMessage":[64]}]]]], options);
23
23
  });
24
24
 
25
25
  exports.setNonce = index.setNonce;
@@ -463,6 +463,122 @@
463
463
  color: var(--sl-text);
464
464
  }
465
465
 
466
+ /* ============ OFFER CARDS ============ */
467
+
468
+ .sl-offer-card {
469
+ display: flex;
470
+ flex-direction: row;
471
+ gap: 0;
472
+ border-radius: 12px;
473
+ overflow: hidden;
474
+ border: 1px solid var(--sl-border);
475
+ background: var(--sl-surface);
476
+ text-decoration: none;
477
+ color: inherit;
478
+ cursor: pointer;
479
+ transition: border-color 0.2s, box-shadow 0.2s;
480
+ }
481
+
482
+ .sl-offer-card:hover {
483
+ border-color: var(--sl-primary);
484
+ box-shadow: 0 2px 8px rgba(0,0,0,0.12);
485
+ }
486
+
487
+ .sl-offer-img {
488
+ width: 80px;
489
+ height: 80px;
490
+ object-fit: cover;
491
+ flex-shrink: 0;
492
+ }
493
+
494
+ .sl-offer-body {
495
+ display: flex;
496
+ flex-direction: column;
497
+ gap: 2px;
498
+ padding: 8px 12px;
499
+ min-width: 0;
500
+ justify-content: center;
501
+ }
502
+
503
+ .sl-offer-title {
504
+ font-size: 13px;
505
+ font-weight: 600;
506
+ color: var(--sl-text);
507
+ line-height: 1.3;
508
+ overflow: hidden;
509
+ text-overflow: ellipsis;
510
+ white-space: nowrap;
511
+ }
512
+
513
+ .sl-offer-desc {
514
+ font-size: 12px;
515
+ color: var(--sl-muted);
516
+ line-height: 1.3;
517
+ overflow: hidden;
518
+ text-overflow: ellipsis;
519
+ display: -webkit-box;
520
+ -webkit-line-clamp: 2;
521
+ -webkit-box-orient: vertical;
522
+ }
523
+
524
+ .sl-offer-link {
525
+ display: inline-flex;
526
+ align-items: center;
527
+ gap: 4px;
528
+ font-size: 12px;
529
+ font-weight: 500;
530
+ color: var(--sl-primary);
531
+ margin-top: 2px;
532
+ }
533
+
534
+ /* ============ OFFER CAROUSEL NAV ============ */
535
+
536
+ .sl-offers-carousel {
537
+ display: flex;
538
+ flex-direction: column;
539
+ gap: 6px;
540
+ max-width: 85%;
541
+ }
542
+
543
+ .sl-offers-nav {
544
+ display: flex;
545
+ align-items: center;
546
+ justify-content: center;
547
+ gap: 8px;
548
+ }
549
+
550
+ .sl-offers-nav-btn {
551
+ width: 28px;
552
+ height: 28px;
553
+ border-radius: 50%;
554
+ border: 1px solid var(--sl-border);
555
+ background: var(--sl-surface);
556
+ color: var(--sl-text);
557
+ cursor: pointer;
558
+ display: flex;
559
+ align-items: center;
560
+ justify-content: center;
561
+ padding: 0;
562
+ transition: all 0.2s;
563
+ }
564
+
565
+ .sl-offers-nav-btn:hover:not(:disabled) {
566
+ border-color: var(--sl-primary);
567
+ color: var(--sl-primary);
568
+ }
569
+
570
+ .sl-offers-nav-btn:disabled {
571
+ opacity: 0.3;
572
+ cursor: default;
573
+ }
574
+
575
+ .sl-offers-counter {
576
+ font-size: 12px;
577
+ color: var(--sl-muted);
578
+ min-width: 40px;
579
+ text-align: center;
580
+ }
581
+
466
582
  /* ============ FOOTER ============ */
467
583
 
468
584
  .sl-footer {
@@ -31,6 +31,10 @@ export class StayliftWidget {
31
31
  this.inputText = '';
32
32
  this.copiedIndex = null;
33
33
  this.selectedMode = 'text';
34
+ this.offerIndexes = {};
35
+ this.pinnedOffers = null;
36
+ this.pinnedOfferIndex = 0;
37
+ this.pinnedMessagesRemaining = 0;
34
38
  // ============ PRIVATE ============
35
39
  this.conversation = null;
36
40
  this.volumeInterval = null;
@@ -145,6 +149,27 @@ export class StayliftWidget {
145
149
  this.conversation = await ConversationClass.startSession({
146
150
  agentId: effectiveAgentId,
147
151
  connectionType: textOnly ? 'websocket' : 'webrtc',
152
+ clientTools: {
153
+ showOffers: async (parameters) => {
154
+ console.log('[Staylift] showOffers client tool called with:', parameters);
155
+ const rawOffers = parameters.offers;
156
+ if (!rawOffers || !Array.isArray(rawOffers)) {
157
+ console.warn('[Staylift] showOffers: no offers array provided');
158
+ return 'No offers to display';
159
+ }
160
+ const offers = rawOffers.map(o => ({
161
+ url: String(o.url || ''),
162
+ photoUrl: o.photo_url ? String(o.photo_url) : undefined,
163
+ title: o.title ? String(o.title) : undefined,
164
+ description: o.description ? String(o.description) : undefined,
165
+ }));
166
+ this.pinnedOfferIndex = 0;
167
+ this.pinnedMessagesRemaining = 1;
168
+ this.pinnedOffers = offers;
169
+ this.scrollToBottom();
170
+ return `${offers.length} offer(s) displayed to user`;
171
+ },
172
+ },
148
173
  overrides: {
149
174
  conversation: {
150
175
  textOnly,
@@ -186,7 +211,27 @@ export class StayliftWidget {
186
211
  role: messageRole === 'user' ? 'user' : 'assistant',
187
212
  content: message.message,
188
213
  };
189
- this.messages = [...this.messages, chatMessage];
214
+ if (this.pinnedOffers) {
215
+ if (this.pinnedMessagesRemaining > 0) {
216
+ // Still pinned — message goes above the carousel
217
+ this.messages = [...this.messages, chatMessage];
218
+ this.pinnedMessagesRemaining--;
219
+ }
220
+ else {
221
+ // Unpin — flush offers into messages, then add new message below
222
+ const offersMessage = {
223
+ role: 'assistant',
224
+ content: '',
225
+ offers: this.pinnedOffers,
226
+ };
227
+ this.messages = [...this.messages, offersMessage, chatMessage];
228
+ this.pinnedOffers = null;
229
+ this.pinnedOfferIndex = 0;
230
+ }
231
+ }
232
+ else {
233
+ this.messages = [...this.messages, chatMessage];
234
+ }
190
235
  this.messageReceived.emit(chatMessage);
191
236
  this.scrollToBottom();
192
237
  }
@@ -339,6 +384,7 @@ export class StayliftWidget {
339
384
  endVoice: 'End Call',
340
385
  startText: 'Start Text Chat',
341
386
  endText: 'End Chat',
387
+ viewOffer: 'View offer',
342
388
  },
343
389
  pl: {
344
390
  microphoneError: 'Proszę włączyć uprawnienia mikrofonu.',
@@ -365,6 +411,7 @@ export class StayliftWidget {
365
411
  endVoice: 'Zakończ',
366
412
  startText: 'Rozpocznij czat',
367
413
  endText: 'Zakończ czat',
414
+ viewOffer: 'Zobacz ofertę',
368
415
  },
369
416
  de: {
370
417
  microphoneError: 'Bitte aktivieren Sie die Mikrofonberechtigung in Ihrem Browser.',
@@ -390,6 +437,7 @@ export class StayliftWidget {
390
437
  startVoice: 'Sprachanruf starten',
391
438
  endVoice: 'Beenden',
392
439
  startText: 'Text-Chat starten',
440
+ viewOffer: 'Angebot ansehen',
393
441
  endText: 'Chat beenden',
394
442
  },
395
443
  };
@@ -453,10 +501,19 @@ export class StayliftWidget {
453
501
  renderHeader(isTransitioning) {
454
502
  return (h("div", { class: "sl-header" }, h("div", { class: "sl-header-left" }, h("div", { class: "sl-orb-ring" }, this.avatarUrl ? (h("img", { src: this.avatarUrl, alt: "", class: "sl-header-avatar-img" })) : (h("staylift-orb", { size: 40, primaryColor: this.primaryColor, inputVolume: this.inputVolume, outputVolume: this.outputVolume, isActive: this.status === 'connected' && !this.isTextOnlyMode }))), h("div", { class: "sl-header-text" }, h("span", { class: "sl-title" }, this.brandName), h("span", { class: "sl-subtitle" }, this.errorMessage ? (h("span", { class: "sl-error" }, this.errorMessage)) : this.status === 'disconnected' ? (this.t('tapToStart')) : this.status === 'connected' ? (h("span", { class: "sl-connected" }, this.t('connected'))) : isTransitioning ? (h("span", { class: "sl-shimmer" }, this.status)) : null))), h("div", { class: "sl-header-right" }, h("div", { class: `sl-dot ${this.status === 'connected' ? 'sl-dot--active' : ''} ${isTransitioning ? 'sl-dot--pulse' : ''}` }), this.variant === 'floating' && (h("button", { class: "sl-close", onClick: this.handleToggleExpand }, h("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("path", { d: "M18 6L6 18M6 6l12 12" })))))));
455
503
  }
504
+ renderOffersCarousel(offers, key, currentIdx, onChangeIdx) {
505
+ const offer = offers[currentIdx];
506
+ const total = offers.length;
507
+ return (h("div", { class: "sl-offers-carousel", key: key }, h("a", { class: "sl-offer-card", href: offer.url, target: "_blank", rel: "noopener noreferrer" }, offer.photoUrl && (h("img", { class: "sl-offer-img", src: offer.photoUrl, alt: offer.title || '' })), h("div", { class: "sl-offer-body" }, offer.title && h("span", { class: "sl-offer-title" }, offer.title), offer.description && h("span", { class: "sl-offer-desc" }, offer.description), h("span", { class: "sl-offer-link" }, h("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }), h("polyline", { points: "15 3 21 3 21 9" }), h("line", { x1: "10", y1: "14", x2: "21", y2: "3" })), this.t('viewOffer')))), total > 1 && (h("div", { class: "sl-offers-nav" }, h("button", { class: "sl-offers-nav-btn", disabled: currentIdx === 0, onClick: (e) => { e.stopPropagation(); onChangeIdx(currentIdx - 1); } }, h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("polyline", { points: "15 18 9 12 15 6" }))), h("span", { class: "sl-offers-counter" }, currentIdx + 1, " / ", total), h("button", { class: "sl-offers-nav-btn", disabled: currentIdx === total - 1, onClick: (e) => { e.stopPropagation(); onChangeIdx(currentIdx + 1); } }, h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("polyline", { points: "9 18 15 12 9 6" })))))));
508
+ }
456
509
  renderContent() {
457
510
  const isConnecting = this.status === 'connecting';
458
511
  const isConnected = this.status === 'connected';
459
- return (h("div", { class: "sl-content", ref: (el) => this.messagesContainer = el ?? null }, this.messages.length === 0 ? (h("div", { class: "sl-empty" }, this.avatarUrl ? (h("img", { src: this.avatarUrl, alt: "", class: "sl-empty-avatar" })) : (h("staylift-orb", { size: 48, primaryColor: this.primaryColor, isActive: false })), h("h3", { class: "sl-empty-title" }, isConnecting ? this.t('starting') : isConnected ? this.t('talkOrType') : this.t('emptyTitle')), h("p", { class: "sl-empty-desc" }, isConnecting ? this.t('connecting') : isConnected ? this.t('ready') : this.t(this.onlyText ? 'emptyDescTextOnly' : 'emptyDesc')))) : (this.messages.map((message, index) => (h("div", { class: `sl-msg sl-msg--${message.role}`, key: index }, h("div", { class: "sl-msg-row" }, h("div", { class: "sl-msg-bubble" }, message.content)), message.role === 'assistant' && (h("div", { class: "sl-msg-actions" }, h("button", { class: "sl-action", onClick: () => this.copyToClipboard(message.content, index) }, this.copiedIndex === index ? (h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("polyline", { points: "20 6 9 17 4 12" }))) : (h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }), h("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }))))))))))));
512
+ return (h("div", { class: "sl-content", ref: (el) => this.messagesContainer = el ?? null }, this.messages.length === 0 && !this.pinnedOffers ? (h("div", { class: "sl-empty" }, this.avatarUrl ? (h("img", { src: this.avatarUrl, alt: "", class: "sl-empty-avatar" })) : (h("staylift-orb", { size: 48, primaryColor: this.primaryColor, isActive: false })), h("h3", { class: "sl-empty-title" }, isConnecting ? this.t('starting') : isConnected ? this.t('talkOrType') : this.t('emptyTitle')), h("p", { class: "sl-empty-desc" }, isConnecting ? this.t('connecting') : isConnected ? this.t('ready') : this.t(this.onlyText ? 'emptyDescTextOnly' : 'emptyDesc')))) : [
513
+ this.messages.map((message, index) => (h("div", { class: `sl-msg sl-msg--${message.role}`, key: index }, message.offers && message.offers.length > 0 ? (this.renderOffersCarousel(message.offers, `msg-offers-${index}`, this.offerIndexes[index] || 0, (idx) => { this.offerIndexes = { ...this.offerIndexes, [index]: idx }; })) : (h("div", { class: "sl-msg-row" }, h("div", { class: "sl-msg-bubble" }, message.content))), message.role === 'assistant' && !message.offers && (h("div", { class: "sl-msg-actions" }, h("button", { class: "sl-action", onClick: () => this.copyToClipboard(message.content, index) }, this.copiedIndex === index ? (h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("polyline", { points: "20 6 9 17 4 12" }))) : (h("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2" }, h("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }), h("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }))))))))),
514
+ // Pinned offers — always rendered at the bottom
515
+ this.pinnedOffers && (h("div", { class: "sl-msg sl-msg--assistant sl-pinned-offers", key: "pinned" }, this.renderOffersCarousel(this.pinnedOffers, 'pinned-offers', this.pinnedOfferIndex, (idx) => { this.pinnedOfferIndex = idx; this.pinnedOffers = [...this.pinnedOffers]; }))),
516
+ ]));
460
517
  }
461
518
  renderFooter(isTransitioning) {
462
519
  const isDisconnected = this.status === 'disconnected';
@@ -833,7 +890,9 @@ export class StayliftWidget {
833
890
  "messages": {},
834
891
  "inputText": {},
835
892
  "copiedIndex": {},
836
- "selectedMode": {}
893
+ "selectedMode": {},
894
+ "offerIndexes": {},
895
+ "pinnedOffers": {}
837
896
  };
838
897
  }
839
898
  static get events() {