pi-roundtable 0.45.2 → 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 +56 -0
- package/docs/plugins.md +33 -8
- package/package.json +2 -2
- package/src/characters/catalog.ts +1 -0
- package/src/characters/characters.css +2 -1
- package/src/characters/compose.ts +7 -3
- package/src/characters/css.ts +2 -1
- package/src/characters/index.ts +1 -0
- package/src/characters/parts-face.ts +14 -1
- package/src/core/agents/agent-claim.ts +2 -2
- package/src/core/agents/agent-group-store.ts +74 -1
- package/src/core/agents/agent-places.ts +32 -0
- package/src/core/agents/agent-ports.ts +0 -94
- package/src/core/agents/agent-prompt.ts +3 -1
- package/src/core/agents/agent-team-fixture.ts +74 -14
- package/src/core/agents/agent-team.ts +50 -59
- package/src/core/agents/agent-tools.ts +34 -166
- package/src/core/agents/message-target.ts +3 -2
- package/src/core/agents/routes.ts +2 -1
- package/src/core/agents/team-editing.ts +121 -150
- package/src/core/agents/team-helpers.ts +80 -59
- package/src/core/agents/team-keys.ts +16 -26
- package/src/core/agents/team-lifecycle.ts +155 -99
- package/src/core/agents/team-looks.ts +102 -0
- package/src/core/agents/team-options.ts +12 -11
- package/src/core/agents/team-place-writes.ts +215 -0
- package/src/core/agents/team-places.ts +30 -0
- package/src/core/agents/team-posts.ts +42 -73
- package/src/core/agents/team-selection.ts +10 -2
- package/src/core/agents/team-status.ts +3 -2
- package/src/core/agents/team-text.ts +14 -43
- package/src/core/agents/team-turn-types.ts +11 -16
- package/src/core/agents/team-turns.ts +7 -6
- package/src/core/builtin/agent-server-options.ts +27 -6
- package/src/core/builtin/agent-server.ts +69 -72
- package/src/core/builtin/discord.ts +60 -8
- package/src/core/builtin/modules.ts +2 -0
- package/src/core/config/agent-team.ts +5 -3
- package/src/core/contract/agent-channels.ts +105 -0
- package/src/core/contract/channels.ts +10 -4
- package/src/core/contract/discord-key.ts +15 -0
- package/src/core/contract/places.ts +28 -3
- package/src/core/db/legacy-channels.ts +31 -0
- package/src/core/db/team-move.ts +2 -2
- package/src/core/discord/agent-dashboard-service.ts +55 -0
- package/src/core/{agents → discord}/agent-dashboard.ts +28 -4
- package/src/core/discord/agent-discord.ts +1 -1
- package/src/core/discord/agent-guild.ts +141 -0
- package/src/core/{agents/team-layout.ts → discord/agent-layout.ts} +15 -31
- package/src/core/discord/agent-places.ts +52 -33
- package/src/core/discord/agent-tools.ts +237 -0
- package/src/core/discord/channel-operations.ts +2 -0
- package/src/core/discord/connection.ts +4 -1
- package/src/core/discord/discord-surface.ts +9 -14
- package/src/core/discord/place-fake-client.ts +59 -0
- package/src/core/host/define-roundtable.ts +7 -5
- package/src/core/modules/delegation/delegator.ts +5 -0
- package/src/core/plugin-api/agent-ops.ts +119 -0
- package/src/core/plugin-api/agent-server-ids.ts +9 -0
- package/src/core/plugin-api/define.ts +9 -0
- package/src/core/plugin-api/plugin.ts +2 -0
- package/src/core/plugin-api/services.ts +6 -0
- package/src/core/registry/contributions.ts +3 -0
- package/src/core/registry/places.ts +31 -1
- package/src/core/routing/channel-queue.ts +28 -12
- package/src/core/runtime/pi-agent-runtime.ts +1 -1
- package/src/core/runtime/runtime-plugin.ts +1 -0
- package/src/core/runtime/runtime-types.ts +6 -0
- package/src/core/{agents/agent-team-fake-channels.ts → testing/fake-agent-channels.ts} +5 -1
- package/src/core/testing/fake-pager-places.ts +16 -2
- package/src/core/testing/modules.ts +2 -1
- package/src/core/testing/place-contract.ts +3 -2
- package/src/core/testing/team-places.ts +73 -7
- package/src/core/testing/test-host.ts +20 -16
- package/src/discord/index.ts +5 -0
- package/src/kit/channels.ts +1 -2
- package/src/kit/support.ts +25 -7
- package/templates/adapters/web/package.json.tmpl +1 -1
- package/templates/package.json.tmpl +1 -1
|
@@ -4,6 +4,8 @@ import type { ResolvedRouting } from "../config/routing.ts";
|
|
|
4
4
|
import type { ModelRef } from "../domain/models.ts";
|
|
5
5
|
import type { OwnerIdentity } from "../identity/owner-identity.ts";
|
|
6
6
|
import type { ErrorReporter } from "../ops/error-reporter.ts";
|
|
7
|
+
import type { FormerChannelOps } from "../plugin-api/agent-ops.ts";
|
|
8
|
+
import type { PluginContext } from "../plugin-api/plugin.ts";
|
|
7
9
|
import type { AgentSessionsSlot } from "../runtime/runtime-plugin.ts";
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -14,9 +16,16 @@ export const LOCAL_TEAM_ID = "local";
|
|
|
14
16
|
|
|
15
17
|
export interface AgentServerOptions {
|
|
16
18
|
/**
|
|
17
|
-
* The
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* The spaces whose stored places the team lives in, by surface, such as a Discord guild: the
|
|
20
|
+
* rows moved from a former team id keep their places only in these, and a host with none has
|
|
21
|
+
* its agents in the rooms of the surfaces that host them. Each surface's place provider must be
|
|
22
|
+
* contributed by a plugin, or the host refuses to start.
|
|
23
|
+
*/
|
|
24
|
+
placeSpaces?: readonly { surface: string; space: string }[];
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated The Discord guild the team's channels live in: give it as a `placeSpaces` entry
|
|
27
|
+
* of the legacy channel surface, and the Discord plugin the entry channel. Without `teamId` the
|
|
28
|
+
* team is stored under it. Removed in 1.0.
|
|
20
29
|
*/
|
|
21
30
|
guildId?: string;
|
|
22
31
|
/**
|
|
@@ -30,11 +39,15 @@ export interface AgentServerOptions {
|
|
|
30
39
|
* ids they carried.
|
|
31
40
|
*/
|
|
32
41
|
formerTeamIds?: readonly string[];
|
|
33
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated The channel the coordinator lives in, a Discord channel of `guildId`: the Discord
|
|
44
|
+
* plugin's `entryChannel` gives it through its place provider. Never set with `coordinator`.
|
|
45
|
+
* Removed in 1.0.
|
|
46
|
+
*/
|
|
34
47
|
entryChannelId?: string;
|
|
35
48
|
/**
|
|
36
|
-
* The coordinator's name on a host
|
|
37
|
-
* seed when absent. Refused with `entryChannelId`.
|
|
49
|
+
* The coordinator's name on a host where no place provider names one (Discord's entry channel);
|
|
50
|
+
* the first seed when absent. Refused with `entryChannelId`.
|
|
38
51
|
*/
|
|
39
52
|
coordinator?: string;
|
|
40
53
|
owner: OwnerIdentity & { id: string };
|
|
@@ -98,4 +111,12 @@ export interface AgentServerOptions {
|
|
|
98
111
|
routing?: ResolvedRouting;
|
|
99
112
|
/** The temp knights' limits; `false` leaves `helper_create` and `helper_end` out. Without it the defaults apply. */
|
|
100
113
|
helpers?: ResolvedHelpers | false;
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated What `AgentOps.arrange` and `AgentOps.read` run while they stay: the side of the
|
|
116
|
+
* surface whose own tools took their place, read at each call from the host's services.
|
|
117
|
+
* Without it, or when it answers undefined, the two refuse. Removed in 1.0.
|
|
118
|
+
*/
|
|
119
|
+
formerChannelOps?: (
|
|
120
|
+
context: Pick<PluginContext, "services" | "logger">,
|
|
121
|
+
) => FormerChannelOps | undefined;
|
|
101
122
|
}
|
|
@@ -2,19 +2,18 @@ import { chmodSync, lstatSync, mkdirSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import type { SQL } from "bun";
|
|
4
4
|
import { agentClaim } from "../agents/agent-claim.ts";
|
|
5
|
-
import { AgentDashboard } from "../agents/agent-dashboard.ts";
|
|
6
5
|
import { PgAgentStore } from "../agents/agent-store.ts";
|
|
7
|
-
import {
|
|
6
|
+
import { AgentServerTeam } from "../agents/agent-team.ts";
|
|
8
7
|
import { AGENT_TOOLS } from "../agents/agent-tools.ts";
|
|
9
8
|
import { FileAvatarStudio } from "../agents/avatar-studio.ts";
|
|
10
9
|
import { RelevanceScorer } from "../agents/group-round.ts";
|
|
11
10
|
import { modeOrigins } from "../agents/helper-modes.ts";
|
|
12
11
|
import { Routes } from "../agents/routes.ts";
|
|
13
|
-
import { discordKey } from "../agents/team-keys.ts";
|
|
14
12
|
import { TeamPlaces } from "../agents/team-places.ts";
|
|
15
13
|
import { ownerAttachmentDir } from "../attachments/attachment-dir.ts";
|
|
16
14
|
import { ROOM_LAYOUT } from "../contract/room-layout.ts";
|
|
17
15
|
import type { AgentSessions } from "../contract/runtime.ts";
|
|
16
|
+
import { channelKey } from "../contract/surface.ts";
|
|
18
17
|
import { LEGACY_CHANNEL_SURFACE } from "../db/legacy-channels.ts";
|
|
19
18
|
import { moveTeam } from "../db/team-move.ts";
|
|
20
19
|
import type { ChannelKey } from "../domain/conversation.ts";
|
|
@@ -24,10 +23,15 @@ import type { SessionTool } from "../domain/sessions.ts";
|
|
|
24
23
|
import type { Tier } from "../identity/speakers.ts";
|
|
25
24
|
import { ConfirmationJudge } from "../judging/confirmation-judge.ts";
|
|
26
25
|
import type { Logger } from "../kernel/log.ts";
|
|
26
|
+
import {
|
|
27
|
+
AGENT_SERVER_PLUGIN,
|
|
28
|
+
AGENT_TEAM_SERVICE,
|
|
29
|
+
} from "../plugin-api/agent-server-ids.ts";
|
|
27
30
|
import type { PluginContext, RoundtablePlugin } from "../plugin-api/plugin.ts";
|
|
28
31
|
import {
|
|
29
32
|
AGENTS,
|
|
30
33
|
BACKGROUND_TURNS,
|
|
34
|
+
CHANNEL_CONTEXT,
|
|
31
35
|
IDENTITY,
|
|
32
36
|
MODES,
|
|
33
37
|
PROMPTS,
|
|
@@ -37,7 +41,6 @@ import {
|
|
|
37
41
|
} from "../plugin-api/services.ts";
|
|
38
42
|
import { splitReply } from "../presentation/reply-splitter.ts";
|
|
39
43
|
import { agentPromptExtension } from "../runtime/extensions/agent-prompt.ts";
|
|
40
|
-
import { DISCORD } from "./discord.ts";
|
|
41
44
|
import { agentOnly } from "./session-tool.ts";
|
|
42
45
|
|
|
43
46
|
export {
|
|
@@ -50,18 +53,14 @@ import {
|
|
|
50
53
|
LOCAL_TEAM_ID,
|
|
51
54
|
} from "./agent-server-options.ts";
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* The agent server's service that starts the team and the dashboard in the background: once its
|
|
58
|
-
* `serviceStarted` event says `ready`, the agents' channels and the dashboard are up.
|
|
59
|
-
*/
|
|
60
|
-
export const AGENT_TEAM_SERVICE = "team";
|
|
56
|
+
export {
|
|
57
|
+
AGENT_SERVER_PLUGIN,
|
|
58
|
+
AGENT_TEAM_SERVICE,
|
|
59
|
+
} from "../plugin-api/agent-server-ids.ts";
|
|
61
60
|
|
|
62
61
|
/** The agent tools and the agent's own prompt, which only agent sessions load. */
|
|
63
62
|
export function agentSessionTools(
|
|
64
|
-
team: Pick<
|
|
63
|
+
team: Pick<AgentServerTeam, "extension" | "systemPrompt">,
|
|
65
64
|
logger: Logger,
|
|
66
65
|
): SessionTool[] {
|
|
67
66
|
return [
|
|
@@ -78,7 +77,6 @@ const AGENT_TIERS: Readonly<Record<string, Tier>> = {
|
|
|
78
77
|
agent_list: "member",
|
|
79
78
|
agent_get: "member",
|
|
80
79
|
message_agent: "member",
|
|
81
|
-
channel_read: "member",
|
|
82
80
|
// A knight may make temp knights for whoever is talking to it; the limits hold the cost.
|
|
83
81
|
helper_create: "member",
|
|
84
82
|
helper_end: "member",
|
|
@@ -122,9 +120,22 @@ export function agentServerPlugin(
|
|
|
122
120
|
"the agent server: entryChannelId and coordinator both name the coordinator. Set the entry channel with Discord, the coordinator without it.",
|
|
123
121
|
);
|
|
124
122
|
const teamId = options.teamId ?? options.guildId ?? LOCAL_TEAM_ID;
|
|
123
|
+
// The spaces the team's stored places live in; the deprecated `guildId` is the legacy channels' one.
|
|
124
|
+
const spaces = [
|
|
125
|
+
...(options.placeSpaces ?? []),
|
|
126
|
+
...(options.guildId === undefined ||
|
|
127
|
+
options.placeSpaces?.some((s) => s.surface === LEGACY_CHANNEL_SURFACE)
|
|
128
|
+
? []
|
|
129
|
+
: [{ surface: LEGACY_CHANNEL_SURFACE, space: options.guildId }]),
|
|
130
|
+
];
|
|
131
|
+
const legacySpace = spaces.find(
|
|
132
|
+
(s) => s.surface === LEGACY_CHANNEL_SURFACE,
|
|
133
|
+
)?.space;
|
|
125
134
|
/** Set once the plugin has set up; the preflight reads it after every plugin linked. */
|
|
126
135
|
let hostsRooms: (() => boolean) | undefined;
|
|
127
|
-
let
|
|
136
|
+
let servesSpaces:
|
|
137
|
+
| (() => { surface: string; space: string } | undefined)
|
|
138
|
+
| undefined;
|
|
128
139
|
let linkRoutes: (() => void) | undefined;
|
|
129
140
|
return {
|
|
130
141
|
name: AGENT_SERVER_PLUGIN,
|
|
@@ -136,15 +147,16 @@ export function agentServerPlugin(
|
|
|
136
147
|
moveTeam({
|
|
137
148
|
from: options.formerTeamIds ?? [],
|
|
138
149
|
to: teamId,
|
|
139
|
-
...(
|
|
150
|
+
...(legacySpace === undefined
|
|
140
151
|
? { clearChannels: true }
|
|
141
|
-
: { discordGuild:
|
|
142
|
-
//
|
|
152
|
+
: { discordGuild: legacySpace }),
|
|
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.
|
|
143
155
|
places: [
|
|
144
|
-
|
|
145
|
-
surface: LEGACY_CHANNEL_SURFACE
|
|
146
|
-
|
|
147
|
-
},
|
|
156
|
+
...(legacySpace === undefined
|
|
157
|
+
? [{ surface: LEGACY_CHANNEL_SURFACE }]
|
|
158
|
+
: []),
|
|
159
|
+
...spaces.map(({ surface, space }) => ({ surface, keep: space })),
|
|
148
160
|
],
|
|
149
161
|
}),
|
|
150
162
|
// After the move, so the rows it brought in with their channel ids get their places at this boot.
|
|
@@ -159,27 +171,28 @@ export function agentServerPlugin(
|
|
|
159
171
|
throw new ConfigError(
|
|
160
172
|
"the agents need a surface that hosts their rooms, such as pi-roundtable-web, and none is installed. Without Discord channels there is nowhere to talk to them; add a plugin whose chat surface declares agentRooms: true, or configure discord with its guild.",
|
|
161
173
|
);
|
|
162
|
-
//
|
|
163
|
-
|
|
174
|
+
// Places the team makes but no provider reads would leave its agents unanswered.
|
|
175
|
+
const unserved = servesSpaces?.();
|
|
176
|
+
if (unserved)
|
|
164
177
|
throw new ConfigError(
|
|
165
|
-
|
|
178
|
+
unserved.surface === LEGACY_CHANNEL_SURFACE
|
|
179
|
+
? `the agent guild ${unserved.space} has Discord channels for the agents, but no plugin contributes the place provider of the "${unserved.surface}" surface, so the team cannot read them. A plugin that replaces DISCORD must contribute Discord's side of the agent guild, the place provider with its tools and dashboard: spread discordAgentGuild(context, { guild, connection }) from pi-roundtable/discord into what its setup returns.`
|
|
180
|
+
: `the team has places in the ${unserved.surface} space ${unserved.space}, but no plugin contributes the place provider of the "${unserved.surface}" surface, so the team cannot read them. Add the plugin that brings that surface's places.`,
|
|
166
181
|
);
|
|
167
182
|
// The surfaces the rules name exist only once every plugin has registered its own.
|
|
168
183
|
linkRoutes?.();
|
|
169
184
|
},
|
|
170
185
|
setup: async (context) => {
|
|
171
|
-
// Absent on a host without Discord: then the team has no channels or dashboard.
|
|
172
|
-
const discord = context.services.find(DISCORD);
|
|
173
186
|
const schedules = context.services.get(SCHEDULES);
|
|
174
|
-
const connection = discord?.connection;
|
|
175
187
|
const { logger, providers, surfaces } = context;
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
188
|
+
// A host with no space for stored places has its agents in rooms only.
|
|
189
|
+
if (spaces.length === 0)
|
|
190
|
+
hostsRooms = () => surfaces.roomSurfaces().length > 0;
|
|
191
|
+
else
|
|
192
|
+
servesSpaces = () =>
|
|
193
|
+
spaces.find(
|
|
194
|
+
({ surface }) => context.places.of(surface) === undefined,
|
|
195
|
+
);
|
|
183
196
|
const studio = new FileAvatarStudio({
|
|
184
197
|
dir: join(options.dataDir, "avatars"),
|
|
185
198
|
skins: context.env.characterSkins,
|
|
@@ -245,25 +258,28 @@ export function agentServerPlugin(
|
|
|
245
258
|
});
|
|
246
259
|
// The surfaces the rules name are registered by the time every plugin has set up.
|
|
247
260
|
linkRoutes = () => routes.validate({ names: surfaces.names?.() ?? [] });
|
|
248
|
-
const built:
|
|
261
|
+
const built: AgentServerTeam = new AgentServerTeam({
|
|
249
262
|
routes,
|
|
250
263
|
places,
|
|
251
264
|
teamId,
|
|
252
|
-
discordGuild: options.guildId,
|
|
253
265
|
...(options.entryChannelId !== undefined
|
|
254
|
-
? { entryChannelId: options.entryChannelId }
|
|
255
|
-
: {}),
|
|
256
|
-
// Without an entry channel the coordinator is the named agent, else the first seed.
|
|
257
|
-
...(options.entryChannelId === undefined
|
|
258
266
|
? {
|
|
267
|
+
entryChannel: channelKey(
|
|
268
|
+
LEGACY_CHANNEL_SURFACE,
|
|
269
|
+
options.entryChannelId,
|
|
270
|
+
),
|
|
271
|
+
}
|
|
272
|
+
: {
|
|
273
|
+
// Without an entry channel a place provider names, the coordinator is the named agent, else the first seed.
|
|
259
274
|
coordinator: () =>
|
|
260
275
|
options.coordinator ?? context.sessions().seeds[0]?.name,
|
|
261
|
-
}
|
|
262
|
-
: {}),
|
|
276
|
+
}),
|
|
263
277
|
seeds: () => context.sessions().seeds,
|
|
264
278
|
promptSections: () => context.sessions().prompt,
|
|
265
279
|
agentTools: context.env.agentTools,
|
|
266
280
|
pluginTools: () => context.sessions().agentTools,
|
|
281
|
+
pluginWithheldFromHelpers: () =>
|
|
282
|
+
context.sessions().agentToolsWithheldFromHelpers ?? [],
|
|
267
283
|
pluginSelection: () => context.sessions().agentSelection(),
|
|
268
284
|
events: context.events,
|
|
269
285
|
owner: options.owner,
|
|
@@ -271,7 +287,6 @@ export function agentServerPlugin(
|
|
|
271
287
|
shellUser: options.shellUser,
|
|
272
288
|
...(options.scratchDir ? { scratchDir: options.scratchDir } : {}),
|
|
273
289
|
store,
|
|
274
|
-
...(channels ? { channels } : {}),
|
|
275
290
|
studio,
|
|
276
291
|
...(options.refreshAvatars ? { refreshAvatars: true } : {}),
|
|
277
292
|
runtime: () => running,
|
|
@@ -305,18 +320,16 @@ export function agentServerPlugin(
|
|
|
305
320
|
...(skills ? { skills } : {}),
|
|
306
321
|
modes: () => context.services.find(MODES),
|
|
307
322
|
rooms: () => context.services.find(ROOM_LAYOUT),
|
|
323
|
+
formerChannelOps: () => options.formerChannelOps?.(context),
|
|
308
324
|
...(options.helpers !== undefined ? { helpers: options.helpers } : {}),
|
|
309
325
|
principals: () => context.services.find(IDENTITY),
|
|
310
326
|
logger,
|
|
311
327
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
.catch((error: unknown) =>
|
|
318
|
-
logger.error({ channelId, err: error }, "archive failed"),
|
|
319
|
-
);
|
|
328
|
+
// The deprecated `AgentTeam.discordGuild`, the agent guild: kept for plugins that read it
|
|
329
|
+
// until 1.0, though the team itself knows no guild but through its place providers.
|
|
330
|
+
Object.defineProperty(built, "discordGuild", {
|
|
331
|
+
value: legacySpace,
|
|
332
|
+
enumerable: true,
|
|
320
333
|
});
|
|
321
334
|
const agentSessions: AgentSessions = {
|
|
322
335
|
workDir: options.workDir,
|
|
@@ -345,17 +358,6 @@ export function agentServerPlugin(
|
|
|
345
358
|
});
|
|
346
359
|
const attachmentDir = (channel: ChannelKey) =>
|
|
347
360
|
ownerAttachmentDir(options.dataDir, channel);
|
|
348
|
-
// The dashboard is a Discord message; a team without Discord has none.
|
|
349
|
-
const dashboard =
|
|
350
|
-
connection && options.guildId
|
|
351
|
-
? new AgentDashboard({
|
|
352
|
-
status: () => built.status(),
|
|
353
|
-
board: connection.agentDashboard(options.guildId),
|
|
354
|
-
lines: () => context.dashboard(),
|
|
355
|
-
logger,
|
|
356
|
-
})
|
|
357
|
-
: undefined;
|
|
358
|
-
if (dashboard) built.onChange(() => dashboard.changed());
|
|
359
361
|
const connectErrorReporter = () =>
|
|
360
362
|
options.errorReporter?.connect({
|
|
361
363
|
channelOf: (name) =>
|
|
@@ -372,19 +374,14 @@ export function agentServerPlugin(
|
|
|
372
374
|
});
|
|
373
375
|
return {
|
|
374
376
|
services: [
|
|
375
|
-
...(dashboard
|
|
376
|
-
? [{ name: "dashboard", stop: () => dashboard.stop() }]
|
|
377
|
-
: []),
|
|
378
377
|
{
|
|
379
378
|
name: AGENT_TEAM_SERVICE,
|
|
380
379
|
stop: () => built.stop(),
|
|
381
380
|
busy: () => built.busy(),
|
|
382
|
-
// The
|
|
383
|
-
// reporter connects whether or not the team did, since it reports the failure.
|
|
381
|
+
// The error reporter connects whether or not the team started, since it reports the failure.
|
|
384
382
|
startInBackground: async () => {
|
|
385
383
|
try {
|
|
386
384
|
await built.start();
|
|
387
|
-
dashboard?.start();
|
|
388
385
|
} finally {
|
|
389
386
|
connectErrorReporter();
|
|
390
387
|
}
|
|
@@ -410,9 +407,9 @@ export function agentServerPlugin(
|
|
|
410
407
|
? { attachmentDownload: options.attachmentDownload }
|
|
411
408
|
: {}),
|
|
412
409
|
logger,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
410
|
+
// Read from the surface that holds the message's channel, when one reads context.
|
|
411
|
+
channelContext: async (message) =>
|
|
412
|
+
context.services.find(CHANNEL_CONTEXT)?.read(message),
|
|
416
413
|
}),
|
|
417
414
|
],
|
|
418
415
|
// The pictures are public on a listener only where a public address reaches it.
|
|
@@ -1,11 +1,14 @@
|
|
|
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,
|
|
6
7
|
ChannelContextOptions,
|
|
7
8
|
} from "../contract/channel-context.ts";
|
|
8
9
|
import { type ServiceKey, serviceKey } from "../contract/services.ts";
|
|
10
|
+
import { discordAgentGuild } from "../discord/agent-guild.ts";
|
|
11
|
+
import { discordChannelOps, discordTeamReads } from "../discord/agent-tools.ts";
|
|
9
12
|
import { CardCopies } from "../discord/card-copies.ts";
|
|
10
13
|
import { ChannelContextReader } from "../discord/channel-context.ts";
|
|
11
14
|
import { CommandCollection } from "../discord/command-collection.ts";
|
|
@@ -24,8 +27,10 @@ import type { DiscordPoster } from "../discord/poster/poster.ts";
|
|
|
24
27
|
import { restOf, restPoster } from "../discord/poster/rest-poster.ts";
|
|
25
28
|
import { stopButtonModule } from "../discord/stop-button.ts";
|
|
26
29
|
import type { InboundMessage } from "../domain/conversation.ts";
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
30
|
+
import { ConfigError } from "../domain/errors.ts";
|
|
31
|
+
import type { FormerChannelOps } from "../plugin-api/agent-ops.ts";
|
|
32
|
+
import type { PluginContext, RoundtablePlugin } from "../plugin-api/plugin.ts";
|
|
33
|
+
import { AGENTS, IDENTITY, THREADS } from "../plugin-api/services.ts";
|
|
29
34
|
import { PeerBots } from "../routing/peer-bots.ts";
|
|
30
35
|
import type { DispatchThreads } from "../threads/dispatch-threads.ts";
|
|
31
36
|
|
|
@@ -63,6 +68,32 @@ export interface DiscordServices {
|
|
|
63
68
|
export const DISCORD: ServiceKey<DiscordServices> =
|
|
64
69
|
serviceKey<DiscordServices>("roundtable.discord");
|
|
65
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Discord's side of the deprecated `AgentOps.arrange` and `AgentOps.read`, for the agent server:
|
|
73
|
+
* what the two channel tools run, over the agent guild's channels of whichever plugin provides
|
|
74
|
+
* `DISCORD`. Undefined on a host without one. Removed in 1.0.
|
|
75
|
+
*/
|
|
76
|
+
export function discordFormerChannelOps(
|
|
77
|
+
guild: string,
|
|
78
|
+
): (
|
|
79
|
+
context: Pick<PluginContext, "services" | "logger">,
|
|
80
|
+
) => FormerChannelOps | undefined {
|
|
81
|
+
return ({ services, logger }) => {
|
|
82
|
+
const connection = services.find(DISCORD)?.connection;
|
|
83
|
+
return (
|
|
84
|
+
connection &&
|
|
85
|
+
discordChannelOps({
|
|
86
|
+
channels: connection.agentChannels(guild),
|
|
87
|
+
directory: () => {
|
|
88
|
+
const server = services.find(AGENTS);
|
|
89
|
+
return server && discordTeamReads(server);
|
|
90
|
+
},
|
|
91
|
+
logger,
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
66
97
|
export interface DiscordOptions {
|
|
67
98
|
token: string;
|
|
68
99
|
/**
|
|
@@ -75,8 +106,13 @@ export interface DiscordOptions {
|
|
|
75
106
|
dataDir: string;
|
|
76
107
|
/** The name of the root slash command, without the slash. */
|
|
77
108
|
rootCommand: string;
|
|
78
|
-
/** The agent guild (`discord.guild`): when given, the plugin contributes the place provider of the agent team's channels and threads
|
|
109
|
+
/** The agent guild (`discord.guild`): when given, the plugin contributes Discord's side of it (`discordAgentGuild`): the place provider of the agent team's channels and threads, their tools, and the dashboard message. */
|
|
79
110
|
agentGuild?: string;
|
|
111
|
+
/**
|
|
112
|
+
* The channel the coordinator lives in (`discord.entryChannel`): the agent in it is the
|
|
113
|
+
* coordinator. Needs `agentGuild`; the agent server's `coordinator` names it without one.
|
|
114
|
+
*/
|
|
115
|
+
entryChannel?: string;
|
|
80
116
|
/** Text appended as it is to the refusal a non-owner gets, such as a pointer to the commands anyone may use. */
|
|
81
117
|
refusalHint?: string;
|
|
82
118
|
/** The host's channel context settings; `false` turns it off. Default: on, with the defaults. */
|
|
@@ -118,6 +154,8 @@ const INTERCOM_KEEP = 300;
|
|
|
118
154
|
* preflight, so a clash fails before any service starts.
|
|
119
155
|
*/
|
|
120
156
|
export function discordPlugin(options: DiscordOptions): RoundtablePlugin {
|
|
157
|
+
if (options.entryChannel !== undefined && options.agentGuild === undefined)
|
|
158
|
+
throw new ConfigError(ENTRY_CHANNEL_WITHOUT_GUILD);
|
|
121
159
|
const collection = new CommandCollection();
|
|
122
160
|
let surface: DiscordSurface | undefined;
|
|
123
161
|
return {
|
|
@@ -129,7 +167,7 @@ export function discordPlugin(options: DiscordOptions): RoundtablePlugin {
|
|
|
129
167
|
collection.compose(ownerRootCommand(options.rootCommand)),
|
|
130
168
|
);
|
|
131
169
|
},
|
|
132
|
-
setup: async ({ conversations, services, logger, events }) => {
|
|
170
|
+
setup: async ({ conversations, services, logger, events, dashboard }) => {
|
|
133
171
|
const identity = services.find(IDENTITY);
|
|
134
172
|
// A host that keeps no copy texts on disk drops what an earlier run left.
|
|
135
173
|
if (options.cardCopies === false)
|
|
@@ -240,13 +278,25 @@ export function discordPlugin(options: DiscordOptions): RoundtablePlugin {
|
|
|
240
278
|
channelContext: (message, given) =>
|
|
241
279
|
connected.channelContext(message, given),
|
|
242
280
|
});
|
|
281
|
+
// Discord's side of the agent guild: the team's channels and threads as its places, their tools, and the dashboard message.
|
|
282
|
+
const agentGuild = options.agentGuild
|
|
283
|
+
? discordAgentGuild(
|
|
284
|
+
{ services, logger, dashboard },
|
|
285
|
+
{
|
|
286
|
+
guild: options.agentGuild,
|
|
287
|
+
connection: connected,
|
|
288
|
+
client: connected.client(),
|
|
289
|
+
...(options.entryChannel === undefined
|
|
290
|
+
? {}
|
|
291
|
+
: { entryChannel: options.entryChannel }),
|
|
292
|
+
},
|
|
293
|
+
)
|
|
294
|
+
: undefined;
|
|
243
295
|
return {
|
|
244
296
|
// The host starts the surface first; it registers the composed commands as it connects.
|
|
245
297
|
surfaces: [connected],
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
? [connected.agentPlaces(options.agentGuild)]
|
|
249
|
-
: [],
|
|
298
|
+
places: agentGuild?.places ?? [],
|
|
299
|
+
tools: agentGuild?.tools ?? [],
|
|
250
300
|
// A person's Discord direct messages, through a Discord identity of theirs.
|
|
251
301
|
directChannels: [
|
|
252
302
|
discordDirectChannel({
|
|
@@ -256,7 +306,9 @@ export function discordPlugin(options: DiscordOptions): RoundtablePlugin {
|
|
|
256
306
|
ownerId: options.ownerId,
|
|
257
307
|
}),
|
|
258
308
|
],
|
|
309
|
+
...(agentGuild ? { events: agentGuild.events } : {}),
|
|
259
310
|
services: [
|
|
311
|
+
...(agentGuild?.services ?? []),
|
|
260
312
|
// The copy texts of the last cards are on disk before the host exits.
|
|
261
313
|
{
|
|
262
314
|
name: "card-copies",
|
|
@@ -117,6 +117,7 @@ export function modulesPlugin(options: ModulesOptions): RoundtablePlugin {
|
|
|
117
117
|
sessions,
|
|
118
118
|
toolTiers,
|
|
119
119
|
directChannels,
|
|
120
|
+
queue,
|
|
120
121
|
}) => {
|
|
121
122
|
const schedules = services.get(SCHEDULES);
|
|
122
123
|
// Absent when a plugin list leaves the prechecks plugin out: then none can be attached.
|
|
@@ -171,6 +172,7 @@ export function modulesPlugin(options: ModulesOptions): RoundtablePlugin {
|
|
|
171
172
|
targets: (name) => conversations.target(name),
|
|
172
173
|
deliver: (job, outcome) => background.runDelegated(job, outcome),
|
|
173
174
|
...(threads ? { threads } : {}),
|
|
175
|
+
draining: () => queue.draining ?? queue.closed,
|
|
174
176
|
logger,
|
|
175
177
|
});
|
|
176
178
|
services.provide(BACKGROUND_TURNS, background);
|
|
@@ -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.",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { IntercomCard } from "../domain/conversation.ts";
|
|
2
|
+
import type { InterimPosts } from "../domain/interim.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One agent's message in a channel, posted under its name and avatar.
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentPost {
|
|
8
|
+
name: string;
|
|
9
|
+
avatarUrl: string;
|
|
10
|
+
/** The turn's thinking, posted first as a quiet line. */
|
|
11
|
+
thinking?: string;
|
|
12
|
+
chunks: string[];
|
|
13
|
+
files?: { name: string; data: Uint8Array }[];
|
|
14
|
+
/** A thread of the channel to post in instead, such as a dispatch's. */
|
|
15
|
+
threadId?: string;
|
|
16
|
+
/** A message between agents, shown as a small card in place of `chunks` where the channel can. */
|
|
17
|
+
intercom?: IntercomCard;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A category's name. Agents live under `Agents` or `Agents-<suffix>`, groups under `Groups` or
|
|
22
|
+
* `Groups-<suffix>`, and archived ones, kept with their history, under `Archive`.
|
|
23
|
+
*/
|
|
24
|
+
export type AgentCategory = string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A category of the agent server and its channels, in server order.
|
|
28
|
+
*/
|
|
29
|
+
export interface CategoryLayout {
|
|
30
|
+
/** Absent for a category still to be made. */
|
|
31
|
+
id?: string;
|
|
32
|
+
name: string;
|
|
33
|
+
channelIds: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A message of the agent server as `channel_read` returns it.
|
|
38
|
+
*/
|
|
39
|
+
export interface ChannelMessage {
|
|
40
|
+
id: string;
|
|
41
|
+
author: string;
|
|
42
|
+
at: Date;
|
|
43
|
+
text: string;
|
|
44
|
+
attachments: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The agent guild's channels. Discord's place provider drives them to make, keep and post in the
|
|
49
|
+
* places of agents and groups, and Discord's tools list, arrange and read categories.
|
|
50
|
+
*/
|
|
51
|
+
export interface AgentChannels {
|
|
52
|
+
post(channelId: string, post: AgentPost): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Where a running turn posts the text it writes before its final answer, under the same name
|
|
55
|
+
* and avatar as `post`; absent = only the final reply is posted.
|
|
56
|
+
*/
|
|
57
|
+
interim?(
|
|
58
|
+
channelId: string,
|
|
59
|
+
as: Omit<AgentPost, "thinking" | "chunks" | "files">,
|
|
60
|
+
): InterimPosts;
|
|
61
|
+
/** Creates a text channel under the category, made when missing; returns its id. */
|
|
62
|
+
createChannel(
|
|
63
|
+
name: string,
|
|
64
|
+
topic: string,
|
|
65
|
+
category: AgentCategory,
|
|
66
|
+
): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Opens a thread under a channel to be a temp knight's place, with no start message; returns its
|
|
69
|
+
* id. Posts to that id speak through the parent channel's webhook into the thread. Absent: Discord
|
|
70
|
+
* makes no place for a temp knight, and making one from a Discord conversation fails.
|
|
71
|
+
*/
|
|
72
|
+
createThread?(parentChannelId: string, name: string): Promise<string>;
|
|
73
|
+
/** Archives and locks a temp knight's thread (locked only when permitted); its history stays. */
|
|
74
|
+
closeThread?(threadId: string): Promise<void>;
|
|
75
|
+
/** Opens a temp knight's archived thread again, unlocked. */
|
|
76
|
+
openThread?(threadId: string): Promise<void>;
|
|
77
|
+
/** Moves a channel into the category when it sits elsewhere; true when it moved. */
|
|
78
|
+
placeIn(channelId: string, category: AgentCategory): Promise<boolean>;
|
|
79
|
+
/** Every category of the server in order, each with its channels in order. */
|
|
80
|
+
layout(): Promise<CategoryLayout[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Puts the categories, and the channels in each, in this order, making categories without an
|
|
83
|
+
* id; then deletes the categories of `remove` that hold no channel.
|
|
84
|
+
*/
|
|
85
|
+
arrange(layout: CategoryLayout[], remove: string[]): Promise<void>;
|
|
86
|
+
setTopic(channelId: string, topic: string): Promise<void>;
|
|
87
|
+
/** Deletes the assistant's webhook in the channel, when it has one; its past messages stay. */
|
|
88
|
+
removeWebhook(channelId: string): Promise<void>;
|
|
89
|
+
exists(channelId: string): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Up to `limit` messages of a text channel or thread of the agent server, oldest first: the
|
|
92
|
+
* latest, or those around `around`. Other servers' channels are refused.
|
|
93
|
+
*/
|
|
94
|
+
read(
|
|
95
|
+
channelId: string,
|
|
96
|
+
options: { limit: number; around?: string },
|
|
97
|
+
): Promise<ChannelMessage[]>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The dashboard channel's one pinned message, made when missing and edited in place.
|
|
102
|
+
*/
|
|
103
|
+
export interface DashboardBoard {
|
|
104
|
+
show(sections: string[]): Promise<void>;
|
|
105
|
+
}
|
|
@@ -429,10 +429,10 @@ export interface QueuePort {
|
|
|
429
429
|
run<T>(channel: ChannelKey, task: () => Promise<T>): Promise<T>;
|
|
430
430
|
/**
|
|
431
431
|
* Runs `task` as the delivery of work the shutdown drain waits for, such as a coding worker's
|
|
432
|
-
* report:
|
|
433
|
-
*
|
|
434
|
-
* ends when the drain does; after that the task
|
|
435
|
-
* predates it: call `task` directly then.
|
|
432
|
+
* report: the queue task it starts runs although the host is shutting down, `closed` reads
|
|
433
|
+
* false there, and the drain waits for it as for any task. A queue task that task starts in
|
|
434
|
+
* turn is refused, and `draining` stays true. It ends when the drain does; after that the task
|
|
435
|
+
* is refused as any other. Absent on a host that predates it: call `task` directly then.
|
|
436
436
|
*/
|
|
437
437
|
finishing?<T>(task: () => Promise<T>): Promise<T>;
|
|
438
438
|
/** Tasks of the channel running or waiting. */
|
|
@@ -444,6 +444,12 @@ export interface QueuePort {
|
|
|
444
444
|
* HostStoppingError, and a plugin that starts work on its own, such as a timer, starts none.
|
|
445
445
|
*/
|
|
446
446
|
readonly closed: boolean;
|
|
447
|
+
/**
|
|
448
|
+
* Whether the host is shutting down, even inside `finishing`, which masks only `closed`: work
|
|
449
|
+
* that a delivery's own turn spawns, such as a transient task, starts none. Absent on a host
|
|
450
|
+
* that predates it: read `closed` then.
|
|
451
|
+
*/
|
|
452
|
+
readonly draining?: boolean;
|
|
447
453
|
/** Called whenever a channel's count of running and waiting tasks changes. */
|
|
448
454
|
onChange(listener: (channel: ChannelKey) => void): void;
|
|
449
455
|
}
|