linkque-cli-v2 1.3.5 → 1.3.6
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 +6 -110
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-LT6VSAY4.js → chunk-7SF3H2GM.js} +51 -144
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NBYB7HSY.js → chunk-NHRW2KQW.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-VVEDZWQ5.js → chunk-RHFHCJYP.js} +143 -35
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +330 -621
- 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/worker.js +183 -63
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-VVEDZWQ5.js → chunk-RHFHCJYP.js}
RENAMED
|
@@ -4250,14 +4250,13 @@ var require_fast_uri = __commonJS({
|
|
|
4250
4250
|
if (!malformedIPLiteral) {
|
|
4251
4251
|
malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP);
|
|
4252
4252
|
}
|
|
4253
|
-
if (uri.indexOf("%") !== -1 && parsed.host !== void 0 && !malformedIPLiteral) {
|
|
4254
|
-
let host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true);
|
|
4255
|
-
if (!isIP) {
|
|
4256
|
-
host = normalizePercentEncoding(host.toLowerCase());
|
|
4257
|
-
}
|
|
4258
|
-
parsed.host = reescapeHostDelimiters(host, isIP);
|
|
4259
|
-
}
|
|
4260
4253
|
if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
|
|
4254
|
+
if (uri.indexOf("%") !== -1) {
|
|
4255
|
+
if (parsed.host !== void 0 && !malformedIPLiteral) {
|
|
4256
|
+
const host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true);
|
|
4257
|
+
parsed.host = reescapeHostDelimiters(host, isIP);
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4261
4260
|
if (parsed.path) {
|
|
4262
4261
|
parsed.path = normalizePathEncoding(parsed.path);
|
|
4263
4262
|
}
|
|
@@ -11823,7 +11822,7 @@ var FALLBACK_OBJECT_SCHEMA = {
|
|
|
11823
11822
|
function createCardPresentationToolName(resourceId) {
|
|
11824
11823
|
return stableToolName("a2ui_card", resourceId);
|
|
11825
11824
|
}
|
|
11826
|
-
async function executeCardPresentation(resource, registry, runtimeContext, args, signal) {
|
|
11825
|
+
async function executeCardPresentation(resource, registry, runtimeContext, args, signal, context) {
|
|
11827
11826
|
const config = parseCardConfig(resource);
|
|
11828
11827
|
if (config.schemaVersion !== "2") {
|
|
11829
11828
|
throw new Error(`Schema v${config.schemaVersion} cards must be executed through the card data-source loop`);
|
|
@@ -11852,7 +11851,7 @@ async function executeCardPresentation(resource, registry, runtimeContext, args,
|
|
|
11852
11851
|
inputSchema,
|
|
11853
11852
|
outputSchema: isJsonObject(handle.outputSchema) ? handle.outputSchema : FALLBACK_OBJECT_SCHEMA,
|
|
11854
11853
|
call: async (input, callSignal) => {
|
|
11855
|
-
const result = await handle.execute(supplementMcpInput(input, invocation, config.presentationInputSchema, inputSchema), callSignal);
|
|
11854
|
+
const result = await handle.execute(supplementMcpInput(input, invocation, config.presentationInputSchema, inputSchema), callSignal, context);
|
|
11856
11855
|
return { structuredContent: readStructuredContent(result) };
|
|
11857
11856
|
}
|
|
11858
11857
|
};
|
|
@@ -12119,6 +12118,8 @@ function aggregateMcpServers(resources, protocolAgentId) {
|
|
|
12119
12118
|
argsMappingRules: [],
|
|
12120
12119
|
allowedTools: void 0,
|
|
12121
12120
|
resourceIds: [],
|
|
12121
|
+
allToolResourceIds: [],
|
|
12122
|
+
resourceIdsByTool: /* @__PURE__ */ new Map(),
|
|
12122
12123
|
description: ""
|
|
12123
12124
|
};
|
|
12124
12125
|
specs.set(serverName, spec);
|
|
@@ -12142,14 +12143,19 @@ function aggregateMcpServers(resources, protocolAgentId) {
|
|
|
12142
12143
|
if (allowed && allowed.length > 0) {
|
|
12143
12144
|
if (!spec.allowedTools)
|
|
12144
12145
|
spec.allowedTools = /* @__PURE__ */ new Set();
|
|
12145
|
-
for (const toolName of allowed)
|
|
12146
|
+
for (const toolName of allowed) {
|
|
12146
12147
|
spec.allowedTools.add(toolName);
|
|
12148
|
+
addToolResourceId(spec.resourceIdsByTool, toolName, resource.resourceId);
|
|
12149
|
+
}
|
|
12150
|
+
} else {
|
|
12151
|
+
spec.allToolResourceIds.push(resource.resourceId);
|
|
12147
12152
|
}
|
|
12148
12153
|
continue;
|
|
12149
12154
|
}
|
|
12150
12155
|
if (!spec.allowedTools)
|
|
12151
12156
|
spec.allowedTools = /* @__PURE__ */ new Set();
|
|
12152
12157
|
spec.allowedTools.add(resource.config.toolName);
|
|
12158
|
+
addToolResourceId(spec.resourceIdsByTool, resource.config.toolName, resource.resourceId);
|
|
12153
12159
|
for (const rule of resource.config.argsMappingRules ?? []) {
|
|
12154
12160
|
const fullRule = {
|
|
12155
12161
|
mcpToolName: resource.config.toolName,
|
|
@@ -12163,6 +12169,53 @@ function aggregateMcpServers(resources, protocolAgentId) {
|
|
|
12163
12169
|
}
|
|
12164
12170
|
return [...specs.values()];
|
|
12165
12171
|
}
|
|
12172
|
+
function addToolResourceId(target, toolName, resourceId) {
|
|
12173
|
+
const current = target.get(toolName) ?? [];
|
|
12174
|
+
current.push(resourceId);
|
|
12175
|
+
target.set(toolName, current);
|
|
12176
|
+
}
|
|
12177
|
+
|
|
12178
|
+
// ../linkque-agent-runtime/dist/esm/core/mcpPhoneAuthorization.js
|
|
12179
|
+
var McpPhoneAuthorizationRequiredError = class extends Error {
|
|
12180
|
+
required;
|
|
12181
|
+
code = "MCP_PHONE_AUTHORIZATION_REQUIRED";
|
|
12182
|
+
constructor(required) {
|
|
12183
|
+
super("\u8C03\u7528\u8BE5 MCP Tool \u524D\u9700\u8981\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743");
|
|
12184
|
+
this.required = required;
|
|
12185
|
+
this.name = "McpPhoneAuthorizationRequiredError";
|
|
12186
|
+
}
|
|
12187
|
+
};
|
|
12188
|
+
var McpPhoneAuthorizationFailedError = class extends Error {
|
|
12189
|
+
code = "MCP_PHONE_AUTHORIZATION_FAILED";
|
|
12190
|
+
constructor() {
|
|
12191
|
+
super("\u672A\u53D6\u5F97\u624B\u673A\u53F7\u6388\u6743\uFF0C\u65E0\u6CD5\u8C03\u7528\u8BE5 MCP Tool");
|
|
12192
|
+
this.name = "McpPhoneAuthorizationFailedError";
|
|
12193
|
+
}
|
|
12194
|
+
};
|
|
12195
|
+
function createRequestMcpPhoneAuthorizer(protocol, attempt) {
|
|
12196
|
+
return async ({ resourceIds, toolName, signal }) => {
|
|
12197
|
+
if (signal?.aborted)
|
|
12198
|
+
throw Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
|
|
12199
|
+
const policy = resolvePhoneAuthorizationDependency(protocol, resourceIds, toolName);
|
|
12200
|
+
if (!policy)
|
|
12201
|
+
return void 0;
|
|
12202
|
+
if (attempt?.kind === "authorized")
|
|
12203
|
+
return { "x-alipay-authcode": attempt.authCode };
|
|
12204
|
+
if (attempt?.kind === "unavailable") {
|
|
12205
|
+
if (policy.required)
|
|
12206
|
+
throw new McpPhoneAuthorizationFailedError();
|
|
12207
|
+
return void 0;
|
|
12208
|
+
}
|
|
12209
|
+
throw new McpPhoneAuthorizationRequiredError(policy.required);
|
|
12210
|
+
};
|
|
12211
|
+
}
|
|
12212
|
+
function isMcpPhoneAuthorizationError(error) {
|
|
12213
|
+
return error instanceof McpPhoneAuthorizationRequiredError || error instanceof McpPhoneAuthorizationFailedError;
|
|
12214
|
+
}
|
|
12215
|
+
function resolvePhoneAuthorizationDependency(protocol, resourceIds, toolName) {
|
|
12216
|
+
const dependencies = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP_TOOL).flatMap((resource) => resourceIds.includes(resource.resourceId) && resource.config.toolName === toolName ? (resource.config.dependencies ?? []).filter((dependency) => dependency.name === "phoneAuthorization") : []);
|
|
12217
|
+
return dependencies.length ? { required: dependencies.some((dependency) => dependency.required) } : void 0;
|
|
12218
|
+
}
|
|
12166
12219
|
|
|
12167
12220
|
// ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
|
|
12168
12221
|
var MCP_PROXY_TOOL_NAME = "mcp";
|
|
@@ -12177,6 +12230,7 @@ var McpProxyTool = class {
|
|
|
12177
12230
|
specByResourceId;
|
|
12178
12231
|
specs;
|
|
12179
12232
|
debugLog;
|
|
12233
|
+
authorizeCall;
|
|
12180
12234
|
constructor(provider, specs, options = {}) {
|
|
12181
12235
|
this.provider = provider;
|
|
12182
12236
|
this.specs = specs;
|
|
@@ -12184,6 +12238,7 @@ var McpProxyTool = class {
|
|
|
12184
12238
|
this.specByResourceId = new Map(specs.flatMap((spec) => spec.resourceIds.map((id) => [id, spec])));
|
|
12185
12239
|
this.debugLog = options.debugLog ?? (() => {
|
|
12186
12240
|
});
|
|
12241
|
+
this.authorizeCall = options.authorizeCall;
|
|
12187
12242
|
}
|
|
12188
12243
|
/**
|
|
12189
12244
|
* 产单个 `mcp` 代理工具描述符,注入 `agentReq.tools`。
|
|
@@ -12196,7 +12251,7 @@ var McpProxyTool = class {
|
|
|
12196
12251
|
label: "MCP",
|
|
12197
12252
|
description: MCP_PROXY_DESCRIPTION,
|
|
12198
12253
|
inputSchema: MCP_PROXY_INPUT_SCHEMA,
|
|
12199
|
-
execute: (args, signal) => this.dispatch(args, signal)
|
|
12254
|
+
execute: (args, signal, context) => this.dispatch(args, signal, context)
|
|
12200
12255
|
};
|
|
12201
12256
|
}
|
|
12202
12257
|
/** {@link IMcpToolRegistry.resolve}:按 (resourceId, toolName) 解析可调用句柄。 */
|
|
@@ -12213,7 +12268,18 @@ var McpProxyTool = class {
|
|
|
12213
12268
|
return {
|
|
12214
12269
|
inputSchema: tool.inputSchema,
|
|
12215
12270
|
outputSchema: tool.outputSchema,
|
|
12216
|
-
execute: (args, sig) =>
|
|
12271
|
+
execute: async (args, sig, context) => {
|
|
12272
|
+
const headers = await this.authorizeCall?.({
|
|
12273
|
+
resourceIds: [resourceId],
|
|
12274
|
+
toolName: tool.name,
|
|
12275
|
+
signal: sig,
|
|
12276
|
+
context
|
|
12277
|
+
});
|
|
12278
|
+
return entry.server.callTool(tool.name, args, sig, {
|
|
12279
|
+
...headers ? { headers } : {},
|
|
12280
|
+
...context ? { context } : {}
|
|
12281
|
+
});
|
|
12282
|
+
}
|
|
12217
12283
|
};
|
|
12218
12284
|
}
|
|
12219
12285
|
/** 关闭所有已连 server(忽略单 server 关闭错误)。 */
|
|
@@ -12300,7 +12366,7 @@ var McpProxyTool = class {
|
|
|
12300
12366
|
}
|
|
12301
12367
|
// —— 派发 ——
|
|
12302
12368
|
/** 按入参字段派发;返回 LLM 可读文本。 */
|
|
12303
|
-
async dispatch(args, signal) {
|
|
12369
|
+
async dispatch(args, signal, context) {
|
|
12304
12370
|
const params = parseProxyArgs(args);
|
|
12305
12371
|
if (params.connect !== void 0) {
|
|
12306
12372
|
return this.executeConnect(params.connect, signal);
|
|
@@ -12315,7 +12381,7 @@ var McpProxyTool = class {
|
|
|
12315
12381
|
return this.executeSearch(params.search, params.server);
|
|
12316
12382
|
}
|
|
12317
12383
|
if (params.tool !== void 0) {
|
|
12318
|
-
return this.executeCall(params.tool, params.args, params.server, signal);
|
|
12384
|
+
return this.executeCall(params.tool, params.args, params.server, signal, context);
|
|
12319
12385
|
}
|
|
12320
12386
|
if (params.server !== void 0) {
|
|
12321
12387
|
return this.executeList(params.server, signal);
|
|
@@ -12443,14 +12509,23 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
12443
12509
|
return lines.join("\n").trim();
|
|
12444
12510
|
}
|
|
12445
12511
|
/** `mcp({ tool: "name", args: {...} })`:调用工具,返回序列化结果。 */
|
|
12446
|
-
async executeCall(toolName, args, serverHint, signal) {
|
|
12512
|
+
async executeCall(toolName, args, serverHint, signal, context) {
|
|
12447
12513
|
const found = await this.findTool(toolName, serverHint, signal);
|
|
12448
12514
|
if (!found) {
|
|
12449
12515
|
return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
|
|
12450
12516
|
}
|
|
12451
|
-
const { entry, tool } = found;
|
|
12517
|
+
const { entry, tool, spec } = found;
|
|
12452
12518
|
try {
|
|
12453
|
-
const
|
|
12519
|
+
const headers = await this.authorizeCall?.({
|
|
12520
|
+
resourceIds: resourceIdsForTool(spec, tool.name),
|
|
12521
|
+
toolName: tool.name,
|
|
12522
|
+
signal,
|
|
12523
|
+
context
|
|
12524
|
+
});
|
|
12525
|
+
const result = await entry.server.callTool(tool.name, args, signal, {
|
|
12526
|
+
...headers ? { headers } : {},
|
|
12527
|
+
...context ? { context } : {}
|
|
12528
|
+
});
|
|
12454
12529
|
return serializeToolResult(result);
|
|
12455
12530
|
} catch (error) {
|
|
12456
12531
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -12467,7 +12542,7 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
12467
12542
|
continue;
|
|
12468
12543
|
const tool = entry.tools.find((t) => t.name === toolName);
|
|
12469
12544
|
if (tool) {
|
|
12470
|
-
return { entry, server: spec.serverName, tool };
|
|
12545
|
+
return { entry, server: spec.serverName, tool, spec };
|
|
12471
12546
|
}
|
|
12472
12547
|
}
|
|
12473
12548
|
await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, signal)));
|
|
@@ -12477,7 +12552,7 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
12477
12552
|
continue;
|
|
12478
12553
|
const tool = entry.tools.find((t) => t.name === toolName);
|
|
12479
12554
|
if (tool) {
|
|
12480
|
-
return { entry, server: spec.serverName, tool };
|
|
12555
|
+
return { entry, server: spec.serverName, tool, spec };
|
|
12481
12556
|
}
|
|
12482
12557
|
}
|
|
12483
12558
|
return void 0;
|
|
@@ -12502,6 +12577,14 @@ ${formatSchema(tool.inputSchema)}`);
|
|
|
12502
12577
|
return lines.join("\n").trim();
|
|
12503
12578
|
}
|
|
12504
12579
|
};
|
|
12580
|
+
function resourceIdsForTool(spec, toolName) {
|
|
12581
|
+
if (!spec.allToolResourceIds && !spec.resourceIdsByTool)
|
|
12582
|
+
return spec.resourceIds;
|
|
12583
|
+
return [
|
|
12584
|
+
...spec.allToolResourceIds ?? [],
|
|
12585
|
+
...spec.resourceIdsByTool?.get(toolName) ?? []
|
|
12586
|
+
];
|
|
12587
|
+
}
|
|
12505
12588
|
function parseProxyArgs(args) {
|
|
12506
12589
|
if (!isRecord(args))
|
|
12507
12590
|
return {};
|
|
@@ -12628,7 +12711,9 @@ async function executeHomeData(input) {
|
|
|
12628
12711
|
if (spec.allowedTools && !spec.allowedTools.has(request.binding.toolName)) {
|
|
12629
12712
|
return failure("TOOL_NOT_ALLOWED", "\u5F53\u524D Agent \u672A\u5141\u8BB8\u8C03\u7528\u8BE5 MCP \u5DE5\u5177", false);
|
|
12630
12713
|
}
|
|
12631
|
-
const registry = new McpProxyTool(input.mcpServerProvider, specs
|
|
12714
|
+
const registry = new McpProxyTool(input.mcpServerProvider, specs, {
|
|
12715
|
+
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
12716
|
+
});
|
|
12632
12717
|
try {
|
|
12633
12718
|
const handle = await registry.resolve(spec.resourceIds[0], request.binding.toolName, input.signal);
|
|
12634
12719
|
if (!handle) {
|
|
@@ -12656,6 +12741,8 @@ async function executeHomeData(input) {
|
|
|
12656
12741
|
try {
|
|
12657
12742
|
result = await handle.execute(toolInput, input.signal);
|
|
12658
12743
|
} catch (error) {
|
|
12744
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
12745
|
+
throw error;
|
|
12659
12746
|
return failure("EXECUTION_FAILED", error instanceof Error ? error.message : "MCP \u5DE5\u5177\u8C03\u7528\u5931\u8D25", true);
|
|
12660
12747
|
}
|
|
12661
12748
|
const structured = readStructuredContent2(result);
|
|
@@ -12901,7 +12988,7 @@ async function executeCardActionInternal(input, diagnostics) {
|
|
|
12901
12988
|
});
|
|
12902
12989
|
diagnostics.write("binding_resolved", { output: createTrade });
|
|
12903
12990
|
diagnostics.stage = "tool_resolve";
|
|
12904
|
-
const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog);
|
|
12991
|
+
const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog, input.phoneAuthorization);
|
|
12905
12992
|
try {
|
|
12906
12993
|
diagnostics.write("tool_resolve_started", { input: createTrade });
|
|
12907
12994
|
const tool = await registry.resolve(createTrade.mcpResourceId, createTrade.toolName, input.signal);
|
|
@@ -12929,6 +13016,8 @@ async function executeCardActionInternal(input, diagnostics) {
|
|
|
12929
13016
|
diagnostics.write("tool_completed", { output: result });
|
|
12930
13017
|
} catch (error) {
|
|
12931
13018
|
diagnostics.error("tool_failed", error);
|
|
13019
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
13020
|
+
throw error;
|
|
12932
13021
|
return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
|
|
12933
13022
|
}
|
|
12934
13023
|
diagnostics.stage = "tool_output";
|
|
@@ -13068,9 +13157,12 @@ function materializeValue(definition, supplied) {
|
|
|
13068
13157
|
}
|
|
13069
13158
|
return definition;
|
|
13070
13159
|
}
|
|
13071
|
-
function createRegistry(protocol, provider, debugLog) {
|
|
13160
|
+
function createRegistry(protocol, provider, debugLog, phoneAuthorization) {
|
|
13072
13161
|
const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
13073
|
-
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), {
|
|
13162
|
+
return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), {
|
|
13163
|
+
debugLog,
|
|
13164
|
+
authorizeCall: createRequestMcpPhoneAuthorizer(protocol, phoneAuthorization)
|
|
13165
|
+
});
|
|
13074
13166
|
}
|
|
13075
13167
|
function readStructuredContent3(result) {
|
|
13076
13168
|
const object3 = cloneJsonObject(result);
|
|
@@ -13103,7 +13195,9 @@ async function executeAuthorizedMcp(input) {
|
|
|
13103
13195
|
if (!input.userId.trim())
|
|
13104
13196
|
return failure3("AUTH_REQUIRED", "\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
|
|
13105
13197
|
const resources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
|
|
13106
|
-
const registry = new McpProxyTool(input.mcpServerProvider, aggregateMcpServers(resources, input.protocol.agentId)
|
|
13198
|
+
const registry = new McpProxyTool(input.mcpServerProvider, aggregateMcpServers(resources, input.protocol.agentId), {
|
|
13199
|
+
authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
|
|
13200
|
+
});
|
|
13107
13201
|
try {
|
|
13108
13202
|
const tool = await registry.resolve(input.tool.mcpResourceId, input.tool.toolName, input.signal);
|
|
13109
13203
|
if (!tool)
|
|
@@ -13115,7 +13209,9 @@ async function executeAuthorizedMcp(input) {
|
|
|
13115
13209
|
let result;
|
|
13116
13210
|
try {
|
|
13117
13211
|
result = await tool.execute(input.tool.input, input.signal);
|
|
13118
|
-
} catch {
|
|
13212
|
+
} catch (error) {
|
|
13213
|
+
if (isMcpPhoneAuthorizationError(error))
|
|
13214
|
+
throw error;
|
|
13119
13215
|
return failure3("EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5", false);
|
|
13120
13216
|
}
|
|
13121
13217
|
const structured = readStructuredContent4(result);
|
|
@@ -13179,7 +13275,8 @@ async function executeFunctionActionMcp(input) {
|
|
|
13179
13275
|
callId: request.callId,
|
|
13180
13276
|
tool: request.tool,
|
|
13181
13277
|
mcpServerProvider: input.mcpServerProvider,
|
|
13182
|
-
signal: input.signal
|
|
13278
|
+
signal: input.signal,
|
|
13279
|
+
phoneAuthorization: input.phoneAuthorization
|
|
13183
13280
|
});
|
|
13184
13281
|
}
|
|
13185
13282
|
function failure4(code, message, retryable) {
|
|
@@ -14512,6 +14609,7 @@ var REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
|
14512
14609
|
"x-api-key",
|
|
14513
14610
|
"x-signature-content",
|
|
14514
14611
|
"x-alipay-sdk-version",
|
|
14612
|
+
"x-alipay-authcode",
|
|
14515
14613
|
"anthropic-api-key"
|
|
14516
14614
|
]);
|
|
14517
14615
|
var REDACTED_VALUE = "ak***";
|
|
@@ -21455,7 +21553,7 @@ var SSEClientTransport = class {
|
|
|
21455
21553
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/signingFetch.js
|
|
21456
21554
|
var ALIPAY_SDK_VERSION = "@alipay/open-mcp-server-2.0.4";
|
|
21457
21555
|
var OAGW_ALIPAY_UID_HEADER = "x-oagw-alipay-uid";
|
|
21458
|
-
function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog) {
|
|
21556
|
+
function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog, getCallHeaders) {
|
|
21459
21557
|
const loggedFetch = debugLog ? createHttpLoggingFetch(debugLog, "mcp-call", baseFetch) : baseFetch;
|
|
21460
21558
|
return async (url2, init) => {
|
|
21461
21559
|
const targetUrl = url2 instanceof URL ? url2 : new URL(typeof url2 === "string" ? url2 : url2.url);
|
|
@@ -21474,6 +21572,13 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
21474
21572
|
} else {
|
|
21475
21573
|
headers.delete(OAGW_ALIPAY_UID_HEADER);
|
|
21476
21574
|
}
|
|
21575
|
+
if ((init?.method ?? "GET").toUpperCase() === "POST") {
|
|
21576
|
+
const authCode = getCallHeaders?.()?.["x-alipay-authcode"];
|
|
21577
|
+
if (authCode)
|
|
21578
|
+
headers.set("x-alipay-authcode", authCode);
|
|
21579
|
+
else
|
|
21580
|
+
headers.delete("x-alipay-authcode");
|
|
21581
|
+
}
|
|
21477
21582
|
const resp = await loggedFetch(url2, { ...init, headers });
|
|
21478
21583
|
if (onTraceId) {
|
|
21479
21584
|
try {
|
|
@@ -21502,10 +21607,10 @@ function withTimeout(fetch2, timeoutMs) {
|
|
|
21502
21607
|
return fetch2(url2, { ...init, signal });
|
|
21503
21608
|
};
|
|
21504
21609
|
}
|
|
21505
|
-
function createSseTransport(config, signer, onTraceId, debugLog) {
|
|
21610
|
+
function createSseTransport(config, signer, onTraceId, debugLog, getCallHeaders) {
|
|
21506
21611
|
const url2 = new URL(config.sseEndpoint, config.remoteBaseUrl);
|
|
21507
21612
|
const timeoutMs = config.requestTimeoutMs ?? 18e4;
|
|
21508
|
-
const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog), timeoutMs);
|
|
21613
|
+
const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog, getCallHeaders), timeoutMs);
|
|
21509
21614
|
return new SSEClientTransport(url2, {
|
|
21510
21615
|
// SSE 建连(EventSource)的 GET fetch:SDK 先包默认头再调这里。
|
|
21511
21616
|
eventSourceInit: { fetch: signingFetch },
|
|
@@ -21605,6 +21710,7 @@ function applyArgsMappingRules(toolName, args, rules) {
|
|
|
21605
21710
|
}
|
|
21606
21711
|
|
|
21607
21712
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
|
|
21713
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
21608
21714
|
var defaultCreateSigner = (config, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
|
|
21609
21715
|
agentId: config.agentId,
|
|
21610
21716
|
signEndpoint: config.signEndpoint,
|
|
@@ -21634,8 +21740,9 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
21634
21740
|
/** 连单个远端 server 并包装成 IMcpServer。建连失败有限重试 + 失败清理由 helper 负责。 */
|
|
21635
21741
|
async connectOne(resource) {
|
|
21636
21742
|
const config = await this.resolveConfig(resource);
|
|
21743
|
+
const callHeaders = new AsyncLocalStorage();
|
|
21637
21744
|
const { client } = await connectMcpClientWithRetry(config, {
|
|
21638
|
-
createTransport: () => createSseTransport(config, this.createSigner(config, this.getAuthorizationHeader), this.onTraceId, this.debugLog),
|
|
21745
|
+
createTransport: () => createSseTransport(config, this.createSigner(config, this.getAuthorizationHeader), this.onTraceId, this.debugLog, () => callHeaders.getStore()),
|
|
21639
21746
|
createClient: () => this.createClient()
|
|
21640
21747
|
});
|
|
21641
21748
|
const serverName = resource.config.serverName ?? resource.resourceId;
|
|
@@ -21670,12 +21777,9 @@ var RemoteGatewayMcpServerProvider = class {
|
|
|
21670
21777
|
resourceId: resource.resourceId,
|
|
21671
21778
|
serverName,
|
|
21672
21779
|
listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
|
|
21673
|
-
callTool: (name, args) => {
|
|
21780
|
+
callTool: (name, args, _signal, options) => {
|
|
21674
21781
|
const mapped = applyArgsMappingRules(name, args, argsMappingRules);
|
|
21675
|
-
return loggedClient.callTool({
|
|
21676
|
-
name,
|
|
21677
|
-
arguments: mapped ?? {}
|
|
21678
|
-
});
|
|
21782
|
+
return callHeaders.run(options?.headers ?? {}, () => loggedClient.callTool({ name, arguments: mapped ?? {} }));
|
|
21679
21783
|
},
|
|
21680
21784
|
close: async () => {
|
|
21681
21785
|
try {
|
|
@@ -23142,6 +23246,10 @@ export {
|
|
|
23142
23246
|
normalizeMcpInputSchema,
|
|
23143
23247
|
CardMappingError,
|
|
23144
23248
|
aggregateMcpServers,
|
|
23249
|
+
McpPhoneAuthorizationRequiredError,
|
|
23250
|
+
McpPhoneAuthorizationFailedError,
|
|
23251
|
+
isMcpPhoneAuthorizationError,
|
|
23252
|
+
resolvePhoneAuthorizationDependency,
|
|
23145
23253
|
McpProxyTool,
|
|
23146
23254
|
executeHomeData,
|
|
23147
23255
|
CardActionDiagnostics,
|