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
@@ -21,7 +21,7 @@ import {
21
21
  McpPhoneAuthorizationRequiredError,
22
22
  RUNTIME_CONFIG_DEFAULTS,
23
23
  RuntimeConfigProvider
24
- } from "./chunk-ZNU4GVF3.js";
24
+ } from "./chunk-OHRCYI66.js";
25
25
  import {
26
26
  __commonJS,
27
27
  __require,
@@ -7375,108 +7375,6 @@ var AppbaseRuntimeConfigProvider = class extends RuntimeConfigProvider {
7375
7375
  }
7376
7376
  };
7377
7377
 
7378
- // ../linkque-agent-appwrite-integrate/dist/esm/runtime/auth.js
7379
- var LINKQUE_AUTHORIZATION_HEADER = "x-linkque-authorization";
7380
- var LinkqueGatewayAuthError = class extends Error {
7381
- code = "invalid_linkque_authorization";
7382
- status = 401;
7383
- constructor(message = "X-Linkque-Authorization \u5FC5\u987B\u662F\u5355\u4E2A Bearer \u51ED\u636E") {
7384
- super(message);
7385
- this.name = "LinkqueGatewayAuthError";
7386
- }
7387
- };
7388
- var LinkqueGatewayAuthUnconfiguredError = class extends Error {
7389
- code = "auth_unconfigured";
7390
- status = 500;
7391
- constructor(message = "\u8BA4\u8BC1\u914D\u7F6E\u7F3A\u5931:LINKQUE_AGENT_ACCESS_KEY \u672A\u8BBE\u7F6E") {
7392
- super(message);
7393
- this.name = "LinkqueGatewayAuthUnconfiguredError";
7394
- }
7395
- };
7396
- function resolveLinkqueGatewayAuth(headers, env = process.env, logCtx) {
7397
- const config = new AppbaseRuntimeConfigProvider({ ...env });
7398
- const log = (...a2) => logCtx?.log?.("[auth-resolve]", ...a2);
7399
- const logError = (...a2) => logCtx?.error?.("[auth-resolve]", ...a2);
7400
- log("stage=start");
7401
- const matches = Object.entries(headers ?? {}).filter(([key]) => key.toLowerCase() === LINKQUE_AUTHORIZATION_HEADER);
7402
- if (matches.length > 0) {
7403
- log(`stage=header-inspection, state=present, count=${matches.length}`);
7404
- log("stage=user-token-validation, state=start");
7405
- if (matches.length !== 1) {
7406
- logError("stage=failed, reason=duplicate-header");
7407
- throw new LinkqueGatewayAuthError();
7408
- }
7409
- const value = matches[0]?.[1];
7410
- if (typeof value !== "string") {
7411
- logError("stage=failed, reason=multi-value-header");
7412
- throw new LinkqueGatewayAuthError();
7413
- }
7414
- if (value.includes(",")) {
7415
- logError("stage=failed, reason=joined-header");
7416
- throw new LinkqueGatewayAuthError();
7417
- }
7418
- const match = /^Bearer[\t ]+([^\s,]+)$/iu.exec(value.trim());
7419
- const token = match?.[1];
7420
- if (!token) {
7421
- logError("stage=failed, reason=invalid-bearer-format");
7422
- throw new LinkqueGatewayAuthError();
7423
- }
7424
- log("stage=user-token-validation, state=success, scheme=Bearer");
7425
- const provider2 = resolveProvider(config.get("LINKQUE_MODEL_PROVIDER"), log, logError);
7426
- log("stage=complete, mode=user-token, source=request-header");
7427
- return {
7428
- mode: "user-token",
7429
- modelCredential: token,
7430
- authorizationHeader: `Bearer ${token}`,
7431
- auth: { provider: provider2, apiKey: token }
7432
- };
7433
- }
7434
- log("stage=header-inspection, state=absent");
7435
- log("stage=aak-fallback, state=start, source=env:LINKQUE_AGENT_ACCESS_KEY");
7436
- const apiKey = config.get("LINKQUE_AGENT_ACCESS_KEY");
7437
- if (!apiKey) {
7438
- logError("stage=failed, reason=aak-unconfigured");
7439
- throw new LinkqueGatewayAuthUnconfiguredError();
7440
- }
7441
- log("stage=aak-fallback, state=configured");
7442
- const provider = resolveProvider(config.get("LINKQUE_MODEL_PROVIDER"), log, logError);
7443
- log("stage=complete, mode=aak, source=env:LINKQUE_AGENT_ACCESS_KEY");
7444
- return {
7445
- mode: "aak",
7446
- modelCredential: apiKey,
7447
- authorizationHeader: `aak ${apiKey}`,
7448
- auth: { provider, apiKey }
7449
- };
7450
- }
7451
- function resolveGatewayAuthContext(gatewayAuth, env = process.env, logCtx, caller = "unknown") {
7452
- const log = (...a2) => logCtx?.log?.("[auth-resolve]", ...a2);
7453
- if (gatewayAuth) {
7454
- log(`stage=context-selection, caller=${caller}, branch=request-context, mode=${gatewayAuth.mode}`);
7455
- return gatewayAuth;
7456
- }
7457
- log(`stage=context-selection, caller=${caller}, branch=compat-env-fallback`);
7458
- return resolveLinkqueGatewayAuth(void 0, env, logCtx);
7459
- }
7460
- function parseProvider(raw) {
7461
- const upper = raw.toUpperCase();
7462
- if (upper === "LINKQUE")
7463
- return "LINKQUE";
7464
- if (upper === "TEST")
7465
- return "TEST";
7466
- throw new Error(`\u4E0D\u652F\u6301\u7684 LINKQUE_MODEL_PROVIDER="${raw}"(\u5F53\u524D\u652F\u6301:LINKQUE\u3001TEST)`);
7467
- }
7468
- function resolveProvider(raw, log, logError) {
7469
- log("stage=provider-resolution, state=start");
7470
- try {
7471
- const provider = parseProvider(raw);
7472
- log(`stage=provider-resolution, state=success, provider=${provider}`);
7473
- return provider;
7474
- } catch (error) {
7475
- logError("stage=failed, reason=invalid-provider");
7476
- throw error;
7477
- }
7478
- }
7479
-
7480
7378
  // ../../node_modules/node-fetch-native-with-agent/dist/index.mjs
