blade-code 0.7.6 → 0.7.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-npaj13y3.js → chunk-0e0z8yc1.js} +2 -2
- package/dist/{chunk-fceeqn6k.js → chunk-1w6tqkxd.js} +2 -2
- package/dist/{chunk-ttf06k8y.js → chunk-2049tv49.js} +3 -3
- package/dist/chunk-4745ktjj.js +1570 -0
- package/dist/chunk-48q9msfk.js +615 -0
- package/dist/chunk-4dmdn3a9.js +2 -0
- package/dist/{chunk-zr71r1z1.js → chunk-5be6qr2v.js} +1 -1
- package/dist/chunk-67vzgcs5.js +2 -0
- package/dist/{chunk-krrm6bjr.js → chunk-6811kbxn.js} +1 -1
- package/dist/{chunk-d9qh7bat.js → chunk-6hn2jgw5.js} +1 -1
- package/dist/chunk-6js5wp6t.js +1 -0
- package/dist/chunk-6kp3z956.js +9 -0
- package/dist/{chunk-pf45ctn7.js → chunk-71n472hj.js} +1 -1
- package/dist/chunk-78txnq4n.js +151 -0
- package/dist/chunk-7r1hm0qz.js +6 -0
- package/dist/{chunk-1y33d6xh.js → chunk-9kejtkey.js} +1 -1
- package/dist/chunk-a7yjnqhd.js +3 -0
- package/dist/chunk-bwaqaktn.js +1 -0
- package/dist/chunk-cb82rf5h.js +1 -0
- package/dist/chunk-ce11m8bq.js +1 -0
- package/dist/{chunk-m3hsaaq5.js → chunk-cjmxggke.js} +1 -1
- package/dist/chunk-e4rhdg3h.js +1 -0
- package/dist/{chunk-64x50qbc.js → chunk-f9ybv4ph.js} +1 -1
- package/dist/{chunk-x4fx52e7.js → chunk-faq7ay4j.js} +3 -3
- package/dist/{chunk-jhzf05kz.js → chunk-fb7amc2s.js} +1 -1
- package/dist/chunk-g6ted982.js +4 -0
- package/dist/{chunk-qyfdt8h1.js → chunk-g7caymjr.js} +1 -1
- package/dist/{chunk-ezkbqmvd.js → chunk-jm2xhnrv.js} +1 -1
- package/dist/chunk-ky8ctbdc.js +1 -0
- package/dist/chunk-mpskff34.js +1 -0
- package/dist/chunk-pd1yqxcv.js +9 -0
- package/dist/{chunk-arwynrtf.js → chunk-phhmmybg.js} +2 -2
- package/dist/chunk-qnevwq1q.js +2 -0
- package/dist/{chunk-ebynn53v.js → chunk-r1spf93b.js} +2 -2
- package/dist/{chunk-r0hc7wad.js → chunk-rnfd5ebv.js} +1 -1
- package/dist/{chunk-wg5nxtb2.js → chunk-s4mke0t6.js} +1 -1
- package/dist/{chunk-wstkn75a.js → chunk-t2spryz0.js} +1 -1
- package/dist/{chunk-rhvxr82g.js → chunk-t70aqrm4.js} +1 -1
- package/dist/{chunk-10q3krvh.js → chunk-z4c68ve0.js} +1 -1
- package/dist/chunk-z9zbcenc.js +6 -0
- package/dist/web/assets/{CodeBlockHighlighter-C86flFwh.js → CodeBlockHighlighter-C1cp8dDv.js} +1 -1
- package/dist/web/assets/FilePreview-DRKRs8i2.js +7 -0
- package/dist/web/assets/{MarkdownRenderer-CW8WpEw1.js → MarkdownRenderer-DFqPpAnM.js} +1 -1
- package/dist/web/assets/{McpModal-DnqrgBON.js → McpModal-CX5-hlNv.js} +1 -1
- package/dist/web/assets/{SettingsModal-CRNT-LCq.js → SettingsModal-CfR_q6N7.js} +1 -1
- package/dist/web/assets/{SettingsStore-B2GIhfKs.js → SettingsStore-jup_Kikq.js} +1 -1
- package/dist/web/assets/{SkillsModal-COQMbIdT.js → SkillsModal-DaAUrwXO.js} +1 -1
- package/dist/web/assets/{TerminalPanel-dCMUvQaH.js → TerminalPanel-DzlllDH7.js} +1 -1
- package/dist/web/assets/index-BJTSF3fc.js +9 -0
- package/dist/web/assets/index-CL6apjgo.css +1 -0
- package/dist/web/assets/{useRequest-C7k7cDPD.js → useRequest-DITGl55G.js} +1 -1
- package/dist/web/assets/{vendor-icons-BKXQ7ALf.js → vendor-icons-BuFpOlRn.js} +38 -28
- package/dist/web/assets/{vendor-markdown-DIcugY1e.js → vendor-markdown-Bo4W9Tae.js} +1 -1
- package/dist/web/assets/vendor-radix-CESj0OOY.js +45 -0
- package/dist/web/assets/{vendor-react-Dm1xU4bP.js → vendor-react-BalntB5F.js} +2 -2
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/chunk-1tzcptyb.js +0 -3
- package/dist/chunk-5accz8n9.js +0 -1
- package/dist/chunk-8raa4q9y.js +0 -1564
- package/dist/chunk-ad19yrq6.js +0 -1
- package/dist/chunk-bvn4e2vq.js +0 -1
- package/dist/chunk-cadngkwr.js +0 -2
- package/dist/chunk-cdx3hp1r.js +0 -9
- package/dist/chunk-g60w2r7f.js +0 -6
- package/dist/chunk-h7qab07x.js +0 -2
- package/dist/chunk-k76q8cyc.js +0 -151
- package/dist/chunk-n2yq1wn8.js +0 -9
- package/dist/chunk-q6sj33v8.js +0 -6
- package/dist/chunk-qedtzcp2.js +0 -1
- package/dist/chunk-t6qek6xk.js +0 -1
- package/dist/chunk-tyjns370.js +0 -1
- package/dist/chunk-ve6bvba4.js +0 -615
- package/dist/chunk-wdxbjvd5.js +0 -2
- package/dist/chunk-xj63cr29.js +0 -1
- package/dist/chunk-zmndvdgb.js +0 -4
- package/dist/web/assets/FilePreview-CbtOITD1.js +0 -7
- package/dist/web/assets/index-21gV5nOE.css +0 -1
- package/dist/web/assets/index-Cnz-_jPt.js +0 -10
- package/dist/web/assets/vendor-radix-2yBsoRqx.js +0 -45
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Ja as d,La as h}from"./chunk-phhmmybg.js";var q={debug:{alias:"d",type:"string",describe:'Enable debug mode with optional category filtering (e.g., "agent,ui" or "!chat,!loop")',group:"Debug Options:"},model:{type:"string",describe:"Override the current run model using a model config ID (TUI / print / headless)",group:"AI Options:"},print:{alias:"p",type:"boolean",describe:"Print response and exit (useful for pipes)",group:"Output Options:"},headless:{type:"boolean",describe:"Run full agent loop without Ink UI and print all events to the terminal",group:"Output Options:"},"output-format":{alias:["outputFormat"],type:"string",choices:["text","json","stream-json","jsonl"],default:"text",describe:"Output format: --print supports text|json|stream-json; --headless supports text|jsonl",group:"Output Options:"},"include-partial-messages":{alias:["includePartialMessages"],type:"boolean",describe:"Include partial message chunks as they arrive",group:"Output Options:"},"input-format":{alias:["inputFormat"],type:"string",choices:["text","stream-json"],default:"text",describe:"Input format",group:"Input Options:"},"replay-user-messages":{alias:["replayUserMessages"],type:"boolean",describe:"Re-emit user messages from stdin",group:"Input Options:"},"allowed-tools":{alias:["allowedTools"],type:"array",string:!0,describe:"Comma or space-separated list of tool names to allow",group:"Security Options:"},"disallowed-tools":{alias:["disallowedTools"],type:"array",string:!0,describe:"Comma or space-separated list of tool names to deny",group:"Security Options:"},"mcp-config":{alias:["mcpConfig"],type:"array",string:!0,describe:"Load MCP servers from JSON files or strings",group:"MCP Options:"},"system-prompt":{alias:["systemPrompt"],type:"string",describe:"System prompt to use for the session (replaces default)",group:"AI Options:"},"append-system-prompt":{alias:["appendSystemPrompt"],type:"string",describe:"Append a system prompt to the default system prompt",group:"AI Options:"},"max-turns":{alias:["maxTurns"],type:"number",describe:"Maximum conversation turns (-1: unlimited, 0: disable chat, N>0: limit to N turns)",group:"AI Options:",default:void 0},"permission-mode":{alias:["permissionMode"],type:"string",choices:["default","autoEdit","yolo","plan"],describe:"Permission mode (default: ask for non-read tools, autoEdit: auto-approve edits, yolo: auto-approve all, plan: reserved)",group:"Security Options:"},yolo:{type:"boolean",describe:"Auto-approve all tools (shortcut for --permission-mode=yolo)",group:"Security Options:"},continue:{alias:"c",type:"boolean",describe:"Continue the most recent conversation",group:"Session Options:"},resume:{alias:"r",describe:"Resume a conversation - provide a session ID or interactively select a conversation to resume",group:"Session Options:",coerce:(b)=>{if(b===void 0||b===!0||b==="")return"true";return String(b)}},"fork-session":{alias:["forkSession"],type:"boolean",describe:"Create a new session ID when resuming",group:"Session Options:"},settings:{type:"string",describe:"Path to a settings JSON file or JSON string",group:"Configuration:"},"add-dir":{alias:["addDir"],type:"array",string:!0,describe:"Additional directories to allow tool access to",group:"Security Options:"},ide:{type:"boolean",describe:"Automatically connect to IDE on startup",group:"Integration:"},acp:{type:"boolean",describe:"Run in ACP (Agent Client Protocol) mode for IDE integration",group:"Integration:"},"strict-mcp-config":{alias:["strictMcpConfig"],type:"boolean",describe:"Only use MCP servers from --mcp-config",group:"MCP Options:"},"session-id":{alias:["sessionId"],type:"string",describe:"Use a specific session ID for the conversation",group:"Session Options:"},agents:{type:"string",describe:"JSON object defining custom agents",group:"AI Options:"},"setting-sources":{alias:["settingSources"],type:"string",describe:"Comma-separated list of setting sources to load",group:"Configuration:"},"plugin-dir":{alias:["pluginDir"],type:"array",string:!0,describe:"Load plugins from specified directories",group:"Plugin Options:"}},w={scriptName:"blade",usage:"$0 [command] [options]",description:h(),version:d(),locale:"en",showHelpOnFail:!0,demandCommand:!1,recommendCommands:!0,strict:!1};
|
|
2
2
|
export{q as t,w as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-
|
|
1
|
+
import"./chunk-f9ybv4ph.js";var d={command:"install [target]",describe:"Install Blade native build. Use [target] to specify version (stable, latest, or specific version)",builder:(b)=>{return b.positional("target",{describe:"Version to install",type:"string",default:"stable",choices:["stable","latest"]}).option("force",{type:"boolean",describe:"Force reinstall",default:!1}).example([["$0 install","Install stable version"],["$0 install latest","Install latest version"],["$0 install --force","Force reinstall stable version"]])},handler:async(b)=>{console.log(`Installing Blade ${b.target}...`);try{if(b.force)console.log("Force reinstall enabled");console.log("Downloading..."),console.log("Installing..."),console.log("Installation completed successfully")}catch(c){console.error(`Error: Installation failed: ${c instanceof Error?c.message:"未知错误"}`),process.exit(1)}}};export{d as installCommands};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{nanoid as q}from"nanoid";var u=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function B(j="session",m=21){if(!u.test(j))throw Error(`Invalid session ID prefix: ${j}`);return`${j}-${q(m)}`}
|
|
2
|
-
export{B as
|
|
2
|
+
export{B as vb};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{p as A,q as E,r as N,s as f}from"./chunk-
|
|
1
|
+
import{p as A,q as E,r as N,s as f}from"./chunk-g6ted982.js";import{t as D}from"./chunk-s4mke0t6.js";import{v as L,w as _,x}from"./chunk-7r1hm0qz.js";import{y as B}from"./chunk-qnevwq1q.js";import{L as $,T as b}from"./chunk-4745ktjj.js";import"./chunk-g7caymjr.js";import"./chunk-1w6tqkxd.js";import"./chunk-0e0z8yc1.js";import"./chunk-faq7ay4j.js";import"./chunk-r1spf93b.js";import"./chunk-phhmmybg.js";import{$a as Z}from"./chunk-48q9msfk.js";import"./chunk-jm2xhnrv.js";import"./chunk-2049tv49.js";import"./chunk-t70aqrm4.js";import{Ab as Y,Bb as T}from"./chunk-4dmdn3a9.js";import"./chunk-6kp3z956.js";import"./chunk-a7yjnqhd.js";import"./chunk-f9ybv4ph.js";import h from"yargs";import{hideBin as R}from"yargs/helpers";var w=new Set(Object.values(Y));function X(k){if(k&&w.has(k))return k;return}function M(k){return k.command("* [message]","Print response and exit (useful for pipes)",(F)=>F.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(F)=>{if(!F.p)return;let q=await O(F);process.exit(q)})}async function O(k,F=process){let q;try{await A();let J=await E({message:k.message,_:k._,defaultMessage:"Hello"}),G=await N(J);if(G.mode==="output"){if(G.content)F.stdout.write(`${G.content}
|
|
2
2
|
`);return G.exitCode??0}let Q=G.content,{sessionId:K,messages:U}=await f({sessionId:k.sessionId,continue:k.continue,resume:k.resume,forkSession:k.forkSession,fallbackSessionPrefix:"print"});q=await $.create({sessionId:K,workspaceRoot:T(),modelId:k.model,mcpConfig:k.mcpConfig,strictMcpConfig:k.strictMcpConfig,agents:k.agents?B(k.agents):void 0});let V=await b.createWithRuntime(q,{sessionId:K,systemPrompt:k.systemPrompt,appendSystemPrompt:k.appendSystemPrompt,maxTurns:k.maxTurns,modelId:k.model,permissionMode:X(k.permissionMode),toolWhitelist:k.allowedTools,toolBlacklist:k.disallowedTools,mcpConfig:k.mcpConfig,strictMcpConfig:k.strictMcpConfig}),H=(await Z(V.chatStream(Q,{messages:[...U],userId:"cli-user",sessionId:K,workspaceRoot:T(),permissionMode:X(k.permissionMode)}))).finalMessage||"";if(k.outputFormat==="json")F.stdout.write(`${JSON.stringify({response:H,input:Q,model:k.model,timestamp:new Date().toISOString()},null,2)}
|
|
3
3
|
`);else if(k.outputFormat==="stream-json")F.stdout.write(`${JSON.stringify({type:"response",content:H})}
|
|
4
4
|
`);else F.stdout.write(`${H}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{p as v,q as u,r as m,s as l}from"./chunk-g6ted982.js";import{t as g}from"./chunk-s4mke0t6.js";import{v as z,w as p,x as d}from"./chunk-7r1hm0qz.js";import{y as c}from"./chunk-qnevwq1q.js";import{L as C,P as E,Q as S,S as W,T as h}from"./chunk-4745ktjj.js";import"./chunk-g7caymjr.js";import"./chunk-1w6tqkxd.js";import"./chunk-0e0z8yc1.js";import"./chunk-faq7ay4j.js";import"./chunk-r1spf93b.js";import"./chunk-phhmmybg.js";import{$a as y}from"./chunk-48q9msfk.js";import"./chunk-jm2xhnrv.js";import"./chunk-2049tv49.js";import"./chunk-t70aqrm4.js";import{Ab as F,Bb as L,Cb as w}from"./chunk-4dmdn3a9.js";import"./chunk-6kp3z956.js";import"./chunk-a7yjnqhd.js";import"./chunk-f9ybv4ph.js";import Mq from"yargs";import{hideBin as Rq}from"yargs/helpers";import{z as X}from"zod";import{z as Y}from"zod";var k=1,_=Y.object({event_version:Y.literal(k)}),t=_.extend({type:Y.literal("content_delta"),delta:Y.string()}),e=_.extend({type:Y.literal("thinking_delta"),delta:Y.string()}),qq=_.extend({type:Y.literal("thinking"),content:Y.string()}),Qq=_.extend({type:Y.literal("stream_end")}),Yq=_.extend({type:Y.literal("content"),content:Y.string()}),Zq=_.extend({type:Y.literal("tool_start"),tool_name:Y.string(),summary:Y.string(),target:Y.string().optional(),tool_kind:Y.enum(["readonly","write","execute"]).optional()}),$q=_.extend({type:Y.literal("tool_result"),tool_name:Y.string(),summary:Y.string(),target:Y.string().optional(),tool_kind:Y.enum(["readonly","write","execute"]).optional(),success:Y.boolean().optional(),error_type:Y.string().optional(),error_message:Y.string().optional()}),Gq=_.extend({type:Y.literal("phase"),phase:Y.enum(["turn","searching","inspecting","target_hit","executing","completed"]),status:Y.enum(["ongoing","hit","done"]),message:Y.string(),turn:Y.number().optional(),tool_name:Y.string().optional(),target:Y.string().optional()}),Xq=_.extend({type:Y.literal("tool_detail"),tool_name:Y.string(),detail:Y.string()}),Uq=_.extend({type:Y.literal("task_update"),tasks:Y.array(W)}),Kq=_.extend({type:Y.literal("subagent"),state:Y.enum(["spawned","completed"]),session_id:Y.string(),subagent_type:Y.string().optional(),success:Y.boolean().optional(),summary:Y.string().optional(),resumed_from:Y.string().optional(),root_agent_id:Y.string().optional(),resume_depth:Y.number().int().nonnegative().optional()}),Vq=_.extend({type:Y.literal("token_usage"),input_tokens:Y.number(),output_tokens:Y.number(),total_tokens:Y.number(),max_context_tokens:Y.number()}),Dq=_.extend({type:Y.literal("compacting"),state:Y.enum(["started","completed"])}),bq=_.extend({type:Y.literal("turn_limit"),turns_count:Y.number(),action:Y.literal("continue")}),_q=_.extend({type:Y.literal("output"),content:Y.string(),exit_code:Y.number()}),Aq=_.extend({type:Y.literal("error"),message:Y.string()}),wq=Y.discriminatedUnion("type",[t,e,qq,Qq,Yq,Zq,$q,Gq,Xq,Uq,Kq,Vq,Dq,bq,_q,Aq]);function H(Q,$){return{event_version:k,type:Q,...$}}function jq(Q){if(Q?.signal)return{signal:Q.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 fq=X.enum(["text","jsonl"]),Iq=X.object({headless:X.boolean().optional(),message:X.string().optional(),_:X.array(X.union([X.string(),X.number()])).optional(),model:X.string().optional(),systemPrompt:X.string().optional(),appendSystemPrompt:X.string().optional(),maxTurns:X.number().int().max(w).refine((Q)=>Q===-1||Q>0,{message:"must be -1 or a positive integer"}).optional(),permissionMode:X.nativeEnum(F).optional(),mcpConfig:X.array(X.string()).optional(),strictMcpConfig:X.boolean().optional(),sessionId:X.string().optional(),allowedTools:X.array(X.string()).optional(),disallowedTools:X.array(X.string()).optional(),agents:X.string().optional(),continue:X.boolean().optional(),resume:X.union([X.string(),X.boolean()]).optional(),forkSession:X.boolean().optional(),outputFormat:fq.optional()});class i{openedThinking=!1;wroteAssistantContent=!1;markAssistantContent(){this.wroteAssistantContent=!0}setThinkingOpened(Q){this.openedThinking=Q}hasOpenThinking(){return this.openedThinking}completeStream(){let Q={openedThinking:this.openedThinking,wroteAssistantContent:this.wroteAssistantContent};return this.openedThinking=!1,this.wroteAssistantContent=!1,Q}}function Bq(Q){return Q.issues.map(($)=>`${$.path.join(".")||"options"}: ${$.message}`).join("; ")}function Jq(Q){let $=Iq.safeParse(Q);if(!$.success)throw Error(`Invalid headless options: ${Bq($.error)}`);return $.data}function Pq(Q){return Q.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"}),async($)=>{if(!$.headless)return;let G=await Hq($);process.exit(G)})}function A(Q,$=""){Q.write(`${$}
|
|
2
|
+
`)}function xq(Q){return`[task] [${Q.status}] ${Q.subject}`}function Lq(){return{requestConfirmation:async(Q)=>({approved:!0,reason:"headless-auto-approved",scope:"session"})}}function Nq(Q){if(!(Q instanceof Error))return"Unknown error";let q=Q.lastError??Q;if(q.responseBody)try{let V=JSON.parse(q.responseBody)?.error?.message;if(V)return q.statusCode?`${V} (HTTP ${q.statusCode})`:V}catch{}let Z=Q.message.match(/Last error:\s*(.+)$/);if(Z)return Z[1];return Q.message}function Wq(Q){return Q==="jsonl"?"jsonl":"text"}function T(Q,$){let G=(...q)=>{for(let Z of q){let b=$[Z];if(typeof b==="string"&&b.trim()!=="")return b}return};switch(Q){case"Read":case"Edit":case"Write":case"UndoEdit":return G("file_path");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 kq(Q,$,G,q){let Z=new Set(["Glob","Grep","WebSearch","LS"]),b=new Set(["Read","WebFetch"]);if(new Set(["Edit","Write","NotebookEdit","Bash","LSP","UndoEdit","EnterWorktree","ExitWorktree"]).has(Q)&&!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(Z.has(Q))return{phase:"searching",status:"ongoing",message:`Still searching: ${$}`,shouldLockTarget:!1};if(b.has(Q))return{phase:"inspecting",status:"ongoing",message:`Inspecting candidate: ${$}`,shouldLockTarget:!1};return{phase:"executing",status:q.targetLocked?"hit":"ongoing",message:`Executing: ${$}`,shouldLockTarget:!1}}function O(Q,$){let G=(q,Z)=>{Q.stdout.write(`${JSON.stringify(H(q,Z))}
|
|
3
|
+
`)};return{contentDelta(q){if($==="jsonl"){G("content_delta",{delta:q});return}Q.stdout.write(q)},thinkingDelta(q,Z){if($==="jsonl")return G("thinking_delta",{delta:q}),Z;if(!Z)Q.stderr.write("[thinking] ");return Q.stderr.write(q),!0},thinking(q){if($==="jsonl"){G("thinking",{content:q});return}A(Q.stderr,`[thinking] ${q}`)},streamEnd(q,Z){if($==="jsonl"){G("stream_end",{});return}if(Z)Q.stderr.write(`
|
|
4
|
+
`);if(q)Q.stdout.write(`
|
|
5
|
+
`)},content(q){if($==="jsonl"){G("content",{content:q});return}A(Q.stdout,q)},toolStart(q,Z,b,V){if($==="jsonl"){G("tool_start",{tool_name:q,summary:Z,target:b,tool_kind:V});return}A(Q.stderr,`[tool:start] ${Z}`)},toolResult(q,Z,b,V,M){if($==="jsonl"){G("tool_result",{tool_name:q,summary:Z,target:b,tool_kind:V,success:M?.success,error_type:M?.errorType,error_message:M?.errorMessage});return}A(Q.stderr,`[tool:result] ${Z}`)},phase(q,Z,b,V={}){if($==="jsonl"){G("phase",{phase:q,status:Z,message:b,turn:V.turn,tool_name:V.toolName,target:V.target});return}A(Q.stderr,`[phase:${q}] ${b}`)},toolDetail(q,Z){if($==="jsonl"){G("tool_detail",{tool_name:q,detail:Z});return}A(Q.stderr,Z)},taskUpdate(q){if($==="jsonl"){G("task_update",{tasks:q});return}for(let Z of q)A(Q.stderr,xq(Z))},subagent(q){let Z=q.kind==="subagent_spawned";if($==="jsonl"){G("subagent",{state:Z?"spawned":"completed",session_id:q.sessionId,subagent_type:Z?q.type:void 0,success:Z?void 0:q.success,summary:Z?void 0:q.summary,resumed_from:q.resumedFrom,root_agent_id:q.rootAgentId,resume_depth:q.resumeDepth});return}A(Q.stderr,`[subagent:${Z?"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});return}A(Q.stderr,`[tokens] in=${q.inputTokens} out=${q.outputTokens} total=${q.totalTokens} / ${q.maxContextTokens}`)},compacting(q){if($==="jsonl"){G("compacting",{state:q?"started":"completed"});return}A(Q.stderr,q?"[context] compacting started":"[context] compacting completed")},turnLimit(q){if($==="jsonl"){G("turn_limit",{turns_count:q,action:"continue"});return}A(Q.stderr,`[turn-limit] continuing after ${q} turns`)},output(q,Z=0){if($==="jsonl"){G("output",{content:q,exit_code:Z});return}A(Z===0?Q.stdout:Q.stderr,q)},error(q){if($==="jsonl"){G("error",{message:q});return}A(Q.stderr,q)}}}async function Hq(Q,$={stdout:process.stdout,stderr:process.stderr},G){let q="text",Z=O($,q),b=new i,V={targetLocked:!1},M,R=jq(G);try{let K=Jq(Q);q=Wq(K.outputFormat),Z=O($,q),await v();let r=await u(K),j=await m(r);if(j.mode==="output"){if(j.content)Z.output(j.content,j.exitCode??0);return j.exitCode??0}let N=K.permissionMode??"yolo",{sessionId:P,messages:n}=await l({sessionId:K.sessionId,continue:K.continue,resume:K.resume,forkSession:K.forkSession,fallbackSessionPrefix:"headless"}),s={messages:[...n],userId:"cli-user",sessionId:P,workspaceRoot:L(),permissionMode:N,signal:R.signal,confirmationHandler:Lq()};M=await C.create({sessionId:P,workspaceRoot:L(),modelId:K.model,mcpConfig:K.mcpConfig,strictMcpConfig:K.strictMcpConfig,agents:K.agents?c(K.agents):void 0});let o=K.maxTurns??M.getConfig().maxTurns,a=await h.createWithRuntime(M,{sessionId:P,systemPrompt:K.systemPrompt,appendSystemPrompt:K.appendSystemPrompt,maxTurns:K.maxTurns,modelId:K.model,permissionMode:N,toolWhitelist:K.allowedTools,toolBlacklist:K.disallowedTools,mcpConfig:K.mcpConfig,strictMcpConfig:K.strictMcpConfig}),x=await y(a.chatStream(j.content,s,{stream:!0,signal:R.signal,maxTurns:K.maxTurns,...o===-1?{onTurnLimitReached:async(D)=>{return Z.turnLimit(D.turnsCount),{continue:!0,reason:"headless-auto-continue"}}}:{}}),async(D)=>{switch(D.kind){case"content_delta":b.markAssistantContent(),Z.contentDelta(D.delta);break;case"thinking_delta":b.setThinkingOpened(Z.thinkingDelta(D.delta,b.hasOpenThinking()));break;case"stream_end":{let U=b.completeStream();Z.streamEnd(U.wroteAssistantContent,U.openedThinking);break}case"tool_start":{let U=D.toolCall;if(!("function"in U))break;if(["TaskCreate","TaskUpdate","TaskList"].includes(U.function.name))break;try{let f=JSON.parse(U.function.arguments),I=E(U.function.name,f),B=T(U.function.name,f),J=kq(U.function.name,I,B,V);if(J.shouldLockTarget)V.targetLocked=!0;Z.phase(J.phase,J.status,J.message,{toolName:U.function.name,target:B}),Z.toolStart(U.function.name,I,B,D.toolKind)}catch{Z.phase(V.targetLocked?"executing":"searching",V.targetLocked?"hit":"ongoing",V.targetLocked?`Working within target: ${U.function.name}`:`Still searching: ${U.function.name}`,{toolName:U.function.name}),Z.toolStart(U.function.name,U.function.name,void 0,D.toolKind)}break}case"tool_result":{let U=D.toolCall;if(!("function"in U))break;let f;try{let B=JSON.parse(U.function.arguments);f=T(U.function.name,B)}catch{f=void 0}let I=S(U.function.name,D.result);if(Z.toolResult(U.function.name,I.summary,f,void 0,{success:D.result.success,errorType:D.result.error?.type,errorMessage:D.result.error?.message}),I.detail)Z.toolDetail(U.function.name,I.detail);break}case"token_usage":Z.tokenUsage(D.usage);break;case"compaction":Z.compacting(D.phase==="start");break;case"task_update":Z.taskUpdate(D.tasks);break;case"steering_applied":case"follow_up_started":case"goal_updated":case"goal_continuation_started":break;case"subagent_spawned":case"subagent_completed":Z.subagent(D);break;case"model_fallback":break;case"turn_start":if(D.turn===1)V.targetLocked=!1;Z.phase("turn",V.targetLocked?"hit":"ongoing",`Turn ${D.turn} started`,{turn:D.turn});break;default:{let U=D}}});if(x.metadata?.outputTruncated)Z.error("[warning] 输出因达到 token 上限被截断,部分内容可能不完整。");if(!x.success)return Z.error(`Error: ${x.error?.message??"Agent execution failed"}`),1;return Z.phase("completed","done","Headless run completed"),0}catch(K){if(b.hasOpenThinking()&&q==="text")$.stderr.write(`
|
|
6
|
+
`);return Z.error(`Error: ${Nq(K)}`),1}finally{try{await M?.dispose()}finally{R.dispose()}}}async function sq(){if(!process.argv.slice(2).includes("--headless"))return!1;let{headless:G,"output-format":q,"system-prompt":Z,"append-system-prompt":b,"max-turns":V,...M}=g,R=Mq(Rq(process.argv)).scriptName("blade").strict(!1).options(M).middleware([p,z,d]);return Pq(R),await R.parse(),!0}export{Hq as runHeadless,sq as handleHeadlessMode,Iq as HeadlessOptionsSchema};
|
package/dist/web/assets/{CodeBlockHighlighter-C86flFwh.js → CodeBlockHighlighter-C1cp8dDv.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as L}from"./vendor-react-
|
|
1
|
+
import{j as L}from"./vendor-react-BalntB5F.js";import{S as e,v as p,o as l,b as s,s as h,a as m,d as c,j as a,e as d,f as y,m as g,p as r,h as j,t as x,i as t,y as i}from"./vendor-markdown-Bo4W9Tae.js";import"./vendor-monaco-w6PwaWGP.js";e.registerLanguage("bash",s);e.registerLanguage("sh",s);e.registerLanguage("shell",s);e.registerLanguage("shell-session",h);e.registerLanguage("css",m);e.registerLanguage("diff",c);e.registerLanguage("javascript",a);e.registerLanguage("js",a);e.registerLanguage("json",d);e.registerLanguage("jsx",y);e.registerLanguage("markdown",g);e.registerLanguage("md",g);e.registerLanguage("python",r);e.registerLanguage("py",r);e.registerLanguage("scss",j);e.registerLanguage("tsx",x);e.registerLanguage("typescript",t);e.registerLanguage("ts",t);e.registerLanguage("yaml",i);e.registerLanguage("yml",i);function S({code:n,language:u,isDark:o}){return L.jsx(e,{style:o?p:l,language:u,PreTag:"div",wrapLongLines:!0,customStyle:{margin:0,padding:"16px",background:"transparent",fontSize:"13px",lineHeight:"1.5"},children:n})}export{S as CodeBlockHighlighter};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{_ as ue}from"./vendor-markdown-Bo4W9Tae.js";import{r as i,j as e}from"./vendor-react-BalntB5F.js";import{c as F,u as Fe,e as $,s as re,B as Ce,f as ae}from"./index-BJTSF3fc.js";import{n as Be,L as xe,o as me,p as pe}from"./vendor-radix-CESj0OOY.js";import{u as Se}from"./SettingsStore-jup_Kikq.js";import{X as Le,k as ne,n as se,i as be,x as Re,y as De}from"./vendor-icons-BuFpOlRn.js";import"./vendor-monaco-w6PwaWGP.js";const Te=Be,ge=i.forwardRef(({className:t,...a},r)=>e.jsx(xe,{ref:r,className:F("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t),...a}));ge.displayName=xe.displayName;const z=i.forwardRef(({className:t,...a},r)=>e.jsx(me,{ref:r,className:F("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",t),...a}));z.displayName=me.displayName;const W=i.forwardRef(({className:t,...a},r)=>e.jsx(pe,{ref:r,className:F("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...a}));W.displayName=pe.displayName;const Ae={"ayu-dark":{background:{primary:"#0f1419",secondary:"#14191f"},text:{primary:"#e6e1cf",secondary:"#bae67e",muted:"#5c6773"},border:{light:"#2d323b"},syntax:{comment:"#5c6773",string:"#bae67e",number:"#ffcc66",keyword:"#ff8f40",function:"#73d0ff",variable:"#e6e1cf",operator:"#f29e74",type:"#73d0ff",tag:"#ff8f40",attr:"#ffd580",default:"#e6e1cf"}},dracula:{background:{primary:"#282a36",secondary:"#44475a"},text:{primary:"#f8f8f2",secondary:"#f1fa8c",muted:"#6272a4"},border:{light:"#44475a"},syntax:{comment:"#6272a4",string:"#f1fa8c",number:"#bd93f9",keyword:"#ff79c6",function:"#50fa7b",variable:"#f8f8f2",operator:"#ff79c6",type:"#8be9fd",tag:"#ff79c6",attr:"#50fa7b",default:"#f8f8f2"}},monokai:{background:{primary:"#272822",secondary:"#3e3d32"},text:{primary:"#f8f8f2",secondary:"#e6db74",muted:"#75715e"},border:{light:"#3e3d32"},syntax:{comment:"#75715e",string:"#e6db74",number:"#ae81ff",keyword:"#f92672",function:"#a6e22e",variable:"#f8f8f2",operator:"#f92672",type:"#66d9ef",tag:"#f92672",attr:"#a6e22e",default:"#f8f8f2"}},nord:{background:{primary:"#2e3440",secondary:"#3b4252"},text:{primary:"#eceff4",secondary:"#d8dee9",muted:"#4c566a"},border:{light:"#434c5e"},syntax:{comment:"#616e88",string:"#a3be8c",number:"#b48ead",keyword:"#81a1c1",function:"#88c0d0",variable:"#d8dee9",operator:"#81a1c1",type:"#8fbcbb",tag:"#81a1c1",attr:"#8fbcbb",default:"#eceff4"}},"solarized-light":{background:{primary:"#fdf6e3",secondary:"#eee8d5"},text:{primary:"#586e75",secondary:"#657b83",muted:"#93a1a1"},border:{light:"#eee8d5"},syntax:{comment:"#93a1a1",string:"#2aa198",number:"#d33682",keyword:"#859900",function:"#268bd2",variable:"#657b83",operator:"#859900",type:"#b58900",tag:"#268bd2",attr:"#93a1a1",default:"#657b83"}},"solarized-dark":{background:{primary:"#002b36",secondary:"#073642"},text:{primary:"#839496",secondary:"#93a1a1",muted:"#586e75"},border:{light:"#073642"},syntax:{comment:"#586e75",string:"#2aa198",number:"#d33682",keyword:"#859900",function:"#268bd2",variable:"#839496",operator:"#859900",type:"#b58900",tag:"#268bd2",attr:"#93a1a1",default:"#839496"}},"tokyo-night":{background:{primary:"#1a1b26",secondary:"#292e42"},text:{primary:"#a9b1d6",secondary:"#c0caf5",muted:"#565f89"},border:{light:"#292e42"},syntax:{comment:"#565f89",string:"#9ece6a",number:"#ff9e64",keyword:"#bb9af7",function:"#7aa2f7",variable:"#c0caf5",operator:"#89ddff",type:"#7dcfff",tag:"#f7768e",attr:"#7aa2f7",default:"#a9b1d6"}},github:{background:{primary:"#ffffff",secondary:"#f6f8fa"},text:{primary:"#24292f",secondary:"#57606a",muted:"#6e7781"},border:{light:"#d0d7de"},syntax:{comment:"#6e7781",string:"#0a3069",number:"#0550ae",keyword:"#cf222e",function:"#8250df",variable:"#24292f",operator:"#cf222e",type:"#0550ae",tag:"#116329",attr:"#0550ae",default:"#24292f"}},gruvbox:{background:{primary:"#282828",secondary:"#3c3836"},text:{primary:"#ebdbb2",secondary:"#d5c4a1",muted:"#928374"},border:{light:"#3c3836"},syntax:{comment:"#928374",string:"#b8bb26",number:"#d3869b",keyword:"#fb4934",function:"#b8bb26",variable:"#ebdbb2",operator:"#fe8019",type:"#fabd2f",tag:"#fb4934",attr:"#fabd2f",default:"#ebdbb2"}},"one-dark":{background:{primary:"#282c34",secondary:"#21252b"},text:{primary:"#abb2bf",secondary:"#e5c07b",muted:"#5c6370"},border:{light:"#3e4451"},syntax:{comment:"#5c6370",string:"#98c379",number:"#d19a66",keyword:"#c678dd",function:"#61afef",variable:"#e06c75",operator:"#56b6c2",type:"#e5c07b",tag:"#e06c75",attr:"#d19a66",default:"#abb2bf"}},catppuccin:{background:{primary:"#1e1e2e",secondary:"#313244"},text:{primary:"#cdd6f4",secondary:"#f5e0dc",muted:"#6c7086"},border:{light:"#313244"},syntax:{comment:"#6c7086",string:"#a6e3a1",number:"#fab387",keyword:"#cba6f7",function:"#89b4fa",variable:"#f5e0dc",operator:"#89dceb",type:"#f9e2af",tag:"#f38ba8",attr:"#f9e2af",default:"#cdd6f4"}},"rose-pine":{background:{primary:"#191724",secondary:"#1f1d2e"},text:{primary:"#e0def4",secondary:"#908caa",muted:"#6e6a86"},border:{light:"#26233a"},syntax:{comment:"#6e6a86",string:"#f6c177",number:"#ebbcba",keyword:"#c4a7e7",function:"#9ccfd8",variable:"#e0def4",operator:"#31748f",type:"#eb6f92",tag:"#eb6f92",attr:"#c4a7e7",default:"#e0def4"}},kanagawa:{background:{primary:"#1f1f28",secondary:"#2a2a37"},text:{primary:"#dcd7ba",secondary:"#c8c093",muted:"#727169"},border:{light:"#2a2a37"},syntax:{comment:"#727169",string:"#98bb6c",number:"#d27e99",keyword:"#957fb8",function:"#7e9cd8",variable:"#dcd7ba",operator:"#c0a36e",type:"#7aa89f",tag:"#e46876",attr:"#ffa066",default:"#dcd7ba"}}};function _e(t){const a=t.replace("#",""),r=parseInt(a.substring(0,2),16),s=parseInt(a.substring(2,4),16),o=parseInt(a.substring(4,6),16);return(.299*r+.587*s+.114*o)/255<.5}function $e(t){return{base:_e(t.background.primary)?"vs-dark":"vs",inherit:!0,rules:[{token:"",foreground:t.text.primary.replace("#",""),background:t.background.primary.replace("#","")},{token:"comment",foreground:t.syntax.comment.replace("#",""),fontStyle:"italic"},{token:"string",foreground:t.syntax.string.replace("#","")},{token:"number",foreground:t.syntax.number.replace("#","")},{token:"keyword",foreground:t.syntax.keyword.replace("#","")},{token:"type",foreground:t.syntax.type.replace("#","")},{token:"identifier",foreground:t.syntax.variable.replace("#","")},{token:"function",foreground:t.syntax.function.replace("#","")},{token:"variable",foreground:t.syntax.variable.replace("#","")},{token:"operator",foreground:t.syntax.operator.replace("#","")},{token:"delimiter",foreground:t.syntax.operator.replace("#","")},{token:"tag",foreground:t.syntax.tag.replace("#","")},{token:"attribute.name",foreground:t.syntax.attr.replace("#","")},{token:"attribute.value",foreground:t.syntax.string.replace("#","")}],colors:{"editor.background":t.background.primary,"editor.foreground":t.text.primary,"editor.lineHighlightBackground":t.background.secondary,"editor.selectionBackground":`${t.syntax.function}40`,"editorLineNumber.foreground":t.text.muted,"editorLineNumber.activeForeground":t.text.secondary,"editorCursor.foreground":t.text.primary,"editorIndentGuide.background":t.border.light,"editorWidget.background":t.background.secondary,"editorWidget.border":t.border.light,"scrollbarSlider.background":`${t.text.muted}40`,"scrollbarSlider.hoverBackground":`${t.text.muted}60`}}}const oe=new Set;function de(t,a){const r=a.toLowerCase().replace(/\s+/g,"-"),s=Ae[r];if(!s)return"vs-dark";if(!oe.has(r)){const o=$e(s);t.editor.defineTheme(r,o),oe.add(r)}return r}i.lazy(async()=>({default:(await ue(()=>import("./vendor-react-BalntB5F.js").then(a=>a.k),[])).DiffEditor}));const ze=i.lazy(async()=>({default:(await ue(()=>import("./vendor-react-BalntB5F.js").then(a=>a.k),[])).Editor}));function ie(t,a){return t instanceof Error?t.message:a}function Ye(){const{toggleFilePreview:t}=Fe(),{messages:a,currentSessionRef:r}=$(),[s,o]=i.useState("diff"),[l,c]=i.useState([]),[d,u]=i.useState({}),[x,m]=i.useState(!1),[b,p]=i.useState(null),[q,E]=i.useState({}),[C,I]=i.useState({}),[v,Q]=i.useState(null),[ye,P]=i.useState(""),[G,O]=i.useState(!1),[V,J]=i.useState(null),[Y,H]=i.useState(!1),Z=i.useRef(r),B=i.useRef(0),D=i.useRef(0),T=i.useRef({}),K=i.useRef(0),S=i.useRef({}),j=i.useRef({}),U=i.useRef(null);i.useLayoutEffect(()=>{re(Z.current,r)||(B.current+=1),Z.current=r},[r]);const X=(n,f)=>f===B.current&&re($.getState().currentSessionRef,n),M=async(n,f="")=>{const g=f?`/suggestions/files/tree?path=${encodeURIComponent(f)}`:"/suggestions/files/tree",h=await fetch(g,{headers:ae(n)});if(!h.ok)throw new Error("Failed to load tree");return(await h.json()).map(y=>({...y,children:y.type==="dir"?[]:void 0}))};i.useEffect(()=>{const n=++D.current;return(async()=>{if(!r){c([]),m(!1),p(null);return}const g={...r},h=B.current,k=()=>n===D.current&&X(g,h);if(k()){c([]),m(!0),p(null);try{const y=await M(g);k()&&c(y)}catch(y){k()&&p(ie(y,"Failed to load tree"))}finally{k()&&m(!1)}}})(),()=>{D.current===n&&(D.current+=1)}},[r==null?void 0:r.projectPath,r==null?void 0:r.sessionId]),i.useEffect(()=>{U.current=null,S.current={},j.current={},T.current={},K.current+=1,Q(null),P(""),O(!1),J(null),H(!1),E({}),u({})},[r==null?void 0:r.projectPath,r==null?void 0:r.sessionId]);const A=i.useMemo(()=>Ie(a),[a]),ee=i.useMemo(()=>qe(a),[a]),[ke,ve]=i.useState({}),Ee=n=>{ve(f=>({...f,[n]:!f[n]}))},je=async n=>{const f=$.getState().currentSessionRef;if(!f)return;const g=B.current,h=++K.current,k=()=>h===K.current&&U.current===n&&X(f,g);U.current=n,Q(n),P(""),O(!0),J(null),H(!1);try{const y=await fetch(`/suggestions/files/content?path=${encodeURIComponent(n)}`,{headers:ae(f)});if(!y.ok)throw new Error("Failed to load file");const L=await y.json();k()&&(P(L.content||""),H(!!L.truncated))}catch(y){k()&&J(ie(y,"Failed to load file"))}finally{k()&&O(!1)}},we=async n=>{const f=(T.current[n]??0)+1;T.current[n]=f;const g=!S.current[n],h={...S.current,[n]:g};if(S.current=h,E(h),!g||j.current[n])return;const k=$.getState().currentSessionRef;if(!k)return;const y=B.current,L=()=>T.current[n]===f&&S.current[n]===!0&&X(k,y);try{const _=await M(k,n);if(L()){const te={...j.current,[n]:_};j.current=te,u(te)}}catch{if(L()){const _={...j.current,[n]:[]};j.current=_,u(_)}}},Ne=n=>{I(f=>({...f,[n]:!f[n]}))};return e.jsxs("div",{className:"w-[55%] min-w-[420px] max-w-[860px] border-l border-[#E5E7EB] dark:border-zinc-800 bg-white dark:bg-[#09090b] flex flex-col h-full shadow-xl shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 h-12 border-b border-[#E5E7EB] dark:border-zinc-800 shrink-0",children:[e.jsx("span",{className:"font-normal text-[13px] text-[#6B7280] dark:text-zinc-400 font-mono",children:"Preview"}),e.jsx(Ce,{variant:"ghost",size:"icon",onClick:t,className:"h-8 w-8 text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB]/60 dark:text-zinc-500 dark:hover:text-zinc-300 dark:hover:bg-zinc-800/50",children:e.jsx(Le,{className:"w-4 h-4"})})]}),e.jsxs(Te,{value:s,onValueChange:n=>o(n),className:"flex flex-col flex-1 min-h-0",children:[e.jsx("div",{className:"px-4 py-3 border-b border-[#E5E7EB] dark:border-zinc-800",children:e.jsxs(ge,{className:"bg-white dark:bg-[#111113] border border-[#E5E7EB] dark:border-[#27272a] h-9 p-1 rounded-md w-full justify-start",children:[e.jsx(z,{value:"diff",className:"text-[12px] font-mono px-3 text-[#6B7280] dark:text-[#a1a1aa] data-[state=active]:bg-[#E5E7EB] data-[state=active]:text-[#111827] dark:data-[state=active]:bg-[#27272a] dark:data-[state=active]:text-white",children:"Diff"}),e.jsx(z,{value:"files",className:"text-[12px] font-mono px-3 text-[#6B7280] dark:text-[#a1a1aa] data-[state=active]:bg-[#E5E7EB] data-[state=active]:text-[#111827] dark:data-[state=active]:bg-[#27272a] dark:data-[state=active]:text-white",children:"Files"}),e.jsx(z,{value:"logs",className:"text-[12px] font-mono px-3 text-[#6B7280] dark:text-[#a1a1aa] data-[state=active]:bg-[#E5E7EB] data-[state=active]:text-[#111827] dark:data-[state=active]:bg-[#27272a] dark:data-[state=active]:text-white",children:"Logs"})]})}),e.jsx(W,{value:"diff",className:"overflow-hidden flex-1 mt-0",children:e.jsx("div",{className:"overflow-y-auto px-4 py-4 space-y-3 h-full",children:A.length===0?e.jsx(R,{title:"No patch yet",subtitle:"Run a tool that changes files to see diffs here."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-[12px] text-[#6B7280] dark:text-[#71717a] font-mono mb-2",children:[A.length," changed file",A.length>1?"s":""]}),A.map(n=>{var h;const f=((h=n.filePath)==null?void 0:h.split("/").pop())||"unknown",g=ke[n.filePath||""]!==!1;return e.jsxs("div",{className:"border border-[#E5E7EB] dark:border-[#27272a] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>Ee(n.filePath||""),className:"w-full flex items-center gap-2 px-3 py-2 bg-[#F9FAFB] dark:bg-[#111113] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b] transition-colors",children:[g?e.jsx(ne,{className:"w-4 h-4 text-[#6B7280] dark:text-[#71717a]"}):e.jsx(se,{className:"w-4 h-4 text-[#6B7280] dark:text-[#71717a]"}),e.jsx(be,{className:"w-4 h-4 text-[#6B7280] dark:text-[#71717a]"}),e.jsx("span",{className:"text-[13px] text-[#111827] dark:text-[#E5E5E5] font-mono flex-1 text-left truncate",children:f}),n.summary&&e.jsx("span",{className:"text-[11px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:n.summary})]}),g&&e.jsxs("div",{className:"border-t border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsx("div",{className:"px-3 py-1 text-[11px] text-[#9CA3AF] dark:text-[#52525b] font-mono truncate",children:n.filePath}),e.jsx(Oe,{diff:n.diff})]})]},n.filePath)})]})})}),e.jsx(W,{value:"files",className:"overflow-hidden flex-1 mt-0",children:e.jsxs("div",{className:"px-4 py-4 h-full",children:[x&&e.jsx(R,{title:"Loading files…",subtitle:"Fetching workspace tree."}),!x&&b&&e.jsx(R,{title:"Failed to load files",subtitle:b}),!x&&!b&&l.length===0&&e.jsx(R,{title:"No files yet",subtitle:"Start a session to load the workspace tree."}),!x&&!b&&l.length>0&&e.jsxs("div",{className:"h-full grid grid-cols-[220px_1fr] gap-4 min-h-0",children:[e.jsx("div",{className:"border border-[#E5E7EB] dark:border-[#27272a] rounded-lg p-2 overflow-y-auto min-h-0",children:l.map(n=>e.jsx(he,{node:n,depth:0,expandedDirs:q,childrenCache:d,toggleDir:we,selectedPath:v,onSelectFile:je},n.path))}),e.jsxs("div",{className:"border border-[#E5E7EB] dark:border-[#27272a] rounded-lg overflow-hidden flex flex-col min-h-0",children:[e.jsxs("div",{className:"px-3 py-2 bg-[#F9FAFB] dark:bg-[#111113] border-b border-[#E5E7EB] dark:border-[#27272a] text-[12px] text-[#6B7280] dark:text-[#71717a] font-mono flex items-center justify-between",children:[e.jsx("span",{children:v||"Select a file to preview"}),v&&e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#a1a1aa] font-mono",children:G?"Loading…":Y?"Truncated":"Ready"})]}),Y&&!G&&e.jsx("div",{className:"px-3 py-2 bg-[#FEF3C7] dark:bg-[#111113] border-b border-[#E5E7EB] dark:border-[#27272a] text-[11px] text-[#b45309] dark:text-[#facc15] font-mono",children:"Preview truncated to 200k characters."}),e.jsxs("div",{className:"flex-1 min-h-0",children:[!v&&e.jsx("div",{className:"h-full flex items-center justify-center text-[12px] text-[#6B7280] dark:text-[#71717a] font-mono",children:"Pick a file from the tree to preview."}),v&&V&&e.jsx("div",{className:"h-full flex items-center justify-center text-[12px] text-[#DC2626] dark:text-[#fca5a5] font-mono",children:V}),v&&!V&&e.jsx("div",{className:"h-full",children:G?e.jsx(fe,{}):e.jsx(i.Suspense,{fallback:e.jsx(fe,{}),children:e.jsx(Pe,{content:ye,filename:v})})})]})]})]})]})}),e.jsx(W,{value:"logs",className:"overflow-hidden flex-1 mt-0",children:e.jsx("div",{className:"overflow-y-auto px-4 py-4 space-y-3 h-full",children:ee.length===0?e.jsx(R,{title:"No logs yet",subtitle:"Tool runs will appear here."}):ee.map(n=>{var y;const f=C[n.id],g=(n.content||"").split(`
|
|
2
|
+
`),h=g.length>10||(((y=n.content)==null?void 0:y.length)||0)>800,k=f||!h?g:g.slice(0,8);return e.jsxs("div",{className:"border border-[#E5E7EB] dark:border-[#27272a] rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-[#F9FAFB] dark:bg-[#111113] border-b border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono",children:n.title}),n.subtitle&&e.jsx("div",{className:"text-[11px] text-[#6B7280] dark:text-[#71717a] font-mono",children:n.subtitle})]}),e.jsx(We,{status:n.status})]}),n.content&&e.jsxs("div",{className:"px-3 py-3 space-y-2",children:[e.jsxs("pre",{className:"text-[12px] text-[#374151] dark:text-[#d4d4d8] bg-[#F3F4F6] dark:bg-[#09090b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md p-3 overflow-x-auto whitespace-pre-wrap font-mono",children:[k.join(`
|
|
3
|
+
`),!f&&h&&`
|
|
4
|
+
…`]}),h&&e.jsxs("button",{onClick:()=>Ne(n.id),className:"flex items-center gap-1 text-[12px] text-[#6B7280] dark:text-[#a1a1aa] font-mono hover:text-[#111827] dark:hover:text-[#E5E5E5] transition-colors",children:[f?e.jsx(ne,{className:"w-3 h-3"}):e.jsx(se,{className:"w-3 h-3"}),f?"Collapse":"Expand"]})]})]},n.id)})})})]})]})}function R({title:t,subtitle:a}){return e.jsxs("div",{className:"border border-dashed border-[#E5E7EB] dark:border-[#27272a] rounded-lg p-6 text-center",children:[e.jsx("div",{className:"text-[13px] text-[#111827] dark:text-[#E5E5E5] font-mono",children:t}),e.jsx("div",{className:"text-[12px] text-[#6B7280] dark:text-[#71717a] font-mono mt-1",children:a})]})}function We({status:t}){const a=t==="success"?"Success":t==="error"?"Failed":"Running",r=t==="success"?"bg-[#22C55E] text-white":t==="error"?"bg-[#FEE2E2] text-[#b91c1c] dark:bg-[#EF4444]/20 dark:text-[#fca5a5]":"bg-[#E5E7EB] text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]";return e.jsx("span",{className:F("text-[11px] px-2 py-0.5 rounded-full font-mono",r),children:a})}function he({node:t,depth:a,expandedDirs:r,childrenCache:s,toggleDir:o,onSelectFile:l,selectedPath:c}){const d=t.type==="dir",u=r[t.path],x=!d&&c===t.path,m=s[t.path]||[];return e.jsxs("div",{children:[e.jsx("button",{onClick:()=>{d?o(t.path):l(t.path)},className:F("flex items-center gap-2 w-full text-left text-[12px] font-mono px-2 py-1 rounded-md transition-colors",x?"bg-[#16A34A]/10 text-[#111827] dark:bg-[#22C55E]/10 dark:text-[#E5E5E5]":"hover:bg-[#F3F4F6] text-[#6B7280] dark:hover:bg-[#111113] dark:text-[#a1a1aa]",d&&"cursor-pointer",x&&"border border-[#16A34A]/30 dark:border-[#22C55E]/30"),style:{paddingLeft:a*14+8},children:d?e.jsxs(e.Fragment,{children:[u?e.jsx(Re,{className:"h-3.5 w-3.5 shrink-0 text-[#111827] dark:text-[#E5E5E5]"}):e.jsx(De,{className:"h-3.5 w-3.5 shrink-0 text-[#6B7280] dark:text-[#a1a1aa]"}),e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name})]}):e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-3.5 w-3.5 shrink-0 text-[#9CA3AF] dark:text-[#71717a]"}),e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name})]})}),d&&u&&e.jsx("div",{children:m.map(b=>e.jsx(he,{node:b,depth:a+1,expandedDirs:r,childrenCache:s,toggleDir:o,onSelectFile:l,selectedPath:c},b.path))})]})}function qe(t){return t.flatMap(a=>{var o,l,c;const r=[];if((o=a.agentContent)!=null&&o.toolCalls)for(const d of a.agentContent.toolCalls){const u=le(d.arguments),x=d.output,m=x?(l=N(x))!=null&&l.diff?ce(x):x:void 0;r.push({id:`${a.id}-${d.toolCallId}`,title:d.toolName||"Tool",subtitle:d.summary,status:d.status==="success"?"success":d.status==="error"?"error":"running",content:m||(u?`Arguments:
|
|
5
|
+
${u}`:void 0),timestamp:a.timestamp})}const s=a.metadata;if(s){if(s.kind==="tool_call"){const d=s.toolName||"Tool",u=le(s.arguments);r.push({id:a.id,title:`Tool Call · ${d}`,subtitle:s.toolKind?String(s.toolKind):void 0,status:s.status==="success"?"success":s.status==="error"?"error":"running",content:u?`Arguments:
|
|
6
|
+
${u}`:void 0,timestamp:a.timestamp})}if(s.kind==="tool_result"){const d=s.toolName||"Tool",u=s.success,x=s.summary,m=s.output,b=m?(c=N(m))!=null&&c.diff?ce(m):m:void 0;r.push({id:a.id,title:`Tool Result · ${d}`,subtitle:x,status:u===void 0?"running":u?"success":"error",content:b,timestamp:a.timestamp})}}return r})}function Ie(t){var s;const a=[],r=new Set;for(let o=t.length-1;o>=0;o-=1){const l=t[o];if((s=l.agentContent)!=null&&s.toolCalls)for(let m=l.agentContent.toolCalls.length-1;m>=0;m-=1){const b=l.agentContent.toolCalls[m],p=b.metadata,q=b.output||"",E=N(q)||N((p==null?void 0:p.diff_snippet)||"");if(E!=null&&E.diff){const C=(p==null?void 0:p.file_path)||b.toolName||"unknown";if(!r.has(C)){r.add(C);const I=typeof(p==null?void 0:p.oldContent)=="string"?p.oldContent:void 0,v=typeof(p==null?void 0:p.newContent)=="string"?p.newContent:void 0;a.push({diff:E.diff,filePath:C,summary:b.summary,oldContent:I,newContent:v})}}}const c=l.metadata;if(!c||c.kind!=="tool_result")continue;const d=c.metadata,u=c.output||(typeof l.content=="string"?l.content:"")||"",x=N(u)||N((d==null?void 0:d.diff_snippet)||"");if(x!=null&&x.diff){const m=(d==null?void 0:d.file_path)||c.toolName||"unknown";if(!r.has(m)){r.add(m);const b=typeof(d==null?void 0:d.oldContent)=="string"?d.oldContent:void 0,p=typeof(d==null?void 0:d.newContent)=="string"?d.newContent:void 0;a.push({diff:x.diff,filePath:m,summary:c.summary,oldContent:b,newContent:p})}}}return a.reverse()}function N(t){if(!t)return null;const a=/<<<DIFF>>>\s*([\s\S]*?)\s*<<<\/DIFF>>>/m,r=t.match(a);if(!r)return null;try{return{diff:JSON.parse(r[1])}}catch{return null}}function ce(t){return t?t.replace(/<<<DIFF>>>[\s\S]*?<<<\/DIFF>>>/m,"").trim():""}function le(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 fe(){return e.jsx("div",{className:"h-full flex items-center justify-center text-[12px] text-[#6B7280] dark:text-[#71717a] font-mono",children:"Loading editor…"})}function Pe({content:t,filename:a}){const{theme:r}=Se(),s=i.useRef(null),[o,l]=i.useState("vs-dark"),c=Ge(a),d=u=>{s.current=u;const x=de(u,r);l(x)};return i.useEffect(()=>{if(s.current){const u=de(s.current,r);l(u)}},[r]),e.jsx(ze,{value:t,language:c,theme:o,height:"100%",beforeMount:d,options:{readOnly:!0,minimap:{enabled:!1},fontSize:12,lineNumbers:"on",wordWrap:"on",scrollBeyondLastLine:!1,automaticLayout:!0}},a)}function Ge(t){var s;const a=((s=t.split(".").pop())==null?void 0:s.toLowerCase())||"";return{ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",scss:"scss",html:"html",yml:"yaml",yaml:"yaml",go:"go",rs:"rust",py:"python",java:"java",c:"c",cpp:"cpp",h:"cpp",hpp:"cpp",sh:"shell",zsh:"shell",toml:"toml",xml:"xml"}[a]||"plaintext"}function Oe({diff:t}){const a=t.patch.split(`
|
|
7
|
+
`);let r=0,s=0;return e.jsxs("div",{className:"border border-[#E5E7EB] dark:border-[#27272a] rounded-md overflow-hidden bg-white dark:bg-[#111113]",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#E5E7EB] dark:border-[#27272a] bg-[#F9FAFB] dark:bg-[#111113] text-[12px] text-[#6B7280] dark:text-[#71717a] font-mono",children:[e.jsx("span",{children:"Patch"}),t.matchLine&&e.jsxs("span",{children:["Line ",t.matchLine]})]}),e.jsx("div",{className:"text-[12px] font-mono",children:a.map((o,l)=>{if(o.startsWith("@@")){const c=/@@ -(?<old>\d+),?(?<oldCount>\d*) \+(?<new>\d+),?(?<newCount>\d*) @@/.exec(o);return c!=null&&c.groups&&(r=parseInt(c.groups.old,10),s=parseInt(c.groups.new,10)),e.jsx(w,{line:o},`${o}-${l}`)}if(o.startsWith("---")||o.startsWith("+++")||o.startsWith("Index:")||o.startsWith("==="))return e.jsx(w,{line:o},`${o}-${l}`);if(o.startsWith("+")){const c=s;return s+=1,e.jsx(w,{line:o,oldLine:null,newLine:c},`${o}-${l}`)}if(o.startsWith("-")){const c=r;return r+=1,e.jsx(w,{line:o,oldLine:c,newLine:null},`${o}-${l}`)}if(o.startsWith(" ")){const c=r,d=s;return r+=1,s+=1,e.jsx(w,{line:o,oldLine:c,newLine:d},`${o}-${l}`)}return e.jsx(w,{line:o},`${o}-${l}`)})})]})}function w({line:t,oldLine:a,newLine:r}){const s=t.startsWith("---")||t.startsWith("+++")||t.startsWith("Index:")||t.startsWith("==="),o=t.startsWith("@@"),l=t[0],c=s||o?t:t.slice(1),d=s?"text-[#6B7280] dark:text-[#a1a1aa]":l==="+"?"text-[#166534] bg-[#22C55E]/10 dark:text-[#86efac] dark:bg-[#22C55E]/10":l==="-"?"text-[#b91c1c] bg-[#EF4444]/10 dark:text-[#fca5a5] dark:bg-[#EF4444]/10":o?"text-[#1d4ed8] bg-[#DBEAFE] dark:text-[#93c5fd] dark:bg-[#1e3a8a]/30":"text-[#374151] dark:text-[#d4d4d8]";return e.jsxs("div",{className:F("grid grid-cols-[40px_40px_1fr] gap-2 px-3 py-0.5",d),children:[e.jsx("span",{className:"text-right text-[#9CA3AF] dark:text-[#71717a]",children:a?String(a).padStart(2," "):""}),e.jsx("span",{className:"text-right text-[#9CA3AF] dark:text-[#71717a]",children:r?String(r).padStart(2," "):""}),e.jsx("span",{className:"whitespace-pre",children:c})]})}export{Ye as FilePreview};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{M as k,r as h,_ as j}from"./vendor-markdown-
|
|
1
|
+
import{M as k,r as h,_ as j}from"./vendor-markdown-Bo4W9Tae.js";import{r as o,j as r}from"./vendor-react-BalntB5F.js";import{c as b}from"./index-BJTSF3fc.js";import{a as f}from"./SettingsStore-jup_Kikq.js";import{c as g,I as N}from"./vendor-icons-BuFpOlRn.js";import"./vendor-monaco-w6PwaWGP.js";import"./vendor-radix-CESj0OOY.js";const v=[h],y=o.lazy(()=>j(()=>import("./CodeBlockHighlighter-C1cp8dDv.js"),[]).then(t=>({default:t.CodeBlockHighlighter}))),P=o.memo(function({content:s,className:a,syntaxHighlight:d=!0}){const i=f(),E=o.useMemo(()=>({code({className:e,children:n,...c}){const x=/language-(\w+)/.exec(e||""),p=!x,m=x?x[1]:"",l=String(n).replace(/\n$/,"");return p?r.jsx("code",{className:b("bg-[#F3F4F6] dark:bg-[#27272a] px-1.5 py-0.5 rounded text-[#111827] dark:text-[#E5E5E5] font-mono text-[13px]",e),...c,children:n}):d?r.jsxs("div",{className:"relative my-4 rounded-lg overflow-hidden border border-[#E5E7EB] dark:border-[#27272a] bg-[#F9FAFB] dark:bg-[#1e1e1e]",children:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-[#F3F4F6] dark:bg-[#27272a] border-b border-[#E5E7EB] dark:border-[#27272a]",children:[r.jsx("span",{className:"text-xs text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:m||"text"}),r.jsx(F,{content:l})]}),r.jsx(o.Suspense,{fallback:r.jsx(u,{className:e,code:l,props:c}),children:r.jsx(y,{code:l,language:m,isDark:i})})]}):r.jsx(u,{className:e,code:l,props:c})},p({children:e}){return r.jsx("p",{className:"mb-4 leading-relaxed last:mb-0",children:e})},ul({children:e}){return r.jsx("ul",{className:"pl-4 mb-4 space-y-1 list-disc last:mb-0",children:e})},ol({children:e}){return r.jsx("ol",{className:"pl-4 mb-4 space-y-1 list-decimal last:mb-0",children:e})},li({children:e}){return r.jsx("li",{className:"leading-relaxed",children:e})},h1({children:e}){return r.jsx("h1",{className:"text-2xl font-bold mb-4 mt-6 text-[#111827] dark:text-[#E5E5E5]",children:e})},h2({children:e}){return r.jsx("h2",{className:"text-xl font-bold mb-3 mt-5 text-[#111827] dark:text-[#E5E5E5]",children:e})},h3({children:e}){return r.jsx("h3",{className:"text-lg font-bold mb-2 mt-4 text-[#111827] dark:text-[#E5E5E5]",children:e})},blockquote({children:e}){return r.jsx("blockquote",{className:"border-l-2 border-[#22C55E] pl-4 italic text-[#6B7280] dark:text-[#a1a1aa] mb-4",children:e})},a({href:e,children:n}){return r.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-[#22C55E] hover:underline transition-colors",children:n})},table({children:e}){return r.jsx("div",{className:"overflow-x-auto mb-4 border border-[#E5E7EB] dark:border-[#27272a] rounded-lg",children:r.jsx("table",{className:"w-full text-sm text-left",children:e})})},thead({children:e}){return r.jsx("thead",{className:"bg-[#F3F4F6] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]",children:e})},tbody({children:e}){return r.jsx("tbody",{className:"divide-y divide-[#E5E7EB] dark:divide-[#27272a]",children:e})},tr({children:e}){return r.jsx("tr",{className:"hover:bg-[#F3F4F6] dark:hover:bg-[#27272a]/50 transition-colors",children:e})},th({children:e}){return r.jsx("th",{className:"px-4 py-3 font-medium whitespace-nowrap",children:e})},td({children:e}){return r.jsx("td",{className:"px-4 py-3 text-[#374151] dark:text-[#d4d4d8]",children:e})},hr(){return r.jsx("hr",{className:"my-6 border-[#E5E7EB] dark:border-[#27272a]"})}}),[i,d]);return r.jsx("div",{className:b("text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono break-words min-w-0 w-full",a),children:r.jsx(k,{remarkPlugins:v,components:E,children:s})})});function u({className:t,code:s,props:a}){return r.jsx("pre",{className:"my-4 overflow-x-auto rounded-lg border border-[#E5E7EB] dark:border-[#27272a] bg-[#F9FAFB] dark:bg-[#1e1e1e] p-4 text-[13px] leading-normal",children:r.jsx("code",{className:t,...a,children:s})})}function F({content:t}){const[s,a]=o.useState(!1),d=async()=>{await navigator.clipboard.writeText(t),a(!0),setTimeout(()=>a(!1),2e3)};return r.jsx("button",{onClick:d,className:"p-1 hover:bg-[#E5E7EB] dark:hover:bg-[#3f3f46] rounded-md transition-colors text-[#9CA3AF] dark:text-[#a1a1aa] hover:text-[#111827] dark:hover:text-[#E5E5E5]",title:"Copy code",children:s?r.jsx(g,{className:"h-3.5 w-3.5 text-[#22C55E]"}):r.jsx(N,{className:"h-3.5 w-3.5"})})}export{P as MarkdownRenderer};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as o,j as e}from"./vendor-react-Dm1xU4bP.js";import{u as ge,D as V,a as ee,b as te,c as A}from"./index-Cnz-_jPt.js";import{_ as T,q as w,r as se,s as oe,t as W}from"./vendor-radix-2yBsoRqx.js";import{i as ve,a as Ee,d as le,u as pe,b as be,c as je,e as P,f as G,g as ke}from"./useRequest-C7k7cDPD.js";import{x as Ne,P as Ce,X as ae,y as ye,L as ce,z as de,c as we,D as Ae}from"./vendor-icons-BKXQ7ALf.js";import"./vendor-markdown-DIcugY1e.js";import"./vendor-monaco-w6PwaWGP.js";function Y(a,n){if(ve){if(!a)return n;var r;return Ee(a)?r=a():"current"in a?r=a.current:r=a,r}}var Se=function(a){var n=function(r,c,d){var l=o.useRef(!1),s=o.useRef([]),m=o.useRef([]),h=o.useRef(void 0);a(function(){var i,k=Array.isArray(d)?d:[d],v=k.map(function(N){return Y(N)});if(!l.current){l.current=!0,s.current=v,m.current=c,h.current=r();return}(v.length!==s.current.length||!le(s.current,v)||!le(m.current,c))&&((i=h.current)===null||i===void 0||i.call(h),s.current=v,m.current=c,h.current=r())}),pe(function(){var i;(i=h.current)===null||i===void 0||i.call(h),l.current=!1})};return n},Fe=Se(o.useEffect);function Be(){var a=(typeof global>"u"?"undefined":typeof global)=="object"&&global&&global.Object===Object&&global,n=typeof self=="object"&&self&&self.Object===Object&&self;return a||n}Be()||(global.Date=Date);function Me(a,n){var r,c=be(a),d=(r=n==null?void 0:n.wait)!==null&&r!==void 0?r:1e3,l=o.useMemo(function(){return je(function(){for(var s=[],m=0;m<arguments.length;m++)s[m]=arguments[m];return c.current.apply(c,T([],w(s),!1))},d,n)},[]);return pe(function(){l.cancel()}),{run:l,cancel:l.cancel,flush:l.flush}}function De(a,n,r){r===void 0&&(r={});var c=r.enable,d=c===void 0?!0:c,l=be(n);Fe(function(){if(d){var s=Y(r.target,window);if(s!=null&&s.addEventListener){var m=function(i){return l.current(i)},h=Array.isArray(a)?a:[a];return h.forEach(function(i){s.addEventListener(i,m,{capture:r.capture,once:r.once,passive:r.passive})}),function(){h.forEach(function(i){s.removeEventListener(i,m,{capture:r.capture})})}}}},[a,r.capture,r.once,r.passive,d],r.target)}var Te=function(a){return a===document||a===document.documentElement||a===document.body?Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop):a.scrollTop},ie=function(a){return a.scrollHeight||Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)},_e=function(a){return a.clientHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight)},Ie=function(a,n){n===void 0&&(n={});var r=n.target,c=n.isNoMore,d=n.threshold,l=d===void 0?100:d,s=n.direction,m=s===void 0?"bottom":s,h=n.reloadDeps,i=h===void 0?[]:h,k=n.manual,v=n.onBefore,N=n.onSuccess,S=n.onError,p=n.onFinally,_=w(o.useState(),2),C=_[0],F=_[1],R=w(o.useState(!1),2),O=R[0],g=R[1],B=m==="top",y=o.useRef(void 0),E=o.useRef(0),L=o.useMemo(function(){return c?c(C):!1},[C]),M=P(function(x){return se(void 0,void 0,void 0,function(){var f;return oe(this,function(t){switch(t.label){case 0:return[4,a(x)];case 1:return f=t.sent(),[2,{currentData:f,lastData:x}]}})})},{manual:k,onFinally:function(x,f,t){g(!1),p==null||p(f==null?void 0:f.currentData,t)},onBefore:function(){return v==null?void 0:v()},onSuccess:function(x){var f,t,j;x.lastData?F(W(W({},x.currentData),{list:B?T(T([],w(x.currentData.list),!1),w((t=x.lastData.list)!==null&&t!==void 0?t:[]),!1):T(T([],w((j=x.lastData.list)!==null&&j!==void 0?j:[]),!1),w(x.currentData.list),!1)})):F(W(W({},x.currentData),{list:T([],w((f=x.currentData.list)!==null&&f!==void 0?f:[]),!1)})),setTimeout(function(){if(B){var b=Y(r);if(b=b===document?document.documentElement:b,b){var J=ie(b);b.scrollTo(0,J-E.current)}}else z()}),N==null||N(x.currentData)},onError:function(x){return S==null?void 0:S(x)}}),$=M.loading,q=M.error,H=M.run,Q=M.runAsync,X=M.cancel,I=G(function(){L||(g(!0),H(C))}),u=function(x){return se(void 0,void 0,void 0,function(){var f;return oe(this,function(t){switch(t.label){case 0:return[4,Q(x)];case 1:return f=t.sent(),[2,f.currentData]}})})},D=G(function(){return L?Promise.reject():(g(!0),u(C))}),U=function(){return g(!1),H()},Z=function(){return g(!1),u()},z=function(){var x=Y(r);if(x){var f=x===document?document.documentElement:x,t=Te(f),j=ie(f),b=_e(f);B?(y.current!==void 0&&y.current>t&&t<=l&&I(),y.current=t,E.current=j-t):j-t<=b+l&&I()}};return De("scroll",function(){$||O||z()},{target:r}),ke(function(){H()},T([],w(i),!1)),{data:C,loading:!O&&$,error:q,loadingMore:O,noMore:L,loadMore:I,loadMoreAsync:D,reload:G(U),reloadAsync:G(Z),mutate:F,cancel:X}};const xe={connected:"text-[#16A34A] dark:text-[#22C55E]",connecting:"text-[#2563eb] dark:text-[#3b82f6]",offline:"text-[#f59e0b]",error:"text-[#ef4444]"},me={connected:"Connected",connecting:"Connecting...",offline:"Offline",error:"Error"},ue=20,Pe=async()=>{const a=await fetch("/mcp");if(!a.ok)throw new Error("Failed to fetch servers");return a.json()},Re="mcp server @modelcontextprotocol",Oe=3,Le=async(a,n)=>{const r=a&&a.length>=Oe?a:Re,c=`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(r)}&size=${ue}&from=${n}`,d=await fetch(c);if(!d.ok)throw new Error("Failed to fetch packages");const l=await d.json();return{list:l.objects.map(s=>s.package),total:l.total,hasMore:n+ue<l.total}};function Xe(){const{isMcpOpen:a,toggleMcp:n}=ge(),[r,c]=o.useState("installed"),[d,l]=o.useState(!1),[s,m]=o.useState(null),[h,i]=o.useState({}),[k,v]=o.useState(""),[N,S]=o.useState(""),[p,_]=o.useState(null),[C,F]=o.useState(null),R=o.useRef(null),{run:O}=Me(t=>{S(t)},{wait:500}),{data:g=[],loading:B,run:y}=P(Pe,{refreshDeps:[a],ready:a,onSuccess:t=>{t.length>0&&!s&&m(t[0].id)}}),{data:E,loading:L,loadingMore:M,noMore:$,reload:q}=Ie(async t=>{var b;const j=((b=t==null?void 0:t.list)==null?void 0:b.length)??0;return Le(N,j)},{target:R,isNoMore:t=>!(t!=null&&t.hasMore),reloadDeps:[N],manual:!a||r!=="catalog"}),{runAsync:H}=P(async t=>{await fetch(`/mcp/${encodeURIComponent(t)}/connect`,{method:"POST"})},{manual:!0,onSuccess:y}),{runAsync:Q}=P(async t=>{await fetch(`/mcp/${encodeURIComponent(t)}/disconnect`,{method:"POST"})},{manual:!0,onSuccess:y}),{runAsync:X}=P(async t=>{await fetch(`/mcp/${encodeURIComponent(t)}`,{method:"DELETE"})},{manual:!0,onSuccess:y}),{runAsync:I}=P(async t=>{await fetch("/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,config:t})})},{manual:!0,onSuccess:()=>{y(),l(!1),F(null),_(null)},onError:()=>{_(null)}}),u=o.useMemo(()=>g.find(t=>t.id===s)??g[0],[g,s]),D=u?h[u.id]??{read:!0,write:!1,shell:!1}:{read:!0,write:!1,shell:!1},U=t=>{u&&i(j=>({...j,[u.id]:{...D,[t]:!D[t]}}))},Z=o.useMemo(()=>new Set(g.map(t=>t.name.toLowerCase())),[g]),z=t=>{F(t)},x=t=>t.startsWith("@modelcontextprotocol/"),f=t=>x(t.name)?"Official":"Community";return e.jsxs(e.Fragment,{children:[e.jsx(V,{open:a,onOpenChange:n,children:e.jsxs(ee,{className:"sm:max-w-[900px] h-[680px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl flex flex-col","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(te,{className:"sr-only",children:"MCP"}),e.jsx("div",{className:"flex flex-1 min-h-0",children:e.jsxs("div",{className:"flex-1 p-8 flex flex-col gap-5 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between 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 items-center gap-2",children:[e.jsx("button",{onClick:y,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:B,children:e.jsx(Ne,{className:A("h-4 w-4",B&&"animate-spin")})}),e.jsxs("button",{onClick:()=>l(!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(Ce,{className:"h-3.5 w-3.5"}),"Add server"]}),e.jsx("button",{onClick:n,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(ae,{className:"h-4 w-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(fe,{active:r==="installed",onClick:()=>c("installed"),children:["Installed (",g.length,")"]}),e.jsx(fe,{active:r==="catalog",onClick:()=>{c("catalog"),E||q()},children:"Catalog"})]}),r==="installed"?e.jsxs("div",{className:"flex gap-5 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-[220px] flex flex-col gap-3 min-h-0 overflow-hidden",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Servers"}),e.jsx("div",{className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] flex items-center px-3 text-[12px] text-[#9CA3AF] dark:text-[#71717a] font-mono shrink-0",children:"Search servers..."}),e.jsxs("div",{className:"flex flex-col gap-2 overflow-y-auto flex-1 min-h-0 pr-1",children:[g.length===0&&!B&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"No MCP servers configured"}),g.map(t=>e.jsxs("button",{onClick:()=>m(t.id),className:A("text-left rounded-lg px-3 py-2 flex flex-col gap-1 transition-colors shrink-0",t.id===s?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:A("text-[11px] font-mono font-semibold",xe[t.status]),children:me[t.status]})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] truncate",children:t.endpoint})]},t.id))]})]}),u?e.jsxs("div",{className:"flex-1 flex flex-col gap-3 overflow-y-auto pr-2 min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:u.name}),e.jsx("span",{className:A("text-xs font-mono font-semibold",xe[u.status]),children:me[u.status]})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:u.description}),u.error&&e.jsxs("p",{className:"text-[12px] font-mono text-[#ef4444]",children:["Error: ",u.error]}),e.jsxs("div",{className:"flex items-center gap-2",children:[u.status==="connected"?e.jsx("button",{onClick:()=>Q(u.name),className:"h-7 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Disconnect"}):e.jsx("button",{onClick:()=>H(u.name),className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:"Connect"}),e.jsx("button",{onClick:()=>X(u.name),className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold",children:"Delete"})]}),e.jsx("div",{className:"h-px bg-[#E5E7EB] dark:bg-[#1f2937]"}),e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Permissions"}),e.jsx(K,{label:"File read",enabled:D.read,onToggle:()=>U("read")}),e.jsx(K,{label:"File write",enabled:D.write,onToggle:()=>U("write")}),e.jsx(K,{label:"Shell exec",enabled:D.shell,onToggle:()=>U("shell")}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Tools (",u.tools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:u.tools.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No tools available"}):u.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("div",{className:"flex-1 flex items-center justify-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 gap-4 flex-1 min-h-0",children:[e.jsx("div",{className:"flex items-center gap-3 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(ye,{className:"h-3.5 w-3.5 text-[#9CA3AF] dark:text-[#71717a]"}),e.jsx("input",{type:"text",value:k,onChange:t=>{v(t.target.value),O(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:R,className:"flex-1 overflow-y-auto min-h-0",children:[L&&!E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ce,{className:"h-6 w-6 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-3 pb-4",children:E==null?void 0:E.list.map(t=>{var ne,re;const j=Z.has(t.name.toLowerCase().replace(/\s+/g,"-")),b=p===t.name,J=f(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 items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name}),e.jsx("span",{className:A("text-[10px] font-mono px-2 py-0.5 rounded shrink-0",J==="Official"?"bg-[#16A34A]/20 dark:bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:J})]}),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]}),((ne=t.publisher)==null?void 0:ne.username)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",t.publisher.username]})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-auto pt-2",children:[e.jsxs("a",{href:((re=t.links)==null?void 0:re.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(de,{className:"h-3 w-3"}),"npm"]}),j?e.jsxs("span",{className:"text-[11px] font-mono text-[#16A34A] dark:text-[#22C55E] flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),"Installed"]}):e.jsxs("button",{onClick:()=>z(t),disabled:b,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(Ae,{className:A("h-3 w-3",b&&"animate-pulse")}),b?"Installing...":"Install"]})]})]},t.name)})}),M&&e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(ce,{className:"h-5 w-5 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}),$&&E&&E.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:[(E==null?void 0:E.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(de,{className:"h-3 w-3"})]})]})]})]})})]})}),e.jsx(Ue,{open:d,onOpenChange:l,onAdd:I}),C&&e.jsx($e,{pkg:C,onClose:()=>F(null),onInstall:t=>{_(C.name),I(t)}})]})}function fe({active:a,children:n,onClick:r}){return e.jsx("button",{onClick:r,className:A("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",a?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:n})}function K({label:a,enabled:n,onToggle:r}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:a}),e.jsx(He,{enabled:n,onChange:r})]})}function He({enabled:a,onChange:n}){return e.jsx("button",{onClick:n,className:A("w-9 h-5 rounded-full px-0.5 flex items-center transition-colors",a?"bg-[#16A34A] dark:bg-[#22C55E] justify-end":"bg-[#E5E7EB] dark:bg-[#27272a] justify-start"),children:e.jsx("span",{className:"h-4 w-4 rounded-full bg-white"})})}function Ue({open:a,onOpenChange:n,onAdd:r}){const[c,d]=o.useState("form"),[l,s]=o.useState(""),[m,h]=o.useState(""),[i,k]=o.useState(""),[v,N]=o.useState(`{
|
|
1
|
+
import{r as o,j as e}from"./vendor-react-BalntB5F.js";import{u as ge,D as V,a as ee,b as te,c as A}from"./index-BJTSF3fc.js";import{_ as T,q as w,r as se,s as oe,t as W}from"./vendor-radix-CESj0OOY.js";import{i as ve,a as Ee,d as le,u as pe,b as be,c as je,e as P,f as G,g as ke}from"./useRequest-DITGl55G.js";import{z as Ne,P as Ce,X as ae,A as ye,L as ce,B as de,c as we,D as Ae}from"./vendor-icons-BuFpOlRn.js";import"./vendor-markdown-Bo4W9Tae.js";import"./vendor-monaco-w6PwaWGP.js";function Y(a,n){if(ve){if(!a)return n;var r;return Ee(a)?r=a():"current"in a?r=a.current:r=a,r}}var Se=function(a){var n=function(r,c,d){var l=o.useRef(!1),s=o.useRef([]),m=o.useRef([]),h=o.useRef(void 0);a(function(){var i,k=Array.isArray(d)?d:[d],v=k.map(function(N){return Y(N)});if(!l.current){l.current=!0,s.current=v,m.current=c,h.current=r();return}(v.length!==s.current.length||!le(s.current,v)||!le(m.current,c))&&((i=h.current)===null||i===void 0||i.call(h),s.current=v,m.current=c,h.current=r())}),pe(function(){var i;(i=h.current)===null||i===void 0||i.call(h),l.current=!1})};return n},Fe=Se(o.useEffect);function Be(){var a=(typeof global>"u"?"undefined":typeof global)=="object"&&global&&global.Object===Object&&global,n=typeof self=="object"&&self&&self.Object===Object&&self;return a||n}Be()||(global.Date=Date);function Me(a,n){var r,c=be(a),d=(r=n==null?void 0:n.wait)!==null&&r!==void 0?r:1e3,l=o.useMemo(function(){return je(function(){for(var s=[],m=0;m<arguments.length;m++)s[m]=arguments[m];return c.current.apply(c,T([],w(s),!1))},d,n)},[]);return pe(function(){l.cancel()}),{run:l,cancel:l.cancel,flush:l.flush}}function De(a,n,r){r===void 0&&(r={});var c=r.enable,d=c===void 0?!0:c,l=be(n);Fe(function(){if(d){var s=Y(r.target,window);if(s!=null&&s.addEventListener){var m=function(i){return l.current(i)},h=Array.isArray(a)?a:[a];return h.forEach(function(i){s.addEventListener(i,m,{capture:r.capture,once:r.once,passive:r.passive})}),function(){h.forEach(function(i){s.removeEventListener(i,m,{capture:r.capture})})}}}},[a,r.capture,r.once,r.passive,d],r.target)}var Te=function(a){return a===document||a===document.documentElement||a===document.body?Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop):a.scrollTop},ie=function(a){return a.scrollHeight||Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)},_e=function(a){return a.clientHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight)},Ie=function(a,n){n===void 0&&(n={});var r=n.target,c=n.isNoMore,d=n.threshold,l=d===void 0?100:d,s=n.direction,m=s===void 0?"bottom":s,h=n.reloadDeps,i=h===void 0?[]:h,k=n.manual,v=n.onBefore,N=n.onSuccess,S=n.onError,p=n.onFinally,_=w(o.useState(),2),C=_[0],F=_[1],R=w(o.useState(!1),2),O=R[0],g=R[1],B=m==="top",y=o.useRef(void 0),E=o.useRef(0),L=o.useMemo(function(){return c?c(C):!1},[C]),M=P(function(x){return se(void 0,void 0,void 0,function(){var f;return oe(this,function(t){switch(t.label){case 0:return[4,a(x)];case 1:return f=t.sent(),[2,{currentData:f,lastData:x}]}})})},{manual:k,onFinally:function(x,f,t){g(!1),p==null||p(f==null?void 0:f.currentData,t)},onBefore:function(){return v==null?void 0:v()},onSuccess:function(x){var f,t,j;x.lastData?F(W(W({},x.currentData),{list:B?T(T([],w(x.currentData.list),!1),w((t=x.lastData.list)!==null&&t!==void 0?t:[]),!1):T(T([],w((j=x.lastData.list)!==null&&j!==void 0?j:[]),!1),w(x.currentData.list),!1)})):F(W(W({},x.currentData),{list:T([],w((f=x.currentData.list)!==null&&f!==void 0?f:[]),!1)})),setTimeout(function(){if(B){var b=Y(r);if(b=b===document?document.documentElement:b,b){var J=ie(b);b.scrollTo(0,J-E.current)}}else z()}),N==null||N(x.currentData)},onError:function(x){return S==null?void 0:S(x)}}),$=M.loading,q=M.error,H=M.run,Q=M.runAsync,X=M.cancel,I=G(function(){L||(g(!0),H(C))}),u=function(x){return se(void 0,void 0,void 0,function(){var f;return oe(this,function(t){switch(t.label){case 0:return[4,Q(x)];case 1:return f=t.sent(),[2,f.currentData]}})})},D=G(function(){return L?Promise.reject():(g(!0),u(C))}),U=function(){return g(!1),H()},Z=function(){return g(!1),u()},z=function(){var x=Y(r);if(x){var f=x===document?document.documentElement:x,t=Te(f),j=ie(f),b=_e(f);B?(y.current!==void 0&&y.current>t&&t<=l&&I(),y.current=t,E.current=j-t):j-t<=b+l&&I()}};return De("scroll",function(){$||O||z()},{target:r}),ke(function(){H()},T([],w(i),!1)),{data:C,loading:!O&&$,error:q,loadingMore:O,noMore:L,loadMore:I,loadMoreAsync:D,reload:G(U),reloadAsync:G(Z),mutate:F,cancel:X}};const xe={connected:"text-[#16A34A] dark:text-[#22C55E]",connecting:"text-[#2563eb] dark:text-[#3b82f6]",offline:"text-[#f59e0b]",error:"text-[#ef4444]"},me={connected:"Connected",connecting:"Connecting...",offline:"Offline",error:"Error"},ue=20,Pe=async()=>{const a=await fetch("/mcp");if(!a.ok)throw new Error("Failed to fetch servers");return a.json()},Re="mcp server @modelcontextprotocol",Oe=3,Le=async(a,n)=>{const r=a&&a.length>=Oe?a:Re,c=`https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(r)}&size=${ue}&from=${n}`,d=await fetch(c);if(!d.ok)throw new Error("Failed to fetch packages");const l=await d.json();return{list:l.objects.map(s=>s.package),total:l.total,hasMore:n+ue<l.total}};function Xe(){const{isMcpOpen:a,toggleMcp:n}=ge(),[r,c]=o.useState("installed"),[d,l]=o.useState(!1),[s,m]=o.useState(null),[h,i]=o.useState({}),[k,v]=o.useState(""),[N,S]=o.useState(""),[p,_]=o.useState(null),[C,F]=o.useState(null),R=o.useRef(null),{run:O}=Me(t=>{S(t)},{wait:500}),{data:g=[],loading:B,run:y}=P(Pe,{refreshDeps:[a],ready:a,onSuccess:t=>{t.length>0&&!s&&m(t[0].id)}}),{data:E,loading:L,loadingMore:M,noMore:$,reload:q}=Ie(async t=>{var b;const j=((b=t==null?void 0:t.list)==null?void 0:b.length)??0;return Le(N,j)},{target:R,isNoMore:t=>!(t!=null&&t.hasMore),reloadDeps:[N],manual:!a||r!=="catalog"}),{runAsync:H}=P(async t=>{await fetch(`/mcp/${encodeURIComponent(t)}/connect`,{method:"POST"})},{manual:!0,onSuccess:y}),{runAsync:Q}=P(async t=>{await fetch(`/mcp/${encodeURIComponent(t)}/disconnect`,{method:"POST"})},{manual:!0,onSuccess:y}),{runAsync:X}=P(async t=>{await fetch(`/mcp/${encodeURIComponent(t)}`,{method:"DELETE"})},{manual:!0,onSuccess:y}),{runAsync:I}=P(async t=>{await fetch("/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,config:t})})},{manual:!0,onSuccess:()=>{y(),l(!1),F(null),_(null)},onError:()=>{_(null)}}),u=o.useMemo(()=>g.find(t=>t.id===s)??g[0],[g,s]),D=u?h[u.id]??{read:!0,write:!1,shell:!1}:{read:!0,write:!1,shell:!1},U=t=>{u&&i(j=>({...j,[u.id]:{...D,[t]:!D[t]}}))},Z=o.useMemo(()=>new Set(g.map(t=>t.name.toLowerCase())),[g]),z=t=>{F(t)},x=t=>t.startsWith("@modelcontextprotocol/"),f=t=>x(t.name)?"Official":"Community";return e.jsxs(e.Fragment,{children:[e.jsx(V,{open:a,onOpenChange:n,children:e.jsxs(ee,{className:"sm:max-w-[900px] h-[680px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl flex flex-col","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(te,{className:"sr-only",children:"MCP"}),e.jsx("div",{className:"flex flex-1 min-h-0",children:e.jsxs("div",{className:"flex-1 p-8 flex flex-col gap-5 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between 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 items-center gap-2",children:[e.jsx("button",{onClick:y,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:B,children:e.jsx(Ne,{className:A("h-4 w-4",B&&"animate-spin")})}),e.jsxs("button",{onClick:()=>l(!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(Ce,{className:"h-3.5 w-3.5"}),"Add server"]}),e.jsx("button",{onClick:n,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(ae,{className:"h-4 w-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(fe,{active:r==="installed",onClick:()=>c("installed"),children:["Installed (",g.length,")"]}),e.jsx(fe,{active:r==="catalog",onClick:()=>{c("catalog"),E||q()},children:"Catalog"})]}),r==="installed"?e.jsxs("div",{className:"flex gap-5 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-[220px] flex flex-col gap-3 min-h-0 overflow-hidden",children:[e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] shrink-0",children:"Servers"}),e.jsx("div",{className:"h-8 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] flex items-center px-3 text-[12px] text-[#9CA3AF] dark:text-[#71717a] font-mono shrink-0",children:"Search servers..."}),e.jsxs("div",{className:"flex flex-col gap-2 overflow-y-auto flex-1 min-h-0 pr-1",children:[g.length===0&&!B&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"No MCP servers configured"}),g.map(t=>e.jsxs("button",{onClick:()=>m(t.id),className:A("text-left rounded-lg px-3 py-2 flex flex-col gap-1 transition-colors shrink-0",t.id===s?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C] hover:bg-[#F3F4F6] dark:hover:bg-[#18181b]"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:t.name}),e.jsx("span",{className:A("text-[11px] font-mono font-semibold",xe[t.status]),children:me[t.status]})]}),e.jsx("span",{className:"text-[11px] font-mono text-[#6B7280] dark:text-[#94a3b8] truncate",children:t.endpoint})]},t.id))]})]}),u?e.jsxs("div",{className:"flex-1 flex flex-col gap-3 overflow-y-auto pr-2 min-h-0",children:[e.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[e.jsx("span",{className:"text-base font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:u.name}),e.jsx("span",{className:A("text-xs font-mono font-semibold",xe[u.status]),children:me[u.status]})]}),e.jsx("p",{className:"text-[12px] font-mono text-[#6B7280] dark:text-[#94a3b8]",children:u.description}),u.error&&e.jsxs("p",{className:"text-[12px] font-mono text-[#ef4444]",children:["Error: ",u.error]}),e.jsxs("div",{className:"flex items-center gap-2",children:[u.status==="connected"?e.jsx("button",{onClick:()=>Q(u.name),className:"h-7 px-3 rounded-md bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5] text-[11px] font-mono font-semibold",children:"Disconnect"}):e.jsx("button",{onClick:()=>H(u.name),className:"h-7 px-3 rounded-md bg-[#16A34A] dark:bg-[#22C55E] text-white dark:text-[#0C0C0C] text-[11px] font-mono font-semibold",children:"Connect"}),e.jsx("button",{onClick:()=>X(u.name),className:"h-7 px-3 rounded-md bg-[#F3F4F6] dark:bg-[#18181b] text-[#ef4444] text-[11px] font-mono font-semibold",children:"Delete"})]}),e.jsx("div",{className:"h-px bg-[#E5E7EB] dark:bg-[#1f2937]"}),e.jsx("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:"Permissions"}),e.jsx(K,{label:"File read",enabled:D.read,onToggle:()=>U("read")}),e.jsx(K,{label:"File write",enabled:D.write,onToggle:()=>U("write")}),e.jsx(K,{label:"Shell exec",enabled:D.shell,onToggle:()=>U("shell")}),e.jsxs("span",{className:"text-sm font-mono font-semibold text-[#111827] dark:text-[#E5E5E5]",children:["Tools (",u.tools.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:u.tools.length===0?e.jsx("span",{className:"text-[12px] font-mono text-[#9CA3AF] dark:text-[#71717a]",children:"No tools available"}):u.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("div",{className:"flex-1 flex items-center justify-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 gap-4 flex-1 min-h-0",children:[e.jsx("div",{className:"flex items-center gap-3 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(ye,{className:"h-3.5 w-3.5 text-[#9CA3AF] dark:text-[#71717a]"}),e.jsx("input",{type:"text",value:k,onChange:t=>{v(t.target.value),O(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:R,className:"flex-1 overflow-y-auto min-h-0",children:[L&&!E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ce,{className:"h-6 w-6 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}):e.jsx("div",{className:"grid grid-cols-2 gap-3 pb-4",children:E==null?void 0:E.list.map(t=>{var ne,re;const j=Z.has(t.name.toLowerCase().replace(/\s+/g,"-")),b=p===t.name,J=f(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 items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[13px] font-mono font-semibold text-[#111827] dark:text-[#E5E5E5] truncate",children:t.name}),e.jsx("span",{className:A("text-[10px] font-mono px-2 py-0.5 rounded shrink-0",J==="Official"?"bg-[#16A34A]/20 dark:bg-[#22C55E]/20 text-[#16A34A] dark:text-[#22C55E]":"bg-[#3b82f6]/20 text-[#3b82f6]"),children:J})]}),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]}),((ne=t.publisher)==null?void 0:ne.username)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",t.publisher.username]})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-auto pt-2",children:[e.jsxs("a",{href:((re=t.links)==null?void 0:re.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(de,{className:"h-3 w-3"}),"npm"]}),j?e.jsxs("span",{className:"text-[11px] font-mono text-[#16A34A] dark:text-[#22C55E] flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),"Installed"]}):e.jsxs("button",{onClick:()=>z(t),disabled:b,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(Ae,{className:A("h-3 w-3",b&&"animate-pulse")}),b?"Installing...":"Install"]})]})]},t.name)})}),M&&e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(ce,{className:"h-5 w-5 text-[#9CA3AF] dark:text-[#71717a] animate-spin"})}),$&&E&&E.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:[(E==null?void 0:E.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(de,{className:"h-3 w-3"})]})]})]})]})})]})}),e.jsx(Ue,{open:d,onOpenChange:l,onAdd:I}),C&&e.jsx($e,{pkg:C,onClose:()=>F(null),onInstall:t=>{_(C.name),I(t)}})]})}function fe({active:a,children:n,onClick:r}){return e.jsx("button",{onClick:r,className:A("px-3 py-1 rounded text-[12px] font-mono font-semibold transition-colors",a?"bg-[#E5E7EB] text-[#111827] dark:bg-[#27272a] dark:text-[#E5E5E5]":"text-[#6B7280] dark:text-[#a1a1aa]"),children:n})}function K({label:a,enabled:n,onToggle:r}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-mono text-[#6B7280] dark:text-[#a1a1aa]",children:a}),e.jsx(He,{enabled:n,onChange:r})]})}function He({enabled:a,onChange:n}){return e.jsx("button",{onClick:n,className:A("w-9 h-5 rounded-full px-0.5 flex items-center transition-colors",a?"bg-[#16A34A] dark:bg-[#22C55E] justify-end":"bg-[#E5E7EB] dark:bg-[#27272a] justify-start"),children:e.jsx("span",{className:"h-4 w-4 rounded-full bg-white"})})}function Ue({open:a,onOpenChange:n,onAdd:r}){const[c,d]=o.useState("form"),[l,s]=o.useState(""),[m,h]=o.useState(""),[i,k]=o.useState(""),[v,N]=o.useState(`{
|
|
2
2
|
"name": "my-server",
|
|
3
3
|
"command": "npx",
|
|
4
4
|
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as n,j as e}from"./vendor-react-Dm1xU4bP.js";import{D as U,a as z,b as K,c as b,u as J,d as Q}from"./index-Cnz-_jPt.js";import{u as V}from"./SettingsStore-B2GIhfKs.js";import{X as P,j as M,E as G,u as _,d as W,e as X}from"./vendor-icons-BKXQ7ALf.js";import"./vendor-markdown-DIcugY1e.js";import"./vendor-monaco-w6PwaWGP.js";import"./vendor-radix-2yBsoRqx.js";const L={id:"custom",name:"Custom (OpenAI Compatible)",icon:"🔌",description:"Any OpenAI-compatible API",envVars:[],bladeProvider:"openai-compatible"};function Y({open:p,onOpenChange:c,onSave:u}){const[E,d]=n.useState([L]),[x,s]=n.useState([]),[r,j]=n.useState("custom"),[o,i]=n.useState({bladeProvider:"openai-compatible",baseUrl:"",apiKey:"",modelId:"",name:""}),[y,N]=n.useState(!1),[w,v]=n.useState(!1),[k,S]=n.useState(!1);n.useEffect(()=>{p&&fetch("/providers").then(a=>a.json()).then(a=>d([L,...a])).catch(a=>console.error("Failed to load providers:",a))},[p]),n.useEffect(()=>{r&&r!=="custom"?fetch(`/providers/${r}/models`).then(a=>a.json()).then(a=>s(a)).catch(a=>console.error("Failed to load models:",a)):s([])},[r]);const F=a=>{j(a.id),i({...o,bladeProvider:a.bladeProvider,baseUrl:a.defaultBaseUrl||"",modelId:"",name:""}),N(!1)},A=()=>{!o.modelId||!o.apiKey||(u({...o,name:o.name||o.modelId}),i({bladeProvider:"openai-compatible",baseUrl:"",apiKey:"",modelId:"",name:""}),j("custom"),c(!1))},h=E.find(a=>a.id===r),B=x.find(a=>a.id===o.modelId),C=!(r==="custom")&&x.length>0,I=o.modelId&&o.apiKey;return e.jsx(U,{open:p,onOpenChange:c,children:e.jsxs(z,{className:"sm:max-w-[480px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl [&>button]:hidden","aria-describedby":void 0,children:[e.jsx(K,{className:"sr-only",children:"Add Model"}),e.jsxs("div",{className:"p-6 flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Add Model"}),e.jsx("button",{onClick:()=>c(!1),className:"text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:e.jsx(P,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(!y),className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#27272a] transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{children:h==null?void 0:h.icon}),e.jsx("span",{children:h==null?void 0:h.name})]}),e.jsx(M,{className:"h-4 w-4 text-[#9CA3AF] dark:text-[#71717a]"})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>N(!1)}),e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white dark:bg-[#18181b] border border-[#E5E7EB] dark:border-zinc-800 rounded-md py-1 z-50 max-h-64 overflow-y-auto shadow-lg",children:E.map(a=>e.jsx("button",{type:"button",className:b("w-full text-left px-3 py-2 text-sm font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#27272a] transition-colors",r===a.id?"text-[#111827] dark:text-[#E5E5E5] bg-[#F3F4F6] dark:bg-[#27272a]":"text-[#6B7280] dark:text-[#a1a1aa]"),onClick:()=>F(a),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:a.icon}),e.jsx("span",{className:"font-medium",children:a.name})]})},a.id))})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Base URL"}),e.jsx("input",{type:"text",value:o.baseUrl,onChange:a=>i({...o,baseUrl:a.target.value}),placeholder:(h==null?void 0:h.defaultBaseUrl)||"https://api.openai.com/v1",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:k?"text":"password",value:o.apiKey,onChange:a=>i({...o,apiKey:a.target.value}),placeholder:"sk-........................",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 pr-10 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"}),e.jsx("button",{type:"button",onClick:()=>S(!k),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:k?e.jsx(G,{className:"h-4 w-4"}):e.jsx(_,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Model ID"}),C&&e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>v(!w),className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#27272a] transition-colors",children:[(B==null?void 0:B.name)||o.modelId||"Select model",e.jsx(M,{className:"h-4 w-4 text-[#9CA3AF] dark:text-[#71717a]"})]}),w&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>v(!1)}),e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white dark:bg-[#18181b] border border-[#E5E7EB] dark:border-zinc-800 rounded-md py-1 z-50 max-h-48 overflow-y-auto shadow-lg",children:x.map(a=>e.jsx("button",{type:"button",className:b("w-full text-left px-3 py-2 text-sm font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#27272a] transition-colors",o.modelId===a.id?"text-[#111827] dark:text-[#E5E5E5] bg-[#F3F4F6] dark:bg-[#27272a]":"text-[#6B7280] dark:text-[#a1a1aa]"),onClick:()=>{i({...o,modelId:a.id,name:a.name}),v(!1)},children:a.name},a.id))})]})]}),e.jsx("input",{type:"text",value:o.modelId,onChange:a=>i({...o,modelId:a.target.value,name:a.target.value}),placeholder:"gpt-4o, claude-3-opus, deepseek-chat, etc.",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"}),C&&e.jsx("p",{className:"text-[12px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:"You can select a listed model or type a custom model ID."})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>c(!1),className:"flex-1 px-4 py-2 rounded-md text-sm text-[#6B7280] dark:text-[#a1a1aa] font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#18181b] transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:A,disabled:!I,className:"flex-1 px-4 py-2 rounded-md text-sm text-white font-semibold font-mono bg-[#16A34A] hover:bg-[#15803d] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Save Model"})]})]})]})})}function q({open:p,onOpenChange:c,model:u,onSave:E}){const[d,x]=n.useState({baseUrl:"",apiKey:"",model:""}),[s,r]=n.useState(!1);n.useEffect(()=>{u&&x({baseUrl:u.baseUrl||"",apiKey:u.apiKey||"",model:u.model||""})},[u]);const j=()=>{!u||!d.model||(E(u.id,{baseUrl:d.baseUrl||void 0,apiKey:d.apiKey||void 0,model:d.model}),c(!1))},o=d.model;return e.jsx(U,{open:p,onOpenChange:c,children:e.jsxs(z,{className:"sm:max-w-[480px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl [&>button]:hidden","aria-describedby":void 0,children:[e.jsx(K,{className:"sr-only",children:"Edit Model"}),e.jsxs("div",{className:"p-6 flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Edit Model"}),e.jsx("button",{onClick:()=>c(!1),className:"text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:e.jsx(P,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Model ID"}),e.jsx("input",{type:"text",value:d.model,onChange:i=>x({...d,model:i.target.value}),placeholder:"gpt-4o, claude-3-opus, etc.",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Base URL"}),e.jsx("input",{type:"text",value:d.baseUrl,onChange:i=>x({...d,baseUrl:i.target.value}),placeholder:"https://api.openai.com/v1",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:s?"text":"password",value:d.apiKey,onChange:i=>x({...d,apiKey:i.target.value}),placeholder:"Leave empty to keep current key",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 pr-10 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"}),e.jsx("button",{type:"button",onClick:()=>r(!s),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:s?e.jsx(G,{className:"h-4 w-4"}):e.jsx(_,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>c(!1),className:"flex-1 px-4 py-2 rounded-md text-sm text-[#6B7280] dark:text-[#a1a1aa] font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#18181b] transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:j,disabled:!o,className:"flex-1 px-4 py-2 rounded-md text-sm text-white font-semibold font-mono bg-[#16A34A] hover:bg-[#15803d] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Save Changes"})]})]})]})})}const Z={"openai-compatible":{bg:"#10a37f",label:"OA"},anthropic:{bg:"#d97757",label:"A"},gemini:{bg:"#4285f4",label:"G"},"azure-openai":{bg:"#0078d4",label:"Az"},"gpt-openai-platform":{bg:"#10a37f",label:"GP"}};function re(){var O;const{isSettingsOpen:p,toggleSettings:c,isSidebarOpen:u,setSidebarOpen:E}=J(),{configuredModels:d,loadModels:x}=Q(),s=V(),[r,j]=n.useState("general"),[o,i]=n.useState(!1),[y,N]=n.useState(null),[w,v]=n.useState(null),[k,S]=n.useState(""),[F,A]=n.useState("all"),h=[{value:"general",label:"General"},{value:"models",label:"Models"},{value:"shortcuts",label:"Shortcuts"}],D=n.useMemo(()=>[{action:"Open command palette",combo:["Ctrl","K"],scope:"Global"},{action:"New chat",combo:["Ctrl","N"],scope:"Chat"},{action:"Focus input",combo:["Ctrl","L"],scope:"Chat"},{action:"Toggle sidebar",combo:["Ctrl","B"],scope:"Layout"},{action:"Search history",combo:["Ctrl","H"],scope:"History"}],[]).filter(t=>{const l=t.action.toLowerCase().includes(k.toLowerCase()),m=F==="all"||t.scope.toLowerCase()===F;return l&&m}),C=d.reduce((t,l)=>{const m=l.provider||"unknown";return t[m]||(t[m]=[]),t[m].push(l),t},{});n.useEffect(()=>{p&&(x(),s.loadSettings())},[p,x,s.loadSettings]);const I=async t=>{try{if(!(await fetch("/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.bladeProvider,name:t.name||t.modelId,model:t.modelId,baseUrl:t.baseUrl||void 0,apiKey:t.apiKey||void 0})})).ok)throw new Error("Failed to save model");await x()}catch(l){console.error("Failed to save model:",l)}},a=async t=>{try{if(!(await fetch(`/models/${t}`,{method:"DELETE"})).ok)throw new Error("Failed to delete model");await x()}catch(l){console.error("Failed to delete model:",l)}},$=async(t,l)=>{try{if(!(await fetch(`/models/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)})).ok)throw new Error("Failed to update model");await x()}catch(m){console.error("Failed to update model:",m)}},H=t=>{N(y===t?null:t)};return e.jsxs(e.Fragment,{children:[e.jsx(U,{open:p,onOpenChange:c,children:e.jsxs(z,{className:"sm:max-w-[800px] h-[600px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl flex flex-col","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(K,{className:"sr-only",children:"Settings"}),e.jsxs("div",{className:"flex h-full",children:[e.jsx("div",{className:"w-[200px] h-full bg-[#F3F4F6] dark:bg-[#18181b] p-6 flex flex-col gap-2",children:h.map(t=>e.jsx("button",{onClick:()=>j(t.value),className:b("w-full text-left px-3 py-2 rounded-md text-sm font-mono transition-colors",r===t.value?"bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5] font-medium":"text-[#6B7280] hover:text-[#111827] hover:bg-[#E5E7EB]/60 dark:text-[#a1a1aa] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a]/50"),children:t.label},t.value))}),e.jsxs("div",{className:"flex-1 p-8 flex flex-col gap-6 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:r==="general"?"Settings":(O=h.find(t=>t.value===r))==null?void 0:O.label}),e.jsx("button",{onClick:c,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(P,{className:"h-4 w-4"})})]}),r==="models"&&e.jsxs("div",{className:"flex flex-col gap-6 flex-1 min-h-0 overflow-hidden",children:[e.jsx("p",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono shrink-0",children:"Configure API keys and model settings for different providers."}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:e.jsxs("div",{className:"flex flex-col gap-2 pr-2",children:[Object.entries(C).map(([t,l])=>{const m=Z[t]||{bg:"#71717a",label:"?"},T=l.some(f=>f.apiKey),R=y===t;return e.jsxs("div",{className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>H(t),className:"w-full p-4 flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#1f1f23] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded flex items-center justify-center text-white text-xs font-bold",style:{backgroundColor:m.bg},children:m.label}),e.jsxs("div",{className:"flex flex-col gap-0.5 text-left",children:[e.jsx("span",{className:"text-sm font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono capitalize",children:t.replace(/-/g," ")}),e.jsxs("span",{className:"text-xs text-[#9CA3AF] dark:text-[#71717a] font-mono",children:[l.length," model",l.length>1?"s":""]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:b("text-xs font-mono",T?"text-[#16A34A]":"text-[#9CA3AF] dark:text-[#71717a]"),children:T?"● Connected":"○ Not Connected"}),e.jsx(M,{className:b("h-4 w-4 text-[#9CA3AF] dark:text-[#71717a] transition-transform",R&&"rotate-180")})]})]}),R&&e.jsx("div",{className:"border-t border-[#E5E7EB] dark:border-zinc-800",children:l.map(f=>e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#1f1f23] group",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm text-[#111827] dark:text-[#E5E5E5] font-mono truncate",children:f.model}),e.jsx("span",{className:"text-xs text-[#9CA3AF] dark:text-[#71717a] font-mono truncate",children:f.baseUrl||"Default URL"})]}),e.jsxs("div",{className:"flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:()=>v(f),className:"p-1.5 text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] rounded transition-colors",children:e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>a(f.id),className:"p-1.5 text-[#9CA3AF] hover:text-red-500 hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-red-400 dark:hover:bg-[#27272a] rounded transition-colors",children:e.jsx(X,{className:"h-3.5 w-3.5"})})]})]},f.id))})]},t)}),Object.keys(C).length===0&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"No models configured yet"})]})}),e.jsx("button",{onClick:()=>i(!0),className:"w-full py-3 rounded-md text-[#6B7280] dark:text-[#a1a1aa] text-[13px] font-mono hover:bg-[#F3F4F6] dark:bg-[#18181b] transition-colors shrink-0",children:"+ Add New Model"})]}),r==="general"&&e.jsxs("div",{className:"flex flex-col gap-6 overflow-y-auto pr-2",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"General"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Response Language"}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:"AI will respond in this language"})]}),e.jsxs("select",{value:s.language,onChange:t=>s.updateSettings({language:t.target.value}),className:"h-8 bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono rounded-md px-3 border border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsx("option",{value:"en-US",children:"English (US)"}),e.jsx("option",{value:"zh-CN",children:"简体中文"}),e.jsx("option",{value:"zh-TW",children:"繁體中文"}),e.jsx("option",{value:"ja-JP",children:"日本語"}),e.jsx("option",{value:"ko-KR",children:"한국어"}),e.jsx("option",{value:"es-ES",children:"Español"}),e.jsx("option",{value:"fr-FR",children:"Français"}),e.jsx("option",{value:"de-DE",children:"Deutsch"}),e.jsx("option",{value:"pt-BR",children:"Português (BR)"}),e.jsx("option",{value:"ru-RU",children:"Русский"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Auto-save sessions"}),e.jsx(g,{enabled:s.autoSaveSessions,onChange:t=>s.updateSettings({autoSaveSessions:t})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"Appearance"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Theme Preference"}),e.jsx("div",{className:"flex items-center gap-2 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md p-1",children:["dark","light","system"].map(t=>e.jsx("button",{onClick:()=>s.updateSettings({uiTheme:t}),className:b("px-3 py-1 rounded text-[12px] font-mono transition-colors",s.uiTheme===t?"bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5]":"text-[#9CA3AF] dark:text-[#71717a] hover:text-[#111827] dark:hover:text-[#E5E5E5]"),children:t==="dark"?"Dark":t==="light"?"Light":"System"},t))})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Compact sidebar"}),e.jsx(g,{enabled:!u,onChange:t=>E(!t)})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Code theme"}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:"Syntax highlighting colors"})]}),e.jsxs("select",{value:s.theme,onChange:t=>s.updateSettings({theme:t.target.value}),className:"h-8 bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono rounded-md px-3 border border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsx("option",{value:"dracula",children:"Dracula"}),e.jsx("option",{value:"monokai",children:"Monokai"}),e.jsx("option",{value:"nord",children:"Nord"}),e.jsx("option",{value:"tokyo-night",children:"Tokyo Night"}),e.jsx("option",{value:"one-dark",children:"One Dark"}),e.jsx("option",{value:"catppuccin",children:"Catppuccin"}),e.jsx("option",{value:"gruvbox",children:"Gruvbox"}),e.jsx("option",{value:"github",children:"GitHub"}),e.jsx("option",{value:"solarized-light",children:"Solarized Light"}),e.jsx("option",{value:"solarized-dark",children:"Solarized Dark"}),e.jsx("option",{value:"ayu-dark",children:"Ayu Dark"}),e.jsx("option",{value:"rose-pine",children:"Rose Pine"}),e.jsx("option",{value:"kanagawa",children:"Kanagawa"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"Notifications"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Build finished"}),e.jsx(g,{enabled:s.notifyBuild,onChange:t=>s.updateSettings({notifyBuild:t})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Errors only"}),e.jsx(g,{enabled:s.notifyErrors,onChange:t=>s.updateSettings({notifyErrors:t})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"System sounds"}),e.jsx(g,{enabled:s.notifySounds,onChange:t=>s.updateSettings({notifySounds:t})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"Privacy"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Telemetry"}),e.jsx(g,{enabled:s.privacyTelemetry,onChange:t=>s.updateSettings({privacyTelemetry:t})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Crash reports"}),e.jsx(g,{enabled:s.privacyCrash,onChange:t=>s.updateSettings({privacyCrash:t})})]})]})]}),r==="shortcuts"&&e.jsxs("div",{className:"flex flex-col gap-4 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsx("input",{value:k,onChange:t=>S(t.target.value),placeholder:"Search actions...",className:"flex-1 h-9 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono"}),e.jsxs("select",{value:F,onChange:t=>A(t.target.value),className:"h-9 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono",children:[e.jsx("option",{value:"all",children:"All scopes"}),e.jsx("option",{value:"global",children:"Global"}),e.jsx("option",{value:"chat",children:"Chat"}),e.jsx("option",{value:"layout",children:"Layout"}),e.jsx("option",{value:"history",children:"History"})]}),e.jsx("button",{onClick:()=>{S(""),A("all")},className:"h-9 px-3 rounded-md bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono font-semibold",children:"Reset"})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto border border-[#E5E7EB] dark:border-[#27272a] rounded-lg bg-[#E5E7EB] dark:bg-[#111827]",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_180px_120px] gap-2 px-3 py-2 bg-white dark:bg-[#0C0C0C] text-[12px] text-[#6B7280] dark:text-[#94a3b8] font-mono font-semibold",children:[e.jsx("span",{children:"Action"}),e.jsx("span",{children:"Shortcut"}),e.jsx("span",{children:"Scope"})]}),D.map((t,l)=>e.jsxs("div",{className:b("grid grid-cols-[1fr_180px_120px] gap-2 px-3 py-2 text-[13px] font-mono",l%2===0?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C]"),children:[e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5]",children:t.action}),e.jsx("div",{className:"flex items-center gap-1",children:t.combo.map(m=>e.jsx("span",{className:"px-2 py-0.5 rounded bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono font-semibold",children:m},m))}),e.jsx("span",{className:"text-[#6B7280] dark:text-[#94a3b8] text-[12px]",children:t.scope})]},`${t.action}-${t.scope}`)),D.length===0&&e.jsx("div",{className:"px-3 py-6 text-center text-[12px] text-[#6B7280] dark:text-[#94a3b8] font-mono",children:"No shortcuts found."})]})]})]})]})]})}),e.jsx(Y,{open:o,onOpenChange:i,onSave:I}),e.jsx(q,{open:!!w,onOpenChange:t=>!t&&v(null),model:w,onSave:$})]})}function g({enabled:p,onChange:c}){return e.jsx("button",{onClick:()=>c(!p),className:b("w-10 h-5 rounded-full px-0.5 flex items-center transition-colors",p?"bg-[#22C55E]":"bg-[#E5E7EB] dark:bg-[#27272a]"),children:e.jsx("span",{className:b("h-4 w-4 rounded-full transition-transform",p?"translate-x-5 bg-white":"translate-x-0 bg-white dark:bg-[#a1a1aa]")})})}export{re as SettingsModal};
|
|
1
|
+
import{r as n,j as e}from"./vendor-react-BalntB5F.js";import{D as U,a as z,b as K,c as b,u as J,d as Q}from"./index-BJTSF3fc.js";import{u as V}from"./SettingsStore-jup_Kikq.js";import{X as P,k as M,E as G,w as _,d as W,e as X}from"./vendor-icons-BuFpOlRn.js";import"./vendor-markdown-Bo4W9Tae.js";import"./vendor-monaco-w6PwaWGP.js";import"./vendor-radix-CESj0OOY.js";const L={id:"custom",name:"Custom (OpenAI Compatible)",icon:"🔌",description:"Any OpenAI-compatible API",envVars:[],bladeProvider:"openai-compatible"};function Y({open:p,onOpenChange:c,onSave:u}){const[E,d]=n.useState([L]),[x,s]=n.useState([]),[r,j]=n.useState("custom"),[o,i]=n.useState({bladeProvider:"openai-compatible",baseUrl:"",apiKey:"",modelId:"",name:""}),[y,N]=n.useState(!1),[w,v]=n.useState(!1),[k,S]=n.useState(!1);n.useEffect(()=>{p&&fetch("/providers").then(a=>a.json()).then(a=>d([L,...a])).catch(a=>console.error("Failed to load providers:",a))},[p]),n.useEffect(()=>{r&&r!=="custom"?fetch(`/providers/${r}/models`).then(a=>a.json()).then(a=>s(a)).catch(a=>console.error("Failed to load models:",a)):s([])},[r]);const F=a=>{j(a.id),i({...o,bladeProvider:a.bladeProvider,baseUrl:a.defaultBaseUrl||"",modelId:"",name:""}),N(!1)},A=()=>{!o.modelId||!o.apiKey||(u({...o,name:o.name||o.modelId}),i({bladeProvider:"openai-compatible",baseUrl:"",apiKey:"",modelId:"",name:""}),j("custom"),c(!1))},h=E.find(a=>a.id===r),B=x.find(a=>a.id===o.modelId),C=!(r==="custom")&&x.length>0,I=o.modelId&&o.apiKey;return e.jsx(U,{open:p,onOpenChange:c,children:e.jsxs(z,{className:"sm:max-w-[480px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl [&>button]:hidden","aria-describedby":void 0,children:[e.jsx(K,{className:"sr-only",children:"Add Model"}),e.jsxs("div",{className:"p-6 flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Add Model"}),e.jsx("button",{onClick:()=>c(!1),className:"text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:e.jsx(P,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(!y),className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#27272a] transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{children:h==null?void 0:h.icon}),e.jsx("span",{children:h==null?void 0:h.name})]}),e.jsx(M,{className:"h-4 w-4 text-[#9CA3AF] dark:text-[#71717a]"})]}),y&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>N(!1)}),e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white dark:bg-[#18181b] border border-[#E5E7EB] dark:border-zinc-800 rounded-md py-1 z-50 max-h-64 overflow-y-auto shadow-lg",children:E.map(a=>e.jsx("button",{type:"button",className:b("w-full text-left px-3 py-2 text-sm font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#27272a] transition-colors",r===a.id?"text-[#111827] dark:text-[#E5E5E5] bg-[#F3F4F6] dark:bg-[#27272a]":"text-[#6B7280] dark:text-[#a1a1aa]"),onClick:()=>F(a),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:a.icon}),e.jsx("span",{className:"font-medium",children:a.name})]})},a.id))})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Base URL"}),e.jsx("input",{type:"text",value:o.baseUrl,onChange:a=>i({...o,baseUrl:a.target.value}),placeholder:(h==null?void 0:h.defaultBaseUrl)||"https://api.openai.com/v1",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:k?"text":"password",value:o.apiKey,onChange:a=>i({...o,apiKey:a.target.value}),placeholder:"sk-........................",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 pr-10 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"}),e.jsx("button",{type:"button",onClick:()=>S(!k),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:k?e.jsx(G,{className:"h-4 w-4"}):e.jsx(_,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Model ID"}),C&&e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>v(!w),className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#27272a] transition-colors",children:[(B==null?void 0:B.name)||o.modelId||"Select model",e.jsx(M,{className:"h-4 w-4 text-[#9CA3AF] dark:text-[#71717a]"})]}),w&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>v(!1)}),e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white dark:bg-[#18181b] border border-[#E5E7EB] dark:border-zinc-800 rounded-md py-1 z-50 max-h-48 overflow-y-auto shadow-lg",children:x.map(a=>e.jsx("button",{type:"button",className:b("w-full text-left px-3 py-2 text-sm font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#27272a] transition-colors",o.modelId===a.id?"text-[#111827] dark:text-[#E5E5E5] bg-[#F3F4F6] dark:bg-[#27272a]":"text-[#6B7280] dark:text-[#a1a1aa]"),onClick:()=>{i({...o,modelId:a.id,name:a.name}),v(!1)},children:a.name},a.id))})]})]}),e.jsx("input",{type:"text",value:o.modelId,onChange:a=>i({...o,modelId:a.target.value,name:a.target.value}),placeholder:"gpt-4o, claude-3-opus, deepseek-chat, etc.",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"}),C&&e.jsx("p",{className:"text-[12px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:"You can select a listed model or type a custom model ID."})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>c(!1),className:"flex-1 px-4 py-2 rounded-md text-sm text-[#6B7280] dark:text-[#a1a1aa] font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#18181b] transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:A,disabled:!I,className:"flex-1 px-4 py-2 rounded-md text-sm text-white font-semibold font-mono bg-[#16A34A] hover:bg-[#15803d] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Save Model"})]})]})]})})}function q({open:p,onOpenChange:c,model:u,onSave:E}){const[d,x]=n.useState({baseUrl:"",apiKey:"",model:""}),[s,r]=n.useState(!1);n.useEffect(()=>{u&&x({baseUrl:u.baseUrl||"",apiKey:u.apiKey||"",model:u.model||""})},[u]);const j=()=>{!u||!d.model||(E(u.id,{baseUrl:d.baseUrl||void 0,apiKey:d.apiKey||void 0,model:d.model}),c(!1))},o=d.model;return e.jsx(U,{open:p,onOpenChange:c,children:e.jsxs(z,{className:"sm:max-w-[480px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl [&>button]:hidden","aria-describedby":void 0,children:[e.jsx(K,{className:"sr-only",children:"Edit Model"}),e.jsxs("div",{className:"p-6 flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:"Edit Model"}),e.jsx("button",{onClick:()=>c(!1),className:"text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:e.jsx(P,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Model ID"}),e.jsx("input",{type:"text",value:d.model,onChange:i=>x({...d,model:i.target.value}),placeholder:"gpt-4o, claude-3-opus, etc.",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Base URL"}),e.jsx("input",{type:"text",value:d.baseUrl,onChange:i=>x({...d,baseUrl:i.target.value}),placeholder:"https://api.openai.com/v1",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:s?"text":"password",value:d.apiKey,onChange:i=>x({...d,apiKey:i.target.value}),placeholder:"Leave empty to keep current key",className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 py-2.5 pr-10 text-sm text-[#111827] dark:text-[#E5E5E5] font-mono placeholder:text-[#9CA3AF] dark:placeholder:text-[#71717a] focus:outline-none focus:ring-1 focus:ring-[#D1D5DB] dark:focus:ring-zinc-600"}),e.jsx("button",{type:"button",onClick:()=>r(!s),className:"absolute right-3 top-1/2 -translate-y-1/2 text-[#9CA3AF] hover:text-[#111827] dark:text-[#71717a] dark:hover:text-[#E5E5E5] transition-colors",children:s?e.jsx(G,{className:"h-4 w-4"}):e.jsx(_,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>c(!1),className:"flex-1 px-4 py-2 rounded-md text-sm text-[#6B7280] dark:text-[#a1a1aa] font-mono hover:bg-[#F3F4F6] dark:hover:bg-[#18181b] transition-colors",children:"Cancel"}),e.jsx("button",{type:"button",onClick:j,disabled:!o,className:"flex-1 px-4 py-2 rounded-md text-sm text-white font-semibold font-mono bg-[#16A34A] hover:bg-[#15803d] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:"Save Changes"})]})]})]})})}const Z={"openai-compatible":{bg:"#10a37f",label:"OA"},anthropic:{bg:"#d97757",label:"A"},gemini:{bg:"#4285f4",label:"G"},"azure-openai":{bg:"#0078d4",label:"Az"},"gpt-openai-platform":{bg:"#10a37f",label:"GP"}};function re(){var O;const{isSettingsOpen:p,toggleSettings:c,isSidebarOpen:u,setSidebarOpen:E}=J(),{configuredModels:d,loadModels:x}=Q(),s=V(),[r,j]=n.useState("general"),[o,i]=n.useState(!1),[y,N]=n.useState(null),[w,v]=n.useState(null),[k,S]=n.useState(""),[F,A]=n.useState("all"),h=[{value:"general",label:"General"},{value:"models",label:"Models"},{value:"shortcuts",label:"Shortcuts"}],D=n.useMemo(()=>[{action:"Open command palette",combo:["Ctrl","K"],scope:"Global"},{action:"New chat",combo:["Ctrl","N"],scope:"Chat"},{action:"Focus input",combo:["Ctrl","L"],scope:"Chat"},{action:"Toggle sidebar",combo:["Ctrl","B"],scope:"Layout"},{action:"Search history",combo:["Ctrl","H"],scope:"History"}],[]).filter(t=>{const l=t.action.toLowerCase().includes(k.toLowerCase()),m=F==="all"||t.scope.toLowerCase()===F;return l&&m}),C=d.reduce((t,l)=>{const m=l.provider||"unknown";return t[m]||(t[m]=[]),t[m].push(l),t},{});n.useEffect(()=>{p&&(x(),s.loadSettings())},[p,x,s.loadSettings]);const I=async t=>{try{if(!(await fetch("/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:t.bladeProvider,name:t.name||t.modelId,model:t.modelId,baseUrl:t.baseUrl||void 0,apiKey:t.apiKey||void 0})})).ok)throw new Error("Failed to save model");await x()}catch(l){console.error("Failed to save model:",l)}},a=async t=>{try{if(!(await fetch(`/models/${t}`,{method:"DELETE"})).ok)throw new Error("Failed to delete model");await x()}catch(l){console.error("Failed to delete model:",l)}},$=async(t,l)=>{try{if(!(await fetch(`/models/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)})).ok)throw new Error("Failed to update model");await x()}catch(m){console.error("Failed to update model:",m)}},H=t=>{N(y===t?null:t)};return e.jsxs(e.Fragment,{children:[e.jsx(U,{open:p,onOpenChange:c,children:e.jsxs(z,{className:"sm:max-w-[800px] h-[600px] p-0 overflow-hidden gap-0 bg-white dark:bg-[#09090b] border border-[#E5E7EB] dark:border-zinc-800 rounded-xl flex flex-col","aria-describedby":void 0,hideCloseButton:!0,children:[e.jsx(K,{className:"sr-only",children:"Settings"}),e.jsxs("div",{className:"flex h-full",children:[e.jsx("div",{className:"w-[200px] h-full bg-[#F3F4F6] dark:bg-[#18181b] p-6 flex flex-col gap-2",children:h.map(t=>e.jsx("button",{onClick:()=>j(t.value),className:b("w-full text-left px-3 py-2 rounded-md text-sm font-mono transition-colors",r===t.value?"bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5] font-medium":"text-[#6B7280] hover:text-[#111827] hover:bg-[#E5E7EB]/60 dark:text-[#a1a1aa] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a]/50"),children:t.label},t.value))}),e.jsxs("div",{className:"flex-1 p-8 flex flex-col gap-6 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono",children:r==="general"?"Settings":(O=h.find(t=>t.value===r))==null?void 0:O.label}),e.jsx("button",{onClick:c,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(P,{className:"h-4 w-4"})})]}),r==="models"&&e.jsxs("div",{className:"flex flex-col gap-6 flex-1 min-h-0 overflow-hidden",children:[e.jsx("p",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono shrink-0",children:"Configure API keys and model settings for different providers."}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:e.jsxs("div",{className:"flex flex-col gap-2 pr-2",children:[Object.entries(C).map(([t,l])=>{const m=Z[t]||{bg:"#71717a",label:"?"},T=l.some(f=>f.apiKey),R=y===t;return e.jsxs("div",{className:"w-full bg-[#F3F4F6] dark:bg-[#18181b] rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>H(t),className:"w-full p-4 flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#1f1f23] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded flex items-center justify-center text-white text-xs font-bold",style:{backgroundColor:m.bg},children:m.label}),e.jsxs("div",{className:"flex flex-col gap-0.5 text-left",children:[e.jsx("span",{className:"text-sm font-semibold text-[#111827] dark:text-[#E5E5E5] font-mono capitalize",children:t.replace(/-/g," ")}),e.jsxs("span",{className:"text-xs text-[#9CA3AF] dark:text-[#71717a] font-mono",children:[l.length," model",l.length>1?"s":""]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:b("text-xs font-mono",T?"text-[#16A34A]":"text-[#9CA3AF] dark:text-[#71717a]"),children:T?"● Connected":"○ Not Connected"}),e.jsx(M,{className:b("h-4 w-4 text-[#9CA3AF] dark:text-[#71717a] transition-transform",R&&"rotate-180")})]})]}),R&&e.jsx("div",{className:"border-t border-[#E5E7EB] dark:border-zinc-800",children:l.map(f=>e.jsxs("div",{className:"px-4 py-3 flex items-center justify-between hover:bg-[#E5E7EB] dark:hover:bg-[#1f1f23] group",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm text-[#111827] dark:text-[#E5E5E5] font-mono truncate",children:f.model}),e.jsx("span",{className:"text-xs text-[#9CA3AF] dark:text-[#71717a] font-mono truncate",children:f.baseUrl||"Default URL"})]}),e.jsxs("div",{className:"flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:()=>v(f),className:"p-1.5 text-[#9CA3AF] hover:text-[#111827] hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-[#E5E5E5] dark:hover:bg-[#27272a] rounded transition-colors",children:e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>a(f.id),className:"p-1.5 text-[#9CA3AF] hover:text-red-500 hover:bg-[#E5E7EB] dark:text-[#71717a] dark:hover:text-red-400 dark:hover:bg-[#27272a] rounded transition-colors",children:e.jsx(X,{className:"h-3.5 w-3.5"})})]})]},f.id))})]},t)}),Object.keys(C).length===0&&e.jsx("div",{className:"text-center py-8 text-[#9CA3AF] dark:text-[#71717a] text-sm font-mono",children:"No models configured yet"})]})}),e.jsx("button",{onClick:()=>i(!0),className:"w-full py-3 rounded-md text-[#6B7280] dark:text-[#a1a1aa] text-[13px] font-mono hover:bg-[#F3F4F6] dark:bg-[#18181b] transition-colors shrink-0",children:"+ Add New Model"})]}),r==="general"&&e.jsxs("div",{className:"flex flex-col gap-6 overflow-y-auto pr-2",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"General"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Response Language"}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:"AI will respond in this language"})]}),e.jsxs("select",{value:s.language,onChange:t=>s.updateSettings({language:t.target.value}),className:"h-8 bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono rounded-md px-3 border border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsx("option",{value:"en-US",children:"English (US)"}),e.jsx("option",{value:"zh-CN",children:"简体中文"}),e.jsx("option",{value:"zh-TW",children:"繁體中文"}),e.jsx("option",{value:"ja-JP",children:"日本語"}),e.jsx("option",{value:"ko-KR",children:"한국어"}),e.jsx("option",{value:"es-ES",children:"Español"}),e.jsx("option",{value:"fr-FR",children:"Français"}),e.jsx("option",{value:"de-DE",children:"Deutsch"}),e.jsx("option",{value:"pt-BR",children:"Português (BR)"}),e.jsx("option",{value:"ru-RU",children:"Русский"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Auto-save sessions"}),e.jsx(g,{enabled:s.autoSaveSessions,onChange:t=>s.updateSettings({autoSaveSessions:t})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"Appearance"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Theme Preference"}),e.jsx("div",{className:"flex items-center gap-2 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md p-1",children:["dark","light","system"].map(t=>e.jsx("button",{onClick:()=>s.updateSettings({uiTheme:t}),className:b("px-3 py-1 rounded text-[12px] font-mono transition-colors",s.uiTheme===t?"bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5]":"text-[#9CA3AF] dark:text-[#71717a] hover:text-[#111827] dark:hover:text-[#E5E5E5]"),children:t==="dark"?"Dark":t==="light"?"Light":"System"},t))})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Compact sidebar"}),e.jsx(g,{enabled:!u,onChange:t=>E(!t)})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Code theme"}),e.jsx("span",{className:"text-[11px] text-[#9CA3AF] dark:text-[#71717a] font-mono",children:"Syntax highlighting colors"})]}),e.jsxs("select",{value:s.theme,onChange:t=>s.updateSettings({theme:t.target.value}),className:"h-8 bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono rounded-md px-3 border border-[#E5E7EB] dark:border-[#27272a]",children:[e.jsx("option",{value:"dracula",children:"Dracula"}),e.jsx("option",{value:"monokai",children:"Monokai"}),e.jsx("option",{value:"nord",children:"Nord"}),e.jsx("option",{value:"tokyo-night",children:"Tokyo Night"}),e.jsx("option",{value:"one-dark",children:"One Dark"}),e.jsx("option",{value:"catppuccin",children:"Catppuccin"}),e.jsx("option",{value:"gruvbox",children:"Gruvbox"}),e.jsx("option",{value:"github",children:"GitHub"}),e.jsx("option",{value:"solarized-light",children:"Solarized Light"}),e.jsx("option",{value:"solarized-dark",children:"Solarized Dark"}),e.jsx("option",{value:"ayu-dark",children:"Ayu Dark"}),e.jsx("option",{value:"rose-pine",children:"Rose Pine"}),e.jsx("option",{value:"kanagawa",children:"Kanagawa"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"Notifications"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Build finished"}),e.jsx(g,{enabled:s.notifyBuild,onChange:t=>s.updateSettings({notifyBuild:t})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Errors only"}),e.jsx(g,{enabled:s.notifyErrors,onChange:t=>s.updateSettings({notifyErrors:t})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"System sounds"}),e.jsx(g,{enabled:s.notifySounds,onChange:t=>s.updateSettings({notifySounds:t})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-[14px] text-[#111827] dark:text-[#E5E5E5] font-mono font-semibold",children:"Privacy"}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Telemetry"}),e.jsx(g,{enabled:s.privacyTelemetry,onChange:t=>s.updateSettings({privacyTelemetry:t})})]}),e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-[13px] text-[#6B7280] dark:text-[#a1a1aa] font-mono",children:"Crash reports"}),e.jsx(g,{enabled:s.privacyCrash,onChange:t=>s.updateSettings({privacyCrash:t})})]})]})]}),r==="shortcuts"&&e.jsxs("div",{className:"flex flex-col gap-4 flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsx("input",{value:k,onChange:t=>S(t.target.value),placeholder:"Search actions...",className:"flex-1 h-9 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono"}),e.jsxs("select",{value:F,onChange:t=>A(t.target.value),className:"h-9 bg-[#F3F4F6] dark:bg-[#18181b] border border-[#E5E7EB] dark:border-[#27272a] rounded-md px-3 text-[12px] text-[#111827] dark:text-[#E5E5E5] font-mono",children:[e.jsx("option",{value:"all",children:"All scopes"}),e.jsx("option",{value:"global",children:"Global"}),e.jsx("option",{value:"chat",children:"Chat"}),e.jsx("option",{value:"layout",children:"Layout"}),e.jsx("option",{value:"history",children:"History"})]}),e.jsx("button",{onClick:()=>{S(""),A("all")},className:"h-9 px-3 rounded-md bg-[#E5E7EB] dark:bg-[#27272a] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono font-semibold",children:"Reset"})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto border border-[#E5E7EB] dark:border-[#27272a] rounded-lg bg-[#E5E7EB] dark:bg-[#111827]",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_180px_120px] gap-2 px-3 py-2 bg-white dark:bg-[#0C0C0C] text-[12px] text-[#6B7280] dark:text-[#94a3b8] font-mono font-semibold",children:[e.jsx("span",{children:"Action"}),e.jsx("span",{children:"Shortcut"}),e.jsx("span",{children:"Scope"})]}),D.map((t,l)=>e.jsxs("div",{className:b("grid grid-cols-[1fr_180px_120px] gap-2 px-3 py-2 text-[13px] font-mono",l%2===0?"bg-[#E5E7EB] dark:bg-[#111827]":"bg-white dark:bg-[#0C0C0C]"),children:[e.jsx("span",{className:"text-[#111827] dark:text-[#E5E5E5]",children:t.action}),e.jsx("div",{className:"flex items-center gap-1",children:t.combo.map(m=>e.jsx("span",{className:"px-2 py-0.5 rounded bg-[#F3F4F6] dark:bg-[#18181b] text-[#111827] dark:text-[#E5E5E5] text-[12px] font-mono font-semibold",children:m},m))}),e.jsx("span",{className:"text-[#6B7280] dark:text-[#94a3b8] text-[12px]",children:t.scope})]},`${t.action}-${t.scope}`)),D.length===0&&e.jsx("div",{className:"px-3 py-6 text-center text-[12px] text-[#6B7280] dark:text-[#94a3b8] font-mono",children:"No shortcuts found."})]})]})]})]})]})}),e.jsx(Y,{open:o,onOpenChange:i,onSave:I}),e.jsx(q,{open:!!w,onOpenChange:t=>!t&&v(null),model:w,onSave:$})]})}function g({enabled:p,onChange:c}){return e.jsx("button",{onClick:()=>c(!p),className:b("w-10 h-5 rounded-full px-0.5 flex items-center transition-colors",p?"bg-[#22C55E]":"bg-[#E5E7EB] dark:bg-[#27272a]"),children:e.jsx("span",{className:b("h-4 w-4 rounded-full transition-transform",p?"translate-x-5 bg-white":"translate-x-0 bg-white dark:bg-[#a1a1aa]")})})}export{re as SettingsModal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{g as n}from"./index-BJTSF3fc.js";const c=s=>s==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches:s==="dark",i=s=>{const t=document.documentElement;if(t.classList.remove("light","dark"),s==="system"){const r=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";t.classList.add(r)}else t.classList.add(s)},o={language:"zh-CN",theme:"dracula",uiTheme:"system",autoSaveSessions:!0,notifyBuild:!0,notifyErrors:!1,notifySounds:!1,privacyTelemetry:!1,privacyCrash:!0},l=n((s,t)=>({...o,isLoading:!1,error:null,loadSettings:async()=>{s({isLoading:!0,error:null});try{const r=await fetch("/configs");if(!r.ok)throw new Error("Failed to load settings");const e=await r.json(),a=e.uiTheme??o.uiTheme;s({language:e.language??o.language,theme:e.theme??o.theme,uiTheme:a,autoSaveSessions:e.autoSaveSessions??o.autoSaveSessions,notifyBuild:e.notifyBuild??o.notifyBuild,notifyErrors:e.notifyErrors??o.notifyErrors,notifySounds:e.notifySounds??o.notifySounds,privacyTelemetry:e.privacyTelemetry??o.privacyTelemetry,privacyCrash:e.privacyCrash??o.privacyCrash,isLoading:!1}),i(a)}catch(r){s({error:r.message,isLoading:!1})}},updateSettings:async r=>{const e=t();s({...r,error:null}),r.uiTheme&&i(r.uiTheme);try{if(!(await fetch("/configs",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates:r,options:{scope:"global"}})})).ok)throw new Error("Failed to save settings")}catch(a){s({language:e.language,theme:e.theme,uiTheme:e.uiTheme,autoSaveSessions:e.autoSaveSessions,notifyBuild:e.notifyBuild,notifyErrors:e.notifyErrors,notifySounds:e.notifySounds,privacyTelemetry:e.privacyTelemetry,privacyCrash:e.privacyCrash,error:a.message}),r.uiTheme&&i(e.uiTheme)}}}));i(o.uiTheme);const u=()=>l(s=>c(s.uiTheme));export{u as a,l as u};
|