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.
@@ -22,15 +22,15 @@ import {
22
22
  createA2UIInfoLog,
23
23
  createAppBaseClient,
24
24
  createClientCapabilityStore,
25
- createPaymentActionStore,
26
- createPaymentInvocation,
27
25
  describeRuntimeEnv,
28
26
  isDebugLogLevel,
29
27
  jsonError,
28
+ mcpPhoneAuthorizationChallenge,
30
29
  parseStoredClientCapabilityResult,
31
30
  readAppwriteApiKey,
32
31
  readAuthenticatedUserId,
33
32
  readEnvSelector,
33
+ readMcpPhoneAuthorization,
34
34
  readTemporaryFrontendAppId,
35
35
  readTraceId,
36
36
  resolveBodyJSON,
@@ -38,13 +38,13 @@ import {
38
38
  resolveLinkqueGatewayAuth,
39
39
  resolveRunStorage,
40
40
  toAgentRunMessages
41
- } from "../../chunk-23PMJWOG.js";
41
+ } from "../../chunk-7SF3H2GM.js";
42
42
  import "../../chunk-IWOFD643.js";
43
43
  import "../../chunk-PXCGFBV5.js";
44
44
  import "../../chunk-ETG6PNHQ.js";
45
45
  import {
46
46
  getBakedProtocol
47
- } from "../../chunk-VSZ3UDC7.js";
47
+ } from "../../chunk-NHRW2KQW.js";
48
48
  import {
49
49
  CANCEL_CONVERSATION_RUN_OPERATION,
50
50
  CONVERSATION_HISTORY_VERSION,
@@ -126,6 +126,7 @@ import {
126
126
  formatHttpLogLine,
127
127
  isAgentPresentationToolResult,
128
128
  isJsonValue,
129
+ isMcpPhoneAuthorizationError,
129
130
  isSafeJsonPointer,
130
131
  normalizeFollowUpQuestionStrings,
131
132
  normalizeHookResources,
@@ -144,6 +145,7 @@ import {
144
145
  readJsonPointer,
145
146
  readStructuredContent,
146
147
  redactHeaders,
148
+ resolvePhoneAuthorizationDependency,
147
149
  resolveWebSearchResource,
148
150
  stableToolName,
149
151
  startRuntimeObservation,
@@ -151,7 +153,7 @@ import {
151
153
  summarizeBody,
152
154
  warnLogFailure,
153
155
  wrapToolWithHooks
154
- } from "../../chunk-YSRA6KFZ.js";
156
+ } from "../../chunk-RHFHCJYP.js";
155
157
  import "../../chunk-XUFLSZM4.js";
156
158
  import "../../chunk-GAYNLDWK.js";
157
159
  import "../../chunk-HM7KNEG3.js";
@@ -7933,7 +7935,7 @@ var require_ignore = __commonJS({
7933
7935
  });
7934
7936
 
7935
7937
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js
7936
- import { randomUUID as randomUUID6 } from "node:crypto";
7938
+ import { randomUUID as randomUUID7 } from "node:crypto";
7937
7939
 
7938
7940
  // ../linkque-agent-runtime/dist/esm/core/telemetry/toolObservation.js
7939
7941
  import { randomUUID } from "node:crypto";
@@ -41230,7 +41232,7 @@ var CardRenderMcpServer = class {
41230
41232
  description: createPresentationDescription(config),
41231
41233
  inputSchema: config.presentationInputSchema,
41232
41234
  // execute 委托 callTool,返回 IAgentPresentationToolResult(execute 返回 unknown 兼容)。
41233
- execute: (args, signal) => this.callTool(name, args, signal)
41235
+ execute: (args, signal, context) => this.callTool(name, args, signal, { context })
41234
41236
  });
41235
41237
  continue;
41236
41238
  }
