linkque-cli-v2 1.6.5 → 1.6.6
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-IATVK6CO.js → chunk-FC6S43DG.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-UTJ7DVT7.js → chunk-FH2M6YD6.js} +407 -59
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-YZLXAZFT.js → chunk-ICPH34ZQ.js} +36 -11
- 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-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 -71
- 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 +357 -94
- 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/worker.js
CHANGED
|
@@ -15367,7 +15367,9 @@ var init_httpLoggingFetch = __esm({
|
|
|
15367
15367
|
"x-signature-content",
|
|
15368
15368
|
"x-alipay-sdk-version",
|
|
15369
15369
|
"x-alipay-authcode",
|
|
15370
|
-
"anthropic-api-key"
|
|
15370
|
+
"anthropic-api-key",
|
|
15371
|
+
"x-linkque-runtime-mac",
|
|
15372
|
+
"x-linkque-run-proof"
|
|
15371
15373
|
]);
|
|
15372
15374
|
REDACTED_VALUE = "ak***";
|
|
15373
15375
|
RESPONSE_CORRELATION_HEADER_NAMES = [
|
|
@@ -69892,64 +69894,50 @@ var require_common2 = __commonJS({
|
|
|
69892
69894
|
createDebug.namespaces = namespaces;
|
|
69893
69895
|
createDebug.names = [];
|
|
69894
69896
|
createDebug.skips = [];
|
|
69895
|
-
|
|
69896
|
-
|
|
69897
|
-
|
|
69898
|
-
|
|
69899
|
-
|
|
69900
|
-
|
|
69897
|
+
let i2;
|
|
69898
|
+
const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
|
|
69899
|
+
const len = split.length;
|
|
69900
|
+
for (i2 = 0; i2 < len; i2++) {
|
|
69901
|
+
if (!split[i2]) {
|
|
69902
|
+
continue;
|
|
69901
69903
|
}
|
|
69902
|
-
|
|
69903
|
-
|
|
69904
|
-
|
|
69905
|
-
let searchIndex = 0;
|
|
69906
|
-
let templateIndex = 0;
|
|
69907
|
-
let starIndex = -1;
|
|
69908
|
-
let matchIndex = 0;
|
|
69909
|
-
while (searchIndex < search3.length) {
|
|
69910
|
-
if (templateIndex < template.length && (template[templateIndex] === search3[searchIndex] || template[templateIndex] === "*")) {
|
|
69911
|
-
if (template[templateIndex] === "*") {
|
|
69912
|
-
starIndex = templateIndex;
|
|
69913
|
-
matchIndex = searchIndex;
|
|
69914
|
-
templateIndex++;
|
|
69915
|
-
} else {
|
|
69916
|
-
searchIndex++;
|
|
69917
|
-
templateIndex++;
|
|
69918
|
-
}
|
|
69919
|
-
} else if (starIndex !== -1) {
|
|
69920
|
-
templateIndex = starIndex + 1;
|
|
69921
|
-
matchIndex++;
|
|
69922
|
-
searchIndex = matchIndex;
|
|
69904
|
+
namespaces = split[i2].replace(/\*/g, ".*?");
|
|
69905
|
+
if (namespaces[0] === "-") {
|
|
69906
|
+
createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
|
|
69923
69907
|
} else {
|
|
69924
|
-
|
|
69908
|
+
createDebug.names.push(new RegExp("^" + namespaces + "$"));
|
|
69925
69909
|
}
|
|
69926
69910
|
}
|
|
69927
|
-
while (templateIndex < template.length && template[templateIndex] === "*") {
|
|
69928
|
-
templateIndex++;
|
|
69929
|
-
}
|
|
69930
|
-
return templateIndex === template.length;
|
|
69931
69911
|
}
|
|
69932
69912
|
function disable() {
|
|
69933
69913
|
const namespaces = [
|
|
69934
|
-
...createDebug.names,
|
|
69935
|
-
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
69914
|
+
...createDebug.names.map(toNamespace),
|
|
69915
|
+
...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
|
|
69936
69916
|
].join(",");
|
|
69937
69917
|
createDebug.enable("");
|
|
69938
69918
|
return namespaces;
|
|
69939
69919
|
}
|
|
69940
69920
|
function enabled(name) {
|
|
69941
|
-
|
|
69942
|
-
|
|
69921
|
+
if (name[name.length - 1] === "*") {
|
|
69922
|
+
return true;
|
|
69923
|
+
}
|
|
69924
|
+
let i2;
|
|
69925
|
+
let len;
|
|
69926
|
+
for (i2 = 0, len = createDebug.skips.length; i2 < len; i2++) {
|
|
69927
|
+
if (createDebug.skips[i2].test(name)) {
|
|
69943
69928
|
return false;
|
|
69944
69929
|
}
|
|
69945
69930
|
}
|
|
69946
|
-
for (
|
|
69947
|
-
if (
|
|
69931
|
+
for (i2 = 0, len = createDebug.names.length; i2 < len; i2++) {
|
|
69932
|
+
if (createDebug.names[i2].test(name)) {
|
|
69948
69933
|
return true;
|
|
69949
69934
|
}
|
|
69950
69935
|
}
|
|
69951
69936
|
return false;
|
|
69952
69937
|
}
|
|
69938
|
+
function toNamespace(regexp) {
|
|
69939
|
+
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
|
|
69940
|
+
}
|
|
69953
69941
|
function coerce2(val) {
|
|
69954
69942
|
if (val instanceof Error) {
|
|
69955
69943
|
return val.stack || val.message;
|
|
@@ -70068,11 +70056,10 @@ var require_browser = __commonJS({
|
|
|
70068
70056
|
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
70069
70057
|
return false;
|
|
70070
70058
|
}
|
|
70071
|
-
let m2;
|
|
70072
70059
|
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
70073
70060
|
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
70074
70061
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
70075
|
-
typeof navigator !== "undefined" && navigator.userAgent &&
|
|
70062
|
+
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
70076
70063
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
70077
70064
|
}
|
|
70078
70065
|
function formatArgs(args) {
|
|
@@ -70110,7 +70097,7 @@ var require_browser = __commonJS({
|
|
|
70110
70097
|
function load() {
|
|
70111
70098
|
let r2;
|
|
70112
70099
|
try {
|
|
70113
|
-
r2 = exports2.storage.getItem("debug")
|
|
70100
|
+
r2 = exports2.storage.getItem("debug");
|
|
70114
70101
|
} catch (error40) {
|
|
70115
70102
|
}
|
|
70116
70103
|
if (!r2 && typeof process !== "undefined" && "env" in process) {
|
|
@@ -70393,7 +70380,7 @@ var require_node5 = __commonJS({
|
|
|
70393
70380
|
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
70394
70381
|
}
|
|
70395
70382
|
function log(...args) {
|
|
70396
|
-
return process.stderr.write(util2.
|
|
70383
|
+
return process.stderr.write(util2.format(...args) + "\n");
|
|
70397
70384
|
}
|
|
70398
70385
|
function save(namespaces) {
|
|
70399
70386
|
if (namespaces) {
|
|
@@ -89878,11 +89865,23 @@ var require_websocket = __commonJS({
|
|
|
89878
89865
|
this._isServer = false;
|
|
89879
89866
|
this._redirects = 0;
|
|
89880
89867
|
if (protocols === void 0) {
|
|
89881
|
-
protocols
|
|
89868
|
+
if (!options || options.protocols === void 0) {
|
|
89869
|
+
protocols = [];
|
|
89870
|
+
} else if (Array.isArray(options.protocols)) {
|
|
89871
|
+
protocols = options.protocols;
|
|
89872
|
+
} else {
|
|
89873
|
+
protocols = [options.protocols];
|
|
89874
|
+
}
|
|
89882
89875
|
} else if (!Array.isArray(protocols)) {
|
|
89883
89876
|
if (typeof protocols === "object" && protocols !== null) {
|
|
89884
89877
|
options = protocols;
|
|
89885
|
-
protocols
|
|
89878
|
+
if (options.protocols === void 0) {
|
|
89879
|
+
protocols = [];
|
|
89880
|
+
} else if (Array.isArray(options.protocols)) {
|
|
89881
|
+
protocols = options.protocols;
|
|
89882
|
+
} else {
|
|
89883
|
+
protocols = [options.protocols];
|
|
89884
|
+
}
|
|
89886
89885
|
} else {
|
|
89887
89886
|
protocols = [protocols];
|
|
89888
89887
|
}
|
|
@@ -90079,7 +90078,6 @@ var require_websocket = __commonJS({
|
|
|
90079
90078
|
}
|
|
90080
90079
|
return;
|
|
90081
90080
|
}
|
|
90082
|
-
this._readyState = _WebSocket.CLOSING;
|
|
90083
90081
|
this._sender.close(code, data, !this._isServer, (err3) => {
|
|
90084
90082
|
if (err3) return;
|
|
90085
90083
|
this._closeFrameSent = true;
|
|
@@ -90087,6 +90085,7 @@ var require_websocket = __commonJS({
|
|
|
90087
90085
|
this._socket.end();
|
|
90088
90086
|
}
|
|
90089
90087
|
});
|
|
90088
|
+
this._readyState = _WebSocket.CLOSING;
|
|
90090
90089
|
setCloseTimer(this);
|
|
90091
90090
|
}
|
|
90092
90091
|
/**
|
|
@@ -90311,6 +90310,7 @@ var require_websocket = __commonJS({
|
|
|
90311
90310
|
socketPath: void 0,
|
|
90312
90311
|
hostname: void 0,
|
|
90313
90312
|
protocol: void 0,
|
|
90313
|
+
protocols: void 0,
|
|
90314
90314
|
timeout: void 0,
|
|
90315
90315
|
method: "GET",
|
|
90316
90316
|
host: void 0,
|
|
@@ -206861,6 +206861,55 @@ var init_testProvider = __esm({
|
|
|
206861
206861
|
}
|
|
206862
206862
|
});
|
|
206863
206863
|
|
|
206864
|
+
// ../linkque-agent-runtime/dist/esm/impl/agent/pi/provider/base/transportAnthropicApi.js
|
|
206865
|
+
function createTransportAnthropicApi(modelFetch) {
|
|
206866
|
+
const call = (model, context2, options = {}) => {
|
|
206867
|
+
const client = new Anthropic({
|
|
206868
|
+
baseURL: model.baseUrl,
|
|
206869
|
+
apiKey: options.apiKey ?? null,
|
|
206870
|
+
authToken: null,
|
|
206871
|
+
defaultHeaders: { ...model.headers, ...options.headers },
|
|
206872
|
+
fetch: modelFetch,
|
|
206873
|
+
maxRetries: 0
|
|
206874
|
+
});
|
|
206875
|
+
return stream(model, context2, {
|
|
206876
|
+
...options,
|
|
206877
|
+
client,
|
|
206878
|
+
maxRetries: 0
|
|
206879
|
+
});
|
|
206880
|
+
};
|
|
206881
|
+
const simple = (model, context2, options) => {
|
|
206882
|
+
const base = buildBaseOptions(model, context2, options, options?.apiKey);
|
|
206883
|
+
if (!options?.reasoning)
|
|
206884
|
+
return call(model, context2, { ...base, thinkingEnabled: false });
|
|
206885
|
+
if (model.compat?.forceAdaptiveThinking === true) {
|
|
206886
|
+
const mapped = model.thinkingLevelMap?.[options.reasoning];
|
|
206887
|
+
const effort = typeof mapped === "string" ? mapped : options.reasoning === "minimal" || options.reasoning === "low" ? "low" : options.reasoning === "medium" ? "medium" : "high";
|
|
206888
|
+
return call(model, context2, { ...base, thinkingEnabled: true, effort });
|
|
206889
|
+
}
|
|
206890
|
+
const adjusted = adjustMaxTokensForThinking(base.maxTokens, model.maxTokens, options.reasoning, options.thinkingBudgets);
|
|
206891
|
+
const maxTokens = clampMaxTokensToContext(model, context2, adjusted.maxTokens);
|
|
206892
|
+
return call(model, context2, {
|
|
206893
|
+
...base,
|
|
206894
|
+
thinkingEnabled: true,
|
|
206895
|
+
maxTokens,
|
|
206896
|
+
thinkingBudgetTokens: Math.min(adjusted.thinkingBudget, Math.max(0, maxTokens - 1024))
|
|
206897
|
+
});
|
|
206898
|
+
};
|
|
206899
|
+
return {
|
|
206900
|
+
stream: (m2, c, o) => call(m2, c, o),
|
|
206901
|
+
streamSimple: (m2, c, o) => simple(m2, c, o)
|
|
206902
|
+
};
|
|
206903
|
+
}
|
|
206904
|
+
var init_transportAnthropicApi = __esm({
|
|
206905
|
+
"../linkque-agent-runtime/dist/esm/impl/agent/pi/provider/base/transportAnthropicApi.js"() {
|
|
206906
|
+
"use strict";
|
|
206907
|
+
init_sdk();
|
|
206908
|
+
init_anthropic_messages();
|
|
206909
|
+
init_simple_options();
|
|
206910
|
+
}
|
|
206911
|
+
});
|
|
206912
|
+
|
|
206864
206913
|
// ../linkque-agent-runtime/dist/esm/impl/agent/pi/provider/base/anthropicProvider.js
|
|
206865
206914
|
function createApiKeyAuth(authName, fixedApiKey) {
|
|
206866
206915
|
return {
|
|
@@ -206883,7 +206932,7 @@ function createAnthropicProvider(options) {
|
|
|
206883
206932
|
auth: { apiKey: createApiKeyAuth(authName, fixedApiKey) },
|
|
206884
206933
|
models,
|
|
206885
206934
|
// 复用 pi-ai 内置的 Anthropic Messages 协议实现(含 stream/SSE 逻辑)
|
|
206886
|
-
api: anthropicMessagesApi()
|
|
206935
|
+
api: options.modelFetch ? createTransportAnthropicApi(options.modelFetch) : anthropicMessagesApi()
|
|
206887
206936
|
});
|
|
206888
206937
|
}
|
|
206889
206938
|
function buildAnthropicModel(providerId, baseUrl, descriptor) {
|
|
@@ -206907,6 +206956,7 @@ var init_anthropicProvider = __esm({
|
|
|
206907
206956
|
"../linkque-agent-runtime/dist/esm/impl/agent/pi/provider/base/anthropicProvider.js"() {
|
|
206908
206957
|
"use strict";
|
|
206909
206958
|
init_compat2();
|
|
206959
|
+
init_transportAnthropicApi();
|
|
206910
206960
|
}
|
|
206911
206961
|
});
|
|
206912
206962
|
|
|
@@ -206917,13 +206967,14 @@ function createLinkqueModel(modelId, baseUrl = LINKQUE_DEFAULT_BASE_URL) {
|
|
|
206917
206967
|
id: modelId
|
|
206918
206968
|
});
|
|
206919
206969
|
}
|
|
206920
|
-
function createLinkqueProvider(baseUrl = LINKQUE_DEFAULT_BASE_URL) {
|
|
206970
|
+
function createLinkqueProvider(baseUrl = LINKQUE_DEFAULT_BASE_URL, modelFetch) {
|
|
206921
206971
|
return createAnthropicProvider({
|
|
206922
206972
|
providerId: LINKQUE_PROVIDER_ID,
|
|
206923
206973
|
providerName: "Linkque",
|
|
206924
206974
|
baseUrl,
|
|
206925
206975
|
models: LINKQUE_MODELS,
|
|
206926
|
-
authName: "Linkque API key"
|
|
206976
|
+
authName: "Linkque API key",
|
|
206977
|
+
modelFetch
|
|
206927
206978
|
});
|
|
206928
206979
|
}
|
|
206929
206980
|
var LINKQUE_PROVIDER_ID, LINKQUE_AGENT_ID_HEADER, LINKQUE_RUN_ID_HEADER, LINKQUE_CHAT_ID_HEADER, LINKQUE_USER_ID_HEADER, LINKQUE_REQUEST_SOURCE_HEADER, LINKQUE_DEFAULT_BASE_URL, SANDBOX_AGENT_ACCESS_KEY_PLACEHOLDER, LINKQUE_MODELS, LINKQUE_PASSTHROUGH_DEFAULTS;
|
|
@@ -207240,7 +207291,7 @@ var init_agentService = __esm({
|
|
|
207240
207291
|
async startSession() {
|
|
207241
207292
|
const models = createModels();
|
|
207242
207293
|
const providerId = providerIdFor(this.auth.provider);
|
|
207243
|
-
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl));
|
|
207294
|
+
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl, this.auth.modelFetch));
|
|
207244
207295
|
models.setProvider(createTestProvider().provider);
|
|
207245
207296
|
let model;
|
|
207246
207297
|
if (this.options.model !== void 0) {
|
|
@@ -207454,7 +207505,7 @@ var init_followUpQuestionGenerator = __esm({
|
|
|
207454
207505
|
}
|
|
207455
207506
|
async generate(input) {
|
|
207456
207507
|
const models = this.modelsFactory();
|
|
207457
|
-
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl));
|
|
207508
|
+
models.setProvider(createLinkqueProvider(this.linkqueBaseUrl, input.auth.modelFetch));
|
|
207458
207509
|
let model = models.getModel(LINKQUE_PROVIDER_ID, FOLLOW_UP_QUESTION_MODEL_ID);
|
|
207459
207510
|
model ??= createLinkqueModel(FOLLOW_UP_QUESTION_MODEL_ID, this.linkqueBaseUrl);
|
|
207460
207511
|
model = {
|
|
@@ -208001,6 +208052,29 @@ var init_types12 = __esm({
|
|
|
208001
208052
|
}
|
|
208002
208053
|
});
|
|
208003
208054
|
|
|
208055
|
+
// ../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js
|
|
208056
|
+
async function authorizeAgentRun(runId, identity, port) {
|
|
208057
|
+
if (typeof runId !== "string" || !/^[\x21-\x7e]{1,64}$/u.test(runId) || typeof identity?.userId !== "string" || !/^[\x21-\x7e]{1,128}$/u.test(identity.userId) || typeof identity.agentId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(identity.agentId)) {
|
|
208058
|
+
throw new Error("SCENARIO_RUNTIME_AUTH_INVALID");
|
|
208059
|
+
}
|
|
208060
|
+
const result = await port.authorizeRun({
|
|
208061
|
+
runId,
|
|
208062
|
+
agentId: identity.agentId,
|
|
208063
|
+
appbaseUserId: identity.userId
|
|
208064
|
+
});
|
|
208065
|
+
if (result?.quotaMode === "NORMAL")
|
|
208066
|
+
return { quotaMode: "NORMAL" };
|
|
208067
|
+
if (result?.quotaMode !== "LIMITED" && result?.quotaMode !== "AUTH_ONLY" || typeof result.modelFetch !== "function") {
|
|
208068
|
+
throw new Error("SCENARIO_RUN_UNAVAILABLE");
|
|
208069
|
+
}
|
|
208070
|
+
return result;
|
|
208071
|
+
}
|
|
208072
|
+
var init_scenarioRunAuthorization = __esm({
|
|
208073
|
+
"../linkque-agent-runtime/dist/esm/core/scenarioRunAuthorization.js"() {
|
|
208074
|
+
"use strict";
|
|
208075
|
+
}
|
|
208076
|
+
});
|
|
208077
|
+
|
|
208004
208078
|
// ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
|
|
208005
208079
|
function assertAgentConfigRoot(value, pluginName) {
|
|
208006
208080
|
if (typeof value !== "object" || value === null || !("agent" in value)) {
|
|
@@ -209270,6 +209344,7 @@ var init_agentRuntime = __esm({
|
|
|
209270
209344
|
init_runtimeErrorBoundary();
|
|
209271
209345
|
init_toolObservation();
|
|
209272
209346
|
init_types12();
|
|
209347
|
+
init_scenarioRunAuthorization();
|
|
209273
209348
|
init_esm();
|
|
209274
209349
|
init_types();
|
|
209275
209350
|
init_followUpQuestionGenerator();
|
|
@@ -209449,6 +209524,28 @@ var init_agentRuntime = __esm({
|
|
|
209449
209524
|
}
|
|
209450
209525
|
/** 产出 AgentStreamEvent 流;内核编排「解析上行资源 → 组请求 → agent loop」。 */
|
|
209451
209526
|
async *runAgentLoop(request, auth2, options = {}) {
|
|
209527
|
+
if (options.runAuthorization) {
|
|
209528
|
+
try {
|
|
209529
|
+
const grant = await authorizeAgentRun(request.runId, options.runtimeContext, options.runAuthorization);
|
|
209530
|
+
if (grant.quotaMode !== "NORMAL")
|
|
209531
|
+
auth2 = { ...auth2, modelFetch: grant.modelFetch };
|
|
209532
|
+
} catch (error40) {
|
|
209533
|
+
const reason = error40 instanceof Error ? error40.message : "";
|
|
209534
|
+
const code = [
|
|
209535
|
+
"SCENARIO_TURN_LIMIT",
|
|
209536
|
+
"SCENARIO_RUNTIME_AUTH_INVALID",
|
|
209537
|
+
"SCENARIO_RUNTIME_REPLAY"
|
|
209538
|
+
].includes(reason) ? reason : "SCENARIO_RUN_UNAVAILABLE";
|
|
209539
|
+
yield {
|
|
209540
|
+
type: "error",
|
|
209541
|
+
error: {
|
|
209542
|
+
code,
|
|
209543
|
+
message: code === "SCENARIO_TURN_LIMIT" ? "\u4F53\u9A8C\u5BF9\u8BDD\u6B21\u6570\u5DF2\u7528\u5B8C" : "\u672C\u8F6E\u5BF9\u8BDD\u672A\u83B7\u51C6\u6267\u884C"
|
|
209544
|
+
}
|
|
209545
|
+
};
|
|
209546
|
+
return;
|
|
209547
|
+
}
|
|
209548
|
+
}
|
|
209452
209549
|
const input = {
|
|
209453
209550
|
runId: request.runId,
|
|
209454
209551
|
agentId: options.runtimeContext?.agentId ?? this.agentId,
|
|
@@ -210034,6 +210131,8 @@ async function* runConversation(request, auth2, options = {}) {
|
|
|
210034
210131
|
const ports = options.agentLoop ? { agentLoop: options.agentLoop } : void 0;
|
|
210035
210132
|
const runtime = options.runtime ?? (options.protocol ? AgentRuntime.create(options.protocol, ports) : new AgentRuntime(ports));
|
|
210036
210133
|
const runOptions = {};
|
|
210134
|
+
if (options.runAuthorization)
|
|
210135
|
+
runOptions.runAuthorization = options.runAuthorization;
|
|
210037
210136
|
if (options.sessionId !== void 0)
|
|
210038
210137
|
runOptions.sessionId = options.sessionId;
|
|
210039
210138
|
if (options.cwd !== void 0)
|
|
@@ -210348,6 +210447,7 @@ async function waitForObservation(promise2, signal) {
|
|
|
210348
210447
|
function createImageTool(image, input, options, rules) {
|
|
210349
210448
|
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
210350
210449
|
const auth2 = { ...input.auth };
|
|
210450
|
+
const modelFetch = auth2.modelFetch ?? fetchImpl;
|
|
210351
210451
|
const cache = /* @__PURE__ */ new Map();
|
|
210352
210452
|
let calls = 0;
|
|
210353
210453
|
return {
|
|
@@ -210387,7 +210487,7 @@ function createImageTool(image, input, options, rules) {
|
|
|
210387
210487
|
const pending = (async () => {
|
|
210388
210488
|
try {
|
|
210389
210489
|
const resolved = await resolveImage(image, fetchImpl, rules, signal);
|
|
210390
|
-
const response = await
|
|
210490
|
+
const response = await modelFetch(`${(options.baseUrl ?? RUNTIME_CONFIG_DEFAULTS.LINKQUE_BASE_URL).replace(/\/+$/, "")}/v1/messages`, {
|
|
210391
210491
|
method: "POST",
|
|
210392
210492
|
signal,
|
|
210393
210493
|
redirect: "error",
|
|
@@ -210646,7 +210746,7 @@ var init_imageUnderstandingPlugin = __esm({
|
|
|
210646
210746
|
});
|
|
210647
210747
|
|
|
210648
210748
|
// ../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js
|
|
210649
|
-
var LINKQUEGW_EVENT_PLUGIN_NAME, LINKQUEGW_EVENT_HOOK_RESOURCE_ID, LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID, LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID, LINKQUEGW_RUN_READ_HOOK_RESOURCE_ID, DEFAULT_LINKQUEGW_EVENT_HOOKS, createLinkquegwEventHookResource,
|
|
210749
|
+
var LINKQUEGW_EVENT_PLUGIN_NAME, LINKQUEGW_EVENT_HOOK_RESOURCE_ID, LINKQUEGW_RUN_COMPLETED_HOOK_RESOURCE_ID, LINKQUEGW_RUN_FAILED_HOOK_RESOURCE_ID, LINKQUEGW_RUN_READ_HOOK_RESOURCE_ID, DEFAULT_LINKQUEGW_EVENT_HOOKS, createLinkquegwEventHookResource, isGatewayAuthorization, isLinkquegwEventHook, LinkquegwEventPlugin;
|
|
210650
210750
|
var init_linkquegwEventPlugin = __esm({
|
|
210651
210751
|
"../linkque-agent-runtime/dist/esm/impl/plugin/linkquegwEventPlugin.js"() {
|
|
210652
210752
|
"use strict";
|
|
@@ -210686,7 +210786,7 @@ var init_linkquegwEventPlugin = __esm({
|
|
|
210686
210786
|
hasSideEffects: false
|
|
210687
210787
|
}
|
|
210688
210788
|
});
|
|
210689
|
-
|
|
210789
|
+
isGatewayAuthorization = (value) => /^Bearer[\t ]+[^\s,]+$/u.test(value) && !/^Bearer[\t ]+lqs_/u.test(value) || /^Scenario[\t ]+lqs_[A-Za-z0-9_-]{43}$/u.test(value);
|
|
210690
210790
|
isLinkquegwEventHook = (resource, stage) => {
|
|
210691
210791
|
if (resource.resourceType !== EResourceType.HOOK)
|
|
210692
210792
|
return false;
|
|
@@ -210697,11 +210797,15 @@ var init_linkquegwEventPlugin = __esm({
|
|
|
210697
210797
|
name = LINKQUEGW_EVENT_PLUGIN_NAME;
|
|
210698
210798
|
hookExecutorList;
|
|
210699
210799
|
constructor(options) {
|
|
210800
|
+
const getAuthorizationHeader = options.getGatewayAuthorizationHeader ?? options.getUserTokenAuthorizationHeader;
|
|
210801
|
+
if (!getAuthorizationHeader) {
|
|
210802
|
+
throw new Error("LinkqueGW event trigger \u7F3A\u5C11\u8BA4\u8BC1\u5934\u63D0\u4F9B\u5668");
|
|
210803
|
+
}
|
|
210700
210804
|
const executorOptions = {
|
|
210701
210805
|
getAuthHeaders: async () => {
|
|
210702
|
-
const authorization = await
|
|
210703
|
-
if (!
|
|
210704
|
-
throw new Error("LinkqueGW event trigger \u53EA\u5141\u8BB8\u5355\u4E2A Bearer
|
|
210806
|
+
const authorization = await getAuthorizationHeader();
|
|
210807
|
+
if (!isGatewayAuthorization(authorization)) {
|
|
210808
|
+
throw new Error("LinkqueGW event trigger \u53EA\u5141\u8BB8\u5355\u4E2A Bearer \u6216 Scenario \u51ED\u636E");
|
|
210705
210809
|
}
|
|
210706
210810
|
return {
|
|
210707
210811
|
authorization,
|
|
@@ -212956,6 +213060,9 @@ var Protocol = class {
|
|
|
212956
213060
|
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
212957
213061
|
const handleTaskResult = async () => {
|
|
212958
213062
|
const taskId = request.params.taskId;
|
|
213063
|
+
if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
|
|
213064
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
213065
|
+
}
|
|
212959
213066
|
if (this._taskMessageQueue) {
|
|
212960
213067
|
let queuedMessage;
|
|
212961
213068
|
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
@@ -212986,12 +213093,12 @@ var Protocol = class {
|
|
|
212986
213093
|
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
212987
213094
|
}
|
|
212988
213095
|
if (!isTerminal(task.status)) {
|
|
212989
|
-
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
213096
|
+
await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
|
|
212990
213097
|
return await handleTaskResult();
|
|
212991
213098
|
}
|
|
212992
213099
|
if (isTerminal(task.status)) {
|
|
212993
213100
|
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
212994
|
-
this._clearTaskQueue(taskId);
|
|
213101
|
+
this._clearTaskQueue(taskId, extra.sessionId);
|
|
212995
213102
|
return {
|
|
212996
213103
|
...result,
|
|
212997
213104
|
_meta: {
|
|
@@ -213028,7 +213135,7 @@ var Protocol = class {
|
|
|
213028
213135
|
throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
213029
213136
|
}
|
|
213030
213137
|
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
213031
|
-
this._clearTaskQueue(request.params.taskId);
|
|
213138
|
+
this._clearTaskQueue(request.params.taskId, extra.sessionId);
|
|
213032
213139
|
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
213033
213140
|
if (!cancelledTask) {
|
|
213034
213141
|
throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
@@ -213156,6 +213263,19 @@ var Protocol = class {
|
|
|
213156
213263
|
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
213157
213264
|
const capturedTransport = this._transport;
|
|
213158
213265
|
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
213266
|
+
const sessionId = capturedTransport?.sessionId;
|
|
213267
|
+
const store = this._taskStore;
|
|
213268
|
+
let relatedTaskFound = true;
|
|
213269
|
+
let relatedTaskLookup;
|
|
213270
|
+
if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
|
|
213271
|
+
relatedTaskFound = false;
|
|
213272
|
+
relatedTaskLookup = (async () => {
|
|
213273
|
+
if (!await store.getTask(relatedTaskId, sessionId)) {
|
|
213274
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
|
|
213275
|
+
}
|
|
213276
|
+
relatedTaskFound = true;
|
|
213277
|
+
})();
|
|
213278
|
+
}
|
|
213159
213279
|
if (handler === void 0) {
|
|
213160
213280
|
const errorResponse = {
|
|
213161
213281
|
jsonrpc: "2.0",
|
|
@@ -213165,7 +213285,10 @@ var Protocol = class {
|
|
|
213165
213285
|
message: "Method not found"
|
|
213166
213286
|
}
|
|
213167
213287
|
};
|
|
213168
|
-
if (relatedTaskId &&
|
|
213288
|
+
if (relatedTaskId && relatedTaskLookup) {
|
|
213289
|
+
const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
|
|
213290
|
+
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error40) => this._onerror(new Error(`Failed to send an error response: ${error40}`)));
|
|
213291
|
+
} else if (relatedTaskId && this._taskMessageQueue) {
|
|
213169
213292
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
213170
213293
|
type: "error",
|
|
213171
213294
|
message: errorResponse,
|
|
@@ -213216,7 +213339,10 @@ var Protocol = class {
|
|
|
213216
213339
|
closeSSEStream: extra?.closeSSEStream,
|
|
213217
213340
|
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
213218
213341
|
};
|
|
213219
|
-
Promise.resolve().then(() => {
|
|
213342
|
+
(relatedTaskLookup ?? Promise.resolve()).then(() => {
|
|
213343
|
+
if (relatedTaskLookup && abortController.signal.aborted) {
|
|
213344
|
+
throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
|
|
213345
|
+
}
|
|
213220
213346
|
if (taskCreationParams) {
|
|
213221
213347
|
this.assertTaskHandlerCapability(request.method);
|
|
213222
213348
|
}
|
|
@@ -213251,7 +213377,7 @@ var Protocol = class {
|
|
|
213251
213377
|
...error40["data"] !== void 0 && { data: error40["data"] }
|
|
213252
213378
|
}
|
|
213253
213379
|
};
|
|
213254
|
-
if (relatedTaskId && this._taskMessageQueue) {
|
|
213380
|
+
if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
|
|
213255
213381
|
await this._enqueueTaskMessage(relatedTaskId, {
|
|
213256
213382
|
type: "error",
|
|
213257
213383
|
message: errorResponse,
|
|
@@ -213731,7 +213857,7 @@ var Protocol = class {
|
|
|
213731
213857
|
throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
213732
213858
|
}
|
|
213733
213859
|
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
213734
|
-
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
213860
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
|
|
213735
213861
|
}
|
|
213736
213862
|
/**
|
|
213737
213863
|
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
@@ -213760,12 +213886,13 @@ var Protocol = class {
|
|
|
213760
213886
|
* Uses polling to check for updates at the task's configured poll interval.
|
|
213761
213887
|
* @param taskId The task ID to wait for
|
|
213762
213888
|
* @param signal Abort signal to cancel the wait
|
|
213889
|
+
* @param sessionId Session of the request that waits, passed to the task store
|
|
213763
213890
|
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
213764
213891
|
*/
|
|
213765
|
-
async _waitForTaskUpdate(taskId, signal) {
|
|
213892
|
+
async _waitForTaskUpdate(taskId, signal, sessionId) {
|
|
213766
213893
|
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
213767
213894
|
try {
|
|
213768
|
-
const task = await this._taskStore?.getTask(taskId);
|
|
213895
|
+
const task = await this._taskStore?.getTask(taskId, sessionId);
|
|
213769
213896
|
if (task?.pollInterval) {
|
|
213770
213897
|
interval = task.pollInterval;
|
|
213771
213898
|
}
|
|
@@ -215405,6 +215532,68 @@ function createFetchWithInit(baseFetch = fetch, baseInit) {
|
|
|
215405
215532
|
return baseFetch(url2, mergedInit);
|
|
215406
215533
|
};
|
|
215407
215534
|
}
|
|
215535
|
+
var MAX_REDIRECTS = 5;
|
|
215536
|
+
var REDIRECT_STATUSES = [301, 302, 303, 307, 308];
|
|
215537
|
+
function isWithinOrigin(from, to) {
|
|
215538
|
+
if (from.protocol === to.protocol && from.hostname === to.hostname && from.port === to.port) {
|
|
215539
|
+
return true;
|
|
215540
|
+
}
|
|
215541
|
+
return from.hostname === to.hostname && from.protocol === "http:" && from.port === "" && to.protocol === "https:" && to.port === "";
|
|
215542
|
+
}
|
|
215543
|
+
function redirectTarget(response, requestUrl) {
|
|
215544
|
+
const location = REDIRECT_STATUSES.includes(response.status) ? response.headers.get("location") : null;
|
|
215545
|
+
try {
|
|
215546
|
+
return location ? new URL(location, requestUrl) : void 0;
|
|
215547
|
+
} catch {
|
|
215548
|
+
return void 0;
|
|
215549
|
+
}
|
|
215550
|
+
}
|
|
215551
|
+
function followWithinOrigin(baseFetch, url2, init, response, followed = 0) {
|
|
215552
|
+
const target = redirectTarget(response, url2);
|
|
215553
|
+
const keepsMethod = response.status === 307 || response.status === 308 || (init?.method ?? "GET").toUpperCase() === "GET";
|
|
215554
|
+
if (!target || followed === MAX_REDIRECTS || !keepsMethod) {
|
|
215555
|
+
return void 0;
|
|
215556
|
+
}
|
|
215557
|
+
const from = new URL(url2);
|
|
215558
|
+
const addsUserinfo = (target.username || target.password) && (target.username !== from.username || target.password !== from.password);
|
|
215559
|
+
if (addsUserinfo || !isWithinOrigin(from, target)) {
|
|
215560
|
+
return void 0;
|
|
215561
|
+
}
|
|
215562
|
+
return Promise.resolve(response.body?.cancel()).then(() => baseFetch(target, { ...init, redirect: "manual" })).then((next) => followWithinOrigin(baseFetch, target, init, next, followed + 1) ?? next);
|
|
215563
|
+
}
|
|
215564
|
+
var followingFetches = /* @__PURE__ */ new WeakSet();
|
|
215565
|
+
function fetchLeavingRedirects(baseFetch) {
|
|
215566
|
+
const following = (url2, init) => (baseFetch ?? fetch)(url2, init);
|
|
215567
|
+
followingFetches.add(following);
|
|
215568
|
+
return following;
|
|
215569
|
+
}
|
|
215570
|
+
function fetchWithinOrigin(baseFetch = fetch) {
|
|
215571
|
+
if (followingFetches.has(baseFetch)) {
|
|
215572
|
+
return baseFetch;
|
|
215573
|
+
}
|
|
215574
|
+
return (url2, init) => {
|
|
215575
|
+
if (init?.redirect === "error" || init?.redirect === "manual") {
|
|
215576
|
+
return baseFetch(url2, init);
|
|
215577
|
+
}
|
|
215578
|
+
return Promise.resolve(baseFetch(url2, { ...init, redirect: "manual" })).then((response) => followWithinOrigin(baseFetch, url2, init, response) ?? response);
|
|
215579
|
+
};
|
|
215580
|
+
}
|
|
215581
|
+
function unfollowedRedirect(response, requestUrl) {
|
|
215582
|
+
if (response.type === "opaqueredirect") {
|
|
215583
|
+
return "Redirect not followed: this runtime does not expose the redirect target";
|
|
215584
|
+
}
|
|
215585
|
+
const from = response.url || requestUrl;
|
|
215586
|
+
const target = redirectTarget(response, from);
|
|
215587
|
+
if (!target) {
|
|
215588
|
+
return void 0;
|
|
215589
|
+
}
|
|
215590
|
+
target.username = target.password = target.search = target.hash = "";
|
|
215591
|
+
if (target.protocol === "http:" && new URL(from).protocol === "https:") {
|
|
215592
|
+
target.protocol = "https:";
|
|
215593
|
+
return `Redirect to plain http not followed; try ${target.href} instead`;
|
|
215594
|
+
}
|
|
215595
|
+
return `Redirect to ${target.href} not followed`;
|
|
215596
|
+
}
|
|
215408
215597
|
|
|
215409
215598
|
// ../../node_modules/pkce-challenge/dist/index.node.js
|
|
215410
215599
|
var crypto2;
|
|
@@ -215552,7 +215741,12 @@ var OAuthTokensSchema = object2({
|
|
|
215552
215741
|
token_type: string2(),
|
|
215553
215742
|
expires_in: coerce_exports.number().optional(),
|
|
215554
215743
|
scope: string2().optional(),
|
|
215555
|
-
refresh_token: string2().optional()
|
|
215744
|
+
refresh_token: string2().optional(),
|
|
215745
|
+
/**
|
|
215746
|
+
* Not part of the wire format: the authorization server this value was obtained from, added by
|
|
215747
|
+
* the client's `auth()` before it is stored and compared when it is read back.
|
|
215748
|
+
*/
|
|
215749
|
+
issuer: string2().optional().catch(void 0)
|
|
215556
215750
|
}).strip();
|
|
215557
215751
|
var OAuthErrorResponseSchema = object2({
|
|
215558
215752
|
error: string2(),
|
|
@@ -215582,7 +215776,12 @@ var OAuthClientInformationSchema = object2({
|
|
|
215582
215776
|
client_id: string2(),
|
|
215583
215777
|
client_secret: string2().optional(),
|
|
215584
215778
|
client_id_issued_at: number2().optional(),
|
|
215585
|
-
client_secret_expires_at: number2().optional()
|
|
215779
|
+
client_secret_expires_at: number2().optional(),
|
|
215780
|
+
/**
|
|
215781
|
+
* Not part of the wire format: the authorization server this value was obtained from, added by
|
|
215782
|
+
* the client's `auth()` before it is stored and compared when it is read back.
|
|
215783
|
+
*/
|
|
215784
|
+
issuer: string2().optional().catch(void 0)
|
|
215586
215785
|
}).strip();
|
|
215587
215786
|
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
|
|
215588
215787
|
var OAuthClientRegistrationErrorSchema = object2({
|
|
@@ -215780,10 +215979,31 @@ async function parseErrorResponse(input) {
|
|
|
215780
215979
|
const errorClass = OAUTH_ERRORS[error40] || ServerError;
|
|
215781
215980
|
return new errorClass(error_description || "", error_uri);
|
|
215782
215981
|
} catch (error40) {
|
|
215783
|
-
const
|
|
215982
|
+
const redirect = input instanceof Response ? unfollowedRedirect(input, input.url) : void 0;
|
|
215983
|
+
const errorMessage4 = `${statusCode ? `HTTP ${statusCode}: ` : ""}${redirect ?? `Invalid OAuth error response: ${error40}. Raw body: ${body}`}`;
|
|
215784
215984
|
return new ServerError(errorMessage4);
|
|
215785
215985
|
}
|
|
215786
215986
|
}
|
|
215987
|
+
function issuersMatch(a, b) {
|
|
215988
|
+
let [x2, y] = [a, b];
|
|
215989
|
+
try {
|
|
215990
|
+
[x2, y] = [new URL(a).href, new URL(b).href];
|
|
215991
|
+
} catch {
|
|
215992
|
+
}
|
|
215993
|
+
return x2 === y || x2.endsWith("/") && x2.slice(0, -1) === y || y.endsWith("/") && y.slice(0, -1) === x2;
|
|
215994
|
+
}
|
|
215995
|
+
function discardIfIssuerMismatch(stored, issuer) {
|
|
215996
|
+
if (!stored)
|
|
215997
|
+
return void 0;
|
|
215998
|
+
if (typeof stored.issuer !== "string")
|
|
215999
|
+
return stored.issuer == null ? stored : { ...stored, issuer: void 0 };
|
|
216000
|
+
return issuersMatch(stored.issuer, issuer) ? stored : void 0;
|
|
216001
|
+
}
|
|
216002
|
+
var TokenResponseSchema = OAuthTokensSchema.omit({ issuer: true });
|
|
216003
|
+
var RegistrationResponseSchema = OAuthClientInformationFullSchema.omit({ issuer: true });
|
|
216004
|
+
function boundElsewhereError(stored, issuer) {
|
|
216005
|
+
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.`);
|
|
216006
|
+
}
|
|
215787
216007
|
async function auth(provider, options) {
|
|
215788
216008
|
try {
|
|
215789
216009
|
return await authInternal(provider, options);
|
|
@@ -215837,9 +216057,24 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
215837
216057
|
authorizationServerMetadata: metadata
|
|
215838
216058
|
});
|
|
215839
216059
|
}
|
|
215840
|
-
const
|
|
216060
|
+
const issuer = String(authorizationServerUrl);
|
|
216061
|
+
const selectedResource = await selectResourceURL(serverUrl, provider, resourceMetadata);
|
|
216062
|
+
const resource = selectedResource && resourceMetadata && !provider.validateResourceURL ? resourceMetadata.resource : selectedResource;
|
|
215841
216063
|
const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
|
|
215842
|
-
|
|
216064
|
+
const storedClientInformation = await Promise.resolve(provider.clientInformation());
|
|
216065
|
+
let clientInformation = discardIfIssuerMismatch(storedClientInformation, issuer);
|
|
216066
|
+
const canRegisterAgain = provider.saveClientInformation !== void 0 && !!provider.redirectUrl;
|
|
216067
|
+
if (storedClientInformation && !clientInformation && !canRegisterAgain) {
|
|
216068
|
+
throw boundElsewhereError(storedClientInformation, issuer);
|
|
216069
|
+
}
|
|
216070
|
+
const unstampedClientInformation = clientInformation?.issuer == null ? clientInformation : void 0;
|
|
216071
|
+
const bindClientInformation = async () => {
|
|
216072
|
+
try {
|
|
216073
|
+
if (unstampedClientInformation)
|
|
216074
|
+
await provider.saveClientInformation?.({ ...unstampedClientInformation, issuer });
|
|
216075
|
+
} catch {
|
|
216076
|
+
}
|
|
216077
|
+
};
|
|
215843
216078
|
if (!clientInformation) {
|
|
215844
216079
|
if (authorizationCode !== void 0) {
|
|
215845
216080
|
throw new Error("Existing OAuth client information is required when exchanging an authorization code");
|
|
@@ -215851,9 +216086,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
215851
216086
|
}
|
|
215852
216087
|
const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl;
|
|
215853
216088
|
if (shouldUseUrlBasedClientId) {
|
|
215854
|
-
clientInformation = {
|
|
215855
|
-
client_id: clientMetadataUrl
|
|
215856
|
-
};
|
|
216089
|
+
clientInformation = { client_id: clientMetadataUrl, issuer };
|
|
215857
216090
|
await provider.saveClientInformation?.(clientInformation);
|
|
215858
216091
|
} else {
|
|
215859
216092
|
if (!provider.saveClientInformation) {
|
|
@@ -215865,8 +216098,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
215865
216098
|
scope: resolvedScope,
|
|
215866
216099
|
fetchFn
|
|
215867
216100
|
});
|
|
215868
|
-
|
|
215869
|
-
clientInformation
|
|
216101
|
+
clientInformation = { ...fullInformation, issuer };
|
|
216102
|
+
await provider.saveClientInformation(clientInformation);
|
|
215870
216103
|
}
|
|
215871
216104
|
}
|
|
215872
216105
|
const nonInteractiveFlow = !provider.redirectUrl;
|
|
@@ -215877,10 +216110,14 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
215877
216110
|
authorizationCode,
|
|
215878
216111
|
fetchFn
|
|
215879
216112
|
});
|
|
215880
|
-
await
|
|
216113
|
+
await bindClientInformation();
|
|
216114
|
+
await provider.saveTokens({ ...tokens2, issuer });
|
|
215881
216115
|
return "AUTHORIZED";
|
|
215882
216116
|
}
|
|
215883
|
-
const tokens = await provider.tokens();
|
|
216117
|
+
const tokens = discardIfIssuerMismatch(await provider.tokens(), issuer);
|
|
216118
|
+
if (tokens?.refresh_token && tokens.issuer == null) {
|
|
216119
|
+
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.");
|
|
216120
|
+
}
|
|
215884
216121
|
if (tokens?.refresh_token) {
|
|
215885
216122
|
try {
|
|
215886
216123
|
const newTokens = await refreshAuthorization(authorizationServerUrl, {
|
|
@@ -215891,7 +216128,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
|
|
|
215891
216128
|
addClientAuthentication: provider.addClientAuthentication,
|
|
215892
216129
|
fetchFn
|
|
215893
216130
|
});
|
|
215894
|
-
await
|
|
216131
|
+
await bindClientInformation();
|
|
216132
|
+
await provider.saveTokens({ ...newTokens, issuer });
|
|
215895
216133
|
return "AUTHORIZED";
|
|
215896
216134
|
} catch (error40) {
|
|
215897
216135
|
if (!(error40 instanceof OAuthError) || error40 instanceof ServerError) {
|
|
@@ -215990,7 +216228,7 @@ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn =
|
|
|
215990
216228
|
}
|
|
215991
216229
|
async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
|
|
215992
216230
|
try {
|
|
215993
|
-
return await fetchFn(url2, { headers });
|
|
216231
|
+
return await fetchWithinOrigin(fetchFn)(url2, { headers });
|
|
215994
216232
|
} catch (error40) {
|
|
215995
216233
|
if (error40 instanceof TypeError) {
|
|
215996
216234
|
if (headers) {
|
|
@@ -216015,7 +216253,7 @@ async function tryMetadataDiscovery(url2, protocolVersion, fetchFn = fetch) {
|
|
|
216015
216253
|
return await fetchWithCorsRetry(url2, headers, fetchFn);
|
|
216016
216254
|
}
|
|
216017
216255
|
function shouldAttemptFallback(response, pathname) {
|
|
216018
|
-
return !response || response.
|
|
216256
|
+
return !response || !response.ok && response.status < 500 && pathname !== "/";
|
|
216019
216257
|
}
|
|
216020
216258
|
async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
|
|
216021
216259
|
const issuer = new URL(serverUrl);
|
|
@@ -216081,7 +216319,7 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
|
|
|
216081
216319
|
}
|
|
216082
216320
|
if (!response.ok) {
|
|
216083
216321
|
await response.body?.cancel();
|
|
216084
|
-
if (response.status
|
|
216322
|
+
if (response.status < 500) {
|
|
216085
216323
|
continue;
|
|
216086
216324
|
}
|
|
216087
216325
|
throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
|
|
@@ -216114,6 +216352,9 @@ async function discoverOAuthServerInfo(serverUrl, opts) {
|
|
|
216114
216352
|
resourceMetadata
|
|
216115
216353
|
};
|
|
216116
216354
|
}
|
|
216355
|
+
function resourceIndicatorToString(resource) {
|
|
216356
|
+
return typeof resource === "string" ? resource : resource.href;
|
|
216357
|
+
}
|
|
216117
216358
|
async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state: state2, resource }) {
|
|
216118
216359
|
let authorizationUrl;
|
|
216119
216360
|
if (metadata) {
|
|
@@ -216145,7 +216386,7 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
|
|
|
216145
216386
|
authorizationUrl.searchParams.append("prompt", "consent");
|
|
216146
216387
|
}
|
|
216147
216388
|
if (resource) {
|
|
216148
|
-
authorizationUrl.searchParams.set("resource", resource
|
|
216389
|
+
authorizationUrl.searchParams.set("resource", resourceIndicatorToString(resource));
|
|
216149
216390
|
}
|
|
216150
216391
|
return { authorizationUrl, codeVerifier };
|
|
216151
216392
|
}
|
|
@@ -216164,7 +216405,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
216164
216405
|
Accept: "application/json"
|
|
216165
216406
|
});
|
|
216166
216407
|
if (resource) {
|
|
216167
|
-
tokenRequestParams.set("resource", resource
|
|
216408
|
+
tokenRequestParams.set("resource", resourceIndicatorToString(resource));
|
|
216168
216409
|
}
|
|
216169
216410
|
if (addClientAuthentication) {
|
|
216170
216411
|
await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
|
|
@@ -216173,7 +216414,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
216173
216414
|
const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
|
|
216174
216415
|
applyClientAuthentication(authMethod, clientInformation, headers, tokenRequestParams);
|
|
216175
216416
|
}
|
|
216176
|
-
const response = await (fetchFn ?? fetch)(tokenUrl, {
|
|
216417
|
+
const response = await fetchWithinOrigin(fetchFn ?? fetch)(tokenUrl, {
|
|
216177
216418
|
method: "POST",
|
|
216178
216419
|
headers,
|
|
216179
216420
|
body: tokenRequestParams
|
|
@@ -216181,7 +216422,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
|
|
|
216181
216422
|
if (!response.ok) {
|
|
216182
216423
|
throw await parseErrorResponse(response);
|
|
216183
216424
|
}
|
|
216184
|
-
return
|
|
216425
|
+
return TokenResponseSchema.parse(await response.json());
|
|
216185
216426
|
}
|
|
216186
216427
|
async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
|
|
216187
216428
|
const tokenRequestParams = new URLSearchParams({
|
|
@@ -216199,6 +216440,15 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
|
|
|
216199
216440
|
return { refresh_token: refreshToken, ...tokens };
|
|
216200
216441
|
}
|
|
216201
216442
|
async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) {
|
|
216443
|
+
const readClientInformation = async () => {
|
|
216444
|
+
const storedClientInformation = await provider.clientInformation();
|
|
216445
|
+
const checked = discardIfIssuerMismatch(storedClientInformation, String(authorizationServerUrl));
|
|
216446
|
+
if (storedClientInformation && !checked) {
|
|
216447
|
+
throw boundElsewhereError(storedClientInformation, String(authorizationServerUrl));
|
|
216448
|
+
}
|
|
216449
|
+
return checked;
|
|
216450
|
+
};
|
|
216451
|
+
let clientInformation = await readClientInformation();
|
|
216202
216452
|
const scope = provider.clientMetadata.scope;
|
|
216203
216453
|
let tokenRequestParams;
|
|
216204
216454
|
if (provider.prepareTokenRequest) {
|
|
@@ -216214,11 +216464,11 @@ async function fetchToken(provider, authorizationServerUrl, { metadata, resource
|
|
|
216214
216464
|
const codeVerifier = await provider.codeVerifier();
|
|
216215
216465
|
tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
|
|
216216
216466
|
}
|
|
216217
|
-
|
|
216467
|
+
clientInformation ?? (clientInformation = await readClientInformation());
|
|
216218
216468
|
return executeTokenRequest(authorizationServerUrl, {
|
|
216219
216469
|
metadata,
|
|
216220
216470
|
tokenRequestParams,
|
|
216221
|
-
clientInformation
|
|
216471
|
+
clientInformation,
|
|
216222
216472
|
addClientAuthentication: provider.addClientAuthentication,
|
|
216223
216473
|
resource,
|
|
216224
216474
|
fetchFn
|
|
@@ -216234,7 +216484,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
216234
216484
|
} else {
|
|
216235
216485
|
registrationUrl = new URL("/register", authorizationServerUrl);
|
|
216236
216486
|
}
|
|
216237
|
-
const response = await (fetchFn ?? fetch)(registrationUrl, {
|
|
216487
|
+
const response = await fetchWithinOrigin(fetchFn ?? fetch)(registrationUrl, {
|
|
216238
216488
|
method: "POST",
|
|
216239
216489
|
headers: {
|
|
216240
216490
|
"Content-Type": "application/json"
|
|
@@ -216247,7 +216497,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
|
|
|
216247
216497
|
if (!response.ok) {
|
|
216248
216498
|
throw await parseErrorResponse(response);
|
|
216249
216499
|
}
|
|
216250
|
-
return
|
|
216500
|
+
return RegistrationResponseSchema.parse(await response.json());
|
|
216251
216501
|
}
|
|
216252
216502
|
|
|
216253
216503
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
|
|
@@ -216268,6 +216518,16 @@ var SSEClientTransport = class {
|
|
|
216268
216518
|
this._authProvider = opts?.authProvider;
|
|
216269
216519
|
this._fetch = opts?.fetch;
|
|
216270
216520
|
this._fetchWithInit = createFetchWithInit(opts?.fetch, opts?.requestInit);
|
|
216521
|
+
this._followRedirects = opts?.redirectPolicy === "follow";
|
|
216522
|
+
if (this._followRedirects) {
|
|
216523
|
+
this._fetch = fetchLeavingRedirects(this._fetch);
|
|
216524
|
+
this._fetchWithInit = fetchLeavingRedirects(this._fetchWithInit);
|
|
216525
|
+
}
|
|
216526
|
+
}
|
|
216527
|
+
/** Error text for a redirect `response` that was not followed, or `undefined` for any other response. */
|
|
216528
|
+
_unfollowedRedirect(response, url2) {
|
|
216529
|
+
const text2 = unfollowedRedirect(response, url2);
|
|
216530
|
+
return text2 && !this._followRedirects ? `${text2} (redirectPolicy: 'same-origin')` : text2;
|
|
216271
216531
|
}
|
|
216272
216532
|
async _authThenStart() {
|
|
216273
216533
|
if (!this._authProvider) {
|
|
@@ -216308,7 +216568,9 @@ var SSEClientTransport = class {
|
|
|
216308
216568
|
});
|
|
216309
216569
|
}
|
|
216310
216570
|
_startOrAuth() {
|
|
216311
|
-
const
|
|
216571
|
+
const baseFetch = this?._eventSourceInit?.fetch ?? this._fetch ?? fetch;
|
|
216572
|
+
const fetchImpl = this._followRedirects ? baseFetch : fetchWithinOrigin(baseFetch);
|
|
216573
|
+
let redirect;
|
|
216312
216574
|
return new Promise((resolve, reject) => {
|
|
216313
216575
|
this._eventSource = new EventSource(this._url.href, {
|
|
216314
216576
|
...this._eventSourceInit,
|
|
@@ -216319,6 +216581,7 @@ var SSEClientTransport = class {
|
|
|
216319
216581
|
...init,
|
|
216320
216582
|
headers
|
|
216321
216583
|
});
|
|
216584
|
+
redirect = this._unfollowedRedirect(response, url2);
|
|
216322
216585
|
if (response.status === 401 && response.headers.has("www-authenticate")) {
|
|
216323
216586
|
const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
|
|
216324
216587
|
this._resourceMetadataUrl = resourceMetadataUrl;
|
|
@@ -216333,7 +216596,7 @@ var SSEClientTransport = class {
|
|
|
216333
216596
|
this._authThenStart().then(resolve, reject);
|
|
216334
216597
|
return;
|
|
216335
216598
|
}
|
|
216336
|
-
const error40 = new SseError(event.code, event.message, event);
|
|
216599
|
+
const error40 = new SseError(event.code, redirect ?? event.message, event);
|
|
216337
216600
|
reject(error40);
|
|
216338
216601
|
this.onerror?.(error40);
|
|
216339
216602
|
};
|
|
@@ -216410,7 +216673,7 @@ var SSEClientTransport = class {
|
|
|
216410
216673
|
body: JSON.stringify(message),
|
|
216411
216674
|
signal: this._abortController?.signal
|
|
216412
216675
|
};
|
|
216413
|
-
const response = await (this._fetch ?? fetch)(this._endpoint, init);
|
|
216676
|
+
const response = await fetchWithinOrigin(this._fetch ?? fetch)(this._endpoint, init);
|
|
216414
216677
|
if (!response.ok) {
|
|
216415
216678
|
const text2 = await response.text().catch(() => null);
|
|
216416
216679
|
if (response.status === 401 && this._authProvider) {
|
|
@@ -216428,7 +216691,7 @@ var SSEClientTransport = class {
|
|
|
216428
216691
|
}
|
|
216429
216692
|
return this.send(message);
|
|
216430
216693
|
}
|
|
216431
|
-
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${text2}`);
|
|
216694
|
+
throw new Error(`Error POSTing to endpoint (HTTP ${response.status}): ${this._unfollowedRedirect(response, this._endpoint) ?? text2}`);
|
|
216432
216695
|
}
|
|
216433
216696
|
await response.body?.cancel();
|
|
216434
216697
|
} catch (error40) {
|