linkque-cli-v2 1.2.5 → 1.2.7

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
@@ -86,6 +86,7 @@ var init_agentProtocol = __esm({
86
86
  EHookStage2["RUN_FAILED"] = "RUN_FAILED";
87
87
  EHookStage2["RUN_READ"] = "RUN_READ";
88
88
  EHookStage2["AFTER_MODEL_CALL"] = "AFTER_MODEL_CALL";
89
+ EHookStage2["MODEL_RESPONSE_RECEIVED"] = "MODEL_RESPONSE_RECEIVED";
89
90
  EHookStage2["BEFORE_TOOL_CALL"] = "BEFORE_TOOL_CALL";
90
91
  EHookStage2["AFTER_TOOL_CALL"] = "AFTER_TOOL_CALL";
91
92
  EHookStage2["TOOL_CALL_FAILED"] = "TOOL_CALL_FAILED";
@@ -3318,6 +3319,7 @@ var require_utils = __commonJS({
3318
3319
  "use strict";
3319
3320
  var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
3320
3321
  var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
3322
+ var isPort = RegExp.prototype.test.bind(/^\d*$/u);
3321
3323
  var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
3322
3324
  var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
3323
3325
  var isPathCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/]$/u);
@@ -3783,8 +3785,12 @@ var require_utils = __commonJS({
3783
3785
  uriTokens.push(host);
3784
3786
  }
3785
3787
  if (typeof component.port === "number" || typeof component.port === "string") {
3788
+ const port = String(component.port);
3789
+ if (!isPort(port)) {
3790
+ throw new TypeError("URI port is malformed.");
3791
+ }
3786
3792
  uriTokens.push(":");
3787
- uriTokens.push(String(component.port));
3793
+ uriTokens.push(port);
3788
3794
  }
3789
3795
  return uriTokens.length ? uriTokens.join("") : void 0;
3790
3796
  }
@@ -4227,12 +4233,15 @@ var require_fast_uri = __commonJS({
4227
4233
  }
4228
4234
  return false;
4229
4235
  }
4236
+ function isIPLiteral(host) {
4237
+ return host[0] === "[" && host[host.length - 1] === "]";
4238
+ }
4230
4239
  function hasMalformedComponentPercentEncoding(matches) {
4231
4240
  const host = matches[4];
4232
- return hasMalformedPercentEncoding(matches[3]) || host !== void 0 && !(host[0] === "[" && host[host.length - 1] === "]") && hasMalformedPercentEncoding(host) || hasMalformedPercentEncoding(matches[6]) || hasMalformedPercentEncoding(matches[7]) || hasMalformedPercentEncoding(matches[8]);
4241
+ return hasMalformedPercentEncoding(matches[3]) || host !== void 0 && !isIPLiteral(host) && hasMalformedPercentEncoding(host) || hasMalformedPercentEncoding(matches[6]) || hasMalformedPercentEncoding(matches[7]) || hasMalformedPercentEncoding(matches[8]);
4233
4242
  }
4234
4243
  function canonicalizeHost(parsed, options, schemeHandler, isIP2) {
4235
- if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport) && parsed.host && parsed.host[0] !== "[" && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP2 === false && nonSimpleDomain(parsed.host)) {
4244
+ if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport) && parsed.host && !isIPLiteral(parsed.host) && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP2 === false && nonSimpleDomain(parsed.host)) {
4236
4245
  try {
4237
4246
  parsed.host = new URL("http://" + parsed.host).hostname;
4238
4247
  } catch (e2) {
@@ -4319,10 +4328,11 @@ var require_fast_uri = __commonJS({
4319
4328
  if (parsed.host) {
4320
4329
  const ipv4result = isIPv4(parsed.host);
4321
4330
  if (ipv4result === false) {
4322
- const bracketedIPLiteral = parsed.host[0] === "[" && parsed.host[parsed.host.length - 1] === "]";
4331
+ const bracketedIPLiteral = isIPLiteral(parsed.host);
4332
+ const hasIPLiteralBracket = parsed.host.indexOf("[") !== -1 || parsed.host.indexOf("]") !== -1;
4323
4333
  const ipv6result = normalizeIPv6(parsed.host);
4324
4334
  isIP2 = ipv6result.isIPV6 || ipv6result.isIPVFuture === true;
4325
- malformedIPLiteral = bracketedIPLiteral && ipv6result.error === true;
4335
+ malformedIPLiteral = hasIPLiteralBracket && (!bracketedIPLiteral || ipv6result.error === true);
4326
4336
  parsed.host = isIP2 ? ipv6result.host : ipv6result.host.toLowerCase();
4327
4337
  if (malformedIPLiteral) {
4328
4338
  parsed.error = parsed.error || "URI host is malformed.";
@@ -4345,7 +4355,9 @@ var require_fast_uri = __commonJS({
4345
4355
  parsed.error = parsed.error || "URI is not a " + options.reference + " reference.";
4346
4356
  }
4347
4357
  const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
4348
- malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP2);
4358
+ if (!malformedIPLiteral) {
4359
+ malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP2);
4360
+ }
4349
4361
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4350
4362
  if (uri.indexOf("%") !== -1) {
4351
4363
  if (parsed.host !== void 0 && !malformedIPLiteral) {
@@ -8677,6 +8689,9 @@ function validateAst(ast) {
8677
8689
  if (!ALLOWED_AST_TYPES.has(value.type)) {
8678
8690
  throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_NODE_FORBIDDEN", `JMESPath node ${value.type} is not allowed`);
8679
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
+ }
8680
8695
  if (value.type === "Function" && value.name !== "not_null") {
8681
8696
  throw new StructuralExpressionError("STRUCTURAL_EXPRESSION_FUNCTION_FORBIDDEN", `JMESPath function ${String(value.name)} is not allowed`);
8682
8697
  }
@@ -8702,6 +8717,8 @@ var init_structural = __esm({
8702
8717
  "Field",
8703
8718
  "Function",
8704
8719
  "Identity",
8720
+ "Index",
8721
+ "IndexExpression",
8705
8722
  "KeyValuePair",
8706
8723
  "Literal",
8707
8724
  "MultiSelectHash",
@@ -9279,6 +9296,9 @@ function validateAst2(ast) {
9279
9296
  if (!ALLOWED_AST_TYPES2.has(value.type)) {
9280
9297
  throw new A2UICardExpressionError("CARD_EXPRESSION_NODE_FORBIDDEN", `JMESPath node ${value.type} is not allowed by ${A2UI_CARD_TRANSFORM_PROFILE}`);
9281
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
+ }
9282
9302
  if (value.type === "Function" && value.name !== "not_null") {
9283
9303
  throw new A2UICardExpressionError("CARD_EXPRESSION_FUNCTION_FORBIDDEN", `JMESPath function ${String(value.name)} is not allowed`);
9284
9304
  }
@@ -9303,6 +9323,8 @@ var init_expression = __esm({
9303
9323
  "Field",
9304
9324
  "Function",
9305
9325
  "Identity",
9326
+ "Index",
9327
+ "IndexExpression",
9306
9328
  "KeyValuePair",
9307
9329
  "Literal",
9308
9330
  "MultiSelectHash",
@@ -11442,6 +11464,96 @@ var init_mcpNaming = __esm({
11442
11464
  }
11443
11465
  });
11444
11466
 
11467
+ // ../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js
11468
+ function createCardSemanticSnapshot(receipt, fields) {
11469
+ const groups = receipt.coverage.map((coverage) => {
11470
+ const field = fields.find((f3) => f3.fieldId === coverage.fieldId);
11471
+ const entities = receipt.entities.filter((e2) => e2.fieldId === coverage.fieldId);
11472
+ const echo = field?.presentation?.visibility === "echo";
11473
+ const attributes = echo ? [...new Set(entities.flatMap((e2) => Object.keys(e2.attributes ?? {})))] : [];
11474
+ const hasValue = echo && entities.some((e2) => Object.hasOwn(e2, "value"));
11475
+ const hasLabel = echo && entities.some((e2) => !Object.hasOwn(e2, "value"));
11476
+ const columns = [
11477
+ "\u6761\u76EE\u5F15\u7528",
11478
+ ...hasLabel ? [columnLabel(field, field?.presentation?.labelPath, "\u540D\u79F0")] : [],
11479
+ ...hasValue ? [short(coverage.label)] : [],
11480
+ ...attributes.map((path6) => columnLabel(field, path6, path6))
11481
+ ];
11482
+ const rows = entities.map((e2) => [
11483
+ e2.ref,
11484
+ ...hasLabel ? [e2.label] : [],
11485
+ ...hasValue ? [e2.value ?? null] : [],
11486
+ ...attributes.map((path6) => e2.attributes?.[path6] ?? null)
11487
+ ]);
11488
+ const total = coverage.itemCount ?? (coverage.present ? 1 : 0);
11489
+ return {
11490
+ field: coverage.fieldId,
11491
+ label: short(coverage.label),
11492
+ present: coverage.present,
11493
+ total,
11494
+ included: rows.length,
11495
+ complete: echo && coverage.present && rows.length === total && !entities.some((e2) => e2.truncated) && !receipt.omissions.some((o) => o.fieldId === coverage.fieldId),
11496
+ columns,
11497
+ rows
11498
+ };
11499
+ });
11500
+ const snapshot = {
11501
+ version: 1,
11502
+ groups,
11503
+ omissions: receipt.omissions.map((o) => ({ ...o }))
11504
+ };
11505
+ while (bytes(snapshot) > MAX_BYTES) {
11506
+ let group;
11507
+ for (let i2 = groups.length - 1; i2 >= 0; i2--) {
11508
+ if (groups[i2].rows.length > 0) {
11509
+ group = groups[i2];
11510
+ break;
11511
+ }
11512
+ }
11513
+ snapshot.truncated = true;
11514
+ if (group) {
11515
+ group.rows.pop();
11516
+ group.included = group.rows.length;
11517
+ group.complete = false;
11518
+ } else if (groups.length) {
11519
+ groups.pop();
11520
+ } else if (snapshot.omissions.length) {
11521
+ snapshot.omissions.pop();
11522
+ } else
11523
+ break;
11524
+ }
11525
+ return snapshot;
11526
+ }
11527
+ function bytes(value) {
11528
+ return Buffer.byteLength(JSON.stringify(value));
11529
+ }
11530
+ function short(value) {
11531
+ return value.length > MAX_LABEL ? `${value.slice(0, MAX_LABEL - 1)}\u2026` : value;
11532
+ }
11533
+ function columnLabel(field, path6, fallback) {
11534
+ if (!field || !path6)
11535
+ return short(fallback);
11536
+ let schema = field.type === "array" ? field.valueSchema.items : field.valueSchema;
11537
+ for (const token of path6.slice(1).split("/").map((t2) => t2.replaceAll("~1", "/").replaceAll("~0", "~"))) {
11538
+ if (!schema || typeof schema !== "object" || Array.isArray(schema))
11539
+ return short(fallback);
11540
+ const properties = schema.properties;
11541
+ if (!properties || typeof properties !== "object" || Array.isArray(properties) || !Object.hasOwn(properties, token))
11542
+ return short(fallback);
11543
+ schema = properties[token];
11544
+ }
11545
+ const title = schema && typeof schema === "object" && !Array.isArray(schema) ? schema.title : void 0;
11546
+ return short(typeof title === "string" && title ? title : fallback);
11547
+ }
11548
+ var MAX_BYTES, MAX_LABEL;
11549
+ var init_cardSemanticSnapshot = __esm({
11550
+ "../linkque-agent-runtime/dist/esm/core/cardSemanticSnapshot.js"() {
11551
+ "use strict";
11552
+ MAX_BYTES = 6e3;
11553
+ MAX_LABEL = 160;
11554
+ }
11555
+ });
11556
+
11445
11557
  // ../linkque-agent-runtime/dist/esm/core/cardTools.js
11446
11558
  function createCardPresentationToolName(resourceId) {
11447
11559
  return stableToolName("a2ui_card", resourceId);
@@ -11561,6 +11673,7 @@ function createPresentationResult(resource, config2, viewModel) {
11561
11673
  ...createA2UICardPresentationReceiptContent(config2.fields, viewModel),
11562
11674
  responsePolicy: { verbatimEcho: "forbidden", hint: "acknowledge" }
11563
11675
  };
11676
+ receipt.semanticSnapshot = createCardSemanticSnapshot(receipt, config2.fields);
11564
11677
  return {
11565
11678
  type: "linkque.presentation-tool-result",
11566
11679
  modelText: formatPresentationReceiptForModel(receipt),
@@ -11580,11 +11693,23 @@ function createPresentationResult(resource, config2, viewModel) {
11580
11693
  function formatPresentationReceiptForModel(receipt) {
11581
11694
  return [
11582
11695
  "<a2ui-presentation-receipt>",
11583
- JSON.stringify(receipt),
11696
+ JSON.stringify(projectPresentationReceiptForModel(receipt)),
11584
11697
  "</a2ui-presentation-receipt>",
11585
- "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."
11698
+ "\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"
11586
11699
  ].join("\n");
11587
11700
  }
11701
+ function projectPresentationReceiptForModel(receipt) {
11702
+ if (!receipt.semanticSnapshot)
11703
+ return receipt;
11704
+ return {
11705
+ version: receipt.version,
11706
+ cardRef: receipt.cardRef,
11707
+ cardRevision: receipt.cardRevision,
11708
+ cardInstanceId: receipt.cardInstanceId,
11709
+ status: receipt.status,
11710
+ semanticSnapshot: receipt.semanticSnapshot
11711
+ };
11712
+ }
11588
11713
  function parseCardConfig(resource) {
11589
11714
  const parsed = parseA2UICardResourceConfig(resource.config);
11590
11715
  if (!parsed.success) {
@@ -11638,9 +11763,9 @@ function collectA2UISurfaceIdsForLegacyContract(protocol) {
11638
11763
  function createPresentationDescription(config2) {
11639
11764
  return [
11640
11765
  config2.description,
11641
- `Use this card when: ${config2.whenToUse}`,
11642
- ...config2.whenNotToUse ? [`Do not use this card when: ${config2.whenNotToUse}`] : [],
11643
- "Provide only the declared identifier/filter arguments. Authoritative business values are resolved by the platform."
11766
+ `\u9002\u7528\u573A\u666F\uFF1A${config2.whenToUse}`,
11767
+ ...config2.whenNotToUse ? [`\u4E0D\u9002\u7528\u573A\u666F\uFF1A${config2.whenNotToUse}`] : [],
11768
+ "\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"
11644
11769
  ].join("\n");
11645
11770
  }
11646
11771
  function cloneJsonObject2(value, label) {
@@ -11714,6 +11839,7 @@ var init_cardTools = __esm({
11714
11839
  import_node_crypto2 = require("node:crypto");
11715
11840
  init_esm3();
11716
11841
  init_mcpNaming();
11842
+ init_cardSemanticSnapshot();
11717
11843
  FALLBACK_OBJECT_SCHEMA = {
11718
11844
  type: "object",
11719
11845
  additionalProperties: true
@@ -12503,13 +12629,26 @@ var init_hookRegistry = __esm({
12503
12629
  }
12504
12630
  });
12505
12631
 
12632
+ // ../linkque-agent-runtime/dist/esm/core/logFailure.js
12633
+ function warnLogFailure(stage, error40) {
12634
+ (0, import_node_process.emitWarning)(`[${stage}] errorType=${error40 instanceof Error ? error40.name : typeof error40}`, { code: "LINKQUE_RUNTIME_DIAGNOSTIC_FAILURE" });
12635
+ }
12636
+ var import_node_process;
12637
+ var init_logFailure = __esm({
12638
+ "../linkque-agent-runtime/dist/esm/core/logFailure.js"() {
12639
+ "use strict";
12640
+ import_node_process = require("node:process");
12641
+ }
12642
+ });
12643
+
12506
12644
  // ../linkque-agent-runtime/dist/esm/core/hook/hookLog.js
12507
12645
  function writeHookLog(debugLog, record3) {
12508
12646
  if (!debugLog)
12509
12647
  return;
12510
12648
  try {
12511
12649
  debugLog(JSON.stringify(redactHookLogRecord(record3)), EDebugLogScope.HOOK);
12512
- } catch {
12650
+ } catch (error40) {
12651
+ warnLogFailure("writeHookLog", error40);
12513
12652
  }
12514
12653
  }
12515
12654
  function redactHookLogRecord(record3) {
@@ -12529,6 +12668,7 @@ var HOOK_LOG_MESSAGE_MAX_LENGTH;
12529
12668
  var init_hookLog = __esm({
12530
12669
  "../linkque-agent-runtime/dist/esm/core/hook/hookLog.js"() {
12531
12670
  "use strict";
12671
+ init_logFailure();
12532
12672
  init_types();
12533
12673
  HOOK_LOG_MESSAGE_MAX_LENGTH = 200;
12534
12674
  }
@@ -12730,6 +12870,15 @@ var init_hookDispatcher = __esm({
12730
12870
  stage: EHookStage.RUN_READ,
12731
12871
  read: { readAt: subject.readAt ?? now() }
12732
12872
  };
12873
+ case EHookStage.MODEL_RESPONSE_RECEIVED: {
12874
+ if (!subject.model)
12875
+ throw new Error("MODEL_RESPONSE_RECEIVED Hook \u7F3A\u5C11\u54CD\u5E94\u4E0A\u4E0B\u6587");
12876
+ return {
12877
+ ...base,
12878
+ stage: EHookStage.MODEL_RESPONSE_RECEIVED,
12879
+ model: subject.model
12880
+ };
12881
+ }
12733
12882
  case EHookStage.AFTER_MODEL_CALL: {
12734
12883
  if (!subject.model || subject.model.messageContent === void 0) {
12735
12884
  throw new Error("AFTER_MODEL_CALL Hook \u7F3A\u5C11\u5B8C\u6574 model context");
@@ -13294,7 +13443,8 @@ function redactHeaders(headers) {
13294
13443
  pairs.push(`${key}=${redactHeader(key, value)}`);
13295
13444
  }
13296
13445
  }
13297
- } catch {
13446
+ } catch (error40) {
13447
+ warnLogFailure("httpLoggingFetch.redactHeaders", error40);
13298
13448
  }
13299
13449
  return pairs.join(",");
13300
13450
  }
@@ -13331,7 +13481,8 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
13331
13481
  const cl = resp.headers.get("content-length");
13332
13482
  if (cl)
13333
13483
  len = cl;
13334
- } catch {
13484
+ } catch (error40) {
13485
+ warnLogFailure("httpLoggingFetch.contentLength", error40);
13335
13486
  }
13336
13487
  const correlation = readResponseCorrelationId(resp.headers);
13337
13488
  const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
@@ -13360,14 +13511,16 @@ function readResponseCorrelationId(headers) {
13360
13511
  };
13361
13512
  });
13362
13513
  return matched;
13363
- } catch {
13514
+ } catch (error40) {
13515
+ warnLogFailure("httpLoggingFetch.responseCorrelationId", error40);
13364
13516
  }
13365
13517
  return void 0;
13366
13518
  }
13367
13519
  function safeLog(debugLog, line) {
13368
13520
  try {
13369
13521
  debugLog(line, EDebugLogScope.HTTP);
13370
- } catch {
13522
+ } catch (error40) {
13523
+ warnLogFailure("httpLoggingFetch.safeLog", error40);
13371
13524
  }
13372
13525
  }
13373
13526
  function nowMs() {
@@ -13382,6 +13535,7 @@ var init_httpLoggingFetch = __esm({
13382
13535
  "../linkque-agent-runtime/dist/esm/impl/httpLoggingFetch.js"() {
13383
13536
  "use strict";
13384
13537
  init_types();
13538
+ init_logFailure();
13385
13539
  MAX_BODY_SUMMARY_LEN = 2e3;
13386
13540
  REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
13387
13541
  "authorization",
@@ -32956,9 +33110,9 @@ function encodeUTF8(str2) {
32956
33110
  let encoder2;
32957
33111
  return (encodeUTF8_ ?? (encoder2 = new globalThis.TextEncoder(), encodeUTF8_ = encoder2.encode.bind(encoder2)))(str2);
32958
33112
  }
32959
- function decodeUTF8(bytes) {
33113
+ function decodeUTF8(bytes2) {
32960
33114
  let decoder;
32961
- return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_ = decoder.decode.bind(decoder)))(bytes);
33115
+ return (decodeUTF8_ ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_ = decoder.decode.bind(decoder)))(bytes2);
32962
33116
  }
32963
33117
  var encodeUTF8_, decodeUTF8_;
32964
33118
  var init_bytes = __esm({
@@ -33338,8 +33492,8 @@ var init_streaming = __esm({
33338
33492
  const { value, done } = await iter.next();
33339
33493
  if (done)
33340
33494
  return ctrl.close();
33341
- const bytes = encodeUTF8(JSON.stringify(value) + "\n");
33342
- ctrl.enqueue(bytes);
33495
+ const bytes2 = encodeUTF8(JSON.stringify(value) + "\n");
33496
+ ctrl.enqueue(bytes2);
33343
33497
  } catch (err3) {
33344
33498
  ctrl.error(err3);
33345
33499
  }
@@ -42387,9 +42541,9 @@ function encodeUTF82(str2) {
42387
42541
  let encoder2;
42388
42542
  return (encodeUTF8_2 ?? (encoder2 = new globalThis.TextEncoder(), encodeUTF8_2 = encoder2.encode.bind(encoder2)))(str2);
42389
42543
  }
42390
- function decodeUTF82(bytes) {
42544
+ function decodeUTF82(bytes2) {
42391
42545
  let decoder;
42392
- return (decodeUTF8_2 ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_2 = decoder.decode.bind(decoder)))(bytes);
42546
+ return (decodeUTF8_2 ?? (decoder = new globalThis.TextDecoder(), decodeUTF8_2 = decoder.decode.bind(decoder)))(bytes2);
42393
42547
  }
42394
42548
  var encodeUTF8_2, decodeUTF8_2;
42395
42549
  var init_bytes2 = __esm({
@@ -42775,8 +42929,8 @@ var init_streaming3 = __esm({
42775
42929
  const { value, done } = await iter.next();
42776
42930
  if (done)
42777
42931
  return ctrl.close();
42778
- const bytes = encodeUTF82(JSON.stringify(value) + "\n");
42779
- ctrl.enqueue(bytes);
42932
+ const bytes2 = encodeUTF82(JSON.stringify(value) + "\n");
42933
+ ctrl.enqueue(bytes2);
42780
42934
  } catch (err3) {
42781
42935
  ctrl.error(err3);
42782
42936
  }
@@ -45493,11 +45647,11 @@ var init_base64 = __esm({
45493
45647
  } else {
45494
45648
  const binaryStr = atob(base64Str);
45495
45649
  const len = binaryStr.length;
45496
- const bytes = new Uint8Array(len);
45650
+ const bytes2 = new Uint8Array(len);
45497
45651
  for (let i2 = 0; i2 < len; i2++) {
45498
- bytes[i2] = binaryStr.charCodeAt(i2);
45652
+ bytes2[i2] = binaryStr.charCodeAt(i2);
45499
45653
  }
45500
- return Array.from(new Float32Array(bytes.buffer));
45654
+ return Array.from(new Float32Array(bytes2.buffer));
45501
45655
  }
45502
45656
  };
45503
45657
  }
@@ -56711,14 +56865,14 @@ var require_streams = __commonJS({
56711
56865
  if (!globalThis.ReadableStream) {
56712
56866
  try {
56713
56867
  const process2 = require("node:process");
56714
- const { emitWarning } = process2;
56868
+ const { emitWarning: emitWarning2 } = process2;
56715
56869
  try {
56716
56870
  process2.emitWarning = () => {
56717
56871
  };
56718
56872
  Object.assign(globalThis, require("node:stream/web"));
56719
- process2.emitWarning = emitWarning;
56873
+ process2.emitWarning = emitWarning2;
56720
56874
  } catch (error40) {
56721
- process2.emitWarning = emitWarning;
56875
+ process2.emitWarning = emitWarning2;
56722
56876
  throw error40;
56723
56877
  }
56724
56878
  } catch (error40) {
@@ -82274,9 +82428,9 @@ function encodeUTF83(str2) {
82274
82428
  let encoder2;
82275
82429
  return (encodeUTF8_3 !== null && encodeUTF8_3 !== void 0 ? encodeUTF8_3 : (encoder2 = new globalThis.TextEncoder(), encodeUTF8_3 = encoder2.encode.bind(encoder2)))(str2);
82276
82430
  }
82277
- function decodeUTF83(bytes) {
82431
+ function decodeUTF83(bytes2) {
82278
82432
  let decoder;
82279
- return (decodeUTF8_3 !== null && decodeUTF8_3 !== void 0 ? decodeUTF8_3 : (decoder = new globalThis.TextDecoder(), decodeUTF8_3 = decoder.decode.bind(decoder)))(bytes);
82433
+ return (decodeUTF8_3 !== null && decodeUTF8_3 !== void 0 ? decodeUTF8_3 : (decoder = new globalThis.TextDecoder(), decodeUTF8_3 = decoder.decode.bind(decoder)))(bytes2);
82280
82434
  }
82281
82435
  function findNewlineIndex3(buffer, startIndex) {
82282
82436
  const newline = 10;
@@ -89436,8 +89590,8 @@ ${underline}`);
89436
89590
  const { value, done } = await iter.next();
89437
89591
  if (done)
89438
89592
  return ctrl.close();
89439
- const bytes = encodeUTF83(JSON.stringify(value) + "\n");
89440
- ctrl.enqueue(bytes);
89593
+ const bytes2 = encodeUTF83(JSON.stringify(value) + "\n");
89594
+ ctrl.enqueue(bytes2);
89441
89595
  } catch (err3) {
89442
89596
  ctrl.error(err3);
89443
89597
  }
@@ -189390,7 +189544,8 @@ async function createAgentSession(options) {
189390
189544
  onDelay: (delayMs) => {
189391
189545
  try {
189392
189546
  options.debugLog?.(`[llm-throttle] wait ${delayMs}ms before next request`, EDebugLogScope.LLM);
189393
- } catch {
189547
+ } catch (error40) {
189548
+ warnLogFailure("createAgentSession.throttleLog", error40);
189394
189549
  }
189395
189550
  }
189396
189551
  });
@@ -189423,7 +189578,8 @@ async function createAgentSession(options) {
189423
189578
  await prevOnPayload?.(payload, m2);
189424
189579
  try {
189425
189580
  logSink(formatHttpLogLine("llm", "req", `POST ${baseUrl} model=${m2.id} payload=${summarizeBody(safeStringifyPayload(payload))}`), EDebugLogScope.LLM);
189426
- } catch {
189581
+ } catch (error40) {
189582
+ warnLogFailure("createAgentSession.requestLog", error40);
189427
189583
  }
189428
189584
  };
189429
189585
  }
@@ -189440,6 +189596,7 @@ async function createAgentSession(options) {
189440
189596
  responseHeaders: response.headers
189441
189597
  }
189442
189598
  };
189599
+ await options.hookRuntime.dispatcher.dispatch(EHookStage.MODEL_RESPONSE_RECEIVED, options.hookRuntime.commonParams, subject);
189443
189600
  if (options.hookRuntime.dispatcher.hasMatchingResource(EHookStage.AFTER_MODEL_CALL, subject)) {
189444
189601
  gateState = { subject };
189445
189602
  }
@@ -189448,7 +189605,8 @@ async function createAgentSession(options) {
189448
189605
  try {
189449
189606
  const baseUrl = model.baseUrl ?? "<unknown>";
189450
189607
  logSink(formatHttpLogLine("llm", "resp", `POST ${baseUrl} model=${m2.id} ${response.status} headers=${redactHeaders(response.headers)}`), EDebugLogScope.LLM);
189451
- } catch {
189608
+ } catch (error40) {
189609
+ warnLogFailure("createAgentSession.responseLog", error40);
189452
189610
  }
189453
189611
  }
189454
189612
  };
@@ -189475,7 +189633,8 @@ async function createAgentSession(options) {
189475
189633
  try {
189476
189634
  agent.abort();
189477
189635
  agent.reset();
189478
- } catch {
189636
+ } catch (error40) {
189637
+ warnLogFailure("createAgentSession.dispose", error40);
189479
189638
  }
189480
189639
  }
189481
189640
  }
@@ -189528,7 +189687,8 @@ function serializeToolResult2(value) {
189528
189687
  try {
189529
189688
  const serialized = JSON.stringify(value);
189530
189689
  return serialized === void 0 ? "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002" : serialized;
189531
- } catch {
189690
+ } catch (error40) {
189691
+ warnLogFailure("createAgentSession.toolResultSerialization", error40);
189532
189692
  return "\u5DE5\u5177\u6267\u884C\u5B8C\u6210\u3002";
189533
189693
  }
189534
189694
  }
@@ -189539,13 +189699,15 @@ function safeStringifyPayload(payload) {
189539
189699
  return payload;
189540
189700
  try {
189541
189701
  return JSON.stringify(payload) ?? "";
189542
- } catch {
189702
+ } catch (error40) {
189703
+ warnLogFailure("createAgentSession.payloadSerialization", error40);
189543
189704
  return "<unserializable>";
189544
189705
  }
189545
189706
  }
189546
189707
  var init_createAgentSession = __esm({
189547
189708
  "../linkque-agent-runtime/dist/esm/impl/agent/pi/createAgentSession.js"() {
189548
189709
  "use strict";
189710
+ init_logFailure();
189549
189711
  init_dist4();
189550
189712
  init_dist3();
189551
189713
  init_esm();
@@ -190363,18 +190525,39 @@ var init_pi = __esm({
190363
190525
  });
190364
190526
 
190365
190527
  // ../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js
190528
+ function readAfterCard(args) {
190529
+ if (!args || typeof args !== "object")
190530
+ return void 0;
190531
+ const mode = args.responseMode;
190532
+ if (Object.hasOwn(args, "responseMode") && !["card_only", "supplement", "user_requested_text"].includes(mode))
190533
+ throw new Error("responseMode \u65E0\u6548\uFF0C\u8BF7\u9009\u62E9\u5DF2\u58F0\u660E\u7684\u6A21\u5F0F");
190534
+ if (!Object.hasOwn(args, "afterCard")) {
190535
+ if (mode !== void 0)
190536
+ throw new Error("\u6307\u5B9A responseMode \u65F6\u5FC5\u987B\u63D0\u4F9B afterCard");
190537
+ return void 0;
190538
+ }
190539
+ const value = args.afterCard;
190540
+ if (typeof value !== "string" || value.length > 16e3)
190541
+ throw new Error("afterCard \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7 16000");
190542
+ if (mode === "card_only" && value.trim() !== "")
190543
+ 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");
190544
+ return value.trim();
190545
+ }
190366
190546
  function createCardSourceToolName(resourceId, sourceId) {
190367
190547
  return stableToolName("card_source", `${resourceId}_${sourceId}`);
190368
190548
  }
190369
190549
  function createCardFinishToolName(resourceId) {
190370
190550
  return stableToolName("card_finish", resourceId);
190371
190551
  }
190372
- var CardRenderMcpServer;
190552
+ var CARD_SEQUENCE, AFTER_CARD_DESCRIPTION, RESPONSE_MODE_DESCRIPTION, CardRenderMcpServer;
190373
190553
  var init_cardRenderMcpServer = __esm({
190374
190554
  "../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js"() {
190375
190555
  "use strict";
190376
190556
  init_cardTools();
190377
190557
  init_mcpNaming();
190558
+ 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";
190559
+ 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";
190560
+ 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";
190378
190561
  CardRenderMcpServer = class {
190379
190562
  resources;
190380
190563
  registry;
@@ -190396,6 +190579,8 @@ var init_cardRenderMcpServer = __esm({
190396
190579
  toolByName = /* @__PURE__ */ new Map();
190397
190580
  activeCardId;
190398
190581
  invalidCards = [];
190582
+ /** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
190583
+ companions = /* @__PURE__ */ new WeakMap();
190399
190584
  /** 本轮被隔离的坏卡,仅供宿主诊断,不影响其它卡片注册。 */
190400
190585
  getInvalidCards() {
190401
190586
  return this.invalidCards;
@@ -190436,7 +190621,7 @@ var init_cardRenderMcpServer = __esm({
190436
190621
  resourceId: resource.resourceId,
190437
190622
  label: config2.displayName,
190438
190623
  description: `${createPresentationDescription(config2)}
190439
- Select this card first, then call its card_source tools and card_finish tool.`,
190624
+ \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}`,
190440
190625
  inputSchema: {
190441
190626
  type: "object",
190442
190627
  properties: {},
@@ -190475,18 +190660,18 @@ Select this card first, then call its card_source tools and card_finish tool.`,
190475
190660
  modelName: sourceToolName,
190476
190661
  resourceId: resource.resourceId,
190477
190662
  label: source.purpose,
190478
- description: `Use after selecting ${name}. ${source.purpose}. Choose all MCP arguments from the conversation and prior source results.`,
190663
+ 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}`,
190479
190664
  inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
190480
190665
  outputSchema: discoveredHandle?.outputSchema ?? source.outputSchema,
190481
190666
  execute: async (args, signal) => {
190482
190667
  if (!state2.selected || this.activeCardId !== resource.resourceId)
190483
- throw new Error(`Select card ${name} before calling its data sources`);
190668
+ throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
190484
190669
  const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
190485
190670
  if (missingDependencies.length)
190486
- throw new Error(`Data source ${source.sourceId} is waiting for: ${missingDependencies.join(", ")}`);
190671
+ throw new Error(`\u6570\u636E\u6E90 ${source.sourceId} \u9700\u8981\u5148\u5B8C\u6210\u4EE5\u4E0B\u4F9D\u8D56\uFF1A${missingDependencies.join(", ")}`);
190487
190672
  const handle = discoveredHandle ?? await this.registry.resolve(source.mcpResourceId, source.toolName, signal);
190488
190673
  if (!handle)
190489
- throw new Error(`MCP tool ${source.mcpResourceId}/${source.toolName} is unavailable`);
190674
+ throw new Error(`MCP \u5DE5\u5177 ${source.mcpResourceId}/${source.toolName} \u5F53\u524D\u4E0D\u53EF\u7528`);
190490
190675
  const result = await handle.execute(args, signal);
190491
190676
  const structured = readStructuredContent(result);
190492
190677
  if (structured === void 0) {
@@ -190513,16 +190698,36 @@ Select this card first, then call its card_source tools and card_finish tool.`,
190513
190698
  modelName: finishName,
190514
190699
  resourceId: resource.resourceId,
190515
190700
  label: `\u5C55\u793A${config2.displayName}`,
190516
- description: `Finish and render ${config2.displayName} after all required card_source tools succeed.`,
190701
+ 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}
190702
+ ${AFTER_CARD_DESCRIPTION}`,
190517
190703
  inputSchema: {
190518
190704
  type: "object",
190519
- properties: {},
190705
+ required: ["responseMode", "afterCard"],
190706
+ properties: {
190707
+ responseMode: {
190708
+ type: "string",
190709
+ enum: ["card_only", "supplement", "user_requested_text"],
190710
+ description: RESPONSE_MODE_DESCRIPTION
190711
+ },
190712
+ afterCard: {
190713
+ type: "string",
190714
+ maxLength: 16e3,
190715
+ description: AFTER_CARD_DESCRIPTION
190716
+ }
190717
+ },
190520
190718
  additionalProperties: false
190521
190719
  },
190522
- execute: async (_args, signal) => {
190720
+ execute: async (args, signal) => {
190523
190721
  if (!state2.selected || this.activeCardId !== resource.resourceId)
190524
- throw new Error(`Select card ${name} before finishing it`);
190722
+ throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
190723
+ const afterCard = readAfterCard(args);
190525
190724
  const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
190725
+ if (afterCard !== void 0) {
190726
+ this.companions.set(result, afterCard);
190727
+ result.modelText += `
190728
+ <a2ui-companion-delivery>${JSON.stringify({ afterCard })}</a2ui-companion-delivery>
190729
+ \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`;
190730
+ }
190526
190731
  state2.selected = false;
190527
190732
  this.activeCardId = void 0;
190528
190733
  return result;
@@ -190553,6 +190758,32 @@ Select this card first, then call its card_source tools and card_finish tool.`,
190553
190758
  this.activeCardId = void 0;
190554
190759
  this.states.clear();
190555
190760
  this.toolByName.clear();
190761
+ this.companions = /* @__PURE__ */ new WeakMap();
190762
+ }
190763
+ /** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
190764
+ async *projectConversation(events) {
190765
+ const pending = /* @__PURE__ */ new WeakMap();
190766
+ let cardOwnsText = false;
190767
+ for await (const event of events) {
190768
+ if (event.type === "tool_start" || event.type === "error" || event.type === "done")
190769
+ cardOwnsText = false;
190770
+ if (event.type === "tool_end" && !event.isError) {
190771
+ const details = event.result && typeof event.result === "object" && "details" in event.result ? event.result.details : void 0;
190772
+ if (details && this.companions.has(details)) {
190773
+ pending.set(details.card, this.companions.get(details));
190774
+ }
190775
+ }
190776
+ if (event.type === "delta" && cardOwnsText)
190777
+ continue;
190778
+ yield event;
190779
+ if (event.type === "a2ui_card" && pending.has(event)) {
190780
+ const text2 = pending.get(event);
190781
+ pending.delete(event);
190782
+ cardOwnsText = true;
190783
+ if (text2)
190784
+ yield { type: "delta", content: text2 };
190785
+ }
190786
+ }
190556
190787
  }
190557
190788
  };
190558
190789
  }
@@ -191198,7 +191429,7 @@ var init_agentRuntime = __esm({
191198
191429
  });
191199
191430
  };
191200
191431
  try {
191201
- for await (const ev of this.agentLoop.run(agentReq)) {
191432
+ for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
191202
191433
  if (ev.type === "delta")
191203
191434
  assistantText += ev.content;
191204
191435
  if (ev.type === "tool_end" && !ev.isError) {
@@ -191218,7 +191449,10 @@ var init_agentRuntime = __esm({
191218
191449
  ...presentationReceipts.map((receipt) => ({
191219
191450
  role: "tool",
191220
191451
  name: "a2ui_presentation_receipt",
191221
- content: { type: "a2ui.presentation-receipt", receipt }
191452
+ content: {
191453
+ type: "a2ui.presentation-receipt",
191454
+ receipt: projectPresentationReceiptForModel(receipt)
191455
+ }
191222
191456
  })),
191223
191457
  { role: "assistant", content: assistantText }
191224
191458
  ];
@@ -191423,16 +191657,16 @@ async function boundedBody(response, max2) {
191423
191657
  }
191424
191658
  }
191425
191659
  function validate(data, mediaType) {
191426
- if (data.length > Math.ceil(MAX_BYTES / 3) * 4)
191660
+ if (data.length > Math.ceil(MAX_BYTES2 / 3) * 4)
191427
191661
  imageError("IMAGE_TOO_LARGE");
191428
191662
  if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data))
191429
191663
  imageError("IMAGE_DATA_INVALID");
191430
- const bytes = Buffer.from(data, "base64");
191431
- if (bytes.length > MAX_BYTES)
191664
+ const bytes2 = Buffer.from(data, "base64");
191665
+ if (bytes2.length > MAX_BYTES2)
191432
191666
  imageError("IMAGE_TOO_LARGE");
191433
- if (bytes.toString("base64") !== data || !bytes.length)
191667
+ if (bytes2.toString("base64") !== data || !bytes2.length)
191434
191668
  imageError("IMAGE_DATA_INVALID");
191435
- 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";
191669
+ 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";
191436
191670
  if (!magic)
191437
191671
  imageError("IMAGE_MEDIA_INVALID");
191438
191672
  return { mediaType, data };
@@ -191440,7 +191674,7 @@ function validate(data, mediaType) {
191440
191674
  async function resolveImage(image, fetchImpl, rules, signal) {
191441
191675
  signal.throwIfAborted();
191442
191676
  if (image.dataUrl) {
191443
- if (image.dataUrl.length > Math.ceil(MAX_BYTES / 3) * 4 + 32)
191677
+ if (image.dataUrl.length > Math.ceil(MAX_BYTES2 / 3) * 4 + 32)
191444
191678
  imageError("IMAGE_TOO_LARGE");
191445
191679
  const match2 = /^data:(image\/(?:png|jpeg|webp));base64,([A-Za-z0-9+/=]+)$/.exec(image.dataUrl);
191446
191680
  if (!match2 || match2[1] !== image.mimeType)
@@ -191469,9 +191703,9 @@ async function resolveImage(image, fetchImpl, rules, signal) {
191469
191703
  await response.body?.cancel();
191470
191704
  imageError("IMAGE_MEDIA_INVALID");
191471
191705
  }
191472
- return validate(Buffer.from(await boundedBody(response, MAX_BYTES)).toString("base64"), mediaType);
191706
+ return validate(Buffer.from(await boundedBody(response, MAX_BYTES2)).toString("base64"), mediaType);
191473
191707
  }
191474
- var DEFAULT_IMAGE_URL_RULES, MAX_BYTES;
191708
+ var DEFAULT_IMAGE_URL_RULES, MAX_BYTES2;
191475
191709
  var init_io = __esm({
191476
191710
  "../linkque-agent-runtime/dist/esm/impl/plugin/imageUnderstanding/io.js"() {
191477
191711
  "use strict";
@@ -191479,7 +191713,7 @@ var init_io = __esm({
191479
191713
  { host: "mass.alipay.com", pathPrefix: "/linkque/afts/img/" },
191480
191714
  { host: "masspre.alipay.com", pathPrefix: "/linkque/afts/img/" }
191481
191715
  ];
191482
- MAX_BYTES = 2 * 1024 * 1024;
191716
+ MAX_BYTES2 = 2 * 1024 * 1024;
191483
191717
  }
191484
191718
  });
191485
191719
 
@@ -191769,12 +192003,6 @@ var init_imageUnderstandingPlugin = __esm({
191769
192003
  ]
191770
192004
  }
191771
192005
  });
191772
- if (!input.agentConfig.agent.multimodel.enabled)
191773
- return currentImage ? {
191774
- ok: false,
191775
- code: "IMAGE_DISABLED",
191776
- message: "\u5F53\u524D Agent \u672A\u5F00\u542F\u591A\u6A21\u6001\uFF0C\u8BF7\u79FB\u9664\u56FE\u7247\u6216\u5F00\u542F\u540E\u91CD\u8BD5"
191777
- } : unavailable();
191778
192006
  const images = selected.turn.attachments;
191779
192007
  if (images.length !== 1)
191780
192008
  return currentImage ? {
@@ -197483,6 +197711,8 @@ function applyArgsMappingRules(toolName, args, rules) {
197483
197711
  init_esm();
197484
197712
 
197485
197713
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
197714
+ init_types();
197715
+ init_logFailure();
197486
197716
  var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
197487
197717
  agentId: config2.agentId,
197488
197718
  signEndpoint: config2.signEndpoint,
@@ -197518,13 +197748,42 @@ var RemoteGatewayMcpServerProvider = class {
197518
197748
  });
197519
197749
  const serverName = resource.config.serverName ?? resource.resourceId;
197520
197750
  const argsMappingRules = resource.config.argsMappingRules ?? [];
197751
+ let requestSequence = 0;
197752
+ const request = async (method, params, invoke) => {
197753
+ const requestId = ++requestSequence;
197754
+ const log = (phase, payload) => {
197755
+ if (!this.debugLog)
197756
+ return;
197757
+ try {
197758
+ this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload })}`, EDebugLogScope.MCP);
197759
+ } catch (error40) {
197760
+ warnLogFailure("remoteGatewayMcpServer.log", error40);
197761
+ }
197762
+ };
197763
+ log("request", params);
197764
+ try {
197765
+ const result = await invoke();
197766
+ log("response", result);
197767
+ return result;
197768
+ } catch (error40) {
197769
+ log("error", error40 instanceof Error ? { name: error40.name, message: error40.message } : error40);
197770
+ throw error40;
197771
+ }
197772
+ };
197773
+ const loggedClient = {
197774
+ listTools: () => request("tools/list", {}, () => client.listTools()),
197775
+ callTool: (params) => request("tools/call", params, () => client.callTool(params))
197776
+ };
197521
197777
  return {
197522
197778
  resourceId: resource.resourceId,
197523
197779
  serverName,
197524
- listTools: () => listToolsFromClient(client, resource.resourceId),
197780
+ listTools: () => listToolsFromClient(loggedClient, resource.resourceId),
197525
197781
  callTool: (name, args) => {
197526
197782
  const mapped = applyArgsMappingRules(name, args, argsMappingRules);
197527
- return client.callTool({ name, arguments: mapped ?? {} });
197783
+ return loggedClient.callTool({
197784
+ name,
197785
+ arguments: mapped ?? {}
197786
+ });
197528
197787
  },
197529
197788
  close: async () => {
197530
197789
  try {
@@ -198480,8 +198739,8 @@ var WebSkillLoader = class {
198480
198739
  return (0, import_promises.readFile)(import_node_path.default.join(candidate, "SKILL.md"), "utf8");
198481
198740
  }
198482
198741
  if (isZipPath(candidate)) {
198483
- const bytes = new Uint8Array(await (0, import_promises.readFile)(candidate));
198484
- const files = await unzipBytes(bytes, resourceId);
198742
+ const bytes2 = new Uint8Array(await (0, import_promises.readFile)(candidate));
198743
+ const files = await unzipBytes(bytes2, resourceId);
198485
198744
  const body = extractSkillMarkdown(files);
198486
198745
  if (body === void 0) {
198487
198746
  throw new Error(`WebSkillLoader \u5728\u672C\u5730 zip \u5185\u672A\u627E\u5230 SKILL.md(\u6216\u56DE\u9000 .md)\u6B63\u6587: ${url2} (resourceId=${resourceId})`);
@@ -198524,7 +198783,7 @@ var extractSkillMarkdown = (files) => {
198524
198783
  const rootMd = paths.find((p) => p.endsWith(".md") && !p.includes("/"));
198525
198784
  return rootMd === void 0 ? void 0 : decodeUtf8(files[rootMd]);
198526
198785
  };
198527
- var decodeUtf8 = (bytes) => new TextDecoder("utf-8", { fatal: true }).decode(bytes);
198786
+ var decodeUtf8 = (bytes2) => new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
198528
198787
  var globalFetch = (url2) => fetch(url2);
198529
198788
  var detectScheme = (url2) => {
198530
198789
  if (/^https:\/\//i.test(url2))