@icanbwell/baileyai-chat-ui 0.4.0 → 0.4.1-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baileyai-chat-ui.cjs +5 -5
- package/dist/baileyai-chat-ui.js +211 -191
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));const c=require("./safeMarkdownUrl-DsMPGzpD.cjs");let l=require("react"),u=require("react-markdown");u=s(u,1);let d=require("remark-gfm");d=s(d,1);let f=require("react/jsx-runtime"),p=require("@radix-ui/react-tooltip");p=s(p,1);var m=/<(search_tools|call_tool)>([\s\S]*?)<\/\1>/g,h=/<name>([\s\S]*?)<\/name>/,g=/<arguments>([\s\S]*?)<\/arguments
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));const c=require("./safeMarkdownUrl-DsMPGzpD.cjs");let l=require("react"),u=require("react-markdown");u=s(u,1);let d=require("remark-gfm");d=s(d,1);let f=require("react/jsx-runtime"),p=require("@radix-ui/react-tooltip");p=s(p,1);var m=/<(search_tools|call_tool|function_calls|function_result)>([\s\S]*?)<\/\1>/g,h=/<name>([\s\S]*?)<\/name>/,g=/<arguments>([\s\S]*?)<\/arguments>/,_=/<invoke\s+name="([^"]*)"\s*>([\s\S]*?)<\/invoke>/g,v=/<parameter\s+name="([^"]*)"\s*>([\s\S]*?)<\/parameter>/g;function y(e){let t=h.exec(e)?.[1]?.trim()||`unknown_tool`,n=g.exec(e)?.[1]?.trim();return n?{name:t,args:n}:{name:t}}function b(e){let t=[];_.lastIndex=0;let n;for(;(n=_.exec(e))!==null;){let[,e,r]=n,i={};v.lastIndex=0;let a;for(;(a=v.exec(r))!==null;)i[a[1]]=a[2].trim();let o=e.trim()||`unknown_tool`;t.push(Object.keys(i).length>0?{name:o,args:JSON.stringify(i,null,2)}:{name:o})}return t}function x(e){let t=[],n=e.replace(m,(e,n,r)=>(n===`call_tool`?t.push(y(r)):n===`search_tools`?t.push({name:`search_tools`,args:r.trim()}):n===`function_calls`?t.push(...b(r)):t.push({name:`function_result`,args:r.trim()}),``));return t.length===0?{cleanedText:n,matches:t}:{cleanedText:n.replace(/\n{3,}/g,`
|
|
2
2
|
|
|
3
|
-
`),matches:t}}function
|
|
4
|
-
`)){if(!n.startsWith(`data: `))continue;let e=n.slice(6);if(e===`[DONE]`)break;try{let n=JSON.parse(e);n?.type===`response.output_text.delta`&&n.delta&&(t+=n.delta)}catch{}}return t||null}function
|
|
3
|
+
`),matches:t}}function S(e){if(!e.startsWith(`data: `))return e;let t=``;for(let n of e.split(`
|
|
4
|
+
`)){if(!n.startsWith(`data: `))continue;let e=n.slice(6);if(e===`[DONE]`)break;try{let n=JSON.parse(e);n?.type===`response.output_text.delta`&&n.delta&&(t+=n.delta)}catch{}}return t||null}function C(e){let t=e.replace(/\r\n/g,`
|
|
5
5
|
`).split(`
|
|
6
6
|
|
|
7
7
|
`),n=t.pop()??``,r=[],i=!1;for(let e of t){let t=e.split(`
|
|
8
8
|
`).filter(e=>e.length>0),n=`message`,a=[];for(let e of t)e.startsWith(`event:`)?n=e.slice(6).trim():e.startsWith(`data:`)&&a.push(e.slice(5).trim());if(a.length===0)continue;let o=a.join(`
|
|
9
|
-
`);if(o===`[DONE]`){i=!0;continue}let s;try{s=JSON.parse(o)}catch{s=void 0}let c=s;if(n===`error`){let e=typeof c?.message==`string`?c.message:o;r.push({type:`error`,message:e})}else if(c?.type===`response.output_text.delta`&&typeof c.delta==`string`){let e=
|
|
9
|
+
`);if(o===`[DONE]`){i=!0;continue}let s;try{s=JSON.parse(o)}catch{s=void 0}let c=s;if(n===`error`){let e=typeof c?.message==`string`?c.message:o;r.push({type:`error`,message:e})}else if(c?.type===`response.output_text.delta`&&typeof c.delta==`string`){let e=S(c.delta);e&&r.push({type:`response.output_text.delta`,delta:e})}else c&&typeof c.type==`string`?r.push(c):n!==`message`&&r.push({type:`info`,message:`${n}: ${o}`})}return{events:r,remainder:n,done:i}}var w=200,T=15e4,E=(e,t,n)=>{if(e===401||e===403)return`Bailey isn't reachable with your current login.`;let r=`Bailey request failed (status ${e??`network error`}).`,i=(n||t||``).trim();return i?`${r} ${i.length>w?`${i.slice(0,w)}…`:i}`:r},D=({transport:e,model:t,instructions:n,tools:r=[],toolChoice:i,firstUserMessagePrefix:a,onAssistantMessageComplete:o,idleTimeoutMs:s=T})=>{let[c,u]=(0,l.useState)([]),[d,f]=(0,l.useState)([]),[p,m]=(0,l.useState)(null),[h,g]=(0,l.useState)(`idle`),[_,v]=(0,l.useState)(null),y=(0,l.useRef)(null),b=(0,l.useRef)(``),S=(0,l.useRef)(0),w=(0,l.useRef)([]);(0,l.useEffect)(()=>{w.current=c},[c]);let D=(0,l.useRef)(new Map),O=(0,l.useRef)(new Map),k=(0,l.useRef)(null),A=(0,l.useCallback)(()=>{k.current!==null&&(clearTimeout(k.current),k.current=null)},[]),j=(0,l.useCallback)(e=>{A(),k.current=setTimeout(()=>{e.abort(new DOMException(`The assistant took too long to respond. Please try again.`,`TimeoutError`))},s)},[A,s]),M=(0,l.useCallback)((e,t,n)=>{let r=e=>{n.push(e),f(t=>[...t,e])};if(t.type===`response.output_text.delta`){if(!t.delta)return!1;let n=D.current.get(e)??{raw:``,emittedCount:0};n.raw+=t.delta;let{cleanedText:i,matches:a}=x(n.raw),o=i.trim(),s=a.slice(n.emittedCount);if(n.emittedCount=a.length,D.current.set(e,n),O.current.set(e,o),u(t=>t.map(t=>t.id===e?{...t,content:o}:t)),s.length>0){let e=Date.now(),t=S.current;s.forEach(n=>r({kind:`pseudo_tool_call`,name:n.name,args:n.args,at:e,turnSentAt:t}))}return!0}if(t.type===`response.output_item.added`||t.type===`response.output_item.done`){let e=t.item;if(e.type===`function_call`||e.type===`mcp_call`){let n=Date.now(),i=S.current,a=e.name||`unknown_tool`;return r(t.type===`response.output_item.added`?{kind:`tool_start`,name:a,args:e.arguments,at:n,turnSentAt:i}:{kind:`tool_end`,name:a,args:e.arguments,at:n,turnSentAt:i,output:e.output,isError:e.is_error,runtimeSeconds:e.runtime_seconds}),!0}return!1}return t.type===`task.progress`?(r({kind:`progress`,status:t.status,message:t.message,at:Date.now(),turnSentAt:S.current}),!0):t.type===`response.output_text.done`||t.type===`response.created`||t.type===`response.completed`?!1:t.type===`info`?(r({kind:`info`,message:t.message,at:Date.now(),turnSentAt:S.current}),!0):(r({kind:`raw`,eventType:t.type,raw:JSON.stringify(t),at:Date.now(),turnSentAt:S.current}),!0)},[]),N=(0,l.useCallback)(async s=>{g(`streaming`),v(null);let c=Date.now();S.current=c;let l=crypto.randomUUID();u(e=>[...e,{id:l,role:`assistant`,content:``,streaming:!0,createdAt:c}]);let d=s.map((e,t)=>t===0&&e.role===`user`&&a?{role:e.role,content:`${a}${e.content}`}:{role:e.role,content:e.content});m({model:t,systemPrompt:n,messages:d,tools:r,toolChoice:i,stream:!0,sentAt:c,streamStats:{chunkCount:0,firstChunkAt:null,lastChunkAt:null}});let p=new AbortController;y.current=p,j(p);let h=``,_=null,b=!1,x=!1,w=[],T=(e,t)=>{g(`error`),v(e);let n={kind:`error`,message:e,at:Date.now(),turnSentAt:c,...t};w.push(n),f(e=>[...e,n])},k=(e,t)=>{e.forEach(e=>{if(e.type===`error`){_=e.message;let t={kind:`error`,message:e.message,at:Date.now(),turnSentAt:c};w.push(t),f(e=>[...e,t]);return}e.type===`response.output_text.delta`&&e.delta&&(x=!0),M(l,e,w)&&(b=!0)}),t&&u(e=>e.map(e=>e.id===l?{...e,streaming:!1}:e))};try{let{status:a,text:s,errorMessage:u}=await e.streamChat({model:t,instructions:n,input:d,tools:r,toolChoice:i,signal:p.signal,onChunk:e=>{j(p),h+=e;let{events:t,remainder:n,done:r}=C(h);h=n,k(t,r);let i=Date.now();m(e=>e&&e.sentAt===c?{...e,streamStats:{chunkCount:e.streamStats.chunkCount+1,firstChunkAt:e.streamStats.firstChunkAt??i,lastChunkAt:i}}:e)},onRequestId:e=>{m(t=>t&&t.sentAt===c?{...t,requestId:e}:t)}});if(h.trim()){let{events:e,done:t}=C(`${h}\n\n`);h=``,k(e,t)}if(_){g(`error`),v(_);return}if(a===void 0||a>=400){T(E(a,s,u),{httpStatus:a,rawBody:s||void 0});return}if(!b){T(`Bailey returned an empty response.`);return}if(!x){T(`Bailey ran some tools but didn't return an answer. Try asking again.`);return}g(`idle`);let f=O.current.get(l)??``;m(e=>e&&e.sentAt===c?{...e,response:{content:f}}:e),o&&await o({id:l,role:`assistant`,content:f,streaming:!1},w)}catch(e){let t=e;if(t?.name===`TimeoutError`){T(t.message,{source:`client-timeout`});return}if(t?.name===`AbortError`){g(`idle`);return}T(t?.message||`Bailey request failed.`)}finally{A(),D.current.delete(l),O.current.delete(l),u(e=>e.flatMap(e=>e.id===l?e.content?[{...e,streaming:!1}]:[]:[e]))}},[e,t,n,r,i,a,o,M,j,A]),P=(0,l.useCallback)(e=>{w.current=e,u(e)},[]);return{messages:c,traceEvents:d,lastRequest:p,status:h,error:_,send:(0,l.useCallback)(e=>{let t=e.trim();if(!t)return;b.current=t;let n=[...w.current,{id:crypto.randomUUID(),role:`user`,content:t,createdAt:Date.now()}];P(n),N(n)},[N,P]),stop:(0,l.useCallback)(()=>{y.current?.abort()},[]),retryLast:(0,l.useCallback)(()=>{if(!b.current)return;let e=w.current,t=e[e.length-1],n=t&&t.role===`assistant`?e.slice(0,-1):e;P(n),N(n)},[N,P]),clearTrace:(0,l.useCallback)(()=>f([]),[]),clearError:(0,l.useCallback)(()=>{v(null),g(e=>e===`error`?`idle`:e)},[]),newChat:(0,l.useCallback)(()=>{y.current?.abort(),P([]),f([]),m(null),g(`idle`),v(null),b.current=``},[P])}};function O(...e){return e.filter(e=>!!(e&&e.trim())).join(`
|
|
10
10
|
|
|
11
|
-
`)}var E=`call_tool`,D=`a tool`;function O(e,t){let n={name:e===E?D:e,args:null,viaCallTool:!1};if(!t)return n;let r;try{r=JSON.parse(t)}catch{return n}if(typeof r!=`object`||!r)return n;let i=r;if(e===E){let e=typeof i.name==`string`?i.name:void 0;if(!e)return n;let t=i.arguments;return{name:e,args:typeof t==`object`&&t?t:null,viaCallTool:!0}}return{name:e,args:i,viaCallTool:!1}}var k=5,A=e=>e.type===`text`?e.value??``:(e.children??[]).map(A).join(``),j=e=>{if(e.tagName===`a`&&e.properties?.href)return e.properties.href;for(let t of e.children??[]){let e=j(t);if(e)return e}},M=(e,t)=>(e.children??[]).find(e=>e.tagName===t),N=e=>{let t=A(e),n=j(e);return n?{text:t,href:n}:{text:t}},P=e=>(e.children??[]).filter(e=>e.type===`element`).map(N),F=e=>{if(e.tagName!==`table`)return null;let t=M(e,`thead`),n=t&&M(t,`tr`);return{headers:n?P(n).map(e=>e.text):[],rows:(M(e,`tbody`)?.children??[]).filter(e=>e.tagName===`tr`).map(P)}},I=e=>e.length>5,ee='When a chart would help answer a question (e.g. plotting a trend over time), include a fenced code block tagged `chartjs` containing a JSON object with this exact shape: {"type": "bar" | "line" | "pie" | "doughnut" | "scatter", "title"?: string, "data": {"labels": string[], "datasets": [{"label": string, "data": number[]}]}}. For "scatter" charts, omit "labels" and give each dataset "data" as an array of {"x": number, "y": number} points instead of a number array. "pie" and "doughnut" charts must have exactly one dataset. Do not include any other fields (no "options", no colors) — the app handles styling. Example:\n```chartjs\n{"type": "line", "title": "BP readings", "data": {"labels": ["Jul 14", "Jul 21", "Jul 28"], "datasets": [{"label": "Systolic", "data": [120, 118, 122]}]}}\n```',te=[`bar`,`line`,`pie`,`doughnut`,`scatter`],ne=8,re=50,ie=8,ae=500,oe=e=>typeof e==`object`&&!!e&&typeof e.x==`number`&&typeof e.y==`number`,L=e=>{let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=`object`||!t)return null;let n=t;if(typeof n.type!=`string`||!te.includes(n.type))return null;let r=n.type;if(n.title!==void 0&&typeof n.title!=`string`)return null;let i=n.title;if(typeof n.data!=`object`||n.data===null)return null;let a=n.data;if(!Array.isArray(a.datasets)||a.datasets.length<1||a.datasets.length>ne||(r===`pie`||r===`doughnut`)&&a.datasets.length!==1)return null;for(let e of a.datasets)if(typeof e!=`object`||!e||typeof e.label!=`string`||!Array.isArray(e.data))return null;let o=a.datasets;if(r===`scatter`){for(let e of o)if(e.data.length<1||e.data.length>ae||!e.data.every(oe))return null;return{type:r,title:i,data:{datasets:o}}}if(!Array.isArray(a.labels)||!a.labels.every(e=>typeof e==`string`))return null;let s=a.labels,c=r===`pie`||r===`doughnut`?ie:re;if(s.length<1||s.length>c)return null;for(let e of o)if(e.data.length!==s.length||!e.data.every(e=>typeof e==`number`))return null;return{type:r,title:i,data:{labels:s,datasets:o}}},R={tool_start:`Tool start`,tool_end:`Tool end`,pseudo_tool_call:`Narrated tool call`,progress:`Progress`,info:`Info`,error:`Error`,raw:`Raw event`};function z(e){return e.kind!==`tool_start`&&e.kind!==`tool_end`?null:O(e.name,e.args)}function B(e,t=z(e)){return e.kind===`pseudo_tool_call`?e.name:t?.name??null}function V(e,t=z(e)){switch(e.kind){case`tool_start`:return t.viaCallTool?`${t.name} (via call_tool)`:t.name;case`tool_end`:return`${t.viaCallTool?`${t.name} (via call_tool)`:t.name}${e.runtimeSeconds===void 0?``:` — ${e.runtimeSeconds.toFixed(2)}s`}${e.isError?` — failed`:``}`;case`pseudo_tool_call`:return`${e.name} — written as text, not actually called`;case`progress`:return e.message?`${e.status} — ${e.message}`:e.status;case`info`:return e.message;case`error`:return e.httpStatus?`${e.message} (HTTP ${e.httpStatus})`:e.message;case`raw`:return`Unrecognized event: ${e.eventType}`}}function H(e,t=z(e)){return e.kind===`tool_start`||e.kind===`tool_end`?t.args?JSON.stringify(t.args,null,2):e.args??null:e.kind===`pseudo_tool_call`?e.args??null:null}function U(e){return e.kind===`tool_end`?e.output??null:null}function W(e){return e.kind===`raw`?e.raw:e.kind===`error`?e.rawBody??null:null}function G(e){switch(e.kind){case`tool_start`:return`Calling ${O(e.name,e.args).name}...`;case`tool_end`:{let t=O(e.name,e.args).name;return e.isError?`${t} failed`:`${t} returned`}case`pseudo_tool_call`:return`${e.name} (written as text, not called)`;case`progress`:return e.message??e.status;case`info`:return e.message;case`error`:return e.source===`client-timeout`?`Timed out: ${e.message}`:`Error: ${e.message}`;case`raw`:return`Unrecognized event: ${e.eventType}`}}function K(e){let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}:${String(t.getSeconds()).padStart(2,`0`)}.${String(t.getMilliseconds()).padStart(3,`0`)}`}function q(e){if(e<=0)return`+0ms`;if(e<1e3)return`+${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`+${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`+${n}m${String(r).padStart(2,`0`)}s`}function J(e){return e.map((t,n)=>{let r=z(t),i=n===0?t.turnSentAt:e[n-1].at;return{key:`${t.at}-${n}`,kind:t.kind,toolName:B(t,r),isToolStart:t.kind===`tool_start`,failed:t.kind===`tool_end`&&t.isError===!0,time:K(t.at),gapMs:t.at-i,label:t.kind===`tool_end`&&t.isError===!0?`Tool failed`:R[t.kind],summary:V(t,r),argsDetail:H(t,r),outputDetail:U(t),rawDetail:W(t)}})}function Y(e){let t=e.filter(e=>e.kind===`tool_end`),n=t.filter(e=>e.kind===`tool_end`&&e.isError),r=e.filter(e=>e.kind===`error`),i=[];return t.length>0&&i.push(`${t.length} tool call${t.length===1?``:`s`}`+(n.length>0?`, ${n.length} failed`:``)),r.length>0&&i.push(`${r.length} stream error${r.length===1?``:`s`}`),i.join(` · `)}function X(e){let t=[];for(let n of e){let e=t[t.length-1];if(n.toolName&&e?.type===`group`&&e.toolName===n.toolName){e.rows.push(n);continue}t.push(n.toolName?{type:`group`,toolName:n.toolName,rows:[n]}:{type:`single`,row:n})}return t}function se(e){return e.some(e=>e.kind===`tool_end`&&e.isError||e.kind===`error`)}function ce(e,t){return t===void 0?[]:e.filter(e=>e.turnSentAt===t&&(e.kind===`tool_end`||e.kind===`pseudo_tool_call`||e.kind===`progress`)).map((e,t)=>({key:`${e.at}-${t}`,text:G(e),toolName:B(e)}))}function le({renderTable:e,renderChart:t}={}){return{a:({href:e,children:t})=>!e||!c.t(e)?(0,f.jsx)(f.Fragment,{children:t}):(0,f.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:t}),table:({node:t,children:n})=>{let r=t&&F(t);if(r&&I(r.rows)&&e){let t=r.rows.map(e=>e.map(e=>e.href&&!c.t(e.href)?{text:e.text}:e));return(0,f.jsx)(f.Fragment,{children:e({headers:r.headers,rows:t})})}return(0,f.jsx)(`table`,{children:n})},pre:({children:e})=>{let n=(Array.isArray(e)?e[0]:e)?.props;if((n?.className?.split(` `)??[]).includes(`language-chartjs`)&&t){let e=n?.children,r=L(Array.isArray(e)?e.join(``):String(e??``));if(r)return(0,f.jsx)(f.Fragment,{children:t(r)})}return(0,f.jsx)(`pre`,{children:e})}}}function ue({className:e}){return(0,f.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:e,"aria-hidden":`true`,children:(0,f.jsx)(`path`,{d:`M12 20.3s-7.6-4.7-10-9.4C.4 7.7 1.7 4 5.2 3.1c2.2-.6 4.4.4 5.5 2.2 1.2-1.8 3.4-2.8 5.6-2.2 3.5.9 4.8 4.6 3.2 7.8-2.4 4.7-10 9.4-10 9.4z`})})}function de({className:e}){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,f.jsx)(`path`,{d:`M7 17 17 7`}),(0,f.jsx)(`path`,{d:`M9 7h8v8`})]})}function fe({className:e}){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,f.jsx)(`rect`,{x:`8`,y:`8`,width:`12`,height:`12`,rx:`2`}),(0,f.jsx)(`path`,{d:`M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2`})]})}function pe({className:e}){return(0,f.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:(0,f.jsx)(`path`,{d:`M5 12.5 9.5 17 19 7`})})}function me({className:e}){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,f.jsx)(`path`,{d:`M8.5 12.5 11 15l4.5-5.5`})]})}var he=1500;function ge({markdown:e,className:t}){let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1),o=(0,l.useRef)(null);return(0,l.useEffect)(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]),(0,f.jsx)(p.Provider,{delayDuration:200,children:(0,f.jsxs)(p.Root,{open:n||i,onOpenChange:a,children:[(0,f.jsx)(p.Trigger,{asChild:!0,children:(0,f.jsx)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(e)}catch{}r(!0),o.current!==null&&clearTimeout(o.current),o.current=setTimeout(()=>r(!1),he)},"aria-label":`copy response as markdown`,className:`bailey-copy-button${t?` ${t}`:``}`,children:n?(0,f.jsx)(pe,{className:`bailey-copy-icon`}):(0,f.jsx)(fe,{className:`bailey-copy-icon`})})}),(0,f.jsx)(p.Portal,{children:(0,f.jsxs)(p.Content,{side:`top`,className:`bailey-tooltip-content`,children:[n?`Copied!`:`Copy as markdown`,(0,f.jsx)(p.Arrow,{className:`bailey-tooltip-arrow`})]})})]})})}async function _e(e){try{await navigator.clipboard.writeText(e)}catch{}}function ve({text:e,label:t=`Copy`}){return(0,f.jsx)(`button`,{type:`button`,onClick:()=>_e(e),className:`bailey-trace-copy-button`,children:t})}function ye(e){if(e.failed||e.kind===`error`)return`bailey-trace-chip bailey-trace-chip-error`;switch(e.kind){case`tool_start`:return`bailey-trace-chip bailey-trace-chip-info`;case`tool_end`:return`bailey-trace-chip bailey-trace-chip-success`;case`progress`:return`bailey-trace-chip bailey-trace-chip-secondary`;default:return`bailey-trace-chip bailey-trace-chip-default`}}function Z({label:e,content:t,copyable:n}){return(0,f.jsxs)(`details`,{className:`bailey-trace-disclosure`,children:[(0,f.jsx)(`summary`,{className:`bailey-trace-disclosure-summary`,children:e}),n&&(0,f.jsx)(`div`,{className:`bailey-trace-disclosure-actions`,children:(0,f.jsx)(ve,{text:t})}),(0,f.jsx)(`pre`,{className:`bailey-trace-disclosure-content`,children:t})]})}function Q({row:e}){return(0,f.jsxs)(`div`,{className:`bailey-trace-row`,children:[(0,f.jsxs)(`div`,{className:`bailey-trace-row-header`,children:[(0,f.jsx)(`span`,{className:`bailey-trace-row-time`,children:e.time}),(0,f.jsx)(`span`,{className:`bailey-trace-row-gap`,title:`Time since the previous event`,children:q(e.gapMs)}),(0,f.jsx)(`span`,{className:ye(e),children:e.label}),(0,f.jsx)(`span`,{className:`bailey-trace-row-summary`,children:e.summary})]}),e.argsDetail&&(0,f.jsx)(Z,{label:`args`,content:e.argsDetail}),e.outputDetail&&(0,f.jsx)(Z,{label:`output`,content:e.outputDetail}),e.rawDetail&&(0,f.jsx)(Z,{label:`raw`,content:e.rawDetail})]})}function be(e,t){if(e.chunkCount===0)return`Streamed: no chunks received`;if(e.chunkCount===1||e.firstChunkAt===null)return`Streamed: 1 chunk (not incremental)`;let n=e.firstChunkAt-t,r=(e.lastChunkAt??e.firstChunkAt)-e.firstChunkAt;return`Streamed: ${e.chunkCount} chunks · first chunk after ${n}ms · spread over ${(r/1e3).toFixed(1)}s`}function xe({request:e}){let t=(0,l.useMemo)(()=>JSON.stringify({model:e.model,instructions:e.systemPrompt,input:e.messages,stream:e.stream,tools:e.tools,toolChoice:e.toolChoice},null,2),[e]);return(0,f.jsxs)(`div`,{className:`bailey-trace-request-details`,children:[(0,f.jsxs)(`span`,{className:`bailey-trace-request-meta`,children:[`Last request — `,e.model,` · `,new Date(e.sentAt).toLocaleTimeString(),e.requestId?` · ${e.requestId}`:``]}),(0,f.jsx)(`span`,{className:`bailey-trace-request-meta`,children:be(e.streamStats,e.sentAt)}),(0,f.jsx)(Z,{label:`System prompt (${e.systemPrompt.length.toLocaleString()} chars)`,content:e.systemPrompt,copyable:!0}),(0,f.jsx)(Z,{label:`Messages (${e.messages.length})`,content:JSON.stringify(e.messages,null,2),copyable:!0}),e.response&&(0,f.jsx)(Z,{label:`Response (${e.response.content.length.toLocaleString()} chars)`,content:e.response.content,copyable:!0}),(0,f.jsx)(Z,{label:`Full payload (JSON)`,content:t,copyable:!0})]})}function Se({events:e,lastRequest:t,onClear:n}){let r=(0,l.useMemo)(()=>J(e),[e]),i=(0,l.useMemo)(()=>X(r),[r]),a=(0,l.useMemo)(()=>JSON.stringify(e,null,2),[e]);return(0,f.jsxs)(`div`,{className:`bailey-trace-body`,children:[(0,f.jsxs)(`div`,{className:`bailey-trace-actions-row`,children:[e.length>0&&(0,f.jsx)(ve,{text:a,label:`Copy trace as JSON`}),(0,f.jsx)(`button`,{type:`button`,onClick:n,className:`bailey-trace-copy-button`,children:`Clear`})]}),t&&(0,f.jsx)(xe,{request:t}),(0,f.jsx)(`div`,{className:`bailey-trace-rows`,children:i.map((e,t)=>{if(e.type===`single`)return(0,f.jsx)(Q,{row:e.row},e.row.key);let n=e.rows.filter(e=>e.isToolStart).length;if(n<=1)return(0,f.jsx)(`div`,{className:`bailey-trace-rows`,children:e.rows.map(e=>(0,f.jsx)(Q,{row:e},e.key))},`group-${t}`);let r=e.rows.filter(e=>e.failed).length;return(0,f.jsxs)(`details`,{className:`bailey-trace-group`,children:[(0,f.jsxs)(`summary`,{className:`bailey-trace-group-summary`,children:[(0,f.jsx)(`strong`,{children:e.toolName}),` × `,n,r>0&&(0,f.jsxs)(`span`,{className:`bailey-trace-group-failed`,children:[` `,r,` failed`]})]}),(0,f.jsx)(`div`,{className:`bailey-trace-rows`,children:e.rows.map(e=>(0,f.jsx)(Q,{row:e},e.key))})]},`group-${t}`)})})]})}function $({events:e,lastRequest:t,onClear:n}){let[r,i]=(0,l.useState)(!1),a=(0,l.useMemo)(()=>se(e),[e]),o=(0,l.useMemo)(()=>Y(e),[e]);return e.length===0&&!t?null:(0,f.jsxs)(`div`,{className:`bailey-trace-panel`,children:[(0,f.jsxs)(`div`,{className:`bailey-trace-toggle-row`,children:[(0,f.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,className:a?`bailey-trace-toggle bailey-trace-toggle-error`:`bailey-trace-toggle`,children:[a&&!r?`⚠ `:``,r?`Hide details`:`Show details`,` (`,e.length,`)`]}),o&&(0,f.jsx)(`span`,{className:a?`bailey-trace-summary bailey-trace-summary-error`:`bailey-trace-summary`,children:o})]}),r&&(0,f.jsx)(Se,{events:e,lastRequest:t,onClear:n})]})}var Ce=`How can bailey AI help you today?`,we=`Reply to bailey AI`,Te=[d.default],Ee=(0,l.memo)(function({content:e,components:t}){return(0,f.jsx)(`div`,{className:`bailey-markdown-content`,children:(0,f.jsx)(u.default,{remarkPlugins:Te,components:t,children:e})})});function De(e,t,n){if(e!==`streaming`)return;let r=t.filter(e=>e.turnSentAt===n?.sentAt);if(r.length!==0)return G(r[r.length-1])}function Oe(e){let t=new Date(e),n=t.toDateString()===new Date().toDateString(),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return n?`Today ${r}`:`${t.toLocaleDateString()} ${r}`}function ke({chat:e,placeholder:t,replyPlaceholder:n=we,suggestions:r,privacyNote:i,resolveActivityIcon:a,className:o,height:s,width:c,hideDeveloperDetails:u=!1,renderMessageActions:d,renderTable:p,renderChart:m}){let{messages:h,traceEvents:g,lastRequest:_,status:v,error:y,send:b,stop:x,retryLast:S,clearTrace:C,clearError:w,newChat:T}=e,[E,D]=(0,l.useState)(``),O=(0,l.useRef)(null),k=(0,l.useMemo)(()=>le({renderTable:p,renderChart:m}),[p,m]),A=(0,l.useMemo)(()=>De(v,g,_),[v,g,_]),j=h.length===0,M=t??(j?Ce:n);return(0,l.useEffect)(()=>{O.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[h]),(0,f.jsx)(`div`,{className:`bailey-chat-panel${o?` ${o}`:``}`,style:s!==void 0||c!==void 0?{height:s,width:c}:void 0,children:(0,f.jsxs)(`div`,{className:`bailey-chat-panel-inner`,children:[(0,f.jsx)(`div`,{className:`bailey-toolbar-row`,children:(0,f.jsx)(`button`,{type:`button`,onClick:T,disabled:h.length===0,"aria-label":`new chat`,className:`bailey-new-chat-button`,children:`New chat`})}),(0,f.jsxs)(`div`,{className:`bailey-chat-transcript`,children:[j&&(r&&r.length>0?(0,f.jsxs)(`div`,{className:`bailey-suggestions`,children:[(0,f.jsx)(`div`,{className:`bailey-suggestions-title`,children:`Suggested for you`}),r.map((e,t)=>(0,f.jsxs)(`button`,{type:`button`,onClick:()=>b(e.value??e.label),className:`bailey-suggestion-card`,children:[(0,f.jsx)(`span`,{children:e.label}),(0,f.jsx)(de,{className:`bailey-suggestion-icon`})]},`${e.label}-${t}`))]}):(0,f.jsx)(`div`,{className:`bailey-empty-state`,children:`Ask Bailey a question to get started.`})),h.map((e,t)=>{let n=e.role===`assistant`&&t===h.length-1,r=v===`streaming`&&n&&e.content===``,i=e.role===`assistant`&&!r?ce(g,e.createdAt):[],o=i[i.length-1];return(0,f.jsx)(`div`,{className:e.role===`user`?`bailey-message-row bailey-message-row-user`:`bailey-message-row`,children:e.role===`user`?(0,f.jsxs)(`div`,{className:`bailey-user-message`,children:[(0,f.jsxs)(`div`,{className:`bailey-message-meta`,children:[(0,f.jsx)(`span`,{className:`bailey-message-meta-name`,children:`You`}),e.createdAt!==void 0&&(0,f.jsx)(`span`,{children:Oe(e.createdAt)})]}),(0,f.jsx)(`div`,{className:`bailey-user-bubble`,children:e.content})]}):r?(0,f.jsx)(`div`,{className:`bailey-thinking-hint`,children:A??`Thinking…`}):(0,f.jsxs)(`div`,{className:`bailey-assistant-message`,children:[o&&(0,f.jsxs)(`div`,{className:`bailey-activity-line`,children:[(0,f.jsx)(`span`,{className:`bailey-activity-icon`,children:a?.(o.toolName)??(0,f.jsx)(me,{})}),(0,f.jsx)(`span`,{children:o.text})]}),(0,f.jsx)(Ee,{content:e.content,components:k}),e.streaming&&A&&(0,f.jsx)(`div`,{className:`bailey-streaming-hint`,children:A}),!e.streaming&&(0,f.jsxs)(`div`,{className:`bailey-message-actions`,children:[(0,f.jsx)(ge,{markdown:e.content}),d?.(e)]})]})},e.id)}),(0,f.jsx)(`div`,{ref:O})]}),j&&i&&(0,f.jsxs)(`div`,{className:`bailey-privacy-note`,children:[i.text,` `,(0,f.jsx)(`a`,{href:i.linkHref,target:`_blank`,rel:`noreferrer`,children:i.linkLabel})]}),y&&(0,f.jsxs)(`div`,{className:`bailey-error-banner`,role:`alert`,children:[(0,f.jsx)(`span`,{children:y}),(0,f.jsxs)(`div`,{className:`bailey-error-actions`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:S,className:`bailey-retry-button`,children:`Retry`}),(0,f.jsx)(`button`,{type:`button`,onClick:w,"aria-label":`dismiss error`,className:`bailey-dismiss-button`,children:`✕`})]})]}),!u&&(0,f.jsx)($,{events:g,lastRequest:_,onClear:C}),(0,f.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),!(!E.trim()||v===`streaming`)&&(b(E),D(``))},className:`bailey-input-row`,children:[(0,f.jsx)(`input`,{type:`text`,placeholder:M,"aria-label":M,value:E,onChange:e=>D(e.target.value),disabled:v===`streaming`,className:`bailey-input`}),v===`streaming`?(0,f.jsx)(`button`,{type:`button`,onClick:x,"aria-label":`stop`,className:`bailey-stop-button`,children:`Stop`}):(0,f.jsx)(`button`,{type:`submit`,"aria-label":`send`,disabled:!E.trim(),className:`bailey-send-button`,children:(0,f.jsx)(ue,{className:`bailey-send-icon`})})]})]})})}var Ae=`0.3.1-pre.2`;exports.ActivityIcon=me,exports.ArrowUpRightIcon=de,exports.BAILEYAI_CHAT_UI_VERSION=Ae,exports.BAILEY_CHART_PROMPT_FRAGMENT=ee,exports.BAILEY_TABLE_GRID_ROW_THRESHOLD=k,exports.BaileyChatPanel=ke,exports.BaileyTracePanel=$,exports.CopyMarkdownButton=ge,exports.HeartIcon=ue,exports.TRACE_KIND_LABEL=R,exports.createBaileyMarkdownComponents=le,exports.extractPseudoToolCalls=v,exports.extractTableData=F,exports.formatTraceGap=q,exports.formatTraceTime=K,exports.hasTraceFailure=se,exports.isSafeMarkdownUrl=c.t,exports.joinInstructions=T,exports.parseBaileyChartSpec=L,exports.parseSseFrames=b,exports.resolveToolCall=O,exports.shouldUseGrid=I,exports.toActivityLines=ce,exports.toTraceRows=J,exports.toTraceSegments=X,exports.traceEventArgsDetail=H,exports.traceEventHint=G,exports.traceEventOutputDetail=U,exports.traceEventRawDetail=W,exports.traceEventSummary=V,exports.traceEventToolName=B,exports.traceSummaryLine=Y,exports.useBaileyChat=w;
|
|
11
|
+
`)}var k=`call_tool`,A=`a tool`;function j(e,t){let n={name:e===k?A:e,args:null,viaCallTool:!1};if(!t)return n;let r;try{r=JSON.parse(t)}catch{return n}if(typeof r!=`object`||!r)return n;let i=r;if(e===k){let e=typeof i.name==`string`?i.name:void 0;if(!e)return n;let t=i.arguments;return{name:e,args:typeof t==`object`&&t?t:null,viaCallTool:!0}}return{name:e,args:i,viaCallTool:!1}}var M=5,N=e=>e.type===`text`?e.value??``:(e.children??[]).map(N).join(``),P=e=>{if(e.tagName===`a`&&e.properties?.href)return e.properties.href;for(let t of e.children??[]){let e=P(t);if(e)return e}},F=(e,t)=>(e.children??[]).find(e=>e.tagName===t),ee=e=>{let t=N(e),n=P(e);return n?{text:t,href:n}:{text:t}},I=e=>(e.children??[]).filter(e=>e.type===`element`).map(ee),L=e=>{if(e.tagName!==`table`)return null;let t=F(e,`thead`),n=t&&F(t,`tr`);return{headers:n?I(n).map(e=>e.text):[],rows:(F(e,`tbody`)?.children??[]).filter(e=>e.tagName===`tr`).map(I)}},R=e=>e.length>5,te='When a chart would help answer a question (e.g. plotting a trend over time), include a fenced code block tagged `chartjs` containing a JSON object with this exact shape: {"type": "bar" | "line" | "pie" | "doughnut" | "scatter", "title"?: string, "data": {"labels": string[], "datasets": [{"label": string, "data": number[]}]}}. For "scatter" charts, omit "labels" and give each dataset "data" as an array of {"x": number, "y": number} points instead of a number array. "pie" and "doughnut" charts must have exactly one dataset. Do not include any other fields (no "options", no colors) — the app handles styling. Example:\n```chartjs\n{"type": "line", "title": "BP readings", "data": {"labels": ["Jul 14", "Jul 21", "Jul 28"], "datasets": [{"label": "Systolic", "data": [120, 118, 122]}]}}\n```',ne=[`bar`,`line`,`pie`,`doughnut`,`scatter`],re=8,ie=50,ae=8,oe=500,se=e=>typeof e==`object`&&!!e&&typeof e.x==`number`&&typeof e.y==`number`,z=e=>{let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=`object`||!t)return null;let n=t;if(typeof n.type!=`string`||!ne.includes(n.type))return null;let r=n.type;if(n.title!==void 0&&typeof n.title!=`string`)return null;let i=n.title;if(typeof n.data!=`object`||n.data===null)return null;let a=n.data;if(!Array.isArray(a.datasets)||a.datasets.length<1||a.datasets.length>re||(r===`pie`||r===`doughnut`)&&a.datasets.length!==1)return null;for(let e of a.datasets)if(typeof e!=`object`||!e||typeof e.label!=`string`||!Array.isArray(e.data))return null;let o=a.datasets;if(r===`scatter`){for(let e of o)if(e.data.length<1||e.data.length>oe||!e.data.every(se))return null;return{type:r,title:i,data:{datasets:o}}}if(!Array.isArray(a.labels)||!a.labels.every(e=>typeof e==`string`))return null;let s=a.labels,c=r===`pie`||r===`doughnut`?ae:ie;if(s.length<1||s.length>c)return null;for(let e of o)if(e.data.length!==s.length||!e.data.every(e=>typeof e==`number`))return null;return{type:r,title:i,data:{labels:s,datasets:o}}},B={tool_start:`Tool start`,tool_end:`Tool end`,pseudo_tool_call:`Narrated tool call`,progress:`Progress`,info:`Info`,error:`Error`,raw:`Raw event`};function V(e){return e.kind!==`tool_start`&&e.kind!==`tool_end`?null:j(e.name,e.args)}function H(e,t=V(e)){return e.kind===`pseudo_tool_call`?e.name:t?.name??null}function U(e,t=V(e)){switch(e.kind){case`tool_start`:return t.viaCallTool?`${t.name} (via call_tool)`:t.name;case`tool_end`:return`${t.viaCallTool?`${t.name} (via call_tool)`:t.name}${e.runtimeSeconds===void 0?``:` — ${e.runtimeSeconds.toFixed(2)}s`}${e.isError?` — failed`:``}`;case`pseudo_tool_call`:return`${e.name} — written as text, not actually called`;case`progress`:return e.message?`${e.status} — ${e.message}`:e.status;case`info`:return e.message;case`error`:return e.httpStatus?`${e.message} (HTTP ${e.httpStatus})`:e.message;case`raw`:return`Unrecognized event: ${e.eventType}`}}function W(e,t=V(e)){return e.kind===`tool_start`||e.kind===`tool_end`?t.args?JSON.stringify(t.args,null,2):e.args??null:e.kind===`pseudo_tool_call`?e.args??null:null}function G(e){return e.kind===`tool_end`?e.output??null:null}function K(e){return e.kind===`raw`?e.raw:e.kind===`error`?e.rawBody??null:null}function q(e){switch(e.kind){case`tool_start`:return`Calling ${j(e.name,e.args).name}...`;case`tool_end`:{let t=j(e.name,e.args).name;return e.isError?`${t} failed`:`${t} returned`}case`pseudo_tool_call`:return`${e.name} (written as text, not called)`;case`progress`:return e.message??e.status;case`info`:return e.message;case`error`:return e.source===`client-timeout`?`Timed out: ${e.message}`:`Error: ${e.message}`;case`raw`:return`Unrecognized event: ${e.eventType}`}}function J(e){let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}:${String(t.getSeconds()).padStart(2,`0`)}.${String(t.getMilliseconds()).padStart(3,`0`)}`}function Y(e){if(e<=0)return`+0ms`;if(e<1e3)return`+${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`+${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`+${n}m${String(r).padStart(2,`0`)}s`}function X(e){return e.map((t,n)=>{let r=V(t),i=n===0?t.turnSentAt:e[n-1].at;return{key:`${t.at}-${n}`,kind:t.kind,toolName:H(t,r),isToolStart:t.kind===`tool_start`,failed:t.kind===`tool_end`&&t.isError===!0,time:J(t.at),gapMs:t.at-i,label:t.kind===`tool_end`&&t.isError===!0?`Tool failed`:B[t.kind],summary:U(t,r),argsDetail:W(t,r),outputDetail:G(t),rawDetail:K(t)}})}function ce(e){let t=e.filter(e=>e.kind===`tool_end`),n=t.filter(e=>e.kind===`tool_end`&&e.isError),r=e.filter(e=>e.kind===`error`),i=[];return t.length>0&&i.push(`${t.length} tool call${t.length===1?``:`s`}`+(n.length>0?`, ${n.length} failed`:``)),r.length>0&&i.push(`${r.length} stream error${r.length===1?``:`s`}`),i.join(` · `)}function le(e){let t=[];for(let n of e){let e=t[t.length-1];if(n.toolName&&e?.type===`group`&&e.toolName===n.toolName){e.rows.push(n);continue}t.push(n.toolName?{type:`group`,toolName:n.toolName,rows:[n]}:{type:`single`,row:n})}return t}function ue(e){return e.some(e=>e.kind===`tool_end`&&e.isError||e.kind===`error`)}function de(e,t){return t===void 0?[]:e.filter(e=>e.turnSentAt===t&&(e.kind===`tool_end`||e.kind===`pseudo_tool_call`||e.kind===`progress`)).map((e,t)=>({key:`${e.at}-${t}`,text:q(e),toolName:H(e)}))}function fe({renderTable:e,renderChart:t}={}){return{a:({href:e,children:t})=>!e||!c.t(e)?(0,f.jsx)(f.Fragment,{children:t}):(0,f.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:t}),table:({node:t,children:n})=>{let r=t&&L(t);if(r&&R(r.rows)&&e){let t=r.rows.map(e=>e.map(e=>e.href&&!c.t(e.href)?{text:e.text}:e));return(0,f.jsx)(f.Fragment,{children:e({headers:r.headers,rows:t})})}return(0,f.jsx)(`table`,{children:n})},pre:({children:e})=>{let n=(Array.isArray(e)?e[0]:e)?.props;if((n?.className?.split(` `)??[]).includes(`language-chartjs`)&&t){let e=n?.children,r=z(Array.isArray(e)?e.join(``):String(e??``));if(r)return(0,f.jsx)(f.Fragment,{children:t(r)})}return(0,f.jsx)(`pre`,{children:e})}}}function pe({className:e}){return(0,f.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:e,"aria-hidden":`true`,children:(0,f.jsx)(`path`,{d:`M12 20.3s-7.6-4.7-10-9.4C.4 7.7 1.7 4 5.2 3.1c2.2-.6 4.4.4 5.5 2.2 1.2-1.8 3.4-2.8 5.6-2.2 3.5.9 4.8 4.6 3.2 7.8-2.4 4.7-10 9.4-10 9.4z`})})}function me({className:e}){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,f.jsx)(`path`,{d:`M7 17 17 7`}),(0,f.jsx)(`path`,{d:`M9 7h8v8`})]})}function he({className:e}){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,f.jsx)(`rect`,{x:`8`,y:`8`,width:`12`,height:`12`,rx:`2`}),(0,f.jsx)(`path`,{d:`M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2`})]})}function ge({className:e}){return(0,f.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:(0,f.jsx)(`path`,{d:`M5 12.5 9.5 17 19 7`})})}function _e({className:e}){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,"aria-hidden":`true`,children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,f.jsx)(`path`,{d:`M8.5 12.5 11 15l4.5-5.5`})]})}var ve=1500;function ye({markdown:e,className:t}){let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(!1),o=(0,l.useRef)(null);return(0,l.useEffect)(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]),(0,f.jsx)(p.Provider,{delayDuration:200,children:(0,f.jsxs)(p.Root,{open:n||i,onOpenChange:a,children:[(0,f.jsx)(p.Trigger,{asChild:!0,children:(0,f.jsx)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(e)}catch{}r(!0),o.current!==null&&clearTimeout(o.current),o.current=setTimeout(()=>r(!1),ve)},"aria-label":`copy response as markdown`,className:`bailey-copy-button${t?` ${t}`:``}`,children:n?(0,f.jsx)(ge,{className:`bailey-copy-icon`}):(0,f.jsx)(he,{className:`bailey-copy-icon`})})}),(0,f.jsx)(p.Portal,{children:(0,f.jsxs)(p.Content,{side:`top`,className:`bailey-tooltip-content`,children:[n?`Copied!`:`Copy as markdown`,(0,f.jsx)(p.Arrow,{className:`bailey-tooltip-arrow`})]})})]})})}async function be(e){try{await navigator.clipboard.writeText(e)}catch{}}function xe({text:e,label:t=`Copy`}){return(0,f.jsx)(`button`,{type:`button`,onClick:()=>be(e),className:`bailey-trace-copy-button`,children:t})}function Se(e){if(e.failed||e.kind===`error`)return`bailey-trace-chip bailey-trace-chip-error`;switch(e.kind){case`tool_start`:return`bailey-trace-chip bailey-trace-chip-info`;case`tool_end`:return`bailey-trace-chip bailey-trace-chip-success`;case`progress`:return`bailey-trace-chip bailey-trace-chip-secondary`;default:return`bailey-trace-chip bailey-trace-chip-default`}}function Z({label:e,content:t,copyable:n}){return(0,f.jsxs)(`details`,{className:`bailey-trace-disclosure`,children:[(0,f.jsx)(`summary`,{className:`bailey-trace-disclosure-summary`,children:e}),n&&(0,f.jsx)(`div`,{className:`bailey-trace-disclosure-actions`,children:(0,f.jsx)(xe,{text:t})}),(0,f.jsx)(`pre`,{className:`bailey-trace-disclosure-content`,children:t})]})}function Q({row:e}){return(0,f.jsxs)(`div`,{className:`bailey-trace-row`,children:[(0,f.jsxs)(`div`,{className:`bailey-trace-row-header`,children:[(0,f.jsx)(`span`,{className:`bailey-trace-row-time`,children:e.time}),(0,f.jsx)(`span`,{className:`bailey-trace-row-gap`,title:`Time since the previous event`,children:Y(e.gapMs)}),(0,f.jsx)(`span`,{className:Se(e),children:e.label}),(0,f.jsx)(`span`,{className:`bailey-trace-row-summary`,children:e.summary})]}),e.argsDetail&&(0,f.jsx)(Z,{label:`args`,content:e.argsDetail}),e.outputDetail&&(0,f.jsx)(Z,{label:`output`,content:e.outputDetail}),e.rawDetail&&(0,f.jsx)(Z,{label:`raw`,content:e.rawDetail})]})}function Ce(e,t){if(e.chunkCount===0)return`Streamed: no chunks received`;if(e.chunkCount===1||e.firstChunkAt===null)return`Streamed: 1 chunk (not incremental)`;let n=e.firstChunkAt-t,r=(e.lastChunkAt??e.firstChunkAt)-e.firstChunkAt;return`Streamed: ${e.chunkCount} chunks · first chunk after ${n}ms · spread over ${(r/1e3).toFixed(1)}s`}function we({request:e}){let t=(0,l.useMemo)(()=>JSON.stringify({model:e.model,instructions:e.systemPrompt,input:e.messages,stream:e.stream,tools:e.tools,toolChoice:e.toolChoice},null,2),[e]);return(0,f.jsxs)(`div`,{className:`bailey-trace-request-details`,children:[(0,f.jsxs)(`span`,{className:`bailey-trace-request-meta`,children:[`Last request — `,e.model,` · `,new Date(e.sentAt).toLocaleTimeString(),e.requestId?` · ${e.requestId}`:``]}),(0,f.jsx)(`span`,{className:`bailey-trace-request-meta`,children:Ce(e.streamStats,e.sentAt)}),(0,f.jsx)(Z,{label:`System prompt (${e.systemPrompt.length.toLocaleString()} chars)`,content:e.systemPrompt,copyable:!0}),(0,f.jsx)(Z,{label:`Messages (${e.messages.length})`,content:JSON.stringify(e.messages,null,2),copyable:!0}),e.response&&(0,f.jsx)(Z,{label:`Response (${e.response.content.length.toLocaleString()} chars)`,content:e.response.content,copyable:!0}),(0,f.jsx)(Z,{label:`Full payload (JSON)`,content:t,copyable:!0})]})}function Te({events:e,lastRequest:t,onClear:n}){let r=(0,l.useMemo)(()=>X(e),[e]),i=(0,l.useMemo)(()=>le(r),[r]),a=(0,l.useMemo)(()=>JSON.stringify(e,null,2),[e]);return(0,f.jsxs)(`div`,{className:`bailey-trace-body`,children:[(0,f.jsxs)(`div`,{className:`bailey-trace-actions-row`,children:[e.length>0&&(0,f.jsx)(xe,{text:a,label:`Copy trace as JSON`}),(0,f.jsx)(`button`,{type:`button`,onClick:n,className:`bailey-trace-copy-button`,children:`Clear`})]}),t&&(0,f.jsx)(we,{request:t}),(0,f.jsx)(`div`,{className:`bailey-trace-rows`,children:i.map((e,t)=>{if(e.type===`single`)return(0,f.jsx)(Q,{row:e.row},e.row.key);let n=e.rows.filter(e=>e.isToolStart).length;if(n<=1)return(0,f.jsx)(`div`,{className:`bailey-trace-rows`,children:e.rows.map(e=>(0,f.jsx)(Q,{row:e},e.key))},`group-${t}`);let r=e.rows.filter(e=>e.failed).length;return(0,f.jsxs)(`details`,{className:`bailey-trace-group`,children:[(0,f.jsxs)(`summary`,{className:`bailey-trace-group-summary`,children:[(0,f.jsx)(`strong`,{children:e.toolName}),` × `,n,r>0&&(0,f.jsxs)(`span`,{className:`bailey-trace-group-failed`,children:[` `,r,` failed`]})]}),(0,f.jsx)(`div`,{className:`bailey-trace-rows`,children:e.rows.map(e=>(0,f.jsx)(Q,{row:e},e.key))})]},`group-${t}`)})})]})}function $({events:e,lastRequest:t,onClear:n}){let[r,i]=(0,l.useState)(!1),a=(0,l.useMemo)(()=>ue(e),[e]),o=(0,l.useMemo)(()=>ce(e),[e]);return e.length===0&&!t?null:(0,f.jsxs)(`div`,{className:`bailey-trace-panel`,children:[(0,f.jsxs)(`div`,{className:`bailey-trace-toggle-row`,children:[(0,f.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),"aria-expanded":r,className:a?`bailey-trace-toggle bailey-trace-toggle-error`:`bailey-trace-toggle`,children:[a&&!r?`⚠ `:``,r?`Hide details`:`Show details`,` (`,e.length,`)`]}),o&&(0,f.jsx)(`span`,{className:a?`bailey-trace-summary bailey-trace-summary-error`:`bailey-trace-summary`,children:o})]}),r&&(0,f.jsx)(Te,{events:e,lastRequest:t,onClear:n})]})}var Ee=`How can bailey AI help you today?`,De=`Reply to bailey AI`,Oe=[d.default],ke=(0,l.memo)(function({content:e,components:t}){return(0,f.jsx)(`div`,{className:`bailey-markdown-content`,children:(0,f.jsx)(u.default,{remarkPlugins:Oe,components:t,children:e})})});function Ae(e,t,n){if(e!==`streaming`)return;let r=t.filter(e=>e.turnSentAt===n?.sentAt);if(r.length!==0)return q(r[r.length-1])}function je(e){let t=new Date(e),n=t.toDateString()===new Date().toDateString(),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return n?`Today ${r}`:`${t.toLocaleDateString()} ${r}`}function Me({chat:e,placeholder:t,replyPlaceholder:n=De,suggestions:r,privacyNote:i,resolveActivityIcon:a,className:o,height:s,width:c,hideDeveloperDetails:u=!1,renderMessageActions:d,renderTable:p,renderChart:m}){let{messages:h,traceEvents:g,lastRequest:_,status:v,error:y,send:b,stop:x,retryLast:S,clearTrace:C,clearError:w,newChat:T}=e,[E,D]=(0,l.useState)(``),O=(0,l.useRef)(null),k=(0,l.useMemo)(()=>fe({renderTable:p,renderChart:m}),[p,m]),A=(0,l.useMemo)(()=>Ae(v,g,_),[v,g,_]),j=h.length===0,M=t??(j?Ee:n);return(0,l.useEffect)(()=>{O.current?.scrollIntoView({behavior:`smooth`,block:`nearest`})},[h]),(0,f.jsx)(`div`,{className:`bailey-chat-panel${o?` ${o}`:``}`,style:s!==void 0||c!==void 0?{height:s,width:c}:void 0,children:(0,f.jsxs)(`div`,{className:`bailey-chat-panel-inner`,children:[(0,f.jsx)(`div`,{className:`bailey-toolbar-row`,children:(0,f.jsx)(`button`,{type:`button`,onClick:T,disabled:h.length===0,"aria-label":`new chat`,className:`bailey-new-chat-button`,children:`New chat`})}),(0,f.jsxs)(`div`,{className:`bailey-chat-transcript`,children:[j&&(r&&r.length>0?(0,f.jsxs)(`div`,{className:`bailey-suggestions`,children:[(0,f.jsx)(`div`,{className:`bailey-suggestions-title`,children:`Suggested for you`}),r.map((e,t)=>(0,f.jsxs)(`button`,{type:`button`,onClick:()=>b(e.value??e.label),className:`bailey-suggestion-card`,children:[(0,f.jsx)(`span`,{children:e.label}),(0,f.jsx)(me,{className:`bailey-suggestion-icon`})]},`${e.label}-${t}`))]}):(0,f.jsx)(`div`,{className:`bailey-empty-state`,children:`Ask Bailey a question to get started.`})),h.map((e,t)=>{let n=e.role===`assistant`&&t===h.length-1,r=v===`streaming`&&n&&e.content===``,i=e.role===`assistant`&&!r?de(g,e.createdAt):[],o=i[i.length-1];return(0,f.jsx)(`div`,{className:e.role===`user`?`bailey-message-row bailey-message-row-user`:`bailey-message-row`,children:e.role===`user`?(0,f.jsxs)(`div`,{className:`bailey-user-message`,children:[(0,f.jsxs)(`div`,{className:`bailey-message-meta`,children:[(0,f.jsx)(`span`,{className:`bailey-message-meta-name`,children:`You`}),e.createdAt!==void 0&&(0,f.jsx)(`span`,{children:je(e.createdAt)})]}),(0,f.jsx)(`div`,{className:`bailey-user-bubble`,children:e.content})]}):r?(0,f.jsx)(`div`,{className:`bailey-thinking-hint`,children:A??`Thinking…`}):(0,f.jsxs)(`div`,{className:`bailey-assistant-message`,children:[o&&(0,f.jsxs)(`div`,{className:`bailey-activity-line`,children:[(0,f.jsx)(`span`,{className:`bailey-activity-icon`,children:a?.(o.toolName)??(0,f.jsx)(_e,{})}),(0,f.jsx)(`span`,{children:o.text})]}),(0,f.jsx)(ke,{content:e.content,components:k}),e.streaming&&A&&(0,f.jsx)(`div`,{className:`bailey-streaming-hint`,children:A}),!e.streaming&&(0,f.jsxs)(`div`,{className:`bailey-message-actions`,children:[(0,f.jsx)(ye,{markdown:e.content}),d?.(e)]})]})},e.id)}),(0,f.jsx)(`div`,{ref:O})]}),j&&i&&(0,f.jsxs)(`div`,{className:`bailey-privacy-note`,children:[i.text,` `,(0,f.jsx)(`a`,{href:i.linkHref,target:`_blank`,rel:`noreferrer`,children:i.linkLabel})]}),y&&(0,f.jsxs)(`div`,{className:`bailey-error-banner`,role:`alert`,children:[(0,f.jsx)(`span`,{children:y}),(0,f.jsxs)(`div`,{className:`bailey-error-actions`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:S,className:`bailey-retry-button`,children:`Retry`}),(0,f.jsx)(`button`,{type:`button`,onClick:w,"aria-label":`dismiss error`,className:`bailey-dismiss-button`,children:`✕`})]})]}),!u&&(0,f.jsx)($,{events:g,lastRequest:_,onClear:C}),(0,f.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),!(!E.trim()||v===`streaming`)&&(b(E),D(``))},className:`bailey-input-row`,children:[(0,f.jsx)(`input`,{type:`text`,placeholder:M,"aria-label":M,value:E,onChange:e=>D(e.target.value),disabled:v===`streaming`,className:`bailey-input`}),v===`streaming`?(0,f.jsx)(`button`,{type:`button`,onClick:x,"aria-label":`stop`,className:`bailey-stop-button`,children:`Stop`}):(0,f.jsx)(`button`,{type:`submit`,"aria-label":`send`,disabled:!E.trim(),className:`bailey-send-button`,children:(0,f.jsx)(pe,{className:`bailey-send-icon`})})]})]})})}var Ne=`0.3.1-pre.2`;exports.ActivityIcon=_e,exports.ArrowUpRightIcon=me,exports.BAILEYAI_CHAT_UI_VERSION=Ne,exports.BAILEY_CHART_PROMPT_FRAGMENT=te,exports.BAILEY_TABLE_GRID_ROW_THRESHOLD=M,exports.BaileyChatPanel=Me,exports.BaileyTracePanel=$,exports.CopyMarkdownButton=ye,exports.HeartIcon=pe,exports.TRACE_KIND_LABEL=B,exports.createBaileyMarkdownComponents=fe,exports.extractPseudoToolCalls=x,exports.extractTableData=L,exports.formatTraceGap=Y,exports.formatTraceTime=J,exports.hasTraceFailure=ue,exports.isSafeMarkdownUrl=c.t,exports.joinInstructions=O,exports.parseBaileyChartSpec=z,exports.parseSseFrames=C,exports.resolveToolCall=j,exports.shouldUseGrid=R,exports.toActivityLines=de,exports.toTraceRows=X,exports.toTraceSegments=le,exports.traceEventArgsDetail=W,exports.traceEventHint=q,exports.traceEventOutputDetail=G,exports.traceEventRawDetail=K,exports.traceEventSummary=U,exports.traceEventToolName=H,exports.traceSummaryLine=ce,exports.useBaileyChat=D;
|
package/dist/baileyai-chat-ui.js
CHANGED
|
@@ -5,18 +5,38 @@ import c from "remark-gfm";
|
|
|
5
5
|
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
6
6
|
import * as f from "@radix-ui/react-tooltip";
|
|
7
7
|
//#region src/utils/pseudoToolCalls.ts
|
|
8
|
-
var p = /<(search_tools|call_tool)>([\s\S]*?)<\/\1>/g, m = /<name>([\s\S]*?)<\/name>/, h = /<arguments>([\s\S]*?)<\/arguments
|
|
9
|
-
function
|
|
8
|
+
var p = /<(search_tools|call_tool|function_calls|function_result)>([\s\S]*?)<\/\1>/g, m = /<name>([\s\S]*?)<\/name>/, h = /<arguments>([\s\S]*?)<\/arguments>/, g = /<invoke\s+name="([^"]*)"\s*>([\s\S]*?)<\/invoke>/g, _ = /<parameter\s+name="([^"]*)"\s*>([\s\S]*?)<\/parameter>/g;
|
|
9
|
+
function v(e) {
|
|
10
10
|
let t = m.exec(e)?.[1]?.trim() || "unknown_tool", n = h.exec(e)?.[1]?.trim();
|
|
11
11
|
return n ? {
|
|
12
12
|
name: t,
|
|
13
13
|
args: n
|
|
14
14
|
} : { name: t };
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
let t = []
|
|
16
|
+
function y(e) {
|
|
17
|
+
let t = [];
|
|
18
|
+
g.lastIndex = 0;
|
|
19
|
+
let n;
|
|
20
|
+
for (; (n = g.exec(e)) !== null;) {
|
|
21
|
+
let [, e, r] = n, i = {};
|
|
22
|
+
_.lastIndex = 0;
|
|
23
|
+
let a;
|
|
24
|
+
for (; (a = _.exec(r)) !== null;) i[a[1]] = a[2].trim();
|
|
25
|
+
let o = e.trim() || "unknown_tool";
|
|
26
|
+
t.push(Object.keys(i).length > 0 ? {
|
|
27
|
+
name: o,
|
|
28
|
+
args: JSON.stringify(i, null, 2)
|
|
29
|
+
} : { name: o });
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
}
|
|
33
|
+
function b(e) {
|
|
34
|
+
let t = [], n = e.replace(p, (e, n, r) => (n === "call_tool" ? t.push(v(r)) : n === "search_tools" ? t.push({
|
|
18
35
|
name: "search_tools",
|
|
19
36
|
args: r.trim()
|
|
37
|
+
}) : n === "function_calls" ? t.push(...y(r)) : t.push({
|
|
38
|
+
name: "function_result",
|
|
39
|
+
args: r.trim()
|
|
20
40
|
}), ""));
|
|
21
41
|
return t.length === 0 ? {
|
|
22
42
|
cleanedText: n,
|
|
@@ -28,7 +48,7 @@ function _(e) {
|
|
|
28
48
|
}
|
|
29
49
|
//#endregion
|
|
30
50
|
//#region src/logic/sse.ts
|
|
31
|
-
function
|
|
51
|
+
function x(e) {
|
|
32
52
|
if (!e.startsWith("data: ")) return e;
|
|
33
53
|
let t = "";
|
|
34
54
|
for (let n of e.split("\n")) {
|
|
@@ -42,7 +62,7 @@ function v(e) {
|
|
|
42
62
|
}
|
|
43
63
|
return t || null;
|
|
44
64
|
}
|
|
45
|
-
function
|
|
65
|
+
function S(e) {
|
|
46
66
|
let t = e.replace(/\r\n/g, "\n").split("\n\n"), n = t.pop() ?? "", r = [], i = !1;
|
|
47
67
|
for (let e of t) {
|
|
48
68
|
let t = e.split("\n").filter((e) => e.length > 0), n = "message", a = [];
|
|
@@ -67,7 +87,7 @@ function y(e) {
|
|
|
67
87
|
message: e
|
|
68
88
|
});
|
|
69
89
|
} else if (c?.type === "response.output_text.delta" && typeof c.delta == "string") {
|
|
70
|
-
let e =
|
|
90
|
+
let e = x(c.delta);
|
|
71
91
|
e && r.push({
|
|
72
92
|
type: "response.output_text.delta",
|
|
73
93
|
delta: e
|
|
@@ -85,38 +105,38 @@ function y(e) {
|
|
|
85
105
|
}
|
|
86
106
|
//#endregion
|
|
87
107
|
//#region src/logic/useBaileyChat.ts
|
|
88
|
-
var
|
|
108
|
+
var C = 200, w = 15e4, ee = (e, t, n) => {
|
|
89
109
|
if (e === 401 || e === 403) return "Bailey isn't reachable with your current login.";
|
|
90
110
|
let r = `Bailey request failed (status ${e ?? "network error"}).`, i = (n || t || "").trim();
|
|
91
|
-
return i ? `${r} ${i.length >
|
|
92
|
-
},
|
|
93
|
-
let [f, p] = o([]), [m, h] = o([]), [g,
|
|
111
|
+
return i ? `${r} ${i.length > C ? `${i.slice(0, C)}…` : i}` : r;
|
|
112
|
+
}, T = ({ transport: e, model: t, instructions: i, tools: s = [], toolChoice: c, firstUserMessagePrefix: l, onAssistantMessageComplete: u, idleTimeoutMs: d = w }) => {
|
|
113
|
+
let [f, p] = o([]), [m, h] = o([]), [g, _] = o(null), [v, y] = o("idle"), [x, C] = o(null), T = a(null), E = a(""), D = a(0), O = a([]);
|
|
94
114
|
r(() => {
|
|
95
|
-
|
|
115
|
+
O.current = f;
|
|
96
116
|
}, [f]);
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
}, []),
|
|
100
|
-
|
|
117
|
+
let k = a(/* @__PURE__ */ new Map()), A = a(/* @__PURE__ */ new Map()), j = a(null), M = n(() => {
|
|
118
|
+
j.current !== null && (clearTimeout(j.current), j.current = null);
|
|
119
|
+
}, []), N = n((e) => {
|
|
120
|
+
M(), j.current = setTimeout(() => {
|
|
101
121
|
e.abort(new DOMException("The assistant took too long to respond. Please try again.", "TimeoutError"));
|
|
102
122
|
}, d);
|
|
103
|
-
}, [
|
|
123
|
+
}, [M, d]), P = n((e, t, n) => {
|
|
104
124
|
let r = (e) => {
|
|
105
125
|
n.push(e), h((t) => [...t, e]);
|
|
106
126
|
};
|
|
107
127
|
if (t.type === "response.output_text.delta") {
|
|
108
128
|
if (!t.delta) return !1;
|
|
109
|
-
let n =
|
|
129
|
+
let n = k.current.get(e) ?? {
|
|
110
130
|
raw: "",
|
|
111
131
|
emittedCount: 0
|
|
112
132
|
};
|
|
113
133
|
n.raw += t.delta;
|
|
114
|
-
let { cleanedText: i, matches: a } =
|
|
115
|
-
if (n.emittedCount = a.length,
|
|
134
|
+
let { cleanedText: i, matches: a } = b(n.raw), o = i.trim(), s = a.slice(n.emittedCount);
|
|
135
|
+
if (n.emittedCount = a.length, k.current.set(e, n), A.current.set(e, o), p((t) => t.map((t) => t.id === e ? {
|
|
116
136
|
...t,
|
|
117
137
|
content: o
|
|
118
138
|
} : t)), s.length > 0) {
|
|
119
|
-
let e = Date.now(), t =
|
|
139
|
+
let e = Date.now(), t = D.current;
|
|
120
140
|
s.forEach((n) => r({
|
|
121
141
|
kind: "pseudo_tool_call",
|
|
122
142
|
name: n.name,
|
|
@@ -130,7 +150,7 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
130
150
|
if (t.type === "response.output_item.added" || t.type === "response.output_item.done") {
|
|
131
151
|
let e = t.item;
|
|
132
152
|
if (e.type === "function_call" || e.type === "mcp_call") {
|
|
133
|
-
let n = Date.now(), i =
|
|
153
|
+
let n = Date.now(), i = D.current, a = e.name || "unknown_tool";
|
|
134
154
|
return r(t.type === "response.output_item.added" ? {
|
|
135
155
|
kind: "tool_start",
|
|
136
156
|
name: a,
|
|
@@ -155,23 +175,23 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
155
175
|
status: t.status,
|
|
156
176
|
message: t.message,
|
|
157
177
|
at: Date.now(),
|
|
158
|
-
turnSentAt:
|
|
178
|
+
turnSentAt: D.current
|
|
159
179
|
}), !0) : t.type === "response.output_text.done" || t.type === "response.created" || t.type === "response.completed" ? !1 : t.type === "info" ? (r({
|
|
160
180
|
kind: "info",
|
|
161
181
|
message: t.message,
|
|
162
182
|
at: Date.now(),
|
|
163
|
-
turnSentAt:
|
|
183
|
+
turnSentAt: D.current
|
|
164
184
|
}), !0) : (r({
|
|
165
185
|
kind: "raw",
|
|
166
186
|
eventType: t.type,
|
|
167
187
|
raw: JSON.stringify(t),
|
|
168
188
|
at: Date.now(),
|
|
169
|
-
turnSentAt:
|
|
189
|
+
turnSentAt: D.current
|
|
170
190
|
}), !0);
|
|
171
|
-
}, []),
|
|
172
|
-
|
|
191
|
+
}, []), F = n(async (n) => {
|
|
192
|
+
y("streaming"), C(null);
|
|
173
193
|
let r = Date.now();
|
|
174
|
-
|
|
194
|
+
D.current = r;
|
|
175
195
|
let a = crypto.randomUUID();
|
|
176
196
|
p((e) => [...e, {
|
|
177
197
|
id: a,
|
|
@@ -187,7 +207,7 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
187
207
|
role: e.role,
|
|
188
208
|
content: e.content
|
|
189
209
|
});
|
|
190
|
-
|
|
210
|
+
_({
|
|
191
211
|
model: t,
|
|
192
212
|
systemPrompt: i,
|
|
193
213
|
messages: o,
|
|
@@ -202,9 +222,9 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
202
222
|
}
|
|
203
223
|
});
|
|
204
224
|
let d = new AbortController();
|
|
205
|
-
|
|
206
|
-
let f = "", m = null, g = !1,
|
|
207
|
-
|
|
225
|
+
T.current = d, N(d);
|
|
226
|
+
let f = "", m = null, g = !1, v = !1, b = [], x = (e, t) => {
|
|
227
|
+
y("error"), C(e);
|
|
208
228
|
let n = {
|
|
209
229
|
kind: "error",
|
|
210
230
|
message: e,
|
|
@@ -226,7 +246,7 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
226
246
|
b.push(t), h((e) => [...e, t]);
|
|
227
247
|
return;
|
|
228
248
|
}
|
|
229
|
-
e.type === "response.output_text.delta" && e.delta && (
|
|
249
|
+
e.type === "response.output_text.delta" && e.delta && (v = !0), P(a, e, b) && (g = !0);
|
|
230
250
|
}), t && p((e) => e.map((e) => e.id === a ? {
|
|
231
251
|
...e,
|
|
232
252
|
streaming: !1
|
|
@@ -241,11 +261,11 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
241
261
|
toolChoice: c,
|
|
242
262
|
signal: d.signal,
|
|
243
263
|
onChunk: (e) => {
|
|
244
|
-
|
|
245
|
-
let { events: t, remainder: n, done: i } =
|
|
264
|
+
N(d), f += e;
|
|
265
|
+
let { events: t, remainder: n, done: i } = S(f);
|
|
246
266
|
f = n, w(t, i);
|
|
247
267
|
let a = Date.now();
|
|
248
|
-
|
|
268
|
+
_((e) => e && e.sentAt === r ? {
|
|
249
269
|
...e,
|
|
250
270
|
streamStats: {
|
|
251
271
|
chunkCount: e.streamStats.chunkCount + 1,
|
|
@@ -255,22 +275,22 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
255
275
|
} : e);
|
|
256
276
|
},
|
|
257
277
|
onRequestId: (e) => {
|
|
258
|
-
|
|
278
|
+
_((t) => t && t.sentAt === r ? {
|
|
259
279
|
...t,
|
|
260
280
|
requestId: e
|
|
261
281
|
} : t);
|
|
262
282
|
}
|
|
263
283
|
});
|
|
264
284
|
if (f.trim()) {
|
|
265
|
-
let { events: e, done: t } =
|
|
285
|
+
let { events: e, done: t } = S(`${f}\n\n`);
|
|
266
286
|
f = "", w(e, t);
|
|
267
287
|
}
|
|
268
288
|
if (m) {
|
|
269
|
-
|
|
289
|
+
y("error"), C(m);
|
|
270
290
|
return;
|
|
271
291
|
}
|
|
272
292
|
if (n === void 0 || n >= 400) {
|
|
273
|
-
x(
|
|
293
|
+
x(ee(n, l, p), {
|
|
274
294
|
httpStatus: n,
|
|
275
295
|
rawBody: l || void 0
|
|
276
296
|
});
|
|
@@ -280,13 +300,13 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
280
300
|
x("Bailey returned an empty response.");
|
|
281
301
|
return;
|
|
282
302
|
}
|
|
283
|
-
if (!
|
|
303
|
+
if (!v) {
|
|
284
304
|
x("Bailey ran some tools but didn't return an answer. Try asking again.");
|
|
285
305
|
return;
|
|
286
306
|
}
|
|
287
|
-
|
|
288
|
-
let h =
|
|
289
|
-
|
|
307
|
+
y("idle");
|
|
308
|
+
let h = A.current.get(a) ?? "";
|
|
309
|
+
_((e) => e && e.sentAt === r ? {
|
|
290
310
|
...e,
|
|
291
311
|
response: { content: h }
|
|
292
312
|
} : e), u && await u({
|
|
@@ -302,12 +322,12 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
302
322
|
return;
|
|
303
323
|
}
|
|
304
324
|
if (t?.name === "AbortError") {
|
|
305
|
-
|
|
325
|
+
y("idle");
|
|
306
326
|
return;
|
|
307
327
|
}
|
|
308
328
|
x(t?.message || "Bailey request failed.");
|
|
309
329
|
} finally {
|
|
310
|
-
|
|
330
|
+
M(), k.current.delete(a), A.current.delete(a), p((e) => e.flatMap((e) => e.id === a ? e.content ? [{
|
|
311
331
|
...e,
|
|
312
332
|
streaming: !1
|
|
313
333
|
}] : [] : [e]));
|
|
@@ -320,58 +340,58 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
320
340
|
c,
|
|
321
341
|
l,
|
|
322
342
|
u,
|
|
323
|
-
F,
|
|
324
343
|
P,
|
|
325
|
-
N
|
|
326
|
-
|
|
327
|
-
|
|
344
|
+
N,
|
|
345
|
+
M
|
|
346
|
+
]), I = n((e) => {
|
|
347
|
+
O.current = e, p(e);
|
|
328
348
|
}, []);
|
|
329
349
|
return {
|
|
330
350
|
messages: f,
|
|
331
351
|
traceEvents: m,
|
|
332
352
|
lastRequest: g,
|
|
333
|
-
status:
|
|
334
|
-
error:
|
|
353
|
+
status: v,
|
|
354
|
+
error: x,
|
|
335
355
|
send: n((e) => {
|
|
336
356
|
let t = e.trim();
|
|
337
357
|
if (!t) return;
|
|
338
|
-
|
|
339
|
-
let n = [...
|
|
358
|
+
E.current = t;
|
|
359
|
+
let n = [...O.current, {
|
|
340
360
|
id: crypto.randomUUID(),
|
|
341
361
|
role: "user",
|
|
342
362
|
content: t,
|
|
343
363
|
createdAt: Date.now()
|
|
344
364
|
}];
|
|
345
|
-
|
|
346
|
-
}, [
|
|
365
|
+
I(n), F(n);
|
|
366
|
+
}, [F, I]),
|
|
347
367
|
stop: n(() => {
|
|
348
|
-
|
|
368
|
+
T.current?.abort();
|
|
349
369
|
}, []),
|
|
350
370
|
retryLast: n(() => {
|
|
351
|
-
if (!
|
|
352
|
-
let e =
|
|
353
|
-
|
|
354
|
-
}, [
|
|
371
|
+
if (!E.current) return;
|
|
372
|
+
let e = O.current, t = e[e.length - 1], n = t && t.role === "assistant" ? e.slice(0, -1) : e;
|
|
373
|
+
I(n), F(n);
|
|
374
|
+
}, [F, I]),
|
|
355
375
|
clearTrace: n(() => h([]), []),
|
|
356
376
|
clearError: n(() => {
|
|
357
|
-
|
|
377
|
+
C(null), y((e) => e === "error" ? "idle" : e);
|
|
358
378
|
}, []),
|
|
359
379
|
newChat: n(() => {
|
|
360
|
-
|
|
361
|
-
}, [
|
|
380
|
+
T.current?.abort(), I([]), h([]), _(null), y("idle"), C(null), E.current = "";
|
|
381
|
+
}, [I])
|
|
362
382
|
};
|
|
363
383
|
};
|
|
364
384
|
//#endregion
|
|
365
385
|
//#region src/utils/prompt.ts
|
|
366
|
-
function
|
|
386
|
+
function E(...e) {
|
|
367
387
|
return e.filter((e) => !!(e && e.trim())).join("\n\n");
|
|
368
388
|
}
|
|
369
389
|
//#endregion
|
|
370
390
|
//#region src/utils/toolCalls.ts
|
|
371
|
-
var
|
|
372
|
-
function
|
|
391
|
+
var D = "call_tool", O = "a tool";
|
|
392
|
+
function k(e, t) {
|
|
373
393
|
let n = {
|
|
374
|
-
name: e ===
|
|
394
|
+
name: e === D ? O : e,
|
|
375
395
|
args: null,
|
|
376
396
|
viaCallTool: !1
|
|
377
397
|
};
|
|
@@ -384,7 +404,7 @@ function D(e, t) {
|
|
|
384
404
|
}
|
|
385
405
|
if (typeof r != "object" || !r) return n;
|
|
386
406
|
let i = r;
|
|
387
|
-
if (e ===
|
|
407
|
+
if (e === D) {
|
|
388
408
|
let e = typeof i.name == "string" ? i.name : void 0;
|
|
389
409
|
if (!e) return n;
|
|
390
410
|
let t = i.arguments;
|
|
@@ -402,32 +422,32 @@ function D(e, t) {
|
|
|
402
422
|
}
|
|
403
423
|
//#endregion
|
|
404
424
|
//#region src/utils/table.ts
|
|
405
|
-
var
|
|
425
|
+
var A = 5, j = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map(j).join(""), M = (e) => {
|
|
406
426
|
if (e.tagName === "a" && e.properties?.href) return e.properties.href;
|
|
407
427
|
for (let t of e.children ?? []) {
|
|
408
|
-
let e =
|
|
428
|
+
let e = M(t);
|
|
409
429
|
if (e) return e;
|
|
410
430
|
}
|
|
411
|
-
},
|
|
412
|
-
let t =
|
|
431
|
+
}, N = (e, t) => (e.children ?? []).find((e) => e.tagName === t), P = (e) => {
|
|
432
|
+
let t = j(e), n = M(e);
|
|
413
433
|
return n ? {
|
|
414
434
|
text: t,
|
|
415
435
|
href: n
|
|
416
436
|
} : { text: t };
|
|
417
|
-
},
|
|
437
|
+
}, F = (e) => (e.children ?? []).filter((e) => e.type === "element").map(P), I = (e) => {
|
|
418
438
|
if (e.tagName !== "table") return null;
|
|
419
|
-
let t =
|
|
439
|
+
let t = N(e, "thead"), n = t && N(t, "tr");
|
|
420
440
|
return {
|
|
421
|
-
headers: n ?
|
|
422
|
-
rows: (
|
|
441
|
+
headers: n ? F(n).map((e) => e.text) : [],
|
|
442
|
+
rows: (N(e, "tbody")?.children ?? []).filter((e) => e.tagName === "tr").map(F)
|
|
423
443
|
};
|
|
424
|
-
},
|
|
444
|
+
}, te = (e) => e.length > 5, ne = "When a chart would help answer a question (e.g. plotting a trend over time), include a fenced code block tagged `chartjs` containing a JSON object with this exact shape: {\"type\": \"bar\" | \"line\" | \"pie\" | \"doughnut\" | \"scatter\", \"title\"?: string, \"data\": {\"labels\": string[], \"datasets\": [{\"label\": string, \"data\": number[]}]}}. For \"scatter\" charts, omit \"labels\" and give each dataset \"data\" as an array of {\"x\": number, \"y\": number} points instead of a number array. \"pie\" and \"doughnut\" charts must have exactly one dataset. Do not include any other fields (no \"options\", no colors) — the app handles styling. Example:\n```chartjs\n{\"type\": \"line\", \"title\": \"BP readings\", \"data\": {\"labels\": [\"Jul 14\", \"Jul 21\", \"Jul 28\"], \"datasets\": [{\"label\": \"Systolic\", \"data\": [120, 118, 122]}]}}\n```", re = [
|
|
425
445
|
"bar",
|
|
426
446
|
"line",
|
|
427
447
|
"pie",
|
|
428
448
|
"doughnut",
|
|
429
449
|
"scatter"
|
|
430
|
-
],
|
|
450
|
+
], ie = 8, ae = 50, oe = 8, se = 500, ce = (e) => typeof e == "object" && !!e && typeof e.x == "number" && typeof e.y == "number", L = (e) => {
|
|
431
451
|
let t;
|
|
432
452
|
try {
|
|
433
453
|
t = JSON.parse(e);
|
|
@@ -436,17 +456,17 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
436
456
|
}
|
|
437
457
|
if (typeof t != "object" || !t) return null;
|
|
438
458
|
let n = t;
|
|
439
|
-
if (typeof n.type != "string" || !
|
|
459
|
+
if (typeof n.type != "string" || !re.includes(n.type)) return null;
|
|
440
460
|
let r = n.type;
|
|
441
461
|
if (n.title !== void 0 && typeof n.title != "string") return null;
|
|
442
462
|
let i = n.title;
|
|
443
463
|
if (typeof n.data != "object" || n.data === null) return null;
|
|
444
464
|
let a = n.data;
|
|
445
|
-
if (!Array.isArray(a.datasets) || a.datasets.length < 1 || a.datasets.length >
|
|
465
|
+
if (!Array.isArray(a.datasets) || a.datasets.length < 1 || a.datasets.length > ie || (r === "pie" || r === "doughnut") && a.datasets.length !== 1) return null;
|
|
446
466
|
for (let e of a.datasets) if (typeof e != "object" || !e || typeof e.label != "string" || !Array.isArray(e.data)) return null;
|
|
447
467
|
let o = a.datasets;
|
|
448
468
|
if (r === "scatter") {
|
|
449
|
-
for (let e of o) if (e.data.length < 1 || e.data.length >
|
|
469
|
+
for (let e of o) if (e.data.length < 1 || e.data.length > se || !e.data.every(ce)) return null;
|
|
450
470
|
return {
|
|
451
471
|
type: r,
|
|
452
472
|
title: i,
|
|
@@ -454,7 +474,7 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
454
474
|
};
|
|
455
475
|
}
|
|
456
476
|
if (!Array.isArray(a.labels) || !a.labels.every((e) => typeof e == "string")) return null;
|
|
457
|
-
let s = a.labels, c = r === "pie" || r === "doughnut" ?
|
|
477
|
+
let s = a.labels, c = r === "pie" || r === "doughnut" ? oe : ae;
|
|
458
478
|
if (s.length < 1 || s.length > c) return null;
|
|
459
479
|
for (let e of o) if (e.data.length !== s.length || !e.data.every((e) => typeof e == "number")) return null;
|
|
460
480
|
return {
|
|
@@ -465,7 +485,7 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
465
485
|
datasets: o
|
|
466
486
|
}
|
|
467
487
|
};
|
|
468
|
-
},
|
|
488
|
+
}, le = {
|
|
469
489
|
tool_start: "Tool start",
|
|
470
490
|
tool_end: "Tool end",
|
|
471
491
|
pseudo_tool_call: "Narrated tool call",
|
|
@@ -474,13 +494,13 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
474
494
|
error: "Error",
|
|
475
495
|
raw: "Raw event"
|
|
476
496
|
};
|
|
477
|
-
function
|
|
478
|
-
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null :
|
|
497
|
+
function R(e) {
|
|
498
|
+
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null : k(e.name, e.args);
|
|
479
499
|
}
|
|
480
|
-
function
|
|
500
|
+
function z(e, t = R(e)) {
|
|
481
501
|
return e.kind === "pseudo_tool_call" ? e.name : t?.name ?? null;
|
|
482
502
|
}
|
|
483
|
-
function
|
|
503
|
+
function ue(e, t = R(e)) {
|
|
484
504
|
switch (e.kind) {
|
|
485
505
|
case "tool_start": return t.viaCallTool ? `${t.name} (via call_tool)` : t.name;
|
|
486
506
|
case "tool_end": return `${t.viaCallTool ? `${t.name} (via call_tool)` : t.name}${e.runtimeSeconds === void 0 ? "" : ` — ${e.runtimeSeconds.toFixed(2)}s`}${e.isError ? " — failed" : ""}`;
|
|
@@ -491,20 +511,20 @@ function V(e, t = z(e)) {
|
|
|
491
511
|
case "raw": return `Unrecognized event: ${e.eventType}`;
|
|
492
512
|
}
|
|
493
513
|
}
|
|
494
|
-
function
|
|
514
|
+
function B(e, t = R(e)) {
|
|
495
515
|
return e.kind === "tool_start" || e.kind === "tool_end" ? t.args ? JSON.stringify(t.args, null, 2) : e.args ?? null : e.kind === "pseudo_tool_call" ? e.args ?? null : null;
|
|
496
516
|
}
|
|
497
|
-
function
|
|
517
|
+
function V(e) {
|
|
498
518
|
return e.kind === "tool_end" ? e.output ?? null : null;
|
|
499
519
|
}
|
|
500
|
-
function
|
|
520
|
+
function H(e) {
|
|
501
521
|
return e.kind === "raw" ? e.raw : e.kind === "error" ? e.rawBody ?? null : null;
|
|
502
522
|
}
|
|
503
|
-
function
|
|
523
|
+
function U(e) {
|
|
504
524
|
switch (e.kind) {
|
|
505
|
-
case "tool_start": return `Calling ${
|
|
525
|
+
case "tool_start": return `Calling ${k(e.name, e.args).name}...`;
|
|
506
526
|
case "tool_end": {
|
|
507
|
-
let t =
|
|
527
|
+
let t = k(e.name, e.args).name;
|
|
508
528
|
return e.isError ? `${t} failed` : `${t} returned`;
|
|
509
529
|
}
|
|
510
530
|
case "pseudo_tool_call": return `${e.name} (written as text, not called)`;
|
|
@@ -514,11 +534,11 @@ function G(e) {
|
|
|
514
534
|
case "raw": return `Unrecognized event: ${e.eventType}`;
|
|
515
535
|
}
|
|
516
536
|
}
|
|
517
|
-
function
|
|
537
|
+
function W(e) {
|
|
518
538
|
let t = new Date(e);
|
|
519
539
|
return `${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}:${String(t.getSeconds()).padStart(2, "0")}.${String(t.getMilliseconds()).padStart(3, "0")}`;
|
|
520
540
|
}
|
|
521
|
-
function
|
|
541
|
+
function G(e) {
|
|
522
542
|
if (e <= 0) return "+0ms";
|
|
523
543
|
if (e < 1e3) return `+${Math.round(e)}ms`;
|
|
524
544
|
let t = e / 1e3;
|
|
@@ -526,30 +546,30 @@ function q(e) {
|
|
|
526
546
|
let n = Math.floor(t / 60), r = Math.round(t % 60);
|
|
527
547
|
return `+${n}m${String(r).padStart(2, "0")}s`;
|
|
528
548
|
}
|
|
529
|
-
function
|
|
549
|
+
function K(e) {
|
|
530
550
|
return e.map((t, n) => {
|
|
531
|
-
let r =
|
|
551
|
+
let r = R(t), i = n === 0 ? t.turnSentAt : e[n - 1].at;
|
|
532
552
|
return {
|
|
533
553
|
key: `${t.at}-${n}`,
|
|
534
554
|
kind: t.kind,
|
|
535
|
-
toolName:
|
|
555
|
+
toolName: z(t, r),
|
|
536
556
|
isToolStart: t.kind === "tool_start",
|
|
537
557
|
failed: t.kind === "tool_end" && t.isError === !0,
|
|
538
|
-
time:
|
|
558
|
+
time: W(t.at),
|
|
539
559
|
gapMs: t.at - i,
|
|
540
|
-
label: t.kind === "tool_end" && t.isError === !0 ? "Tool failed" :
|
|
541
|
-
summary:
|
|
542
|
-
argsDetail:
|
|
543
|
-
outputDetail:
|
|
544
|
-
rawDetail:
|
|
560
|
+
label: t.kind === "tool_end" && t.isError === !0 ? "Tool failed" : le[t.kind],
|
|
561
|
+
summary: ue(t, r),
|
|
562
|
+
argsDetail: B(t, r),
|
|
563
|
+
outputDetail: V(t),
|
|
564
|
+
rawDetail: H(t)
|
|
545
565
|
};
|
|
546
566
|
});
|
|
547
567
|
}
|
|
548
|
-
function
|
|
568
|
+
function q(e) {
|
|
549
569
|
let t = e.filter((e) => e.kind === "tool_end"), n = t.filter((e) => e.kind === "tool_end" && e.isError), r = e.filter((e) => e.kind === "error"), i = [];
|
|
550
570
|
return t.length > 0 && i.push(`${t.length} tool call${t.length === 1 ? "" : "s"}` + (n.length > 0 ? `, ${n.length} failed` : "")), r.length > 0 && i.push(`${r.length} stream error${r.length === 1 ? "" : "s"}`), i.join(" · ");
|
|
551
571
|
}
|
|
552
|
-
function
|
|
572
|
+
function J(e) {
|
|
553
573
|
let t = [];
|
|
554
574
|
for (let n of e) {
|
|
555
575
|
let e = t[t.length - 1];
|
|
@@ -568,19 +588,19 @@ function X(e) {
|
|
|
568
588
|
}
|
|
569
589
|
return t;
|
|
570
590
|
}
|
|
571
|
-
function
|
|
591
|
+
function Y(e) {
|
|
572
592
|
return e.some((e) => e.kind === "tool_end" && e.isError || e.kind === "error");
|
|
573
593
|
}
|
|
574
|
-
function
|
|
594
|
+
function X(e, t) {
|
|
575
595
|
return t === void 0 ? [] : e.filter((e) => e.turnSentAt === t && (e.kind === "tool_end" || e.kind === "pseudo_tool_call" || e.kind === "progress")).map((e, t) => ({
|
|
576
596
|
key: `${e.at}-${t}`,
|
|
577
|
-
text:
|
|
578
|
-
toolName:
|
|
597
|
+
text: U(e),
|
|
598
|
+
toolName: z(e)
|
|
579
599
|
}));
|
|
580
600
|
}
|
|
581
601
|
//#endregion
|
|
582
602
|
//#region src/ui/markdown.tsx
|
|
583
|
-
function
|
|
603
|
+
function de({ renderTable: t, renderChart: n } = {}) {
|
|
584
604
|
return {
|
|
585
605
|
a: ({ href: t, children: n }) => !t || !e(t) ? /* @__PURE__ */ u(l, { children: n }) : /* @__PURE__ */ u("a", {
|
|
586
606
|
href: t,
|
|
@@ -589,8 +609,8 @@ function ce({ renderTable: t, renderChart: n } = {}) {
|
|
|
589
609
|
children: n
|
|
590
610
|
}),
|
|
591
611
|
table: ({ node: n, children: r }) => {
|
|
592
|
-
let i = n &&
|
|
593
|
-
if (i &&
|
|
612
|
+
let i = n && I(n);
|
|
613
|
+
if (i && te(i.rows) && t) {
|
|
594
614
|
let n = i.rows.map((t) => t.map((t) => t.href && !e(t.href) ? { text: t.text } : t));
|
|
595
615
|
return /* @__PURE__ */ u(l, { children: t({
|
|
596
616
|
headers: i.headers,
|
|
@@ -602,7 +622,7 @@ function ce({ renderTable: t, renderChart: n } = {}) {
|
|
|
602
622
|
pre: ({ children: e }) => {
|
|
603
623
|
let t = (Array.isArray(e) ? e[0] : e)?.props;
|
|
604
624
|
if ((t?.className?.split(" ") ?? []).includes("language-chartjs") && n) {
|
|
605
|
-
let e = t?.children, r =
|
|
625
|
+
let e = t?.children, r = L(Array.isArray(e) ? e.join("") : String(e ?? ""));
|
|
606
626
|
if (r) return /* @__PURE__ */ u(l, { children: n(r) });
|
|
607
627
|
}
|
|
608
628
|
return /* @__PURE__ */ u("pre", { children: e });
|
|
@@ -611,7 +631,7 @@ function ce({ renderTable: t, renderChart: n } = {}) {
|
|
|
611
631
|
}
|
|
612
632
|
//#endregion
|
|
613
633
|
//#region src/ui/icons.tsx
|
|
614
|
-
function
|
|
634
|
+
function fe({ className: e }) {
|
|
615
635
|
return /* @__PURE__ */ u("svg", {
|
|
616
636
|
viewBox: "0 0 24 24",
|
|
617
637
|
fill: "currentColor",
|
|
@@ -620,7 +640,7 @@ function le({ className: e }) {
|
|
|
620
640
|
children: /* @__PURE__ */ u("path", { d: "M12 20.3s-7.6-4.7-10-9.4C.4 7.7 1.7 4 5.2 3.1c2.2-.6 4.4.4 5.5 2.2 1.2-1.8 3.4-2.8 5.6-2.2 3.5.9 4.8 4.6 3.2 7.8-2.4 4.7-10 9.4-10 9.4z" })
|
|
621
641
|
});
|
|
622
642
|
}
|
|
623
|
-
function
|
|
643
|
+
function Z({ className: e }) {
|
|
624
644
|
return /* @__PURE__ */ d("svg", {
|
|
625
645
|
viewBox: "0 0 24 24",
|
|
626
646
|
fill: "none",
|
|
@@ -633,7 +653,7 @@ function ue({ className: e }) {
|
|
|
633
653
|
children: [/* @__PURE__ */ u("path", { d: "M7 17 17 7" }), /* @__PURE__ */ u("path", { d: "M9 7h8v8" })]
|
|
634
654
|
});
|
|
635
655
|
}
|
|
636
|
-
function
|
|
656
|
+
function pe({ className: e }) {
|
|
637
657
|
return /* @__PURE__ */ d("svg", {
|
|
638
658
|
viewBox: "0 0 24 24",
|
|
639
659
|
fill: "none",
|
|
@@ -652,7 +672,7 @@ function de({ className: e }) {
|
|
|
652
672
|
}), /* @__PURE__ */ u("path", { d: "M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" })]
|
|
653
673
|
});
|
|
654
674
|
}
|
|
655
|
-
function
|
|
675
|
+
function me({ className: e }) {
|
|
656
676
|
return /* @__PURE__ */ u("svg", {
|
|
657
677
|
viewBox: "0 0 24 24",
|
|
658
678
|
fill: "none",
|
|
@@ -665,7 +685,7 @@ function fe({ className: e }) {
|
|
|
665
685
|
children: /* @__PURE__ */ u("path", { d: "M5 12.5 9.5 17 19 7" })
|
|
666
686
|
});
|
|
667
687
|
}
|
|
668
|
-
function
|
|
688
|
+
function he({ className: e }) {
|
|
669
689
|
return /* @__PURE__ */ d("svg", {
|
|
670
690
|
viewBox: "0 0 24 24",
|
|
671
691
|
fill: "none",
|
|
@@ -684,8 +704,8 @@ function pe({ className: e }) {
|
|
|
684
704
|
}
|
|
685
705
|
//#endregion
|
|
686
706
|
//#region src/ui/CopyMarkdownButton.tsx
|
|
687
|
-
var
|
|
688
|
-
function
|
|
707
|
+
var ge = 1500;
|
|
708
|
+
function _e({ markdown: e, className: t }) {
|
|
689
709
|
let [n, i] = o(!1), [s, c] = o(!1), l = a(null);
|
|
690
710
|
return r(() => () => {
|
|
691
711
|
l.current !== null && clearTimeout(l.current);
|
|
@@ -702,11 +722,11 @@ function he({ markdown: e, className: t }) {
|
|
|
702
722
|
try {
|
|
703
723
|
await navigator.clipboard.writeText(e);
|
|
704
724
|
} catch {}
|
|
705
|
-
i(!0), l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => i(!1),
|
|
725
|
+
i(!0), l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => i(!1), ge);
|
|
706
726
|
},
|
|
707
727
|
"aria-label": "copy response as markdown",
|
|
708
728
|
className: `bailey-copy-button${t ? ` ${t}` : ""}`,
|
|
709
|
-
children: u(n ?
|
|
729
|
+
children: u(n ? me : pe, { className: "bailey-copy-icon" })
|
|
710
730
|
})
|
|
711
731
|
}), /* @__PURE__ */ u(f.Portal, { children: /* @__PURE__ */ d(f.Content, {
|
|
712
732
|
side: "top",
|
|
@@ -718,20 +738,20 @@ function he({ markdown: e, className: t }) {
|
|
|
718
738
|
}
|
|
719
739
|
//#endregion
|
|
720
740
|
//#region src/ui/BaileyTracePanel.tsx
|
|
721
|
-
async function
|
|
741
|
+
async function ve(e) {
|
|
722
742
|
try {
|
|
723
743
|
await navigator.clipboard.writeText(e);
|
|
724
744
|
} catch {}
|
|
725
745
|
}
|
|
726
|
-
function
|
|
746
|
+
function ye({ text: e, label: t = "Copy" }) {
|
|
727
747
|
return /* @__PURE__ */ u("button", {
|
|
728
748
|
type: "button",
|
|
729
|
-
onClick: () =>
|
|
749
|
+
onClick: () => ve(e),
|
|
730
750
|
className: "bailey-trace-copy-button",
|
|
731
751
|
children: t
|
|
732
752
|
});
|
|
733
753
|
}
|
|
734
|
-
function
|
|
754
|
+
function be(e) {
|
|
735
755
|
if (e.failed || e.kind === "error") return "bailey-trace-chip bailey-trace-chip-error";
|
|
736
756
|
switch (e.kind) {
|
|
737
757
|
case "tool_start": return "bailey-trace-chip bailey-trace-chip-info";
|
|
@@ -740,7 +760,7 @@ function ve(e) {
|
|
|
740
760
|
default: return "bailey-trace-chip bailey-trace-chip-default";
|
|
741
761
|
}
|
|
742
762
|
}
|
|
743
|
-
function
|
|
763
|
+
function Q({ label: e, content: t, copyable: n }) {
|
|
744
764
|
return /* @__PURE__ */ d("details", {
|
|
745
765
|
className: "bailey-trace-disclosure",
|
|
746
766
|
children: [
|
|
@@ -750,7 +770,7 @@ function Z({ label: e, content: t, copyable: n }) {
|
|
|
750
770
|
}),
|
|
751
771
|
n && /* @__PURE__ */ u("div", {
|
|
752
772
|
className: "bailey-trace-disclosure-actions",
|
|
753
|
-
children: /* @__PURE__ */ u(
|
|
773
|
+
children: /* @__PURE__ */ u(ye, { text: t })
|
|
754
774
|
}),
|
|
755
775
|
/* @__PURE__ */ u("pre", {
|
|
756
776
|
className: "bailey-trace-disclosure-content",
|
|
@@ -759,7 +779,7 @@ function Z({ label: e, content: t, copyable: n }) {
|
|
|
759
779
|
]
|
|
760
780
|
});
|
|
761
781
|
}
|
|
762
|
-
function
|
|
782
|
+
function $({ row: e }) {
|
|
763
783
|
return /* @__PURE__ */ d("div", {
|
|
764
784
|
className: "bailey-trace-row",
|
|
765
785
|
children: [
|
|
@@ -773,10 +793,10 @@ function Q({ row: e }) {
|
|
|
773
793
|
/* @__PURE__ */ u("span", {
|
|
774
794
|
className: "bailey-trace-row-gap",
|
|
775
795
|
title: "Time since the previous event",
|
|
776
|
-
children:
|
|
796
|
+
children: G(e.gapMs)
|
|
777
797
|
}),
|
|
778
798
|
/* @__PURE__ */ u("span", {
|
|
779
|
-
className:
|
|
799
|
+
className: be(e),
|
|
780
800
|
children: e.label
|
|
781
801
|
}),
|
|
782
802
|
/* @__PURE__ */ u("span", {
|
|
@@ -785,28 +805,28 @@ function Q({ row: e }) {
|
|
|
785
805
|
})
|
|
786
806
|
]
|
|
787
807
|
}),
|
|
788
|
-
e.argsDetail && /* @__PURE__ */ u(
|
|
808
|
+
e.argsDetail && /* @__PURE__ */ u(Q, {
|
|
789
809
|
label: "args",
|
|
790
810
|
content: e.argsDetail
|
|
791
811
|
}),
|
|
792
|
-
e.outputDetail && /* @__PURE__ */ u(
|
|
812
|
+
e.outputDetail && /* @__PURE__ */ u(Q, {
|
|
793
813
|
label: "output",
|
|
794
814
|
content: e.outputDetail
|
|
795
815
|
}),
|
|
796
|
-
e.rawDetail && /* @__PURE__ */ u(
|
|
816
|
+
e.rawDetail && /* @__PURE__ */ u(Q, {
|
|
797
817
|
label: "raw",
|
|
798
818
|
content: e.rawDetail
|
|
799
819
|
})
|
|
800
820
|
]
|
|
801
821
|
});
|
|
802
822
|
}
|
|
803
|
-
function
|
|
823
|
+
function xe(e, t) {
|
|
804
824
|
if (e.chunkCount === 0) return "Streamed: no chunks received";
|
|
805
825
|
if (e.chunkCount === 1 || e.firstChunkAt === null) return "Streamed: 1 chunk (not incremental)";
|
|
806
826
|
let n = e.firstChunkAt - t, r = (e.lastChunkAt ?? e.firstChunkAt) - e.firstChunkAt;
|
|
807
827
|
return `Streamed: ${e.chunkCount} chunks · first chunk after ${n}ms · spread over ${(r / 1e3).toFixed(1)}s`;
|
|
808
828
|
}
|
|
809
|
-
function
|
|
829
|
+
function Se({ request: e }) {
|
|
810
830
|
let t = i(() => JSON.stringify({
|
|
811
831
|
model: e.model,
|
|
812
832
|
instructions: e.systemPrompt,
|
|
@@ -830,24 +850,24 @@ function be({ request: e }) {
|
|
|
830
850
|
}),
|
|
831
851
|
/* @__PURE__ */ u("span", {
|
|
832
852
|
className: "bailey-trace-request-meta",
|
|
833
|
-
children:
|
|
853
|
+
children: xe(e.streamStats, e.sentAt)
|
|
834
854
|
}),
|
|
835
|
-
/* @__PURE__ */ u(
|
|
855
|
+
/* @__PURE__ */ u(Q, {
|
|
836
856
|
label: `System prompt (${e.systemPrompt.length.toLocaleString()} chars)`,
|
|
837
857
|
content: e.systemPrompt,
|
|
838
858
|
copyable: !0
|
|
839
859
|
}),
|
|
840
|
-
/* @__PURE__ */ u(
|
|
860
|
+
/* @__PURE__ */ u(Q, {
|
|
841
861
|
label: `Messages (${e.messages.length})`,
|
|
842
862
|
content: JSON.stringify(e.messages, null, 2),
|
|
843
863
|
copyable: !0
|
|
844
864
|
}),
|
|
845
|
-
e.response && /* @__PURE__ */ u(
|
|
865
|
+
e.response && /* @__PURE__ */ u(Q, {
|
|
846
866
|
label: `Response (${e.response.content.length.toLocaleString()} chars)`,
|
|
847
867
|
content: e.response.content,
|
|
848
868
|
copyable: !0
|
|
849
869
|
}),
|
|
850
|
-
/* @__PURE__ */ u(
|
|
870
|
+
/* @__PURE__ */ u(Q, {
|
|
851
871
|
label: "Full payload (JSON)",
|
|
852
872
|
content: t,
|
|
853
873
|
copyable: !0
|
|
@@ -855,14 +875,14 @@ function be({ request: e }) {
|
|
|
855
875
|
]
|
|
856
876
|
});
|
|
857
877
|
}
|
|
858
|
-
function
|
|
859
|
-
let r = i(() =>
|
|
878
|
+
function Ce({ events: e, lastRequest: t, onClear: n }) {
|
|
879
|
+
let r = i(() => K(e), [e]), a = i(() => J(r), [r]), o = i(() => JSON.stringify(e, null, 2), [e]);
|
|
860
880
|
return /* @__PURE__ */ d("div", {
|
|
861
881
|
className: "bailey-trace-body",
|
|
862
882
|
children: [
|
|
863
883
|
/* @__PURE__ */ d("div", {
|
|
864
884
|
className: "bailey-trace-actions-row",
|
|
865
|
-
children: [e.length > 0 && /* @__PURE__ */ u(
|
|
885
|
+
children: [e.length > 0 && /* @__PURE__ */ u(ye, {
|
|
866
886
|
text: o,
|
|
867
887
|
label: "Copy trace as JSON"
|
|
868
888
|
}), /* @__PURE__ */ u("button", {
|
|
@@ -872,15 +892,15 @@ function xe({ events: e, lastRequest: t, onClear: n }) {
|
|
|
872
892
|
children: "Clear"
|
|
873
893
|
})]
|
|
874
894
|
}),
|
|
875
|
-
t && /* @__PURE__ */ u(
|
|
895
|
+
t && /* @__PURE__ */ u(Se, { request: t }),
|
|
876
896
|
/* @__PURE__ */ u("div", {
|
|
877
897
|
className: "bailey-trace-rows",
|
|
878
898
|
children: a.map((e, t) => {
|
|
879
|
-
if (e.type === "single") return /* @__PURE__ */ u(
|
|
899
|
+
if (e.type === "single") return /* @__PURE__ */ u($, { row: e.row }, e.row.key);
|
|
880
900
|
let n = e.rows.filter((e) => e.isToolStart).length;
|
|
881
901
|
if (n <= 1) return /* @__PURE__ */ u("div", {
|
|
882
902
|
className: "bailey-trace-rows",
|
|
883
|
-
children: e.rows.map((e) => /* @__PURE__ */ u(
|
|
903
|
+
children: e.rows.map((e) => /* @__PURE__ */ u($, { row: e }, e.key))
|
|
884
904
|
}, `group-${t}`);
|
|
885
905
|
let r = e.rows.filter((e) => e.failed).length;
|
|
886
906
|
return /* @__PURE__ */ d("details", {
|
|
@@ -902,7 +922,7 @@ function xe({ events: e, lastRequest: t, onClear: n }) {
|
|
|
902
922
|
]
|
|
903
923
|
}), /* @__PURE__ */ u("div", {
|
|
904
924
|
className: "bailey-trace-rows",
|
|
905
|
-
children: e.rows.map((e) => /* @__PURE__ */ u(
|
|
925
|
+
children: e.rows.map((e) => /* @__PURE__ */ u($, { row: e }, e.key))
|
|
906
926
|
})]
|
|
907
927
|
}, `group-${t}`);
|
|
908
928
|
})
|
|
@@ -910,8 +930,8 @@ function xe({ events: e, lastRequest: t, onClear: n }) {
|
|
|
910
930
|
]
|
|
911
931
|
});
|
|
912
932
|
}
|
|
913
|
-
function
|
|
914
|
-
let [r, a] = o(!1), s = i(() =>
|
|
933
|
+
function we({ events: e, lastRequest: t, onClear: n }) {
|
|
934
|
+
let [r, a] = o(!1), s = i(() => Y(e), [e]), c = i(() => q(e), [e]);
|
|
915
935
|
return e.length === 0 && !t ? null : /* @__PURE__ */ d("div", {
|
|
916
936
|
className: "bailey-trace-panel",
|
|
917
937
|
children: [/* @__PURE__ */ d("div", {
|
|
@@ -932,7 +952,7 @@ function $({ events: e, lastRequest: t, onClear: n }) {
|
|
|
932
952
|
className: s ? "bailey-trace-summary bailey-trace-summary-error" : "bailey-trace-summary",
|
|
933
953
|
children: c
|
|
934
954
|
})]
|
|
935
|
-
}), r && /* @__PURE__ */ u(
|
|
955
|
+
}), r && /* @__PURE__ */ u(Ce, {
|
|
936
956
|
events: e,
|
|
937
957
|
lastRequest: t,
|
|
938
958
|
onClear: n
|
|
@@ -941,39 +961,39 @@ function $({ events: e, lastRequest: t, onClear: n }) {
|
|
|
941
961
|
}
|
|
942
962
|
//#endregion
|
|
943
963
|
//#region src/ui/BaileyChatPanel.tsx
|
|
944
|
-
var
|
|
964
|
+
var Te = "How can bailey AI help you today?", Ee = "Reply to bailey AI", De = [c], Oe = t(function({ content: e, components: t }) {
|
|
945
965
|
return /* @__PURE__ */ u("div", {
|
|
946
966
|
className: "bailey-markdown-content",
|
|
947
967
|
children: /* @__PURE__ */ u(s, {
|
|
948
|
-
remarkPlugins:
|
|
968
|
+
remarkPlugins: De,
|
|
949
969
|
components: t,
|
|
950
970
|
children: e
|
|
951
971
|
})
|
|
952
972
|
});
|
|
953
973
|
});
|
|
954
|
-
function
|
|
974
|
+
function ke(e, t, n) {
|
|
955
975
|
if (e !== "streaming") return;
|
|
956
976
|
let r = t.filter((e) => e.turnSentAt === n?.sentAt);
|
|
957
|
-
if (r.length !== 0) return
|
|
977
|
+
if (r.length !== 0) return U(r[r.length - 1]);
|
|
958
978
|
}
|
|
959
|
-
function
|
|
979
|
+
function Ae(e) {
|
|
960
980
|
let t = new Date(e), n = t.toDateString() === (/* @__PURE__ */ new Date()).toDateString(), r = t.toLocaleTimeString([], {
|
|
961
981
|
hour: "numeric",
|
|
962
982
|
minute: "2-digit"
|
|
963
983
|
});
|
|
964
984
|
return n ? `Today ${r}` : `${t.toLocaleDateString()} ${r}`;
|
|
965
985
|
}
|
|
966
|
-
function
|
|
967
|
-
let { messages: y, traceEvents: b, lastRequest: x, status: S, error: C, send: w, stop:
|
|
986
|
+
function je({ chat: e, placeholder: t, replyPlaceholder: n = Ee, suggestions: s, privacyNote: c, resolveActivityIcon: l, className: f, height: p, width: m, hideDeveloperDetails: h = !1, renderMessageActions: g, renderTable: _, renderChart: v }) {
|
|
987
|
+
let { messages: y, traceEvents: b, lastRequest: x, status: S, error: C, send: w, stop: ee, retryLast: T, clearTrace: E, clearError: D, newChat: O } = e, [k, A] = o(""), j = a(null), M = i(() => de({
|
|
968
988
|
renderTable: _,
|
|
969
989
|
renderChart: v
|
|
970
|
-
}), [_, v]),
|
|
990
|
+
}), [_, v]), N = i(() => ke(S, b, x), [
|
|
971
991
|
S,
|
|
972
992
|
b,
|
|
973
993
|
x
|
|
974
|
-
]),
|
|
994
|
+
]), P = y.length === 0, F = t ?? (P ? Te : n);
|
|
975
995
|
return r(() => {
|
|
976
|
-
|
|
996
|
+
j.current?.scrollIntoView({
|
|
977
997
|
behavior: "smooth",
|
|
978
998
|
block: "nearest"
|
|
979
999
|
});
|
|
@@ -990,7 +1010,7 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
990
1010
|
className: "bailey-toolbar-row",
|
|
991
1011
|
children: /* @__PURE__ */ u("button", {
|
|
992
1012
|
type: "button",
|
|
993
|
-
onClick:
|
|
1013
|
+
onClick: O,
|
|
994
1014
|
disabled: y.length === 0,
|
|
995
1015
|
"aria-label": "new chat",
|
|
996
1016
|
className: "bailey-new-chat-button",
|
|
@@ -1000,7 +1020,7 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
1000
1020
|
/* @__PURE__ */ d("div", {
|
|
1001
1021
|
className: "bailey-chat-transcript",
|
|
1002
1022
|
children: [
|
|
1003
|
-
|
|
1023
|
+
P && (s && s.length > 0 ? /* @__PURE__ */ d("div", {
|
|
1004
1024
|
className: "bailey-suggestions",
|
|
1005
1025
|
children: [/* @__PURE__ */ u("div", {
|
|
1006
1026
|
className: "bailey-suggestions-title",
|
|
@@ -1009,14 +1029,14 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
1009
1029
|
type: "button",
|
|
1010
1030
|
onClick: () => w(e.value ?? e.label),
|
|
1011
1031
|
className: "bailey-suggestion-card",
|
|
1012
|
-
children: [/* @__PURE__ */ u("span", { children: e.label }), /* @__PURE__ */ u(
|
|
1032
|
+
children: [/* @__PURE__ */ u("span", { children: e.label }), /* @__PURE__ */ u(Z, { className: "bailey-suggestion-icon" })]
|
|
1013
1033
|
}, `${e.label}-${t}`))]
|
|
1014
1034
|
}) : /* @__PURE__ */ u("div", {
|
|
1015
1035
|
className: "bailey-empty-state",
|
|
1016
1036
|
children: "Ask Bailey a question to get started."
|
|
1017
1037
|
})),
|
|
1018
1038
|
y.map((e, t) => {
|
|
1019
|
-
let n = e.role === "assistant" && t === y.length - 1, r = S === "streaming" && n && e.content === "", i = e.role === "assistant" && !r ?
|
|
1039
|
+
let n = e.role === "assistant" && t === y.length - 1, r = S === "streaming" && n && e.content === "", i = e.role === "assistant" && !r ? X(b, e.createdAt) : [], a = i[i.length - 1];
|
|
1020
1040
|
return /* @__PURE__ */ u("div", {
|
|
1021
1041
|
className: e.role === "user" ? "bailey-message-row bailey-message-row-user" : "bailey-message-row",
|
|
1022
1042
|
children: e.role === "user" ? /* @__PURE__ */ d("div", {
|
|
@@ -1026,14 +1046,14 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
1026
1046
|
children: [/* @__PURE__ */ u("span", {
|
|
1027
1047
|
className: "bailey-message-meta-name",
|
|
1028
1048
|
children: "You"
|
|
1029
|
-
}), e.createdAt !== void 0 && /* @__PURE__ */ u("span", { children:
|
|
1049
|
+
}), e.createdAt !== void 0 && /* @__PURE__ */ u("span", { children: Ae(e.createdAt) })]
|
|
1030
1050
|
}), /* @__PURE__ */ u("div", {
|
|
1031
1051
|
className: "bailey-user-bubble",
|
|
1032
1052
|
children: e.content
|
|
1033
1053
|
})]
|
|
1034
1054
|
}) : r ? /* @__PURE__ */ u("div", {
|
|
1035
1055
|
className: "bailey-thinking-hint",
|
|
1036
|
-
children:
|
|
1056
|
+
children: N ?? "Thinking…"
|
|
1037
1057
|
}) : /* @__PURE__ */ d("div", {
|
|
1038
1058
|
className: "bailey-assistant-message",
|
|
1039
1059
|
children: [
|
|
@@ -1041,29 +1061,29 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
1041
1061
|
className: "bailey-activity-line",
|
|
1042
1062
|
children: [/* @__PURE__ */ u("span", {
|
|
1043
1063
|
className: "bailey-activity-icon",
|
|
1044
|
-
children: l?.(a.toolName) ?? /* @__PURE__ */ u(
|
|
1064
|
+
children: l?.(a.toolName) ?? /* @__PURE__ */ u(he, {})
|
|
1045
1065
|
}), /* @__PURE__ */ u("span", { children: a.text })]
|
|
1046
1066
|
}),
|
|
1047
|
-
/* @__PURE__ */ u(
|
|
1067
|
+
/* @__PURE__ */ u(Oe, {
|
|
1048
1068
|
content: e.content,
|
|
1049
|
-
components:
|
|
1069
|
+
components: M
|
|
1050
1070
|
}),
|
|
1051
|
-
e.streaming &&
|
|
1071
|
+
e.streaming && N && /* @__PURE__ */ u("div", {
|
|
1052
1072
|
className: "bailey-streaming-hint",
|
|
1053
|
-
children:
|
|
1073
|
+
children: N
|
|
1054
1074
|
}),
|
|
1055
1075
|
!e.streaming && /* @__PURE__ */ d("div", {
|
|
1056
1076
|
className: "bailey-message-actions",
|
|
1057
|
-
children: [/* @__PURE__ */ u(
|
|
1077
|
+
children: [/* @__PURE__ */ u(_e, { markdown: e.content }), g?.(e)]
|
|
1058
1078
|
})
|
|
1059
1079
|
]
|
|
1060
1080
|
})
|
|
1061
1081
|
}, e.id);
|
|
1062
1082
|
}),
|
|
1063
|
-
/* @__PURE__ */ u("div", { ref:
|
|
1083
|
+
/* @__PURE__ */ u("div", { ref: j })
|
|
1064
1084
|
]
|
|
1065
1085
|
}),
|
|
1066
|
-
|
|
1086
|
+
P && c && /* @__PURE__ */ d("div", {
|
|
1067
1087
|
className: "bailey-privacy-note",
|
|
1068
1088
|
children: [
|
|
1069
1089
|
c.text,
|
|
@@ -1083,48 +1103,48 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
1083
1103
|
className: "bailey-error-actions",
|
|
1084
1104
|
children: [/* @__PURE__ */ u("button", {
|
|
1085
1105
|
type: "button",
|
|
1086
|
-
onClick:
|
|
1106
|
+
onClick: T,
|
|
1087
1107
|
className: "bailey-retry-button",
|
|
1088
1108
|
children: "Retry"
|
|
1089
1109
|
}), /* @__PURE__ */ u("button", {
|
|
1090
1110
|
type: "button",
|
|
1091
|
-
onClick:
|
|
1111
|
+
onClick: D,
|
|
1092
1112
|
"aria-label": "dismiss error",
|
|
1093
1113
|
className: "bailey-dismiss-button",
|
|
1094
1114
|
children: "✕"
|
|
1095
1115
|
})]
|
|
1096
1116
|
})]
|
|
1097
1117
|
}),
|
|
1098
|
-
!h && /* @__PURE__ */ u(
|
|
1118
|
+
!h && /* @__PURE__ */ u(we, {
|
|
1099
1119
|
events: b,
|
|
1100
1120
|
lastRequest: x,
|
|
1101
|
-
onClear:
|
|
1121
|
+
onClear: E
|
|
1102
1122
|
}),
|
|
1103
1123
|
/* @__PURE__ */ d("form", {
|
|
1104
1124
|
onSubmit: (e) => {
|
|
1105
|
-
e.preventDefault(), !(!
|
|
1125
|
+
e.preventDefault(), !(!k.trim() || S === "streaming") && (w(k), A(""));
|
|
1106
1126
|
},
|
|
1107
1127
|
className: "bailey-input-row",
|
|
1108
1128
|
children: [/* @__PURE__ */ u("input", {
|
|
1109
1129
|
type: "text",
|
|
1110
|
-
placeholder:
|
|
1111
|
-
"aria-label":
|
|
1112
|
-
value:
|
|
1113
|
-
onChange: (e) =>
|
|
1130
|
+
placeholder: F,
|
|
1131
|
+
"aria-label": F,
|
|
1132
|
+
value: k,
|
|
1133
|
+
onChange: (e) => A(e.target.value),
|
|
1114
1134
|
disabled: S === "streaming",
|
|
1115
1135
|
className: "bailey-input"
|
|
1116
1136
|
}), S === "streaming" ? /* @__PURE__ */ u("button", {
|
|
1117
1137
|
type: "button",
|
|
1118
|
-
onClick:
|
|
1138
|
+
onClick: ee,
|
|
1119
1139
|
"aria-label": "stop",
|
|
1120
1140
|
className: "bailey-stop-button",
|
|
1121
1141
|
children: "Stop"
|
|
1122
1142
|
}) : /* @__PURE__ */ u("button", {
|
|
1123
1143
|
type: "submit",
|
|
1124
1144
|
"aria-label": "send",
|
|
1125
|
-
disabled: !
|
|
1145
|
+
disabled: !k.trim(),
|
|
1126
1146
|
className: "bailey-send-button",
|
|
1127
|
-
children: /* @__PURE__ */ u(
|
|
1147
|
+
children: /* @__PURE__ */ u(fe, { className: "bailey-send-icon" })
|
|
1128
1148
|
})]
|
|
1129
1149
|
})
|
|
1130
1150
|
]
|
|
@@ -1133,6 +1153,6 @@ function Oe({ chat: e, placeholder: t, replyPlaceholder: n = Ce, suggestions: s,
|
|
|
1133
1153
|
}
|
|
1134
1154
|
//#endregion
|
|
1135
1155
|
//#region src/index.ts
|
|
1136
|
-
var
|
|
1156
|
+
var Me = "0.3.1-pre.2";
|
|
1137
1157
|
//#endregion
|
|
1138
|
-
export {
|
|
1158
|
+
export { he as ActivityIcon, Z as ArrowUpRightIcon, Me as BAILEYAI_CHAT_UI_VERSION, ne as BAILEY_CHART_PROMPT_FRAGMENT, A as BAILEY_TABLE_GRID_ROW_THRESHOLD, je as BaileyChatPanel, we as BaileyTracePanel, _e as CopyMarkdownButton, fe as HeartIcon, le as TRACE_KIND_LABEL, de as createBaileyMarkdownComponents, b as extractPseudoToolCalls, I as extractTableData, G as formatTraceGap, W as formatTraceTime, Y as hasTraceFailure, e as isSafeMarkdownUrl, E as joinInstructions, L as parseBaileyChartSpec, S as parseSseFrames, k as resolveToolCall, te as shouldUseGrid, X as toActivityLines, K as toTraceRows, J as toTraceSegments, B as traceEventArgsDetail, U as traceEventHint, V as traceEventOutputDetail, H as traceEventRawDetail, ue as traceEventSummary, z as traceEventToolName, q as traceSummaryLine, T as useBaileyChat };
|