linkque-cli-v2 1.3.6 → 1.3.8-beta.1

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.
Files changed (19) hide show
  1. package/linkquejs.js +1106 -324
  2. package/package.json +1 -1
  3. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-RHFHCJYP.js → chunk-7MJID6LL.js} +15253 -393
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NHRW2KQW.js → chunk-BU3S4JYG.js} +1 -1
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-HM7KNEG3.js → chunk-DNTEEBEH.js} +5 -0
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-EAODRPW4.js +518 -0
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-7SF3H2GM.js → chunk-EFUO43CY.js} +6 -1
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-bsd-H2ZLZRGB.js → getMachineId-bsd-JGCLGHFY.js} +1 -1
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-darwin-HUKYR46U.js → getMachineId-darwin-COHLFNXH.js} +1 -1
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-linux-M5ZADHBA.js → getMachineId-linux-XV3Z5FQG.js} +1 -1
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-unsupported-BM5RZZVM.js → getMachineId-unsupported-FCRKLIZL.js} +1 -1
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-win-BQPUF5TW.js → getMachineId-win-A4WRNVV6.js} +1 -1
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-TQA2MPJJ.js → mistral-conversations-5RZTVEO2.js} +1 -1
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-RXJWJ2TU.js → otel-WGS5CC2J.js} +250 -267
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +134 -19
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +4 -3
  17. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +4 -3
  18. package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
  19. package/worker.js +418 -68
@@ -38,14 +38,15 @@ import {
38
38
  resolveLinkqueGatewayAuth,
39
39
  resolveRunStorage,
40
40
  toAgentRunMessages
41
- } from "../../chunk-7SF3H2GM.js";
41
+ } from "../../chunk-EFUO43CY.js";
42
42
  import "../../chunk-IWOFD643.js";
43
43
  import "../../chunk-PXCGFBV5.js";
44
44
  import "../../chunk-ETG6PNHQ.js";
