@rei-standard/amsg-server 2.4.0-next.2 → 2.4.1

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
@@ -9,7 +9,7 @@
9
9
  - 业务端点统一使用 `Authorization: Bearer <tenantToken>`
10
10
  - `send-notifications` 支持 `cronToken`(Header 或 query token)
11
11
 
12
- 2.2+ 的字段增量(`messages` 数组、`splitPattern`、`avatarUrl` 软清空策略)在规范的 [§6.1](https://github.com/Tosd0/ReiStandard/blob/main/standards/active-messaging-api.md#61-ai-消息字段约束) / [§6.2](https://github.com/Tosd0/ReiStandard/blob/main/standards/active-messaging-api.md#62-avatarurl-软清空策略);行为已对齐 `amsg-instant`,向后兼容。
12
+ 2.2+ 的字段增量(`messages` 数组、`splitPattern`、`avatarUrl` 软清空策略)在规范的 [§6.1](https://github.com/Tosd0/ReiStandard/blob/main/standards/active-messaging-api.md#61-ai-消息字段约束) / [§6.2](https://github.com/Tosd0/ReiStandard/blob/main/standards/active-messaging-api.md#62-avatarurl-软清空策略)。其中 `splitPattern` 是 server 调度任务的持久化配置;`amsg-instant` 0.8.0 起改为 hook 内自定义 split 函数 + `pushPayloads`。
13
13
 
14
14
  ## 安装
15
15
 
@@ -78,7 +78,7 @@ AI 配置消息的提示词可以用两种形态之一,**互斥二选一**:
78
78
 
79
79
  可选 `temperature?: number` 透传给 LLM:`completePrompt` 路径未传时默认 0.8(保持旧行为);`messages` 路径未传时**不发**,让上游主路径自己决定。
80
80
 
81
- ## 自定义分句正则 `splitPattern`(2.3.0+)
81
+ ## 自定义分句正则 `splitPattern`(server 2.3.0+)
82
82
 
83
83
  `processSingleMessage` 默认按 `/([。!?!?]+)/` 把 LLM 返回的整段文本切成多条推送(每条间隔 1.5s)。`splitPattern` 让调用方覆盖这个正则:
84
84
 
package/dist/index.cjs CHANGED
@@ -515,13 +515,23 @@ function readReasoningContent(llmResponse) {
515
515
  );
516
516
  if (!Array.isArray(choices) || choices.length === 0) return null;
517
517
  const message = (
518
- /** @type {{ message?: { reasoning_content?: unknown } }} */
518
+ /** @type {{ message?: { reasoning_content?: unknown, content?: unknown } }} */
519
519
  _optionalChain([choices, 'access', _2 => _2[0], 'optionalAccess', _3 => _3.message])
520
520
  );
521
521
  const raw = _optionalChain([message, 'optionalAccess', _4 => _4.reasoning_content]);
522
- if (typeof raw !== "string") return null;
523
- const trimmed = raw.trim();
524
- return trimmed.length > 0 ? trimmed : null;
522
+ if (typeof raw === "string") {
523
+ const trimmed = raw.trim();
524
+ if (trimmed.length > 0) return trimmed;
525
+ }
526
+ const content = _optionalChain([message, 'optionalAccess', _5 => _5.content]);
527
+ if (typeof content === "string") {
528
+ const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);
529
+ if (match) {
530
+ const trimmed = match[2].trim();
531
+ if (trimmed.length > 0) return trimmed;
532
+ }
533
+ }
534
+ return null;
525
535
  }
