linkque-cli-v2 1.4.4 → 1.4.6

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.
@@ -40,15 +40,17 @@ import {
40
40
  resolveRunStorage,
41
41
  toAgentRunMessages,
42
42
  withIsoTimestamp
43
- } from "../../chunk-CUMXO6KK.js";
43
+ } from "../../chunk-STGFILDE.js";
44
44
  import "../../chunk-IWOFD643.js";
45
45
  import "../../chunk-PXCGFBV5.js";
46
46
  import "../../chunk-ETG6PNHQ.js";
47
47
  import {
48
48
  getBakedProtocol
49
- } from "../../chunk-XL6BPKTI.js";
49
+ } from "../../chunk-JD3IL3IC.js";
50
50
  import {
51
+ ACTIVATE_SKILL_TOOL_NAME,
51
52
  CANCEL_CONVERSATION_RUN_OPERATION,
53
+ CONTENT_VALUE_MAX_LENGTH,
52
54
  CONVERSATION_HISTORY_VERSION,
53
55
  CardActionDiagnostics,
54
56
  CardMappingError,
@@ -74,6 +76,7 @@ import {
74
76
  ETelemetryCancelSource,
75
77
  ETelemetryCommitStatus,
76
78
  ETelemetryCompleteness,
79
+ ETelemetryContentSection,
77
80
  ETelemetryCoverage,
78
81
  ETelemetryErrorType,
79
82
  ETelemetryEventName,
@@ -119,6 +122,7 @@ import {
119
122
  createCardPresentationToolName,
120
123
  createKnowledgeTools,
121
124
  createPresentationDescription,
125
+ createRuntimeDebugLog,
122
126
  createWebSearchTool,
123
127
  encodeConversationSseEvent,
124
128
  executeA2UICardResolver,
@@ -149,6 +153,7 @@ import {
149
153
  projectPresentationReceiptForModel,
150
154
  readJsonPointer,
151
155
  readStructuredContent,
156
+ recordContentSection,
152
157
  redactHeaders,
153
158
  resolvePhoneAuthorizationDependency,
154
159
  resolveWebSearchResource,
@@ -158,7 +163,7 @@ import {
158
163
  summarizeBody,
159
164
  warnLogFailure,
160
165
  wrapToolWithHooks
161
- } from "../../chunk-OHRCYI66.js";
166
+ } from "../../chunk-PM2UO433.js";
162
167
  import "../../chunk-EAODRPW4.js";
163
168
  import "../../chunk-XUFLSZM4.js";
164
169
  import "../../chunk-GAYNLDWK.js";
@@ -7945,15 +7950,16 @@ import { randomUUID as randomUUID7 } from "node:crypto";
7945
7950
 
7946
7951
  // ../linkque-agent-runtime/dist/esm/core/telemetry/toolObservation.js
7947
7952
  import { randomUUID } from "node:crypto";
7953
+ var isSkillTool = (tool) => (tool.modelName ?? tool.name) === ACTIVATE_SKILL_TOOL_NAME;
7948
7954
  function toolResultOutcome(result) {
7949
7955
  try {
7950
7956
  if (!(result && typeof result === "object")) {
7951
7957
  return ETelemetryOutcome.UNKNOWN;
7952
7958
  }
7953
7959
  const record2 = result;
7954
- if (record2.isError === true || record2.ok === false || record2.success === false)
7960
+ if (record2.isError === true)
7955
7961
  return ETelemetryOutcome.ERROR;
7956
- if (record2.isError === false || record2.ok === true || record2.success === true || record2.type === "linkque.presentation-tool-result")
7962
+ if (record2.isError === false || record2.type === "linkque.presentation-tool-result")
7957
7963
  return ETelemetryOutcome.SUCCESS;
7958
7964
  } catch {
7959
7965
  }
@@ -7971,6 +7977,7 @@ function observeTool(tool, observation) {
7971
7977
  eventPrefix: ETelemetryEventPrefix.TOOL_ATTEMPT,
7972
7978
  attributes: {
7973
7979
  [ETelemetryAttribute.GEN_AI_TOOL_NAME]: tool.modelName ?? tool.name,
7980
+ [ETelemetryAttribute.LINKQUE_TOOL_DISPLAY_NAME]: tool.label ?? tool.name,
7974
7981
  [ETelemetryAttribute.GEN_AI_TOOL_CALL_ID]: context?.toolCallId ?? "",
7975
7982
  [ETelemetryAttribute.HARNESS_ATTEMPT_ID]: randomUUID(),
7976
7983
  [ETelemetryAttribute.HARNESS_ATTEMPT_VISIBILITY]: ETelemetryAttemptVisibility.TOOL_PROVIDER_INVOCATION
@@ -7978,8 +7985,19 @@ function observeTool(tool, observation) {
7978
7985
  detached: false,
7979
7986
  links: []
7980
7987
  });
7988
+ const captureBody = !isSkillTool(tool);
7981
7989
  try {
7982
- const result = await tool.execute(args, signal, context);
7990
+ if (captureBody) {
7991
+ recordContentSection(operation, ETelemetryContentSection.TOOL_INPUT, args);
7992
+ }
7993
+ const execContext = {
7994
+ ...context ?? { toolCallId: "", emit: () => void 0 },
7995
+ observation: operation
7996
+ };
7997
+ const result = await tool.execute(args, signal, execContext);
7998
+ if (captureBody) {
7999
+ recordContentSection(operation, ETelemetryContentSection.TOOL_OUTPUT, result);
8000
+ }
7983
8001
  operation.finish(toolResultOutcome(result), {
7984
8002
  [ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS]: toolResultOutcome(result)
7985
8003
  });
@@ -8006,8 +8024,6 @@ var PiTelemetry = class {
8006
8024
  proposed = /* @__PURE__ */ new Map();
8007
8025
  loop;
8008
8026
  lastProvider = null;
8009
- publicTextSeen = false;
8010
- started = performance.now();
8011
8027
  terminal = ETelemetryStreamTermination.EXHAUSTED;
8012
8028
  constructor(root) {
8013
8029
  this.root = root;
@@ -8022,6 +8038,9 @@ var PiTelemetry = class {
8022
8038
  [ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: ETelemetryCoverage.PI_MODEL_TOOL_HOOK
8023
8039
  });
8024
8040
  }
8041
+ get currentModel() {
8042
+ return this.root.find(ETelemetryAssociation.MODEL);
8043
+ }
8025
8044
  startModel(model) {
8026
8045
  const parent = this.root.find(ETelemetryAssociation.ITERATION) ?? this.loop;
8027
8046
  return parent.startOperation({
@@ -8118,12 +8137,6 @@ var PiTelemetry = class {
8118
8137
  break;
8119
8138
  case "message_update": {
8120
8139
  const update = event.assistantMessageEvent;
8121
- if (update.type === "text_delta" && update.delta && !this.publicTextSeen) {
8122
- this.publicTextSeen = true;
8123
- this.loop.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
8124
- [ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.started
8125
- });
8126
- }
8127
8140
  if (update.type === "error")
8128
8141
  this.terminal = update.reason === "aborted" ? ETelemetryStreamTermination.CANCEL : ETelemetryStreamTermination.ERROR;
8129
8142
  break;
@@ -40483,6 +40496,9 @@ var StreamBridge = class {
40483
40496
  this.unsubscribe = this.session.subscribe((event) => {
40484
40497
  if (this.aborted)
40485
40498
  return;
40499
+ if (event.type === "message_end" && event.message.role === "assistant") {
40500
+ this.options.publicOutput?.completeSource(this.telemetry?.currentModel, event.message.stopReason !== "error" && event.message.stopReason !== "aborted");
40501
+ }
40486
40502
  this.telemetry?.onEvent(event);
40487
40503
  this.logDebug(`[pi-event] ${this.safeStringify(event)}`);
40488
40504
  for (const translated of translateEvents(event, this.uiStatusToolNames)) {
@@ -40491,6 +40507,7 @@ var StreamBridge = class {
40491
40507
  return;
40492
40508
  this.settled = true;
40493
40509
  }
40510
+ this.options.publicOutput?.associate(translated, this.telemetry?.currentModel);
40494
40511
  this.enqueue(translated);
40495
40512
  }
40496
40513
  });
@@ -40702,6 +40719,7 @@ var PiAgentLoop = class {
40702
40719
  },
40703
40720
  ...req.debugLog && { debugLog: req.debugLog },
40704
40721
  ...req.observation && { observation: req.observation },
40722
+ ...req.publicOutput && { publicOutput: req.publicOutput },
40705
40723
  // agentId 透传:agentService 在 LINKQUE provider 时注入 x-agent-id 请求头,供网关计费归因。
40706
40724
  ...req.agentId !== void 0 && { agentId: req.agentId },
40707
40725
  // runId 透传:注入 x-run-id 请求头,供网关用量上报归因(落库 run_id)。
@@ -40795,6 +40813,85 @@ function safeStringify(value) {
40795
40813
  }
40796
40814
  }
40797
40815
 
40816
+ // ../linkque-agent-runtime/dist/esm/core/telemetry/publicOutputObservation.js
40817
+ var PublicOutputObservation = class {
40818
+ root;
40819
+ sources = /* @__PURE__ */ new WeakMap();
40820
+ completedSources = /* @__PURE__ */ new WeakMap();
40821
+ source;
40822
+ text = "";
40823
+ bytes = 0;
40824
+ index = 0;
40825
+ truncated = false;
40826
+ firstText = false;
40827
+ startedAt = performance.now();
40828
+ constructor(root) {
40829
+ this.root = root;
40830
+ }
40831
+ associate(event, source) {
40832
+ if (source)
40833
+ this.sources.set(event, source);
40834
+ }
40835
+ /** 来源终态可能早于队列中的正文到达,不能在此提前刷空缓冲。 */
40836
+ completeSource(source, complete) {
40837
+ if (source)
40838
+ this.completedSources.set(source, complete);
40839
+ }
40840
+ accept(event) {
40841
+ if (event.type === "done" || event.type === "error") {
40842
+ const completed = this.source ? this.completedSources.get(this.source) : void 0;
40843
+ this.finish(completed ?? event.type === "done");
40844
+ return;
40845
+ }
40846
+ if (event.type !== "delta" || !event.content)
40847
+ return;
40848
+ if (!this.firstText) {
40849
+ this.firstText = true;
40850
+ this.root.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
40851
+ [ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.startedAt
40852
+ });
40853
+ }
40854
+ const source = this.sources.get(event);
40855
+ if (!source)
40856
+ return;
40857
+ if (source !== this.source) {
40858
+ this.finish(true);
40859
+ this.source = source;
40860
+ }
40861
+ if (this.truncated)
40862
+ return;
40863
+ for (const character of event.content) {
40864
+ const size = Buffer.byteLength(character, "utf8");
40865
+ if (this.bytes + size > 512 * 1024) {
40866
+ this.truncated = true;
40867
+ break;
40868
+ }
40869
+ this.bytes += size;
40870
+ this.text += character;
40871
+ if (this.text.length >= 16 * 1024)
40872
+ this.flush(false, false);
40873
+ }
40874
+ }
40875
+ finish(complete) {
40876
+ if (this.bytes)
40877
+ this.flush(true, complete && (this.source ? this.completedSources.get(this.source) ?? true : true));
40878
+ this.source = void 0;
40879
+ this.bytes = 0;
40880
+ this.index = 0;
40881
+ this.truncated = false;
40882
+ }
40883
+ flush(final, complete) {
40884
+ this.source?.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
40885
+ section: ETelemetryContentSection.MODEL_OUTPUT,
40886
+ value: this.text,
40887
+ chunkIndex: this.index++,
40888
+ final,
40889
+ availability: final && complete && !this.truncated ? "available" : "partial"
40890
+ });
40891
+ this.text = "";
40892
+ }
40893
+ };
40894
+
40798
40895
  // ../linkque-agent-runtime/dist/esm/core/telemetry/runtimeErrorBoundary.js
40799
40896
  var ERROR_FLUSH_TIMEOUT_MS = 200;
40800
40897
  async function* withRuntimeErrorBoundary(telemetry, input, run, signal) {
@@ -40833,6 +40930,96 @@ async function* withRuntimeErrorBoundary(telemetry, input, run, signal) {
40833
40930
  }
40834
40931
  }
40835
40932
 
40933
+ // ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
40934
+ var validatePlugins = (plugins) => {
40935
+ const names = /* @__PURE__ */ new Set();
40936
+ for (const plugin of plugins) {
40937
+ const name = plugin.name.trim();
40938
+ if (!name) {
40939
+ throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
40940
+ }
40941
+ if (names.has(name)) {
40942
+ throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
40943
+ }
40944
+ names.add(name);
40945
+ }
40946
+ return plugins;
40947
+ };
40948
+ function assertAgentConfigRoot(value, pluginName) {
40949
+ if (typeof value !== "object" || value === null || !("agent" in value)) {
40950
+ throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
40951
+ }
40952
+ }
40953
+ var applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
40954
+ const validatedPlugins = validatePlugins(plugins);
40955
+ const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
40956
+ if (modifiers.length === 0)
40957
+ return agentConfig;
40958
+ let current = structuredClone(agentConfig);
40959
+ for (const plugin of modifiers) {
40960
+ try {
40961
+ const modified = plugin.modifyAgentConfig?.(current);
40962
+ if (modified !== void 0) {
40963
+ assertAgentConfigRoot(modified, plugin.name);
40964
+ current = modified;
40965
+ }
40966
+ current = structuredClone(current);
40967
+ } catch (error) {
40968
+ throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error });
40969
+ }
40970
+ }
40971
+ return current;
40972
+ };
40973
+ var MergedHookExecutorHandler = class {
40974
+ executorByName;
40975
+ constructor(executorByName) {
40976
+ this.executorByName = executorByName;
40977
+ }
40978
+ matches(resource, stage, subject) {
40979
+ const executor = this.executorByName.get(resource.config.executorName);
40980
+ return executor?.matches?.(resource, stage, subject) ?? true;
40981
+ }
40982
+ async execute(resource, context, options) {
40983
+ const executor = this.executorByName.get(resource.config.executorName);
40984
+ if (executor)
40985
+ return executor.execute(resource, context, options);
40986
+ return {
40987
+ ok: true,
40988
+ skipped: true,
40989
+ code: "PLUGIN_EXECUTOR_NOT_FOUND",
40990
+ message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
40991
+ };
40992
+ }
40993
+ };
40994
+ var resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
40995
+ const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
40996
+ executor,
40997
+ source: `plugin:${plugin.name}[${index2}]`
40998
+ })));
40999
+ entries.push(...portHookExecutorList.map((executor, index2) => ({
41000
+ executor,
41001
+ source: `ports.hookExecutorList[${index2}]`
41002
+ })));
41003
+ if (entries.length === 0)
41004
+ return void 0;
41005
+ const merged = /* @__PURE__ */ new Map();
41006
+ for (const entry of entries) {
41007
+ const name = entry.executor.name;
41008
+ if (!name.trim())
41009
+ throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
41010
+ const previous = merged.get(name);
41011
+ if (previous) {
41012
+ try {
41013
+ debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
41014
+ } catch {
41015
+ }
41016
+ }
41017
+ merged.set(name, entry);
41018
+ }
41019
+ const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
41020
+ return new MergedHookExecutorHandler(executorByName);
41021
+ };
41022
+
40836
41023
  // ../linkque-agent-runtime/dist/esm/core/cardSourceResult.js
