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.
- package/CHANGELOG.md +41 -0
- package/docs/plugins.md +32 -7
- package/package.json +1 -1
- package/src/characters/compose.ts +7 -3
- package/src/characters/index.ts +1 -0
- package/src/characters/parts-face.ts +4 -1
- package/src/core/agents/agent-claim.ts +2 -2
- package/src/core/agents/agent-group-store.ts +74 -1
- package/src/core/agents/agent-places.ts +32 -0
- package/src/core/agents/agent-ports.ts +0 -94
- package/src/core/agents/agent-prompt.ts +3 -1
- package/src/core/agents/agent-team-fixture.ts +48 -7
- package/src/core/agents/agent-team.ts +54 -59
- package/src/core/agents/agent-tools.ts +34 -166
- package/src/core/agents/message-target.ts +3 -2
- package/src/core/agents/routes.ts +2 -1
- package/src/core/agents/team-editing.ts +121 -150
- package/src/core/agents/team-helpers.ts +80 -59
- package/src/core/agents/team-keys.ts +16 -26
- package/src/core/agents/team-lifecycle.ts +155 -99
- package/src/core/agents/team-looks.ts +102 -0
- package/src/core/agents/team-options.ts +12 -11
- package/src/core/agents/team-place-writes.ts +193 -0
- package/src/core/agents/team-places.ts +30 -0
- package/src/core/agents/team-posts.ts +42 -73
- package/src/core/agents/team-selection.ts +10 -2
- package/src/core/agents/team-status.ts +3 -2
- package/src/core/agents/team-text.ts +13 -46
- package/src/core/agents/team-turn-types.ts +11 -16
- package/src/core/agents/team-turns.ts +7 -6
- package/src/core/builtin/agent-server-options.ts +27 -6
- package/src/core/builtin/agent-server.ts +65 -69
- package/src/core/builtin/discord.ts +58 -8
- package/src/core/builtin/modules.ts +2 -0
- package/src/core/contract/agent-channels.ts +97 -0
- package/src/core/contract/channels.ts +10 -4
- package/src/core/contract/discord-key.ts +15 -0
- package/src/core/contract/places.ts +8 -2
- package/src/core/db/legacy-channels.ts +31 -0
- package/src/core/discord/agent-dashboard-service.ts +55 -0
- package/src/core/{agents → discord}/agent-dashboard.ts +7 -2
- package/src/core/discord/agent-discord.ts +1 -1
- package/src/core/discord/agent-guild.ts +87 -0
- package/src/core/{agents/team-layout.ts → discord/agent-layout.ts} +9 -29
- package/src/core/discord/agent-places.ts +52 -33
- package/src/core/discord/agent-tools.ts +210 -0
- package/src/core/discord/connection.ts +4 -1
- package/src/core/discord/discord-surface.ts +9 -14
- package/src/core/discord/place-fake-client.ts +59 -0
- package/src/core/host/define-roundtable.ts +7 -5
- package/src/core/modules/delegation/delegator.ts +5 -0
- package/src/core/plugin-api/agent-ops.ts +123 -0
- package/src/core/plugin-api/agent-server-ids.ts +9 -0
- package/src/core/plugin-api/define.ts +9 -0
- package/src/core/plugin-api/plugin.ts +2 -0
- package/src/core/plugin-api/services.ts +6 -0
- package/src/core/registry/contributions.ts +3 -0
- package/src/core/routing/channel-queue.ts +28 -12
- package/src/core/runtime/pi-agent-runtime.ts +1 -1
- package/src/core/runtime/runtime-plugin.ts +1 -0
- package/src/core/runtime/runtime-types.ts +6 -0
- package/src/core/{agents/agent-team-fake-channels.ts → testing/fake-agent-channels.ts} +5 -1
- package/src/core/testing/fake-pager-places.ts +16 -2
- package/src/core/testing/modules.ts +2 -1
- package/src/core/testing/place-contract.ts +3 -2
- package/src/core/testing/team-places.ts +75 -7
- package/src/core/testing/test-host.ts +20 -16
- package/src/discord/index.ts +5 -0
- package/src/kit/channels.ts +1 -2
- package/src/kit/support.ts +9 -5
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { PlaceProvider, PlaceRef, PlaceSpec } from "../contract/places.ts";
|
|
2
|
+
import type { ChannelKey } from "../domain/conversation.ts";
|
|
3
|
+
import type { Agent } from "./agent-store.ts";
|
|
4
|
+
import type { TeamContext } from "./team-options.ts";
|
|
5
|
+
|
|
6
|
+
/** A place made or brought back on a surface, by its id there. */
|
|
7
|
+
export interface MadePlace {
|
|
8
|
+
surface: string;
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** What a place is made or kept for: its owner, and the texts the surface shows it under. */
|
|
13
|
+
export interface PlaceWish extends PlaceRef {
|
|
14
|
+
displayName: string;
|
|
15
|
+
/** An agent's display name; a group's members and host on one line. */
|
|
16
|
+
topic: string;
|
|
17
|
+
/** What the creating tool was given for the providers' own arguments, such as `category`. */
|
|
18
|
+
hints?: Readonly<Record<string, string>>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Where a temp knight's place goes: under its parent's place, on the surface it was made from. */
|
|
22
|
+
export interface HelperOrigin {
|
|
23
|
+
parent: Agent;
|
|
24
|
+
/** The conversation it was made from; absent, every surface that has a place for the parent. */
|
|
25
|
+
origin?: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const specOf = (wish: PlaceWish): PlaceSpec => ({
|
|
29
|
+
kind: wish.kind,
|
|
30
|
+
name: wish.name,
|
|
31
|
+
displayName: wish.displayName,
|
|
32
|
+
topic: wish.topic,
|
|
33
|
+
...(wish.hints ? { hints: wish.hints } : {}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The team's writes to the places of its agents and groups, through the stored place providers
|
|
38
|
+
* that make them: `ensure` makes a place or brings an archived one back, `remove` keeps it where
|
|
39
|
+
* nobody answers, and `describe` writes a group's topic. A provider that does not make places
|
|
40
|
+
* (a derived one's rooms exist with the name) is left out; so is one the owner has no place on.
|
|
41
|
+
*/
|
|
42
|
+
export class TeamPlaceWrites {
|
|
43
|
+
readonly #ctx: TeamContext;
|
|
44
|
+
|
|
45
|
+
constructor(ctx: TeamContext) {
|
|
46
|
+
this.#ctx = ctx;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The stored providers that make places, in contribution order. */
|
|
50
|
+
#makers(): PlaceProvider[] {
|
|
51
|
+
return this.#ctx.options.places
|
|
52
|
+
.stored()
|
|
53
|
+
.filter((provider) => provider.ensure !== undefined);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Makes the places of a new agent or group, one on each provider that makes them, or, for a
|
|
58
|
+
* temp knight, under its parent's place on each surface it was made from. Nothing is recorded:
|
|
59
|
+
* `record` does that once the owner exists.
|
|
60
|
+
*/
|
|
61
|
+
async make(wish: PlaceWish, under?: HelperOrigin): Promise<MadePlace[]> {
|
|
62
|
+
const made: MadePlace[] = [];
|
|
63
|
+
for (const provider of this.#makers()) {
|
|
64
|
+
const colon = under?.origin?.indexOf(":") ?? -1;
|
|
65
|
+
const from = colon > 0 ? under?.origin?.slice(0, colon) : undefined;
|
|
66
|
+
if (from && from !== provider.surface) continue;
|
|
67
|
+
const place = await this.makeOn(provider.surface, wish, under?.parent);
|
|
68
|
+
if (place) made.push(place);
|
|
69
|
+
}
|
|
70
|
+
return made;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Makes the owner's place on one surface, or brings back the one it has there; for a temp
|
|
75
|
+
* knight, under its parent's place on that surface. None when the surface makes no places or the
|
|
76
|
+
* parent has none there. Nothing is recorded.
|
|
77
|
+
*/
|
|
78
|
+
async makeOn(
|
|
79
|
+
surface: string,
|
|
80
|
+
wish: PlaceWish,
|
|
81
|
+
parent?: Agent,
|
|
82
|
+
): Promise<MadePlace | undefined> {
|
|
83
|
+
const { places } = this.#ctx.options;
|
|
84
|
+
const provider = places.providerOf(surface);
|
|
85
|
+
if (provider?.storage !== "stored" || !provider.ensure) return undefined;
|
|
86
|
+
const spec = specOf(wish);
|
|
87
|
+
if (parent) {
|
|
88
|
+
const above = places.idOf(
|
|
89
|
+
{ kind: "agent", name: parent.name },
|
|
90
|
+
provider.surface,
|
|
91
|
+
);
|
|
92
|
+
if (above === undefined) return undefined;
|
|
93
|
+
spec.parent = above;
|
|
94
|
+
}
|
|
95
|
+
const existing = places.idOf(wish, provider.surface);
|
|
96
|
+
if (existing !== undefined) spec.existing = existing;
|
|
97
|
+
return { surface, id: await provider.ensure(spec) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Records the places an owner now has, in place of any it had on those surfaces. */
|
|
101
|
+
async record(ref: PlaceRef, made: readonly MadePlace[]): Promise<void> {
|
|
102
|
+
const { store } = this.#ctx.options;
|
|
103
|
+
for (const place of made)
|
|
104
|
+
await store.setPlace(ref.kind, ref.name, place.surface, place.id);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Brings an owner's archived places back, each under its own id (a place deleted meanwhile is
|
|
109
|
+
* made again), and makes one for an agent that had none on a surface that makes them; a group
|
|
110
|
+
* is given none it never had. Recorded by the caller.
|
|
111
|
+
*/
|
|
112
|
+
async bringBack(wish: PlaceWish): Promise<MadePlace[]> {
|
|
113
|
+
const { places } = this.#ctx.options;
|
|
114
|
+
const made: MadePlace[] = [];
|
|
115
|
+
for (const provider of this.#makers()) {
|
|
116
|
+
if (
|
|
117
|
+
wish.kind === "group" &&
|
|
118
|
+
places.idOf(wish, provider.surface) === undefined
|
|
119
|
+
)
|
|
120
|
+
continue;
|
|
121
|
+
const place = await this.makeOn(provider.surface, wish);
|
|
122
|
+
if (place) made.push(place);
|
|
123
|
+
}
|
|
124
|
+
return made;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Keeps an archived owner's places where nobody answers, with their history; says, for the
|
|
129
|
+
* archive tool's answer, what each provider did. A provider that fails is logged, and the rest
|
|
130
|
+
* go on.
|
|
131
|
+
*/
|
|
132
|
+
async keep(wish: PlaceWish, helper: boolean): Promise<string> {
|
|
133
|
+
const { places, logger } = this.#ctx.options;
|
|
134
|
+
let said = "";
|
|
135
|
+
for (const provider of places.stored()) {
|
|
136
|
+
const id = places.idOf(wish, provider.surface);
|
|
137
|
+
if (id === undefined || !provider.remove) continue;
|
|
138
|
+
try {
|
|
139
|
+
const line = await provider.remove(id, { ...specOf(wish), helper });
|
|
140
|
+
// A line that brings no separator of its own (a provider of the first contract) gets one.
|
|
141
|
+
if (line) said += /^[;,]/.test(line) ? line : `; ${line}`;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
logger.warn(
|
|
144
|
+
{ name: wish.name, surface: provider.surface, err: error },
|
|
145
|
+
"archived place not kept",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return said;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Closes the places made for an owner that was never recorded, logging a failure. */
|
|
153
|
+
async discard(wish: PlaceWish, made: readonly MadePlace[]): Promise<void> {
|
|
154
|
+
const { places, logger } = this.#ctx.options;
|
|
155
|
+
for (const place of made)
|
|
156
|
+
await places
|
|
157
|
+
.providerOf(place.surface)
|
|
158
|
+
?.remove?.(place.id, { ...specOf(wish), helper: true })
|
|
159
|
+
.catch((err: unknown) =>
|
|
160
|
+
logger.warn({ err }, "orphan place not closed"),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Writes a group's topic on every surface that has a place for it, without waiting. */
|
|
165
|
+
describe(wish: PlaceWish): void {
|
|
166
|
+
const { places, logger } = this.#ctx.options;
|
|
167
|
+
for (const provider of places.stored()) {
|
|
168
|
+
const id = places.idOf(wish, provider.surface);
|
|
169
|
+
if (id === undefined || !provider.describe) continue;
|
|
170
|
+
provider
|
|
171
|
+
.describe(id, wish.topic)
|
|
172
|
+
.catch((error: unknown) =>
|
|
173
|
+
logger.warn(
|
|
174
|
+
{ group: wish.name, err: error },
|
|
175
|
+
"group topic not updated",
|
|
176
|
+
),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** How the model names the made places in text, such as `<#id>`. */
|
|
182
|
+
mentions(ref: PlaceRef, made: readonly MadePlace[]): string {
|
|
183
|
+
const { places } = this.#ctx.options;
|
|
184
|
+
return made
|
|
185
|
+
.flatMap((place) => {
|
|
186
|
+
const key: ChannelKey | undefined = places
|
|
187
|
+
.providerOf(place.surface)
|
|
188
|
+
?.key(ref, place.id);
|
|
189
|
+
return key === undefined ? [] : [places.mention(key)];
|
|
190
|
+
})
|
|
191
|
+
.join(", ");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -61,6 +61,36 @@ export class TeamPlaces {
|
|
|
61
61
|
return this.#port?.all() ?? [];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/** The stored providers, in contribution order: the surfaces whose places the team keeps rows for. */
|
|
65
|
+
stored(): readonly PlaceProvider[] {
|
|
66
|
+
return this.#port?.stored() ?? [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The id of the agent's or group's place on a surface, when it has one there. */
|
|
70
|
+
idOf(ref: PlaceRef, surface: string): string | undefined {
|
|
71
|
+
return this.#stored.on(ref.kind, ref.name, surface);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The key of a stored place by its id on a surface, as a provider that reports a deleted place gives only the id. */
|
|
75
|
+
keyOfId(surface: string, id: string): ChannelKey | undefined {
|
|
76
|
+
const provider = this.providerOf(surface);
|
|
77
|
+
// A stored key comes from the id alone; the owner does not enter into it.
|
|
78
|
+
return provider?.storage === "stored"
|
|
79
|
+
? provider.key({ kind: "agent", name: id }, id)
|
|
80
|
+
: undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The place whose agent is the coordinator, when a stored provider names one (Discord's entry
|
|
85
|
+
* channel); undefined when none does, and the configured `coordinator` is it.
|
|
86
|
+
*/
|
|
87
|
+
entry(): ChannelKey | undefined {
|
|
88
|
+
for (const provider of this.stored())
|
|
89
|
+
if (provider.coordinatorPlace !== undefined)
|
|
90
|
+
return this.keyOfId(provider.surface, provider.coordinatorPlace);
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
64
94
|
/** The surfaces that hold places, in "auto" order. */
|
|
65
95
|
surfaces(): readonly string[] {
|
|
66
96
|
return this.ordered().map((provider) => provider.surface);
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { channelKey, parseChannelKey } from "../contract/surface.ts";
|
|
2
1
|
import { supportOf } from "../domain/block-support.ts";
|
|
3
2
|
import type {
|
|
4
3
|
ChannelKey,
|
|
5
4
|
IntercomCard,
|
|
6
|
-
PostAuthor,
|
|
7
5
|
ReplyFile,
|
|
8
6
|
} from "../domain/conversation.ts";
|
|
9
7
|
import { AgentError } from "../domain/errors.ts";
|
|
10
8
|
import type { InterimPosts } from "../domain/interim.ts";
|
|
11
9
|
import { chunksFor } from "../presentation/reply-chunks.ts";
|
|
12
10
|
import type { Agent } from "./agent-store.ts";
|
|
13
|
-
import { channelIdOf, discordIdOf } from "./team-keys.ts";
|
|
14
11
|
import type { TeamTurnsOptions } from "./team-turn-types.ts";
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* How the team's turns reach a place: whether a reply there may carry files, how its text is cut,
|
|
18
|
-
* and the interim posts and replies under the agent's name, which
|
|
19
|
-
* surface carry.
|
|
15
|
+
* and the interim posts and replies under the agent's name, which the place's provider carries.
|
|
20
16
|
*/
|
|
21
17
|
export class TeamPosts {
|
|
22
18
|
readonly #options: TeamTurnsOptions;
|
|
@@ -31,14 +27,11 @@ export class TeamPosts {
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
/**
|
|
34
|
-
* Whether a reply in the channel may carry files:
|
|
35
|
-
*
|
|
30
|
+
* Whether a reply in the channel may carry files: only when the surface that serves it declares
|
|
31
|
+
* `supportsFiles`, since a reply with files that surface refuses is lost whole.
|
|
36
32
|
*/
|
|
37
33
|
carriesFiles(channel: ChannelKey): boolean {
|
|
38
|
-
return (
|
|
39
|
-
discordIdOf(channel) !== undefined ||
|
|
40
|
-
this.#options.surfaces?.of(channel)?.supportsFiles === true
|
|
41
|
-
);
|
|
34
|
+
return this.#options.surfaces?.of(channel)?.supportsFiles === true;
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
/** What the surface that serves the channel does there (see `supportOf`). */
|
|
@@ -57,49 +50,35 @@ export class TeamPosts {
|
|
|
57
50
|
|
|
58
51
|
/**
|
|
59
52
|
* The turn's interim posts under the agent's name, read as each goes out so a name changed
|
|
60
|
-
* during the turn shows; none in a channel no agent or group owns any more
|
|
53
|
+
* during the turn shows; none in a channel no agent or group owns any more, and none where the
|
|
54
|
+
* place's provider shows none.
|
|
61
55
|
*/
|
|
62
56
|
interim(channel: ChannelKey, agent: Agent): InterimPosts | undefined {
|
|
63
|
-
const { places
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!surfaces || !first) return undefined;
|
|
68
|
-
return {
|
|
69
|
-
...(first.tools === false ? { tools: false } : {}),
|
|
70
|
-
// The poster cuts text for the surface the posts go to.
|
|
71
|
-
...(first.blocks ? { blocks: first.blocks } : {}),
|
|
72
|
-
...(first.blockText ? { blockText: first.blockText } : {}),
|
|
73
|
-
post: async (text) => {
|
|
74
|
-
if (!places.ownerKind(channel))
|
|
75
|
-
throw new AgentError(`${channel} is archived`);
|
|
76
|
-
const posts = surfaces.interim(
|
|
77
|
-
channel,
|
|
78
|
-
this.author(this.#current(agent)),
|
|
79
|
-
);
|
|
80
|
-
if (!posts) throw new AgentError(`${channel} shows no interim posts`);
|
|
81
|
-
return posts.post(text);
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (!channels?.interim) return undefined;
|
|
86
|
-
const interim = channels.interim.bind(channels);
|
|
57
|
+
const { places } = this.#options;
|
|
58
|
+
const provider = places.providerOf(channel);
|
|
59
|
+
const first = provider?.interim?.(channel, this.author(agent));
|
|
60
|
+
if (!provider || !first) return undefined;
|
|
87
61
|
return {
|
|
62
|
+
...(first.tools === false ? { tools: false } : {}),
|
|
63
|
+
// The poster cuts text for the surface the posts go to.
|
|
64
|
+
...(first.blocks ? { blocks: first.blocks } : {}),
|
|
65
|
+
...(first.blockText ? { blockText: first.blockText } : {}),
|
|
88
66
|
post: async (text) => {
|
|
89
67
|
if (!places.ownerKind(channel))
|
|
90
68
|
throw new AgentError(`${channel} is archived`);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
const posts = provider.interim?.(
|
|
70
|
+
channel,
|
|
71
|
+
this.author(this.#current(agent)),
|
|
72
|
+
);
|
|
73
|
+
if (!posts) throw new AgentError(`${channel} shows no interim posts`);
|
|
74
|
+
return posts.post(text);
|
|
96
75
|
},
|
|
97
76
|
};
|
|
98
77
|
}
|
|
99
78
|
|
|
100
79
|
/**
|
|
101
|
-
* Posts under the agent's name. A channel no agent or group owns
|
|
102
|
-
* turn ran, gets nothing, so its webhook is not made again.
|
|
80
|
+
* Posts under the agent's name through the place's provider. A channel no agent or group owns
|
|
81
|
+
* any more, archived while a turn ran, gets nothing, so its webhook is not made again.
|
|
103
82
|
*/
|
|
104
83
|
async post(
|
|
105
84
|
channel: ChannelKey,
|
|
@@ -113,7 +92,7 @@ export class TeamPosts {
|
|
|
113
92
|
intercom?: IntercomCard;
|
|
114
93
|
},
|
|
115
94
|
): Promise<void> {
|
|
116
|
-
const { places,
|
|
95
|
+
const { places, logger } = this.#options;
|
|
117
96
|
if (!places.ownerKind(channel)) {
|
|
118
97
|
logger.info(
|
|
119
98
|
{ channel, agent: as.name },
|
|
@@ -121,37 +100,27 @@ export class TeamPosts {
|
|
|
121
100
|
);
|
|
122
101
|
return;
|
|
123
102
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
...(thinking ? { thinking } : {}),
|
|
137
|
-
chunks,
|
|
138
|
-
...(files?.length ? { files } : {}),
|
|
139
|
-
author: this.author(as),
|
|
140
|
-
...(failed ? { failed } : {}),
|
|
141
|
-
...(intercom ? { intercom } : {}),
|
|
142
|
-
},
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
if (!channels) throw new AgentError(`no Discord channels serve ${channel}`);
|
|
146
|
-
return channels.post(channelIdOf(channel), {
|
|
147
|
-
name: as.displayName,
|
|
148
|
-
avatarUrl: studio.url(as.avatarHash),
|
|
149
|
-
...rest,
|
|
103
|
+
const provider = places.providerOf(channel);
|
|
104
|
+
if (!provider)
|
|
105
|
+
throw new AgentError(`no surface serves the place ${channel}`);
|
|
106
|
+
const { threadId, thinking, chunks, files, failed, intercom } = body;
|
|
107
|
+
return provider.post(channel, {
|
|
108
|
+
author: this.author(as),
|
|
109
|
+
...(thinking ? { thinking } : {}),
|
|
110
|
+
chunks,
|
|
111
|
+
...(files?.length ? { files } : {}),
|
|
112
|
+
...(threadId === undefined ? {} : { thread: threadId }),
|
|
113
|
+
...(failed ? { failed } : {}),
|
|
114
|
+
...(intercom ? { intercom } : {}),
|
|
150
115
|
});
|
|
151
116
|
}
|
|
152
117
|
|
|
153
|
-
/** Who speaks for the agent
|
|
154
|
-
author(agent: Agent)
|
|
155
|
-
return {
|
|
118
|
+
/** Who speaks for the agent: its name and look. */
|
|
119
|
+
author(agent: Agent) {
|
|
120
|
+
return {
|
|
121
|
+
name: agent.displayName,
|
|
122
|
+
agent: agent.name,
|
|
123
|
+
avatarUrl: this.#options.studio.url(agent.avatarHash),
|
|
124
|
+
};
|
|
156
125
|
}
|
|
157
126
|
}
|
|
@@ -14,7 +14,11 @@ import type { AgentTeamOptions } from "./team-options.ts";
|
|
|
14
14
|
export function teamSelection(
|
|
15
15
|
options: Pick<
|
|
16
16
|
AgentTeamOptions,
|
|
17
|
-
|
|
17
|
+
| "pluginSelection"
|
|
18
|
+
| "pluginTools"
|
|
19
|
+
| "pluginWithheldFromHelpers"
|
|
20
|
+
| "agentTools"
|
|
21
|
+
| "helpers"
|
|
18
22
|
> & { store?: Pick<AgentTeamOptions["store"], "agent"> },
|
|
19
23
|
scope?: AgentTurnScope,
|
|
20
24
|
): TurnSelection {
|
|
@@ -24,7 +28,11 @@ export function teamSelection(
|
|
|
24
28
|
const helper =
|
|
25
29
|
scope !== undefined && isHelper(options.store?.agent(scope.name));
|
|
26
30
|
const kept = (tool: string): boolean =>
|
|
27
|
-
!(
|
|
31
|
+
!(
|
|
32
|
+
helper &&
|
|
33
|
+
(WITHHELD_FROM_HELPERS.includes(tool) ||
|
|
34
|
+
options.pluginWithheldFromHelpers?.().includes(tool))
|
|
35
|
+
) &&
|
|
28
36
|
!(
|
|
29
37
|
(options.helpers === false || scope?.group) &&
|
|
30
38
|
(HELPER_TOOLS as readonly string[]).includes(tool)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { legacyChannelIdOf } from "../db/legacy-channels.ts";
|
|
1
2
|
import type { ThinkingSetting } from "../domain/models.ts";
|
|
2
3
|
import type { ContextUse } from "./agent-ports.ts";
|
|
3
|
-
import { discordIdOf } from "./team-keys.ts";
|
|
4
4
|
import type { TeamContext } from "./team-options.ts";
|
|
5
5
|
import type { TeamPlace } from "./team-places.ts";
|
|
6
6
|
|
|
@@ -63,7 +63,8 @@ export async function teamStatus(ctx: TeamContext): Promise<TeamStatus> {
|
|
|
63
63
|
const keys = places.keysOf(agent.name);
|
|
64
64
|
const working = turns.workingIn(agent.name);
|
|
65
65
|
// The board links Discord channels; a turn in a room has none to link.
|
|
66
|
-
const workingIn =
|
|
66
|
+
const workingIn =
|
|
67
|
+
working === undefined ? undefined : legacyChannelIdOf(working);
|
|
67
68
|
const queued = keys.reduce((sum, key) => sum + queue.size(key), 0);
|
|
68
69
|
const context = keys
|
|
69
70
|
.map((key) => runtime.contextUsage?.(key))
|
|
@@ -1,36 +1,10 @@
|
|
|
1
1
|
import { CATALOG, type CharacterSpec } from "../../characters/index.ts";
|
|
2
|
-
import { AgentError } from "../domain/errors.ts";
|
|
3
2
|
import type { ThinkingSetting } from "../domain/models.ts";
|
|
4
|
-
import { assistantName } from "../i18n/index.ts";
|
|
5
|
-
import { zonedStamp } from "../kernel/time.ts";
|
|
3
|
+
import { assistantName, messages } from "../i18n/index.ts";
|
|
6
4
|
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
7
|
-
import type { AgentChannels, ChannelMessage } from "./agent-ports.ts";
|
|
8
5
|
import { characterOf, isHelper } from "./agent-rules.ts";
|
|
9
6
|
import { describeThinking } from "./agent-settings.ts";
|
|
10
|
-
import type { Agent } from "./agent-store.ts";
|
|
11
|
-
|
|
12
|
-
/** Said by the tools that work on Discord channels when the team has none. */
|
|
13
|
-
export const NO_CHANNELS =
|
|
14
|
-
"This host has no Discord channels: the agents live in rooms of a chat surface, so there is nothing to arrange or read here.";
|
|
15
|
-
|
|
16
|
-
/** One message as channel_read shows it: id, local time, author, text, attachments. */
|
|
17
|
-
export function messageLine(message: ChannelMessage): string {
|
|
18
|
-
const files =
|
|
19
|
-
message.attachments.length > 0
|
|
20
|
-
? ` [attachments: ${message.attachments.join(", ")}]`
|
|
21
|
-
: "";
|
|
22
|
-
return `[${message.id}] ${zonedStamp(message.at)} ${message.author}: ${message.text}${files}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** A channel given as `<#id>` or its id, as its id. */
|
|
26
|
-
export function channelIdFromRef(channel: string): string {
|
|
27
|
-
const id = /^<#(\d+)>$/.exec(channel.trim())?.[1] ?? channel.trim();
|
|
28
|
-
if (!/^\d+$/.test(id))
|
|
29
|
-
throw new AgentError(
|
|
30
|
-
"Give the channel as <#id> or its id, as in a forwarded message.",
|
|
31
|
-
);
|
|
32
|
-
return id;
|
|
33
|
-
}
|
|
7
|
+
import type { Agent, AgentGroup } from "./agent-store.ts";
|
|
34
8
|
|
|
35
9
|
/** Every agent and group as agent_list shows them, before the category layout. */
|
|
36
10
|
export function teamListText(store: Pick<AgentDirectory, "agents" | "groups">) {
|
|
@@ -91,22 +65,15 @@ export function agentDetails(
|
|
|
91
65
|
].join("\n");
|
|
92
66
|
}
|
|
93
67
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const messages = await channels.read(id, {
|
|
106
|
-
limit: Math.min(Math.max(limit ?? 20, 1), READ_LIMIT),
|
|
107
|
-
...(around ? { around } : {}),
|
|
108
|
-
});
|
|
109
|
-
return messages.length > 0
|
|
110
|
-
? messages.map(messageLine).join("\n")
|
|
111
|
-
: `<#${id}> has no messages there.`;
|
|
68
|
+
/** A group channel's topic: who is in it and who hosts. */
|
|
69
|
+
export function groupTopic(
|
|
70
|
+
group: AgentGroup,
|
|
71
|
+
store: Pick<AgentDirectory, "agent">,
|
|
72
|
+
): string {
|
|
73
|
+
const shown = (name: string) => store.agent(name)?.displayName ?? name;
|
|
74
|
+
return messages().groupTopic(
|
|
75
|
+
group.displayName,
|
|
76
|
+
group.members.map(shown),
|
|
77
|
+
shown(group.host),
|
|
78
|
+
);
|
|
112
79
|
}
|
|
@@ -16,7 +16,7 @@ import type { Logger } from "../kernel/log.ts";
|
|
|
16
16
|
import type { EventSink } from "../plugin-api/plugin.ts";
|
|
17
17
|
import type { AvatarStudio } from "../plugin-api/services.ts";
|
|
18
18
|
import type { ToolTiers } from "../runtime/tool-tiers.ts";
|
|
19
|
-
import type {
|
|
19
|
+
import type { AgentTurnRunner } from "./agent-ports.ts";
|
|
20
20
|
import type { Agent, PgAgentStore } from "./agent-store.ts";
|
|
21
21
|
import type { RelevanceScorer } from "./group-round.ts";
|
|
22
22
|
import type { HelperWork } from "./helper-work.ts";
|
|
@@ -35,12 +35,12 @@ export interface Chain {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface TeamTurnsOptions {
|
|
38
|
-
/** The agent server's entry channel, where the coordinator lives; absent on a host without
|
|
39
|
-
|
|
38
|
+
/** The agent server's entry channel, where the coordinator lives; absent on a host without one. */
|
|
39
|
+
entryChannel?: ChannelKey;
|
|
40
40
|
/**
|
|
41
|
-
* The coordinator's name on a host without
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* The coordinator's name on a host without an entry channel to find it by; a function is asked
|
|
42
|
+
* each time, for a name that is only known once the plugins linked. Ignored when `entryChannel`
|
|
43
|
+
* is set.
|
|
44
44
|
*/
|
|
45
45
|
coordinator?: string | (() => string | undefined);
|
|
46
46
|
/** Who the agents work for, as their prompts and group history name them. */
|
|
@@ -48,18 +48,13 @@ export interface TeamTurnsOptions {
|
|
|
48
48
|
store: PgAgentStore;
|
|
49
49
|
/** Where the agents and groups are: their keys, and who owns a key, through the host's place providers. */
|
|
50
50
|
places: TeamPlaces;
|
|
51
|
-
/** The Discord channels the agents post in; absent on a host without Discord, where every reply goes through a room's surface. */
|
|
52
|
-
channels?: Pick<AgentChannels, "post" | "interim">;
|
|
53
51
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
52
|
+
* What the team asks of the chat surfaces beyond their places: `of` tells how a place's surface
|
|
53
|
+
* cuts text and whether it carries reply files, `progress` and `groupRound` show a turn's
|
|
54
|
+
* state in a room. Replies and interim posts go through the place providers, which post through
|
|
55
|
+
* the surfaces themselves.
|
|
58
56
|
*/
|
|
59
|
-
surfaces?: Pick<
|
|
60
|
-
SurfacePort,
|
|
61
|
-
"sendReply" | "interim" | "of" | "lang" | "progress" | "groupRound"
|
|
62
|
-
>;
|
|
57
|
+
surfaces?: Pick<SurfacePort, "of" | "lang" | "progress" | "groupRound">;
|
|
63
58
|
studio: Pick<AvatarStudio, "url">;
|
|
64
59
|
/**
|
|
65
60
|
* The host's routing table, which says where work no person started lands. Without one the team
|
|
@@ -18,7 +18,7 @@ import { HelperWork } from "./helper-work.ts";
|
|
|
18
18
|
import { roomProgress } from "./room-progress.ts";
|
|
19
19
|
import { type Routes, routesOf } from "./routes.ts";
|
|
20
20
|
import { mayApprove } from "./team-approval.ts";
|
|
21
|
-
import { coordinatorOf,
|
|
21
|
+
import { coordinatorOf, entryChannelOf } from "./team-keys.ts";
|
|
22
22
|
import { TeamPosts } from "./team-posts.ts";
|
|
23
23
|
import {
|
|
24
24
|
type Chain,
|
|
@@ -295,20 +295,21 @@ export class TeamTurns {
|
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
297
|
* The assistant's own notice, such as a new release, posted in the coordinator's channel under
|
|
298
|
-
* its name: the entry channel, or, without
|
|
298
|
+
* its name: the entry channel, or, without one, its place on the first surface that has one.
|
|
299
299
|
*/
|
|
300
300
|
async announce(text: string): Promise<void> {
|
|
301
|
-
const { store, places
|
|
301
|
+
const { store, places } = this.#options;
|
|
302
|
+
const entryChannel = entryChannelOf(places, this.#options);
|
|
302
303
|
const coordinator = coordinatorOf(store, places, this.#options);
|
|
303
304
|
if (!coordinator)
|
|
304
305
|
throw new AgentError(
|
|
305
|
-
|
|
306
|
+
entryChannel === undefined
|
|
306
307
|
? "no active coordinator"
|
|
307
308
|
: "no active agent in the entry channel",
|
|
308
309
|
);
|
|
309
310
|
const home =
|
|
310
|
-
|
|
311
|
-
?
|
|
311
|
+
entryChannel !== undefined
|
|
312
|
+
? entryChannel
|
|
312
313
|
: this.routes.primary(coordinator.name);
|
|
313
314
|
if (!home)
|
|
314
315
|
throw new AgentError(`${coordinator.name} has no room to post in`);
|