blade-code 0.7.3 → 0.7.5

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.
Files changed (33) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-29pqj0tb.js → chunk-0rw4tdqy.js} +1 -1
  3. package/dist/{chunk-gb0x14v5.js → chunk-7pcm8vy5.js} +37 -37
  4. package/dist/chunk-8ea9h3mb.js +151 -0
  5. package/dist/{chunk-wp67n9q7.js → chunk-8w1hd9ct.js} +153 -153
  6. package/dist/{chunk-y50fy1gq.js → chunk-a8znntss.js} +1 -1
  7. package/dist/{chunk-wev2rke6.js → chunk-apb1p5q4.js} +1 -1
  8. package/dist/{chunk-5n7h04jg.js → chunk-ay3rhhx8.js} +1 -1
  9. package/dist/{chunk-98fvxsvc.js → chunk-c3yn8ds8.js} +2 -2
  10. package/dist/{chunk-d0fata6n.js → chunk-g1eb7f4q.js} +1 -1
  11. package/dist/{chunk-hs4j2fcr.js → chunk-jfykets9.js} +1 -1
  12. package/dist/{chunk-06awrjgg.js → chunk-jsn8476q.js} +1 -1
  13. package/dist/chunk-kssr4fbg.js +1 -0
  14. package/dist/{chunk-vw3f4mbt.js → chunk-n969rv4v.js} +1 -1
  15. package/dist/{chunk-e9kfbbpm.js → chunk-vhc1yr3v.js} +1 -1
  16. package/dist/{chunk-87gff8b7.js → chunk-yaj4nmmp.js} +1 -1
  17. package/dist/chunk-yz2jztga.js +7 -0
  18. package/dist/chunk-zye2s6f0.js +2 -0
  19. package/dist/web/assets/{FilePreview-IDRQBiWa.js → FilePreview-evNzCuVx.js} +1 -1
  20. package/dist/web/assets/{MarkdownRenderer-BgDKGD2u.js → MarkdownRenderer-BQoiQTDd.js} +1 -1
  21. package/dist/web/assets/{McpModal-CJ2l7j-5.js → McpModal-BT9OivhK.js} +1 -1
  22. package/dist/web/assets/{SettingsModal-BWpbIioU.js → SettingsModal-CDRcorCS.js} +1 -1
  23. package/dist/web/assets/{SettingsStore-BZjkLZcL.js → SettingsStore-CfDjhOkS.js} +1 -1
  24. package/dist/web/assets/{SkillsModal-CRuRJrN-.js → SkillsModal-DCPaqoOe.js} +1 -1
  25. package/dist/web/assets/{TerminalPanel-BnZPkS19.js → TerminalPanel-Cs16_6ew.js} +1 -1
  26. package/dist/web/assets/{dialog-DYRMhlp_.js → dialog-C8VDk-ma.js} +1 -1
  27. package/dist/web/assets/{index-D4CAglTd.js → index-9t-WxRrl.js} +8 -8
  28. package/dist/web/index.html +1 -1
  29. package/package.json +1 -1
  30. package/dist/chunk-avebc3bj.js +0 -2
  31. package/dist/chunk-eady1q1w.js +0 -150
  32. package/dist/chunk-k63hr1eg.js +0 -7
  33. package/dist/chunk-txjvy8qp.js +0 -1
