pi-roundtable 0.44.0 → 0.45.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/docs/plugins.md +36 -2
  3. package/package.json +2 -2
  4. package/src/core/agents/agent-claim.ts +15 -21
  5. package/src/core/agents/agent-messages.ts +10 -10
  6. package/src/core/agents/agent-prompt.ts +7 -8
  7. package/src/core/agents/agent-rules.ts +9 -2
  8. package/src/core/agents/agent-store.ts +16 -0
  9. package/src/core/agents/agent-team-fake-channels.ts +105 -0
  10. package/src/core/agents/agent-team-fixture.ts +30 -105
  11. package/src/core/agents/agent-team.ts +20 -21
  12. package/src/core/agents/group-turns.ts +8 -15
  13. package/src/core/agents/helper-modes.ts +7 -13
  14. package/src/core/agents/helper-work.ts +7 -6
  15. package/src/core/agents/message-target.ts +24 -12
  16. package/src/core/agents/room-progress.ts +8 -6
  17. package/src/core/agents/routes.ts +24 -47
  18. package/src/core/agents/team-editing.ts +5 -8
  19. package/src/core/agents/team-keys.ts +5 -190
  20. package/src/core/agents/team-lifecycle.ts +23 -39
  21. package/src/core/agents/team-options.ts +1 -1
  22. package/src/core/agents/team-places.ts +335 -0
  23. package/src/core/agents/team-posts.ts +157 -0
  24. package/src/core/agents/team-prompt.ts +3 -3
  25. package/src/core/agents/team-status.ts +18 -10
  26. package/src/core/agents/team-turn-types.ts +5 -8
  27. package/src/core/agents/team-turns.ts +26 -169
  28. package/src/core/builtin/agent-server-test-kit.ts +29 -0
  29. package/src/core/builtin/agent-server.ts +19 -12
  30. package/src/core/builtin/discord.ts +6 -0
  31. package/src/core/contract/places.ts +141 -0
  32. package/src/core/discord/agent-places.ts +215 -0
  33. package/src/core/discord/discord-surface.ts +13 -0
  34. package/src/core/host/define-roundtable.ts +1 -0
  35. package/src/core/plugin-api/agent-assets.ts +36 -0
  36. package/src/core/plugin-api/plugin-context.ts +30 -0
  37. package/src/core/plugin-api/plugin.ts +10 -28
  38. package/src/core/plugin-api/services.ts +20 -39
  39. package/src/core/registry/claims.ts +120 -0
  40. package/src/core/registry/contributions.ts +36 -118
  41. package/src/core/registry/place-port.ts +94 -0
  42. package/src/core/registry/places.ts +43 -0
  43. package/src/core/testing/fake-pager-places.ts +120 -0
  44. package/src/core/testing/fake-room-surface.ts +60 -0
  45. package/src/core/testing/modules.ts +5 -5
  46. package/src/core/testing/place-contract.ts +481 -0
  47. package/src/core/testing/team-places.ts +121 -0
  48. package/src/core/testing/test-host.ts +36 -10
  49. package/src/discord/index.ts +2 -0
  50. package/src/index.ts +12 -0
  51. package/src/testing.ts +15 -3
