pi-roundtable 0.45.2 → 0.46.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 (70) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/docs/plugins.md +32 -7
  3. package/package.json +1 -1
  4. package/src/characters/compose.ts +7 -3
  5. package/src/characters/index.ts +1 -0
  6. package/src/characters/parts-face.ts +4 -1
  7. package/src/core/agents/agent-claim.ts +2 -2
  8. package/src/core/agents/agent-group-store.ts +74 -1
  9. package/src/core/agents/agent-places.ts +32 -0
  10. package/src/core/agents/agent-ports.ts +0 -94
  11. package/src/core/agents/agent-prompt.ts +3 -1
  12. package/src/core/agents/agent-team-fixture.ts +48 -7
  13. package/src/core/agents/agent-team.ts +54 -59
  14. package/src/core/agents/agent-tools.ts +34 -166
  15. package/src/core/agents/message-target.ts +3 -2
  16. package/src/core/agents/routes.ts +2 -1
  17. package/src/core/agents/team-editing.ts +121 -150
  18. package/src/core/agents/team-helpers.ts +80 -59
  19. package/src/core/agents/team-keys.ts +16 -26
  20. package/src/core/agents/team-lifecycle.ts +155 -99
  21. package/src/core/agents/team-looks.ts +102 -0
  22. package/src/core/agents/team-options.ts +12 -11
  23. package/src/core/agents/team-place-writes.ts +193 -0
  24. package/src/core/agents/team-places.ts +30 -0
  25. package/src/core/agents/team-posts.ts +42 -73
  26. package/src/core/agents/team-selection.ts +10 -2
  27. package/src/core/agents/team-status.ts +3 -2
  28. package/src/core/agents/team-text.ts +13 -46
  29. package/src/core/agents/team-turn-types.ts +11 -16
  30. package/src/core/agents/team-turns.ts +7 -6
  31. package/src/core/builtin/agent-server-options.ts +27 -6
  32. package/src/core/builtin/agent-server.ts +65 -69
  33. package/src/core/builtin/discord.ts +58 -8
  34. package/src/core/builtin/modules.ts +2 -0
  35. package/src/core/contract/agent-channels.ts +97 -0
  36. package/src/core/contract/channels.ts +10 -4
  37. package/src/core/contract/discord-key.ts +15 -0
  38. package/src/core/contract/places.ts +8 -2
  39. package/src/core/db/legacy-channels.ts +31 -0
  40. package/src/core/discord/agent-dashboard-service.ts +55 -0
  41. package/src/core/{agents → discord}/agent-dashboard.ts +7 -2
  42. package/src/core/discord/agent-discord.ts +1 -1
  43. package/src/core/discord/agent-guild.ts +87 -0
  44. package/src/core/{agents/team-layout.ts → discord/agent-layout.ts} +9 -29
  45. package/src/core/discord/agent-places.ts +52 -33
  46. package/src/core/discord/agent-tools.ts +210 -0
  47. package/src/core/discord/connection.ts +4 -1
  48. package/src/core/discord/discord-surface.ts +9 -14
  49. package/src/core/discord/place-fake-client.ts +59 -0
  50. package/src/core/host/define-roundtable.ts +7 -5
  51. package/src/core/modules/delegation/delegator.ts +5 -0
  52. package/src/core/plugin-api/agent-ops.ts +123 -0
  53. package/src/core/plugin-api/agent-server-ids.ts +9 -0
  54. package/src/core/plugin-api/define.ts +9 -0
  55. package/src/core/plugin-api/plugin.ts +2 -0
  56. package/src/core/plugin-api/services.ts +6 -0
  57. package/src/core/registry/contributions.ts +3 -0
  58. package/src/core/routing/channel-queue.ts +28 -12
  59. package/src/core/runtime/pi-agent-runtime.ts +1 -1
  60. package/src/core/runtime/runtime-plugin.ts +1 -0
  61. package/src/core/runtime/runtime-types.ts +6 -0
  62. package/src/core/{agents/agent-team-fake-channels.ts → testing/fake-agent-channels.ts} +5 -1
  63. package/src/core/testing/fake-pager-places.ts +16 -2
  64. package/src/core/testing/modules.ts +2 -1
  65. package/src/core/testing/place-contract.ts +3 -2
  66. package/src/core/testing/team-places.ts +75 -7
  67. package/src/core/testing/test-host.ts +20 -16
  68. package/src/discord/index.ts +5 -0
  69. package/src/kit/channels.ts +1 -2
  70. package/src/kit/support.ts +9 -5
