pi-roundtable 0.46.0 → 0.47.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 +26 -0
- package/docs/plugins.md +3 -3
- package/package.json +2 -2
- package/src/characters/catalog.ts +1 -0
- package/src/characters/characters.css +2 -1
- package/src/characters/css.ts +2 -1
- package/src/characters/parts-face.ts +10 -0
- package/src/core/agents/agent-team-fixture.ts +31 -12
- package/src/core/agents/agent-team.ts +2 -6
- package/src/core/agents/team-place-writes.ts +27 -5
- package/src/core/agents/team-text.ts +4 -0
- package/src/core/builtin/agent-server.ts +6 -5
- package/src/core/builtin/discord.ts +7 -5
- package/src/core/config/agent-team.ts +5 -3
- package/src/core/contract/agent-channels.ts +12 -4
- package/src/core/contract/places.ts +20 -1
- package/src/core/db/team-move.ts +2 -2
- package/src/core/discord/agent-dashboard.ts +21 -2
- package/src/core/discord/agent-guild.ts +64 -10
- package/src/core/discord/agent-layout.ts +7 -3
- package/src/core/discord/agent-tools.ts +41 -14
- package/src/core/discord/channel-operations.ts +2 -0
- package/src/core/plugin-api/agent-ops.ts +0 -4
- package/src/core/registry/places.ts +31 -1
- package/src/core/testing/team-places.ts +2 -4
- package/src/kit/support.ts +24 -10
- package/templates/adapters/web/package.json.tmpl +1 -1
- package/templates/package.json.tmpl +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,32 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.47.0] - 2026-11-11
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- pi-roundtable-web: Hidden and archived: a Select button (or holding a row) chooses several rows of one section and handles them together. Hidden rooms are unhidden, dispatch threads dismissed, archived knights and groups restored or deleted for good, each with an Undo notice where the action can be undone. A knight is chosen with its temp knights; the delete question names the items (eight, then "and N more"), says how many temp knights go with them, and carries the count on its button. Chips filter a long section by 7 or 30 days without activity before "Select all in section". A run shows its progress, goes on after a refusal, and then names each row the server refused with its reason. Archived rows now show the knight's own picture and when it was last active; `GET api/archive` entries carry `lastActive`.
|
|
13
|
+
- pi-roundtable-web: Overview: stored workspaces and outside AI client conversations are short rows (name; last active, size and archives; a badge while a turn runs) with Start over, Delete and Transcript in the row's ⋯ menu, instead of cards about 225 px tall. Each section folds, says what it holds beside its heading, and keeps its fold on the device; the knights, outside conversations and party channels start folded. Select (or holding a row) chooses workspaces or outside conversations, with the same 7 and 30 day chips, and starts them over or deletes them for good after a question that names them and their total size.
|
|
14
|
+
- pi-roundtable-web: A person can design their own knight on the profile page, with the creator the knights use ("Your knight": Design my knight, Change look, Remove). The chat home's own picture, the person's own messages (beside the first of each group, at the right), their notes, the "seen by" faces and the profile's account head draw it, and so does everyone else past the gate. A person without a knight keeps their account picture, then their initials. The profile shows the card on hosts that serve the rooms pane.
|
|
15
|
+
- pi-roundtable-web: New routes: `PUT` and `DELETE api/profile/character`, and `GET api/people/<principal>/character` (another person's only past the gate, like their picture). `GET api/profile` and the socket's `ready` frame carry the person's own knight as `character`. The knights are kept in a new table, `web_person_characters`.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- On the chat home an idle agent rests with its eyes closed instead of blinking, so a list of idle figures no longer blinks all at the same moment. The kit adds a `resting` expression (a calm closed-eyed face; `STATE_EXPRESSION` is unchanged), `characters.css` never blinks it, and every other figure's blink is now offset by its `--phase`, so neighbours blink at different moments. The chat home's per-figure phase has a finer step, so two rooms rarely share one.
|
|
20
|
+
- `typebox` is pinned at 1.4.6 (was 1.3.37), here and in the projects `roundtable init` generates, which carry the same pin.
|
|
21
|
+
- pi-roundtable-web: Home (the coordinator's room) can be pinned by hand: its room menu offers Pin and Unpin (and Move up and down once pinned), still no folder or Hide. A pinned Home sits among the pins in the owner's order, in the dock, the pins row and the room drawer; unpinned it stays the first row of the All list.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- pi-roundtable-web: The person's picture on the chat home now opens a menu (their name, Profile, Settings, light or dark, Log out) instead of a link that did nothing on hosts that do not serve the profile pane. The Profile entry and the Profile tile of the features grid show only where the host serves the profile pane.
|
|
26
|
+
- pi-roundtable-web: The chat home no longer has the collapsed "Hidden · Archived" row; the features grid's "Hidden and archived" tile is the way to that page.
|
|
27
|
+
- A place provider's `createArguments` for `agent_create` or `group_create` may no longer reuse an argument the tool takes itself (`name`, `task`, `group`, ...) or one another provider adds: the boot stops with a `PluginError` naming both plugins, where the later one used to replace the earlier's schema silently. Only a string the model gives reaches `ensure` as `hints`, so give a string schema.
|
|
28
|
+
- A team whose stored places of a surface other than Discord belong to another space (`placeSpaces`) drops the places moved in from a former team id of another space, as Discord's channels were already, instead of keeping them.
|
|
29
|
+
- Restoring an archived agent or group whose stored place the provider finds `foreign` (a Discord channel of a server the team left, while the bot is still in it) makes a new place in the agent guild instead of moving the old channel inside the other server.
|
|
30
|
+
- `discordAgentGuild` takes `own: { services, events }`, the services and event handlers the replacing plugin makes itself, and returns them merged with the dashboard's: spreading the result used to replace them. A handler of an event both hear (`serviceStarted`) runs after the dashboard's, and still runs when that one throws.
|
|
31
|
+
- Discord's tools and dashboard find an agent's or group's channel and the owner of a channel through the places (`placeOwner`, `placesOf` and the status views' `places`), (an archived owner's channel that stays in an `Agents` or `Groups` category is named by its owner now, not shown as `<#id>`), not through the deprecated `agentByChannel`, `groupByChannel` and `channelId`, which they read only for an agent server written before places were providers. The agent server's refusal for `discord.entryChannel` without `discord.guild` has one text in the configuration check and in the Discord plugin.
|
|
32
|
+
- `AgentChannels`, `AgentPost`, `AgentCategory`, `CategoryLayout`, `ChannelMessage` and `DashboardBoard` carry `@deprecated` in their declarations, saying that `pi-roundtable/kit` stops exporting them in 1.0 and `pi-roundtable/discord` exports them then.
|
|
33
|
+
|
|
8
34
|
## [0.46.0] - 2026-11-10
|
|
9
35
|
|
|
10
36
|
### Added
|
package/docs/plugins.md
CHANGED
|
@@ -3266,13 +3266,13 @@ It returns four contributions, the same the built-in plugin makes:
|
|
|
3266
3266
|
|
|
3267
3267
|
- `places`: the provider that gives the guild's channels the keys, group seats and log names the built-in Discord gives them, names the coordinator's place from `entryChannel`, and writes the categories section of `agent_list` with the agents' and groups' names. Pass `client` too to have the team check its stored channels at start.
|
|
3268
3268
|
- `tools`: `channel_arrange` and `channel_read`, which an agent's turn carries.
|
|
3269
|
-
- `services` and `events`: the `#dashboard` message over `connection.agentDashboard(guild)`, started when the agent server's team is ready.
|
|
3269
|
+
- `services` and `events`: the `#dashboard` message over `connection.agentDashboard(guild)`, started when the agent server's team is ready. Spreading the result puts these in place of the plugin's own `services` and `events`, so a plugin that has some gives them as `own: { services, events }`: the services follow the dashboard's, and a handler of an event the dashboard also hears (`serviceStarted`) runs after it, and still runs when the dashboard's throws.
|
|
3270
3270
|
|
|
3271
3271
|
`guild` and `entryChannel` are the host's `discord.guild` and `discord.entryChannel`. Without `entryChannel` the coordinator is the first agent the host seeds, since a host with `discord.guild` names no coordinator in its configuration. `discordPlaceProvider({ guild, connection, logger })` is the provider alone: a replacement that contributes only it has no channel tools and no dashboard, and its `agent_list` shows channel mentions where the names were. Without a provider for the `discord` surface the host refuses to start, since the team would make channels it cannot read.
|
|
3272
3272
|
|
|
3273
3273
|
The agent team reads its places through the providers: the keys of an agent or group (`AGENTS.team.roomsOf(name)`, and `placesOf(name)` with each key's surface), who owns a key (`AGENTS.team.owns(key)`, and `AGENTS.directory.placeOwner(key)` for an archived owner too), the routing table, the conversation keys of a group's seats and log, and the outbox replay. A stored provider's places are the rows of `agent_places`; a derived provider's are rooms. "Auto" order puts every stored place before the rooms, so with Discord configured the Discord channel is still an agent's primary place. A row of a surface no provider serves on this host is kept and ignored. `TeamStatus` views carry `places` (`TeamPlace`: `{ surface, key }`). `Agent.channelId`, `AgentGroup.channelId`, `AgentDirectory.agentByChannel` and `groupByChannel`, `AgentTeam.guildId` and `discordGuild`, and the status views' `channelId` are deprecated and removed in 1.0; the team still writes them.
|
|
3274
3274
|
|
|
3275
|
-
The team writes through the providers too. At start it calls `ensure` for each active agent without a place on a stored provider (a temp knight lives in its rooms until reached) and `check` for each place it has stored: `gone` archives the owner as a deletion does, and `foreign` (an id that is no place of the provider's space, such as a channel of a guild the team left) drops the row and makes a new place with `ensure`. Creating an agent or group makes its place with `ensure` (the values of a provider's `createArguments` arrive as `hints`), a temp knight's thread is made with `ensure` and `parent`, archiving calls `remove`, restoring calls `ensure` with `existing
|
|
3275
|
+
The team writes through the providers too. At start it calls `ensure` for each active agent without a place on a stored provider (a temp knight lives in its rooms until reached) and `check` for each place it has stored: `gone` archives the owner as a deletion does, and `foreign` (an id that is no place of the provider's space, such as a channel of a guild the team left) drops the row and makes a new place with `ensure`. Creating an agent or group makes its place with `ensure` (the values of a provider's `createArguments` arrive as `hints`; only a string the model gave reaches it, so give a string schema, and a name the tool takes itself, such as `name`, `task` or `group`, or another provider already adds, stops the boot with a `PluginError`), a temp knight's thread is made with `ensure` and `parent`, archiving calls `remove`, restoring calls `check` and then `ensure` with `existing` (a place found `foreign` is not brought back: a new one is made), a group's topic is written with `describe`, and a place the provider reports through `onRemoved` archives its owner. `remove` resolves to the rest of the archive tool's answer after `Archived "<name>"`, starting with its own separator (`; its channel <#id> is kept under Archive.`), or to nothing. Replies and interim posts go through `post` and `interim`, and a reply carries files only where the place's surface declares `supportsFiles`.
|
|
3276
3276
|
|
|
3277
3277
|
`placeProviderContract(name, make)` from `pi-roundtable/testing` registers the provider contract as tests for any provider; `make` returns a `PlaceContractSubject` with the provider and a view of what a person on the surface sees.
|
|
3278
3278
|
|
|
@@ -3907,7 +3907,7 @@ The parts are medieval: the clothes, hats and gear of an agent are what a late-m
|
|
|
3907
3907
|
|
|
3908
3908
|
### The picture: `composeSvg`
|
|
3909
3909
|
|
|
3910
|
-
`ComposeOptions` are all optional: `expr` (one of the
|
|
3910
|
+
`ComposeOptions` are all optional: `expr` (one of the 14 `EXPRESSIONS`, by default the one `STATE_EXPRESSION` gives the state; `resting` is a calm face with closed eyes that no state maps to, and `characters.css` never blinks it), `state` (one of the seven `AVATAR_STATES`: `idle`, `thinking`, `working`, `waiting`, `done`, `error`, `sleepy`), `look` (`modern-light` by default, `modern-dark`, `camelot-light` or `camelot-dark`, which change only the background and ring), `frame` (`disc` or `shield`), `bare` (no frame or background), `mouth` (`open` or `closed`, drawn in place of the expression's own mouth, for the two frames of a talking figure), `still`, `uid`, `size`, `label` and `skins` (six `#rrggbb` skin tones that `CharacterSpec.skin` indexes, in place of `CATALOG.skins`; anything but six valid colors throws a `CharacterError` whose `field` is `skins` or `skins[3]`).
|
|
3911
3911
|
|
|
3912
3912
|
- The output has literal colors only. It has no `style` attribute, variable, `<style>`, script, text, image, link, event handler or `<foreignObject>`, so a page whose content security policy forbids inline styles can inject it, and `canvas` rasterizes it as it is. It is at most 8 KB and the same for the same input. The root is `<svg class="av" data-expr>` and the layers are `<g class="NAME" data-part="NAME">` in a fixed order (`frame`, `ch` holding `back`, `body`, `headset`, `prop`, then `state`); `headset` (class `hd`) holds `head`, `hat`, `eyes-brows`, `mouth`, `fx` and `acc`, and `back` carries class `hd` too, so one rule turns the hair behind the head with the head about `PIVOTS.neck`; the prop group carries `data-prop`.
|
|
3913
3913
|
- `composeSvg` checks the spec again with `parseCharacter`, so a spec cast from untrusted data throws instead of reaching the markup. `uid` (`/^[a-z0-9]{1,16}$/`, default `a`) ends every clip path id, so each avatar on a page needs its own `uid`: two with the same one share clip path ids and one clips the other. The server-side renders pass an explicit one. `size` (an integer up to 4096) adds `width` and `height`, which `canvas` needs. `label` (at most 200 characters) becomes `aria-label` with `<>"'=()&` written as entities; without it the figure is `aria-hidden`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-roundtable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.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",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"pi-better-show": "0.5.0",
|
|
77
77
|
"pi-mcp-adapter": "5.3.0",
|
|
78
78
|
"pino": "10.4.0",
|
|
79
|
-
"typebox": "1.
|
|
79
|
+
"typebox": "1.4.6",
|
|
80
80
|
"unpdf": "1.8.1"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
.av .glow{opacity:.28}
|
|
6
6
|
.av .ch,.av .prop,.av .eyes,.av .ov{transform-box:view-box}
|
|
7
7
|
.av .ch{transform-origin:50px 94px}
|
|
8
|
-
.av .eyes{transform-origin:50px 52px;animation:av-blink 5.2s infinite}
|
|
8
|
+
.av .eyes{transform-origin:50px 52px;animation:av-blink 5.2s calc(var(--phase,0s)*1.7) infinite}
|
|
9
|
+
.av[data-expr=resting] .eyes{animation:none}
|
|
9
10
|
.av .o-wait,.av .o-done,.av .o-err{transform-origin:17px 19px}
|
|
10
11
|
.av .o-think{transform-origin:50px 50px}
|
|
11
12
|
.av [data-prop=staff]{transform-origin:73px 82px}
|
package/src/characters/css.ts
CHANGED
|
@@ -21,7 +21,8 @@ export function characterCss(): string {
|
|
|
21
21
|
.av .glow{opacity:.28}
|
|
22
22
|
.av .ch,.av .prop,.av .eyes,.av .ov{transform-box:view-box}
|
|
23
23
|
.av .ch{transform-origin:${PIVOTS.character}}
|
|
24
|
-
.av .eyes{transform-origin:${PIVOTS.eyes};animation:av-blink 5.2s infinite}
|
|
24
|
+
.av .eyes{transform-origin:${PIVOTS.eyes};animation:av-blink 5.2s calc(var(--phase,0s)*1.7) infinite}
|
|
25
|
+
.av[data-expr=resting] .eyes{animation:none}
|
|
25
26
|
.av .o-wait,.av .o-done,.av .o-err{transform-origin:${PIVOTS.badge}}
|
|
26
27
|
.av .o-think{transform-origin:${PIVOTS.orbit}}
|
|
27
28
|
${pivots}
|
|
@@ -157,6 +157,16 @@ const EXPRESSION_ROWS: Record<Expression, ExpressionRow> = {
|
|
|
157
157
|
mouth: "yawn",
|
|
158
158
|
fx: [],
|
|
159
159
|
},
|
|
160
|
+
// A calm face at rest, eyes shut and no yawn: the chat home draws an idle agent so, where
|
|
161
|
+
// `sleepy` is the dozing one.
|
|
162
|
+
resting: {
|
|
163
|
+
eye: "closed",
|
|
164
|
+
look: [0, 0],
|
|
165
|
+
bl: [0, 0],
|
|
166
|
+
br: [0, 0],
|
|
167
|
+
mouth: "smileS",
|
|
168
|
+
fx: [],
|
|
169
|
+
},
|
|
160
170
|
};
|
|
161
171
|
|
|
162
172
|
const f1 = (n: number): number => +n.toFixed(2);
|
|
@@ -3,7 +3,7 @@ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { SQL } from "bun";
|
|
6
|
-
import { discordKey } from "../contract/discord-key.ts";
|
|
6
|
+
import { discordIdOf, discordKey } from "../contract/discord-key.ts";
|
|
7
7
|
import type { PlaceProvider } from "../contract/places.ts";
|
|
8
8
|
import type { ChatSurface } from "../contract/surface.ts";
|
|
9
9
|
import { NO_ATTACHMENTS } from "../domain/attachment.ts";
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
discordTestPlaces,
|
|
34
34
|
testPlacePort,
|
|
35
35
|
} from "../testing/team-places.ts";
|
|
36
|
+
import type { Agent } from "./agent-rules.ts";
|
|
36
37
|
import { PgAgentStore as AgentStore } from "./agent-store.ts";
|
|
37
38
|
import {
|
|
38
39
|
AgentServerTeam as AgentTeam,
|
|
@@ -174,21 +175,32 @@ export const eventLog: string[] = [];
|
|
|
174
175
|
/** What a plugin adds to every agent's tools: a tool of its own and a group of another server's. */
|
|
175
176
|
const PLUGIN_SELECTION = { tools: ["memory_add"], groups: ["workspace"] };
|
|
176
177
|
|
|
178
|
+
/** Whether an action of the agent waits for the owner, in any of its places. */
|
|
179
|
+
function holdsAction(agent: Agent): boolean {
|
|
180
|
+
return places
|
|
181
|
+
.keysOf(agent.name)
|
|
182
|
+
.some((key) => runtime.held.has(places.scopeOf(agent, key).session));
|
|
183
|
+
}
|
|
184
|
+
|
|
177
185
|
/**
|
|
178
186
|
* Waits until every queued channel task has settled, every active agent has its avatar, which
|
|
179
|
-
* startup draws in the background, and every temp knight
|
|
180
|
-
*
|
|
181
|
-
*
|
|
187
|
+
* startup draws in the background, and every temp knight's stamp has caught up with its work (the
|
|
188
|
+
* stamp is written after the turn starts or ends, off the queue): finished, or still working
|
|
189
|
+
* while an action of it is held. A fixed sleep was too short on a slow runner.
|
|
182
190
|
*/
|
|
183
191
|
export async function settle(): Promise<void> {
|
|
184
192
|
const deadline = Date.now() + 10_000;
|
|
185
193
|
const quiet = () =>
|
|
186
194
|
queue.busy().length === 0 &&
|
|
187
195
|
store.agents().every((a) => a.status !== "active" || a.avatarHash) &&
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
196
|
+
store
|
|
197
|
+
.agents()
|
|
198
|
+
.every(
|
|
199
|
+
(a) =>
|
|
200
|
+
!a.parent ||
|
|
201
|
+
a.status !== "active" ||
|
|
202
|
+
(a.finishedAt === undefined) === holdsAction(a),
|
|
203
|
+
);
|
|
192
204
|
while (!quiet() && Date.now() < deadline) await Bun.sleep(5);
|
|
193
205
|
// Work the last task queued is still finishing.
|
|
194
206
|
await Bun.sleep(20);
|
|
@@ -281,9 +293,7 @@ export function useTeamFixture(
|
|
|
281
293
|
fails: (id) => channels.failing.has(id),
|
|
282
294
|
},
|
|
283
295
|
onRemoved: (listener) => removedListeners.push(listener),
|
|
284
|
-
nameOf: (id) =>
|
|
285
|
-
store.agentByChannel(id)?.name ??
|
|
286
|
-
store.groupByChannel(id)?.name,
|
|
296
|
+
nameOf: (id) => store.placeOwner(discordKey(id))?.name,
|
|
287
297
|
}),
|
|
288
298
|
]),
|
|
289
299
|
...stored,
|
|
@@ -371,7 +381,16 @@ export function useTeamFixture(
|
|
|
371
381
|
...(local
|
|
372
382
|
? {}
|
|
373
383
|
: {
|
|
374
|
-
formerChannelOps: () =>
|
|
384
|
+
formerChannelOps: () =>
|
|
385
|
+
discordTestChannelOps(channels, {
|
|
386
|
+
agent: (name) => store.agent(name),
|
|
387
|
+
group: (name) => store.group(name),
|
|
388
|
+
ownerOf: (id) => store.placeOwner(discordKey(id))?.name,
|
|
389
|
+
channelOf: (name) => {
|
|
390
|
+
const key = places.placeOn(name, "discord");
|
|
391
|
+
return key === undefined ? undefined : discordIdOf(key);
|
|
392
|
+
},
|
|
393
|
+
}),
|
|
375
394
|
}),
|
|
376
395
|
logger: silentLogger(),
|
|
377
396
|
});
|
|
@@ -10,11 +10,7 @@ import type { TurnSelection } from "../domain/sessions.ts";
|
|
|
10
10
|
import { type Speaker, THE_SPEAKER } from "../identity/speakers.ts";
|
|
11
11
|
import type { PromptVersion } from "../modules/prompts/prompt-history.ts";
|
|
12
12
|
import type { ResolvedSkill } from "../modules/skills/skill-rules.ts";
|
|
13
|
-
import {
|
|
14
|
-
type AgentOps,
|
|
15
|
-
type FormerChannelOps,
|
|
16
|
-
NO_CHANNELS,
|
|
17
|
-
} from "../plugin-api/agent-ops.ts";
|
|
13
|
+
import type { AgentOps, FormerChannelOps } from "../plugin-api/agent-ops.ts";
|
|
18
14
|
import type { AgentChange, AgentTeam } from "../plugin-api/services.ts";
|
|
19
15
|
import type { Agent } from "./agent-store.ts";
|
|
20
16
|
import {
|
|
@@ -36,7 +32,7 @@ import { teamSystemPrompt } from "./team-prompt.ts";
|
|
|
36
32
|
import { TeamRooms } from "./team-rooms.ts";
|
|
37
33
|
import { teamSelection } from "./team-selection.ts";
|
|
38
34
|
import { type TeamStatus, teamStatus } from "./team-status.ts";
|
|
39
|
-
import { agentDetails, teamListText } from "./team-text.ts";
|
|
35
|
+
import { agentDetails, NO_CHANNELS, teamListText } from "./team-text.ts";
|
|
40
36
|
import { TeamTurns } from "./team-turns.ts";
|
|
41
37
|
|
|
42
38
|
export type { AgentTeamOptions } from "./team-options.ts";
|
|
@@ -73,12 +73,14 @@ export class TeamPlaceWrites {
|
|
|
73
73
|
/**
|
|
74
74
|
* Makes the owner's place on one surface, or brings back the one it has there; for a temp
|
|
75
75
|
* knight, under its parent's place on that surface. None when the surface makes no places or the
|
|
76
|
-
* parent has none there.
|
|
76
|
+
* parent has none there. `stored.forget` leaves the place it has stored out, as one that is not
|
|
77
|
+
* the surface's own. Nothing is recorded.
|
|
77
78
|
*/
|
|
78
79
|
async makeOn(
|
|
79
80
|
surface: string,
|
|
80
81
|
wish: PlaceWish,
|
|
81
82
|
parent?: Agent,
|
|
83
|
+
stored: { forget: boolean } = { forget: false },
|
|
82
84
|
): Promise<MadePlace | undefined> {
|
|
83
85
|
const { places } = this.#ctx.options;
|
|
84
86
|
const provider = places.providerOf(surface);
|
|
@@ -93,7 +95,7 @@ export class TeamPlaceWrites {
|
|
|
93
95
|
spec.parent = above;
|
|
94
96
|
}
|
|
95
97
|
const existing = places.idOf(wish, provider.surface);
|
|
96
|
-
if (existing !== undefined) spec.existing = existing;
|
|
98
|
+
if (existing !== undefined && !stored.forget) spec.existing = existing;
|
|
97
99
|
return { surface, id: await provider.ensure(spec) };
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -106,8 +108,10 @@ export class TeamPlaceWrites {
|
|
|
106
108
|
|
|
107
109
|
/**
|
|
108
110
|
* Brings an owner's archived places back, each under its own id (a place deleted meanwhile is
|
|
109
|
-
* made again
|
|
110
|
-
* is
|
|
111
|
+
* made again, and so is one the provider finds foreign: another space's, such as a channel of a
|
|
112
|
+
* server the team left, which is left where it is), and makes one for an agent that had none on
|
|
113
|
+
* a surface that makes them; a group is given none it never had. A place that cannot be checked
|
|
114
|
+
* is taken as it is. Recorded by the caller.
|
|
111
115
|
*/
|
|
112
116
|
async bringBack(wish: PlaceWish): Promise<MadePlace[]> {
|
|
113
117
|
const { places } = this.#ctx.options;
|
|
@@ -118,12 +122,30 @@ export class TeamPlaceWrites {
|
|
|
118
122
|
places.idOf(wish, provider.surface) === undefined
|
|
119
123
|
)
|
|
120
124
|
continue;
|
|
121
|
-
const place = await this.makeOn(provider.surface, wish
|
|
125
|
+
const place = await this.makeOn(provider.surface, wish, undefined, {
|
|
126
|
+
forget: await this.#foreign(provider, wish),
|
|
127
|
+
});
|
|
122
128
|
if (place) made.push(place);
|
|
123
129
|
}
|
|
124
130
|
return made;
|
|
125
131
|
}
|
|
126
132
|
|
|
133
|
+
/** Whether the provider finds the place the owner has stored on its surface to be another space's. */
|
|
134
|
+
async #foreign(provider: PlaceProvider, wish: PlaceRef): Promise<boolean> {
|
|
135
|
+
const { places, logger } = this.#ctx.options;
|
|
136
|
+
const id = places.idOf(wish, provider.surface);
|
|
137
|
+
if (id === undefined || !provider.check) return false;
|
|
138
|
+
try {
|
|
139
|
+
return (await provider.check(id)) === "foreign";
|
|
140
|
+
} catch (error) {
|
|
141
|
+
logger.warn(
|
|
142
|
+
{ name: wish.name, surface: provider.surface, err: error },
|
|
143
|
+
"archived place not checked; taken as it is",
|
|
144
|
+
);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
127
149
|
/**
|
|
128
150
|
* Keeps an archived owner's places where nobody answers, with their history; says, for the
|
|
129
151
|
* archive tool's answer, what each provider did. A provider that fails is logged, and the rest
|
|
@@ -6,6 +6,10 @@ import { characterOf, isHelper } from "./agent-rules.ts";
|
|
|
6
6
|
import { describeThinking } from "./agent-settings.ts";
|
|
7
7
|
import type { Agent, AgentGroup } from "./agent-store.ts";
|
|
8
8
|
|
|
9
|
+
/** What `AgentOps.arrange` and `AgentOps.read` refuse with when the team has no Discord channels. */
|
|
10
|
+
export const NO_CHANNELS =
|
|
11
|
+
"This host has no Discord channels: the agents live in rooms of a chat surface, so there is nothing to arrange or read here.";
|
|
12
|
+
|
|
9
13
|
/** Every agent and group as agent_list shows them, before the category layout. */
|
|
10
14
|
export function teamListText(store: Pick<AgentDirectory, "agents" | "groups">) {
|
|
11
15
|
const all = store.agents();
|
|
@@ -150,12 +150,13 @@ export function agentServerPlugin(
|
|
|
150
150
|
...(legacySpace === undefined
|
|
151
151
|
? { clearChannels: true }
|
|
152
152
|
: { discordGuild: legacySpace }),
|
|
153
|
-
//
|
|
153
|
+
// Every surface's places follow their space: kept in it, dropped elsewhere. The legacy
|
|
154
|
+
// channels' follow their columns, and with no space all of a moved row's go.
|
|
154
155
|
places: [
|
|
155
|
-
|
|
156
|
-
surface: LEGACY_CHANNEL_SURFACE
|
|
157
|
-
|
|
158
|
-
},
|
|
156
|
+
...(legacySpace === undefined
|
|
157
|
+
? [{ surface: LEGACY_CHANNEL_SURFACE }]
|
|
158
|
+
: []),
|
|
159
|
+
...spaces.map(({ surface, space }) => ({ surface, keep: space })),
|
|
159
160
|
],
|
|
160
161
|
}),
|
|
161
162
|
// After the move, so the rows it brought in with their channel ids get their places at this boot.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rmSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { ENTRY_CHANNEL_WITHOUT_GUILD } from "../config/agent-team.ts";
|
|
3
4
|
import type { PeerBotsConfig } from "../config/peer-bots.ts";
|
|
4
5
|
import type {
|
|
5
6
|
ChannelContext,
|
|
@@ -7,7 +8,7 @@ import type {
|
|
|
7
8
|
} from "../contract/channel-context.ts";
|
|
8
9
|
import { type ServiceKey, serviceKey } from "../contract/services.ts";
|
|
9
10
|
import { discordAgentGuild } from "../discord/agent-guild.ts";
|
|
10
|
-
import { discordChannelOps } from "../discord/agent-tools.ts";
|
|
11
|
+
import { discordChannelOps, discordTeamReads } from "../discord/agent-tools.ts";
|
|
11
12
|
import { CardCopies } from "../discord/card-copies.ts";
|
|
12
13
|
import { ChannelContextReader } from "../discord/channel-context.ts";
|
|
13
14
|
import { CommandCollection } from "../discord/command-collection.ts";
|
|
@@ -83,7 +84,10 @@ export function discordFormerChannelOps(
|
|
|
83
84
|
connection &&
|
|
84
85
|
discordChannelOps({
|
|
85
86
|
channels: connection.agentChannels(guild),
|
|
86
|
-
directory: () =>
|
|
87
|
+
directory: () => {
|
|
88
|
+
const server = services.find(AGENTS);
|
|
89
|
+
return server && discordTeamReads(server);
|
|
90
|
+
},
|
|
87
91
|
logger,
|
|
88
92
|
})
|
|
89
93
|
);
|
|
@@ -151,9 +155,7 @@ const INTERCOM_KEEP = 300;
|
|
|
151
155
|
*/
|
|
152
156
|
export function discordPlugin(options: DiscordOptions): RoundtablePlugin {
|
|
153
157
|
if (options.entryChannel !== undefined && options.agentGuild === undefined)
|
|
154
|
-
throw new ConfigError(
|
|
155
|
-
"config discord.entryChannel: the coordinator's channel is in the agent guild, and discord.guild is left out, so the agents live in the app's rooms. Remove entryChannel and name the coordinator with coordinator, or add discord.guild.",
|
|
156
|
-
);
|
|
158
|
+
throw new ConfigError(ENTRY_CHANNEL_WITHOUT_GUILD);
|
|
157
159
|
const collection = new CommandCollection();
|
|
158
160
|
let surface: DiscordSurface | undefined;
|
|
159
161
|
return {
|
|
@@ -49,6 +49,10 @@ interface AgentGuildKeys {
|
|
|
49
49
|
agents?: readonly unknown[];
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** What `discord.entryChannel` without `discord.guild` is refused with, here and in the Discord plugin that takes the same option. */
|
|
53
|
+
export const ENTRY_CHANNEL_WITHOUT_GUILD =
|
|
54
|
+
"config discord.entryChannel: the coordinator's channel is in the agent guild, and discord.guild is left out, so the agents live in the app's rooms. Remove entryChannel and name the coordinator with coordinator, or add discord.guild.";
|
|
55
|
+
|
|
52
56
|
/**
|
|
53
57
|
* Whether the agent team lives in the Discord guild `discord.guild` names; refuses what that
|
|
54
58
|
* guild needs and lacks, and an entry channel without it. Without `discord.guild` the bot still
|
|
@@ -62,9 +66,7 @@ export function checkAgentGuild(
|
|
|
62
66
|
if (!discord) return false;
|
|
63
67
|
if (discord.guild === undefined) {
|
|
64
68
|
if (discord.entryChannel !== undefined)
|
|
65
|
-
throw new ConfigError(
|
|
66
|
-
"config discord.entryChannel: the coordinator's channel is in the agent guild, and discord.guild is left out, so the agents live in the app's rooms. Remove entryChannel and name the coordinator with coordinator, or add discord.guild.",
|
|
67
|
-
);
|
|
69
|
+
throw new ConfigError(ENTRY_CHANNEL_WITHOUT_GUILD);
|
|
68
70
|
if (agentServer && (config.agents?.length ?? 0) === 0)
|
|
69
71
|
throw new ConfigError(
|
|
70
72
|
"config discord.guild: left out, so the agents live in the app's rooms, and agents configures none. Add agents, add discord.guild for an agent server in Discord, or set agentServer: false for a host without agents.",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { IntercomCard } from "../domain/conversation.ts";
|
|
2
2
|
import type { InterimPosts } from "../domain/interim.ts";
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* One agent's message in a channel, posted under its name and avatar.
|
|
6
|
+
*/
|
|
5
7
|
export interface AgentPost {
|
|
6
8
|
name: string;
|
|
7
9
|
avatarUrl: string;
|
|
@@ -21,7 +23,9 @@ export interface AgentPost {
|
|
|
21
23
|
*/
|
|
22
24
|
export type AgentCategory = string;
|
|
23
25
|
|
|
24
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* A category of the agent server and its channels, in server order.
|
|
28
|
+
*/
|
|
25
29
|
export interface CategoryLayout {
|
|
26
30
|
/** Absent for a category still to be made. */
|
|
27
31
|
id?: string;
|
|
@@ -29,7 +33,9 @@ export interface CategoryLayout {
|
|
|
29
33
|
channelIds: string[];
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* A message of the agent server as `channel_read` returns it.
|
|
38
|
+
*/
|
|
33
39
|
export interface ChannelMessage {
|
|
34
40
|
id: string;
|
|
35
41
|
author: string;
|
|
@@ -91,7 +97,9 @@ export interface AgentChannels {
|
|
|
91
97
|
): Promise<ChannelMessage[]>;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* The dashboard channel's one pinned message, made when missing and edited in place.
|
|
102
|
+
*/
|
|
95
103
|
export interface DashboardBoard {
|
|
96
104
|
show(sections: string[]): Promise<void>;
|
|
97
105
|
}
|
|
@@ -49,9 +49,28 @@ export interface PlaceSpec extends PlaceRef {
|
|
|
49
49
|
/** What `check` finds of a stored place at start. */
|
|
50
50
|
export type PlaceCheck = "ok" | "gone" | "foreign";
|
|
51
51
|
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* An argument a provider adds to a creation tool: a Typebox schema, with its description in the
|
|
54
|
+
* schema. Only a string value the model gives reaches `ensure` (as `hints`), so give a string schema.
|
|
55
|
+
*/
|
|
53
56
|
export type ToolArgument = TSchema;
|
|
54
57
|
|
|
58
|
+
/** The arguments `agent_create` and `group_create` take of their own, which no provider's `createArguments` may reuse. */
|
|
59
|
+
export const CREATION_TOOL_ARGUMENTS = {
|
|
60
|
+
agent: [
|
|
61
|
+
"name",
|
|
62
|
+
"display_name",
|
|
63
|
+
"prompt",
|
|
64
|
+
"class",
|
|
65
|
+
"color",
|
|
66
|
+
"task",
|
|
67
|
+
"group",
|
|
68
|
+
"long_running",
|
|
69
|
+
"skills",
|
|
70
|
+
],
|
|
71
|
+
group: ["name", "display_name", "members", "host", "group"],
|
|
72
|
+
} as const;
|
|
73
|
+
|
|
55
74
|
/**
|
|
56
75
|
* What a chat surface holds of the team's places: where an agent or group is spoken to on it.
|
|
57
76
|
* The members a minimal provider needs are `surface`, `storage`, `key`, `placeOf` and `post`; the
|
package/src/core/db/team-move.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface TeamMoveOptions {
|
|
|
20
20
|
* The surfaces whose stored places name something of the space the team lived in, such as the
|
|
21
21
|
* channels of a Discord guild. A place row moved from a former id other than `keep` is dropped, as
|
|
22
22
|
* the legacy channel ids are cleared, so start makes new places; without `keep` every moved row
|
|
23
|
-
* is dropped. With `clearChannels` the team's own rows of
|
|
23
|
+
* is dropped. With `clearChannels` the team's own rows of the surfaces without `keep` go too.
|
|
24
24
|
*/
|
|
25
25
|
places?: readonly { surface: string; keep?: string }[];
|
|
26
26
|
}
|
|
@@ -75,7 +75,7 @@ export function moveTeam(options: TeamMoveOptions): Migration {
|
|
|
75
75
|
);
|
|
76
76
|
if (table === PLACES_TABLE)
|
|
77
77
|
for (const { surface, keep } of options.places ?? []) {
|
|
78
|
-
if (options.clearChannels)
|
|
78
|
+
if (options.clearChannels && keep === undefined)
|
|
79
79
|
await tx.unsafe(
|
|
80
80
|
`DELETE FROM "${table}" WHERE ${scope} = $1 AND surface = $2`,
|
|
81
81
|
[options.to, surface],
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
TeamStatus,
|
|
6
6
|
} from "../agents/agent-team.ts";
|
|
7
7
|
import type { DashboardBoard } from "../contract/agent-channels.ts";
|
|
8
|
+
import { discordIdOf } from "../contract/discord-key.ts";
|
|
8
9
|
import { thinkingLabel } from "../domain/models.ts";
|
|
9
10
|
import { messages } from "../i18n/index.ts";
|
|
10
11
|
import type { Logger } from "../kernel/log.ts";
|
|
@@ -17,6 +18,22 @@ const DASHBOARD_REFRESH_MS = 5 * 60_000;
|
|
|
17
18
|
/** Components V2 allows 4000 characters of text per message. */
|
|
18
19
|
const TEXT_BUDGET = 3_800;
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The Discord channel a status names, from its places; the deprecated `channelId` answers only for
|
|
23
|
+
* a status written before places were providers, which has none.
|
|
24
|
+
*/
|
|
25
|
+
function discordChannelOf(status: {
|
|
26
|
+
places?: AgentStatus["places"];
|
|
27
|
+
channelId?: string;
|
|
28
|
+
}): string | undefined {
|
|
29
|
+
if (!status.places) return status.channelId;
|
|
30
|
+
for (const place of status.places) {
|
|
31
|
+
const id = discordIdOf(place.key);
|
|
32
|
+
if (id !== undefined) return id;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
20
37
|
/** Configured local time, with the month and day when it is not today's. */
|
|
21
38
|
function when(at: Date, now: Date): string {
|
|
22
39
|
const date = zonedDate(at);
|
|
@@ -50,7 +67,8 @@ function agentBlock(
|
|
|
50
67
|
now: Date,
|
|
51
68
|
helpers: readonly AgentStatus[],
|
|
52
69
|
): string {
|
|
53
|
-
const
|
|
70
|
+
const channelId = discordChannelOf(agent);
|
|
71
|
+
const channel = channelId ? ` <#${channelId}>` : "";
|
|
54
72
|
const text = messages();
|
|
55
73
|
const last = agent.lastActive
|
|
56
74
|
? text.dashLastActive(when(agent.lastActive, now))
|
|
@@ -74,12 +92,13 @@ function agentBlock(
|
|
|
74
92
|
|
|
75
93
|
function groupBlock(group: GroupStatus, now: Date): string {
|
|
76
94
|
const text = messages();
|
|
95
|
+
const channelId = discordChannelOf(group);
|
|
77
96
|
const state = group.busy > 0 ? text.dashGroupBusy(group.busy) : text.dashIdle;
|
|
78
97
|
const last = group.lastActive
|
|
79
98
|
? text.dashLastActive(when(group.lastActive, now))
|
|
80
99
|
: text.dashNotActive;
|
|
81
100
|
return [
|
|
82
|
-
`**${group.displayName}**${
|
|
101
|
+
`**${group.displayName}**${channelId ? ` <#${channelId}>` : ""}`,
|
|
83
102
|
text.dashGroupMembers(group.members, group.host),
|
|
84
103
|
state,
|
|
85
104
|
`-# ${last}`,
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Client } from "discord.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Contribution,
|
|
4
|
+
EventHandlers,
|
|
5
|
+
PluginContext,
|
|
6
|
+
} from "../plugin-api/plugin.ts";
|
|
3
7
|
import { AGENTS } from "../plugin-api/services.ts";
|
|
4
8
|
import { agentDashboardContribution } from "./agent-dashboard-service.ts";
|
|
5
9
|
import { discordPlaces } from "./agent-places.ts";
|
|
6
|
-
import { discordAgentTools,
|
|
10
|
+
import { discordAgentTools, discordTeamReads } from "./agent-tools.ts";
|
|
7
11
|
import type { DiscordConnection } from "./connection.ts";
|
|
8
12
|
|
|
9
13
|
export interface DiscordAgentGuildOptions {
|
|
@@ -25,6 +29,13 @@ export interface DiscordAgentGuildOptions {
|
|
|
25
29
|
* names no coordinator in its configuration.
|
|
26
30
|
*/
|
|
27
31
|
entryChannel?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The services and event handlers the plugin contributes itself. Spreading the result puts
|
|
34
|
+
* `services` and `events` in place of the plugin's own, so give them here: the services follow
|
|
35
|
+
* the dashboard's, and a handler of an event the dashboard also hears runs after it, and runs
|
|
36
|
+
* even when the dashboard's throws.
|
|
37
|
+
*/
|
|
38
|
+
own?: Pick<Contribution, "services" | "events">;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
/** Discord's side of the agent guild, as a plugin's setup returns it. */
|
|
@@ -44,7 +55,8 @@ export type DiscordAgentGuild = Required<
|
|
|
44
55
|
* with the agents' and groups' names.
|
|
45
56
|
* - `tools`: `channel_arrange` and `channel_read`, which an agent's turn carries.
|
|
46
57
|
* - `services` and `events`: the `#dashboard` message, started once the agent server's team is
|
|
47
|
-
* ready. A plugin with services or event handlers of its own
|
|
58
|
+
* ready. A plugin with services or event handlers of its own gives them as `own`, and the result
|
|
59
|
+
* merges them with these.
|
|
48
60
|
*
|
|
49
61
|
* It reads the team through `AGENTS` when a tool runs or the dashboard updates, never during
|
|
50
62
|
* setup, so the plugin may be set up before the agent server.
|
|
@@ -56,7 +68,10 @@ export function discordAgentGuild(
|
|
|
56
68
|
const { guild, connection } = options;
|
|
57
69
|
const { services, logger } = context;
|
|
58
70
|
const channels = connection.agentChannels(guild);
|
|
59
|
-
const directory = () =>
|
|
71
|
+
const directory = () => {
|
|
72
|
+
const server = services.find(AGENTS);
|
|
73
|
+
return server && discordTeamReads(server);
|
|
74
|
+
};
|
|
60
75
|
const dashboard = agentDashboardContribution({
|
|
61
76
|
board: connection.agentDashboard(guild),
|
|
62
77
|
agents: () => services.find(AGENTS)?.team,
|
|
@@ -73,15 +88,54 @@ export function discordAgentGuild(
|
|
|
73
88
|
guild,
|
|
74
89
|
channels,
|
|
75
90
|
onRemoved: (listener) => connection.onChannelDeleted(listener),
|
|
76
|
-
nameOf: (channelId) =>
|
|
77
|
-
const found = directory();
|
|
78
|
-
return found ? ownerNameOf(found)(channelId) : undefined;
|
|
79
|
-
},
|
|
91
|
+
nameOf: (channelId) => directory()?.ownerOf(channelId),
|
|
80
92
|
logger,
|
|
81
93
|
}),
|
|
82
94
|
],
|
|
83
95
|
tools: discordAgentTools({ channels, directory, logger }),
|
|
84
|
-
services: dashboard.services ?? [],
|
|
85
|
-
events:
|
|
96
|
+
services: [...(dashboard.services ?? []), ...(options.own?.services ?? [])],
|
|
97
|
+
events: mergedEvents(
|
|
98
|
+
dashboard.events ?? {},
|
|
99
|
+
options.own?.events ?? {},
|
|
100
|
+
logger,
|
|
101
|
+
),
|
|
86
102
|
};
|
|
87
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Handlers of both sets under one event name each: those of an event both hear run in order, each
|
|
107
|
+
* even when one before it throws. The first error is the one raised, as the bus logs it; the later
|
|
108
|
+
* ones are logged here, or they would be lost.
|
|
109
|
+
*/
|
|
110
|
+
function mergedEvents(
|
|
111
|
+
first: EventHandlers,
|
|
112
|
+
second: EventHandlers,
|
|
113
|
+
logger: Pick<PluginContext["logger"], "error">,
|
|
114
|
+
): EventHandlers {
|
|
115
|
+
const merged: Record<string, (...args: unknown[]) => Promise<void>> = {};
|
|
116
|
+
const names = new Set([...Object.keys(first), ...Object.keys(second)]);
|
|
117
|
+
for (const name of names) {
|
|
118
|
+
const handlers = [first, second].flatMap((set) => {
|
|
119
|
+
const handler = (set as Record<string, unknown>)[name] as
|
|
120
|
+
| ((...args: unknown[]) => Promise<void> | void)
|
|
121
|
+
| undefined;
|
|
122
|
+
return handler ? [{ set, handler }] : [];
|
|
123
|
+
});
|
|
124
|
+
merged[name] = async (...args) => {
|
|
125
|
+
const failures: unknown[] = [];
|
|
126
|
+
for (const { set, handler } of handlers)
|
|
127
|
+
try {
|
|
128
|
+
await handler.apply(set, args);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
failures.push(error);
|
|
131
|
+
}
|
|
132
|
+
for (const error of failures.slice(1))
|
|
133
|
+
logger.error(
|
|
134
|
+
{ err: error, event: name },
|
|
135
|
+
"a later handler of the event failed",
|
|
136
|
+
);
|
|
137
|
+
if (failures.length > 0) throw failures[0];
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return merged as EventHandlers;
|
|
141
|
+
}
|
|
@@ -2,7 +2,10 @@ import type { CategoryLayout } from "../contract/agent-channels.ts";
|
|
|
2
2
|
import { AgentError } from "../domain/errors.ts";
|
|
3
3
|
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
4
4
|
|
|
5
|
-
type TeamStore = Pick<AgentDirectory, "agent" | "group"
|
|
5
|
+
type TeamStore = Pick<AgentDirectory, "agent" | "group"> & {
|
|
6
|
+
/** The Discord channel of an agent or group; undefined when it has none. */
|
|
7
|
+
channelOf(name: string): string | undefined;
|
|
8
|
+
};
|
|
6
9
|
|
|
7
10
|
/** The two kinds of team category (spec behavior 56). */
|
|
8
11
|
export type CategoryKind = "Agents" | "Groups";
|
|
@@ -75,8 +78,9 @@ export function resolveArrangement(
|
|
|
75
78
|
if (target.status !== "active")
|
|
76
79
|
throw new AgentError(`"${name}" is archived.`);
|
|
77
80
|
teamCategory(category, agent ? "Agents" : "Groups");
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
const channelId = store.channelOf(name);
|
|
82
|
+
if (!channelId) throw new AgentError(`${name} has no channel.`);
|
|
83
|
+
return channelId;
|
|
80
84
|
});
|
|
81
85
|
return { category, channelIds };
|
|
82
86
|
});
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
AgentChannels,
|
|
4
4
|
ChannelMessage,
|
|
5
5
|
} from "../contract/agent-channels.ts";
|
|
6
|
+
import { discordIdOf, discordKey } from "../contract/discord-key.ts";
|
|
6
7
|
import { AgentError } from "../domain/errors.ts";
|
|
7
8
|
import { messages } from "../i18n/index.ts";
|
|
8
9
|
import { ownerWords } from "../identity/owner-identity.ts";
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
type ToolContribution,
|
|
16
17
|
ToolRefusal,
|
|
17
18
|
} from "../plugin-api/define.ts";
|
|
18
|
-
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
19
|
+
import type { AgentDirectory, AgentServer } from "../plugin-api/services.ts";
|
|
19
20
|
import {
|
|
20
21
|
categoryLayoutText,
|
|
21
22
|
planArrangement,
|
|
@@ -44,24 +45,50 @@ export function channelIdFromRef(channel: string): string {
|
|
|
44
45
|
return id;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
/**
|
|
49
|
+
* What the Discord tools read of the team: the agents and groups by name, and which one a Discord
|
|
50
|
+
* channel is the place of, either way.
|
|
51
|
+
*/
|
|
52
|
+
export interface DiscordTeamReads
|
|
53
|
+
extends Pick<AgentDirectory, "agent" | "group"> {
|
|
54
|
+
/** The name of the agent or group whose place the Discord channel is, whatever its status. */
|
|
55
|
+
ownerOf(channelId: string): string | undefined;
|
|
56
|
+
/** The Discord channel of an agent or group; undefined when it has none. */
|
|
57
|
+
channelOf(name: string): string | undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The tools' reads over what the agent server builds. They go through the places: `placeOwner`
|
|
62
|
+
* and `placesOf`, and the deprecated Discord-only members (`agentByChannel`, `channelId`) only for
|
|
63
|
+
* a server written before places were providers, which has neither.
|
|
64
|
+
*/
|
|
65
|
+
export function discordTeamReads(
|
|
66
|
+
server: Pick<AgentServer, "team" | "directory">,
|
|
67
|
+
): DiscordTeamReads {
|
|
68
|
+
const { team, directory } = server;
|
|
69
|
+
return {
|
|
70
|
+
agent: (name) => directory.agent(name),
|
|
71
|
+
group: (name) => directory.group(name),
|
|
72
|
+
ownerOf: (id) =>
|
|
73
|
+
directory.placeOwner
|
|
74
|
+
? directory.placeOwner(discordKey(id))?.name
|
|
75
|
+
: (directory.agentByChannel(id)?.name ??
|
|
76
|
+
directory.groupByChannel(id)?.name),
|
|
77
|
+
channelOf: (name) =>
|
|
78
|
+
team.placesOf
|
|
79
|
+
? team
|
|
80
|
+
.placesOf(name)
|
|
81
|
+
.map((place) => discordIdOf(place.key))
|
|
82
|
+
.find((id) => id !== undefined)
|
|
83
|
+
: (directory.agent(name) ?? directory.group(name))?.channelId,
|
|
84
|
+
};
|
|
53
85
|
}
|
|
54
86
|
|
|
55
87
|
export interface DiscordAgentToolsOptions {
|
|
56
88
|
/** The agent guild's channels, which the tools list, arrange and read. */
|
|
57
89
|
channels: Pick<AgentChannels, "layout" | "arrange" | "read">;
|
|
58
90
|
/** The team's agents and groups, read when a tool runs; undefined on a host whose agent server is off. */
|
|
59
|
-
directory: () =>
|
|
60
|
-
| Pick<
|
|
61
|
-
AgentDirectory,
|
|
62
|
-
"agent" | "group" | "agentByChannel" | "groupByChannel"
|
|
63
|
-
>
|
|
64
|
-
| undefined;
|
|
91
|
+
directory: () => DiscordTeamReads | undefined;
|
|
65
92
|
logger: Logger;
|
|
66
93
|
}
|
|
67
94
|
|
|
@@ -127,7 +154,7 @@ export function discordChannelOps(
|
|
|
127
154
|
remove.length > 0
|
|
128
155
|
? ` ${remove.length} empty team categories were deleted.`
|
|
129
156
|
: "";
|
|
130
|
-
return `Arranged the channels.${removed}\n\n${categoryLayoutText(await channels.layout(),
|
|
157
|
+
return `Arranged the channels.${removed}\n\n${categoryLayoutText(await channels.layout(), team.ownerOf)}`;
|
|
131
158
|
},
|
|
132
159
|
read: async (channel, around, limit) => {
|
|
133
160
|
const id = channelIdFromRef(channel);
|
|
@@ -350,6 +350,8 @@ export function parseChannelTool(
|
|
|
350
350
|
const after = parsed.afterDate && Date.parse(String(parsed.afterDate));
|
|
351
351
|
const before = parsed.beforeDate && Date.parse(String(parsed.beforeDate));
|
|
352
352
|
for (const date of [after, before]) {
|
|
353
|
+
if (Number.isNaN(date))
|
|
354
|
+
throw new ChannelToolError("INVALID_CHANNEL_ARGUMENTS");
|
|
353
355
|
if (typeof date === "number" && date < DISCORD_EPOCH)
|
|
354
356
|
throw new ChannelToolError("INVALID_CHANNEL_DATE_RANGE");
|
|
355
357
|
}
|
|
@@ -11,10 +11,6 @@ import type { AgentTurnScope } from "../domain/ports.ts";
|
|
|
11
11
|
*/
|
|
12
12
|
export type FormerChannelOps = Pick<AgentOps, "arrange" | "read">;
|
|
13
13
|
|
|
14
|
-
/** What `AgentOps.arrange` and `AgentOps.read` refuse with when the team has no Discord channels. */
|
|
15
|
-
export const NO_CHANNELS =
|
|
16
|
-
"This host has no Discord channels: the agents live in rooms of a chat surface, so there is nothing to arrange or read here.";
|
|
17
|
-
|
|
18
14
|
/**
|
|
19
15
|
* What the agent tools do; the agent team implements it. Each returns text for the model.
|
|
20
16
|
* `arrange`, `read`, and the `category` of `create` and `createGroup` are what 0.45 had: the
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
CREATION_TOOL_ARGUMENTS,
|
|
3
|
+
type PlaceProvider,
|
|
4
|
+
} from "../contract/places.ts";
|
|
2
5
|
import type { ChatSurface } from "../contract/surface.ts";
|
|
3
6
|
import { PluginError } from "../kernel/errors.ts";
|
|
4
7
|
|
|
@@ -8,6 +11,11 @@ import { PluginError } from "../kernel/errors.ts";
|
|
|
8
11
|
*/
|
|
9
12
|
export class PlaceClaims {
|
|
10
13
|
readonly #owners = new Map<string, string>();
|
|
14
|
+
/** The plugin that added each creation-tool argument, by tool. */
|
|
15
|
+
readonly #arguments = {
|
|
16
|
+
agent: new Map<string, string>(),
|
|
17
|
+
group: new Map<string, string>(),
|
|
18
|
+
};
|
|
11
19
|
|
|
12
20
|
claim(plugin: string, provider: PlaceProvider): void {
|
|
13
21
|
const { surface } = provider;
|
|
@@ -29,9 +37,31 @@ export class PlaceClaims {
|
|
|
29
37
|
throw new PluginError(
|
|
30
38
|
`plugin ${plugin}: surface ${surface} already has the place provider of plugin ${other}. Keep one provider per surface.`,
|
|
31
39
|
);
|
|
40
|
+
this.#claimArguments(plugin, provider);
|
|
32
41
|
this.#owners.set(surface, plugin);
|
|
33
42
|
}
|
|
34
43
|
|
|
44
|
+
/** Refuses an argument a provider adds to a creation tool that the tool takes itself or another provider adds. */
|
|
45
|
+
#claimArguments(plugin: string, provider: PlaceProvider): void {
|
|
46
|
+
for (const tool of ["agent", "group"] as const) {
|
|
47
|
+
const added = this.#arguments[tool];
|
|
48
|
+
const own: readonly string[] = CREATION_TOOL_ARGUMENTS[tool];
|
|
49
|
+
for (const name of Object.keys(provider.createArguments?.[tool] ?? {})) {
|
|
50
|
+
const where = `plugin ${plugin}: the place provider of surface ${provider.surface} adds the argument ${name} to ${tool}_create`;
|
|
51
|
+
if (own.includes(name))
|
|
52
|
+
throw new PluginError(
|
|
53
|
+
`${where}, which the tool takes itself. Name it otherwise.`,
|
|
54
|
+
);
|
|
55
|
+
const other = added.get(name);
|
|
56
|
+
if (other !== undefined)
|
|
57
|
+
throw new PluginError(
|
|
58
|
+
`${where}, which the place provider of plugin ${other} adds already. Name it otherwise.`,
|
|
59
|
+
);
|
|
60
|
+
added.set(name, plugin);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
35
65
|
/** Refuses a provider whose surface no plugin registered, once every plugin is set up. */
|
|
36
66
|
check(surfaces: readonly ChatSurface[]): void {
|
|
37
67
|
for (const [surface, plugin] of this.#owners)
|
|
@@ -5,7 +5,7 @@ import type { PlacePort, PlaceProvider } from "../contract/places.ts";
|
|
|
5
5
|
import type { SurfacePort } from "../contract/surface.ts";
|
|
6
6
|
import { discordPlaces } from "../discord/agent-places.ts";
|
|
7
7
|
import {
|
|
8
|
-
type
|
|
8
|
+
type DiscordTeamReads,
|
|
9
9
|
discordChannelOps,
|
|
10
10
|
} from "../discord/agent-tools.ts";
|
|
11
11
|
import {
|
|
@@ -100,9 +100,7 @@ export function discordTestPlaces(
|
|
|
100
100
|
/** Discord's side of the team's deprecated `arrange` and `read`, as a host hands it with a guild. */
|
|
101
101
|
export function discordTestChannelOps(
|
|
102
102
|
channels: AgentChannels,
|
|
103
|
-
directory:
|
|
104
|
-
? NonNullable<D>
|
|
105
|
-
: never,
|
|
103
|
+
directory: DiscordTeamReads,
|
|
106
104
|
): FormerChannelOps {
|
|
107
105
|
return discordChannelOps({
|
|
108
106
|
channels,
|
package/src/kit/support.ts
CHANGED
|
@@ -5,16 +5,30 @@ export type {
|
|
|
5
5
|
AgentTurnRunner,
|
|
6
6
|
} from "../core/agents/agent-ports.ts";
|
|
7
7
|
export type { Backlog, GroupMessage } from "../core/agents/agent-rules.ts";
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
|
|
9
|
+
// Deprecated here, removed from `pi-roundtable/kit` in 1.0: Discord's agent guild internals, which
|
|
10
|
+
// `pi-roundtable/discord` exports then (an entry holds a name once until 1.0). The aliases carry
|
|
11
|
+
// the tag, so the same types stay unmarked where `pi-roundtable/discord` hands them out.
|
|
12
|
+
import type * as AgentChannelTypes from "../core/contract/agent-channels.ts";
|
|
13
|
+
|
|
14
|
+
/** @deprecated Since 0.46 a Discord internal: its export from `pi-roundtable/kit` goes away in 1.0, and `pi-roundtable/discord` exports it then. */
|
|
15
|
+
export type AgentCategory = AgentChannelTypes.AgentCategory;
|
|
16
|
+
|
|
17
|
+
/** @deprecated Since 0.46 a Discord internal: its export from `pi-roundtable/kit` goes away in 1.0, and `pi-roundtable/discord` exports it then. */
|
|
18
|
+
export type AgentChannels = AgentChannelTypes.AgentChannels;
|
|
19
|
+
|
|
20
|
+
/** @deprecated Since 0.46 a Discord internal: its export from `pi-roundtable/kit` goes away in 1.0, and `pi-roundtable/discord` exports it then. */
|
|
21
|
+
export type AgentPost = AgentChannelTypes.AgentPost;
|
|
22
|
+
|
|
23
|
+
/** @deprecated Since 0.46 a Discord internal: its export from `pi-roundtable/kit` goes away in 1.0, and `pi-roundtable/discord` exports it then. */
|
|
24
|
+
export type CategoryLayout = AgentChannelTypes.CategoryLayout;
|
|
25
|
+
|
|
26
|
+
/** @deprecated Since 0.46 a Discord internal: its export from `pi-roundtable/kit` goes away in 1.0, and `pi-roundtable/discord` exports it then. */
|
|
27
|
+
export type ChannelMessage = AgentChannelTypes.ChannelMessage;
|
|
28
|
+
|
|
29
|
+
/** @deprecated Since 0.46 a Discord internal: its export from `pi-roundtable/kit` goes away in 1.0, and `pi-roundtable/discord` exports it then. */
|
|
30
|
+
export type DashboardBoard = AgentChannelTypes.DashboardBoard;
|
|
31
|
+
|
|
18
32
|
export type {
|
|
19
33
|
EffortPolicy,
|
|
20
34
|
EffortRequest,
|