linkque-cli-v2 1.6.7 → 1.6.9

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 (17) hide show
  1. package/linkquejs.js +102 -32
  2. package/package.json +1 -1
  3. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-C2TN5LPS.js → chunk-BJXGRRWL.js} +1 -1
  4. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-SICWMO5Y.js → chunk-DNTEEBEH.js} +0 -1
  5. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Z2A5GMVJ.js → chunk-HGKCCOSQ.js} +1 -26
  6. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Y2STWI2J.js → chunk-NJKO34ZC.js} +143 -62
  7. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-bsd-NYGVHXGN.js → getMachineId-bsd-JGCLGHFY.js} +1 -1
  8. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-darwin-OPTJOAYC.js → getMachineId-darwin-COHLFNXH.js} +1 -1
  9. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-linux-5SQRYTUJ.js → getMachineId-linux-XV3Z5FQG.js} +1 -1
  10. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-unsupported-OJE7WPEH.js → getMachineId-unsupported-FCRKLIZL.js} +1 -1
  11. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{getMachineId-win-SLTTCNXU.js → getMachineId-win-A4WRNVV6.js} +1 -1
  12. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-C43A6QIS.js → mistral-conversations-OEOTQWE5.js} +1 -1
  13. package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-RUUFBBFE.js → otel-WGS5CC2J.js} +1 -1
  14. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +28 -58
  15. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +3 -3
  16. package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +3 -3
  17. package/worker.js +122 -76
@@ -42,23 +42,21 @@ import {
42
42
  readAuthenticatedUserId,
43
43
  readEnvSelector,
44
44
  readMcpPhoneAuthorization,
45
- readOtelTraceId,
46
45
  readTemporaryFrontendAppId,
47
46
  readTraceId,
48
47
  resolveBodyJSON,
49
48
  resolveGatewayAuthContext,
50
- resolveLinkqueGatewayAuth,
51
49
  resolveLinkqueGatewayRequestAuth,
52
50
  resolveRunStorage,
53
51
  toAgentRunMessages,
54
52
  withIsoTimestamp
55
- } from "../../chunk-Z2A5GMVJ.js";
53
+ } from "../../chunk-HGKCCOSQ.js";
56
54
  import "../../chunk-IWOFD643.js";
57
55
  import "../../chunk-PXCGFBV5.js";
58
56
  import "../../chunk-ETG6PNHQ.js";