@@ -3,28 +3,34 @@ import {
3
3
  resolveCharacter,
4
4
  suggestCharacter,
5
5
  } from "../../characters/index.ts";
6
+ import type { PlaceCheck, PlaceProvider } from "../contract/places.ts";
6
7
  import type { ChannelKey } from "../domain/conversation.ts";
7
8
  import { AgentError } from "../domain/errors.ts";
8
9
  import type { AgentTurnScope } from "../domain/ports.ts";
9
10
  import { messages } from "../i18n/index.ts";
10
- import type { AgentChannels } from "./agent-ports.ts";
11
11
  import { isHelper, overBase } from "./agent-rules.ts";
12
12
  import type { Agent, AgentGroup } from "./agent-store.ts";
13
13
  import { refreshAvatars } from "./avatar-refresh.ts";
14
14
  import { TeamHelpers } from "./team-helpers.ts";
15
15
  import { coordinatorOf } from "./team-keys.ts";
16
- import { categoryKind, groupTopic } from "./team-layout.ts";
17
16
  import type { TeamContext } from "./team-options.ts";
17
+ import { type PlaceWish, TeamPlaceWrites } from "./team-place-writes.ts";
18
+ import { groupTopic } from "./team-text.ts";
18
19
 
19
20
  /** The team's startup, fresh starts, and archiving of agents and groups. */
