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.
package/worker.js CHANGED
@@ -39,6 +39,7 @@ var init_types = __esm({
39
39
  "../linkque-agent-runtime/dist/esm/core/types.js"() {
40
40
  "use strict";
41
41
  (function(EDebugLogScope2) {
42
+ EDebugLogScope2["A2UI_ACTION"] = "A2UI_ACTION";
42
43
  EDebugLogScope2["CONFIG"] = "CONFIG";
43
44
  EDebugLogScope2["LLM"] = "LLM";
44
45
  EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
@@ -85,6 +86,7 @@ var init_agentProtocol = __esm({
85
86
  EHookStage2["RUN_FAILED"] = "RUN_FAILED";
86
87
  EHookStage2["RUN_READ"] = "RUN_READ";
87
88
  EHookStage2["AFTER_MODEL_CALL"] = "AFTER_MODEL_CALL";
89
+ EHookStage2["MODEL_RESPONSE_RECEIVED"] = "MODEL_RESPONSE_RECEIVED";
88
90
  EHookStage2["BEFORE_TOOL_CALL"] = "BEFORE_TOOL_CALL";
89
91
  EHookStage2["AFTER_TOOL_CALL"] = "AFTER_TOOL_CALL";
90
92
  EHookStage2["TOOL_CALL_FAILED"] = "TOOL_CALL_FAILED";
@@ -8687,6 +8689,9 @@ function validateAst(ast) {
8687
8689
  if (!ALLOWED_AST_TYPES.has(value.type)) {
8688
8690
  throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_NODE_FORBIDDEN", `JMESPath node ${value.type} is not allowed`);
8689
8691
  }
8692
+ if (value.type === "Index" && (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 0)) {
8693
+ throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_INVALID", "array index must be a non-negative safe integer");
8694
+ }
8690
8695
  if (value.type === "Function" && value.name !== "not_null") {
8691
8696
  throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_FUNCTION_FORBIDDEN", `JMESPath function ${String(value.name)} is not allowed`);
8692
8697
  }
@@ -8712,6 +8717,8 @@ var init_structural = __esm({
8712
8717
  "Field",
8713
8718
  "Function",
8714
8719
  "Identity",
8720
+ "Index",
8721
+ "IndexExpression",
8715
8722
  "KeyValuePair",
8716
8723
  "Literal",
8717
8724
  "MultiSelectHash",
@@ -9289,6 +9296,9 @@ function validateAst2(ast) {
9289
9296
  if (!ALLOWED_AST_TYPES2.has(value.type)) {
9290
9297
  throw new A2UICardExpressionError("CARD_EXPRESSION_NODE_FORBIDDEN", `JMESPath node ${value.type} is not allowed by ${A2UI_CARD_TRANSFORM_PROFILE}`);
9291
9298
  }
9299
+ if (value.type === "Index" && (typeof value.value !== "number" || !Number.isSafeInteger(value.value) || value.value < 0)) {
9300
+ throw new A2UICardExpressionError("CARD_EXPRESSION_INVALID", "array index must be a non-negative safe integer");
9301
+ }
9292
9302
  if (value.type === "Function" && value.name !== "not_null") {
9293
9303
  throw new A2UICardExpressionError("CARD_EXPRESSION_FUNCTION_FORBIDDEN", `JMESPath function ${String(value.name)} is not allowed`);
9294
9304
  }
@@ -9313,6 +9323,8 @@ var init_expression = __esm({
9313
9323
  "Field",
9314
9324
  "Function",
9315
9325
  "Identity",
9326
+ "Index",
9327
+ "IndexExpression",
9316
9328
  "KeyValuePair",
9317
9329
  "Literal",
9318
9330
  "MultiSelectHash",
@@ -9744,8 +9756,6 @@ function validateComponents(payload, path6, surfaces, issues) {
9744
9756
  if (value !== void 0)
9745
9757
  validateProperty(value, property, `${componentPath}.${name}`, issues, name);
9746
9758
  }
9747
- if (component.component === "Tag" && component.icon === void 0 && component.gap !== void 0)
9748
- issues.push(issue2(`${componentPath}.gap`, "TAG_GAP_REQUIRES_ICON", "Tag.gap requires Tag.icon"));
9749
9759
  if (component["x2-overflow"] !== void 0)
9750
9760
  validateOverflow(component, componentPath, issues);
9751
9761
  if (component.component === "TextField")
@@ -9759,7 +9769,7 @@ function validateComponents(payload, path6, surfaces, issues) {
9759
9769
  validateStepper(component, componentPath, issues);
9760
9770
  if (component.checks !== void 0)
9761
9771
  validateChecks(component.checks, `${componentPath}.checks`, issues);
9762
- if (component.format !== void 0 && (component.component === "Text" || component.component === "Tag"))
9772
+ if (component.format !== void 0 && component.component === "Text")
9763
9773
  validateNumberFormat(component.format, `${componentPath}.format`, issues);
9764
9774
  if (component.action !== void 0)
9765
9775
  validateAction(component.action, `${componentPath}.action`, issues, 0);
@@ -9773,6 +9783,11 @@ function validateProperty(value, schema, path6, issues, propertyName) {
9773
9783
  issues.push(issue2(path6, "INVALID_DISPLAY_VALUE", `display value must be ${stringOnly ? "a string" : "a string or finite number"}, or a compatible display binding`));
9774
9784
  return;
9775
9785
  }
9786
+ if (schema.kind === "child") {
9787
+ if (!isSafeIdentifier(value))
9788
+ issues.push(issue2(path6, "INVALID_CHILD", "child must be a safe component id"));
9789
+ return;
9790
+ }
9776
9791
  if (schema.kind === "children") {
9777
9792
  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);
9778
9793
  if (!valid)
@@ -10013,20 +10028,27 @@ function validateReferences(surfaces, path6, issues) {
10013
10028
  issues.push(issue2(`${path6}.surfaces.${surfaceId}`, "MISSING_ROOT_COMPONENT", "surface must define root"));
10014
10029
  const edges = /* @__PURE__ */ new Map();
10015
10030
  for (const [id, component] of components) {
10016
- const children = component.children;
10017
- const refs = Array.isArray(children) ? children.filter((entry) => typeof entry === "string") : isPlainRecord(children) && typeof children.componentId === "string" ? [children.componentId] : [];
10031
+ const refs = getComponentReferences(component);
10018
10032
  edges.set(id, refs);
10019
10033
  refs.forEach((ref) => {
10020
10034
  if (!components.has(ref))
10021
- issues.push(issue2(`${path6}.surfaces.${surfaceId}.components.${id}.children`, "MISSING_COMPONENT_REFERENCE", `component ${ref} does not exist`));
10035
+ issues.push(issue2(`${path6}.surfaces.${surfaceId}.components.${id}.${component.child !== void 0 ? "child" : "children"}`, "MISSING_COMPONENT_REFERENCE", `component ${ref} does not exist`));
10022
10036
  });
10023
10037
  if ((component.component === "Button" || component.component === "Card" && component.action !== void 0) && refs.some((ref) => hasInteractiveDescendant(ref, components, /* @__PURE__ */ new Set())))
10024
- issues.push(issue2(`${path6}.surfaces.${surfaceId}.components.${id}.children`, "NESTED_INTERACTION", "action components cannot contain interactive descendants"));
10038
+ issues.push(issue2(`${path6}.surfaces.${surfaceId}.components.${id}.${component.child !== void 0 ? "child" : "children"}`, "NESTED_INTERACTION", "action components cannot contain interactive descendants"));
10025
10039
  collectSurfaceOpenReferences(component.action).forEach((targetSurfaceId) => {
10026
10040
  if (!surfaces.has(targetSurfaceId))
10027
10041
  issues.push(issue2(`${path6}.surfaces.${surfaceId}.components.${id}.action`, "MISSING_SURFACE_REFERENCE", `surface ${targetSurfaceId} does not exist`));
10028
10042
  });
10029
10043
  }
10044
+ components.forEach((component, id) => {
10045
+ if (component.grow === void 0)
10046
+ return;
10047
+ const parents = [...components.values()].filter((parent) => getComponentReferences(parent).includes(id));
10048
+ if (id === "root" || parents.length === 0 || parents.some((parent) => parent.component !== "Row" && parent.component !== "Column")) {
10049
+ issues.push(issue2(`${path6}.surfaces.${surfaceId}.components.${id}.grow`, "INVALID_LAYOUT_PARENT", "grow requires a direct Row or Column parent in every occurrence"));
10050
+ }
10051
+ });
10030
10052
  const visiting = /* @__PURE__ */ new Set();
10031
10053
  const visited2 = /* @__PURE__ */ new Set();
10032
10054
  const walk = (id) => {
@@ -10057,6 +10079,14 @@ function collectSurfaceOpenReferences(value, result = /* @__PURE__ */ new Set())
10057
10079
  }
10058
10080
  return result;
10059
10081
  }
10082
+ function getComponentReferences(component) {
10083
+ if (typeof component.child === "string")
10084
+ return [component.child];
10085
+ const children = component.children;
10086
+ if (Array.isArray(children))
10087
+ return children.filter((entry) => typeof entry === "string");
10088
+ return isPlainRecord(children) && typeof children.componentId === "string" ? [children.componentId] : [];
10089
+ }
10060
10090
  function hasInteractiveDescendant(id, components, visited2) {
10061
10091
  if (visited2.has(id))
10062
10092
  return false;
@@ -10066,22 +10096,20 @@ function hasInteractiveDescendant(id, components, visited2) {
10066
10096
  return false;
10067
10097
  if (component.component === "Button" || component.action !== void 0 || ["TextField", "ChoicePicker", "Stepper"].includes(String(component.component)))
10068
10098
  return true;
10069
- const children = component.children;
10070
- const refs = Array.isArray(children) ? children : isPlainRecord(children) ? [children.componentId] : [];
10099
+ const refs = getComponentReferences(component);
10071
10100
  return refs.some((ref) => typeof ref === "string" && hasInteractiveDescendant(ref, components, visited2));
10072
10101
  }
10073
- var spacing, colors, iconNames, box, typography, container, A2UI_V4_COMPONENT_CATALOG;
10102
+ var spacing, colors, iconNames, layoutItem, width, radius, decoration, typography, container, _listJustify, listContainer, A2UI_V4_COMPONENT_CATALOG;
10074
10103
  var init_v4Catalog = __esm({
10075
10104
  "../agent-a2ui-card-contract/dist/esm/v4Catalog.js"() {
10076
10105
  "use strict";
10077
- init_protocol();
10078
10106
  init_json2();
10107
+ init_protocol();
10079
10108
  spacing = ["none", "xs", "sm", "md", "lg"];
10080
10109
  colors = [
10081
10110
  "default",
10082
10111
  "muted",
10083
10112
  "primary",
10084
- "accent",
10085
10113
  "success",
10086
10114
  "warning",
10087
10115
  "error",
@@ -10133,8 +10161,18 @@ var init_v4Catalog = __esm({
10133
10161
  "warning",
10134
10162
  "arrow-right-long"
10135
10163
  ];
10136
- box = {
10137
- margin: { kind: "string", values: spacing },
10164
+ layoutItem = {
10165
+ grow: {
10166
+ kind: "number",
10167
+ values: [0, 1, 2, 3, 4],
10168
+ parentComponents: ["Row", "Column"]
10169
+ }
10170
+ };
10171
+ width = { width: { kind: "string", values: ["fit", "fill"] } };
10172
+ radius = {
10173
+ radius: { kind: "string", values: ["none", "xs", "sm", "md", "full"] }
10174
+ };
10175
+ decoration = {
10138
10176
  padding: { kind: "string", values: spacing },
10139
10177
  background: {
10140
10178
  kind: "string",
@@ -10152,29 +10190,17 @@ var init_v4Catalog = __esm({
10152
10190
  kind: "string",
10153
10191
  values: ["none", "subtle", "card-border", "primary"]
10154
10192
  },
10155
- radius: { kind: "string", values: ["none", "xs", "sm", "md", "full"] },
10156
- width: { kind: "string", values: ["fit", "fill"] },
10157
- grow: { kind: "number", values: [0, 1, 2, 3, 4] },
10158
- shrink: { kind: "boolean" }
10193
+ ...radius
10159
10194
  };
10160
10195
  typography = {
10161
10196
  color: { kind: "string", values: colors },
10162
- fontSize: {
10163
- kind: "string",
10164
- values: [
10165
- "small",
10166
- "medium",
10167
- "large",
10168
- "striking",
10169
- "display",
10170
- "badge",
10171
- "merchant"
10172
- ]
10173
- },
10197
+ fontSize: { kind: "string", values: ["xs", "sm", "md", "lg", "xl", "xxl"] },
10174
10198
  fontWeight: { kind: "string", values: ["normal", "semibold", "bold"] }
10175
10199
  };
10176
10200
  container = {
10177
- ...box,
10201
+ ...layoutItem,
10202
+ ...width,
10203
+ padding: { kind: "string", values: spacing },
10178
10204
  children: { kind: "children", required: true },
10179
10205
  gap: { kind: "string", values: spacing },
10180
10206
  align: {
@@ -10194,6 +10220,7 @@ var init_v4Catalog = __esm({
10194
10220
  },
10195
10221
  "x2-overflow": { kind: "format" }
10196
10222
  };
10223
+ ({ justify: _listJustify, ...listContainer } = container);
10197
10224
  A2UI_V4_COMPONENT_CATALOG = Object.freeze({
10198
10225
  catalogId: LINKQUE_A2UI_V4_CATALOG_ID,
10199
10226
  protocolVersion: "0.9",
@@ -10201,7 +10228,10 @@ var init_v4Catalog = __esm({
10201
10228
  Card: {
10202
10229
  interaction: "action",
10203
10230
  properties: {
10204
- ...container,
10231
+ ...layoutItem,
10232
+ ...width,
10233
+ ...decoration,
10234
+ child: { kind: "child", required: true },
10205
10235
  action: { kind: "action" },
10206
10236
  disabled: { kind: "boolean" }
10207
10237
  }
@@ -10211,13 +10241,14 @@ var init_v4Catalog = __esm({
10211
10241
  interaction: "none",
10212
10242
  properties: {
10213
10243
  ...container,
10214
- wrap: { kind: "string", values: ["wrap", "nowrap"] }
10244
+ wrap: { kind: "string", values: ["wrap", "nowrap"] },
10245
+ layout: { kind: "string", values: ["flex", "inline"] }
10215
10246
  }
10216
10247
  },
10217
10248
  List: {
10218
10249
  interaction: "none",
10219
10250
  properties: {
10220
- ...container,
10251
+ ...listContainer,
10221
10252
  variant: {
10222
10253
  kind: "string",
10223
10254
  required: true,
@@ -10228,8 +10259,9 @@ var init_v4Catalog = __esm({
10228
10259
  Text: {
10229
10260
  interaction: "none",
10230
10261
  properties: {
10231
- ...box,
10262
+ ...layoutItem,
10232
10263
  ...typography,
10264
+ shrink: { kind: "boolean" },
10233
10265
  text: { kind: "binding", required: true },
10234
10266
  maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] },
10235
10267
  decoration: { kind: "string", values: ["line-through"] },
@@ -10239,19 +10271,31 @@ var init_v4Catalog = __esm({
10239
10271
  Tag: {
10240
10272
  interaction: "none",
10241
10273
  properties: {
10242
- ...box,
10243
- ...typography,
10274
+ ...layoutItem,
10244
10275
  text: { kind: "binding", required: true },
10245
10276
  icon: { kind: "string", values: iconNames },
10246
- gap: { kind: "string", values: spacing },
10247
- maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] },
10248
- format: { kind: "format" }
10277
+ tone: {
10278
+ kind: "string",
10279
+ values: [
10280
+ "default",
10281
+ "muted",
10282
+ "primary",
10283
+ "success",
10284
+ "warning",
10285
+ "error"
10286
+ ]
10287
+ },
10288
+ variant: { kind: "string", values: ["soft", "outline", "plain"] },
10289
+ size: { kind: "string", values: ["sm", "md"] },
10290
+ shrink: { kind: "boolean" },
10291
+ maxLines: { kind: "number", values: [0, 1, 2, 3, 4, 5, 6] }
10249
10292
  }
10250
10293
  },
10251
10294
  Button: {
10252
10295
  interaction: "action",
10253
10296
  properties: {
10254
- ...box,
10297
+ ...layoutItem,
10298
+ ...width,
10255
10299
  label: { kind: "binding", required: true },
10256
10300
  action: { kind: "action", required: true },
10257
10301
  checks: { kind: "format" },
@@ -10269,34 +10313,29 @@ var init_v4Catalog = __esm({
10269
10313
  Image: {
10270
10314
  interaction: "none",
10271
10315
  properties: {
10272
- ...box,
10316
+ ...layoutItem,
10317
+ ...radius,
10273
10318
  src: { kind: "binding", required: true },
10274
10319
  alt: { kind: "binding" },
10275
10320
  fit: {
10276
10321
  kind: "string",
10277
10322
  values: ["contain", "cover", "fill", "none", "scale-down"]
10278
10323
  },
10279
- variant: {
10324
+ aspectRatio: {
10280
10325
  kind: "string",
10281
- values: [
10282
- "icon",
10283
- "avatar",
10284
- "merchantLogo",
10285
- "smallFeature",
10286
- "mediumFeature",
10287
- "portraitFeature",
10288
- "productThumbnail",
10289
- "voucherThumbnail",
10290
- "largeFeature",
10291
- "header"
10292
- ]
10326
+ values: ["square", "portrait", "landscape", "wide", "banner"]
10327
+ },
10328
+ height: { kind: "string", values: ["auto", "fill"] },
10329
+ size: {
10330
+ kind: "string",
10331
+ values: ["xs", "sm", "md", "lg", "xl", "full"]
10293
10332
  }
10294
10333
  }
10295
10334
  },
10296
10335
  Icon: {
10297
10336
  interaction: "none",
10298
10337
  properties: {
10299
- ...box,
10338
+ ...layoutItem,
10300
10339
  name: { kind: "string", required: true, values: iconNames },
10301
10340
  label: { kind: "string" },
10302
10341
  color: { kind: "string", values: colors },
@@ -10309,15 +10348,15 @@ var init_v4Catalog = __esm({
10309
10348
  Divider: {
10310
10349
  interaction: "none",
10311
10350
  properties: {
10312
- ...box,
10351
+ ...layoutItem,
10313
10352
  axis: { kind: "string", values: ["horizontal", "vertical"] }
10314
10353
  }
10315
10354
  },
10316
10355
  TextField: {
10317
10356
  interaction: "input",
10318
10357
  properties: {
10319
- ...box,
10320
- ...typography,
10358
+ ...layoutItem,
10359
+ ...width,
10321
10360
  label: { kind: "string", required: true },
10322
10361
  value: { kind: "binding", required: true },
10323
10362
  checks: { kind: "format" },
@@ -10341,7 +10380,8 @@ var init_v4Catalog = __esm({
10341
10380
  ChoicePicker: {
10342
10381
  interaction: "input",
10343
10382
  properties: {
10344
- ...box,
10383
+ ...layoutItem,
10384
+ ...width,
10345
10385
  label: { kind: "string", required: true },
10346
10386
  value: { kind: "binding", required: true },
10347
10387
  options: { kind: "options", required: true },
@@ -10356,7 +10396,8 @@ var init_v4Catalog = __esm({
10356
10396
  Stepper: {
10357
10397
  interaction: "input",
10358
10398
  properties: {
10359
- ...box,
10399
+ ...layoutItem,
10400
+ ...width,
10360
10401
  label: { kind: "string", required: true },
10361
10402
  value: { kind: "binding", required: true },
10362
10403
  min: { kind: "number" },
@@ -11424,6 +11465,96 @@ var init_mcpNaming = __esm({
11424
11465
  }
11425
11466
  });
11426
11467
 
11468
+ // ../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js
11469
+ function createCardSemanticSnapshot(receipt, fields) {
11470
+ const groups = receipt.coverage.map((coverage) => {
11471
+ const field = fields.find((f3) => f3.fieldId === coverage.fieldId);
11472
+ const entities = receipt.entities.filter((e2) => e2.fieldId === coverage.fieldId);
11473
+ const echo = field?.presentation?.visibility === "echo";
11474
+ const attributes = echo ? [...new Set(entities.flatMap((e2) => Object.keys(e2.attributes ?? {})))] : [];
11475
+ const hasValue = echo && entities.some((e2) => Object.hasOwn(e2, "value"));
11476
+ const hasLabel = echo && entities.some((e2) => !Object.hasOwn(e2, "value"));
11477
+ const columns = [
11478
+ "\u6761\u76EE\u5F15\u7528",
11479
+ ...hasLabel ? [columnLabel(field, field?.presentation?.labelPath, "\u540D\u79F0")] : [],
11480
+ ...hasValue ? [short(coverage.label)] : [],
11481
+ ...attributes.map((path6) => columnLabel(field, path6, path6))
11482
+ ];
11483
+ const rows = entities.map((e2) => [
11484
+ e2.ref,
11485
+ ...hasLabel ? [e2.label] : [],
11486
+ ...hasValue ? [e2.value ?? null] : [],
11487
+ ...attributes.map((path6) => e2.attributes?.[path6] ?? null)
11488
+ ]);
11489
+ const total = coverage.itemCount ?? (coverage.present ? 1 : 0);
11490
+ return {
11491
+ field: coverage.fieldId,
11492
+ label: short(coverage.label),
11493
+ present: coverage.present,
11494
+ total,
11495
+ included: rows.length,
11496
+ complete: echo && coverage.present && rows.length === total && !entities.some((e2) => e2.truncated) && !receipt.omissions.some((o) => o.fieldId === coverage.fieldId),
11497
+ columns,
11498
+ rows
11499
+ };
11500
+ });
11501
+ const snapshot = {
11502
+ version: 1,
11503
+ groups,
11504
+ omissions: receipt.omissions.map((o) => ({ ...o }))
11505
+ };
11506
+ while (bytes(snapshot) > MAX_BYTES) {
11507
+ let group;
11508
+ for (let i2 = groups.length - 1; i2 >= 0; i2--) {
11509
+ if (groups[i2].rows.length > 0) {
11510
+ group = groups[i2];
11511
+ break;
11512
+ }
11513
+ }
11514
+ snapshot.truncated = true;
11515
+ if (group) {
11516
+ group.rows.pop();
11517
+ group.included = group.rows.length;
11518
+ group.complete = false;
11519
+ } else if (groups.length) {
11520
+ groups.pop();
11521
+ } else if (snapshot.omissions.length) {
11522
+ snapshot.omissions.pop();
11523
+ } else
11524
+ break;
11525
+ }
11526
+ return snapshot;
11527
+ }
11528
+ function bytes(value) {
11529
+ return Buffer.byteLength(JSON.stringify(value));
11530
+ }
11531
+ function short(value) {
11532
+ return value.length > MAX_LABEL ? `${value.slice(0, MAX_LABEL - 1)}\u2026` : value;
11533
+ }
11534
+ function columnLabel(field, path6, fallback) {
11535
+ if (!field || !path6)
11536
+ return short(fallback);
11537
+ let schema = field.type === "array" ? field.valueSchema.items : field.valueSchema;
11538
+ for (const token of path6.slice(1).split("/").map((t2) => t2.replaceAll("~1", "/").replaceAll("~0", "~"))) {
11539
+ if (!schema || typeof schema !== "object" || Array.isArray(schema))
11540
+ return short(fallback);
11541
+ const properties = schema.properties;
11542
+ if (!properties || typeof properties !== "object" || Array.isArray(properties) || !Object.hasOwn(properties, token))
11543
+ return short(fallback);
11544
+ schema = properties[token];
11545
+ }
11546
+ const title = schema && typeof schema === "object" && !Array.isArray(schema) ? schema.title : void 0;
11547
+ return short(typeof title === "string" && title ? title : fallback);
11548
+ }
11549
+ var MAX_BYTES, MAX_LABEL;
11550
+ var init_cardSemanticSnapshot = __esm({
11551
+ "../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js"() {
11552
+ "use strict";
11553
+ MAX_BYTES = 6e3;
11554
+ MAX_LABEL = 160;
11555
+ }
11556
+ });
11557
+
11427
11558
  // ../linkque-agent-runtime/dist/esm/core/cardTools.js
11428
11559
  function createCardPresentationToolName(resourceId) {
11429
11560
  return stableToolName("a2ui_card", resourceId);
@@ -11543,6 +11674,7 @@ function createPresentationResult(resource, config2, viewModel) {
11543
11674
  ...createA2UICardPresentationReceiptContent(config2.fields, viewModel),
11544
11675
  responsePolicy: { verbatimEcho: "forbidden", hint: "acknowledge" }
11545
11676
  };
11677
+ receipt.semanticSnapshot = createCardSemanticSnapshot(receipt, config2.fields);
11546
11678
  return {
11547
11679
  type: "linkque.presentation-tool-result",
11548
11680
  modelText: formatPresentationReceiptForModel(receipt),
@@ -11562,11 +11694,23 @@ function createPresentationResult(resource, config2, viewModel) {
11562
11694
  function formatPresentationReceiptForModel(receipt) {
11563
11695
  return [
11564
11696
  "<a2ui-presentation-receipt>",
11565
- JSON.stringify(receipt),
11697
+ JSON.stringify(projectPresentationReceiptForModel(receipt)),
11566
11698
  "</a2ui-presentation-receipt>",
11567
- "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."
11699
+ "\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"
11568
11700
  ].join("\n");
11569
11701
  }
11702
+ function projectPresentationReceiptForModel(receipt) {
11703
+ if (!receipt.semanticSnapshot)
11704
+ return receipt;
11705
+ return {
11706
+ version: receipt.version,
11707
+ cardRef: receipt.cardRef,
11708
+ cardRevision: receipt.cardRevision,
11709
+ cardInstanceId: receipt.cardInstanceId,
11710
+ status: receipt.status,
11711
+ semanticSnapshot: receipt.semanticSnapshot
11712
+ };
11713
+ }
11570
11714
  function parseCardConfig(resource) {
11571
11715
  const parsed = parseA2UICardResourceConfig(resource.config);
11572
11716
  if (!parsed.success) {
@@ -11620,9 +11764,9 @@ function collectA2UISurfaceIdsForLegacyContract(protocol) {
11620
11764
  function createPresentationDescription(config2) {
11621
11765
  return [
11622
11766
  config2.description,
11623
- `Use this card when: ${config2.whenToUse}`,
11624
- ...config2.whenNotToUse ? [`Do not use this card when: ${config2.whenNotToUse}`] : [],
11625
- "Provide only the declared identifier/filter arguments. Authoritative business values are resolved by the platform."
11767
+ `\u9002\u7528\u573A\u666F\uFF1A${config2.whenToUse}`,
11768
+ ...config2.whenNotToUse ? [`\u4E0D\u9002\u7528\u573A\u666F\uFF1A${config2.whenNotToUse}`] : [],
11769
+ "\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"
11626
11770
  ].join("\n");
11627
11771
  }
11628
11772
  function cloneJsonObject2(value, label) {
@@ -11696,6 +11840,7 @@ var init_cardTools = __esm({
11696
11840
  import_node_crypto2 = require("node:crypto");
11697
11841
  init_esm3();
11698
11842
  init_mcpNaming();
11843
+ init_cardSemanticSnapshot();
11699
11844
  FALLBACK_OBJECT_SCHEMA = {
11700
11845
  type: "object",
11701
11846
  additionalProperties: true
@@ -11896,7 +12041,11 @@ var init_mcpProxyTool = __esm({
11896
12041
  return;
11897
12042
  try {
11898
12043
  await entry.server.close?.();
11899
- } catch {
12044
+ } catch (error40) {
12045
+ try {
12046
+ this.debugLog(`[mcp] server ${entry.server.serverName} close failed: ${error40 instanceof Error ? error40.message : "unknown error"}`, EDebugLogScope.MCP);
12047
+ } catch {
12048
+ }
11900
12049
  }
11901
12050
  }));
11902
12051
  }
@@ -12481,13 +12630,26 @@ var init_hookRegistry = __esm({
12481
12630
  }
12482
12631
  });
12483
12632
 
12633
+ // ../linkque-agent-runtime/dist/esm/core/logFailure.js
12634
+ function warnLogFailure(stage, error40) {
12635
+ (0, import_node_process.emitWarning)(`[${stage}] errorType=${error40 instanceof Error ? error40.name : typeof error40}`, { code: "LINKQUE_RUNTIME_DIAGNOSTIC_FAILURE" });
12636
+ }
12637
+ var import_node_process;
12638
+ var init_logFailure = __esm({
12639
+ "../linkque-agent-runtime/dist/esm/core/logFailure.js"() {
12640
+ "use strict";
12641
+ import_node_process = require("node:process");
12642
+ }
12643
+ });
12644
+
12484
12645
  // ../linkque-agent-runtime/dist/esm/core/hook/hookLog.js
12485
12646
  function writeHookLog(debugLog, record3) {
12486
12647
  if (!debugLog)
12487
12648
  return;
12488
12649
  try {
12489
12650
  debugLog(JSON.stringify(redactHookLogRecord(record3)), EDebugLogScope.HOOK);
12490
- } catch {
12651
+ } catch (error40) {
12652
+ warnLogFailure("writeHookLog", error40);
12491
12653
  }
12492
12654
  }
12493
12655
  function redactHookLogRecord(record3) {
@@ -12507,6 +12669,7 @@ var HOOK_LOG_MESSAGE_MAX_LENGTH;
12507
12669
  var init_hookLog = __esm({
12508
12670
  "../linkque-agent-runtime/dist/esm/core/hook/hookLog.js"() {
12509
12671
  "use strict";
12672
+ init_logFailure();
12510
12673
  init_types();
12511
12674
  HOOK_LOG_MESSAGE_MAX_LENGTH = 200;
12512
12675
  }
@@ -12708,6 +12871,15 @@ var init_hookDispatcher = __esm({
12708
12871
  stage: EHookStage.RUN_READ,
12709
12872
  read: { readAt: subject.readAt ?? now() }
12710
12873
  };
12874
+ case EHookStage.MODEL_RESPONSE_RECEIVED: {
12875
+ if (!subject.model)
12876
+ throw new Error("MODEL_RESPONSE_RECEIVED Hook \u7F3A\u5C11\u54CD\u5E94\u4E0A\u4E0B\u6587");
12877
+ return {
12878
+ ...base,
12879
+ stage: EHookStage.MODEL_RESPONSE_RECEIVED,
12880
+ model: subject.model
12881
+ };
12882
+ }
12711
12883
  case EHookStage.AFTER_MODEL_CALL: {
12712
12884
  if (!subject.model || subject.model.messageContent === void 0) {
12713
12885
  throw new Error("AFTER_MODEL_CALL Hook \u7F3A\u5C11\u5B8C\u6574 model context");
@@ -13272,7 +13444,8 @@ function redactHeaders(headers) {
13272
13444
  pairs.push(`${key}=${redactHeader(key, value)}`);
13273
13445
  }
13274
13446
  }
13275
- } catch {
13447
+ } catch (error40) {
13448
+ warnLogFailure("httpLoggingFetch.redactHeaders", error40);
13276
13449
  }
13277
13450
  return pairs.join(",");
13278
13451
  }
@@ -13309,7 +13482,8 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
13309
13482
  const cl = resp.headers.get("content-length");
13310
13483
  if (cl)
13311
13484
  len = cl;
13312
- } catch {
13485
+ } catch (error40) {
13486
+ warnLogFailure("httpLoggingFetch.contentLength", error40);
13313
13487
  }
13314
13488
  const correlation = readResponseCorrelationId(resp.headers);
13315
13489
  const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
@@ -13338,14 +13512,16 @@ function readResponseCorrelationId(headers) {
13338
13512
  };
13339
13513
  });
13340
13514
  return matched;
13341
- } catch {
13515
+ } catch (error40) {
13516
+ warnLogFailure("httpLoggingFetch.responseCorrelationId", error40);
13342
13517
  }
13343
13518
  return void 0;
13344
13519
  }
13345
13520
  function safeLog(debugLog, line) {
13346
13521
  try {
13347
13522
  debugLog(line, EDebugLogScope.HTTP);
13348
- } catch {
13523
+ } catch (error40) {
13524
+ warnLogFailure("httpLoggingFetch.safeLog", error40);
13349
13525
  }
13350
13526
  }
13351
13527
  function nowMs() {
@@ -13360,6 +13536,7 @@ var init_httpLoggingFetch = __esm({
13360
13536
  "../linkque-agent-runtime/dist/esm/impl/httpLoggingFetch.js"() {
13361
13537
  "use strict";
13362
13538
  init_types();
13539
+ init_logFailure();
13363
13540
  MAX_BODY_SUMMARY_LEN = 2e3;
13364
13541
  REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
13365
13542
  "authorization",
@@ -32940,9 +33117,9 @@ function encodeUTF8(str2) {
32940
33117
  let encoder2;
32941
33118
  return (encodeUTF8_ ?? (encoder2 = new globalThis.TextEncoder(), encodeUTF8_ = encoder2.encode.bind(encoder2)))(str2);
32942
33119
  }
32943
- function decodeUTF8(bytes) {
33120
+ function decodeUTF8(bytes2) {
32944
33121
  let decoder;
32945
- return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_ = decoder.decode.bind(decoder)))(bytes);
33122
+ return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_ = decoder.decode.bind(decoder)))(bytes2);
32946
33123
  }
32947
33124
  var encodeUTF8_, decodeUTF8_;
32948
33125
  var init_bytes = __esm({
@@ -33322,8 +33499,8 @@ var init_streaming = __esm({
33322
33499
  const { value, done } = await iter.next();
33323
33500
  if (done)
33324
33501
  return ctrl.close();
33325
- const bytes = encodeUTF8(JSON.stringify(value) + "\n");
33326
- ctrl.enqueue(bytes);
33502
+ const bytes2 = encodeUTF8(JSON.stringify(value) + "\n");
33503
+ ctrl.enqueue(bytes2);
33327
33504
  } catch (err3) {
33328
33505
  ctrl.error(err3);
33329
33506
  }
@@ -42371,9 +42548,9 @@ function encodeUTF82(str2) {
42371
42548
  let encoder2;
42372
42549
  return (encodeUTF8_2 ?? (encoder2 = new globalThis.TextEncoder(), encodeUTF8_2 = encoder2.encode.bind(encoder2)))(str2);
42373
42550
  }
42374
- function decodeUTF82(bytes) {
42551
+ function decodeUTF82(bytes2) {
42375
42552
  let decoder;
42376
- return (decodeUTF8_2 ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_2 = decoder.decode.bind(decoder)))(bytes);
42553
+ return (decodeUTF8_2 ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_2 = decoder.decode.bind(decoder)))(bytes2);
42377
42554
  }
42378
42555
  var encodeUTF8_2, decodeUTF8_2;
42379
42556
  var init_bytes2 = __esm({
@@ -42759,8 +42936,8 @@ var init_streaming3 = __esm({
42759
42936
  const { value, done } = await iter.next();
42760
42937
  if (done)
42761
42938
  return ctrl.close();
42762
- const bytes = encodeUTF82(JSON.stringify(value) + "\n");
42763
- ctrl.enqueue(bytes);
42939
+ const bytes2 = encodeUTF82(JSON.stringify(value) + "\n");
42940
+ ctrl.enqueue(bytes2);
42764
42941
  } catch (err3) {
42765
42942
  ctrl.error(err3);
42766
42943
  }
@@ -45477,11 +45654,11 @@ var init_base64 = __esm({
45477
45654
  } else {
45478
45655
  const binaryStr = atob(base64Str);
45479
45656
  const len = binaryStr.length;
45480
- const bytes = new Uint8Array(len);
45657
+ const bytes2 = new Uint8Array(len);
45481
45658
  for (let i2 = 0; i2 < len; i2++) {
45482
- bytes[i2] = binaryStr.charCodeAt(i2);
45659
+ bytes2[i2] = binaryStr.charCodeAt(i2);
45483
45660
  }
45484
- return Array.from(new Float32Array(bytes.buffer));
45661
+ return Array.from(new Float32Array(bytes2.buffer));
45485
45662
  }
45486
45663
  };
45487
45664
  }
@@ -56695,14 +56872,14 @@ var require_streams = __commonJS({
56695
56872
  if (!globalThis.ReadableStream) {
56696
56873
  try {
56697
56874
  const process2 = require("node:process");
56698
- const { emitWarning } = process2;
56875
+ const { emitWarning: emitWarning2 } = process2;
56699
56876
  try {
56700
56877
  process2.emitWarning = () => {
56701
56878
  };
56702
56879
  Object.assign(globalThis, require("node:stream/web"));
56703
- process2.emitWarning = emitWarning;
56880
+ process2.emitWarning = emitWarning2;
56704
56881
  } catch (error40) {
56705
- process2.emitWarning = emitWarning;
56882
+ process2.emitWarning = emitWarning2;
56706
56883
  throw error40;
56707
56884
  }
56708
56885
  } catch (error40) {
@@ -82258,9 +82435,9 @@ function encodeUTF83(str2) {
82258
82435
  let encoder2;
82259
82436
  return (encodeUTF8_3 !== null && encodeUTF8_3 !== void 0 ? encodeUTF8_3 : (encoder2 = new globalThis.TextEncoder(), encodeUTF8_3 = encoder2.encode.bind(encoder2)))(str2);
82260
82437
  }
82261
- function decodeUTF83(bytes) {
82438
+ function decodeUTF83(bytes2) {
82262
82439
  let decoder;
82263
- return (decodeUTF8_3 !== null && decodeUTF8_3 !== void 0 ? decodeUTF8_3 : (decoder = new globalThis.TextDecoder(), decodeUTF8_3 = decoder.decode.bind(decoder)))(bytes);
82440
+ return (decodeUTF8_3 !== null && decodeUTF8_3 !== void 0 ? decodeUTF8_3 : (decoder = new globalThis.TextDecoder(), decodeUTF8_3 = decoder.decode.bind(decoder)))(bytes2);
82264
82441
  }
82265
82442
  function findNewlineIndex3(buffer, startIndex) {
82266
82443
  const newline = 10;
@@ -89420,8 +89597,8 @@ ${underline}`);
89420
89597
  const { value, done } = await iter.next();
89421
89598
  if (done)
89422
89599
  return ctrl.close();
89423
- const bytes = encodeUTF83(JSON.stringify(value) + "\n");
89424
- ctrl.enqueue(bytes);
89600
+ const bytes2 = encodeUTF83(JSON.stringify(value) + "\n");
89601
+ ctrl.enqueue(bytes2);
89425
89602
  } catch (err3) {
89426
89603
  ctrl.error(err3);
89427
89604
  }
@@ -189374,7 +189551,8 @@ async function createAgentSession(options) {
189374
189551
  onDelay: (delayMs) => {
189375
189552
  try {
189376
189553
  options.debugLog?.(`[llm-throttle] wait ${delayMs}ms before next request`, EDebugLogScope.LLM);
189377
- } catch {
189554
+ } catch (error40) {
189555
+ warnLogFailure("createAgentSession.throttleLog", error40);
189378
189556
  }
189379
189557
  }
189380
189558
  });
@@ -189407,7 +189585,8 @@ async function createAgentSession(options) {
189407
189585
  await prevOnPayload?.(payload, m2);
189408
189586
  try {
189409
189587
  logSink(formatHttpLogLine("llm", "req", `POST ${baseUrl} model=${m2.id} payload=${summarizeBody(safeStringifyPayload(payload))}`), EDebugLogScope.LLM);
189410
- } catch {
189588
+ } catch (error40) {
189589
+ warnLogFailure("createAgentSession.requestLog", error40);
189411
189590
  }
189412
189591
  };
189413
189592
  }
@@ -189424,6 +189603,7 @@ async function createAgentSession(options) {
189424
189603
  responseHeaders: response.headers
189425
189604
  }
189426
189605
  };
189606
+ await options.hookRuntime.dispatcher.dispatch(EHookStage.MODEL_RESPONSE_RECEIVED, options.hookRuntime.commonParams, subject);
189427
189607
  if (options.hookRuntime.dispatcher.hasMatchingResource(EHookStage.AFTER_MODEL_CALL, subject)) {
189428
189608
  gateState = { subject };
189429
189609
  }
@@ -189432,7 +189612,8 @@ async function createAgentSession(options) {
189432
189612
  try {
189433
189613
  const baseUrl = model.baseUrl ?? "<unknown>";
189434
189614
  logSink(formatHttpLogLine("llm", "resp", `POST ${baseUrl} model=${m2.id} ${response.status} headers=${redactHeaders(response.headers)}`), EDebugLogScope.LLM);
189435
- } catch {
189615
+ } catch (error40) {
189616
+ warnLogFailure("createAgentSession.responseLog", error40);
189436
189617
  }
189437
189618
  }
189438
189619
  };
@@ -189459,7 +189640,8 @@ async function createAgentSession(options) {
189459
189640
  try {
189460
189641
  agent.abort();
189461
189642
  agent.reset();
189462
- } catch {
189643
+ } catch (error40) {
189644
+ warnLogFailure("createAgentSession.dispose", error40);
189463
189645
  }
189464
189646
  }
189465
189647
  }
@@ -189512,7 +189694,8 @@ function serializeToolResult2(value) {
189512
189694
  try {
189513
189695
  const serialized = JSON.stringify(value);
189514
189696
  return serialized === void 0 ? "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002" : serialized;
189515
- } catch {
189697
+ } catch (error40) {
189698
+ warnLogFailure("createAgentSession.toolResultSerialization", error40);
189516
189699
  return "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002";
189517
189700
  }
189518
189701
  }
@@ -189523,13 +189706,15 @@ function safeStringifyPayload(payload) {
189523
189706
  return payload;
189524
189707
  try {
189525
189708
  return JSON.stringify(payload) ?? "";
189526
- } catch {
189709
+ } catch (error40) {
189710
+ warnLogFailure("createAgentSession.payloadSerialization", error40);
189527
189711
  return "<unserializable>";
189528
189712
  }
189529
189713
  }
189530
189714
  var init_createAgentSession = __esm({
189531
189715
  "../linkque-agent-runtime/dist/esm/impl/agent/pi/createAgentSession.js"() {
189532
189716
  "use strict";
189717
+ init_logFailure();
189533
189718
  init_dist4();
189534
189719
  init_dist3();
189535
189720
  init_esm();
@@ -190126,6 +190311,10 @@ var init_followUpQuestionGenerator = __esm({
190126
190311
  FOLLOW_UP_QUESTION_TOOL_NAME = "submit_follow_up_questions";
190127
190312
  FOLLOW_UP_QUESTION_TIMEOUT_MS = 4500;
190128
190313
  SYSTEM_PROMPT = `\u6839\u636E\u5BF9\u8BDD\u8C03\u7528 submit_follow_up_questions\uFF0C\u63D0\u4EA4\u7528\u6237\u63A5\u4E0B\u6765\u53EF\u80FD\u63D0\u51FA\u7684\u8FFD\u95EE\uFF1A
190314
+ - \u8FD9\u4E9B\u5EFA\u8BAE\u70B9\u51FB\u540E\u4F1A\u76F4\u63A5\u4F5C\u4E3A\u4E0B\u4E00\u6761\u7528\u6237\u6D88\u606F\u53D1\u9001\u3002\u7AD9\u5728\u5F53\u524D\u6D88\u8D39\u8005/\u670D\u52A1\u4F7F\u7528\u8005\u7684\u89C6\u89D2\u5411\u52A9\u624B\u63D0\u95EE\uFF0C\u4E0D\u8981\u66FF\u5546\u6237\u3001\u5BA2\u670D\u6216\u52A9\u624B\u5411\u7528\u6237\u53D1\u95EE\u3002
190315
+ - \u4FDD\u6301\u5F53\u524D\u7528\u6237\u7684\u8EAB\u4EFD\u548C\u610F\u56FE\uFF1B\u53EA\u6709\u7528\u6237\u660E\u786E\u4EE5\u5546\u6237\u8EAB\u4EFD\u54A8\u8BE2\u7ECF\u8425\u95EE\u9898\u65F6\uFF0C\u624D\u6CBF\u7528\u8BE5\u8EAB\u4EFD\u3002\u4E0D\u8981\u56E0\u4E3A\u52A9\u624B\u7684\u63AA\u8F9E\u6539\u53D8\u7528\u6237\u89D2\u8272\u3002
190316
+ - \u4F8B\u5982\u8D2D\u7968\u573A\u666F\u53EF\u95EE\u201C\u53EF\u4EE5\u9884\u7EA6\u8BB2\u89E3\u670D\u52A1\u5417\uFF1F\u201D\u6216\u201C\u513F\u7AE5\u7968\u600E\u4E48\u4E70\uFF1F\u201D\uFF0C\u4E0D\u8981\u5199\u201C\u9700\u8981\u9884\u7EA6\u8BB2\u89E3\u670D\u52A1\u5417\uFF1F\u201D\u201C\u8BF7\u63D0\u4F9B\u6BCF\u4F4D\u5165\u56ED\u4EBA\u7684\u8EAB\u4EFD\u8BC1\u4FE1\u606F\u201D\u3002
190317
+ - \u52A9\u624B\u6B63\u5728\u8BE2\u95EE\u4EBA\u6570\u3001\u65E5\u671F\u3001\u9884\u7B97\u7B49\u4FE1\u606F\u65F6\uFF0C\u4E0D\u8981\u91CD\u590D\u5B83\u7684\u53CD\u95EE\uFF0C\u4E0D\u8981\u7F16\u9020\u7528\u6237\u5C1A\u672A\u63D0\u4F9B\u7684\u7B54\u6848\u6216\u66FF\u7528\u6237\u627F\u8BFA\u4E0B\u5355\u3001\u652F\u4ED8\uFF1B\u53EF\u5EFA\u8BAE\u76F8\u5173\u89C4\u5219\u95EE\u9898\uFF0C\u6CA1\u6709\u5408\u9002\u95EE\u9898\u5C31\u7559\u7A7A\u3002
190129
190318
  - 0\uFF5E3 \u6761\uFF0C\u81EA\u7136\u3001\u76F8\u5173\u3001\u4E0D\u91CD\u590D\uFF1B\u6CA1\u6709\u5408\u9002\u8FFD\u95EE\u65F6\u63D0\u4EA4\u7A7A\u6570\u7EC4\u3002
190130
190319
  - \u8DDF\u968F\u6700\u540E\u4E00\u6761\u7528\u6237\u6D88\u606F\u7684\u8BED\u8A00\uFF0C\u6BCF\u6761 JavaScript \u5B57\u7B26\u4E32\u957F\u5EA6\u4E3A 1\uFF5E20\u3002
190131
190320
  - \u5386\u53F2\u8FFD\u95EE\u662F\u7CFB\u7EDF\u66FE\u751F\u6210\u7684\u5EFA\u8BAE\uFF0C\u4E0D\u662F\u7528\u6237\u8BF4\u8FC7\u7684\u8BDD\uFF1B\u4EC5\u7528\u4E8E\u7406\u89E3\u8BDD\u9898\u548C\u907F\u514D\u91CD\u590D\u3002
@@ -190164,8 +190353,10 @@ var init_followUpQuestionGenerator = __esm({
190164
190353
  tools: [
190165
190354
  {
190166
190355
  name: FOLLOW_UP_QUESTION_TOOL_NAME,
190167
- description: "\u63D0\u4EA4\u6700\u7EC8\u8FFD\u95EE\u5217\u8868\u3002",
190168
- parameters: typebox_exports.Object({ questions: typebox_exports.Array(typebox_exports.String(), { maxItems: 3 }) }, { additionalProperties: false })
190356
+ description: "\u63D0\u4EA4\u5F53\u524D\u7528\u6237\u63A5\u4E0B\u6765\u5411\u52A9\u624B\u63D0\u51FA\u7684\u95EE\u9898\uFF0C\u9ED8\u8BA4\u91C7\u7528\u6D88\u8D39\u8005\u89C6\u89D2\uFF1B\u70B9\u51FB\u540E\u4F5C\u4E3A\u7528\u6237\u6D88\u606F\u53D1\u9001\uFF0C\u4E0D\u80FD\u662F\u5BA2\u670D\u5411\u6D88\u8D39\u8005\u7684\u53CD\u95EE\u6216\u8D44\u6599\u7D22\u53D6\u3002",
190357
+ parameters: typebox_exports.Object({
190358
+ questions: typebox_exports.Array(typebox_exports.String({ minLength: 1, maxLength: 20 }), { maxItems: 3 })
190359
+ }, { additionalProperties: false })
190169
190360
  }
190170
190361
  ]
190171
190362
  };
@@ -190341,18 +190532,39 @@ var init_pi = __esm({
190341
190532
  });
190342
190533
 
190343
190534
  // ../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js
190535
+ function readAfterCard(args) {
190536
+ if (!args || typeof args !== "object")
190537
+ return void 0;
190538
+ const mode = args.responseMode;
190539
+ if (Object.hasOwn(args, "responseMode") && !["card_only", "supplement", "user_requested_text"].includes(mode))
190540
+ throw new Error("responseMode \u65E0\u6548\uFF0C\u8BF7\u9009\u62E9\u5DF2\u58F0\u660E\u7684\u6A21\u5F0F");
190541
+ if (!Object.hasOwn(args, "afterCard")) {
190542
+ if (mode !== void 0)
190543
+ throw new Error("\u6307\u5B9A responseMode \u65F6\u5FC5\u987B\u63D0\u4F9B afterCard");
190544
+ return void 0;
190545
+ }
190546
+ const value = args.afterCard;
190547
+ if (typeof value !== "string" || value.length > 16e3)
190548
+ throw new Error("afterCard \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7 16000");
190549
+ if (mode === "card_only" && value.trim() !== "")
190550
+ throw new Error("card_only \u6A21\u5F0F\u4E0B afterCard \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF1B\u5361\u7247\u5DF2\u7ECF\u56DE\u7B54\u4E86\u67E5\u8BE2");
190551
+ return value.trim();
190552
+ }
190344
190553
  function createCardSourceToolName(resourceId, sourceId) {
190345
190554
  return stableToolName("card_source", `${resourceId}_${sourceId}`);
190346
190555
  }
190347
190556
  function createCardFinishToolName(resourceId) {
190348
190557
  return stableToolName("card_finish", resourceId);
190349
190558
  }
190350
- var CardRenderMcpServer;
190559
+ var CARD_SEQUENCE, AFTER_CARD_DESCRIPTION, RESPONSE_MODE_DESCRIPTION, CardRenderMcpServer;
190351
190560
  var init_cardRenderMcpServer = __esm({
190352
190561
  "../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js"() {
190353
190562
  "use strict";
190354
190563
  init_cardTools();
190355
190564
  init_mcpNaming();
190565
+ CARD_SEQUENCE = "\u540C\u4E00\u65F6\u95F4\u53EA\u80FD\u5236\u4F5C\u4E00\u5F20\u5361\u7247\uFF1A\u5148\u5B8C\u6210\u5F53\u524D\u5361\u7247\u7684\u9009\u62E9 \u2192 \u6570\u636E\u6E90\u8C03\u7528 \u2192 \u5C55\u793A\uFF0C\u518D\u9009\u62E9\u4E0B\u4E00\u5F20\u5361\u7247\u3002\u4E0D\u8981\u4EA4\u53C9\u8C03\u7528\u4E0D\u540C\u672A\u5B8C\u6210\u5361\u7247\u7684\u5DE5\u5177\u3002";
190566
+ AFTER_CARD_DESCRIPTION = "\u968F\u5361\u7247\u4E00\u8D77\u5C55\u793A\u7684\u6587\u5B57\u3002card_only \u5FC5\u987B\u4E3A\u7A7A\u5B57\u7B26\u4E32\u3002supplement \u53EA\u5B8C\u6210\u5269\u4F59\u95EE\u9898\uFF0C\u76F4\u63A5\u7ED9\u7ED3\u8BBA\uFF0C\u4E0D\u5148\u6982\u8FF0\u5404\u4E2A\u5019\u9009\uFF1A\u4EF7\u683C\u603B\u7ED3\u5E94\u8BF4\u8303\u56F4/\u96C6\u4E2D\u533A\u95F4/\u53D6\u820D\uFF0C\u4E0D\u6309\u9152\u5E97\u5206\u522B\u5199\u8BC4\u4EF7\uFF1B\u8FFD\u95EE\u53EA\u95EE\u6240\u9700\u6761\u4EF6\uFF0C\u4E0D\u5148\u4ECB\u7ECD\u5168\u90E8\u9152\u5E97\uFF1B\u9009\u4E00\u5BB6\u53EA\u7ED9\u8BE5\u9879\u53CA\u7406\u7531\u3002\u5141\u8BB8\u5FC5\u8981\u5F15\u7528\u4E2A\u522B\u540D\u79F0\u6570\u503C\u3002\u4E0D\u8981\u4ECE\u8BC4\u5206\u63A8\u65AD\u536B\u751F\u3001\u4ECE\u8FD1\u5730\u94C1\u63A8\u65AD\u7279\u5B9A\u666F\u70B9\u4FBF\u5229\u6027\uFF0C\u672A\u77E5\u4FDD\u6301\u672A\u77E5\u3002user_requested_text \u53EF\u63D0\u4F9B\u7528\u6237\u660E\u786E\u8981\u6C42\u7684\u5B8C\u6574\u6587\u5B57/\u8868\u683C\u3002\u591A\u5361\u7247\u65F6\u586B\u5199\u7D27\u63A5\u5F53\u524D\u5361\u7247\u7684\u8BF4\u660E\uFF0C\u7136\u540E\u7EE7\u7EED\u8C03\u7528\u4E0B\u4E00\u5F20\u5361\u7247\u5DE5\u5177\u3002\u6B64\u5904\u6587\u5B57\u4F1A\u76F4\u63A5\u5C55\u793A\uFF0Cfinish \u6210\u529F\u540E\u4E0D\u8981\u53E6\u5199\u4E00\u904D\uFF1B\u5361\u7247\u5931\u8D25\u65F6\u4ECD\u53EF\u6B63\u5E38\u6587\u5B57\u56DE\u7B54\u3002";
190567
+ RESPONSE_MODE_DESCRIPTION = "\u6309\u7528\u6237\u4EFB\u52A1\u9009\u62E9\uFF1Acard_only=\u67E5\u8BE2/\u5C55\u793A\u7ED3\u679C/\u6CDB\u6CDB\u63A8\u8350\u5019\u9009\uFF0C\u5361\u7247\u5DF2\u7ECF\u5B8C\u6210\u4EFB\u52A1\uFF0C\u4E0D\u4E3B\u52A8\u65B0\u589E\u89E3\u91CA\u6216\u8FFD\u95EE\uFF1Bsupplement=\u7528\u6237\u8FD8\u8981\u6C42\u9009\u4E00\u5BB6\u53CA\u7406\u7531\u3001\u603B\u7ED3\u53D6\u820D\u3001\u8865\u5145\u653F\u7B56\u3001\u9884\u8BA2\u6240\u9700\u4FE1\u606F\uFF0C\u6216\u67E5\u8BE2\u4E3A\u7A7A\u9700\u8BF4\u660E\uFF1Buser_requested_text=\u7528\u6237\u660E\u786E\u8981\u6C42\u53E6\u7ED9\u6587\u5B57/\u53EF\u590D\u5236\u8868\u683C\u3002\u793A\u4F8B\uFF1A\u201C\u63A8\u8350\u676D\u5DDE\u9152\u5E97\u201D\u2192card_only\uFF1B\u201C\u63A8\u8350\u676D\u5DDE\u9152\u5E97\uFF0C\u9009\u4E00\u5BB6\u9002\u5408\u5E26\u5B69\u5B50\u7684\u201D\u2192supplement\uFF1B\u201C\u65E2\u8981\u5361\u7247\u4E5F\u8981\u5B8C\u6574\u8868\u683C\u201D\u2192user_requested_text\u3002";
190356
190568
  CardRenderMcpServer = class {
190357
190569
  resources;
190358
190570
  registry;
@@ -190374,6 +190586,8 @@ var init_cardRenderMcpServer = __esm({
190374
190586
  toolByName = /* @__PURE__ */ new Map();
190375
190587
  activeCardId;
190376
190588
  invalidCards = [];
190589
+ /** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
190590
+ companions = /* @__PURE__ */ new WeakMap();
190377
190591
  /** 本轮被隔离的坏卡,仅供宿主诊断,不影响其它卡片注册。 */
190378
190592
  getInvalidCards() {
190379
190593
  return this.invalidCards;
@@ -190414,7 +190628,7 @@ var init_cardRenderMcpServer = __esm({
190414
190628
  resourceId: resource.resourceId,
190415
190629
  label: config2.displayName,
190416
190630
  description: `${createPresentationDescription(config2)}
190417
- Select this card first, then call its card_source tools and card_finish tool.`,
190631
+ \u5148\u9009\u62E9\u6B64\u5361\u7247\uFF0C\u518D\u4F9D\u6B21\u8C03\u7528\u5B83\u7684 card_source \u6570\u636E\u6E90\u5DE5\u5177\u548C card_finish \u5C55\u793A\u5DE5\u5177\u3002${CARD_SEQUENCE}`,
190418
190632
  inputSchema: {
190419
190633
  type: "object",
190420
190634
  properties: {},
@@ -190453,18 +190667,18 @@ Select this card first, then call its card_source tools and card_finish tool.`,
190453
190667
  modelName: sourceToolName,
190454
190668
  resourceId: resource.resourceId,
190455
190669
  label: source.purpose,
190456
- description: `Use after selecting ${name}. ${source.purpose}. Choose all MCP arguments from the conversation and prior source results.`,
190670
+ 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}`,
190457
190671
  inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
190458
190672
  outputSchema: discoveredHandle?.outputSchema ?? source.outputSchema,
190459
190673
  execute: async (args, signal) => {
190460
190674
  if (!state2.selected || this.activeCardId !== resource.resourceId)
190461
- throw new Error(`Select card ${name} before calling its data sources`);
190675
+ throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
190462
190676
  const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
190463
190677
  if (missingDependencies.length)
190464
- throw new Error(`Data source ${source.sourceId} is waiting for: ${missingDependencies.join(", ")}`);
190678
+ throw new Error(`\u6570\u636E\u6E90 ${source.sourceId} \u9700\u8981\u5148\u5B8C\u6210\u4EE5\u4E0B\u4F9D\u8D56\uFF1A${missingDependencies.join(", ")}`);
190465
190679
  const handle = discoveredHandle ?? await this.registry.resolve(source.mcpResourceId, source.toolName, signal);
190466
190680
  if (!handle)
190467
- throw new Error(`MCP tool ${source.mcpResourceId}/${source.toolName} is unavailable`);
190681
+ throw new Error(`MCP \u5DE5\u5177 ${source.mcpResourceId}/${source.toolName} \u5F53\u524D\u4E0D\u53EF\u7528`);
190468
190682
  const result = await handle.execute(args, signal);
190469
190683
  const structured = readStructuredContent(result);
190470
190684
  if (structured === void 0) {
@@ -190491,16 +190705,36 @@ Select this card first, then call its card_source tools and card_finish tool.`,
190491
190705
  modelName: finishName,
190492
190706
  resourceId: resource.resourceId,
190493
190707
  label: `\u5C55\u793A${config2.displayName}`,
190494
- description: `Finish and render ${config2.displayName} after all required card_source tools succeed.`,
190708
+ description: `\u6240\u6709\u5FC5\u9700\u7684 card_source \u6570\u636E\u6E90\u5DE5\u5177\u6210\u529F\u540E\uFF0C\u5B8C\u6210\u5E76\u5C55\u793A${config2.displayName}\u3002${CARD_SEQUENCE}
190709
+ ${AFTER_CARD_DESCRIPTION}`,
190495
190710
  inputSchema: {
190496
190711
  type: "object",
190497
- properties: {},
190712
+ required: ["responseMode", "afterCard"],
190713
+ properties: {
190714
+ responseMode: {
190715
+ type: "string",
190716
+ enum: ["card_only", "supplement", "user_requested_text"],
190717
+ description: RESPONSE_MODE_DESCRIPTION
190718
+ },
190719
+ afterCard: {
190720
+ type: "string",
190721
+ maxLength: 16e3,
190722
+ description: AFTER_CARD_DESCRIPTION
190723
+ }
190724
+ },
190498
190725
  additionalProperties: false
190499
190726
  },
190500
- execute: async (_args, signal) => {
190727
+ execute: async (args, signal) => {
190501
190728
  if (!state2.selected || this.activeCardId !== resource.resourceId)
190502
- throw new Error(`Select card ${name} before finishing it`);
190729
+ throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
190730
+ const afterCard = readAfterCard(args);
190503
190731
  const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
190732
+ if (afterCard !== void 0) {
190733
+ this.companions.set(result, afterCard);
190734
+ result.modelText += `
190735
+ <a2ui-companion-delivery>${JSON.stringify({ afterCard })}</a2ui-companion-delivery>
190736
+ \u5361\u7247\u548C\u4E0A\u8FF0\u4F34\u968F\u6587\u5B57\u5DF2\u4F5C\u4E3A\u56DE\u7B54\u53D1\u51FA\u3002\u65E0\u9700\u518D\u6B21\u8F93\u51FA\u6587\u5B57\uFF1B\u82E5\u8FD8\u6709\u5176\u4ED6\u4EFB\u52A1\uFF0C\u7EE7\u7EED\u8C03\u7528\u5DE5\u5177\u3002`;
190737
+ }
190504
190738
  state2.selected = false;
190505
190739
  this.activeCardId = void 0;
190506
190740
  return result;
@@ -190531,6 +190765,32 @@ Select this card first, then call its card_source tools and card_finish tool.`,
190531
190765
  this.activeCardId = void 0;
190532
190766
  this.states.clear();
190533
190767
  this.toolByName.clear();
190768
+ this.companions = /* @__PURE__ */ new WeakMap();
190769
+ }
190770
+ /** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
190771
+ async *projectConversation(events) {
190772
+ const pending = /* @__PURE__ */ new WeakMap();
190773
+ let cardOwnsText = false;
190774
+ for await (const event of events) {
190775
+ if (event.type === "tool_start" || event.type === "error" || event.type === "done")
190776
+ cardOwnsText = false;
190777
+ if (event.type === "tool_end" && !event.isError) {
190778
+ const details = event.result && typeof event.result === "object" && "details" in event.result ? event.result.details : void 0;
190779
+ if (details && this.companions.has(details)) {
190780
+ pending.set(details.card, this.companions.get(details));
190781
+ }
190782
+ }
190783
+ if (event.type === "delta" && cardOwnsText)
190784
+ continue;
190785
+ yield event;
190786
+ if (event.type === "a2ui_card" && pending.has(event)) {
190787
+ const text2 = pending.get(event);
190788
+ pending.delete(event);
190789
+ cardOwnsText = true;
190790
+ if (text2)
190791
+ yield { type: "delta", content: text2 };
190792
+ }
190793
+ }
190534
190794
  }
190535
190795
  };
190536
190796
  }
@@ -191176,7 +191436,7 @@ var init_agentRuntime = __esm({
191176
191436
  });
191177
191437
  };
191178
191438
  try {
191179
- for await (const ev of this.agentLoop.run(agentReq)) {
191439
+ for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
191180
191440
  if (ev.type === "delta")
191181
191441
  assistantText += ev.content;
191182
191442
  if (ev.type === "tool_end" && !ev.isError) {
@@ -191196,7 +191456,10 @@ var init_agentRuntime = __esm({
191196
191456
  ...presentationReceipts.map((receipt) => ({
191197
191457
  role: "tool",
191198
191458
  name: "a2ui_presentation_receipt",
191199
- content: { type: "a2ui.presentation-receipt", receipt }
191459
+ content: {
191460
+ type: "a2ui.presentation-receipt",
191461
+ receipt: projectPresentationReceiptForModel(receipt)
191462
+ }
191200
191463
  })),
191201
191464
  { role: "assistant", content: assistantText }
191202
191465
  ];
@@ -191401,16 +191664,16 @@ async function boundedBody(response, max2) {
191401
191664
  }
191402
191665
  }
191403
191666
  function validate(data, mediaType) {
191404
- if (data.length > Math.ceil(MAX_BYTES / 3) * 4)
191667
+ if (data.length > Math.ceil(MAX_BYTES2 / 3) * 4)
191405
191668
  imageError("IMAGE_TOO_LARGE");
191406
- if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data))
191669
+ if (data.length % 4 !== 0 || /[^A-Za-z0-9+/=]/.test(data))
191407
191670
  imageError("IMAGE_DATA_INVALID");
191408
- const bytes = Buffer.from(data, "base64");
191409
- if (bytes.length > MAX_BYTES)
191671
+ const bytes2 = Buffer.from(data, "base64");
191672
+ if (bytes2.length > MAX_BYTES2)
191410
191673
  imageError("IMAGE_TOO_LARGE");
191411
- if (bytes.toString("base64") !== data || !bytes.length)
191674
+ if (bytes2.toString("base64") !== data || !bytes2.length)
191412
191675
  imageError("IMAGE_DATA_INVALID");
191413
- const magic = mediaType === "image/png" ? bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) : mediaType === "image/jpeg" ? bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255 : mediaType === "image/webp" && bytes.subarray(0, 4).toString() === "RIFF" && bytes.subarray(8, 12).toString() === "WEBP";
191676
+ const magic = mediaType === "image/png" ? bytes2.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) : mediaType === "image/jpeg" ? bytes2[0] === 255 && bytes2[1] === 216 && bytes2[2] === 255 : mediaType === "image/webp" && bytes2.subarray(0, 4).toString() === "RIFF" && bytes2.subarray(8, 12).toString() === "WEBP";
191414
191677
  if (!magic)
191415
191678
  imageError("IMAGE_MEDIA_INVALID");
191416
191679
  return { mediaType, data };
@@ -191418,7 +191681,7 @@ function validate(data, mediaType) {
191418
191681
  async function resolveImage(image, fetchImpl, rules, signal) {
191419
191682
  signal.throwIfAborted();
191420
191683
  if (image.dataUrl) {
191421
- if (image.dataUrl.length > Math.ceil(MAX_BYTES / 3) * 4 + 32)
191684
+ if (image.dataUrl.length > Math.ceil(MAX_BYTES2 / 3) * 4 + 32)
191422
191685
  imageError("IMAGE_TOO_LARGE");
191423
191686
  const match2 = /^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/=]+)$/.exec(image.dataUrl);
191424
191687
  if (!match2 || match2[1] !== image.mimeType)
@@ -191447,9 +191710,9 @@ async function resolveImage(image, fetchImpl, rules, signal) {
191447
191710
  await response.body?.cancel();
191448
191711
  imageError("IMAGE_MEDIA_INVALID");
191449
191712
  }
191450
- return validate(Buffer.from(await boundedBody(response, MAX_BYTES)).toString("base64"), mediaType);
191713
+ return validate(Buffer.from(await boundedBody(response, MAX_BYTES2)).toString("base64"), mediaType);
191451
191714
  }
191452
- var DEFAULT_IMAGE_URL_RULES, MAX_BYTES;
191715
+ var DEFAULT_IMAGE_URL_RULES, MAX_BYTES2;
191453
191716
  var init_io = __esm({
191454
191717
  "../linkque-agent-runtime/dist/esm/impl/plugin/imageUnderstanding/io.js"() {
191455
191718
  "use strict";
@@ -191458,7 +191721,7 @@ var init_io = __esm({
191458
191721
  { host: "masspre.alipay.com", pathPrefix: "/linkque/afts/img/" },
191459
191722
  { host: "mdn.alipayobjects.com", pathPrefix: "/linkque/afts/img/" }
191460
191723
  ];
191461
- MAX_BYTES = 2 * 1024 * 1024;
191724
+ MAX_BYTES2 = 20 * 1024 * 1024;
191462
191725
  }
191463
191726
  });
191464
191727
 
@@ -192039,6 +192302,61 @@ function failure(code, message, retryable) {
192039
192302
  return { ok: false, error: { code, message, retryable } };
192040
192303
  }
192041
192304
 
192305
+ // ../linkque-agent-runtime/dist/esm/core/cardActionDiagnostics.js
192306
+ init_types();
192307
+ var CardActionDiagnostics = class {
192308
+ sink;
192309
+ layer;
192310
+ stage = "validate";
192311
+ context;
192312
+ debugLog;
192313
+ startedAt = performance.now();
192314
+ constructor(sink, context2, layer = "runtime") {
192315
+ this.sink = sink;
192316
+ this.layer = layer;
192317
+ this.context = { ...context2 };
192318
+ if (sink) {
192319
+ this.debugLog = (line, scope) => {
192320
+ this.write("diagnostic", { message: line }, scope);
192321
+ };
192322
+ }
192323
+ }
192324
+ write(event, fields = {}, scope = EDebugLogScope.A2UI_ACTION) {
192325
+ if (!this.sink)
192326
+ return;
192327
+ try {
192328
+ const record3 = { ...this.context, ...fields };
192329
+ if (record3.message)
192330
+ record3.message = sanitizeDiagnosticText(record3.message);
192331
+ if (record3.errorName)
192332
+ record3.errorName = sanitizeDiagnosticText(record3.errorName);
192333
+ this.sink(JSON.stringify({
192334
+ operation: "a2uiAction.execute",
192335
+ layer: this.layer,
192336
+ event,
192337
+ stage: this.stage,
192338
+ ...record3,
192339
+ costMs: Math.max(0, Math.round(performance.now() - this.startedAt))
192340
+ }), scope);
192341
+ } catch {
192342
+ }
192343
+ }
192344
+ error(event, error40) {
192345
+ if (!this.sink)
192346
+ return;
192347
+ try {
192348
+ this.write(event, {
192349
+ errorName: error40 instanceof Error ? error40.name : typeof error40,
192350
+ message: error40 instanceof Error ? error40.message : typeof error40 === "string" ? error40 : "\u975E\u6807\u51C6\u5F02\u5E38"
192351
+ });
192352
+ } catch {
192353
+ }
192354
+ }
192355
+ };
192356
+ function sanitizeDiagnosticText(value) {
192357
+ 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);
192358
+ }
192359
+
192042
192360
  // ../linkque-agent-runtime/dist/esm/core/cardActionExecutor.js
192043
192361
  init_esm3();
192044
192362
  init_esm2();
@@ -192046,12 +192364,33 @@ init_esm();
192046
192364
  init_mcpAggregator();
192047
192365
  init_mcpProxyTool();
192048
192366
  async function executeCardAction(input) {
192367
+ const diagnostics = new CardActionDiagnostics(input.debugLog, {
192368
+ agentId: input.protocol.agentId,
192369
+ threadId: input.runtimeContext.threadId
192370
+ });
192371
+ diagnostics.write("started");
192372
+ try {
192373
+ const response = await executeCardActionInternal(input, diagnostics);
192374
+ diagnostics.write(response.ok ? "completed" : "failed", response.ok ? {} : { code: response.error.code, retryable: response.error.retryable });
192375
+ return response;
192376
+ } catch (error40) {
192377
+ diagnostics.error("failed", error40);
192378
+ throw error40;
192379
+ }
192380
+ }
192381
+ async function executeCardActionInternal(input, diagnostics) {
192049
192382
  let request;
192050
192383
  try {
192051
192384
  request = parseA2UIActionExecuteRequest(input.request);
192052
192385
  } catch (error40) {
192053
192386
  return failure2("INVALID_INPUT", errorMessage(error40, "\u652F\u4ED8\u52A8\u4F5C\u8BF7\u6C42\u65E0\u6548"), false);
192054
192387
  }
192388
+ Object.assign(diagnostics.context, {
192389
+ invocationId: request.invocationId,
192390
+ actionId: request.actionId,
192391
+ cardRef: request.source.cardRef,
192392
+ cardRevision: request.source.cardRevision
192393
+ });
192055
192394
  if (request.agentId !== input.protocol.agentId) {
192056
192395
  return failure2("AGENT_MISMATCH", "\u652F\u4ED8\u52A8\u4F5C\u4E0E\u5F53\u524D Agent \u4E0D\u5339\u914D", false);
192057
192396
  }
@@ -192061,24 +192400,38 @@ async function executeCardAction(input) {
192061
192400
  if (!input.runtimeContext.userId.trim()) {
192062
192401
  return failure2("AUTH_REQUIRED", "\u652F\u4ED8\u52A8\u4F5C\u7F3A\u5C11\u53EF\u4FE1\u7528\u6237\u8EAB\u4EFD", false);
192063
192402
  }
192403
+ diagnostics.write("validated");
192404
+ diagnostics.stage = "binding";
192064
192405
  const resolved = resolvePaymentBinding(input.protocol, request.source, request.actionId);
192065
192406
  if (!resolved.ok)
192066
192407
  return resolved.response;
192067
- const registry2 = createRegistry(input.protocol, input.mcpServerProvider);
192408
+ Object.assign(diagnostics.context, {
192409
+ mcpResourceId: resolved.binding.createTrade.mcpResourceId,
192410
+ toolName: resolved.binding.createTrade.toolName
192411
+ });
192412
+ diagnostics.write("binding_resolved");
192413
+ diagnostics.stage = "tool_resolve";
192414
+ const registry2 = createRegistry(input.protocol, input.mcpServerProvider, diagnostics.debugLog);
192068
192415
  try {
192069
192416
  const tool = await registry2.resolve(resolved.binding.createTrade.mcpResourceId, resolved.binding.createTrade.toolName, input.signal);
192070
192417
  if (!tool) {
192071
192418
  return failure2("TOOL_NOT_ALLOWED", "\u521B\u5EFA\u4EA4\u6613 MCP Tool \u4E0D\u5B58\u5728\u6216\u672A\u6388\u6743", false);
192072
192419
  }
192420
+ diagnostics.stage = "tool_input";
192073
192421
  const args = createToolInput(resolved.binding.createTrade.inputBindings, request.actionContext, input.runtimeContext);
192074
192422
  if (!args)
192075
192423
  return failure2("INVALID_INPUT", "\u65E0\u6CD5\u751F\u6210\u521B\u5EFA\u4EA4\u6613 MCP \u5165\u53C2", false);
192076
192424
  let result;
192425
+ diagnostics.stage = "tool_execute";
192426
+ diagnostics.write("tool_started");
192077
192427
  try {
192078
192428
  result = await tool.execute(args, input.signal);
192079
- } catch {
192429
+ diagnostics.write("tool_completed");
192430
+ } catch (error40) {
192431
+ diagnostics.error("tool_failed", error40);
192080
192432
  return failure2("EXECUTION_FAILED", "\u521B\u5EFA\u4EA4\u6613\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", true);
192081
192433
  }
192434
+ diagnostics.stage = "tool_output";
192082
192435
  const structured = readStructuredContent3(result);
192083
192436
  const tradeNO = readJsonPointer(structured, resolved.binding.createTrade.tradeNoPath);
192084
192437
  if (typeof tradeNO !== "string" || !tradeNO.trim() || tradeNO.length > 64) {
@@ -192090,7 +192443,10 @@ async function executeCardAction(input) {
192090
192443
  result: { kind: "payment", tradeNO }
192091
192444
  };
192092
192445
  } finally {
192446
+ const stage = diagnostics.stage;
192447
+ diagnostics.stage = "cleanup";
192093
192448
  await registry2.closeAll();
192449
+ diagnostics.stage = stage;
192094
192450
  }
192095
192451
  }
192096
192452
  function resolvePaymentBinding(protocol, source, actionId) {
@@ -192120,9 +192476,9 @@ function resolvePaymentBinding(protocol, source, actionId) {
192120
192476
  }
192121
192477
  return { ok: true, binding };
192122
192478
  }
192123
- function createRegistry(protocol, provider) {
192479
+ function createRegistry(protocol, provider, debugLog) {
192124
192480
  const resources = protocol.agent.resources.filter((resource) => resource.resourceType === EResourceType.MCP || resource.resourceType === EResourceType.MCP_TOOL);
192125
- return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId));
192481
+ return new McpProxyTool(provider, aggregateMcpServers(resources, protocol.agentId), { debugLog });
192126
192482
  }
192127
192483
  function createToolInput(bindings, actionContext, runtimeContext, tradeNO, callback) {
192128
192484
  const result = {};
@@ -197363,6 +197719,8 @@ function applyArgsMappingRules(toolName, args, rules) {
197363
197719
  init_esm();
197364
197720
 
197365
197721
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
197722
+ init_types();
197723
+ init_logFailure();
197366
197724
  var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
197367
197725
  agentId: config2.agentId,
197368
197726
  signEndpoint: config2.signEndpoint,
@@ -197398,13 +197756,42 @@ var RemoteGatewayMcpServerProvider = class {
197398
197756
  });
197399
197757
  const serverName = resource.config.serverName ?? resource.resourceId;
197400
197758
  const argsMappingRules = resource.config.argsMappingRules ?? [];
197759
+ let requestSequence = 0;
197760
+ const request = async (method, params, invoke) => {
197761
+ const requestId = ++requestSequence;
197762
+ const log = (phase, payload) => {
197763
+ if (!this.debugLog)
197764
+ return;
197765
+ try {
197766
+ this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload })}`, EDebugLogScope.MCP);
197767
+ } catch (error40) {
197768
+ warnLogFailure("remoteGatewayMcpServer.log", error40);
197769
+ }
197770
+ };
197771
+ log("request", params);
197772
+ try {
197773
+ const result = await invoke();
197774
+ log("response", result);
197775
+ return result;
197776
+ } catch (error40) {
197777
+ log("error", error40 instanceof Error ? { name: error40.name, message: error40.message } : error40);
197778
+ throw error40;
197779
+ }
197780
+ };
197781
+ const loggedClient = {
197782
+ listTools: () => request("tools/list", {}, () => client.listTools()),
197783
+ callTool: (params) => request("tools/call", params, () => client.callTool(params))
197784
+ };
197401
197785
  return {
197402
197786
  resourceId: resource.resourceId,
197403
197787
  serverName,
197404
- listTools: () => listToolsFromClient(client, resource.resourceId),
197788
+ listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
197405
197789
  callTool: (name, args) => {
197406
197790
  const mapped = applyArgsMappingRules(name, args, argsMappingRules);
197407
- return client.callTool({ name, arguments: mapped ?? {} });
197791
+ return loggedClient.callTool({
197792
+ name,
197793
+ arguments: mapped ?? {}
197794
+ });
197408
197795
  },
197409
197796
  close: async () => {
197410
197797
  try {
@@ -198360,8 +198747,8 @@ var WebSkillLoader = class {
198360
198747
  return (0, import_promises.readFile)(import_node_path.default.join(candidate, "SKILL.md"), "utf8");
198361
198748
  }
198362
198749
  if (isZipPath(candidate)) {
198363
- const bytes = new Uint8Array(await (0, import_promises.readFile)(candidate));
198364
- const files = await unzipBytes(bytes, resourceId);
198750
+ const bytes2 = new Uint8Array(await (0, import_promises.readFile)(candidate));
198751
+ const files = await unzipBytes(bytes2, resourceId);
198365
198752
  const body = extractSkillMarkdown(files);
198366
198753
  if (body === void 0) {
198367
198754
  throw new Error(`WebSkillLoader \u5728\u672C\u5730 zip \u5185\u672A\u627E\u5230 SKILL.md(\u6216\u56DE\u9000 .md)\u6B63\u6587: ${url2} (resourceId=${resourceId})`);
@@ -198404,7 +198791,7 @@ var extractSkillMarkdown = (files) => {
198404
198791
  const rootMd = paths.find((p) => p.endsWith(".md") && !p.includes("/"));
198405
198792
  return rootMd === void 0 ? void 0 : decodeUtf8(files[rootMd]);
198406
198793
  };
198407
- var decodeUtf8 = (bytes) => new TextDecoder("utf-8", { fatal: true }).decode(bytes);
198794
+ var decodeUtf8 = (bytes2) => new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
198408
198795
  var globalFetch = (url2) => fetch(url2);
198409
198796
  var detectScheme = (url2) => {
198410
198797
  if (/^https:\/\//i.test(url2))
@@ -198908,7 +199295,7 @@ var handleHomeData = async (req, res, input) => {
198908
199295
  );
198909
199296
  }
198910
199297
  };
198911
- var handleA2UIAction = async (req, res, input) => {
199298
+ var handleA2UIAction = async (req, res, input, debugLog) => {
198912
199299
  if (!executeCardAction2 || !createMcpServerProvider) {
198913
199300
  writeJsonError2(res, 500, "AGENTDEV_NOT_READY", "agent runtime not loaded");
198914
199301
  return;
@@ -198932,7 +199319,8 @@ var handleA2UIAction = async (req, res, input) => {
198932
199319
  userId: proxyInput.userId,
198933
199320
  ...proxyInput.tenantId ? { tenantId: proxyInput.tenantId } : {}
198934
199321
  },
198935
- mcpServerProvider: createMcpServerProvider(protocol)
199322
+ mcpServerProvider: createMcpServerProvider(protocol),
199323
+ debugLog
198936
199324
  });
198937
199325
  res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
198938
199326
  res.end(JSON.stringify(result));
@@ -199110,7 +199498,7 @@ var main = async () => {
199110
199498
  return;
199111
199499
  }
199112
199500
  if (req.method === "POST" && pathname === input.a2uiActionPath) {
199113
- void handleA2UIAction(req, res, input);
199501
+ void handleA2UIAction(req, res, input, debugLog);
199114
199502
  return;
199115
199503
  }
199116
199504
  const cancelMatch = pathname.match(