pi-roundtable 0.53.5 → 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 +19 -0
- package/README.md +14 -2
- package/README.zh-TW.md +14 -2
- package/docs/plugins.md +201 -8
- 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/attachments/attachment-expiry.ts +12 -0
- package/src/core/attachments/attachment-store.ts +20 -5
- package/src/core/attachments/model-images.ts +3 -2
- 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/attachments.ts +2 -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/client.ts +6 -2
- 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/attachment-reader.ts +10 -1
- 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
|
@@ -37,6 +37,7 @@ export function schedulesEn(ctx: CatalogContext) {
|
|
|
37
37
|
target: string,
|
|
38
38
|
) => `**#${id} ${title}** · ${channel} · ${target}`,
|
|
39
39
|
scheduleModeOwner: ctx.assistant,
|
|
40
|
+
scheduleModePoll: "Poll results",
|
|
40
41
|
scheduleFooter: `Schedules are created and edited by the bot in conversation; here you can review and cancel them. \`/${ctx.root} schedule cancel\` cancels one.`,
|
|
41
42
|
scheduleGroupDescription: "Schedules",
|
|
42
43
|
scheduleListDescription: "List the schedules of every channel",
|
|
@@ -88,6 +89,7 @@ export function schedulesZhTW(
|
|
|
88
89
|
target: string,
|
|
89
90
|
) => `**#${id} ${title}** ${channel} ${target}`,
|
|
90
91
|
scheduleModeOwner: ctx.assistant,
|
|
92
|
+
scheduleModePoll: "投票結果",
|
|
91
93
|
scheduleFooter: `排程由 bot 在對話中建立與修改;這裡可以總覽與取消。\`/${ctx.root} schedule cancel\` 取消。`,
|
|
92
94
|
scheduleGroupDescription: "排程",
|
|
93
95
|
scheduleListDescription: "列出所有頻道的排程",
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BackgroundTurn,
|
|
3
|
+
ScheduledOutcome,
|
|
4
|
+
} from "../../contract/channels.ts";
|
|
5
|
+
import type { ConversationRegistry } from "../../conversations/conversation-registry.ts";
|
|
6
|
+
import type { ChannelKey, TurnSelection } from "../../domain/sessions.ts";
|
|
7
|
+
import type { Speaker } from "../../identity/speakers.ts";
|
|
8
|
+
import type { ConversationTurns } from "../../routing/conversation-turns.ts";
|
|
9
|
+
import { POLL_TARGET } from "../../shared/poll-target.ts";
|
|
10
|
+
|
|
11
|
+
/** How a claim answers a poll's results in one of its conversations. */
|
|
12
|
+
export interface PollResultAnswer {
|
|
13
|
+
/** The conversation's kind, whose persona answers. */
|
|
14
|
+
kind: string;
|
|
15
|
+
/** The tools of the result turn, such as the ones the conversation's own turns carry. */
|
|
16
|
+
selection: TurnSelection;
|
|
17
|
+
/** Where the turn comes from, as the claim's own turns there say it; left out, none. */
|
|
18
|
+
origin?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PollResultTurnsOptions {
|
|
22
|
+
/** Runs the turn: the plugin's `context.turns`. */
|
|
23
|
+
turns: Pick<ConversationTurns, "run">;
|
|
24
|
+
/**
|
|
25
|
+
* The host's conversation registry (`CONVERSATIONS`), read at each turn; undefined on a host
|
|
26
|
+
* that records none, where every result turn is skipped, since whose conversation it is
|
|
27
|
+
* cannot be checked.
|
|
28
|
+
*/
|
|
29
|
+
conversations: () => Pick<ConversationRegistry, "get"> | undefined;
|
|
30
|
+
/** How the claim answers a poll's results in a channel; undefined skips the turn. */
|
|
31
|
+
answer(channel: ChannelKey): PollResultAnswer | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What a claim spreads into itself to answer poll results: `background` and its `backgroundRefusal`. */
|
|
35
|
+
export interface PollResultTurns {
|
|
36
|
+
background(turn: BackgroundTurn): Promise<ScheduledOutcome>;
|
|
37
|
+
backgroundRefusal(
|
|
38
|
+
turn: BackgroundTurn & { speaker: Speaker },
|
|
39
|
+
): string | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A claim's `background` for `POLL_TARGET` alone, so a plugin's claim hears the results of the
|
|
44
|
+
* polls its turns started: `...pollResultTurns({ turns, conversations, answer })`. Each result
|
|
45
|
+
* turn runs as the poll's starter, as the router checked them, with the selection `answer` gives
|
|
46
|
+
* for the channel; it is never a message (no `byMessage`, no `confirmed`), so it approves no held
|
|
47
|
+
* action, and nobody waits on it. It skips every other target, a turn the router did not run as
|
|
48
|
+
* the starter, a channel `answer` leaves out, and a conversation that is gone or now private to
|
|
49
|
+
* someone else.
|
|
50
|
+
*/
|
|
51
|
+
export function pollResultTurns(
|
|
52
|
+
options: PollResultTurnsOptions,
|
|
53
|
+
): PollResultTurns {
|
|
54
|
+
/** Why the turn is skipped, or how it is answered. */
|
|
55
|
+
const check = (
|
|
56
|
+
turn: BackgroundTurn & { speaker: Speaker },
|
|
57
|
+
): { reason: string } | { answer: PollResultAnswer } => {
|
|
58
|
+
if (turn.target !== POLL_TARGET.name)
|
|
59
|
+
return {
|
|
60
|
+
reason: `this claim answers only "${POLL_TARGET.name}" background turns`,
|
|
61
|
+
};
|
|
62
|
+
if (turn.speaker.principalId !== turn.author.principalId)
|
|
63
|
+
return {
|
|
64
|
+
reason: "a poll's results run only as the person who started it",
|
|
65
|
+
};
|
|
66
|
+
const answer = options.answer(turn.channel);
|
|
67
|
+
return answer
|
|
68
|
+
? { answer }
|
|
69
|
+
: { reason: "this conversation takes no poll results" };
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
backgroundRefusal: (turn) => {
|
|
73
|
+
const checked = check(turn);
|
|
74
|
+
return "reason" in checked ? checked.reason : undefined;
|
|
75
|
+
},
|
|
76
|
+
background: async (turn) => {
|
|
77
|
+
const { speaker } = turn;
|
|
78
|
+
if (!speaker)
|
|
79
|
+
return {
|
|
80
|
+
status: "skipped",
|
|
81
|
+
reason:
|
|
82
|
+
"a poll's results reach a claim through the router, which says whom they run as",
|
|
83
|
+
};
|
|
84
|
+
const checked = check({ ...turn, speaker });
|
|
85
|
+
if ("reason" in checked)
|
|
86
|
+
return { status: "skipped", reason: checked.reason };
|
|
87
|
+
const { answer } = checked;
|
|
88
|
+
const registry = options.conversations();
|
|
89
|
+
if (!registry)
|
|
90
|
+
return {
|
|
91
|
+
status: "skipped",
|
|
92
|
+
reason:
|
|
93
|
+
"the host records no conversations, so whose this one is cannot be checked",
|
|
94
|
+
};
|
|
95
|
+
const kept = await registry.get(turn.channel);
|
|
96
|
+
if (!kept)
|
|
97
|
+
return { status: "skipped", reason: "the conversation is gone" };
|
|
98
|
+
if (
|
|
99
|
+
kept.visibility === "private" &&
|
|
100
|
+
kept.principalId !== speaker.principalId
|
|
101
|
+
)
|
|
102
|
+
return {
|
|
103
|
+
status: "skipped",
|
|
104
|
+
reason:
|
|
105
|
+
"the conversation now belongs to someone other than the poll's starter",
|
|
106
|
+
};
|
|
107
|
+
const result = await options.turns.run({
|
|
108
|
+
channel: turn.channel,
|
|
109
|
+
kind: answer.kind,
|
|
110
|
+
text: turn.text,
|
|
111
|
+
speaker,
|
|
112
|
+
selection: answer.selection,
|
|
113
|
+
...(answer.origin === undefined ? {} : { origin: answer.origin }),
|
|
114
|
+
unattended: true,
|
|
115
|
+
...(turn.timeLimitMs === undefined
|
|
116
|
+
? {}
|
|
117
|
+
: { timeLimitMs: turn.timeLimitMs }),
|
|
118
|
+
});
|
|
119
|
+
return result.ok
|
|
120
|
+
? { status: "ran" }
|
|
121
|
+
: { status: "failed", error: "a poll's result turn failed" };
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { PollLimits, SurfacePolls } from "../../contract/polls.ts";
|
|
2
|
+
import type { ChatSurface } from "../../contract/surface.ts";
|
|
3
|
+
import type { ChannelKey } from "../../domain/conversation.ts";
|
|
4
|
+
import { PollError } from "../../domain/errors.ts";
|
|
5
|
+
|
|
6
|
+
/** The host's rules for polls, within what each surface allows. */
|
|
7
|
+
export interface PollRules {
|
|
8
|
+
/** The most polls open at once in one conversation. */
|
|
9
|
+
maxOpen: number;
|
|
10
|
+
minDurationMs: number;
|
|
11
|
+
maxDurationMs: number;
|
|
12
|
+
/** How long the results of an ended poll are tried, from the first try or a restart. */
|
|
13
|
+
readForMs: number;
|
|
14
|
+
/** The first wait between tries, doubled each time up to `retryMaxMs`. */
|
|
15
|
+
retryFirstMs: number;
|
|
16
|
+
retryMaxMs: number;
|
|
17
|
+
/** How long a reported poll's row is kept. */
|
|
18
|
+
keepDays: number;
|
|
19
|
+
/**
|
|
20
|
+
* How long a poll stored but not yet posted is left to the process posting it; after that
|
|
21
|
+
* another process takes it for one whose process stopped, and discards it.
|
|
22
|
+
*/
|
|
23
|
+
postGraceMs: number;
|
|
24
|
+
/**
|
|
25
|
+
* How long a result turn one process claimed is left to it; after that another process takes
|
|
26
|
+
* it for one whose process stopped, and runs it. Longer than any result turn runs.
|
|
27
|
+
*/
|
|
28
|
+
reportLeaseMs: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const POLL_RULES: PollRules = {
|
|
32
|
+
maxOpen: 3,
|
|
33
|
+
minDurationMs: 60_000,
|
|
34
|
+
maxDurationMs: 7 * 24 * 3_600_000,
|
|
35
|
+
readForMs: 3_600_000,
|
|
36
|
+
retryFirstMs: 60_000,
|
|
37
|
+
retryMaxMs: 15 * 60_000,
|
|
38
|
+
keepDays: 30,
|
|
39
|
+
postGraceMs: 2 * 60_000,
|
|
40
|
+
reportLeaseMs: 3 * 3_600_000,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** At least two answers, as every poll needs. */
|
|
44
|
+
const MIN_ANSWERS = 2;
|
|
45
|
+
|
|
46
|
+
/** What `poll_create` asks for. */
|
|
47
|
+
export interface PollRequest {
|
|
48
|
+
question: string;
|
|
49
|
+
answers: readonly string[];
|
|
50
|
+
multi: boolean;
|
|
51
|
+
closesInMinutes: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A surface's polls in a channel, or why there are none. */
|
|
55
|
+
export function pollsOf(
|
|
56
|
+
surfaces: { of(channel: ChannelKey): ChatSurface | undefined },
|
|
57
|
+
channel: ChannelKey,
|
|
58
|
+
): SurfacePolls {
|
|
59
|
+
const surface = surfaces.of(channel);
|
|
60
|
+
if (!surface)
|
|
61
|
+
throw new PollError(
|
|
62
|
+
"This conversation is on no chat surface, so there is nowhere to post a poll.",
|
|
63
|
+
);
|
|
64
|
+
if (!surface.polls)
|
|
65
|
+
throw new PollError(
|
|
66
|
+
`${surface.label ?? surface.surface} has no native polls, so a poll cannot be posted in this conversation.`,
|
|
67
|
+
);
|
|
68
|
+
return surface.polls;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The request, trimmed, within the surface's limits and the host's rules. */
|
|
72
|
+
export function checked(
|
|
73
|
+
request: PollRequest,
|
|
74
|
+
limits: PollLimits,
|
|
75
|
+
rules: PollRules,
|
|
76
|
+
): PollRequest & { durationMs: number } {
|
|
77
|
+
const question = request.question.trim();
|
|
78
|
+
const answers = request.answers.map((answer) => answer.trim());
|
|
79
|
+
if (!question) throw new PollError("question is required.");
|
|
80
|
+
if (question.length > limits.questionChars)
|
|
81
|
+
throw new PollError(
|
|
82
|
+
`The question is ${question.length} characters; a poll here takes at most ${limits.questionChars}.`,
|
|
83
|
+
);
|
|
84
|
+
if (answers.length < MIN_ANSWERS || answers.length > limits.answers)
|
|
85
|
+
throw new PollError(
|
|
86
|
+
`A poll here has ${MIN_ANSWERS} to ${limits.answers} answers; ${answers.length} were given.`,
|
|
87
|
+
);
|
|
88
|
+
const long = answers.find((answer) => answer.length > limits.answerChars);
|
|
89
|
+
if (long !== undefined)
|
|
90
|
+
throw new PollError(
|
|
91
|
+
`The answer ${JSON.stringify(long)} is ${long.length} characters; an answer here takes at most ${limits.answerChars}.`,
|
|
92
|
+
);
|
|
93
|
+
if (answers.some((answer) => !answer))
|
|
94
|
+
throw new PollError("Every answer needs text.");
|
|
95
|
+
if (new Set(answers).size !== answers.length)
|
|
96
|
+
throw new PollError("Each answer must differ from the others.");
|
|
97
|
+
const durationMs = request.closesInMinutes * 60_000;
|
|
98
|
+
const longest = Math.min(rules.maxDurationMs, limits.maxDurationMs);
|
|
99
|
+
if (
|
|
100
|
+
!Number.isFinite(durationMs) ||
|
|
101
|
+
durationMs < rules.minDurationMs ||
|
|
102
|
+
durationMs > longest
|
|
103
|
+
)
|
|
104
|
+
throw new PollError(
|
|
105
|
+
`closes_in_minutes must be from ${Math.ceil(rules.minDurationMs / 60_000)} to ${Math.floor(longest / 60_000)}.`,
|
|
106
|
+
);
|
|
107
|
+
return { ...request, question, answers, durationMs };
|
|
108
|
+
}
|