blade-code 0.10.7 → 0.10.8
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/blade.js +2 -2
- package/dist/chunk-1w6azndv.js +1 -0
- package/dist/chunk-2gwaqpge.js +1 -0
- package/dist/chunk-2pjd4cys.js +1 -0
- package/dist/{chunk-vafn0spm.js → chunk-2thg3fq1.js} +1 -1
- package/dist/chunk-2zn5en0w.js +1 -0
- package/dist/{chunk-1v7hpr34.js → chunk-33ave20b.js} +1 -1
- package/dist/chunk-3w1z6fwm.js +1 -0
- package/dist/chunk-43x4qbvt.js +1 -0
- package/dist/{chunk-e9ckf8e7.js → chunk-4h9ff923.js} +1 -1
- package/dist/chunk-52csdk21.js +3 -0
- package/dist/{chunk-ahxc3n3g.js → chunk-66hb7kxm.js} +2 -2
- package/dist/chunk-6j8wgp2s.js +2 -0
- package/dist/chunk-6vsszvgg.js +2 -0
- package/dist/chunk-7evtr0yr.js +10 -0
- package/dist/{chunk-tp9zk241.js → chunk-7hbw6q6d.js} +1 -1
- package/dist/chunk-7zsyejr1.js +22 -0
- package/dist/{chunk-x3780wpy.js → chunk-8gcg2z3y.js} +16 -16
- package/dist/{chunk-p3ahf1fh.js → chunk-8gcvpmwk.js} +1 -1
- package/dist/{chunk-w01sec4f.js → chunk-8gnfj89a.js} +2 -2
- package/dist/{chunk-7a200q5g.js → chunk-8h0yxh6y.js} +2 -2
- package/dist/chunk-8sfycn3y.js +194 -0
- package/dist/{chunk-847e0sk9.js → chunk-954vmnrn.js} +1 -1
- package/dist/chunk-a8h3fymk.js +100 -0
- package/dist/chunk-b5szbtmp.js +5 -0
- package/dist/chunk-bxm2hq0m.js +1 -0
- package/dist/chunk-c8da4b3d.js +1 -0
- package/dist/{chunk-tc83e1b0.js → chunk-cbpqcdga.js} +1 -1
- package/dist/{chunk-qycwavck.js → chunk-cf8e7e92.js} +2 -2
- package/dist/{chunk-kqpwz9b7.js → chunk-d0g4t8fw.js} +2 -2
- package/dist/{chunk-1sw9z975.js → chunk-eq2qj9ja.js} +1 -1
- package/dist/{chunk-p0j8994h.js → chunk-fj8v7pep.js} +1 -1
- package/dist/{chunk-tcc3v4n2.js → chunk-fxpq9nh6.js} +1 -1
- package/dist/chunk-g00wj2we.js +4 -0
- package/dist/{chunk-3fdyzgpv.js → chunk-h28ptrrt.js} +1 -1
- package/dist/{chunk-qk2z6gag.js → chunk-h421wzbm.js} +2 -2
- package/dist/{chunk-4hhkbyja.js → chunk-j4tttsaz.js} +2 -2
- package/dist/{chunk-wrbm6rch.js → chunk-kagpk2x5.js} +2 -2
- package/dist/chunk-kvnwhwx3.js +1 -0
- package/dist/{chunk-mt4328yf.js → chunk-m2xrx1je.js} +1 -1
- package/dist/{chunk-g3wgzyhx.js → chunk-nhc49pan.js} +48 -48
- package/dist/{chunk-jpy61wna.js → chunk-nymm525r.js} +1 -1
- package/dist/{chunk-rz9yh6e4.js → chunk-nz57y1ad.js} +3 -3
- package/dist/{chunk-wmdgb5pz.js → chunk-p2m56new.js} +2 -2
- package/dist/{chunk-43j2f1b5.js → chunk-pv9sw79c.js} +1 -1
- package/dist/chunk-qgp08qmz.js +6 -0
- package/dist/{chunk-7pkrwh10.js → chunk-r7tsa2zv.js} +1 -1
- package/dist/{chunk-zjf1z27e.js → chunk-rkvfsx8e.js} +1 -1
- package/dist/{chunk-y573s5r8.js → chunk-rxqft6td.js} +2 -2
- package/dist/{chunk-rn908m3v.js → chunk-s9aj3p11.js} +2 -2
- package/dist/{chunk-0z7q89w7.js → chunk-senkwdh6.js} +1 -1
- package/dist/chunk-v1c58sm6.js +1 -0
- package/dist/{chunk-m86ekqp0.js → chunk-v8pq6qmv.js} +2 -2
- package/dist/chunk-van4ysq6.js +1466 -0
- package/dist/chunk-vgp8m9fg.js +2 -0
- package/dist/{chunk-ne7zdjrh.js → chunk-vsg8f0e6.js} +1 -1
- package/dist/{chunk-0n04bmta.js → chunk-w0nscjd2.js} +2 -2
- package/dist/chunk-w26jhcj9.js +1 -0
- package/dist/{chunk-qqwgb9ja.js → chunk-wmnszjmv.js} +2 -2
- package/dist/chunk-x6wgh726.js +1 -0
- package/dist/{chunk-yyvx1avz.js → chunk-xa05phpw.js} +3 -3
- package/dist/{chunk-0xm8hn2h.js → chunk-xmcsn7y0.js} +2 -2
- package/dist/{chunk-az4b6106.js → chunk-y4c3wwpa.js} +1 -1
- package/dist/{chunk-vcq624qv.js → chunk-yfs9tq3y.js} +2 -2
- package/dist/chunk-ymzcxryf.js +1 -0
- package/dist/{chunk-akev4wsz.js → chunk-zknv3d6y.js} +1 -1
- package/dist/chunk-zp4x2mwj.js +1 -0
- package/dist/chunk-zvk3g177.js +9 -0
- package/dist/web/assets/ChatView-Fqy97qw9.js +7 -0
- package/dist/web/assets/{CodeBlockHighlighter-CC4e9nFc.js → CodeBlockHighlighter-EgdsVoMQ.js} +1 -1
- package/dist/web/assets/{FilePreview-C3HEoLYS.js → FilePreview-xicd9-Sl.js} +1 -1
- package/dist/web/assets/{MarkdownRenderer-COycrGUX.js → MarkdownRenderer-DBSjC_z3.js} +18 -18
- package/dist/web/assets/SettingsModal-Bkh5rMAJ.js +5 -0
- package/dist/web/assets/TaskSwitcher-DXcj0iJ_.js +1 -0
- package/dist/web/assets/{TerminalPanel-DqQ-7CTG.js → TerminalPanel-DWVY-Elm.js} +1 -1
- package/dist/web/assets/index-Bi5ijAQP.css +1 -0
- package/dist/web/assets/index-CxEh32hc.js +32 -0
- package/dist/web/assets/{vendor-icons-D_AkWmWB.js → vendor-icons-Cv18Q6rW.js} +72 -67
- package/dist/web/assets/{vendor-radix-DBy9B2DN.js → vendor-radix-DXRuAJHH.js} +1 -1
- package/dist/web/index.html +4 -4
- package/package.json +3 -1
- package/dist/chunk-4rhssb85.js +0 -2
- package/dist/chunk-598egka3.js +0 -22
- package/dist/chunk-5ak9tw83.js +0 -100
- package/dist/chunk-738pkjf8.js +0 -1
- package/dist/chunk-7xfmzvxp.js +0 -1
- package/dist/chunk-867rz2ss.js +0 -1
- package/dist/chunk-a3e97syg.js +0 -3
- package/dist/chunk-f7854pbx.js +0 -187
- package/dist/chunk-fwt0kje3.js +0 -1
- package/dist/chunk-g1q27q6q.js +0 -2
- package/dist/chunk-g4snq0dx.js +0 -1
- package/dist/chunk-ggm04adj.js +0 -1
- package/dist/chunk-hpytxsge.js +0 -1
- package/dist/chunk-htr91q9c.js +0 -1
- package/dist/chunk-hwcp940f.js +0 -1
- package/dist/chunk-j5ysjbyr.js +0 -10
- package/dist/chunk-m8k1mv0j.js +0 -4
- package/dist/chunk-pt659n0v.js +0 -1466
- package/dist/chunk-q1gfeadm.js +0 -1
- package/dist/chunk-rk1w5pry.js +0 -2
- package/dist/chunk-rz2ftt6h.js +0 -5
- package/dist/chunk-tzh4ahry.js +0 -6
- package/dist/chunk-v0rn831t.js +0 -1
- package/dist/chunk-vynsgc2g.js +0 -1
- package/dist/chunk-w0ena7fe.js +0 -9
- package/dist/chunk-ydwjttdz.js +0 -1
- package/dist/chunk-z9fsh3kn.js +0 -1
- package/dist/web/assets/ChatView-BYfHmxKJ.js +0 -7
- package/dist/web/assets/McpModal-CDgr9kVq.js +0 -5
- package/dist/web/assets/SettingsModal-CvdVIbeG.js +0 -1
- package/dist/web/assets/SkillsModal-lSX1ZKTu.js +0 -1
- package/dist/web/assets/TaskSwitcher-peKi9KvN.js +0 -1
- package/dist/web/assets/index-BF5HEN_f.js +0 -32
- package/dist/web/assets/index-BrkTYxtS.css +0 -1
- package/dist/web/assets/useRequest-BvqVDnKl.js +0 -1
package/dist/chunk-q1gfeadm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Sc as a,Tc as b,Uc as c}from"./chunk-y573s5r8.js";import"./chunk-vcq624qv.js";import"./chunk-akev4wsz.js";import"./chunk-rk1w5pry.js";import"./chunk-az4b6106.js";import"./chunk-m86ekqp0.js";import"./chunk-p0j8994h.js";import"./chunk-g1q27q6q.js";import"./chunk-0n04bmta.js";import"./chunk-1v7hpr34.js";import"./chunk-ahxc3n3g.js";import"./chunk-847e0sk9.js";export{c as snapshotWorkspaceModelResources,b as resolveWorkspaceModelResources,a as cloneWorkspaceModelConfig};
|
package/dist/chunk-rk1w5pry.js
DELETED
package/dist/chunk-rz2ftt6h.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{Cd as g}from"./chunk-w01sec4f.js";import{Je as _,Le as k}from"./chunk-m86ekqp0.js";import{Oe as U}from"./chunk-p0j8994h.js";var H={openrouter:{"HTTP-Referer":"https://github.com/echoVic/blade-code","X-Title":"Blade"},cerebras:{"X-Cerebras-3rd-Party-Integration":"blade"}},v=(e)=>H[e]||{};var $=new Set(["user-cancel","interrupt","sibling-error","timeout"]);function C(e){return typeof e==="string"&&$.has(e)}function ae(e){if(!e.aborted)return;if(C(e.reason))return e.reason;return"user-cancel"}function ue(e){if(C(e))return!0;if(!(e instanceof Error))return!1;if(e.name==="AbortError")return!0;if(e instanceof DOMException&&e.name==="AbortError")return!0;if(e.message.includes("aborted"))return!0;return!1}function R(...e){let t=e.filter(Boolean);if(t.length===0)return new AbortController().signal;if(t.length===1)return t[0];let n=AbortSignal;if(typeof n.any==="function")return n.any(t);for(let i of t)if(i.aborted)return i;let r=new AbortController,o=new Map;for(let i of t){let c=()=>{r.abort(i.reason);for(let[m,s]of o)m.removeEventListener("abort",s)};o.set(i,c)}for(let[i,c]of o)i.addEventListener("abort",c,{once:!0});return r.signal}function T(e,t,n){let r=n?.throwOnAbort??!1;if(t?.aborted){if(r)return Promise.reject(new DOMException("Aborted","AbortError"));return Promise.resolve()}return new Promise((o,i)=>{let c,m=setTimeout(()=>{if(t&&c)t.removeEventListener("abort",c);o()},e);if(t)c=()=>{if(clearTimeout(m),r)i(new DOMException("Aborted","AbortError"));else o()},t.addEventListener("abort",c,{once:!0})})}var q=g("Chat"),N={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};function x(e){if(typeof e==="string")return e;return e.filter((t)=>t.type==="text").map((t)=>t.text).join(`
|
|
2
|
-
`)}function G(e){if(!e)return{};try{let t=JSON.parse(e);return t&&typeof t==="object"&&!Array.isArray(t)?t:{}}catch{return q.warn("[PiAIChatService] Invalid historical tool arguments",{value:e}),{}}}function J(e){let t=e.match(/^data:([^;,]+);base64,(.+)$/s);return t?{mimeType:t[1],data:t[2]}:void 0}async function K(e,t){let n=J(e);if(n)return{type:"image",...n};if(!/^https?:\/\//i.test(e))return{type:"text",text:`[Unsupported image source: ${e}]`};let r=await fetch(e,{signal:t});if(!r.ok)throw Error(`Failed to load image ${e}: HTTP ${r.status}`);return{type:"image",mimeType:r.headers.get("content-type")?.split(";")[0]??"image/png",data:Buffer.from(await r.arrayBuffer()).toString("base64")}}async function E(e,t,n,r,o){let i=e.filter((s)=>s.role==="system").map((s)=>x(s.content)).filter(Boolean).join(`
|
|
3
|
-
|
|
4
|
-
`),c=[];for(let s of e){if(s.role==="system")continue;if(s.role==="user"){let l=t.input.includes("image"),a=typeof s.content==="string"?s.content:await Promise.all(s.content.map((u)=>u.type==="text"?Promise.resolve({type:"text",text:u.text}):l?K(u.image_url.url,r):Promise.resolve({type:"text",text:"[Image omitted: current model does not support image input]"})));c.push({role:"user",content:a,timestamp:Date.now()});continue}if(s.role==="assistant"){let l=[];if(s.reasoningContent?.trim())l.push({type:"thinking",thinking:s.reasoningContent});let a=x(s.content);if(a)l.push({type:"text",text:a});for(let u of s.tool_calls??[]){if(!("function"in u))continue;l.push({type:"toolCall",id:u.id,name:u.function.name,arguments:G(u.function.arguments)})}c.push({role:"assistant",content:l,api:t.api,provider:t.provider,model:t.id,usage:N,stopReason:s.tool_calls?.length?"toolUse":"stop",timestamp:Date.now()});continue}c.push({role:"toolResult",toolCallId:s.tool_call_id??"",toolName:s.name??"unknown",content:[{type:"text",text:x(s.content)}],isError:!1,timestamp:Date.now()})}let m=n?.filter((s)=>!o||s.name===o).map((s)=>({name:s.name,description:s.description,parameters:s.parameters}));return{...i?{systemPrompt:i}:{},messages:c,...m?.length?{tools:m}:{}}}function I(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.role==="tool")continue;let o=r.role==="assistant"&&r.tool_calls?.length?r.tool_calls:void 0;if(!o){t.push(r);continue}let i=[],c=n+1;while(c<e.length&&e[c].role==="tool")i.push(e[c++]);let m=new Set(o.map((a)=>a.id)),s=i.filter((a)=>a.tool_call_id&&m.has(a.tool_call_id)),l=new Set(s.map((a)=>a.tool_call_id));if(m.size===o.length&&s.length===m.size&&l.size===m.size)t.push(r,...s);n=c-1}return t}function P(e){return e.some((t)=>t.role==="assistant"&&Boolean(t.tool_calls?.length)&&!t.reasoningContent?.trim())}function O(e,t){return{...e,...t.baseUrl?{baseUrl:_(e.api,t.baseUrl)}:{},...t.maxOutputTokens?{maxTokens:t.maxOutputTokens}:{}}}function M(e){let t=e.modelCatalog??k();return{models:t.models,model:O(t.getModel(e.provider,e.model),e)}}function S(e,t){let n=e.modelCatalog??k();return O(n.getModel(t.provider,t.model),e)}function L(e,t){let n=e.onPayload;e.onPayload=async(r,o)=>{let i=n?await n(r,o):r;return t(i===void 0?r:i,o)}}function X(e){if(!e.reasoningEnabled)return;return e.reasoningEffort??e.reasoningLevel??"high"}function Z(e){switch(e){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";default:return"HIGH"}}function Q(e,t,n,r){let o=r?void 0:X(n);if(!o){if(t.api==="anthropic-messages")e.thinkingEnabled=!1;if(t.api==="google-generative-ai"||t.api==="google-vertex")e.thinking={enabled:!1};return}switch(t.api){case"anthropic-messages":e.thinkingEnabled=!0,e.effort=o;break;case"google-generative-ai":case"google-vertex":e.thinking={enabled:!0,level:Z(o)};break;case"mistral-conversations":e.reasoningEffort="high";break;case"bedrock-converse-stream":case"pi-messages":e.reasoning=o;break;default:e.reasoningEffort=o}}function Y(e,t,n){if(!n)return;switch(t){case"anthropic-messages":case"bedrock-converse-stream":e.toolChoice={type:"tool",name:n};break;case"openai-completions":case"mistral-conversations":case"pi-messages":e.toolChoice={type:"function",function:{name:n}};break;case"openai-responses":case"openai-codex-responses":case"azure-openai-responses":e.toolChoice={type:"function",name:n};break;case"google-generative-ai":case"google-vertex":e.toolChoice="any";break}}function ee(e,t,n){let r=n.serviceTier;if(!r)return;if(t.api==="openai-responses"||t.api==="openai-codex-responses"||t.api==="azure-openai-responses"){e.serviceTier=r;return}if(t.api!=="openai-completions"&&!(t.api==="anthropic-messages"&&r==="fast"))return;L(e,(o)=>{if(!o||typeof o!=="object"||Array.isArray(o))return o;return t.api==="anthropic-messages"?{...o,speed:"fast"}:{...o,service_tier:r}})}function te(e,t,n){let r=n.responseVerbosity;if(!r)return;if(U(t,r),t.api==="openai-codex-responses"){e.textVerbosity=r;return}L(e,(o)=>{if(!o||typeof o!=="object"||Array.isArray(o))return o;if(t.api==="openai-completions")return{...o,verbosity:r};let i="text"in o&&o.text&&typeof o.text==="object"&&!Array.isArray(o.text)?o.text:{};return{...o,text:{...i,verbosity:r}}})}function D(e,t,n,r,o=!1){let i={apiKey:e.apiKey,headers:e.customHeaders,signal:n,temperature:r?.temperature??e.temperature??0,maxTokens:r?.maxOutputTokens??e.maxOutputTokens,timeoutMs:e.timeout,maxRetries:0,cacheRetention:e.enablePromptCaching?"short":"none"};if(Q(i,t,e,o),Y(i,t.api,r?.toolChoice?.toolName),ee(i,t,e),te(i,t,e),t.api==="azure-openai-responses")i.azureBaseUrl=e.baseUrl,i.azureApiVersion=e.apiVersion,i.azureDeploymentName=t.id;return i}function z(e){return{promptTokens:e.input+e.cacheRead+e.cacheWrite,completionTokens:e.output,totalTokens:e.totalTokens,costUsd:e.cost.total,...e.reasoning!==void 0?{reasoningTokens:e.reasoning}:{},...e.cacheWrite>0?{cacheCreationInputTokens:e.cacheWrite}:{},...e.cacheRead>0?{cacheReadInputTokens:e.cacheRead}:{}}}function y(e){if(e!==null&&typeof e==="object"&&"code"in e&&e.code==="STREAM_IDLE_TIMEOUT")return!1;let t=e instanceof Error?e.message.toLowerCase():String(e).toLowerCase();if(["prompt_too_long","prompt is too long","maximum context length","context length exceeded","context_length_exceeded","request too large"].some((o)=>t.includes(o)))return!1;if(t.match(/\b(?:status(?:\s+code)?|http)[:\s]+(408|409|429|5\d\d)\b/))return!0;return["timeout","timed out","econnreset","econnrefused","enotfound","eai_again","etimedout","fetch failed","network error","socket hang up","stream closed before completion","temporarily unavailable","upstream_error"].some((o)=>t.includes(o))}var b=300000;class W extends Error{timeoutMs;code="STREAM_IDLE_TIMEOUT";constructor(e){super(`Provider stream idle timeout after ${e}ms without an event`);this.timeoutMs=e;this.name="StreamIdleTimeoutError"}}class B extends Error{code="PROVIDER_STREAM_CLOSED";constructor(){super("Provider stream closed before completion");this.name="ProviderStreamClosedError"}}function j(e){return e.reason instanceof Error?e.reason:new DOMException("Aborted","AbortError")}function oe(e,t){let n=t.idleTimeoutMs&&t.idleTimeoutMs>0?t.idleTimeoutMs:b;if(t.signal?.aborted)return Promise.reject(j(t.signal));return new Promise((r,o)=>{let i=!1,c=()=>{clearTimeout(a),t.signal?.removeEventListener("abort",l)},m=(u)=>{if(i)return;i=!0,c(),r(u)},s=(u)=>{if(i)return;i=!0,c(),o(u)},l=()=>{if(!t.signal)return;s(j(t.signal))},a=setTimeout(()=>{if(i)return;let u=new W(n);i=!0,t.signal?.removeEventListener("abort",l),t.abort?.(u),o(u)},n);if(t.signal?.addEventListener("abort",l,{once:!0}),t.signal?.aborted){l();return}Promise.resolve().then(()=>e.next()).then(m,(u)=>s(u instanceof Error?u:Error(String(u))))})}async function*F(e,t,n,r,o={}){let c=e.stream(t,n,r)[Symbol.asyncIterator](),m=0,s=!1;try{while(!0){let l=await oe(c,o);if(l.done)throw new B;let a=l.value;switch(a.type){case"text_delta":yield{content:a.delta};break;case"thinking_delta":yield{reasoningContent:a.delta};break;case"toolcall_end":yield{toolCalls:[{index:m++,id:a.toolCall.id,type:"function",function:{name:a.toolCall.name,arguments:JSON.stringify(a.toolCall.arguments)}}]};break;case"done":s=!0,yield{finishReason:a.reason,usage:z(a.message.usage)};return;case"error":throw Error(a.error.errorMessage??`Request ${a.reason==="aborted"?"aborted":"failed"}`)}}}finally{if(!s)Promise.resolve(c.return?.()).catch(()=>{return})}}var V=g("Chat");function ne(e){return Boolean(e&&e.role==="user"&&Array.isArray(e.content)&&e.content.some((t)=>t.type==="image_url"))}class w{config;models;model;constructor(e){let t=M(e);this.config={...e,maxContextTokens:t.model.contextWindow,maxOutputTokens:e.maxOutputTokens??t.model.maxTokens},this.models=t.models,this.model=t.model,V.debug("[PiAIChatService] Initialized",{provider:this.model.provider,model:this.model.id,api:this.model.api})}async chat(e,t,n,r){let o="",i="",c=[],m,s;for await(let l of this.streamChat(e,t,n,r)){o+=l.content??"",i+=l.reasoningContent??"";for(let a of l.toolCalls??[])if(a.id&&a.type==="function"&&a.function?.name)c.push(a);m=l.usage??m,s=l.finishReason??s}return{content:o,...i?{reasoningContent:i}:{},...c.length>0?{toolCalls:c}:{},usage:m,finishReason:s}}async*streamChat(e,t,n,r){let o=r?.toolChoice?.toolName;if(o&&!t?.some((p)=>p.name===o))throw Error(`Required tool is unavailable: ${o}`);let i=I(e);if(i.some((p)=>ne(p))&&!this.model.input.includes("image"))throw Error(`${this.model.name} does not support image input`);let c=Boolean(o)||P(i),m=await E(i,this.model,t,n,o),s=(p)=>{let d=new AbortController,h=n?R(n,d.signal):d.signal;return F(this.models,p,m,D(this.config,p,h,r,c),{idleTimeoutMs:this.config.streamIdleTimeout??b,signal:h,abort:(f)=>d.abort(f)})},l=this.config.maxRetries??2,a,u=!1;for(let p=0;p<=l;p++)try{for await(let d of s(this.model))u=!0,yield d;return}catch(d){if(a=d,this.logIdleTimeout(d,u,this.model),await this.handleAbort(n),u||!y(d))throw d;if(p<l)await T(1000*2**p,n,{throwOnAbort:!0})}for(let p of this.config.fallbackModels??[]){yield{modelFallback:!0};let d=!1,h;try{h=S(this.config,p);for await(let f of s(h))d=!0,yield f;return}catch(f){if(a=f,h)this.logIdleTimeout(f,d,h);if(await this.handleAbort(n),d||!y(f))throw f}}throw a}async handleAbort(e){if(e?.aborted)await T(0,e,{throwOnAbort:!0})}logIdleTimeout(e,t,n){if(e===null||typeof e!=="object"||!("code"in e)||e.code!=="STREAM_IDLE_TIMEOUT"||!("timeoutMs"in e)||typeof e.timeoutMs!=="number")return;V.warn("[PiAIChatService] Provider stream idle timeout",{provider:n.provider,model:n.id,timeoutMs:e.timeoutMs,replayBoundaryCrossed:t})}getConfig(){return{...this.config}}updateConfig(e){let t={...this.config,...e},n=M(t);this.config={...t,maxContextTokens:n.model.contextWindow,maxOutputTokens:t.maxOutputTokens??n.model.maxTokens},this.models=n.models,this.model=n.model}}var re=g("Service");async function Se(e){let t=e;if(t.provider){let n=v(t.provider);if(Object.keys(n).length>0)t={...t,customHeaders:{...n,...t.customHeaders}},re.debug(`Injected ${t.provider} specific headers:`,Object.keys(n))}return ie(t)}function ie(e){return new w(e)}
|
|
5
|
-
export{ae as Ic,ue as Jc,R as Kc,w as Lc,Se as Mc};
|
package/dist/chunk-tzh4ahry.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{m as Zq,n as $q,o as Gq,p as Vq}from"./chunk-m8k1mv0j.js";import{r as Yq}from"./chunk-7a200q5g.js";import{E as r,G as s,H as a,J as k,K as o}from"./chunk-pt659n0v.js";import"./chunk-rn908m3v.js";import{Aa as l,Da as v,Oa as i}from"./chunk-f7854pbx.js";import"./chunk-jpy61wna.js";import{Bb as S}from"./chunk-5ak9tw83.js";import"./chunk-wrbm6rch.js";import{Ub as t}from"./chunk-4rhssb85.js";import{Wb as e,Xb as qq,Yb as Qq}from"./chunk-rz9yh6e4.js";import{Zb as n}from"./chunk-wmdgb5pz.js";import"./chunk-0xm8hn2h.js";import{xc as u}from"./chunk-x3780wpy.js";import"./chunk-tp9zk241.js";import"./chunk-3fdyzgpv.js";import"./chunk-rz2ftt6h.js";import"./chunk-qqwgb9ja.js";import"./chunk-1sw9z975.js";import"./chunk-y573s5r8.js";import"./chunk-qycwavck.js";import"./chunk-0z7q89w7.js";import"./chunk-ne7zdjrh.js";import"./chunk-e9ckf8e7.js";import"./chunk-yyvx1avz.js";import"./chunk-tc83e1b0.js";import"./chunk-w01sec4f.js";import"./chunk-vcq624qv.js";import{qe as d,re as p,te as q,ue as F,we as j,xe as m}from"./chunk-akev4wsz.js";import"./chunk-rk1w5pry.js";import{Ge as x}from"./chunk-az4b6106.js";import"./chunk-m86ekqp0.js";import"./chunk-p0j8994h.js";import"./chunk-g1q27q6q.js";import"./chunk-0n04bmta.js";import"./chunk-1v7hpr34.js";import"./chunk-ahxc3n3g.js";import"./chunk-847e0sk9.js";import lq from"yargs";import{hideBin as vq}from"yargs/helpers";var w=1;function B(Z){return q.Object({event_version:q.Literal(w),...Z})}var bq=B({type:q.Literal("content_delta"),delta:q.String()}),Aq=B({type:q.Literal("thinking_delta"),delta:q.String()}),Hq=B({type:q.Literal("thinking"),content:q.String()}),zq=B({type:q.Literal("stream_end")}),Rq=B({type:q.Literal("content"),content:q.String()}),T=j(["readonly","write","execute"]),Mq=B({type:q.Literal("tool_start"),tool_name:q.String(),summary:q.String(),target:q.Optional(q.String()),tool_kind:q.Optional(T)}),Eq=B({type:q.Literal("tool_progress"),tool_name:q.String(),message:q.String(),progress:q.Optional(q.Number()),total:q.Optional(q.Number())}),Pq=B({type:q.Literal("tool_result"),tool_name:q.String(),summary:q.String(),target:q.Optional(q.String()),tool_kind:q.Optional(T),success:q.Optional(q.Boolean()),error_type:q.Optional(q.String()),error_message:q.Optional(q.String())}),Nq=B({type:q.Literal("mcp_catalog_changed"),revision:q.Integer({minimum:1}),server_name:q.String(),added:q.Array(q.String()),removed:q.Array(q.String()),updated:q.Array(q.String())}),fq=B({type:q.Literal("mcp_content_changed"),revision:q.Integer({minimum:1}),server_name:q.String(),content_kind:j(["resources","resource_templates","prompts"]),added:q.Array(q.String()),removed:q.Array(q.String()),updated:q.Array(q.String())}),xq=B({type:q.Literal("mcp_resource_updated"),revision:q.Integer({minimum:1}),server_name:q.String(),uri:q.String()}),Lq=B({type:q.Literal("mcp_connection_changed"),revision:q.Integer({minimum:1}),server_name:q.String(),phase:j(["reconnecting","recovered","failed"]),reason:q.String(),attempt:q.Integer({minimum:0}),max_attempts:q.Integer({minimum:0}),next_retry_at:q.Optional(q.Integer({minimum:0})),error:q.Optional(q.String())}),Iq=B({type:q.Literal("mcp_log"),revision:q.Integer({minimum:1}),server_name:q.String(),level:j(["debug","info","notice","warning","error","critical","alert","emergency"]),logger:q.Optional(q.String()),message:q.String(),projected_bytes:q.Integer({minimum:0}),data_sha256:q.String(),truncated:q.Boolean(),details_omitted:q.Boolean(),timestamp:q.Integer({minimum:0}),synthetic:q.Optional(q.Boolean())}),Jq=B({type:q.Literal("mcp_instructions_changed"),revision:q.Integer({minimum:0}),server_name:q.String(),action:j(["added","removed"]),reason:j(["snapshot","connection","disconnection"]),text:q.Optional(q.String()),source_bytes:q.Optional(q.Integer({minimum:0})),projected_bytes:q.Optional(q.Integer({minimum:0})),sha256:q.Optional(q.String()),truncated:q.Optional(q.Boolean()),details_omitted:q.Optional(q.Boolean())}),Wq=B({type:q.Literal("mcp_task_changed"),revision:q.Integer({minimum:0}),task_id:q.String(),server_name:q.String(),tool_name:q.String(),status:j(["working","input_required","interrupted","completed","failed","cancelled"]),status_message:q.Optional(q.String()),created_at:q.Integer({minimum:0}),updated_at:q.Integer({minimum:0}),completed_at:q.Optional(q.Integer({minimum:0})),has_result:q.Boolean(),error:q.Optional(q.String())}),Sq=B({type:q.Literal("project_rules_loaded"),files:q.Array(q.Object({id:q.String(),relative_path:q.String(),source:j(["project","local"]),conditional:q.Boolean(),content_sha256:q.String({pattern:"^[a-f0-9]{64}$"})})),trigger_paths:q.Array(q.String()),blocked_write:q.Boolean()}),Oq=B({type:q.Literal("user_shell_started"),execution_id:q.String(),command:q.String(),auxiliary:q.Boolean()}),hq=B({type:q.Literal("user_shell_output"),execution_id:q.String(),stream:j(["stdout","stderr"]),chunk:q.String(),stream_truncated:q.Boolean()}),Cq=B({type:q.Literal("user_shell_completed"),execution_id:q.String(),message_id:q.String(),status:j(["completed","failed","aborted","timed_out","spawn_error"]),exit_code:q.Union([q.Integer(),q.Null()]),duration_ms:q.Number({minimum:0}),stdout:q.String(),stderr:q.String(),truncated:q.Boolean(),auxiliary:q.Boolean()}),Fq=B({type:q.Literal("phase"),phase:j(["turn","searching","inspecting","target_hit","executing","completed"]),status:j(["ongoing","hit","done"]),message:q.String(),turn:q.Optional(q.Number()),tool_name:q.Optional(q.String()),target:q.Optional(q.String())}),kq=B({type:q.Literal("tool_detail"),tool_name:q.String(),detail:q.String()}),wq=B({type:q.Literal("task_update"),tasks:q.Array(k)}),Tq=B({type:q.Literal("subagent"),state:j(["spawned","completed"]),session_id:q.String(),subagent_type:q.Optional(q.String()),success:q.Optional(q.Boolean()),summary:q.Optional(q.String()),verification_verdict:q.Optional(j(["pass","fail","partial"])),resumed_from:q.Optional(q.String()),root_agent_id:q.Optional(q.String()),resume_depth:q.Optional(q.Integer({minimum:0}))}),yq=B({type:q.Literal("token_usage"),input_tokens:q.Number(),output_tokens:q.Number(),total_tokens:q.Number(),max_context_tokens:q.Number(),cache_read_tokens:q.Optional(q.Number()),cache_write_tokens:q.Optional(q.Number()),cost_usd:q.Optional(q.Number())}),gq=B({type:q.Literal("compacting"),state:j(["started","completed"])}),cq=B({type:q.Literal("turn_limit"),turns_count:q.Number(),action:q.Literal("continue")}),dq=B({type:q.Literal("task_session"),session_id:q.String(),project_path:q.String(),source_project_path:q.String(),isolation:j(["local","worktree"]),worktree_branch:q.Optional(q.String()),base_commit:q.Optional(q.String())}),pq=B({type:q.Literal("task_admission"),state:j(["queued","running"]),queue_position:q.Optional(q.Integer({minimum:1})),queue_depth:q.Integer({minimum:0}),in_flight:q.Integer({minimum:0}),max_concurrent_tasks:q.Integer({minimum:1})}),mq=B({type:q.Literal("output"),content:q.String(),exit_code:q.Number()}),uq=B({type:q.Literal("error"),message:q.String()}),XQ=F(q.Union([bq,Aq,Hq,zq,Rq,Mq,Eq,Pq,Nq,fq,xq,Lq,Iq,Jq,Wq,Sq,Oq,hq,Cq,Fq,kq,wq,Tq,yq,gq,cq,dq,pq,mq,uq]));function y(Z,$){return{event_version:w,type:Z,...$}}function iq(Z){if(Z?.signal)return{signal:Z.signal,dispose:()=>{return}};let $=new AbortController,G=()=>$.abort("interrupt");return process.once("SIGINT",G),process.once("SIGTERM",G),{signal:$.signal,dispose:()=>{process.removeListener("SIGINT",G),process.removeListener("SIGTERM",G)}}}var rq=j(["text","jsonl"]),sq=q.Object({headless:q.Optional(q.Boolean()),message:q.Optional(q.String()),_:q.Optional(q.Array(q.Union([q.String(),q.Number()]))),model:q.Optional(q.String()),systemPrompt:q.Optional(q.String()),appendSystemPrompt:q.Optional(q.String()),maxTurns:q.Optional(q.Refine(q.Integer({maximum:m}),(Z)=>Z===-1||Z>0,()=>"must be -1 or a positive integer")),permissionMode:q.Optional(q.Enum(d)),mcpConfig:q.Optional(q.Array(q.String())),strictMcpConfig:q.Optional(q.Boolean()),sessionId:q.Optional(q.String()),allowedTools:q.Optional(q.Array(q.String())),disallowedTools:q.Optional(q.Array(q.String())),agents:q.Optional(q.String()),continue:q.Optional(q.Boolean()),resume:q.Optional(q.Union([q.String(),q.Boolean()])),forkSession:q.Optional(q.Boolean()),taskIsolation:q.Optional(j(["local","worktree"])),outputFormat:q.Optional(rq)});class Xq{openedThinking=!1;wroteAssistantContent=!1;markAssistantContent(){this.wroteAssistantContent=!0}setThinkingOpened(Z){this.openedThinking=Z}hasOpenThinking(){return this.openedThinking}completeStream(){let Z={openedThinking:this.openedThinking,wroteAssistantContent:this.wroteAssistantContent};return this.openedThinking=!1,this.wroteAssistantContent=!1,Z}}function aq(Z){return Z.issues.map(($)=>`${$.path.join(".")||"options"}: ${$.message}`).join("; ")}function oq(Z){let $=p(sq,Z);if(!$.success)throw Error(`Invalid headless options: ${aq($.error)}`);return $.data}function nq(Z){return Z.command("* [message]","Run full agent loop without Ink UI and print events to the terminal",($)=>$.positional("message",{describe:"Message to process",type:"string"}).option("headless",{type:"boolean",describe:"Run full agent loop without Ink UI and print events to the terminal"}).option("model",{describe:"Model ID for this run",type:"string"}).option("system-prompt",{describe:"Replace the default system prompt",type:"string"}).option("append-system-prompt",{describe:"Append a system prompt to the default system prompt",type:"string"}).option("max-turns",{alias:["maxTurns"],describe:"Maximum conversation turns (-1: unlimited, N>0: limit to N turns)",type:"number"}).option("output-format",{alias:["outputFormat"],choices:["text","jsonl"],describe:"Headless output format",type:"string"}).option("task-isolation",{alias:["taskIsolation"],choices:["local","worktree"],describe:"Dispatch a new durable task in the selected workspace mode",type:"string"}),async($)=>{if(!$.headless)return;let G=await ZQ($);process.exit(G)})}function _(Z,$=""){Z.write(`${$}
|
|
2
|
-
`)}function tq(Z){return`[task] [${Z.status}] ${Z.subject}`}function eq(){return{requestConfirmation:async(Z)=>Z.type==="mcpElicitation"?{approved:!1,reason:"headless-mcp-elicitation-unavailable",elicitation:{action:"cancel"}}:Z.type==="mcpSampling"?{approved:!1,reason:"headless-mcp-sampling-unavailable"}:{approved:!0,reason:"headless-auto-approved",scope:"session"}}}function qQ(Z){if(!(Z instanceof Error))return"Unknown error";let Q=Z.lastError??Z;if(Q.responseBody)try{let K=JSON.parse(Q.responseBody)?.error?.message;if(K)return Q.statusCode?`${K} (HTTP ${Q.statusCode})`:K}catch{}let Y=Z.message.match(/Last error:\s*(.+)$/);if(Y)return Y[1];return Z.message}function QQ(Z){return Z==="jsonl"?"jsonl":"text"}function g(Z,$){let G=(...Q)=>{for(let Y of Q){let U=$[Y];if(typeof U==="string"&&U.trim()!=="")return U}return};switch(Z){case"Read":case"Edit":case"Write":case"UndoEdit":return G("file_path");case"ApplyPatch":return"multi-file patch";case"NotebookEdit":return G("notebook_path");case"Grep":return G("path","pattern");case"Glob":return G("pattern");case"WebFetch":return G("url");case"WebSearch":return G("query");case"Bash":return G("command","description");case"Task":return G("description");case"LSP":return G("filePath","operation");case"EnterWorktree":return G("name");case"ExitWorktree":return G("action");default:return}}function YQ(Z,$,G,Q){let Y=new Set(["Glob","Grep","WebSearch","LS"]),U=new Set(["Read","WebFetch"]);if(new Set(["Edit","Write","ApplyPatch","NotebookEdit","Bash","LSP","UndoEdit","EnterWorktree","ExitWorktree"]).has(Z)&&!Q.targetLocked)return{phase:"target_hit",status:"hit",message:`Target locked: ${$}`,shouldLockTarget:!0};if(Q.targetLocked)return{phase:"executing",status:"hit",message:G?`Working within target: ${$}`:`Executing: ${$}`,shouldLockTarget:!1};if(Y.has(Z))return{phase:"searching",status:"ongoing",message:`Still searching: ${$}`,shouldLockTarget:!1};if(U.has(Z))return{phase:"inspecting",status:"ongoing",message:`Inspecting candidate: ${$}`,shouldLockTarget:!1};return{phase:"executing",status:Q.targetLocked?"hit":"ongoing",message:`Executing: ${$}`,shouldLockTarget:!1}}function c(Z,$){let G=(Q,Y)=>{Z.stdout.write(`${JSON.stringify(y(Q,Y))}
|
|
3
|
-
`)};return{contentDelta(Q){if($==="jsonl"){G("content_delta",{delta:Q});return}Z.stdout.write(Q)},thinkingDelta(Q,Y){if($==="jsonl")return G("thinking_delta",{delta:Q}),Y;if(!Y)Z.stderr.write("[thinking] ");return Z.stderr.write(Q),!0},thinking(Q){if($==="jsonl"){G("thinking",{content:Q});return}_(Z.stderr,`[thinking] ${Q}`)},streamEnd(Q,Y){if($==="jsonl"){G("stream_end",{});return}if(Y)Z.stderr.write(`
|
|
4
|
-
`);if(Q)Z.stdout.write(`
|
|
5
|
-
`)},content(Q){if($==="jsonl"){G("content",{content:Q});return}_(Z.stdout,Q)},toolStart(Q,Y,U,K){if($==="jsonl"){G("tool_start",{tool_name:Q,summary:Y,target:U,tool_kind:K});return}_(Z.stderr,`[tool:start] ${Y}`)},toolProgress(Q,Y,U,K){if($==="jsonl"){G("tool_progress",{tool_name:Q,message:Y,progress:U,total:K});return}_(Z.stderr,`[tool:progress] ${Q}: ${Y}`)},toolResult(Q,Y,U,K,A){if($==="jsonl"){G("tool_result",{tool_name:Q,summary:Y,target:U,tool_kind:K,success:A?.success,error_type:A?.errorType,error_message:A?.errorMessage});return}_(Z.stderr,`[tool:result] ${Y}`)},mcpCatalogChanged(Q){if($==="jsonl"){G("mcp_catalog_changed",{revision:Q.revision,server_name:Q.serverName,added:Q.added,removed:Q.removed,updated:Q.updated});return}_(Z.stderr,`[mcp:catalog] r${Q.revision} ${Q.serverName} +${Q.added.length} -${Q.removed.length} ~${Q.updated.length}`)},mcpContentChanged(Q){if($==="jsonl"){G("mcp_content_changed",{revision:Q.revision,server_name:Q.serverName,content_kind:Q.contentKind==="resourceTemplates"?"resource_templates":Q.contentKind,added:Q.added,removed:Q.removed,updated:Q.updated});return}_(Z.stderr,`[mcp:${Q.contentKind}] r${Q.revision} ${Q.serverName} +${Q.added.length} -${Q.removed.length} ~${Q.updated.length}`)},mcpResourceUpdated(Q){if($==="jsonl"){G("mcp_resource_updated",{revision:Q.revision,server_name:Q.serverName,uri:Q.uri});return}_(Z.stderr,`[mcp:resource] r${Q.revision} ${Q.serverName} updated ${Q.uri}`)},mcpConnectionChanged(Q){if($==="jsonl"){G("mcp_connection_changed",{revision:Q.revision,server_name:Q.serverName,phase:Q.phase,reason:Q.reason,attempt:Q.attempt,max_attempts:Q.maxAttempts,...Q.nextRetryAt!==void 0?{next_retry_at:Q.nextRetryAt}:{},...Q.error?{error:Q.error}:{}});return}_(Z.stderr,`[mcp:connection] r${Q.revision} ${Q.serverName} ${Q.phase} ${Q.attempt}/${Q.maxAttempts}`)},mcpLog(Q){if($==="jsonl"){G("mcp_log",{revision:Q.revision,server_name:Q.serverName,level:Q.level,logger:Q.logger,message:Q.message,projected_bytes:Q.projectedBytes,data_sha256:Q.dataSha256,truncated:Q.truncated,details_omitted:Q.detailsOmitted,timestamp:Q.timestamp,synthetic:Q.synthetic});return}_(Z.stderr,`[mcp:log] ${Q.level} ${Q.serverName}${Q.logger?` logger=${Q.logger}`:""}: ${Q.message}`)},mcpInstructionsChanged(Q){if($==="jsonl"){G("mcp_instructions_changed",{revision:Q.revision,server_name:Q.serverName,action:Q.action,reason:Q.reason,text:Q.text,source_bytes:Q.sourceBytes,projected_bytes:Q.projectedBytes,sha256:Q.sha256,truncated:Q.truncated,details_omitted:Q.detailsOmitted});return}_(Z.stderr,`[mcp:instructions] ${Q.action} ${Q.serverName}${Q.truncated?" (truncated)":""}`)},mcpTaskChanged(Q){if($==="jsonl"){G("mcp_task_changed",{revision:Q.revision,task_id:Q.taskId,server_name:Q.serverName,tool_name:Q.toolName,status:Q.status,status_message:Q.statusMessage,created_at:Q.createdAt,updated_at:Q.updatedAt,completed_at:Q.completedAt,has_result:Q.hasResult,error:Q.error});return}_(Z.stderr,`[mcp:task] ${Q.taskId} ${Q.serverName}/${Q.toolName} `+Q.status)},projectRulesLoaded(Q){if($==="jsonl"){G("project_rules_loaded",{files:Q.files.map((Y)=>({id:Y.id,relative_path:Y.relativePath,source:Y.source,conditional:Y.conditional,content_sha256:Y.contentSha256})),trigger_paths:Q.triggerPaths,blocked_write:Q.blockedWrite});return}_(Z.stderr,`[project-rules] loaded ${Q.files.length} file(s)${Q.blockedWrite?" before write":""}`)},userShellStarted(Q,Y,U){if($==="jsonl"){G("user_shell_started",{execution_id:Q,command:Y,auxiliary:U});return}_(Z.stderr,`[user-shell:start] ${Y}`)},userShellOutput(Q,Y,U,K){if($==="jsonl"){G("user_shell_output",{execution_id:Q,stream:Y,chunk:U,stream_truncated:K});return}(Y==="stderr"?Z.stderr:Z.stdout).write(U)},userShellCompleted(Q){if($==="jsonl"){G("user_shell_completed",{execution_id:Q.executionId,message_id:Q.messageId,status:Q.record.status,exit_code:Q.record.exitCode,duration_ms:Q.record.durationMs,stdout:Q.record.stdout,stderr:Q.record.stderr,truncated:Q.record.truncated,auxiliary:Q.auxiliary});return}_(Z.stderr,`[user-shell:${Q.record.status}] exit=${Q.record.exitCode??"null"} ${Q.record.durationMs}ms`)},phase(Q,Y,U,K={}){if($==="jsonl"){G("phase",{phase:Q,status:Y,message:U,turn:K.turn,tool_name:K.toolName,target:K.target});return}_(Z.stderr,`[phase:${Q}] ${U}`)},toolDetail(Q,Y){if($==="jsonl"){G("tool_detail",{tool_name:Q,detail:Y});return}_(Z.stderr,Y)},taskUpdate(Q){if($==="jsonl"){G("task_update",{tasks:Q});return}for(let Y of Q)_(Z.stderr,tq(Y))},subagent(Q){let Y=Q.kind==="subagent_spawned";if($==="jsonl"){G("subagent",{state:Y?"spawned":"completed",session_id:Q.sessionId,subagent_type:Q.type,success:Y?void 0:Q.success,summary:Y?void 0:Q.summary,verification_verdict:Y?void 0:Q.verificationVerdict,resumed_from:Q.resumedFrom,root_agent_id:Q.rootAgentId,resume_depth:Q.resumeDepth});return}_(Z.stderr,`[subagent:${Y?"spawned":"completed"}] ${Q.sessionId}${Q.resumedFrom?` resumed from ${Q.resumedFrom}`:""}`)},tokenUsage(Q){if($==="jsonl"){G("token_usage",{input_tokens:Q.inputTokens,output_tokens:Q.outputTokens,total_tokens:Q.totalTokens,max_context_tokens:Q.maxContextTokens,cache_read_tokens:Q.cacheReadTokens,cache_write_tokens:Q.cacheWriteTokens,cost_usd:Q.costUsd});return}_(Z.stderr,`[tokens] in=${Q.inputTokens} out=${Q.outputTokens} total=${Q.totalTokens} / ${Q.maxContextTokens}`)},compacting(Q){if($==="jsonl"){G("compacting",{state:Q?"started":"completed"});return}_(Z.stderr,Q?"[context] compacting started":"[context] compacting completed")},turnLimit(Q){if($==="jsonl"){G("turn_limit",{turns_count:Q,action:"continue"});return}_(Z.stderr,`[turn-limit] continuing after ${Q} turns`)},taskSession(Q){if($==="jsonl"){G("task_session",{session_id:Q.sessionId,project_path:Q.projectPath,source_project_path:Q.sourceProjectPath,isolation:Q.isolation,worktree_branch:Q.worktreeBranch,base_commit:Q.baseCommit});return}_(Z.stderr,`[task:${Q.isolation}] ${Q.sessionId} ${Q.sourceProjectPath} -> ${Q.projectPath}${Q.worktreeBranch?` (${Q.worktreeBranch})`:""}`)},taskAdmission(Q){if($==="jsonl"){G("task_admission",{state:Q.state,queue_position:Q.queuePosition,queue_depth:Q.queueDepth,in_flight:Q.inFlight,max_concurrent_tasks:Q.maxConcurrentTasks});return}_(Z.stderr,Q.state==="queued"?`[task:queued] position ${Q.queuePosition??1}/${Q.queueDepth} (running ${Q.inFlight}/${Q.maxConcurrentTasks})`:`[task:running] admitted (running ${Q.inFlight}/${Q.maxConcurrentTasks})`)},output(Q,Y=0){if($==="jsonl"){G("output",{content:Q,exit_code:Y});return}_(Y===0?Z.stdout:Z.stderr,Q)},error(Q){if($==="jsonl"){G("error",{message:Q});return}_(Z.stderr,Q)}}}async function ZQ(Z,$={stdout:process.stdout,stderr:process.stderr},G){let Q="text",Y=c($,Q),U=new Xq,K={targetLocked:!1},A,P,L=iq(G);try{let D=oq(Z);Q=QQ(D.outputFormat),Y=c($,Q),await Zq();let Dq=await $q(D),H=await Gq(Dq);if(H.mode==="output"){if(H.content)Y.output(H.content,H.exitCode??0);return H.exitCode??0}let J=H.content.trimStart().startsWith("!")?H.content.trimStart().slice(1).trim():void 0;if(J!==void 0&&D.taskIsolation)throw Error("User shell commands cannot be combined with --task-isolation");if(D.taskIsolation&&(D.continue||D.resume||D.forkSession))throw Error("--task-isolation cannot be combined with --continue, --resume, or --fork-session");let{sessionId:z,messages:O,metadata:h}=await Vq({sessionId:D.sessionId,continue:D.continue,resume:D.resume,forkSession:D.forkSession,fallbackSessionPrefix:"headless"}),N=D.permissionMode??h?.permissionMode??"yolo",C=D.model&&D.model!=="inherit"?D.model:u()?.id,b=D.taskIsolation?await Yq.createSessionTask({sessionId:z,prompt:H.content,sourceProjectPath:x(),isolation:D.taskIsolation,dispatch:{version:1,prompt:H.content,sourceProjectPath:x(),isolation:D.taskIsolation,permissionMode:N,...C?{modelId:C}:{}}}):void 0,R=b?.metadata.projectPath??h?.projectPath??x();if(!b)await S.setSessionPermissionMode(z,R,N);let Bq=b?!1:await i.cancelPendingNonInteractive(R,z);if(b)Y.taskSession({sessionId:z,projectPath:R,sourceProjectPath:b.metadata.taskSourceProjectPath??x(),isolation:D.taskIsolation,worktreeBranch:b.metadata.taskWorktreeBranch,baseCommit:b.metadata.taskBaseCommit}),P=v.subscribe((V)=>{if(V.type!=="task.status"||V.sessionId!==z||V.projectPath!==R||!["queued","running"].includes(String(V.properties.taskStatus))||typeof V.properties.taskQueueDepth!=="number"||typeof V.properties.taskInFlight!=="number"||typeof V.properties.taskConcurrencyLimit!=="number")return;Y.taskAdmission({state:V.properties.taskStatus,queuePosition:typeof V.properties.taskQueuePosition==="number"?V.properties.taskQueuePosition:void 0,queueDepth:V.properties.taskQueueDepth,inFlight:V.properties.taskInFlight,maxConcurrentTasks:V.properties.taskConcurrencyLimit})});let Uq={messages:Bq?await S.loadSession(z,R):[...O],userId:"cli-user",sessionId:z,workspaceRoot:R,permissionMode:N,signal:L.signal,...b?.taskWorktree?{worktreeActive:!0}:{},confirmationHandler:eq()};if(A=await r.create({sessionId:z,workspaceRoot:R,modelId:D.model,permissionMode:N,mcpConfig:D.mcpConfig,strictMcpConfig:D.strictMcpConfig,agents:D.agents?n(D.agents):void 0,...b?.taskWorktree?{taskWorktree:b.taskWorktree}:{},...b?.metadata.taskIsolation?{taskIsolation:b.metadata.taskIsolation}:{},...O.length>0?{sessionStart:{isResume:!0,resumeSessionId:z}}:{}}),J!==void 0){let V=await A.executeUserShellCommand(J,{signal:L.signal,onEvent:(X)=>{if(X.type==="started")Y.userShellStarted(X.executionId,X.command,X.auxiliary);else if(X.type==="output")Y.userShellOutput(X.executionId,X.stream,X.chunk,X.streamTruncated)}});return Y.userShellCompleted(V),V.record.status==="completed"?0:V.record.status==="aborted"?130:V.record.exitCode??1}let _q=D.maxTurns??A.getConfig().maxTurns,Kq=b?.taskWorktree?[...new Set([...D.disallowedTools??[],"EnterWorktree","ExitWorktree"])]:D.disallowedTools,jq=await o.createWithRuntime(A,{sessionId:z,systemPrompt:D.systemPrompt,appendSystemPrompt:D.appendSystemPrompt,maxTurns:D.maxTurns,modelId:D.model,permissionMode:N,toolWhitelist:D.allowedTools,toolBlacklist:Kq,mcpConfig:D.mcpConfig,strictMcpConfig:D.strictMcpConfig}),W=await l(jq.chatStream(H.content,Uq,{stream:!0,signal:L.signal,maxTurns:D.maxTurns,..._q===-1?{onTurnLimitReached:async(V)=>{return Y.turnLimit(V.turnsCount),{continue:!0,reason:"headless-auto-continue"}}}:{}}),async(V)=>{switch(V.kind){case"content_delta":U.markAssistantContent(),Y.contentDelta(V.delta);break;case"thinking_delta":U.setThinkingOpened(Y.thinkingDelta(V.delta,U.hasOpenThinking()));break;case"stream_end":{let X=U.completeStream();Y.streamEnd(X.wroteAssistantContent,X.openedThinking);break}case"tool_start":{let X=V.toolCall;if(!("function"in X))break;if(["TaskCreate","TaskUpdate","TaskList"].includes(X.function.name))break;try{let M=JSON.parse(X.function.arguments),E=s(X.function.name,M),f=g(X.function.name,M),I=YQ(X.function.name,E,f,K);if(I.shouldLockTarget)K.targetLocked=!0;Y.phase(I.phase,I.status,I.message,{toolName:X.function.name,target:f}),Y.toolStart(X.function.name,E,f,V.toolKind)}catch{Y.phase(K.targetLocked?"executing":"searching",K.targetLocked?"hit":"ongoing",K.targetLocked?`Working within target: ${X.function.name}`:`Still searching: ${X.function.name}`,{toolName:X.function.name}),Y.toolStart(X.function.name,X.function.name,void 0,V.toolKind)}break}case"tool_progress":{let X=V.toolCall;if(!("function"in X))break;Y.toolProgress(X.function.name,V.update.message,V.update.progress,V.update.total);break}case"tool_result":{let X=V.toolCall;if(!("function"in X))break;let M;try{let f=JSON.parse(X.function.arguments);M=g(X.function.name,f)}catch{M=void 0}let E=a(X.function.name,V.result);if(Y.toolResult(X.function.name,E.summary,M,void 0,{success:V.result.success,errorType:V.result.error?.type,errorMessage:V.result.error?.message}),E.detail)Y.toolDetail(X.function.name,E.detail);break}case"token_usage":Y.tokenUsage(V.usage);break;case"compaction":Y.compacting(V.phase==="start");break;case"task_update":Y.taskUpdate(V.tasks);break;case"mcp_catalog_changed":Y.mcpCatalogChanged(V);break;case"mcp_content_changed":Y.mcpContentChanged(V);break;case"mcp_resource_updated":Y.mcpResourceUpdated(V);break;case"mcp_connection_changed":Y.mcpConnectionChanged(V);break;case"mcp_log":Y.mcpLog(V);break;case"mcp_instructions_changed":Y.mcpInstructionsChanged(V);break;case"mcp_task_changed":Y.mcpTaskChanged(V);break;case"project_rules_loaded":Y.projectRulesLoaded(V);break;case"steering_applied":case"follow_up_started":case"goal_updated":case"goal_continuation_started":break;case"subagent_spawned":case"subagent_completed":Y.subagent(V);break;case"model_fallback":break;case"turn_start":if(V.turn===1)K.targetLocked=!1;Y.phase("turn",K.targetLocked?"hit":"ongoing",`Turn ${V.turn} started`,{turn:V.turn});break;default:{let X=V}}});if(W.metadata?.outputTruncated)Y.error("[warning] 输出因达到 token 上限被截断,部分内容可能不完整。");if(!W.success)return Y.error(`Error: ${W.error?.message??"Agent execution failed"}`),1;return Y.phase("completed","done","Headless run completed"),0}catch(D){if(U.hasOpenThinking()&&Q==="text")$.stderr.write(`
|
|
6
|
-
`);return Y.error(`Error: ${qQ(D)}`),1}finally{P?.();try{await A?.dispose()}finally{L.dispose()}}}async function OQ(){if(!process.argv.slice(2).includes("--headless"))return!1;let{headless:G,"output-format":Q,"system-prompt":Y,"append-system-prompt":U,"max-turns":K,...A}=t,P=lq(vq(process.argv)).scriptName("blade").strict(!1).options(A).middleware([qq,e,Qq]);return nq(P),await P.parse(),!0}export{ZQ as runHeadless,OQ as handleHeadlessMode,sq as HeadlessOptionsSchema};
|
package/dist/chunk-v0rn831t.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Nc as a,Oc as b,Pc as c}from"./chunk-qqwgb9ja.js";import"./chunk-1sw9z975.js";import"./chunk-m86ekqp0.js";import"./chunk-p0j8994h.js";import"./chunk-ahxc3n3g.js";import"./chunk-847e0sk9.js";export{b as resolveModelConfig,c as getModelDisplayName,a as getModelApiKeyEnvironmentVariable};
|
package/dist/chunk-vynsgc2g.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Aa as f,Ea as g,Fa as h,Ga as i,Ha as j,Ia as k,Pa as l,Qa as m,Ra as n,Sa as o,Ta as p,Ua as q,Va as r,ua as a,va as b,xa as c,ya as d,za as e}from"./chunk-f7854pbx.js";import"./chunk-jpy61wna.js";import"./chunk-5ak9tw83.js";import"./chunk-wrbm6rch.js";import"./chunk-3fdyzgpv.js";import"./chunk-rz2ftt6h.js";import"./chunk-1sw9z975.js";import"./chunk-0z7q89w7.js";import"./chunk-ne7zdjrh.js";import"./chunk-yyvx1avz.js";import"./chunk-tc83e1b0.js";import"./chunk-w01sec4f.js";import"./chunk-akev4wsz.js";import"./chunk-rk1w5pry.js";import"./chunk-az4b6106.js";import"./chunk-m86ekqp0.js";import"./chunk-p0j8994h.js";import"./chunk-g1q27q6q.js";import"./chunk-1v7hpr34.js";import"./chunk-ahxc3n3g.js";import"./chunk-847e0sk9.js";export{g as saveUserMessage,i as saveToolUse,j as saveToolResult,k as saveCompaction,h as saveAssistantMessage,d as isRootSystemPrompt,m as handleTaskListUpdate,n as handleSkillActivation,o as extractModelSwitch,r as executeLoopGenerator,f as drainLoop,c as checkStopHook,a as checkOutputRecovery,b as checkIncompleteIntent,q as checkAndCompactInLoop,p as applyToolDomainEffects,l as StreamingToolExecutor,e as ConversationState};
|
package/dist/chunk-w0ena7fe.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{m as y,n as w,o as z,p as P}from"./chunk-m8k1mv0j.js";import{E as D,K as E}from"./chunk-pt659n0v.js";import"./chunk-rn908m3v.js";import{Aa as A,Oa as $}from"./chunk-f7854pbx.js";import"./chunk-jpy61wna.js";import{Bb as X,tb as f}from"./chunk-5ak9tw83.js";import"./chunk-wrbm6rch.js";import{Ub as h}from"./chunk-4rhssb85.js";import{Wb as x,Xb as k,Yb as O}from"./chunk-rz9yh6e4.js";import{Zb as N}from"./chunk-wmdgb5pz.js";import"./chunk-0xm8hn2h.js";import{uc as _}from"./chunk-x3780wpy.js";import"./chunk-tp9zk241.js";import"./chunk-3fdyzgpv.js";import"./chunk-rz2ftt6h.js";import"./chunk-qqwgb9ja.js";import"./chunk-1sw9z975.js";import"./chunk-y573s5r8.js";import"./chunk-qycwavck.js";import"./chunk-0z7q89w7.js";import"./chunk-ne7zdjrh.js";import"./chunk-e9ckf8e7.js";import"./chunk-yyvx1avz.js";import"./chunk-tc83e1b0.js";import"./chunk-w01sec4f.js";import"./chunk-vcq624qv.js";import{qe as L}from"./chunk-akev4wsz.js";import"./chunk-rk1w5pry.js";import{Ge as U}from"./chunk-az4b6106.js";import"./chunk-m86ekqp0.js";import"./chunk-p0j8994h.js";import"./chunk-g1q27q6q.js";import"./chunk-0n04bmta.js";import"./chunk-1v7hpr34.js";import"./chunk-ahxc3n3g.js";import"./chunk-847e0sk9.js";import M from"yargs";import{hideBin as C}from"yargs/helpers";var I=new Set(Object.values(L));function S(j){if(j&&I.has(j))return j;return}function c(j){return j.command("* [message]","Print response and exit (useful for pipes)",(q)=>q.positional("message",{describe:"Message to process",type:"string"}).option("p",{alias:"print",describe:"Print response and exit (useful for pipes)",type:"boolean"}).option("output-format",{describe:'Output format: "text", "json", "stream-json"',type:"string",default:"text"}).option("include-partial-messages",{describe:"Include partial message chunks as they arrive",type:"boolean"}).option("input-format",{describe:'Input format: "text", "stream-json"',type:"string",default:"text"}).option("model",{describe:"Model for the current session",type:"string"}).option("append-system-prompt",{describe:"Append a system prompt to the default system prompt",type:"string"}).option("system-prompt",{describe:"Replace the default system prompt",type:"string"}).option("max-turns",{alias:["maxTurns"],describe:"Maximum conversation turns (-1: unlimited, N>0: limit to N turns)",type:"number"}),async(q)=>{if(!q.p)return;let B=await v(q);process.exit(B)})}async function v(j,q=process){let B;try{await y();let Q=await w({message:j.message,_:j._,defaultMessage:"Hello"}),K=await z(Q);if(K.mode==="output"){if(K.content)q.stdout.write(`${K.content}
|
|
2
|
-
`);return K.exitCode??0}let T=K.content,Y=T.trimStart().startsWith("!")?T.trimStart().slice(1).trim():void 0,{sessionId:G,messages:b,metadata:V}=await P({sessionId:j.sessionId,continue:j.continue,resume:j.resume,forkSession:j.forkSession,fallbackSessionPrefix:"print"}),H=V?.projectPath??U(),W=S(j.permissionMode)??V?.permissionMode??_()?.permissionMode??"default";await X.setSessionPermissionMode(G,H,W);let F=await $.cancelPendingNonInteractive(H,G)?await X.loadSession(G,H):b;if(B=await D.create({sessionId:G,workspaceRoot:H,modelId:j.model,permissionMode:W,mcpConfig:j.mcpConfig,strictMcpConfig:j.strictMcpConfig,agents:j.agents?N(j.agents):void 0,...F.length>0?{sessionStart:{isResume:!0,resumeSessionId:G}}:{}}),Y!==void 0){let J=await B.executeUserShellCommand(Y);if(j.outputFormat==="json")q.stdout.write(`${JSON.stringify(J,null,2)}
|
|
3
|
-
`);else if(j.outputFormat==="stream-json")q.stdout.write(`${JSON.stringify({type:"user_shell_completed",executionId:J.executionId,record:J.record})}
|
|
4
|
-
`);else q.stdout.write(`${f(J.record)}
|
|
5
|
-
`);return J.record.status==="completed"?0:J.record.status==="aborted"?130:J.record.exitCode??1}let R=await E.createWithRuntime(B,{sessionId:G,systemPrompt:j.systemPrompt,appendSystemPrompt:j.appendSystemPrompt,maxTurns:j.maxTurns,modelId:j.model,permissionMode:W,toolWhitelist:j.allowedTools,toolBlacklist:j.disallowedTools,mcpConfig:j.mcpConfig,strictMcpConfig:j.strictMcpConfig}),Z=(await A(R.chatStream(T,{messages:[...F],userId:"cli-user",sessionId:G,workspaceRoot:H,permissionMode:W}))).finalMessage||"";if(j.outputFormat==="json")q.stdout.write(`${JSON.stringify({response:Z,input:T,model:j.model,timestamp:new Date().toISOString()},null,2)}
|
|
6
|
-
`);else if(j.outputFormat==="stream-json")q.stdout.write(`${JSON.stringify({type:"response",content:Z})}
|
|
7
|
-
`);else q.stdout.write(`${Z}
|
|
8
|
-
`);return 0}catch(Q){return q.stderr.write(`Error: ${Q instanceof Error?Q.message:"未知错误"}
|
|
9
|
-
`),1}finally{await B?.dispose()}}async function Hj(){if(process.argv.slice(2).findIndex((B)=>B==="--print"||B==="-p")===-1)return!1;try{let{print:B,"output-format":Q,"include-partial-messages":K,"input-format":T,"system-prompt":Y,"append-system-prompt":G,"max-turns":b,...V}=h,H=M(C(process.argv)).scriptName("blade").strict(!1).options(V).middleware([k,x,O]);return c(H),await H.parse(),!0}catch(B){console.error(`Print mode error: ${B instanceof Error?B.message:"未知错误"}`),process.exit(1)}}export{v as runPrint,Hj as handlePrintMode};
|
package/dist/chunk-ydwjttdz.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ub as a,Vb as b}from"./chunk-4rhssb85.js";import"./chunk-g1q27q6q.js";import"./chunk-847e0sk9.js";export{a as globalOptions,b as cliConfig};
|
package/dist/chunk-z9fsh3kn.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{h as a,i as b,j as c,k as d,l as e}from"./chunk-mt4328yf.js";import"./chunk-847e0sk9.js";export{b as setSkipUntilVersion,d as performUpgrade,c as getUpgradeCommand,e as checkVersionOnStartup,a as checkVersion};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-COycrGUX.js","assets/index-BF5HEN_f.js","assets/vendor-react-DG5dkZ_t.js","assets/vendor-radix-DBy9B2DN.js","assets/vendor-icons-D_AkWmWB.js","assets/index-BrkTYxtS.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as h,j as e}from"./vendor-react-DG5dkZ_t.js";import{u as M,a as N,b as ae,s as je,c as $e,d as z,D as ye,e as we,f as _e,g as Ne,h as Se,i as Ce,j as A,k as O,l as Pe,B as re,m as Le,n as Ve,o as Oe,_ as He,S as Ue,p as Ke,t as qe,q as ze,C as Ge,r as We}from"./index-BF5HEN_f.js";import{O as xe,N as Qe,G as Je,V as Ye,L as F,z as Xe,T as J,C as ne,Y as Ze,v as et,Z as tt,_ as st,y as X,m as ie,R as oe,s as rt,H as at,$ as Ee,Q as nt,a0 as it,a1 as ot,a2 as lt,P as Te,a3 as ct,X as dt,a4 as ut,a5 as mt,f as Ae,a6 as xt,W as ht,a as pt}from"./vendor-icons-D_AkWmWB.js";import{j as ft,k as bt,l as gt,m as Fe}from"./vendor-radix-DBy9B2DN.js";function he(t){return t.split("/").filter(Boolean).at(-1)||t}function vt(){const t=M(),s=N(C=>C.sessions),r=N(C=>C.currentSessionRef),a=N(C=>C.taskDeliveryActions),c=N(C=>C.deliverTask),i=ae(C=>C.openFilePreview),[d,p]=h.useState(!1),l=s.find(C=>je({sessionId:C.sessionId,projectPath:C.projectPath},r));if(!(l!=null&&l.taskIsolation))return null;const n=l.taskDiffStat,j=l.taskIsolation==="worktree",o=$e(l),u=a[z(o)],x=l.taskDelivery,y=(x==null?void 0:x.status)==="conflicted",f=!!(n&&(n.changedFiles>0||n.commits>0)),k=!["queued","running"].includes(l.taskStatus),w=(x==null?void 0:x.status)==="applied"||(x==null?void 0:x.status)==="discarded",b=j&&f&&k&&!w,m=n?n.additions+n.deletions:0,g=m>0&&n?n.additions/m*100:0,S=C=>{c(o,C).catch(()=>{})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-10 flex-wrap items-center gap-x-3 gap-y-1.5 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/60 px-3 py-1.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:px-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx(xe,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:he(l.taskSourceProjectPath||l.projectPath)})]}),e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[j?e.jsx(Qe,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(xe,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:j?"text-[hsl(var(--deck-accent))]":void 0,children:t(j?"artifact.env.isolated":"artifact.env.local")})]}),l.taskWorktreeBranch&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 truncate",title:l.taskWorktreeBranch,children:[e.jsx(Je,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:l.taskWorktreeBranch})]})]})]}),n&&e.jsxs("div",{className:"ml-auto flex max-w-full items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(Ye,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:n.changedFiles})]}),m>0&&e.jsxs("span",{className:"relative hidden h-1.5 w-14 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:inline-flex","aria-hidden":"true",children:[e.jsx("span",{className:"h-full bg-[hsl(var(--deck-accent))]",style:{width:`${g}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-g}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",n.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",n.deletions]}),n.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:n.commits})}),f&&(x==null?void 0:x.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:()=>i({tab:"diff"}),className:"inline-flex items-center gap-1 rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-2 py-1 text-[hsl(var(--deck-ink))] transition hover:border-[hsl(var(--deck-accent)/0.55)] hover:text-[hsl(var(--deck-accent))]",children:t("artifact.review")}),b&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!u,onClick:()=>S("apply"),className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2 py-1 font-semibold text-white transition hover:brightness-95 disabled:cursor-wait disabled:opacity-65",children:[u==="apply"?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(Xe,{className:"h-3 w-3"}),t(u==="apply"?"artifact.applying":y?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!u,onClick:()=>p(!0),className:"inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[hsl(var(--deck-ink-faint))] transition hover:bg-red-500/10 hover:text-red-600 disabled:cursor-wait disabled:opacity-50 dark:hover:text-red-400","aria-label":t("artifact.discard"),title:t("artifact.discard"),children:u==="discard"?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(J,{className:"h-3 w-3"})})]}),(x==null?void 0:x.status)==="applied"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/10 px-2 py-1 font-semibold text-emerald-700 dark:text-emerald-300",children:[e.jsx(ne,{className:"h-3 w-3"}),t("artifact.applied")]}),(x==null?void 0:x.status)==="discarded"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-surface-2))] px-2 py-1 text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(J,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(x==null?void 0:x.status)==="conflicted"&&e.jsxs("div",{className:"flex w-full items-start gap-1.5 border-t border-amber-500/20 pt-1.5 text-amber-700 dark:text-amber-300",role:"alert",children:[e.jsx(Ze,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsx("span",{className:"block",children:x.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(ye,{open:d,onOpenChange:p,children:e.jsxs(we,{className:"w-[calc(100%_-_2rem)] max-w-md border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] text-[hsl(var(--deck-ink))]",children:[e.jsxs(_e,{children:[e.jsx(Ne,{children:t("artifact.discardDialog.title")}),e.jsx(Se,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:he(l.taskSourceProjectPath||l.projectPath),count:(n==null?void 0:n.changedFiles)??0})})]}),e.jsx("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-xs leading-relaxed text-red-700 dark:text-red-300",children:t("artifact.discardDialog.warning")}),e.jsxs(Ce,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>p(!1),className:"rounded-md border border-[hsl(var(--deck-border))] px-3 py-2 text-sm hover:bg-[hsl(var(--deck-surface-2))]",children:t("artifact.discardDialog.cancel")}),e.jsxs("button",{type:"button",onClick:()=>{p(!1),S("discard")},className:"inline-flex items-center justify-center gap-1.5 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white hover:bg-red-700",children:[e.jsx(J,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}const kt=new Set(["completed","stale","failed","aborted","interrupted"]),jt={completed:"chat.review.status.completed",stale:"chat.review.status.stale",failed:"chat.review.status.failed",aborted:"chat.review.status.aborted",interrupted:"chat.review.status.interrupted"},yt={completed:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/20",stale:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20",failed:"bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/20",aborted:"bg-zinc-500/10 text-zinc-700 dark:text-zinc-300 border-zinc-500/20",interrupted:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20"};function Y(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function wt(t){const s=Y(t),r=Y(s==null?void 0:s.codeLocation),a=s==null?void 0:s.priority,c=s==null?void 0:s.confidenceScore,i=r==null?void 0:r.lineStart,d=r==null?void 0:r.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||a!==0&&a!==1&&a!==2&&a!==3||typeof c!="number"||!Number.isFinite(c)||typeof(r==null?void 0:r.path)!="string"||!Number.isInteger(i)||!Number.isInteger(d)))return{title:s.title,body:s.body,priority:a,confidenceScore:c,codeLocation:{path:r.path,lineStart:i,lineEnd:d}}}function Nt(t){const s=Y(t),r=Y(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!kt.has(s.status)||typeof(r==null?void 0:r.label)!="string"||r.kind!=="uncommitted"&&r.kind!=="base"&&r.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const a=s.findings.map(wt);if(!a.some(c=>c===void 0))return{status:s.status,target:{kind:r.kind,label:r.label,...typeof r.reference=="string"?{reference:r.reference}:{}},overallExplanation:s.overallExplanation,findings:a,...typeof s.error=="string"?{error:s.error}:{}}}function St(t){const{path:s,lineStart:r,lineEnd:a}=t.codeLocation;return r===a?`${s}:L${r}`:`${s}:L${r}-${a}`}function Ct({report:t}){const s=M(),r=t.target.kind==="uncommitted"?s("chat.review.target.uncommitted"):t.target.kind==="base"?s("chat.review.target.base",{ref:t.target.reference??t.target.label}):s("chat.review.target.commit",{ref:t.target.reference??t.target.label});return e.jsxs("section",{"data-code-review-report":!0,className:"overflow-hidden rounded-xl border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface-2))]/60 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.review.title")}),e.jsxs("p",{className:"mt-0.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-faint))]",children:[s("chat.review.target"),": ",r]})]}),e.jsxs("span",{className:A("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",yt[t.status]),children:[s("chat.review.status"),": ",s(jt[t.status])]})]}),e.jsxs("div",{className:"space-y-4 px-4 py-3.5",children:[e.jsx("p",{className:"whitespace-pre-wrap text-[13px] leading-6 text-[hsl(var(--deck-ink-muted))]",children:t.overallExplanation}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("h4",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.findings")}),e.jsx("span",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:t.findings.length})]}),t.findings.length===0?e.jsx("div",{className:"rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2.5 text-[12px] text-[hsl(var(--deck-ink-muted))]",children:s("chat.review.noFindings")}):e.jsx("ol",{className:"space-y-2",children:t.findings.map((a,c)=>e.jsxs("li",{className:"rounded-lg border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))] px-3 py-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsx("h5",{className:"text-[12.5px] font-medium leading-5 text-[hsl(var(--deck-ink))]",children:a.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:a.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:St(a)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:a.body})]},`${a.codeLocation.path}:${a.codeLocation.lineStart}:${c}`))})]}),t.error&&e.jsxs("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-[11px] text-red-700 dark:text-red-300",children:[e.jsxs("span",{className:"font-medium",children:[s("chat.review.error"),":"]})," ",t.error]})]})]})}function Et({elicitation:t,messageId:s}){const r=M(),a=N(b=>b.currentSessionRef),c=N(b=>b.setElicitation),[i,d]=h.useState(()=>At(t.details.fields??[])),[p,l]=h.useState(()=>Ft(t.details.fields??[])),[n,j]=h.useState(!1),[o,u]=h.useState(),x=t.details.fields??[],y=h.useMemo(()=>x.every(b=>{var g;if(!b.required)return!0;if(Z(b))return!!((g=p[b.name])!=null&&g.trim()||b.defaultValue!==void 0);const m=i[b.name]??b.defaultValue;return Array.isArray(m)?m.length>0:m!==void 0}),[x,p,i]);if(t.status!=="pending")return e.jsx("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:r(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const f=async(b,m)=>{if(!(!a||n)){j(!0),u(void 0);try{await O.respondToElicitation(a,t.toolCallId,{action:b,...m?{content:m}:{}}),c(s,{...t,status:"responded"})}catch(g){u(g instanceof Error?g.message:r("interaction.elicitation.failed"))}finally{j(!1)}}},k=async()=>{try{await f("accept",Rt(x,i,p))}catch(b){u(b instanceof Error?b.message:String(b))}},w=()=>{const b=t.details.url;if(!b){u("MCP URL is unavailable");return}if(!window.open(b,"_blank","noopener,noreferrer")){u("The browser blocked the external window");return}f("accept")};return e.jsxs("div",{"data-pending-interaction":"elicitation",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(et,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"font-mono text-[12px] font-semibold text-[hsl(var(--deck-ink))]",children:[r("interaction.elicitation.title")," · ",t.details.serverName]}),e.jsx("div",{className:"font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:t.details.message}),e.jsx("div",{className:"font-mono text-[11px] text-amber-700 dark:text-amber-300",children:r("interaction.elicitation.warning")})]})]}),t.details.mode==="url"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] p-3 font-mono text-[11px]",children:[e.jsx("div",{className:"text-[hsl(var(--deck-ink-muted))]",children:t.details.domain}),e.jsx("div",{className:"mt-1 break-all text-[hsl(var(--deck-ink))]",children:t.details.url})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(U,{onClick:w,disabled:n,primary:!0,label:r("interaction.elicitation.open"),icon:e.jsx(tt,{className:"h-3.5 w-3.5"})}),e.jsx(U,{onClick:()=>void f("decline"),disabled:n,label:r("interaction.elicitation.decline")}),e.jsx(U,{onClick:()=>void f("cancel"),disabled:n,label:r("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[x.map(b=>e.jsx(Tt,{field:b,value:i[b.name],rawValue:p[b.name]??"",onValueChange:m=>d(g=>({...g,[b.name]:m})),onRawChange:m=>l(g=>({...g,[b.name]:m}))},b.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(U,{onClick:()=>void k(),disabled:n||!y,primary:!0,label:r("interaction.elicitation.submit"),icon:n?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(U,{onClick:()=>void f("decline"),disabled:n,label:r("interaction.elicitation.decline")}),e.jsx(U,{onClick:()=>void f("cancel"),disabled:n,label:r("interaction.elicitation.cancel")})]})]}),o&&e.jsx("div",{className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:o})]})}function Tt({field:t,value:s,rawValue:r,onValueChange:a,onRawChange:c}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{htmlFor:`mcp-elicitation-${t.name}`,className:"block font-mono text-[12px] font-medium text-[hsl(var(--deck-ink))]",children:[t.title,t.required?" *":""]}),t.description&&e.jsx("div",{className:"font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:t.description}),t.type==="select"||t.type==="multi-select"||t.type==="boolean"?e.jsx("div",{id:`mcp-elicitation-${t.name}`,className:"flex flex-wrap gap-2",children:Mt(t).map(i=>{const d=Array.isArray(s)?s.includes(i.value):s===i.typedValue;return e.jsx("button",{type:"button","aria-pressed":d,onClick:()=>{if(t.type==="multi-select"){const p=Array.isArray(s)?s:[];a(p.includes(i.value)?p.filter(l=>l!==i.value):[...p,i.value])}else a(i.typedValue)},className:A("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",d?"border-emerald-500 bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-200":"border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:i.label},i.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Dt(t),value:r,onChange:i=>c(i.target.value),min:t.minimum,max:t.maximum,minLength:t.minLength,maxLength:t.maxLength,required:t.required,placeholder:t.defaultValue===void 0?t.required?"Required":"Optional":String(t.defaultValue),className:"w-full rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink))] outline-none transition-colors focus:border-amber-500 focus:ring-1 focus:ring-amber-500"})]})}function U({onClick:t,disabled:s,primary:r=!1,label:a,icon:c}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:A("inline-flex min-h-8 items-center gap-1.5 rounded-md px-3 py-1.5 font-mono text-[12px] transition-colors disabled:cursor-wait disabled:opacity-50",r?"bg-amber-600 text-white hover:bg-amber-700":"border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:[c,a]})}function At(t){return Object.fromEntries(t.filter(s=>!Z(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function Ft(t){return Object.fromEntries(t.filter(s=>Z(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Rt(t,s,r){var c;const a={};for(const i of t){if(Z(i)){const p=((c=r[i.name])==null?void 0:c.trim())??"";if(!p){if(i.defaultValue!==void 0)a[i.name]=i.defaultValue;else if(i.required)throw new Error(`${i.title} is required`);continue}if(i.type==="number"||i.type==="integer"){const l=Number(p);if(!Number.isFinite(l))throw new Error(`${i.title} must be a finite number`);if(i.type==="integer"&&!Number.isSafeInteger(l))throw new Error(`${i.title} must be a safe integer`);a[i.name]=l}else a[i.name]=p;continue}const d=s[i.name]??i.defaultValue;if(d===void 0){if(i.required)throw new Error(`${i.title} is required`);continue}if(Array.isArray(d)){if(i.minItems!==void 0&&d.length<i.minItems)throw new Error(`${i.title} requires at least ${i.minItems} choices`);if(i.maxItems!==void 0&&d.length>i.maxItems)throw new Error(`${i.title} allows at most ${i.maxItems} choices`)}a[i.name]=d}return a}function Mt(t){return t.type==="boolean"?[{value:"true",label:"Yes",typedValue:!0},{value:"false",label:"No",typedValue:!1}]:(t.options??[]).map(s=>({...s,typedValue:s.value}))}function Z(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Dt(t){return t.type==="number"||t.type==="integer"?"number":t.format==="email"?"email":t.format==="uri"?"url":t.format==="date"?"date":t.format==="date-time"?"datetime-local":"text"}const It=h.lazy(()=>He(()=>import("./MarkdownRenderer-COycrGUX.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.MarkdownRenderer})));function pe({text:t,label:s}){const[r,a]=h.useState(!1);if(!t.trim())return null;const c=async()=>{try{await navigator.clipboard.writeText(t),a(!0),window.setTimeout(()=>a(!1),1400)}catch{}};return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:c,className:"flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:r?e.jsx(ne,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(st,{className:"h-3.5 w-3.5"})})}function Bt(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] shadow-[0_1px_0_hsl(var(--deck-hairline))]",children:e.jsx(re,{size:20,pulse:!1})})}function $t(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-full border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas-veil))]",children:e.jsx("span",{className:"font-mono text-[11px] font-medium text-[hsl(var(--deck-ink))]",children:"U"})})}function fe(t){let s=t;return s=s.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g,""),s=s.replace(/<file path="[^"]*">[\s\S]*?<\/file>/g,""),s=s.replace(/<attached_files>[\s\S]*?<\/attached_files>/g,""),s=s.trim(),s}function _t(t){if(typeof t=="string")return{text:fe(t),images:[]};const s=t.filter(a=>a.type==="text").map(a=>a.text).join(`
|
|
3
|
-
`),r=t.filter(a=>a.type==="image_url").map(a=>a.image_url.url);return{text:fe(s),images:r}}function le(t){return typeof t=="string"?t:t.filter(s=>s.type==="text").map(s=>s.text).join(`
|
|
4
|
-
`)}function Pt(t){const s=t.agentContent;return s?Pe(s):le(t.content)}function be({content:t,syntaxHighlight:s=!0}){return e.jsx(h.Suspense,{fallback:e.jsx("pre",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono whitespace-pre-wrap",children:t}),children:e.jsx(It,{content:t,syntaxHighlight:s})})}function ce({status:t}){if(!t)return null;const s={running:"bg-[#FEF3C7] text-[#92400E] dark:bg-[#F59E0B]/20 dark:text-[#FBBF24]",success:"bg-[#DCFCE7] text-[#15803D] dark:bg-[#22C55E]/20 dark:text-[#22C55E]",error:"bg-[#FEE2E2] text-[#b91c1c] dark:bg-[#EF4444]/20 dark:text-[#fca5a5]",pending:"bg-[#E5E7EB] text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]",info:"bg-[#DBEAFE] text-[#1D4ED8] dark:bg-[#3B82F6]/20 dark:text-[#60A5FA]"},r={running:"Running",success:"Success",error:"Error",pending:"Pending",info:"Info"};return e.jsx("span",{className:A("text-[11px] px-2 py-0.5 rounded-full font-mono",s[t]),children:r[t]})}function Lt(t){if(!t)return"";if(typeof t=="string")try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}return JSON.stringify(t,null,2)}function Vt({tool:t}){const[s,r]=h.useState(!1),a=Lt(t.arguments);return e.jsxs("div",{className:"bg-white dark:bg-[#18181b] border border-[hsl(var(--deck-border))] rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button","aria-expanded":s,"data-tool-call-id":t.toolCallId,onClick:()=>r(c=>!c),className:"w-full flex items-center justify-between px-3 py-2 bg-[hsl(var(--deck-surface-2))] hover:bg-[hsl(var(--deck-surface))] transition-colors",children:[e.jsxs("div",{className:"flex gap-2 items-center min-w-0",children:[s?e.jsx(X,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}):e.jsx(ie,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}),e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink))] font-mono shrink-0",children:t.toolName}),t.summary&&e.jsx("span",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono truncate",children:t.summary})]}),e.jsx(ce,{status:t.status})]}),t.status==="running"&&t.progressMessage&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx("span",{className:"truncate",children:t.progressMessage}),t.progressTotal!==void 0&&t.progress!==void 0&&e.jsxs("span",{className:"shrink-0",children:[Math.max(0,Math.min(100,Math.round(t.progress/t.progressTotal*100))),"%"]})]}),t.progressTotal!==void 0&&t.progress!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${t.toolName} progress`,"aria-valuemin":0,"aria-valuemax":t.progressTotal,"aria-valuenow":Math.min(t.progress,t.progressTotal),className:"h-1 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,t.progress/t.progressTotal*100))}%`}})})]}),s&&e.jsxs("div",{className:"px-3 py-2 space-y-2 border-t border-[hsl(var(--deck-border))]",children:[a&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:"Arguments"}),e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:a})]}),t.output&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:"Output"}),e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:t.output.length>500?t.output.slice(0,500)+"...":t.output})]})]})]})}function Re({toolCalls:t}){return t.length===0?null:e.jsx("div",{className:"space-y-2",children:t.map(s=>e.jsx(Vt,{tool:s},s.toolCallId))})}function Ot({toolCalls:t,toolCallIds:s}){const r=M(),[a,c]=h.useState(!1),i=h.useMemo(()=>new Map(t.map(o=>[o.toolCallId,o])),[t]),d=s.flatMap(o=>{const u=i.get(o);return u?[u]:[]});if(d.length===0)return null;const p=d.filter(o=>o.status==="running").length,l=d.filter(o=>o.status==="error").length,n=[...d].reverse().find(o=>o.status==="running"&&!!o.progressMessage),j=p>0?r(d.length===1?"chat.timeline.tools.runningOne":"chat.timeline.tools.running",{count:d.length}):l>0?r(d.length===1?"chat.timeline.tools.completedOneWithError":"chat.timeline.tools.completedWithErrors",{count:d.length,errors:l}):r(d.length===1?"chat.timeline.tools.completedOne":"chat.timeline.tools.completed",{count:d.length});return e.jsxs("div",{"data-agent-tool-group":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>c(o=>!o),className:"group flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[a?e.jsx(X,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(ie,{className:"h-3.5 w-3.5 shrink-0"}),p>0&&e.jsx(F,{className:"h-3 w-3 shrink-0 animate-spin text-[hsl(var(--deck-accent))]"}),e.jsx("span",{children:j}),(n==null?void 0:n.progressMessage)&&e.jsxs("span",{className:"min-w-0 truncate text-[10.5px] text-[hsl(var(--deck-ink-muted))]",children:[n.progressMessage,n.progress!==void 0&&n.progressTotal!==void 0&&` · ${Math.max(0,Math.min(100,Math.round(n.progress/n.progressTotal*100)))}%`]})]}),(n==null?void 0:n.progress)!==void 0&&n.progressTotal!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${n.toolName} progress`,"aria-valuemin":0,"aria-valuemax":n.progressTotal,"aria-valuenow":Math.min(n.progress,n.progressTotal),className:"mx-1.5 h-0.5 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,n.progress/n.progressTotal*100))}%`}})}),a&&e.jsx("div",{"data-agent-tool-group-details":!0,className:"mt-2 space-y-2 pl-1",children:e.jsx(Re,{toolCalls:d})})]})}function Ht({content:t}){const s=M(),[r,a]=h.useState(!1);return t?e.jsxs("div",{"data-agent-thinking":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>a(c=>!c),className:"flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[r?e.jsx(X,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}):e.jsx(ie,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{children:s("chat.timeline.thinking")})]}),r&&e.jsx("div",{className:"ml-1 mt-1 border-l border-[hsl(var(--deck-border))] py-1 pl-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:t})})]}):null}function Ut({tasks:t}){if(t.length===0)return null;const s=t.filter(a=>a.status==="completed").length,r=s===t.length;return e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"flex gap-2 items-center",children:e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:r?"✓ All tasks done":`Tasks: ${s}/${t.length}`})})})}function Kt({toolCalls:t}){const s=ae(a=>a.openFilePreview),r=h.useMemo(()=>{const a=new Map,c=["Write","SearchReplace","Edit","ApplyPatch"];for(const i of t){if(i.status!=="success")continue;const d=i.metadata;if(i.toolName==="ApplyPatch"&&Array.isArray(d==null?void 0:d.changes)){for(const l of d.changes)l&&typeof l=="object"&&"path"in l&&typeof l.path=="string"&&a.set(l.path,{path:l.path,toolName:i.toolName});continue}const p=d==null?void 0:d.file_path;p&&c.includes(i.toolName)&&a.set(p,{path:p,toolName:i.toolName})}return Array.from(a.values())},[t]);return r.length===0?null:e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono mb-1.5",children:["Changed files (",r.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map(({path:a})=>{const c=a.split("/").pop()||a;return e.jsxs("button",{onClick:()=>s({tab:"diff",targetPath:a}),className:"flex items-center gap-1 px-2 py-1 text-[11px] font-mono bg-[#E5E7EB] dark:bg-[#27272a] text-[hsl(var(--deck-ink))] rounded hover:bg-[#D1D5DB] dark:hover:bg-[#3f3f46] transition-colors",title:a,children:[e.jsx(rt,{className:"w-3 h-3"}),c]},a)})})]})}function qt({subagent:t}){var H,G;const[s,r]=h.useState(null),[a,c]=h.useState(!1),[i,d]=h.useState(null),[p,l]=h.useState(!1),[n,j]=h.useState(""),[o,u]=h.useState(!1),[x,y]=h.useState(null),[f,k]=h.useState(null),w=N(T=>T.currentSessionRef),b=N(T=>T.isStreaming),m=N(T=>T.isTemporarySession);if(!t)return null;const g=t.status==="running",S=s!==null?s:g,C=t.toolCalls||i||[],D=t.output||t.thinking||C.length>0||t.sessionId,P=f&&f.status!=="running"?f.id:t.sessionId,E=!g&&!b&&!m&&(f==null?void 0:f.status)!=="running"&&!!(P&&w);h.useEffect(()=>{if(!S||g||!t.sessionId||!(w!=null&&w.projectPath)||i!==null||t.toolCalls&&t.toolCalls.length>0)return;let T=!0;return c(!0),O.getMessages({sessionId:t.sessionId,projectPath:w.projectPath}).then(_=>{var I,R;if(!T)return;const L=Oe(_),B=new Map;for(const V of L)if((R=(I=V.agentContent)==null?void 0:I.toolCalls)!=null&&R.length)for(const K of V.agentContent.toolCalls)B.has(K.toolCallId)||B.set(K.toolCallId,K);d(Array.from(B.values()))}).finally(()=>{T&&c(!1)}),()=>{T=!1}},[S,g,t.sessionId,t.toolCalls,i,w==null?void 0:w.projectPath]),h.useEffect(()=>{if(!t.sessionId||!w)return;let T=!0;const _=t.rootAgentId??t.sessionId,L=t.resumeDepth??0;return O.listSubagents(w).then(B=>{if(!T)return;const I=B.filter(R=>R.id!==t.sessionId&&R.rootAgentId===_&&R.resumeDepth>L).sort((R,V)=>V.resumeDepth-R.resumeDepth||V.lastActiveAt-R.lastActiveAt)[0];I&&k(I)}).catch(()=>{}),()=>{T=!1}},[w==null?void 0:w.sessionId,w==null?void 0:w.projectPath,t.sessionId,t.rootAgentId,t.resumeDepth]),h.useEffect(()=>{if(!f||f.status!=="running"||!w)return;let T=!0;const _=async()=>{try{const I=(await O.listSubagents(w)).find(R=>R.id===f.id);T&&I&&k(I)}catch{}},L=window.setInterval(()=>{_()},1e3);return()=>{T=!1,window.clearInterval(L)}},[w,f==null?void 0:f.id,f==null?void 0:f.status]);const $=async()=>{if(!(!w||!P||!n.trim()||o)){u(!0),y(null);try{const T=await O.resumeSubagent(w,P,n.trim());k(T.session),j(""),l(!1),r(!0)}catch(T){y(T instanceof Error?T.message:"Failed to resume subagent")}finally{u(!1)}}};return e.jsxs("div",{"data-subagent-id":t.id,className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>r(!S),className:"flex gap-2 justify-between items-center w-full transition-opacity cursor-pointer hover:opacity-80",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[g&&e.jsx(F,{className:"h-3 w-3 animate-spin text-[hsl(var(--deck-ink-muted))]"}),e.jsxs("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[t.type,": ",t.description]}),e.jsx(ce,{status:t.status==="completed"?"success":t.status==="failed"?"error":"running"}),t.type==="verification"&&t.verificationVerdict&&e.jsx("span",{"data-verification-verdict":t.verificationVerdict,className:A("rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide",t.verificationVerdict==="pass"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":t.verificationVerdict==="fail"?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"),children:t.verificationVerdict}),t.resumedFrom&&e.jsxs("span",{className:"rounded bg-[#EDE9FE] px-1.5 py-0.5 text-[10px] font-mono text-[#6D28D9] dark:bg-[#2E1065] dark:text-[#C4B5FD]",title:`Resumed from ${t.resumedFrom}`,children:["resumed · depth ",t.resumeDepth??1]})]}),D&&e.jsx(X,{className:A("h-3.5 w-3.5 text-[hsl(var(--deck-ink-muted))] transition-transform",S&&"rotate-180")})]}),S&&e.jsxs("div",{className:"mt-2 space-y-2",children:[(t.output||t.thinking)&&e.jsxs(e.Fragment,{children:[t.output&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[160px] overflow-y-auto",children:t.output}),t.thinking&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:t.thinking})]}),a&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[e.jsx(F,{className:"w-3 h-3 animate-spin"}),"Loading subagent logs..."]}),!a&&C.length>0&&e.jsx(Re,{toolCalls:C}),f&&e.jsxs("div",{className:"rounded-md border border-[#DDD6FE] bg-[#F5F3FF] p-2 text-[11px] font-mono text-[#5B21B6] dark:border-[#4C1D95] dark:bg-[#1E1B4B] dark:text-[#C4B5FD]",children:[e.jsxs("div",{children:["Resumed as ",f.id," · ",f.status," · depth"," ",f.resumeDepth]}),(((H=f.result)==null?void 0:H.message)||((G=f.result)==null?void 0:G.error))&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap text-[hsl(var(--deck-ink))]",children:f.result.message||f.result.error})]}),E&&e.jsxs("div",{className:"space-y-2",children:[p?e.jsxs("div",{className:"space-y-2 rounded-md border border-[#E5E7EB] bg-white p-2 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsx("textarea",{"aria-label":"Subagent follow-up",value:n,onChange:T=>j(T.target.value),placeholder:"Describe the follow-up work",rows:3,className:"w-full resize-y rounded border border-[#D1D5DB] bg-white p-2 text-[11px] text-[#111827] outline-none focus:border-[#8B5CF6] dark:border-[#3f3f46] dark:bg-[#18181b] dark:text-[#f4f4f5]"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>{l(!1),y(null)},className:"rounded px-2 py-1 text-[11px] text-[#6B7280] hover:bg-[#F3F4F6] dark:hover:bg-[#27272a]",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:()=>void $(),disabled:!n.trim()||o,className:"flex items-center gap-1 rounded bg-[#7C3AED] px-2 py-1 text-[11px] font-medium text-white disabled:opacity-50",children:[o&&e.jsx(F,{className:"w-3 h-3 animate-spin"}),"Resume agent"]})]})]}):e.jsxs("button",{type:"button","aria-label":"Resume subagent",onClick:()=>l(!0),className:"flex items-center gap-1.5 rounded-md border border-[#D1D5DB] px-2 py-1 text-[11px] font-medium text-[#374151] transition-colors hover:bg-[#F3F4F6] dark:border-[#3f3f46] dark:text-[#d4d4d8] dark:hover:bg-[#27272a]",children:[e.jsx(oe,{className:"w-3 h-3"}),"Resume"]}),x&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:x})]})]})]})}function zt({confirmation:t,messageId:s}){const r=M(),[a,c]=h.useState(!1),[i,d]=h.useState(null),p=N(j=>j.currentSessionRef),l=N(j=>j.setConfirmation);if(!t)return null;const n=async(j,o)=>{if(!(!p||a)){c(!0),d(null);try{await O.respondPermission(p,t.toolCallId,{approved:j,scope:o}),l(s,{...t,status:j?"approved":"denied"})}catch(u){d(u instanceof Error?u.message:r("interaction.permission.failed"))}finally{c(!1)}}};return t.status!=="pending"?null:e.jsxs("div",{"data-pending-interaction":"permission",tabIndex:-1,role:"alert",className:"space-y-3 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:r("interaction.permission.title",{tool:t.toolName})}),e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:t.description}),t.diff&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[200px] overflow-y-auto",children:t.diff}),i&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:i}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void n(!0,"once"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:a?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):r("interaction.permission.once")}),t.allowRemember!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void n(!0,"session"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#3B82F6] text-white rounded-md hover:bg-[#2563EB] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.session")}),e.jsx("button",{type:"button",onClick:()=>void n(!0,"project"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#6366F1] text-white rounded-md hover:bg-[#4F46E5] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.project")})]}),e.jsx("button",{type:"button",onClick:()=>void n(!1),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#EF4444] text-white rounded-md hover:bg-[#DC2626] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.deny")})]})]})}function Gt({question:t,messageId:s}){const r=M(),[a,c]=h.useState({}),[i,d]=h.useState({}),[p,l]=h.useState(!1),[n,j]=h.useState(null),o=N(k=>k.currentSessionRef),u=N(k=>k.setQuestion),x=h.useMemo(()=>t?t.questions.reduce((k,w)=>{var S;const b=(S=i[w.header])==null?void 0:S.trim(),m=a[w.header];if(w.multiSelect){const C=Array.isArray(m)?[...m]:[];return b&&C.push(b),C.length>0&&(k[w.header]=C),k}const g=b||(typeof m=="string"?m:"");return g&&(k[w.header]=g),k},{}):{},[a,i,t]),y=(t==null?void 0:t.questions.every(k=>k.header in x))??!1;if(!t)return null;const f=async()=>{if(!(!o||p||!y)){l(!0),j(null);try{await O.respondToQuestion(o,t.toolCallId,x),u(s,{...t,status:"answered",answers:x})}catch(k){j(k instanceof Error?k.message:r("interaction.question.failed"))}finally{l(!1)}}};return t.status!=="pending"?e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:r("interaction.question.answered")})}):e.jsxs("div",{"data-pending-interaction":"question",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[t.questions.map((k,w)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:k.question}),e.jsxs("div",{className:"space-y-1",children:[k.options.map((b,m)=>e.jsxs("button",{type:"button",onClick:()=>{if(k.multiSelect){const g=a[k.header]||[],S=g.includes(b.label)?g.filter(C=>C!==b.label):[...g,b.label];c({...a,[k.header]:S})}else c({...a,[k.header]:b.label}),d({...i,[k.header]:""})},className:A("w-full text-left px-3 py-2 rounded-md border text-[12px] font-mono transition-colors","border-[hsl(var(--deck-border))]",(k.multiSelect?(a[k.header]||[]).includes(b.label):a[k.header]===b.label)?"bg-[#DCFCE7] text-[#166534] dark:bg-[#22C55E]/20 dark:text-[#E5E5E5]":"bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))]"),children:[e.jsx("div",{children:b.label}),e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-faint))] mt-1",children:b.description})]},m)),e.jsx("input",{"aria-label":`${k.header} other response`,value:i[k.header]??"",onChange:b=>d({...i,[k.header]:b.target.value}),placeholder:r("interaction.question.other"),className:"w-full rounded-md border border-[#E5E7EB] bg-white px-3 py-2 text-[12px] text-[#111827] outline-none focus:border-[#22C55E] dark:border-[#27272a] dark:bg-[#111113] dark:text-[#E5E5E5]"})]})]},w)),n&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:n}),e.jsxs("button",{type:"button",onClick:()=>void f(),disabled:p||!y,className:"inline-flex min-h-8 items-center gap-1.5 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:[p&&e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}),r("interaction.question.submit")]})]})}function Wt({message:t}){const s=t.agentContent,r=N(y=>y.isStreaming&&y.currentAssistantMessageId===t.id);if(!s){const y=le(t.content);return y?e.jsx(be,{content:y}):null}const{toolCalls:a,tasks:c,confirmation:i,question:d,elicitation:p}=s,l=Le(s),n=Ve(s);if(!(n.length>0||c.length>0||l.length>0||i||d||p)&&r)return e.jsxs("div",{className:"flex items-center gap-2 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(F,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-[12px] font-mono",children:"Thinking..."})]});const u=a.length>0&&a.every(y=>y.status==="success"||y.status==="error")&&!r,x=!r;return e.jsxs("div",{className:"space-y-3",children:[n.map(y=>y.type==="thinking"?e.jsx("div",{"data-agent-timeline-block":"thinking",children:e.jsx(Ht,{content:y.content})},y.id):y.type==="text"?e.jsx("div",{"data-agent-timeline-block":"text",children:e.jsx(be,{content:y.content,syntaxHighlight:x})},y.id):e.jsx("div",{"data-agent-timeline-block":"tool_group",children:e.jsx(Ot,{toolCalls:a,toolCallIds:y.toolCallIds})},y.id)),c.length>0&&e.jsx(Ut,{tasks:c}),l.map(y=>e.jsx(qt,{subagent:y},y.id)),i&&e.jsx(zt,{confirmation:i,messageId:t.id}),d&&e.jsx(Gt,{question:d,messageId:t.id}),p&&e.jsx(Et,{elicitation:p,messageId:t.id}),u&&e.jsx(Kt,{toolCalls:a})]})}function Qt({message:t,showAvatar:s=!0}){var d,p,l;const r=t.role==="user";if(t.role==="system"){const n=le(t.content);return e.jsx("div",{"data-chat-message-id":t.id,className:"flex justify-center p-2 w-full",children:e.jsx("div",{className:"text-xs text-[hsl(var(--deck-ink-muted))] bg-[#F3F4F6] dark:bg-[#18181b] px-3 py-1 rounded-full font-mono",children:n})})}if(r){const n=(d=t.metadata)!=null&&d.userShellCommand&&typeof t.metadata.userShellCommand=="object"?t.metadata.userShellCommand:(p=t.metadata)!=null&&p.userShellExecution&&typeof t.metadata.userShellExecution=="object"?t.metadata.userShellExecution:void 0;if(n){const u=typeof n.command=="string"?n.command:"",x=n.status==="running"?"running":n.status==="completed"?"success":"error",y=typeof n.output=="string"?n.output:[typeof n.stdout=="string"?n.stdout:"",typeof n.stderr=="string"&&n.stderr?`stderr:
|
|
5
|
-
${n.stderr}`:""].filter(Boolean).join(`
|
|
6
|
-
`);return e.jsx("div",{"data-chat-message-id":t.id,"data-user-shell-command":!0,className:"flex w-full justify-end p-4",children:e.jsxs("div",{className:"w-full max-w-[85%] overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 truncate font-mono text-[12px] text-[hsl(var(--deck-ink))]",children:[e.jsx("span",{className:"mr-2 text-amber-600 dark:text-amber-400",children:"$"}),u]}),e.jsx(ce,{status:x})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:y||"(no output)"}),typeof n.exitCode=="number"&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-1.5 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:["exit ",n.exitCode,typeof n.durationMs=="number"?` · ${(n.durationMs/1e3).toFixed(3)}s`:"",n.truncated===!0?" · truncated":""]})]})})}const{text:j,images:o}=_t(t.content);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"user",className:"group flex gap-2 justify-end p-4 w-full items-start",children:[e.jsx("div",{className:"mt-1 flex shrink-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(pe,{text:j,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[j&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:j}),o.length>0&&e.jsx("div",{className:A("grid gap-2",o.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:o.map((u,x)=>e.jsx("img",{src:u,alt:`attachment-${x+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${u}-${x}`))})]}),e.jsx($t,{})]})}const c=Pt(t),i=Nt((l=t.metadata)==null?void 0:l.codeReview);return e.jsxs("div",{"data-chat-message-id":t.id,className:A("group flex gap-4 justify-start w-full",s?"p-4":"px-4 pt-0 pb-3"),children:[s?e.jsx(Bt,{}):e.jsx("div",{className:"w-8 shrink-0"}),e.jsxs("div",{className:"overflow-hidden flex-1 min-w-0",children:[i?e.jsx(Ct,{report:i}):e.jsx(Wt,{message:t}),c.trim()&&e.jsx("div",{className:"mt-1.5 flex opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(pe,{text:c,label:"Copy response"})})]})]})}const Jt=h.memo(Qt);function Yt(t,s,r){return Math.max(0,t+(r-s))}function Xt(t,s,r){return Math.min(s,Math.max(0,t)+Math.max(0,r))}function ge(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function Zt({turns:t,viewportRef:s,containerRef:r,onRevealTurn:a}){const c=M(),[i,d]=h.useState(null),[p,l]=h.useState(!1),n=h.useRef(null),j=h.useCallback(()=>{var k;const u=s.current,x=r.current;if(!u||!x||t.length===0)return;const y=u.getBoundingClientRect().top;let f=((k=t[0])==null?void 0:k.id)??null;for(const w of t){const b=ge(x,w.id);if(b)if(b.getBoundingClientRect().top-y<=24)f=w.id;else break}d(f)},[t,s,r]);h.useEffect(()=>{const u=s.current;if(!u)return;const x=()=>{n.current===null&&(n.current=window.requestAnimationFrame(()=>{n.current=null,j()}))};return j(),u.addEventListener("scroll",x,{passive:!0}),()=>{u.removeEventListener("scroll",x),n.current!==null&&(window.cancelAnimationFrame(n.current),n.current=null)}},[j,s]);const o=h.useCallback(u=>{const x=()=>{const f=ge(r.current,u.id);f&&(f.scrollIntoView({behavior:"smooth",block:"start"}),d(u.id))};a(u.index)?x():window.requestAnimationFrame(()=>window.requestAnimationFrame(x))},[r,a]);return t.length<2?null:e.jsx("nav",{"aria-label":c("chat.turns.aria"),className:"absolute right-1 top-1/2 z-20 hidden -translate-y-1/2 sm:block",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onFocusCapture:()=>l(!0),onBlurCapture:u=>{u.currentTarget.contains(u.relatedTarget)||l(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:A("flex flex-col items-center gap-2 py-2 transition-opacity",p?"opacity-0":"opacity-100"),"aria-hidden":p,children:t.map(u=>e.jsx("li",{children:e.jsx("span",{className:A("block rounded-full transition-all",u.id===i?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},u.id))}),e.jsx("div",{className:A("absolute right-0 max-h-[min(70vh,520px)] w-[280px] overflow-y-auto rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/95 p-1 shadow-xl backdrop-blur transition-all",p?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((u,x)=>e.jsxs("button",{type:"button",onClick:()=>o(u),className:A("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u.id===i?"bg-[hsl(var(--deck-hairline))]/70 text-[hsl(var(--deck-ink))]":"text-[hsl(var(--deck-ink-muted))] hover:bg-[hsl(var(--deck-hairline))]/50 hover:text-[hsl(var(--deck-ink))]"),children:[e.jsx("span",{className:A("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",u.id===i?"bg-[hsl(var(--deck-accent))]":"bg-[hsl(var(--deck-ink-faint))]/40")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[9.5px] uppercase tracking-[0.12em] text-[hsl(var(--deck-ink-faint))]",children:c("chat.turns.label",{n:x+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:u.preview})]})]},u.id))})]})})}const ve=80;function es(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ts(t){const s=es(t).replace(/\s+/g," ").trim();return s?s.length>ve?`${s.slice(0,ve-1)}…`:s:""}function ss(t){const s=[];for(let r=0;r<t.length;r+=1){const a=t[r];if(a.role!=="user"||!a.id)continue;const c=ts(a.content);c&&s.push({id:a.id,index:r,preview:c})}return s}const te=120,se=80,rs=96;function q(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function as({messages:t,isLoading:s}){const r=M(),a=h.useRef(null),c=h.useRef(null),i=h.useRef(!0),d=h.useRef(t.length),p=h.useRef(null),[l,n]=h.useState(te),[j,o]=h.useState(!1);h.useEffect(()=>{const m=q(a.current);if(!m||!i.current)return;const g=window.requestAnimationFrame(()=>{m.scrollTop=m.scrollHeight});return()=>window.cancelAnimationFrame(g)},[t]),h.useEffect(()=>{const m=q(a.current);if(!m)return;c.current=m;const g=()=>{const C=m.scrollHeight-m.scrollTop-m.clientHeight<=rs;i.current=C,o(!C)};return g(),m.addEventListener("scroll",g,{passive:!0}),()=>m.removeEventListener("scroll",g)},[]),h.useEffect(()=>{const m=d.current;d.current=t.length,n(g=>g>=m&&t.length>m?t.length:Math.min(Math.max(g,te),t.length||te))},[t.length]);const u=Math.max(t.length-l,0),x=u,y=h.useMemo(()=>t.slice(x),[t,x]),f=h.useMemo(()=>ss(t),[t]);if(h.useLayoutEffect(()=>{var S;const m=p.current;if(!m)return;const g=q(a.current);if(p.current=null,!!g){if((S=m.element)!=null&&S.isConnected){const C=m.element.getBoundingClientRect().top-m.viewportTop;g.scrollTop+=C;return}g.scrollTop=Yt(m.scrollTop,m.scrollHeight,g.scrollHeight)}},[l]),s)return e.jsx("div",{role:"status","aria-live":"polite","aria-busy":"true",className:"flex overflow-hidden flex-1 justify-center items-center px-5 py-8 min-h-0",children:e.jsxs("div",{className:"w-full max-w-[560px]",children:[e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 animate-pulse rounded-full bg-[hsl(var(--deck-accent-soft))] blur-xl"}),e.jsx(re,{size:42,className:"relative"})]}),e.jsxs("div",{className:"mt-4 inline-flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--deck-accent))]",children:[e.jsx(at,{className:"w-3 h-3"}),r("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:r("chat.list.loading.title")}),e.jsx("p",{className:"mt-1 max-w-sm text-[11.5px] leading-5 text-[hsl(var(--deck-ink-faint))]",children:r("chat.list.loading.hint")})]}),e.jsx("div",{"aria-hidden":"true",className:"mt-7 space-y-4 rounded-xl border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))]/45 px-4 py-5",children:[72,88,64].map((m,g)=>e.jsxs("div",{className:A("flex gap-3",g%2===1&&"flex-row-reverse"),children:[e.jsx("span",{className:"h-7 w-7 shrink-0 animate-pulse rounded-md bg-[hsl(var(--deck-surface-2))]"}),e.jsx("span",{className:"h-10 animate-pulse rounded-lg bg-[hsl(var(--deck-surface-2))]",style:{width:`${m}%`,animationDelay:`${g*120}ms`}})]},m))})]})});if(t.length===0&&!s)return e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsxs("div",{className:"flex flex-col gap-4 items-center text-center",children:[e.jsx(re,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:r("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:r("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:r("chat.list.empty.hint")})]})]})});const k=()=>{const m=q(a.current);m&&(i.current=!0,o(!1),m.scrollTo({top:m.scrollHeight,behavior:"smooth"}))},w=()=>{var g;const m=q(a.current);if(m){const S=((g=a.current)==null?void 0:g.querySelector("[data-chat-message-id]"))??null;p.current={element:S,viewportTop:(S==null?void 0:S.getBoundingClientRect().top)??0,scrollHeight:m.scrollHeight,scrollTop:m.scrollTop}}n(S=>Xt(S,t.length,se))},b=m=>m>=x?!0:(n(t.length),!1);return e.jsxs("div",{ref:a,className:"relative flex-1 min-h-0",children:[e.jsx(Ue,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[u>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:w,"aria-label":r("chat.list.showEarlierWithRemaining",{count:Math.min(u,se),remaining:u}),className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-3 py-1.5 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:border-[hsl(var(--deck-border-strong))] hover:text-[hsl(var(--deck-ink))]",children:r("chat.list.showEarlier",{count:Math.min(u,se)})})}),y.map((m,g)=>{const S=x+g,C=S>0?t[S-1]:null,D=!C||C.role!==m.role||C.role==="user";return e.jsx(Jt,{message:m,showAvatar:D},m.id||`msg-${S}`)})]})}),e.jsx(Zt,{turns:f,viewportRef:c,containerRef:a,onRevealTurn:b}),j&&e.jsxs("button",{type:"button",onClick:k,className:"absolute bottom-4 left-1/2 z-10 inline-flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/95 px-3 py-1.5 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] shadow-lg backdrop-blur transition-colors hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),r("chat.list.jumpLatest")]})]})}const ns=h.memo(as),Me=ft,De=bt,Ie=gt,de=h.forwardRef(({className:t,sideOffset:s=4,...r},a)=>e.jsx(Fe,{ref:a,sideOffset:s,className:A("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",t),...r}));de.displayName=Fe.displayName;const is={active:{labelKey:"goal.status.active",dot:"bg-[hsl(var(--deck-accent))] shadow-[0_0_6px_hsl(var(--deck-accent-glow)/0.5)]",accent:"text-[hsl(var(--deck-accent))]"},paused:{labelKey:"goal.status.paused",dot:"bg-amber-400",accent:"text-amber-600 dark:text-amber-300"},blocked:{labelKey:"goal.status.blocked",dot:"bg-rose-500",accent:"text-rose-600 dark:text-rose-300"},usage_limited:{labelKey:"goal.status.usageLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},budget_limited:{labelKey:"goal.status.budgetLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},complete:{labelKey:"goal.status.complete",dot:"bg-emerald-500",accent:"text-emerald-600 dark:text-emerald-300"}};function W(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function os(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),r=t%60;return r===0?`${s}m`:`${s}m ${r}s`}function ls(){const t=M(),s=N(E=>E.goal),r=N(E=>E.pauseGoal),a=N(E=>E.resumeGoal),c=N(E=>E.editGoal),i=N(E=>E.clearGoal),[d,p]=h.useState(!1),[l,n]=h.useState(!1),[j,o]=h.useState(""),[u,x]=h.useState(null),[y,f]=h.useState(!1);if(h.useEffect(()=>{p(!1),n(!1),o((s==null?void 0:s.objective)??""),f(!1)},[s==null?void 0:s.goalId]),!s)return null;const k=is[s.status],w=["active","paused","blocked"].includes(s.status),b=s.status==="active",m=s.status==="paused"||s.status==="blocked",g=u!==null,S=async(E,$)=>{x(E);try{await $()}finally{x(null)}},C=()=>{o(s.objective),n(!0),p(!0)},D=async E=>{E.preventDefault();const $=j.trim();if(!$||$===s.objective){n(!1);return}await S("edit",()=>c($)),n(!1)},P=async()=>{await S("delete",i),f(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Me,{delayDuration:250,children:e.jsxs("section",{"aria-label":t("goal.aria.section"),className:"mx-3 mb-1 shrink-0",children:[e.jsxs("div",{className:A("flex h-9 items-center gap-2 rounded-lg border px-3 transition-colors","border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 backdrop-blur-sm",d&&"rounded-b-none border-b-0"),children:[s.status==="complete"?e.jsx(nt,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(it,{className:A("h-3.5 w-3.5 shrink-0",k.accent)}),e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",k.dot)}),e.jsx("span",{className:A("shrink-0 text-[10px] font-medium leading-none",k.accent),children:t(k.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(d?"goal.action.collapse":"goal.action.expand"),className:"min-w-0 flex-1 truncate text-left text-[12px] leading-5 text-[hsl(var(--deck-ink))]/85 outline-none transition-colors hover:text-[hsl(var(--deck-ink))]",onClick:()=>p(E=>!E),"aria-expanded":d,title:s.objective,children:s.objective}),s.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[W(s.tokensUsed),s.tokenBudget!==void 0&&`/${W(s.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[b&&e.jsx(Q,{label:t("goal.action.pause"),disabled:g,onClick:()=>void S("pause",r),children:u==="pause"?e.jsx(F,{className:"animate-spin"}):e.jsx(ot,{})}),m&&e.jsx(Q,{label:t("goal.action.resume"),disabled:g,onClick:()=>void S("resume",a),children:u==="resume"?e.jsx(F,{className:"animate-spin"}):e.jsx(lt,{})}),e.jsx(Q,{label:t(w?"goal.action.edit":"goal.action.expand"),disabled:!w&&!d,onClick:w?C:()=>p(E=>!E),children:w?e.jsx(Te,{}):e.jsx(ct,{})}),e.jsx(Q,{label:t("goal.action.delete"),disabled:g,destructive:!0,onClick:()=>f(!0),children:e.jsx(J,{})})]})]}),d&&e.jsx("div",{className:"rounded-b-lg border border-t-0 border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 px-4 py-3 backdrop-blur-sm",children:l?e.jsxs("form",{onSubmit:D,children:[e.jsx("textarea",{id:"goal-objective",value:j,onChange:E=>o(E.target.value),onKeyDown:E=>{E.key==="Escape"&&n(!1)},rows:3,autoFocus:!0,className:"w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] outline-none transition-shadow focus:border-[hsl(var(--deck-accent))] focus:ring-1 focus:ring-[hsl(var(--deck-accent-glow))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-hairline))]/60",children:[e.jsx(dt,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!j.trim()||u==="edit",className:"inline-flex h-7 items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2.5 text-[11px] font-medium text-white transition-colors hover:bg-[hsl(var(--deck-accent))]/90 disabled:cursor-not-allowed disabled:opacity-50",children:[u==="edit"?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(ne,{className:"h-3 w-3"}),t("goal.action.save")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink))]/90",children:s.objective}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ut,{className:"h-3 w-3"}),W(s.tokensUsed),s.tokenBudget!==void 0&&` / ${W(s.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(mt,{className:"h-3 w-3"}),os(s.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(oe,{className:"h-3 w-3"}),s.continuationCount===1?t("goal.metrics.continuationOne",{n:s.continuationCount}):t("goal.metrics.continuationMany",{n:s.continuationCount})]})]}),s.statusReason&&e.jsx("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-1.5 text-[11px] text-amber-800 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-200",children:s.statusReason})]})})]})}),e.jsx(ye,{open:y,onOpenChange:f,children:e.jsxs(we,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(Ne,{children:t("goal.dialog.title")}),e.jsx(Se,{children:t("goal.dialog.description")}),e.jsxs(Ce,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>f(!1),className:"inline-flex h-8 items-center justify-center rounded-md border border-[hsl(var(--deck-border))] px-3 text-[12px] text-[hsl(var(--deck-ink))] hover:bg-[hsl(var(--deck-hairline))]/60",children:t("goal.action.cancel")}),e.jsxs("button",{type:"button",disabled:u==="delete",onClick:()=>void P(),className:"inline-flex gap-1.5 justify-center items-center px-3 h-8 text-[12px] font-medium text-white bg-rose-600 rounded-md hover:bg-rose-500 disabled:opacity-50",children:[u==="delete"&&e.jsx(F,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function Q({label:t,children:s,disabled:r,destructive:a,onClick:c}){return e.jsxs(De,{children:[e.jsx(Ie,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:r,onClick:c,className:A("flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-muted))] outline-none transition-colors focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent-glow))]/50 disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",a?"hover:bg-rose-500/10 hover:text-rose-500":"hover:bg-[hsl(var(--deck-hairline))]/60 hover:text-[hsl(var(--deck-ink))]"),children:s})}),e.jsx(de,{side:"top",className:"text-[10px]",children:t})]})}function cs(){const t=M(),s=N(l=>l.currentSessionRef),r=N(l=>l.sessions),a=N(l=>l.messages),c=h.useMemo(()=>{var n,j,o,u,x;const l=s?(n=Ke(r,s))==null?void 0:n.pendingInteraction:void 0;if(l)return l.type;for(let y=a.length-1;y>=0;y-=1){const f=(j=a[y])==null?void 0:j.agentContent;if(((o=f==null?void 0:f.confirmation)==null?void 0:o.status)==="pending")return"permission";if(((u=f==null?void 0:f.question)==null?void 0:u.status)==="pending")return"question";if(((x=f==null?void 0:f.elicitation)==null?void 0:x.status)==="pending")return"elicitation"}return null},[s,a,r]);if(!c)return null;const i=()=>{const l=document.querySelector(`[data-pending-interaction="${c}"]`);l==null||l.scrollIntoView({block:"center",behavior:"smooth"}),window.setTimeout(()=>l==null?void 0:l.focus(),250)},d=c==="question",p=c==="elicitation";return e.jsxs("div",{role:"alert",className:"mx-3 mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-amber-300/80 bg-amber-50/95 px-3 py-2 font-mono text-amber-950 shadow-sm backdrop-blur dark:border-amber-800/80 dark:bg-amber-950/90 dark:text-amber-100 sm:mx-5",children:[e.jsx(Ae,{className:"h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-[180px] flex-1",children:[e.jsx("div",{className:"text-[11.5px] font-semibold",children:t(d?"interaction.bar.questionTitle":p?"interaction.bar.elicitationTitle":"interaction.bar.permissionTitle")}),e.jsx("div",{className:"mt-0.5 text-[10px] leading-4 text-amber-800 dark:text-amber-300",children:t(d?"interaction.bar.questionHint":p?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:i,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/80 bg-white/80 px-2.5 text-[10.5px] font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/70 dark:hover:bg-amber-900",children:[e.jsx(Ee,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}const ds={running:"status.phase.running",compacting:"status.phase.compacting",switching_model:"status.phase.switchingModel",waiting_permission:"status.phase.waitingPermission",error:"status.phase.error",idle:""},ke=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString();function us(){const t=M(),s=N(n=>n.tokenUsage),r=N(n=>n.isStreaming),a=N(n=>n.agentPhase),c=ds[a]??"",i=c?t(c):"",d=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,p=Math.min(d,100),l=d>95?"danger":d>80?"warn":"safe";return e.jsxs("div",{className:"flex items-center gap-4 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-5 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm",children:[e.jsxs("div",{className:"flex gap-3 items-center",children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.context")}),e.jsxs("span",{className:"flex gap-1 items-baseline tabular-nums",children:[e.jsx("span",{className:A("text-[12px] font-medium",l==="safe"&&"text-[hsl(var(--deck-ink))]",l==="warn"&&"text-amber-600 dark:text-amber-400",l==="danger"&&"text-red-600 dark:text-red-400"),children:ke(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",ke(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(Me,{children:e.jsxs(De,{children:[e.jsx(Ie,{asChild:!0,children:e.jsx(xt,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(de,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]","aria-hidden":"true",children:[e.jsx("div",{className:A("absolute inset-y-0 left-0 transition-[width] duration-300",l==="safe"&&"bg-[hsl(var(--deck-accent))]",l==="warn"&&"bg-amber-500",l==="danger"&&"bg-red-500"),style:{width:`${p}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(n=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${n}%`}},n))})]}),e.jsxs("span",{className:A("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",l==="warn"&&"text-amber-600 dark:text-amber-400",l==="danger"&&"text-red-600 dark:text-red-400"),children:[d,"%"]})]}),e.jsx("div",{className:"flex-1"}),r&&i&&e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("span",{className:"deck-pulse-dot"}),e.jsx("span",{className:"text-[hsl(var(--deck-accent))]",children:i})]})]})}function ms(t){const s=[...t].reverse().find(c=>c.role==="user");if(!s)return null;if(typeof s.content=="string")return{content:s.content,attachments:[]};const r=s.content.filter(c=>c.type==="text").map(c=>c.text).join(`
|
|
7
|
-
`),a=s.content.filter(c=>c.type==="image_url").map((c,i)=>{var p;const d=((p=c.image_url.url.match(/^data:([^;,]+)[;,]/))==null?void 0:p[1])??"application/octet-stream";return{id:`recovery-${s.id}-${i}`,name:`attachment-${i+1}`,mimeType:d,dataUrl:c.image_url.url}});return{content:r,attachments:a}}function bs(){var me;const t=M(),s=N(v=>v.messages),r=N(v=>v.currentSessionRef),a=N(v=>v.isStreaming),c=N(v=>v.isStopping),i=N(v=>v.sessionEventConnectionState),d=N(v=>v.pendingSteeringCount),p=N(v=>v.pendingInputDelivery),l=N(v=>v.recoveredSteeringCount),n=N(v=>v.isLoading),j=N(v=>v.error),o=N(v=>v.errorContext),u=N(v=>v.sessions),x=N(v=>v.sendMessage),y=N(v=>v.abortSession),f=N(v=>v.retryTask),k=N(v=>v.retryingTaskKeys),w=ae(v=>v.openSettings),b=N(v=>v.reconnectSessionEvents),m=N(v=>v.clearError),g=N(v=>v.unsubscribeFromEvents),[S,C]=h.useState(null),D=r?u.find(v=>v.sessionId===r.sessionId&&v.projectPath===r.projectPath):void 0,P=!!j&&((o==null?void 0:o.kind)==="navigation"||!(o!=null&&o.sessionRef)||je(o.sessionRef,r)),E=(o==null?void 0:o.failureCode)??((me=D==null?void 0:D.taskFailure)==null?void 0:me.code),$=(o==null?void 0:o.kind)==="execution"&&E?t(qe(E)):j==="queue_full"?t("chat.error.queueFull"):j==="turn_unavailable"||j==="turn_active"?t("chat.error.turnChanged"):j,H=i==="connecting"||i==="reconnecting",G=a&&i!=="connected",T=r?`session:${z(r)}`:"session:temporary",_=h.useMemo(()=>ms(s),[s]),L=r?z(r):"temporary-session",B=!!(r&&(D!=null&&D.taskRetryAvailable)&&(!E||ze(E)))&&((o==null?void 0:o.kind)==="execution"||(o==null?void 0:o.kind)==="task_action"),I=(o==null?void 0:o.kind)==="execution"&&(E==="authentication"||E==="permission"||E==="model_unavailable"),R=r?k.includes(z(r)):!1;h.useEffect(()=>()=>{g()},[g]),h.useEffect(()=>{C(null)},[L]);const V=async v=>x({content:v.content,modelId:v.modelId,reasoningEffort:v.reasoningEffort,serviceTier:v.serviceTier,responseVerbosity:v.responseVerbosity,communicationStyle:v.communicationStyle,attachments:v.attachments.map(ee=>({type:"image",content:ee.dataUrl,mimeType:ee.mimeType,name:ee.name}))}),K=()=>y(),Be=async()=>{if(I){m(),w("models");return}if(B&&r){m(),await f(r).catch(()=>{});return}if((o==null?void 0:o.kind)==="execution"&&_){C({..._,revision:Date.now()}),m();return}m(),requestAnimationFrame(()=>We())},ue=B?t(R?"chat.error.action.retryingTask":"chat.error.action.retryTask"):I?t("chat.error.action.checkModels"):(o==null?void 0:o.kind)==="execution"&&_?t("chat.error.action.editResend"):(o==null?void 0:o.kind)==="submission"?t("chat.error.action.returnDraft"):null;return e.jsxs("div",{className:"flex h-full flex-col bg-[hsl(var(--deck-canvas))]",children:[P&&e.jsxs("div",{role:"alert",className:"flex min-h-11 flex-wrap items-center gap-2 border-b border-red-200/60 bg-red-50/80 px-4 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-300 sm:px-5",children:[e.jsx(Ae,{className:"h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 break-words",children:[e.jsx("span",{className:"font-semibold",children:t((o==null?void 0:o.kind)==="submission"?"chat.error.title.submission":(o==null?void 0:o.kind)==="execution"?"chat.error.title.execution":(o==null?void 0:o.kind)==="navigation"?"chat.error.title.navigation":"chat.error.title.generic")})," ",$]}),ue&&e.jsxs("button",{type:"button",onClick:()=>void Be(),disabled:R,className:"inline-flex min-h-7 shrink-0 items-center gap-1.5 rounded-md border border-red-300/70 bg-white/65 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 disabled:cursor-wait disabled:opacity-60 dark:border-red-800 dark:bg-red-950/45 dark:hover:bg-red-900/60",children:[B?R?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(oe,{className:"h-3 w-3"}):e.jsx(Te,{className:"h-3 w-3"}),ue]}),e.jsx("button",{type:"button",onClick:m,"aria-label":t("chat.error.dismiss"),className:"p-1 text-red-500 rounded transition-colors hover:bg-red-100/60 hover:text-red-700 dark:hover:bg-red-950/60 dark:hover:text-red-100",children:"✕"})]}),(H||i==="offline")&&e.jsxs("div",{role:i==="offline"?"alert":"status","aria-live":"polite",className:"flex min-h-10 flex-wrap items-center gap-2 border-b border-amber-300/60 bg-amber-50/80 px-4 py-2 font-mono text-[11px] text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/35 dark:text-amber-200 sm:px-5",children:[H?e.jsx(F,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(ht,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t(H?"chat.connection.reconnecting":"chat.connection.offline")}),i==="offline"&&e.jsxs("button",{type:"button",onClick:()=>void b().catch(()=>{}),className:"inline-flex min-h-7 items-center gap-1.5 rounded-md border border-amber-400/70 bg-white/60 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/50 dark:hover:bg-amber-900/50",children:[e.jsx(pt,{className:"h-3 w-3"}),t("chat.connection.retry")]})]}),e.jsx(vt,{}),e.jsx(ns,{messages:s,isLoading:n},r?z(r):"temporary-session"),e.jsx(cs,{}),e.jsx(ls,{}),e.jsx(Ge,{draftKey:T,draft:S==null?void 0:S.content,draftAttachments:S==null?void 0:S.attachments,draftRevision:S==null?void 0:S.revision,onSend:V,onAbort:K,disabled:n||G,isStreaming:a,isStopping:c,pendingSteeringCount:d,pendingInputDelivery:p,recoveredSteeringCount:l,workspacePath:r==null?void 0:r.projectPath},T),e.jsx(us,{})]})}export{bs as ChatView};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{r,j as e}from"./vendor-react-DG5dkZ_t.js";import{_ as $,n as P,o as Se,p as Fe,q as se}from"./vendor-radix-DBy9B2DN.js";import{i as Ze,a as Xe,d as Me,u as $e,b as ze,c as et,e as de,f as oe,g as tt}from"./useRequest-BvqVDnKl.js";import{b as at,D as he,e as be,G as nt,g as ge,j as w,x as L,y as rt}from"./index-BF5HEN_f.js";import{a as Be,i as st,X as ve,f as De,L as le,k as ot,Z as Te,C as lt,D as dt}from"./vendor-icons-D_AkWmWB.js";function ie(n,s){if(Ze){if(!n)return s;var o;return Xe(n)?o=n():"current"in n?o=n.current:o=n,o}}var it=function(n){var s=function(o,u,f){var x=r.useRef(!1),c=r.useRef([]),p=r.useRef([]),h=r.useRef(void 0);n(function(){var b,S=Array.isArray(f)?f:[f],g=S.map(function(j){return ie(j)});if(!x.current){x.current=!0,c.current=g,p.current=u,h.current=o();return}(g.length!==c.current.length||!Me(c.current,g)||!Me(p.current,u))&&((b=h.current)===null||b===void 0||b.call(h),c.current=g,p.current=u,h.current=o())}),$e(function(){var b;(b=h.current)===null||b===void 0||b.call(h),x.current=!1})};return s},ct=it(r.useEffect);function xt(){var n=(typeof global>"u"?"undefined":typeof global)=="object"&&global&&global.Object===Object&&global,s=typeof self=="object"&&self&&self.Object===Object&&self;return n||s}xt()||(global.Date=Date);function mt(n,s){var o,u=ze(n),f=(o=s==null?void 0:s.wait)!==null&&o!==void 0?o:1e3,x=r.useMemo(function(){return et(function(){for(var c=[],p=0;p<arguments.length;p++)c[p]=arguments[p];return u.current.apply(u,$([],P(c),!1))},f,s)},[]);return $e(function(){x.cancel()}),{run:x,cancel:x.cancel,flush:x.flush}}function ut(n,s,o){o===void 0&&(o={});var u=o.enable,f=u===void 0?!0:u,x=ze(s);ct(function(){if(f){var c=ie(o.target,window);if(c!=null&&c.addEventListener){var p=function(b){return x.current(b)},h=Array.isArray(n)?n:[n];return h.forEach(function(b){c.addEventListener(b,p,{capture:o.capture,once:o.once,passive:o.passive})}),function(){h.forEach(function(b){c.removeEventListener(b,p,{capture:o.capture})})}}}},[n,o.capture,o.once,o.passive,f],o.target)}var ft=function(n){return n===document||n===document.documentElement||n===document.body?Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop):n.scrollTop},Pe=function(n){return n.scrollHeight||Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)},pt=function(n){return n.clientHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight)},ht=function(n,s){s===void 0&&(s={});var o=s.target,u=s.isNoMore,f=s.threshold,x=f===void 0?100:f,c=s.direction,p=c===void 0?"bottom":c,h=s.reloadDeps,b=h===void 0?[]:h,S=s.manual,g=s.onBefore,j=s.onSuccess,C=s.onError,d=s.onFinally,F=P(r.useState(),2),M=F[0],O=F[1],N=P(r.useState(!1),2),z=N[0],R=N[1],U=p==="top",D=r.useRef(void 0),_=r.useRef(0),H=r.useMemo(function(){return u?u(M):!1},[M]),I=de(function(m){return Se(void 0,void 0,void 0,function(){var v;return Fe(this,function(k){switch(k.label){case 0:return[4,n(m)];case 1:return v=k.sent(),[2,{currentData:v,lastData:m}]}})})},{manual:S,onFinally:function(m,v,k){R(!1),d==null||d(v==null?void 0:v.currentData,k)},onBefore:function(){return g==null?void 0:g()},onSuccess:function(m){var v,k,E;m.lastData?O(se(se({},m.currentData),{list:U?$($([],P(m.currentData.list),!1),P((k=m.lastData.list)!==null&&k!==void 0?k:[]),!1):$($([],P((E=m.lastData.list)!==null&&E!==void 0?E:[]),!1),P(m.currentData.list),!1)})):O(se(se({},m.currentData),{list:$([],P((v=m.currentData.list)!==null&&v!==void 0?v:[]),!1)})),setTimeout(function(){requestAnimationFrame(function(){if(U){var y=ie(o);if(y=y===document?document.documentElement:y,y){var ee=Pe(y);y.scrollTo(0,ee-_.current)}}else G()})}),j==null||j(m.currentData)},onError:function(m){return C==null?void 0:C(m)}}),Y=I.loading,J=I.error,K=I.run,q=I.runAsync,ce=I.cancel,Q=oe(function(){H||(R(!0),K(M))}),Z=function(m){return Se(void 0,void 0,void 0,function(){var v;return Fe(this,function(k){switch(k.label){case 0:return[4,q(m)];case 1:return v=k.sent(),[2,v.currentData]}})})},xe=oe(function(){return H?Promise.reject():(R(!0),Z(M))}),me=function(){return R(!1),K()},X=function(){return R(!1),Z()},G=function(){var m=ie(o);if(m){var v=m===document?document.documentElement:m,k=ft(v),E=Pe(v),y=pt(v);U?(D.current!==void 0&&D.current>k&&k<=x&&Q(),D.current=k,_.current=E-k):E-k<=y+x&&Q()}};return ut("scroll",function(){Y||z||G()},{target:o}),tt(function(){K()},$([],P(b),!1)),{data:M,loading:!z&&Y,error:J,loadingMore:z,noMore:H,loadMore:Q,loadMoreAsync:xe,reload:oe(me),reloadAsync:oe(X),mutate:O,cancel:ce}};const Le={connected:"text-[#16A34A] dark:text-[#22C55E]",connecting:"text-[#2563eb] dark:text-[#3b82f6]",reconnecting:"text-[#2563eb] dark:text-[#60a5fa]",offline:"text-[#f59e0b]",error:"text-[#ef4444]"},bt={connected:"Connected",connecting:"Connecting...",reconnecting:"Recovering...",offline:"Offline",error:"Error"},gt={disabled:"Not configured",unavailable:"Unavailable in this runtime",unauthenticated:"Authorization required",authorizing:"Waiting for authorization...",authenticated:"Authorized",error:"Authorization failed"},Oe=20,vt=["debug","info","notice","warning","error","critical","alert","emergency"],Re=n=>n.status!=="reconnecting"||!n.recovery?bt[n.status]:`Recovering ${n.recovery.attempt}/${n.recovery.maxAttempts}`,kt=async()=>L("/mcp"),Et=async n=>L(`/mcp/${encodeURIComponent(n)}/logs?limit=20`),jt="mcp server @modelcontextprotocol",Nt=3,Ue=n=>{var s;return((s=n.split("/").pop())==null?void 0:s.replace(/^server-/,""))||n},Ct=async(n,s)=>{const o=n&&n.length>=Nt?n:jt,u=`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(o)}&size=${Oe}&from=${s}`,f=await L(u);return{list:f.objects.map(x=>x.package),total:f.total,hasMore:s+Oe<f.total}};function Dt(){const{isMcpOpen:n,toggleMcp:s}=at(),[o,u]=r.useState("installed"),[f,x]=r.useState(!1),[c,p]=r.useState(null),[h,b]=r.useState(""),[S,g]=r.useState(null),[j,C]=r.useState(null),[d,F]=r.useState(null),[M,O]=r.useState(null),[N,z]=r.useState(null),[R,U]=r.useState(""),[D,_]=r.useState(null),[H,I]=r.useState(!1),[Y,J]=r.useState(null),[K,q]=r.useState(null),[ce,Q]=r.useState(""),[Z,xe]=r.useState(""),[me,X]=r.useState(null),[G,m]=r.useState(null),v=r.useRef(null),{run:k}=mt(t=>{xe(t)},{wait:500}),{data:E=[],loading:y,error:ee,run:ke,runAsync:W}=de(kt,{refreshDeps:[n],ready:n,onSuccess:t=>{t.length>0&&!c&&p(t[0].id)}}),{data:ae,loading:ue,error:Ee,runAsync:ne}=de(Et,{manual:!0}),{data:A,loading:He,loadingMore:Je,noMore:qe,error:je,reload:Ne}=ht(async t=>{var l;const i=((l=t==null?void 0:t.list)==null?void 0:l.length)??0;return Ct(Z,i)},{target:v,isNoMore:t=>!(t!=null&&t.hasMore),reloadDeps:[Z],manual:!n||o!=="catalog"}),{runAsync:Ce,loading:ye,error:V}=de(async t=>{await L("/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,config:t})})},{manual:!0,onSuccess:()=>{W(),x(!1),m(null),X(null)},onError:()=>{X(null)}}),te=r.useMemo(()=>{const t=h.trim().toLowerCase();return t?E.filter(i=>[i.name,i.endpoint,i.description].some(l=>l.toLowerCase().includes(t))):E},[h,E]),a=r.useMemo(()=>te.find(t=>t.id===c)??te[0],[te,c]),re=r.useMemo(()=>{if(!a)return[];const t=(a.prompts??[]).flatMap(l=>l.arguments.map(B=>({key:`prompt:${l.name}:${B.name}`,label:`${l.name}.${B.name}`,reference:{type:"prompt",name:l.name},argument:B.name}))),i=(a.resourceTemplates??[]).flatMap(l=>(l.variables??[]).map(B=>({key:`resource:${l.uriTemplate}:${B}`,label:`${l.uriTemplate} · ${B}`,reference:{type:"resource",uri:l.uriTemplate},argument:B})));return[...t,...i]},[a]),T=re.find(t=>t.key===N)??re[0];r.useEffect(()=>{if(!n||!E.some(i=>i.oauthStatus==="authorizing"||i.status==="connecting"||i.status==="reconnecting"))return;const t=window.setInterval(()=>{W()},1e3);return()=>window.clearInterval(t)},[n,W,E]),r.useEffect(()=>{j&&E.some(t=>t.name===j.serverName&&(t.oauthStatus==="authenticated"||t.oauthStatus==="disabled"||t.oauthStatus==="unavailable"))&&C(null)},[j,E]),r.useEffect(()=>{!n||o!=="installed"||!a||ne(a.name).catch(()=>{})},[n,ne,a,o]);const fe=async(t,i)=>{F({type:t,name:i}),g(null);try{const l=t==="delete"?"":`/${t}`;await L(`/mcp/${encodeURIComponent(i)}${l}`,{method:t==="delete"?"DELETE":"POST"}),await W(),t==="delete"&&(q(null),p(null))}catch(l){g(l instanceof Error?l.message:`Failed to ${t} server`)}finally{F(null)}},pe=async(t,i)=>{F({type:t,name:i.name}),g(null);try{if(t==="login"){const l=await L(`/mcp/${encodeURIComponent(i.name)}/oauth/login`,{method:"POST"});C({serverName:i.name,url:l.authorizationUrl})}else await L(`/mcp/${encodeURIComponent(i.name)}/oauth/logout`,{method:"POST"}),C(null);await W()}catch(l){g(l instanceof Error?l.message:`Failed to ${t} MCP OAuth`)}finally{F(null)}},Ge=async(t,i)=>{O(i),g(null);try{await L(`/mcp/${encodeURIComponent(t.name)}/logging-level`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:i})}),await W(),ne(t.name).catch(()=>{})}catch(l){g(l instanceof Error?l.message:"Failed to set MCP logging level")}finally{O(null)}},We=async t=>{if(T){I(!0),J(null),_(null);try{const i=await L(`/mcp/${encodeURIComponent(t.name)}/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reference:T.reference,argument:{name:T.argument,value:R}})});_(i)}catch(i){J(i instanceof Error?i.message:"MCP completion failed")}finally{I(!1)}}},Ve=r.useMemo(()=>new Set(E.map(t=>t.name.toLowerCase())),[E]),Ye=t=>{m(t)},Ke=t=>t.startsWith("@modelcontextprotocol/"),Qe=t=>Ke(t.name)?"Official":"Community";return e.jsxs(e.Fragment,{children:[e.jsx(he,{open:n,onOpenChange:s,children:e.jsxs(be,{onCloseAutoFocus:nt,className:"flex h-[min(680px,calc(100dvh-24px))] flex-col gap-0 overflow-hidden rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[900px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(ge,{className:"sr-only",children:"MCP"}),e.jsx("div",{className:"flex flex-1 min-h-0",children:e.jsxs("div",{className:"flex overflow-hidden flex-col flex-1 gap-4 p-4 min-h-0 sm:gap-5 sm:p-8",children:[e.jsxs("div",{className:"flex justify-between items-center shrink-0",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"MCP"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:ke,"aria-label":"Refresh MCP servers",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",disabled:y,children:e.jsx(Be,{className:w("h-4 w-4",y&&"animate-spin")})}),e.jsxs("button",{"data-mcp-add-server-trigger":!0,onClick:()=>x(!0),className:"h-8 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-xs font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a]",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Add server"]}),e.jsx("button",{onClick:s,"aria-label":"Close MCP",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(ve,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] w-fit shrink-0",children:[e.jsxs(Ie,{active:o==="installed",onClick:()=>u("installed"),children:["Installed (",E.length,")"]}),e.jsx(Ie,{active:o==="catalog",onClick:()=>{u("catalog"),A||Ne()},children:"Catalog"})]}),S&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(De,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0",children:S}),e.jsx("button",{type:"button",onClick:()=>g(null),className:"underline shrink-0",children:"Dismiss"})]}),o==="installed"?e.jsxs("div",{className:"flex overflow-hidden flex-col flex-1 gap-3 min-h-0 sm:flex-row sm:gap-5",children:[e.jsxs("div",{className:"flex h-[180px] w-full shrink-0 flex-col gap-3 overflow-hidden sm:h-auto sm:w-[220px]",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Servers"}),e.jsx("input",{type:"search","aria-label":"Search installed MCP servers",value:h,onChange:t=>b(t.target.value),placeholder:"Search servers...",className:"h-8 shrink-0 rounded-md border border-transparent bg-[#F3F4F6] px-3 text-[12px] font-mono text-[#111827] outline-none placeholder:text-[#9CA3AF] focus:border-[#D1D5DB] dark:bg-[#18181b] dark:text-[#E5E5E5] dark:placeholder:text-[#71717a] dark:focus:border-[#3f3f46]"}),e.jsxs("div",{className:"flex overflow-y-auto flex-col flex-1 gap-2 pr-1 min-h-0",children:[y&&E.length===0&&e.jsxs("div",{role:"status",className:"flex items-center justify-center gap-2 py-8 text-sm font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsx(le,{className:"w-4 h-4 animate-spin"}),"Loading servers..."]}),ee&&!y&&e.jsxs("div",{role:"alert",className:"flex flex-col gap-2 items-center py-6 font-mono text-xs text-center text-red-600 dark:text-red-400",children:[e.jsx("span",{children:ee.message}),e.jsx("button",{type:"button",onClick:ke,className:"rounded-md border border-red-200 px-2.5 py-1 text-[11px] dark:border-red-900",children:"Retry"})]}),!ee&&!y&&te.length===0&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:h?"No servers match your search":"No MCP servers configured"}),te.map(t=>e.jsxs("button",{onClick:()=>{p(t.id),q(null),g(null),z(null),U(""),_(null),J(null)},className:w("text-left rounded-lg px-3 py-2 flex flex-col gap-1 transition-colors shrink-0",t.id===(a==null?void 0:a.id)?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:w("text-[11px] font-mono font-semibold",Le[t.status]),children:Re(t)})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] truncate",children:t.endpoint})]},t.id))]})]}),a?e.jsxs("div",{className:"flex overflow-y-auto flex-col flex-1 gap-3 pr-2 min-h-0",children:[e.jsxs("div",{className:"flex justify-between items-center shrink-0",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:a.name}),e.jsx("span",{className:w("text-xs font-mono font-semibold",Le[a.status]),children:Re(a)})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:a.description}),a.error&&e.jsxs("p",{className:"text-[12px] font-mono text-[#ef4444]",children:["Error: ",a.error]}),a.instructions&&e.jsxs("div",{className:"rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"Server instructions"}),e.jsxs("span",{className:"truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",a.instructions.sha256]})]}),e.jsx("pre",{className:"mt-1 max-h-36 overflow-y-auto whitespace-pre-wrap break-words text-[11px] font-mono text-[#374151] dark:text-[#d4d4d8]",children:a.instructions.text??"[details omitted by runtime policy]"}),(a.instructions.truncated||a.instructions.detailsOmitted)&&e.jsx("span",{className:"mt-1 block text-[9px] font-mono text-amber-600 dark:text-amber-400",children:a.instructions.detailsOmitted?"Details omitted":"Truncated to the safe display budget"})]}),a.tasks&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"Experimental MCP Tasks"}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:a.tasks.enabled?`${a.tasks.maxTasksPerSession} per Session · ${a.tasks.pollIntervalMs}ms poll`:"Disabled by default"})]}),e.jsx("span",{className:w("text-[10px] font-mono font-semibold uppercase",a.tasks.enabled?"text-[#16A34A] dark:text-[#22C55E]":"text-[#9CA3AF] dark:text-[#71717a]"),children:a.tasks.enabled?"Enabled":"Disabled"})]}),a.oauthEnabled&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md bg-[#F3F4F6] px-3 py-2 dark:bg-[#18181b]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase tracking-wide text-[#9CA3AF] dark:text-[#71717a]",children:"OAuth"}),e.jsx("span",{role:a.oauthStatus==="authorizing"?"status":void 0,className:w("text-[11px] font-mono",a.oauthStatus==="authenticated"?"text-[#16A34A] dark:text-[#22C55E]":a.oauthStatus==="error"?"text-[#ef4444]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:gt[a.oauthStatus]})]}),a.oauthStatus==="authenticated"?e.jsx("button",{type:"button",onClick:()=>void pe("logout",a),disabled:d!==null,className:"h-7 rounded-md border border-[#D1D5DB] px-2.5 text-[11px] font-mono text-[#374151] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#d4d4d8]",children:(d==null?void 0:d.type)==="logout"?"Signing out...":"Sign out"}):a.oauthStatus==="authorizing"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-3.5 w-3.5 animate-spin text-[#2563eb]","aria-hidden":"true"}),(j==null?void 0:j.serverName)===a.name?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex h-7 items-center rounded-md bg-[#2563eb] px-2.5 text-[11px] font-mono font-semibold text-white dark:bg-[#3b82f6]",children:"Continue authorization"}):e.jsx("button",{type:"button",onClick:()=>void pe("login",a),disabled:d!==null,className:"h-7 rounded-md border border-[#D1D5DB] px-2.5 text-[11px] font-mono text-[#374151] disabled:opacity-50 dark:border-[#3f3f46] dark:text-[#d4d4d8]",children:"Resume authorization"})]}):a.oauthStatus==="unavailable"?null:e.jsx("button",{type:"button",onClick:()=>void pe("login",a),disabled:d!==null,className:"h-7 rounded-md bg-[#2563eb] px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-50 dark:bg-[#3b82f6]",children:(d==null?void 0:d.type)==="login"?"Opening...":"Authorize"})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[a.status==="connected"||a.status==="reconnecting"?e.jsx("button",{onClick:()=>void fe("disconnect",a.name),disabled:d!==null,className:"h-7 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:(d==null?void 0:d.type)==="disconnect"&&d.name===a.name?"Disconnecting...":a.status==="reconnecting"?"Stop recovery":"Disconnect"}):e.jsx("button",{onClick:()=>void fe("connect",a.name),disabled:d!==null||a.oauthEnabled&&a.oauthStatus!=="authenticated",className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:(d==null?void 0:d.type)==="connect"&&d.name===a.name?"Connecting...":a.oauthEnabled&&a.oauthStatus!=="authenticated"?"Authorize first":"Connect"}),e.jsx("button",{onClick:()=>q(a.name),disabled:d!==null,className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold",children:"Delete"})]}),K===a.name&&e.jsxs("div",{role:"alertdialog","aria-label":`Delete ${a.name}`,className:"flex flex-wrap gap-2 justify-between items-center px-3 py-2 bg-red-50 rounded-md border border-red-200 dark:border-red-900/60 dark:bg-red-950/30",children:[e.jsx("span",{className:"text-[11px] font-mono text-red-700 dark:text-red-300",children:"Remove this server and its saved configuration?"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{type:"button",onClick:()=>q(null),className:"h-7 rounded-md px-2.5 text-[11px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>void fe("delete",a.name),disabled:d!==null,className:"h-7 rounded-md bg-red-600 px-2.5 text-[11px] font-mono font-semibold text-white disabled:opacity-60",children:(d==null?void 0:d.type)==="delete"?"Deleting...":"Delete server"})]})]}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Tools (",a.tools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.tools.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No tools available"}):a.tools.map(t=>e.jsx("span",{className:"px-2 py-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[11px] font-mono text-[#111827] dark:text-[#E5E5E5]",children:t},t))}),e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Argument completion"}),a.status!=="connected"?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"Connect the server to request suggestions"}):a.completionSupported?re.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No completable prompt arguments or template variables"}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{"aria-label":"MCP completion target",className:"flex max-h-20 flex-wrap gap-1 overflow-y-auto",children:re.map(t=>e.jsx("button",{type:"button","aria-pressed":(T==null?void 0:T.key)===t.key,onClick:()=>{z(t.key),_(null),J(null)},className:w("max-w-full truncate rounded px-2 py-1 text-[10px] font-mono",(T==null?void 0:T.key)===t.key?"bg-[#111827] text-white dark:bg-[#E5E5E5] dark:text-[#111827]":"bg-[#F3F4F6] text-[#6B7280] dark:bg-[#18181b] dark:text-[#a1a1aa]"),children:t.label},t.key))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text","aria-label":"MCP completion partial value",value:R,onChange:t=>U(t.target.value),placeholder:"Partial value",className:"h-8 min-w-0 flex-1 rounded-md border border-transparent bg-[#F3F4F6] px-3 text-[11px] font-mono text-[#111827] outline-none placeholder:text-[#9CA3AF] focus:border-[#D1D5DB] dark:bg-[#18181b] dark:text-[#E5E5E5] dark:placeholder:text-[#71717a] dark:focus:border-[#3f3f46]"}),e.jsx("button",{type:"button",onClick:()=>void We(a),disabled:H,className:"h-8 shrink-0 rounded-md bg-[#2563eb] px-3 text-[11px] font-mono font-semibold text-white disabled:opacity-50 dark:bg-[#3b82f6]",children:H?"Completing...":"Complete"})]}),Y&&e.jsx("span",{role:"alert",className:"text-[11px] font-mono text-red-600 dark:text-red-400",children:Y}),D&&e.jsxs("div",{"aria-label":"MCP completion suggestions",className:"rounded-md bg-[#F3F4F6] p-2 dark:bg-[#18181b]",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:D.values.length>0?D.values.map(t=>e.jsx("span",{className:"rounded bg-white px-2 py-1 text-[10px] font-mono text-[#111827] dark:bg-[#0C0C0C] dark:text-[#E5E5E5]",children:t||"[empty]"},t)):e.jsx("span",{className:"text-[10px] font-mono text-[#9CA3AF]",children:"No suggestions"})}),e.jsxs("span",{className:"mt-1 block truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",D.sha256,D.truncated?" · truncated":""]})]})]}):e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"Server does not advertise MCP completions"}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Diagnostics"}),e.jsx("button",{type:"button","aria-label":`Refresh ${a.name} MCP logs`,onClick:()=>void ne(a.name),disabled:ue,className:"flex h-7 w-7 items-center justify-center rounded-md text-[#9CA3AF] transition-colors hover:bg-[#E5E7EB] hover:text-[#111827] disabled:opacity-50 dark:text-[#71717a] dark:hover:bg-[#27272a] dark:hover:text-[#E5E5E5]",children:e.jsx(Be,{className:w("h-3.5 w-3.5",ue&&"animate-spin")})})]}),e.jsx("div",{"aria-label":"MCP logging level",className:"flex flex-wrap gap-1",children:vt.map(t=>{var i,l;return e.jsx("button",{type:"button",onClick:()=>void Ge(a,t),disabled:a.status!=="connected"||M!==null,"aria-pressed":(((i=a.logging)==null?void 0:i.level)??"warning")===t,className:w("rounded px-2 py-1 text-[10px] font-mono transition-colors disabled:opacity-40",(((l=a.logging)==null?void 0:l.level)??"warning")===t?"bg-[#111827] text-white dark:bg-[#E5E5E5] dark:text-[#111827]":"bg-[#F3F4F6] text-[#6B7280] hover:text-[#111827] dark:bg-[#18181b] dark:text-[#a1a1aa] dark:hover:text-[#E5E5E5]"),children:M===t?"Setting...":t},t)})}),Ee?e.jsx("div",{role:"alert",className:"rounded-md bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:bg-red-950/30 dark:text-red-300",children:Ee.message}):ae!=null&&ae.entries.length?e.jsx("div",{"aria-label":`${a.name} MCP logs`,className:"flex max-h-52 flex-col gap-1.5 overflow-y-auto rounded-md bg-[#F3F4F6] p-2 dark:bg-[#18181b]",children:ae.entries.map(t=>e.jsxs("div",{className:"rounded bg-white px-2.5 py-2 dark:bg-[#0C0C0C]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:w("text-[10px] font-mono font-semibold uppercase",["error","critical","alert","emergency"].includes(t.level)?"text-red-600 dark:text-red-400":t.level==="warning"?"text-amber-600 dark:text-amber-400":"text-[#2563eb] dark:text-[#60a5fa]"),children:t.level}),e.jsxs("span",{className:"truncate text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[t.logger||a.name," · r",t.revision]})]}),e.jsx("pre",{className:"mt-1 whitespace-pre-wrap break-words text-[11px] font-mono text-[#374151] dark:text-[#d4d4d8]",children:t.message}),e.jsxs("span",{className:"mt-1 block truncate text-[9px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["sha256 ",t.dataSha256,t.truncated?" · truncated":"",t.detailsOmitted?" · details omitted":""]})]},t.revision))}):e.jsx("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:ue?"Loading logs...":"No logs captured"})]}):e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsx("span",{className:"text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"Select a server to view details"})})]}):e.jsxs("div",{className:"flex flex-col flex-1 gap-4 min-h-0",children:[e.jsx("div",{className:"flex gap-3 items-center shrink-0",children:e.jsxs("div",{className:"flex-1 h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] flex items-center px-3 gap-2",children:[e.jsx(ot,{className:"h-3.5 w-3.5 text-[#9CA3AF] dark:text-[#71717a]"}),e.jsx("input",{type:"text","aria-label":"Search MCP server catalog",value:ce,onChange:t=>{Q(t.target.value),k(t.target.value)},placeholder:"Search MCP servers on npm (min 3 chars)...",className:"flex-1 bg-transparent text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none"})]})}),e.jsxs("div",{ref:v,className:"overflow-y-auto flex-1 min-h-0",children:[je?e.jsxs("div",{role:"alert",className:"flex flex-col gap-3 items-center py-12 font-mono text-center",children:[e.jsx(De,{className:"w-6 h-6 text-red-500"}),e.jsx("span",{className:"text-xs text-red-600 dark:text-red-400",children:je.message}),e.jsx("button",{type:"button",onClick:Ne,className:"rounded-md border border-[#E5E7EB] px-3 py-1.5 text-[11px] text-[#6B7280] dark:border-[#27272a] dark:text-[#a1a1aa]",children:"Retry catalog"})]}):He&&!A?e.jsx("div",{className:"flex justify-center items-center py-12",children:e.jsx(le,{className:"h-6 w-6 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}):e.jsxs("div",{className:"grid grid-cols-1 gap-3 pb-4 sm:grid-cols-2",children:[A==null?void 0:A.list.map(t=>{var we,Ae;const i=Ve.has(Ue(t.name).toLowerCase()),l=me===t.name,B=Qe(t);return e.jsxs("div",{className:"rounded-lg bg-white dark:bg-[#0C0C0C] p-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2 justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name}),e.jsx("span",{className:w("text-[10px] font-mono px-2 py-0.5 rounded shrink-0",B==="Official"?"bg-[#16A34A]/20 dark:bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:B})]}),e.jsx("p",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] line-clamp-2",children:t.description||"No description"}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[e.jsxs("span",{children:["v",t.version]}),((we=t.publisher)==null?void 0:we.username)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",t.publisher.username]})]})]}),e.jsxs("div",{className:"flex justify-between items-center pt-2 mt-auto",children:[e.jsxs("a",{href:((Ae=t.links)==null?void 0:Ae.npm)||`https://www.npmjs.com/package/${t.name}`,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a] hover:text-[#111827] dark:hover:text-[#E5E5E5] flex items-center gap-1",children:[e.jsx(Te,{className:"w-3 h-3"}),"npm"]}),i?e.jsxs("span",{className:"text-[11px] font-mono text-[#16A34A] dark:text-[#22C55E] flex items-center gap-1",children:[e.jsx(lt,{className:"w-3 h-3"}),"Installed"]}):e.jsxs("button",{onClick:()=>Ye(t),disabled:l,className:"h-6 px-2 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[10px] font-mono font-semibold flex items-center gap-1 hover:bg-[#D1D5DB] dark:hover:bg-[#32323a] disabled:opacity-50",children:[e.jsx(dt,{className:w("h-3 w-3",l&&"animate-pulse")}),l?"Installing...":"Install"]})]})]},t.name)}),(A==null?void 0:A.list.length)===0&&e.jsx("div",{className:"col-span-full py-12 text-center text-xs font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No packages found"})]}),Je&&e.jsx("div",{className:"flex justify-center items-center py-4",children:e.jsx(le,{className:"h-5 w-5 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}),qe&&A&&A.list.length>0&&e.jsx("div",{className:"text-center py-4 text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No more packages"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-[#E5E7EB] dark:border-[#1f2937] shrink-0",children:[e.jsxs("span",{className:"text-[11px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:[(A==null?void 0:A.total)??0," packages found"]}),e.jsxs("a",{href:"https://glama.ai/mcp/servers",target:"_blank",rel:"noopener noreferrer",className:"text-[11px] font-mono text-[#3b82f6] hover:underline flex items-center gap-1",children:["Browse more on Glama",e.jsx(Te,{className:"w-3 h-3"})]})]})]})]})})]})}),e.jsx(yt,{open:f,onOpenChange:x,onAdd:Ce,saving:ye,error:(V==null?void 0:V.message)??null}),G&&e.jsx(wt,{pkg:G,onClose:()=>m(null),installing:ye,error:(V==null?void 0:V.message)??null,onInstall:t=>(X(G.name),Ce(t))})]})}function Ie({active:n,children:s,onClick:o}){return e.jsx("button",{onClick:o,className:w("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",n?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:s})}function yt({open:n,onOpenChange:s,onAdd:o,saving:u,error:f}){const[x,c]=r.useState("form"),[p,h]=r.useState(""),[b,S]=r.useState(""),[g,j]=r.useState(""),[C,d]=r.useState(null),[F,M]=r.useState(`{
|
|
2
|
-
"name": "my-server",
|
|
3
|
-
"command": "npx",
|
|
4
|
-
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
5
|
-
}`);r.useEffect(()=>{n&&d(null)},[n]);const O=async()=>{if(d(null),x==="json"){let N;try{N=JSON.parse(F)}catch{d("Enter valid JSON with a server name and transport.");return}await o(N).catch(()=>{})}else{if(!p||!b){d("Name and command are required.");return}await o({name:p,command:b,args:g.split(" ").filter(Boolean)}).catch(()=>{})}};return e.jsx(he,{open:n,onOpenChange:s,children:e.jsxs(be,{onCloseAutoFocus:N=>rt("[data-mcp-add-server-trigger]",N),className:"gap-0 overflow-y-auto rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[540px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(ge,{className:"sr-only",children:"Add MCP Server"}),e.jsxs("div",{className:"flex flex-col gap-4 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Add MCP Server"}),e.jsx("button",{onClick:()=>s(!1),"aria-label":"Close add MCP server",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(ve,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 p-1 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] w-fit",children:[e.jsx(_e,{active:x==="form",onClick:()=>c("form"),children:"Form"}),e.jsx(_e,{active:x==="json",onClick:()=>c("json"),children:"JSON"})]}),x==="json"?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"JSON config"}),e.jsx("textarea",{"aria-label":"JSON configuration",className:"min-h-[140px] rounded-md bg-white dark:bg-[#0C0C0C] text-[#111827] dark:text-[#E5E5E5] font-mono text-[12px] p-3 border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:border-[#27272a]",value:F,onChange:N=>M(N.target.value)})]}):e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Server name"}),e.jsx("input",{"aria-label":"Server name",type:"text",value:p,onChange:N=>h(N.target.value),placeholder:"my-server",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:border-[#27272a]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Command"}),e.jsx("input",{"aria-label":"Server command",type:"text",value:b,onChange:N=>S(N.target.value),placeholder:"npx",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:border-[#27272a]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Arguments (space separated)"}),e.jsx("input",{"aria-label":"Server arguments",type:"text",value:g,onChange:N=>j(N.target.value),placeholder:"-y @modelcontextprotocol/server-filesystem /tmp",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:border-[#27272a]"})]})]}),(C||f)&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:C||f}),e.jsxs("div",{className:"flex gap-2 justify-end items-center pt-2",children:[e.jsx("button",{onClick:()=>s(!1),className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Cancel"}),e.jsx("button",{onClick:()=>void O(),disabled:u,className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold disabled:opacity-60",children:u?"Adding...":"Add Server"})]})]})]})})}function wt({pkg:n,onClose:s,onInstall:o,installing:u,error:f}){const x=Ue(n.name),[c,p]=r.useState(x),[h,b]=r.useState(`-y ${n.name}`),[S,g]=r.useState(null),j=async()=>{if(g(null),!c.trim()){g("Server name is required.");return}await o({name:c.trim(),command:"npx",args:h.split(" ").filter(Boolean)}).catch(()=>{})};return e.jsx(he,{open:!0,onOpenChange:s,children:e.jsxs(be,{className:"gap-0 overflow-y-auto rounded-xl border border-[#E5E7EB] bg-white p-0 dark:border-zinc-800 dark:bg-[#09090b] sm:max-w-[480px]","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsxs(ge,{className:"sr-only",children:["Install ",n.name]}),e.jsxs("div",{className:"flex flex-col gap-4 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Install MCP Server"}),e.jsx("button",{onClick:s,"aria-label":"Close MCP installation",className:"h-8 w-8 rounded-md text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] transition-colors flex items-center justify-center",children:e.jsx(ve,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"rounded-md bg-white dark:bg-[#0C0C0C] p-3",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:n.name}),e.jsx("p",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] mt-1",children:n.description||"No description"})]}),e.jsx("div",{className:"h-px bg-[#E5E7EB] dark:bg-[#1f2937]"}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Server name"}),e.jsx("input",{"aria-label":"Server name",type:"text",value:c,onChange:C=>p(C.target.value),placeholder:"my-server",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:border-[#27272a]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:"Arguments"}),e.jsx("input",{"aria-label":"Server arguments",type:"text",value:h,onChange:C=>b(C.target.value),placeholder:"-y package-name",className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] px-3 text-[12px] font-mono text-[#111827] dark:text-[#E5E5E5] border border-transparent focus:outline-none focus:border-[#E5E7EB] dark:border-[#27272a]"}),e.jsxs("span",{className:"text-[10px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:["Command: npx ",h]})]})]}),(S||f)&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-mono text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300",children:S||f}),e.jsxs("div",{className:"flex gap-2 justify-end items-center pt-2",children:[e.jsx("button",{onClick:s,className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Cancel"}),e.jsx("button",{onClick:()=>void j(),disabled:u,className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold disabled:opacity-60",children:u?"Installing...":"Install"})]})]})]})})}function _e({active:n,children:s,onClick:o}){return e.jsx("button",{onClick:o,className:w("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",n?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:s})}export{Dt as McpModal};
|