linkque-cli-v2 1.1.1 → 1.1.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/linkquejs.js CHANGED
@@ -19639,6 +19639,8 @@ var LINKQUE_BASE_URL = `${LINKQUE_ENDPOINT_PROD}/api/anthropic`;
19639
19639
  var LINKQUE_BASE_URL_PRE = `${LINKQUE_ENDPOINT_PRE}/api/anthropic`;
19640
19640
  var LINKQUEGW_KNOWLEDGE_BASE_URL = LINKQUE_ENDPOINT_PROD;
19641
19641
  var LINKQUEGW_KNOWLEDGE_BASE_URL_PRE = LINKQUE_ENDPOINT_PRE;
19642
+ var LINKQUEGW_EVENT_BASE_URL = LINKQUE_ENDPOINT_PROD;
19643
+ var LINKQUEGW_EVENT_BASE_URL_PRE = LINKQUE_ENDPOINT_PRE;
19642
19644
  var LINKQUEGW_MCP_SIGN_ENDPOINT = `${LINKQUE_ENDPOINT_PROD}/api/mcp/signature`;
19643
19645
  var LINKQUEGW_MCP_SIGN_ENDPOINT_PRE = `${LINKQUE_ENDPOINT_PRE}/api/mcp/signature`;
19644
19646
  var RUN_TABLE_COLUMNS = [
@@ -20154,6 +20156,7 @@ var FUNCTION_DEFS = [
20154
20156
  key: "LINKQUEGW_KNOWLEDGE_BASE_URL",
20155
20157
  value: LINKQUEGW_KNOWLEDGE_BASE_URL
20156
20158
  },
20159
+ { key: "LINKQUEGW_EVENT_BASE_URL", value: LINKQUEGW_EVENT_BASE_URL },
20157
20160
  {
20158
20161
  key: "LINKQUEGW_MCP_SIGN_ENDPOINT",
20159
20162
  value: LINKQUEGW_MCP_SIGN_ENDPOINT
@@ -20164,6 +20167,10 @@ var FUNCTION_DEFS = [
20164
20167
  key: "LINKQUEGW_KNOWLEDGE_BASE_URL_PRE",
20165
20168
  value: LINKQUEGW_KNOWLEDGE_BASE_URL_PRE
20166
20169
  },
20170
+ {
20171
+ key: "LINKQUEGW_EVENT_BASE_URL_PRE",
20172
+ value: LINKQUEGW_EVENT_BASE_URL_PRE
20173
+ },
20167
20174
  {
20168
20175
  key: "LINKQUEGW_MCP_SIGN_ENDPOINT_PRE",
20169
20176
  value: LINKQUEGW_MCP_SIGN_ENDPOINT_PRE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkque-cli-v2",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Public Linkque CLI bundle for sandbox debugging",
5
5
  "bin": {
6
6
  "linkquejs": "linkquejs.js"
@@ -11811,6 +11811,8 @@ function describeRuntimeEnv(env, hasRequestKey = false) {
11811
11811
  lines.push(envLine("LINKQUE_BASE_URL_PRE", maskEndpoint(env.LINKQUE_BASE_URL_PRE)));
11812
11812
  lines.push(envLine("LINKQUEGW_KNOWLEDGE_BASE_URL", maskEndpoint(env.LINKQUEGW_KNOWLEDGE_BASE_URL)));
11813
11813
  lines.push(envLine("LINKQUEGW_KNOWLEDGE_BASE_URL_PRE", maskEndpoint(env.LINKQUEGW_KNOWLEDGE_BASE_URL_PRE)));
11814
+ lines.push(envLine("LINKQUEGW_EVENT_BASE_URL", maskEndpoint(env.LINKQUEGW_EVENT_BASE_URL)));
11815
+ lines.push(envLine("LINKQUEGW_EVENT_BASE_URL_PRE", maskEndpoint(env.LINKQUEGW_EVENT_BASE_URL_PRE)));
11814
11816
  lines.push(envLine("LINKQUEGW_MCP_SIGN_ENDPOINT", maskEndpoint(env.LINKQUEGW_MCP_SIGN_ENDPOINT)));
11815
11817
  lines.push(envLine("LINKQUEGW_MCP_SIGN_ENDPOINT_PRE", maskEndpoint(env.LINKQUEGW_MCP_SIGN_ENDPOINT_PRE)));
11816
11818
  lines.push(envLine("RUN_DATABASE_ID", envValue(env, "RUN_DATABASE_ID")));
@@ -16583,6 +16583,7 @@ var require_dist2 = __commonJS({
16583
16583
  // ../linkque-agent-runtime/dist/esm/core/types.js
16584
16584
  var EDebugLogScope;
16585
16585
  (function(EDebugLogScope2) {
16586
+ EDebugLogScope2["CONFIG"] = "CONFIG";
16586
16587
  EDebugLogScope2["LLM"] = "LLM";
16587
16588
  EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
16588
16589
  EDebugLogScope2["MCP"] = "MCP";
@@ -18342,11 +18343,7 @@ function injectResolvedViewModel(protocol, viewModel) {
18342
18343
  {
18343
18344
  version: "0.9",
18344
18345
  datas: surfaceIds.map((surfaceId) => ({
18345
- updateDataModel: {
18346
- surfaceId,
18347
- path: "/",
18348
- value: viewModel
18349
- }
18346
+ updateDataModel: { surfaceId, path: "/", value: viewModel }
18350
18347
  }))
18351
18348
  }
18352
18349
  ];
@@ -19793,6 +19790,17 @@ var REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
19793
19790
  "anthropic-api-key"
19794
19791
  ]);
19795
19792
  var REDACTED_VALUE = "ak***";
19793
+ var RESPONSE_CORRELATION_HEADER_NAMES = [
19794
+ "alipay-trace-id",
19795
+ "x-trace-id",
19796
+ "x-traceid",
19797
+ "trace-id",
19798
+ "traceid",
19799
+ "eagleeye-traceid",
19800
+ "eagleeye-trace-id",
19801
+ "sofa-traceid",
19802
+ "sofa-trace-id"
19803
+ ];
19796
19804
  function redactHeader(name, value) {
19797
19805
  return REDACTED_HEADER_NAMES.has(name.toLowerCase()) ? REDACTED_VALUE : value;
19798
19806
  }
@@ -19849,10 +19857,37 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
19849
19857
  len = cl;
19850
19858
  } catch {
19851
19859
  }
19852
- safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}`));
19860
+ const correlation = readResponseCorrelationId(resp.headers);
19861
+ const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
19862
+ safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}${correlationField}`));
19853
19863
  return resp;
19854
19864
  };
19855
19865
  }
19866
+ function readResponseCorrelationId(headers) {
19867
+ try {
19868
+ for (const name of RESPONSE_CORRELATION_HEADER_NAMES) {
19869
+ const value = headers.get(name)?.trim();
19870
+ if (value) {
19871
+ return { name, value: value.replace(/\s+/gu, " ").slice(0, 200) };
19872
+ }
19873
+ }
19874
+ let matched;
19875
+ headers.forEach((rawValue, rawName) => {
19876
+ if (matched || !/(?:^|[-_])trace[-_]?id$/iu.test(rawName))
19877
+ return;
19878
+ const value = rawValue.trim();
19879
+ if (!value)
19880
+ return;
19881
+ matched = {
19882
+ name: rawName,
19883
+ value: value.replace(/\s+/gu, " ").slice(0, 200)
19884
+ };
19885
+ });
19886
+ return matched;
19887
+ } catch {
19888
+ }
19889
+ return void 0;
19890
+ }
19856
19891
  function safeLog(debugLog, line) {
19857
19892
  try {
19858
19893
  debugLog(line, EDebugLogScope.HTTP);
@@ -19870,7 +19905,11 @@ function errorMsg(error) {
19870
19905
  // ../linkque-agent-runtime/dist/esm/core/hook/linkquegwEventHookExecutor.js
19871
19906
  var DEFAULT_LINKQUEGW_EVENT_BASE_URL = "https://linkquegw.alipay.com";
19872
19907
  var LINKQUEGW_AGENT_EVENT_TRIGGER_PATH = "/api/agent/event/trigger";
19873
- var LINKQUEGW_EVENT_TYPE_BY_STAGE = { [EHookStage.RUN_STARTED]: "AGENT_DIALOG_ROUND_STARTED" };
19908
+ var LINKQUEGW_EVENT_TYPE_BY_STAGE = {
19909
+ [EHookStage.RUN_STARTED]: "RUN_STARTED",
19910
+ [EHookStage.RUN_COMPLETED]: "RUN_ENDED",
19911
+ [EHookStage.RUN_FAILED]: "RUN_ENDED"
19912
+ };
19874
19913
  function buildLinkquegwEventBody(context) {
19875
19914
  const eventType = LINKQUEGW_EVENT_TYPE_BY_STAGE[context.stage];
19876
19915
  if (eventType === void 0)
@@ -19881,13 +19920,14 @@ function buildLinkquegwEventBody(context) {
19881
19920
  eventType,
19882
19921
  eventId: context.eventId,
19883
19922
  eventTime: context.timestamp,
19884
- conversationId: commonParams.conversationId,
19923
+ ...commonParams.conversationId !== void 0 && {
19924
+ conversationId: commonParams.conversationId
19925
+ },
19885
19926
  ...commonParams.sessionId !== void 0 && {
19886
19927
  sessionId: commonParams.sessionId
19887
19928
  },
19888
19929
  runId: commonParams.runId,
19889
- runIndex: commonParams.runIndex,
19890
- traceId: commonParams.traceId ?? commonParams.runId
19930
+ runIndex: commonParams.runIndex
19891
19931
  };
19892
19932
  }
19893
19933
  var LinkquegwEventHookExecutor = class {
@@ -19927,7 +19967,7 @@ var LinkquegwEventHookExecutor = class {
19927
19967
  const startedAt = this.now();
19928
19968
  let result = "ok";
19929
19969
  try {
19930
- const traceId = body.traceId;
19970
+ const traceId = context.commonParams.traceId ?? context.commonParams.runId;
19931
19971
  const resp = await this.fetchImpl(`${this.baseUrl}${LINKQUEGW_AGENT_EVENT_TRIGGER_PATH}`, {
19932
19972
  method: "POST",
19933
19973
  headers: {
@@ -52766,6 +52806,8 @@ var AgentRuntime = class _AgentRuntime {
52766
52806
  hookMetricsSink;
52767
52807
  /** 装配期固化的统一诊断 sink(逐 run options.debugLog 可覆盖)。 */
52768
52808
  portsDebugLog;
52809
+ /** 插件处理后、runtime 实际使用的完整 Agent Config JSON 快照。 */
52810
+ effectiveAgentConfigJson;
52769
52811
  // —— 从 IAgentProtocol 提取并固化的运行期默认(经 create 注入)——
52770
52812
  /** systemPrompt 默认(来自 protocol.agent.systemPrompt.content)。 */
52771
52813
  defaultSystemPrompt = "";
@@ -52849,6 +52891,11 @@ var AgentRuntime = class _AgentRuntime {
52849
52891
  rt.agentId = agentConfig.agentId;
52850
52892
  rt.followUpQuestionGenerationEnabled = followUpQuestionGenerationEnabled;
52851
52893
  rt.hookResources = normalizeHookResources(agentConfig.agent.resources.filter((r) => r.resourceType === EResourceType.HOOK));
52894
+ try {
52895
+ rt.effectiveAgentConfigJson = JSON.stringify(agentConfig);
52896
+ } catch {
52897
+ rt.effectiveAgentConfigJson = void 0;
52898
+ }
52852
52899
  return rt;
52853
52900
  }
52854
52901
  async prepareFollowUpQuestionContext(sessionId, history = []) {
@@ -52869,6 +52916,12 @@ var AgentRuntime = class _AgentRuntime {
52869
52916
  async *runAgentLoop(request, auth2, options = {}) {
52870
52917
  const sessionId = options.sessionId;
52871
52918
  const debugLog = options.debugLog ?? this.portsDebugLog;
52919
+ if (debugLog) {
52920
+ try {
52921
+ debugLog(this.effectiveAgentConfigJson === void 0 ? "[agent-config] final=<Agent Config \u5E8F\u5217\u5316\u5931\u8D25\uFF0C\u65E0\u6CD5\u6253\u5370\u5B8C\u6574\u5185\u5BB9>" : `[agent-config] final=${this.effectiveAgentConfigJson}`, EDebugLogScope.CONFIG);
52922
+ } catch {
52923
+ }
52924
+ }
52872
52925
  const newTurns = request.messages.map((m) => ({
52873
52926
  role: m.role,
52874
52927
  content: m.content,
@@ -52976,6 +53029,19 @@ var AgentRuntime = class _AgentRuntime {
52976
53029
  let assistantText = "";
52977
53030
  let failed = false;
52978
53031
  let runError;
53032
+ let terminalHookDispatched = false;
53033
+ const dispatchTerminalHook = async () => {
53034
+ if (terminalHookDispatched || hookDispatcher.isEmpty)
53035
+ return;
53036
+ terminalHookDispatched = true;
53037
+ if (failed) {
53038
+ await hookDispatcher.dispatch(EHookStage.RUN_FAILED, hookCommonParams, {
53039
+ error: runError ?? { message: "unknown error" }
53040
+ });
53041
+ return;
53042
+ }
53043
+ await hookDispatcher.dispatch(EHookStage.RUN_COMPLETED, hookCommonParams, { runDurationMs: Date.now() - runStartedAt });
53044
+ };
52979
53045
  try {
52980
53046
  for await (const ev of this.agentLoop.run(agentReq)) {
52981
53047
  if (ev.type === "delta")
@@ -52983,6 +53049,7 @@ var AgentRuntime = class _AgentRuntime {
52983
53049
  if (ev.type === "error") {
52984
53050
  failed = true;
52985
53051
  runError = { message: ev.error.message, code: ev.error.code };
53052
+ await dispatchTerminalHook();
52986
53053
  }
52987
53054
  if (ev.type === "done" && !failed && sessionId !== void 0) {
52988
53055
  const completedTurns = [
@@ -52997,22 +53064,18 @@ var AgentRuntime = class _AgentRuntime {
52997
53064
  }
52998
53065
  }
52999
53066
  }
53067
+ if (ev.type === "done")
53068
+ await dispatchTerminalHook();
53000
53069
  yield ev;
53001
53070
  }
53002
- if (!hookDispatcher.isEmpty) {
53003
- if (failed) {
53004
- await hookDispatcher.dispatch(EHookStage.RUN_FAILED, hookCommonParams, { error: runError ?? { message: "unknown error" } });
53005
- } else {
53006
- await hookDispatcher.dispatch(EHookStage.RUN_COMPLETED, hookCommonParams, { runDurationMs: Date.now() - runStartedAt });
53007
- }
53008
- }
53071
+ await dispatchTerminalHook();
53009
53072
  } catch (error) {
53010
- if (!hookDispatcher.isEmpty) {
53011
- await hookDispatcher.dispatch(EHookStage.RUN_FAILED, hookCommonParams, {
53012
- error: {
53013
- message: error instanceof Error ? error.message : String(error)
53014
- }
53015
- });
53073
+ if (!terminalHookDispatched) {
53074
+ failed = true;
53075
+ runError = {
53076
+ message: error instanceof Error ? error.message : String(error)
53077
+ };
53078
+ await dispatchTerminalHook();
53016
53079
  }
53017
53080
  throw error;
53018
53081
  } finally {
@@ -17,7 +17,7 @@ import {
17
17
  resolveLinkqueGatewayAuth,
18
18
  resolveRunStorage,
19
19
  toAgentRunMessages
20
- } from "../../chunk-IAT272TH.js";
20
+ } from "../../chunk-B56A2RV5.js";
21
21
  import "../../chunk-MKS245OU.js";
22
22
  import "../../chunk-YDKZZ6EH.js";
23
23
  import "../../chunk-2NGJGNYB.js";
@@ -51,7 +51,7 @@ import {
51
51
  parseConversationRunRequest,
52
52
  parseSkillFile,
53
53
  streamToConversationEvents
54
- } from "../../chunk-TM6MTGSL.js";
54
+ } from "../../chunk-MR5QT2A5.js";
55
55
  import "../../chunk-XUFLSZM4.js";
56
56
  import "../../chunk-I64V3ICJ.js";
57
57
  import "../../chunk-6MHDOBWO.js";
@@ -68,23 +68,39 @@ import { randomUUID as randomUUID3 } from "node:crypto";
68
68
  // ../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js
69
69
  var LINKQUEGW_EVENT_PLUGIN_NAME = "linkquegw-event-plugin";
70
70
  var LINKQUEGW_EVENT_HOOK_RESOURCE_ID = "linkquegw-event-run-started";
71
- var createLinkquegwEventHookResource = () => ({
72
- resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
71
+ var LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID = "linkquegw-event-run-completed";
72
+ var LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID = "linkquegw-event-run-failed";
73
+ var DEFAULT_LINKQUEGW_EVENT_HOOKS = [
74
+ {
75
+ resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
76
+ stage: EHookStage.RUN_STARTED
77
+ },
78
+ {
79
+ resourceId: LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID,
80
+ stage: EHookStage.RUN_COMPLETED
81
+ },
82
+ {
83
+ resourceId: LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID,
84
+ stage: EHookStage.RUN_FAILED
85
+ }
86
+ ];
87
+ var createLinkquegwEventHookResource = (resourceId, stage) => ({
88
+ resourceId,
73
89
  resourceType: EResourceType.HOOK,
74
90
  providerType: EResourceProviderType.LINK_QUE,
75
91
  config: {
76
92
  name: "LinkqueGW \u751F\u547D\u5468\u671F\u4E8B\u4EF6\u4E0A\u62A5",
77
93
  executorName: EHookExecutorName.LinkquegwEventHookExecutor,
78
- stage: EHookStage.RUN_STARTED,
94
+ stage,
79
95
  hasSideEffects: true
80
96
  }
81
97
  });
82
98
  var isUserTokenAuthorization = (value) => /^Bearer[\t ]+[^\s,]+$/u.test(value);
83
- var isLinkquegwRunStartedHook = (resource) => {
99
+ var isLinkquegwEventHook = (resource, stage) => {
84
100
  if (resource.resourceType !== EResourceType.HOOK)
85
101
  return false;
86
102
  const hookResource = resource;
87
- return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === EHookStage.RUN_STARTED;
103
+ return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === stage;
88
104
  };
89
105
  var LinkquegwEventPlugin = class {
90
106
  name = LINKQUEGW_EVENT_PLUGIN_NAME;
@@ -113,10 +129,12 @@ var LinkquegwEventPlugin = class {
113
129
  }
114
130
  /** 自动补入 event trigger 所需 HookResource;已有同 executorName + stage 时保持原配置。 */
115
131
  modifyAgentConfig(agentConfig) {
116
- const exists = agentConfig.agent.resources.some(isLinkquegwRunStartedHook);
117
- if (exists)
118
- return;
119
- agentConfig.agent.resources.push(createLinkquegwEventHookResource());
132
+ for (const hook of DEFAULT_LINKQUEGW_EVENT_HOOKS) {
133
+ const exists = agentConfig.agent.resources.some((resource) => isLinkquegwEventHook(resource, hook.stage));
134
+ if (!exists) {
135
+ agentConfig.agent.resources.push(createLinkquegwEventHookResource(hook.resourceId, hook.stage));
136
+ }
137
+ }
120
138
  }
121
139
  };
122
140
 
@@ -298,6 +316,7 @@ function resolveLinkqueEndpoints(env, envSelector) {
298
316
  return {
299
317
  linkqueBaseUrl: trimEnvVar(isPre ? env.LINKQUE_BASE_URL_PRE : env.LINKQUE_BASE_URL),
300
318
  knowledgeBaseUrl: trimEnvVar(isPre ? env.LINKQUEGW_KNOWLEDGE_BASE_URL_PRE : env.LINKQUEGW_KNOWLEDGE_BASE_URL),
319
+ eventBaseUrl: trimEnvVar(isPre ? env.LINKQUEGW_EVENT_BASE_URL_PRE : env.LINKQUEGW_EVENT_BASE_URL),
301
320
  mcpSignEndpoint: trimEnvVar(isPre ? env.LINKQUEGW_MCP_SIGN_ENDPOINT_PRE : env.LINKQUEGW_MCP_SIGN_ENDPOINT)
302
321
  };
303
322
  }
@@ -353,10 +372,11 @@ function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
353
372
  }
354
373
  const plugins = [...ports.plugins ?? []];
355
374
  const hasLinkquegwEventPlugin = plugins.some((plugin) => plugin.name === LINKQUEGW_EVENT_PLUGIN_NAME);
375
+ const eventBaseUrl = ports.eventBaseUrl ?? ports.knowledgeBaseUrl;
356
376
  if (ports.gatewayAuthMode === "user-token" && mcpAuthHeader && !hasLinkquegwEventPlugin) {
357
377
  plugins.push(new LinkquegwEventPlugin({
358
378
  getUserTokenAuthorizationHeader: mcpAuthHeader,
359
- ...ports.knowledgeBaseUrl ? { baseUrl: ports.knowledgeBaseUrl } : {},
379
+ ...eventBaseUrl ? { baseUrl: eventBaseUrl } : {},
360
380
  ...ports.gatewayAgentId ? { agentId: ports.gatewayAgentId } : {},
361
381
  ...debugLog ? { debugLog } : {}
362
382
  }));
@@ -1745,7 +1765,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
1745
1765
  chunkSize = storage.chunkSize;
1746
1766
  }
1747
1767
  const mcpAuthorizationHeaderProvider = async () => resolved.authorizationHeader;
1748
- const { linkqueBaseUrl, knowledgeBaseUrl, mcpSignEndpoint } = resolveLinkqueEndpoints(env, envSelector);
1768
+ const { linkqueBaseUrl, knowledgeBaseUrl, eventBaseUrl, mcpSignEndpoint } = resolveLinkqueEndpoints(env, envSelector);
1749
1769
  const mcpConfigResolver = createAppbaseMcpConfigResolver({
1750
1770
  agentId: protocol.agentId,
1751
1771
  ...mcpSignEndpoint ? { signEndpoint: mcpSignEndpoint } : {}
@@ -1757,7 +1777,8 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
1757
1777
  gatewayAuthMode: resolved.mode,
1758
1778
  gatewayAgentId: protocol.agentId,
1759
1779
  ...linkqueBaseUrl ? { linkqueBaseUrl } : {},
1760
- ...knowledgeBaseUrl ? { knowledgeBaseUrl } : {}
1780
+ ...knowledgeBaseUrl ? { knowledgeBaseUrl } : {},
1781
+ ...eventBaseUrl ? { eventBaseUrl } : {}
1761
1782
  }, logCtx);
1762
1783
  return {
1763
1784
  auth: resolved.auth,
@@ -3,7 +3,7 @@ import {
3
3
  runClientCapability,
4
4
  runClientCapabilityCleanup,
5
5
  runClientCapabilityResult
6
- } from "../../chunk-IAT272TH.js";
6
+ } from "../../chunk-B56A2RV5.js";
7
7
  import "../../chunk-MKS245OU.js";
8
8
  import "../../chunk-YDKZZ6EH.js";
9
9
  import "../../chunk-2NGJGNYB.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getBakedProtocol,
3
3
  setBakedProtocol
4
- } from "../chunk-TM6MTGSL.js";
4
+ } from "../chunk-MR5QT2A5.js";
5
5
  import "../chunk-XUFLSZM4.js";
6
6
  import "../chunk-I64V3ICJ.js";
7
7
  import "../chunk-6MHDOBWO.js";
package/worker.js CHANGED
@@ -4981,6 +4981,7 @@ var init_types2 = __esm({
4981
4981
  "../linkque-agent-runtime/dist/esm/core/types.js"() {
4982
4982
  "use strict";
4983
4983
  (function(EDebugLogScope2) {
4984
+ EDebugLogScope2["CONFIG"] = "CONFIG";
4984
4985
  EDebugLogScope2["LLM"] = "LLM";
4985
4986
  EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
4986
4987
  EDebugLogScope2["MCP"] = "MCP";
@@ -15270,11 +15271,7 @@ function injectResolvedViewModel(protocol, viewModel) {
15270
15271
  {
15271
15272
  version: "0.9",
15272
15273
  datas: surfaceIds.map((surfaceId) => ({
15273
- updateDataModel: {
15274
- surfaceId,
15275
- path: "/",
15276
- value: viewModel
15277
- }
15274
+ updateDataModel: { surfaceId, path: "/", value: viewModel }
15278
15275
  }))
15279
15276
  }
15280
15277
  ];
@@ -16884,10 +16881,37 @@ function createHttpLoggingFetch(debugLog, tag, baseFetch = globalThis.fetch) {
16884
16881
  len = cl;
16885
16882
  } catch {
16886
16883
  }
16887
- safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}`));
16884
+ const correlation = readResponseCorrelationId(resp.headers);
16885
+ const correlationField = correlation ? ` traceId=${correlation.value} traceHeader=${correlation.name}` : "";
16886
+ safeLog(debugLog, formatHttpLogLine(tag, "resp", `${method} ${targetUrl} ${resp.status} in ${elapsed}ms len=${len}${correlationField}`));
16888
16887
  return resp;
16889
16888
  };
16890
16889
  }
16890
+ function readResponseCorrelationId(headers) {
16891
+ try {
16892
+ for (const name of RESPONSE_CORRELATION_HEADER_NAMES) {
16893
+ const value = headers.get(name)?.trim();
16894
+ if (value) {
16895
+ return { name, value: value.replace(/\s+/gu, " ").slice(0, 200) };
16896
+ }
16897
+ }
16898
+ let matched;
16899
+ headers.forEach((rawValue, rawName) => {
16900
+ if (matched || !/(?:^|[-_])trace[-_]?id$/iu.test(rawName))
16901
+ return;
16902
+ const value = rawValue.trim();
16903
+ if (!value)
16904
+ return;
16905
+ matched = {
16906
+ name: rawName,
16907
+ value: value.replace(/\s+/gu, " ").slice(0, 200)
16908
+ };
16909
+ });
16910
+ return matched;
16911
+ } catch {
16912
+ }
16913
+ return void 0;
16914
+ }
16891
16915
  function safeLog(debugLog, line) {
16892
16916
  try {
16893
16917
  debugLog(line, EDebugLogScope.HTTP);
@@ -16901,7 +16925,7 @@ function errorMsg(error40) {
16901
16925
  const msg = error40 instanceof Error ? error40.message : String(error40);
16902
16926
  return msg.replace(/\s+/g, " ").slice(0, 500);
16903
16927
  }
16904
- var MAX_BODY_SUMMARY_LEN, REDACTED_HEADER_NAMES, REDACTED_VALUE;
16928
+ var MAX_BODY_SUMMARY_LEN, REDACTED_HEADER_NAMES, REDACTED_VALUE, RESPONSE_CORRELATION_HEADER_NAMES;
16905
16929
  var init_httpLoggingFetch = __esm({
16906
16930
  "../linkque-agent-runtime/dist/esm/impl/httpLoggingFetch.js"() {
16907
16931
  "use strict";
@@ -16915,6 +16939,17 @@ var init_httpLoggingFetch = __esm({
16915
16939
  "anthropic-api-key"
16916
16940
  ]);
16917
16941
  REDACTED_VALUE = "ak***";
16942
+ RESPONSE_CORRELATION_HEADER_NAMES = [
16943
+ "alipay-trace-id",
16944
+ "x-trace-id",
16945
+ "x-traceid",
16946
+ "trace-id",
16947
+ "traceid",
16948
+ "eagleeye-traceid",
16949
+ "eagleeye-trace-id",
16950
+ "sofa-traceid",
16951
+ "sofa-trace-id"
16952
+ ];
16918
16953
  }
16919
16954
  });
16920
16955
 
@@ -16929,13 +16964,14 @@ function buildLinkquegwEventBody(context2) {
16929
16964
  eventType,
16930
16965
  eventId: context2.eventId,
16931
16966
  eventTime: context2.timestamp,
16932
- conversationId: commonParams.conversationId,
16967
+ ...commonParams.conversationId !== void 0 && {
16968
+ conversationId: commonParams.conversationId
16969
+ },
16933
16970
  ...commonParams.sessionId !== void 0 && {
16934
16971
  sessionId: commonParams.sessionId
16935
16972
  },
16936
16973
  runId: commonParams.runId,
16937
- runIndex: commonParams.runIndex,
16938
- traceId: commonParams.traceId ?? commonParams.runId
16974
+ runIndex: commonParams.runIndex
16939
16975
  };
16940
16976
  }
16941
16977
  var DEFAULT_LINKQUEGW_EVENT_BASE_URL, LINKQUEGW_AGENT_EVENT_TRIGGER_PATH, LINKQUEGW_EVENT_TYPE_BY_STAGE, LinkquegwEventHookExecutor;
@@ -16947,7 +16983,11 @@ var init_linkquegwEventHookExecutor = __esm({
16947
16983
  init_hookMetrics();
16948
16984
  DEFAULT_LINKQUEGW_EVENT_BASE_URL = "https://linkquegw.alipay.com";
16949
16985
  LINKQUEGW_AGENT_EVENT_TRIGGER_PATH = "/api/agent/event/trigger";
16950
- LINKQUEGW_EVENT_TYPE_BY_STAGE = { [EHookStage.RUN_STARTED]: "AGENT_DIALOG_ROUND_STARTED" };
16986
+ LINKQUEGW_EVENT_TYPE_BY_STAGE = {
16987
+ [EHookStage.RUN_STARTED]: "RUN_STARTED",
16988
+ [EHookStage.RUN_COMPLETED]: "RUN_ENDED",
16989
+ [EHookStage.RUN_FAILED]: "RUN_ENDED"
16990
+ };
16951
16991
  LinkquegwEventHookExecutor = class {
16952
16992
  name = EHookExecutorName.LinkquegwEventHookExecutor;
16953
16993
  baseUrl;
@@ -16985,7 +17025,7 @@ var init_linkquegwEventHookExecutor = __esm({
16985
17025
  const startedAt = this.now();
16986
17026
  let result = "ok";
16987
17027
  try {
16988
- const traceId = body.traceId;
17028
+ const traceId = context2.commonParams.traceId ?? context2.commonParams.runId;
16989
17029
  const resp = await this.fetchImpl(`${this.baseUrl}${LINKQUEGW_AGENT_EVENT_TRIGGER_PATH}`, {
16990
17030
  method: "POST",
16991
17031
  headers: {
@@ -188725,6 +188765,8 @@ var init_agentRuntime = __esm({
188725
188765
  hookMetricsSink;
188726
188766
  /** 装配期固化的统一诊断 sink(逐 run options.debugLog 可覆盖)。 */
188727
188767
  portsDebugLog;
188768
+ /** 插件处理后、runtime 实际使用的完整 Agent Config JSON 快照。 */
188769
+ effectiveAgentConfigJson;
188728
188770
  // —— 从 IAgentProtocol 提取并固化的运行期默认(经 create 注入)——
188729
188771
  /** systemPrompt 默认(来自 protocol.agent.systemPrompt.content)。 */
188730
188772
  defaultSystemPrompt = "";
@@ -188808,6 +188850,11 @@ var init_agentRuntime = __esm({
188808
188850
  rt.agentId = agentConfig.agentId;
188809
188851
  rt.followUpQuestionGenerationEnabled = followUpQuestionGenerationEnabled;
188810
188852
  rt.hookResources = normalizeHookResources(agentConfig.agent.resources.filter((r2) => r2.resourceType === EResourceType.HOOK));
188853
+ try {
188854
+ rt.effectiveAgentConfigJson = JSON.stringify(agentConfig);
188855
+ } catch {
188856
+ rt.effectiveAgentConfigJson = void 0;
188857
+ }
188811
188858
  return rt;
188812
188859
  }
188813
188860
  async prepareFollowUpQuestionContext(sessionId, history = []) {
@@ -188828,6 +188875,12 @@ var init_agentRuntime = __esm({
188828
188875
  async *runAgentLoop(request, auth2, options = {}) {
188829
188876
  const sessionId = options.sessionId;
188830
188877
  const debugLog = options.debugLog ?? this.portsDebugLog;
188878
+ if (debugLog) {
188879
+ try {
188880
+ debugLog(this.effectiveAgentConfigJson === void 0 ? "[agent-config] final=<Agent Config \u5E8F\u5217\u5316\u5931\u8D25\uFF0C\u65E0\u6CD5\u6253\u5370\u5B8C\u6574\u5185\u5BB9>" : `[agent-config] final=${this.effectiveAgentConfigJson}`, EDebugLogScope.CONFIG);
188881
+ } catch {
188882
+ }
188883
+ }
188831
188884
  const newTurns = request.messages.map((m2) => ({
188832
188885
  role: m2.role,
188833
188886
  content: m2.content,
@@ -188935,6 +188988,19 @@ var init_agentRuntime = __esm({
188935
188988
  let assistantText = "";
188936
188989
  let failed = false;
188937
188990
  let runError;
188991
+ let terminalHookDispatched = false;
188992
+ const dispatchTerminalHook = async () => {
188993
+ if (terminalHookDispatched || hookDispatcher.isEmpty)
188994
+ return;
188995
+ terminalHookDispatched = true;
188996
+ if (failed) {
188997
+ await hookDispatcher.dispatch(EHookStage.RUN_FAILED, hookCommonParams, {
188998
+ error: runError ?? { message: "unknown error" }
188999
+ });
189000
+ return;
189001
+ }
189002
+ await hookDispatcher.dispatch(EHookStage.RUN_COMPLETED, hookCommonParams, { runDurationMs: Date.now() - runStartedAt });
189003
+ };
188938
189004
  try {
188939
189005
  for await (const ev of this.agentLoop.run(agentReq)) {
188940
189006
  if (ev.type === "delta")
@@ -188942,6 +189008,7 @@ var init_agentRuntime = __esm({
188942
189008
  if (ev.type === "error") {
188943
189009
  failed = true;
188944
189010
  runError = { message: ev.error.message, code: ev.error.code };
189011
+ await dispatchTerminalHook();
188945
189012
  }
188946
189013
  if (ev.type === "done" && !failed && sessionId !== void 0) {
188947
189014
  const completedTurns = [
@@ -188956,22 +189023,18 @@ var init_agentRuntime = __esm({
188956
189023
  }
188957
189024
  }
188958
189025
  }
189026
+ if (ev.type === "done")
189027
+ await dispatchTerminalHook();
188959
189028
  yield ev;
188960
189029
  }
188961
- if (!hookDispatcher.isEmpty) {
188962
- if (failed) {
188963
- await hookDispatcher.dispatch(EHookStage.RUN_FAILED, hookCommonParams, { error: runError ?? { message: "unknown error" } });
188964
- } else {
188965
- await hookDispatcher.dispatch(EHookStage.RUN_COMPLETED, hookCommonParams, { runDurationMs: Date.now() - runStartedAt });
188966
- }
188967
- }
189030
+ await dispatchTerminalHook();
188968
189031
  } catch (error40) {
188969
- if (!hookDispatcher.isEmpty) {
188970
- await hookDispatcher.dispatch(EHookStage.RUN_FAILED, hookCommonParams, {
188971
- error: {
188972
- message: error40 instanceof Error ? error40.message : String(error40)
188973
- }
188974
- });
189032
+ if (!terminalHookDispatched) {
189033
+ failed = true;
189034
+ runError = {
189035
+ message: error40 instanceof Error ? error40.message : String(error40)
189036
+ };
189037
+ await dispatchTerminalHook();
188975
189038
  }
188976
189039
  throw error40;
188977
189040
  } finally {
@@ -196985,7 +197048,7 @@ var init_examplePlugin = __esm({
196985
197048
  });
196986
197049
 
196987
197050
  // ../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js
196988
- var LINKQUEGW_EVENT_PLUGIN_NAME, LINKQUEGW_EVENT_HOOK_RESOURCE_ID, createLinkquegwEventHookResource, isUserTokenAuthorization, isLinkquegwRunStartedHook, LinkquegwEventPlugin;
197051
+ var LINKQUEGW_EVENT_PLUGIN_NAME, LINKQUEGW_EVENT_HOOK_RESOURCE_ID, LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID, LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID, DEFAULT_LINKQUEGW_EVENT_HOOKS, createLinkquegwEventHookResource, isUserTokenAuthorization, isLinkquegwEventHook, LinkquegwEventPlugin;
196989
197052
  var init_linkquegwEventPlugin = __esm({
196990
197053
  "../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js"() {
196991
197054
  "use strict";
@@ -196993,23 +197056,39 @@ var init_linkquegwEventPlugin = __esm({
196993
197056
  init_linkquegwEventHookExecutor();
196994
197057
  LINKQUEGW_EVENT_PLUGIN_NAME = "linkquegw-event-plugin";
196995
197058
  LINKQUEGW_EVENT_HOOK_RESOURCE_ID = "linkquegw-event-run-started";
196996
- createLinkquegwEventHookResource = () => ({
196997
- resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
197059
+ LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID = "linkquegw-event-run-completed";
197060
+ LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID = "linkquegw-event-run-failed";
197061
+ DEFAULT_LINKQUEGW_EVENT_HOOKS = [
197062
+ {
197063
+ resourceId: LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
197064
+ stage: EHookStage.RUN_STARTED
197065
+ },
197066
+ {
197067
+ resourceId: LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID,
197068
+ stage: EHookStage.RUN_COMPLETED
197069
+ },
197070
+ {
197071
+ resourceId: LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID,
197072
+ stage: EHookStage.RUN_FAILED
197073
+ }
197074
+ ];
197075
+ createLinkquegwEventHookResource = (resourceId, stage) => ({
197076
+ resourceId,
196998
197077
  resourceType: EResourceType.HOOK,
196999
197078
  providerType: EResourceProviderType.LINK_QUE,
197000
197079
  config: {
197001
197080
  name: "LinkqueGW \u751F\u547D\u5468\u671F\u4E8B\u4EF6\u4E0A\u62A5",
197002
197081
  executorName: EHookExecutorName.LinkquegwEventHookExecutor,
197003
- stage: EHookStage.RUN_STARTED,
197082
+ stage,
197004
197083
  hasSideEffects: true
197005
197084
  }
197006
197085
  });
197007
197086
  isUserTokenAuthorization = (value) => /^Bearer[\t ]+[^\s,]+$/u.test(value);
197008
- isLinkquegwRunStartedHook = (resource) => {
197087
+ isLinkquegwEventHook = (resource, stage) => {
197009
197088
  if (resource.resourceType !== EResourceType.HOOK)
197010
197089
  return false;
197011
197090
  const hookResource = resource;
197012
- return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === EHookStage.RUN_STARTED;
197091
+ return hookResource.config.executorName === EHookExecutorName.LinkquegwEventHookExecutor && hookResource.config.stage === stage;
197013
197092
  };
197014
197093
  LinkquegwEventPlugin = class {
197015
197094
  name = LINKQUEGW_EVENT_PLUGIN_NAME;
@@ -197038,10 +197117,12 @@ var init_linkquegwEventPlugin = __esm({
197038
197117
  }
197039
197118
  /** 自动补入 event trigger 所需 HookResource;已有同 executorName + stage 时保持原配置。 */
197040
197119
  modifyAgentConfig(agentConfig) {
197041
- const exists = agentConfig.agent.resources.some(isLinkquegwRunStartedHook);
197042
- if (exists)
197043
- return;
197044
- agentConfig.agent.resources.push(createLinkquegwEventHookResource());
197120
+ for (const hook of DEFAULT_LINKQUEGW_EVENT_HOOKS) {
197121
+ const exists = agentConfig.agent.resources.some((resource) => isLinkquegwEventHook(resource, hook.stage));
197122
+ if (!exists) {
197123
+ agentConfig.agent.resources.push(createLinkquegwEventHookResource(hook.resourceId, hook.stage));
197124
+ }
197125
+ }
197045
197126
  }
197046
197127
  };
197047
197128
  }
@@ -197053,6 +197134,8 @@ __export(plugin_exports, {
197053
197134
  ExamplePlugin: () => ExamplePlugin,
197054
197135
  LINKQUEGW_EVENT_HOOK_RESOURCE_ID: () => LINKQUEGW_EVENT_HOOK_RESOURCE_ID,
197055
197136
  LINKQUEGW_EVENT_PLUGIN_NAME: () => LINKQUEGW_EVENT_PLUGIN_NAME,
197137
+ LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID: () => LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID,
197138
+ LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID: () => LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID,
197056
197139
  LinkquegwEventPlugin: () => LinkquegwEventPlugin
197057
197140
  });
197058
197141
  var init_plugin = __esm({