40837
41024
  import { randomUUID as randomUUID3 } from "node:crypto";
40838
41025
  var MAX_RECEIPT_BYTES = 1e5;
@@ -41280,6 +41467,7 @@ var CardRenderMcpServer = class {
41280
41467
  toolByName = /* @__PURE__ */ new Map();
41281
41468
  sourceResultByRef = /* @__PURE__ */ new Map();
41282
41469
  activeCardId;
41470
+ deliveries = /* @__PURE__ */ new WeakMap();
41283
41471
  closed = false;
41284
41472
  invalidCards = [];
41285
41473
  /** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
@@ -41316,7 +41504,11 @@ var CardRenderMcpServer = class {
41316
41504
  });
41317
41505
  continue;
41318
41506
  }
41319
- const state2 = { selected: false, results: /* @__PURE__ */ new Map() };
41507
+ const state2 = {
41508
+ selected: false,
41509
+ results: /* @__PURE__ */ new Map(),
41510
+ executionId: void 0
41511
+ };
41320
41512
  this.states.set(resource.resourceId, state2);
41321
41513
  const finishName = createCardFinishToolName(resource.resourceId);
41322
41514
  const readName = createCardSourceReadToolName(resource.resourceId);
@@ -41332,7 +41524,9 @@ var CardRenderMcpServer = class {
41332
41524
  properties: {},
41333
41525
  additionalProperties: false
41334
41526
  },
