pi-roundtable 0.48.0 → 0.49.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.
@@ -38,6 +38,8 @@ export interface VoiceLinkHandlers {
38
38
  status(status: VoiceLinkStatus): void;
39
39
  /** One decoded frame of a speaker, in the `VOICE_PCM` format, which the link keeps no reference to. */
40
40
  frame(userId: string, pcm: Uint8Array): void;
41
+ /** Whether the user is a person in the channel, not a bot; with no user, whether any person is. */
42
+ person(userId?: string): boolean;
41
43
  }
42
44
 
43
45
  /** One voice connection: the bot in a channel, muted and not deafened. */
@@ -47,6 +49,12 @@ export interface VoiceLink {
47
49
  listen(handlers: VoiceLinkHandlers): void;
48
50
  /** Someone left the channel: what the link kept to hear them is freed, and made again if they are heard after all. */
49
51
  forget(userId: string): void;
52
+ /**
53
+ * Whether the bot's leaving the channel, as the gateway now reports it, is the link's own on
54
+ * its way to join again, as it does for a speaker it does not hear. True once for each such leave: a second one before the link is back
55
+ * is someone removing the bot.
56
+ */
57
+ leftItself(): boolean;
50
58
  /** Leaves the channel and frees the decoders; does nothing the second time. */
51
59
  close(): void;
52
60
  }
@@ -61,6 +69,11 @@ export interface VoiceGateway {
61
69
  channel(channelId: string): Promise<VoiceChannelFacts | "gone" | "forbidden">;
62
70
  /** Reports every voice channel change in every guild. */
63
71
  onVoiceState(listener: (change: VoiceStateChange) => void): void;
72
+ /**
73
+ * Reports each time the gateway connection is up again, resumed or identified anew: who is in
74
+ * a channel may have changed meanwhile with no word of it.
75
+ */
76
+ onReady(listener: () => void): void;
64
77
  /** Loads what a connection needs, so a host that cannot hear fails as it starts. */
65
78
  prepare(): Promise<void>;
66
79
  /** Opens the voice connection; rejects when it cannot be opened at all. */
@@ -169,9 +182,9 @@ export function voiceService(options: VoiceServiceOptions): VoiceService {
169
182
  };
170
183
 
171
184
  /**
172
- * A dropped connection is back: who is in the channel is read again, and whoever left or
173
- * entered meanwhile is reported now. A gateway that had to identify again is sent the guild's
174
- * voice states anew, with no word of what changed.
185
+ * A dropped connection is back, the voice one or the gateway's: who is in the channel is read
186
+ * again, and whoever left or entered meanwhile is reported now. A gateway that had to identify
187
+ * again is sent the guild's voice states anew, with no word of what changed.
175
188
  */
176
189
  const reread = async (entry: Joined): Promise<void> => {
177
190
  const { session } = entry;
@@ -190,6 +203,11 @@ export function voiceService(options: VoiceServiceOptions): VoiceService {
190
203
  }
191
204
  };
192
205
 
206
+ // A gateway that identified again holds the guild's voice states anew, whatever the voice connection did meanwhile.
207
+ gateway.onReady(() => {
208
+ for (const entry of [...joined.values()]) void reread(entry);
209
+ });
210
+
193
211
  gateway.onVoiceState((change) => {
194
212
  const entry = joined.get(change.guildId);
195
213
  if (!entry) return;
@@ -197,6 +215,8 @@ export function voiceService(options: VoiceServiceOptions): VoiceService {
197
215
  if (change.userId === gateway.botId()) {
198
216
  // Its own way into the channel is the join's to wait for.
199
217
  if (!entry.open || change.channelId === session.channelId) return;
218
+ // A link that left to join again, for a speaker it does not hear, was not removed.
219
+ if (change.channelId === undefined && entry.link?.leftItself()) return;
200
220
  return end(entry, change.channelId === undefined ? "removed" : "moved");
201
221
  }
202
222
  if (change.channelId === session.channelId)
@@ -219,6 +239,14 @@ export function voiceService(options: VoiceServiceOptions): VoiceService {
219
239
  onStatus(entry, status);
220
240
  },
221
241
  frame: (userId, pcm) => entry.session.frame(userId, pcm),
242
+ person: (userId) =>
243
+ entry.session
244
+ .members()
245
+ .some(
246
+ (member) =>
247
+ !member.bot &&
248
+ (userId === undefined || member.userId === userId),
249
+ ),
222
250
  });
223
251
  settle(link.status());
224
252
  });
