pi-roundtable 0.39.1 → 0.40.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.
- package/CHANGELOG.md +11 -0
- package/docs/plugins.md +5 -3
- package/package.json +2 -2
- package/src/core/agents/team-turn-types.ts +7 -1
- package/src/core/agents/team-turns.ts +5 -1
- package/src/core/contract/surface.ts +18 -2
- package/src/core/domain/block-support.ts +50 -3
- package/src/core/host/host-registration.ts +4 -1
- package/src/core/presence/delivery-router.ts +7 -2
- package/src/core/presentation/reply-chunks.ts +14 -3
- package/src/core/routing/conversation-turns.ts +4 -1
- package/src/core/routing/surface-port.ts +10 -1
- package/src/core/testing/surface-contract-blocks.ts +6 -1
- package/src/core/threads/dispatch-threads.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.40.0] - 2026-11-08
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- A chat that cannot show an interactive block no longer lets the model believe its reader can fill one in. Core closes the formatting guidance of a turn on any surface whose `blocks` lack an interactive kind (`options`, `suggest`, `form`, `checklist`, `review`) with one line: the chat cannot show forms, option buttons or checklists, so ask in plain text; such a block is shown as text and answered by typing. Discord, LINE, the web chat and a host's room get it without editing their own strings; a surface whose guidance already says so sets `ChatSurface.blockNote: false`. A surface that lists an interactive kind in `blocks` promises that the reader's answer reaches the agent as a message from them.
|
|
13
|
+
- A block that reads as text asks in the host's language: `ChatSurface.lang` (`en` or `zh-TW`) and `SurfacePort.lang`, the locale the host was defined with, reach `supportOf(surface, channel, lang)`, `chunksFor` and `textFor`. The reply instructions of `options`, `form`, `review`, `suggest` and `checklist` read in Traditional Chinese for a `zh-TW` host.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- `pi-better-show` is pinned to 0.3.0.
|
|
18
|
+
|
|
8
19
|
## [0.39.1] - 2026-11-08
|
|
9
20
|
|
|
10
21
|
- Release in lockstep with pi-roundtable 0.39.1 (the coding plugin reads its stored worker limit at start, so `Roundtable.check()` passes with `settingsInDatabase`); no package-specific behavior changes.
|
package/docs/plugins.md
CHANGED
|
@@ -3126,9 +3126,11 @@ The agent server claims `discord:` keys, and, only on a surface that declares `a
|
|
|
3126
3126
|
| `readAttachment(channel, ref)` | Returns the content of an attachment this surface made, such as an upload to a room, as `Promise<AttachmentContent>`: the bytes, `{ path }` of a file on the host, or a stream, the last two stored without holding them whole; the agent server's claim reads the refs of the surface's messages here and never fetches them over the network, and a rejection fails that file. A claim of your own passes the same function as `read` to `attachmentsOf`, or its refs are downloaded | the refs' URLs are downloaded, up to 25 MB each |
|
|
3127
3127
|
| `maxAttachmentBytes` | The most bytes of one attachment a turn takes from this surface, for a ref, a file, a stream or a download alike; a positive integer, so a surface that keeps large uploads can raise it past 25 MiB. See [files from outside a turn](#contextattachments-files-from-outside-a-turn) | 25 MiB, as Discord's |
|
|
3128
3128
|
| `formatting` | A short English text on how a reply renders here, such as "no Markdown tables"; the runtime appends it to the system prompt of every turn that replies on this surface, after the persona | nothing is appended |
|
|
3129
|
-
| `blocks` | The [display-block](#display-blocks-in-a-reply) kinds the surface draws itself, such as `["table", "mermaid"]` (`BlockKind` of `pi-better-show`); a reply reaches `sendReply` whole, with the fences of those kinds intact. Every other block arrives as text | none: every block arrives as text |
|
|
3129
|
+
| `blocks` | The [display-block](#display-blocks-in-a-reply) kinds the surface draws itself, such as `["table", "mermaid"]` (`BlockKind` of `pi-better-show`); a reply reaches `sendReply` whole, with the fences of those kinds intact. Every other block arrives as text. Listing an interactive kind (`options`, `suggest`, `form`, `checklist`, `review`) also promises that the reader's answer reaches the agent as a message from them, as typing it would | none: every block arrives as text |
|
|
3130
3130
|
| `blockText` | How a block the surface does not draw reads as text: `"discord"` (Markdown, with Discord's native `diff` fence), `"line"` (plain text without Markdown markup) or `"plain"` | `"discord"` |
|
|
3131
|
-
| `
|
|
3131
|
+
| `lang` | The language (`"en"` or `"zh-TW"`) a block the surface does not draw asks its reader to answer in, such as "Reply with a number." | the host's locale |
|
|
3132
|
+
| `blockNote` | `false` when the surface's own `formatting` already says what it cannot do with forms, option buttons and checklists, so core adds no line about them | core adds the line whenever the surface does not draw every interactive kind |
|
|
3133
|
+
| `support(channel)` | What differs in one channel of the surface: a `formatting`, `blocks`, `blockText`, `lang` or `blockNote` that replaces the surface's own for a turn that replies there, such as a host's room on a surface that draws blocks only in its own rooms. Return `undefined` for a channel that is like the rest | every channel is like the surface |
|
|
3132
3134
|
| `startTyping(channel)` | Shows a typing indicator until the returned function is called | none is shown |
|
|
3133
3135
|
| `showStop(channel)` | Shows the owner a stop control until the returned function is called; using it calls `conversations.stop(channel)`. A group's round shows it for the whole round, and stopping ends the round: the member speaking is stopped and the members still waiting do not speak | none is shown |
|
|
3134
3136
|
| `react`, `unreact` | Adds or removes the bot's reaction on a message | no marks on queued or steered messages |
|
|
@@ -3237,7 +3239,7 @@ A custom runtime provider reads the same lookup as `RuntimeDeps.formatting(chann
|
|
|
3237
3239
|
|
|
3238
3240
|
### Display blocks in a reply
|
|
3239
3241
|
|
|
3240
|
-
An agent may write a *display block* in a reply: a fenced block whose first word is a kind (`cards`, `table`, `steps`, `stats`, `mindmap`, `mermaid`, `diff`, `options`, `form`, ...) or a GitHub alert (`> [!NOTE]`), as `pi-better-show` defines. A block is YAML or source that only a surface that draws it should show, so the host cuts agent text with `chunksFor(surface, text)` (from `pi-roundtable/kit`), never `splitReply` alone: a block whose kind the surface does not list in `blocks` becomes text first (Discord's flavor by default, `blockText: "line"` for plain text; a diagram is drawn as Unicode boxes, unless its source is over 3 KB or the drawing, which runs in a worker the host waits on for at most 500 ms, is not done by then, and then the source is shown), and the result is split into messages within Discord's limit. A surface that lists any kind in `blocks` gets the text whole in one chunk, because cutting a fence breaks the block. `textFor(surface, text)` does the conversion alone, for a surface that shows a message of any length in one piece (the web chat's replies and inbox notices) and so needs no cutting. A block that is not closed at the end of the reply is still a block: a text surface gets it as text, and a surface that draws it gets it as written. A block that does not parse becomes a plain code block. The same applies to interim posts: the host's surface port copies the surface's `blocks` and `blockText` onto the `InterimPosts` it returns, so the poster cuts for the right surface. A surface whose channels differ (a host's room, read on a page that does not draw blocks) answers `support(channel)` with what is different, and `supportOf(surface, channel)` (from `pi-roundtable/kit`) reads the result; the formatting guidance a turn gets follows it too. Host notices and error reports are the host's own text and keep `splitReply`.
|
|
3242
|
+
An agent may write a *display block* in a reply: a fenced block whose first word is a kind (`cards`, `table`, `steps`, `stats`, `mindmap`, `mermaid`, `diff`, `options`, `form`, ...) or a GitHub alert (`> [!NOTE]`), as `pi-better-show` defines. A block is YAML or source that only a surface that draws it should show, so the host cuts agent text with `chunksFor(surface, text)` (from `pi-roundtable/kit`), never `splitReply` alone: a block whose kind the surface does not list in `blocks` becomes text first (Discord's flavor by default, `blockText: "line"` for plain text; a diagram is drawn as Unicode boxes, unless its source is over 3 KB or the drawing, which runs in a worker the host waits on for at most 500 ms, is not done by then, and then the source is shown), and the result is split into messages within Discord's limit. A surface that lists any kind in `blocks` gets the text whole in one chunk, because cutting a fence breaks the block. `textFor(surface, text)` does the conversion alone, for a surface that shows a message of any length in one piece (the web chat's replies and inbox notices) and so needs no cutting. A block that is not closed at the end of the reply is still a block: a text surface gets it as text, and a surface that draws it gets it as written. A block that does not parse becomes a plain code block. The same applies to interim posts: the host's surface port copies the surface's `blocks` and `blockText` onto the `InterimPosts` it returns, so the poster cuts for the right surface. A surface whose channels differ (a host's room, read on a page that does not draw blocks) answers `support(channel)` with what is different, and `supportOf(surface, channel)` (from `pi-roundtable/kit`) reads the result; the formatting guidance a turn gets follows it too. A surface that does not draw every interactive kind (`options`, `suggest`, `form`, `checklist`, `review`) gets one more line, closing its `formatting`, which tells the model the chat cannot show forms, option buttons or checklists, to ask in plain text, and that such a block is shown as text for the user to answer by typing; `blockNote: false` leaves it out. A block that reads as text asks in the host's language: `supportOf(surface, channel, surfaces.lang)` carries the locale the host was defined with, and the surface's own `lang` wins. Host notices and error reports are the host's own text and keep `splitReply`.
|
|
3241
3243
|
`describeSurfaceContract` checks that a surface listing `blocks` delivers a block of a declared kind longer than a message whole; `describeBlocksContract(name, make)` registers only that check, for a surface that cannot run the whole contract (the subject needs `surface`, `channel` and `observations()` of the replies its person has seen).
|
|
3242
3244
|
|
|
3243
3245
|
Each message a surface delivers says who wrote it in `actor`, the `ActorFacts` the identity service resolves: `provider` and `subject`, such as `discord` and the user id, `name`, `roles` written `<surface>:role:<name>` (left out where the surface does not know them, such as a Discord DM, which is not the same as none), and `legacyId`, the speaker id 0.8 gave the person, so someone carried over keeps their principal.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-roundtable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
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",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"canvas": "3.2.3",
|
|
72
72
|
"discord.js": "14.27.0",
|
|
73
73
|
"pi-jev-compaction": "1.0.0",
|
|
74
|
-
"pi-better-show": "0.
|
|
74
|
+
"pi-better-show": "0.3.0",
|
|
75
75
|
"pi-mcp-adapter": "5.3.0",
|
|
76
76
|
"pino": "10.4.0",
|
|
77
77
|
"typebox": "1.3.37",
|
|
@@ -55,7 +55,13 @@ export interface TeamTurnsOptions {
|
|
|
55
55
|
*/
|
|
56
56
|
surfaces?: Pick<
|
|
57
57
|
SurfacePort,
|
|
58
|
-
|
|
58
|
+
| "sendReply"
|
|
59
|
+
| "interim"
|
|
60
|
+
| "roomSurfaces"
|
|
61
|
+
| "of"
|
|
62
|
+
| "lang"
|
|
63
|
+
| "progress"
|
|
64
|
+
| "groupRound"
|
|
59
65
|
>;
|
|
60
66
|
studio: Pick<AvatarStudio, "url">;
|
|
61
67
|
/**
|
|
@@ -305,7 +305,11 @@ export class TeamTurns {
|
|
|
305
305
|
|
|
306
306
|
/** What the surface that serves the channel does there (see `supportOf`). */
|
|
307
307
|
#support(channel: ChannelKey) {
|
|
308
|
-
return supportOf(
|
|
308
|
+
return supportOf(
|
|
309
|
+
this.#options.surfaces?.of(channel),
|
|
310
|
+
channel,
|
|
311
|
+
this.#options.surfaces?.lang,
|
|
312
|
+
);
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
/** The messages that carry an agent's text to the channel, cut for the surface that serves it. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlockKind } from "pi-better-show";
|
|
1
|
+
import type { BlockKind, TextLang } from "pi-better-show";
|
|
2
2
|
import type {
|
|
3
3
|
BlockTextFlavor,
|
|
4
4
|
ChannelSupport,
|
|
@@ -140,7 +140,10 @@ export interface ChatSurface {
|
|
|
140
140
|
* The display-block kinds this surface draws itself, such as `table` or `mermaid` (see
|
|
141
141
|
* pi-better-show). A reply reaches `sendReply` whole, with the fences of those kinds intact; a
|
|
142
142
|
* block of any other kind arrives as text, and a surface that lists none gets every block as
|
|
143
|
-
* text. Absent = none.
|
|
143
|
+
* text. Absent = none. Listing an interactive kind (`options`, `suggest`, `form`, `checklist`,
|
|
144
|
+
* `review`) also promises that the surface hands the reader's answer to the agent as a message
|
|
145
|
+
* from them, the way typing it would; a surface that cannot promise that leaves the kind out,
|
|
146
|
+
* and core tells the model it cannot show forms, option buttons or checklists (see `blockNote`).
|
|
144
147
|
*/
|
|
145
148
|
readonly blocks?: readonly BlockKind[];
|
|
146
149
|
/**
|
|
@@ -148,6 +151,17 @@ export interface ChatSurface {
|
|
|
148
151
|
* `diff` fence), `line` (plain text without Markdown markup), or `plain`. Absent = `discord`.
|
|
149
152
|
*/
|
|
150
153
|
readonly blockText?: BlockTextFlavor;
|
|
154
|
+
/**
|
|
155
|
+
* The language a block this surface does not draw asks its reader to answer in, `en` or
|
|
156
|
+
* `zh-TW`. Absent = the host's locale.
|
|
157
|
+
*/
|
|
158
|
+
readonly lang?: TextLang;
|
|
159
|
+
/**
|
|
160
|
+
* `false` = this surface's `formatting` already says what it cannot do with forms, option
|
|
161
|
+
* buttons and checklists, so core adds no line about them. Absent = core adds one to the
|
|
162
|
+
* guidance of a turn when the surface does not draw every interactive kind.
|
|
163
|
+
*/
|
|
164
|
+
readonly blockNote?: false;
|
|
151
165
|
/**
|
|
152
166
|
* What differs in one channel of this surface: its `formatting`, `blocks` or `blockText`
|
|
153
167
|
* replace the surface's for a turn that replies there, such as a host's room on a surface that
|
|
@@ -239,6 +253,8 @@ export interface ChatSurface {
|
|
|
239
253
|
* NotLinkedError, because the surfaces are collected once every plugin is set up.
|
|
240
254
|
*/
|
|
241
255
|
export interface SurfacePort {
|
|
256
|
+
/** The host's locale: the language a block that reads as text asks its reader to answer in. */
|
|
257
|
+
readonly lang?: TextLang;
|
|
242
258
|
/** The surface that serves the channel's prefix; undefined when none does. */
|
|
243
259
|
of(channel: ChannelKey): ChatSurface | undefined;
|
|
244
260
|
/** Throws PluginError naming the prefix when no surface serves it. */
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
type BlockKind,
|
|
3
|
+
INTERACTIVE_KINDS,
|
|
4
|
+
type TextLang,
|
|
5
|
+
} from "pi-better-show";
|
|
2
6
|
|
|
3
7
|
/** How a block that a surface does not draw reads as text. */
|
|
4
8
|
export type BlockTextFlavor = "discord" | "line" | "plain";
|
|
@@ -9,6 +13,17 @@ export interface BlockSupport {
|
|
|
9
13
|
readonly blocks?: readonly BlockKind[];
|
|
10
14
|
/** The flavor of text for the other kinds; absent = `discord`. */
|
|
11
15
|
readonly blockText?: BlockTextFlavor;
|
|
16
|
+
/**
|
|
17
|
+
* The language a block that reads as text asks its reader to answer in: `en` or `zh-TW`.
|
|
18
|
+
* Absent = the host's, and without one `en`.
|
|
19
|
+
*/
|
|
20
|
+
readonly lang?: TextLang;
|
|
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.
|
|
25
|
+
*/
|
|
26
|
+
readonly blockNote?: false;
|
|
12
27
|
}
|
|
13
28
|
|
|
14
29
|
/** What a surface says about one channel where it differs from the surface's own; a field that is absent changes nothing. */
|
|
@@ -19,7 +34,10 @@ export interface ChannelSupport extends BlockSupport {
|
|
|
19
34
|
|
|
20
35
|
/**
|
|
21
36
|
* What a surface does in `channel`: its own `formatting`, `blocks` and `blockText`, over which the
|
|
22
|
-
* channel's `support` lays what differs (a host's room on an app, which draws no blocks).
|
|
37
|
+
* channel's `support` lays what differs (a host's room on an app, which draws no blocks). A
|
|
38
|
+
* surface that does not draw every interactive kind (`options`, `suggest`, `form`, `checklist`,
|
|
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.
|
|
23
41
|
*/
|
|
24
42
|
export function supportOf(
|
|
25
43
|
surface:
|
|
@@ -28,6 +46,7 @@ export function supportOf(
|
|
|
28
46
|
})
|
|
29
47
|
| undefined,
|
|
30
48
|
channel: string,
|
|
49
|
+
lang?: TextLang,
|
|
31
50
|
): ChannelSupport {
|
|
32
51
|
if (!surface) return {};
|
|
33
52
|
const own = {
|
|
@@ -36,6 +55,34 @@ export function supportOf(
|
|
|
36
55
|
: { formatting: surface.formatting }),
|
|
37
56
|
...(surface.blocks ? { blocks: surface.blocks } : {}),
|
|
38
57
|
...(surface.blockText ? { blockText: surface.blockText } : {}),
|
|
58
|
+
...(surface.lang ? { lang: surface.lang } : {}),
|
|
59
|
+
...(surface.blockNote === false ? { blockNote: false as const } : {}),
|
|
39
60
|
};
|
|
40
|
-
|
|
61
|
+
const merged: ChannelSupport = { ...own, ...surface.support?.(channel) };
|
|
62
|
+
const note =
|
|
63
|
+
merged.blockNote === false ? undefined : interactiveNote(merged.blocks);
|
|
64
|
+
const language = merged.lang ?? lang;
|
|
65
|
+
return {
|
|
66
|
+
...merged,
|
|
67
|
+
...(note === undefined
|
|
68
|
+
? {}
|
|
69
|
+
: { formatting: [merged.formatting, note].filter(Boolean).join(" ") }),
|
|
70
|
+
...(language === undefined ? {} : { lang: language }),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 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.
|
|
77
|
+
*/
|
|
78
|
+
function interactiveNote(
|
|
79
|
+
blocks: readonly BlockKind[] | undefined,
|
|
80
|
+
): string | undefined {
|
|
81
|
+
const missing = INTERACTIVE_KINDS.filter((kind) => !blocks?.includes(kind));
|
|
82
|
+
if (missing.length === 0) return undefined;
|
|
83
|
+
const cannot =
|
|
84
|
+
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.`;
|
|
41
88
|
}
|
|
@@ -311,7 +311,10 @@ export class Linkage {
|
|
|
311
311
|
);
|
|
312
312
|
return this.registry.surfaces;
|
|
313
313
|
},
|
|
314
|
-
{
|
|
314
|
+
{
|
|
315
|
+
deprecated: (message) => this.#deprecated(message),
|
|
316
|
+
lang: this.#options.environment?.locale ?? "en",
|
|
317
|
+
},
|
|
315
318
|
);
|
|
316
319
|
}
|
|
317
320
|
|
|
@@ -50,7 +50,8 @@ export interface DeliveryRouter {
|
|
|
50
50
|
|
|
51
51
|
export function deliveryRouter(
|
|
52
52
|
providers: () => readonly DirectChannelProvider[],
|
|
53
|
-
surfaces: Pick<SurfacePort, "sendReply"> &
|
|
53
|
+
surfaces: Pick<SurfacePort, "sendReply"> &
|
|
54
|
+
Partial<Pick<SurfacePort, "of" | "lang">>,
|
|
54
55
|
logger?: Pick<Logger, "warn">,
|
|
55
56
|
): DeliveryRouter {
|
|
56
57
|
const order = (origin: Origin): readonly DirectChannelProvider[] => {
|
|
@@ -127,7 +128,11 @@ export function deliveryRouter(
|
|
|
127
128
|
await surfaces.sendReply(reached.channel, {
|
|
128
129
|
// The text of a notice may be an agent's (the notify tool's), block fences included.
|
|
129
130
|
chunks: chunksFor(
|
|
130
|
-
supportOf(
|
|
131
|
+
supportOf(
|
|
132
|
+
surfaces.of?.(reached.channel),
|
|
133
|
+
reached.channel,
|
|
134
|
+
surfaces.lang,
|
|
135
|
+
),
|
|
131
136
|
text,
|
|
132
137
|
),
|
|
133
138
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BlockKind, parse, toText } from "pi-better-show";
|
|
1
|
+
import { type BlockKind, parse, type TextLang, toText } from "pi-better-show";
|
|
2
2
|
import type { BlockSupport, BlockTextFlavor } from "../domain/block-support.ts";
|
|
3
3
|
import { diagramDrawer } from "./diagram-text.ts";
|
|
4
4
|
import { splitReply } from "./reply-splitter.ts";
|
|
@@ -29,18 +29,29 @@ export function textFor(
|
|
|
29
29
|
surface: BlockSupport | undefined,
|
|
30
30
|
text: string,
|
|
31
31
|
): string {
|
|
32
|
-
return convert(
|
|
32
|
+
return convert(
|
|
33
|
+
text,
|
|
34
|
+
surface?.blocks ?? [],
|
|
35
|
+
surface?.blockText ?? "discord",
|
|
36
|
+
surface?.lang,
|
|
37
|
+
);
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
function convert(
|
|
36
41
|
text: string,
|
|
37
42
|
draws: readonly BlockKind[],
|
|
38
43
|
flavor: BlockTextFlavor,
|
|
44
|
+
lang: TextLang | undefined,
|
|
39
45
|
): string {
|
|
40
46
|
const segments = parse(text);
|
|
41
47
|
const blocks = segments.filter((segment) => segment.type !== "markdown");
|
|
42
48
|
// Toward a surface that draws all of them the text is already right, and rejoining the
|
|
43
49
|
// segments would only change its spacing.
|
|
44
50
|
if (blocks.every((block) => draws.includes(block.kind))) return text;
|
|
45
|
-
return toText(segments, {
|
|
51
|
+
return toText(segments, {
|
|
52
|
+
flavor,
|
|
53
|
+
mermaid: diagramDrawer(),
|
|
54
|
+
keep: draws,
|
|
55
|
+
...(lang ? { lang } : {}),
|
|
56
|
+
});
|
|
46
57
|
}
|
|
@@ -251,7 +251,10 @@ export function conversationTurns(
|
|
|
251
251
|
else
|
|
252
252
|
await surfaces.sendReply(
|
|
253
253
|
channel,
|
|
254
|
-
replyBody(
|
|
254
|
+
replyBody(
|
|
255
|
+
result,
|
|
256
|
+
supportOf(surfaces.of(channel), channel, surfaces.lang),
|
|
257
|
+
),
|
|
255
258
|
);
|
|
256
259
|
} catch (error) {
|
|
257
260
|
logger.error({ channel, kind, err: error }, "reply not posted");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TextLang } from "pi-better-show";
|
|
1
2
|
import type { ChatSurface, SurfacePort } from "../contract/surface.ts";
|
|
2
3
|
import { parseChannelKey } from "../contract/surface.ts";
|
|
3
4
|
import { supportOf } from "../domain/block-support.ts";
|
|
@@ -13,6 +14,8 @@ import { PluginError } from "../kernel/errors.ts";
|
|
|
13
14
|
export interface SurfacePortOptions {
|
|
14
15
|
/** Told when a caller uses a form that goes away, such as `prompts(channel, speaker)`. */
|
|
15
16
|
deprecated?(message: string): void;
|
|
17
|
+
/** The host's locale, the language a block that reads as text asks its reader to answer in. */
|
|
18
|
+
lang?: TextLang;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -38,6 +41,7 @@ export function surfacePort(
|
|
|
38
41
|
return surface;
|
|
39
42
|
};
|
|
40
43
|
return {
|
|
44
|
+
...(options.lang ? { lang: options.lang } : {}),
|
|
41
45
|
of,
|
|
42
46
|
sendReply: async (channel, reply) => {
|
|
43
47
|
const surface = served(channel);
|
|
@@ -67,11 +71,16 @@ export function surfacePort(
|
|
|
67
71
|
const posts = surface?.interim?.(channel, as);
|
|
68
72
|
if (!surface || !posts) return posts;
|
|
69
73
|
// The poster cuts text for the surface it posts on, which only the port knows.
|
|
70
|
-
const { blocks, blockText } = supportOf(
|
|
74
|
+
const { blocks, blockText, lang } = supportOf(
|
|
75
|
+
surface,
|
|
76
|
+
channel,
|
|
77
|
+
options.lang,
|
|
78
|
+
);
|
|
71
79
|
return {
|
|
72
80
|
...(posts.tools === undefined ? {} : { tools: posts.tools }),
|
|
73
81
|
...(blocks ? { blocks } : {}),
|
|
74
82
|
...(blockText ? { blockText } : {}),
|
|
83
|
+
...(lang ? { lang } : {}),
|
|
75
84
|
post: (text) => posts.post(text),
|
|
76
85
|
};
|
|
77
86
|
},
|
|
@@ -8,7 +8,12 @@ import {
|
|
|
8
8
|
until,
|
|
9
9
|
} from "./surface-contract-support.ts";
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The contract of a surface that lists `ChatSurface.blocks`: what it says it draws arrives whole.
|
|
13
|
+
* A surface that lists an interactive kind (`options`, `suggest`, `form`, `checklist`, `review`)
|
|
14
|
+
* also promises that the reader's answer reaches the agent as a message from them, sent the way
|
|
15
|
+
* typing it would be: the contract cannot drive a reader's click, so a surface's own tests show it.
|
|
16
|
+
*/
|
|
12
17
|
export const BLOCK_CHECKS: readonly {
|
|
13
18
|
name: string;
|
|
14
19
|
applies(subject: SurfaceContractSubject): boolean;
|
|
@@ -78,7 +78,7 @@ export interface DispatchThreadsOptions {
|
|
|
78
78
|
* the surface that serves the channel's prefix; a channel whose surface has none gets no thread.
|
|
79
79
|
* Give this or `host`, not both.
|
|
80
80
|
*/
|
|
81
|
-
surfaces?: Pick<SurfacePort, "of">;
|
|
81
|
+
surfaces?: Pick<SurfacePort, "of" | "lang">;
|
|
82
82
|
/**
|
|
83
83
|
* Discord's thread host, for the `discord:` channels only.
|
|
84
84
|
*
|
|
@@ -248,9 +248,10 @@ export class DispatchThreads {
|
|
|
248
248
|
const { id } = parseChannelKey(channel);
|
|
249
249
|
let closed = false;
|
|
250
250
|
const send = threads.send?.bind(threads);
|
|
251
|
-
const { blocks, blockText } = supportOf(
|
|
251
|
+
const { blocks, blockText, lang } = supportOf(
|
|
252
252
|
this.#options.surfaces?.of(channel),
|
|
253
253
|
channel,
|
|
254
|
+
this.#options.surfaces?.lang,
|
|
254
255
|
);
|
|
255
256
|
const post = async (text: string) => {
|
|
256
257
|
try {
|
|
@@ -273,6 +274,7 @@ export class DispatchThreads {
|
|
|
273
274
|
// The poster cuts text for the surface the thread is on.
|
|
274
275
|
...(blocks ? { blocks } : {}),
|
|
275
276
|
...(blockText ? { blockText } : {}),
|
|
277
|
+
...(lang ? { lang } : {}),
|
|
276
278
|
post: (text: string) => send(id, text),
|
|
277
279
|
},
|
|
278
280
|
}
|