linkque-cli-v2 1.3.0 → 1.3.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.
@@ -8846,6 +8846,7 @@ var EHookStage;
8846
8846
  EHookStage2["RUN_FAILED"] = "RUN_FAILED";
8847
8847
  EHookStage2["RUN_READ"] = "RUN_READ";
8848
8848
  EHookStage2["AFTER_MODEL_CALL"] = "AFTER_MODEL_CALL";
8849
+ EHookStage2["MODEL_RESPONSE_RECEIVED"] = "MODEL_RESPONSE_RECEIVED";
8849
8850
  EHookStage2["BEFORE_TOOL_CALL"] = "BEFORE_TOOL_CALL";
8850
8851
  EHookStage2["AFTER_TOOL_CALL"] = "AFTER_TOOL_CALL";
8851
8852
  EHookStage2["TOOL_CALL_FAILED"] = "TOOL_CALL_FAILED";
@@ -8993,6 +8994,8 @@ var ALLOWED_AST_TYPES = /* @__PURE__ */ new Set([
8993
8994
  "Field",
8994
8995
  "Function",
8995
8996
  "Identity",
8997
+ "Index",
8998
+ "IndexExpression",
8996
8999
  "KeyValuePair",
8997
9000
  "Literal",
8998
9001
  "MultiSelectHash",
@@ -9064,6 +9067,9 @@ function validateAst(ast) {
9064
9067
  if (!ALLOWED_AST_TYPES.has(value.type)) {
9065
9068
  throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_NODE_FORBIDDEN", `JMESPath node ${value.type} is not allowed`);
9066
9069
  }
9070
+ if (value.type === "Index" && (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 0)) {
9071
+ throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_INVALID", "array index must be a non-negative safe integer");
9072
+ }
9067
9073
  if (value.type === "Function" && value.name !== "not_null") {
9068
9074
  throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_FUNCTION_FORBIDDEN", `JMESPath function ${String(value.name)} is not allowed`);
9069
9075
  }
@@ -9851,6 +9857,8 @@ var ALLOWED_AST_TYPES2 = /* @__PURE__ */ new Set([
9851
9857
  "Field",
9852
9858
  "Function",
9853
9859
  "Identity",
9860
+ "Index",
9861
+ "IndexExpression",
9854
9862
  "KeyValuePair",
9855
9863
  "Literal",
9856
9864
  "MultiSelectHash",
@@ -9943,6 +9951,9 @@ function validateAst2(ast) {
9943
9951
  if (!ALLOWED_AST_TYPES2.has(value.type)) {
9944
9952
  throw new A2UICardExpressionError("CARD_EXPRESSION_NODE_FORBIDDEN", `JMESPath node ${value.type} is not allowed by ${A2UI_CARD_TRANSFORM_PROFILE}`);
9945
9953
  }
9954
+ if (value.type === "Index" && (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 0)) {
9955
+ throw new A2UICardExpressionError("CARD_EXPRESSION_INVALID", "array index must be a non-negative safe integer");
9956
+ }
9946
9957
  if (value.type === "Function" && value.name !== "not_null") {
9947
9958
  throw new A2UICardExpressionError("CARD_EXPRESSION_FUNCTION_FORBIDDEN", `JMESPath function ${String(value.name)} is not allowed`);
9948
9959
  }
@@ -9961,7 +9972,6 @@ var colors = [
9961
9972
  "default",
9962
9973
  "muted",
9963
9974
  "primary",
9964
- "accent",
9965
9975
  "success",
9966
9976
  "warning",
9967
9977
  "error",
@@ -10013,8 +10023,18 @@ var iconNames = [
10013
10023
  "warning",
10014
10024
  "arrow-right-long"
10015
10025
  ];
10016
- var box = {
10017
- margin: { kind: "string", values: spacing },
10026
+ var layoutItem = {
10027
+ grow: {
10028
+ kind: "number",
10029
+ values: [0, 1, 2, 3, 4],
10030
+ parentComponents: ["Row", "Column"]
10031
+ }
10032
+ };
10033
+ var width = { width: { kind: "string", values: ["fit", "fill"] } };
10034
+ var radius = {
10035
+ radius: { kind: "string", values: ["none", "xs", "sm", "md", "full"] }
10036
+ };
10037
+ var decoration = {
10018
10038
  padding: { kind: "string", values: spacing },
10019
10039
  background: {
10020
10040
  kind: "string",
@@ -10032,29 +10052,17 @@ var box = {
10032
10052
  kind: "string",
10033
10053
  values: ["none", "subtle", "card-border", "primary"]
10034
10054
  },
10035
- radius: { kind: "string", values: ["none", "xs", "sm", "md", "full"] },
10036
- width: { kind: "string", values: ["fit", "fill"] },
10037
- grow: { kind: "number", values: [0, 1, 2, 3, 4] },
10038
- shrink: { kind: "boolean" }
10055
+ ...radius
10039
10056
  };
10040
10057
  var typography = {
10041
10058
  color: { kind: "string", values: colors },
10042
- fontSize: {
10043
- kind: "string",
10044
- values: [
10045
- "small",
10046
- "medium",
10047
- "large",
10048
- "striking",
10049
- "display",
10050
- "badge",
10051
- "merchant"
10052
- ]
10053
- },
10059
+ fontSize: { kind: "string", values: ["xs", "sm", "md", "lg", "xl", "xxl"] },
10054
10060
  fontWeight: { kind: "string", values: ["normal", "semibold", "bold"] }
10055
10061
  };
10056
10062
  var container = {
10057
- ...box,
10063
+ ...layoutItem,
10064
+ ...width,
10065
+ padding: { kind: "string", values: spacing },
10058
10066
  children: { kind: "children", required: true },
10059
10067
  gap: { kind: "string", values: spacing },
10060
10068
  align: {
@@ -10074,6 +10082,7 @@ var container = {
10074
10082
  },
10075
10083
  "x2-overflow": { kind: "format" }
10076
10084
  };
10085
+ var { justify: _listJustify, ...listContainer } = container;
10077
10086
  var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10078
10087
  catalogId: LINKQUE_A2UI_V4_CATALOG_ID,
10079
10088
  protocolVersion: "0.9",
@@ -10081,7 +10090,10 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10081
10090
  Card: {
10082
10091
  interaction: "action",
10083
10092
  properties: {
10084
- ...container,
10093
+ ...layoutItem,
10094
+ ...width,
10095
+ ...decoration,
10096
+ child: { kind: "child", required: true },
10085
10097
  action: { kind: "action" },
10086
10098
  disabled: { kind: "boolean" }
10087
10099
  }
@@ -10091,13 +10103,14 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10091
10103
  interaction: "none",
10092
10104
  properties: {
10093
10105
  ...container,
10094
- wrap: { kind: "string", values: ["wrap", "nowrap"] }
10106
+ wrap: { kind: "string", values: ["wrap", "nowrap"] },
10107
+ layout: { kind: "string", values: ["flex", "inline"] }
10095
10108
  }
10096
10109
  },
10097
10110
  List: {
10098
10111
  interaction: "none",
10099
10112
  properties: {
10100
- ...container,
10113
+ ...listContainer,
10101
10114
  variant: {
10102
10115
  kind: "string",
10103
10116
  required: true,
@@ -10108,8 +10121,9 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10108
10121
  Text: {
10109
10122
  interaction: "none",
10110
10123
  properties: {
10111
- ...box,
10124
+ ...layoutItem,
10112
10125
  ...typography,
10126
+ shrink: { kind: "boolean" },
10113
10127
  text: { kind: "binding", required: true },
10114
10128
  maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] },
10115
10129
  decoration: { kind: "string", values: ["line-through"] },
@@ -10119,19 +10133,31 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10119
10133
  Tag: {
10120
10134
  interaction: "none",
10121
10135
  properties: {
10122
- ...box,
10123
- ...typography,
10136
+ ...layoutItem,
10124
10137
  text: { kind: "binding", required: true },
10125
10138
  icon: { kind: "string", values: iconNames },
10126
- gap: { kind: "string", values: spacing },
10127
- maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] },
10128
- format: { kind: "format" }
10139
+ tone: {
10140
+ kind: "string",
10141
+ values: [
10142
+ "default",
10143
+ "muted",
10144
+ "primary",
10145
+ "success",
10146
+ "warning",
10147
+ "error"
10148
+ ]
10149
+ },
10150
+ variant: { kind: "string", values: ["soft", "outline", "plain"] },
10151
+ size: { kind: "string", values: ["sm", "md"] },
10152
+ shrink: { kind: "boolean" },
10153
+ maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] }
10129
10154
  }
10130
10155
  },
10131
10156
  Button: {
10132
10157
  interaction: "action",
10133
10158
  properties: {
10134
- ...box,
10159
+ ...layoutItem,
10160
+ ...width,
10135
10161
  label: { kind: "binding", required: true },
10136
10162
  action: { kind: "action", required: true },
10137
10163
  checks: { kind: "format" },
@@ -10149,34 +10175,29 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10149
10175
  Image: {
10150
10176
  interaction: "none",
10151
10177
  properties: {
10152
- ...box,
10178
+ ...layoutItem,
10179
+ ...radius,
10153
10180
  src: { kind: "binding", required: true },
10154
10181
  alt: { kind: "binding" },
10155
10182
  fit: {
10156
10183
  kind: "string",
10157
10184
  values: ["contain", "cover", "fill", "none", "scale-down"]
10158
10185
  },
10159
- variant: {
10186
+ aspectRatio: {
10160
10187
  kind: "string",
10161
- values: [
10162
- "icon",
10163
- "avatar",
10164
- "merchantLogo",
10165
- "smallFeature",
10166
- "mediumFeature",
10167
- "portraitFeature",
10168
- "productThumbnail",
10169
- "voucherThumbnail",
10170
- "largeFeature",
10171
- "header"
10172
- ]
10188
+ values: ["square", "portrait", "landscape", "wide", "banner"]
10189
+ },
10190
+ height: { kind: "string", values: ["auto", "fill"] },
10191
+ size: {
10192
+ kind: "string",
10193
+ values: ["xs", "sm", "md", "lg", "xl", "full"]
10173
10194
  }
10174
10195
  }
10175
10196
  },
10176
10197
  Icon: {
10177
10198
  interaction: "none",
10178
10199
  properties: {
10179
- ...box,
10200
+ ...layoutItem,
10180
10201
  name: { kind: "string", required: true, values: iconNames },
10181
10202
  label: { kind: "string" },
10182
10203
  color: { kind: "string", values: colors },
@@ -10189,15 +10210,15 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10189
10210
  Divider: {
10190
10211
  interaction: "none",
10191
10212
  properties: {
10192
- ...box,
10213
+ ...layoutItem,
10193
10214
  axis: { kind: "string", values: ["horizontal", "vertical"] }
10194
10215
  }
10195
10216
  },
10196
10217
  TextField: {
10197
10218
  interaction: "input",
10198
10219
  properties: {
10199
- ...box,
10200
- ...typography,
10220
+ ...layoutItem,
10221
+ ...width,
10201
10222
  label: { kind: "string", required: true },
10202
10223
  value: { kind: "binding", required: true },
10203
10224
  checks: { kind: "format" },
@@ -10221,7 +10242,8 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10221
10242
  ChoicePicker: {
10222
10243
  interaction: "input",
10223
10244
  properties: {
10224
- ...box,
10245
+ ...layoutItem,
10246
+ ...width,
10225
10247
  label: { kind: "string", required: true },
10226
10248
  value: { kind: "binding", required: true },
10227
10249
  options: { kind: "options", required: true },
@@ -10236,7 +10258,8 @@ var A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10236
10258
  Stepper: {
10237
10259
  interaction: "input",
10238
10260
  properties: {
10239
- ...box,
10261
+ ...layoutItem,
10262
+ ...width,
10240
10263
  label: { kind: "string", required: true },
10241
10264
  value: { kind: "binding", required: true },
10242
10265
  min: { kind: "number" },
@@ -10352,8 +10375,6 @@ function validateComponents(payload, path2, surfaces, issues) {
10352
10375
  if (value !== void 0)
10353
10376
  validateProperty(value, property, `${componentPath}.${name}`, issues, name);
10354
10377
  }
10355
- if (component.component === "Tag" && component.icon === void 0 && component.gap !== void 0)
10356
- issues.push(issue2(`${componentPath}.gap`, "TAG_GAP_REQUIRES_ICON", "Tag.gap requires Tag.icon"));
10357
10378
  if (component["x2-overflow"] !== void 0)
10358
10379
  validateOverflow(component, componentPath, issues);
10359
10380
  if (component.component === "TextField")
@@ -10367,7 +10388,7 @@ function validateComponents(payload, path2, surfaces, issues) {
10367
10388
  validateStepper(component, componentPath, issues);
10368
10389
  if (component.checks !== void 0)
10369
10390
  validateChecks(component.checks, `${componentPath}.checks`, issues);
10370
- if (component.format !== void 0 && (component.component === "Text" || component.component === "Tag"))
10391
+ if (component.format !== void 0 && component.component === "Text")
10371
10392
  validateNumberFormat(component.format, `${componentPath}.format`, issues);
10372
10393
  if (component.action !== void 0)
10373
10394
  validateAction(component.action, `${componentPath}.action`, issues, 0);
@@ -10381,6 +10402,11 @@ function validateProperty(value, schema, path2, issues, propertyName) {
10381
10402
  issues.push(issue2(path2, "INVALID_DISPLAY_VALUE", `display value must be ${stringOnly ? "a string" : "a string or finite number"}, or a compatible display binding`));
10382
10403
  return;
10383
10404
  }
10405
+ if (schema.kind === "child") {
10406
+ if (!isSafeIdentifier(value))
10407
+ issues.push(issue2(path2, "INVALID_CHILD", "child must be a safe component id"));
10408
+ return;
10409
+ }
10384
10410
  if (schema.kind === "children") {
10385
10411
  const valid = Array.isArray(value) ? value.every(isSafeIdentifier) : isPlainRecord(value) && Object.keys(value).length === 2 && isSafeIdentifier(value.componentId) && typeof value.path === "string" && isSafePath(value.path);
10386
10412
  if (!valid)
@@ -10621,20 +10647,27 @@ function validateReferences(surfaces, path2, issues) {
10621
10647
  issues.push(issue2(`${path2}.surfaces.${surfaceId}`, "MISSING_ROOT_COMPONENT", "surface must define root"));
10622
10648
  const edges = /* @__PURE__ */ new Map();
10623
10649
  for (const [id, component] of components) {
10624
- const children = component.children;
10625
- const refs = Array.isArray(children) ? children.filter((entry) => typeof entry === "string") : isPlainRecord(children) && typeof children.componentId === "string" ? [children.componentId] : [];
10650
+ const refs = getComponentReferences(component);
10626
10651
  edges.set(id, refs);
10627
10652
  refs.forEach((ref) => {
10628
10653
  if (!components.has(ref))
10629
- issues.push(issue2(`${path2}.surfaces.${surfaceId}.components.${id}.children`, "MISSING_COMPONENT_REFERENCE", `component ${ref} does not exist`));
10654
+ issues.push(issue2(`${path2}.surfaces.${surfaceId}.components.${id}.${component.child !== void 0 ? "child" : "children"}`, "MISSING_COMPONENT_REFERENCE", `component ${ref} does not exist`));
10630
10655
  });
10631
10656
  if ((component.component === "Button" || component.component === "Card" && component.action !== void 0) && refs.some((ref) => hasInteractiveDescendant(ref, components, /* @__PURE__ */ new Set())))
10632
- issues.push(issue2(`${path2}.surfaces.${surfaceId}.components.${id}.children`, "NESTED_INTERACTION", "action components cannot contain interactive descendants"));
10657
+ issues.push(issue2(`${path2}.surfaces.${surfaceId}.components.${id}.${component.child !== void 0 ? "child" : "children"}`, "NESTED_INTERACTION", "action components cannot contain interactive descendants"));
10633
10658
  collectSurfaceOpenReferences(component.action).forEach((targetSurfaceId) => {
10634
10659
  if (!surfaces.has(targetSurfaceId))
10635
10660
  issues.push(issue2(`${path2}.surfaces.${surfaceId}.components.${id}.action`, "MISSING_SURFACE_REFERENCE", `surface ${targetSurfaceId} does not exist`));
10636
10661
  });
10637
10662
  }
10663
+ components.forEach((component, id) => {
10664
+ if (component.grow === void 0)
10665
+ return;
10666
+ const parents = [...components.values()].filter((parent) => getComponentReferences(parent).includes(id));
10667
+ if (id === "root" || parents.length === 0 || parents.some((parent) => parent.component !== "Row" && parent.component !== "Column")) {
10668
+ issues.push(issue2(`${path2}.surfaces.${surfaceId}.components.${id}.grow`, "INVALID_LAYOUT_PARENT", "grow requires a direct Row or Column parent in every occurrence"));
10669
+ }
10670
+ });
10638
10671
  const visiting = /* @__PURE__ */ new Set();
10639
10672
  const visited = /* @__PURE__ */ new Set();
10640
10673
  const walk = (id) => {
@@ -10665,6 +10698,14 @@ function collectSurfaceOpenReferences(value, result = /* @__PURE__ */ new Set())
10665
10698
  }
10666
10699
  return result;
10667
10700
  }
10701
+ function getComponentReferences(component) {
10702
+ if (typeof component.child === "string")
10703
+ return [component.child];
10704
+ const children = component.children;
10705
+ if (Array.isArray(children))
10706
+ return children.filter((entry) => typeof entry === "string");
10707
+ return isPlainRecord(children) && typeof children.componentId === "string" ? [children.componentId] : [];
10708
+ }
10668
10709
  function hasInteractiveDescendant(id, components, visited) {
10669
10710
  if (visited.has(id))
10670
10711
  return false;
@@ -10674,8 +10715,7 @@ function hasInteractiveDescendant(id, components, visited) {
10674
10715
  return false;
10675
10716
  if (component.component === "Button" || component.action !== void 0 || ["TextField", "ChoicePicker", "Stepper"].includes(String(component.component)))
10676
10717
  return true;
10677
- const children = component.children;
10678
- const refs = Array.isArray(children) ? children : isPlainRecord(children) ? [children.componentId] : [];
10718
+ const refs = getComponentReferences(component);
10679
10719
  return refs.some((ref) => typeof ref === "string" && hasInteractiveDescendant(ref, components, visited));
10680
10720
  }
10681
10721
 
@@ -11669,6 +11709,7 @@ function aggregateMcpServers(resources, protocolAgentId) {
11669
11709
  // ../linkque-agent-runtime/dist/esm/core/types.js
11670
11710
  var EDebugLogScope;
11671
11711
  (function(EDebugLogScope2) {
11712
+ EDebugLogScope2["A2UI_ACTION"] = "A2UI_ACTION";
11672
11713
  EDebugLogScope2["CONFIG"] = "CONFIG";
11673
11714
  EDebugLogScope2["LLM"] = "LLM";
11674
11715
  EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
@@ -11736,7 +11777,11 @@ var McpProxyTool = class {
11736
11777
  return;
11737
11778
  try {
11738
11779
  await entry.server.close?.();
11739
- } catch {
11780
+ } catch (error) {
11781
+ try {
11782
+ this.debugLog(`[mcp] server ${entry.server.serverName} close failed: ${error instanceof Error ? error.message : "unknown error"}`, EDebugLogScope.MCP);
11783
+ } catch {
11784
+ }
11740
11785
  }
11741
11786
  }));
11742
11787
  }
@@ -12114,14 +12159,89 @@ var MCP_PROXY_INPUT_SCHEMA = {
12114
12159
  }
12115
12160
  };
12116
12161
 
12162
+ // ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
12163
+ var CardActionDiagnostics = class {
12164
+ sink;
12165
+ layer;
12166
+ stage = "validate";
12167
+ context;
12168
+ debugLog;
12169
+ startedAt = performance.now();
12170
+ constructor(sink, context, layer = "runtime") {
12171
+ this.sink = sink;
12172
+ this.layer = layer;
12173
+ this.context = { ...context };
12174
+ if (sink) {
12175
+ this.debugLog = (line, scope) => {
12176
+ this.write("diagnostic", { message: line }, scope);
12177
+ };
12178
+ }
12179
+ }
12180
+ write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
12181
+ if (!this.sink)
12182
+ return;
12183
+ try {
12184
+ const record2 = { ...this.context, ...fields };
12185
+ if (record2.message)
12186
+ record2.message = sanitizeDiagnosticText(record2.message);
12187
+ if (record2.errorName)
12188
+ record2.errorName = sanitizeDiagnosticText(record2.errorName);
12189
+ this.sink(JSON.stringify({
12190
+ operation: "a2uiAction.execute",
12191
+ layer: this.layer,
12192
+ event,
12193
+ stage: this.stage,
12194
+ ...record2,
12195
+ costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
12196
+ }), scope);
12197
+ } catch {
12198
+ }
12199
+ }
12200
+ error(event, error) {
12201
+ if (!this.sink)
12202
+ return;
12203
+ try {
12204
+ this.write(event, {
12205
+ errorName: error instanceof Error ? error.name : typeof error,
12206
+ message: error instanceof Error ? error.message : typeof error === "string" ? error : "\u975E\u6807\u51C6\u5F02\u5E38"
12207
+ });
12208
+ } catch {
12209
+ }
12210
+ }
12211
+ };
12212
+ function sanitizeDiagnosticText(value) {
12213
+ return value.replace(/\b(?:body|arguments|payload|headers)\s*[:=][\s\S]*/giu, "<payload>").replace(/\{[\s\S]*/gu, "<payload>").replace(/https?:\/\/[^\s]+/giu, "<url>").replace(/\b(?:authorization|cookie|set-cookie)\s*[:=][^\r\n]*/giu, "<redacted>").replace(/\bbearer\s+[^\s,;]+/giu, "Bearer <redacted>").replace(/\b((?:api[_-]?key|access[_-]?key|token|secret|password|ak|sk|tradeNO|userId|orderId)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu, "$1<redacted>").replace(/\s+/gu, " ").slice(0, 300);
12214
+ }
12215
+
12117
12216
  // ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
12118
12217
  async function executeCardAction(input) {
12218
+ const diagnostics = new CardActionDiagnostics(input.debugLog, {
12219
+ agentId: input.protocol.agentId,
12220
+ threadId: input.runtimeContext.threadId
12221
+ });
12222
+ diagnostics.write("started");
12223
+ try {
12224
+ const response = await executeCardActionInternal(input, diagnostics);
12225
+ diagnostics.write(response.ok ? "completed" : "failed", response.ok ? {} : { code: response.error.code, retryable: response.error.retryable });
12226
+ return response;
12227
+ } catch (error) {
12228
+ diagnostics.error("failed", error);
12229
+ throw error;
12230
+ }
12231
+ }
12232
+ async function executeCardActionInternal(input, diagnostics) {
12119
12233
  let request;
12120
12234
  try {
12121
12235
  request = parseA2UIActionExecuteRequest(input.request);
12122
12236
  } catch (error) {
12123
12237
  return failure("INVALID_INPUT", errorMessage(error, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
12124
12238
  }
12239
+ Object.assign(diagnostics.context, {
12240
+ invocationId: request.invocationId,
12241
+ actionId: request.actionId,
12242
+ cardRef: request.source.cardRef,
12243
+ cardRevision: request.source.cardRevision
12244
+ });
12125
12245
  if (request.agentId !== input.protocol.agentId) {
12126
12246
  return failure("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
12127
12247
  }
@@ -12131,24 +12251,38 @@ async function executeCardAction(input) {
12131
12251
  if (!input.runtimeContext.userId.trim()) {
12132
12252
  return failure("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
12133
12253
  }
12254
+ diagnostics.write("validated");
12255
+ diagnostics.stage = "binding";
12134
12256
  const resolved = resolvePaymentBinding(input.protocol, request.source, request.actionId);
12135
12257
  if (!resolved.ok)
12136
12258
  return resolved.response;
12137
- const registry = createRegistry(input.protocol, input.mcpServerProvider);
12259
+ Object.assign(diagnostics.context, {
12260
+ mcpResourceId: resolved.binding.createTrade.mcpResourceId,
12261
+ toolName: resolved.binding.createTrade.toolName
12262
+ });
12263
+ diagnostics.write("binding_resolved");
12264
+ diagnostics.stage = "tool_resolve";
12265
+ const registry = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog);
12138
12266
  try {
12139
12267
  const tool = await registry.resolve(resolved.binding.createTrade.mcpResourceId, resolved.binding.createTrade.toolName, input.signal);
12140
12268
  if (!tool) {
12141
12269
  return failure("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
12142
12270
  }
12271
+ diagnostics.stage = "tool_input";
12143
12272
  const args = createToolInput(resolved.binding.createTrade.inputBindings, request.actionContext, input.runtimeContext);
12144
12273
  if (!args)
12145
12274
  return failure("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
12146
12275
  let result;
12276
+ diagnostics.stage = "tool_execute";
12277
+ diagnostics.write("tool_started");
12147
12278
  try {
12148
12279
  result = await tool.execute(args, input.signal);
12149
- } catch {
12280
+ diagnostics.write("tool_completed");
12281
+ } catch (error) {
12282
+ diagnostics.error("tool_failed", error);
12150
12283
  return failure("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
12151
12284
  }
12285
+ diagnostics.stage = "tool_output";
12152
12286
  const structured = readStructuredContent(result);
12153
12287
  const tradeNO = readJsonPointer(structured, resolved.binding.createTrade.tradeNoPath);
12154
12288
  if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64) {
@@ -12160,7 +12294,10 @@ async function executeCardAction(input) {
12160
12294
  result: { kind: "payment", tradeNO }
12161
12295
  };
12162
12296
  } finally {
12297
+ const stage = diagnostics.stage;
12298
+ diagnostics.stage = "cleanup";
12163
12299
  await registry.closeAll();
12300
+ diagnostics.stage = stage;
12164
12301
  }
12165
12302
  }
12166
12303
  async function verifyPaymentResult(input) {
@@ -12223,9 +12360,9 @@ function resolvePaymentBinding(protocol, source, actionId) {
12223
12360
  }
12224
12361
  return { ok: true, binding };
12225
12362
  }
12226
- function createRegistry(protocol, provider) {
12363
+ function createRegistry(protocol, provider, debugLog) {
12227
12364
  const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
12228
- return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId));
12365
+ return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), { debugLog });
12229
12366
  }
12230
12367
  function createToolInput(bindings, actionContext, runtimeContext, tradeNO, callback) {
12231
12368
  const result = {};
@@ -12425,6 +12562,90 @@ function stableToolName(prefix, raw) {
12425
12562
  return `${prefix}_${readable}_${digest}`;
12426
12563
  }
12427
12564
 
12565
+ // ../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js
12566
+ var MAX_BYTES = 6e3;
12567
+ var MAX_LABEL = 160;
12568
+ function createCardSemanticSnapshot(receipt, fields) {
12569
+ const groups = receipt.coverage.map((coverage) => {
12570
+ const field = fields.find((f) => f.fieldId === coverage.fieldId);
12571
+ const entities = receipt.entities.filter((e) => e.fieldId === coverage.fieldId);
12572
+ const echo = field?.presentation?.visibility === "echo";
12573
+ const attributes = echo ? [...new Set(entities.flatMap((e) => Object.keys(e.attributes ?? {})))] : [];
12574
+ const hasValue = echo && entities.some((e) => Object.hasOwn(e, "value"));
12575
+ const hasLabel = echo && entities.some((e) => !Object.hasOwn(e, "value"));
12576
+ const columns = [
12577
+ "\u6761\u76EE\u5F15\u7528",
12578
+ ...hasLabel ? [columnLabel(field, field?.presentation?.labelPath, "\u540D\u79F0")] : [],
12579
+ ...hasValue ? [short(coverage.label)] : [],
12580
+ ...attributes.map((path2) => columnLabel(field, path2, path2))
12581
+ ];
12582
+ const rows = entities.map((e) => [
12583
+ e.ref,
12584
+ ...hasLabel ? [e.label] : [],
12585
+ ...hasValue ? [e.value ?? null] : [],
12586
+ ...attributes.map((path2) => e.attributes?.[path2] ?? null)
12587
+ ]);
12588
+ const total = coverage.itemCount ?? (coverage.present ? 1 : 0);
12589
+ return {
12590
+ field: coverage.fieldId,
12591
+ label: short(coverage.label),
12592
+ present: coverage.present,
12593
+ total,
12594
+ included: rows.length,
12595
+ complete: echo && coverage.present && rows.length === total && !entities.some((e) => e.truncated) && !receipt.omissions.some((o) => o.fieldId === coverage.fieldId),
12596
+ columns,
12597
+ rows
12598
+ };
12599
+ });
12600
+ const snapshot = {
12601
+ version: 1,
12602
+ groups,
12603
+ omissions: receipt.omissions.map((o) => ({ ...o }))
12604
+ };
12605
+ while (bytes(snapshot) > MAX_BYTES) {
12606
+ let group;
12607
+ for (let i = groups.length - 1; i >= 0; i--) {
12608
+ if (groups[i].rows.length > 0) {
12609
+ group = groups[i];
12610
+ break;
12611
+ }
12612
+ }
12613
+ snapshot.truncated = true;
12614
+ if (group) {
12615
+ group.rows.pop();
12616
+ group.included = group.rows.length;
12617
+ group.complete = false;
12618
+ } else if (groups.length) {
12619
+ groups.pop();
12620
+ } else if (snapshot.omissions.length) {
12621
+ snapshot.omissions.pop();
12622
+ } else
12623
+ break;
12624
+ }
12625
+ return snapshot;
12626
+ }
12627
+ function bytes(value) {
12628
+ return Buffer.byteLength(JSON.stringify(value));
12629
+ }
12630
+ function short(value) {
12631
+ return value.length > MAX_LABEL ? `${value.slice(0, MAX_LABEL - 1)}\u2026` : value;
12632
+ }
12633
+ function columnLabel(field, path2, fallback) {
12634
+ if (!field || !path2)
12635
+ return short(fallback);
12636
+ let schema = field.type === "array" ? field.valueSchema.items : field.valueSchema;
12637
+ for (const token of path2.slice(1).split("/").map((t) => t.replaceAll("~1", "/").replaceAll("~0", "~"))) {
12638
+ if (!schema || typeof schema !== "object" || Array.isArray(schema))
12639
+ return short(fallback);
12640
+ const properties = schema.properties;
12641
+ if (!properties || typeof properties !== "object" || Array.isArray(properties) || !Object.hasOwn(properties, token))
12642
+ return short(fallback);
12643
+ schema = properties[token];
12644
+ }
12645
+ const title = schema && typeof schema === "object" && !Array.isArray(schema) ? schema.title : void 0;
12646
+ return short(typeof title === "string" && title ? title : fallback);
12647
+ }
12648
+
12428
12649
  // ../linkque-agent-runtime/dist/esm/core/cardTools.js
12429
12650
  var FALLBACK_OBJECT_SCHEMA = {
12430
12651
  type: "object",
@@ -12548,6 +12769,7 @@ function createPresentationResult(resource, config, viewModel) {
12548
12769
  ...createA2UICardPresentationReceiptContent(config.fields, viewModel),
12549
12770
  responsePolicy: { verbatimEcho: "forbidden", hint: "acknowledge" }
12550
12771
  };
12772
+ receipt.semanticSnapshot = createCardSemanticSnapshot(receipt, config.fields);
12551
12773
  return {
12552
12774
  type: "linkque.presentation-tool-result",
12553
12775
  modelText: formatPresentationReceiptForModel(receipt),
@@ -12567,11 +12789,23 @@ function createPresentationResult(resource, config, viewModel) {
12567
12789
  function formatPresentationReceiptForModel(receipt) {
12568
12790
  return [
12569
12791
  "<a2ui-presentation-receipt>",
12570
- JSON.stringify(receipt),
12792
+ JSON.stringify(projectPresentationReceiptForModel(receipt)),
12571
12793
  "</a2ui-presentation-receipt>",
12572
- "The card above already presents these results. Do not repeat or restate its items as Markdown. Reply only with a brief acknowledgement or information not already presented by the card."
12794
+ "\u5361\u7247\u5DF2\u53D1\u51FA\uFF08\u4E0D\u4EE3\u8868\u5BA2\u6237\u7AEF\u5DF2\u6E32\u67D3\uFF09\u3002\u8BED\u4E49\u5FEB\u7167\u6765\u81EA\u6388\u6743\u7684\u6700\u7EC8\u5361\u7247\u6570\u636E\uFF1Bcolumns \u4E0E rows \u6309\u4F4D\u7F6E\u5BF9\u5E94\uFF0Cnull \u8868\u793A\u7F3A\u5931\u6216\u7A7A\u503C\uFF0Ccomplete=false \u65F6\u4E0D\u5F97\u628A\u91C7\u6837\u5F53\u4F5C\u5168\u96C6\u3002\u4E0D\u8981\u7528 Markdown \u91CD\u590D\u5217\u51FA\u6216\u6539\u5199\u5361\u7247\u4E2D\u7684\u6761\u76EE\uFF1B\u53EA\u8865\u5145\u7528\u6237\u5C1A\u672A\u5F97\u5230\u7684\u6BD4\u8F83\u3001\u89E3\u91CA\u6216\u5FC5\u8981\u8FFD\u95EE\uFF0C\u7528\u6237\u660E\u786E\u8981\u6C42\u6587\u5B57\u8868\u683C\u65F6\u53EF\u4EE5\u63D0\u4F9B\u3002\u5FEB\u7167\u672A\u5305\u542B\u7684\u4FE1\u606F\u4FDD\u6301\u672A\u77E5\uFF0C\u6E90\u5DE5\u5177\u7684\u989D\u5916\u4FE1\u606F\u4E0D\u80FD\u79F0\u4E3A\u5361\u7247\u5DF2\u5C55\u793A\u5185\u5BB9\u3002"
12573
12795
  ].join("\n");
12574
12796
  }
12797
+ function projectPresentationReceiptForModel(receipt) {
12798
+ if (!receipt.semanticSnapshot)
12799
+ return receipt;
12800
+ return {
12801
+ version: receipt.version,
12802
+ cardRef: receipt.cardRef,
12803
+ cardRevision: receipt.cardRevision,
12804
+ cardInstanceId: receipt.cardInstanceId,
12805
+ status: receipt.status,
12806
+ semanticSnapshot: receipt.semanticSnapshot
12807
+ };
12808
+ }
12575
12809
  function parseCardConfig(resource) {
12576
12810
  const parsed = parseA2UICardResourceConfig(resource.config);
12577
12811
  if (!parsed.success) {
@@ -12625,9 +12859,9 @@ function collectA2UISurfaceIdsForLegacyContract(protocol) {
12625
12859
  function createPresentationDescription(config) {
12626
12860
  return [
12627
12861
  config.description,
12628
- `Use this card when: ${config.whenToUse}`,
12629
- ...config.whenNotToUse ? [`Do not use this card when: ${config.whenNotToUse}`] : [],
12630
- "Provide only the declared identifier/filter arguments. Authoritative business values are resolved by the platform."
12862
+ `\u9002\u7528\u573A\u666F\uFF1A${config.whenToUse}`,
12863
+ ...config.whenNotToUse ? [`\u4E0D\u9002\u7528\u573A\u666F\uFF1A${config.whenNotToUse}`] : [],
12864
+ "\u53EA\u63D0\u4F9B\u5DF2\u58F0\u660E\u7684\u6807\u8BC6\u6216\u7B5B\u9009\u53C2\u6570\u3002\u6743\u5A01\u4E1A\u52A1\u6570\u636E\u7531\u5E73\u53F0\u89E3\u6790\u83B7\u53D6\u3002"
12631
12865
  ].join("\n");
12632
12866
  }
12633
12867
  function cloneJsonObject2(value, label) {
@@ -12891,6 +13125,12 @@ function normalizeHookResources(resources) {
12891
13125
  }).sort((a, b) => (a.config.order ?? 0) - (b.config.order ?? 0));
12892
13126
  }
12893
13127
 
13128
+ // ../linkque-agent-runtime/dist/esm/core/logFailure.js
13129
+ import { emitWarning } from "node:process";
13130
+ function warnLogFailure(stage, error) {
13131
+ emitWarning(`[${stage}] errorType=${error instanceof Error ? error.name : typeof error}`, { code: "LINKQUE_RUNTIME_DIAGNOSTIC_FAILURE" });
13132
+ }
13133
+
12894
13134
  // ../linkque-agent-runtime/dist/esm/core/hook/hookLog.js
12895
13135
  var HOOK_LOG_MESSAGE_MAX_LENGTH = 200;
12896
13136
  function writeHookLog(debugLog, record2) {
@@ -12898,7 +13138,8 @@ function writeHookLog(debugLog, record2) {
12898
13138
  return;
12899
13139
  try {
12900
13140
  debugLog(JSON.stringify(redactHookLogRecord(record2)), EDebugLogScope.HOOK);
12901
- } catch {
13141
+ } catch (error) {
13142
+ warnLogFailure("writeHookLog", error);
12902
13143
  }
12903
13144
  }
12904
13145
  function redactHookLogRecord(record2) {
@@ -13097,6 +13338,15 @@ var HookDispatcher = class {
13097
13338
  stage: EHookStage.RUN_READ,
13098
13339
  read: { readAt: subject.readAt ?? now() }
13099
13340
  };
13341
+ case EHookStage.MODEL_RESPONSE_RECEIVED: {
13342
+ if (!subject.model)
13343
+ throw new Error("MODEL_RESPONSE_RECEIVED Hook \u7F3A\u5C11\u54CD\u5E94\u4E0A\u4E0B\u6587");
13344
+ return {
13345
+ ...base,
13346
+ stage: EHookStage.MODEL_RESPONSE_RECEIVED,
13347
+ model: subject.model
13348
+ };
13349
+ }
13100
13350
  case EHookStage.AFTER_MODEL_CALL: {
13101
13351
  if (!subject.model || subject.model.messageContent === void 0) {
13102
13352
  throw new Error("AFTER_MODEL_CALL Hook \u7F3A\u5C11\u5B8C\u6574 model context");
@@ -13645,7 +13895,8 @@ function redactHeaders(headers) {
13645
13895
  pairs.push(`${key}=${redactHeader(key, value)}`);
13646
13896
  }
13647
13897
  }
13648
- } catch {
13898
+ } catch (error) {
13899
+ warnLogFailure("httpLoggingFetch.redactHeaders", error);
13649
13900
  }
13650
13901
  return pairs.join(",");
13651
13902
  }
@@ -13682,7 +13933,8 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
13682
13933
  const cl = resp.headers.get("content-length");
13683
13934
  if (cl)
13684
13935
  len = cl;
13685
- } catch {
13936
+ } catch (error) {
13937
+ warnLogFailure("httpLoggingFetch.contentLength", error);
13686
13938
  }
13687
13939
  const correlation = readResponseCorrelationId(resp.headers);
13688
13940
  const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
@@ -13711,14 +13963,16 @@ function readResponseCorrelationId(headers) {
13711
13963
  };
13712
13964
  });
13713
13965
  return matched;
13714
- } catch {
13966
+ } catch (error) {
13967
+ warnLogFailure("httpLoggingFetch.responseCorrelationId", error);
13715
13968
  }
13716
13969
  return void 0;
13717
13970
  }
13718
13971
  function safeLog(debugLog, line) {
13719
13972
  try {
13720
13973
  debugLog(line, EDebugLogScope.HTTP);
13721
- } catch {
13974
+ } catch (error) {
13975
+ warnLogFailure("httpLoggingFetch.safeLog", error);
13722
13976
  }
13723
13977
  }
13724
13978
  function nowMs() {
@@ -20316,13 +20570,42 @@ var RemoteGatewayMcpServerProvider = class {
20316
20570
  });
20317
20571
  const serverName = resource.config.serverName ?? resource.resourceId;
20318
20572
  const argsMappingRules = resource.config.argsMappingRules ?? [];
20573
+ let requestSequence = 0;
20574
+ const request = async (method, params, invoke) => {
20575
+ const requestId = ++requestSequence;
20576
+ const log = (phase, payload) => {
20577
+ if (!this.debugLog)
20578
+ return;
20579
+ try {
20580
+ this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload })}`, EDebugLogScope.MCP);
20581
+ } catch (error) {
20582
+ warnLogFailure("remoteGatewayMcpServer.log", error);
20583
+ }
20584
+ };
20585
+ log("request", params);
20586
+ try {
20587
+ const result = await invoke();
20588
+ log("response", result);
20589
+ return result;
20590
+ } catch (error) {
20591
+ log("error", error instanceof Error ? { name: error.name, message: error.message } : error);
20592
+ throw error;
20593
+ }
20594
+ };
20595
+ const loggedClient = {
20596
+ listTools: () => request("tools/list", {}, () => client.listTools()),
20597
+ callTool: (params) => request("tools/call", params, () => client.callTool(params))
20598
+ };
20319
20599
  return {
20320
20600
  resourceId: resource.resourceId,
20321
20601
  serverName,
20322
- listTools: () => listToolsFromClient(client, resource.resourceId),
20602
+ listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
20323
20603
  callTool: (name, args) => {
20324
20604
  const mapped = applyArgsMappingRules(name, args, argsMappingRules);
20325
- return client.callTool({ name, arguments: mapped ?? {} });
20605
+ return loggedClient.callTool({
20606
+ name,
20607
+ arguments: mapped ?? {}
20608
+ });
20326
20609
  },
20327
20610
  close: async () => {
20328
20611
  try {
@@ -21196,8 +21479,8 @@ var WebSkillLoader = class {
21196
21479
  return readFile(path.join(candidate, "SKILL.md"), "utf8");
21197
21480
  }
21198
21481
  if (isZipPath(candidate)) {
21199
- const bytes = new Uint8Array(await readFile(candidate));
21200
- const files = await unzipBytes(bytes, resourceId);
21482
+ const bytes2 = new Uint8Array(await readFile(candidate));
21483
+ const files = await unzipBytes(bytes2, resourceId);
21201
21484
  const body = extractSkillMarkdown(files);
21202
21485
  if (body === void 0) {
21203
21486
  throw new Error(`WebSkillLoader \u5728\u672C\u5730 zip \u5185\u672A\u627E\u5230 SKILL.md(\u6216\u56DE\u9000 .md)\u6B63\u6587: ${url2} (resourceId=${resourceId})`);
@@ -21240,7 +21523,7 @@ var extractSkillMarkdown = (files) => {
21240
21523
  const rootMd = paths.find((p) => p.endsWith(".md") && !p.includes("/"));
21241
21524
  return rootMd === void 0 ? void 0 : decodeUtf8(files[rootMd]);
21242
21525
  };
21243
- var decodeUtf8 = (bytes) => new TextDecoder("utf-8", { fatal: true }).decode(bytes);
21526
+ var decodeUtf8 = (bytes2) => new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
21244
21527
  var globalFetch = (url2) => fetch(url2);
21245
21528
  var detectScheme = (url2) => {
21246
21529
  if (/^https:\/\//i.test(url2))
@@ -21447,6 +21730,7 @@ export {
21447
21730
  createCardPresentationToolName,
21448
21731
  executeCardPresentation,
21449
21732
  executeCardPresentationFromSources,
21733
+ projectPresentationReceiptForModel,
21450
21734
  parseCardConfig,
21451
21735
  isAgentPresentationToolResult,
21452
21736
  createPresentationDescription,
@@ -21456,6 +21740,7 @@ export {
21456
21740
  aggregateMcpServers,
21457
21741
  McpProxyTool,
21458
21742
  executeHomeData,
21743
+ CardActionDiagnostics,
21459
21744
  executeCardAction,
21460
21745
  verifyPaymentResult,
21461
21746
  FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
@@ -21466,6 +21751,7 @@ export {
21466
21751
  NoopMcpServerProvider,
21467
21752
  buildHookCommonParams,
21468
21753
  normalizeHookResources,
21754
+ warnLogFailure,
21469
21755
  HookDispatcher,
21470
21756
  DEFAULT_HOOK_DRAIN_BUDGET_MS,
21471
21757
  SideEffectRunner,