cs-bots 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +164 -2
- package/cordis.patch.agent-team.yml +31 -0
- package/cordis.patch.yml +30 -0
- package/install.sh +218 -0
- package/package.json +57 -4
- package/src/api.js +706 -0
- package/src/board.js +1056 -0
- package/src/botprofile.js +331 -0
- package/src/client.js +2089 -0
- package/src/compat.js +196 -0
- package/src/dirbrowse.js +555 -0
- package/src/dispatcher.js +651 -0
- package/src/index.js +311 -0
- package/src/kernel.js +480 -0
- package/src/library.js +740 -0
- package/src/memory.js +1905 -0
- package/src/registry.js +34 -0
- package/src/room.js +1550 -0
- package/src/roster.js +1119 -0
- package/src/settings.js +107 -0
- package/src/store.js +243 -0
- package/src/tools.js +469 -0
package/src/registry.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cs-bots 服务注册表 —— 把「已装配的域服务」与宿主 ctx 关联。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它(**真实踩过的坑**,2026-11-02 临时 profile 启动实测):
|
|
5
|
+
* Cordis 的 `ctx` **不允许任意属性赋值**:
|
|
6
|
+
* `Error: cannot set property "csBots" without provide`
|
|
7
|
+
* ⇒ 直接 `ctx.csBots = services` 会让**插件在真实宿主里加载失败**
|
|
8
|
+
* (单元测试用普通对象跑,反而发现不了 —— 这是「测了但没测真」的典型)。
|
|
9
|
+
*
|
|
10
|
+
* ⇒ 改用 `WeakMap<ctx, services>`:不污染宿主命名空间、不依赖 `provide`,
|
|
11
|
+
* 插件卸载后随 ctx 一起被 GC。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** @type {WeakMap<object, object>} */
|
|
15
|
+
const registry = new WeakMap()
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 登记某个 ctx 的域服务集合。
|
|
19
|
+
* @param {object} ctx
|
|
20
|
+
* @param {object} services
|
|
21
|
+
*/
|
|
22
|
+
export function setServices(ctx, services) {
|
|
23
|
+
if (ctx && typeof ctx === 'object') registry.set(ctx, services ?? {})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 取某个 ctx 的域服务集合。未登记时返回空对象(**不抛**,让工具走降级分支)。
|
|
28
|
+
* @param {object} ctx
|
|
29
|
+
* @returns {{ board?: object, roster?: object, room?: object, memory?: object, dispatcher?: object }}
|
|
30
|
+
*/
|
|
31
|
+
export function getServices(ctx) {
|
|
32
|
+
if (!ctx || typeof ctx !== 'object') return {}
|
|
33
|
+
return registry.get(ctx) ?? {}
|
|
34
|
+
}
|