@@ -0,0 +1,335 @@
1
+ import {
2
+ type PlaceKind,
3
+ type PlacePort,
4
+ type PlaceProvider,
5
+ type PlaceRef,
6
+ roomKey,
7
+ } from "../contract/places.ts";
8
+ import { parseChannelKey } from "../contract/surface.ts";
9
+ import type { ChannelKey } from "../domain/conversation.ts";
10
+ import { AgentError } from "../domain/errors.ts";
11
+ import type { AgentTurnScope } from "../domain/ports.ts";
12
+ import type { AgentDirectory } from "../plugin-api/services.ts";
13
+ import type { AgentPlaces } from "./agent-places.ts";
14
+ import type { Agent, AgentGroup } from "./agent-rules.ts";
15
+
16
+ /** The part of the stored places the team reads: an owner's place id on a surface, and the owner of a place id. */
17
+ export type StoredPlaces = Pick<AgentPlaces, "on" | "ownerOf">;
18
+
19
+ /** Whose place a key is. */
20
+ export interface PlaceOwner {
21
+ kind: PlaceKind;
22
+ name: string;
23
+ /** A stored place keeps its owner's row when the owner is archived, so it names an archived owner too; a room does not. */
24
+ stored: boolean;
25
+ }
26
+
27
+ /** One place of an agent or group, as a surface and the key of its conversation there. */
28
+ export interface TeamPlace {
29
+ surface: string;
30
+ key: ChannelKey;
31
+ }
32
+
33
+ /**
34
+ * Where the team's agents and groups are, read through the place providers of the host: their keys,
35
+ * who owns a key, and the conversation keys of a group's seats and log. A stored provider's places
36
+ * are the rows of `agent_places`; a derived provider's are rooms named after the agent or group.
37
+ * A surface with no provider on this host has no place here, whatever rows are stored for it.
38
+ *
39
+ * "Auto" order is the port's: the stored providers in contribution order, then the derived ones.
40
+ * Call it only once the host has linked (the port throws NotLinkedError before): a team reads it
41
+ * from its start on.
42
+ */
43
+ export class TeamPlaces {
44
+ readonly #store: Pick<AgentDirectory, "agent" | "group">;
45
+ readonly #stored: StoredPlaces;
46
+ readonly #port: PlacePort | undefined;
47
+
48
+ /** `port` absent: a team nobody can reach has no places at all. */
49
+ constructor(
50
+ store: Pick<AgentDirectory, "agent" | "group">,
51
+ stored: StoredPlaces,
52
+ port: PlacePort | undefined,
53
+ ) {
54
+ this.#store = store;
55
+ this.#stored = stored;
56
+ this.#port = port;
57
+ }
58
+
59
+ /** The providers in "auto" order. */
60
+ ordered(): readonly PlaceProvider[] {
61
+ return this.#port?.all() ?? [];
62
+ }
63
+
64
+ /** The surfaces that hold places, in "auto" order. */
65
+ surfaces(): readonly string[] {
66
+ return this.ordered().map((provider) => provider.surface);
67
+ }
68
+
69
+ /** The surfaces whose places are rooms named after the agent or group. */
70
+ rooms(): readonly string[] {
71
+ return this.ordered().flatMap((provider) =>
72
+ provider.storage === "derived" ? [provider.surface] : [],
73
+ );
74
+ }
75
+
76
+ /** The provider of a surface by name, or of a key by its prefix. */
77
+ providerOf(surfaceOrKey: string): PlaceProvider | undefined {
78
+ return this.#port?.of(surfaceOrKey);
79
+ }
80
+
81
+ /** The surface of a key that is a room's, or no provider's: any key but a stored place's. */
82
+ roomSurfaceOf(key: ChannelKey): string | undefined {
83
+ if (typeof key !== "string" || !key.includes(":")) return undefined;
84
+ return this.#provider(key)?.storage === "stored"
85
+ ? undefined
86
+ : parseChannelKey(key).surface;
87
+ }
88
+
89
+ /** Whether a provider of this host serves the key's surface; a key of any other surface is no place and no room here. */
90
+ serves(key: ChannelKey): boolean {
91
+ return this.#provider(key) !== undefined;
92
+ }
93
+
94
+ /** Whether the key is a stored place's: one a provider made or bound. */
95
+ isStored(key: ChannelKey): boolean {
96
+ return this.#provider(key)?.storage === "stored";
97
+ }
98
+
99
+ /** The space of the provider of the key's surface; a message from it is the team's even outside the places it knows. */
100
+ spaceOf(key: ChannelKey): string | undefined {
101
+ return this.#provider(key)?.space;
102
+ }
103
+
104
+ /** How the model names the place in text: the provider's mention, else the key. */
105
+ mention(key: ChannelKey): string {
106
+ return this.#provider(key)?.mention?.(key) ?? key;
107
+ }
108
+
109
+ /** The agent's or group's name as a place owner; an agent first, since names are shared. */
110
+ #ref(name: string): PlaceRef | undefined {
111
+ if (this.#store.agent(name)) return { kind: "agent", name };
112
+ if (this.#store.group(name)) return { kind: "group", name };
113
+ return undefined;
114
+ }
115
+
116
+ #keyOn(ref: PlaceRef, provider: PlaceProvider): ChannelKey | undefined {
117
+ if (provider.storage === "derived") return provider.key(ref);
118
+ const id = this.#stored.on(ref.kind, ref.name, provider.surface);
119
+ return id === undefined ? undefined : provider.key(ref, id);
120
+ }
121
+
122
+ /**
123
+ * Every key an agent or group is addressed by, in "auto" order: the places it has on each
124
+ * provider's surface. Archived ones count, so what they left behind can be cleared; none for a
125
+ * name the team does not know.
126
+ */
127
+ keysOf(name: string): ChannelKey[] {
128
+ return this.placesOf(name).map((place) => place.key);
129
+ }
130
+
131
+ /** The places of an agent or group, each with its surface, in "auto" order. */
132
+ placesOf(name: string): TeamPlace[] {
133
+ const ref = this.#ref(name);
134
+ if (!ref) return [];
135
+ return this.ordered().flatMap((provider) => {
136
+ const key = this.#keyOn(ref, provider);
137
+ return key === undefined ? [] : [{ surface: provider.surface, key }];
138
+ });
139
+ }
140
+
141
+ /** The agent's place on a surface, or undefined when it has none there. */
142
+ placeOn(name: string, surface: string): ChannelKey | undefined {
143
+ const ref = this.#ref(name);
144
+ const provider = this.providerOf(surface);
145
+ return ref && provider ? this.#keyOn(ref, provider) : undefined;
146
+ }
147
+
148
+ #provider(key: ChannelKey): PlaceProvider | undefined {
149
+ return typeof key === "string" && key.includes(":")
150
+ ? this.#port?.of(key)
151
+ : undefined;
152
+ }
153
+
154
+ /** Whose place a key is, whatever the owner's status; undefined for a key no provider of this host reads as one, and for an owner the team does not have. */
155
+ ownerOf(key: ChannelKey): PlaceOwner | undefined {
156
+ const provider = this.#provider(key);
157
+ const place = provider?.placeOf(key);
158
+ if (!provider || !place) return undefined;
159
+ const stored = "id" in place;
160
+ const owner = stored
161
+ ? this.#stored.ownerOf(provider.surface, place.id)
162
+ : place;
163
+ if (!owner) return undefined;
164
+ const found =
165
+ owner.kind === "agent"
166
+ ? this.#store.agent(owner.name)
167
+ : this.#store.group(owner.name);
168
+ return found && { kind: owner.kind, name: owner.name, stored };
169
+ }
170
+
171
+ /**
172
+ * The agent whose place the key is. A stored place keeps its row while its owner is archived,
173
+ * and an archived agent owns nothing there; a room names an archived agent too, so what it
174
+ * left behind can be found.
175
+ */
176
+ agentOf(key: ChannelKey): Agent | undefined {
177
+ const owner = this.ownerOf(key);
178
+ if (owner?.kind !== "agent") return undefined;
179
+ const agent = this.#store.agent(owner.name);
180
+ return owner.stored && agent?.status !== "active" ? undefined : agent;
181
+ }
182
+
183
+ /** The group whose place the key is, under the same rule as `agentOf`. */
184
+ groupOf(key: ChannelKey): AgentGroup | undefined {
185
+ const owner = this.ownerOf(key);
186
+ if (owner?.kind !== "group") return undefined;
187
+ const group = this.#store.group(owner.name);
188
+ return owner.stored && group?.status !== "active" ? undefined : group;
189
+ }
190
+
191
+ /** What owns the key while active: an archived agent or group owns nothing. */
192
+ ownerKind(key: ChannelKey): PlaceKind | undefined {
193
+ const owner = this.ownerOf(key);
194
+ if (!owner) return undefined;
195
+ const found =
196
+ owner.kind === "agent"
197
+ ? this.#store.agent(owner.name)
198
+ : this.#store.group(owner.name);
199
+ return found?.status === "active" ? owner.kind : undefined;
200
+ }
201
+
202
+ /**
203
+ * An agent's conversation inside a group. In a stored place of the group, the provider's form
204
+ * (`conversations.seat`, else `agentgroup:<surface>.<id>.<agent>`); in a room, or when the key is
205
+ * no provider's, `agentgroup:<surface>.group.<group>.<agent>`, so a room's seats are
206
+ * conversations of their own. Without `channel`, the group's first stored place. Throws
207
+ * AgentError for a group with no stored place there.
208
+ */
209
+ seatKey(group: AgentGroup, agent: string, channel?: ChannelKey): ChannelKey {
210
+ if (channel !== undefined) {
211
+ const provider = this.#provider(channel);
212
+ if (provider?.storage !== "stored")
213
+ return roomSeat(parseChannelKey(channel).surface, group, agent);
214
+ return this.#seatOn(group, agent, provider);
215
+ }
216
+ for (const provider of this.ordered())
217
+ if (
218
+ provider.storage === "stored" &&
219
+ this.#stored.on("group", group.name, provider.surface) !== undefined
220
+ )
221
+ return this.#seatOn(group, agent, provider);
222
+ throw new AgentError(`the group ${group.name} has no place of its own`);
223
+ }
224
+
225
+ #seatOn(
226
+ group: AgentGroup,
227
+ agent: string,
228
+ provider: PlaceProvider,
229
+ ): ChannelKey {
230
+ const id = this.#stored.on("group", group.name, provider.surface);
231
+ if (id === undefined)
232
+ throw new AgentError(
233
+ `the group ${group.name} has no place on ${provider.surface}`,
234
+ );
235
+ return (
236
+ provider.conversations?.seat(id, agent) ??
237
+ `agentgroup:${provider.surface}.${id}.${agent}`
238
+ );
239
+ }
240
+
241
+ /** Every conversation of an agent's seat in a group: one on each stored place of the group, then each room's. */
242
+ seatsOf(group: AgentGroup, agent: string): ChannelKey[] {
243
+ return this.ordered().flatMap((provider) => {
244
+ if (provider.storage === "derived")
245
+ return [roomSeat(provider.surface, group, agent)];
246
+ return this.#stored.on("group", group.name, provider.surface) ===
247
+ undefined
248
+ ? []
249
+ : [this.#seatOn(group, agent, provider)];
250
+ });
251
+ }
252
+
253
+ /**
254
+ * The name a group's messages are logged under: in a stored place the provider's
255
+ * (`conversations.log`, else `<group>@<surface>`), in a room `<group>@<surface>`, so each
256
+ * conversation keeps its own history and cursors.
257
+ */
258
+ logName(group: AgentGroup, channel: ChannelKey): string {
259
+ const provider = this.#provider(channel);
260
+ if (provider?.storage === "stored")
261
+ return (
262
+ provider.conversations?.log(group.name) ??
263
+ `${group.name}@${provider.surface}`
264
+ );
265
+ return `${group.name}@${parseChannelKey(channel).surface}`;
266
+ }
267
+
268
+ /** An agent's conversation in the channel: its own place's, or its room's. */
269
+ scopeOf(agent: Agent, channel: ChannelKey): AgentTurnScope {
270
+ // A key no provider serves is no room: the agent's own place stands for it, else the key.
271
+ const home =
272
+ this.#provider(channel)?.storage === "derived"
273
+ ? channel
274
+ : this.#ownKey(agent, channel);
275
+ return { name: agent.name, session: home, home };
276
+ }
277
+
278
+ /**
279
+ * An agent's conversation inside a group: in a stored place of the group, or without a room,
280
+ * the seat of that place, whose home is the agent's own place on that surface; in a room, the
281
+ * room's seat, whose home is the agent's own room there.
282
+ */
283
+ groupScope(
284
+ agent: Agent,
285
+ group: AgentGroup,
286
+ room?: ChannelKey,
287
+ ): AgentTurnScope {
288
+ const seat = this.seatKey(group, agent.name, room);
289
+ const surface = room === undefined ? undefined : this.roomSurfaceOf(room);
290
+ const ref: PlaceRef = { kind: "agent", name: agent.name };
291
+ const home =
292
+ surface === undefined
293
+ ? this.#ownKey(agent, room ?? seat)
294
+ : roomKey(surface, ref);
295
+ return { name: agent.name, session: seat, home, group: group.name };
296
+ }
297
+
298
+ /** The key of the agent's own place on the stored surface of `channel`, else on its first stored surface, else `channel`. */
299
+ #ownKey(agent: Agent, channel: ChannelKey): ChannelKey {
300
+ const wanted = this.#provider(channel);
301
+ const ref: PlaceRef = { kind: "agent", name: agent.name };
302
+ for (const provider of this.ordered()) {
303
+ if (provider.storage !== "stored") continue;
304
+ if (wanted && provider.surface !== wanted.surface) continue;
305
+ const key = this.#keyOn(ref, provider);
306
+ if (key !== undefined) return key;
307
+ }
308
+ return channel;
309
+ }
310
+
311
+ /**
312
+ * The channel a group seat runs in outside a running turn: the group's room on the surface of
313
+ * the seat's home for a room seat, so it never falls out to the group's stored place; otherwise
314
+ * the group's place on the surface of the seat's home, or the seat's home.
315
+ */
316
+ seatChannel(
317
+ group: Pick<AgentGroup, "name">,
318
+ scope: Pick<AgentTurnScope, "home">,
319
+ ): ChannelKey {
320
+ const provider = this.#provider(scope.home);
321
+ const ref: PlaceRef = { kind: "group", name: group.name };
322
+ // A home no provider serves is no room: the seat stays where its home is.
323
+ if (!provider) return scope.home;
324
+ if (provider.storage === "stored")
325
+ return this.#keyOn(ref, provider) ?? scope.home;
326
+ return roomKey(parseChannelKey(scope.home).surface, ref);
327
+ }
328
+ }
329
+
330
+ /** A group's seat in its room on a surface: its own conversation, apart from the room's. */
331
+ const roomSeat = (
332
+ surface: string,
333
+ group: Pick<AgentGroup, "name">,
334
+ agent: string,
335
+ ): ChannelKey => `agentgroup:${surface}.group.${group.name}.${agent}`;
@@ -0,0 +1,157 @@
1
+ import { channelKey, parseChannelKey } from "../contract/surface.ts";
2
+ import { supportOf } from "../domain/block-support.ts";
3
+ import type {
4
+ ChannelKey,
5
+ IntercomCard,
6
+ PostAuthor,
7
+ ReplyFile,
8
+ } from "../domain/conversation.ts";
9
+ import { AgentError } from "../domain/errors.ts";
10
+ import type { InterimPosts } from "../domain/interim.ts";
11
+ import { chunksFor } from "../presentation/reply-chunks.ts";
12
+ import type { Agent } from "./agent-store.ts";
13
+ import { channelIdOf, discordIdOf } from "./team-keys.ts";
14
+ import type { TeamTurnsOptions } from "./team-turn-types.ts";
15
+
16
+ /**
17
+ * How the team's turns reach a place: whether a reply there may carry files, how its text is cut,
18
+ * and the interim posts and replies under the agent's name, which Discord's channels or a room's
19
+ * surface carry.
20
+ */
21
+ export class TeamPosts {
22
+ readonly #options: TeamTurnsOptions;
23
+
24
+ constructor(options: TeamTurnsOptions) {
25
+ this.#options = options;
26
+ }
27
+
28
+ /** The agent's latest row, so a display name or avatar changed during the turn shows. */
29
+ #current(agent: Agent): Agent {
30
+ return this.#options.store.agent(agent.name) ?? agent;
31
+ }
32
+
33
+ /**
34
+ * Whether a reply in the channel may carry files: Discord's webhook posts do; a room only when
35
+ * its surface declares `supportsFiles`, since a reply with files that surface refuses is lost whole.
36
+ */
37
+ carriesFiles(channel: ChannelKey): boolean {
38
+ return (
39
+ discordIdOf(channel) !== undefined ||
40
+ this.#options.surfaces?.of(channel)?.supportsFiles === true
41
+ );
42
+ }
43
+
44
+ /** What the surface that serves the channel does there (see `supportOf`). */
45
+ support(channel: ChannelKey) {
46
+ return supportOf(
47
+ this.#options.surfaces?.of(channel),
48
+ channel,
49
+ this.#options.surfaces?.lang,
50
+ );
51
+ }
52
+
53
+ /** The messages that carry an agent's text to the channel, cut for the surface that serves it. */
54
+ chunks(channel: ChannelKey, text: string): string[] {
55
+ return chunksFor(this.support(channel), text);
56
+ }
57
+
58
+ /**
59
+ * The turn's interim posts under the agent's name, read as each goes out so a name changed
60
+ * during the turn shows; none in a channel no agent or group owns any more.
61
+ */
62
+ interim(channel: ChannelKey, agent: Agent): InterimPosts | undefined {
63
+ const { places, channels, studio, surfaces } = this.#options;
64
+ if (discordIdOf(channel) === undefined) {
65
+ // A room's interim posts are its surface's, under the agent as author.
66
+ const first = surfaces?.interim(channel, this.author(agent));
67
+ if (!surfaces || !first) return undefined;
68
+ return {
69
+ ...(first.tools === false ? { tools: false } : {}),
70
+ // The poster cuts text for the surface the posts go to.
71
+ ...(first.blocks ? { blocks: first.blocks } : {}),
72
+ ...(first.blockText ? { blockText: first.blockText } : {}),
73
+ post: async (text) => {
74
+ if (!places.ownerKind(channel))
75
+ throw new AgentError(`${channel} is archived`);
76
+ const posts = surfaces.interim(
77
+ channel,
78
+ this.author(this.#current(agent)),
79
+ );
80
+ if (!posts) throw new AgentError(`${channel} shows no interim posts`);
81
+ return posts.post(text);
82
+ },
83
+ };
84
+ }
85
+ if (!channels?.interim) return undefined;
86
+ const interim = channels.interim.bind(channels);
87
+ return {
88
+ post: async (text) => {
89
+ if (!places.ownerKind(channel))
90
+ throw new AgentError(`${channel} is archived`);
91
+ const as = this.#current(agent);
92
+ return interim(channelIdOf(channel), {
93
+ name: as.displayName,
94
+ avatarUrl: studio.url(as.avatarHash),
95
+ }).post(text);
96
+ },
97
+ };
98
+ }
99
+
100
+ /**
101
+ * Posts under the agent's name. A channel no agent or group owns any more, archived while a
102
+ * turn ran, gets nothing, so its webhook is not made again.
103
+ */
104
+ async post(
105
+ channel: ChannelKey,
106
+ as: Agent,
107
+ body: {
108
+ thinking?: string;
109
+ chunks: string[];
110
+ files?: ReplyFile[];
111
+ threadId?: string;
112
+ failed?: true;
113
+ intercom?: IntercomCard;
114
+ },
115
+ ): Promise<void> {
116
+ const { places, channels, studio, surfaces, logger } = this.#options;
117
+ if (!places.ownerKind(channel)) {
118
+ logger.info(
119
+ { channel, agent: as.name },
120
+ "post to an archived channel dropped",
121
+ );
122
+ return;
123
+ }
124
+ // Discord ignores `failed`.
125
+ const { failed, ...rest } = body;
126
+ if (discordIdOf(channel) === undefined) {
127
+ if (!surfaces)
128
+ throw new AgentError(`no surface serves the room ${channel}`);
129
+ const { thinking, chunks, files, threadId, intercom } = rest;
130
+ // A thread of the room's surface is a channel of that surface, and speaks there.
131
+ return surfaces.sendReply(
132
+ threadId === undefined
133
+ ? channel
134
+ : channelKey(parseChannelKey(channel).surface, threadId),
135
+ {
136
+ ...(thinking ? { thinking } : {}),
137
+ chunks,
138
+ ...(files?.length ? { files } : {}),
139
+ author: this.author(as),
140
+ ...(failed ? { failed } : {}),
141
+ ...(intercom ? { intercom } : {}),
142
+ },
143
+ );
144
+ }
145
+ if (!channels) throw new AgentError(`no Discord channels serve ${channel}`);
146
+ return channels.post(channelIdOf(channel), {
147
+ name: as.displayName,
148
+ avatarUrl: studio.url(as.avatarHash),
149
+ ...rest,
150
+ });
151
+ }
152
+
153
+ /** Who speaks for the agent on a surface that shows authors. */
154
+ author(agent: Agent): PostAuthor {
155
+ return { name: agent.displayName, agent: agent.name };
156
+ }
157
+ }
@@ -27,7 +27,7 @@ export function teamSystemPrompt(
27
27
  scratchDir,
28
28
  agentTools,
29
29
  surfaces,
30
- channels,
30
+ places,
31
31
  } = options;
