linkque-cli-v2 1.6.3 → 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 +1015 -631
- 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-ZRFVXCIT.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-MK4MI4S5.js → chunk-UZS5YLV2.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-4VLP3ODV.js → chunk-VBERH5QM.js} +404 -59
- 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 +181 -60
- 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 +348 -89
- 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-4VLP3ODV.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;
|
|
@@ -29313,7 +29313,9 @@ var REDACTED_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
|
29313
29313
|
"x-signature-content",
|
|
29314
29314
|
"x-alipay-sdk-version",
|
|
29315
29315
|
"x-alipay-authcode",
|
|
29316
|
-
"anthropic-api-key"
|
|
29316
|
+
"anthropic-api-key",
|
|
29317
|
+
"x-linkque-runtime-mac",
|
|
29318
|
+
"x-linkque-run-proof"
|
|
29317
29319
|
]);
|
|
29318
29320
|
var REDACTED_VALUE = "ak***";
|
|
29319
29321
|
var RESPONSE_CORRELATION_HEADER_NAMES = [
|
|
@@ -29768,20 +29770,20 @@ function toWebSearchFailure(error) {
|
|
|
29768
29770
|
return { code: safe.code, message: safe.message, retryable: safe.retryable };
|
|
29769
29771
|
}
|
|
29770
29772
|
function parseWebSearchArgs(args) {
|
|
29771
|
-
const
|
|
29773
|
+
const invalid2 = () => new WebSearchError("WEB_SEARCH_INVALID_ARGS");
|
|
29772
29774
|
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
29773
|
-
throw
|
|
29775
|
+
throw invalid2();
|
|
29774
29776
|
const value = args;
|
|
29775
29777
|
if (Object.keys(value).some((key) => key !== "query" && key !== "topK"))
|
|
29776
|
-
throw
|
|
29778
|
+
throw invalid2();
|
|
29777
29779
|
if (typeof value.query !== "string")
|
|
29778
|
-
throw
|
|
29780
|
+
throw invalid2();
|
|
29779
29781
|
const query = value.query.trim();
|
|
29780
29782
|
if (!query || [...query].length > WEB_SEARCH_QUERY_MAX_LENGTH)
|
|
29781
|
-
throw
|
|
29783
|
+
throw invalid2();
|
|
29782
29784
|
const topK = value.topK;
|
|
29783
29785
|
if (topK !== void 0 && (typeof topK !== "number" || !Number.isInteger(topK) || topK < 1 || topK > WEB_SEARCH_TOP_K_MAX))
|
|
29784
|
-
throw
|
|
29786
|
+
throw invalid2();
|
|
29785
29787
|
return { query, ...topK !== void 0 ? { topK } : {} };
|
|
29786
29788
|
}
|
|
29787
29789
|
function throwIfWebSearchAborted(signal) {
|
|
@@ -31200,6 +31202,189 @@ function encodeConversationSseEvent(event) {
|
|
|
31200
31202
|
`;
|
|
31201
31203
|
}
|
|
31202
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
|
+
|
|
31203
31388
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
31204
31389
|
function isZ4Schema(s) {
|
|
31205
31390
|
const schema = s;
|
|
@@ -32849,6 +33034,9 @@ var Protocol = class {
|
|
|
32849
33034
|
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
32850
33035
|
const handleTaskResult = async () => {
|
|
32851
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
|
+
}
|
|
32852
33040
|
if (this._taskMessageQueue) {
|
|
32853
33041
|
let queuedMessage;
|
|
32854
33042
|
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
@@ -32879,12 +33067,12 @@ var Protocol = class {
|
|
|
32879
33067
|
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
32880
33068
|
}
|
|
32881
33069
|
if (!isTerminal(task.status)) {
|
|
32882
|
-
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
33070
|
+
await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
|
|
32883
33071
|
return await handleTaskResult();
|
|
32884
33072
|
}
|
|
32885
33073
|
if (isTerminal(task.status)) {
|
|
32886
33074
|
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
32887
|
-
this._clearTaskQueue(taskId);
|
|
33075
|
+
this._clearTaskQueue(taskId, extra.sessionId);
|
|
32888
33076
|
return {
|
|
32889
33077
|
...result,
|
|
32890
33078
|
_meta: {
|
|
@@ -32921,7 +33109,7 @@ var Protocol = class {
|
|
|
32921
33109
|
throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
32922
33110
|
}
|
|
32923
33111
|
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
32924
|
-
this._clearTaskQueue(request.params.taskId);
|
|
33112
|
+
this._clearTaskQueue(request.params.taskId, extra.sessionId);
|
|
32925
33113
|
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
32926
33114
|
if (!cancelledTask) {
|
|
32927
33115
|
throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
@@ -33049,6 +33237,19 @@ var Protocol = class {
|
|
|
33049
33237
|
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
33050
33238
|
const capturedTransport = this._transport;
|
|
33051
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
|
+
}
|
|
33052
33253
|
if (handler === void 0) {
|
|
33053
33254
|
const errorResponse = {
|
|
33054
33255
|
jsonrpc: "2.0",
|
|
@@ -33058,7 +33259,10 @@ var Protocol = class {
|
|
|
33058
33259
|
message: "Method not found"
|
|
33059
33260
|
}
|
|
33060
33261
|
};
|
|
33061
|
-
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) {
|
|
33062
33266
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
33063
33267
|
type: "error",
|
|
33064
33268
|
message: errorResponse,
|
|
@@ -33109,7 +33313,10 @@ var Protocol = class {
|
|
|
33109
33313
|
closeSSEStream: extra?.closeSSEStream,
|
|
33110
33314
|
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
33111
33315
|
};
|
|
33112
|
-
Promise.resolve().then(() => {
|
|
33316
|
+
(relatedTaskLookup ?? Promise.resolve()).then(() => {
|
|
33317
|
+
if (relatedTaskLookup && abortController.signal.aborted) {
|
|
33318
|
+
throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
|
|
33319
|
+
}
|
|
33113
33320
|
if (taskCreationParams) {
|
|
33114
33321
|
this.assertTaskHandlerCapability(request.method);
|
|
33115
33322
|
}
|
|
@@ -33144,7 +33351,7 @@ var Protocol = class {
|
|
|
33144
33351
|
...error["data"] !== void 0 && { data: error["data"] }
|
|
33145
33352
|
}
|
|
33146
33353
|
};
|
|
33147
|
-
if (relatedTaskId && this._taskMessageQueue) {
|
|
33354
|
+
if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
|
|
33148
33355
|
await this._enqueueTaskMessage(relatedTaskId, {
|
|
33149
33356
|
type: "error",
|
|
33150
33357
|
message: errorResponse,
|
|
@@ -33624,7 +33831,7 @@ var Protocol = class {
|
|
|
33624
33831
|
throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
33625
33832
|
}
|
|
33626
33833
|
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
33627
|
-
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
33834
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
|
|
33628
33835
|
}
|
|
33629
33836
|
/**
|
|
33630
33837
|
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
@@ -33653,12 +33860,13 @@ var Protocol = class {
|
|
|
33653
33860
|
* Uses polling to check for updates at the task's configured poll interval.
|
|
33654
33861
|
* @param taskId The task ID to wait for
|
|
33655
33862
|
* @param signal Abort signal to cancel the wait
|
|
33863
|
+
* @param sessionId Session of the request that waits, passed to the task store
|
|
33656
33864
|
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
33657
33865
|
*/
|
|
33658
|
-
async _waitForTaskUpdate(taskId, signal) {
|
|
33866
|
+
async _waitForTaskUpdate(taskId, signal, sessionId) {
|
|
33659
33867
|
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
33660
33868
|
try {
|
|
33661
|
-
const task = await this._taskStore?.getTask(taskId);
|
|
33869
|
+
const task = await this._taskStore?.getTask(taskId, sessionId);
|
|
33662
33870
|
if (task?.pollInterval) {
|
|
33663
33871
|
interval = task.pollInterval;
|
|
33664
33872
|
}
|
|
@@ -35293,6 +35501,68 @@ function createFetchWithInit(baseFetch = fetch, baseInit) {
|
|
|
35293
35501
|
return baseFetch(url2, mergedInit);
|
|
35294
35502
|
};
|
|
35295
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
|
+
}
|
|
35296
35566
|
|
|
35297
35567
|
// ../../node_modules/pkce-challenge/dist/index.node.js
|
|
35298
35568
|
var crypto;
|
|
@@ -35307,8 +35577,8 @@ async function random(size) {
|
|
|
35307
35577
|
const evenDistCutoff = Math.pow(2, 8) - Math.pow(2, 8) % mask.length;
|
|
35308
35578
|
let result = "";
|
|
35309
35579
|
while (result.length < size) {
|
|
35310
|
-
const
|
|
35311
|
-
for (const randomByte of
|
|
35580
|
+
const randomBytes2 = await getRandomValues(size - result.length);
|
|
35581
|
+
for (const randomByte of randomBytes2) {
|
|
35312
35582
|
if (randomByte < evenDistCutoff) {
|
|
35313
35583
|
result += mask[randomByte % mask.length];
|
|
35314
35584
|
}
|
|
@@ -35439,7 +35709,12 @@ var OAuthTokensSchema = object({
|
|
|
35439
35709
|
token_type: string(),
|
|
35440
35710
|
expires_in: coerce_exports.number().optional(),
|
|
35441
35711
|
scope: string().optional(),
|
|
35442
|
-
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)
|
|
35443
35718
|
}).strip();
|
|
35444
35719
|
var OAuthErrorResponseSchema = object({
|
|
35445
35720
|
error: string(),
|
|
@@ -35469,7 +35744,12 @@ var OAuthClientInformationSchema = object({
|
|
|
35469
35744
|
client_id: string(),
|
|
35470
35745
|
client_secret: string().optional(),
|
|
35471
35746
|
client_id_issued_at: number().optional(),
|
|
35472
|
-
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)
|
|
35473
35753
|
}).strip();
|
|
35474
35754
|
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
35475
35755
|
var OAuthClientRegistrationErrorSchema = object({
|
|
@@ -35667,10 +35947,31 @@ async function parseErrorResponse(input) {
|
|
|
35667
35947
|
const errorClass = OAUTH_ERRORS[error] || ServerError;
|
|
35668
35948
|
return new errorClass(error_description || "", error_uri);
|
|
35669
35949
|
} catch (error) {
|
|
35670
|
-
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}`}`;
|
|
35671
35952
|
return new ServerError(errorMessage2);
|
|
35672
35953
|
}
|
|
35673
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
|
+
}
|
|
35674
35975
|
async function auth(provider, options) {
|
|
35675
35976
|
try {
|
|
35676
35977
|
return await authInternal(provider, options);
|
|
@@ -35724,9 +36025,24 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35724
36025
|
authorizationServerMetadata: metadata
|
|
35725
36026
|
});
|
|
35726
36027
|
}
|
|
35727
|
-
const
|
|
36028
|
+
const issuer = String(authorizationServerUrl);
|
|
36029
|
+
const selectedResource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
36030
|
+
const resource = selectedResource && resourceMetadata && !provider.validateResourceURL ? resourceMetadata.resource : selectedResource;
|
|
35728
36031
|
const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
|
|
35729
|
-
|
|
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
|
+
};
|
|
35730
36046
|
if (!clientInformation) {
|
|
35731
36047
|
if (authorizationCode !== void 0) {
|
|
35732
36048
|
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
@@ -35738,9 +36054,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35738
36054
|
}
|
|
35739
36055
|
const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl;
|
|
35740
36056
|
if (shouldUseUrlBasedClientId) {
|
|
35741
|
-
clientInformation = {
|
|
35742
|
-
client_id: clientMetadataUrl
|
|
35743
|
-
};
|
|
36057
|
+
clientInformation = { client_id: clientMetadataUrl, issuer };
|
|
35744
36058
|
await provider.saveClientInformation?.(clientInformation);
|
|
35745
36059
|
} else {
|
|
35746
36060
|
if (!provider.saveClientInformation) {
|
|
@@ -35752,8 +36066,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35752
36066
|
scope: resolvedScope,
|
|
35753
36067
|
fetchFn
|
|
35754
36068
|
});
|
|
35755
|
-
|
|
35756
|
-
clientInformation
|
|
36069
|
+
clientInformation = { ...fullInformation, issuer };
|
|
36070
|
+
await provider.saveClientInformation(clientInformation);
|
|
35757
36071
|
}
|
|
35758
36072
|
}
|
|
35759
36073
|
const nonInteractiveFlow = !provider.redirectUrl;
|
|
@@ -35764,10 +36078,14 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35764
36078
|
authorizationCode,
|
|
35765
36079
|
fetchFn
|
|
35766
36080
|
});
|
|
35767
|
-
await
|
|
36081
|
+
await bindClientInformation();
|
|
36082
|
+
await provider.saveTokens({ ...tokens2, issuer });
|
|
35768
36083
|
return "AUTHORIZED";
|
|
35769
36084
|
}
|
|
35770
|
-
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
|
+
}
|
|
35771
36089
|
if (tokens?.refresh_token) {
|
|
35772
36090
|
try {
|
|
35773
36091
|
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
@@ -35778,7 +36096,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
35778
36096
|
addClientAuthentication: provider.addClientAuthentication,
|
|
35779
36097
|
fetchFn
|
|
35780
36098
|
});
|
|
35781
|
-
await
|
|
36099
|
+
await bindClientInformation();
|
|
36100
|
+
await provider.saveTokens({ ...newTokens, issuer });
|
|
35782
36101
|
return "AUTHORIZED";
|
|
35783
36102
|
} catch (error) {
|
|
35784
36103
|
if (!(error instanceof OAuthError) || error instanceof ServerError) {
|
|
@@ -35877,7 +36196,7 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn =
|
|
|
35877
36196
|
}
|
|
35878
36197
|
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
35879
36198
|
try {
|
|
35880
|
-
return await fetchFn(url2, { headers });
|
|
36199
|
+
return await fetchWithinOrigin(fetchFn)(url2, { headers });
|
|
35881
36200
|
} catch (error) {
|
|
35882
36201
|
if (error instanceof TypeError) {
|
|
35883
36202
|
if (headers) {
|
|
@@ -35902,7 +36221,7 @@ async function tryMetadataDiscovery(url2, protocolVersion, fetchFn = fetch) {
|
|
|
35902
36221
|
return await fetchWithCorsRetry(url2, headers, fetchFn);
|
|
35903
36222
|
}
|
|
35904
36223
|
function shouldAttemptFallback(response, pathname) {
|
|
35905
|
-
return !response || response.
|
|
36224
|
+
return !response || !response.ok && response.status < 500 && pathname !== "/";
|
|
35906
36225
|
}
|
|
35907
36226
|
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
35908
36227
|
const issuer = new URL(serverUrl);
|
|
@@ -35968,7 +36287,7 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
35968
36287
|
}
|
|
35969
36288
|
if (!response.ok) {
|
|
35970
36289
|
await response.body?.cancel();
|
|
35971
|
-
if (response.status
|
|
36290
|
+
if (response.status < 500) {
|
|
35972
36291
|
continue;
|
|
35973
36292
|
}
|
|
35974
36293
|
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
@@ -36001,6 +36320,9 @@ async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
|
36001
36320
|
resourceMetadata
|
|
36002
36321
|
};
|
|
36003
36322
|
}
|
|
36323
|
+
function resourceIndicatorToString(resource) {
|
|
36324
|
+
return typeof resource === "string" ? resource : resource.href;
|
|
36325
|
+
}
|
|
36004
36326
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
|
|
36005
36327
|
let authorizationUrl;
|
|
36006
36328
|
if (metadata) {
|
|
@@ -36032,7 +36354,7 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
|
|
|
36032
36354
|
authorizationUrl.searchParams.append("prompt", "consent");
|
|
36033
36355
|
}
|
|
36034
36356
|
if (resource) {
|
|
36035
|
-
authorizationUrl.searchParams.set("resource", resource
|
|
36357
|
+
authorizationUrl.searchParams.set("resource", resourceIndicatorToString(resource));
|
|
36036
36358
|
}
|
|
36037
36359
|
return { authorizationUrl, codeVerifier };
|
|
36038
36360
|
}
|
|
@@ -36051,7 +36373,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
36051
36373
|
Accept: "application/json"
|
|
36052
36374
|
});
|
|
36053
36375
|
if (resource) {
|
|
36054
|
-
tokenRequestParams.set("resource", resource
|
|
36376
|
+
tokenRequestParams.set("resource", resourceIndicatorToString(resource));
|
|
36055
36377
|
}
|
|
36056
36378
|
if (addClientAuthentication) {
|
|
36057
36379
|
await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
|
|
@@ -36060,7 +36382,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
36060
36382
|
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
36061
36383
|
applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams);
|
|
36062
36384
|
}
|
|
36063
|
-
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
36385
|
+
const response = await fetchWithinOrigin(fetchFn ?? fetch)(tokenUrl, {
|
|
36064
36386
|
method: "POST",
|
|
36065
36387
|
headers,
|
|
36066
36388
|
body: tokenRequestParams
|
|
@@ -36068,7 +36390,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
36068
36390
|
if (!response.ok) {
|
|
36069
36391
|
throw await parseErrorResponse(response);
|
|
36070
36392
|
}
|
|
36071
|
-
return
|
|
36393
|
+
return TokenResponseSchema.parse(await response.json());
|
|
36072
36394
|
}
|
|
36073
36395
|
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
36074
36396
|
const tokenRequestParams = new URLSearchParams({
|
|
@@ -36086,6 +36408,15 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
|
|
|
36086
36408
|
return { refresh_token: refreshToken, ...tokens };
|
|
36087
36409
|
}
|
|
36088
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();
|
|
36089
36420
|
const scope = provider.clientMetadata.scope;
|
|
36090
36421
|
let tokenRequestParams;
|
|
36091
36422
|
if (provider.prepareTokenRequest) {
|
|
@@ -36101,11 +36432,11 @@ async function fetchToken(provider, authorizationServerUrl, { metadata, resource
|
|
|
36101
36432
|
const codeVerifier = await provider.codeVerifier();
|
|
36102
36433
|
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
|
|
36103
36434
|
}
|
|
36104
|
-
|
|
36435
|
+
clientInformation ?? (clientInformation = await readClientInformation());
|
|
36105
36436
|
return executeTokenRequest(authorizationServerUrl, {
|
|
36106
36437
|
metadata,
|
|
36107
36438
|
tokenRequestParams,
|
|
36108
|
-
clientInformation
|
|
36439
|
+
clientInformation,
|
|
36109
36440
|
addClientAuthentication: provider.addClientAuthentication,
|
|
36110
36441
|
resource,
|
|
36111
36442
|
fetchFn
|
|
@@ -36121,7 +36452,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
36121
36452
|
} else {
|
|
36122
36453
|
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
36123
36454
|
}
|
|
36124
|
-
const response = await (fetchFn ?? fetch)(registrationUrl, {
|
|
36455
|
+
const response = await fetchWithinOrigin(fetchFn ?? fetch)(registrationUrl, {
|
|
36125
36456
|
method: "POST",
|
|
36126
36457
|
headers: {
|
|
36127
36458
|
"Content-Type": "application/json"
|
|
@@ -36134,7 +36465,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
36134
36465
|
if (!response.ok) {
|
|
36135
36466
|
throw await parseErrorResponse(response);
|
|
36136
36467
|
}
|
|
36137
|
-
return
|
|
36468
|
+
return RegistrationResponseSchema.parse(await response.json());
|
|
36138
36469
|
}
|
|
36139
36470
|
|
|
36140
36471
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
@@ -36155,6 +36486,16 @@ var SSEClientTransport = class {
|
|
|
36155
36486
|
this._authProvider = opts?.authProvider;
|
|
36156
36487
|
this._fetch = opts?.fetch;
|
|
36157
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;
|
|
36158
36499
|
}
|
|
36159
36500
|
async _authThenStart() {
|
|
36160
36501
|
if (!this._authProvider) {
|
|
@@ -36195,7 +36536,9 @@ var SSEClientTransport = class {
|
|
|
36195
36536
|
});
|
|
36196
36537
|
}
|
|
36197
36538
|
_startOrAuth() {
|
|
36198
|
-
const
|
|
36539
|
+
const baseFetch = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
36540
|
+
const fetchImpl = this._followRedirects ? baseFetch : fetchWithinOrigin(baseFetch);
|
|
36541
|
+
let redirect;
|
|
36199
36542
|
return new Promise((resolve, reject) => {
|
|
36200
36543
|
this._eventSource = new EventSource(this._url.href, {
|
|
36201
36544
|
...this._eventSourceInit,
|
|
@@ -36206,6 +36549,7 @@ var SSEClientTransport = class {
|
|
|
36206
36549
|
...init,
|
|
36207
36550
|
headers
|
|
36208
36551
|
});
|
|
36552
|
+
redirect = this._unfollowedRedirect(response, url2);
|
|
36209
36553
|
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
36210
36554
|
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
36211
36555
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
@@ -36220,7 +36564,7 @@ var SSEClientTransport = class {
|
|
|
36220
36564
|
this._authThenStart().then(resolve, reject);
|
|
36221
36565
|
return;
|
|
36222
36566
|
}
|
|
36223
|
-
const error = new SseError(event.code, event.message, event);
|
|
36567
|
+
const error = new SseError(event.code, redirect ?? event.message, event);
|
|
36224
36568
|
reject(error);
|
|
36225
36569
|
this.onerror?.(error);
|
|
36226
36570
|
};
|
|
@@ -36297,7 +36641,7 @@ var SSEClientTransport = class {
|
|
|
36297
36641
|
body: JSON.stringify(message),
|
|
36298
36642
|
signal: this._abortController?.signal
|
|
36299
36643
|
};
|
|
36300
|
-
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
36644
|
+
const response = await fetchWithinOrigin(this._fetch ?? fetch)(this._endpoint, init);
|
|
36301
36645
|
if (!response.ok) {
|
|
36302
36646
|
const text = await response.text().catch(() => null);
|
|
36303
36647
|
if (response.status === 401 && this._authProvider) {
|
|
@@ -36315,7 +36659,7 @@ var SSEClientTransport = class {
|
|
|
36315
36659
|
}
|
|
36316
36660
|
return this.send(message);
|
|
36317
36661
|
}
|
|
36318
|
-
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}`);
|
|
36319
36663
|
}
|
|
36320
36664
|
await response.body?.cancel();
|
|
36321
36665
|
} catch (error) {
|
|
@@ -37107,9 +37451,9 @@ function isText(value, max2) {
|
|
|
37107
37451
|
return typeof value === "string" && !!value.trim() && [...value].length <= max2;
|
|
37108
37452
|
}
|
|
37109
37453
|
function parseResponse(body, query, topK) {
|
|
37110
|
-
const
|
|
37454
|
+
const invalid2 = () => new WebSearchError("WEB_SEARCH_INVALID_RESPONSE");
|
|
37111
37455
|
if (!isObject2(body))
|
|
37112
|
-
throw
|
|
37456
|
+
throw invalid2();
|
|
37113
37457
|
if (body.success === false) {
|
|
37114
37458
|
const code = body.errorCode;
|
|
37115
37459
|
if (code === "UNAUTHORIZED")
|
|
@@ -37127,7 +37471,7 @@ function parseResponse(body, query, topK) {
|
|
|
37127
37471
|
throw new WebSearchError(supported.includes(code) ? code : "WEB_SEARCH_UPSTREAM_ERROR");
|
|
37128
37472
|
}
|
|
37129
37473
|
if (body.success !== true || !isObject2(body.data) || body.data.query !== query || !Array.isArray(body.data.items) || body.data.items.length > topK)
|
|
37130
|
-
throw
|
|
37474
|
+
throw invalid2();
|
|
37131
37475
|
const ids = /* @__PURE__ */ new Set();
|
|
37132
37476
|
let contentLength = 0;
|
|
37133
37477
|
const items = body.data.items.map((item) => {
|
|
@@ -37138,28 +37482,28 @@ function parseResponse(body, query, topK) {
|
|
|
37138
37482
|
"snippet",
|
|
37139
37483
|
"doc"
|
|
37140
37484
|
].includes(item.contentSource))
|
|
37141
|
-
throw
|
|
37485
|
+
throw invalid2();
|
|
37142
37486
|
if (ids.has(item.id))
|
|
37143
|
-
throw
|
|
37487
|
+
throw invalid2();
|
|
37144
37488
|
ids.add(item.id);
|
|
37145
37489
|
contentLength += [...item.content].length;
|
|
37146
37490
|
if (contentLength > 2e4)
|
|
37147
|
-
throw
|
|
37491
|
+
throw invalid2();
|
|
37148
37492
|
if (item.url !== void 0) {
|
|
37149
37493
|
if (typeof item.url !== "string" || item.url.length > 4096)
|
|
37150
|
-
throw
|
|
37494
|
+
throw invalid2();
|
|
37151
37495
|
try {
|
|
37152
37496
|
if (!["http:", "https:"].includes(new URL(item.url).protocol))
|
|
37153
|
-
throw
|
|
37497
|
+
throw invalid2();
|
|
37154
37498
|
} catch {
|
|
37155
|
-
throw
|
|
37499
|
+
throw invalid2();
|
|
37156
37500
|
}
|
|
37157
37501
|
}
|
|
37158
37502
|
if (item.channel !== void 0 && !isText(item.channel, 64))
|
|
37159
|
-
throw
|
|
37503
|
+
throw invalid2();
|
|
37160
37504
|
if (item.publishedAt !== void 0) {
|
|
37161
37505
|
if (typeof item.publishedAt !== "string" || !Number.isFinite(Date.parse(item.publishedAt)) || new Date(item.publishedAt).toISOString() !== item.publishedAt)
|
|
37162
|
-
throw
|
|
37506
|
+
throw invalid2();
|
|
37163
37507
|
}
|
|
37164
37508
|
return {
|
|
37165
37509
|
id: item.id,
|
|
@@ -39326,6 +39670,7 @@ export {
|
|
|
39326
39670
|
createKnowledgeTools,
|
|
39327
39671
|
NoopWebSearchPort,
|
|
39328
39672
|
EventObservationRegistry,
|
|
39673
|
+
createGatewayRunAuthorization,
|
|
39329
39674
|
abortableDelay,
|
|
39330
39675
|
RemoteGatewayMcpServerProvider,
|
|
39331
39676
|
LinkqueKnowledgeSearchPort,
|