pi-roundtable 0.43.0 → 0.44.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 +11 -0
- package/package.json +3 -1
- package/src/characters/catalog.ts +7 -750
- package/src/characters/class-data.ts +56 -0
- package/src/characters/classes-a.ts +235 -0
- package/src/characters/classes-b.ts +242 -0
- package/src/characters/classes-c.ts +241 -0
- package/src/core/agents/agent-group-store.ts +176 -0
- package/src/core/agents/agent-places.ts +197 -0
- package/src/core/agents/agent-schema.ts +37 -3
- package/src/core/agents/agent-statements.ts +14 -12
- package/src/core/agents/agent-store.ts +81 -211
- package/src/core/builtin/agent-server.ts +10 -0
- package/src/core/db/legacy-channels.ts +92 -0
- package/src/core/db/team-move.ts +55 -20
- package/src/core/testing/fake-discord.ts +67 -0
- package/src/core/testing/plugin-stand-ins.ts +95 -0
- package/src/core/testing/service-pair.ts +18 -0
- package/src/core/testing/test-plugin-types.ts +110 -0
- package/src/testing.ts +32 -272
package/src/core/db/team-move.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LEGACY_CHANNEL_TABLES } from "./legacy-channels.ts";
|
|
1
2
|
import type { Migration } from "./migrations.ts";
|
|
2
3
|
|
|
3
4
|
export interface TeamMoveOptions {
|
|
@@ -15,16 +16,26 @@ export interface TeamMoveOptions {
|
|
|
15
16
|
* already holds, are cleared. Default false.
|
|
16
17
|
*/
|
|
17
18
|
clearChannels?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The surfaces whose stored places name something of the space the team lived in, such as the
|
|
21
|
+
* channels of a Discord guild. A place row moved from a former id other than `keep` is dropped, as
|
|
22
|
+
* the legacy channel ids are cleared, so start makes new places; without `keep` every moved row
|
|
23
|
+
* is dropped. With `clearChannels` the team's own rows of these surfaces go too.
|
|
24
|
+
*/
|
|
25
|
+
places?: readonly { surface: string; keep?: string }[];
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
/** The tables whose rows hold a
|
|
21
|
-
const CHANNEL_TABLES = new Set(
|
|
28
|
+
/** The tables whose rows hold a legacy channel id. */
|
|
29
|
+
const CHANNEL_TABLES = new Set(Object.keys(LEGACY_CHANNEL_TABLES));
|
|
30
|
+
|
|
31
|
+
/** The table of stored places: its second unique key is a place id, which no two owners of a team share. */
|
|
32
|
+
const PLACES_TABLE = "agent_places";
|
|
22
33
|
|
|
23
34
|
/**
|
|
24
|
-
* Moves a former team's rows to the team id: every row of a table with a `guild_id` column whose id
|
|
35
|
+
* Moves a former team's rows to the team id: every row of a table with a `guild_id` (or, for places, `team_id`) column whose id
|
|
25
36
|
* is one of `from`, in the tables the host's plugins keep (agents, groups, skills, prompts, presets,
|
|
26
|
-
* outbox, conversations). Rows of other guilds stay, such as the `discord_*` grants and audit of the
|
|
27
|
-
* guilds a bot still serves. A row whose key the team already holds stays where it is (a warning
|
|
37
|
+
* outbox, conversations, places). Rows of other guilds stay, such as the `discord_*` grants and audit of the
|
|
38
|
+
* guilds a bot still serves. A row whose key, or for places whose id, the team already holds stays where it is (a warning
|
|
28
39
|
* names it), so a second boot changes nothing; of two former ids holding one key, the one listed
|
|
29
40
|
* first moves.
|
|
30
41
|
*
|
|
@@ -39,36 +50,55 @@ export function moveTeam(options: TeamMoveOptions): Migration {
|
|
|
39
50
|
up: (sql) =>
|
|
40
51
|
sql.begin(async (tx) => {
|
|
41
52
|
if (from.length === 0 && !options.clearChannels) return;
|
|
42
|
-
const tables: { table: string; key: string[] | null }[] =
|
|
43
|
-
|
|
53
|
+
const tables: { table: string; scope: string; key: string[] | null }[] =
|
|
54
|
+
await tx`
|
|
55
|
+
SELECT c.table_name AS table, c.column_name AS scope,
|
|
44
56
|
(SELECT array_agg(a.attname::text ORDER BY a.attnum)
|
|
45
57
|
FROM pg_constraint p
|
|
46
58
|
JOIN pg_attribute a
|
|
47
59
|
ON a.attrelid = p.conrelid AND a.attnum = ANY (p.conkey)
|
|
48
60
|
WHERE p.conrelid = format('%I', c.table_name)::regclass
|
|
49
|
-
AND p.contype = 'p' AND a.attname <>
|
|
61
|
+
AND p.contype = 'p' AND a.attname <> c.column_name) AS key
|
|
50
62
|
FROM information_schema.columns c
|
|
51
63
|
JOIN information_schema.tables t
|
|
52
64
|
ON t.table_schema = c.table_schema AND t.table_name = c.table_name
|
|
53
|
-
WHERE c.table_schema = current_schema()
|
|
65
|
+
WHERE c.table_schema = current_schema()
|
|
66
|
+
AND c.column_name IN ('guild_id', 'team_id')
|
|
54
67
|
AND t.table_type = 'BASE TABLE' AND c.table_name NOT LIKE 'discord\\_%'
|
|
55
68
|
ORDER BY c.table_name`;
|
|
56
|
-
for (const { table, key } of tables) {
|
|
69
|
+
for (const { table, scope, key } of tables) {
|
|
57
70
|
const channels = CHANNEL_TABLES.has(table);
|
|
58
71
|
if (options.clearChannels && channels)
|
|
59
72
|
await tx.unsafe(
|
|
60
|
-
`UPDATE "${table}" SET channel_id = NULL WHERE
|
|
73
|
+
`UPDATE "${table}" SET channel_id = NULL WHERE ${scope} = $1 AND channel_id IS NOT NULL`,
|
|
61
74
|
[options.to],
|
|
62
75
|
);
|
|
76
|
+
if (table === PLACES_TABLE)
|
|
77
|
+
for (const { surface, keep } of options.places ?? []) {
|
|
78
|
+
if (options.clearChannels)
|
|
79
|
+
await tx.unsafe(
|
|
80
|
+
`DELETE FROM "${table}" WHERE ${scope} = $1 AND surface = $2`,
|
|
81
|
+
[options.to, surface],
|
|
82
|
+
);
|
|
83
|
+
// The places of a former id whose space is not the team's now name nothing it can reach.
|
|
84
|
+
await tx.unsafe(
|
|
85
|
+
`DELETE FROM "${table}" WHERE ${scope} = ANY ($1::text[]) AND surface = $2 AND ${scope} IS DISTINCT FROM $3::text`,
|
|
86
|
+
[from, surface, keep ?? null],
|
|
87
|
+
);
|
|
88
|
+
}
|
|
63
89
|
const match = (key ?? [])
|
|
64
90
|
.map((column) => `l."${column}" = t."${column}"`)
|
|
65
91
|
.join(" AND ");
|
|
66
92
|
// One former id at a time, in the listed order: the first to hold a key wins, and the
|
|
67
93
|
// later ones find it taken.
|
|
68
94
|
for (const id of from) {
|
|
95
|
+
const same =
|
|
96
|
+
table === PLACES_TABLE
|
|
97
|
+
? ` AND NOT EXISTS (SELECT 1 FROM "${table}" l WHERE l.${scope} = $1 AND l.surface = t.surface AND l.external_id = t.external_id)`
|
|
98
|
+
: "";
|
|
69
99
|
const taken = match
|
|
70
|
-
? ` AND NOT EXISTS (SELECT 1 FROM "${table}" l WHERE l
|
|
71
|
-
:
|
|
100
|
+
? ` AND NOT EXISTS (SELECT 1 FROM "${table}" l WHERE l.${scope} = $1 AND ${match})${same}`
|
|
101
|
+
: same;
|
|
72
102
|
const clear =
|
|
73
103
|
channels &&
|
|
74
104
|
(options.clearChannels ||
|
|
@@ -77,23 +107,28 @@ export function moveTeam(options: TeamMoveOptions): Migration {
|
|
|
77
107
|
? ", channel_id = NULL"
|
|
78
108
|
: "";
|
|
79
109
|
await tx.unsafe(
|
|
80
|
-
`UPDATE "${table}" t SET
|
|
110
|
+
`UPDATE "${table}" t SET ${scope} = $1${clear} WHERE t.${scope} = $2${taken}`,
|
|
81
111
|
[options.to, id],
|
|
82
112
|
);
|
|
83
113
|
}
|
|
84
114
|
if (!match || from.length === 0) continue;
|
|
115
|
+
// A place also stays when the team holds its id on the surface, which the key does not show.
|
|
116
|
+
const sameId =
|
|
117
|
+
table === PLACES_TABLE
|
|
118
|
+
? ` OR EXISTS (SELECT 1 FROM "${table}" l WHERE l.${scope} = $1 AND l.surface = t.surface AND l.external_id = t.external_id)`
|
|
119
|
+
: "";
|
|
85
120
|
const kept: Record<string, unknown>[] = await tx.unsafe(
|
|
86
|
-
`SELECT t
|
|
87
|
-
WHERE t
|
|
88
|
-
AND EXISTS (SELECT 1 FROM "${table}" l WHERE l
|
|
121
|
+
`SELECT t.${scope} AS moved_from, ${key?.map((column) => `t."${column}"`).join(", ")} FROM "${table}" t
|
|
122
|
+
WHERE t.${scope} = ANY ($2::text[])
|
|
123
|
+
AND (EXISTS (SELECT 1 FROM "${table}" l WHERE l.${scope} = $1 AND ${match})${sameId})`,
|
|
89
124
|
[options.to, from],
|
|
90
125
|
);
|
|
91
126
|
if (kept.length > 0)
|
|
92
127
|
console.warn(
|
|
93
|
-
`team-move: ${kept.length} row(s) of "${table}" stay under their former id, because team "${options.to}" already holds the same key: ${kept
|
|
128
|
+
`team-move: ${kept.length} row(s) of "${table}" stay under their former id, because team "${options.to}" already holds the same ${sameId ? "key or place id" : "key"}: ${kept
|
|
94
129
|
.map(
|
|
95
|
-
({
|
|
96
|
-
`${
|
|
130
|
+
({ moved_from, ...rest }) =>
|
|
131
|
+
`${moved_from}/${Object.values(rest).join("/")}`,
|
|
97
132
|
)
|
|
98
133
|
.join(", ")}`,
|
|
99
134
|
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DISCORD, type DiscordServices } from "../builtin/discord.ts";
|
|
2
|
+
import { CommandCollection } from "../discord/command-collection.ts";
|
|
3
|
+
import type { ComposedCommands } from "../discord/compose-commands.ts";
|
|
4
|
+
import type {
|
|
5
|
+
CommandGuard,
|
|
6
|
+
CommandRegistrar,
|
|
7
|
+
InteractionContribution,
|
|
8
|
+
} from "../discord/interaction-module.ts";
|
|
9
|
+
import { commandGuard, ownerRootCommand } from "../discord/owner-command.ts";
|
|
10
|
+
import type { DiscordPoster } from "../discord/poster/poster.ts";
|
|
11
|
+
import { silentLogger } from "../kernel/log.ts";
|
|
12
|
+
import { fakeDiscordPoster } from "./fake-poster.ts";
|
|
13
|
+
import { type ServicePair, servicePair } from "./service-pair.ts";
|
|
14
|
+
|
|
15
|
+
/** A stand-in for the Discord plugin's `DISCORD` service, made by `fakeDiscord()`. */
|
|
16
|
+
export interface FakeDiscord {
|
|
17
|
+
/** Give this to `testPlugin`'s `services` option: `{ services: [discord.service] }`. */
|
|
18
|
+
readonly service: ServicePair;
|
|
19
|
+
/** What `DISCORD.commands` is to the plugin: the real registrar, which refuses what the Discord plugin refuses. */
|
|
20
|
+
readonly commands: CommandRegistrar;
|
|
21
|
+
/** What `DISCORD.poster` is: the one the test gave, else a `fakeDiscordPoster()`. */
|
|
22
|
+
readonly poster: DiscordPoster;
|
|
23
|
+
/** What `DISCORD.guard` is: the owner, `owner` unless the test gave another id, serving the root command. */
|
|
24
|
+
readonly guard: CommandGuard;
|
|
25
|
+
/** Every contribution the plugin added, in the order it added them. */
|
|
26
|
+
added(): readonly InteractionContribution[];
|
|
27
|
+
/** The tree the Discord plugin would register, composed under the root command the fake was made with. */
|
|
28
|
+
compose(): ComposedCommands;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A `DISCORD` service for a plugin that adds slash commands, without a Discord connection: the
|
|
33
|
+
* plugin's `commands.add` calls are recorded, and `compose()` shows the tree Discord would get.
|
|
34
|
+
* `rootCommand` is the root command's name, `roundtable` by default. `channelContext` is what
|
|
35
|
+
* `DISCORD.channelContext` answers, by default no context, as on a host with it off. Only
|
|
36
|
+
* `commands`, `guard`, `poster`, and `channelContext` are given; reading another member throws.
|
|
37
|
+
*/
|
|
38
|
+
export function fakeDiscord(
|
|
39
|
+
options: {
|
|
40
|
+
ownerId?: string;
|
|
41
|
+
rootCommand?: string;
|
|
42
|
+
channelContext?: DiscordServices["channelContext"];
|
|
43
|
+
poster?: DiscordPoster;
|
|
44
|
+
} = {},
|
|
45
|
+
): FakeDiscord {
|
|
46
|
+
const collection = new CommandCollection();
|
|
47
|
+
const { rootCommand = "roundtable" } = options;
|
|
48
|
+
const guard = commandGuard({
|
|
49
|
+
ownerId: options.ownerId ?? "owner",
|
|
50
|
+
root: rootCommand,
|
|
51
|
+
logger: silentLogger(),
|
|
52
|
+
});
|
|
53
|
+
const poster = options.poster ?? fakeDiscordPoster();
|
|
54
|
+
return {
|
|
55
|
+
service: servicePair(DISCORD, {
|
|
56
|
+
commands: collection.registrar,
|
|
57
|
+
guard,
|
|
58
|
+
poster,
|
|
59
|
+
channelContext: options.channelContext ?? (async () => undefined),
|
|
60
|
+
}),
|
|
61
|
+
poster,
|
|
62
|
+
commands: collection.registrar,
|
|
63
|
+
guard,
|
|
64
|
+
added: () => collection.added(),
|
|
65
|
+
compose: () => collection.compose(ownerRootCommand(rootCommand)),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ConversationPort } from "../contract/channels.ts";
|
|
2
|
+
import type { HeldActionStore } from "../contract/runtime.ts";
|
|
3
|
+
import type { ServiceKey } from "../contract/services.ts";
|
|
4
|
+
import type { PendingConfirmation } from "../domain/conversation.ts";
|
|
5
|
+
import type { ChannelKey } from "../domain/sessions.ts";
|
|
6
|
+
import { NotLinkedError, PluginError } from "../kernel/errors.ts";
|
|
7
|
+
import type { ChannelRouter } from "../routing/channel-router.ts";
|
|
8
|
+
|
|
9
|
+
/** The same pre-link failures and wording the host exposes during setup. */
|
|
10
|
+
export const NOT_LINKED = {
|
|
11
|
+
conversations:
|
|
12
|
+
"conversations are linked once every plugin is set up. Use them from a service's start or from a handler, not during setup.",
|
|
13
|
+
sessions:
|
|
14
|
+
"session parts are linked once every plugin is set up. Call sessions() from a service's start or from a handler, not during setup.",
|
|
15
|
+
surfaces:
|
|
16
|
+
"chat surfaces are linked once every plugin is set up. Use surfaces from a service's start or from a handler, not during setup.",
|
|
17
|
+
turns:
|
|
18
|
+
"conversation turns are linked once every plugin is set up. Use turns from a service's start or from a handler, not during setup.",
|
|
19
|
+
dashboard:
|
|
20
|
+
"dashboard lines are linked once every plugin is set up. Call dashboard() from a service's start or from a handler, not during setup.",
|
|
21
|
+
chatCommands:
|
|
22
|
+
"chat commands are linked once every plugin is set up. Call chatCommands() from a service's start or from a handler, not during setup.",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function unlinked(part: keyof typeof NOT_LINKED): never {
|
|
26
|
+
throw new NotLinkedError(NOT_LINKED[part]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Members a probe may ask of any object: a test's partial service is not refused for them. */
|
|
30
|
+
const PROBED = new Set(["then", "toJSON", "asymmetricMatch"]);
|
|
31
|
+
|
|
32
|
+
/** A service the test gave only some members of: reading another names the option that adds it. */
|
|
33
|
+
export function partialService<T extends object>(
|
|
34
|
+
key: ServiceKey<unknown>,
|
|
35
|
+
given: T,
|
|
36
|
+
): T {
|
|
37
|
+
return new Proxy(given, {
|
|
38
|
+
get(target, member, receiver) {
|
|
39
|
+
if (member in target || typeof member === "symbol" || PROBED.has(member))
|
|
40
|
+
return Reflect.get(target, member, receiver);
|
|
41
|
+
throw new PluginError(
|
|
42
|
+
`testPlugin gave service ${key.id} no "${member}". Give it in the services option: testPlugin(plugin, { services: [servicePair(KEY, { ${member}: ... })] }).`,
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Held actions kept in memory, for the runtime a plugin's provider builds under test. */
|
|
49
|
+
export function memoryHeldActions(): HeldActionStore {
|
|
50
|
+
const held = new Map<ChannelKey, PendingConfirmation>();
|
|
51
|
+
return {
|
|
52
|
+
load: async (conversation) => held.get(conversation),
|
|
53
|
+
save: async (conversation, actions) => {
|
|
54
|
+
if (actions) held.set(conversation, actions);
|
|
55
|
+
else held.delete(conversation);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A conversation port that reads the router once the host links it, and throws before; `overrides` replace its methods. */
|
|
61
|
+
export function routedConversations(
|
|
62
|
+
router: () => ChannelRouter | undefined,
|
|
63
|
+
overrides: Partial<ConversationPort> | undefined,
|
|
64
|
+
): ConversationPort {
|
|
65
|
+
return {
|
|
66
|
+
handle: async (message) =>
|
|
67
|
+
(router() ?? unlinked("conversations")).handle(message),
|
|
68
|
+
messageDeleted: async (channel, id, space) =>
|
|
69
|
+
(router() ?? unlinked("conversations")).messageDeleted(
|
|
70
|
+
channel,
|
|
71
|
+
id,
|
|
72
|
+
space,
|
|
73
|
+
),
|
|
74
|
+
messageEdited: async (message) =>
|
|
75
|
+
(router() ?? unlinked("conversations")).messageEdited(message),
|
|
76
|
+
background: async (turn) =>
|
|
77
|
+
(router() ?? unlinked("conversations")).background(turn),
|
|
78
|
+
runsAs: async (turn) =>
|
|
79
|
+
(router() ?? unlinked("conversations")).runsAs(turn),
|
|
80
|
+
target: (name) => (router() ?? unlinked("conversations")).target(name),
|
|
81
|
+
startFresh: async (channel) =>
|
|
82
|
+
(router() ?? unlinked("conversations")).startFresh(channel),
|
|
83
|
+
deleteConversation: async (channel) =>
|
|
84
|
+
(router() ?? unlinked("conversations")).deleteConversation(channel),
|
|
85
|
+
stop: (channel) => (router() ?? unlinked("conversations")).stop(channel),
|
|
86
|
+
postsInPlace: (channel) =>
|
|
87
|
+
(router() ?? unlinked("conversations")).postsInPlace(channel),
|
|
88
|
+
owns: (channel) => (router() ?? unlinked("conversations")).owns(channel),
|
|
89
|
+
takesBackground: (channel) =>
|
|
90
|
+
(router() ?? unlinked("conversations")).takesBackground(channel),
|
|
91
|
+
takesSystemReports: (channel) =>
|
|
92
|
+
(router() ?? unlinked("conversations")).takesSystemReports(channel),
|
|
93
|
+
...overrides,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ServiceKey } from "../contract/services.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A service the plugin under test reads, with the members the test gives it, made by `servicePair(KEY,
|
|
5
|
+
* { ... })`. Reading a member the test did not give throws a PluginError that names it.
|
|
6
|
+
*/
|
|
7
|
+
export interface ServicePair {
|
|
8
|
+
readonly key: ServiceKey<unknown>;
|
|
9
|
+
readonly given: object;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Pairs a service key with the members the test gives it, for the `services` option of `testPlugin`. */
|
|
13
|
+
export function servicePair<T extends object>(
|
|
14
|
+
key: ServiceKey<T>,
|
|
15
|
+
given: Partial<T>,
|
|
16
|
+
): ServicePair {
|
|
17
|
+
return { key, given };
|
|
18
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import type { PeerBotsConfig } from "../config/peer-bots.ts";
|
|
3
|
+
import type { ConversationPort } from "../contract/channels.ts";
|
|
4
|
+
import type { Providers } from "../contract/providers.ts";
|
|
5
|
+
import type { AgentRuntime } from "../contract/runtime.ts";
|
|
6
|
+
import type { ChatSurface, SurfacePort } from "../contract/surface.ts";
|
|
7
|
+
import type { ClientPart, ClientPort } from "../domain/client.ts";
|
|
8
|
+
import type { ReplyFile } from "../domain/conversation.ts";
|
|
9
|
+
import type { ChannelKey, SessionContext } from "../domain/sessions.ts";
|
|
10
|
+
import type { ListenerConfig } from "../http/listeners.ts";
|
|
11
|
+
import type { OwnerIdentity } from "../identity/owner-identity.ts";
|
|
12
|
+
import type { Speaker } from "../identity/speakers.ts";
|
|
13
|
+
import type { HoldCheck } from "../plugin-api/holds.ts";
|
|
14
|
+
import type {
|
|
15
|
+
Contribution,
|
|
16
|
+
HostEnv,
|
|
17
|
+
TurnEndEvent,
|
|
18
|
+
TurnEvent,
|
|
19
|
+
} from "../plugin-api/plugin.ts";
|
|
20
|
+
import type { ConversationTurns } from "../routing/conversation-turns.ts";
|
|
21
|
+
import type { ToolTierTable } from "../runtime/tool-tiers.ts";
|
|
22
|
+
import type { ServicePair } from "./service-pair.ts";
|
|
23
|
+
|
|
24
|
+
export interface TestPluginOptions {
|
|
25
|
+
/** The host environment the plugin sees; default en and UTC. */
|
|
26
|
+
env?: Partial<HostEnv>;
|
|
27
|
+
/**
|
|
28
|
+
* The owner the runtime's dependencies and the agent server's claim know; default `owner`,
|
|
29
|
+
* named Owner, who is addressed as they.
|
|
30
|
+
*/
|
|
31
|
+
owner?: { id: string; name: string; pronouns?: OwnerIdentity["pronouns"] };
|
|
32
|
+
database?: SQL;
|
|
33
|
+
providers?: Partial<Providers>;
|
|
34
|
+
/**
|
|
35
|
+
* Chat surfaces besides the plugin's own, such as a fake one: they are in `context.surfaces`,
|
|
36
|
+
* started with the plugin's services (their messages reach `conversations`), and stopped last.
|
|
37
|
+
*/
|
|
38
|
+
surfaces?: readonly ChatSurface[];
|
|
39
|
+
/**
|
|
40
|
+
* What the plugin reads from `context.services`, one `servicePair(KEY, { ... })` per service.
|
|
41
|
+
* `servicePair(RUNTIME, runtime)` is the runtime that `context.turns` runs turns on, given
|
|
42
|
+
* whole rather than member by member; `servicePair(AGENTS, { runtime })` still works when no
|
|
43
|
+
* `RUNTIME` is given. Without either, a plugin that fills the `runtime` slot gets the runtime its
|
|
44
|
+
* provider builds, under both keys. A service
|
|
45
|
+
* not given here reads as absent to `find`, and `get` names this option, except for what the
|
|
46
|
+
* host supplies anyway: `BACKGROUND_TURNS`, the real background turns over the test's router,
|
|
47
|
+
* and, once `AGENTS` is given, its `approvals` (the real confirmation judge over
|
|
48
|
+
* `providers.judge`, when the test gives a judge). Giving `AGENTS` a `team` adds the agent
|
|
49
|
+
* server's own claim to the router, answering as the host's would for the `owner`. The router
|
|
50
|
+
* resolves who wrote each message through a given `IDENTITY`; without one only the `owner` is
|
|
51
|
+
* anyone, at the owner tier, their principal their id.
|
|
52
|
+
*/
|
|
53
|
+
services?: readonly ServicePair[];
|
|
54
|
+
/**
|
|
55
|
+
* The plugin's conversations: by default a router over the plugin's own `channels` claims, so a
|
|
56
|
+
* message a surface delivers reaches them. Methods given here replace the router's.
|
|
57
|
+
*/
|
|
58
|
+
conversations?: Partial<ConversationPort>;
|
|
59
|
+
/** Replaces `context.turns`, which by default runs turns over the runtime and the surfaces. */
|
|
60
|
+
turns?: ConversationTurns;
|
|
61
|
+
/** The credentials `context.apiKey` returns, by provider name; a provider not listed reads as having none, as on a host not logged in to it. */
|
|
62
|
+
apiKeys?: Readonly<Record<string, string>>;
|
|
63
|
+
/** How long the router holds a bare forward for the message that follows it; the host option `conversations.forwardJoinMs`. */
|
|
64
|
+
forwardJoinMs?: number;
|
|
65
|
+
/** The peer bots the router answers, as the host option `peerBots` (`discord.peerBots`); default none. */
|
|
66
|
+
peerBots?: PeerBotsConfig;
|
|
67
|
+
/** The addresses `context.listener(id)` reports; a plugin that reads one gets `undefined` for any not listed. */
|
|
68
|
+
listeners?: readonly ListenerConfig[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface RecordedEvent {
|
|
72
|
+
name: "turnStarted" | "turnEnded" | "changed";
|
|
73
|
+
turn?: TurnEvent | TurnEndEvent;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TestPluginResult {
|
|
77
|
+
contribution: Contribution;
|
|
78
|
+
/** The hold rules the plugin contributed, chained as the host links them: the description of a call that must be approved first, or undefined. `holds.inTurn(tool, input, context, turn)` asks them as a turn does, so a hold that looks things up (and may return a promise) is called with the turn; the plain call has no turn, and counts a hold that declares `turn` as held under `run <tool>`. */
|
|
79
|
+
holds: HoldCheck;
|
|
80
|
+
/** What the plugin sees as `context.conversations`, for a test to drive its claims. */
|
|
81
|
+
conversations: ConversationPort;
|
|
82
|
+
/** What the plugin sees as `context.turns`. */
|
|
83
|
+
turns: ConversationTurns;
|
|
84
|
+
/** What the plugin sees as `context.surfaces`: its own surfaces and the injected ones. */
|
|
85
|
+
surfaces: SurfacePort;
|
|
86
|
+
/** The runtime the plugin's `runtime` provider built, given stand-in dependencies; undefined when it fills no such slot. */
|
|
87
|
+
runtime: AgentRuntime | undefined;
|
|
88
|
+
tools: readonly string[];
|
|
89
|
+
tiers: ToolTierTable;
|
|
90
|
+
events: RecordedEvent[];
|
|
91
|
+
/** Files accepted by successful runTool calls, copied and recorded with their channel. */
|
|
92
|
+
files: { channel: ChannelKey; file: ReplyFile }[];
|
|
93
|
+
/** Images returned by successful runTool calls, with their channel. */
|
|
94
|
+
images: { channel: ChannelKey; image: ClientPart }[];
|
|
95
|
+
runTool(
|
|
96
|
+
name: string,
|
|
97
|
+
args: Record<string, unknown>,
|
|
98
|
+
/** `workspace` gives the session a workspace and scratch dir, as an agent's session has. */
|
|
99
|
+
options?: {
|
|
100
|
+
speaker?: Speaker;
|
|
101
|
+
/** Where the turn's request came from, as `ToolTurn.origin` shows it to the tool. */
|
|
102
|
+
origin?: string;
|
|
103
|
+
/** What the side that started the turn can do for the tool, as `ToolTurn.client` shows it. */
|
|
104
|
+
client?: ClientPort;
|
|
105
|
+
channel?: ChannelKey;
|
|
106
|
+
workspace?: SessionContext["workspace"];
|
|
107
|
+
},
|
|
108
|
+
): Promise<string>;
|
|
109
|
+
stop(): Promise<void>;
|
|
110
|
+
}
|