koishi-plugin-prism 0.5.1 → 0.5.3

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
@@ -42,17 +42,21 @@ Koishi 里只填怎么连到店铺:
42
42
  | 门锁 | `lock` 打开的门(带门锁能力的资源);店里只有一扇门时默认就是它。没有门时 `lock` 回复本店还没有设置。 |
43
43
  | 入场后自动获取门锁密码 | 默认关闭。打开后 `login`/`入场` 成功时顺带生成一个 8 位 TTLock 临时密码(有效期 3 分钟)一并回复;门锁失败只多一行提示,不会让入场失败。没有门锁时不生效。 |
44
44
  | 播报与提醒 | 只有一处设置:**播报群**(Koishi 的 `平台:频道` 格式,如群 `onebot:群号`、私聊 `onebot:private:QQ号`)和**提醒提前量**(分钟)。闲置提醒和店内动态都发到这一处,不再分成两个群。 |
45
- | 播报这些 | 五个开关,各自默认关闭:设备闲置(关机前提醒,提前量为 0 时不提醒)、开机/关机(含闲置自动关机)、上机(刷卡或投币后开始占用机台)、刷卡、投币。刷卡或投币同时上机时只发一条:开了「上机」按上机播报,否则按刷卡/投币播报。这个 Bot 自己执行的命令已经回复过,不再播报;别的 Bot、网页和机台上发生的照常播报。下机不播报。 |
45
+ | 播报这些 | 在后台按事件类型逐项勾选(`announceEvents`),平台按勾选只发相应的动态,写好要说的话并直接发到播报群(其中的玩家由插件换成群里的称呼)。分三组:**现场发生的事**(开机、关机、刷卡、上机、机台投币、开局扣币、投币计数清零,来自机台和 Home Assistant 的回报,不论在哪里操作的都只说一次)、**通过平台的操作**(通过平台开机/关机、闲置自动关机、通过平台刷卡、通过平台投币,只说明有人在平台上发起了它)和**提醒**(闲置关机提醒,提前量为 0 时不提醒)。这个 Bot 自己执行的命令已经回复过,不再播报。 |
46
+
47
+ 播报与闲置提醒直接通过对应平台的第一个在线机器人发送,不依赖 Koishi 的数据库、频道分配或 silent 标记,是否播报由 PRiSM 设置决定。群聊填写 `平台:频道`,私聊填写 `平台:private:用户ID`;频道 ID 内的冒号保持原样。连续播报不会修改缓存的频道列表,单个目标发送失败会记录目标及错误并继续其他目标和后续播报。相同平台有多个机器人时,第一个在线账号须能访问目标群;离线时不缓存补发。
48
+
49
+ HA 监听的健康心跳与 HA ping 均为每 60 秒一次,与机台 IO 对齐;平台仍使用 150 秒报告租约。电源变化由平台根据 HA 上报确认后分发 `shop.event`,Bot 按设置播报,不在本地另做电源判断。
46
50
 
47
51
  **店员**是在这家店工作、并在网页里绑定了聊天平台身份的人:Bot 按「平台 + 账号」认人,`onebot:114514` 是店员不代表 `telegram:114514` 也是。**货币名称**取店铺的余额资产名,**麻将桌**和**门锁**取店铺的资源,都不需要在 Koishi 里重复填写。店铺没有整店计费开关。Bot 属于一个资源组,`login`/`入场` 开始的是这个资源组(或 Bot 资源专属)的计费方案;平台下发的 `billingEnabled` 只表示通过这个 Bot 入场是否计费。为 `false` 时 Bot 不请求平台,直接回复「这里不计费,无需入场」;平台拒绝时(例如资源组刚改成免费)回复同样的话。钱包、账单、结账、兑换、上下桌、`list` 等命令属于玩家或各自的资源,跟 Bot 所在资源组无关,一律交给平台处理。旧平台整店未启用计费时返回的 `BILLING_DISABLED` 仍提示「本店未启用计费」。
48
52
 
49
- Bot 连上平台后先读取这些设置,再向平台打招呼;网页里改了设置、店员绑定了新身份、增删了麻将桌或门锁时,平台会通知 Bot 重新读取,**不需要重启 Koishi**。
53
+ 这些设置由平台自己读、自己判断,插件不读取;网页里改了设置、店员绑定了新身份、增删了麻将桌或门锁时立即生效,**不需要重启 Koishi**。
50
54
 