32
32
  const agent = store.agent(scope.name);
33
33
  if (!agent) throw new AgentError(`no agent ${scope.name}`);
@@ -35,7 +35,7 @@ export function teamSystemPrompt(
35
35
  typeof sharedPrompt === "function" ? sharedPrompt() : sharedPrompt;
36
36
  const guest = typeof guestPrompt === "function" ? guestPrompt() : guestPrompt;
37
37
  const group = scope.group ? store.group(scope.group) : undefined;
38
- const coordinator = coordinatorOf(store, options);
38
+ const coordinator = coordinatorOf(store, places, options);
39
39
  const speaker = turns.speakerOf(scope);
40
40
  const base = agentSystemPrompt({
41
41
  agent,
@@ -51,7 +51,7 @@ export function teamSystemPrompt(
51
51
  ...(agent.parent ? { parent: store.agent(agent.parent) } : {}),
52
52
  helpers: options.helpers !== false,
53
53
  ...(agentTools ? { agentTools } : {}),
54
- ...placeOf(turns.turnChannel(scope), surfaces, !!channels),
54
+ ...placeOf(turns.turnChannel(scope), surfaces, places.surfaces()),
55
55
  ...(group
56
56
  ? {
57
57
  group: {
@@ -1,13 +1,19 @@
1
1
  import type { ThinkingSetting } from "../domain/models.ts";
2
2
  import type { ContextUse } from "./agent-ports.ts";
3
- import { discordIdOf, keysOf } from "./team-keys.ts";
3
+ import { discordIdOf } from "./team-keys.ts";
4
4
  import type { TeamContext } from "./team-options.ts";
5
+ import type { TeamPlace } from "./team-places.ts";
6
+
7
+ export type { TeamPlace } from "./team-places.ts";
5
8
 
6
9
  /** An active agent as the dashboard shows it. */
7
10
  export interface AgentStatus {
8
11
  name: string;
9
12
  displayName: string;
13
+ /** @deprecated Its Discord channel; read `places`, which names the place on every surface. Removed in 1.0. */
10
14
  channelId?: string;
15
+ /** Where it is: its place on each surface that holds one, in the order "auto" routing prefers. */
16
+ places?: TeamPlace[];
11
17
  model: string;
12
18
  thinking: ThinkingSetting;
13
19
  /** The channel of its running turn: its own, a group's, or where it answers a message. */
@@ -29,8 +35,10 @@ export interface AgentStatus {
29
35
  export interface GroupStatus {
30
36
  name: string;
31
37
  displayName: string;
32
- /** Its Discord channel; absent in a team without Discord. */
38
+ /** @deprecated Its Discord channel; read `places`, which names the place on every surface. Removed in 1.0. */
33
39
  channelId?: string;
40
+ /** Where it is: its place on each surface that holds one, in the order "auto" routing prefers. */
41
+ places?: TeamPlace[];
34
42
  members: string[];
35
43
  host: string;
36
44
  /** Messages of its channel and rooms running or waiting, a round counting as one. */
@@ -46,14 +54,13 @@ export interface TeamStatus {
46
54
  /** Every active agent and group, with what each is doing now. */
47
55
  export async function teamStatus(ctx: TeamContext): Promise<TeamStatus> {
48
56
  const { options, turns } = ctx;
49
- const { store, queue, schedules } = options;
57
+ const { store, queue, schedules, places } = options;
50
58
  const runtime = options.runtime();
51
- const rooms = options.surfaces?.roomSurfaces() ?? [];
52
59
  const agents: AgentStatus[] = [];
53
60
  for (const agent of store.agents()) {
54
61
  if (agent.status !== "active") continue;
55
- // Its Discord channel and each room are conversations of their own, and all count.
56
- const keys = keysOf(store, agent.name, rooms);
62
+ // Each place is a conversation of its own, and all count.
63
+ const keys = places.keysOf(agent.name);
57
64
  const working = turns.workingIn(agent.name);
58
65
  // The board links Discord channels; a turn in a room has none to link.
59
66
  const workingIn = working === undefined ? undefined : discordIdOf(working);
@@ -69,6 +76,7 @@ export async function teamStatus(ctx: TeamContext): Promise<TeamStatus> {
69
76
  name: agent.name,
70
77
  displayName: agent.displayName,
71
78
  ...(agent.channelId ? { channelId: agent.channelId } : {}),
79
+ places: places.placesOf(agent.name),
72
80
  ...ctx.modelOf(agent.name),
73
81
  ...(workingIn ? { workingIn } : {}),
74
82
  waiting: Math.max(
@@ -90,12 +98,12 @@ export async function teamStatus(ctx: TeamContext): Promise<TeamStatus> {
90
98
  name: group.name,
91
99
  displayName: group.displayName,
92
100
  ...(group.channelId ? { channelId: group.channelId } : {}),
101
+ places: places.placesOf(group.name),
93
102
  members: group.members.map((m) => store.agent(m)?.displayName ?? m),
94
103
  host: store.agent(group.host)?.displayName ?? group.host,
95
- busy: keysOf(store, group.name, rooms).reduce(
96
- (sum, key) => sum + queue.size(key),
97
- 0,
98
- ),
104
+ busy: places
105
+ .keysOf(group.name)
106
+ .reduce((sum, key) => sum + queue.size(key), 0),
99
107
  ...(lastActive ? { lastActive } : {}),
100
108
  },
101
109
  ];
@@ -21,6 +21,7 @@ import type { Agent, PgAgentStore } from "./agent-store.ts";
21
21
  import type { RelevanceScorer } from "./group-round.ts";
22
22
  import type { HelperWork } from "./helper-work.ts";
23
23
  import type { Routes } from "./routes.ts";
24
+ import type { TeamPlaces } from "./team-places.ts";
24
25
 
25
26
  /** Agent messages without an owner message in between (spec behavior 13). */
26
27
  export const MAX_CHAIN_MESSAGES = 8;
@@ -45,23 +46,19 @@ export interface TeamTurnsOptions {
45
46
  /** Who the agents work for, as their prompts and group history name them. */
46
47
  owner: OwnerIdentity;
47
48
  store: PgAgentStore;
49
+ /** Where the agents and groups are: their keys, and who owns a key, through the host's place providers. */
50
+ places: TeamPlaces;
48
51
  /** The Discord channels the agents post in; absent on a host without Discord, where every reply goes through a room's surface. */
49
52
  channels?: Pick<AgentChannels, "post" | "interim">;
50
53
  /**
51
54
  * The surfaces that host agent rooms. A reply in a room goes through `sendReply` with the
52
55
  * agent as author, and its interim posts through `interim`, never through the Discord
53
56
  * channels; without it no key but Discord's is the team's. `of` tells whether the room's
54
- * surface carries reply files.
57
+ * surface carries reply files. Which surfaces host rooms is `places`'s to say.
55
58
  */
56
59
  surfaces?: Pick<
57
60
  SurfacePort,
58
- | "sendReply"
59
- | "interim"
60
- | "roomSurfaces"
61
- | "of"
62
- | "lang"
63
- | "progress"
64
- | "groupRound"
61
+ "sendReply" | "interim" | "of" | "lang" | "progress" | "groupRound"
65
62
  >;
66
63
  studio: Pick<AvatarStudio, "url">;
67
64
  /**