linkque-cli-v2 1.4.3 → 1.4.5
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/linkquejs.js +147 -48
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Y36JLYIE.js → chunk-CLYLJ5MD.js} +1257 -1217
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-OMFQ2KRJ.js → chunk-NFVKWQGM.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-SAQYWJAA.js → chunk-S75HFRLD.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +59 -9
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
- package/worker.js +468 -383
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Y36JLYIE.js → chunk-CLYLJ5MD.js}
RENAMED
|
@@ -26050,1176 +26050,8 @@ function resolvePhoneAuthorizationDependency(protocol, resourceIds, toolName) {
|
|
|
26050
26050
|
return dependencies.length ? { required: dependencies.some((dependency) => dependency.required) } : void 0;
|
|
26051
26051
|
}
|
|
26052
26052
|
|
|
26053
|
-
// ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
|
|
26054
|
-
var MCP_PROXY_TOOL_NAME = "mcp";
|
|
26055
|
-
var McpProxyTool = class {
|
|
26056
|
-
provider;
|
|
26057
|
-
/** serverName → 缓存条目(同 serverName 多 resourceId 聚合为一个连接)。 */
|
|
26058
|
-
entries = /* @__PURE__ */ new Map();
|
|
26059
|
-
/** 进行中的连接(去重并发 ensureEntry)。 */
|
|
26060
|
-
inFlight = /* @__PURE__ */ new Map();
|
|
26061
|
-
specByServerName;
|
|
26062
|
-
/** 原始 resourceId → 所属 spec(resolve(resourceId,...) 反查用)。 */
|
|
26063
|
-
specByResourceId;
|
|
26064
|
-
specs;
|
|
26065
|
-
debugLog;
|
|
26066
|
-
authorizeCall;
|
|
26067
|
-
constructor(provider, specs, options = {}) {
|
|
26068
|
-
this.provider = provider;
|
|
26069
|
-
this.specs = specs;
|
|
26070
|
-
this.specByServerName = new Map(specs.map((spec) => [spec.serverName, spec]));
|
|
26071
|
-
this.specByResourceId = new Map(specs.flatMap((spec) => spec.resourceIds.map((id) => [id, spec])));
|
|
26072
|
-
this.debugLog = options.debugLog ?? (() => {
|
|
26073
|
-
});
|
|
26074
|
-
this.authorizeCall = options.authorizeCall;
|
|
26075
|
-
}
|
|
26076
|
-
/**
|
|
26077
|
-
* 产单个 `mcp` 代理工具描述符,注入 `agentReq.tools`。
|
|
26078
|
-
* `execute` 闭包按入参字段派发到 status/connect/list/search/describe/call。
|
|
26079
|
-
*/
|
|
26080
|
-
asTool() {
|
|
26081
|
-
return {
|
|
26082
|
-
name: MCP_PROXY_TOOL_NAME,
|
|
26083
|
-
modelName: MCP_PROXY_TOOL_NAME,
|
|
26084
|
-
label: "MCP",
|
|
26085
|
-
description: MCP_PROXY_DESCRIPTION,
|
|
26086
|
-
inputSchema: MCP_PROXY_INPUT_SCHEMA,
|
|
26087
|
-
execute: (args, signal, context2) => this.dispatch(args, signal, context2)
|
|
26088
|
-
};
|
|
26089
|
-
}
|
|
26090
|
-
/** {@link IMcpToolRegistry.resolve}:按 (resourceId, toolName) 解析可调用句柄。 */
|
|
26091
|
-
async resolve(resourceId, toolName, signal) {
|
|
26092
|
-
const spec = this.findSpec(resourceId);
|
|
26093
|
-
if (!spec)
|
|
26094
|
-
return void 0;
|
|
26095
|
-
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
26096
|
-
if (!entry || !entry.server)
|
|
26097
|
-
return void 0;
|
|
26098
|
-
const tool = entry.tools.find((t) => t.name === toolName);
|
|
26099
|
-
if (!tool)
|
|
26100
|
-
return void 0;
|
|
26101
|
-
return {
|
|
26102
|
-
inputSchema: tool.inputSchema,
|
|
26103
|
-
outputSchema: tool.outputSchema,
|
|
26104
|
-
execute: async (args, sig, context2) => {
|
|
26105
|
-
const headers = await this.authorizeCall?.({
|
|
26106
|
-
resourceIds: [resourceId],
|
|
26107
|
-
toolName: tool.name,
|
|
26108
|
-
signal: sig,
|
|
26109
|
-
context: context2
|
|
26110
|
-
});
|
|
26111
|
-
return entry.server.callTool(tool.name, args, sig, {
|
|
26112
|
-
toolSchema: {
|
|
26113
|
-
inputSchema: tool.inputSchema,
|
|
26114
|
-
outputSchema: tool.outputSchema
|
|
26115
|
-
},
|
|
26116
|
-
...headers ? { headers } : {},
|
|
26117
|
-
...context2 ? { context: context2 } : {}
|
|
26118
|
-
});
|
|
26119
|
-
}
|
|
26120
|
-
};
|
|
26121
|
-
}
|
|
26122
|
-
/** 关闭所有已连 server(忽略单 server 关闭错误)。 */
|
|
26123
|
-
async closeAll() {
|
|
26124
|
-
await Promise.all([...this.entries.values()].map(async (entry) => {
|
|
26125
|
-
if (!entry.server)
|
|
26126
|
-
return;
|
|
26127
|
-
try {
|
|
26128
|
-
await entry.server.close?.();
|
|
26129
|
-
} catch (error) {
|
|
26130
|
-
try {
|
|
26131
|
-
this.debugLog(`[mcp] server ${entry.server.serverName} close failed: ${error instanceof Error ? error.message : "unknown error"}`, EDebugLogScope.MCP);
|
|
26132
|
-
} catch {
|
|
26133
|
-
}
|
|
26134
|
-
}
|
|
26135
|
-
}));
|
|
26136
|
-
}
|
|
26137
|
-
// —— 内部:连接与缓存 ——
|
|
26138
|
-
/** 确保某 server 已连;返回 connected 条目,依失败返回 null(不抛错)。 */
|
|
26139
|
-
async ensureEntry(serverName, signal) {
|
|
26140
|
-
const existing = this.entries.get(serverName);
|
|
26141
|
-
if (existing) {
|
|
26142
|
-
return existing.status === "connected" ? existing : null;
|
|
26143
|
-
}
|
|
26144
|
-
let promise = this.inFlight.get(serverName);
|
|
26145
|
-
if (!promise) {
|
|
26146
|
-
promise = this.connect(serverName, signal).finally(() => {
|
|
26147
|
-
this.inFlight.delete(serverName);
|
|
26148
|
-
});
|
|
26149
|
-
this.inFlight.set(serverName, promise);
|
|
26150
|
-
}
|
|
26151
|
-
const entry = await promise;
|
|
26152
|
-
return entry.status === "connected" ? entry : null;
|
|
26153
|
-
}
|
|
26154
|
-
/** 连单个 server 并 listTools;按 spec.allowedTools 过滤后缓存;失败记为 failed。 */
|
|
26155
|
-
async connect(serverName, _signal) {
|
|
26156
|
-
const spec = this.specByServerName.get(serverName);
|
|
26157
|
-
if (!spec) {
|
|
26158
|
-
const entry = {
|
|
26159
|
-
server: null,
|
|
26160
|
-
tools: [],
|
|
26161
|
-
status: "failed",
|
|
26162
|
-
error: `unknown serverName: ${serverName}`
|
|
26163
|
-
};
|
|
26164
|
-
this.entries.set(serverName, entry);
|
|
26165
|
-
this.debugLog(`[mcp] server ${serverName} unknown serverName`, EDebugLogScope.MCP);
|
|
26166
|
-
return entry;
|
|
26167
|
-
}
|
|
26168
|
-
try {
|
|
26169
|
-
const synthetic = {
|
|
26170
|
-
resourceId: spec.serverName,
|
|
26171
|
-
resourceType: EResourceType.MCP,
|
|
26172
|
-
providerType: EResourceProviderType.ALIPAY_OPEN,
|
|
26173
|
-
config: {
|
|
26174
|
-
agentId: spec.agentId,
|
|
26175
|
-
serverName: spec.serverName,
|
|
26176
|
-
description: spec.description,
|
|
26177
|
-
argsMappingRules: spec.argsMappingRules
|
|
26178
|
-
}
|
|
26179
|
-
};
|
|
26180
|
-
const servers = await this.provider.servers([synthetic]);
|
|
26181
|
-
const server = servers[0];
|
|
26182
|
-
if (!server) {
|
|
26183
|
-
throw new Error(`provider returned no server for ${spec.serverName}`);
|
|
26184
|
-
}
|
|
26185
|
-
const all = await server.listTools();
|
|
26186
|
-
const tools = spec.allowedTools ? all.filter((tool) => spec.allowedTools.has(tool.name)) : all;
|
|
26187
|
-
const entry = { server, tools, status: "connected" };
|
|
26188
|
-
this.entries.set(serverName, entry);
|
|
26189
|
-
this.debugLog(`[mcp] server ${spec.serverName} connected (${tools.length}/${all.length} tools)`, EDebugLogScope.MCP);
|
|
26190
|
-
return entry;
|
|
26191
|
-
} catch (error) {
|
|
26192
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
26193
|
-
const entry = {
|
|
26194
|
-
server: null,
|
|
26195
|
-
tools: [],
|
|
26196
|
-
status: "failed",
|
|
26197
|
-
error: message
|
|
26198
|
-
};
|
|
26199
|
-
this.entries.set(serverName, entry);
|
|
26200
|
-
this.debugLog(`[mcp] server ${spec.serverName} connect failed: ${message}`, EDebugLogScope.MCP);
|
|
26201
|
-
return entry;
|
|
26202
|
-
}
|
|
26203
|
-
}
|
|
26204
|
-
// —— 派发 ——
|
|
26205
|
-
/** 按入参字段派发;返回 LLM 可读文本。 */
|
|
26206
|
-
async dispatch(args, signal, context2) {
|
|
26207
|
-
const params = parseProxyArgs(args);
|
|
26208
|
-
if (params.connect !== void 0) {
|
|
26209
|
-
return this.executeConnect(params.connect, signal);
|
|
26210
|
-
}
|
|
26211
|
-
if (params.describe !== void 0) {
|
|
26212
|
-
return this.executeDescribe(params.describe, params.server, signal);
|
|
26213
|
-
}
|
|
26214
|
-
if (params.searches !== void 0) {
|
|
26215
|
-
return this.executeBatchSearch(params.searches, params.server);
|
|
26216
|
-
}
|
|
26217
|
-
if (params.search !== void 0) {
|
|
26218
|
-
return this.executeSearch(params.search, params.server);
|
|
26219
|
-
}
|
|
26220
|
-
if (params.tool !== void 0) {
|
|
26221
|
-
return this.executeCall(params.tool, params.args, params.server, signal, context2);
|
|
26222
|
-
}
|
|
26223
|
-
if (params.server !== void 0) {
|
|
26224
|
-
return this.executeList(params.server, signal);
|
|
26225
|
-
}
|
|
26226
|
-
return this.executeStatus();
|
|
26227
|
-
}
|
|
26228
|
-
/** `mcp({})` / `mcp({ status: true })`:列各 server 连接状态 + 工具数。 */
|
|
26229
|
-
executeStatus() {
|
|
26230
|
-
const lines = [];
|
|
26231
|
-
let connected = 0;
|
|
26232
|
-
let totalTools = 0;
|
|
26233
|
-
for (const spec of this.specs) {
|
|
26234
|
-
const label = spec.serverName;
|
|
26235
|
-
const entry = this.entries.get(spec.serverName);
|
|
26236
|
-
if (!entry) {
|
|
26237
|
-
lines.push(`\u25CB ${label} (not connected)`);
|
|
26238
|
-
continue;
|
|
26239
|
-
}
|
|
26240
|
-
if (entry.status === "connected") {
|
|
26241
|
-
connected += 1;
|
|
26242
|
-
totalTools += entry.tools.length;
|
|
26243
|
-
lines.push(`\u2713 ${label} (${entry.tools.length} tools)`);
|
|
26244
|
-
} else {
|
|
26245
|
-
lines.push(`\u2717 ${label} (failed${entry.error ? ": " + entry.error : ""})`);
|
|
26246
|
-
}
|
|
26247
|
-
}
|
|
26248
|
-
const header = `MCP: ${connected}/${this.specs.length} servers, ${totalTools} tools`;
|
|
26249
|
-
const hint = this.specs.length > 0 ? '\nmcp({ server: "name" }) to list tools, mcp({ search: "..." }) to search, mcp({ tool: "...", args: {...} }) to call' : "\n(no MCP resources configured)";
|
|
26250
|
-
return `${header}
|
|
26251
|
-
|
|
26252
|
-
${lines.join("\n")}${hint}`.trim();
|
|
26253
|
-
}
|
|
26254
|
-
/** `mcp({ connect: "server" })`:显式连接并刷元数据,返回该 server 工具列表。 */
|
|
26255
|
-
async executeConnect(server, signal) {
|
|
26256
|
-
const spec = this.findSpec(server);
|
|
26257
|
-
if (!spec)
|
|
26258
|
-
return `Server "${server}" not found. Use mcp({}) to see available servers.`;
|
|
26259
|
-
this.entries.delete(spec.serverName);
|
|
26260
|
-
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
26261
|
-
if (!entry) {
|
|
26262
|
-
const failed = this.entries.get(spec.serverName);
|
|
26263
|
-
const detail = failed?.error ? `: ${failed.error}` : "";
|
|
26264
|
-
return `Failed to connect to "${spec.serverName}"${detail}.`;
|
|
26265
|
-
}
|
|
26266
|
-
return this.formatToolList(spec.serverName, entry.tools);
|
|
26267
|
-
}
|
|
26268
|
-
/** `mcp({ server: "name" })`:列该 server 工具名 + 截断 description。 */
|
|
26269
|
-
async executeList(server, signal) {
|
|
26270
|
-
const spec = this.findSpec(server);
|
|
26271
|
-
if (!spec)
|
|
26272
|
-
return `Server "${server}" not found. Use mcp({}) to see available servers.`;
|
|
26273
|
-
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
26274
|
-
if (!entry) {
|
|
26275
|
-
return `Server "${spec.serverName}" is not connected. Use mcp({ connect: "${spec.serverName}" }) to retry.`;
|
|
26276
|
-
}
|
|
26277
|
-
return this.formatToolList(spec.serverName, entry.tools);
|
|
26278
|
-
}
|
|
26279
|
-
/** `mcp({ search: "query" })`:空格分词 OR 子串匹配 name/description(跨所有 server)。 */
|
|
26280
|
-
async executeSearch(query, serverHint) {
|
|
26281
|
-
const terms = query.trim().split(/\s+/u).filter((t) => t.length > 0);
|
|
26282
|
-
if (terms.length === 0)
|
|
26283
|
-
return "Search query cannot be empty.";
|
|
26284
|
-
const pattern = new RegExp(terms.map(escapeRegExp).join("|"), "iu");
|
|
26285
|
-
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26286
|
-
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName)));
|
|
26287
|
-
const matches = [];
|
|
26288
|
-
for (const spec of specs) {
|
|
26289
|
-
const entry = this.entries.get(spec.serverName);
|
|
26290
|
-
if (!entry || entry.status !== "connected")
|
|
26291
|
-
continue;
|
|
26292
|
-
for (const tool of entry.tools) {
|
|
26293
|
-
if (pattern.test(tool.name) || pattern.test(tool.description ?? "")) {
|
|
26294
|
-
matches.push({ server: spec.serverName, tool });
|
|
26295
|
-
}
|
|
26296
|
-
}
|
|
26297
|
-
}
|
|
26298
|
-
if (matches.length === 0) {
|
|
26299
|
-
return serverHint ? `No tools matching "${query}" in "${serverHint}"` : `No tools matching "${query}"`;
|
|
26300
|
-
}
|
|
26301
|
-
const lines = [`Found ${matches.length} tool(s) matching "${query}":`, ""];
|
|
26302
|
-
for (const { server, tool } of matches) {
|
|
26303
|
-
lines.push(`${tool.name} [${server}]`);
|
|
26304
|
-
lines.push(` ${tool.description ?? "(no description)"}`);
|
|
26305
|
-
if (tool.inputSchema) {
|
|
26306
|
-
lines.push(` Parameters:
|
|
26307
|
-
${formatSchema(tool.inputSchema, " ")}`);
|
|
26308
|
-
}
|
|
26309
|
-
lines.push("");
|
|
26310
|
-
}
|
|
26311
|
-
return lines.join("\n").trim();
|
|
26312
|
-
}
|
|
26313
|
-
/** `mcp({ searches: [...] })`:一次连接元数据并按 query 分组执行多组搜索。 */
|
|
26314
|
-
async executeBatchSearch(queries, serverHint) {
|
|
26315
|
-
const normalized = [
|
|
26316
|
-
...new Set(queries.map((query) => query.trim()).filter(Boolean))
|
|
26317
|
-
].slice(0, MCP_BATCH_SEARCH_MAX_ITEMS);
|
|
26318
|
-
if (normalized.length === 0) {
|
|
26319
|
-
return "Batch search requires at least one non-empty query.";
|
|
26320
|
-
}
|
|
26321
|
-
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26322
|
-
await Promise.all(specs.map((spec) => this.ensureEntry(spec.serverName)));
|
|
26323
|
-
const results = await Promise.all(normalized.map((query) => this.executeSearch(query, serverHint)));
|
|
26324
|
-
return results.map((result, index) => `Query ${index + 1}: "${normalized[index]}"
|
|
26325
|
-
${result}`).join("\n\n");
|
|
26326
|
-
}
|
|
26327
|
-
/** `mcp({ describe: "tool" })`:输出工具所属 server + 参数 schema。 */
|
|
26328
|
-
async executeDescribe(toolName, serverHint, signal) {
|
|
26329
|
-
const found = await this.findTool(toolName, serverHint, signal);
|
|
26330
|
-
if (!found) {
|
|
26331
|
-
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
26332
|
-
}
|
|
26333
|
-
const { server, tool } = found;
|
|
26334
|
-
const lines = [
|
|
26335
|
-
`${tool.name}`,
|
|
26336
|
-
`Server: ${server}`,
|
|
26337
|
-
"",
|
|
26338
|
-
tool.description ?? "(no description)"
|
|
26339
|
-
];
|
|
26340
|
-
if (tool.inputSchema) {
|
|
26341
|
-
lines.push("", `Parameters:
|
|
26342
|
-
${formatSchema(tool.inputSchema)}`);
|
|
26343
|
-
} else {
|
|
26344
|
-
lines.push("", "No parameters defined.");
|
|
26345
|
-
}
|
|
26346
|
-
return lines.join("\n").trim();
|
|
26347
|
-
}
|
|
26348
|
-
/** `mcp({ tool: "name", args: {...} })`:调用工具,返回序列化结果。 */
|
|
26349
|
-
async executeCall(toolName, args, serverHint, signal, context2) {
|
|
26350
|
-
const found = await this.findTool(toolName, serverHint, signal);
|
|
26351
|
-
if (!found) {
|
|
26352
|
-
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
26353
|
-
}
|
|
26354
|
-
const { entry, tool, spec } = found;
|
|
26355
|
-
try {
|
|
26356
|
-
const headers = await this.authorizeCall?.({
|
|
26357
|
-
resourceIds: resourceIdsForTool(spec, tool.name),
|
|
26358
|
-
toolName: tool.name,
|
|
26359
|
-
signal,
|
|
26360
|
-
context: context2
|
|
26361
|
-
});
|
|
26362
|
-
const result = await entry.server.callTool(tool.name, args, signal, {
|
|
26363
|
-
toolSchema: {
|
|
26364
|
-
inputSchema: tool.inputSchema,
|
|
26365
|
-
outputSchema: tool.outputSchema
|
|
26366
|
-
},
|
|
26367
|
-
...headers ? { headers } : {},
|
|
26368
|
-
...context2 ? { context: context2 } : {}
|
|
26369
|
-
});
|
|
26370
|
-
return serializeToolResult(result);
|
|
26371
|
-
} catch (error) {
|
|
26372
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
26373
|
-
return `Tool "${toolName}" call failed: ${message}`;
|
|
26374
|
-
}
|
|
26375
|
-
}
|
|
26376
|
-
// —— 辅助 ——
|
|
26377
|
-
/** 跨(或按 hint)已连 server 查找工具;未连则触发懒连接。 */
|
|
26378
|
-
async findTool(toolName, serverHint, signal) {
|
|
26379
|
-
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26380
|
-
for (const spec of specs) {
|
|
26381
|
-
const entry = this.entries.get(spec.serverName);
|
|
26382
|
-
if (!entry || entry.status !== "connected")
|
|
26383
|
-
continue;
|
|
26384
|
-
const tool = entry.tools.find((t) => t.name === toolName);
|
|
26385
|
-
if (tool) {
|
|
26386
|
-
return { entry, server: spec.serverName, tool, spec };
|
|
26387
|
-
}
|
|
26388
|
-
}
|
|
26389
|
-
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, signal)));
|
|
26390
|
-
for (const spec of specs) {
|
|
26391
|
-
const entry = this.entries.get(spec.serverName);
|
|
26392
|
-
if (!entry || entry.status !== "connected")
|
|
26393
|
-
continue;
|
|
26394
|
-
const tool = entry.tools.find((t) => t.name === toolName);
|
|
26395
|
-
if (tool) {
|
|
26396
|
-
return { entry, server: spec.serverName, tool, spec };
|
|
26397
|
-
}
|
|
26398
|
-
}
|
|
26399
|
-
return void 0;
|
|
26400
|
-
}
|
|
26401
|
-
/** 按 serverName 或原始 resourceId 找 spec(server 入参可为二者)。 */
|
|
26402
|
-
findSpec(server) {
|
|
26403
|
-
return this.specByServerName.get(server) ?? this.specByResourceId.get(server);
|
|
26404
|
-
}
|
|
26405
|
-
/** serverHint(serverName 或 resourceId)命中的 spec 子集。 */
|
|
26406
|
-
specsMatching(serverHint) {
|
|
26407
|
-
return this.specs.filter((spec) => spec.serverName === serverHint || spec.resourceIds.includes(serverHint));
|
|
26408
|
-
}
|
|
26409
|
-
/** 格式化某 server 的工具列表。 */
|
|
26410
|
-
formatToolList(server, tools) {
|
|
26411
|
-
if (tools.length === 0)
|
|
26412
|
-
return `Server "${server}" has no tools.`;
|
|
26413
|
-
const lines = [`${server} (${tools.length} tools):`, ""];
|
|
26414
|
-
for (const tool of tools) {
|
|
26415
|
-
const desc = truncate(tool.description ?? "", 50);
|
|
26416
|
-
lines.push(`- ${tool.name}${desc ? " - " + desc : ""}`);
|
|
26417
|
-
}
|
|
26418
|
-
return lines.join("\n").trim();
|
|
26419
|
-
}
|
|
26420
|
-
};
|
|
26421
|
-
function resourceIdsForTool(spec, toolName) {
|
|
26422
|
-
if (!spec.allToolResourceIds && !spec.resourceIdsByTool)
|
|
26423
|
-
return spec.resourceIds;
|
|
26424
|
-
return [
|
|
26425
|
-
...spec.allToolResourceIds ?? [],
|
|
26426
|
-
...spec.resourceIdsByTool?.get(toolName) ?? []
|
|
26427
|
-
];
|
|
26428
|
-
}
|
|
26429
|
-
function parseProxyArgs(args) {
|
|
26430
|
-
if (!isRecord(args))
|
|
26431
|
-
return {};
|
|
26432
|
-
const out = {};
|
|
26433
|
-
if (typeof args.connect === "string")
|
|
26434
|
-
out.connect = args.connect;
|
|
26435
|
-
if (typeof args.describe === "string")
|
|
26436
|
-
out.describe = args.describe;
|
|
26437
|
-
if (typeof args.search === "string")
|
|
26438
|
-
out.search = args.search;
|
|
26439
|
-
if (Array.isArray(args.searches)) {
|
|
26440
|
-
out.searches = args.searches.filter((query) => typeof query === "string").slice(0, MCP_BATCH_SEARCH_MAX_ITEMS);
|
|
26441
|
-
}
|
|
26442
|
-
if (typeof args.tool === "string")
|
|
26443
|
-
out.tool = args.tool;
|
|
26444
|
-
if (typeof args.server === "string")
|
|
26445
|
-
out.server = args.server;
|
|
26446
|
-
if (args.args !== void 0)
|
|
26447
|
-
out.args = args.args;
|
|
26448
|
-
return out;
|
|
26449
|
-
}
|
|
26450
|
-
function formatSchema(schema, indent = " ") {
|
|
26451
|
-
if (!isRecord(schema))
|
|
26452
|
-
return `${indent}No parameters defined.`;
|
|
26453
|
-
const props = schema.properties;
|
|
26454
|
-
if (!isRecord(props) || Object.keys(props).length === 0) {
|
|
26455
|
-
return `${indent}No parameters defined.`;
|
|
26456
|
-
}
|
|
26457
|
-
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
26458
|
-
const lines = Object.entries(props).map(([key, value]) => {
|
|
26459
|
-
const type = isRecord(value) && typeof value.type === "string" ? value.type : "any";
|
|
26460
|
-
const desc = isRecord(value) && typeof value.description === "string" ? value.description : "";
|
|
26461
|
-
const req = required.has(key) ? " [required]" : "";
|
|
26462
|
-
return `${indent}- ${key} (${type})${req}${desc ? " - " + desc : ""}`;
|
|
26463
|
-
});
|
|
26464
|
-
return lines.join("\n");
|
|
26465
|
-
}
|
|
26466
|
-
function serializeToolResult(value) {
|
|
26467
|
-
if (typeof value === "string")
|
|
26468
|
-
return value;
|
|
26469
|
-
try {
|
|
26470
|
-
const serialized = JSON.stringify(value);
|
|
26471
|
-
return serialized === void 0 ? "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002" : serialized;
|
|
26472
|
-
} catch {
|
|
26473
|
-
return "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002";
|
|
26474
|
-
}
|
|
26475
|
-
}
|
|
26476
|
-
function escapeRegExp(text) {
|
|
26477
|
-
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
26478
|
-
}
|
|
26479
|
-
function truncate(text, max2) {
|
|
26480
|
-
return text.length > max2 ? `${text.slice(0, max2)}\u2026` : text;
|
|
26481
|
-
}
|
|
26482
|
-
function isRecord(value) {
|
|
26483
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
26484
|
-
}
|
|
26485
|
-
var MCP_BATCH_SEARCH_MAX_ITEMS = 5;
|
|
26486
|
-
var MCP_PROXY_DESCRIPTION = [
|
|
26487
|
-
"MCP \u7F51\u5173:\u53D1\u73B0\u5E76\u8C03\u7528 MCP server \u63D0\u4F9B\u7684\u5DE5\u5177\u3002\u53EF\u7528\u52A8\u4F5C:",
|
|
26488
|
-
"- mcp({}) \u6216 mcp({ status: true }):\u67E5\u770B\u6240\u6709 server \u8FDE\u63A5\u72B6\u6001\u4E0E\u5DE5\u5177\u6570\u3002",
|
|
26489
|
-
'- mcp({ connect: "server" }):\u8FDE\u63A5\u5E76\u5237\u65B0\u67D0 server \u7684\u5DE5\u5177\u5217\u8868\u3002',
|
|
26490
|
-
'- mcp({ server: "name" }):\u5217\u51FA\u8BE5 server \u7684\u5DE5\u5177\u3002',
|
|
26491
|
-
'- mcp({ search: "\u5173\u952E\u8BCD" }):\u6309\u540D\u79F0/\u63CF\u8FF0\u6A21\u7CCA\u641C\u7D22\u5DE5\u5177(\u7A7A\u683C\u5206\u8BCD OR)\u3002',
|
|
26492
|
-
'- mcp({ searches: ["\u5173\u952E\u8BCD1", "\u5173\u952E\u8BCD2"] }):\u4E00\u6B21\u6267\u884C\u591A\u7EC4\u641C\u7D22\u5E76\u6309 query \u5206\u7EC4\u8FD4\u56DE(\u6700\u591A 5 \u7EC4)\u3002',
|
|
26493
|
-
'- mcp({ describe: "toolName" }):\u67E5\u770B\u67D0\u5DE5\u5177\u7684\u53C2\u6570 schema\u3002',
|
|
26494
|
-
'- mcp({ tool: "toolName", args: { ... } }):\u8C03\u7528\u67D0\u5DE5\u5177,args \u4E3A\u5BF9\u8C61\u3002',
|
|
26495
|
-
"\u53EF\u7528 server \u540D\u89C1 mcp({}) \u8F93\u51FA\u3002\u4EC5\u5728\u786E\u9700\u8C03\u7528 MCP \u5DE5\u5177\u65F6\u4F7F\u7528\u672C\u5DE5\u5177\u3002",
|
|
26496
|
-
"\u4EC5 mcp({}) \u5217\u51FA\u7684\u5DE5\u5177\u53EF\u8C03\u7528(\u672A\u58F0\u660E\u7684\u5DE5\u5177\u4E0D\u4F1A\u51FA\u73B0)\u3002"
|
|
26497
|
-
].join("\n");
|
|
26498
|
-
var MCP_PROXY_INPUT_SCHEMA = {
|
|
26499
|
-
type: "object",
|
|
26500
|
-
additionalProperties: false,
|
|
26501
|
-
properties: {
|
|
26502
|
-
status: {
|
|
26503
|
-
type: "boolean",
|
|
26504
|
-
description: "\u67E5\u770B\u6240\u6709 server \u8FDE\u63A5\u72B6\u6001(\u7B49\u4EF7\u4E8E\u7A7A\u5165\u53C2)"
|
|
26505
|
-
},
|
|
26506
|
-
connect: {
|
|
26507
|
-
type: "string",
|
|
26508
|
-
description: "\u663E\u5F0F\u8FDE\u63A5\u5E76\u5237\u65B0\u67D0 server(serverName \u6216 resourceId)"
|
|
26509
|
-
},
|
|
26510
|
-
server: { type: "string", description: "\u6307\u5B9A server:\u5217\u5DE5\u5177\u6216\u6D88\u6B67\u5DE5\u5177\u8C03\u7528" },
|
|
26511
|
-
search: {
|
|
26512
|
-
type: "string",
|
|
26513
|
-
description: "\u6309\u540D\u79F0/\u63CF\u8FF0\u6A21\u7CCA\u641C\u7D22\u5DE5\u5177(\u7A7A\u683C\u5206\u8BCD OR)"
|
|
26514
|
-
},
|
|
26515
|
-
searches: {
|
|
26516
|
-
type: "array",
|
|
26517
|
-
description: "\u6279\u91CF\u641C\u7D22\u5173\u952E\u8BCD\uFF1B\u4E00\u6B21\u63D0\u4EA4\u6240\u6709\u5019\u9009 query\uFF0C\u6309 query \u5206\u7EC4\u8FD4\u56DE",
|
|
26518
|
-
minItems: 1,
|
|
26519
|
-
maxItems: MCP_BATCH_SEARCH_MAX_ITEMS,
|
|
26520
|
-
items: { type: "string", minLength: 1 }
|
|
26521
|
-
},
|
|
26522
|
-
describe: { type: "string", description: "\u67E5\u770B\u67D0\u5DE5\u5177\u7684\u53C2\u6570 schema" },
|
|
26523
|
-
tool: { type: "string", description: "\u8981\u8C03\u7528\u7684\u5DE5\u5177\u540D(\u53EF\u914D\u5408 server \u6D88\u6B67)" },
|
|
26524
|
-
args: {
|
|
26525
|
-
type: "object",
|
|
26526
|
-
description: "\u5DE5\u5177\u5165\u53C2\u5BF9\u8C61(\u4EC5\u5728 tool \u6307\u5B9A\u65F6\u6709\u6548)",
|
|
26527
|
-
additionalProperties: true
|
|
26528
|
-
}
|
|
26529
|
-
}
|
|
26530
|
-
};
|
|
26531
|
-
|
|
26532
|
-
// ../linkque-agent-runtime/dist/esm/core/homeData.js
|
|
26533
|
-
async function executeHomeData(input) {
|
|
26534
|
-
let request;
|
|
26535
|
-
try {
|
|
26536
|
-
request = parseHomeDataRequest(input.request);
|
|
26537
|
-
} catch (error) {
|
|
26538
|
-
return failure("INVALID_INPUT", error instanceof Error ? error.message : "\u9996\u9875\u5361\u7247\u8BF7\u6C42\u65E0\u6548", false);
|
|
26539
|
-
}
|
|
26540
|
-
if (request.agentId !== input.protocol.agentId) {
|
|
26541
|
-
return failure("AGENT_MISMATCH", "\u9996\u9875\u6570\u636E\u8BF7\u6C42\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
26542
|
-
}
|
|
26543
|
-
if (!input.userId.trim()) {
|
|
26544
|
-
return failure("AUTH_REQUIRED", "\u9996\u9875\u6570\u636E\u8BF7\u6C42\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
26545
|
-
}
|
|
26546
|
-
const resources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
26547
|
-
const specs = aggregateMcpServers(resources, input.protocol.agentId);
|
|
26548
|
-
const spec = specs.find((candidate) => candidate.serverName === request.binding.mcpName);
|
|
26549
|
-
if (!spec) {
|
|
26550
|
-
return failure("MCP_NOT_BOUND", "\u5F53\u524D Agent \u672A\u7ED1\u5B9A\u8BE5 MCP", false);
|
|
26551
|
-
}
|
|
26552
|
-
if (spec.allowedTools && !spec.allowedTools.has(request.binding.toolName)) {
|
|
26553
|
-
return failure("TOOL_NOT_ALLOWED", "\u5F53\u524D Agent \u672A\u5141\u8BB8\u8C03\u7528\u8BE5 MCP \u5DE5\u5177", false);
|
|
26554
|
-
}
|
|
26555
|
-
const registry = new McpProxyTool(input.mcpServerProvider, specs, {
|
|
26556
|
-
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
26557
|
-
});
|
|
26558
|
-
try {
|
|
26559
|
-
const handle = await registry.resolve(spec.resourceIds[0], request.binding.toolName, input.signal);
|
|
26560
|
-
if (!handle) {
|
|
26561
|
-
return failure("TOOL_NOT_ALLOWED", "MCP \u5DE5\u5177\u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u7528", false);
|
|
26562
|
-
}
|
|
26563
|
-
const toolInput = {};
|
|
26564
|
-
for (const mapping of request.binding.input) {
|
|
26565
|
-
let value;
|
|
26566
|
-
switch (mapping.source.kind) {
|
|
26567
|
-
case "parameter":
|
|
26568
|
-
value = readJsonPointer(request.parameters, mapping.source.pointer);
|
|
26569
|
-
break;
|
|
26570
|
-
case "runtime-context":
|
|
26571
|
-
value = mapping.source.key === "agentId" ? input.protocol.agentId : input.userId;
|
|
26572
|
-
break;
|
|
26573
|
-
case "literal":
|
|
26574
|
-
value = mapping.source.value;
|
|
26575
|
-
break;
|
|
26576
|
-
}
|
|
26577
|
-
if (value === void 0 || !writeJsonPointer(toolInput, mapping.target, value)) {
|
|
26578
|
-
return failure("INVALID_INPUT", `\u65E0\u6CD5\u751F\u6210 MCP \u5165\u53C2 ${mapping.target}`, false);
|
|
26579
|
-
}
|
|
26580
|
-
}
|
|
26581
|
-
let result;
|
|
26582
|
-
try {
|
|
26583
|
-
result = await handle.execute(toolInput, input.signal);
|
|
26584
|
-
} catch (error) {
|
|
26585
|
-
if (isMcpPhoneAuthorizationError(error))
|
|
26586
|
-
throw error;
|
|
26587
|
-
return failure("EXECUTION_FAILED", error instanceof Error ? error.message : "MCP \u5DE5\u5177\u8C03\u7528\u5931\u8D25", true);
|
|
26588
|
-
}
|
|
26589
|
-
const structured = readStructuredContent2(result);
|
|
26590
|
-
let cardData = structured;
|
|
26591
|
-
if (request.binding.transform) {
|
|
26592
|
-
try {
|
|
26593
|
-
cardData = executeStructuralTransform(request.binding.transform, structured);
|
|
26594
|
-
} catch (error) {
|
|
26595
|
-
return failure("TRANSFORM_FAILED", error instanceof Error ? error.message : "\u9996\u9875\u5361\u7247\u6570\u636E\u8F6C\u6362\u5931\u8D25", false);
|
|
26596
|
-
}
|
|
26597
|
-
}
|
|
26598
|
-
const cardDataObject = cloneJsonObject(cardData);
|
|
26599
|
-
if (!cardDataObject) {
|
|
26600
|
-
return failure("INVALID_CARD_DATA", "\u9996\u9875\u5361\u7247\u6570\u636E\u5FC5\u987B\u662F JSON object", false);
|
|
26601
|
-
}
|
|
26602
|
-
return { ok: true, data: cardDataObject };
|
|
26603
|
-
} finally {
|
|
26604
|
-
await registry.closeAll();
|
|
26605
|
-
}
|
|
26606
|
-
}
|
|
26607
|
-
function readStructuredContent2(result) {
|
|
26608
|
-
const object3 = cloneJsonObject(result);
|
|
26609
|
-
if (!object3)
|
|
26610
|
-
return void 0;
|
|
26611
|
-
if (cloneJsonObject(object3.structuredContent)) {
|
|
26612
|
-
return object3.structuredContent;
|
|
26613
|
-
}
|
|
26614
|
-
if (!Array.isArray(object3.content) || object3.content.length !== 1) {
|
|
26615
|
-
return void 0;
|
|
26616
|
-
}
|
|
26617
|
-
const content = cloneJsonObject(object3.content[0]);
|
|
26618
|
-
if (!content || content.type !== "text" || typeof content.text !== "string") {
|
|
26619
|
-
return void 0;
|
|
26620
|
-
}
|
|
26621
|
-
try {
|
|
26622
|
-
return JSON.parse(content.text);
|
|
26623
|
-
} catch {
|
|
26624
|
-
return void 0;
|
|
26625
|
-
}
|
|
26626
|
-
}
|
|
26627
|
-
function failure(code, message, retryable) {
|
|
26628
|
-
return { ok: false, error: { code, message, retryable } };
|
|
26629
|
-
}
|
|
26630
|
-
|
|
26631
|
-
// ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
|
|
26632
|
-
var CardActionDiagnostics = class {
|
|
26633
|
-
sink;
|
|
26634
|
-
layer;
|
|
26635
|
-
operation;
|
|
26636
|
-
stage = "validate";
|
|
26637
|
-
context;
|
|
26638
|
-
debugLog;
|
|
26639
|
-
startedAt = performance.now();
|
|
26640
|
-
sensitiveValues = /* @__PURE__ */ new Set();
|
|
26641
|
-
constructor(sink, context2, layer = "runtime", operation = "a2uiAction.execute") {
|
|
26642
|
-
this.sink = sink;
|
|
26643
|
-
this.layer = layer;
|
|
26644
|
-
this.operation = operation;
|
|
26645
|
-
this.context = { ...context2 };
|
|
26646
|
-
if (sink) {
|
|
26647
|
-
this.debugLog = (line, scope) => {
|
|
26648
|
-
this.write("diagnostic", { message: line }, scope);
|
|
26649
|
-
};
|
|
26650
|
-
}
|
|
26651
|
-
}
|
|
26652
|
-
/** 根据绑定路径登记敏感值;解析仅为日志服务,失败不影响业务。 */
|
|
26653
|
-
protect(readValue) {
|
|
26654
|
-
if (!this.sink)
|
|
26655
|
-
return;
|
|
26656
|
-
try {
|
|
26657
|
-
const value = readValue();
|
|
26658
|
-
if (typeof value === "string" && value)
|
|
26659
|
-
this.sensitiveValues.add(value);
|
|
26660
|
-
} catch {
|
|
26661
|
-
}
|
|
26662
|
-
}
|
|
26663
|
-
write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
|
|
26664
|
-
if (!this.sink)
|
|
26665
|
-
return;
|
|
26666
|
-
try {
|
|
26667
|
-
const record2 = { ...this.context, ...fields };
|
|
26668
|
-
if (record2.message)
|
|
26669
|
-
record2.message = sanitizeDiagnosticText(redactKnownValues(record2.message, this.sensitiveValues));
|
|
26670
|
-
if (record2.errorName)
|
|
26671
|
-
record2.errorName = sanitizeDiagnosticText(redactKnownValues(record2.errorName, this.sensitiveValues));
|
|
26672
|
-
if ("input" in record2)
|
|
26673
|
-
record2.input = sanitizeLogValue(record2.input, this.sensitiveValues);
|
|
26674
|
-
if ("output" in record2)
|
|
26675
|
-
record2.output = sanitizeLogValue(record2.output, this.sensitiveValues);
|
|
26676
|
-
this.sink(JSON.stringify({
|
|
26677
|
-
operation: this.operation,
|
|
26678
|
-
level: "info",
|
|
26679
|
-
layer: this.layer,
|
|
26680
|
-
event,
|
|
26681
|
-
stage: this.stage,
|
|
26682
|
-
...record2,
|
|
26683
|
-
costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
|
|
26684
|
-
}), scope);
|
|
26685
|
-
} catch {
|
|
26686
|
-
}
|
|
26687
|
-
}
|
|
26688
|
-
error(event, error) {
|
|
26689
|
-
if (!this.sink)
|
|
26690
|
-
return;
|
|
26691
|
-
try {
|
|
26692
|
-
this.write(event, {
|
|
26693
|
-
errorName: error instanceof Error ? error.name : typeof error,
|
|
26694
|
-
message: error instanceof Error ? error.message : typeof error === "string" ? error : "\u975E\u6807\u51C6\u5F02\u5E38"
|
|
26695
|
-
});
|
|
26696
|
-
} catch {
|
|
26697
|
-
}
|
|
26698
|
-
}
|
|
26699
|
-
};
|
|
26700
|
-
function sanitizeLogValue(value, sensitiveValues) {
|
|
26701
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
26702
|
-
let nodes = 200;
|
|
26703
|
-
let characters = 4e3;
|
|
26704
|
-
const visit = (item, depth, key = "") => {
|
|
26705
|
-
if (/authorization|cookie|token|secret|password|api[_-]?key|access[_-]?key|private[_-]?key|^(?:ak|sk|userId|orderId|tradeNO|phone|mobile|email|idCard)$/iu.test(key)) {
|
|
26706
|
-
if (typeof item === "string" && item)
|
|
26707
|
-
sensitiveValues.add(item);
|
|
26708
|
-
return "<redacted>";
|
|
26709
|
-
}
|
|
26710
|
-
if (--nodes < 0 || depth > 8 || characters <= 0)
|
|
26711
|
-
return "<truncated>";
|
|
26712
|
-
if (item === null || typeof item === "number" || typeof item === "boolean")
|
|
26713
|
-
return item;
|
|
26714
|
-
if (typeof item === "string") {
|
|
26715
|
-
if (/^\s*[{[]/u.test(item)) {
|
|
26716
|
-
if (item.length > 16e3)
|
|
26717
|
-
return "<truncated JSON>";
|
|
26718
|
-
try {
|
|
26719
|
-
return JSON.stringify(visit(JSON.parse(item), depth + 1));
|
|
26720
|
-
} catch {
|
|
26721
|
-
return "<invalid JSON>";
|
|
26722
|
-
}
|
|
26723
|
-
}
|
|
26724
|
-
const text2 = sanitizeDiagnosticText(redactKnownValues(item, sensitiveValues));
|
|
26725
|
-
const result2 = text2.slice(0, Math.min(512, characters));
|
|
26726
|
-
characters -= result2.length;
|
|
26727
|
-
return result2.length < item.length ? `${result2}<truncated>` : result2;
|
|
26728
|
-
}
|
|
26729
|
-
if (typeof item !== "object")
|
|
26730
|
-
return `<${typeof item}>`;
|
|
26731
|
-
if (seen.has(item))
|
|
26732
|
-
return "<circular>";
|
|
26733
|
-
seen.add(item);
|
|
26734
|
-
try {
|
|
26735
|
-
const keys = Object.keys(item);
|
|
26736
|
-
const result2 = /* @__PURE__ */ Object.create(null);
|
|
26737
|
-
for (const name of keys.slice(0, 20)) {
|
|
26738
|
-
const descriptor = Object.getOwnPropertyDescriptor(item, name);
|
|
26739
|
-
if (name === "value" && Object.getOwnPropertyDescriptor(item, "kind")?.value === "literal" && typeof descriptor?.value === "string" && descriptor.value)
|
|
26740
|
-
sensitiveValues.add(descriptor.value);
|
|
26741
|
-
result2[name.slice(0, 100)] = name === "value" && Object.getOwnPropertyDescriptor(item, "kind")?.value === "literal" ? "<redacted>" : descriptor && "value" in descriptor ? visit(descriptor.value, depth + 1, name) : "<accessor>";
|
|
26742
|
-
}
|
|
26743
|
-
if (Array.isArray(item)) {
|
|
26744
|
-
const values = Object.values(result2);
|
|
26745
|
-
if (keys.length > 20)
|
|
26746
|
-
values.push("<truncated>");
|
|
26747
|
-
return values;
|
|
26748
|
-
}
|
|
26749
|
-
if (keys.length > 20)
|
|
26750
|
-
result2["<truncated>"] = true;
|
|
26751
|
-
return result2;
|
|
26752
|
-
} catch {
|
|
26753
|
-
return "<unreadable>";
|
|
26754
|
-
} finally {
|
|
26755
|
-
seen.delete(item);
|
|
26756
|
-
}
|
|
26757
|
-
};
|
|
26758
|
-
const result = visit(value, 0);
|
|
26759
|
-
const text = JSON.stringify(result);
|
|
26760
|
-
return text.length > 6e3 ? { truncated: true, preview: text.slice(0, 2e3) } : result;
|
|
26761
|
-
}
|
|
26762
|
-
function sanitizeDiagnosticText(value) {
|
|
26763
|
-
return value.replace(/\b(?:body|arguments|payload|headers)\s*[:=][\s\S]*/giu, "<payload>").replace(/\{[\s\S]*/gu, "<payload>").replace(/https?:\/\/[^\s]+/giu, "<url>").replace(/\b(?:authorization|cookie|set-cookie)\s*[:=][^\r\n]*/giu, "<redacted>").replace(/\bbearer\s+[^\s,;]+/giu, "Bearer <redacted>").replace(/\b((?:api[_-]?key|access[_-]?key|token|secret|password|ak|sk|tradeNO|userId|orderId)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu, "$1<redacted>").replace(/\s+/gu, " ").slice(0, 300);
|
|
26764
|
-
}
|
|
26765
|
-
function redactKnownValues(text, sensitiveValues) {
|
|
26766
|
-
let result = text;
|
|
26767
|
-
for (const sensitive of sensitiveValues)
|
|
26768
|
-
result = result.replaceAll(sensitive, "<redacted>");
|
|
26769
|
-
return result;
|
|
26770
|
-
}
|
|
26771
|
-
|
|
26772
|
-
// ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
|
|
26773
|
-
async function executeCardAction(input) {
|
|
26774
|
-
const diagnostics = new CardActionDiagnostics(input.debugLog, {
|
|
26775
|
-
agentId: input.protocol.agentId,
|
|
26776
|
-
threadId: input.runtimeContext.threadId
|
|
26777
|
-
});
|
|
26778
|
-
diagnostics.protect(() => input.runtimeContext.userId);
|
|
26779
|
-
diagnostics.protect(() => input.runtimeContext.tenantId);
|
|
26780
|
-
diagnostics.write("started", {
|
|
26781
|
-
input: { request: input.request, runtimeContext: input.runtimeContext }
|
|
26782
|
-
});
|
|
26783
|
-
try {
|
|
26784
|
-
const response = await executeCardActionInternal(input, diagnostics);
|
|
26785
|
-
diagnostics.write(response.ok ? "completed" : "failed", response.ok ? { output: response } : {
|
|
26786
|
-
code: response.error.code,
|
|
26787
|
-
retryable: response.error.retryable,
|
|
26788
|
-
output: response
|
|
26789
|
-
});
|
|
26790
|
-
return response;
|
|
26791
|
-
} catch (error) {
|
|
26792
|
-
diagnostics.error("failed", error);
|
|
26793
|
-
throw error;
|
|
26794
|
-
}
|
|
26795
|
-
}
|
|
26796
|
-
async function executeCardActionInternal(input, diagnostics) {
|
|
26797
|
-
let request;
|
|
26798
|
-
try {
|
|
26799
|
-
request = parseA2UIActionExecuteRequest(input.request);
|
|
26800
|
-
} catch (error) {
|
|
26801
|
-
return failure2("INVALID_INPUT", errorMessage(error, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
|
|
26802
|
-
}
|
|
26803
|
-
Object.assign(diagnostics.context, {
|
|
26804
|
-
invocationId: request.invocationId,
|
|
26805
|
-
cardRef: request.source.cardRef,
|
|
26806
|
-
cardRevision: request.source.cardRevision
|
|
26807
|
-
});
|
|
26808
|
-
if (request.agentId !== input.protocol.agentId)
|
|
26809
|
-
return failure2("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
26810
|
-
if (request.threadId !== input.runtimeContext.threadId)
|
|
26811
|
-
return failure2("INVALID_INPUT", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D\u4F1A\u8BDD\u4E0D\u5339\u914D", false);
|
|
26812
|
-
if (!input.runtimeContext.userId.trim())
|
|
26813
|
-
return failure2("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
26814
|
-
diagnostics.write("validated", { output: request });
|
|
26815
|
-
diagnostics.stage = "binding";
|
|
26816
|
-
diagnostics.write("binding_started", { input: { source: request.source } });
|
|
26817
|
-
const resolved = resolvePaymentAction(input.protocol, request.source);
|
|
26818
|
-
if (!resolved.ok) {
|
|
26819
|
-
diagnostics.write("binding_failed", { output: resolved.response });
|
|
26820
|
-
return resolved.response;
|
|
26821
|
-
}
|
|
26822
|
-
const args = materializePaymentInput(resolved.payment.createTrade.input, request.input);
|
|
26823
|
-
if (!args)
|
|
26824
|
-
return failure2("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
|
|
26825
|
-
const createTrade = resolved.payment.createTrade;
|
|
26826
|
-
Object.assign(diagnostics.context, {
|
|
26827
|
-
mcpResourceId: createTrade.mcpResourceId,
|
|
26828
|
-
toolName: createTrade.toolName
|
|
26829
|
-
});
|
|
26830
|
-
diagnostics.write("binding_resolved", { output: createTrade });
|
|
26831
|
-
diagnostics.stage = "tool_resolve";
|
|
26832
|
-
const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog, input.phoneAuthorization);
|
|
26833
|
-
try {
|
|
26834
|
-
diagnostics.write("tool_resolve_started", { input: createTrade });
|
|
26835
|
-
const tool = await registry.resolve(createTrade.mcpResourceId, createTrade.toolName, input.signal);
|
|
26836
|
-
diagnostics.write("tool_resolved", {
|
|
26837
|
-
output: {
|
|
26838
|
-
found: Boolean(tool),
|
|
26839
|
-
inputSchema: tool?.inputSchema,
|
|
26840
|
-
outputSchema: tool?.outputSchema
|
|
26841
|
-
}
|
|
26842
|
-
});
|
|
26843
|
-
if (!tool)
|
|
26844
|
-
return failure2("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
26845
|
-
diagnostics.stage = "tool_input";
|
|
26846
|
-
const inputSchema = cloneJsonObject(tool.inputSchema);
|
|
26847
|
-
if (inputSchema && validateJsonSchemaValue(inputSchema, args).length > 0) {
|
|
26848
|
-
return failure2("INVALID_INPUT", "\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2\u4E0D\u7B26\u5408 Tool Schema", false);
|
|
26849
|
-
}
|
|
26850
|
-
diagnostics.write("tool_input_completed", { output: { args } });
|
|
26851
|
-
let result;
|
|
26852
|
-
diagnostics.stage = "tool_execute";
|
|
26853
|
-
diagnostics.write("tool_started", { input: args });
|
|
26854
|
-
try {
|
|
26855
|
-
result = await tool.execute(args, input.signal);
|
|
26856
|
-
diagnostics.protect(() => readJsonPointer(readStructuredContent3(result), createTrade.tradeNoPath));
|
|
26857
|
-
diagnostics.write("tool_completed", { output: result });
|
|
26858
|
-
} catch (error) {
|
|
26859
|
-
diagnostics.error("tool_failed", error);
|
|
26860
|
-
if (isMcpPhoneAuthorizationError(error))
|
|
26861
|
-
throw error;
|
|
26862
|
-
return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
|
|
26863
|
-
}
|
|
26864
|
-
diagnostics.stage = "tool_output";
|
|
26865
|
-
const structured = readStructuredContent3(result);
|
|
26866
|
-
const tradeNO = readJsonPointer(structured, createTrade.tradeNoPath);
|
|
26867
|
-
diagnostics.write("tool_output_completed", {
|
|
26868
|
-
output: {
|
|
26869
|
-
structured,
|
|
26870
|
-
tradeNO,
|
|
26871
|
-
valid: typeof tradeNO === "string" && Boolean(tradeNO.trim()) && tradeNO.length <= 64
|
|
26872
|
-
}
|
|
26873
|
-
});
|
|
26874
|
-
if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64)
|
|
26875
|
-
return failure2("INVALID_OUTPUT", "\u521B\u5EFA\u4EA4\u6613 MCP \u672A\u8FD4\u56DE\u6709\u6548 tradeNO", false);
|
|
26876
|
-
return {
|
|
26877
|
-
ok: true,
|
|
26878
|
-
invocationId: request.invocationId,
|
|
26879
|
-
result: { kind: "payment", tradeNO }
|
|
26880
|
-
};
|
|
26881
|
-
} finally {
|
|
26882
|
-
const stage = diagnostics.stage;
|
|
26883
|
-
diagnostics.stage = "cleanup";
|
|
26884
|
-
diagnostics.write("cleanup_started", {
|
|
26885
|
-
input: { mcpResourceId: diagnostics.context.mcpResourceId }
|
|
26886
|
-
});
|
|
26887
|
-
await registry.closeAll();
|
|
26888
|
-
diagnostics.write("cleanup_completed", {
|
|
26889
|
-
output: { closeAttempted: true }
|
|
26890
|
-
});
|
|
26891
|
-
diagnostics.stage = stage;
|
|
26892
|
-
}
|
|
26893
|
-
}
|
|
26894
|
-
function resolvePaymentAction(protocol, source) {
|
|
26895
|
-
const card = protocol.agent.resources.find((resource) => resource.resourceType === EResourceType.CARD && resource.resourceId === source.cardRef);
|
|
26896
|
-
if (!card)
|
|
26897
|
-
return {
|
|
26898
|
-
ok: false,
|
|
26899
|
-
response: failure2("CARD_NOT_FOUND", "\u652F\u4ED8\u5361\u7247\u4E0D\u5B58\u5728", false)
|
|
26900
|
-
};
|
|
26901
|
-
if (card.config.revision !== source.cardRevision) {
|
|
26902
|
-
return {
|
|
26903
|
-
ok: false,
|
|
26904
|
-
response: failure2("CARD_REVISION_MISMATCH", "\u652F\u4ED8\u5361\u7247\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5", false)
|
|
26905
|
-
};
|
|
26906
|
-
}
|
|
26907
|
-
if (card.config.schemaVersion !== "4")
|
|
26908
|
-
return {
|
|
26909
|
-
ok: false,
|
|
26910
|
-
response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u4E0D\u5B58\u5728", false)
|
|
26911
|
-
};
|
|
26912
|
-
const component = findSavedComponent(card.config.a2uiTemplate.content, source.surfaceId, source.componentId);
|
|
26913
|
-
if (!component)
|
|
26914
|
-
return {
|
|
26915
|
-
ok: false,
|
|
26916
|
-
response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u4E0D\u5B58\u5728", false)
|
|
26917
|
-
};
|
|
26918
|
-
const payments = collectPaymentActions(component.action);
|
|
26919
|
-
if (payments.length !== 1)
|
|
26920
|
-
return {
|
|
26921
|
-
ok: false,
|
|
26922
|
-
response: failure2("ACTION_KIND_MISMATCH", "\u7EC4\u4EF6\u5FC5\u987B\u5305\u542B\u552F\u4E00\u652F\u4ED8\u52A8\u4F5C", false)
|
|
26923
|
-
};
|
|
26924
|
-
return { ok: true, payment: payments[0] };
|
|
26925
|
-
}
|
|
26926
|
-
function findSavedComponent(content, surfaceId, componentId) {
|
|
26927
|
-
let parsed;
|
|
26928
|
-
try {
|
|
26929
|
-
parsed = JSON.parse(content);
|
|
26930
|
-
} catch {
|
|
26931
|
-
return void 0;
|
|
26932
|
-
}
|
|
26933
|
-
if (!Array.isArray(parsed))
|
|
26934
|
-
return void 0;
|
|
26935
|
-
const instructions = parsed.flatMap((entry) => {
|
|
26936
|
-
const record2 = cloneJsonObject(entry);
|
|
26937
|
-
return record2 && Array.isArray(record2.datas) ? record2.datas : [entry];
|
|
26938
|
-
});
|
|
26939
|
-
for (const instruction of instructions) {
|
|
26940
|
-
const record2 = cloneJsonObject(instruction);
|
|
26941
|
-
const update = record2 && cloneJsonObject(record2.updateComponents);
|
|
26942
|
-
if (!update || update.surfaceId !== surfaceId || !Array.isArray(update.components))
|
|
26943
|
-
continue;
|
|
26944
|
-
const component = update.components.find((candidate) => {
|
|
26945
|
-
const item = cloneJsonObject(candidate);
|
|
26946
|
-
return item?.id === componentId;
|
|
26947
|
-
});
|
|
26948
|
-
const result = cloneJsonObject(component);
|
|
26949
|
-
if (result)
|
|
26950
|
-
return result;
|
|
26951
|
-
}
|
|
26952
|
-
return void 0;
|
|
26953
|
-
}
|
|
26954
|
-
function collectPaymentActions(value) {
|
|
26955
|
-
const action = cloneJsonObject(value);
|
|
26956
|
-
if (!action)
|
|
26957
|
-
return [];
|
|
26958
|
-
const client = cloneJsonObject(action.client);
|
|
26959
|
-
if (client?.name === "payment.trade-pay") {
|
|
26960
|
-
const context2 = cloneJsonObject(client.context);
|
|
26961
|
-
return context2 ? [context2] : [];
|
|
26962
|
-
}
|
|
26963
|
-
const select = cloneJsonObject(action.select);
|
|
26964
|
-
if (!select)
|
|
26965
|
-
return [];
|
|
26966
|
-
const cases = Array.isArray(select.cases) ? select.cases : [];
|
|
26967
|
-
return [
|
|
26968
|
-
...cases.flatMap((entry) => collectPaymentActions(cloneJsonObject(entry)?.action)),
|
|
26969
|
-
...collectPaymentActions(select.default)
|
|
26970
|
-
];
|
|
26971
|
-
}
|
|
26972
|
-
function materializePaymentInput(definition, supplied) {
|
|
26973
|
-
const materialized = materializeValue(definition, supplied);
|
|
26974
|
-
return cloneJsonObject(materialized);
|
|
26975
|
-
}
|
|
26976
|
-
function materializeValue(definition, supplied) {
|
|
26977
|
-
if (Array.isArray(definition)) {
|
|
26978
|
-
if (!Array.isArray(supplied) || supplied.length !== definition.length)
|
|
26979
|
-
return void 0;
|
|
26980
|
-
const result = definition.map((entry, index) => materializeValue(entry, supplied[index]));
|
|
26981
|
-
return result.some((entry) => entry === void 0) ? void 0 : result;
|
|
26982
|
-
}
|
|
26983
|
-
if (definition && typeof definition === "object") {
|
|
26984
|
-
const keys = Object.keys(definition);
|
|
26985
|
-
if (keys.length === 1 && keys[0] === "path" && typeof definition.path === "string")
|
|
26986
|
-
return supplied;
|
|
26987
|
-
const suppliedObject = cloneJsonObject(supplied);
|
|
26988
|
-
if (!suppliedObject)
|
|
26989
|
-
return void 0;
|
|
26990
|
-
const result = {};
|
|
26991
|
-
for (const [key, entry] of Object.entries(definition)) {
|
|
26992
|
-
const value = materializeValue(entry, suppliedObject[key]);
|
|
26993
|
-
if (value === void 0)
|
|
26994
|
-
return void 0;
|
|
26995
|
-
result[key] = value;
|
|
26996
|
-
}
|
|
26997
|
-
return result;
|
|
26998
|
-
}
|
|
26999
|
-
return definition;
|
|
27000
|
-
}
|
|
27001
|
-
function createRegistry(protocol, provider, debugLog, phoneAuthorization) {
|
|
27002
|
-
const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
27003
|
-
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), {
|
|
27004
|
-
debugLog,
|
|
27005
|
-
authorizeCall: createRequestMcpPhoneAuthorizer(protocol, phoneAuthorization)
|
|
27006
|
-
});
|
|
27007
|
-
}
|
|
27008
|
-
function readStructuredContent3(result) {
|
|
27009
|
-
const object3 = cloneJsonObject(result);
|
|
27010
|
-
if (!object3)
|
|
27011
|
-
return void 0;
|
|
27012
|
-
if (cloneJsonObject(object3.structuredContent))
|
|
27013
|
-
return object3.structuredContent;
|
|
27014
|
-
if (!Array.isArray(object3.content) || object3.content.length !== 1)
|
|
27015
|
-
return void 0;
|
|
27016
|
-
const content = cloneJsonObject(object3.content[0]);
|
|
27017
|
-
if (!content || content.type !== "text" || typeof content.text !== "string")
|
|
27018
|
-
return void 0;
|
|
27019
|
-
try {
|
|
27020
|
-
return JSON.parse(content.text);
|
|
27021
|
-
} catch {
|
|
27022
|
-
return void 0;
|
|
27023
|
-
}
|
|
27024
|
-
}
|
|
27025
|
-
function failure2(code, message, retryable) {
|
|
27026
|
-
return { ok: false, error: { code, message, retryable } };
|
|
27027
|
-
}
|
|
27028
|
-
function errorMessage(error, fallback) {
|
|
27029
|
-
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
27030
|
-
}
|
|
27031
|
-
|
|
27032
|
-
// ../linkque-agent-runtime/dist/esm/core/mcpExecution.js
|
|
27033
|
-
async function executeAuthorizedMcp(input) {
|
|
27034
|
-
if (input.agentId !== input.protocol.agentId)
|
|
27035
|
-
return failure3("AGENT_MISMATCH", "\u8BF7\u6C42\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27036
|
-
if (!input.userId.trim())
|
|
27037
|
-
return failure3("AUTH_REQUIRED", "\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
27038
|
-
const resources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
27039
|
-
const registry = new McpProxyTool(input.mcpServerProvider, aggregateMcpServers(resources, input.protocol.agentId), {
|
|
27040
|
-
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
27041
|
-
});
|
|
27042
|
-
try {
|
|
27043
|
-
const tool = await registry.resolve(input.tool.mcpResourceId, input.tool.toolName, input.signal);
|
|
27044
|
-
if (!tool)
|
|
27045
|
-
return failure3("TOOL_NOT_ALLOWED", "MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
27046
|
-
const schema = cloneJsonObject(tool.inputSchema);
|
|
27047
|
-
if (schema && validateJsonSchemaValue(schema, input.tool.input).length > 0) {
|
|
27048
|
-
return failure3("INVALID_INPUT", "MCP \u5165\u53C2\u4E0D\u7B26\u5408 Tool Schema", false);
|
|
27049
|
-
}
|
|
27050
|
-
let result;
|
|
27051
|
-
try {
|
|
27052
|
-
result = await tool.execute(input.tool.input, input.signal);
|
|
27053
|
-
} catch (error) {
|
|
27054
|
-
if (isMcpPhoneAuthorizationError(error))
|
|
27055
|
-
throw error;
|
|
27056
|
-
return failure3("EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5", false);
|
|
27057
|
-
}
|
|
27058
|
-
const structured = readStructuredContent4(result);
|
|
27059
|
-
if (!isJsonValue2(structured)) {
|
|
27060
|
-
return failure3("INVALID_OUTPUT", "MCP \u672A\u8FD4\u56DE\u6709\u6548 JSON \u7ED3\u679C", false);
|
|
27061
|
-
}
|
|
27062
|
-
return { ok: true, callId: input.callId, result: structured };
|
|
27063
|
-
} finally {
|
|
27064
|
-
await registry.closeAll();
|
|
27065
|
-
}
|
|
27066
|
-
}
|
|
27067
|
-
function readStructuredContent4(result) {
|
|
27068
|
-
const object3 = cloneJsonObject(result);
|
|
27069
|
-
if (!object3)
|
|
27070
|
-
return void 0;
|
|
27071
|
-
if (object3.structuredContent !== void 0)
|
|
27072
|
-
return object3.structuredContent;
|
|
27073
|
-
if (!Array.isArray(object3.content) || object3.content.length !== 1)
|
|
27074
|
-
return void 0;
|
|
27075
|
-
const text = cloneJsonObject(object3.content[0]);
|
|
27076
|
-
if (text?.type !== "text" || typeof text.text !== "string")
|
|
27077
|
-
return void 0;
|
|
27078
|
-
try {
|
|
27079
|
-
return JSON.parse(text.text);
|
|
27080
|
-
} catch {
|
|
27081
|
-
return void 0;
|
|
27082
|
-
}
|
|
27083
|
-
}
|
|
27084
|
-
function isJsonValue2(value) {
|
|
27085
|
-
if (value === null || ["string", "boolean"].includes(typeof value))
|
|
27086
|
-
return true;
|
|
27087
|
-
if (typeof value === "number")
|
|
27088
|
-
return Number.isFinite(value);
|
|
27089
|
-
if (Array.isArray(value))
|
|
27090
|
-
return value.every(isJsonValue2);
|
|
27091
|
-
const object3 = cloneJsonObject(value);
|
|
27092
|
-
return Boolean(object3) && Object.values(object3 ?? {}).every(isJsonValue2);
|
|
27093
|
-
}
|
|
27094
|
-
function failure3(code, message, retryable) {
|
|
27095
|
-
return { ok: false, error: { code, message, retryable } };
|
|
27096
|
-
}
|
|
27097
|
-
|
|
27098
|
-
// ../linkque-agent-runtime/dist/esm/core/functionActionExecutor.js
|
|
27099
|
-
async function executeFunctionActionMcp(input) {
|
|
27100
|
-
let request;
|
|
27101
|
-
try {
|
|
27102
|
-
request = parseA2UIFunctionMcpExecuteRequest(input.request);
|
|
27103
|
-
} catch (error) {
|
|
27104
|
-
return failure4("INVALID_INPUT", errorMessage2(error, "\u51FD\u6570 MCP \u8BF7\u6C42\u65E0\u6548"), false);
|
|
27105
|
-
}
|
|
27106
|
-
if (request.agentId !== input.protocol.agentId) {
|
|
27107
|
-
return failure4("AGENT_MISMATCH", "\u51FD\u6570\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27108
|
-
}
|
|
27109
|
-
if (request.threadId !== input.runtimeContext.threadId || !input.runtimeContext.userId.trim()) {
|
|
27110
|
-
return failure4("AUTH_REQUIRED", "\u51FD\u6570\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u4F1A\u8BDD\u8EAB\u4EFD", false);
|
|
27111
|
-
}
|
|
27112
|
-
return executeAuthorizedMcp({
|
|
27113
|
-
protocol: input.protocol,
|
|
27114
|
-
agentId: request.agentId,
|
|
27115
|
-
userId: input.runtimeContext.userId,
|
|
27116
|
-
callId: request.callId,
|
|
27117
|
-
tool: request.tool,
|
|
27118
|
-
mcpServerProvider: input.mcpServerProvider,
|
|
27119
|
-
signal: input.signal,
|
|
27120
|
-
phoneAuthorization: input.phoneAuthorization
|
|
27121
|
-
});
|
|
27122
|
-
}
|
|
27123
|
-
function failure4(code, message, retryable) {
|
|
27124
|
-
return { ok: false, error: { code, message, retryable } };
|
|
27125
|
-
}
|
|
27126
|
-
function errorMessage2(error, fallback) {
|
|
27127
|
-
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
27128
|
-
}
|
|
27129
|
-
|
|
27130
|
-
// ../linkque-agent-runtime/dist/esm/core/inMemorySessionManager.js
|
|
27131
|
-
var InMemorySessionManager = class {
|
|
27132
|
-
/** 私有会话历史表:sessionId → 累积的 IAgentTurn[]。 */
|
|
27133
|
-
sessions = /* @__PURE__ */ new Map();
|
|
27134
|
-
async load(sessionId) {
|
|
27135
|
-
return this.sessions.get(sessionId) ?? [];
|
|
27136
|
-
}
|
|
27137
|
-
async append(sessionId, turn) {
|
|
27138
|
-
await this.appendMany(sessionId, [turn]);
|
|
27139
|
-
}
|
|
27140
|
-
async appendMany(sessionId, newTurns) {
|
|
27141
|
-
const turns = this.sessions.get(sessionId);
|
|
27142
|
-
if (turns) {
|
|
27143
|
-
turns.push(...newTurns);
|
|
27144
|
-
} else {
|
|
27145
|
-
this.sessions.set(sessionId, [...newTurns]);
|
|
27146
|
-
}
|
|
27147
|
-
}
|
|
27148
|
-
};
|
|
27149
|
-
|
|
27150
|
-
// ../linkque-agent-runtime/dist/esm/core/noopSkillLoader.js
|
|
27151
|
-
var NoopSkillLoader = class {
|
|
27152
|
-
async load(_resources) {
|
|
27153
|
-
return [];
|
|
27154
|
-
}
|
|
27155
|
-
};
|
|
27156
|
-
|
|
27157
|
-
// ../linkque-agent-runtime/dist/esm/core/noopMcpServerProvider.js
|
|
27158
|
-
var NoopMcpServerProvider = class {
|
|
27159
|
-
async servers(_resources) {
|
|
27160
|
-
return [];
|
|
27161
|
-
}
|
|
27162
|
-
};
|
|
27163
|
-
|
|
27164
|
-
// ../linkque-agent-runtime/dist/esm/core/hook/hookContext.js
|
|
27165
|
-
function buildHookCommonParams(input) {
|
|
27166
|
-
const userTurns = input.history.reduce((count, turn) => turn.role === "user" ? count + 1 : count, 0);
|
|
27167
|
-
const commonParams = {
|
|
27168
|
-
agentId: input.agentId,
|
|
27169
|
-
runId: input.request.runId,
|
|
27170
|
-
conversationId: input.request.threadId,
|
|
27171
|
-
threadId: input.request.threadId,
|
|
27172
|
-
runIndex: input.hostParams?.runIndex ?? userTurns + 1
|
|
27173
|
-
};
|
|
27174
|
-
if (input.sessionId !== void 0)
|
|
27175
|
-
commonParams.sessionId = input.sessionId;
|
|
27176
|
-
if (input.userId !== void 0)
|
|
27177
|
-
commonParams.userId = input.userId;
|
|
27178
|
-
if (input.hostParams?.traceId !== void 0) {
|
|
27179
|
-
commonParams.traceId = input.hostParams.traceId;
|
|
27180
|
-
}
|
|
27181
|
-
return commonParams;
|
|
27182
|
-
}
|
|
27183
|
-
function createHookEventId(commonParams, stage, hookResourceId, sequence) {
|
|
27184
|
-
return `${commonParams.runId}:${stage}:${hookResourceId}:${sequence}`;
|
|
27185
|
-
}
|
|
27186
|
-
var HookEventSequencer = class {
|
|
27187
|
-
counters = /* @__PURE__ */ new Map();
|
|
27188
|
-
/** 取下一序号(1-based)。 */
|
|
27189
|
-
next(stage, hookResourceId) {
|
|
27190
|
-
const key = `${stage}:${hookResourceId}`;
|
|
27191
|
-
const nextValue = (this.counters.get(key) ?? 0) + 1;
|
|
27192
|
-
this.counters.set(key, nextValue);
|
|
27193
|
-
return nextValue;
|
|
27194
|
-
}
|
|
27195
|
-
};
|
|
27196
|
-
function buildHookContextBase(resource, stage, commonParams, eventId, timestamp) {
|
|
27197
|
-
return {
|
|
27198
|
-
version: "1.0",
|
|
27199
|
-
stage,
|
|
27200
|
-
hookId: resource.resourceId,
|
|
27201
|
-
hookName: resource.config.name,
|
|
27202
|
-
eventId,
|
|
27203
|
-
timestamp,
|
|
27204
|
-
commonParams
|
|
27205
|
-
};
|
|
27206
|
-
}
|
|
27207
|
-
|
|
27208
|
-
// ../linkque-agent-runtime/dist/esm/core/hook/hookRegistry.js
|
|
27209
|
-
var DEFAULT_HOOK_ORDER = 100;
|
|
27210
|
-
var DEFAULT_HOOK_TIMEOUT_MS = 1e3;
|
|
27211
|
-
var MAX_HOOK_TIMEOUT_MS = 5e3;
|
|
27212
|
-
function normalizeHookResources(resources) {
|
|
27213
|
-
return resources.filter((resource) => resource.config.enabled !== false).map((resource) => {
|
|
27214
|
-
const config = Object.assign({}, resource.config, {
|
|
27215
|
-
order: resource.config.order ?? DEFAULT_HOOK_ORDER,
|
|
27216
|
-
timeoutMs: Math.min(Math.max(resource.config.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS, 0), MAX_HOOK_TIMEOUT_MS)
|
|
27217
|
-
});
|
|
27218
|
-
return Object.assign({}, resource, { config });
|
|
27219
|
-
}).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
|
|
27220
|
-
}
|
|
27221
|
-
|
|
27222
26053
|
// ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
|
|
26054
|
+
var CONTENT_VALUE_MAX_LENGTH = 16 * 1024;
|
|
27223
26055
|
var ETelemetryAttribute;
|
|
27224
26056
|
(function(ETelemetryAttribute2) {
|
|
27225
26057
|
ETelemetryAttribute2["HARNESS_TELEMETRY_SCHEMA_VERSION"] = "harness.telemetry.schema.version";
|
|
@@ -27276,6 +26108,7 @@ var ETelemetryAttribute;
|
|
|
27276
26108
|
ETelemetryAttribute2["GEN_AI_REQUEST_MODEL"] = "gen_ai.request.model";
|
|
27277
26109
|
ETelemetryAttribute2["GEN_AI_RESPONSE_MODEL"] = "gen_ai.response.model";
|
|
27278
26110
|
ETelemetryAttribute2["GEN_AI_RESPONSE_ID"] = "gen_ai.response.id";
|
|
26111
|
+
ETelemetryAttribute2["LINKQUE_CONTENT_VALUE_TRUNCATED"] = "linkque.content.value.truncated";
|
|
27279
26112
|
ETelemetryAttribute2["GEN_AI_RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
27280
26113
|
ETelemetryAttribute2["GEN_AI_USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
27281
26114
|
ETelemetryAttribute2["GEN_AI_USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
@@ -27379,11 +26212,13 @@ var ETelemetryEventName;
|
|
|
27379
26212
|
ETelemetryEventName2["HISTORY_APPEND_FINISHED"] = "linkque.history.append.finished";
|
|
27380
26213
|
ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
|
|
27381
26214
|
ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
|
|
27382
|
-
ETelemetryEventName2["
|
|
26215
|
+
ETelemetryEventName2["CONTENT_RECORDED"] = "linkque.content.recorded";
|
|
27383
26216
|
})(ETelemetryEventName || (ETelemetryEventName = {}));
|
|
27384
26217
|
var ETelemetryContentSection;
|
|
27385
26218
|
(function(ETelemetryContentSection2) {
|
|
27386
26219
|
ETelemetryContentSection2["QUERY_INPUT"] = "query.input";
|
|
26220
|
+
ETelemetryContentSection2["MODEL_OUTPUT"] = "model.output";
|
|
26221
|
+
ETelemetryContentSection2["MCP_ACTION_OUTPUT"] = "mcp_action.output";
|
|
27387
26222
|
ETelemetryContentSection2["TOOL_INPUT"] = "tool.input";
|
|
27388
26223
|
ETelemetryContentSection2["TOOL_OUTPUT"] = "tool.output";
|
|
27389
26224
|
ETelemetryContentSection2["MCP_REQUESTED_INPUT"] = "mcp.requested_input";
|
|
@@ -27561,6 +26396,1231 @@ var ETelemetryVersion;
|
|
|
27561
26396
|
ETelemetryVersion2["V1_0"] = "1.0";
|
|
27562
26397
|
})(ETelemetryVersion || (ETelemetryVersion = {}));
|
|
27563
26398
|
|
|
26399
|
+
// ../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js
|
|
26400
|
+
function recordContentSection(observation, section, value, availability = "available") {
|
|
26401
|
+
observation?.record(ETelemetryEventName.CONTENT_RECORDED, {}, { section, value, availability });
|
|
26402
|
+
}
|
|
26403
|
+
function recordMcpContentSection(observation, section, value, schema) {
|
|
26404
|
+
if (!observation)
|
|
26405
|
+
return;
|
|
26406
|
+
const fieldTitles = {};
|
|
26407
|
+
const visit = (node, path2) => {
|
|
26408
|
+
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
26409
|
+
return;
|
|
26410
|
+
const definition = node;
|
|
26411
|
+
if (path2 && typeof definition.title === "string" && definition.title.trim())
|
|
26412
|
+
fieldTitles[path2] = definition.title;
|
|
26413
|
+
const properties = definition.properties;
|
|
26414
|
+
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
26415
|
+
for (const [key, child] of Object.entries(properties))
|
|
26416
|
+
visit(child, `${path2}/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`);
|
|
26417
|
+
}
|
|
26418
|
+
if (definition.items)
|
|
26419
|
+
visit(definition.items, `${path2}/*`);
|
|
26420
|
+
};
|
|
26421
|
+
visit(schema, section === ETelemetryContentSection.MCP_OUTPUT ? "/structuredContent" : "");
|
|
26422
|
+
observation.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
|
|
26423
|
+
section,
|
|
26424
|
+
value,
|
|
26425
|
+
availability: "available",
|
|
26426
|
+
...Object.keys(fieldTitles).length ? { fieldTitles } : {}
|
|
26427
|
+
});
|
|
26428
|
+
}
|
|
26429
|
+
|
|
26430
|
+
// ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
|
|
26431
|
+
var MCP_PROXY_TOOL_NAME = "mcp";
|
|
26432
|
+
var McpProxyTool = class {
|
|
26433
|
+
provider;
|
|
26434
|
+
/** serverName → 缓存条目(同 serverName 多 resourceId 聚合为一个连接)。 */
|
|
26435
|
+
entries = /* @__PURE__ */ new Map();
|
|
26436
|
+
/** 进行中的连接(去重并发 ensureEntry)。 */
|
|
26437
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
26438
|
+
specByServerName;
|
|
26439
|
+
/** 原始 resourceId → 所属 spec(resolve(resourceId,...) 反查用)。 */
|
|
26440
|
+
specByResourceId;
|
|
26441
|
+
specs;
|
|
26442
|
+
debugLog;
|
|
26443
|
+
authorizeCall;
|
|
26444
|
+
constructor(provider, specs, options = {}) {
|
|
26445
|
+
this.provider = provider;
|
|
26446
|
+
this.specs = specs;
|
|
26447
|
+
this.specByServerName = new Map(specs.map((spec) => [spec.serverName, spec]));
|
|
26448
|
+
this.specByResourceId = new Map(specs.flatMap((spec) => spec.resourceIds.map((id) => [id, spec])));
|
|
26449
|
+
this.debugLog = options.debugLog ?? (() => {
|
|
26450
|
+
});
|
|
26451
|
+
this.authorizeCall = options.authorizeCall;
|
|
26452
|
+
}
|
|
26453
|
+
/**
|
|
26454
|
+
* 产单个 `mcp` 代理工具描述符,注入 `agentReq.tools`。
|
|
26455
|
+
* `execute` 闭包按入参字段派发到 status/connect/list/search/describe/call。
|
|
26456
|
+
*/
|
|
26457
|
+
asTool() {
|
|
26458
|
+
return {
|
|
26459
|
+
name: MCP_PROXY_TOOL_NAME,
|
|
26460
|
+
modelName: MCP_PROXY_TOOL_NAME,
|
|
26461
|
+
label: "MCP",
|
|
26462
|
+
description: MCP_PROXY_DESCRIPTION,
|
|
26463
|
+
inputSchema: MCP_PROXY_INPUT_SCHEMA,
|
|
26464
|
+
execute: (args, signal, context2) => this.dispatch(args, signal, context2)
|
|
26465
|
+
};
|
|
26466
|
+
}
|
|
26467
|
+
/** {@link IMcpToolRegistry.resolve}:按 (resourceId, toolName) 解析可调用句柄。 */
|
|
26468
|
+
async resolve(resourceId, toolName, signal) {
|
|
26469
|
+
const spec = this.findSpec(resourceId);
|
|
26470
|
+
if (!spec)
|
|
26471
|
+
return void 0;
|
|
26472
|
+
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
26473
|
+
if (!entry || !entry.server)
|
|
26474
|
+
return void 0;
|
|
26475
|
+
const tool = entry.tools.find((t) => t.name === toolName);
|
|
26476
|
+
if (!tool)
|
|
26477
|
+
return void 0;
|
|
26478
|
+
return {
|
|
26479
|
+
inputSchema: tool.inputSchema,
|
|
26480
|
+
outputSchema: tool.outputSchema,
|
|
26481
|
+
execute: async (args, sig, context2) => {
|
|
26482
|
+
const headers = await this.authorizeCall?.({
|
|
26483
|
+
resourceIds: [resourceId],
|
|
26484
|
+
toolName: tool.name,
|
|
26485
|
+
signal: sig,
|
|
26486
|
+
context: context2
|
|
26487
|
+
});
|
|
26488
|
+
return entry.server.callTool(tool.name, args, sig, {
|
|
26489
|
+
toolSchema: {
|
|
26490
|
+
inputSchema: tool.inputSchema,
|
|
26491
|
+
outputSchema: tool.outputSchema
|
|
26492
|
+
},
|
|
26493
|
+
...headers ? { headers } : {},
|
|
26494
|
+
...context2 ? { context: context2 } : {}
|
|
26495
|
+
});
|
|
26496
|
+
}
|
|
26497
|
+
};
|
|
26498
|
+
}
|
|
26499
|
+
/** 关闭所有已连 server(忽略单 server 关闭错误)。 */
|
|
26500
|
+
async closeAll() {
|
|
26501
|
+
await Promise.all([...this.entries.values()].map(async (entry) => {
|
|
26502
|
+
if (!entry.server)
|
|
26503
|
+
return;
|
|
26504
|
+
try {
|
|
26505
|
+
await entry.server.close?.();
|
|
26506
|
+
} catch (error) {
|
|
26507
|
+
try {
|
|
26508
|
+
this.debugLog(`[mcp] server ${entry.server.serverName} close failed: ${error instanceof Error ? error.message : "unknown error"}`, EDebugLogScope.MCP);
|
|
26509
|
+
} catch {
|
|
26510
|
+
}
|
|
26511
|
+
}
|
|
26512
|
+
}));
|
|
26513
|
+
}
|
|
26514
|
+
// —— 内部:连接与缓存 ——
|
|
26515
|
+
/** 确保某 server 已连;返回 connected 条目,依失败返回 null(不抛错)。 */
|
|
26516
|
+
async ensureEntry(serverName, signal) {
|
|
26517
|
+
const existing = this.entries.get(serverName);
|
|
26518
|
+
if (existing) {
|
|
26519
|
+
return existing.status === "connected" ? existing : null;
|
|
26520
|
+
}
|
|
26521
|
+
let promise = this.inFlight.get(serverName);
|
|
26522
|
+
if (!promise) {
|
|
26523
|
+
promise = this.connect(serverName, signal).finally(() => {
|
|
26524
|
+
this.inFlight.delete(serverName);
|
|
26525
|
+
});
|
|
26526
|
+
this.inFlight.set(serverName, promise);
|
|
26527
|
+
}
|
|
26528
|
+
const entry = await promise;
|
|
26529
|
+
return entry.status === "connected" ? entry : null;
|
|
26530
|
+
}
|
|
26531
|
+
/** 连单个 server 并 listTools;按 spec.allowedTools 过滤后缓存;失败记为 failed。 */
|
|
26532
|
+
async connect(serverName, _signal) {
|
|
26533
|
+
const spec = this.specByServerName.get(serverName);
|
|
26534
|
+
if (!spec) {
|
|
26535
|
+
const entry = {
|
|
26536
|
+
server: null,
|
|
26537
|
+
tools: [],
|
|
26538
|
+
status: "failed",
|
|
26539
|
+
error: `unknown serverName: ${serverName}`
|
|
26540
|
+
};
|
|
26541
|
+
this.entries.set(serverName, entry);
|
|
26542
|
+
this.debugLog(`[mcp] server ${serverName} unknown serverName`, EDebugLogScope.MCP);
|
|
26543
|
+
return entry;
|
|
26544
|
+
}
|
|
26545
|
+
try {
|
|
26546
|
+
const synthetic = {
|
|
26547
|
+
resourceId: spec.serverName,
|
|
26548
|
+
resourceType: EResourceType.MCP,
|
|
26549
|
+
providerType: EResourceProviderType.ALIPAY_OPEN,
|
|
26550
|
+
config: {
|
|
26551
|
+
agentId: spec.agentId,
|
|
26552
|
+
serverName: spec.serverName,
|
|
26553
|
+
description: spec.description,
|
|
26554
|
+
argsMappingRules: spec.argsMappingRules
|
|
26555
|
+
}
|
|
26556
|
+
};
|
|
26557
|
+
const servers = await this.provider.servers([synthetic]);
|
|
26558
|
+
const server = servers[0];
|
|
26559
|
+
if (!server) {
|
|
26560
|
+
throw new Error(`provider returned no server for ${spec.serverName}`);
|
|
26561
|
+
}
|
|
26562
|
+
const all = await server.listTools();
|
|
26563
|
+
const tools = spec.allowedTools ? all.filter((tool) => spec.allowedTools.has(tool.name)) : all;
|
|
26564
|
+
const entry = { server, tools, status: "connected" };
|
|
26565
|
+
this.entries.set(serverName, entry);
|
|
26566
|
+
this.debugLog(`[mcp] server ${spec.serverName} connected (${tools.length}/${all.length} tools)`, EDebugLogScope.MCP);
|
|
26567
|
+
return entry;
|
|
26568
|
+
} catch (error) {
|
|
26569
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26570
|
+
const entry = {
|
|
26571
|
+
server: null,
|
|
26572
|
+
tools: [],
|
|
26573
|
+
status: "failed",
|
|
26574
|
+
error: message
|
|
26575
|
+
};
|
|
26576
|
+
this.entries.set(serverName, entry);
|
|
26577
|
+
this.debugLog(`[mcp] server ${spec.serverName} connect failed: ${message}`, EDebugLogScope.MCP);
|
|
26578
|
+
return entry;
|
|
26579
|
+
}
|
|
26580
|
+
}
|
|
26581
|
+
// —— 派发 ——
|
|
26582
|
+
/** 按入参字段派发;返回 LLM 可读文本。 */
|
|
26583
|
+
async dispatch(args, signal, context2) {
|
|
26584
|
+
const params = parseProxyArgs(args);
|
|
26585
|
+
if (params.connect !== void 0) {
|
|
26586
|
+
return this.executeConnect(params.connect, signal, context2);
|
|
26587
|
+
}
|
|
26588
|
+
if (params.describe !== void 0) {
|
|
26589
|
+
return this.executeDescribe(params.describe, params.server, signal, context2);
|
|
26590
|
+
}
|
|
26591
|
+
if (params.searches !== void 0) {
|
|
26592
|
+
return this.executeBatchSearch(params.searches, params.server, context2);
|
|
26593
|
+
}
|
|
26594
|
+
if (params.search !== void 0) {
|
|
26595
|
+
const result = await this.executeSearch(params.search, params.server);
|
|
26596
|
+
this.recordAction(context2, "search", result.tools.length ? "matched" : "no_hits", { query: result.query, tools: result.tools });
|
|
26597
|
+
return result.text;
|
|
26598
|
+
}
|
|
26599
|
+
if (params.tool !== void 0) {
|
|
26600
|
+
return this.executeCall(params.tool, params.args, params.server, signal, context2);
|
|
26601
|
+
}
|
|
26602
|
+
if (params.server !== void 0) {
|
|
26603
|
+
return this.executeList(params.server, signal, context2);
|
|
26604
|
+
}
|
|
26605
|
+
return this.executeStatus();
|
|
26606
|
+
}
|
|
26607
|
+
/** 保留代理动作事实,不改变供模型消费的原始返回值。 */
|
|
26608
|
+
recordAction(context2, action, status, data = {}) {
|
|
26609
|
+
recordContentSection(context2?.observation, ETelemetryContentSection.MCP_ACTION_OUTPUT, {
|
|
26610
|
+
action,
|
|
26611
|
+
status,
|
|
26612
|
+
...data
|
|
26613
|
+
});
|
|
26614
|
+
}
|
|
26615
|
+
/** `mcp({})` / `mcp({ status: true })`:列各 server 连接状态 + 工具数。 */
|
|
26616
|
+
executeStatus() {
|
|
26617
|
+
const lines = [];
|
|
26618
|
+
let connected = 0;
|
|
26619
|
+
let totalTools = 0;
|
|
26620
|
+
for (const spec of this.specs) {
|
|
26621
|
+
const label = spec.serverName;
|
|
26622
|
+
const entry = this.entries.get(spec.serverName);
|
|
26623
|
+
if (!entry) {
|
|
26624
|
+
lines.push(`\u25CB ${label} (not connected)`);
|
|
26625
|
+
continue;
|
|
26626
|
+
}
|
|
26627
|
+
if (entry.status === "connected") {
|
|
26628
|
+
connected += 1;
|
|
26629
|
+
totalTools += entry.tools.length;
|
|
26630
|
+
lines.push(`\u2713 ${label} (${entry.tools.length} tools)`);
|
|
26631
|
+
} else {
|
|
26632
|
+
lines.push(`\u2717 ${label} (failed${entry.error ? ": " + entry.error : ""})`);
|
|
26633
|
+
}
|
|
26634
|
+
}
|
|
26635
|
+
const header = `MCP: ${connected}/${this.specs.length} servers, ${totalTools} tools`;
|
|
26636
|
+
const hint = this.specs.length > 0 ? '\nmcp({ server: "name" }) to list tools, mcp({ search: "..." }) to search, mcp({ tool: "...", args: {...} }) to call' : "\n(no MCP resources configured)";
|
|
26637
|
+
return `${header}
|
|
26638
|
+
|
|
26639
|
+
${lines.join("\n")}${hint}`.trim();
|
|
26640
|
+
}
|
|
26641
|
+
/** `mcp({ connect: "server" })`:显式连接并刷元数据,返回该 server 工具列表。 */
|
|
26642
|
+
async executeConnect(server, signal, context2) {
|
|
26643
|
+
const spec = this.findSpec(server);
|
|
26644
|
+
if (!spec) {
|
|
26645
|
+
this.recordAction(context2, "connect", "not_found", { server });
|
|
26646
|
+
return `Server "${server}" not found. Use mcp({}) to see available servers.`;
|
|
26647
|
+
}
|
|
26648
|
+
this.entries.delete(spec.serverName);
|
|
26649
|
+
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
26650
|
+
if (!entry) {
|
|
26651
|
+
this.recordAction(context2, "connect", "failed", { server: spec.serverName });
|
|
26652
|
+
const failed = this.entries.get(spec.serverName);
|
|
26653
|
+
const detail = failed?.error ? `: ${failed.error}` : "";
|
|
26654
|
+
return `Failed to connect to "${spec.serverName}"${detail}.`;
|
|
26655
|
+
}
|
|
26656
|
+
this.recordAction(context2, "connect", "matched", { server: spec.serverName, tools: entry.tools.map((tool) => ({ name: tool.name, description: tool.description })) });
|
|
26657
|
+
return this.formatToolList(spec.serverName, entry.tools);
|
|
26658
|
+
}
|
|
26659
|
+
/** `mcp({ server: "name" })`:列该 server 工具名 + 截断 description。 */
|
|
26660
|
+
async executeList(server, signal, context2) {
|
|
26661
|
+
const spec = this.findSpec(server);
|
|
26662
|
+
if (!spec) {
|
|
26663
|
+
this.recordAction(context2, "list", "not_found", { server });
|
|
26664
|
+
return `Server "${server}" not found. Use mcp({}) to see available servers.`;
|
|
26665
|
+
}
|
|
26666
|
+
const entry = await this.ensureEntry(spec.serverName, signal);
|
|
26667
|
+
if (!entry) {
|
|
26668
|
+
this.recordAction(context2, "list", "failed", { server: spec.serverName });
|
|
26669
|
+
return `Server "${spec.serverName}" is not connected. Use mcp({ connect: "${spec.serverName}" }) to retry.`;
|
|
26670
|
+
}
|
|
26671
|
+
this.recordAction(context2, "list", "matched", { server: spec.serverName, tools: entry.tools.map((tool) => ({ name: tool.name, description: tool.description })) });
|
|
26672
|
+
return this.formatToolList(spec.serverName, entry.tools);
|
|
26673
|
+
}
|
|
26674
|
+
/** `mcp({ search: "query" })`:空格分词 OR 子串匹配 name/description(跨所有 server)。 */
|
|
26675
|
+
async executeSearch(query, serverHint) {
|
|
26676
|
+
const terms = query.trim().split(/\s+/u).filter((t) => t.length > 0);
|
|
26677
|
+
if (terms.length === 0)
|
|
26678
|
+
return { query, text: "Search query cannot be empty.", tools: [] };
|
|
26679
|
+
const pattern = new RegExp(terms.map(escapeRegExp).join("|"), "iu");
|
|
26680
|
+
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26681
|
+
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName)));
|
|
26682
|
+
const matches = [];
|
|
26683
|
+
for (const spec of specs) {
|
|
26684
|
+
const entry = this.entries.get(spec.serverName);
|
|
26685
|
+
if (!entry || entry.status !== "connected")
|
|
26686
|
+
continue;
|
|
26687
|
+
for (const tool of entry.tools) {
|
|
26688
|
+
if (pattern.test(tool.name) || pattern.test(tool.description ?? "")) {
|
|
26689
|
+
matches.push({ server: spec.serverName, tool });
|
|
26690
|
+
}
|
|
26691
|
+
}
|
|
26692
|
+
}
|
|
26693
|
+
const tools = matches.map(({ server, tool }) => ({ server, name: tool.name, description: tool.description, inputSchema: tool.inputSchema }));
|
|
26694
|
+
if (matches.length === 0) {
|
|
26695
|
+
return { query, tools, text: serverHint ? `No tools matching "${query}" in "${serverHint}"` : `No tools matching "${query}"` };
|
|
26696
|
+
}
|
|
26697
|
+
const lines = [`Found ${matches.length} tool(s) matching "${query}":`, ""];
|
|
26698
|
+
for (const { server, tool } of matches) {
|
|
26699
|
+
lines.push(`${tool.name} [${server}]`);
|
|
26700
|
+
lines.push(` ${tool.description ?? "(no description)"}`);
|
|
26701
|
+
if (tool.inputSchema) {
|
|
26702
|
+
lines.push(` Parameters:
|
|
26703
|
+
${formatSchema(tool.inputSchema, " ")}`);
|
|
26704
|
+
}
|
|
26705
|
+
lines.push("");
|
|
26706
|
+
}
|
|
26707
|
+
return { query, tools, text: lines.join("\n").trim() };
|
|
26708
|
+
}
|
|
26709
|
+
/** `mcp({ searches: [...] })`:一次连接元数据并按 query 分组执行多组搜索。 */
|
|
26710
|
+
async executeBatchSearch(queries, serverHint, context2) {
|
|
26711
|
+
const normalized = [
|
|
26712
|
+
...new Set(queries.map((query) => query.trim()).filter(Boolean))
|
|
26713
|
+
].slice(0, MCP_BATCH_SEARCH_MAX_ITEMS);
|
|
26714
|
+
if (normalized.length === 0) {
|
|
26715
|
+
return "Batch search requires at least one non-empty query.";
|
|
26716
|
+
}
|
|
26717
|
+
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26718
|
+
await Promise.all(specs.map((spec) => this.ensureEntry(spec.serverName)));
|
|
26719
|
+
const results = await Promise.all(normalized.map((query) => this.executeSearch(query, serverHint)));
|
|
26720
|
+
this.recordAction(context2, "search", results.some((result) => result.tools.length) ? "matched" : "no_hits", { results: results.map(({ query, tools }) => ({ query, tools })) });
|
|
26721
|
+
return results.map((result, index) => `Query ${index + 1}: "${normalized[index]}"
|
|
26722
|
+
${result.text}`).join("\n\n");
|
|
26723
|
+
}
|
|
26724
|
+
/** `mcp({ describe: "tool" })`:输出工具所属 server + 参数 schema。 */
|
|
26725
|
+
async executeDescribe(toolName, serverHint, signal, context2) {
|
|
26726
|
+
const found = await this.findTool(toolName, serverHint, signal);
|
|
26727
|
+
if (!found) {
|
|
26728
|
+
this.recordAction(context2, "describe", "not_found", { name: toolName });
|
|
26729
|
+
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
26730
|
+
}
|
|
26731
|
+
const { server, tool } = found;
|
|
26732
|
+
this.recordAction(context2, "describe", "matched", { server, name: tool.name, inputSchema: tool.inputSchema });
|
|
26733
|
+
const lines = [
|
|
26734
|
+
`${tool.name}`,
|
|
26735
|
+
`Server: ${server}`,
|
|
26736
|
+
"",
|
|
26737
|
+
tool.description ?? "(no description)"
|
|
26738
|
+
];
|
|
26739
|
+
if (tool.inputSchema) {
|
|
26740
|
+
lines.push("", `Parameters:
|
|
26741
|
+
${formatSchema(tool.inputSchema)}`);
|
|
26742
|
+
} else {
|
|
26743
|
+
lines.push("", "No parameters defined.");
|
|
26744
|
+
}
|
|
26745
|
+
return lines.join("\n").trim();
|
|
26746
|
+
}
|
|
26747
|
+
/** `mcp({ tool: "name", args: {...} })`:调用工具,返回序列化结果。 */
|
|
26748
|
+
async executeCall(toolName, args, serverHint, signal, context2) {
|
|
26749
|
+
const found = await this.findTool(toolName, serverHint, signal);
|
|
26750
|
+
if (!found) {
|
|
26751
|
+
this.recordAction(context2, "call", "not_found", { name: toolName });
|
|
26752
|
+
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
26753
|
+
}
|
|
26754
|
+
const { entry, tool, spec } = found;
|
|
26755
|
+
try {
|
|
26756
|
+
const headers = await this.authorizeCall?.({
|
|
26757
|
+
resourceIds: resourceIdsForTool(spec, tool.name),
|
|
26758
|
+
toolName: tool.name,
|
|
26759
|
+
signal,
|
|
26760
|
+
context: context2
|
|
26761
|
+
});
|
|
26762
|
+
const result = await entry.server.callTool(tool.name, args, signal, {
|
|
26763
|
+
toolSchema: {
|
|
26764
|
+
inputSchema: tool.inputSchema,
|
|
26765
|
+
outputSchema: tool.outputSchema
|
|
26766
|
+
},
|
|
26767
|
+
...headers ? { headers } : {},
|
|
26768
|
+
...context2 ? { context: context2 } : {}
|
|
26769
|
+
});
|
|
26770
|
+
this.recordAction(context2, "call", result && typeof result === "object" && "isError" in result && result.isError === true ? "failed" : "completed", { name: tool.name, server: spec.serverName });
|
|
26771
|
+
return serializeToolResult(result);
|
|
26772
|
+
} catch (error) {
|
|
26773
|
+
this.recordAction(context2, "call", signal?.aborted ? "cancelled" : "failed", { name: tool.name, server: spec.serverName });
|
|
26774
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26775
|
+
return `Tool "${toolName}" call failed: ${message}`;
|
|
26776
|
+
}
|
|
26777
|
+
}
|
|
26778
|
+
// —— 辅助 ——
|
|
26779
|
+
/** 跨(或按 hint)已连 server 查找工具;未连则触发懒连接。 */
|
|
26780
|
+
async findTool(toolName, serverHint, signal) {
|
|
26781
|
+
const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
|
|
26782
|
+
for (const spec of specs) {
|
|
26783
|
+
const entry = this.entries.get(spec.serverName);
|
|
26784
|
+
if (!entry || entry.status !== "connected")
|
|
26785
|
+
continue;
|
|
26786
|
+
const tool = entry.tools.find((t) => t.name === toolName);
|
|
26787
|
+
if (tool) {
|
|
26788
|
+
return { entry, server: spec.serverName, tool, spec };
|
|
26789
|
+
}
|
|
26790
|
+
}
|
|
26791
|
+
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, signal)));
|
|
26792
|
+
for (const spec of specs) {
|
|
26793
|
+
const entry = this.entries.get(spec.serverName);
|
|
26794
|
+
if (!entry || entry.status !== "connected")
|
|
26795
|
+
continue;
|
|
26796
|
+
const tool = entry.tools.find((t) => t.name === toolName);
|
|
26797
|
+
if (tool) {
|
|
26798
|
+
return { entry, server: spec.serverName, tool, spec };
|
|
26799
|
+
}
|
|
26800
|
+
}
|
|
26801
|
+
return void 0;
|
|
26802
|
+
}
|
|
26803
|
+
/** 按 serverName 或原始 resourceId 找 spec(server 入参可为二者)。 */
|
|
26804
|
+
findSpec(server) {
|
|
26805
|
+
return this.specByServerName.get(server) ?? this.specByResourceId.get(server);
|
|
26806
|
+
}
|
|
26807
|
+
/** serverHint(serverName 或 resourceId)命中的 spec 子集。 */
|
|
26808
|
+
specsMatching(serverHint) {
|
|
26809
|
+
return this.specs.filter((spec) => spec.serverName === serverHint || spec.resourceIds.includes(serverHint));
|
|
26810
|
+
}
|
|
26811
|
+
/** 格式化某 server 的工具列表。 */
|
|
26812
|
+
formatToolList(server, tools) {
|
|
26813
|
+
if (tools.length === 0)
|
|
26814
|
+
return `Server "${server}" has no tools.`;
|
|
26815
|
+
const lines = [`${server} (${tools.length} tools):`, ""];
|
|
26816
|
+
for (const tool of tools) {
|
|
26817
|
+
const desc = truncate(tool.description ?? "", 50);
|
|
26818
|
+
lines.push(`- ${tool.name}${desc ? " - " + desc : ""}`);
|
|
26819
|
+
}
|
|
26820
|
+
return lines.join("\n").trim();
|
|
26821
|
+
}
|
|
26822
|
+
};
|
|
26823
|
+
function resourceIdsForTool(spec, toolName) {
|
|
26824
|
+
if (!spec.allToolResourceIds && !spec.resourceIdsByTool)
|
|
26825
|
+
return spec.resourceIds;
|
|
26826
|
+
return [
|
|
26827
|
+
...spec.allToolResourceIds ?? [],
|
|
26828
|
+
...spec.resourceIdsByTool?.get(toolName) ?? []
|
|
26829
|
+
];
|
|
26830
|
+
}
|
|
26831
|
+
function parseProxyArgs(args) {
|
|
26832
|
+
if (!isRecord(args))
|
|
26833
|
+
return {};
|
|
26834
|
+
const out = {};
|
|
26835
|
+
if (typeof args.connect === "string")
|
|
26836
|
+
out.connect = args.connect;
|
|
26837
|
+
if (typeof args.describe === "string")
|
|
26838
|
+
out.describe = args.describe;
|
|
26839
|
+
if (typeof args.search === "string")
|
|
26840
|
+
out.search = args.search;
|
|
26841
|
+
if (Array.isArray(args.searches)) {
|
|
26842
|
+
out.searches = args.searches.filter((query) => typeof query === "string").slice(0, MCP_BATCH_SEARCH_MAX_ITEMS);
|
|
26843
|
+
}
|
|
26844
|
+
if (typeof args.tool === "string")
|
|
26845
|
+
out.tool = args.tool;
|
|
26846
|
+
if (typeof args.server === "string")
|
|
26847
|
+
out.server = args.server;
|
|
26848
|
+
if (args.args !== void 0)
|
|
26849
|
+
out.args = args.args;
|
|
26850
|
+
return out;
|
|
26851
|
+
}
|
|
26852
|
+
function formatSchema(schema, indent = " ") {
|
|
26853
|
+
if (!isRecord(schema))
|
|
26854
|
+
return `${indent}No parameters defined.`;
|
|
26855
|
+
const props = schema.properties;
|
|
26856
|
+
if (!isRecord(props) || Object.keys(props).length === 0) {
|
|
26857
|
+
return `${indent}No parameters defined.`;
|
|
26858
|
+
}
|
|
26859
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
26860
|
+
const lines = Object.entries(props).map(([key, value]) => {
|
|
26861
|
+
const type = isRecord(value) && typeof value.type === "string" ? value.type : "any";
|
|
26862
|
+
const desc = isRecord(value) && typeof value.description === "string" ? value.description : "";
|
|
26863
|
+
const req = required.has(key) ? " [required]" : "";
|
|
26864
|
+
return `${indent}- ${key} (${type})${req}${desc ? " - " + desc : ""}`;
|
|
26865
|
+
});
|
|
26866
|
+
return lines.join("\n");
|
|
26867
|
+
}
|
|
26868
|
+
function serializeToolResult(value) {
|
|
26869
|
+
if (typeof value === "string")
|
|
26870
|
+
return value;
|
|
26871
|
+
try {
|
|
26872
|
+
const serialized = JSON.stringify(value);
|
|
26873
|
+
return serialized === void 0 ? "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002" : serialized;
|
|
26874
|
+
} catch {
|
|
26875
|
+
return "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002";
|
|
26876
|
+
}
|
|
26877
|
+
}
|
|
26878
|
+
function escapeRegExp(text) {
|
|
26879
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
26880
|
+
}
|
|
26881
|
+
function truncate(text, max2) {
|
|
26882
|
+
return text.length > max2 ? `${text.slice(0, max2)}\u2026` : text;
|
|
26883
|
+
}
|
|
26884
|
+
function isRecord(value) {
|
|
26885
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
26886
|
+
}
|
|
26887
|
+
var MCP_BATCH_SEARCH_MAX_ITEMS = 5;
|
|
26888
|
+
var MCP_PROXY_DESCRIPTION = [
|
|
26889
|
+
"MCP \u7F51\u5173:\u53D1\u73B0\u5E76\u8C03\u7528 MCP server \u63D0\u4F9B\u7684\u5DE5\u5177\u3002\u53EF\u7528\u52A8\u4F5C:",
|
|
26890
|
+
"- mcp({}) \u6216 mcp({ status: true }):\u67E5\u770B\u6240\u6709 server \u8FDE\u63A5\u72B6\u6001\u4E0E\u5DE5\u5177\u6570\u3002",
|
|
26891
|
+
'- mcp({ connect: "server" }):\u8FDE\u63A5\u5E76\u5237\u65B0\u67D0 server \u7684\u5DE5\u5177\u5217\u8868\u3002',
|
|
26892
|
+
'- mcp({ server: "name" }):\u5217\u51FA\u8BE5 server \u7684\u5DE5\u5177\u3002',
|
|
26893
|
+
'- mcp({ search: "\u5173\u952E\u8BCD" }):\u6309\u540D\u79F0/\u63CF\u8FF0\u6A21\u7CCA\u641C\u7D22\u5DE5\u5177(\u7A7A\u683C\u5206\u8BCD OR)\u3002',
|
|
26894
|
+
'- mcp({ searches: ["\u5173\u952E\u8BCD1", "\u5173\u952E\u8BCD2"] }):\u4E00\u6B21\u6267\u884C\u591A\u7EC4\u641C\u7D22\u5E76\u6309 query \u5206\u7EC4\u8FD4\u56DE(\u6700\u591A 5 \u7EC4)\u3002',
|
|
26895
|
+
'- mcp({ describe: "toolName" }):\u67E5\u770B\u67D0\u5DE5\u5177\u7684\u53C2\u6570 schema\u3002',
|
|
26896
|
+
'- mcp({ tool: "toolName", args: { ... } }):\u8C03\u7528\u67D0\u5DE5\u5177,args \u4E3A\u5BF9\u8C61\u3002',
|
|
26897
|
+
"\u53EF\u7528 server \u540D\u89C1 mcp({}) \u8F93\u51FA\u3002\u4EC5\u5728\u786E\u9700\u8C03\u7528 MCP \u5DE5\u5177\u65F6\u4F7F\u7528\u672C\u5DE5\u5177\u3002",
|
|
26898
|
+
"\u4EC5 mcp({}) \u5217\u51FA\u7684\u5DE5\u5177\u53EF\u8C03\u7528(\u672A\u58F0\u660E\u7684\u5DE5\u5177\u4E0D\u4F1A\u51FA\u73B0)\u3002"
|
|
26899
|
+
].join("\n");
|
|
26900
|
+
var MCP_PROXY_INPUT_SCHEMA = {
|
|
26901
|
+
type: "object",
|
|
26902
|
+
additionalProperties: false,
|
|
26903
|
+
properties: {
|
|
26904
|
+
status: {
|
|
26905
|
+
type: "boolean",
|
|
26906
|
+
description: "\u67E5\u770B\u6240\u6709 server \u8FDE\u63A5\u72B6\u6001(\u7B49\u4EF7\u4E8E\u7A7A\u5165\u53C2)"
|
|
26907
|
+
},
|
|
26908
|
+
connect: {
|
|
26909
|
+
type: "string",
|
|
26910
|
+
description: "\u663E\u5F0F\u8FDE\u63A5\u5E76\u5237\u65B0\u67D0 server(serverName \u6216 resourceId)"
|
|
26911
|
+
},
|
|
26912
|
+
server: { type: "string", description: "\u6307\u5B9A server:\u5217\u5DE5\u5177\u6216\u6D88\u6B67\u5DE5\u5177\u8C03\u7528" },
|
|
26913
|
+
search: {
|
|
26914
|
+
type: "string",
|
|
26915
|
+
description: "\u6309\u540D\u79F0/\u63CF\u8FF0\u6A21\u7CCA\u641C\u7D22\u5DE5\u5177(\u7A7A\u683C\u5206\u8BCD OR)"
|
|
26916
|
+
},
|
|
26917
|
+
searches: {
|
|
26918
|
+
type: "array",
|
|
26919
|
+
description: "\u6279\u91CF\u641C\u7D22\u5173\u952E\u8BCD\uFF1B\u4E00\u6B21\u63D0\u4EA4\u6240\u6709\u5019\u9009 query\uFF0C\u6309 query \u5206\u7EC4\u8FD4\u56DE",
|
|
26920
|
+
minItems: 1,
|
|
26921
|
+
maxItems: MCP_BATCH_SEARCH_MAX_ITEMS,
|
|
26922
|
+
items: { type: "string", minLength: 1 }
|
|
26923
|
+
},
|
|
26924
|
+
describe: { type: "string", description: "\u67E5\u770B\u67D0\u5DE5\u5177\u7684\u53C2\u6570 schema" },
|
|
26925
|
+
tool: { type: "string", description: "\u8981\u8C03\u7528\u7684\u5DE5\u5177\u540D(\u53EF\u914D\u5408 server \u6D88\u6B67)" },
|
|
26926
|
+
args: {
|
|
26927
|
+
type: "object",
|
|
26928
|
+
description: "\u5DE5\u5177\u5165\u53C2\u5BF9\u8C61(\u4EC5\u5728 tool \u6307\u5B9A\u65F6\u6709\u6548)",
|
|
26929
|
+
additionalProperties: true
|
|
26930
|
+
}
|
|
26931
|
+
}
|
|
26932
|
+
};
|
|
26933
|
+
|
|
26934
|
+
// ../linkque-agent-runtime/dist/esm/core/homeData.js
|
|
26935
|
+
async function executeHomeData(input) {
|
|
26936
|
+
let request;
|
|
26937
|
+
try {
|
|
26938
|
+
request = parseHomeDataRequest(input.request);
|
|
26939
|
+
} catch (error) {
|
|
26940
|
+
return failure("INVALID_INPUT", error instanceof Error ? error.message : "\u9996\u9875\u5361\u7247\u8BF7\u6C42\u65E0\u6548", false);
|
|
26941
|
+
}
|
|
26942
|
+
if (request.agentId !== input.protocol.agentId) {
|
|
26943
|
+
return failure("AGENT_MISMATCH", "\u9996\u9875\u6570\u636E\u8BF7\u6C42\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
26944
|
+
}
|
|
26945
|
+
if (!input.userId.trim()) {
|
|
26946
|
+
return failure("AUTH_REQUIRED", "\u9996\u9875\u6570\u636E\u8BF7\u6C42\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
26947
|
+
}
|
|
26948
|
+
const resources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
26949
|
+
const specs = aggregateMcpServers(resources, input.protocol.agentId);
|
|
26950
|
+
const spec = specs.find((candidate) => candidate.serverName === request.binding.mcpName);
|
|
26951
|
+
if (!spec) {
|
|
26952
|
+
return failure("MCP_NOT_BOUND", "\u5F53\u524D Agent \u672A\u7ED1\u5B9A\u8BE5 MCP", false);
|
|
26953
|
+
}
|
|
26954
|
+
if (spec.allowedTools && !spec.allowedTools.has(request.binding.toolName)) {
|
|
26955
|
+
return failure("TOOL_NOT_ALLOWED", "\u5F53\u524D Agent \u672A\u5141\u8BB8\u8C03\u7528\u8BE5 MCP \u5DE5\u5177", false);
|
|
26956
|
+
}
|
|
26957
|
+
const registry = new McpProxyTool(input.mcpServerProvider, specs, {
|
|
26958
|
+
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
26959
|
+
});
|
|
26960
|
+
try {
|
|
26961
|
+
const handle = await registry.resolve(spec.resourceIds[0], request.binding.toolName, input.signal);
|
|
26962
|
+
if (!handle) {
|
|
26963
|
+
return failure("TOOL_NOT_ALLOWED", "MCP \u5DE5\u5177\u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u7528", false);
|
|
26964
|
+
}
|
|
26965
|
+
const toolInput = {};
|
|
26966
|
+
for (const mapping of request.binding.input) {
|
|
26967
|
+
let value;
|
|
26968
|
+
switch (mapping.source.kind) {
|
|
26969
|
+
case "parameter":
|
|
26970
|
+
value = readJsonPointer(request.parameters, mapping.source.pointer);
|
|
26971
|
+
break;
|
|
26972
|
+
case "runtime-context":
|
|
26973
|
+
value = mapping.source.key === "agentId" ? input.protocol.agentId : input.userId;
|
|
26974
|
+
break;
|
|
26975
|
+
case "literal":
|
|
26976
|
+
value = mapping.source.value;
|
|
26977
|
+
break;
|
|
26978
|
+
}
|
|
26979
|
+
if (value === void 0 || !writeJsonPointer(toolInput, mapping.target, value)) {
|
|
26980
|
+
return failure("INVALID_INPUT", `\u65E0\u6CD5\u751F\u6210 MCP \u5165\u53C2 ${mapping.target}`, false);
|
|
26981
|
+
}
|
|
26982
|
+
}
|
|
26983
|
+
let result;
|
|
26984
|
+
try {
|
|
26985
|
+
result = await handle.execute(toolInput, input.signal);
|
|
26986
|
+
} catch (error) {
|
|
26987
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
26988
|
+
throw error;
|
|
26989
|
+
return failure("EXECUTION_FAILED", error instanceof Error ? error.message : "MCP \u5DE5\u5177\u8C03\u7528\u5931\u8D25", true);
|
|
26990
|
+
}
|
|
26991
|
+
const structured = readStructuredContent2(result);
|
|
26992
|
+
let cardData = structured;
|
|
26993
|
+
if (request.binding.transform) {
|
|
26994
|
+
try {
|
|
26995
|
+
cardData = executeStructuralTransform(request.binding.transform, structured);
|
|
26996
|
+
} catch (error) {
|
|
26997
|
+
return failure("TRANSFORM_FAILED", error instanceof Error ? error.message : "\u9996\u9875\u5361\u7247\u6570\u636E\u8F6C\u6362\u5931\u8D25", false);
|
|
26998
|
+
}
|
|
26999
|
+
}
|
|
27000
|
+
const cardDataObject = cloneJsonObject(cardData);
|
|
27001
|
+
if (!cardDataObject) {
|
|
27002
|
+
return failure("INVALID_CARD_DATA", "\u9996\u9875\u5361\u7247\u6570\u636E\u5FC5\u987B\u662F JSON object", false);
|
|
27003
|
+
}
|
|
27004
|
+
return { ok: true, data: cardDataObject };
|
|
27005
|
+
} finally {
|
|
27006
|
+
await registry.closeAll();
|
|
27007
|
+
}
|
|
27008
|
+
}
|
|
27009
|
+
function readStructuredContent2(result) {
|
|
27010
|
+
const object3 = cloneJsonObject(result);
|
|
27011
|
+
if (!object3)
|
|
27012
|
+
return void 0;
|
|
27013
|
+
if (cloneJsonObject(object3.structuredContent)) {
|
|
27014
|
+
return object3.structuredContent;
|
|
27015
|
+
}
|
|
27016
|
+
if (!Array.isArray(object3.content) || object3.content.length !== 1) {
|
|
27017
|
+
return void 0;
|
|
27018
|
+
}
|
|
27019
|
+
const content = cloneJsonObject(object3.content[0]);
|
|
27020
|
+
if (!content || content.type !== "text" || typeof content.text !== "string") {
|
|
27021
|
+
return void 0;
|
|
27022
|
+
}
|
|
27023
|
+
try {
|
|
27024
|
+
return JSON.parse(content.text);
|
|
27025
|
+
} catch {
|
|
27026
|
+
return void 0;
|
|
27027
|
+
}
|
|
27028
|
+
}
|
|
27029
|
+
function failure(code, message, retryable) {
|
|
27030
|
+
return { ok: false, error: { code, message, retryable } };
|
|
27031
|
+
}
|
|
27032
|
+
|
|
27033
|
+
// ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
|
|
27034
|
+
var CardActionDiagnostics = class {
|
|
27035
|
+
sink;
|
|
27036
|
+
layer;
|
|
27037
|
+
operation;
|
|
27038
|
+
stage = "validate";
|
|
27039
|
+
context;
|
|
27040
|
+
debugLog;
|
|
27041
|
+
startedAt = performance.now();
|
|
27042
|
+
sensitiveValues = /* @__PURE__ */ new Set();
|
|
27043
|
+
constructor(sink, context2, layer = "runtime", operation = "a2uiAction.execute") {
|
|
27044
|
+
this.sink = sink;
|
|
27045
|
+
this.layer = layer;
|
|
27046
|
+
this.operation = operation;
|
|
27047
|
+
this.context = { ...context2 };
|
|
27048
|
+
if (sink) {
|
|
27049
|
+
this.debugLog = (line, scope) => {
|
|
27050
|
+
this.write("diagnostic", { message: line }, scope);
|
|
27051
|
+
};
|
|
27052
|
+
}
|
|
27053
|
+
}
|
|
27054
|
+
/** 根据绑定路径登记敏感值;解析仅为日志服务,失败不影响业务。 */
|
|
27055
|
+
protect(readValue) {
|
|
27056
|
+
if (!this.sink)
|
|
27057
|
+
return;
|
|
27058
|
+
try {
|
|
27059
|
+
const value = readValue();
|
|
27060
|
+
if (typeof value === "string" && value)
|
|
27061
|
+
this.sensitiveValues.add(value);
|
|
27062
|
+
} catch {
|
|
27063
|
+
}
|
|
27064
|
+
}
|
|
27065
|
+
write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
|
|
27066
|
+
if (!this.sink)
|
|
27067
|
+
return;
|
|
27068
|
+
try {
|
|
27069
|
+
const record2 = { ...this.context, ...fields };
|
|
27070
|
+
if (record2.message)
|
|
27071
|
+
record2.message = sanitizeDiagnosticText(redactKnownValues(record2.message, this.sensitiveValues));
|
|
27072
|
+
if (record2.errorName)
|
|
27073
|
+
record2.errorName = sanitizeDiagnosticText(redactKnownValues(record2.errorName, this.sensitiveValues));
|
|
27074
|
+
if ("input" in record2)
|
|
27075
|
+
record2.input = sanitizeLogValue(record2.input, this.sensitiveValues);
|
|
27076
|
+
if ("output" in record2)
|
|
27077
|
+
record2.output = sanitizeLogValue(record2.output, this.sensitiveValues);
|
|
27078
|
+
this.sink(JSON.stringify({
|
|
27079
|
+
operation: this.operation,
|
|
27080
|
+
level: "info",
|
|
27081
|
+
layer: this.layer,
|
|
27082
|
+
event,
|
|
27083
|
+
stage: this.stage,
|
|
27084
|
+
...record2,
|
|
27085
|
+
costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
|
|
27086
|
+
}), scope);
|
|
27087
|
+
} catch {
|
|
27088
|
+
}
|
|
27089
|
+
}
|
|
27090
|
+
error(event, error) {
|
|
27091
|
+
if (!this.sink)
|
|
27092
|
+
return;
|
|
27093
|
+
try {
|
|
27094
|
+
this.write(event, {
|
|
27095
|
+
errorName: error instanceof Error ? error.name : typeof error,
|
|
27096
|
+
message: error instanceof Error ? error.message : typeof error === "string" ? error : "\u975E\u6807\u51C6\u5F02\u5E38"
|
|
27097
|
+
});
|
|
27098
|
+
} catch {
|
|
27099
|
+
}
|
|
27100
|
+
}
|
|
27101
|
+
};
|
|
27102
|
+
function sanitizeLogValue(value, sensitiveValues) {
|
|
27103
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
27104
|
+
let nodes = 200;
|
|
27105
|
+
let characters = 4e3;
|
|
27106
|
+
const visit = (item, depth, key = "") => {
|
|
27107
|
+
if (/authorization|cookie|token|secret|password|api[_-]?key|access[_-]?key|private[_-]?key|^(?:ak|sk|userId|orderId|tradeNO|phone|mobile|email|idCard)$/iu.test(key)) {
|
|
27108
|
+
if (typeof item === "string" && item)
|
|
27109
|
+
sensitiveValues.add(item);
|
|
27110
|
+
return "<redacted>";
|
|
27111
|
+
}
|
|
27112
|
+
if (--nodes < 0 || depth > 8 || characters <= 0)
|
|
27113
|
+
return "<truncated>";
|
|
27114
|
+
if (item === null || typeof item === "number" || typeof item === "boolean")
|
|
27115
|
+
return item;
|
|
27116
|
+
if (typeof item === "string") {
|
|
27117
|
+
if (/^\s*[{[]/u.test(item)) {
|
|
27118
|
+
if (item.length > 16e3)
|
|
27119
|
+
return "<truncated JSON>";
|
|
27120
|
+
try {
|
|
27121
|
+
return JSON.stringify(visit(JSON.parse(item), depth + 1));
|
|
27122
|
+
} catch {
|
|
27123
|
+
return "<invalid JSON>";
|
|
27124
|
+
}
|
|
27125
|
+
}
|
|
27126
|
+
const text2 = sanitizeDiagnosticText(redactKnownValues(item, sensitiveValues));
|
|
27127
|
+
const result2 = text2.slice(0, Math.min(512, characters));
|
|
27128
|
+
characters -= result2.length;
|
|
27129
|
+
return result2.length < item.length ? `${result2}<truncated>` : result2;
|
|
27130
|
+
}
|
|
27131
|
+
if (typeof item !== "object")
|
|
27132
|
+
return `<${typeof item}>`;
|
|
27133
|
+
if (seen.has(item))
|
|
27134
|
+
return "<circular>";
|
|
27135
|
+
seen.add(item);
|
|
27136
|
+
try {
|
|
27137
|
+
const keys = Object.keys(item);
|
|
27138
|
+
const result2 = /* @__PURE__ */ Object.create(null);
|
|
27139
|
+
for (const name of keys.slice(0, 20)) {
|
|
27140
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, name);
|
|
27141
|
+
if (name === "value" && Object.getOwnPropertyDescriptor(item, "kind")?.value === "literal" && typeof descriptor?.value === "string" && descriptor.value)
|
|
27142
|
+
sensitiveValues.add(descriptor.value);
|
|
27143
|
+
result2[name.slice(0, 100)] = name === "value" && Object.getOwnPropertyDescriptor(item, "kind")?.value === "literal" ? "<redacted>" : descriptor && "value" in descriptor ? visit(descriptor.value, depth + 1, name) : "<accessor>";
|
|
27144
|
+
}
|
|
27145
|
+
if (Array.isArray(item)) {
|
|
27146
|
+
const values = Object.values(result2);
|
|
27147
|
+
if (keys.length > 20)
|
|
27148
|
+
values.push("<truncated>");
|
|
27149
|
+
return values;
|
|
27150
|
+
}
|
|
27151
|
+
if (keys.length > 20)
|
|
27152
|
+
result2["<truncated>"] = true;
|
|
27153
|
+
return result2;
|
|
27154
|
+
} catch {
|
|
27155
|
+
return "<unreadable>";
|
|
27156
|
+
} finally {
|
|
27157
|
+
seen.delete(item);
|
|
27158
|
+
}
|
|
27159
|
+
};
|
|
27160
|
+
const result = visit(value, 0);
|
|
27161
|
+
const text = JSON.stringify(result);
|
|
27162
|
+
return text.length > 6e3 ? { truncated: true, preview: text.slice(0, 2e3) } : result;
|
|
27163
|
+
}
|
|
27164
|
+
function sanitizeDiagnosticText(value) {
|
|
27165
|
+
return value.replace(/\b(?:body|arguments|payload|headers)\s*[:=][\s\S]*/giu, "<payload>").replace(/\{[\s\S]*/gu, "<payload>").replace(/https?:\/\/[^\s]+/giu, "<url>").replace(/\b(?:authorization|cookie|set-cookie)\s*[:=][^\r\n]*/giu, "<redacted>").replace(/\bbearer\s+[^\s,;]+/giu, "Bearer <redacted>").replace(/\b((?:api[_-]?key|access[_-]?key|token|secret|password|ak|sk|tradeNO|userId|orderId)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu, "$1<redacted>").replace(/\s+/gu, " ").slice(0, 300);
|
|
27166
|
+
}
|
|
27167
|
+
function redactKnownValues(text, sensitiveValues) {
|
|
27168
|
+
let result = text;
|
|
27169
|
+
for (const sensitive of sensitiveValues)
|
|
27170
|
+
result = result.replaceAll(sensitive, "<redacted>");
|
|
27171
|
+
return result;
|
|
27172
|
+
}
|
|
27173
|
+
|
|
27174
|
+
// ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
|
|
27175
|
+
async function executeCardAction(input) {
|
|
27176
|
+
const diagnostics = new CardActionDiagnostics(input.debugLog, {
|
|
27177
|
+
agentId: input.protocol.agentId,
|
|
27178
|
+
threadId: input.runtimeContext.threadId
|
|
27179
|
+
});
|
|
27180
|
+
diagnostics.protect(() => input.runtimeContext.userId);
|
|
27181
|
+
diagnostics.protect(() => input.runtimeContext.tenantId);
|
|
27182
|
+
diagnostics.write("started", {
|
|
27183
|
+
input: { request: input.request, runtimeContext: input.runtimeContext }
|
|
27184
|
+
});
|
|
27185
|
+
try {
|
|
27186
|
+
const response = await executeCardActionInternal(input, diagnostics);
|
|
27187
|
+
diagnostics.write(response.ok ? "completed" : "failed", response.ok ? { output: response } : {
|
|
27188
|
+
code: response.error.code,
|
|
27189
|
+
retryable: response.error.retryable,
|
|
27190
|
+
output: response
|
|
27191
|
+
});
|
|
27192
|
+
return response;
|
|
27193
|
+
} catch (error) {
|
|
27194
|
+
diagnostics.error("failed", error);
|
|
27195
|
+
throw error;
|
|
27196
|
+
}
|
|
27197
|
+
}
|
|
27198
|
+
async function executeCardActionInternal(input, diagnostics) {
|
|
27199
|
+
let request;
|
|
27200
|
+
try {
|
|
27201
|
+
request = parseA2UIActionExecuteRequest(input.request);
|
|
27202
|
+
} catch (error) {
|
|
27203
|
+
return failure2("INVALID_INPUT", errorMessage(error, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
|
|
27204
|
+
}
|
|
27205
|
+
Object.assign(diagnostics.context, {
|
|
27206
|
+
invocationId: request.invocationId,
|
|
27207
|
+
cardRef: request.source.cardRef,
|
|
27208
|
+
cardRevision: request.source.cardRevision
|
|
27209
|
+
});
|
|
27210
|
+
if (request.agentId !== input.protocol.agentId)
|
|
27211
|
+
return failure2("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27212
|
+
if (request.threadId !== input.runtimeContext.threadId)
|
|
27213
|
+
return failure2("INVALID_INPUT", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D\u4F1A\u8BDD\u4E0D\u5339\u914D", false);
|
|
27214
|
+
if (!input.runtimeContext.userId.trim())
|
|
27215
|
+
return failure2("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
27216
|
+
diagnostics.write("validated", { output: request });
|
|
27217
|
+
diagnostics.stage = "binding";
|
|
27218
|
+
diagnostics.write("binding_started", { input: { source: request.source } });
|
|
27219
|
+
const resolved = resolvePaymentAction(input.protocol, request.source);
|
|
27220
|
+
if (!resolved.ok) {
|
|
27221
|
+
diagnostics.write("binding_failed", { output: resolved.response });
|
|
27222
|
+
return resolved.response;
|
|
27223
|
+
}
|
|
27224
|
+
const args = materializePaymentInput(resolved.payment.createTrade.input, request.input);
|
|
27225
|
+
if (!args)
|
|
27226
|
+
return failure2("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
|
|
27227
|
+
const createTrade = resolved.payment.createTrade;
|
|
27228
|
+
Object.assign(diagnostics.context, {
|
|
27229
|
+
mcpResourceId: createTrade.mcpResourceId,
|
|
27230
|
+
toolName: createTrade.toolName
|
|
27231
|
+
});
|
|
27232
|
+
diagnostics.write("binding_resolved", { output: createTrade });
|
|
27233
|
+
diagnostics.stage = "tool_resolve";
|
|
27234
|
+
const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog, input.phoneAuthorization);
|
|
27235
|
+
try {
|
|
27236
|
+
diagnostics.write("tool_resolve_started", { input: createTrade });
|
|
27237
|
+
const tool = await registry.resolve(createTrade.mcpResourceId, createTrade.toolName, input.signal);
|
|
27238
|
+
diagnostics.write("tool_resolved", {
|
|
27239
|
+
output: {
|
|
27240
|
+
found: Boolean(tool),
|
|
27241
|
+
inputSchema: tool?.inputSchema,
|
|
27242
|
+
outputSchema: tool?.outputSchema
|
|
27243
|
+
}
|
|
27244
|
+
});
|
|
27245
|
+
if (!tool)
|
|
27246
|
+
return failure2("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
27247
|
+
diagnostics.stage = "tool_input";
|
|
27248
|
+
const inputSchema = cloneJsonObject(tool.inputSchema);
|
|
27249
|
+
if (inputSchema && validateJsonSchemaValue(inputSchema, args).length > 0) {
|
|
27250
|
+
return failure2("INVALID_INPUT", "\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2\u4E0D\u7B26\u5408 Tool Schema", false);
|
|
27251
|
+
}
|
|
27252
|
+
diagnostics.write("tool_input_completed", { output: { args } });
|
|
27253
|
+
let result;
|
|
27254
|
+
diagnostics.stage = "tool_execute";
|
|
27255
|
+
diagnostics.write("tool_started", { input: args });
|
|
27256
|
+
try {
|
|
27257
|
+
result = await tool.execute(args, input.signal);
|
|
27258
|
+
diagnostics.protect(() => readJsonPointer(readStructuredContent3(result), createTrade.tradeNoPath));
|
|
27259
|
+
diagnostics.write("tool_completed", { output: result });
|
|
27260
|
+
} catch (error) {
|
|
27261
|
+
diagnostics.error("tool_failed", error);
|
|
27262
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
27263
|
+
throw error;
|
|
27264
|
+
return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
|
|
27265
|
+
}
|
|
27266
|
+
diagnostics.stage = "tool_output";
|
|
27267
|
+
const structured = readStructuredContent3(result);
|
|
27268
|
+
const tradeNO = readJsonPointer(structured, createTrade.tradeNoPath);
|
|
27269
|
+
diagnostics.write("tool_output_completed", {
|
|
27270
|
+
output: {
|
|
27271
|
+
structured,
|
|
27272
|
+
tradeNO,
|
|
27273
|
+
valid: typeof tradeNO === "string" && Boolean(tradeNO.trim()) && tradeNO.length <= 64
|
|
27274
|
+
}
|
|
27275
|
+
});
|
|
27276
|
+
if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64)
|
|
27277
|
+
return failure2("INVALID_OUTPUT", "\u521B\u5EFA\u4EA4\u6613 MCP \u672A\u8FD4\u56DE\u6709\u6548 tradeNO", false);
|
|
27278
|
+
return {
|
|
27279
|
+
ok: true,
|
|
27280
|
+
invocationId: request.invocationId,
|
|
27281
|
+
result: { kind: "payment", tradeNO }
|
|
27282
|
+
};
|
|
27283
|
+
} finally {
|
|
27284
|
+
const stage = diagnostics.stage;
|
|
27285
|
+
diagnostics.stage = "cleanup";
|
|
27286
|
+
diagnostics.write("cleanup_started", {
|
|
27287
|
+
input: { mcpResourceId: diagnostics.context.mcpResourceId }
|
|
27288
|
+
});
|
|
27289
|
+
await registry.closeAll();
|
|
27290
|
+
diagnostics.write("cleanup_completed", {
|
|
27291
|
+
output: { closeAttempted: true }
|
|
27292
|
+
});
|
|
27293
|
+
diagnostics.stage = stage;
|
|
27294
|
+
}
|
|
27295
|
+
}
|
|
27296
|
+
function resolvePaymentAction(protocol, source) {
|
|
27297
|
+
const card = protocol.agent.resources.find((resource) => resource.resourceType === EResourceType.CARD && resource.resourceId === source.cardRef);
|
|
27298
|
+
if (!card)
|
|
27299
|
+
return {
|
|
27300
|
+
ok: false,
|
|
27301
|
+
response: failure2("CARD_NOT_FOUND", "\u652F\u4ED8\u5361\u7247\u4E0D\u5B58\u5728", false)
|
|
27302
|
+
};
|
|
27303
|
+
if (card.config.revision !== source.cardRevision) {
|
|
27304
|
+
return {
|
|
27305
|
+
ok: false,
|
|
27306
|
+
response: failure2("CARD_REVISION_MISMATCH", "\u652F\u4ED8\u5361\u7247\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5", false)
|
|
27307
|
+
};
|
|
27308
|
+
}
|
|
27309
|
+
if (card.config.schemaVersion !== "4")
|
|
27310
|
+
return {
|
|
27311
|
+
ok: false,
|
|
27312
|
+
response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u4E0D\u5B58\u5728", false)
|
|
27313
|
+
};
|
|
27314
|
+
const component = findSavedComponent(card.config.a2uiTemplate.content, source.surfaceId, source.componentId);
|
|
27315
|
+
if (!component)
|
|
27316
|
+
return {
|
|
27317
|
+
ok: false,
|
|
27318
|
+
response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u4E0D\u5B58\u5728", false)
|
|
27319
|
+
};
|
|
27320
|
+
const payments = collectPaymentActions(component.action);
|
|
27321
|
+
if (payments.length !== 1)
|
|
27322
|
+
return {
|
|
27323
|
+
ok: false,
|
|
27324
|
+
response: failure2("ACTION_KIND_MISMATCH", "\u7EC4\u4EF6\u5FC5\u987B\u5305\u542B\u552F\u4E00\u652F\u4ED8\u52A8\u4F5C", false)
|
|
27325
|
+
};
|
|
27326
|
+
return { ok: true, payment: payments[0] };
|
|
27327
|
+
}
|
|
27328
|
+
function findSavedComponent(content, surfaceId, componentId) {
|
|
27329
|
+
let parsed;
|
|
27330
|
+
try {
|
|
27331
|
+
parsed = JSON.parse(content);
|
|
27332
|
+
} catch {
|
|
27333
|
+
return void 0;
|
|
27334
|
+
}
|
|
27335
|
+
if (!Array.isArray(parsed))
|
|
27336
|
+
return void 0;
|
|
27337
|
+
const instructions = parsed.flatMap((entry) => {
|
|
27338
|
+
const record2 = cloneJsonObject(entry);
|
|
27339
|
+
return record2 && Array.isArray(record2.datas) ? record2.datas : [entry];
|
|
27340
|
+
});
|
|
27341
|
+
for (const instruction of instructions) {
|
|
27342
|
+
const record2 = cloneJsonObject(instruction);
|
|
27343
|
+
const update = record2 && cloneJsonObject(record2.updateComponents);
|
|
27344
|
+
if (!update || update.surfaceId !== surfaceId || !Array.isArray(update.components))
|
|
27345
|
+
continue;
|
|
27346
|
+
const component = update.components.find((candidate) => {
|
|
27347
|
+
const item = cloneJsonObject(candidate);
|
|
27348
|
+
return item?.id === componentId;
|
|
27349
|
+
});
|
|
27350
|
+
const result = cloneJsonObject(component);
|
|
27351
|
+
if (result)
|
|
27352
|
+
return result;
|
|
27353
|
+
}
|
|
27354
|
+
return void 0;
|
|
27355
|
+
}
|
|
27356
|
+
function collectPaymentActions(value) {
|
|
27357
|
+
const action = cloneJsonObject(value);
|
|
27358
|
+
if (!action)
|
|
27359
|
+
return [];
|
|
27360
|
+
const client = cloneJsonObject(action.client);
|
|
27361
|
+
if (client?.name === "payment.trade-pay") {
|
|
27362
|
+
const context2 = cloneJsonObject(client.context);
|
|
27363
|
+
return context2 ? [context2] : [];
|
|
27364
|
+
}
|
|
27365
|
+
const select = cloneJsonObject(action.select);
|
|
27366
|
+
if (!select)
|
|
27367
|
+
return [];
|
|
27368
|
+
const cases = Array.isArray(select.cases) ? select.cases : [];
|
|
27369
|
+
return [
|
|
27370
|
+
...cases.flatMap((entry) => collectPaymentActions(cloneJsonObject(entry)?.action)),
|
|
27371
|
+
...collectPaymentActions(select.default)
|
|
27372
|
+
];
|
|
27373
|
+
}
|
|
27374
|
+
function materializePaymentInput(definition, supplied) {
|
|
27375
|
+
const materialized = materializeValue(definition, supplied);
|
|
27376
|
+
return cloneJsonObject(materialized);
|
|
27377
|
+
}
|
|
27378
|
+
function materializeValue(definition, supplied) {
|
|
27379
|
+
if (Array.isArray(definition)) {
|
|
27380
|
+
if (!Array.isArray(supplied) || supplied.length !== definition.length)
|
|
27381
|
+
return void 0;
|
|
27382
|
+
const result = definition.map((entry, index) => materializeValue(entry, supplied[index]));
|
|
27383
|
+
return result.some((entry) => entry === void 0) ? void 0 : result;
|
|
27384
|
+
}
|
|
27385
|
+
if (definition && typeof definition === "object") {
|
|
27386
|
+
const keys = Object.keys(definition);
|
|
27387
|
+
if (keys.length === 1 && keys[0] === "path" && typeof definition.path === "string")
|
|
27388
|
+
return supplied;
|
|
27389
|
+
const suppliedObject = cloneJsonObject(supplied);
|
|
27390
|
+
if (!suppliedObject)
|
|
27391
|
+
return void 0;
|
|
27392
|
+
const result = {};
|
|
27393
|
+
for (const [key, entry] of Object.entries(definition)) {
|
|
27394
|
+
const value = materializeValue(entry, suppliedObject[key]);
|
|
27395
|
+
if (value === void 0)
|
|
27396
|
+
return void 0;
|
|
27397
|
+
result[key] = value;
|
|
27398
|
+
}
|
|
27399
|
+
return result;
|
|
27400
|
+
}
|
|
27401
|
+
return definition;
|
|
27402
|
+
}
|
|
27403
|
+
function createRegistry(protocol, provider, debugLog, phoneAuthorization) {
|
|
27404
|
+
const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
27405
|
+
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), {
|
|
27406
|
+
debugLog,
|
|
27407
|
+
authorizeCall: createRequestMcpPhoneAuthorizer(protocol, phoneAuthorization)
|
|
27408
|
+
});
|
|
27409
|
+
}
|
|
27410
|
+
function readStructuredContent3(result) {
|
|
27411
|
+
const object3 = cloneJsonObject(result);
|
|
27412
|
+
if (!object3)
|
|
27413
|
+
return void 0;
|
|
27414
|
+
if (cloneJsonObject(object3.structuredContent))
|
|
27415
|
+
return object3.structuredContent;
|
|
27416
|
+
if (!Array.isArray(object3.content) || object3.content.length !== 1)
|
|
27417
|
+
return void 0;
|
|
27418
|
+
const content = cloneJsonObject(object3.content[0]);
|
|
27419
|
+
if (!content || content.type !== "text" || typeof content.text !== "string")
|
|
27420
|
+
return void 0;
|
|
27421
|
+
try {
|
|
27422
|
+
return JSON.parse(content.text);
|
|
27423
|
+
} catch {
|
|
27424
|
+
return void 0;
|
|
27425
|
+
}
|
|
27426
|
+
}
|
|
27427
|
+
function failure2(code, message, retryable) {
|
|
27428
|
+
return { ok: false, error: { code, message, retryable } };
|
|
27429
|
+
}
|
|
27430
|
+
function errorMessage(error, fallback) {
|
|
27431
|
+
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
27432
|
+
}
|
|
27433
|
+
|
|
27434
|
+
// ../linkque-agent-runtime/dist/esm/core/mcpExecution.js
|
|
27435
|
+
async function executeAuthorizedMcp(input) {
|
|
27436
|
+
if (input.agentId !== input.protocol.agentId)
|
|
27437
|
+
return failure3("AGENT_MISMATCH", "\u8BF7\u6C42\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27438
|
+
if (!input.userId.trim())
|
|
27439
|
+
return failure3("AUTH_REQUIRED", "\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
27440
|
+
const resources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
27441
|
+
const registry = new McpProxyTool(input.mcpServerProvider, aggregateMcpServers(resources, input.protocol.agentId), {
|
|
27442
|
+
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
27443
|
+
});
|
|
27444
|
+
try {
|
|
27445
|
+
const tool = await registry.resolve(input.tool.mcpResourceId, input.tool.toolName, input.signal);
|
|
27446
|
+
if (!tool)
|
|
27447
|
+
return failure3("TOOL_NOT_ALLOWED", "MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
|
|
27448
|
+
const schema = cloneJsonObject(tool.inputSchema);
|
|
27449
|
+
if (schema && validateJsonSchemaValue(schema, input.tool.input).length > 0) {
|
|
27450
|
+
return failure3("INVALID_INPUT", "MCP \u5165\u53C2\u4E0D\u7B26\u5408 Tool Schema", false);
|
|
27451
|
+
}
|
|
27452
|
+
let result;
|
|
27453
|
+
try {
|
|
27454
|
+
result = await tool.execute(input.tool.input, input.signal);
|
|
27455
|
+
} catch (error) {
|
|
27456
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
27457
|
+
throw error;
|
|
27458
|
+
return failure3("EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5", false);
|
|
27459
|
+
}
|
|
27460
|
+
const structured = readStructuredContent4(result);
|
|
27461
|
+
if (!isJsonValue2(structured)) {
|
|
27462
|
+
return failure3("INVALID_OUTPUT", "MCP \u672A\u8FD4\u56DE\u6709\u6548 JSON \u7ED3\u679C", false);
|
|
27463
|
+
}
|
|
27464
|
+
return { ok: true, callId: input.callId, result: structured };
|
|
27465
|
+
} finally {
|
|
27466
|
+
await registry.closeAll();
|
|
27467
|
+
}
|
|
27468
|
+
}
|
|
27469
|
+
function readStructuredContent4(result) {
|
|
27470
|
+
const object3 = cloneJsonObject(result);
|
|
27471
|
+
if (!object3)
|
|
27472
|
+
return void 0;
|
|
27473
|
+
if (object3.structuredContent !== void 0)
|
|
27474
|
+
return object3.structuredContent;
|
|
27475
|
+
if (!Array.isArray(object3.content) || object3.content.length !== 1)
|
|
27476
|
+
return void 0;
|
|
27477
|
+
const text = cloneJsonObject(object3.content[0]);
|
|
27478
|
+
if (text?.type !== "text" || typeof text.text !== "string")
|
|
27479
|
+
return void 0;
|
|
27480
|
+
try {
|
|
27481
|
+
return JSON.parse(text.text);
|
|
27482
|
+
} catch {
|
|
27483
|
+
return void 0;
|
|
27484
|
+
}
|
|
27485
|
+
}
|
|
27486
|
+
function isJsonValue2(value) {
|
|
27487
|
+
if (value === null || ["string", "boolean"].includes(typeof value))
|
|
27488
|
+
return true;
|
|
27489
|
+
if (typeof value === "number")
|
|
27490
|
+
return Number.isFinite(value);
|
|
27491
|
+
if (Array.isArray(value))
|
|
27492
|
+
return value.every(isJsonValue2);
|
|
27493
|
+
const object3 = cloneJsonObject(value);
|
|
27494
|
+
return Boolean(object3) && Object.values(object3 ?? {}).every(isJsonValue2);
|
|
27495
|
+
}
|
|
27496
|
+
function failure3(code, message, retryable) {
|
|
27497
|
+
return { ok: false, error: { code, message, retryable } };
|
|
27498
|
+
}
|
|
27499
|
+
|
|
27500
|
+
// ../linkque-agent-runtime/dist/esm/core/functionActionExecutor.js
|
|
27501
|
+
async function executeFunctionActionMcp(input) {
|
|
27502
|
+
let request;
|
|
27503
|
+
try {
|
|
27504
|
+
request = parseA2UIFunctionMcpExecuteRequest(input.request);
|
|
27505
|
+
} catch (error) {
|
|
27506
|
+
return failure4("INVALID_INPUT", errorMessage2(error, "\u51FD\u6570 MCP \u8BF7\u6C42\u65E0\u6548"), false);
|
|
27507
|
+
}
|
|
27508
|
+
if (request.agentId !== input.protocol.agentId) {
|
|
27509
|
+
return failure4("AGENT_MISMATCH", "\u51FD\u6570\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
|
|
27510
|
+
}
|
|
27511
|
+
if (request.threadId !== input.runtimeContext.threadId || !input.runtimeContext.userId.trim()) {
|
|
27512
|
+
return failure4("AUTH_REQUIRED", "\u51FD\u6570\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u4F1A\u8BDD\u8EAB\u4EFD", false);
|
|
27513
|
+
}
|
|
27514
|
+
return executeAuthorizedMcp({
|
|
27515
|
+
protocol: input.protocol,
|
|
27516
|
+
agentId: request.agentId,
|
|
27517
|
+
userId: input.runtimeContext.userId,
|
|
27518
|
+
callId: request.callId,
|
|
27519
|
+
tool: request.tool,
|
|
27520
|
+
mcpServerProvider: input.mcpServerProvider,
|
|
27521
|
+
signal: input.signal,
|
|
27522
|
+
phoneAuthorization: input.phoneAuthorization
|
|
27523
|
+
});
|
|
27524
|
+
}
|
|
27525
|
+
function failure4(code, message, retryable) {
|
|
27526
|
+
return { ok: false, error: { code, message, retryable } };
|
|
27527
|
+
}
|
|
27528
|
+
function errorMessage2(error, fallback) {
|
|
27529
|
+
return error instanceof Error && error.message.trim() ? error.message : fallback;
|
|
27530
|
+
}
|
|
27531
|
+
|
|
27532
|
+
// ../linkque-agent-runtime/dist/esm/core/inMemorySessionManager.js
|
|
27533
|
+
var InMemorySessionManager = class {
|
|
27534
|
+
/** 私有会话历史表:sessionId → 累积的 IAgentTurn[]。 */
|
|
27535
|
+
sessions = /* @__PURE__ */ new Map();
|
|
27536
|
+
async load(sessionId) {
|
|
27537
|
+
return this.sessions.get(sessionId) ?? [];
|
|
27538
|
+
}
|
|
27539
|
+
async append(sessionId, turn) {
|
|
27540
|
+
await this.appendMany(sessionId, [turn]);
|
|
27541
|
+
}
|
|
27542
|
+
async appendMany(sessionId, newTurns) {
|
|
27543
|
+
const turns = this.sessions.get(sessionId);
|
|
27544
|
+
if (turns) {
|
|
27545
|
+
turns.push(...newTurns);
|
|
27546
|
+
} else {
|
|
27547
|
+
this.sessions.set(sessionId, [...newTurns]);
|
|
27548
|
+
}
|
|
27549
|
+
}
|
|
27550
|
+
};
|
|
27551
|
+
|
|
27552
|
+
// ../linkque-agent-runtime/dist/esm/core/noopSkillLoader.js
|
|
27553
|
+
var NoopSkillLoader = class {
|
|
27554
|
+
async load(_resources) {
|
|
27555
|
+
return [];
|
|
27556
|
+
}
|
|
27557
|
+
};
|
|
27558
|
+
|
|
27559
|
+
// ../linkque-agent-runtime/dist/esm/core/noopMcpServerProvider.js
|
|
27560
|
+
var NoopMcpServerProvider = class {
|
|
27561
|
+
async servers(_resources) {
|
|
27562
|
+
return [];
|
|
27563
|
+
}
|
|
27564
|
+
};
|
|
27565
|
+
|
|
27566
|
+
// ../linkque-agent-runtime/dist/esm/core/hook/hookContext.js
|
|
27567
|
+
function buildHookCommonParams(input) {
|
|
27568
|
+
const userTurns = input.history.reduce((count, turn) => turn.role === "user" ? count + 1 : count, 0);
|
|
27569
|
+
const commonParams = {
|
|
27570
|
+
agentId: input.agentId,
|
|
27571
|
+
runId: input.request.runId,
|
|
27572
|
+
conversationId: input.request.threadId,
|
|
27573
|
+
threadId: input.request.threadId,
|
|
27574
|
+
runIndex: input.hostParams?.runIndex ?? userTurns + 1
|
|
27575
|
+
};
|
|
27576
|
+
if (input.sessionId !== void 0)
|
|
27577
|
+
commonParams.sessionId = input.sessionId;
|
|
27578
|
+
if (input.userId !== void 0)
|
|
27579
|
+
commonParams.userId = input.userId;
|
|
27580
|
+
if (input.hostParams?.traceId !== void 0) {
|
|
27581
|
+
commonParams.traceId = input.hostParams.traceId;
|
|
27582
|
+
}
|
|
27583
|
+
return commonParams;
|
|
27584
|
+
}
|
|
27585
|
+
function createHookEventId(commonParams, stage, hookResourceId, sequence) {
|
|
27586
|
+
return `${commonParams.runId}:${stage}:${hookResourceId}:${sequence}`;
|
|
27587
|
+
}
|
|
27588
|
+
var HookEventSequencer = class {
|
|
27589
|
+
counters = /* @__PURE__ */ new Map();
|
|
27590
|
+
/** 取下一序号(1-based)。 */
|
|
27591
|
+
next(stage, hookResourceId) {
|
|
27592
|
+
const key = `${stage}:${hookResourceId}`;
|
|
27593
|
+
const nextValue = (this.counters.get(key) ?? 0) + 1;
|
|
27594
|
+
this.counters.set(key, nextValue);
|
|
27595
|
+
return nextValue;
|
|
27596
|
+
}
|
|
27597
|
+
};
|
|
27598
|
+
function buildHookContextBase(resource, stage, commonParams, eventId, timestamp) {
|
|
27599
|
+
return {
|
|
27600
|
+
version: "1.0",
|
|
27601
|
+
stage,
|
|
27602
|
+
hookId: resource.resourceId,
|
|
27603
|
+
hookName: resource.config.name,
|
|
27604
|
+
eventId,
|
|
27605
|
+
timestamp,
|
|
27606
|
+
commonParams
|
|
27607
|
+
};
|
|
27608
|
+
}
|
|
27609
|
+
|
|
27610
|
+
// ../linkque-agent-runtime/dist/esm/core/hook/hookRegistry.js
|
|
27611
|
+
var DEFAULT_HOOK_ORDER = 100;
|
|
27612
|
+
var DEFAULT_HOOK_TIMEOUT_MS = 1e3;
|
|
27613
|
+
var MAX_HOOK_TIMEOUT_MS = 5e3;
|
|
27614
|
+
function normalizeHookResources(resources) {
|
|
27615
|
+
return resources.filter((resource) => resource.config.enabled !== false).map((resource) => {
|
|
27616
|
+
const config = Object.assign({}, resource.config, {
|
|
27617
|
+
order: resource.config.order ?? DEFAULT_HOOK_ORDER,
|
|
27618
|
+
timeoutMs: Math.min(Math.max(resource.config.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS, 0), MAX_HOOK_TIMEOUT_MS)
|
|
27619
|
+
});
|
|
27620
|
+
return Object.assign({}, resource, { config });
|
|
27621
|
+
}).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
|
|
27622
|
+
}
|
|
27623
|
+
|
|
27564
27624
|
// ../linkque-agent-runtime/dist/esm/core/hook/hookDispatcher.js
|
|
27565
27625
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
27566
27626
|
|
|
@@ -28720,37 +28780,6 @@ var LinkquegwEventHookExecutor = class {
|
|
|
28720
28780
|
}
|
|
28721
28781
|
};
|
|
28722
28782
|
|
|
28723
|
-
// ../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js
|
|
28724
|
-
function recordContentSection(observation, section, value, availability = "available") {
|
|
28725
|
-
observation?.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, { section, value, availability });
|
|
28726
|
-
}
|
|
28727
|
-
function recordMcpContentSection(observation, section, value, schema) {
|
|
28728
|
-
if (!observation)
|
|
28729
|
-
return;
|
|
28730
|
-
const fieldTitles = {};
|
|
28731
|
-
const visit = (node, path2) => {
|
|
28732
|
-
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
28733
|
-
return;
|
|
28734
|
-
const definition = node;
|
|
28735
|
-
if (path2 && typeof definition.title === "string" && definition.title.trim())
|
|
28736
|
-
fieldTitles[path2] = definition.title;
|
|
28737
|
-
const properties = definition.properties;
|
|
28738
|
-
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
28739
|
-
for (const [key, child] of Object.entries(properties))
|
|
28740
|
-
visit(child, `${path2}/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`);
|
|
28741
|
-
}
|
|
28742
|
-
if (definition.items)
|
|
28743
|
-
visit(definition.items, `${path2}/*`);
|
|
28744
|
-
};
|
|
28745
|
-
visit(schema, section === ETelemetryContentSection.MCP_OUTPUT ? "/structuredContent" : "");
|
|
28746
|
-
observation.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, {
|
|
28747
|
-
section,
|
|
28748
|
-
value,
|
|
28749
|
-
availability: "available",
|
|
28750
|
-
...Object.keys(fieldTitles).length ? { fieldTitles } : {}
|
|
28751
|
-
});
|
|
28752
|
-
}
|
|
28753
|
-
|
|
28754
28783
|
// ../linkque-agent-runtime/dist/esm/core/skillTools.js
|
|
28755
28784
|
var ACTIVATE_SKILL_TOOL_NAME = "activate_skill";
|
|
28756
28785
|
var AVAILABLE_SKILLS_OPEN = "<available_skills>";
|
|
@@ -35977,7 +36006,7 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
35977
36006
|
} catch (error) {
|
|
35978
36007
|
invocation.signal.throwIfAborted();
|
|
35979
36008
|
if (invocation.auth && !(error instanceof McpInvocationError))
|
|
35980
|
-
throw new Error("MCP \u7528\u6237\u5DE5\u5177\u8C03\u7528\u5931\u8D25");
|
|
36009
|
+
throw new Error("MCP \u7528\u6237\u5DE5\u5177\u8C03\u7528\u5931\u8D25", { cause: error });
|
|
35981
36010
|
throw error;
|
|
35982
36011
|
}
|
|
35983
36012
|
}));
|
|
@@ -37709,6 +37738,7 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
|
|
|
37709
37738
|
ETelemetryAttribute.GEN_AI_REQUEST_MODEL,
|
|
37710
37739
|
ETelemetryAttribute.GEN_AI_RESPONSE_MODEL,
|
|
37711
37740
|
ETelemetryAttribute.GEN_AI_RESPONSE_ID,
|
|
37741
|
+
ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED,
|
|
37712
37742
|
ETelemetryAttribute.GEN_AI_RESPONSE_FINISH_REASONS,
|
|
37713
37743
|
ETelemetryAttribute.GEN_AI_USAGE_INPUT_TOKENS,
|
|
37714
37744
|
ETelemetryAttribute.GEN_AI_USAGE_OUTPUT_TOKENS,
|
|
@@ -38037,7 +38067,16 @@ var OtelRuntimeTelemetry = class {
|
|
|
38037
38067
|
Math.floor(now / 1e3),
|
|
38038
38068
|
now % 1e3 * 1e6
|
|
38039
38069
|
];
|
|
38040
|
-
const localOnly = name === ETelemetryEventName.
|
|
38070
|
+
const localOnly = name === ETelemetryEventName.CONTENT_RECORDED;
|
|
38071
|
+
if (localOnly && body && typeof body === "object" && "value" in body) {
|
|
38072
|
+
const { value, ...metadata } = body;
|
|
38073
|
+
try {
|
|
38074
|
+
const valueJson = JSON.stringify(value);
|
|
38075
|
+
body = valueJson !== void 0 && Buffer.byteLength(JSON.stringify(valueJson), "utf8") <= 512 * 1024 ? { ...metadata, valueJson } : { ...metadata, availability: "unavailable", reason: "content_limit" };
|
|
38076
|
+
} catch {
|
|
38077
|
+
body = { ...metadata, availability: "unavailable" };
|
|
38078
|
+
}
|
|
38079
|
+
}
|
|
38041
38080
|
if (!localOnly && operation.span.isRecording())
|
|
38042
38081
|
operation.span.addEvent(
|
|
38043
38082
|
name,
|
|
@@ -38204,19 +38243,7 @@ export {
|
|
|
38204
38243
|
McpPhoneAuthorizationFailedError,
|
|
38205
38244
|
isMcpPhoneAuthorizationError,
|
|
38206
38245
|
resolvePhoneAuthorizationDependency,
|
|
38207
|
-
|
|
38208
|
-
executeHomeData,
|
|
38209
|
-
CardActionDiagnostics,
|
|
38210
|
-
executeCardAction,
|
|
38211
|
-
executeFunctionActionMcp,
|
|
38212
|
-
FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
|
|
38213
|
-
prepareFollowUpQuestionContext,
|
|
38214
|
-
normalizeFollowUpQuestionStrings,
|
|
38215
|
-
InMemorySessionManager,
|
|
38216
|
-
NoopSkillLoader,
|
|
38217
|
-
NoopMcpServerProvider,
|
|
38218
|
-
buildHookCommonParams,
|
|
38219
|
-
normalizeHookResources,
|
|
38246
|
+
CONTENT_VALUE_MAX_LENGTH,
|
|
38220
38247
|
ETelemetryAttribute,
|
|
38221
38248
|
ETelemetryEventPrefix,
|
|
38222
38249
|
ETelemetryEventName,
|
|
@@ -38242,6 +38269,20 @@ export {
|
|
|
38242
38269
|
ETelemetryModelPurpose,
|
|
38243
38270
|
ETelemetryErrorType,
|
|
38244
38271
|
ETelemetryGenAiOperation,
|
|
38272
|
+
recordContentSection,
|
|
38273
|
+
McpProxyTool,
|
|
38274
|
+
executeHomeData,
|
|
38275
|
+
CardActionDiagnostics,
|
|
38276
|
+
executeCardAction,
|
|
38277
|
+
executeFunctionActionMcp,
|
|
38278
|
+
FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
|
|
38279
|
+
prepareFollowUpQuestionContext,
|
|
38280
|
+
normalizeFollowUpQuestionStrings,
|
|
38281
|
+
InMemorySessionManager,
|
|
38282
|
+
NoopSkillLoader,
|
|
38283
|
+
NoopMcpServerProvider,
|
|
38284
|
+
buildHookCommonParams,
|
|
38285
|
+
normalizeHookResources,
|
|
38245
38286
|
warnLogFailure,
|
|
38246
38287
|
HookDispatcher,
|
|
38247
38288
|
DEFAULT_HOOK_DRAIN_BUDGET_MS,
|
|
@@ -38256,7 +38297,6 @@ export {
|
|
|
38256
38297
|
summarizeBody,
|
|
38257
38298
|
formatHttpLogLine,
|
|
38258
38299
|
LinkquegwEventHookExecutor,
|
|
38259
|
-
recordContentSection,
|
|
38260
38300
|
ACTIVATE_SKILL_TOOL_NAME,
|
|
38261
38301
|
parseSkillFile,
|
|
38262
38302
|
buildSkillCatalog,
|