45
45
  import {
46
46
  getBakedProtocol
47
- } from "../../chunk-NHRW2KQW.js";
47
+ } from "../../chunk-BU3S4JYG.js";
48
48
  import {
49
+ ACTIVATE_SKILL_TOOL_NAME,
49
50
  CANCEL_CONVERSATION_RUN_OPERATION,
50
51
  CONVERSATION_HISTORY_VERSION,
51
52
  CardActionDiagnostics,
@@ -72,6 +73,7 @@ import {
72
73
  ETelemetryCancelSource,
73
74
  ETelemetryCommitStatus,
74
75
  ETelemetryCompleteness,
76
+ ETelemetryContentSection,
75
77
  ETelemetryCoverage,
76
78
  ETelemetryErrorType,
77
79
  ETelemetryEventName,
@@ -104,6 +106,7 @@ import {
104
106
  NoopRuntimeTelemetry,
105
107
  NoopSkillLoader,
106
108
  NoopWebSearchPort,
109
+ OtelRuntimeTelemetry,
107
110
  RUNTIME_CONFIG_DEFAULTS,
108
111
  RemoteGatewayMcpServerProvider,
109
112
  SideEffectRunner,
@@ -144,6 +147,7 @@ import {
144
147
  projectPresentationReceiptForModel,
145
148
  readJsonPointer,
146
149
  readStructuredContent,
150
+ recordContentSection,
147
151
  redactHeaders,
148
152
  resolvePhoneAuthorizationDependency,
149
153
  resolveWebSearchResource,
@@ -153,10 +157,11 @@ import {
153
157
  summarizeBody,
154
158
  warnLogFailure,
155
159
  wrapToolWithHooks
156
- } from "../../chunk-RHFHCJYP.js";
160
+ } from "../../chunk-7MJID6LL.js";
157
161
  import "../../chunk-XUFLSZM4.js";
162
+ import "../../chunk-EAODRPW4.js";
158
163
  import "../../chunk-GAYNLDWK.js";
159
- import "../../chunk-HM7KNEG3.js";
164
+ import "../../chunk-DNTEEBEH.js";
160
165
  import {
161
166
  __commonJS,
162
167
  __export,
@@ -7939,6 +7944,7 @@ import { randomUUID as randomUUID7 } from "node:crypto";
7939
7944
 
7940
7945
  // ../linkque-agent-runtime/dist/esm/core/telemetry/toolObservation.js
7941
7946
  import { randomUUID } from "node:crypto";
7947
+ var isSkillTool = (tool) => (tool.modelName ?? tool.name) === ACTIVATE_SKILL_TOOL_NAME;
7942
7948
  function toolResultOutcome(result) {
7943
7949
  try {
7944
7950
  if (!(result && typeof result === "object")) {
@@ -7972,8 +7978,19 @@ function observeTool(tool, observation) {
7972
7978
  detached: false,
7973
7979
  links: []
7974
7980
  });
7981
+ const captureBody = !isSkillTool(tool);
7975
7982
  try {
7976
- const result = await tool.execute(args, signal, context);
7983
+ if (captureBody) {
7984
+ recordContentSection(operation, ETelemetryContentSection.TOOL_INPUT, args);
7985
+ }
7986
+ const execContext = {
7987
+ ...context ?? { toolCallId: "", emit: () => void 0 },
7988
+ observation: operation
7989
+ };
7990
+ const result = await tool.execute(args, signal, execContext);
7991
+ if (captureBody) {
7992
+ recordContentSection(operation, ETelemetryContentSection.TOOL_OUTPUT, result);
7993
+ }
7977
7994
  operation.finish(toolResultOutcome(result), {
7978
7995
  [ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS]: toolResultOutcome(result)
7979
7996
  });
@@ -8267,7 +8284,7 @@ var googleGenerativeAIApi = () => lazyApi(() => import("../../google-generative-
8267
8284
  var googleVertexApi = () => lazyApi(() => import("../../google-vertex-RIGAEYLC.js"));
8268
8285
 
8269
8286
  // ../../node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.js
8270
- var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-TQA2MPJJ.js"));
8287
+ var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-5RZTVEO2.js"));
8271
8288
 
8272
8289
  // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.js
8273
8290
  var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-WLREQPZK.js"));
@@ -41861,11 +41878,32 @@ var AgentRuntime = class _AgentRuntime {
41861
41878
  }
41862
41879
  }, (observation) => this.runObservedAdvance(request, auth, options, observation), options.signal);
41863
41880
  }
41881
+ /**
41882
+ * 记录本次用户输入(RFC §4.1):取进入 Runtime 的本次新消息中最后一条 user message
41883
+ * 的 content,作为 `linkque.debug.content.recorded` 的 body 走 record 链路落入
41884
+ * OTLP logs(body 含 section/value/availability)。不以模型 messages 上下文为输入;
41885
+ * 无 user 文本(卡片交互等)时按可用性如实标记,不伪造自然语言 Query。
41886
+ */
41887
+ recordCurrentQuery(observation, request) {
41888
+ let lastUser;
41889
+ for (const message of request.messages) {
41890
+ if (message.role === "user")
41891
+ lastUser = message;
41892
+ }
41893
+ const text2 = typeof lastUser?.content === "string" ? lastUser.content : "";
41894
+ const body = {
41895
+ section: ETelemetryContentSection.QUERY_INPUT,
41896
+ value: text2,
41897
+ availability: text2 ? "available" : "not_recorded"
41898
+ };
41899
+ observation.record(ETelemetryEventName.DEBUG_CONTENT_RECORDED, {}, body);
41900
+ }
41864
41901
  async *runObservedAdvance(request, auth, options, observation) {
41865
41902
  observation.record(ETelemetryEventName.TELEMETRY_COVERAGE, {
41866
41903
  [ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCoverage.PI_MODEL_TOOL_HOOK : ETelemetryCoverage.CORE_ONLY,
41867
41904
  [ETelemetryAttribute.HARNESS_TELEMETRY_COMPLETENESS]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCompleteness.COMPLETE : ETelemetryCompleteness.PARTIAL
41868
41905
  });
41906
+ this.recordCurrentQuery(observation, request);
41869
41907
  const cleanup = [];
41870
41908
  let termination = ETelemetryStreamTermination.CANCEL;
41871
41909
  let failed = false;
@@ -42960,6 +42998,8 @@ function resolveLinkqueEndpoints(env, envSelector) {
42960
42998
  const config = new AppbaseRuntimeConfigProvider(env);
42961
42999
  const isPre = envSelector === "PRE";
42962
43000
  return {
43001
+ telemetryLogsEndpoint: config.get(isPre ? "LINKQUEGW_TELEMETRY_LOGS_ENDPOINT_PRE" : "LINKQUEGW_TELEMETRY_LOGS_ENDPOINT"),
43002
+ telemetryTracesEndpoint: config.get(isPre ? "LINKQUEGW_TELEMETRY_TRACES_ENDPOINT_PRE" : "LINKQUEGW_TELEMETRY_TRACES_ENDPOINT"),
42963
43003
  linkqueBaseUrl: config.get(isPre ? "LINKQUE_BASE_URL_PRE" : "LINKQUE_BASE_URL"),
42964
43004
  knowledgeBaseUrl: config.get(isPre ? "LINKQUEGW_KNOWLEDGE_BASE_URL_PRE" : "LINKQUEGW_KNOWLEDGE_BASE_URL"),
42965
43005
  webSearchBaseUrl: config.get(isPre ? "LINKQUEGW_WEB_SEARCH_BASE_URL_PRE" : "LINKQUEGW_WEB_SEARCH_BASE_URL"),
@@ -42975,6 +43015,8 @@ function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
42975
43015
  logCtx.log?.(prefix + line);
42976
43016
  } : void 0;
42977
43017
  const runtimePorts = {};
43018
+ if (ports.telemetry)
43019
+ runtimePorts.telemetry = ports.telemetry;
42978
43020
  if (ports.linkqueBaseUrl) {
42979
43021
  runtimePorts.linkqueBaseUrl = ports.linkqueBaseUrl;
42980
43022
  log("linkqueBaseUrl: ->", ports.linkqueBaseUrl);
@@ -44842,6 +44884,64 @@ function errorMessage(error, fallback) {
44842
44884
  return error instanceof Error && error.message.trim() ? error.message : fallback;
44843
44885
  }
44844
44886
 
44887
+ // ../linkque-agent-appwrite-integrate/dist/esm/runtime/appbaseTelemetry.js
44888
+ import { createHash as createHash3 } from "node:crypto";
44889
+ function createAppbaseTelemetry(options) {
44890
+ const diagnostic = (code) => {
44891
+ try {
44892
+ options.logCtx?.log?.("[telemetry]", code);
44893
+ } catch {
44894
+ }
44895
+ };
44896
+ let telemetry;
44897
+ try {
44898
+ telemetry = new OtelRuntimeTelemetry({
44899
+ serviceName: "linkque-appbase",
44900
+ serviceVersion: "0.0.0",
44901
+ environment: options.environment,
44902
+ logsEndpoint: options.logsEndpoint,
44903
+ tracesEndpoint: options.tracesEndpoint,
44904
+ diagnostic: ({ code }) => diagnostic(code)
44905
+ });
44906
+ } catch {
44907
+ diagnostic("initialization_failed");
44908
+ telemetry = new NoopRuntimeTelemetry();
44909
+ }
44910
+ const { authorizationHeader, mode } = options.gatewayAuth;
44911
+ const version = createHash3("sha256").update(authorizationHeader).digest("hex");
44912
+ return {
44913
+ telemetry,
44914
+ createContext(requestId) {
44915
+ return {
44916
+ parent: null,
44917
+ authorization: {
44918
+ subject: version,
44919
+ version,
44920
+ mode: mode === "user-token" ? "bearer" : "aak",
44921
+ agentId: options.agentId,
44922
+ environment: options.environment,
44923
+ getHeaders: () => ({
44924
+ authorization: authorizationHeader,
44925
+ "x-linkque-agent-id": options.agentId
44926
+ })
44927
+ },
44928
+ requestId,
44929
+ turnId: "",
44930
+ accountId: "",
44931
+ channel: "appbase",
44932
+ userKey: ""
44933
+ };
44934
+ },
44935
+ async shutdown() {
44936
+ try {
44937
+ await telemetry.shutdown({ timeoutMs: 2e3, authorization: null });
44938
+ } catch {
44939
+ diagnostic("shutdown_failed");
44940
+ }
44941
+ }
44942
+ };
44943
+ }
44944
+
44845
44945
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/securityAnswerPlugin.js
44846
44946
  var SECURITY_ANSWER_HEADER = "x-linkque-guardrails-action";
44847
44947
  var SECURITY_ANSWER_ACTION = "SECURITY_ANSWER";
@@ -45007,7 +45107,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
45007
45107
  chunkSize = storage.chunkSize;
45008
45108
  }
45009
45109
  const mcpAuthorizationHeaderProvider = async () => resolved.authorizationHeader;
45010
- const { linkqueBaseUrl, knowledgeBaseUrl, webSearchBaseUrl, eventBaseUrl, mcpSignEndpoint, openMcpBaseUrl } = resolveLinkqueEndpoints(env, envSelector);
45110
+ const { linkqueBaseUrl, knowledgeBaseUrl, webSearchBaseUrl, eventBaseUrl, mcpSignEndpoint, openMcpBaseUrl, telemetryLogsEndpoint, telemetryTracesEndpoint } = resolveLinkqueEndpoints(env, envSelector);
45011
45111
  const mcpConfigResolver = createAppbaseMcpConfigResolver({
45012
45112
  agentId: protocol.agentId,
45013
45113
  remoteBaseUrl: openMcpBaseUrl,
@@ -45019,7 +45119,16 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
45019
45119
  });
45020
45120
  const mcpServerProvider = rawMcpServerProvider;
45021
45121
  const securityAnswerPlugin = deps?.securityAnswerPlugin ?? createSecurityAnswerPlugin(historyStore, logCtx?.log);
45122
+ const telemetry = deps?.runtime ? void 0 : createAppbaseTelemetry({
45123
+ agentId: protocol.agentId,
45124
+ gatewayAuth: resolved,
45125
+ environment: new AppbaseRuntimeConfigProvider(env).get("LINKQUE_TELEMETRY_ENVIRONMENT") ?? (envSelector === "PRE" ? "pre" : "prod"),
45126
+ logsEndpoint: telemetryLogsEndpoint,
45127
+ tracesEndpoint: telemetryTracesEndpoint,
45128
+ logCtx
45129
+ });
45022
45130
  const runtime = deps?.runtime ?? createAppBaseRuntime(protocol, env, {
45131
+ telemetry: telemetry?.telemetry,
45023
45132
  ...appwriteApiKey ? { appBaseApiKey: appwriteApiKey } : {},
45024
45133
  mcpServerProvider,
45025
45134
  mcpConfigResolver,
@@ -45042,6 +45151,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
45042
45151
  model: protocol.agent.model.defaultModel || void 0,
45043
45152
  protocol,
45044
45153
  runtime,
45154
+ telemetry,
45045
45155
  store,
45046
45156
  sessionLease,
45047
45157
  historyStore,
@@ -45361,6 +45471,7 @@ async function runAgentToChunks(deps, request, env, logCtx, authenticatedUserId,
45361
45471
  };
45362
45472
  }
45363
45473
  const runOptions = {
45474
+ telemetryContext: deps.telemetry?.createContext(request.runId),
45364
45475
  requestSource: EModelRequestSource.APPBASE_FUNCTION,
45365
45476
  runtimeContext: {
45366
45477
  agentId: deps.protocol.agentId,
@@ -45567,17 +45678,6 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
45567
45678
  const leaseOwnerId = randomUUID7();
45568
45679
  let leaseAcquired = false;
45569
45680
  let leaseReleased = false;
45570
- if (cfg.sessionLease && !isPresentationRun) {
45571
- try {
45572
- leaseAcquired = await cfg.sessionLease.acquire(request.threadId, leaseOwnerId);
45573
- } catch (err2) {
45574
- logError("session \u79DF\u7EA6\u83B7\u53D6\u5931\u8D25:", err2);
45575
- return jsonError(500, "session_lock_failed", err2 instanceof Error ? err2.message : "\u4F1A\u8BDD\u79DF\u7EA6\u83B7\u53D6\u5931\u8D25");
45576
- }
45577
- if (!leaseAcquired) {
45578
- return jsonError(409, "thread_busy", "\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u6B63\u5728\u8FD0\u884C\u7684\u8BF7\u6C42");
45579
- }
45580
- }
45581
45681
  const releaseLease = async () => {
45582
45682
  if (!leaseAcquired || !cfg.sessionLease)
45583
45683
  return true;
@@ -45593,6 +45693,17 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
45593
45693
  }
45594
45694
  };
45595
45695
  try {
45696
+ if (cfg.sessionLease && !isPresentationRun) {
45697
+ try {
45698
+ leaseAcquired = await cfg.sessionLease.acquire(request.threadId, leaseOwnerId);
45699
+ } catch (err2) {
45700
+ logError("session \u79DF\u7EA6\u83B7\u53D6\u5931\u8D25:", err2);
45701
+ return jsonError(500, "session_lock_failed", err2 instanceof Error ? err2.message : "\u4F1A\u8BDD\u79DF\u7EA6\u83B7\u53D6\u5931\u8D25");
45702
+ }
45703
+ if (!leaseAcquired) {
45704
+ return jsonError(409, "thread_busy", "\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u6B63\u5728\u8FD0\u884C\u7684\u8BF7\u6C42");
45705
+ }
45706
+ }
45596
45707
  if (cfg.historyStore && !isPresentationRun) {
45597
45708
  try {
45598
45709
  await cfg.historyStore.beginRun(request, cfg.protocol.agentId);
@@ -45743,7 +45854,11 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
45743
45854
  }
45744
45855
  return execution.response;
45745
45856
  } finally {
45746
- await releaseLease();
45857
+ try {
45858
+ await releaseLease();
45859
+ } finally {
45860
+ await cfg.telemetry?.shutdown();
45861
+ }
45747
45862
  }
45748
45863
  }
45749
45864
  function readSearchableUserContent(request) {
@@ -3,14 +3,15 @@ import {
3
3
  runClientCapability,
4
4
  runClientCapabilityCleanup,
5
5
  runClientCapabilityResult
6
- } from "../../chunk-7SF3H2GM.js";
6
+ } from "../../chunk-EFUO43CY.js";
7
7
  import "../../chunk-IWOFD643.js";
8
8
  import "../../chunk-PXCGFBV5.js";
9
9
  import "../../chunk-ETG6PNHQ.js";
10
- import "../../chunk-RHFHCJYP.js";
10
+ import "../../chunk-7MJID6LL.js";
11
11
  import "../../chunk-XUFLSZM4.js";
12
+ import "../../chunk-EAODRPW4.js";
12
13
  import "../../chunk-GAYNLDWK.js";
13
- import "../../chunk-HM7KNEG3.js";
14
+ import "../../chunk-DNTEEBEH.js";
14
15
  import "../../chunk-2ESYSVXG.js";
15
16
  export {
16
17
  clientCapability as default,
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  getBakedProtocol,
3
3
  setBakedProtocol
4
- } from "../chunk-NHRW2KQW.js";
5
- import "../chunk-RHFHCJYP.js";
4
+ } from "../chunk-BU3S4JYG.js";
5
+ import "../chunk-7MJID6LL.js";
6
6
  import "../chunk-XUFLSZM4.js";
7
+ import "../chunk-EAODRPW4.js";
7
8
  import "../chunk-GAYNLDWK.js";
8
- import "../chunk-HM7KNEG3.js";
9
+ import "../chunk-DNTEEBEH.js";
9
10
  import "../chunk-2ESYSVXG.js";
10
11
  export {
11
12
  getBakedProtocol,
@@ -1 +1 @@
1
- {"name":"@alipay/linkque-agent-appwrite-integrate","version":"1.0.2-beta.0","type":"module"}
1
+ {"name":"@alipay/linkque-agent-appwrite-integrate","version":"1.3.8-beta.1","type":"module"}