aws-runtime-bridge 1.9.171 → 1.9.175
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/CHANGELOG.md +171 -0
- package/dist/adapter/AcodeSdkAdapter.d.ts +11 -13
- package/dist/adapter/AcodeSdkAdapter.js +3 -3
- package/dist/adapter/ClaudeSdkAdapter.d.ts +2 -0
- package/dist/adapter/ClaudeSdkAdapter.js +3 -3
- package/dist/adapter/types.d.ts +6 -7
- package/dist/index.js +1 -1
- package/dist/routes/bridge-temp-files.d.ts +1 -0
- package/dist/routes/bridge-temp-files.js +2 -0
- package/dist/routes/dashboard.js +35 -5
- package/dist/routes/file-browser.d.ts +4 -10
- package/dist/routes/file-browser.js +1 -1
- package/dist/routes/git.d.ts +42 -0
- package/dist/routes/git.js +34 -34
- package/dist/routes/sessions.js +1 -1
- package/dist/routes/tech-stack.d.ts +2 -0
- package/dist/routes/tech-stack.js +2 -0
- package/dist/routes/terminal.d.ts +8 -0
- package/dist/routes/terminal.js +27 -27
- package/dist/services/agent-pty-manager.d.ts +2 -0
- package/dist/services/agent-pty-manager.js +5 -4
- package/dist/services/agent-startup-memory.js +4 -4
- package/dist/services/bridge-temp-files.d.ts +36 -0
- package/dist/services/bridge-temp-files.js +2 -0
- package/dist/services/fileSnapshotStore.d.ts +9 -0
- package/dist/services/fileSnapshotStore.js +1 -1
- package/dist/services/gitignore.d.ts +12 -0
- package/dist/services/gitignore.js +2 -0
- package/dist/services/log-retention.js +1 -1
- package/dist/services/open-doc-events.d.ts +21 -0
- package/dist/services/open-doc-events.js +2 -0
- package/dist/services/open-doc-registry.d.ts +24 -0
- package/dist/services/open-doc-registry.js +2 -0
- package/dist/services/request-invalid-dump.js +1 -1
- package/dist/services/runtime-resources-snapshot.js +2 -2
- package/dist/services/session-output.d.ts +2 -0
- package/dist/services/session-output.js +2 -2
- package/dist/services/snapshot-retention.d.ts +7 -0
- package/dist/services/snapshot-retention.js +2 -0
- package/dist/services/tech-stack-scanner.d.ts +31 -0
- package/dist/services/tech-stack-scanner.js +2 -0
- package/dist/services/tunnel-client.d.ts +42 -0
- package/dist/services/tunnel-client.js +1 -1
- package/dist/services/workspaceTaskChangeWatcher.js +2 -2
- package/package/acode/dist/__tests__/summary-request-helper.d.ts +2 -0
- package/package/acode/dist/__tests__/summary-request-helper.js +2 -0
- package/package/acode/dist/ask-user-question-tool.d.ts +11 -1
- package/package/acode/dist/ask-user-question-tool.js +3 -3
- package/package/acode/dist/built-in-file-tools.js +2 -2
- package/package/acode/dist/cache-control.d.ts +26 -0
- package/package/acode/dist/cache-control.js +2 -0
- package/package/acode/dist/compaction.d.ts +174 -32
- package/package/acode/dist/compaction.js +22 -6
- package/package/acode/dist/microcompact.d.ts +57 -0
- package/package/acode/dist/microcompact.js +2 -0
- package/package/acode/dist/runtime-environment.js +1 -1
- package/package/acode/dist/runtime.d.ts +17 -4
- package/package/acode/dist/runtime.js +50 -40
- package/package/acode/dist/token-estimator.d.ts +15 -0
- package/package/acode/dist/token-estimator.js +2 -0
- package/package/acode/dist/types.d.ts +14 -1
- package/package/aws-client-agent-mcp/dist/ability-market-tools.js +1 -1
- package/package/aws-client-agent-mcp/dist/agent-client.d.ts +15 -2
- package/package/aws-client-agent-mcp/dist/agent-client.js +1 -1
- package/package/aws-client-agent-mcp/dist/mcp-server.d.ts +5 -0
- package/package/aws-client-agent-mcp/dist/mcp-server.js +25 -23
- package/package/aws-client-agent-mcp/dist/mcp-tools.js +7 -7
- package/package/aws-client-agent-mcp/dist/memory-store.d.ts +21 -2
- package/package/aws-client-agent-mcp/dist/memory-store.js +27 -2
- package/package/aws-client-agent-mcp/dist/memory-tools.js +13 -9
- package/package/aws-client-agent-mcp/dist/server-memory-store.d.ts +1 -1
- package/package/aws-client-agent-mcp/dist/server-memory-store.js +1 -1
- package/package/aws-client-agent-mcp/dist/types.d.ts +51 -0
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export declare const ESTIMATION_CJK_CHARS_PER_TOKEN = 1.5;
|
|
4
|
+
|
|
5
|
+
export declare const ESTIMATION_ASCII_CHARS_PER_TOKEN = 4;
|
|
6
|
+
|
|
7
|
+
export declare const ESTIMATION_SAFE_PADDING = 1.15;
|
|
8
|
+
|
|
9
|
+
export declare const ESTIMATION_IMAGE_TOKENS = 2000;
|
|
10
|
+
|
|
11
|
+
export declare const ESTIMATION_TOOL_OVERHEAD = 8;
|
|
12
|
+
|
|
13
|
+
export declare function estimateTextTokens(text: string): number;
|
|
14
|
+
|
|
15
|
+
export declare function estimateTokens(text: string): number;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const E=1.5,o=4,A=1.15,n=2e3,S=8;function e(t){if(!t)return 0;let T=0,_=0;for(const I of t)I>"\xFF"?T++:_++;return Math.ceil(T/1.5+_/4)}function r(t){return t?Math.ceil(e(t)*1.15):0}export{o as ESTIMATION_ASCII_CHARS_PER_TOKEN,E as ESTIMATION_CJK_CHARS_PER_TOKEN,n as ESTIMATION_IMAGE_TOKENS,A as ESTIMATION_SAFE_PADDING,S as ESTIMATION_TOOL_OVERHEAD,e as estimateTextTokens,r as estimateTokens};
|
|
2
|
+
|
|
@@ -65,7 +65,7 @@ export interface ACodeSkillGroup {
|
|
|
65
65
|
exists: boolean;
|
|
66
66
|
skills: ACodeSkillMetadata[];
|
|
67
67
|
}
|
|
68
|
-
export type ACodeEventType = "session_started" | "startup_phase" | "ai_request" | "iteration_usage" | "thinking_delta" | "assistant_delta" | "command_output" | "command_status" | "mcp_status" | "skill_status" | "warning" | "turn_complete" | "session_complete" | "context_compaction" | "question_request" | "tool_permission_request" | "error" | "background_command_completed";
|
|
68
|
+
export type ACodeEventType = "session_started" | "startup_phase" | "ai_request" | "iteration_usage" | "thinking_delta" | "assistant_delta" | "command_output" | "command_status" | "mcp_status" | "skill_status" | "warning" | "turn_complete" | "session_complete" | "context_compaction" | "compaction_summary" | "question_request" | "tool_permission_request" | "error" | "background_command_completed";
|
|
69
69
|
export interface ACodeEvent {
|
|
70
70
|
type: ACodeEventType;
|
|
71
71
|
sessionId: string;
|
|
@@ -195,4 +195,17 @@ export interface ACodeResolvedProviderConfig {
|
|
|
195
195
|
inputLimit?: number;
|
|
196
196
|
|
|
197
197
|
maxOutput?: number;
|
|
198
|
+
|
|
199
|
+
cacheControlMode?: "off" | "message" | "content-block";
|
|
200
|
+
|
|
201
|
+
microcompact?: {
|
|
202
|
+
|
|
203
|
+
enabled?: boolean;
|
|
204
|
+
|
|
205
|
+
thresholdTokens?: number;
|
|
206
|
+
|
|
207
|
+
keepRecentToolResults?: number;
|
|
208
|
+
|
|
209
|
+
minTokenSavings?: number;
|
|
210
|
+
};
|
|
198
211
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={name:"list_ability_market",description:"\u6D4F\u89C8\u80FD\u529B\u5E02\u573A\uFF08\u5BF9\u5F53\u524D\u8EAB\u4EFD\u53EF\u89C1\u7684 system + \u672C\u79DF\u6237\u6A21\u677F\uFF09\u3002\u8FD4\u56DE\u7D27\u51D1\u76EE\u5F55\uFF1Akind/name/displayName/description/transport/packageFileName/visibility/envSchema/installed\u3002envSchema \u5217\u51FA\u8BE5\u5236\u54C1\u53EF\u914D\u7F6E\u7684\u73AF\u5883\u53D8\u91CF\uFF08key/required/sensitive/description/example\uFF09\uFF0CMCP \u901A\u5E38\u9700\u8981\u5728\u5B89\u88C5\u65F6\u914D\u7F6E\uFF08API Key\u3001\u5165\u53E3\u8DEF\u5F84\u7B49\uFF09\u3002\u627E\u5230\u76EE\u6807\u540E\u7528 install_ability_market_item \u5B89\u88C5\uFF0C\u5E76\u628A envSchema \u4E2D\u7684\u53D6\u503C\u901A\u8FC7 env \u53C2\u6570\u4F20\u5165\uFF1B\u654F\u611F\u9879\uFF08sensitive=true\uFF09\u5982\u5BC6\u7801/API Key \u5FC5\u987B\u7531\u7528\u6237\u63D0\u4F9B\uFF0C\u5207\u52FF\u81EA\u884C\u731C\u6D4B\u6216\u4ECE\u5176\u5B83\u6765\u6E90\u63A8\u65AD\u3002",inputSchema:{type:"object",properties:{kind:{type:"string",enum:["mcp","skill","plugin"],description:"\u53EF\u9009\uFF1A\u6309\u5E02\u573A\u5236\u54C1\u7C7B\u578B\u8FC7\u6EE4"},keyword:{type:"string",description:"\u53EF\u9009\uFF1A\u6309\u540D\u79F0/\u5C55\u793A\u540D/\u8BF4\u660E\u6A21\u7CCA\u8FC7\u6EE4"},limit:{type:"number",description:"\u53EF\u9009\uFF1A\u8FD4\u56DE\u6761\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4 20\uFF0C\u6700\u5927 100\uFF09"}},required:[]}},i={name:"install_ability_market_item",description:"\u628A\u5E02\u573A\u4E2D\u7684 MCP\u3001Skill \u6216 Plugin \u5B89\u88C5\u5230\u6307\u5B9A\u843D\u70B9\uFF08scope\uFF09\uFF1Ainstance\uFF08\u4EC5\u5728\u663E\u5F0F\u6307\u5B9A\u65F6\u4F7F\u7528\uFF09= \u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\uFF0C\u5199\u5165\u7528\u6237\u5B9E\u4F8B\u6A21\u677F\u5E76\u521D\u59CB\u5316\u6240\u5728 bridge\uFF0C\u7ACB\u5373\u751F\u6548\uFF1Bglobal = \u53EA\u767B\u8BB0\u5230\u4F60\u7684\u300C\u5168\u5C40\u914D\u7F6E\u6A21\u677F\u300D\uFF08\u5B9E\u4F8B\u6A21\u677F\u76EE\u5F55\uFF09\uFF0C\u9ED8\u8BA4\u4E0D\u53C2\u4E0E\u5B9E\u4F8B\u521D\u59CB\u5316\uFF0C\u9700\u7528\u6237\u5728\u300C\u5168\u5C40\u914D\u7F6E \u2192 \u5B9E\u4F8B\u6A21\u677F\u300D\u5F00\u542F\u8BE5\u9879\u5F00\u5173\u540E\u624D\u968F\u521D\u59CB\u5316\u4E0B\u53D1\uFF08\u9002\u5408\u5148\u5728\u6A21\u677F\u4E2D\u96C6\u4E2D\u7BA1\u7406\u3001\u7A0D\u540E\u7EDF\u4E00\u542F\u7528\uFF09\uFF1Bprivate = \u4EC5\u5B89\u88C5\u5230\u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\uFF0C\u5176\u5B83\u89D2\u8272\u5B9E\u4F8B\u4E0D\u53EF\u89C1\uFF08\u9002\u5408\u81EA\u7814\u5236\u54C1\u300C\u53EA\u7ED9\u81EA\u5DF1\u7528\u300D\uFF09\u3002scope=instance \u65F6\u540C\u65F6\u5199\u5165\u5B9E\u4F8B\u80FD\u529B\u8986\u76D6\uFF0C\u5931\u8D25\u4F1A\u56DE\u6EDA\u6A21\u677F\u3001\u80FD\u529B\u548C bridge \u521D\u59CB\u5316\u3002env \u7528\u4E8E\u914D\u7F6E\u73AF\u5883\u53D8\u91CF\uFF08\u8303\u56F4=\u5F53\u524D\u5B9E\u4F8B\uFF09\uFF1A\u53EA\u9700\u63D0\u4F9B list_ability_market \u8FD4\u56DE\u7684 envSchema \u4E2D\u7684\u952E\uFF0C\u53D6\u503C\u5FC5\u987B\u7531\u7528\u6237\u63D0\u4F9B\uFF08\u5C24\u5176\u662F sensitive \u9879\uFF09\uFF0C\u4E0D\u8981\u4ECE\u5176\u5B83\u6765\u6E90\u63A8\u65AD\u6216\u590D\u7528\uFF1B\u91CD\u590D\u5B89\u88C5\u540C\u4E00\u5236\u54C1\u5373\u66F4\u65B0\u5176 env\u3002\u6210\u529F\u540E\u8FD4\u56DE templateConfig\u3001\u751F\u6548\u72B6\u6001\u3001\u53EF\u7528\u5DE5\u5177\u53CA\u8C03\u7528\u65B9\u5F0F\uFF1BMCP \u9ED8\u8BA4\u6536\u7EB3\uFF0C\u9700\u7ECF expand_tools \u5C55\u5F00\u540E\u7528 call_tool \u8C03\u7528\u3002\u6210\u529F\u72B6\u6001\u4E3A bridge-initialized\uFF0C\u8868\u793A\u6A21\u677F\u521D\u59CB\u5316\u4E0E\u80FD\u529B\u540C\u6B65\u5DF2\u5B8C\u6210\uFF0C\u53EF\u76F4\u63A5\u5C1D\u8BD5\u8C03\u7528\uFF1B\u4E0D\u8981\u5728\u540C\u4E00\u4F1A\u8BDD\u5185\u53CD\u590D\u91CD\u8BD5\u3002\u82E5\u6A21\u677F\u58F0\u660E\u4E86\u5FC5\u586B\u73AF\u5883\u53D8\u91CF\uFF0C\u8C03\u7528\u524D\u5FC5\u987B\u5148\u4ECE\u7528\u6237\u5904\u53D6\u5F97\u8FD9\u4E9B\u503C\uFF08\u7F3A\u53C2\u65F6\u5DE5\u5177\u4F1A\u8FD4\u56DE errorCode=MCP_ENV_REQUIRED \u4E0E\u7F3A\u5931\u952E\u540D\uFF09\u3002",inputSchema:{type:"object",properties:{template:{type:"string",description:"\u5E02\u573A\u9879 id \u6216 name\uFF08list_ability_market \u8FD4\u56DE\u503C\u4E2D\u7684 name \u5B57\u6BB5\uFF09"},kind:{type:"string",enum:["mcp","skill","plugin"],description:"\u53EF\u9009\uFF1A\u5E02\u573A\u5236\u54C1\u7C7B\u578B\uFF0C\u7528\u4E8E\u540C\u540D\u9879\u6D88\u6B67"},scope:{type:"string",enum:["instance","global","private"],description:"\u53EF\u9009\uFF1A\u5B89\u88C5\u843D\u70B9\u3002instance = \u5F53\u524D\u6240\u5728\u89D2\u8272\u5B9E\u4F8B\uFF08\u7ACB\u5373\u751F\u6548\uFF09\uFF1Bglobal = \u53EA\u767B\u8BB0\u5230\u5168\u5C40\u914D\u7F6E\u6A21\u677F\uFF0C\u9ED8\u8BA4\u4E0D\u53C2\u4E0E\u5B9E\u4F8B\u521D\u59CB\u5316\uFF08\u5F85\u7528\u6237\u5728\u300C\u5168\u5C40\u914D\u7F6E \u2192 \u5B9E\u4F8B\u6A21\u677F\u300D\u5F00\u542F\u5F00\u5173\u540E\u751F\u6548\uFF09\uFF1Bprivate = \u4EC5\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\u3001\u5176\u5B83\u5B9E\u4F8B\u4E0D\u53EF\u89C1\u3002"},env:{type:"object",description:"\u73AF\u5883\u53D8\u91CF\u53D6\u503C { KEY: value }\uFF0C\u8303\u56F4=\u5F53\u524D\u5B9E\u4F8B\u3002\u4EC5\u9700\u63D0\u4F9B envSchema \u4E2D\u7684\u952E\uFF1B\u4EC5 MCP \u4F7F\u7528\uFF1B\u654F\u611F\u503C\u7531\u7528\u6237\u63D0\u4F9B\uFF0C\u4E0D\u8981\u4ECE\u5176\u5B83\u6765\u6E90\u63A8\u65AD\u6216\u590D\u7528\u3002",additionalProperties:{type:"string"}},collapsed:{type:"boolean",description:"\u53EF\u9009\uFF1A\u4EC5 MCP\uFF0C\u662F\u5426\u6536\u7EB3\uFF08\u9ED8\u8BA4\u53D6\u6A21\u677F\u8BBE\u7F6E\uFF0C\u901A\u5E38\u4E3A true\uFF09\u3002true=\u5DE5\u5177\u9ED8\u8BA4\u9690\u85CF\uFF0C\u9700 expand_tools \u5C55\u5F00"}},required:["template"]}},t={name:"uninstall_ability_market_item",description:"\u4ECE\u300C\u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\u300D\u5378\u8F7D\u6307\u5B9A\u5E02\u573A\u9879\uFF1A\u4ECE\u7528\u6237\u5B9E\u4F8B\u6A21\u677F\u79FB\u9664\u914D\u7F6E\u3001\u6E05\u5B9E\u4F8B\u80FD\u529B\u8986\u76D6\u5E76\u91CD\u65B0\u521D\u59CB\u5316 bridge\u3002\u4E0D\u5F71\u54CD\u5E02\u573A\u9879\u672C\u8EAB\u6216\u540C bridge \u4E0A\u5176\u5B83\u5B9E\u4F8B\uFF1B\u6210\u529F\u540E\u8FD0\u884C\u4E2D\u5B9E\u4F8B\u7ACB\u5373\u505C\u6B62\u52A0\u8F7D\u8BE5\u9879\u3002\u5185\u7F6E\u901A\u8BAF MCP\uFF08agents-work-studio\u3001aws-mcp\u3001aws-mcp-dev\uFF09\u4E0D\u53EF\u5378\u8F7D\u3002",inputSchema:{type:"object",properties:{template:{type:"string",description:"\u5E02\u573A\u9879 id \u6216 name"},kind:{type:"string",enum:["mcp","skill","plugin"],description:"\u5E02\u573A\u5236\u54C1\u7C7B\u578B"}},required:["template","kind"]}},n=new Set(["list_ability_market","install_ability_market_item","uninstall_ability_market_item"]),p=new Set(["ability_dev_ide","formal_ability","list_my_abilities"]),l={name:"ability_dev_ide",description:"\u80FD\u529B\u5F00\u53D1 IDE\u2014\u2014\u81EA\u7814 MCP / \u63D2\u4EF6 / Skill \u7684\u7EDF\u4E00\u5165\u53E3\u3002action\uFF1Aguide=\u8BFB\u53D6\u5185\u7F6E\u5F00\u53D1\u6307\u5357\u539F\u6587\uFF08Markdown\uFF0C\u53EA\u8BFB\uFF1Bkind=plugin|mcp|skill\uFF0C\u7F3A\u7701 plugin\uFF09\uFF0C\u7F16\u5199/\u6539\u9020\u524D\u5148\u53D6\u6743\u5A01\u89C4\u8303\uFF08\u76EE\u5F55\u7ED3\u6784\u3001\u6E05\u5355\u5B57\u6BB5\u3001stdio \u534F\u8BAE\u7EA6\u5B9A\u3001\u5DE5\u5177\u4E0E\u76D1\u542C\u5668\u58F0\u660E\u3001\u6253\u5305\u4E0E\u5B89\u88C5\uFF09\uFF0C\u4E0D\u8981\u51ED\u8BB0\u5FC6\u731C\u6D4B\u6E05\u5355\u683C\u5F0F\u6216\u534F\u8BAE\u5E27\u683C\u5F0F\uFF1Bmount=\u628A\u5DE5\u4F5C\u533A\u5185\u6B63\u5728\u5F00\u53D1\u7684 MCP/\u63D2\u4EF6\u4E34\u65F6\u6302\u5230\u5F53\u524D\u4F1A\u8BDD\u8BD5\u7528\uFF08kind=mcp \u65F6 path \u6307\u5411\u5DE5\u4F5C\u533A\u5185 mcp.json \u6587\u4EF6\u6216\u5176\u5305\u76EE\u5F55\uFF1Bkind=plugin \u65F6 path \u6307\u5411\u542B plugin.json \u7684\u63D2\u4EF6\u76EE\u5F55\uFF1B\u6302\u8F7D\u540E\u6587\u4EF6\u53D8\u66F4\u81EA\u52A8\u91CD\u8F7D\uFF0C\u6539\u4EE3\u7801\u540E\u53EF\u91CD\u65B0 mount \u540C\u4E00\u8DEF\u5F84\u751F\u6548\uFF09\uFF1Bunmount=\u6458\u9664\u4E00\u4E2A\u6302\u8F7D\u9879\uFF08kind+name\uFF09\uFF1Blist=\u67E5\u770B\u5F53\u524D\u6302\u8F7D\u9879\uFF0C\u6BCF\u9879\u542B name/path/mounted/toolCount/tools/error\uFF08mounted=false \u8868\u793A\u672A\u6210\u529F\u6302\u8F7D\uFF0Cerror \u4E3A\u5931\u8D25\u539F\u56E0\uFF1BMCP \u5DE5\u5177\u540D\u5F62\u5982 <server>__<tool>\uFF0C\u53EF\u7528 call_tool \u8C03\u7528\uFF09\uFF1Blogs=\u8BFB\u53D6\u67D0\u6302\u8F7D\u9879\u6700\u8FD1\u8FD0\u884C\u65E5\u5FD7\uFF08kind+name\uFF0C\u53EF\u9009 tail\uFF1BMCP \u4E3A\u5B50\u8FDB\u7A0B stderr \u73AF\u5F62\u7F13\u51B2\uFF0C\u63D2\u4EF6\u4E3A\u8FD0\u884C\u65E5\u5FD7\uFF09\uFF0C\u7528\u4E8E\u6392\u67E5\u300C\u6302\u8F7D\u540E\u6CA1\u6709\u5DE5\u5177 / \u8C03\u7528\u62A5\u9519 / \u5B50\u8FDB\u7A0B\u5361\u6B7B\u300D\u3002mount/unmount/logs \u7684 path/name \u5FC5\u987B\u4F4D\u4E8E\u4F60\u81EA\u5DF1\u7684\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u5185\uFF0C\u8C03\u8BD5\u6302\u8F7D\u4E0D\u6301\u4E45\u5316\uFF08bridge \u91CD\u542F\u5373\u5931\u6548\uFF09\uFF1BSkill \u65E0\u8C03\u8BD5\u6001\uFF0C\u8BFB\u89C4\u8303\u540E\u76F4\u63A5\u7528 formal_ability \u6216 install_ability_market_item\u3002\u6CE8\u610F\uFF1A\u6302\u8F7D\u5931\u8D25\u4E0D\u4F1A\u51FA\u73B0\u5728 list \u4E2D\uFF08mount \u54CD\u5E94\u76F4\u63A5\u8FD4\u56DE mounted=false \u4E0E error\uFF09\uFF0C\u67E5\u4E0D\u5230\u4E0D\u4EE3\u8868\u6CA1\u5C1D\u8BD5\u8FC7\u3002",inputSchema:{type:"object",properties:{action:{type:"string",enum:["guide","mount","unmount","list","logs"],description:"\u5F00\u53D1\u52A8\u4F5C"},kind:{type:"string",enum:["plugin","mcp","skill"],description:"guide\uFF1A\u89C4\u8303\u7C7B\u578B\uFF08plugin|mcp|skill\uFF0C\u7F3A\u7701 plugin\uFF09\uFF1Bmount/unmount/logs\uFF1A\u5236\u54C1\u7C7B\u578B\uFF08\u4EC5 mcp|plugin\uFF0C\u5FC5\u586B\uFF09\uFF1Blist\uFF1A\u53EF\u9009\u8FC7\u6EE4\uFF08\u7F3A\u7701\u5217\u51FA\u5168\u90E8\uFF09"},path:{type:"string",description:"\u4EC5 mount\uFF1A\u5DE5\u4F5C\u533A\u5185\u8DEF\u5F84\u3002kind=mcp \u4E3A mcp.json \u6587\u4EF6\u6216\u5176\u5305\u76EE\u5F55\uFF1Bkind=plugin \u4E3A\u542B plugin.json \u7684\u63D2\u4EF6\u76EE\u5F55\u3002\u652F\u6301\u76F8\u5BF9\u5DE5\u4F5C\u533A\u7684\u76F8\u5BF9\u8DEF\u5F84\u3002"},name:{type:"string",description:"\u8C03\u8BD5\u9879\u540D\uFF08unmount/logs \u5FC5\u586B\uFF1Bmount \u65F6 MCP \u53EF\u9009\u3001\u7F3A\u7701\u53D6\u8DEF\u5F84 basename\uFF0C\u63D2\u4EF6\u4EE5 plugin.json \u4E3A\u51C6\uFF09"},tail:{type:"number",description:"\u4EC5 logs\uFF1A\u8FD4\u56DE\u6700\u8FD1 N \u884C\uFF08\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 500\uFF09"}},required:["action"]}},s={name:"formal_ability",description:"\u628A\u5F00\u53D1\u597D\u7684\u5236\u54C1\u8F6C\u6B63\uFF08\u6301\u4E45\u5316\u5B89\u88C5\uFF09\u3002kind=mcp|plugin \u65F6\u4F20 path\uFF08\u5DE5\u4F5C\u533A\u5185\u5DF2\u8C03\u8BD5\u597D\u7684\u5236\u54C1\u8DEF\u5F84\uFF09\uFF0C\u670D\u52A1\u7AEF\u6253\u5305\u5E76\u8D70\u80FD\u529B\u5E02\u573A\u5B89\u88C5\u6D41\u7A0B\uFF1Bkind=skill \u65F6\u4F20 path\uFF08\u5DE5\u4F5C\u533A\u5185\u542B SKILL.md \u7684\u76EE\u5F55\uFF09\uFF0C\u76F4\u63A5\u6253\u5305\u767B\u8BB0\u5E76\u5B89\u88C5\uFF08Skill \u65E0\u8C03\u8BD5\u6001\uFF0C\u4E0D\u9700\u8981\u6302\u8F7D\uFF09\u3002scope \u7F3A\u7701\u4E3A global\uFF1A\u53EA\u767B\u8BB0\u5230\u300C\u5168\u5C40\u914D\u7F6E \u2192 \u5B9E\u4F8B\u6A21\u677F\u300D\u4E14 instantiate=false\uFF08\u9ED8\u8BA4\u5173\u95ED\u3001\u4E0D\u53C2\u4E0E\u5B9E\u4F8B\u521D\u59CB\u5316\uFF09\uFF0C\u9700\u7528\u6237\u5728\u9762\u677F\u5F00\u542F\u8BE5\u9879\u5F00\u5173\u540E\u624D\u968F\u521D\u59CB\u5316\u4E0B\u53D1\u2014\u2014\u8F6C\u6B63\u6210\u529F\u540E\u5E76\u4E0D\u7B49\u4E8E\u5F53\u524D\u5B9E\u4F8B\u5DF2\u751F\u6548\u3002\u663E\u5F0F\u4F20 scope=instance \u624D\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\u5E76\u7ACB\u5373\u751F\u6548\uFF1Bscope=private \u4EC5\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\u3001\u5176\u5B83\u5B9E\u4F8B\u4E0D\u53EF\u89C1\u3002",inputSchema:{type:"object",properties:{kind:{type:"string",enum:["mcp","plugin","skill"],description:"\u5236\u54C1\u7C7B\u578B"},path:{type:"string",description:"\u5DE5\u4F5C\u533A\u5185\u5236\u54C1\u8DEF\u5F84\uFF1Akind=mcp|plugin \u4E3A\u5DF2\u8C03\u8BD5\u597D\u7684\u5236\u54C1\u76EE\u5F55\uFF08MCP \u5305\u76EE\u5F55 / \u63D2\u4EF6\u76EE\u5F55\uFF09\uFF1Bkind=skill \u4E3A\u542B SKILL.md \u7684\u76EE\u5F55\u3002"},name:{type:"string",description:"\u53EF\u9009\uFF1A\u5236\u54C1\u540D\uFF08\u7F3A\u7701\u4ECE\u6E05\u5355\u6216 SKILL.md \u8BFB\u53D6\uFF09"},scope:{type:"string",enum:["global","instance","private"],description:"\u53EF\u9009\uFF1A\u5B89\u88C5\u843D\u70B9\uFF0C\u7F3A\u7701 global\uFF08\u53EA\u5165\u5168\u5C40\u914D\u7F6E\u6A21\u677F\u3001\u521D\u59CB\u5316\u5173\u95ED\uFF09\uFF1Binstance=\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\u7ACB\u5373\u751F\u6548\uFF1Bprivate=\u4EC5\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\u3001\u5176\u5B83\u5B9E\u4F8B\u4E0D\u53EF\u89C1"}},required:["kind","path"]}},a={name:"list_my_abilities",description:"\u67E5\u8BE2\u300C\u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\u300D\u5F53\u524D\u7684\u5168\u90E8\u80FD\u529B\u72B6\u6001\uFF08\u53EA\u8BFB\uFF09\u3002\u8FD4\u56DE\uFF1Amcp / skills / plugins\uFF08\u540D\u79F0\u3001\u542F\u7528\u72B6\u6001\u3001\u6765\u6E90\u5C42\u7EA7\uFF1B\u63D2\u4EF6\u53E6\u542B\u8FD0\u884C\u6001\u4E0E\u5DE5\u5177\u6570\uFF09\u3001tools\uFF08\u529F\u80FD\u5F00\u5173\u7684\u6709\u6548\u4E09\u6001\uFF1Adisabled/collapsed/expanded\uFF09\u3001debugMounts\uFF08\u5F53\u524D\u4F1A\u8BDD\u7684\u8C03\u8BD5\u6302\u8F7D\u9879\uFF0C\u4E0E\u6301\u4E45\u5316\u5B89\u88C5\u9694\u79BB\uFF09\u3002\u7528\u4E8E\u81EA\u7BA1\u7406\uFF1A\u786E\u8BA4\u5DF2\u5B89\u88C5\u80FD\u529B\u3001\u53D1\u73B0\u91CD\u590D\u5B89\u88C5\u3001\u8BC6\u522B\u4E0D\u7528\u7684\u80FD\u529B\u540E\u7528 uninstall_ability_market_item \u5378\u8F7D\u3002",inputSchema:{type:"object",properties:{},required:[]}};export{l as ABILITY_DEV_IDE_TOOL,p as ABILITY_DEV_TOOL_NAMES,n as ABILITY_MARKET_TOOL_NAMES,s as FORMAL_ABILITY_TOOL,i as INSTALL_ABILITY_MARKET_ITEM_TOOL,e as LIST_ABILITY_MARKET_TOOL,a as LIST_MY_ABILITIES_TOOL,t as UNINSTALL_ABILITY_MARKET_ITEM_TOOL};
|
|
1
|
+
const e={name:"list_ability_market",description:"\u6D4F\u89C8\u80FD\u529B\u5E02\u573A\uFF08\u5BF9\u5F53\u524D\u8EAB\u4EFD\u53EF\u89C1\u7684 system + \u672C\u79DF\u6237\u6A21\u677F\uFF09\u3002\u8FD4\u56DE\u7D27\u51D1\u76EE\u5F55\uFF1Akind/name/description/transport/packageFileName/visibility/envSchema/installed\u3002envSchema \u5217\u51FA\u8BE5\u5236\u54C1\u53EF\u914D\u7F6E\u7684\u73AF\u5883\u53D8\u91CF\uFF08key/required/sensitive/description/example\uFF09\uFF0CMCP \u901A\u5E38\u9700\u8981\u5728\u5B89\u88C5\u65F6\u914D\u7F6E\uFF08API Key\u3001\u5165\u53E3\u8DEF\u5F84\u7B49\uFF09\u3002\u627E\u5230\u76EE\u6807\u540E\u7528 install_ability_market_item \u5B89\u88C5\uFF0C\u5E76\u628A envSchema \u4E2D\u7684\u53D6\u503C\u901A\u8FC7 env \u53C2\u6570\u4F20\u5165\uFF1B\u654F\u611F\u9879\uFF08sensitive=true\uFF09\u5982\u5BC6\u7801/API Key \u5FC5\u987B\u7531\u7528\u6237\u63D0\u4F9B\uFF0C\u5207\u52FF\u81EA\u884C\u731C\u6D4B\u6216\u4ECE\u5176\u5B83\u6765\u6E90\u63A8\u65AD\u3002",inputSchema:{type:"object",properties:{kind:{type:"string",enum:["mcp","skill","plugin"],description:"\u53EF\u9009\uFF1A\u6309\u5E02\u573A\u5236\u54C1\u7C7B\u578B\u8FC7\u6EE4"},keyword:{type:"string",description:"\u53EF\u9009\uFF1A\u6309\u540D\u79F0/\u8BF4\u660E\u6A21\u7CCA\u8FC7\u6EE4"},limit:{type:"number",description:"\u53EF\u9009\uFF1A\u8FD4\u56DE\u6761\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4 20\uFF0C\u6700\u5927 100\uFF09"}},required:[]}},i={name:"install_ability_market_item",description:"\u628A\u5E02\u573A\u4E2D\u7684 MCP\u3001Skill \u6216 Plugin \u5B89\u88C5\u5230\u6307\u5B9A\u843D\u70B9\uFF08scope\uFF09\uFF1Ainstance\uFF08\u4EC5\u5728\u663E\u5F0F\u6307\u5B9A\u65F6\u4F7F\u7528\uFF09= \u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\uFF0C\u5199\u5165\u7528\u6237\u5B9E\u4F8B\u6A21\u677F\u5E76\u521D\u59CB\u5316\u6240\u5728 bridge\uFF0C\u7ACB\u5373\u751F\u6548\uFF1Bglobal = \u53EA\u767B\u8BB0\u5230\u4F60\u7684\u300C\u5168\u5C40\u914D\u7F6E\u6A21\u677F\u300D\uFF08\u5B9E\u4F8B\u6A21\u677F\u76EE\u5F55\uFF09\uFF0C\u9ED8\u8BA4\u4E0D\u53C2\u4E0E\u5B9E\u4F8B\u521D\u59CB\u5316\uFF0C\u9700\u7528\u6237\u5728\u300C\u5168\u5C40\u914D\u7F6E \u2192 \u5B9E\u4F8B\u6A21\u677F\u300D\u5F00\u542F\u8BE5\u9879\u5F00\u5173\u540E\u624D\u968F\u521D\u59CB\u5316\u4E0B\u53D1\uFF08\u9002\u5408\u5148\u5728\u6A21\u677F\u4E2D\u96C6\u4E2D\u7BA1\u7406\u3001\u7A0D\u540E\u7EDF\u4E00\u542F\u7528\uFF09\uFF1Bprivate = \u4EC5\u5B89\u88C5\u5230\u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\uFF0C\u5176\u5B83\u89D2\u8272\u5B9E\u4F8B\u4E0D\u53EF\u89C1\uFF08\u9002\u5408\u81EA\u7814\u5236\u54C1\u300C\u53EA\u7ED9\u81EA\u5DF1\u7528\u300D\uFF09\u3002scope=instance \u65F6\u540C\u65F6\u5199\u5165\u5B9E\u4F8B\u80FD\u529B\u8986\u76D6\uFF0C\u5931\u8D25\u4F1A\u56DE\u6EDA\u6A21\u677F\u3001\u80FD\u529B\u548C bridge \u521D\u59CB\u5316\u3002env \u7528\u4E8E\u914D\u7F6E\u73AF\u5883\u53D8\u91CF\uFF08\u8303\u56F4=\u5F53\u524D\u5B9E\u4F8B\uFF09\uFF1A\u53EA\u9700\u63D0\u4F9B list_ability_market \u8FD4\u56DE\u7684 envSchema \u4E2D\u7684\u952E\uFF0C\u53D6\u503C\u5FC5\u987B\u7531\u7528\u6237\u63D0\u4F9B\uFF08\u5C24\u5176\u662F sensitive \u9879\uFF09\uFF0C\u4E0D\u8981\u4ECE\u5176\u5B83\u6765\u6E90\u63A8\u65AD\u6216\u590D\u7528\uFF1B\u91CD\u590D\u5B89\u88C5\u540C\u4E00\u5236\u54C1\u5373\u66F4\u65B0\u5176 env\u3002\u6210\u529F\u540E\u8FD4\u56DE templateConfig\u3001\u751F\u6548\u72B6\u6001\u3001\u53EF\u7528\u5DE5\u5177\u53CA\u8C03\u7528\u65B9\u5F0F\uFF1BMCP \u9ED8\u8BA4\u6536\u7EB3\uFF0C\u9700\u7ECF expand_tools \u5C55\u5F00\u540E\u7528 call_tool \u8C03\u7528\u3002\u6210\u529F\u72B6\u6001\u4E3A bridge-initialized\uFF0C\u8868\u793A\u6A21\u677F\u521D\u59CB\u5316\u4E0E\u80FD\u529B\u540C\u6B65\u5DF2\u5B8C\u6210\uFF0C\u53EF\u76F4\u63A5\u5C1D\u8BD5\u8C03\u7528\uFF1B\u4E0D\u8981\u5728\u540C\u4E00\u4F1A\u8BDD\u5185\u53CD\u590D\u91CD\u8BD5\u3002\u82E5\u6A21\u677F\u58F0\u660E\u4E86\u5FC5\u586B\u73AF\u5883\u53D8\u91CF\uFF0C\u8C03\u7528\u524D\u5FC5\u987B\u5148\u4ECE\u7528\u6237\u5904\u53D6\u5F97\u8FD9\u4E9B\u503C\uFF08\u7F3A\u53C2\u65F6\u5DE5\u5177\u4F1A\u8FD4\u56DE errorCode=MCP_ENV_REQUIRED \u4E0E\u7F3A\u5931\u952E\u540D\uFF09\u3002",inputSchema:{type:"object",properties:{template:{type:"string",description:"\u5E02\u573A\u9879 id \u6216 name\uFF08list_ability_market \u8FD4\u56DE\u503C\u4E2D\u7684 name \u5B57\u6BB5\uFF09"},kind:{type:"string",enum:["mcp","skill","plugin"],description:"\u53EF\u9009\uFF1A\u5E02\u573A\u5236\u54C1\u7C7B\u578B\uFF0C\u7528\u4E8E\u540C\u540D\u9879\u6D88\u6B67"},scope:{type:"string",enum:["instance","global","private"],description:"\u53EF\u9009\uFF1A\u5B89\u88C5\u843D\u70B9\u3002instance = \u5F53\u524D\u6240\u5728\u89D2\u8272\u5B9E\u4F8B\uFF08\u7ACB\u5373\u751F\u6548\uFF09\uFF1Bglobal = \u53EA\u767B\u8BB0\u5230\u5168\u5C40\u914D\u7F6E\u6A21\u677F\uFF0C\u9ED8\u8BA4\u4E0D\u53C2\u4E0E\u5B9E\u4F8B\u521D\u59CB\u5316\uFF08\u5F85\u7528\u6237\u5728\u300C\u5168\u5C40\u914D\u7F6E \u2192 \u5B9E\u4F8B\u6A21\u677F\u300D\u5F00\u542F\u5F00\u5173\u540E\u751F\u6548\uFF09\uFF1Bprivate = \u4EC5\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\u3001\u5176\u5B83\u5B9E\u4F8B\u4E0D\u53EF\u89C1\u3002"},env:{type:"object",description:"\u73AF\u5883\u53D8\u91CF\u53D6\u503C { KEY: value }\uFF0C\u8303\u56F4=\u5F53\u524D\u5B9E\u4F8B\u3002\u4EC5\u9700\u63D0\u4F9B envSchema \u4E2D\u7684\u952E\uFF1B\u4EC5 MCP \u4F7F\u7528\uFF1B\u654F\u611F\u503C\u7531\u7528\u6237\u63D0\u4F9B\uFF0C\u4E0D\u8981\u4ECE\u5176\u5B83\u6765\u6E90\u63A8\u65AD\u6216\u590D\u7528\u3002",additionalProperties:{type:"string"}},collapsed:{type:"boolean",description:"\u53EF\u9009\uFF1A\u4EC5 MCP\uFF0C\u662F\u5426\u6536\u7EB3\uFF08\u9ED8\u8BA4\u53D6\u6A21\u677F\u8BBE\u7F6E\uFF0C\u901A\u5E38\u4E3A true\uFF09\u3002true=\u5DE5\u5177\u9ED8\u8BA4\u9690\u85CF\uFF0C\u9700 expand_tools \u5C55\u5F00"}},required:["template"]}},t={name:"uninstall_ability_market_item",description:"\u4ECE\u300C\u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\u300D\u5378\u8F7D\u6307\u5B9A\u5E02\u573A\u9879\uFF1A\u4ECE\u7528\u6237\u5B9E\u4F8B\u6A21\u677F\u79FB\u9664\u914D\u7F6E\u3001\u6E05\u5B9E\u4F8B\u80FD\u529B\u8986\u76D6\u5E76\u91CD\u65B0\u521D\u59CB\u5316 bridge\u3002\u4E0D\u5F71\u54CD\u5E02\u573A\u9879\u672C\u8EAB\u6216\u540C bridge \u4E0A\u5176\u5B83\u5B9E\u4F8B\uFF1B\u6210\u529F\u540E\u8FD0\u884C\u4E2D\u5B9E\u4F8B\u7ACB\u5373\u505C\u6B62\u52A0\u8F7D\u8BE5\u9879\u3002\u5185\u7F6E\u901A\u8BAF MCP\uFF08agents-work-studio\u3001aws-mcp\u3001aws-mcp-dev\uFF09\u4E0D\u53EF\u5378\u8F7D\u3002",inputSchema:{type:"object",properties:{template:{type:"string",description:"\u5E02\u573A\u9879 id \u6216 name"},kind:{type:"string",enum:["mcp","skill","plugin"],description:"\u5E02\u573A\u5236\u54C1\u7C7B\u578B"}},required:["template","kind"]}},n=new Set(["list_ability_market","install_ability_market_item","uninstall_ability_market_item"]),p=new Set(["ability_dev_ide","formal_ability","list_my_abilities"]),l={name:"ability_dev_ide",description:"\u80FD\u529B\u5F00\u53D1 IDE\u2014\u2014\u81EA\u7814 MCP / \u63D2\u4EF6 / Skill \u7684\u7EDF\u4E00\u5165\u53E3\u3002action\uFF1Aguide=\u8BFB\u53D6\u5185\u7F6E\u5F00\u53D1\u6307\u5357\u539F\u6587\uFF08Markdown\uFF0C\u53EA\u8BFB\uFF1Bkind=plugin|mcp|skill\uFF0C\u7F3A\u7701 plugin\uFF09\uFF0C\u7F16\u5199/\u6539\u9020\u524D\u5148\u53D6\u6743\u5A01\u89C4\u8303\uFF08\u76EE\u5F55\u7ED3\u6784\u3001\u6E05\u5355\u5B57\u6BB5\u3001stdio \u534F\u8BAE\u7EA6\u5B9A\u3001\u5DE5\u5177\u4E0E\u76D1\u542C\u5668\u58F0\u660E\u3001\u6253\u5305\u4E0E\u5B89\u88C5\uFF09\uFF0C\u4E0D\u8981\u51ED\u8BB0\u5FC6\u731C\u6D4B\u6E05\u5355\u683C\u5F0F\u6216\u534F\u8BAE\u5E27\u683C\u5F0F\uFF1Bmount=\u628A\u5DE5\u4F5C\u533A\u5185\u6B63\u5728\u5F00\u53D1\u7684 MCP/\u63D2\u4EF6\u4E34\u65F6\u6302\u5230\u5F53\u524D\u4F1A\u8BDD\u8BD5\u7528\uFF08kind=mcp \u65F6 path \u6307\u5411\u5DE5\u4F5C\u533A\u5185 mcp.json \u6587\u4EF6\u6216\u5176\u5305\u76EE\u5F55\uFF1Bkind=plugin \u65F6 path \u6307\u5411\u542B plugin.json \u7684\u63D2\u4EF6\u76EE\u5F55\uFF1B\u6302\u8F7D\u540E\u6587\u4EF6\u53D8\u66F4\u81EA\u52A8\u91CD\u8F7D\uFF0C\u6539\u4EE3\u7801\u540E\u53EF\u91CD\u65B0 mount \u540C\u4E00\u8DEF\u5F84\u751F\u6548\uFF09\uFF1Bunmount=\u6458\u9664\u4E00\u4E2A\u6302\u8F7D\u9879\uFF08kind+name\uFF09\uFF1Blist=\u67E5\u770B\u5F53\u524D\u6302\u8F7D\u9879\uFF0C\u6BCF\u9879\u542B name/path/mounted/toolCount/tools/error\uFF08mounted=false \u8868\u793A\u672A\u6210\u529F\u6302\u8F7D\uFF0Cerror \u4E3A\u5931\u8D25\u539F\u56E0\uFF1BMCP \u5DE5\u5177\u540D\u5F62\u5982 <server>__<tool>\uFF0C\u53EF\u7528 call_tool \u8C03\u7528\uFF09\uFF1Blogs=\u8BFB\u53D6\u67D0\u6302\u8F7D\u9879\u6700\u8FD1\u8FD0\u884C\u65E5\u5FD7\uFF08kind+name\uFF0C\u53EF\u9009 tail\uFF1BMCP \u4E3A\u5B50\u8FDB\u7A0B stderr \u73AF\u5F62\u7F13\u51B2\uFF0C\u63D2\u4EF6\u4E3A\u8FD0\u884C\u65E5\u5FD7\uFF09\uFF0C\u7528\u4E8E\u6392\u67E5\u300C\u6302\u8F7D\u540E\u6CA1\u6709\u5DE5\u5177 / \u8C03\u7528\u62A5\u9519 / \u5B50\u8FDB\u7A0B\u5361\u6B7B\u300D\u3002mount/unmount/logs \u7684 path/name \u5FC5\u987B\u4F4D\u4E8E\u4F60\u81EA\u5DF1\u7684\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u5185\uFF0C\u8C03\u8BD5\u6302\u8F7D\u4E0D\u6301\u4E45\u5316\uFF08bridge \u91CD\u542F\u5373\u5931\u6548\uFF09\uFF1BSkill \u65E0\u8C03\u8BD5\u6001\uFF0C\u8BFB\u89C4\u8303\u540E\u76F4\u63A5\u7528 formal_ability \u6216 install_ability_market_item\u3002\u6CE8\u610F\uFF1A\u6302\u8F7D\u5931\u8D25\u4E0D\u4F1A\u51FA\u73B0\u5728 list \u4E2D\uFF08mount \u54CD\u5E94\u76F4\u63A5\u8FD4\u56DE mounted=false \u4E0E error\uFF09\uFF0C\u67E5\u4E0D\u5230\u4E0D\u4EE3\u8868\u6CA1\u5C1D\u8BD5\u8FC7\u3002",inputSchema:{type:"object",properties:{action:{type:"string",enum:["guide","mount","unmount","list","logs"],description:"\u5F00\u53D1\u52A8\u4F5C"},kind:{type:"string",enum:["plugin","mcp","skill"],description:"guide\uFF1A\u89C4\u8303\u7C7B\u578B\uFF08plugin|mcp|skill\uFF0C\u7F3A\u7701 plugin\uFF09\uFF1Bmount/unmount/logs\uFF1A\u5236\u54C1\u7C7B\u578B\uFF08\u4EC5 mcp|plugin\uFF0C\u5FC5\u586B\uFF09\uFF1Blist\uFF1A\u53EF\u9009\u8FC7\u6EE4\uFF08\u7F3A\u7701\u5217\u51FA\u5168\u90E8\uFF09"},path:{type:"string",description:"\u4EC5 mount\uFF1A\u5DE5\u4F5C\u533A\u5185\u8DEF\u5F84\u3002kind=mcp \u4E3A mcp.json \u6587\u4EF6\u6216\u5176\u5305\u76EE\u5F55\uFF1Bkind=plugin \u4E3A\u542B plugin.json \u7684\u63D2\u4EF6\u76EE\u5F55\u3002\u652F\u6301\u76F8\u5BF9\u5DE5\u4F5C\u533A\u7684\u76F8\u5BF9\u8DEF\u5F84\u3002"},name:{type:"string",description:"\u8C03\u8BD5\u9879\u540D\uFF08unmount/logs \u5FC5\u586B\uFF1Bmount \u65F6 MCP \u53EF\u9009\u3001\u7F3A\u7701\u53D6\u8DEF\u5F84 basename\uFF0C\u63D2\u4EF6\u4EE5 plugin.json \u4E3A\u51C6\uFF09"},tail:{type:"number",description:"\u4EC5 logs\uFF1A\u8FD4\u56DE\u6700\u8FD1 N \u884C\uFF08\u9ED8\u8BA4 100\uFF0C\u4E0A\u9650 500\uFF09"}},required:["action"]}},s={name:"formal_ability",description:"\u628A\u5F00\u53D1\u597D\u7684\u5236\u54C1\u8F6C\u6B63\uFF08\u6301\u4E45\u5316\u5B89\u88C5\uFF09\u3002kind=mcp|plugin \u65F6\u4F20 path\uFF08\u5DE5\u4F5C\u533A\u5185\u5DF2\u8C03\u8BD5\u597D\u7684\u5236\u54C1\u8DEF\u5F84\uFF09\uFF0C\u670D\u52A1\u7AEF\u6253\u5305\u5E76\u8D70\u80FD\u529B\u5E02\u573A\u5B89\u88C5\u6D41\u7A0B\uFF1Bkind=skill \u65F6\u4F20 path\uFF08\u5DE5\u4F5C\u533A\u5185\u542B SKILL.md \u7684\u76EE\u5F55\uFF09\uFF0C\u76F4\u63A5\u6253\u5305\u767B\u8BB0\u5E76\u5B89\u88C5\uFF08Skill \u65E0\u8C03\u8BD5\u6001\uFF0C\u4E0D\u9700\u8981\u6302\u8F7D\uFF09\u3002scope \u7F3A\u7701\u4E3A global\uFF1A\u53EA\u767B\u8BB0\u5230\u300C\u5168\u5C40\u914D\u7F6E \u2192 \u5B9E\u4F8B\u6A21\u677F\u300D\u4E14 instantiate=false\uFF08\u9ED8\u8BA4\u5173\u95ED\u3001\u4E0D\u53C2\u4E0E\u5B9E\u4F8B\u521D\u59CB\u5316\uFF09\uFF0C\u9700\u7528\u6237\u5728\u9762\u677F\u5F00\u542F\u8BE5\u9879\u5F00\u5173\u540E\u624D\u968F\u521D\u59CB\u5316\u4E0B\u53D1\u2014\u2014\u8F6C\u6B63\u6210\u529F\u540E\u5E76\u4E0D\u7B49\u4E8E\u5F53\u524D\u5B9E\u4F8B\u5DF2\u751F\u6548\u3002\u663E\u5F0F\u4F20 scope=instance \u624D\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\u5E76\u7ACB\u5373\u751F\u6548\uFF1Bscope=private \u4EC5\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\u3001\u5176\u5B83\u5B9E\u4F8B\u4E0D\u53EF\u89C1\u3002",inputSchema:{type:"object",properties:{kind:{type:"string",enum:["mcp","plugin","skill"],description:"\u5236\u54C1\u7C7B\u578B"},path:{type:"string",description:"\u5DE5\u4F5C\u533A\u5185\u5236\u54C1\u8DEF\u5F84\uFF1Akind=mcp|plugin \u4E3A\u5DF2\u8C03\u8BD5\u597D\u7684\u5236\u54C1\u76EE\u5F55\uFF08MCP \u5305\u76EE\u5F55 / \u63D2\u4EF6\u76EE\u5F55\uFF09\uFF1Bkind=skill \u4E3A\u542B SKILL.md \u7684\u76EE\u5F55\u3002"},name:{type:"string",description:"\u53EF\u9009\uFF1A\u5236\u54C1\u540D\uFF08\u7F3A\u7701\u4ECE\u6E05\u5355\u6216 SKILL.md \u8BFB\u53D6\uFF09"},scope:{type:"string",enum:["global","instance","private"],description:"\u53EF\u9009\uFF1A\u5B89\u88C5\u843D\u70B9\uFF0C\u7F3A\u7701 global\uFF08\u53EA\u5165\u5168\u5C40\u914D\u7F6E\u6A21\u677F\u3001\u521D\u59CB\u5316\u5173\u95ED\uFF09\uFF1Binstance=\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\u7ACB\u5373\u751F\u6548\uFF1Bprivate=\u4EC5\u5B89\u88C5\u5230\u5F53\u524D\u5B9E\u4F8B\uFF08per-agent \u79C1\u6709\uFF09\uFF0C\u4E0D\u6539\u5171\u4EAB\u5B9E\u4F8B\u6A21\u677F\u3001\u5176\u5B83\u5B9E\u4F8B\u4E0D\u53EF\u89C1"}},required:["kind","path"]}},a={name:"list_my_abilities",description:"\u67E5\u8BE2\u300C\u4F60\u81EA\u5DF1\u6240\u5728\u7684\u89D2\u8272\u5B9E\u4F8B\u300D\u5F53\u524D\u7684\u5168\u90E8\u80FD\u529B\u72B6\u6001\uFF08\u53EA\u8BFB\uFF09\u3002\u8FD4\u56DE\uFF1Amcp / skills / plugins\uFF08\u540D\u79F0\u3001\u542F\u7528\u72B6\u6001\u3001\u6765\u6E90\u5C42\u7EA7\uFF1B\u63D2\u4EF6\u53E6\u542B\u8FD0\u884C\u6001\u4E0E\u5DE5\u5177\u6570\uFF09\u3001tools\uFF08\u529F\u80FD\u5F00\u5173\u7684\u6709\u6548\u4E09\u6001\uFF1Adisabled/collapsed/expanded\uFF09\u3001debugMounts\uFF08\u5F53\u524D\u4F1A\u8BDD\u7684\u8C03\u8BD5\u6302\u8F7D\u9879\uFF0C\u4E0E\u6301\u4E45\u5316\u5B89\u88C5\u9694\u79BB\uFF09\u3002\u7528\u4E8E\u81EA\u7BA1\u7406\uFF1A\u786E\u8BA4\u5DF2\u5B89\u88C5\u80FD\u529B\u3001\u53D1\u73B0\u91CD\u590D\u5B89\u88C5\u3001\u8BC6\u522B\u4E0D\u7528\u7684\u80FD\u529B\u540E\u7528 uninstall_ability_market_item \u5378\u8F7D\u3002",inputSchema:{type:"object",properties:{},required:[]}};export{l as ABILITY_DEV_IDE_TOOL,p as ABILITY_DEV_TOOL_NAMES,n as ABILITY_MARKET_TOOL_NAMES,s as FORMAL_ABILITY_TOOL,i as INSTALL_ABILITY_MARKET_ITEM_TOOL,e as LIST_ABILITY_MARKET_TOOL,a as LIST_MY_ABILITIES_TOOL,t as UNINSTALL_ABILITY_MARKET_ITEM_TOOL};
|
|
2
2
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import type { MemoryStats } from "./memory-store.js";
|
|
3
3
|
import { StatusReporter } from "./status-reporter.js";
|
|
4
|
-
import type { AgentConfig, BrowserListenerEvent, Card, DirectMessage, DmHistoryResponse, FetchUnreadMessagesOptions, FinishTaskRollbackArgs, GroupHistoryResponse, GroupRoomsResponse, HireBatchResult, HireColleagueArgs, MessageHandler, OnlineListResponse, ProfileInfo, ProjectMembersResponse, RegisterResult, ReplyToRef, ServerConfig, SendDmResult, SendMessageResult, StartTaskRollbackArgs, TaskInstanceCommentArgs, UnreadMessagesResult } from "./types.js";
|
|
4
|
+
import type { AgentConfig, BrowserListenerEvent, Card, CurrentActionSnapshot, DirectMessage, DmHistoryResponse, FetchUnreadMessagesOptions, FinishTaskRollbackArgs, GroupHistoryResponse, GroupRoomsResponse, HireBatchResult, HireColleagueArgs, MessageHandler, OnlineListResponse, ProfileInfo, ProjectMembersResponse, RegisterResult, ReplyToRef, ServerConfig, SendDmResult, SendMessageResult, StartTaskRollbackArgs, TaskInstanceCommentArgs, UnreadMessagesResult } from "./types.js";
|
|
5
5
|
export type ProfileHandler = (profile: ProfileInfo) => void;
|
|
6
6
|
export type AgentConfigHandler = (data: Record<string, unknown>) => void;
|
|
7
7
|
export type SystemNotifyHandler = (data: Record<string, unknown>) => void;
|
|
@@ -62,7 +62,16 @@ export declare class AgentClient {
|
|
|
62
62
|
|
|
63
63
|
sendGroupMessage(content: string, projectId?: string, roomId?: string, card?: Card, replyTo?: ReplyToRef[]): Promise<SendMessageResult>;
|
|
64
64
|
|
|
65
|
-
sendDirectMessage(targetId: string, content: string, waitReply?: boolean, replyToCallId?: string, timeoutMs?: number, card?: Card, replyTo?: ReplyToRef[]
|
|
65
|
+
sendDirectMessage(targetId: string, content: string, waitReply?: boolean, replyToCallId?: string, timeoutMs?: number, card?: Card, replyTo?: ReplyToRef[], forceOptions?: {
|
|
66
|
+
priority?: "normal" | "force";
|
|
67
|
+
intent?: "stop" | "redirect" | "constraint";
|
|
68
|
+
ref?: {
|
|
69
|
+
taskInstanceId?: string;
|
|
70
|
+
nodeId?: string;
|
|
71
|
+
messageId?: string;
|
|
72
|
+
};
|
|
73
|
+
reason?: string;
|
|
74
|
+
}): Promise<SendDmResult>;
|
|
66
75
|
|
|
67
76
|
sendCallAndWaitReply(targetId: string, content: string, timeoutMs?: number): Promise<DirectMessage>;
|
|
68
77
|
|
|
@@ -86,6 +95,8 @@ export declare class AgentClient {
|
|
|
86
95
|
|
|
87
96
|
markDmRead(msgIds: string[]): Promise<Set<string>>;
|
|
88
97
|
|
|
98
|
+
markForceInjected(msgIds: string[]): Promise<Set<string>>;
|
|
99
|
+
|
|
89
100
|
markGroupRead(roomId: string, msgIds: number[]): Promise<Set<number>>;
|
|
90
101
|
|
|
91
102
|
markNotificationRead(msgIds: string[]): Promise<void>;
|
|
@@ -101,6 +112,8 @@ export declare class AgentClient {
|
|
|
101
112
|
|
|
102
113
|
notifyBridgeForceMessage(): Promise<void>;
|
|
103
114
|
|
|
115
|
+
fetchCurrentAction(): Promise<CurrentActionSnapshot | null>;
|
|
116
|
+
|
|
104
117
|
private fetchDirectMessagesWithRecovery;
|
|
105
118
|
|
|
106
119
|
private isRecoverableLongPollError;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{configManager as h}from"./config.js";import{MESSAGE_POLL_INTERVAL_MS as I}from"./constants.js";import{HttpClient as f}from"./http-client.js";import{logger as i,setMcpNodeLogSink as w,updateStartupLogIdentity as u}from"./logger.js";import{claimRuntimeLaunchBindingDetailed as m}from"./runtime-launch-binding.js";import{StatusReporter as A}from"./status-reporter.js";import{WebSocketClient as p}from"./websocket-client.js";class T extends Error{constructor(e){super(e),this.name="PollLongPollTimeoutError"}}const C=27e4;class N{wsClient;httpClient;agentConfig;serverConfig;agentId=null;displayName=null;projectId=null;isRunning=!1;isDegradedMode=!1;messageHandler=null;profileHandler=null;configHandler=null;systemNotifyHandler=null;pollTimer=null;statusReporter=null;newCharacterHandler=null;runtimeTokenRefreshTimer=null;pendingLaunchBindingClaim=!1;cachedProfile=null;constructor(){h.loadConfig(),this.agentConfig=h.getAgentConfig(),this.serverConfig=h.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async initialize(){const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed"){this.applyLaunchBinding(e.binding);return}if(e.status==="unreachable"){this.pendingLaunchBindingClaim=!0,i.warn("[AgentClient] runtime-bridge \u672A\u5C31\u7EEA\uFF0C\u542F\u52A8\u7ED1\u5B9A\u8BA4\u9886\u5DF2\u6302\u8D77\uFF0C\u5C06\u5728\u6CE8\u518C\u91CD\u8BD5\u4E2D\u91CD\u65B0\u8BA4\u9886: %s",e.message);return}this.serverConfig.runtimeBridgeBaseUrl=void 0}applyLaunchBinding(e){h.applyRuntimeLaunchBinding(e),this.agentConfig=h.getAgentConfig(),this.serverConfig=h.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async retryPendingLaunchBindingClaim(){if(!this.pendingLaunchBindingClaim)return!0;const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed")return this.pendingLaunchBindingClaim=!1,i.info("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u6210\u529F\uFF0C\u7EE7\u7EED\u6CE8\u518C\u6D41\u7A0B"),this.applyLaunchBinding(e.binding),!0;if(e.status==="missing")return this.pendingLaunchBindingClaim=!1,this.serverConfig.runtimeBridgeBaseUrl=void 0,i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u672A\u627E\u5230\u5F85\u8BA4\u9886\u8BB0\u5F55\uFF0C\u6309\u65E0\u7ED1\u5B9A\u6A21\u5F0F\u7EE7\u7EED\u6CE8\u518C"),!1;const t=e.status==="unreachable"?e.message:e.reason;return i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u5931\u8D25\uFF0C\u4FDD\u7559\u6302\u8D77\u72B6\u6001\u7B49\u5F85\u4E0B\u6B21\u6CE8\u518C\u91CD\u8BD5: %s",t),!1}setupWebSocketListeners(){this.wsClient.on("directMessage",e=>{this.handleIncomingDm(e)}),this.wsClient.on("groupMessage",e=>{this.handleIncomingGroup(e)}),this.wsClient.on("meetingMessage",e=>{this.handleIncomingMeeting(e)}),this.wsClient.on("systemNotify",e=>{this.systemNotifyHandler?.(e)}),this.wsClient.on("profileInfo",e=>{i.info(`[AgentClient] WebSocket profileInfo \u4E8B\u4EF6\u89E6\u53D1\uFF0CdisplayName: ${e.displayName}`),this.handleProfileInfo(e)}),this.wsClient.on("agentConfig",e=>{i.info("[AgentClient] WebSocket agentConfig \u4E8B\u4EF6\u89E6\u53D1"),this.configHandler&&this.configHandler(e??{})}),this.wsClient.on("agentStatus",e=>{i.info(`[AgentClient] WebSocket agentStatus \u4E8B\u4EF6\u89E6\u53D1: ${e.status}`)}),this.wsClient.on("disconnected",(e,t)=>{const n=t?.toString()||"";i.warn("[AgentClient] WebSocket \u65AD\u5F00\u8FDE\u63A5: code=%s, reason=%s, agentId=%s, \u6B63\u5728\u81EA\u52A8\u91CD\u8FDE",e,n,this.agentId)}),this.wsClient.on("error",e=>{i.error("[AgentClient] WebSocket \u9519\u8BEF: %s, stack=%s",e.message,e.stack)}),this.wsClient.on("reconnectFailed",()=>{i.error("[AgentClient] \u91CD\u8FDE\u5931\u8D25\uFF08\u5DF2\u8FBE\u91CD\u8BD5\u4E0A\u9650\uFF09\uFF0C\u505C\u6B62\u6D88\u606F\u5FAA\u73AF, agentId=%s",this.agentId),this.stop()}),this.wsClient.on("tokenRejected",()=>{i.error("[AgentClient] runtime token \u88AB 1008 \u62D2\u7EDD\u4E14\u5237\u65B0\u65E0\u53D8\u5316\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85\u65B0 token \u7B7E\u53D1: agentId=%s",this.agentId)}),this.wsClient.on("tokenRefreshFailed",e=>{i.error("[AgentClient] runtime token \u5237\u65B0\u8FDE\u7EED\u5931\u8D25 %s \u6B21\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85 bridge \u6062\u590D: agentId=%s",e,this.agentId)})}async register(){return i.info("[AgentClient] \u6B63\u5728\u6CE8\u518C Agent..."),await this.retryPendingLaunchBindingClaim(),this.hasPresetAgentId()?await this.registerWithExistingAgentId():await this.registerAsNewAgent()}hasPresetAgentId(){return!!(this.agentConfig.agentId&&this.agentConfig.agentId.trim().length>0)}async registerWithExistingAgentId(){const e=this.agentConfig.agentId;if(!e)throw new Error("Preset agentId is missing");this.agentId=e.trim();let t;try{t=await this.getProfileByAgentId(this.agentId)}catch(r){throw i.error("[AgentClient] getProfileByAgentId \u5931\u8D25 (presetAgentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}this.displayName=t.displayName,this.projectId=t.projectId||null,i.info(`[AgentClient] \u4F7F\u7528\u9884\u8BBE AgentID \u7ED1\u5B9A\u5B9E\u4F8B: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`);try{await this.wsClient.connect(this.agentId)}catch(r){throw i.error("[AgentClient] WebSocket \u8FDE\u63A5\u5931\u8D25 (agentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter();const n=await this.getProfileByAgentId(this.agentId);return this.displayName=n.displayName,this.projectId=n.projectId||null,u(n.roleName||"unknown-role",n.instanceName||this.agentId),{agentId:this.agentId,displayName:this.displayName,status:n.isOnline?"online":"offline",projectId:n.projectId,workspacePath:n.workspacePath,runtimeStatus:n.runtimeStatus,runtimeSessionId:n.runtimeSessionId}}async registerAsNewAgent(){const e=await this.httpClient.callTool("register",{roleName:this.agentConfig.roleName,projectId:this.agentConfig.projectId,workspacePath:this.agentConfig.workspacePath,prompt:this.agentConfig.prompt,runtimeBridgeBaseUrl:this.serverConfig.runtimeBridgeBaseUrl}),t=e.agentId;if(!t)throw new Error("Registration failed: agentId was not returned");return this.agentId=t,this.displayName=e.displayName,this.projectId=e.projectId||null,u(this.agentConfig.roleName||"unknown-role",e.instanceName||t),i.info(`[AgentClient] \u6CE8\u518C\u6210\u529F: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u72B6\u6001: ${e.status}`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`),await this.wsClient.connect(this.agentId),i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter(),e.isExisting===!1&&this.newCharacterHandler&&this.newCharacterHandler(),e}async unregister(){i.info("[AgentClient] \u6B63\u5728\u6CE8\u9500 Agent..."),this.agentId&&await this.httpClient.callTool("unregister",{agentId:this.agentId}),this.stopRuntimeTokenRefresh(),this.wsClient.disconnect(),this.agentId=null,this.displayName=null,this.projectId=null,this.isRunning=!1,i.info("[AgentClient] \u5DF2\u6CE8\u9500")}async discoverColleagues(){return await this.httpClient.callTool("discover_colleague",{agentId:this.agentId})}async discoverGroupRooms(){return this.ensureRegistered(),await this.httpClient.callTool("discover_group_rooms",{agentId:this.agentId})}async listProjectMembers(){return this.ensureRegistered(),await this.httpClient.callTool("list_project_members",{agentId:this.agentId})}async hireColleague(e){return this.ensureRegistered(),await this.httpClient.callTool("hire_colleague",{...e,agentId:this.agentId})}async callAgentScopedTool(e,t){this.ensureRegistered();const n={...t,agentId:this.agentId};if(e==="create_meeting"){const r=typeof t.waitTimeoutMs=="number"?t.waitTimeoutMs:Number.NaN,s=Number.isFinite(r)&&r>0?Math.min(r,C):C;return await this.httpClient.callToolOnce(e,{...n,waitTimeoutMs:s},0)}return await this.httpClient.callTool(e,n)}async reportMemoryStats(e){await this.callAgentScopedTool("report_memory_stats",{memoryStats:e})}async sendGroupMessage(e,t,n,r,s){this.ensureRegistered();const a=t||this.projectId||this.agentConfig.projectId;return await this.httpClient.callTool("send_group_message",{agentId:this.agentId,projectId:a,roomId:n,content:e,card:r,replyTo:s})}async sendDirectMessage(e,t,n=!1,r,s,a,c){this.ensureRegistered();const g={agentId:this.agentId,targetId:e,content:t,requireReply:n,waitReply:n,replyToCallId:r,card:a,replyTo:c};if(typeof s=="number"&&s>0&&(g.timeoutMs=s),n){const o=typeof s=="number"&&s>0?s+3e4:0;return await this.httpClient.callToolOnce("send_dm",g,o)}return await this.httpClient.callTool("send_dm",g)}async sendCallAndWaitReply(e,t,n=6e4){const r=await this.sendDirectMessage(e,t,!0,void 0,n);if(r.reply)return r.reply;throw new Error("No reply received for call-style direct message before timeout")}async replyToCall(e,t,n){return await this.sendDirectMessage(t,n,!1,e)}async sendEmail(e){return await this.callAgentScopedTool("send_email",e)}async listEmails(e){return await this.callAgentScopedTool("list_emails",e)}async readEmail(e){return await this.callAgentScopedTool("read_email",{mailId:e})}async replyEmail(e){return await this.callAgentScopedTool("reply_email",e)}async ackEmail(e){return await this.callAgentScopedTool("ack_email",{mailId:e})}async getDmHistory(e,t=50,n){this.ensureRegistered();const r={agentId:this.agentId,targetUserId:e,limit:t};return n&&(r.since=n),await this.httpClient.callTool("get_dm_history",r)}async getGroupHistory(e=50,t,n){if(this.ensureRegistered(),t){const o={projectId:this.projectId||this.agentConfig.projectId,roomId:t,limit:e};return n&&(o.since=n),await this.httpClient.callTool("get_group_history",o)}const r=await this.discoverGroupRooms(),s=this.projectId||this.agentConfig.projectId,a=this.collectRoomIds(r,s);if(a.length===0)return{messages:[],count:0};const g=(await Promise.all(a.map(async o=>{const l={projectId:s,roomId:o,limit:e};return n&&(l.since=n),await this.httpClient.callTool("get_group_history",l)}))).flatMap(o=>o.messages).sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime());return{messages:g,count:g.length}}async fetchUnreadMessages(e={}){this.ensureRegistered();const t=this.projectId||this.agentConfig.projectId,n={agentId:this.agentId,blockIfEmpty:e.blockIfEmpty??!1};e.since&&(n.since=e.since),e.blockTimeoutMs&&e.blockTimeoutMs>0&&(n.blockTimeoutMs=e.blockTimeoutMs),e.preemptiveJoinWaitMs!==void 0&&e.preemptiveJoinWaitMs!==null&&e.preemptiveJoinWaitMs>=0&&(n.preemptiveJoinWaitMs=e.preemptiveJoinWaitMs);const r=e.includePipelineTasks?"poll_message":"get_dm_messages";i.info("[AgentClient] fetchUnreadMessages \u5165\u53E3: tool=%s, blockIfEmpty=%s, blockTimeoutMs=%s, pollMessageTimeoutMs=%s, skipGroupMessages=%s, preemptiveJoinWaitMs=%s, agentId=%s",r,String(e.blockIfEmpty??!1),String(e.blockTimeoutMs??"-"),String(e.pollMessageTimeoutMs??"-"),String(e.skipGroupMessages??!1),String(e.preemptiveJoinWaitMs??"-"),this.agentId);const s=await this.fetchDirectMessagesWithRecovery(r,n,e.pollMessageTimeoutMs,e.propagatePollTimeout===!0);if(i.info("[AgentClient] fetchUnreadMessages \u79C1\u4FE1\u9636\u6BB5\u8FD4\u56DE: %s \u6761",Array.isArray(s.messages)?s.messages.length:0),e.skipGroupMessages)return i.info("[AgentClient] \u4F1A\u8BAE\u5FEB\u901F hydrate \u5DF2\u53D6\u5F97\u79C1\u4FE1\u54CD\u5E94\uFF0C\u8DF3\u8FC7\u7FA4\u804A\u53D1\u73B0\u5E76\u7ACB\u5373\u8FD4\u56DE: directMessages=%s",Array.isArray(s.messages)?s.messages.length:0),{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:[]};let a;try{a=await this.discoverGroupRooms()}catch(o){i.warn("[AgentClient] \u53D1\u73B0\u7FA4\u623F\u95F4\u5931\u8D25\uFF0C\u672C\u6B21\u6309\u65E0\u7FA4\u6D88\u606F\u5904\u7406\uFF08\u5DF2\u53D6\u5230\u7684\u79C1\u4FE1\u4E0D\u53D7\u5F71\u54CD\uFF09: %s",o instanceof Error?o.message:String(o)),a={groups:[]}}const c=this.collectRoomIds(a,t),g=await Promise.all(c.map(async o=>{const l={agentId:this.agentId,projectId:t,roomId:o};e.since&&(l.since=e.since);try{return await this.httpClient.callTool("get_group_messages",l)}catch(d){return i.warn("[AgentClient] \u8DF3\u8FC7\u7FA4\u623F\u95F4\u672A\u8BFB\u8865\u62C9\u5931\u8D25: roomId=%s, error=%s",o,d instanceof Error?d.message:String(d)),{messages:[],currentReadPos:0,hasMore:!1}}}));return{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:g.flatMap(o=>this.normalizeGroupMessages(o)).sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime())}}async markDmRead(e){if(e.length===0)return new Set;this.ensureRegistered();try{const t=await this.httpClient.callTool("mark_dm_read",{agentId:this.agentId,msgIds:e}),n=new Set(Array.isArray(t?.deliverableMsgIds)?t.deliverableMsgIds:[]),r=e.filter(s=>!n.has(s));return r.length>0?i.warn("[AgentClient] mark_dm_read \u786E\u8BA4\u540E\u5C06\u6709 %d \u6761\u6D88\u606F\u88AB\u4E22\u5F03\u4E0D\u4EA4\u4ED8: \u8BF7\u6C42=%s, \u53EF\u4EA4\u4ED8=%s, \u88AB\u4E22\u5F03=%s",r.length,JSON.stringify(e),JSON.stringify([...n]),JSON.stringify(r)):i.info("[AgentClient] mark_dm_read \u786E\u8BA4\u5B8C\u6210: %d \u6761\u5168\u90E8\u53EF\u4EA4\u4ED8",e.length),n}catch(t){throw i.warn("[AgentClient] mark_dm_read \u8BF7\u6C42\u5931\u8D25\uFF08\u5C06\u964D\u7EA7\u4E3A\u76F4\u63A5\u4EA4\u4ED8\uFF09: %s",t instanceof Error?t.message:String(t)),t}}async markGroupRead(e,t){if(t.length===0)return new Set;this.ensureRegistered();const n=await this.httpClient.callTool("mark_group_read",{agentId:this.agentId,roomId:e,msgIds:t});return new Set(Array.isArray(n?.deliverableMsgIds)?n.deliverableMsgIds:[])}async markNotificationRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_notification_read",{agentId:this.agentId,msgIds:e})}catch{}}}async markMeetingRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_meeting_read",{agentId:this.agentId,msgIds:e})}catch{}}}async fetchBrowserListenerEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return i.info("[AgentClient] fetchBrowserListenerEvents \u8DF3\u8FC7: bridgeBaseUrl=%s, agentId=%s",e||"(\u7A7A)",t||"(\u7A7A)"),[];try{const n=`${e}/runtime/browser-listeners/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"";i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6: url=%s, tokenLen=%d",n,r.length);const s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),[];const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s, eventsType=%s",a.ok,Array.isArray(a.events)?"array":typeof a.events),[]):(i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6",a.events.length),a.events)}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),[]}}async fetchPluginEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return{revision:0,events:[]};try{const n=`${e}/runtime/plugin-events/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),{revision:0,events:[]};const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s",String(a.ok)),{revision:0,events:[]}):(i.debug("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6, revision=%s",a.events.length,String(a.revision??0)),{revision:a.revision??0,events:a.events})}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),{revision:0,events:[]}}}async notifyBridgeForceMessage(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!(!e||!t))try{const n=`${e}/runtime/sessions/${encodeURIComponent(t)}/notify-force-message`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"POST",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});s.ok||i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5931\u8D25: HTTP %s, url=%s",s.status,n)}catch(n){i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5F02\u5E38: %s",n instanceof Error?n.message:String(n))}}async fetchDirectMessagesWithRecovery(e,t,n,r=!1){if(e==="poll_message"){i.info("[AgentClient] fetchDirectMessagesWithRecovery \u5165\u53E3: tool=poll_message, pollMessageTimeoutMs=%s, agentId=%s",String(n??"(\u9ED8\u8BA4)"),String(t?.agentId??""));try{const s=await this.httpClient.callToolOnce(e,t,n);return i.info("[AgentClient] fetchDirectMessagesWithRecovery poll_message \u6210\u529F\u8FD4\u56DE: %s \u6761",Array.isArray(s?.messages)?s.messages.length:0),s}catch(s){if(this.isRecoverableLongPollError(s)){if(r)throw new T(s instanceof Error?s.message:String(s));return i.warn("[AgentClient] poll_message \u5355\u6B21\u957F\u8F6E\u8BE2\u8D85\u65F6\uFF0C\u6309\u7A7A\u7ED3\u679C\u9000\u907F\u540E\u7EE7\u7EED\u7B49\u5F85:",s),{messages:[]}}throw s}}return await this.httpClient.callTool(e,t)}isRecoverableLongPollError(e){return e instanceof Error?/MCP tool poll_message call failed: 503(?:\s|$)/.test(e.message)||/MCP tool poll_message timed out after \d+ms/.test(e.message):!1}normalizeGroupMessages(e){return Array.isArray(e.messages)?e.messages.filter(t=>!!(t&&typeof t=="object"&&typeof t.msgId=="number"&&typeof t.senderId=="string"&&typeof t.content=="string"&&typeof t.timestamp=="string")):[]}collectRoomIds(e,t){const n=e.groups.filter(r=>r.projectId===t).map(r=>r.id);return Array.from(new Set(n))}async getProfile(){this.ensureRegistered();const e=this.agentId;if(!e)throw new Error("Agent is not registered");return{...await this.getProfileByAgentId(e),describe:this.agentConfig.describe}}async getProfileByAgentId(e){return await this.httpClient.callTool("get_profile",{agentId:e})}async getMyTasks(){return this.ensureRegistered(),await this.httpClient.callTool("my_task",{agentId:this.agentId})}async listTaskNodeIterations(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_task_node_iterations",{agentId:this.agentId,...e})}async createTaskInstanceComment(e){this.ensureRegistered();const t={agentId:this.agentId,...e};return await this.httpClient.callTool("create_task_instance_comment",t)}async submitTaskResult(e,t,n,r,s){this.ensureRegistered();const a={agentId:this.agentId,nodeId:e,outputPayload:t};return(Array.isArray(n)&&n.length>0||typeof n=="string"&&n.trim().length>0)&&(a.changeLog=n),typeof r=="string"&&r.trim().length>0&&(a.handoverNote=r),s&&Array.isArray(s)&&s.length>0&&(a.deliverables=s),await this.httpClient.callTool("submit_task_result",a)}async startTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("start_task_rollback",{agentId:this.agentId,...e})}async finishTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("finish_task_rollback",{agentId:this.agentId,...e})}async getDebugLogConfig(){return await this.httpClient.callTool("get_debug_log_config",{agentId:this.agentId})}async queryDebugLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("query_debug_logs",{...e})}async queryFileChangesHistory(e){return this.ensureRegistered(),await this.httpClient.callTool("query_file_changes_history",{...e})}async listColleagueEvents(e){return this.ensureRegistered(),await this.httpClient.callTool("list_colleague_events",{...e})}async getRuntimeFeatures(){return await this.httpClient.fetchRuntimeFeatures()}async listLaunchConfigs(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_list",{})}async createLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_create",{...e})}async updateLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_update",{...e})}async deleteLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_delete",{configId:e})}async startLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_start",e,t+6e4):await this.httpClient.callTool("launch_config_start",{...e})}async restartLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_restart",e,t+6e4):await this.httpClient.callTool("launch_config_restart",{...e})}async stopLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_stop",{configId:e})}async getLaunchLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_logs",{...e})}async listLaunchRuns(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_status",{})}async listAbilityMarket(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_ability_market",{...e})}async installAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("install_ability_market_item",{...e})}async uninstallAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("uninstall_ability_market_item",{...e})}async abilityDevIde(e){return this.ensureRegistered(),await this.httpClient.callTool("ability_dev_ide",{...e})}async formalAbility(e){return this.ensureRegistered(),await this.httpClient.callTool("formal_ability",{...e})}async listMyAbilities(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_my_abilities",{...e})}start(e,t){if(this.isRunning){i.warn("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u5DF2\u5728\u8FD0\u884C\u4E2D");return}this.isDegradedMode||this.ensureRegistered(),this.messageHandler=e,this.profileHandler=t?.profileHandler||null,this.configHandler=t?.configHandler||null,this.systemNotifyHandler=t?.systemNotifyHandler||null,this.isRunning=!0,i.info(`[AgentClient] start() \u88AB\u8C03\u7528\uFF0CcachedProfile: ${this.cachedProfile?"\u5B58\u5728":"\u4E0D\u5B58\u5728"}, profileHandler: ${this.profileHandler?"\u5DF2\u8BBE\u7F6E":"\u672A\u8BBE\u7F6E"}, \u964D\u7EA7\u6A21\u5F0F: ${this.isDegradedMode?"\u662F":"\u5426"}`),this.cachedProfile&&this.profileHandler&&(i.info(`[AgentClient] \u5904\u7406\u7F13\u5B58\u7684 Profile \u4FE1\u606F: ${this.cachedProfile.displayName}`),this.profileHandler(this.cachedProfile),this.cachedProfile=null),t?.pollMode??!1?(i.warn("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08HTTP\u8F6E\u8BE2\u6A21\u5F0F - \u4E0D\u63A8\u8350\uFF09"),this.messageLoop()):i.info("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08WebSocket\u63A8\u9001\u6A21\u5F0F - \u63A8\u8350\uFF09")}stop(){this.isRunning=!1,this.pollTimer&&(clearTimeout(this.pollTimer),this.pollTimer=null),this.stopRuntimeTokenRefresh(),i.info("[AgentClient] \u6D88\u606F\u4E3B\u5FAA\u73AF\u5DF2\u505C\u6B62")}async messageLoop(){for(;this.isRunning;)try{await this.delay(I)}catch(e){i.error("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u9519\u8BEF:",e),await this.delay(5e3)}}handleIncomingDm(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingGroup(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingMeeting(e){!e||e.senderId===this.agentId||this.processMessage(e)}handleProfileInfo(e){i.info(`[AgentClient] \u6536\u5230 Profile \u4FE1\u606F: ${e.displayName} (${e.roleName})`),e.projectId&&(this.projectId=e.projectId,i.info(`[AgentClient] \u66F4\u65B0\u6240\u5C5E\u9879\u76EE: ${this.projectId}`)),e.roleName&&e.roleName!==this.agentConfig.roleName&&(i.info(`[AgentClient] \u540C\u6B65\u89D2\u8272\u540D: "${this.agentConfig.roleName||"(\u7A7A)"}" -> "${e.roleName}"`),this.agentConfig.roleName=e.roleName),e.roleName&&u(e.roleName,e.instanceName||this.agentId||""),this.profileHandler?this.profileHandler(e):(i.info("[AgentClient] profileHandler \u672A\u8BBE\u7F6E\uFF0C\u7F13\u5B58 Profile \u4FE1\u606F"),this.cachedProfile=e)}async processMessage(e){if(!this.messageHandler)return;const t=typeof e.msgId=="string";i.info(`[AgentClient] \u6536\u5230${t?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F"}\u6765\u81EA ${e.senderName}: ${e.content.substring(0,50)}...`);try{const n=await this.messageHandler(e);if(t){const r=e;r.requireReply&&r.callId&&await this.replyToCall(r.callId,r.senderId,n||"\u5DF2\u6536\u5230\u6D88\u606F\uFF0C\u6B63\u5728\u5904\u7406\u4E2D...")}}catch(n){const r=typeof e.msgId=="string";if(i.error("[AgentClient] \u5904\u7406\u6D88\u606F\u5931\u8D25: type=%s, senderId=%s, senderName=%s, msgId=%s, error=%s",r?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F",e.senderId,e.senderName,e.msgId,n instanceof Error?n.message:String(n)),r){const s=e;s.requireReply&&s.callId&&await this.replyToCall(s.callId,s.senderId,`\u5904\u7406\u5931\u8D25: ${n}`)}}}ensureRegistered(){if(!this.agentId)throw new Error("Agent is not registered")}delay(e){return new Promise(t=>{this.pollTimer=setTimeout(t,e)})}onNewCharacter(e){this.newCharacterHandler=e}getState(){return{agentId:this.agentId,displayName:this.displayName,projectId:this.projectId,isConnected:this.wsClient.isConnected(),isRunning:this.isRunning}}getAgentConfig(){return this.agentConfig}getServerConfig(){return this.serverConfig}reloadConfig(){h.loadConfig(),this.agentConfig=h.getAgentConfig(),i.info(`[AgentClient] \u914D\u7F6E\u5DF2\u91CD\u65B0\u52A0\u8F7D\uFF0C\u89D2\u8272: ${this.agentConfig.roleName}`)}enterDegradedMode(){this.isDegradedMode=!0,i.warn("[AgentClient] \u8FDB\u5165\u964D\u7EA7\u6A21\u5F0F\uFF0C\u5C06\u5728\u540E\u53F0\u6301\u7EED\u5C1D\u8BD5\u91CD\u8FDE")}exitDegradedMode(){this.isDegradedMode=!1,i.info("[AgentClient] \u9000\u51FA\u964D\u7EA7\u6A21\u5F0F")}isInDegradedMode(){return this.isDegradedMode}async retryRegistrationInBackground(e,t){let n=0;(async()=>{for(;this.isDegradedMode;)try{i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u5C1D\u8BD5\u91CD\u65B0\u6CE8\u518C (${n+1}/${t===-1?"\u65E0\u9650":t})`);const s=await this.register();i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u6210\u529F - ${s.displayName} (${s.agentId})`),this.exitDegradedMode(),this.messageHandler&&this.start(this.messageHandler);return}catch(s){n++;const a=s instanceof Error?s.message:String(s);if(i.warn(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u5931\u8D25 (${n}/${t===-1?"\u65E0\u9650":t}): ${a}`),t>0&&n>=t){i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u505C\u6B62\u91CD\u8FDE"),this.isDegradedMode=!1;return}await new Promise(c=>setTimeout(c,e))}})().catch(s=>{i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\u540E\u53F0\u91CD\u8BD5\u5FAA\u73AF\u5F02\u5E38\u9000\u51FA: error=%s, stack=%s",s instanceof Error?s.message:String(s),s instanceof Error?s.stack:"(no stack)")})}initializeStatusReporter(){if(!this.agentId){i.warn("[AgentClient] \u65E0\u6CD5\u521D\u59CB\u5316\u72B6\u6001\u62A5\u544A\u5668\uFF1AagentId \u4E3A\u7A7A");return}this.statusReporter=new A({agentId:this.agentId,sendStatusUpdate:e=>{this.wsClient.send({type:"AGENT_STATUS",data:e,timestamp:new Date().toISOString()})}}),w(e=>this.reportMcpNodeLog(e)),this.startRuntimeTokenRefresh(),i.info("[AgentClient] \u72B6\u6001\u62A5\u544A\u5668\u5DF2\u521D\u59CB\u5316")}startRuntimeTokenRefresh(){this.stopRuntimeTokenRefresh();const e=this.serverConfig.runtimeTokenRefreshIntervalMs;if(!e||e<=0){i.warn("[AgentClient] runtimeTokenRefreshIntervalMs \u672A\u914D\u7F6E\u6216\u65E0\u6548\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}const t=this.agentId;if(!t){i.warn("[AgentClient] agentId \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}this.runtimeTokenRefreshTimer=setInterval(async()=>{try{await this.httpClient.refreshRuntimeAccessToken(t)&&i.info("[AgentClient] runtimeAccessToken \u5DF2\u4E3B\u52A8\u7EED\u671F")}catch(n){i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F runtimeAccessToken \u5931\u8D25: %s",n instanceof Error?n.message:String(n)),n instanceof Error&&n.stack&&i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F\u5F02\u5E38\u5806\u6808:",n.stack)}},e),this.runtimeTokenRefreshTimer.unref?.(),i.info(`[AgentClient] runtime token \u4E3B\u52A8\u7EED\u671F\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694 ${e}ms`)}stopRuntimeTokenRefresh(){this.runtimeTokenRefreshTimer&&(clearInterval(this.runtimeTokenRefreshTimer),this.runtimeTokenRefreshTimer=null)}reportMcpNodeLog(e){const t=this.wsClient;!this.agentId||!this.wsClient.isConnected()||typeof t.sendMcpNodeLog!="function"||t.sendMcpNodeLog(e)}getStatusReporter(){return this.statusReporter}}export{N as AgentClient,T as PollLongPollTimeoutError};
|
|
1
|
+
import{configManager as c}from"./config.js";import{MESSAGE_POLL_INTERVAL_MS as I}from"./constants.js";import{HttpClient as f}from"./http-client.js";import{logger as i,setMcpNodeLogSink as w,updateStartupLogIdentity as u}from"./logger.js";import{claimRuntimeLaunchBindingDetailed as m}from"./runtime-launch-binding.js";import{StatusReporter as A}from"./status-reporter.js";import{WebSocketClient as p}from"./websocket-client.js";class T extends Error{constructor(e){super(e),this.name="PollLongPollTimeoutError"}}const C=27e4;class N{wsClient;httpClient;agentConfig;serverConfig;agentId=null;displayName=null;projectId=null;isRunning=!1;isDegradedMode=!1;messageHandler=null;profileHandler=null;configHandler=null;systemNotifyHandler=null;pollTimer=null;statusReporter=null;newCharacterHandler=null;runtimeTokenRefreshTimer=null;pendingLaunchBindingClaim=!1;cachedProfile=null;constructor(){c.loadConfig(),this.agentConfig=c.getAgentConfig(),this.serverConfig=c.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async initialize(){const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed"){this.applyLaunchBinding(e.binding);return}if(e.status==="unreachable"){this.pendingLaunchBindingClaim=!0,i.warn("[AgentClient] runtime-bridge \u672A\u5C31\u7EEA\uFF0C\u542F\u52A8\u7ED1\u5B9A\u8BA4\u9886\u5DF2\u6302\u8D77\uFF0C\u5C06\u5728\u6CE8\u518C\u91CD\u8BD5\u4E2D\u91CD\u65B0\u8BA4\u9886: %s",e.message);return}this.serverConfig.runtimeBridgeBaseUrl=void 0}applyLaunchBinding(e){c.applyRuntimeLaunchBinding(e),this.agentConfig=c.getAgentConfig(),this.serverConfig=c.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async retryPendingLaunchBindingClaim(){if(!this.pendingLaunchBindingClaim)return!0;const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed")return this.pendingLaunchBindingClaim=!1,i.info("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u6210\u529F\uFF0C\u7EE7\u7EED\u6CE8\u518C\u6D41\u7A0B"),this.applyLaunchBinding(e.binding),!0;if(e.status==="missing")return this.pendingLaunchBindingClaim=!1,this.serverConfig.runtimeBridgeBaseUrl=void 0,i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u672A\u627E\u5230\u5F85\u8BA4\u9886\u8BB0\u5F55\uFF0C\u6309\u65E0\u7ED1\u5B9A\u6A21\u5F0F\u7EE7\u7EED\u6CE8\u518C"),!1;const t=e.status==="unreachable"?e.message:e.reason;return i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u5931\u8D25\uFF0C\u4FDD\u7559\u6302\u8D77\u72B6\u6001\u7B49\u5F85\u4E0B\u6B21\u6CE8\u518C\u91CD\u8BD5: %s",t),!1}setupWebSocketListeners(){this.wsClient.on("directMessage",e=>{this.handleIncomingDm(e)}),this.wsClient.on("groupMessage",e=>{this.handleIncomingGroup(e)}),this.wsClient.on("meetingMessage",e=>{this.handleIncomingMeeting(e)}),this.wsClient.on("systemNotify",e=>{this.systemNotifyHandler?.(e)}),this.wsClient.on("profileInfo",e=>{i.info(`[AgentClient] WebSocket profileInfo \u4E8B\u4EF6\u89E6\u53D1\uFF0CdisplayName: ${e.displayName}`),this.handleProfileInfo(e)}),this.wsClient.on("agentConfig",e=>{i.info("[AgentClient] WebSocket agentConfig \u4E8B\u4EF6\u89E6\u53D1"),this.configHandler&&this.configHandler(e??{})}),this.wsClient.on("agentStatus",e=>{i.info(`[AgentClient] WebSocket agentStatus \u4E8B\u4EF6\u89E6\u53D1: ${e.status}`)}),this.wsClient.on("disconnected",(e,t)=>{const n=t?.toString()||"";i.warn("[AgentClient] WebSocket \u65AD\u5F00\u8FDE\u63A5: code=%s, reason=%s, agentId=%s, \u6B63\u5728\u81EA\u52A8\u91CD\u8FDE",e,n,this.agentId)}),this.wsClient.on("error",e=>{i.error("[AgentClient] WebSocket \u9519\u8BEF: %s, stack=%s",e.message,e.stack)}),this.wsClient.on("reconnectFailed",()=>{i.error("[AgentClient] \u91CD\u8FDE\u5931\u8D25\uFF08\u5DF2\u8FBE\u91CD\u8BD5\u4E0A\u9650\uFF09\uFF0C\u505C\u6B62\u6D88\u606F\u5FAA\u73AF, agentId=%s",this.agentId),this.stop()}),this.wsClient.on("tokenRejected",()=>{i.error("[AgentClient] runtime token \u88AB 1008 \u62D2\u7EDD\u4E14\u5237\u65B0\u65E0\u53D8\u5316\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85\u65B0 token \u7B7E\u53D1: agentId=%s",this.agentId)}),this.wsClient.on("tokenRefreshFailed",e=>{i.error("[AgentClient] runtime token \u5237\u65B0\u8FDE\u7EED\u5931\u8D25 %s \u6B21\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85 bridge \u6062\u590D: agentId=%s",e,this.agentId)})}async register(){return i.info("[AgentClient] \u6B63\u5728\u6CE8\u518C Agent..."),await this.retryPendingLaunchBindingClaim(),this.hasPresetAgentId()?await this.registerWithExistingAgentId():await this.registerAsNewAgent()}hasPresetAgentId(){return!!(this.agentConfig.agentId&&this.agentConfig.agentId.trim().length>0)}async registerWithExistingAgentId(){const e=this.agentConfig.agentId;if(!e)throw new Error("Preset agentId is missing");this.agentId=e.trim();let t;try{t=await this.getProfileByAgentId(this.agentId)}catch(r){throw i.error("[AgentClient] getProfileByAgentId \u5931\u8D25 (presetAgentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}this.displayName=t.displayName,this.projectId=t.projectId||null,i.info(`[AgentClient] \u4F7F\u7528\u9884\u8BBE AgentID \u7ED1\u5B9A\u5B9E\u4F8B: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`);try{await this.wsClient.connect(this.agentId)}catch(r){throw i.error("[AgentClient] WebSocket \u8FDE\u63A5\u5931\u8D25 (agentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter();const n=await this.getProfileByAgentId(this.agentId);return this.displayName=n.displayName,this.projectId=n.projectId||null,u(n.roleName||"unknown-role",n.instanceName||this.agentId),{agentId:this.agentId,displayName:this.displayName,status:n.isOnline?"online":"offline",projectId:n.projectId,workspacePath:n.workspacePath,runtimeStatus:n.runtimeStatus,runtimeSessionId:n.runtimeSessionId}}async registerAsNewAgent(){const e=await this.httpClient.callTool("register",{roleName:this.agentConfig.roleName,projectId:this.agentConfig.projectId,workspacePath:this.agentConfig.workspacePath,prompt:this.agentConfig.prompt,runtimeBridgeBaseUrl:this.serverConfig.runtimeBridgeBaseUrl}),t=e.agentId;if(!t)throw new Error("Registration failed: agentId was not returned");return this.agentId=t,this.displayName=e.displayName,this.projectId=e.projectId||null,u(this.agentConfig.roleName||"unknown-role",e.instanceName||t),i.info(`[AgentClient] \u6CE8\u518C\u6210\u529F: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u72B6\u6001: ${e.status}`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`),await this.wsClient.connect(this.agentId),i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter(),e.isExisting===!1&&this.newCharacterHandler&&this.newCharacterHandler(),e}async unregister(){i.info("[AgentClient] \u6B63\u5728\u6CE8\u9500 Agent..."),this.agentId&&await this.httpClient.callTool("unregister",{agentId:this.agentId}),this.stopRuntimeTokenRefresh(),this.wsClient.disconnect(),this.agentId=null,this.displayName=null,this.projectId=null,this.isRunning=!1,i.info("[AgentClient] \u5DF2\u6CE8\u9500")}async discoverColleagues(){return await this.httpClient.callTool("discover_colleague",{agentId:this.agentId})}async discoverGroupRooms(){return this.ensureRegistered(),await this.httpClient.callTool("discover_group_rooms",{agentId:this.agentId})}async listProjectMembers(){return this.ensureRegistered(),await this.httpClient.callTool("list_project_members",{agentId:this.agentId})}async hireColleague(e){return this.ensureRegistered(),await this.httpClient.callTool("hire_colleague",{...e,agentId:this.agentId})}async callAgentScopedTool(e,t){this.ensureRegistered();const n={...t,agentId:this.agentId};if(e==="create_meeting"){const r=typeof t.waitTimeoutMs=="number"?t.waitTimeoutMs:Number.NaN,s=Number.isFinite(r)&&r>0?Math.min(r,C):C;return await this.httpClient.callToolOnce(e,{...n,waitTimeoutMs:s},0)}return await this.httpClient.callTool(e,n)}async reportMemoryStats(e){await this.callAgentScopedTool("report_memory_stats",{memoryStats:e})}async sendGroupMessage(e,t,n,r,s){this.ensureRegistered();const a=t||this.projectId||this.agentConfig.projectId;return await this.httpClient.callTool("send_group_message",{agentId:this.agentId,projectId:a,roomId:n,content:e,card:r,replyTo:s})}async sendDirectMessage(e,t,n=!1,r,s,a,h,l){this.ensureRegistered();const o={agentId:this.agentId,targetId:e,content:t,requireReply:n,waitReply:n,replyToCallId:r,card:a,replyTo:h};if(typeof s=="number"&&s>0&&(o.timeoutMs=s),l?.priority&&l.priority!=="normal"&&(o.priority=l.priority,o.force=l.priority==="force",l.intent&&(o.intent=l.intent),l.ref&&(o.ref=l.ref),l.reason&&(o.reason=l.reason)),n){const g=typeof s=="number"&&s>0?s+3e4:0;return await this.httpClient.callToolOnce("send_dm",o,g)}return await this.httpClient.callTool("send_dm",o)}async sendCallAndWaitReply(e,t,n=6e4){const r=await this.sendDirectMessage(e,t,!0,void 0,n);if(r.reply)return r.reply;throw new Error("No reply received for call-style direct message before timeout")}async replyToCall(e,t,n){return await this.sendDirectMessage(t,n,!1,e)}async sendEmail(e){return await this.callAgentScopedTool("send_email",e)}async listEmails(e){return await this.callAgentScopedTool("list_emails",e)}async readEmail(e){return await this.callAgentScopedTool("read_email",{mailId:e})}async replyEmail(e){return await this.callAgentScopedTool("reply_email",e)}async ackEmail(e){return await this.callAgentScopedTool("ack_email",{mailId:e})}async getDmHistory(e,t=50,n){this.ensureRegistered();const r={agentId:this.agentId,targetUserId:e,limit:t};return n&&(r.since=n),await this.httpClient.callTool("get_dm_history",r)}async getGroupHistory(e=50,t,n){if(this.ensureRegistered(),t){const o={projectId:this.projectId||this.agentConfig.projectId,roomId:t,limit:e};return n&&(o.since=n),await this.httpClient.callTool("get_group_history",o)}const r=await this.discoverGroupRooms(),s=this.projectId||this.agentConfig.projectId,a=this.collectRoomIds(r,s);if(a.length===0)return{messages:[],count:0};const l=(await Promise.all(a.map(async o=>{const g={projectId:s,roomId:o,limit:e};return n&&(g.since=n),await this.httpClient.callTool("get_group_history",g)}))).flatMap(o=>o.messages).sort((o,g)=>new Date(o.timestamp).getTime()-new Date(g.timestamp).getTime());return{messages:l,count:l.length}}async fetchUnreadMessages(e={}){this.ensureRegistered();const t=this.projectId||this.agentConfig.projectId,n={agentId:this.agentId,blockIfEmpty:e.blockIfEmpty??!1};e.since&&(n.since=e.since),e.blockTimeoutMs&&e.blockTimeoutMs>0&&(n.blockTimeoutMs=e.blockTimeoutMs),e.preemptiveJoinWaitMs!==void 0&&e.preemptiveJoinWaitMs!==null&&e.preemptiveJoinWaitMs>=0&&(n.preemptiveJoinWaitMs=e.preemptiveJoinWaitMs);const r=e.includePipelineTasks?"poll_message":"get_dm_messages";i.info("[AgentClient] fetchUnreadMessages \u5165\u53E3: tool=%s, blockIfEmpty=%s, blockTimeoutMs=%s, pollMessageTimeoutMs=%s, skipGroupMessages=%s, preemptiveJoinWaitMs=%s, agentId=%s",r,String(e.blockIfEmpty??!1),String(e.blockTimeoutMs??"-"),String(e.pollMessageTimeoutMs??"-"),String(e.skipGroupMessages??!1),String(e.preemptiveJoinWaitMs??"-"),this.agentId);const s=await this.fetchDirectMessagesWithRecovery(r,n,e.pollMessageTimeoutMs,e.propagatePollTimeout===!0);if(i.info("[AgentClient] fetchUnreadMessages \u79C1\u4FE1\u9636\u6BB5\u8FD4\u56DE: %s \u6761",Array.isArray(s.messages)?s.messages.length:0),e.skipGroupMessages)return i.info("[AgentClient] \u4F1A\u8BAE\u5FEB\u901F hydrate \u5DF2\u53D6\u5F97\u79C1\u4FE1\u54CD\u5E94\uFF0C\u8DF3\u8FC7\u7FA4\u804A\u53D1\u73B0\u5E76\u7ACB\u5373\u8FD4\u56DE: directMessages=%s",Array.isArray(s.messages)?s.messages.length:0),{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:[]};let a;try{a=await this.discoverGroupRooms()}catch(o){i.warn("[AgentClient] \u53D1\u73B0\u7FA4\u623F\u95F4\u5931\u8D25\uFF0C\u672C\u6B21\u6309\u65E0\u7FA4\u6D88\u606F\u5904\u7406\uFF08\u5DF2\u53D6\u5230\u7684\u79C1\u4FE1\u4E0D\u53D7\u5F71\u54CD\uFF09: %s",o instanceof Error?o.message:String(o)),a={groups:[]}}const h=this.collectRoomIds(a,t),l=await Promise.all(h.map(async o=>{const g={agentId:this.agentId,projectId:t,roomId:o};e.since&&(g.since=e.since);try{return await this.httpClient.callTool("get_group_messages",g)}catch(d){return i.warn("[AgentClient] \u8DF3\u8FC7\u7FA4\u623F\u95F4\u672A\u8BFB\u8865\u62C9\u5931\u8D25: roomId=%s, error=%s",o,d instanceof Error?d.message:String(d)),{messages:[],currentReadPos:0,hasMore:!1}}}));return{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:l.flatMap(o=>this.normalizeGroupMessages(o)).sort((o,g)=>new Date(o.timestamp).getTime()-new Date(g.timestamp).getTime())}}async markDmRead(e){if(e.length===0)return new Set;this.ensureRegistered();try{const t=await this.httpClient.callTool("mark_dm_read",{agentId:this.agentId,msgIds:e}),n=new Set(Array.isArray(t?.deliverableMsgIds)?t.deliverableMsgIds:[]),r=e.filter(s=>!n.has(s));return r.length>0?i.warn("[AgentClient] mark_dm_read \u786E\u8BA4\u540E\u5C06\u6709 %d \u6761\u6D88\u606F\u88AB\u4E22\u5F03\u4E0D\u4EA4\u4ED8: \u8BF7\u6C42=%s, \u53EF\u4EA4\u4ED8=%s, \u88AB\u4E22\u5F03=%s",r.length,JSON.stringify(e),JSON.stringify([...n]),JSON.stringify(r)):i.info("[AgentClient] mark_dm_read \u786E\u8BA4\u5B8C\u6210: %d \u6761\u5168\u90E8\u53EF\u4EA4\u4ED8",e.length),n}catch(t){throw i.warn("[AgentClient] mark_dm_read \u8BF7\u6C42\u5931\u8D25\uFF08\u5C06\u964D\u7EA7\u4E3A\u76F4\u63A5\u4EA4\u4ED8\uFF09: %s",t instanceof Error?t.message:String(t)),t}}async markForceInjected(e){if(e.length===0)return new Set;this.ensureRegistered();try{const t=await this.httpClient.callTool("mark_force_injected",{agentId:this.agentId,msgIds:e}),n=new Set(Array.isArray(t?.deliverableMsgIds)?t.deliverableMsgIds:[]),r=e.filter(s=>!n.has(s));return r.length>0?i.warn("[AgentClient] mark_force_injected \u786E\u8BA4\u540E\u5C06\u6709 %d \u6761\u5F3A\u5236\u6D88\u606F\u88AB\u4E22\u5F03\u4E0D\u4EA4\u4ED8: \u8BF7\u6C42=%s, \u53EF\u4EA4\u4ED8=%s",r.length,JSON.stringify(e),JSON.stringify([...n])):i.info("[AgentClient] mark_force_injected \u786E\u8BA4\u5B8C\u6210: %d \u6761\u5F3A\u5236\u6D88\u606F\u5DF2\u6CE8\u5165",e.length),n}catch(t){throw i.warn("[AgentClient] mark_force_injected \u8BF7\u6C42\u5931\u8D25\uFF08\u5C06\u964D\u7EA7\u4E3A\u76F4\u63A5\u4EA4\u4ED8\uFF09: %s",t instanceof Error?t.message:String(t)),t}}async markGroupRead(e,t){if(t.length===0)return new Set;this.ensureRegistered();const n=await this.httpClient.callTool("mark_group_read",{agentId:this.agentId,roomId:e,msgIds:t});return new Set(Array.isArray(n?.deliverableMsgIds)?n.deliverableMsgIds:[])}async markNotificationRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_notification_read",{agentId:this.agentId,msgIds:e})}catch{}}}async markMeetingRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_meeting_read",{agentId:this.agentId,msgIds:e})}catch{}}}async fetchBrowserListenerEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return i.info("[AgentClient] fetchBrowserListenerEvents \u8DF3\u8FC7: bridgeBaseUrl=%s, agentId=%s",e||"(\u7A7A)",t||"(\u7A7A)"),[];try{const n=`${e}/runtime/browser-listeners/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"";i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6: url=%s, tokenLen=%d",n,r.length);const s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),[];const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s, eventsType=%s",a.ok,Array.isArray(a.events)?"array":typeof a.events),[]):(i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6",a.events.length),a.events)}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),[]}}async fetchPluginEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return{revision:0,events:[]};try{const n=`${e}/runtime/plugin-events/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),{revision:0,events:[]};const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s",String(a.ok)),{revision:0,events:[]}):(i.debug("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6, revision=%s",a.events.length,String(a.revision??0)),{revision:a.revision??0,events:a.events})}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),{revision:0,events:[]}}}async notifyBridgeForceMessage(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!(!e||!t))try{const n=`${e}/runtime/sessions/${encodeURIComponent(t)}/notify-force-message`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"POST",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});s.ok||i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5931\u8D25: HTTP %s, url=%s",s.status,n)}catch(n){i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5F02\u5E38: %s",n instanceof Error?n.message:String(n))}}async fetchCurrentAction(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return null;try{const n=`${e}/runtime/sessions/${encodeURIComponent(t)}/current-action`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u67E5\u8BE2 bridge \u5F53\u524D\u52A8\u4F5C\u5931\u8D25: HTTP %s, url=%s",s.status,n),null;const a=await s.json();return a?.ok?a:null}catch(n){return i.warn("[AgentClient] \u67E5\u8BE2 bridge \u5F53\u524D\u52A8\u4F5C\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),null}}async fetchDirectMessagesWithRecovery(e,t,n,r=!1){if(e==="poll_message"){i.info("[AgentClient] fetchDirectMessagesWithRecovery \u5165\u53E3: tool=poll_message, pollMessageTimeoutMs=%s, agentId=%s",String(n??"(\u9ED8\u8BA4)"),String(t?.agentId??""));try{const s=await this.httpClient.callToolOnce(e,t,n);return i.info("[AgentClient] fetchDirectMessagesWithRecovery poll_message \u6210\u529F\u8FD4\u56DE: %s \u6761",Array.isArray(s?.messages)?s.messages.length:0),s}catch(s){if(this.isRecoverableLongPollError(s)){if(r)throw new T(s instanceof Error?s.message:String(s));return i.warn("[AgentClient] poll_message \u5355\u6B21\u957F\u8F6E\u8BE2\u8D85\u65F6\uFF0C\u6309\u7A7A\u7ED3\u679C\u9000\u907F\u540E\u7EE7\u7EED\u7B49\u5F85:",s),{messages:[]}}throw s}}return await this.httpClient.callTool(e,t)}isRecoverableLongPollError(e){return e instanceof Error?/MCP tool poll_message call failed: 503(?:\s|$)/.test(e.message)||/MCP tool poll_message timed out after \d+ms/.test(e.message):!1}normalizeGroupMessages(e){return Array.isArray(e.messages)?e.messages.filter(t=>!!(t&&typeof t=="object"&&typeof t.msgId=="number"&&typeof t.senderId=="string"&&typeof t.content=="string"&&typeof t.timestamp=="string")):[]}collectRoomIds(e,t){const n=e.groups.filter(r=>r.projectId===t).map(r=>r.id);return Array.from(new Set(n))}async getProfile(){this.ensureRegistered();const e=this.agentId;if(!e)throw new Error("Agent is not registered");return{...await this.getProfileByAgentId(e),describe:this.agentConfig.describe}}async getProfileByAgentId(e){return await this.httpClient.callTool("get_profile",{agentId:e})}async getMyTasks(){return this.ensureRegistered(),await this.httpClient.callTool("my_task",{agentId:this.agentId})}async listTaskNodeIterations(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_task_node_iterations",{agentId:this.agentId,...e})}async createTaskInstanceComment(e){this.ensureRegistered();const t={agentId:this.agentId,...e};return await this.httpClient.callTool("create_task_instance_comment",t)}async submitTaskResult(e,t,n,r,s){this.ensureRegistered();const a={agentId:this.agentId,nodeId:e,outputPayload:t};return(Array.isArray(n)&&n.length>0||typeof n=="string"&&n.trim().length>0)&&(a.changeLog=n),typeof r=="string"&&r.trim().length>0&&(a.handoverNote=r),s&&Array.isArray(s)&&s.length>0&&(a.deliverables=s),await this.httpClient.callTool("submit_task_result",a)}async startTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("start_task_rollback",{agentId:this.agentId,...e})}async finishTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("finish_task_rollback",{agentId:this.agentId,...e})}async getDebugLogConfig(){return await this.httpClient.callTool("get_debug_log_config",{agentId:this.agentId})}async queryDebugLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("query_debug_logs",{...e})}async queryFileChangesHistory(e){return this.ensureRegistered(),await this.httpClient.callTool("query_file_changes_history",{...e})}async listColleagueEvents(e){return this.ensureRegistered(),await this.httpClient.callTool("list_colleague_events",{...e})}async getRuntimeFeatures(){return await this.httpClient.fetchRuntimeFeatures()}async listLaunchConfigs(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_list",{})}async createLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_create",{...e})}async updateLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_update",{...e})}async deleteLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_delete",{configId:e})}async startLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_start",e,t+6e4):await this.httpClient.callTool("launch_config_start",{...e})}async restartLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_restart",e,t+6e4):await this.httpClient.callTool("launch_config_restart",{...e})}async stopLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_stop",{configId:e})}async getLaunchLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_logs",{...e})}async listLaunchRuns(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_status",{})}async listAbilityMarket(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_ability_market",{...e})}async installAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("install_ability_market_item",{...e})}async uninstallAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("uninstall_ability_market_item",{...e})}async abilityDevIde(e){return this.ensureRegistered(),await this.httpClient.callTool("ability_dev_ide",{...e})}async formalAbility(e){return this.ensureRegistered(),await this.httpClient.callTool("formal_ability",{...e})}async listMyAbilities(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_my_abilities",{...e})}start(e,t){if(this.isRunning){i.warn("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u5DF2\u5728\u8FD0\u884C\u4E2D");return}this.isDegradedMode||this.ensureRegistered(),this.messageHandler=e,this.profileHandler=t?.profileHandler||null,this.configHandler=t?.configHandler||null,this.systemNotifyHandler=t?.systemNotifyHandler||null,this.isRunning=!0,i.info(`[AgentClient] start() \u88AB\u8C03\u7528\uFF0CcachedProfile: ${this.cachedProfile?"\u5B58\u5728":"\u4E0D\u5B58\u5728"}, profileHandler: ${this.profileHandler?"\u5DF2\u8BBE\u7F6E":"\u672A\u8BBE\u7F6E"}, \u964D\u7EA7\u6A21\u5F0F: ${this.isDegradedMode?"\u662F":"\u5426"}`),this.cachedProfile&&this.profileHandler&&(i.info(`[AgentClient] \u5904\u7406\u7F13\u5B58\u7684 Profile \u4FE1\u606F: ${this.cachedProfile.displayName}`),this.profileHandler(this.cachedProfile),this.cachedProfile=null),t?.pollMode??!1?(i.warn("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08HTTP\u8F6E\u8BE2\u6A21\u5F0F - \u4E0D\u63A8\u8350\uFF09"),this.messageLoop()):i.info("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08WebSocket\u63A8\u9001\u6A21\u5F0F - \u63A8\u8350\uFF09")}stop(){this.isRunning=!1,this.pollTimer&&(clearTimeout(this.pollTimer),this.pollTimer=null),this.stopRuntimeTokenRefresh(),i.info("[AgentClient] \u6D88\u606F\u4E3B\u5FAA\u73AF\u5DF2\u505C\u6B62")}async messageLoop(){for(;this.isRunning;)try{await this.delay(I)}catch(e){i.error("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u9519\u8BEF:",e),await this.delay(5e3)}}handleIncomingDm(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingGroup(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingMeeting(e){!e||e.senderId===this.agentId||this.processMessage(e)}handleProfileInfo(e){i.info(`[AgentClient] \u6536\u5230 Profile \u4FE1\u606F: ${e.displayName} (${e.roleName})`),e.projectId&&(this.projectId=e.projectId,i.info(`[AgentClient] \u66F4\u65B0\u6240\u5C5E\u9879\u76EE: ${this.projectId}`)),e.roleName&&e.roleName!==this.agentConfig.roleName&&(i.info(`[AgentClient] \u540C\u6B65\u89D2\u8272\u540D: "${this.agentConfig.roleName||"(\u7A7A)"}" -> "${e.roleName}"`),this.agentConfig.roleName=e.roleName),e.roleName&&u(e.roleName,e.instanceName||this.agentId||""),this.profileHandler?this.profileHandler(e):(i.info("[AgentClient] profileHandler \u672A\u8BBE\u7F6E\uFF0C\u7F13\u5B58 Profile \u4FE1\u606F"),this.cachedProfile=e)}async processMessage(e){if(!this.messageHandler)return;const t=typeof e.msgId=="string";i.info(`[AgentClient] \u6536\u5230${t?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F"}\u6765\u81EA ${e.senderName}: ${e.content.substring(0,50)}...`);try{const n=await this.messageHandler(e);if(t){const r=e;r.requireReply&&r.callId&&await this.replyToCall(r.callId,r.senderId,n||"\u5DF2\u6536\u5230\u6D88\u606F\uFF0C\u6B63\u5728\u5904\u7406\u4E2D...")}}catch(n){const r=typeof e.msgId=="string";if(i.error("[AgentClient] \u5904\u7406\u6D88\u606F\u5931\u8D25: type=%s, senderId=%s, senderName=%s, msgId=%s, error=%s",r?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F",e.senderId,e.senderName,e.msgId,n instanceof Error?n.message:String(n)),r){const s=e;s.requireReply&&s.callId&&await this.replyToCall(s.callId,s.senderId,`\u5904\u7406\u5931\u8D25: ${n}`)}}}ensureRegistered(){if(!this.agentId)throw new Error("Agent is not registered")}delay(e){return new Promise(t=>{this.pollTimer=setTimeout(t,e)})}onNewCharacter(e){this.newCharacterHandler=e}getState(){return{agentId:this.agentId,displayName:this.displayName,projectId:this.projectId,isConnected:this.wsClient.isConnected(),isRunning:this.isRunning}}getAgentConfig(){return this.agentConfig}getServerConfig(){return this.serverConfig}reloadConfig(){c.loadConfig(),this.agentConfig=c.getAgentConfig(),i.info(`[AgentClient] \u914D\u7F6E\u5DF2\u91CD\u65B0\u52A0\u8F7D\uFF0C\u89D2\u8272: ${this.agentConfig.roleName}`)}enterDegradedMode(){this.isDegradedMode=!0,i.warn("[AgentClient] \u8FDB\u5165\u964D\u7EA7\u6A21\u5F0F\uFF0C\u5C06\u5728\u540E\u53F0\u6301\u7EED\u5C1D\u8BD5\u91CD\u8FDE")}exitDegradedMode(){this.isDegradedMode=!1,i.info("[AgentClient] \u9000\u51FA\u964D\u7EA7\u6A21\u5F0F")}isInDegradedMode(){return this.isDegradedMode}async retryRegistrationInBackground(e,t){let n=0;(async()=>{for(;this.isDegradedMode;)try{i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u5C1D\u8BD5\u91CD\u65B0\u6CE8\u518C (${n+1}/${t===-1?"\u65E0\u9650":t})`);const s=await this.register();i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u6210\u529F - ${s.displayName} (${s.agentId})`),this.exitDegradedMode(),this.messageHandler&&this.start(this.messageHandler);return}catch(s){n++;const a=s instanceof Error?s.message:String(s);if(i.warn(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u5931\u8D25 (${n}/${t===-1?"\u65E0\u9650":t}): ${a}`),t>0&&n>=t){i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u505C\u6B62\u91CD\u8FDE"),this.isDegradedMode=!1;return}await new Promise(h=>setTimeout(h,e))}})().catch(s=>{i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\u540E\u53F0\u91CD\u8BD5\u5FAA\u73AF\u5F02\u5E38\u9000\u51FA: error=%s, stack=%s",s instanceof Error?s.message:String(s),s instanceof Error?s.stack:"(no stack)")})}initializeStatusReporter(){if(!this.agentId){i.warn("[AgentClient] \u65E0\u6CD5\u521D\u59CB\u5316\u72B6\u6001\u62A5\u544A\u5668\uFF1AagentId \u4E3A\u7A7A");return}this.statusReporter=new A({agentId:this.agentId,sendStatusUpdate:e=>{this.wsClient.send({type:"AGENT_STATUS",data:e,timestamp:new Date().toISOString()})}}),w(e=>this.reportMcpNodeLog(e)),this.startRuntimeTokenRefresh(),i.info("[AgentClient] \u72B6\u6001\u62A5\u544A\u5668\u5DF2\u521D\u59CB\u5316")}startRuntimeTokenRefresh(){this.stopRuntimeTokenRefresh();const e=this.serverConfig.runtimeTokenRefreshIntervalMs;if(!e||e<=0){i.warn("[AgentClient] runtimeTokenRefreshIntervalMs \u672A\u914D\u7F6E\u6216\u65E0\u6548\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}const t=this.agentId;if(!t){i.warn("[AgentClient] agentId \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}this.runtimeTokenRefreshTimer=setInterval(async()=>{try{await this.httpClient.refreshRuntimeAccessToken(t)&&i.info("[AgentClient] runtimeAccessToken \u5DF2\u4E3B\u52A8\u7EED\u671F")}catch(n){i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F runtimeAccessToken \u5931\u8D25: %s",n instanceof Error?n.message:String(n)),n instanceof Error&&n.stack&&i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F\u5F02\u5E38\u5806\u6808:",n.stack)}},e),this.runtimeTokenRefreshTimer.unref?.(),i.info(`[AgentClient] runtime token \u4E3B\u52A8\u7EED\u671F\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694 ${e}ms`)}stopRuntimeTokenRefresh(){this.runtimeTokenRefreshTimer&&(clearInterval(this.runtimeTokenRefreshTimer),this.runtimeTokenRefreshTimer=null)}reportMcpNodeLog(e){const t=this.wsClient;!this.agentId||!this.wsClient.isConnected()||typeof t.sendMcpNodeLog!="function"||t.sendMcpNodeLog(e)}getStatusReporter(){return this.statusReporter}}export{N as AgentClient,T as PollLongPollTimeoutError};
|
|
2
2
|
|
|
@@ -157,6 +157,8 @@ export declare class McpServer {
|
|
|
157
157
|
|
|
158
158
|
private handleToolCall;
|
|
159
159
|
|
|
160
|
+
private reconcilePanelActionWithAuthority;
|
|
161
|
+
|
|
160
162
|
private safeReportStatus;
|
|
161
163
|
|
|
162
164
|
private executeToolCall;
|
|
@@ -181,9 +183,12 @@ export declare class McpServer {
|
|
|
181
183
|
private getOptionalNumber;
|
|
182
184
|
private getOptionalStringArray;
|
|
183
185
|
private getOptionalMemoryType;
|
|
186
|
+
|
|
184
187
|
private parseMemoryType;
|
|
185
188
|
private isMemoryType;
|
|
186
189
|
|
|
190
|
+
private isAgentWritableMemoryType;
|
|
191
|
+
|
|
187
192
|
private getMemoryStoreForType;
|
|
188
193
|
|
|
189
194
|
private readMemoryFromScopedStores;
|