@acosmi/sdk-ts 2.16.0 → 2.17.0
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/CHANGELOG.md +14 -0
- package/dist/browser/index.mjs +30 -4
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +30 -4
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +31 -3
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +17 -3
- package/dist/node/index.d.ts +17 -3
- package/dist/node/index.mjs +30 -4
- package/dist/node/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/node/index.cjs
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __esm = (fn, res) => function __init() {
|
|
6
|
-
|
|
5
|
+
var __esm = (fn, res, err) => function __init() {
|
|
6
|
+
if (err) throw err[0];
|
|
7
|
+
try {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw err = [e], e;
|
|
11
|
+
}
|
|
7
12
|
};
|
|
8
13
|
var __export = (target, all) => {
|
|
9
14
|
for (var name in all)
|
|
@@ -1324,6 +1329,7 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1324
1329
|
};
|
|
1325
1330
|
const verifier = await generateCodeVerifier();
|
|
1326
1331
|
const challenge = await codeChallenge(verifier);
|
|
1332
|
+
const state = await generateState();
|
|
1327
1333
|
const http = await import('http');
|
|
1328
1334
|
const server = http.createServer();
|
|
1329
1335
|
await new Promise((resolve, reject) => {
|
|
@@ -1339,6 +1345,8 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1339
1345
|
codeResolver = resolve;
|
|
1340
1346
|
codeRejecter = reject;
|
|
1341
1347
|
});
|
|
1348
|
+
codePromise.catch(() => {
|
|
1349
|
+
});
|
|
1342
1350
|
server.on("request", (req, res) => {
|
|
1343
1351
|
const url = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
1344
1352
|
if (url.pathname !== "/callback") {
|
|
@@ -1346,6 +1354,16 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1346
1354
|
res.end();
|
|
1347
1355
|
return;
|
|
1348
1356
|
}
|
|
1357
|
+
const states = url.searchParams.getAll("state");
|
|
1358
|
+
const stateFailure = states.length === 0 ? "callback missing state" : states.length > 1 ? "callback carried multiple state values" : states[0] !== state ? "callback state does not match pending state" : null;
|
|
1359
|
+
if (stateFailure !== null) {
|
|
1360
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
1361
|
+
res.end(
|
|
1362
|
+
`<!DOCTYPE html><html><head><meta charset="utf-8"><title>\u6388\u6743\u5931\u8D25</title></head><body style="font-family:system-ui,sans-serif;text-align:center;padding:60px 20px"><h2>\u6388\u6743\u5931\u8D25</h2><p>\u56DE\u8C03\u6821\u9A8C\u672A\u901A\u8FC7, \u5DF2\u4E2D\u6B62\u767B\u5F55\u3002</p><p style="color:#888;font-size:14px">\u53EF\u4EE5\u5173\u95ED\u6B64\u7A97\u53E3\u3002</p></body></html>`
|
|
1363
|
+
);
|
|
1364
|
+
codeRejecter(new Error(`authorize: ${ErrStateMismatch}: ${stateFailure} (possible CSRF)`));
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1349
1367
|
const code = url.searchParams.get("code");
|
|
1350
1368
|
if (!code) {
|
|
1351
1369
|
const errMsg = url.searchParams.get("error_description") || url.searchParams.get("error") || "";
|
|
@@ -1376,6 +1394,7 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1376
1394
|
authURL.searchParams.set("response_type", "code");
|
|
1377
1395
|
authURL.searchParams.set("code_challenge", challenge);
|
|
1378
1396
|
authURL.searchParams.set("code_challenge_method", "S256");
|
|
1397
|
+
authURL.searchParams.set("state", state);
|
|
1379
1398
|
if (scopes.length > 0) {
|
|
1380
1399
|
authURL.searchParams.set("scope", scopes.join(" "));
|
|
1381
1400
|
}
|
|
@@ -1413,7 +1432,9 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1413
1432
|
return { result: { code, redirectURI }, verifier };
|
|
1414
1433
|
} catch (e) {
|
|
1415
1434
|
const msg = e instanceof Error ? e.message : String(e);
|
|
1416
|
-
if (msg.includes(
|
|
1435
|
+
if (msg.includes(ErrStateMismatch)) {
|
|
1436
|
+
emit({ type: EventError, err_code: ErrStateMismatch, error: msg });
|
|
1437
|
+
} else if (msg.includes("denied")) {
|
|
1417
1438
|
emit({ type: EventError, err_code: ErrAuthDenied, error: msg });
|
|
1418
1439
|
} else if (msg.includes("timed out")) {
|
|
1419
1440
|
emit({ type: EventError, err_code: ErrTimeout, error: msg });
|
|
@@ -1424,6 +1445,7 @@ async function authorize(meta, clientID, scopes, opts = {}) {
|
|
|
1424
1445
|
} finally {
|
|
1425
1446
|
if (abortHandler && signal) signal.removeEventListener("abort", abortHandler);
|
|
1426
1447
|
server.close();
|
|
1448
|
+
server.closeIdleConnections?.();
|
|
1427
1449
|
}
|
|
1428
1450
|
}
|
|
1429
1451
|
function htmlEscape(s) {
|
|
@@ -4171,6 +4193,7 @@ var ScopeChatBridge = "chat_bridge";
|
|
|
4171
4193
|
var ScopeChatBridgeRead = "chat_bridge:read";
|
|
4172
4194
|
var ScopeChatBridgeWrite = "chat_bridge:write";
|
|
4173
4195
|
var ScopeChatBridgeRotate = "chat_bridge:rotate";
|
|
4196
|
+
var ScopeAgentAccessManage = "agent_access:manage";
|
|
4174
4197
|
var ScopeModels = "models";
|
|
4175
4198
|
var ScopeModelsChat = "models:chat";
|
|
4176
4199
|
var ScopeEntitlements = "entitlements";
|
|
@@ -4199,6 +4222,9 @@ function remoteControlScopes() {
|
|
|
4199
4222
|
function chatBridgeScopes() {
|
|
4200
4223
|
return [ScopeChatBridge];
|
|
4201
4224
|
}
|
|
4225
|
+
function agentAccessScopes() {
|
|
4226
|
+
return [ScopeAgentAccessManage];
|
|
4227
|
+
}
|
|
4202
4228
|
|
|
4203
4229
|
// src/models/index.ts
|
|
4204
4230
|
init_types();
|
|
@@ -7854,6 +7880,7 @@ exports.RETRY_ADVICE_REASONS = RETRY_ADVICE_REASONS;
|
|
|
7854
7880
|
exports.RegionScopeEnum = RegionScopeEnum;
|
|
7855
7881
|
exports.ScopeAI = ScopeAI;
|
|
7856
7882
|
exports.ScopeAccount = ScopeAccount;
|
|
7883
|
+
exports.ScopeAgentAccessManage = ScopeAgentAccessManage;
|
|
7857
7884
|
exports.ScopeChatBridge = ScopeChatBridge;
|
|
7858
7885
|
exports.ScopeChatBridgeRead = ScopeChatBridgeRead;
|
|
7859
7886
|
exports.ScopeChatBridgeRotate = ScopeChatBridgeRotate;
|
|
@@ -7888,6 +7915,7 @@ exports.ScopeTools = ScopeTools;
|
|
|
7888
7915
|
exports.ScopeToolsExecute = ScopeToolsExecute;
|
|
7889
7916
|
exports.ScopeWallet = ScopeWallet;
|
|
7890
7917
|
exports.ScopeWalletReadonly = ScopeWalletReadonly;
|
|
7918
|
+
exports.agentAccessScopes = agentAccessScopes;
|
|
7891
7919
|
exports.allScopes = allScopes;
|
|
7892
7920
|
exports.anthropicResponseTextContent = anthropicResponseTextContent;
|
|
7893
7921
|
exports.anthropicResponseThinkingContent = anthropicResponseThinkingContent;
|