@tencent-ai/cloud-agent-sdk 0.2.6 → 0.2.7-next.4a35c5d.20260128
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/index.cjs +1507 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2099 -1565
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2099 -1565
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1507 -194
- package/dist/index.mjs.map +1 -1
- package/dist/tencent-ai-cloud-agent-sdk-0.2.7-next.4a35c5d.20260128.tgz +0 -0
- package/package.json +4 -3
- package/dist/MockAgentProvider-4e4oOusg.cjs +0 -3
- package/dist/MockAgentProvider-D-basTXz.cjs +0 -3219
- package/dist/MockAgentProvider-D-basTXz.cjs.map +0 -1
- package/dist/MockAgentProvider-TNsV559x.mjs +0 -3202
- package/dist/MockAgentProvider-TNsV559x.mjs.map +0 -1
- package/dist/MockAgentProvider-tNdtAJCv.mjs +0 -3
- package/dist/tencent-ai-cloud-agent-sdk-0.2.6.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,633 @@
|
|
|
1
|
-
require(
|
|
1
|
+
let zod = require("zod");
|
|
2
2
|
let _agentclientprotocol_sdk = require("@agentclientprotocol/sdk");
|
|
3
3
|
require("@connectrpc/connect");
|
|
4
4
|
require("@connectrpc/connect-web");
|
|
5
5
|
require("@bufbuild/protobuf");
|
|
6
6
|
let e2b = require("e2b");
|
|
7
7
|
|
|
8
|
+
//#region ../agent-provider/src/common/_legacy/tool-schemas.ts
|
|
9
|
+
/**
|
|
10
|
+
* ACP Tool Input/Output Schema 定义
|
|
11
|
+
*
|
|
12
|
+
* 用于约束 ACP 协议中 ToolCallUpdate 的 rawInput 和 rawOutput 字段
|
|
13
|
+
* 基于 getCraftToolProvider 使用的工具定义
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* 工具输入 Schema 定义
|
|
17
|
+
* 用于验证和约束 rawInput
|
|
18
|
+
*/
|
|
19
|
+
const ToolInputSchemas = {
|
|
20
|
+
list_dir: zod.z.object({
|
|
21
|
+
target_directory: zod.z.string().describe("要列出内容的目录路径"),
|
|
22
|
+
ignore_globs: zod.z.string().optional().describe("可选的 glob 模式数组,用于忽略特定文件")
|
|
23
|
+
}),
|
|
24
|
+
search_file: zod.z.object({
|
|
25
|
+
target_directory: zod.z.string().describe("搜索的目录绝对路径"),
|
|
26
|
+
pattern: zod.z.string().describe("文件模式(如 \"*.js\"),支持通配符"),
|
|
27
|
+
recursive: zod.z.boolean().describe("是否递归搜索子目录"),
|
|
28
|
+
caseSensitive: zod.z.boolean().describe("是否区分大小写")
|
|
29
|
+
}),
|
|
30
|
+
read_file: zod.z.object({
|
|
31
|
+
filePath: zod.z.string().describe("要读取的文件的绝对路径"),
|
|
32
|
+
offset: zod.z.number().optional().describe("开始读取的行号"),
|
|
33
|
+
limit: zod.z.number().optional().describe("要读取的行数")
|
|
34
|
+
}),
|
|
35
|
+
read_lints: zod.z.object({ paths: zod.z.string().optional().describe("要读取 lint 错误的文件或目录路径") }),
|
|
36
|
+
rag_search: zod.z.object({
|
|
37
|
+
queryString: zod.z.string().describe("用户的实际问题或搜索查询"),
|
|
38
|
+
knowledgeBaseNames: zod.z.string().describe("知识库名称,多个用逗号分隔")
|
|
39
|
+
}),
|
|
40
|
+
read_rules: zod.z.object({ ruleNames: zod.z.string().describe("要读取的规则关键词,用逗号分隔,格式:{ruleName}_{ruleId}") }),
|
|
41
|
+
mcp_get_tool_description: zod.z.object({ toolRequests: zod.z.string().describe("JSON 字符串,二维数组格式:[[\"server1\", \"tool1\"], [\"server2\", \"tool2\"]]") }),
|
|
42
|
+
mcp_call_tool: zod.z.object({
|
|
43
|
+
serverName: zod.z.string().describe("MCP 服务器名称"),
|
|
44
|
+
toolName: zod.z.string().describe("要调用的工具名称"),
|
|
45
|
+
arguments: zod.z.string().describe("目标 MCP 工具的参数,JSON 格式字符串"),
|
|
46
|
+
maxOutputLength: zod.z.number().optional().describe("控制工具输出的最大长度,默认 200000")
|
|
47
|
+
}),
|
|
48
|
+
fetch_mcp_resource: zod.z.object({
|
|
49
|
+
server: zod.z.string().describe("MCP 服务器标识符"),
|
|
50
|
+
uri: zod.z.string().describe("要读取的资源 URI"),
|
|
51
|
+
arguments: zod.z.record(zod.z.unknown()).optional().describe("资源模板的参数"),
|
|
52
|
+
downloadPath: zod.z.string().optional().describe("可选的绝对路径,用于保存资源到磁盘")
|
|
53
|
+
}),
|
|
54
|
+
create_rule: zod.z.object({
|
|
55
|
+
ruleScope: zod.z.string().describe("规则范围,project rule 或 user rule"),
|
|
56
|
+
ruleName: zod.z.string().describe("规则文件名,不带扩展名"),
|
|
57
|
+
ruleType: zod.z.string().describe("规则类型,always、manual 或 requested"),
|
|
58
|
+
ruleContent: zod.z.string().describe("规则内容,使用 Markdown 格式"),
|
|
59
|
+
ruleDescription: zod.z.string().optional().describe("规则描述,使用 Markdown 格式")
|
|
60
|
+
}),
|
|
61
|
+
update_memory: zod.z.object({
|
|
62
|
+
action: zod.z.enum([
|
|
63
|
+
"create",
|
|
64
|
+
"update",
|
|
65
|
+
"delete"
|
|
66
|
+
]).optional().describe("执行的操作"),
|
|
67
|
+
existing_knowledge_id: zod.z.string().optional().describe("更新或删除时必需,现有记忆的 ID"),
|
|
68
|
+
knowledge_to_store: zod.z.string().optional().describe("要存储的特定记忆"),
|
|
69
|
+
title: zod.z.string().optional().describe("记忆的标题")
|
|
70
|
+
}),
|
|
71
|
+
search_content: zod.z.object({
|
|
72
|
+
pattern: zod.z.string().describe("要搜索的关键字或正则表达式模式"),
|
|
73
|
+
directory: zod.z.string().describe("要搜索的目录的绝对路径"),
|
|
74
|
+
fileTypes: zod.z.string().optional().describe("可选的逗号分隔文件扩展名"),
|
|
75
|
+
contextBefore: zod.z.number().optional().describe("每个匹配前显示的行数"),
|
|
76
|
+
contextAfter: zod.z.number().optional().describe("每个匹配后显示的行数"),
|
|
77
|
+
contextAround: zod.z.number().optional().describe("每个匹配前后显示的行数"),
|
|
78
|
+
outputMode: zod.z.string().optional().describe("输出模式:content、files_with_matches 或 count"),
|
|
79
|
+
caseSensitive: zod.z.boolean().optional().describe("是否区分大小写")
|
|
80
|
+
}),
|
|
81
|
+
write_to_file: zod.z.object({
|
|
82
|
+
filePath: zod.z.string().describe("目标文件的绝对路径"),
|
|
83
|
+
content: zod.z.string().describe("要写入的内容")
|
|
84
|
+
}),
|
|
85
|
+
replace_in_file: zod.z.object({
|
|
86
|
+
filePath: zod.z.string().describe("要修改的文件的绝对路径"),
|
|
87
|
+
old_str: zod.z.string().describe("要替换的文本"),
|
|
88
|
+
new_str: zod.z.string().describe("替换后的文本")
|
|
89
|
+
}),
|
|
90
|
+
delete_file: zod.z.object({
|
|
91
|
+
target_file: zod.z.string().describe("要删除的文件的绝对路径"),
|
|
92
|
+
explanation: zod.z.string().optional().describe("为什么使用此工具的一句话解释")
|
|
93
|
+
}),
|
|
94
|
+
execute_command: zod.z.object({
|
|
95
|
+
command: zod.z.string().describe("要执行的 CLI 命令"),
|
|
96
|
+
requires_approval: zod.z.boolean().describe("命令是否需要用户批准")
|
|
97
|
+
}),
|
|
98
|
+
preview_url: zod.z.object({ url: zod.z.string().describe("要打开的完整、有效的 HTTP/HTTPS URL") }),
|
|
99
|
+
ask_followup_question: zod.z.object({ questions: zod.z.array(zod.z.object({
|
|
100
|
+
question: zod.z.string(),
|
|
101
|
+
header: zod.z.string().max(12),
|
|
102
|
+
options: zod.z.array(zod.z.object({
|
|
103
|
+
label: zod.z.string().max(50),
|
|
104
|
+
description: zod.z.string()
|
|
105
|
+
})).min(2).max(4),
|
|
106
|
+
multiSelect: zod.z.boolean().optional()
|
|
107
|
+
})).min(1).max(4) }),
|
|
108
|
+
invoke_integration: zod.z.object({}).passthrough(),
|
|
109
|
+
call_integration: zod.z.object({}).passthrough(),
|
|
110
|
+
search_integration_tool: zod.z.object({}).passthrough(),
|
|
111
|
+
supabase_get_logs: zod.z.object({}).passthrough(),
|
|
112
|
+
supabase_execute_sql: zod.z.object({}).passthrough(),
|
|
113
|
+
supabase_apply_migration: zod.z.object({}).passthrough(),
|
|
114
|
+
supabase_list_migration: zod.z.object({}).passthrough(),
|
|
115
|
+
supabase_list_tables: zod.z.object({}).passthrough(),
|
|
116
|
+
cloud_studio_fetch_log: zod.z.object({}).passthrough(),
|
|
117
|
+
cloud_studio_execute_command: zod.z.object({}).passthrough(),
|
|
118
|
+
cloud_studio_deploy_sandbox: zod.z.object({}).passthrough(),
|
|
119
|
+
component_get_prompt: zod.z.object({}).passthrough(),
|
|
120
|
+
web_fetch: zod.z.object({
|
|
121
|
+
url: zod.z.string().describe("要获取内容的 URL"),
|
|
122
|
+
fetchInfo: zod.z.string().describe("用户想要获取的信息描述")
|
|
123
|
+
}),
|
|
124
|
+
use_skill: zod.z.object({ command: zod.z.string().describe("技能名称(不含参数),如 \"pdf\" 或 \"xlsx\"") }),
|
|
125
|
+
web_search: zod.z.object({
|
|
126
|
+
explanation: zod.z.string().describe("为什么使用此工具的一句话解释"),
|
|
127
|
+
searchTerm: zod.z.string().describe("要在网络上搜索的搜索词")
|
|
128
|
+
}),
|
|
129
|
+
task: zod.z.object({
|
|
130
|
+
subagent_name: zod.z.string().describe("要调用的子代理名称"),
|
|
131
|
+
description: zod.z.string().describe("任务的简短描述(3-5 个词)"),
|
|
132
|
+
prompt: zod.z.string().describe("子代理要执行的任务"),
|
|
133
|
+
subagent_path: zod.z.string().optional().describe("子代理定义文件的路径")
|
|
134
|
+
}),
|
|
135
|
+
codebase_search: zod.z.object({
|
|
136
|
+
query: zod.z.string().describe("关于你想理解的内容的完整问题"),
|
|
137
|
+
path: zod.z.string().describe("限制搜索范围的目录路径前缀"),
|
|
138
|
+
limit: zod.z.number().max(100).optional().describe("返回的最大结果数,默认 10")
|
|
139
|
+
}),
|
|
140
|
+
lsp: zod.z.object({}).passthrough(),
|
|
141
|
+
spec_create: zod.z.object({
|
|
142
|
+
name: zod.z.string().describe("Plan 名称,用作稳定标识符/文件名"),
|
|
143
|
+
overview: zod.z.string().describe("用一两句话精确概括本次 plan 的主要内容"),
|
|
144
|
+
relative_history: zod.z.string().describe("准备阶段的上下文,包含用户需求、代码位置、额外上下文等")
|
|
145
|
+
}),
|
|
146
|
+
spec_update: zod.z.object({ status: zod.z.enum([
|
|
147
|
+
"prepare",
|
|
148
|
+
"ready",
|
|
149
|
+
"building",
|
|
150
|
+
"finished"
|
|
151
|
+
]).optional().describe("Plan 状态") })
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 工具输出 Schema 定义
|
|
155
|
+
* 用于验证和约束 rawOutput
|
|
156
|
+
*/
|
|
157
|
+
const ToolOutputSchemas = {
|
|
158
|
+
list_dir: zod.z.object({
|
|
159
|
+
type: zod.z.literal("list_files_result"),
|
|
160
|
+
files: zod.z.array(zod.z.object({
|
|
161
|
+
filePath: zod.z.string(),
|
|
162
|
+
size: zod.z.string(),
|
|
163
|
+
modifyTime: zod.z.string()
|
|
164
|
+
})),
|
|
165
|
+
root: zod.z.string(),
|
|
166
|
+
listing: zod.z.string().optional()
|
|
167
|
+
}),
|
|
168
|
+
search_file: zod.z.object({
|
|
169
|
+
type: zod.z.literal("search_file_result"),
|
|
170
|
+
path: zod.z.string(),
|
|
171
|
+
pattern: zod.z.string(),
|
|
172
|
+
recursive: zod.z.boolean().optional(),
|
|
173
|
+
caseSensitive: zod.z.boolean().optional(),
|
|
174
|
+
results: zod.z.array(zod.z.object({
|
|
175
|
+
filePath: zod.z.string(),
|
|
176
|
+
size: zod.z.string(),
|
|
177
|
+
modifyTime: zod.z.string()
|
|
178
|
+
}))
|
|
179
|
+
}),
|
|
180
|
+
read_file: zod.z.object({
|
|
181
|
+
type: zod.z.literal("read_file_result"),
|
|
182
|
+
path: zod.z.string(),
|
|
183
|
+
content: zod.z.string(),
|
|
184
|
+
totalLineCount: zod.z.number(),
|
|
185
|
+
hasMore: zod.z.boolean(),
|
|
186
|
+
diagnostic: zod.z.string().optional(),
|
|
187
|
+
hint: zod.z.string().optional(),
|
|
188
|
+
image: zod.z.object({
|
|
189
|
+
data: zod.z.string(),
|
|
190
|
+
mimeType: zod.z.string()
|
|
191
|
+
}).optional()
|
|
192
|
+
}),
|
|
193
|
+
read_lints: zod.z.object({
|
|
194
|
+
type: zod.z.literal("read_lints_result"),
|
|
195
|
+
diagnostics: zod.z.array(zod.z.string()),
|
|
196
|
+
totalCount: zod.z.number().optional(),
|
|
197
|
+
hint: zod.z.string().optional(),
|
|
198
|
+
isTruncated: zod.z.boolean().optional()
|
|
199
|
+
}),
|
|
200
|
+
rag_search: zod.z.object({
|
|
201
|
+
type: zod.z.literal("knowledge_base_result"),
|
|
202
|
+
selectedKnowledgeBases: zod.z.string(),
|
|
203
|
+
queryInput: zod.z.string()
|
|
204
|
+
}),
|
|
205
|
+
read_rules: zod.z.object({
|
|
206
|
+
type: zod.z.literal("rule_match_result"),
|
|
207
|
+
ruleDescription: zod.z.string(),
|
|
208
|
+
filePaths: zod.z.array(zod.z.string())
|
|
209
|
+
}),
|
|
210
|
+
mcp_get_tool_description: zod.z.object({}).passthrough(),
|
|
211
|
+
mcp_call_tool: zod.z.object({
|
|
212
|
+
type: zod.z.literal("mcp_call_tool_result"),
|
|
213
|
+
serverName: zod.z.string(),
|
|
214
|
+
toolName: zod.z.string(),
|
|
215
|
+
data: zod.z.array(zod.z.union([
|
|
216
|
+
zod.z.object({
|
|
217
|
+
type: zod.z.literal("text"),
|
|
218
|
+
text: zod.z.string()
|
|
219
|
+
}),
|
|
220
|
+
zod.z.object({
|
|
221
|
+
type: zod.z.literal("image"),
|
|
222
|
+
data: zod.z.string(),
|
|
223
|
+
mimeType: zod.z.string()
|
|
224
|
+
}),
|
|
225
|
+
zod.z.object({
|
|
226
|
+
type: zod.z.literal("resource"),
|
|
227
|
+
resource: zod.z.object({
|
|
228
|
+
uri: zod.z.string(),
|
|
229
|
+
mimeType: zod.z.string().optional(),
|
|
230
|
+
text: zod.z.string().optional(),
|
|
231
|
+
blob: zod.z.string().optional()
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
])),
|
|
235
|
+
isError: zod.z.boolean().optional(),
|
|
236
|
+
error: zod.z.unknown().optional(),
|
|
237
|
+
hint: zod.z.string().optional()
|
|
238
|
+
}),
|
|
239
|
+
fetch_mcp_resource: zod.z.object({
|
|
240
|
+
type: zod.z.literal("fetch_mcp_resource_result"),
|
|
241
|
+
server: zod.z.string(),
|
|
242
|
+
uri: zod.z.string(),
|
|
243
|
+
content: zod.z.string(),
|
|
244
|
+
downloadPath: zod.z.string().optional()
|
|
245
|
+
}),
|
|
246
|
+
create_rule: zod.z.object({
|
|
247
|
+
type: zod.z.literal("rule_create_result"),
|
|
248
|
+
ruleName: zod.z.string(),
|
|
249
|
+
createState: zod.z.enum([
|
|
250
|
+
"success",
|
|
251
|
+
"invoke",
|
|
252
|
+
"cancelled"
|
|
253
|
+
]),
|
|
254
|
+
hint: zod.z.string().optional(),
|
|
255
|
+
filePath: zod.z.string().optional()
|
|
256
|
+
}),
|
|
257
|
+
update_memory: zod.z.object({
|
|
258
|
+
type: zod.z.literal("update_memory_result"),
|
|
259
|
+
success: zod.z.boolean(),
|
|
260
|
+
message: zod.z.string(),
|
|
261
|
+
action: zod.z.enum([
|
|
262
|
+
"create",
|
|
263
|
+
"update",
|
|
264
|
+
"delete"
|
|
265
|
+
]),
|
|
266
|
+
knowledge_id: zod.z.string().optional()
|
|
267
|
+
}),
|
|
268
|
+
search_content: zod.z.object({
|
|
269
|
+
type: zod.z.literal("search_content_result"),
|
|
270
|
+
directory: zod.z.string(),
|
|
271
|
+
pattern: zod.z.string(),
|
|
272
|
+
fileTypes: zod.z.string(),
|
|
273
|
+
matches: zod.z.array(zod.z.object({
|
|
274
|
+
filePath: zod.z.string(),
|
|
275
|
+
content: zod.z.string(),
|
|
276
|
+
startLine: zod.z.number(),
|
|
277
|
+
endLine: zod.z.number(),
|
|
278
|
+
size: zod.z.string(),
|
|
279
|
+
modifyTime: zod.z.string()
|
|
280
|
+
})),
|
|
281
|
+
totalCount: zod.z.number(),
|
|
282
|
+
hasMore: zod.z.boolean(),
|
|
283
|
+
offset: zod.z.number(),
|
|
284
|
+
limit: zod.z.number(),
|
|
285
|
+
contextBefore: zod.z.number(),
|
|
286
|
+
contextAfter: zod.z.number(),
|
|
287
|
+
contextAround: zod.z.number().optional(),
|
|
288
|
+
outputMode: zod.z.string(),
|
|
289
|
+
caseSensitive: zod.z.boolean(),
|
|
290
|
+
hint: zod.z.string().optional()
|
|
291
|
+
}),
|
|
292
|
+
write_to_file: zod.z.object({
|
|
293
|
+
type: zod.z.literal("write_to_file_result"),
|
|
294
|
+
path: zod.z.string(),
|
|
295
|
+
addLineCount: zod.z.number(),
|
|
296
|
+
removedLines: zod.z.number(),
|
|
297
|
+
addedChars: zod.z.number().optional(),
|
|
298
|
+
removedChars: zod.z.number().optional(),
|
|
299
|
+
bytesWritten: zod.z.number(),
|
|
300
|
+
isNewFile: zod.z.boolean(),
|
|
301
|
+
oldContent: zod.z.string().optional(),
|
|
302
|
+
diagnostic: zod.z.string().optional()
|
|
303
|
+
}),
|
|
304
|
+
replace_in_file: zod.z.object({
|
|
305
|
+
type: zod.z.literal("replace_in_file_result"),
|
|
306
|
+
path: zod.z.string(),
|
|
307
|
+
addLineCount: zod.z.number().optional(),
|
|
308
|
+
removedLines: zod.z.number().optional(),
|
|
309
|
+
addedChars: zod.z.number().optional(),
|
|
310
|
+
removedChars: zod.z.number().optional(),
|
|
311
|
+
matchCount: zod.z.number().optional(),
|
|
312
|
+
hint: zod.z.string().optional(),
|
|
313
|
+
diagnosticChange: zod.z.object({
|
|
314
|
+
added: zod.z.string(),
|
|
315
|
+
removed: zod.z.string(),
|
|
316
|
+
unchanged: zod.z.string()
|
|
317
|
+
}).optional()
|
|
318
|
+
}),
|
|
319
|
+
delete_file: zod.z.object({
|
|
320
|
+
type: zod.z.literal("delete_file_result"),
|
|
321
|
+
path: zod.z.string(),
|
|
322
|
+
recursive: zod.z.boolean(),
|
|
323
|
+
hint: zod.z.string().optional()
|
|
324
|
+
}),
|
|
325
|
+
execute_command: zod.z.object({
|
|
326
|
+
type: zod.z.literal("execute_command_result"),
|
|
327
|
+
stdout: zod.z.string(),
|
|
328
|
+
stderr: zod.z.string(),
|
|
329
|
+
exitCode: zod.z.number(),
|
|
330
|
+
hint: zod.z.string().optional(),
|
|
331
|
+
serviceInfo: zod.z.object({
|
|
332
|
+
isWatchCommand: zod.z.boolean(),
|
|
333
|
+
isServiceOutput: zod.z.boolean(),
|
|
334
|
+
serviceReady: zod.z.boolean(),
|
|
335
|
+
message: zod.z.string()
|
|
336
|
+
}).optional(),
|
|
337
|
+
use_standalone_terminal: zod.z.boolean().optional()
|
|
338
|
+
}),
|
|
339
|
+
preview_url: zod.z.object({
|
|
340
|
+
type: zod.z.literal("preview_tool_result"),
|
|
341
|
+
url: zod.z.string(),
|
|
342
|
+
message: zod.z.string()
|
|
343
|
+
}),
|
|
344
|
+
ask_followup_question: zod.z.object({
|
|
345
|
+
type: zod.z.literal("multi_question_result"),
|
|
346
|
+
questions: zod.z.array(zod.z.object({
|
|
347
|
+
id: zod.z.string(),
|
|
348
|
+
question: zod.z.string(),
|
|
349
|
+
options: zod.z.array(zod.z.string()),
|
|
350
|
+
multiSelect: zod.z.boolean().optional(),
|
|
351
|
+
title: zod.z.string().optional()
|
|
352
|
+
})),
|
|
353
|
+
answers: zod.z.record(zod.z.union([zod.z.string(), zod.z.array(zod.z.string())])),
|
|
354
|
+
message: zod.z.string()
|
|
355
|
+
}),
|
|
356
|
+
invoke_integration: zod.z.object({
|
|
357
|
+
type: zod.z.literal("invoke_integration_tool_result"),
|
|
358
|
+
recommend: zod.z.object({
|
|
359
|
+
id: zod.z.string(),
|
|
360
|
+
type: zod.z.string(),
|
|
361
|
+
status: zod.z.enum(["connected", "disconnected"])
|
|
362
|
+
}),
|
|
363
|
+
message: zod.z.string()
|
|
364
|
+
}),
|
|
365
|
+
call_integration: zod.z.object({
|
|
366
|
+
type: zod.z.literal("call_integration_tool_result"),
|
|
367
|
+
integrationId: zod.z.string(),
|
|
368
|
+
toolName: zod.z.string(),
|
|
369
|
+
data: zod.z.object({
|
|
370
|
+
type: zod.z.literal("text"),
|
|
371
|
+
text: zod.z.string()
|
|
372
|
+
}),
|
|
373
|
+
isError: zod.z.boolean().optional(),
|
|
374
|
+
error: zod.z.unknown().optional()
|
|
375
|
+
}),
|
|
376
|
+
search_integration_tool: zod.z.object({
|
|
377
|
+
type: zod.z.literal("search_integration_tool_result"),
|
|
378
|
+
data: zod.z.array(zod.z.object({
|
|
379
|
+
integrationId: zod.z.string(),
|
|
380
|
+
integrationName: zod.z.string(),
|
|
381
|
+
toolName: zod.z.string(),
|
|
382
|
+
description: zod.z.string(),
|
|
383
|
+
inputSchema: zod.z.record(zod.z.unknown())
|
|
384
|
+
})),
|
|
385
|
+
hint: zod.z.string().optional()
|
|
386
|
+
}),
|
|
387
|
+
supabase_get_logs: zod.z.object({
|
|
388
|
+
type: zod.z.enum([
|
|
389
|
+
"supabase_get_logs_result",
|
|
390
|
+
"supabase_execute_sql_result",
|
|
391
|
+
"supabase_apply_migration_result",
|
|
392
|
+
"supabase_list_migration_result",
|
|
393
|
+
"supabase_list_tables_result"
|
|
394
|
+
]),
|
|
395
|
+
message: zod.z.string()
|
|
396
|
+
}),
|
|
397
|
+
supabase_execute_sql: zod.z.object({
|
|
398
|
+
type: zod.z.enum([
|
|
399
|
+
"supabase_get_logs_result",
|
|
400
|
+
"supabase_execute_sql_result",
|
|
401
|
+
"supabase_apply_migration_result",
|
|
402
|
+
"supabase_list_migration_result",
|
|
403
|
+
"supabase_list_tables_result"
|
|
404
|
+
]),
|
|
405
|
+
message: zod.z.string()
|
|
406
|
+
}),
|
|
407
|
+
supabase_apply_migration: zod.z.object({
|
|
408
|
+
type: zod.z.enum([
|
|
409
|
+
"supabase_get_logs_result",
|
|
410
|
+
"supabase_execute_sql_result",
|
|
411
|
+
"supabase_apply_migration_result",
|
|
412
|
+
"supabase_list_migration_result",
|
|
413
|
+
"supabase_list_tables_result"
|
|
414
|
+
]),
|
|
415
|
+
message: zod.z.string()
|
|
416
|
+
}),
|
|
417
|
+
supabase_list_migration: zod.z.object({
|
|
418
|
+
type: zod.z.enum([
|
|
419
|
+
"supabase_get_logs_result",
|
|
420
|
+
"supabase_execute_sql_result",
|
|
421
|
+
"supabase_apply_migration_result",
|
|
422
|
+
"supabase_list_migration_result",
|
|
423
|
+
"supabase_list_tables_result"
|
|
424
|
+
]),
|
|
425
|
+
message: zod.z.string()
|
|
426
|
+
}),
|
|
427
|
+
supabase_list_tables: zod.z.object({
|
|
428
|
+
type: zod.z.enum([
|
|
429
|
+
"supabase_get_logs_result",
|
|
430
|
+
"supabase_execute_sql_result",
|
|
431
|
+
"supabase_apply_migration_result",
|
|
432
|
+
"supabase_list_migration_result",
|
|
433
|
+
"supabase_list_tables_result"
|
|
434
|
+
]),
|
|
435
|
+
message: zod.z.string()
|
|
436
|
+
}),
|
|
437
|
+
cloud_studio_fetch_log: zod.z.object({
|
|
438
|
+
type: zod.z.literal("cloud_studio_fetch_log_result"),
|
|
439
|
+
success: zod.z.boolean(),
|
|
440
|
+
logs: zod.z.record(zod.z.string())
|
|
441
|
+
}),
|
|
442
|
+
cloud_studio_execute_command: zod.z.object({
|
|
443
|
+
type: zod.z.literal("cloud_studio_execute_command_result"),
|
|
444
|
+
success: zod.z.boolean(),
|
|
445
|
+
message: zod.z.string()
|
|
446
|
+
}),
|
|
447
|
+
cloud_studio_deploy_sandbox: zod.z.object({
|
|
448
|
+
type: zod.z.literal("cloud_studio_integration_result"),
|
|
449
|
+
previewUrl: zod.z.string().optional(),
|
|
450
|
+
steps: zod.z.array(zod.z.object({
|
|
451
|
+
status: zod.z.enum([
|
|
452
|
+
"idle",
|
|
453
|
+
"success",
|
|
454
|
+
"running",
|
|
455
|
+
"error"
|
|
456
|
+
]),
|
|
457
|
+
name: zod.z.enum([
|
|
458
|
+
"createSandbox",
|
|
459
|
+
"uploadProject",
|
|
460
|
+
"installDependencies",
|
|
461
|
+
"startService",
|
|
462
|
+
"preview"
|
|
463
|
+
]),
|
|
464
|
+
error: zod.z.object({
|
|
465
|
+
code: zod.z.number().optional(),
|
|
466
|
+
message: zod.z.string().optional()
|
|
467
|
+
}).optional()
|
|
468
|
+
}))
|
|
469
|
+
}),
|
|
470
|
+
component_get_prompt: zod.z.object({
|
|
471
|
+
type: zod.z.literal("component_get_prompt_result"),
|
|
472
|
+
componentType: zod.z.string(),
|
|
473
|
+
webFramework: zod.z.string(),
|
|
474
|
+
data: zod.z.object({
|
|
475
|
+
type: zod.z.literal("text"),
|
|
476
|
+
text: zod.z.string()
|
|
477
|
+
})
|
|
478
|
+
}),
|
|
479
|
+
web_fetch: zod.z.object({
|
|
480
|
+
type: zod.z.literal("web_fetch_tool_result"),
|
|
481
|
+
message: zod.z.string(),
|
|
482
|
+
data: zod.z.string(),
|
|
483
|
+
loading: zod.z.string().optional(),
|
|
484
|
+
title: zod.z.string().optional(),
|
|
485
|
+
favicon: zod.z.string().optional()
|
|
486
|
+
}),
|
|
487
|
+
use_skill: zod.z.object({
|
|
488
|
+
type: zod.z.literal("use_skill_tool_result"),
|
|
489
|
+
commandMessage: zod.z.string(),
|
|
490
|
+
message: zod.z.string()
|
|
491
|
+
}),
|
|
492
|
+
web_search: zod.z.object({
|
|
493
|
+
type: zod.z.literal("web_search_tool_result"),
|
|
494
|
+
data: zod.z.array(zod.z.object({
|
|
495
|
+
passage: zod.z.string(),
|
|
496
|
+
uri: zod.z.string(),
|
|
497
|
+
site: zod.z.string(),
|
|
498
|
+
title: zod.z.string(),
|
|
499
|
+
snippets: zod.z.array(zod.z.string()).optional(),
|
|
500
|
+
content: zod.z.string().optional()
|
|
501
|
+
})),
|
|
502
|
+
searchInput: zod.z.string().optional()
|
|
503
|
+
}),
|
|
504
|
+
task: zod.z.object({
|
|
505
|
+
type: zod.z.literal("task_tool_result"),
|
|
506
|
+
toolInfo: zod.z.array(zod.z.object({
|
|
507
|
+
name: zod.z.string(),
|
|
508
|
+
info: zod.z.string(),
|
|
509
|
+
needApprove: zod.z.boolean().optional(),
|
|
510
|
+
toolCallId: zod.z.string().optional(),
|
|
511
|
+
executeStatus: zod.z.enum([
|
|
512
|
+
"ing",
|
|
513
|
+
"completed",
|
|
514
|
+
"cancel",
|
|
515
|
+
"fail"
|
|
516
|
+
]).optional()
|
|
517
|
+
})).optional(),
|
|
518
|
+
startCallTool: zod.z.boolean().optional(),
|
|
519
|
+
finalResult: zod.z.string().optional(),
|
|
520
|
+
toolCallBrief: zod.z.string().optional()
|
|
521
|
+
}),
|
|
522
|
+
codebase_search: zod.z.object({
|
|
523
|
+
type: zod.z.literal("codebase_search_result"),
|
|
524
|
+
query: zod.z.string(),
|
|
525
|
+
path: zod.z.string(),
|
|
526
|
+
content: zod.z.string()
|
|
527
|
+
}),
|
|
528
|
+
lsp: zod.z.object({
|
|
529
|
+
type: zod.z.literal("lsp_tool_result"),
|
|
530
|
+
operation: zod.z.string(),
|
|
531
|
+
result: zod.z.string(),
|
|
532
|
+
resultCount: zod.z.number().optional(),
|
|
533
|
+
fileCount: zod.z.number().optional(),
|
|
534
|
+
character: zod.z.number().optional()
|
|
535
|
+
}),
|
|
536
|
+
spec_create: zod.z.object({
|
|
537
|
+
type: zod.z.literal("plan_create_tool_result"),
|
|
538
|
+
message: zod.z.string(),
|
|
539
|
+
data: zod.z.string()
|
|
540
|
+
}),
|
|
541
|
+
spec_update: zod.z.object({
|
|
542
|
+
type: zod.z.literal("plan_update_tool_result"),
|
|
543
|
+
status: zod.z.enum([
|
|
544
|
+
"prepare",
|
|
545
|
+
"ready",
|
|
546
|
+
"building",
|
|
547
|
+
"finished"
|
|
548
|
+
]),
|
|
549
|
+
data: zod.z.string(),
|
|
550
|
+
reminder: zod.z.string()
|
|
551
|
+
})
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region ../agent-provider/src/common/_legacy/MockAgentProvider.ts
|
|
556
|
+
/**
|
|
557
|
+
* Mock 会话数据存储
|
|
558
|
+
* 每个会话都有对应的模拟历史消息
|
|
559
|
+
*/
|
|
560
|
+
const mockSessionHistories = /* @__PURE__ */ new Map();
|
|
561
|
+
mockSessionHistories.set("1", [
|
|
562
|
+
{
|
|
563
|
+
type: "user",
|
|
564
|
+
content: "帮我开发一个五子棋游戏,需要包含以下功能:\n1. 双人对战模式\n2. 悔棋功能\n3. 计时器",
|
|
565
|
+
timestamp: Date.now() - 18e5 - 6e4
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
type: "assistant",
|
|
569
|
+
content: "好的,我来帮你开发一个五子棋游戏。我会创建以下文件结构:\n\n- `index.html` - 主页面\n- `game.js` - 游戏逻辑\n- `style.css` - 样式文件\n\n让我开始创建这些文件...",
|
|
570
|
+
timestamp: Date.now() - 18e5 - 5e4
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
type: "assistant",
|
|
574
|
+
content: "我已经完成了所有文件的创建和修改。游戏支持双人对战、悔棋和计时功能。你可以直接在浏览器中打开 index.html 开始游戏。",
|
|
575
|
+
timestamp: Date.now() - 18e5
|
|
576
|
+
}
|
|
577
|
+
]);
|
|
578
|
+
mockSessionHistories.set("2", [
|
|
579
|
+
{
|
|
580
|
+
type: "user",
|
|
581
|
+
content: "登录页面的样式有问题,按钮颜色不对齐,帮我修复一下",
|
|
582
|
+
timestamp: Date.now() - 72e5 - 12e4
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
type: "assistant",
|
|
586
|
+
content: "我来检查登录页面的样式。让我先看看相关的 CSS 文件...",
|
|
587
|
+
timestamp: Date.now() - 72e5 - 1e5
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
type: "assistant",
|
|
591
|
+
content: "样式问题已修复,请查看效果。主要修改了按钮的 flex 布局和颜色变量。",
|
|
592
|
+
timestamp: Date.now() - 72e5
|
|
593
|
+
}
|
|
594
|
+
]);
|
|
595
|
+
mockSessionHistories.set("3", [
|
|
596
|
+
{
|
|
597
|
+
type: "user",
|
|
598
|
+
content: "API 接口响应太慢了,需要添加缓存和错误重试机制",
|
|
599
|
+
timestamp: Date.now() - 144e5 - 18e4
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
type: "assistant",
|
|
603
|
+
content: "好的,我来优化 API 接口。我会实现:\n1. Redis 缓存层\n2. 指数退避重试策略\n3. 请求去重",
|
|
604
|
+
timestamp: Date.now() - 144e5 - 15e4
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
type: "assistant",
|
|
608
|
+
content: "已添加缓存和错误重试机制。性能提升了约 60%。",
|
|
609
|
+
timestamp: Date.now() - 144e5
|
|
610
|
+
}
|
|
611
|
+
]);
|
|
612
|
+
mockSessionHistories.set("4", [
|
|
613
|
+
{
|
|
614
|
+
type: "user",
|
|
615
|
+
content: "帮我为核心模块添加单元测试,覆盖率要达到 80% 以上",
|
|
616
|
+
timestamp: Date.now() - 864e5 - 3e5
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
type: "assistant",
|
|
620
|
+
content: "好的,我会使用 Jest 来编写单元测试。让我先看看核心模块的代码结构...",
|
|
621
|
+
timestamp: Date.now() - 864e5 - 25e4
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
type: "assistant",
|
|
625
|
+
content: "测试覆盖率已达到 85%,超过了目标。主要测试了:\n- 用户认证逻辑\n- 数据验证\n- 错误处理",
|
|
626
|
+
timestamp: Date.now() - 864e5
|
|
627
|
+
}
|
|
628
|
+
]);
|
|
629
|
+
|
|
630
|
+
//#endregion
|
|
8
631
|
//#region ../agent-client-protocol/src/common/types.ts
|
|
9
632
|
/**
|
|
10
633
|
* Protocol Extension Types for Agent Client Protocol
|
|
@@ -19,7 +642,8 @@ const ExtensionMethod = {
|
|
|
19
642
|
ARTIFACT: "_codebuddy.ai/artifact",
|
|
20
643
|
QUESTION: "_codebuddy.ai/question",
|
|
21
644
|
CHECKPOINT: "_codebuddy.ai/checkpoint",
|
|
22
|
-
USAGE: "_codebuddy.ai/usage"
|
|
645
|
+
USAGE: "_codebuddy.ai/usage",
|
|
646
|
+
COMMAND: "_codebuddy.ai/command"
|
|
23
647
|
};
|
|
24
648
|
/**
|
|
25
649
|
* All known extension methods
|
|
@@ -28,7 +652,8 @@ const KNOWN_EXTENSIONS = [
|
|
|
28
652
|
ExtensionMethod.ARTIFACT,
|
|
29
653
|
ExtensionMethod.QUESTION,
|
|
30
654
|
ExtensionMethod.CHECKPOINT,
|
|
31
|
-
ExtensionMethod.USAGE
|
|
655
|
+
ExtensionMethod.USAGE,
|
|
656
|
+
ExtensionMethod.COMMAND
|
|
32
657
|
];
|
|
33
658
|
|
|
34
659
|
//#endregion
|
|
@@ -81,7 +706,7 @@ function parseSSELine(line, currentEvent) {
|
|
|
81
706
|
function streamableHttp(options) {
|
|
82
707
|
const { endpoint, authToken, headers: customHeaders = {}, reconnect = {}, signal: externalSignal, fetch: customFetch = globalThis.fetch, onConnect, onDisconnect, onError, heartbeatTimeout = 6e4, postTimeout = 3e4, backpressure = {} } = options;
|
|
83
708
|
const { enabled: reconnectEnabled = true, initialDelay = 1e3, maxDelay = 3e4, maxRetries = Infinity, jitter: jitterEnabled = true } = reconnect;
|
|
84
|
-
const { highWaterMark = 100, lowWaterMark = 50 } = backpressure;
|
|
709
|
+
const { highWaterMark = 100, lowWaterMark = 50, pauseTimeout = 5e3 } = backpressure;
|
|
85
710
|
let connectionId;
|
|
86
711
|
let lastEventId;
|
|
87
712
|
let reconnectAttempts = 0;
|
|
@@ -110,6 +735,7 @@ function streamableHttp(options) {
|
|
|
110
735
|
let streamError = null;
|
|
111
736
|
let isPaused = false;
|
|
112
737
|
let resumeReading = null;
|
|
738
|
+
let backgroundSSEProcessors = /* @__PURE__ */ new Set();
|
|
113
739
|
let lastActivity = Date.now();
|
|
114
740
|
let heartbeatCheckTimer;
|
|
115
741
|
function enqueueMessage(message) {
|
|
@@ -132,7 +758,8 @@ function streamableHttp(options) {
|
|
|
132
758
|
const message = messageQueue.shift();
|
|
133
759
|
if (isPaused && messageQueue.length <= lowWaterMark) {
|
|
134
760
|
isPaused = false;
|
|
135
|
-
resumeReading
|
|
761
|
+
const resume = resumeReading;
|
|
762
|
+
if (resume) queueMicrotask(() => resume());
|
|
136
763
|
}
|
|
137
764
|
return Promise.resolve(message);
|
|
138
765
|
}
|
|
@@ -186,6 +813,7 @@ function streamableHttp(options) {
|
|
|
186
813
|
resumeReading();
|
|
187
814
|
resumeReading = null;
|
|
188
815
|
}
|
|
816
|
+
backgroundSSEProcessors.clear();
|
|
189
817
|
while (messageResolvers.length > 0) messageResolvers.shift()(null);
|
|
190
818
|
}
|
|
191
819
|
async function sendDelete() {
|
|
@@ -218,7 +846,21 @@ function streamableHttp(options) {
|
|
|
218
846
|
while (true) {
|
|
219
847
|
if (isPaused) {
|
|
220
848
|
await new Promise((resolve) => {
|
|
221
|
-
|
|
849
|
+
let resolved = false;
|
|
850
|
+
const timeoutId = setTimeout(() => {
|
|
851
|
+
if (!resolved) {
|
|
852
|
+
resolved = true;
|
|
853
|
+
console.warn("[StreamableHTTP] Backpressure pause timeout, forcing resume");
|
|
854
|
+
resolve();
|
|
855
|
+
}
|
|
856
|
+
}, pauseTimeout);
|
|
857
|
+
resumeReading = () => {
|
|
858
|
+
if (!resolved) {
|
|
859
|
+
resolved = true;
|
|
860
|
+
clearTimeout(timeoutId);
|
|
861
|
+
resolve();
|
|
862
|
+
}
|
|
863
|
+
};
|
|
222
864
|
});
|
|
223
865
|
resumeReading = null;
|
|
224
866
|
}
|
|
@@ -251,6 +893,19 @@ function streamableHttp(options) {
|
|
|
251
893
|
reader.releaseLock();
|
|
252
894
|
}
|
|
253
895
|
}
|
|
896
|
+
/**
|
|
897
|
+
* Process SSE stream in background without blocking the caller.
|
|
898
|
+
* This prevents deadlock when POST responses return SSE streams.
|
|
899
|
+
*/
|
|
900
|
+
function processSSEStreamBackground(reader) {
|
|
901
|
+
const promise = processSSEStream(reader).catch((error) => {
|
|
902
|
+
console.error("[StreamableHTTP] Background SSE processing error:", error);
|
|
903
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
904
|
+
}).finally(() => {
|
|
905
|
+
backgroundSSEProcessors.delete(promise);
|
|
906
|
+
});
|
|
907
|
+
backgroundSSEProcessors.add(promise);
|
|
908
|
+
}
|
|
254
909
|
async function startSSEConnection() {
|
|
255
910
|
let currentReader = null;
|
|
256
911
|
const triggerReconnect = () => {
|
|
@@ -286,14 +941,14 @@ function streamableHttp(options) {
|
|
|
286
941
|
stopHeartbeatCheck();
|
|
287
942
|
const endedConnectionId = connectionId;
|
|
288
943
|
connectionId = void 0;
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
944
|
+
if (endedConnectionId) onDisconnect?.(endedConnectionId);
|
|
945
|
+
if (!reconnectEnabled || closed) break;
|
|
293
946
|
connectionReady = new Promise((resolve, reject) => {
|
|
294
947
|
resolveConnection = resolve;
|
|
295
948
|
rejectConnection = reject;
|
|
296
949
|
});
|
|
950
|
+
const reconnectDelay = calculateDelay(1);
|
|
951
|
+
await new Promise((resolve) => setTimeout(resolve, reconnectDelay));
|
|
297
952
|
} catch (error) {
|
|
298
953
|
stopHeartbeatCheck();
|
|
299
954
|
currentReader = null;
|
|
@@ -310,14 +965,21 @@ function streamableHttp(options) {
|
|
|
310
965
|
}
|
|
311
966
|
async function sendMessage(message) {
|
|
312
967
|
if (closed) throw new Error("Connection is closed");
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
968
|
+
const maxWaitAttempts = 5;
|
|
969
|
+
let currentConnectionId;
|
|
970
|
+
for (let attempt = 0; attempt < maxWaitAttempts; attempt++) {
|
|
971
|
+
const versionBeforeWait = connectionVersion;
|
|
972
|
+
await connectionReady;
|
|
973
|
+
if (versionBeforeWait !== connectionVersion && versionBeforeWait > 0) await connectionReady;
|
|
974
|
+
currentConnectionId = connectionId;
|
|
975
|
+
if (currentConnectionId) break;
|
|
976
|
+
if (attempt < maxWaitAttempts - 1) await new Promise((resolve) => setTimeout(resolve, 100));
|
|
977
|
+
}
|
|
978
|
+
if (!currentConnectionId) throw new Error("No connection ID available after multiple attempts");
|
|
317
979
|
const headers = buildHeaders();
|
|
318
980
|
headers["Content-Type"] = "application/json";
|
|
319
981
|
headers["Accept"] = "application/json, text/event-stream";
|
|
320
|
-
headers["Acp-Connection-Id"] =
|
|
982
|
+
headers["Acp-Connection-Id"] = currentConnectionId;
|
|
321
983
|
const postController = new AbortController();
|
|
322
984
|
let timeoutId;
|
|
323
985
|
const postSignal = postTimeout > 0 ? postController.signal : combinedSignal;
|
|
@@ -340,7 +1002,7 @@ function streamableHttp(options) {
|
|
|
340
1002
|
const contentType = response.headers.get("Content-Type") || "";
|
|
341
1003
|
if (contentType.includes("text/event-stream")) {
|
|
342
1004
|
const reader = response.body?.getReader();
|
|
343
|
-
if (reader)
|
|
1005
|
+
if (reader) processSSEStreamBackground(reader);
|
|
344
1006
|
} else if (contentType.includes("application/json")) {
|
|
345
1007
|
const data = await response.json();
|
|
346
1008
|
if (data && typeof data === "object" && "jsonrpc" in data) enqueueMessage(data);
|
|
@@ -2155,12 +2817,13 @@ var AccountService = class {
|
|
|
2155
2817
|
*/
|
|
2156
2818
|
setAccount(account) {
|
|
2157
2819
|
const prev = this.account;
|
|
2820
|
+
const wasInitialized = this.initialized;
|
|
2158
2821
|
this.account = account;
|
|
2159
2822
|
if (!this.initialized) {
|
|
2160
2823
|
this.initialized = true;
|
|
2161
2824
|
this.initResolve?.(account);
|
|
2162
2825
|
}
|
|
2163
|
-
if (prev?.uid !== account?.uid) this.notifyListeners();
|
|
2826
|
+
if (!wasInitialized || prev?.uid !== account?.uid) this.notifyListeners();
|
|
2164
2827
|
}
|
|
2165
2828
|
/**
|
|
2166
2829
|
* 清除账号(登出)
|
|
@@ -2467,7 +3130,6 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
2467
3130
|
*/
|
|
2468
3131
|
async list(options) {
|
|
2469
3132
|
try {
|
|
2470
|
-
console.log("[CloudAgentProvider] list called with options:", JSON.stringify(options, null, 2));
|
|
2471
3133
|
const params = {
|
|
2472
3134
|
page: 1,
|
|
2473
3135
|
size: 30,
|
|
@@ -2484,7 +3146,6 @@ var CloudAgentProvider = class CloudAgentProvider {
|
|
|
2484
3146
|
...options.title !== void 0 && { title: options.title }
|
|
2485
3147
|
}
|
|
2486
3148
|
};
|
|
2487
|
-
console.log("[CloudAgentProvider] API request params:", JSON.stringify(params, null, 2));
|
|
2488
3149
|
const response = await this.request("GET", "/console/cloudagent/agentmgmt/agents", params);
|
|
2489
3150
|
if (!response.ok) throw new Error(`Failed to list agents: ${response.statusText}`);
|
|
2490
3151
|
const apiResponse = await response.json();
|
|
@@ -3048,6 +3709,13 @@ var ActiveSessionImpl = class {
|
|
|
3048
3709
|
return this._availableCommands;
|
|
3049
3710
|
}
|
|
3050
3711
|
/**
|
|
3712
|
+
* Set available commands (called when available_commands_update is received)
|
|
3713
|
+
*/
|
|
3714
|
+
setAvailableCommands(commands) {
|
|
3715
|
+
this._availableCommands = commands;
|
|
3716
|
+
this.logger?.info(`Session ${this._id}: Available commands updated, count: ${commands.length}`);
|
|
3717
|
+
}
|
|
3718
|
+
/**
|
|
3051
3719
|
* Check if the session is active
|
|
3052
3720
|
*/
|
|
3053
3721
|
get isActive() {
|
|
@@ -3359,6 +4027,9 @@ var ActiveSessionImpl = class {
|
|
|
3359
4027
|
connection.on("questionRequest", (request) => {
|
|
3360
4028
|
this.emit("questionRequest", request);
|
|
3361
4029
|
});
|
|
4030
|
+
connection.on("questionCancelled", () => {
|
|
4031
|
+
this.prompts.cancel();
|
|
4032
|
+
});
|
|
3362
4033
|
connection.on("usageUpdate", (usage) => {
|
|
3363
4034
|
this.emit("usageUpdate", usage);
|
|
3364
4035
|
});
|
|
@@ -3368,6 +4039,13 @@ var ActiveSessionImpl = class {
|
|
|
3368
4039
|
connection.on("checkpointUpdated", (checkpoint) => {
|
|
3369
4040
|
this.emit("checkpointUpdated", checkpoint);
|
|
3370
4041
|
});
|
|
4042
|
+
connection.on("command", (command) => {
|
|
4043
|
+
console.log("[Session] Forwarding command:", {
|
|
4044
|
+
action: command.action,
|
|
4045
|
+
paramsKeys: command.params ? Object.keys(command.params) : []
|
|
4046
|
+
});
|
|
4047
|
+
this.emit("command", command);
|
|
4048
|
+
});
|
|
3371
4049
|
}
|
|
3372
4050
|
mapPromptResponse(response) {
|
|
3373
4051
|
return {
|
|
@@ -3420,12 +4098,7 @@ var SessionManager = class {
|
|
|
3420
4098
|
* @param options - Optional query parameters for filtering, sorting, and pagination
|
|
3421
4099
|
*/
|
|
3422
4100
|
async listSessions(options) {
|
|
3423
|
-
console.log("[SessionManager] listSessions called with options:", JSON.stringify(options, null, 2));
|
|
3424
4101
|
const result = await this.provider.list(options);
|
|
3425
|
-
console.log("[SessionManager] provider.list returned:", {
|
|
3426
|
-
agentsCount: result.agents.length,
|
|
3427
|
-
pagination: result.pagination
|
|
3428
|
-
});
|
|
3429
4102
|
const sessions = result.agents.map((agent) => ({
|
|
3430
4103
|
id: agent.id,
|
|
3431
4104
|
agentId: agent.id,
|
|
@@ -3464,6 +4137,7 @@ var SessionManager = class {
|
|
|
3464
4137
|
const connection = await this.provider.connect(agentId);
|
|
3465
4138
|
this.logger?.debug(`Connected to agent: ${agentId}`);
|
|
3466
4139
|
const response = await connection.createSession({
|
|
4140
|
+
_meta: params._meta,
|
|
3467
4141
|
cwd: params.cwd,
|
|
3468
4142
|
mcpServers: params.mcpServers
|
|
3469
4143
|
});
|
|
@@ -3623,6 +4297,20 @@ var AgentClient = class {
|
|
|
3623
4297
|
throw error;
|
|
3624
4298
|
}
|
|
3625
4299
|
},
|
|
4300
|
+
move: async (sessionId) => {
|
|
4301
|
+
this.logger?.debug("AgentClient.sessions.move called", { sessionId });
|
|
4302
|
+
try {
|
|
4303
|
+
if (this.provider.move) {
|
|
4304
|
+
const result = await this.provider.move(sessionId);
|
|
4305
|
+
this.logger?.info("Session moved successfully", { sessionId });
|
|
4306
|
+
return result;
|
|
4307
|
+
}
|
|
4308
|
+
throw new Error("Provider does not support move method");
|
|
4309
|
+
} catch (error) {
|
|
4310
|
+
this.logger?.error("Failed to move session", error);
|
|
4311
|
+
throw error;
|
|
4312
|
+
}
|
|
4313
|
+
},
|
|
3626
4314
|
initializeWorkspace: async (params) => {
|
|
3627
4315
|
this.logger?.debug("AgentClient.sessions.initializeWorkspace called", params);
|
|
3628
4316
|
try {
|
|
@@ -3775,6 +4463,36 @@ var AgentClient = class {
|
|
|
3775
4463
|
};
|
|
3776
4464
|
}
|
|
3777
4465
|
},
|
|
4466
|
+
batchTogglePlugins: async (request) => {
|
|
4467
|
+
try {
|
|
4468
|
+
if (this.provider && this.provider.batchTogglePlugins) {
|
|
4469
|
+
const result = await this.provider.batchTogglePlugins(request);
|
|
4470
|
+
this.logger?.info("Batch toggle plugins completed", {
|
|
4471
|
+
succeededCount: result.succeededPlugins.length,
|
|
4472
|
+
failedCount: result.failedPlugins.length
|
|
4473
|
+
});
|
|
4474
|
+
return result;
|
|
4475
|
+
}
|
|
4476
|
+
return {
|
|
4477
|
+
success: false,
|
|
4478
|
+
succeededPlugins: [],
|
|
4479
|
+
failedPlugins: request.items.map((item) => ({
|
|
4480
|
+
...item,
|
|
4481
|
+
error: "Provider does not support batchTogglePlugins"
|
|
4482
|
+
}))
|
|
4483
|
+
};
|
|
4484
|
+
} catch (error) {
|
|
4485
|
+
this.logger?.error("Failed to batch toggle plugins", error);
|
|
4486
|
+
return {
|
|
4487
|
+
success: false,
|
|
4488
|
+
succeededPlugins: [],
|
|
4489
|
+
failedPlugins: request.items.map((item) => ({
|
|
4490
|
+
...item,
|
|
4491
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
4492
|
+
}))
|
|
4493
|
+
};
|
|
4494
|
+
}
|
|
4495
|
+
},
|
|
3778
4496
|
models: this.createModelsResource()
|
|
3779
4497
|
};
|
|
3780
4498
|
}
|
|
@@ -3855,12 +4573,33 @@ const getSelectAccountUrl = () => `${window.location.origin}/login/select`;
|
|
|
3855
4573
|
/** localStorage 中存储选中账号 ID 的 key */
|
|
3856
4574
|
const SELECTED_ACCOUNT_KEY = "CODEBUDDY_IDE_SELECTED_ACCOUNT_ID";
|
|
3857
4575
|
/**
|
|
4576
|
+
* 套餐代码对应的 i18n key 映射
|
|
4577
|
+
*/
|
|
4578
|
+
const CommodityCodeText = {
|
|
4579
|
+
[CommodityCode.free]: "plan.codebuddyFreePlan",
|
|
4580
|
+
[CommodityCode.proMon]: "plan.codebuddyProPlanMonthly",
|
|
4581
|
+
[CommodityCode.proMonPlus]: "plan.codebuddyProPlanMonthly",
|
|
4582
|
+
[CommodityCode.gift]: "plan.codebuddyProPlanTrial",
|
|
4583
|
+
[CommodityCode.activity]: "plan.codebuddyGrowthPlan",
|
|
4584
|
+
[CommodityCode.proYear]: "plan.codebuddyProPlanYearly",
|
|
4585
|
+
[CommodityCode.freeMon]: "plan.codebuddyProPlanDaily",
|
|
4586
|
+
[CommodityCode.extra]: "plan.codebuddyCreditPackage"
|
|
4587
|
+
};
|
|
4588
|
+
/**
|
|
4589
|
+
* 获取套餐名称的 i18n key
|
|
4590
|
+
*/
|
|
4591
|
+
const getPackageName = (packageCode) => {
|
|
4592
|
+
return CommodityCodeText[packageCode] || "";
|
|
4593
|
+
};
|
|
4594
|
+
/**
|
|
3858
4595
|
* Backend Provider 实现类
|
|
3859
4596
|
*
|
|
3860
4597
|
* 职责:
|
|
3861
|
-
* - 与后端 API 通信(getAgents, getModels, getAccount 等)
|
|
3862
4598
|
* - 触发登录/登出流程
|
|
3863
4599
|
* - 获取 account 后自动同步到 accountService
|
|
4600
|
+
*
|
|
4601
|
+
* 注意:getAgents 和 getModels 方法已废弃并移除,
|
|
4602
|
+
* 请使用 IAgentAdapter 中的对应方法
|
|
3864
4603
|
*/
|
|
3865
4604
|
var BackendProvider = class {
|
|
3866
4605
|
constructor(config) {
|
|
@@ -3868,98 +4607,6 @@ var BackendProvider = class {
|
|
|
3868
4607
|
this.authToken = config.authToken;
|
|
3869
4608
|
}
|
|
3870
4609
|
/**
|
|
3871
|
-
* 获取 Agent 列表
|
|
3872
|
-
* API 端点: GET /v2/cloudagent/agentmgmt/agents
|
|
3873
|
-
*/
|
|
3874
|
-
async getAgents(request = {}) {
|
|
3875
|
-
const { MockAgentProvider } = await Promise.resolve().then(() => require("./MockAgentProvider-4e4oOusg.cjs"));
|
|
3876
|
-
const sessions = new MockAgentProvider().getAllSessions();
|
|
3877
|
-
const mockTitles = {
|
|
3878
|
-
"1": "开发五子棋游戏",
|
|
3879
|
-
"2": "修复登录页面样式",
|
|
3880
|
-
"3": "API 接口优化"
|
|
3881
|
-
};
|
|
3882
|
-
const agents = sessions.map((session, index) => ({
|
|
3883
|
-
id: session.sessionId,
|
|
3884
|
-
name: mockTitles[session.sessionId] || `Agent ${session.sessionId}`,
|
|
3885
|
-
status: "RUNNING",
|
|
3886
|
-
visibility: "PRIVATE",
|
|
3887
|
-
createdAt: new Date(session.createdAt).toISOString(),
|
|
3888
|
-
summary: `Session created at ${new Date(session.createdAt).toLocaleString()}`,
|
|
3889
|
-
source: {
|
|
3890
|
-
provider: "github",
|
|
3891
|
-
ref: "refs/heads/main",
|
|
3892
|
-
repository: session.cwd
|
|
3893
|
-
},
|
|
3894
|
-
target: {
|
|
3895
|
-
autoCreatePr: false,
|
|
3896
|
-
branchName: "feature/mock",
|
|
3897
|
-
prUrl: void 0,
|
|
3898
|
-
url: void 0
|
|
3899
|
-
}
|
|
3900
|
-
}));
|
|
3901
|
-
return {
|
|
3902
|
-
agents,
|
|
3903
|
-
pagination: {
|
|
3904
|
-
hasNext: false,
|
|
3905
|
-
hasPrev: false,
|
|
3906
|
-
page: 1,
|
|
3907
|
-
size: agents.length,
|
|
3908
|
-
total: agents.length,
|
|
3909
|
-
totalPages: 1
|
|
3910
|
-
}
|
|
3911
|
-
};
|
|
3912
|
-
}
|
|
3913
|
-
/**
|
|
3914
|
-
* 获取可用模型列表
|
|
3915
|
-
* API 端点: GET /v2/cloudagent/models (假设)
|
|
3916
|
-
*
|
|
3917
|
-
* 当前实现: 返回 Mock 数据
|
|
3918
|
-
*/
|
|
3919
|
-
async getModels(request) {
|
|
3920
|
-
const mockModels = [{
|
|
3921
|
-
id: "glm-4.7",
|
|
3922
|
-
name: "GLM-4.7",
|
|
3923
|
-
vendor: "f",
|
|
3924
|
-
maxOutputTokens: 48e3,
|
|
3925
|
-
maxInputTokens: 2e5,
|
|
3926
|
-
supportsToolCall: true,
|
|
3927
|
-
supportsImages: false,
|
|
3928
|
-
disabledMultimodal: true,
|
|
3929
|
-
maxAllowedSize: 2e5,
|
|
3930
|
-
supportsReasoning: true,
|
|
3931
|
-
onlyReasoning: true,
|
|
3932
|
-
temperature: 1,
|
|
3933
|
-
reasoning: {
|
|
3934
|
-
effort: "medium",
|
|
3935
|
-
summary: "auto"
|
|
3936
|
-
},
|
|
3937
|
-
descriptionEn: "GLM-4.7 model, Well-rounded model for everyday use",
|
|
3938
|
-
descriptionZh: "GLM-4.7 大模型,能力均衡,适合日常使用"
|
|
3939
|
-
}, {
|
|
3940
|
-
id: "glm-4.7-flash",
|
|
3941
|
-
name: "GLM-4.7 Flash",
|
|
3942
|
-
vendor: "f",
|
|
3943
|
-
maxOutputTokens: 4e4,
|
|
3944
|
-
maxInputTokens: 128e3,
|
|
3945
|
-
supportsToolCall: true,
|
|
3946
|
-
supportsImages: false,
|
|
3947
|
-
disabledMultimodal: false,
|
|
3948
|
-
maxAllowedSize: 128e3,
|
|
3949
|
-
supportsReasoning: false,
|
|
3950
|
-
onlyReasoning: false,
|
|
3951
|
-
temperature: .7,
|
|
3952
|
-
reasoning: {
|
|
3953
|
-
effort: "low",
|
|
3954
|
-
summary: "never"
|
|
3955
|
-
},
|
|
3956
|
-
descriptionEn: "GLM-4.7 Flash, Fast and efficient model",
|
|
3957
|
-
descriptionZh: "GLM-4.7 Flash,快速高效的模型"
|
|
3958
|
-
}];
|
|
3959
|
-
console.log("[BackendProvider] getModels called for repository:", request.repository);
|
|
3960
|
-
return { models: mockModels };
|
|
3961
|
-
}
|
|
3962
|
-
/**
|
|
3963
4610
|
* 获取当前账号信息
|
|
3964
4611
|
* API 端点: GET /console/accounts (返回账号列表)
|
|
3965
4612
|
*
|
|
@@ -4010,53 +4657,335 @@ var BackendProvider = class {
|
|
|
4010
4657
|
if (account.type === "personal") return account.uid === selectedAccountId;
|
|
4011
4658
|
return account.enterpriseId === selectedAccountId;
|
|
4012
4659
|
});
|
|
4013
|
-
if (selectedAccount)
|
|
4014
|
-
const
|
|
4015
|
-
const editionType = this.getEditionDisplayType(selectedAccount.type, plan.isPro);
|
|
4016
|
-
console.log("account", {
|
|
4017
|
-
...selectedAccount,
|
|
4018
|
-
...plan,
|
|
4019
|
-
editionType
|
|
4020
|
-
});
|
|
4021
|
-
const account = {
|
|
4022
|
-
...selectedAccount,
|
|
4023
|
-
...plan,
|
|
4024
|
-
editionType
|
|
4025
|
-
};
|
|
4660
|
+
if (selectedAccount) {
|
|
4661
|
+
const account = await this.enrichAccountWithUsage(selectedAccount);
|
|
4026
4662
|
accountService.setAccount(account);
|
|
4027
4663
|
return account;
|
|
4028
|
-
} catch (error) {
|
|
4029
|
-
accountService.setAccount(selectedAccount);
|
|
4030
|
-
return { ...selectedAccount };
|
|
4031
4664
|
}
|
|
4032
4665
|
}
|
|
4033
4666
|
if (accounts.length === 1) {
|
|
4034
4667
|
selectedAccount = accounts[0];
|
|
4035
4668
|
const accountId = selectedAccount.type === "personal" ? selectedAccount.uid : selectedAccount.enterpriseId;
|
|
4036
4669
|
if (accountId) localStorage.setItem(SELECTED_ACCOUNT_KEY, accountId);
|
|
4670
|
+
const account = await this.enrichAccountWithUsage(selectedAccount);
|
|
4671
|
+
console.log("account (auto-selected)", account);
|
|
4672
|
+
accountService.setAccount(account);
|
|
4673
|
+
return account;
|
|
4674
|
+
}
|
|
4675
|
+
const redirectUrl = encodeURIComponent(window.location.href);
|
|
4676
|
+
window.location.href = `${getSelectAccountUrl()}?platform=website&state=0&redirect_uri=${redirectUrl}`;
|
|
4677
|
+
accountService.setAccount(null);
|
|
4678
|
+
return null;
|
|
4679
|
+
} catch (error) {
|
|
4680
|
+
console.error("[BackendProvider] getAccount failed:", error);
|
|
4681
|
+
accountService.setAccount(null);
|
|
4682
|
+
return null;
|
|
4683
|
+
}
|
|
4684
|
+
}
|
|
4685
|
+
/**
|
|
4686
|
+
* 获取用户连接器列表
|
|
4687
|
+
* API 端点: GET /console/as/connector/user/
|
|
4688
|
+
*/
|
|
4689
|
+
async getUserConnector() {
|
|
4690
|
+
const url = `${this.baseUrl}/console/as/connector/user/`;
|
|
4691
|
+
const headers = {
|
|
4692
|
+
"Content-Type": "application/json",
|
|
4693
|
+
"Accept": "application/json"
|
|
4694
|
+
};
|
|
4695
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4696
|
+
try {
|
|
4697
|
+
const result = await (await fetch(url, {
|
|
4698
|
+
method: "GET",
|
|
4699
|
+
headers,
|
|
4700
|
+
credentials: "include"
|
|
4701
|
+
})).json();
|
|
4702
|
+
if (result.code === 0) {
|
|
4703
|
+
const { connectors } = result.data;
|
|
4704
|
+
return { connectors: connectors.map((connector) => ({
|
|
4705
|
+
...connector,
|
|
4706
|
+
connectStatus: connector.connect_status,
|
|
4707
|
+
activeStatus: connector.active_status,
|
|
4708
|
+
displayName: connector.display_name,
|
|
4709
|
+
oauthClientId: connector.oauth_client_id,
|
|
4710
|
+
oauthRedirectUrl: connector.oauth_redirect_url
|
|
4711
|
+
})) };
|
|
4712
|
+
}
|
|
4713
|
+
throw result;
|
|
4714
|
+
} catch (error) {
|
|
4715
|
+
throw error;
|
|
4716
|
+
}
|
|
4717
|
+
}
|
|
4718
|
+
/**
|
|
4719
|
+
* 修改用户连接器连接状态
|
|
4720
|
+
* API 端点: PATCH /console/as/connector/user/:name/connect_status
|
|
4721
|
+
*/
|
|
4722
|
+
async modifyUserConnectorConnectStatus(request) {
|
|
4723
|
+
const url = `${this.baseUrl}/console/as/connector/user/${request.name}/connect_status`;
|
|
4724
|
+
const headers = {
|
|
4725
|
+
"Content-Type": "application/json",
|
|
4726
|
+
"Accept": "application/json"
|
|
4727
|
+
};
|
|
4728
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4729
|
+
const body = {
|
|
4730
|
+
name: request.name,
|
|
4731
|
+
connect_status: request.connectStatus
|
|
4732
|
+
};
|
|
4733
|
+
if (request.activeStatus !== void 0) body.active_status = request.activeStatus;
|
|
4734
|
+
if (request.repos !== void 0) body.repos = request.repos;
|
|
4735
|
+
try {
|
|
4736
|
+
const result = await (await fetch(url, {
|
|
4737
|
+
method: "PATCH",
|
|
4738
|
+
headers,
|
|
4739
|
+
credentials: "include",
|
|
4740
|
+
body: JSON.stringify(body)
|
|
4741
|
+
})).json();
|
|
4742
|
+
if (result.code === 0) return;
|
|
4743
|
+
throw result;
|
|
4744
|
+
} catch (error) {
|
|
4745
|
+
throw error;
|
|
4746
|
+
}
|
|
4747
|
+
}
|
|
4748
|
+
/**
|
|
4749
|
+
* 修改用户连接器仓库
|
|
4750
|
+
* API 端点: PATCH /console/as/connector/user/:name/repo/
|
|
4751
|
+
*/
|
|
4752
|
+
async modifyUserConnectorRepo(request) {
|
|
4753
|
+
const url = `${this.baseUrl}/console/as/connector/user/${request.name}/repo`;
|
|
4754
|
+
const headers = {
|
|
4755
|
+
"Content-Type": "application/json",
|
|
4756
|
+
"Accept": "application/json"
|
|
4757
|
+
};
|
|
4758
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4759
|
+
const body = { name: request.name };
|
|
4760
|
+
if (request.repo !== void 0) body.repo = request.repo;
|
|
4761
|
+
try {
|
|
4762
|
+
const result = await (await fetch(url, {
|
|
4763
|
+
method: "PATCH",
|
|
4764
|
+
headers,
|
|
4765
|
+
credentials: "include",
|
|
4766
|
+
body: JSON.stringify(body)
|
|
4767
|
+
})).json();
|
|
4768
|
+
if (result.code === 0) return;
|
|
4769
|
+
throw result;
|
|
4770
|
+
} catch (error) {
|
|
4771
|
+
throw error;
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
/**
|
|
4775
|
+
* 修改用户连接器激活状态
|
|
4776
|
+
* API 端点: PATCH /console/as/connector/user/:name/active_status
|
|
4777
|
+
*/
|
|
4778
|
+
async modifyUserConnectorActiveStatus(request) {
|
|
4779
|
+
const url = `${this.baseUrl}/console/as/connector/user/${request.name}/active_status`;
|
|
4780
|
+
const headers = {
|
|
4781
|
+
"Content-Type": "application/json",
|
|
4782
|
+
"Accept": "application/json"
|
|
4783
|
+
};
|
|
4784
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4785
|
+
const body = {
|
|
4786
|
+
name: request.name,
|
|
4787
|
+
active_status: request.activeStatus
|
|
4788
|
+
};
|
|
4789
|
+
try {
|
|
4790
|
+
const result = await (await fetch(url, {
|
|
4791
|
+
method: "PATCH",
|
|
4792
|
+
headers,
|
|
4793
|
+
credentials: "include",
|
|
4794
|
+
body: JSON.stringify(body)
|
|
4795
|
+
})).json();
|
|
4796
|
+
if (result.code === 0) return;
|
|
4797
|
+
throw result;
|
|
4798
|
+
} catch (error) {
|
|
4799
|
+
throw error;
|
|
4800
|
+
}
|
|
4801
|
+
}
|
|
4802
|
+
/**
|
|
4803
|
+
* 删除用户连接器
|
|
4804
|
+
* API 端点: DELETE /console/as/connector/user/:name/
|
|
4805
|
+
*/
|
|
4806
|
+
async deleteUserConnector(name) {
|
|
4807
|
+
const url = `${this.baseUrl}/console/as/connector/user/${name}/`;
|
|
4808
|
+
const headers = {
|
|
4809
|
+
"Content-Type": "application/json",
|
|
4810
|
+
"Accept": "application/json"
|
|
4811
|
+
};
|
|
4812
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4813
|
+
try {
|
|
4814
|
+
const result = await (await fetch(url, {
|
|
4815
|
+
method: "DELETE",
|
|
4816
|
+
headers,
|
|
4817
|
+
credentials: "include"
|
|
4818
|
+
})).json();
|
|
4819
|
+
if (result.code === 0) return;
|
|
4820
|
+
throw result;
|
|
4821
|
+
} catch (error) {
|
|
4822
|
+
throw error;
|
|
4823
|
+
}
|
|
4824
|
+
}
|
|
4825
|
+
/**
|
|
4826
|
+
* 添加任务
|
|
4827
|
+
* API 端点: POST /console/as/connector/task/
|
|
4828
|
+
*/
|
|
4829
|
+
async addConnectorTask(request) {
|
|
4830
|
+
const url = `${this.baseUrl}/console/as/connector/task/`;
|
|
4831
|
+
const headers = {
|
|
4832
|
+
"Content-Type": "application/json",
|
|
4833
|
+
"Accept": "application/json"
|
|
4834
|
+
};
|
|
4835
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4836
|
+
const body = { task_id: request.taskId };
|
|
4837
|
+
if (request.connectors !== void 0) body.connectors = request.connectors.map((c) => ({
|
|
4838
|
+
name: c.name,
|
|
4839
|
+
repos: c.repos,
|
|
4840
|
+
active_status: c.activeStatus
|
|
4841
|
+
}));
|
|
4842
|
+
try {
|
|
4843
|
+
const result = await (await fetch(url, {
|
|
4844
|
+
method: "POST",
|
|
4845
|
+
headers,
|
|
4846
|
+
credentials: "include",
|
|
4847
|
+
body: JSON.stringify(body)
|
|
4848
|
+
})).json();
|
|
4849
|
+
if (result.code === 0) return { taskId: result.data?.task_id || request.taskId };
|
|
4850
|
+
throw result;
|
|
4851
|
+
} catch (error) {
|
|
4852
|
+
throw error;
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4855
|
+
/**
|
|
4856
|
+
* 获取任务连接器列表
|
|
4857
|
+
* API 端点: GET /console/as/connector/task/:taskid
|
|
4858
|
+
*/
|
|
4859
|
+
async getTaskConnector(taskId) {
|
|
4860
|
+
const url = `${this.baseUrl}/console/as/connector/task/${taskId}`;
|
|
4861
|
+
const headers = {
|
|
4862
|
+
"Content-Type": "application/json",
|
|
4863
|
+
"Accept": "application/json"
|
|
4864
|
+
};
|
|
4865
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4866
|
+
try {
|
|
4867
|
+
const result = await (await fetch(url, {
|
|
4868
|
+
method: "GET",
|
|
4869
|
+
headers,
|
|
4870
|
+
credentials: "include"
|
|
4871
|
+
})).json();
|
|
4872
|
+
if (result.code === 0) {
|
|
4873
|
+
const { connectors } = result.data;
|
|
4874
|
+
return { connectors: (connectors || []).map((connector) => ({
|
|
4875
|
+
...connector,
|
|
4876
|
+
activeStatus: connector.active_status,
|
|
4877
|
+
connectStatus: connector.connect_status,
|
|
4878
|
+
displayName: connector.display_name,
|
|
4879
|
+
oauthClientId: connector.oauth_client_id,
|
|
4880
|
+
oauthRedirectUrl: connector.oauth_redirect_url
|
|
4881
|
+
})) };
|
|
4882
|
+
}
|
|
4883
|
+
throw result;
|
|
4884
|
+
} catch (error) {
|
|
4885
|
+
throw error;
|
|
4886
|
+
}
|
|
4887
|
+
}
|
|
4888
|
+
/**
|
|
4889
|
+
* 修改任务连接器激活状态
|
|
4890
|
+
* API 端点: PATCH /console/as/connector/task/:taskid/active_status
|
|
4891
|
+
*/
|
|
4892
|
+
async modifyTaskConnectorActiveStatus(request) {
|
|
4893
|
+
const url = `${this.baseUrl}/console/as/connector/task/${request.taskId}/active_status`;
|
|
4894
|
+
const headers = {
|
|
4895
|
+
"Content-Type": "application/json",
|
|
4896
|
+
"Accept": "application/json"
|
|
4897
|
+
};
|
|
4898
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4899
|
+
const body = {
|
|
4900
|
+
task_id: request.taskId,
|
|
4901
|
+
name: request.name,
|
|
4902
|
+
active_status: request.activeStatus
|
|
4903
|
+
};
|
|
4904
|
+
try {
|
|
4905
|
+
const result = await (await fetch(url, {
|
|
4906
|
+
method: "PATCH",
|
|
4907
|
+
headers,
|
|
4908
|
+
credentials: "include",
|
|
4909
|
+
body: JSON.stringify(body)
|
|
4910
|
+
})).json();
|
|
4911
|
+
if (result.code === 0) return { taskId: result.data?.task_id || request.taskId };
|
|
4912
|
+
throw result;
|
|
4913
|
+
} catch (error) {
|
|
4914
|
+
throw error;
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
/**
|
|
4918
|
+
* 修改任务连接器仓库
|
|
4919
|
+
* API 端点: PATCH /console/as/connector/task/:taskid/repo
|
|
4920
|
+
*/
|
|
4921
|
+
async modifyTaskConnectorRepo(request) {
|
|
4922
|
+
const url = `${this.baseUrl}/console/as/connector/task/${request.taskId}/repo`;
|
|
4923
|
+
const headers = {
|
|
4924
|
+
"Content-Type": "application/json",
|
|
4925
|
+
"Accept": "application/json"
|
|
4926
|
+
};
|
|
4927
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4928
|
+
const body = {
|
|
4929
|
+
task_id: request.taskId,
|
|
4930
|
+
name: request.name,
|
|
4931
|
+
repo: request.repo
|
|
4932
|
+
};
|
|
4933
|
+
try {
|
|
4934
|
+
const result = await (await fetch(url, {
|
|
4935
|
+
method: "PATCH",
|
|
4936
|
+
headers,
|
|
4937
|
+
credentials: "include",
|
|
4938
|
+
body: JSON.stringify(body)
|
|
4939
|
+
})).json();
|
|
4940
|
+
if (result.code === 0) return { taskId: result.data?.task_id || request.taskId };
|
|
4941
|
+
throw result;
|
|
4942
|
+
} catch (error) {
|
|
4943
|
+
throw error;
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4946
|
+
/**
|
|
4947
|
+
* 根据账号类型获取用量信息并合并到账号中
|
|
4948
|
+
* - 企业用户:调用 getEnterpriseUsage 获取月度限额
|
|
4949
|
+
* - 个人用户:调用 getCurrentPlan 获取套餐信息
|
|
4950
|
+
*/
|
|
4951
|
+
async enrichAccountWithUsage(selectedAccount) {
|
|
4952
|
+
const isEnterpriseUser = !!(selectedAccount.enterpriseId && selectedAccount.enterpriseId !== "");
|
|
4953
|
+
try {
|
|
4954
|
+
if (isEnterpriseUser) {
|
|
4955
|
+
const enterpriseUsage = await this.getEnterpriseUsage(selectedAccount.enterpriseId);
|
|
4956
|
+
const editionType = this.getEditionDisplayType(selectedAccount.type, false);
|
|
4957
|
+
if (enterpriseUsage) {
|
|
4958
|
+
const usageLeft = (enterpriseUsage.limitNum - enterpriseUsage.credit).toString();
|
|
4959
|
+
const usageTotal = enterpriseUsage.limitNum.toString();
|
|
4960
|
+
return {
|
|
4961
|
+
...selectedAccount,
|
|
4962
|
+
editionType,
|
|
4963
|
+
usageLeft,
|
|
4964
|
+
usageTotal,
|
|
4965
|
+
refreshAt: enterpriseUsage.cycleResetTime ? new Date(enterpriseUsage.cycleResetTime).getTime() : void 0
|
|
4966
|
+
};
|
|
4967
|
+
}
|
|
4968
|
+
return {
|
|
4969
|
+
...selectedAccount,
|
|
4970
|
+
editionType
|
|
4971
|
+
};
|
|
4972
|
+
} else {
|
|
4037
4973
|
const plan = await this.getCurrentPlan();
|
|
4038
4974
|
const editionType = this.getEditionDisplayType(selectedAccount.type, plan.isPro);
|
|
4039
|
-
console.log("account
|
|
4975
|
+
console.log("account", {
|
|
4040
4976
|
...selectedAccount,
|
|
4041
4977
|
...plan,
|
|
4042
4978
|
editionType
|
|
4043
4979
|
});
|
|
4044
|
-
|
|
4980
|
+
return {
|
|
4045
4981
|
...selectedAccount,
|
|
4046
4982
|
...plan,
|
|
4047
4983
|
editionType
|
|
4048
4984
|
};
|
|
4049
|
-
accountService.setAccount(account);
|
|
4050
|
-
return account;
|
|
4051
4985
|
}
|
|
4052
|
-
const redirectUrl = encodeURIComponent(window.location.href);
|
|
4053
|
-
window.location.href = `${getSelectAccountUrl()}?platform=website&state=0&redirect_uri=${redirectUrl}`;
|
|
4054
|
-
accountService.setAccount(null);
|
|
4055
|
-
return null;
|
|
4056
4986
|
} catch (error) {
|
|
4057
|
-
console.error("[BackendProvider]
|
|
4058
|
-
|
|
4059
|
-
return null;
|
|
4987
|
+
console.error("[BackendProvider] enrichAccountWithUsage failed:", error);
|
|
4988
|
+
return { ...selectedAccount };
|
|
4060
4989
|
}
|
|
4061
4990
|
}
|
|
4062
4991
|
/**
|
|
@@ -4078,7 +5007,6 @@ var BackendProvider = class {
|
|
|
4078
5007
|
"Content-Type": "application/json",
|
|
4079
5008
|
"Accept": "application/json"
|
|
4080
5009
|
};
|
|
4081
|
-
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
4082
5010
|
const now = /* @__PURE__ */ new Date();
|
|
4083
5011
|
const futureDate = new Date(now.getTime() + 101 * 365 * 24 * 60 * 60 * 1e3);
|
|
4084
5012
|
const formatDate = (d) => {
|
|
@@ -4105,34 +5033,174 @@ var BackendProvider = class {
|
|
|
4105
5033
|
}
|
|
4106
5034
|
const resources = (await response.json())?.data?.Response?.Data?.Accounts || [];
|
|
4107
5035
|
if (!resources || resources.length === 0) return defaultPlan;
|
|
5036
|
+
const parseTime = (time) => {
|
|
5037
|
+
if (!time) return 0;
|
|
5038
|
+
return new Date(time).getTime();
|
|
5039
|
+
};
|
|
5040
|
+
const dailyCredits = [CommodityCode.free, CommodityCode.freeMon];
|
|
5041
|
+
const planResources = resources.map((r) => {
|
|
5042
|
+
const isDaily = dailyCredits.includes(r.PackageCode);
|
|
5043
|
+
const endTime = isDaily ? r.CycleEndTime : r.DeductionEndTime;
|
|
5044
|
+
return {
|
|
5045
|
+
id: r.ResourceId,
|
|
5046
|
+
name: isDaily ? "plan.addonCredits" : getPackageName(r.PackageCode),
|
|
5047
|
+
packageCode: r.PackageCode,
|
|
5048
|
+
isDaily,
|
|
5049
|
+
total: Number(r.CycleCapacitySizePrecise) || 0,
|
|
5050
|
+
used: Math.max(0, Number(r.CycleCapacitySizePrecise) - Number(r.CycleCapacityRemainPrecise)) || 0,
|
|
5051
|
+
left: Number(r.CycleCapacityRemainPrecise) || 0,
|
|
5052
|
+
expireAt: parseTime(endTime),
|
|
5053
|
+
refreshAt: isDaily ? void 0 : parseTime(r.CycleEndTime)
|
|
5054
|
+
};
|
|
5055
|
+
}).sort((a, b) => {
|
|
5056
|
+
const getPriority = (code) => {
|
|
5057
|
+
if ([
|
|
5058
|
+
CommodityCode.proMon,
|
|
5059
|
+
CommodityCode.proMonPlus,
|
|
5060
|
+
CommodityCode.proYear,
|
|
5061
|
+
CommodityCode.extra
|
|
5062
|
+
].includes(code)) return 1;
|
|
5063
|
+
if ([CommodityCode.gift, CommodityCode.activity].includes(code)) return 2;
|
|
5064
|
+
if ([CommodityCode.free, CommodityCode.freeMon].includes(code)) return 3;
|
|
5065
|
+
return 4;
|
|
5066
|
+
};
|
|
5067
|
+
return getPriority(a.packageCode) - getPriority(b.packageCode);
|
|
5068
|
+
});
|
|
4108
5069
|
const proPlan = resources.find((r) => r.PackageCode === CommodityCode.proYear || r.PackageCode === CommodityCode.proMon || r.PackageCode === CommodityCode.proMonPlus);
|
|
4109
5070
|
const trialPlan = resources.find((r) => r.PackageCode === CommodityCode.gift || r.PackageCode === CommodityCode.freeMon);
|
|
4110
5071
|
const activePlan = proPlan || trialPlan;
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
5072
|
+
const totalUsageLeft = planResources.reduce((sum, r) => sum + r.left, 0);
|
|
5073
|
+
const totalUsageTotal = planResources.reduce((sum, r) => sum + r.total, 0);
|
|
5074
|
+
const totalUsageUsed = planResources.reduce((sum, r) => sum + r.used, 0);
|
|
5075
|
+
if (activePlan) return {
|
|
5076
|
+
isPro: !!proPlan,
|
|
5077
|
+
isTria: trialPlan ? [AccountStatus.valid, AccountStatus.usedUp].includes(trialPlan.Status) : false,
|
|
5078
|
+
expireAt: parseTime(activePlan.DeductionEndTime || activePlan.ExpiredTime || activePlan.CycleEndTime),
|
|
5079
|
+
refreshAt: parseTime(activePlan.CycleEndTime),
|
|
5080
|
+
renewFlag: Number(activePlan.AutoRenewFlag) === 1 ? 1 : 0,
|
|
5081
|
+
PackageCode: activePlan.PackageCode,
|
|
5082
|
+
name: getPackageName(activePlan.PackageCode),
|
|
5083
|
+
usageTotal: String(totalUsageTotal),
|
|
5084
|
+
usageUsed: String(totalUsageUsed),
|
|
5085
|
+
usageLeft: String(totalUsageLeft),
|
|
5086
|
+
resources: planResources
|
|
5087
|
+
};
|
|
5088
|
+
return {
|
|
5089
|
+
...defaultPlan,
|
|
5090
|
+
usageTotal: String(totalUsageTotal),
|
|
5091
|
+
usageUsed: String(totalUsageUsed),
|
|
5092
|
+
usageLeft: String(totalUsageLeft),
|
|
5093
|
+
resources: planResources
|
|
5094
|
+
};
|
|
4130
5095
|
} catch (error) {
|
|
4131
5096
|
console.error("[BackendProvider] getCurrentPlan error:", error);
|
|
4132
5097
|
return defaultPlan;
|
|
4133
5098
|
}
|
|
4134
5099
|
}
|
|
4135
5100
|
/**
|
|
5101
|
+
* 通过回调code,换token
|
|
5102
|
+
* @param request
|
|
5103
|
+
* @returns
|
|
5104
|
+
*/
|
|
5105
|
+
async saveOauthToken(request) {
|
|
5106
|
+
const url = `${this.baseUrl}/console/as/connector/oauth/${request.name}/connect`;
|
|
5107
|
+
const headers = {
|
|
5108
|
+
"Content-Type": "application/json",
|
|
5109
|
+
"Accept": "application/json"
|
|
5110
|
+
};
|
|
5111
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
5112
|
+
const body = { authorization_code: request.authorizationCode };
|
|
5113
|
+
try {
|
|
5114
|
+
const result = await (await fetch(url, {
|
|
5115
|
+
method: "POST",
|
|
5116
|
+
headers,
|
|
5117
|
+
credentials: "include",
|
|
5118
|
+
body: JSON.stringify(body)
|
|
5119
|
+
})).json();
|
|
5120
|
+
if (result.code === 0) return;
|
|
5121
|
+
throw result;
|
|
5122
|
+
} catch (error) {
|
|
5123
|
+
throw error;
|
|
5124
|
+
}
|
|
5125
|
+
}
|
|
5126
|
+
/**
|
|
5127
|
+
* 获取OAuth连接器的仓库列表
|
|
5128
|
+
*/
|
|
5129
|
+
async getRepoList(request) {
|
|
5130
|
+
const url = `${this.baseUrl}/console/as/connector/oauth/${request.name}/repos`;
|
|
5131
|
+
const headers = {
|
|
5132
|
+
"Content-Type": "application/json",
|
|
5133
|
+
"Accept": "application/json"
|
|
5134
|
+
};
|
|
5135
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
5136
|
+
try {
|
|
5137
|
+
const result = await (await fetch(url, {
|
|
5138
|
+
method: "GET",
|
|
5139
|
+
headers,
|
|
5140
|
+
credentials: "include"
|
|
5141
|
+
})).json();
|
|
5142
|
+
if (result.code === 0) return result.data;
|
|
5143
|
+
throw result;
|
|
5144
|
+
} catch (error) {
|
|
5145
|
+
throw error;
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
/**
|
|
5149
|
+
* 撤销OAuth连接器的所有连接
|
|
5150
|
+
*/
|
|
5151
|
+
async revokeAll(request) {
|
|
5152
|
+
const url = `${this.baseUrl}/console/as/connector/oauth/${request.name}/revokeall`;
|
|
5153
|
+
const installationIds = request?.installationIds ?? [];
|
|
5154
|
+
const headers = {
|
|
5155
|
+
"Content-Type": "application/json",
|
|
5156
|
+
"Accept": "application/json"
|
|
5157
|
+
};
|
|
5158
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
5159
|
+
const body = { name: request.name };
|
|
5160
|
+
if (installationIds) body.installation_ids = installationIds;
|
|
5161
|
+
try {
|
|
5162
|
+
const result = await (await fetch(url, {
|
|
5163
|
+
method: "POST",
|
|
5164
|
+
headers,
|
|
5165
|
+
credentials: "include",
|
|
5166
|
+
body: JSON.stringify(body)
|
|
5167
|
+
})).json();
|
|
5168
|
+
if (result.code === 0) return;
|
|
5169
|
+
throw result;
|
|
5170
|
+
} catch (error) {
|
|
5171
|
+
throw error;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
/**
|
|
5175
|
+
* 获取 OAuth 用户信息
|
|
5176
|
+
* API 端点: GET /console/as/connector/oauth/:name/oauthuser
|
|
5177
|
+
*/
|
|
5178
|
+
async getOauthUser(request) {
|
|
5179
|
+
const url = `${this.baseUrl}/console/as/connector/oauth/${request.name}/oauthuser`;
|
|
5180
|
+
const headers = {
|
|
5181
|
+
"Content-Type": "application/json",
|
|
5182
|
+
"Accept": "application/json"
|
|
5183
|
+
};
|
|
5184
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
5185
|
+
try {
|
|
5186
|
+
const result = await (await fetch(url, {
|
|
5187
|
+
method: "GET",
|
|
5188
|
+
headers,
|
|
5189
|
+
credentials: "include"
|
|
5190
|
+
})).json();
|
|
5191
|
+
if (result.code === 0) {
|
|
5192
|
+
const data = result.data || {};
|
|
5193
|
+
return { user: {
|
|
5194
|
+
avatarUrl: data.user?.avatar_url || "",
|
|
5195
|
+
name: data.user?.name || ""
|
|
5196
|
+
} };
|
|
5197
|
+
}
|
|
5198
|
+
throw result;
|
|
5199
|
+
} catch (error) {
|
|
5200
|
+
throw error;
|
|
5201
|
+
}
|
|
5202
|
+
}
|
|
5203
|
+
/**
|
|
4136
5204
|
* 根据账号类型和 Pro 状态计算版本展示类型
|
|
4137
5205
|
* - personal + isPro = 'pro'
|
|
4138
5206
|
* - personal + !isPro = 'free'
|
|
@@ -4155,14 +5223,28 @@ var BackendProvider = class {
|
|
|
4155
5223
|
}
|
|
4156
5224
|
/**
|
|
4157
5225
|
* 登出账号
|
|
4158
|
-
* Web 环境:
|
|
5226
|
+
* Web 环境: 通过 iframe 访问登出 URL 清除 cookie
|
|
4159
5227
|
*/
|
|
4160
5228
|
async logout() {
|
|
4161
5229
|
const url = `${this.baseUrl}/console/logout`;
|
|
4162
5230
|
try {
|
|
4163
|
-
await
|
|
4164
|
-
|
|
4165
|
-
|
|
5231
|
+
await new Promise((resolve) => {
|
|
5232
|
+
const iframe = document.createElement("iframe");
|
|
5233
|
+
iframe.style.cssText = "position:fixed;top:-9999px;left:-9999px;width:1px;height:1px;border:none;";
|
|
5234
|
+
iframe.src = url;
|
|
5235
|
+
const timeout = setTimeout(() => {
|
|
5236
|
+
cleanup();
|
|
5237
|
+
resolve();
|
|
5238
|
+
}, 5e3);
|
|
5239
|
+
const cleanup = () => {
|
|
5240
|
+
clearTimeout(timeout);
|
|
5241
|
+
if (iframe.parentNode) iframe.parentNode.removeChild(iframe);
|
|
5242
|
+
};
|
|
5243
|
+
iframe.onerror = () => {
|
|
5244
|
+
cleanup();
|
|
5245
|
+
resolve();
|
|
5246
|
+
};
|
|
5247
|
+
document.body.appendChild(iframe);
|
|
4166
5248
|
});
|
|
4167
5249
|
} catch (error) {
|
|
4168
5250
|
console.error("[BackendProvider] logout failed:", error);
|
|
@@ -4170,6 +5252,54 @@ var BackendProvider = class {
|
|
|
4170
5252
|
localStorage.removeItem(SELECTED_ACCOUNT_KEY);
|
|
4171
5253
|
accountService.clearAccount();
|
|
4172
5254
|
}
|
|
5255
|
+
/**
|
|
5256
|
+
* 批量切换插件状态
|
|
5257
|
+
* Web 环境不支持此功能
|
|
5258
|
+
*/
|
|
5259
|
+
async batchTogglePlugins(request) {
|
|
5260
|
+
console.warn("[BackendProvider] batchTogglePlugins is not supported in web environment");
|
|
5261
|
+
return {
|
|
5262
|
+
success: false,
|
|
5263
|
+
succeededPlugins: [],
|
|
5264
|
+
failedPlugins: request.items.map((item) => ({
|
|
5265
|
+
...item,
|
|
5266
|
+
error: "Plugin batch toggle is not supported in web environment"
|
|
5267
|
+
}))
|
|
5268
|
+
};
|
|
5269
|
+
}
|
|
5270
|
+
/**
|
|
5271
|
+
* 获取企业用户用量信息
|
|
5272
|
+
* API: POST /billing/meter/get-enterprise-user-usage
|
|
5273
|
+
* 构建查询参数字符串
|
|
5274
|
+
*/
|
|
5275
|
+
async getEnterpriseUsage(enterpriseId) {
|
|
5276
|
+
try {
|
|
5277
|
+
const url = `${this.baseUrl}/billing/meter/get-enterprise-user-usage`;
|
|
5278
|
+
const headers = {
|
|
5279
|
+
"Content-Type": "application/json",
|
|
5280
|
+
"Accept": "application/json",
|
|
5281
|
+
"X-Enterprise-Id": enterpriseId
|
|
5282
|
+
};
|
|
5283
|
+
if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
5284
|
+
const response = await fetch(url, {
|
|
5285
|
+
method: "POST",
|
|
5286
|
+
headers,
|
|
5287
|
+
credentials: "include",
|
|
5288
|
+
body: JSON.stringify({})
|
|
5289
|
+
});
|
|
5290
|
+
if (!response.ok) {
|
|
5291
|
+
console.warn("[BackendProvider] getEnterpriseUsage failed:", response.status);
|
|
5292
|
+
return null;
|
|
5293
|
+
}
|
|
5294
|
+
const result = await response.json();
|
|
5295
|
+
const usageData = result?.data?.data || result?.data || result;
|
|
5296
|
+
if (usageData && typeof usageData.limitNum === "number") return usageData;
|
|
5297
|
+
return null;
|
|
5298
|
+
} catch (error) {
|
|
5299
|
+
console.error("[BackendProvider] getEnterpriseUsage error:", error);
|
|
5300
|
+
return null;
|
|
5301
|
+
}
|
|
5302
|
+
}
|
|
4173
5303
|
};
|
|
4174
5304
|
/**
|
|
4175
5305
|
* 创建 BackendProvider 实例
|
|
@@ -4184,11 +5314,24 @@ function createBackendProvider(config) {
|
|
|
4184
5314
|
* Backend 请求类型常量
|
|
4185
5315
|
*/
|
|
4186
5316
|
const BACKEND_REQUEST_TYPES = {
|
|
4187
|
-
GET_AGENTS: "backend:get-agents-request",
|
|
4188
|
-
GET_MODELS: "backend:get-models",
|
|
4189
5317
|
LOGIN: "backend:login",
|
|
4190
5318
|
LOGOUT: "backend:logout",
|
|
4191
|
-
GET_ACCOUNT: "backend:get-account"
|
|
5319
|
+
GET_ACCOUNT: "backend:get-account",
|
|
5320
|
+
GET_USER_CONNECTOR: "backend:get-user-connector",
|
|
5321
|
+
MODIFY_USER_CONNECTOR_CONNECT_STATUS: "backend:modify-user-connector-connect-status",
|
|
5322
|
+
MODIFY_USER_CONNECTOR_REPO: "backend:modify-user-connector-repo",
|
|
5323
|
+
MODIFY_USER_CONNECTOR_ACTIVE_STATUS: "backend:modify-user-connector-active-status",
|
|
5324
|
+
DELETE_USER_CONNECTOR: "backend:delete-user-connector",
|
|
5325
|
+
ADD_CONNECTOR_TASK: "backend:add-connector-task",
|
|
5326
|
+
GET_TASK_CONNECTOR: "backend:get-task-connector",
|
|
5327
|
+
MODIFY_TASK_CONNECTOR_ACTIVE_STATUS: "backend:modify-task-connector-active-status",
|
|
5328
|
+
MODIFY_TASK_CONNECTOR_REPO: "backend:modify-task-connector-repo",
|
|
5329
|
+
GET_OAUTH_USER: "backend:get-oauth-user",
|
|
5330
|
+
SAVE_OAUTH_TOKEN: "backend:save-oauth-token",
|
|
5331
|
+
GET_REPO_LIST: "backend:get-repo-list",
|
|
5332
|
+
REVOKE_ALL: "backend:revoke-all",
|
|
5333
|
+
RELOAD_WINDOW: "backend:reload-window",
|
|
5334
|
+
BATCH_TOGGLE_PLUGINS: "backend:batch-toggle-plugins"
|
|
4192
5335
|
};
|
|
4193
5336
|
/**
|
|
4194
5337
|
* 生成唯一请求 ID
|
|
@@ -4199,7 +5342,7 @@ function generateRequestId() {
|
|
|
4199
5342
|
/**
|
|
4200
5343
|
* IPC Backend Provider 实现类
|
|
4201
5344
|
*
|
|
4202
|
-
* 通过 IWidgetChannel
|
|
5345
|
+
* 通过 IWidgetChannel 与后端通信
|
|
4203
5346
|
*/
|
|
4204
5347
|
var IPCBackendProvider = class {
|
|
4205
5348
|
constructor(config) {
|
|
@@ -4230,45 +5373,188 @@ var IPCBackendProvider = class {
|
|
|
4230
5373
|
return response?.data !== void 0 ? response.data : response;
|
|
4231
5374
|
}
|
|
4232
5375
|
/**
|
|
4233
|
-
*
|
|
4234
|
-
* 通过
|
|
5376
|
+
* 获取当前账号信息
|
|
5377
|
+
* IDE 环境: 通过 IPC 获取账号信息,并同步到 accountService
|
|
5378
|
+
*/
|
|
5379
|
+
async getAccount() {
|
|
5380
|
+
this.log("Getting account via IPC");
|
|
5381
|
+
try {
|
|
5382
|
+
const account = await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_ACCOUNT);
|
|
5383
|
+
accountService.setAccount(account);
|
|
5384
|
+
return account;
|
|
5385
|
+
} catch (error) {
|
|
5386
|
+
this.log("Get account failed:", error);
|
|
5387
|
+
accountService.setAccount(null);
|
|
5388
|
+
return null;
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
/**
|
|
5392
|
+
* 获取用户连接器列表
|
|
5393
|
+
* IDE 环境: 通过 IPC 获取用户连接器列表
|
|
4235
5394
|
*/
|
|
4236
|
-
async
|
|
4237
|
-
this.log("Getting
|
|
5395
|
+
async getUserConnector() {
|
|
5396
|
+
this.log("Getting user connector via IPC");
|
|
4238
5397
|
try {
|
|
4239
|
-
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.
|
|
5398
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_USER_CONNECTOR);
|
|
4240
5399
|
} catch (error) {
|
|
4241
|
-
this.log("Get
|
|
5400
|
+
this.log("Get user connector failed:", error);
|
|
4242
5401
|
throw error;
|
|
4243
5402
|
}
|
|
4244
5403
|
}
|
|
4245
5404
|
/**
|
|
4246
|
-
*
|
|
4247
|
-
* 通过
|
|
5405
|
+
* 修改用户连接器连接状态
|
|
5406
|
+
* IDE 环境: 通过 IPC 修改用户连接器连接状态
|
|
4248
5407
|
*/
|
|
4249
|
-
async
|
|
4250
|
-
this.log("
|
|
5408
|
+
async modifyUserConnectorConnectStatus(request) {
|
|
5409
|
+
this.log("Modifying user connector connect status via IPC:", request);
|
|
4251
5410
|
try {
|
|
4252
|
-
|
|
5411
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.MODIFY_USER_CONNECTOR_CONNECT_STATUS, request);
|
|
4253
5412
|
} catch (error) {
|
|
4254
|
-
this.log("
|
|
5413
|
+
this.log("Modify user connector connect status failed:", error);
|
|
4255
5414
|
throw error;
|
|
4256
5415
|
}
|
|
4257
5416
|
}
|
|
4258
5417
|
/**
|
|
4259
|
-
*
|
|
4260
|
-
* IDE 环境: 通过 IPC
|
|
5418
|
+
* 修改用户连接器仓库
|
|
5419
|
+
* IDE 环境: 通过 IPC 修改用户连接器仓库
|
|
4261
5420
|
*/
|
|
4262
|
-
async
|
|
4263
|
-
this.log("
|
|
5421
|
+
async modifyUserConnectorRepo(request) {
|
|
5422
|
+
this.log("Modifying user connector repo via IPC:", request);
|
|
4264
5423
|
try {
|
|
4265
|
-
|
|
4266
|
-
accountService.setAccount(account);
|
|
4267
|
-
return account;
|
|
5424
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.MODIFY_USER_CONNECTOR_REPO, request);
|
|
4268
5425
|
} catch (error) {
|
|
4269
|
-
this.log("
|
|
4270
|
-
|
|
4271
|
-
|
|
5426
|
+
this.log("Modify user connector repo failed:", error);
|
|
5427
|
+
throw error;
|
|
5428
|
+
}
|
|
5429
|
+
}
|
|
5430
|
+
/**
|
|
5431
|
+
* 修改用户连接器激活状态
|
|
5432
|
+
* IDE 环境: 通过 IPC 修改用户连接器激活状态
|
|
5433
|
+
*/
|
|
5434
|
+
async modifyUserConnectorActiveStatus(request) {
|
|
5435
|
+
this.log("Modifying user connector active status via IPC:", request);
|
|
5436
|
+
try {
|
|
5437
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.MODIFY_USER_CONNECTOR_ACTIVE_STATUS, request);
|
|
5438
|
+
} catch (error) {
|
|
5439
|
+
this.log("Modify user connector active status failed:", error);
|
|
5440
|
+
throw error;
|
|
5441
|
+
}
|
|
5442
|
+
}
|
|
5443
|
+
/**
|
|
5444
|
+
* 删除用户连接器
|
|
5445
|
+
* IDE 环境: 通过 IPC 删除用户连接器
|
|
5446
|
+
*/
|
|
5447
|
+
async deleteUserConnector(name) {
|
|
5448
|
+
this.log("Deleting user connector via IPC:", name);
|
|
5449
|
+
try {
|
|
5450
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.DELETE_USER_CONNECTOR, { name });
|
|
5451
|
+
} catch (error) {
|
|
5452
|
+
this.log("Delete user connector failed:", error);
|
|
5453
|
+
throw error;
|
|
5454
|
+
}
|
|
5455
|
+
}
|
|
5456
|
+
/**
|
|
5457
|
+
* 添加任务
|
|
5458
|
+
* IDE 环境: 通过 IPC 添加任务
|
|
5459
|
+
*/
|
|
5460
|
+
async addConnectorTask(request) {
|
|
5461
|
+
this.log("Adding connector task via IPC:", request);
|
|
5462
|
+
try {
|
|
5463
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.ADD_CONNECTOR_TASK, request);
|
|
5464
|
+
} catch (error) {
|
|
5465
|
+
this.log("Add task failed:", error);
|
|
5466
|
+
throw error;
|
|
5467
|
+
}
|
|
5468
|
+
}
|
|
5469
|
+
/**
|
|
5470
|
+
* 获取任务连接器列表
|
|
5471
|
+
* IDE 环境: 通过 IPC 获取任务连接器列表
|
|
5472
|
+
*/
|
|
5473
|
+
async getTaskConnector(taskId) {
|
|
5474
|
+
this.log("Getting task connector via IPC:", taskId);
|
|
5475
|
+
try {
|
|
5476
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_TASK_CONNECTOR, { taskId });
|
|
5477
|
+
} catch (error) {
|
|
5478
|
+
this.log("Get task connector failed:", error);
|
|
5479
|
+
throw error;
|
|
5480
|
+
}
|
|
5481
|
+
}
|
|
5482
|
+
/**
|
|
5483
|
+
* 修改任务连接器激活状态
|
|
5484
|
+
* IDE 环境: 通过 IPC 修改任务连接器激活状态
|
|
5485
|
+
*/
|
|
5486
|
+
async modifyTaskConnectorActiveStatus(request) {
|
|
5487
|
+
this.log("Modifying task connector active status via IPC:", request);
|
|
5488
|
+
try {
|
|
5489
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.MODIFY_TASK_CONNECTOR_ACTIVE_STATUS, request);
|
|
5490
|
+
} catch (error) {
|
|
5491
|
+
this.log("Modify task connector active status failed:", error);
|
|
5492
|
+
throw error;
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5495
|
+
/**
|
|
5496
|
+
* 修改任务连接器仓库
|
|
5497
|
+
* IDE 环境: 通过 IPC 修改任务连接器仓库
|
|
5498
|
+
*/
|
|
5499
|
+
async modifyTaskConnectorRepo(request) {
|
|
5500
|
+
this.log("Modifying task connector repo via IPC:", request);
|
|
5501
|
+
try {
|
|
5502
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.MODIFY_TASK_CONNECTOR_REPO, request);
|
|
5503
|
+
} catch (error) {
|
|
5504
|
+
this.log("Modify task connector repo failed:", error);
|
|
5505
|
+
throw error;
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
/**
|
|
5509
|
+
* 获取 OAuth 用户信息
|
|
5510
|
+
* IDE 环境: 通过 IPC 获取 OAuth 用户信息
|
|
5511
|
+
*/
|
|
5512
|
+
async getOauthUser(request) {
|
|
5513
|
+
this.log("Getting OAuth user via IPC:", request);
|
|
5514
|
+
try {
|
|
5515
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_OAUTH_USER, request);
|
|
5516
|
+
} catch (error) {
|
|
5517
|
+
this.log("Get OAuth user failed:", error);
|
|
5518
|
+
throw error;
|
|
5519
|
+
}
|
|
5520
|
+
}
|
|
5521
|
+
/**
|
|
5522
|
+
* 通过回调code,换token
|
|
5523
|
+
* IDE 环境: 通过 IPC 保存 OAuth Token
|
|
5524
|
+
*/
|
|
5525
|
+
async saveOauthToken(request) {
|
|
5526
|
+
this.log("Saving OAuth token via IPC:", request);
|
|
5527
|
+
try {
|
|
5528
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.SAVE_OAUTH_TOKEN, request);
|
|
5529
|
+
} catch (error) {
|
|
5530
|
+
this.log("Save OAuth token failed:", error);
|
|
5531
|
+
throw error;
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
/**
|
|
5535
|
+
* 获取OAuth连接器的仓库列表
|
|
5536
|
+
* IDE 环境: 通过 IPC 获取仓库列表
|
|
5537
|
+
*/
|
|
5538
|
+
async getRepoList(request) {
|
|
5539
|
+
this.log("Getting repo list via IPC:", request);
|
|
5540
|
+
try {
|
|
5541
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.GET_REPO_LIST, request);
|
|
5542
|
+
} catch (error) {
|
|
5543
|
+
this.log("Get repo list failed:", error);
|
|
5544
|
+
throw error;
|
|
5545
|
+
}
|
|
5546
|
+
}
|
|
5547
|
+
/**
|
|
5548
|
+
* 撤销OAuth连接器的所有连接
|
|
5549
|
+
* IDE 环境: 通过 IPC 撤销所有连接
|
|
5550
|
+
*/
|
|
5551
|
+
async revokeAll(request) {
|
|
5552
|
+
this.log("Revoking all connections via IPC:", request);
|
|
5553
|
+
try {
|
|
5554
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.REVOKE_ALL, request);
|
|
5555
|
+
} catch (error) {
|
|
5556
|
+
this.log("Revoke all connections failed:", error);
|
|
5557
|
+
throw error;
|
|
4272
5558
|
}
|
|
4273
5559
|
}
|
|
4274
5560
|
/**
|
|
@@ -4299,6 +5585,33 @@ var IPCBackendProvider = class {
|
|
|
4299
5585
|
}
|
|
4300
5586
|
}
|
|
4301
5587
|
/**
|
|
5588
|
+
* 重新加载窗口
|
|
5589
|
+
* IDE 环境: 通过 IPC 通知 IDE 重新加载窗口(用于应用语言设置等)
|
|
5590
|
+
* @param params 可选参数,如 locale
|
|
5591
|
+
*/
|
|
5592
|
+
async reloadWindow(params) {
|
|
5593
|
+
this.log("Triggering reload window via IPC", params);
|
|
5594
|
+
try {
|
|
5595
|
+
await this.sendBackendRequest(BACKEND_REQUEST_TYPES.RELOAD_WINDOW, params);
|
|
5596
|
+
} catch (error) {
|
|
5597
|
+
this.log("Reload window request failed:", error);
|
|
5598
|
+
throw error;
|
|
5599
|
+
}
|
|
5600
|
+
}
|
|
5601
|
+
/**
|
|
5602
|
+
* 批量切换插件状态
|
|
5603
|
+
* IDE 环境: 通过 IPC 调用 Extension Host 的 PluginService
|
|
5604
|
+
*/
|
|
5605
|
+
async batchTogglePlugins(request) {
|
|
5606
|
+
this.log("Batch toggling plugins via IPC:", request);
|
|
5607
|
+
try {
|
|
5608
|
+
return await this.sendBackendRequest(BACKEND_REQUEST_TYPES.BATCH_TOGGLE_PLUGINS, request);
|
|
5609
|
+
} catch (error) {
|
|
5610
|
+
this.log("Batch toggle plugins failed:", error);
|
|
5611
|
+
throw error;
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
/**
|
|
4302
5615
|
* 调试日志
|
|
4303
5616
|
*/
|
|
4304
5617
|
log(...args) {
|