@rei-standard/amsg-client 2.2.3 → 2.3.0-next.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/README.md CHANGED
@@ -2,6 +2,42 @@
2
2
 
3
3
  `@rei-standard/amsg-client` 是 ReiStandard 主动消息标准的浏览器端 SDK 包,负责加密请求、解密响应和 Push 订阅。
4
4
 
5
+ ## v2.3.0 — Shared push types
6
+
7
+ The client now re-exports `@rei-standard/amsg-shared` 的类型、运行时常量(`MESSAGE_KIND` / `MESSAGE_TYPE` / `PUSH_SOURCE`)、推送 builder(`buildContentPush` 等)和类型守卫(`isContentPush` 等)。调用方可以直接 `import { MessageKind, buildContentPush, isContentPush } from '@rei-standard/amsg-client'`,无需单独再装一个 `@rei-standard/amsg-shared` 依赖。client 本身在运行时不消费这些导出 —— 它们是给同时调 `ReiClient` 又在 Service Worker / 客户端处理推送的 app 用的便利出口。
8
+
9
+ ```js
10
+ // app.js — 用 ReiClient 发即时消息
11
+ import { ReiClient } from '@rei-standard/amsg-client';
12
+
13
+ const client = new ReiClient({
14
+ baseUrl: 'https://instant.example.com',
15
+ instantEncryption: false,
16
+ });
17
+ await client.sendInstant({
18
+ contactName: 'Rei',
19
+ completePrompt: '你是 Rei,用一句话提醒用户带伞',
20
+ apiUrl: 'https://api.openai.com/v1/chat/completions',
21
+ apiKey: '...',
22
+ primaryModel: 'gpt-4o-mini',
23
+ pushSubscription: subscription.toJSON(),
24
+ });
25
+
26
+ // service-worker.js — 用 isContentPush 在收到推送时收窄类型
27
+ import { isContentPush } from '@rei-standard/amsg-client';
28
+
29
+ self.addEventListener('push', (event) => {
30
+ const payload = event.data?.json();
31
+ if (isContentPush(payload)) {
32
+ // payload 已被收窄为 ContentPush —— 安全读取 payload.message
33
+ event.waitUntil(
34
+ self.registration.showNotification(payload.contactName ?? 'Rei', {
35
+ body: payload.message,
36
+ })
37
+ );
38
+ }
39
+ });
40
+ ```
5
41
 
6
42
  ## 安装
7
43
 
package/dist/index.cjs CHANGED
@@ -19,9 +19,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/index.js
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
- ReiClient: () => ReiClient
22
+ MESSAGE_KIND: () => import_amsg_shared.MESSAGE_KIND,
23
+ MESSAGE_TYPE: () => import_amsg_shared.MESSAGE_TYPE,
24
+ PUSH_SOURCE: () => import_amsg_shared.PUSH_SOURCE,
25
+ ReiClient: () => ReiClient,
26
+ buildContentPush: () => import_amsg_shared.buildContentPush,
27
+ buildErrorPush: () => import_amsg_shared.buildErrorPush,
28
+ buildReasoningPush: () => import_amsg_shared.buildReasoningPush,
29
+ buildToolRequestPush: () => import_amsg_shared.buildToolRequestPush,
30
+ isContentPush: () => import_amsg_shared.isContentPush,
31
+ isErrorPush: () => import_amsg_shared.isErrorPush,
32
+ isReasoningPush: () => import_amsg_shared.isReasoningPush,
33
+ isToolRequestPush: () => import_amsg_shared.isToolRequestPush
23
34
  });
24
35
  module.exports = __toCommonJS(src_exports);
36
+ var import_amsg_shared = require("@rei-standard/amsg-shared");
25
37
  var AVATAR_URL_MAX_LENGTH = 2048;
26
38
  var PAYLOAD_LOCAL_MAX_BYTES = 3072;