@@ -1,7 +0,0 @@
1
- import{B as W,H as L,K as P,L as T,N as R,Q as U,T as M,V as h,W as j}from"./chunk-wp67n9q7.js";import"./chunk-e21htmg4.js";import{_ as y}from"./chunk-y50fy1gq.js";import"./chunk-rtn0rb16.js";import{ra as A}from"./chunk-5smacbk0.js";import"./chunk-rkhhzc4r.js";import"./chunk-06awrjgg.js";import{Va as f}from"./chunk-gb0x14v5.js";import"./chunk-cyxb6fxe.js";import"./chunk-jf48kahn.js";import{tb as B}from"./chunk-63dzf6hr.js";import"./chunk-98jpdmgc.js";import{Lb as _}from"./chunk-w1zb8zac.js";import"./chunk-kfg3vx5z.js";import{Readable as v,Writable as c}from"node:stream";import*as w from"@agentclientprotocol/sdk";import{PROTOCOL_VERSION as u}from"@agentclientprotocol/sdk";import{nanoid as C}from"nanoid";import{nanoid as K}from"nanoid";var Y=_("Agent");function N(z){return Object.fromEntries(z.map((G)=>[G.name,G.value]))}function b(z){if("command"in z)return{type:"stdio",command:z.command,args:z.args,env:N(z.env)};return{type:z.type,url:z.url,headers:N(z.headers)}}function k(z){return Object.fromEntries(z.map((G)=>[G.name,b(G)]))}function S(z){if(typeof z==="string")return z?[{type:"text",text:z}]:[];return z.flatMap((G)=>{if(G.type==="text")return G.text?[{type:"text",text:G.text}]:[];let H=G.image_url.url,J=/^data:([^;,]+);base64,(.+)$/s.exec(H);if(!J)return[{type:"text",text:"[Image]"}];return[{type:"image",mimeType:J[1]??"image/png",data:J[2]??""}]})}class D{id;cwd;connection;clientCapabilities;options;agent=null;runtime=null;pendingPrompt=null;messages;mode="default";sessionApprovals=new Set;constructor(z,G,H,J,Q={}){this.id=z;this.cwd=G;this.connection=H;this.clientCapabilities=J;this.options=Q;this.messages=[...Q.initialMessages??[]]}async initialize(){Y.debug(`[AcpSession ${this.id}] Initializing...`),W.initializeSession(this.connection,this.id,this.clientCapabilities,this.cwd),Y.debug(`[AcpSession ${this.id}] ACP service context initialized`);let z=this.options.mcpServers?k(this.options.mcpServers):void 0;this.runtime=await L.create({sessionId:this.id,workspaceRoot:this.cwd,...z?{mcpServers:z}:{}}),this.agent=await R.createWithRuntime(this.runtime,{sessionId:this.id}),Y.debug(`[AcpSession ${this.id}] Agent created successfully`)}async replayHistory(){for(let z of this.messages){let G=z.role==="user"?"user_message_chunk":z.role==="assistant"?"agent_message_chunk":void 0;if(!G)continue;for(let H of S(z.content))await this.connection.sessionUpdate({sessionId:this.id,update:{sessionUpdate:G,content:H}})}}sendAvailableCommandsDelayed(){Y.debug(`[AcpSession ${this.id}] Scheduling available commands update (500ms delay)`),setTimeout(()=>{this.sendAvailableCommands()},500)}async handleSlashCommand(z,G){try{Y.debug(`[AcpSession ${this.id}] Executing slash command: ${z}`);let H={cwd:this.cwd,signal:G,acp:{sendMessage:(X)=>{this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:X}})},sendToolStart:(X,Z,E)=>{let $=`tool_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,F=this.mapToolKind(E);this.sendUpdate({sessionUpdate:"tool_call",toolCallId:$,status:"in_progress",title:`${X}`,content:[{type:"content",content:{type:"text",text:JSON.stringify(Z,null,2)}}],kind:F})},sendToolResult:(X,Z)=>{if(Z.summary)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:Z.summary}})}}},J=await h(z,H),Q=J.content||J.message;if(Q)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:Q}});if(J.error)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`[FAIL] ${J.error}`}});return{stopReason:J.success?"end_turn":"cancelled"}}catch(H){return Y.error(`[AcpSession ${this.id}] Slash command error:`,H),this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`[FAIL] 命令执行失败: ${H instanceof Error?H.message:"未知错误"}`}}),{stopReason:"cancelled"}}}async sendAvailableCommands(){try{let z=j(),G=["model","permissions","theme","config","exit","ide"],J=z.filter((Q)=>!G.includes(Q.name)).map((Q)=>{let X;if(Q.usage){let Z=Q.usage.replace(/^\/\w+\s*/,"").trim();if(Z)X=Z}if(Q.aliases?.length){let Z=`Aliases: ${Q.aliases.join(", ")}`;X=X?`${X} | ${Z}`:Z}return{name:Q.name,description:Q.description,input:X?{hint:X}:void 0}});Y.info(`[AcpSession ${this.id}] Sending available commands: ${JSON.stringify(J.map((Q)=>Q.name))}`),this.sendUpdate({sessionUpdate:"available_commands_update",availableCommands:J}),Y.info(`[AcpSession ${this.id}] Sent ${J.length} available commands`)}catch(z){Y.error(`[AcpSession ${this.id}] Failed to send available commands:`,z)}}async prompt(z){if(W.setCurrentSession(this.id),!this.agent||!this.runtime)throw Error("Session not initialized");let G=this.resolvePrompt(z.prompt);if(this.pendingPrompt){let J=await this.runtime.enqueueSteering(G,{allowBeforeTurn:!0});if(!J.accepted)throw Error(J.reason==="queue_full"?"Active turn steering queue is full":"Active turn is no longer steerable");return Y.debug(`[AcpSession ${this.id}] Queued steering for active turn (${J.queued})`),{stopReason:"end_turn"}}let H=new AbortController;this.pendingPrompt=H;try{if(Y.debug(`[AcpSession ${this.id}] Received prompt: ${G.slice(0,100)}...`),M(G))return await this.handleSlashCommand(G,H.signal);let J={sessionId:this.id,userId:"acp-user",workspaceRoot:this.cwd,messages:[...this.messages],signal:H.signal,permissionMode:this.mapModeToPermissionMode(),confirmationHandler:{requestConfirmation:async(Q)=>{return this.requestPermission(Q)}}};if(await f(this.agent.chatStream(G,J),async(Q)=>{switch(Q.kind){case"content_delta":this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:Q.delta}});break;case"thinking_delta":this.sendUpdate({sessionUpdate:"agent_thought_chunk",content:{type:"text",text:Q.delta}});break;case"tool_start":{let X=Q.toolCall,Z="function"in X?X.function.name:X.type,E=this.mapToolKind(Q.toolKind);this.sendUpdate({sessionUpdate:"tool_call",toolCallId:X.id,status:"in_progress",title:`Executing ${Z}`,content:[],kind:E});break}case"tool_result":{let{toolCall:X,result:Z}=Q,E=[],$=Z.metadata;if($?.kind==="edit"&&typeof $.file_path==="string"&&typeof $.oldContent==="string"&&(typeof $.newContent==="string"||$.newContent===void 0))E.push({type:"diff",path:$.file_path,oldText:$.oldContent,newText:$.newContent??null});else{let V="function"in X?X.function.name:X.type,x=T(P(V,Z));E.push({type:"content",content:{type:"text",text:x}})}let F=Z.success?"completed":"failed";this.sendUpdate({sessionUpdate:"tool_call_update",toolCallId:X.id,status:F,content:E});break}case"task_update":this.sendPlanUpdate(Q.tasks);break;case"steering_applied":if(Q.recovered>0)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`[Recovered ${Q.recovered} queued instruction${Q.recovered===1?"":"s"} after restart]
2
- `}});break;default:break}}),this.messages=[...J.messages],H.signal.aborted)return{stopReason:"cancelled"};return{stopReason:"end_turn"}}catch(J){if(H.signal.aborted||J instanceof Error&&J.name==="AbortError")return{stopReason:"cancelled"};throw Y.error(`[AcpSession ${this.id}] Prompt error:`,J),J}finally{if(this.pendingPrompt===H)this.pendingPrompt=null}}cancel(){if(Y.info(`[AcpSession ${this.id}] Cancel requested`),this.pendingPrompt)this.pendingPrompt.abort(),this.pendingPrompt=null,Y.info(`[AcpSession ${this.id}] Cancelled successfully`);else Y.warn(`[AcpSession ${this.id}] No pending prompt to cancel`)}async setMode(z){let G=["default","auto-edit","yolo","plan"];this.mode=G.includes(z)?z:"default",Y.info(`[AcpSession ${this.id}] Mode set to: ${this.mode}`),this.sendUpdate({sessionUpdate:"current_mode_update",currentModeId:this.mode})}mapModeToPermissionMode(){switch(this.mode){case"yolo":return"yolo";case"auto-edit":return"autoEdit";case"plan":return"plan";case"default":default:return"default"}}shouldAutoApprove(z){switch(this.mode){case"yolo":return!0;case"auto-edit":return z==="readonly"||z==="write";case"plan":return z==="readonly";case"default":default:return!1}}async setModel(z){if(Y.info(`[AcpSession ${this.id}] Model set to: ${z}`),this.pendingPrompt)throw Error("Cannot switch models while a prompt is active");if(!this.agent)throw Error("Session not initialized");await this.agent.switchModel(z)}async destroy(){if(this.cancel(),this.agent)await this.agent.destroy(),this.agent=null;if(this.runtime)await this.runtime.dispose(),this.runtime=null;W.destroySession(this.id),Y.debug(`[AcpSession ${this.id}] Destroyed`)}resolvePrompt(z){let G=[];for(let H of z)if(H.type==="text")G.push(H.text);else if(H.type==="image")G.push(`[Image: ${H.mimeType}]`);else if(H.type==="resource"){let J=H.resource;if("text"in J)G.push(`<file path="${J.uri}">
3
- ${J.text}
4
- </file>`)}else if(H.type==="resource_link")G.push(`[Resource: ${H.uri}]`);return G.join(`
5
- `)}sendUpdate(z){let G={sessionId:this.id,update:z};this.connection.sessionUpdate(G).catch((H)=>{Y.warn(`[AcpSession ${this.id}] Failed to send update:`,H)})}sendPlanUpdate(z){let G=z.map((H)=>({content:H.subject,priority:H.priority,status:H.status}));Y.debug(`[AcpSession ${this.id}] Sending plan update with ${G.length} entries`),this.sendUpdate({sessionUpdate:"plan",entries:G})}async requestPermission(z){let G=z.kind?.toLowerCase()||"execute";if(this.shouldAutoApprove(G))return Y.debug(`[AcpSession ${this.id}] Auto-approving ${G} in mode: ${this.mode}`),{approved:!0};if(this.mode==="plan"&&(G==="write"||G==="execute"))return Y.debug(`[AcpSession ${this.id}] Rejecting ${G} in plan mode`),{approved:!1,reason:"Write and execute operations are not allowed in Plan mode"};let H=`${G}:${z.title||"unknown"}`;if(this.sessionApprovals.has(H))return Y.debug(`[AcpSession ${this.id}] Using cached approval for: ${H}`),{approved:!0};try{let J=K(),Q=[];if(z.message)Q.push({type:"content",content:{type:"text",text:z.message}});if(z.risks&&z.risks.length>0)Q.push({type:"content",content:{type:"text",text:`Risks:
6
- - ${z.risks.join(`
7
- - `)}`}});let X=this.mapToolKind(G),Z={sessionId:this.id,options:[{optionId:"allow_once",name:"Allow once",kind:"allow_once"},{optionId:"allow_always",name:"Always allow",kind:"allow_always"},{optionId:"reject_once",name:"Deny once",kind:"reject_once"},{optionId:"reject_always",name:"Always deny",kind:"reject_always"}],toolCall:{toolCallId:J,status:"pending",title:z.title||"Permission Required",content:Q,kind:X}},$=(await this.connection.requestPermission(Z)).outcome;if($.outcome==="cancelled")return{approved:!1,reason:"User cancelled the permission request"};let F=$.optionId,V=F==="allow_once"||F==="allow_always";if(F==="allow_always")this.sessionApprovals.add(H),Y.debug(`[AcpSession ${this.id}] Cached approval for: ${H}`);return{approved:V,reason:V?void 0:"User denied the operation"}}catch(J){return Y.warn(`[AcpSession ${this.id}] Permission request failed:`,J),{approved:!1,reason:"Permission request failed"}}}mapToolKind(z){return{readonly:"read",write:"edit",execute:"execute",read:"read",edit:"edit",delete:"delete",move:"move",search:"search",think:"think",fetch:"fetch"}[z||""]||"other"}}var q=_("Agent");class O{connection;sessions=new Map;clientCapabilities;constructor(z){this.connection=z}async initialize(z){return q.info("[BladeAgent] Initializing ACP connection"),q.debug(`[BladeAgent] Client capabilities: ${JSON.stringify(z.clientCapabilities)}`),this.clientCapabilities=z.clientCapabilities,{protocolVersion:u,agentCapabilities:{loadSession:!0,promptCapabilities:{image:!0,audio:!1,embeddedContext:!0},mcpCapabilities:{http:!0,sse:!0}}}}async authenticate(z){return}async newSession(z){let G=C();q.info(`[BladeAgent] Creating new session: ${G}`),q.debug(`[BladeAgent] Session cwd: ${z.cwd||B()}`);let H=new D(G,z.cwd||B(),this.connection,this.clientCapabilities,{mcpServers:z.mcpServers});try{await H.initialize()}catch(J){throw await H.destroy().catch(()=>{return}),J}return this.sessions.set(G,H),q.info(`[BladeAgent] Session ${G} created, scheduling available commands update`),H.sendAvailableCommandsDelayed(),{sessionId:G,...this.buildSessionState()}}async loadSession(z){q.info(`[BladeAgent] Loading session: ${z.sessionId}`);let G=await U.loadSession(z.sessionId,z.cwd),H=this.sessions.get(z.sessionId);if(H)await H.destroy(),this.sessions.delete(z.sessionId),G=await U.loadSession(z.sessionId,z.cwd);let J=new D(z.sessionId,z.cwd,this.connection,this.clientCapabilities,{initialMessages:G,mcpServers:z.mcpServers});try{await J.initialize(),await J.replayHistory()}catch(Q){throw await J.destroy().catch(()=>{return}),Q}return this.sessions.set(z.sessionId,J),J.sendAvailableCommandsDelayed(),this.buildSessionState()}buildSessionState(){let z=A(),G=z?.models||[],H=z?.currentModelId||G[0]?.id,J=G.map((X)=>({modelId:X.id,name:X.name||X.id,description:X.provider?`Provider: ${X.provider}`:void 0}));return{modes:{availableModes:[{id:"default",name:"Default",description:"Ask for confirmation before all file edits and commands"},{id:"auto-edit",name:"Auto Edit",description:"Auto-approve file edits, ask for shell commands"},{id:"yolo",name:"Full Auto",description:"Auto-approve everything without confirmation"},{id:"plan",name:"Plan Only",description:"Read-only mode, no file changes or commands"}],currentModeId:"default"},models:J.length>0?{availableModels:J,currentModelId:H}:void 0}}async prompt(z){let G=this.sessions.get(z.sessionId);if(!G)throw Error(`Session not found: ${z.sessionId}`);return G.prompt(z)}async cancel(z){q.info(`[BladeAgent] Cancel notification received for session: ${z.sessionId}`);let G=this.sessions.get(z.sessionId);if(G)q.info("[BladeAgent] Found session, calling session.cancel()"),G.cancel();else q.warn(`[BladeAgent] Session not found for cancel: ${z.sessionId}`)}async setSessionMode(z){q.info(`[BladeAgent] Setting session mode: ${z.modeId}`);let G=this.sessions.get(z.sessionId);if(G)await G.setMode(z.modeId);return{}}async unstable_setSessionModel(z){q.info(`[BladeAgent] Setting session model: ${z.modelId}`);let G=this.sessions.get(z.sessionId);if(!G)throw Error(`Session not found: ${z.sessionId}`);return await G.setModel(z.modelId),{}}async destroy(){for(let z of this.sessions.values())await z.destroy();this.sessions.clear(),await y.getInstance().disconnectAll()}}async function qz(){let z=c.toWeb(process.stdout),G=v.toWeb(process.stdin),H=w.ndJsonStream(z,G);await new w.AgentSideConnection((Q)=>new O(Q),H).closed}export{qz as runAcpIntegration};
@@ -1 +0,0 @@
1
- import{t as a,u as b}from"./chunk-vw3f4mbt.js";import"./chunk-06awrjgg.js";import"./chunk-kfg3vx5z.js";export{a as globalOptions,b as cliConfig};