linkque-cli-v2 1.1.0 → 1.1.2

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 CHANGED
@@ -19639,6 +19639,8 @@ var LINKQUE_BASE_URL = `${LINKQUE_ENDPOINT_PROD}/api/anthropic`;
19639
19639
  var LINKQUE_BASE_URL_PRE = `${LINKQUE_ENDPOINT_PRE}/api/anthropic`;
19640
19640
  var LINKQUEGW_KNOWLEDGE_BASE_URL = LINKQUE_ENDPOINT_PROD;
19641
19641
  var LINKQUEGW_KNOWLEDGE_BASE_URL_PRE = LINKQUE_ENDPOINT_PRE;
19642
+ var LINKQUEGW_EVENT_BASE_URL = LINKQUE_ENDPOINT_PROD;
19643
+ var LINKQUEGW_EVENT_BASE_URL_PRE = LINKQUE_ENDPOINT_PRE;
19642
19644
  var LINKQUEGW_MCP_SIGN_ENDPOINT = `${LINKQUE_ENDPOINT_PROD}/api/mcp/signature`;
19643
19645
  var LINKQUEGW_MCP_SIGN_ENDPOINT_PRE = `${LINKQUE_ENDPOINT_PRE}/api/mcp/signature`;
19644
19646
  var RUN_TABLE_COLUMNS = [
@@ -20154,6 +20156,7 @@ var FUNCTION_DEFS = [
20154
20156
  key: "LINKQUEGW_KNOWLEDGE_BASE_URL",
20155
20157
  value: LINKQUEGW_KNOWLEDGE_BASE_URL
20156
20158
  },
20159
+ { key: "LINKQUEGW_EVENT_BASE_URL", value: LINKQUEGW_EVENT_BASE_URL },
20157
20160
  {
20158
20161
  key: "LINKQUEGW_MCP_SIGN_ENDPOINT",
20159
20162
  value: LINKQUEGW_MCP_SIGN_ENDPOINT
@@ -20164,6 +20167,10 @@ var FUNCTION_DEFS = [
20164
20167
  key: "LINKQUEGW_KNOWLEDGE_BASE_URL_PRE",
20165
20168
  value: LINKQUEGW_KNOWLEDGE_BASE_URL_PRE
20166
20169
  },
20170
+ {
20171
+ key: "LINKQUEGW_EVENT_BASE_URL_PRE",
20172
+ value: LINKQUEGW_EVENT_BASE_URL_PRE
20173
+ },
20167
20174
  {
20168
20175
  key: "LINKQUEGW_MCP_SIGN_ENDPOINT_PRE",
20169
20176
  value: LINKQUEGW_MCP_SIGN_ENDPOINT_PRE
@@ -25322,6 +25329,7 @@ function analyzeA2UIBindings(protocol) {
25322
25329
  }
25323
25330
  }
25324
25331
  return {
25332
+ surfaceIds: [...surfaces],
25325
25333
  surfaceId: surfaces.size === 1 ? [...surfaces][0] : void 0,
25326
25334
  occurrences,
25327
25335
  issues
@@ -27399,9 +27407,6 @@ function createA2UICardDraftStructureChecksum(draft) {
27399
27407
  function createA2UICardMcpConfigChecksum(resources) {
27400
27408
  return sha256Hex(stableJsonStringify(resources));
27401
27409
  }
27402
- function createA2UICardBindingContextChecksum(context) {
27403
- return sha256Hex(stableJsonStringify(context));
27404
- }
27405
27410
  function createA2UICardRevision(draftChecksum2, bindings) {
27406
27411
  const digest = sha256Hex(`${draftChecksum2}
27407
27412
  ${stableJsonStringify(bindings)}`);
@@ -27530,16 +27535,14 @@ async function readCardDraft(cwd, draftId) {
27530
27535
  ...theme ? { theme } : {}
27531
27536
  };
27532
27537
  }
27533
- async function validateCardBindings(cwd, draftId, contextChecksum, fieldId) {
27538
+ async function validateCardBindings(cwd, draftId, _contextChecksum, fieldId) {
27534
27539
  assertDraftId(draftId);
27535
- assertChecksum(contextChecksum, "\u7ED1\u5B9A\u4E0A\u4E0B\u6587 checksum");
27536
27540
  if (fieldId !== void 0) assertDraftId(fieldId);
27537
- return validateCardBindingsFromDisk(cwd, draftId, contextChecksum, fieldId);
27541
+ return validateCardBindingsFromDisk(cwd, draftId, fieldId);
27538
27542
  }
27539
- async function finalizeCard(cwd, draftId, expectedDraftChecksum, contextChecksum) {
27543
+ async function finalizeCard(cwd, draftId, expectedDraftChecksum, _contextChecksum) {
27540
27544
  assertDraftId(draftId);
27541
27545
  assertChecksum(expectedDraftChecksum, "\u8349\u7A3F checksum");
27542
- assertChecksum(contextChecksum, "\u7ED1\u5B9A\u4E0A\u4E0B\u6587 checksum");
27543
27546
  return withWorkspaceLock(
27544
27547
  {
27545
27548
  path: import_path22.default.join(cwd, FINALIZE_LOCK_PATH),
@@ -27549,17 +27552,12 @@ async function finalizeCard(cwd, draftId, expectedDraftChecksum, contextChecksum
27549
27552
  retryMs: FINALIZE_LOCK_RETRY_MS,
27550
27553
  timeoutMs: FINALIZE_LOCK_TIMEOUT_MS
27551
27554
  },
27552
- async () => finalizeCardWhileLocked(
27553
- cwd,
27554
- draftId,
27555
- expectedDraftChecksum,
27556
- contextChecksum
27557
- )
27555
+ async () => finalizeCardWhileLocked(cwd, draftId, expectedDraftChecksum)
27558
27556
  );
27559
27557
  }
27560
27558
  async function finalizeCardFromRequest(cwd, requestFile) {
27561
27559
  const value = await readRequiredJson(import_path22.default.resolve(cwd, requestFile));
27562
- if (!isJsonObject(value) || value.version !== 1 || typeof value.draftId !== "string" || typeof value.expectedDraftChecksum !== "string" || typeof value.contextChecksum !== "string" || Object.keys(value).some(
27560
+ if (!isJsonObject(value) || value.version !== 1 || typeof value.draftId !== "string" || typeof value.expectedDraftChecksum !== "string" || value.contextChecksum !== void 0 && typeof value.contextChecksum !== "string" || Object.keys(value).some(
27563
27561
  (key) => ![
27564
27562
  "version",
27565
27563
  "draftId",
@@ -27612,7 +27610,7 @@ async function rollbackCardFinalize(cwd, rollbackToken) {
27612
27610
  }
27613
27611
  );
27614
27612
  }
27615
- async function validateCardBindingsFromDisk(cwd, draftId, expectedContextChecksum, fieldId) {
27613
+ async function validateCardBindingsFromDisk(cwd, draftId, fieldId) {
27616
27614
  const directory = draftDirectory(cwd, draftId);
27617
27615
  const [bundle, contextValue, configValue] = await Promise.all([
27618
27616
  readBundle(directory, draftId),
@@ -27627,16 +27625,6 @@ async function validateCardBindingsFromDisk(cwd, draftId, expectedContextChecksu
27627
27625
  );
27628
27626
  }
27629
27627
  const context = contextResult.data;
27630
- const actualContextChecksum = createA2UICardBindingContextChecksum(context);
27631
- const legacyContextChecksum = createA2UICardBindingContextChecksum(
27632
- contextValue
27633
- );
27634
- if (actualContextChecksum !== expectedContextChecksum && legacyContextChecksum !== expectedContextChecksum) {
27635
- throw new LinkqueCliError(
27636
- "CARD_BINDING_CONTEXT_STALE",
27637
- "\u7ED1\u5B9A\u4E0A\u4E0B\u6587\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u53D1\u8D77 AI \u8F85\u52A9\u7ED1\u5B9A"
27638
- );
27639
- }
27640
27628
  const draftStructureChecksum = createA2UICardDraftStructureChecksum(bundle);
27641
27629
  const config2 = parseAgentConfig(configValue);
27642
27630
  const mcpResources = normalizedMcpResources(config2);
@@ -27669,7 +27657,6 @@ async function validateCardBindingsFromDisk(cwd, draftId, expectedContextChecksu
27669
27657
  return {
27670
27658
  bindingCount: bundle.manifest.bindings?.length ?? 0,
27671
27659
  complete: businessFieldIds.every((id) => boundFieldIds.has(id)),
27672
- contextChecksum: actualContextChecksum,
27673
27660
  draftChecksum: draftChecksum(bundle),
27674
27661
  draftId,
27675
27662
  draftStructureChecksum,
@@ -27677,12 +27664,8 @@ async function validateCardBindingsFromDisk(cwd, draftId, expectedContextChecksu
27677
27664
  valid: true
27678
27665
  };
27679
27666
  }
27680
- async function finalizeCardWhileLocked(cwd, draftId, expectedDraftChecksum, contextChecksum) {
27681
- const validation = await validateCardBindingsFromDisk(
27682
- cwd,
27683
- draftId,
27684
- contextChecksum
27685
- );
27667
+ async function finalizeCardWhileLocked(cwd, draftId, expectedDraftChecksum) {
27668
+ const validation = await validateCardBindingsFromDisk(cwd, draftId);
27686
27669
  if (validation.draftChecksum !== expectedDraftChecksum) {
27687
27670
  throw new LinkqueCliError(
27688
27671
  "CARD_FINALIZE_CONFLICT",
@@ -29107,7 +29090,7 @@ var cardValidateBindings = {
29107
29090
  },
29108
29091
  {
29109
29092
  flags: "--context-checksum <checksum>",
29110
- description: "binding-context.json checksum prepared by the platform",
29093
+ description: "deprecated compatibility option; accepted and ignored",
29111
29094
  key: "contextChecksum"
29112
29095
  },
29113
29096
  {
@@ -29119,9 +29102,9 @@ var cardValidateBindings = {
29119
29102
  summarize: ({ draftId }) => `Card draft ${draftId} bindings validated.
29120
29103
  `,
29121
29104
  run: (cwd, options) => {
29122
- if (options.draftId === void 0 || options.contextChecksum === void 0) {
29105
+ if (options.draftId === void 0) {
29123
29106
  throw new InvalidArgumentError(
29124
- "required options '--draft-id' and '--context-checksum' not specified"
29107
+ "required option '--draft-id' not specified"
29125
29108
  );
29126
29109
  }
29127
29110
  return validateCardBindings(
@@ -29153,7 +29136,7 @@ var cardFinalize = {
29153
29136
  },
29154
29137
  {
29155
29138
  flags: "--context-checksum <checksum>",
29156
- description: "binding-context.json checksum prepared by the platform",
29139
+ description: "deprecated compatibility option; accepted and ignored",
29157
29140
  key: "contextChecksum"
29158
29141
  }
29159
29142
  ],
@@ -29168,9 +29151,9 @@ var cardFinalize = {
29168
29151
  }
29169
29152
  return finalizeCardFromRequest(cwd, options.requestFile);
29170
29153
  }
29171
- if (options.draftId === void 0 || options.expectedDraftChecksum === void 0 || options.contextChecksum === void 0) {
29154
+ if (options.draftId === void 0 || options.expectedDraftChecksum === void 0) {
29172
29155
  throw new InvalidArgumentError(
29173
- "required options '--draft-id', '--expected-draft-checksum' and '--context-checksum' not specified"
29156
+ "required options '--draft-id' and '--expected-draft-checksum' not specified"
29174
29157
  );
29175
29158
  }
29176
29159
  return finalizeCard(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkque-cli-v2",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Public Linkque CLI bundle for sandbox debugging",
5
5
  "bin": {
6
6
  "linkquejs": "linkquejs.js"
@@ -11811,6 +11811,8 @@ function describeRuntimeEnv(env, hasRequestKey = false) {
11811
11811
  lines.push(envLine("LINKQUE_BASE_URL_PRE", maskEndpoint(env.LINKQUE_BASE_URL_PRE)));
11812
11812
  lines.push(envLine("LINKQUEGW_KNOWLEDGE_BASE_URL", maskEndpoint(env.LINKQUEGW_KNOWLEDGE_BASE_URL)));
11813
11813
  lines.push(envLine("LINKQUEGW_KNOWLEDGE_BASE_URL_PRE", maskEndpoint(env.LINKQUEGW_KNOWLEDGE_BASE_URL_PRE)));
11814
+ lines.push(envLine("LINKQUEGW_EVENT_BASE_URL", maskEndpoint(env.LINKQUEGW_EVENT_BASE_URL)));
11815
+ lines.push(envLine("LINKQUEGW_EVENT_BASE_URL_PRE", maskEndpoint(env.LINKQUEGW_EVENT_BASE_URL_PRE)));
11814
11816
  lines.push(envLine("LINKQUEGW_MCP_SIGN_ENDPOINT", maskEndpoint(env.LINKQUEGW_MCP_SIGN_ENDPOINT)));
11815
11817
  lines.push(envLine("LINKQUEGW_MCP_SIGN_ENDPOINT_PRE", maskEndpoint(env.LINKQUEGW_MCP_SIGN_ENDPOINT_PRE)));
11816
11818
  lines.push(envLine("RUN_DATABASE_ID", envValue(env, "RUN_DATABASE_ID")));
@@ -17030,6 +17030,7 @@ function analyzeA2UIBindings(protocol) {
17030
17030
  }
17031
17031
  }
17032
17032
  return {
17033
+ surfaceIds: [...surfaces],
17033
17034
  surfaceId: surfaces.size === 1 ? [...surfaces][0] : void 0,
17034
17035
  occurrences,
17035
17036
  issues
@@ -18331,25 +18332,42 @@ function isAgentPresentationToolResult(value) {
18331
18332
  }
18332
18333
  function injectResolvedViewModel(protocol, viewModel) {
18333
18334
  const analysis = analyzeA2UIBindings(protocol);
18334
- if (analysis.issues.length || !analysis.surfaceId) {
18335
- throw new Error("CARD template does not contain one valid A2UI surface");
18335
+ const declaredSurfaceIds = analysis.surfaceIds;
18336
+ const surfaceIds = Array.isArray(declaredSurfaceIds) && declaredSurfaceIds.every((surfaceId) => typeof surfaceId === "string") ? declaredSurfaceIds : collectA2UISurfaceIdsForLegacyContract(protocol);
18337
+ if (analysis.issues.length || surfaceIds.length === 0) {
18338
+ throw new Error("CARD template does not contain a valid A2UI surface");
18336
18339
  }
18337
18340
  return [
18338
18341
  ...protocol,
18339
18342
  {
18340
18343
  version: "0.9",
18341
- datas: [
18342
- {
18343
- updateDataModel: {
18344
- surfaceId: analysis.surfaceId,
18345
- path: "/",
18346
- value: viewModel
18347
- }
18348
- }
18349
- ]
18344
+ datas: surfaceIds.map((surfaceId) => ({
18345
+ updateDataModel: { surfaceId, path: "/", value: viewModel }
18346
+ }))
18350
18347
  }
18351
18348
  ];
18352
18349
  }
18350
+ function collectA2UISurfaceIdsForLegacyContract(protocol) {
18351
+ const surfaceIds = /* @__PURE__ */ new Set();
18352
+ for (const message of protocol) {
18353
+ if (!isJsonObject(message) || !Array.isArray(message.datas))
18354
+ continue;
18355
+ for (const instruction of message.datas) {
18356
+ if (!isJsonObject(instruction))
18357
+ continue;
18358
+ const operations = [
18359
+ "createSurface" in instruction ? instruction.createSurface : void 0,
18360
+ "updateComponents" in instruction ? instruction.updateComponents : void 0
18361
+ ];
18362
+ for (const operation of operations) {
18363
+ if (isJsonObject(operation) && typeof operation.surfaceId === "string") {
18364
+ surfaceIds.add(operation.surfaceId);
18365
+ }
18366
+ }
18367
+ }
18368
+ }
18369
+ return [...surfaceIds];
18370
+ }
18353
18371
  function createPresentationDescription(config) {
18354
18372
  return [
18355
18373
  config.description,
@@ -19771,6 +19789,17 @@ var REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
19771
19789
  "anthropic-api-key"
19772
19790
  ]);
19773
19791
  var REDACTED_VALUE = "ak***";
19792
+ var RESPONSE_CORRELATION_HEADER_NAMES = [
19793
+ "alipay-trace-id",
19794
+ "x-trace-id",
19795
+ "x-traceid",
19796
+ "trace-id",
19797
+ "traceid",
19798
+ "eagleeye-traceid",
19799
+ "eagleeye-trace-id",
19800
+ "sofa-traceid",
19801
+ "sofa-trace-id"
19802
+ ];
19774
19803
  function redactHeader(name, value) {
19775
19804
  return REDACTED_HEADER_NAMES.has(name.toLowerCase()) ? REDACTED_VALUE : value;
19776
19805
  }
@@ -19827,10 +19856,37 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
19827
19856
  len = cl;
19828
19857
  } catch {
19829
19858
  }
19830
- safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}`));
19859
+ const correlation = readResponseCorrelationId(resp.headers);
19860
+ const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
19861
+ safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}${correlationField}`));
19831
19862
  return resp;
19832
19863
  };
19833
19864
  }
19865
+ function readResponseCorrelationId(headers) {
19866
+ try {
19867
+ for (const name of RESPONSE_CORRELATION_HEADER_NAMES) {
19868
+ const value = headers.get(name)?.trim();
19869
+ if (value) {
19870
+ return { name, value: value.replace(/\s+/gu, " ").slice(0, 200) };
19871
+ }
19872
+ }
19873
+ let matched;
19874
+ headers.forEach((rawValue, rawName) => {
19875
+ if (matched || !/(?:^|[-_])trace[-_]?id$/iu.test(rawName))
19876
+ return;
19877
+ const value = rawValue.trim();
19878
+ if (!value)
19879
+ return;
19880
+ matched = {
19881
+ name: rawName,
19882
+ value: value.replace(/\s+/gu, " ").slice(0, 200)
19883
+ };
19884
+ });
19885
+ return matched;
19886
+ } catch {
19887
+ }
19888
+ return void 0;
19889
+ }
19834
19890
  function safeLog(debugLog, line) {
19835
19891
  try {
19836
19892
  debugLog(line, EDebugLogScope.HTTP);
@@ -19848,7 +19904,11 @@ function errorMsg(error) {
19848
19904
  // ../linkque-agent-runtime/dist/esm/core/hook/linkquegwEventHookExecutor.js
19849
19905
  var DEFAULT_LINKQUEGW_EVENT_BASE_URL = "https://linkquegw.alipay.com";
19850
19906
  var LINKQUEGW_AGENT_EVENT_TRIGGER_PATH = "/api/agent/event/trigger";
19851
- var LINKQUEGW_EVENT_TYPE_BY_STAGE = { [EHookStage.RUN_STARTED]: "AGENT_DIALOG_ROUND_STARTED" };
19907
+ var LINKQUEGW_EVENT_TYPE_BY_STAGE = {
19908
+ [EHookStage.RUN_STARTED]: "RUN_STARTED",
19909
+ [EHookStage.RUN_COMPLETED]: "RUN_ENDED",
19910
+ [EHookStage.RUN_FAILED]: "RUN_ENDED"
19911
+ };
19852
19912
  function buildLinkquegwEventBody(context) {
19853
19913
  const eventType = LINKQUEGW_EVENT_TYPE_BY_STAGE[context.stage];
19854
19914
  if (eventType === void 0)
@@ -19859,13 +19919,14 @@ function buildLinkquegwEventBody(context) {
19859
19919
  eventType,
19860
19920
  eventId: context.eventId,
19861
19921
  eventTime: context.timestamp,
19862
- conversationId: commonParams.conversationId,
19922
+ ...commonParams.conversationId !== void 0 && {
19923
+ conversationId: commonParams.conversationId
19924
+ },
19863
19925
  ...commonParams.sessionId !== void 0 && {
19864
19926
  sessionId: commonParams.sessionId
19865
19927
  },
19866
19928
  runId: commonParams.runId,
19867
- runIndex: commonParams.runIndex,
19868
- traceId: commonParams.traceId ?? commonParams.runId
19929
+ runIndex: commonParams.runIndex
19869
19930
  };
19870
19931
  }
19871
19932
  var LinkquegwEventHookExecutor = class {
@@ -19905,7 +19966,7 @@ var LinkquegwEventHookExecutor = class {
19905
19966
  const startedAt = this.now();
19906
19967
  let result = "ok";
19907
19968
  try {
19908
- const traceId = body.traceId;
19969
+ const traceId = context.commonParams.traceId ?? context.commonParams.runId;
19909
19970
  const resp = await this.fetchImpl(`${this.baseUrl}${LINKQUEGW_AGENT_EVENT_TRIGGER_PATH}`, {
19910
19971
  method: "POST",
19911
19972
  headers: {
@@ -17,7 +17,7 @@ import {
17
17
  resolveLinkqueGatewayAuth,
18
18
  resolveRunStorage,
19
19
  toAgentRunMessages
20
- } from "../../chunk-IAT272TH.js";
20
+ } from "../../chunk-B56A2RV5.js";
21
21
  import "../../chunk-MKS245OU.js";
22
22
  import "../../chunk-YDKZZ6EH.js";
23
23
  import "../../chunk-2NGJGNYB.js";
@@ -51,7 +51,7 @@ import {
51
51
  parseConversationRunRequest,
52
52
  parseSkillFile,
53
53
  streamToConversationEvents
54
- } from "../../chunk-MN4S5EF5.js";
54
+ } from "../../chunk-XGIMLCNP.js";
55
55
  import "../../chunk-XUFLSZM4.js";
56
56
  import "../../chunk-I64V3ICJ.js";
57
57
  import "../../chunk-6MHDOBWO.js";
@@ -68,23 +68,39 @@ import { randomUUID as randomUUID3 } from "node:crypto";
68
68
  // ../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js
69
69
  var LINKQUEGW_EVENT_PLUGIN_NAME = "linkquegw-event-plugin";
70
70
  var LINKQUEGW_EVENT_HOOK_RESOURCE_ID = "linkquegw-event-run-started";
71
- var createLinkquegwEventHookResource = () => ({
72
- resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
71
+ var LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID = "linkquegw-event-run-completed";
72
+ var LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID = "linkquegw-event-run-failed";
73
+ var DEFAULT_LINKQUEGW_EVENT_HOOKS = [
74
+ {
75
+ resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
76
+ stage: EHookStage.RUN_STARTED
77
+ },
78
+ {
79
+ resourceId: LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID,
80
+ stage: EHookStage.RUN_COMPLETED
81
+ },
82
+ {
83
+ resourceId: LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID,
84
+ stage: EHookStage.RUN_FAILED
85
+ }
86
+ ];
87
+ var createLinkquegwEventHookResource = (resourceId, stage) => ({
88
+ resourceId,
73
89
  resourceType: EResourceType.HOOK,
74
90
  providerType: EResourceProviderType.LINK_QUE,
75
91
  config: {
76
92
  name: "LinkqueGW \u751F\u547D\u5468\u671F\u4E8B\u4EF6\u4E0A\u62A5",
77
93
  executorName: EHookExecutorName.LinkquegwEventHookExecutor,
78
- stage: EHookStage.RUN_STARTED,
94
+ stage,
79
95
  hasSideEffects: true
80
96
  }
81
97
  });
82
98
  var isUserTokenAuthorization = (value) => /^Bearer[\t ]+[^\s,]+$/u.test(value);
83
- var isLinkquegwRunStartedHook = (resource) => {
99
+ var isLinkquegwEventHook = (resource, stage) => {
84
100
  if (resource.resourceType !== EResourceType.HOOK)
85
101
  return false;
86
102
  const hookResource = resource;
87
- return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === EHookStage.RUN_STARTED;
103
+ return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === stage;
88
104
  };
89
105
  var LinkquegwEventPlugin = class {
90
106
  name = LINKQUEGW_EVENT_PLUGIN_NAME;
@@ -113,10 +129,12 @@ var LinkquegwEventPlugin = class {
113
129
  }
114
130
  /** 自动补入 event trigger 所需 HookResource;已有同 executorName + stage 时保持原配置。 */
115
131
  modifyAgentConfig(agentConfig) {
116
- const exists = agentConfig.agent.resources.some(isLinkquegwRunStartedHook);
117
- if (exists)
118
- return;
119
- agentConfig.agent.resources.push(createLinkquegwEventHookResource());
132
+ for (const hook of DEFAULT_LINKQUEGW_EVENT_HOOKS) {
133
+ const exists = agentConfig.agent.resources.some((resource) => isLinkquegwEventHook(resource, hook.stage));
134
+ if (!exists) {
135
+ agentConfig.agent.resources.push(createLinkquegwEventHookResource(hook.resourceId, hook.stage));
136
+ }
137
+ }
120
138
  }
121
139
  };
122
140
 
@@ -298,6 +316,7 @@ function resolveLinkqueEndpoints(env, envSelector) {
298
316
  return {
299
317
  linkqueBaseUrl: trimEnvVar(isPre ? env.LINKQUE_BASE_URL_PRE : env.LINKQUE_BASE_URL),
300
318
  knowledgeBaseUrl: trimEnvVar(isPre ? env.LINKQUEGW_KNOWLEDGE_BASE_URL_PRE : env.LINKQUEGW_KNOWLEDGE_BASE_URL),
319
+ eventBaseUrl: trimEnvVar(isPre ? env.LINKQUEGW_EVENT_BASE_URL_PRE : env.LINKQUEGW_EVENT_BASE_URL),
301
320
  mcpSignEndpoint: trimEnvVar(isPre ? env.LINKQUEGW_MCP_SIGN_ENDPOINT_PRE : env.LINKQUEGW_MCP_SIGN_ENDPOINT)
302
321
  };
303
322
  }
@@ -353,10 +372,11 @@ function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
353
372
  }
354
373
  const plugins = [...ports.plugins ?? []];
355
374
  const hasLinkquegwEventPlugin = plugins.some((plugin) => plugin.name === LINKQUEGW_EVENT_PLUGIN_NAME);
375
+ const eventBaseUrl = ports.eventBaseUrl ?? ports.knowledgeBaseUrl;
356
376
  if (ports.gatewayAuthMode === "user-token" && mcpAuthHeader && !hasLinkquegwEventPlugin) {
357
377
  plugins.push(new LinkquegwEventPlugin({
358
378
  getUserTokenAuthorizationHeader: mcpAuthHeader,
359
- ...ports.knowledgeBaseUrl ? { baseUrl: ports.knowledgeBaseUrl } : {},
379
+ ...eventBaseUrl ? { baseUrl: eventBaseUrl } : {},
360
380
  ...ports.gatewayAgentId ? { agentId: ports.gatewayAgentId } : {},
361
381
  ...debugLog ? { debugLog } : {}
362
382
  }));
@@ -1745,7 +1765,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
1745
1765
  chunkSize = storage.chunkSize;
1746
1766
  }
1747
1767
  const mcpAuthorizationHeaderProvider = async () => resolved.authorizationHeader;
1748
- const { linkqueBaseUrl, knowledgeBaseUrl, mcpSignEndpoint } = resolveLinkqueEndpoints(env, envSelector);
1768
+ const { linkqueBaseUrl, knowledgeBaseUrl, eventBaseUrl, mcpSignEndpoint } = resolveLinkqueEndpoints(env, envSelector);
1749
1769
  const mcpConfigResolver = createAppbaseMcpConfigResolver({
1750
1770
  agentId: protocol.agentId,
1751
1771
  ...mcpSignEndpoint ? { signEndpoint: mcpSignEndpoint } : {}
@@ -1757,7 +1777,8 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
1757
1777
  gatewayAuthMode: resolved.mode,
1758
1778
  gatewayAgentId: protocol.agentId,
1759
1779
  ...linkqueBaseUrl ? { linkqueBaseUrl } : {},
1760
- ...knowledgeBaseUrl ? { knowledgeBaseUrl } : {}
1780
+ ...knowledgeBaseUrl ? { knowledgeBaseUrl } : {},
1781
+ ...eventBaseUrl ? { eventBaseUrl } : {}
1761
1782
  }, logCtx);
1762
1783
  return {
1763
1784
  auth: resolved.auth,
@@ -3,7 +3,7 @@ import {
3
3
  runClientCapability,
4
4
  runClientCapabilityCleanup,
5
5
  runClientCapabilityResult
6
- } from "../../chunk-IAT272TH.js";
6
+ } from "../../chunk-B56A2RV5.js";
7
7
  import "../../chunk-MKS245OU.js";
8
8
  import "../../chunk-YDKZZ6EH.js";
9
9
  import "../../chunk-2NGJGNYB.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getBakedProtocol,
3
3
  setBakedProtocol
4
- } from "../chunk-MN4S5EF5.js";
4
+ } from "../chunk-XGIMLCNP.js";
5
5
  import "../chunk-XUFLSZM4.js";
6
6
  import "../chunk-I64V3ICJ.js";
7
7
  import "../chunk-6MHDOBWO.js";
package/worker.js CHANGED
@@ -13846,6 +13846,7 @@ function analyzeA2UIBindings(protocol) {
13846
13846
  }
13847
13847
  }
13848
13848
  return {
13849
+ surfaceIds: [...surfaces],
13849
13850
  surfaceId: surfaces.size === 1 ? [...surfaces][0] : void 0,
13850
13851
  occurrences,
13851
13852
  issues
@@ -15259,25 +15260,42 @@ function isAgentPresentationToolResult(value) {
15259
15260
  }
15260
15261
  function injectResolvedViewModel(protocol, viewModel) {
15261
15262
  const analysis = analyzeA2UIBindings(protocol);
15262
- if (analysis.issues.length || !analysis.surfaceId) {
15263
- throw new Error("CARD template does not contain one valid A2UI surface");
15263
+ const declaredSurfaceIds = analysis.surfaceIds;
15264
+ const surfaceIds = Array.isArray(declaredSurfaceIds) && declaredSurfaceIds.every((surfaceId) => typeof surfaceId === "string") ? declaredSurfaceIds : collectA2UISurfaceIdsForLegacyContract(protocol);
15265
+ if (analysis.issues.length || surfaceIds.length === 0) {
15266
+ throw new Error("CARD template does not contain a valid A2UI surface");
15264
15267
  }
15265
15268
  return [
15266
15269
  ...protocol,
15267
15270
  {
15268
15271
  version: "0.9",
15269
- datas: [
15270
- {
15271
- updateDataModel: {
15272
- surfaceId: analysis.surfaceId,
15273
- path: "/",
15274
- value: viewModel
15275
- }
15276
- }
15277
- ]
15272
+ datas: surfaceIds.map((surfaceId) => ({
15273
+ updateDataModel: { surfaceId, path: "/", value: viewModel }
15274
+ }))
15278
15275
  }
15279
15276
  ];
15280
15277
  }
15278
+ function collectA2UISurfaceIdsForLegacyContract(protocol) {
15279
+ const surfaceIds = /* @__PURE__ */ new Set();
15280
+ for (const message of protocol) {
15281
+ if (!isJsonObject(message) || !Array.isArray(message.datas))
15282
+ continue;
15283
+ for (const instruction of message.datas) {
15284
+ if (!isJsonObject(instruction))
15285
+ continue;
15286
+ const operations = [
15287
+ "createSurface" in instruction ? instruction.createSurface : void 0,
15288
+ "updateComponents" in instruction ? instruction.updateComponents : void 0
15289
+ ];
15290
+ for (const operation of operations) {
15291
+ if (isJsonObject(operation) && typeof operation.surfaceId === "string") {
15292
+ surfaceIds.add(operation.surfaceId);
15293
+ }
15294
+ }
15295
+ }
15296
+ }
15297
+ return [...surfaceIds];
15298
+ }
15281
15299
  function createPresentationDescription(config2) {
15282
15300
  return [
15283
15301
  config2.description,
@@ -16862,10 +16880,37 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
16862
16880
  len = cl;
16863
16881
  } catch {
16864
16882
  }
16865
- safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}`));
16883
+ const correlation = readResponseCorrelationId(resp.headers);
16884
+ const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
16885
+ safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}${correlationField}`));
16866
16886
  return resp;
16867
16887
  };
16868
16888
  }
16889
+ function readResponseCorrelationId(headers) {
16890
+ try {
16891
+ for (const name of RESPONSE_CORRELATION_HEADER_NAMES) {
16892
+ const value = headers.get(name)?.trim();
16893
+ if (value) {
16894
+ return { name, value: value.replace(/\s+/gu, " ").slice(0, 200) };
16895
+ }
16896
+ }
16897
+ let matched;
16898
+ headers.forEach((rawValue, rawName) => {
16899
+ if (matched || !/(?:^|[-_])trace[-_]?id$/iu.test(rawName))
16900
+ return;
16901
+ const value = rawValue.trim();
16902
+ if (!value)
16903
+ return;
16904
+ matched = {
16905
+ name: rawName,
16906
+ value: value.replace(/\s+/gu, " ").slice(0, 200)
16907
+ };
16908
+ });
16909
+ return matched;
16910
+ } catch {
16911
+ }
16912
+ return void 0;
16913
+ }
16869
16914
  function safeLog(debugLog, line) {
16870
16915
  try {
16871
16916
  debugLog(line, EDebugLogScope.HTTP);
@@ -16879,7 +16924,7 @@ function errorMsg(error40) {
16879
16924
  const msg = error40 instanceof Error ? error40.message : String(error40);
16880
16925
  return msg.replace(/\s+/g, " ").slice(0, 500);
16881
16926
  }
16882
- var MAX_BODY_SUMMARY_LEN, REDACTED_HEADER_NAMES, REDACTED_VALUE;
16927
+ var MAX_BODY_SUMMARY_LEN, REDACTED_HEADER_NAMES, REDACTED_VALUE, RESPONSE_CORRELATION_HEADER_NAMES;
16883
16928
  var init_httpLoggingFetch = __esm({
16884
16929
  "../linkque-agent-runtime/dist/esm/impl/httpLoggingFetch.js"() {
16885
16930
  "use strict";
@@ -16893,6 +16938,17 @@ var init_httpLoggingFetch = __esm({
16893
16938
  "anthropic-api-key"
16894
16939
  ]);
16895
16940
  REDACTED_VALUE = "ak***";
16941
+ RESPONSE_CORRELATION_HEADER_NAMES = [
16942
+ "alipay-trace-id",
16943
+ "x-trace-id",
16944
+ "x-traceid",
16945
+ "trace-id",
16946
+ "traceid",
16947
+ "eagleeye-traceid",
16948
+ "eagleeye-trace-id",
16949
+ "sofa-traceid",
16950
+ "sofa-trace-id"
16951
+ ];
16896
16952
  }
16897
16953
  });
16898
16954
 
@@ -16907,13 +16963,14 @@ function buildLinkquegwEventBody(context2) {
16907
16963
  eventType,
16908
16964
  eventId: context2.eventId,
16909
16965
  eventTime: context2.timestamp,
16910
- conversationId: commonParams.conversationId,
16966
+ ...commonParams.conversationId !== void 0 && {
16967
+ conversationId: commonParams.conversationId
16968
+ },
16911
16969
  ...commonParams.sessionId !== void 0 && {
16912
16970
  sessionId: commonParams.sessionId
16913
16971
  },
16914
16972
  runId: commonParams.runId,
16915
- runIndex: commonParams.runIndex,
16916
- traceId: commonParams.traceId ?? commonParams.runId
16973
+ runIndex: commonParams.runIndex
16917
16974
  };
16918
16975
  }
16919
16976
  var DEFAULT_LINKQUEGW_EVENT_BASE_URL, LINKQUEGW_AGENT_EVENT_TRIGGER_PATH, LINKQUEGW_EVENT_TYPE_BY_STAGE, LinkquegwEventHookExecutor;
@@ -16925,7 +16982,11 @@ var init_linkquegwEventHookExecutor = __esm({
16925
16982
  init_hookMetrics();
16926
16983
  DEFAULT_LINKQUEGW_EVENT_BASE_URL = "https://linkquegw.alipay.com";
16927
16984
  LINKQUEGW_AGENT_EVENT_TRIGGER_PATH = "/api/agent/event/trigger";
16928
- LINKQUEGW_EVENT_TYPE_BY_STAGE = { [EHookStage.RUN_STARTED]: "AGENT_DIALOG_ROUND_STARTED" };
16985
+ LINKQUEGW_EVENT_TYPE_BY_STAGE = {
16986
+ [EHookStage.RUN_STARTED]: "RUN_STARTED",
16987
+ [EHookStage.RUN_COMPLETED]: "RUN_ENDED",
16988
+ [EHookStage.RUN_FAILED]: "RUN_ENDED"
16989
+ };
16929
16990
  LinkquegwEventHookExecutor = class {
16930
16991
  name = EHookExecutorName.LinkquegwEventHookExecutor;
16931
16992
  baseUrl;
@@ -16963,7 +17024,7 @@ var init_linkquegwEventHookExecutor = __esm({
16963
17024
  const startedAt = this.now();
16964
17025
  let result = "ok";
16965
17026
  try {
16966
- const traceId = body.traceId;
17027
+ const traceId = context2.commonParams.traceId ?? context2.commonParams.runId;
16967
17028
  const resp = await this.fetchImpl(`${this.baseUrl}${LINKQUEGW_AGENT_EVENT_TRIGGER_PATH}`, {
16968
17029
  method: "POST",
16969
17030
  headers: {
@@ -196963,7 +197024,7 @@ var init_examplePlugin = __esm({
196963
197024
  });
196964
197025
 
196965
197026
  // ../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js
196966
- var LINKQUEGW_EVENT_PLUGIN_NAME, LINKQUEGW_EVENT_HOOK_RESOURCE_ID, createLinkquegwEventHookResource, isUserTokenAuthorization, isLinkquegwRunStartedHook, LinkquegwEventPlugin;
197027
+ var LINKQUEGW_EVENT_PLUGIN_NAME, LINKQUEGW_EVENT_HOOK_RESOURCE_ID, LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID, LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID, DEFAULT_LINKQUEGW_EVENT_HOOKS, createLinkquegwEventHookResource, isUserTokenAuthorization, isLinkquegwEventHook, LinkquegwEventPlugin;
196967
197028
  var init_linkquegwEventPlugin = __esm({
196968
197029
  "../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js"() {
196969
197030
  "use strict";
@@ -196971,23 +197032,39 @@ var init_linkquegwEventPlugin = __esm({
196971
197032
  init_linkquegwEventHookExecutor();
196972
197033
  LINKQUEGW_EVENT_PLUGIN_NAME = "linkquegw-event-plugin";
196973
197034
  LINKQUEGW_EVENT_HOOK_RESOURCE_ID = "linkquegw-event-run-started";
196974
- createLinkquegwEventHookResource = () => ({
196975
- resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
197035
+ LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID = "linkquegw-event-run-completed";
197036
+ LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID = "linkquegw-event-run-failed";
197037
+ DEFAULT_LINKQUEGW_EVENT_HOOKS = [
197038
+ {
197039
+ resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
197040
+ stage: EHookStage.RUN_STARTED
197041
+ },
197042
+ {
197043
+ resourceId: LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID,
197044
+ stage: EHookStage.RUN_COMPLETED
197045
+ },
197046
+ {
197047
+ resourceId: LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID,
197048
+ stage: EHookStage.RUN_FAILED
197049
+ }
197050
+ ];
197051
+ createLinkquegwEventHookResource = (resourceId, stage) => ({
197052
+ resourceId,
196976
197053
  resourceType: EResourceType.HOOK,
196977
197054
  providerType: EResourceProviderType.LINK_QUE,
196978
197055
  config: {
196979
197056
  name: "LinkqueGW \u751F\u547D\u5468\u671F\u4E8B\u4EF6\u4E0A\u62A5",
196980
197057
  executorName: EHookExecutorName.LinkquegwEventHookExecutor,
196981
- stage: EHookStage.RUN_STARTED,
197058
+ stage,
196982
197059
  hasSideEffects: true
196983
197060
  }
196984
197061
  });
196985
197062
  isUserTokenAuthorization = (value) => /^Bearer[\t ]+[^\s,]+$/u.test(value);
196986
- isLinkquegwRunStartedHook = (resource) => {
197063
+ isLinkquegwEventHook = (resource, stage) => {
196987
197064
  if (resource.resourceType !== EResourceType.HOOK)
196988
197065
  return false;
196989
197066
  const hookResource = resource;
196990
- return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === EHookStage.RUN_STARTED;
197067
+ return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === stage;
196991
197068
  };
196992
197069
  LinkquegwEventPlugin = class {
196993
197070
  name = LINKQUEGW_EVENT_PLUGIN_NAME;
@@ -197016,10 +197093,12 @@ var init_linkquegwEventPlugin = __esm({
197016
197093
  }
197017
197094
  /** 自动补入 event trigger 所需 HookResource;已有同 executorName + stage 时保持原配置。 */
197018
197095
  modifyAgentConfig(agentConfig) {
197019
- const exists = agentConfig.agent.resources.some(isLinkquegwRunStartedHook);
197020
- if (exists)
197021
- return;
197022
- agentConfig.agent.resources.push(createLinkquegwEventHookResource());
197096
+ for (const hook of DEFAULT_LINKQUEGW_EVENT_HOOKS) {
197097
+ const exists = agentConfig.agent.resources.some((resource) => isLinkquegwEventHook(resource, hook.stage));
197098
+ if (!exists) {
197099
+ agentConfig.agent.resources.push(createLinkquegwEventHookResource(hook.resourceId, hook.stage));
197100
+ }
197101
+ }
197023
197102
  }
197024
197103
  };
197025
197104
  }
@@ -197031,6 +197110,8 @@ __export(plugin_exports, {
197031
197110
  ExamplePlugin: () => ExamplePlugin,
197032
197111
  LINKQUEGW_EVENT_HOOK_RESOURCE_ID: () => LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
197033
197112
  LINKQUEGW_EVENT_PLUGIN_NAME: () => LINKQUEGW_EVENT_PLUGIN_NAME,
197113
+ LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID: () => LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID,
197114
+ LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID: () => LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID,
197034
197115
  LinkquegwEventPlugin: () => LinkquegwEventPlugin
197035
197116
  });
197036
197117
  var init_plugin = __esm({