pi-roundtable 0.45.2 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/docs/plugins.md +33 -8
  3. package/package.json +2 -2
  4. package/src/characters/catalog.ts +1 -0
  5. package/src/characters/characters.css +2 -1
  6. package/src/characters/compose.ts +7 -3
  7. package/src/characters/css.ts +2 -1
  8. package/src/characters/index.ts +1 -0
  9. package/src/characters/parts-face.ts +14 -1
  10. package/src/core/agents/agent-claim.ts +2 -2
  11. package/src/core/agents/agent-group-store.ts +74 -1
  12. package/src/core/agents/agent-places.ts +32 -0
  13. package/src/core/agents/agent-ports.ts +0 -94
  14. package/src/core/agents/agent-prompt.ts +3 -1
  15. package/src/core/agents/agent-team-fixture.ts +74 -14
  16. package/src/core/agents/agent-team.ts +50 -59
  17. package/src/core/agents/agent-tools.ts +34 -166
  18. package/src/core/agents/message-target.ts +3 -2
  19. package/src/core/agents/routes.ts +2 -1
  20. package/src/core/agents/team-editing.ts +121 -150
  21. package/src/core/agents/team-helpers.ts +80 -59
  22. package/src/core/agents/team-keys.ts +16 -26
  23. package/src/core/agents/team-lifecycle.ts +155 -99
  24. package/src/core/agents/team-looks.ts +102 -0
  25. package/src/core/agents/team-options.ts +12 -11
  26. package/src/core/agents/team-place-writes.ts +215 -0
  27. package/src/core/agents/team-places.ts +30 -0
  28. package/src/core/agents/team-posts.ts +42 -73
  29. package/src/core/agents/team-selection.ts +10 -2
  30. package/src/core/agents/team-status.ts +3 -2
  31. package/src/core/agents/team-text.ts +14 -43
  32. package/src/core/agents/team-turn-types.ts +11 -16
  33. package/src/core/agents/team-turns.ts +7 -6
  34. package/src/core/builtin/agent-server-options.ts +27 -6
  35. package/src/core/builtin/agent-server.ts +69 -72
  36. package/src/core/builtin/discord.ts +60 -8
  37. package/src/core/builtin/modules.ts +2 -0
  38. package/src/core/config/agent-team.ts +5 -3
  39. package/src/core/contract/agent-channels.ts +105 -0
  40. package/src/core/contract/channels.ts +10 -4
  41. package/src/core/contract/discord-key.ts +15 -0
  42. package/src/core/contract/places.ts +28 -3
  43. package/src/core/db/legacy-channels.ts +31 -0
  44. package/src/core/db/team-move.ts +2 -2
  45. package/src/core/discord/agent-dashboard-service.ts +55 -0
  46. package/src/core/{agents → discord}/agent-dashboard.ts +28 -4
  47. package/src/core/discord/agent-discord.ts +1 -1
  48. package/src/core/discord/agent-guild.ts +141 -0
  49. package/src/core/{agents/team-layout.ts → discord/agent-layout.ts} +15 -31
  50. package/src/core/discord/agent-places.ts +52 -33
  51. package/src/core/discord/agent-tools.ts +237 -0
  52. package/src/core/discord/channel-operations.ts +2 -0
  53. package/src/core/discord/connection.ts +4 -1
  54. package/src/core/discord/discord-surface.ts +9 -14
  55. package/src/core/discord/place-fake-client.ts +59 -0
  56. package/src/core/host/define-roundtable.ts +7 -5
  57. package/src/core/modules/delegation/delegator.ts +5 -0
  58. package/src/core/plugin-api/agent-ops.ts +119 -0
  59. package/src/core/plugin-api/agent-server-ids.ts +9 -0
  60. package/src/core/plugin-api/define.ts +9 -0
  61. package/src/core/plugin-api/plugin.ts +2 -0
  62. package/src/core/plugin-api/services.ts +6 -0
  63. package/src/core/registry/contributions.ts +3 -0
  64. package/src/core/registry/places.ts +31 -1
  65. package/src/core/routing/channel-queue.ts +28 -12
  66. package/src/core/runtime/pi-agent-runtime.ts +1 -1
  67. package/src/core/runtime/runtime-plugin.ts +1 -0
  68. package/src/core/runtime/runtime-types.ts +6 -0
  69. package/src/core/{agents/agent-team-fake-channels.ts → testing/fake-agent-channels.ts} +5 -1
  70. package/src/core/testing/fake-pager-places.ts +16 -2
  71. package/src/core/testing/modules.ts +2 -1
  72. package/src/core/testing/place-contract.ts +3 -2
  73. package/src/core/testing/team-places.ts +73 -7
  74. package/src/core/testing/test-host.ts +20 -16
  75. package/src/discord/index.ts +5 -0
  76. package/src/kit/channels.ts +1 -2
  77. package/src/kit/support.ts +25 -7
  78. package/templates/adapters/web/package.json.tmpl +1 -1
  79. package/templates/package.json.tmpl +1 -1
