pi-roundtable 0.53.6 → 0.54.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 +12 -0
- package/README.md +6 -2
- package/README.zh-TW.md +6 -2
- package/docs/plugins.md +199 -7
- package/package.json +3 -1
- package/runner/Dockerfile +46 -0
- package/runner/Dockerfile.dockerignore +5 -0
- package/src/cli/checks/images.ts +3 -2
- package/src/cli/checks/preset.ts +20 -0
- package/src/cli/checks/runner.ts +45 -0
- package/src/cli/doctor.ts +7 -1
- package/src/core/agents/agent-claim.ts +7 -4
- package/src/core/agents/agent-prompt.ts +11 -2
- package/src/core/agents/helper-workspace.ts +72 -0
- package/src/core/agents/team-options.ts +2 -0
- package/src/core/agents/team-prompt.ts +12 -1
- package/src/core/builtin/agent-server.ts +8 -0
- package/src/core/builtin/polls.ts +67 -0
- package/src/core/builtin/runner.ts +139 -0
- package/src/core/config/config-schema.ts +4 -0
- package/src/core/config/config.ts +49 -185
- package/src/core/config/preset.ts +51 -0
- package/src/core/config/resolve-config.ts +175 -0
- package/src/core/config/runner-config.ts +80 -0
- package/src/core/contract/polls.ts +71 -0
- package/src/core/contract/runtime.ts +12 -0
- package/src/core/contract/surface.ts +13 -0
- package/src/core/discord/discord-polls.ts +156 -0
- package/src/core/discord/discord-replies.ts +55 -0
- package/src/core/discord/discord-surface.ts +13 -43
- package/src/core/domain/errors.ts +5 -0
- package/src/core/domain/sessions.ts +8 -1
- package/src/core/host/define-roundtable.ts +8 -0
- package/src/core/host/host-registration.ts +7 -0
- package/src/core/host/host.ts +8 -0
- package/src/core/i18n/schedules.ts +2 -0
- package/src/core/modules/polls/poll-result-turns.ts +124 -0
- package/src/core/modules/polls/poll-rules.ts +108 -0
- package/src/core/modules/polls/poll-service.ts +477 -0
- package/src/core/modules/polls/poll-store.ts +336 -0
- package/src/core/modules/polls/poll-tools.ts +118 -0
- package/src/core/modules/polls/poll-turn-text.ts +60 -0
- package/src/core/plugin-api/define.ts +9 -2
- package/src/core/plugin-api/holds.ts +2 -0
- package/src/core/plugin-api/plugin.ts +8 -0
- package/src/core/runner/protocol.ts +456 -0
- package/src/core/runner/runner-client.ts +450 -0
- package/src/core/runner/runner-drivers.ts +356 -0
- package/src/core/runner/runner-files.ts +102 -0
- package/src/core/runner/runner-holds.ts +76 -0
- package/src/core/runner/runner-port.ts +77 -0
- package/src/core/runner/runner-probe.ts +53 -0
- package/src/core/runner/runner-prompt.ts +36 -0
- package/src/core/runner/runner-session.ts +131 -0
- package/src/core/runner/runner-tiers.ts +20 -0
- package/src/core/runner/runner-tools.ts +325 -0
- package/src/core/runner/settings.ts +108 -0
- package/src/core/runtime/conversation-sessions.ts +73 -15
- package/src/core/runtime/extensions/approval-card.ts +29 -2
- package/src/core/runtime/extensions/confirmation-gate.ts +24 -63
- package/src/core/runtime/extensions/gate-card.ts +105 -0
- package/src/core/runtime/extensions/yolo.ts +17 -3
- package/src/core/runtime/pi-agent-runtime.ts +37 -68
- package/src/core/runtime/runtime-plugin.ts +9 -0
- package/src/core/runtime/runtime-types.ts +29 -1
- package/src/core/runtime/session-factory.ts +59 -62
- package/src/core/runtime/session-shell.ts +43 -0
- package/src/core/runtime/session-tool-names.ts +78 -0
- package/src/core/runtime/turn-selection.ts +97 -0
- package/src/core/shared/generate-image-tool.ts +4 -4
- package/src/core/shared/poll-target.ts +14 -0
- package/src/core/shared/workspace-files.ts +42 -4
- package/src/core/testing/fake-polls.ts +131 -0
- package/src/core/testing/fake-runner.ts +146 -0
- package/src/core/testing/surface-contract-approvals.ts +215 -0
- package/src/core/testing/surface-contract-polls.ts +142 -0
- package/src/core/testing/surface-contract.ts +32 -208
- package/src/core/tool-set.snapshot.json +8 -0
- package/src/index.ts +17 -0
- package/src/kit/index.ts +6 -0
- package/src/kit/polls.ts +8 -0
- package/src/runner-server/exec.ts +174 -0
- package/src/runner-server/file-helper.ts +208 -0
- package/src/runner-server/files.ts +93 -0
- package/src/runner-server/host.ts +65 -0
- package/src/runner-server/main.ts +89 -0
- package/src/runner-server/server.ts +318 -0
- package/src/runner-server/shared-dirs.ts +45 -0
- package/src/runner-server/state.ts +293 -0
- package/src/runner-server/transports.ts +187 -0
- package/src/testing.ts +7 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
probeRunner,
|
|
3
|
+
type RunnerReach,
|
|
4
|
+
} from "../../core/runner/runner-probe.ts";
|
|
5
|
+
import type { RunnerSettings } from "../../core/runner/settings.ts";
|
|
6
|
+
import type { Project } from "../project.ts";
|
|
7
|
+
import { fail, ok, type Result, skipped } from "../report.ts";
|
|
8
|
+
|
|
9
|
+
/** Looks for the configured runner without starting it; a test hands a stand-in. */
|
|
10
|
+
export type RunnerProbe = (
|
|
11
|
+
settings: RunnerSettings,
|
|
12
|
+
dataDir: string,
|
|
13
|
+
) => Promise<RunnerReach>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Where multi-user conversations' shell and file tools run: the runner's driver, its image or
|
|
17
|
+
* socket, and whether it answers; without `runner` they run as before.
|
|
18
|
+
*/
|
|
19
|
+
export async function checkRunner(
|
|
20
|
+
project: Project,
|
|
21
|
+
probe: RunnerProbe = probeRunner,
|
|
22
|
+
): Promise<Result> {
|
|
23
|
+
const assembled = await project.assembled();
|
|
24
|
+
if (!assembled.ok) return skipped("the configuration is not valid yet");
|
|
25
|
+
const { runner, dataDir } = assembled.value.config;
|
|
26
|
+
if (!runner)
|
|
27
|
+
return ok(
|
|
28
|
+
"none; shell and file tools run on the host as agentServer says. Set runner to run every conversation but the owner's own in a container",
|
|
29
|
+
);
|
|
30
|
+
const where =
|
|
31
|
+
runner.driver === "docker"
|
|
32
|
+
? `docker, image ${runner.image}`
|
|
33
|
+
: `socket ${runner.socket}`;
|
|
34
|
+
const reach = await probe(runner, dataDir);
|
|
35
|
+
if (reach.reachable)
|
|
36
|
+
return ok(
|
|
37
|
+
`${where}: reachable (${reach.detail}); minTier ${runner.minTier}`,
|
|
38
|
+
);
|
|
39
|
+
return fail(
|
|
40
|
+
`${where}: not reachable (${reach.reason})`,
|
|
41
|
+
runner.driver === "docker"
|
|
42
|
+
? `Install Docker and build the image: docker build -t ${runner.image} -f node_modules/pi-roundtable/runner/Dockerfile node_modules/pi-roundtable`
|
|
43
|
+
: "Start the runner sidecar, which listens on that socket and writes its token beside it, in a directory only the bot's account may enter.",
|
|
44
|
+
);
|
|
45
|
+
}
|
package/src/cli/doctor.ts
CHANGED
|
@@ -14,7 +14,9 @@ import { checkEnvironment } from "./checks/environment.ts";
|
|
|
14
14
|
import { checkAccess, checkPrincipals } from "./checks/identity.ts";
|
|
15
15
|
import { checkImageProvider } from "./checks/images.ts";
|
|
16
16
|
import { checkModelLogin } from "./checks/model.ts";
|
|
17
|
+
import { checkPreset } from "./checks/preset.ts";
|
|
17
18
|
import { checkPublicUrl } from "./checks/public-url.ts";
|
|
19
|
+
import { checkRunner, type RunnerProbe } from "./checks/runner.ts";
|
|
18
20
|
import type { Http } from "./http.ts";
|
|
19
21
|
import { type Ports, Project } from "./project.ts";
|
|
20
22
|
import {
|
|
@@ -35,6 +37,8 @@ export interface DoctorInputs {
|
|
|
35
37
|
http: Http;
|
|
36
38
|
/** Also ask the public address to answer, which is only true while the bot runs. */
|
|
37
39
|
reachable: boolean;
|
|
40
|
+
/** Looks for the configured runner; default the docker CLI or the socket. */
|
|
41
|
+
runner?: RunnerProbe;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export interface DoctorReport {
|
|
@@ -47,7 +51,7 @@ export function buildChecks(
|
|
|
47
51
|
inputs: DoctorInputs,
|
|
48
52
|
project = new Project(inputs.cwd, inputs.ports),
|
|
49
53
|
): Check[] {
|
|
50
|
-
const { cwd, env, bun, ports, database, http, reachable } = inputs;
|
|
54
|
+
const { cwd, env, bun, ports, database, http, reachable, runner } = inputs;
|
|
51
55
|
const discord = new Discord(project, http);
|
|
52
56
|
// A project without Discord asks Discord nothing.
|
|
53
57
|
const ifDiscord = (run: () => Promise<Result>) => async (): Promise<Result> =>
|
|
@@ -68,6 +72,7 @@ export function buildChecks(
|
|
|
68
72
|
},
|
|
69
73
|
{ name: "plugins", offline: true, run: () => checkPlugins(project) },
|
|
70
74
|
{ name: "access", offline: true, run: () => checkAccess(project) },
|
|
75
|
+
{ name: "preset", offline: true, run: () => checkPreset(project) },
|
|
71
76
|
{
|
|
72
77
|
name: "agent tools",
|
|
73
78
|
offline: true,
|
|
@@ -79,6 +84,7 @@ export function buildChecks(
|
|
|
79
84
|
run: () => checkImageProvider(project),
|
|
80
85
|
},
|
|
81
86
|
{ name: "characters", offline: true, run: () => checkCharacters() },
|
|
87
|
+
{ name: "runner", offline: false, run: () => checkRunner(project, runner) },
|
|
82
88
|
{
|
|
83
89
|
name: "PostgreSQL",
|
|
84
90
|
offline: false,
|
|
@@ -22,6 +22,7 @@ import { answersAuthor } from "../routing/peer-bots.ts";
|
|
|
22
22
|
import { outcome } from "../routing/settle-turn.ts";
|
|
23
23
|
import { systemTurn } from "../routing/system-turns.ts";
|
|
24
24
|
import { PERSONAL_TARGET } from "../shared/personal-target.ts";
|
|
25
|
+
import { POLL_TARGET } from "../shared/poll-target.ts";
|
|
25
26
|
import type { AgentServerTeam } from "./agent-team.ts";
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -133,10 +134,12 @@ export function agentClaim(options: AgentClaimOptions): ChannelClaim {
|
|
|
133
134
|
const backgroundRefusal = (
|
|
134
135
|
turn: BackgroundTurn & { speaker: Speaker },
|
|
135
136
|
): string | undefined => {
|
|
136
|
-
// Fail closed: a turn for any target but the owner's never reaches the owner's tools.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
// Fail closed: a turn for any target but the owner's, or a poll's results, never reaches the owner's tools.
|
|
138
|
+
const poll = turn.target === POLL_TARGET.name;
|
|
139
|
+
if (turn.target !== PERSONAL_TARGET.name && !poll)
|
|
140
|
+
return `the agent server answers only "${PERSONAL_TARGET.name}" and "${POLL_TARGET.name}" background turns`;
|
|
141
|
+
if (team.owns(turn.channel) === "group")
|
|
142
|
+
return poll ? "groups take no poll results" : "groups have no schedules";
|
|
140
143
|
if (options.speakers === "owners" && turn.speaker.tier !== "owner")
|
|
141
144
|
return 'the agent server answers owners only (speakers: "owners")';
|
|
142
145
|
return undefined;
|
|
@@ -31,6 +31,10 @@ export function agentSystemPrompt(input: {
|
|
|
31
31
|
images?: boolean;
|
|
32
32
|
/** "chat-only": the agent has no shell, file tools or workspace, and the prompt says so. Default "full". */
|
|
33
33
|
agentTools?: AgentTools;
|
|
34
|
+
/** Whether the full tools run in the runner's container rather than on the host. Default false. */
|
|
35
|
+
runner?: boolean;
|
|
36
|
+
/** In the runner, the display name of the agent whose workspace a temp knight shares. */
|
|
37
|
+
runnerWith?: string;
|
|
34
38
|
/** Where this conversation is, and the other surfaces the agent has places on. */
|
|
35
39
|
surface?: { label: string; key: string; others: readonly string[] };
|
|
36
40
|
/** Whether the agent has the temp knight tools. */
|
|
@@ -44,14 +48,19 @@ export function agentSystemPrompt(input: {
|
|
|
44
48
|
const o = ownerWords(owner);
|
|
45
49
|
const w = ownerWords(who);
|
|
46
50
|
const guest = input.speaker && input.speaker.tier !== "owner";
|
|
51
|
+
const drawing = input.images
|
|
52
|
+
? " To make a new picture, describe it to generate_image, which saves it and attaches it to your reply."
|
|
53
|
+
: "";
|
|
47
54
|
const parts = [
|
|
48
55
|
(guest && input.guestShared) || shared,
|
|
49
56
|
`You are "${agent.displayName}" (agent name \`${agent.name}\`), one of ${o.name}'s agents in ${o.his} agent server.${placeText(input.surface)} Each agent owns one channel and one conversation; you all share ${o.his} tools and ${o.his} memory.`,
|
|
50
57
|
roleText(agent, coordinator, who),
|
|
51
58
|
`The team: agent_list shows every agent and group; agent_get and agent_update read and improve any agent's prompt, display name, model, and thinking level, yours included; agent_create adds an agent with its own channel; agent_avatar changes an agent's look (class, colors, parts); schedule_list with agent reads another agent's schedules. A message marked as coming from another agent is that agent speaking, not ${w.name}; only ${w.name} approves held actions.`,
|
|
52
59
|
input.agentTools === "chat-only"
|
|
53
|
-
? `You have no shell or file tools and no workspace on ${o.his} machine: you work through the conversation and the tools listed to you.${
|
|
54
|
-
:
|
|
60
|
+
? `You have no shell or file tools and no workspace on ${o.his} machine: you work through the conversation and the tools listed to you.${drawing}`
|
|
61
|
+
: input.runner
|
|
62
|
+
? `Your shell and file tools run in an isolated container, not on ${o.his} machine, ${input.runnerWith ? `in the workspace of "${input.runnerWith}" there, which is your working directory, so you see and change the files it works on` : "in a workspace of your own there, kept across your channel and the rooms you are in, which is your working directory"}. Commands that are destructive, and writes outside the workspace, are held for confirmation: tell ${w.him} exactly what will run and ask ${w.him} to confirm. To show a file you have, attach it to your reply with attach_file or give its path to discord_send_message; never read an image or base64 a file to send it.${drawing}`
|
|
63
|
+
: `Your shell and file tools run on ${o.his} VPS as the user ${shellUser}, in the shared workspace ${workDir}.${input.scratchDir ? ` Write temporary files under the scratch dir ${input.scratchDir} ($TMPDIR), not elsewhere in /tmp; make them with \`mktemp -p "$TMPDIR"\`, since a bare \`mktemp\` ignores $TMPDIR on some systems.` : ""} Commands that are destructive or change the system, and writes outside the workspace${input.scratchDir ? " and the scratch dir" : ""}, are held for ${w.his} confirmation: tell ${w.him} exactly what will run and ask ${w.him} to confirm. To show a file you have, attach it to your reply with attach_file or give its path to discord_send_message; never read an image or base64 a file to send it.${drawing}`,
|
|
55
64
|
];
|
|
56
65
|
if (input.parent)
|
|
57
66
|
parts.push(
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { SurfacePort } from "../contract/surface.ts";
|
|
2
|
+
import type { AgentTurnScope } from "../domain/ports.ts";
|
|
3
|
+
import type { ChannelKey } from "../domain/sessions.ts";
|
|
4
|
+
import type { AgentDirectory } from "../plugin-api/services.ts";
|
|
5
|
+
import { isHelper } from "./agent-rules.ts";
|
|
6
|
+
import { roomOf } from "./team-keys.ts";
|
|
7
|
+
import type { TeamPlaces } from "./team-places.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The home whose runner workspace an agent's turns work in (`AgentSessions.runnerHome`). A temp
|
|
11
|
+
* knight shares its parent's workspace, as it shares the workspace on the host: in every one of
|
|
12
|
+
* its conversations it works in the home its parent's turn had in the conversation that made it
|
|
13
|
+
* (the parent's own home there, a group's room included), so it sees and changes the files that
|
|
14
|
+
* turn left. Once that origin is gone (the agent or group whose conversation it is, else the
|
|
15
|
+
* parent, is archived or deleted), or the parent is, the temp knight works in its own home, as
|
|
16
|
+
* every other agent does in its own.
|
|
17
|
+
*/
|
|
18
|
+
export function runnerHomeOf(
|
|
19
|
+
store: Pick<AgentDirectory, "agent">,
|
|
20
|
+
places: Pick<TeamPlaces, "ownerKind" | "groupOf" | "scopeOf" | "groupScope">,
|
|
21
|
+
scope: AgentTurnScope,
|
|
22
|
+
): ChannelKey {
|
|
23
|
+
const helper = store.agent(scope.name);
|
|
24
|
+
if (!helper || !isHelper(helper) || helper.origin === undefined)
|
|
25
|
+
return scope.home;
|
|
26
|
+
const parent = store.agent(helper.parent as string);
|
|
27
|
+
if (parent?.status !== "active") return scope.home;
|
|
28
|
+
const origin = helper.origin as ChannelKey;
|
|
29
|
+
// Gone when no active agent or group owns the place: archived (a stored place keeps its row),
|
|
30
|
+
// deleted, or the place itself removed.
|
|
31
|
+
if (places.ownerKind(origin) === undefined) return scope.home;
|
|
32
|
+
const group = places.groupOf(origin);
|
|
33
|
+
return group
|
|
34
|
+
? places.groupScope(parent, group, origin).home
|
|
35
|
+
: places.scopeOf(parent, origin).home;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Whether only the owners reach an agent's conversation (`AgentSessions.ownersOnly`), so its turns
|
|
40
|
+
* keep the host's shell on a host with a runner: the agent's own room on a surface that declares
|
|
41
|
+
* its rooms the owners' alone (`ChatSurface.agentRoomsOwnersOnly`, as the web app does). A room of
|
|
42
|
+
* any other surface, or of one `surfaces` does not know, is not. A temp knight's own room too,
|
|
43
|
+
* unless the conversation it was made in, while that is there, is not its parent's room: made in a
|
|
44
|
+
* group's place or a Discord channel, it works for the people there. Not a Discord channel or its
|
|
45
|
+
* threads, whose readers and writers are the server's to say, nor a group's room or seats, a room
|
|
46
|
+
* of several.
|
|
47
|
+
*/
|
|
48
|
+
export function ownersOnlyConversation(
|
|
49
|
+
store: Pick<AgentDirectory, "agent">,
|
|
50
|
+
places: Pick<
|
|
51
|
+
TeamPlaces,
|
|
52
|
+
"rooms" | "ownerKind" | "groupOf" | "scopeOf" | "groupScope"
|
|
53
|
+
>,
|
|
54
|
+
surfaces: Pick<SurfacePort, "of"> | undefined,
|
|
55
|
+
scope: AgentTurnScope,
|
|
56
|
+
): boolean {
|
|
57
|
+
const rooms = places
|
|
58
|
+
.rooms()
|
|
59
|
+
.filter(
|
|
60
|
+
(surface) => surfaces?.of(`${surface}:`)?.agentRoomsOwnersOnly === true,
|
|
61
|
+
);
|
|
62
|
+
const ownRoom = (key: ChannelKey, name: string) => {
|
|
63
|
+
const room = roomOf(key, rooms);
|
|
64
|
+
return room?.kind === "agent" && room.name === name;
|
|
65
|
+
};
|
|
66
|
+
if (!ownRoom(scope.session, scope.name)) return false;
|
|
67
|
+
const helper = store.agent(scope.name);
|
|
68
|
+
if (!helper || !isHelper(helper) || helper.origin === undefined) return true;
|
|
69
|
+
// Where it works while its origin is there (`runnerHomeOf`); its own room once that is gone.
|
|
70
|
+
if (runnerHomeOf(store, places, scope) === scope.home) return true;
|
|
71
|
+
return ownRoom(helper.origin as ChannelKey, helper.parent as string);
|
|
72
|
+
}
|
|
@@ -24,6 +24,8 @@ export interface AgentTeamOptions
|
|
|
24
24
|
promptSections?: () => readonly PromptSection[];
|
|
25
25
|
/** "chat-only": agent turns carry no shell or file tools, and the prompt says so; default "full". */
|
|
26
26
|
agentTools?: AgentTools;
|
|
27
|
+
/** Whether a full-tools host's agents run their shell and file tools in the runner, as the prompt then says. */
|
|
28
|
+
runner?: boolean;
|
|
27
29
|
/** The tools plugins defined for agents, read before each agent turn. */
|
|
28
30
|
pluginTools?: () => readonly string[];
|
|
29
31
|
/** Those of `pluginTools` a temp knight's turns leave out. */
|
|
@@ -2,6 +2,7 @@ import { AgentError } from "../domain/errors.ts";
|
|
|
2
2
|
import type { AgentTurnScope } from "../domain/ports.ts";
|
|
3
3
|
import { agentSystemPrompt, placeOf } from "./agent-prompt.ts";
|
|
4
4
|
import type { Agent } from "./agent-store.ts";
|
|
5
|
+
import { ownersOnlyConversation, runnerHomeOf } from "./helper-workspace.ts";
|
|
5
6
|
import { coordinatorOf } from "./team-keys.ts";
|
|
6
7
|
import type { AgentTeamOptions } from "./team-options.ts";
|
|
7
8
|
import type { TeamTurns } from "./team-turns.ts";
|
|
@@ -26,6 +27,7 @@ export function teamSystemPrompt(
|
|
|
26
27
|
shellUser,
|
|
27
28
|
scratchDir,
|
|
28
29
|
agentTools,
|
|
30
|
+
runner,
|
|
29
31
|
surfaces,
|
|
30
32
|
places,
|
|
31
33
|
} = options;
|
|
@@ -37,6 +39,13 @@ export function teamSystemPrompt(
|
|
|
37
39
|
const group = scope.group ? store.group(scope.group) : undefined;
|
|
38
40
|
const coordinator = coordinatorOf(store, places, options);
|
|
39
41
|
const speaker = turns.speakerOf(scope);
|
|
42
|
+
// A conversation only the owners reach keeps the host's shell on a host with a runner.
|
|
43
|
+
const inRunner =
|
|
44
|
+
runner && !ownersOnlyConversation(store, places, surfaces, scope);
|
|
45
|
+
// A temp knight that shares its parent's workspace in the runner is told whose files it sees.
|
|
46
|
+
const parent = agent.parent ? store.agent(agent.parent) : undefined;
|
|
47
|
+
const shares =
|
|
48
|
+
inRunner && parent && runnerHomeOf(store, places, scope) !== scope.home;
|
|
40
49
|
const base = agentSystemPrompt({
|
|
41
50
|
agent,
|
|
42
51
|
...(speaker ? { speaker } : {}),
|
|
@@ -48,9 +57,11 @@ export function teamSystemPrompt(
|
|
|
48
57
|
shellUser,
|
|
49
58
|
...(scratchDir ? { scratchDir } : {}),
|
|
50
59
|
images,
|
|
51
|
-
...(agent.parent ? { parent
|
|
60
|
+
...(agent.parent ? { parent } : {}),
|
|
61
|
+
...(shares ? { runnerWith: parent.displayName } : {}),
|
|
52
62
|
helpers: options.helpers !== false,
|
|
53
63
|
...(agentTools ? { agentTools } : {}),
|
|
64
|
+
...(inRunner ? { runner } : {}),
|
|
54
65
|
...placeOf(turns.turnChannel(scope), surfaces, places.surfaces()),
|
|
55
66
|
...(group
|
|
56
67
|
? {
|
|
@@ -8,6 +8,10 @@ import { AGENT_TOOLS } from "../agents/agent-tools.ts";
|
|
|
8
8
|
import { FileAvatarStudio } from "../agents/avatar-studio.ts";
|
|
9
9
|
import { RelevanceScorer } from "../agents/group-round.ts";
|
|
10
10
|
import { modeOrigins } from "../agents/helper-modes.ts";
|
|
11
|
+
import {
|
|
12
|
+
ownersOnlyConversation,
|
|
13
|
+
runnerHomeOf,
|
|
14
|
+
} from "../agents/helper-workspace.ts";
|
|
11
15
|
import { Routes } from "../agents/routes.ts";
|
|
12
16
|
import { TeamPlaces } from "../agents/team-places.ts";
|
|
13
17
|
import { ownerAttachmentDir } from "../attachments/attachment-dir.ts";
|
|
@@ -277,6 +281,7 @@ export function agentServerPlugin(
|
|
|
277
281
|
seeds: () => context.sessions().seeds,
|
|
278
282
|
promptSections: () => context.sessions().prompt,
|
|
279
283
|
agentTools: context.env.agentTools,
|
|
284
|
+
...(context.env.runner ? { runner: true } : {}),
|
|
280
285
|
pluginTools: () => context.sessions().agentTools,
|
|
281
286
|
pluginWithheldFromHelpers: () =>
|
|
282
287
|
context.sessions().agentToolsWithheldFromHelpers ?? [],
|
|
@@ -339,6 +344,9 @@ export function agentServerPlugin(
|
|
|
339
344
|
modelOf: (name) => built.modelOf(name),
|
|
340
345
|
skills: (name) => built.skillsOf(name),
|
|
341
346
|
turnChannel: (scope) => built.turnChannel(scope),
|
|
347
|
+
runnerHome: (scope) => runnerHomeOf(store, places, scope),
|
|
348
|
+
ownersOnly: (scope) =>
|
|
349
|
+
ownersOnlyConversation(store, places, surfaces, scope),
|
|
342
350
|
...(options.memory ? { memory: options.memory } : {}),
|
|
343
351
|
};
|
|
344
352
|
options.agents?.bind(agentSessions);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Tier } from "../identity/speakers.ts";
|
|
2
|
+
import type { PollRules } from "../modules/polls/poll-rules.ts";
|
|
3
|
+
import { PollService, type PollTimer } from "../modules/polls/poll-service.ts";
|
|
4
|
+
import { PgPollStore, type PollStore } from "../modules/polls/poll-store.ts";
|
|
5
|
+
import { POLL_TOOLS, pollsExtension } from "../modules/polls/poll-tools.ts";
|
|
6
|
+
import type { RoundtablePlugin } from "../plugin-api/plugin.ts";
|
|
7
|
+
import { POLL_TARGET } from "../shared/poll-target.ts";
|
|
8
|
+
import { fixed } from "./session-tool.ts";
|
|
9
|
+
|
|
10
|
+
/** Every speaker may start a poll and end their own; an owner may end anyone's. */
|
|
11
|
+
const POLL_TIERS: Readonly<Record<string, Tier>> = Object.fromEntries(
|
|
12
|
+
POLL_TOOLS.map((tool) => [tool, "member" as const]),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export interface PollsOptions {
|
|
16
|
+
/** The host's rules over the defaults (`POLL_RULES`); for tests and hosts that hold polls tighter. */
|
|
17
|
+
rules?: Partial<PollRules>;
|
|
18
|
+
/** Replaces the store over the host's database; for tests. */
|
|
19
|
+
store?: PollStore;
|
|
20
|
+
/** Replaces the timers; for tests. */
|
|
21
|
+
timer?: PollTimer;
|
|
22
|
+
now?: () => Date;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Native polls on the surfaces that have them (`ChatSurface.polls`): the table, the poll service,
|
|
27
|
+
* `poll_create` and `poll_end` in every session (offered where a selection names them), and
|
|
28
|
+
* `POLL_TARGET`, whose turns bring each poll's results back to its conversation as its starter's.
|
|
29
|
+
*/
|
|
30
|
+
export function pollsPlugin(options: PollsOptions = {}): RoundtablePlugin {
|
|
31
|
+
return {
|
|
32
|
+
name: "polls",
|
|
33
|
+
...(options.store ? {} : { migrations: PgPollStore.migrations() }),
|
|
34
|
+
setup: ({ database, conversations, surfaces, logger }) => {
|
|
35
|
+
const service = new PollService({
|
|
36
|
+
store: options.store ?? PgPollStore.attach(database()),
|
|
37
|
+
surfaces,
|
|
38
|
+
conversations,
|
|
39
|
+
logger,
|
|
40
|
+
...(options.rules ? { rules: options.rules } : {}),
|
|
41
|
+
...(options.timer ? { timer: options.timer } : {}),
|
|
42
|
+
...(options.now ? { now: options.now } : {}),
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
services: [
|
|
46
|
+
{
|
|
47
|
+
name: "polls",
|
|
48
|
+
start: () => service.start(),
|
|
49
|
+
beginDrain: () => service.beginDrain(),
|
|
50
|
+
stop: () => service.stop(),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
sessionTools: [
|
|
54
|
+
fixed("polls", (session) =>
|
|
55
|
+
pollsExtension(
|
|
56
|
+
service,
|
|
57
|
+
() => session.turnChannel,
|
|
58
|
+
() => session.speaker(),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
],
|
|
62
|
+
toolTiers: POLL_TIERS,
|
|
63
|
+
backgroundTargets: [POLL_TARGET],
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { ConfigError } from "../domain/errors.ts";
|
|
2
|
+
import type { Logger } from "../kernel/log.ts";
|
|
3
|
+
import type { RoundtablePlugin, Service } from "../plugin-api/plugin.ts";
|
|
4
|
+
import { RunnerClient, type RunnerDriver } from "../runner/runner-client.ts";
|
|
5
|
+
import { DockerDriver, socketDriver } from "../runner/runner-drivers.ts";
|
|
6
|
+
import { runnerShellRule } from "../runner/runner-holds.ts";
|
|
7
|
+
import { RUNNER } from "../runner/runner-port.ts";
|
|
8
|
+
import type { RunnerSettings } from "../runner/settings.ts";
|
|
9
|
+
|
|
10
|
+
/** The name of the runner's plugin. */
|
|
11
|
+
export const RUNNER_PLUGIN = "runner";
|
|
12
|
+
|
|
13
|
+
/** The wait between two sweeps of idle workspaces. */
|
|
14
|
+
export const RUNNER_SWEEP_EVERY_MS = 24 * 60 * 60_000;
|
|
15
|
+
|
|
16
|
+
/** A driver and what it checks before the host starts. */
|
|
17
|
+
export interface RunnerStart {
|
|
18
|
+
driver: RunnerDriver;
|
|
19
|
+
/**
|
|
20
|
+
* Throws a ConfigError when the host must not start, as the docker driver does without the
|
|
21
|
+
* docker CLI or the image; a runner that is only not up yet is logged and the host starts.
|
|
22
|
+
*/
|
|
23
|
+
check(logger: Logger): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The configured driver: the docker CLI's container, or a sidecar's socket. */
|
|
27
|
+
export function runnerStart(
|
|
28
|
+
settings: RunnerSettings,
|
|
29
|
+
dataDir: string,
|
|
30
|
+
): RunnerStart {
|
|
31
|
+
if (settings.driver === "docker") {
|
|
32
|
+
const driver = new DockerDriver(settings, dataDir);
|
|
33
|
+
return { driver, check: () => driver.check() };
|
|
34
|
+
}
|
|
35
|
+
const driver = socketDriver(settings.socket);
|
|
36
|
+
return {
|
|
37
|
+
driver,
|
|
38
|
+
check: async (logger) => {
|
|
39
|
+
// The two containers start in either order: a missing socket is waited for, then logged.
|
|
40
|
+
if (!(await driver.ready()))
|
|
41
|
+
logger.error(
|
|
42
|
+
{ socket: settings.socket },
|
|
43
|
+
"the runner's socket is not there; the runner's tools fail until it is",
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface RunnerPluginOptions {
|
|
50
|
+
/** The data directory, which names the docker driver's container. */
|
|
51
|
+
dataDir: string;
|
|
52
|
+
/** The driver for the host's `env.runner`; default `runnerStart`, a test hands its own. */
|
|
53
|
+
start?: (settings: RunnerSettings) => RunnerStart;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The runner, provided as `RUNNER` for the runtime's sessions, from the host's `env.runner`. At
|
|
58
|
+
* start it checks the driver (a docker host without the CLI or the image stops with a
|
|
59
|
+
* ConfigError naming `runner.image`), then removes the workspaces idle for `keepDays`, and again
|
|
60
|
+
* once a day. It links the `runner-shell` hold rule, which judges only the calls of sessions the
|
|
61
|
+
* runner serves.
|
|
62
|
+
*/
|
|
63
|
+
export function runnerPlugin(options: RunnerPluginOptions): RoundtablePlugin {
|
|
64
|
+
return {
|
|
65
|
+
name: RUNNER_PLUGIN,
|
|
66
|
+
provides: [RUNNER],
|
|
67
|
+
setup: ({ env, logger, services }) => {
|
|
68
|
+
const settings = env.runner;
|
|
69
|
+
if (!settings)
|
|
70
|
+
throw new ConfigError(
|
|
71
|
+
"the runner plugin needs the host's runner setting (environment.runner); set runner in the configuration, or leave the plugin out.",
|
|
72
|
+
);
|
|
73
|
+
const start = (options.start ?? ((s) => runnerStart(s, options.dataDir)))(
|
|
74
|
+
settings,
|
|
75
|
+
);
|
|
76
|
+
const client = new RunnerClient(start.driver);
|
|
77
|
+
services.provide(RUNNER, client);
|
|
78
|
+
return {
|
|
79
|
+
holdRules: [runnerShellRule],
|
|
80
|
+
services: [runnerService(client, start, settings, logger)],
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function runnerService(
|
|
87
|
+
client: RunnerClient,
|
|
88
|
+
start: RunnerStart,
|
|
89
|
+
settings: RunnerSettings,
|
|
90
|
+
logger: Logger,
|
|
91
|
+
): Service {
|
|
92
|
+
let timer: ReturnType<typeof setInterval> | undefined;
|
|
93
|
+
let sweeping: Promise<void> | undefined;
|
|
94
|
+
const sweep = (): Promise<void> => {
|
|
95
|
+
sweeping ??= client
|
|
96
|
+
.sweep(settings.keepDays)
|
|
97
|
+
.then(
|
|
98
|
+
(removed) => {
|
|
99
|
+
if (removed.length > 0)
|
|
100
|
+
logger.info(
|
|
101
|
+
{ removed: removed.length, keepDays: settings.keepDays },
|
|
102
|
+
"idle runner workspaces removed",
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
(error: unknown) =>
|
|
106
|
+
logger.warn({ err: error }, "idle runner workspaces not swept"),
|
|
107
|
+
)
|
|
108
|
+
.finally(() => {
|
|
109
|
+
sweeping = undefined;
|
|
110
|
+
});
|
|
111
|
+
return sweeping;
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
name: "runner",
|
|
115
|
+
start: async () => {
|
|
116
|
+
await start.check(logger);
|
|
117
|
+
try {
|
|
118
|
+
const { version } = await client.ping();
|
|
119
|
+
logger.info(
|
|
120
|
+
{ driver: settings.driver, target: client.target, version },
|
|
121
|
+
"runner reachable",
|
|
122
|
+
);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
logger.error(
|
|
125
|
+
{ driver: settings.driver, target: client.target, err: error },
|
|
126
|
+
"the runner is not reachable; its tools fail until it is",
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
void sweep();
|
|
130
|
+
timer = setInterval(() => void sweep(), RUNNER_SWEEP_EVERY_MS);
|
|
131
|
+
},
|
|
132
|
+
stop: async () => {
|
|
133
|
+
clearInterval(timer);
|
|
134
|
+
timer = undefined;
|
|
135
|
+
await sweeping;
|
|
136
|
+
client.end();
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -12,6 +12,7 @@ import { helpersField } from "./helpers.ts";
|
|
|
12
12
|
import { limitsShape } from "./limits.ts";
|
|
13
13
|
import { profilesShape } from "./profiles.ts";
|
|
14
14
|
import { routingShape } from "./routing.ts";
|
|
15
|
+
import { runnerField } from "./runner-config.ts";
|
|
15
16
|
import {
|
|
16
17
|
bool,
|
|
17
18
|
characterInput,
|
|
@@ -118,6 +119,9 @@ export const configSchema = shape({
|
|
|
118
119
|
),
|
|
119
120
|
}),
|
|
120
121
|
),
|
|
122
|
+
preset: optional(oneOf("shared")),
|
|
123
|
+
imageTool: optional(oneOf("every-selection", "selected")),
|
|
124
|
+
runner: optional(runnerField),
|
|
121
125
|
toolTiers: optional(record(oneOf<Tier>("owner", "admin", "member"))),
|
|
122
126
|
prompts: optional(shape({ shared: text, guest: optional(text) })),
|
|
123
127
|
agents: optional(
|