pi-roundtable 0.50.0 → 0.50.2
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 +13 -0
- package/docs/plugins.md +1 -1
- package/package.json +1 -1
- package/src/core/contract/channel-context.ts +4 -1
- package/src/core/discord/channel-context.ts +24 -1
- package/src/core/discord/inbound-message.ts +12 -6
- package/src/core/discord/owner-card-types.ts +5 -0
- package/src/core/discord/owner-cards-fixture.ts +14 -1
- package/src/core/discord/owner-cards.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.50.2] - 2026-11-16
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- A card answered after its turn stopped waiting now starts its late turn with the card's thread (`thread.parentId` and `parentKind`), as the live message there carries it, so a consumer that routes by thread, such as a forum post, handles the late answer the same way as a live one.
|
|
13
|
+
|
|
14
|
+
## [0.50.1] - 2026-11-16
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- `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.
|
|
19
|
+
- 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.
|
|
20
|
+
|
|
8
21
|
## [0.50.0] - 2026-11-16
|
|
9
22
|
|
|
10
23
|
### Added
|
package/docs/plugins.md
CHANGED
|
@@ -2772,7 +2772,7 @@ It reads Discord, not the host's history, so it survives restarts:
|
|
|
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. 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
|
+
- 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`.
|
|
2776
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.
|
|
2777
2777
|
|
|
2778
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.
|
package/package.json
CHANGED
|
@@ -83,7 +83,10 @@ export interface ChannelContextOptions {
|
|
|
83
83
|
* history. So a second person who asks in a post gets the earlier messages and the starter, and
|
|
84
84
|
* the first who asks again after them gets them once more. `undefined` names the channel's own
|
|
85
85
|
* conversation. One record is kept per channel either way, so the memory it takes is as without
|
|
86
|
-
* this option.
|
|
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.
|
|
87
90
|
*/
|
|
88
91
|
conversation?: (message: InboundMessage) => string | undefined;
|
|
89
92
|
/** Which attachments of the kept messages are fetched for the turn; none by default. */
|
|
@@ -343,7 +343,10 @@ export class ChannelContextReader {
|
|
|
343
343
|
if (surface !== "discord") return undefined;
|
|
344
344
|
const settings = resolvedSettings(host, options);
|
|
345
345
|
assertChannelContextSettings(settings);
|
|
346
|
-
const seen = this.#seenIn(
|
|
346
|
+
const seen = this.#seenIn(
|
|
347
|
+
channelId,
|
|
348
|
+
this.#conversationOf(settings, message),
|
|
349
|
+
);
|
|
347
350
|
seen.add(message.messageId);
|
|
348
351
|
try {
|
|
349
352
|
const fetched = await this.#options.read(
|
|
@@ -441,6 +444,26 @@ export class ChannelContextReader {
|
|
|
441
444
|
}
|
|
442
445
|
}
|
|
443
446
|
|
|
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;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
444
467
|
/** The channel's record of what was handed over, made anew for a conversation other than its own. */
|
|
445
468
|
#seenIn(channelId: string, conversation: string | undefined): Set<string> {
|
|
446
469
|
const record = this.#seen.get(channelId);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Channel,
|
|
3
|
+
ChannelType,
|
|
4
|
+
type Message,
|
|
5
|
+
MessageReferenceType,
|
|
6
|
+
} from "discord.js";
|
|
2
7
|
import type { InboundMessage } from "../contract/channels.ts";
|
|
3
8
|
import { channelKey } from "../contract/surface.ts";
|
|
4
9
|
import type { AttachmentRef } from "../domain/attachment.ts";
|
|
@@ -38,11 +43,10 @@ function referenceOf(referenced: Message, mention: RegExp) {
|
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
/** What a thread's parent is: a text channel, a forum, or something else (also a parent that cannot be read). */
|
|
41
|
-
async function threadOf(
|
|
42
|
-
|
|
46
|
+
export async function threadOf(
|
|
47
|
+
channel: Channel | null | undefined,
|
|
43
48
|
): Promise<InboundMessage["thread"] | undefined> {
|
|
44
|
-
|
|
45
|
-
if (!channel.isThread() || !channel.parentId) return undefined;
|
|
49
|
+
if (!channel?.isThread() || !channel.parentId) return undefined;
|
|
46
50
|
const parent =
|
|
47
51
|
channel.parent ??
|
|
48
52
|
(await channel.guild.channels.fetch(channel.parentId).catch(() => null));
|
|
@@ -87,7 +91,7 @@ export async function toInbound(
|
|
|
87
91
|
const roleIds = message.member
|
|
88
92
|
? [...message.member.roles.cache.keys()]
|
|
89
93
|
: undefined;
|
|
90
|
-
const thread = await threadOf(message);
|
|
94
|
+
const thread = await threadOf(message.channel);
|
|
91
95
|
return {
|
|
92
96
|
channel: channelKey("discord", message.channelId),
|
|
93
97
|
messageId: message.id,
|
|
@@ -169,6 +173,8 @@ export function lateAnswerMessage(turn: LateTurn): InboundMessage {
|
|
|
169
173
|
...(roles ? { authorRoleIds: roles } : {}),
|
|
170
174
|
...(turn.guildId ? { space: turn.guildId } : {}),
|
|
171
175
|
isDirect: turn.isDirect,
|
|
176
|
+
// The card's thread, as the live message there carries it, so a consumer routes it the same.
|
|
177
|
+
...(turn.thread ? { thread: turn.thread } : {}),
|
|
172
178
|
// Pressing the assistant's card speaks to it, as a mention does.
|
|
173
179
|
mentionsBot: true,
|
|
174
180
|
repliesToBot: true,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TextDisplayBuilder } from "discord.js";
|
|
2
|
+
import type { InboundMessage } from "../contract/channels.ts";
|
|
2
3
|
import type {
|
|
3
4
|
ApprovedBy,
|
|
4
5
|
OwnerQuestion,
|
|
@@ -45,6 +46,8 @@ export interface LateTurn {
|
|
|
45
46
|
/** The server the channel belongs to; absent in a direct message. */
|
|
46
47
|
guildId?: string;
|
|
47
48
|
isDirect: boolean;
|
|
49
|
+
/** The thread the card was posted in, and its parent; absent outside a thread. */
|
|
50
|
+
thread?: InboundMessage["thread"];
|
|
48
51
|
text: string;
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -56,6 +59,8 @@ export interface Answerer {
|
|
|
56
59
|
messageId?: string;
|
|
57
60
|
guildId?: string;
|
|
58
61
|
isDirect: boolean;
|
|
62
|
+
/** The thread the card was answered in, and its parent. */
|
|
63
|
+
thread?: InboundMessage["thread"];
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
/** One open card: how it looks, and how it ends. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { ChannelType, type Interaction } from "discord.js";
|
|
2
2
|
import { CARD_PREFIX, type CardPayload } from "./owner-cards.ts";
|
|
3
3
|
|
|
4
4
|
/** The primary owner of the cards' tests. */
|
|
@@ -53,6 +53,8 @@ export function press(
|
|
|
53
53
|
fields?: Record<string, string>;
|
|
54
54
|
/** Holds `deferUpdate` until it resolves, so the card can change while the press is in flight. */
|
|
55
55
|
gate?: Promise<void>;
|
|
56
|
+
/** The thread the card sits in: its parent and the parent's kind. */
|
|
57
|
+
thread?: { parentId: string; forum: boolean };
|
|
56
58
|
} = {},
|
|
57
59
|
) {
|
|
58
60
|
const replies: string[] = [];
|
|
@@ -74,6 +76,17 @@ export function press(
|
|
|
74
76
|
inGuild: () => true,
|
|
75
77
|
guildId: "300000000000000003",
|
|
76
78
|
message: { id: "400000000000000004" },
|
|
79
|
+
channel: options.thread
|
|
80
|
+
? {
|
|
81
|
+
isThread: () => true,
|
|
82
|
+
parentId: options.thread.parentId,
|
|
83
|
+
parent: {
|
|
84
|
+
type: options.thread.forum
|
|
85
|
+
? ChannelType.GuildForum
|
|
86
|
+
: ChannelType.GuildText,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
: null,
|
|
77
90
|
user: { id: options.user ?? OWNER },
|
|
78
91
|
member: {
|
|
79
92
|
roles: { cache: new Map((options.roles ?? []).map((r) => [r, r])) },
|
|
@@ -12,6 +12,7 @@ import type { Logger } from "../kernel/log.ts";
|
|
|
12
12
|
import { type CardAudienceOptions, CardAudiences } from "./card-audience.ts";
|
|
13
13
|
import { CardCopies, copyReply, offeredCopy } from "./card-copies.ts";
|
|
14
14
|
import { DiscordOwners, discordUser } from "./discord-owners.ts";
|
|
15
|
+
import { threadOf } from "./inbound-message.ts";
|
|
15
16
|
import type { InteractionModule } from "./interaction-module.ts";
|
|
16
17
|
import {
|
|
17
18
|
answerDeferred,
|
|
@@ -289,6 +290,7 @@ export class OwnerCards implements InteractionModule {
|
|
|
289
290
|
user: by.user,
|
|
290
291
|
...(by.guildId ? { guildId: by.guildId } : {}),
|
|
291
292
|
isDirect: by.isDirect,
|
|
293
|
+
...(by.thread ? { thread: by.thread } : {}),
|
|
292
294
|
text,
|
|
293
295
|
});
|
|
294
296
|
} catch (error) {
|
|
@@ -382,11 +384,13 @@ export class OwnerCards implements InteractionModule {
|
|
|
382
384
|
return true;
|
|
383
385
|
}
|
|
384
386
|
const user = discordUser(interaction);
|
|
387
|
+
const thread = await threadOf(interaction.channel);
|
|
385
388
|
const by: Answerer = {
|
|
386
389
|
user,
|
|
387
390
|
...(interaction.message ? { messageId: interaction.message.id } : {}),
|
|
388
391
|
...(interaction.guildId ? { guildId: interaction.guildId } : {}),
|
|
389
392
|
isDirect: !interaction.inGuild(),
|
|
393
|
+
...(thread ? { thread } : {}),
|
|
390
394
|
};
|
|
391
395
|
// A menu pick or Submit is deferred before the audience is looked up, which may take a while.
|
|
392
396
|
if (
|