59
57
  import {
60
58
  getBakedProtocol
61
- } from "../../chunk-C2TN5LPS.js";
59
+ } from "../../chunk-BJXGRRWL.js";
62
60
  import {
63
61
  ACTIVATE_SKILL_TOOL_NAME,
64
62
  CANCEL_CONVERSATION_RUN_OPERATION,
@@ -135,6 +133,7 @@ import {
135
133
  WebSkillLoader,
136
134
  abortableDelay,
137
135
  aggregateMcpServers,
136
+ authorizeAgentRun,
138
137
  buildHookCommonParams,
139
138
  buildSkillCatalog,
140
139
  cloneJsonObject,
@@ -165,6 +164,7 @@ import {
165
164
  normalizeFollowUpQuestionStrings,
166
165
  normalizeHookResources,
167
166
  normalizeMcpInputSchema,
167
+ normalizeScenarioRunErrorCode,
168
168
  observeEvent,
169
169
  observeIo,
170
170
  observePromise,
@@ -196,11 +196,11 @@ import {
196
196
  warnLogFailure,
197
197
  wrapToolWithHooks,
198
198
  writeJsonPointer
199
- } from "../../chunk-Y2STWI2J.js";
199
+ } from "../../chunk-NJKO34ZC.js";
200
200
  import "../../chunk-EAODRPW4.js";
201
201
  import "../../chunk-XUFLSZM4.js";
202
202
  import "../../chunk-GAYNLDWK.js";
203
- import "../../chunk-SICWMO5Y.js";
203
+ import "../../chunk-DNTEEBEH.js";
204
204
  import {
205
205
  __commonJS,
206
206
  __export,
@@ -8449,7 +8449,7 @@ var googleGenerativeAIApi = () => lazyApi(() => import("../../google-generative-
8449
8449
  var googleVertexApi = () => lazyApi(() => import("../../google-vertex-TREYA472.js"));
8450
8450
 
8451
8451
  // ../../node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.lazy.js
8452
- var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-C43A6QIS.js"));
8452
+ var mistralConversationsApi = () => lazyApi(() => import("../../mistral-conversations-OEOTQWE5.js"));
8453
8453
 
8454
8454
  // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.lazy.js
8455
8455
  var openAICodexResponsesApi = () => lazyApi(() => import("../../openai-codex-responses-GEFKSNVN.js"));
@@ -41315,24 +41315,6 @@ var EMPTY_TELEMETRY_RUN_CONTEXT = {
41315
41315
  userKey: ""
41316
41316
  };
41317
41317
 
41318
- // ../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js
41319
- async function authorizeAgentRun(runId, identity, port) {
41320
- if (typeof runId !== "string" || !/^[\x21-\x7e]{1,64}$/u.test(runId) || typeof identity?.userId !== "string" || !/^[\x21-\x7e]{1,128}$/u.test(identity.userId) || typeof identity.agentId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(identity.agentId)) {
41321
- throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
41322
- }
41323
- const result = await port.authorizeRun({
41324
- runId,
41325
- agentId: identity.agentId,
41326
- appbaseUserId: identity.userId
41327
- });
41328
- if (result?.quotaMode === "NORMAL")
41329
- return { quotaMode: "NORMAL" };
41330
- if (result?.quotaMode !== "LIMITED" && result?.quotaMode !== "AUTH_ONLY" || typeof result.modelFetch !== "function") {
41331
- throw new Error("SCENARIO_RUN_UNAVAILABLE");
41332
- }
41333
- return result;
41334
- }
41335
-
41336
41318
  // ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
41337
41319
  var validatePlugins = (plugins) => {
41338
41320
  const names = /* @__PURE__ */ new Set();
@@ -42664,11 +42646,7 @@ var AgentRuntime = class _AgentRuntime {
42664
42646
  auth = { ...auth, modelFetch: grant.modelFetch };
42665
42647
  } catch (error) {
42666
42648
  const reason = error instanceof Error ? error.message : "";
42667
- const code = [
42668
- "SCENARIO_TURN_LIMIT",
42669
- "SCENARIO_RUNTIME_AUTH_INVALID",
42670
- "SCENARIO_RUNTIME_REPLAY"
42671
- ].includes(reason) ? reason : "SCENARIO_RUN_UNAVAILABLE";
42649
+ const code = normalizeScenarioRunErrorCode(reason);
42672
42650
  yield {
42673
42651
  type: "error",
42674
42652
  error: {
@@ -42719,12 +42697,9 @@ var AgentRuntime = class _AgentRuntime {
42719
42697
  const body = {
42720
42698
  section: ETelemetryContentSection.QUERY_INPUT,
42721
42699
  inputType: "card",
42722
- displayText,
42700
+ ...displayText ? { displayText } : {},
42723
42701
  availability: card ? "available" : "not_recorded"
42724
42702
  };
42725
- if (displayText) {
42726
- body.displayText = displayText;
42727
- }
42728
42703
  observation.record(ETelemetryEventName.CONTENT_RECORDED, { [ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED]: false }, body);
42729
42704
  }
42730
42705
  }
@@ -44319,9 +44294,9 @@ function describeHookExecutorAssembly(ports, mcpAuthHeader, hasLinkquegwEventPlu
44319
44294
  return "\u7AEF\u53E3\u5217\u8868\u4E0E\u63D2\u4EF6\u5217\u8868\u6309 name \u5408\u5E76";
44320
44295
  } else if ((ports.gatewayAuthMode === "user-token" || ports.gatewayAuthMode === "scenario-token") && mcpAuthHeader) {
44321
44296
  if (hasLinkquegwEventPlugin) {
44322
- return "\u4F7F\u7528\u6CE8\u5165\u7684 LinkquegwEventPlugin";
44297
+ return `\u4F7F\u7528\u6CE8\u5165\u7684 LinkquegwEventPlugin(auth-mode=${ports.gatewayAuthMode})`;
44323
44298
  } else {
44324
- return "LinkquegwEventPlugin(user-token,\u9ED8\u8BA4\u6CE8\u5165)";
44299
+ return `LinkquegwEventPlugin(auth-mode=${ports.gatewayAuthMode},\u9ED8\u8BA4\u6CE8\u5165)`;
44325
44300
  }
44326
44301
  } else if (ports.gatewayAuthMode === "aak") {
44327
44302
  return "Noop(AAK \u6A21\u5F0F\u4E0D\u89E6\u53D1 user-token-only event)";
@@ -45593,6 +45568,7 @@ function isUncertainWriteError(error) {
45593
45568
  import { createHash as createHash3 } from "node:crypto";
45594
45569
  var DEFAULT_LEASE_TTL_MS = 20 * 60 * 1e3;
45595
45570
  var TRANSACTION_TTL_SECONDS = 60;
45571
+ var LEASE_RELEASE_MAX_ATTEMPTS = 3;
45596
45572
  function createSessionLease(persistence, options = {}) {
45597
45573
  const ttlMs = options.ttlMs ?? DEFAULT_LEASE_TTL_MS;
45598
45574
  const now = options.now ?? Date.now;
@@ -45610,10 +45586,14 @@ function createSessionLease(persistence, options = {}) {
45610
45586
  },
45611
45587
  release: async (threadId, ownerId) => {
45612
45588
  const leaseId = createSessionLeaseId(threadId);
45613
- const deleted = await persistence.deleteIfOwner(leaseId, ownerId);
45614
- if (!deleted && (await persistence.read(leaseId))?.ownerId === ownerId) {
45615
- throw new Error("\u4F1A\u8BDD\u79DF\u7EA6\u91CA\u653E\u672A\u63D0\u4EA4\uFF0C\u5F53\u524D\u8BF7\u6C42\u4ECD\u6301\u6709\u79DF\u7EA6");
45589
+ for (let attempt = 0; attempt < LEASE_RELEASE_MAX_ATTEMPTS; attempt += 1) {
45590
+ if (await persistence.deleteIfOwner(leaseId, ownerId))
45591
+ return;
45592
+ const current = await persistence.read(leaseId);
45593
+ if (!current || current.ownerId !== ownerId)
45594
+ return;
45616
45595
  }
45596
+ throw new Error("\u4F1A\u8BDD\u79DF\u7EA6\u91CA\u653E\u672A\u63D0\u4EA4\uFF0C\u5F53\u524D\u8BF7\u6C42\u4ECD\u6301\u6709\u79DF\u7EA6");
45617
45597
  }
45618
45598
  };
45619
45599
  }
@@ -46265,7 +46245,6 @@ function createAppbaseTelemetry(options) {
46265
46245
  environment: options.environment,
46266
46246
  logsEndpoint: options.logsEndpoint,
46267
46247
  tracesEndpoint: options.tracesEndpoint,
46268
- ...options.initialRootTraceId ? { initialRootTraceId: options.initialRootTraceId } : {},
46269
46248
  diagnostic: ({ code }) => diagnostic(code)
46270
46249
  });
46271
46250
  } catch {
@@ -46416,7 +46395,7 @@ function createSecurityAnswerPlugin(historyStore, log) {
46416
46395
  }
46417
46396
 
46418
46397
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chatConfig.js
46419
- function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth, temporaryFrontendAppId, initialRootTraceId) {
46398
+ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth, temporaryFrontendAppId) {
46420
46399
  const log = (...a) => logCtx?.log?.("[chat]", ...a);
46421
46400
  const logError = (...a) => logCtx?.error?.("[chat]", ...a);
46422
46401
  const protocol = deps?.protocol ?? getBakedProtocol();
@@ -46491,7 +46470,8 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
46491
46470
  baseUrl: linkqueBaseUrl,
46492
46471
  token: resolved.modelCredential,
46493
46472
  authorizationHeader: resolved.authorizationHeader,
46494
- accessKey
46473
+ accessKey,
46474
+ debugLog: (...args) => log(...args)
46495
46475
  });
46496
46476
  } catch {
46497
46477
  return jsonError(503, "SCENARIO_RUN_UNAVAILABLE", "\u573A\u666F\u53EF\u4FE1\u8BA4\u8BC1\u914D\u7F6E\u6682\u4E0D\u53EF\u7528");
@@ -46514,7 +46494,6 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
46514
46494
  environment: new AppbaseRuntimeConfigProvider(env).get("LINKQUE_TELEMETRY_ENVIRONMENT") ?? (envSelector === "PRE" ? "pre" : "prod"),
46515
46495
  logsEndpoint: telemetryLogsEndpoint,
46516
46496
  tracesEndpoint: telemetryTracesEndpoint,
46517
- ...initialRootTraceId ? { initialRootTraceId } : {},
46518
46497
  logCtx
46519
46498
  });
46520
46499
  const runtime = deps?.runtime ?? createAppBaseRuntime(protocol, env, {
@@ -47226,7 +47205,7 @@ function failure2(status, code, message, retryable = false) {
47226
47205
  }
47227
47206
 
47228
47207
  // ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js
47229
- async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, otelTraceId) {
47208
+ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId) {
47230
47209
  const log = (...args) => logCtx?.log?.("[chat]", ...args);
47231
47210
  const logError = (...args) => logCtx?.error?.("[chat]", ...args);
47232
47211
  const guarded = guardChatRequest(method, bodyJSON, logCtx);
@@ -47234,7 +47213,7 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
47234
47213
  return guarded;
47235
47214
  let request = guarded;
47236
47215
  const isPresentationRun = request.executionScope === "presentation";
47237
- const cfg = resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth, temporaryFrontendAppId, otelTraceId);
47216
+ const cfg = resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth, temporaryFrontendAppId);
47238
47217
  if ("status" in cfg)
47239
47218
  return cfg;
47240
47219
  const leaseOwnerId = randomUUID8();
@@ -47543,7 +47522,7 @@ function waitForCancellationPoll(delayMs, signal) {
47543
47522
  }
47544
47523
  });
47545
47524
  }
47546
- async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, mcpPhoneAuthorization, otelTraceId) {
47525
+ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, mcpPhoneAuthorization) {
47547
47526
  const operation = readOperation(bodyJSON);
47548
47527
  const startedAt = Date.now();
47549
47528
  const logGateway = (event, fields = {}, failed = false) => {
@@ -47624,7 +47603,7 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
47624
47603
  if (operation) {
47625
47604
  return observe(() => jsonError(400, "operation_unsupported", `\u4E0D\u652F\u6301\u7684 operation: ${operation}`));
47626
47605
  }
47627
- return observe(() => runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId, otelTraceId));
47606
+ return observe(() => runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth, temporaryFrontendAppId));
47628
47607
  }
