pi-roundtable 0.49.1 → 0.50.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/CHANGELOG.md CHANGED
@@ -5,6 +5,23 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.50.1] - 2026-11-16
9
+
10
+ ### Fixed
11
+
12
+ - `ChannelContextOptions.conversation` that throws, or returns something other than a string or `undefined`, is now logged and counts as `undefined` instead of rejecting the read; the docs say to set it as the host default or on every read of a channel, since an unnamed read is a conversation of its own.
13
+ - The sandbox's `channelContext` refuses `conversation` (a clear error) and ignores a host default of it: its history is one file per channel that never starts fresh for another asker, so the option would only hand the window over again.
14
+
15
+ ## [0.50.0] - 2026-11-16
16
+
17
+ ### Added
18
+
19
+ - `ChannelContextOptions.conversation(message)` (and the host default `discord.channelContext.conversation`, code only) names the conversation a turn runs in, such as the principal of a person's private conversation in a forum post. What channel context remembers as handed over then belongs to that conversation: a turn of another conversation than the channel's last reads the window as if nothing had been handed over, the thread's starter too, so a second person who asks in a post gets the card, the comments and the earlier discussion that the first asker's turn already read. One record is still kept per channel, so it takes no more memory. Without the option nothing changes. The sandbox's `channelContext` accepts it.
20
+
21
+ ### Fixed
22
+
23
+ - `discord.channelContext.authors` is accepted as a host default, as the plugin docs describe; the configuration refused it as an unknown key.
24
+
8
25
  ## [0.49.1] - 2026-11-16
9
26
 
10
27
  ### Fixed
package/docs/plugins.md CHANGED
@@ -2767,11 +2767,12 @@ The same call works on any surface. A chat surface a plugin contributes implemen
2767
2767
  It reads Discord, not the host's history, so it survives restarts:
2768
2768
 
2769
2769
  - It fetches the `fetch` messages before the addressed one (default 50, at most 100) and keeps those after the assistant's latest post there: its bot user's, or one of its application's webhooks, such as an agent's voice. Any post of the assistant ends the window, including the divider the core posts when a conversation starts over (see `discord.freshMarker`) and a notice that it did; a fresh-start reply must be a public post, not an ephemeral one, to cut the window.
2770
- - It leaves out the assistant's own posts, the addressed message, empty messages, and every message it handed over before or that addressed it before in that channel, remembered in memory per channel, so a restart can repeat at most what came since the assistant's last post.
2770
+ - It leaves out the assistant's own posts, the addressed message, empty messages, and every message it handed over before or that addressed it before in that channel, remembered in memory per channel, so a restart can repeat at most what came since the assistant's last post (per conversation with `conversation`, below).
2771
2771
  - Other bots and integrations are kept and marked as bots; the host's owners (the primary owner and every other owner's Discord identities) are marked as owners.
2772
2772
  - Consecutive messages of one author at least `similarity` alike (default 0.8, by their longest common run of text) count as one, the later kept.
2773
2773
  - It keeps the newest `keep` (default 15), oldest first. Mentions read as names, and stickers and files as text with their names and links; by default nothing is downloaded or shown to the model as an image (see `attachments` below). A message is cut at `messageChars` (default 500), another bot's at `botMessageChars` (default 80), and a peer bot's (one `discord.peerBots` lists for the channel, see below) at `peerMessageChars` (default 4000).
2774
2774
  - With `starter: true` (default false) a thread's opening message is always part of the context, even when it lies outside the `fetch` messages: a forum post's first message (its id is the thread's), or the message a text channel's thread was started from (`fetchStarterMessage`). It comes first, outside `keep` (a context may hold `keep` messages plus the starter), is cut at the same limits as any message by its author, and is not repeated when the window holds it already. It passes the same filters as every other message: `authors` (or `foreignWebhook`) answering `"skip"` or `"end"` for it, an empty text, the assistant's own post, and a message handed over or addressed before drop it, so it comes in the first turn that reads it and not again (the conversation's history carries it from then on); it is also dropped when it is the addressed message itself. It stays even when the assistant's last post lies after it. A channel that is not a thread, a thread without a starter (private, or its starter deleted) and a starter Discord will not return add nothing and never fail the turn (an unexpected refusal is logged at debug). A chat surface of another network that implements `channelContext` reads `starter` itself.