526
536
  async function processSingleMessage(task, ctx, providedMasterKey) {
527
537
  try {
@@ -694,7 +704,7 @@ async function _callAI(payload) {
694
704
  );
695
705
  }
696
706
  const aiData = await aiResponse.json();
697
- const content = _optionalChain([aiData, 'optionalAccess', _5 => _5.choices, 'optionalAccess', _6 => _6[0], 'optionalAccess', _7 => _7.message, 'optionalAccess', _8 => _8.content]);
707
+ const content = _optionalChain([aiData, 'optionalAccess', _6 => _6.choices, 'optionalAccess', _7 => _7[0], 'optionalAccess', _8 => _8.message, 'optionalAccess', _9 => _9.content]);
698
708
  if (typeof content !== "string" || !content.trim()) {
699
709
  throw new Error("AI API error: response missing choices[0].message.content");
700
710
  }
@@ -1378,7 +1388,7 @@ async function resolveBlobStore(namespace) {
1378
1388
  }
1379
1389
  try {
1380
1390
  const blobModule = await Promise.resolve().then(() => _interopRequireWildcard(require("@netlify/blobs")));
1381
- const getStore = blobModule.getStore || _optionalChain([blobModule, 'access', _9 => _9.default, 'optionalAccess', _10 => _10.getStore]);
1391
+ const getStore = blobModule.getStore || _optionalChain([blobModule, 'access', _10 => _10.default, 'optionalAccess', _11 => _11.getStore]);
1382
1392
  if (typeof getStore === "function") {
1383
1393
  return getStore({ name: namespace });
1384
1394
  }
package/dist/index.d.cts CHANGED
@@ -879,11 +879,24 @@ function readReasoningContent(llmResponse) {
879
879
  if (!llmResponse || typeof llmResponse !== 'object') return null;
880
880
  const choices = /** @type {{ choices?: unknown }} */ (llmResponse).choices;
881
881
  if (!Array.isArray(choices) || choices.length === 0) return null;
882
- const message = /** @type {{ message?: { reasoning_content?: unknown } }} */ (choices[0])?.message;
882
+ const message = /** @type {{ message?: { reasoning_content?: unknown, content?: unknown } }} */ (choices[0])?.message;
883
+
883
884
  const raw = message?.reasoning_content;
884
- if (typeof raw !== 'string') return null;
885
- const trimmed = raw.trim();
886
- return trimmed.length > 0 ? trimmed : null;
885
+ if (typeof raw === 'string') {
886
+ const trimmed = raw.trim();
887
+ if (trimmed.length > 0) return trimmed;
888
+ }
889
+
890
+ const content = message?.content;
891
+ if (typeof content === 'string') {
892
+ const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);
893
+ if (match) {
894
+ const trimmed = match[2].trim();
895
+ if (trimmed.length > 0) return trimmed;
896
+ }
897
+ }
898
+
899
+ return null;
887
900
  }
888
901
 
889
902
  /**
package/dist/index.d.ts CHANGED
@@ -879,11 +879,24 @@ function readReasoningContent(llmResponse) {
879
879
  if (!llmResponse || typeof llmResponse !== 'object') return null;
880
880
  const choices = /** @type {{ choices?: unknown }} */ (llmResponse).choices;
881
881
  if (!Array.isArray(choices) || choices.length === 0) return null;
882
- const message = /** @type {{ message?: { reasoning_content?: unknown } }} */ (choices[0])?.message;
882
+ const message = /** @type {{ message?: { reasoning_content?: unknown, content?: unknown } }} */ (choices[0])?.message;
883
+
883
884
  const raw = message?.reasoning_content;
884
- if (typeof raw !== 'string') return null;
885
- const trimmed = raw.trim();
886
- return trimmed.length > 0 ? trimmed : null;
885
+ if (typeof raw === 'string') {
886
+ const trimmed = raw.trim();
887
+ if (trimmed.length > 0) return trimmed;
888
+ }
889
+
890
+ const content = message?.content;
891
+ if (typeof content === 'string') {
892
+ const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);
893
+ if (match) {
894
+ const trimmed = match[2].trim();
895
+ if (trimmed.length > 0) return trimmed;
896
+ }
897
+ }
898
+
899
+ return null;
887
900
  }
888
901
 
889
902
  /**
package/dist/index.mjs CHANGED
@@ -515,13 +515,23 @@ function readReasoningContent(llmResponse) {
515
515
  );
516
516
  if (!Array.isArray(choices) || choices.length === 0) return null;
517
517
  const message = (
518
- /** @type {{ message?: { reasoning_content?: unknown } }} */
518
+ /** @type {{ message?: { reasoning_content?: unknown, content?: unknown } }} */
519
519
  choices[0]?.message
520
520
  );
521
521
  const raw = message?.reasoning_content;
522
- if (typeof raw !== "string") return null;
523
- const trimmed = raw.trim();
524
- return trimmed.length > 0 ? trimmed : null;
522
+ if (typeof raw === "string") {
523
+ const trimmed = raw.trim();
524
+ if (trimmed.length > 0) return trimmed;
525
+ }
526
+ const content = message?.content;
527
+ if (typeof content === "string") {
528
+ const match = content.match(/<(think|thinking|thought)>([\s\S]*?)<\/\1>/i);
529
+ if (match) {
530
+ const trimmed = match[2].trim();
531
+ if (trimmed.length > 0) return trimmed;
532
+ }
533
+ }
534
+ return null;
525
535
  }
526
536
  async function processSingleMessage(task, ctx, providedMasterKey) {
527
537
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rei-standard/amsg-server",
3
- "version": "2.4.0-next.2",
3
+ "version": "2.4.1",
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",
@@ -33,7 +33,7 @@
33
33
  "node": ">=20"
34
34
  },
35
35
  "dependencies": {
36
- "@rei-standard/amsg-shared": "0.1.0-next.4",
36
+ "@rei-standard/amsg-shared": "0.1.0",
37
37
  "web-push": "^3.6.7",
38
38
  "@netlify/blobs": "^8.1.0"
39
39
  },