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
@@ -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
  }
@@ -1,3 +1,4 @@
1
+ import { LEGACY_CHANNEL_SURFACE } from "../db/legacy-channels.ts";
1
2
  import type { ChannelKey } from "../domain/conversation.ts";
2
3
  import { AgentError } from "../domain/errors.ts";
3
4
  import type { AgentDirectory } from "../plugin-api/services.ts";
@@ -55,13 +56,13 @@ export function messageTarget(
55
56
  const rooms = ctx.places.rooms();
56
57
  // A surface whose places are stored: the agent has one there or none.
57
58
  if (
58
- wanted === "discord" ||
59
+ wanted === LEGACY_CHANNEL_SURFACE ||
59
60
  (!rooms.includes(wanted) && ctx.places.surfaces().includes(wanted))
60
61
  ) {
61
62
  const place = routes.placeOn(target.name, wanted);
62
63
  if (!place)
63
64
  throw new AgentError(
64
- `${target.name} has no ${wanted === "discord" ? "Discord channel" : `place on ${wanted}`}; its conversations: ${has}.`,
65
+ `${target.name} has no ${wanted === LEGACY_CHANNEL_SURFACE ? "Discord channel" : `place on ${wanted}`}; its conversations: ${has}.`,
65
66
  );
66
67
  return place;
67
68
  }
@@ -4,6 +4,7 @@ import type {
4
4
  } from "../config/routing.ts";
5
5
  import { ROUTE_WORDS } from "../config/routing.ts";
6
6
  import { parseChannelKey } from "../contract/surface.ts";
7
+ import { LEGACY_CHANNEL_SURFACE } from "../db/legacy-channels.ts";
7
8
  import type { ChannelKey } from "../domain/conversation.ts";
8
9
  import { AgentError, ConfigError } from "../domain/errors.ts";
9
10
  import type { AgentDirectory } from "../plugin-api/services.ts";
@@ -304,7 +305,7 @@ export class Routes implements RoutingTable {
304
305
  );
305
306
  if (!holders.includes(surface))
306
307
  throw new ConfigError(
307
- `config ${path}: the ${surface} surface holds no agent places, since it hosts no rooms${surface === "discord" ? " here (the agents have no Discord channels)" : ""}. Name one that does: ${holders.join(", ") || "none on this host"}.`,
308
+ `config ${path}: the ${surface} surface holds no agent places, since it hosts no rooms${surface === LEGACY_CHANNEL_SURFACE ? " here (the agents have no Discord channels)" : ""}. Name one that does: ${holders.join(", ") || "none on this host"}.`,
308
309
  );
309
310
  }
310
311
  }