codicent-app-sdk 0.4.5 → 0.4.6
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/cjs/components/ListView.d.ts.map +1 -1
- package/dist/cjs/components/ListView.js +1 -1
- package/dist/cjs/hooks/useRealtimeVoiceAI.js +1 -1
- package/dist/esm/components/ListView.d.ts.map +1 -1
- package/dist/esm/components/ListView.js +1 -1
- package/dist/esm/hooks/useRealtimeVoiceAI.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListView.d.ts","sourceRoot":"","sources":["../../../src/components/ListView.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAgB5D,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,kHAAkH;IAClH,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC;IAC1B,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACrD;AA2JD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IACpD,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gHAAgH;IAChH,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC7B,2HAA2H;IAC3H,MA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,EAAE,MAAM,KAAK,IAAI,CAAC;IACrH,oBAAoB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC;CAC1E;AAID,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAic5C,CAAC;;AAGF,wBAAoC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("@fluentui/react-components"),i=require("@fluentui/react-icons"),r=require("../services/codicent.js"),o=require("../hooks/useLocalization.js");const l=n.makeStyles({container:{width:"100%",overflowX:"auto",userSelect:"text"},table:{width:"100%",borderCollapse:"collapse",backgroundColor:"#ffffff",fontSize:"14px",tableLayout:"fixed",userSelect:"text"},th:{textAlign:"left",padding:"12px 8px",borderBottom:"2px solid #e0e0e0",fontWeight:"600",backgroundColor:"#f5f5f5",position:"sticky",top:0,zIndex:1,cursor:"pointer",userSelect:"none","&:hover":{backgroundColor:"#e8e8e8"}},td:{padding:"12px 8px",borderBottom:"1px solid #e0e0e0",verticalAlign:"top",wordWrap:"break-word",overflow:"hidden",userSelect:"text"},tdTruncated:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap","@media (hover: none)":{cursor:"pointer"}},tr:{"&:hover":{backgroundColor:"#f9f9f9"}},emptyState:{padding:"20px",textAlign:"center",color:"#666"},sortIndicator:{marginLeft:"4px",fontSize:"10px"},hideOnMobile:{"@media (max-width: 768px)":{display:"none"}},dialogContent:{wordWrap:"break-word",whiteSpace:"pre-wrap",maxHeight:"60vh",overflowY:"auto"},thumbnail:{maxWidth:"50px",maxHeight:"50px",objectFit:"cover"},tooltip:{maxWidth:"600px",whiteSpace:"normal",wordWrap:"break-word"},editButton:{minWidth:"auto",padding:"4px 8px"},actionsColumn:{width:"100px",textAlign:"center"},filterInput:{width:"100%",padding:"4px 8px",fontSize:"14px",border:"1px solid #e0e0e0",borderRadius:"4px",paddingRight:"28px"},filterWrapper:{position:"relative"},clearFilterButton:{position:"absolute",right:"6px",top:"50%",transform:"translateY(-50%)",minWidth:"auto",height:"20px",padding:"0 6px",lineHeight:"18px"},filterToolbar:{display:"flex",justifyContent:"flex-end",padding:"8px",gap:"8px"},cellWithAction:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"4px"},actionIcon:{minWidth:"auto",padding:"2px",marginLeft:"4px",flexShrink:0,cursor:"pointer",opacity:.7,"&:hover":{opacity:1}},cellText:{flex:1,overflow:"hidden",textOverflow:"ellipsis"}}),a=(e,t)=>{if("string"==typeof t)return e[t];for(const n of t)if(void 0!==e[n])return e[n]},s=({data:s,columns:c,canEdit:d,onEdit:p,onDelete:h,onToggleCheckbox:x,onFilteredDataChange:u})=>{const f=l(),{visibleColumns:m,defaultSortIndex:g,defaultSortDirection:j}=t.useMemo((()=>{const e=s&&s.length>0?Array.from(new Set(s.flatMap((e=>Object.keys(e))))):[],t=(c||e.map((e=>({key:e})))).filter((e=>!e.hidden)),n=t.findIndex((e=>e.defaultSort));return{visibleColumns:t,defaultSortIndex:n,defaultSortDirection:n>=0&&t[n].defaultSort||null}}),[s,c]),[y,b]=t.useState(g>=0?g:null),[w,S]=t.useState(j),[C,k]=t.useState(!1),[v,W]=t.useState({title:"",text:""}),[N,$]=t.useState({}),[M,B]=t.useState(0),{t:D}=o.default(),I=e=>e.title?D(e.title):Array.isArray(e.key)?e.key[0]:e.key,A=e=>{const t=[];return e.hideOnMobile&&t.push(f.hideOnMobile),t.join(" ")},T=e=>null==e||"string"==typeof e&&e.startsWith("[")&&e.endsWith("]")?"":"object"==typeof e?JSON.stringify(e):String(e),O=[...s];if(null!==y&&w){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("@fluentui/react-components"),i=require("@fluentui/react-icons"),r=require("../services/codicent.js"),o=require("../hooks/useLocalization.js");const l=n.makeStyles({container:{width:"100%",overflowX:"auto",userSelect:"text"},table:{width:"100%",borderCollapse:"collapse",backgroundColor:"#ffffff",fontSize:"14px",tableLayout:"fixed",userSelect:"text"},th:{textAlign:"left",padding:"12px 8px",borderBottom:"2px solid #e0e0e0",fontWeight:"600",backgroundColor:"#f5f5f5",position:"sticky",top:0,zIndex:1,cursor:"pointer",userSelect:"none","&:hover":{backgroundColor:"#e8e8e8"}},td:{padding:"12px 8px",borderBottom:"1px solid #e0e0e0",verticalAlign:"top",wordWrap:"break-word",overflow:"hidden",userSelect:"text"},tdTruncated:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap","@media (hover: none)":{cursor:"pointer"}},tr:{"&:hover":{backgroundColor:"#f9f9f9"}},emptyState:{padding:"20px",textAlign:"center",color:"#666"},sortIndicator:{marginLeft:"4px",fontSize:"10px"},hideOnMobile:{"@media (max-width: 768px)":{display:"none"}},dialogContent:{wordWrap:"break-word",whiteSpace:"pre-wrap",maxHeight:"60vh",overflowY:"auto"},thumbnail:{maxWidth:"50px",maxHeight:"50px",objectFit:"cover"},tooltip:{maxWidth:"600px",whiteSpace:"normal",wordWrap:"break-word"},editButton:{minWidth:"auto",padding:"4px 8px"},actionsColumn:{width:"100px",textAlign:"center"},filterInput:{width:"100%",padding:"4px 8px",fontSize:"14px",border:"1px solid #e0e0e0",borderRadius:"4px",paddingRight:"28px"},filterWrapper:{position:"relative"},clearFilterButton:{position:"absolute",right:"6px",top:"50%",transform:"translateY(-50%)",minWidth:"auto",height:"20px",padding:"0 6px",lineHeight:"18px"},filterToolbar:{display:"flex",justifyContent:"flex-end",padding:"8px",gap:"8px"},cellWithAction:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"4px"},actionIcon:{minWidth:"auto",padding:"2px",marginLeft:"4px",flexShrink:0,cursor:"pointer",opacity:.7,"&:hover":{opacity:1}},cellText:{flex:1,overflow:"hidden",textOverflow:"ellipsis"}}),a=(e,t)=>{if("string"==typeof t)return e[t];for(const n of t)if(void 0!==e[n])return e[n]},s=({data:s,columns:c,canEdit:d,onEdit:p,onDelete:h,onToggleCheckbox:x,onFilteredDataChange:u})=>{const f=l(),{visibleColumns:m,defaultSortIndex:g,defaultSortDirection:j}=t.useMemo((()=>{const e=s&&s.length>0?Array.from(new Set(s.flatMap((e=>Object.keys(e))))):[],t=(c||e.map((e=>({key:e})))).filter((e=>!e.hidden)),n=t.findIndex((e=>e.defaultSort));return{visibleColumns:t,defaultSortIndex:n,defaultSortDirection:n>=0&&t[n].defaultSort||null}}),[s,c]),[y,b]=t.useState(g>=0?g:null),[w,S]=t.useState(j),[C,k]=t.useState(!1),[v,W]=t.useState({title:"",text:""}),[N,$]=t.useState({}),[M,B]=t.useState(0),{t:D}=o.default(),I=e=>e.title?D(e.title):Array.isArray(e.key)?e.key[0]:e.key,A=e=>{const t=[];return e.hideOnMobile&&t.push(f.hideOnMobile),t.join(" ")},T=e=>null==e||"string"==typeof e&&e.startsWith("[")&&e.endsWith("]")?"":"object"==typeof e?JSON.stringify(e):String(e),O=t.useMemo((()=>{const e=[...s];if(null!==y&&w){const t=m[y];e.sort(((e,n)=>{const i=a(e,t.key),r=a(n,t.key);if(null==i)return 1;if(null==r)return-1;let o=0;return o="string"==typeof i&&"string"==typeof r?i.localeCompare(r):"number"==typeof i&&"number"==typeof r?i-r:String(i).localeCompare(String(r)),"asc"===w?o:-o}))}return e}),[s,y,w,m]),F=t.useMemo((()=>O.filter((e=>{for(const[t,n]of Object.entries(N)){const i=parseInt(t),r=m[i],o=a(e,r.key),l=T(o).toLowerCase(),s=n.toLowerCase();if(!l.includes(s))return!1}return!0}))),[O,N,m]);t.useEffect((()=>{u&&u(F)}),[F,u]);const L="undefined"!=typeof window?window.innerHeight-250:600,q=Math.max(0,Math.floor(M/49)-5),z=Math.min(F.length,Math.ceil((M+L)/49)+5),E=F.slice(q,z),H=49*F.length,P=49*q,R=(e,t)=>{if(void 0!==e.id)return String(e.id);return`row-${t}-${(e=>{let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)})(m.slice(0,3).map((t=>String(a(e,t.key)??""))).join("-"))}`};return s&&0!==s.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:f.container,onScroll:e=>{B(e.currentTarget.scrollTop)},style:{maxHeight:"calc(100vh - 200px)",overflowY:"auto"},children:e.jsxs("table",{className:f.table,children:[e.jsxs("thead",{children:[e.jsxs("tr",{children:[m.map(((t,n)=>{const i=t.maxWidth?{width:`${t.maxWidth}px`,maxWidth:`${t.maxWidth}px`}:{};return e.jsxs("th",{className:`${f.th} ${A(t)}`.trim(),style:i,onClick:()=>(e=>{y===e?"asc"===w?S("desc"):"desc"===w&&(b(null),S(null)):(b(e),S("asc"))})(n),children:[I(t),y===n&&e.jsx("span",{className:f.sortIndicator,children:"asc"===w?"▲":"▼"})]},n)})),d&&e.jsx("th",{className:`${f.th} ${f.actionsColumn}`,style:{width:"100px"},children:D("Actions")})]}),e.jsxs("tr",{children:[m.map(((t,i)=>{const r=t.maxWidth?{width:`${t.maxWidth}px`,maxWidth:`${t.maxWidth}px`}:{};return e.jsx("th",{className:A(t),style:r,children:t.filterable&&e.jsxs("div",{className:f.filterWrapper,children:[e.jsx("input",{type:"text",className:f.filterInput,placeholder:D("Filter")+"...",value:N[i]||"",onChange:e=>((e,t)=>{$((n=>{const i={...n};return""===t.trim()?delete i[e]:i[e]=t,i}))})(i,e.target.value),onClick:e=>e.stopPropagation()}),(N[i]||"").length>0&&e.jsx(n.Button,{appearance:"subtle",className:f.clearFilterButton,onClick:e=>{e.stopPropagation(),(e=>{$((t=>{const n={...t};return delete n[e],n}))})(i)},children:"×"})]})},i)})),d&&e.jsx("th",{className:f.actionsColumn})]})]}),e.jsxs("tbody",{children:[q>0&&e.jsx("tr",{style:{height:`${P}px`},children:e.jsx("td",{colSpan:m.length+(d?1:0),style:{padding:0,border:"none"}})}),E.map(((t,o)=>{const l=t._index,s="number"==typeof l?l:q+o;return e.jsxs("tr",{className:f.tr,children:[m.map(((i,o)=>{const l=a(t,i.key),c=i.format?i.format(l):T(l),d=i.maxWidth?`${f.td} ${f.tdTruncated} ${A(i)}`.trim():`${f.td} ${A(i)}`.trim(),p=()=>{window.matchMedia("(hover: hover)").matches||i.maxWidth&&c.length>0&&(W({title:I(i),text:c}),k(!0))};if("file"===i.type&&c)return e.jsx("td",{className:d,onClick:p,children:e.jsx("a",{href:r.CodicentService.getFileUrl(c),target:"_blank",rel:"noopener noreferrer",children:D("Download")})},o);if("checkbox"===i.type){const r=!0===l||"true"===l||"yes"===l||"1"===l;return e.jsx("td",{className:d,children:e.jsx(n.Checkbox,{checked:r,onChange:(e,n)=>{x&&x(t,i.key,!0===n.checked,s)}})},o)}const h=()=>i.maxWidth&&c.length>0?e.jsx(n.Tooltip,{content:{children:c,style:{maxWidth:"600px",whiteSpace:"normal"}},relationship:"description",children:e.jsx("span",{children:c})}):c;return e.jsx("td",{className:d,onClick:p,children:i.action?e.jsxs("div",{className:f.cellWithAction,children:[e.jsx("span",{className:f.cellText,children:h()}),(()=>{if(!i.action)return null;const r=i.action,o=i.action.icon,l=e.jsx(n.Button,{appearance:"subtle",icon:e.jsx(o,{}),className:f.actionIcon,onClick:e=>{e.stopPropagation(),r.onClick(t)},size:"small"});return r.tooltip?e.jsx(n.Tooltip,{content:D(r.tooltip),relationship:"label",children:l}):l})()]}):h()},o)})),d&&(p||h)&&e.jsx("td",{className:`${f.td} ${f.actionsColumn}`,children:e.jsxs("div",{style:{display:"flex",gap:"4px",justifyContent:"center"},children:[p&&e.jsx(n.Button,{appearance:"subtle",icon:e.jsx(i.Edit24Regular,{}),className:f.editButton,onClick:()=>p(t,s),title:D("Edit")}),h&&e.jsx(n.Button,{appearance:"subtle",icon:e.jsx(i.Delete24Regular,{}),className:f.editButton,onClick:()=>h(t,s),title:D("Delete")})]})})]},R(t,s))})),z<F.length&&e.jsx("tr",{style:{height:H-P-49*E.length+"px"},children:e.jsx("td",{colSpan:m.length+(d?1:0),style:{padding:0,border:"none"}})})]})]})}),e.jsx(n.Dialog,{open:C,onOpenChange:(e,t)=>k(t.open),children:e.jsx(n.DialogSurface,{children:e.jsxs(n.DialogBody,{children:[e.jsx(n.DialogTitle,{children:v.title}),e.jsx(n.DialogContent,{className:f.dialogContent,children:v.text})]})})})]}):e.jsx("div",{className:f.emptyState,children:D("No data to display")})};var c=t.memo(s);exports.ListView=s,exports.default=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../utils/wav_renderer.js");require("../lib/wavtools/lib/wav_packer.js"),require("../lib/wavtools/lib/analysis/audio_analysis.js");var n=require("../lib/wavtools/lib/wav_stream_player.js"),r=require("../lib/wavtools/lib/wav_recorder.js"),a=require("../config/index.js");exports.default=(o,s,i,c,l)=>{const u=!!a.getConfigValue("APP_CONFIG"),d=!!a.getConfigValue("APP_BUTTONS");u||console.warn("APP_CONFIG is not set. Voice AI will not be available."),d||console.warn("APP_BUTTONS is not set. Voice AI will not be available.");const p=a.getConfigValue("APP_CONFIG"),f=a.getConfigValue("APP_BUTTONS");a.getConfigValue("API_BASE_URL").replace(/\/$/,""),a.getConfigValue("USE_REALTIME_SESSION_ENDPOINT"),a.getConfigValue("REALTIME_SESSION_ENDPOINT");const g=c||a.getConfigValue("REALTIME_VOICE_MODEL")||"alloy",m=l||a.getConfigValue("REALTIME_VOICE_PROVIDER")||"openai",y=["alloy","shimmer","echo"],_=y.includes(g)?g:"alloy";g!==_&&console.warn(`[codicent-app-sdk] Voice "${g}" is not supported in the current SDK version. Supported voices: ${y.join(", ")}. Falling back to "${_}".`)
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../utils/wav_renderer.js");require("../lib/wavtools/lib/wav_packer.js"),require("../lib/wavtools/lib/analysis/audio_analysis.js");var n=require("../lib/wavtools/lib/wav_stream_player.js"),r=require("../lib/wavtools/lib/wav_recorder.js"),a=require("../config/index.js");exports.default=(o,s,i,c,l)=>{const u=!!a.getConfigValue("APP_CONFIG"),d=!!a.getConfigValue("APP_BUTTONS");u||console.warn("APP_CONFIG is not set. Voice AI will not be available."),d||console.warn("APP_BUTTONS is not set. Voice AI will not be available.");const p=a.getConfigValue("APP_CONFIG"),f=a.getConfigValue("APP_BUTTONS");a.getConfigValue("API_BASE_URL").replace(/\/$/,""),a.getConfigValue("USE_REALTIME_SESSION_ENDPOINT"),a.getConfigValue("REALTIME_SESSION_ENDPOINT");const g=c||a.getConfigValue("REALTIME_VOICE_MODEL")||"alloy",m=l||a.getConfigValue("REALTIME_VOICE_PROVIDER")||"openai",y=["alloy","shimmer","echo"],_=y.includes(g)?g:"alloy";g!==_&&console.warn(`[codicent-app-sdk] Voice "${g}" is not supported in the current SDK version. Supported voices: ${y.join(", ")}. Falling back to "${_}".`);const S=e.useRef(new r.WavRecorder({sampleRate:24e3})),w=e.useRef(new n.WavStreamPlayer({sampleRate:24e3})),v=e.useRef(null),h=e.useRef(null),O=e.useRef(null),R=e.useRef(null),C=e.useRef(!1),I=e.useRef(null),T=e.useRef(null),E=e.useRef(null),N=e.useRef((new Date).toISOString()),[b,A]=e.useState([]),[P,V]=e.useState([]),[k,D]=e.useState(!1),[M,x]=e.useState(!1),[F,J]=e.useState(!1),[$,L]=e.useState(!1),j=e.useRef(0),q=e.useRef(0),[U,B]=e.useState(""),[W,G]=e.useState("en-US"),H=e.useRef(new Map),z=e.useRef(null),[K,Q]=e.useState((()=>u&&d&&f&&p&&p.apps&&p.apps[f]?p.apps[f].voiceInstructions||p.REALTIME_VOICE_INSTRUCTIONS||"":p&&p.REALTIME_VOICE_INSTRUCTIONS||"")),X=e.useCallback((e=>{const t=N.current,n=new Date(t).valueOf(),r=new Date(e).valueOf()-n,a=Math.floor(r/10)%100,o=Math.floor(r/1e3)%60,s=e=>{let t=e+"";for(;t.length<2;)t="0"+t;return t};return`${s(Math.floor(r/6e4)%60)}:${s(o)}.${s(a)}`}),[]),Y=e.useCallback((async()=>{try{N.current=(new Date).toISOString(),D(!0),V([]),A([]),H.current.clear();const e=await o.getRealtimeSessionToken(_,m);if(!e)throw new Error("No ephemeral key returned from session endpoint");const t=new RTCPeerConnection;v.current=t,O.current||(O.current=new Audio,O.current.autoplay=!0),t.ontrack=e=>{O.current&&e.streams[0]&&(O.current.srcObject=e.streams[0])};const n=await navigator.mediaDevices.getUserMedia({audio:!0});R.current=n;const r=n.getTracks()[0];t.addTrack(r,n);const s=t.createDataChannel("oai-events");h.current=s,s.addEventListener("message",(e=>{try{const t=JSON.parse(e.data);if("session.created"===t.type);else if("conversation.item.created"===t.type)A((e=>[...e,t.item]));else if("conversation.item.input_audio_transcription.completed"===t.type)A((e=>{const n=[...e],r=n.findIndex((e=>e.id===t.item_id));return-1!==r&&n[r].formatted&&(n[r].formatted.transcript=t.transcript),n}));else if("response.audio_transcript.delta"===t.type);else if("response.audio_transcript.done"===t.type);else if("response.output_item.added"===t.type){const e=t.item;"function_call"===e?.type&&(console.log("[Voice AI] Function call initiated:",e.name),H.current.set(e.id,{name:e.name||"",arguments:"",call_id:e.call_id||e.id}))}else if("response.function_call_arguments.delta"===t.type){const e=t.item_id,n=t.delta,r=H.current.get(e);r&&n&&(r.arguments+=n,H.current.set(e,r))}else if("response.function_call_arguments.done"===t.type){const e=t.item_id,n=H.current.get(e);if(n){console.log(`[Voice AI] Executing tool: ${n.name}`);const t=i.find((e=>e.definition.name===n.name));if(t){let e={};try{e=n.arguments?JSON.parse(n.arguments):{}}catch(t){console.error("[Voice AI] Failed to parse tool arguments:",t),e={}}Promise.resolve(t.handler(e)).then((e=>{console.log(`[Voice AI] Tool ${n.name} completed:`,e),s&&"open"===s.readyState&&(s.send(JSON.stringify({type:"conversation.item.create",item:{type:"function_call_output",call_id:n.call_id,output:JSON.stringify(e)}})),s.send(JSON.stringify({type:"response.create"})))})).catch((e=>{console.error(`[Voice AI] Tool ${n.name} failed:`,e),s&&"open"===s.readyState&&(s.send(JSON.stringify({type:"conversation.item.create",item:{type:"function_call_output",call_id:n.call_id,output:JSON.stringify({error:e.message||"Tool execution failed"})}})),s.send(JSON.stringify({type:"response.create"})))}))}else console.error(`[Voice AI] Tool not found: ${n.name}`);H.current.delete(e)}}else"error"===t.type&&console.error("Server error:",t.error)}catch(t){console.warn("Invalid message:",e.data)}})),s.onopen=()=>{console.log("Data channel opened, configuring session");const e=z.current||K;z.current=null,s.send(JSON.stringify({type:"session.update",session:{instructions:e.replace("{{name}}",U).replace("{{language}}",W).replace("{{time}}",(new Date).toISOString()),modalities:["text","audio"],input_audio_transcription:{model:"whisper-1"},turn_detection:{type:"server_vad",threshold:.5,prefix_padding_ms:300,silence_duration_ms:500},voice:_,temperature:.8,max_response_output_tokens:4096,input_audio_format:"pcm16",output_audio_format:"pcm16",tools:i.map((e=>({type:"function",...e.definition})))}})),x(!0)},s.onclose=()=>{console.log("Data channel closed"),x(!1)};const c=await t.createOffer();await t.setLocalDescription(c);let l="gpt-4o-realtime-preview";try{if(a.getConfigValue("REALTIME_CONFIG_ENDPOINT")){const e=await o.getRealtimeConfig();e&&e.model&&(l=e.model)}}catch(e){console.warn("Failed to fetch realtime config, using default model:",e)}const u="https://api.openai.com/v1/realtime",d=await fetch(`${u}?model=${l}`,{method:"POST",body:c.sdp,headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/sdp"}});if(!d.ok)throw new Error(`Failed to get SDP answer: ${d.statusText}`);const p={type:"answer",sdp:await d.text()};await t.setRemoteDescription(p),J(!1);const f=S.current,g=w.current;await f.begin(),await g.connect()}catch(e){throw console.error("[codicent-app-sdk] Failed to establish WebRTC connection:",e),D(!1),e}}),[o,_,K,U,W,i]),Z=e.useCallback((async()=>{D(!1),x(!1),V([]),A([]),H.current.clear(),z.current=null,h.current&&(h.current.close(),h.current=null),v.current&&(v.current.close(),v.current=null),R.current&&(R.current.getTracks().forEach((e=>e.stop())),R.current=null),O.current&&(O.current.pause(),O.current.srcObject=null);const e=S.current;await e.end();const t=w.current;await t.interrupt()}),[]),ee=e.useCallback((async e=>{const t=h.current;t&&"open"===t.readyState&&t.send(JSON.stringify({type:"conversation.item.delete",item_id:e}))}),[]),te=e.useCallback((async()=>{L(!0);const e=h.current;e&&"open"===e.readyState&&e.send(JSON.stringify({type:"input_audio_buffer.commit"}))}),[]),ne=e.useCallback((async()=>{L(!1);const e=h.current;e&&"open"===e.readyState&&e.send(JSON.stringify({type:"response.create"}))}),[]),re=e.useCallback((async e=>{const t=h.current;t&&"open"===t.readyState&&t.send(JSON.stringify({type:"session.update",session:{turn_detection:"none"===e?null:{type:"server_vad"}}})),J("none"===e)}),[]);e.useEffect((()=>{if(U&&M){const e=h.current;e&&"open"===e.readyState&&e.send(JSON.stringify({type:"session.update",session:{instructions:K.replace("{{name}}",U).replace("{{language}}",W).replace("{{time}}",(new Date).toISOString())}}))}}),[K,U,W,M]),e.useEffect((()=>{let e=!0;const n=S.current,r=I.current;let a=null;const o=w.current,s=T.current;let i=null;const c=()=>{if(e){if(r&&(r.width&&r.height||(r.width=r.offsetWidth,r.height=r.offsetHeight),a=a||r.getContext("2d"),a)){a.clearRect(0,0,r.width,r.height);const e=n.recording?n.getFrequencies("voice"):{values:new Float32Array([0])},o=1-Math.max(...e.values);j.current=o,t.WavRenderer.drawCircularBars(r,a,e.values,"#0099ff",20,0,8)}if(s&&(s.width&&s.height||(s.width=s.offsetWidth,s.height=s.offsetHeight),i=i||s.getContext("2d"),i)){i.clearRect(0,0,s.width,s.height);const e=o.analyser?o.getFrequencies("voice"):{values:new Float32Array([0])},n=1-Math.max(...e.values);q.current=n,t.WavRenderer.drawCircularBars(s,i,e.values,"#009900",20,0,8)}window.requestAnimationFrame(c)}};return c(),()=>{e=!1}}),[]),e.useEffect((()=>{!C.current&&i&&K&&(C.current=!0)}),[i,K]);const ae=e.useCallback((e=>{Q(e);const t=h.current;if(t&&"open"===t.readyState){const n=e.replace("{{name}}",U).replace("{{language}}",W).replace("{{time}}",(new Date).toISOString());t.send(JSON.stringify({type:"session.update",session:{instructions:n}}))}else z.current=e}),[U,W]);return e.useMemo((()=>{if(u&&d)return{items:b,realtimeEvents:P,isConnected:k,isSessionReady:M,canPushToTalk:F,isRecording:$,clientCanvasRef:I,serverCanvasRef:T,eventsScrollRef:E,formatTime:X,connectConversation:Y,disconnectConversation:Z,deleteConversationItem:ee,startRecording:te,stopRecording:ne,changeTurnEndType:re,getRecorderLevel:()=>j.current,getStreamLevel:()=>q.current,setUsername:B,updateInstructions:ae,setLanguage:G}}),[u,d,b,P,k,M,F,$,I,T,E])};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListView.d.ts","sourceRoot":"","sources":["../../../src/components/ListView.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAgB5D,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,kHAAkH;IAClH,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC;IAC1B,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACrD;AA2JD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IACpD,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gHAAgH;IAChH,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;I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,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrH,oBAAoB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC;CAC1E;AAID,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAic5C,CAAC;;AAGF,wBAAoC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import i,{useMemo as r,useState as o,useEffect as l}from"react";import{makeStyles as a,Button as c,Checkbox as d,Dialog as s,DialogSurface as p,DialogBody as h,DialogTitle as m,DialogContent as u,Tooltip as f}from"@fluentui/react-components";import{Edit24Regular as x,Delete24Regular as g}from"@fluentui/react-icons";import{CodicentService as y}from"../services/codicent.js";import b from"../hooks/useLocalization.js";const w=a({container:{width:"100%",overflowX:"auto",userSelect:"text"},table:{width:"100%",borderCollapse:"collapse",backgroundColor:"#ffffff",fontSize:"14px",tableLayout:"fixed",userSelect:"text"},th:{textAlign:"left",padding:"12px 8px",borderBottom:"2px solid #e0e0e0",fontWeight:"600",backgroundColor:"#f5f5f5",position:"sticky",top:0,zIndex:1,cursor:"pointer",userSelect:"none","&:hover":{backgroundColor:"#e8e8e8"}},td:{padding:"12px 8px",borderBottom:"1px solid #e0e0e0",verticalAlign:"top",wordWrap:"break-word",overflow:"hidden",userSelect:"text"},tdTruncated:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap","@media (hover: none)":{cursor:"pointer"}},tr:{"&:hover":{backgroundColor:"#f9f9f9"}},emptyState:{padding:"20px",textAlign:"center",color:"#666"},sortIndicator:{marginLeft:"4px",fontSize:"10px"},hideOnMobile:{"@media (max-width: 768px)":{display:"none"}},dialogContent:{wordWrap:"break-word",whiteSpace:"pre-wrap",maxHeight:"60vh",overflowY:"auto"},thumbnail:{maxWidth:"50px",maxHeight:"50px",objectFit:"cover"},tooltip:{maxWidth:"600px",whiteSpace:"normal",wordWrap:"break-word"},editButton:{minWidth:"auto",padding:"4px 8px"},actionsColumn:{width:"100px",textAlign:"center"},filterInput:{width:"100%",padding:"4px 8px",fontSize:"14px",border:"1px solid #e0e0e0",borderRadius:"4px",paddingRight:"28px"},filterWrapper:{position:"relative"},clearFilterButton:{position:"absolute",right:"6px",top:"50%",transform:"translateY(-50%)",minWidth:"auto",height:"20px",padding:"0 6px",lineHeight:"18px"},filterToolbar:{display:"flex",justifyContent:"flex-end",padding:"8px",gap:"8px"},cellWithAction:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"4px"},actionIcon:{minWidth:"auto",padding:"2px",marginLeft:"4px",flexShrink:0,cursor:"pointer",opacity:.7,"&:hover":{opacity:1}},cellText:{flex:1,overflow:"hidden",textOverflow:"ellipsis"}}),k=(e,t)=>{if("string"==typeof t)return e[t];for(const n of t)if(void 0!==e[n])return e[n]},C=({data:i,columns:a,canEdit:C,onEdit:v,onDelete:S,onToggleCheckbox:W,onFilteredDataChange:N})=>{const $=w(),{visibleColumns:j,defaultSortIndex:I,defaultSortDirection:A}=r((()=>{const e=i&&i.length>0?Array.from(new Set(i.flatMap((e=>Object.keys(e))))):[],t=(a||e.map((e=>({key:e})))).filter((e=>!e.hidden)),n=t.findIndex((e=>e.defaultSort));return{visibleColumns:t,defaultSortIndex:n,defaultSortDirection:n>=0&&t[n].defaultSort||null}}),[i,a]),[M,O]=o(I>=0?I:null),[T,B]=o(A),[z,D]=o(!1),[F,L]=o({title:"",text:""}),[H,E]=o({}),[P,Y]=o(0),{t:R}=b(),_=e=>e.title?R(e.title):Array.isArray(e.key)?e.key[0]:e.key,J=e=>{const t=[];return e.hideOnMobile&&t.push($.hideOnMobile),t.join(" ")},U=e=>null==e||"string"==typeof e&&e.startsWith("[")&&e.endsWith("]")?"":"object"==typeof e?JSON.stringify(e):String(e),X=[...i];if(null!==M&&T){const
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import i,{useMemo as r,useState as o,useEffect as l}from"react";import{makeStyles as a,Button as c,Checkbox as d,Dialog as s,DialogSurface as p,DialogBody as h,DialogTitle as m,DialogContent as u,Tooltip as f}from"@fluentui/react-components";import{Edit24Regular as x,Delete24Regular as g}from"@fluentui/react-icons";import{CodicentService as y}from"../services/codicent.js";import b from"../hooks/useLocalization.js";const w=a({container:{width:"100%",overflowX:"auto",userSelect:"text"},table:{width:"100%",borderCollapse:"collapse",backgroundColor:"#ffffff",fontSize:"14px",tableLayout:"fixed",userSelect:"text"},th:{textAlign:"left",padding:"12px 8px",borderBottom:"2px solid #e0e0e0",fontWeight:"600",backgroundColor:"#f5f5f5",position:"sticky",top:0,zIndex:1,cursor:"pointer",userSelect:"none","&:hover":{backgroundColor:"#e8e8e8"}},td:{padding:"12px 8px",borderBottom:"1px solid #e0e0e0",verticalAlign:"top",wordWrap:"break-word",overflow:"hidden",userSelect:"text"},tdTruncated:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap","@media (hover: none)":{cursor:"pointer"}},tr:{"&:hover":{backgroundColor:"#f9f9f9"}},emptyState:{padding:"20px",textAlign:"center",color:"#666"},sortIndicator:{marginLeft:"4px",fontSize:"10px"},hideOnMobile:{"@media (max-width: 768px)":{display:"none"}},dialogContent:{wordWrap:"break-word",whiteSpace:"pre-wrap",maxHeight:"60vh",overflowY:"auto"},thumbnail:{maxWidth:"50px",maxHeight:"50px",objectFit:"cover"},tooltip:{maxWidth:"600px",whiteSpace:"normal",wordWrap:"break-word"},editButton:{minWidth:"auto",padding:"4px 8px"},actionsColumn:{width:"100px",textAlign:"center"},filterInput:{width:"100%",padding:"4px 8px",fontSize:"14px",border:"1px solid #e0e0e0",borderRadius:"4px",paddingRight:"28px"},filterWrapper:{position:"relative"},clearFilterButton:{position:"absolute",right:"6px",top:"50%",transform:"translateY(-50%)",minWidth:"auto",height:"20px",padding:"0 6px",lineHeight:"18px"},filterToolbar:{display:"flex",justifyContent:"flex-end",padding:"8px",gap:"8px"},cellWithAction:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"4px"},actionIcon:{minWidth:"auto",padding:"2px",marginLeft:"4px",flexShrink:0,cursor:"pointer",opacity:.7,"&:hover":{opacity:1}},cellText:{flex:1,overflow:"hidden",textOverflow:"ellipsis"}}),k=(e,t)=>{if("string"==typeof t)return e[t];for(const n of t)if(void 0!==e[n])return e[n]},C=({data:i,columns:a,canEdit:C,onEdit:v,onDelete:S,onToggleCheckbox:W,onFilteredDataChange:N})=>{const $=w(),{visibleColumns:j,defaultSortIndex:I,defaultSortDirection:A}=r((()=>{const e=i&&i.length>0?Array.from(new Set(i.flatMap((e=>Object.keys(e))))):[],t=(a||e.map((e=>({key:e})))).filter((e=>!e.hidden)),n=t.findIndex((e=>e.defaultSort));return{visibleColumns:t,defaultSortIndex:n,defaultSortDirection:n>=0&&t[n].defaultSort||null}}),[i,a]),[M,O]=o(I>=0?I:null),[T,B]=o(A),[z,D]=o(!1),[F,L]=o({title:"",text:""}),[H,E]=o({}),[P,Y]=o(0),{t:R}=b(),_=e=>e.title?R(e.title):Array.isArray(e.key)?e.key[0]:e.key,J=e=>{const t=[];return e.hideOnMobile&&t.push($.hideOnMobile),t.join(" ")},U=e=>null==e||"string"==typeof e&&e.startsWith("[")&&e.endsWith("]")?"":"object"==typeof e?JSON.stringify(e):String(e),X=r((()=>{const e=[...i];if(null!==M&&T){const t=j[M];e.sort(((e,n)=>{const i=k(e,t.key),r=k(n,t.key);if(null==i)return 1;if(null==r)return-1;let o=0;return o="string"==typeof i&&"string"==typeof r?i.localeCompare(r):"number"==typeof i&&"number"==typeof r?i-r:String(i).localeCompare(String(r)),"asc"===T?o:-o}))}return e}),[i,M,T,j]),q=r((()=>X.filter((e=>{for(const[t,n]of Object.entries(H)){const i=parseInt(t),r=j[i],o=k(e,r.key),l=U(o).toLowerCase(),a=n.toLowerCase();if(!l.includes(a))return!1}return!0}))),[X,H,j]);l((()=>{N&&N(q)}),[q,N]);const G="undefined"!=typeof window?window.innerHeight-250:600,K=Math.max(0,Math.floor(P/49)-5),Q=Math.min(q.length,Math.ceil((P+G)/49)+5),V=q.slice(K,Q),Z=49*q.length,ee=49*K,te=(e,t)=>{if(void 0!==e.id)return String(e.id);return`row-${t}-${(e=>{let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)})(j.slice(0,3).map((t=>String(k(e,t.key)??""))).join("-"))}`};return i&&0!==i.length?t(n,{children:[e("div",{className:$.container,onScroll:e=>{Y(e.currentTarget.scrollTop)},style:{maxHeight:"calc(100vh - 200px)",overflowY:"auto"},children:t("table",{className:$.table,children:[t("thead",{children:[t("tr",{children:[j.map(((n,i)=>{const r=n.maxWidth?{width:`${n.maxWidth}px`,maxWidth:`${n.maxWidth}px`}:{};return t("th",{className:`${$.th} ${J(n)}`.trim(),style:r,onClick:()=>(e=>{M===e?"asc"===T?B("desc"):"desc"===T&&(O(null),B(null)):(O(e),B("asc"))})(i),children:[_(n),M===i&&e("span",{className:$.sortIndicator,children:"asc"===T?"▲":"▼"})]},i)})),C&&e("th",{className:`${$.th} ${$.actionsColumn}`,style:{width:"100px"},children:R("Actions")})]}),t("tr",{children:[j.map(((n,i)=>{const r=n.maxWidth?{width:`${n.maxWidth}px`,maxWidth:`${n.maxWidth}px`}:{};return e("th",{className:J(n),style:r,children:n.filterable&&t("div",{className:$.filterWrapper,children:[e("input",{type:"text",className:$.filterInput,placeholder:R("Filter")+"...",value:H[i]||"",onChange:e=>((e,t)=>{E((n=>{const i={...n};return""===t.trim()?delete i[e]:i[e]=t,i}))})(i,e.target.value),onClick:e=>e.stopPropagation()}),(H[i]||"").length>0&&e(c,{appearance:"subtle",className:$.clearFilterButton,onClick:e=>{e.stopPropagation(),(e=>{E((t=>{const n={...t};return delete n[e],n}))})(i)},children:"×"})]})},i)})),C&&e("th",{className:$.actionsColumn})]})]}),t("tbody",{children:[K>0&&e("tr",{style:{height:`${ee}px`},children:e("td",{colSpan:j.length+(C?1:0),style:{padding:0,border:"none"}})}),V.map(((n,i)=>{const r=n._index,o="number"==typeof r?r:K+i;return t("tr",{className:$.tr,children:[j.map(((i,r)=>{const l=k(n,i.key),a=i.format?i.format(l):U(l),s=i.maxWidth?`${$.td} ${$.tdTruncated} ${J(i)}`.trim():`${$.td} ${J(i)}`.trim(),p=()=>{window.matchMedia("(hover: hover)").matches||i.maxWidth&&a.length>0&&(L({title:_(i),text:a}),D(!0))};if("file"===i.type&&a)return e("td",{className:s,onClick:p,children:e("a",{href:y.getFileUrl(a),target:"_blank",rel:"noopener noreferrer",children:R("Download")})},r);if("checkbox"===i.type){return e("td",{className:s,children:e(d,{checked:!0===l||"true"===l||"yes"===l||"1"===l,onChange:(e,t)=>{W&&W(n,i.key,!0===t.checked,o)}})},r)}const h=()=>i.maxWidth&&a.length>0?e(f,{content:{children:a,style:{maxWidth:"600px",whiteSpace:"normal"}},relationship:"description",children:e("span",{children:a})}):a;return e("td",{className:s,onClick:p,children:i.action?t("div",{className:$.cellWithAction,children:[e("span",{className:$.cellText,children:h()}),(()=>{if(!i.action)return null;const t=i.action,r=i.action.icon,o=e(c,{appearance:"subtle",icon:e(r,{}),className:$.actionIcon,onClick:e=>{e.stopPropagation(),t.onClick(n)},size:"small"});return t.tooltip?e(f,{content:R(t.tooltip),relationship:"label",children:o}):o})()]}):h()},r)})),C&&(v||S)&&e("td",{className:`${$.td} ${$.actionsColumn}`,children:t("div",{style:{display:"flex",gap:"4px",justifyContent:"center"},children:[v&&e(c,{appearance:"subtle",icon:e(x,{}),className:$.editButton,onClick:()=>v(n,o),title:R("Edit")}),S&&e(c,{appearance:"subtle",icon:e(g,{}),className:$.editButton,onClick:()=>S(n,o),title:R("Delete")})]})})]},te(n,o))})),Q<q.length&&e("tr",{style:{height:Z-ee-49*V.length+"px"},children:e("td",{colSpan:j.length+(C?1:0),style:{padding:0,border:"none"}})})]})]})}),e(s,{open:z,onOpenChange:(e,t)=>D(t.open),children:e(p,{children:t(h,{children:[e(m,{children:F.title}),e(u,{className:$.dialogContent,children:F.text})]})})})]}):e("div",{className:$.emptyState,children:R("No data to display")})};var v=i.memo(C);export{C as ListView,v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useRef as e,useState as t,useCallback as n,useEffect as r,useMemo as o}from"react";import{WavRenderer as a}from"../utils/wav_renderer.js";import"../lib/wavtools/lib/wav_packer.js";import"../lib/wavtools/lib/analysis/audio_analysis.js";import{WavStreamPlayer as s}from"../lib/wavtools/lib/wav_stream_player.js";import{WavRecorder as i}from"../lib/wavtools/lib/wav_recorder.js";import{getConfigValue as c}from"../config/index.js";const l=(l,u,d,p,m)=>{const f=!!c("APP_CONFIG"),g=!!c("APP_BUTTONS");f||console.warn("APP_CONFIG is not set. Voice AI will not be available."),g||console.warn("APP_BUTTONS is not set. Voice AI will not be available.");const y=c("APP_CONFIG"),_=c("APP_BUTTONS");c("API_BASE_URL").replace(/\/$/,""),c("USE_REALTIME_SESSION_ENDPOINT"),c("REALTIME_SESSION_ENDPOINT");const w=p||c("REALTIME_VOICE_MODEL")||"alloy",h=m||c("REALTIME_VOICE_PROVIDER")||"openai",S=["alloy","shimmer","echo"],v=S.includes(w)?w:"alloy";w!==v&&console.warn(`[codicent-app-sdk] Voice "${w}" is not supported in the current SDK version. Supported voices: ${S.join(", ")}. Falling back to "${v}".`)
|
|
1
|
+
import{useRef as e,useState as t,useCallback as n,useEffect as r,useMemo as o}from"react";import{WavRenderer as a}from"../utils/wav_renderer.js";import"../lib/wavtools/lib/wav_packer.js";import"../lib/wavtools/lib/analysis/audio_analysis.js";import{WavStreamPlayer as s}from"../lib/wavtools/lib/wav_stream_player.js";import{WavRecorder as i}from"../lib/wavtools/lib/wav_recorder.js";import{getConfigValue as c}from"../config/index.js";const l=(l,u,d,p,m)=>{const f=!!c("APP_CONFIG"),g=!!c("APP_BUTTONS");f||console.warn("APP_CONFIG is not set. Voice AI will not be available."),g||console.warn("APP_BUTTONS is not set. Voice AI will not be available.");const y=c("APP_CONFIG"),_=c("APP_BUTTONS");c("API_BASE_URL").replace(/\/$/,""),c("USE_REALTIME_SESSION_ENDPOINT"),c("REALTIME_SESSION_ENDPOINT");const w=p||c("REALTIME_VOICE_MODEL")||"alloy",h=m||c("REALTIME_VOICE_PROVIDER")||"openai",S=["alloy","shimmer","echo"],v=S.includes(w)?w:"alloy";w!==v&&console.warn(`[codicent-app-sdk] Voice "${w}" is not supported in the current SDK version. Supported voices: ${S.join(", ")}. Falling back to "${v}".`);const O=e(new i({sampleRate:24e3})),I=e(new s({sampleRate:24e3})),T=e(null),N=e(null),E=e(null),R=e(null),A=e(!1),C=e(null),P=e(null),b=e(null),D=e((new Date).toISOString()),[F,J]=t([]),[M,$]=t([]),[x,L]=t(!1),[V,k]=t(!1),[U,j]=t(!1),[B,G]=t(!1),q=e(0),W=e(0),[H,z]=t(""),[K,Q]=t("en-US"),X=e(new Map),Y=e(null),[Z,ee]=t((()=>f&&g&&_&&y&&y.apps&&y.apps[_]?y.apps[_].voiceInstructions||y.REALTIME_VOICE_INSTRUCTIONS||"":y&&y.REALTIME_VOICE_INSTRUCTIONS||"")),te=n((e=>{const t=D.current,n=new Date(t).valueOf(),r=new Date(e).valueOf()-n,o=Math.floor(r/10)%100,a=Math.floor(r/1e3)%60,s=e=>{let t=e+"";for(;t.length<2;)t="0"+t;return t};return`${s(Math.floor(r/6e4)%60)}:${s(a)}.${s(o)}`}),[]),ne=n((async()=>{try{D.current=(new Date).toISOString(),L(!0),$([]),J([]),X.current.clear();const e=await l.getRealtimeSessionToken(v,h);if(!e)throw new Error("No ephemeral key returned from session endpoint");const t=new RTCPeerConnection;T.current=t,E.current||(E.current=new Audio,E.current.autoplay=!0),t.ontrack=e=>{E.current&&e.streams[0]&&(E.current.srcObject=e.streams[0])};const n=await navigator.mediaDevices.getUserMedia({audio:!0});R.current=n;const r=n.getTracks()[0];t.addTrack(r,n);const o=t.createDataChannel("oai-events");N.current=o,o.addEventListener("message",(e=>{try{const t=JSON.parse(e.data);if("session.created"===t.type);else if("conversation.item.created"===t.type)J((e=>[...e,t.item]));else if("conversation.item.input_audio_transcription.completed"===t.type)J((e=>{const n=[...e],r=n.findIndex((e=>e.id===t.item_id));return-1!==r&&n[r].formatted&&(n[r].formatted.transcript=t.transcript),n}));else if("response.audio_transcript.delta"===t.type);else if("response.audio_transcript.done"===t.type);else if("response.output_item.added"===t.type){const e=t.item;"function_call"===e?.type&&(console.log("[Voice AI] Function call initiated:",e.name),X.current.set(e.id,{name:e.name||"",arguments:"",call_id:e.call_id||e.id}))}else if("response.function_call_arguments.delta"===t.type){const e=t.item_id,n=t.delta,r=X.current.get(e);r&&n&&(r.arguments+=n,X.current.set(e,r))}else if("response.function_call_arguments.done"===t.type){const e=t.item_id,n=X.current.get(e);if(n){console.log(`[Voice AI] Executing tool: ${n.name}`);const t=d.find((e=>e.definition.name===n.name));if(t){let e={};try{e=n.arguments?JSON.parse(n.arguments):{}}catch(t){console.error("[Voice AI] Failed to parse tool arguments:",t),e={}}Promise.resolve(t.handler(e)).then((e=>{console.log(`[Voice AI] Tool ${n.name} completed:`,e),o&&"open"===o.readyState&&(o.send(JSON.stringify({type:"conversation.item.create",item:{type:"function_call_output",call_id:n.call_id,output:JSON.stringify(e)}})),o.send(JSON.stringify({type:"response.create"})))})).catch((e=>{console.error(`[Voice AI] Tool ${n.name} failed:`,e),o&&"open"===o.readyState&&(o.send(JSON.stringify({type:"conversation.item.create",item:{type:"function_call_output",call_id:n.call_id,output:JSON.stringify({error:e.message||"Tool execution failed"})}})),o.send(JSON.stringify({type:"response.create"})))}))}else console.error(`[Voice AI] Tool not found: ${n.name}`);X.current.delete(e)}}else"error"===t.type&&console.error("Server error:",t.error)}catch(t){console.warn("Invalid message:",e.data)}})),o.onopen=()=>{console.log("Data channel opened, configuring session");const e=Y.current||Z;Y.current=null,o.send(JSON.stringify({type:"session.update",session:{instructions:e.replace("{{name}}",H).replace("{{language}}",K).replace("{{time}}",(new Date).toISOString()),modalities:["text","audio"],input_audio_transcription:{model:"whisper-1"},turn_detection:{type:"server_vad",threshold:.5,prefix_padding_ms:300,silence_duration_ms:500},voice:v,temperature:.8,max_response_output_tokens:4096,input_audio_format:"pcm16",output_audio_format:"pcm16",tools:d.map((e=>({type:"function",...e.definition})))}})),k(!0)},o.onclose=()=>{console.log("Data channel closed"),k(!1)};const a=await t.createOffer();await t.setLocalDescription(a);let s="gpt-4o-realtime-preview";try{if(c("REALTIME_CONFIG_ENDPOINT")){const e=await l.getRealtimeConfig();e&&e.model&&(s=e.model)}}catch(e){console.warn("Failed to fetch realtime config, using default model:",e)}const i="https://api.openai.com/v1/realtime",u=await fetch(`${i}?model=${s}`,{method:"POST",body:a.sdp,headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/sdp"}});if(!u.ok)throw new Error(`Failed to get SDP answer: ${u.statusText}`);const p={type:"answer",sdp:await u.text()};await t.setRemoteDescription(p),j(!1);const m=O.current,f=I.current;await m.begin(),await f.connect()}catch(e){throw console.error("[codicent-app-sdk] Failed to establish WebRTC connection:",e),L(!1),e}}),[l,v,Z,H,K,d]),re=n((async()=>{L(!1),k(!1),$([]),J([]),X.current.clear(),Y.current=null,N.current&&(N.current.close(),N.current=null),T.current&&(T.current.close(),T.current=null),R.current&&(R.current.getTracks().forEach((e=>e.stop())),R.current=null),E.current&&(E.current.pause(),E.current.srcObject=null);const e=O.current;await e.end();const t=I.current;await t.interrupt()}),[]),oe=n((async e=>{const t=N.current;t&&"open"===t.readyState&&t.send(JSON.stringify({type:"conversation.item.delete",item_id:e}))}),[]),ae=n((async()=>{G(!0);const e=N.current;e&&"open"===e.readyState&&e.send(JSON.stringify({type:"input_audio_buffer.commit"}))}),[]),se=n((async()=>{G(!1);const e=N.current;e&&"open"===e.readyState&&e.send(JSON.stringify({type:"response.create"}))}),[]),ie=n((async e=>{const t=N.current;t&&"open"===t.readyState&&t.send(JSON.stringify({type:"session.update",session:{turn_detection:"none"===e?null:{type:"server_vad"}}})),j("none"===e)}),[]);r((()=>{if(H&&V){const e=N.current;e&&"open"===e.readyState&&e.send(JSON.stringify({type:"session.update",session:{instructions:Z.replace("{{name}}",H).replace("{{language}}",K).replace("{{time}}",(new Date).toISOString())}}))}}),[Z,H,K,V]),r((()=>{let e=!0;const t=O.current,n=C.current;let r=null;const o=I.current,s=P.current;let i=null;const c=()=>{if(e){if(n&&(n.width&&n.height||(n.width=n.offsetWidth,n.height=n.offsetHeight),r=r||n.getContext("2d"),r)){r.clearRect(0,0,n.width,n.height);const e=t.recording?t.getFrequencies("voice"):{values:new Float32Array([0])},o=1-Math.max(...e.values);q.current=o,a.drawCircularBars(n,r,e.values,"#0099ff",20,0,8)}if(s&&(s.width&&s.height||(s.width=s.offsetWidth,s.height=s.offsetHeight),i=i||s.getContext("2d"),i)){i.clearRect(0,0,s.width,s.height);const e=o.analyser?o.getFrequencies("voice"):{values:new Float32Array([0])},t=1-Math.max(...e.values);W.current=t,a.drawCircularBars(s,i,e.values,"#009900",20,0,8)}window.requestAnimationFrame(c)}};return c(),()=>{e=!1}}),[]),r((()=>{!A.current&&d&&Z&&(A.current=!0)}),[d,Z]);const ce=n((e=>{ee(e);const t=N.current;if(t&&"open"===t.readyState){const n=e.replace("{{name}}",H).replace("{{language}}",K).replace("{{time}}",(new Date).toISOString());t.send(JSON.stringify({type:"session.update",session:{instructions:n}}))}else Y.current=e}),[H,K]);return o((()=>{if(f&&g)return{items:F,realtimeEvents:M,isConnected:x,isSessionReady:V,canPushToTalk:U,isRecording:B,clientCanvasRef:C,serverCanvasRef:P,eventsScrollRef:b,formatTime:te,connectConversation:ne,disconnectConversation:re,deleteConversationItem:oe,startRecording:ae,stopRecording:se,changeTurnEndType:ie,getRecorderLevel:()=>q.current,getStreamLevel:()=>W.current,setUsername:z,updateInstructions:ce,setLanguage:Q}}),[f,g,F,M,x,V,U,B,C,P,b])};export{l as default};
|