@rei-standard/amsg-server 2.6.0-next.17 → 2.6.0-next.19
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/README.md +7 -2
- package/dist/{chunk-QL6PMTIN.mjs → chunk-PRQHHRAK.mjs} +36 -11
- package/dist/{chunk-QHWGWKB4.cjs → chunk-XVJ7ZLZX.cjs} +36 -11
- package/dist/cloudflare.cjs +2 -2
- package/dist/cloudflare.mjs +1 -1
- package/dist/index.cjs +25 -25
- package/dist/index.mjs +1 -1
- package/dist/lib/llm-credentials-store.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -197,8 +197,13 @@ ctx / metadata / push 上)。
|
|
|
197
197
|
- fire 时的解析顺序:`credRefs.chat` → 查表;行没了 → 退回任务里的内联三件套
|
|
198
198
|
(如有);都没有 → 本轮失败,`lastError` 记 `CREDENTIAL_MISSING`,走常规重
|
|
199
199
|
试——补传凭据后下一轮自愈。
|
|
200
|
-
- hook 的 `ctx.scheduleTask()`
|
|
201
|
-
|
|
200
|
+
- hook 的 `ctx.scheduleTask()` 自排任务时按 **`credRefs.chat`** 分支:父任务带
|
|
201
|
+
chat 引用 → 复制整份引用、不复制凭据本体,换 Key 自动作用于整条自排链;父任
|
|
202
|
+
务只带非 chat 引用(如仅 emotion)→ 引用与内联三件套**都**复制(引用归 hook
|
|
203
|
+
用途,聊天凭据在内联那份里);存量内联任务照旧复制三件套。
|
|
204
|
+
- `prompted` / `auto` 任务 fire 时既无 `credRefs.chat` 也无内联三件套 → 按
|
|
205
|
+
`CREDENTIAL_MISSING` 失败进常规重试(不会被静默判成「不需要 LLM」)。
|
|
206
|
+
`instant` 保持「无凭据 = 纯推送 `userMessage`」的路由语义。
|
|
202
207
|
- 任务投影(`GET /messages` / hook 的 `ctx.task`)带 `credRefs`(只是名字,不
|
|
203
208
|
是机密),客户端对账用;凭据本体照旧被白名单挡在外面。
|
|
204
209
|
- 数据库侧是 `llm_credentials` 表(`(user_id, cred_id)` 主键,`encrypted_value`
|
|
@@ -270,6 +270,10 @@ function hasChatCredRef(payload) {
|
|
|
270
270
|
const refs = payload && payload.credRefs;
|
|
271
271
|
return !!refs && typeof refs === "object" && !Array.isArray(refs) && typeof refs.chat === "string" && refs.chat.length > 0;
|
|
272
272
|
}
|
|
273
|
+
function hasCredRefs(payload) {
|
|
274
|
+
const refs = payload && payload.credRefs;
|
|
275
|
+
return !!refs && typeof refs === "object" && !Array.isArray(refs) && Object.keys(refs).length > 0;
|
|
276
|
+
}
|
|
273
277
|
async function saveLlmCredentials({ db, userId, userKey, credentials }) {
|
|
274
278
|
const entries = [];
|
|
275
279
|
for (const { credId, value } of credentials) {
|
|
@@ -307,7 +311,17 @@ function codedError(code, message) {
|
|
|
307
311
|
return error;
|
|
308
312
|
}
|
|
309
313
|
async function resolveFireCredentials({ db, userId, userKey, decryptedPayload }) {
|
|
310
|
-
if (!hasChatCredRef(decryptedPayload))
|
|
314
|
+
if (!hasChatCredRef(decryptedPayload)) {
|
|
315
|
+
const type = decryptedPayload.messageType;
|
|
316
|
+
const hasInlineTrio = !!(decryptedPayload.apiUrl && decryptedPayload.apiKey && decryptedPayload.primaryModel);
|
|
317
|
+
if ((type === "prompted" || type === "auto") && !hasInlineTrio) {
|
|
318
|
+
throw codedError(
|
|
319
|
+
"CREDENTIAL_MISSING",
|
|
320
|
+
"\u4EFB\u52A1\u65E2\u65E0 credRefs.chat \u4E5F\u65E0\u5185\u8054 apiUrl / apiKey / primaryModel\uFF08\u8865\u4F20\u51ED\u636E\u6216\u66F4\u65B0\u4EFB\u52A1\u540E\uFF0C\u4E0B\u4E00\u8F6E\u91CD\u8BD5\u5373\u81EA\u6108\uFF09"
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
311
325
|
const credId = decryptedPayload.credRefs.chat;
|
|
312
326
|
if (supportsLlmCredentialsStore(db)) {
|
|
313
327
|
const resolved = await resolveLlmCredential({ db, userId, userKey, credId });
|
|
@@ -1179,10 +1193,15 @@ async function runAgenticFire({ task, decryptedPayload, userKey, ctx }) {
|
|
|
1179
1193
|
firstSendTime: nextSendAt,
|
|
1180
1194
|
recurrenceType,
|
|
1181
1195
|
tzId,
|
|
1182
|
-
//
|
|
1183
|
-
//
|
|
1184
|
-
//
|
|
1185
|
-
|
|
1196
|
+
// 凭据继承按 **credRefs.chat** 分支:
|
|
1197
|
+
// - 父带 chat 引用 → 复制整份引用、内联置空(换 Key 只要覆盖
|
|
1198
|
+
// llm_credentials 里那一行,自排链上的后代自动跟随——「自排链传旧
|
|
1199
|
+
// Key」那个洞的修口);
|
|
1200
|
+
// - 父只带非 chat 引用(如仅 emotion)→ 引用与内联**都**复制:引用归
|
|
1201
|
+
// hook 用途,聊天凭据在内联那份里,只复制引用会造出既无引用可解析
|
|
1202
|
+
// 又无内联的空壳后代;
|
|
1203
|
+
// - 父没带引用 → 照旧复制内联三件套。
|
|
1204
|
+
...hasChatCredRef(decryptedPayload) ? {
|
|
1186
1205
|
apiUrl: null,
|
|
1187
1206
|
apiKey: null,
|
|
1188
1207
|
primaryModel: null,
|
|
@@ -1191,7 +1210,7 @@ async function runAgenticFire({ task, decryptedPayload, userKey, ctx }) {
|
|
|
1191
1210
|
apiUrl: decryptedPayload.apiUrl || null,
|
|
1192
1211
|
apiKey: decryptedPayload.apiKey || null,
|
|
1193
1212
|
primaryModel: decryptedPayload.primaryModel || null,
|
|
1194
|
-
credRefs: null
|
|
1213
|
+
credRefs: hasCredRefs(decryptedPayload) ? { ...decryptedPayload.credRefs } : null
|
|
1195
1214
|
},
|
|
1196
1215
|
// 见文件头:fire-time hook 每次现场重组 prompt,旧 prompt 带过去只会在新
|
|
1197
1216
|
// 任务走回老链路时顶替宿主的意图。
|
|
@@ -3270,6 +3289,10 @@ var SQLITE_REQUIRED_SCHEMA = Object.freeze({
|
|
|
3270
3289
|
function escapeLikePrefix(prefix) {
|
|
3271
3290
|
return prefix.replace(/[\\%_]/g, (ch) => `\\${ch}`);
|
|
3272
3291
|
}
|
|
3292
|
+
var INTERNAL_TABLE_PREFIXES = ["sqlite_", "_cf_"];
|
|
3293
|
+
function isInternalTableName(name) {
|
|
3294
|
+
return INTERNAL_TABLE_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
3295
|
+
}
|
|
3273
3296
|
var D1Adapter = class {
|
|
3274
3297
|
/** @param {{ prepare: (sql: string) => any }} db - Cloudflare D1 binding */
|
|
3275
3298
|
constructor(db) {
|
|
@@ -3337,13 +3360,15 @@ var D1Adapter = class {
|
|
|
3337
3360
|
*/
|
|
3338
3361
|
async describeSchema() {
|
|
3339
3362
|
const tableRes = await this._db.prepare(
|
|
3340
|
-
`SELECT name FROM sqlite_master WHERE type = 'table'
|
|
3363
|
+
`SELECT name FROM sqlite_master WHERE type = 'table'`
|
|
3341
3364
|
).all();
|
|
3342
3365
|
const tables = {};
|
|
3343
3366
|
for (const row of tableRes.results || []) {
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3367
|
+
const name = String(row.name ?? "");
|
|
3368
|
+
if (isInternalTableName(name)) continue;
|
|
3369
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) continue;
|
|
3370
|
+
const columnRes = await this._db.prepare(`PRAGMA table_info(${name})`).all();
|
|
3371
|
+
tables[name] = (columnRes.results || []).map((column) => column.name);
|
|
3347
3372
|
}
|
|
3348
3373
|
const indexRes = await this._db.prepare(
|
|
3349
3374
|
`SELECT name FROM sqlite_master WHERE type = 'index' AND name IS NOT NULL`
|
|
@@ -4224,7 +4249,7 @@ function createClientStateHandler(ctx) {
|
|
|
4224
4249
|
}
|
|
4225
4250
|
|
|
4226
4251
|
// src/server/lib/version.js
|
|
4227
|
-
var SERVER_VERSION = true ? "2.6.0-next.
|
|
4252
|
+
var SERVER_VERSION = true ? "2.6.0-next.19" : "0.0.0-dev";
|
|
4228
4253
|
|
|
4229
4254
|
// src/server/handlers/capabilities.js
|
|
4230
4255
|
var SERVER_FEATURES = Object.freeze([
|
|
@@ -270,6 +270,10 @@ function hasChatCredRef(payload) {
|
|
|
270
270
|
const refs = payload && payload.credRefs;
|
|
271
271
|
return !!refs && typeof refs === "object" && !Array.isArray(refs) && typeof refs.chat === "string" && refs.chat.length > 0;
|
|
272
272
|
}
|
|
273
|
+
function hasCredRefs(payload) {
|
|
274
|
+
const refs = payload && payload.credRefs;
|
|
275
|
+
return !!refs && typeof refs === "object" && !Array.isArray(refs) && Object.keys(refs).length > 0;
|
|
276
|
+
}
|
|
273
277
|
async function saveLlmCredentials({ db, userId, userKey, credentials }) {
|
|
274
278
|
const entries = [];
|
|
275
279
|
for (const { credId, value } of credentials) {
|
|
@@ -307,7 +311,17 @@ function codedError(code, message) {
|
|
|
307
311
|
return error;
|
|
308
312
|
}
|
|
309
313
|
async function resolveFireCredentials({ db, userId, userKey, decryptedPayload }) {
|
|
310
|
-
if (!hasChatCredRef(decryptedPayload))
|
|
314
|
+
if (!hasChatCredRef(decryptedPayload)) {
|
|
315
|
+
const type = decryptedPayload.messageType;
|
|
316
|
+
const hasInlineTrio = !!(decryptedPayload.apiUrl && decryptedPayload.apiKey && decryptedPayload.primaryModel);
|
|
317
|
+
if ((type === "prompted" || type === "auto") && !hasInlineTrio) {
|
|
318
|
+
throw codedError(
|
|
319
|
+
"CREDENTIAL_MISSING",
|
|
320
|
+
"\u4EFB\u52A1\u65E2\u65E0 credRefs.chat \u4E5F\u65E0\u5185\u8054 apiUrl / apiKey / primaryModel\uFF08\u8865\u4F20\u51ED\u636E\u6216\u66F4\u65B0\u4EFB\u52A1\u540E\uFF0C\u4E0B\u4E00\u8F6E\u91CD\u8BD5\u5373\u81EA\u6108\uFF09"
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
311
325
|
const credId = decryptedPayload.credRefs.chat;
|
|
312
326
|
if (supportsLlmCredentialsStore(db)) {
|
|
313
327
|
const resolved = await resolveLlmCredential({ db, userId, userKey, credId });
|
|
@@ -1179,10 +1193,15 @@ async function runAgenticFire({ task, decryptedPayload, userKey, ctx }) {
|
|
|
1179
1193
|
firstSendTime: nextSendAt,
|
|
1180
1194
|
recurrenceType,
|
|
1181
1195
|
tzId,
|
|
1182
|
-
//
|
|
1183
|
-
//
|
|
1184
|
-
//
|
|
1185
|
-
|
|
1196
|
+
// 凭据继承按 **credRefs.chat** 分支:
|
|
1197
|
+
// - 父带 chat 引用 → 复制整份引用、内联置空(换 Key 只要覆盖
|
|
1198
|
+
// llm_credentials 里那一行,自排链上的后代自动跟随——「自排链传旧
|
|
1199
|
+
// Key」那个洞的修口);
|
|
1200
|
+
// - 父只带非 chat 引用(如仅 emotion)→ 引用与内联**都**复制:引用归
|
|
1201
|
+
// hook 用途,聊天凭据在内联那份里,只复制引用会造出既无引用可解析
|
|
1202
|
+
// 又无内联的空壳后代;
|
|
1203
|
+
// - 父没带引用 → 照旧复制内联三件套。
|
|
1204
|
+
...hasChatCredRef(decryptedPayload) ? {
|
|
1186
1205
|
apiUrl: null,
|
|
1187
1206
|
apiKey: null,
|
|
1188
1207
|
primaryModel: null,
|
|
@@ -1191,7 +1210,7 @@ async function runAgenticFire({ task, decryptedPayload, userKey, ctx }) {
|
|
|
1191
1210
|
apiUrl: decryptedPayload.apiUrl || null,
|
|
1192
1211
|
apiKey: decryptedPayload.apiKey || null,
|
|
1193
1212
|
primaryModel: decryptedPayload.primaryModel || null,
|
|
1194
|
-
credRefs: null
|
|
1213
|
+
credRefs: hasCredRefs(decryptedPayload) ? { ...decryptedPayload.credRefs } : null
|
|
1195
1214
|
},
|
|
1196
1215
|
// 见文件头:fire-time hook 每次现场重组 prompt,旧 prompt 带过去只会在新
|
|
1197
1216
|
// 任务走回老链路时顶替宿主的意图。
|
|
@@ -3270,6 +3289,10 @@ var SQLITE_REQUIRED_SCHEMA = Object.freeze({
|
|
|
3270
3289
|
function escapeLikePrefix(prefix) {
|
|
3271
3290
|
return prefix.replace(/[\\%_]/g, (ch) => `\\${ch}`);
|
|
3272
3291
|
}
|
|
3292
|
+
var INTERNAL_TABLE_PREFIXES = ["sqlite_", "_cf_"];
|
|
3293
|
+
function isInternalTableName(name) {
|
|
3294
|
+
return INTERNAL_TABLE_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
3295
|
+
}
|
|
3273
3296
|
var D1Adapter = class {
|
|
3274
3297
|
/** @param {{ prepare: (sql: string) => any }} db - Cloudflare D1 binding */
|
|
3275
3298
|
constructor(db) {
|
|
@@ -3337,13 +3360,15 @@ var D1Adapter = class {
|
|
|
3337
3360
|
*/
|
|
3338
3361
|
async describeSchema() {
|
|
3339
3362
|
const tableRes = await this._db.prepare(
|
|
3340
|
-
`SELECT name FROM sqlite_master WHERE type = 'table'
|
|
3363
|
+
`SELECT name FROM sqlite_master WHERE type = 'table'`
|
|
3341
3364
|
).all();
|
|
3342
3365
|
const tables = {};
|
|
3343
3366
|
for (const row of tableRes.results || []) {
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3367
|
+
const name = String(_nullishCoalesce(row.name, () => ( "")));
|
|
3368
|
+
if (isInternalTableName(name)) continue;
|
|
3369
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) continue;
|
|
3370
|
+
const columnRes = await this._db.prepare(`PRAGMA table_info(${name})`).all();
|
|
3371
|
+
tables[name] = (columnRes.results || []).map((column) => column.name);
|
|
3347
3372
|
}
|
|
3348
3373
|
const indexRes = await this._db.prepare(
|
|
3349
3374
|
`SELECT name FROM sqlite_master WHERE type = 'index' AND name IS NOT NULL`
|
|
@@ -4224,7 +4249,7 @@ function createClientStateHandler(ctx) {
|
|
|
4224
4249
|
}
|
|
4225
4250
|
|
|
4226
4251
|
// src/server/lib/version.js
|
|
4227
|
-
var SERVER_VERSION = true ? "2.6.0-next.
|
|
4252
|
+
var SERVER_VERSION = true ? "2.6.0-next.19" : "0.0.0-dev";
|
|
4228
4253
|
|
|
4229
4254
|
// src/server/handlers/capabilities.js
|
|
4230
4255
|
var SERVER_FEATURES = Object.freeze([
|
package/dist/cloudflare.cjs
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _chunkXVJ7ZLZXcjs = require('./chunk-XVJ7ZLZX.cjs');
|
|
28
28
|
require('./chunk-V6NZQ22S.cjs');
|
|
29
29
|
|
|
30
30
|
|
|
@@ -52,4 +52,4 @@ require('./chunk-V6NZQ22S.cjs');
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
exports.MAX_PUSH_PAYLOAD_BYTES =
|
|
55
|
+
exports.MAX_PUSH_PAYLOAD_BYTES = _chunkXVJ7ZLZXcjs.MAX_PUSH_PAYLOAD_BYTES; exports.NonRetryableError = _chunkXVJ7ZLZXcjs.NonRetryableError; exports.PUSH_ENVELOPE_RESERVED_BYTES = _chunkXVJ7ZLZXcjs.PUSH_ENVELOPE_RESERVED_BYTES; exports.SCHEMA_VERSION = _chunkXVJ7ZLZXcjs.SCHEMA_VERSION; exports.WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES = _chunkXVJ7ZLZXcjs.WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES; exports.WEB_PUSH_MAX_BODY_BYTES = _chunkXVJ7ZLZXcjs.WEB_PUSH_MAX_BODY_BYTES; exports.advanceOccurrence = _chunkXVJ7ZLZXcjs.advanceOccurrence; exports.createD1Adapter = _chunkXVJ7ZLZXcjs.createD1Adapter; exports.createSingleUserCloudflareWorker = _chunkXVJ7ZLZXcjs.createSingleUserCloudflareWorker; exports.createSingleUserServer = _chunkXVJ7ZLZXcjs.createSingleUserServer; exports.createWebCryptoWebPush = _chunkXVJ7ZLZXcjs.createWebCryptoWebPush; exports.decryptFromStorage = _chunkXVJ7ZLZXcjs.decryptFromStorage; exports.decryptPayload = _chunkXVJ7ZLZXcjs.decryptPayload; exports.deriveUserEncryptionKey = _chunkXVJ7ZLZXcjs.deriveUserEncryptionKey; exports.encryptForStorage = _chunkXVJ7ZLZXcjs.encryptForStorage; exports.ensureSchema = _chunkXVJ7ZLZXcjs.ensureSchema; exports.getSchemaVersion = _chunkXVJ7ZLZXcjs.getSchemaVersion; exports.isNonRetryableError = _chunkXVJ7ZLZXcjs.isNonRetryableError; exports.isValidTimeZoneId = _chunkXVJ7ZLZXcjs.isValidTimeZoneId; exports.measurePushPayload = _chunkXVJ7ZLZXcjs.measurePushPayload; exports.nextFutureOccurrence = _chunkXVJ7ZLZXcjs.nextFutureOccurrence; exports.planNextOccurrence = _chunkXVJ7ZLZXcjs.planNextOccurrence; exports.runScheduledTick = _chunkXVJ7ZLZXcjs.runScheduledTick; exports.runTask = _chunkXVJ7ZLZXcjs.runTask; exports.summarizeErrorCause = _chunkXVJ7ZLZXcjs.summarizeErrorCause;
|
package/dist/cloudflare.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
var
|
|
70
|
+
var _chunkXVJ7ZLZXcjs = require('./chunk-XVJ7ZLZX.cjs');
|
|
71
71
|
require('./chunk-V6NZQ22S.cjs');
|
|
72
72
|
|
|
73
73
|
// src/server/adapters/factory.js
|
|
@@ -101,7 +101,7 @@ async function createAdapter(config) {
|
|
|
101
101
|
// src/server/handlers/init-tenant.js
|
|
102
102
|
function createInitTenantHandler(ctx) {
|
|
103
103
|
async function POST(headers, body) {
|
|
104
|
-
const initSecret =
|
|
104
|
+
const initSecret = _chunkXVJ7ZLZXcjs.getHeader.call(void 0, headers, "x-init-secret");
|
|
105
105
|
if (ctx.tenant.initSecret && initSecret !== ctx.tenant.initSecret) {
|
|
106
106
|
return {
|
|
107
107
|
status: 401,
|
|
@@ -114,7 +114,7 @@ function createInitTenantHandler(ctx) {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
const parsed =
|
|
117
|
+
const parsed = _chunkXVJ7ZLZXcjs.parseJsonBody.call(void 0, body);
|
|
118
118
|
if (!parsed.ok) {
|
|
119
119
|
return {
|
|
120
120
|
status: 400,
|
|
@@ -128,7 +128,7 @@ function createInitTenantHandler(ctx) {
|
|
|
128
128
|
const tenantId = payload.tenantId || void 0;
|
|
129
129
|
const driver = payload.driver;
|
|
130
130
|
const databaseUrl = payload.databaseUrl || payload.connectionString;
|
|
131
|
-
if (tenantId && !
|
|
131
|
+
if (tenantId && !_chunkXVJ7ZLZXcjs.isValidUUIDv4.call(void 0, tenantId)) {
|
|
132
132
|
return {
|
|
133
133
|
status: 400,
|
|
134
134
|
body: {
|
|
@@ -248,7 +248,7 @@ function createSendNotificationsHandler(ctx) {
|
|
|
248
248
|
}
|
|
249
249
|
};
|
|
250
250
|
}
|
|
251
|
-
const data = await
|
|
251
|
+
const data = await _chunkXVJ7ZLZXcjs.runScheduledTick.call(void 0, { ...ctx, db, masterKey });
|
|
252
252
|
return { status: 200, body: { success: true, data } };
|
|
253
253
|
}
|
|
254
254
|
return { POST };
|
|
@@ -270,16 +270,16 @@ function encryptConfig(config, kekBuffer) {
|
|
|
270
270
|
const plaintext = Buffer.from(JSON.stringify(config), "utf8");
|
|
271
271
|
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
272
272
|
const authTag = cipher.getAuthTag();
|
|
273
|
-
return `v1.${
|
|
273
|
+
return `v1.${_chunkXVJ7ZLZXcjs.bytesToBase64Url.call(void 0, iv)}.${_chunkXVJ7ZLZXcjs.bytesToBase64Url.call(void 0, authTag)}.${_chunkXVJ7ZLZXcjs.bytesToBase64Url.call(void 0, ciphertext)}`;
|
|
274
274
|
}
|
|
275
275
|
function decryptConfig(encrypted, kekBuffer) {
|
|
276
276
|
const parts = String(encrypted || "").split(".");
|
|
277
277
|
if (parts.length !== 4 || parts[0] !== "v1") {
|
|
278
278
|
throw new Error("INVALID_TENANT_CONFIG");
|
|
279
279
|
}
|
|
280
|
-
const iv =
|
|
281
|
-
const authTag =
|
|
282
|
-
const ciphertext =
|
|
280
|
+
const iv = _chunkXVJ7ZLZXcjs.base64UrlToBytes.call(void 0, parts[1]);
|
|
281
|
+
const authTag = _chunkXVJ7ZLZXcjs.base64UrlToBytes.call(void 0, parts[2]);
|
|
282
|
+
const ciphertext = _chunkXVJ7ZLZXcjs.base64UrlToBytes.call(void 0, parts[3]);
|
|
283
283
|
const decipher = _crypto.createDecipheriv.call(void 0, "aes-256-gcm", kekBuffer, iv);
|
|
284
284
|
decipher.setAuthTag(authTag);
|
|
285
285
|
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
|
|
@@ -347,7 +347,7 @@ function createTenantBlobStore(options) {
|
|
|
347
347
|
// src/server/tenant/token.js
|
|
348
348
|
|
|
349
349
|
function sign(input, secret) {
|
|
350
|
-
return
|
|
350
|
+
return _chunkXVJ7ZLZXcjs.bytesToBase64Url.call(void 0, _crypto.createHmac.call(void 0, "sha256", secret).update(input).digest());
|
|
351
351
|
}
|
|
352
352
|
function nowEpochSeconds() {
|
|
353
353
|
return Math.floor(Date.now() / 1e3);
|
|
@@ -363,8 +363,8 @@ function createTenantToken(params, secret) {
|
|
|
363
363
|
v: 1
|
|
364
364
|
};
|
|
365
365
|
const header = { alg: "HS256", typ: "JWT" };
|
|
366
|
-
const encodedHeader =
|
|
367
|
-
const encodedPayload =
|
|
366
|
+
const encodedHeader = _chunkXVJ7ZLZXcjs.bytesToBase64Url.call(void 0, _chunkXVJ7ZLZXcjs.utf8.call(void 0, JSON.stringify(header)));
|
|
367
|
+
const encodedPayload = _chunkXVJ7ZLZXcjs.bytesToBase64Url.call(void 0, _chunkXVJ7ZLZXcjs.utf8.call(void 0, JSON.stringify(payload)));
|
|
368
368
|
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
369
369
|
const signature = sign(signingInput, secret);
|
|
370
370
|
return `${signingInput}.${signature}`;
|
|
@@ -383,17 +383,17 @@ function verifyTenantToken(token, secret, options = {}) {
|
|
|
383
383
|
let receivedBytes;
|
|
384
384
|
let expectedBytes;
|
|
385
385
|
try {
|
|
386
|
-
receivedBytes =
|
|
387
|
-
expectedBytes =
|
|
386
|
+
receivedBytes = _chunkXVJ7ZLZXcjs.base64UrlToBytes.call(void 0, receivedSignature);
|
|
387
|
+
expectedBytes = _chunkXVJ7ZLZXcjs.base64UrlToBytes.call(void 0, expectedSignature);
|
|
388
388
|
} catch (e) {
|
|
389
389
|
throw new Error("INVALID_TENANT_AUTH");
|
|
390
390
|
}
|
|
391
|
-
if (!
|
|
391
|
+
if (!_chunkXVJ7ZLZXcjs.timingSafeEqualBytes.call(void 0, receivedBytes, expectedBytes)) {
|
|
392
392
|
throw new Error("INVALID_TENANT_AUTH");
|
|
393
393
|
}
|
|
394
394
|
let payload;
|
|
395
395
|
try {
|
|
396
|
-
payload = JSON.parse(
|
|
396
|
+
payload = JSON.parse(_chunkXVJ7ZLZXcjs.utf8Decode.call(void 0, _chunkXVJ7ZLZXcjs.base64UrlToBytes.call(void 0, encodedPayload)));
|
|
397
397
|
} catch (e2) {
|
|
398
398
|
throw new Error("INVALID_TENANT_AUTH");
|
|
399
399
|
}
|
|
@@ -613,15 +613,15 @@ async function createReiServer(config) {
|
|
|
613
613
|
return {
|
|
614
614
|
handlers: {
|
|
615
615
|
initTenant: createInitTenantHandler(ctx),
|
|
616
|
-
getUserKey:
|
|
617
|
-
scheduleMessage:
|
|
616
|
+
getUserKey: _chunkXVJ7ZLZXcjs.createGetUserKeyHandler.call(void 0, ctx),
|
|
617
|
+
scheduleMessage: _chunkXVJ7ZLZXcjs.createScheduleMessageHandler.call(void 0, ctx),
|
|
618
618
|
sendNotifications: createSendNotificationsHandler(ctx),
|
|
619
|
-
updateMessage:
|
|
620
|
-
cancelMessage:
|
|
621
|
-
messages:
|
|
622
|
-
getMessage:
|
|
623
|
-
pushSubscription:
|
|
624
|
-
llmCredentials:
|
|
619
|
+
updateMessage: _chunkXVJ7ZLZXcjs.createUpdateMessageHandler.call(void 0, ctx),
|
|
620
|
+
cancelMessage: _chunkXVJ7ZLZXcjs.createCancelMessageHandler.call(void 0, ctx),
|
|
621
|
+
messages: _chunkXVJ7ZLZXcjs.createMessagesHandler.call(void 0, ctx),
|
|
622
|
+
getMessage: _chunkXVJ7ZLZXcjs.createGetMessageHandler.call(void 0, ctx),
|
|
623
|
+
pushSubscription: _chunkXVJ7ZLZXcjs.createPushSubscriptionHandler.call(void 0, ctx),
|
|
624
|
+
llmCredentials: _chunkXVJ7ZLZXcjs.createLlmCredentialsHandler.call(void 0, ctx)
|
|
625
625
|
}
|
|
626
626
|
};
|
|
627
627
|
}
|
|
@@ -683,4 +683,4 @@ async function createReiServer(config) {
|
|
|
683
683
|
|
|
684
684
|
|
|
685
685
|
|
|
686
|
-
exports.CORS_ALLOW_HEADERS =
|
|
686
|
+
exports.CORS_ALLOW_HEADERS = _chunkXVJ7ZLZXcjs.CORS_ALLOW_HEADERS; exports.CORS_ALLOW_METHODS = _chunkXVJ7ZLZXcjs.CORS_ALLOW_METHODS; exports.CRED_ID_MAX_LENGTH = _chunkXVJ7ZLZXcjs.CRED_ID_MAX_LENGTH; exports.CRED_PUT_BATCH_MAX = _chunkXVJ7ZLZXcjs.CRED_PUT_BATCH_MAX; exports.CRED_REFS_MAX_ENTRIES = _chunkXVJ7ZLZXcjs.CRED_REFS_MAX_ENTRIES; exports.CRED_ROWS_PER_USER_MAX = _chunkXVJ7ZLZXcjs.CRED_ROWS_PER_USER_MAX; exports.DEFAULT_CLAIM_LEASE_MS = _chunkXVJ7ZLZXcjs.DEFAULT_CLAIM_LEASE_MS; exports.DEFAULT_HEARTBEAT_LEASE_TTL_MS = _chunkXVJ7ZLZXcjs.DEFAULT_HEARTBEAT_LEASE_TTL_MS; exports.DEFAULT_LEASE_HEARTBEAT_MS = _chunkXVJ7ZLZXcjs.DEFAULT_LEASE_HEARTBEAT_MS; exports.DEFAULT_MAX_SCHEDULED_TASKS_PER_FIRE = _chunkXVJ7ZLZXcjs.DEFAULT_MAX_SCHEDULED_TASKS_PER_FIRE; exports.DEFAULT_MAX_TOOL_ITERATIONS = _chunkXVJ7ZLZXcjs.DEFAULT_MAX_TOOL_ITERATIONS; exports.DEFAULT_TOTAL_TIMEOUT_MS = _chunkXVJ7ZLZXcjs.DEFAULT_TOTAL_TIMEOUT_MS; exports.MAX_PUSH_PAYLOAD_BYTES = _chunkXVJ7ZLZXcjs.MAX_PUSH_PAYLOAD_BYTES; exports.MIN_SCHEDULE_LEAD_MS = _chunkXVJ7ZLZXcjs.MIN_SCHEDULE_LEAD_MS; exports.NonRetryableError = _chunkXVJ7ZLZXcjs.NonRetryableError; exports.PUSH_ENVELOPE_RESERVED_BYTES = _chunkXVJ7ZLZXcjs.PUSH_ENVELOPE_RESERVED_BYTES; exports.SCHEMA_VERSION = _chunkXVJ7ZLZXcjs.SCHEMA_VERSION; exports.WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES = _chunkXVJ7ZLZXcjs.WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES; exports.WEB_PUSH_MAX_BODY_BYTES = _chunkXVJ7ZLZXcjs.WEB_PUSH_MAX_BODY_BYTES; exports.advanceOccurrence = _chunkXVJ7ZLZXcjs.advanceOccurrence; exports.createAdapter = createAdapter; exports.createD1Adapter = _chunkXVJ7ZLZXcjs.createD1Adapter; exports.createReiServer = createReiServer; exports.createSingleUserCloudflareWorker = _chunkXVJ7ZLZXcjs.createSingleUserCloudflareWorker; exports.createSingleUserServer = _chunkXVJ7ZLZXcjs.createSingleUserServer; exports.createTenantToken = createTenantToken; exports.createWebCryptoWebPush = _chunkXVJ7ZLZXcjs.createWebCryptoWebPush; exports.decryptFromStorage = _chunkXVJ7ZLZXcjs.decryptFromStorage; exports.decryptPayload = _chunkXVJ7ZLZXcjs.decryptPayload; exports.deriveUserEncryptionKey = _chunkXVJ7ZLZXcjs.deriveUserEncryptionKey; exports.encryptForStorage = _chunkXVJ7ZLZXcjs.encryptForStorage; exports.ensureSchema = _chunkXVJ7ZLZXcjs.ensureSchema; exports.getSchemaVersion = _chunkXVJ7ZLZXcjs.getSchemaVersion; exports.hasChatCredRef = _chunkXVJ7ZLZXcjs.hasChatCredRef; exports.isNonRetryableError = _chunkXVJ7ZLZXcjs.isNonRetryableError; exports.isValidCredId = _chunkXVJ7ZLZXcjs.isValidCredId; exports.isValidISO8601 = _chunkXVJ7ZLZXcjs.isValidISO8601; exports.isValidTimeZoneId = _chunkXVJ7ZLZXcjs.isValidTimeZoneId; exports.isValidUUID = _chunkXVJ7ZLZXcjs.isValidUUID; exports.isValidUUIDv4 = _chunkXVJ7ZLZXcjs.isValidUUIDv4; exports.isValidUrl = _chunkXVJ7ZLZXcjs.isValidUrl; exports.measurePushPayload = _chunkXVJ7ZLZXcjs.measurePushPayload; exports.nextFutureOccurrence = _chunkXVJ7ZLZXcjs.nextFutureOccurrence; exports.planNextOccurrence = _chunkXVJ7ZLZXcjs.planNextOccurrence; exports.resolveLlmCredential = _chunkXVJ7ZLZXcjs.resolveLlmCredential; exports.runScheduledTick = _chunkXVJ7ZLZXcjs.runScheduledTick; exports.runTask = _chunkXVJ7ZLZXcjs.runTask; exports.sanitizeErrorSummary = _chunkXVJ7ZLZXcjs.sanitizeErrorSummary; exports.summarizeErrorCause = _chunkXVJ7ZLZXcjs.summarizeErrorCause; exports.supportsLlmCredentialsStore = _chunkXVJ7ZLZXcjs.supportsLlmCredentialsStore; exports.validateAvatarUrl = _chunkXVJ7ZLZXcjs.validateAvatarUrl; exports.validateCredRefs = _chunkXVJ7ZLZXcjs.validateCredRefs; exports.validateCredValue = _chunkXVJ7ZLZXcjs.validateCredValue; exports.validateLlmMessagesArray = _chunkXVJ7ZLZXcjs.validateLlmMessagesArray; exports.validateScheduleMessagePayload = _chunkXVJ7ZLZXcjs.validateScheduleMessagePayload; exports.validateSplitPattern = _chunkXVJ7ZLZXcjs.validateSplitPattern; exports.verifyTenantToken = verifyTenantToken;
|
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,14 @@ export function validateCredRefs(credRefs: unknown): string | null;
|
|
|
32
32
|
* @returns {boolean}
|
|
33
33
|
*/
|
|
34
34
|
export function hasChatCredRef(payload: any | null | undefined): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* payload 带没带非空的 credRefs 映射(不管里面是什么 purpose)。自排继承要在
|
|
37
|
+
* 「有 chat 引用」和「只有非 chat 引用」之间分支,这是后者用的那半个判据。
|
|
38
|
+
*
|
|
39
|
+
* @param {Object|null|undefined} payload
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
export function hasCredRefs(payload: any | null | undefined): boolean;
|
|
35
43
|
/**
|
|
36
44
|
* 批量写入(覆盖)这个用户的凭据。value 在这里加密。
|
|
37
45
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rei-standard/amsg-server",
|
|
3
|
-
"version": "2.6.0-next.
|
|
3
|
+
"version": "2.6.0-next.19",
|
|
4
4
|
"description": "ReiStandard Active Messaging server SDK with pluggable database adapters. Three-axis push schema (messageKind / messageType / messageSubtype) from @rei-standard/amsg-shared. Auto-emits ReasoningPush when the LLM response carries reasoning_content.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|