efficient-shell 12.25.0 → 12.27.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/{Browser-XIJNQPN5.js → Browser-6YRO47YI.js} +12 -12
- package/dist/{Files-3USUXZM2.js → Files-K7H7WHRS.js} +141 -141
- package/dist/{Notepad-MXANPUG3.js → Notepad-EHISTRGJ.js} +7 -7
- package/dist/{Preview-UVQVZYR7.js → Preview-L4RT7TBC.js} +18 -18
- package/dist/ai/index.d.ts +17 -2
- package/dist/ai/index.js +116 -115
- package/dist/ai.css +1 -1
- package/dist/apps/index.js +1 -1
- package/dist/bin/media-host-check.js +1 -1
- package/dist/bin/ui-check.js +1 -1
- package/dist/brand.css +1 -1
- package/dist/chunk-24Y5JHIR.js +4 -0
- package/dist/{chunk-7MJYT6IW.js → chunk-676TKVDM.js} +1 -1
- package/dist/{chunk-JVOH7776.js → chunk-DMEP2SCP.js} +1 -1
- package/dist/{chunk-WVMCKM5Z.js → chunk-FD6DJRD4.js} +1 -1
- package/dist/chunk-INADSWOF.js +28 -0
- package/dist/{chunk-NPTF6MP4.js → chunk-KZHVKSNF.js} +1 -1
- package/dist/{chunk-GBTL3G36.js → chunk-NUPK6CUV.js} +1 -1
- package/dist/{chunk-OG53D3R5.js → chunk-PLPMCE44.js} +4 -4
- package/dist/chunk-VABHQDN5.js +1 -0
- package/dist/forms/MediaLibrary.js +1 -1
- package/dist/forms/MediaUploadGrid.d.ts +3 -2
- package/dist/forms/MediaUploadGrid.js +1 -1
- package/dist/index.js +101 -101
- package/dist/shell/Avatar.js +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/templates/ChatTemplate.js +1 -1
- package/dist/templates/DashboardTemplate.js +1 -1
- package/dist/templates/EmailTemplate.js +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7NYCPO54.js +0 -1
- package/dist/chunk-EC3P3W7Z.js +0 -28
- package/dist/chunk-LDVDNAXP.js +0 -4
package/dist/ai/index.js
CHANGED
|
@@ -1,116 +1,117 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{StepChainItem as e,StepChain as t}from"../chunk-R62JKPYY.js";import{Markdown as n}from"../chunk-LPPJNZQ6.js";import{Divider as a}from"../chunk-DFOFEBYX.js";import{Avatar as r}from"../chunk-LDVDNAXP.js";import"../chunk-UJUTS6LJ.js";import"../chunk-Z5TE3MEG.js";import{useContextMenu as s,ContextMenu as o}from"../chunk-6FZ5JTBY.js";import{Banner as i}from"../chunk-N3R6N7LG.js";import{AttachmentDropZone as l}from"../chunk-Z3CTYK3U.js";import{Input_default as c}from"../chunk-6RK6R3RY.js";import"../chunk-SFULX4E3.js";import"../chunk-FTMCNC66.js";import{IconButton_default as d}from"../chunk-SV5RRBVA.js";import"../chunk-AYZY3YNC.js";import{CloseGlyph as p}from"../chunk-VLMBXPRM.js";import"../chunk-FJVZ2W55.js";import{useFileIntake as u,humanSize as m,FileIntakeAlert as h}from"../chunk-V4XR4MOS.js";import{parseChartSpec as f}from"../chunk-CR7T435F.js";import{SpecChart as g}from"../chunk-EEB5XPWP.js";import{formatBytes as x}from"../chunk-GEYM4WN3.js";import{formatTime as v}from"../chunk-Y3JW2GW5.js";import"../chunk-36BRD5J3.js";import"../chunk-LF27WIN2.js";import"../chunk-XQWHKXLS.js";import{FlowChart as b}from"../chunk-DCCYUCBM.js";import{parseFlowSpec as y}from"../chunk-FAERBT6Y.js";import"../chunk-TU2L7NW3.js";import"../chunk-CK2YOGUS.js";import"../chunk-RBS3AWE7.js";import"../chunk-VFC6QUEN.js";import"../chunk-GC4N4UQM.js";import"../chunk-465RRWBY.js";import{ChartSkeleton as w}from"../chunk-WXZZGHET.js";import"../chunk-CNYAHYE6.js";import"../chunk-DWGYC7OD.js";import"../chunk-JMGDGNM7.js";import"../chunk-THLXDI76.js";import"../chunk-URHGHXDN.js";import"../chunk-5QFPTDQF.js";import{Button_default as k}from"../chunk-EVYD6UFQ.js";import"../chunk-M5K4AX4E.js";import{Icon as N}from"../chunk-XZXFUZIK.js";import"../chunk-J75ZT2JQ.js";import{SpinnerRing as A}from"../chunk-R2VKEMZH.js";import"../chunk-G67CJAQ2.js";import"../chunk-SOZCWT6I.js";import"../chunk-PGN5ME7B.js";import"../chunk-62LW225J.js";import"../chunk-GLUJS42B.js";import"../chunk-D65T4H6J.js";import"../chunk-UQYNPYF4.js";import"../chunk-MRJKZWWV.js";import"../chunk-ENFXDIIZ.js";import"../chunk-2DYVVHZA.js";import"../chunk-MAFUXCPZ.js";import"../chunk-2JWPNR2U.js";import"../chunk-WDQI3FV6.js";import"../chunk-TZFACUMR.js";import"../chunk-TWVUQUUD.js";import"../chunk-5FYDNH4Y.js";import"../chunk-LNXBTK7Q.js";import{useShellStrings as C}from"../chunk-JSHMIMAJ.js";import"../chunk-C3QOHMR6.js";import{useRef as T,Fragment as j,useState as S,useEffect as O,useId as _,useCallback as $,useMemo as R}from"react";import{isToolUIPart as D,getToolName as I,DefaultChatTransport as F,lastAssistantMessageIsCompleteWithApprovalResponses as M}from"ai";import{jsx as L,jsxs as z,Fragment as P}from"react/jsx-runtime";import{useChat as B}from"@ai-sdk/react";function E(e){if(!D(e))return null;const t=e;return{toolName:I(e),toolCallId:t.toolCallId,state:t.state,input:t.input,output:t.output,errorText:t.errorText,approvalId:t.approval?.id,approved:t.approval?.approved}}function U(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-tool-summary"!==n.type)continue;const e=n.data;e&&"string"==typeof e.tool_call_id&&Array.isArray(e.rows)&&e.rows.length>0&&t.set(e.tool_call_id,e)}return t}function W(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-file"!==n.type)continue;const e=n.data;e&&"string"==typeof e.id&&"string"==typeof e.filename&&t.set(e.id,e)}return[...t.values()]}function q(e){return e.parts.map(e=>"text"===e.type?e.text:"").join("")}var Y="efficient-attachment:";function H(e){return{type:"file",mediaType:e.content_type,filename:e.filename,url:`${Y}${e.id}`,providerMetadata:{efficient:{size:e.size}}}}function Q(e){const t=[];for(const n of e.parts){if("file"!==n.type||!n.url.startsWith(Y))continue;const e=n.providerMetadata?.efficient?.size;t.push({id:n.url.slice(21),filename:n.filename??"",content_type:n.mediaType,size:"number"==typeof e?e:0})}return t}var J=/* @__PURE__ */new Set(["data-conversation","data-plan","data-followups","data-choices","data-tool-summary","data-error","data-file","data-approval","data-busy"]);function Z(e,t){const n=e[e.length-1];if(!n)throw new Error("assistant chat: no message to send");if("user"===n.role){const e=q(n).trim();if(!e)throw new Error("assistant chat: empty message");const a=Q(n).map(e=>e.id),r=n.metadata?.replyTo?.id;return{conversation_id:t,text:e,approvals:[],...a.length>0?{attachments:a}:{},...r?{reply_to:r}:{}}}const a=function(e){const t=[];for(const n of e.parts){if(!D(n))continue;const e=n;if("approval-responded"!==e.state||!e.approval||"boolean"!=typeof e.approval.approved)continue;const a={approval_id:e.approval.id,approved:e.approval.approved};e.approval.reason&&(a.reason=e.approval.reason),t.push(a)}return t}(n);if(0===a.length)throw new Error("assistant chat: no approval decision to send");return{conversation_id:t,text:null,approvals:a}}var G=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function X(e,t,n=""){const a=[t.trim(),n.trim()].filter(Boolean).map(G);return 0!==a.length&&new RegExp(`(^|[^\\p{L}\\p{N}_@])(?:${a.join("|")})(?![\\p{L}\\p{N}_@])`,"iu").test(e)}function V(e,t){const n=t.trim();if(!n||!e)return e?[{text:e,mention:!1}]:[];const a=[];let r=0;const s=new RegExp(`(^|[^\\p{L}\\p{N}_@])(${G(n)})(?![\\p{L}\\p{N}_@])`,"giu");for(const t of e.matchAll(s)){const n=(t.index??0)+t[1].length;n>r&&a.push({text:e.slice(r,n),mention:!1}),a.push({text:t[2],mention:!0}),r=n+t[2].length}return r<e.length&&a.push({text:e.slice(r),mention:!1}),a}function K(e,t){return X(e,t)?e:`${t.trim()} ${e.trimStart()}`}function ee(e){const t=e.map(e=>e.name).filter(Boolean);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}var te=/* @__PURE__ */new Set(["proposed","approved","running"]);function ne(e){return te.has(e.status)}function ae(e){const t=[];for(const n of e.parts)"data-plan"===n.type&&t.push(n.data);return t}function re(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of ae(n))t.delete(e.id),t.set(e.id,e);return t}function se(e){const t=[...re(e).values()],n=t[t.length-1];if(!n)return null;if(ne(n))return n;const a=e[e.length-1];return a&&"assistant"===a.role&&ae(a).some(e=>e.id===n.id)?n:null}function oe(e){const t={};return e.source&&e.source!==e.role&&(t.source=e.source),e.author&&(t.author=e.author),e.asked_by&&(t.askedBy=e.asked_by),e.created_at&&(t.createdAt=e.created_at),e.reply_to&&(t.replyTo=e.reply_to),"assistant"===e.role&&e.run_id&&(t.run_id=e.run_id,t.rating=e.rating??null),Object.keys(t).length>0?{metadata:t}:{}}function ie(e,t){const n=/* @__PURE__ */new Map;for(const a of e.parts){if("data-approval"!==a.type)continue;const e=a.data,r=e?.[t];"string"==typeof e?.approval_id&&"string"==typeof r&&r&&n.set(e.approval_id,r)}return n}function le(e){const t=e.messages.filter(e=>e.text).map(e=>({id:e.id,role:e.role,parts:[...(e.attachments??[]).map(H),{type:"text",text:e.text},...(e.files??[]).map(e=>({type:"data-file",id:`file-${e.id}`,data:e}))],...oe(e)})),n=(e.plans??[]).filter(ne);return(e.pending_approvals.length>0||n.length>0)&&t.push({id:`pending-approvals-${e.id}`,role:"assistant",parts:[...n.map(e=>({type:"data-plan",id:e.id,data:e})),...e.pending_approvals.map(e=>({type:`tool-${e.tool_name}`,toolCallId:e.tool_call_id??e.approval_id,state:"approval-requested",input:e.input,approval:{id:e.approval_id}})),...e.pending_approvals.filter(e=>e.expires_at||e.notice).map(e=>({type:"data-approval",id:e.approval_id,data:{approval_id:e.approval_id,expires_at:e.expires_at,...e.notice?{notice:e.notice}:{}}}))]}),t}function ce(e,t){const n=e?.message?.trim();if(!n)return t;if(n.startsWith("{")){try{const e=JSON.parse(n);for(const t of["detail","errorText","message","title","error"]){const n=e[t];if("string"==typeof n&&n.trim())return n.trim()}for(const t of Object.values(e)){const e=Array.isArray(t)?t[0]:void 0;if("string"==typeof e&&e.trim()&&e.length<=400)return e.trim()}}catch{return t}return t}return n.startsWith("<")||n.length>400?t:n}var de=/^(load failed|failed to fetch|network ?error( when attempting to fetch resource)?|(the )?network connection was lost|error in input stream|terminated)\.?$/i;function pe(e){return!(!e||"AbortError"===e.name)&&de.test(e.message?.trim()??"")}var ue=/* @__PURE__ */new Set(["budget_reached","not_permitted"]);function me(e,t,n){return pe(e)?{text:n.connectionDropped,retryable:!0}:{text:ce(e,n.genericError),retryable:!(t&&ue.has(t))}}function he(e){const t=e[e.length-1];if(!t)return!1;if("user"===t.role)return""!==q(t).trim();const n=e[e.length-2];return!(!n||"user"!==n.role||!q(n).trim())&&!t.parts.some(e=>void 0!==E(e)?.approvalId)}var fe={title:"Assistant",placeholder:"Ask a question…",inputLabel:"Message to the assistant",send:"Send",stop:"Stop",newChat:"New chat",open:"Open assistant",close:"Close assistant",thinking:"Thinking",loadingHistory:"Loading the conversation",historyFailed:"The earlier conversation could not be loaded.",emptyState:"Ask me anything to get started.",approvalNeeded:"Approval needed",approve:"Approve",deny:"Deny",approvalExpired:"This request expired. Ask again if you still want it done.",approved:"Approved",declined:"Declined",toolFailed:"did not complete",toolDeclined:"was not approved",details:"Details",stepSources:"Where these figures came from",reasoning:"Reasoning",genericError:"Something went wrong. Please try again.",connectionDropped:"The connection dropped. Your question may still be answering; reopen the chat in a moment.",retry:"Retry",working:"Working",steps:"Steps",teamName:"Team",teamJoined:"A team member has joined",plan:"Plan",planSummary:"Plan: {done} of {total} done",planProposed:"waiting for your approval",planApproved:"approved, starting",planRunning:"in progress",planCompleted:"finished",planFailed:"stopped — not every step ran",planDenied:"not approved — nothing was changed",planExpired:"expired — nothing was changed",planApprovalHeading:"Approve this plan of {count} steps",approvePlan:"Approve plan",replyStats:"{tokens} tokens · {seconds} s · {rate} tok/s",replyTokens:"{tokens} tokens",streaming:"Streaming",streamingRate:"Streaming · ~{rate} tok/s",followups:"Suggested follow-up questions",choices:"Answers to choose from",attach:"Attach a file",attaching:"Uploading",removeAttachment:"Remove {name}",openAttachment:"Open {name}",copyAnswer:"Copy",copied:"Copied",readOnly:"You can read this chat but not continue it.",rateAnswer:"Rate this answer",rateUp:"Helpful",rateDown:"Not helpful",rateNote:"What was wrong? (optional)",rateNoteSend:"Send",rateNoteSkip:"Skip",rateThanks:"Thanks for telling us.",rateFailed:"Your rating could not be saved.",openFile:"Open {name}",thinkingWords:["Thinking","Working it out","Checking"],waitingSeconds:"{seconds}s",notReplied:"The assistant didn’t reply. It took this as for the people.",askToReply:"Ask the assistant to reply",askToReplyText:"please reply to that.",flowDownloadPng:"Download PNG",flowDownloadSvg:"Download SVG",flowToPdf:"Add to the PDF",flowToPdfText:"Put that flowchart in a PDF.",detailsPanel:"Details",detailsChat:"Chat",detailsUsage:"Usage",detailsFiles:"Files",detailsTools:"Tools used",detailsAnswers:"{count} answers",detailsOneAnswer:"1 answer",detailsTokensIn:"Tokens in",detailsTokensOut:"Tokens out",detailsSpeed:"Average speed",detailsRate:"{rate} tok/s",detailsUsagePartial:"Counts the answers written while this window was open.",detailsYou:"You",detailsNoFiles:"No files yet.",detailsNoTools:"No tools used yet.",assistantMention:"@Assistant",assistantName:"",toPeople:"To {names} only. The assistant won’t reply.",toAssistant:"The assistant will reply. Everyone in the chat sees it.",assistantDecides:"The assistant replies if this is for it. Name it to be sure.",deciding:"The assistant is reading your message",askAssistant:"Ask the assistant",peopleOnly:"People only",letAssistantDecide:"Let the assistant decide",peoplePlaceholder:"Message {names}, or type {mention} to ask",askedBy:"Asked by {name}",sayFailed:"Your message didn’t send. Try again.",you:"You",quote:"Quote",moreActions:"More actions",replyingTo:"Replying to {name}",clearQuote:"Remove quote"},ge=140;function xe(e){const t=(n=e,n.replace(/```[\s\S]*?(```|$)/g," ").replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-*+]\s+|\d+[.)]\s+)/gm,"").replace(/!?\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/(\*\*|\*|`|~~)(?=\S)([^\n]*?\S)\1/g,"$2").replace(/\|/g," ")).replace(/\s+/g," ").trim();var n;if(t.length<=ge)return t;const a=t.slice(0,ge),r=a.lastIndexOf(" ");return`${(r>70?a.slice(0,r):a).trimEnd()}…`}function ve(e){const t=e.trim().split(/\s+/).filter(Boolean);if(0===t.length)return"?";return`${Array.from(t[0])[0]??""}${t.length>1?Array.from(t[t.length-1])[0]??"":""}`.toUpperCase()}function be({name:e,assistant:t,avatarUrl:n}){/* @__PURE__ */
|
|
3
|
-
return
|
|
4
|
-
return
|
|
5
|
-
/* @__PURE__ */
|
|
6
|
-
return
|
|
7
|
-
return
|
|
8
|
-
/* @__PURE__ */
|
|
9
|
-
/* @__PURE__ */
|
|
10
|
-
/* @__PURE__ */
|
|
11
|
-
/* @__PURE__ */z(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/* @__PURE__ */z("
|
|
15
|
-
/* @__PURE__ */L("div",{className:"min-w-0
|
|
16
|
-
/* @__PURE__ */L(
|
|
17
|
-
/* @__PURE__ */z(
|
|
18
|
-
/* @__PURE__ */
|
|
19
|
-
/* @__PURE__ */L("
|
|
20
|
-
/* @__PURE__ */z("
|
|
21
|
-
/* @__PURE__ */L("div",{className:"min-w-0
|
|
22
|
-
|
|
23
|
-
return z("
|
|
24
|
-
|
|
25
|
-
/* @__PURE__ */
|
|
26
|
-
/* @__PURE__ */
|
|
27
|
-
/* @__PURE__ */
|
|
28
|
-
/* @__PURE__ */
|
|
29
|
-
/* @__PURE__ */
|
|
30
|
-
/* @__PURE__ */
|
|
31
|
-
/* @__PURE__ */
|
|
32
|
-
/* @__PURE__ */
|
|
33
|
-
/* @__PURE__ */z(
|
|
34
|
-
/* @__PURE__ */L("
|
|
35
|
-
/* @__PURE__ */
|
|
36
|
-
/* @__PURE__ */
|
|
37
|
-
/* @__PURE__ */
|
|
38
|
-
/* @__PURE__ */z(
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
/* @__PURE__ */L("
|
|
42
|
-
/* @__PURE__ */
|
|
43
|
-
/* @__PURE__ */
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/* @__PURE__ */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/* @__PURE__ */
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
/* @__PURE__ */L(
|
|
53
|
-
/* @__PURE__ */
|
|
54
|
-
/* @__PURE__ */z(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/* @__PURE__ */
|
|
58
|
-
/* @__PURE__ */
|
|
59
|
-
/* @__PURE__ */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
/* @__PURE__ */
|
|
63
|
-
/* @__PURE__ */
|
|
64
|
-
/* @__PURE__ */
|
|
65
|
-
/* @__PURE__ */
|
|
66
|
-
/* @__PURE__ */z("
|
|
67
|
-
|
|
68
|
-
return z("
|
|
69
|
-
|
|
70
|
-
/* @__PURE__ */
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
/* @__PURE__ */
|
|
75
|
-
/* @__PURE__ */
|
|
76
|
-
return
|
|
77
|
-
return z(
|
|
78
|
-
|
|
79
|
-
/* @__PURE__ */L("div",{className:"
|
|
80
|
-
/* @__PURE__ */
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
/* @__PURE__ */
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/* @__PURE__ */L("span",{className:"
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/* @__PURE__ */
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
/* @__PURE__ */
|
|
97
|
-
/* @__PURE__ */
|
|
98
|
-
/* @__PURE__ */
|
|
99
|
-
/* @__PURE__ */
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
-
/* @__PURE__ */
|
|
103
|
-
|
|
104
|
-
return z("div",
|
|
105
|
-
|
|
106
|
-
/* @__PURE__ */
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/* @__PURE__ */
|
|
110
|
-
/* @__PURE__ */
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
/* @__PURE__ */z("
|
|
113
|
-
/* @__PURE__ */
|
|
114
|
-
/* @__PURE__ */L(
|
|
115
|
-
/* @__PURE__ */
|
|
116
|
-
|
|
2
|
+
import{StepChainItem as e,StepChain as t}from"../chunk-R62JKPYY.js";import{Markdown as n}from"../chunk-LPPJNZQ6.js";import{Divider as a}from"../chunk-DFOFEBYX.js";import{Avatar as r}from"../chunk-24Y5JHIR.js";import"../chunk-UJUTS6LJ.js";import"../chunk-Z5TE3MEG.js";import{useContextMenu as s,ContextMenu as o}from"../chunk-6FZ5JTBY.js";import{Banner as i}from"../chunk-N3R6N7LG.js";import{AttachmentDropZone as l}from"../chunk-Z3CTYK3U.js";import{Input_default as c}from"../chunk-6RK6R3RY.js";import"../chunk-SFULX4E3.js";import"../chunk-FTMCNC66.js";import{IconButton_default as d}from"../chunk-SV5RRBVA.js";import"../chunk-AYZY3YNC.js";import{CloseGlyph as p}from"../chunk-VLMBXPRM.js";import"../chunk-FJVZ2W55.js";import{useFileIntake as u,humanSize as m,FileIntakeAlert as h}from"../chunk-V4XR4MOS.js";import{parseChartSpec as f}from"../chunk-CR7T435F.js";import{SpecChart as g}from"../chunk-EEB5XPWP.js";import{formatBytes as x}from"../chunk-GEYM4WN3.js";import{formatTime as v}from"../chunk-Y3JW2GW5.js";import"../chunk-36BRD5J3.js";import"../chunk-LF27WIN2.js";import"../chunk-XQWHKXLS.js";import{FlowChart as b}from"../chunk-DCCYUCBM.js";import{parseFlowSpec as y}from"../chunk-FAERBT6Y.js";import"../chunk-TU2L7NW3.js";import"../chunk-CK2YOGUS.js";import"../chunk-RBS3AWE7.js";import"../chunk-VFC6QUEN.js";import"../chunk-GC4N4UQM.js";import"../chunk-465RRWBY.js";import{ChartSkeleton as w}from"../chunk-WXZZGHET.js";import"../chunk-CNYAHYE6.js";import"../chunk-DWGYC7OD.js";import"../chunk-JMGDGNM7.js";import"../chunk-THLXDI76.js";import"../chunk-URHGHXDN.js";import"../chunk-5QFPTDQF.js";import{Button_default as k}from"../chunk-EVYD6UFQ.js";import"../chunk-M5K4AX4E.js";import{Icon as N}from"../chunk-XZXFUZIK.js";import"../chunk-J75ZT2JQ.js";import{SpinnerRing as A}from"../chunk-R2VKEMZH.js";import"../chunk-G67CJAQ2.js";import"../chunk-SOZCWT6I.js";import"../chunk-PGN5ME7B.js";import"../chunk-62LW225J.js";import"../chunk-GLUJS42B.js";import"../chunk-D65T4H6J.js";import"../chunk-UQYNPYF4.js";import"../chunk-MRJKZWWV.js";import"../chunk-ENFXDIIZ.js";import"../chunk-2DYVVHZA.js";import"../chunk-MAFUXCPZ.js";import"../chunk-2JWPNR2U.js";import"../chunk-WDQI3FV6.js";import"../chunk-TZFACUMR.js";import"../chunk-TWVUQUUD.js";import"../chunk-5FYDNH4Y.js";import"../chunk-LNXBTK7Q.js";import{useShellStrings as C}from"../chunk-JSHMIMAJ.js";import"../chunk-C3QOHMR6.js";import{useRef as T,Fragment as S,useState as j,useEffect as O,useId as _,useCallback as R,useMemo as $}from"react";import{isToolUIPart as I,getToolName as D,DefaultChatTransport as F,lastAssistantMessageIsCompleteWithApprovalResponses as M}from"ai";import{jsx as z,jsxs as L,Fragment as P}from"react/jsx-runtime";import{useChat as B}from"@ai-sdk/react";function E(e){if(!I(e))return null;const t=e;return{toolName:D(e),toolCallId:t.toolCallId,state:t.state,input:t.input,output:t.output,errorText:t.errorText,approvalId:t.approval?.id,approved:t.approval?.approved}}function U(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-tool-summary"!==n.type)continue;const e=n.data;e&&"string"==typeof e.tool_call_id&&Array.isArray(e.rows)&&e.rows.length>0&&t.set(e.tool_call_id,e)}return t}function W(e){const t=/* @__PURE__ */new Map;for(const n of e.parts){if("data-file"!==n.type)continue;const e=n.data;e&&"string"==typeof e.id&&"string"==typeof e.filename&&t.set(e.id,e)}return[...t.values()]}function q(e){return e.parts.map(e=>"text"===e.type?e.text:"").join("")}var Y="efficient-attachment:";function H(e){return{type:"file",mediaType:e.content_type,filename:e.filename,url:`${Y}${e.id}`,providerMetadata:{efficient:{size:e.size}}}}function Q(e){const t=[];for(const n of e.parts){if("file"!==n.type||!n.url.startsWith(Y))continue;const e=n.providerMetadata?.efficient?.size;t.push({id:n.url.slice(21),filename:n.filename??"",content_type:n.mediaType,size:"number"==typeof e?e:0})}return t}var J=/* @__PURE__ */new Set(["data-conversation","data-plan","data-followups","data-choices","data-tool-summary","data-error","data-file","data-approval","data-busy"]);function Z(e,t){const n=e[e.length-1];if(!n)throw new Error("assistant chat: no message to send");if("user"===n.role){const e=q(n).trim();if(!e)throw new Error("assistant chat: empty message");const a=Q(n).map(e=>e.id),r=n.metadata?.replyTo?.id;return{conversation_id:t,text:e,approvals:[],...a.length>0?{attachments:a}:{},...r?{reply_to:r}:{}}}const a=function(e){const t=[];for(const n of e.parts){if(!I(n))continue;const e=n;if("approval-responded"!==e.state||!e.approval||"boolean"!=typeof e.approval.approved)continue;const a={approval_id:e.approval.id,approved:e.approval.approved};e.approval.reason&&(a.reason=e.approval.reason),t.push(a)}return t}(n);if(0===a.length)throw new Error("assistant chat: no approval decision to send");return{conversation_id:t,text:null,approvals:a}}var G=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function X(e,t,n=""){const a=[t.trim(),n.trim()].filter(Boolean).map(G);return 0!==a.length&&new RegExp(`(^|[^\\p{L}\\p{N}_@])(?:${a.join("|")})(?![\\p{L}\\p{N}_@])`,"iu").test(e)}function V(e,t){const n=t.trim();if(!n||!e)return e?[{text:e,mention:!1}]:[];const a=[];let r=0;const s=new RegExp(`(^|[^\\p{L}\\p{N}_@])(${G(n)})(?![\\p{L}\\p{N}_@])`,"giu");for(const t of e.matchAll(s)){const n=(t.index??0)+t[1].length;n>r&&a.push({text:e.slice(r,n),mention:!1}),a.push({text:t[2],mention:!0}),r=n+t[2].length}return r<e.length&&a.push({text:e.slice(r),mention:!1}),a}function K(e,t){return X(e,t)?e:`${t.trim()} ${e.trimStart()}`}function ee(e){const t=e.map(e=>e.name).filter(Boolean);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}var te=/* @__PURE__ */new Set(["proposed","approved","running"]);function ne(e){return te.has(e.status)}function ae(e){const t=[];for(const n of e.parts)"data-plan"===n.type&&t.push(n.data);return t}function re(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of ae(n))t.delete(e.id),t.set(e.id,e);return t}function se(e){const t=[...re(e).values()],n=t[t.length-1];if(!n)return null;if(ne(n))return n;const a=e[e.length-1];return a&&"assistant"===a.role&&ae(a).some(e=>e.id===n.id)?n:null}function oe(e){const t={};return e.source&&e.source!==e.role&&(t.source=e.source),e.author&&(t.author=e.author),e.asked_by&&(t.askedBy=e.asked_by),e.created_at&&(t.createdAt=e.created_at),e.reply_to&&(t.replyTo=e.reply_to),"assistant"===e.role&&e.run_id&&(t.run_id=e.run_id,t.rating=e.rating??null),Object.keys(t).length>0?{metadata:t}:{}}function ie(e,t){const n=/* @__PURE__ */new Map;for(const a of e.parts){if("data-approval"!==a.type)continue;const e=a.data,r=e?.[t];"string"==typeof e?.approval_id&&"string"==typeof r&&r&&n.set(e.approval_id,r)}return n}function le(e){const t=e.messages.filter(e=>e.text).map(e=>({id:e.id,role:e.role,parts:[...(e.attachments??[]).map(H),{type:"text",text:e.text},...(e.files??[]).map(e=>({type:"data-file",id:`file-${e.id}`,data:e}))],...oe(e)})),n=(e.plans??[]).filter(ne);return(e.pending_approvals.length>0||n.length>0)&&t.push({id:`pending-approvals-${e.id}`,role:"assistant",parts:[...n.map(e=>({type:"data-plan",id:e.id,data:e})),...e.pending_approvals.map(e=>({type:`tool-${e.tool_name}`,toolCallId:e.tool_call_id??e.approval_id,state:"approval-requested",input:e.input,approval:{id:e.approval_id}})),...e.pending_approvals.filter(e=>e.expires_at||e.notice).map(e=>({type:"data-approval",id:e.approval_id,data:{approval_id:e.approval_id,expires_at:e.expires_at,...e.notice?{notice:e.notice}:{}}}))]}),t}function ce(e,t){const n=e?.message?.trim();if(!n)return t;if(n.startsWith("{")){try{const e=JSON.parse(n);for(const t of["detail","errorText","message","title","error"]){const n=e[t];if("string"==typeof n&&n.trim())return n.trim()}for(const t of Object.values(e)){const e=Array.isArray(t)?t[0]:void 0;if("string"==typeof e&&e.trim()&&e.length<=400)return e.trim()}}catch{return t}return t}return n.startsWith("<")||n.length>400?t:n}var de=/^(load failed|failed to fetch|network ?error( when attempting to fetch resource)?|(the )?network connection was lost|error in input stream|terminated)\.?$/i;function pe(e){return!(!e||"AbortError"===e.name)&&de.test(e.message?.trim()??"")}var ue=/* @__PURE__ */new Set(["budget_reached","not_permitted"]);function me(e,t,n){return pe(e)?{text:n.connectionDropped,retryable:!0}:{text:ce(e,n.genericError),retryable:!(t&&ue.has(t))}}function he(e){const t=e[e.length-1];if(!t)return!1;if("user"===t.role)return""!==q(t).trim();const n=e[e.length-2];return!(!n||"user"!==n.role||!q(n).trim())&&!t.parts.some(e=>void 0!==E(e)?.approvalId)}var fe={title:"Assistant",placeholder:"Ask a question…",inputLabel:"Message to the assistant",send:"Send",stop:"Stop",newChat:"New chat",open:"Open assistant",close:"Close assistant",thinking:"Thinking",loadingHistory:"Loading the conversation",historyFailed:"The earlier conversation could not be loaded.",emptyState:"Ask me anything to get started.",approvalNeeded:"Approval needed",approve:"Approve",deny:"Deny",approvalExpired:"This request expired. Ask again if you still want it done.",approved:"Approved",declined:"Declined",toolFailed:"did not complete",toolDeclined:"was not approved",details:"Details",stepSources:"Where these figures came from",reasoning:"Reasoning",genericError:"Something went wrong. Please try again.",connectionDropped:"The connection dropped. Your question may still be answering; reopen the chat in a moment.",retry:"Retry",working:"Working",steps:"Steps",teamName:"Team",teamJoined:"A team member has joined",plan:"Plan",planSummary:"Plan: {done} of {total} done",planProposed:"waiting for your approval",planApproved:"approved, starting",planRunning:"in progress",planCompleted:"finished",planFailed:"stopped — not every step ran",planDenied:"not approved — nothing was changed",planExpired:"expired — nothing was changed",planApprovalHeading:"Approve this plan of {count} steps",approvePlan:"Approve plan",replyStats:"{tokens} tokens · {seconds} s · {rate} tok/s",replyTokens:"{tokens} tokens",streaming:"Streaming",streamingRate:"Streaming · ~{rate} tok/s",followups:"Suggested follow-up questions",choices:"Answers to choose from",attach:"Attach a file",attaching:"Uploading",removeAttachment:"Remove {name}",openAttachment:"Open {name}",copyAnswer:"Copy",copied:"Copied",readOnly:"You can read this chat but not continue it.",rateAnswer:"Rate this answer",rateUp:"Helpful",rateDown:"Not helpful",rateNote:"What was wrong? (optional)",rateNoteSend:"Send",rateNoteSkip:"Skip",rateThanks:"Thanks for telling us.",rateFailed:"Your rating could not be saved.",openFile:"Open {name}",thinkingWords:["Thinking","Working it out","Checking"],waitingSeconds:"{seconds}s",notReplied:"The assistant didn’t reply. It took this as for the people.",askToReply:"Ask the assistant to reply",askToReplyText:"please reply to that.",flowDownloadPng:"Download PNG",flowDownloadSvg:"Download SVG",flowToPdf:"Add to the PDF",flowToPdfText:"Put that flowchart in a PDF.",detailsPanel:"Details",detailsChat:"Chat",detailsUsage:"Usage",detailsFiles:"Files",detailsTools:"Tools used",detailsAnswers:"{count} answers",detailsOneAnswer:"1 answer",detailsTokensIn:"Tokens in",detailsTokensOut:"Tokens out",detailsSpeed:"Average speed",detailsRate:"{rate} tok/s",detailsUsagePartial:"Counts the answers written while this window was open.",detailsYou:"You",detailsNoFiles:"No files yet.",detailsNoTools:"No tools used yet.",assistantMention:"@Assistant",assistantName:"",toPeople:"To {names} only. The assistant won’t reply.",toAssistant:"The assistant will reply. Everyone in the chat sees it.",assistantDecides:"The assistant replies if this is for it. Name it to be sure.",deciding:"The assistant is reading your message",askAssistant:"Ask the assistant",peopleOnly:"People only",letAssistantDecide:"Let the assistant decide",peoplePlaceholder:"Message {names}, or type {mention} to ask",askedBy:"Asked by {name}",sayFailed:"Your message didn’t send. Try again.",you:"You",quote:"Quote",moreActions:"More actions",replyingTo:"Replying to {name}",clearQuote:"Remove quote"},ge=140;function xe(e){const t=(n=e,n.replace(/```[\s\S]*?(```|$)/g," ").replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-*+]\s+|\d+[.)]\s+)/gm,"").replace(/!?\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/(\*\*|\*|`|~~)(?=\S)([^\n]*?\S)\1/g,"$2").replace(/\|/g," ")).replace(/\s+/g," ").trim();var n;if(t.length<=ge)return t;const a=t.slice(0,ge),r=a.lastIndexOf(" ");return`${(r>70?a.slice(0,r):a).trimEnd()}…`}function ve(e){const t=e.trim().split(/\s+/).filter(Boolean);if(0===t.length)return"?";return`${Array.from(t[0])[0]??""}${t.length>1?Array.from(t[t.length-1])[0]??"":""}`.toUpperCase()}function be({name:e,assistant:t,avatarUrl:n}){/* @__PURE__ */
|
|
3
|
+
return z("span",t?{"aria-hidden":"true",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-accent-tint text-accent-text","data-row-avatar":"assistant",children:/* @__PURE__ */z(N,{name:"sparkles",size:16})}:{"aria-hidden":"true",className:"flex shrink-0","data-row-avatar":n?"photo":"person",children:/* @__PURE__ */z(r,{src:n??void 0,name:e,size:"sm"})})}function ye({quote:e}){/* @__PURE__ */
|
|
4
|
+
return L("blockquote",{className:"m-0 mb-1 min-w-0 rounded-none border-l-[3px] border-line-strong pl-2 text-xs leading-5 text-ink-faint","data-reply-to":e.id,children:[
|
|
5
|
+
/* @__PURE__ */z("span",{className:"font-medium",children:e.author_name}),`: ${e.excerpt}`]})}function we({text:e,mention:t}){/* @__PURE__ */
|
|
6
|
+
return z(P,{children:V(e,t).map((e,t)=>e.mention?/* @__PURE__ */z("span",{className:"rounded bg-accent-tint px-1 font-medium text-accent-text","data-mention":"",children:e.text},t):e.text)})}var ke=e=>({...fe,...e});function Ne({quote:e,labels:t,onClear:n}){const a=ke(t);/* @__PURE__ */
|
|
7
|
+
return L("div",{className:"flex items-start gap-2 px-3 pt-2","data-composer-quote":"",children:[
|
|
8
|
+
/* @__PURE__ */L("div",{className:"min-w-0 flex-1 rounded-none border-l-[3px] border-line-strong pl-2 text-xs leading-5 text-ink-faint",children:[
|
|
9
|
+
/* @__PURE__ */z("div",{className:"font-medium text-ink",children:a.replyingTo.replace("{name}",e.author_name)}),
|
|
10
|
+
/* @__PURE__ */z("div",{className:"truncate",children:e.excerpt})]}),n&&/* @__PURE__ */z(d,{type:"button",size:"sm",variant:"ghost","aria-label":a.clearQuote,title:a.clearQuote,onClick:n,children:/* @__PURE__ */z(N,{name:"close"})})]})}var Ae={sent:"Sent",delivered:"Delivered",read:"Read"};function Ce({receipt:e,onInfo:t}){const n=Ae[e],a=/* @__PURE__ */L("span",{className:"inline-flex "+("read"===e?"text-accent-text":"text-ink-faint"),"data-receipt":e,children:[
|
|
11
|
+
/* @__PURE__ */z(N,{name:"check",size:12}),"sent"!==e&&/* @__PURE__ */z(N,{name:"check",size:12,className:"-ml-2"})]});return t?/* @__PURE__ */z(d,{size:"sm",variant:"ghost","aria-label":`${n}. Message info`,title:`${n}. Message info`,onClick:t,children:a}):/* @__PURE__ */z("span",{role:"img","aria-label":n,title:n,className:"inline-flex",children:a})}function Te({name:e,assistant:t,avatarUrl:n,mine:a=!1,receipt:r,onReceiptInfo:i,createdAt:l,note:c,replyTo:p,labels:u,onQuote:m,barItems:h,menu:f,menuText:g,footer:x,children:b}){const y=ke(u),w=s(),k=l?v(l):"",A=Boolean(f?.length),C=m||h||A?
|
|
12
|
+
/* @__PURE__ */L("div",{className:`absolute -top-3 ${a?"left-2":"right-2"} z-10 flex items-center gap-0.5 rounded-md border border-line bg-surface p-0.5 opacity-0 shadow-sm transition-opacity focus-within:opacity-100 group-hover:opacity-100`,"data-chat-chrome":"","data-row-actions":"",children:[m&&/* @__PURE__ */z(d,{size:"sm",variant:"ghost","aria-label":y.quote,title:y.quote,onClick:m,children:/* @__PURE__ */z(N,{name:"quote",className:"h-3.5 w-3.5"})}),h,A&&/* @__PURE__ */z(d,{size:"sm",variant:"ghost","aria-label":y.moreActions,title:y.moreActions,"aria-haspopup":"menu",onClick:e=>w.open(e,void 0),children:/* @__PURE__ */z(N,{name:"more",className:"h-3.5 w-3.5"})})]}):null,T=A&&w.state&&f&&/* @__PURE__ */z(o,{...w.props,"aria-label":y.moreActions,items:f.map(e=>({key:e.key,label:e.label,onSelect:()=>e.onSelect(g??"")}))}),S=k?/* @__PURE__ */z("time",{dateTime:l,className:"shrink-0 text-xs tabular-nums text-ink-faint",children:k}):null;/* @__PURE__ */
|
|
13
|
+
return L("div",a?{className:"group relative flex min-w-0 flex-col items-end px-2 py-1","data-chat-row":"mine",onContextMenu:A?e=>w.open(e,void 0):void 0,children:[
|
|
14
|
+
/* @__PURE__ */z("span",{className:"sr-only",children:e}),
|
|
15
|
+
/* @__PURE__ */L("div",{className:"min-w-0 max-w-[75%] rounded-2xl rounded-br-sm bg-accent-fill px-3 py-2 text-sm text-on-accent","data-bubble":"mine",children:[p&&/* @__PURE__ */z(ye,{quote:p}),
|
|
16
|
+
/* @__PURE__ */z("div",{className:"min-w-0",children:b})]}),(S||c||r)&&/* @__PURE__ */L("div",{className:"mt-0.5 flex items-center gap-2",children:[c&&/* @__PURE__ */z("span",{className:"min-w-0 truncate text-xs text-ink-faint",children:c}),S,r&&/* @__PURE__ */z(Ce,{receipt:r,onInfo:i})]}),x,C,T]}:{className:"group relative flex min-w-0 gap-2 px-2 py-1","data-chat-row":t?"assistant":"person",onContextMenu:A?e=>w.open(e,void 0):void 0,children:[
|
|
17
|
+
/* @__PURE__ */z(be,{name:e,assistant:t,avatarUrl:n}),
|
|
18
|
+
/* @__PURE__ */L("div",{className:"flex min-w-0 flex-col items-start "+(t?"flex-1":"max-w-[85%]"),children:[
|
|
19
|
+
/* @__PURE__ */L("div",{className:"flex min-w-0 items-baseline gap-2",children:[
|
|
20
|
+
/* @__PURE__ */z("span",{className:"truncate text-sm font-medium text-ink-strong",children:e}),S,c&&/* @__PURE__ */z("span",{className:"min-w-0 truncate text-xs text-ink-faint",children:c})]}),
|
|
21
|
+
/* @__PURE__ */L("div",{className:t?"min-w-0 w-full text-sm text-ink":"min-w-0 max-w-full rounded-2xl rounded-bl-sm bg-surface-sunken px-3 py-2 text-sm text-ink","data-bubble":t?void 0:"theirs",children:[p&&/* @__PURE__ */z(ye,{quote:p}),
|
|
22
|
+
/* @__PURE__ */z("div",{className:"min-w-0",children:b})]}),x]}),C,T]})}var Se=["·","✢","✳","✶","✻","✽","✻","✶","✳","✢"];function je(){return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Oe({resting:e=!1}){const t=function(){const[e,t]=j(0);return O(()=>{if(je())return;const e=setInterval(()=>t(e=>(e+1)%Se.length),130);return()=>clearInterval(e)},[]),je()?"✻":Se[e]}();/* @__PURE__ */
|
|
23
|
+
return z("span",{"aria-hidden":"true",className:"inline-block w-4 shrink-0 text-center text-base leading-none text-accent-text "+(e?"opacity-60":"motion-safe:animate-pulse"),children:e?"✻":t})}function _e({label:e,words:t,since:n,secondsLabel:a,steadyLabel:r}){const[s,o]=j(0);O(()=>{if(e||t.length<2||je())return;const n=setInterval(()=>o(e=>(e+1)%t.length),1600);return()=>clearInterval(n)},[e,t.length]);const i=function(e){const[t]=j(()=>e||Date.now()),[n,a]=j(()=>Date.now());return O(()=>{const e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},[]),Math.max(0,Math.floor((n-(e||t))/1e3))}(n),l=e||t[s%Math.max(t.length,1)]||r;/* @__PURE__ */
|
|
24
|
+
return L("div",{className:"flex items-center gap-2 text-sm text-ink-faint","data-assistant-waiting":"",children:[
|
|
25
|
+
/* @__PURE__ */z("span",{className:"sr-only",children:r}),
|
|
26
|
+
/* @__PURE__ */z(Oe,{}),
|
|
27
|
+
/* @__PURE__ */z("span",{"aria-hidden":"true",className:"min-w-0 truncate",children:`${l}…`}),
|
|
28
|
+
/* @__PURE__ */z("span",{"aria-hidden":"true",className:"shrink-0 text-xs tabular-nums",children:a.replace("{seconds}",String(i))})]})}function Re({labels:e,placeholder:t,busy:n,focusWhen:a,onSend:r,onStop:s,onNewChat:o,actions:i,attachments:c,people:f,assistantDecides:g,deciding:x,quiet:v,onAskToReply:b,quote:y,onClearQuote:w}){const[S,_]=j(""),[$,I]=j(!1),D=T(null),F=function(e){const[t,n]=j([]),a=T(0),r=T(!0);O(()=>()=>{r.current=!1},[]);const s=e?.upload,o=R(e=>{if(s)for(const t of e){const e=a.current++;n(n=>[...n,{key:e,name:t.name,size:t.size}]),s(t).then(t=>{r.current&&n(n=>n.map(n=>n.key===e?{...n,attachment:t}:n))},t=>{const a=t instanceof Error&&t.message?t.message:String(t);r.current&&n(t=>t.map(t=>t.key===e?{...t,error:a}:t))})}},[s]),i=t.some(e=>!e.attachment&&!e.error),l=t.flatMap(e=>e.attachment?[e.attachment]:[]);return{pending:t,add:o,remove:e=>n(t=>t.filter(t=>t.key!==e)),clear:()=>n([]),uploading:i,ready:l}}(c),M=C().files,P=u({accept:c?.accept,maxSizeBytes:c?.maxSizeBytes,maxFiles:c?.maxFiles??5,acceptHint:c?.acceptHint,currentCount:F.pending.length,disabled:!c,onAccept:F.add});O(()=>{a&&D.current?.focus()},[a]);const B=y?.id;O(()=>{B&&D.current?.focus()},[B]);const E=()=>{const e=D.current;e&&(e.value&&0!==e.clientWidth?(e.style.height="auto",e.style.height=`${e.scrollHeight}px`):e.style.height="")};O(E,[S]),O(()=>{const e=D.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=e.clientWidth;const n=new ResizeObserver(()=>{e.clientWidth!==t&&(t=e.clientWidth,E())});return n.observe(e),()=>n.disconnect()},[]);const U=n||x||F.uploading||!S.trim(),W=()=>{U||(r(S,F.ready,{peopleOnly:!!g&&$,...y?{reply_to:y.id}:{}}),_(""),F.clear(),P.clearRejections(),y&&w?.())},q=!!f&&(X(S,e.assistantMention,e.assistantName)||F.pending.length>0),Y=!!g&&!$,H=q?e.toAssistant:Y?e.assistantDecides:e.toPeople.replace("{names}",f??""),Q=q||x?null:g?{label:Y?e.peopleOnly:e.letAssistantDecide,onClick:()=>I(Y)}:{label:e.askAssistant,onClick:()=>_(t=>K(t,e.assistantMention))},J=f?/* @__PURE__ */L("div",{className:"flex items-center gap-2 px-3 pt-1 text-xs",children:[
|
|
29
|
+
/* @__PURE__ */z("span",{role:"status",className:"min-w-0 flex-1 truncate "+(q?"text-accent-text":"text-ink-faint"),children:H}),Q&&/* @__PURE__ */z(k,{type:"button",size:"sm",variant:"ghost",onClick:()=>{Q.onClick(),D.current?.focus()},children:Q.label})]}):null,Z=/* @__PURE__ */L("form",{className:"flex items-end gap-1 p-1",onSubmit:e=>{e.preventDefault(),W()},children:[o&&/* @__PURE__ */z(d,{type:"button",variant:"ghost","aria-label":e.newChat,title:e.newChat,onClick:o,children:/* @__PURE__ */z(N,{name:"compose"})}),c&&/* @__PURE__ */z(d,{type:"button",variant:"ghost","aria-label":e.attach,title:e.attach,onClick:P.open,disabled:n,children:/* @__PURE__ */z(N,{name:"add"})}),
|
|
30
|
+
/* @__PURE__ */z("textarea",{ref:D,"aria-label":e.inputLabel,placeholder:t,rows:1,value:S,onChange:e=>_(e.target.value),onInput:E,onKeyDown:e=>{if("Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing)return e.preventDefault(),void W();"Escape"===e.key&&y&&w&&(e.preventDefault(),w())},className:"block max-h-48 min-w-0 flex-1 resize-none overflow-y-auto bg-transparent py-1 text-sm leading-6 text-ink-strong outline-none placeholder:text-[color:var(--ink-placeholder)] "+(o||c?"px-1":"px-2")}),i?.map(e=>e.icon?/* @__PURE__ */z(d,{type:"button",variant:"ghost","aria-label":e.label,title:e.label,disabled:!S.trim(),onClick:()=>e.onSelect(S.trim()),children:/* @__PURE__ */z(N,{name:e.icon})},e.key):/* @__PURE__ */z(k,{type:"button",variant:"ghost",disabled:!S.trim(),onClick:()=>e.onSelect(S.trim()),children:e.label},e.key)),/* @__PURE__ */z(d,n?{type:"button",variant:"ghost","aria-label":e.stop,title:e.stop,onClick:s,children:/* @__PURE__ */z(N,{name:"stop-circle"})}:{type:"submit",variant:"ghost","aria-label":e.send,title:e.send,disabled:U,children:/* @__PURE__ */z(N,{name:"enter"})})]}),G=f&&x?/* @__PURE__ */z("div",{className:"px-1 pb-1",children:/* @__PURE__ */z(_e,{label:e.deciding,words:[],secondsLabel:e.waitingSeconds,steadyLabel:e.deciding})}):f&&v&&b?/* @__PURE__ */L("div",{className:"flex items-center gap-2 px-1 pb-1 text-xs text-ink-faint",children:[
|
|
31
|
+
/* @__PURE__ */z(Oe,{resting:!0}),
|
|
32
|
+
/* @__PURE__ */z("span",{role:"status",className:"min-w-0 flex-1 truncate",children:e.notReplied}),
|
|
33
|
+
/* @__PURE__ */z(k,{type:"button",size:"sm",variant:"secondary",onClick:b,children:e.askToReply})]}):null,V=y?/* @__PURE__ */z(Ne,{quote:y,labels:e,onClear:w?()=>{w(),D.current?.focus()}:void 0}):null,ee="rounded-2xl border border-line bg-surface shadow-sm transition-colors focus-within:border-line-strong";return c?/* @__PURE__ */L(l,{intake:P,className:"px-3 pt-2 pb-3",children:[G,
|
|
34
|
+
/* @__PURE__ */L("div",{className:ee,children:[F.pending.length>0&&/* @__PURE__ */z("ul",{className:"flex flex-wrap gap-2 px-3 pt-3",children:F.pending.map(t=>/* @__PURE__ */L("li",{className:"flex max-w-full items-center gap-2 rounded-md border py-1 pl-2 pr-1 text-xs "+(t.error?"border-red-200 bg-red-50 text-red-700":"border-gray-200 bg-gray-50 text-gray-700"),children:[t.attachment||t.error?/* @__PURE__ */z(N,{name:"page",size:14,"aria-hidden":"true"}):/* @__PURE__ */z("span",{role:"status","aria-label":e.attaching,className:"inline-flex",children:/* @__PURE__ */z(A,{className:"h-3 w-3"})}),
|
|
35
|
+
/* @__PURE__ */z("span",{className:"min-w-0 truncate",title:t.error??t.name,children:t.name}),
|
|
36
|
+
/* @__PURE__ */z("span",{className:"shrink-0 tabular-nums text-gray-400",children:m(t.size,M)}),
|
|
37
|
+
/* @__PURE__ */z("button",{type:"button",onClick:()=>F.remove(t.key),"aria-label":e.removeAttachment.replace("{name}",t.name),className:"shrink-0 rounded p-0.5 text-gray-400 hover:bg-gray-200 hover:text-gray-600",children:/* @__PURE__ */z(p,{className:"h-3.5 w-3.5"})})]},t.key))}),F.pending.some(e=>e.error)&&/* @__PURE__ */z("ul",{role:"alert",className:"flex flex-col gap-0.5 px-3 pt-1",children:F.pending.flatMap(e=>e.error?[/* @__PURE__ */z("li",{className:"text-xs text-red-600",children:`${e.name}: ${e.error}`},e.key)]:[])}),
|
|
38
|
+
/* @__PURE__ */z(h,{rejections:P.rejections,className:"px-3 pt-1"}),V,Z]}),J]}):/* @__PURE__ */L("div",{className:"px-3 pt-2 pb-3",children:[G,
|
|
39
|
+
/* @__PURE__ */L("div",{className:ee,children:[V,Z]}),J]})}function $e(e){const t=e.replace(/^tool-/,"").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_\-.]+/g," ").trim().toLowerCase();return t?t.charAt(0).toUpperCase()+t.slice(1):e}var Ie={propose_plan:{label:"Plan the changes",running:"Planning the changes",done:"Planned the changes"}};function De(e,t){const n=t?.[e]??Ie[e];return"string"==typeof n?{label:n}:n??{label:$e(e)}}function Fe(e,t){return De(e,t).label}function Me(e,t){const n=De(e,t);return n.done??n.label}function ze(e){return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}function Le(e,t,n){const a=De(e,n).describe;if(!a)return"";try{return a(ze(t))?.trim()??""}catch{return""}}function Pe(e,t){return null==e?"":"boolean"==typeof e?e?"Yes":"No":"object"!=typeof e?String(e):Array.isArray(e)?e.map(e=>Pe(e,t+1)).filter(Boolean).join(", "):t>=3?"…":Object.entries(e).map(([e,n])=>{const a=Pe(n,t+1);return a?`${$e(e)}: ${a}`:""}).filter(Boolean).join("; ")}function Be(e){const t=ze(e),n=[];for(const[e,a]of Object.entries(t)){if(e.startsWith("_"))continue;const t=Pe(a,0);t&&n.push({label:$e(e),value:t})}return 0===n.length&&null!=e&&"object"!=typeof e&&n.push({label:"Value",value:Pe(e,0)}),n}function Ee(e,t){const n={answers:0,counted:0,inputTokens:0,outputTokens:0,rate:null};let a=0;const r=[],s=/* @__PURE__ */new Set,o=/* @__PURE__ */new Map;for(const i of e){if("user"===i.role){const e=i.metadata?.author?.name??null;for(const t of Q(i))s.has(t.id)||(s.add(t.id),r.push({kind:"attached",attachment:t,from:e}));continue}if("assistant"!==i.role)continue;if(i.metadata?.source)continue;n.answers+=1;const e=i.metadata?.usage;e&&(n.counted+=1,n.inputTokens+=e.input_tokens,n.outputTokens+=e.output_tokens,a+=e.generation_ms);for(const e of W(i))s.has(e.id)||(s.add(e.id),r.push({kind:"made",file:e}));const l=/* @__PURE__ */new Set;for(const e of i.parts){const n=E(e);if(!n||"output-available"!==n.state||l.has(n.toolCallId))continue;l.add(n.toolCallId);const a=Me(n.toolName,t);o.set(a,(o.get(a)??0)+1)}}return n.outputTokens>0&&a>=100&&(n.rate=n.outputTokens/(a/1e3)),{usage:n,files:r,tools:[...o].map(([e,t])=>({label:e,count:t})).sort((e,t)=>t.count-e.count)}}function Ue(e){return e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(e<1e5?1:0).replace(/\.0$/,"")}k`:`${(e/1e6).toFixed(1).replace(/\.0$/,"")}M`}function We(e,t){return e>0&&t>=100?e/(t/1e3):null}function qe(e){return Math.ceil(e.length/4)}var Ye=(e,t)=>e.replace(/\{(\w+)\}/g,(e,n)=>t[n]??e),He=e=>Math.round(e).toLocaleString();function Qe(e,t){const n=We(e.output_tokens,e.generation_ms);return null===n?Ye(t.replyTokens,{tokens:He(e.output_tokens)}):Ye(t.replyStats,{tokens:He(e.output_tokens),seconds:(e.generation_ms/1e3).toFixed(1),rate:He(n)})}function Je(e,t,n){const a=t>=1e3?We(qe(e),t):null;return null===a?n.streaming:Ye(n.streamingRate,{rate:He(a)})}var Ze=(e,t)=>e.replace(/\{(\w+)\}/g,(e,n)=>t[n]??e);function Ge({title:e,aside:t,children:n}){/* @__PURE__ */
|
|
40
|
+
return L("details",{open:!0,className:"group rounded-lg border border-line bg-surface px-3 py-2",children:[
|
|
41
|
+
/* @__PURE__ */L("summary",{className:"flex cursor-pointer select-none list-none items-center gap-1 text-sm font-medium text-ink-strong [&::-webkit-details-marker]:hidden",children:[
|
|
42
|
+
/* @__PURE__ */z("span",{children:e}),
|
|
43
|
+
/* @__PURE__ */z(N,{name:"chevron-down",size:14,"aria-hidden":"true",className:"-rotate-90 transition-transform group-open:rotate-0"}),t&&/* @__PURE__ */z("span",{className:"ml-auto text-xs font-normal text-ink-faint",children:t})]}),
|
|
44
|
+
/* @__PURE__ */z("div",{className:"mt-2",children:n})]})}function Xe({rows:e}){/* @__PURE__ */
|
|
45
|
+
return z("dl",{className:"grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-xs",children:e.map(e=>/* @__PURE__ */L("div",{className:"contents",children:[
|
|
46
|
+
/* @__PURE__ */z("dt",{className:"text-ink-faint",children:e.label}),
|
|
47
|
+
/* @__PURE__ */z("dd",{className:"min-w-0 text-right text-ink",children:e.value})]},e.key))})}function Ve(e){return"pdf"===e?"document":"csv"===e||"xlsx"===e?"table":"page"}function Ke({entry:e,labels:t,assistantName:n,onOpenFile:a,onOpenAttachment:r}){const s="made"===e.kind,o=s?e.file.filename:e.attachment.filename,i=s?e.file.kind:o.split(".").pop()?.toLowerCase()??"",l=s?n:e.from??t.detailsYou,c=s?a&&(()=>a(e.file)):r&&(()=>r(e.attachment));/* @__PURE__ */
|
|
48
|
+
return L("li",{className:"flex min-w-0 items-center gap-2 text-xs",children:[
|
|
49
|
+
/* @__PURE__ */z(N,{name:Ve(i),size:14,"aria-hidden":"true",className:"shrink-0"}),c?/* @__PURE__ */z("button",{type:"button",onClick:c,title:o,"aria-label":Ze(t.openFile,{name:o}),className:"min-w-0 flex-1 truncate text-left text-accent-text hover:underline",children:o}):/* @__PURE__ */z("span",{className:"min-w-0 flex-1 truncate text-ink",title:o,children:o}),
|
|
50
|
+
/* @__PURE__ */z("span",{className:"shrink-0 text-ink-faint",children:l})]})}function et({messages:e,facts:t,toolLabels:n,labels:a,assistantName:r,onOpenFile:s,onOpenAttachment:o}){const{usage:i,files:l,tools:c}=Ee(e,n),d=c.reduce((e,t)=>e+t.count,0),p=i.counted<i.answers,u=p?/* @__PURE__ */z("p",{className:"mt-2 text-xs text-ink-faint",children:a.detailsUsagePartial}):null;/* @__PURE__ */
|
|
51
|
+
return L("aside",{"aria-label":a.detailsPanel,className:"flex w-64 shrink-0 flex-col gap-2 overflow-y-auto border-l border-line bg-surface-sunken p-2",children:[t&&t.length>0&&/* @__PURE__ */z(Ge,{title:a.detailsChat,children:/* @__PURE__ */z(Xe,{rows:t})}),
|
|
52
|
+
/* @__PURE__ */L(Ge,{title:a.detailsUsage,aside:1===i.answers?a.detailsOneAnswer:Ze(a.detailsAnswers,{count:He(i.answers)}),children:[
|
|
53
|
+
/* @__PURE__ */z(Xe,{rows:[{key:"in",label:a.detailsTokensIn,value:i.counted>0?Ue(i.inputTokens):"—"},{key:"out",label:a.detailsTokensOut,value:i.counted>0?Ue(i.outputTokens):"—"},...null===i.rate?[]:[{key:"rate",label:a.detailsSpeed,value:Ze(a.detailsRate,{rate:He(i.rate)})}]]}),u]}),
|
|
54
|
+
/* @__PURE__ */z(Ge,{title:a.detailsFiles,aside:l.length>0?He(l.length):void 0,children:l.length>0?/* @__PURE__ */z("ul",{className:"flex flex-col gap-1",children:l.map(e=>/* @__PURE__ */z(Ke,{entry:e,labels:a,assistantName:r,onOpenFile:s,onOpenAttachment:o},"made"===e.kind?e.file.id:e.attachment.id))}):/* @__PURE__ */z("p",{className:"text-xs text-ink-faint",children:a.detailsNoFiles})}),
|
|
55
|
+
/* @__PURE__ */L(Ge,{title:a.detailsTools,aside:d>0?He(d):void 0,children:[c.length>0&&/* @__PURE__ */z(Xe,{rows:c.map(e=>({key:e.label,label:e.label,value:He(e.count)}))}),0===c.length&&!p&&/* @__PURE__ */z("p",{className:"text-xs text-ink-faint",children:a.detailsNoTools}),u]})]})}function tt({rows:e,label:t}){/* @__PURE__ */
|
|
56
|
+
return z("dl",{"aria-label":t,className:"grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1 text-xs",children:e.map((e,t)=>/* @__PURE__ */L("div",{className:"contents",children:[
|
|
57
|
+
/* @__PURE__ */z("dt",{className:"text-gray-500",children:e.label}),
|
|
58
|
+
/* @__PURE__ */z("dd",{className:"min-w-0 break-words "+(e.warn?"font-medium text-amber-700":"text-gray-800"),children:e.value})]},`${e.label}-${t}`))})}function nt({approvalId:e,expiresAt:t,expired:n=!1,approveLabel:a,labels:r,onApprove:s}){const o=function(e){const t=e?Date.parse(e):Number.NaN,[n,a]=j(()=>Number.isFinite(t)&&t<=Date.now());return O(()=>{if(!Number.isFinite(t))return;const e=t-Date.now();if(e<=0)return void a(!0);if(a(!1),e>2147483647)return;const n=setTimeout(()=>a(!0),e);return()=>clearTimeout(n)},[t]),n}(t)||n;return o?/* @__PURE__ */z("p",{role:"note",className:"mt-3 text-xs text-ink-faint",children:r.approvalExpired}):/* @__PURE__ */L("div",{className:"mt-3 flex gap-2",children:[
|
|
59
|
+
/* @__PURE__ */z(k,{size:"sm",onClick:()=>s(e,!0),children:a}),
|
|
60
|
+
/* @__PURE__ */z(k,{size:"sm",variant:"secondary",onClick:()=>s(e,!1),children:r.deny})]})}function at({tool:e,toolLabels:t,labels:n,onApprove:a,expiresAt:r,notice:s}){const o=Le(e.toolName,e.input,t),i=Be(e.input),l=e.approvalId,c=`${n.approvalNeeded}: ${Fe(e.toolName,t)}${o?` ${o}`:""}`;/* @__PURE__ */
|
|
61
|
+
return L("div",{role:"group","aria-label":c,className:"rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm",children:[
|
|
62
|
+
/* @__PURE__ */z("div",{className:"font-medium text-gray-900",children:c}),s&&/* @__PURE__ */L("p",{role:"note",className:"mt-2 flex items-start gap-1 text-xs font-medium text-warning-text",children:[
|
|
63
|
+
/* @__PURE__ */z(N,{name:"warning",size:14,"aria-hidden":"true",className:"mt-0.5 shrink-0"}),
|
|
64
|
+
/* @__PURE__ */z("span",{children:s})]}),i.length>0&&/* @__PURE__ */z("div",{className:"mt-2",children:/* @__PURE__ */z(tt,{rows:i})}),
|
|
65
|
+
/* @__PURE__ */z(nt,{approvalId:l,expiresAt:r,approveLabel:n.approve,labels:n,onApprove:a})]})}var rt={running:"active",done:"complete",failed:"failed",declined:"stopped",waiting:"waiting"};function st(e,t,n){return function(e,t,n,a,r,s){const o=De(n,r),i=Le(n,a,r),l=(e,t)=>({kind:e,base:t,subject:i,text:i?`${t} ${i}`:t});switch(e){case"output-available":return l("done",o.done??o.label);case"output-error":return l("failed",`${o.label} ${s.toolFailed}`);case"output-denied":return l("declined",`${o.label} ${s.toolDeclined}`);case"approval-requested":return l("waiting",`${s.approvalNeeded}: ${o.label}`);case"approval-responded":return!1===t?l("declined",`${o.label} — ${s.declined}`):l("running",`${s.approved}: ${o.running??o.label}`);default:return l("running",o.running??o.label)}}(e.state,e.approved,e.toolName,e.input,t,n)}function ot({tool:t,summary:n,toolLabels:a,labels:r,showOutput:s}){const o=st(t,a,r),i=Be(t.input),l=s&&"output-available"===t.state?Be(t.output):[],c=s&&"output-error"===t.state&&t.errorText?t.errorText:"",d="output-available"===t.state&&n?n.rows:[];let p=null;return(i.length>0||l.length>0||c)&&(p=/* @__PURE__ */L("details",{className:d.length>0?"mt-1":void 0,children:[
|
|
66
|
+
/* @__PURE__ */z("summary",{className:"cursor-pointer select-none",children:r.details}),
|
|
67
|
+
/* @__PURE__ */L("div",{className:"mt-1 space-y-2",children:[i.length>0&&/* @__PURE__ */z(tt,{rows:i}),l.length>0&&/* @__PURE__ */z(tt,{rows:l}),c&&/* @__PURE__ */z("div",{className:"text-red-600",children:c})]})]})),/* @__PURE__ */L(e,{label:o.base,description:o.subject||void 0,status:rt[o.kind],children:[d.length>0&&/* @__PURE__ */z(tt,{rows:d,label:r.stepSources}),p]})}var it={proposed:"planProposed",approved:"planApproved",running:"planRunning",completed:"planCompleted",failed:"planFailed",denied:"planDenied",expired:"planExpired"},lt={pending:"pending",running:"active",done:"complete",failed:"failed",skipped:"skipped"};function ct(e,t){const n=Le(e.tool_name,e.input,t);return`${Fe(e.tool_name,t)}${n?` ${n}`:""}`}function dt(e,t){return e.replace(/\{(\w+)\}/g,(e,n)=>n in t?String(t[n]):e)}function pt(e,t){const n=e.steps.filter(e=>"done"===e.status).length;return`${dt(t.planSummary,{done:n,total:e.steps.length})} · ${t[it[e.status]]}`}function ut({plan:n,labels:a}){/* @__PURE__ */
|
|
68
|
+
return z("section",{"aria-label":a.plan,className:"border-t border-gray-200 bg-white px-3 py-2",children:/* @__PURE__ */z(t,{summary:pt(n,a),busy:ne(n),label:a.plan,children:n.steps.map(t=>/* @__PURE__ */z(e,{label:t.title,status:lt[t.status],description:"done"!==t.status&&t.result_summary?t.result_summary:void 0},t.id))})})}function mt({approvalId:e,plan:t,input:n,labels:a,toolLabels:r,onApprove:s,expiresAt:o}){const i=function(e,t){if(e)return e.steps.map(e=>({key:e.id,title:e.title,tool_name:e.tool_name,input:e.input}));const n=t?.steps;return Array.isArray(n)?n.map((e,t)=>{const n=e??{};return{key:String(t),title:"string"==typeof n.title?n.title:"",tool_name:"string"==typeof n.tool?n.tool:"",input:n.args}}):[]}(t,n),l=dt(a.planApprovalHeading,{count:i.length});/* @__PURE__ */
|
|
69
|
+
return L("div",{role:"group","aria-label":l,className:"rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm",children:[
|
|
70
|
+
/* @__PURE__ */z("div",{className:"font-medium text-gray-900",children:l}),
|
|
71
|
+
/* @__PURE__ */z("ol",{className:"mt-2 list-decimal space-y-2 pl-5",children:i.map(e=>{const t=Be(e.input);/* @__PURE__ */
|
|
72
|
+
return L("li",{children:[
|
|
73
|
+
/* @__PURE__ */z("div",{className:"font-medium text-gray-900",children:ct(e,r)}),e.title&&/* @__PURE__ */z("div",{className:"text-xs text-gray-600",children:e.title}),t.length>0&&/* @__PURE__ */z("dl",{className:"mt-1 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1 text-xs",children:t.map(e=>/* @__PURE__ */L("div",{className:"contents",children:[
|
|
74
|
+
/* @__PURE__ */z("dt",{className:"text-gray-500",children:e.label}),
|
|
75
|
+
/* @__PURE__ */z("dd",{className:"min-w-0 break-words text-gray-800",children:e.value})]},e.label))})]},e.key)})}),
|
|
76
|
+
/* @__PURE__ */z(nt,{approvalId:e,expiresAt:o,expired:"expired"===t?.status,approveLabel:a.approvePlan,labels:a,onApprove:s})]})}function ht({choices:e,label:t,onAnswer:n}){return 0===e.length?null:/* @__PURE__ */z("div",{role:"group","aria-label":t,className:"flex flex-col items-start gap-2 pl-1",children:e.map(e=>/* @__PURE__ */z(k,{size:"sm",variant:"secondary",onClick:()=>n(e),children:e},e))})}function ft({questions:e,label:t,onAsk:n}){return 0===e.length?null:/* @__PURE__ */z("div",{role:"group","aria-label":t,className:"flex flex-wrap gap-2 pl-1",children:e.map(e=>/* @__PURE__ */z(k,{size:"sm",variant:"secondary",onClick:()=>n(e),children:e},e))})}function gt({initial:e,labels:t,onRate:n}){const[a,r]=j(e??null),[s,o]=j(!1),[i,l]=j(""),[p,u]=j(!1),[m,h]=j(!1),[f,g]=j(!1),x=async e=>{const t=a;r(e),h(!1),g(!0);try{return await n(e),!0}catch{return r(t),h(!0),!1}finally{g(!1)}},v=e=>{const n="up"===e?t.rateUp:t.rateDown;/* @__PURE__ */
|
|
77
|
+
return z(d,{size:"sm","aria-label":n,title:n,"aria-pressed":a?.verdict===e,disabled:f,onClick:()=>{(async e=>{if(u(!1),a?.verdict===e)return o(!1),void await x(null);const t=await x({verdict:e,note:""});o(t&&"down"===e),l("")})(e)},children:/* @__PURE__ */z(N,{name:"hand-thumb-up",className:"down"===e?"h-3.5 w-3.5 rotate-180":"h-3.5 w-3.5"})})};/* @__PURE__ */
|
|
78
|
+
return L("div",{role:"group","aria-label":t.rateAnswer,className:"flex min-w-0 flex-1 flex-col gap-1",children:[
|
|
79
|
+
/* @__PURE__ */L("div",{className:"flex items-center gap-1",children:[v("up"),v("down"),p&&/* @__PURE__ */z("span",{role:"status",className:"px-1 text-xs text-gray-500",children:t.rateThanks}),m&&/* @__PURE__ */z("span",{role:"alert",className:"px-1 text-xs text-red-600",children:t.rateFailed})]}),s&&/* @__PURE__ */L("form",{className:"flex items-center gap-2",onSubmit:e=>{(async e=>{e.preventDefault();const t=i.trim();t&&!await x({verdict:"down",note:t})||(o(!1),u(Boolean(t)))})(e)},children:[
|
|
80
|
+
/* @__PURE__ */z("div",{className:"min-w-0 flex-1",children:/* @__PURE__ */z(c,{size:"sm","aria-label":t.rateNote,placeholder:t.rateNote,maxLength:500,value:i,onChange:e=>l(e.target.value),autoFocus:!0})}),
|
|
81
|
+
/* @__PURE__ */z(k,{type:"submit",size:"sm",variant:"secondary",disabled:f||!i.trim(),children:t.rateNoteSend}),
|
|
82
|
+
/* @__PURE__ */z(k,{type:"button",size:"sm",variant:"ghost",onClick:()=>o(!1),children:t.rateNoteSkip})]})]})}function xt(e,t){return n=>{if("chart"===n.lang){if(!n.closed)/* @__PURE__ */return z(w,{height:200});const e=f(n.code);return e?/* @__PURE__ */z(g,{spec:e}):null}if("flow"===n.lang){if(!n.closed)/* @__PURE__ */return z(w,{height:200});const a=y(n.code);return a?/* @__PURE__ */z(b,{spec:a,labels:{downloadPng:e.flowDownloadPng,downloadSvg:e.flowDownloadSvg,toPdf:e.flowToPdf},onToPdf:t?()=>t(e.flowToPdfText):void 0}):null}return null}}function vt(e,t){return"approval-responded"===e.state&&t.some(t=>{return t.toolName===e.toolName&&"approval-requested"!==t.state&&(t.toolCallId===e.toolCallId||(n=t.input,a=e.input,JSON.stringify(n)===JSON.stringify(a)));var n,a})}function bt(e,t,n,a){const r=e.flatMap(e=>"tool"===e.kind?[st(e.tool,n,a)]:[]);if(t){const e=r.find(e=>"running"===e.kind);return e?e.base:a.working}const s=[...new Set(r.map(e=>e.base))];return s.length>0?s.join(" · "):a.reasoning}function yt({message:e,live:t,labels:n}){const a=q(e),r=a.length>0,s=T(null),[o,i]=j(0);O(()=>{if(!t)return;null===s.current&&(s.current=performance.now());const e=setInterval(()=>i(performance.now()-(s.current??performance.now())),500);return()=>clearInterval(e)},[t]);const l=e.metadata?.usage;let c=null;return t?c=r?Je(a,o,n):null:l&&(c=Qe(l,n)),c?/* @__PURE__ */z("div",{className:"px-1 text-xs leading-6 tabular-nums text-gray-500",children:c}):null}function wt({files:e,labels:t,onOpen:n,start:a}){const r="flex max-w-full items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700";/* @__PURE__ */
|
|
83
|
+
return z("ul",{className:a?"mt-1 flex flex-wrap gap-2":"flex max-w-[85%] flex-wrap justify-end gap-2",children:e.map(e=>{const a=/* @__PURE__ */L(P,{children:[
|
|
84
|
+
/* @__PURE__ */z(N,{name:"page",size:14,"aria-hidden":"true",className:"shrink-0"}),
|
|
85
|
+
/* @__PURE__ */z("span",{className:"min-w-0 truncate",children:e.filename})]});/* @__PURE__ */
|
|
86
|
+
return z("li",{className:"max-w-full",children:n?/* @__PURE__ */z("button",{type:"button",className:`${r} hover:bg-gray-50`,title:t.openAttachment.replace("{name}",e.filename),onClick:()=>n(e),children:a}):/* @__PURE__ */z("span",{className:r,children:a})},e.id)})})}function kt(e){return["xlsx"===e.kind?"Excel":String(e.kind||"").toUpperCase(),x(e.size)].filter(Boolean).join(" · ")}function Nt({file:e,labels:t,onOpen:n}){const a=/* @__PURE__ */L(P,{children:["pdf"===e.kind?/* @__PURE__ */z(N,{name:"document",size:20,className:"shrink-0"}):/* @__PURE__ */z(N,{name:"table",size:20,className:"shrink-0"}),
|
|
87
|
+
/* @__PURE__ */L("span",{className:"min-w-0 flex-1",children:[
|
|
88
|
+
/* @__PURE__ */z("span",{className:"block truncate text-sm font-medium text-gray-800",children:e.filename}),
|
|
89
|
+
/* @__PURE__ */z("span",{className:"block text-xs text-gray-500",children:kt(e)})]})]}),r="flex w-full max-w-sm items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-left";return n?/* @__PURE__ */z("button",{type:"button",className:`${r} hover:border-blue-300 hover:bg-blue-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500`,"data-assistant-file":e.id,"aria-label":t.openFile.replace("{name}",e.filename),onClick:()=>n(e),children:a}):/* @__PURE__ */z("div",{className:r,"data-assistant-file":e.id,children:a})}function At({message:e,labels:t,showCopy:n,actions:r,answer:s,bar:o}){const[i,l]=j(!1);O(()=>{if(!i)return;const e=setTimeout(()=>l(!1),1500);return()=>clearTimeout(e)},[i]);const c=q(e);if(!c.trim()||!n&&!r?.length)return null;const p=async()=>{const e=Array.from(s.current?.querySelectorAll("[data-answer-text]")??[]);l(await async function(e,t){const n="undefined"!=typeof navigator?navigator.clipboard:void 0;if(!n)return!1;try{return t&&"undefined"!=typeof ClipboardItem&&n.write?(await n.write([new ClipboardItem({"text/html":new Blob([t],{type:"text/html"}),"text/plain":new Blob([e],{type:"text/plain"})})]),!0):(await n.writeText(e),!0)}catch{return!1}}(c,function(e){return e.map(e=>{const t=e.cloneNode(!0);return t.querySelectorAll("button, [data-chat-chrome]").forEach(e=>e.remove()),t.querySelectorAll("[class]").forEach(e=>e.removeAttribute("class")),t.removeAttribute("class"),t.querySelectorAll("table").forEach(e=>e.setAttribute("style","border-collapse:collapse")),t.querySelectorAll("th, td").forEach(e=>e.setAttribute("style","border:1px solid #d0d5dd;padding:4px 8px;text-align:left;vertical-align:top")),t.innerHTML.trim()}).filter(Boolean).join("\n")}(e)))};if(o){const a=i?t.copied:t.copyAnswer;/* @__PURE__ */
|
|
90
|
+
return L(P,{children:[n&&/* @__PURE__ */z(d,{size:"sm",variant:"ghost","aria-label":a,title:a,onClick:()=>{p()},children:/* @__PURE__ */z(N,{name:i?"check":"copy",className:"h-3.5 w-3.5"})}),r?.map(t=>t.icon?/* @__PURE__ */z(d,{size:"sm",variant:"ghost","aria-label":t.label,title:t.label,onClick:()=>t.onSelect({id:e.id,text:c}),children:/* @__PURE__ */z(N,{name:t.icon,className:"h-3.5 w-3.5"})},t.key):/* @__PURE__ */z(k,{size:"sm",variant:"ghost",onClick:()=>t.onSelect({id:e.id,text:c}),children:t.label},t.key))]})}const u=[];return n&&u.push(
|
|
91
|
+
/* @__PURE__ */z(k,{size:"sm",variant:"ghost",leftIcon:/* @__PURE__ */z(N,{name:i?"check":"copy",look:"mini",className:"h-3.5 w-3.5","aria-hidden":"true"}),onClick:()=>{p()},children:i?t.copied:t.copyAnswer},"copy")),r?.forEach(t=>u.push(
|
|
92
|
+
/* @__PURE__ */z(k,{size:"sm",variant:"ghost",leftIcon:t.icon?/* @__PURE__ */z(N,{name:t.icon,look:"mini",className:"h-3.5 w-3.5","aria-hidden":"true"}):void 0,onClick:()=>t.onSelect({id:e.id,text:c}),children:t.label},t.key))),/* @__PURE__ */z("div",{className:"ml-auto flex items-center gap-0.5","data-chat-chrome":"",children:u.map((e,t)=>/* @__PURE__ */L(S,{children:[t>0&&/* @__PURE__ */z("span",{className:"flex h-3",children:/* @__PURE__ */z(a,{orientation:"vertical"})}),e]},t))})}function Ct({text:e,actions:t,files:n,labels:a,onOpenAttachment:r}){const i=s(),l=/* @__PURE__ */z("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl bg-blue-600 px-3 py-2 text-sm text-white",children:e}),c=n.length>0?/* @__PURE__ */z(wt,{files:n,labels:a,onOpen:r}):null;return t?.length?/* @__PURE__ */L("div",{className:c?"flex flex-col items-end gap-2":"flex justify-end",onContextMenu:e=>i.open(e,void 0),children:[c,l,i.state&&/* @__PURE__ */z(o,{...i.props,"aria-label":e,items:t.map(t=>({key:t.key,label:t.label,onSelect:()=>t.onSelect(e)}))})]}):c?/* @__PURE__ */L("div",{className:"flex flex-col items-end gap-2",children:[c,l]}):/* @__PURE__ */z("div",{className:"flex justify-end",children:l})}var Tt=/* @__PURE__ */new Set(["input-streaming","input-available","approval-responded"]);function St({message:a,speaker:r,toolLabels:s,labels:o,showReasoning:i,showToolOutput:l,showUsage:c,live:d,waitingSince:p,onApprove:u,plans:m,userActions:h,tableActions:f,onLinkClick:g,onOpenAttachment:x,onOpenFile:v,renderDataPart:b,showCopy:y,answerActions:w,onRate:k,onAsk:N,layout:A,selfName:C,onQuote:j}){const O=a.metadata?.source,_=T(null),R="rows"===A,$=a.metadata?.createdAt,I=a.metadata?.replyTo??null,D=(e,t)=>j&&$&&!d&&t.trim()?()=>j({id:a.id,author_name:e,excerpt:xe(t)}):void 0;if("system"===O){const e=q(a);return e?/* @__PURE__ */z("div",{className:"text-center text-xs text-gray-500",children:e}):null}if("user"===a.role){const e=q(a);if(!e)return null;const t=a.metadata?.author;if(R){const n=t?.name??(C||o.you),r=Q(a);/* @__PURE__ */
|
|
93
|
+
return L(Te,{name:n,assistant:!1,avatarUrl:t?.avatar_url,mine:!t,createdAt:$,replyTo:I,labels:o,onQuote:D(n,e),menu:t?void 0:h,menuText:e,children:[
|
|
94
|
+
/* @__PURE__ */z("div",{className:"whitespace-pre-wrap break-words",children:/* @__PURE__ */z(we,{text:e,mention:o.assistantMention})}),r.length>0&&/* @__PURE__ */z(wt,{files:r,labels:o,onOpen:x,start:!0})]})}return t?/* @__PURE__ */L("div",{className:"flex flex-col items-start gap-0.5",children:[
|
|
95
|
+
/* @__PURE__ */z("div",{className:"px-1 text-xs text-ink-faint",children:t.name}),
|
|
96
|
+
/* @__PURE__ */z("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl border border-line bg-surface px-3 py-2 text-sm text-ink shadow-sm",children:e})]}):/* @__PURE__ */z(Ct,{text:e,actions:h,files:Q(a),labels:o,onOpenAttachment:x})}const F=a.parts.map(E),M=U(a),B=[],W=/* @__PURE__ */new Set,Y=[];let H=-1;const Z=e=>{H<0&&(H=B.push(null)-1),Y.push(e)},G=function(e){return ie(e,"expires_at")}(a),X=function(e){return ie(e,"notice")}(a);a.parts.forEach((e,t)=>{if("text"===e.type)return void(e.text.trim()&&B.push(
|
|
97
|
+
/* @__PURE__ */z("div",{"data-answer-text":"",children:/* @__PURE__ */z(n,{renderFence:xt(o,d?void 0:N),tableActions:d?void 0:f,onLinkClick:g,children:e.text})},t)));if("data-file"===e.type){const t=e.data;return void(t&&"string"==typeof t.id&&!W.has(t.id)&&(W.add(t.id),B.push(/* @__PURE__ */z(Nt,{file:t,labels:o,onOpen:v},`file-${t.id}`))))}if(b&&e.type.startsWith("data-")&&!J.has(e.type)){const n=b(e,a);return void(n&&B.push(/* @__PURE__ */z(S,{children:n},`data-${t}`)))}if("reasoning"===e.type)return void(i&&e.text.trim()&&Z({kind:"reasoning",key:`r${t}`,text:e.text}));const r=F[t];r&&(vt(r,F.slice(t+1).filter(e=>null!==e))||("approval-requested"===r.state&&r.approvalId&&"propose_plan"===r.toolName?B.push(
|
|
98
|
+
/* @__PURE__ */z(mt,{approvalId:r.approvalId,plan:m?.get(r.approvalId),expiresAt:G.get(r.approvalId),input:r.input,labels:o,toolLabels:s,onApprove:u},r.toolCallId)):"approval-requested"===r.state&&r.approvalId?B.push(
|
|
99
|
+
/* @__PURE__ */z(at,{tool:r,toolLabels:s,labels:o,onApprove:u,expiresAt:G.get(r.approvalId),notice:X.get(r.approvalId)},r.toolCallId)):Z({kind:"tool",key:r.toolCallId,tool:r})))}),H>=0&&(B[H]=/* @__PURE__ */z(t,{summary:bt(Y,d,s,o),busy:d,label:o.steps,children:Y.map(t=>"tool"===t.kind?/* @__PURE__ */z(ot,{tool:t.tool,summary:M.get(t.tool.toolCallId),toolLabels:s,labels:o,showOutput:l},t.key):/* @__PURE__ */z(e,{status:"complete",label:/* @__PURE__ */L("details",{children:[
|
|
100
|
+
/* @__PURE__ */z("summary",{className:"cursor-pointer select-none",children:o.reasoning}),
|
|
101
|
+
/* @__PURE__ */z("div",{className:"mt-1 whitespace-pre-wrap text-gray-500",children:t.text})]})},t.key))},"chain"));const V=d&&function(e,t){if(t.some(e=>"approval-requested"===e?.state))return!1;let n=-1;for(let t=e.parts.length-1;t>=0;t-=1){const a=e.parts[t];if("step-start"!==a.type&&!a.type.startsWith("data-")&&("text"!==a.type||a.text.trim())){n=t;break}}if(n<0)return!0;if("text"===e.parts[n].type)return!1;const a=t[n];return!a||!Tt.has(a.state)||a}(a,F);if(V&&B.push(
|
|
102
|
+
/* @__PURE__ */z(_e,{label:!0===V?void 0:st(V,s,o).base,words:o.thinkingWords,since:p,secondsLabel:o.waitingSeconds,steadyLabel:o.thinking},"waiting")),0===B.length)return null;const K=a.metadata?.askedBy?o.askedBy.replace("{name}",a.metadata.askedBy.name):"";if(R){const e="staff"===O,t=e?o.teamName:r||o.assistantName||o.title,n=a.metadata?.run_id,s=Boolean(k&&n&&!d&&!O),i=Boolean(q(a).trim())&&(!0===y||Boolean(w?.length)),l=d||!s&&!i?null:/* @__PURE__ */L(P,{children:[s&&k&&n&&/* @__PURE__ */z(gt,{initial:a.metadata?.rating,labels:o,onRate:e=>k(n,e)}),
|
|
103
|
+
/* @__PURE__ */z(At,{message:a,labels:o,showCopy:!0===y,actions:w,answer:_,bar:!0})]});/* @__PURE__ */
|
|
104
|
+
return z(Te,{name:t,assistant:!e,createdAt:$,note:K,replyTo:I,labels:o,onQuote:D(t,q(a)),barItems:l,footer:c&&!O?/* @__PURE__ */z(yt,{message:a,live:d,labels:o}):null,children:/* @__PURE__ */z("div",{ref:_,className:"min-w-0 space-y-2",children:B})})}const ee=Boolean(r)&&!O,te=/* @__PURE__ */L("div",{ref:_,className:ee?"min-w-0 max-w-full space-y-2 rounded-2xl border border-line bg-surface px-3 py-2 text-sm text-ink shadow-sm":"min-w-0 max-w-full space-y-2 rounded-2xl bg-white px-3 py-2 text-gray-800 shadow-sm",children:["staff"===O&&/* @__PURE__ */z("div",{className:"text-xs font-medium text-blue-600",children:o.teamName}),!ee&&K&&/* @__PURE__ */z("div",{className:"text-xs text-ink-faint",children:K}),B]}),ne=ee?/* @__PURE__ */z("div",{className:"px-1 text-xs text-ink-faint",children:[r,K].filter(Boolean).join(" · ")}):null,ae=d?null:/* @__PURE__ */z(At,{message:a,labels:o,showCopy:!0===y,actions:w,answer:_}),re=c&&!O,se=a.metadata?.run_id,oe=Boolean(k&&se&&!d&&!O);/* @__PURE__ */
|
|
105
|
+
return L("div",re||oe||ae?{className:"flex w-fit min-w-0 max-w-[92%] flex-col items-stretch gap-1",children:[ne,te,
|
|
106
|
+
/* @__PURE__ */L("div",{className:"flex flex-wrap items-start gap-x-2 gap-y-1",children:[
|
|
107
|
+
/* @__PURE__ */L("div",{className:"flex min-w-0 flex-1 items-start gap-1",children:[re&&/* @__PURE__ */z(yt,{message:a,live:d,labels:o}),oe&&k&&se&&/* @__PURE__ */z(gt,{initial:a.metadata?.rating,labels:o,onRate:e=>k(se,e)})]}),ae]})]}:{className:"flex max-w-[92%] flex-col items-start gap-0.5",children:[ne,te]})}var jt={id:"pending-answer",role:"assistant",parts:[]};function Ot(e){const{messages:t,status:n,error:a,history:r,labels:s}=e,o="rows"===e.layout,l=T(null),c=$(()=>function(e){const t=/* @__PURE__ */new Map;for(const n of re(e).values())t.set(n.approval_id,n);return t}(t),[t]),d=a?me(a,e.errorCode??null,s):null,p=t[t.length-1],u="submitted"===n||"streaming"===n,[m,h]=j(void 0);O(()=>{h(e=>u?e??Date.now():void 0)},[u]);const f="ready"===n&&!a&&!e.handedOver&&"assistant"===p?.role&&!!e.onAsk,g=f?e.choices??[]:[],x=f&&0===g.length?e.followups??[]:[],v=T(null),b=T(!0),y=T(0),w=T("undefined"==typeof ResizeObserver),N=T(void 0),C=()=>{const e=l.current;e&&(e.scrollTop=e.scrollHeight)};O(()=>{const e=t[t.length-1];e&&e.id!==N.current&&(void 0===N.current||"user"===e.role&&!e.metadata?.author)&&(b.current=!0),N.current=e?.id,b.current&&C()},[t,n]),O(()=>{const e=l.current,t=v.current;if(!e||!t||"undefined"==typeof ResizeObserver)return;const n=new ResizeObserver(()=>{const t=e.clientHeight>0;t&&!w.current&&(b.current=!0),w.current=t,t&&(b.current?C():e.scrollTop=y.current)});return n.observe(e),n.observe(t),()=>n.disconnect()},[]);/* @__PURE__ */
|
|
108
|
+
return z("div",{ref:l,role:"log","aria-label":e.title,"aria-live":"polite","aria-busy":"submitted"===n||"streaming"===n,onScroll:()=>{const e=l.current;e&&0!==e.clientHeight&&w.current&&(y.current=e.scrollTop,b.current=e.scrollHeight-e.scrollTop-e.clientHeight<=48)},className:o?"min-h-0 flex-1 overflow-auto bg-surface px-2 py-3":"min-h-0 flex-1 overflow-auto bg-gray-50 p-3",children:/* @__PURE__ */L("div",{ref:v,className:o?"flex min-h-full flex-col gap-1":"flex min-h-full flex-col gap-3",children:["loading"===r&&/* @__PURE__ */L("div",{role:"status",className:"flex items-center gap-2 text-xs text-gray-500",children:[
|
|
109
|
+
/* @__PURE__ */z(A,{className:"h-3 w-3"}),s.loadingHistory]}),"failed"===r&&/* @__PURE__ */z(i,{tone:"warning",children:s.historyFailed}),0===t.length&&"idle"===r&&/* @__PURE__ */z("p",{className:"m-auto text-center text-sm text-gray-500",children:s.emptyState}),t.map((n,a)=>/* @__PURE__ */z(St,{live:a===t.length-1&&u,waitingSince:m,message:n,speaker:e.assistantName,toolLabels:e.toolLabels,labels:s,showReasoning:e.showReasoning,showToolOutput:e.showToolOutput,showUsage:e.showUsage,tableActions:e.tableActions,onApprove:e.onApprove,onLinkClick:e.onLinkClick,onOpenFile:e.onOpenFile,renderDataPart:e.renderDataPart,plans:c,userActions:e.userMessageActions,onOpenAttachment:e.onOpenAttachment,showCopy:e.showCopy,answerActions:e.answerActions,onRate:e.onRate,onAsk:e.onAsk,layout:e.layout,selfName:e.selfName,onQuote:e.onQuote},n.id)),e.onAsk&&/* @__PURE__ */z(ht,{choices:g,label:s.choices,onAnswer:e.onAsk}),e.onAsk&&/* @__PURE__ */z(ft,{questions:x,label:s.followups,onAsk:e.onAsk}),e.handedOver&&/* @__PURE__ */z("div",{role:"status",className:"text-center text-xs text-gray-500",children:s.teamJoined}),"submitted"===n&&"assistant"!==p?.role&&
|
|
110
|
+
/* @__PURE__ */z(St,{message:jt,live:!0,waitingSince:m,speaker:e.assistantName,toolLabels:e.toolLabels,labels:s,showReasoning:e.showReasoning,showToolOutput:e.showToolOutput,onApprove:e.onApprove,layout:e.layout},"pending-answer"),d&&/* @__PURE__ */L("div",{role:"alert",className:"flex flex-col items-start gap-2",children:[
|
|
111
|
+
/* @__PURE__ */z(i,{tone:"danger",children:d.text}),d.retryable&&e.onRetry&&"error"===n&&/* @__PURE__ */z(k,{size:"sm",variant:"secondary",onClick:e.onRetry,children:s.retry})]})]})})}var _t=(e,t)=>`${e.replace(/\/+$/,"")}/${t}`;function Rt(e){return _t(e,"assistant/chat/")}function $t(e,t){return _t(e,`assistant/chat/${encodeURIComponent(t)}/`)}function It(e){const t=e.metadata;return Boolean(t?.source||t?.author||t?.askedBy)}function Dt(e){return e.parts.map(e=>e.approval?.id??"").filter(Boolean).sort().join(",")}function Ft(e){const t=T(e);t.current=e;const n=T(e.conversationId?{id:e.conversationId}:null),[a,r]=j("idle"),[s,o]=j(!1),[i,l]=j(null),[c,d]=j([]),[p,u]=j([]),[m,h]=j([]),[f,g]=j(!1),[x,v]=j(!1),[b,y]=j(!1),[w,k]=j(n.current),N=R(e=>{n.current=e,k(e)},[]),A=R((e,n)=>(t.current.fetch??fetch)(e,n),[]),C=$(()=>new F({api:Rt(e.apiBase),fetch:A,prepareSendMessagesRequest:async({messages:e})=>{const{apiBase:a,getHeaders:r,credentials:s}=t.current;return{api:Rt(a),body:Z(e,n.current?.id??null),headers:await(r?.())??{},...s?{credentials:s}:{}}}}),[A]),S=B({transport:C,sendAutomaticallyWhen:M,onData:e=>{if(!J.has(e.type))return void t.current.onDataPart?.(e);if("data-error"===e.type)return void l(e.data.code);if("data-followups"===e.type)return void d(function(e){const t=e?.questions;if(!Array.isArray(t))return[];const n=[];for(const e of t){if("string"!=typeof e)continue;const t=e.trim();!t||t.includes("\n")||n.includes(t)||n.push(t)}return n.slice(0,3)}(e.data));if("data-choices"===e.type)return void u(function(e){const t=e?.choices;if(!Array.isArray(t))return[];const n=[];for(const e of t){if("string"!=typeof e)continue;const t=e.trim();!t||t.includes("\n")||n.includes(t)||n.push(t)}return n.length>=2?n.slice(0,4):[]}(e.data));if("data-conversation"!==e.type)return;const{id:a,guest_token:r}=e.data,s=n.current,o=r??(s?.id===a?s.guestToken:void 0);s&&s.id===a&&s.guestToken===o||(N(o?{id:a,guestToken:o}:{id:a}),t.current.onConversation?.(n.current))}}),{setMessages:_,stop:I}=S,D=R(async(e,n)=>{const{apiBase:a,getHeaders:s,credentials:i,onConversation:l}=t.current;r("loading"),d([]),u([]);try{const t=await A($t(a,e),{method:"GET",headers:await(s?.())??{},...i?{credentials:i}:{},signal:n});if(n.aborted)return;if(404===t.status)return N(null),l?.(null),void r("idle");if(!t.ok)throw new Error(`history ${t.status}`);const c=await t.json();if(n.aborted)return;o(!0===c.handed_over),h(c.people??[]),_(e=>e.length>0?e:le(c)),r("idle")}catch{n.aborted||r("failed")}},[A,_,N]),z=e.conversationId??null;O(()=>{if(z===(n.current?.id??null)&&S.messages.length>0)return;if(null===z)return n.current&&(N(null),I(),_([]),d([]),u([]),h([])),void r("idle");n.current?.id===z||N({id:z});const e=new AbortController;return D(z,e.signal),()=>e.abort()},[z,D,_,I,N]);const L=R(async e=>{const a=n.current?.id;if(a)try{const{apiBase:r,getHeaders:s,credentials:i}=t.current,l=await A($t(r,a),{method:"GET",headers:await(s?.())??{},...i?{credentials:i}:{},...e?{signal:e}:{}});if(!l.ok||e?.aborted||n.current?.id!==a)return;const c=await l.json();o(!0===c.handed_over),h(c.people??[]);const d=le(c),p=d.filter(It),u=d.find(e=>e.id===`pending-approvals-${a}`);if(0===p.length&&!u)return;_(e=>{const t=new Set(e.map(e=>e.id)),n=p.filter(e=>!t.has(e.id));let a=n.length>0?[...e,...n]:e;const r=new Set(a.filter(e=>e.id!==u?.id).flatMap(e=>Dt(e).split(",").filter(Boolean)));if(u&&!Dt(u).split(",").every(e=>r.has(e))){const e=a.find(e=>e.id===u.id);e?Dt(e)!==Dt(u)&&(a=[...a.filter(e=>e.id!==u.id),u]):a=[...a,u]}return a})}catch{}},[A,_]),P=T(L);P.current=L;const{status:E}=S,U="submitted"===E||"streaming"===E,W=T(!1),q=T(!1),Y=!!e.subscribe;O(()=>{const e=W.current&&!U;if(W.current=U,!e)return;if(Y&&!q.current)return;q.current=!1;const t=new AbortController;return P.current(t.signal),()=>t.abort()},[U,Y]);const Q=T(U);Q.current=U;const G=w?.id,V=w?.guestToken;O(()=>{const e=n.current,a=t.current.subscribe;if(e&&a)return a(e,()=>{Q.current?q.current=!0:P.current()})??void 0},[G,V]);const ee=R((e,t=[],n)=>{const a=e.trim();a&&(l(null),d([]),u([]),g(!1),S.sendMessage({text:a,...t.length>0?{files:t.map(H)}:{},...n?{metadata:{replyTo:n}}:{}}))},[S]),te=T(0),ne=R((e,t)=>{te.current+=1;const n=`sending-${te.current}`;return _(a=>[...a,{id:n,role:"user",parts:[{type:"text",text:e}],...t?{metadata:{replyTo:t}}:{}}]),n},[_]),ae=R(e=>_(t=>t.filter(t=>t.id!==e)),[_]),re=R(async(e,a,r)=>{const s=n.current?.id;if(!s)return;g(!1),d([]),u([]);const o=a??ne(e,r);try{const{apiBase:n,getHeaders:a,credentials:i}=t.current,l=await A(function(e,t){return _t(e,`assistant/chat/${encodeURIComponent(t)}/messages/`)}(n,s),{method:"POST",headers:{"Content-Type":"application/json",...await(a?.())??{}},body:JSON.stringify(r?{text:e,reply_to:r.id}:{text:e}),...i?{credentials:i}:{}});if(!l.ok)throw new Error(`say ${l.status}`);const c=await l.json(),[d]=le({id:s,messages:[c],pending_approvals:[]});_(e=>!d||e.some(e=>e.id===d.id)?e.filter(e=>e.id!==o):e.map(e=>e.id===o?d:e))}catch{ae(o),g(!0)}},[A,_,ne,ae]),se=R(async e=>{const a=n.current?.id;if(!a)return!1;try{const{apiBase:n,getHeaders:r,credentials:s}=t.current,o=await A(function(e,t){return _t(e,`assistant/chat/${encodeURIComponent(t)}/addressee/`)}(n,a),{method:"POST",headers:{"Content-Type":"application/json",...await(r?.())??{}},body:JSON.stringify({text:e}),...s?{credentials:s}:{}});return!!o.ok&&!0===(await o.json()).to_assistant}catch{return!1}},[A]),oe=e.mention??"",ie=e.name??"",ce=!0===e.assistantDecides,de=m.length>0,pe=R((e,t=[],n={})=>{const a=e.trim();if(!a)return;y(!1);const{replyTo:r}=n;if(!de||t.length>0||X(a,oe,ie))return void ee(a,t,r);if(!ce||n.peopleOnly)return void re(a,void 0,r);const s=ne(a,r);v(!0),se(a).then(e=>{if(!e)return y(!0),re(a,s,r);ae(s),ee(a,[],r)}).finally(()=>v(!1))},[ee,re,se,ne,ae,de,oe,ie,ce]),ue=R(e=>{y(!1),ee(de?K(e,oe):e)},[ee,de,oe]),me=R(()=>{he(S.messages)&&(l(null),d([]),u([]),S.regenerate())},[S]),fe=R((e,t)=>{l(null),d([]),u([]),S.addToolApprovalResponse({id:e,approved:t})},[S]),ge=R(()=>{I(),N(null),_([]),r("idle"),o(!1),l(null),d([]),u([]),h([]),g(!1),v(!1),y(!1),t.current.onConversation?.(null)},[_,I,N]);return{conversationId:w?.id??null,messages:S.messages,status:S.status,error:S.error,errorCode:i,canRetry:he(S.messages),retry:me,historyState:a,handedOver:s,followups:c,choices:p,people:m,sayFailed:f,deciding:x,quiet:b,send:pe,askAssistant:ue,stop:I,approve:fe,reset:ge}}function Mt(e){const t={...fe,...e.labels},n=e.variant??"panel",a=Ft({...e,mention:t.assistantMention,name:t.assistantName}),r=ee(a.people),s="submitted"===a.status||"streaming"===a.status,o=T(e.onBusyChange);o.current=e.onBusyChange,O(()=>{o.current?.(s)},[s]);const i="window"===n,l=e.showHeader??"window"!==n,c=e.title??t.title,p=se(a.messages),u=!0===e.readOnly,{onRate:m}=e,{conversationId:h}=a,f=T(!1),{send:g}=a,[x,v]=j(null);return O(()=>v(null),[h]),O(()=>{f.current||u||e.conversationId||!e.initialQuestion?.trim()||(f.current=!0,g(e.initialQuestion))},[]),/* @__PURE__ */L("section",{"aria-label":c,className:`flex h-full min-h-0 flex-col bg-white text-gray-900 ${e.className??""}`.trim(),children:[l&&/* @__PURE__ */L("header",{className:"flex items-center gap-2 border-b border-gray-200 px-3 py-2",children:[
|
|
112
|
+
/* @__PURE__ */z("h2",{className:"min-w-0 flex-1 truncate text-sm font-semibold",children:c}),a.messages.length>0&&/* @__PURE__ */z(k,{size:"sm",variant:"ghost",onClick:a.reset,children:t.newChat}),e.onClose&&/* @__PURE__ */z(d,{size:"sm","aria-label":t.close,onClick:e.onClose,children:/* @__PURE__ */z(N,{name:"close"})})]}),
|
|
113
|
+
/* @__PURE__ */L("div",{className:"flex min-h-0 flex-1",children:[
|
|
114
|
+
/* @__PURE__ */L("div",{className:"flex min-w-0 flex-1 flex-col",children:[
|
|
115
|
+
/* @__PURE__ */z(Ot,{messages:a.messages,status:a.status,error:a.error,errorCode:a.errorCode,history:a.historyState,handedOver:a.handedOver,labels:t,title:c,assistantName:r?t.assistantName||c:void 0,toolLabels:e.toolLabels,showReasoning:i&&!0===e.showReasoning,showToolOutput:i,showUsage:i&&!0===e.showUsage,tableActions:e.tableActions,onApprove:a.approve,onLinkClick:e.onLinkClick,onOpenFile:e.onOpenFile,renderDataPart:e.renderDataPart,userMessageActions:u?void 0:e.userMessageActions,showCopy:e.showCopy??i,answerActions:e.answerActions,onOpenAttachment:e.attachments?.onOpen,followups:a.followups,choices:a.choices,onAsk:u?void 0:a.askAssistant,onRetry:u?void 0:a.canRetry?a.retry:void 0,onRate:m&&h&&!u?(e,t)=>m({conversationId:h,runId:e,rating:t}):void 0,layout:e.layout,selfName:e.selfName,onQuote:u||"rows"!==e.layout?void 0:v}),p&&/* @__PURE__ */z(ut,{plan:p,labels:t},p.id),!u&&e.composerTop,!u&&a.sayFailed&&/* @__PURE__ */z("p",{role:"alert",className:"border-t border-line px-3 py-2 text-xs text-danger-text",children:t.sayFailed}),u?/* @__PURE__ */z("p",{role:"note",className:"border-t border-gray-200 px-3 py-2 text-xs text-gray-500",children:t.readOnly}):/* @__PURE__ */z(Re,{labels:t,placeholder:r?t.peoplePlaceholder.replace("{names}",r).replace("{mention}",t.assistantMention):e.placeholder??t.placeholder,people:r||void 0,assistantDecides:e.assistantDecides,deciding:a.deciding,quiet:a.quiet,onAskToReply:()=>a.askAssistant(t.askToReplyText),busy:s,focusWhen:e.focusComposer,onSend:(e,t,n)=>a.send(e,t,{peopleOnly:n.peopleOnly,replyTo:n.reply_to&&x?.id===n.reply_to?x:void 0}),quote:x,onClearQuote:()=>v(null),onStop:a.stop,onNewChat:!l&&!1!==e.showNewChat&&a.messages.length>0?a.reset:void 0,actions:e.composerActions,attachments:e.attachments})]}),i&&e.details?.open&&/* @__PURE__ */z(et,{messages:a.messages,facts:e.details.facts,toolLabels:e.toolLabels,labels:t,assistantName:t.assistantName||c,onOpenFile:e.onOpenFile,onOpenAttachment:e.attachments?.onOpen})]})]})}function zt(e){const t={...fe,...e.labels},[n,a]=j(e.defaultOpen??!1),r=_(),s=T(null),o=T(n),i=t=>{a(t),e.onOpenChange?.(t)};return O(()=>{o.current&&!n&&s.current?.focus(),o.current=n},[n]),/* @__PURE__ */L("div",{className:"rosh-assistant",style:{display:"contents"},children:[n&&/* @__PURE__ */z("div",{id:r,role:"dialog","aria-label":e.title??t.title,onKeyDown:e=>{"Escape"===e.key&&i(!1)},className:"fixed inset-x-2 bottom-20 z-[var(--z-window,1000)] h-[min(34rem,calc(100dvh-6rem))] overflow-hidden rounded-xl border border-gray-200 shadow-xl sm:inset-x-auto sm:right-4 sm:w-96",children:/* @__PURE__ */z(Mt,{...e,onClose:()=>i(!1),focusComposer:!0})}),
|
|
116
|
+
/* @__PURE__ */z("button",{ref:s,type:"button","aria-expanded":n,"aria-controls":n?r:void 0,"aria-label":n?t.close:t.open,onClick:()=>i(!n),className:"fixed bottom-4 right-4 z-[var(--z-window,1000)] flex h-12 w-12 items-center justify-center rounded-full shadow-lg bg-[var(--assistant-launcher-bg,var(--color-blue-600))] text-[var(--assistant-launcher-ink,var(--color-white))] hover:bg-[var(--assistant-launcher-bg-hover,var(--color-blue-700))] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--assistant-launcher-bg,var(--color-blue-600))]",children:/* @__PURE__ */z(N,n?{name:"close",size:20}:{name:"chat-bubble-left-right",size:22})})]})}function Lt(e){if("bubble"===e.variant)/* @__PURE__ */return z(zt,{...e});const t="window"!==e.variant;/* @__PURE__ */
|
|
117
|
+
return z(Mt,{...e,className:`${t?"border-l border-gray-200":""} ${e.className??""}`.trim()})}export{at as ApprovalCard,Lt as AssistantChat,St as AssistantMessage,fe as DEFAULT_ASSISTANT_CHAT_LABELS,we as MentionText,Te as MessageRow,J as OWN_DATA_PARTS,mt as PlanApprovalCard,ut as PlanChecklist,ge as QUOTE_EXCERPT_LENGTH,ye as QuoteBlock,Ne as QuoteChip,Ce as ReceiptTicks,be as RowAvatar,ot as ToolStep,K as addressedToAssistant,H as attachmentPart,Q as attachmentsOf,Z as buildRequestBody,Ue as compactCount,qe as estimateTokens,me as failureView,W as filesOf,Qe as finishedStats,ve as initialsOf,pe as isDroppedConnection,Je as liveStats,V as mentionSpans,X as mentionsAssistant,le as messagesFromHistory,ee as peopleNames,se as pinnedPlan,re as plansOf,xe as quoteExcerpt,Ee as summarizeChat,We as tokensPerSecond,U as toolSummariesOf};
|