@@ -0,0 +1,237 @@
1
+ import { Type } from "typebox";
2
+ import type {
3
+ AgentChannels,
4
+ ChannelMessage,
5
+ } from "../contract/agent-channels.ts";
6
+ import { discordIdOf, discordKey } from "../contract/discord-key.ts";
7
+ import { AgentError } from "../domain/errors.ts";
8
+ import { messages } from "../i18n/index.ts";
9
+ import { ownerWords } from "../identity/owner-identity.ts";
10
+ import { THE_SPEAKER } from "../identity/speakers.ts";
11
+ import type { Logger } from "../kernel/log.ts";
12
+ import { timeZone, zonedStamp } from "../kernel/time.ts";
13
+ import type { FormerChannelOps } from "../plugin-api/agent-ops.ts";
14
+ import {
15
+ defineTool,
16
+ type ToolContribution,
17
+ ToolRefusal,
18
+ } from "../plugin-api/define.ts";
19
+ import type { AgentDirectory, AgentServer } from "../plugin-api/services.ts";
20
+ import {
21
+ categoryLayoutText,
22
+ planArrangement,
23
+ resolveArrangement,
24
+ } from "./agent-layout.ts";
25
+
26
+ /** The most messages `channel_read` returns. */
27
+ const READ_LIMIT = 50;
28
+
29
+ /** One message as channel_read shows it: id, local time, author, text, attachments. */
30
+ export function messageLine(message: ChannelMessage): string {
31
+ const files =
32
+ message.attachments.length > 0
33
+ ? ` [attachments: ${message.attachments.join(", ")}]`
34
+ : "";
35
+ return `[${message.id}] ${zonedStamp(message.at)} ${message.author}: ${message.text}${files}`;
36
+ }
37
+
38
+ /** A channel given as `<#id>` or its id, as its id. */
39
+ export function channelIdFromRef(channel: string): string {
40
+ const id = /^<#(\d+)>$/.exec(channel.trim())?.[1] ?? channel.trim();
41
+ if (!/^\d+$/.test(id))
42
+ throw new AgentError(
43
+ "Give the channel as <#id> or its id, as in a forwarded message.",
44
+ );
45
+ return id;
46
+ }
47
+
48
+ /**
49
+ * What the Discord tools read of the team: the agents and groups by name, and which one a Discord
50
+ * channel is the place of, either way.
51
+ */
52
+ export interface DiscordTeamReads
53
+ extends Pick<AgentDirectory, "agent" | "group"> {
54
+ /** The name of the agent or group whose place the Discord channel is, whatever its status. */
55
+ ownerOf(channelId: string): string | undefined;
56
+ /** The Discord channel of an agent or group; undefined when it has none. */
57
+ channelOf(name: string): string | undefined;
58
+ }
59
+
60
+ /**
61
+ * The tools' reads over what the agent server builds. They go through the places: `placeOwner`
62
+ * and `placesOf`, and the deprecated Discord-only members (`agentByChannel`, `channelId`) only for
63
+ * a server written before places were providers, which has neither.
64
+ */
65
+ export function discordTeamReads(
66
+ server: Pick<AgentServer, "team" | "directory">,
67
+ ): DiscordTeamReads {
68
+ const { team, directory } = server;
69
+ return {
70
+ agent: (name) => directory.agent(name),
71
+ group: (name) => directory.group(name),
72
+ ownerOf: (id) =>
73
+ directory.placeOwner
74
+ ? directory.placeOwner(discordKey(id))?.name
75
+ : (directory.agentByChannel(id)?.name ??
76
+ directory.groupByChannel(id)?.name),
77
+ channelOf: (name) =>
78
+ team.placesOf
79
+ ? team
80
+ .placesOf(name)
81
+ .map((place) => discordIdOf(place.key))
82
+ .find((id) => id !== undefined)
83
+ : (directory.agent(name) ?? directory.group(name))?.channelId,
84
+ };
85
+ }
86
+
87
+ export interface DiscordAgentToolsOptions {
88
+ /** The agent guild's channels, which the tools list, arrange and read. */
89
+ channels: Pick<AgentChannels, "layout" | "arrange" | "read">;
90
+ /** The team's agents and groups, read when a tool runs; undefined on a host whose agent server is off. */
91
+ directory: () => DiscordTeamReads | undefined;
92
+ logger: Logger;
93
+ }
94
+
95
+ /** A tool that only agents' turns carry: the owner's sessions load none of it. */
96
+ function agentsOnly(tool: ToolContribution): ToolContribution {
97
+ return {
98
+ ...tool,
99
+ session: {
100
+ ...tool.session,
101
+ snapshot: () => {
102
+ // Not required at startup: the sessions the preflight builds are no agent's.
103
+ const { requiredTools: _, factory, ...rest } = tool.session.snapshot();
104
+ return {
105
+ ...rest,
106
+ factory: (session) => (session.agent ? factory(session) : null),
107
+ };
108
+ },
109
+ },
110
+ };
111
+ }
112
+
113
+ /** A refusal the model reads, where the tool's own code throws an `AgentError`. */
114
+ async function refusing<T>(run: () => Promise<T> | T): Promise<T> {
115
+ try {
116
+ return await run();
117
+ } catch (error) {
118
+ if (error instanceof AgentError) throw new ToolRefusal(error.message);
119
+ throw error;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * What `channel_arrange` and `channel_read` run, and Discord's side of the deprecated
125
+ * `AgentOps.arrange` and `AgentOps.read`, which the host hands the team until 1.0. Each refuses
126
+ * with an `AgentError`.
127
+ */
128
+ export function discordChannelOps(
129
+ options: DiscordAgentToolsOptions,
130
+ ): FormerChannelOps {
131
+ const { channels, logger } = options;
132
+ const directory = () => {
133
+ const found = options.directory();
134
+ if (!found)
135
+ throw new AgentError(
136
+ "This host has no agent team, so there are no agent channels here.",
137
+ );
138
+ return found;
139
+ };
140
+ return {
141
+ arrange: async (entries) => {
142
+ const team = directory();
143
+ const listed = resolveArrangement(entries, team);
144
+ const { layout, remove } = planArrangement(
145
+ listed,
146
+ await channels.layout(),
147
+ );
148
+ await channels.arrange(layout, remove);
149
+ logger.info(
150
+ { entries: listed.map((l) => l.category), removed: remove.length },
151
+ "agent channels arranged",
152
+ );
153
+ const removed =
154
+ remove.length > 0
155
+ ? ` ${remove.length} empty team categories were deleted.`
156
+ : "";
157
+ return `Arranged the channels.${removed}\n\n${categoryLayoutText(await channels.layout(), team.ownerOf)}`;
158
+ },
159
+ read: async (channel, around, limit) => {
160
+ const id = channelIdFromRef(channel);
161
+ const found = await channels.read(id, {
162
+ limit: Math.min(Math.max(limit ?? 20, 1), READ_LIMIT),
163
+ ...(around ? { around } : {}),
164
+ });
165
+ return found.length > 0
166
+ ? found.map(messageLine).join("\n")
167
+ : `<#${id}> has no messages there.`;
168
+ },
169
+ };
170
+ }
171
+
172
+ /**
173
+ * The tools of the agent guild's channels: `channel_arrange` sorts agent and group channels into
174
+ * categories and `channel_read` reads a channel's messages. Agents carry them, as they carried
175
+ * them when the agent team offered them; a temp knight carries neither arrange nor creation.
176
+ */
177
+ export function discordAgentTools(
178
+ options: DiscordAgentToolsOptions,
179
+ ): ToolContribution[] {
180
+ const ops = discordChannelOps(options);
181
+ const speaker = ownerWords(THE_SPEAKER).name;
182
+ return [
183
+ defineTool({
184
+ name: "channel_arrange",
185
+ description: `Sort agent and group channels into categories and order them, when ${speaker} 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.`,
186
+ minTier: "admin",
187
+ withheldFromHelpers: true,
188
+ parameters: Type.Object({
189
+ categories: Type.Array(
190
+ Type.Object({
191
+ category: Type.String({
192
+ description:
193
+ "Agents, Groups, or either with -<suffix>, the suffix 1 to 32 characters in any language.",
194
+ }),
195
+ channels: Type.Array(Type.String(), {
196
+ minItems: 1,
197
+ description:
198
+ "Agent or group names (from agent_list), in the order they should appear.",
199
+ }),
200
+ }),
201
+ { minItems: 1, description: "Categories in server order." },
202
+ ),
203
+ }),
204
+ run: ({ categories }) =>
205
+ refusing(() =>
206
+ ops.arrange(
207
+ categories.map((entry) => ({
208
+ category: entry.category,
209
+ names: entry.channels,
210
+ })),
211
+ ),
212
+ ),
213
+ }),
214
+ defineTool({
215
+ name: "channel_read",
216
+ 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 ${speaker} forwarded to you: pass the source channel and the message id from the forwarded link. Read-only.`,
217
+ minTier: "member",
218
+ parameters: Type.Object({
219
+ channel: Type.String({
220
+ description: "The channel as <#id> or its id.",
221
+ }),
222
+ around: Type.Optional(
223
+ Type.String({
224
+ pattern: "^\\d+$",
225
+ description:
226
+ "A message id: read the messages around it instead of the latest.",
227
+ }),
228
+ ),
229
+ limit: Type.Optional(
230
+ Type.Integer({ minimum: 1, maximum: 50, description: "Default 20." }),
231
+ ),
232
+ }),
233
+ run: ({ channel, around, limit }) =>
234
+ refusing(() => ops.read(channel, around, limit)),
235
+ }),
236
+ ].map(agentsOnly);
237
+ }
@@ -350,6 +350,8 @@ export function parseChannelTool(
350
350
  const after = parsed.afterDate && Date.parse(String(parsed.afterDate));
351
351
  const before = parsed.beforeDate && Date.parse(String(parsed.beforeDate));
352
352
  for (const date of [after, before]) {
353
+ if (Number.isNaN(date))
354
+ throw new ChannelToolError("INVALID_CHANNEL_ARGUMENTS");
353
355
  if (typeof date === "number" && date < DISCORD_EPOCH)
354
356
  throw new ChannelToolError("INVALID_CHANNEL_DATE_RANGE");
355
357
  }
@@ -1,4 +1,7 @@
1
- import type { AgentChannels, DashboardBoard } from "../agents/agent-ports.ts";
1
+ import type {
2
+ AgentChannels,
3
+ DashboardBoard,
4
+ } from "../contract/agent-channels.ts";
2
5
  import type { ChannelKey } from "../domain/conversation.ts";
3
6
  import type { OwnerOperations } from "../modules/discord-admin/discord-admin.ts";
4
7
  import type { ThreadHost } from "../threads/dispatch-threads.ts";
@@ -8,12 +8,14 @@ import {
8
8
  Partials,
9
9
  type REST,
10
10
  } from "discord.js";
11
- import type { AgentChannels, DashboardBoard } from "../agents/agent-ports.ts";
11
+ import type {
12
+ AgentChannels,
13
+ DashboardBoard,
14
+ } from "../contract/agent-channels.ts";
12
15
  import type {
13
16
  ChannelContext,
14
17
  ChannelContextOptions,
15
18
  } from "../contract/channel-context.ts";
16
- import type { PlaceProvider } from "../contract/places.ts";
17
19
  import type {
18
20
  ChatSurface,
19
21
  SurfaceMessageEvents,
@@ -34,7 +36,6 @@ import type { MemberJoinedEvent } from "../plugin-api/event-types.ts";
34
36
  import { chunksFor } from "../presentation/reply-chunks.ts";
35
37
  import { threadsOfHost } from "../threads/host-threads.ts";
36
38
  import { DiscordAgentChannels, DiscordDashboard } from "./agent-discord.ts";
37
- import { discordPlaces } from "./agent-places.ts";
38
39
  import {
39
40
  type ContextSourceMessage,
40
41
  contextSourceOf,
@@ -137,6 +138,11 @@ export class DiscordSurface
137
138
  ): Promise<ChannelContext | undefined> =>
138
139
  this.#options.channelContext?.(message, options);
139
140
 
141
+ /** The discord.js client, with which the agent guild's place provider checks its stored channels. */
142
+ client(): Client {
143
+ return this.#client;
144
+ }
145
+
140
146
  /** The client's REST queue, whose rate limits every request of this process shares. */
141
147
  rest(): REST {
142
148
  return this.#client.rest;
@@ -172,17 +178,6 @@ export class DiscordSurface
172
178
  );
173
179
  }
174
180
 
175
- /** The agent team's places in the agent guild: its channels and threads, as a place provider. */
176
- agentPlaces(guildId: string): PlaceProvider {
177
- return discordPlaces({
178
- client: this.#client,
179
- guild: guildId,
180
- channels: this.agentChannels(guildId),
181
- onRemoved: (listener) => this.onChannelDeleted(listener),
182
- logger: this.#options.logger,
183
- });
184
- }
185
-
186
181
  /** Threads for background dispatches, in the channel that started each. */
187
182
  threadHost(): DiscordThreadHost {
188
183
  return new DiscordThreadHost(this.#client);
@@ -0,0 +1,59 @@
1
+ import { type Client, DiscordAPIError } from "discord.js";
2
+
3
+ /** What a stand-in server says of a channel id. */
4
+ export interface FakeServer {
5
+ /** The server the agent guild is. */
6
+ guild: string;
7
+ /** Whether the channel was deleted. */
8
+ gone(id: string): boolean;
9
+ /** Whether the channel is one of another server. */
10
+ foreign(id: string): boolean;
11
+ /** Whether the server answers Missing Access (50001) for the channel, as for one of a server the bot left. */
12
+ denied?(id: string): boolean;
13
+ /** The ids of the agent guild's channels, as its list gives them; absent = none. */
14
+ listed?(): readonly string[];
15
+ /** Whether the request fails with an error that says nothing of the channel. */
16
+ fails?(id: string): boolean;
17
+ }
18
+
19
+ /**
20
+ * A discord.js client that only answers `channels.fetch`, as a place provider's `check` asks it:
21
+ * a channel of the agent guild, one of another server, or Discord's own "unknown channel".
22
+ */
23
+ export function fakeDiscordClient(server: FakeServer): Client {
24
+ const fetch = async (id: string) => {
25
+ if (server.fails?.(id)) throw new Error("the server did not answer");
26
+ if (server.denied?.(id))
27
+ throw new DiscordAPIError(
28
+ { message: "Missing Access", code: 50001 },
29
+ 50001,
30
+ 403,
31
+ "GET",
32
+ `/channels/${id}`,
33
+ {},
34
+ );
35
+ if (server.gone(id))
36
+ throw new DiscordAPIError(
37
+ { message: "Unknown Channel", code: 10003 },
38
+ 10003,
39
+ 404,
40
+ "GET",
41
+ `/channels/${id}`,
42
+ {},
43
+ );
44
+ return {
45
+ isDMBased: () => false,
46
+ guildId: server.foreign(id) ? "999999999999999999" : server.guild,
47
+ };
48
+ };
49
+ // SAFETY: the provider reads nothing of the client but `channels.fetch` and the agent guild's channel list.
50
+ const guilds = {
51
+ fetch: async () => ({
52
+ channels: {
53
+ fetch: async () =>
54
+ new Map((server.listed?.() ?? []).map((id) => [id, {}])),
55
+ },
56
+ }),
57
+ };
58
+ return { channels: { fetch }, guilds } as unknown as Client;
59
+ }
@@ -4,7 +4,7 @@ import { join } from "node:path";
4
4
  import { ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
5
5
  import { agentServerPlugin, LOCAL_TEAM_ID } from "../builtin/agent-server.ts";
6
6
  import { channelContextPlugin } from "../builtin/channel-context.ts";
7
- import { discordPlugin } from "../builtin/discord.ts";
7
+ import { discordFormerChannelOps, discordPlugin } from "../builtin/discord.ts";
8
8
  import { discordAdminPlugin } from "../builtin/discord-admin.ts";
9
9
  import { identityPlugin } from "../builtin/identity.ts";
10
10
  import { modulesPlugin, schedulerPlugin } from "../builtin/modules.ts";
@@ -154,6 +154,9 @@ function discordAssembly(
154
154
  ownerName: owner.name,
155
155
  rootCommand: discord.rootCommand,
156
156
  ...(discord.guild ? { agentGuild: discord.guild } : {}),
157
+ ...(discord.guild && discord.entryChannel
158
+ ? { entryChannel: discord.entryChannel }
159
+ : {}),
157
160
  dataDir: config.dataDir,
158
161
  ...(discord.refusalHint === undefined
159
162
  ? {}
@@ -225,12 +228,11 @@ function agentAssembly(
225
228
  teamId,
226
229
  formerTeamIds: config.team.formerIds,
227
230
  // Without the agent guild the team lives in the app's rooms, as on a host without Discord.
231
+ // With the agent guild the Discord plugin names the coordinator by its entry channel.
228
232
  ...(discord?.guild
229
233
  ? {
230
- guildId: discord.guild,
231
- ...(discord.entryChannel
232
- ? { entryChannelId: discord.entryChannel }
233
- : {}),
234
+ placeSpaces: [{ surface: "discord", space: discord.guild }],
235
+ formerChannelOps: discordFormerChannelOps(discord.guild),
234
236
  }
235
237
  : config.coordinator
236
238
  ? { coordinator: config.coordinator }
@@ -3,6 +3,7 @@ import type { ChannelKey } from "../../domain/conversation.ts";
3
3
  import { DelegationError } from "../../domain/errors.ts";
4
4
  import { messages } from "../../i18n/index.ts";
5
5
  import type { Tier } from "../../identity/speakers.ts";
6
+ import { HostStoppingError } from "../../kernel/errors.ts";
6
7
  import type { Logger } from "../../kernel/log.ts";
7
8
  import { timeZone } from "../../kernel/time.ts";
8
9
  import type { Delegator } from "../../plugin-api/services.ts";
@@ -49,6 +50,8 @@ export interface DelegatorOptions {
49
50
  threads?: Pick<DispatchThreads, "open">;
50
51
  logger: Logger;
51
52
  timeoutMs?: number;
53
+ /** True while the host's shutdown drain runs; a job started then is refused, as any new work. */
54
+ draining?: () => boolean;
52
55
  }
53
56
 
54
57
  const MAX_TASK_CHARS = 4_000;
@@ -73,6 +76,8 @@ export class DefaultDelegator implements Delegator {
73
76
  start(
74
77
  request: Omit<DelegationJob, "id" | "startedAt" | "thread">,
75
78
  ): DelegationJob {
79
+ if (this.#options.draining?.())
80
+ throw new DelegationError(new HostStoppingError().message);
76
81
  const title = request.title.trim();
77
82
  const task = request.task.trim();
78
83
  if (!title || !task)
@@ -0,0 +1,119 @@
1
+ import type { CharacterInput } from "../../characters/index.ts";
2
+ import type {
3
+ HelperFields,
4
+ PresetAction,
5
+ } from "../agents/helper-preset-ops.ts";
6
+ import type { AgentTurnScope } from "../domain/ports.ts";
7
+
8
+ /**
9
+ * Discord's side of `AgentOps.arrange` and `AgentOps.read`, which the host hands the team while
10
+ * the two stay on `AgentOps`: what the Discord plugin's `channel_arrange` and `channel_read` run.
11
+ */
12
+ export type FormerChannelOps = Pick<AgentOps, "arrange" | "read">;
13
+
14
+ /**
15
+ * What the agent tools do; the agent team implements it. Each returns text for the model.
16
+ * `arrange`, `read`, and the `category` of `create` and `createGroup` are what 0.45 had: the
17
+ * Discord plugin's own tools and its `category` argument took their place, and they stay here,
18
+ * deprecated, until 1.0.
19
+ */
20
+ export interface AgentOps {
21
+ list(): Promise<string>;
22
+ get(name: string): string;
23
+ update(
24
+ name: string,
25
+ change: {
26
+ displayName?: string;
27
+ prompt?: string;
28
+ model?: string;
29
+ thinking?: string;
30
+ },
31
+ /** Who changes it: the agent whose turn asks, for the prompt history. */
32
+ by?: string,
33
+ ): Promise<string>;
34
+ create(
35
+ caller: AgentTurnScope,
36
+ input: {
37
+ name: string;
38
+ displayName: string;
39
+ prompt: string;
40
+ /** Fields of its look; any left out come from the look its role suggests. */
41
+ character?: CharacterInput;
42
+ task: string;
43
+ /** @deprecated Discord's category for its channel; give it as `hints.category`. Removed in 1.0. */
44
+ category?: string;
45
+ /** The values of the arguments the surfaces' place providers add to the tool, by name. */
46
+ hints?: Readonly<Record<string, string>>;
47
+ skills?: string[];
48
+ /** Turn long-running mode on for its conversations; an owner's turn only. */
49
+ longRunning?: boolean;
50
+ },
51
+ ): Promise<string>;
52
+ /** Makes a temp knight of the caller for one task; the answer returns to the caller's conversation. */
53
+ helperCreate(
54
+ caller: AgentTurnScope,
55
+ input: HelperFields & { name?: string; task: string },
56
+ ): Promise<string>;
57
+ /** Saves, lists, or deletes the caller's own temp-knight presets. */
58
+ helperPreset(caller: AgentTurnScope, action: PresetAction): Promise<string>;
59
+ /** Archives the caller's own temp knights: the named ones, or every one that is finished. */
60
+ helperEnd(
61
+ caller: AgentTurnScope,
62
+ names: readonly string[] | "finished",
63
+ ): Promise<string>;
64
+ /** Changes an agent's look; a field left out stays as it is. */
65
+ avatar(name: string, look: CharacterInput): Promise<string>;
66
+ /** Queues the message and returns at once. */
67
+ /**
68
+ * Hands a request to another agent, in its conversation on the sender's surface, or in the
69
+ * `conversation` named: "discord", "web" (or a room surface's name), or one of its conversation keys.
70
+ */
71
+ message(
72
+ caller: AgentTurnScope,
73
+ to: string,
74
+ text: string,
75
+ conversation?: string,
76
+ ): string;
77
+ /**
78
+ * Readies the place a message is about to reach: a temp knight made in the web app gets its
79
+ * Discord thread when the caller may message it and names "discord". Never rejects.
80
+ */
81
+ reach?(
82
+ caller: AgentTurnScope,
83
+ to: string,
84
+ conversation?: string,
85
+ ): Promise<void>;
86
+ createGroup(input: {
87
+ name: string;
88
+ displayName: string;
89
+ members: string[];
90
+ host?: string;
91
+ /** @deprecated Discord's category for its channel; give it as `hints.category`. Removed in 1.0. */
92
+ category?: string;
93
+ /** The values of the arguments the surfaces' place providers add to the tool, by name. */
94
+ hints?: Readonly<Record<string, string>>;
95
+ }): Promise<string>;
96
+ updateGroup(
97
+ name: string,
98
+ change: { displayName?: string; members?: string[]; host?: string },
99
+ ): Promise<string>;
100
+ archive(caller: AgentTurnScope, name: string): Promise<string>;
101
+ /**
102
+ * Sorts the agent guild's channels into categories, as the Discord plugin's `channel_arrange`
103
+ * tool does; refused on a host whose team has no Discord channels.
104
+ * @deprecated The Discord plugin contributes `channel_arrange`, which an agent's turn carries;
105
+ * a plugin that arranges channels itself uses `DISCORD.connection.agentChannels`. Removed in 1.0.
106
+ */
107
+ arrange(entries: { category: string; names: string[] }[]): Promise<string>;
108
+ /**
109
+ * Reads a channel's messages, as the Discord plugin's `channel_read` tool does; refused on a
110
+ * host whose team has no Discord channels.
111
+ * @deprecated The Discord plugin contributes `channel_read`, which an agent's turn carries; a
112
+ * plugin that reads channels itself uses `DISCORD.connection.agentChannels`. Removed in 1.0.
113
+ */
114
+ read(
115
+ channel: string,
116
+ around: string | undefined,
117
+ limit: number | undefined,
118
+ ): Promise<string>;
119
+ }
@@ -0,0 +1,9 @@
1
+ /** The name of the agent server's plugin, as `serviceStarted` events name it. */
2
+ export const AGENT_SERVER_PLUGIN = "agent-server";
3
+
4
+ /**
5
+ * The agent server's service that starts the team in the background: once its `serviceStarted`
6
+ * event says `ready`, the agents' places are up, and what shows the team, such as Discord's
7
+ * dashboard, starts.
8
+ */
9
+ export const AGENT_TEAM_SERVICE = "team";
@@ -109,6 +109,12 @@ export interface ToolSpec<Schema extends TObject> {
109
109
  minTier: Tier;
110
110
  /** Whether agents carry the tool in their turns; default true. */
111
111
  agent?: boolean;
112
+ /**
113
+ * Whether a temp knight's turns leave the tool out, as they leave out making agents and
114
+ * groups, archiving and scheduling: work a knight started would have no one to end it. Default
115
+ * false.
116
+ */
117
+ withheldFromHelpers?: boolean;
112
118
  /**
113
119
  * A short description of what the call would do when it must wait for approval; undefined lets it
114
120
  * run. It may answer later, after looking something up as the turn's speaker, such as a name to
@@ -160,6 +166,8 @@ export interface ToolContribution {
160
166
  readonly name: string;
161
167
  readonly minTier: Tier;
162
168
  readonly agent: boolean;
169
+ /** Whether a temp knight's turns leave the tool out. */
170
+ readonly withheldFromHelpers?: boolean;
163
171
  /** The extension that registers the tool in a session. */
164
172
  readonly session: SessionTool;
165
173
  /** The hold rule for the tool's `hold`, when it has one. */
@@ -231,6 +239,7 @@ export function defineTool<Schema extends TObject>(
231
239
  name,
232
240
  minTier: spec.minTier,
233
241
  agent: spec.agent ?? true,
242
+ withheldFromHelpers: spec.withheldFromHelpers ?? false,
234
243
  session,
235
244
  };
236
245
  if (!hold && !approvers) return contribution;
@@ -293,6 +293,8 @@ export interface LinkedSessions {
293
293
  requiredTools: readonly string[];
294
294
  /** The tools plugins defined for agents, by name. */
295
295
  agentTools: readonly string[];
296
+ /** Those of `agentTools` a temp knight's turns leave out. Optional, because a host that links sessions by hand may leave it out, and then none is withheld. */
297
+ agentToolsWithheldFromHelpers?: readonly string[];
296
298
  /** Every plugin's agent selection merged, read before each agent turn. */
297
299
  agentSelection(): ToolSelection;
298
300
  /** Told which commands each built session registers, so only declared commands that exist are listed; a host that links sessions by hand may leave it out, and then no declared command is listed. */
@@ -223,7 +223,10 @@ export interface NewAgent {
223
223
  * without it, or for a surface with no rooms, where `agent_create` runs it: the agent's Discord channel, else its first room.
224
224
  */
225
225
  openIn?: string;
226
+ /** @deprecated Discord's category for its channel; give it as `hints.category`. Removed in 1.0. */
226
227
  category?: string;
228
+ /** The values of the arguments the surfaces' place providers add to `agent_create` (`createArguments`), by name, such as Discord's `category`. */
229
+ hints?: Readonly<Record<string, string>>;
227
230
  /** Skills it carries; refused when the skills addon is off. */
228
231
  skills?: string[];
229
232
  model?: string;
@@ -324,7 +327,10 @@ export interface AgentTeam extends HelperTeam {
324
327
  displayName: string;
325
328
  members: string[];
326
329
  host?: string;
330
+ /** @deprecated Discord's category for its channel; give it as `hints.category`. Removed in 1.0. */
327
331
  category?: string;
332
+ /** The values of the arguments the surfaces' place providers add to `group_create`, by name, such as Discord's `category`. */
333
+ hints?: Readonly<Record<string, string>>;
328
334
  }): Promise<string>;
329
335
  /** Changes a group's display name, members (all of them) or host. */
330
336
  updateGroup(
@@ -409,6 +409,9 @@ export function linkSessions(registry: Registry): LinkedSessions {
409
409
  personaMemory: (kind) => personas.get(kind)?.memory ?? "speaker",
410
410
  requiredTools: [...new Set(registry.requiredTools)],
411
411
  agentTools: registry.tools.flatMap((t) => (t.agent ? [t.name] : [])),
412
+ agentToolsWithheldFromHelpers: registry.tools.flatMap((t) =>
413
+ t.agent && t.withheldFromHelpers ? [t.name] : [],
414
+ ),
412
415
  agentSelection: () => mergeSelections(registry.agentSelections),
413
416
  chatCommands: registry.chatCommandSources,
414
417
  };