@yuandc/aica 0.1.90 → 0.1.91
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{workBuddyCredits as C}from"../../../core/workbuddy-credits/worker.js";import c from"node:fs";import{enterWorkBuddySession as B}from"./session-lock.js";import{forkWorkBuddySession as A}from"./fork.js";import{runAbortableRequest as E}from"../../client/abortable-request.js";import{defaultAcpRuntimePool as h}from"../../client/acp-runtime-pool.js";import{BoundedItemBuffer as m}from"../../client/bounded-buffer.js";import{contextUsageFromAcpSessionUpdate as W}from"../../client/context-usage.js";import{providerEventFromAcpSessionUpdate as f,providerStatusFromAcpSessionUpdate as M}from"../standard-acp-events.js";import{resolveWorkBuddyLaunch as R,workBuddyTimeout as U}from"./launch.js";import{applyWorkBuddyConfig as _,record as r,rememberWorkBuddyCapabilities as w}from"./config.js";import{handleWorkBuddyRequest as q}from"./interactions.js";import{WorkBuddyEventRouter as y}from"./events.js";import{WorkBuddySupplements as x,workBuddyPromptContent as D}from"./supplements.js";import{assertWorkBuddyPromptCompleted as O,workBuddyError as g}from"./errors.js";import{WorkBuddyTurnCredits as v,workBuddyContextUsage as P}from"./usage.js";import{workBuddyCommands as S}from"./commands.js";const l=new WeakMap,T={sessionResume:!0,liveSupplement:!0,imageInput:!0,fileAttachment:!0,filesystem:!0,terminal:!0,permissionRequest:!0,configOptions:!0,usage:!0,contextUsage:!0,contextCompaction:!0,plan:!0,diff:!0};class is{id="workbuddy";name="腾讯 Code Buddy";capabilities=T;async createSession(s){return new z(s.cwd,s.providerSessionId??null,s.timeoutMs)}async forkSession(s){return A(s)}}class z{cwd;providerSessionId;timeoutMs;lease=null;input=null;acceptingOutput=!1;busy=!1;content="";usage=null;response={};commands=new Set;commandCatalog=null;credits=new v;technicalError=null;router=new y;supplements=null;updates=new m(16);statuses=new m(64);firstEventAtMs=null;lastEventAtMs=null;constructor(s,t,i=U()){this.cwd=s,this.providerSessionId=t,this.timeoutMs=i}async sendPrompt(s){return this.run(s,!1)}async compactContext(s){if(!this.providerSessionId)throw new Error("WorkBuddy 当前没有可压缩的会话。");const t=await this.run({...s,cwd:s.cwd,prompt:"/compact",requireSessionResume:!0},!0);return{providerSessionId:t.providerSessionId,contextUsage:t.contextUsage??null,maintenance:{action:"compact",provider:"workbuddy",protocol:"session/prompt",stopReason:r(t.promptResponse).stopReason},durationMs:t.durationMs}}async run(s,t){if(this.busy)throw new Error("WorkBuddy 会话正在执行另一轮任务。");if(c.realpathSync(s.cwd)!==c.realpathSync(this.cwd))throw new Error("WorkBuddy 会话不能切换工作目录。");if(s.requireSessionResume&&!this.providerSessionId)throw new Error("WorkBuddy 历史会话缺少 Session ID,禁止新建会话。");if(/^\s*\/(fork|branch|fork-bg)(?:\s|$)/i.test(s.prompt))throw new Error("请使用会话菜单中的“从当前会话分叉”,以便 ACA 正确保存新会话。");const i=B(this.providerSessionId);this.busy=!0,this.input=s,this.content="",this.usage=null,this.response={},this.commands.clear(),this.commandCatalog=null,this.credits=new v,this.technicalError=null,this.router=new y,this.updates.clear(),this.statuses.clear(),this.firstEventAtMs=this.lastEventAtMs=null;const o=Date.now();let d;try{return await E({signal:s.signal,cancelledMessage:"WorkBuddy 任务已取消",onAbort:()=>this.cancelAndDispose(),startRequest:async()=>{this.status("initializing","WorkBuddy ACP 启动中");const n=R(s.canExecuteTools!==!1);if(this.providerSessionId&&await h.retireSessionRuntimes({providerId:"workbuddy",cwd:this.cwd,providerSessionId:this.providerSessionId,keepRuntimeIdentity:n.runtimeIdentity}),s.signal?.aborted)throw new Error("WorkBuddy 任务已取消");const e=await h.acquire({providerId:"workbuddy",cwd:this.cwd,providerSessionId:this.providerSessionId,...n,onSessionUpdate:a=>this.handleUpdate(a),onClientRequest:(a,k,b)=>this.handleRequest(a,k,b.id)});if(this.lease=e,s.signal?.aborted)throw await e.dispose(),new Error("WorkBuddy 任务已取消");await this.initialize(e),await this.establishSession(e),i.bind(this.providerSessionId);const p=r(r(l.get(e.client)?.agentCapabilities).promptCapabilities);if(s.promptBlocks?.some(a=>a.type==="image")&&p.image!==!0)throw new Error("当前 CodeBuddy ACP 版本未声明图片输入支持。");if(t||(this.response=await _(e.client,this.providerSessionId,this.response,s)),e.setSessionResponse(this.response),t&&!this.commands.has("compact"))throw new Error("当前 WorkBuddy 会话未提供 /compact 命令,无法压缩上下文。");this.acceptingOutput=!0,this.publishCommands(),this.status("thinking",t?"正在压缩上下文":"思考中"),d=C.beginUsage();const u=await e.client.prompt({sessionId:this.providerSessionId,prompt:D(s.prompt,s.promptBlocks)},s.timeoutMs??this.timeoutMs);if(s.signal?.aborted)throw new Error("WorkBuddy 任务已取消");if(this.credits.identifyResponse(u),this.technicalError)throw g(this.technicalError);return O(u),t&&this.usage&&(this.usage={...this.usage,state:"compacted",maintenanceAction:"compact"}),this.status("completed",t?"上下文压缩完成":"已完成"),{providerSessionId:this.providerSessionId,cliType:"builtin",agentType:"workbuddy",effectiveConfig:{model:s.model||null,mode:s.mode||"default",configOptions:this.response.configOptions,provider:"workbuddy",protocol:"acp",command:e.started.command,processPid:e.started.child.pid},command:e.started.command,args:e.started.args,cwd:this.cwd,exitCode:e.started.child.exitCode,signal:e.started.child.signalCode,durationMs:Date.now()-o,stdout:e.client.rpc.stdout,stderr:e.client.rpc.stderr,content:this.content.trim(),updateCount:this.updates.count(),updates:this.updates.snapshot(),statusTimeline:this.statuses.snapshot(),contextUsage:this.usage,promptResponse:u,providerDiagnostics:this.diagnostics(),performance:{startedAtMs:o,firstEventAtMs:this.firstEventAtMs,lastEventAtMs:this.lastEventAtMs,eventCount:this.updates.count(),firstEventLatencyMs:this.firstEventAtMs===null?null:this.firstEventAtMs-o,silentForMs:Date.now()-(this.lastEventAtMs??o),durationMs:Date.now()-o}}}})}catch(n){await this.lease?.dispose();const e=g(n);throw this.status(e.failure.category==="cancelled"?"cancelled":"failed",e.message),Object.assign(e,{providerDiagnostics:this.diagnostics(),statusTimeline:this.statuses.snapshot()})}finally{d?.(),this.acceptingOutput=!1,s.onSupplementReady?.(null);try{await this.supplements?.close()}finally{i.release()}this.supplements=null,this.lease?.release(),this.lease=null,this.input=null,this.busy=!1}}async initialize(s){if(s.initialized)return;const t=r(await s.client.rpc.request("initialize",{protocolVersion:1,clientInfo:{name:"aca",version:"0.1.0"},clientCapabilities:{fs:{readTextFile:!1,writeTextFile:!1},terminal:!1,elicitation:{form:{}},_meta:{"codebuddy.ai":{question:!0}}}},6e4));if(t.protocolVersion!==1)throw new Error("WorkBuddy ACP 协议版本不兼容。");l.set(s.client,t),s.markInitialized()}async establishSession(s){if(s.sessionEstablished&&s.providerSessionId){this.providerSessionId=s.providerSessionId,this.response=s.sessionResponse??{};const t=this.response.acaAvailableCommands;Array.isArray(t)&&(this.commandCatalog=S(t),this.commands=new Set(this.commandCatalog.map(i=>i.name)));return}if(this.providerSessionId){if(r(l.get(s.client)?.agentCapabilities).loadSession!==!0)throw new Error("当前 WorkBuddy 版本不支持恢复会话,禁止静默新建。");if(this.status("resuming","WorkBuddy 会话恢复中"),this.response=r(await s.client.loadSession({sessionId:this.providerSessionId,cwd:this.cwd},12e4)),this.response.sessionId&&this.response.sessionId!==this.providerSessionId)throw new Error("WorkBuddy 恢复返回了不同的会话 ID。")}else{if(this.status("acp","WorkBuddy 会话创建中"),this.response=r(await s.client.newSession({cwd:this.cwd},12e4)),typeof this.response.sessionId!="string"||!this.response.sessionId.trim())throw new Error("WorkBuddy session/new 未返回会话 ID。");this.providerSessionId=this.response.sessionId}this.commandCatalog&&(this.response.acaAvailableCommands=this.commandCatalog),w(this.response),s.setProviderSession({providerSessionId:this.providerSessionId,sessionResponse:this.response})}handleUpdate(s){const t=r(s),i=r(t.update);if(this.providerSessionId&&t.sessionId!==this.providerSessionId)return;const o=this.router.route(s);if(!o.child&&i.sessionUpdate==="available_commands_update"&&Array.isArray(i.availableCommands)&&(this.commandCatalog=S(i.availableCommands),this.commands=new Set(this.commandCatalog.map(p=>p.name)),this.response.acaAvailableCommands=this.commandCatalog,this.lease?.setSessionResponse(this.response)),!o.child&&i.sessionUpdate==="config_option_update"&&Array.isArray(i.configOptions)&&(this.response={...this.response,configOptions:i.configOptions},this.lease?.setSessionResponse(this.response),w(this.response)),!this.acceptingOutput||!this.input)return;if(this.updates.push({method:"session/update",params:o.params}),this.firstEventAtMs??=Date.now(),this.lastEventAtMs=Date.now(),!o.child){this.credits.observe(s);const p=W(s,this.input.contextWindow);this.usage=P(s,p)??this.usage;const u=r(i._meta)["codebuddy.ai/error"];u&&(this.technicalError=u);const a=r(i._meta)["codebuddy.ai/requestId"]||r(t._meta)["codebuddy.ai/requestId"];!this.supplements&&typeof a=="string"&&a&&this.lease&&this.providerSessionId&&(this.supplements=new x(this.lease.client,this.providerSessionId,a),this.input.onSupplementReady?.(this.supplements.channel))}const d=!o.child&&i.sessionUpdate==="available_commands_update"?{...o.params,update:{...i,availableCommands:this.commandCatalog??[]}}:o.params,n=f("workbuddy",d);n&&(!o.child&&n.type==="agent_message_chunk"&&(this.content+=n.text??""),this.input.onUpdate?.(n));const e=M("workbuddy",o.params);e&&this.status(e.phase,e.label,e.detail,e.updateType)}diagnostics(){return{workbuddy:{creditUsage:this.credits.snapshot(),...this.commandCatalog!==null?{availableCommands:this.commandCatalog}:{}}}}publishCommands(){if(this.commandCatalog===null)return;const s=f("workbuddy",{sessionId:this.providerSessionId,update:{sessionUpdate:"available_commands_update",availableCommands:this.commandCatalog}});s&&this.input?.onUpdate?.(s)}async handleRequest(s,t,i){if(!this.input||!this.acceptingOutput)throw new Error("WorkBuddy 当前没有可交互的执行轮次。");const o=r(t).sessionId;if((s!=="elicitation/create"||o!==void 0)&&o!==this.providerSessionId)throw new Error("WorkBuddy 交互请求会话不匹配。");this.status("requestPermission",s==="session/request_permission"?"等待授权":"等待回答",void 0,s);try{return await q(s,t,i,this.input)}finally{this.acceptingOutput&&this.status("thinking","处理中")}}status(s,t,i,o){const d={phase:s,label:t,detail:i,updateType:o,atMs:Date.now()};this.statuses.push(d),this.input?.onStatus?.(d)}async cancel(){await this.cancelAndDispose()}async cancelAndDispose(){this.acceptingOutput=!1,this.input?.onSupplementReady?.(null),this.providerSessionId&&this.lease?.client.cancel(this.providerSessionId),await this.lease?.dispose()}async close(){this.busy?await this.cancelAndDispose():this.lease?.release()}}export{is as WorkBuddyProvider,T as workBuddyCapabilities};
|
|
1
|
+
import{workBuddyCredits as B}from"../../../core/workbuddy-credits/worker.js";import h from"node:fs";import{enterWorkBuddySession as A}from"./session-lock.js";import{forkWorkBuddySession as E}from"./fork.js";import{runAbortableRequest as W}from"../../client/abortable-request.js";import{defaultAcpRuntimePool as m}from"../../client/acp-runtime-pool.js";import{BoundedItemBuffer as f}from"../../client/bounded-buffer.js";import{contextUsageFromAcpSessionUpdate as M}from"../../client/context-usage.js";import{providerEventFromAcpSessionUpdate as w,providerStatusFromAcpSessionUpdate as R}from"../standard-acp-events.js";import{resolveWorkBuddyLaunch as U,workBuddyTimeout as x}from"./launch.js";import{applyWorkBuddyConfig as q,record as n,rememberWorkBuddyCapabilities as y}from"./config.js";import{handleWorkBuddyRequest as D}from"./interactions.js";import{WorkBuddyEventRouter as g}from"./events.js";import{WorkBuddySupplementIdentity as v,WorkBuddySupplements as _,workBuddyPromptContent as O}from"./supplements.js";import{assertWorkBuddyPromptCompleted as P,workBuddyError as S}from"./errors.js";import{WorkBuddyTurnCredits as I,workBuddyContextUsage as T}from"./usage.js";import{workBuddyCommands as k}from"./commands.js";const c=new WeakMap,z={sessionResume:!0,liveSupplement:!0,imageInput:!0,fileAttachment:!0,filesystem:!0,terminal:!0,permissionRequest:!0,configOptions:!0,usage:!0,contextUsage:!0,contextCompaction:!0,plan:!0,diff:!0};class os{id="workbuddy";name="腾讯 Code Buddy";capabilities=z;async createSession(s){return new F(s.cwd,s.providerSessionId??null,s.timeoutMs)}async forkSession(s){return E(s)}}class F{cwd;providerSessionId;timeoutMs;lease=null;input=null;acceptingOutput=!1;busy=!1;content="";usage=null;response={};commands=new Set;commandCatalog=null;credits=new I;technicalError=null;router=new g;supplements=null;supplementIdentity=new v;updates=new f(16);statuses=new f(64);firstEventAtMs=null;lastEventAtMs=null;constructor(s,t,o=x()){this.cwd=s,this.providerSessionId=t,this.timeoutMs=o}async sendPrompt(s){return this.run(s,!1)}async compactContext(s){if(!this.providerSessionId)throw new Error("WorkBuddy 当前没有可压缩的会话。");const t=await this.run({...s,cwd:s.cwd,prompt:"/compact",requireSessionResume:!0},!0);return{providerSessionId:t.providerSessionId,contextUsage:t.contextUsage??null,maintenance:{action:"compact",provider:"workbuddy",protocol:"session/prompt",stopReason:n(t.promptResponse).stopReason},durationMs:t.durationMs}}async run(s,t){if(this.busy)throw new Error("WorkBuddy 会话正在执行另一轮任务。");if(h.realpathSync(s.cwd)!==h.realpathSync(this.cwd))throw new Error("WorkBuddy 会话不能切换工作目录。");if(s.requireSessionResume&&!this.providerSessionId)throw new Error("WorkBuddy 历史会话缺少 Session ID,禁止新建会话。");if(/^\s*\/(fork|branch|fork-bg)(?:\s|$)/i.test(s.prompt))throw new Error("请使用会话菜单中的“从当前会话分叉”,以便 ACA 正确保存新会话。");const o=A(this.providerSessionId);this.busy=!0,this.input=s,this.content="",this.usage=null,this.response={},this.commands.clear(),this.commandCatalog=null,this.credits=new I,this.technicalError=null,this.router=new g,this.supplementIdentity=new v,this.updates.clear(),this.statuses.clear(),this.firstEventAtMs=this.lastEventAtMs=null;const i=Date.now();let a;try{return await W({signal:s.signal,cancelledMessage:"WorkBuddy 任务已取消",onAbort:()=>this.cancelAndDispose(),startRequest:async()=>{this.status("initializing","WorkBuddy ACP 启动中");const l=U(s.canExecuteTools!==!1);if(this.providerSessionId&&await m.retireSessionRuntimes({providerId:"workbuddy",cwd:this.cwd,providerSessionId:this.providerSessionId,keepRuntimeIdentity:l.runtimeIdentity}),s.signal?.aborted)throw new Error("WorkBuddy 任务已取消");const e=await m.acquire({providerId:"workbuddy",cwd:this.cwd,providerSessionId:this.providerSessionId,...l,onSessionUpdate:r=>this.handleUpdate(r),onClientRequest:(r,u,C)=>this.handleRequest(r,u,C.id)});if(this.lease=e,s.signal?.aborted)throw await e.dispose(),new Error("WorkBuddy 任务已取消");await this.initialize(e),await this.establishSession(e),o.bind(this.providerSessionId);const d=n(n(c.get(e.client)?.agentCapabilities).promptCapabilities);if(s.promptBlocks?.some(r=>r.type==="image")&&d.image!==!0)throw new Error("当前 CodeBuddy ACP 版本未声明图片输入支持。");if(t||(this.response=await q(e.client,this.providerSessionId,this.response,s)),e.setSessionResponse(this.response),t&&!this.commands.has("compact"))throw new Error("当前 WorkBuddy 会话未提供 /compact 命令,无法压缩上下文。");this.acceptingOutput=!0,this.publishCommands(),this.status("thinking",t?"正在压缩上下文":"思考中"),a=B.beginUsage();const p=await e.client.prompt({sessionId:this.providerSessionId,prompt:O(s.prompt,s.promptBlocks)},s.timeoutMs??this.timeoutMs);if(s.signal?.aborted)throw new Error("WorkBuddy 任务已取消");if(this.credits.identifyResponse(p),this.technicalError)throw S(this.technicalError);return P(p),t&&this.usage&&(this.usage={...this.usage,state:"compacted",maintenanceAction:"compact"}),this.status("completed",t?"上下文压缩完成":"已完成"),{providerSessionId:this.providerSessionId,cliType:"builtin",agentType:"workbuddy",effectiveConfig:{model:s.model||null,mode:s.mode||"default",configOptions:this.response.configOptions,provider:"workbuddy",protocol:"acp",command:e.started.command,processPid:e.started.child.pid},command:e.started.command,args:e.started.args,cwd:this.cwd,exitCode:e.started.child.exitCode,signal:e.started.child.signalCode,durationMs:Date.now()-i,stdout:e.client.rpc.stdout,stderr:e.client.rpc.stderr,content:this.content.trim(),updateCount:this.updates.count(),updates:this.updates.snapshot(),statusTimeline:this.statuses.snapshot(),contextUsage:this.usage,promptResponse:p,providerDiagnostics:this.diagnostics(),performance:{startedAtMs:i,firstEventAtMs:this.firstEventAtMs,lastEventAtMs:this.lastEventAtMs,eventCount:this.updates.count(),firstEventLatencyMs:this.firstEventAtMs===null?null:this.firstEventAtMs-i,silentForMs:Date.now()-(this.lastEventAtMs??i),durationMs:Date.now()-i}}}})}catch(l){await this.lease?.dispose();const e=S(l);throw this.status(e.failure.category==="cancelled"?"cancelled":"failed",e.message),Object.assign(e,{providerDiagnostics:this.diagnostics(),statusTimeline:this.statuses.snapshot()})}finally{a?.(),this.acceptingOutput=!1,s.onSupplementReady?.(null);try{await this.supplements?.close()}finally{o.release()}this.supplements=null,this.lease?.release(),this.lease=null,this.input=null,this.busy=!1}}async initialize(s){if(s.initialized)return;const t=n(await s.client.rpc.request("initialize",{protocolVersion:1,clientInfo:{name:"aca",version:"0.1.0"},clientCapabilities:{fs:{readTextFile:!1,writeTextFile:!1},terminal:!1,elicitation:{form:{}},_meta:{"codebuddy.ai":{question:!0}}}},6e4));if(t.protocolVersion!==1)throw new Error("WorkBuddy ACP 协议版本不兼容。");c.set(s.client,t),s.markInitialized()}async establishSession(s){if(s.sessionEstablished&&s.providerSessionId){this.providerSessionId=s.providerSessionId,this.response=s.sessionResponse??{};const t=this.response.acaAvailableCommands;Array.isArray(t)&&(this.commandCatalog=k(t),this.commands=new Set(this.commandCatalog.map(o=>o.name)));return}if(this.providerSessionId){if(n(c.get(s.client)?.agentCapabilities).loadSession!==!0)throw new Error("当前 WorkBuddy 版本不支持恢复会话,禁止静默新建。");if(this.status("resuming","WorkBuddy 会话恢复中"),this.response=n(await s.client.loadSession({sessionId:this.providerSessionId,cwd:this.cwd},12e4)),this.response.sessionId&&this.response.sessionId!==this.providerSessionId)throw new Error("WorkBuddy 恢复返回了不同的会话 ID。")}else{if(this.status("acp","WorkBuddy 会话创建中"),this.response=n(await s.client.newSession({cwd:this.cwd},12e4)),typeof this.response.sessionId!="string"||!this.response.sessionId.trim())throw new Error("WorkBuddy session/new 未返回会话 ID。");this.providerSessionId=this.response.sessionId}this.commandCatalog&&(this.response.acaAvailableCommands=this.commandCatalog),y(this.response),s.setProviderSession({providerSessionId:this.providerSessionId,sessionResponse:this.response})}handleUpdate(s){const t=n(s),o=n(t.update);if(this.providerSessionId&&t.sessionId!==this.providerSessionId)return;const i=this.router.route(s),a=i.child?null:this.supplementIdentity.observe(s);if(!i.child&&o.sessionUpdate==="available_commands_update"&&Array.isArray(o.availableCommands)&&(this.commandCatalog=k(o.availableCommands),this.commands=new Set(this.commandCatalog.map(p=>p.name)),this.response.acaAvailableCommands=this.commandCatalog,this.lease?.setSessionResponse(this.response)),!i.child&&o.sessionUpdate==="config_option_update"&&Array.isArray(o.configOptions)&&(this.response={...this.response,configOptions:o.configOptions},this.lease?.setSessionResponse(this.response),y(this.response)),!this.acceptingOutput||!this.input)return;if(this.updates.push({method:"session/update",params:i.params}),this.firstEventAtMs??=Date.now(),this.lastEventAtMs=Date.now(),!i.child){this.credits.observe(s);const p=M(s,this.input.contextWindow);this.usage=T(s,p)??this.usage;const r=n(o._meta)["codebuddy.ai/error"];r&&(this.technicalError=r);const u=a;!this.supplements&&typeof u=="string"&&u&&this.lease&&this.providerSessionId&&(this.supplements=new _(this.lease.client,this.providerSessionId,u),this.input.onSupplementReady?.(this.supplements.channel))}const l=!i.child&&o.sessionUpdate==="available_commands_update"?{...i.params,update:{...o,availableCommands:this.commandCatalog??[]}}:i.params,e=w("workbuddy",l);e&&(!i.child&&e.type==="agent_message_chunk"&&(this.content+=e.text??""),this.input.onUpdate?.(e));const d=R("workbuddy",i.params);d&&this.status(d.phase,d.label,d.detail,d.updateType)}diagnostics(){return{workbuddy:{creditUsage:this.credits.snapshot(),...this.commandCatalog!==null?{availableCommands:this.commandCatalog}:{}}}}publishCommands(){if(this.commandCatalog===null)return;const s=w("workbuddy",{sessionId:this.providerSessionId,update:{sessionUpdate:"available_commands_update",availableCommands:this.commandCatalog}});s&&this.input?.onUpdate?.(s)}async handleRequest(s,t,o){if(!this.input||!this.acceptingOutput)throw new Error("WorkBuddy 当前没有可交互的执行轮次。");const i=n(t).sessionId;if((s!=="elicitation/create"||i!==void 0)&&i!==this.providerSessionId)throw new Error("WorkBuddy 交互请求会话不匹配。");this.status("requestPermission",s==="session/request_permission"?"等待授权":"等待回答",void 0,s);try{return await D(s,t,o,this.input)}finally{this.acceptingOutput&&this.status("thinking","处理中")}}status(s,t,o,i){const a={phase:s,label:t,detail:o,updateType:i,atMs:Date.now()};this.statuses.push(a),this.input?.onStatus?.(a)}async cancel(){await this.cancelAndDispose()}async cancelAndDispose(){this.acceptingOutput=!1,this.input?.onSupplementReady?.(null),this.providerSessionId&&this.lease?.client.cancel(this.providerSessionId),await this.lease?.dispose()}async close(){this.busy?await this.cancelAndDispose():this.lease?.release()}}export{os as WorkBuddyProvider,z as workBuddyCapabilities};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{record as
|
|
1
|
+
import{record as a}from"./config.js";const l=new Set(["user_message_chunk","agent_message_chunk","agent_thought_chunk","tool_call","tool_call_update"]);class g{replaying=!1;observe(n){const t=a(n),i=a(t.update),e={...a(t._meta),...a(i._meta)},d=e["codebuddy.ai/historyReplay"];if(d==="start"&&(this.replaying=!0),d==="end"&&(this.replaying=!1),d||this.replaying||e["codebuddy.ai/isCompactInternal"]===!0||e["codebuddy.ai/subagent"]||e["codebuddy.ai/memberEvent"]!==void 0||e["codebuddy.ai/parentToolCallId"]!==void 0||!l.has(String(i.sessionUpdate)))return null;for(const o of["codebuddy.ai/conversationRequestId","codebuddy.ai/requestId"]){const s=e[o];if(typeof s=="string"&&s.trim()&&s.length<=256)return s}return null}}function p(c,n){return(n?.length?n:[{type:"text",text:c}]).map(t=>t.type==="image"?{type:"image",data:t.data,mimeType:t.mimeType}:{type:"text",text:t.text})}class h{active=!0;receipts=new Map;pending=new Set;channel;constructor(n,t,i){this.channel={threadId:t,turnId:i,receipt:async e=>this.receipts.get(e)??null,send:(e,d)=>{const o=this.receipts.get(e);if(o)return Promise.resolve(o);if(!this.active)return Promise.resolve({status:"failed",error:"执行轮次已结束"});this.receipts.set(e,{status:"sending"});const s=(async()=>{let u;try{const r=a(await n.rpc.request("session/steer",{sessionId:t,expectedRequestId:i,clientUserMessageId:e,contentBlocks:p("",d)},15e3));u=r.steered===!0?{status:"accepted"}:{status:"failed",error:r.reason==="stale"?"CodeBuddy 未接受补充:目标执行轮次已变化(stale),可作为新消息发送":r.reason==="idle"?"CodeBuddy 未接受补充:当前轮次已结束或暂不支持补充(idle),可作为新消息发送":`CodeBuddy 未接受补充:${String(r.reason||"当前状态不支持")}`}}catch(r){u={status:a(r).rpcResponse===!0?"failed":"uncertain",error:r instanceof Error?r.message:String(r)}}return this.receipts.set(e,u),u})();return this.pending.add(s),s.finally(()=>this.pending.delete(s)),s}}}async close(){this.active=!1,await Promise.allSettled(this.pending)}}export{g as WorkBuddySupplementIdentity,h as WorkBuddySupplements,p as workBuddyPromptContent};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.1.
|
|
1
|
+
const o="0.1.91";export{o as AICA_VERSION};
|