47629
47608
  async function chat(ctx) {
47630
47609
  let result;
@@ -47633,18 +47612,9 @@ async function chat(ctx) {
47633
47612
  const bodyJSON = resolveBodyJSON(ctx.req);
47634
47613
  const historyOwnerId = readAuthenticatedUserId(ctx.req.headers);
47635
47614
  const appwriteApiKey = readAppwriteApiKey(ctx.req.headers);
47636
- const otelTraceIdResult = readOtelTraceId(ctx.req.headers);
47637
- if (otelTraceIdResult.kind === "invalid") {
47638
- result = jsonError(400, "invalid_otel_trace_id", "x-linkque-otel-trace-id \u683C\u5F0F\u975E\u6CD5");
47639
- } else if (readOperation(bodyJSON) === REPLACE_ANSWER_OPERATION) {
47615
+ if (readOperation(bodyJSON) === REPLACE_ANSWER_OPERATION) {
47640
47616
  const control = await runReplaceAnswer(ctx.req.method, bodyJSON, process.env, void 0, logCtx, appwriteApiKey);
47641
- result = control;
47642
- } else {
47643
- const envSelector2 = readEnvSelector(ctx.req.headers);
47644
- const traceId2 = readTraceId(ctx.req.headers);
47645
- const temporaryFrontendAppId2 = readTemporaryFrontendAppId(ctx.req.headers);
47646
- const gatewayAuth2 = historyOwnerId ? resolveLinkqueGatewayAuth(ctx.req.headers, process.env, logCtx) : void 0;
47647
- result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, logCtx, historyOwnerId, appwriteApiKey, envSelector2, traceId2, gatewayAuth2, temporaryFrontendAppId2, readMcpPhoneAuthorization(ctx.req.headers), otelTraceIdResult.kind === "valid" ? otelTraceIdResult.traceId : void 0) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
47617
+ return ctx.res.json?.(control.body, control.status);
47648
47618
  }
47649
47619
  const envSelector = readEnvSelector(ctx.req.headers);
47650
47620
  const traceId = readTraceId(ctx.req.headers);
@@ -3,15 +3,15 @@ import {
3
3
  runClientCapability,
4
4
  runClientCapabilityCleanup,
5
5
  runClientCapabilityResult
6
- } from "../../chunk-Z2A5GMVJ.js";
6
+ } from "../../chunk-HGKCCOSQ.js";
7
7
  import "../../chunk-IWOFD643.js";
8
8
  import "../../chunk-PXCGFBV5.js";
9
9
  import "../../chunk-ETG6PNHQ.js";
10
- import "../../chunk-Y2STWI2J.js";
10
+ import "../../chunk-NJKO34ZC.js";
11
11
  import "../../chunk-EAODRPW4.js";
12
12
  import "../../chunk-XUFLSZM4.js";
13
13
  import "../../chunk-GAYNLDWK.js";
14
- import "../../chunk-SICWMO5Y.js";
14
+ import "../../chunk-DNTEEBEH.js";
15
15
  import "../../chunk-2ESYSVXG.js";
16
16
  export {
17
17
  clientCapability as default,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  getBakedProtocol,
3
3
  setBakedProtocol
4
- } from "../chunk-C2TN5LPS.js";
5
- import "../chunk-Y2STWI2J.js";
4
+ } from "../chunk-BJXGRRWL.js";
5
+ import "../chunk-NJKO34ZC.js";
6
6
  import "../chunk-EAODRPW4.js";
