linkque-cli-v2 1.3.4 → 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.
@@ -10211,6 +10211,54 @@ function getA2UIV4ProtocolIssues(value, path2 = "card") {
10211
10211
  validateReferences(surfaces, path2, issues);
10212
10212
  return issues;
10213
10213
  }
10214
+ function validateV4Component(component, componentPath, issues) {
10215
+ const schema = A2UI_V4_COMPONENT_CATALOG.components[component.component];
10216
+ if (!schema) {
10217
+ issues.push(issue2(`${componentPath}.component`, "UNSUPPORTED_COMPONENT", `V4 does not support component ${component.component}`));
10218
+ return;
10219
+ }
10220
+ const allowed = /* @__PURE__ */ new Set([
10221
+ "id",
10222
+ "component",
10223
+ ...Object.keys(schema.properties)
10224
+ ]);
10225
+ for (const key of Object.keys(component))
10226
+ if (!allowed.has(key))
10227
+ issues.push(issue2(`${componentPath}.${key}`, "UNSUPPORTED_COMPONENT_PROP", `${component.component} does not support property ${key}`));
10228
+ for (const [name, property] of Object.entries(schema.properties)) {
10229
+ const value = component[name];
10230
+ if (property.required && value === void 0)
10231
+ issues.push(issue2(`${componentPath}.${name}`, "REQUIRED_COMPONENT_PROP_MISSING", `${component.component}.${name} is required`));
10232
+ if (value !== void 0)
10233
+ validateProperty(value, property, `${componentPath}.${name}`, issues, name);
10234
+ }
10235
+ if (component["x2-overflow"] !== void 0)
10236
+ validateOverflow(component, componentPath, issues);
10237
+ if (component.component === "TextField")
10238
+ validateTextField(component, componentPath, issues);
10239
+ if (component.component === "ChoicePicker") {
10240
+ if (!isStrictBinding(component.value))
10241
+ issues.push(issue2(`${componentPath}.value`, "INPUT_REQUIRES_BINDING", "ChoicePicker.value must be a strict writable binding"));
10242
+ validateOptions(component.options, `${componentPath}.options`, issues);
10243
+ }
10244
+ if (component.component === "Stepper")
10245
+ validateStepper(component, componentPath, issues);
10246
+ if (["Card", "Row", "Column", "List"].includes(component.component)) {
10247
+ for (const axis of ["width", "height"]) {
10248
+ const value = component[axis];
10249
+ const modes = axis === "width" ? ["fit", "fill"] : ["auto"];
10250
+ if (value !== void 0 && !(typeof value === "string" && (modes.includes(value) || /^\d+(?:\.\d+)?px$/.test(value) && Number.isFinite(parseFloat(value))))) {
10251
+ issues.push(issue2(`${componentPath}.${axis}`, "INVALID_COMPONENT_PROP_VALUE", `size must be ${modes.join(" / ")} or a non-negative px string such as 120px`));
10252
+ }
10253
+ }
10254
+ }
10255
+ if (component.checks !== void 0)
10256
+ validateChecks(component.checks, `${componentPath}.checks`, issues);
10257
+ if (component.format !== void 0 && component.component === "Text")
10258
+ validateNumberFormat(component.format, `${componentPath}.format`, issues);
10259
+ if (component.action !== void 0)
10260
+ validateAction(component.action, `${componentPath}.action`, issues, 0);
10261
+ }
10214
10262
  function validateComponents(payload, path2, surfaces, issues) {
10215
10263
  if (!Array.isArray(payload.components)) {
10216
10264
  issues.push(issue2(`${path2}.updateComponents.components`, "INVALID_A2UI_COMPONENTS", "components must be an array"));
@@ -10227,52 +10275,7 @@ function validateComponents(payload, path2, surfaces, issues) {
10227
10275
  if (surface.has(component.id))
10228
10276
  issues.push(issue2(`${componentPath}.id`, "DUPLICATE_COMPONENT_ID", `component id ${component.id} is duplicated`));
10229
10277
  surface.set(component.id, component);
10230
- const schema = A2UI_V4_COMPONENT_CATALOG.components[component.component];
10231
- if (!schema) {
10232
- issues.push(issue2(`${componentPath}.component`, "UNSUPPORTED_COMPONENT", `V4 does not support component ${component.component}`));
10233
- return;
10234
- }
10235
- const allowed = /* @__PURE__ */ new Set([
10236
- "id",
10237
- "component",
10238
- ...Object.keys(schema.properties)
10239
- ]);
10240
- for (const key of Object.keys(component))
10241
- if (!allowed.has(key))
10242
- issues.push(issue2(`${componentPath}.${key}`, "UNSUPPORTED_COMPONENT_PROP", `${component.component} does not support property ${key}`));
10243
- for (const [name, property] of Object.entries(schema.properties)) {
10244
- const value = component[name];
10245
- if (property.required && value === void 0)
10246
- issues.push(issue2(`${componentPath}.${name}`, "REQUIRED_COMPONENT_PROP_MISSING", `${component.component}.${name} is required`));
10247
- if (value !== void 0)
10248
- validateProperty(value, property, `${componentPath}.${name}`, issues, name);
10249
- }
10250
- if (component["x2-overflow"] !== void 0)
10251
- validateOverflow(component, componentPath, issues);
10252
- if (component.component === "TextField")
10253
- validateTextField(component, componentPath, issues);
10254
- if (component.component === "ChoicePicker") {
10255
- if (!isStrictBinding(component.value))
10256
- issues.push(issue2(`${componentPath}.value`, "INPUT_REQUIRES_BINDING", "ChoicePicker.value must be a strict writable binding"));
10257
- validateOptions(component.options, `${componentPath}.options`, issues);
10258
- }
10259
- if (component.component === "Stepper")
10260
- validateStepper(component, componentPath, issues);
10261
- if (["Card", "Row", "Column", "List"].includes(component.component)) {
10262
- for (const axis of ["width", "height"]) {
10263
- const value = component[axis];
10264
- const modes = axis === "width" ? ["fit", "fill"] : ["auto"];
10265
- if (value !== void 0 && !(typeof value === "string" && (modes.includes(value) || /^\d+(?:\.\d+)?px$/.test(value) && Number.isFinite(parseFloat(value))))) {
10266
- issues.push(issue2(`${componentPath}.${axis}`, "INVALID_COMPONENT_PROP_VALUE", `size must be ${modes.join(" / ")} or a non-negative px string such as 120px`));
10267
- }
10268
- }
10269
- }
10270
- if (component.checks !== void 0)
10271
- validateChecks(component.checks, `${componentPath}.checks`, issues);
10272
- if (component.format !== void 0 && component.component === "Text")
10273
- validateNumberFormat(component.format, `${componentPath}.format`, issues);
10274
- if (component.action !== void 0)
10275
- validateAction(component.action, `${componentPath}.action`, issues, 0);
10278
+ validateV4Component(component, componentPath, issues);
10276
10279
  });
10277
10280
  }
