@rei-standard/amsg-server 2.5.1 → 2.5.2
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 +3 -1
- package/dist/index.d.cts +32 -15
- package/dist/index.d.ts +32 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,9 @@ const rei = await createReiServer({
|
|
|
54
54
|
|
|
55
55
|
## 关于 `messageType: 'instant'`
|
|
56
56
|
|
|
57
|
-
>
|
|
57
|
+
> **两条 instant 路径,按各自特点选一条(都是正式支持路径):**
|
|
58
|
+
> - **本端点的 `messageType: 'instant'`**(create task → process by UUID → delete task):任务先写进数据库再处理,投递不绑在请求连接上——客户端断开也没关系,任务行还在,能继续跑、能重试,想跑多久跑多久。适合**有数据库、需要长时间生成或保证消息零丢失**的场景。
|
|
59
|
+
> - **[@rei-standard/amsg-instant](https://github.com/Tosd0/ReiStandard/blob/main/packages/rei-standard-amsg/instant/README.md)**:纯 SSE 流 + Web Push backup,不需要数据库,适合无状态边缘运行时(如 Cloudflare Workers)。它的处理挂在响应连接上,客户端一断开就只剩平台给的那点宽限期把活干完(Deno Deploy 实测 ≈20-30s),所以适合**能快速跑完的短即时消息**。
|
|
58
60
|
|
|
59
61
|
## AI 接口 `apiUrl` 约束
|
|
60
62
|
|
package/dist/index.d.cts
CHANGED
|
@@ -801,13 +801,13 @@ function isUniqueViolation(error) {
|
|
|
801
801
|
* ReiStandard amsg-server v2.4.0
|
|
802
802
|
*
|
|
803
803
|
* Handles single message content generation and Web Push delivery for
|
|
804
|
-
* scheduled tasks (`fixed` / `prompted` / `auto`) and the
|
|
805
|
-
*
|
|
804
|
+
* scheduled tasks (`fixed` / `prompted` / `auto`) and the
|
|
805
|
+
* in-server instant path (`messageType: 'instant'`).
|
|
806
806
|
*
|
|
807
807
|
* Push wire shape comes from `@rei-standard/amsg-shared`'s
|
|
808
808
|
* discriminated union (`AmsgPush`). The SW (`@rei-standard/amsg-sw`)
|
|
809
809
|
* routes on `messageKind`. Server-driven pushes always carry
|
|
810
|
-
* `source: 'instant'` (for the
|
|
810
|
+
* `source: 'instant'` (for the in-server instant path) or
|
|
811
811
|
* `source: 'scheduled'` (for everything else).
|
|
812
812
|
*
|
|
813
813
|
* v2.4.0: when the LLM response carries non-empty
|
|
@@ -1004,7 +1004,7 @@ async function processSingleMessage(task, ctx, providedMasterKey) {
|
|
|
1004
1004
|
// `messageId` format — deterministic when we have a task.id so a
|
|
1005
1005
|
// retry produces the same id for the same (task, sentence) pair
|
|
1006
1006
|
// (downstream dedupers can key on it). Falls back to a UUID for
|
|
1007
|
-
// the
|
|
1007
|
+
// the in-server instant path that has no row id.
|
|
1008
1008
|
const messageIdBase = task.id != null
|
|
1009
1009
|
? `msg_task_${task.id}`
|
|
1010
1010
|
: `msg_${randomUUID()}_instant`;
|
|
@@ -1398,12 +1398,20 @@ function createScheduleMessageHandler(ctx) {
|
|
|
1398
1398
|
const encryptedPayload = encryptForStorage(JSON.stringify(fullTaskData), userKey);
|
|
1399
1399
|
|
|
1400
1400
|
/**
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
*
|
|
1401
|
+
* In-server instant path. Delivers an instant message through this
|
|
1402
|
+
* server's own task queue (create task → process by UUID → delete task).
|
|
1403
|
+
* The task is written to the database before processing, so delivery is
|
|
1404
|
+
* not tied to the request connection: even if the client disconnects, the
|
|
1405
|
+
* row stays and the generation keeps running (and can be retried) for as
|
|
1406
|
+
* long as it needs. Use this when you have a database and want long or
|
|
1407
|
+
* guaranteed-complete generations with no dropped messages.
|
|
1408
|
+
*
|
|
1409
|
+
* The stateless alternative is `@rei-standard/amsg-instant`: it streams
|
|
1410
|
+
* over SSE with a Web Push backup and needs no database, which makes it a
|
|
1411
|
+
* good fit for edge runtimes (e.g. Cloudflare Workers). Its work rides the
|
|
1412
|
+
* response connection, so after the client disconnects it only has the
|
|
1413
|
+
* platform's brief grace window to finish (≈20-30s observed on Deno
|
|
1414
|
+
* Deploy) — ideal for short instant messages that complete quickly.
|
|
1407
1415
|
*/
|
|
1408
1416
|
// Instant type: check VAPID before creating the task to avoid orphaned rows
|
|
1409
1417
|
if (payload.messageType === 'instant') {
|
|
@@ -1459,11 +1467,20 @@ function createScheduleMessageHandler(ctx) {
|
|
|
1459
1467
|
}
|
|
1460
1468
|
|
|
1461
1469
|
/**
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
1470
|
+
* In-server instant path. Delivers an instant message through this
|
|
1471
|
+
* server's own task queue (create task → process by UUID → delete task).
|
|
1472
|
+
* The task is written to the database before processing, so delivery is
|
|
1473
|
+
* not tied to the request connection: even if the client disconnects, the
|
|
1474
|
+
* row stays and the generation keeps running (and can be retried) for as
|
|
1475
|
+
* long as it needs. Use this when you have a database and want long or
|
|
1476
|
+
* guaranteed-complete generations with no dropped messages.
|
|
1477
|
+
*
|
|
1478
|
+
* The stateless alternative is `@rei-standard/amsg-instant`: it streams
|
|
1479
|
+
* over SSE with a Web Push backup and needs no database, which makes it a
|
|
1480
|
+
* good fit for edge runtimes (e.g. Cloudflare Workers). Its work rides the
|
|
1481
|
+
* response connection, so after the client disconnects it only has the
|
|
1482
|
+
* platform's brief grace window to finish (≈20-30s observed on Deno
|
|
1483
|
+
* Deploy) — ideal for short instant messages that complete quickly.
|
|
1467
1484
|
*/
|
|
1468
1485
|
// Instant type: send immediately
|
|
1469
1486
|
if (payload.messageType === 'instant') {
|
package/dist/index.d.ts
CHANGED
|
@@ -801,13 +801,13 @@ function isUniqueViolation(error) {
|
|
|
801
801
|
* ReiStandard amsg-server v2.4.0
|
|
802
802
|
*
|
|
803
803
|
* Handles single message content generation and Web Push delivery for
|
|
804
|
-
* scheduled tasks (`fixed` / `prompted` / `auto`) and the
|
|
805
|
-
*
|
|
804
|
+
* scheduled tasks (`fixed` / `prompted` / `auto`) and the
|
|
805
|
+
* in-server instant path (`messageType: 'instant'`).
|
|
806
806
|
*
|
|
807
807
|
* Push wire shape comes from `@rei-standard/amsg-shared`'s
|
|
808
808
|
* discriminated union (`AmsgPush`). The SW (`@rei-standard/amsg-sw`)
|
|
809
809
|
* routes on `messageKind`. Server-driven pushes always carry
|
|
810
|
-
* `source: 'instant'` (for the
|
|
810
|
+
* `source: 'instant'` (for the in-server instant path) or
|
|
811
811
|
* `source: 'scheduled'` (for everything else).
|
|
812
812
|
*
|
|
813
813
|
* v2.4.0: when the LLM response carries non-empty
|
|
@@ -1004,7 +1004,7 @@ async function processSingleMessage(task, ctx, providedMasterKey) {
|
|
|
1004
1004
|
// `messageId` format — deterministic when we have a task.id so a
|
|
1005
1005
|
// retry produces the same id for the same (task, sentence) pair
|
|
1006
1006
|
// (downstream dedupers can key on it). Falls back to a UUID for
|
|
1007
|
-
// the
|
|
1007
|
+
// the in-server instant path that has no row id.
|
|
1008
1008
|
const messageIdBase = task.id != null
|
|
1009
1009
|
? `msg_task_${task.id}`
|
|
1010
1010
|
: `msg_${randomUUID()}_instant`;
|
|
@@ -1398,12 +1398,20 @@ function createScheduleMessageHandler(ctx) {
|
|
|
1398
1398
|
const encryptedPayload = encryptForStorage(JSON.stringify(fullTaskData), userKey);
|
|
1399
1399
|
|
|
1400
1400
|
/**
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
*
|
|
1401
|
+
* In-server instant path. Delivers an instant message through this
|
|
1402
|
+
* server's own task queue (create task → process by UUID → delete task).
|
|
1403
|
+
* The task is written to the database before processing, so delivery is
|
|
1404
|
+
* not tied to the request connection: even if the client disconnects, the
|
|
1405
|
+
* row stays and the generation keeps running (and can be retried) for as
|
|
1406
|
+
* long as it needs. Use this when you have a database and want long or
|
|
1407
|
+
* guaranteed-complete generations with no dropped messages.
|
|
1408
|
+
*
|
|
1409
|
+
* The stateless alternative is `@rei-standard/amsg-instant`: it streams
|
|
1410
|
+
* over SSE with a Web Push backup and needs no database, which makes it a
|
|
1411
|
+
* good fit for edge runtimes (e.g. Cloudflare Workers). Its work rides the
|
|
1412
|
+
* response connection, so after the client disconnects it only has the
|
|
1413
|
+
* platform's brief grace window to finish (≈20-30s observed on Deno
|
|
1414
|
+
* Deploy) — ideal for short instant messages that complete quickly.
|
|
1407
1415
|
*/
|
|
1408
1416
|
// Instant type: check VAPID before creating the task to avoid orphaned rows
|
|
1409
1417
|
if (payload.messageType === 'instant') {
|
|
@@ -1459,11 +1467,20 @@ function createScheduleMessageHandler(ctx) {
|
|
|
1459
1467
|
}
|
|
1460
1468
|
|
|
1461
1469
|
/**
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
1470
|
+
* In-server instant path. Delivers an instant message through this
|
|
1471
|
+
* server's own task queue (create task → process by UUID → delete task).
|
|
1472
|
+
* The task is written to the database before processing, so delivery is
|
|
1473
|
+
* not tied to the request connection: even if the client disconnects, the
|
|
1474
|
+
* row stays and the generation keeps running (and can be retried) for as
|
|
1475
|
+
* long as it needs. Use this when you have a database and want long or
|
|
1476
|
+
* guaranteed-complete generations with no dropped messages.
|
|
1477
|
+
*
|
|
1478
|
+
* The stateless alternative is `@rei-standard/amsg-instant`: it streams
|
|
1479
|
+
* over SSE with a Web Push backup and needs no database, which makes it a
|
|
1480
|
+
* good fit for edge runtimes (e.g. Cloudflare Workers). Its work rides the
|
|
1481
|
+
* response connection, so after the client disconnects it only has the
|
|
1482
|
+
* platform's brief grace window to finish (≈20-30s observed on Deno
|
|
1483
|
+
* Deploy) — ideal for short instant messages that complete quickly.
|
|
1467
1484
|
*/
|
|
1468
1485
|
// Instant type: send immediately
|
|
1469
1486
|
if (payload.messageType === 'instant') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rei-standard/amsg-server",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
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",
|