pi-roundtable 0.38.1 → 0.39.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 +11 -0
- package/docs/plugins.md +6 -0
- package/package.json +1 -1
- package/src/core/agents/agent-team.ts +2 -0
- package/src/core/agents/agent-tools.ts +41 -22
- package/src/core/agents/room-tools.ts +80 -0
- package/src/core/agents/team-options.ts +3 -0
- package/src/core/agents/team-rooms.ts +125 -0
- package/src/core/builtin/agent-server.ts +2 -0
- package/src/core/contract/room-layout.ts +33 -0
- package/src/core/tool-set.snapshot.json +5 -0
- package/src/index.ts +5 -0
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.39.1] - 2026-11-08
|
|
9
|
+
|
|
10
|
+
- 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.
|
|
11
|
+
|
|
12
|
+
## [0.39.0] - 2026-11-08
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- Agent tools place agents and groups in the web app's room groups. `agent_create` and `group_create` take `group`, the app group the new room goes into (made when missing); `category` stays Discord's alone, and a room without `group` stays ungrouped. `agent_list` ends with the app's groups, each with its rooms in order, and the pinned rooms. `room_arrange { groups: [{ group, names }] }` sorts rooms into the app's groups and orders them, with `channel_arrange`'s contract: the listed groups and rooms first, the rest where they were, and any wrong entry refuses the whole call. A host without the app's room list refuses `group` and `room_arrange`.
|
|
17
|
+
- `ROOM_LAYOUT`, `RoomLayoutService` and `RoomGroupsView`: the service of an app's room groups by agent and group names (`view`, `place`, `arrange`); pi-roundtable-web provides it.
|
|
18
|
+
|
|
8
19
|
## [0.38.1] - 2026-11-08
|
|
9
20
|
|
|
10
21
|
### Fixed
|
package/docs/plugins.md
CHANGED
|
@@ -271,6 +271,7 @@ The built-in plugins provide these, from the main entry:
|
|
|
271
271
|
| `DELEGATION` | `Delegator` | `modules` | `start(request)` a background task, `runningChannels()`, `idle()` |
|
|
272
272
|
| `THREADS` | `DispatchThreads` | `threads` | The threads of background dispatches (coding tasks, delegated tasks), on any surface that hosts them: `open(origin, title, intro?)` opens the thread under the channel `origin` through the `threads` of the surface that serves its prefix and resolves to a `DispatchThread`, or `undefined` when that surface hosts none or the channel cannot. See [Dispatch threads on any surface](#dispatch-threads-on-any-surface) |
|
|
273
273
|
| `CHANNEL_CONTEXT` | `ChannelContexts` | `channel-context` | `read(message, options?)` gives the context of one addressed message, from the surface whose key prefix its channel carries: the messages posted there since the assistant last posted, or `undefined` for a surface without `channelContext`, a channel that is not shared, and when nothing new was said. See [Channel context](#channel-context-what-was-said-around-an-addressed-message) |
|
|
274
|
+
| `ROOM_LAYOUT` | `RoomLayoutService` | `web-console` (pi-roundtable-web, with its rooms pane) | The groups of the app's room list by agent and group names: `view()` (the groups in order with their active rooms, and the pinned rooms), `place(name, group)` (into a group, last, made when missing; `null` for none), `arrange(entries)` (the listed groups and rooms first in order, the rest where they were). A change runs under the layout's lock, a wrong name refuses it whole, and every open page updates. The agent tools' `group` and `room_arrange` read it; absent on a host without the app, read it with `find` |
|
|
274
275
|
| `WORKER_SESSIONS` | `WorkerSessions` | `worker-sessions` | Fresh Pi sessions for a plugin's own workers, on the host's model login: `delegation` is the host's delegation `model` and `thinking`, and `run({ task, signal, prompt, extensions, toolNames, model?, thinking?, aborted? })` runs the task in a session that has only the tools `extensions` register and `toolNames` names (no built-in tool, skill, context file, memory or agent tool) and returns the worker's final answer; see [Workers of your own](#workers-of-your-own) |
|
|
275
276
|
|
|
276
277
|
The data types the ports use (`Schedule`, `NewSchedule`, `Agent`, `AgentGroup`, `TeamStatus`, `Memory`, `SkillSet`, `DelegationJob`, and so on) are in the main entry too.
|
|
@@ -3664,6 +3665,7 @@ A host that keeps Discord may write it as an adapter instead, as [`adapters`](#a
|
|
|
3664
3665
|
- The team's id is `LOCAL_TEAM_ID`, `"local"`, where Discord's is the guild's id; the rows are stored under it as under the guild's, and `AGENTS.team.guildId` is it.
|
|
3665
3666
|
- The start fails, naming the fix ("agents need a surface that hosts their rooms, such as pi-roundtable-web"), when no installed surface declares `agentRooms`: without Discord channels the agents could never be spoken to. The check runs when the plugins are linked, so a surface added by any plugin counts.
|
|
3666
3667
|
- No channel is made, checked or arranged, and the dashboard (a Discord message) does not exist. `channel_arrange` and `channel_read` answer that the host has no Discord channels. `agent_create` and `group_create` make no channel, and a new agent starts its opening task in its room on the first surface that hosts rooms. Archiving an agent or group stops its rooms from answering.
|
|
3668
|
+
- `category` on `agent_create` and `group_create` places a Discord channel only. Their `group` places the new room in a group of the app's room list through `ROOM_LAYOUT`, made when missing; without `group` the room stays ungrouped. `agent_list` ends with the app's groups and pinned rooms, and `room_arrange { groups: [{ group, names }] }` sorts rooms into groups the way `channel_arrange` sorts channels into categories, an owner's tool like it. On a host without the app's room list, `group` and `room_arrange` are refused before anything is made.
|
|
3667
3669
|
- An agent's pictures have no public address unless `http.publicUrl` is set: `AGENTS.avatars.url(hash)` is then the path `/avatars/<hash>.png`, which the surface serves itself through `AGENTS.avatars.serve(pathname)` under its own origin, as the web console does. With `http.publicUrl` they are served on the `public` listener as with Discord.
|
|
3668
3670
|
- `AgentTeam.channelOf(name, near?)` answers with the agent's room on the surface of `near` (the asker's own conversation) when that surface hosts rooms, so `schedule_list` from a room reads the room's schedules; for an agent with no Discord channel it falls back to its room on the first surface that hosts rooms. The status the dashboard and the web read counts an agent's schedules, waiting turns and context use across its Discord channel and its rooms.
|
|
3669
3671
|
- A surface that lets the owner edit the team uses the same operations the agent tools do, from outside any agent turn: `AgentTeam.createAgent(speaker, input)` (the fields of `agent_create`, plus `model` and `thinking`, which are checked before anything is made; without a `task` the agent only exists, and `openIn` names the surface whose room runs the opening task instead of the Discord channel), `archive(undefined, name)` (an owner has no calling agent, so only the coordinator is protected), `restore(name)`, `remove(name, cleanup?)` (an archived agent or group only, and never an agent the host's seeds name, which the next start would seed again; it runs `cleanup`, your surface's part of the delete, after its checks and before deleting anything, so a cleanup that throws leaves the target in place to try again; then it frees the name, detaches the agent's skills, clears its group cursors and makes the runtime forget the conversations the name kept, and leaves a Discord channel under Archive), and `createGroup` and `updateGroup`. All of them throw `AgentError` with the reason, and fire the team's change signal.
|
|
@@ -3777,6 +3779,7 @@ The page is in English, and `presentation: { locale: "zh-TW" }` switches it to t
|
|
|
3777
3779
|
| `ChatSurface.readAttachment`, `maxAttachmentBytes`, `AttachmentContent` | Uploads of any kind up to `uploadMaxBytes`, handed to the agent as a stored file's path, never held whole in memory |
|
|
3778
3780
|
| `MODES`, `autonomy`, `ApprovedBy.auto`, `MODES.onAutoApproved` | The yolo and long-running switches of a room, and the line in the room for each call yolo approved |
|
|
3779
3781
|
| `DirectChannelProvider` with `mirror` | A notice to the owner lands in Home and is pushed to their devices; a notice another channel delivered is pushed too |
|
|
3782
|
+
| `ROOM_LAYOUT` (it provides it) | The agent tools' `group` on `agent_create` and `group_create`, `room_arrange`, and the room groups in `agent_list` |
|
|
3780
3783
|
| `context.listener(id)` | `auth: { mode: "none" }` refuses a listener that reaches beyond the machine |
|
|
3781
3784
|
| `identities` with `token:web-console` | `none` and `password` speak for the primary owner (or `auth.principal`) without an `access.owners` entry |
|
|
3782
3785
|
|
|
@@ -4662,6 +4665,9 @@ Import from the entries listed below; source area files are internal.
|
|
|
4662
4665
|
| `ResolvedSkill` | `pi-roundtable` | type |
|
|
4663
4666
|
| `RoleGrant` | `pi-roundtable` | type |
|
|
4664
4667
|
| `RoleSource` | `pi-roundtable` | type |
|
|
4668
|
+
| `ROOM_LAYOUT` | `pi-roundtable` | value |
|
|
4669
|
+
| `RoomGroupsView` | `pi-roundtable` | type |
|
|
4670
|
+
| `RoomLayoutService` | `pi-roundtable` | type |
|
|
4665
4671
|
| `RoundEnd` | `pi-roundtable` | type |
|
|
4666
4672
|
| `RoundProgress` | `pi-roundtable` | type |
|
|
4667
4673
|
| `Roundtable` | `pi-roundtable` | value |
|
package/package.json
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
import { TeamLifecycle } from "./team-lifecycle.ts";
|
|
38
38
|
import type { AgentTeamOptions, TeamContext } from "./team-options.ts";
|
|
39
39
|
import { teamSystemPrompt } from "./team-prompt.ts";
|
|
40
|
+
import { TeamRooms } from "./team-rooms.ts";
|
|
40
41
|
import { teamSelection } from "./team-selection.ts";
|
|
41
42
|
import { type TeamStatus, teamStatus } from "./team-status.ts";
|
|
42
43
|
import {
|
|
@@ -176,6 +177,7 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
|
|
|
176
177
|
extension(scope: AgentTurnScope): ExtensionFactory {
|
|
177
178
|
return agentToolsExtension(this, scope, THE_SPEAKER, {
|
|
178
179
|
skills: this.#options.skills !== undefined,
|
|
180
|
+
rooms: new TeamRooms(this.#options.store, () => this.#options.rooms?.()),
|
|
179
181
|
});
|
|
180
182
|
}
|
|
181
183
|
|
|
@@ -26,6 +26,8 @@ import {
|
|
|
26
26
|
} from "./agent-tool-schema.ts";
|
|
27
27
|
import type { HelperFields, PresetAction } from "./helper-preset-ops.ts";
|
|
28
28
|
import { helperToolDefs } from "./helper-tools.ts";
|
|
29
|
+
import { placedAfter, ROOM_GROUP, roomToolDefs } from "./room-tools.ts";
|
|
30
|
+
import type { RoomOps } from "./team-rooms.ts";
|
|
29
31
|
|
|
30
32
|
/** The tool that hands a request to another agent; a group seat has none. */
|
|
31
33
|
export const MESSAGE_AGENT_TOOL = "message_agent";
|
|
@@ -54,12 +56,13 @@ export const AGENT_TOOLS = [
|
|
|
54
56
|
"group_update",
|
|
55
57
|
"archive",
|
|
56
58
|
"channel_arrange",
|
|
59
|
+
"room_arrange",
|
|
57
60
|
"channel_read",
|
|
58
61
|
] as const;
|
|
59
62
|
|
|
60
63
|
/**
|
|
61
64
|
* The tools a temp knight's turns do not get: making knights, temp knights or groups, archiving,
|
|
62
|
-
* arranging channels, and scheduling, which would leave work behind with no one to end it.
|
|
65
|
+
* arranging channels and rooms, and scheduling, which would leave work behind with no one to end it.
|
|
63
66
|
*/
|
|
64
67
|
export const WITHHELD_FROM_HELPERS: readonly string[] = [
|
|
65
68
|
"agent_create",
|
|
@@ -68,6 +71,7 @@ export const WITHHELD_FROM_HELPERS: readonly string[] = [
|
|
|
68
71
|
"group_update",
|
|
69
72
|
"archive",
|
|
70
73
|
"channel_arrange",
|
|
74
|
+
"room_arrange",
|
|
71
75
|
"schedule_create",
|
|
72
76
|
];
|
|
73
77
|
|
|
@@ -163,7 +167,7 @@ export interface AgentOps {
|
|
|
163
167
|
|
|
164
168
|
const category = (kind: "Agents" | "Groups") =>
|
|
165
169
|
Type.String({
|
|
166
|
-
description: `
|
|
170
|
+
description: `Discord only: the category its channel opens under, ${kind} (the default) or ${kind}-<suffix>, such as ${kind}-work; made when missing. Keep to the categories agent_list shows unless a new one fits better. The app's room groups follow group.`,
|
|
167
171
|
});
|
|
168
172
|
const MEMBERS = Type.Array(Type.String(), {
|
|
169
173
|
minItems: MIN_GROUP_MEMBERS,
|
|
@@ -177,13 +181,15 @@ type AgentToolDef = TextToolDef<(typeof AGENT_TOOLS)[number]>;
|
|
|
177
181
|
export interface AgentToolOptions {
|
|
178
182
|
/** Whether the skills addon is on; without it agent_create takes no skills. */
|
|
179
183
|
skills: boolean;
|
|
184
|
+
/** The app's room groups; without them `group` and room_arrange are refused. */
|
|
185
|
+
rooms?: RoomOps;
|
|
180
186
|
}
|
|
181
187
|
|
|
182
188
|
function toolDefs(
|
|
183
189
|
ops: AgentOps,
|
|
184
190
|
scope: AgentTurnScope,
|
|
185
191
|
owner: OwnerIdentity,
|
|
186
|
-
{ skills: skillsOn }: AgentToolOptions,
|
|
192
|
+
{ skills: skillsOn, rooms }: AgentToolOptions,
|
|
187
193
|
): AgentToolDef[] {
|
|
188
194
|
const o = ownerWords(owner);
|
|
189
195
|
const defs: AgentToolDef[] = [
|
|
@@ -191,9 +197,13 @@ function toolDefs(
|
|
|
191
197
|
name: "agent_list",
|
|
192
198
|
label: "List agents",
|
|
193
199
|
description:
|
|
194
|
-
"List every agent and group: name, display name, channel, and status; then the Agents and Groups categories in server order with their channels.",
|
|
200
|
+
"List every agent and group: name, display name, channel, and status; then the Agents and Groups categories in server order with their channels; then the web app's room groups in order with their rooms, and its pinned rooms.",
|
|
195
201
|
parameters: Type.Object({}),
|
|
196
|
-
run: () =>
|
|
202
|
+
run: async () => {
|
|
203
|
+
const list = await ops.list();
|
|
204
|
+
const groups = await rooms?.listText();
|
|
205
|
+
return groups ? `${list}\n\n${groups}` : list;
|
|
206
|
+
},
|
|
197
207
|
},
|
|
198
208
|
{
|
|
199
209
|
name: "agent_get",
|
|
@@ -264,6 +274,7 @@ function toolDefs(
|
|
|
264
274
|
description: "Its opening task, self-contained.",
|
|
265
275
|
}),
|
|
266
276
|
category: Type.Optional(category("Agents")),
|
|
277
|
+
group: Type.Optional(ROOM_GROUP),
|
|
267
278
|
long_running: Type.Optional(
|
|
268
279
|
Type.Boolean({
|
|
269
280
|
description: `Turn on long-running mode for its conversations: its turns, such as the opening task, go on past the usual 10-minute limit by themselves, up to the host's cap (four hours by default). Set it for an agent whose tasks run long, such as research or large changes.`,
|
|
@@ -285,16 +296,19 @@ function toolDefs(
|
|
|
285
296
|
const skills = stringList(i, "skills");
|
|
286
297
|
const look = lookOf(i);
|
|
287
298
|
const longRunning = i.long_running === true;
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
299
|
+
const name = requiredString(i, "name");
|
|
300
|
+
return placedAfter(rooms, name, optionalString(i, "group"), () =>
|
|
301
|
+
ops.create(scope, {
|
|
302
|
+
name,
|
|
303
|
+
displayName: requiredString(i, "display_name"),
|
|
304
|
+
prompt: requiredString(i, "prompt"),
|
|
305
|
+
...(Object.keys(look).length > 0 ? { character: look } : {}),
|
|
306
|
+
task: requiredString(i, "task"),
|
|
307
|
+
...(category ? { category } : {}),
|
|
308
|
+
...(skills && skills.length > 0 ? { skills } : {}),
|
|
309
|
+
...(longRunning ? { longRunning } : {}),
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
298
312
|
},
|
|
299
313
|
},
|
|
300
314
|
...helperToolDefs(ops, scope, skillsOn),
|
|
@@ -326,17 +340,21 @@ function toolDefs(
|
|
|
326
340
|
members: MEMBERS,
|
|
327
341
|
host: Type.Optional(NAME),
|
|
328
342
|
category: Type.Optional(category("Groups")),
|
|
343
|
+
group: Type.Optional(ROOM_GROUP),
|
|
329
344
|
}),
|
|
330
345
|
run: (i) => {
|
|
331
346
|
const host = optionalString(i, "host");
|
|
332
347
|
const category = optionalString(i, "category");
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
348
|
+
const name = requiredString(i, "name");
|
|
349
|
+
return placedAfter(rooms, name, optionalString(i, "group"), () =>
|
|
350
|
+
ops.createGroup({
|
|
351
|
+
name,
|
|
352
|
+
displayName: requiredString(i, "display_name"),
|
|
353
|
+
members: stringList(i, "members") ?? [],
|
|
354
|
+
...(host ? { host } : {}),
|
|
355
|
+
...(category ? { category } : {}),
|
|
356
|
+
}),
|
|
357
|
+
);
|
|
340
358
|
},
|
|
341
359
|
},
|
|
342
360
|
{
|
|
@@ -401,6 +419,7 @@ function toolDefs(
|
|
|
401
419
|
);
|
|
402
420
|
},
|
|
403
421
|
},
|
|
422
|
+
...roomToolDefs(rooms, o.name),
|
|
404
423
|
{
|
|
405
424
|
name: "channel_read",
|
|
406
425
|
label: "Read channel",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { AgentError } from "../domain/errors.ts";
|
|
3
|
+
import {
|
|
4
|
+
requiredString,
|
|
5
|
+
stringList,
|
|
6
|
+
type TextToolDef,
|
|
7
|
+
} from "../runtime/text-tools.ts";
|
|
8
|
+
import { NO_ROOM_GROUPS, type RoomOps } from "./team-rooms.ts";
|
|
9
|
+
|
|
10
|
+
/** The `group` of agent_create and group_create: the room's group in the app. */
|
|
11
|
+
export const ROOM_GROUP = Type.String({
|
|
12
|
+
minLength: 1,
|
|
13
|
+
maxLength: 40,
|
|
14
|
+
description:
|
|
15
|
+
"The group its room goes into in the web app's room list, made when missing; agent_list shows the groups there. Leave it out to keep the room ungrouped.",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Makes an agent or group, then places its room in the app group when one is given. A group the
|
|
20
|
+
* host cannot place in refuses before anything is made.
|
|
21
|
+
*/
|
|
22
|
+
export async function placedAfter(
|
|
23
|
+
rooms: RoomOps | undefined,
|
|
24
|
+
name: string,
|
|
25
|
+
group: string | undefined,
|
|
26
|
+
make: () => Promise<string>,
|
|
27
|
+
): Promise<string> {
|
|
28
|
+
if (group === undefined) return make();
|
|
29
|
+
if (!rooms) throw new AgentError(NO_ROOM_GROUPS);
|
|
30
|
+
rooms.check(group);
|
|
31
|
+
const made = await make();
|
|
32
|
+
try {
|
|
33
|
+
return `${made} ${await rooms.place(name, group)}`;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
36
|
+
return `${made} Its room stays ungrouped: ${why}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The tool that sorts rooms into the app's groups. */
|
|
41
|
+
export function roomToolDefs(
|
|
42
|
+
rooms: RoomOps | undefined,
|
|
43
|
+
owner: string,
|
|
44
|
+
): TextToolDef<"room_arrange">[] {
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
name: "room_arrange",
|
|
48
|
+
label: "Arrange app rooms",
|
|
49
|
+
description: `Sort agent and group rooms into the web app's room groups and order them, when ${owner} asks. Missing groups are made. The listed groups come first in the room list in list order, then every other group as it was; in each listed group the listed rooms come first in order, then its other rooms as they were. Rooms you leave out keep their place, Home stays on top, and a temp knight's room stays under its knight's. Any wrong entry refuses the whole call and nothing moves. Read the current groups with agent_list first.`,
|
|
50
|
+
parameters: Type.Object({
|
|
51
|
+
groups: Type.Array(
|
|
52
|
+
Type.Object({
|
|
53
|
+
group: Type.String({
|
|
54
|
+
minLength: 1,
|
|
55
|
+
maxLength: 40,
|
|
56
|
+
description:
|
|
57
|
+
"The group's name, 1 to 40 characters in any language.",
|
|
58
|
+
}),
|
|
59
|
+
names: Type.Array(Type.String(), {
|
|
60
|
+
minItems: 1,
|
|
61
|
+
description:
|
|
62
|
+
"Agent or group names (from agent_list), in the order their rooms should appear.",
|
|
63
|
+
}),
|
|
64
|
+
}),
|
|
65
|
+
{ minItems: 1, description: "Groups in room-list order." },
|
|
66
|
+
),
|
|
67
|
+
}),
|
|
68
|
+
run: (i) => {
|
|
69
|
+
if (!rooms) throw new AgentError(NO_ROOM_GROUPS);
|
|
70
|
+
const entries = Array.isArray(i.groups) ? i.groups : [];
|
|
71
|
+
return rooms.arrange(
|
|
72
|
+
entries.map((entry: Record<string, unknown>) => ({
|
|
73
|
+
group: requiredString(entry, "group"),
|
|
74
|
+
names: stringList(entry, "names") ?? [],
|
|
75
|
+
})),
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ResolvedHelpers } from "../config/helpers.ts";
|
|
2
|
+
import type { RoomLayoutService } from "../contract/room-layout.ts";
|
|
2
3
|
import type { ChannelKey } from "../domain/conversation.ts";
|
|
3
4
|
import type { ThinkingSetting } from "../domain/models.ts";
|
|
4
5
|
import type { ToolSelection } from "../domain/sessions.ts";
|
|
@@ -70,6 +71,8 @@ export interface AgentTeamOptions
|
|
|
70
71
|
* defaults apply.
|
|
71
72
|
*/
|
|
72
73
|
helpers?: ResolvedHelpers | false;
|
|
74
|
+
/** The app's room groups, read at each call; absent or undefined, the tools refuse a room group. */
|
|
75
|
+
rooms?: () => RoomLayoutService | undefined;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
/** What the team's collaborators share: its options, its turns, and its change signal. */
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RoomGroupsView,
|
|
3
|
+
RoomLayoutService,
|
|
4
|
+
} from "../contract/room-layout.ts";
|
|
5
|
+
import { AgentError } from "../domain/errors.ts";
|
|
6
|
+
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
7
|
+
import { isHelper } from "./agent-rules.ts";
|
|
8
|
+
|
|
9
|
+
/** The refusal of a room group on a host whose app has no room list. */
|
|
10
|
+
export const NO_ROOM_GROUPS =
|
|
11
|
+
"This host has no app room list to group rooms in: groups come with the web app's rooms pane. Leave group out; category places a Discord channel.";
|
|
12
|
+
|
|
13
|
+
/** What the agent tools do with the app's room groups; `TeamRooms` is the team's. */
|
|
14
|
+
export interface RoomOps {
|
|
15
|
+
/** Refuses a group the room could not be placed in, before anything is made. */
|
|
16
|
+
check(group: string): void;
|
|
17
|
+
/** Puts an agent's or group's room into an app group, made when missing; returns text for the model. */
|
|
18
|
+
place(name: string, group: string): Promise<string>;
|
|
19
|
+
/** The app's groups with their rooms, and the pinned rooms; empty when the host has no app room list. */
|
|
20
|
+
listText(): Promise<string>;
|
|
21
|
+
arrange(entries: { group: string; names: string[] }[]): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The room groups of the app that hosts the agents' rooms, by agent and group names. */
|
|
25
|
+
export class TeamRooms implements RoomOps {
|
|
26
|
+
readonly #store: Pick<AgentDirectory, "agent" | "group">;
|
|
27
|
+
readonly #layout: () => RoomLayoutService | undefined;
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
store: Pick<AgentDirectory, "agent" | "group">,
|
|
31
|
+
layout: () => RoomLayoutService | undefined,
|
|
32
|
+
) {
|
|
33
|
+
this.#store = store;
|
|
34
|
+
this.#layout = layout;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
check(group: string): void {
|
|
38
|
+
this.#service();
|
|
39
|
+
if (group.trim() === "") throw new AgentError("Give the group a name.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async place(name: string, group: string): Promise<string> {
|
|
43
|
+
this.check(group);
|
|
44
|
+
await provided(() => this.#service().place(name, group.trim()));
|
|
45
|
+
return `Its room is in the app group "${group.trim()}".`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async listText(): Promise<string> {
|
|
49
|
+
const service = this.#layout();
|
|
50
|
+
return service ? roomGroupsText(await service.view()) : "";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Sorts rooms into the app's groups and orders them: the listed groups and rooms first, the
|
|
55
|
+
* rest where they were. A wrong entry refuses the whole call before anything moves.
|
|
56
|
+
*/
|
|
57
|
+
async arrange(
|
|
58
|
+
entries: { group: string; names: string[] }[],
|
|
59
|
+
): Promise<string> {
|
|
60
|
+
const service = this.#service();
|
|
61
|
+
if (entries.length === 0) throw new AgentError("List at least one group.");
|
|
62
|
+
const groups = new Set<string>();
|
|
63
|
+
const names = new Set<string>();
|
|
64
|
+
const listed = entries.map(({ group, names: rooms }) => {
|
|
65
|
+
const name = group.trim();
|
|
66
|
+
if (name === "") throw new AgentError("Give every group a name.");
|
|
67
|
+
if (groups.has(name.toLocaleLowerCase()))
|
|
68
|
+
throw new AgentError(`The group "${name}" is listed twice.`);
|
|
69
|
+
groups.add(name.toLocaleLowerCase());
|
|
70
|
+
if (rooms.length === 0)
|
|
71
|
+
throw new AgentError(
|
|
72
|
+
`List at least one agent or group under "${name}".`,
|
|
73
|
+
);
|
|
74
|
+
for (const room of rooms) {
|
|
75
|
+
if (names.has(room)) throw new AgentError(`"${room}" is listed twice.`);
|
|
76
|
+
names.add(room);
|
|
77
|
+
this.#placeable(room);
|
|
78
|
+
}
|
|
79
|
+
return { group: name, names: rooms };
|
|
80
|
+
});
|
|
81
|
+
await provided(() => service.arrange(listed));
|
|
82
|
+
return `Arranged the app's room groups.\n\n${roomGroupsText(await service.view())}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#service(): RoomLayoutService {
|
|
86
|
+
const service = this.#layout();
|
|
87
|
+
if (!service) throw new AgentError(NO_ROOM_GROUPS);
|
|
88
|
+
return service;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#placeable(name: string): void {
|
|
92
|
+
const agent = this.#store.agent(name);
|
|
93
|
+
const target = agent ?? this.#store.group(name);
|
|
94
|
+
if (!target)
|
|
95
|
+
throw new AgentError(
|
|
96
|
+
`There is no agent or group "${name}"; see agent_list.`,
|
|
97
|
+
);
|
|
98
|
+
if (target.status !== "active")
|
|
99
|
+
throw new AgentError(`"${name}" is archived.`);
|
|
100
|
+
if (agent && isHelper(agent))
|
|
101
|
+
throw new AgentError(
|
|
102
|
+
`"${name}" is a temp knight; its room stays under its knight's.`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The app's groups in list order with their rooms, then the pinned rooms. */
|
|
108
|
+
export function roomGroupsText(view: RoomGroupsView): string {
|
|
109
|
+
const lines = view.groups.map(
|
|
110
|
+
(group) => `- ${group.name}: ${group.rooms.join(", ") || "empty"}`,
|
|
111
|
+
);
|
|
112
|
+
return `App room groups, in list order:\n${lines.join("\n") || "none"}\nPinned in the app: ${view.pins.join(", ") || "none"}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Runs a change of the provider, its refusal read as the agent's. */
|
|
116
|
+
async function provided(change: () => Promise<void>): Promise<void> {
|
|
117
|
+
try {
|
|
118
|
+
await change();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (error instanceof AgentError) throw error;
|
|
121
|
+
throw new AgentError(
|
|
122
|
+
error instanceof Error ? error.message : String(error),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -15,6 +15,7 @@ import { agentOfChannel, discordKey } from "../agents/team-keys.ts";
|
|
|
15
15
|
import { ownerAttachmentDir } from "../attachments/attachment-dir.ts";
|
|
16
16
|
import type { ResolvedHelpers } from "../config/helpers.ts";
|
|
17
17
|
import type { ResolvedRouting } from "../config/routing.ts";
|
|
18
|
+
import { ROOM_LAYOUT } from "../contract/room-layout.ts";
|
|
18
19
|
import type { AgentSessions } from "../contract/runtime.ts";
|
|
19
20
|
import type { ChannelKey } from "../domain/conversation.ts";
|
|
20
21
|
import { ConfigError } from "../domain/errors.ts";
|
|
@@ -353,6 +354,7 @@ export function agentServerPlugin(
|
|
|
353
354
|
: {}),
|
|
354
355
|
...(skills ? { skills } : {}),
|
|
355
356
|
modes: () => context.services.find(MODES),
|
|
357
|
+
rooms: () => context.services.find(ROOM_LAYOUT),
|
|
356
358
|
...(options.helpers !== undefined ? { helpers: options.helpers } : {}),
|
|
357
359
|
principals: () => context.services.find(IDENTITY),
|
|
358
360
|
logger,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ServiceKey, serviceKey } from "./services.ts";
|
|
2
|
+
|
|
3
|
+
/** The room list of an app as agent and group names: its groups in order, and its pinned rooms. */
|
|
4
|
+
export interface RoomGroupsView {
|
|
5
|
+
groups: { name: string; rooms: string[] }[];
|
|
6
|
+
pins: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The groups of an app's room list, read and changed by agent and group names. A change is one
|
|
11
|
+
* step that no other edit overlaps; a wrong name or group refuses it whole and nothing moves.
|
|
12
|
+
*/
|
|
13
|
+
export interface RoomLayoutService {
|
|
14
|
+
/** The groups with the active rooms in each, in order, and the pinned rooms. */
|
|
15
|
+
view(): Promise<RoomGroupsView>;
|
|
16
|
+
/** Puts the room into a group, last; `null` takes it out of every group. A missing group is made. */
|
|
17
|
+
place(name: string, group: string | null): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* The listed groups first in list order, then the others as they were; in each listed group the
|
|
20
|
+
* listed rooms first in order, then its other rooms. Missing groups are made, and rooms not
|
|
21
|
+
* listed keep their place.
|
|
22
|
+
*/
|
|
23
|
+
arrange(
|
|
24
|
+
entries: readonly { group: string; names: readonly string[] }[],
|
|
25
|
+
): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The room groups of the web app; pi-roundtable-web provides it while its rooms pane is served. */
|
|
29
|
+
export const ROOM_LAYOUT: ServiceKey<RoomLayoutService> =
|
|
30
|
+
serviceKey<RoomLayoutService>("roundtable.room-layout", {
|
|
31
|
+
absent:
|
|
32
|
+
"the room groups belong to an app's room list; register pi-roundtable-web with its rooms pane.",
|
|
33
|
+
});
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"memory_search",
|
|
100
100
|
"message_agent",
|
|
101
101
|
"notify",
|
|
102
|
+
"room_arrange",
|
|
102
103
|
"schedule_cancel",
|
|
103
104
|
"schedule_create",
|
|
104
105
|
"schedule_list",
|
|
@@ -133,6 +134,7 @@
|
|
|
133
134
|
"helper_preset_set",
|
|
134
135
|
"message_agent",
|
|
135
136
|
"read",
|
|
137
|
+
"room_arrange",
|
|
136
138
|
"skill_create",
|
|
137
139
|
"skill_delete",
|
|
138
140
|
"skill_group_delete",
|
|
@@ -198,6 +200,7 @@
|
|
|
198
200
|
"memory_remove",
|
|
199
201
|
"memory_search",
|
|
200
202
|
"notify",
|
|
203
|
+
"room_arrange",
|
|
201
204
|
"schedule_cancel",
|
|
202
205
|
"schedule_create",
|
|
203
206
|
"schedule_list",
|
|
@@ -226,6 +229,7 @@
|
|
|
226
229
|
"group_create",
|
|
227
230
|
"group_update",
|
|
228
231
|
"read",
|
|
232
|
+
"room_arrange",
|
|
229
233
|
"skill_create",
|
|
230
234
|
"skill_delete",
|
|
231
235
|
"skill_group_delete",
|
|
@@ -300,6 +304,7 @@
|
|
|
300
304
|
"notify": "owner",
|
|
301
305
|
"read": "owner",
|
|
302
306
|
"read_attachment": "member",
|
|
307
|
+
"room_arrange": "admin",
|
|
303
308
|
"schedule_cancel": "admin",
|
|
304
309
|
"schedule_create": "admin",
|
|
305
310
|
"schedule_list": "member",
|
package/src/index.ts
CHANGED
|
@@ -121,6 +121,11 @@ export type {
|
|
|
121
121
|
ReferenceImage,
|
|
122
122
|
ResolvedProviders,
|
|
123
123
|
} from "./core/contract/providers.ts";
|
|
124
|
+
export type {
|
|
125
|
+
RoomGroupsView,
|
|
126
|
+
RoomLayoutService,
|
|
127
|
+
} from "./core/contract/room-layout.ts";
|
|
128
|
+
export { ROOM_LAYOUT } from "./core/contract/room-layout.ts";
|
|
124
129
|
export type {
|
|
125
130
|
AgentRuntime,
|
|
126
131
|
AgentSessions,
|