10278
10281
  function validateProperty(value, schema, path2, issues, propertyName) {
@@ -11819,7 +11822,7 @@ var FALLBACK_OBJECT_SCHEMA = {
11819
11822
  function createCardPresentationToolName(resourceId) {
11820
11823
  return stableToolName("a2ui_card", resourceId);
11821
11824
  }
11822
- async function executeCardPresentation(resource, registry, runtimeContext, args, signal) {
11825
+ async function executeCardPresentation(resource, registry, runtimeContext, args, signal, context) {
11823
11826
  const config = parseCardConfig(resource);
11824
11827
  if (config.schemaVersion !== "2") {
11825
11828
  throw new Error(`Schema v${config.schemaVersion} cards must be executed through the card data-source loop`);
@@ -11848,7 +11851,7 @@ async function executeCardPresentation(resource, registry, runtimeContext, args,
11848
11851
  inputSchema,
11849
11852
  outputSchema: isJsonObject(handle.outputSchema) ? handle.outputSchema : FALLBACK_OBJECT_SCHEMA,
11850
11853
  call: async (input, callSignal) => {
11851
- 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);
11852
11855
  return { structuredContent: readStructuredContent(result) };
11853
11856
  }
11854
11857
  };
@@ -12115,6 +12118,8 @@ function aggregateMcpServers(resources, protocolAgentId) {
12115
12118
  argsMappingRules: [],
12116
12119
  allowedTools: void 0,
12117
12120
  resourceIds: [],
12121
+ allToolResourceIds: [],
12122
+ resourceIdsByTool: /* @__PURE__ */ new Map(),
12118
12123
  description: ""
12119
12124
  };
12120
12125
  specs.set(serverName, spec);
@@ -12138,14 +12143,19 @@ function aggregateMcpServers(resources, protocolAgentId) {
12138
12143
  if (allowed && allowed.length > 0) {
12139
12144
  if (!spec.allowedTools)
12140
12145
  spec.allowedTools = /* @__PURE__ */ new Set();
12141
- for (const toolName of allowed)
12146
+ for (const toolName of allowed) {
12142
12147
  spec.allowedTools.add(toolName);
12148
+ addToolResourceId(spec.resourceIdsByTool, toolName, resource.resourceId);
12149
+ }
12150
+ } else {
12151
+ spec.allToolResourceIds.push(resource.resourceId);
12143
12152
  }
12144
12153
  continue;
12145
12154
  }
12146
12155
  if (!spec.allowedTools)
12147
12156
  spec.allowedTools = /* @__PURE__ */ new Set();
12148
12157
  spec.allowedTools.add(resource.config.toolName);
12158
+ addToolResourceId(spec.resourceIdsByTool, resource.config.toolName, resource.resourceId);
12149
12159
  for (const rule of resource.config.argsMappingRules ?? []) {
12150
12160
  const fullRule = {
12151
12161
  mcpToolName: resource.config.toolName,
@@ -12159,6 +12169,53 @@ function aggregateMcpServers(resources, protocolAgentId) {
12159
12169
  }
12160
12170
  return [...specs.values()];
12161
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
+ }
12162
12219
 
12163
12220
  // ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
12164
12221
  var MCP_PROXY_TOOL_NAME = "mcp";
@@ -12173,6 +12230,7 @@ var McpProxyTool = class {
12173
12230
  specByResourceId;
12174
12231
  specs;
12175
12232
  debugLog;
12233
+ authorizeCall;
12176
12234
  constructor(provider, specs, options = {}) {
12177
12235
  this.provider = provider;
12178
12236
  this.specs = specs;
@@ -12180,6 +12238,7 @@ var McpProxyTool = class {
12180
12238
  this.specByResourceId = new Map(specs.flatMap((spec) => spec.resourceIds.map((id) => [id, spec])));
12181
12239
  this.debugLog = options.debugLog ?? (() => {
12182
12240
  });
12241
+ this.authorizeCall = options.authorizeCall;
12183
12242
  }
12184
12243
  /**
12185
12244
  * 产单个 `mcp` 代理工具描述符,注入 `agentReq.tools`。
@@ -12192,7 +12251,7 @@ var McpProxyTool = class {
12192
12251
  label: "MCP",
12193
12252
  description: MCP_PROXY_DESCRIPTION,
12194
12253
  inputSchema: MCP_PROXY_INPUT_SCHEMA,
12195
- execute: (args, signal) => this.dispatch(args, signal)
12254
+ execute: (args, signal, context) => this.dispatch(args, signal, context)
12196
12255
  };
12197
12256
  }
12198
12257
  /** {@link IMcpToolRegistry.resolve}:按 (resourceId, toolName) 解析可调用句柄。 */
@@ -12209,7 +12268,18 @@ var McpProxyTool = class {
12209
12268
  return {
12210
12269
  inputSchema: tool.inputSchema,
12211
12270
  outputSchema: tool.outputSchema,
12212
- execute: (args, sig) => entry.server.callTool(tool.name, 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
+ }
12213
12283
  };
12214
12284
  }
12215
12285
  /** 关闭所有已连 server(忽略单 server 关闭错误)。 */
@@ -12296,7 +12366,7 @@ var McpProxyTool = class {
12296
12366
  }
12297
12367
  // —— 派发 ——
12298
12368
  /** 按入参字段派发;返回 LLM 可读文本。 */
12299
- async dispatch(args, signal) {
12369
+ async dispatch(args, signal, context) {
12300
12370
  const params = parseProxyArgs(args);
12301
12371
  if (params.connect !== void 0) {
12302
12372
  return this.executeConnect(params.connect, signal);
@@ -12311,7 +12381,7 @@ var McpProxyTool = class {
12311
12381
  return this.executeSearch(params.search, params.server);
12312
12382
  }
12313
12383
  if (params.tool !== void 0) {
12314
- return this.executeCall(params.tool, params.args, params.server, signal);
12384
+ return this.executeCall(params.tool, params.args, params.server, signal, context);
12315
12385
  }
12316
12386
  if (params.server !== void 0) {
12317
12387
  return this.executeList(params.server, signal);
@@ -12439,14 +12509,23 @@ ${formatSchema(tool.inputSchema)}`);
12439
12509
  return lines.join("\n").trim();
12440
12510
  }
12441
12511
  /** `mcp({ tool: "name", args: {...} })`:调用工具,返回序列化结果。 */
12442
- async executeCall(toolName, args, serverHint, signal) {
12512
+ async executeCall(toolName, args, serverHint, signal, context) {
12443
12513
  const found = await this.findTool(toolName, serverHint, signal);
12444
12514
  if (!found) {
12445
12515
  return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
12446
12516
  }
12447
- const { entry, tool } = found;
12517
+ const { entry, tool, spec } = found;
12448
12518
  try {
12449
- const result = await entry.server.callTool(tool.name, args, signal);
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
+ });
12450
12529
  return serializeToolResult(result);
12451
12530
  } catch (error) {
12452
12531
  const message = error instanceof Error ? error.message : String(error);
@@ -12463,7 +12542,7 @@ ${formatSchema(tool.inputSchema)}`);
12463
12542
  continue;
12464
12543
  const tool = entry.tools.find((t) => t.name === toolName);
12465
12544
  if (tool) {
12466
- return { entry, server: spec.serverName, tool };
12545
+ return { entry, server: spec.serverName, tool, spec };
12467
12546
  }
12468
12547
  }
12469
12548
  await Promise.all(specs.map((s) => this.ensureEntry(s.serverName, signal)));
@@ -12473,7 +12552,7 @@ ${formatSchema(tool.inputSchema)}`);
12473
12552
  continue;
12474
12553
  const tool = entry.tools.find((t) => t.name === toolName);
12475
12554
  if (tool) {
12476
- return { entry, server: spec.serverName, tool };
12555
+ return { entry, server: spec.serverName, tool, spec };
12477
12556
  }
12478
12557
  }
12479
12558
  return void 0;
@@ -12498,6 +12577,14 @@ ${formatSchema(tool.inputSchema)}`);
12498
12577
  return lines.join("\n").trim();
12499
12578
  }
12500
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
+ }
12501
12588
  function parseProxyArgs(args) {
12502
12589
  if (!isRecord(args))
12503
12590
  return {};
@@ -12624,7 +12711,9 @@ async function executeHomeData(input) {
12624
12711
  if (spec.allowedTools && !spec.allowedTools.has(request.binding.toolName)) {
12625
12712
  return failure("TOOL_NOT_ALLOWED", "\u5F53\u524D Agent \u672A\u5141\u8BB8\u8C03\u7528\u8BE5 MCP \u5DE5\u5177", false);
12626
12713
  }
12627
- const registry = new McpProxyTool(input.mcpServerProvider, specs);
12714
+ const registry = new McpProxyTool(input.mcpServerProvider, specs, {
12715
+ authorizeCall: createRequestMcpPhoneAuthorizer(input.protocol, input.phoneAuthorization)
12716
+ });
12628
12717
  try {
12629
12718
  const handle = await registry.resolve(spec.resourceIds[0], request.binding.toolName, input.signal);
12630
12719
  if (!handle) {
@@ -12652,6 +12741,8 @@ async function executeHomeData(input) {
12652
12741
  try {
12653
12742
  result = await handle.execute(toolInput, input.signal);
12654
12743
  } catch (error) {
12744
+ if (isMcpPhoneAuthorizationError(error))
12745
+ throw error;
12655
12746
  return failure("EXECUTION_FAILED", error instanceof Error ? error.message : "MCP \u5DE5\u5177\u8C03\u7528\u5931\u8D25", true);
12656
12747
  }
12657
12748
  const structured = readStructuredContent2(result);
@@ -12897,7 +12988,7 @@ async function executeCardActionInternal(input, diagnostics) {
12897
12988
  });
12898
12989
  diagnostics.write("binding_resolved", { output: createTrade });
12899
12990
  diagnostics.stage = "tool_resolve";
12900
- const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog);
12991
+ const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog, input.phoneAuthorization);
12901
12992
  try {
12902
12993
  diagnostics.write("tool_resolve_started", { input: createTrade });
12903
12994
  const tool = await registry.resolve(createTrade.mcpResourceId, createTrade.toolName, input.signal);
@@ -12925,6 +13016,8 @@ async function executeCardActionInternal(input, diagnostics) {
12925
13016
  diagnostics.write("tool_completed", { output: result });
12926
13017
  } catch (error) {
12927
13018
  diagnostics.error("tool_failed", error);
13019
+ if (isMcpPhoneAuthorizationError(error))
13020
+ throw error;
12928
13021
  return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
12929
13022
  }
12930
13023
  diagnostics.stage = "tool_output";
@@ -13064,9 +13157,12 @@ function materializeValue(definition, supplied) {
13064
13157
  }
13065
13158
  return definition;
13066
13159
  }
13067
- function createRegistry(protocol, provider, debugLog) {
13160
+ function createRegistry(protocol, provider, debugLog, phoneAuthorization) {
13068
13161
  const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
13069
- return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), { debugLog });
13162
+ return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), {
13163
+ debugLog,
13164
+ authorizeCall: createRequestMcpPhoneAuthorizer(protocol, phoneAuthorization)
13165
+ });
13070
13166
  }
13071
13167
  function readStructuredContent3(result) {
13072
13168
  const object3 = cloneJsonObject(result);
@@ -13099,7 +13195,9 @@ async function executeAuthorizedMcp(input) {
13099
13195
  if (!input.userId.trim())
13100
13196
  return failure3("AUTH_REQUIRED", "\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
13101
13197
  const resources = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
13102
- 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
+ });
13103
13201
  try {
13104
13202
  const tool = await registry.resolve(input.tool.mcpResourceId, input.tool.toolName, input.signal);
13105
13203
  if (!tool)
@@ -13111,7 +13209,9 @@ async function executeAuthorizedMcp(input) {
13111
13209
  let result;
13112
13210
  try {
13113
13211
  result = await tool.execute(input.tool.input, input.signal);
13114
- } catch {
13212
+ } catch (error) {
13213
+ if (isMcpPhoneAuthorizationError(error))
13214
+ throw error;
13115
13215
  return failure3("EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5", false);
13116
13216
  }
13117
13217
  const structured = readStructuredContent4(result);
@@ -13175,7 +13275,8 @@ async function executeFunctionActionMcp(input) {
13175
13275
  callId: request.callId,
13176
13276
  tool: request.tool,
13177
13277
  mcpServerProvider: input.mcpServerProvider,
13178
- signal: input.signal
13278
+ signal: input.signal,
13279
+ phoneAuthorization: input.phoneAuthorization
13179
13280
  });
13180
13281
  }
13181
13282
  function failure4(code, message, retryable) {
@@ -13277,7 +13378,7 @@ function normalizeHookResources(resources) {
13277
13378
  }).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
13278
13379
  }
13279
13380
 
13280
- // ../linkque-agent-runtime/dist/esm/core/telemetry/telemetryEnums.js
13381
+ // ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
13281
13382
  var ETelemetryAttribute;
13282
13383
  (function(ETelemetryAttribute2) {
13283
13384
  ETelemetryAttribute2["HARNESS_TELEMETRY_SCHEMA_VERSION"] = "harness.telemetry.schema.version";
@@ -13469,24 +13570,6 @@ var ETelemetrySignal;
13469
13570
  ETelemetrySignal2["LOGS"] = "logs";
13470
13571
  ETelemetrySignal2["TRACES"] = "traces";
13471
13572
  })(ETelemetrySignal || (ETelemetrySignal = {}));
13472
- var ETelemetryDiagnosticCode;
13473
- (function(ETelemetryDiagnosticCode2) {
13474
- ETelemetryDiagnosticCode2["INVALID_AUTHORIZATION"] = "invalid_authorization";
13475
- ETelemetryDiagnosticCode2["PARTITION_LIMIT"] = "partition_limit";
13476
- ETelemetryDiagnosticCode2["UNAVAILABLE_PARTITION"] = "unavailable_partition";
13477
- ETelemetryDiagnosticCode2["QUEUE_LIMIT"] = "queue_limit";
13478
- ETelemetryDiagnosticCode2["QUEUE_EXPIRED"] = "queue_expired";
13479
- ETelemetryDiagnosticCode2["SENDER_FAILED"] = "sender_failed";
13480
- ETelemetryDiagnosticCode2["PARTIAL_SUCCESS"] = "partial_success";
13481
- ETelemetryDiagnosticCode2["AUTHORIZATION_REJECTED"] = "authorization_rejected";
13482
- ETelemetryDiagnosticCode2["PERMANENT_REJECTION"] = "permanent_rejection";
13483
- ETelemetryDiagnosticCode2["SEND_RETRY"] = "send_retry";
13484
- ETelemetryDiagnosticCode2["SHUTDOWN_DROP"] = "shutdown_drop";
13485
- ETelemetryDiagnosticCode2["LOCAL_SINK_FAILED"] = "local_sink_failed";
13486
- ETelemetryDiagnosticCode2["CAPTURE_FAILED"] = "capture_failed";
13487
- ETelemetryDiagnosticCode2["IDENTITY_MISMATCH"] = "identity_mismatch";
13488
- ETelemetryDiagnosticCode2["ACTIVE_LIMIT"] = "active_limit";
13489
- })(ETelemetryDiagnosticCode || (ETelemetryDiagnosticCode = {}));
13490
13573
  var ETelemetryLossReason;
13491
13574
  (function(ETelemetryLossReason2) {
13492
13575
  ETelemetryLossReason2["UNCAUGHT_ERROR"] = "uncaught_error";
@@ -13617,21 +13700,6 @@ var ETelemetryGenAiOperation;
13617
13700
  ETelemetryGenAiOperation2["EXECUTE_TOOL"] = "execute_tool";
13618
13701
  ETelemetryGenAiOperation2["INVOKE_AGENT"] = "invoke_agent";
13619
13702
  })(ETelemetryGenAiOperation || (ETelemetryGenAiOperation = {}));
13620
- var ETelemetryAssociation;
13621
- (function(ETelemetryAssociation2) {
13622
- ETelemetryAssociation2["LOOP"] = "loop";
13623
- ETelemetryAssociation2["ITERATION"] = "iteration";
13624
- ETelemetryAssociation2["MODEL"] = "model";
13625
- ETelemetryAssociation2["TOOL"] = "tool";
13626
- ETelemetryAssociation2["PROVIDER"] = "provider";
13627
- })(ETelemetryAssociation || (ETelemetryAssociation = {}));
13628
- var ETelemetryMetadata;
13629
- (function(ETelemetryMetadata2) {
13630
- ETelemetryMetadata2["SCOPE_NAME"] = "com.alipay.linkque.runtime.telemetry";
13631
- ETelemetryMetadata2["RUNTIME_KIND"] = "node_toolkit";
13632
- ETelemetryMetadata2["SERVICE_NAMESPACE"] = "linkque";
13633
- ETelemetryMetadata2["ROUTE_CONTEXT_KEY"] = "linkque.telemetry.route";
13634
- })(ETelemetryMetadata || (ETelemetryMetadata = {}));
13635
13703
  var ETelemetryVersion;
13636
13704
  (function(ETelemetryVersion2) {
13637
13705
  ETelemetryVersion2["V0_2"] = "0.2";
@@ -14412,6 +14480,41 @@ var SideEffectRunner = class {
14412
14480
  }
14413
14481
  };
14414
14482
 
14483
+ // ../linkque-agent-runtime/dist/esm/core/telemetry/telemetryEnums.js
14484
+ var ETelemetryDiagnosticCode;
14485
+ (function(ETelemetryDiagnosticCode2) {
14486
+ ETelemetryDiagnosticCode2["INVALID_AUTHORIZATION"] = "invalid_authorization";
14487
+ ETelemetryDiagnosticCode2["PARTITION_LIMIT"] = "partition_limit";
14488
+ ETelemetryDiagnosticCode2["UNAVAILABLE_PARTITION"] = "unavailable_partition";
14489
+ ETelemetryDiagnosticCode2["QUEUE_LIMIT"] = "queue_limit";
14490
+ ETelemetryDiagnosticCode2["QUEUE_EXPIRED"] = "queue_expired";
14491
+ ETelemetryDiagnosticCode2["SENDER_FAILED"] = "sender_failed";
14492
+ ETelemetryDiagnosticCode2["PARTIAL_SUCCESS"] = "partial_success";
14493
+ ETelemetryDiagnosticCode2["AUTHORIZATION_REJECTED"] = "authorization_rejected";
14494
+ ETelemetryDiagnosticCode2["PERMANENT_REJECTION"] = "permanent_rejection";
14495
+ ETelemetryDiagnosticCode2["SEND_RETRY"] = "send_retry";
14496
+ ETelemetryDiagnosticCode2["SHUTDOWN_DROP"] = "shutdown_drop";
14497
+ ETelemetryDiagnosticCode2["LOCAL_SINK_FAILED"] = "local_sink_failed";
14498
+ ETelemetryDiagnosticCode2["CAPTURE_FAILED"] = "capture_failed";
14499
+ ETelemetryDiagnosticCode2["IDENTITY_MISMATCH"] = "identity_mismatch";
14500
+ ETelemetryDiagnosticCode2["ACTIVE_LIMIT"] = "active_limit";
14501
+ })(ETelemetryDiagnosticCode || (ETelemetryDiagnosticCode = {}));
14502
+ var ETelemetryAssociation;
14503
+ (function(ETelemetryAssociation2) {
14504
+ ETelemetryAssociation2["LOOP"] = "loop";
14505
+ ETelemetryAssociation2["ITERATION"] = "iteration";
14506
+ ETelemetryAssociation2["MODEL"] = "model";
14507
+ ETelemetryAssociation2["TOOL"] = "tool";
14508
+ ETelemetryAssociation2["PROVIDER"] = "provider";
14509
+ })(ETelemetryAssociation || (ETelemetryAssociation = {}));
14510
+ var ETelemetryMetadata;
14511
+ (function(ETelemetryMetadata2) {
14512
+ ETelemetryMetadata2["SCOPE_NAME"] = "com.alipay.linkque.runtime.telemetry";
14513
+ ETelemetryMetadata2["RUNTIME_KIND"] = "node_toolkit";
14514
+ ETelemetryMetadata2["SERVICE_NAMESPACE"] = "linkque";
14515
+ ETelemetryMetadata2["ROUTE_CONTEXT_KEY"] = "linkque.telemetry.route";
14516
+ })(ETelemetryMetadata || (ETelemetryMetadata = {}));
14517
+
14415
14518
  // ../linkque-agent-runtime/dist/esm/core/hook/hookToolWrapper.js
14416
14519
  function resolveHookToolName(tool) {
14417
14520
  return tool.modelName ?? tool.name;
@@ -14506,6 +14609,7 @@ var REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
14506
14609
  "x-api-key",
14507
14610
  "x-signature-content",
14508
14611
  "x-alipay-sdk-version",
14612
+ "x-alipay-authcode",
14509
14613
  "anthropic-api-key"
14510
14614
  ]);
14511
14615
  var REDACTED_VALUE = "ak***";
@@ -16076,7 +16180,10 @@ function createConversationCustomEvent(name, value, fields = {}) {
16076
16180
  }
16077
16181
 
16078
16182
  // ../agent-conversation-contract/dist/esm/run.js
16079
- var CONVERSATION_CLIENT_CAPABILITIES = ["location"];
16183
+ var CONVERSATION_CLIENT_CAPABILITIES = [
16184
+ "location",
16185
+ "userInfo"
16186
+ ];
16080
16187
  var ConversationProtocolValidationError = class extends Error {
16081
16188
  issues;
16082
16189
  code = "CONVERSATION_PROTOCOL_INVALID";
@@ -21446,7 +21553,7 @@ var SSEClientTransport = class {
21446
21553
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/signingFetch.js
21447
21554
  var ALIPAY_SDK_VERSION = "@alipay/open-mcp-server-2.0.4";
21448
21555
  var OAGW_ALIPAY_UID_HEADER = "x-oagw-alipay-uid";
21449
- function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog) {
21556
+ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog, getCallHeaders) {
21450
21557
  const loggedFetch = debugLog ? createHttpLoggingFetch(debugLog, "mcp-call", baseFetch) : baseFetch;
21451
21558
  return async (url2, init) => {
21452
21559
  const targetUrl = url2 instanceof URL ? url2 : new URL(typeof url2 === "string" ? url2 : url2.url);
@@ -21465,6 +21572,13 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
21465
21572
  } else {
21466
21573
  headers.delete(OAGW_ALIPAY_UID_HEADER);
21467
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
+ }
21468
21582
  const resp = await loggedFetch(url2, { ...init, headers });
21469
21583
  if (onTraceId) {
21470
21584
  try {
@@ -21493,10 +21607,10 @@ function withTimeout(fetch2, timeoutMs) {
21493
21607
  return fetch2(url2, { ...init, signal });
21494
21608
  };
21495
21609
  }
21496
- function createSseTransport(config, signer, onTraceId, debugLog) {
21610
+ function createSseTransport(config, signer, onTraceId, debugLog, getCallHeaders) {
21497
21611
  const url2 = new URL(config.sseEndpoint, config.remoteBaseUrl);
21498
21612
  const timeoutMs = config.requestTimeoutMs ?? 18e4;
21499
- const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog), timeoutMs);
21613
+ const signingFetch = withTimeout(createSigningFetch(signer, void 0, onTraceId, debugLog, getCallHeaders), timeoutMs);
21500
21614
  return new SSEClientTransport(url2, {
21501
21615
  // SSE 建连(EventSource)的 GET fetch:SDK 先包默认头再调这里。
21502
21616
  eventSourceInit: { fetch: signingFetch },
@@ -21596,6 +21710,7 @@ function applyArgsMappingRules(toolName, args, rules) {
21596
21710
  }
21597
21711
 
21598
21712
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
21713
+ import { AsyncLocalStorage } from "node:async_hooks";
21599
21714
  var defaultCreateSigner = (config, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
21600
21715
  agentId: config.agentId,
21601
21716
  signEndpoint: config.signEndpoint,
@@ -21625,8 +21740,9 @@ var RemoteGatewayMcpServerProvider = class {
21625
21740
  /** 连单个远端 server 并包装成 IMcpServer。建连失败有限重试 + 失败清理由 helper 负责。 */
21626
21741
  async connectOne(resource) {
21627
21742
  const config = await this.resolveConfig(resource);
21743
+ const callHeaders = new AsyncLocalStorage();
21628
21744
  const { client } = await connectMcpClientWithRetry(config, {
21629
- 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()),
21630
21746
  createClient: () => this.createClient()
21631
21747
  });
21632
21748
  const serverName = resource.config.serverName ?? resource.resourceId;
@@ -21661,12 +21777,9 @@ var RemoteGatewayMcpServerProvider = class {
21661
21777
  resourceId: resource.resourceId,
21662
21778
  serverName,
21663
21779
  listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
21664
- callTool: (name, args) => {
21780
+ callTool: (name, args, _signal, options) => {
21665
21781
  const mapped = applyArgsMappingRules(name, args, argsMappingRules);
21666
- return loggedClient.callTool({
21667
- name,
21668
- arguments: mapped ?? {}
21669
- });
21782
+ return callHeaders.run(options?.headers ?? {}, () => loggedClient.callTool({ name, arguments: mapped ?? {} }));
21670
21783
  },
21671
21784
  close: async () => {
21672
21785
  try {
@@ -23133,6 +23246,10 @@ export {
23133
23246
  normalizeMcpInputSchema,
23134
23247
  CardMappingError,
23135
23248
  aggregateMcpServers,
23249
+ McpPhoneAuthorizationRequiredError,
23250
+ McpPhoneAuthorizationFailedError,
23251
+ isMcpPhoneAuthorizationError,
23252
+ resolvePhoneAuthorizationDependency,
23136
23253
  McpProxyTool,
23137
23254
  executeHomeData,
23138
23255
  CardActionDiagnostics,
@@ -23170,11 +23287,11 @@ export {
23170
23287
  ETelemetryModelPurpose,
23171
23288
  ETelemetryErrorType,
23172
23289
  ETelemetryGenAiOperation,
23173
- ETelemetryAssociation,
23174
23290
  warnLogFailure,
23175
23291
  HookDispatcher,
23176
23292
  DEFAULT_HOOK_DRAIN_BUDGET_MS,
23177
23293
  SideEffectRunner,
23294
+ ETelemetryAssociation,
23178
23295
  wrapToolWithHooks,
23179
23296
  NoopHookExecutor,
23180
23297
  RUNTIME_CONFIG_DEFAULTS,