20
21
  export class TeamLifecycle {
21
22
  readonly #ctx: TeamContext;
22
23
  readonly #stopped = new AbortController();
24
+ /** The surfaces whose deleted places the team listens for, so a second start listens once. */
25
+ readonly #listening = new Set<string>();
26
+ /** The writes to the places of agents and groups. */
27
+ readonly #places: TeamPlaceWrites;
23
28
  /** The temp knights: their archive, restore and sweep, which archiving a parent calls. */
24
29
  readonly helpers: TeamHelpers;
25
30
 
26
31
  constructor(ctx: TeamContext) {
27
32
  this.#ctx = ctx;
33
+ this.#places = new TeamPlaceWrites(ctx);
28
34
  this.helpers = new TeamHelpers(ctx, (agent) => this.#archiveAgent(agent));
29
35
  }
30
36
 
@@ -37,17 +43,17 @@ export class TeamLifecycle {
37
43
  // ── Startup ────────────────────────────────────────────────────────────
38
44
 
39
45
  /**
40
- * Inserts the seed agents, gives every active agent a channel, archives agents and groups
41
- * whose channels were deleted while the assistant was down, and dresses agents without a
42
- * character in the background, then, with `refreshAvatars`, renders every agent's picture
43
- * again. Without Discord channels the agents live in rooms, which need no setup, so
44
- * none is made or checked.
46
+ * Inserts the seed agents, gives every active agent a place on each stored provider that makes
47
+ * them, archives agents and groups whose places were deleted while the assistant was down, and
48
+ * dresses agents without a character in the background, then, with `refreshAvatars`, renders
49
+ * every agent's picture again. Rooms exist with the name, so none is made or checked.
45
50
  */
46
51
  async start(): Promise<void> {
47
- const { store, channels, seeds, logger } = this.#ctx.options;
52
+ const { store, seeds, logger } = this.#ctx.options;
48
53
  const added = await store.seed(seeds());
49
54
  if (added.length > 0) logger.info({ added }, "seed agents added");
50
- if (channels) await this.#startChannels(channels);
55
+ for (const provider of this.#ctx.options.places.stored())
56
+ await this.#startPlaces(provider);
51
57
  this.#ctx.changed();
52
58
  await this.helpers.reconcile();
53
59
  this.helpers.startSweeper();
@@ -73,44 +79,133 @@ export class TeamLifecycle {
73
79
  });
74
80
  }
75
81
 
76
- async #startChannels(channels: AgentChannels): Promise<void> {
77
- const { store, logger } = this.#ctx.options;
82
+ /**
83
+ * One stored provider's places at start: an active agent that has none gets one (not a temp
84
+ * knight, which lives in its rooms until reached), a place the provider finds `gone` archives
85
+ * its owner as a deletion would, and a `foreign` one (a channel of a server the team left) is
86
+ * dropped and made again, with nobody archived. An active group's place is checked the same
87
+ * way, then given its topic again and put where it belongs.
88
+ */
89
+ async #startPlaces(provider: PlaceProvider): Promise<void> {
90
+ const { store, places } = this.#ctx.options;
91
+ this.#listen(provider);
78
92
  for (const agent of store.agents()) {
79
93
  if (agent.status !== "active") continue;
80
- // A temp knight of a parent without a channel lives in rooms only.
81
- if (!agent.channelId && isHelper(agent)) continue;
82
- if (!agent.channelId) {
83
- const id = await channels.createChannel(
84
- agent.name,
85
- agent.displayName,
86
- "Agents",
87
- );
88
- await store.updateAgent(agent.name, { channelId: id });
89
- logger.info(
90
- { agent: agent.name, channel: id },
91
- "agent channel created",
92
- );
93
- } else if (!(await channels.exists(agent.channelId))) {
94
- await this.channelDeleted(agent.channelId);
94
+ const wish = this.#wish(agent);
95
+ const id = places.idOf(wish, provider.surface);
96
+ if (id === undefined) {
97
+ if (!isHelper(agent)) await this.#make(provider, wish);
98
+ continue;
99
+ }
100
+ const found = await this.#checked(provider, wish, id);
101
+ if (found === "gone") await this.#archiveAgent(agent);
102
+ else if (found === "foreign") {
103
+ await this.#drop(provider, wish);
104
+ if (!isHelper(agent)) await this.#make(provider, wish);
95
105
  }
96
106
  }
97
- const layout = await channels.layout();
98
107
  for (const group of store.groups()) {
99
- // A group of a team that once ran without Discord lives in rooms only.
100
- if (group.status !== "active" || !group.channelId) continue;
101
- const { channelId } = group;
102
- if (!(await channels.exists(channelId))) {
103
- await this.channelDeleted(channelId);
108
+ if (group.status !== "active") continue;
109
+ const wish = this.#wish(group);
110
+ const id = places.idOf(wish, provider.surface);
111
+ if (id === undefined) continue;
112
+ const found = await this.#checked(provider, wish, id);
113
+ if (found === "unknown") continue;
114
+ if (found === "gone") {
115
+ await this.#archiveGroup(group);
116
+ continue;
117
+ }
118
+ if (found === "foreign") {
119
+ await this.#drop(provider, wish);
120
+ await this.#make(provider, wish);
104
121
  continue;
105
122
  }
106
123
  this.retitle(group);
107
- const home = layout.find((c) => c.channelIds.includes(channelId));
108
- if (home && categoryKind(home.name) === "Groups") continue;
109
- if (await channels.placeIn(channelId, "Groups"))
110
- logger.info({ group: group.name }, "group channel moved to Groups");
124
+ // Without `check` a place is taken as it is, as an agent's is: `ensure` would make a deleted one again.
125
+ if (!provider.ensure || !provider.check) continue;
126
+ const kept = await provider.ensure({ ...wish, existing: id });
127
+ if (kept !== id) await this.#record(provider, wish, kept);
111
128
  }
112
129
  }
113
130
 
131
+ /**
132
+ * What the provider says of a stored place; `ok` when it cannot check. A check that fails says
133
+ * nothing of the place: it is logged and `unknown` returned, so the place is kept as it is and
134
+ * the start goes on.
135
+ */
136
+ async #checked(
137
+ provider: PlaceProvider,
138
+ wish: PlaceWish,
139
+ id: string,
140
+ ): Promise<PlaceCheck | "unknown"> {
141
+ try {
142
+ return (await provider.check?.(id)) ?? "ok";
143
+ } catch (error) {
144
+ this.#ctx.options.logger.warn(
145
+ { [wish.kind]: wish.name, surface: provider.surface, err: error },
146
+ "place not checked; kept as it is",
147
+ );
148
+ return "unknown";
149
+ }
150
+ }
151
+
152
+ /** Archives the owner of a place the provider reports deleted, once it says so. */
153
+ #listen(provider: PlaceProvider): void {
154
+ const { places, queue, logger } = this.#ctx.options;
155
+ if (!provider.onRemoved || this.#listening.has(provider.surface)) return;
156
+ this.#listening.add(provider.surface);
157
+ provider.onRemoved((id) => {
158
+ if (this.#stopped.signal.aborted) return;
159
+ const key = places.keyOfId(provider.surface, id);
160
+ if (key === undefined || !places.ownerKind(key)) return;
161
+ void queue
162
+ .run(key, () => this.placeRemoved(key))
163
+ .catch((error: unknown) =>
164
+ logger.error({ channel: key, err: error }, "archive failed"),
165
+ );
166
+ });
167
+ }
168
+
169
+ /** The owner of a place as a place wish: who it belongs to and the texts it is shown under. */
170
+ #wish(owner: Agent | AgentGroup): PlaceWish {
171
+ const { store } = this.#ctx.options;
172
+ const group = "members" in owner;
173
+ return {
174
+ kind: group ? "group" : "agent",
175
+ name: owner.name,
176
+ displayName: owner.displayName,
177
+ topic: group ? groupTopic(owner, store) : owner.displayName,
178
+ };
179
+ }
180
+
181
+ /** Makes the owner's place on a provider that makes them, and records it. */
182
+ async #make(provider: PlaceProvider, wish: PlaceWish): Promise<void> {
183
+ if (!provider.ensure) return;
184
+ const id = await provider.ensure({ ...wish });
185
+ await this.#record(provider, wish, id);
186
+ this.#ctx.options.logger.info(
187
+ { [wish.kind]: wish.name, surface: provider.surface, place: id },
188
+ `${wish.kind} place created`,
189
+ );
190
+ }
191
+
192
+ #record(provider: PlaceProvider, wish: PlaceWish, id: string): Promise<void> {
193
+ return this.#places.record(wish, [{ surface: provider.surface, id }]);
194
+ }
195
+
196
+ /** Forgets the owner's place on the provider's surface, which another server's channel is. */
197
+ async #drop(provider: PlaceProvider, wish: PlaceWish): Promise<void> {
198
+ await this.#ctx.options.store.clearPlace(
199
+ wish.kind,
200
+ wish.name,
201
+ provider.surface,
202
+ );
203
+ this.#ctx.options.logger.warn(
204
+ { [wish.kind]: wish.name, surface: provider.surface },
205
+ `${wish.kind} place is another server's; dropped`,
206
+ );
207
+ }
208
+
114
209
  /**
115
210
  * Dresses every active agent that has no character: the seed of that name gives it (its fields
116
211
  * over what the role suggests), otherwise the suggestion for the role, spread over the looks
@@ -175,19 +270,19 @@ export class TeamLifecycle {
175
270
 
176
271
  // ── Archive ────────────────────────────────────────────────────────────
177
272
 
178
- /** A deleted channel archives the agent or group that owned it. */
179
- async channelDeleted(channelId: string): Promise<void> {
180
- const { store } = this.#ctx.options;
181
- const agent = store.agentByChannel(channelId);
273
+ /** A place deleted on its surface archives the agent or group that owned it. */
274
+ async placeRemoved(key: ChannelKey): Promise<void> {
275
+ const { places } = this.#ctx.options;
276
+ const agent = places.agentOf(key);
182
277
  if (agent) return this.#archiveAgent(agent);
183
- const group = store.groupByChannel(channelId);
278
+ const group = places.groupOf(key);
184
279
  if (group) await this.#archiveGroup(group);
185
280
  }
186
281
 
187
282
  /**
188
- * Archives an agent or group like a deleted channel, then keeps its channel under Archive,
189
- * where no one owns it and so nothing answers; an agent or group without a Discord channel
190
- * only stops answering in its rooms. Runs at once, not in the target's queue: the caller may be
283
+ * Archives an agent or group like a deleted place, then keeps its places where no one owns them
284
+ * and so nothing answers (a channel under Archive, for one); an agent or group without a
285
+ * stored place only stops answering in its rooms. Runs at once, not in the target's queue: the caller may be
191
286
  * a member of the group it archives, and the round stops at its next turn. An owner's call from
192
287
  * outside any turn has no `caller`, so no agent is protected from archiving itself.
193
288
  */
@@ -195,7 +290,7 @@ export class TeamLifecycle {
195
290
  caller: AgentTurnScope | undefined,
196
291
  name: string,
197
292
  ): Promise<string> {
198
- const { store, channels, logger } = this.#ctx.options;
293
+ const { store } = this.#ctx.options;
199
294
  const agent = store.agent(name);
200
295
  const group = agent ? undefined : store.group(name);
201
296
  const target = agent ?? group;
@@ -213,7 +308,6 @@ export class TeamLifecycle {
213
308
  throw new AgentError("The coordinator cannot be archived.");
214
309
  if (agent && name === caller?.name)
215
310
  throw new AgentError("You cannot archive yourself; ask another agent.");
216
- const { channelId } = target;
217
311
  // A temp knight's place is a thread of its parent's channel, closed rather than moved.
218
312
  if (agent && isHelper(agent)) {
219
313
  await this.helpers.archiveOne(agent);
@@ -221,32 +315,17 @@ export class TeamLifecycle {
221
315
  }
222
316
  if (agent) await this.#archiveAgent(agent);
223
317
  else if (group) await this.#archiveGroup(group);
224
- if (!channelId || !channels)
225
- return `Archived "${target.displayName}"; it no longer answers anywhere.`;
226
- try {
227
- await channels.removeWebhook(channelId);
228
- } catch (error) {
229
- logger.warn(
230
- { name, err: error },
231
- "archived channel's webhook not removed",
232
- );
233
- }
234
- try {
235
- await channels.placeIn(channelId, "Archive");
236
- } catch (error) {
237
- logger.error({ name, err: error }, "archived channel not moved");
238
- return `Archived "${target.displayName}", but its channel <#${channelId}> could not be moved to Archive (${error instanceof Error ? error.message : String(error)}); it stays silent where it is.`;
239
- }
240
- return `Archived "${target.displayName}"; its channel <#${channelId}> is kept under Archive.`;
318
+ const kept = await this.#places.keep(this.#wish(target), false);
319
+ return `Archived "${target.displayName}"${kept || "; it no longer answers anywhere."}`;
241
320
  }
242
321
 
243
322
  /**
244
- * Returns an archived agent or group to the active ones: its channel leaves Archive for its
245
- * category (a new channel replaces one deleted meanwhile), and it answers again from its next
323
+ * Returns an archived agent or group to the active ones: its places leave the archive for where
324
+ * they belong (a new place replaces one deleted meanwhile), and it answers again from its next
246
325
  * message. An agent does not rejoin the groups it left; a group needs all its members active.
247
326
  */
248
327
  async restore(name: string): Promise<string> {
249
- const { store, channels, logger } = this.#ctx.options;
328
+ const { store, logger } = this.#ctx.options;
250
329
  const agent = store.agent(name);
251
330
  const group = agent ? undefined : store.group(name);
252
331
  const target = agent ?? group;
@@ -262,25 +341,12 @@ export class TeamLifecycle {
262
341
  }
263
342
  if (group) store.checkRestorableGroup(name);
264
343
  // The store checks again when it restores. A member archived, or a second restore of the
265
- // same name, between the two checks leaves the channel moved or made with no owner; it
266
- // then waits under its category until the next restore claims it or an owner deletes it.
267
- let { channelId } = target;
268
- if (channels) {
269
- const category = agent ? "Agents" : "Groups";
270
- if (channelId && (await channels.exists(channelId)))
271
- await channels.placeIn(channelId, category);
272
- else if (agent || channelId)
273
- channelId = await channels.createChannel(
274
- name,
275
- agent ? agent.displayName : groupTopic(target as AgentGroup, store),
276
- category,
277
- );
278
- }
279
- if (agent) await store.restoreAgent(name, channelId);
280
- else {
281
- const restored = await store.restoreGroup(name, channelId);
282
- this.retitle(restored);
283
- }
344
+ // same name, between the two checks leaves the place moved or made with no owner; it
345
+ // then waits where it is until the next restore claims it or an owner deletes it.
346
+ const wish = this.#wish(target);
347
+ await this.#places.record(wish, await this.#places.bringBack(wish));
348
+ if (agent) await store.restoreAgent(name);
349
+ else this.retitle(await store.restoreGroup(name));
284
350
  logger.info({ name, kind: agent ? "agent" : "group" }, "restored");
285
351
  this.#ctx.changed();
286
352
  return `Restored "${target.displayName}"; it answers again.${agent ? " It is in no group until it is added to one." : ""}`;
@@ -290,8 +356,8 @@ export class TeamLifecycle {
290
356
  * Deletes an archived agent or group for good, its name free again. Its carried skills are
291
357
  * detached, and the runtime forgets its conversations (an agent's own, its seats in every
292
358
  * group, a group's members' seats), so nothing is left for a later agent or group of that name;
293
- * a Discord channel it had stays under Archive with its history, since Discord is never asked
294
- * to delete one. An active agent or group is refused: archive it first, and so is an
359
+ * a place it had stays kept with its history on its surface, since no provider is asked to
360
+ * delete one. An active agent or group is refused: archive it first, and so is an
295
361
  * agent the host's seeds name, since the next start would seed it again.
296
362
  */
297
363
  async remove(name: string, cleanup?: () => Promise<void>): Promise<string> {
@@ -371,18 +437,8 @@ export class TeamLifecycle {
371
437
  this.#ctx.changed();
372
438
  }
373
439
 
374
- /** Writes a group's members and host into its channel topic, without waiting on Discord; a group without a channel has no topic. */
440
+ /** Writes a group's members and host into the topic of its places, without waiting on the surface; a group without a place has no topic. */
375
441
  retitle(group: AgentGroup): void {
376
- const { channels, store, logger } = this.#ctx.options;
377
- const { channelId } = group;
378
- if (!channels || !channelId) return;
379
- channels
380
- .setTopic(channelId, groupTopic(group, store))
381
- .catch((error: unknown) =>
382
- logger.warn(
383
- { group: group.name, err: error },
384
- "group topic not updated",
385
- ),
386
- );
442
+ this.#places.describe(this.#wish(group));
387
443
  }
388
444
  }
@@ -0,0 +1,102 @@
1
+ import {
2
+ CharacterError,
3
+ type CharacterInput,
4
+ type CharacterSpec,
5
+ resolveCharacter,
6
+ } from "../../characters/index.ts";
7
+ import { AgentError } from "../domain/errors.ts";
8
+ import { characterOf, overBase } from "./agent-rules.ts";
9
+ import type { Agent } from "./agent-store.ts";
10
+ import type { AvatarMode } from "./agent-tools.ts";
11
+ import type { TeamContext } from "./team-options.ts";
12
+
13
+ /** Said when an avatar is to be redrawn on a host without an image provider. */
14
+ const NO_IMAGE_PROVIDER =
15
+ "No image provider is configured, so avatars cannot be redrawn; the current picture stays. A plugin fills the images slot to draw them.";
16
+
17
+ /** An input over a base look (see overBase); a bad field is an AgentError that names it. */
18
+ export function resolveLook(
19
+ input: CharacterInput,
20
+ base: CharacterSpec,
21
+ ): CharacterSpec {
22
+ try {
23
+ return resolveCharacter(overBase(input, base), base);
24
+ } catch (error) {
25
+ if (error instanceof CharacterError)
26
+ throw new AgentError(`The look is not usable: ${error.message}.`);
27
+ throw error;
28
+ }
29
+ }
30
+
31
+ /** Changing an agent's look and picture. */
32
+ export class TeamLooks {
33
+ readonly #ctx: TeamContext;
34
+
35
+ constructor(ctx: TeamContext) {
36
+ this.#ctx = ctx;
37
+ }
38
+
39
+ /** The agent tool: changes a look, then says what the owner sees. */
40
+ async avatar(name: string, look: CharacterInput): Promise<string> {
41
+ const agent = await this.dress(name, look);
42
+ return `"${agent.displayName}" now looks like a ${characterOf(agent).class}; the new picture shows from its next message.`;
43
+ }
44
+
45
+ /**
46
+ * Changes an agent's look. The input is resolved over the agent's current character; a new
47
+ * class keeps the agent's colors unless the input names a palette or colors. The picture is
48
+ * rendered before anything is stored, and the character and picture are stored together.
49
+ */
50
+ async dress(name: string, input: CharacterInput): Promise<Agent> {
51
+ const { store, studio, logger } = this.#ctx.options;
52
+ const agent = store.activeAgent(name);
53
+ const base = characterOf(agent);
54
+ const character = resolveLook(input, base);
55
+ let avatarHash: string;
56
+ try {
57
+ avatarHash = await studio.render(character);
58
+ } catch (error) {
59
+ throw new AgentError(
60
+ `The picture could not be rendered: ${error instanceof Error ? error.message : String(error)}. The previous look stays.`,
61
+ );
62
+ }
63
+ const dressed = await store.updateAgent(name, { character, avatarHash });
64
+ logger.info({ agent: name, class: character.class }, "agent dressed");
65
+ this.#ctx.changed();
66
+ return dressed;
67
+ }
68
+
69
+ /** @deprecated Use `dress`; removed in 1.0. Draws and stores a new picture. */
70
+ async redrawAvatar(
71
+ name: string,
72
+ mode: AvatarMode,
73
+ text?: string,
74
+ ): Promise<Agent> {
75
+ const { store, studio, logger } = this.#ctx.options;
76
+ const agent = store.activeAgent(name);
77
+ if (studio.canDraw === false) throw new AgentError(NO_IMAGE_PROVIDER);
78
+ if (mode !== "redraw" && !text?.trim())
79
+ throw new AgentError(
80
+ mode === "edit"
81
+ ? "Give the edit instruction as text."
82
+ : "Give the new avatar prompt as text.",
83
+ );
84
+ const avatarPrompt =
85
+ mode === "new_prompt" ? (text as string) : agent.avatarPrompt;
86
+ if (mode === "new_prompt") await store.updateAgent(name, { avatarPrompt });
87
+ let hash: string;
88
+ try {
89
+ hash =
90
+ mode === "edit"
91
+ ? await studio.edit(agent.avatarHash, text as string)
92
+ : await studio.draw(avatarPrompt);
93
+ } catch (error) {
94
+ logger.warn({ agent: name, mode, err: error }, "avatar drawing failed");
95
+ throw new AgentError(
96
+ `The avatar could not be drawn: ${error instanceof Error ? error.message : String(error)}. The previous picture stays.`,
97
+ );
98
+ }
99
+ logger.info({ agent: name, mode }, "avatar redrawn");
100
+ return store.updateAgent(name, { avatarHash: hash });
101
+ }
102
+ }
@@ -4,21 +4,20 @@ import type { ChannelKey } from "../domain/conversation.ts";
4
4
  import type { ThinkingSetting } from "../domain/models.ts";
5
5
  import type { ToolSelection } from "../domain/sessions.ts";
6
6
  import type { ConversationModes } from "../modes/conversation-modes.ts";
7
+ import type { FormerChannelOps } from "../plugin-api/agent-ops.ts";
7
8
  import type { AgentTools, PromptSection } from "../plugin-api/plugin.ts";
8
9
  import type { AvatarStudio, SkillRegistry } from "../plugin-api/services.ts";
9
- import type { AgentChannels, AgentModels } from "./agent-ports.ts";
10
+ import type { AgentModels } from "./agent-ports.ts";
10
11
  import type { AgentGroup, AgentSeed } from "./agent-store.ts";
11
12
  import type { TeamTurns, TeamTurnsOptions } from "./team-turns.ts";
12
13
 
13
14
  export interface AgentTeamOptions
14
15
  extends Omit<TeamTurnsOptions, "selection" | "changed"> {
15
16
  /**
16
- * The team's id: the Discord guild, or `LOCAL_TEAM_ID` on a host without Discord. It scopes the
17
- * rows the team keeps.
17
+ * The team's id: the agent guild of the host, or `LOCAL_TEAM_ID` on a host without one. It
18
+ * scopes the rows the team keeps.
18
19
  */
19
20
  teamId: string;
20
- /** The Discord guild the team's channels live in, which is not the team's id when the host sets one; absent without Discord channels. */
21
- discordGuild?: string | undefined;
22
21
  /** The first team, read and inserted once on start; an agent already stored is never overwritten. */
23
22
  seeds: () => readonly AgentSeed[];
24
23
  /** Sections the plugins add to every agent turn's system prompt, read before each run. */
@@ -27,11 +26,8 @@ export interface AgentTeamOptions
27
26
  agentTools?: AgentTools;
28
27
  /** The tools plugins defined for agents, read before each agent turn. */
29
28
  pluginTools?: () => readonly string[];
30
- /**
31
- * The Discord channels the agents live in; absent on a host without Discord. Then no channel is
32
- * made, arranged or read, and the agents live in the rooms of the surfaces that host them.
33
- */
34
- channels?: AgentChannels;
29
+ /** Those of `pluginTools` a temp knight's turns leave out. */
30
+ pluginWithheldFromHelpers?: () => readonly string[];
35
31
  /**
36
32
  * Agents are composed characters, rendered by `render`. `canDraw: false` marks a host without
37
33
  * an image provider, which is not told about generate_image; a studio that leaves it out has one.
@@ -75,6 +71,11 @@ export interface AgentTeamOptions
75
71
  helpers?: ResolvedHelpers | false;
76
72
  /** The app's room groups, read at each call; absent or undefined, the tools refuse a room group. */
77
73
  rooms?: () => RoomLayoutService | undefined;
74
+ /**
75
+ * @deprecated What the team's own `arrange` and `read` run, read at each call: the side of the
76
+ * surface whose tools took their place. Absent or undefined, the two refuse. Removed in 1.0.
77
+ */
78
+ formerChannelOps?: () => FormerChannelOps | undefined;
78
79
  }
79
80
 
80
81
  /** What the team's collaborators share: its options, its turns, and its change signal. */
@@ -85,7 +86,7 @@ export interface TeamContext {
85
86
  changed(): void;
86
87
  /** The model and thinking setting of an agent's next run. */
87
88
  modelOf(name: string): { model: string; thinking: ThinkingSetting };
88
- /** Writes a group's members and host into its channel topic, without waiting on Discord. */
89
+ /** Writes a group's members and host into the topic of its places, without waiting on the surface. */
89
90
  retitle(group: AgentGroup): void;
90
91
  /** Archives temp knights, closing their threads; says which were archived. */
91
92
  archiveHelpers(names: readonly string[]): Promise<string[]>;