2775
+ - With `conversation(message)` (default none) the record of what was handed over belongs to a conversation, not only to the channel. Use it where one channel holds several conversations in turn, such as a forum post where each person who asks gets a private conversation of their own (`TurnRequest.conversation` naming their principal), which the runtime makes anew, without the earlier person's history, when the asker changes. Return a key of the conversation the turn for `message` runs in, such as that principal id, or `undefined` for the channel's own. A turn of the conversation the channel's last turn ran in reads only what is new to it, as without the option; a turn of another conversation reads the window as if nothing had been handed over, the starter too. So a second person who asks in a post gets the card, the comments and the earlier discussion, and the first who asks again after them gets them once more, since their session was made anew too. One record is kept per channel either way, as many ids as before, so the option takes no more memory. Set it as the host default or pass it on every read of a channel: a read that names none is the channel's own conversation, a key of its own, so mixing named and unnamed reads of one channel starts the record anew each time and hands the window over again. A callback that throws, or returns something other than a string or `undefined`, is logged and counts as `undefined`. The sandbox refuses the option and ignores a host default of it, since its history is one file per channel that never starts fresh. It is a function, so it is set only in code, as a host default (`discord.channelContext.conversation`) or per call. The window still ends at the assistant's last post; a forum that wants the whole post answers `"skip"` for the assistant's answers with `authors`.
2775
2776
  - It never fails the turn over Discord: a Discord error, such as a channel the bot cannot read, is logged and the turn runs without context.
2776
2777
 
2777
2778
  A plugin may mirror an outside chat into a channel through a webhook of its own, created by the bot, so that the application owns it; by default such a post counts as the assistant's own, which ends the window and is left out, and the people mirrored never reach a turn. `foreignWebhook(webhookId)` changes that for the webhooks it returns true for: a post through one is another author's, kept like another bot's (`bot: true`, `authorName` the post's username, `authorId` the webhook's id) and no longer ends the window, which then ends only at the assistant's own posts: its bot user's and every webhook `foreignWebhook` returns false for, such as an agent's voice. It may also return `"skip"` for a webhook that is neither, such as one the plugin posts its own status notices through: a post through it is dropped from the context and does not end the window, as if it were not in the channel, so notices between two mirrored posts neither appear as someone's words nor cut the window, and they are not counted among the messages delivered. Any answer other than `true` and `"skip"` reads as false. A skipped post is still one of the `fetch` messages read, so it uses the budget the window is chosen from. The host sets it as `discord.channelContext.foreignWebhook` and a call overrides it for that call; being a function, it can be set only in code. `authors(message)` is the same decision for any surface and any message, not only a webhook's: it receives the fetched message (`ChannelContextSource`: `id`, `authorId`, `authorName`, `bot`, `own`, `webhookId?`, `external?`, `attachments?`, `at`, `text`) and answers `"keep"` (another author's, which does not end the window; `foreignWebhook` returning `true`), `"skip"` (dropped as if it were not in the channel, without ending the window; `"skip"` of `foreignWebhook`), `"end"` (the assistant's own, which ends the window and is left out; `foreignWebhook` returning `false` for an application webhook) or `undefined`, which leaves the default: the assistant's own posts end the window and everything else is kept. Where it answers, it wins over `foreignWebhook`; it is a function, so it can be set only in code, as a host default (`discord.channelContext.authors`) or per call. Posts through a webhook that `foreignWebhook` returns true for are merged as near repeats only when the poster's name is the same too, since one webhook carries many people; every other message merges by author alone, as before. An edited message reads as Discord now holds it.