41335
- execute: async () => {
41527
+ execute: async (_args, _signal, context) => {
41528
+ state2.executionId = context?.toolCallId;
41529
+ this.observeCard(context, resource, config, "prepare", state2.executionId);
41336
41530
  for (const candidate of this.states.values())
41337
41531
  candidate.selected = false;
41338
41532
  this.activeCardId = resource.resourceId;
@@ -41370,6 +41564,8 @@ var CardRenderMcpServer = class {
41370
41564
  inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
41371
41565
  outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
41372
41566
  execute: async (args, signal, context) => {
41567
+ const executionId = state2.executionId;
41568
+ this.observeCard(context, resource, config, "source", executionId, source.sourceId);
41373
41569
  if (!state2.selected || this.activeCardId !== resource.resourceId)
41374
41570
  throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
41375
41571
  const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
@@ -41413,7 +41609,10 @@ var CardRenderMcpServer = class {
41413
41609
  signal?.throwIfAborted();
41414
41610
  if (this.closed)
41415
41611
  throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
41416
- this.sourceResultByRef.set(cacheEntry.resultRef, cacheEntry);
41612
+ this.sourceResultByRef.set(cacheEntry.resultRef, {
41613
+ ...cacheEntry,
41614
+ executionId
41615
+ });
41417
41616
  this.logMetric(() => `source=${source.sourceId} mcpMs=${projectionStartedAt - mcpStartedAt} projectionMs=${Date.now() - projectionStartedAt} rawBytes=${byteLength(structured)} receiptBytes=${byteLength(receipt)}`);
41418
41617
  return receipt;
41419
41618
  }
@@ -41427,17 +41626,18 @@ var CardRenderMcpServer = class {
41427
41626
  description: "\u8BFB\u53D6\u672C\u8F6E\u5DF2\u6210\u529F\u6267\u884C\u7684\u6570\u636E\u6E90\u7F13\u5B58\uFF0C\u4E0D\u4F1A\u518D\u6B21\u8C03\u7528 MCP\u3002\u4EC5\u5F53\u6570\u636E\u6E90\u56DE\u6267\u7F3A\u5C11\u51B3\u7B56\u6240\u9700\u5B57\u6BB5\u3001\u6807\u8BB0\u4E3A\u4E0D\u5B8C\u6574\uFF0C\u6216\u540E\u7EED\u5DE5\u5177\u9700\u8981\u672A\u7ED1\u5B9A\u5B57\u6BB5\u65F6\u8C03\u7528\u3002\u4F18\u5148\u8BFB\u53D6 bound \u89C6\u56FE\uFF1B\u8BFB\u53D6\u96C6\u5408\u540E\u7EED\u6761\u76EE\u65F6\uFF0C\u628A\u56DE\u6267 fields.path \u4F5C\u4E3A path \u5E76\u8BBE\u7F6E offset/limit\uFF1B\u53EA\u6709\u672A\u7ED1\u5B9A\u5B57\u6BB5\u624D\u4F7F\u7528 raw\u3002\u4E0D\u8981\u628A\u5206\u9875\u6216\u622A\u65AD\u7ED3\u679C\u5F53\u4F5C\u5168\u96C6\u3002",
41428
41627
  inputSchema: CARD_SOURCE_READ_INPUT_SCHEMA,
41429
41628
  outputSchema: CARD_SOURCE_READ_OUTPUT_SCHEMA,
41430
- execute: async (args) => {
41629
+ execute: async (args, _signal, context) => {
41431
41630
  const resultRef = readResultRef(args);
41631
+ const entry = this.sourceResultByRef.get(resultRef);
41632
+ const matchingEntry = entry?.cardId === resource.resourceId ? entry : void 0;
41633
+ this.observeCard(context, resource, config, "read", matchingEntry?.executionId);
41432
41634
  if (this.closed)
41433
41635
  throw new Error(`\u7F13\u5B58\u5DF2\u5931\u6548: ${resultRef}`);
41434
- const entry = this.sourceResultByRef.get(resultRef);
41435
- if (!entry || entry.cardId !== resource.resourceId) {
41636
+ if (!matchingEntry)
41436
41637
  throw new Error(`\u672A\u77E5\u7ED3\u679C\u5F15\u7528: ${resultRef}`);
41437
- }
41438
41638
  const startedAt = Date.now();
41439
- const receipt = readCardSourceResult(entry, args);
41440
- this.logMetric(() => `source=${entry.sourceId} cacheReadMs=${Date.now() - startedAt} receiptBytes=${byteLength(receipt)}`);
41639
+ const receipt = readCardSourceResult(matchingEntry, args);
41640
+ this.logMetric(() => `source=${matchingEntry.sourceId} cacheReadMs=${Date.now() - startedAt} receiptBytes=${byteLength(receipt)}`);
41441
41641
  return receipt;
41442
41642
  }
41443
41643
  });
@@ -41465,12 +41665,15 @@ ${AFTER_CARD_DESCRIPTION}`,
41465
41665
  },
41466
41666
  additionalProperties: false
41467
41667
  },
41468
- execute: async (args, signal) => {
41668
+ execute: async (args, signal, context) => {
41669
+ this.observeCard(context, resource, config, "finish", state2.executionId);
41469
41670
  if (!state2.selected || this.activeCardId !== resource.resourceId)
41470
41671
  throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
41471
41672
  const afterCard = readAfterCard(args);
41472
41673
  const finishStartedAt = Date.now();
41473
41674
  const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
41675
+ if (context?.observation)
41676
+ this.deliveries.set(result.card, context.observation);
41474
41677
  if (afterCard !== void 0) {
41475
41678
  this.companions.set(result, afterCard);
41476
41679
  result.modelText += `
@@ -41502,7 +41705,11 @@ ${AFTER_CARD_DESCRIPTION}`,
41502
41705
  throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
41503
41706
  return descriptor.execute(args, signal, options?.context);
41504
41707
  }
41505
- return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
41708
+ this.observeCard(options?.context, resource, config, "finish", options?.context?.toolCallId);
41709
+ const result = await executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
41710
+ if (options?.context?.observation)
41711
+ this.deliveries.set(result.card, options.context.observation);
41712
+ return result;
41506
41713
  }
41507
41714
  async close() {
41508
41715
  this.closed = true;
@@ -41512,6 +41719,17 @@ ${AFTER_CARD_DESCRIPTION}`,
41512
41719
  this.toolByName.clear();
41513
41720
  this.companions = /* @__PURE__ */ new WeakMap();
41514
41721
  }
41722
+ /** 记录执行时配置和显式关联,不从工具名称反推业务身份。 */
41723
+ observeCard(context, resource, config, phase, executionId, sourceId) {
41724
+ context?.observation?.record(ETelemetryEventName.TOOL_CONTEXT, {
41725
+ [ETelemetryAttribute.LINKQUE_CARD_REF]: resource.resourceId,
41726
+ [ETelemetryAttribute.LINKQUE_CARD_REVISION]: config.revision,
41727
+ [ETelemetryAttribute.LINKQUE_CARD_DISPLAY_NAME]: config.displayName,
41728
+ [ETelemetryAttribute.LINKQUE_CARD_PHASE]: phase,
41729
+ ...executionId ? { [ETelemetryAttribute.LINKQUE_CARD_EXECUTION_ID]: executionId } : {},
41730
+ ...sourceId ? { [ETelemetryAttribute.LINKQUE_CARD_SOURCE_ID]: sourceId } : {}
41731
+ });
41732
+ }
41515
41733
  logMetric(message) {
41516
41734
  try {
41517
41735
  if (!this.debugLog)
@@ -41521,7 +41739,7 @@ ${AFTER_CARD_DESCRIPTION}`,
41521
41739
  }
41522
41740
  }
41523
41741
  /** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
41524
- async *projectConversation(events) {
41742
+ async *projectConversation(events, publicOutput) {
41525
41743
  const pending = /* @__PURE__ */ new WeakMap();
41526
41744
  let cardOwnsText = false;
41527
41745
  for await (const event of events) {
@@ -41538,13 +41756,24 @@ ${AFTER_CARD_DESCRIPTION}`,
41538
41756
  if (event.type === "a2ui_card" && pending.has(event)) {
41539
41757
  this.logMetric(`phase=card-event-emitted atMs=${Date.now()}`);
41540
41758
  }
41759
+ if (event.type === "a2ui_card") {
41760
+ this.deliveries.get(event)?.record(ETelemetryEventName.TOOL_CONTEXT, {
41761
+ [ETelemetryAttribute.LINKQUE_CARD_DELIVERY]: "emitted"
41762
+ });
41763
+ }
41541
41764
  yield event;
41542
41765
  if (event.type === "a2ui_card" && pending.has(event)) {
41543
41766
  const text2 = pending.get(event);
41544
41767
  pending.delete(event);
41545
41768
  cardOwnsText = true;
41546
- if (text2)
41547
- yield { type: "delta", content: text2 };
41769
+ if (text2) {
41770
+ const companion = { type: "delta", content: text2 };
41771
+ const source = this.deliveries.get(event);
41772
+ publicOutput?.associate(companion, source);
41773
+ publicOutput?.completeSource(source, true);
41774
+ yield companion;
41775
+ }
41776
+ this.deliveries.delete(event);
41548
41777
  }
41549
41778
  }
41550
41779
  }
@@ -41687,96 +41916,6 @@ var NoopKnowledgeSearchPort = class {
41687
41916
  }
41688
41917
  };
41689
41918
 
41690
- // ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
41691
- var validatePlugins = (plugins) => {
41692
- const names = /* @__PURE__ */ new Set();
41693
- for (const plugin of plugins) {
41694
- const name = plugin.name.trim();
41695
- if (!name) {
41696
- throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
41697
- }
41698
- if (names.has(name)) {
41699
- throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
41700
- }
41701
- names.add(name);
41702
- }
41703
- return plugins;
41704
- };
41705
- function assertAgentConfigRoot(value, pluginName) {
41706
- if (typeof value !== "object" || value === null || !("agent" in value)) {
41707
- throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
41708
- }
41709
- }
41710
- var applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
41711
- const validatedPlugins = validatePlugins(plugins);
41712
- const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
41713
- if (modifiers.length === 0)
41714
- return agentConfig;
41715
- let current = structuredClone(agentConfig);
41716
- for (const plugin of modifiers) {
41717
- try {
41718
- const modified = plugin.modifyAgentConfig?.(current);
41719
- if (modified !== void 0) {
41720
- assertAgentConfigRoot(modified, plugin.name);
41721
- current = modified;
41722
- }
41723
- current = structuredClone(current);
41724
- } catch (error) {
41725
- throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error });
41726
- }
41727
- }
41728
- return current;
41729
- };
41730
- var MergedHookExecutorHandler = class {
41731
- executorByName;
41732
- constructor(executorByName) {
41733
- this.executorByName = executorByName;
41734
- }
41735
- matches(resource, stage, subject) {
41736
- const executor = this.executorByName.get(resource.config.executorName);
41737
- return executor?.matches?.(resource, stage, subject) ?? true;
41738
- }
41739
- async execute(resource, context, options) {
41740
- const executor = this.executorByName.get(resource.config.executorName);
41741
- if (executor)
41742
- return executor.execute(resource, context, options);
41743
- return {
41744
- ok: true,
41745
- skipped: true,
41746
- code: "PLUGIN_EXECUTOR_NOT_FOUND",
41747
- message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
41748
- };
41749
- }
41750
- };
41751
- var resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
41752
- const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
41753
- executor,
41754
- source: `plugin:${plugin.name}[${index2}]`
41755
- })));
41756
- entries.push(...portHookExecutorList.map((executor, index2) => ({
41757
- executor,
41758
- source: `ports.hookExecutorList[${index2}]`
41759
- })));
41760
- if (entries.length === 0)
41761
- return void 0;
41762
- const merged = /* @__PURE__ */ new Map();
41763
- for (const entry of entries) {
41764
- const name = entry.executor.name;
41765
- if (!name.trim())
41766
- throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
41767
- const previous = merged.get(name);
41768
- if (previous) {
41769
- try {
41770
- debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
41771
- } catch {
41772
- }
41773
- }
41774
- merged.set(name, entry);
41775
- }
41776
- const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
41777
- return new MergedHookExecutorHandler(executorByName);
41778
- };
41779
-
41780
41919
  // ../linkque-agent-runtime/dist/esm/core/agentRuntime.js
