linkque-cli-v2 1.2.1 → 1.2.3

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.
@@ -3,7 +3,7 @@ import {
3
3
  DIRTY,
4
4
  EMPTY_PATH,
5
5
  INVALID,
6
- NEVER as NEVER2,
6
+ NEVER,
7
7
  OK,
8
8
  ParseStatus,
9
9
  ZodAny,
@@ -21,7 +21,7 @@ import {
21
21
  ZodFirstPartyTypeKind,
22
22
  ZodFunction,
23
23
  ZodIntersection,
24
- ZodIssueCode as ZodIssueCode2,
24
+ ZodIssueCode,
25
25
  ZodLazy,
26
26
  ZodLiteral,
27
27
  ZodMap,
@@ -53,7 +53,7 @@ import {
53
53
  bigIntType,
54
54
  booleanType,
55
55
  coerce,
56
- custom as custom2,
56
+ custom,
57
57
  dateType,
58
58
  datetimeRegex,
59
59
  discriminatedUnionType,
@@ -104,15 +104,15 @@ import {
104
104
  voidType
105
105
  } from "./chunk-XUFLSZM4.js";
106
106
  import {
107
- NEVER,
108
- ZodIssueCode,
107
+ NEVER as NEVER2,
108
+ ZodIssueCode as ZodIssueCode2,
109
109
  _enum,
110
110
  _null,
111
111
  any,
112
112
  array,
113
113
  boolean,
114
114
  coerce_exports,
115
- custom,
115
+ custom as custom2,
116
116
  discriminatedUnion,
117
117
  intersection,
118
118
  iso_exports,
@@ -6997,7 +6997,7 @@ var require_jmespath = __commonJS({
6997
6997
  return false;
6998
6998
  }
6999
6999
  }
7000
- function isObject(obj) {
7000
+ function isObject2(obj) {
7001
7001
  if (obj !== null) {
7002
7002
  return Object.prototype.toString.call(obj) === "[object Object]";
7003
7003
  } else {
@@ -7023,7 +7023,7 @@ var require_jmespath = __commonJS({
7023
7023
  }
7024
7024
  return true;
7025
7025
  }
7026
- if (isObject(first) === true) {
7026
+ if (isObject2(first) === true) {
7027
7027
  var keysSeen = {};
7028
7028
  for (var key in first) {
7029
7029
  if (hasOwnProperty.call(first, key)) {
@@ -7049,7 +7049,7 @@ var require_jmespath = __commonJS({
7049
7049
  return true;
7050
7050
  } else if (isArray(obj) && obj.length === 0) {
7051
7051
  return true;
7052
- } else if (isObject(obj)) {
7052
+ } else if (isObject2(obj)) {
7053
7053
  for (var key in obj) {
7054
7054
  if (obj.hasOwnProperty(key)) {
7055
7055
  return false;
@@ -7766,7 +7766,7 @@ var require_jmespath = __commonJS({
7766
7766
  var matched, current, result, first, second, field, left, right, collected, i;
7767
7767
  switch (node.type) {
7768
7768
  case "Field":
7769
- if (value !== null && isObject(value)) {
7769
+ if (value !== null && isObject2(value)) {
7770
7770
  field = value[node.name];
7771
7771
  if (field === void 0) {
7772
7772
  return null;
@@ -7836,7 +7836,7 @@ var require_jmespath = __commonJS({
7836
7836
  return collected;
7837
7837
  case "ValueProjection":
7838
7838
  base = this.visit(node.children[0], value);
7839
- if (!isObject(base)) {
7839
+ if (!isObject2(base)) {
7840
7840
  return null;
7841
7841
  }
7842
7842
  collected = [];
@@ -8233,7 +8233,7 @@ var require_jmespath = __commonJS({
8233
8233
  return Math.floor(resolvedArgs[0]);
8234
8234
  },
8235
8235
  _functionLength: function(resolvedArgs) {
8236
- if (!isObject(resolvedArgs[0])) {
8236
+ if (!isObject2(resolvedArgs[0])) {
8237
8237
  return resolvedArgs[0].length;
8238
8238
  } else {
8239
8239
  return Object.keys(resolvedArgs[0]).length;
@@ -16626,6 +16626,7 @@ var EHookStage;
16626
16626
  EHookStage2["RUN_STARTED"] = "RUN_STARTED";
16627
16627
  EHookStage2["RUN_COMPLETED"] = "RUN_COMPLETED";
16628
16628
  EHookStage2["RUN_FAILED"] = "RUN_FAILED";
16629
+ EHookStage2["RUN_READ"] = "RUN_READ";
16629
16630
  EHookStage2["BEFORE_TOOL_CALL"] = "BEFORE_TOOL_CALL";
16630
16631
  EHookStage2["AFTER_TOOL_CALL"] = "AFTER_TOOL_CALL";
16631
16632
  EHookStage2["TOOL_CALL_FAILED"] = "TOOL_CALL_FAILED";
@@ -17457,7 +17458,15 @@ function getA2UIActionExecuteRequestIssues(value) {
17457
17458
  if (!isPlainRecord(value))
17458
17459
  return ["request must be an object"];
17459
17460
  const issues = [];
17460
- rejectExtraKeysAsStrings(value, ["schemaVersion", "agentId", "threadId", "invocationId", "actionId", "source", "actionContext"], "request", issues);
17461
+ rejectExtraKeysAsStrings(value, [
17462
+ "schemaVersion",
17463
+ "agentId",
17464
+ "threadId",
17465
+ "invocationId",
17466
+ "actionId",
17467
+ "source",
17468
+ "actionContext"
17469
+ ], "request", issues);
17461
17470
  if (value.schemaVersion !== "1")
17462
17471
  issues.push("schemaVersion must be 1");
17463
17472
  requiredIdentifier(value.agentId, "agentId", issues);
@@ -17472,7 +17481,9 @@ function getA2UIActionExecuteRequestIssues(value) {
17472
17481
  }
17473
17482
  function parseA2UIPaymentResultEventPayload(value) {
17474
17483
  if (!isPlainRecord(value)) {
17475
- throw new A2UIActionContractError(["payment result payload must be an object"]);
17484
+ throw new A2UIActionContractError([
17485
+ "payment result payload must be an object"
17486
+ ]);
17476
17487
  }
17477
17488
  const issues = [];
17478
17489
  rejectExtraKeysAsStrings(value, ["actionId", "actionInvocationId", "tradeNO", "actionContext", "callback"], "payment result payload", issues);
@@ -17496,7 +17507,9 @@ function parseA2UIPaymentResultEventPayload(value) {
17496
17507
  }
17497
17508
  function getA2UICardActionBindingIssues(value, path2 = "actionBindings") {
17498
17509
  if (!Array.isArray(value)) {
17499
- return [issue2(path2, "INVALID_ACTION_BINDINGS", "actionBindings must be an array")];
17510
+ return [
17511
+ issue2(path2, "INVALID_ACTION_BINDINGS", "actionBindings must be an array")
17512
+ ];
17500
17513
  }
17501
17514
  const issues = [];
17502
17515
  const actionIds = /* @__PURE__ */ new Set();
@@ -17556,7 +17569,13 @@ function validateToolBinding(value, path2, phase, issues) {
17556
17569
  issues.push(issue2(path2, "INVALID_PAYMENT_TOOL", `${path2} must be an object`));
17557
17570
  return;
17558
17571
  }
17559
- rejectExtraKeys(value, phase === "create" ? ["mcpResourceId", "toolName", "inputBindings", "tradeNoPath"] : ["mcpResourceId", "toolName", "inputBindings", "statusPath", "paidValues"], path2, issues);
17572
+ rejectExtraKeys(value, phase === "create" ? ["mcpResourceId", "toolName", "inputBindings", "tradeNoPath"] : [
17573
+ "mcpResourceId",
17574
+ "toolName",
17575
+ "inputBindings",
17576
+ "statusPath",
17577
+ "paidValues"
17578
+ ], path2, issues);
17560
17579
  if (!isSafeIdentifier(value.mcpResourceId)) {
17561
17580
  issues.push(issue2(`${path2}.mcpResourceId`, "INVALID_MCP_RESOURCE_ID", "mcpResourceId is invalid"));
17562
17581
  }
@@ -17705,7 +17724,12 @@ function requiredText(value, path2, issues) {
17705
17724
  function isJsonPrimitive(value) {
17706
17725
  return value === null || ["string", "number", "boolean"].includes(typeof value);
17707
17726
  }
17708
- var RUNTIME_CONTEXT_KEYS = /* @__PURE__ */ new Set(["agentId", "tenantId", "threadId", "userId"]);
17727
+ var RUNTIME_CONTEXT_KEYS = /* @__PURE__ */ new Set([
17728
+ "agentId",
17729
+ "tenantId",
17730
+ "threadId",
17731
+ "userId"
17732
+ ]);
17709
17733
 
17710
17734
  // ../agent-a2ui-card-contract/dist/esm/validation.js
17711
17735
  var FIELD_TYPES = [
@@ -17963,7 +17987,8 @@ function validateFields(value, path2, issues) {
17963
17987
  "valueSchema",
17964
17988
  "sourcePath",
17965
17989
  "runtimeContextKey",
17966
- "consistencyGroup"
17990
+ "consistencyGroup",
17991
+ "presentation"
17967
17992
  ], itemPath, issues);
17968
17993
  if (!isSafeIdentifier(candidate.fieldId)) {
17969
17994
  issues.push(issue2(`${itemPath}.fieldId`, "INVALID_FIELD_ID", "fieldId is invalid"));
@@ -17999,9 +18024,33 @@ function validateFields(value, path2, issues) {
17999
18024
  }
18000
18025
  validateFieldSource(candidate, itemPath, issues);
18001
18026
  optionalString(candidate.consistencyGroup, `${itemPath}.consistencyGroup`, issues);
18027
+ validateFieldPresentation(candidate.presentation, itemPath, issues);
18002
18028
  });
18003
18029
  return value;
18004
18030
  }
18031
+ function validateFieldPresentation(value, itemPath, issues) {
18032
+ if (value === void 0)
18033
+ return;
18034
+ const path2 = `${itemPath}.presentation`;
18035
+ if (!isPlainRecord(value)) {
18036
+ issues.push(issue2(path2, "INVALID_FIELD_PRESENTATION", `${path2} must be an object`));
18037
+ return;
18038
+ }
18039
+ if (!["echo", "reference-only", "never"].includes(String(value.visibility))) {
18040
+ issues.push(issue2(`${path2}.visibility`, "INVALID_PRESENTATION_VISIBILITY", "presentation visibility must be echo, reference-only or never"));
18041
+ }
18042
+ if (value.labelPath !== void 0 && !isSafeJsonPointer(value.labelPath)) {
18043
+ issues.push(issue2(`${path2}.labelPath`, "INVALID_PRESENTATION_PATH", "labelPath must be a safe JSON pointer"));
18044
+ }
18045
+ if (value.attributePaths !== void 0) {
18046
+ if (!Array.isArray(value.attributePaths) || value.attributePaths.length > 3 || value.attributePaths.some((candidate) => !isSafeJsonPointer(candidate))) {
18047
+ issues.push(issue2(`${path2}.attributePaths`, "INVALID_PRESENTATION_PATHS", "attributePaths must contain at most 3 safe JSON pointers"));
18048
+ }
18049
+ }
18050
+ if (value.maxItems !== void 0 && (!Number.isInteger(value.maxItems) || Number(value.maxItems) < 1 || Number(value.maxItems) > 10)) {
18051
+ issues.push(issue2(`${path2}.maxItems`, "INVALID_PRESENTATION_MAX_ITEMS", "maxItems must be an integer between 1 and 10"));
18052
+ }
18053
+ }
18005
18054
  function validateFieldSource(candidate, itemPath, issues) {
18006
18055
  if (candidate.source === "invocation") {
18007
18056
  if (!isSafeJsonPointer(candidate.sourcePath)) {
@@ -18472,6 +18521,122 @@ function valueType2(value) {
18472
18521
  return typeof value === "object" ? "object" : typeof value;
18473
18522
  }
18474
18523
 
18524
+ // ../agent-a2ui-card-contract/dist/esm/presentation.js
18525
+ var MAX_FIELDS = 32;
18526
+ var MAX_ENTITIES = 10;
18527
+ var DEFAULT_FIELD_ITEMS = 3;
18528
+ var MAX_FIELD_ITEMS = 10;
18529
+ var MAX_ATTRIBUTES = 3;
18530
+ var MAX_TEXT_LENGTH = 160;
18531
+ function createA2UICardPresentationReceiptContent(fields, viewModel) {
18532
+ const coverage = [];
18533
+ const entities = [];
18534
+ const omissions = [];
18535
+ for (const field of fields.slice(0, MAX_FIELDS)) {
18536
+ const policy = field.presentation;
18537
+ if (policy?.visibility === "never") {
18538
+ omissions.push({ fieldId: field.fieldId, reason: "policy" });
18539
+ continue;
18540
+ }
18541
+ const value = readJsonPointer(viewModel, field.path);
18542
+ coverage.push({
18543
+ fieldId: field.fieldId,
18544
+ label: truncateText(field.label).value,
18545
+ present: value !== void 0,
18546
+ valueType: field.type,
18547
+ ...Array.isArray(value) && { itemCount: value.length }
18548
+ });
18549
+ if (!policy || value === void 0)
18550
+ continue;
18551
+ const isCollection = Array.isArray(value);
18552
+ const values = isCollection ? value : [value];
18553
+ const remainingBudget = MAX_ENTITIES - entities.length;
18554
+ const fieldBudget = Math.min(policy.maxItems ?? DEFAULT_FIELD_ITEMS, MAX_FIELD_ITEMS, remainingBudget);
18555
+ const selected = values.slice(0, Math.max(0, fieldBudget));
18556
+ for (const [index2, candidate] of selected.entries()) {
18557
+ const entity = createEntity(field, candidate, index2, isCollection, policy.visibility);
18558
+ if (entity)
18559
+ entities.push(entity);
18560
+ else
18561
+ omissions.push({ fieldId: field.fieldId, reason: "unsupported-value" });
18562
+ }
18563
+ if (values.length > selected.length) {
18564
+ omissions.push({
18565
+ fieldId: field.fieldId,
18566
+ reason: "budget",
18567
+ omittedCount: values.length - selected.length
18568
+ });
18569
+ }
18570
+ }
18571
+ if (fields.length > MAX_FIELDS) {
18572
+ omissions.push({
18573
+ fieldId: "*",
18574
+ reason: "budget",
18575
+ omittedCount: fields.length - MAX_FIELDS
18576
+ });
18577
+ }
18578
+ return { coverage, entities, omissions };
18579
+ }
18580
+ function createEntity(field, value, index2, isCollection, visibility) {
18581
+ const ref = `${field.fieldId}:${index2 + 1}`;
18582
+ if (visibility === "reference-only") {
18583
+ return {
18584
+ ref,
18585
+ fieldId: field.fieldId,
18586
+ ...isCollection && { ordinal: index2 + 1 },
18587
+ label: isCollection ? `${field.label} ${index2 + 1}` : field.label
18588
+ };
18589
+ }
18590
+ if (isPrimitive(value)) {
18591
+ const normalized = normalizePrimitive(value);
18592
+ return {
18593
+ ref,
18594
+ fieldId: field.fieldId,
18595
+ label: field.label,
18596
+ value: normalized.value,
18597
+ ...normalized.truncated && { truncated: true }
18598
+ };
18599
+ }
18600
+ if (!isObject(value))
18601
+ return void 0;
18602
+ const rawLabel = field.presentation?.labelPath ? readJsonPointer(value, field.presentation.labelPath) : void 0;
18603
+ const normalizedLabel = isPrimitive(rawLabel) ? truncateText(String(rawLabel)) : truncateText(`${field.label} ${index2 + 1}`);
18604
+ const attributes = {};
18605
+ let truncated = normalizedLabel.truncated;
18606
+ for (const path2 of (field.presentation?.attributePaths ?? []).slice(0, MAX_ATTRIBUTES)) {
18607
+ const attribute = readJsonPointer(value, path2);
18608
+ if (!isPrimitive(attribute))
18609
+ continue;
18610
+ const normalized = normalizePrimitive(attribute);
18611
+ attributes[path2] = normalized.value;
18612
+ truncated || (truncated = normalized.truncated);
18613
+ }
18614
+ return {
18615
+ ref,
18616
+ fieldId: field.fieldId,
18617
+ ...isCollection && { ordinal: index2 + 1 },
18618
+ label: normalizedLabel.value,
18619
+ ...Object.keys(attributes).length > 0 && { attributes },
18620
+ ...truncated && { truncated: true }
18621
+ };
18622
+ }
18623
+ function isObject(value) {
18624
+ return value !== null && typeof value === "object" && !Array.isArray(value);
18625
+ }
18626
+ function isPrimitive(value) {
18627
+ return value === null || ["string", "number", "boolean"].includes(typeof value);
18628
+ }
18629
+ function normalizePrimitive(value) {
18630
+ if (typeof value !== "string")
18631
+ return { value, truncated: false };
18632
+ return truncateText(value);
18633
+ }
18634
+ function truncateText(value) {
18635
+ if (value.length <= MAX_TEXT_LENGTH)
18636
+ return { value, truncated: false };
18637
+ return { value: `${value.slice(0, MAX_TEXT_LENGTH - 1)}\u2026`, truncated: true };
18638
+ }
18639
+
18475
18640
  // ../linkque-agent-runtime/dist/esm/core/mcpNaming.js
18476
18641
  import { createHash } from "node:crypto";
18477
18642
  function stableToolName(prefix, raw) {
@@ -18481,7 +18646,6 @@ function stableToolName(prefix, raw) {
18481
18646
  }
18482
18647
 
18483
18648
  // ../linkque-agent-runtime/dist/esm/core/cardTools.js
18484
- var PRESENTATION_RESULT_TEXT = "\u5361\u7247\u5DF2\u5C55\u793A\u3002";
18485
18649
  var FALLBACK_OBJECT_SCHEMA = {
18486
18650
  type: "object",
18487
18651
  additionalProperties: true
@@ -18525,22 +18689,7 @@ async function executeCardPresentation(resource, registry, runtimeContext, args,
18525
18689
  })),
18526
18690
  signal
18527
18691
  });
18528
- const protocol = injectResolvedViewModel(JSON.parse(config.a2uiTemplate.content), viewModel);
18529
- const cardInstanceId = `card-instance-${randomUUID()}`;
18530
- return {
18531
- type: "linkque.presentation-tool-result",
18532
- modelText: PRESENTATION_RESULT_TEXT,
18533
- card: {
18534
- type: "a2ui_card",
18535
- itemId: cardInstanceId,
18536
- payload: { protocol },
18537
- metadata: {
18538
- cardRef: resource.resourceId,
18539
- cardRevision: config.revision,
18540
- cardInstanceId
18541
- }
18542
- }
18543
- };
18692
+ return createPresentationResult(resource, config, viewModel);
18544
18693
  }
18545
18694
  async function executeCardPresentationFromSources(resource, runtimeContext, sourceResults, signal) {
18546
18695
  const config = parseCardConfig(resource);
@@ -18610,9 +18759,19 @@ async function executeCardPresentationFromSources(resource, runtimeContext, sour
18610
18759
  function createPresentationResult(resource, config, viewModel) {
18611
18760
  const protocol = injectResolvedViewModel(JSON.parse(config.a2uiTemplate.content), viewModel);
18612
18761
  const cardInstanceId = `card-instance-${randomUUID()}`;
18762
+ const receipt = {
18763
+ version: 1,
18764
+ cardRef: resource.resourceId,
18765
+ cardRevision: config.revision,
18766
+ cardInstanceId,
18767
+ status: "emitted",
18768
+ ...createA2UICardPresentationReceiptContent(config.fields, viewModel),
18769
+ responsePolicy: { verbatimEcho: "forbidden", hint: "acknowledge" }
18770
+ };
18613
18771
  return {
18614
18772
  type: "linkque.presentation-tool-result",
18615
- modelText: PRESENTATION_RESULT_TEXT,
18773
+ modelText: formatPresentationReceiptForModel(receipt),
18774
+ receipt,
18616
18775
  card: {
18617
18776
  type: "a2ui_card",
18618
18777
  itemId: cardInstanceId,
@@ -18625,6 +18784,14 @@ function createPresentationResult(resource, config, viewModel) {
18625
18784
  }
18626
18785
  };
18627
18786
  }
18787
+ function formatPresentationReceiptForModel(receipt) {
18788
+ return [
18789
+ "<a2ui-presentation-receipt>",
18790
+ JSON.stringify(receipt),
18791
+ "</a2ui-presentation-receipt>",
18792
+ "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."
18793
+ ].join("\n");
18794
+ }
18628
18795
  function parseCardConfig(resource) {
18629
18796
  const parsed = parseA2UICardResourceConfig(resource.config);
18630
18797
  if (!parsed.success) {
@@ -19431,15 +19598,27 @@ async function verifyPaymentResult(input) {
19431
19598
  function resolvePaymentBinding(protocol, source, actionId) {
19432
19599
  const card = protocol.agent.resources.find((resource) => resource.resourceType === EResourceType.CARD && resource.resourceId === source.cardRef);
19433
19600
  if (!card)
19434
- return { ok: false, response: failure2("CARD_NOT_FOUND", "\u652F\u4ED8\u5361\u7247\u4E0D\u5B58\u5728", false) };
19601
+ return {
19602
+ ok: false,
19603
+ response: failure2("CARD_NOT_FOUND", "\u652F\u4ED8\u5361\u7247\u4E0D\u5B58\u5728", false)
19604
+ };
19435
19605
  if (card.config.revision !== source.cardRevision) {
19436
- return { ok: false, response: failure2("CARD_REVISION_MISMATCH", "\u652F\u4ED8\u5361\u7247\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5", false) };
19606
+ return {
19607
+ ok: false,
19608
+ response: failure2("CARD_REVISION_MISMATCH", "\u652F\u4ED8\u5361\u7247\u7248\u672C\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5", false)
19609
+ };
19437
19610
  }
19438
19611
  const binding = card.config.schemaVersion === "3" ? card.config.actionBindings?.find((candidate) => candidate.actionId === actionId) : void 0;
19439
19612
  if (!binding)
19440
- return { ok: false, response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u672A\u7ED1\u5B9A", false) };
19613
+ return {
19614
+ ok: false,
19615
+ response: failure2("ACTION_NOT_FOUND", "\u652F\u4ED8\u52A8\u4F5C\u672A\u7ED1\u5B9A", false)
19616
+ };
19441
19617
  if (binding.kind !== "payment") {
19442
- return { ok: false, response: failure2("ACTION_KIND_MISMATCH", "\u52A8\u4F5C\u4E0D\u662F\u652F\u4ED8\u7C7B\u578B", false) };
19618
+ return {
19619
+ ok: false,
19620
+ response: failure2("ACTION_KIND_MISMATCH", "\u52A8\u4F5C\u4E0D\u662F\u652F\u4ED8\u7C7B\u578B", false)
19621
+ };
19443
19622
  }
19444
19623
  return { ok: true, binding };
19445
19624
  }
@@ -19853,6 +20032,9 @@ var HookDispatcher = class {
19853
20032
  run: {
19854
20033
  ...subject.runDurationMs !== void 0 && {
19855
20034
  durationMs: subject.runDurationMs
20035
+ },
20036
+ ...subject.messageContent !== void 0 && {
20037
+ messageContent: subject.messageContent
19856
20038
  }
19857
20039
  }
19858
20040
  };
@@ -19862,6 +20044,12 @@ var HookDispatcher = class {
19862
20044
  stage: EHookStage.RUN_FAILED,
19863
20045
  error: subject.error ?? { message: "unknown error" }
19864
20046
  };
20047
+ case EHookStage.RUN_READ:
20048
+ return {
20049
+ ...base,
20050
+ stage: EHookStage.RUN_READ,
20051
+ read: { readAt: subject.readAt ?? now() }
20052
+ };
19865
20053
  case EHookStage.BEFORE_TOOL_CALL:
19866
20054
  return {
19867
20055
  ...base,
@@ -19896,7 +20084,9 @@ var HookDispatcher = class {
19896
20084
  eventId: context.eventId,
19897
20085
  runId: context.commonParams.runId,
19898
20086
  conversationId: context.commonParams.conversationId,
19899
- runIndex: context.commonParams.runIndex,
20087
+ ...context.commonParams.runIndex !== void 0 && {
20088
+ runIndex: context.commonParams.runIndex
20089
+ },
19900
20090
  agentId: context.commonParams.agentId,
19901
20091
  ...context.commonParams.sessionId !== void 0 && {
19902
20092
  sessionId: context.commonParams.sessionId
@@ -19927,7 +20117,9 @@ var HookDispatcher = class {
19927
20117
  eventId: context.eventId,
19928
20118
  runId: context.commonParams.runId,
19929
20119
  conversationId: context.commonParams.conversationId,
19930
- runIndex: context.commonParams.runIndex,
20120
+ ...context.commonParams.runIndex !== void 0 && {
20121
+ runIndex: context.commonParams.runIndex
20122
+ },
19931
20123
  agentId: context.commonParams.agentId,
19932
20124
  ...context.commonParams.sessionId !== void 0 && {
19933
20125
  sessionId: context.commonParams.sessionId
@@ -19955,7 +20147,9 @@ var HookDispatcher = class {
19955
20147
  eventId: context.eventId,
19956
20148
  runId: context.commonParams.runId,
19957
20149
  conversationId: context.commonParams.conversationId,
19958
- runIndex: context.commonParams.runIndex,
20150
+ ...context.commonParams.runIndex !== void 0 && {
20151
+ runIndex: context.commonParams.runIndex
20152
+ },
19959
20153
  agentId: context.commonParams.agentId,
19960
20154
  ...context.commonParams.sessionId !== void 0 && {
19961
20155
  sessionId: context.commonParams.sessionId
@@ -20112,7 +20306,9 @@ var SideEffectRunner = class {
20112
20306
  eventId: context.eventId,
20113
20307
  runId: context.commonParams.runId,
20114
20308
  conversationId: context.commonParams.conversationId,
20115
- runIndex: context.commonParams.runIndex,
20309
+ ...context.commonParams.runIndex !== void 0 && {
20310
+ runIndex: context.commonParams.runIndex
20311
+ },
20116
20312
  agentId: context.commonParams.agentId,
20117
20313
  ...context.commonParams.sessionId !== void 0 && {
20118
20314
  sessionId: context.commonParams.sessionId
@@ -20395,16 +20591,29 @@ function errorMsg(error) {
20395
20591
  // ../linkque-agent-runtime/dist/esm/core/hook/linkquegwEventHookExecutor.js
20396
20592
  var DEFAULT_LINKQUEGW_EVENT_BASE_URL = "https://linkquegw.alipay.com";
20397
20593
  var LINKQUEGW_AGENT_EVENT_TRIGGER_PATH = "/api/agent/event/trigger";
20594
+ var LINKQUEGW_MESSAGE_CONTENT_MAX_LENGTH = 2048;
20398
20595
  var LINKQUEGW_EVENT_TYPE_BY_STAGE = {
20399
20596
  [EHookStage.RUN_STARTED]: "RUN_STARTED",
20400
20597
  [EHookStage.RUN_COMPLETED]: "RUN_ENDED",
20401
- [EHookStage.RUN_FAILED]: "RUN_ENDED"
20598
+ [EHookStage.RUN_FAILED]: "RUN_ENDED",
20599
+ [EHookStage.RUN_READ]: "RUN_READ"
20402
20600
  };
20403
- function buildLinkquegwEventBody(context) {
20601
+ function truncateMessageContent(messageContent) {
20602
+ return Array.from(messageContent).slice(0, LINKQUEGW_MESSAGE_CONTENT_MAX_LENGTH).join("");
20603
+ }
20604
+ function buildLinkquegwEventBody(context, temporaryFrontendAppId) {
20404
20605
  const eventType = LINKQUEGW_EVENT_TYPE_BY_STAGE[context.stage];
20405
20606
  if (eventType === void 0)
20406
20607
  return void 0;
20407
20608
  const { commonParams } = context;
20609
+ const payload = {
20610
+ ...temporaryFrontendAppId !== void 0 && {
20611
+ appId: temporaryFrontendAppId
20612
+ },
20613
+ ...context.stage === EHookStage.RUN_COMPLETED && context.run.messageContent !== void 0 && {
20614
+ messageContent: truncateMessageContent(context.run.messageContent)
20615
+ }
20616
+ };
20408
20617
  return {
20409
20618
  agentId: commonParams.agentId,
20410
20619
  eventType,
@@ -20417,7 +20626,13 @@ function buildLinkquegwEventBody(context) {
20417
20626
  sessionId: commonParams.sessionId
20418
20627
  },
20419
20628
  runId: commonParams.runId,
20420
- runIndex: commonParams.runIndex
20629
+ ...commonParams.runIndex !== void 0 && {
20630
+ runIndex: commonParams.runIndex
20631
+ },
20632
+ ...context.stage === EHookStage.RUN_READ && {
20633
+ readAt: context.read.readAt
20634
+ },
20635
+ ...Object.keys(payload).length > 0 && { payload }
20421
20636
  };
20422
20637
  }
20423
20638
  var LinkquegwEventHookExecutor = class {
@@ -20426,6 +20641,7 @@ var LinkquegwEventHookExecutor = class {
20426
20641
  getAuthHeaders;
20427
20642
  fetchImpl;
20428
20643
  metricsSink;
20644
+ temporaryFrontendAppId;
20429
20645
  now;
20430
20646
  constructor(options) {
20431
20647
  this.baseUrl = options.baseUrl ?? DEFAULT_LINKQUEGW_EVENT_BASE_URL;
@@ -20433,6 +20649,7 @@ var LinkquegwEventHookExecutor = class {
20433
20649
  const baseFetch = options.fetchImpl ?? globalThis.fetch;
20434
20650
  this.fetchImpl = options.debugLog ? createHttpLoggingFetch(options.debugLog, "hook-linkque", baseFetch) : baseFetch;
20435
20651
  this.metricsSink = options.metricsSink;
20652
+ this.temporaryFrontendAppId = options.temporaryFrontendAppId;
20436
20653
  this.now = options.now ?? Date.now;
20437
20654
  }
20438
20655
  async execute(resource, context, options) {
@@ -20444,7 +20661,7 @@ var LinkquegwEventHookExecutor = class {
20444
20661
  message: `hook \u671F\u671B executor=${resource.config.executorName} provider=${resource.providerType},\u975E LinkquegwEventHookExecutor \u6D88\u8D39\u8303\u56F4`
20445
20662
  };
20446
20663
  }
20447
- const body = buildLinkquegwEventBody(context);
20664
+ const body = buildLinkquegwEventBody(context, this.temporaryFrontendAppId);
20448
20665
  if (body === void 0) {
20449
20666
  return {
20450
20667
  ok: true,
@@ -53580,6 +53797,7 @@ var AgentRuntime = class _AgentRuntime {
53580
53797
  await hookDispatcher.dispatch(EHookStage.RUN_STARTED, hookCommonParams);
53581
53798
  }
53582
53799
  let assistantText = "";
53800
+ const presentationReceipts = [];
53583
53801
  let failed = false;
53584
53802
  let runError;
53585
53803
  let terminalHookDispatched = false;
@@ -53593,12 +53811,21 @@ var AgentRuntime = class _AgentRuntime {
53593
53811
  });
53594
53812
  return;
53595
53813
  }
53596
- await hookDispatcher.dispatch(EHookStage.RUN_COMPLETED, hookCommonParams, { runDurationMs: Date.now() - runStartedAt });
53814
+ await hookDispatcher.dispatch(EHookStage.RUN_COMPLETED, hookCommonParams, {
53815
+ runDurationMs: Date.now() - runStartedAt,
53816
+ ...assistantText !== "" && { messageContent: assistantText }
53817
+ });
53597
53818
  };
53598
53819
  try {
53599
53820
  for await (const ev of this.agentLoop.run(agentReq)) {
53600
53821
  if (ev.type === "delta")
53601
53822
  assistantText += ev.content;
53823
+ if (ev.type === "tool_end" && !ev.isError) {
53824
+ const details = ev.result && typeof ev.result === "object" && "details" in ev.result ? ev.result.details : void 0;
53825
+ if (isAgentPresentationToolResult(details) && details.receipt && !presentationReceipts.some((receipt) => receipt.cardInstanceId === details.receipt?.cardInstanceId)) {
53826
+ presentationReceipts.push(details.receipt);
53827
+ }
53828
+ }
53602
53829
  if (ev.type === "error") {
53603
53830
  failed = true;
53604
53831
  runError = { message: ev.error.message, code: ev.error.code };
@@ -53607,6 +53834,11 @@ var AgentRuntime = class _AgentRuntime {
53607
53834
  if (ev.type === "done" && !failed && sessionId !== void 0) {
53608
53835
  const completedTurns = [
53609
53836
  ...newTurns,
53837
+ ...presentationReceipts.map((receipt) => ({
53838
+ role: "tool",
53839
+ name: "a2ui_presentation_receipt",
53840
+ content: { type: "a2ui.presentation-receipt", receipt }
53841
+ })),
53610
53842
  { role: "assistant", content: assistantText }
53611
53843
  ];
53612
53844
  if (this.sessionManager.appendMany) {
@@ -53664,7 +53896,7 @@ __export(external_exports, {
53664
53896
  DIRTY: () => DIRTY,
53665
53897
  EMPTY_PATH: () => EMPTY_PATH,
53666
53898
  INVALID: () => INVALID,
53667
- NEVER: () => NEVER2,
53899
+ NEVER: () => NEVER,
53668
53900
  OK: () => OK,
53669
53901
  ParseStatus: () => ParseStatus,
53670
53902
  Schema: () => ZodType,
@@ -53683,7 +53915,7 @@ __export(external_exports, {
53683
53915
  ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
53684
53916
  ZodFunction: () => ZodFunction,
53685
53917
  ZodIntersection: () => ZodIntersection,
53686
- ZodIssueCode: () => ZodIssueCode2,
53918
+ ZodIssueCode: () => ZodIssueCode,
53687
53919
  ZodLazy: () => ZodLazy,
53688
53920
  ZodLiteral: () => ZodLiteral,
53689
53921
  ZodMap: () => ZodMap,
@@ -53717,7 +53949,7 @@ __export(external_exports, {
53717
53949
  bigint: () => bigIntType,
53718
53950
  boolean: () => booleanType,
53719
53951
  coerce: () => coerce,
53720
- custom: () => custom2,
53952
+ custom: () => custom,
53721
53953
  date: () => dateType,
53722
53954
  datetimeRegex: () => datetimeRegex,
53723
53955
  defaultErrorMap: () => en_default,
@@ -53837,7 +54069,7 @@ var LATEST_PROTOCOL_VERSION = "2025-11-25";
53837
54069
  var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
53838
54070
  var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
53839
54071
  var JSONRPC_VERSION = "2.0";
53840
- var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
54072
+ var AssertObjectSchema = custom2((v) => v !== null && (typeof v === "object" || typeof v === "function"));
53841
54073
  var ProgressTokenSchema = union([string(), number().int()]);
53842
54074
  var CursorSchema = string();
53843
54075
  var TaskCreationParamsSchema = looseObject({
@@ -57786,11 +58018,11 @@ async function pkceChallenge(length) {
57786
58018
  var SafeUrlSchema = url().superRefine((val, ctx) => {
57787
58019
  if (!URL.canParse(val)) {
57788
58020
  ctx.addIssue({
57789
- code: ZodIssueCode.custom,
58021
+ code: ZodIssueCode2.custom,
57790
58022
  message: "URL must be parseable",
57791
58023
  fatal: true
57792
58024
  });
57793
- return NEVER;
58025
+ return NEVER2;
57794
58026
  }
57795
58027
  }).refine((url2) => {
57796
58028
  const u = new URL(url2);
@@ -60467,6 +60699,8 @@ function isSupportedConversationProtocolVersion(value) {
60467
60699
 
60468
60700
  // ../agent-conversation-contract/dist/esm/control.js
60469
60701
  var CANCEL_CONVERSATION_RUN_OPERATION = "cancelConversationRun";
60702
+ var MARK_CONVERSATION_RUNS_READ_OPERATION = "markConversationRunsRead";
60703
+ var MAX_MARK_CONVERSATION_RUNS_READ_BATCH_SIZE = 50;
60470
60704
  var ConversationControlValidationError = class extends Error {
60471
60705
  issues;
60472
60706
  code = "CONVERSATION_CONTROL_INVALID";
@@ -60496,6 +60730,39 @@ function parseCancelConversationRunRequest(value) {
60496
60730
  throw new ConversationControlValidationError(issues);
60497
60731
  return value;
60498
60732
  }
60733
+ function parseMarkConversationRunsReadRequest(value) {
60734
+ const issues = [];
60735
+ if (!isRecord4(value)) {
60736
+ throw new ConversationControlValidationError([
60737
+ "control request must be an object"
60738
+ ]);
60739
+ }
60740
+ if (!isSupportedConversationProtocolVersion(value.protocolVersion)) {
60741
+ issues.push(`protocolVersion must be ${CONVERSATION_PROTOCOL_VERSION}`);
60742
+ }
60743
+ if (value.operation !== MARK_CONVERSATION_RUNS_READ_OPERATION) {
60744
+ issues.push("operation is unsupported");
60745
+ }
60746
+ if (!Array.isArray(value.runIds)) {
60747
+ issues.push("runIds must be an array");
60748
+ } else {
60749
+ if (value.runIds.length < 1 || value.runIds.length > MAX_MARK_CONVERSATION_RUNS_READ_BATCH_SIZE) {
60750
+ issues.push(`runIds must contain between 1 and ${MAX_MARK_CONVERSATION_RUNS_READ_BATCH_SIZE} items`);
60751
+ }
60752
+ value.runIds.forEach((runId, index2) => {
60753
+ if (!isNonEmptyString(runId)) {
60754
+ issues.push(`runIds[${index2}] must be a non-empty string`);
60755
+ }
60756
+ });
60757
+ }
60758
+ if (issues.length)
60759
+ throw new ConversationControlValidationError(issues);
60760
+ return {
60761
+ protocolVersion: value.protocolVersion,
60762
+ operation: MARK_CONVERSATION_RUNS_READ_OPERATION,
60763
+ runIds: [...new Set(value.runIds)]
60764
+ };
60765
+ }
60499
60766
  function isNonEmptyString(value) {
60500
60767
  return typeof value === "string" && Boolean(value.trim());
60501
60768
  }
@@ -61071,6 +61338,22 @@ function setBakedProtocol(protocol) {
61071
61338
  }
61072
61339
 
61073
61340
  export {
61341
+ EventType,
61342
+ parseConversationFollowUpQuestions,
61343
+ CANCEL_CONVERSATION_RUN_OPERATION,
61344
+ MARK_CONVERSATION_RUNS_READ_OPERATION,
61345
+ ConversationControlValidationError,
61346
+ parseCancelConversationRunRequest,
61347
+ parseMarkConversationRunsReadRequest,
61348
+ ConversationProtocolValidationError,
61349
+ parseConversationRunRequest,
61350
+ CONVERSATION_HISTORY_VERSION,
61351
+ DEFAULT_CONVERSATION_LIST_LIMIT,
61352
+ DEFAULT_CONVERSATION_RUN_LIST_LIMIT,
61353
+ DEFAULT_CONVERSATION_SEARCH_LIMIT,
61354
+ ConversationHistoryValidationError,
61355
+ parseConversationHistoryRequest,
61356
+ encodeConversationSseEvent,
61074
61357
  A2UI_PAYMENT_RESULT_EVENT_NAME,
61075
61358
  parseA2UIActionExecuteRequest,
61076
61359
  parseA2UIPaymentResultEventPayload,
@@ -61082,6 +61365,10 @@ export {
61082
61365
  executeCardAction,
61083
61366
  verifyPaymentResult,
61084
61367
  FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
61368
+ normalizeHookResources,
61369
+ HookDispatcher,
61370
+ DEFAULT_HOOK_DRAIN_BUDGET_MS,
61371
+ SideEffectRunner,
61085
61372
  LinkquegwEventHookExecutor,
61086
61373
  parseSkillFile,
61087
61374
  AgentRuntime,
@@ -61089,20 +61376,6 @@ export {
61089
61376
  LinkqueKnowledgeSearchPort,
61090
61377
  ESkillUrlScheme,
61091
61378
  WebSkillLoader,
61092
- EventType,
61093
- parseConversationFollowUpQuestions,
61094
- CANCEL_CONVERSATION_RUN_OPERATION,
61095
- ConversationControlValidationError,
61096
- parseCancelConversationRunRequest,
61097
- ConversationProtocolValidationError,
61098
- parseConversationRunRequest,
61099
- CONVERSATION_HISTORY_VERSION,
61100
- DEFAULT_CONVERSATION_LIST_LIMIT,
61101
- DEFAULT_CONVERSATION_RUN_LIST_LIMIT,
61102
- DEFAULT_CONVERSATION_SEARCH_LIMIT,
61103
- ConversationHistoryValidationError,
61104
- parseConversationHistoryRequest,
61105
- encodeConversationSseEvent,
61106
61379
  streamToConversationEvents,
61107
61380
  getBakedProtocol,
61108
61381
  setBakedProtocol