linkque-cli-v2 1.3.8 → 1.4.0

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 (16) hide show
  1. package/linkquejs.js +6 -7
  2. package/package.json +1 -1
  3. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-ZNU4GVF3.js → chunk-OHRCYI66.js} +146 -119
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-RHMVQTA7.js → chunk-WM6JHW55.js} +225 -214
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-AACYYAZ6.js → chunk-XL6BPKTI.js} +1 -1
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +109 -34
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +3 -3
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +3 -3
  9. package/worker.js +135 -32
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{anthropic-messages-EL2IU4YU.js → anthropic-messages-5DOLTIGP.js} +3 -3
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{azure-openai-responses-A4XURCOX.js → azure-openai-responses-HVAVRLTK.js} +1 -1
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-5RZTVEO2.js → mistral-conversations-OEBGEDLQ.js} +10 -10
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-codex-responses-WLREQPZK.js → openai-codex-responses-3KOC6KHN.js} +1 -1
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-completions-U6LUBY4P.js → openai-completions-HG6OJRL5.js} +3 -3
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-responses-SFZAU5JA.js → openai-responses-F6V2PG3Y.js} +1 -1
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{pi-messages-QQA6ZGV2.js → pi-messages-DC4DVRAJ.js} +3 -3
@@ -1,9 +1,9 @@
1
1
  import "../../chunk-6MHDOBWO.js";
2
2
  import "../../chunk-E2P6TIFG.js";
3
- import "../../chunk-WJHOHUET.js";
4
3
  import {
5
4
  getProviderEnvValue
6
5
  } from "../../chunk-B5XRGKYX.js";
6
+ import "../../chunk-WJHOHUET.js";
7
7
  import {
8
8
  createModels,
9
9
  createProvider,
@@ -37,14 +37,15 @@ import {
37
37
  resolveGatewayAuthContext,
38
38
  resolveLinkqueGatewayAuth,
39
39
  resolveRunStorage,
40
- toAgentRunMessages
41
- } from "../../chunk-RHMVQTA7.js";
40
+ toAgentRunMessages,
41
+ withIsoTimestamp
42
+ } from "../../chunk-WM6JHW55.js";
42
43
  import "../../chunk-IWOFD643.js";
43
44
  import "../../chunk-PXCGFBV5.js";
44
45
  import "../../chunk-ETG6PNHQ.js";