7
7
  import "../chunk-XUFLSZM4.js";
8
8
  import "../chunk-GAYNLDWK.js";
9
- import "../chunk-SICWMO5Y.js";
9
+ import "../chunk-DNTEEBEH.js";
10
10
  import "../chunk-2ESYSVXG.js";
11
11
  export {
12
12
  getBakedProtocol,
package/worker.js CHANGED
@@ -3851,6 +3851,37 @@ var require_utils = __commonJS({
3851
3851
  }
3852
3852
  return output.join("");
3853
3853
  }
3854
+ function removeDotSegmentsRelative(path9) {
3855
+ if (path9 === "" || path9[0] === "/") {
3856
+ return removeDotSegments(path9);
3857
+ }
3858
+ const segments = path9.split("/");
3859
+ const last = segments.length - 1;
3860
+ const output = [];
3861
+ let trailingDirectory = false;
3862
+ for (let i2 = 0; i2 <= last; i2++) {
3863
+ const segment = segments[i2];
3864
+ if (segment === "." || segment === "..") {
3865
+ if (segment === "..") {
3866
+ if (output.length !== 0 && output[output.length - 1] !== "..") {
3867
+ output.pop();
3868
+ } else {
3869
+ output.push("..");
3870
+ }
3871
+ }
3872
+ trailingDirectory = i2 === last;
3873
+ } else {
3874
+ output.push(segment);
3875
+ }
3876
+ }
3877
+ if (trailingDirectory && output[output.length - 1] !== "..") {
3878
+ output.push("");
3879
+ }
3880
+ if (output.length === 0 || output[0] === "" || output[0].includes(":")) {
3881
+ output.unshift(".");
3882
+ }
3883
+ return output.join("/");
3884
+ }
3854
3885
  var HOST_DELIMS = { "@": "%40", "/": "%2F", "?": "%3F", "#": "%23", ":": "%3A" };
3855
3886
  var HOST_DELIM_RE = /[@/?#:]/g;
3856
3887
  var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
@@ -4111,6 +4142,7 @@ var require_utils = __commonJS({
4111
4142
  encodeFragment,
4112
4143
  escapePreservingEscapes,
4113
4144
  removeDotSegments,
4145
+ removeDotSegmentsRelative,
4114
4146
  isIPv4,
4115
4147
  isUUID,
4116
4148
  normalizeIPv6,
@@ -4334,16 +4366,18 @@ var require_schemes = __commonJS({
4334
4366
  var require_fast_uri = __commonJS({
4335
4367
  "../../node_modules/fast-uri/index.js"(exports2, module2) {
4336
4368
  "use strict";
4337
- var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
4369
+ var { normalizeIPv6, removeDotSegments, removeDotSegmentsRelative, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
4338
4370
  var { SCHEMES, getSchemeHandler } = require_schemes();
4339
4371
  var VALID_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/u;
4340
4372
  var MALFORMED_SCHEME_ERROR = "URI scheme is malformed.";
4341
- function decodeValidScheme(scheme) {
4342
- const decodedScheme = unescape(String(scheme));
4343
- if (!VALID_SCHEME.test(decodedScheme)) {
4373
+ var MALFORMED_HOST_ERROR = "URI host is malformed.";
4374
+ var FORBIDDEN_DOMAIN_HOST_CHARACTER = /[\0-\x20"#/:<>?@[\\\]^`{|}\x7F]/u;
4375
+ function validateScheme(scheme) {
4376
+ const stringScheme = String(scheme);
4377
+ if (!VALID_SCHEME.test(stringScheme)) {
4344
4378
  throw new TypeError(MALFORMED_SCHEME_ERROR);
4345
4379
  }
4346
- return decodedScheme;
4380
+ return stringScheme;
4347
4381
  }
4348
4382
  function normalize(uri, options) {
4349
4383
  if (typeof uri === "string") {
@@ -4380,6 +4414,9 @@ var require_fast_uri = __commonJS({
4380
4414
  const resolvedSchemeHandler = getSchemeHandler(options && options.scheme || resolved.scheme);
4381
4415
  const resolvedHost = resolved.host;
4382
4416
  const resolvedHostIsIP = resolvedHost !== void 0 && resolvedHost !== "" && (isIPv4(resolvedHost) || normalizeIPv6(resolvedHost).isIPV6);
4417
+ if (hasForbiddenDomainHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP)) {
4418
+ throw new Error(MALFORMED_HOST_ERROR);
4419
+ }
4383
4420
  canonicalizeHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP);
4384
4421
  const encodedASCIIHost = resolvedHost && resolvedHost.indexOf("%") !== -1 && !/\P{ASCII}/u.test(resolvedHost);
4385
4422
  if (resolved.error && !encodedASCIIHost) {
@@ -4421,14 +4458,15 @@ var require_fast_uri = __commonJS({
4421
4458
  if (relative.path[0] === "/") {
4422
4459
  target.path = removeDotSegments(relative.path);
4423
4460
  } else {
4424
- if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
4461
+ const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
4462
+ if (baseHasAuthority && !base.path) {
4425
4463
  target.path = "/" + relative.path;
4426
4464
  } else if (!base.path) {
4427
4465
  target.path = relative.path;
4428
4466
  } else {
4429
4467
  target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
4430
4468
  }
4431
- target.path = removeDotSegments(target.path);
4469
+ target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
4432
4470
  }
4433
4471
  target.query = relative.query;
4434
4472
  }
@@ -4466,12 +4504,13 @@ var require_fast_uri = __commonJS({
4466
4504
  const options = Object.assign({}, opts);
4467
4505
  const uriTokens = [];
4468
4506
  if (component.scheme) {
4469
- component.scheme = decodeValidScheme(component.scheme);
4507
+ component.scheme = validateScheme(component.scheme);
4470
4508
  }
4471
4509
  const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
4472
4510
  if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
4473
4511
  const hasAuthority = component.userinfo !== void 0 || component.host !== void 0 || component.port !== void 0;
4474
- const pathNoScheme = !options.skipEscape && component.scheme === void 0 && !hasAuthority;
4512
+ const schemelessReference = (component.scheme === void 0 || options.reference === "suffix") && !hasAuthority;
4513
+ const pathNoScheme = !options.skipEscape && schemelessReference;
4475
4514
  if (component.path !== void 0) {
4476
4515
  if (!options.skipEscape) {
4477
4516
  component.path = serializePathEncoding(component.path, pathNoScheme);
@@ -4480,7 +4519,7 @@ var require_fast_uri = __commonJS({
4480
4519
  }
4481
4520
  }
4482
4521
  if (options.reference !== "suffix" && component.scheme) {
4483
- component.scheme = decodeValidScheme(component.scheme);
4522
+ component.scheme = validateScheme(component.scheme);
4484
4523
  uriTokens.push(component.scheme, ":");
4485
4524
  }
4486
4525
  const authority = recomposeAuthority(component);
@@ -4496,9 +4535,9 @@ var require_fast_uri = __commonJS({
4496
4535
  if (component.path !== void 0) {
4497
4536
  let s2 = component.path;
4498
4537
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
4499
- s2 = removeDotSegments(s2);
4538
+ s2 = schemelessReference && s2[0] !== "/" ? removeDotSegmentsRelative(s2) : removeDotSegments(s2);
4500
4539
  }
4501
- if (pathNoScheme) {
4540
+ if (schemelessReference) {
4502
4541
  s2 = serializePathEncoding(s2, true);
4503
4542
  }
4504
4543
  if (authority === void 0 && s2[0] === "/" && s2[1] === "/") {
@@ -4545,16 +4584,34 @@ var require_fast_uri = __commonJS({
4545
4584
  return hasMalformedPercentEncoding(matches[3]) || host !== void 0 && !isIPLiteral(host) && hasMalformedPercentEncoding(host) || hasMalformedPercentEncoding(matches[6]) || hasMalformedPercentEncoding(matches[7]) || hasMalformedPercentEncoding(matches[8]);
4546
4585
  }
4547
4586
  function canonicalizeHost(parsed, options, schemeHandler, isIP2) {
4587
+ if (hasForbiddenDomainHost(parsed, options, schemeHandler, isIP2)) {
4588
+ parsed.error = parsed.error || MALFORMED_HOST_ERROR;
4589
+ return true;
4590
+ }
4548
4591
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport) && parsed.host && !isIPLiteral(parsed.host) && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP2 === false && nonSimpleDomain(parsed.host)) {
4592
+ let url2;
4549
4593
  try {
4550
- parsed.host = new URL("http://" + parsed.host).hostname;
4594
+ url2 = new URL("http://" + parsed.host);
4551
4595
  } catch (e2) {
4552
4596
  parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e2;
4553
4597
  return true;
4554
4598
  }
4599
+ if (!isHostOnlyURL(url2)) {
4600
+ parsed.error = parsed.error || MALFORMED_HOST_ERROR;
4601
+ return true;
4602
+ }
4603
+ parsed.host = url2.hostname;
4555
4604
  }
4556
4605
  return false;
4557
4606
  }
4607
+ function hasForbiddenDomainHost(parsed, options, schemeHandler, isIP2) {
4608
+ return Boolean(
4609
+ parsed.host && isIP2 === false && !isIPLiteral(parsed.host) && (options.domainHost || schemeHandler && schemeHandler.domainHost) && FORBIDDEN_DOMAIN_HOST_CHARACTER.test(parsed.host)
4610
+ );
4611
+ }
4612
+ function isHostOnlyURL(url2) {
4613
+ return url2.username === "" && url2.password === "" && url2.port === "" && url2.pathname === "/" && url2.search === "" && url2.hash === "" && url2.hostname !== "";
4614
+ }
4558
4615
  function parseWithStatus(uri, opts) {
4559
4616
  const options = Object.assign({}, opts);
4560
4617
  const parsed = {
@@ -4609,9 +4666,8 @@ var require_fast_uri = __commonJS({
4609
4666
  parsed.query = matches[7];
4610
4667
  parsed.fragment = matches[8];
4611
4668
  if (parsed.scheme !== void 0) {
4612
- const decodedScheme = unescape(parsed.scheme);
4613
- if (VALID_SCHEME.test(decodedScheme)) {
4614
- parsed.scheme = decodedScheme.toLowerCase();
4669
+ if (VALID_SCHEME.test(parsed.scheme)) {
4670
+ parsed.scheme = parsed.scheme.toLowerCase();
4615
4671
  } else {
4616
4672
  parsed.error = parsed.error || MALFORMED_SCHEME_ERROR;
4617
4673
  malformedScheme = true;
@@ -4639,7 +4695,7 @@ var require_fast_uri = __commonJS({
4639
4695
  malformedIPLiteral = hasIPLiteralBracket && (!bracketedIPLiteral || ipv6result.error === true);
4640
4696
  parsed.host = isIP2 ? ipv6result.host : ipv6result.host.toLowerCase();
4641
4697
  if (malformedIPLiteral) {
4642
- parsed.error = parsed.error || "URI host is malformed.";
4698
+ parsed.error = parsed.error || MALFORMED_HOST_ERROR;
4643
4699
  malformedAuthorityOrPort = true;
4644
4700
  }
4645
4701
  } else {
@@ -4667,7 +4723,7 @@ var require_fast_uri = __commonJS({
4667
4723
  if (!isIP2) {
4668
4724
  host = normalizePercentEncoding(host.toLowerCase());
4669
4725
  }
4670
- parsed.host = reescapeHostDelimiters(host, isIP2);
4726
+ parsed.host = isIP2 || options.scheme !== "null" ? reescapeHostDelimiters(host, isIP2) : host;
4671
4727
  }
4672
4728
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4673
4729
  if (parsed.path) {
@@ -9983,11 +10039,11 @@ function validateClientAction(body, path9, issues) {
9983
10039
  issues.push(issue2(`${path9}.context`, "INVALID_CLIENT_ACTION_CONTEXT", "ui.surface.open requires context.surfaceId"));
9984
10040
  return;
9985
10041
  }
9986
- if (body.name === "ui.page.open") {
10042
+ if (body.name === "ui.page.open" || body.name === "ui.miniprogram.embed") {
9987
10043
  if (!isPlainRecord(body.context) || Object.keys(body.context).length !== 1 || typeof body.context.url !== "string" && !isStrictBinding(body.context.url))
9988
- issues.push(issue2(`${path9}.context`, "INVALID_CLIENT_ACTION_CONTEXT", "ui.page.open requires one literal or bound URL"));
10044
+ issues.push(issue2(`${path9}.context`, "INVALID_CLIENT_ACTION_CONTEXT", `${body.name} requires one literal or bound URL`));
9989
10045
  else if (typeof body.context.url === "string" && !isSafePageUrl(body.context.url))
9990
- issues.push(issue2(`${path9}.context.url`, "INVALID_PAGE_URL", "ui.page.open URL must use https or the approved Alipay scheme"));
10046
+ issues.push(issue2(`${path9}.context.url`, "INVALID_PAGE_URL", `${body.name} URL must use https or the approved Alipay scheme`));
9991
10047
  return;
9992
10048
  }
9993
10049
  issues.push(issue2(`${path9}.name`, "UNSUPPORTED_CLIENT_ACTION", `unsupported client action ${String(body.name)}`));
@@ -16077,6 +16133,43 @@ var init_noopWebSearchPort = __esm({
16077
16133
  }
16078
16134
  });
16079
16135
 
16136
+ // ../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js
16137
+ function normalizeScenarioRunErrorCode(value) {
16138
+ return typeof value === "string" && SCENARIO_RUN_ERROR_CODES.includes(value) ? value : "SCENARIO_RUN_UNAVAILABLE";
16139
+ }
16140
+ async function authorizeAgentRun(runId, identity, port) {
16141
+ if (typeof runId !== "string" || !/^[\x21-\x7e]{1,64}$/u.test(runId) || typeof identity?.userId !== "string" || !/^[\x21-\x7e]{1,128}$/u.test(identity.userId) || typeof identity.agentId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(identity.agentId)) {
16142
+ throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
16143
+ }
16144
+ const result = await port.authorizeRun({
16145
+ runId,
16146
+ agentId: identity.agentId,
16147
+ appbaseUserId: identity.userId
16148
+ });
16149
+ if (result?.quotaMode === "NORMAL")
16150
+ return { quotaMode: "NORMAL" };
16151
+ if (result?.quotaMode !== "LIMITED" && result?.quotaMode !== "AUTH_ONLY" || typeof result.modelFetch !== "function") {
16152
+ throw new Error("SCENARIO_RUN_UNAVAILABLE");
16153
+ }
16154
+ return result;
16155
+ }
16156
+ var SCENARIO_RUN_ERROR_CODES;
16157
+ var init_scenarioRunAuthorization = __esm({
16158
+ "../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js"() {
16159
+ "use strict";
16160
+ SCENARIO_RUN_ERROR_CODES = [
16161
+ "SCENARIO_TURN_LIMIT",
16162
+ "SCENARIO_TURN_ID_CONFLICT",
16163
+ "SCENARIO_CIPHER_TIMEOUT",
16164
+ "SCENARIO_CIPHER_UNAVAILABLE",
16165
+ "SCENARIO_TURN_CONFIG_UNAVAILABLE",
16166
+ "SCENARIO_RUNTIME_AUTH_INVALID",
16167
+ "SCENARIO_RUNTIME_REPLAY",
16168
+ "SCENARIO_RUN_UNAVAILABLE"
16169
+ ];
16170
+ }
16171
+ });
16172
+
16080
16173
  // ../../node_modules/zod/v3/helpers/util.js
16081
16174
  var util, objectUtil, ZodParsedType, getParsedType;
16082
16175
  var init_util = __esm({
@@ -41998,7 +42091,7 @@ var require_RandomIdGenerator = __commonJS({
41998
42091
  exports2.RandomIdGenerator = void 0;
41999
42092
  var SPAN_ID_BYTES = 8;
42000
42093
  var TRACE_ID_BYTES = 16;
42001
- var RandomIdGenerator2 = class {
42094
+ var RandomIdGenerator = class {
42002
42095
  /**
42003
42096
  * Returns a random 16-byte trace ID formatted/encoded as a 32 lowercase hex
42004
42097
  * characters corresponding to 128 bits.
@@ -42010,7 +42103,7 @@ var require_RandomIdGenerator = __commonJS({
42010
42103
  */
42011
42104
  generateSpanId = getIdGenerator(SPAN_ID_BYTES);
42012
42105
  };
42013
- exports2.RandomIdGenerator = RandomIdGenerator2;
42106
+ exports2.RandomIdGenerator = RandomIdGenerator;
42014
42107
  var SHARED_BUFFER = Buffer.allocUnsafe(TRACE_ID_BYTES);
42015
42108
  function getIdGenerator(bytes2) {
42016
42109
  return function generateId() {
@@ -208052,29 +208145,6 @@ var init_types12 = __esm({
208052
208145
  }
208053
208146
  });
208054
208147
 
208055
- // ../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js
208056
- async function authorizeAgentRun(runId, identity, port) {
208057
- if (typeof runId !== "string" || !/^[\x21-\x7e]{1,64}$/u.test(runId) || typeof identity?.userId !== "string" || !/^[\x21-\x7e]{1,128}$/u.test(identity.userId) || typeof identity.agentId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(identity.agentId)) {
208058
- throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
208059
- }
208060
- const result = await port.authorizeRun({
208061
- runId,
208062
- agentId: identity.agentId,
208063
- appbaseUserId: identity.userId
208064
- });
208065
- if (result?.quotaMode === "NORMAL")
208066
- return { quotaMode: "NORMAL" };
208067
- if (result?.quotaMode !== "LIMITED" && result?.quotaMode !== "AUTH_ONLY" || typeof result.modelFetch !== "function") {
208068
- throw new Error("SCENARIO_RUN_UNAVAILABLE");
208069
- }
208070
- return result;
208071
- }
208072
- var init_scenarioRunAuthorization = __esm({
208073
- "../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js"() {
208074
- "use strict";
208075
- }
208076
- });
208077
-
208078
208148
  // ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
208079
208149
  function assertAgentConfigRoot(value, pluginName) {
208080
208150
  if (typeof value !== "object" || value === null || !("agent" in value)) {
@@ -209531,11 +209601,7 @@ var init_agentRuntime = __esm({
209531
209601
  auth2 = { ...auth2, modelFetch: grant.modelFetch };
209532
209602
  } catch (error40) {
209533
209603
  const reason = error40 instanceof Error ? error40.message : "";
209534
- const code = [
209535
- "SCENARIO_TURN_LIMIT",
209536
- "SCENARIO_RUNTIME_AUTH_INVALID",
209537
- "SCENARIO_RUNTIME_REPLAY"
209538
- ].includes(reason) ? reason : "SCENARIO_RUN_UNAVAILABLE";
209604
+ const code = normalizeScenarioRunErrorCode(reason);
209539
209605
  yield {
209540
209606
  type: "error",
209541
209607
  error: {
@@ -209586,12 +209652,9 @@ var init_agentRuntime = __esm({
209586
209652
  const body = {
209587
209653
  section: ETelemetryContentSection.QUERY_INPUT,
209588
209654
  inputType: "card",
209589
- displayText,
209655
+ ...displayText ? { displayText } : {},
209590
209656
  availability: card ? "available" : "not_recorded"
209591
209657
  };
209592
- if (displayText) {
209593
- body.displayText = displayText;
209594
- }
209595
209658
  observation.record(ETelemetryEventName.CONTENT_RECORDED, { [ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED]: false }, body);
209596
209659
  }
209597
209660
  }
@@ -211406,6 +211469,9 @@ init_runtimeObservation();
211406
211469
  init_telemetryEnums2();
211407
211470
  init_observe();
211408
211471
 
211472
+ // ../linkque-agent-runtime/dist/esm/impl/scenario/gatewayRunAuthorization.js
211473
+ init_scenarioRunAuthorization();
211474
+
211409
211475
  // ../../node_modules/zod/v4/mini/parse.js
211410
211476
  init_core2();
211411
211477
 
@@ -219132,24 +219198,6 @@ function sanitizeAttributeValue(value) {
219132
219198
  }
219133
219199
 
219134
219200
  // ../linkque-agent-runtime/dist/esm/impl/telemetry/otelRuntimeTelemetry.js
219135
- var InitialRootTraceIdGenerator = class {
219136
- initialRootTraceId;
219137
- fallback = new import_sdk_trace_base.RandomIdGenerator();
219138
- constructor(initialRootTraceId) {
219139
- this.initialRootTraceId = initialRootTraceId;
219140
- }
219141
- generateTraceId() {
219142
- if (this.initialRootTraceId) {
219143
- const traceId = this.initialRootTraceId;
219144
- this.initialRootTraceId = void 0;
219145
- return traceId;
219146
- }
219147
- return this.fallback.generateTraceId();
219148
- }
219149
- generateSpanId() {
219150
- return this.fallback.generateSpanId();
219151
- }
219152
- };
219153
219201
  var OtelRuntimeTelemetry = class {
219154
219202
  options;
219155
219203
  queue;
@@ -219169,10 +219217,9 @@ var OtelRuntimeTelemetry = class {
219169
219217
  this.options = options;
219170
219218
  this.queue = new IdentityQueue(options);
219171
219219
  const ratio = options.sampleRatio ?? 1;
219172
- const initialRootTraceId = options.initialRootTraceId?.toLowerCase();
219173
219220
  this.maxActive = options.maxActiveOperations ?? 4096;
219174
219221
  this.maxAge = options.operationMaxAgeMs ?? 24 * 60 * 60 * 1e3;
219175
- if (!options.serviceName || !options.serviceVersion || !options.environment || !Number.isFinite(ratio) || ratio < 0 || ratio > 1 || !Number.isSafeInteger(this.maxActive) || this.maxActive < 1 || !Number.isSafeInteger(this.maxAge) || this.maxAge < 1 || initialRootTraceId !== void 0 && !isValidTraceId(initialRootTraceId))
219222
+ if (!options.serviceName || !options.serviceVersion || !options.environment || !Number.isFinite(ratio) || ratio < 0 || ratio > 1 || !Number.isSafeInteger(this.maxActive) || this.maxActive < 1 || !Number.isSafeInteger(this.maxAge) || this.maxAge < 1)
219176
219223
  throw new Error("\u975E\u6CD5\u9065\u6D4B\u5B9E\u4F8B\u914D\u7F6E");
219177
219224
  const resource = (0, import_resources.resourceFromAttributes)({
219178
219225
  [ETelemetryAttribute.SERVICE_NAME]: options.serviceName,
@@ -219183,7 +219230,6 @@ var OtelRuntimeTelemetry = class {
219183
219230
  });
219184
219231
  this.tracerProvider = new import_sdk_trace_base.BasicTracerProvider({
219185
219232
  resource,
219186
- idGenerator: new InitialRootTraceIdGenerator(initialRootTraceId),
219187
219233
  sampler: new import_sdk_trace_base.ParentBasedSampler({
219188
219234
  root: new import_sdk_trace_base.TraceIdRatioBasedSampler(ratio)
219189
219235
  }),