linkque-cli-v2 1.6.2 → 1.6.4
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.
- package/dev/worker.js +16 -3
- package/linkquejs.js +1030 -644
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/anthropic-messages-GSYNBLMR.js +17 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{azure-openai-responses-HVAVRLTK.js → azure-openai-responses-NPKMM3LF.js} +7 -9
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-2HV35GH7.js → chunk-CO4I3RJE.js} +15 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Q2Y6LMNC.js → chunk-J4JCPZDI.js} +5 -7
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-4XAZNSEQ.js → chunk-JMBJJF7P.js} +18 -5
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{anthropic-messages-5DOLTIGP.js → chunk-KDHBKVSL.js} +14 -15
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-SDEXPSW4.js → chunk-UZS5YLV2.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-2CFN5G5A.js → chunk-VBERH5QM.js} +419 -73
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Y3G4J3TB.js → chunk-XOLFZ4XS.js} +316 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{dist-ZPLSQEAM.js → dist-TGBYXSBU.js} +27 -42
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-generative-ai-OLT56CSV.js → google-generative-ai-KD7MXONK.js} +8 -10
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-vertex-4DBBJ7SR.js → google-vertex-TREYA472.js} +9 -11
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-OEBGEDLQ.js → mistral-conversations-OEOTQWE5.js} +7 -9
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-codex-responses-3KOC6KHN.js → openai-codex-responses-GEFKSNVN.js} +10 -12
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-completions-HG6OJRL5.js → openai-completions-TAACO6T5.js} +13 -15
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{openai-responses-F6V2PG3Y.js → openai-responses-4DDTXIGI.js} +12 -14
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +197 -61
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +2 -2
- package/worker.js +387 -106
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-RYONFGPP.js +0 -317
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{pi-messages-DC4DVRAJ.js → pi-messages-7JN3W3BC.js} +4 -4
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-2CFN5G5A.js → chunk-VBERH5QM.js}
RENAMED
|
@@ -5420,8 +5420,8 @@ var require_multipleOf = __commonJS({
|
|
|
5420
5420
|
const { gen, data, schemaCode, it } = cxt;
|
|
5421
5421
|
const prec = it.opts.multipleOfPrecision;
|
|
5422
5422
|
const res = gen.let("res");
|
|
5423
|
-
const
|
|
5424
|
-
cxt.fail$data((0, codegen_1._)`(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${
|
|
5423
|
+
const invalid2 = prec ? (0, codegen_1._)`Math.abs(Math.round(${res}) - ${res}) > 1e-${prec}` : (0, codegen_1._)`${res} !== parseInt(${res})`;
|
|
5424
|
+
cxt.fail$data((0, codegen_1._)`(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${invalid2}))`);
|
|
5425
5425
|
}
|
|
5426
5426
|
};
|
|
5427
5427
|
exports.default = def;
|
|
@@ -22822,10 +22822,19 @@ function truncateToEstimatedTokens(text, budget) {
|
|
|
22822
22822
|
|
|
22823
22823
|
// ../linkque-agent-runtime/dist/esm/core/dataTransformExecutor.js
|
|
22824
22824
|
import { createHash } from "node:crypto";
|
|
22825
|
-
import { dirname, join } from "node:path";
|
|
22826
|
-
import { createRequire } from "node:module";
|
|
22827
|
-
import { pathToFileURL } from "node:url";
|
|
22828
22825
|
import { Worker } from "node:worker_threads";
|
|
22826
|
+
|
|
22827
|
+
// ../linkque-agent-runtime/dist/esm/core/dataTransformWorkerUrl.js
|
|
22828
|
+
import { join } from "node:path";
|
|
22829
|
+
import { pathToFileURL } from "node:url";
|
|
22830
|
+
function defaultDataTransformWorkerUrl() {
|
|
22831
|
+
if (typeof __dirname === "string") {
|
|
22832
|
+
return pathToFileURL(join(__dirname, "dataTransformWorker.js"));
|
|
22833
|
+
}
|
|
22834
|
+
return new URL("dataTransformWorker.js", import.meta.url);
|
|
22835
|
+
}
|
|
22836
|
+
|
|
22837
|
+
// ../linkque-agent-runtime/dist/esm/core/dataTransformExecutor.js
|
|
22829
22838
|
var DATA_TRANSFORM_LIMITS = Object.freeze({
|
|
22830
22839
|
sourceBytes: 32 * 1024,
|
|
22831
22840
|
inputBytes: 2 * 1024 * 1024,
|
|
@@ -22855,7 +22864,7 @@ var DataTransformExecutor = class {
|
|
|
22855
22864
|
slots = [];
|
|
22856
22865
|
nextRequestId = 1;
|
|
22857
22866
|
disposed = false;
|
|
22858
|
-
constructor(workerUrl =
|
|
22867
|
+
constructor(workerUrl = defaultDataTransformWorkerUrl()) {
|
|
22859
22868
|
this.workerUrl = workerUrl;
|
|
22860
22869
|
}
|
|
22861
22870
|
execute(source, input, signal) {
|
|
@@ -23085,14 +23094,6 @@ var DataTransformExecutor = class {
|
|
|
23085
23094
|
void slot.worker.terminate();
|
|
23086
23095
|
}
|
|
23087
23096
|
};
|
|
23088
|
-
function defaultWorkerUrl() {
|
|
23089
|
-
if (typeof __dirname === "string") {
|
|
23090
|
-
return pathToFileURL(join(__dirname, "dataTransformWorker.js"));
|
|
23091
|
-
}
|
|
23092
|
-
const resolver = createRequire(pathToFileURL(join(process.cwd(), "__linkque_worker_resolver__.js")).href);
|
|
23093
|
-
const packageJson = resolver.resolve("@alipay/linkque-agent-runtime/package.json");
|
|
23094
|
-
return pathToFileURL(join(dirname(packageJson), "dist/esm/core/dataTransformWorker.js"));
|
|
23095
|
-
}
|
|
23096
23097
|
function jsonDepth(value, depth = 0) {
|
|
23097
23098
|
if (value === null || typeof value !== "object")
|
|
23098
23099
|
return depth;
|
|
@@ -29312,7 +29313,9 @@ var REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
|
29312
29313
|
"x-signature-content",
|
|
29313
29314
|
"x-alipay-sdk-version",
|
|
29314
29315
|
"x-alipay-authcode",
|
|
29315
|
-
"anthropic-api-key"
|
|
29316
|
+
"anthropic-api-key",
|
|
29317
|
+
"x-linkque-runtime-mac",
|
|
29318
|
+
"x-linkque-run-proof"
|
|
29316
29319
|
]);
|
|
29317
29320
|
var REDACTED_VALUE = "ak***";
|
|
29318
29321
|
var RESPONSE_CORRELATION_HEADER_NAMES = [
|
|
@@ -29767,20 +29770,20 @@ function toWebSearchFailure(error) {
|
|
|
29767
29770
|
return { code: safe.code, message: safe.message, retryable: safe.retryable };
|
|
29768
29771
|
}
|
|
29769
29772
|
function parseWebSearchArgs(args) {
|
|
29770
|
-
const
|
|
29773
|
+
const invalid2 = () => new WebSearchError("WEB_SEARCH_INVALID_ARGS");
|
|
29771
29774
|
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
29772
|
-
throw
|
|
29775
|
+
throw invalid2();
|
|
29773
29776
|
const value = args;
|
|
29774
29777
|
if (Object.keys(value).some((key) => key !== "query" && key !== "topK"))
|
|
29775
|
-
throw
|
|
29778
|
+
throw invalid2();
|
|
29776
29779
|
if (typeof value.query !== "string")
|
|
29777
|
-
throw
|
|
29780
|
+
throw invalid2();
|
|
29778
29781
|
const query = value.query.trim();
|
|
29779
29782
|
if (!query || [...query].length > WEB_SEARCH_QUERY_MAX_LENGTH)
|
|
29780
|
-
throw
|
|
29783
|
+
throw invalid2();
|
|
29781
29784
|
const topK = value.topK;
|
|
29782
29785
|
if (topK !== void 0 && (typeof topK !== "number" || !Number.isInteger(topK) || topK < 1 || topK > WEB_SEARCH_TOP_K_MAX))
|
|
29783
|
-
throw
|
|
29786
|
+
throw invalid2();
|
|
29784
29787
|
return { query, ...topK !== void 0 ? { topK } : {} };
|
|
29785
29788
|
}
|
|
29786
29789
|
function throwIfWebSearchAborted(signal) {
|
|
@@ -31199,6 +31202,189 @@ function encodeConversationSseEvent(event) {
|
|
|
31199
31202
|
`;
|
|
31200
31203
|
}
|
|
31201
31204
|
|
|
31205
|
+
// ../linkque-agent-runtime/dist/esm/impl/scenario/gatewayRunAuthorization.js
|
|
31206
|
+
import { hkdfSync, randomBytes } from "node:crypto";
|
|
31207
|
+
|
|
31208
|
+
// ../linkque-agent-runtime/dist/esm/impl/scenario/runtimeMac.js
|
|
31209
|
+
import { createHash as createHash3, createHmac, timingSafeEqual } from "node:crypto";
|
|
31210
|
+
function invalid() {
|
|
31211
|
+
throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
|
|
31212
|
+
}
|
|
31213
|
+
function canonicalJson(value, depth = 0) {
|
|
31214
|
+
if (depth > 64)
|
|
31215
|
+
invalid();
|
|
31216
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
31217
|
+
return JSON.stringify(value);
|
|
31218
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
31219
|
+
return JSON.stringify(value);
|
|
31220
|
+
if (Array.isArray(value))
|
|
31221
|
+
return `[${value.map((v) => canonicalJson(v, depth + 1)).join(",")}]`;
|
|
31222
|
+
if (value && typeof value === "object" && Object.prototype.toString.call(value) === "[object Object]") {
|
|
31223
|
+
return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k], depth + 1)}`).join(",")}}`;
|
|
31224
|
+
}
|
|
31225
|
+
return invalid();
|
|
31226
|
+
}
|
|
31227
|
+
function signRuntimeRequest(input, key) {
|
|
31228
|
+
if (!input || key?.length !== 32 || !Number.isSafeInteger(input.timestamp) || input.timestamp <= 0 || !/^[A-Za-z0-9_-]{1,64}$/u.test(input.caller) || !/^[A-Za-z0-9_-]{1,64}$/u.test(input.keyId) || !/^[a-f0-9]{32}$/u.test(input.nonce) || !/^[A-Z]{3,8}$/u.test(input.method) || typeof input.path !== "string" || !input.path.startsWith("/") || input.path.length > 2048 || typeof input.runId !== "string" || !/^[\x21-\x7e]{1,64}$/u.test(input.runId) || typeof input.appbaseUserId !== "string" || !/^[\x21-\x7e]{1,128}$/u.test(input.appbaseUserId) || typeof input.token !== "string" || !input.token || input.token.length > 8192 || typeof input.proof !== "string" || input.proof.length > 4200)
|
|
31229
|
+
invalid();
|
|
31230
|
+
const sha256 = (value) => createHash3("sha256").update(value).digest("hex");
|
|
31231
|
+
const body = canonicalJson(input.body);
|
|
31232
|
+
if (Buffer.byteLength(body) > 4 * 1024 * 1024)
|
|
31233
|
+
invalid();
|
|
31234
|
+
const payload = JSON.stringify([
|
|
31235
|
+
"linkque-runtime-request-v1",
|
|
31236
|
+
input.caller,
|
|
31237
|
+
input.keyId,
|
|
31238
|
+
input.timestamp,
|
|
31239
|
+
input.nonce,
|
|
31240
|
+
input.method,
|
|
31241
|
+
input.path,
|
|
31242
|
+
sha256(body),
|
|
31243
|
+
sha256(input.token),
|
|
31244
|
+
sha256(input.proof),
|
|
31245
|
+
input.runId,
|
|
31246
|
+
input.appbaseUserId
|
|
31247
|
+
]);
|
|
31248
|
+
return createHmac("sha256", key).update(payload).digest("base64url");
|
|
31249
|
+
}
|
|
31250
|
+
|
|
31251
|
+
// ../linkque-agent-runtime/dist/esm/impl/scenario/gatewayRunAuthorization.js
|
|
31252
|
+
var SCENARIO_RUNTIME_CALLER = "appbase-agent-function";
|
|
31253
|
+
var SCENARIO_RUNTIME_KEY_ID = "agent-aak-v1";
|
|
31254
|
+
function deriveScenarioRuntimeMacKey(accessKey) {
|
|
31255
|
+
const normalized = accessKey.trim();
|
|
31256
|
+
if (!normalized)
|
|
31257
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31258
|
+
return Buffer.from(hkdfSync("sha256", Buffer.from(normalized, "utf8"), "linkque-scenario-agent-aak-v1", "linkque:scenario:runtime-mac:v1", 32));
|
|
31259
|
+
}
|
|
31260
|
+
function createGatewayRunAuthorization(options) {
|
|
31261
|
+
const base = new URL(options.baseUrl);
|
|
31262
|
+
const key = deriveScenarioRuntimeMacKey(options.accessKey);
|
|
31263
|
+
if (base.protocol !== "https:" || base.username || base.password || base.search || base.hash) {
|
|
31264
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31265
|
+
}
|
|
31266
|
+
const modelPath = `${base.pathname.replace(/\/$/u, "")}/v1/messages`;
|
|
31267
|
+
const baseFetch = options.fetch ?? globalThis.fetch;
|
|
31268
|
+
return {
|
|
31269
|
+
async authorizeRun(identity) {
|
|
31270
|
+
const signedHeaders = (url2, body, proof) => {
|
|
31271
|
+
const timestamp = Date.now();
|
|
31272
|
+
const nonce = randomBytes(16).toString("hex");
|
|
31273
|
+
const mac = signRuntimeRequest({
|
|
31274
|
+
...identity,
|
|
31275
|
+
caller: SCENARIO_RUNTIME_CALLER,
|
|
31276
|
+
keyId: SCENARIO_RUNTIME_KEY_ID,
|
|
31277
|
+
timestamp,
|
|
31278
|
+
nonce,
|
|
31279
|
+
method: "POST",
|
|
31280
|
+
path: url2.pathname + url2.search,
|
|
31281
|
+
token: options.token,
|
|
31282
|
+
proof,
|
|
31283
|
+
body
|
|
31284
|
+
}, key);
|
|
31285
|
+
return {
|
|
31286
|
+
"x-linkque-runtime-caller": SCENARIO_RUNTIME_CALLER,
|
|
31287
|
+
"x-linkque-runtime-key-id": SCENARIO_RUNTIME_KEY_ID,
|
|
31288
|
+
"x-linkque-runtime-timestamp": String(timestamp),
|
|
31289
|
+
"x-linkque-runtime-nonce": nonce,
|
|
31290
|
+
"x-linkque-runtime-user-id": identity.appbaseUserId,
|
|
31291
|
+
"x-linkque-runtime-mac": mac
|
|
31292
|
+
};
|
|
31293
|
+
};
|
|
31294
|
+
const invoke = async (path2, previousProof) => {
|
|
31295
|
+
const url2 = new URL(path2, base.origin);
|
|
31296
|
+
const body = {
|
|
31297
|
+
agentId: identity.agentId,
|
|
31298
|
+
runId: identity.runId,
|
|
31299
|
+
...previousProof ? { proof: previousProof } : {}
|
|
31300
|
+
};
|
|
31301
|
+
let response;
|
|
31302
|
+
try {
|
|
31303
|
+
response = await baseFetch(url2, {
|
|
31304
|
+
method: "POST",
|
|
31305
|
+
redirect: "error",
|
|
31306
|
+
signal: AbortSignal.timeout(5e3),
|
|
31307
|
+
headers: {
|
|
31308
|
+
authorization: `Bearer ${options.token}`,
|
|
31309
|
+
"content-type": "application/json",
|
|
31310
|
+
...signedHeaders(url2, body, previousProof ?? "")
|
|
31311
|
+
},
|
|
31312
|
+
body: JSON.stringify(body)
|
|
31313
|
+
});
|
|
31314
|
+
} catch {
|
|
31315
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31316
|
+
}
|
|
31317
|
+
if (!response.ok)
|
|
31318
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31319
|
+
const raw = await response.text();
|
|
31320
|
+
if (raw.length > 16384)
|
|
31321
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31322
|
+
let result;
|
|
31323
|
+
try {
|
|
31324
|
+
result = JSON.parse(raw);
|
|
31325
|
+
} catch {
|
|
31326
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31327
|
+
}
|
|
31328
|
+
if (result?.success !== true) {
|
|
31329
|
+
throw new Error([
|
|
31330
|
+
"SCENARIO_TURN_LIMIT",
|
|
31331
|
+
"SCENARIO_RUNTIME_AUTH_INVALID",
|
|
31332
|
+
"SCENARIO_RUNTIME_REPLAY"
|
|
31333
|
+
].includes(result?.errorCode) ? result.errorCode : "SCENARIO_RUN_UNAVAILABLE");
|
|
31334
|
+
}
|
|
31335
|
+
const data = result.data;
|
|
31336
|
+
if (data?.quotaMode === "NORMAL" && !previousProof)
|
|
31337
|
+
return { quotaMode: "NORMAL" };
|
|
31338
|
+
if (!["LIMITED", "AUTH_ONLY"].includes(data?.quotaMode) || typeof data.proof !== "string" || !data.proof || data.proof.length > 4200 || !Number.isSafeInteger(data.expiresAt) || data.expiresAt <= Date.now())
|
|
31339
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31340
|
+
return data;
|
|
31341
|
+
};
|
|
31342
|
+
let grant = await invoke("/api/scenario/authorize-run");
|
|
31343
|
+
if (grant.quotaMode === "NORMAL")
|
|
31344
|
+
return { quotaMode: "NORMAL" };
|
|
31345
|
+
const quotaMode = grant.quotaMode;
|
|
31346
|
+
let renewing;
|
|
31347
|
+
const requireProof = async () => {
|
|
31348
|
+
if (grant.expiresAt - Date.now() > 15e3)
|
|
31349
|
+
return;
|
|
31350
|
+
renewing ??= invoke("/api/scenario/renew-run", grant.proof).then((next) => {
|
|
31351
|
+
if (next.quotaMode !== quotaMode)
|
|
31352
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
31353
|
+
grant = next;
|
|
31354
|
+
}).finally(() => {
|
|
31355
|
+
renewing = void 0;
|
|
31356
|
+
});
|
|
31357
|
+
await renewing;
|
|
31358
|
+
};
|
|
31359
|
+
const modelFetch = async (input, init) => {
|
|
31360
|
+
const request = new Request(input, init);
|
|
31361
|
+
const url2 = new URL(request.url);
|
|
31362
|
+
if (request.method !== "POST" || url2.origin !== base.origin || url2.pathname !== modelPath || url2.search || url2.hash || request.headers.get("x-api-key") !== options.token)
|
|
31363
|
+
throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
|
|
31364
|
+
const raw = await request.text();
|
|
31365
|
+
if (Buffer.byteLength(raw) > 4 * 1024 * 1024)
|
|
31366
|
+
throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
|
|
31367
|
+
const body = JSON.parse(raw);
|
|
31368
|
+
await requireProof();
|
|
31369
|
+
const headers = new Headers(request.headers);
|
|
31370
|
+
headers.set("x-linkque-run-proof", grant.proof);
|
|
31371
|
+
headers.set("x-run-id", identity.runId);
|
|
31372
|
+
headers.set("x-agent-id", identity.agentId);
|
|
31373
|
+
for (const [headerName, value] of Object.entries(signedHeaders(url2, body, grant.proof)))
|
|
31374
|
+
headers.set(headerName, value);
|
|
31375
|
+
return baseFetch(request.url, {
|
|
31376
|
+
method: "POST",
|
|
31377
|
+
headers,
|
|
31378
|
+
body: raw,
|
|
31379
|
+
signal: request.signal,
|
|
31380
|
+
redirect: "error"
|
|
31381
|
+
});
|
|
31382
|
+
};
|
|
31383
|
+
return { quotaMode, modelFetch };
|
|
31384
|
+
}
|
|
31385
|
+
};
|
|
31386
|
+
}
|
|
31387
|
+
|
|
31202
31388
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
31203
31389
|
function isZ4Schema(s) {
|
|
31204
31390
|
const schema = s;
|
|
@@ -32848,6 +33034,9 @@ var Protocol = class {
|
|
|
32848
33034
|
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
32849
33035
|
const handleTaskResult = async () => {
|
|
32850
33036
|
const taskId = request.params.taskId;
|
|
33037
|
+
if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
|
|
33038
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
33039
|
+
}
|
|
32851
33040
|
if (this._taskMessageQueue) {
|
|
32852
33041
|
let queuedMessage;
|
|
32853
33042
|
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
@@ -32878,12 +33067,12 @@ var Protocol = class {
|
|
|
32878
33067
|
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
32879
33068
|
}
|
|
32880
33069
|
if (!isTerminal(task.status)) {
|
|
32881
|
-
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
33070
|
+
await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
|
|
32882
33071
|
return await handleTaskResult();
|
|
32883
33072
|
}
|
|
32884
33073
|
if (isTerminal(task.status)) {
|
|
32885
33074
|
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
32886
|
-
this._clearTaskQueue(taskId);
|
|
33075
|
+
this._clearTaskQueue(taskId, extra.sessionId);
|
|
32887
33076
|
return {
|
|
32888
33077
|
...result,
|
|
32889
33078
|
_meta: {
|
|
@@ -32920,7 +33109,7 @@ var Protocol = class {
|
|
|
32920
33109
|
throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
32921
33110
|
}
|
|
32922
33111
|
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
32923
|
-
this._clearTaskQueue(request.params.taskId);
|
|
33112
|
+
this._clearTaskQueue(request.params.taskId, extra.sessionId);
|
|
32924
33113
|
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
32925
33114
|
if (!cancelledTask) {
|
|
32926
33115
|
throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
@@ -33048,6 +33237,19 @@ var Protocol = class {
|
|
|
33048
33237
|
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
33049
33238
|
const capturedTransport = this._transport;
|
|
33050
33239
|
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
33240
|
+
const sessionId = capturedTransport?.sessionId;
|
|
33241
|
+
const store = this._taskStore;
|
|
33242
|
+
let relatedTaskFound = true;
|
|
33243
|
+
let relatedTaskLookup;
|
|
33244
|
+
if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
|
|
33245
|
+
relatedTaskFound = false;
|
|
33246
|
+
relatedTaskLookup = (async () => {
|
|
33247
|
+
if (!await store.getTask(relatedTaskId, sessionId)) {
|
|
33248
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
|
|
33249
|
+
}
|
|
33250
|
+
relatedTaskFound = true;
|
|
33251
|
+
})();
|
|
33252
|
+
}
|
|
33051
33253
|
if (handler === void 0) {
|
|
33052
33254
|
const errorResponse = {
|
|
33053
33255
|
jsonrpc: "2.0",
|
|
@@ -33057,7 +33259,10 @@ var Protocol = class {
|
|
|
33057
33259
|
message: "Method not found"
|
|
33058
33260
|
}
|
|
33059
33261
|
};
|
|
33060
|
-
if (relatedTaskId &&
|
|
33262
|
+
if (relatedTaskId && relatedTaskLookup) {
|
|
33263
|
+
const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
|
|
33264
|
+
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
|
|
33265
|
+
} else if (relatedTaskId && this._taskMessageQueue) {
|
|
33061
33266
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
33062
33267
|
type: "error",
|
|
33063
33268
|
message: errorResponse,
|
|
@@ -33108,7 +33313,10 @@ var Protocol = class {
|
|
|
33108
33313
|
closeSSEStream: extra?.closeSSEStream,
|
|
33109
33314
|
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
33110
33315
|
};
|
|
33111
|
-
Promise.resolve().then(() => {
|
|
33316
|
+
(relatedTaskLookup ?? Promise.resolve()).then(() => {
|
|
33317
|
+
if (relatedTaskLookup && abortController.signal.aborted) {
|
|
33318
|
+
throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
|
|
33319
|
+
}
|
|
33112
33320
|
if (taskCreationParams) {
|
|
33113
33321
|
this.assertTaskHandlerCapability(request.method);
|
|
33114
33322
|
}
|
|
@@ -33143,7 +33351,7 @@ var Protocol = class {
|
|
|
33143
33351
|
...error["data"] !== void 0 && { data: error["data"] }
|
|
33144
33352
|
}
|
|
33145
33353
|
};
|
|
33146
|
-
if (relatedTaskId && this._taskMessageQueue) {
|
|
33354
|
+
if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
|
|
33147
33355
|
await this._enqueueTaskMessage(relatedTaskId, {
|
|
33148
33356
|
type: "error",
|
|
33149
33357
|
message: errorResponse,
|
|
@@ -33623,7 +33831,7 @@ var Protocol = class {
|
|
|
33623
33831
|
throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
33624
33832
|
}
|
|
33625
33833
|
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
33626
|
-
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
33834
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
|
|
33627
33835
|
}
|
|
33628
33836
|
/**
|
|
33629
33837
|
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
@@ -33652,12 +33860,13 @@ var Protocol = class {
|
|
|
33652
33860
|
* Uses polling to check for updates at the task's configured poll interval.
|
|
33653
33861
|
* @param taskId The task ID to wait for
|
|
33654
33862
|
* @param signal Abort signal to cancel the wait
|
|
33863
|
+
* @param sessionId Session of the request that waits, passed to the task store
|
|
33655
33864
|
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
33656
33865
|
*/
|
|
33657
|
-
async _waitForTaskUpdate(taskId, signal) {
|
|
33866
|
+
async _waitForTaskUpdate(taskId, signal, sessionId) {
|
|
33658
33867
|
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
33659
33868
|
try {
|
|
33660
|
-
const task = await this._taskStore?.getTask(taskId);
|
|
33869
|
+
const task = await this._taskStore?.getTask(taskId, sessionId);
|
|
33661
33870
|
if (task?.pollInterval) {
|
|
33662
33871
|
interval = task.pollInterval;
|
|
33663
33872
|
}
|
|
@@ -35292,6 +35501,68 @@ function createFetchWithInit(baseFetch = fetch, baseInit) {
|
|
|
35292
35501
|
return baseFetch(url2, mergedInit);
|
|
35293
35502
|
};
|
|
35294
35503
|
}
|
|
35504
|
+
var MAX_REDIRECTS = 5;
|
|
35505
|
+
var REDIRECT_STATUSES = [301, 302, 303, 307, 308];
|
|
35506
|
+
function isWithinOrigin(from, to) {
|
|
35507
|
+
if (from.protocol === to.protocol && from.hostname === to.hostname && from.port === to.port) {
|
|
35508
|
+
return true;
|
|
35509
|
+
}
|
|
35510
|
+
return from.hostname === to.hostname && from.protocol === "http:" && from.port === "" && to.protocol === "https:" && to.port === "";
|
|
35511
|
+
}
|
|
35512
|
+
function redirectTarget(response, requestUrl) {
|
|
35513
|
+
const location = REDIRECT_STATUSES.includes(response.status) ? response.headers.get("location") : null;
|
|
35514
|
+
try {
|
|
35515
|
+
return location ? new URL(location, requestUrl) : void 0;
|
|
35516
|
+
} catch {
|
|
35517
|
+
return void 0;
|
|
35518
|
+
}
|
|
35519
|
+
}
|
|
35520
|
+
function followWithinOrigin(baseFetch, url2, init, response, followed = 0) {
|
|
35521
|
+
const target = redirectTarget(response, url2);
|
|
35522
|
+
const keepsMethod = response.status === 307 || response.status === 308 || (init?.method ?? "GET").toUpperCase() === "GET";
|
|
35523
|
+
if (!target || followed === MAX_REDIRECTS || !keepsMethod) {
|
|
35524
|
+
return void 0;
|
|
35525
|
+
}
|
|
35526
|
+
const from = new URL(url2);
|
|
35527
|
+
const addsUserinfo = (target.username || target.password) && (target.username !== from.username || target.password !== from.password);
|
|
35528
|
+
if (addsUserinfo || !isWithinOrigin(from, target)) {
|
|
35529
|
+
return void 0;
|
|
35530
|
+
}
|
|
35531
|
+
return Promise.resolve(response.body?.cancel()).then(() => baseFetch(target, { ...init, redirect: "manual" })).then((next) => followWithinOrigin(baseFetch, target, init, next, followed + 1) ?? next);
|
|
35532
|
+
}
|
|
35533
|
+
var followingFetches = /* @__PURE__ */ new WeakSet();
|
|
35534
|
+
function fetchLeavingRedirects(baseFetch) {
|
|
35535
|
+
const following = (url2, init) => (baseFetch ?? fetch)(url2, init);
|
|
35536
|
+
followingFetches.add(following);
|
|
35537
|
+
return following;
|
|
35538
|
+
}
|
|
35539
|
+
function fetchWithinOrigin(baseFetch = fetch) {
|
|
35540
|
+
if (followingFetches.has(baseFetch)) {
|
|
35541
|
+
return baseFetch;
|
|
35542
|
+
}
|
|
35543
|
+
return (url2, init) => {
|
|
35544
|
+
if (init?.redirect === "error" || init?.redirect === "manual") {
|
|
35545
|
+
return baseFetch(url2, init);
|
|
35546
|
+
}
|
|
35547
|
+
return Promise.resolve(baseFetch(url2, { ...init, redirect: "manual" })).then((response) => followWithinOrigin(baseFetch, url2, init, response) ?? response);
|
|
35548
|
+
};
|
|
35549
|
+
}
|
|
35550
|
+
function unfollowedRedirect(response, requestUrl) {
|
|
35551
|
+
if (response.type === "opaqueredirect") {
|
|
35552
|
+
return "Redirect not followed: this runtime does not expose the redirect target";
|
|
35553
|
+
}
|
|
35554
|
+
const from = response.url || requestUrl;
|
|
35555
|
+
const target = redirectTarget(response, from);
|
|
35556
|
+
if (!target) {
|
|
35557
|
+
return void 0;
|
|
35558
|
+
}
|
|
35559
|
+
target.username = target.password = target.search = target.hash = "";
|
|
35560
|
+
if (target.protocol === "http:" && new URL(from).protocol === "https:") {
|
|
35561
|
+
target.protocol = "https:";
|
|
35562
|
+
return `Redirect to plain http not followed; try ${target.href} instead`;
|
|
35563
|
+
}
|
|
35564
|
+
return `Redirect to ${target.href} not followed`;
|
|
35565
|
+
}
|
|
35295
35566
|
|
|
35296
35567
|
// ../../node_modules/pkce-challenge/dist/index.node.js
|
|
35297
35568
|
var crypto;
|
|
@@ -35306,8 +35577,8 @@ async function random(size) {
|
|
|
35306
35577
|
const evenDistCutoff = Math.pow(2, 8) - Math.pow(2, 8) % mask.length;
|
|
35307
35578
|
let result = "";
|
|
35308
35579
|
while (result.length < size) {
|
|
35309
|
-
const
|
|
35310
|
-
for (const randomByte of
|
|
35580
|
+
const randomBytes2 = await getRandomValues(size - result.length);
|
|
35581
|
+
for (const randomByte of randomBytes2) {
|
|
35311
35582
|
if (randomByte < evenDistCutoff) {
|
|
35312
35583
|
result += mask[randomByte % mask.length];
|
|
35313
35584
|
}
|
|
@@ -35438,7 +35709,12 @@ var OAuthTokensSchema = object({
|
|
|
35438
35709
|
token_type: string(),
|
|
35439
35710
|
expires_in: coerce_exports.number().optional(),
|
|
35440
35711
|
scope: string().optional(),
|
|
35441
|
-
refresh_token: string().optional()
|
|
35712
|
+
refresh_token: string().optional(),
|
|
35713
|
+
/**
|
|
35714
|
+
* Not part of the wire format: the authorization server this value was obtained from, added by
|
|
35715
|
+
* the client's `auth()` before it is stored and compared when it is read back.
|
|
35716
|
+
*/
|
|
35717
|
+
issuer: string().optional().catch(void 0)
|
|
35442
35718
|
}).strip();
|
|
35443
35719
|
var OAuthErrorResponseSchema = object({
|
|
35444
35720
|
error: string(),
|
|
@@ -35468,7 +35744,12 @@ var OAuthClientInformationSchema = object({
|
|
|
35468
35744
|
client_id: string(),
|
|
35469
35745
|
client_secret: string().optional(),
|
|
35470
35746
|
client_id_issued_at: number().optional(),
|
|
35471
|
-
client_secret_expires_at: number().optional()
|
|
35747
|
+
client_secret_expires_at: number().optional(),
|
|
35748
|
+
/**
|
|
35749
|
+
* Not part of the wire format: the authorization server this value was obtained from, added by
|
|
35750
|
+
* the client's `auth()` before it is stored and compared when it is read back.
|
|
35751
|
+
*/
|
|
35752
|
+
issuer: string().optional().catch(void 0)
|
|
35472
35753
|
}).strip();
|
|
35473
35754
|
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
35474
35755
|
var OAuthClientRegistrationErrorSchema = object({
|
|
@@ -35666,10 +35947,31 @@ async function parseErrorResponse(input) {
|
|
|
35666
35947
|
const errorClass = OAUTH_ERRORS[error] || ServerError;
|
|
35667
35948
|
return new errorClass(error_description || "", error_uri);
|
|
35668
35949
|
} catch (error) {
|
|
35669
|
-
const
|
|
35950
|
+
const redirect = input instanceof Response ? unfollowedRedirect(input, input.url) : void 0;
|
|
35951
|
+
const errorMessage2 = `${statusCode ? `HTTP ${statusCode}: ` : ""}${redirect ?? `Invalid OAuth error response: ${error}. Raw body: ${body}`}`;
|
|
35670
35952
|
return new ServerError(errorMessage2);
|
|
35671
35953
|
}
|
|
35672
35954
|
}
|
|
35955
|
+
function issuersMatch(a, b) {
|
|
35956
|
+
let [x, y] = [a, b];
|
|
35957
|
+
try {
|
|
35958
|
+
[x, y] = [new URL(a).href, new URL(b).href];
|
|
35959
|
+
} catch {
|
|
35960
|
+
}
|
|
35961
|
+
return x === y || x.endsWith("/") && x.slice(0, -1) === y || y.endsWith("/") && y.slice(0, -1) === x;
|
|
35962
|
+
}
|
|
35963
|
+
function discardIfIssuerMismatch(stored, issuer) {
|
|
35964
|
+
if (!stored)
|
|
35965
|
+
return void 0;
|
|
35966
|
+
if (typeof stored.issuer !== "string")
|
|
35967
|
+
return stored.issuer == null ? stored : { ...stored, issuer: void 0 };
|
|
35968
|
+
return issuersMatch(stored.issuer, issuer) ? stored : void 0;
|
|
35969
|
+
}
|
|
35970
|
+
var TokenResponseSchema = OAuthTokensSchema.omit({ issuer: true });
|
|
35971
|
+
var RegistrationResponseSchema = OAuthClientInformationFullSchema.omit({ issuer: true });
|
|
35972
|
+
function boundElsewhereError(stored, issuer) {
|
|
35973
|
+
return new Error(`OAuth client information is bound to authorization server ${stored.issuer} and is not presented to ${issuer}. Clear the stored client information, or correct \`expectedIssuer\`, if the authorization server has moved.`);
|
|
35974
|
+
}
|
|
35673
35975
|
async function auth(provider, options) {
|
|
35674
35976
|
try {
|
|
35675
35977
|
return await authInternal(provider, options);
|
|
@@ -35723,9 +36025,24 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35723
36025
|
authorizationServerMetadata: metadata
|
|
35724
36026
|
});
|
|
35725
36027
|
}
|
|
35726
|
-
const
|
|
36028
|
+
const issuer = String(authorizationServerUrl);
|
|
36029
|
+
const selectedResource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
36030
|
+
const resource = selectedResource && resourceMetadata && !provider.validateResourceURL ? resourceMetadata.resource : selectedResource;
|
|
35727
36031
|
const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
|
|
35728
|
-
|
|
36032
|
+
const storedClientInformation = await Promise.resolve(provider.clientInformation());
|
|
36033
|
+
let clientInformation = discardIfIssuerMismatch(storedClientInformation, issuer);
|
|
36034
|
+
const canRegisterAgain = provider.saveClientInformation !== void 0 && !!provider.redirectUrl;
|
|
36035
|
+
if (storedClientInformation && !clientInformation && !canRegisterAgain) {
|
|
36036
|
+
throw boundElsewhereError(storedClientInformation, issuer);
|
|
36037
|
+
}
|
|
36038
|
+
const unstampedClientInformation = clientInformation?.issuer == null ? clientInformation : void 0;
|
|
36039
|
+
const bindClientInformation = async () => {
|
|
36040
|
+
try {
|
|
36041
|
+
if (unstampedClientInformation)
|
|
36042
|
+
await provider.saveClientInformation?.({ ...unstampedClientInformation, issuer });
|
|
36043
|
+
} catch {
|
|
36044
|
+
}
|
|
36045
|
+
};
|
|
35729
36046
|
if (!clientInformation) {
|
|
35730
36047
|
if (authorizationCode !== void 0) {
|
|
35731
36048
|
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
@@ -35737,9 +36054,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35737
36054
|
}
|
|
35738
36055
|
const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl;
|
|
35739
36056
|
if (shouldUseUrlBasedClientId) {
|
|
35740
|
-
clientInformation = {
|
|
35741
|
-
client_id: clientMetadataUrl
|
|
35742
|
-
};
|
|
36057
|
+
clientInformation = { client_id: clientMetadataUrl, issuer };
|
|
35743
36058
|
await provider.saveClientInformation?.(clientInformation);
|
|
35744
36059
|
} else {
|
|
35745
36060
|
if (!provider.saveClientInformation) {
|
|
@@ -35751,8 +36066,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35751
36066
|
scope: resolvedScope,
|
|
35752
36067
|
fetchFn
|
|
35753
36068
|
});
|
|
35754
|
-
|
|
35755
|
-
clientInformation
|
|
36069
|
+
clientInformation = { ...fullInformation, issuer };
|
|
36070
|
+
await provider.saveClientInformation(clientInformation);
|
|
35756
36071
|
}
|
|
35757
36072
|
}
|
|
35758
36073
|
const nonInteractiveFlow = !provider.redirectUrl;
|
|
@@ -35763,10 +36078,14 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35763
36078
|
authorizationCode,
|
|
35764
36079
|
fetchFn
|
|
35765
36080
|
});
|
|
35766
|
-
await
|
|
36081
|
+
await bindClientInformation();
|
|
36082
|
+
await provider.saveTokens({ ...tokens2, issuer });
|
|
35767
36083
|
return "AUTHORIZED";
|
|
35768
36084
|
}
|
|
35769
|
-
const tokens = await provider.tokens();
|
|
36085
|
+
const tokens = discardIfIssuerMismatch(await provider.tokens(), issuer);
|
|
36086
|
+
if (tokens?.refresh_token && tokens.issuer == null) {
|
|
36087
|
+
console.warn("[mcp-sdk] stored OAuth tokens have no 'issuer' property (saved by an earlier version, or by a provider that does not keep it) and are used as-is; make sure your OAuthClientProvider stores what saveTokens() and saveClientInformation() receive unchanged.");
|
|
36088
|
+
}
|
|
35770
36089
|
if (tokens?.refresh_token) {
|
|
35771
36090
|
try {
|
|
35772
36091
|
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
@@ -35777,7 +36096,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35777
36096
|
addClientAuthentication: provider.addClientAuthentication,
|
|
35778
36097
|
fetchFn
|
|
35779
36098
|
});
|
|
35780
|
-
await
|
|
36099
|
+
await bindClientInformation();
|
|
36100
|
+
await provider.saveTokens({ ...newTokens, issuer });
|
|
35781
36101
|
return "AUTHORIZED";
|
|
35782
36102
|
} catch (error) {
|
|
35783
36103
|
if (!(error instanceof OAuthError) || error instanceof ServerError) {
|
|
@@ -35876,7 +36196,7 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn =
|
|
|
35876
36196
|
}
|
|
35877
36197
|
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
35878
36198
|
try {
|
|
35879
|
-
return await fetchFn(url2, { headers });
|
|
36199
|
+
return await fetchWithinOrigin(fetchFn)(url2, { headers });
|
|
35880
36200
|
} catch (error) {
|
|
35881
36201
|
if (error instanceof TypeError) {
|
|
35882
36202
|
if (headers) {
|
|
@@ -35901,7 +36221,7 @@ async function tryMetadataDiscovery(url2, protocolVersion, fetchFn = fetch) {
|
|
|
35901
36221
|
return await fetchWithCorsRetry(url2, headers, fetchFn);
|
|
35902
36222
|
}
|
|
35903
36223
|
function shouldAttemptFallback(response, pathname) {
|
|
35904
|
-
return !response || response.
|
|
36224
|
+
return !response || !response.ok && response.status < 500 && pathname !== "/";
|
|
35905
36225
|
}
|
|
35906
36226
|
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
35907
36227
|
const issuer = new URL(serverUrl);
|
|
@@ -35967,7 +36287,7 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
35967
36287
|
}
|
|
35968
36288
|
if (!response.ok) {
|
|
35969
36289
|
await response.body?.cancel();
|
|
35970
|
-
if (response.status
|
|
36290
|
+
if (response.status < 500) {
|
|
35971
36291
|
continue;
|
|
35972
36292
|
}
|
|
35973
36293
|
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
@@ -36000,6 +36320,9 @@ async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
|
36000
36320
|
resourceMetadata
|
|
36001
36321
|
};
|
|
36002
36322
|
}
|
|
36323
|
+
function resourceIndicatorToString(resource) {
|
|
36324
|
+
return typeof resource === "string" ? resource : resource.href;
|
|
36325
|
+
}
|
|
36003
36326
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
36004
36327
|
let authorizationUrl;
|
|
36005
36328
|
if (metadata) {
|
|
@@ -36031,7 +36354,7 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
|
|
|
36031
36354
|
authorizationUrl.searchParams.append("prompt", "consent");
|
|
36032
36355
|
}
|
|
36033
36356
|
if (resource) {
|
|
36034
|
-
authorizationUrl.searchParams.set("resource", resource
|
|
36357
|
+
authorizationUrl.searchParams.set("resource", resourceIndicatorToString(resource));
|
|
36035
36358
|
}
|
|
36036
36359
|
return { authorizationUrl, codeVerifier };
|
|
36037
36360
|
}
|
|
@@ -36050,7 +36373,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
36050
36373
|
Accept: "application/json"
|
|
36051
36374
|
});
|
|
36052
36375
|
if (resource) {
|
|
36053
|
-
tokenRequestParams.set("resource", resource
|
|
36376
|
+
tokenRequestParams.set("resource", resourceIndicatorToString(resource));
|
|
36054
36377
|
}
|
|
36055
36378
|
if (addClientAuthentication) {
|
|
36056
36379
|
await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
|
|
@@ -36059,7 +36382,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
36059
36382
|
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
36060
36383
|
applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams);
|
|
36061
36384
|
}
|
|
36062
|
-
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
36385
|
+
const response = await fetchWithinOrigin(fetchFn ?? fetch)(tokenUrl, {
|
|
36063
36386
|
method: "POST",
|
|
36064
36387
|
headers,
|
|
36065
36388
|
body: tokenRequestParams
|
|
@@ -36067,7 +36390,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
36067
36390
|
if (!response.ok) {
|
|
36068
36391
|
throw await parseErrorResponse(response);
|
|
36069
36392
|
}
|
|
36070
|
-
return
|
|
36393
|
+
return TokenResponseSchema.parse(await response.json());
|
|
36071
36394
|
}
|
|
36072
36395
|
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
36073
36396
|
const tokenRequestParams = new URLSearchParams({
|
|
@@ -36085,6 +36408,15 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
|
|
|
36085
36408
|
return { refresh_token: refreshToken, ...tokens };
|
|
36086
36409
|
}
|
|
36087
36410
|
async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) {
|
|
36411
|
+
const readClientInformation = async () => {
|
|
36412
|
+
const storedClientInformation = await provider.clientInformation();
|
|
36413
|
+
const checked = discardIfIssuerMismatch(storedClientInformation, String(authorizationServerUrl));
|
|
36414
|
+
if (storedClientInformation && !checked) {
|
|
36415
|
+
throw boundElsewhereError(storedClientInformation, String(authorizationServerUrl));
|
|
36416
|
+
}
|
|
36417
|
+
return checked;
|
|
36418
|
+
};
|
|
36419
|
+
let clientInformation = await readClientInformation();
|
|
36088
36420
|
const scope = provider.clientMetadata.scope;
|
|
36089
36421
|
let tokenRequestParams;
|
|
36090
36422
|
if (provider.prepareTokenRequest) {
|
|
@@ -36100,11 +36432,11 @@ async function fetchToken(provider, authorizationServerUrl, { metadata, resource
|
|
|
36100
36432
|
const codeVerifier = await provider.codeVerifier();
|
|
36101
36433
|
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
|
|
36102
36434
|
}
|
|
36103
|
-
|
|
36435
|
+
clientInformation ?? (clientInformation = await readClientInformation());
|
|
36104
36436
|
return executeTokenRequest(authorizationServerUrl, {
|
|
36105
36437
|
metadata,
|
|
36106
36438
|
tokenRequestParams,
|
|
36107
|
-
clientInformation
|
|
36439
|
+
clientInformation,
|
|
36108
36440
|
addClientAuthentication: provider.addClientAuthentication,
|
|
36109
36441
|
resource,
|
|
36110
36442
|
fetchFn
|
|
@@ -36120,7 +36452,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
36120
36452
|
} else {
|
|
36121
36453
|
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
36122
36454
|
}
|
|
36123
|
-
const response = await (fetchFn ?? fetch)(registrationUrl, {
|
|
36455
|
+
const response = await fetchWithinOrigin(fetchFn ?? fetch)(registrationUrl, {
|
|
36124
36456
|
method: "POST",
|
|
36125
36457
|
headers: {
|
|
36126
36458
|
"Content-Type": "application/json"
|
|
@@ -36133,7 +36465,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
36133
36465
|
if (!response.ok) {
|
|
36134
36466
|
throw await parseErrorResponse(response);
|
|
36135
36467
|
}
|
|
36136
|
-
return
|
|
36468
|
+
return RegistrationResponseSchema.parse(await response.json());
|
|
36137
36469
|
}
|
|
36138
36470
|
|
|
36139
36471
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
@@ -36154,6 +36486,16 @@ var SSEClientTransport = class {
|
|
|
36154
36486
|
this._authProvider = opts?.authProvider;
|
|
36155
36487
|
this._fetch = opts?.fetch;
|
|
36156
36488
|
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
36489
|
+
this._followRedirects = opts?.redirectPolicy === "follow";
|
|
36490
|
+
if (this._followRedirects) {
|
|
36491
|
+
this._fetch = fetchLeavingRedirects(this._fetch);
|
|
36492
|
+
this._fetchWithInit = fetchLeavingRedirects(this._fetchWithInit);
|
|
36493
|
+
}
|
|
36494
|
+
}
|
|
36495
|
+
/** Error text for a redirect `response` that was not followed, or `undefined` for any other response. */
|
|
36496
|
+
_unfollowedRedirect(response, url2) {
|
|
36497
|
+
const text = unfollowedRedirect(response, url2);
|
|
36498
|
+
return text && !this._followRedirects ? `${text} (redirectPolicy: 'same-origin')` : text;
|
|
36157
36499
|
}
|
|
36158
36500
|
async _authThenStart() {
|
|
36159
36501
|
if (!this._authProvider) {
|
|
@@ -36194,7 +36536,9 @@ var SSEClientTransport = class {
|
|
|
36194
36536
|
});
|
|
36195
36537
|
}
|
|
36196
36538
|
_startOrAuth() {
|
|
36197
|
-
const
|
|
36539
|
+
const baseFetch = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
36540
|
+
const fetchImpl = this._followRedirects ? baseFetch : fetchWithinOrigin(baseFetch);
|
|
36541
|
+
let redirect;
|
|
36198
36542
|
return new Promise((resolve, reject) => {
|
|
36199
36543
|
this._eventSource = new EventSource(this._url.href, {
|
|
36200
36544
|
...this._eventSourceInit,
|
|
@@ -36205,6 +36549,7 @@ var SSEClientTransport = class {
|
|
|
36205
36549
|
...init,
|
|
36206
36550
|
headers
|
|
36207
36551
|
});
|
|
36552
|
+
redirect = this._unfollowedRedirect(response, url2);
|
|
36208
36553
|
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
36209
36554
|
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
36210
36555
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
@@ -36219,7 +36564,7 @@ var SSEClientTransport = class {
|
|
|
36219
36564
|
this._authThenStart().then(resolve, reject);
|
|
36220
36565
|
return;
|
|
36221
36566
|
}
|
|
36222
|
-
const error = new SseError(event.code, event.message, event);
|
|
36567
|
+
const error = new SseError(event.code, redirect ?? event.message, event);
|
|
36223
36568
|
reject(error);
|
|
36224
36569
|
this.onerror?.(error);
|
|
36225
36570
|
};
|
|
@@ -36296,7 +36641,7 @@ var SSEClientTransport = class {
|
|
|
36296
36641
|
body: JSON.stringify(message),
|
|
36297
36642
|
signal: this._abortController?.signal
|
|
36298
36643
|
};
|
|
36299
|
-
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
36644
|
+
const response = await fetchWithinOrigin(this._fetch ?? fetch)(this._endpoint, init);
|
|
36300
36645
|
if (!response.ok) {
|
|
36301
36646
|
const text = await response.text().catch(() => null);
|
|
36302
36647
|
if (response.status === 401 && this._authProvider) {
|
|
@@ -36314,7 +36659,7 @@ var SSEClientTransport = class {
|
|
|
36314
36659
|
}
|
|
36315
36660
|
return this.send(message);
|
|
36316
36661
|
}
|
|
36317
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text}`);
|
|
36662
|
+
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${this._unfollowedRedirect(response, this._endpoint) ?? text}`);
|
|
36318
36663
|
}
|
|
36319
36664
|
await response.body?.cancel();
|
|
36320
36665
|
} catch (error) {
|
|
@@ -37106,9 +37451,9 @@ function isText(value, max2) {
|
|
|
37106
37451
|
return typeof value === "string" && !!value.trim() && [...value].length <= max2;
|
|
37107
37452
|
}
|
|
37108
37453
|
function parseResponse(body, query, topK) {
|
|
37109
|
-
const
|
|
37454
|
+
const invalid2 = () => new WebSearchError("WEB_SEARCH_INVALID_RESPONSE");
|
|
37110
37455
|
if (!isObject2(body))
|
|
37111
|
-
throw
|
|
37456
|
+
throw invalid2();
|
|
37112
37457
|
if (body.success === false) {
|
|
37113
37458
|
const code = body.errorCode;
|
|
37114
37459
|
if (code === "UNAUTHORIZED")
|
|
@@ -37126,7 +37471,7 @@ function parseResponse(body, query, topK) {
|
|
|
37126
37471
|
throw new WebSearchError(supported.includes(code) ? code : "WEB_SEARCH_UPSTREAM_ERROR");
|
|
37127
37472
|
}
|
|
37128
37473
|
if (body.success !== true || !isObject2(body.data) || body.data.query !== query || !Array.isArray(body.data.items) || body.data.items.length > topK)
|
|
37129
|
-
throw
|
|
37474
|
+
throw invalid2();
|
|
37130
37475
|
const ids = /* @__PURE__ */ new Set();
|
|
37131
37476
|
let contentLength = 0;
|
|
37132
37477
|
const items = body.data.items.map((item) => {
|
|
@@ -37137,28 +37482,28 @@ function parseResponse(body, query, topK) {
|
|
|
37137
37482
|
"snippet",
|
|
37138
37483
|
"doc"
|
|
37139
37484
|
].includes(item.contentSource))
|
|
37140
|
-
throw
|
|
37485
|
+
throw invalid2();
|
|
37141
37486
|
if (ids.has(item.id))
|
|
37142
|
-
throw
|
|
37487
|
+
throw invalid2();
|
|
37143
37488
|
ids.add(item.id);
|
|
37144
37489
|
contentLength += [...item.content].length;
|
|
37145
37490
|
if (contentLength > 2e4)
|
|
37146
|
-
throw
|
|
37491
|
+
throw invalid2();
|
|
37147
37492
|
if (item.url !== void 0) {
|
|
37148
37493
|
if (typeof item.url !== "string" || item.url.length > 4096)
|
|
37149
|
-
throw
|
|
37494
|
+
throw invalid2();
|
|
37150
37495
|
try {
|
|
37151
37496
|
if (!["http:", "https:"].includes(new URL(item.url).protocol))
|
|
37152
|
-
throw
|
|
37497
|
+
throw invalid2();
|
|
37153
37498
|
} catch {
|
|
37154
|
-
throw
|
|
37499
|
+
throw invalid2();
|
|
37155
37500
|
}
|
|
37156
37501
|
}
|
|
37157
37502
|
if (item.channel !== void 0 && !isText(item.channel, 64))
|
|
37158
|
-
throw
|
|
37503
|
+
throw invalid2();
|
|
37159
37504
|
if (item.publishedAt !== void 0) {
|
|
37160
37505
|
if (typeof item.publishedAt !== "string" || !Number.isFinite(Date.parse(item.publishedAt)) || new Date(item.publishedAt).toISOString() !== item.publishedAt)
|
|
37161
|
-
throw
|
|
37506
|
+
throw invalid2();
|
|
37162
37507
|
}
|
|
37163
37508
|
return {
|
|
37164
37509
|
id: item.id,
|
|
@@ -37180,8 +37525,8 @@ import path from "node:path";
|
|
|
37180
37525
|
import { fileURLToPath } from "node:url";
|
|
37181
37526
|
|
|
37182
37527
|
// ../../node_modules/fflate/esm/index.mjs
|
|
37183
|
-
import { createRequire
|
|
37184
|
-
var require2 =
|
|
37528
|
+
import { createRequire } from "module";
|
|
37529
|
+
var require2 = createRequire("/");
|
|
37185
37530
|
var _a;
|
|
37186
37531
|
var Worker2;
|
|
37187
37532
|
var isMarkedAsUntransferable;
|
|
@@ -39325,6 +39670,7 @@ export {
|
|
|
39325
39670
|
createKnowledgeTools,
|
|
39326
39671
|
NoopWebSearchPort,
|
|
39327
39672
|
EventObservationRegistry,
|
|
39673
|
+
createGatewayRunAuthorization,
|
|
39328
39674
|
abortableDelay,
|
|
39329
39675
|
RemoteGatewayMcpServerProvider,
|
|
39330
39676
|
LinkqueKnowledgeSearchPort,
|