grix-connector 4.19.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapter/acp/acp-adapter.js +12 -12
- package/dist/adapter/agy/agy-adapter.js +10 -10
- package/dist/adapter/agy/model-list.js +2 -2
- package/dist/adapter/agy/quota.js +5 -5
- package/dist/adapter/claude/claude-adapter.js +20 -20
- package/dist/adapter/claude/claude-bridge-server.js +1 -1
- package/dist/adapter/claude/claude-tools.js +1 -1
- package/dist/adapter/claude/claude-worker-client.js +1 -1
- package/dist/adapter/claude/mcp-http-launcher.js +2 -2
- package/dist/adapter/claude/result-timeout.js +1 -1
- package/dist/adapter/cursor/cursor-adapter.js +12 -11
- package/dist/adapter/deepseek-harness/event-mapper.js +1 -1
- package/dist/adapter/deepseek-harness/jsonrpc-adapter.js +3 -3
- package/dist/adapter/pi/pi-adapter.js +8 -6
- package/dist/adapter/pi/pi-grix-tools-extension.js +2 -0
- package/dist/assets/dsh-bridge/grix-dsh-bridge-5.1.0.tgz +0 -0
- package/dist/assets/dsh-bridge/manifest.json +6 -6
- package/dist/bridge/bridge.js +3 -2
- package/dist/bridge/rate-limits.js +1 -1
- package/dist/bridge/send-controller.js +3 -3
- package/dist/bridge/toolbar-meta.js +1 -1
- package/dist/core/access/allowlist-store.js +1 -1
- package/dist/core/aibot/client.js +2 -2
- package/dist/core/file-ops/list-files.js +1 -1
- package/dist/core/installer/registry.js +1 -1
- package/dist/core/protocol/protocol-text.js +1 -1
- package/dist/core/util/home-env.js +1 -0
- package/dist/grix.js +5 -5
- package/dist/log.js +2 -2
- package/dist/manager.js +1 -1
- package/dist/mcp/stream-http/config.js +1 -1
- package/dist/mcp/stream-http/connection-binding.js +1 -1
- package/dist/mcp/stream-http/tool-executor.js +1 -1
- package/dist/mcp/stream-http/tool-registry.js +1 -1
- package/dist/mcp/stream-http/tool-schemas.js +1 -1
- package/dist/protocol/acp-client.js +1 -1
- package/openclaw-plugin/audit-recorder-worker.js +2 -1
- package/openclaw-plugin/index.js +10 -4
- package/package.json +1 -1
- package/dist/assets/dsh-bridge/grix-dsh-bridge-4.19.0.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EventEmitter as b}from"events";import{log as a}from"../core/log/index.js";import{AgentEventType as h}from"../types/events.js";import{mapSessionUpdate as M}from"./event-mapper.js";import{AcpTerminalHost as v,acpTerminalErrorCode as g}from"./acp-terminal.js";class m extends Error{authMethods;constructor(e){super("ACP authentication required"),this.name="AcpAuthRequiredError",this.authMethods=e}}function f(d){if(!d||typeof d!="object")return!1;const e=d;return e.code===-32e3?!0:e.code===-32603&&e.data?.details?/\b(401|token\s*expired|access\s*token)\b/i.test(e.data.details):!1}function S(d){return!d||typeof d!="object"?[{id:"oauth"}]:d.data?.authMethods??[{id:"oauth"}]}const y=new Set(["cwd","mcpServers","sessionId","additionalDirectories"]);function w(d,e){if(e)for(const[t,i]of Object.entries(e))y.has(t)||(d[t]=i)}class p extends b{acpSessionId="";alive=!1;pendingPermissions=new Map;availableModes=[];availableModels=[];currentMode="";currentModel="";listSupported=!1;loadSupported=!1;_supportsCommandsExecute=!1;_availableCommands=[];transport;terminalEnabled=!1;terminalHost=new v;settleTimer=null;static SETTLE_MS=3e3;pendingToolCallIds=new Set;settleSuppressedSince=0;static SETTLE_SUPPRESS_MAX_MS=900*1e3;constructor(){super(),this.transport=null}get sessionId(){return this.acpSessionId}get isAlive(){return this.alive}get modes(){return[...this.availableModes]}get mode(){return this.currentMode}get models(){return[...this.availableModels]}get model(){return this.currentModel}get sessionOptions(){return{modes:[...this.availableModes],currentModeId:this.currentMode,models:[...this.availableModels],currentModelId:this.currentModel}}get supportsCommandsExecute(){return this._supportsCommandsExecute}get availableCommands(){return[...this._availableCommands]}async connect(e){this.transport=e.transport,this.terminalEnabled=e.terminal===!0,this.transport.on("close",()=>{this.terminalHost.dispose(),this.alive&&(this.alive=!1,this.emit("session-lost"))}),this.transport.setHandlers((o,l)=>{o==="session/update"?this.handleSessionUpdate(l):o==="_kiro.dev/metadata"?this.handleKiroMetadata(l):o==="_kiro.dev/commands/available"?this.handleCommandsAvailable(l):o==="_kiro.dev/compaction/status"?this.emit("compactionStatus",l):o==="_kiro.dev/clear/status"&&this.emit("clearStatus",l)},(o,l,c)=>{o==="session/request_permission"?this.handlePermissionRequest(l,c):o.startsWith("terminal/")&&this.terminalEnabled?this.handleTerminalRequest(o,l,c).catch(u=>{a.warn("acp-client",`terminal response failed: ${u instanceof Error?u.message:String(u)}`)}):o.startsWith("cursor/")?this.transport.respondSuccess(l,{}).catch(()=>{}):this.transport.respondError(l,-32601,"method not implemented").catch(()=>{})});const t=await this.initialize();this.listSupported=!!t.agentCapabilities?.sessionCapabilities?.list,this.loadSupported=!!t.agentCapabilities?.loadSession;const i=t.agentCapabilities??{};this._supportsCommandsExecute=!!(i.extensions?.["_kiro.dev/commands"]||i.commands);const s=t?._meta;if(s?.modelState&&this.absorbModels(s.modelState),e.authMethod)try{await this.transport.call("authenticate",{methodId:e.authMethod})}catch(o){throw f(o)?new m(S(o)):o}const n=e.sessionId&&e.sessionId!=="__continue__";let r=!1;if(n){if(!this.loadSupported)throw new Error(`session/load not supported by agent, cannot resume session ${e.sessionId}`);try{await this.loadSession(e.sessionId,e)&&(r=!0)}catch(o){throw f(o)?new m(S(o)):o}if(!r)throw new Error(`session/load failed for session ${e.sessionId}`)}else try{await this.newSession(e)}catch(o){throw f(o)?new m(S(o)):o}e.initialMode&&await this.setLiveMode(e.initialMode).catch(()=>{}),e.initialModel&&await this.setModel(e.initialModel).catch(()=>{}),this.alive=!0}async initialize(){return await this.transport.call("initialize",{protocolVersion:1,clientCapabilities:{fs:{readTextFile:!1,writeTextFile:!1},terminal:this.terminalEnabled},clientInfo:{name:"grix-connector-acp",version:"0.2.0"}})}buildMcpEntries(e){return(e??[]).map(t=>{if("type"in t){const s={type:t.type,name:t.name,url:t.url};return t.headers&&(s.headers=Object.entries(t.headers).map(([n,r])=>({name:n,value:r}))),s}const i={name:t.name,command:t.command};return t.args&&(i.args=t.args),t.env&&(i.env=Object.entries(t.env).map(([s,n])=>({name:s,value:n}))),i})}async newSession(e){const t=this.buildMcpEntries(e.mcpServers),i={cwd:e.cwd||process.cwd(),mcpServers:t};e.additionalDirectories&&e.additionalDirectories.length>0&&(i.additionalDirectories=e.additionalDirectories),w(i,e.newSessionParams);const s=await this.transport.call("session/new",i);if(!s?.sessionId)throw new Error("session/new returned empty sessionId");this.acpSessionId=s.sessionId,this.absorbModes(s.modes),a.info("acp-client",`[handshake] session/new models block: ${JSON.stringify(s.models)}`),this.absorbModels(s.models),this.absorbConfigOptions(s.configOptions)}async loadSession(e,t){const i=this.buildMcpEntries(t.mcpServers),s={sessionId:e,cwd:t.cwd||process.cwd(),mcpServers:i};t.additionalDirectories&&t.additionalDirectories.length>0&&(s.additionalDirectories=t.additionalDirectories),w(s,t.newSessionParams);const n=await this.transport.call("session/load",s);return n?.sessionId?(this.acpSessionId=n.sessionId,this.absorbModes(n.modes),a.info("acp-client",`[handshake] session/load models block: ${JSON.stringify(n.models)}`),this.absorbModels(n.models),this.absorbConfigOptions(n.configOptions),!0):n&&(n.modes||n.models||n.configOptions)?(this.acpSessionId=e,this.absorbModes(n.modes),a.info("acp-client",`[handshake] session/load (compat) models block: ${JSON.stringify(n.models)}`),this.absorbModels(n.models),this.absorbConfigOptions(n.configOptions),!0):(a.info("acp-client",`[handshake] session/load returned empty result for ${e}`),this.acpSessionId=e,!0)}absorbModes(e){e?.availableModes?.length&&(this.availableModes=[...e.availableModes],e.currentModeId&&(this.currentMode=e.currentModeId))}absorbConfigOptions(e){if(Array.isArray(e))for(const t of e){const i=t,s=Array.isArray(i?.options)?i.options.filter(r=>typeof r?.value=="string"&&r.value):[];if(s.length===0)continue;const n=i.category||i.id;n==="mode"&&this.availableModes.length===0?(this.availableModes=s.map(r=>({id:r.value,name:r.name||r.value,...r.description?{description:r.description}:{}})),typeof i.currentValue=="string"&&i.currentValue&&(this.currentMode=i.currentValue),a.info("acp-client",`[handshake] absorbConfigOptions modes: count=${this.availableModes.length} ids=${JSON.stringify(this.availableModes.map(r=>r.id))} current=${i.currentValue??"<none>"}`)):n==="model"&&this.availableModels.length===0&&(this.availableModels=s.map(r=>({modelId:r.value,name:r.name||r.value})),typeof i.currentValue=="string"&&i.currentValue&&(this.currentModel=i.currentValue),a.info("acp-client",`[handshake] absorbConfigOptions models: count=${this.availableModels.length} ids=${JSON.stringify(this.availableModels.map(r=>r.modelId))} current=${i.currentValue??"<none>"}`))}}absorbModels(e){if(!e?.availableModels?.length){a.info("acp-client","[handshake] absorbModels skipped: block empty");return}this.availableModels=[...e.availableModels],a.info("acp-client",`[handshake] absorbModels: count=${this.availableModels.length} ids=${JSON.stringify(this.availableModels.map(t=>t.modelId))} current=${e.currentModelId??"<none>"}`),e.currentModelId&&(this.currentModel=e.currentModelId)}async send(e,t,i){if(!this.alive)throw new Error("session not active");if(!this.acpSessionId)throw new Error("no agent session id");const s=[{type:"text",text:e}];if(t)for(const n of t)s.push({type:"image",data:n.data.toString("base64"),mimeType:n.mimeType});this.pendingToolCallIds.clear(),this.settleSuppressedSince=0,await this.transport.call("session/prompt",{sessionId:this.acpSessionId,prompt:s,...this.currentModel?{modelId:this.currentModel}:{}}),this.scheduleSettledResult()}scheduleSettledResult(){this.settleTimer&&clearTimeout(this.settleTimer),this.settleTimer=setTimeout(()=>{if(this.settleTimer=null,!!this.alive){if(this.pendingToolCallIds.size>0){if(this.settleSuppressedSince===0&&(this.settleSuppressedSince=Date.now()),Date.now()-this.settleSuppressedSince<p.SETTLE_SUPPRESS_MAX_MS){a.info("acp-client",`settle suppressed: ${this.pendingToolCallIds.size} pending tool call(s) for session ${this.acpSessionId}`),this.scheduleSettledResult();return}a.warn("acp-client",`settle suppression exceeded ${p.SETTLE_SUPPRESS_MAX_MS/6e4}min with ${this.pendingToolCallIds.size} pending tool call(s), emitting Result anyway`)}this.settleSuppressedSince=0,a.info("acp-client",`settle timer fired, emitting Result for session ${this.acpSessionId}`),this.emit("event",{type:h.Result,sessionId:this.acpSessionId,done:!0,synthetic:!0})}},p.SETTLE_MS),this.settleTimer.unref()}deferSettledResult(){this.scheduleSettledResult()}clearSettleTimer(){this.settleTimer&&(clearTimeout(this.settleTimer),this.settleTimer=null),this.settleSuppressedSince=0}dispose(){this.clearSettleTimer(),this.terminalHost.dispose(),this.alive=!1}async handleTerminalRequest(e,t,i){try{const s=await this.terminalHost.handle(e,i,this.acpSessionId);await this.transport.respondSuccess(t,s)}catch(s){await this.transport.respondError(t,g(s),s instanceof Error?s.message:String(s))}}async cancel(){if(this.acpSessionId){this.pendingToolCallIds.clear(),this.settleSuppressedSince=0;try{await this.transport.notify("session/cancel",{sessionId:this.acpSessionId})}catch{}}}async authenticate(e){await this.transport.call("authenticate",{methodId:e})}async respondPermission(e,t){const i=this.pendingPermissions.get(e);if(!i)throw new Error(`unknown permission request: ${e}`);this.pendingPermissions.delete(e);const s=this.pickPermissionOptionId(t.behavior,i.options),n=this.buildPermissionResult(t.behavior,s);await this.transport.respondSuccess(i.rpcId,n)}async respondPermissionOption(e,t){const i=this.pendingPermissions.get(e);if(!i)throw new Error(`unknown permission request: ${e}`);if(!i.options.some(s=>s.optionId===t))throw new Error(`unknown permission option: ${t}`);this.pendingPermissions.delete(e),await this.transport.respondSuccess(i.rpcId,{outcome:{outcome:"selected",optionId:t}})}async ping(e=1e4){if(!this.alive)return!1;try{const t=new AbortController,i=setTimeout(()=>t.abort(),e);return await this.transport.call("session/list",{},t.signal),clearTimeout(i),!0}catch(t){return t?.code===-32601}}async setLiveMode(e){if(!this.acpSessionId)return a.warn("acp-client",`setLiveMode("${e}") skipped: no active session`),!1;const t=this.matchAvailableMode(e);if(!t)return a.warn("acp-client",`setLiveMode("${e}") failed: mode not found in available [${this.availableModes.map(i=>i.id).join(",")}]`),!1;try{const i=new AbortController,s=setTimeout(()=>i.abort(),8e3);return await this.transport.call("session/set_mode",{sessionId:this.acpSessionId,modeId:t},i.signal),clearTimeout(s),this.currentMode=t,!0}catch(i){return a.warn("acp-client",`setLiveMode("${t}") RPC failed: ${i instanceof Error?i.message:i}`),!1}}async setModel(e){if(!this.acpSessionId)return a.warn("acp-client",`setModel("${e}") skipped: no active session`),!1;try{const t=new AbortController,i=setTimeout(()=>t.abort(),8e3);return await this.transport.call("session/set_model",{sessionId:this.acpSessionId,modelId:e},t.signal),clearTimeout(i),this.currentModel=e,!0}catch(t){return a.warn("acp-client",`setModel("${e}") RPC failed: ${t instanceof Error?t.message:t}`),!1}}handleSessionUpdate(e){this.emit("activity");const t=e?.update?.sessionUpdate,i=t==="usage_update";if(t==="tool_call"||t==="tool_call_update"){const n=e?.update??{},r=String(n.toolCallId??""),o=String(n.status??"").toLowerCase().trim();r&&(o==="completed"||o==="failed"?this.pendingToolCallIds.delete(r):t==="tool_call"&&this.pendingToolCallIds.add(r))}this.settleTimer&&!i&&this.scheduleSettledResult();const s=M(this.acpSessionId,e);for(const n of s)n.sessionId||(n.sessionId=this.acpSessionId),n.type===h.Result&&(this.pendingToolCallIds.clear(),this.settleTimer&&this.clearSettleTimer()),this.emit("event",n)}handleKiroMetadata(e){const i=e?.contextUsagePercentage;typeof i!="number"||!Number.isFinite(i)||this.emit("event",{type:h.ContextWindowUpdate,sessionId:this.acpSessionId,contextWindow:{usedPercentage:Math.min(100,Math.max(0,i))}})}handleCommandsAvailable(e){const t=e,i=Array.isArray(t?.commands)?t.commands:[];this._availableCommands=i.map(s=>({name:String(s.name??""),description:s.description?String(s.description):void 0,args:s.args?String(s.args):void 0})),this._supportsCommandsExecute=!0,this.emit("commandsAvailable",this._availableCommands)}async executeCommand(e,t,i=2e4){if(!this.alive)throw new Error("session not active");if(!this.acpSessionId)throw new Error("no agent session id");const s=new AbortController;let n=!1;const r=setTimeout(()=>{n=!0,s.abort()},i);try{const o=await this.transport.call("_kiro.dev/commands/execute",{sessionId:this.acpSessionId,command:e,...t?{args:t}:{}},s.signal);return clearTimeout(r),{status:o?.status??"ok",message:o?.message,options:o?.options,data:o?.data}}catch(o){if(clearTimeout(r),n)return{status:"failed",message:`command timed out after ${i}ms`};const l=o instanceof Error?o.message:String(o);if(o?.code===-32601)throw this._supportsCommandsExecute=!1,o;return{status:"failed",message:l}}}handlePermissionRequest(e,t){const i=t,s=i?.toolCall??{},n=String(e),r=Array.isArray(i?.options)?i.options:[];this.pendingPermissions.set(n,{rpcId:e,options:r});const o=s.title||s.kind||"permission",l=s.toolCallId||n,c=s.title||"",u={type:h.PermissionRequest,requestId:n,toolName:o,toolInput:c||l,sessionId:this.acpSessionId,permissionRequest:{requestId:n,toolCallId:l,toolName:o,toolTitle:c,options:r,rawParams:t}};this.emit("event",u)}matchAvailableMode(e){const t=e.toLowerCase();for(const i of this.availableModes)if(i.id.toLowerCase()===t||i.name.toLowerCase()===t)return i.id;return""}pickPermissionOptionId(e,t){if(t.length===0)return"";if(e==="deny"){for(const s of t)if(s.kind==="reject_once"||s.kind==="reject_always")return s.optionId;for(const s of t)if(s.kind.toLowerCase().includes("reject")||s.kind.toLowerCase().includes("deny"))return s.optionId;for(const s of t)if(s.name.toLowerCase().includes("reject")||s.name.toLowerCase().includes("deny"))return s.optionId;return t[t.length-1].optionId}const i=e==="allow-always"?"allow_always":e==="allow-once"?"allow_once":null;if(i){for(const s of t)if(s.kind===i)return s.optionId}for(const s of t)if(s.kind.toLowerCase().includes("allow"))return s.optionId;for(const s of t)if(s.name.toLowerCase().includes("allow"))return s.optionId;return t[0].optionId}buildPermissionResult(e,t){return e==="deny"?t?{outcome:{outcome:"selected",optionId:t}}:{outcome:{outcome:"cancelled"}}:t?{outcome:{outcome:"selected",optionId:t}}:{outcome:{outcome:"cancelled"}}}}export{y as ACP_NEW_SESSION_RESERVED_KEYS,m as AcpAuthRequiredError,p as AcpClient,f as isAuthRequiredError};
|
|
1
|
+
import{EventEmitter as S}from"events";import{log as l}from"../core/log/index.js";import{AgentEventType as p}from"../types/events.js";import{mapSessionUpdate as b}from"./event-mapper.js";import{AcpTerminalHost as M,acpTerminalErrorCode as I}from"./acp-terminal.js";class f extends Error{authMethods;constructor(e){super("ACP authentication required"),this.name="AcpAuthRequiredError",this.authMethods=e}}function g(c){if(!c||typeof c!="object")return!1;const e=c;return e.code===-32e3?!0:e.code===-32603&&e.data?.details?/\b(401|token\s*expired|access\s*token)\b/i.test(e.data.details):!1}function v(c){return!c||typeof c!="object"?[{id:"oauth"}]:c.data?.authMethods??[{id:"oauth"}]}const y=new Set(["cwd","mcpServers","sessionId","additionalDirectories"]);function w(c,e){if(e)for(const[t,i]of Object.entries(e))y.has(t)||(c[t]=i)}class m extends S{acpSessionId="";alive=!1;pendingPermissions=new Map;availableModes=[];availableModels=[];availableThoughtLevels=[];currentMode="";currentModel="";currentThoughtLevel="";thoughtLevelConfigId="";listSupported=!1;loadSupported=!1;_supportsCommandsExecute=!1;_availableCommands=[];transport;terminalEnabled=!1;terminalHost=new M;settleTimer=null;static SETTLE_MS=3e3;pendingToolCallIds=new Set;settleSuppressedSince=0;static SETTLE_SUPPRESS_MAX_MS=900*1e3;constructor(){super(),this.transport=null}get sessionId(){return this.acpSessionId}get isAlive(){return this.alive}get modes(){return[...this.availableModes]}get mode(){return this.currentMode}get models(){return[...this.availableModels]}get model(){return this.currentModel}get sessionOptions(){const e={modes:[...this.availableModes],currentModeId:this.currentMode,models:[...this.availableModels],currentModelId:this.currentModel};return(this.availableThoughtLevels.length>0||this.thoughtLevelConfigId)&&(e.thoughtLevels=[...this.availableThoughtLevels],e.currentThoughtLevelId=this.currentThoughtLevel,e.thoughtLevelConfigId=this.thoughtLevelConfigId||"thinking"),e}get hasThoughtLevel(){return this.availableThoughtLevels.length>0||!!this.thoughtLevelConfigId}get supportsCommandsExecute(){return this._supportsCommandsExecute}get availableCommands(){return[...this._availableCommands]}async connect(e){this.transport=e.transport,this.terminalEnabled=e.terminal===!0,this.transport.on("close",()=>{this.terminalHost.dispose(),this.alive&&(this.alive=!1,this.emit("session-lost"))}),this.transport.setHandlers((o,d)=>{o==="session/update"?this.handleSessionUpdate(d):o==="_kiro.dev/metadata"?this.handleKiroMetadata(d):o==="_kiro.dev/commands/available"?this.handleCommandsAvailable(d):o==="_kiro.dev/compaction/status"?this.emit("compactionStatus",d):o==="_kiro.dev/clear/status"&&this.emit("clearStatus",d)},(o,d,h)=>{o==="session/request_permission"?this.handlePermissionRequest(d,h):o.startsWith("terminal/")&&this.terminalEnabled?this.handleTerminalRequest(o,d,h).catch(u=>{l.warn("acp-client",`terminal response failed: ${u instanceof Error?u.message:String(u)}`)}):o.startsWith("cursor/")?this.transport.respondSuccess(d,{}).catch(()=>{}):this.transport.respondError(d,-32601,"method not implemented").catch(()=>{})});const t=await this.initialize();this.listSupported=!!t.agentCapabilities?.sessionCapabilities?.list,this.loadSupported=!!t.agentCapabilities?.loadSession;const i=t.agentCapabilities??{};this._supportsCommandsExecute=!!(i.extensions?.["_kiro.dev/commands"]||i.commands);const s=t?._meta;if(s?.modelState&&this.absorbModels(s.modelState),e.authMethod)try{await this.transport.call("authenticate",{methodId:e.authMethod})}catch(o){throw g(o)?new f(v(o)):o}const n=e.sessionId&&e.sessionId!=="__continue__";let a=!1;if(n){if(!this.loadSupported)throw new Error(`session/load not supported by agent, cannot resume session ${e.sessionId}`);try{await this.loadSession(e.sessionId,e)&&(a=!0)}catch(o){throw g(o)?new f(v(o)):o}if(!a)throw new Error(`session/load failed for session ${e.sessionId}`)}else try{await this.newSession(e)}catch(o){throw g(o)?new f(v(o)):o}e.initialMode&&await this.setLiveMode(e.initialMode).catch(()=>{}),e.initialModel&&await this.setModel(e.initialModel).catch(()=>{}),this.alive=!0}async initialize(){return await this.transport.call("initialize",{protocolVersion:1,clientCapabilities:{fs:{readTextFile:!1,writeTextFile:!1},terminal:this.terminalEnabled},clientInfo:{name:"grix-connector-acp",version:"0.2.0"}})}buildMcpEntries(e){return(e??[]).map(t=>{if("type"in t){const s={type:t.type,name:t.name,url:t.url};return t.headers&&(s.headers=Object.entries(t.headers).map(([n,a])=>({name:n,value:a}))),s}const i={name:t.name,command:t.command};return t.args&&(i.args=t.args),t.env&&(i.env=Object.entries(t.env).map(([s,n])=>({name:s,value:n}))),i})}async newSession(e){const t=this.buildMcpEntries(e.mcpServers),i={cwd:e.cwd||process.cwd(),mcpServers:t};e.additionalDirectories&&e.additionalDirectories.length>0&&(i.additionalDirectories=e.additionalDirectories),w(i,e.newSessionParams);const s=await this.transport.call("session/new",i);if(!s?.sessionId)throw new Error("session/new returned empty sessionId");this.acpSessionId=s.sessionId,this.absorbModes(s.modes),l.info("acp-client",`[handshake] session/new models block: ${JSON.stringify(s.models)}`),this.absorbModels(s.models),this.absorbConfigOptions(s.configOptions)}async loadSession(e,t){const i=this.buildMcpEntries(t.mcpServers),s={sessionId:e,cwd:t.cwd||process.cwd(),mcpServers:i};t.additionalDirectories&&t.additionalDirectories.length>0&&(s.additionalDirectories=t.additionalDirectories),w(s,t.newSessionParams);const n=await this.transport.call("session/load",s);return n?.sessionId?(this.acpSessionId=n.sessionId,this.absorbModes(n.modes),l.info("acp-client",`[handshake] session/load models block: ${JSON.stringify(n.models)}`),this.absorbModels(n.models),this.absorbConfigOptions(n.configOptions),!0):n&&(n.modes||n.models||n.configOptions)?(this.acpSessionId=e,this.absorbModes(n.modes),l.info("acp-client",`[handshake] session/load (compat) models block: ${JSON.stringify(n.models)}`),this.absorbModels(n.models),this.absorbConfigOptions(n.configOptions),!0):(l.info("acp-client",`[handshake] session/load returned empty result for ${e}`),this.acpSessionId=e,!0)}absorbModes(e){e?.availableModes?.length&&(this.availableModes=[...e.availableModes],e.currentModeId&&(this.currentMode=e.currentModeId))}absorbConfigOptions(e,t){if(!Array.isArray(e))return;const i=t?.overwrite===!0;for(const s of e){const n=s,a=Array.isArray(n?.options)?n.options.filter(r=>typeof r?.value=="string"&&r.value):[];if(a.length===0)continue;const o=typeof n?.category=="string"?n.category:"",d=typeof n?.id=="string"?n.id:"",h=o||d,u=o==="thought_level"||d==="thinking"||h==="thought_level";h==="mode"&&(i||this.availableModes.length===0)?(this.availableModes=a.map(r=>({id:r.value,name:r.name||r.value,...r.description?{description:r.description}:{}})),typeof n.currentValue=="string"&&n.currentValue&&(this.currentMode=n.currentValue),l.info("acp-client",`[configOptions] absorb modes: count=${this.availableModes.length} ids=${JSON.stringify(this.availableModes.map(r=>r.id))} current=${n.currentValue??"<none>"} overwrite=${i}`)):h==="model"&&(i||this.availableModels.length===0)?(this.availableModels=a.map(r=>({modelId:r.value,name:r.name||r.value})),typeof n.currentValue=="string"&&n.currentValue&&(this.currentModel=n.currentValue),l.info("acp-client",`[configOptions] absorb models: count=${this.availableModels.length} ids=${JSON.stringify(this.availableModels.map(r=>r.modelId))} current=${n.currentValue??"<none>"} overwrite=${i}`)):u&&(i||this.availableThoughtLevels.length===0)&&(this.thoughtLevelConfigId=d||"thinking",this.availableThoughtLevels=a.map(r=>({id:r.value,name:r.name||r.value,...r.description?{description:r.description}:{}})),typeof n.currentValue=="string"&&n.currentValue&&(this.currentThoughtLevel=n.currentValue),l.info("acp-client",`[configOptions] absorb thought_level: configId=${this.thoughtLevelConfigId} count=${this.availableThoughtLevels.length} ids=${JSON.stringify(this.availableThoughtLevels.map(r=>r.id))} current=${n.currentValue??"<none>"} overwrite=${i}`))}}absorbModels(e){if(!e?.availableModels?.length){l.info("acp-client","[handshake] absorbModels skipped: block empty");return}this.availableModels=[...e.availableModels],l.info("acp-client",`[handshake] absorbModels: count=${this.availableModels.length} ids=${JSON.stringify(this.availableModels.map(t=>t.modelId))} current=${e.currentModelId??"<none>"}`),e.currentModelId&&(this.currentModel=e.currentModelId)}async send(e,t,i){if(!this.alive)throw new Error("session not active");if(!this.acpSessionId)throw new Error("no agent session id");const s=[{type:"text",text:e}];if(t)for(const n of t)s.push({type:"image",data:n.data.toString("base64"),mimeType:n.mimeType});this.pendingToolCallIds.clear(),this.settleSuppressedSince=0,await this.transport.call("session/prompt",{sessionId:this.acpSessionId,prompt:s,...this.currentModel?{modelId:this.currentModel}:{}}),this.scheduleSettledResult()}scheduleSettledResult(){this.settleTimer&&clearTimeout(this.settleTimer),this.settleTimer=setTimeout(()=>{if(this.settleTimer=null,!!this.alive){if(this.pendingToolCallIds.size>0){if(this.settleSuppressedSince===0&&(this.settleSuppressedSince=Date.now()),Date.now()-this.settleSuppressedSince<m.SETTLE_SUPPRESS_MAX_MS){l.info("acp-client",`settle suppressed: ${this.pendingToolCallIds.size} pending tool call(s) for session ${this.acpSessionId}`),this.scheduleSettledResult();return}l.warn("acp-client",`settle suppression exceeded ${m.SETTLE_SUPPRESS_MAX_MS/6e4}min with ${this.pendingToolCallIds.size} pending tool call(s), emitting Result anyway`)}this.settleSuppressedSince=0,l.info("acp-client",`settle timer fired, emitting Result for session ${this.acpSessionId}`),this.emit("event",{type:p.Result,sessionId:this.acpSessionId,done:!0,synthetic:!0})}},m.SETTLE_MS),this.settleTimer.unref()}deferSettledResult(){this.scheduleSettledResult()}clearSettleTimer(){this.settleTimer&&(clearTimeout(this.settleTimer),this.settleTimer=null),this.settleSuppressedSince=0}dispose(){this.clearSettleTimer(),this.terminalHost.dispose(),this.alive=!1}async handleTerminalRequest(e,t,i){try{const s=await this.terminalHost.handle(e,i,this.acpSessionId);await this.transport.respondSuccess(t,s)}catch(s){await this.transport.respondError(t,I(s),s instanceof Error?s.message:String(s))}}async cancel(){if(this.acpSessionId){this.pendingToolCallIds.clear(),this.settleSuppressedSince=0;try{await this.transport.notify("session/cancel",{sessionId:this.acpSessionId})}catch{}}}async authenticate(e){await this.transport.call("authenticate",{methodId:e})}async respondPermission(e,t){const i=this.pendingPermissions.get(e);if(!i)throw new Error(`unknown permission request: ${e}`);this.pendingPermissions.delete(e);const s=this.pickPermissionOptionId(t.behavior,i.options),n=this.buildPermissionResult(t.behavior,s);await this.transport.respondSuccess(i.rpcId,n)}async respondPermissionOption(e,t){const i=this.pendingPermissions.get(e);if(!i)throw new Error(`unknown permission request: ${e}`);if(!i.options.some(s=>s.optionId===t))throw new Error(`unknown permission option: ${t}`);this.pendingPermissions.delete(e),await this.transport.respondSuccess(i.rpcId,{outcome:{outcome:"selected",optionId:t}})}async ping(e=1e4){if(!this.alive)return!1;try{const t=new AbortController,i=setTimeout(()=>t.abort(),e);return await this.transport.call("session/list",{},t.signal),clearTimeout(i),!0}catch(t){return t?.code===-32601}}async setLiveMode(e){if(!this.acpSessionId)return l.warn("acp-client",`setLiveMode("${e}") skipped: no active session`),!1;const t=this.matchAvailableMode(e);if(!t)return l.warn("acp-client",`setLiveMode("${e}") failed: mode not found in available [${this.availableModes.map(i=>i.id).join(",")}]`),!1;try{const i=new AbortController,s=setTimeout(()=>i.abort(),8e3);return await this.transport.call("session/set_mode",{sessionId:this.acpSessionId,modeId:t},i.signal),clearTimeout(s),this.currentMode=t,!0}catch(i){return l.warn("acp-client",`setLiveMode("${t}") RPC failed: ${i instanceof Error?i.message:i}`),!1}}async setModel(e){if(!this.acpSessionId)return l.warn("acp-client",`setModel("${e}") skipped: no active session`),!1;try{const t=new AbortController,i=setTimeout(()=>t.abort(),8e3);return await this.transport.call("session/set_model",{sessionId:this.acpSessionId,modelId:e},t.signal),clearTimeout(i),this.currentModel=e,!0}catch(t){return l.warn("acp-client",`setModel("${e}") RPC failed: ${t instanceof Error?t.message:t}`),!1}}async setConfigOption(e,t){const i=String(e??"").trim(),s=String(t??"").trim();if(!this.acpSessionId)return l.warn("acp-client",`setConfigOption("${i}","${s}") skipped: no active session`),!1;if(!i||!s)return l.warn("acp-client","setConfigOption skipped: empty configId/value"),!1;try{const n=new AbortController,a=setTimeout(()=>n.abort(),8e3),o=await this.transport.call("session/set_config_option",{sessionId:this.acpSessionId,configId:i,value:s},n.signal);return clearTimeout(a),o?.configOptions?(this.absorbConfigOptions(o.configOptions,{overwrite:!0}),this.emit("configOptionsUpdated")):(i===this.thoughtLevelConfigId||i==="thinking")&&(this.currentThoughtLevel=s,this.thoughtLevelConfigId||(this.thoughtLevelConfigId=i)),!0}catch(n){return l.warn("acp-client",`setConfigOption("${i}","${s}") RPC failed: ${n instanceof Error?n.message:n}`),!1}}handleSessionUpdate(e){this.emit("activity");const t=e?.update?.sessionUpdate,i=t==="usage_update"||t==="config_option_update";if(t==="config_option_update"){const a=(e?.update??{}).configOptions??e?.configOptions;this.absorbConfigOptions(a,{overwrite:!0}),this.emit("configOptionsUpdated")}if(t==="tool_call"||t==="tool_call_update"){const n=e?.update??{},a=String(n.toolCallId??""),o=String(n.status??"").toLowerCase().trim();a&&(o==="completed"||o==="failed"?this.pendingToolCallIds.delete(a):t==="tool_call"&&this.pendingToolCallIds.add(a))}this.settleTimer&&!i&&this.scheduleSettledResult();const s=b(this.acpSessionId,e);for(const n of s)n.sessionId||(n.sessionId=this.acpSessionId),n.type===p.Result&&(this.pendingToolCallIds.clear(),this.settleTimer&&this.clearSettleTimer()),this.emit("event",n)}handleKiroMetadata(e){const i=e?.contextUsagePercentage;typeof i!="number"||!Number.isFinite(i)||this.emit("event",{type:p.ContextWindowUpdate,sessionId:this.acpSessionId,contextWindow:{usedPercentage:Math.min(100,Math.max(0,i))}})}handleCommandsAvailable(e){const t=e,i=Array.isArray(t?.commands)?t.commands:[];this._availableCommands=i.map(s=>({name:String(s.name??""),description:s.description?String(s.description):void 0,args:s.args?String(s.args):void 0})),this._supportsCommandsExecute=!0,this.emit("commandsAvailable",this._availableCommands)}async executeCommand(e,t,i=2e4){if(!this.alive)throw new Error("session not active");if(!this.acpSessionId)throw new Error("no agent session id");const s=new AbortController;let n=!1;const a=setTimeout(()=>{n=!0,s.abort()},i);try{const o=await this.transport.call("_kiro.dev/commands/execute",{sessionId:this.acpSessionId,command:e,...t?{args:t}:{}},s.signal);return clearTimeout(a),{status:o?.status??"ok",message:o?.message,options:o?.options,data:o?.data}}catch(o){if(clearTimeout(a),n)return{status:"failed",message:`command timed out after ${i}ms`};const d=o instanceof Error?o.message:String(o);if(o?.code===-32601)throw this._supportsCommandsExecute=!1,o;return{status:"failed",message:d}}}handlePermissionRequest(e,t){const i=t,s=i?.toolCall??{},n=String(e),a=Array.isArray(i?.options)?i.options:[];this.pendingPermissions.set(n,{rpcId:e,options:a});const o=s.title||s.kind||"permission",d=s.toolCallId||n,h=s.title||"",u={type:p.PermissionRequest,requestId:n,toolName:o,toolInput:h||d,sessionId:this.acpSessionId,permissionRequest:{requestId:n,toolCallId:d,toolName:o,toolTitle:h,options:a,rawParams:t}};this.emit("event",u)}matchAvailableMode(e){const t=e.toLowerCase();for(const i of this.availableModes)if(i.id.toLowerCase()===t||i.name.toLowerCase()===t)return i.id;return""}pickPermissionOptionId(e,t){if(t.length===0)return"";if(e==="deny"){for(const s of t)if(s.kind==="reject_once"||s.kind==="reject_always")return s.optionId;for(const s of t)if(s.kind.toLowerCase().includes("reject")||s.kind.toLowerCase().includes("deny"))return s.optionId;for(const s of t)if(s.name.toLowerCase().includes("reject")||s.name.toLowerCase().includes("deny"))return s.optionId;return t[t.length-1].optionId}const i=e==="allow-always"?"allow_always":e==="allow-once"?"allow_once":null;if(i){for(const s of t)if(s.kind===i)return s.optionId}for(const s of t)if(s.kind.toLowerCase().includes("allow"))return s.optionId;for(const s of t)if(s.name.toLowerCase().includes("allow"))return s.optionId;return t[0].optionId}buildPermissionResult(e,t){return e==="deny"?t?{outcome:{outcome:"selected",optionId:t}}:{outcome:{outcome:"cancelled"}}:t?{outcome:{outcome:"selected",optionId:t}}:{outcome:{outcome:"cancelled"}}}}export{y as ACP_NEW_SESSION_RESERVED_KEYS,f as AcpAuthRequiredError,m as AcpClient,g as isAuthRequiredError};
|
|
@@ -7983,7 +7983,8 @@ function mapDshSessionEvent(event) {
|
|
|
7983
7983
|
const blocks = Array.isArray(message.content) ? message.content : [];
|
|
7984
7984
|
const hasToolCall = blocks.some((item) => item && typeof item === "object" && String(item.type ?? "") === "tool-call");
|
|
7985
7985
|
const content = Array.isArray(message.content) ? blocks.filter((item) => item && typeof item === "object" && String(item.type ?? "") === "text").map((item) => String(item.text ?? "")).join("") : String(message.content ?? message.text ?? "");
|
|
7986
|
-
|
|
7986
|
+
const reasoning = blocks.filter((item) => item && typeof item === "object" && String(item.type ?? "") === "reasoning").map((item) => String(item.text ?? "")).join("");
|
|
7987
|
+
return { kind: "text", text: content, reasoning, usage: message.usage ?? data.usage, payload: { committed: true, hasToolCall } };
|
|
7987
7988
|
}
|
|
7988
7989
|
if (event.type === "request/context") {
|
|
7989
7990
|
return {
|
package/openclaw-plugin/index.js
CHANGED
|
@@ -187,6 +187,9 @@ function computeAibotSendThrottleDelayMs(sentAtMs, nowMs, limit = resolveAibotSe
|
|
|
187
187
|
// src/core/protocol/protocol-text.ts
|
|
188
188
|
var AIBOT_PROTOCOL_MAX_RUNES = 16 * 1024;
|
|
189
189
|
var AIBOT_PROTOCOL_MAX_BYTES = 12 * 1024;
|
|
190
|
+
var AIBOT_PROTOCOL_MAX_MESSAGE_RUNES = 64 * 1024;
|
|
191
|
+
var AIBOT_PROTOCOL_MAX_EXTRA_BYTES = 32 * 1024;
|
|
192
|
+
var AIBOT_PROTOCOL_MAX_PACKET_BYTES = 1 << 20;
|
|
190
193
|
var DEFAULT_OUTBOUND_TEXT_CHUNK_LIMIT = 1200;
|
|
191
194
|
var DEFAULT_STREAM_CHUNK_LIMIT = 48;
|
|
192
195
|
function normalizePositiveInt(value, fallbackValue) {
|
|
@@ -206,10 +209,8 @@ function resolveStreamTextChunkLimit(value) {
|
|
|
206
209
|
normalizePositiveInt(value, DEFAULT_STREAM_CHUNK_LIMIT)
|
|
207
210
|
);
|
|
208
211
|
}
|
|
209
|
-
function
|
|
210
|
-
const source = String(text ?? "");
|
|
212
|
+
function splitText(source, runeLimit, byteLimit) {
|
|
211
213
|
if (!source) return [];
|
|
212
|
-
const runeLimit = resolveOutboundTextChunkLimit(preferredRunes, DEFAULT_OUTBOUND_TEXT_CHUNK_LIMIT);
|
|
213
214
|
const chunks = [];
|
|
214
215
|
let current = "";
|
|
215
216
|
let currentRunes = 0;
|
|
@@ -218,7 +219,7 @@ function splitTextForAibotProtocol(text, preferredRunes) {
|
|
|
218
219
|
const runeBytes = Buffer.byteLength(rune, "utf8");
|
|
219
220
|
const nextRunes = currentRunes + 1;
|
|
220
221
|
const nextBytes = currentBytes + runeBytes;
|
|
221
|
-
if (current && (nextRunes > runeLimit || nextBytes >
|
|
222
|
+
if (current && (nextRunes > runeLimit || byteLimit !== void 0 && nextBytes > byteLimit)) {
|
|
222
223
|
chunks.push(current);
|
|
223
224
|
current = "";
|
|
224
225
|
currentRunes = 0;
|
|
@@ -231,6 +232,11 @@ function splitTextForAibotProtocol(text, preferredRunes) {
|
|
|
231
232
|
if (current) chunks.push(current);
|
|
232
233
|
return chunks;
|
|
233
234
|
}
|
|
235
|
+
function splitTextForAibotProtocol(text, preferredRunes) {
|
|
236
|
+
const source = String(text ?? "");
|
|
237
|
+
const runeLimit = resolveOutboundTextChunkLimit(preferredRunes, DEFAULT_OUTBOUND_TEXT_CHUNK_LIMIT);
|
|
238
|
+
return splitText(source, runeLimit, AIBOT_PROTOCOL_MAX_BYTES);
|
|
239
|
+
}
|
|
234
240
|
|
|
235
241
|
// src/openclaw/shared/file-listing/handler.ts
|
|
236
242
|
import * as os2 from "node:os";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grix-connector",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Connect local AI coding agents (Claude, Codex, Gemini, Qwen, DeepSeek, Cursor, OpenCode, Pi, OpenHuman, Reasonix) to the Grix scheduling platform. Also serves as an OpenClaw plugin for Grix channel transport.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
Binary file
|