linkque-cli-v2 1.0.6 → 1.0.7
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/linkquejs.js +7 -11
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-52BVDZQ2.js → chunk-FJ2BZPIM.js} +15 -6
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NQM5ZCTR.js → chunk-IAT272TH.js} +109 -3
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +50 -56
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +1 -1
- package/worker.js +16 -6
package/linkquejs.js
CHANGED
|
@@ -20363,31 +20363,27 @@ function parseEnvEntry(raw) {
|
|
|
20363
20363
|
var import_fs6 = require("fs");
|
|
20364
20364
|
var import_path9 = require("path");
|
|
20365
20365
|
var INTEGRATE_PKG = "@alipay/linkque-agent-appwrite-integrate";
|
|
20366
|
-
var resolveIntegrateRoot = () =>
|
|
20366
|
+
var resolveIntegrateRoot = () => resolvePortableIntegrateRoot() ?? resolveInstalledIntegrateRoot();
|
|
20367
20367
|
var resolveInstalledIntegrateRoot = () => {
|
|
20368
20368
|
try {
|
|
20369
20369
|
return (0, import_path9.dirname)(require.resolve(`${INTEGRATE_PKG}/package.json`));
|
|
20370
20370
|
} catch {
|
|
20371
|
-
|
|
20371
|
+
throw new LinkqueCliError(
|
|
20372
|
+
"AGENTBUILD_INTEGRATE_NOT_BUILT",
|
|
20373
|
+
"@alipay/linkque-agent-appwrite-integrate \u672A\u5B89\u88C5\uFF0C\u4E14 public bundle \u672A\u643A\u5E26 vendor \u6784\u5EFA\u8D44\u4EA7"
|
|
20374
|
+
);
|
|
20372
20375
|
}
|
|
20373
20376
|
};
|
|
20374
20377
|
var resolvePortableIntegrateRoot = () => {
|
|
20375
20378
|
let dir = __dirname;
|
|
20376
20379
|
while (true) {
|
|
20377
|
-
const candidate = (0, import_path9.join)(
|
|
20378
|
-
dir,
|
|
20379
|
-
"vendor",
|
|
20380
|
-
"linkque-agent-appwrite-integrate"
|
|
20381
|
-
);
|
|
20380
|
+
const candidate = (0, import_path9.join)(dir, "vendor", "linkque-agent-appwrite-integrate");
|
|
20382
20381
|
if ((0, import_fs6.existsSync)((0, import_path9.join)(candidate, "package.json"))) return candidate;
|
|
20383
20382
|
const parent = (0, import_path9.dirname)(dir);
|
|
20384
20383
|
if (parent === dir) break;
|
|
20385
20384
|
dir = parent;
|
|
20386
20385
|
}
|
|
20387
|
-
|
|
20388
|
-
"AGENTBUILD_INTEGRATE_NOT_BUILT",
|
|
20389
|
-
"@alipay/linkque-agent-appwrite-integrate \u672A\u5B89\u88C5\uFF0C\u4E14 public bundle \u672A\u643A\u5E26 vendor \u6784\u5EFA\u8D44\u4EA7"
|
|
20390
|
-
);
|
|
20386
|
+
return void 0;
|
|
20391
20387
|
};
|
|
20392
20388
|
var assertIntegrateBuilt = (pkgRoot) => {
|
|
20393
20389
|
const distEsm = (0, import_path9.join)(pkgRoot, "dist", "esm");
|
package/package.json
CHANGED
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-52BVDZQ2.js → chunk-FJ2BZPIM.js}
RENAMED
|
@@ -19798,7 +19798,6 @@ function buildLinkquegwEventBody(context) {
|
|
|
19798
19798
|
eventType,
|
|
19799
19799
|
eventId: context.eventId,
|
|
19800
19800
|
eventTime: context.timestamp,
|
|
19801
|
-
...commonParams.userId !== void 0 && { userId: commonParams.userId },
|
|
19802
19801
|
conversationId: commonParams.conversationId,
|
|
19803
19802
|
...commonParams.sessionId !== void 0 && {
|
|
19804
19803
|
sessionId: commonParams.sessionId
|
|
@@ -56373,7 +56372,7 @@ var RemoteSignatureSigner = class {
|
|
|
56373
56372
|
* 对一次出站请求取签名。
|
|
56374
56373
|
*
|
|
56375
56374
|
* @param req 见 {@link ISignRequest}(method/url/body)
|
|
56376
|
-
* @returns `{authorization, signatureContent}`
|
|
56375
|
+
* @returns `{authorization, signatureContent, userId?}`
|
|
56377
56376
|
* @throws 签名服务非 2xx / 鉴权头获取失败 / 响应缺字段时抛错(由 signingFetch 转 transport-error)。
|
|
56378
56377
|
*/
|
|
56379
56378
|
async sign(req) {
|
|
@@ -56409,7 +56408,8 @@ var RemoteSignatureSigner = class {
|
|
|
56409
56408
|
}
|
|
56410
56409
|
return {
|
|
56411
56410
|
authorization: payload.authorization,
|
|
56412
|
-
signatureContent: payload.signatureContent
|
|
56411
|
+
signatureContent: payload.signatureContent,
|
|
56412
|
+
...optionalUserId(payload.userId)
|
|
56413
56413
|
};
|
|
56414
56414
|
}
|
|
56415
56415
|
};
|
|
@@ -56431,9 +56431,13 @@ function extractFromWrapped(wrapped) {
|
|
|
56431
56431
|
}
|
|
56432
56432
|
return {
|
|
56433
56433
|
authorization: data.authorization,
|
|
56434
|
-
signatureContent: data.signatureContent
|
|
56434
|
+
signatureContent: data.signatureContent,
|
|
56435
|
+
...optionalUserId(data.userId)
|
|
56435
56436
|
};
|
|
56436
56437
|
}
|
|
56438
|
+
function optionalUserId(value) {
|
|
56439
|
+
return typeof value === "string" && value.trim() ? { userId: value.trim() } : {};
|
|
56440
|
+
}
|
|
56437
56441
|
async function safeText(resp) {
|
|
56438
56442
|
try {
|
|
56439
56443
|
return await resp.text();
|
|
@@ -57978,6 +57982,7 @@ var SSEClientTransport = class {
|
|
|
57978
57982
|
|
|
57979
57983
|
// ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/signingFetch.js
|
|
57980
57984
|
var ALIPAY_SDK_VERSION = "@alipay/open-mcp-server-2.0.4";
|
|
57985
|
+
var OAGW_ALIPAY_UID_HEADER = "x-oagw-alipay-uid";
|
|
57981
57986
|
function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, debugLog) {
|
|
57982
57987
|
const loggedFetch = debugLog ? createHttpLoggingFetch(debugLog, "mcp-call", baseFetch) : baseFetch;
|
|
57983
57988
|
return async (url2, init) => {
|
|
@@ -57987,11 +57992,16 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
57987
57992
|
httpRequestUrl: targetUrl.pathname + targetUrl.search,
|
|
57988
57993
|
httpRequestBody: typeof init?.body === "string" ? init.body : ""
|
|
57989
57994
|
};
|
|
57990
|
-
const { authorization, signatureContent } = await signer.sign(req);
|
|
57995
|
+
const { authorization, signatureContent, userId } = await signer.sign(req);
|
|
57991
57996
|
const headers = new Headers(init?.headers);
|
|
57992
57997
|
headers.set("Authorization", authorization);
|
|
57993
57998
|
headers.set("X-Signature-Content", Buffer.from(signatureContent).toString("base64"));
|
|
57994
57999
|
headers.set("X-Alipay-SDK-Version", ALIPAY_SDK_VERSION);
|
|
58000
|
+
if (userId) {
|
|
58001
|
+
headers.set(OAGW_ALIPAY_UID_HEADER, userId);
|
|
58002
|
+
} else {
|
|
58003
|
+
headers.delete(OAGW_ALIPAY_UID_HEADER);
|
|
58004
|
+
}
|
|
57995
58005
|
const resp = await loggedFetch(url2, { ...init, headers });
|
|
57996
58006
|
if (onTraceId) {
|
|
57997
58007
|
try {
|
|
@@ -60268,7 +60278,6 @@ function setBakedProtocol(protocol) {
|
|
|
60268
60278
|
}
|
|
60269
60279
|
|
|
60270
60280
|
export {
|
|
60271
|
-
EModelProvider,
|
|
60272
60281
|
EResourceType,
|
|
60273
60282
|
executeHomeData,
|
|
60274
60283
|
FOLLOW_UP_CONTEXT_MAX_HISTORY_RUNS,
|
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-NQM5ZCTR.js → chunk-IAT272TH.js}
RENAMED
|
@@ -7328,6 +7328,109 @@ var require_agent = __commonJS({
|
|
|
7328
7328
|
}
|
|
7329
7329
|
});
|
|
7330
7330
|
|
|
7331
|
+
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/auth.js
|
|
7332
|
+
var LINKQUE_AUTHORIZATION_HEADER = "x-linkque-authorization";
|
|
7333
|
+
var LinkqueGatewayAuthError = class extends Error {
|
|
7334
|
+
code = "invalid_linkque_authorization";
|
|
7335
|
+
status = 401;
|
|
7336
|
+
constructor(message = "X-Linkque-Authorization \u5FC5\u987B\u662F\u5355\u4E2A Bearer \u51ED\u636E") {
|
|
7337
|
+
super(message);
|
|
7338
|
+
this.name = "LinkqueGatewayAuthError";
|
|
7339
|
+
}
|
|
7340
|
+
};
|
|
7341
|
+
var LinkqueGatewayAuthUnconfiguredError = class extends Error {
|
|
7342
|
+
code = "auth_unconfigured";
|
|
7343
|
+
status = 500;
|
|
7344
|
+
constructor(message = "\u8BA4\u8BC1\u914D\u7F6E\u7F3A\u5931:LINKQUE_AGENT_ACCESS_KEY \u672A\u8BBE\u7F6E") {
|
|
7345
|
+
super(message);
|
|
7346
|
+
this.name = "LinkqueGatewayAuthUnconfiguredError";
|
|
7347
|
+
}
|
|
7348
|
+
};
|
|
7349
|
+
function resolveLinkqueGatewayAuth(headers, env = process.env, logCtx) {
|
|
7350
|
+
const log = (...a2) => logCtx?.log?.("[auth-resolve]", ...a2);
|
|
7351
|
+
const logError = (...a2) => logCtx?.error?.("[auth-resolve]", ...a2);
|
|
7352
|
+
log("stage=start");
|
|
7353
|
+
const matches = Object.entries(headers ?? {}).filter(([key]) => key.toLowerCase() === LINKQUE_AUTHORIZATION_HEADER);
|
|
7354
|
+
if (matches.length > 0) {
|
|
7355
|
+
log(`stage=header-inspection, state=present, count=${matches.length}`);
|
|
7356
|
+
log("stage=user-token-validation, state=start");
|
|
7357
|
+
if (matches.length !== 1) {
|
|
7358
|
+
logError("stage=failed, reason=duplicate-header");
|
|
7359
|
+
throw new LinkqueGatewayAuthError();
|
|
7360
|
+
}
|
|
7361
|
+
const value = matches[0]?.[1];
|
|
7362
|
+
if (typeof value !== "string") {
|
|
7363
|
+
logError("stage=failed, reason=multi-value-header");
|
|
7364
|
+
throw new LinkqueGatewayAuthError();
|
|
7365
|
+
}
|
|
7366
|
+
if (value.includes(",")) {
|
|
7367
|
+
logError("stage=failed, reason=joined-header");
|
|
7368
|
+
throw new LinkqueGatewayAuthError();
|
|
7369
|
+
}
|
|
7370
|
+
const match = /^Bearer[\t ]+([^\s,]+)$/iu.exec(value.trim());
|
|
7371
|
+
const token = match?.[1];
|
|
7372
|
+
if (!token) {
|
|
7373
|
+
logError("stage=failed, reason=invalid-bearer-format");
|
|
7374
|
+
throw new LinkqueGatewayAuthError();
|
|
7375
|
+
}
|
|
7376
|
+
log("stage=user-token-validation, state=success, scheme=Bearer");
|
|
7377
|
+
const provider2 = resolveProvider(env.LINKQUE_MODEL_PROVIDER, log, logError);
|
|
7378
|
+
log("stage=complete, mode=user-token, source=request-header");
|
|
7379
|
+
return {
|
|
7380
|
+
mode: "user-token",
|
|
7381
|
+
modelCredential: token,
|
|
7382
|
+
authorizationHeader: `Bearer ${token}`,
|
|
7383
|
+
auth: { provider: provider2, apiKey: token }
|
|
7384
|
+
};
|
|
7385
|
+
}
|
|
7386
|
+
log("stage=header-inspection, state=absent");
|
|
7387
|
+
log("stage=aak-fallback, state=start, source=env:LINKQUE_AGENT_ACCESS_KEY");
|
|
7388
|
+
const apiKey = env.LINKQUE_AGENT_ACCESS_KEY?.trim();
|
|
7389
|
+
if (!apiKey) {
|
|
7390
|
+
logError("stage=failed, reason=aak-unconfigured");
|
|
7391
|
+
throw new LinkqueGatewayAuthUnconfiguredError();
|
|
7392
|
+
}
|
|
7393
|
+
log("stage=aak-fallback, state=configured");
|
|
7394
|
+
const provider = resolveProvider(env.LINKQUE_MODEL_PROVIDER, log, logError);
|
|
7395
|
+
log("stage=complete, mode=aak, source=env:LINKQUE_AGENT_ACCESS_KEY");
|
|
7396
|
+
return {
|
|
7397
|
+
mode: "aak",
|
|
7398
|
+
modelCredential: apiKey,
|
|
7399
|
+
authorizationHeader: `aak ${apiKey}`,
|
|
7400
|
+
auth: { provider, apiKey }
|
|
7401
|
+
};
|
|
7402
|
+
}
|
|
7403
|
+
function resolveGatewayAuthContext(gatewayAuth, env = process.env, logCtx, caller = "unknown") {
|
|
7404
|
+
const log = (...a2) => logCtx?.log?.("[auth-resolve]", ...a2);
|
|
7405
|
+
if (gatewayAuth) {
|
|
7406
|
+
log(`stage=context-selection, caller=${caller}, branch=request-context, mode=${gatewayAuth.mode}`);
|
|
7407
|
+
return gatewayAuth;
|
|
7408
|
+
}
|
|
7409
|
+
log(`stage=context-selection, caller=${caller}, branch=compat-env-fallback`);
|
|
7410
|
+
return resolveLinkqueGatewayAuth(void 0, env, logCtx);
|
|
7411
|
+
}
|
|
7412
|
+
function parseProvider(raw) {
|
|
7413
|
+
if (!raw)
|
|
7414
|
+
return "LINKQUE";
|
|
7415
|
+
const upper = raw.toUpperCase();
|
|
7416
|
+
if (upper === "LINKQUE")
|
|
7417
|
+
return "LINKQUE";
|
|
7418
|
+
if (upper === "TEST")
|
|
7419
|
+
return "TEST";
|
|
7420
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684 LINKQUE_MODEL_PROVIDER="${raw}"(\u5F53\u524D\u652F\u6301:LINKQUE\u3001TEST)`);
|
|
7421
|
+
}
|
|
7422
|
+
function resolveProvider(raw, log, logError) {
|
|
7423
|
+
log("stage=provider-resolution, state=start");
|
|
7424
|
+
try {
|
|
7425
|
+
const provider = parseProvider(raw);
|
|
7426
|
+
log(`stage=provider-resolution, state=success, provider=${provider}`);
|
|
7427
|
+
return provider;
|
|
7428
|
+
} catch (error) {
|
|
7429
|
+
logError("stage=failed, reason=invalid-provider");
|
|
7430
|
+
throw error;
|
|
7431
|
+
}
|
|
7432
|
+
}
|
|
7433
|
+
|
|
7331
7434
|
// ../../node_modules/node-fetch-native-with-agent/dist/index.mjs
|
|
7332
7435
|
var a = Object.defineProperty;
|
|
7333
7436
|
var t = (e, r) => a(e, "name", { value: r, configurable: true });
|
|
@@ -11699,7 +11802,7 @@ function apiKeySource(env, hasRequestKey) {
|
|
|
11699
11802
|
}
|
|
11700
11803
|
function describeRuntimeEnv(env, hasRequestKey = false) {
|
|
11701
11804
|
const lines = [];
|
|
11702
|
-
lines.push(envLine("LINKQUE_AGENT_ACCESS_KEY",
|
|
11805
|
+
lines.push(envLine("LINKQUE_AGENT_ACCESS_KEY", env.LINKQUE_AGENT_ACCESS_KEY?.trim() ? "<set>" : "<unset>"));
|
|
11703
11806
|
lines.push(envLine("LINKQUE_MODEL_PROVIDER", envValue(env, "LINKQUE_MODEL_PROVIDER")));
|
|
11704
11807
|
lines.push(envLine("APPBASE_ENDPOINT", `${maskEndpoint(firstHit(env, ENDPOINT_SOURCES))}(src=${whichSource(env, ENDPOINT_SOURCES)})`));
|
|
11705
11808
|
lines.push(envLine("APPBASE_PROJECT_ID", `${firstHit(env, PROJECT_SOURCES)}(src=${whichSource(env, PROJECT_SOURCES)})`));
|
|
@@ -11954,7 +12057,7 @@ async function clientCapability(ctx) {
|
|
|
11954
12057
|
result = await runClientCapability(readAppwriteTrigger(ctx.req.headers), ctx.req.method, resolveBodyJSON(ctx.req), readAuthenticatedUserId(ctx.req.headers), store);
|
|
11955
12058
|
} catch (error) {
|
|
11956
12059
|
ctx.error?.(error);
|
|
11957
|
-
result = jsonError(500, "internal_error", error instanceof Error ? error.message : "unknown error");
|
|
12060
|
+
result = error instanceof LinkqueGatewayAuthError || error instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(error.status, error.code, error.message) : jsonError(500, "internal_error", error instanceof Error ? error.message : "unknown error");
|
|
11958
12061
|
}
|
|
11959
12062
|
return ctx.res.json?.(result.body, result.status);
|
|
11960
12063
|
}
|
|
@@ -11993,6 +12096,10 @@ function requiredEnv(name) {
|
|
|
11993
12096
|
}
|
|
11994
12097
|
|
|
11995
12098
|
export {
|
|
12099
|
+
LinkqueGatewayAuthError,
|
|
12100
|
+
LinkqueGatewayAuthUnconfiguredError,
|
|
12101
|
+
resolveLinkqueGatewayAuth,
|
|
12102
|
+
resolveGatewayAuthContext,
|
|
11996
12103
|
resolveBodyJSON,
|
|
11997
12104
|
toAgentRunMessages,
|
|
11998
12105
|
jsonError,
|
|
@@ -12001,7 +12108,6 @@ export {
|
|
|
12001
12108
|
readAuthenticatedUserId,
|
|
12002
12109
|
readAppwriteApiKey,
|
|
12003
12110
|
Query,
|
|
12004
|
-
maskSecret,
|
|
12005
12111
|
isDebugLogLevel,
|
|
12006
12112
|
describeRuntimeEnv,
|
|
12007
12113
|
resolveRunStorage,
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
+
LinkqueGatewayAuthError,
|
|
3
|
+
LinkqueGatewayAuthUnconfiguredError,
|
|
2
4
|
Query,
|
|
3
5
|
createAppBaseClient,
|
|
4
6
|
createClientCapabilityStore,
|
|
5
7
|
describeRuntimeEnv,
|
|
6
8
|
isDebugLogLevel,
|
|
7
9
|
jsonError,
|
|
8
|
-
maskSecret,
|
|
9
10
|
parseStoredClientCapabilityResult,
|
|
10
11
|
readAppwriteApiKey,
|
|
11
12
|
readAuthenticatedUserId,
|
|
12
13
|
readEnvSelector,
|
|
13
14
|
readTraceId,
|
|
14
15
|
resolveBodyJSON,
|
|
16
|
+
resolveGatewayAuthContext,
|
|
17
|
+
resolveLinkqueGatewayAuth,
|
|
15
18
|
resolveRunStorage,
|
|
16
19
|
toAgentRunMessages
|
|
17
|
-
} from "../../chunk-
|
|
20
|
+
} from "../../chunk-IAT272TH.js";
|
|
18
21
|
import "../../chunk-MKS245OU.js";
|
|
19
22
|
import "../../chunk-YDKZZ6EH.js";
|
|
20
23
|
import "../../chunk-2NGJGNYB.js";
|
|
@@ -28,7 +31,6 @@ import {
|
|
|
28
31
|
DEFAULT_CONVERSATION_LIST_LIMIT,
|
|
29
32
|
DEFAULT_CONVERSATION_RUN_LIST_LIMIT,
|
|
30
33
|
DEFAULT_CONVERSATION_SEARCH_LIMIT,
|
|
31
|
-
EModelProvider,
|
|
32
34
|
EResourceType,
|
|
33
35
|
ESkillUrlScheme,
|
|
34
36
|
EventType,
|
|
@@ -46,7 +48,7 @@ import {
|
|
|
46
48
|
parseConversationRunRequest,
|
|
47
49
|
parseSkillFile,
|
|
48
50
|
streamToConversationEvents
|
|
49
|
-
} from "../../chunk-
|
|
51
|
+
} from "../../chunk-FJ2BZPIM.js";
|
|
50
52
|
import "../../chunk-XUFLSZM4.js";
|
|
51
53
|
import "../../chunk-I64V3ICJ.js";
|
|
52
54
|
import "../../chunk-6MHDOBWO.js";
|
|
@@ -307,25 +309,29 @@ function createAppBaseRuntime(protocol, env = process.env, ports = {}, logCtx) {
|
|
|
307
309
|
|
|
308
310
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/asr.js
|
|
309
311
|
var ASR_CREATE_CREDENTIAL_OPERATION = "asr.createCredential";
|
|
310
|
-
async function runAsrCredential(method, env, authenticatedUserId, agentId, fetchImpl = fetch, envSelector) {
|
|
312
|
+
async function runAsrCredential(method, env, authenticatedUserId, agentId, fetchImpl = fetch, envSelector, gatewayAuth, logCtx) {
|
|
311
313
|
if (method !== "POST")
|
|
312
314
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
313
315
|
if (!authenticatedUserId) {
|
|
314
316
|
return jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
|
|
315
317
|
}
|
|
316
|
-
|
|
318
|
+
let resolvedAuth;
|
|
319
|
+
try {
|
|
320
|
+
resolvedAuth = resolveGatewayAuthContext(gatewayAuth, env, logCtx, "asr");
|
|
321
|
+
} catch {
|
|
322
|
+
return jsonError(500, "auth_unconfigured", "linkquegw AAK \u672A\u914D\u7F6E");
|
|
323
|
+
}
|
|
317
324
|
const gatewayBaseUrl = resolveLinkqueEndpoints(env, envSelector).knowledgeBaseUrl;
|
|
318
|
-
if (!
|
|
319
|
-
return jsonError(500, "gateway_unconfigured", "linkquegw
|
|
325
|
+
if (!gatewayBaseUrl) {
|
|
326
|
+
return jsonError(500, "gateway_unconfigured", "linkquegw \u5730\u5740\u672A\u914D\u7F6E");
|
|
320
327
|
}
|
|
321
328
|
let response;
|
|
322
329
|
try {
|
|
323
330
|
response = await fetchImpl(`${gatewayBaseUrl}/api/asr/credential`, {
|
|
324
331
|
method: "POST",
|
|
325
332
|
headers: {
|
|
326
|
-
Authorization:
|
|
327
|
-
"x-linkque-agent-id": agentId
|
|
328
|
-
"x-linkque-appbase-user-id": authenticatedUserId
|
|
333
|
+
Authorization: resolvedAuth.authorizationHeader,
|
|
334
|
+
"x-linkque-agent-id": agentId
|
|
329
335
|
}
|
|
330
336
|
});
|
|
331
337
|
} catch {
|
|
@@ -352,27 +358,31 @@ async function runAsrCredential(method, env, authenticatedUserId, agentId, fetch
|
|
|
352
358
|
|
|
353
359
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/attachment.js
|
|
354
360
|
var ATTACHMENT_CREATE_UPLOAD_TOKEN_OPERATION = "attachment.createUploadToken";
|
|
355
|
-
async function runAttachmentUploadToken(method, env, authenticatedUserId, agentId, fetchImpl = fetch, envSelector) {
|
|
361
|
+
async function runAttachmentUploadToken(method, env, authenticatedUserId, agentId, fetchImpl = fetch, envSelector, gatewayAuth, logCtx) {
|
|
356
362
|
if (method !== "POST") {
|
|
357
363
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
358
364
|
}
|
|
359
365
|
if (!authenticatedUserId) {
|
|
360
366
|
return jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
|
|
361
367
|
}
|
|
362
|
-
|
|
368
|
+
let resolvedAuth;
|
|
369
|
+
try {
|
|
370
|
+
resolvedAuth = resolveGatewayAuthContext(gatewayAuth, env, logCtx, "attachment");
|
|
371
|
+
} catch {
|
|
372
|
+
return jsonError(500, "auth_unconfigured", "linkquegw AAK \u672A\u914D\u7F6E");
|
|
373
|
+
}
|
|
363
374
|
const gatewayBaseUrl = resolveLinkqueEndpoints(env, envSelector).knowledgeBaseUrl;
|
|
364
|
-
if (!
|
|
365
|
-
return jsonError(500, "gateway_unconfigured", "linkquegw
|
|
375
|
+
if (!gatewayBaseUrl) {
|
|
376
|
+
return jsonError(500, "gateway_unconfigured", "linkquegw \u5730\u5740\u672A\u914D\u7F6E");
|
|
366
377
|
}
|
|
367
378
|
let response;
|
|
368
379
|
try {
|
|
369
380
|
response = await fetchImpl(`${gatewayBaseUrl}/api/mass/token`, {
|
|
370
381
|
method: "POST",
|
|
371
382
|
headers: {
|
|
372
|
-
Authorization:
|
|
383
|
+
Authorization: resolvedAuth.authorizationHeader,
|
|
373
384
|
"content-type": "application/json",
|
|
374
|
-
"x-linkque-agent-id": agentId
|
|
375
|
-
"x-linkque-appbase-user-id": authenticatedUserId
|
|
385
|
+
"x-linkque-agent-id": agentId
|
|
376
386
|
},
|
|
377
387
|
body: JSON.stringify({ massType: 3 })
|
|
378
388
|
});
|
|
@@ -1143,28 +1153,6 @@ function controlError(status, code, message) {
|
|
|
1143
1153
|
return { status, body: { error: { code, message, status } } };
|
|
1144
1154
|
}
|
|
1145
1155
|
|
|
1146
|
-
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/auth.js
|
|
1147
|
-
function resolveAuthFromEnv(env = process.env, logCtx) {
|
|
1148
|
-
const log = (...a) => logCtx?.log?.("[auth-resolve]", ...a);
|
|
1149
|
-
const apiKey = env.LINKQUE_AGENT_ACCESS_KEY?.trim();
|
|
1150
|
-
if (!apiKey) {
|
|
1151
|
-
throw new Error("\u8BA4\u8BC1\u914D\u7F6E\u7F3A\u5931:LINKQUE_AGENT_ACCESS_KEY \u672A\u8BBE\u7F6E");
|
|
1152
|
-
}
|
|
1153
|
-
const provider = parseProvider(env.LINKQUE_MODEL_PROVIDER);
|
|
1154
|
-
log("agent \u8BA4\u8BC1\u89E3\u6790\u6210\u529F, provider=", provider, "apiKey=", maskSecret(apiKey), "source=env:LINKQUE_AGENT_ACCESS_KEY");
|
|
1155
|
-
return { auth: { provider, apiKey } };
|
|
1156
|
-
}
|
|
1157
|
-
function parseProvider(raw) {
|
|
1158
|
-
if (!raw)
|
|
1159
|
-
return EModelProvider.LINKQUE;
|
|
1160
|
-
const upper = raw.toUpperCase();
|
|
1161
|
-
if (upper === "LINKQUE")
|
|
1162
|
-
return EModelProvider.LINKQUE;
|
|
1163
|
-
if (upper === "TEST")
|
|
1164
|
-
return EModelProvider.TEST;
|
|
1165
|
-
throw new Error(`\u4E0D\u652F\u6301\u7684 LINKQUE_MODEL_PROVIDER="${raw}"(\u5F53\u524D\u652F\u6301:LINKQUE\u3001TEST)`);
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
1156
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/appbaseStore.js
|
|
1169
1157
|
function createAppBaseStore(databases, databaseId, tableId, ownerId) {
|
|
1170
1158
|
const permissions = rowPermissions(ownerId);
|
|
@@ -1599,7 +1587,7 @@ function historyError(status, code, message) {
|
|
|
1599
1587
|
|
|
1600
1588
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/homeData.js
|
|
1601
1589
|
var HOME_DATA_REQUEST_OPERATION = "homeData.request";
|
|
1602
|
-
async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD") {
|
|
1590
|
+
async function runHomeData(method, body, userId, deps = {}, env = process.env, envSelector = "PROD", gatewayAuth, logCtx) {
|
|
1603
1591
|
if (method.toUpperCase() !== "POST") {
|
|
1604
1592
|
return jsonError(405, "method_not_allowed", "\u4EC5\u652F\u6301 POST");
|
|
1605
1593
|
}
|
|
@@ -1609,8 +1597,10 @@ async function runHomeData(method, body, userId, deps = {}, env = process.env, e
|
|
|
1609
1597
|
const protocol = deps.protocol ?? getBakedProtocol();
|
|
1610
1598
|
let provider = deps.mcpServerProvider;
|
|
1611
1599
|
if (!provider) {
|
|
1612
|
-
|
|
1613
|
-
|
|
1600
|
+
let resolvedAuth;
|
|
1601
|
+
try {
|
|
1602
|
+
resolvedAuth = resolveGatewayAuthContext(gatewayAuth, env, logCtx, "home-data");
|
|
1603
|
+
} catch {
|
|
1614
1604
|
return jsonError(500, "auth_unconfigured", "LINKQUE_AGENT_ACCESS_KEY \u672A\u914D\u7F6E");
|
|
1615
1605
|
}
|
|
1616
1606
|
const { mcpSignEndpoint } = resolveLinkqueEndpoints(env, envSelector);
|
|
@@ -1619,7 +1609,7 @@ async function runHomeData(method, body, userId, deps = {}, env = process.env, e
|
|
|
1619
1609
|
agentId: protocol.agentId,
|
|
1620
1610
|
...mcpSignEndpoint ? { signEndpoint: mcpSignEndpoint } : {}
|
|
1621
1611
|
}),
|
|
1622
|
-
getAuthorizationHeader: async () =>
|
|
1612
|
+
getAuthorizationHeader: async () => resolvedAuth.authorizationHeader
|
|
1623
1613
|
});
|
|
1624
1614
|
}
|
|
1625
1615
|
const response = await executeHomeData({
|
|
@@ -1632,7 +1622,7 @@ async function runHomeData(method, body, userId, deps = {}, env = process.env, e
|
|
|
1632
1622
|
}
|
|
1633
1623
|
|
|
1634
1624
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chatConfig.js
|
|
1635
|
-
function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector) {
|
|
1625
|
+
function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth) {
|
|
1636
1626
|
const log = (...a) => logCtx?.log?.("[chat]", ...a);
|
|
1637
1627
|
const logError = (...a) => logCtx?.error?.("[chat]", ...a);
|
|
1638
1628
|
const protocol = deps?.protocol ?? getBakedProtocol();
|
|
@@ -1642,8 +1632,8 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
1642
1632
|
}
|
|
1643
1633
|
let resolved;
|
|
1644
1634
|
try {
|
|
1645
|
-
resolved =
|
|
1646
|
-
log("\u8BA4\u8BC1\u89E3\u6790\u6210\u529F, provider=", resolved.auth.provider, "model=", protocol.agent.model.defaultModel ?? "default");
|
|
1635
|
+
resolved = resolveGatewayAuthContext(gatewayAuth, env, logCtx, "chat");
|
|
1636
|
+
log("\u8BA4\u8BC1\u89E3\u6790\u6210\u529F, provider=", resolved.auth.provider, "mode=", resolved.mode, "model=", protocol.agent.model.defaultModel ?? "default");
|
|
1647
1637
|
} catch (err) {
|
|
1648
1638
|
logError("\u8BA4\u8BC1\u914D\u7F6E\u7F3A\u5931:", err);
|
|
1649
1639
|
return jsonError(500, "auth_unconfigured", err instanceof Error ? err.message : "\u8BA4\u8BC1\u914D\u7F6E\u7F3A\u5931");
|
|
@@ -1688,7 +1678,7 @@ function resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envS
|
|
|
1688
1678
|
}
|
|
1689
1679
|
chunkSize = storage.chunkSize;
|
|
1690
1680
|
}
|
|
1691
|
-
const mcpAuthorizationHeaderProvider = async () =>
|
|
1681
|
+
const mcpAuthorizationHeaderProvider = async () => resolved.authorizationHeader;
|
|
1692
1682
|
const { linkqueBaseUrl, knowledgeBaseUrl, mcpSignEndpoint } = resolveLinkqueEndpoints(env, envSelector);
|
|
1693
1683
|
const mcpConfigResolver = createAppbaseMcpConfigResolver({
|
|
1694
1684
|
agentId: protocol.agentId,
|
|
@@ -2035,7 +2025,7 @@ function shouldFlushConversationEvent(event) {
|
|
|
2035
2025
|
}
|
|
2036
2026
|
|
|
2037
2027
|
// ../linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js
|
|
2038
|
-
async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId) {
|
|
2028
|
+
async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth) {
|
|
2039
2029
|
const log = (...args) => logCtx?.log?.("[chat]", ...args);
|
|
2040
2030
|
const logError = (...args) => logCtx?.error?.("[chat]", ...args);
|
|
2041
2031
|
const guarded = guardChatRequest(method, bodyJSON, logCtx);
|
|
@@ -2043,7 +2033,7 @@ async function runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appw
|
|
|
2043
2033
|
return guarded;
|
|
2044
2034
|
const request = guarded;
|
|
2045
2035
|
const isPresentationRun = request.executionScope === "presentation";
|
|
2046
|
-
const cfg = resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector);
|
|
2036
|
+
const cfg = resolveChatDeps(env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, gatewayAuth);
|
|
2047
2037
|
if ("status" in cfg)
|
|
2048
2038
|
return cfg;
|
|
2049
2039
|
const leaseOwnerId = randomUUID3();
|
|
@@ -2265,18 +2255,18 @@ function waitForCancellationPoll(delayMs, signal) {
|
|
|
2265
2255
|
}
|
|
2266
2256
|
});
|
|
2267
2257
|
}
|
|
2268
|
-
async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId) {
|
|
2258
|
+
async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth) {
|
|
2269
2259
|
const operation = readOperation(bodyJSON);
|
|
2270
2260
|
if (operation === "cancelConversationRun") {
|
|
2271
2261
|
return runCancelConversation(method, bodyJSON, env, deps ? { protocol: deps.protocol, store: deps.historyStore } : void 0, logCtx, historyOwnerId, appwriteApiKey);
|
|
2272
2262
|
}
|
|
2273
2263
|
if (operation === ASR_CREATE_CREDENTIAL_OPERATION) {
|
|
2274
2264
|
const agentId = deps?.protocol?.agentId ?? getBakedProtocol().agentId;
|
|
2275
|
-
return runAsrCredential(method, env, historyOwnerId, agentId, void 0, envSelector);
|
|
2265
|
+
return runAsrCredential(method, env, historyOwnerId, agentId, void 0, envSelector, gatewayAuth, logCtx);
|
|
2276
2266
|
}
|
|
2277
2267
|
if (operation === ATTACHMENT_CREATE_UPLOAD_TOKEN_OPERATION) {
|
|
2278
2268
|
const agentId = deps?.protocol?.agentId ?? getBakedProtocol().agentId;
|
|
2279
|
-
return runAttachmentUploadToken(method, env, historyOwnerId, agentId, void 0, envSelector);
|
|
2269
|
+
return runAttachmentUploadToken(method, env, historyOwnerId, agentId, void 0, envSelector, gatewayAuth, logCtx);
|
|
2280
2270
|
}
|
|
2281
2271
|
if (operation === HOME_DATA_REQUEST_OPERATION) {
|
|
2282
2272
|
const request = readOperationPayload(bodyJSON);
|
|
@@ -2294,7 +2284,7 @@ async function runGateway(method, bodyJSON, env, deps, logCtx, historyOwnerId, a
|
|
|
2294
2284
|
if (operation) {
|
|
2295
2285
|
return jsonError(400, "operation_unsupported", `\u4E0D\u652F\u6301\u7684 operation: ${operation}`);
|
|
2296
2286
|
}
|
|
2297
|
-
return runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId);
|
|
2287
|
+
return runChat(method, bodyJSON, env, deps, logCtx, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth);
|
|
2298
2288
|
}
|
|
2299
2289
|
async function chat(ctx) {
|
|
2300
2290
|
let result;
|
|
@@ -2304,10 +2294,14 @@ async function chat(ctx) {
|
|
|
2304
2294
|
const appwriteApiKey = readAppwriteApiKey(ctx.req.headers);
|
|
2305
2295
|
const envSelector = readEnvSelector(ctx.req.headers);
|
|
2306
2296
|
const traceId = readTraceId(ctx.req.headers);
|
|
2307
|
-
|
|
2297
|
+
const gatewayAuth = historyOwnerId ? resolveLinkqueGatewayAuth(ctx.req.headers, process.env, {
|
|
2298
|
+
log: ctx.log,
|
|
2299
|
+
error: ctx.error
|
|
2300
|
+
}) : void 0;
|
|
2301
|
+
result = historyOwnerId ? await runGateway(ctx.req.method, bodyJSON, process.env, void 0, { log: ctx.log, error: ctx.error }, historyOwnerId, appwriteApiKey, envSelector, traceId, gatewayAuth) : jsonError(401, "authentication_required", "\u7F3A\u5C11 Appwrite \u8BA4\u8BC1\u7528\u6237");
|
|
2308
2302
|
} catch (err) {
|
|
2309
2303
|
ctx.error?.(err);
|
|
2310
|
-
result = {
|
|
2304
|
+
result = err instanceof LinkqueGatewayAuthError || err instanceof LinkqueGatewayAuthUnconfiguredError ? jsonError(err.status, err.code, err.message) : {
|
|
2311
2305
|
status: 500,
|
|
2312
2306
|
body: {
|
|
2313
2307
|
error: {
|
package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
runClientCapability,
|
|
4
4
|
runClientCapabilityCleanup,
|
|
5
5
|
runClientCapabilityResult
|
|
6
|
-
} from "../../chunk-
|
|
6
|
+
} from "../../chunk-IAT272TH.js";
|
|
7
7
|
import "../../chunk-MKS245OU.js";
|
|
8
8
|
import "../../chunk-YDKZZ6EH.js";
|
|
9
9
|
import "../../chunk-2NGJGNYB.js";
|
package/worker.js
CHANGED
|
@@ -16845,7 +16845,6 @@ function buildLinkquegwEventBody(context2) {
|
|
|
16845
16845
|
eventType,
|
|
16846
16846
|
eventId: context2.eventId,
|
|
16847
16847
|
eventTime: context2.timestamp,
|
|
16848
|
-
...commonParams.userId !== void 0 && { userId: commonParams.userId },
|
|
16849
16848
|
conversationId: commonParams.conversationId,
|
|
16850
16849
|
...commonParams.sessionId !== void 0 && {
|
|
16851
16850
|
sessionId: commonParams.sessionId
|
|
@@ -193399,9 +193398,13 @@ function extractFromWrapped(wrapped) {
|
|
|
193399
193398
|
}
|
|
193400
193399
|
return {
|
|
193401
193400
|
authorization: data.authorization,
|
|
193402
|
-
signatureContent: data.signatureContent
|
|
193401
|
+
signatureContent: data.signatureContent,
|
|
193402
|
+
...optionalUserId(data.userId)
|
|
193403
193403
|
};
|
|
193404
193404
|
}
|
|
193405
|
+
function optionalUserId(value) {
|
|
193406
|
+
return typeof value === "string" && value.trim() ? { userId: value.trim() } : {};
|
|
193407
|
+
}
|
|
193405
193408
|
async function safeText(resp) {
|
|
193406
193409
|
try {
|
|
193407
193410
|
return await resp.text();
|
|
@@ -193431,7 +193434,7 @@ var init_remoteSignatureSigner = __esm({
|
|
|
193431
193434
|
* 对一次出站请求取签名。
|
|
193432
193435
|
*
|
|
193433
193436
|
* @param req 见 {@link ISignRequest}(method/url/body)
|
|
193434
|
-
* @returns `{authorization, signatureContent}`
|
|
193437
|
+
* @returns `{authorization, signatureContent, userId?}`
|
|
193435
193438
|
* @throws 签名服务非 2xx / 鉴权头获取失败 / 响应缺字段时抛错(由 signingFetch 转 transport-error)。
|
|
193436
193439
|
*/
|
|
193437
193440
|
async sign(req) {
|
|
@@ -193467,7 +193470,8 @@ var init_remoteSignatureSigner = __esm({
|
|
|
193467
193470
|
}
|
|
193468
193471
|
return {
|
|
193469
193472
|
authorization: payload.authorization,
|
|
193470
|
-
signatureContent: payload.signatureContent
|
|
193473
|
+
signatureContent: payload.signatureContent,
|
|
193474
|
+
...optionalUserId(payload.userId)
|
|
193471
193475
|
};
|
|
193472
193476
|
}
|
|
193473
193477
|
};
|
|
@@ -195049,11 +195053,16 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
195049
195053
|
httpRequestUrl: targetUrl.pathname + targetUrl.search,
|
|
195050
195054
|
httpRequestBody: typeof init?.body === "string" ? init.body : ""
|
|
195051
195055
|
};
|
|
195052
|
-
const { authorization, signatureContent } = await signer.sign(req);
|
|
195056
|
+
const { authorization, signatureContent, userId } = await signer.sign(req);
|
|
195053
195057
|
const headers = new Headers(init?.headers);
|
|
195054
195058
|
headers.set("Authorization", authorization);
|
|
195055
195059
|
headers.set("X-Signature-Content", Buffer.from(signatureContent).toString("base64"));
|
|
195056
195060
|
headers.set("X-Alipay-SDK-Version", ALIPAY_SDK_VERSION);
|
|
195061
|
+
if (userId) {
|
|
195062
|
+
headers.set(OAGW_ALIPAY_UID_HEADER, userId);
|
|
195063
|
+
} else {
|
|
195064
|
+
headers.delete(OAGW_ALIPAY_UID_HEADER);
|
|
195065
|
+
}
|
|
195057
195066
|
const resp = await loggedFetch(url2, { ...init, headers });
|
|
195058
195067
|
if (onTraceId) {
|
|
195059
195068
|
try {
|
|
@@ -195071,12 +195080,13 @@ function createSigningFetch(signer, baseFetch = globalThis.fetch, onTraceId, deb
|
|
|
195071
195080
|
return resp;
|
|
195072
195081
|
};
|
|
195073
195082
|
}
|
|
195074
|
-
var ALIPAY_SDK_VERSION;
|
|
195083
|
+
var ALIPAY_SDK_VERSION, OAGW_ALIPAY_UID_HEADER;
|
|
195075
195084
|
var init_signingFetch = __esm({
|
|
195076
195085
|
"../linkque-agent-runtime/dist/esm/impl/mcp/alipay/signingFetch.js"() {
|
|
195077
195086
|
"use strict";
|
|
195078
195087
|
init_httpLoggingFetch();
|
|
195079
195088
|
ALIPAY_SDK_VERSION = "@alipay/open-mcp-server-2.0.4";
|
|
195089
|
+
OAGW_ALIPAY_UID_HEADER = "x-oagw-alipay-uid";
|
|
195080
195090
|
}
|
|
195081
195091
|
});
|
|
195082
195092
|
|