pi-roundtable 0.53.5 → 0.53.6
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 +7 -0
- package/README.md +8 -0
- package/README.zh-TW.md +8 -0
- package/docs/plugins.md +2 -1
- package/package.json +1 -1
- package/src/core/attachments/attachment-expiry.ts +12 -0
- package/src/core/attachments/attachment-store.ts +20 -5
- package/src/core/attachments/model-images.ts +3 -2
- package/src/core/contract/attachments.ts +2 -0
- package/src/core/domain/client.ts +6 -2
- package/src/core/shared/attachment-reader.ts +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.53.6] - 2026-11-29
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Plugins can limit the uploaded images the model sees with `TurnAttachmentOptions.modelImages` or web chat's `limits.modelImagesPerMessage` (0–4, default 4). At zero, the prompt still lists the files and tools can read them; `read_attachment` on such an image says it was not shown to the model and points to a document reader.
|
|
13
|
+
- Web chat advertises `limits.clientCalls.maxArgsBytes` in `ready.clientCalls` and exports `DEFAULT_MAX_ARGS_BYTES` (16 KiB). Tools can read the dispatched browser call's id from `ClientCallResult.callId` on success or failure.
|
|
14
|
+
|
|
8
15
|
## [0.53.5] - 2026-11-24
|
|
9
16
|
|
|
10
17
|
### Changed
|
package/README.md
CHANGED
|
@@ -134,6 +134,10 @@ A plugin can also listen without owning a channel: `context.observe` hears guild
|
|
|
134
134
|
It is the entry that names discord.js types (`pi-roundtable/testing` names a few, through `testHost`'s composed commands).
|
|
135
135
|
Both follow the main entry's versioning: before 1.0, breaking changes come in minor releases and are listed in the changelog.
|
|
136
136
|
|
|
137
|
+
A plugin that handles uploaded images itself can call `context.attachments.turnAttachments(channel, principalId, files, { modelImages: 0 })`.
|
|
138
|
+
The prompt still lists the files and tools can read them with `turn.attachment(file)`, but the model receives no image parts from those uploads.
|
|
139
|
+
`TurnAttachmentOptions.modelImages` accepts integers from 0 to 4; the default is 4.
|
|
140
|
+
|
|
137
141
|
## Web chat
|
|
138
142
|
|
|
139
143
|
The package [pi-roundtable-webchat](packages/webchat) is a chat network that comes as a plugin: a WebSocket and a REST API under `/chat` on the host's listener.
|
|
@@ -146,6 +150,10 @@ npx pi-roundtable init my-desk --adapter web
|
|
|
146
150
|
|
|
147
151
|
Its README describes the protocol, core access rules, the private notice inbox, the limits, and the [provider settings](packages/webchat/README.md#provider-settings) that keep one person one identity, such as a stable subject claim and a pinned tenant.
|
|
148
152
|
|
|
153
|
+
Web chat exposes the same image limit as `limits.modelImagesPerMessage`.
|
|
154
|
+
For browser calls, `limits.clientCalls.maxArgsBytes` bounds the UTF-8 JSON arguments (default 16 KiB); the client receives the limit in `ready.clientCalls.maxArgsBytes`.
|
|
155
|
+
A tool can record `result.callId` from `turn.client.call(...)` to match its audit entry to the browser's call.
|
|
156
|
+
|
|
149
157
|
## MCP connectors
|
|
150
158
|
|
|
151
159
|
The separate package [pi-roundtable-mcp](https://www.npmjs.com/package/pi-roundtable-mcp) connects the bot to the MCP ecosystem in both directions, with two plugins:
|
package/README.zh-TW.md
CHANGED
|
@@ -129,6 +129,10 @@ test("hello greets", async () => {
|
|
|
129
129
|
`pi-roundtable/discord` 提供斜線指令註冊器、擁有者指令與面板的輔助函式,以及智慧體面板;它是會用到 discord.js 型別的入口(`pi-roundtable/testing` 也透過 `testHost` 組合出的指令用到少數幾個)。
|
|
130
130
|
這兩個入口的版本規則與主入口相同:1.0 之前,不相容的變更會放在次版本(minor)發佈,並列在變更記錄中。
|
|
131
131
|
|
|
132
|
+
外掛如果要自己處理上傳的圖片,可以在呼叫 `context.attachments.turnAttachments` 時將第四個參數設為 `{ modelImages: 0 }`。
|
|
133
|
+
提示詞仍會列出檔案,工具也能用 `turn.attachment(file)` 讀取內容,但對話模型不會收到這些附件的影像。
|
|
134
|
+
`TurnAttachmentOptions.modelImages` 接受 0 到 4 的整數,預設為 4。
|
|
135
|
+
|
|
132
136
|
## 網頁聊天
|
|
133
137
|
|
|
134
138
|
套件 [pi-roundtable-webchat](packages/webchat) 是以外掛形式提供的聊天管道:在主機的 listener 上的 `/chat` 底下提供 WebSocket 和 REST API。
|
|
@@ -141,6 +145,10 @@ npx pi-roundtable init my-desk --adapter web
|
|
|
141
145
|
|
|
142
146
|
它的 README(英文)說明協定、存取對照、各項上限,以及讓同一個人只有一個身分的[供應商設定](packages/webchat/README.md#provider-settings),例如使用穩定的 subject claim、固定租戶。
|
|
143
147
|
|
|
148
|
+
網頁聊天用 `limits.modelImagesPerMessage` 設定每則訊息送給模型的圖片張數。
|
|
149
|
+
`limits.clientCalls.maxArgsBytes` 限制傳給瀏覽器的呼叫參數大小,以 UTF-8 編碼的 JSON 計算,預設為 16 KiB;瀏覽器從 `ready.clientCalls.maxArgsBytes` 取得上限。
|
|
150
|
+
工具可將 `turn.client.call(...)` 回傳的 `result.callId` 寫入稽核紀錄,用來比對瀏覽器收到的呼叫。
|
|
151
|
+
|
|
144
152
|
## MCP connector
|
|
145
153
|
|
|
146
154
|
獨立套件 [pi-roundtable-mcp](https://www.npmjs.com/package/pi-roundtable-mcp) 用兩個外掛,把 bot 雙向接上 MCP:
|
package/docs/plugins.md
CHANGED
|
@@ -729,7 +729,7 @@ A plugin whose clients upload a file themselves, over HTTP for instance, has the
|
|
|
729
729
|
| Call | What it does |
|
|
730
730
|
|---|---|
|
|
731
731
|
| `save(channel, principalId, { name, contentType, data })` | Keeps the file for that principal in that conversation and returns a `StoredAttachment`; its `file` is the name to hand back to the client. Refuses a file over 25 MiB (`too_large`) |
|
|
732
|
-
| `turnAttachments(channel, principalId, files, options?)` | Takes the `file` names `save` returned and returns the turn's `TurnAttachments`; pass it as `attachments` to [`turns.run`](#personas-and-contextturns-conversations-of-a-kind-of-your-own). Each file moves into the conversation's attachment directory,
|
|
732
|
+
| `turnAttachments(channel, principalId, files, options?)` | Takes the `file` names `save` returned and returns the turn's `TurnAttachments`; pass it as `attachments` to [`turns.run`](#personas-and-contextturns-conversations-of-a-kind-of-your-own). Each file moves into the conversation's attachment directory, `options.modelImages` limits how many images are prepared for the model (0–4, default 4; 0 skips decoding but leaves the bytes available to tools), and the turn's prompt lists every file under `## Attachments`. Refuses the whole set when one name is unknown or already used (`unknown_file`), or when `options.usedBytesLimit` would be passed (`quota_exceeded`); then none moves, even when other calls for the same principal run at once |
|
|
733
733
|
| `remove(channel, principalId, file)` | Discards a saved file no turn used; `false` when there is none |
|
|
734
734
|
| `discardPending(olderThan)` | Discards every saved file no turn used that was saved before the date, and returns how many; call it from a service's timer so abandoned uploads do not pile up |
|
|
735
735
|
| `pendingBytes(principalId)` | The bytes the principal has saved that no turn used yet, for a quota of your own |
|
|
@@ -795,6 +795,7 @@ Some transports carry a client that can do something for a tool: the web chat's
|
|
|
795
795
|
`turn.client` is that client's `ClientPort` when the turn's transport provides one and the client declared it, and undefined otherwise (a Discord message, a schedule, an agent's turn, and a web chat connection that declared nothing have none), so a tool that needs it fails closed with a `ToolRefusal` when it is undefined.
|
|
796
796
|
`client.names` lists the functions the client declared, and `client.call(name, args, { timeoutMs?, maxValueBytes?, signal?, approval? })` asks it to run one. `approval: { prompt }` names the approval the call acts on, normally `{ prompt: turn.approvedPrompt }` for a tool whose hold the person approved: the transport hands it to the client beside the call (the web chat as `client_call.approval`, see its README), so a client can check that the person approved this very card before it acts. A call without `approval` carries no such field; the core does not judge it, the client does.
|
|
797
797
|
The call never rejects for a transport problem: it resolves `{ ok: true, value, parts }`, with the value the client answered with and its binary `parts` (`{ mimeType, data }`, such as a screenshot), or `{ ok: false, error, message }` where `error` is `no_client`, `refused`, `timeout`, `cancelled`, `disconnected`, `too_large`, `busy`, or `failed`.
|
|
798
|
+
When a transport supplies `result.callId`, it identifies the dispatched call even if the client disconnected or the call timed out; a call refused before dispatch has no id.
|
|
798
799
|
One call is open on a client at a time: a second one made meanwhile resolves `busy`, so make calls one after another.
|
|
799
800
|
The core gives every call the turn's `signal`, so stopping the turn cancels the call in flight (`cancelled`) and the tool need not handle it.
|
|
800
801
|
The value and the parts come from the client, outside the host, so a tool treats them as untrusted data: it checks their shape, and passes images on as `ToolOutput` images rather than trusting their names or types.
|
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ import { shrinkTally } from "./attachment-tally.ts";
|
|
|
9
9
|
export interface UsedRecord {
|
|
10
10
|
name: string;
|
|
11
11
|
contentType: string;
|
|
12
|
+
/** This upload was an image claimed with modelImages: 0. Older records omit the flag. */
|
|
13
|
+
modelImageHidden?: true;
|
|
12
14
|
/** The owner's directory segment (a hash, never the id), when the core recorded it. */
|
|
13
15
|
principal?: string;
|
|
14
16
|
/** When the turn took the file, in epoch milliseconds. */
|
|
@@ -48,6 +50,16 @@ const isUsedRecord = (value: unknown): value is UsedRecord =>
|
|
|
48
50
|
!isExpiredMark(value) &&
|
|
49
51
|
typeof (value as UsedRecord).name === "string";
|
|
50
52
|
|
|
53
|
+
/** Whether this file's upload was kept for tools but not shown as a model image. */
|
|
54
|
+
export async function wasModelImageHidden(
|
|
55
|
+
dir: string,
|
|
56
|
+
file: string,
|
|
57
|
+
): Promise<boolean> {
|
|
58
|
+
if (!isAttachmentName(file)) return false;
|
|
59
|
+
const record = await readRecord(recordPath(dir, file));
|
|
60
|
+
return isUsedRecord(record) && record.modelImageHidden === true;
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
/** Whether the file's retention period ended and the core removed it. */
|
|
52
64
|
export async function wasExpired(dir: string, file: string): Promise<boolean> {
|
|
53
65
|
if (!isAttachmentName(file)) return false;
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
type TurnAttachmentOptions,
|
|
11
11
|
} from "../contract/attachments.ts";
|
|
12
12
|
import type { ConversationRegistry } from "../conversations/conversation-registry.ts";
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import {
|
|
14
|
+
MAX_TURN_IMAGES,
|
|
15
|
+
type StoredAttachment,
|
|
16
|
+
type TurnAttachments,
|
|
16
17
|
} from "../domain/attachment.ts";
|
|
17
18
|
import type { ChannelKey } from "../domain/sessions.ts";
|
|
18
19
|
import type { Logger } from "../kernel/log.ts";
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
} from "./attachment-dir.ts";
|
|
28
29
|
import { expireUsedFiles, type UsedRecord } from "./attachment-expiry.ts";
|
|
29
30
|
import { MAX_ATTACHMENT_BYTES, safeFileName } from "./attachment-fetcher.ts";
|
|
30
|
-
import { isAttachmentName } from "./attachment-name.ts";
|
|
31
|
+
import { isAttachmentName, plainContentType } from "./attachment-name.ts";
|
|
31
32
|
import { principalSegment, readTally, writeTally } from "./attachment-tally.ts";
|
|
32
33
|
import { modelImagesOf } from "./model-images.ts";
|
|
33
34
|
|
|
@@ -155,13 +156,23 @@ export class AttachmentStore implements AttachmentPort {
|
|
|
155
156
|
files: readonly string[],
|
|
156
157
|
options: TurnAttachmentOptions = {},
|
|
157
158
|
): Promise<TurnAttachments> {
|
|
159
|
+
const { modelImages = MAX_TURN_IMAGES } = options;
|
|
160
|
+
if (
|
|
161
|
+
!Number.isInteger(modelImages) ||
|
|
162
|
+
modelImages < 0 ||
|
|
163
|
+
modelImages > MAX_TURN_IMAGES
|
|
164
|
+
)
|
|
165
|
+
throw new RangeError(
|
|
166
|
+
`modelImages must be an integer from 0 to ${MAX_TURN_IMAGES}`,
|
|
167
|
+
);
|
|
158
168
|
await this.#admit(channel, principalId);
|
|
159
169
|
const found = await this.#exclusive(principalSegment(principalId), () =>
|
|
160
|
-
this.#claim(channel, principalId, files, options),
|
|
170
|
+
this.#claim(channel, principalId, files, { ...options, modelImages }),
|
|
161
171
|
);
|
|
162
172
|
const { images, failures } = await modelImagesOf(
|
|
163
173
|
found,
|
|
164
174
|
this.#options.logger,
|
|
175
|
+
modelImages,
|
|
165
176
|
);
|
|
166
177
|
return { files: found, images, failures };
|
|
167
178
|
}
|
|
@@ -218,6 +229,10 @@ export class AttachmentStore implements AttachmentPort {
|
|
|
218
229
|
const used: UsedRecord = {
|
|
219
230
|
name: stored.name,
|
|
220
231
|
contentType: stored.contentType,
|
|
232
|
+
...(options.modelImages === 0 &&
|
|
233
|
+
plainContentType(stored.contentType).startsWith("image/")
|
|
234
|
+
? ({ modelImageHidden: true } as const)
|
|
235
|
+
: {}),
|
|
221
236
|
principal: principalSegment(principalId),
|
|
222
237
|
usedAt: (this.#options.now ?? Date.now)(),
|
|
223
238
|
size: stored.size,
|
|
@@ -11,16 +11,17 @@ import {
|
|
|
11
11
|
} from "./image-prep.ts";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* The first
|
|
14
|
+
* The first `limit` images among the files, prepared as the model accepts them. An image that cannot
|
|
15
15
|
* be decoded is reported as a failure and the turn goes on without it.
|
|
16
16
|
*/
|
|
17
17
|
export async function modelImagesOf(
|
|
18
18
|
files: readonly StoredAttachment[],
|
|
19
19
|
logger: Logger,
|
|
20
|
+
limit = MAX_IMAGES_PER_TURN,
|
|
20
21
|
): Promise<{ images: ModelImage[]; failures: AttachmentFailure[] }> {
|
|
21
22
|
const images: ModelImage[] = [];
|
|
22
23
|
const failures: AttachmentFailure[] = [];
|
|
23
|
-
for (const file of files.filter(isModelImage).slice(0,
|
|
24
|
+
for (const file of files.filter(isModelImage).slice(0, limit)) {
|
|
24
25
|
try {
|
|
25
26
|
images.push(await prepareImage(file));
|
|
26
27
|
} catch (error) {
|
|
@@ -36,6 +36,8 @@ export class AttachmentRefusal extends Error {
|
|
|
36
36
|
|
|
37
37
|
/** What a plugin asks of `turnAttachments` besides the files. */
|
|
38
38
|
export interface TurnAttachmentOptions {
|
|
39
|
+
/** Number of images to prepare for the model (0–4; default 4). Every file is still listed and readable. */
|
|
40
|
+
modelImages?: number;
|
|
39
41
|
/**
|
|
40
42
|
* The most bytes the principal may have used in turns across all their conversations, these
|
|
41
43
|
* files included. A call that would pass it is refused with `quota_exceeded` and moves nothing.
|
|
@@ -24,9 +24,13 @@ export type ClientCallError =
|
|
|
24
24
|
| "failed";
|
|
25
25
|
|
|
26
26
|
/** What a client call comes to: the value the client answered with and its binary parts, or why not. */
|
|
27
|
-
export type ClientCallResult =
|
|
27
|
+
export type ClientCallResult = (
|
|
28
28
|
| { ok: true; value: unknown; parts: readonly ClientPart[] }
|
|
29
|
-
| { ok: false; error: ClientCallError; message: string }
|
|
29
|
+
| { ok: false; error: ClientCallError; message: string }
|
|
30
|
+
) & {
|
|
31
|
+
/** Transport id of the dispatched call, if available. Absent when the call was never sent. */
|
|
32
|
+
readonly callId?: string;
|
|
33
|
+
};
|
|
30
34
|
|
|
31
35
|
/** How one client call is bounded. */
|
|
32
36
|
export interface ClientCallOptions {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
wasExpired,
|
|
4
|
+
wasModelImageHidden,
|
|
5
|
+
} from "../attachments/attachment-expiry.ts";
|
|
3
6
|
import { MAX_ATTACHMENT_BYTES } from "../attachments/attachment-fetcher.ts";
|
|
4
7
|
import { isAttachmentName, plainText } from "../attachments/attachment-name.ts";
|
|
5
8
|
import { AttachmentExpiredError } from "../attachments/tool-attachment.ts";
|
|
6
9
|
import {
|
|
7
10
|
ATTACHMENT_TEXT_LIMIT,
|
|
11
|
+
AttachmentTextError,
|
|
8
12
|
readAttachmentText,
|
|
9
13
|
} from "./attachment-text.ts";
|
|
10
14
|
|
|
@@ -36,6 +40,11 @@ export async function readAttachment(
|
|
|
36
40
|
throw new AttachmentExpiredError(plainText(file));
|
|
37
41
|
throw new Error(`no attachment named "${file}" in this channel`);
|
|
38
42
|
}
|
|
43
|
+
if (await wasModelImageHidden(dir, file))
|
|
44
|
+
throw new AttachmentTextError(
|
|
45
|
+
"unsupported",
|
|
46
|
+
`"${plainText(file)}": This image is not shown to you; use a document tool that reads image files.`,
|
|
47
|
+
);
|
|
39
48
|
// A file a surface took past the default limit is for tools that take files, not for reading whole.
|
|
40
49
|
if (handle.size > MAX_ATTACHMENT_BYTES)
|
|
41
50
|
throw new Error(
|