@tencent-ai/cloud-agent-sdk 0.2.13 → 0.2.14-next.cb03fb2.20260319
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/e2b-filesystem-4-LU6-jg.cjs +168 -0
- package/dist/e2b-filesystem-4-LU6-jg.cjs.map +1 -0
- package/dist/e2b-filesystem-BNmEfpoW.mjs +162 -0
- package/dist/e2b-filesystem-BNmEfpoW.mjs.map +1 -0
- package/dist/e2b-filesystem-B_WoA22S.cjs +252 -0
- package/dist/e2b-filesystem-B_WoA22S.cjs.map +1 -0
- package/dist/e2b-filesystem-Cac-bpRR.cjs +3 -0
- package/dist/e2b-filesystem-DM_jsT05.mjs +234 -0
- package/dist/e2b-filesystem-DM_jsT05.mjs.map +1 -0
- package/dist/e2b-filesystem-DWj9UkV8.mjs +3 -0
- package/dist/e2b-filesystem-DcVVT_tP.cjs +4 -0
- package/dist/e2b-filesystem-UheQECjB.mjs +3 -0
- package/dist/index.cjs +2177 -383
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1840 -72
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1840 -72
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2169 -376
- package/dist/index.mjs.map +1 -1
- package/dist/legacy/index.cjs +24008 -0
- package/dist/legacy/index.cjs.map +1 -0
- package/dist/legacy/index.d.cts +6387 -0
- package/dist/legacy/index.d.cts.map +1 -0
- package/dist/legacy/index.d.mts +6387 -0
- package/dist/legacy/index.d.mts.map +1 -0
- package/dist/legacy/index.mjs +13284 -0
- package/dist/legacy/index.mjs.map +1 -0
- package/dist/tencent-ai-cloud-agent-sdk-0.2.14-next.cb03fb2.20260319.tgz +0 -0
- package/package.json +44 -7
- package/dist/tencent-ai-cloud-agent-sdk-0.2.13.tgz +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { t as E2BFilesystem } from "./e2b-filesystem-BNmEfpoW.mjs";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { ClientSideConnection, PROTOCOL_VERSION } from "@agentclientprotocol/sdk";
|
|
3
4
|
import "@bufbuild/protobuf";
|
|
4
5
|
import "@connectrpc/connect";
|
|
5
6
|
import "@connectrpc/connect-web";
|
|
6
|
-
import { Sandbox } from "e2b";
|
|
7
7
|
|
|
8
8
|
//#region rolldown:runtime
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
@@ -54,7 +54,6 @@ const ToolInputSchemas = {
|
|
|
54
54
|
queryString: z.string().describe("用户的实际问题或搜索查询"),
|
|
55
55
|
knowledgeBaseNames: z.string().describe("知识库名称,多个用逗号分隔")
|
|
56
56
|
}),
|
|
57
|
-
read_rules: z.object({ ruleNames: z.string().describe("要读取的规则关键词,用逗号分隔,格式:{ruleName}_{ruleId}") }),
|
|
58
57
|
mcp_get_tool_description: z.object({ toolRequests: z.string().describe("JSON 字符串,二维数组格式:[[\"server1\", \"tool1\"], [\"server2\", \"tool2\"]]") }),
|
|
59
58
|
mcp_call_tool: z.object({
|
|
60
59
|
serverName: z.string().describe("MCP 服务器名称"),
|
|
@@ -68,13 +67,6 @@ const ToolInputSchemas = {
|
|
|
68
67
|
arguments: z.record(z.unknown()).optional().describe("资源模板的参数"),
|
|
69
68
|
downloadPath: z.string().optional().describe("可选的绝对路径,用于保存资源到磁盘")
|
|
70
69
|
}),
|
|
71
|
-
create_rule: z.object({
|
|
72
|
-
ruleScope: z.string().describe("规则范围,project rule 或 user rule"),
|
|
73
|
-
ruleName: z.string().describe("规则文件名,不带扩展名"),
|
|
74
|
-
ruleType: z.string().describe("规则类型,always、manual 或 requested"),
|
|
75
|
-
ruleContent: z.string().describe("规则内容,使用 Markdown 格式"),
|
|
76
|
-
ruleDescription: z.string().optional().describe("规则描述,使用 Markdown 格式")
|
|
77
|
-
}),
|
|
78
70
|
update_memory: z.object({
|
|
79
71
|
action: z.enum([
|
|
80
72
|
"create",
|
|
@@ -133,7 +125,6 @@ const ToolInputSchemas = {
|
|
|
133
125
|
cloud_studio_fetch_log: z.object({}).passthrough(),
|
|
134
126
|
cloud_studio_execute_command: z.object({}).passthrough(),
|
|
135
127
|
cloud_studio_deploy_sandbox: z.object({}).passthrough(),
|
|
136
|
-
component_get_prompt: z.object({}).passthrough(),
|
|
137
128
|
web_fetch: z.object({
|
|
138
129
|
url: z.string().describe("要获取内容的 URL"),
|
|
139
130
|
fetchInfo: z.string().describe("用户想要获取的信息描述")
|
|
@@ -141,7 +132,9 @@ const ToolInputSchemas = {
|
|
|
141
132
|
use_skill: z.object({ command: z.string().describe("技能名称(不含参数),如 \"pdf\" 或 \"xlsx\"") }),
|
|
142
133
|
web_search: z.object({
|
|
143
134
|
explanation: z.string().describe("为什么使用此工具的一句话解释"),
|
|
144
|
-
|
|
135
|
+
query: z.string().describe("搜索关键词"),
|
|
136
|
+
max_results: z.number().optional().describe("最大返回数量"),
|
|
137
|
+
language: z.string().optional().describe("语言代码,例如 zh-CN")
|
|
145
138
|
}),
|
|
146
139
|
task: z.object({
|
|
147
140
|
subagent_name: z.string().describe("要调用的子代理名称"),
|
|
@@ -219,11 +212,6 @@ const ToolOutputSchemas = {
|
|
|
219
212
|
selectedKnowledgeBases: z.string(),
|
|
220
213
|
queryInput: z.string()
|
|
221
214
|
}),
|
|
222
|
-
read_rules: z.object({
|
|
223
|
-
type: z.literal("rule_match_result"),
|
|
224
|
-
ruleDescription: z.string(),
|
|
225
|
-
filePaths: z.array(z.string())
|
|
226
|
-
}),
|
|
227
215
|
mcp_get_tool_description: z.object({}).passthrough(),
|
|
228
216
|
mcp_call_tool: z.object({
|
|
229
217
|
type: z.literal("mcp_call_tool_result"),
|
|
@@ -260,17 +248,6 @@ const ToolOutputSchemas = {
|
|
|
260
248
|
content: z.string(),
|
|
261
249
|
downloadPath: z.string().optional()
|
|
262
250
|
}),
|
|
263
|
-
create_rule: z.object({
|
|
264
|
-
type: z.literal("rule_create_result"),
|
|
265
|
-
ruleName: z.string(),
|
|
266
|
-
createState: z.enum([
|
|
267
|
-
"success",
|
|
268
|
-
"invoke",
|
|
269
|
-
"cancelled"
|
|
270
|
-
]),
|
|
271
|
-
hint: z.string().optional(),
|
|
272
|
-
filePath: z.string().optional()
|
|
273
|
-
}),
|
|
274
251
|
update_memory: z.object({
|
|
275
252
|
type: z.literal("update_memory_result"),
|
|
276
253
|
success: z.boolean(),
|
|
@@ -284,9 +261,9 @@ const ToolOutputSchemas = {
|
|
|
284
261
|
}),
|
|
285
262
|
search_content: z.object({
|
|
286
263
|
type: z.literal("search_content_result"),
|
|
287
|
-
|
|
264
|
+
path: z.string(),
|
|
288
265
|
pattern: z.string(),
|
|
289
|
-
|
|
266
|
+
glob: z.string(),
|
|
290
267
|
matches: z.array(z.object({
|
|
291
268
|
filePath: z.string(),
|
|
292
269
|
content: z.string(),
|
|
@@ -298,7 +275,7 @@ const ToolOutputSchemas = {
|
|
|
298
275
|
totalCount: z.number(),
|
|
299
276
|
hasMore: z.boolean(),
|
|
300
277
|
offset: z.number(),
|
|
301
|
-
|
|
278
|
+
headLimit: z.number(),
|
|
302
279
|
contextBefore: z.number(),
|
|
303
280
|
contextAfter: z.number(),
|
|
304
281
|
contextAround: z.number().optional(),
|
|
@@ -484,15 +461,6 @@ const ToolOutputSchemas = {
|
|
|
484
461
|
}).optional()
|
|
485
462
|
}))
|
|
486
463
|
}),
|
|
487
|
-
component_get_prompt: z.object({
|
|
488
|
-
type: z.literal("component_get_prompt_result"),
|
|
489
|
-
componentType: z.string(),
|
|
490
|
-
webFramework: z.string(),
|
|
491
|
-
data: z.object({
|
|
492
|
-
type: z.literal("text"),
|
|
493
|
-
text: z.string()
|
|
494
|
-
})
|
|
495
|
-
}),
|
|
496
464
|
web_fetch: z.object({
|
|
497
465
|
type: z.literal("web_fetch_tool_result"),
|
|
498
466
|
message: z.string(),
|
|
@@ -508,14 +476,29 @@ const ToolOutputSchemas = {
|
|
|
508
476
|
}),
|
|
509
477
|
web_search: z.object({
|
|
510
478
|
type: z.literal("web_search_tool_result"),
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
479
|
+
query: z.string().optional(),
|
|
480
|
+
searchType: z.literal("text2text").optional(),
|
|
481
|
+
provider: z.string().optional(),
|
|
482
|
+
results: z.array(z.object({
|
|
515
483
|
title: z.string(),
|
|
516
|
-
|
|
517
|
-
|
|
484
|
+
url: z.string(),
|
|
485
|
+
snippet: z.string().optional(),
|
|
486
|
+
site: z.string().optional(),
|
|
487
|
+
highlights: z.array(z.string()).optional(),
|
|
488
|
+
content: z.string().optional(),
|
|
489
|
+
favicon: z.string().optional()
|
|
518
490
|
})),
|
|
491
|
+
images: z.array(z.object({
|
|
492
|
+
url: z.string(),
|
|
493
|
+
description: z.string().optional(),
|
|
494
|
+
sourceUrl: z.string().optional(),
|
|
495
|
+
width: z.number().optional(),
|
|
496
|
+
height: z.number().optional(),
|
|
497
|
+
title: z.string().optional(),
|
|
498
|
+
siteName: z.string().optional()
|
|
499
|
+
})),
|
|
500
|
+
totalResults: z.number().optional(),
|
|
501
|
+
responseTimeMs: z.number().optional(),
|
|
519
502
|
searchInput: z.string().optional()
|
|
520
503
|
}),
|
|
521
504
|
task: z.object({
|
|
@@ -661,7 +644,11 @@ const ExtensionMethod = {
|
|
|
661
644
|
CHECKPOINT: "_codebuddy.ai/checkpoint",
|
|
662
645
|
USAGE: "_codebuddy.ai/usage",
|
|
663
646
|
COMMAND: "_codebuddy.ai/command",
|
|
664
|
-
AUTH_URL: "_codebuddy.ai/authUrl"
|
|
647
|
+
AUTH_URL: "_codebuddy.ai/authUrl",
|
|
648
|
+
FILE_HISTORY_SNAPSHOT: "_codebuddy.ai/file_history_snapshot",
|
|
649
|
+
DELEGATE_TOOL: "_codebuddy.ai/delegateTool",
|
|
650
|
+
DELEGATE_TOOLS_CHANGED: "_codebuddy.ai/delegateToolsChanged",
|
|
651
|
+
UI_CONTROL: "_codebuddy.ai/uiControl"
|
|
665
652
|
};
|
|
666
653
|
/**
|
|
667
654
|
* All known extension methods
|
|
@@ -672,7 +659,10 @@ const KNOWN_EXTENSIONS = [
|
|
|
672
659
|
ExtensionMethod.CHECKPOINT,
|
|
673
660
|
ExtensionMethod.USAGE,
|
|
674
661
|
ExtensionMethod.COMMAND,
|
|
675
|
-
ExtensionMethod.AUTH_URL
|
|
662
|
+
ExtensionMethod.AUTH_URL,
|
|
663
|
+
ExtensionMethod.FILE_HISTORY_SNAPSHOT,
|
|
664
|
+
ExtensionMethod.DELEGATE_TOOL,
|
|
665
|
+
ExtensionMethod.DELEGATE_TOOLS_CHANGED
|
|
676
666
|
];
|
|
677
667
|
|
|
678
668
|
//#endregion
|
|
@@ -723,7 +713,7 @@ function parseSSELine(line, currentEvent) {
|
|
|
723
713
|
};
|
|
724
714
|
}
|
|
725
715
|
function streamableHttp(options) {
|
|
726
|
-
const { endpoint, authToken, headers: customHeaders = {}, reconnect = {}, signal: externalSignal, fetch: customFetch = globalThis.fetch, onConnect, onDisconnect, onError, heartbeatTimeout = 6e4, postTimeout = 3e4, backpressure = {} } = options;
|
|
716
|
+
const { endpoint, authToken, headers: customHeaders = {}, reconnect = {}, signal: externalSignal, fetch: customFetch = globalThis.fetch, onConnect, onDisconnect, onError, heartbeatTimeout = 6e4, connectionTimeout = 3e4, postTimeout = 3e4, backpressure = {} } = options;
|
|
727
717
|
const { enabled: reconnectEnabled = true, initialDelay = 1e3, maxDelay = 3e4, maxRetries = Infinity, jitter: jitterEnabled = true } = reconnect;
|
|
728
718
|
const { highWaterMark = 100, lowWaterMark = 50, pauseTimeout = 5e3 } = backpressure;
|
|
729
719
|
let connectionId;
|
|
@@ -934,11 +924,21 @@ function streamableHttp(options) {
|
|
|
934
924
|
const headers = buildHeaders();
|
|
935
925
|
headers["Accept"] = "text/event-stream";
|
|
936
926
|
if (lastEventId) headers["Last-Event-ID"] = lastEventId;
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
});
|
|
927
|
+
const connectTimeoutMs = connectionTimeout > 0 ? connectionTimeout : 3e4;
|
|
928
|
+
const connectController = new AbortController();
|
|
929
|
+
const connectTimer = setTimeout(() => connectController.abort(), connectTimeoutMs);
|
|
930
|
+
if (externalSignal) externalSignal.addEventListener("abort", () => connectController.abort(), { once: true });
|
|
931
|
+
abortController.signal.addEventListener("abort", () => connectController.abort(), { once: true });
|
|
932
|
+
let response;
|
|
933
|
+
try {
|
|
934
|
+
response = await customFetch(endpoint, {
|
|
935
|
+
method: "GET",
|
|
936
|
+
headers,
|
|
937
|
+
signal: connectController.signal
|
|
938
|
+
});
|
|
939
|
+
} finally {
|
|
940
|
+
clearTimeout(connectTimer);
|
|
941
|
+
}
|
|
942
942
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
943
943
|
const newConnectionId = response.headers.get("Acp-Connection-Id");
|
|
944
944
|
if (!newConnectionId) throw new Error("Server did not return Acp-Connection-Id header");
|
|
@@ -1874,6 +1874,9 @@ var StreamableHttpClient = class {
|
|
|
1874
1874
|
headers: this.options.headers,
|
|
1875
1875
|
reconnect: this.options.reconnect,
|
|
1876
1876
|
fetch: this.options.fetch,
|
|
1877
|
+
heartbeatTimeout: this.options.heartbeatTimeout,
|
|
1878
|
+
postTimeout: this.options.postTimeout,
|
|
1879
|
+
connectionTimeout: this.options.connectionTimeout,
|
|
1877
1880
|
onConnect: (connectionId) => {
|
|
1878
1881
|
this.options.logger?.debug(`Transport connected: ${connectionId}`);
|
|
1879
1882
|
},
|
|
@@ -1948,10 +1951,6 @@ var StreamableHttpClient = class {
|
|
|
1948
1951
|
},
|
|
1949
1952
|
requestPermission: async (params) => this.handleRequestPermission(params),
|
|
1950
1953
|
extNotification: async (method, params) => {
|
|
1951
|
-
console.log("[ACP-Client] extNotification callback invoked:", {
|
|
1952
|
-
method,
|
|
1953
|
-
paramsKeys: Object.keys(params)
|
|
1954
|
-
});
|
|
1955
1954
|
await this.handleExtNotification(method, params);
|
|
1956
1955
|
},
|
|
1957
1956
|
extMethod: async (method, params) => this.handleExtMethod(method, params)
|
|
@@ -1959,10 +1958,15 @@ var StreamableHttpClient = class {
|
|
|
1959
1958
|
}
|
|
1960
1959
|
/**
|
|
1961
1960
|
* Create a new session
|
|
1961
|
+
*
|
|
1962
|
+
* Retries on transient network errors (e.g., proxy connection reset)
|
|
1963
|
+
* since session/new is idempotent and safe to retry.
|
|
1962
1964
|
*/
|
|
1963
1965
|
async createSession(cwd) {
|
|
1964
1966
|
this.ensureInitialized("createSession");
|
|
1965
|
-
|
|
1967
|
+
const maxRetries = 2;
|
|
1968
|
+
let lastError;
|
|
1969
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) try {
|
|
1966
1970
|
const response = await this.connection.newSession({
|
|
1967
1971
|
cwd,
|
|
1968
1972
|
mcpServers: []
|
|
@@ -1970,8 +1974,16 @@ var StreamableHttpClient = class {
|
|
|
1970
1974
|
this.options.logger?.info(`Session created: ${response.sessionId}`);
|
|
1971
1975
|
return response;
|
|
1972
1976
|
} catch (err) {
|
|
1973
|
-
|
|
1977
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
1978
|
+
if (attempt < maxRetries && isRetryableNetworkError(err)) {
|
|
1979
|
+
const delay = 500 * Math.pow(2, attempt);
|
|
1980
|
+
this.options.logger?.warn(`session/new network error, retrying in ${delay}ms (attempt ${attempt + 1}/${maxRetries}): ${lastError.message}`);
|
|
1981
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
throw new SessionError(`Failed to create session: ${lastError.message}`, void 0, lastError);
|
|
1974
1985
|
}
|
|
1986
|
+
throw new SessionError(`Failed to create session: ${lastError?.message}`, void 0, lastError);
|
|
1975
1987
|
}
|
|
1976
1988
|
/**
|
|
1977
1989
|
* Load an existing session
|
|
@@ -2195,6 +2207,18 @@ var StreamableHttpClient = class {
|
|
|
2195
2207
|
if (this.state !== "initialized") throw new InvalidStateError(operation, this.state, ["initialized"]);
|
|
2196
2208
|
}
|
|
2197
2209
|
};
|
|
2210
|
+
/**
|
|
2211
|
+
* Check if an error is a retryable network-level error.
|
|
2212
|
+
* Only network failures (TypeError from fetch) are retried, NOT HTTP errors (4xx/5xx).
|
|
2213
|
+
*/
|
|
2214
|
+
function isRetryableNetworkError(error) {
|
|
2215
|
+
if (error instanceof TypeError) return true;
|
|
2216
|
+
if (error instanceof Error) {
|
|
2217
|
+
const msg = error.message.toLowerCase();
|
|
2218
|
+
return msg.includes("failed to fetch") || msg.includes("fetch failed") || msg.includes("network request failed") || msg.includes("econnreset") || msg.includes("econnrefused") || msg.includes("socket hang up");
|
|
2219
|
+
}
|
|
2220
|
+
return false;
|
|
2221
|
+
}
|
|
2198
2222
|
|
|
2199
2223
|
//#endregion
|
|
2200
2224
|
//#region ../agent-provider/src/common/providers/cloud-agent-provider/cloud-connection.ts
|
|
@@ -2230,7 +2254,7 @@ var CloudAgentConnection = class {
|
|
|
2230
2254
|
fetch: config.fetch,
|
|
2231
2255
|
clientCapabilities: config.clientCapabilities,
|
|
2232
2256
|
onSessionUpdate: (update) => {
|
|
2233
|
-
if (!this._isStreaming) this.emit("sessionUpdate", update);
|
|
2257
|
+
if (!this._isStreaming && this.isOwnSessionNotification(update)) this.emit("sessionUpdate", update);
|
|
2234
2258
|
},
|
|
2235
2259
|
onArtifact: (artifact, event) => {
|
|
2236
2260
|
console.log("[CloudConnection] onArtifact callback:", {
|
|
@@ -2244,10 +2268,41 @@ var CloudAgentConnection = class {
|
|
|
2244
2268
|
},
|
|
2245
2269
|
onUsageUpdate: (usage) => {
|
|
2246
2270
|
this.emit("usageUpdate", usage);
|
|
2271
|
+
},
|
|
2272
|
+
onExtNotification: (method, params) => {
|
|
2273
|
+
console.log("[CloudConnection] Received extNotification:", {
|
|
2274
|
+
method,
|
|
2275
|
+
paramsKeys: Object.keys(params)
|
|
2276
|
+
});
|
|
2277
|
+
if (method === ExtensionMethod.COMMAND) {
|
|
2278
|
+
const action = params.action;
|
|
2279
|
+
const commandParams = params.params;
|
|
2280
|
+
console.log("[CloudConnection] Emitting command event:", {
|
|
2281
|
+
action,
|
|
2282
|
+
paramsKeys: commandParams ? Object.keys(commandParams) : []
|
|
2283
|
+
});
|
|
2284
|
+
this.emit("command", {
|
|
2285
|
+
action,
|
|
2286
|
+
params: commandParams
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2247
2289
|
}
|
|
2248
2290
|
});
|
|
2249
2291
|
this.setupEventForwarding();
|
|
2250
2292
|
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Check whether a notification belongs to this connection's own session.
|
|
2295
|
+
*
|
|
2296
|
+
* CloudConnection.createSession() overrides sessionId to agentId, so the
|
|
2297
|
+
* rest of the client stack uses agentId as the canonical session
|
|
2298
|
+
* identifier. Notifications whose sessionId differs from agentId
|
|
2299
|
+
* originate from sub-agent sessions running inside the same sandbox and
|
|
2300
|
+
* should be silently ignored at this layer — the adapter layer handles
|
|
2301
|
+
* sub-agent messages independently via parentToolUseId in _meta.
|
|
2302
|
+
*/
|
|
2303
|
+
isOwnSessionNotification(notification) {
|
|
2304
|
+
return notification.sessionId === this.agentId;
|
|
2305
|
+
}
|
|
2251
2306
|
setupEventForwarding() {
|
|
2252
2307
|
this.client.on("connecting", () => {
|
|
2253
2308
|
this.emit("connecting", void 0);
|
|
@@ -2408,6 +2463,7 @@ var CloudAgentConnection = class {
|
|
|
2408
2463
|
let resolveUpdate = null;
|
|
2409
2464
|
let done = false;
|
|
2410
2465
|
const listener = (update) => {
|
|
2466
|
+
if (!this.isOwnSessionNotification(update)) return;
|
|
2411
2467
|
if (resolveUpdate) {
|
|
2412
2468
|
resolveUpdate(update);
|
|
2413
2469
|
resolveUpdate = null;
|
|
@@ -2490,6 +2546,16 @@ var CloudAgentConnection = class {
|
|
|
2490
2546
|
get sessionConnectionInfo() {
|
|
2491
2547
|
return this._sessionConnectionInfo;
|
|
2492
2548
|
}
|
|
2549
|
+
async reportTelemetry(eventName, payload) {
|
|
2550
|
+
try {
|
|
2551
|
+
await this.client.extMethod("reportTelemetry", {
|
|
2552
|
+
eventName,
|
|
2553
|
+
payload
|
|
2554
|
+
});
|
|
2555
|
+
} catch (error) {
|
|
2556
|
+
console.warn("[CloudAgentConnection] reportTelemetry failed:", error);
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2493
2559
|
async extMethod(method, params) {
|
|
2494
2560
|
return this.client.extMethod(method, params);
|
|
2495
2561
|
}
|
|
@@ -3092,7 +3158,7 @@ var utils_default = {
|
|
|
3092
3158
|
*
|
|
3093
3159
|
* @returns {Error} The created error.
|
|
3094
3160
|
*/
|
|
3095
|
-
function AxiosError(message, code, config, request, response) {
|
|
3161
|
+
function AxiosError$1(message, code, config, request, response) {
|
|
3096
3162
|
Error.call(this);
|
|
3097
3163
|
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
3098
3164
|
else this.stack = (/* @__PURE__ */ new Error()).stack;
|
|
@@ -3106,7 +3172,7 @@ function AxiosError(message, code, config, request, response) {
|
|
|
3106
3172
|
this.status = response.status ? response.status : null;
|
|
3107
3173
|
}
|
|
3108
3174
|
}
|
|
3109
|
-
utils_default.inherits(AxiosError, Error, { toJSON: function toJSON() {
|
|
3175
|
+
utils_default.inherits(AxiosError$1, Error, { toJSON: function toJSON() {
|
|
3110
3176
|
return {
|
|
3111
3177
|
message: this.message,
|
|
3112
3178
|
name: this.name,
|
|
@@ -3121,7 +3187,7 @@ utils_default.inherits(AxiosError, Error, { toJSON: function toJSON() {
|
|
|
3121
3187
|
status: this.status
|
|
3122
3188
|
};
|
|
3123
3189
|
} });
|
|
3124
|
-
const prototype$1 = AxiosError.prototype;
|
|
3190
|
+
const prototype$1 = AxiosError$1.prototype;
|
|
3125
3191
|
const descriptors = {};
|
|
3126
3192
|
[
|
|
3127
3193
|
"ERR_BAD_OPTION_VALUE",
|
|
@@ -3139,22 +3205,22 @@ const descriptors = {};
|
|
|
3139
3205
|
].forEach((code) => {
|
|
3140
3206
|
descriptors[code] = { value: code };
|
|
3141
3207
|
});
|
|
3142
|
-
Object.defineProperties(AxiosError, descriptors);
|
|
3208
|
+
Object.defineProperties(AxiosError$1, descriptors);
|
|
3143
3209
|
Object.defineProperty(prototype$1, "isAxiosError", { value: true });
|
|
3144
|
-
AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
3210
|
+
AxiosError$1.from = (error, code, config, request, response, customProps) => {
|
|
3145
3211
|
const axiosError = Object.create(prototype$1);
|
|
3146
3212
|
utils_default.toFlatObject(error, axiosError, function filter(obj) {
|
|
3147
3213
|
return obj !== Error.prototype;
|
|
3148
3214
|
}, (prop) => {
|
|
3149
3215
|
return prop !== "isAxiosError";
|
|
3150
3216
|
});
|
|
3151
|
-
AxiosError.call(axiosError, error.message, code, config, request, response);
|
|
3217
|
+
AxiosError$1.call(axiosError, error.message, code, config, request, response);
|
|
3152
3218
|
axiosError.cause = error;
|
|
3153
3219
|
axiosError.name = error.name;
|
|
3154
3220
|
customProps && Object.assign(axiosError, customProps);
|
|
3155
3221
|
return axiosError;
|
|
3156
3222
|
};
|
|
3157
|
-
var AxiosError_default = AxiosError;
|
|
3223
|
+
var AxiosError_default = AxiosError$1;
|
|
3158
3224
|
|
|
3159
3225
|
//#endregion
|
|
3160
3226
|
//#region ../agent-provider/node_modules/axios/lib/helpers/null.js
|
|
@@ -3233,7 +3299,7 @@ const predicates = utils_default.toFlatObject(utils_default, {}, null, function
|
|
|
3233
3299
|
*
|
|
3234
3300
|
* @returns
|
|
3235
3301
|
*/
|
|
3236
|
-
function toFormData(obj, formData, options) {
|
|
3302
|
+
function toFormData$1(obj, formData, options) {
|
|
3237
3303
|
if (!utils_default.isObject(obj)) throw new TypeError("target must be an object");
|
|
3238
3304
|
formData = formData || new (null_default || FormData)();
|
|
3239
3305
|
options = utils_default.toFlatObject(options, {
|
|
@@ -3304,7 +3370,7 @@ function toFormData(obj, formData, options) {
|
|
|
3304
3370
|
build(obj);
|
|
3305
3371
|
return formData;
|
|
3306
3372
|
}
|
|
3307
|
-
var toFormData_default = toFormData;
|
|
3373
|
+
var toFormData_default = toFormData$1;
|
|
3308
3374
|
|
|
3309
3375
|
//#endregion
|
|
3310
3376
|
//#region ../agent-provider/node_modules/axios/lib/helpers/AxiosURLSearchParams.js
|
|
@@ -3821,7 +3887,7 @@ function buildAccessors(obj, header) {
|
|
|
3821
3887
|
});
|
|
3822
3888
|
});
|
|
3823
3889
|
}
|
|
3824
|
-
var AxiosHeaders = class {
|
|
3890
|
+
var AxiosHeaders$1 = class {
|
|
3825
3891
|
constructor(headers) {
|
|
3826
3892
|
headers && this.set(headers);
|
|
3827
3893
|
}
|
|
@@ -3959,7 +4025,7 @@ var AxiosHeaders = class {
|
|
|
3959
4025
|
return this;
|
|
3960
4026
|
}
|
|
3961
4027
|
};
|
|
3962
|
-
AxiosHeaders.accessor([
|
|
4028
|
+
AxiosHeaders$1.accessor([
|
|
3963
4029
|
"Content-Type",
|
|
3964
4030
|
"Content-Length",
|
|
3965
4031
|
"Accept",
|
|
@@ -3967,7 +4033,7 @@ AxiosHeaders.accessor([
|
|
|
3967
4033
|
"User-Agent",
|
|
3968
4034
|
"Authorization"
|
|
3969
4035
|
]);
|
|
3970
|
-
utils_default.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
|
|
4036
|
+
utils_default.reduceDescriptors(AxiosHeaders$1.prototype, ({ value }, key) => {
|
|
3971
4037
|
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
3972
4038
|
return {
|
|
3973
4039
|
get: () => value,
|
|
@@ -3976,8 +4042,8 @@ utils_default.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
|
|
|
3976
4042
|
}
|
|
3977
4043
|
};
|
|
3978
4044
|
});
|
|
3979
|
-
utils_default.freezeMethods(AxiosHeaders);
|
|
3980
|
-
var AxiosHeaders_default = AxiosHeaders;
|
|
4045
|
+
utils_default.freezeMethods(AxiosHeaders$1);
|
|
4046
|
+
var AxiosHeaders_default = AxiosHeaders$1;
|
|
3981
4047
|
|
|
3982
4048
|
//#endregion
|
|
3983
4049
|
//#region ../agent-provider/node_modules/axios/lib/core/transformData.js
|
|
@@ -4003,7 +4069,7 @@ function transformData(fns, response) {
|
|
|
4003
4069
|
|
|
4004
4070
|
//#endregion
|
|
4005
4071
|
//#region ../agent-provider/node_modules/axios/lib/cancel/isCancel.js
|
|
4006
|
-
function isCancel(value) {
|
|
4072
|
+
function isCancel$1(value) {
|
|
4007
4073
|
return !!(value && value.__CANCEL__);
|
|
4008
4074
|
}
|
|
4009
4075
|
|
|
@@ -4018,12 +4084,12 @@ function isCancel(value) {
|
|
|
4018
4084
|
*
|
|
4019
4085
|
* @returns {CanceledError} The created error.
|
|
4020
4086
|
*/
|
|
4021
|
-
function CanceledError(message, config, request) {
|
|
4087
|
+
function CanceledError$1(message, config, request) {
|
|
4022
4088
|
AxiosError_default.call(this, message == null ? "canceled" : message, AxiosError_default.ERR_CANCELED, config, request);
|
|
4023
4089
|
this.name = "CanceledError";
|
|
4024
4090
|
}
|
|
4025
|
-
utils_default.inherits(CanceledError, AxiosError_default, { __CANCEL__: true });
|
|
4026
|
-
var CanceledError_default = CanceledError;
|
|
4091
|
+
utils_default.inherits(CanceledError$1, AxiosError_default, { __CANCEL__: true });
|
|
4092
|
+
var CanceledError_default = CanceledError$1;
|
|
4027
4093
|
|
|
4028
4094
|
//#endregion
|
|
4029
4095
|
//#region ../agent-provider/node_modules/axios/lib/core/settle.js
|
|
@@ -4250,7 +4316,7 @@ const headersToObject = (thing) => thing instanceof AxiosHeaders_default ? { ...
|
|
|
4250
4316
|
*
|
|
4251
4317
|
* @returns {Object} New object resulting from merging config2 to config1
|
|
4252
4318
|
*/
|
|
4253
|
-
function mergeConfig(config1, config2) {
|
|
4319
|
+
function mergeConfig$1(config1, config2) {
|
|
4254
4320
|
config2 = config2 || {};
|
|
4255
4321
|
const config = {};
|
|
4256
4322
|
function getMergedValue(target, source, prop, caseless) {
|
|
@@ -4316,7 +4382,7 @@ function mergeConfig(config1, config2) {
|
|
|
4316
4382
|
//#endregion
|
|
4317
4383
|
//#region ../agent-provider/node_modules/axios/lib/helpers/resolveConfig.js
|
|
4318
4384
|
var resolveConfig_default = (config) => {
|
|
4319
|
-
const newConfig = mergeConfig({}, config);
|
|
4385
|
+
const newConfig = mergeConfig$1({}, config);
|
|
4320
4386
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
4321
4387
|
newConfig.headers = headers = AxiosHeaders_default.from(headers);
|
|
4322
4388
|
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
|
|
@@ -4747,7 +4813,7 @@ function dispatchRequest(config) {
|
|
|
4747
4813
|
response.headers = AxiosHeaders_default.from(response.headers);
|
|
4748
4814
|
return response;
|
|
4749
4815
|
}, function onAdapterRejection(reason) {
|
|
4750
|
-
if (!isCancel(reason)) {
|
|
4816
|
+
if (!isCancel$1(reason)) {
|
|
4751
4817
|
throwIfCancellationRequested(config);
|
|
4752
4818
|
if (reason && reason.response) {
|
|
4753
4819
|
reason.response.data = transformData.call(config, config.transformResponse, reason.response);
|
|
@@ -4760,7 +4826,7 @@ function dispatchRequest(config) {
|
|
|
4760
4826
|
|
|
4761
4827
|
//#endregion
|
|
4762
4828
|
//#region ../agent-provider/node_modules/axios/lib/env/data.js
|
|
4763
|
-
const VERSION = "1.10.0";
|
|
4829
|
+
const VERSION$1 = "1.10.0";
|
|
4764
4830
|
|
|
4765
4831
|
//#endregion
|
|
4766
4832
|
//#region ../agent-provider/node_modules/axios/lib/helpers/validator.js
|
|
@@ -4789,7 +4855,7 @@ const deprecatedWarnings = {};
|
|
|
4789
4855
|
*/
|
|
4790
4856
|
validators$1.transitional = function transitional(validator, version, message) {
|
|
4791
4857
|
function formatMessage(opt, desc) {
|
|
4792
|
-
return "[Axios v" + VERSION + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
|
|
4858
|
+
return "[Axios v" + VERSION$1 + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
|
|
4793
4859
|
}
|
|
4794
4860
|
return (value, opt, opts) => {
|
|
4795
4861
|
if (validator === false) throw new AxiosError_default(formatMessage(opt, " has been removed" + (version ? " in " + version : "")), AxiosError_default.ERR_DEPRECATED);
|
|
@@ -4846,7 +4912,7 @@ const validators = validator_default.validators;
|
|
|
4846
4912
|
*
|
|
4847
4913
|
* @return {Axios} A new instance of Axios
|
|
4848
4914
|
*/
|
|
4849
|
-
var Axios = class {
|
|
4915
|
+
var Axios$1 = class {
|
|
4850
4916
|
constructor(instanceConfig) {
|
|
4851
4917
|
this.defaults = instanceConfig || {};
|
|
4852
4918
|
this.interceptors = {
|
|
@@ -4883,7 +4949,7 @@ var Axios = class {
|
|
|
4883
4949
|
config = config || {};
|
|
4884
4950
|
config.url = configOrUrl;
|
|
4885
4951
|
} else config = configOrUrl || {};
|
|
4886
|
-
config = mergeConfig(this.defaults, config);
|
|
4952
|
+
config = mergeConfig$1(this.defaults, config);
|
|
4887
4953
|
const { transitional, paramsSerializer, headers } = config;
|
|
4888
4954
|
if (transitional !== void 0) validator_default.assertOptions(transitional, {
|
|
4889
4955
|
silentJSONParsing: validators.transitional(validators.boolean),
|
|
@@ -4962,7 +5028,7 @@ var Axios = class {
|
|
|
4962
5028
|
return promise;
|
|
4963
5029
|
}
|
|
4964
5030
|
getUri(config) {
|
|
4965
|
-
config = mergeConfig(this.defaults, config);
|
|
5031
|
+
config = mergeConfig$1(this.defaults, config);
|
|
4966
5032
|
return buildURL(buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls), config.params, config.paramsSerializer);
|
|
4967
5033
|
}
|
|
4968
5034
|
};
|
|
@@ -4972,8 +5038,8 @@ utils_default.forEach([
|
|
|
4972
5038
|
"head",
|
|
4973
5039
|
"options"
|
|
4974
5040
|
], function forEachMethodNoData(method) {
|
|
4975
|
-
Axios.prototype[method] = function(url, config) {
|
|
4976
|
-
return this.request(mergeConfig(config || {}, {
|
|
5041
|
+
Axios$1.prototype[method] = function(url, config) {
|
|
5042
|
+
return this.request(mergeConfig$1(config || {}, {
|
|
4977
5043
|
method,
|
|
4978
5044
|
url,
|
|
4979
5045
|
data: (config || {}).data
|
|
@@ -4987,7 +5053,7 @@ utils_default.forEach([
|
|
|
4987
5053
|
], function forEachMethodWithData(method) {
|
|
4988
5054
|
function generateHTTPMethod(isForm) {
|
|
4989
5055
|
return function httpMethod(url, data, config) {
|
|
4990
|
-
return this.request(mergeConfig(config || {}, {
|
|
5056
|
+
return this.request(mergeConfig$1(config || {}, {
|
|
4991
5057
|
method,
|
|
4992
5058
|
headers: isForm ? { "Content-Type": "multipart/form-data" } : {},
|
|
4993
5059
|
url,
|
|
@@ -4995,10 +5061,10 @@ utils_default.forEach([
|
|
|
4995
5061
|
}));
|
|
4996
5062
|
};
|
|
4997
5063
|
}
|
|
4998
|
-
Axios.prototype[method] = generateHTTPMethod();
|
|
4999
|
-
Axios.prototype[method + "Form"] = generateHTTPMethod(true);
|
|
5064
|
+
Axios$1.prototype[method] = generateHTTPMethod();
|
|
5065
|
+
Axios$1.prototype[method + "Form"] = generateHTTPMethod(true);
|
|
5000
5066
|
});
|
|
5001
|
-
var Axios_default = Axios;
|
|
5067
|
+
var Axios_default = Axios$1;
|
|
5002
5068
|
|
|
5003
5069
|
//#endregion
|
|
5004
5070
|
//#region ../agent-provider/node_modules/axios/lib/cancel/CancelToken.js
|
|
@@ -5009,7 +5075,7 @@ var Axios_default = Axios;
|
|
|
5009
5075
|
*
|
|
5010
5076
|
* @returns {CancelToken}
|
|
5011
5077
|
*/
|
|
5012
|
-
var CancelToken = class CancelToken {
|
|
5078
|
+
var CancelToken$1 = class CancelToken$1 {
|
|
5013
5079
|
constructor(executor) {
|
|
5014
5080
|
if (typeof executor !== "function") throw new TypeError("executor must be a function.");
|
|
5015
5081
|
let resolvePromise;
|
|
@@ -5081,14 +5147,14 @@ var CancelToken = class CancelToken {
|
|
|
5081
5147
|
static source() {
|
|
5082
5148
|
let cancel;
|
|
5083
5149
|
return {
|
|
5084
|
-
token: new CancelToken(function executor(c) {
|
|
5150
|
+
token: new CancelToken$1(function executor(c) {
|
|
5085
5151
|
cancel = c;
|
|
5086
5152
|
}),
|
|
5087
5153
|
cancel
|
|
5088
5154
|
};
|
|
5089
5155
|
}
|
|
5090
5156
|
};
|
|
5091
|
-
var CancelToken_default = CancelToken;
|
|
5157
|
+
var CancelToken_default = CancelToken$1;
|
|
5092
5158
|
|
|
5093
5159
|
//#endregion
|
|
5094
5160
|
//#region ../agent-provider/node_modules/axios/lib/helpers/spread.js
|
|
@@ -5113,7 +5179,7 @@ var CancelToken_default = CancelToken;
|
|
|
5113
5179
|
*
|
|
5114
5180
|
* @returns {Function}
|
|
5115
5181
|
*/
|
|
5116
|
-
function spread(callback) {
|
|
5182
|
+
function spread$1(callback) {
|
|
5117
5183
|
return function wrap(arr) {
|
|
5118
5184
|
return callback.apply(null, arr);
|
|
5119
5185
|
};
|
|
@@ -5128,13 +5194,13 @@ function spread(callback) {
|
|
|
5128
5194
|
*
|
|
5129
5195
|
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
|
5130
5196
|
*/
|
|
5131
|
-
function isAxiosError(payload) {
|
|
5197
|
+
function isAxiosError$1(payload) {
|
|
5132
5198
|
return utils_default.isObject(payload) && payload.isAxiosError === true;
|
|
5133
5199
|
}
|
|
5134
5200
|
|
|
5135
5201
|
//#endregion
|
|
5136
5202
|
//#region ../agent-provider/node_modules/axios/lib/helpers/HttpStatusCode.js
|
|
5137
|
-
const HttpStatusCode = {
|
|
5203
|
+
const HttpStatusCode$1 = {
|
|
5138
5204
|
Continue: 100,
|
|
5139
5205
|
SwitchingProtocols: 101,
|
|
5140
5206
|
Processing: 102,
|
|
@@ -5199,10 +5265,10 @@ const HttpStatusCode = {
|
|
|
5199
5265
|
NotExtended: 510,
|
|
5200
5266
|
NetworkAuthenticationRequired: 511
|
|
5201
5267
|
};
|
|
5202
|
-
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
|
5203
|
-
HttpStatusCode[value] = key;
|
|
5268
|
+
Object.entries(HttpStatusCode$1).forEach(([key, value]) => {
|
|
5269
|
+
HttpStatusCode$1[value] = key;
|
|
5204
5270
|
});
|
|
5205
|
-
var HttpStatusCode_default = HttpStatusCode;
|
|
5271
|
+
var HttpStatusCode_default = HttpStatusCode$1;
|
|
5206
5272
|
|
|
5207
5273
|
//#endregion
|
|
5208
5274
|
//#region ../agent-provider/node_modules/axios/lib/axios.js
|
|
@@ -5219,7 +5285,7 @@ function createInstance(defaultConfig) {
|
|
|
5219
5285
|
utils_default.extend(instance, Axios_default.prototype, context, { allOwnKeys: true });
|
|
5220
5286
|
utils_default.extend(instance, context, null, { allOwnKeys: true });
|
|
5221
5287
|
instance.create = function create(instanceConfig) {
|
|
5222
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
5288
|
+
return createInstance(mergeConfig$1(defaultConfig, instanceConfig));
|
|
5223
5289
|
};
|
|
5224
5290
|
return instance;
|
|
5225
5291
|
}
|
|
@@ -5227,17 +5293,17 @@ const axios = createInstance(defaults_default);
|
|
|
5227
5293
|
axios.Axios = Axios_default;
|
|
5228
5294
|
axios.CanceledError = CanceledError_default;
|
|
5229
5295
|
axios.CancelToken = CancelToken_default;
|
|
5230
|
-
axios.isCancel = isCancel;
|
|
5231
|
-
axios.VERSION = VERSION;
|
|
5296
|
+
axios.isCancel = isCancel$1;
|
|
5297
|
+
axios.VERSION = VERSION$1;
|
|
5232
5298
|
axios.toFormData = toFormData_default;
|
|
5233
5299
|
axios.AxiosError = AxiosError_default;
|
|
5234
5300
|
axios.Cancel = axios.CanceledError;
|
|
5235
5301
|
axios.all = function all(promises) {
|
|
5236
5302
|
return Promise.all(promises);
|
|
5237
5303
|
};
|
|
5238
|
-
axios.spread = spread;
|
|
5239
|
-
axios.isAxiosError = isAxiosError;
|
|
5240
|
-
axios.mergeConfig = mergeConfig;
|
|
5304
|
+
axios.spread = spread$1;
|
|
5305
|
+
axios.isAxiosError = isAxiosError$1;
|
|
5306
|
+
axios.mergeConfig = mergeConfig$1;
|
|
5241
5307
|
axios.AxiosHeaders = AxiosHeaders_default;
|
|
5242
5308
|
axios.formToJSON = (thing) => formDataToJSON_default(utils_default.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
5243
5309
|
axios.getAdapter = adapters_default.getAdapter;
|
|
@@ -5245,6 +5311,10 @@ axios.HttpStatusCode = HttpStatusCode_default;
|
|
|
5245
5311
|
axios.default = axios;
|
|
5246
5312
|
var axios_default = axios;
|
|
5247
5313
|
|
|
5314
|
+
//#endregion
|
|
5315
|
+
//#region ../agent-provider/node_modules/axios/index.js
|
|
5316
|
+
const { Axios, AxiosError, CanceledError, isCancel, CancelToken, VERSION, all, Cancel, isAxiosError, spread, toFormData, AxiosHeaders, HttpStatusCode, formToJSON, getAdapter, mergeConfig } = axios_default;
|
|
5317
|
+
|
|
5248
5318
|
//#endregion
|
|
5249
5319
|
//#region ../agent-provider/src/http/http-service.ts
|
|
5250
5320
|
/**
|
|
@@ -5253,7 +5323,7 @@ var axios_default = axios;
|
|
|
5253
5323
|
* 特性:
|
|
5254
5324
|
* - 单例模式,全局唯一实例,延迟初始化(首次使用时自动创建)
|
|
5255
5325
|
* - 支持拦截器注册(其他模块可注入 header)
|
|
5256
|
-
* - 统一 401
|
|
5326
|
+
* - 统一 401 处理(支持自动刷新 token 并重试)
|
|
5257
5327
|
* - 自动携带凭证(withCredentials)
|
|
5258
5328
|
* - 类型安全
|
|
5259
5329
|
*
|
|
@@ -5293,6 +5363,8 @@ var HttpService = class HttpService {
|
|
|
5293
5363
|
*/
|
|
5294
5364
|
constructor(config = {}) {
|
|
5295
5365
|
this.unauthorizedCallbacks = /* @__PURE__ */ new Set();
|
|
5366
|
+
this.isRefreshing = false;
|
|
5367
|
+
this.refreshSubscribers = [];
|
|
5296
5368
|
this.config = config;
|
|
5297
5369
|
this.axiosInstance = axios_default.create({
|
|
5298
5370
|
baseURL: config.baseURL?.replace(/\/$/, "") || "",
|
|
@@ -5333,18 +5405,54 @@ var HttpService = class HttpService {
|
|
|
5333
5405
|
}, (error) => Promise.reject(error));
|
|
5334
5406
|
}
|
|
5335
5407
|
/**
|
|
5336
|
-
* 注册默认响应拦截器(处理 401
|
|
5408
|
+
* 注册默认响应拦截器(处理 401,支持自动重试)
|
|
5337
5409
|
*/
|
|
5338
5410
|
registerDefaultResponseInterceptor() {
|
|
5339
|
-
this.axiosInstance.interceptors.response.use((response) => response, (error) => {
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5411
|
+
this.axiosInstance.interceptors.response.use((response) => response, async (error) => {
|
|
5412
|
+
const originalRequest = error.config;
|
|
5413
|
+
if (error.response?.status === 401 && originalRequest && !originalRequest._retry) {
|
|
5414
|
+
if (originalRequest.url?.includes("/console/accounts")) {
|
|
5415
|
+
console.warn("[HttpService] Unauthorized 401 on refresh endpoint, not retrying");
|
|
5416
|
+
return Promise.reject(error);
|
|
5417
|
+
}
|
|
5418
|
+
console.warn("[HttpService] Unauthorized 401, attempting token refresh and retry");
|
|
5419
|
+
originalRequest._retry = true;
|
|
5420
|
+
if (this.isRefreshing) return new Promise((resolve, reject) => {
|
|
5421
|
+
this.refreshSubscribers.push((success) => {
|
|
5422
|
+
if (success) this.axiosInstance.request(originalRequest).then(resolve).catch(reject);
|
|
5423
|
+
else reject(error);
|
|
5424
|
+
});
|
|
5425
|
+
});
|
|
5426
|
+
this.isRefreshing = true;
|
|
5427
|
+
try {
|
|
5428
|
+
await this.triggerUnauthorizedCallbacks();
|
|
5429
|
+
this.onRefreshSuccess();
|
|
5430
|
+
return this.axiosInstance.request(originalRequest);
|
|
5431
|
+
} catch (refreshError) {
|
|
5432
|
+
this.onRefreshFailure();
|
|
5433
|
+
return Promise.reject(error);
|
|
5434
|
+
} finally {
|
|
5435
|
+
this.isRefreshing = false;
|
|
5436
|
+
}
|
|
5343
5437
|
}
|
|
5344
5438
|
return Promise.reject(error);
|
|
5345
5439
|
});
|
|
5346
5440
|
}
|
|
5347
5441
|
/**
|
|
5442
|
+
* token 刷新成功,通知所有等待的请求
|
|
5443
|
+
*/
|
|
5444
|
+
onRefreshSuccess() {
|
|
5445
|
+
this.refreshSubscribers.forEach((callback) => callback(true));
|
|
5446
|
+
this.refreshSubscribers = [];
|
|
5447
|
+
}
|
|
5448
|
+
/**
|
|
5449
|
+
* token 刷新失败,通知所有等待的请求
|
|
5450
|
+
*/
|
|
5451
|
+
onRefreshFailure() {
|
|
5452
|
+
this.refreshSubscribers.forEach((callback) => callback(false));
|
|
5453
|
+
this.refreshSubscribers = [];
|
|
5454
|
+
}
|
|
5455
|
+
/**
|
|
5348
5456
|
* 注册请求拦截器
|
|
5349
5457
|
* @param onFulfilled 请求成功拦截器
|
|
5350
5458
|
* @param onRejected 请求失败拦截器
|
|
@@ -5421,16 +5529,18 @@ var HttpService = class HttpService {
|
|
|
5421
5529
|
this.unauthorizedCallbacks.delete(callback);
|
|
5422
5530
|
}
|
|
5423
5531
|
/**
|
|
5424
|
-
* 触发所有 401
|
|
5532
|
+
* 触发所有 401 回调并等待完成
|
|
5533
|
+
* @returns Promise,等待所有回调完成
|
|
5534
|
+
* @throws 如果任何回调失败,则抛出错误
|
|
5425
5535
|
*/
|
|
5426
|
-
triggerUnauthorizedCallbacks() {
|
|
5427
|
-
this.unauthorizedCallbacks
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
}
|
|
5536
|
+
async triggerUnauthorizedCallbacks() {
|
|
5537
|
+
const callbacks = Array.from(this.unauthorizedCallbacks);
|
|
5538
|
+
const failedResults = (await Promise.allSettled(callbacks.map((callback) => callback()))).filter((r) => r.status === "rejected");
|
|
5539
|
+
if (failedResults.length > 0) {
|
|
5540
|
+
const errors = failedResults.map((r) => r.reason);
|
|
5541
|
+
console.error("[HttpService] Some unauthorized callbacks failed:", errors);
|
|
5542
|
+
throw errors[0];
|
|
5543
|
+
}
|
|
5434
5544
|
}
|
|
5435
5545
|
/**
|
|
5436
5546
|
* 更新 authToken
|
|
@@ -5496,6 +5606,14 @@ var HttpService = class HttpService {
|
|
|
5496
5606
|
return (await this.axiosInstance.put(url, data, config)).data;
|
|
5497
5607
|
}
|
|
5498
5608
|
/**
|
|
5609
|
+
* 通用请求方法
|
|
5610
|
+
* @param config axios 请求配置
|
|
5611
|
+
* @returns 原始 AxiosResponse
|
|
5612
|
+
*/
|
|
5613
|
+
async request(config) {
|
|
5614
|
+
return this.axiosInstance.request(config);
|
|
5615
|
+
}
|
|
5616
|
+
/**
|
|
5499
5617
|
* 获取原始 axios 实例(用于高级场景)
|
|
5500
5618
|
*/
|
|
5501
5619
|
getAxiosInstance() {
|
|
@@ -5689,6 +5807,109 @@ const accountService = new AccountService();
|
|
|
5689
5807
|
*/
|
|
5690
5808
|
if (typeof window !== "undefined") window.__genieAccountService = accountService;
|
|
5691
5809
|
|
|
5810
|
+
//#endregion
|
|
5811
|
+
//#region ../agent-provider/src/common/utils/lru-cache.ts
|
|
5812
|
+
/**
|
|
5813
|
+
* LRU (Least Recently Used) Cache
|
|
5814
|
+
* 当缓存达到容量上限时,自动淘汰最久未使用的数据
|
|
5815
|
+
*
|
|
5816
|
+
* @template K - Key 类型
|
|
5817
|
+
* @template V - Value 类型
|
|
5818
|
+
*/
|
|
5819
|
+
var LRUCache = class {
|
|
5820
|
+
/**
|
|
5821
|
+
* 创建 LRU 缓存实例
|
|
5822
|
+
* @param capacity - 缓存容量上限
|
|
5823
|
+
*/
|
|
5824
|
+
constructor(capacity) {
|
|
5825
|
+
if (capacity <= 0) throw new Error("Cache capacity must be greater than 0");
|
|
5826
|
+
this.capacity = capacity;
|
|
5827
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
5828
|
+
}
|
|
5829
|
+
/**
|
|
5830
|
+
* 获取缓存值
|
|
5831
|
+
* @param key - 键
|
|
5832
|
+
* @returns 值,如果不存在返回 undefined
|
|
5833
|
+
*/
|
|
5834
|
+
get(key) {
|
|
5835
|
+
if (!this.cache.has(key)) return;
|
|
5836
|
+
const value = this.cache.get(key);
|
|
5837
|
+
this.cache.delete(key);
|
|
5838
|
+
this.cache.set(key, value);
|
|
5839
|
+
return value;
|
|
5840
|
+
}
|
|
5841
|
+
/**
|
|
5842
|
+
* 设置缓存值
|
|
5843
|
+
* @param key - 键
|
|
5844
|
+
* @param value - 值
|
|
5845
|
+
*/
|
|
5846
|
+
set(key, value) {
|
|
5847
|
+
if (this.cache.has(key)) this.cache.delete(key);
|
|
5848
|
+
else if (this.cache.size >= this.capacity) {
|
|
5849
|
+
const firstKey = this.cache.keys().next().value;
|
|
5850
|
+
this.cache.delete(firstKey);
|
|
5851
|
+
}
|
|
5852
|
+
this.cache.set(key, value);
|
|
5853
|
+
}
|
|
5854
|
+
/**
|
|
5855
|
+
* 检查 key 是否存在
|
|
5856
|
+
* @param key - 键
|
|
5857
|
+
* @returns 是否存在
|
|
5858
|
+
*/
|
|
5859
|
+
has(key) {
|
|
5860
|
+
return this.cache.has(key);
|
|
5861
|
+
}
|
|
5862
|
+
/**
|
|
5863
|
+
* 删除指定 key
|
|
5864
|
+
* @param key - 键
|
|
5865
|
+
* @returns 是否删除成功
|
|
5866
|
+
*/
|
|
5867
|
+
delete(key) {
|
|
5868
|
+
return this.cache.delete(key);
|
|
5869
|
+
}
|
|
5870
|
+
/**
|
|
5871
|
+
* 清空缓存
|
|
5872
|
+
*/
|
|
5873
|
+
clear() {
|
|
5874
|
+
this.cache.clear();
|
|
5875
|
+
}
|
|
5876
|
+
/**
|
|
5877
|
+
* 获取当前缓存大小
|
|
5878
|
+
* @returns 当前缓存的元素数量
|
|
5879
|
+
*/
|
|
5880
|
+
get size() {
|
|
5881
|
+
return this.cache.size;
|
|
5882
|
+
}
|
|
5883
|
+
/**
|
|
5884
|
+
* 获取缓存容量
|
|
5885
|
+
* @returns 缓存容量上限
|
|
5886
|
+
*/
|
|
5887
|
+
get maxSize() {
|
|
5888
|
+
return this.capacity;
|
|
5889
|
+
}
|
|
5890
|
+
/**
|
|
5891
|
+
* 获取所有 key
|
|
5892
|
+
* @returns key 数组
|
|
5893
|
+
*/
|
|
5894
|
+
keys() {
|
|
5895
|
+
return Array.from(this.cache.keys());
|
|
5896
|
+
}
|
|
5897
|
+
/**
|
|
5898
|
+
* 获取所有 value
|
|
5899
|
+
* @returns value 数组
|
|
5900
|
+
*/
|
|
5901
|
+
values() {
|
|
5902
|
+
return Array.from(this.cache.values());
|
|
5903
|
+
}
|
|
5904
|
+
/**
|
|
5905
|
+
* 遍历缓存
|
|
5906
|
+
* @param callback - 回调函数
|
|
5907
|
+
*/
|
|
5908
|
+
forEach(callback) {
|
|
5909
|
+
this.cache.forEach((value, key) => callback(value, key));
|
|
5910
|
+
}
|
|
5911
|
+
};
|
|
5912
|
+
|
|
5692
5913
|
//#endregion
|
|
5693
5914
|
//#region ../agent-provider/src/common/utils/concurrency.ts
|
|
5694
5915
|
/**
|
|
@@ -5790,20 +6011,32 @@ var CosUploadService = class {
|
|
|
5790
6011
|
* 上传单个文件到 COS
|
|
5791
6012
|
*
|
|
5792
6013
|
* @param file - 要上传的文件
|
|
6014
|
+
* @param abortSignal - 可选的 AbortSignal,用于取消上传
|
|
5793
6015
|
* @returns 上传结果,包含访问 URL 或错误信息
|
|
5794
6016
|
*/
|
|
5795
|
-
async uploadFile(file) {
|
|
6017
|
+
async uploadFile(file, abortSignal) {
|
|
5796
6018
|
const filename = file.name;
|
|
5797
6019
|
this.logger?.info(`[CosUploadService] Uploading file: ${filename}`);
|
|
5798
6020
|
try {
|
|
6021
|
+
if (abortSignal?.aborted) return {
|
|
6022
|
+
success: false,
|
|
6023
|
+
error: "Upload cancelled",
|
|
6024
|
+
aborted: true
|
|
6025
|
+
};
|
|
5799
6026
|
const objectKey = this.generateObjectKey(filename);
|
|
5800
6027
|
this.logger?.debug(`[CosUploadService] Generated objectKey: ${objectKey}`);
|
|
5801
6028
|
const presignedItem = (await this.getPresignedUrls([objectKey])).items[0];
|
|
5802
6029
|
if (!presignedItem) throw new Error("No presigned URL item returned");
|
|
6030
|
+
if (abortSignal?.aborted) return {
|
|
6031
|
+
success: false,
|
|
6032
|
+
error: "Upload cancelled",
|
|
6033
|
+
aborted: true
|
|
6034
|
+
};
|
|
5803
6035
|
const uploadResponse = await fetch(presignedItem.upload_url, {
|
|
5804
6036
|
method: "PUT",
|
|
5805
6037
|
body: file,
|
|
5806
|
-
headers: { "Content-Type": file.type || "application/octet-stream" }
|
|
6038
|
+
headers: { "Content-Type": file.type || "application/octet-stream" },
|
|
6039
|
+
signal: abortSignal
|
|
5807
6040
|
});
|
|
5808
6041
|
if (!uploadResponse.ok) {
|
|
5809
6042
|
const errorText = await uploadResponse.text().catch(() => uploadResponse.statusText);
|
|
@@ -5817,6 +6050,11 @@ var CosUploadService = class {
|
|
|
5817
6050
|
objectKey
|
|
5818
6051
|
};
|
|
5819
6052
|
} catch (error) {
|
|
6053
|
+
if (error instanceof Error && error.name === "AbortError") return {
|
|
6054
|
+
success: false,
|
|
6055
|
+
error: "Upload cancelled",
|
|
6056
|
+
aborted: true
|
|
6057
|
+
};
|
|
5820
6058
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
5821
6059
|
this.logger?.error(`[CosUploadService] Upload failed: ${filename}`, error);
|
|
5822
6060
|
return {
|
|
@@ -5831,14 +6069,25 @@ var CosUploadService = class {
|
|
|
5831
6069
|
* 使用并发控制,限制同时上传的文件数量
|
|
5832
6070
|
*
|
|
5833
6071
|
* @param files - 要上传的文件数组
|
|
6072
|
+
* @param abortSignal - 可选的 AbortSignal,用于取消上传
|
|
5834
6073
|
* @returns 所有文件的上传结果
|
|
5835
6074
|
*/
|
|
5836
|
-
async uploadFiles(files) {
|
|
6075
|
+
async uploadFiles(files, abortSignal) {
|
|
5837
6076
|
if (files.length === 0) return {
|
|
5838
6077
|
success: true,
|
|
5839
6078
|
urls: [],
|
|
5840
6079
|
results: []
|
|
5841
6080
|
};
|
|
6081
|
+
if (abortSignal?.aborted) return {
|
|
6082
|
+
success: false,
|
|
6083
|
+
error: "Upload cancelled",
|
|
6084
|
+
aborted: true,
|
|
6085
|
+
results: files.map(() => ({
|
|
6086
|
+
success: false,
|
|
6087
|
+
error: "Upload cancelled",
|
|
6088
|
+
aborted: true
|
|
6089
|
+
}))
|
|
6090
|
+
};
|
|
5842
6091
|
this.logger?.info(`[CosUploadService] Uploading ${files.length} file(s) with concurrency ${this.uploadConcurrency}`);
|
|
5843
6092
|
try {
|
|
5844
6093
|
const fileInfos = files.map((file) => ({
|
|
@@ -5850,6 +6099,12 @@ var CosUploadService = class {
|
|
|
5850
6099
|
this.logger?.debug(`[CosUploadService] Got ${presignedResponse.items.length} presigned URLs`);
|
|
5851
6100
|
if (presignedResponse.items.length !== fileInfos.length) throw new Error(`Expected ${fileInfos.length} presigned URLs, got ${presignedResponse.items.length}`);
|
|
5852
6101
|
const results = (await runWithConcurrencySettled(fileInfos.map(({ file }, index) => async () => {
|
|
6102
|
+
if (abortSignal?.aborted) return {
|
|
6103
|
+
success: false,
|
|
6104
|
+
error: "Upload cancelled",
|
|
6105
|
+
aborted: true,
|
|
6106
|
+
objectKey: fileInfos[index].objectKey
|
|
6107
|
+
};
|
|
5853
6108
|
const presignedItem = presignedResponse.items[index];
|
|
5854
6109
|
if (!presignedItem) return {
|
|
5855
6110
|
success: false,
|
|
@@ -5860,7 +6115,8 @@ var CosUploadService = class {
|
|
|
5860
6115
|
const uploadResponse = await fetch(presignedItem.upload_url, {
|
|
5861
6116
|
method: "PUT",
|
|
5862
6117
|
body: file,
|
|
5863
|
-
headers: { "Content-Type": file.type || "application/octet-stream" }
|
|
6118
|
+
headers: { "Content-Type": file.type || "application/octet-stream" },
|
|
6119
|
+
signal: abortSignal
|
|
5864
6120
|
});
|
|
5865
6121
|
if (!uploadResponse.ok) {
|
|
5866
6122
|
const errorText = await uploadResponse.text().catch(() => uploadResponse.statusText);
|
|
@@ -5877,6 +6133,12 @@ var CosUploadService = class {
|
|
|
5877
6133
|
objectKey: presignedItem.object_key
|
|
5878
6134
|
};
|
|
5879
6135
|
} catch (error) {
|
|
6136
|
+
if (error instanceof Error && error.name === "AbortError") return {
|
|
6137
|
+
success: false,
|
|
6138
|
+
error: "Upload cancelled",
|
|
6139
|
+
aborted: true,
|
|
6140
|
+
objectKey: presignedItem.object_key
|
|
6141
|
+
};
|
|
5880
6142
|
return {
|
|
5881
6143
|
success: false,
|
|
5882
6144
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -5924,91 +6186,6 @@ var CosUploadService = class {
|
|
|
5924
6186
|
}
|
|
5925
6187
|
};
|
|
5926
6188
|
|
|
5927
|
-
//#endregion
|
|
5928
|
-
//#region ../agent-provider/src/common/providers/cloud-agent-provider/e2b-filesystem.ts
|
|
5929
|
-
/**
|
|
5930
|
-
* E2B Filesystem Implementation
|
|
5931
|
-
*
|
|
5932
|
-
* Provides FilesResource implementation using E2B Sandbox SDK.
|
|
5933
|
-
* Directly uses e2b SDK types.
|
|
5934
|
-
*
|
|
5935
|
-
* @see https://e2b.dev/docs/filesystem/read-write
|
|
5936
|
-
* @see https://e2b.dev/docs/filesystem/watch
|
|
5937
|
-
*/
|
|
5938
|
-
/**
|
|
5939
|
-
* E2B Filesystem Implementation
|
|
5940
|
-
*
|
|
5941
|
-
* Wraps E2B Sandbox SDK's filesystem operations to implement FilesResource interface.
|
|
5942
|
-
*
|
|
5943
|
-
* @example
|
|
5944
|
-
* ```typescript
|
|
5945
|
-
* const fs = await E2BFilesystem.connect({
|
|
5946
|
-
* sandboxId: 'sandbox-123',
|
|
5947
|
-
* apiKey: 'e2b_xxx'
|
|
5948
|
-
* });
|
|
5949
|
-
*
|
|
5950
|
-
* // Read/write files
|
|
5951
|
-
* await fs.write('/test.txt', 'Hello World');
|
|
5952
|
-
* const content = await fs.read('/test.txt');
|
|
5953
|
-
*
|
|
5954
|
-
* // Watch for changes
|
|
5955
|
-
* const handle = await fs.watchDir('/workspace', (event) => {
|
|
5956
|
-
* console.log('File changed:', event);
|
|
5957
|
-
* });
|
|
5958
|
-
* ```
|
|
5959
|
-
*/
|
|
5960
|
-
var E2BFilesystem = class E2BFilesystem {
|
|
5961
|
-
constructor(sandbox) {
|
|
5962
|
-
this.sandbox = sandbox;
|
|
5963
|
-
}
|
|
5964
|
-
/**
|
|
5965
|
-
* Connect to an E2B Sandbox and create filesystem instance
|
|
5966
|
-
*/
|
|
5967
|
-
static async connect(info) {
|
|
5968
|
-
return new E2BFilesystem(await Sandbox.connect(info.sandboxId, {
|
|
5969
|
-
domain: info.domain,
|
|
5970
|
-
apiUrl: info.apiUrl,
|
|
5971
|
-
requestTimeoutMs: info.requestTimeoutMs,
|
|
5972
|
-
debug: info.debug,
|
|
5973
|
-
headers: info.headers
|
|
5974
|
-
}));
|
|
5975
|
-
}
|
|
5976
|
-
/**
|
|
5977
|
-
* Get the underlying E2B Sandbox instance
|
|
5978
|
-
*/
|
|
5979
|
-
getSandbox() {
|
|
5980
|
-
return this.sandbox;
|
|
5981
|
-
}
|
|
5982
|
-
read(path, opts) {
|
|
5983
|
-
return this.sandbox.files.read(path, opts);
|
|
5984
|
-
}
|
|
5985
|
-
write(pathOrFiles, dataOrOpts, opts) {
|
|
5986
|
-
if (Array.isArray(pathOrFiles)) return this.sandbox.files.write(pathOrFiles, dataOrOpts);
|
|
5987
|
-
return this.sandbox.files.write(pathOrFiles, dataOrOpts, opts);
|
|
5988
|
-
}
|
|
5989
|
-
async list(path, opts) {
|
|
5990
|
-
return this.sandbox.files.list(path, opts);
|
|
5991
|
-
}
|
|
5992
|
-
async exists(path, opts) {
|
|
5993
|
-
return this.sandbox.files.exists(path, opts);
|
|
5994
|
-
}
|
|
5995
|
-
async makeDir(path, opts) {
|
|
5996
|
-
return this.sandbox.files.makeDir(path, opts);
|
|
5997
|
-
}
|
|
5998
|
-
async remove(path, opts) {
|
|
5999
|
-
return this.sandbox.files.remove(path, opts);
|
|
6000
|
-
}
|
|
6001
|
-
async rename(oldPath, newPath, opts) {
|
|
6002
|
-
return this.sandbox.files.rename(oldPath, newPath, opts);
|
|
6003
|
-
}
|
|
6004
|
-
async getInfo(path, opts) {
|
|
6005
|
-
return this.sandbox.files.getInfo(path, opts);
|
|
6006
|
-
}
|
|
6007
|
-
async watchDir(path, onEvent, opts) {
|
|
6008
|
-
return this.sandbox.files.watchDir(path, onEvent, opts);
|
|
6009
|
-
}
|
|
6010
|
-
};
|
|
6011
|
-
|
|
6012
6189
|
//#endregion
|
|
6013
6190
|
//#region ../agent-provider/src/common/providers/cloud-agent-provider/cloud-provider.ts
|
|
6014
6191
|
/**
|
|
@@ -6157,8 +6334,11 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6157
6334
|
this.filesystemCache = /* @__PURE__ */ new Map();
|
|
6158
6335
|
this.connectionCache = /* @__PURE__ */ new Map();
|
|
6159
6336
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
6337
|
+
this.productConfigCache = null;
|
|
6160
6338
|
this.options = options;
|
|
6161
6339
|
this.logger = options.logger;
|
|
6340
|
+
this.marketplaceCache = new LRUCache(200);
|
|
6341
|
+
this.pluginCache = new LRUCache(2e3);
|
|
6162
6342
|
if (options.endpoint) httpService.setBaseURL(options.endpoint);
|
|
6163
6343
|
if (options.authToken) httpService.setAuthToken(options.authToken);
|
|
6164
6344
|
if (options.headers && Object.keys(options.headers).length > 0) this.requestInterceptorId = httpService.registerRequestInterceptor((config) => {
|
|
@@ -6209,7 +6389,19 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6209
6389
|
const cached = this.filesystemCache.get(agentId);
|
|
6210
6390
|
if (cached) return cached;
|
|
6211
6391
|
const info = await this.getSandboxInfo(agentId);
|
|
6212
|
-
|
|
6392
|
+
let e2bFilesystem;
|
|
6393
|
+
if (this.options.filesystemFactory) e2bFilesystem = await this.options.filesystemFactory(info);
|
|
6394
|
+
else {
|
|
6395
|
+
const { E2BFilesystem } = await import("./e2b-filesystem-DWj9UkV8.mjs");
|
|
6396
|
+
e2bFilesystem = await E2BFilesystem.connect(info);
|
|
6397
|
+
}
|
|
6398
|
+
if (e2bFilesystem.setReconnectFn) e2bFilesystem.setReconnectFn(async () => {
|
|
6399
|
+
this.logger?.debug(`Reconnecting E2B sandbox for agent: ${agentId}`);
|
|
6400
|
+
const newInfo = await this.getSandboxInfo(agentId);
|
|
6401
|
+
this.logger?.debug(`E2B sandbox reconnected for agent: ${agentId}`);
|
|
6402
|
+
return newInfo;
|
|
6403
|
+
});
|
|
6404
|
+
const filesystem = createAgentFilesystem(e2bFilesystem);
|
|
6213
6405
|
this.filesystemCache.set(agentId, filesystem);
|
|
6214
6406
|
this.logger?.debug(`Created filesystem for agent: ${agentId}`);
|
|
6215
6407
|
return filesystem;
|
|
@@ -6277,15 +6469,9 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6277
6469
|
const url = this.buildGetUrl("/console/as/conversations/", params);
|
|
6278
6470
|
const apiResponse = await httpService.get(url);
|
|
6279
6471
|
if (!apiResponse.data) throw new Error("No data in API response");
|
|
6280
|
-
const agents = apiResponse.data.conversations.map((a) => this.toAgentState(a));
|
|
6281
|
-
const pagination = apiResponse.data.pagination;
|
|
6282
|
-
console.log("[CloudAgentProvider] API response:", {
|
|
6283
|
-
agentsCount: agents.length,
|
|
6284
|
-
pagination
|
|
6285
|
-
});
|
|
6286
6472
|
return {
|
|
6287
|
-
agents,
|
|
6288
|
-
pagination
|
|
6473
|
+
agents: apiResponse.data.conversations.map((a) => this.toAgentState(a)),
|
|
6474
|
+
pagination: apiResponse.data.pagination
|
|
6289
6475
|
};
|
|
6290
6476
|
} catch (error) {
|
|
6291
6477
|
this.logger?.error("Failed to list agents:", error);
|
|
@@ -6295,15 +6481,17 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6295
6481
|
/**
|
|
6296
6482
|
* Create a new conversation
|
|
6297
6483
|
* POST {endpoint}/console/as/conversations
|
|
6298
|
-
* @param params -
|
|
6484
|
+
* @param params - Session params containing cwd and optional configuration
|
|
6299
6485
|
*/
|
|
6300
6486
|
async create(params) {
|
|
6301
6487
|
try {
|
|
6302
|
-
const
|
|
6488
|
+
const { options = {} } = params;
|
|
6489
|
+
const codebuddyMeta = options._meta?.["codebuddy.ai"];
|
|
6490
|
+
const tagsObj = options.tags || codebuddyMeta?.tags;
|
|
6303
6491
|
const tagsArray = tagsObj ? Object.entries(tagsObj).map(([key, value]) => `${key}:${value}`) : void 0;
|
|
6304
6492
|
const createPayload = {
|
|
6305
|
-
prompt: "",
|
|
6306
|
-
model: "deepseek-r1",
|
|
6493
|
+
prompt: (options.prompt || "").slice(0, 100),
|
|
6494
|
+
model: options.model || "deepseek-r1",
|
|
6307
6495
|
...tagsArray && tagsArray.length > 0 ? { tags: tagsArray } : {}
|
|
6308
6496
|
};
|
|
6309
6497
|
console.log("[CloudAgentProvider] Creating conversation with payload:", createPayload);
|
|
@@ -6357,7 +6545,14 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6357
6545
|
} catch (error) {
|
|
6358
6546
|
this.logger?.debug(`Failed to fetch conversation details for ${agentId}:`, error);
|
|
6359
6547
|
}
|
|
6360
|
-
|
|
6548
|
+
const existingConnection = this.connectionCache.get(endpoint);
|
|
6549
|
+
if (existingConnection) {
|
|
6550
|
+
this.connectionCache.delete(endpoint);
|
|
6551
|
+
existingConnection.removeAllListeners();
|
|
6552
|
+
existingConnection.disconnect().catch((err) => {
|
|
6553
|
+
this.logger?.debug("Failed to disconnect old connection:", err);
|
|
6554
|
+
});
|
|
6555
|
+
}
|
|
6361
6556
|
const clientCapabilities = {
|
|
6362
6557
|
...this.options.clientCapabilities,
|
|
6363
6558
|
_meta: {
|
|
@@ -6477,6 +6672,35 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6477
6672
|
}
|
|
6478
6673
|
}
|
|
6479
6674
|
/**
|
|
6675
|
+
* Update conversation status by ID
|
|
6676
|
+
* POST {endpoint}/console/as/conversations/{agentId}
|
|
6677
|
+
*
|
|
6678
|
+
* @param agentId - Conversation ID to update
|
|
6679
|
+
* @param status - New status for the conversation
|
|
6680
|
+
* @returns PatchConversationResponse containing the updated conversation ID
|
|
6681
|
+
*
|
|
6682
|
+
* @example
|
|
6683
|
+
* ```typescript
|
|
6684
|
+
* const result = await provider.updateStatus('agent-123', 'completed');
|
|
6685
|
+
* console.log('Updated conversation status:', result.id);
|
|
6686
|
+
* ```
|
|
6687
|
+
*/
|
|
6688
|
+
async updateStatus(agentId, status) {
|
|
6689
|
+
try {
|
|
6690
|
+
const body = { status };
|
|
6691
|
+
const apiResponse = await httpService.post(`/console/as/conversations/${agentId}`, body);
|
|
6692
|
+
if (!apiResponse.data) {
|
|
6693
|
+
this.logger?.info(`Updated conversation status: ${agentId} to "${status}"`);
|
|
6694
|
+
return { id: agentId };
|
|
6695
|
+
}
|
|
6696
|
+
this.logger?.info(`Updated conversation status: ${apiResponse.data.id} to "${status}"`);
|
|
6697
|
+
return apiResponse.data;
|
|
6698
|
+
} catch (error) {
|
|
6699
|
+
this.logger?.error(`Failed to update conversation status ${agentId}:`, error);
|
|
6700
|
+
throw error;
|
|
6701
|
+
}
|
|
6702
|
+
}
|
|
6703
|
+
/**
|
|
6480
6704
|
* Get available models from product configuration
|
|
6481
6705
|
*
|
|
6482
6706
|
* GET {endpoint}/console/enterprises/{personal|enterpriseId}/models?repos[]={repo}
|
|
@@ -6507,9 +6731,13 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6507
6731
|
this.logger?.warn("[CloudAgentProvider] No data in config response, returning empty models");
|
|
6508
6732
|
return [];
|
|
6509
6733
|
}
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6734
|
+
this.productConfigCache = apiResponse.data;
|
|
6735
|
+
const productConfig = apiResponse.data;
|
|
6736
|
+
const allModels = productConfig.models ?? [];
|
|
6737
|
+
const cliModelIds = (productConfig.agents ?? []).find((agent) => agent.name === "cli")?.models ?? [];
|
|
6738
|
+
const filteredModels = cliModelIds.length > 0 ? allModels.filter((model) => cliModelIds.includes(model.id)) : allModels;
|
|
6739
|
+
this.logger?.info(`[CloudAgentProvider] Retrieved ${filteredModels.length} models for cli agent (total: ${allModels.length})`);
|
|
6740
|
+
return filteredModels.map((model) => ({
|
|
6513
6741
|
id: model.id,
|
|
6514
6742
|
name: model.name ?? model.id,
|
|
6515
6743
|
description: model.description,
|
|
@@ -6531,6 +6759,43 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6531
6759
|
}
|
|
6532
6760
|
}
|
|
6533
6761
|
/**
|
|
6762
|
+
* 获取产品部署类型(从缓存)
|
|
6763
|
+
* 需要先调用 getModels() 初始化缓存
|
|
6764
|
+
*
|
|
6765
|
+
* @returns 部署类型:'SaaS' | 'Cloud-Hosted' | 'Self-Hosted',默认为 'SaaS'
|
|
6766
|
+
*/
|
|
6767
|
+
getDeploymentType() {
|
|
6768
|
+
return this.productConfigCache?.deploymentType ?? "SaaS";
|
|
6769
|
+
}
|
|
6770
|
+
/**
|
|
6771
|
+
* 获取 Credit 购买引导配置(从缓存)
|
|
6772
|
+
* 需要先调用 getModels() 初始化缓存
|
|
6773
|
+
*
|
|
6774
|
+
* @returns Credit 购买引导配置,key 为错误码。如果后端未返回,则使用默认配置
|
|
6775
|
+
*/
|
|
6776
|
+
getCreditPurchaseActions() {
|
|
6777
|
+
return this.productConfigCache?.config?.creditPurchaseActions ?? {
|
|
6778
|
+
"14018": {
|
|
6779
|
+
labelZh: "获取 Credits",
|
|
6780
|
+
labelEn: "Get credits",
|
|
6781
|
+
url: "https://www.codebuddy.cn/profile/plan",
|
|
6782
|
+
showButton: true
|
|
6783
|
+
},
|
|
6784
|
+
"6004": {
|
|
6785
|
+
labelZh: "升级专业版",
|
|
6786
|
+
labelEn: "Upgrade to Pro",
|
|
6787
|
+
url: "https://www.codebuddy.cn/profile/plan",
|
|
6788
|
+
showButton: true
|
|
6789
|
+
},
|
|
6790
|
+
"6005": {
|
|
6791
|
+
labelZh: "升级专业版",
|
|
6792
|
+
labelEn: "Upgrade to Pro",
|
|
6793
|
+
url: "https://www.codebuddy.cn/profile/plan",
|
|
6794
|
+
showButton: true
|
|
6795
|
+
}
|
|
6796
|
+
};
|
|
6797
|
+
}
|
|
6798
|
+
/**
|
|
6534
6799
|
* Generate a unique request ID
|
|
6535
6800
|
*/
|
|
6536
6801
|
generateRequestId() {
|
|
@@ -6613,7 +6878,7 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6613
6878
|
/**
|
|
6614
6879
|
* Upload files to cloud storage via COS presigned URL
|
|
6615
6880
|
*
|
|
6616
|
-
* @param params - files array (File objects in browser)
|
|
6881
|
+
* @param params - files array (File objects in browser), optional abortSignal
|
|
6617
6882
|
* @returns Response with corresponding cloud URLs
|
|
6618
6883
|
*/
|
|
6619
6884
|
async uploadFile(params) {
|
|
@@ -6623,12 +6888,13 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6623
6888
|
success: false,
|
|
6624
6889
|
error: "No valid File objects provided"
|
|
6625
6890
|
};
|
|
6626
|
-
const result = await this.cosUploadService.uploadFiles(files);
|
|
6891
|
+
const result = await this.cosUploadService.uploadFiles(files, params.abortSignal);
|
|
6627
6892
|
return {
|
|
6628
6893
|
success: result.success,
|
|
6629
6894
|
urls: result.urls,
|
|
6630
6895
|
expireSeconds: result.expireSeconds,
|
|
6631
|
-
error: result.error
|
|
6896
|
+
error: result.error,
|
|
6897
|
+
aborted: result.aborted
|
|
6632
6898
|
};
|
|
6633
6899
|
}
|
|
6634
6900
|
/**
|
|
@@ -6670,20 +6936,22 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6670
6936
|
}
|
|
6671
6937
|
/**
|
|
6672
6938
|
* 获取支持的场景列表
|
|
6673
|
-
* API 端点: GET /
|
|
6939
|
+
* API 端点: GET /v2/as/support/scenes (不鉴权)
|
|
6674
6940
|
* 用于 Welcome 页面的 QuickActions 快捷操作
|
|
6675
6941
|
*
|
|
6942
|
+
* @param locale - 可选,语言环境(如 'zh-CN', 'en-US'),用于获取对应语言的场景数据
|
|
6676
6943
|
* @returns Promise<SupportScene[]> 支持的场景列表
|
|
6677
6944
|
*/
|
|
6678
|
-
async getSupportScenes() {
|
|
6945
|
+
async getSupportScenes(locale) {
|
|
6679
6946
|
try {
|
|
6680
|
-
const
|
|
6947
|
+
const url = this.buildGetUrl("/v2/as/support/scenes", locale ? { locale } : void 0);
|
|
6948
|
+
const apiResponse = await httpService.get(url);
|
|
6681
6949
|
if (!apiResponse.data) {
|
|
6682
6950
|
this.logger?.warn("[CloudAgentProvider] No data in support scenes response");
|
|
6683
6951
|
return [];
|
|
6684
6952
|
}
|
|
6685
6953
|
const scenes = apiResponse.data.scenes || [];
|
|
6686
|
-
this.logger?.info(`[CloudAgentProvider] Retrieved ${scenes.length} support scenes`);
|
|
6954
|
+
this.logger?.info(`[CloudAgentProvider] Retrieved ${scenes.length} support scenes${locale ? ` for locale: ${locale}` : ""}`);
|
|
6687
6955
|
return scenes;
|
|
6688
6956
|
} catch (error) {
|
|
6689
6957
|
this.logger?.error("[CloudAgentProvider] Failed to get support scenes:", error);
|
|
@@ -6699,7 +6967,8 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6699
6967
|
type: "cloud",
|
|
6700
6968
|
status,
|
|
6701
6969
|
createdAt: data.createdAt ? new Date(data.createdAt) : void 0,
|
|
6702
|
-
capabilities: this.options.clientCapabilities
|
|
6970
|
+
capabilities: this.options.clientCapabilities,
|
|
6971
|
+
isUserDefinedTitle: data.isUserDefinedTitle
|
|
6703
6972
|
};
|
|
6704
6973
|
}
|
|
6705
6974
|
/**
|
|
@@ -6715,69 +6984,524 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
6715
6984
|
const queryString = searchParams.toString();
|
|
6716
6985
|
return queryString ? `${path}?${queryString}` : path;
|
|
6717
6986
|
}
|
|
6718
|
-
};
|
|
6719
|
-
|
|
6720
|
-
//#endregion
|
|
6721
|
-
//#region ../agent-provider/src/common/client/session.ts
|
|
6722
|
-
/**
|
|
6723
|
-
* ActiveSessionImpl - Implements the ActiveSession interface
|
|
6724
|
-
*
|
|
6725
|
-
* This class wraps an AgentConnection and provides the session-centric API.
|
|
6726
|
-
* It is created by SessionManager when creating or loading sessions.
|
|
6727
|
-
*
|
|
6728
|
-
* @example
|
|
6729
|
-
* ```typescript
|
|
6730
|
-
* // Created by client.sessions.new() or client.sessions.load()
|
|
6731
|
-
* const session = await client.sessions.new({ cwd: '/workspace' });
|
|
6732
|
-
*
|
|
6733
|
-
* // Access agent state
|
|
6734
|
-
* console.log(session.agentState.status);
|
|
6735
|
-
*
|
|
6736
|
-
* // Send prompt
|
|
6737
|
-
* const response = await session.prompts.send({ content: 'Hello!' });
|
|
6738
|
-
*
|
|
6739
|
-
* // Cleanup
|
|
6740
|
-
* session.disconnect();
|
|
6741
|
-
* ```
|
|
6742
|
-
*/
|
|
6743
|
-
var ActiveSessionImpl = class {
|
|
6744
6987
|
/**
|
|
6745
|
-
*
|
|
6746
|
-
*
|
|
6747
|
-
* @param sessionId - Session ID
|
|
6748
|
-
* @param agentId - Agent ID
|
|
6749
|
-
* @param connection - Already connected AgentConnection
|
|
6750
|
-
* @param options - Additional options
|
|
6988
|
+
* 获取已安装插件列表
|
|
6989
|
+
* GET /console/as/user/plugins/installed
|
|
6751
6990
|
*/
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6991
|
+
async getInstalledPlugins(forceRefresh) {
|
|
6992
|
+
try {
|
|
6993
|
+
const result = ((await httpService.get("/console/as/user/plugins/installed")).data?.plugins || []).map((p) => ({
|
|
6994
|
+
name: p.plugin_name,
|
|
6995
|
+
marketplaceName: p.marketplace_name,
|
|
6996
|
+
status: p.enabled ? "enabled" : "disabled",
|
|
6997
|
+
description: p.description,
|
|
6998
|
+
version: p.version,
|
|
6999
|
+
installScope: p.scope === "local" ? "project" : p.scope,
|
|
7000
|
+
installedScopes: [p.scope],
|
|
7001
|
+
installId: p.id
|
|
7002
|
+
}));
|
|
7003
|
+
result.forEach((plugin) => {
|
|
7004
|
+
this.pluginCache.set(plugin.name, plugin);
|
|
7005
|
+
});
|
|
7006
|
+
return result;
|
|
7007
|
+
} catch (error) {
|
|
7008
|
+
this.logger?.error("[CloudAgentProvider] getInstalledPlugins failed:", error);
|
|
7009
|
+
throw error;
|
|
7010
|
+
}
|
|
6767
7011
|
}
|
|
6768
7012
|
/**
|
|
6769
|
-
*
|
|
7013
|
+
* 安装插件
|
|
7014
|
+
* POST /console/as/user/plugins/install
|
|
7015
|
+
*
|
|
7016
|
+
* @param pluginNames - 插件名称数组
|
|
7017
|
+
* @param marketplaceNameOrId - 市场名称或 ID
|
|
6770
7018
|
*/
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
7019
|
+
async installPlugins(pluginNames, marketplaceNameOrId, installScope, marketplaceSource, workspacePath) {
|
|
7020
|
+
try {
|
|
7021
|
+
const marketplaceId = await this.findMarketplaceId(marketplaceNameOrId);
|
|
7022
|
+
if (!marketplaceId) return {
|
|
7023
|
+
success: false,
|
|
7024
|
+
error: `Marketplace not found: ${marketplaceNameOrId}`
|
|
7025
|
+
};
|
|
7026
|
+
const failed = (await Promise.allSettled(pluginNames.map((pluginName) => httpService.post("/console/as/user/plugins/install", {
|
|
7027
|
+
plugin_name: pluginName,
|
|
7028
|
+
marketplace_id: marketplaceId,
|
|
7029
|
+
version: "latest"
|
|
7030
|
+
})))).filter((r) => r.status === "rejected");
|
|
7031
|
+
if (failed.length > 0) {
|
|
7032
|
+
const errors = failed.map((r) => r.reason?.message || "Unknown error");
|
|
7033
|
+
return {
|
|
7034
|
+
success: false,
|
|
7035
|
+
error: `安装失败 ${failed.length} 个插件: ${errors.join(", ")}`
|
|
7036
|
+
};
|
|
7037
|
+
}
|
|
7038
|
+
return { success: true };
|
|
7039
|
+
} catch (error) {
|
|
7040
|
+
return {
|
|
7041
|
+
success: false,
|
|
7042
|
+
error: this.extractErrorMessage(error)
|
|
7043
|
+
};
|
|
7044
|
+
}
|
|
7045
|
+
}
|
|
7046
|
+
/**
|
|
7047
|
+
* 卸载插件
|
|
7048
|
+
* POST /console/as/user/plugins/installed/:id/uninstall
|
|
7049
|
+
*
|
|
7050
|
+
* 完整链路:
|
|
7051
|
+
* CloudAgentProvider.uninstallPlugin()
|
|
7052
|
+
* -> HTTP POST /console/as/user/plugins/installed/:id/uninstall
|
|
7053
|
+
* -> agentserver: PluginInstallService.Uninstall()
|
|
7054
|
+
* -> 软删除 DB + 异步同步到活跃沙箱
|
|
7055
|
+
*
|
|
7056
|
+
* @param pluginName - 插件名称
|
|
7057
|
+
* @param marketplaceName - 市场名称(用于标识唯一插件)
|
|
7058
|
+
* @param scope - 卸载范围 ('user' | 'project' | 'project-local')
|
|
7059
|
+
*/
|
|
7060
|
+
async uninstallPlugin(pluginName, marketplaceName, scope) {
|
|
7061
|
+
try {
|
|
7062
|
+
const installId = await this.findPluginInstallId(pluginName);
|
|
7063
|
+
if (!installId) return {
|
|
7064
|
+
success: false,
|
|
7065
|
+
error: `Plugin not found or not installed: ${pluginName}`
|
|
7066
|
+
};
|
|
7067
|
+
await httpService.post(`/console/as/user/plugins/installed/${installId}/uninstall`);
|
|
7068
|
+
return { success: true };
|
|
7069
|
+
} catch (error) {
|
|
7070
|
+
return {
|
|
7071
|
+
success: false,
|
|
7072
|
+
error: this.extractErrorMessage(error)
|
|
7073
|
+
};
|
|
7074
|
+
}
|
|
7075
|
+
}
|
|
7076
|
+
/**
|
|
7077
|
+
* 获取插件市场列表
|
|
7078
|
+
* GET /console/as/marketplace/sources
|
|
7079
|
+
*/
|
|
7080
|
+
async getPluginMarketplaces(forceRefresh) {
|
|
7081
|
+
try {
|
|
7082
|
+
const result = ((await httpService.get("/console/as/marketplace/sources")).data?.sources || []).map((src) => ({
|
|
7083
|
+
id: src.id,
|
|
7084
|
+
name: src.name,
|
|
7085
|
+
type: this.mapSourceType(src.source_type),
|
|
7086
|
+
source: { url: src.url },
|
|
7087
|
+
description: src.name,
|
|
7088
|
+
isBuiltin: src.is_default
|
|
7089
|
+
}));
|
|
7090
|
+
result.forEach((m) => {
|
|
7091
|
+
const marketplaceInfo = {
|
|
7092
|
+
id: m.id,
|
|
7093
|
+
name: m.name
|
|
7094
|
+
};
|
|
7095
|
+
this.marketplaceCache.set(m.name, marketplaceInfo);
|
|
7096
|
+
this.marketplaceCache.set(m.id, marketplaceInfo);
|
|
7097
|
+
});
|
|
7098
|
+
return result;
|
|
7099
|
+
} catch (error) {
|
|
7100
|
+
this.logger?.error("[CloudAgentProvider] getPluginMarketplaces failed:", error);
|
|
7101
|
+
throw error;
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
/**
|
|
7105
|
+
* 获取市场下的插件列表
|
|
7106
|
+
* - 有 searchText: GET /console/as/marketplace/plugins/search (跨所有市场搜索)
|
|
7107
|
+
* - 无 searchText: GET /console/as/marketplace/plugins (指定市场)
|
|
7108
|
+
*
|
|
7109
|
+
* @param marketplaceNameOrId - 市场名称或 ID(优先使用 ID,如果是名称则从缓存查询 ID)
|
|
7110
|
+
* @param forceRefresh - 是否强制刷新
|
|
7111
|
+
* @param searchText - 搜索关键字(如果提供,则跨所有市场搜索)
|
|
7112
|
+
*/
|
|
7113
|
+
async getMarketplacePlugins(marketplaceNameOrId, forceRefresh, searchText) {
|
|
7114
|
+
try {
|
|
7115
|
+
if (searchText) return ((await httpService.get("/console/as/marketplace/plugins/search", { params: {
|
|
7116
|
+
q: searchText,
|
|
7117
|
+
page: 1,
|
|
7118
|
+
page_size: 100
|
|
7119
|
+
} })).data?.plugins || []).map((p) => this.mapPluginData(p));
|
|
7120
|
+
const sourceId = await this.findMarketplaceId(marketplaceNameOrId);
|
|
7121
|
+
if (!sourceId) {
|
|
7122
|
+
this.logger?.warn(`[CloudAgentProvider] Marketplace not found: ${marketplaceNameOrId}`);
|
|
7123
|
+
return [];
|
|
7124
|
+
}
|
|
7125
|
+
const params = {
|
|
7126
|
+
source_id: sourceId,
|
|
7127
|
+
page: 1,
|
|
7128
|
+
page_size: 100
|
|
7129
|
+
};
|
|
7130
|
+
return ((await httpService.get("/console/as/marketplace/plugins", { params })).data?.plugins || []).map((p) => this.mapPluginData(p));
|
|
7131
|
+
} catch (error) {
|
|
7132
|
+
this.logger?.error("[CloudAgentProvider] getMarketplacePlugins failed:", error);
|
|
7133
|
+
throw error;
|
|
7134
|
+
}
|
|
7135
|
+
}
|
|
7136
|
+
/**
|
|
7137
|
+
* 获取插件详情
|
|
7138
|
+
* GET /console/as/marketplace/plugins/:name/detail
|
|
7139
|
+
*
|
|
7140
|
+
* @param pluginName - 插件名称
|
|
7141
|
+
* @param marketplaceNameOrId - 市场名称或 ID(优先使用 ID,如果是名称则从缓存查询 ID)
|
|
7142
|
+
*/
|
|
7143
|
+
async getPluginDetail(pluginName, marketplaceNameOrId) {
|
|
7144
|
+
try {
|
|
7145
|
+
const sourceId = await this.findMarketplaceId(marketplaceNameOrId);
|
|
7146
|
+
if (!sourceId) {
|
|
7147
|
+
this.logger?.warn(`[CloudAgentProvider] Marketplace not found: ${marketplaceNameOrId}`);
|
|
7148
|
+
return null;
|
|
7149
|
+
}
|
|
7150
|
+
const p = (await httpService.get(`/console/as/marketplace/plugins/${pluginName}/detail`, { params: { source_id: sourceId } })).data?.plugin;
|
|
7151
|
+
if (!p) return null;
|
|
7152
|
+
const capabilities = p.capabilities ? this.parseCapabilities(p.capabilities) : {};
|
|
7153
|
+
const tags = p.tags ? JSON.parse(p.tags) : [];
|
|
7154
|
+
return {
|
|
7155
|
+
name: p.name,
|
|
7156
|
+
marketplaceName: p.marketplace_name,
|
|
7157
|
+
description: p.description,
|
|
7158
|
+
version: p.version,
|
|
7159
|
+
iconUrl: p.icon_url,
|
|
7160
|
+
tags,
|
|
7161
|
+
installed: p.installed,
|
|
7162
|
+
status: p.enabled ? "enabled" : p.installed ? "disabled" : "not-installed",
|
|
7163
|
+
readme: p.readme,
|
|
7164
|
+
author: p.author,
|
|
7165
|
+
homepage: p.homepage,
|
|
7166
|
+
repositoryUrl: p.repository_url,
|
|
7167
|
+
license: p.license,
|
|
7168
|
+
...capabilities
|
|
7169
|
+
};
|
|
7170
|
+
} catch (error) {
|
|
7171
|
+
this.logger?.error("[CloudAgentProvider] getPluginDetail failed:", error);
|
|
7172
|
+
throw error;
|
|
7173
|
+
}
|
|
7174
|
+
}
|
|
7175
|
+
/**
|
|
7176
|
+
* 添加插件市场
|
|
7177
|
+
* POST /console/as/marketplace/sources
|
|
7178
|
+
*/
|
|
7179
|
+
async addPluginMarketplace(sourceUrl, name) {
|
|
7180
|
+
try {
|
|
7181
|
+
const body = {
|
|
7182
|
+
source_type: sourceUrl.startsWith("http") ? "url" : "github",
|
|
7183
|
+
url: sourceUrl,
|
|
7184
|
+
name: name || sourceUrl
|
|
7185
|
+
};
|
|
7186
|
+
const sourceData = (await httpService.post("/console/as/marketplace/sources", body)).data?.source;
|
|
7187
|
+
if (!sourceData) throw new Error("Invalid response from server");
|
|
7188
|
+
const marketplaceInfo = {
|
|
7189
|
+
id: sourceData.id,
|
|
7190
|
+
name: sourceData.name
|
|
7191
|
+
};
|
|
7192
|
+
this.marketplaceCache.set(sourceData.name, marketplaceInfo);
|
|
7193
|
+
this.marketplaceCache.set(sourceData.id, marketplaceInfo);
|
|
7194
|
+
return {
|
|
7195
|
+
success: true,
|
|
7196
|
+
marketplace: {
|
|
7197
|
+
id: sourceData.id,
|
|
7198
|
+
name: sourceData.name,
|
|
7199
|
+
type: this.mapSourceType(sourceData.source_type),
|
|
7200
|
+
source: { url: sourceData.url },
|
|
7201
|
+
isBuiltin: sourceData.is_default
|
|
7202
|
+
}
|
|
7203
|
+
};
|
|
7204
|
+
} catch (error) {
|
|
7205
|
+
return {
|
|
7206
|
+
success: false,
|
|
7207
|
+
error: this.extractErrorMessage(error)
|
|
7208
|
+
};
|
|
7209
|
+
}
|
|
7210
|
+
}
|
|
7211
|
+
/**
|
|
7212
|
+
* 删除插件市场
|
|
7213
|
+
* POST /console/as/marketplace/sources/:id/delete
|
|
7214
|
+
*/
|
|
7215
|
+
async removePluginMarketplace(marketplaceNameOrId) {
|
|
7216
|
+
try {
|
|
7217
|
+
const marketplaceId = await this.findMarketplaceId(marketplaceNameOrId);
|
|
7218
|
+
if (!marketplaceId) return {
|
|
7219
|
+
success: false,
|
|
7220
|
+
error: `Marketplace not found: ${marketplaceNameOrId}`
|
|
7221
|
+
};
|
|
7222
|
+
await httpService.post(`/console/as/marketplace/sources/${marketplaceId}/delete`, {});
|
|
7223
|
+
return { success: true };
|
|
7224
|
+
} catch (error) {
|
|
7225
|
+
return {
|
|
7226
|
+
success: false,
|
|
7227
|
+
error: this.extractErrorMessage(error)
|
|
7228
|
+
};
|
|
7229
|
+
}
|
|
7230
|
+
}
|
|
7231
|
+
/**
|
|
7232
|
+
* 刷新插件市场
|
|
7233
|
+
* POST /console/as/marketplace/sources/:id/check-updates
|
|
7234
|
+
*/
|
|
7235
|
+
async refreshPluginMarketplace(marketplaceNameOrId) {
|
|
7236
|
+
try {
|
|
7237
|
+
const marketplaceId = await this.findMarketplaceId(marketplaceNameOrId);
|
|
7238
|
+
if (!marketplaceId) return {
|
|
7239
|
+
success: false,
|
|
7240
|
+
error: `Marketplace not found: ${marketplaceNameOrId}`
|
|
7241
|
+
};
|
|
7242
|
+
return {
|
|
7243
|
+
success: true,
|
|
7244
|
+
plugins: (await httpService.post(`/console/as/marketplace/sources/${marketplaceId}/check-updates`, {})).data?.updated_plugins || []
|
|
7245
|
+
};
|
|
7246
|
+
} catch (error) {
|
|
7247
|
+
return {
|
|
7248
|
+
success: false,
|
|
7249
|
+
error: this.extractErrorMessage(error)
|
|
7250
|
+
};
|
|
7251
|
+
}
|
|
7252
|
+
}
|
|
7253
|
+
/**
|
|
7254
|
+
* 批量切换插件启用/禁用状态
|
|
7255
|
+
* POST /console/as/user/plugins/installed/:id/toggle
|
|
7256
|
+
*/
|
|
7257
|
+
async batchTogglePlugins(request) {
|
|
7258
|
+
try {
|
|
7259
|
+
const results = await Promise.allSettled(request.items.map(async (item) => {
|
|
7260
|
+
const installId = await this.findPluginInstallId(item.pluginName);
|
|
7261
|
+
if (!installId) throw new Error(`Plugin not found or not installed: ${item.pluginName}`);
|
|
7262
|
+
const enabled = item.operation === "enable";
|
|
7263
|
+
await httpService.post(`/console/as/user/plugins/installed/${installId}/toggle`, { enabled });
|
|
7264
|
+
return item;
|
|
7265
|
+
}));
|
|
7266
|
+
const succeededPlugins = [];
|
|
7267
|
+
const failedPlugins = [];
|
|
7268
|
+
results.forEach((r, i) => {
|
|
7269
|
+
const item = request.items[i];
|
|
7270
|
+
if (r.status === "fulfilled") succeededPlugins.push(item);
|
|
7271
|
+
else failedPlugins.push({
|
|
7272
|
+
...item,
|
|
7273
|
+
error: r.reason?.message || "Unknown error"
|
|
7274
|
+
});
|
|
7275
|
+
});
|
|
7276
|
+
return {
|
|
7277
|
+
success: failedPlugins.length === 0,
|
|
7278
|
+
succeededPlugins,
|
|
7279
|
+
failedPlugins
|
|
7280
|
+
};
|
|
7281
|
+
} catch (error) {
|
|
7282
|
+
return {
|
|
7283
|
+
success: false,
|
|
7284
|
+
succeededPlugins: [],
|
|
7285
|
+
failedPlugins: request.items.map((item) => ({
|
|
7286
|
+
...item,
|
|
7287
|
+
error: this.extractErrorMessage(error)
|
|
7288
|
+
}))
|
|
7289
|
+
};
|
|
7290
|
+
}
|
|
7291
|
+
}
|
|
7292
|
+
/**
|
|
7293
|
+
* 将后端插件数据映射为前端格式
|
|
7294
|
+
*/
|
|
7295
|
+
mapPluginData(p) {
|
|
7296
|
+
const capabilities = p.capabilities ? this.parseCapabilities(p.capabilities) : {};
|
|
7297
|
+
let tags = [];
|
|
7298
|
+
if (p.tags) {
|
|
7299
|
+
if (Array.isArray(p.tags)) tags = p.tags;
|
|
7300
|
+
else if (typeof p.tags === "string") try {
|
|
7301
|
+
const parsed = JSON.parse(p.tags);
|
|
7302
|
+
tags = Array.isArray(parsed) ? parsed : [parsed];
|
|
7303
|
+
} catch {
|
|
7304
|
+
tags = p.tags.split(",").map((t) => t.trim()).filter((t) => t);
|
|
7305
|
+
}
|
|
7306
|
+
}
|
|
7307
|
+
return {
|
|
7308
|
+
name: p.name,
|
|
7309
|
+
marketplaceName: p.marketplace_name,
|
|
7310
|
+
description: p.description,
|
|
7311
|
+
version: p.version,
|
|
7312
|
+
iconUrl: p.icon_url,
|
|
7313
|
+
tags,
|
|
7314
|
+
installed: p.installed,
|
|
7315
|
+
status: p.enabled ? "enabled" : p.installed ? "disabled" : "not-installed",
|
|
7316
|
+
installedScopes: p.installed ? [p.installed_scope] : [],
|
|
7317
|
+
...capabilities
|
|
7318
|
+
};
|
|
7319
|
+
}
|
|
7320
|
+
/**
|
|
7321
|
+
* 从缓存中查找插件的 install_id
|
|
7322
|
+
* 如果缓存未命中,则调用 API 获取并缓存
|
|
7323
|
+
*
|
|
7324
|
+
* @param pluginName - 插件名称
|
|
7325
|
+
* @returns install_id 或 null
|
|
7326
|
+
*/
|
|
7327
|
+
async findPluginInstallId(pluginName) {
|
|
7328
|
+
const cached = this.pluginCache.get(pluginName);
|
|
7329
|
+
if (cached) return cached.installId;
|
|
7330
|
+
await this.getInstalledPlugins();
|
|
7331
|
+
return this.pluginCache.get(pluginName)?.installId || null;
|
|
7332
|
+
}
|
|
7333
|
+
/**
|
|
7334
|
+
* 从缓存中查找 marketplace ID
|
|
7335
|
+
* 如果缓存未命中,则调用 API 获取并缓存
|
|
7336
|
+
*/
|
|
7337
|
+
async findMarketplaceId(nameOrId) {
|
|
7338
|
+
const cached = this.marketplaceCache.get(nameOrId);
|
|
7339
|
+
if (cached) return cached.id;
|
|
7340
|
+
await this.getPluginMarketplaces();
|
|
7341
|
+
return this.marketplaceCache.get(nameOrId)?.id || null;
|
|
7342
|
+
}
|
|
7343
|
+
/**
|
|
7344
|
+
* 提取 API 错误信息
|
|
7345
|
+
* 从 AxiosError 中提取详细的错误信息,包括 HTTP 状态码、错误码和错误消息
|
|
7346
|
+
*/
|
|
7347
|
+
extractErrorMessage(error) {
|
|
7348
|
+
if (error instanceof AxiosError) {
|
|
7349
|
+
const status = error.response?.status;
|
|
7350
|
+
const apiResponse = error.response?.data;
|
|
7351
|
+
const parts = [];
|
|
7352
|
+
if (status) parts.push(`HTTP ${status}`);
|
|
7353
|
+
if (apiResponse?.code) parts.push(`Code ${apiResponse.code}`);
|
|
7354
|
+
if (apiResponse?.msg) parts.push(apiResponse.msg);
|
|
7355
|
+
else if (error.message) parts.push(error.message);
|
|
7356
|
+
const errorMessage = parts.join(" - ");
|
|
7357
|
+
this.logger?.error("[CloudAgentProvider] API Error:", {
|
|
7358
|
+
status,
|
|
7359
|
+
code: apiResponse?.code,
|
|
7360
|
+
msg: apiResponse?.msg,
|
|
7361
|
+
requestId: apiResponse?.requestId,
|
|
7362
|
+
url: error.config?.url,
|
|
7363
|
+
method: error.config?.method
|
|
7364
|
+
});
|
|
7365
|
+
return errorMessage;
|
|
7366
|
+
}
|
|
7367
|
+
if (error instanceof Error) return error.message;
|
|
7368
|
+
return "Unknown error";
|
|
7369
|
+
}
|
|
7370
|
+
/**
|
|
7371
|
+
* 映射后端 source_type 到前端类型
|
|
7372
|
+
*/
|
|
7373
|
+
mapSourceType(sourceType) {
|
|
7374
|
+
switch (sourceType) {
|
|
7375
|
+
case "github": return "github";
|
|
7376
|
+
case "official": return "custom";
|
|
7377
|
+
default: return "custom";
|
|
7378
|
+
}
|
|
7379
|
+
}
|
|
7380
|
+
/**
|
|
7381
|
+
* 解析 capabilities JSON 字符串
|
|
7382
|
+
*/
|
|
7383
|
+
parseCapabilities(capabilitiesStr) {
|
|
7384
|
+
try {
|
|
7385
|
+
const cap = JSON.parse(capabilitiesStr);
|
|
7386
|
+
return {
|
|
7387
|
+
commands: cap.commands,
|
|
7388
|
+
skills: cap.skills,
|
|
7389
|
+
mcpServers: cap.mcp,
|
|
7390
|
+
agents: cap.agents,
|
|
7391
|
+
hooks: cap.hooks,
|
|
7392
|
+
rules: cap.rules
|
|
7393
|
+
};
|
|
7394
|
+
} catch {
|
|
7395
|
+
return {};
|
|
7396
|
+
}
|
|
7397
|
+
}
|
|
7398
|
+
/**
|
|
7399
|
+
* 上报 telemetry 事件(Cloud 模式)
|
|
7400
|
+
* 通过 HTTP POST 发送到 /v2/report
|
|
7401
|
+
* 注入用户信息和浏览器环境等公共字段
|
|
7402
|
+
*/
|
|
7403
|
+
async reportTelemetry(eventName, payload) {
|
|
7404
|
+
try {
|
|
7405
|
+
const account = accountService.getAccount();
|
|
7406
|
+
const commonFields = {};
|
|
7407
|
+
if (account) {
|
|
7408
|
+
commonFields.userId = account.uid;
|
|
7409
|
+
commonFields.userNickname = account.nickname;
|
|
7410
|
+
if (account.enterpriseId) commonFields.enterpriseId = account.enterpriseId;
|
|
7411
|
+
if (account.enterpriseUserName) commonFields.username = account.enterpriseUserName;
|
|
7412
|
+
}
|
|
7413
|
+
if (typeof navigator !== "undefined") {
|
|
7414
|
+
commonFields.userAgent = navigator.userAgent;
|
|
7415
|
+
commonFields.os = navigator.platform;
|
|
7416
|
+
}
|
|
7417
|
+
const events = [{
|
|
7418
|
+
eventCode: eventName,
|
|
7419
|
+
timestamp: Date.now(),
|
|
7420
|
+
reportDelay: 0,
|
|
7421
|
+
...commonFields,
|
|
7422
|
+
...payload
|
|
7423
|
+
}];
|
|
7424
|
+
await httpService.post("/v2/report", events);
|
|
7425
|
+
} catch (error) {
|
|
7426
|
+
this.logger?.warn("reportTelemetry() failed:", error);
|
|
7427
|
+
}
|
|
7428
|
+
}
|
|
7429
|
+
};
|
|
7430
|
+
|
|
7431
|
+
//#endregion
|
|
7432
|
+
//#region ../agent-provider/src/common/client/session.ts
|
|
7433
|
+
/**
|
|
7434
|
+
* ActiveSessionImpl - Implements the ActiveSession interface
|
|
7435
|
+
*
|
|
7436
|
+
* This class wraps an AgentConnection and provides the session-centric API.
|
|
7437
|
+
* It is created by SessionManager when creating or loading sessions.
|
|
7438
|
+
*
|
|
7439
|
+
* @example
|
|
7440
|
+
* ```typescript
|
|
7441
|
+
* // Created by client.sessions.new() or client.sessions.load()
|
|
7442
|
+
* const session = await client.sessions.new({ cwd: '/workspace' });
|
|
7443
|
+
*
|
|
7444
|
+
* // Access agent state
|
|
7445
|
+
* console.log(session.agentState.status);
|
|
7446
|
+
*
|
|
7447
|
+
* // Send prompt
|
|
7448
|
+
* const response = await session.prompts.send({ content: 'Hello!' });
|
|
7449
|
+
*
|
|
7450
|
+
* // Cleanup
|
|
7451
|
+
* session.disconnect();
|
|
7452
|
+
* ```
|
|
7453
|
+
*/
|
|
7454
|
+
var ActiveSessionImpl = class {
|
|
7455
|
+
/**
|
|
7456
|
+
* Create an ActiveSessionImpl instance
|
|
7457
|
+
*
|
|
7458
|
+
* @param sessionId - Session ID
|
|
7459
|
+
* @param agentId - Agent ID
|
|
7460
|
+
* @param connection - Already connected AgentConnection
|
|
7461
|
+
* @param options - Additional options
|
|
7462
|
+
*/
|
|
7463
|
+
constructor(sessionId, agentId, connection, options = {}) {
|
|
7464
|
+
this._availableCommands = [];
|
|
7465
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
7466
|
+
this.onceListeners = /* @__PURE__ */ new Map();
|
|
7467
|
+
this.connectionListeners = [];
|
|
7468
|
+
this._id = sessionId;
|
|
7469
|
+
this._agentId = agentId;
|
|
7470
|
+
this.connection = connection;
|
|
7471
|
+
this.logger = options.logger;
|
|
7472
|
+
this._getFilesystem = options.getFilesystem;
|
|
7473
|
+
this._connectionInfo = options.connectionInfo;
|
|
7474
|
+
this.setupConnectionEvents(connection);
|
|
7475
|
+
this.agent = this.createAgentOperations();
|
|
7476
|
+
this.prompts = this.createPromptsResource();
|
|
7477
|
+
this.artifacts = this.createArtifactsResource();
|
|
7478
|
+
this.files = this.createFilesResource();
|
|
7479
|
+
}
|
|
7480
|
+
/**
|
|
7481
|
+
* Session ID
|
|
7482
|
+
*/
|
|
7483
|
+
get id() {
|
|
7484
|
+
return this._id;
|
|
7485
|
+
}
|
|
7486
|
+
/**
|
|
7487
|
+
* Agent ID
|
|
6776
7488
|
*/
|
|
6777
7489
|
get agentId() {
|
|
6778
7490
|
return this._agentId;
|
|
6779
7491
|
}
|
|
6780
7492
|
/**
|
|
7493
|
+
* Actual workspace path (set from newSession response _meta)
|
|
7494
|
+
*/
|
|
7495
|
+
get cwd() {
|
|
7496
|
+
return this._cwd;
|
|
7497
|
+
}
|
|
7498
|
+
/**
|
|
7499
|
+
* Set actual workspace path (called by SessionManager after createSession)
|
|
7500
|
+
*/
|
|
7501
|
+
setCwd(cwd) {
|
|
7502
|
+
this._cwd = cwd;
|
|
7503
|
+
}
|
|
7504
|
+
/**
|
|
6781
7505
|
* Agent state (live connection state)
|
|
6782
7506
|
* Returns LocalAgentState or CloudAgentState based on transport type
|
|
6783
7507
|
*/
|
|
@@ -6971,10 +7695,10 @@ var ActiveSessionImpl = class {
|
|
|
6971
7695
|
return this.connection.cancelQuestion(toolCallId, reason);
|
|
6972
7696
|
}
|
|
6973
7697
|
/**
|
|
6974
|
-
* Callback for tool operations (skip
|
|
7698
|
+
* Callback for tool operations (approve / skip / cancel)
|
|
6975
7699
|
* @param toolCallId Tool call ID
|
|
6976
7700
|
* @param toolName Tool name
|
|
6977
|
-
* @param action Action to perform ('skip'
|
|
7701
|
+
* @param action Action to perform ('approve' / 'skip' / 'cancel')
|
|
6978
7702
|
*/
|
|
6979
7703
|
async toolCallback(toolCallId, toolName, action) {
|
|
6980
7704
|
return await this.getConnectionOrThrow().toolCallback(this._id, toolCallId, toolName, action);
|
|
@@ -7018,6 +7742,7 @@ var ActiveSessionImpl = class {
|
|
|
7018
7742
|
* ```
|
|
7019
7743
|
*/
|
|
7020
7744
|
async setSessionModel(modelId) {
|
|
7745
|
+
this._currentModelId = modelId;
|
|
7021
7746
|
await this.getConnectionOrThrow().setSessionModel(this._id, modelId);
|
|
7022
7747
|
}
|
|
7023
7748
|
/**
|
|
@@ -7095,11 +7820,23 @@ var ActiveSessionImpl = class {
|
|
|
7095
7820
|
* Disconnect from the session/agent
|
|
7096
7821
|
*/
|
|
7097
7822
|
disconnect() {
|
|
7823
|
+
this.removeConnectionListeners();
|
|
7098
7824
|
this.connection.disconnect();
|
|
7099
7825
|
this.removeAllListeners();
|
|
7100
7826
|
this.logger?.info(`Session ${this._id}: Disconnected`);
|
|
7101
7827
|
}
|
|
7102
7828
|
/**
|
|
7829
|
+
* Detach the session from connection events without disconnecting the connection.
|
|
7830
|
+
* This should be called when the session is being replaced but the connection is shared.
|
|
7831
|
+
* Unlike disconnect(), this only removes event listeners without closing the connection.
|
|
7832
|
+
*/
|
|
7833
|
+
detach() {
|
|
7834
|
+
this.logger?.info(`Session ${this._id}: Detaching from connection events`);
|
|
7835
|
+
this.removeConnectionListeners();
|
|
7836
|
+
this.removeAllListeners();
|
|
7837
|
+
this.logger?.info(`Session ${this._id}: Detached successfully`);
|
|
7838
|
+
}
|
|
7839
|
+
/**
|
|
7103
7840
|
* Symbol.dispose for 'using' keyword support
|
|
7104
7841
|
* Automatically disconnects and cleans up when session goes out of scope
|
|
7105
7842
|
*
|
|
@@ -7118,60 +7855,85 @@ var ActiveSessionImpl = class {
|
|
|
7118
7855
|
if (!this.connection.isInitialized) throw new Error(`Session ${this._id}: Connection not initialized.`);
|
|
7119
7856
|
return this.connection;
|
|
7120
7857
|
}
|
|
7858
|
+
/**
|
|
7859
|
+
* 在 connection 上注册 listener 并保存引用,便于 disconnect 时移除
|
|
7860
|
+
*/
|
|
7861
|
+
addConnectionListener(connection, event, listener) {
|
|
7862
|
+
connection.on(event, listener);
|
|
7863
|
+
this.connectionListeners.push({
|
|
7864
|
+
event,
|
|
7865
|
+
listener
|
|
7866
|
+
});
|
|
7867
|
+
}
|
|
7868
|
+
/**
|
|
7869
|
+
* 从 connection 上移除所有本 session 注册的 listener
|
|
7870
|
+
*/
|
|
7871
|
+
removeConnectionListeners() {
|
|
7872
|
+
for (const { event, listener } of this.connectionListeners) this.connection.off(event, listener);
|
|
7873
|
+
this.connectionListeners = [];
|
|
7874
|
+
}
|
|
7121
7875
|
setupConnectionEvents(connection) {
|
|
7122
|
-
|
|
7876
|
+
this.addConnectionListener(connection, "connected", () => {
|
|
7123
7877
|
this.emit("connected", void 0);
|
|
7124
7878
|
});
|
|
7125
|
-
|
|
7879
|
+
this.addConnectionListener(connection, "disconnected", () => {
|
|
7126
7880
|
this.emit("disconnected", void 0);
|
|
7127
7881
|
});
|
|
7128
|
-
|
|
7882
|
+
this.addConnectionListener(connection, "error", (error) => {
|
|
7129
7883
|
this.emit("error", error);
|
|
7130
7884
|
});
|
|
7131
|
-
|
|
7885
|
+
this.addConnectionListener(connection, "sessionUpdate", (update) => {
|
|
7886
|
+
const notificationSessionId = update?.sessionId;
|
|
7887
|
+
if (notificationSessionId && notificationSessionId !== this._id) {
|
|
7888
|
+
console.log(`[RT-DEBUG][AgentMgr:Session] sessionUpdate SKIPPED: notifSessionId mismatch, notif=${notificationSessionId?.substring(0, 8)}, my=${this._id?.substring(0, 8)}`);
|
|
7889
|
+
return;
|
|
7890
|
+
}
|
|
7132
7891
|
this.emit("sessionUpdate", update);
|
|
7133
7892
|
});
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
artifactUri: artifact.uri,
|
|
7137
|
-
artifactType: artifact.type
|
|
7138
|
-
});
|
|
7893
|
+
this.addConnectionListener(connection, "artifactCreated", (artifact) => {
|
|
7894
|
+
if (!this.shouldForwardArtifact(artifact)) return;
|
|
7139
7895
|
this.emit("artifactCreated", artifact);
|
|
7140
7896
|
});
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
artifactUri: artifact.uri,
|
|
7144
|
-
artifactType: artifact.type
|
|
7145
|
-
});
|
|
7897
|
+
this.addConnectionListener(connection, "artifactUpdated", (artifact) => {
|
|
7898
|
+
if (!this.shouldForwardArtifact(artifact)) return;
|
|
7146
7899
|
this.emit("artifactUpdated", artifact);
|
|
7147
7900
|
});
|
|
7148
|
-
|
|
7149
|
-
|
|
7901
|
+
this.addConnectionListener(connection, "artifactDeleted", (artifact) => {
|
|
7902
|
+
if (!this.shouldForwardArtifact(artifact)) return;
|
|
7150
7903
|
this.emit("artifactDeleted", artifact);
|
|
7151
7904
|
});
|
|
7152
|
-
|
|
7905
|
+
this.addConnectionListener(connection, "permissionRequest", (request) => {
|
|
7153
7906
|
this.emit("permissionRequest", request);
|
|
7154
7907
|
});
|
|
7155
|
-
|
|
7908
|
+
this.addConnectionListener(connection, "questionRequest", (request) => {
|
|
7156
7909
|
this.emit("questionRequest", request);
|
|
7157
7910
|
});
|
|
7158
|
-
|
|
7911
|
+
this.addConnectionListener(connection, "questionCancelled", () => {
|
|
7159
7912
|
this.prompts.cancel();
|
|
7160
7913
|
});
|
|
7161
|
-
|
|
7914
|
+
this.addConnectionListener(connection, "usageUpdate", (usage) => {
|
|
7162
7915
|
this.emit("usageUpdate", usage);
|
|
7163
7916
|
});
|
|
7164
|
-
|
|
7917
|
+
this.addConnectionListener(connection, "checkpointCreated", (checkpoint) => {
|
|
7918
|
+
const originSessionId = checkpoint.__sessionId;
|
|
7919
|
+
if (originSessionId && originSessionId !== this._id) return;
|
|
7165
7920
|
this.emit("checkpointCreated", checkpoint);
|
|
7166
7921
|
});
|
|
7167
|
-
|
|
7922
|
+
this.addConnectionListener(connection, "checkpointUpdated", (checkpoint) => {
|
|
7923
|
+
const originSessionId = checkpoint.__sessionId;
|
|
7924
|
+
if (originSessionId && originSessionId !== this._id) return;
|
|
7168
7925
|
this.emit("checkpointUpdated", checkpoint);
|
|
7169
7926
|
});
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7927
|
+
this.addConnectionListener(connection, "command", (command) => {
|
|
7928
|
+
const originSessionId = command.__sessionId;
|
|
7929
|
+
if (originSessionId && originSessionId !== this._id) {
|
|
7930
|
+
console.log("[Session] Command not forwarded:", {
|
|
7931
|
+
command,
|
|
7932
|
+
originSessionId,
|
|
7933
|
+
sessionId: this._id
|
|
7934
|
+
});
|
|
7935
|
+
return;
|
|
7936
|
+
}
|
|
7175
7937
|
this.emit("command", command);
|
|
7176
7938
|
});
|
|
7177
7939
|
}
|
|
@@ -7181,6 +7943,15 @@ var ActiveSessionImpl = class {
|
|
|
7181
7943
|
_meta: response._meta ?? void 0
|
|
7182
7944
|
};
|
|
7183
7945
|
}
|
|
7946
|
+
/**
|
|
7947
|
+
* 判断 artifact 是否应该转发给当前 session
|
|
7948
|
+
* 所有类型的 artifact 都按 __sessionId 严格隔离
|
|
7949
|
+
*/
|
|
7950
|
+
shouldForwardArtifact(artifact) {
|
|
7951
|
+
const originSessionId = artifact.__sessionId;
|
|
7952
|
+
if (!originSessionId || originSessionId !== this._id) return false;
|
|
7953
|
+
return true;
|
|
7954
|
+
}
|
|
7184
7955
|
};
|
|
7185
7956
|
|
|
7186
7957
|
//#endregion
|
|
@@ -7235,7 +8006,8 @@ var SessionManager = class {
|
|
|
7235
8006
|
createdAt: agent.createdAt,
|
|
7236
8007
|
lastActivityAt: agent.updatedAt,
|
|
7237
8008
|
cwd: agent.type === "local" ? agent.cwd : void 0,
|
|
7238
|
-
isPlayground: agent.isPlayground
|
|
8009
|
+
isPlayground: agent.isPlayground,
|
|
8010
|
+
isUserDefinedTitle: agent.isUserDefinedTitle
|
|
7239
8011
|
}));
|
|
7240
8012
|
console.log("[SessionManager] Returning sessions:", {
|
|
7241
8013
|
count: sessions.length,
|
|
@@ -7262,13 +8034,26 @@ var SessionManager = class {
|
|
|
7262
8034
|
if (this.provider.create) {
|
|
7263
8035
|
agentId = await this.provider.create(params);
|
|
7264
8036
|
this.logger?.debug(`Created new agent: ${agentId}`);
|
|
8037
|
+
if (params.options?.onSessionPrepared) {
|
|
8038
|
+
const initialPrompt = params.options?.prompt;
|
|
8039
|
+
const initialTitle = initialPrompt?.slice(0, 50) || "";
|
|
8040
|
+
params.options.onSessionPrepared({
|
|
8041
|
+
id: agentId,
|
|
8042
|
+
agentId,
|
|
8043
|
+
name: initialTitle + (initialPrompt && initialPrompt.length > 50 ? "..." : ""),
|
|
8044
|
+
status: "connecting",
|
|
8045
|
+
cwd: params.cwd || "",
|
|
8046
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
8047
|
+
});
|
|
8048
|
+
this.logger?.debug(`Called onSessionPrepared for: ${agentId}`);
|
|
8049
|
+
}
|
|
7265
8050
|
} else throw new Error("Provider does not support creating agents. Use sessions.load() with an existing sessionId.");
|
|
7266
8051
|
const connection = await this.provider.connect(agentId);
|
|
7267
8052
|
this.logger?.debug(`Connected to agent: ${agentId}`);
|
|
7268
8053
|
const response = await connection.createSession({
|
|
7269
|
-
_meta: params._meta,
|
|
8054
|
+
_meta: params.options?._meta,
|
|
7270
8055
|
cwd: params.cwd,
|
|
7271
|
-
mcpServers: params.mcpServers
|
|
8056
|
+
mcpServers: params.options?.mcpServers
|
|
7272
8057
|
});
|
|
7273
8058
|
if (this.provider.registerSession) {
|
|
7274
8059
|
this.provider.registerSession(response.sessionId, agentId);
|
|
@@ -7283,6 +8068,8 @@ var SessionManager = class {
|
|
|
7283
8068
|
session.setModes(response.modes?.availableModes, response.modes?.currentModeId);
|
|
7284
8069
|
const availableModels = this.extractAvailableModels(response);
|
|
7285
8070
|
if (availableModels) session.setModels(availableModels, response.models?.currentModelId);
|
|
8071
|
+
const responseCwd = response._meta?.["codebuddy.ai"]?.cwd;
|
|
8072
|
+
if (responseCwd) session.setCwd(responseCwd);
|
|
7286
8073
|
this.logger?.info(`Session created: ${response.sessionId}`);
|
|
7287
8074
|
return session;
|
|
7288
8075
|
}
|
|
@@ -7449,6 +8236,26 @@ var AgentClient = class {
|
|
|
7449
8236
|
throw error;
|
|
7450
8237
|
}
|
|
7451
8238
|
},
|
|
8239
|
+
updateStatus: async (sessionId, status) => {
|
|
8240
|
+
this.logger?.debug("AgentClient.sessions.updateStatus called", {
|
|
8241
|
+
sessionId,
|
|
8242
|
+
status
|
|
8243
|
+
});
|
|
8244
|
+
try {
|
|
8245
|
+
if (this.provider.updateStatus) {
|
|
8246
|
+
const result = await this.provider.updateStatus(sessionId, status);
|
|
8247
|
+
this.logger?.info("Session status updated successfully", {
|
|
8248
|
+
sessionId,
|
|
8249
|
+
status
|
|
8250
|
+
});
|
|
8251
|
+
return result;
|
|
8252
|
+
}
|
|
8253
|
+
throw new Error("Provider does not support updateStatus method");
|
|
8254
|
+
} catch (error) {
|
|
8255
|
+
this.logger?.error("Failed to update session status", error);
|
|
8256
|
+
throw error;
|
|
8257
|
+
}
|
|
8258
|
+
},
|
|
7452
8259
|
move: async (sessionId) => {
|
|
7453
8260
|
this.logger?.debug("AgentClient.sessions.move called", { sessionId });
|
|
7454
8261
|
try {
|
|
@@ -7481,6 +8288,16 @@ var AgentClient = class {
|
|
|
7481
8288
|
};
|
|
7482
8289
|
}
|
|
7483
8290
|
},
|
|
8291
|
+
requestYieldAfterCurrentStep: async (sessionId) => {
|
|
8292
|
+
try {
|
|
8293
|
+
if (this.provider?.requestYieldAfterCurrentStep) return await this.provider.requestYieldAfterCurrentStep(sessionId);
|
|
8294
|
+
this.logger?.warn("Provider does not support requestYieldAfterCurrentStep");
|
|
8295
|
+
return false;
|
|
8296
|
+
} catch (error) {
|
|
8297
|
+
this.logger?.error("Failed to request yield after current step", error);
|
|
8298
|
+
return false;
|
|
8299
|
+
}
|
|
8300
|
+
},
|
|
7484
8301
|
getCurrentWorkspaces: async (filter) => {
|
|
7485
8302
|
this.logger?.debug("AgentClient.sessions.getCurrentWorkspaces called", filter);
|
|
7486
8303
|
try {
|
|
@@ -7496,6 +8313,100 @@ var AgentClient = class {
|
|
|
7496
8313
|
return [];
|
|
7497
8314
|
}
|
|
7498
8315
|
},
|
|
8316
|
+
getAutomationSnapshot: async () => {
|
|
8317
|
+
try {
|
|
8318
|
+
if (this.provider?.getAutomationSnapshot) return await this.provider.getAutomationSnapshot();
|
|
8319
|
+
this.logger?.warn("Provider does not support getAutomationSnapshot");
|
|
8320
|
+
} catch (error) {
|
|
8321
|
+
this.logger?.error("Failed to get automation snapshot", error);
|
|
8322
|
+
}
|
|
8323
|
+
return {
|
|
8324
|
+
automations: [],
|
|
8325
|
+
inbox: [],
|
|
8326
|
+
runtimeState: {},
|
|
8327
|
+
updatedAt: Date.now()
|
|
8328
|
+
};
|
|
8329
|
+
},
|
|
8330
|
+
updateAutomation: async (payload) => {
|
|
8331
|
+
try {
|
|
8332
|
+
if (this.provider?.updateAutomation) return await this.provider.updateAutomation(payload);
|
|
8333
|
+
this.logger?.warn("Provider does not support updateAutomation");
|
|
8334
|
+
} catch (error) {
|
|
8335
|
+
this.logger?.error("Failed to update automation", error);
|
|
8336
|
+
return {
|
|
8337
|
+
success: false,
|
|
8338
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
8339
|
+
};
|
|
8340
|
+
}
|
|
8341
|
+
return {
|
|
8342
|
+
success: false,
|
|
8343
|
+
message: "Provider does not support updateAutomation"
|
|
8344
|
+
};
|
|
8345
|
+
},
|
|
8346
|
+
deleteAutomation: async (id) => {
|
|
8347
|
+
try {
|
|
8348
|
+
if (this.provider?.deleteAutomation) return await this.provider.deleteAutomation(id);
|
|
8349
|
+
this.logger?.warn("Provider does not support deleteAutomation");
|
|
8350
|
+
} catch (error) {
|
|
8351
|
+
this.logger?.error("Failed to delete automation", error);
|
|
8352
|
+
return {
|
|
8353
|
+
success: false,
|
|
8354
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
8355
|
+
};
|
|
8356
|
+
}
|
|
8357
|
+
return {
|
|
8358
|
+
success: false,
|
|
8359
|
+
message: "Provider does not support deleteAutomation"
|
|
8360
|
+
};
|
|
8361
|
+
},
|
|
8362
|
+
archiveAutomationInboxItem: async (itemId) => {
|
|
8363
|
+
try {
|
|
8364
|
+
if (this.provider?.archiveAutomationInboxItem) return await this.provider.archiveAutomationInboxItem(itemId);
|
|
8365
|
+
this.logger?.warn("Provider does not support archiveAutomationInboxItem");
|
|
8366
|
+
} catch (error) {
|
|
8367
|
+
this.logger?.error("Failed to archive automation inbox item", error);
|
|
8368
|
+
return {
|
|
8369
|
+
success: false,
|
|
8370
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
8371
|
+
};
|
|
8372
|
+
}
|
|
8373
|
+
return {
|
|
8374
|
+
success: false,
|
|
8375
|
+
message: "Provider does not support archiveAutomationInboxItem"
|
|
8376
|
+
};
|
|
8377
|
+
},
|
|
8378
|
+
deleteAutomationInboxItem: async (itemId) => {
|
|
8379
|
+
try {
|
|
8380
|
+
if (this.provider?.deleteAutomationInboxItem) return await this.provider.deleteAutomationInboxItem(itemId);
|
|
8381
|
+
this.logger?.warn("Provider does not support deleteAutomationInboxItem");
|
|
8382
|
+
} catch (error) {
|
|
8383
|
+
this.logger?.error("Failed to delete automation inbox item", error);
|
|
8384
|
+
return {
|
|
8385
|
+
success: false,
|
|
8386
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
8387
|
+
};
|
|
8388
|
+
}
|
|
8389
|
+
return {
|
|
8390
|
+
success: false,
|
|
8391
|
+
message: "Provider does not support deleteAutomationInboxItem"
|
|
8392
|
+
};
|
|
8393
|
+
},
|
|
8394
|
+
testAutomation: async (id) => {
|
|
8395
|
+
try {
|
|
8396
|
+
if (this.provider?.testAutomation) return await this.provider.testAutomation(id);
|
|
8397
|
+
this.logger?.warn("Provider does not support testAutomation");
|
|
8398
|
+
} catch (error) {
|
|
8399
|
+
this.logger?.error("Failed to test automation", error);
|
|
8400
|
+
return {
|
|
8401
|
+
success: false,
|
|
8402
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
8403
|
+
};
|
|
8404
|
+
}
|
|
8405
|
+
return {
|
|
8406
|
+
success: false,
|
|
8407
|
+
message: "Provider does not support testAutomation"
|
|
8408
|
+
};
|
|
8409
|
+
},
|
|
7499
8410
|
on: (event, handler) => {
|
|
7500
8411
|
if (this.provider.on) this.provider.on(event, handler);
|
|
7501
8412
|
else this.logger?.warn(`Provider does not support event registration: ${String(event)}`);
|
|
@@ -7637,6 +8548,167 @@ var AgentClient = class {
|
|
|
7637
8548
|
};
|
|
7638
8549
|
}
|
|
7639
8550
|
},
|
|
8551
|
+
getSkillList: async (params) => {
|
|
8552
|
+
try {
|
|
8553
|
+
if (this.provider && this.provider.getSkillList) {
|
|
8554
|
+
const result = await this.provider.getSkillList(params);
|
|
8555
|
+
this.logger?.info("Skill list retrieved", {
|
|
8556
|
+
resultCount: result.results.length,
|
|
8557
|
+
hasError: !!result.error
|
|
8558
|
+
});
|
|
8559
|
+
return result;
|
|
8560
|
+
}
|
|
8561
|
+
return {
|
|
8562
|
+
results: [],
|
|
8563
|
+
error: "Provider does not support getSkillList"
|
|
8564
|
+
};
|
|
8565
|
+
} catch (error) {
|
|
8566
|
+
this.logger?.error("Failed to get skill list", error);
|
|
8567
|
+
return {
|
|
8568
|
+
results: [],
|
|
8569
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8570
|
+
};
|
|
8571
|
+
}
|
|
8572
|
+
},
|
|
8573
|
+
importSkill: async (params) => {
|
|
8574
|
+
try {
|
|
8575
|
+
if (this.provider && this.provider.importSkill) {
|
|
8576
|
+
const result = await this.provider.importSkill(params);
|
|
8577
|
+
this.logger?.info("Import skill completed", {
|
|
8578
|
+
success: result.success,
|
|
8579
|
+
hasError: !!result.error
|
|
8580
|
+
});
|
|
8581
|
+
return result;
|
|
8582
|
+
}
|
|
8583
|
+
return {
|
|
8584
|
+
success: false,
|
|
8585
|
+
error: "Provider does not support importSkill"
|
|
8586
|
+
};
|
|
8587
|
+
} catch (error) {
|
|
8588
|
+
this.logger?.error("Failed to import skill", error);
|
|
8589
|
+
return {
|
|
8590
|
+
success: false,
|
|
8591
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8592
|
+
};
|
|
8593
|
+
}
|
|
8594
|
+
},
|
|
8595
|
+
toggleSkill: async (params) => {
|
|
8596
|
+
try {
|
|
8597
|
+
if (this.provider && this.provider.toggleSkill) {
|
|
8598
|
+
const result = await this.provider.toggleSkill(params);
|
|
8599
|
+
this.logger?.info("Toggle skill completed", {
|
|
8600
|
+
success: result.success,
|
|
8601
|
+
hasError: !!result.error
|
|
8602
|
+
});
|
|
8603
|
+
return result;
|
|
8604
|
+
}
|
|
8605
|
+
return {
|
|
8606
|
+
success: false,
|
|
8607
|
+
error: "Provider does not support toggleSkill"
|
|
8608
|
+
};
|
|
8609
|
+
} catch (error) {
|
|
8610
|
+
this.logger?.error("Failed to toggle skill", error);
|
|
8611
|
+
return {
|
|
8612
|
+
success: false,
|
|
8613
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8614
|
+
};
|
|
8615
|
+
}
|
|
8616
|
+
},
|
|
8617
|
+
deleteSkill: async (params) => {
|
|
8618
|
+
try {
|
|
8619
|
+
if (this.provider && this.provider.deleteSkill) {
|
|
8620
|
+
const result = await this.provider.deleteSkill(params);
|
|
8621
|
+
this.logger?.info("Delete skill completed", {
|
|
8622
|
+
success: result.success,
|
|
8623
|
+
hasError: !!result.error
|
|
8624
|
+
});
|
|
8625
|
+
return result;
|
|
8626
|
+
}
|
|
8627
|
+
return {
|
|
8628
|
+
success: false,
|
|
8629
|
+
error: "Provider does not support deleteSkill"
|
|
8630
|
+
};
|
|
8631
|
+
} catch (error) {
|
|
8632
|
+
this.logger?.error("Failed to delete skill", error);
|
|
8633
|
+
return {
|
|
8634
|
+
success: false,
|
|
8635
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8636
|
+
};
|
|
8637
|
+
}
|
|
8638
|
+
},
|
|
8639
|
+
getSkillContent: async (params) => {
|
|
8640
|
+
try {
|
|
8641
|
+
if (this.provider && this.provider.getSkillContent) {
|
|
8642
|
+
const result = await this.provider.getSkillContent(params);
|
|
8643
|
+
this.logger?.info("Get skill content completed", { hasError: !!result.error });
|
|
8644
|
+
return result;
|
|
8645
|
+
}
|
|
8646
|
+
return {
|
|
8647
|
+
content: "",
|
|
8648
|
+
error: "Provider does not support getSkillContent"
|
|
8649
|
+
};
|
|
8650
|
+
} catch (error) {
|
|
8651
|
+
this.logger?.error("Failed to get skill content", error);
|
|
8652
|
+
return {
|
|
8653
|
+
content: "",
|
|
8654
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8655
|
+
};
|
|
8656
|
+
}
|
|
8657
|
+
},
|
|
8658
|
+
getMarketplaceSkills: async () => {
|
|
8659
|
+
try {
|
|
8660
|
+
if (this.provider && this.provider.getMarketplaceSkills) {
|
|
8661
|
+
const result = await this.provider.getMarketplaceSkills();
|
|
8662
|
+
this.logger?.info("Marketplace skills retrieved", {
|
|
8663
|
+
resultCount: result.results.length,
|
|
8664
|
+
hasError: !!result.error
|
|
8665
|
+
});
|
|
8666
|
+
return result;
|
|
8667
|
+
}
|
|
8668
|
+
return {
|
|
8669
|
+
results: [],
|
|
8670
|
+
error: "Provider does not support getMarketplaceSkills"
|
|
8671
|
+
};
|
|
8672
|
+
} catch (error) {
|
|
8673
|
+
this.logger?.error("Failed to get marketplace skills", error);
|
|
8674
|
+
return {
|
|
8675
|
+
results: [],
|
|
8676
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8677
|
+
};
|
|
8678
|
+
}
|
|
8679
|
+
},
|
|
8680
|
+
getMarketplaceSkillContent: async (params) => {
|
|
8681
|
+
try {
|
|
8682
|
+
if (this.provider && this.provider.getMarketplaceSkillContent) return await this.provider.getMarketplaceSkillContent(params);
|
|
8683
|
+
return {
|
|
8684
|
+
content: "",
|
|
8685
|
+
error: "Provider does not support getMarketplaceSkillContent"
|
|
8686
|
+
};
|
|
8687
|
+
} catch (error) {
|
|
8688
|
+
this.logger?.error("Failed to get marketplace skill content", error);
|
|
8689
|
+
return {
|
|
8690
|
+
content: "",
|
|
8691
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8692
|
+
};
|
|
8693
|
+
}
|
|
8694
|
+
},
|
|
8695
|
+
installMarketplaceSkill: async (params) => {
|
|
8696
|
+
try {
|
|
8697
|
+
if (this.provider && this.provider.installMarketplaceSkill) return await this.provider.installMarketplaceSkill(params);
|
|
8698
|
+
return {
|
|
8699
|
+
success: false,
|
|
8700
|
+
skillName: params.skillName,
|
|
8701
|
+
errorMessage: "Provider does not support installMarketplaceSkill"
|
|
8702
|
+
};
|
|
8703
|
+
} catch (error) {
|
|
8704
|
+
this.logger?.error("Failed to install marketplace skill", error);
|
|
8705
|
+
return {
|
|
8706
|
+
success: false,
|
|
8707
|
+
skillName: params.skillName,
|
|
8708
|
+
errorMessage: error instanceof Error ? error.message : "Unknown error"
|
|
8709
|
+
};
|
|
8710
|
+
}
|
|
8711
|
+
},
|
|
7640
8712
|
batchTogglePlugins: async (request) => {
|
|
7641
8713
|
try {
|
|
7642
8714
|
if (this.provider && this.provider.batchTogglePlugins) {
|
|
@@ -7681,37 +8753,229 @@ var AgentClient = class {
|
|
|
7681
8753
|
return [];
|
|
7682
8754
|
}
|
|
7683
8755
|
},
|
|
7684
|
-
installPlugins: async (pluginNames, marketplaceName, installScope, marketplaceSource) => {
|
|
8756
|
+
installPlugins: async (pluginNames, marketplaceName, installScope, marketplaceSource, workspacePath) => {
|
|
8757
|
+
try {
|
|
8758
|
+
if (this.provider && "installPlugins" in this.provider && typeof this.provider.installPlugins === "function") {
|
|
8759
|
+
const result = await this.provider.installPlugins(pluginNames, marketplaceName, installScope, marketplaceSource, workspacePath);
|
|
8760
|
+
this.logger?.info("Install plugins", {
|
|
8761
|
+
pluginNames,
|
|
8762
|
+
marketplaceName,
|
|
8763
|
+
success: result.success
|
|
8764
|
+
});
|
|
8765
|
+
return result;
|
|
8766
|
+
}
|
|
8767
|
+
this.logger?.warn("Provider does not support installPlugins");
|
|
8768
|
+
return {
|
|
8769
|
+
success: false,
|
|
8770
|
+
error: "Provider does not support installPlugins"
|
|
8771
|
+
};
|
|
8772
|
+
} catch (error) {
|
|
8773
|
+
this.logger?.error("Failed to install plugins", error);
|
|
8774
|
+
return {
|
|
8775
|
+
success: false,
|
|
8776
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8777
|
+
};
|
|
8778
|
+
}
|
|
8779
|
+
},
|
|
8780
|
+
uninstallPlugin: async (pluginName, marketplaceName, scope) => {
|
|
8781
|
+
try {
|
|
8782
|
+
if (this.provider && "uninstallPlugin" in this.provider && typeof this.provider.uninstallPlugin === "function") {
|
|
8783
|
+
const result = await this.provider.uninstallPlugin(pluginName, marketplaceName, scope);
|
|
8784
|
+
this.logger?.info("Uninstall plugin", {
|
|
8785
|
+
pluginName,
|
|
8786
|
+
marketplaceName,
|
|
8787
|
+
scope,
|
|
8788
|
+
success: result.success
|
|
8789
|
+
});
|
|
8790
|
+
return result;
|
|
8791
|
+
}
|
|
8792
|
+
this.logger?.warn("Provider does not support uninstallPlugin");
|
|
8793
|
+
return {
|
|
8794
|
+
success: false,
|
|
8795
|
+
error: "Provider does not support uninstallPlugin"
|
|
8796
|
+
};
|
|
8797
|
+
} catch (error) {
|
|
8798
|
+
this.logger?.error("Failed to uninstall plugin", error);
|
|
8799
|
+
return {
|
|
8800
|
+
success: false,
|
|
8801
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8802
|
+
};
|
|
8803
|
+
}
|
|
8804
|
+
},
|
|
8805
|
+
updatePlugin: async (pluginName, marketplaceName) => {
|
|
8806
|
+
try {
|
|
8807
|
+
if (this.provider && "updatePlugin" in this.provider && typeof this.provider.updatePlugin === "function") {
|
|
8808
|
+
const result = await this.provider.updatePlugin(pluginName, marketplaceName);
|
|
8809
|
+
this.logger?.info("Update plugin", {
|
|
8810
|
+
pluginName,
|
|
8811
|
+
marketplaceName,
|
|
8812
|
+
success: result.success
|
|
8813
|
+
});
|
|
8814
|
+
return result;
|
|
8815
|
+
}
|
|
8816
|
+
this.logger?.warn("Provider does not support updatePlugin");
|
|
8817
|
+
return {
|
|
8818
|
+
success: false,
|
|
8819
|
+
error: "Provider does not support updatePlugin"
|
|
8820
|
+
};
|
|
8821
|
+
} catch (error) {
|
|
8822
|
+
this.logger?.error("Failed to update plugin", error);
|
|
8823
|
+
return {
|
|
8824
|
+
success: false,
|
|
8825
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8826
|
+
};
|
|
8827
|
+
}
|
|
8828
|
+
},
|
|
8829
|
+
getPluginMarketplaces: async (forceRefresh) => {
|
|
8830
|
+
try {
|
|
8831
|
+
if (this.provider && "getPluginMarketplaces" in this.provider && typeof this.provider.getPluginMarketplaces === "function") {
|
|
8832
|
+
const result = await this.provider.getPluginMarketplaces(forceRefresh);
|
|
8833
|
+
this.logger?.info("Got plugin marketplaces", { count: result?.length ?? 0 });
|
|
8834
|
+
return result;
|
|
8835
|
+
}
|
|
8836
|
+
this.logger?.warn("Provider does not support getPluginMarketplaces");
|
|
8837
|
+
return [];
|
|
8838
|
+
} catch (error) {
|
|
8839
|
+
this.logger?.error("Failed to get plugin marketplaces", error);
|
|
8840
|
+
return [];
|
|
8841
|
+
}
|
|
8842
|
+
},
|
|
8843
|
+
getMarketplacePlugins: async (marketplaceName, forceRefresh, searchText) => {
|
|
8844
|
+
try {
|
|
8845
|
+
if (this.provider && "getMarketplacePlugins" in this.provider && typeof this.provider.getMarketplacePlugins === "function") {
|
|
8846
|
+
const result = await this.provider.getMarketplacePlugins(marketplaceName, forceRefresh, searchText);
|
|
8847
|
+
this.logger?.info("Got marketplace plugins", {
|
|
8848
|
+
marketplaceName,
|
|
8849
|
+
count: result?.length ?? 0
|
|
8850
|
+
});
|
|
8851
|
+
return result;
|
|
8852
|
+
}
|
|
8853
|
+
this.logger?.warn("Provider does not support getMarketplacePlugins");
|
|
8854
|
+
return [];
|
|
8855
|
+
} catch (error) {
|
|
8856
|
+
this.logger?.error("Failed to get marketplace plugins", error);
|
|
8857
|
+
return [];
|
|
8858
|
+
}
|
|
8859
|
+
},
|
|
8860
|
+
getPluginDetail: async (pluginName, marketplaceName) => {
|
|
8861
|
+
try {
|
|
8862
|
+
if (this.provider && "getPluginDetail" in this.provider && typeof this.provider.getPluginDetail === "function") {
|
|
8863
|
+
const result = await this.provider.getPluginDetail(pluginName, marketplaceName);
|
|
8864
|
+
this.logger?.info("Got plugin detail", {
|
|
8865
|
+
pluginName,
|
|
8866
|
+
marketplaceName
|
|
8867
|
+
});
|
|
8868
|
+
return result;
|
|
8869
|
+
}
|
|
8870
|
+
this.logger?.warn("Provider does not support getPluginDetail");
|
|
8871
|
+
return null;
|
|
8872
|
+
} catch (error) {
|
|
8873
|
+
this.logger?.error("Failed to get plugin detail", error);
|
|
8874
|
+
return null;
|
|
8875
|
+
}
|
|
8876
|
+
},
|
|
8877
|
+
addPluginMarketplace: async (source, name) => {
|
|
8878
|
+
try {
|
|
8879
|
+
if (this.provider && "addPluginMarketplace" in this.provider && typeof this.provider.addPluginMarketplace === "function") {
|
|
8880
|
+
const result = await this.provider.addPluginMarketplace(source, name);
|
|
8881
|
+
this.logger?.info("Add plugin marketplace", {
|
|
8882
|
+
source,
|
|
8883
|
+
name,
|
|
8884
|
+
success: result.success
|
|
8885
|
+
});
|
|
8886
|
+
return result;
|
|
8887
|
+
}
|
|
8888
|
+
this.logger?.warn("Provider does not support addPluginMarketplace");
|
|
8889
|
+
return {
|
|
8890
|
+
success: false,
|
|
8891
|
+
error: "Provider does not support addPluginMarketplace"
|
|
8892
|
+
};
|
|
8893
|
+
} catch (error) {
|
|
8894
|
+
this.logger?.error("Failed to add plugin marketplace", error);
|
|
8895
|
+
return {
|
|
8896
|
+
success: false,
|
|
8897
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8898
|
+
};
|
|
8899
|
+
}
|
|
8900
|
+
},
|
|
8901
|
+
removePluginMarketplace: async (marketplaceName) => {
|
|
8902
|
+
try {
|
|
8903
|
+
if (this.provider && "removePluginMarketplace" in this.provider && typeof this.provider.removePluginMarketplace === "function") {
|
|
8904
|
+
const result = await this.provider.removePluginMarketplace(marketplaceName);
|
|
8905
|
+
this.logger?.info("Remove plugin marketplace", {
|
|
8906
|
+
marketplaceName,
|
|
8907
|
+
success: result.success
|
|
8908
|
+
});
|
|
8909
|
+
return result;
|
|
8910
|
+
}
|
|
8911
|
+
this.logger?.warn("Provider does not support removePluginMarketplace");
|
|
8912
|
+
return {
|
|
8913
|
+
success: false,
|
|
8914
|
+
error: "Provider does not support removePluginMarketplace"
|
|
8915
|
+
};
|
|
8916
|
+
} catch (error) {
|
|
8917
|
+
this.logger?.error("Failed to remove plugin marketplace", error);
|
|
8918
|
+
return {
|
|
8919
|
+
success: false,
|
|
8920
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
8921
|
+
};
|
|
8922
|
+
}
|
|
8923
|
+
},
|
|
8924
|
+
refreshPluginMarketplace: async (marketplaceName) => {
|
|
7685
8925
|
try {
|
|
7686
|
-
if (this.provider && "
|
|
7687
|
-
const result = await this.provider.
|
|
7688
|
-
this.logger?.info("
|
|
7689
|
-
pluginNames,
|
|
8926
|
+
if (this.provider && "refreshPluginMarketplace" in this.provider && typeof this.provider.refreshPluginMarketplace === "function") {
|
|
8927
|
+
const result = await this.provider.refreshPluginMarketplace(marketplaceName);
|
|
8928
|
+
this.logger?.info("Refresh plugin marketplace", {
|
|
7690
8929
|
marketplaceName,
|
|
7691
8930
|
success: result.success
|
|
7692
8931
|
});
|
|
7693
8932
|
return result;
|
|
7694
8933
|
}
|
|
7695
|
-
this.logger?.warn("Provider does not support
|
|
8934
|
+
this.logger?.warn("Provider does not support refreshPluginMarketplace");
|
|
7696
8935
|
return {
|
|
7697
8936
|
success: false,
|
|
7698
|
-
error: "Provider does not support
|
|
8937
|
+
error: "Provider does not support refreshPluginMarketplace"
|
|
7699
8938
|
};
|
|
7700
8939
|
} catch (error) {
|
|
7701
|
-
this.logger?.error("Failed to
|
|
8940
|
+
this.logger?.error("Failed to refresh plugin marketplace", error);
|
|
7702
8941
|
return {
|
|
7703
8942
|
success: false,
|
|
7704
8943
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
7705
8944
|
};
|
|
7706
8945
|
}
|
|
7707
8946
|
},
|
|
7708
|
-
|
|
8947
|
+
openFolderInNewWindow: async (folderPath) => {
|
|
8948
|
+
try {
|
|
8949
|
+
if (this.provider && "openFolderInNewWindow" in this.provider && typeof this.provider.openFolderInNewWindow === "function") {
|
|
8950
|
+
await this.provider.openFolderInNewWindow(folderPath);
|
|
8951
|
+
this.logger?.info("Opened folder in new window", { folderPath });
|
|
8952
|
+
} else {
|
|
8953
|
+
this.logger?.warn("Provider does not support openFolderInNewWindow");
|
|
8954
|
+
throw new Error("Provider does not support openFolderInNewWindow");
|
|
8955
|
+
}
|
|
8956
|
+
} catch (error) {
|
|
8957
|
+
this.logger?.error("Failed to open folder in new window", error);
|
|
8958
|
+
throw error;
|
|
8959
|
+
}
|
|
8960
|
+
},
|
|
8961
|
+
openFolder: async (folderPath) => {
|
|
7709
8962
|
try {
|
|
7710
|
-
if (this.provider && "
|
|
7711
|
-
const result = await this.provider.
|
|
7712
|
-
this.logger?.info("
|
|
8963
|
+
if (this.provider && "openFolder" in this.provider && typeof this.provider.openFolder === "function") {
|
|
8964
|
+
const result = await this.provider.openFolder(folderPath);
|
|
8965
|
+
this.logger?.info("Opened folder in system file manager", { folderPath });
|
|
7713
8966
|
return result;
|
|
8967
|
+
} else {
|
|
8968
|
+
this.logger?.warn("Provider does not support openFolder");
|
|
8969
|
+
throw new Error("Provider does not support openFolder");
|
|
7714
8970
|
}
|
|
8971
|
+
} catch (error) {
|
|
8972
|
+
this.logger?.error("Failed to open folder", error);
|
|
8973
|
+
throw error;
|
|
8974
|
+
}
|
|
8975
|
+
},
|
|
8976
|
+
getSupportScenes: async (locale) => {
|
|
8977
|
+
try {
|
|
8978
|
+
if (this.provider && "getSupportScenes" in this.provider && typeof this.provider.getSupportScenes === "function") return await this.provider.getSupportScenes(locale);
|
|
7715
8979
|
this.logger?.warn("Provider does not support getSupportScenes");
|
|
7716
8980
|
return [];
|
|
7717
8981
|
} catch (error) {
|
|
@@ -7719,23 +8983,193 @@ var AgentClient = class {
|
|
|
7719
8983
|
return [];
|
|
7720
8984
|
}
|
|
7721
8985
|
},
|
|
7722
|
-
|
|
8986
|
+
getProductScenes: async (locale) => {
|
|
8987
|
+
try {
|
|
8988
|
+
if (this.provider?.getProductScenes) {
|
|
8989
|
+
const result = await this.provider.getProductScenes(locale);
|
|
8990
|
+
this.logger?.info("Got product scenes", { count: result?.length ?? 0 });
|
|
8991
|
+
return result;
|
|
8992
|
+
}
|
|
8993
|
+
this.logger?.warn("Provider does not support getProductScenes");
|
|
8994
|
+
return [];
|
|
8995
|
+
} catch (error) {
|
|
8996
|
+
this.logger?.error("Failed to get product scenes", error);
|
|
8997
|
+
return [];
|
|
8998
|
+
}
|
|
8999
|
+
},
|
|
9000
|
+
getAvailableCommands: async (params) => {
|
|
7723
9001
|
try {
|
|
7724
9002
|
if (this.provider && "getAvailableCommands" in this.provider && typeof this.provider.getAvailableCommands === "function") {
|
|
7725
|
-
const result = await this.provider.getAvailableCommands(
|
|
9003
|
+
const result = await this.provider.getAvailableCommands(params);
|
|
7726
9004
|
this.logger?.info("Got available commands from provider", {
|
|
7727
|
-
sessionId: sessionId ?? "(default)",
|
|
9005
|
+
sessionId: params?.sessionId ?? "(default)",
|
|
7728
9006
|
count: result?.length ?? 0
|
|
7729
9007
|
});
|
|
7730
9008
|
return result;
|
|
7731
9009
|
}
|
|
7732
|
-
this.logger?.warn("Provider does not support getAvailableCommands", {
|
|
9010
|
+
this.logger?.warn("Provider does not support getAvailableCommands", { params });
|
|
7733
9011
|
return [];
|
|
7734
9012
|
} catch (error) {
|
|
7735
9013
|
this.logger?.error("Failed to get available commands", error);
|
|
7736
9014
|
return [];
|
|
7737
9015
|
}
|
|
7738
9016
|
},
|
|
9017
|
+
reportTelemetry: async (eventName, payload) => {
|
|
9018
|
+
try {
|
|
9019
|
+
if (this.provider?.reportTelemetry) await this.provider.reportTelemetry(eventName, payload);
|
|
9020
|
+
else this.logger?.warn("Provider does not support reportTelemetry");
|
|
9021
|
+
} catch (error) {
|
|
9022
|
+
this.logger?.error("Failed to report telemetry", error);
|
|
9023
|
+
}
|
|
9024
|
+
},
|
|
9025
|
+
getProductConfiguration: async () => {
|
|
9026
|
+
try {
|
|
9027
|
+
if (this.provider?.getProductConfiguration) return await this.provider.getProductConfiguration();
|
|
9028
|
+
this.logger?.warn("Provider does not support getProductConfiguration");
|
|
9029
|
+
return {};
|
|
9030
|
+
} catch (error) {
|
|
9031
|
+
this.logger?.error("Failed to get product configuration", error);
|
|
9032
|
+
return {};
|
|
9033
|
+
}
|
|
9034
|
+
},
|
|
9035
|
+
getUserInfo: async () => {
|
|
9036
|
+
this.logger?.info("[AgentClient.sessions] getUserInfo() called");
|
|
9037
|
+
try {
|
|
9038
|
+
if (this.provider?.getUserInfo) {
|
|
9039
|
+
const result = await this.provider.getUserInfo();
|
|
9040
|
+
this.logger?.info("[AgentClient.sessions] getUserInfo() result:", JSON.stringify(result));
|
|
9041
|
+
return result;
|
|
9042
|
+
}
|
|
9043
|
+
this.logger?.warn("Provider does not support getUserInfo");
|
|
9044
|
+
return {};
|
|
9045
|
+
} catch (error) {
|
|
9046
|
+
this.logger?.error("Failed to get user info", error);
|
|
9047
|
+
return {};
|
|
9048
|
+
}
|
|
9049
|
+
},
|
|
9050
|
+
respondToSampling: async (sessionId, response) => {
|
|
9051
|
+
try {
|
|
9052
|
+
if (this.provider?.respondToSampling) {
|
|
9053
|
+
await this.provider.respondToSampling(sessionId, response);
|
|
9054
|
+
this.logger?.info("Responded to sampling request", {
|
|
9055
|
+
sessionId,
|
|
9056
|
+
requestId: response.id,
|
|
9057
|
+
approved: response.approved
|
|
9058
|
+
});
|
|
9059
|
+
} else this.logger?.warn("Provider does not support respondToSampling");
|
|
9060
|
+
} catch (error) {
|
|
9061
|
+
this.logger?.error("Failed to respond to sampling request", error);
|
|
9062
|
+
throw error;
|
|
9063
|
+
}
|
|
9064
|
+
},
|
|
9065
|
+
respondToRoots: async (sessionId, response) => {
|
|
9066
|
+
try {
|
|
9067
|
+
if (this.provider?.respondToRoots) {
|
|
9068
|
+
await this.provider.respondToRoots(sessionId, response);
|
|
9069
|
+
this.logger?.info("Responded to roots request", {
|
|
9070
|
+
sessionId,
|
|
9071
|
+
requestId: response.id,
|
|
9072
|
+
approved: response.approved
|
|
9073
|
+
});
|
|
9074
|
+
} else this.logger?.warn("Provider does not support respondToRoots");
|
|
9075
|
+
} catch (error) {
|
|
9076
|
+
this.logger?.error("Failed to respond to roots request", error);
|
|
9077
|
+
throw error;
|
|
9078
|
+
}
|
|
9079
|
+
},
|
|
9080
|
+
subscribeSamplingRequests: (serverName, callback) => {
|
|
9081
|
+
if (this.provider?.subscribeSamplingRequests) {
|
|
9082
|
+
this.logger?.info("Subscribing to sampling requests", { serverName });
|
|
9083
|
+
return this.provider.subscribeSamplingRequests(serverName, callback);
|
|
9084
|
+
}
|
|
9085
|
+
this.logger?.warn("Provider does not support subscribeSamplingRequests");
|
|
9086
|
+
return () => {};
|
|
9087
|
+
},
|
|
9088
|
+
subscribeRootsRequests: (serverName, callback) => {
|
|
9089
|
+
if (this.provider?.subscribeRootsRequests) {
|
|
9090
|
+
this.logger?.info("Subscribing to roots requests", { serverName });
|
|
9091
|
+
return this.provider.subscribeRootsRequests(serverName, callback);
|
|
9092
|
+
}
|
|
9093
|
+
this.logger?.warn("Provider does not support subscribeRootsRequests");
|
|
9094
|
+
return () => {};
|
|
9095
|
+
},
|
|
9096
|
+
getMcpServers: async () => {
|
|
9097
|
+
if (this.provider?.getMcpServers) {
|
|
9098
|
+
this.logger?.info("Getting MCP servers list");
|
|
9099
|
+
return this.provider.getMcpServers();
|
|
9100
|
+
}
|
|
9101
|
+
this.logger?.warn("Provider does not support getMcpServers");
|
|
9102
|
+
return [];
|
|
9103
|
+
},
|
|
9104
|
+
toggleMcpServer: async (serverName, enabled) => {
|
|
9105
|
+
if (this.provider?.toggleMcpServer) {
|
|
9106
|
+
this.logger?.info("Toggling MCP server", {
|
|
9107
|
+
serverName,
|
|
9108
|
+
enabled
|
|
9109
|
+
});
|
|
9110
|
+
await this.provider.toggleMcpServer(serverName, enabled);
|
|
9111
|
+
} else {
|
|
9112
|
+
this.logger?.warn("Provider does not support toggleMcpServer");
|
|
9113
|
+
throw new Error("toggleMcpServer not supported by provider");
|
|
9114
|
+
}
|
|
9115
|
+
},
|
|
9116
|
+
reconnectMcpServer: async (serverName, forceHttpCallback) => {
|
|
9117
|
+
if (this.provider?.reconnectMcpServer) {
|
|
9118
|
+
this.logger?.info("Reconnecting MCP server", {
|
|
9119
|
+
serverName,
|
|
9120
|
+
forceHttpCallback
|
|
9121
|
+
});
|
|
9122
|
+
await this.provider.reconnectMcpServer(serverName, forceHttpCallback);
|
|
9123
|
+
} else {
|
|
9124
|
+
this.logger?.warn("Provider does not support reconnectMcpServer");
|
|
9125
|
+
throw new Error("reconnectMcpServer not supported by provider");
|
|
9126
|
+
}
|
|
9127
|
+
},
|
|
9128
|
+
deleteMcpServer: async (serverName) => {
|
|
9129
|
+
if (this.provider?.deleteMcpServer) {
|
|
9130
|
+
this.logger?.info("Deleting MCP server", { serverName });
|
|
9131
|
+
await this.provider.deleteMcpServer(serverName);
|
|
9132
|
+
} else {
|
|
9133
|
+
this.logger?.warn("Provider does not support deleteMcpServer");
|
|
9134
|
+
throw new Error("deleteMcpServer not supported by provider");
|
|
9135
|
+
}
|
|
9136
|
+
},
|
|
9137
|
+
openMcpConfig: async () => {
|
|
9138
|
+
if (this.provider?.openMcpConfig) {
|
|
9139
|
+
this.logger?.info("Opening MCP config");
|
|
9140
|
+
await this.provider.openMcpConfig();
|
|
9141
|
+
} else {
|
|
9142
|
+
this.logger?.warn("Provider does not support openMcpConfig");
|
|
9143
|
+
throw new Error("openMcpConfig not supported by provider");
|
|
9144
|
+
}
|
|
9145
|
+
},
|
|
9146
|
+
getMcpConfigContent: async () => {
|
|
9147
|
+
if (this.provider?.getMcpConfigContent) {
|
|
9148
|
+
this.logger?.info("Getting MCP config content");
|
|
9149
|
+
return await this.provider.getMcpConfigContent();
|
|
9150
|
+
} else {
|
|
9151
|
+
this.logger?.warn("Provider does not support getMcpConfigContent");
|
|
9152
|
+
throw new Error("getMcpConfigContent not supported by provider");
|
|
9153
|
+
}
|
|
9154
|
+
},
|
|
9155
|
+
saveMcpConfigContent: async (content) => {
|
|
9156
|
+
if (this.provider?.saveMcpConfigContent) {
|
|
9157
|
+
this.logger?.info("Saving MCP config content");
|
|
9158
|
+
await this.provider.saveMcpConfigContent(content);
|
|
9159
|
+
} else {
|
|
9160
|
+
this.logger?.warn("Provider does not support saveMcpConfigContent");
|
|
9161
|
+
throw new Error("saveMcpConfigContent not supported by provider");
|
|
9162
|
+
}
|
|
9163
|
+
},
|
|
9164
|
+
clipboardReadText: async () => {
|
|
9165
|
+
if (this.provider?.clipboardReadText) {
|
|
9166
|
+
this.logger?.info("Reading clipboard text");
|
|
9167
|
+
return await this.provider.clipboardReadText();
|
|
9168
|
+
} else {
|
|
9169
|
+
this.logger?.warn("Provider does not support clipboardReadText");
|
|
9170
|
+
throw new Error("clipboardReadText not supported by provider");
|
|
9171
|
+
}
|
|
9172
|
+
},
|
|
7739
9173
|
models: this.createModelsResource()
|
|
7740
9174
|
};
|
|
7741
9175
|
}
|
|
@@ -7961,10 +9395,6 @@ const oauthRepositoryService = new OAuthRepositoryService();
|
|
|
7961
9395
|
* 判断当前账号是否是 SSO 账号
|
|
7962
9396
|
* 通过 account.accountType === 'sso' 来判断,这种不行,因为未登录之前account 为空
|
|
7963
9397
|
*/
|
|
7964
|
-
const isSSODomain = () => {
|
|
7965
|
-
const { hostname } = window.location;
|
|
7966
|
-
return hostname.includes(".sso.copilot") || hostname.includes("sso.codebuddy.cn") || hostname.includes(".sso.copilot-staging") || hostname.includes(".staging-sso.codebuddy.cn");
|
|
7967
|
-
};
|
|
7968
9398
|
/**
|
|
7969
9399
|
* 根据路径获取完整 URL
|
|
7970
9400
|
* - SSO 账号需要跳转到对应的预发/生产域名
|
|
@@ -7972,16 +9402,7 @@ const isSSODomain = () => {
|
|
|
7972
9402
|
* @param path 路径,如 '/login'、'/logout'、'/home' 等
|
|
7973
9403
|
* @returns 完整的 URL 地址
|
|
7974
9404
|
*/
|
|
7975
|
-
const getFullUrl = (path) => {
|
|
7976
|
-
const { hostname, protocol } = window.location;
|
|
7977
|
-
if (isSSODomain()) {
|
|
7978
|
-
const isCodebuddy = hostname.includes("codebuddy.cn");
|
|
7979
|
-
const isStaging = hostname.includes("staging");
|
|
7980
|
-
if (isCodebuddy) return isStaging ? `${protocol}//staging.codebuddy.cn${path}` : `${protocol}//www.codebuddy.cn${path}`;
|
|
7981
|
-
else return isStaging ? `${protocol}//staging-copilot.tencent.com${path}` : `${protocol}//copilot.tencent.com${path}`;
|
|
7982
|
-
}
|
|
7983
|
-
return `${window.location.origin}${path}`;
|
|
7984
|
-
};
|
|
9405
|
+
const getFullUrl = (path) => `${window.location.origin}${path}`;
|
|
7985
9406
|
/** 获取当前域名的账号选择页面 URL */
|
|
7986
9407
|
const getSelectAccountUrl = () => `${window.location.origin}/login/select`;
|
|
7987
9408
|
/** localStorage 中存储选中账号 ID 的 key */
|
|
@@ -8014,16 +9435,34 @@ const getPackageName = (packageCode) => CommodityCodeText[packageCode] || "";
|
|
|
8014
9435
|
* 注意:getAgents 和 getModels 方法已废弃并移除,
|
|
8015
9436
|
* 请使用 IAgentAdapter 中的对应方法
|
|
8016
9437
|
*/
|
|
8017
|
-
var BackendProvider = class {
|
|
9438
|
+
var BackendProvider = class BackendProvider {
|
|
8018
9439
|
constructor(config) {
|
|
8019
9440
|
httpService.setBaseURL(config.baseUrl);
|
|
8020
9441
|
if (config.authToken) httpService.setAuthToken(config.authToken);
|
|
8021
|
-
httpService.onUnauthorized(() =>
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
9442
|
+
httpService.onUnauthorized(() => this.handleUnauthorized());
|
|
9443
|
+
}
|
|
9444
|
+
/**
|
|
9445
|
+
* 处理 401 未授权错误
|
|
9446
|
+
* 先尝试刷新 token,失败后再执行登出流程
|
|
9447
|
+
*
|
|
9448
|
+
* @throws 如果 token 刷新失败,抛出错误通知 HttpService 不要重试
|
|
9449
|
+
*/
|
|
9450
|
+
async handleUnauthorized() {
|
|
9451
|
+
console.log("[BackendProvider] User unauthorized (401), attempting token refresh first");
|
|
9452
|
+
try {
|
|
9453
|
+
if (await this.refreshToken()) {
|
|
9454
|
+
console.log("[BackendProvider] Token refresh successful after 401, user still logged in");
|
|
9455
|
+
return;
|
|
9456
|
+
}
|
|
9457
|
+
throw new Error("Token refresh returned null");
|
|
9458
|
+
} catch (error) {
|
|
9459
|
+
console.error("[BackendProvider] Token refresh failed after 401:", error);
|
|
9460
|
+
console.log("[BackendProvider] Token refresh failed, triggering logout");
|
|
9461
|
+
this.logout().catch((logoutError) => {
|
|
9462
|
+
console.error("[BackendProvider] Logout failed in 401 handler:", logoutError);
|
|
8025
9463
|
});
|
|
8026
|
-
|
|
9464
|
+
throw error;
|
|
9465
|
+
}
|
|
8027
9466
|
}
|
|
8028
9467
|
/**
|
|
8029
9468
|
* 获取当前账号信息
|
|
@@ -8287,10 +9726,11 @@ var BackendProvider = class {
|
|
|
8287
9726
|
if (!time) return 0;
|
|
8288
9727
|
return new Date(time).getTime();
|
|
8289
9728
|
};
|
|
8290
|
-
const dailyCredits = [CommodityCode.free
|
|
9729
|
+
const dailyCredits = [CommodityCode.free];
|
|
8291
9730
|
const planResources = resources.map((r) => {
|
|
8292
9731
|
const isDaily = dailyCredits.includes(r.PackageCode);
|
|
8293
9732
|
const endTime = isDaily ? r.CycleEndTime : r.DeductionEndTime;
|
|
9733
|
+
const refreshAt = parseTime(r.CycleEndTime) + 1e3;
|
|
8294
9734
|
return {
|
|
8295
9735
|
id: r.ResourceId,
|
|
8296
9736
|
name: isDaily ? "plan.addonCredits" : getPackageName(r.PackageCode),
|
|
@@ -8300,7 +9740,7 @@ var BackendProvider = class {
|
|
|
8300
9740
|
used: Math.max(0, Number(r.CycleCapacitySizePrecise) - Number(r.CycleCapacityRemainPrecise)) || 0,
|
|
8301
9741
|
left: Number(r.CycleCapacityRemainPrecise) || 0,
|
|
8302
9742
|
expireAt: parseTime(endTime),
|
|
8303
|
-
refreshAt: isDaily ? void 0 :
|
|
9743
|
+
refreshAt: isDaily ? void 0 : refreshAt
|
|
8304
9744
|
};
|
|
8305
9745
|
}).sort((a, b) => {
|
|
8306
9746
|
const getPriority = (code) => {
|
|
@@ -8308,10 +9748,11 @@ var BackendProvider = class {
|
|
|
8308
9748
|
CommodityCode.proMon,
|
|
8309
9749
|
CommodityCode.proMonPlus,
|
|
8310
9750
|
CommodityCode.proYear,
|
|
9751
|
+
CommodityCode.freeMon,
|
|
8311
9752
|
CommodityCode.extra
|
|
8312
9753
|
].includes(code)) return 1;
|
|
8313
9754
|
if ([CommodityCode.gift, CommodityCode.activity].includes(code)) return 2;
|
|
8314
|
-
if ([CommodityCode.free
|
|
9755
|
+
if ([CommodityCode.free].includes(code)) return 3;
|
|
8315
9756
|
return 4;
|
|
8316
9757
|
};
|
|
8317
9758
|
return getPriority(a.packageCode) - getPriority(b.packageCode);
|
|
@@ -8436,34 +9877,65 @@ var BackendProvider = class {
|
|
|
8436
9877
|
}
|
|
8437
9878
|
/**
|
|
8438
9879
|
* 登出账号
|
|
8439
|
-
*
|
|
9880
|
+
*
|
|
9881
|
+
* 策略:
|
|
9882
|
+
* - IOA 企业:用 iframe 走 SSO/SAML SLO 登出链路(涉及跨域重定向),通过轮询 iframe URL 变化检测完成
|
|
9883
|
+
* - 非 IOA 企业:直接用 httpService 请求 /console/logout,速度快
|
|
8440
9884
|
*/
|
|
8441
9885
|
async logout() {
|
|
8442
|
-
const
|
|
9886
|
+
const account = accountService.getAccount();
|
|
9887
|
+
if (account?.enterpriseId && ["esoikz80kd8g", "etahzsqej0n4"].includes(account.enterpriseId)) await this.logoutViaIframe();
|
|
9888
|
+
else await this.logoutViaHttp();
|
|
9889
|
+
localStorage.removeItem(SELECTED_ACCOUNT_KEY);
|
|
9890
|
+
accountService.clearAccount();
|
|
9891
|
+
}
|
|
9892
|
+
/**
|
|
9893
|
+
* IOA 企业登出:通过 iframe 走 SSO/SAML SLO 登出链路
|
|
9894
|
+
* 轮询 iframe URL 变化检测完成,兜底超时 5 秒
|
|
9895
|
+
*/
|
|
9896
|
+
async logoutViaIframe() {
|
|
9897
|
+
const logoutUrl = `${httpService.getAxiosInstance().defaults.baseURL}/console/logout`;
|
|
8443
9898
|
try {
|
|
8444
9899
|
await new Promise((resolve) => {
|
|
8445
9900
|
const iframe = document.createElement("iframe");
|
|
8446
9901
|
iframe.style.cssText = "position:fixed;top:-9999px;left:-9999px;width:1px;height:1px;border:none;";
|
|
8447
|
-
iframe.src =
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
9902
|
+
iframe.src = logoutUrl;
|
|
9903
|
+
let pollTimer;
|
|
9904
|
+
let settled = false;
|
|
9905
|
+
const done = () => {
|
|
9906
|
+
if (settled) return;
|
|
9907
|
+
settled = true;
|
|
9908
|
+
clearInterval(pollTimer);
|
|
8453
9909
|
clearTimeout(timeout);
|
|
8454
9910
|
if (iframe.parentNode) iframe.parentNode.removeChild(iframe);
|
|
8455
|
-
};
|
|
8456
|
-
iframe.onerror = () => {
|
|
8457
|
-
cleanup();
|
|
8458
9911
|
resolve();
|
|
8459
9912
|
};
|
|
9913
|
+
let wasRedirecting = false;
|
|
9914
|
+
pollTimer = setInterval(() => {
|
|
9915
|
+
try {
|
|
9916
|
+
const href = iframe.contentWindow?.location?.href;
|
|
9917
|
+
if (wasRedirecting && href) done();
|
|
9918
|
+
} catch {
|
|
9919
|
+
wasRedirecting = true;
|
|
9920
|
+
}
|
|
9921
|
+
}, 100);
|
|
9922
|
+
const timeout = setTimeout(done, 5e3);
|
|
9923
|
+
iframe.onerror = done;
|
|
8460
9924
|
document.body.appendChild(iframe);
|
|
8461
9925
|
});
|
|
8462
9926
|
} catch (error) {
|
|
8463
|
-
console.error("[BackendProvider] logout failed:", error);
|
|
9927
|
+
console.error("[BackendProvider] logout via iframe failed:", error);
|
|
9928
|
+
}
|
|
9929
|
+
}
|
|
9930
|
+
/**
|
|
9931
|
+
* 非 IOA 企业登出:直接 HTTP 请求 /console/logout
|
|
9932
|
+
*/
|
|
9933
|
+
async logoutViaHttp() {
|
|
9934
|
+
try {
|
|
9935
|
+
await httpService.get("/console/logout");
|
|
9936
|
+
} catch (error) {
|
|
9937
|
+
console.error("[BackendProvider] logout via http failed:", error);
|
|
8464
9938
|
}
|
|
8465
|
-
localStorage.removeItem(SELECTED_ACCOUNT_KEY);
|
|
8466
|
-
accountService.clearAccount();
|
|
8467
9939
|
}
|
|
8468
9940
|
/**
|
|
8469
9941
|
* 批量切换插件状态
|
|
@@ -8541,6 +10013,132 @@ var BackendProvider = class {
|
|
|
8541
10013
|
async getRepositories(connector, page = 0, perPage = 100) {
|
|
8542
10014
|
return oauthRepositoryService.getRepositories(connector, page, perPage);
|
|
8543
10015
|
}
|
|
10016
|
+
/**
|
|
10017
|
+
* 保存待发送的输入内容到后端
|
|
10018
|
+
* API 端点: POST /api/v1/code-id
|
|
10019
|
+
*/
|
|
10020
|
+
async savePendingInput(code) {
|
|
10021
|
+
try {
|
|
10022
|
+
const result = await httpService.post("/api/v1/code-id", { code });
|
|
10023
|
+
return result?.codeId || result?.data?.codeId || null;
|
|
10024
|
+
} catch (e) {
|
|
10025
|
+
console.warn("[BackendProvider] savePendingInput failed:", e);
|
|
10026
|
+
return null;
|
|
10027
|
+
}
|
|
10028
|
+
}
|
|
10029
|
+
/**
|
|
10030
|
+
* 从后端加载待发送的输入内容
|
|
10031
|
+
* API 端点: GET /api/v1/code?id=xxx
|
|
10032
|
+
*/
|
|
10033
|
+
async loadPendingInput(codeId) {
|
|
10034
|
+
try {
|
|
10035
|
+
const result = await httpService.get(`/api/v1/code?id=${encodeURIComponent(codeId)}`);
|
|
10036
|
+
return result?.code || result?.data?.code || null;
|
|
10037
|
+
} catch (e) {
|
|
10038
|
+
console.warn("[BackendProvider] loadPendingInput failed:", e);
|
|
10039
|
+
return null;
|
|
10040
|
+
}
|
|
10041
|
+
}
|
|
10042
|
+
/**
|
|
10043
|
+
* 获取每日签到状态
|
|
10044
|
+
* API 端点: POST /billing/meter/checkin-status
|
|
10045
|
+
*/
|
|
10046
|
+
async getCheckinStatus() {
|
|
10047
|
+
try {
|
|
10048
|
+
const result = await httpService.post("/billing/meter/checkin-status", {});
|
|
10049
|
+
if (result?.code === 0 && result?.data) return result.data;
|
|
10050
|
+
return null;
|
|
10051
|
+
} catch (error) {
|
|
10052
|
+
console.error("[BackendProvider] getCheckinStatus failed:", error);
|
|
10053
|
+
return null;
|
|
10054
|
+
}
|
|
10055
|
+
}
|
|
10056
|
+
/**
|
|
10057
|
+
* 执行每日签到
|
|
10058
|
+
* API 端点: POST /billing/meter/daily-checkin
|
|
10059
|
+
*/
|
|
10060
|
+
async claimDailyCheckin() {
|
|
10061
|
+
const result = await httpService.post("/billing/meter/daily-checkin", {});
|
|
10062
|
+
if (result?.code === 0 && result?.data) return result.data;
|
|
10063
|
+
throw new Error(result?.msg || "Checkin failed");
|
|
10064
|
+
}
|
|
10065
|
+
static {
|
|
10066
|
+
this.SKILLHUB_BASE_URL = "https://lightmake.site";
|
|
10067
|
+
}
|
|
10068
|
+
static {
|
|
10069
|
+
this.SKILLHUB_FETCH_TIMEOUT = 1e4;
|
|
10070
|
+
}
|
|
10071
|
+
async skillHubFetch(url, init) {
|
|
10072
|
+
const controller = new AbortController();
|
|
10073
|
+
const timer = setTimeout(() => controller.abort(), BackendProvider.SKILLHUB_FETCH_TIMEOUT);
|
|
10074
|
+
try {
|
|
10075
|
+
return await fetch(url, {
|
|
10076
|
+
...init,
|
|
10077
|
+
signal: controller.signal
|
|
10078
|
+
});
|
|
10079
|
+
} finally {
|
|
10080
|
+
clearTimeout(timer);
|
|
10081
|
+
}
|
|
10082
|
+
}
|
|
10083
|
+
async getSkillHubList(params = {}) {
|
|
10084
|
+
const qs = new URLSearchParams();
|
|
10085
|
+
if (params.page) qs.set("page", String(params.page));
|
|
10086
|
+
if (params.pageSize) qs.set("pageSize", String(params.pageSize));
|
|
10087
|
+
if (params.sortBy) qs.set("sortBy", params.sortBy);
|
|
10088
|
+
if (params.order) qs.set("order", params.order);
|
|
10089
|
+
if (params.keyword) qs.set("keyword", params.keyword);
|
|
10090
|
+
if (params.category) qs.set("category", params.category);
|
|
10091
|
+
const res = await this.skillHubFetch(`${BackendProvider.SKILLHUB_BASE_URL}/api/skills?${qs.toString()}`);
|
|
10092
|
+
if (!res.ok) throw new Error(`SkillHub list: ${res.status}`);
|
|
10093
|
+
return res.json();
|
|
10094
|
+
}
|
|
10095
|
+
async getSkillHubCategories() {
|
|
10096
|
+
const res = await this.skillHubFetch(`${BackendProvider.SKILLHUB_BASE_URL}/api/v1/categories`);
|
|
10097
|
+
if (!res.ok) throw new Error(`SkillHub categories: ${res.status}`);
|
|
10098
|
+
return res.json();
|
|
10099
|
+
}
|
|
10100
|
+
async getSkillHubSearch(q, limit = 20) {
|
|
10101
|
+
const qs = new URLSearchParams({
|
|
10102
|
+
q,
|
|
10103
|
+
limit: String(limit)
|
|
10104
|
+
});
|
|
10105
|
+
const res = await this.skillHubFetch(`${BackendProvider.SKILLHUB_BASE_URL}/api/v1/search?${qs.toString()}`);
|
|
10106
|
+
if (!res.ok) throw new Error(`SkillHub search: ${res.status}`);
|
|
10107
|
+
return res.json();
|
|
10108
|
+
}
|
|
10109
|
+
async getSkillHubDetail(slug) {
|
|
10110
|
+
const res = await this.skillHubFetch(`${BackendProvider.SKILLHUB_BASE_URL}/api/v1/skills/${encodeURIComponent(slug)}`);
|
|
10111
|
+
if (!res.ok) throw new Error(`SkillHub detail: ${res.status}`);
|
|
10112
|
+
return res.json();
|
|
10113
|
+
}
|
|
10114
|
+
async getSkillHubExists(slugs) {
|
|
10115
|
+
const res = await this.skillHubFetch(`${BackendProvider.SKILLHUB_BASE_URL}/api/v1/skills/exists`, {
|
|
10116
|
+
method: "POST",
|
|
10117
|
+
headers: { "Content-Type": "application/json" },
|
|
10118
|
+
body: JSON.stringify({ slugs })
|
|
10119
|
+
});
|
|
10120
|
+
if (!res.ok) throw new Error(`SkillHub exists: ${res.status}`);
|
|
10121
|
+
return res.json();
|
|
10122
|
+
}
|
|
10123
|
+
async reportSkillHubStats(slug, inc) {
|
|
10124
|
+
try {
|
|
10125
|
+
await this.skillHubFetch(`${BackendProvider.SKILLHUB_BASE_URL}/api/v1/skills/${encodeURIComponent(slug)}/stats/inc`, {
|
|
10126
|
+
method: "POST",
|
|
10127
|
+
headers: { "Content-Type": "application/json" },
|
|
10128
|
+
body: JSON.stringify(inc)
|
|
10129
|
+
});
|
|
10130
|
+
} catch {}
|
|
10131
|
+
}
|
|
10132
|
+
async installSkillHubSkill(_slug, _version, _name) {
|
|
10133
|
+
return {
|
|
10134
|
+
success: false,
|
|
10135
|
+
skillName: _slug,
|
|
10136
|
+
errorMessage: "SkillHub install requires IDE mode (no IPC channel available)"
|
|
10137
|
+
};
|
|
10138
|
+
}
|
|
10139
|
+
async getSkillHubInstalledMetas() {
|
|
10140
|
+
return [];
|
|
10141
|
+
}
|
|
8544
10142
|
};
|
|
8545
10143
|
/**
|
|
8546
10144
|
* 创建 BackendProvider 实例
|
|
@@ -8579,10 +10177,21 @@ const BACKEND_REQUEST_TYPES = {
|
|
|
8579
10177
|
REVOKE_ALL: "backend:revoke-all",
|
|
8580
10178
|
GET_FILE: "backend:get-file",
|
|
8581
10179
|
RELOAD_WINDOW: "backend:reload-window",
|
|
10180
|
+
SAVE_LOCALE: "backend:save-locale",
|
|
8582
10181
|
CLOSE_AGENT_MANAGER: "backend:close-agent-manager",
|
|
8583
10182
|
OPEN_EXTERNAL: "backend:open-external",
|
|
8584
10183
|
BATCH_TOGGLE_PLUGINS: "backend:batch-toggle-plugins",
|
|
8585
|
-
GET_SUPPORT_SCENES: "backend:get-support-scenes"
|
|
10184
|
+
GET_SUPPORT_SCENES: "backend:get-support-scenes",
|
|
10185
|
+
GET_ACCOUNT_USAGE: "backend:get-account-usage",
|
|
10186
|
+
GET_CHECKIN_STATUS: "backend:get-checkin-status",
|
|
10187
|
+
CLAIM_DAILY_CHECKIN: "backend:claim-daily-checkin",
|
|
10188
|
+
SKILLHUB_LIST: "backend:skillhub-list",
|
|
10189
|
+
SKILLHUB_CATEGORIES: "backend:skillhub-categories",
|
|
10190
|
+
SKILLHUB_SEARCH: "backend:skillhub-search",
|
|
10191
|
+
SKILLHUB_DETAIL: "backend:skillhub-detail",
|
|
10192
|
+
SKILLHUB_DOWNLOAD_URL: "backend:skillhub-download-url",
|
|
10193
|
+
SKILLHUB_EXISTS: "backend:skillhub-exists",
|
|
10194
|
+
SKILLHUB_REPORT_STATS: "backend:skillhub-report-stats"
|
|
8586
10195
|
};
|
|
8587
10196
|
/**
|
|
8588
10197
|
* 生成唯一请求 ID
|
|
@@ -8629,12 +10238,14 @@ var IPCBackendProvider = class {
|
|
|
8629
10238
|
*/
|
|
8630
10239
|
async getAccount() {
|
|
8631
10240
|
this.log("Getting account via IPC");
|
|
10241
|
+
const startTime = performance.now();
|
|
8632
10242
|
try {
|
|
8633
10243
|
const account = await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_ACCOUNT);
|
|
10244
|
+
this.log(`getAccount IPC completed in ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
8634
10245
|
accountService.setAccount(account);
|
|
8635
10246
|
return account;
|
|
8636
10247
|
} catch (error) {
|
|
8637
|
-
this.log(
|
|
10248
|
+
this.log(`getAccount IPC failed after ${(performance.now() - startTime).toFixed(0)}ms:`, error);
|
|
8638
10249
|
accountService.setAccount(null);
|
|
8639
10250
|
return null;
|
|
8640
10251
|
}
|
|
@@ -8863,6 +10474,20 @@ var IPCBackendProvider = class {
|
|
|
8863
10474
|
}
|
|
8864
10475
|
}
|
|
8865
10476
|
/**
|
|
10477
|
+
* Save locale to argv.json without restarting the app.
|
|
10478
|
+
* The change takes effect on next manual restart.
|
|
10479
|
+
* @param params locale to save
|
|
10480
|
+
*/
|
|
10481
|
+
async saveLocale(params) {
|
|
10482
|
+
this.log("Saving locale to argv.json via IPC", params);
|
|
10483
|
+
try {
|
|
10484
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SAVE_LOCALE, params);
|
|
10485
|
+
} catch (error) {
|
|
10486
|
+
this.log("Save locale request failed:", error);
|
|
10487
|
+
throw error;
|
|
10488
|
+
}
|
|
10489
|
+
}
|
|
10490
|
+
/**
|
|
8866
10491
|
* 关闭 Agent Manager 面板
|
|
8867
10492
|
* IDE 环境: 通过 IPC 通知 IDE 关闭 Agent Manager(用于返回 IDE)
|
|
8868
10493
|
*/
|
|
@@ -8923,6 +10548,174 @@ var IPCBackendProvider = class {
|
|
|
8923
10548
|
}
|
|
8924
10549
|
}
|
|
8925
10550
|
/**
|
|
10551
|
+
* 获取账号用量信息(积分/Credits)
|
|
10552
|
+
* IDE 环境: 通过 IPC 实时获取用量信息,每次打开菜单时调用
|
|
10553
|
+
*
|
|
10554
|
+
* 调用链:
|
|
10555
|
+
* 1. agent-ui: IPCBackendProvider.getAccountUsage()
|
|
10556
|
+
* 2. Agent Manager renderer: BackendService.getAccountUsage()
|
|
10557
|
+
* 3. Main Process: codebuddy:getAccountUsage IPC handler
|
|
10558
|
+
* 4. 返回 { usageLeft, usageTotal, editionType, refreshAt } 等字段
|
|
10559
|
+
*/
|
|
10560
|
+
async getAccountUsage() {
|
|
10561
|
+
this.log("Getting account usage via IPC");
|
|
10562
|
+
try {
|
|
10563
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_ACCOUNT_USAGE);
|
|
10564
|
+
} catch (error) {
|
|
10565
|
+
this.log("Get account usage failed:", error);
|
|
10566
|
+
return null;
|
|
10567
|
+
}
|
|
10568
|
+
}
|
|
10569
|
+
/**
|
|
10570
|
+
* 获取每日签到状态
|
|
10571
|
+
* IDE 环境: 通过 IPC 获取签到状态
|
|
10572
|
+
*/
|
|
10573
|
+
async getCheckinStatus() {
|
|
10574
|
+
this.log("Getting checkin status via IPC");
|
|
10575
|
+
try {
|
|
10576
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_CHECKIN_STATUS);
|
|
10577
|
+
} catch (error) {
|
|
10578
|
+
this.log("Get checkin status failed:", error);
|
|
10579
|
+
return null;
|
|
10580
|
+
}
|
|
10581
|
+
}
|
|
10582
|
+
/**
|
|
10583
|
+
* 执行每日签到
|
|
10584
|
+
* IDE 环境: 通过 IPC 执行签到
|
|
10585
|
+
*/
|
|
10586
|
+
async claimDailyCheckin() {
|
|
10587
|
+
this.log("Claiming daily checkin via IPC");
|
|
10588
|
+
try {
|
|
10589
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.CLAIM_DAILY_CHECKIN);
|
|
10590
|
+
} catch (error) {
|
|
10591
|
+
this.log("Claim daily checkin failed:", error);
|
|
10592
|
+
throw error;
|
|
10593
|
+
}
|
|
10594
|
+
}
|
|
10595
|
+
/**
|
|
10596
|
+
* 获取 SkillHub 技能列表
|
|
10597
|
+
* IDE 环境: 通过 IPC 获取技能列表
|
|
10598
|
+
*/
|
|
10599
|
+
async getSkillHubList(params) {
|
|
10600
|
+
this.log("Getting SkillHub list via IPC", params);
|
|
10601
|
+
try {
|
|
10602
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SKILLHUB_LIST, params);
|
|
10603
|
+
} catch (error) {
|
|
10604
|
+
this.log("Get SkillHub list failed:", error);
|
|
10605
|
+
throw error;
|
|
10606
|
+
}
|
|
10607
|
+
}
|
|
10608
|
+
/**
|
|
10609
|
+
* 获取 SkillHub 分类列表
|
|
10610
|
+
* IDE 环境: 通过 IPC 获取分类列表
|
|
10611
|
+
*/
|
|
10612
|
+
async getSkillHubCategories() {
|
|
10613
|
+
this.log("Getting SkillHub categories via IPC");
|
|
10614
|
+
try {
|
|
10615
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SKILLHUB_CATEGORIES);
|
|
10616
|
+
} catch (error) {
|
|
10617
|
+
this.log("Get SkillHub categories failed:", error);
|
|
10618
|
+
throw error;
|
|
10619
|
+
}
|
|
10620
|
+
}
|
|
10621
|
+
/**
|
|
10622
|
+
* 搜索 SkillHub 技能
|
|
10623
|
+
* IDE 环境: 通过 IPC 搜索技能
|
|
10624
|
+
*/
|
|
10625
|
+
async getSkillHubSearch(q, limit = 20) {
|
|
10626
|
+
this.log("Searching SkillHub via IPC", {
|
|
10627
|
+
q,
|
|
10628
|
+
limit
|
|
10629
|
+
});
|
|
10630
|
+
try {
|
|
10631
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SKILLHUB_SEARCH, {
|
|
10632
|
+
q,
|
|
10633
|
+
limit
|
|
10634
|
+
});
|
|
10635
|
+
} catch (error) {
|
|
10636
|
+
this.log("SkillHub search failed:", error);
|
|
10637
|
+
throw error;
|
|
10638
|
+
}
|
|
10639
|
+
}
|
|
10640
|
+
/**
|
|
10641
|
+
* 获取 SkillHub 技能详情
|
|
10642
|
+
* IDE 环境: 通过 IPC 获取技能详情
|
|
10643
|
+
*/
|
|
10644
|
+
async getSkillHubDetail(slug) {
|
|
10645
|
+
this.log("Getting SkillHub detail via IPC", { slug });
|
|
10646
|
+
try {
|
|
10647
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SKILLHUB_DETAIL, { slug });
|
|
10648
|
+
} catch (error) {
|
|
10649
|
+
this.log("Get SkillHub detail failed:", error);
|
|
10650
|
+
throw error;
|
|
10651
|
+
}
|
|
10652
|
+
}
|
|
10653
|
+
/**
|
|
10654
|
+
* 批量检查 SkillHub 技能是否存在
|
|
10655
|
+
* IDE 环境: 通过 IPC 检查技能是否存在
|
|
10656
|
+
*/
|
|
10657
|
+
async getSkillHubExists(slugs) {
|
|
10658
|
+
this.log("Checking SkillHub exists via IPC", { slugs });
|
|
10659
|
+
try {
|
|
10660
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SKILLHUB_EXISTS, { slugs });
|
|
10661
|
+
} catch (error) {
|
|
10662
|
+
this.log("SkillHub exists check failed:", error);
|
|
10663
|
+
throw error;
|
|
10664
|
+
}
|
|
10665
|
+
}
|
|
10666
|
+
/**
|
|
10667
|
+
* 上报 SkillHub 技能统计
|
|
10668
|
+
* IDE 环境: 通过 IPC 上报统计
|
|
10669
|
+
*/
|
|
10670
|
+
async reportSkillHubStats(slug, inc) {
|
|
10671
|
+
this.log("Reporting SkillHub stats via IPC", {
|
|
10672
|
+
slug,
|
|
10673
|
+
inc
|
|
10674
|
+
});
|
|
10675
|
+
try {
|
|
10676
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SKILLHUB_REPORT_STATS, {
|
|
10677
|
+
slug,
|
|
10678
|
+
inc
|
|
10679
|
+
});
|
|
10680
|
+
} catch (error) {
|
|
10681
|
+
this.log("Report SkillHub stats failed:", error);
|
|
10682
|
+
}
|
|
10683
|
+
}
|
|
10684
|
+
/**
|
|
10685
|
+
* 安装 SkillHub 技能
|
|
10686
|
+
* IDE 环境: 通过 IPC 安装技能(下载 zip → 解压到本地)
|
|
10687
|
+
*/
|
|
10688
|
+
async installSkillHubSkill(slug, version, name) {
|
|
10689
|
+
this.log("Installing SkillHub skill via IPC", {
|
|
10690
|
+
slug,
|
|
10691
|
+
version,
|
|
10692
|
+
name
|
|
10693
|
+
});
|
|
10694
|
+
try {
|
|
10695
|
+
return await this.sendBackendRequest("backend:skillhub-install", {
|
|
10696
|
+
slug,
|
|
10697
|
+
version,
|
|
10698
|
+
name
|
|
10699
|
+
});
|
|
10700
|
+
} catch (error) {
|
|
10701
|
+
this.log("Install SkillHub skill failed:", error);
|
|
10702
|
+
throw error;
|
|
10703
|
+
}
|
|
10704
|
+
}
|
|
10705
|
+
/**
|
|
10706
|
+
* 获取本地已安装的 SkillHub 技能元信息
|
|
10707
|
+
* IDE 环境: 通过 IPC 获取元信息
|
|
10708
|
+
*/
|
|
10709
|
+
async getSkillHubInstalledMetas() {
|
|
10710
|
+
this.log("Getting SkillHub installed metas via IPC");
|
|
10711
|
+
try {
|
|
10712
|
+
return await this.sendBackendRequest("backend:skillhub-installed-metas");
|
|
10713
|
+
} catch (error) {
|
|
10714
|
+
this.log("Get SkillHub installed metas failed:", error);
|
|
10715
|
+
return [];
|
|
10716
|
+
}
|
|
10717
|
+
}
|
|
10718
|
+
/**
|
|
8926
10719
|
* 调试日志
|
|
8927
10720
|
*/
|
|
8928
10721
|
log(...args) {
|