27
39
  function makeLocalError(code, message, details) {
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ export { MESSAGE_KIND, MESSAGE_TYPE, PUSH_SOURCE, buildContentPush, buildErrorPush, buildReasoningPush, buildToolRequestPush, isContentPush, isErrorPush, isReasoningPush, isToolRequestPush } from '@rei-standard/amsg-shared';
2
+
1
3
  /**
2
4
  * ReiStandard Client SDK
3
5
  *
@@ -22,6 +24,15 @@
22
24
  * await client.scheduleMessage({ ... });
23
25
  */
24
26
 
27
+ /** @typedef {import('@rei-standard/amsg-shared').MessageKind} MessageKind */
28
+ /** @typedef {import('@rei-standard/amsg-shared').MessageType} MessageType */
29
+ /** @typedef {import('@rei-standard/amsg-shared').PushSource} PushSource */
30
+ /** @typedef {import('@rei-standard/amsg-shared').AmsgPush} AmsgPush */
31
+ /** @typedef {import('@rei-standard/amsg-shared').ContentPush} ContentPush */
32
+ /** @typedef {import('@rei-standard/amsg-shared').ReasoningPush} ReasoningPush */
33
+ /** @typedef {import('@rei-standard/amsg-shared').ToolRequestPush} ToolRequestPush */
34
+ /** @typedef {import('@rei-standard/amsg-shared').ErrorPush} ErrorPush */
35
+
25
36
  /**
26
37
  * @typedef {Object} ReiClientConfig
27
38
  * @property {string} baseUrl - Default base URL of the API (e.g. https://host/api/v1).
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { MESSAGE_KIND, MESSAGE_TYPE, PUSH_SOURCE, buildContentPush, buildErrorPush, buildReasoningPush, buildToolRequestPush, isContentPush, isErrorPush, isReasoningPush, isToolRequestPush } from '@rei-standard/amsg-shared';
2
+
1
3
  /**
2
4
  * ReiStandard Client SDK
3
5
  *
@@ -22,6 +24,15 @@
22
24
  * await client.scheduleMessage({ ... });
23
25
  */
24
26
 
27
+ /** @typedef {import('@rei-standard/amsg-shared').MessageKind} MessageKind */
28
+ /** @typedef {import('@rei-standard/amsg-shared').MessageType} MessageType */
29
+ /** @typedef {import('@rei-standard/amsg-shared').PushSource} PushSource */
30
+ /** @typedef {import('@rei-standard/amsg-shared').AmsgPush} AmsgPush */
31
+ /** @typedef {import('@rei-standard/amsg-shared').ContentPush} ContentPush */
32
+ /** @typedef {import('@rei-standard/amsg-shared').ReasoningPush} ReasoningPush */
33
+ /** @typedef {import('@rei-standard/amsg-shared').ToolRequestPush} ToolRequestPush */
34
+ /** @typedef {import('@rei-standard/amsg-shared').ErrorPush} ErrorPush */
35
+
25
36
  /**
26
37
  * @typedef {Object} ReiClientConfig
27
38
  * @property {string} baseUrl - Default base URL of the API (e.g. https://host/api/v1).
package/dist/index.mjs CHANGED
@@ -1,4 +1,17 @@
1
1
  // src/index.js
2
+ import {
3
+ MESSAGE_KIND,
4
+ MESSAGE_TYPE,
5
+ PUSH_SOURCE,
6
+ buildContentPush,
7
+ buildReasoningPush,
8
+ buildToolRequestPush,
9
+ buildErrorPush,
10
+ isContentPush,
11
+ isReasoningPush,
12
+ isToolRequestPush,
13
+ isErrorPush
14
+ } from "@rei-standard/amsg-shared";
2
15
  var AVATAR_URL_MAX_LENGTH = 2048;
3
16
  var PAYLOAD_LOCAL_MAX_BYTES = 3072;
4
17
  function makeLocalError(code, message, details) {
@@ -382,5 +395,16 @@ var ReiClient = class {
382
395
  }
383
396
  };
384
397
  export {
385
- ReiClient
398
+ MESSAGE_KIND,
399
+ MESSAGE_TYPE,
400
+ PUSH_SOURCE,
401
+ ReiClient,
402
+ buildContentPush,
403
+ buildErrorPush,
404
+ buildReasoningPush,
405
+ buildToolRequestPush,
406
+ isContentPush,
407
+ isErrorPush,
408
+ isReasoningPush,
409
+ isToolRequestPush
386
410
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rei-standard/amsg-client",
3
- "version": "2.2.3",
4
- "description": "ReiStandard Active Messaging browser client SDK",
3
+ "version": "2.3.0-next.0",
4
+ "description": "ReiStandard Active Messaging browser client SDK — also re-exports shared push types, builders, and guards from @rei-standard/amsg-shared",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Tosd0/ReiStandard",
@@ -26,11 +26,15 @@
26
26
  "dist"
27
27
  ],
28
28
  "scripts": {
29
- "build": "tsup"
29
+ "build": "tsup",
30
+ "test": "node --test test/*.test.mjs"
30
31
  },
31
32
  "engines": {
32
33
  "node": ">=20"
33
34
  },
35
+ "dependencies": {
36
+ "@rei-standard/amsg-shared": "0.1.0-next.0"
37
+ },
34
38
  "devDependencies": {
35
39
  "tsup": "^8.0.0",
36
40
  "typescript": "^5.0.0"