@@ -15,7 +15,7 @@ export type VoiceDisconnectReason =
15
15
  | "left" // the plugin called `leave()`
16
16
  | "removed" // the bot was disconnected from the channel: someone disconnected it, or the channel was deleted
17
17
  | "moved" // someone moved the bot to another channel; a session never follows
18
- | "connection_lost" // the voice connection dropped and did not come back within the resume time
18
+ | "connection_lost" // the voice connection dropped and did not come back within the resume time, or it heard nothing while someone spoke and neither setting it up again nor rejoining the channel brought the audio back
19
19
  | "stopped"; // the host is stopping
20
20
 
21
21
  /** Someone in a voice channel. */
@@ -19,9 +19,9 @@ export interface BlockSupport {
19
19
  */
20
20
  readonly lang?: TextLang;
21
21
  /**
22
- * `false` = the surface's own guidance already says what it cannot do with forms, option
23
- * buttons and checklists, so core adds no line about them. Absent = core adds one whenever the
24
- * surface does not draw every interactive kind.
22
+ * `false` = the surface's own guidance already says what becomes of a form, option-button or
23
+ * checklist block it does not draw, so core adds no line about them. Absent = core adds one
24
+ * whenever the surface does not draw every interactive kind.
25
25
  */
26
26
  readonly blockNote?: false;
27
27
  }
@@ -37,7 +37,9 @@ export interface ChannelSupport extends BlockSupport {
37
37
  * channel's `support` lays what differs (a host's room on an app, which draws no blocks). A
38
38
  * surface that does not draw every interactive kind (`options`, `suggest`, `form`, `checklist`,
39
39
  * `review`) gets a closing line in its `formatting` that says so, so the model does not expect
40
- * its reader to fill one in. `lang` is the host's language for the text form of a block.
40
+ * its reader to fill one in. The line speaks of blocks written in a reply and of nothing else:
41
+ * a tool that asks the user on the surface's own cards, as `ask_user` does, is not a block.
42
+ * `lang` is the host's language for the text form of a block.
41
43
  */
42
44
  export function supportOf(
43
45
  surface:
@@ -73,16 +75,20 @@ export function supportOf(
73
75
 
74
76
  /**
75
77
  * What the model is told about the interactive kinds a surface does not draw: none when it draws
76
- * them all. Such a block reaches the reader as a question to answer by typing.
78
+ * them all. Such a block reaches the reader as a question to answer by typing. It names blocks
79
+ * written in a reply only, and says so: read as "this chat has no buttons", it kept a model from
80
+ * `ask_user`, whose card with buttons the same chat shows.
77
81
  */
78
82
  function interactiveNote(
79
83
  blocks: readonly BlockKind[] | undefined,
80
84
  ): string | undefined {
81
85
  const missing = INTERACTIVE_KINDS.filter((kind) => !blocks?.includes(kind));
82
86
  if (missing.length === 0) return undefined;
83
- const cannot =
87
+ const notDrawn =
84
88
  missing.length === INTERACTIVE_KINDS.length
85
- ? "forms, option buttons or checklists"
86
- : `${missing.map((kind) => `\`${kind}\``).join(", ")} blocks`;
87
- return `This chat cannot show ${cannot}. Ask in plain text. If you write such a block anyway, the user sees it as text and answers by typing.`;
89
+ ? "Display blocks that ask for input (a form, option buttons or a checklist written as a fenced block in a reply) are"
90
+ : missing.length === 1
91
+ ? `The display block \`${missing[0]}\` is`
92
+ : `The display blocks ${missing.map((kind) => `\`${kind}\``).join(", ")} are`;
93
+ return `${notDrawn} not drawn in this chat: the user sees one as text and answers by typing, so put the question in plain words instead of writing one. This is about blocks written in a reply only: a tool that asks the user, such as ask_user, works as its description says.`;
88
94
  }
@@ -122,6 +122,7 @@ export function fakeDiscordVoice(
122
122
  onVoiceState: (listener) => {
123
123
  report = listener;
124
124
  },
125
+ onReady: () => undefined,
125
126
  prepare: async () => undefined,
126
127
  connect: async ({ guildId, channelId }) => {
127
128
  let status: VoiceLinkStatus = "ready";
@@ -136,6 +137,7 @@ export function fakeDiscordVoice(
136
137
  link.handlers = handlers;
137
138
  },
138
139
  forget: () => undefined,
140
+ leftItself: () => false,
139
141
  close: () => {
140
142
  status = "closed";
141
143
  if (links.get(guildId) === link) links.delete(guildId);