51
55
  旧版的 `autoRegister`、`currencyName`、`defaultDoorDeviceId`、`defaultScanProvider`(刷卡固定使用 Aime)、`loginPricingConfigIds`、`loginSessionLabel`、`enableStaffCommands`、`staffUserIds`、`powerCommandsAdminOnly`、`playerCommands`、`readOnlyNotice`、`logoutNotifyUserIds`、`idleNotifyChannelIds`、`idleReminderMinutes`、`watchHomeAssistant`(改由平台调度)、`botName`、`mahjongTableConfigs`、`mahjongTableSize` 已全部移除;升级后请到 Bot 的资源页重新设置。玩家首次使用时是否自动建档由店铺自己的注册开关决定。入场开始这个 Bot 在 PRiSM 里的计费方案:Bot 资源的专属方案,否则它所属资源组的方案;没改过的 Bot 在默认资源组,即店铺默认计费方案。已经在计费时 Bot 回复「您已在「方案名」中」。
52
56
 
53
57
  ### 统一平台
54
58
 
55
- 配置 `baseUrl` 和本店的 Integration 令牌后(店铺编号可选),插件直接连 `/integration/ws`:凭据在握手时解析出店铺,和机台连 `/io/ws` 一样,地址里没有店铺编号。插件与 PRiSM 只保持**一条 WebSocket 连接**,所有命令都作为请求帧走这条连接,平台也通过它推送闲置关机提醒。连接断开时命令直接回复「操作失败,暂时连不上服务器。」,不排队、不自动重发;插件在后台自动重连。需要 Koishi 的 `http` 服务(`ctx.http.ws`)。不再支持不填 `shopCode` 的单店兼容部署。
59
+ 配置 `baseUrl` 和本店的 Integration 令牌后(店铺编号可选),插件直接连 `/integration/ws`:凭据在握手时解析出店铺,和机台连 `/io/ws` 一样,地址里没有店铺编号。插件与 PRiSM 只保持**一条 WebSocket 连接**,玩家的命令原样(命令名和参数)转给平台,平台执行后告诉插件说什么:第一句作为命令的回复(引用原消息),其余的(如私聊店员的账单)照平台说的地方发出;店内动态和闲置提醒也是平台写好、指定发到哪个群。插件里没有命令的业务逻辑,也不再自己判断权限和措辞。30 秒没有回音时回复「服务器没有及时回应,请稍后确认结果」。连接断开时命令直接回复「操作失败,暂时连不上服务器。」,不排队、不自动重发;插件在后台自动重连。需要 Koishi 的 `http` 服务(`ctx.http.ws`)。不再支持不填 `shopCode` 的单店兼容部署。
56
60
 
57
61
  玩家在网页取得验证码后,向任意已接入的店铺 Bot 发送 `bind 验证码`(旧命令 `prism.bind` 仍可用)。店家可以在 PRiSM「设置 → 玩家与身份 → 绑定提示」改写玩家看到的绑定提示。所有命令从消息的 `session.platform` 和 `session.userId` 读取身份,发送 `{ code, provider, subject }`,不接受手填或代填身份;`provider` 配置已移除。例如同一实例的 OneBot 和 Telegram 消息分别使用 `onebot:114514` 和 `telegram:114514`。群/私聊过滤交给 Koishi。网页账号可以跨店使用,平台验证、玩家和余额按店铺隔离;同一网页账号追加平台绑定时复用同一个玩家。
58
62
 
@@ -96,16 +100,19 @@ Bot 设置开启「账单私聊店员」时,玩家退场或店员覆盖结账
96
100
  * `coin <设备名或别名> [count]` - 请求向后台配置的 Hinata IO 设备投币;需要玩家已入场。
97
101
  * `scan <设备名或别名>` - 使用当前玩家后台绑定的 Aime 卡向设备刷卡,不在群聊中输入或显示卡号。
98
102
  * `redeem <code>` - 兑换礼物码。