7481
7379
  var a = Object.defineProperty;
7482
7380
  var t = (e, r) => a(e, "name", { value: r, configurable: true });
@@ -11633,6 +11531,220 @@ _Operator.dateAddDays = (days) => new _Operator("dateAddDays", [days]).toString(
11633
11531
  _Operator.dateSubDays = (days) => new _Operator("dateSubDays", [days]).toString();
11634
11532
  _Operator.dateSetNow = () => new _Operator("dateSetNow", []).toString();
11635
11533
 
11534
+ // ../linkque-agent-appwrite-integrate/dist/esm/runtime/runStorage.js
11535
+ var ENDPOINT_SOURCES = [
11536
+ "APPWRITE_FUNCTION_API_ENDPOINT",
11537
+ "APPWRITE_API_ENDPOINT",
11538
+ "APPWRITE_ENDPOINT",
11539
+ "APPBASE_API_ENDPOINT",
11540
+ "APPBASE_ENDPOINT"
11541
+ ];
11542
+ var PROJECT_SOURCES = [
11543
+ "APPWRITE_FUNCTION_PROJECT_ID",
11544
+ "APPWRITE_PROJECT_ID",
11545
+ "APPWRITE_PROJECT",
11546
+ "APPBASE_PROJECT_ID",
11547
+ "APPBASE_PROJECT"
11548
+ ];
11549
+ function resolveRunStorage(env = process.env, logCtx) {
11550
+ const log = (...a2) => logCtx?.log?.("[runStorage]", ...a2);
11551
+ const config = new AppbaseRuntimeConfigProvider(env);
11552
+ const databaseId = config.get("RUN_DATABASE_ID");
11553
+ const tableId = config.get("RUN_TABLE_ID");
11554
+ const chunkSize = parsePositiveInt(config.get("RUN_CHUNK_SIZE"), "RUN_CHUNK_SIZE");
11555
+ log("\u843D\u5E93\u914D\u7F6E\u89E3\u6790\u6210\u529F, databaseId=", databaseId, "tableId=", tableId, "chunkSize=", chunkSize);
11556
+ return { databaseId, tableId, chunkSize };
11557
+ }
11558
+ function createAppBaseClient(env = process.env, logCtx, executionApiKey) {
11559
+ const log = (...a2) => logCtx?.log?.("[appbase-client]", ...a2);
11560
+ const config = new AppbaseRuntimeConfigProvider(env);
11561
+ const endpoint = config.getRaw("APPWRITE_FUNCTION_API_ENDPOINT") ?? config.getRaw("APPWRITE_API_ENDPOINT") ?? config.getRaw("APPWRITE_ENDPOINT") ?? config.getRaw("APPBASE_API_ENDPOINT") ?? config.getRaw("APPBASE_ENDPOINT");
11562
+ if (!endpoint) {
11563
+ throw new Error("APPBASE_ENDPOINT \u672A\u914D\u7F6E:\u5E73\u53F0\u4E0D\u6CE8\u5165 AppBase API \u5165\u53E3\u70B9\u7531 deploy \u5199\u5165 APPBASE_ENDPOINT");
11564
+ }
11565
+ const projectId = config.getRaw("APPWRITE_FUNCTION_PROJECT_ID") ?? config.getRaw("APPWRITE_PROJECT_ID") ?? config.getRaw("APPWRITE_PROJECT") ?? config.getRaw("APPBASE_PROJECT_ID") ?? config.getRaw("APPBASE_PROJECT");
11566
+ const apiKey = executionApiKey?.trim() || config.getRaw("APPWRITE_FUNCTION_API_KEY") || config.getRaw("APPWRITE_API_KEY") || config.getRaw("APPBASE_API_KEY");
11567
+ if (!projectId) {
11568
+ throw new Error("APPBASE_PROJECT_ID \u672A\u914D\u7F6E:\u5E73\u53F0\u5E94\u6CE8\u5165 APPWRITE_FUNCTION_PROJECT_ID,\u6216\u7531 deploy \u5199\u5165 APPBASE_PROJECT_ID");
11569
+ }
11570
+ if (!apiKey) {
11571
+ throw new Error("Appwrite Server API Key \u7F3A\u5931:\u5E73\u53F0\u5E94\u5728 x-appwrite-key \u6CE8\u5165\u52A8\u6001 key,\u6216\u7531\u672C\u5730/\u6D4B\u8BD5 export APPWRITE_FUNCTION_API_KEY/APPWRITE_API_KEY/APPBASE_API_KEY");
11572
+ }
11573
+ log("AppBase Client \u6784\u9020, endpoint=", maskEndpoint(endpoint), "(source=", whichSource(env, ENDPOINT_SOURCES), ") projectId=", projectId, "(source=", whichSource(env, PROJECT_SOURCES), ") apiKey=", maskSecret(apiKey), "(source=", executionApiKey?.trim() ? "request:x-appwrite-key" : config.getRaw("APPWRITE_FUNCTION_API_KEY") ? "APPWRITE_FUNCTION_API_KEY" : config.getRaw("APPWRITE_API_KEY") ? "APPWRITE_API_KEY" : "APPBASE_API_KEY", ")");
11574
+ const client = new Client().setEndpoint(endpoint).setProject(projectId).setKey(apiKey);
11575
+ return { client, databases: new Databases(client) };
11576
+ }
11577
+ function parsePositiveInt(raw, name) {
11578
+ const n = Number(raw);
11579
+ if (!Number.isFinite(n) || n < 1 || !Number.isInteger(n)) {
11580
+ throw new Error(`${name} \u5FC5\u987B\u662F\u6B63\u6574\u6570,\u5B9E\u9645="${raw}"`);
11581
+ }
11582
+ return n;
11583
+ }
11584
+
11585
+ // ../linkque-agent-appwrite-integrate/dist/esm/runtime/diagnostics.js
11586
+ function withIsoTimestamp(logCtx, now = () => /* @__PURE__ */ new Date()) {
11587
+ if (!logCtx)
11588
+ return void 0;
11589
+ const wrap = (write) => write ? (...args) => write(`[${now().toISOString()}]`, ...args) : void 0;
11590
+ return {
11591
+ ...logCtx.log ? { log: wrap(logCtx.log) } : {},
11592
+ ...logCtx.error ? { error: wrap(logCtx.error) } : {}
11593
+ };
11594
+ }
11595
+ function createA2UIInfoLog(env, logCtx, traceId, getMcpTraceId) {
11596
+ const level = new AppbaseRuntimeConfigProvider(env).get("LOG_LEVEL").trim().toLowerCase();
11597
+ if (!logCtx?.log || !["info", "debug"].includes(level))
11598
+ return void 0;
11599
+ return (line, scope) => {
11600
+ try {
11601
+ logCtx.log?.("[a2ui-action][info]", JSON.stringify({
11602
+ ...JSON.parse(line),
11603
+ level: "info",
11604
+ scope,
11605
+ traceId,
11606
+ mcpTraceId: getMcpTraceId?.()
11607
+ }));
11608
+ } catch {
11609
+ }
11610
+ };
11611
+ }
11612
+ function maskSecret(raw) {
11613
+ return raw ? "<set>" : "<unset>";
11614
+ }
11615
+ function maskEndpoint(raw) {
11616
+ return raw ? raw.replace(/\/+$/, "") : "<unset>";
11617
+ }
11618
+ function isDebugLogLevel(env) {
11619
+ return new AppbaseRuntimeConfigProvider(env).get("LOG_LEVEL") === "debug";
11620
+ }
11621
+ function whichSource(env, candidates) {
11622
+ const config = new AppbaseRuntimeConfigProvider(env);
11623
+ return candidates.find((name) => config.getRaw(name) !== void 0) ?? "<none>";
11624
+ }
11625
+ function describeRuntimeEnv(env, hasRequestKey = false) {
11626
+ const config = new AppbaseRuntimeConfigProvider(env);
11627
+ const endpointSource = whichSource(env, ENDPOINT_SOURCES);
11628
+ const projectSource = whichSource(env, PROJECT_SOURCES);
11629
+ const apiKeySource = [
11630
+ "APPWRITE_FUNCTION_API_KEY",
11631
+ "APPWRITE_API_KEY",
11632
+ "APPBASE_API_KEY"
11633
+ ].find((name) => Boolean(config.getRaw(name)));
11634
+ const lines = [
11635
+ `LINKQUE_AGENT_ACCESS_KEY=${maskSecret(config.get("LINKQUE_AGENT_ACCESS_KEY"))}`,
11636
+ `APPBASE_ENDPOINT=${maskEndpoint(config.getRaw(endpointSource))}(src=${endpointSource})`,
11637
+ `APPBASE_PROJECT_ID=${config.getRaw(projectSource) || "<unset>"}(src=${projectSource})`,
11638
+ `APPBASE_API_KEY=${hasRequestKey ? "<set>" : maskSecret(apiKeySource ? config.getRaw(apiKeySource) : void 0)}(src=${hasRequestKey ? "request:x-appwrite-key" : apiKeySource ?? "<none>"})`
11639
+ ];
11640
+ for (const name of Object.keys(APPBASE_RUNTIME_CONFIG_DEFAULTS)) {
11641
+ lines.push(`${name}=${config.get(name)}(src=${config.getSource(name)})`);
11642
+ }
11643
+ return lines;
11644
+ }
11645
+
11646
+ // ../linkque-agent-appwrite-integrate/dist/esm/runtime/auth.js
11647
+ var LINKQUE_AUTHORIZATION_HEADER = "x-linkque-authorization";
11648
+ var LinkqueGatewayAuthError = class extends Error {
11649
+ code = "invalid_linkque_authorization";
11650
+ status = 401;
11651
+ constructor(message = "X-Linkque-Authorization \u5FC5\u987B\u662F\u5355\u4E2A Bearer \u51ED\u636E") {
11652
+ super(message);
11653
+ this.name = "LinkqueGatewayAuthError";
11654
+ }
11655
+ };
11656
+ var LinkqueGatewayAuthUnconfiguredError = class extends Error {
11657
+ code = "auth_unconfigured";
11658
+ status = 500;
11659
+ constructor(message = "\u8BA4\u8BC1\u914D\u7F6E\u7F3A\u5931:LINKQUE_AGENT_ACCESS_KEY \u672A\u8BBE\u7F6E") {
11660
+ super(message);
11661
+ this.name = "LinkqueGatewayAuthUnconfiguredError";
11662
+ }
11663
+ };
11664
+ function resolveLinkqueGatewayAuth(headers, env = process.env, logCtx) {
11665
+ const config = new AppbaseRuntimeConfigProvider({ ...env });
11666
+ const log = (...a2) => logCtx?.log?.("[auth-resolve]", ...a2);
11667
+ const logError = (...a2) => logCtx?.error?.("[auth-resolve]", ...a2);
11668
+ log("stage=start");
11669
+ const matches = Object.entries(headers ?? {}).filter(([key]) => key.toLowerCase() === LINKQUE_AUTHORIZATION_HEADER);
11670
+ if (matches.length > 0) {
11671
+ log(`stage=header-inspection, state=present, count=${matches.length}`);
11672
+ log("stage=user-token-validation, state=start");
11673
+ if (matches.length !== 1) {
11674
+ logError("stage=failed, reason=duplicate-header");
11675
+ throw new LinkqueGatewayAuthError();
11676
+ }
11677
+ const value = matches[0]?.[1];
11678
+ if (typeof value !== "string") {
11679
+ logError("stage=failed, reason=multi-value-header");
11680
+ throw new LinkqueGatewayAuthError();
11681
+ }
11682
+ if (value.includes(",")) {
11683
+ logError("stage=failed, reason=joined-header");
11684
+ throw new LinkqueGatewayAuthError();
11685
+ }
11686
+ const match = /^Bearer[\t ]+([^\s,]+)$/iu.exec(value.trim());
11687
+ const token = match?.[1];
11688
+ if (!token) {
11689
+ logError("stage=failed, reason=invalid-bearer-format");
11690
+ throw new LinkqueGatewayAuthError();
11691
+ }
11692
+ log("stage=user-token-validation, state=success, scheme=Bearer");
11693
+ const provider2 = resolveProvider(config.get("LINKQUE_MODEL_PROVIDER"), log, logError);
11694
+ log("stage=complete, mode=user-token, source=request-header");
11695
+ return {
11696
+ mode: "user-token",
11697
+ modelCredential: token,
11698
+ authorizationHeader: `Bearer ${token}`,
11699
+ auth: { provider: provider2, apiKey: token }
11700
+ };
11701
+ }
11702
+ log("stage=header-inspection, state=absent");
11703
+ log("stage=aak-fallback, state=start, source=env:LINKQUE_AGENT_ACCESS_KEY");
11704
+ const apiKey = config.get("LINKQUE_AGENT_ACCESS_KEY");
11705
+ if (!apiKey) {
11706
+ logError("stage=failed, reason=aak-unconfigured");
11707
+ throw new LinkqueGatewayAuthUnconfiguredError();
11708
+ }
11709
+ log("stage=aak-fallback, state=configured");
11710
+ const provider = resolveProvider(config.get("LINKQUE_MODEL_PROVIDER"), log, logError);
11711
+ log("stage=complete, mode=aak, source=env:LINKQUE_AGENT_ACCESS_KEY");
11712
+ return {
11713
+ mode: "aak",
11714
+ modelCredential: apiKey,
11715
+ authorizationHeader: `aak ${apiKey}`,
11716
+ auth: { provider, apiKey }
11717
+ };
11718
+ }
11719
+ function resolveGatewayAuthContext(gatewayAuth, env = process.env, logCtx, caller = "unknown") {
11720
+ const log = (...a2) => logCtx?.log?.("[auth-resolve]", ...a2);
11721
+ if (gatewayAuth) {
11722
+ log(`stage=context-selection, caller=${caller}, branch=request-context, mode=${gatewayAuth.mode}`);
11723
+ return gatewayAuth;
11724
+ }
11725
+ log(`stage=context-selection, caller=${caller}, branch=compat-env-fallback`);
11726
+ return resolveLinkqueGatewayAuth(void 0, env, logCtx);
11727
+ }
11728
+ function parseProvider(raw) {
11729
+ const upper = raw.toUpperCase();
11730
+ if (upper === "LINKQUE")
11731
+ return "LINKQUE";
11732
+ if (upper === "TEST")
11733
+ return "TEST";
11734
+ throw new Error(`\u4E0D\u652F\u6301\u7684 LINKQUE_MODEL_PROVIDER="${raw}"(\u5F53\u524D\u652F\u6301:LINKQUE\u3001TEST)`);
11735
+ }
11736
+ function resolveProvider(raw, log, logError) {
11737
+ log("stage=provider-resolution, state=start");
11738
+ try {
11739
+ const provider = parseProvider(raw);
11740
+ log(`stage=provider-resolution, state=success, provider=${provider}`);
11741
+ return provider;
11742
+ } catch (error) {
11743
+ logError("stage=failed, reason=invalid-provider");
11744
+ throw error;
11745
+ }
11746
+ }
11747
+
11636
11748
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/clientCapabilityStore.js
11637
11749
  import { createHash } from "node:crypto";
11638
11750
  var TRANSACTION_TTL_SECONDS = 60;
@@ -11815,109 +11927,6 @@ function isConflict(error) {
11815
11927
  return value.code === 409 || /already exists|conflict|duplicate|409/i.test(value.message ?? "");
11816
11928
  }
11817
11929
 
11818
- // ../linkque-agent-appwrite-integrate/dist/esm/runtime/diagnostics.js
11819
- function createA2UIInfoLog(env, logCtx, traceId, getMcpTraceId) {
11820
- const level = new AppbaseRuntimeConfigProvider(env).get("LOG_LEVEL").trim().toLowerCase();
11821
- if (!logCtx?.log || !["info", "debug"].includes(level))
11822
- return void 0;
11823
- return (line, scope) => {
11824
- try {
11825
- logCtx.log?.("[a2ui-action][info]", JSON.stringify({
11826
- ...JSON.parse(line),
11827
- level: "info",
11828
- scope,
11829
- traceId,
11830
- mcpTraceId: getMcpTraceId?.()
11831
- }));
11832
- } catch {
11833
- }
11834
- };
11835
- }
11836
- function maskSecret(raw) {
11837
- return raw ? "<set>" : "<unset>";
11838
- }
11839
- function maskEndpoint(raw) {
11840
- return raw ? raw.replace(/\/+$/, "") : "<unset>";
11841
- }
11842
- function isDebugLogLevel(env) {
11843
- return new AppbaseRuntimeConfigProvider(env).get("LOG_LEVEL") === "debug";
11844
- }
11845
- function whichSource(env, candidates) {
11846
- const config = new AppbaseRuntimeConfigProvider(env);
11847
- return candidates.find((name) => config.getRaw(name) !== void 0) ?? "<none>";
11848
- }
11849
- function describeRuntimeEnv(env, hasRequestKey = false) {
11850
- const config = new AppbaseRuntimeConfigProvider(env);
11851
- const endpointSource = whichSource(env, ENDPOINT_SOURCES);
11852
- const projectSource = whichSource(env, PROJECT_SOURCES);
11853
- const apiKeySource = [
11854
- "APPWRITE_FUNCTION_API_KEY",
11855
- "APPWRITE_API_KEY",
11856
- "APPBASE_API_KEY"
11857
- ].find((name) => Boolean(config.getRaw(name)));
11858
- const lines = [
11859
- `LINKQUE_AGENT_ACCESS_KEY=${maskSecret(config.get("LINKQUE_AGENT_ACCESS_KEY"))}`,
11860
- `APPBASE_ENDPOINT=${maskEndpoint(config.getRaw(endpointSource))}(src=${endpointSource})`,
11861
- `APPBASE_PROJECT_ID=${config.getRaw(projectSource) || "<unset>"}(src=${projectSource})`,
11862
- `APPBASE_API_KEY=${hasRequestKey ? "<set>" : maskSecret(apiKeySource ? config.getRaw(apiKeySource) : void 0)}(src=${hasRequestKey ? "request:x-appwrite-key" : apiKeySource ?? "<none>"})`
11863
- ];
11864
- for (const name of Object.keys(APPBASE_RUNTIME_CONFIG_DEFAULTS)) {
11865
- lines.push(`${name}=${config.get(name)}(src=${config.getSource(name)})`);
11866
- }
11867
- return lines;
11868
- }
11869
-
11870
- // ../linkque-agent-appwrite-integrate/dist/esm/runtime/runStorage.js
11871
- var ENDPOINT_SOURCES = [
11872
- "APPWRITE_FUNCTION_API_ENDPOINT",
11873
- "APPWRITE_API_ENDPOINT",
11874
- "APPWRITE_ENDPOINT",
11875
- "APPBASE_API_ENDPOINT",
11876
- "APPBASE_ENDPOINT"
11877
- ];
11878
- var PROJECT_SOURCES = [
11879
- "APPWRITE_FUNCTION_PROJECT_ID",
11880
- "APPWRITE_PROJECT_ID",
11881
- "APPWRITE_PROJECT",
11882
- "APPBASE_PROJECT_ID",
11883
- "APPBASE_PROJECT"
11884
- ];
11885
- function resolveRunStorage(env = process.env, logCtx) {
11886
- const log = (...a2) => logCtx?.log?.("[runStorage]", ...a2);
11887
- const config = new AppbaseRuntimeConfigProvider(env);
11888
- const databaseId = config.get("RUN_DATABASE_ID");
11889
- const tableId = config.get("RUN_TABLE_ID");
11890
- const chunkSize = parsePositiveInt(config.get("RUN_CHUNK_SIZE"), "RUN_CHUNK_SIZE");
11891
- log("\u843D\u5E93\u914D\u7F6E\u89E3\u6790\u6210\u529F, databaseId=", databaseId, "tableId=", tableId, "chunkSize=", chunkSize);
11892
- return { databaseId, tableId, chunkSize };
11893
- }
11894
- function createAppBaseClient(env = process.env, logCtx, executionApiKey) {
11895
- const log = (...a2) => logCtx?.log?.("[appbase-client]", ...a2);
11896
- const config = new AppbaseRuntimeConfigProvider(env);
11897
- const endpoint = config.getRaw("APPWRITE_FUNCTION_API_ENDPOINT") ?? config.getRaw("APPWRITE_API_ENDPOINT") ?? config.getRaw("APPWRITE_ENDPOINT") ?? config.getRaw("APPBASE_API_ENDPOINT") ?? config.getRaw("APPBASE_ENDPOINT");
11898
- if (!endpoint) {
11899
- throw new Error("APPBASE_ENDPOINT \u672A\u914D\u7F6E:\u5E73\u53F0\u4E0D\u6CE8\u5165 AppBase API \u5165\u53E3\u70B9\u7531 deploy \u5199\u5165 APPBASE_ENDPOINT");
11900
- }
11901
- const projectId = config.getRaw("APPWRITE_FUNCTION_PROJECT_ID") ?? config.getRaw("APPWRITE_PROJECT_ID") ?? config.getRaw("APPWRITE_PROJECT") ?? config.getRaw("APPBASE_PROJECT_ID") ?? config.getRaw("APPBASE_PROJECT");
11902
- const apiKey = executionApiKey?.trim() || config.getRaw("APPWRITE_FUNCTION_API_KEY") || config.getRaw("APPWRITE_API_KEY") || config.getRaw("APPBASE_API_KEY");
11903
- if (!projectId) {
11904
- throw new Error("APPBASE_PROJECT_ID \u672A\u914D\u7F6E:\u5E73\u53F0\u5E94\u6CE8\u5165 APPWRITE_FUNCTION_PROJECT_ID,\u6216\u7531 deploy \u5199\u5165 APPBASE_PROJECT_ID");
11905
- }
11906
- if (!apiKey) {
11907
- throw new Error("Appwrite Server API Key \u7F3A\u5931:\u5E73\u53F0\u5E94\u5728 x-appwrite-key \u6CE8\u5165\u52A8\u6001 key,\u6216\u7531\u672C\u5730/\u6D4B\u8BD5 export APPWRITE_FUNCTION_API_KEY/APPWRITE_API_KEY/APPBASE_API_KEY");
11908
- }
11909
- log("AppBase Client \u6784\u9020, endpoint=", maskEndpoint(endpoint), "(source=", whichSource(env, ENDPOINT_SOURCES), ") projectId=", projectId, "(source=", whichSource(env, PROJECT_SOURCES), ") apiKey=", maskSecret(apiKey), "(source=", executionApiKey?.trim() ? "request:x-appwrite-key" : config.getRaw("APPWRITE_FUNCTION_API_KEY") ? "APPWRITE_FUNCTION_API_KEY" : config.getRaw("APPWRITE_API_KEY") ? "APPWRITE_API_KEY" : "APPBASE_API_KEY", ")");
11910
- const client = new Client().setEndpoint(endpoint).setProject(projectId).setKey(apiKey);
11911
- return { client, databases: new Databases(client) };
11912
- }
11913
- function parsePositiveInt(raw, name) {
11914
- const n = Number(raw);
11915
- if (!Number.isFinite(n) || n < 1 || !Number.isInteger(n)) {
11916
- throw new Error(`${name} \u5FC5\u987B\u662F\u6B63\u6574\u6570,\u5B9E\u9645="${raw}"`);
11917
- }
11918
- return n;
11919
- }
11920
-
11921
11930
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/handlerUtils.js
11922
11931
  function resolveBodyJSON(req) {
11923
11932
  if (req.bodyJSON !== void 0 && typeof req.bodyJSON !== "string") {
@@ -12149,14 +12158,15 @@ async function runClientCapabilityCleanup(store, now = (/* @__PURE__ */ new Date
12149
12158
  }
12150
12159
  async function clientCapability(ctx) {
12151
12160
  let result;
12161
+ const logCtx = withIsoTimestamp({ log: ctx.log, error: ctx.error });
12152
12162
  try {
12153
- const handle = createAppBaseClient(process.env, { log: ctx.log, error: ctx.error }, readAppwriteApiKey(ctx.req.headers));
12163
+ const handle = createAppBaseClient(process.env, logCtx, readAppwriteApiKey(ctx.req.headers));
12154
12164
  const config = new AppbaseRuntimeConfigProvider();
12155
12165
  const store = createClientCapabilityStore(handle.databases, config.get("CLIENT_CAPABILITY_DATABASE_ID"), config.get("CLIENT_CAPABILITY_TABLE_ID"));
12156
12166
  const trigger = readAppwriteTrigger(ctx.req.headers);
12157
12167
  result = await runClientCapability(trigger, ctx.req.method, resolveBodyJSON(ctx.req), readAuthenticatedUserId(ctx.req.headers), store);
12158
12168
  } catch (error) {
12159
- ctx.error?.(error);
12169
+ logCtx?.error?.(error);
12160
12170
  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");
12161
12171
  }
12162
12172
  return ctx.res.json?.(result.body, result.status);
@@ -12195,6 +12205,13 @@ function nonEmpty(value) {
12195
12205
  export {
12196
12206
  APPBASE_RUNTIME_CONFIG_DEFAULTS,
12197
12207
  AppbaseRuntimeConfigProvider,
12208
+ Query,
12209
+ resolveRunStorage,
12210
+ createAppBaseClient,
12211
+ withIsoTimestamp,
12212
+ createA2UIInfoLog,
12213
+ isDebugLogLevel,
12214
+ describeRuntimeEnv,
12198
12215
  LinkqueGatewayAuthError,
12199
12216
  LinkqueGatewayAuthUnconfiguredError,
12200
12217
  resolveLinkqueGatewayAuth,
@@ -12209,12 +12226,6 @@ export {
12209
12226
  readTemporaryFrontendAppId,
12210
12227
  readAuthenticatedUserId,
12211
12228
  readAppwriteApiKey,
12212
- Query,
12213
- createA2UIInfoLog,
12214
- isDebugLogLevel,
12215
- describeRuntimeEnv,
12216
- resolveRunStorage,
12217
- createAppBaseClient,
12218
12229
  createClientCapabilityStore,
12219
12230
  parseStoredClientCapabilityResult,
12220
12231
  runClientCapability,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  EModelProvider
3
- } from "./chunk-ZNU4GVF3.js";
3
+ } from "./chunk-OHRCYI66.js";
4
4
 
5
5
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js
6
6
  var baked;