linkque-cli-v2 1.4.2 → 1.4.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.
package/worker.js CHANGED
@@ -45,6 +45,7 @@ var init_types = __esm({
45
45
  EDebugLogScope2["LLM"] = "LLM";
46
46
  EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
47
47
  EDebugLogScope2["MCP"] = "MCP";
48
+ EDebugLogScope2["SKILL"] = "SKILL";
48
49
  EDebugLogScope2["HTTP"] = "HTTP";
49
50
  EDebugLogScope2["HOOK"] = "HOOK";
50
51
  })(EDebugLogScope || (EDebugLogScope = {}));
@@ -4361,13 +4362,14 @@ var require_fast_uri = __commonJS({
4361
4362
  if (!malformedIPLiteral) {
4362
4363
  malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP2);
4363
4364
  }
4364
- if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4365
- if (uri.indexOf("%") !== -1) {
4366
- if (parsed.host !== void 0 && !malformedIPLiteral) {
4367
- const host = isIP2 ? parsed.host : normalizePercentEncoding(parsed.host, true);
4368
- parsed.host = reescapeHostDelimiters(host, isIP2);
4369
- }
4365
+ if (uri.indexOf("%") !== -1 && parsed.host !== void 0 && !malformedIPLiteral) {
4366
+ let host = isIP2 ? parsed.host : normalizePercentEncoding(parsed.host, true);
4367
+ if (!isIP2) {
4368
+ host = normalizePercentEncoding(host.toLowerCase());
4370
4369
  }
4370
+ parsed.host = reescapeHostDelimiters(host, isIP2);
4371
+ }
4372
+ if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4371
4373
  if (parsed.path) {
4372
4374
  parsed.path = normalizePathEncoding(parsed.path);
4373
4375
  }
@@ -12015,6 +12017,10 @@ var init_mcpProxyTool = __esm({
12015
12017
  context: context2
12016
12018
  });
12017
12019
  return entry.server.callTool(tool.name, args, sig, {
12020
+ toolSchema: {
12021
+ inputSchema: tool.inputSchema,
12022
+ outputSchema: tool.outputSchema
12023
+ },
12018
12024
  ...headers ? { headers } : {},
12019
12025
  ...context2 ? { context: context2 } : {}
12020
12026
  });
@@ -12262,6 +12268,10 @@ ${formatSchema(tool.inputSchema)}`);
12262
12268
  context: context2
12263
12269
  });
12264
12270
  const result = await entry.server.callTool(tool.name, args, signal, {
12271
+ toolSchema: {
12272
+ inputSchema: tool.inputSchema,
12273
+ outputSchema: tool.outputSchema
12274
+ },
12265
12275
  ...headers ? { headers } : {},
12266
12276
  ...context2 ? { context: context2 } : {}
12267
12277
  });
@@ -12627,7 +12637,7 @@ var init_hookRegistry = __esm({
12627
12637
  });
12628
12638
 
12629
12639
  // ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
12630
- var ETelemetryAttribute, ETelemetryEventPrefix, ETelemetryEventPhase, ETelemetryEventName, ETelemetryOperationName, ETelemetryOutcome, ETelemetrySignal, ETelemetryLossReason, ETelemetryAdvanceOutcome, ETelemetryStreamTermination, ETelemetryCancelSource, ETelemetryObservationBoundary, ETelemetryRemoteCompletion, ETelemetryCommitStatus, ETelemetryHookMode, ETelemetryHookResult, ETelemetrySource, ETelemetryEvidence, ETelemetryCompleteness, ETelemetryCoverage, ETelemetryUsageSource, ETelemetryAttemptVisibility, ETelemetryLinkRelation, ETelemetryToolFailureStage, ETelemetryTerminalEvidence, ETelemetryTerminalSource, ETelemetryModelPurpose, ETelemetryErrorType, ETelemetrySpanKind, ETelemetryGenAiOperation, ETelemetryVersion;
12640
+ var ETelemetryAttribute, ETelemetryEventPrefix, ETelemetryEventPhase, ETelemetryEventName, ETelemetryContentSection, ETelemetryOperationName, ETelemetryOutcome, ETelemetrySignal, ETelemetryLossReason, ETelemetryAdvanceOutcome, ETelemetryStreamTermination, ETelemetryCancelSource, ETelemetryObservationBoundary, ETelemetryRemoteCompletion, ETelemetryCommitStatus, ETelemetryHookMode, ETelemetryHookResult, ETelemetrySource, ETelemetryEvidence, ETelemetryCompleteness, ETelemetryCoverage, ETelemetryUsageSource, ETelemetryAttemptVisibility, ETelemetryLinkRelation, ETelemetryToolFailureStage, ETelemetryTerminalEvidence, ETelemetryTerminalSource, ETelemetryModelPurpose, ETelemetryErrorType, ETelemetrySpanKind, ETelemetryGenAiOperation, ETelemetryVersion;
12631
12641
  var init_telemetryEnums = __esm({
12632
12642
  "../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js"() {
12633
12643
  "use strict";
@@ -12786,7 +12796,20 @@ var init_telemetryEnums = __esm({
12786
12796
  ETelemetryEventName2["HISTORY_APPEND_FINISHED"] = "linkque.history.append.finished";
12787
12797
  ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
12788
12798
  ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
12799
+ ETelemetryEventName2["DEBUG_CONTENT_RECORDED"] = "linkque.debug.content.recorded";
12789
12800
  })(ETelemetryEventName || (ETelemetryEventName = {}));
12801
+ (function(ETelemetryContentSection2) {
12802
+ ETelemetryContentSection2["QUERY_INPUT"] = "query.input";
12803
+ ETelemetryContentSection2["TOOL_INPUT"] = "tool.input";
12804
+ ETelemetryContentSection2["TOOL_OUTPUT"] = "tool.output";
12805
+ ETelemetryContentSection2["MCP_REQUESTED_INPUT"] = "mcp.requested_input";
12806
+ ETelemetryContentSection2["MCP_INPUT"] = "mcp.input";
12807
+ ETelemetryContentSection2["MCP_OUTPUT"] = "mcp.output";
12808
+ ETelemetryContentSection2["SKILL_INPUT"] = "skill.input";
12809
+ ETelemetryContentSection2["SKILL_OUTPUT"] = "skill.output";
12810
+ ETelemetryContentSection2["KNOWLEDGE_INPUT"] = "knowledge.input";
12811
+ ETelemetryContentSection2["KNOWLEDGE_OUTPUT"] = "knowledge.output";
12812
+ })(ETelemetryContentSection || (ETelemetryContentSection = {}));
12790
12813
  (function(ETelemetryOperationName2) {
12791
12814
  ETelemetryOperationName2["OPERATION"] = "linkque.operation";
12792
12815
  ETelemetryOperationName2["TOOL_INVOKE"] = "harness.tool.invoke";
@@ -14184,6 +14207,43 @@ var init_linkquegwEventHookExecutor = __esm({
14184
14207
  }
14185
14208
  });
14186
14209
 
14210
+ // ../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js
14211
+ function recordContentSection(observation, section, value, availability = "available") {
14212
+ observation?.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, { section, value, availability });
14213
+ }
14214
+ function recordMcpContentSection(observation, section, value, schema) {
14215
+ if (!observation)
14216
+ return;
14217
+ const fieldTitles = {};
14218
+ const visit = (node, path9) => {
14219
+ if (!node || typeof node !== "object" || Array.isArray(node))
14220
+ return;
14221
+ const definition = node;
14222
+ if (path9 && typeof definition.title === "string" && definition.title.trim())
14223
+ fieldTitles[path9] = definition.title;
14224
+ const properties = definition.properties;
14225
+ if (properties && typeof properties === "object" && !Array.isArray(properties)) {
14226
+ for (const [key, child] of Object.entries(properties))
14227
+ visit(child, `${path9}/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`);
14228
+ }
14229
+ if (definition.items)
14230
+ visit(definition.items, `${path9}/*`);
14231
+ };
14232
+ visit(schema, section === ETelemetryContentSection.MCP_OUTPUT ? "/structuredContent" : "");
14233
+ observation.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, {
14234
+ section,
14235
+ value,
14236
+ availability: "available",
14237
+ ...Object.keys(fieldTitles).length ? { fieldTitles } : {}
14238
+ });
14239
+ }
14240
+ var init_contentRecording = __esm({
14241
+ "../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js"() {
14242
+ "use strict";
14243
+ init_telemetry();
14244
+ }
14245
+ });
14246
+
14187
14247
  // ../linkque-agent-runtime/dist/esm/core/skillTools.js
14188
14248
  function parseSkillFile(raw, fallbackName) {
14189
14249
  const parsed = splitFrontmatter(raw);
@@ -14252,18 +14312,45 @@ function createActivateSkillTool(records) {
14252
14312
  required: ["name"],
14253
14313
  additionalProperties: false
14254
14314
  },
14255
- execute: async (args) => {
14315
+ execute: async (args, _signal, context2) => {
14256
14316
  const name = extractName(args);
14257
- if (!name)
14317
+ const startedAt = Date.now();
14318
+ const obs = context2?.observation;
14319
+ recordContentSection(obs, ETelemetryContentSection.SKILL_INPUT, {
14320
+ name: name ?? null
14321
+ });
14322
+ if (!name) {
14323
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14324
+ status: "failed",
14325
+ error: "\u7F3A\u5C11 name \u53C2\u6570",
14326
+ durationMs: Date.now() - startedAt
14327
+ });
14258
14328
  return "\u6FC0\u6D3B\u6280\u80FD\u5931\u8D25:\u7F3A\u5C11 name \u53C2\u6570\u3002";
14329
+ }
14259
14330
  if (!bodyByName.has(name)) {
14331
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14332
+ name,
14333
+ status: "failed",
14334
+ error: `\u672A\u627E\u5230\u6280\u80FD "${name}"`,
14335
+ durationMs: Date.now() - startedAt
14336
+ });
14260
14337
  return `\u6FC0\u6D3B\u6280\u80FD\u5931\u8D25:\u672A\u627E\u5230\u6280\u80FD "${name}"\u3002\u53EF\u7528:${[...bodyByName.keys()].join(", ")}`;
14261
14338
  }
14262
14339
  if (activated.has(name)) {
14340
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14341
+ name,
14342
+ status: "already_loaded",
14343
+ durationMs: Date.now() - startedAt
14344
+ });
14263
14345
  return `\u6280\u80FD "${name}" \u5DF2\u5728\u672C\u8F6E\u52A0\u8F7D,\u65E0\u9700\u91CD\u590D\u6FC0\u6D3B\u3002`;
14264
14346
  }
14265
14347
  activated.add(name);
14266
14348
  const body = bodyByName.get(name) ?? "";
14349
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14350
+ name,
14351
+ status: "loaded",
14352
+ durationMs: Date.now() - startedAt
14353
+ });
14267
14354
  return `<skill name="${escapeXml(name)}">
14268
14355
  ${body}
14269
14356
  </skill>`;
@@ -14321,6 +14408,8 @@ var ACTIVATE_SKILL_TOOL_NAME, AVAILABLE_SKILLS_OPEN, AVAILABLE_SKILLS_CLOSE;
14321
14408
  var init_skillTools = __esm({
14322
14409
  "../linkque-agent-runtime/dist/esm/core/skillTools.js"() {
14323
14410
  "use strict";
14411
+ init_telemetry();
14412
+ init_contentRecording();
14324
14413
  ACTIVATE_SKILL_TOOL_NAME = "activate_skill";
14325
14414
  AVAILABLE_SKILLS_OPEN = "<available_skills>";
14326
14415
  AVAILABLE_SKILLS_CLOSE = "</available_skills>";
@@ -14548,7 +14637,7 @@ function createKnowledgeTools(resources, searchPort, agentId) {
14548
14637
  additionalProperties: false
14549
14638
  },
14550
14639
  annotations: { readOnlyHint: true },
14551
- execute: () => listKnowledge()
14640
+ execute: (_args, _signal, context2) => listKnowledge(context2)
14552
14641
  },
14553
14642
  {
14554
14643
  name: KNOWLEDGE_RECALL_TOOL_NAME,
@@ -14575,24 +14664,48 @@ function createKnowledgeTools(resources, searchPort, agentId) {
14575
14664
  additionalProperties: false
14576
14665
  },
14577
14666
  annotations: { readOnlyHint: true },
14578
- execute: (args, signal) => recallKnowledge(args, signal)
14667
+ execute: (args, signal, context2) => recallKnowledge(args, signal, context2)
14579
14668
  }
14580
14669
  ];
14581
- async function listKnowledge() {
14582
- return { knowledgeBases: await getKnowledgeBases() };
14670
+ async function listKnowledge(context2) {
14671
+ const result = { knowledgeBases: await getKnowledgeBases() };
14672
+ recordContentSection(context2?.observation, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14673
+ knowledgeBases: result.knowledgeBases.map((kb) => ({
14674
+ knowledgeBaseId: kb.knowledgeBaseId,
14675
+ knowledgeDesc: kb.knowledgeDesc
14676
+ }))
14677
+ });
14678
+ return result;
14583
14679
  }
14584
- async function recallKnowledge(args, signal) {
14680
+ async function recallKnowledge(args, signal, context2) {
14585
14681
  const parsed = parseRecallArgs(args);
14682
+ const obs = context2?.observation;
14586
14683
  if ("error" in parsed) {
14684
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_INPUT, {
14685
+ error: parsed.error
14686
+ });
14687
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14688
+ status: "failed",
14689
+ hits: [],
14690
+ error: parsed.error
14691
+ });
14587
14692
  return { hits: [], error: parsed.error };
14588
14693
  }
14694
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_INPUT, {
14695
+ knowledgeBaseId: parsed.knowledgeBaseId,
14696
+ query: parsed.query,
14697
+ topK: parsed.topK
14698
+ });
14589
14699
  const knowledgeBases = await getKnowledgeBases();
14590
14700
  const bound = knowledgeBases.some((info) => info.knowledgeBaseId === parsed.knowledgeBaseId);
14591
14701
  if (!bound) {
14592
- return {
14702
+ const error40 = `knowledgeBaseId \u672A\u7ED1\u5B9A: ${parsed.knowledgeBaseId}\u3002\u8BF7\u5148\u8C03\u7528 knowledge_list \u67E5\u770B\u53EF\u7528\u77E5\u8BC6\u5E93\u3002`;
14703
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14704
+ status: "failed",
14593
14705
  hits: [],
14594
- error: `knowledgeBaseId \u672A\u7ED1\u5B9A: ${parsed.knowledgeBaseId}\u3002\u8BF7\u5148\u8C03\u7528 knowledge_list \u67E5\u770B\u53EF\u7528\u77E5\u8BC6\u5E93\u3002`
14595
- };
14706
+ error: error40
14707
+ });
14708
+ return { hits: [], error: error40 };
14596
14709
  }
14597
14710
  try {
14598
14711
  const result = await searchPort.search({
@@ -14601,10 +14714,20 @@ function createKnowledgeTools(resources, searchPort, agentId) {
14601
14714
  agentId,
14602
14715
  topK: parsed.topK
14603
14716
  }, signal);
14717
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14718
+ status: result.hits.length ? "matched" : "no_hits",
14719
+ hits: result.hits
14720
+ });
14604
14721
  return { hits: result.hits };
14605
14722
  } catch (e2) {
14606
14723
  const msg = e2 instanceof Error ? e2.message : String(e2);
14607
- return { hits: [], error: `\u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${msg}` };
14724
+ const error40 = `\u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${msg}`;
14725
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14726
+ status: "failed",
14727
+ hits: [],
14728
+ error: error40
14729
+ });
14730
+ return { hits: [], error: error40 };
14608
14731
  }
14609
14732
  }
14610
14733
  async function getKnowledgeBases() {
@@ -14618,6 +14741,8 @@ var init_createKnowledgeTools = __esm({
14618
14741
  "../linkque-agent-runtime/dist/esm/core/createKnowledgeTools.js"() {
14619
14742
  "use strict";
14620
14743
  init_knowledgeTools();
14744
+ init_telemetry();
14745
+ init_contentRecording();
14621
14746
  }
14622
14747
  });
14623
14748
 
@@ -14648,7 +14773,7 @@ var init_noopRuntimeTelemetry = __esm({
14648
14773
  startOperation(_operation) {
14649
14774
  return this;
14650
14775
  }
14651
- record(_name, _attributes) {
14776
+ record(_name, _attributes, _body) {
14652
14777
  }
14653
14778
  finish(_outcome, _attributes) {
14654
14779
  }
@@ -14746,7 +14871,7 @@ var init_runtimeObservation = __esm({
14746
14871
  find(key) {
14747
14872
  return this.associations.get(key);
14748
14873
  }
14749
- record(name, attributes) {
14874
+ record(name, attributes, body) {
14750
14875
  if (this.abandoned)
14751
14876
  return;
14752
14877
  try {
@@ -14754,7 +14879,7 @@ var init_runtimeObservation = __esm({
14754
14879
  this.resultAttributes = {
14755
14880
  [ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]: attributes[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]
14756
14881
  };
14757
- this.sink.record(name, attributes);
14882
+ this.sink.record(name, attributes, body);
14758
14883
  } catch {
14759
14884
  }
14760
14885
  }
@@ -49081,8 +49206,19 @@ function observeTool(tool, observation) {
49081
49206
  detached: false,
49082
49207
  links: []
49083
49208
  });
49209
+ const captureBody = !isSkillTool(tool);
49084
49210
  try {
49085
- const result = await tool.execute(args, signal, context2);
49211
+ if (captureBody) {
49212
+ recordContentSection(operation, ETelemetryContentSection.TOOL_INPUT, args);
49213
+ }
49214
+ const execContext = {
49215
+ ...context2 ?? { toolCallId: "", emit: () => void 0 },
49216
+ observation: operation
49217
+ };
49218
+ const result = await tool.execute(args, signal, execContext);
49219
+ if (captureBody) {
49220
+ recordContentSection(operation, ETelemetryContentSection.TOOL_OUTPUT, result);
49221
+ }
49086
49222
  operation.finish(toolResultOutcome(result), {
49087
49223
  [ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS]: toolResultOutcome(result)
49088
49224
  });
@@ -49100,13 +49236,16 @@ function observeTool(tool, observation) {
49100
49236
  }
49101
49237
  };
49102
49238
  }
49103
- var import_node_crypto6;
49239
+ var import_node_crypto6, isSkillTool;
49104
49240
  var init_toolObservation = __esm({
49105
49241
  "../linkque-agent-runtime/dist/esm/core/telemetry/toolObservation.js"() {
49106
49242
  "use strict";
49107
49243
  init_telemetry();
49108
49244
  init_telemetryEnums2();
49245
+ init_skillTools();
49109
49246
  import_node_crypto6 = require("node:crypto");
49247
+ init_contentRecording();
49248
+ isSkillTool = (tool) => (tool.modelName ?? tool.name) === ACTIVATE_SKILL_TOOL_NAME;
49110
49249
  }
49111
49250
  });
49112
49251
 
@@ -207422,11 +207561,36 @@ var init_agentRuntime = __esm({
207422
207561
  }
207423
207562
  }, (observation) => this.runObservedAdvance(request, auth2, options, observation), options.signal);
207424
207563
  }
207564
+ /**
207565
+ * 记录本次用户输入(RFC §4.1):取进入 Runtime 的本次新消息中最后一条 user message
207566
+ * 的 content,作为 `linkque.debug.content.recorded` 的 body 走 record 链路落入
207567
+ * OTLP logs(body 含 section/value/availability)。不以模型 messages 上下文为输入;
207568
+ * 无 user 文本(卡片交互等)时按可用性如实标记,不伪造自然语言 Query。
207569
+ */
207570
+ recordCurrentQuery(observation, request) {
207571
+ let lastUser;
207572
+ for (const message of request.messages) {
207573
+ if (message.role === "user")
207574
+ lastUser = message;
207575
+ }
207576
+ const content = lastUser?.content;
207577
+ const text2 = typeof content === "string" && content ? content : void 0;
207578
+ const card = content && typeof content === "object" && "type" in content && content.type === "a2ui.event" ? content : void 0;
207579
+ const displayText = card && "displayText" in card && typeof card.displayText === "string" && card.displayText ? card.displayText : void 0;
207580
+ const body = {
207581
+ section: ETelemetryContentSection.QUERY_INPUT,
207582
+ ...text2 !== void 0 ? { value: text2 } : {},
207583
+ ...card ? { inputType: "card", ...displayText ? { displayText } : {} } : {},
207584
+ availability: text2 !== void 0 || card ? "available" : "not_recorded"
207585
+ };
207586
+ observation.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, body);
207587
+ }
207425
207588
  async *runObservedAdvance(request, auth2, options, observation) {
207426
207589
  observation.record(ETelemetryEventName.TELEMETRY_COVERAGE, {
207427
207590
  [ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCoverage.PI_MODEL_TOOL_HOOK : ETelemetryCoverage.CORE_ONLY,
207428
207591
  [ETelemetryAttribute.HARNESS_TELEMETRY_COMPLETENESS]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCompleteness.COMPLETE : ETelemetryCompleteness.PARTIAL
207429
207592
  });
207593
+ this.recordCurrentQuery(observation, request);
207430
207594
  const cleanup = [];
207431
207595
  let termination = ETelemetryStreamTermination.CANCEL;
207432
207596
  let failed = false;
@@ -208531,6 +208695,22 @@ var EModelRequestSource;
208531
208695
 
208532
208696
  // ../linkque-agent-runtime/dist/esm/core/index.js
208533
208697
  init_types();
208698
+
208699
+ // ../linkque-agent-runtime/dist/esm/core/debugLog.js
208700
+ init_types();
208701
+ function isDebugLoggingEnabled(level) {
208702
+ return level?.trim().toLowerCase() === "debug";
208703
+ }
208704
+ function createRuntimeDebugLog(level, sink) {
208705
+ const debug = isDebugLoggingEnabled(level);
208706
+ return (line, scope) => {
208707
+ if (!debug && (scope === EDebugLogScope.PI_EVENT || scope === EDebugLogScope.HTTP || scope === EDebugLogScope.MCP || scope === EDebugLogScope.SKILL))
208708
+ return;
208709
+ sink(line, scope);
208710
+ };
208711
+ }
208712
+
208713
+ // ../linkque-agent-runtime/dist/esm/core/index.js
208534
208714
  init_esm();
208535
208715
  init_cardTools();
208536
208716
  init_mcpNaming();
@@ -214525,6 +214705,10 @@ init_esm();
214525
214705
 
214526
214706
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
214527
214707
  var import_node_async_hooks2 = require("node:async_hooks");
214708
+ init_telemetry();
214709
+ init_logFailure();
214710
+ init_contentRecording();
214711
+ init_types();
214528
214712
 
214529
214713
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/linkquegwTokenVerifier.js
214530
214714
  init_config();
@@ -214571,8 +214755,6 @@ var LinkquegwTokenVerifier = class {
214571
214755
  };
214572
214756
 
214573
214757
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
214574
- init_types();
214575
- init_logFailure();
214576
214758
  var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
214577
214759
  agentId: config2.agentId,
214578
214760
  signEndpoint: config2.signEndpoint,
@@ -214623,7 +214805,14 @@ var RemoteGatewayMcpServerProvider = class {
214623
214805
  if (!this.debugLog)
214624
214806
  return;
214625
214807
  try {
214626
- this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload: this.invocationContext.current()?.auth ? { redacted: true } : payload })}`, EDebugLogScope.MCP);
214808
+ this.debugLog(`[mcp-client] ${JSON.stringify({
214809
+ serverName,
214810
+ resourceId: resource.resourceId,
214811
+ requestId,
214812
+ method,
214813
+ phase,
214814
+ payload: this.invocationContext.current()?.auth ? { redacted: true } : payload
214815
+ })}`, EDebugLogScope.MCP);
214627
214816
  } catch (error40) {
214628
214817
  warnLogFailure("remoteGatewayMcpServer.log", error40);
214629
214818
  }
@@ -214643,6 +214832,8 @@ var RemoteGatewayMcpServerProvider = class {
214643
214832
  callTool: (params, resultSchema, requestOptions) => request("tools/call", params, () => client.callTool(params, resultSchema, requestOptions))
214644
214833
  };
214645
214834
  const callTool = (name, args, signal, options) => callHeaders.run(options?.headers ?? {}, () => this.invocationContext.run(timeoutMs, signal, async (invocation) => {
214835
+ const observation = options?.context?.observation;
214836
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_REQUESTED_INPUT, args, options?.toolSchema?.inputSchema);
214646
214837
  const plan = createArgsMappingPlan(name, args, argsMappingRules);
214647
214838
  if (plan.requiresUserId) {
214648
214839
  if (config2.signEndpoint !== void 0 && config2.signEndpoint !== DEFAULT_SIGN_ENDPOINT && !config2.verifyTokenEndpoint?.trim())
@@ -214665,15 +214856,18 @@ var RemoteGatewayMcpServerProvider = class {
214665
214856
  };
214666
214857
  }
214667
214858
  const mapped = resolveArgsMappingPlan(plan, invocation.auth);
214859
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_INPUT, mapped, options?.toolSchema?.inputSchema);
214668
214860
  invocation.signal.throwIfAborted();
214669
214861
  const remaining = Math.max(1, invocation.deadline - performance.now());
214670
214862
  try {
214671
- return await loggedClient.callTool({ name, arguments: mapped }, void 0, {
214863
+ const result = await loggedClient.callTool({ name, arguments: mapped }, void 0, {
214672
214864
  signal: invocation.signal,
214673
214865
  timeout: remaining,
214674
214866
  maxTotalTimeout: remaining,
214675
214867
  resetTimeoutOnProgress: false
214676
214868
  });
214869
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_OUTPUT, result, options?.toolSchema?.outputSchema);
214870
+ return result;
214677
214871
  } catch (error40) {
214678
214872
  invocation.signal.throwIfAborted();
214679
214873
  if (invocation.auth && !(error40 instanceof McpInvocationError))
@@ -214702,7 +214896,13 @@ async function listToolsFromClient(client, resourceId, callTool) {
214702
214896
  const descriptor = {
214703
214897
  name: tool.name,
214704
214898
  resourceId,
214705
- execute: (args, signal) => callTool(tool.name, args, signal)
214899
+ execute: (args, signal, context2) => callTool(tool.name, args, signal, {
214900
+ context: context2,
214901
+ toolSchema: {
214902
+ inputSchema: tool.inputSchema,
214903
+ outputSchema: tool.outputSchema
214904
+ }
214905
+ })
214706
214906
  };
214707
214907
  if (tool.description !== void 0)
214708
214908
  descriptor.description = tool.description;
@@ -215053,6 +215253,8 @@ function parseResponse(body, query, topK) {
215053
215253
  }
215054
215254
 
215055
215255
  // ../linkque-agent-runtime/dist/esm/impl/mcp/localHttpMcpServerProvider.js
215256
+ init_telemetry();
215257
+ init_contentRecording();
215056
215258
  init_httpLoggingFetch();
215057
215259
  var LocalHttpMcpServerProvider = class {
215058
215260
  baseUrl;
@@ -215081,7 +215283,7 @@ var LocalHttpMcpServerProvider = class {
215081
215283
  }
215082
215284
  return body.tools.map((value) => this.createDescriptor(resource.resourceId, value));
215083
215285
  },
215084
- callTool: (name, args, signal) => this.callTool(resource.resourceId, name, args, signal)
215286
+ callTool: (name, args, signal, options) => this.callTool(resource.resourceId, name, args, signal, options)
215085
215287
  };
215086
215288
  }
215087
215289
  createDescriptor(resourceId, value) {
@@ -215095,17 +215297,28 @@ var LocalHttpMcpServerProvider = class {
215095
215297
  ...isRecord2(value.inputSchema) ? { inputSchema: value.inputSchema } : {},
215096
215298
  ...isRecord2(value.outputSchema) ? { outputSchema: value.outputSchema } : {},
215097
215299
  ...isRecord2(value.annotations) ? { annotations: value.annotations } : {},
215098
- execute: (args, signal) => this.callTool(resourceId, value.name, args, signal)
215300
+ execute: (args, signal, context2) => this.callTool(resourceId, value.name, args, signal, {
215301
+ context: context2,
215302
+ toolSchema: {
215303
+ inputSchema: value.inputSchema,
215304
+ outputSchema: value.outputSchema
215305
+ }
215306
+ })
215099
215307
  };
215100
215308
  }
215101
- async callTool(resourceId, toolName, args, signal) {
215309
+ async callTool(resourceId, toolName, args, signal, options) {
215310
+ const observation = options?.context?.observation;
215311
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_REQUESTED_INPUT, args, options?.toolSchema?.inputSchema);
215312
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_INPUT, args, options?.toolSchema?.inputSchema);
215102
215313
  const response = await this.fetchImpl(this.resourceUrl(resourceId, `tools/${encodeURIComponent(toolName)}/call`), {
215103
215314
  method: "POST",
215104
215315
  headers: { "content-type": "application/json" },
215105
215316
  body: JSON.stringify({ arguments: args }),
215106
215317
  signal
215107
215318
  });
215108
- return readJsonResponse(response);
215319
+ const result = await readJsonResponse(response);
215320
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_OUTPUT, result, options?.toolSchema?.outputSchema);
215321
+ return result;
215109
215322
  }
215110
215323
  resourceUrl(resourceId, suffix) {
215111
215324
  return new URL(`resources/${encodeURIComponent(resourceId)}/${suffix}`, ensureTrailingSlash(this.baseUrl));
@@ -215784,6 +215997,7 @@ function unzip(data, opts, cb) {
215784
215997
  }
215785
215998
 
215786
215999
  // ../linkque-agent-runtime/dist/esm/impl/webSkillLoader.js
216000
+ init_types();
215787
216001
  init_skillTools();
215788
216002
  init_httpLoggingFetch();
215789
216003
  var ESkillUrlScheme;
@@ -215821,7 +216035,7 @@ var WebSkillLoader = class {
215821
216035
  return records.filter((record4, idx) => {
215822
216036
  if (record4 !== void 0)
215823
216037
  return true;
215824
- this.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${resources[idx]?.resourceId ?? "?"}:SKILL.md \u7F3A description(\u524D\u7F6E\u65E0\u6548),\u6309 spec \u4E0D\u52A0\u8F7D`);
216038
+ this.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${resources[idx]?.resourceId ?? "?"}:SKILL.md \u7F3A description(\u524D\u7F6E\u65E0\u6548),\u6309 spec \u4E0D\u52A0\u8F7D`, EDebugLogScope.SKILL);
215825
216039
  return false;
215826
216040
  });
215827
216041
  }
@@ -216482,7 +216696,7 @@ var OtelRuntimeTelemetry = class {
216482
216696
  {
216483
216697
  onEmit: (record4, ctx) => {
216484
216698
  const route = ctx?.getValue(this.routeKey);
216485
- this.output(ETelemetrySignal.LOGS, import_otlp_transformer.JsonLogsSerializer.serializeRequest([record4]), route?.route, route?.critical ?? false);
216699
+ this.output(ETelemetrySignal.LOGS, import_otlp_transformer.JsonLogsSerializer.serializeRequest([record4]), route?.route, route?.critical ?? false, route?.localOnly ?? false);
216486
216700
  },
216487
216701
  forceFlush: async () => void 0,
216488
216702
  shutdown: async () => void 0
@@ -216490,12 +216704,13 @@ var OtelRuntimeTelemetry = class {
216490
216704
  ]
216491
216705
  });
216492
216706
  }
216493
- output(signal, encoded, route, critical) {
216707
+ output(signal, encoded, route, critical, localOnly = false) {
216494
216708
  if (!encoded || this.outputActive || this.disposed)
216495
216709
  return;
216496
216710
  this.outputActive = true;
216497
216711
  try {
216498
- this.queue.enqueue(route, signal, encoded, critical);
216712
+ if (!localOnly)
216713
+ this.queue.enqueue(route, signal, encoded, critical);
216499
216714
  if (this.options.localSink) {
216500
216715
  try {
216501
216716
  const payload = JSON.parse(new TextDecoder().decode(encoded));
@@ -216520,7 +216735,6 @@ var OtelRuntimeTelemetry = class {
216520
216735
  return new NoopRuntimeObservation();
216521
216736
  }
216522
216737
  const state2 = {
216523
- agentId: input.agentId,
216524
216738
  sequence: 0,
216525
216739
  route: auth2 ? this.queue.authorize(auth2) : void 0,
216526
216740
  attributes: sanitizeTelemetryAttributes({
@@ -216576,7 +216790,6 @@ var OtelRuntimeTelemetry = class {
216576
216790
  isRemote: upstream !== null,
216577
216791
  traceState: parentContext.traceState ? createTraceState(parentContext.traceState) : void 0
216578
216792
  });
216579
- const spanName = spec.name === ETelemetryOperationName.MODEL_ATTEMPT ? `${ETelemetryGenAiOperation.CHAT} ${spec.attributes[ETelemetryAttribute.GEN_AI_REQUEST_MODEL]}` : spec.name === ETelemetryOperationName.TOOL_INVOKE ? `${ETelemetryGenAiOperation.EXECUTE_TOOL} ${spec.attributes[ETelemetryAttribute.GEN_AI_TOOL_NAME]}` : spec.name === ETelemetryOperationName.ADVANCE && state2.agentId ? `${ETelemetryGenAiOperation.INVOKE_AGENT} ${state2.agentId}` : spec.name;
216580
216793
  const attributes = sanitizeTelemetryAttributes({
216581
216794
  ...state2.attributes,
216582
216795
  ...parent?.attributes,
@@ -216594,11 +216807,11 @@ var OtelRuntimeTelemetry = class {
216594
216807
  ETelemetryAttribute.LINKQUE_CONVERSATION_ID
216595
216808
  ].some((attribute) => attribute === key))),
216596
216809
  [ETelemetryAttribute.LINKQUE_OPERATION_ID]: (0, import_node_crypto5.randomUUID)(),
216597
- [ETelemetryAttribute.LINKQUE_OPERATION_NAME]: spanName,
216810
+ [ETelemetryAttribute.LINKQUE_OPERATION_NAME]: spec.name,
216598
216811
  [ETelemetryAttribute.LINKQUE_OPERATION_PARENT_ID]: spec.detached ? "" : parent?.operationId ?? "",
216599
216812
  [ETelemetryAttribute.LINKQUE_SPAN_PARENT_ID]: spec.detached ? "" : parentContext?.spanId ?? ""
216600
216813
  });
216601
- const span = this.tracerProvider.getTracer(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).startSpan(spanName.slice(0, 256), {
216814
+ const span = this.tracerProvider.getTracer(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).startSpan(spec.name, {
216602
216815
  kind: spec.name === ETelemetryOperationName.MODEL_ATTEMPT ? SpanKind.CLIENT : SpanKind.INTERNAL,
216603
216816
  attributes,
216604
216817
  links: spec.links.filter((link) => validContext(link.context)).slice(0, 16).map((link) => ({
@@ -216626,7 +216839,7 @@ var OtelRuntimeTelemetry = class {
216626
216839
  operation.record(`${spec.eventPrefix}.${ETelemetryEventPhase.STARTED}`, {});
216627
216840
  return operation;
216628
216841
  }
216629
- emit(operation, name, attributes, critical) {
216842
+ emit(operation, name, attributes, critical, body) {
216630
216843
  if (this.disposed || this.queue.isExporting)
216631
216844
  return;
216632
216845
  const contextAttributes = operation.attributes;
@@ -216653,18 +216866,24 @@ var OtelRuntimeTelemetry = class {
216653
216866
  Math.floor(now / 1e3),
216654
216867
  now % 1e3 * 1e6
216655
216868
  ];
216656
- if (operation.span.isRecording())
216869
+ const localOnly = name === ETelemetryEventName.DEBUG_CONTENT_RECORDED;
216870
+ if (!localOnly && operation.span.isRecording())
216657
216871
  operation.span.addEvent(
216658
216872
  name,
216659
216873
  // 复用已投影的属性;Span 已持有上下文,事件只保留本次事实及去重字段。
216660
216874
  Object.fromEntries(Object.entries(record4).filter(([key]) => Object.hasOwn(attributes, key) || key === ETelemetryAttribute.HARNESS_RECORD_ID || key === ETelemetryAttribute.HARNESS_EVENT_SEQUENCE)),
216661
216875
  time3
216662
216876
  );
216663
- const ctx = trace.setSpan(ROOT_CONTEXT, operation.span).setValue(this.routeKey, { route: operation.state.route, critical });
216877
+ const ctx = trace.setSpan(ROOT_CONTEXT, operation.span).setValue(this.routeKey, {
216878
+ route: operation.state.route,
216879
+ critical,
216880
+ localOnly
216881
+ });
216664
216882
  this.loggerProvider.getLogger(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).emit({
216665
216883
  eventName: name,
216666
216884
  timestamp: time3,
216667
216885
  observedTimestamp: time3,
216886
+ ...body !== void 0 ? { body } : {},
216668
216887
  severityNumber: record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.ERROR || record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.TIMEOUT ? import_api_logs.SeverityNumber.ERROR : import_api_logs.SeverityNumber.INFO,
216669
216888
  severityText: record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.ERROR || record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.TIMEOUT ? import_api_logs.SeverityNumber[import_api_logs.SeverityNumber.ERROR] : import_api_logs.SeverityNumber[import_api_logs.SeverityNumber.INFO],
216670
216889
  attributes: record4,
@@ -216735,10 +216954,11 @@ var OtelObservation = class {
216735
216954
  return new NoopRuntimeObservation();
216736
216955
  return this.owner.createOperation(this.state, spec, this);
216737
216956
  }
216738
- record(name, attributes) {
216957
+ record(name, attributes, body) {
216739
216958
  if (this.lost || !/^(harness|linkque)\.[a-z0-9_.]{1,128}$/.test(name))
216740
216959
  return;
216741
- this.owner.emit(this, name, attributes, name.endsWith(`.${ETelemetryEventPhase.FINISHED}`) || name === ETelemetryEventName.MODEL_USAGE_RECORDED || name === ETelemetryEventName.RUNTIME_UNCAUGHT_ERROR || name.endsWith(`.${ETelemetryEventPhase.OBSERVATION_LOST}`));
216960
+ const critical = name.endsWith(`.${ETelemetryEventPhase.FINISHED}`) || name === ETelemetryEventName.MODEL_USAGE_RECORDED || name === ETelemetryEventName.RUNTIME_UNCAUGHT_ERROR || name.endsWith(`.${ETelemetryEventPhase.OBSERVATION_LOST}`);
216961
+ this.owner.emit(this, name, attributes, critical, body);
216742
216962
  }
216743
216963
  finish(outcome, attributes) {
216744
216964
  if (this.ended)
@@ -216978,6 +217198,7 @@ var OtlpFileSink = class {
216978
217198
  // src/commands/agentdev/sandboxIntegrate/sandboxRuntimeConfigProvider.ts
216979
217199
  var SANDBOX_RUNTIME_CONFIG_DEFAULTS = Object.freeze({
216980
217200
  ...RUNTIME_CONFIG_DEFAULTS,
217201
+ LOG_LEVEL: "DEBUG",
216981
217202
  LINKQUE_MCP_SIGN_ENDPOINT: RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_MCP_SIGN_ENDPOINT,
216982
217203
  LINKQUE_OPEN_MCP_BASE_URL: "https://opengw.alipay.com",
216983
217204
  LINKQUEGW_TELEMETRY_LOGS_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/telemetry/v1/logs`,
@@ -217435,6 +217656,7 @@ var fileSize = async (filePath) => {
217435
217656
  };
217436
217657
  var maskSecret = (raw) => raw ? "<set>" : "<unset>";
217437
217658
  var AGENT_ENV_SNAPSHOT = [
217659
+ ["LOG_LEVEL", false],
217438
217660
  ["LINKQUE_AGENT_API_KEY", true],
217439
217661
  ["LINKQUE_AGENT_ACCESS_KEY", true],
217440
217662
  ["LINKQUE_USER_TOKEN", true],
@@ -217671,11 +217893,15 @@ var main = async () => {
217671
217893
  `[${(/* @__PURE__ */ new Date()).toISOString()}] agent worker loading agent runtime
217672
217894
  `
217673
217895
  );
217674
- const debugLog = (line, scope) => {
217675
- const prefix = scope ? `[${scope}] ` : "";
217676
- log.write(`[${(/* @__PURE__ */ new Date()).toISOString()}]${prefix}${line}
217896
+ const config2 = new SandboxRuntimeConfigProvider();
217897
+ const debugLog = createRuntimeDebugLog(
217898
+ config2.get("LOG_LEVEL"),
217899
+ (line, scope) => {
217900
+ const prefix = scope ? `[${scope}] ` : "";
217901
+ log.write(`[${(/* @__PURE__ */ new Date()).toISOString()}]${prefix}${line}
217677
217902
  `);
217678
- };
217903
+ }
217904
+ );
217679
217905
  agentDevTelemetry = await createAgentDevTelemetry(
217680
217906
  input.agentId,
217681
217907
  input.logPath,
@@ -217689,7 +217915,6 @@ var main = async () => {
217689
217915
  executeHomeData2 = executeHomeData;
217690
217916
  executeCardAction2 = executeCardAction;
217691
217917
  executeFunctionActionMcp2 = executeFunctionActionMcp;
217692
- const config2 = new SandboxRuntimeConfigProvider();
217693
217918
  const localMcpUrl = config2.get("LINKQUE_AGENT_MCP_FIXTURE_URL");
217694
217919
  const gatewayAuthorization = resolveSandboxGatewayAuthorization(process.env);
217695
217920
  const remoteAuthorizationHeader = gatewayAuthorization ? async () => gatewayAuthorization : void 0;
@@ -217764,9 +217989,9 @@ var main = async () => {
217764
217989
  // opengw 响应头 alipay-trace-id 下沉到 agent.log(同 SSE 会话级复用,
217765
217990
  // 每会话首个 POST 上报一次有效值),供 MCP 调用链路归因排查。
217766
217991
  onTraceId: (info) => {
217767
- log.write(
217768
- `[${(/* @__PURE__ */ new Date()).toISOString()}] [mcp-trace] ${info.httpMethod} ${info.requestUrl} alipay-trace-id=${info.traceId}
217769
- `
217992
+ debugLog(
217993
+ `[mcp-trace] ${info.httpMethod} ${info.requestUrl} alipay-trace-id=${info.traceId}`,
217994
+ EDebugLogScope.MCP
217770
217995
  );
217771
217996
  },
217772
217997
  // HTTP 出站日志下沉(scope=http):tag=mcp-sign(签名服务)+ mcp-call(SSE GET/POST 工具调用)→ agent.log。