99
- * `mahjong <桌号>` / `上桌 [桌号]` - 按桌名或别名(不区分大小写)坐上麻将桌;`/上桌` 未提供桌号时会引导查看 `/麻将列表`。不需要先入场:坐满时平台为全桌开始计费,已开局的桌补位后立即开始计费。满桌、已在别的桌,或平台拒绝计费(例如不在麻将计费时段)时回复原因。
103
+ * `mahjong <桌号>` / `上桌 [桌号]` - 按桌名或别名(不区分大小写)坐上麻将桌;`/上桌` 未提供桌号时会引导查看 `/麻将列表`。不需要先入场:坐满时平台为全桌开始计费,已开局的桌补位后立即开始计费。直接加入另一桌即为换桌,无需先下桌;相同方案保持原计时,目标满桌或计费失败保留原桌。平台拒绝计费(例如不在麻将计费时段)时回复原因。
100
104
  * `下桌 [桌号]` - 离开当前所在的麻将桌(也可以指明哪一桌),正在计费的会停止计费,并显示该桌剩余人数。
101
105
  * `麻将列表` - 查看店里麻将桌的桌名、别名,以及空闲、等位或游玩中状态。
102
106
  * `api测速 [次数]` - 走 HTTP 连续查询自己的钱包:首次(含建立连接)单独列出,之后显示最小、平均与最大延迟,并给出服务端处理时间和经过的 Cloudflare 节点(默认 5 次,最多 10 次)。
103
107
  * `ws测速 [次数]` - 走 Bot 的 WebSocket 连接:心跳往返(纯网络)和同样的钱包查询,并给出服务端处理时间(默认 5 次,最多 10 次)。两者对比可以看出延迟在网络还是在服务端,以及长连接能省下多少。
104
- * `versions` - 显示当前 Bot npm 包版本和后端发布版本;后端不可达时仍会显示 Bot 版本。
108
+ * `versions` - 显示当前 Bot npm 包版本,以及后端是哪次部署(Worker 名称和提交号的前 12 位,如 `prism-link-beta (df66f121da54)`);后端不可达时仍会显示 Bot 版本。
105
109
 
106
- Bot 版本直接读取本 npm 包的 `package.json`,后端版本读取无需认证的 `GET /version`。插件发布遵循 SemVer;修复使用 patch、兼容新增功能使用 minor、不兼容改动使用 major,发布前通过 `npm version <patch|minor|major>` 自动更新包版本。
110
+ Bot 版本直接读取本 npm 包的 `package.json`,后端的部署读取无需认证的 `GET /version`(`{ worker, revision }`;后端没有发布版本号)。插件发布遵循 SemVer;修复使用 patch、兼容新增功能使用 minor、不兼容改动使用 major,发布前通过 `npm version <patch|minor|major>` 自动更新包版本。
107
111
 
108
112
  ### 店员快捷指令
113
+
114
+ 支持 `/上桌 a @玩家`、`/下桌 a @玩家`(`mahjong a @玩家` 同上桌),可直接代玩家上下桌或换桌,无需玩家先入场。与其他代操作相同,须开启店员命令且发送者是本店绑定了当前平台身份的店员。回复显示目标玩家。普通玩家省略 `@玩家` 操作自己。计费与座位由平台原子提交,Bot 不维护另一份桌位或计费状态。
115
+
109
116
  Bot 设置开启「店员命令」后,店员(在网页绑定了当前聊天平台身份的店员)可使用:
110
117
  * `add <target:user> <amount:number>` - 为目标用户增加余额。
111
118
  * `del <target:user> <amount:number>` - 从目标用户扣除余额。
@@ -159,6 +166,16 @@ npm version minor --no-git-tag-version
159
166
 
160
167
  绑定支持 Koishi 提供的各适配器标识,身份值保持字符串,不限定数字格式。店员和账单私聊按「平台标识 + 身份值」认人,相同号码的其他平台不会继承权限或通知。管理员代操作使用目标平台标识,禁止通过当前适配器误操作另一个平台。`/list` 只用当前平台的身份查询昵称,缺失时使用后台名称。源码和 npm 发行包需要分别核对版本。
161
168
 
