pi-roundtable 0.45.1 → 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 +41 -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,6 +3,7 @@ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { SQL } from "bun";
6
+ import { discordKey } from "../contract/discord-key.ts";
6
7
  import type { PlaceProvider } from "../contract/places.ts";
7
8
  import type { ChatSurface } from "../contract/surface.ts";
8
9
  import { NO_ATTACHMENTS } from "../domain/attachment.ts";
@@ -27,14 +28,17 @@ import {
27
28
  } from "../testing/database.ts";
28
29
  import { useTestLocale } from "../testing/locale.ts";
29
30
  import { OWNER_SPEAKER, TEST_OWNER } from "../testing/owner.ts";
30
- import { discordTestPlaces, testPlacePort } from "../testing/team-places.ts";
31
+ import {
32
+ discordTestChannelOps,
33
+ discordTestPlaces,
34
+ testPlacePort,
35
+ } from "../testing/team-places.ts";
31
36
  import { PgAgentStore as AgentStore } from "./agent-store.ts";
32
37
  import {
33
- DiscordAgentTeam as AgentTeam,
38
+ AgentServerTeam as AgentTeam,
34
39
  type AgentTeamOptions,
35
40
  } from "./agent-team.ts";
36
41
  import { seeds } from "./agent-team-seeds.ts";
37
- import { discordKey } from "./team-keys.ts";
38
42
  import { TeamPlaces } from "./team-places.ts";
39
43
 
40
44
  export const ENTRY = "1000";
@@ -94,10 +98,10 @@ class FakeSurfaces {
94
98
  }
95
99
  }
96
100
 
97
- export { FakeChannels } from "./agent-team-fake-channels.ts";
101
+ export { FakeChannels } from "../testing/fake-agent-channels.ts";
98
102
  export { FakeRuntime } from "./agent-team-fake-runtime.ts";
99
103
 
100
- import { FakeChannels } from "./agent-team-fake-channels.ts";
104
+ import { FakeChannels } from "../testing/fake-agent-channels.ts";
101
105
 
102
106
  import { FakeRuntime } from "./agent-team-fake-runtime.ts";
103
107
 