41781
41920
  var DEFAULT_HARNESS_PROMPT = `# Harness \u8FD0\u884C\u89C4\u7EA6
41782
41921
 
@@ -41941,11 +42080,38 @@ var AgentRuntime = class _AgentRuntime {
41941
42080
  }
41942
42081
  }, (observation) => this.runObservedAdvance(request, auth, options, observation), options.signal);
41943
42082
  }
42083
+ /**
42084
+ * 记录本次用户输入(RFC §4.1):取进入 Runtime 的本次新消息中最后一条 user message
42085
+ * 的 content,作为 `linkque.content.recorded` 的 body 走 record 链路落入
42086
+ * OTLP logs(body 含 section/value/availability)。不以模型 messages 上下文为输入;
42087
+ * 无 user 文本(卡片交互等)时按可用性如实标记,不伪造自然语言 Query。
42088
+ */
42089
+ recordCurrentQuery(observation, request) {
42090
+ let lastUser;
42091
+ for (const message of request.messages) {
42092
+ if (message.role === "user")
42093
+ lastUser = message;
42094
+ }
42095
+ const content = lastUser?.content;
42096
+ const text2 = typeof content === "string" && content ? content : void 0;
42097
+ const value = text2?.slice(0, CONTENT_VALUE_MAX_LENGTH);
42098
+ const truncated = text2 !== void 0 && text2.length > CONTENT_VALUE_MAX_LENGTH;
42099
+ const card = content && typeof content === "object" && "type" in content && content.type === "a2ui.event" ? content : void 0;
42100
+ const displayText = card && "displayText" in card && typeof card.displayText === "string" && card.displayText ? card.displayText : void 0;
42101
+ const body = {
42102
+ section: ETelemetryContentSection.QUERY_INPUT,
42103
+ ...value !== void 0 ? { value } : {},
42104
+ ...card ? { inputType: "card", ...displayText ? { displayText } : {} } : {},
42105
+ availability: text2 !== void 0 || card ? "available" : "not_recorded"
42106
+ };
42107
+ observation.record(ETelemetryEventName.CONTENT_RECORDED, { [ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED]: truncated }, body);
42108
+ }
41944
42109
  async *runObservedAdvance(request, auth, options, observation) {
41945
42110
  observation.record(ETelemetryEventName.TELEMETRY_COVERAGE, {
41946
42111
  [ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCoverage.PI_MODEL_TOOL_HOOK : ETelemetryCoverage.CORE_ONLY,
41947
42112
  [ETelemetryAttribute.HARNESS_TELEMETRY_COMPLETENESS]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCompleteness.COMPLETE : ETelemetryCompleteness.PARTIAL
41948
42113
  });
42114
+ this.recordCurrentQuery(observation, request);
41949
42115
  const cleanup = [];
41950
42116
  let termination = ETelemetryStreamTermination.CANCEL;
41951
42117
  let failed = false;
@@ -42216,8 +42382,11 @@ var AgentRuntime = class _AgentRuntime {
42216
42382
  ...assistantText !== "" && { messageContent: assistantText }
42217
42383
  });
42218
42384
  };
42385
+ const publicOutput = new PublicOutputObservation(observation);
42386
+ agentReq.publicOutput = publicOutput;
42219
42387
  try {
42220
- for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
42388
+ for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq), publicOutput)) {
42389
+ publicOutput.accept(ev);
42221
42390
  if (ev.type === "delta")
42222
42391
  assistantText += ev.content;
42223
42392
  if (ev.type === "tool_end" && !ev.isError) {
@@ -42279,6 +42448,7 @@ var AgentRuntime = class _AgentRuntime {
42279
42448
  await dispatchTerminalHook();
42280
42449
  yield ev;
42281
42450
  }
42451
+ publicOutput.finish(true);
42282
42452
  await dispatchTerminalHook();
42283
42453
  } catch (error) {
42284
42454
  if (!terminalHookDispatched) {
@@ -42289,6 +42459,8 @@ var AgentRuntime = class _AgentRuntime {
42289
42459
  await dispatchTerminalHook();
42290
42460
  }
42291
42461
  throw error;
42462
+ } finally {
42463
+ publicOutput.finish(false);
42292
42464
  }
42293
42465
  }
42294
42466
  };
@@ -43058,10 +43230,10 @@ function resolveLinkqueEndpoints(env, envSelector) {
43058
43230
  }
43059
43231
  function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
43060
43232
  const log = (...a) => logCtx?.log?.("[runtime-factory]", ...a);
43061
- const debugLog = logCtx?.log ? (line, scope) => {
43233
+ const debugLog = logCtx?.log ? createRuntimeDebugLog(new AppbaseRuntimeConfigProvider(env).get("LOG_LEVEL"), (line, scope) => {
43062
43234
  const prefix = scope ? `[${scope}] ` : "";
43063
43235
  logCtx.log?.(prefix + line);
43064
- } : void 0;
43236
+ }) : void 0;
43065
43237
  const runtimePorts = {};
43066
43238
  if (ports.telemetry)
43067
43239
  runtimePorts.telemetry = ports.telemetry;
@@ -3,11 +3,11 @@ import {
3
3
  runClientCapability,
4
4
  runClientCapabilityCleanup,
5
5
  runClientCapabilityResult
6
- } from "../../chunk-CUMXO6KK.js";
6
+ } from "../../chunk-STGFILDE.js";
7
7
  import "../../chunk-IWOFD643.js";
8
8
  import "../../chunk-PXCGFBV5.js";
9
9
  import "../../chunk-ETG6PNHQ.js";
10
- import "../../chunk-OHRCYI66.js";
10
+ import "../../chunk-PM2UO433.js";
11
11
  import "../../chunk-EAODRPW4.js";
12
12
  import "../../chunk-XUFLSZM4.js";
13
13
  import "../../chunk-GAYNLDWK.js";