169
+ ### 0.5.3
170
+
171
+ 插件改为只转发命令:`login`、`logout`、`wallet` 等命令连同参数原样发给平台(`command` 帧),平台执行、判断权限(只读模式、店员、计费)、写好回复,插件照发(`say` 帧);账单私聊店员、入场附带的门锁密码也由平台决定发到哪。店内动态和闲置提醒同样由平台写好、按 Bot 的监听规则发到规则指定的群或个人,插件不再读取 Bot 设置,也不再收 `shop.event`。插件自己只保留 `versions`、`api测速`、`ws测速` 和 Home Assistant 监听。播报新增机台投币、开局扣币、投币计数清零(需要机台 IO 开启 `cabinetMonitor`),以及来自 Home Assistant 的开机、关机;刷卡改为在游戏取到卡时播报,网页刷卡和实体卡一样只说一次;`下桌` 不必再指定桌号。需要支持命令协议的 PRiSM,店铺所在的 PRiSM 升级之前不要升级到此版本。
172
+
173
+ `versions` 按平台现在的 `GET /version` 显示后端:Worker 名称和提交号,不再有发布版本号。
174
+
175
+ ### 0.5.2
176
+
177
+ 完整恢复 0.4.1/0.4.2 的修复:HA 心跳与 ping 每 60 秒一次;店内动态和闲置预告直接通过适配器发送,不依赖 Koishi 数据库,不修改频道列表,支持群聊/私聊及逐目标失败隔离。电源播报继续由平台根据 HA 事件分发。同时支持店员 `/上桌 a @玩家`、`/下桌 a @玩家`,保留 0.5.1 的兑换提示修复。
178
+
162
179
  ### 0.5.1
163
180
 
164
181
  在 0.4.0 的基础上补齐兑换失败提示:区分无效、未生效、过期、领完、已领取、达到限领次数与操作争用,不再统一回复稍后重试。公共码并发保护由平台负责(PRiSM `b4871d8` 起);本次不恢复旧 0.5.0 的 HA 本地播报实现,电源播报仍由平台确认 HA 事件后分发给 Bot。npm 上已发布的 0.5.0 不可覆盖,因此此修复使用 0.5.1。
@@ -187,4 +204,4 @@ Koishi 配置只剩 `baseUrl` 和 `integrationToken`(`shopCode` 可选、已
187
204
 
188
205
  ## 时间展示
189
206
 
190
- 账单、历史与资产到期使用 API 时间字符串所带的店铺偏移,例如 `2026-10-03T10:08:00+08:00`,不依赖 Bot 服务器时区,也不手工加八小时。账单注明 UTC 偏移;时间排序及游玩时长按绝对时间计算,兼容旧 `Z` 时间戳。网页/Swift 的个人时间可按玩家设备时区展示,因此跨地区使用时显示时钟不同,但时长和金额一致。
207
+ 账单、历史与资产到期的时间由平台按店铺时区写好,例如「⏰ 游玩时间:18:00–19:00(UTC+08:00)」,不依赖 Bot 服务器时区。
package/lib/ha-watch.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * The platform hands a bot the Home Assistant addresses to try, a read-only token and the entities it
5
5
  * cares about (`ha.watch`). The bot subscribes with `subscribe_entities` and reports `ha.status` (also
6
- * every 30 s, as a heartbeat) and `ha.states` back over its platform connection, every report carrying
6
+ * every 60 s, as a heartbeat) and `ha.states` back over its platform connection, every report carrying
7
7
  * the term of the assignment it answers; that is how the platform tells a current watcher from a
8
8
  * replaced one. This is the same job a HINATA IO does, in the same shape, so the platform treats both
9
9
  * alike.
package/lib/ha-watch.js CHANGED
@@ -10,7 +10,9 @@ exports.parseWatch = parseWatch;
10
10
  exports.HA_TIMING = {
11
11
  connectMs: 10_000,
12
12
  authMs: 10_000,
13
- heartbeatMs: 30_000,
13
+ // The same beat as a machine's IO: the platform gives a watcher two beats of
14
+ // lease plus slack, and does not care whether the watcher is a bot or a box.
15
+ heartbeatMs: 60_000,
14
16
  firstRetryMs: 2_000,
15
17
  maxRetryMs: 60_000,
16
18
  };