@@ -41287,7 +41289,7 @@ var CardRenderMcpServer = class {
41287
41289
  description: `\u9009\u62E9 ${name} \u540E\u4F7F\u7528\u3002${source.purpose}\u3002\u6839\u636E\u5BF9\u8BDD\u548C\u5DF2\u6709\u6570\u636E\u6E90\u7ED3\u679C\u786E\u5B9A\u6240\u6709 MCP \u53C2\u6570\u3002${CARD_SEQUENCE}`,
41288
41290
  inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
41289
41291
  outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
41290
- execute: async (args, signal) => {
41292
+ execute: async (args, signal, context) => {
41291
41293
  if (!state2.selected || this.activeCardId !== resource.resourceId)
41292
41294
  throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
41293
41295
  const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
@@ -41297,7 +41299,7 @@ var CardRenderMcpServer = class {
41297
41299
  if (!handle)
41298
41300
  throw new Error(`MCP \u5DE5\u5177 ${source.mcpResourceId}/${source.toolName} \u5F53\u524D\u4E0D\u53EF\u7528`);
41299
41301
  const mcpStartedAt = Date.now();
41300
- const result = await handle.execute(args, signal);
41302
+ const result = await handle.execute(args, signal, context);
41301
41303
  signal?.throwIfAborted();
41302
41304
  if (this.closed)
41303
41305
  throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
@@ -41405,22 +41407,22 @@ ${AFTER_CARD_DESCRIPTION}`,
41405
41407
  this.toolByName = new Map(tools.map((tool) => [tool.name, tool]));
41406
41408
  return tools;
41407
41409
  }
41408
- async callTool(name, args, signal) {
41410
+ async callTool(name, args, signal, options) {
41409
41411
  const resource = this.resources.find((r) => createCardPresentationToolName(r.resourceId) === name);
41410
41412
  if (!resource) {
41411
41413
  const descriptor = this.toolByName.get(name);
41412
41414
  if (!descriptor)
41413
41415
  throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
41414
- return descriptor.execute(args, signal);
41416
+ return descriptor.execute(args, signal, options?.context);
41415
41417
  }
41416
41418
  const config = parseCardConfig(resource);
41417
41419
  if (config.schemaVersion === "3" || config.schemaVersion === "4") {
41418
41420
  const descriptor = this.toolByName.get(name);
41419
41421
  if (!descriptor)
41420
41422
  throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
41421
- return descriptor.execute(args, signal);
41423
+ return descriptor.execute(args, signal, options?.context);
41422
41424
  }
41423
- return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal);
41425
+ return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
41424
41426
  }
41425
41427
  async close() {
41426
41428
  this.closed = true;
@@ -42038,7 +42040,8 @@ var AgentRuntime = class _AgentRuntime {
42038
42040
  debugLog?.("[mcp] no mcp servers configured (no MCP tools will be available)", EDebugLogScope.MCP);
42039
42041
  }
42040
42042
  const mcpProxy = new McpProxyTool(this.mcpServerProvider, mcpServerSpecs, {
42041
- debugLog
42043
+ debugLog,
42044
+ ...options.mcpCallAuthorizer ? { authorizeCall: options.mcpCallAuthorizer } : {}
42042
42045
  });
42043
42046
  cleanup.push(() => mcpProxy.closeAll());
42044
42047
  const cardServer = new CardRenderMcpServer(this.cardResources, mcpProxy, { ...options.runtimeContext, threadId: request.threadId }, debugLog);
@@ -42346,17 +42349,72 @@ function parseArgs(args, imageId) {
42346
42349
  imageError("IMAGE_INPUT_INVALID");
42347
42350
  return { imageId, query, mode: args.mode };
42348
42351
  }
42352
+ function outputError(reason) {
42353
+ imageError(`IMAGE_OUTPUT_INVALID_${reason}`);
42354
+ }
42349
42355
  function parseObservation(value, imageId, mode) {
42350
- if (!record(value) || !keys(value, ["version", "imageId", "mode", "truncated", "observation"]) || value.version !== "tool-v1" || value.imageId !== imageId || value.mode !== mode || typeof value.truncated !== "boolean" || !record(value.observation))
42351
- imageError("IMAGE_OUTPUT_INVALID");
42356
+ if (!record(value) || !keys(value, ["version", "imageId", "mode", "truncated", "observation"]))
42357
+ outputError("ROOT_FIELDS");
42358
+ if (value.version !== "tool-v1")
42359
+ outputError("VERSION");
42360
+ if (value.imageId !== imageId)
42361
+ outputError("IMAGE_ID");
42362
+ if (value.mode !== mode)
42363
+ outputError("MODE");
42364
+ if (typeof value.truncated !== "boolean")
42365
+ outputError("TRUNCATED");
42352
42366
  const obs = value.observation;
42367
+ if (!record(obs) || !keys(obs, ["summary", "ocrText", "facts", "uncertainties"]))
42368
+ outputError("OBSERVATION_FIELDS");
42353
42369
  const list = (v, count, chars) => Array.isArray(v) && v.length <= count && v.every((s) => text(s, 1, chars));
42354
- if (!keys(obs, ["summary", "ocrText", "facts", "uncertainties"]) || !text(obs.summary, 1, 400) || !text(obs.ocrText, 0, 800) || !list(obs.facts, 8, 120) || !list(obs.uncertainties, 6, 160))
42355
- imageError("IMAGE_OUTPUT_INVALID");
42356
- if ([obs.summary, obs.ocrText, ...obs.facts, ...obs.uncertainties].reduce((n, s) => n + Array.from(s).length, 0) > 1200 || obs.uncertainties.filter((s) => s === MARKER).length !== (value.truncated ? 1 : 0))
42357
- imageError("IMAGE_OUTPUT_INVALID");
42370
+ if (!text(obs.summary, 1, 400))
42371
+ outputError("SUMMARY");
42372
+ if (!text(obs.ocrText, 0, 800))
42373
+ outputError("OCR_TEXT");
42374
+ if (!list(obs.facts, 8, 120))
42375
+ outputError("FACTS");
42376
+ if (!list(obs.uncertainties, 6, 160))
42377
+ outputError("UNCERTAINTIES");
42378
+ if ([obs.summary, obs.ocrText, ...obs.facts, ...obs.uncertainties].reduce((n, s) => n + Array.from(s).length, 0) > 1200)
42379
+ outputError("OBSERVATION_BUDGET");
42380
+ if (obs.uncertainties.filter((s) => s === MARKER).length !== (value.truncated ? 1 : 0))
42381
+ outputError("TRUNCATION_MARKER");
42358
42382
  return { ok: true, ...value };
42359
42383
  }
42384
+ function parseImageEnvelope(envelope, imageId, mode) {
42385
+ if (!record(envelope) || typeof envelope.id !== "string" || !envelope.id || envelope.type !== "message" || envelope.role !== "assistant" || envelope.model !== "linkque-image-understanding")
42386
+ outputError("ENVELOPE");
42387
+ if (envelope.stop_reason !== "end_turn")
42388
+ outputError("STOP_REASON");
42389
+ const usage = envelope.usage;
42390
+ if (!record(usage) || !["input_tokens", "output_tokens"].every((k) => Number.isSafeInteger(usage[k]) && Number(usage[k]) >= 0))
42391
+ outputError("USAGE");
42392
+ if (!Array.isArray(envelope.content) || !envelope.content.length)
42393
+ outputError("TEXT_EMPTY");
42394
+ const parts = [];
42395
+ for (const block of envelope.content) {
42396
+ if (!record(block))
42397
+ outputError("BLOCK_TYPE");
42398
+ if (block.type === "thinking" || block.type === "redacted_thinking")
42399
+ continue;
42400
+ if (block.type !== "text")
42401
+ outputError("BLOCK_TYPE");
42402
+ if (typeof block.text !== "string")
42403
+ outputError("TEXT_TYPE");
42404
+ parts.push(block.text);
42405
+ }
42406
+ const visible = parts.join("").trim();
42407
+ if (!visible)
42408
+ outputError("TEXT_EMPTY");
42409
+ const fence = /^```(?:json)?[ \t]*\r?\n([\s\S]*?)\r?\n```$/i.exec(visible);
42410
+ let value;
42411
+ try {
42412
+ value = JSON.parse(fence ? fence[1] : visible);
42413
+ } catch {
42414
+ outputError("TEXT_JSON");
42415
+ }
42416
+ return parseObservation(value, imageId, mode);
42417
+ }
42360
42418
 
42361
42419
  // ../linkque-agent-runtime/dist/esm/impl/plugin/imageUnderstanding/tool.js
42362
42420
  async function waitForObservation(promise, signal) {
@@ -42464,19 +42522,11 @@ function createImageTool(image, input, options, rules) {
42464
42522
  }
42465
42523
  let envelope;
42466
42524
  try {
42467
- envelope = JSON.parse(Buffer.from(await boundedBody(response, 128 * 1024)).toString("utf8"));
42468
- } catch {
42469
- imageError("IMAGE_OUTPUT_INVALID");
42470
- }
42471
- if (!record(envelope) || typeof envelope.id !== "string" || !envelope.id || envelope.type !== "message" || envelope.role !== "assistant" || envelope.model !== "linkque-image-understanding" || envelope.stop_reason !== "end_turn" || !record(envelope.usage) || !["input_tokens", "output_tokens"].every((k) => Number.isSafeInteger(envelope.usage && envelope.usage[k]) && Number(envelope.usage[k]) >= 0) || !Array.isArray(envelope.content) || !envelope.content.length || !envelope.content.every((block) => record(block) && block.type === "text" && typeof block.text === "string"))
42472
- imageError("IMAGE_OUTPUT_INVALID");
42473
- let value;
42474
- try {
42475
- value = JSON.parse(envelope.content.map((block) => block.text).join(""));
42525
+ envelope = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(await boundedBody(response, 128 * 1024)));
42476
42526
  } catch {
42477
- imageError("IMAGE_OUTPUT_INVALID");
42527
+ imageError("IMAGE_OUTPUT_INVALID_ENVELOPE_JSON");
42478
42528
  }
42479
- return parseObservation(value, image.id, parsed.mode);
42529
+ return parseImageEnvelope(envelope, image.id, parsed.mode);
42480
42530
  } catch (error) {
42481
42531
  if (signal.aborted)
42482
42532
  imageError("IMAGE_CANCELLED");
@@ -44559,7 +44609,7 @@ function readStatusError(status, code, message) {
44559
44609
 
44560
44610
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/homeData.js
44561
44611
  var HOME_DATA_REQUEST_OPERATION = "homeData.request";
44562
- async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx, traceId) {
44612
+ async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx, traceId, phoneAuthorization) {
44563
44613
  if (method.toUpperCase() !== "POST") {
44564
44614
  return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
44565
44615
  }
@@ -44599,7 +44649,8 @@ async function runHomeData(method, body, userId, deps = {}, env = process.env, e
44599
44649
  request: body,
44600
44650
  protocol,
44601
44651
  userId,
44602
- mcpServerProvider: provider
44652
+ mcpServerProvider: provider,
44653
+ phoneAuthorization
44603
44654
  });
44604
44655
  debugLog?.("response", response.ok ? { ok: true } : { ok: false, errorCode: response.error.code });
44605
44656
  return { status: 200, body: response };
@@ -44695,7 +44746,7 @@ function sanitizeDiagnosticText(value) {
44695
44746
 
44696
44747
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/a2uiAction.js
44697
44748
  var A2UI_ACTION_EXECUTE_OPERATION = "a2uiAction.execute";
44698
- async function runA2UIAction(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth, logCtx, traceId) {
44749
+ async function runA2UIAction(method, body, userId, deps = {}, env = process.env, _appwriteApiKey, envSelector = "PROD", gatewayAuth, logCtx, traceId, phoneAuthorization) {
44699
44750
  let mcpTraceId;
44700
44751
  const debugLog = createA2UIInfoLog(env, logCtx, traceId, () => mcpTraceId);
44701
44752
  const diagnostics = new CardActionDiagnostics(debugLog, {}, "handler");
@@ -44725,10 +44776,6 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
44725
44776
  if (request.agentId !== protocol.agentId) {
44726
44777
  return paymentFailure(403, "AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
44727
44778
  }
44728
- const store = deps.paymentActionStore ?? resolveStore(env, appwriteApiKey);
44729
- if (!store) {
44730
- return paymentFailure(503, "EXECUTION_FAILED", "\u652F\u4ED8\u52A8\u4F5C\u5B58\u50A8\u672A\u914D\u7F6E", true);
44731
- }
44732
44779
  const provider = deps.mcpServerProvider ?? resolveProvider(protocol, env, envSelector, gatewayAuth, diagnostics.debugLog, (info) => {
44733
44780
  mcpTraceId = info.traceId;
44734
44781
  diagnostics.write("mcp_trace");
@@ -44736,34 +44783,9 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
44736
44783
  if (!provider) {
44737
44784
  return paymentFailure(503, "MCP_NOT_BOUND", "\u652F\u4ED8 MCP \u8FDE\u63A5\u672A\u914D\u7F6E", true);
44738
44785
  }
44739
- diagnostics.stage = "store_begin";
44740
- const invocation = createPaymentInvocation(userId, request);
44741
- diagnostics.context.invocationId = invocation.invocationId;
44742
- diagnostics.write("store_started");
44743
- const begin = await store.begin(invocation);
44744
- diagnostics.context.invocationId = begin.invocation.invocationId;
44745
- if (begin.kind === "existing") {
44746
- const current = begin.invocation;
44747
- diagnostics.write("idempotency_hit", { status: current.status });
44748
- if (current.tradeNO && current.status === "trade-created") {
44749
- return {
44750
- status: 200,
44751
- body: success(current.invocationId, current.tradeNO)
44752
- };
44753
- }
44754
- if (current.status === "executing") {
44755
- return paymentFailure(409, "ACTION_IN_PROGRESS", "\u652F\u4ED8\u52A8\u4F5C\u6B63\u5728\u5904\u7406\u4E2D", true);
44756
- }
44757
- if (current.status === "uncertain") {
44758
- return paymentFailure(409, "EXECUTION_UNCERTAIN", "\u521B\u5EFA\u4EA4\u6613\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u91CD\u590D\u652F\u4ED8", false);
44759
- }
44760
- return paymentFailure(409, "EXECUTION_FAILED", "\u652F\u4ED8\u52A8\u4F5C\u5DF2\u5931\u8D25\uFF0C\u8BF7\u5237\u65B0\u5361\u7247\u540E\u91CD\u8BD5", false);
44761
- }
44762
- diagnostics.write("store_created", { status: begin.invocation.status });
44763
- const invocationId = begin.invocation.invocationId;
44764
44786
  diagnostics.stage = "execute";
44765
44787
  const response = await executeCardAction({
44766
- request: { ...request, invocationId },
44788
+ request,
44767
44789
  protocol,
44768
44790
  runtimeContext: {
44769
44791
  agentId: protocol.agentId,
@@ -44771,23 +44793,11 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
44771
44793
  userId
44772
44794
  },
44773
44795
  mcpServerProvider: provider,
44774
- debugLog
44796
+ debugLog,
44797
+ phoneAuthorization
44775
44798
  });
44776
- diagnostics.stage = "store_update";
44777
- if (response.ok) {
44778
- await store.update(invocationId, {
44779
- status: "trade-created",
44780
- tradeNO: response.result.tradeNO
44781
- });
44782
- diagnostics.write("store_updated", { status: "trade-created" });
44799
+ if (response.ok)
44783
44800
  return { status: 200, body: response };
44784
- }
44785
- await store.update(invocationId, {
44786
- status: response.error.code === "EXECUTION_FAILED" ? "uncertain" : "failed-before-execute"
44787
- });
44788
- diagnostics.write("store_updated", {
44789
- status: response.error.code === "EXECUTION_FAILED" ? "uncertain" : "failed-before-execute"
44790
- });
44791
44801
  return {
44792
44802
  status: response.error.code === "EXECUTION_FAILED" ? 502 : 400,
44793
44803
  body: response
@@ -44806,11 +44816,6 @@ async function runA2UIAction(method, body, userId, deps = {}, env = process.env,
44806
44816
  throw error;
44807
44817
  }
44808
44818
  }
44809
- function resolveStore(env, appwriteApiKey) {
44810
- const config = new AppbaseRuntimeConfigProvider(env);
44811
- const handle = createAppBaseClient(env, void 0, appwriteApiKey);
44812
- return createPaymentActionStore(handle.databases, config.get("A2UI_ACTION_DATABASE_ID"), config.get("A2UI_ACTION_TABLE_ID"));
44813
- }
44814
44819
  function resolveProvider(protocol, env, envSelector, gatewayAuth, debugLog, onTraceId) {
44815
44820
  let auth;
44816
44821
  try {
@@ -44830,9 +44835,6 @@ function resolveProvider(protocol, env, envSelector, gatewayAuth, debugLog, onTr
44830
44835
  ...debugLog ? { onTraceId } : {}
44831
44836
  });
44832
44837
  }
44833
- function success(invocationId, tradeNO) {
44834
- return { ok: true, invocationId, result: { kind: "payment", tradeNO } };
44835
- }
44836
44838
  function paymentFailure(status, code, message, retryable) {
44837
44839
  return { status, body: { ok: false, error: { code, message, retryable } } };
44838
44840
  }
@@ -44969,7 +44971,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
44969
44971
  let sessionLease = deps?.sessionLease;
44970
44972
  let historyStore = deps?.historyStore;
44971
44973
  let clientCapabilityStore = deps?.clientCapabilityStore;
44972
- let paymentActionStore = deps?.paymentActionStore;
44973
44974
  let chunkSize = Number(APPBASE_RUNTIME_CONFIG_DEFAULTS.RUN_CHUNK_SIZE);
44974
44975
  if (!store) {
44975
44976
  let storage;
@@ -44989,7 +44990,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
44989
44990
  store = createAppBaseStore(handle.databases, storage.databaseId, storage.tableId, historyOwnerId);
44990
44991
  const config = new AppbaseRuntimeConfigProvider(env);
44991
44992
  clientCapabilityStore ??= createClientCapabilityStore(handle.databases, config.get("CLIENT_CAPABILITY_DATABASE_ID"), config.get("CLIENT_CAPABILITY_TABLE_ID"));
44992
- paymentActionStore ??= createPaymentActionStore(handle.databases, config.get("A2UI_ACTION_DATABASE_ID"), config.get("A2UI_ACTION_TABLE_ID"));
44993
44993
  try {
44994
44994
  historyStore ??= createConversationHistoryStore(handle.databases, resolveConversationHistoryStorage(env), historyOwnerId);
44995
44995
  } catch (err2) {
@@ -45013,13 +45013,15 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
45013
45013
  remoteBaseUrl: openMcpBaseUrl,
45014
45014
  ...mcpSignEndpoint ? { signEndpoint: mcpSignEndpoint } : {}
45015
45015
  });
45016
- const mcpServerProvider = deps?.mcpServerProvider ?? createAppbaseMcpProvider({
45016
+ const rawMcpServerProvider = deps?.mcpServerProvider ?? createAppbaseMcpProvider({
45017
45017
  resolveConfig: mcpConfigResolver,
45018
45018
  getAuthorizationHeader: mcpAuthorizationHeaderProvider
45019
45019
  });
45020
+ const mcpServerProvider = rawMcpServerProvider;
45020
45021
  const securityAnswerPlugin = deps?.securityAnswerPlugin ?? createSecurityAnswerPlugin(historyStore, logCtx?.log);
45021
45022
  const runtime = deps?.runtime ?? createAppBaseRuntime(protocol, env, {
45022
45023
  ...appwriteApiKey ? { appBaseApiKey: appwriteApiKey } : {},
45024
+ mcpServerProvider,
45023
45025
  mcpConfigResolver,
45024
45026
  mcpAuthorizationHeaderProvider,
45025
45027
  ...resolved.mode === "user-token" ? {
@@ -45044,7 +45046,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
45044
45046
  sessionLease,
45045
45047
  historyStore,
45046
45048
  clientCapabilityStore,
45047
- paymentActionStore,
45048
45049
  securityAnswerPlugin,
45049
45050
  mcpServerProvider,
45050
45051
  chunkSize
@@ -45114,8 +45115,8 @@ async function* debugLogAgentStream(stream, debugLog) {
45114
45115
 
45115
45116
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/clientCapabilityTool.js
45116
45117
  import { randomUUID as randomUUID5 } from "node:crypto";
45117
- var WAIT_TIMEOUT_MS = 2e4;
45118
45118
  var POLL_INTERVAL_MS = 500;
45119
+ var LOCATION_WAIT_MS = 2e4;
45119
45120
  var ROW_TTL_MS = 3 * 6e4;
45120
45121
  var LOCATION_INPUT = Object.freeze({
45121
45122
  type: 0,
@@ -45124,17 +45125,15 @@ var LOCATION_INPUT = Object.freeze({
45124
45125
  });
45125
45126
  function createClientCapabilityTool(input) {
45126
45127
  const resource = input.protocol.agent.resources.find((candidate) => candidate.resourceType === EResourceType.CLIENT_CAPABILITY);
45127
- if (!resource || !input.ownerId || !input.store || !resource.config.allowedCapabilities.includes("location") || !input.request.clientCapabilities?.includes("location"))
45128
+ if (!resource?.config.allowedCapabilities.includes("location") || !input.request.clientCapabilities?.includes("location") || !input.ownerId || !input.store)
45128
45129
  return void 0;
45129
- const ownerId = input.ownerId;
45130
- const store = input.store;
45131
45130
  let pending = false;
45132
45131
  return {
45133
45132
  name: "client_capability",
45134
45133
  modelName: "client_capability",
45135
45134
  resourceId: resource.resourceId,
45136
- label: "\u83B7\u53D6\u7528\u6237\u5F53\u524D\u4F4D\u7F6E",
45137
- description: "\u5F53\u56DE\u7B54\u786E\u5B9E\u9700\u8981\u7528\u6237\u5F53\u524D\u5730\u7406\u4F4D\u7F6E\u65F6\u8C03\u7528\u3002\u80FD\u529B\u7531\u7528\u6237\u5F53\u524D\u8BBE\u5907\u6267\u884C\uFF0C\u5931\u8D25\u65F6\u8BF7\u7EE7\u7EED\u7ED9\u51FA\u53EF\u884C\u8BF4\u660E\u3002",
45135
+ label: "\u83B7\u53D6\u7528\u6237\u8BBE\u5907\u4FE1\u606F",
45136
+ description: "\u9700\u8981\u7528\u6237\u5F53\u524D\u4F4D\u7F6E\u65F6\u8C03\u7528\u3002",
45138
45137
  inputSchema: {
45139
45138
  type: "object",
45140
45139
  additionalProperties: false,
@@ -45144,24 +45143,33 @@ function createClientCapabilityTool(input) {
45144
45143
  reason: { type: "string", minLength: 1, maxLength: 200 }
45145
45144
  }
45146
45145
  },
45147
- execute: async (args, signal, context) => {
45146
+ async execute(args, signal, context) {
45148
45147
  if (!context)
45149
45148
  return failure("CLIENT_CAPABILITY_CONTEXT_MISSING", "\u7AEF\u4FA7\u8C03\u7528\u4E0A\u4E0B\u6587\u4E0D\u53EF\u7528");
45149
+ const reason = readReason(args);
45150
+ if (!reason)
45151
+ return failure("CLIENT_CAPABILITY_INVALID_ARGS", "\u7AEF\u4FA7\u80FD\u529B\u53C2\u6570\u4E0D\u5408\u6CD5");
45150
45152
  if (pending)
45151
- return failure("CLIENT_CAPABILITY_BUSY", "\u5F53\u524D\u5DF2\u6709\u4E00\u4E2A\u7AEF\u4FA7\u80FD\u529B\u8C03\u7528\u6B63\u5728\u7B49\u5F85");
45152
- const parsed = readArgs(args);
45153
- if (!parsed)
45154
- return failure("CLIENT_CAPABILITY_INVALID_ARGS", "\u7AEF\u4FA7\u5B9A\u4F4D\u53C2\u6570\u4E0D\u5408\u6CD5");
45153
+ return failure("CLIENT_CAPABILITY_BUSY", "\u5DF2\u6709\u5B9A\u4F4D\u8C03\u7528\u6B63\u5728\u7B49\u5F85");
45155
45154
  pending = true;
45156
45155
  const invocationId = randomUUID5();
45157
45156
  const now = Date.now();
45158
- const acceptUntil = new Date(now + WAIT_TIMEOUT_MS).toISOString();
45159
- const expiresAt = new Date(now + ROW_TTL_MS).toISOString();
45157
+ const acceptUntil = new Date(now + LOCATION_WAIT_MS).toISOString();
45158
+ const event = {
45159
+ version: "1.0",
45160
+ invocationId,
45161
+ runId: input.request.runId,
45162
+ toolCallId: context.toolCallId,
45163
+ capability: "location",
45164
+ reason,
45165
+ input: LOCATION_INPUT,
45166
+ expiresAt: acceptUntil
45167
+ };
45160
45168
  let created = false;
45161
45169
  try {
45162
- await store.create({
45170
+ await input.store.create({
45163
45171
  invocationId,
45164
- ownerId,
45172
+ ownerId: input.ownerId,
45165
45173
  agentId: input.protocol.agentId,
45166
45174
  threadId: input.request.threadId,
45167
45175
  runId: input.request.runId,
@@ -45171,79 +45179,162 @@ function createClientCapabilityTool(input) {
45171
45179
  input: JSON.stringify(LOCATION_INPUT),
45172
45180
  createdAt: new Date(now).toISOString(),
45173
45181
  acceptUntil,
45174
- expiresAt
45182
+ expiresAt: new Date(now + ROW_TTL_MS).toISOString()
45175
45183
  });
45176
45184
  created = true;
45177
- context.emit({
45178
- type: "client_capability_request",
45179
- value: {
45180
- version: "1.0",
45181
- invocationId,
45182
- runId: input.request.runId,
45183
- toolCallId: context.toolCallId,
45184
- capability: "location",
45185
- reason: parsed.reason,
45186
- input: LOCATION_INPUT,
45187
- expiresAt: acceptUntil
45188
- }
45189
- });
45185
+ context.emit({ type: "client_capability_request", value: event });
45190
45186
  while (Date.now() < Date.parse(acceptUntil)) {
45191
45187
  if (signal?.aborted)
45192
45188
  throw abortError();
45193
- const row = await store.get(invocationId);
45189
+ const row = await input.store.get(invocationId);
45194
45190
  if (row?.status === "succeeded" || row?.status === "failed") {
45195
45191
  const result = parseStoredClientCapabilityResult(row.result);
45196
- if (!result)
45197
- return failure("CLIENT_CAPABILITY_INVALID_RESULT", "\u7AEF\u4FA7\u8FD4\u56DE\u5185\u5BB9\u65E0\u6CD5\u89E3\u6790");
45198
- await store.consume(invocationId);
45199
- return result;
45192
+ await input.store.consume(invocationId);
45193
+ return result ?? failure("CLIENT_CAPABILITY_INVALID_RESULT", "\u7AEF\u4FA7\u8FD4\u56DE\u5185\u5BB9\u65E0\u6CD5\u89E3\u6790");
45200
45194
  }
45201
45195
  await wait(POLL_INTERVAL_MS, signal);
45202
45196
  }
45203
- await store.expire(invocationId);
45204
- return failure("CLIENT_CAPABILITY_TIMEOUT", "\u7B49\u5F85\u7AEF\u4FA7\u5B9A\u4F4D\u7ED3\u679C\u8D85\u65F6", true);
45205
- } catch (error) {
45206
- if (created && signal?.aborted)
45207
- await store.expire(invocationId);
45208
- throw error;
45197
+ await input.store.expire(invocationId);
45198
+ return failure("CLIENT_CAPABILITY_TIMEOUT", "\u7B49\u5F85\u7AEF\u4FA7\u80FD\u529B\u7ED3\u679C\u8D85\u65F6", true);
45209
45199
  } finally {
45200
+ if (created && signal?.aborted)
45201
+ await input.store.expire(invocationId);
45210
45202
  pending = false;
45211
45203
  }
45212
45204
  }
45213
45205
  };
45214
45206
  }
45215
- function readArgs(value) {
45207
+ function readReason(value) {
45216
45208
  if (!value || typeof value !== "object" || Array.isArray(value))
45217
45209
  return void 0;
45218
45210
  const args = value;
45219
45211
  if (args.capability !== "location" || typeof args.reason !== "string")
45220
45212
  return void 0;
45221
45213
  const reason = args.reason.trim();
45222
- return reason && reason.length <= 200 ? { reason } : void 0;
45214
+ return reason && reason.length <= 200 ? reason : void 0;
45223
45215
  }
45224
45216
  function failure(code, message, retriable = false) {
45225
45217
  return { ok: false, error: { code, message, retriable } };
45226
45218
  }
45219
+ function abortError() {
45220
+ return Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
45221
+ }
45227
45222
  function wait(ms, signal) {
45228
45223
  return new Promise((resolve, reject) => {
45229
- if (signal?.aborted)
45230
- return reject(abortError());
45231
- const onAbort = () => {
45224
+ const timer = setTimeout(resolve, ms);
45225
+ signal?.addEventListener("abort", () => {
45232
45226
  clearTimeout(timer);
45233
45227
  reject(abortError());
45228
+ }, { once: true });
45229
+ });
45230
+ }
45231
+
45232
+ // ../linkque-agent-appwrite-integrate/dist/esm/runtime/mcpPhoneAuthorization.js
45233
+ import { randomUUID as randomUUID6 } from "node:crypto";
45234
+ var POLL_INTERVAL_MS2 = 500;
45235
+ var AUTH_WAIT_MS = 95e3;
45236
+ var ROW_TTL_MS2 = 3 * 6e4;
45237
+ var AUTH_CODE_HEADER = "x-alipay-authcode";
45238
+ function createMcpPhoneAuthorizer(input) {
45239
+ const hasDependencies = input.protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP_TOOL).some((resource) => resource.config.dependencies?.some((dependency) => dependency.name === "phoneAuthorization"));
45240
+ if (!hasDependencies)
45241
+ return void 0;
45242
+ return async ({ resourceIds, toolName, signal, context }) => {
45243
+ const policy = resolvePhoneAuthorizationDependency(input.protocol, resourceIds, toolName);
45244
+ if (!policy)
45245
+ return void 0;
45246
+ if (signal?.aborted)
45247
+ throw abortError2();
45248
+ if (!input.ownerId || !input.store || !context || !input.request.clientCapabilities?.includes("userInfo")) {
45249
+ if (policy.required)
45250
+ throw authError("AUTH_UNAVAILABLE", "\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743");
45251
+ return void 0;
45252
+ }
45253
+ const invocationId = randomUUID6();
45254
+ const now = Date.now();
45255
+ const acceptUntil = new Date(now + AUTH_WAIT_MS).toISOString();
45256
+ const capabilityInput = { scopes: ["auth_user"] };
45257
+ const event = {
45258
+ version: "1.0",
45259
+ invocationId,
45260
+ runId: input.request.runId,
45261
+ toolCallId: context.toolCallId,
45262
+ capability: "userInfo",
45263
+ reason: `\u8C03\u7528 ${toolName} \u9700\u8981\u83B7\u53D6\u624B\u673A\u53F7\u6388\u6743`,
45264
+ input: capabilityInput,
45265
+ expiresAt: acceptUntil
45234
45266
  };
45235
- const timer = setTimeout(() => {
45267
+ let created = false;
45268
+ try {
45269
+ await input.store.create({
45270
+ invocationId,
45271
+ ownerId: input.ownerId,
45272
+ agentId: input.protocol.agentId,
45273
+ threadId: input.request.threadId,
45274
+ runId: input.request.runId,
45275
+ toolCallId: context.toolCallId,
45276
+ capability: "userInfo",
45277
+ status: "pending",
45278
+ input: JSON.stringify(capabilityInput),
45279
+ createdAt: new Date(now).toISOString(),
45280
+ acceptUntil,
45281
+ expiresAt: new Date(now + ROW_TTL_MS2).toISOString()
45282
+ });
45283
+ created = true;
45284
+ context.emit({ type: "client_capability_request", value: event });
45285
+ while (Date.now() < Date.parse(acceptUntil)) {
45286
+ if (signal?.aborted)
45287
+ throw abortError2();
45288
+ const row = await input.store.get(invocationId);
45289
+ if (row?.status === "succeeded" || row?.status === "failed") {
45290
+ const result = parseStoredClientCapabilityResult(row.result);
45291
+ await input.store.consume(invocationId);
45292
+ if (result?.ok && "authCode" in result.data) {
45293
+ return { [AUTH_CODE_HEADER]: result.data.authCode };
45294
+ }
45295
+ if (policy.required) {
45296
+ throw authError(result && !result.ok ? result.error.code : "AUTH_INVALID_RESULT", result && !result.ok ? result.error.message : "\u6388\u6743\u7ED3\u679C\u65E0\u6548");
45297
+ }
45298
+ return void 0;
45299
+ }
45300
+ await wait2(POLL_INTERVAL_MS2, signal);
45301
+ }
45302
+ await input.store.expire(invocationId);
45303
+ if (policy.required)
45304
+ throw authError("AUTH_TIMEOUT", "\u7B49\u5F85\u624B\u673A\u53F7\u6388\u6743\u8D85\u65F6");
45305
+ return void 0;
45306
+ } catch (error) {
45307
+ if (created)
45308
+ await input.store.expire(invocationId).catch(() => void 0);
45309
+ if (signal?.aborted || error instanceof Error && error.name === "AbortError")
45310
+ throw error;
45311
+ if (policy.required) {
45312
+ if (error instanceof Error && "code" in error)
45313
+ throw error;
45314
+ throw authError("AUTH_FAILED", "\u624B\u673A\u53F7\u6388\u6743\u8BF7\u6C42\u5931\u8D25");
45315
+ }
45316
+ return void 0;
45317
+ }
45318
+ };
45319
+ }
45320
+ function authError(code, message) {
45321
+ return Object.assign(new Error(message), { code });
45322
+ }
45323
+ function abortError2() {
45324
+ return Object.assign(new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88"), { name: "AbortError" });
45325
+ }
45326
+ function wait2(ms, signal) {
45327
+ return new Promise((resolve, reject) => {
45328
+ const finish = (settle) => {
45329
+ clearTimeout(timer);
45236
45330
  signal?.removeEventListener("abort", onAbort);
45237
- resolve();
45238
- }, ms);
45331
+ settle();
45332
+ };
45333
+ const onAbort = () => finish(() => reject(abortError2()));
45334
+ const timer = setTimeout(() => finish(resolve), ms);
45239
45335
  signal?.addEventListener("abort", onAbort, { once: true });
45240
45336
  });
45241
45337
  }
45242
- function abortError() {
45243
- const error = new Error("client capability call aborted");
45244
- error.name = "AbortError";
45245
- return error;
45246
- }
45247
45338
 
45248
45339
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chatExecution.js
45249
45340
  async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId, signal, traceId) {
@@ -45293,6 +45384,14 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
45293
45384
  });
45294
45385
  if (clientCapabilityTool)
45295
45386
  runOptions.additionalTools = [clientCapabilityTool];
45387
+ const mcpCallAuthorizer = createMcpPhoneAuthorizer({
45388
+ protocol: deps.protocol,
45389
+ request,
45390
+ ownerId: authenticatedUserId,
45391
+ store: deps.clientCapabilityStore
45392
+ });
45393
+ if (mcpCallAuthorizer)
45394
+ runOptions.mcpCallAuthorizer = mcpCallAuthorizer;
45296
45395
  if (signal)
45297
45396
  runOptions.signal = signal;
45298
45397
  const agentReq = {
@@ -45351,6 +45450,7 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
45351
45450
  log("chunk \u5DF2 finalize, status=", status, "\u603B chunk \u6570=", sink.totalChunks);
45352
45451
  } catch (err2) {
45353
45452
  logError("finalize \u5931\u8D25:", err2);
45453
+ } finally {
45354
45454
  }
45355
45455
  }
45356
45456
  return {
@@ -45374,7 +45474,7 @@ function shouldFlushConversationEvent(event) {
45374
45474
 
45375
45475
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/a2uiFunctionMcp.js
45376
45476
  var A2UI_FUNCTION_MCP_EXECUTE_OPERATION = "a2uiFunctionMcp.execute";
45377
- async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth) {
45477
+ async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process.env, appwriteApiKey, envSelector = "PROD", gatewayAuth, phoneAuthorization) {
45378
45478
  if (method.toUpperCase() !== "POST") {
45379
45479
  return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
45380
45480
  }
@@ -45406,9 +45506,12 @@ async function runA2UIFunctionMcp(method, body, userId, deps = {}, env = process
45406
45506
  request,
45407
45507
  protocol,
45408
45508
  runtimeContext: { threadId: request.threadId, userId },
45409
- mcpServerProvider: provider
45509
+ mcpServerProvider: provider,
45510
+ phoneAuthorization
45410
45511
  });
45411
- } catch {
45512
+ } catch (error) {
45513
+ if (isMcpPhoneAuthorizationError(error))
45514
+ throw error;
45412
45515
  return failure2(502, "EXECUTION_UNCERTAIN", "MCP \u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8BF7\u52FF\u81EA\u52A8\u91CD\u8BD5");
45413
45516
  }
45414
45517
  return {
@@ -45461,7 +45564,7 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
45461
45564
  const cfg = resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth, temporaryFrontendAppId);
45462
45565
  if ("status" in cfg)
45463
45566
  return cfg;
45464
- const leaseOwnerId = randomUUID6();
45567
+ const leaseOwnerId = randomUUID7();
45465
45568
  let leaseAcquired = false;
45466
45569
  let leaseReleased = false;
45467
45570
  if (cfg.sessionLease && !isPresentationRun) {
@@ -45697,7 +45800,7 @@ function waitForCancellationPoll(delayMs, signal) {
45697
45800
  }
45698
45801
  });
45699
45802
  }
45700
- async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId) {
45803
+ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, mcpPhoneAuthorization) {
45701
45804
  const operation = readOperation(bodyJSON);
45702
45805
  const startedAt = Date.now();
45703
45806
  const logGateway = (event, fields = {}, failed = false) => {
@@ -45729,6 +45832,9 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
45729
45832
  }, result.status >= 400);
45730
45833
  return result;
45731
45834
  } catch (error) {
45835
+ const challenge = mcpPhoneAuthorizationChallenge(error);
45836
+ if (challenge)
45837
+ return challenge;
45732
45838
  logGateway("dispatch.error", {
45733
45839
  errorType: error instanceof Error ? error.name : typeof error,
45734
45840
  durationMs: Date.now() - startedAt
@@ -45757,22 +45863,21 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
45757
45863
  return observe(() => runHomeData(method, request, historyOwnerId, {
45758
45864
  ...deps?.protocol ? { protocol: deps.protocol } : {},
45759
45865
  ...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
45760
- }, env, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId));
45866
+ }, env, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId, mcpPhoneAuthorization));
45761
45867
  }
45762
45868
  if (operation === A2UI_ACTION_EXECUTE_OPERATION) {
45763
45869
  const request = readOperationPayload(bodyJSON);
45764
45870
  return observe(() => runA2UIAction(method, request, historyOwnerId, {
45765
45871
  ...deps?.protocol ? { protocol: deps.protocol } : {},
45766
- ...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {},
45767
- ...deps?.paymentActionStore ? { paymentActionStore: deps.paymentActionStore } : {}
45768
- }, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId));
45872
+ ...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
45873
+ }, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, logCtx, traceId, mcpPhoneAuthorization));
45769
45874
  }
45770
45875
  if (operation === A2UI_FUNCTION_MCP_EXECUTE_OPERATION) {
45771
45876
  const request = readOperationPayload(bodyJSON);
45772
45877
  return observe(() => runA2UIFunctionMcp(method, request, historyOwnerId, {
45773
45878
  ...deps?.protocol ? { protocol: deps.protocol } : {},
45774
45879
  ...deps?.mcpServerProvider ? { mcpServerProvider: deps.mcpServerProvider } : {}
45775
- }, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth));
45880
+ }, env, appwriteApiKey, envSelector === "PRE" ? "PRE" : "PROD", gatewayAuth, mcpPhoneAuthorization));
45776
45881
  }
45777
45882
  if (operation && HISTORY_OPERATIONS.has(operation)) {
45778
45883
  return observe(() => runHistory(method, bodyJSON, env, deps ? { protocol: deps.protocol, store: deps.historyStore } : void 0, logCtx, historyOwnerId, appwriteApiKey));
@@ -45802,7 +45907,7 @@ async function chat(ctx) {
45802
45907
  log: ctx.log,
45803
45908
  error: ctx.error
45804
45909
  }) : void 0;
45805
- result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
45910
+ result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, readMcpPhoneAuthorization(ctx.req.headers)) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
45806
45911
  } catch (err2) {
45807
45912
  ctx.error?.(err2);
45808
45913
  result = err2 instanceof LinkqueGatewayAuthError || err2 instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(err2.status, err2.code, err2.message) : {