@dsh-plus/agent-preset-rea 0.1.3 → 0.1.4

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/lib/client.js CHANGED
@@ -750,7 +750,28 @@ ${extra}
750
750
  * 字节数另有 {@link DEFAULT_PERSONA_PREFIX_BYTES} 供测试用(正文含 CJK,两者不同值)。
751
751
  */
752
752
  const DEFAULT_PERSONA_PREFIX_LENGTH = DEFAULT_PERSONA_PREFIX.length;
753
- Buffer.byteLength(DEFAULT_PERSONA_PREFIX, "utf8");
753
+ /**
754
+ * UTF-8 字节数(纯 JS 计数,不依赖任何运行期能力)。
755
+ *
756
+ * 本模块随 client bundle 进浏览器(卡片要取预览与字符数),因此这里不能出现
757
+ * `Buffer.byteLength` 之类的 Node 专有 API——浏览器里没有 `Buffer` 全局,模块
758
+ * 顶层求值即抛 `Buffer is not defined`,整个 client 半加载失败。
759
+ * 落单代理按 U+FFFD 的 3 字节计,与 `Buffer.byteLength` 同值。
760
+ */
761
+ function utf8ByteLength(text) {
762
+ let bytes = 0;
763
+ for (let index = 0; index < text.length; index += 1) {
764
+ const code = text.charCodeAt(index);
765
+ if (code < 128) bytes += 1;
766
+ else if (code < 2048) bytes += 2;
767
+ else if (code >= 55296 && code <= 56319 && index + 1 < text.length && text.charCodeAt(index + 1) >= 56320 && text.charCodeAt(index + 1) <= 57343) {
768
+ bytes += 4;
769
+ index += 1;
770
+ } else bytes += 3;
771
+ }
772
+ return bytes;
773
+ }
774
+ utf8ByteLength(DEFAULT_PERSONA_PREFIX);
754
775
  /** 内置文本的只读预览(卡片在「默认」模式展示;正文真源仍是上面的常量)。 */
755
776
  const DEFAULT_PERSONA_PREFIX_PREVIEW = DEFAULT_PERSONA_PREFIX.slice(0, 1200);
756
777
  //#endregion
package/lib/index.js CHANGED
@@ -328,8 +328,29 @@ const DEFAULT_PERSONA_PREFIX_HASH = "3e47b4b5b11beb0de6aaea95d195f4974d59c14a84a
328
328
  * 字节数另有 {@link DEFAULT_PERSONA_PREFIX_BYTES} 供测试用(正文含 CJK,两者不同值)。
329
329
  */
330
330
  const DEFAULT_PERSONA_PREFIX_LENGTH = DEFAULT_PERSONA_PREFIX.length;
331
+ /**
332
+ * UTF-8 字节数(纯 JS 计数,不依赖任何运行期能力)。
333
+ *
334
+ * 本模块随 client bundle 进浏览器(卡片要取预览与字符数),因此这里不能出现
335
+ * `Buffer.byteLength` 之类的 Node 专有 API——浏览器里没有 `Buffer` 全局,模块
336
+ * 顶层求值即抛 `Buffer is not defined`,整个 client 半加载失败。
337
+ * 落单代理按 U+FFFD 的 3 字节计,与 `Buffer.byteLength` 同值。
338
+ */
339
+ function utf8ByteLength(text) {
340
+ let bytes = 0;
341
+ for (let index = 0; index < text.length; index += 1) {
342
+ const code = text.charCodeAt(index);
343
+ if (code < 128) bytes += 1;
344
+ else if (code < 2048) bytes += 2;
345
+ else if (code >= 55296 && code <= 56319 && index + 1 < text.length && text.charCodeAt(index + 1) >= 56320 && text.charCodeAt(index + 1) <= 57343) {
346
+ bytes += 4;
347
+ index += 1;
348
+ } else bytes += 3;
349
+ }
350
+ return bytes;
351
+ }
331
352
  /** 内置文本的 UTF-8 字节数(测试的第二道独立守卫;正文含 CJK,比字符数大)。 */
332
- const DEFAULT_PERSONA_PREFIX_BYTES = Buffer.byteLength(DEFAULT_PERSONA_PREFIX, "utf8");
353
+ const DEFAULT_PERSONA_PREFIX_BYTES = utf8ByteLength(DEFAULT_PERSONA_PREFIX);
333
354
  /** 内置文本的只读预览(卡片在「默认」模式展示;正文真源仍是上面的常量)。 */
334
355
  const DEFAULT_PERSONA_PREFIX_PREVIEW = DEFAULT_PERSONA_PREFIX.slice(0, 1200);
335
356
  /** 内置文本必须覆盖的规则段标题(缺一即测试失败)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-plus/agent-preset-rea",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "dsh-plus service + UI plugin: 注册逆向工程 agent preset(id=rea)——官方 standard 全量行镜像 + 预设作用域的 REA MCP 客户端(mcp__rea__*)、随包 REA 官方 skill、提示词卡片与 REA/skill 的受管安装更新",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@dsh-plus/shared": "0.1.41"
35
+ "@dsh-plus/shared": "0.1.42"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@deepseek-ai/cordis": "^4.0.5-alpha.2",
@@ -286,8 +286,40 @@ export const DEFAULT_PERSONA_PREFIX_HASH =
286
286
  */
287
287
  export const DEFAULT_PERSONA_PREFIX_LENGTH = DEFAULT_PERSONA_PREFIX.length
288
288
 
289
+ /**
290
+ * UTF-8 字节数(纯 JS 计数,不依赖任何运行期能力)。
291
+ *
292
+ * 本模块随 client bundle 进浏览器(卡片要取预览与字符数),因此这里不能出现
293
+ * `Buffer.byteLength` 之类的 Node 专有 API——浏览器里没有 `Buffer` 全局,模块
294
+ * 顶层求值即抛 `Buffer is not defined`,整个 client 半加载失败。
295
+ * 落单代理按 U+FFFD 的 3 字节计,与 `Buffer.byteLength` 同值。
296
+ */
297
+ function utf8ByteLength(text: string): number {
298
+ let bytes = 0
299
+ for (let index = 0; index < text.length; index += 1) {
300
+ const code = text.charCodeAt(index)
301
+ if (code < 0x80) {
302
+ bytes += 1
303
+ } else if (code < 0x800) {
304
+ bytes += 2
305
+ } else if (
306
+ code >= 0xd800 &&
307
+ code <= 0xdbff &&
308
+ index + 1 < text.length &&
309
+ text.charCodeAt(index + 1) >= 0xdc00 &&
310
+ text.charCodeAt(index + 1) <= 0xdfff
311
+ ) {
312
+ bytes += 4
313
+ index += 1
314
+ } else {
315
+ bytes += 3
316
+ }
317
+ }
318
+ return bytes
319
+ }
320
+
289
321
  /** 内置文本的 UTF-8 字节数(测试的第二道独立守卫;正文含 CJK,比字符数大)。 */
290
- export const DEFAULT_PERSONA_PREFIX_BYTES = Buffer.byteLength(DEFAULT_PERSONA_PREFIX, 'utf8')
322
+ export const DEFAULT_PERSONA_PREFIX_BYTES = utf8ByteLength(DEFAULT_PERSONA_PREFIX)
291
323
 
292
324
  /** 内置文本的只读预览(卡片在「默认」模式展示;正文真源仍是上面的常量)。 */
293
325
  export const DEFAULT_PERSONA_PREFIX_PREVIEW = DEFAULT_PERSONA_PREFIX.slice(0, 1200)