package/lib/index.d.ts CHANGED
@@ -10,77 +10,18 @@ export declare class PrismBotClientError extends Error {
10
10
  readonly code: string;
11
11
  readonly status: number;
12
12
  readonly body: unknown;
13
- readonly originalError?: unknown | undefined;
14
- constructor(message: string, code: string, status: number, body: unknown, originalError?: unknown | undefined);
13
+ constructor(message: string, code: string, status: number, body: unknown);
15
14
  }
16
- /** What the bot is told about itself and the shop by `GET integration/bot`. */
17
- export type BotConfig = {
18
- bot: {
19
- id: string;
20
- name: string;
21
- };
22
- settings: {
23
- /** "readonly" leaves players binding, lookups and redeeming; staff keep every command. */
24
- playerCommands: "all" | "readonly";
25
- readOnlyNotice: string;
26
- /** Staff may act for other players. */
27
- staffCommands: boolean;
28
- /** Only staff may switch machines off. */
29
- powerOffStaffOnly: boolean;
30
- /** Staff on the same platform get checkout receipts privately. */
31
- receiptsToStaff: boolean;
32
- /** `login`/`入场` also hands out the door code. */
33
- doorPasswordOnEntry: boolean;
34
- /** Channels (`platform:channelId`) the shop says everything in: idle warnings and what happens. */
35
- announceChannelIds: string[];
36
- /** How many minutes before an idle power-off to tell them; 0 for never. */
37
- idleReminderMinutes: number;
38
- /** Which news is told, each on its own. */
39
- announceIdle: boolean;
40
- announcePower: boolean;
41
- announceStarts: boolean;
42
- announceCards: boolean;
43
- announceCoins: boolean;
44
- };
45
- /** Which shop this credential belongs to; the shop code is no longer configured by hand. */
46
- shop?: {
47
- code: string;
48
- name: string;
49
- };
50
- /** Whether entering through this bot bills: its own plan, otherwise its resource group's. */
51
- billingEnabled: boolean;
52
- currencyName: string;
53
- /** Staff are these platform identities. */
54
- staff: Array<{
55
- provider: string;
56
- subject: string;
57
- }>;
58
- /** The door `lock`/开门 opens. */
59
- door: {
60
- id: string;
61
- name: string;
62
- } | null;
63
- mahjongTables: Array<{
64
- id: string;
65
- name: string;
66
- aliases: string[];
67
- capacity: number;
68
- }>;
69
- };
70
15
  export type PrismKoishiPluginConfig = {
71
16
  /**
72
- * Used by /list to resolve player display names from the chat platform.
73
- * For Koishi, this maps an adapter subject and provider to a nickname (e.g. the
74
- * member list of the current group). If not provided, the plugin will fall
75
- * back to `playerDisplayName` from the backend.
17
+ * How the chat names a player: an adapter subject and provider to a nickname
18
+ * (e.g. from the current group's member list). Without it, the platform's
19
+ * display name is used.
76
20
  */
77
21
  resolveDisplayName?: (subject: string, provider: string) => Promise<string | null | undefined> | string | null | undefined;
78
- /** Get a stable current ISO timestamp; mainly for tests. */
79
- now?: () => Date;
80
22
  shopCode?: string;
81
23
  baseUrl?: string;
82
24
  integrationToken?: string;
83
- client?: any;
84
25
  /** Opens the platform connection; defaults to Koishi's `ctx.http.ws`. Mainly for tests. */
85
26
  socket?: SocketFactory;
86
27
  /** Plain HTTP POST, used only by `api测速`; defaults to Koishi's `ctx.http`. Mainly for tests. */
@@ -108,20 +49,20 @@ export type SocketLike = {
108
49
  addEventListener(type: "open" | "message" | "close" | "error", listener: (event: any) => void): void;
109
50
  };
110
51
  export type SocketFactory = (url: string, headers: Record<string, string>) => SocketLike;
111
- export type KoishiCommandRegistration = {
112
- description: string;
113
- action: (context: KoishiActionContext, ...args: string[]) => Promise<string> | string;
114
- };
115
52
  export type KoishiCommandBuilder = {
116
- action(handler: KoishiCommandRegistration["action"]): KoishiCommandBuilder;
53
+ action(handler: (context: KoishiActionContext, ...args: any[]) => Promise<string> | string): KoishiCommandBuilder;
117
54
  };
118
55
  export type KoishiLikeContext = {
119
56
  command(name: string, description: string): KoishiCommandBuilder;
120
57
  logger?(name: string): {
121
58
  warn(...args: unknown[]): void;
122
59
  };
123
- /** Send to channels as `platform:channelId`. */
124
- broadcast?(channels: string[], content: string): Promise<unknown>;
60
+ bots?: Array<{
61
+ platform: string;
62
+ isActive: boolean;
63
+ sendMessage(channelId: string, content: string): Promise<unknown>;
64
+ sendPrivateMessage(userId: string, content: string): Promise<unknown>;
65
+ }>;
125
66
  on?(event: "dispose", listener: () => void): void;
126
67
  };
127
68
  export type KoishiActionContext = {
@@ -129,8 +70,8 @@ export type KoishiActionContext = {
129
70
  platform?: string;
130
71
  isDirect?: boolean;
131
72
  userId: string;
73
+ channelId?: string;
132
74
  messageId?: string;
133
- senderId?: string;
134
75
  senderName?: string;
135
76
  username?: string;
136
77
  bot?: {
@@ -138,33 +79,70 @@ export type KoishiActionContext = {
138
79
  getUser?(id: string): Promise<{
139
80
  name?: string;
140
81
  }>;
141
- broadcast?(userIds: string[], content: string): Promise<void>;
82
+ /** Send to this bot's channels by id; `private:<user>` for a private chat. */
83
+ broadcast?(channels: string[], content: string): Promise<unknown>;
142
84
  };
143
85
  };
144
86
  };
145
87
  export declare function applyPrismKoishiPlugin(ctx: KoishiLikeContext, config: PrismKoishiPluginConfig): void;
146
- type PlatformEvent = {
147
- event: string;
148
- data: unknown;
88
+ /** A player as the platform names one in what it says. */
89
+ type MessagePlayer = {
90
+ playerId: string;
91
+ displayName: string | null;
92
+ identities: Array<{
93
+ provider: string;
94
+ subject: string;
95
+ }>;
96
+ };
97
+ /**
98
+ * What the platform writes for a bot to say (PRiSM's core `bot-message.ts`):
99
+ * text, and players the bot names as its chat knows them. A segment of a kind
100
+ * this version does not know is said by its `text`, if it has one.
101
+ */
102
+ type BotMessage = Array<{
103
+ text?: string;
104
+ player?: MessagePlayer;
105
+ }>;
106
+ /** `say`: something to say, the answer to a command (`replyTo`) or the shop's news. */
107
+ export type SayFrame = {
108
+ type: "say";
109
+ message: BotMessage;
110
+ replyTo?: string;
111
+ to?: string;
112
+ done?: boolean;
113
+ };
114
+ type ChatIdentity = {
115
+ provider: string;
116
+ subject: string;
117
+ name?: string;
118
+ };
119
+ /** A player's command as the platform runs it. */
120
+ type CommandFrame = {
121
+ name: string;
122
+ args: string[];
123
+ from: ChatIdentity;
124
+ target?: ChatIdentity;
125
+ channel: string;
126
+ };
127
+ type SocketReply = {
128
+ status: number;
129
+ body: any;
130
+ serverMs?: number | null;
149
131
  };
150
132
  /**
151
- * The one connection to PRiSM. Requests go out as frames and are matched to
152
- * their replies by id; the platform also pushes events down it. While it is
153
- * down a request fails at once: queueing a checkout or a top-up to run later
154
- * would make players repeat it, and a resend could run it twice.
133
+ * The one connection to PRiSM. Commands go out as `command` frames and the
134
+ * platform answers with `say` frames naming them; the shop's news comes as
135
+ * `say` frames naming none. While it is down a command fails at once:
136
+ * queueing a checkout or a top-up to run later would make players repeat it.
155
137
  */
156
138
  export declare class PrismSocket {
157
139
  private readonly open;
158
- /** Resolved at each connection: the shop is learned from the credential first. */
159
140
  private readonly url;
160
141
  private readonly token;
161
- /**
162
- * What to say in hello, read afresh each time: the bot's settings live on
163
- * the platform, so they are fetched over this connection before it is
164
- * sent. Null when they could not be read.
165
- */
142
+ /** What to say in hello besides that this bot sends commands. */
166
143
  private readonly hello;
167
- private readonly onEvent;
144
+ /** The shop's news: something to say that answers no command. */
145
+ private readonly onNews;
168
146
  private readonly logger?;
169
147
  /**
170
148
  * `onWatch`: the platform asked this bot to watch Home Assistant, or with null to stop.
@@ -173,24 +151,20 @@ export declare class PrismSocket {
173
151
  private readonly hooks?;
174
152
  private socket;
175
153
  private readonly pending;
154
+ /** Commands still being answered, by id. */
155
+ private readonly listening;
176
156
  private retryMs;
177
157
  private retryTimer;
178
158
  private pingTimer;
179
159
  private lastHeard;
180
160
  private stopped;
181
161
  private sequence;
182
- /** Bumped by every hello being prepared, so only the newest one is sent. */
183
- private greeting;
184
162
  private readonly pongWaiters;
185
- constructor(open: SocketFactory,
186
- /** Resolved at each connection: the shop is learned from the credential first. */
187
- url: string | (() => string), token: string,
188
- /**
189
- * What to say in hello, read afresh each time: the bot's settings live on
190
- * the platform, so they are fetched over this connection before it is
191
- * sent. Null when they could not be read.
192
- */
193
- hello: () => Promise<Record<string, unknown> | null>, onEvent: (event: PlatformEvent) => void, logger?: {
163
+ constructor(open: SocketFactory, url: string, token: string,
164
+ /** What to say in hello besides that this bot sends commands. */
165
+ hello: () => Record<string, unknown>,
166
+ /** The shop's news: something to say that answers no command. */
167
+ onNews: (say: SayFrame) => void, logger?: {
194
168
  warn(...args: unknown[]): void;
195
169
  } | undefined,
196
170
  /**
@@ -204,45 +178,33 @@ export declare class PrismSocket {
204
178
  /** Send a frame if the connection is up; a report made while it is down is dropped, as the platform has forgotten the watch by then. */
205
179
  send(frame: Record<string, unknown>): void;
206
180
  start(): void;
207
- /** Connect again with what the platform has just told us, such as the shop. */
208
- reconnect(): void;
209
181
  stop(): void;
210
182
  private connect;
211
- /**
212
- * Read the bot's settings and say hello with them: on connecting, and again
213
- * when the platform says they changed. A connection that cannot read them
214
- * at all is closed and tried again later, without resetting the backoff, so
215
- * a platform that keeps failing is not asked every second.
216
- */
183
+ /** Hello: on connecting, and again when the platform says the bot's settings changed, so it rereads them. */
217
184
  private greet;
218
185
  private reconnectLater;
219
186
  private failPending;
220
187
  private receive;
188
+ private nextId;
189
+ /**
190
+ * Send a command; `onSay` hears each thing the platform says for it, or
191
+ * null once the connection is gone. False while the connection is down.
192
+ */
193
+ command(frame: CommandFrame, onSay: (say: SayFrame | null) => void): boolean;
221
194
  /** One heartbeat round trip in milliseconds: the network to the platform and nothing else. */
222
195
  ping(): Promise<number>;
196
+ /** A platform route over the connection: the version and the speed tests, which measure exactly that. */
223
197
  request(frame: {
224
- method: "GET" | "POST" | "PUT";
198
+ method: "GET" | "POST";
225
199
  path: string;
226
- query?: Record<string, unknown>;
227
200
  body?: unknown;
228
201
  }): Promise<SocketReply>;
229
202
  }
230
- type SocketReply = {
231
- status: number;
232
- body: any;
233
- serverMs?: number | null;
234
- };
235
203
  /**
236
204
  * The platform connection URL. The credential names the shop, as a device's
237
205
  * token names its machine at `/io/ws`, so nothing identifying is in the path.
238
206
  */
239
207
  export declare function platformSocketUrl(baseUrl: string): string;
240
- export type Sender = {
241
- id: string;
242
- name: string;
243
- provider: string;
244
- };
245
- export declare function humanReadableBotError(error: PrismBotClientError): string;
246
208
  declare const _default: {
247
209
  name: string;
248
210
  Config: Schema<PrismKoishiPluginConfig>;