45
46
  import {
46
47
  getBakedProtocol
47
- } from "../../chunk-AACYYAZ6.js";
48
+ } from "../../chunk-XL6BPKTI.js";
48
49
  import {
49
50
  CANCEL_CONVERSATION_RUN_OPERATION,
50
51
  CONVERSATION_HISTORY_VERSION,
@@ -98,6 +99,7 @@ import {
98
99
  LinkqueWebSearchPort,
99
100
  LinkquegwEventHookExecutor,
100
101
  MARK_CONVERSATION_RUNS_READ_OPERATION,
102
+ MAX_CONVERSATION_TOOL_CALL_DISPLAY_NAME_LENGTH,
101
103
  McpProxyTool,
102
104
  NoopHookExecutor,
103
105
  NoopMcpServerProvider,
@@ -139,6 +141,7 @@ import {
139
141
  parseConversationFollowUpQuestions,
140
142
  parseConversationHistoryRequest,
141
143
  parseConversationRunRequest,
144
+ parseConversationToolCallDisplayName,
142
145
  parseMarkConversationRunsReadRequest,
143
146
  parseSkillFile,
144
147
  prepareFollowUpQuestionContext,
@@ -154,9 +157,9 @@ import {
154
157
  summarizeBody,
155
158
  warnLogFailure,
156
159
  wrapToolWithHooks
157
- } from "../../chunk-ZNU4GVF3.js";
158
- import "../../chunk-XUFLSZM4.js";
160
+ } from "../../chunk-OHRCYI66.js";
159
161
  import "../../chunk-EAODRPW4.js";
162
+ import "../../chunk-XUFLSZM4.js";
160
163
  import "../../chunk-GAYNLDWK.js";
161
164
  import "../../chunk-DNTEEBEH.js";
162
165
  import {
@@ -8241,10 +8244,10 @@ function projectProviderUsage(usage) {
8241
8244
  }
8242
8245
 
8243
8246
  // ../../node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.lazy.js
8244
- var anthropicMessagesApi = () => lazyApi(() => import("../../anthropic-messages-EL2IU4YU.js"));
8247
+ var anthropicMessagesApi = () => lazyApi(() => import("../../anthropic-messages-5DOLTIGP.js"));
8245
8248
 
8246
8249
  // ../../node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.lazy.js
8247
- var azureOpenAIResponsesApi = () => lazyApi(() => import("../../azure-openai-responses-A4XURCOX.js"));
8250
+ var azureOpenAIResponsesApi = () => lazyApi(() => import("../../azure-openai-responses-HVAVRLTK.js"));
8248
8251
 
8249
8252
  // ../../node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.lazy.js
8250
8253
  var __rewriteRelativeImportExtension = function(path, preserveJsx) {
@@ -8269,19 +8272,19 @@ var googleGenerativeAIApi = () => lazyApi(() => import("../../google-generative-
8269
8272
  var googleVertexApi = () => lazyApi(() => import("../../google-vertex-RIGAEYLC.js"));
8270
8273
 
8271
8274
  // ../../node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.js
8272
- var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-5RZTVEO2.js"));
8275
+ var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-OEBGEDLQ.js"));
8273
8276
 
8274
8277
  // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.js
8275
- var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-WLREQPZK.js"));
8278
+ var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-3KOC6KHN.js"));
8276
8279
 
8277
8280
  // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-completions.lazy.js
8278
- var openAICompletionsApi = () => lazyApi(() => import("../../openai-completions-U6LUBY4P.js"));
8281
+ var openAICompletionsApi = () => lazyApi(() => import("../../openai-completions-HG6OJRL5.js"));
8279
8282
 
8280
8283
  // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-responses.lazy.js
8281
- var openAIResponsesApi = () => lazyApi(() => import("../../openai-responses-SFZAU5JA.js"));
8284
+ var openAIResponsesApi = () => lazyApi(() => import("../../openai-responses-F6V2PG3Y.js"));
8282
8285
 
8283
8286
  // ../../node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.js
8284
- var piMessagesApi = () => lazyApi(() => import("../../pi-messages-QQA6ZGV2.js"));
8287
+ var piMessagesApi = () => lazyApi(() => import("../../pi-messages-DC4DVRAJ.js"));
8285
8288
 
8286
8289
  // ../../node_modules/@earendil-works/pi-ai/dist/env-api-keys.js
8287
8290
  var __rewriteRelativeImportExtension2 = function(path, preserveJsx) {
@@ -39899,13 +39902,16 @@ function toPiAgentTools(descriptors, emitToolEvent = () => void 0) {
39899
39902
  if (names.has(name))
39900
39903
  throw new Error(`Duplicate AgentTool name ${name}`);
39901
39904
  names.add(name);
39905
+ const uiStatusParameters = decorateToolParametersWithUiStatus(descriptor.inputSchema);
39902
39906
  return {
39903
39907
  name,
39904
39908
  label: descriptor.label ?? descriptor.name,
39905
39909
  description: descriptor.description ?? descriptor.name,
39906
- parameters: normalizeParameters(descriptor.inputSchema),
39910
+ parameters: uiStatusParameters.parameters,
39911
+ ...uiStatusParameters.enabled ? { prepareArguments: stripToolUiStatusArgument } : {},
39907
39912
  execute: async (toolCallId, params, signal) => {
39908
- const result = await descriptor.execute(params, signal, {
39913
+ const args = uiStatusParameters.enabled ? stripToolUiStatusArgument(params) : params;
39914
+ const result = await descriptor.execute(args, signal, {
39909
39915
  toolCallId,
39910
39916
  emit: emitToolEvent
39911
39917
  });
@@ -39923,6 +39929,68 @@ function toPiAgentTools(descriptors, emitToolEvent = () => void 0) {
39923
39929
  };
39924
39930
  });
39925
39931
  }
39932
+ var TOOL_UI_STATUS_ARGUMENT = "__ui_status";
39933
+ var TOOL_UI_STATUS_SCHEMA = Object.freeze({
39934
+ type: "string",
39935
+ minLength: 1,
39936
+ maxLength: MAX_CONVERSATION_TOOL_CALL_DISPLAY_NAME_LENGTH,
39937
+ description: "\u754C\u9762\u8FDB\u884C\u4E2D\u72B6\u6001\u3002\u8BF7\u7528\u4E0D\u8D85\u8FC720\u4E2A\u5B57\u7684\u4E2D\u6587\u77ED\u53E5\u6982\u62EC\u672C\u6B21\u8C03\u7528\u76EE\u7684\uFF0C\u4F8B\u5982\u201C\u6B63\u5728\u641C\u7D22\u9644\u8FD1\u9152\u5E97\u201D\uFF1B\u63CF\u8FF0\u52A8\u4F5C\u4E0E\u5BF9\u8C61\uFF0C\u4E0D\u590D\u8FF0\u624B\u673A\u53F7\u3001\u8BA2\u5355\u53F7\u7B49\u5177\u4F53\u53C2\u6570\u503C\u3002"
39938
+ });
39939
+ var UNSAFE_TOOL_SCHEMA_KEYS = /* @__PURE__ */ new Set([
39940
+ "$dynamicRef",
39941
+ "$ref",
39942
+ "$recursiveRef",
39943
+ "allOf",
39944
+ "anyOf",
39945
+ "dependentSchemas",
39946
+ "else",
39947
+ "if",
39948
+ "not",
39949
+ "oneOf",
39950
+ "patternProperties",
39951
+ "propertyNames",
39952
+ "then",
39953
+ "unevaluatedProperties"
39954
+ ]);
39955
+ function getToolUiStatusEnabledNames(descriptors) {
39956
+ return new Set(descriptors.flatMap((descriptor) => decorateToolParametersWithUiStatus(descriptor.inputSchema).enabled ? [descriptor.modelName ?? descriptor.name] : []));
39957
+ }
39958
+ function decorateToolParametersWithUiStatus(value) {
39959
+ const parameters = normalizeParameters(value);
39960
+ if (!isRecord2(parameters) || parameters.type !== "object") {
39961
+ return { parameters, enabled: false };
39962
+ }
39963
+ if ([...UNSAFE_TOOL_SCHEMA_KEYS].some((key) => key in parameters)) {
39964
+ return { parameters, enabled: false };
39965
+ }
39966
+ const properties = parameters.properties;
39967
+ if (properties !== void 0 && !isRecord2(properties)) {
39968
+ return { parameters, enabled: false };
39969
+ }
39970
+ const required = parameters.required;
39971
+ if (properties && TOOL_UI_STATUS_ARGUMENT in properties || Array.isArray(required) && required.includes(TOOL_UI_STATUS_ARGUMENT)) {
39972
+ return { parameters, enabled: false };
39973
+ }
39974
+ return {
39975
+ parameters: {
39976
+ ...parameters,
39977
+ properties: {
39978
+ ...properties,
39979
+ [TOOL_UI_STATUS_ARGUMENT]: TOOL_UI_STATUS_SCHEMA
39980
+ }
39981
+ },
39982
+ enabled: true
39983
+ };
39984
+ }
39985
+ function stripToolUiStatusArgument(value) {
39986
+ if (!isRecord2(value) || !(TOOL_UI_STATUS_ARGUMENT in value))
39987
+ return value;
39988
+ const { [TOOL_UI_STATUS_ARGUMENT]: _status, ...args } = value;
39989
+ return args;
39990
+ }
39991
+ function isRecord2(value) {
39992
+ return typeof value === "object" && value !== null && !Array.isArray(value);
39993
+ }
39926
39994
  function normalizeParameters(value) {
39927
39995
  if (value && typeof value === "object" && !Array.isArray(value)) {
39928
39996
  return value;
@@ -40182,7 +40250,7 @@ var AgentService = class {
40182
40250
  };
40183
40251
  }
40184
40252
  };
40185
- function translateEvent(event) {
40253
+ function translateEvent(event, uiStatusToolNames = /* @__PURE__ */ new Set()) {
40186
40254
  switch (event.type) {
40187
40255
  case "message_update": {
40188
40256
  const inner = event.assistantMessageEvent;
@@ -40216,13 +40284,17 @@ function translateEvent(event) {
40216
40284
  }
40217
40285
  return void 0;
40218
40286
  }
40219
- case "tool_execution_start":
40287
+ case "tool_execution_start": {
40288
+ const uiStatusEnabled = uiStatusToolNames.has(event.toolName);
40289
+ const displayName = uiStatusEnabled ? parseConversationToolCallDisplayName(readToolUiStatus(event.args)) : void 0;
40220
40290
  return {
40221
40291
  type: "tool_start",
40222
40292
  toolCallId: event.toolCallId,
40223
40293
  toolName: event.toolName,
40224
- args: event.args
40294
+ ...displayName ? { displayName } : {},
40295
+ args: uiStatusEnabled ? stripToolUiStatusArgument(event.args) : event.args
40225
40296
  };
40297
+ }
40226
40298
  case "tool_execution_end":
40227
40299
  return {
40228
40300
  type: "tool_end",
@@ -40237,14 +40309,17 @@ function translateEvent(event) {
40237
40309
  return void 0;
40238
40310
  }
40239
40311
  }
40240
- function translateEvents(event) {
40241
- const translated = translateEvent(event);
40312
+ function translateEvents(event, uiStatusToolNames = /* @__PURE__ */ new Set()) {
40313
+ const translated = translateEvent(event, uiStatusToolNames);
40242
40314
  const events = translated ? [translated] : [];
40243
40315
  if (event.type === "tool_execution_end" && !event.isError && event.result && typeof event.result === "object" && isAgentPresentationToolResult(event.result.details)) {
40244
40316
  events.push(event.result.details.card);
40245
40317
  }
40246
40318
  return events;
40247
40319
  }
40320
+ function readToolUiStatus(args) {
40321
+ return args && typeof args === "object" && !Array.isArray(args) ? args[TOOL_UI_STATUS_ARGUMENT] : void 0;
40322
+ }
40248
40323
  function toErrorEvent(err2) {
40249
40324
  const message = err2 instanceof Error ? err2.message : typeof err2 === "string" ? err2 : "unknown agent error";
40250
40325
  const code = err2 !== null && typeof err2 === "object" && "code" in err2 && typeof err2.code === "string" ? err2.code : void 0;
@@ -40267,6 +40342,7 @@ var StreamBridge = class {
40267
40342
  sessionDisposed = false;
40268
40343
  session;
40269
40344
  unsubscribe;
40345
+ uiStatusToolNames;
40270
40346
  constructor(prompt, auth, options, images, createSession, linkqueBaseUrl) {
40271
40347
  this.prompt = prompt;
40272
40348
  this.auth = auth;
@@ -40274,6 +40350,7 @@ var StreamBridge = class {
40274
40350
  this.images = images;
40275
40351
  this.createSession = createSession;
40276
40352
  this.linkqueBaseUrl = linkqueBaseUrl;
40353
+ this.uiStatusToolNames = getToolUiStatusEnabledNames(options.tools ?? []);
40277
40354
  }
40278
40355
  /** 产出事件直到 done/error;迭代异常(return()/throw())时走 finally 清理。 */
40279
40356
  async *iterate() {
@@ -40407,7 +40484,7 @@ var StreamBridge = class {
40407
40484
  return;
40408
40485
  this.telemetry?.onEvent(event);
40409
40486
  this.logDebug(`[pi-event] ${this.safeStringify(event)}`);
40410
- for (const translated of translateEvents(event)) {
40487
+ for (const translated of translateEvents(event, this.uiStatusToolNames)) {
40411
40488
  if (translated.type === "error" || translated.type === "done") {
40412
40489
  if (this.settled)
40413
40490
  return;
@@ -44713,27 +44790,27 @@ function wrapMcpServer(server, debugLog) {
44713
44790
  };
44714
44791
  }
44715
44792
  function summarizeMcpResult(result) {
44716
- const object = isRecord2(result) ? result : void 0;
44793
+ const object = isRecord3(result) ? result : void 0;
44717
44794
  const content = Array.isArray(object?.content) ? object.content : void 0;
44718
44795
  const summary = {
44719
44796
  resultType: valueType(result),
44720
44797
  resultKeys: objectKeys(object),
44721
44798
  structuredContentType: valueType(object?.structuredContent),
44722
- structuredContentKeys: objectKeys(isRecord2(object?.structuredContent) ? object.structuredContent : void 0),
44799
+ structuredContentKeys: objectKeys(isRecord3(object?.structuredContent) ? object.structuredContent : void 0),
44723
44800
  contentCount: content?.length ?? 0,
44724
- contentTypes: content?.map((item) => isRecord2(item) && typeof item.type === "string" ? item.type : valueType(item))
44801
+ contentTypes: content?.map((item) => isRecord3(item) && typeof item.type === "string" ? item.type : valueType(item))
44725
44802
  };
44726
44803
  if (typeof object?.isError === "boolean")
44727
44804
  summary.isError = object.isError;
44728
44805
  if (object?.isError === true) {
44729
- const errorText = content?.find((item) => isRecord2(item) && item.type === "text" && typeof item.text === "string");
44730
- if (isRecord2(errorText) && typeof errorText.text === "string") {
44806
+ const errorText = content?.find((item) => isRecord3(item) && item.type === "text" && typeof item.text === "string");
44807
+ if (isRecord3(errorText) && typeof errorText.text === "string") {
44731
44808
  summary.errorMessage = sanitizeDiagnosticText(errorText.text);
44732
44809
  }
44733
44810
  }
44734
44811
  return summary;
44735
44812
  }
44736
- function isRecord2(value) {
44813
+ function isRecord3(value) {
44737
44814
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
44738
44815
  }
44739
44816
  function objectKeys(value) {
@@ -45971,24 +46048,22 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
45971
46048
  }
45972
46049
  async function chat(ctx) {
45973
46050
  let result;
46051
+ const logCtx = withIsoTimestamp({ log: ctx.log, error: ctx.error });
45974
46052
  try {
45975
46053
  const bodyJSON = resolveBodyJSON(ctx.req);
45976
46054
  const historyOwnerId = readAuthenticatedUserId(ctx.req.headers);
45977
46055
  const appwriteApiKey = readAppwriteApiKey(ctx.req.headers);
45978
46056
  if (readOperation(bodyJSON) === REPLACE_ANSWER_OPERATION) {
45979
- const control = await runReplaceAnswer(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, appwriteApiKey);
46057
+ const control = await runReplaceAnswer(ctx.req.method, bodyJSON, process.env, void 0, logCtx, appwriteApiKey);
45980
46058
  return ctx.res.json?.(control.body, control.status);
45981
46059
  }
45982
46060
  const envSelector = readEnvSelector(ctx.req.headers);
45983
46061
  const traceId = readTraceId(ctx.req.headers);
45984
46062
  const temporaryFrontendAppId = readTemporaryFrontendAppId(ctx.req.headers);
45985
- const gatewayAuth = historyOwnerId ? resolveLinkqueGatewayAuth(ctx.req.headers, process.env, {
45986
- log: ctx.log,
45987
- error: ctx.error
45988
- }) : void 0;
45989
- result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, readMcpPhoneAuthorization(ctx.req.headers)) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
46063
+ const gatewayAuth = historyOwnerId ? resolveLinkqueGatewayAuth(ctx.req.headers, process.env, logCtx) : void 0;
46064
+ result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, readMcpPhoneAuthorization(ctx.req.headers)) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
45990
46065
  } catch (err2) {
45991
- ctx.error?.(err2);
46066
+ logCtx?.error?.(err2);
45992
46067
  result = err2 instanceof LinkqueGatewayAuthError || err2 instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(err2.status, err2.code, err2.message) : {
45993
46068
  status: 500,
45994
46069
  body: {
@@ -3,13 +3,13 @@ import {
3
3
  runClientCapability,
4
4
  runClientCapabilityCleanup,
5
5
  runClientCapabilityResult
6
- } from "../../chunk-RHMVQTA7.js";
6
+ } from "../../chunk-WM6JHW55.js";
7
7
  import "../../chunk-IWOFD643.js";
8
8
  import "../../chunk-PXCGFBV5.js";
9
9
  import "../../chunk-ETG6PNHQ.js";
10
- import "../../chunk-ZNU4GVF3.js";
11
- import "../../chunk-XUFLSZM4.js";
10
+ import "../../chunk-OHRCYI66.js";
12
11
  import "../../chunk-EAODRPW4.js";
12
+ import "../../chunk-XUFLSZM4.js";
13
13
  import "../../chunk-GAYNLDWK.js";
14
14
  import "../../chunk-DNTEEBEH.js";
15
15
  import "../../chunk-2ESYSVXG.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  getBakedProtocol,
3
3
  setBakedProtocol
4
- } from "../chunk-AACYYAZ6.js";
5
- import "../chunk-ZNU4GVF3.js";
6
- import "../chunk-XUFLSZM4.js";
4
+ } from "../chunk-XL6BPKTI.js";
5
+ import "../chunk-OHRCYI66.js";
7
6
  import "../chunk-EAODRPW4.js";
7
+ import "../chunk-XUFLSZM4.js";
8
8
  import "../chunk-GAYNLDWK.js";
9
9
  import "../chunk-DNTEEBEH.js";
10
10
  import "../chunk-2ESYSVXG.js";