teodor-new-chat-ui 2.0.22 → 2.0.23
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/index.esm.js +11 -11
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2902,7 +2902,7 @@ function gp({
|
|
|
2902
2902
|
const Y = _ ? St(e.content) : O;
|
|
2903
2903
|
C(e.id, Y);
|
|
2904
2904
|
}, oe = () => I == null ? void 0 : I(t), ie = () => {
|
|
2905
|
-
const ge = A(T ? "h-3 w-3" : "h-4 w-4", "opacity-60 flex-shrink-0");
|
|
2905
|
+
const ge = A(T ? "h-3 w-3" : "h-4 w-4", "opacity-60 flex-shrink-0 text-current dark:text-primary-foreground");
|
|
2906
2906
|
switch (P) {
|
|
2907
2907
|
case "user":
|
|
2908
2908
|
return /* @__PURE__ */ c(Bu, { className: ge });
|
|
@@ -3021,11 +3021,11 @@ function gp({
|
|
|
3021
3021
|
const he = O.trim();
|
|
3022
3022
|
if (he.length > g)
|
|
3023
3023
|
return /* @__PURE__ */ R(As, { open: F, onOpenChange: G, children: [
|
|
3024
|
-
/* @__PURE__ */ c("div", { className: A("text-sm text-
|
|
3024
|
+
/* @__PURE__ */ c("div", { className: A("text-sm text-gray-900 dark:text-primary-foreground", T && "text-xs"), children: F ? /* @__PURE__ */ c(gn, { content: he }) : /* @__PURE__ */ R("pre", { className: A("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-gray-900 dark:text-primary-foreground", T && "text-xs"), children: [
|
|
3025
3025
|
he.substring(0, g),
|
|
3026
3026
|
"..."
|
|
3027
3027
|
] }) }),
|
|
3028
|
-
/* @__PURE__ */ c(Ps, { asChild: !0, children: /* @__PURE__ */ c(fe, { variant: "ghost", size: "sm", className: "h-6 text-xs text-
|
|
3028
|
+
/* @__PURE__ */ c(Ps, { asChild: !0, children: /* @__PURE__ */ c(fe, { variant: "ghost", size: "sm", className: "h-6 text-xs !text-gray-900 dark:!text-primary-foreground", children: F ? /* @__PURE__ */ R(De, { children: [
|
|
3029
3029
|
/* @__PURE__ */ c(Wt, { className: "h-3 w-3 mr-1" }),
|
|
3030
3030
|
" Show less"
|
|
3031
3031
|
] }) : /* @__PURE__ */ R(De, { children: [
|
|
@@ -3114,7 +3114,7 @@ function gp({
|
|
|
3114
3114
|
size: "sm",
|
|
3115
3115
|
onClick: ae,
|
|
3116
3116
|
className: A("h-6 w-6 p-0 hover:bg-background/50 text-current", T && "h-5 w-5"),
|
|
3117
|
-
children: /* @__PURE__ */ c(ns, { className: A(D ? "text-success" : "", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3117
|
+
children: /* @__PURE__ */ c(ns, { className: A(D ? "text-success" : "text-current", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3118
3118
|
}
|
|
3119
3119
|
),
|
|
3120
3120
|
P === "user" && C && /* @__PURE__ */ c(
|
|
@@ -3124,7 +3124,7 @@ function gp({
|
|
|
3124
3124
|
size: "sm",
|
|
3125
3125
|
onClick: V,
|
|
3126
3126
|
className: A("h-6 w-6 p-0 hover:bg-background/50 text-current", T && "h-5 w-5"),
|
|
3127
|
-
children: /* @__PURE__ */ c(rs, { className: A(T ? "h-3 w-3" : "h-4 w-4") })
|
|
3127
|
+
children: /* @__PURE__ */ c(rs, { className: A("text-current", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3128
3128
|
}
|
|
3129
3129
|
),
|
|
3130
3130
|
P === "assistant" && I && /* @__PURE__ */ c(
|
|
@@ -3134,7 +3134,7 @@ function gp({
|
|
|
3134
3134
|
size: "sm",
|
|
3135
3135
|
onClick: oe,
|
|
3136
3136
|
className: A("h-6 w-6 p-0 hover:bg-background/50 text-current", T && "h-5 w-5"),
|
|
3137
|
-
children: /* @__PURE__ */ c(Wr, { className: A(T ? "h-3 w-3" : "h-4 w-4") })
|
|
3137
|
+
children: /* @__PURE__ */ c(Wr, { className: A("text-current", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3138
3138
|
}
|
|
3139
3139
|
)
|
|
3140
3140
|
]
|
|
@@ -3173,7 +3173,7 @@ function gp({
|
|
|
3173
3173
|
disabled: !y.canGoBack,
|
|
3174
3174
|
onClick: () => x == null ? void 0 : x(),
|
|
3175
3175
|
title: "Go back to previous branch",
|
|
3176
|
-
children: /* @__PURE__ */ c(Fu, { className: "h-3 w-3" })
|
|
3176
|
+
children: /* @__PURE__ */ c(Fu, { className: "h-3 w-3 text-current" })
|
|
3177
3177
|
}
|
|
3178
3178
|
),
|
|
3179
3179
|
/* @__PURE__ */ c(
|
|
@@ -3185,7 +3185,7 @@ function gp({
|
|
|
3185
3185
|
disabled: !y.canGoForward,
|
|
3186
3186
|
onClick: () => E == null ? void 0 : E(),
|
|
3187
3187
|
title: "Go forward to next branch",
|
|
3188
|
-
children: /* @__PURE__ */ c(da, { className: "h-3 w-3" })
|
|
3188
|
+
children: /* @__PURE__ */ c(da, { className: "h-3 w-3 text-current" })
|
|
3189
3189
|
}
|
|
3190
3190
|
)
|
|
3191
3191
|
] })
|
|
@@ -3206,7 +3206,7 @@ function gp({
|
|
|
3206
3206
|
size: "sm",
|
|
3207
3207
|
onClick: ae,
|
|
3208
3208
|
className: A("h-6 w-6 p-0 hover:bg-background/50 text-current", T && "h-5 w-5"),
|
|
3209
|
-
children: /* @__PURE__ */ c(ns, { className: A(D ? "text-success" : "", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3209
|
+
children: /* @__PURE__ */ c(ns, { className: A(D ? "text-success" : "text-current", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3210
3210
|
}
|
|
3211
3211
|
),
|
|
3212
3212
|
P === "user" && C && /* @__PURE__ */ c(
|
|
@@ -3216,7 +3216,7 @@ function gp({
|
|
|
3216
3216
|
size: "sm",
|
|
3217
3217
|
onClick: V,
|
|
3218
3218
|
className: A("h-6 w-6 p-0 hover:bg-background/50 text-current", T && "h-5 w-5"),
|
|
3219
|
-
children: /* @__PURE__ */ c(rs, { className: A(T ? "h-3 w-3" : "h-4 w-4") })
|
|
3219
|
+
children: /* @__PURE__ */ c(rs, { className: A("text-current", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3220
3220
|
}
|
|
3221
3221
|
),
|
|
3222
3222
|
P === "assistant" && I && /* @__PURE__ */ c(
|
|
@@ -3226,7 +3226,7 @@ function gp({
|
|
|
3226
3226
|
size: "sm",
|
|
3227
3227
|
onClick: oe,
|
|
3228
3228
|
className: A("h-6 w-6 p-0 hover:bg-background/50 text-current", T && "h-5 w-5"),
|
|
3229
|
-
children: /* @__PURE__ */ c(Wr, { className: A(T ? "h-3 w-3" : "h-4 w-4") })
|
|
3229
|
+
children: /* @__PURE__ */ c(Wr, { className: A("text-current", T ? "h-3 w-3" : "h-4 w-4") })
|
|
3230
3230
|
}
|
|
3231
3231
|
)
|
|
3232
3232
|
]
|
package/dist/index.umd.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=it(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&vn.assertOptions(r,{silentJSONParsing:He.transitional(He.boolean),forcedJSONParsing:He.transitional(He.boolean),clarifyTimeoutError:He.transitional(He.boolean)},!1),o!=null&&(S.isFunction(o)?n.paramsSerializer={serialize:o}:vn.assertOptions(o,{encode:He.function,serialize:He.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),vn.assertOptions(n,{baseUrl:He.spelling("baseURL"),withXsrfToken:He.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let a=s&&S.merge(s.common,s[n.method]);s&&S.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),n.headers=Ne.concat(a,s);const c=[];let d=!0;this.interceptors.request.forEach(function(h){typeof h.runWhen=="function"&&h.runWhen(n)===!1||(d=d&&h.synchronous,c.unshift(h.fulfilled,h.rejected))});const f=[];this.interceptors.response.forEach(function(h){f.push(h.fulfilled,h.rejected)});let u,p=0,m;if(!d){const g=[Ds.bind(this),void 0];for(g.unshift(...c),g.push(...f),m=g.length,u=Promise.resolve(n);p<m;)u=u.then(g[p++],g[p++]);return u}m=c.length;let v=n;for(;p<m;){const g=c[p++],h=c[p++];try{v=g(v)}catch(b){h.call(this,b);break}}try{u=Ds.call(this,v)}catch(g){return Promise.reject(g)}for(p=0,m=f.length;p<m;)u=u.then(f[p++],f[p++]);return u}getUri(t){t=it(this.defaults,t);const n=Cs(t.baseURL,t.url,t.allowAbsoluteUrls);return hs(n,t.params,t.paramsSerializer)}};S.forEach(["delete","get","head","options"],function(t){ct.prototype[t]=function(n,r){return this.request(it(r||{},{method:t,url:n,data:(r||{}).data}))}}),S.forEach(["post","put","patch"],function(t){function n(r){return function(s,a,c){return this.request(it(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}ct.prototype[t]=n(),ct.prototype[t+"Form"]=n(!0)});let Xu=class Nd{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const a=new Promise(c=>{r.subscribe(c),s=c}).then(o);return a.cancel=function(){r.unsubscribe(s)},a},t(function(s,a,c){r.reason||(r.reason=new wt(s,a,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Nd(function(o){t=o}),cancel:t}}};function Yu(e){return function(n){return e.apply(null,n)}}function Ju(e){return S.isObject(e)&&e.isAxiosError===!0}const Pr={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Pr).forEach(([e,t])=>{Pr[t]=e});function $s(e){const t=new ct(e),n=Qo(ct.prototype.request,t);return S.extend(n,ct.prototype,t,{allOwnKeys:!0}),S.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return $s(it(e,o))},n}const me=$s(Ut);me.Axios=ct,me.CanceledError=wt,me.CancelToken=Xu,me.isCancel=ws,me.VERSION=Ls,me.toFormData=pn,me.AxiosError=ne,me.Cancel=me.CanceledError,me.all=function(t){return Promise.all(t)},me.spread=Yu,me.isAxiosError=Ju,me.mergeConfig=it,me.AxiosHeaders=Ne,me.formToJSON=e=>bs(S.isHTMLForm(e)?new FormData(e):e),me.getAdapter=Ms.getAdapter,me.HttpStatusCode=Pr,me.default=me;const{Axios:pw,AxiosError:hw,CanceledError:gw,isCancel:mw,CancelToken:bw,VERSION:vw,all:ww,Cancel:yw,isAxiosError:xw,spread:Sw,toFormData:Cw,AxiosHeaders:Ew,HttpStatusCode:Nw,formToJSON:Tw,getAdapter:Aw,mergeConfig:Pw}=me,_r={};function Ht(){var e;try{return typeof window<"u"&&((e=window.localStorage)==null?void 0:e.getItem("chat-debug"))==="1"}catch{return!1}}const Bs=_r==null?void 0:_r.VITE_API_BASE_URL,Us=Bs?Bs.replace(/\/+$/,""):void 0;!Us&&typeof window<"u"&&console.warn("VITE_API_BASE_URL is not set. The API client will need to be configured via apiConfig prop.");let wn=null;const Ir=new Set;function Or(){return wn}function kr(e){wn=e,Ir.forEach(t=>t(e))}function zs(e){return Ir.add(e),()=>Ir.delete(e)}const We=me.create({baseURL:Us||"http://localhost:8000",timeout:3e4,withCredentials:!0});We.interceptors.request.use(e=>(wn&&(e.headers.Authorization=`Bearer ${wn}`),e)),We.interceptors.response.use(e=>e,e=>Promise.reject(e));async function lt(e,t){return(await We.get(e,t)).data}async function Mr(e,t,n){return(await We.post(e,t,n)).data}async function Hs(e,t,n){return(await We.put(e,t,n)).data}async function Ws(e,t){return(await We.delete(e,t)).data}async function Zu(e,t){var m;if(Ht()){let v=t.body;try{const g=JSON.parse(JSON.stringify(t.body));(m=g==null?void 0:g.payload)!=null&&m.files_info&&Array.isArray(g.payload.files_info)&&(g.payload.files_info=g.payload.files_info.map(h=>({...h,data:h!=null&&h.data?`<base64 ${String(h.data).length} chars>`:h==null?void 0:h.data}))),v=g}catch{}console.debug("[api.stream]",t.method,`${We.defaults.baseURL}${e}`,v)}const r=(We.defaults.baseURL||"").replace(/\/+$|^\s+|\s+$/g,""),o=t.method??"POST",s=Or(),a=t.headers??{},c=e?e.startsWith("/")?e:`/${e}`:"",d=r?`${r}${c}`:c||r,f=await fetch(d,{method:o,headers:{"Content-Type":"application/json",...s?{Authorization:`Bearer ${s}`}:{},...a},body:t.body!==void 0?JSON.stringify(t.body):void 0,credentials:"include",signal:t.signal});if(!f.ok||!f.body){const v=await f.text().catch(()=>"");throw Ht()&&console.debug("[api.stream] non-OK",f.status,v==null?void 0:v.slice(0,500)),new Error(`Stream failed: ${f.status} ${f.statusText}${v?": "+v:""}`)}const u=f.body.getReader(),p=new TextDecoder;for(;;){const{done:v,value:g}=await u.read();if(v)break;const h=p.decode(g,{stream:!0});Ht()&&console.debug("[api.stream] chunk",h.slice(0,200)),t.onChunk(h)}}function Ve(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class yn{get baseUrl(){const t=We.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(We.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&kr(t.authToken)}getAuthToken(){return Or()}setAuthToken(t){kr(t)}onTokenChange(t){return zs(t)}async listThreads(){const t=await lt("/chat/threads"),n=Ve(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Mr("/chat/threads",t?{title:t}:void 0);return Ve(r)}async updateThread(t,n){const r=await Hs(`/chat/threads/${t}`,{title:n});return Ve(r)}async deleteThread(t){const n=await Ws(`/chat/threads/${t}`);return Ve(n)}async threadInfo(t){const n=await lt(`/chat/threads/${t}/info`);return Ve(n)}async getMessages(t){const n=await lt("/chat/messages",{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Ve(n)}async getState(t){const n=await lt("/chat/state",{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Ve(n)}async getStateHistory(t){const n=await lt("/chat/state/history",{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return Ve(n)}async listCheckpoints(t){const n=await lt("/chat/checkpoints",{params:{thread_id:t}});return Ve(n)}async uploadImage(t,n="/upload"){const r=new FormData;r.append("file",t,t.name),Ht()&&console.debug("[api.uploadImage] ->",n,{name:t.name,type:t.type,size:t.size});const o=await Mr(n,r,{headers:{Accept:"application/json"},maxBodyLength:1/0}),s=Ve(o);if(Ht()&&console.debug("[api.uploadImage] <-",s),!(s!=null&&s.url))throw new Error("Invalid upload response: missing url");return{url:s.url,mimeType:s.mimeType??t.type,name:s.name??t.name,size:s.size??t.size}}}const Ye=new yn;function Vs(e={}){const t=e.baseUrl??"/api/chat",n=e.streamPath??"/stream",[r,o]=P.useState(e.token??null),s=P.useRef(e.headers??{}),[a,c]=P.useState(!1),[d,f]=P.useState(null),[u,p]=P.useState(""),[m,v]=P.useState(null),g=P.useRef(null),h=P.useCallback(x=>{o(x)},[]),b=P.useCallback(()=>{var x;(x=g.current)==null||x.abort(),g.current=null,c(!1)},[]),w=P.useCallback(()=>{p(""),v(null),f(null)},[]),y=P.useCallback((x,E,C)=>{g.current&&(g.current.abort(),g.current=null),c(!0),f(null),e.autoAppendAssistant!==!1&&p("");const O=new AbortController;return g.current=O,(async()=>{var M,L,j,G;const N=(()=>{var V;try{return typeof window<"u"&&((V=window.localStorage)==null?void 0:V.getItem("chat-debug"))==="1"}catch{return!1}})(),F=V=>{var z;try{const X=JSON.parse(JSON.stringify(V));return(z=X==null?void 0:X.payload)!=null&&z.files_info&&Array.isArray(X.payload.files_info)&&(X.payload.files_info=X.payload.files_info.map($=>({...$,data:$!=null&&$.data?`<base64 ${String($.data).length} chars>`:$==null?void 0:$.data}))),X}catch{return V}};try{let V={};try{if(r)V={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const _=window.__AUTH_TOKEN__,I=((M=window.localStorage)==null?void 0:M.getItem("authToken"))||null;let k=null;try{const B=(L=window.localStorage)==null?void 0:L.getItem("chat-settings");B&&(k=((j=JSON.parse(B))==null?void 0:j.apiKey)||null)}catch{}const Y=_||I||k||null;Y&&(V={Authorization:`Bearer ${Y}`})}}catch{}N&&console.debug("[use-chat] POST",t+n,F(x));const z=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...V,...s.current},body:JSON.stringify(x),signal:O.signal});if(!z.ok||!z.body){const T=await z.text().catch(()=>"");throw N&&console.debug("[use-chat] non-OK response",z.status,T==null?void 0:T.slice(0,500)),new Error(`stream ${z.status}${T?": "+T:""}`)}const X=z.body.getReader(),$=new TextDecoder;let q="";for(;;){const{value:T,done:_}=await X.read();if(_)break;q+=$.decode(T,{stream:!0});let I;for(;(I=q.indexOf(`
|
|
7
7
|
|
|
8
8
|
`))>=0;){const k=q.slice(0,I);q=q.slice(I+2);const Y=ef(k);if(!Y)continue;let B;try{B=JSON.parse(Y)}catch{N&&console.debug("[use-chat] skip malformed SSE data:",Y==null?void 0:Y.slice(0,200));continue}const H=Qu(B)?B.data:B;if(N&&console.debug("[use-chat] event:",H==null?void 0:H.type,H),E==null||E(H),H.type==="token")e.autoAppendAssistant!==!1&&p(de=>de+H.content);else if(H.type==="message_delta"){const de=H.delta.filter(ce=>ce.type==="text").map(ce=>ce.text).join("");de&&e.autoAppendAssistant!==!1&&p(ce=>ce+de)}else H.type==="checkpoint"?v(H.checkpointId):H.type==="error"&&f(H.message)}}}catch(V){if((V==null?void 0:V.name)==="AbortError")return;const z=(V==null?void 0:V.message)||String(V);N&&console.debug("[use-chat] error:",z),f(z),(G=C==null?void 0:C.onError)==null||G.call(C,z)}finally{c(!1),g.current=null}})(),{close:()=>O.abort()}},[t,r,e.autoAppendAssistant]);return P.useEffect(()=>()=>{var x;return(x=g.current)==null?void 0:x.abort()},[]),{isStreaming:a,error:d,assistantText:u,lastCheckpointId:m,stream:y,stop:b,clear:w,setToken:h}}function Qu(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function ef(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
9
|
-
`)}const tf={messages:[],assemblingId:null,lastCheckpointId:null,toolIndex:{}};function nf(e,t){var n,r;switch(t.type){case"reset":return{messages:js(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,toolIndex:{}};case"seed":return{...e,messages:js(t.payload.messages)};case"user_message":{const o=t.payload.message;if(e.assemblingId){const s=e.messages.findIndex(a=>a.id===e.assemblingId&&a.role==="assistant");if(s>=0){const a=e.messages.slice(0,s),c=e.messages.slice(s);return{...e,messages:[...a,o,...c]}}}return{...e,messages:[...e.messages,o]}}case"event":{const o=t.payload.ev;if(o.type==="message_start"&&o.role==="assistant"){const s=o.id,a=af(o.model),c={id:s,role:"assistant",name:a||void 0,model:o.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,c]}}if(o.type==="token"){const s=e.assemblingId??Dr(e.messages);return s?{...e,messages:rf(e.messages,s,o.content)}:e}if(o.type==="message_delta"){const s=e.assemblingId??Dr(e.messages);return s?{...e,messages:Ks(e.messages,s,o.delta)}:e}if(o.type==="message_end"){const s=e.assemblingId??Dr(e.messages);if(!s)return{...e,assemblingId:null};const a=e.messages,c=a.findIndex(d=>d.id===s&&d.role==="assistant");if(c>=0&&!((r=a[c].content)==null?void 0:r.some(u=>{var p;return(u==null?void 0:u.type)==="text"&&((p=u.text)==null?void 0:p.trim())}))){const u=[...a.slice(0,c),...a.slice(c+1)];return{...e,assemblingId:null,messages:u}}return{...e,assemblingId:null}}if(o.type==="tool_start"){const s=`tool-${o.id}`,a={type:"tool_call",id:o.id,name:o.name,args:o.args},c={id:s,role:"tool",name:o.name,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,c],toolIndex:{...e.toolIndex,[o.id]:s}}}if(o.type==="tool_result"){const s=e.toolIndex[o.id]??`tool-${o.id}`,a={type:"tool_result",toolCallId:o.id,output:o.output,error:o.error},c=e.messages.find(u=>u.id===s),d={id:s,role:"tool",content:[a],createdAt:new Date().toISOString()},f=c?Ks(e.messages,s,[a]):[...e.messages,d];return{...e,messages:f}}if(o.type==="checkpoint"){const s=sf(e.messages,o.checkpointId);return{...e,lastCheckpointId:o.checkpointId,messages:s}}if(o.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${o.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}return e}default:return e}}function Rs(e=[]){const[t,n]=P.useReducer(nf,{...tf,messages:e}),r=P.useCallback(s=>{n({type:"event",payload:{ev:s}})},[]),o=P.useMemo(()=>({reset:s=>n({type:"reset",payload:{messages:s}}),seed:s=>n({type:"seed",payload:{messages:s}}),pushUser:s=>n({type:"user_message",payload:{message:s}}),onEvent:r}),[r]);return{state:t,dispatch:n,...o}}function js(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function Dr(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function rf(e,t,n){return e.map(r=>{if(r.id!==t)return r;const o=r.content.slice(),s=o[o.length-1];return s&&s.type==="text"?s.text+=n:o.push({type:"text",text:n}),{...r,content:o}})}function Ks(e,t,n){return e.map(r=>r.id===t?{...r,content:of(r.content,n)}:r)}function of(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function sf(e,t){for(let n=e.length-1;n>=0;n--)if(e[n].role==="assistant"){const o={...e[n],checkpointId:t};return[...e.slice(0,n),o,...e.slice(n+1)]}return e}function af(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const Gs=P.createContext(null);function Wt({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null}){const s=Ye;P.useEffect(()=>{t&&s.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[s,t]);const{isStreaming:a,error:c,stream:d,stop:f,setToken:u}=Vs({baseUrl:s.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/stream"}),[p,m]=P.useState(()=>typeof s.getAuthToken=="function"?s.getAuthToken():null);P.useEffect(()=>{u(typeof s.getAuthToken=="function"?s.getAuthToken():null);const I=s.onTokenChange(k=>{m(k),u(k)});return()=>{I()}},[s,u]);const v=P.useCallback(I=>{s.setAuthToken(I)},[s]),{state:g,seed:h,pushUser:b,onEvent:w,reset:y}=Rs(),[x,E]=P.useState([]),[C,O]=P.useState(null),N=P.useCallback(async()=>{const I=await s.listThreads();E(I)},[s]);P.useEffect(()=>{N().catch(()=>{})},[N]),P.useEffect(()=>{r==null||r(C)},[C,r]);const F=P.useRef(null);P.useEffect(()=>{o&&F.current!==o&&(F.current=o,L(o).catch(()=>{}))},[o]);const M=P.useRef(null),L=P.useCallback(async(I,k,Y)=>{var B;if(M.current!==I){M.current=I;try{const H=k??((B=(await s.listCheckpoints(I)).checkpoints.slice().sort((ce,R)=>new Date(R.createdAt).getTime()-new Date(ce.createdAt).getTime())[0])==null?void 0:B.checkpointId),de=await s.getMessages({threadId:I,checkpointId:H,checkpointNs:Y});O(I),h(de.messages)}finally{M.current=null}}},[s,h]),j=P.useCallback(async I=>s.listCheckpoints(I),[s]),G=P.useCallback(async I=>{if(!C)throw new Error("No active thread");const k=await s.getMessages({threadId:C,checkpointId:I});h(k.messages)},[s,C,h]),V=P.useCallback(async()=>{if(!C)throw new Error("No active thread");await L(C)},[C,L]),z=P.useRef(!1);P.useEffect(()=>{const I=z.current;if(z.current=a,I&&!a&&C){const k=g.lastCheckpointId??void 0;(async()=>{try{const Y=await s.getMessages({threadId:C,checkpointId:k});h(Y.messages)}catch{}try{await N()}catch{}})()}},[a,C,g.lastCheckpointId,s,h,N]);const X=P.useCallback(async I=>{const k=await s.createThread(I);return await N(),await L(k.threadId),k.threadId},[s,N,L]),$=P.useCallback(async I=>{await s.deleteThread(I),await N(),C===I&&(O(null),y([]))},[s,N,C,y]),q=P.useCallback(async(I,k)=>{await s.updateThread(I,k),await N()},[s,N]),T=P.useCallback(async(I,k)=>{var ie;if(!C)throw new Error("No active thread");async function Y(W){return await new Promise((ee,pe)=>{const he=new FileReader;he.onload=()=>ee(String(he.result)),he.onerror=J=>pe(J),he.readAsDataURL(W)})}async function B(W){return await new Promise((ee,pe)=>{const he=new FileReader;he.onload=()=>{try{const J=he.result;let ve="";const re=new Uint8Array(J),ge=re.byteLength;for(let ye=0;ye<ge;ye++)ve+=String.fromCharCode(re[ye]);ee(btoa(ve))}catch(J){pe(J)}},he.onerror=J=>pe(J),he.readAsArrayBuffer(W)})}const H=[];I&&H.push({type:"text",text:I});const de=(k==null?void 0:k.attachments)||[];let ce=[];if(de.length>0)for(const W of de)if(W.type&&W.type.startsWith("image/")){let ee=null;try{const pe=await s.uploadImage(W,(t==null?void 0:t.uploadPath)||"/upload").catch(()=>null);ee=(pe==null?void 0:pe.url)||null}catch{}if(!ee)try{ee=await Y(W)}catch{ee=null}if(ee){const pe={type:"image_url",url:ee,mimeType:W.type,alt:W.name};H.push(pe)}try{ce.push({filename:W.name,data:await B(W),mime_type:W.type||"application/octet-stream"})}catch{}}else{const ee=await Y(W).catch(()=>null),pe={type:"file",url:String(ee),mimeType:W.type||void 0,name:W.name,size:W.size};H.push(pe);try{ce.push({filename:W.name,data:await B(W),mime_type:W.type||"application/octet-stream"})}catch{}}const R={id:((ie=crypto.randomUUID)==null?void 0:ie.call(crypto))||`user-${Date.now()}`,role:"user",content:H,createdAt:new Date().toISOString(),checkpointId:(k==null?void 0:k.checkpointId)??g.lastCheckpointId??void 0};b(R);const ae={...R,content:R.content.filter(W=>W.type==="text"||W.type==="image_url")},le={threadId:C,payload:{messages:[ae],attachments:R.content.filter(W=>W.type==="file").map(W=>({type:"file",url:W.url,mimeType:W.mimeType,name:W.name,size:W.size})),files_info:ce,...(k==null?void 0:k.payloadExtras)??{}},checkpointId:(k==null?void 0:k.checkpointId)??g.lastCheckpointId??void 0,checkpointNs:k==null?void 0:k.checkpointNs,nodeFilter:k==null?void 0:k.nodeFilter,config:k==null?void 0:k.config};d(le,W=>w(W),{onError:W=>console.warn("stream error",W)})},[C,b,d,w,g.lastCheckpointId,s,t==null?void 0:t.uploadPath]),_={baseUrl:s.baseUrl,token:p,setToken:v,api:s,threads:x,currentThreadId:C,setCurrentThreadId:O,messages:g.messages,isStreaming:a,error:c,lastCheckpointId:g.lastCheckpointId,streamingAssistantId:g.assemblingId,refreshThreads:N,createThread:X,deleteThread:$,renameThread:q,loadThread:L,listCheckpoints:j,navigateToCheckpoint:G,returnToLatest:V,send:T,stop:f};return i.jsx(Gs.Provider,{value:_,children:e})}function Lr(){const e=P.useContext(Gs);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function A(...e){return Ad.twMerge(Td.clsx(e))}const cf=Lt.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),fe=l.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const a=r?Pe.Slot:"button";return i.jsx(a,{className:A(cf({variant:t,size:n,className:e})),ref:s,...o})});fe.displayName="Button";const qs=l.forwardRef(({className:e,...t},n)=>i.jsx("textarea",{className:A("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));qs.displayName="Textarea";const lf=Lt.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Xs({className:e,variant:t,...n}){return i.jsx("div",{className:A(lf({variant:t}),e),...n})}function U(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function df(e,t){const n=l.createContext(t),r=s=>{const{children:a,...c}=s,d=l.useMemo(()=>c,Object.values(c));return i.jsx(n.Provider,{value:d,children:a})};r.displayName=e+"Provider";function o(s){const a=l.useContext(n);if(a)return a;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Le(e,t=[]){let n=[];function r(s,a){const c=l.createContext(a),d=n.length;n=[...n,a];const f=p=>{var w;const{scope:m,children:v,...g}=p,h=((w=m==null?void 0:m[e])==null?void 0:w[d])||c,b=l.useMemo(()=>g,Object.values(g));return i.jsx(h.Provider,{value:b,children:v})};f.displayName=s+"Provider";function u(p,m){var h;const v=((h=m==null?void 0:m[e])==null?void 0:h[d])||c,g=l.useContext(v);if(g)return g;if(a!==void 0)return a;throw new Error(`\`${p}\` must be used within \`${s}\``)}return[f,u]}const o=()=>{const s=n.map(a=>l.createContext(a));return function(c){const d=(c==null?void 0:c[e])||s;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:d}}),[c,d])}};return o.scopeName=e,[r,uf(o,...t)]}function uf(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const a=r.reduce((c,{useScope:d,scopeName:f})=>{const p=d(s)[`__scope${f}`];return{...c,...p}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:a}),[a])}};return n.scopeName=t.scopeName,n}var be=globalThis!=null&&globalThis.document?l.useLayoutEffect:()=>{},ff=l[" useInsertionEffect ".trim().toString()]||be;function Qe({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,a]=pf({defaultProp:t,onChange:n}),c=e!==void 0,d=c?e:o;{const u=l.useRef(e!==void 0);l.useEffect(()=>{const p=u.current;p!==c&&console.warn(`${r} is changing from ${p?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),u.current=c},[c,r])}const f=l.useCallback(u=>{var p;if(c){const m=hf(u)?u(e):u;m!==e&&((p=a.current)==null||p.call(a,m))}else s(u)},[c,e,s,a]);return[d,f]}function pf({defaultProp:e,onChange:t}){const[n,r]=l.useState(e),o=l.useRef(n),s=l.useRef(t);return ff(()=>{s.current=t},[t]),l.useEffect(()=>{var a;o.current!==n&&((a=s.current)==null||a.call(s,n),o.current=n)},[n,o]),[n,r,s]}function hf(e){return typeof e=="function"}function Ys(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Fr(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Ys(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():Ys(e[o],null)}}}}function oe(...e){return l.useCallback(Fr(...e),e)}var gf=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Z=gf.reduce((e,t)=>{const n=Pe.createSlot(`Primitive.${t}`),r=l.forwardRef((o,s)=>{const{asChild:a,...c}=o,d=a?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(d,{...c,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Js(e,t){e&&cn.flushSync(()=>e.dispatchEvent(t))}function mf(e,t){return l.useReducer((n,r)=>t[n][r]??n,e)}var Te=e=>{const{present:t,children:n}=e,r=bf(t),o=typeof n=="function"?n({present:r.isPresent}):l.Children.only(n),s=oe(r.ref,vf(o));return typeof n=="function"||r.isPresent?l.cloneElement(o,{ref:s}):null};Te.displayName="Presence";function bf(e){const[t,n]=l.useState(),r=l.useRef(null),o=l.useRef(e),s=l.useRef("none"),a=e?"mounted":"unmounted",[c,d]=mf(a,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{const f=xn(r.current);s.current=c==="mounted"?f:"none"},[c]),be(()=>{const f=r.current,u=o.current;if(u!==e){const m=s.current,v=xn(f);e?d("MOUNT"):v==="none"||(f==null?void 0:f.display)==="none"?d("UNMOUNT"):d(u&&m!==v?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,d]),be(()=>{if(t){let f;const u=t.ownerDocument.defaultView??window,p=v=>{const h=xn(r.current).includes(CSS.escape(v.animationName));if(v.target===t&&h&&(d("ANIMATION_END"),!o.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",f=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},m=v=>{v.target===t&&(s.current=xn(r.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{u.clearTimeout(f),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:l.useCallback(f=>{r.current=f?getComputedStyle(f):null,n(f)},[])}}function xn(e){return(e==null?void 0:e.animationName)||"none"}function vf(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var wf=l[" useId ".trim().toString()]||(()=>{}),yf=0;function Fe(e){const[t,n]=l.useState(wf());return be(()=>{n(r=>r??String(yf++))},[e]),t?`radix-${t}`:""}var Sn="Collapsible",[xf,_w]=Le(Sn),[Sf,$r]=xf(Sn),Zs=l.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:a,...c}=e,[d,f]=Qe({prop:r,defaultProp:o??!1,onChange:a,caller:Sn});return i.jsx(Sf,{scope:n,disabled:s,contentId:Fe(),open:d,onOpenToggle:l.useCallback(()=>f(u=>!u),[f]),children:i.jsx(Z.div,{"data-state":Ur(d),"data-disabled":s?"":void 0,...c,ref:t})})});Zs.displayName=Sn;var Qs="CollapsibleTrigger",ea=l.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=$r(Qs,n);return i.jsx(Z.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ur(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:U(e.onClick,o.onOpenToggle)})});ea.displayName=Qs;var Br="CollapsibleContent",Cf=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=$r(Br,e.__scopeCollapsible);return i.jsx(Te,{present:n||o.open,children:({present:s})=>i.jsx(Ef,{...r,ref:t,present:s})})});Cf.displayName=Br;var Ef=l.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,a=$r(Br,n),[c,d]=l.useState(r),f=l.useRef(null),u=oe(t,f),p=l.useRef(0),m=p.current,v=l.useRef(0),g=v.current,h=a.open||c,b=l.useRef(h),w=l.useRef(void 0);return l.useEffect(()=>{const y=requestAnimationFrame(()=>b.current=!1);return()=>cancelAnimationFrame(y)},[]),be(()=>{const y=f.current;if(y){w.current=w.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const x=y.getBoundingClientRect();p.current=x.height,v.current=x.width,b.current||(y.style.transitionDuration=w.current.transitionDuration,y.style.animationName=w.current.animationName),d(r)}},[a.open,r]),i.jsx(Z.div,{"data-state":Ur(a.open),"data-disabled":a.disabled?"":void 0,id:a.contentId,hidden:!h,...s,ref:u,style:{"--radix-collapsible-content-height":m?`${m}px`:void 0,"--radix-collapsible-content-width":g?`${g}px`:void 0,...e.style},children:h&&o})});function Ur(e){return e?"open":"closed"}var Nf=Zs;const ta=Nf,na=ea;function Vt({content:e,className:t=""}){return i.jsx("div",{className:`prose prose-sm max-w-none break-words dark:prose-invert prose-pre:rounded prose-pre:border prose-pre:bg-background/50 prose-code:bg-background/50 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-table:my-4 prose-th:px-2 prose-td:px-2 leading-relaxed ${t}`,children:i.jsx(Pd,{remarkPlugins:[_d],children:e})})}function ra({message:e,messageIndex:t,isStreamingMessage:n=!1,streamingDebounceMs:r=40,isEditing:o=!1,showActions:s=!0,showTimestamp:a=!0,showAgentName:c=!0,layoutSize:d="desktop",truncateToolMessages:f=!0,toolMessagePreviewLength:u=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:v={},checkpointBranches:g=[],currentCheckpointId:h,onSwitchToCheckpoint:b,onReturnToMainThread:w,temporalNavigation:y,onNavigateToPreviousBranch:x,onNavigateToNextBranch:E,onEdit:C,onRegenerate:O,onEditFromCheckpoint:N,onCancelEdit:F,onCopy:M}){const[L,j]=P.useState(!1),[G,V]=P.useState(!1),[z,X]=P.useState(!1),[$,q]=P.useState(!1),T=d==="phone"||d==="half-screen",_=e.role,I=_==="tool",k=P.useMemo(()=>Tf(e.content),[e.content]),Y=P.useMemo(()=>kf(e.content),[e.content]),B=P.useMemo(()=>e.content.filter(J=>J.type==="image_url"),[e.content]),H=P.useMemo(()=>e.content.filter(J=>J.type==="file"),[e.content]),de=Lf(k,n?r:0),ce=async()=>{try{const J=I?yt(e.content):k;await navigator.clipboard.writeText(J),j(!0),setTimeout(()=>j(!1),2e3),M==null||M(J)}catch(J){console.error("Failed to copy:",J)}},R=()=>{if(!C)return;const J=I?yt(e.content):k;C(e.id,J)},ae=()=>O==null?void 0:O(t),le=()=>{const ve=A(T?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0");switch(_){case"user":return i.jsx(K.User,{className:ve});case"assistant":return i.jsx(K.Bot,{className:ve});case"tool":return i.jsx(K.Wrench,{className:ve});default:return i.jsx(K.Bot,{className:ve})}},ie=()=>{const J="group relative mb-4 max-w-full";switch(_){case"user":return A(J,"flex justify-end");case"assistant":case"tool":case"system":return A(J,"flex justify-start");default:return J}},W=()=>{const J=A("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 break-words",T&&"px-3 py-2 text-sm");switch(_){case"user":return A(J,"max-w-[95%]",d==="phone"&&"max-w-[98%]","bg-blue-50 text-gray-900 dark:bg-primary dark:text-primary-foreground","border border-blue-100 dark:border-transparent");case"assistant":return A(J,"max-w-[95%]",d==="phone"&&"max-w-[98%]","bg-white text-gray-900 border border-gray-200 dark:bg-muted dark:text-muted-foreground dark:border-transparent");case"tool":return A(J,"bg-secondary/50 text-secondary-foreground border border-dashed max-w-[95%]",d==="phone"&&"max-w-[98%]");case"system":return A(J,"bg-accent/40 text-muted-foreground max-w-[85%] border");default:return J}},ee=J=>{if(!J)return"";try{return new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},pe=()=>{if(e.model==="reflection"){const re=k.trim(),ge=zr(re);if(ge&&typeof ge=="object")return i.jsx(Ff,{data:ge})}if(I&&Y.name==="get_issues"){const re=e.content.find(D=>D.type==="tool_result"),ge=(re==null?void 0:re.output)??yt(e.content),ye=sa(ge);if(ye)return i.jsx($f,{issues:ye})}if(I&&!z){const re=yt(e.content).slice(0,80).replace(/\s+/g," ");return i.jsx("div",{className:A("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",T&&"text-[10px]"),children:i.jsxs("span",{className:"truncate max-w-full text-current",children:[re,re.length>=80?"…":""]})})}if(I&&f){const re=yt(e.content),ge=re.length>u;return i.jsx(ta,{open:G,onOpenChange:V,children:i.jsxs("div",{className:"font-mono text-sm text-current",children:[i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",T&&"text-xs"),children:ge&&!G?re.substring(0,u)+"...":re}),ge&&i.jsx(na,{asChild:!0,children:i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:G?i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",re.length-u," chars)"]})})})]})})}if(I&&z&&!f){const re=Of(e.content);if(re&&Af(re))return i.jsx(Vt,{content:re.trim()});const ge=yt(e.content);return i.jsx("div",{className:"font-mono text-sm text-current",children:i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",T&&"text-xs"),children:ge})})}const J=B.length>0&&_!=="tool",ve=H.length>0&&_!=="tool";return i.jsxs("div",{children:[n?i.jsxs("div",{className:"relative",children:[(()=>{const re=zr(de);return re!==null?i.jsx(oa,{data:re}):i.jsx(Vt,{content:_f(Pf(de))})})(),i.jsx("span",{className:"inline-block w-[6px] h-[14px] align-baseline ml-0.5 bg-foreground/40 animate-pulse",style:{verticalAlign:"text-bottom"}})]}):(()=>{const re=zr(k.trim());if(re!==null)return i.jsx(oa,{data:re});if(_==="user"&&p){const ge=k.trim();if(ge.length>m)return i.jsxs(ta,{open:$,onOpenChange:q,children:[i.jsx("div",{className:A("text-sm text-current dark:text-primary-foreground",T&&"text-xs"),children:$?i.jsx(Vt,{content:ge}):i.jsxs("pre",{className:A("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-current dark:text-primary-foreground",T&&"text-xs"),children:[ge.substring(0,m),"..."]})}),i.jsx(na,{asChild:!0,children:i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current dark:!text-primary-foreground",children:$?i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",ge.length-m," chars)"]})})})]})}return i.jsx(Vt,{content:k.trim()})})(),J&&i.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:B.map((re,ge)=>i.jsxs("div",{className:"relative border rounded overflow-hidden",children:[i.jsx("img",{src:re.url,alt:re.alt??"image",className:"w-full h-auto"}),i.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[i.jsx(K.Image,{className:"h-3 w-3"}),i.jsx("span",{children:"image"})]})]},ge))}),ve&&i.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:H.map((re,ge)=>{const ye=re,D=ye.name||"file";return i.jsxs("a",{href:ye.url,download:D,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 bg-gray-100 border border-gray-200 rounded px-2 py-1 text-xs hover:bg-gray-200",title:D,children:[i.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-gray-400"}),i.jsx("span",{className:"truncate max-w-[180px]",children:D})]},ge)})})]})},he=P.useMemo(()=>Mf(e),[e]);return P.useMemo(()=>Df(e,h),[e,h]),i.jsx("div",{className:A(ie(),v.container),children:i.jsxs("div",{className:A(W(),v.content),children:[(a||c||I)&&i.jsxs("div",{className:A("flex items-center justify-between mb-2 pb-2 border-b border-current/10",T&&"mb-1 pb-1",v.header),children:[i.jsxs("div",{className:"flex items-center gap-2",children:[le(),c&&he&&i.jsx("span",{className:A("font-medium",T?"text-xs":"text-sm"),children:he}),I&&Y.name&&i.jsxs(Xs,{variant:"outline",className:A("text-xs flex items-center gap-1 cursor-pointer text-current",T&&"text-xs h-4"),onClick:()=>X(J=>!J),children:[i.jsx("span",{children:Y.name}),i.jsx("span",{className:"inline-flex items-center",children:z?i.jsx(K.ChevronUp,{className:"h-3 w-3"}):i.jsx(K.ChevronDown,{className:"h-3 w-3"})})]}),I&&!Y.name&&i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 px-1 text-current",onClick:()=>X(J=>!J),children:i.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",z?i.jsx(K.ChevronUp,{className:"h-3 w-3"}):i.jsx(K.ChevronDown,{className:"h-3 w-3"})]})})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[a&&i.jsx("span",{className:A("text-xs opacity-60",T&&"text-xs"),children:ee(e.createdAt)}),s&&!o&&i.jsxs("div",{className:A("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(fe,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Copy,{className:A(L?"text-success":"",T?"h-3 w-3":"h-4 w-4")})}),_==="user"&&C&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:R,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Edit,{className:A(T?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:ae,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.RotateCcw,{className:A(T?"h-3 w-3":"h-4 w-4")})})]})]})]}),i.jsx("div",{className:"relative",children:pe()}),I&&z&&(Y.toolCallId||Y.name)&&i.jsxs("div",{className:A("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",T&&"text-xs"),children:[Y.name&&i.jsxs("div",{children:["Function: ",Y.name]}),Y.toolCallId&&i.jsxs("div",{children:["Call ID: ",Y.toolCallId]})]}),s&&_==="user"&&y&&y.totalBranches>1&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 p-2 bg-muted/30 rounded border",children:[i.jsx(K.GitBranch,{className:"h-3 w-3 text-muted-foreground"}),i.jsxs("span",{className:"text-xs text-muted-foreground",children:["Branch ",y.currentIndex+1," of ",y.totalBranches]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-current",disabled:!y.canGoBack,onClick:()=>x==null?void 0:x(),title:"Go back to previous branch",children:i.jsx(K.ChevronLeft,{className:"h-3 w-3"})}),i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-current",disabled:!y.canGoForward,onClick:()=>E==null?void 0:E(),title:"Go forward to next branch",children:i.jsx(K.ChevronRight,{className:"h-3 w-3"})})]})]}),!(a||c||I)&&s&&!o&&i.jsxs("div",{className:A("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(fe,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Copy,{className:A(L?"text-success":"",T?"h-3 w-3":"h-4 w-4")})}),_==="user"&&C&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:R,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Edit,{className:A(T?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:ae,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.RotateCcw,{className:A(T?"h-3 w-3":"h-4 w-4")})})]})]})})}function Tf(e){const t=e.filter(n=>n.type==="text").map(n=>n.text).join("");return t||JSON.stringify(e)}function Af(e){return e.includes(`
|
|
9
|
+
`)}const tf={messages:[],assemblingId:null,lastCheckpointId:null,toolIndex:{}};function nf(e,t){var n,r;switch(t.type){case"reset":return{messages:js(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,toolIndex:{}};case"seed":return{...e,messages:js(t.payload.messages)};case"user_message":{const o=t.payload.message;if(e.assemblingId){const s=e.messages.findIndex(a=>a.id===e.assemblingId&&a.role==="assistant");if(s>=0){const a=e.messages.slice(0,s),c=e.messages.slice(s);return{...e,messages:[...a,o,...c]}}}return{...e,messages:[...e.messages,o]}}case"event":{const o=t.payload.ev;if(o.type==="message_start"&&o.role==="assistant"){const s=o.id,a=af(o.model),c={id:s,role:"assistant",name:a||void 0,model:o.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,c]}}if(o.type==="token"){const s=e.assemblingId??Dr(e.messages);return s?{...e,messages:rf(e.messages,s,o.content)}:e}if(o.type==="message_delta"){const s=e.assemblingId??Dr(e.messages);return s?{...e,messages:Ks(e.messages,s,o.delta)}:e}if(o.type==="message_end"){const s=e.assemblingId??Dr(e.messages);if(!s)return{...e,assemblingId:null};const a=e.messages,c=a.findIndex(d=>d.id===s&&d.role==="assistant");if(c>=0&&!((r=a[c].content)==null?void 0:r.some(u=>{var p;return(u==null?void 0:u.type)==="text"&&((p=u.text)==null?void 0:p.trim())}))){const u=[...a.slice(0,c),...a.slice(c+1)];return{...e,assemblingId:null,messages:u}}return{...e,assemblingId:null}}if(o.type==="tool_start"){const s=`tool-${o.id}`,a={type:"tool_call",id:o.id,name:o.name,args:o.args},c={id:s,role:"tool",name:o.name,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,c],toolIndex:{...e.toolIndex,[o.id]:s}}}if(o.type==="tool_result"){const s=e.toolIndex[o.id]??`tool-${o.id}`,a={type:"tool_result",toolCallId:o.id,output:o.output,error:o.error},c=e.messages.find(u=>u.id===s),d={id:s,role:"tool",content:[a],createdAt:new Date().toISOString()},f=c?Ks(e.messages,s,[a]):[...e.messages,d];return{...e,messages:f}}if(o.type==="checkpoint"){const s=sf(e.messages,o.checkpointId);return{...e,lastCheckpointId:o.checkpointId,messages:s}}if(o.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${o.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}return e}default:return e}}function Rs(e=[]){const[t,n]=P.useReducer(nf,{...tf,messages:e}),r=P.useCallback(s=>{n({type:"event",payload:{ev:s}})},[]),o=P.useMemo(()=>({reset:s=>n({type:"reset",payload:{messages:s}}),seed:s=>n({type:"seed",payload:{messages:s}}),pushUser:s=>n({type:"user_message",payload:{message:s}}),onEvent:r}),[r]);return{state:t,dispatch:n,...o}}function js(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function Dr(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function rf(e,t,n){return e.map(r=>{if(r.id!==t)return r;const o=r.content.slice(),s=o[o.length-1];return s&&s.type==="text"?s.text+=n:o.push({type:"text",text:n}),{...r,content:o}})}function Ks(e,t,n){return e.map(r=>r.id===t?{...r,content:of(r.content,n)}:r)}function of(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1];(o==null?void 0:o.type)==="text"?o.text+=r.text:n.push({type:"text",text:r.text})}else n.push(r);return n}function sf(e,t){for(let n=e.length-1;n>=0;n--)if(e[n].role==="assistant"){const o={...e[n],checkpointId:t};return[...e.slice(0,n),o,...e.slice(n+1)]}return e}function af(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const Gs=P.createContext(null);function Wt({children:e,apiConfig:t,onError:n,onThreadChange:r,initialThreadId:o=null}){const s=Ye;P.useEffect(()=>{t&&s.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[s,t]);const{isStreaming:a,error:c,stream:d,stop:f,setToken:u}=Vs({baseUrl:s.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/stream"}),[p,m]=P.useState(()=>typeof s.getAuthToken=="function"?s.getAuthToken():null);P.useEffect(()=>{u(typeof s.getAuthToken=="function"?s.getAuthToken():null);const I=s.onTokenChange(k=>{m(k),u(k)});return()=>{I()}},[s,u]);const v=P.useCallback(I=>{s.setAuthToken(I)},[s]),{state:g,seed:h,pushUser:b,onEvent:w,reset:y}=Rs(),[x,E]=P.useState([]),[C,O]=P.useState(null),N=P.useCallback(async()=>{const I=await s.listThreads();E(I)},[s]);P.useEffect(()=>{N().catch(()=>{})},[N]),P.useEffect(()=>{r==null||r(C)},[C,r]);const F=P.useRef(null);P.useEffect(()=>{o&&F.current!==o&&(F.current=o,L(o).catch(()=>{}))},[o]);const M=P.useRef(null),L=P.useCallback(async(I,k,Y)=>{var B;if(M.current!==I){M.current=I;try{const H=k??((B=(await s.listCheckpoints(I)).checkpoints.slice().sort((ce,R)=>new Date(R.createdAt).getTime()-new Date(ce.createdAt).getTime())[0])==null?void 0:B.checkpointId),de=await s.getMessages({threadId:I,checkpointId:H,checkpointNs:Y});O(I),h(de.messages)}finally{M.current=null}}},[s,h]),j=P.useCallback(async I=>s.listCheckpoints(I),[s]),G=P.useCallback(async I=>{if(!C)throw new Error("No active thread");const k=await s.getMessages({threadId:C,checkpointId:I});h(k.messages)},[s,C,h]),V=P.useCallback(async()=>{if(!C)throw new Error("No active thread");await L(C)},[C,L]),z=P.useRef(!1);P.useEffect(()=>{const I=z.current;if(z.current=a,I&&!a&&C){const k=g.lastCheckpointId??void 0;(async()=>{try{const Y=await s.getMessages({threadId:C,checkpointId:k});h(Y.messages)}catch{}try{await N()}catch{}})()}},[a,C,g.lastCheckpointId,s,h,N]);const X=P.useCallback(async I=>{const k=await s.createThread(I);return await N(),await L(k.threadId),k.threadId},[s,N,L]),$=P.useCallback(async I=>{await s.deleteThread(I),await N(),C===I&&(O(null),y([]))},[s,N,C,y]),q=P.useCallback(async(I,k)=>{await s.updateThread(I,k),await N()},[s,N]),T=P.useCallback(async(I,k)=>{var ie;if(!C)throw new Error("No active thread");async function Y(W){return await new Promise((ee,pe)=>{const he=new FileReader;he.onload=()=>ee(String(he.result)),he.onerror=J=>pe(J),he.readAsDataURL(W)})}async function B(W){return await new Promise((ee,pe)=>{const he=new FileReader;he.onload=()=>{try{const J=he.result;let ve="";const re=new Uint8Array(J),ge=re.byteLength;for(let ye=0;ye<ge;ye++)ve+=String.fromCharCode(re[ye]);ee(btoa(ve))}catch(J){pe(J)}},he.onerror=J=>pe(J),he.readAsArrayBuffer(W)})}const H=[];I&&H.push({type:"text",text:I});const de=(k==null?void 0:k.attachments)||[];let ce=[];if(de.length>0)for(const W of de)if(W.type&&W.type.startsWith("image/")){let ee=null;try{const pe=await s.uploadImage(W,(t==null?void 0:t.uploadPath)||"/upload").catch(()=>null);ee=(pe==null?void 0:pe.url)||null}catch{}if(!ee)try{ee=await Y(W)}catch{ee=null}if(ee){const pe={type:"image_url",url:ee,mimeType:W.type,alt:W.name};H.push(pe)}try{ce.push({filename:W.name,data:await B(W),mime_type:W.type||"application/octet-stream"})}catch{}}else{const ee=await Y(W).catch(()=>null),pe={type:"file",url:String(ee),mimeType:W.type||void 0,name:W.name,size:W.size};H.push(pe);try{ce.push({filename:W.name,data:await B(W),mime_type:W.type||"application/octet-stream"})}catch{}}const R={id:((ie=crypto.randomUUID)==null?void 0:ie.call(crypto))||`user-${Date.now()}`,role:"user",content:H,createdAt:new Date().toISOString(),checkpointId:(k==null?void 0:k.checkpointId)??g.lastCheckpointId??void 0};b(R);const ae={...R,content:R.content.filter(W=>W.type==="text"||W.type==="image_url")},le={threadId:C,payload:{messages:[ae],attachments:R.content.filter(W=>W.type==="file").map(W=>({type:"file",url:W.url,mimeType:W.mimeType,name:W.name,size:W.size})),files_info:ce,...(k==null?void 0:k.payloadExtras)??{}},checkpointId:(k==null?void 0:k.checkpointId)??g.lastCheckpointId??void 0,checkpointNs:k==null?void 0:k.checkpointNs,nodeFilter:k==null?void 0:k.nodeFilter,config:k==null?void 0:k.config};d(le,W=>w(W),{onError:W=>console.warn("stream error",W)})},[C,b,d,w,g.lastCheckpointId,s,t==null?void 0:t.uploadPath]),_={baseUrl:s.baseUrl,token:p,setToken:v,api:s,threads:x,currentThreadId:C,setCurrentThreadId:O,messages:g.messages,isStreaming:a,error:c,lastCheckpointId:g.lastCheckpointId,streamingAssistantId:g.assemblingId,refreshThreads:N,createThread:X,deleteThread:$,renameThread:q,loadThread:L,listCheckpoints:j,navigateToCheckpoint:G,returnToLatest:V,send:T,stop:f};return i.jsx(Gs.Provider,{value:_,children:e})}function Lr(){const e=P.useContext(Gs);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function A(...e){return Ad.twMerge(Td.clsx(e))}const cf=Lt.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),fe=l.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const a=r?Pe.Slot:"button";return i.jsx(a,{className:A(cf({variant:t,size:n,className:e})),ref:s,...o})});fe.displayName="Button";const qs=l.forwardRef(({className:e,...t},n)=>i.jsx("textarea",{className:A("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));qs.displayName="Textarea";const lf=Lt.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Xs({className:e,variant:t,...n}){return i.jsx("div",{className:A(lf({variant:t}),e),...n})}function U(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function df(e,t){const n=l.createContext(t),r=s=>{const{children:a,...c}=s,d=l.useMemo(()=>c,Object.values(c));return i.jsx(n.Provider,{value:d,children:a})};r.displayName=e+"Provider";function o(s){const a=l.useContext(n);if(a)return a;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Le(e,t=[]){let n=[];function r(s,a){const c=l.createContext(a),d=n.length;n=[...n,a];const f=p=>{var w;const{scope:m,children:v,...g}=p,h=((w=m==null?void 0:m[e])==null?void 0:w[d])||c,b=l.useMemo(()=>g,Object.values(g));return i.jsx(h.Provider,{value:b,children:v})};f.displayName=s+"Provider";function u(p,m){var h;const v=((h=m==null?void 0:m[e])==null?void 0:h[d])||c,g=l.useContext(v);if(g)return g;if(a!==void 0)return a;throw new Error(`\`${p}\` must be used within \`${s}\``)}return[f,u]}const o=()=>{const s=n.map(a=>l.createContext(a));return function(c){const d=(c==null?void 0:c[e])||s;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:d}}),[c,d])}};return o.scopeName=e,[r,uf(o,...t)]}function uf(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const a=r.reduce((c,{useScope:d,scopeName:f})=>{const p=d(s)[`__scope${f}`];return{...c,...p}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:a}),[a])}};return n.scopeName=t.scopeName,n}var be=globalThis!=null&&globalThis.document?l.useLayoutEffect:()=>{},ff=l[" useInsertionEffect ".trim().toString()]||be;function Qe({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,a]=pf({defaultProp:t,onChange:n}),c=e!==void 0,d=c?e:o;{const u=l.useRef(e!==void 0);l.useEffect(()=>{const p=u.current;p!==c&&console.warn(`${r} is changing from ${p?"controlled":"uncontrolled"} to ${c?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),u.current=c},[c,r])}const f=l.useCallback(u=>{var p;if(c){const m=hf(u)?u(e):u;m!==e&&((p=a.current)==null||p.call(a,m))}else s(u)},[c,e,s,a]);return[d,f]}function pf({defaultProp:e,onChange:t}){const[n,r]=l.useState(e),o=l.useRef(n),s=l.useRef(t);return ff(()=>{s.current=t},[t]),l.useEffect(()=>{var a;o.current!==n&&((a=s.current)==null||a.call(s,n),o.current=n)},[n,o]),[n,r,s]}function hf(e){return typeof e=="function"}function Ys(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Fr(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Ys(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():Ys(e[o],null)}}}}function oe(...e){return l.useCallback(Fr(...e),e)}var gf=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Z=gf.reduce((e,t)=>{const n=Pe.createSlot(`Primitive.${t}`),r=l.forwardRef((o,s)=>{const{asChild:a,...c}=o,d=a?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(d,{...c,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Js(e,t){e&&cn.flushSync(()=>e.dispatchEvent(t))}function mf(e,t){return l.useReducer((n,r)=>t[n][r]??n,e)}var Te=e=>{const{present:t,children:n}=e,r=bf(t),o=typeof n=="function"?n({present:r.isPresent}):l.Children.only(n),s=oe(r.ref,vf(o));return typeof n=="function"||r.isPresent?l.cloneElement(o,{ref:s}):null};Te.displayName="Presence";function bf(e){const[t,n]=l.useState(),r=l.useRef(null),o=l.useRef(e),s=l.useRef("none"),a=e?"mounted":"unmounted",[c,d]=mf(a,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{const f=xn(r.current);s.current=c==="mounted"?f:"none"},[c]),be(()=>{const f=r.current,u=o.current;if(u!==e){const m=s.current,v=xn(f);e?d("MOUNT"):v==="none"||(f==null?void 0:f.display)==="none"?d("UNMOUNT"):d(u&&m!==v?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,d]),be(()=>{if(t){let f;const u=t.ownerDocument.defaultView??window,p=v=>{const h=xn(r.current).includes(CSS.escape(v.animationName));if(v.target===t&&h&&(d("ANIMATION_END"),!o.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",f=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},m=v=>{v.target===t&&(s.current=xn(r.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{u.clearTimeout(f),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:l.useCallback(f=>{r.current=f?getComputedStyle(f):null,n(f)},[])}}function xn(e){return(e==null?void 0:e.animationName)||"none"}function vf(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var wf=l[" useId ".trim().toString()]||(()=>{}),yf=0;function Fe(e){const[t,n]=l.useState(wf());return be(()=>{n(r=>r??String(yf++))},[e]),t?`radix-${t}`:""}var Sn="Collapsible",[xf,_w]=Le(Sn),[Sf,$r]=xf(Sn),Zs=l.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:a,...c}=e,[d,f]=Qe({prop:r,defaultProp:o??!1,onChange:a,caller:Sn});return i.jsx(Sf,{scope:n,disabled:s,contentId:Fe(),open:d,onOpenToggle:l.useCallback(()=>f(u=>!u),[f]),children:i.jsx(Z.div,{"data-state":Ur(d),"data-disabled":s?"":void 0,...c,ref:t})})});Zs.displayName=Sn;var Qs="CollapsibleTrigger",ea=l.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=$r(Qs,n);return i.jsx(Z.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":Ur(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:U(e.onClick,o.onOpenToggle)})});ea.displayName=Qs;var Br="CollapsibleContent",Cf=l.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=$r(Br,e.__scopeCollapsible);return i.jsx(Te,{present:n||o.open,children:({present:s})=>i.jsx(Ef,{...r,ref:t,present:s})})});Cf.displayName=Br;var Ef=l.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,a=$r(Br,n),[c,d]=l.useState(r),f=l.useRef(null),u=oe(t,f),p=l.useRef(0),m=p.current,v=l.useRef(0),g=v.current,h=a.open||c,b=l.useRef(h),w=l.useRef(void 0);return l.useEffect(()=>{const y=requestAnimationFrame(()=>b.current=!1);return()=>cancelAnimationFrame(y)},[]),be(()=>{const y=f.current;if(y){w.current=w.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const x=y.getBoundingClientRect();p.current=x.height,v.current=x.width,b.current||(y.style.transitionDuration=w.current.transitionDuration,y.style.animationName=w.current.animationName),d(r)}},[a.open,r]),i.jsx(Z.div,{"data-state":Ur(a.open),"data-disabled":a.disabled?"":void 0,id:a.contentId,hidden:!h,...s,ref:u,style:{"--radix-collapsible-content-height":m?`${m}px`:void 0,"--radix-collapsible-content-width":g?`${g}px`:void 0,...e.style},children:h&&o})});function Ur(e){return e?"open":"closed"}var Nf=Zs;const ta=Nf,na=ea;function Vt({content:e,className:t=""}){return i.jsx("div",{className:`prose prose-sm max-w-none break-words dark:prose-invert prose-pre:rounded prose-pre:border prose-pre:bg-background/50 prose-code:bg-background/50 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-table:my-4 prose-th:px-2 prose-td:px-2 leading-relaxed ${t}`,children:i.jsx(Pd,{remarkPlugins:[_d],children:e})})}function ra({message:e,messageIndex:t,isStreamingMessage:n=!1,streamingDebounceMs:r=40,isEditing:o=!1,showActions:s=!0,showTimestamp:a=!0,showAgentName:c=!0,layoutSize:d="desktop",truncateToolMessages:f=!0,toolMessagePreviewLength:u=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:v={},checkpointBranches:g=[],currentCheckpointId:h,onSwitchToCheckpoint:b,onReturnToMainThread:w,temporalNavigation:y,onNavigateToPreviousBranch:x,onNavigateToNextBranch:E,onEdit:C,onRegenerate:O,onEditFromCheckpoint:N,onCancelEdit:F,onCopy:M}){const[L,j]=P.useState(!1),[G,V]=P.useState(!1),[z,X]=P.useState(!1),[$,q]=P.useState(!1),T=d==="phone"||d==="half-screen",_=e.role,I=_==="tool",k=P.useMemo(()=>Tf(e.content),[e.content]),Y=P.useMemo(()=>kf(e.content),[e.content]),B=P.useMemo(()=>e.content.filter(J=>J.type==="image_url"),[e.content]),H=P.useMemo(()=>e.content.filter(J=>J.type==="file"),[e.content]),de=Lf(k,n?r:0),ce=async()=>{try{const J=I?yt(e.content):k;await navigator.clipboard.writeText(J),j(!0),setTimeout(()=>j(!1),2e3),M==null||M(J)}catch(J){console.error("Failed to copy:",J)}},R=()=>{if(!C)return;const J=I?yt(e.content):k;C(e.id,J)},ae=()=>O==null?void 0:O(t),le=()=>{const ve=A(T?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0 text-current dark:text-primary-foreground");switch(_){case"user":return i.jsx(K.User,{className:ve});case"assistant":return i.jsx(K.Bot,{className:ve});case"tool":return i.jsx(K.Wrench,{className:ve});default:return i.jsx(K.Bot,{className:ve})}},ie=()=>{const J="group relative mb-4 max-w-full";switch(_){case"user":return A(J,"flex justify-end");case"assistant":case"tool":case"system":return A(J,"flex justify-start");default:return J}},W=()=>{const J=A("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 break-words",T&&"px-3 py-2 text-sm");switch(_){case"user":return A(J,"max-w-[95%]",d==="phone"&&"max-w-[98%]","bg-blue-50 text-gray-900 dark:bg-primary dark:text-primary-foreground","border border-blue-100 dark:border-transparent");case"assistant":return A(J,"max-w-[95%]",d==="phone"&&"max-w-[98%]","bg-white text-gray-900 border border-gray-200 dark:bg-muted dark:text-muted-foreground dark:border-transparent");case"tool":return A(J,"bg-secondary/50 text-secondary-foreground border border-dashed max-w-[95%]",d==="phone"&&"max-w-[98%]");case"system":return A(J,"bg-accent/40 text-muted-foreground max-w-[85%] border");default:return J}},ee=J=>{if(!J)return"";try{return new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},pe=()=>{if(e.model==="reflection"){const re=k.trim(),ge=zr(re);if(ge&&typeof ge=="object")return i.jsx(Ff,{data:ge})}if(I&&Y.name==="get_issues"){const re=e.content.find(D=>D.type==="tool_result"),ge=(re==null?void 0:re.output)??yt(e.content),ye=sa(ge);if(ye)return i.jsx($f,{issues:ye})}if(I&&!z){const re=yt(e.content).slice(0,80).replace(/\s+/g," ");return i.jsx("div",{className:A("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",T&&"text-[10px]"),children:i.jsxs("span",{className:"truncate max-w-full text-current",children:[re,re.length>=80?"…":""]})})}if(I&&f){const re=yt(e.content),ge=re.length>u;return i.jsx(ta,{open:G,onOpenChange:V,children:i.jsxs("div",{className:"font-mono text-sm text-current",children:[i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",T&&"text-xs"),children:ge&&!G?re.substring(0,u)+"...":re}),ge&&i.jsx(na,{asChild:!0,children:i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:G?i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",re.length-u," chars)"]})})})]})})}if(I&&z&&!f){const re=Of(e.content);if(re&&Af(re))return i.jsx(Vt,{content:re.trim()});const ge=yt(e.content);return i.jsx("div",{className:"font-mono text-sm text-current",children:i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",T&&"text-xs"),children:ge})})}const J=B.length>0&&_!=="tool",ve=H.length>0&&_!=="tool";return i.jsxs("div",{children:[n?i.jsxs("div",{className:"relative",children:[(()=>{const re=zr(de);return re!==null?i.jsx(oa,{data:re}):i.jsx(Vt,{content:_f(Pf(de))})})(),i.jsx("span",{className:"inline-block w-[6px] h-[14px] align-baseline ml-0.5 bg-foreground/40 animate-pulse",style:{verticalAlign:"text-bottom"}})]}):(()=>{const re=zr(k.trim());if(re!==null)return i.jsx(oa,{data:re});if(_==="user"&&p){const ge=k.trim();if(ge.length>m)return i.jsxs(ta,{open:$,onOpenChange:q,children:[i.jsx("div",{className:A("text-sm text-gray-900 dark:text-primary-foreground",T&&"text-xs"),children:$?i.jsx(Vt,{content:ge}):i.jsxs("pre",{className:A("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-gray-900 dark:text-primary-foreground",T&&"text-xs"),children:[ge.substring(0,m),"..."]})}),i.jsx(na,{asChild:!0,children:i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-gray-900 dark:!text-primary-foreground",children:$?i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(K.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",ge.length-m," chars)"]})})})]})}return i.jsx(Vt,{content:k.trim()})})(),J&&i.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:B.map((re,ge)=>i.jsxs("div",{className:"relative border rounded overflow-hidden",children:[i.jsx("img",{src:re.url,alt:re.alt??"image",className:"w-full h-auto"}),i.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[i.jsx(K.Image,{className:"h-3 w-3"}),i.jsx("span",{children:"image"})]})]},ge))}),ve&&i.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:H.map((re,ge)=>{const ye=re,D=ye.name||"file";return i.jsxs("a",{href:ye.url,download:D,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 bg-gray-100 border border-gray-200 rounded px-2 py-1 text-xs hover:bg-gray-200",title:D,children:[i.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-gray-400"}),i.jsx("span",{className:"truncate max-w-[180px]",children:D})]},ge)})})]})},he=P.useMemo(()=>Mf(e),[e]);return P.useMemo(()=>Df(e,h),[e,h]),i.jsx("div",{className:A(ie(),v.container),children:i.jsxs("div",{className:A(W(),v.content),children:[(a||c||I)&&i.jsxs("div",{className:A("flex items-center justify-between mb-2 pb-2 border-b border-current/10",T&&"mb-1 pb-1",v.header),children:[i.jsxs("div",{className:"flex items-center gap-2",children:[le(),c&&he&&i.jsx("span",{className:A("font-medium",T?"text-xs":"text-sm"),children:he}),I&&Y.name&&i.jsxs(Xs,{variant:"outline",className:A("text-xs flex items-center gap-1 cursor-pointer text-current",T&&"text-xs h-4"),onClick:()=>X(J=>!J),children:[i.jsx("span",{children:Y.name}),i.jsx("span",{className:"inline-flex items-center",children:z?i.jsx(K.ChevronUp,{className:"h-3 w-3"}):i.jsx(K.ChevronDown,{className:"h-3 w-3"})})]}),I&&!Y.name&&i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 px-1 text-current",onClick:()=>X(J=>!J),children:i.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",z?i.jsx(K.ChevronUp,{className:"h-3 w-3"}):i.jsx(K.ChevronDown,{className:"h-3 w-3"})]})})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[a&&i.jsx("span",{className:A("text-xs opacity-60",T&&"text-xs"),children:ee(e.createdAt)}),s&&!o&&i.jsxs("div",{className:A("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(fe,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Copy,{className:A(L?"text-success":"text-current",T?"h-3 w-3":"h-4 w-4")})}),_==="user"&&C&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:R,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Edit,{className:A("text-current",T?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:ae,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.RotateCcw,{className:A("text-current",T?"h-3 w-3":"h-4 w-4")})})]})]})]}),i.jsx("div",{className:"relative",children:pe()}),I&&z&&(Y.toolCallId||Y.name)&&i.jsxs("div",{className:A("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",T&&"text-xs"),children:[Y.name&&i.jsxs("div",{children:["Function: ",Y.name]}),Y.toolCallId&&i.jsxs("div",{children:["Call ID: ",Y.toolCallId]})]}),s&&_==="user"&&y&&y.totalBranches>1&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 p-2 bg-muted/30 rounded border",children:[i.jsx(K.GitBranch,{className:"h-3 w-3 text-muted-foreground"}),i.jsxs("span",{className:"text-xs text-muted-foreground",children:["Branch ",y.currentIndex+1," of ",y.totalBranches]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-current",disabled:!y.canGoBack,onClick:()=>x==null?void 0:x(),title:"Go back to previous branch",children:i.jsx(K.ChevronLeft,{className:"h-3 w-3 text-current"})}),i.jsx(fe,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-current",disabled:!y.canGoForward,onClick:()=>E==null?void 0:E(),title:"Go forward to next branch",children:i.jsx(K.ChevronRight,{className:"h-3 w-3 text-current"})})]})]}),!(a||c||I)&&s&&!o&&i.jsxs("div",{className:A("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(fe,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Copy,{className:A(L?"text-success":"text-current",T?"h-3 w-3":"h-4 w-4")})}),_==="user"&&C&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:R,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.Edit,{className:A("text-current",T?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(fe,{variant:"ghost",size:"sm",onClick:ae,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",T&&"h-5 w-5"),children:i.jsx(K.RotateCcw,{className:A("text-current",T?"h-3 w-3":"h-4 w-4")})})]})]})})}function Tf(e){const t=e.filter(n=>n.type==="text").map(n=>n.text).join("");return t||JSON.stringify(e)}function Af(e){return e.includes(`
|
|
10
10
|
`)||e.includes("```")||/[-*] /.test(e)||/#+\s/.test(e)}function Pf(e){let t=e;try{(t.match(/```/g)||[]).length%2===1&&(t+="\n```"),(t.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(t+="`")}catch{}return t}function _f(e){let t=e;try{const n=[],r=[],o="\0F",s="\0I";let a=t.replace(/```[\s\S]*?```/g,c=>(n.push(c),`${o}${n.length-1}\0`));a=a.replace(/`[^`]*`/g,c=>(r.push(c),`${s}${r.length-1}\0`)),a=a.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),a=a.replace(/\u0000F(\d+)\u0000/g,(c,d)=>n[Number(d)]??""),a=a.replace(/\u0000I(\d+)\u0000/g,(c,d)=>r[Number(d)]??""),t=a}catch{}return t}function zr(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function oa({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?i.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:i.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>i.jsx("li",{children:String(n)},r))})}):i.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 overflow-x-auto whitespace-pre-wrap break-words",children:Rt(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return i.jsxs("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:[typeof r=="boolean"&&i.jsxs("p",{children:[i.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&i.jsxs("div",{children:[i.jsx("p",{children:i.jsx("strong",{children:"Follow-up queries:"})}),i.jsx("ul",{className:"list-disc pl-5",children:n.map((s,a)=>i.jsx("li",{children:String(s)},a))})]}),t&&t.length>0&&i.jsxs("div",{children:[i.jsx("p",{children:i.jsx("strong",{children:"Facts:"})}),i.jsx("ul",{className:"list-disc pl-5",children:t.map((s,a)=>i.jsx("li",{children:String(s)},a))})]})]});const o=Object.entries(e);return i.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:i.jsx("dl",{className:"mt-0",children:o.map(([s,a])=>i.jsxs("div",{className:"mb-1",children:[i.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),i.jsx("dd",{className:"inline",children:If(a)})]},s))})})}return i.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 overflow-x-auto whitespace-pre-wrap break-words",children:Rt(e)})}function If(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return i.jsx("code",{className:"text-xs",children:JSON.stringify(e)})}catch{return String(e)}}function yt(e){const t=e.filter(n=>n.type==="tool_result");if(t.length)try{return t.length===1?Rt(t[0].output):Rt(t.map(n=>({toolCallId:n.toolCallId,output:n.output})))}catch{}return Rt(e)}function Of(e){const t=e.find(r=>r.type==="tool_result");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function Rt(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function kf(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_result");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Mf(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function Df(e,t){return e.checkpointId||t||null}function Lf(e,t){const[n,r]=P.useState(e);return P.useEffect(()=>{if(!t){r(e);return}const o=setTimeout(()=>r(e),t);return()=>clearTimeout(o)},[e,t]),n}function Ff({data:e}){return i.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>i.jsxs("div",{className:"flex",children:[i.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),i.jsx("dd",{className:"flex-1",children:Array.isArray(n)?n.map((r,o)=>i.jsxs("div",{className:"ml-4",children:["- ",String(r)]},o)):String(n)})]},t))})}function sa(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return sa(e.output)}const t=String(e),n={desirability:[],feasibility:[],viability:[],other:[]};let r=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(a=>{const c=r.toLowerCase().indexOf(a);return c===-1?Number.MAX_SAFE_INTEGER:c}));o!==Number.MAX_SAFE_INTEGER&&(r=r.slice(o));for(const a of Object.keys(n)){const d=new RegExp(a+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!d)continue;const f=d[1],u=/Issue\(([\s\S]*?)\)(?:,|$)/g;let p=null;for(;(p=u.exec(f))!==null;){const m=p[1],v=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(m),g=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(m),h=v?v[2].trim():"",b=g?g[2].trim():"";n[a].push({title:h,description:b})}}return Object.values(n).some(a=>a.length>0)?n:null}function $f({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return i.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),i.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>i.jsxs("li",{children:[i.jsx("div",{className:"font-medium",children:o.title}),i.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const xt=1e4;function Bf(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
11
11
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
12
12
|
|
package/package.json
CHANGED