linkque-cli-v2 1.3.5 → 1.3.7

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 (18) hide show
  1. package/linkquejs.js +14 -104
  2. package/package.json +1 -1
  3. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NBYB7HSY.js → chunk-AACYYAZ6.js} +1 -1
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-HM7KNEG3.js → chunk-DNTEEBEH.js} +5 -0
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-EAODRPW4.js +518 -0
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-LT6VSAY4.js → chunk-RHMVQTA7.js} +56 -144
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-VVEDZWQ5.js → chunk-ZNU4GVF3.js} +15262 -378
  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 +413 -625
  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/worker.js +430 -87
@@ -16,9 +16,12 @@ import {
16
16
  require_json_bigint
17
17
  } from "./chunk-ETG6PNHQ.js";
18
18
  import {
19
+ LINKQUE_ENDPOINT_PROD,
20
+ McpPhoneAuthorizationFailedError,
21
+ McpPhoneAuthorizationRequiredError,
19
22
  RUNTIME_CONFIG_DEFAULTS,
20
23
  RuntimeConfigProvider
21
- } from "./chunk-VVEDZWQ5.js";
24
+ } from "./chunk-ZNU4GVF3.js";
22
25
  import {
23
26
  __commonJS,
24
27
  __require,
@@ -7343,6 +7346,10 @@ var APPBASE_RUNTIME_CONFIG_DEFAULTS = Object.freeze({
7343
7346
  LINKQUEGW_KNOWLEDGE_BASE_URL_PRE: LINKQUE_ENDPOINT_PRE,
7344
7347
  LINKQUEGW_WEB_SEARCH_BASE_URL_PRE: LINKQUE_ENDPOINT_PRE,
7345
7348
  LINKQUEGW_EVENT_BASE_URL_PRE: LINKQUE_ENDPOINT_PRE,
7349
+ LINKQUEGW_TELEMETRY_LOGS_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/telemetry/v1/logs`,
7350
+ LINKQUEGW_TELEMETRY_TRACES_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/telemetry/v1/traces`,
7351
+ LINKQUEGW_TELEMETRY_LOGS_ENDPOINT_PRE: `${LINKQUE_ENDPOINT_PRE}/api/telemetry/v1/logs`,
7352
+ LINKQUEGW_TELEMETRY_TRACES_ENDPOINT_PRE: `${LINKQUE_ENDPOINT_PRE}/api/telemetry/v1/traces`,
7346
7353
  LINKQUEGW_MCP_SIGN_ENDPOINT_PRE: `${LINKQUE_ENDPOINT_PRE}/api/mcp/signature`,
7347
7354
  LINKQUE_OPEN_MCP_BASE_URL: "https://opengw.alipay.com",
7348
7355
  LINKQUE_OPEN_MCP_BASE_URL_PRE: "https://opengw-pre.alipay.com",
@@ -7358,8 +7365,6 @@ var APPBASE_RUNTIME_CONFIG_DEFAULTS = Object.freeze({
7358
7365
  SEARCH_TABLE_ID: "linkque_conversation_message_search",
7359
7366
  CLIENT_CAPABILITY_DATABASE_ID: "linkque",
7360
7367
  CLIENT_CAPABILITY_TABLE_ID: "linkque_client_cap_invocations",
7361
- A2UI_ACTION_DATABASE_ID: "linkque",
7362
- A2UI_ACTION_TABLE_ID: "linkque_a2ui_action_invocations",
7363
7368
  RUN_CHUNK_SIZE: "30",
7364
7369
  RUN_CANCEL_POLL_INTERVAL_MS: "500",
7365
7370
  LOG_LEVEL: "INFO"
@@ -11913,138 +11918,6 @@ function parsePositiveInt(raw, name) {
11913
11918
  return n;
11914
11919
  }
11915
11920
 
11916
- // ../linkque-agent-appwrite-integrate/dist/esm/runtime/paymentActionStore.js
11917
- import { createHash as createHash2 } from "node:crypto";
11918
- var PAYMENT_INVOCATION_TTL_MS = 24 * 60 * 60 * 1e3;
11919
- function createPaymentInvocation(ownerId, request, now = /* @__PURE__ */ new Date()) {
11920
- const invocationId = createPaymentInvocationId(ownerId, request);
11921
- return {
11922
- invocationId,
11923
- ownerId,
11924
- agentId: request.agentId,
11925
- threadId: request.threadId,
11926
- cardRef: request.source.cardRef,
11927
- cardRevision: request.source.cardRevision,
11928
- cardInstanceId: request.source.cardInstanceId,
11929
- surfaceId: request.source.surfaceId,
11930
- componentId: request.source.componentId,
11931
- input: request.input,
11932
- status: "executing",
11933
- createdAt: now.toISOString(),
11934
- expiresAt: new Date(now.getTime() + PAYMENT_INVOCATION_TTL_MS).toISOString()
11935
- };
11936
- }
11937
- function createPaymentInvocationId(ownerId, request) {
11938
- const material = stableStringify({
11939
- ownerId,
11940
- agentId: request.agentId,
11941
- threadId: request.threadId,
11942
- cardInstanceId: request.source.cardInstanceId,
11943
- cardRevision: request.source.cardRevision,
11944
- surfaceId: request.source.surfaceId,
11945
- componentId: request.source.componentId,
11946
- input: request.input
11947
- });
11948
- return `pa_${createHash2("sha256").update(material).digest("hex").slice(0, 32)}`;
11949
- }
11950
- function createPaymentActionStore(databases, databaseId, tableId) {
11951
- return {
11952
- async begin(invocation) {
11953
- const { invocationId, input, ...fields } = invocation;
11954
- try {
11955
- const document = await databases.createDocument(databaseId, tableId, invocationId, { ...fields, input: JSON.stringify(input) }, []);
11956
- return {
11957
- kind: "created",
11958
- invocation: readInvocation2(document) ?? invocation
11959
- };
11960
- } catch (error) {
11961
- if (!isConflict2(error))
11962
- throw error;
11963
- const existing = await this.get(invocationId);
11964
- if (!existing)
11965
- throw error;
11966
- return { kind: "existing", invocation: existing };
11967
- }
11968
- },
11969
- async get(invocationId) {
11970
- try {
11971
- return readInvocation2(await databases.getDocument(databaseId, tableId, invocationId));
11972
- } catch (error) {
11973
- if (isNotFound2(error))
11974
- return void 0;
11975
- throw error;
11976
- }
11977
- },
11978
- async update(invocationId, patch) {
11979
- const data = { ...patch };
11980
- const document = await databases.updateDocument(databaseId, tableId, invocationId, data);
11981
- const invocation = readInvocation2(document);
11982
- if (!invocation)
11983
- throw new Error("\u652F\u4ED8 invocation \u6301\u4E45\u5316\u7ED3\u679C\u65E0\u6548");
11984
- return invocation;
11985
- },
11986
- async cleanup(now) {
11987
- const result = await databases.listDocuments(databaseId, tableId, [
11988
- Query.lessThanEqual("expiresAt", now),
11989
- Query.limit(500)
11990
- ]);
11991
- for (const document of result.documents) {
11992
- await databases.deleteDocument(databaseId, tableId, document.$id);
11993
- }
11994
- return result.documents.length;
11995
- }
11996
- };
11997
- }
11998
- function readInvocation2(value) {
11999
- if (!value || typeof value !== "object" || Array.isArray(value))
12000
- return void 0;
12001
- const row = value;
12002
- if (typeof row.$id !== "string" || typeof row.ownerId !== "string" || typeof row.agentId !== "string" || typeof row.threadId !== "string" || typeof row.cardRef !== "string" || typeof row.cardRevision !== "string" || typeof row.cardInstanceId !== "string" || typeof row.surfaceId !== "string" || typeof row.componentId !== "string" || typeof row.input !== "string" || typeof row.status !== "string" || typeof row.createdAt !== "string" || typeof row.expiresAt !== "string")
12003
- return void 0;
12004
- const input = parseJsonObject(row.input);
12005
- if (!input)
12006
- return void 0;
12007
- return {
12008
- invocationId: row.$id,
12009
- ownerId: row.ownerId,
12010
- agentId: row.agentId,
12011
- threadId: row.threadId,
12012
- cardRef: row.cardRef,
12013
- cardRevision: row.cardRevision,
12014
- cardInstanceId: row.cardInstanceId,
12015
- surfaceId: row.surfaceId,
12016
- componentId: row.componentId,
12017
- input,
12018
- status: row.status,
12019
- ...typeof row.tradeNO === "string" ? { tradeNO: row.tradeNO } : {},
12020
- createdAt: row.createdAt,
12021
- expiresAt: row.expiresAt
12022
- };
12023
- }
12024
- function parseJsonObject(value) {
12025
- try {
12026
- const parsed = JSON.parse(value);
12027
- return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
12028
- } catch {
12029
- return void 0;
12030
- }
12031
- }
12032
- function stableStringify(value) {
12033
- if (Array.isArray(value))
12034
- return `[${value.map(stableStringify).join(",")}]`;
12035
- if (value && typeof value === "object") {
12036
- return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item)}`).join(",")}}`;
12037
- }
12038
- return JSON.stringify(value);
12039
- }
12040
- function isNotFound2(error) {
12041
- return Boolean(error && typeof error === "object" && "code" in error && error.code === 404);
12042
- }
12043
- function isConflict2(error) {
12044
- const value = error;
12045
- return value?.code === 409 || /already exists|conflict|duplicate|409/i.test(value?.message ?? "");
12046
- }
12047
-
12048
11921
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/handlerUtils.js
12049
11922
  function resolveBodyJSON(req) {
12050
11923
  if (req.bodyJSON !== void 0 && typeof req.bodyJSON !== "string") {
@@ -12089,6 +11962,52 @@ var TRIGGER_HEADER = "x-appwrite-trigger";
12089
11962
  var ENV_SELECTOR_HEADER = "x-linkque-env";
12090
11963
  var TRACE_ID_HEADER = "x-trace-id";
12091
11964
  var TEMPORARY_FRONTEND_APP_ID_HEADER = "x-linkque-alipay-app-id";
11965
+ var ALIPAY_AUTH_CODE_HEADER = "x-alipay-authcode";
11966
+ var AUTH_UNAVAILABLE_HEADER = "x-linkque-phone-auth-unavailable";
11967
+ function readMcpPhoneAuthorization(headers) {
11968
+ const authCode = readHeader(headers, ALIPAY_AUTH_CODE_HEADER)?.trim();
11969
+ if (authCode && authCode.length <= 4096)
11970
+ return { kind: "authorized", authCode };
11971
+ if (readHeader(headers, AUTH_UNAVAILABLE_HEADER) === "1")
11972
+ return { kind: "unavailable" };
11973
+ return void 0;
11974
+ }
11975
+ function mcpPhoneAuthorizationChallenge(error) {
11976
+ if (error instanceof McpPhoneAuthorizationFailedError) {
11977
+ return {
11978
+ status: 403,
11979
+ body: {
11980
+ ok: false,
11981
+ error: { code: error.code, message: error.message, retryable: true }
11982
+ }
11983
+ };
11984
+ }
11985
+ if (!(error instanceof McpPhoneAuthorizationRequiredError))
11986
+ return void 0;
11987
+ return {
11988
+ status: 428,
11989
+ body: {
11990
+ error: { code: error.code, message: error.message, retryable: true },
11991
+ authorization: {
11992
+ capability: "userInfo",
11993
+ scopes: ["auth_user"],
11994
+ required: error.required
11995
+ }
11996
+ }
11997
+ };
11998
+ }
11999
+ function readHeader(headers, name) {
12000
+ if (!headers)
12001
+ return void 0;
12002
+ const direct = headValue(headers[name]);
12003
+ if (direct !== void 0)
12004
+ return direct;
12005
+ for (const [key, value] of Object.entries(headers)) {
12006
+ if (key.toLowerCase() === name)
12007
+ return headValue(value);
12008
+ }
12009
+ return void 0;
12010
+ }
12092
12011
  function readEnvSelector(headers) {
12093
12012
  if (!headers)
12094
12013
  return "PROD";
@@ -12236,13 +12155,6 @@ async function clientCapability(ctx) {
12236
12155
  const store = createClientCapabilityStore(handle.databases, config.get("CLIENT_CAPABILITY_DATABASE_ID"), config.get("CLIENT_CAPABILITY_TABLE_ID"));
12237
12156
  const trigger = readAppwriteTrigger(ctx.req.headers);
12238
12157
  result = await runClientCapability(trigger, ctx.req.method, resolveBodyJSON(ctx.req), readAuthenticatedUserId(ctx.req.headers), store);
12239
- if (trigger === "schedule") {
12240
- const paymentDeleted = await createPaymentActionStore(handle.databases, config.get("A2UI_ACTION_DATABASE_ID"), config.get("A2UI_ACTION_TABLE_ID")).cleanup((/* @__PURE__ */ new Date()).toISOString());
12241
- result = {
12242
- status: 200,
12243
- body: { ...result.body, paymentDeleted }
12244
- };
12245
- }
12246
12158
  } catch (error) {
12247
12159
  ctx.error?.(error);
12248
12160
  result = error instanceof LinkqueGatewayAuthError || error instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(error.status, error.code, error.message) : jsonError(500, "internal_error", error instanceof Error ? error.message : "unknown error");
@@ -12290,6 +12202,8 @@ export {
12290
12202
  resolveBodyJSON,
12291
12203
  toAgentRunMessages,
12292
12204
  jsonError,
12205
+ readMcpPhoneAuthorization,
12206
+ mcpPhoneAuthorizationChallenge,
12293
12207
  readEnvSelector,
12294
12208
  readTraceId,
12295
12209
  readTemporaryFrontendAppId,
@@ -12303,8 +12217,6 @@ export {
12303
12217
  createAppBaseClient,
12304
12218
  createClientCapabilityStore,
12305
12219
  parseStoredClientCapabilityResult,
12306
- createPaymentInvocation,
12307
- createPaymentActionStore,
12308
12220
  runClientCapability,
12309
12221
  runClientCapabilityResult,
12310
12222
  runClientCapabilityCleanup,