@@ -140,6 +144,7 @@ export const script: {
140
144
  prompt: PromptSection[];
141
145
  /** The tools plugins defined for agents. */
142
146
  tools: string[];
147
+ withheld: string[];
143
148
  /** The prompt every agent's starts with; read before each turn, so a test may change it. */
144
149
  shared: string;
145
150
  /** The one a speaker other than the owner gets instead; empty falls back to `shared`. */
@@ -148,6 +153,7 @@ export const script: {
148
153
  scores: undefined,
149
154
  prompt: [],
150
155
  tools: [],
156
+ withheld: [],
151
157
  shared: "Shared rules.",
152
158
  guest: "",
153
159
  };
@@ -158,6 +164,8 @@ let skillStore: TestStore<SkillStore>;
158
164
  let skills: SkillRegistry;
159
165
  let places: TeamPlaces;
160
166
  const stored: PlaceProvider[] = [];
167
+ /** The listeners the stand-in Discord was given for a deleted channel; `deleteChannel` calls them, as the server does. */
168
+ const removedListeners: ((channelId: string) => void)[] = [];
161
169
  export const removedSchedules: number[] = [];
162
170
  export const stops: string[] = [];
163
171
  /** The events the team reported, in order, as `turnStarted infra`, `turnEnded infra ok`, or `changed`. */
@@ -254,13 +262,32 @@ export function useTeamFixture(
254
262
  if (local) surfaces.rooms = ["app"];
255
263
  runtime = new FakeRuntime();
256
264
  stored.length = 0;
265
+ removedListeners.length = 0;
257
266
  // The host's providers: Discord's channels with a guild, a room on each surface that hosts them, and a test's own.
258
267
  places = new TeamPlaces(
259
268
  store,
260
269
  store.places,
261
270
  testPlacePort({
262
271
  rooms: () => surfaces.rooms,
263
- stored: () => [...(local ? [] : [discordTestPlaces()]), ...stored],
272
+ stored: () => [
273
+ ...(local
274
+ ? []
275
+ : [
276
+ discordTestPlaces(TEST_GUILD, {
277
+ channels,
278
+ server: {
279
+ gone: (id) => channels.deleted.has(id),
280
+ foreign: (id) => channels.foreign.has(id),
281
+ fails: (id) => channels.failing.has(id),
282
+ },
283
+ onRemoved: (listener) => removedListeners.push(listener),
284
+ nameOf: (id) =>
285
+ store.agentByChannel(id)?.name ??
286
+ store.groupByChannel(id)?.name,
287
+ }),
288
+ ]),
289
+ ...stored,
290
+ ],
264
291
  // SAFETY: only a derived provider's post reads it, which the team does not use yet.
265
292
  surfaces: surfaces as never,
266
293
  }),
@@ -269,6 +296,7 @@ export function useTeamFixture(
269
296
  script.scores = undefined;
270
297
  script.prompt = [];
271
298
  script.tools = [];
299
+ script.withheld = [];
272
300
  script.shared = "Shared rules.";
273
301
  script.guest = "";
274
302
  queue = channelQueue();
@@ -286,7 +314,7 @@ export function useTeamFixture(
286
314
  teamId: local ? "local" : "1",
287
315
  ...(local
288
316
  ? { coordinator: "coordinator" }
289
- : { entryChannelId: ENTRY, channels }),
317
+ : { entryChannel: discordKey(ENTRY) }),
290
318
  seeds: () => seeds(local ? undefined : ENTRY),
291
319
  store,
292
320
  surfaces,
@@ -311,6 +339,7 @@ export function useTeamFixture(
311
339
  },
312
340
  promptSections: () => script.prompt,
313
341
  pluginTools: () => script.tools,
342
+ pluginWithheldFromHelpers: () => script.withheld,
314
343
  models: {
315
344
  defaults: {
316
345
  model: "claude-bridge/claude-opus-5-5",
@@ -338,6 +367,12 @@ export function useTeamFixture(
338
367
  guestPrompt: () => script.guest,
339
368
  skills,
340
369
  ...(options.helpers !== undefined ? { helpers: options.helpers } : {}),
370
+ // Discord's side of the deprecated `arrange` and `read`, as the host hands it with a guild.
371
+ ...(local
372
+ ? {}
373
+ : {
374
+ formerChannelOps: () => discordTestChannelOps(channels, store),
375
+ }),
341
376
  logger: silentLogger(),
342
377
  });
343
378
  team = build();
@@ -358,6 +393,12 @@ export function useTeamFixture(
358
393
  }, HOOK_TIMEOUT_MS);
359
394
  }
360
395
 
396
+ /** The server deletes a channel and tells the listeners the team registered. */
397
+ export function deleteChannel(channelId: string): void {
398
+ channels.deleted.add(channelId);
399
+ for (const listener of removedListeners) listener(channelId);
400
+ }
401
+
361
402
  /** Starts the team again over the same database, as a restarted host: a new queue, runtime and team. */
362
403
  /** The identity service the team's replay asks; none until a test sets one. */
363
404
  export const identity: { current?: Pick<IdentityService, "speakerFor"> } = {};
@@ -10,10 +10,15 @@ import type { TurnSelection } from "../domain/sessions.ts";
10
10
  import { type Speaker, THE_SPEAKER } from "../identity/speakers.ts";
11
11
  import type { PromptVersion } from "../modules/prompts/prompt-history.ts";
12
12
  import type { ResolvedSkill } from "../modules/skills/skill-rules.ts";
13
+ import {
14
+ type AgentOps,
15
+ type FormerChannelOps,
16
+ NO_CHANNELS,
17
+ } from "../plugin-api/agent-ops.ts";
13
18
  import type { AgentChange, AgentTeam } from "../plugin-api/services.ts";
14
19
  import type { Agent } from "./agent-store.ts";
15
20
  import {
16
- type AgentOps,
21
+ type AgentToolOptions,
17
22
  type AvatarMode,
18
23
  agentToolsExtension,
19
24
  } from "./agent-tools.ts";
@@ -24,23 +29,14 @@ import { type Routes, routesOf } from "./routes.ts";
24
29
  import { TeamEditing } from "./team-editing.ts";
25
30
  import type { TeamHelpers } from "./team-helpers.ts";
26
31
  import { coordinatorOf } from "./team-keys.ts";
27
- import {
28
- layoutText,
29
- planArrangement,
30
- resolveArrangement,
31
- } from "./team-layout.ts";
32
32
  import { TeamLifecycle } from "./team-lifecycle.ts";
33
+ import { TeamLooks } from "./team-looks.ts";
33
34
  import type { AgentTeamOptions, TeamContext } from "./team-options.ts";
34
35
  import { teamSystemPrompt } from "./team-prompt.ts";
35
36
  import { TeamRooms } from "./team-rooms.ts";
36
37
  import { teamSelection } from "./team-selection.ts";
37
38
  import { type TeamStatus, teamStatus } from "./team-status.ts";
38
- import {
39
- agentDetails,
40
- NO_CHANNELS,
41
- readChannel,
42
- teamListText,
43
- } from "./team-text.ts";
39
+ import { agentDetails, teamListText } from "./team-text.ts";
44
40
  import { TeamTurns } from "./team-turns.ts";
45
41
 
46
42
  export type { AgentTeamOptions } from "./team-options.ts";
@@ -51,13 +47,14 @@ export type { AgentStatus, GroupStatus, TeamStatus } from "./team-status.ts";
51
47
  * This team creates, changes, arranges, and archives agents and groups; its TeamTurns runs
52
48
  * their turns, group rounds, and messages between agents.
53
49
  */
54
- export class DiscordAgentTeam implements AgentOps, AgentTeam {
50
+ export class AgentServerTeam implements AgentOps, AgentTeam {
55
51
  readonly #options: AgentTeamOptions;
56
52
  readonly #turns: TeamTurns;
57
53
  readonly #listeners: (() => void)[] = [];
58
54
  readonly #context: TeamContext;
59
55
  readonly #lifecycle: TeamLifecycle;
60
56
  readonly #editing: TeamEditing;
57
+ readonly #looks: TeamLooks;
61
58
 
62
59
  constructor(options: AgentTeamOptions) {
63
60
  // One routing table for the team's turns and its editing.
@@ -80,6 +77,7 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
80
77
  };
81
78
  this.#lifecycle = new TeamLifecycle(this.#context);
82
79
  this.#editing = new TeamEditing(this.#context);
80
+ this.#looks = new TeamLooks(this.#context);
83
81
  }
84
82
 
85
83
  get teamId(): string {
@@ -91,11 +89,6 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
91
89
  return this.#options.teamId;
92
90
  }
93
91
 
94
- /** @deprecated The Discord guild is the Discord place provider's `space`; removed in 1.0. */
95
- get discordGuild(): string | undefined {
96
- return this.#options.discordGuild;
97
- }
98
-
99
92
  /** Called when a turn starts or ends and when an agent or group changes. */
100
93
  onChange(listener: () => void): void {
101
94
  this.#listeners.push(listener);
@@ -123,7 +116,7 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
123
116
 
124
117
  /**
125
118
  * Every key an agent or group is addressed by: its place on each provider's surface, in the
126
- * order "auto" routing prefers (its Discord channel first when it has one); empty for an unknown name.
119
+ * order "auto" routing prefers (a stored place first when it has one); empty for an unknown name.
127
120
  */
128
121
  roomsOf(name: string): ChannelKey[] {
129
122
  return this.#options.places.keysOf(name);
@@ -174,11 +167,20 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
174
167
  extension(scope: AgentTurnScope): ExtensionFactory {
175
168
  return agentToolsExtension(this, scope, THE_SPEAKER, {
176
169
  skills: this.#options.skills !== undefined,
177
- channels: this.#options.channels !== undefined,
170
+ arguments: this.#createArguments(),
178
171
  rooms: new TeamRooms(this.#options.store, () => this.#options.rooms?.()),
179
172
  });
180
173
  }
181
174
 
175
+ /** What the surfaces' place providers add to the creation tools, merged over the stored providers in contribution order. */
176
+ #createArguments(): NonNullable<AgentToolOptions["arguments"]> {
177
+ const stored = this.#options.places.stored();
178
+ return {
179
+ agent: Object.assign({}, ...stored.map((p) => p.createArguments?.agent)),
180
+ group: Object.assign({}, ...stored.map((p) => p.createArguments?.group)),
181
+ };
182
+ }
183
+
182
184
  /** The skill files an agent's sessions load, built-in ones included; none while the skills addon is off. */
183
185
  skillsOf(name: string): ResolvedSkill[] {
184
186
  return this.#options.skills?.carried(name).skills ?? [];
@@ -233,12 +235,12 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
233
235
  return this.#lifecycle.startFresh(channel);
234
236
  }
235
237
 
236
- /** A deleted channel archives the agent or group that owned it. */
237
- channelDeleted(channelId: string): Promise<void> {
238
- return this.#lifecycle.channelDeleted(channelId);
238
+ /** A place deleted on its surface archives the agent or group that owned it. */
239
+ placeRemoved(key: ChannelKey): Promise<void> {
240
+ return this.#lifecycle.placeRemoved(key);
239
241
  }
240
242
 
241
- /** Archives an agent or group like a deleted channel, keeping its channel under Archive. */
243
+ /** Archives an agent or group like a deleted place, keeping its places where nothing answers. */
242
244
  archive(caller: AgentTurnScope | undefined, name: string): Promise<string> {
243
245
  return this.#lifecycle.archive(caller, name);
244
246
  }
@@ -316,42 +318,16 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
316
318
  return this.#lifecycle.helpers.reach(...args);
317
319
  }
318
320
 
319
- read(...args: [string, string | undefined, number | undefined]) {
320
- return readChannel(this.#options.channels, ...args);
321
- }
322
-
323
321
  // ── AgentOps ───────────────────────────────────────────────────────────
324
322
 
325
323
  async list(): Promise<string> {
326
- const { store, channels } = this.#options;
327
- const list = teamListText(store);
328
- return channels
329
- ? `${list}\n\n${layoutText(await channels.layout(), store)}`
330
- : list;
331
- }
332
-
333
- /**
334
- * Sorts agent and group channels into team categories and orders them (spec behavior 57):
335
- * the listed categories and channels first, everything else after in its current order. A
336
- * wrong entry refuses the whole call before anything moves.
337
- */
338
- async arrange(
339
- entries: { category: string; names: string[] }[],
340
- ): Promise<string> {
341
- const { store, channels, logger } = this.#options;
342
- if (!channels) throw new AgentError(NO_CHANNELS);
343
- const listed = resolveArrangement(entries, store);
344
- const { layout, remove } = planArrangement(listed, await channels.layout());
345
- await channels.arrange(layout, remove);
346
- logger.info(
347
- { entries: listed.map((l) => l.category), removed: remove.length },
348
- "agent channels arranged",
324
+ const sections = await Promise.all(
325
+ this.#options.places.stored().map((provider) => provider.layoutText?.()),
349
326
  );
350
- const removed =
351
- remove.length > 0
352
- ? ` ${remove.length} empty team categories were deleted.`
353
- : "";
354
- return `Arranged the channels.${removed}\n\n${layoutText(await channels.layout(), store)}`;
327
+ return [
328
+ teamListText(this.#options.store),
329
+ ...sections.filter((text) => text !== undefined),
330
+ ].join("\n\n");
355
331
  }
356
332
 
357
333
  get(name: string): string {
@@ -469,17 +445,17 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
469
445
 
470
446
  /** Changes an agent's look; see `AgentTeam.dress`. */
471
447
  dress(name: string, input: CharacterInput): Promise<Agent> {
472
- return this.#editing.dress(name, input);
448
+ return this.#looks.dress(name, input);
473
449
  }
474
450
 
475
451
  /** The agent tool that changes a look; see `AgentTeam.dress`. */
476
452
  avatar(name: string, look: CharacterInput): Promise<string> {
477
- return this.#editing.avatar(name, look);
453
+ return this.#looks.avatar(name, look);
478
454
  }
479
455
 
480
456
  /** @deprecated Use `dress`; removed in 1.0. Draws and stores a new picture. */
481
457
  redrawAvatar(name: string, mode: AvatarMode, text?: string): Promise<Agent> {
482
- return this.#editing.redrawAvatar(name, mode, text);
458
+ return this.#looks.redrawAvatar(name, mode, text);
483
459
  }
484
460
 
485
461
  createGroup(
@@ -494,4 +470,23 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
494
470
  ): Promise<string> {
495
471
  return this.#editing.updateGroup(name, change);
496
472
  }
473
+
474
+ /** The surface's side of `arrange` and `read`, which its own tools took over; refuses without one. */
475
+ #formerChannelOps(): FormerChannelOps {
476
+ const ops = this.#options.formerChannelOps?.();
477
+ if (!ops) throw new AgentError(NO_CHANNELS);
478
+ return ops;
479
+ }
480
+
481
+ /** @deprecated The surface that holds the channels contributes the tool; see `AgentOps.arrange`. Removed in 1.0. */
482
+ async arrange(
483
+ ...args: Parameters<FormerChannelOps["arrange"]>
484
+ ): Promise<string> {
485
+ return this.#formerChannelOps().arrange(...args);
486
+ }
487
+
488
+ /** @deprecated The surface that holds the channels contributes the tool; see `AgentOps.read`. Removed in 1.0. */
489
+ async read(...args: Parameters<FormerChannelOps["read"]>): Promise<string> {
490
+ return this.#formerChannelOps().read(...args);
491
+ }
497
492
  }
@@ -1,12 +1,12 @@
1
1
  import type { ExtensionFactory } from "@earendil-works/pi-coding-agent";
2
2
  import { Type } from "typebox";
3
- import type { CharacterInput } from "../../characters/index.ts";
3
+ import type { ToolArgument } from "../contract/places.ts";
4
4
  import { AgentError } from "../domain/errors.ts";
5
5
  import { THINKING_LEVELS } from "../domain/models.ts";
6
6
  import type { AgentTurnScope } from "../domain/ports.ts";
7
- import { assistantName, messages } from "../i18n/index.ts";
7
+ import { assistantName } from "../i18n/index.ts";
8
8
  import { type OwnerIdentity, ownerWords } from "../identity/owner-identity.ts";
9
- import { timeZone } from "../kernel/time.ts";
9
+ import type { AgentOps as TeamAgentOps } from "../plugin-api/agent-ops.ts";
10
10
  import {
11
11
  optionalString,
12
12
  requiredString,
@@ -24,7 +24,6 @@ import {
24
24
  PARTS,
25
25
  PROMPT,
26
26
  } from "./agent-tool-schema.ts";
27
- import type { HelperFields, PresetAction } from "./helper-preset-ops.ts";
28
27
  import { helperToolDefs } from "./helper-tools.ts";
29
28
  import { placedAfter, ROOM_GROUP, roomToolDefs } from "./room-tools.ts";
30
29
  import type { RoomOps } from "./team-rooms.ts";
@@ -55,14 +54,13 @@ export const AGENT_TOOLS = [
55
54
  "group_create",
56
55
  "group_update",
57
56
  "archive",
58
- "channel_arrange",
59
57
  "room_arrange",
60
- "channel_read",
61
58
  ] as const;
62
59
 
63
60
  /**
64
61
  * The tools a temp knight's turns do not get: making knights, temp knights or groups, archiving,
65
- * arranging channels and rooms, and scheduling, which would leave work behind with no one to end it.
62
+ * arranging rooms, and scheduling, which would leave work behind with no one to end it. Tools a
63
+ * plugin adds, such as a surface's arranging of its places, say so with `withheldFromHelpers`.
66
64
  */
67
65
  export const WITHHELD_FROM_HELPERS: readonly string[] = [
68
66
  "agent_create",
@@ -70,7 +68,6 @@ export const WITHHELD_FROM_HELPERS: readonly string[] = [
70
68
  "group_create",
71
69
  "group_update",
72
70
  "archive",
73
- "channel_arrange",
74
71
  "room_arrange",
75
72
  "schedule_create",
76
73
  ];
@@ -81,94 +78,9 @@ export const WITHHELD_FROM_HELPERS: readonly string[] = [
81
78
  */
82
79
  export type AvatarMode = "redraw" | "new_prompt" | "edit";
83
80
 
84
- /** What the agent tools do; the agent team implements it. Each returns text for the model. */
85
- export interface AgentOps {
86
- list(): Promise<string>;
87
- get(name: string): string;
88
- update(
89
- name: string,
90
- change: {
91
- displayName?: string;
92
- prompt?: string;
93
- model?: string;
94
- thinking?: string;
95
- },
96
- /** Who changes it: the agent whose turn asks, for the prompt history. */
97
- by?: string,
98
- ): Promise<string>;
99
- create(
100
- caller: AgentTurnScope,
101
- input: {
102
- name: string;
103
- displayName: string;
104
- prompt: string;
105
- /** Fields of its look; any left out come from the look its role suggests. */
106
- character?: CharacterInput;
107
- task: string;
108
- category?: string;
109
- skills?: string[];
110
- /** Turn long-running mode on for its conversations; an owner's turn only. */
111
- longRunning?: boolean;
112
- },
113
- ): Promise<string>;
114
- /** Makes a temp knight of the caller for one task; the answer returns to the caller's conversation. */
115
- helperCreate(
116
- caller: AgentTurnScope,
117
- input: HelperFields & { name?: string; task: string },
118
- ): Promise<string>;
119
- /** Saves, lists, or deletes the caller's own temp-knight presets. */
120
- helperPreset(caller: AgentTurnScope, action: PresetAction): Promise<string>;
121
- /** Archives the caller's own temp knights: the named ones, or every one that is finished. */
122
- helperEnd(
123
- caller: AgentTurnScope,
124
- names: readonly string[] | "finished",
125
- ): Promise<string>;
126
- /** Changes an agent's look; a field left out stays as it is. */
127
- avatar(name: string, look: CharacterInput): Promise<string>;
128
- /** Queues the message and returns at once. */
129
- /**
130
- * Hands a request to another agent, in its conversation on the sender's surface, or in the
131
- * `conversation` named: "discord", "web" (or a room surface's name), or one of its conversation keys.
132
- */
133
- message(
134
- caller: AgentTurnScope,
135
- to: string,
136
- text: string,
137
- conversation?: string,
138
- ): string;
139
- /**
140
- * Readies the place a message is about to reach: a temp knight made in the web app gets its
141
- * Discord thread when the caller may message it and names "discord". Never rejects.
142
- */
143
- reach?(
144
- caller: AgentTurnScope,
145
- to: string,
146
- conversation?: string,
147
- ): Promise<void>;
148
- createGroup(input: {
149
- name: string;
150
- displayName: string;
151
- members: string[];
152
- host?: string;
153
- category?: string;
154
- }): Promise<string>;
155
- updateGroup(
156
- name: string,
157
- change: { displayName?: string; members?: string[]; host?: string },
158
- ): Promise<string>;
159
- archive(caller: AgentTurnScope, name: string): Promise<string>;
160
- arrange(entries: { category: string; names: string[] }[]): Promise<string>;
161
- read(
162
- channel: string,
163
- around: string | undefined,
164
- limit: number | undefined,
165
- ): Promise<string>;
166
- }
81
+ /** What the agent tools call of the team: `AgentOps` without the two calls a surface's own tools took over. */
82
+ export type AgentOps = Omit<TeamAgentOps, "arrange" | "read">;
167
83
 
168
- const category = (kind: "Agents" | "Groups") =>
169
- Type.String({
170
- description: `Discord only: the category its channel opens under, ${kind} (the default) or ${kind}-<suffix>, such as ${kind}-work; made when missing. Keep to the categories agent_list shows unless a new one fits better. The app's room groups follow group.`,
171
- });
172
84
  const MEMBERS = Type.Array(Type.String(), {
173
85
  minItems: MIN_GROUP_MEMBERS,
174
86
  maxItems: MAX_GROUP_MEMBERS,
@@ -183,18 +95,35 @@ export interface AgentToolOptions {
183
95
  skills: boolean;
184
96
  /** The app's room groups; without them `group` and room_arrange are refused. */
185
97
  rooms?: RoomOps;
186
- /** Whether the team has Discord channels; without them no `category`, channel_arrange or channel_read. */
187
- channels: boolean;
98
+ /**
99
+ * The arguments the surfaces' place providers add to the creation tools (`createArguments`),
100
+ * merged in after the tool's own and left out where no provider adds any.
101
+ */
102
+ arguments?: {
103
+ agent?: Readonly<Record<string, ToolArgument>>;
104
+ group?: Readonly<Record<string, ToolArgument>>;
105
+ };
188
106
  }
189
107
 
190
- /** The tools that work on the team's Discord channels, left out of a team without them. */
191
- const CHANNEL_TOOLS: readonly string[] = ["channel_arrange", "channel_read"];
108
+ /** The values the model gave the provider-added arguments, by name; those it left out are absent. */
109
+ function hintsOf(
110
+ input: Record<string, unknown>,
111
+ added: Readonly<Record<string, ToolArgument>> | undefined,
112
+ ): { hints?: Readonly<Record<string, string>> } {
113
+ const hints = Object.fromEntries(
114
+ Object.keys(added ?? {}).flatMap((name) => {
115
+ const value = optionalString(input, name);
116
+ return value ? [[name, value] as const] : [];
117
+ }),
118
+ );
119
+ return Object.keys(hints).length > 0 ? { hints } : {};
120
+ }
192
121
 
193
122
  function toolDefs(
194
123
  ops: AgentOps,
195
124
  scope: AgentTurnScope,
196
125
  owner: OwnerIdentity,
197
- { skills: skillsOn, rooms, channels }: AgentToolOptions,
126
+ { skills: skillsOn, rooms, arguments: added }: AgentToolOptions,
198
127
  ): AgentToolDef[] {
199
128
  const o = ownerWords(owner);
200
129
  const defs: AgentToolDef[] = [
@@ -278,7 +207,7 @@ function toolDefs(
278
207
  maxLength: 4000,
279
208
  description: "Its opening task, self-contained.",
280
209
  }),
281
- ...(channels ? { category: Type.Optional(category("Agents")) } : {}),
210
+ ...added?.agent,
282
211
  group: Type.Optional(ROOM_GROUP),
283
212
  long_running: Type.Optional(
284
213
  Type.Boolean({
@@ -297,7 +226,6 @@ function toolDefs(
297
226
  : {}),
298
227
  }),
299
228
  run: (i) => {
300
- const category = optionalString(i, "category");
301
229
  const skills = stringList(i, "skills");
302
230
  const look = lookOf(i);
303
231
  const longRunning = i.long_running === true;
@@ -309,7 +237,7 @@ function toolDefs(
309
237
  prompt: requiredString(i, "prompt"),
310
238
  ...(Object.keys(look).length > 0 ? { character: look } : {}),
311
239
  task: requiredString(i, "task"),
312
- ...(category ? { category } : {}),
240
+ ...hintsOf(i, added?.agent),
313
241
  ...(skills && skills.length > 0 ? { skills } : {}),
314
242
  ...(longRunning ? { longRunning } : {}),
315
243
  }),
@@ -344,12 +272,11 @@ function toolDefs(
344
272
  display_name: DISPLAY,
345
273
  members: MEMBERS,
346
274
  host: Type.Optional(NAME),
347
- ...(channels ? { category: Type.Optional(category("Groups")) } : {}),
275
+ ...added?.group,
348
276
  group: Type.Optional(ROOM_GROUP),
349
277
  }),
350
278
  run: (i) => {
351
279
  const host = optionalString(i, "host");
352
- const category = optionalString(i, "category");
353
280
  const name = requiredString(i, "name");
354
281
  return placedAfter(rooms, name, optionalString(i, "group"), () =>
355
282
  ops.createGroup({
@@ -357,7 +284,7 @@ function toolDefs(
357
284
  displayName: requiredString(i, "display_name"),
358
285
  members: stringList(i, "members") ?? [],
359
286
  ...(host ? { host } : {}),
360
- ...(category ? { category } : {}),
287
+ ...hintsOf(i, added?.group),
361
288
  }),
362
289
  );
363
290
  },
@@ -394,63 +321,7 @@ function toolDefs(
394
321
  }),
395
322
  run: (i) => ops.archive(scope, requiredString(i, "name")),
396
323
  },
397
- {
398
- name: "channel_arrange",
399
- label: "Arrange channels",
400
- description: `Sort agent and group channels into categories and order them, when ${o.name} asks. Agents go under Agents or Agents-<suffix>, groups under Groups or Groups-<suffix>; missing categories are made. The listed categories come first in the server in list order, then every other category as it was; in each listed category the listed channels come first in order, then its other channels as they were. Agents and Groups categories left empty are deleted. Any wrong entry refuses the whole call and nothing moves. Read the current layout with agent_list first.`,
401
- parameters: Type.Object({
402
- categories: Type.Array(
403
- Type.Object({
404
- category: Type.String({
405
- description:
406
- "Agents, Groups, or either with -<suffix>, the suffix 1 to 32 characters in any language.",
407
- }),
408
- channels: Type.Array(Type.String(), {
409
- minItems: 1,
410
- description:
411
- "Agent or group names (from agent_list), in the order they should appear.",
412
- }),
413
- }),
414
- { minItems: 1, description: "Categories in server order." },
415
- ),
416
- }),
417
- run: (i) => {
418
- const entries = Array.isArray(i.categories) ? i.categories : [];
419
- return ops.arrange(
420
- entries.map((entry: Record<string, unknown>) => ({
421
- category: requiredString(entry, "category"),
422
- names: stringList(entry, "channels") ?? [],
423
- })),
424
- );
425
- },
426
- },
427
324
  ...roomToolDefs(rooms, o.name),
428
- {
429
- name: "channel_read",
430
- label: "Read channel",
431
- description: `Read messages of a text channel or thread of the agent server, oldest first, each with its id, ${messages().zoneTime(timeZone())}, author, text, and attachment names. Use it for the surroundings of a message ${o.name} forwarded to you: pass the source channel and the message id from the forwarded link. Read-only.`,
432
- parameters: Type.Object({
433
- channel: Type.String({
434
- description: "The channel as <#id> or its id.",
435
- }),
436
- around: Type.Optional(
437
- Type.String({
438
- pattern: "^\\d+$",
439
- description:
440
- "A message id: read the messages around it instead of the latest.",
441
- }),
442
- ),
443
- limit: Type.Optional(
444
- Type.Integer({ minimum: 1, maximum: 50, description: "Default 20." }),
445
- ),
446
- }),
447
- run: (i) =>
448
- ops.read(
449
- requiredString(i, "channel"),
450
- optionalString(i, "around"),
451
- typeof i.limit === "number" ? i.limit : undefined,
452
- ),
453
- },
454
325
  ];
455
326
  // In a group, members hand off by mentioning each other where everyone can see it.
456
327
  if (!scope.group)
@@ -486,8 +357,5 @@ export function agentToolsExtension(
486
357
  owner: OwnerIdentity,
487
358
  options: AgentToolOptions,
488
359
  ): ExtensionFactory {
489
- const defs = toolDefs(ops, scope, owner, options).filter(
490
- (def) => options.channels || !CHANNEL_TOOLS.includes(def.name),
491
- );
492
- return textToolsExtension(defs, AgentError);
360
+ return textToolsExtension(toolDefs(ops, scope, owner, options), AgentError);
493
361
  }