pi-roundtable 0.44.1 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/docs/plugins.md +36 -2
- package/package.json +2 -2
- package/src/core/agents/agent-claim.ts +15 -21
- package/src/core/agents/agent-messages.ts +10 -10
- package/src/core/agents/agent-prompt.ts +7 -8
- package/src/core/agents/agent-rules.ts +9 -2
- package/src/core/agents/agent-store.ts +16 -0
- package/src/core/agents/agent-team-fake-channels.ts +105 -0
- package/src/core/agents/agent-team-fixture.ts +30 -105
- package/src/core/agents/agent-team.ts +20 -21
- package/src/core/agents/group-turns.ts +8 -15
- package/src/core/agents/helper-modes.ts +7 -13
- package/src/core/agents/helper-work.ts +7 -6
- package/src/core/agents/message-target.ts +24 -12
- package/src/core/agents/room-progress.ts +8 -6
- package/src/core/agents/routes.ts +24 -47
- package/src/core/agents/team-editing.ts +5 -8
- package/src/core/agents/team-keys.ts +5 -190
- package/src/core/agents/team-lifecycle.ts +23 -39
- package/src/core/agents/team-options.ts +1 -1
- package/src/core/agents/team-places.ts +335 -0
- package/src/core/agents/team-posts.ts +157 -0
- package/src/core/agents/team-prompt.ts +3 -3
- package/src/core/agents/team-status.ts +18 -10
- package/src/core/agents/team-turn-types.ts +5 -8
- package/src/core/agents/team-turns.ts +26 -169
- package/src/core/builtin/agent-server-test-kit.ts +29 -0
- package/src/core/builtin/agent-server.ts +19 -12
- package/src/core/builtin/discord.ts +6 -0
- package/src/core/contract/places.ts +141 -0
- package/src/core/discord/agent-places.ts +215 -0
- package/src/core/discord/discord-surface.ts +13 -0
- package/src/core/host/define-roundtable.ts +1 -0
- package/src/core/plugin-api/agent-assets.ts +36 -0
- package/src/core/plugin-api/plugin-context.ts +30 -0
- package/src/core/plugin-api/plugin.ts +10 -28
- package/src/core/plugin-api/services.ts +20 -39
- package/src/core/registry/claims.ts +120 -0
- package/src/core/registry/contributions.ts +36 -118
- package/src/core/registry/place-port.ts +94 -0
- package/src/core/registry/places.ts +43 -0
- package/src/core/testing/fake-pager-places.ts +120 -0
- package/src/core/testing/fake-room-surface.ts +60 -0
- package/src/core/testing/modules.ts +5 -5
- package/src/core/testing/place-contract.ts +481 -0
- package/src/core/testing/team-places.ts +121 -0
- package/src/core/testing/test-host.ts +36 -10
- package/src/discord/index.ts +2 -0
- package/src/index.ts +12 -0
- package/src/testing.ts +15 -3
|
@@ -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 type { PlaceProvider } from "../contract/places.ts";
|
|
6
7
|
import type { ChatSurface } from "../contract/surface.ts";
|
|
7
8
|
import { NO_ATTACHMENTS } from "../domain/attachment.ts";
|
|
8
9
|
import type {
|
|
@@ -26,13 +27,7 @@ import {
|
|
|
26
27
|
} from "../testing/database.ts";
|
|
27
28
|
import { useTestLocale } from "../testing/locale.ts";
|
|
28
29
|
import { OWNER_SPEAKER, TEST_OWNER } from "../testing/owner.ts";
|
|
29
|
-
import
|
|
30
|
-
AgentCategory,
|
|
31
|
-
AgentChannels,
|
|
32
|
-
AgentPost,
|
|
33
|
-
CategoryLayout,
|
|
34
|
-
ChannelMessage,
|
|
35
|
-
} from "./agent-ports.ts";
|
|
30
|
+
import { discordTestPlaces, testPlacePort } from "../testing/team-places.ts";
|
|
36
31
|
import { PgAgentStore as AgentStore } from "./agent-store.ts";
|
|
37
32
|
import {
|
|
38
33
|
DiscordAgentTeam as AgentTeam,
|
|
@@ -40,6 +35,7 @@ import {
|
|
|
40
35
|
} from "./agent-team.ts";
|
|
41
36
|
import { seeds } from "./agent-team-seeds.ts";
|
|
42
37
|
import { discordKey } from "./team-keys.ts";
|
|
38
|
+
import { TeamPlaces } from "./team-places.ts";
|
|
43
39
|
|
|
44
40
|
export const ENTRY = "1000";
|
|
45
41
|
export const USABLE = [
|
|
@@ -47,103 +43,6 @@ export const USABLE = [
|
|
|
47
43
|
"openai-codex/gpt-6-sol",
|
|
48
44
|
];
|
|
49
45
|
|
|
50
|
-
export class FakeChannels implements AgentChannels {
|
|
51
|
-
posts: { channelId: string; post: AgentPost }[] = [];
|
|
52
|
-
created: string[] = [];
|
|
53
|
-
deleted = new Set<string>();
|
|
54
|
-
#next = 2000;
|
|
55
|
-
async post(channelId: string, post: AgentPost) {
|
|
56
|
-
this.posts.push({ channelId, post });
|
|
57
|
-
}
|
|
58
|
-
/** The server's categories in order, each with its channels in order. */
|
|
59
|
-
categories: CategoryLayout[] = [];
|
|
60
|
-
#nextCategory = 9000;
|
|
61
|
-
arranged: { layout: CategoryLayout[]; remove: string[] }[] = [];
|
|
62
|
-
categoryOf(channelId: string) {
|
|
63
|
-
return this.categories.find((c) => c.channelIds.includes(channelId))?.name;
|
|
64
|
-
}
|
|
65
|
-
/** Moves a channel to the end of the category, made when missing. */
|
|
66
|
-
put(channelId: string, category: AgentCategory) {
|
|
67
|
-
for (const c of this.categories)
|
|
68
|
-
c.channelIds = c.channelIds.filter((id) => id !== channelId);
|
|
69
|
-
let found = this.categories.find((c) => c.name === category);
|
|
70
|
-
if (!found) {
|
|
71
|
-
found = {
|
|
72
|
-
id: String(this.#nextCategory++),
|
|
73
|
-
name: category,
|
|
74
|
-
channelIds: [],
|
|
75
|
-
};
|
|
76
|
-
this.categories.push(found);
|
|
77
|
-
}
|
|
78
|
-
found.channelIds.push(channelId);
|
|
79
|
-
}
|
|
80
|
-
async createChannel(name: string, topic: string, category: AgentCategory) {
|
|
81
|
-
this.created.push(name);
|
|
82
|
-
const id = String(this.#next++);
|
|
83
|
-
this.topics.set(id, topic);
|
|
84
|
-
this.put(id, category);
|
|
85
|
-
return id;
|
|
86
|
-
}
|
|
87
|
-
/** The threads made under a channel for temp knights, by id; `archived` once closed. */
|
|
88
|
-
threads = new Map<
|
|
89
|
-
string,
|
|
90
|
-
{ parent: string; name: string; archived: boolean }
|
|
91
|
-
>();
|
|
92
|
-
async createThread(parentChannelId: string, name: string) {
|
|
93
|
-
const id = String(this.#next++);
|
|
94
|
-
this.threads.set(id, { parent: parentChannelId, name, archived: false });
|
|
95
|
-
return id;
|
|
96
|
-
}
|
|
97
|
-
async closeThread(threadId: string) {
|
|
98
|
-
const thread = this.threads.get(threadId);
|
|
99
|
-
if (thread) thread.archived = true;
|
|
100
|
-
}
|
|
101
|
-
async openThread(threadId: string) {
|
|
102
|
-
const thread = this.threads.get(threadId);
|
|
103
|
-
if (thread) thread.archived = false;
|
|
104
|
-
}
|
|
105
|
-
async placeIn(channelId: string, category: AgentCategory) {
|
|
106
|
-
if (this.categoryOf(channelId) === category) return false;
|
|
107
|
-
this.put(channelId, category);
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
async layout() {
|
|
111
|
-
return structuredClone(this.categories);
|
|
112
|
-
}
|
|
113
|
-
async arrange(layout: CategoryLayout[], remove: string[]) {
|
|
114
|
-
this.arranged.push({ layout: structuredClone(layout), remove });
|
|
115
|
-
this.categories = layout.map((c) => ({
|
|
116
|
-
id: c.id ?? String(this.#nextCategory++),
|
|
117
|
-
name: c.name,
|
|
118
|
-
channelIds: [...c.channelIds],
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
history: ChannelMessage[] = [];
|
|
122
|
-
reads: { channelId: string; limit: number; around?: string }[] = [];
|
|
123
|
-
async read(channelId: string, options: { limit: number; around?: string }) {
|
|
124
|
-
this.reads.push({ channelId, ...options });
|
|
125
|
-
return this.history;
|
|
126
|
-
}
|
|
127
|
-
topics = new Map<string, string>();
|
|
128
|
-
async setTopic(channelId: string, topic: string) {
|
|
129
|
-
this.topics.set(channelId, topic);
|
|
130
|
-
}
|
|
131
|
-
async exists(channelId: string) {
|
|
132
|
-
return !this.deleted.has(channelId);
|
|
133
|
-
}
|
|
134
|
-
webhooksRemoved: string[] = [];
|
|
135
|
-
async removeWebhook(channelId: string) {
|
|
136
|
-
this.webhooksRemoved.push(channelId);
|
|
137
|
-
}
|
|
138
|
-
texts(channelId: string) {
|
|
139
|
-
return this.posts.flatMap((p) =>
|
|
140
|
-
p.channelId === channelId
|
|
141
|
-
? [`${p.post.name}: ${p.post.chunks.join("")}`]
|
|
142
|
-
: [],
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
46
|
/**
|
|
148
47
|
* The surfaces a team replies through in rooms. `rooms` names the surfaces that host rooms and
|
|
149
48
|
* starts empty, so the Discord suites run as if no surface did; a room suite sets it.
|
|
@@ -195,8 +94,11 @@ class FakeSurfaces {
|
|
|
195
94
|
}
|
|
196
95
|
}
|
|
197
96
|
|
|
97
|
+
export { FakeChannels } from "./agent-team-fake-channels.ts";
|
|
198
98
|
export { FakeRuntime } from "./agent-team-fake-runtime.ts";
|
|
199
99
|
|
|
100
|
+
import { FakeChannels } from "./agent-team-fake-channels.ts";
|
|
101
|
+
|
|
200
102
|
import { FakeRuntime } from "./agent-team-fake-runtime.ts";
|
|
201
103
|
|
|
202
104
|
// CI runs the setup below about ten times slower than a laptop, and bun's 5 s hook limit
|
|
@@ -209,6 +111,10 @@ let channels: FakeChannels;
|
|
|
209
111
|
let surfaces: FakeSurfaces;
|
|
210
112
|
let runtime: FakeRuntime;
|
|
211
113
|
export interface TeamFixture {
|
|
114
|
+
/** Where the team's agents are, as the host's place providers give it: Discord's (unless `local`), a room on each of `surfaces.rooms`, and `stored`. */
|
|
115
|
+
places: TeamPlaces;
|
|
116
|
+
/** The stored place providers a test adds to the host's, read at each call; empty at the start of each test. */
|
|
117
|
+
stored: PlaceProvider[];
|
|
212
118
|
store: TestStore<AgentStore>;
|
|
213
119
|
channels: FakeChannels;
|
|
214
120
|
surfaces: FakeSurfaces;
|
|
@@ -250,6 +156,8 @@ let team: AgentTeam;
|
|
|
250
156
|
let build: () => AgentTeam;
|
|
251
157
|
let skillStore: TestStore<SkillStore>;
|
|
252
158
|
let skills: SkillRegistry;
|
|
159
|
+
let places: TeamPlaces;
|
|
160
|
+
const stored: PlaceProvider[] = [];
|
|
253
161
|
export const removedSchedules: number[] = [];
|
|
254
162
|
export const stops: string[] = [];
|
|
255
163
|
/** The events the team reported, in order, as `turnStarted infra`, `turnEnded infra ok`, or `changed`. */
|
|
@@ -300,6 +208,7 @@ export function useTeamFixture(
|
|
|
300
208
|
await skillStore?.close();
|
|
301
209
|
const admin = new SQL(testDatabaseUrl);
|
|
302
210
|
for (const table of [
|
|
211
|
+
"agent_places",
|
|
303
212
|
"agents",
|
|
304
213
|
"agent_groups",
|
|
305
214
|
"agent_group_messages",
|
|
@@ -344,6 +253,19 @@ export function useTeamFixture(
|
|
|
344
253
|
surfaces = new FakeSurfaces();
|
|
345
254
|
if (local) surfaces.rooms = ["app"];
|
|
346
255
|
runtime = new FakeRuntime();
|
|
256
|
+
stored.length = 0;
|
|
257
|
+
// The host's providers: Discord's channels with a guild, a room on each surface that hosts them, and a test's own.
|
|
258
|
+
places = new TeamPlaces(
|
|
259
|
+
store,
|
|
260
|
+
store.places,
|
|
261
|
+
testPlacePort({
|
|
262
|
+
rooms: () => surfaces.rooms,
|
|
263
|
+
stored: () => [...(local ? [] : [discordTestPlaces()]), ...stored],
|
|
264
|
+
// SAFETY: only a derived provider's post reads it, which the team does not use yet.
|
|
265
|
+
surfaces: surfaces as never,
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
store.readPlacesWith(places);
|
|
347
269
|
script.scores = undefined;
|
|
348
270
|
script.prompt = [];
|
|
349
271
|
script.tools = [];
|
|
@@ -360,7 +282,8 @@ export function useTeamFixture(
|
|
|
360
282
|
toolTiers: FIXTURE_TIERS,
|
|
361
283
|
principals: () => identity.current,
|
|
362
284
|
shellUser: "mcops",
|
|
363
|
-
|
|
285
|
+
places,
|
|
286
|
+
teamId: local ? "local" : "1",
|
|
364
287
|
...(local
|
|
365
288
|
? { coordinator: "coordinator" }
|
|
366
289
|
: { entryChannelId: ENTRY, channels }),
|
|
@@ -420,6 +343,8 @@ export function useTeamFixture(
|
|
|
420
343
|
team = build();
|
|
421
344
|
await team.start();
|
|
422
345
|
Object.assign(fx, {
|
|
346
|
+
places,
|
|
347
|
+
stored,
|
|
423
348
|
store,
|
|
424
349
|
channels,
|
|
425
350
|
surfaces,
|
|
@@ -23,12 +23,7 @@ import { allPresets, transferPreset } from "./helper-preset-overview.ts";
|
|
|
23
23
|
import { type Routes, routesOf } from "./routes.ts";
|
|
24
24
|
import { TeamEditing } from "./team-editing.ts";
|
|
25
25
|
import type { TeamHelpers } from "./team-helpers.ts";
|
|
26
|
-
import {
|
|
27
|
-
channelOwner,
|
|
28
|
-
coordinatorOf,
|
|
29
|
-
discordIdOf,
|
|
30
|
-
keysOf,
|
|
31
|
-
} from "./team-keys.ts";
|
|
26
|
+
import { coordinatorOf } from "./team-keys.ts";
|
|
32
27
|
import {
|
|
33
28
|
layoutText,
|
|
34
29
|
planArrangement,
|
|
@@ -87,10 +82,16 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
|
|
|
87
82
|
this.#editing = new TeamEditing(this.#context);
|
|
88
83
|
}
|
|
89
84
|
|
|
85
|
+
get teamId(): string {
|
|
86
|
+
return this.#options.teamId;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @deprecated The team's id, which is not always a guild; read `teamId`. Removed in 1.0. */
|
|
90
90
|
get guildId(): string {
|
|
91
|
-
return this.#options.
|
|
91
|
+
return this.#options.teamId;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/** @deprecated The Discord guild is the Discord place provider's `space`; removed in 1.0. */
|
|
94
95
|
get discordGuild(): string | undefined {
|
|
95
96
|
return this.#options.discordGuild;
|
|
96
97
|
}
|
|
@@ -109,30 +110,28 @@ export class DiscordAgentTeam implements AgentOps, AgentTeam {
|
|
|
109
110
|
return teamStatus(this.#context);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
/** The agent or group that owns a
|
|
113
|
+
/** The agent or group that owns a place of the agent server: a stored place, or a room. */
|
|
113
114
|
owns(channel: ChannelKey): "agent" | "group" | undefined {
|
|
114
|
-
|
|
115
|
-
return channelOwner(
|
|
116
|
-
store,
|
|
117
|
-
channel,
|
|
118
|
-
discordIdOf(channel) === undefined
|
|
119
|
-
? (surfaces?.roomSurfaces() ?? [])
|
|
120
|
-
: [],
|
|
121
|
-
);
|
|
115
|
+
return this.#options.places.ownerKind(channel);
|
|
122
116
|
}
|
|
123
117
|
|
|
124
118
|
/** The coordinator's name: the entry channel's agent, else the configured one; undefined while none is active. */
|
|
125
119
|
coordinator(): string | undefined {
|
|
126
|
-
|
|
120
|
+
const { store, places } = this.#options;
|
|
121
|
+
return coordinatorOf(store, places, this.#options)?.name;
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
/**
|
|
130
|
-
* Every key an agent or group is addressed by: its
|
|
131
|
-
*
|
|
125
|
+
* 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.
|
|
132
127
|
*/
|
|
133
128
|
roomsOf(name: string): ChannelKey[] {
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
return this.#options.places.keysOf(name);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Where an agent or group is: its place on each surface that holds one, with that surface's name; empty for an unknown name. */
|
|
133
|
+
placesOf(name: string): { surface: string; key: ChannelKey }[] {
|
|
134
|
+
return this.#options.places.placesOf(name);
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
/** The tools every agent turn runs with: the plugins', plus the shell and agent tools. */
|
|
@@ -12,12 +12,6 @@ import {
|
|
|
12
12
|
planRound,
|
|
13
13
|
RECENT_FOR_SCORING,
|
|
14
14
|
} from "./group-round.ts";
|
|
15
|
-
import {
|
|
16
|
-
groupLogName,
|
|
17
|
-
groupOfChannel,
|
|
18
|
-
groupScope,
|
|
19
|
-
groupSessionKey,
|
|
20
|
-
} from "./team-keys.ts";
|
|
21
15
|
import {
|
|
22
16
|
BACKLOG_LIMIT,
|
|
23
17
|
type Chain,
|
|
@@ -64,10 +58,9 @@ export class GroupTurns {
|
|
|
64
58
|
return [...round.sessions];
|
|
65
59
|
}
|
|
66
60
|
|
|
67
|
-
/** The active group whose
|
|
61
|
+
/** The active group whose place the key is. */
|
|
68
62
|
#groupOf(channel: ChannelKey): AgentGroup {
|
|
69
|
-
const
|
|
70
|
-
const group = groupOfChannel(store, surfaces, channel);
|
|
63
|
+
const group = this.#host.options.places.groupOf(channel);
|
|
71
64
|
if (group?.status !== "active")
|
|
72
65
|
throw new AgentError(`no group owns ${channel}`);
|
|
73
66
|
return group;
|
|
@@ -86,12 +79,12 @@ export class GroupTurns {
|
|
|
86
79
|
attachments: TurnAttachments,
|
|
87
80
|
repliedToName: string | undefined,
|
|
88
81
|
): Promise<void> {
|
|
89
|
-
const { store, scorer, confirmations, logger } = this.#host.options;
|
|
82
|
+
const { store, places, scorer, confirmations, logger } = this.#host.options;
|
|
90
83
|
const runtime = this.#host.options.runtime();
|
|
91
84
|
const group = this.#groupOf(channel);
|
|
92
|
-
// Each conversation of a group keeps its own log:
|
|
93
|
-
//
|
|
94
|
-
const log =
|
|
85
|
+
// Each conversation of a group keeps its own log: a stored place's under the provider's name
|
|
86
|
+
// for it (a Discord channel's, the group's own), a room's under `<group>@<surface>`.
|
|
87
|
+
const log = places.logName(group, channel);
|
|
95
88
|
const members = group.members
|
|
96
89
|
.map((name) => store.agent(name))
|
|
97
90
|
.filter((m): m is Agent => m?.status === "active");
|
|
@@ -110,7 +103,7 @@ export class GroupTurns {
|
|
|
110
103
|
const approvals = new Map<string, boolean>();
|
|
111
104
|
for (const member of members) {
|
|
112
105
|
const pending = await runtime.heldActions(
|
|
113
|
-
|
|
106
|
+
places.seatKey(group, member.name, channel),
|
|
114
107
|
);
|
|
115
108
|
// Only a speaker whose tier holds the held tools may approve or wake a seat for them.
|
|
116
109
|
if (!pending || !this.#host.mayApprove(speaker, pending)) continue;
|
|
@@ -191,7 +184,7 @@ export class GroupTurns {
|
|
|
191
184
|
extra.attachments = attachments;
|
|
192
185
|
if (approvals.get(name)) extra.confirmed = true;
|
|
193
186
|
}
|
|
194
|
-
const scope = groupScope(member, group, channel);
|
|
187
|
+
const scope = places.groupScope(member, group, channel);
|
|
195
188
|
control.sessions.add(scope.session);
|
|
196
189
|
share("running", name);
|
|
197
190
|
let result: TurnResult;
|
|
@@ -5,8 +5,8 @@ import type { ModeOrigins } from "../modes/mode-inheritance.ts";
|
|
|
5
5
|
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
6
6
|
import { isHelper } from "./agent-rules.ts";
|
|
7
7
|
import type { Agent } from "./agent-store.ts";
|
|
8
|
-
import { agentOfChannel, groupOfChannel, keysOf } from "./team-keys.ts";
|
|
9
8
|
import type { TeamContext } from "./team-options.ts";
|
|
9
|
+
import type { TeamPlaces } from "./team-places.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Makes the temp knight's conversations follow the modes of the conversation that asked for it,
|
|
@@ -21,10 +21,10 @@ export async function followOrigin(
|
|
|
21
21
|
speaker: Speaker,
|
|
22
22
|
helper: Agent,
|
|
23
23
|
): Promise<void> {
|
|
24
|
-
const {
|
|
24
|
+
const { places } = ctx.options;
|
|
25
25
|
const modes = ctx.options.modes?.();
|
|
26
26
|
if (!modes) return;
|
|
27
|
-
const keys = keysOf(
|
|
27
|
+
const keys = places.keysOf(helper.name);
|
|
28
28
|
if (speaker.tier !== "owner" || speaker.principalId === SYSTEM_PRINCIPAL) {
|
|
29
29
|
for (const key of keys) await modes.forget(key);
|
|
30
30
|
return;
|
|
@@ -39,22 +39,16 @@ export async function followOrigin(
|
|
|
39
39
|
* archived or deleted.
|
|
40
40
|
*/
|
|
41
41
|
export function modeOrigins(
|
|
42
|
-
store: Pick<
|
|
43
|
-
|
|
44
|
-
"agent" | "agentByChannel" | "group" | "groupByChannel"
|
|
45
|
-
>,
|
|
46
|
-
hosts: { roomSurfaces(): readonly string[] },
|
|
42
|
+
store: Pick<AgentDirectory, "agent">,
|
|
43
|
+
places: Pick<TeamPlaces, "agentOf" | "groupOf">,
|
|
47
44
|
): ModeOrigins {
|
|
48
45
|
return {
|
|
49
46
|
originOf: (channel, origin) => {
|
|
50
|
-
const helper =
|
|
47
|
+
const helper = places.agentOf(channel);
|
|
51
48
|
if (!helper || !isHelper(helper) || helper.origin !== origin)
|
|
52
49
|
return undefined;
|
|
53
50
|
const parent = store.agent(helper.parent as string);
|
|
54
|
-
const owner =
|
|
55
|
-
agentOfChannel(store, hosts, origin) ??
|
|
56
|
-
groupOfChannel(store, hosts, origin) ??
|
|
57
|
-
parent;
|
|
51
|
+
const owner = places.agentOf(origin) ?? places.groupOf(origin) ?? parent;
|
|
58
52
|
return {
|
|
59
53
|
name: parent?.displayName ?? (helper.parent as string),
|
|
60
54
|
alive: owner?.status === "active",
|
|
@@ -4,14 +4,14 @@ import type { Logger } from "../kernel/log.ts";
|
|
|
4
4
|
import type { AgentTurnRunner } from "./agent-ports.ts";
|
|
5
5
|
import { isHelper } from "./agent-rules.ts";
|
|
6
6
|
import type { PgAgentStore } from "./agent-store.ts";
|
|
7
|
-
import {
|
|
7
|
+
import type { TeamPlaces } from "./team-places.ts";
|
|
8
8
|
|
|
9
9
|
export interface HelperWorkOptions {
|
|
10
10
|
store: Pick<PgAgentStore, "agent" | "group" | "setFinished">;
|
|
11
11
|
queue: Pick<QueuePort, "size">;
|
|
12
12
|
runtime: () => Pick<AgentTurnRunner, "heldActions">;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** Where the temp knight is: its stored place, such as a Discord thread, and its room on each surface that hosts rooms. */
|
|
14
|
+
places: Pick<TeamPlaces, "keysOf" | "scopeOf">;
|
|
15
15
|
/** Called after a temp knight's state changed, so the pages and the dashboard redraw. */
|
|
16
16
|
changed: () => void;
|
|
17
17
|
logger: Logger;
|
|
@@ -73,15 +73,16 @@ export class HelperWork {
|
|
|
73
73
|
|
|
74
74
|
/** Whether something else waits: a turn queued behind this one, or an action held for the owner. */
|
|
75
75
|
async #waiting(name: string): Promise<boolean> {
|
|
76
|
-
const { store, queue,
|
|
76
|
+
const { store, queue, places } = this.#options;
|
|
77
77
|
const agent = store.agent(name);
|
|
78
78
|
if (!agent) return false;
|
|
79
|
-
const keys: ChannelKey[] = keysOf(
|
|
79
|
+
const keys: ChannelKey[] = places.keysOf(name);
|
|
80
80
|
// The task that just ended still counts in its channel's queue until it returns.
|
|
81
81
|
if (keys.some((key) => queue.size(key) > 1)) return true;
|
|
82
82
|
const runtime = this.#options.runtime();
|
|
83
83
|
for (const key of keys)
|
|
84
|
-
if (await runtime.heldActions(scopeOf(agent, key).session))
|
|
84
|
+
if (await runtime.heldActions(places.scopeOf(agent, key).session))
|
|
85
|
+
return true;
|
|
85
86
|
return false;
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -3,13 +3,16 @@ import { AgentError } from "../domain/errors.ts";
|
|
|
3
3
|
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
4
4
|
import type { Agent } from "./agent-store.ts";
|
|
5
5
|
import { Routes } from "./routes.ts";
|
|
6
|
-
import {
|
|
6
|
+
import type { TeamPlaces } from "./team-places.ts";
|
|
7
7
|
|
|
8
8
|
/** What the choice of a message's conversation reads. */
|
|
9
9
|
export interface MessageTargetContext {
|
|
10
10
|
store: Pick<AgentDirectory, "agent" | "group">;
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/** Where the agents are: their places on the surfaces that hold them. */
|
|
12
|
+
places: Pick<
|
|
13
|
+
TeamPlaces,
|
|
14
|
+
"keysOf" | "placeOn" | "rooms" | "surfaces" | "roomSurfaceOf"
|
|
15
|
+
>;
|
|
13
16
|
/**
|
|
14
17
|
* The conversation the target last ran a turn in, if it ran one since the host started; read
|
|
15
18
|
* only under the `"latest"` routing rule, and only on the sender's surface.
|
|
@@ -35,13 +38,13 @@ export function messageTarget(
|
|
|
35
38
|
target: Agent,
|
|
36
39
|
ask: string | undefined,
|
|
37
40
|
): ChannelKey {
|
|
38
|
-
const keys = keysOf(
|
|
41
|
+
const keys = ctx.places.keysOf(target.name);
|
|
39
42
|
const has = keys.length > 0 ? keys.join(", ") : "none";
|
|
40
43
|
const routes =
|
|
41
44
|
ctx.routes ??
|
|
42
45
|
new Routes({
|
|
43
46
|
store: ctx.store,
|
|
44
|
-
|
|
47
|
+
places: ctx.places,
|
|
45
48
|
latest: () => ctx.latest,
|
|
46
49
|
});
|
|
47
50
|
if (ask === undefined || ask.trim() === "")
|
|
@@ -49,20 +52,29 @@ export function messageTarget(
|
|
|
49
52
|
const wanted = ask.trim();
|
|
50
53
|
const exact = keys.find((key) => key === wanted);
|
|
51
54
|
if (exact !== undefined) return exact;
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
const rooms = ctx.places.rooms();
|
|
56
|
+
// A surface whose places are stored: the agent has one there or none.
|
|
57
|
+
if (
|
|
58
|
+
wanted === "discord" ||
|
|
59
|
+
(!rooms.includes(wanted) && ctx.places.surfaces().includes(wanted))
|
|
60
|
+
) {
|
|
61
|
+
const place = routes.placeOn(target.name, wanted);
|
|
54
62
|
if (!place)
|
|
55
63
|
throw new AgentError(
|
|
56
|
-
`${target.name} has no Discord channel; its conversations: ${has}.`,
|
|
64
|
+
`${target.name} has no ${wanted === "discord" ? "Discord channel" : `place on ${wanted}`}; its conversations: ${has}.`,
|
|
57
65
|
);
|
|
58
66
|
return place;
|
|
59
67
|
}
|
|
60
|
-
const surface =
|
|
68
|
+
const surface = rooms.includes(wanted)
|
|
61
69
|
? wanted
|
|
62
|
-
: wanted === WEB &&
|
|
63
|
-
?
|
|
70
|
+
: wanted === WEB && rooms.length === 1
|
|
71
|
+
? rooms[0]
|
|
64
72
|
: undefined;
|
|
65
|
-
|
|
73
|
+
const room =
|
|
74
|
+
surface === undefined
|
|
75
|
+
? undefined
|
|
76
|
+
: ctx.places.placeOn(target.name, surface);
|
|
77
|
+
if (room !== undefined) return room;
|
|
66
78
|
throw new AgentError(
|
|
67
79
|
`${target.name} has no conversation "${wanted}"; its conversations: ${has}. Give "discord", "web" (or the surface's name), or one of those keys.`,
|
|
68
80
|
);
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { ChannelKey } from "../domain/conversation.ts";
|
|
2
2
|
import type { TurnProgress } from "../domain/progress.ts";
|
|
3
|
-
import { discordIdOf } from "./team-keys.ts";
|
|
4
3
|
import type { TeamTurnsOptions } from "./team-turn-types.ts";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
* What a turn in a room shows as it goes, through the room's surface; none in a
|
|
8
|
-
* channel, which shows only the final reply, or on a surface that shows no progress.
|
|
6
|
+
* What a turn in a room shows as it goes, through the room's surface; none in a stored place,
|
|
7
|
+
* such as a Discord channel, which shows only the final reply, or on a surface that shows no progress.
|
|
9
8
|
*/
|
|
10
9
|
export function roomProgress(
|
|
11
|
-
{
|
|
10
|
+
{
|
|
11
|
+
surfaces,
|
|
12
|
+
places,
|
|
13
|
+
logger,
|
|
14
|
+
}: Pick<TeamTurnsOptions, "surfaces" | "places" | "logger">,
|
|
12
15
|
channel: ChannelKey,
|
|
13
16
|
): ((event: TurnProgress) => void) | undefined {
|
|
14
|
-
if (
|
|
15
|
-
return undefined;
|
|
17
|
+
if (places.isStored(channel) || !surfaces?.progress) return undefined;
|
|
16
18
|
return (event) => {
|
|
17
19
|
// pi-lens-ignore: no-unknown-parameters — a rejection reason is unknown; it only reaches the logger
|
|
18
20
|
surfaces
|