@@ -2783,7 +2784,7 @@ Every returned message has `attachments` (`ChannelContextAttachment`: `name`, `c
2783
2784
  `DISCORD.channelContext` resolves undefined in a direct message, on another surface, when nothing new was said, and when the host's `discord.channelContext` is `false`, which turns it off for the agent server and every claim.
2784
2785
  The configuration's values are the host's defaults, and a call's `options` override them for that call.
2785
2786
  Call it once per answered message: what it returns is remembered as handed over.
2786
- A call's `options` are validated like the configuration (`fetch`, `keep`, `messageChars`, `botMessageChars` and `peerMessageChars` positive integers, `similarity` from 0 to 1, `starter` a boolean, `foreignWebhook` a function of a webhook id returning `true`, `false` or `"skip"`, `authors` a function of a message returning `"keep"`, `"skip"`, `"end"` or `undefined`, `attachments.images` an integer from 0 to 4, `attachments.maxBytes` an integer from 1 to 25 MiB); an invalid one makes the call reject, a programming error, so `keep: 0` is not "none" (skip the call for that).
2787
+ A call's `options` are validated like the configuration (`fetch`, `keep`, `messageChars`, `botMessageChars` and `peerMessageChars` positive integers, `similarity` from 0 to 1, `starter` a boolean, `conversation` a function of a message returning a string or `undefined`, `foreignWebhook` a function of a webhook id returning `true`, `false` or `"skip"`, `authors` a function of a message returning `"keep"`, `"skip"`, `"end"` or `undefined`, `attachments.images` an integer from 0 to 4, `attachments.maxBytes` an integer from 1 to 25 MiB); an invalid one makes the call reject, a programming error, so `keep: 0` is not "none" (skip the call for that).
2787
2788
  It remembers what it handed over and what addressed the assistant, not every message that ran a turn: a post a claim answered some other way, such as a webhook report turn or a steered message, can also come in the context of a later turn if the assistant has not posted since.
2788
2789
 
2789
2790
  What it returns is public channel text, visible to everyone in the channel; it is not private memory, carries no `privateTo`, and goes into the turn's text, so it lives in the conversation's history, not in the system prompt.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-roundtable",
3
- "version": "0.49.1",
3
+ "version": "0.50.1",
4
4
  "description": "A plugin-driven Pi agent server for one owner, reached through Discord or the web",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,4 +1,9 @@
1
- import type { ChannelContextOptions } from "../contract/channel-context.ts";
1
+ import type {
2
+ ChannelContextOptions,
3
+ ChannelContextSource,
4
+ ChannelContextVerdict,
5
+ } from "../contract/channel-context.ts";
6
+ import type { InboundMessage } from "../contract/channels.ts";
2
7
  import { ConfigError } from "../domain/errors.ts";
3
8
  import { type PeerBotsConfig, peerBotsShape } from "./peer-bots.ts";
4
9
  import {
@@ -199,6 +204,23 @@ const channelContextShape = shape({
199
204
  typeof value === "function",
200
205
  ),
201
206
  ),
207
+ authors: optional(
208
+ guarded(
209
+ "a function of a fetched message",
210
+ (
211
+ value,
212
+ ): value is (
213
+ message: ChannelContextSource,
214
+ ) => ChannelContextVerdict | undefined => typeof value === "function",
215
+ ),
216
+ ),
217
+ conversation: optional(
218
+ guarded(
219
+ "a function of a message",
220
+ (value): value is (message: InboundMessage) => string | undefined =>
221
+ typeof value === "function",
222
+ ),
223
+ ),
202
224
  attachments: optional(
203
225
  shape({
204
226
  images: optional(integer(0, 4)),
@@ -65,13 +65,30 @@ export interface ChannelContextOptions {
65
65
  * a thread. The starter is subject to every filter of the other messages: `authors` (or
66
66
  * `foreignWebhook`) saying `"skip"` or `"end"` for it drops it, as do an empty text, the
67
67
  * assistant's own post and a message handed over (or addressed to the assistant) before, so it
68
- * comes in the first turn's context and not again. It is also dropped when it is the addressed
69
- * message itself. It comes first, oldest first, outside `keep` (a context may hold `keep` plus
70
- * the starter), is cut at the same limits as another message by its author, and never merges as
71
- * a near repeat; when the window holds it already it is not repeated, and it stays even when
72
- * the assistant's last post lies after it.
68
+ * comes in the first turn's context and not again (in each conversation, with `conversation`).
69
+ * It is also dropped when it is the addressed message itself. It comes first, oldest first,
70
+ * outside `keep` (a context may hold `keep` plus the starter), is cut at the same limits as
71
+ * another message by its author, and never merges as a near repeat; when the window holds it
72
+ * already it is not repeated, and it stays even when the assistant's last post lies after it.
73
73
  */
74
74
  starter?: boolean;
75
+ /**
76
+ * Names the conversation the turn for `message` runs in, when one channel holds several in turn,
77
+ * such as a forum post where each person who asks gets a private conversation of their own: a
78
+ * key of it, such as the principal id of the private `TurnRequest.conversation` the turn runs
79
+ * in. What is remembered as handed over then belongs to that conversation: a turn of the
80
+ * conversation the channel's last turn ran in reads only what is new to it, as without this
81
+ * option, and a turn of another one reads the window as if nothing had been handed over, the
82
+ * starter too, since the runtime makes that conversation's session anew without the other's
83
+ * history. So a second person who asks in a post gets the earlier messages and the starter, and
84
+ * the first who asks again after them gets them once more. `undefined` names the channel's own
85
+ * conversation. One record is kept per channel either way, so the memory it takes is as without
86
+ * this option. Set it as the host default or on every read of a channel: a read that names none
87
+ * is the channel's own conversation, a key of its own, so mixing named and unnamed reads starts
88
+ * the record anew each time. A callback that throws or returns a non-string is logged and counts
89
+ * as `undefined`. Default: none, every turn of a channel is one conversation's.
90
+ */
91
+ conversation?: (message: InboundMessage) => string | undefined;
75
92
  /** Which attachments of the kept messages are fetched for the turn; none by default. */
76
93
  attachments?: ChannelContextAttachmentOptions;
77
94
  }
@@ -27,6 +27,7 @@ export const CHANNEL_CONTEXT_DEFAULTS: Readonly<
27
27
  foreignWebhook: () => false,
28
28
  authors: () => undefined,
29
29
  starter: false,
30
+ conversation: () => undefined,
30
31
  attachments: Object.freeze({ images: 0, maxBytes: 10 * 1024 * 1024 }),
31
32
  });
32
33
 
@@ -87,6 +88,10 @@ export function assertChannelContextSettings(
87
88
  throw new TypeError("channel context option authors must be a function");
88
89
  if (typeof settings.starter !== "boolean")
89
90
  throw new TypeError("channel context option starter must be a boolean");
91
+ if (typeof settings.conversation !== "function")
92
+ throw new TypeError(
93
+ "channel context option conversation must be a function",
94
+ );
90
95
  if (!Number.isInteger(images) || images < 0 || images > MAX_TURN_IMAGES)
91
96
  throw new RangeError(
92
97
  `channel context option attachments.images must be an integer from 0 to ${MAX_TURN_IMAGES}, got ${images}`,
@@ -161,6 +161,7 @@ export interface ChannelContextSelection {
161
161
  | "attachments"
162
162
  | "peerMessageChars"
163
163
  | "starter"
164
+ | "conversation"
164
165
  > &
165
166
  Partial<
166
167
  Pick<
@@ -311,11 +312,16 @@ export interface ChannelContextReaderOptions {
311
312
 
312
313
  /**
313
314
  * Reads the channel context of addressed messages and remembers, per channel and in memory, what
314
- * it handed over and which messages addressed the assistant, so neither comes again.
315
+ * it handed over and which messages addressed the assistant, so neither comes again; a turn of
316
+ * another conversation than the channel's last (`ChannelContextOptions.conversation`) starts
317
+ * the channel's record anew.
315
318
  */
316
319
  export class ChannelContextReader {
317
320
  readonly #options: ChannelContextReaderOptions;
318
- readonly #seen = new Map<string, Set<string>>();
321
+ readonly #seen = new Map<
322
+ string,
323
+ { conversation: string | undefined; ids: Set<string> }
324
+ >();
319
325
 
320
326
  constructor(options: ChannelContextReaderOptions) {
321
327
  this.#options = options;
@@ -337,7 +343,10 @@ export class ChannelContextReader {
337
343
  if (surface !== "discord") return undefined;
338
344
  const settings = resolvedSettings(host, options);
339
345
  assertChannelContextSettings(settings);
340
- const seen = this.#seenIn(channelId);
346
+ const seen = this.#seenIn(
347
+ channelId,
348
+ this.#conversationOf(settings, message),
349
+ );
341
350
  seen.add(message.messageId);
342
351
  try {
343
352
  const fetched = await this.#options.read(
@@ -435,15 +444,37 @@ export class ChannelContextReader {
435
444
  }
436
445
  }
437
446
 
438
- #seenIn(channelId: string): Set<string> {
439
- let seen = this.#seen.get(channelId);
440
- if (!seen) {
441
- seen = new Set();
442
- this.#seen.set(channelId, seen);
443
- const oldest = this.#seen.keys().next().value;
444
- if (this.#seen.size > SEEN_CHANNELS && oldest !== undefined)
445
- this.#seen.delete(oldest);
447
+ /** The conversation the callback names; a throw or a value that is no string is logged and counts as none. */
448
+ #conversationOf(
449
+ settings: ChannelContextSettings,
450
+ message: InboundMessage,
451
+ ): string | undefined {
452
+ try {
453
+ const given: unknown = settings.conversation(message);
454
+ if (given === undefined || typeof given === "string") return given;
455
+ throw new TypeError(
456
+ `channel context option conversation returned ${typeof given}, not a string or undefined`,
457
+ );
458
+ } catch (error) {
459
+ this.#options.logger.warn(
460
+ { channel: message.channel, err: error },
461
+ "channel context conversation not named; the channel's own is used",
462
+ );
463
+ return undefined;
446
464
  }
465
+ }
466
+
467
+ /** The channel's record of what was handed over, made anew for a conversation other than its own. */
468
+ #seenIn(channelId: string, conversation: string | undefined): Set<string> {
469
+ const record = this.#seen.get(channelId);
470
+ if (record && record.conversation === conversation) return record.ids;
471
+ const seen = new Set<string>();
472
+ // Another conversation's record is replaced, not kept beside it: the channel holds one at a time.
473
+ this.#seen.delete(channelId);
474
+ this.#seen.set(channelId, { conversation, ids: seen });
475
+ const oldest = this.#seen.keys().next().value;
476
+ if (this.#seen.size > SEEN_CHANNELS && oldest !== undefined)
477
+ this.#seen.delete(oldest);
447
478
  return seen;
448
479
  }
449
480