toolroll 0.9.53 → 0.9.54
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 +8 -0
- package/dist/chat-ask.js +8 -8
- package/dist/chat-core.d.ts +171 -0
- package/dist/chat-core.js +288 -0
- package/dist/chat-decide.d.ts +10 -8
- package/dist/chat-decide.js +26 -21
- package/dist/chat-delivery-state.d.ts +51 -75
- package/dist/chat-delivery-state.js +140 -170
- package/dist/chat-delivery.d.ts +21 -2
- package/dist/chat-delivery.js +313 -194
- package/dist/chat-flow.d.ts +29 -1
- package/dist/chat-flow.js +24 -50
- package/dist/chat-messages.d.ts +319 -0
- package/dist/chat-messages.js +841 -0
- package/dist/chat-migration.d.ts +30 -0
- package/dist/chat-migration.js +802 -0
- package/dist/chat-quiet.d.ts +3 -0
- package/dist/chat-quiet.js +5 -0
- package/dist/contracts/chat-content.d.ts +71 -2
- package/dist/contracts/chat-content.js +22 -3
- package/dist/contracts/chat-tables.d.ts +11 -4
- package/dist/contracts/chat-tables.js +165 -87
- package/dist/contracts/discord-callback.js +2 -1
- package/dist/contracts/slack-callback.js +3 -2
- package/dist/contracts/store-json.d.ts +1 -5
- package/dist/contracts/store-json.js +1 -4
- package/dist/contracts/teams-callback.js +2 -1
- package/dist/discord-chat.js +19 -38
- package/dist/discord-settings.js +4 -13
- package/dist/discord.js +4 -14
- package/dist/export.js +4 -4
- package/dist/mate-tools.js +3 -2
- package/dist/modes.d.ts +13 -1
- package/dist/modes.js +17 -1
- package/dist/notification-rows.d.ts +30 -0
- package/dist/notification-rows.js +102 -0
- package/dist/operate.js +5 -2
- package/dist/plane-review.js +5 -11
- package/dist/project-delete.js +21 -26
- package/dist/result-shots.js +2 -2
- package/dist/retention.js +1 -1
- package/dist/server/settings.js +5 -4
- package/dist/slack-api.d.ts +5 -1
- package/dist/slack-api.js +2 -2
- package/dist/slack-chat.d.ts +9 -4
- package/dist/slack-chat.js +29 -52
- package/dist/slack-settings.js +6 -15
- package/dist/slack.js +6 -16
- package/dist/store.d.ts +97 -364
- package/dist/store.js +207 -1531
- package/dist/teammate-question.js +12 -12
- package/dist/teams-chat.js +12 -9
- package/dist/teams-settings.js +2 -2
- package/dist/teams.js +4 -5
- package/dist/telegram-flow.js +5 -5
- package/dist/telegram.js +4 -4
- package/dist/toolroll-update.d.ts +10 -0
- package/dist/toolroll-update.js +50 -3
- package/dist/workspace-revision.js +3 -1
- package/package.json +1 -1
- package/dist/slack-state.d.ts +0 -13
- package/dist/slack-state.js +0 -10
package/dist/chat-quiet.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export type QuietView = {
|
|
|
11
11
|
also?: PhoneTaskLink[];
|
|
12
12
|
target?: DecideTarget;
|
|
13
13
|
};
|
|
14
|
+
/** What still wants a person who pairs after it landed, in every chat app: an open decision or an unresolved attention
|
|
15
|
+
* notice. Routine history is never replayed to a chat that just arrived (store.ts WANTED_BEFORE_PAIRING, the same rule). */
|
|
16
|
+
export declare function wantedBeforePairing(row: Pick<Notification, "dedupeKey" | "pushClass" | "resolvedAt">): boolean;
|
|
14
17
|
export declare function needsPerson(row: Pick<Notification, "dedupeKey" | "kind" | "pushClass" | "recipient">): boolean;
|
|
15
18
|
/** A fact about one placed task: in quiet mode it lands on that task's card. */
|
|
16
19
|
export declare function isTaskFact(row: Pick<Notification, "taskRef" | "taskId" | "project">): row is typeof row & {
|
package/dist/chat-quiet.js
CHANGED
|
@@ -20,6 +20,11 @@ const NEEDED_KINDS = new Set([
|
|
|
20
20
|
"acceptance-ready", "acceptance-evidence", "flow-decision", "flow-card", "plan-ready", "report-ready",
|
|
21
21
|
"stale-approval", "security-release", "secret-detected",
|
|
22
22
|
]);
|
|
23
|
+
/** What still wants a person who pairs after it landed, in every chat app: an open decision or an unresolved attention
|
|
24
|
+
* notice. Routine history is never replayed to a chat that just arrived (store.ts WANTED_BEFORE_PAIRING, the same rule). */
|
|
25
|
+
export function wantedBeforePairing(row) {
|
|
26
|
+
return row.resolvedAt === null && (row.dedupeKey.startsWith("decision:") || row.pushClass === "attention");
|
|
27
|
+
}
|
|
23
28
|
export function needsPerson(row) {
|
|
24
29
|
if (row.recipient !== null)
|
|
25
30
|
return true;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What
|
|
2
|
+
* What every chat app keeps between steps (chat-delivery-state.ts, and Telegram's store methods): one schema for a received event's body
|
|
3
3
|
* (`chat_event.payload`, by the event's kind) and one for a planned message part (`chat_part.payload`), the message a
|
|
4
4
|
* button rides and the content a delivery repaints. Both are saved with `version`; a body or part saved before they
|
|
5
5
|
* carried one reads as it did then (its known fields; a reader then passed any others by unread).
|
|
6
6
|
*
|
|
7
|
-
* An event body lives only until the event is handled (then it is `{}
|
|
7
|
+
* An event body lives only until the event is handled (then it is `{}`; a Telegram message keeps its words as its
|
|
8
|
+
* record until its chat is unpaired); a part lives as long as its message.
|
|
8
9
|
*/
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
import { type ContractResult } from "./contract.js";
|
|
12
|
+
/** A Toolroll button's one-time token, as every chat app carries it: 32 hex, or `d:` and 24 hex for a decide button
|
|
13
|
+
* (chat-decide.ts: a result's, plan's, failure's or pull request's own buttons). */
|
|
14
|
+
export declare const CHAT_BUTTON_TOKEN: RegExp;
|
|
11
15
|
/** One planned message part, as delivery reads it. */
|
|
12
16
|
export declare const chatContentShape: {
|
|
13
17
|
text: z.ZodString;
|
|
@@ -78,6 +82,31 @@ export declare const chatContentShape: {
|
|
|
78
82
|
}, z.core.$strict>>;
|
|
79
83
|
/** The lead's own reply, already shaped (reply-shape.ts): the channel renders its bold anchors and labelled links in its own format. */
|
|
80
84
|
voice: z.ZodOptional<z.ZodLiteral<true>>;
|
|
85
|
+
/** Telegram: the person's message the first reply part answers. */
|
|
86
|
+
replyTo: z.ZodOptional<z.ZodString>;
|
|
87
|
+
/** Telegram: the part's buttons exactly as sent, their tokens minted with the part (a resend carries the same ones). */
|
|
88
|
+
keyboard: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
89
|
+
text: z.ZodString;
|
|
90
|
+
callback_data: z.ZodString;
|
|
91
|
+
}, z.core.$loose>>>>;
|
|
92
|
+
/** Telegram: a proposal card, still one after its proposal is gone. */
|
|
93
|
+
card: z.ZodOptional<z.ZodLiteral<true>>;
|
|
94
|
+
/** A result's, plan's, failure's or pull request's own buttons (chat-decide.ts), minted with the part: each an act's
|
|
95
|
+
* one-time token or a link. They ride the message once it is sent. */
|
|
96
|
+
decide: z.ZodOptional<z.ZodObject<{
|
|
97
|
+
rows: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
98
|
+
label: z.ZodString;
|
|
99
|
+
token: z.ZodString;
|
|
100
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
101
|
+
label: z.ZodString;
|
|
102
|
+
link: z.ZodObject<{
|
|
103
|
+
label: z.ZodString;
|
|
104
|
+
path: z.ZodString;
|
|
105
|
+
}, z.core.$strict>;
|
|
106
|
+
}, z.core.$strict>]>>>;
|
|
107
|
+
}, z.core.$strict>>;
|
|
108
|
+
/** The "What should change?" this part asks (chat-decide.ts): a reply to its message is the feedback. */
|
|
109
|
+
prompt: z.ZodOptional<z.ZodInt>;
|
|
81
110
|
};
|
|
82
111
|
export declare const chatContentSchema: z.ZodObject<{
|
|
83
112
|
text: z.ZodString;
|
|
@@ -138,6 +167,25 @@ export declare const chatContentSchema: z.ZodObject<{
|
|
|
138
167
|
options: z.ZodArray<z.ZodString>;
|
|
139
168
|
}, z.core.$strict>>;
|
|
140
169
|
voice: z.ZodOptional<z.ZodLiteral<true>>;
|
|
170
|
+
replyTo: z.ZodOptional<z.ZodString>;
|
|
171
|
+
keyboard: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
172
|
+
text: z.ZodString;
|
|
173
|
+
callback_data: z.ZodString;
|
|
174
|
+
}, z.core.$loose>>>>;
|
|
175
|
+
card: z.ZodOptional<z.ZodLiteral<true>>;
|
|
176
|
+
decide: z.ZodOptional<z.ZodObject<{
|
|
177
|
+
rows: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
178
|
+
label: z.ZodString;
|
|
179
|
+
token: z.ZodString;
|
|
180
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
181
|
+
label: z.ZodString;
|
|
182
|
+
link: z.ZodObject<{
|
|
183
|
+
label: z.ZodString;
|
|
184
|
+
path: z.ZodString;
|
|
185
|
+
}, z.core.$strict>;
|
|
186
|
+
}, z.core.$strict>]>>>;
|
|
187
|
+
}, z.core.$strict>>;
|
|
188
|
+
prompt: z.ZodOptional<z.ZodInt>;
|
|
141
189
|
}, z.core.$strict>;
|
|
142
190
|
export type ChatContent = z.infer<typeof chatContentSchema>;
|
|
143
191
|
export declare const CHAT_PART_VERSION = 1;
|
|
@@ -201,6 +249,25 @@ export declare const savedChatPartSchema: z.ZodObject<{
|
|
|
201
249
|
options: z.ZodArray<z.ZodString>;
|
|
202
250
|
}, z.core.$strict>>;
|
|
203
251
|
voice: z.ZodOptional<z.ZodLiteral<true>>;
|
|
252
|
+
replyTo: z.ZodOptional<z.ZodString>;
|
|
253
|
+
keyboard: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
254
|
+
text: z.ZodString;
|
|
255
|
+
callback_data: z.ZodString;
|
|
256
|
+
}, z.core.$loose>>>>;
|
|
257
|
+
card: z.ZodOptional<z.ZodLiteral<true>>;
|
|
258
|
+
decide: z.ZodOptional<z.ZodObject<{
|
|
259
|
+
rows: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
260
|
+
label: z.ZodString;
|
|
261
|
+
token: z.ZodString;
|
|
262
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
263
|
+
label: z.ZodString;
|
|
264
|
+
link: z.ZodObject<{
|
|
265
|
+
label: z.ZodString;
|
|
266
|
+
path: z.ZodString;
|
|
267
|
+
}, z.core.$strict>;
|
|
268
|
+
}, z.core.$strict>]>>>;
|
|
269
|
+
}, z.core.$strict>>;
|
|
270
|
+
prompt: z.ZodOptional<z.ZodInt>;
|
|
204
271
|
}, z.core.$strict>;
|
|
205
272
|
/** A saved part's content (`version` is the saved form's, not the content's). */
|
|
206
273
|
export declare function readChatPart(raw: string): ContractResult<ChatContent>;
|
|
@@ -227,6 +294,8 @@ export declare const chatMessageBodySchema: z.ZodObject<{
|
|
|
227
294
|
run: z.ZodNullable<z.ZodInt>;
|
|
228
295
|
}, z.core.$strict>>;
|
|
229
296
|
lead: z.ZodOptional<z.ZodLiteral<true>>;
|
|
297
|
+
context: z.ZodOptional<z.ZodString>;
|
|
298
|
+
request: z.ZodOptional<z.ZodString>;
|
|
230
299
|
}, z.core.$strict>;
|
|
231
300
|
/**
|
|
232
301
|
* A button: the one-time token it carried, or, when the app's callback came from the paired person but its data
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What
|
|
2
|
+
* What every chat app keeps between steps (chat-delivery-state.ts, and Telegram's store methods): one schema for a received event's body
|
|
3
3
|
* (`chat_event.payload`, by the event's kind) and one for a planned message part (`chat_part.payload`), the message a
|
|
4
4
|
* button rides and the content a delivery repaints. Both are saved with `version`; a body or part saved before they
|
|
5
5
|
* carried one reads as it did then (its known fields; a reader then passed any others by unread).
|
|
6
6
|
*
|
|
7
|
-
* An event body lives only until the event is handled (then it is `{}
|
|
7
|
+
* An event body lives only until the event is handled (then it is `{}`; a Telegram message keeps its words as its
|
|
8
|
+
* record until its chat is unpaired); a part lives as long as its message.
|
|
8
9
|
*/
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
import { parseContract, readVersioned, versioned } from "./contract.js";
|
|
11
12
|
const id = z.int().min(1);
|
|
12
13
|
const link = z.strictObject({ label: z.string(), path: z.string() });
|
|
14
|
+
/** A Toolroll button's one-time token, as every chat app carries it: 32 hex, or `d:` and 24 hex for a decide button
|
|
15
|
+
* (chat-decide.ts: a result's, plan's, failure's or pull request's own buttons). */
|
|
16
|
+
export const CHAT_BUTTON_TOKEN = /^(?:[a-f0-9]{32}|d:[a-f0-9]{24})$/;
|
|
13
17
|
/** One planned message part, as delivery reads it. */
|
|
14
18
|
export const chatContentShape = {
|
|
15
19
|
text: z.string(),
|
|
@@ -39,6 +43,17 @@ export const chatContentShape = {
|
|
|
39
43
|
ask: z.strictObject({ turn: id, options: z.array(z.string()) }).optional(),
|
|
40
44
|
/** The lead's own reply, already shaped (reply-shape.ts): the channel renders its bold anchors and labelled links in its own format. */
|
|
41
45
|
voice: z.literal(true).optional(),
|
|
46
|
+
/** Telegram: the person's message the first reply part answers. */
|
|
47
|
+
replyTo: z.string().optional(),
|
|
48
|
+
/** Telegram: the part's buttons exactly as sent, their tokens minted with the part (a resend carries the same ones). */
|
|
49
|
+
keyboard: z.array(z.array(z.looseObject({ text: z.string(), callback_data: z.string() }))).optional(),
|
|
50
|
+
/** Telegram: a proposal card, still one after its proposal is gone. */
|
|
51
|
+
card: z.literal(true).optional(),
|
|
52
|
+
/** A result's, plan's, failure's or pull request's own buttons (chat-decide.ts), minted with the part: each an act's
|
|
53
|
+
* one-time token or a link. They ride the message once it is sent. */
|
|
54
|
+
decide: z.strictObject({ rows: z.array(z.array(z.union([z.strictObject({ label: z.string(), token: z.string().regex(CHAT_BUTTON_TOKEN) }), z.strictObject({ label: z.string(), link })]))) }).optional(),
|
|
55
|
+
/** The "What should change?" this part asks (chat-decide.ts): a reply to its message is the feedback. */
|
|
56
|
+
prompt: id.optional(),
|
|
42
57
|
};
|
|
43
58
|
export const chatContentSchema = z.strictObject(chatContentShape);
|
|
44
59
|
export const CHAT_PART_VERSION = 1;
|
|
@@ -92,12 +107,16 @@ export const chatMessageBodySchema = versioned(CHAT_EVENT_VERSION, {
|
|
|
92
107
|
unsupported: z.string().optional(),
|
|
93
108
|
about: z.strictObject({ task: z.string(), run: z.int().nullable() }).optional(),
|
|
94
109
|
lead: z.literal(true).optional(),
|
|
110
|
+
/** Telegram: the server-authored context its turn carries (the exact task or result a reply bound to). */
|
|
111
|
+
context: z.string().optional(),
|
|
112
|
+
/** Telegram: the request identity the lead's engine receipts the turn under. */
|
|
113
|
+
request: z.string().optional(),
|
|
95
114
|
});
|
|
96
115
|
/**
|
|
97
116
|
* A button: the one-time token it carried, or, when the app's callback came from the paired person but its data
|
|
98
117
|
* couldn't be read, the path-named line saying why — answered plainly, and nothing is done.
|
|
99
118
|
*/
|
|
100
|
-
export const chatTokenBodySchema = versioned(CHAT_EVENT_VERSION, { token: z.string().regex(
|
|
119
|
+
export const chatTokenBodySchema = versioned(CHAT_EVENT_VERSION, { token: z.string().regex(CHAT_BUTTON_TOKEN, { error: "must be a Toolroll button token" }) });
|
|
101
120
|
export const chatProblemBodySchema = versioned(CHAT_EVENT_VERSION, { problem: z.string().min(1) });
|
|
102
121
|
export const chatActionBodySchema = z.union([chatTokenBodySchema, chatProblemBodySchema]);
|
|
103
122
|
/** A notice carries its parts, not a body. */
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
2
|
+
* The one set of chat tables every chat app shares (v116): Telegram, Slack, Discord and Teams keep their pairings,
|
|
3
|
+
* received events, planned message parts, buttons, rooms and delivery receipts here, each row keyed by `provider`.
|
|
4
|
+
* A row's identity is (provider, id): ids carried over from the per-app tables keep their numbers, and nothing infers
|
|
5
|
+
* the app from an id. A leaf: it imports nothing, so the store creates these tables without loading the chat modules.
|
|
4
6
|
*/
|
|
5
|
-
export declare const
|
|
6
|
-
export
|
|
7
|
+
export declare const CHAT_PROVIDERS: readonly ["telegram", "slack", "discord", "teams"];
|
|
8
|
+
export type ChatProvider = (typeof CHAT_PROVIDERS)[number];
|
|
9
|
+
export declare const isChatProvider: (value: unknown) => value is ChatProvider;
|
|
10
|
+
export declare const CHAT_SCHEMA: string;
|
|
11
|
+
/** Every shared chat table, parents before children. */
|
|
12
|
+
export declare const CHAT_TABLES: readonly ["chat_binding", "chat_pair", "chat_event", "chat_part", "chat_action", "chat_progress", "chat_runtime", "chat_room", "chat_meta", "chat_flow_action", "chat_flow_prompt", "chat_flow_choice", "chat_flow_note", "chat_question_action", "chat_question_prompt", "chat_ask_action", "chat_message_ref", "chat_note_draft", "chat_digest"];
|
|
13
|
+
export type ChatTable = (typeof CHAT_TABLES)[number];
|
|
@@ -1,129 +1,197 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
2
|
+
* The one set of chat tables every chat app shares (v116): Telegram, Slack, Discord and Teams keep their pairings,
|
|
3
|
+
* received events, planned message parts, buttons, rooms and delivery receipts here, each row keyed by `provider`.
|
|
4
|
+
* A row's identity is (provider, id): ids carried over from the per-app tables keep their numbers, and nothing infers
|
|
5
|
+
* the app from an id. A leaf: it imports nothing, so the store creates these tables without loading the chat modules.
|
|
4
6
|
*/
|
|
5
|
-
const
|
|
7
|
+
export const CHAT_PROVIDERS = ["telegram", "slack", "discord", "teams"];
|
|
8
|
+
export const isChatProvider = (value) => CHAT_PROVIDERS.includes(value);
|
|
9
|
+
const PROVIDER = `provider TEXT NOT NULL CHECK (provider IN (${CHAT_PROVIDERS.map(one => `'${one}'`).join(",")}))`;
|
|
10
|
+
export const CHAT_SCHEMA = `
|
|
11
|
+
-- One person's chat in one app, speaking as one approver generation. Revoked, never deleted.
|
|
12
|
+
-- installation: the bot (Telegram) or workspace app; member: the app's user id; channel: their private chat.
|
|
6
13
|
CREATE TABLE IF NOT EXISTS chat_binding (
|
|
7
|
-
id INTEGER
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
|
|
14
|
+
${PROVIDER}, id INTEGER NOT NULL, installation TEXT NOT NULL, team TEXT NOT NULL, app TEXT NOT NULL,
|
|
15
|
+
member TEXT NOT NULL, channel TEXT NOT NULL, approver TEXT NOT NULL, generation INTEGER NOT NULL,
|
|
16
|
+
created TEXT NOT NULL, created_by TEXT, pair_event TEXT, revoked TEXT, revoked_by TEXT,
|
|
17
|
+
PRIMARY KEY (provider, id)
|
|
18
|
+
);
|
|
19
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_binding_live ON chat_binding(provider, installation, member) WHERE revoked IS NULL;
|
|
20
|
+
CREATE INDEX IF NOT EXISTS chat_binding_approver ON chat_binding(provider, approver) WHERE revoked IS NULL;
|
|
21
|
+
-- One-time pairing codes, by hash. installation NULL: any installation of the app (a Telegram code works on its bot).
|
|
12
22
|
CREATE TABLE IF NOT EXISTS chat_pair (
|
|
13
|
-
hash TEXT
|
|
14
|
-
|
|
23
|
+
${PROVIDER}, hash TEXT NOT NULL, installation TEXT, approver TEXT NOT NULL, generation INTEGER NOT NULL,
|
|
24
|
+
created TEXT, created_by TEXT, expires TEXT NOT NULL, consumed TEXT, consumed_channel TEXT, consumed_member TEXT, consumed_event TEXT,
|
|
25
|
+
PRIMARY KEY (provider, hash)
|
|
15
26
|
);
|
|
27
|
+
-- Everything an app sent us, once each (the key is the idempotency). kind 'update' is an applied (or pushed and
|
|
28
|
+
-- waiting) Telegram update; 'message' is a message the lead answers, queued to running to done or failed.
|
|
29
|
+
-- session: the lead session its turn was dispatched under, a pointer to its receipt (never an authority).
|
|
16
30
|
CREATE TABLE IF NOT EXISTS chat_event (
|
|
17
|
-
id TEXT
|
|
18
|
-
kind TEXT NOT NULL CHECK(kind IN ('message','action','pair','notice')),
|
|
31
|
+
${PROVIDER}, id TEXT NOT NULL, installation TEXT NOT NULL, binding INTEGER,
|
|
32
|
+
kind TEXT NOT NULL CHECK (kind IN ('message','action','pair','notice','update')),
|
|
19
33
|
channel TEXT NOT NULL, member TEXT NOT NULL, ts TEXT NOT NULL, thread TEXT NOT NULL,
|
|
20
|
-
payload TEXT NOT NULL, created TEXT NOT NULL,
|
|
21
|
-
|
|
22
|
-
next_at TEXT, problem TEXT
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
payload TEXT NOT NULL, created TEXT NOT NULL, session INTEGER,
|
|
35
|
+
state TEXT NOT NULL DEFAULT 'queued' CHECK (state IN ('queued','running','done','failed','dropped')),
|
|
36
|
+
next_at TEXT, problem TEXT, claim_owner TEXT, claim_until TEXT, attempts INTEGER NOT NULL DEFAULT 0,
|
|
37
|
+
turn INTEGER, started TEXT, finished TEXT, result TEXT, reply TEXT,
|
|
38
|
+
PRIMARY KEY (provider, id),
|
|
39
|
+
FOREIGN KEY (provider, binding) REFERENCES chat_binding(provider, id)
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS chat_event_pending ON chat_event(provider, installation, state, next_at);
|
|
42
|
+
CREATE INDEX IF NOT EXISTS chat_event_binding ON chat_event(provider, binding, state);
|
|
43
|
+
-- What we send, planned before any send and marked sent only on the app's own message id.
|
|
25
44
|
CREATE TABLE IF NOT EXISTS chat_part (
|
|
26
|
-
id INTEGER
|
|
27
|
-
|
|
45
|
+
${PROVIDER}, id INTEGER NOT NULL, event TEXT NOT NULL, ordinal INTEGER NOT NULL, payload TEXT NOT NULL,
|
|
46
|
+
state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending','sent','dropped')),
|
|
28
47
|
message TEXT, file TEXT, uploaded INTEGER NOT NULL DEFAULT 0, attempts INTEGER NOT NULL DEFAULT 0,
|
|
29
|
-
uncertain INTEGER NOT NULL DEFAULT 0, next_at TEXT, problem TEXT, created TEXT NOT NULL,
|
|
30
|
-
UNIQUE(event,ordinal)
|
|
31
|
-
)
|
|
48
|
+
uncertain INTEGER NOT NULL DEFAULT 0, next_at TEXT, problem TEXT, created TEXT NOT NULL, sent TEXT,
|
|
49
|
+
PRIMARY KEY (provider, id), UNIQUE (provider, event, ordinal),
|
|
50
|
+
FOREIGN KEY (provider, event) REFERENCES chat_event(provider, id)
|
|
51
|
+
);
|
|
52
|
+
CREATE INDEX IF NOT EXISTS chat_part_pending ON chat_part(provider, state, next_at);
|
|
53
|
+
CREATE INDEX IF NOT EXISTS chat_part_message ON chat_part(provider, message);
|
|
54
|
+
-- A lead proposal's buttons (proposal), or a builder decision's (decision, option_id), one opaque token each.
|
|
55
|
+
-- A button rides its planned part, or (Telegram) the binding, chat and message it was placed on.
|
|
32
56
|
CREATE TABLE IF NOT EXISTS chat_action (
|
|
33
|
-
token TEXT
|
|
34
|
-
proposal INTEGER
|
|
35
|
-
|
|
36
|
-
)
|
|
57
|
+
${PROVIDER}, token TEXT NOT NULL, part INTEGER, binding INTEGER, chat TEXT, message TEXT,
|
|
58
|
+
proposal INTEGER REFERENCES mate_proposal(id) ON DELETE CASCADE,
|
|
59
|
+
decision INTEGER REFERENCES decision(id) ON DELETE CASCADE, option_id TEXT, note_digest TEXT,
|
|
60
|
+
phase TEXT NOT NULL CHECK (phase IN ('confirm','dismiss','yes','cancel','choose')),
|
|
61
|
+
created TEXT, expires TEXT, consumed TEXT,
|
|
62
|
+
PRIMARY KEY (provider, token),
|
|
63
|
+
CHECK ((proposal IS NULL) <> (decision IS NULL)),
|
|
64
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id)
|
|
65
|
+
);
|
|
66
|
+
CREATE INDEX IF NOT EXISTS chat_action_part ON chat_action(provider, part);
|
|
67
|
+
CREATE INDEX IF NOT EXISTS chat_action_proposal ON chat_action(proposal);
|
|
68
|
+
CREATE INDEX IF NOT EXISTS chat_action_decision ON chat_action(decision);
|
|
37
69
|
CREATE TABLE IF NOT EXISTS chat_progress (
|
|
38
|
-
binding INTEGER NOT NULL
|
|
39
|
-
|
|
40
|
-
|
|
70
|
+
${PROVIDER}, binding INTEGER NOT NULL, run INTEGER NOT NULL REFERENCES run(id), part INTEGER NOT NULL, digest TEXT NOT NULL,
|
|
71
|
+
PRIMARY KEY (provider, binding, run),
|
|
72
|
+
FOREIGN KEY (provider, binding) REFERENCES chat_binding(provider, id),
|
|
73
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id)
|
|
41
74
|
);
|
|
75
|
+
-- One live worker per installation (lease, its generation and the poll cursor), its connection and retry state,
|
|
76
|
+
-- the newest notification its notices started from, and where (Telegram) pushes updates.
|
|
42
77
|
CREATE TABLE IF NOT EXISTS chat_runtime (
|
|
43
|
-
installation TEXT
|
|
44
|
-
|
|
78
|
+
${PROVIDER}, installation TEXT NOT NULL, owner TEXT, lease_until TEXT, generation INTEGER NOT NULL DEFAULT 0,
|
|
79
|
+
cursor INTEGER NOT NULL DEFAULT 0, heartbeat TEXT, connected TEXT, problem TEXT, retry_at TEXT,
|
|
80
|
+
notification INTEGER NOT NULL DEFAULT 0, push_url TEXT, push_at TEXT, push_problem TEXT,
|
|
81
|
+
PRIMARY KEY (provider, installation)
|
|
45
82
|
);
|
|
46
|
-
|
|
47
|
-
/** v73: a chat's place in the shared team conversations — a channel follows one
|
|
48
|
-
* conversation, a DM may select one. Rows are revoked, never deleted. */
|
|
49
|
-
const CHAT_ROOM_SCHEMA = `
|
|
83
|
+
-- A chat's place in the shared team conversations: a group follows one conversation, a private chat may select one.
|
|
50
84
|
CREATE TABLE IF NOT EXISTS chat_room (
|
|
51
|
-
id INTEGER
|
|
52
|
-
kind TEXT NOT NULL CHECK(kind IN ('group','private')), conversation TEXT NOT NULL,
|
|
53
|
-
binding INTEGER NOT NULL
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
CREATE UNIQUE INDEX IF NOT EXISTS
|
|
85
|
+
${PROVIDER}, id INTEGER NOT NULL, installation TEXT NOT NULL, chat TEXT NOT NULL,
|
|
86
|
+
kind TEXT NOT NULL CHECK (kind IN ('group','private')), conversation TEXT NOT NULL REFERENCES team_conversation(id),
|
|
87
|
+
binding INTEGER NOT NULL, bound_by TEXT NOT NULL, bound TEXT NOT NULL, cursor INTEGER NOT NULL DEFAULT 0,
|
|
88
|
+
revoked TEXT, revoked_by TEXT,
|
|
89
|
+
PRIMARY KEY (provider, id),
|
|
90
|
+
FOREIGN KEY (provider, binding) REFERENCES chat_binding(provider, id)
|
|
91
|
+
);
|
|
92
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_room_live ON chat_room(provider, installation, chat) WHERE revoked IS NULL;
|
|
93
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_room_group ON chat_room(provider, conversation) WHERE revoked IS NULL AND kind = 'group';
|
|
94
|
+
-- Small transport facts an app must remember per chat (a Teams service URL). Never credentials.
|
|
59
95
|
CREATE TABLE IF NOT EXISTS chat_meta (
|
|
60
|
-
installation TEXT NOT NULL, key TEXT NOT NULL, value TEXT NOT NULL, updated TEXT NOT NULL,
|
|
61
|
-
PRIMARY KEY(installation, key)
|
|
96
|
+
${PROVIDER}, installation TEXT NOT NULL, key TEXT NOT NULL, value TEXT NOT NULL, updated TEXT NOT NULL,
|
|
97
|
+
PRIMARY KEY (provider, installation, key)
|
|
62
98
|
);
|
|
63
|
-
|
|
64
|
-
/** v88: flow decisions in the chat app, as on Telegram (telegram-flow.ts).
|
|
65
|
-
* A button is one opaque token for one visit (card, entry) of one card, on
|
|
66
|
-
* the part it rides; Edit and Send back open a prompt the person's next
|
|
67
|
-
* message in their DM answers. */
|
|
68
|
-
const CHAT_FLOW_SCHEMA = `
|
|
99
|
+
-- A flow decision's buttons (Approve, Edit, Send back, and the Yes or Cancel Approve arms) for one visit of one card.
|
|
69
100
|
CREATE TABLE IF NOT EXISTS chat_flow_action (
|
|
70
|
-
token TEXT
|
|
101
|
+
${PROVIDER}, token TEXT NOT NULL, part INTEGER, binding INTEGER, chat TEXT, message TEXT,
|
|
71
102
|
card INTEGER NOT NULL REFERENCES flow_card(id), entry INTEGER NOT NULL,
|
|
72
|
-
action TEXT NOT NULL CHECK(action IN ('approve','edit','send-back')),
|
|
103
|
+
action TEXT NOT NULL CHECK (action IN ('approve','edit','send-back','yes','cancel')),
|
|
104
|
+
created TEXT, expires TEXT NOT NULL, consumed TEXT,
|
|
105
|
+
PRIMARY KEY (provider, token),
|
|
106
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id)
|
|
73
107
|
);
|
|
74
108
|
CREATE INDEX IF NOT EXISTS chat_flow_action_visit ON chat_flow_action(card, entry);
|
|
109
|
+
CREATE INDEX IF NOT EXISTS chat_flow_action_part ON chat_flow_action(provider, part);
|
|
110
|
+
-- Edit and Send back wait for the person's next message (or, on Telegram, a reply to the prompt message).
|
|
75
111
|
CREATE TABLE IF NOT EXISTS chat_flow_prompt (
|
|
76
|
-
id INTEGER
|
|
112
|
+
${PROVIDER}, id INTEGER NOT NULL, binding INTEGER NOT NULL, chat TEXT, message TEXT,
|
|
77
113
|
card INTEGER NOT NULL REFERENCES flow_card(id), entry INTEGER NOT NULL,
|
|
78
|
-
mode TEXT NOT NULL CHECK(mode IN ('edit','send-back')), created TEXT NOT NULL, expires TEXT NOT NULL, consumed TEXT
|
|
114
|
+
mode TEXT NOT NULL CHECK (mode IN ('edit','send-back')), created TEXT NOT NULL, expires TEXT NOT NULL, consumed TEXT,
|
|
115
|
+
PRIMARY KEY (provider, id)
|
|
79
116
|
);
|
|
80
|
-
CREATE INDEX IF NOT EXISTS chat_flow_prompt_open ON chat_flow_prompt(binding, consumed);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* when sent) for one visit of one card, on the part it rides. A reply in that notice's thread is the note; chat_flow_note
|
|
84
|
-
* is "Use this as your note?" Yes / No about one other message (held: its event; words: what it said, kept only until
|
|
85
|
-
* answered, as an event's own payload is cleared once it is handled), asked once per visit.
|
|
86
|
-
* Never in CHAT_TABLES: an older database has no such table until this schema creates it. */
|
|
87
|
-
const CHAT_FLOW_CHOICE_SCHEMA = `
|
|
117
|
+
CREATE INDEX IF NOT EXISTS chat_flow_prompt_open ON chat_flow_prompt(provider, binding, consumed);
|
|
118
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_flow_prompt_message ON chat_flow_prompt(provider, chat, message) WHERE message IS NOT NULL;
|
|
119
|
+
-- A flow's "Person chooses" buttons: one per option (choice is its index, label its words when sent).
|
|
88
120
|
CREATE TABLE IF NOT EXISTS chat_flow_choice (
|
|
89
|
-
token TEXT
|
|
121
|
+
${PROVIDER}, token TEXT NOT NULL, part INTEGER, binding INTEGER, chat TEXT, message TEXT,
|
|
90
122
|
card INTEGER NOT NULL REFERENCES flow_card(id), entry INTEGER NOT NULL,
|
|
91
|
-
choice INTEGER NOT NULL, label TEXT NOT NULL, expires TEXT NOT NULL, consumed TEXT
|
|
123
|
+
choice INTEGER NOT NULL, label TEXT NOT NULL, created TEXT, expires TEXT NOT NULL, consumed TEXT,
|
|
124
|
+
PRIMARY KEY (provider, token),
|
|
125
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id)
|
|
92
126
|
);
|
|
93
127
|
CREATE INDEX IF NOT EXISTS chat_flow_choice_visit ON chat_flow_choice(card, entry);
|
|
128
|
+
CREATE INDEX IF NOT EXISTS chat_flow_choice_part ON chat_flow_choice(provider, part);
|
|
129
|
+
-- "Use this as your note?" Yes / No about the person's message held (its event; words kept only until answered).
|
|
94
130
|
CREATE TABLE IF NOT EXISTS chat_flow_note (
|
|
95
|
-
token TEXT
|
|
131
|
+
${PROVIDER}, token TEXT NOT NULL, part INTEGER NOT NULL,
|
|
96
132
|
card INTEGER NOT NULL REFERENCES flow_card(id), entry INTEGER NOT NULL,
|
|
97
|
-
held TEXT NOT NULL, words TEXT, answer TEXT NOT NULL CHECK(answer IN ('yes','no')), expires TEXT NOT NULL, consumed TEXT
|
|
133
|
+
held TEXT NOT NULL, words TEXT, answer TEXT NOT NULL CHECK (answer IN ('yes','no')), expires TEXT NOT NULL, consumed TEXT,
|
|
134
|
+
PRIMARY KEY (provider, token),
|
|
135
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id)
|
|
98
136
|
);
|
|
99
137
|
CREATE INDEX IF NOT EXISTS chat_flow_note_visit ON chat_flow_note(card, entry);
|
|
100
|
-
|
|
101
|
-
/** v93: a teammate's question in the chat app. One button per option (choice)
|
|
102
|
-
* and one to answer in words (choice NULL); that one opens a prompt the
|
|
103
|
-
* person's next message in their DM answers. Never in CHAT_TABLES: an older
|
|
104
|
-
* database has no such tables until this schema creates them. */
|
|
105
|
-
const CHAT_QUESTION_SCHEMA = `
|
|
138
|
+
-- A teammate's question: one button per option and one to answer in words (choice NULL).
|
|
106
139
|
CREATE TABLE IF NOT EXISTS chat_question_action (
|
|
107
|
-
token TEXT
|
|
108
|
-
question INTEGER NOT NULL REFERENCES teammate_question(id), choice TEXT, expires TEXT NOT NULL, consumed TEXT
|
|
140
|
+
${PROVIDER}, token TEXT NOT NULL, part INTEGER, binding INTEGER, chat TEXT, message TEXT,
|
|
141
|
+
question INTEGER NOT NULL REFERENCES teammate_question(id), choice TEXT, created TEXT, expires TEXT NOT NULL, consumed TEXT,
|
|
142
|
+
PRIMARY KEY (provider, token),
|
|
143
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id)
|
|
109
144
|
);
|
|
110
145
|
CREATE INDEX IF NOT EXISTS chat_question_action_question ON chat_question_action(question);
|
|
111
146
|
CREATE TABLE IF NOT EXISTS chat_question_prompt (
|
|
112
|
-
id INTEGER
|
|
113
|
-
question INTEGER NOT NULL REFERENCES teammate_question(id), created TEXT NOT NULL, expires TEXT NOT NULL, consumed TEXT
|
|
147
|
+
${PROVIDER}, id INTEGER NOT NULL, binding INTEGER NOT NULL, chat TEXT, message TEXT,
|
|
148
|
+
question INTEGER NOT NULL REFERENCES teammate_question(id), created TEXT NOT NULL, expires TEXT NOT NULL, consumed TEXT,
|
|
149
|
+
PRIMARY KEY (provider, id)
|
|
114
150
|
);
|
|
115
|
-
CREATE INDEX IF NOT EXISTS chat_question_prompt_open ON chat_question_prompt(binding, consumed);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* "Something else" (choice NULL). A tap sends the option as the owner's next message. Never in CHAT_TABLES. */
|
|
119
|
-
const CHAT_ASK_SCHEMA = `
|
|
151
|
+
CREATE INDEX IF NOT EXISTS chat_question_prompt_open ON chat_question_prompt(provider, binding, consumed);
|
|
152
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_question_prompt_message ON chat_question_prompt(provider, chat, message) WHERE message IS NOT NULL;
|
|
153
|
+
-- The lead's question to its owner (ask_owner): one button per option and one for "Something else" (choice NULL).
|
|
120
154
|
CREATE TABLE IF NOT EXISTS chat_ask_action (
|
|
121
|
-
token TEXT
|
|
122
|
-
|
|
155
|
+
${PROVIDER}, token TEXT NOT NULL, part INTEGER NOT NULL, turn INTEGER NOT NULL, choice INTEGER, expires TEXT NOT NULL, consumed TEXT,
|
|
156
|
+
PRIMARY KEY (provider, token),
|
|
157
|
+
FOREIGN KEY (provider, part) REFERENCES chat_part(provider, id) ON DELETE CASCADE
|
|
123
158
|
);
|
|
124
159
|
CREATE INDEX IF NOT EXISTS chat_ask_action_turn ON chat_ask_action(turn);
|
|
160
|
+
-- What one sent message carried, so a reply to it is about exactly that: a notification (kind 'notification', one row
|
|
161
|
+
-- per notification it showed), a builder decision ('decision') or the task a status showed ('task').
|
|
162
|
+
CREATE TABLE IF NOT EXISTS chat_message_ref (
|
|
163
|
+
${PROVIDER}, binding INTEGER NOT NULL, chat TEXT NOT NULL, message TEXT NOT NULL,
|
|
164
|
+
kind TEXT NOT NULL CHECK (kind IN ('notification','decision','task')),
|
|
165
|
+
notification INTEGER REFERENCES notification(id), destination TEXT, project TEXT,
|
|
166
|
+
task_ref INTEGER REFERENCES task_ref(id), task_id TEXT, run INTEGER,
|
|
167
|
+
decision INTEGER REFERENCES decision(id) ON DELETE CASCADE, created TEXT NOT NULL,
|
|
168
|
+
CHECK ((kind = 'notification') = (notification IS NOT NULL AND destination IS NOT NULL)),
|
|
169
|
+
CHECK ((kind = 'decision') = (decision IS NOT NULL)),
|
|
170
|
+
CHECK (kind <> 'task' OR task_id IS NOT NULL)
|
|
171
|
+
);
|
|
172
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_message_ref_notification ON chat_message_ref(provider, binding, chat, message, notification) WHERE kind = 'notification';
|
|
173
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_message_ref_one ON chat_message_ref(provider, binding, chat, message, kind) WHERE kind <> 'notification';
|
|
174
|
+
CREATE INDEX IF NOT EXISTS chat_message_ref_destination ON chat_message_ref(destination, notification);
|
|
175
|
+
CREATE INDEX IF NOT EXISTS chat_message_ref_task ON chat_message_ref(destination, task_ref) WHERE kind = 'notification';
|
|
176
|
+
-- A note typed as a reply to a builder decision, held until a tap answers with it. Only a later event replaces it.
|
|
177
|
+
CREATE TABLE IF NOT EXISTS chat_note_draft (
|
|
178
|
+
${PROVIDER}, id INTEGER NOT NULL, binding INTEGER NOT NULL,
|
|
179
|
+
decision INTEGER NOT NULL REFERENCES decision(id) ON DELETE CASCADE, event INTEGER NOT NULL,
|
|
180
|
+
message TEXT NOT NULL, reply_to TEXT NOT NULL, note TEXT NOT NULL,
|
|
181
|
+
state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending','armed','superseded','consumed','discarded')),
|
|
182
|
+
created TEXT NOT NULL, expires TEXT NOT NULL,
|
|
183
|
+
PRIMARY KEY (provider, id),
|
|
184
|
+
FOREIGN KEY (provider, binding) REFERENCES chat_binding(provider, id)
|
|
185
|
+
);
|
|
186
|
+
CREATE UNIQUE INDEX IF NOT EXISTS chat_note_draft_live ON chat_note_draft(provider, binding, decision) WHERE state IN ('pending','armed');
|
|
187
|
+
-- Away mode: routine facts wait and go as one digest every every_ms (null: each fact as it lands).
|
|
188
|
+
CREATE TABLE IF NOT EXISTS chat_digest (
|
|
189
|
+
${PROVIDER}, every_ms INTEGER, set_by TEXT, set_at TEXT, last_sent_at TEXT,
|
|
190
|
+
PRIMARY KEY (provider)
|
|
191
|
+
);
|
|
125
192
|
`;
|
|
126
|
-
|
|
193
|
+
/** Every shared chat table, parents before children. */
|
|
194
|
+
export const CHAT_TABLES = [
|
|
127
195
|
"chat_binding",
|
|
128
196
|
"chat_pair",
|
|
129
197
|
"chat_event",
|
|
@@ -131,6 +199,16 @@ const CHAT_TABLES = [
|
|
|
131
199
|
"chat_action",
|
|
132
200
|
"chat_progress",
|
|
133
201
|
"chat_runtime",
|
|
202
|
+
"chat_room",
|
|
203
|
+
"chat_meta",
|
|
204
|
+
"chat_flow_action",
|
|
205
|
+
"chat_flow_prompt",
|
|
206
|
+
"chat_flow_choice",
|
|
207
|
+
"chat_flow_note",
|
|
208
|
+
"chat_question_action",
|
|
209
|
+
"chat_question_prompt",
|
|
210
|
+
"chat_ask_action",
|
|
211
|
+
"chat_message_ref",
|
|
212
|
+
"chat_note_draft",
|
|
213
|
+
"chat_digest",
|
|
134
214
|
];
|
|
135
|
-
export const chatSchema = (channel) => (CHAT_SCHEMA + CHAT_ROOM_SCHEMA + CHAT_FLOW_SCHEMA + CHAT_FLOW_CHOICE_SCHEMA + CHAT_QUESTION_SCHEMA + CHAT_ASK_SCHEMA).replaceAll("chat_", `${channel}_`);
|
|
136
|
-
export const chatTables = (channel) => CHAT_TABLES.map((name) => name.replace("chat_", `${channel}_`));
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* message whose button can't be read is answered with why (`data.custom_id: not a Toolroll button`), and nothing is done.
|
|
6
6
|
*/
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { CHAT_BUTTON_TOKEN } from "./chat-content.js";
|
|
8
9
|
import { parseContract } from "./contract.js";
|
|
9
10
|
const user = z.object({ id: z.string() });
|
|
10
11
|
/** The interaction around a tap (type 3: a message component): the app, the person, the channel, the message. */
|
|
@@ -22,7 +23,7 @@ export const discordComponentInteractionSchema = z.object({
|
|
|
22
23
|
});
|
|
23
24
|
/** Toolroll's button data: `so_` and a one-time token. */
|
|
24
25
|
export const discordButtonSchema = z.object({
|
|
25
|
-
custom_id: z.string().regex(
|
|
26
|
+
custom_id: z.string().regex(new RegExp(`^so_${CHAT_BUTTON_TOKEN.source.slice(1)}`), { error: "not a Toolroll button" }),
|
|
26
27
|
});
|
|
27
28
|
export function readDiscordComponentInteraction(body) {
|
|
28
29
|
return parseContract(discordComponentInteractionSchema, body);
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { parseContract } from "./contract.js";
|
|
9
|
+
import { CHAT_BUTTON_TOKEN } from "./chat-content.js";
|
|
9
10
|
/** Toolroll's buttons: toolroll_* since the rename; standing_orders_* buttons on older messages still work. */
|
|
10
|
-
export const SLACK_BUTTON_ACTION = /^(?:toolroll|standing_orders)_(?:confirm|dismiss|yes|cancel|flow_approve|flow_edit|flow_send_back|flow_choose_[0-3]|flow_note_(?:yes|no)|question_choice|question_words)$/;
|
|
11
|
+
export const SLACK_BUTTON_ACTION = /^(?:toolroll|standing_orders)_(?:confirm|dismiss|yes|cancel|flow_approve|flow_edit|flow_send_back|flow_choose_[0-3]|flow_note_(?:yes|no)|question_choice|question_words|decide_[0-9]{1,2})$/;
|
|
11
12
|
/** A link button opens its page in Slack's own client; Slack still reports the tap, and there is nothing to do. */
|
|
12
13
|
export const SLACK_LINK_ACTION = /^(?:toolroll|standing_orders)_link(?:_[0-9]+)?$/;
|
|
13
|
-
const token = z.string().regex(
|
|
14
|
+
const token = z.string().regex(CHAT_BUTTON_TOKEN, { error: "must be a Toolroll button token" });
|
|
14
15
|
/** The interaction around a tap: who, and the message the button is on. */
|
|
15
16
|
export const slackBlockActionsSchema = z.object({
|
|
16
17
|
type: z.literal("block_actions"),
|
|
@@ -155,10 +155,6 @@ declare const STORE_COLUMN_VALUES: {
|
|
|
155
155
|
note: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
156
156
|
}, z.core.$loose>>;
|
|
157
157
|
}, z.core.$loose>;
|
|
158
|
-
readonly "telegram_conversation_part.keyboard_json": z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
159
|
-
text: z.ZodString;
|
|
160
|
-
callback_data: z.ZodString;
|
|
161
|
-
}, z.core.$loose>>>;
|
|
162
158
|
readonly "publication_grant.capabilities": z.ZodArray<z.ZodEnum<{
|
|
163
159
|
"open-pr": "open-pr";
|
|
164
160
|
"push-branch": "push-branch";
|
|
@@ -254,7 +250,7 @@ declare const STORE_COLUMN_VALUES: {
|
|
|
254
250
|
export type StoreColumn = keyof typeof STORE_COLUMN_VALUES;
|
|
255
251
|
export type StoreColumnValue<C extends StoreColumn> = z.infer<(typeof STORE_COLUMN_VALUES)[C]>;
|
|
256
252
|
/** Every JSON column the store reads itself, by `table.column`. */
|
|
257
|
-
export declare const STORE_COLUMNS: ("approval_policy.protected_paths" | "backend_grant.mutations" | "backend_grant.paths" | "coordinator_proposal.outcome_json" | "coordinator_proposal.payload_json" | "criterion_review.screenshots_json" | "decision.options" | "flow_card.source_json" | "flow_comment.mentions_json" | "lead_config.about_json" | "mate_ask.options_json" | "mate_proposal.outcome_json" | "mate_proposal.payload_json" | "mutation.result" | "operating_mode.terms_json" | "plan_revision.changed_fields" | "proof_verdict.matrix_json" | "proof_verdict.reasons_json" | "publication_grant.capabilities" | "repair_chain.unresolved_json" | "run_check.suites_json" | "run_checkpoint.snapshot_json" | "run_tool.tools_json" | "runner.agents" | "runner.repos" | "task_ref.capability_requirements" | "task_ref.zones" | "task_scope.acceptance_json" | "task_scope.touches" | "teammate_call.input_json" | "teammate_event.detail_json" | "teammate_question.options_json" | "teammate_suggestion.evidence_json" | "teammate_suggestion.rule_json" | "teammate_suggestion.was_json" | "teammate_tool.actions_json" | "teammate_tool.rules_json" | "
|
|
253
|
+
export declare const STORE_COLUMNS: ("approval_policy.protected_paths" | "backend_grant.mutations" | "backend_grant.paths" | "coordinator_proposal.outcome_json" | "coordinator_proposal.payload_json" | "criterion_review.screenshots_json" | "decision.options" | "flow_card.source_json" | "flow_comment.mentions_json" | "lead_config.about_json" | "mate_ask.options_json" | "mate_proposal.outcome_json" | "mate_proposal.payload_json" | "mutation.result" | "operating_mode.terms_json" | "plan_revision.changed_fields" | "proof_verdict.matrix_json" | "proof_verdict.reasons_json" | "publication_grant.capabilities" | "repair_chain.unresolved_json" | "run_check.suites_json" | "run_checkpoint.snapshot_json" | "run_tool.tools_json" | "runner.agents" | "runner.repos" | "task_ref.capability_requirements" | "task_ref.zones" | "task_scope.acceptance_json" | "task_scope.touches" | "teammate_call.input_json" | "teammate_event.detail_json" | "teammate_question.options_json" | "teammate_suggestion.evidence_json" | "teammate_suggestion.rule_json" | "teammate_suggestion.was_json" | "teammate_tool.actions_json" | "teammate_tool.rules_json" | "tool_seal.tools_json")[];
|
|
258
254
|
/** A SQL projection, not a physical column; replay it separately after its owning column. */
|
|
259
255
|
export declare const STORE_PROJECTIONS: readonly ["run_tool.tools_json.fence"];
|
|
260
256
|
/** These readers historically only parsed JSON. Shape errors must not change their values or catch boundaries. */
|
|
@@ -16,7 +16,6 @@ import { decisionOptionSchema } from "./decision.js";
|
|
|
16
16
|
import { scopeTermsSchema, storedRubricSchema } from "./scope.js";
|
|
17
17
|
import { criterionEvidenceSchema, proofCriterionSchema } from "./proof.js";
|
|
18
18
|
import { sharedActionSchema } from "./chat-actions.js";
|
|
19
|
-
import { telegramCallbackButtonSchema } from "./telegram-callback.js";
|
|
20
19
|
import { readVersioned, versioned } from "./contract.js";
|
|
21
20
|
/** Dynamic tool arguments, event details and operation results have no common field contract. */
|
|
22
21
|
const savedObject = z.looseObject({});
|
|
@@ -53,7 +52,6 @@ const savedProgressSchema = z.looseObject({
|
|
|
53
52
|
id: z.string(), state: z.enum(["pending", "current", "completed", "blocked"]), note: z.string().nullable().optional(),
|
|
54
53
|
})),
|
|
55
54
|
});
|
|
56
|
-
const savedKeyboardSchema = z.array(z.array(telegramCallbackButtonSchema.extend({ callback_data: z.string() }).loose()));
|
|
57
55
|
const savedMatrixRowSchema = proofCriterionSchema.pick({ id: true, statement: true }).extend({
|
|
58
56
|
id: z.string(), statement: z.string(), requiredEvidence: savedList, state: z.string(), detail: savedList,
|
|
59
57
|
answered: z.array(criterionEvidenceSchema.extend({ ref: z.string() }).loose()).optional(),
|
|
@@ -88,7 +86,6 @@ const STORE_COLUMN_VALUES = {
|
|
|
88
86
|
"mutation.result": z.unknown(),
|
|
89
87
|
"plan_revision.changed_fields": z.array(z.string()),
|
|
90
88
|
"run_checkpoint.snapshot_json": savedProgressSchema,
|
|
91
|
-
"telegram_conversation_part.keyboard_json": savedKeyboardSchema,
|
|
92
89
|
"publication_grant.capabilities": z.array(z.enum(["push-branch", "open-pr"])),
|
|
93
90
|
"task_ref.zones": savedList,
|
|
94
91
|
"task_ref.capability_requirements": savedList,
|
|
@@ -115,7 +112,7 @@ export const LEGACY_JSON_COLUMNS = [
|
|
|
115
112
|
"teammate_event.detail_json", "task_scope.touches", "task_scope.acceptance_json",
|
|
116
113
|
"operating_mode.terms_json", "decision.options", "run_tool.tools_json",
|
|
117
114
|
"run_tool.tools_json.fence", "mate_ask.options_json", "mutation.result", "plan_revision.changed_fields",
|
|
118
|
-
"run_checkpoint.snapshot_json", "
|
|
115
|
+
"run_checkpoint.snapshot_json", "publication_grant.capabilities",
|
|
119
116
|
"coordinator_proposal.payload_json", "coordinator_proposal.outcome_json",
|
|
120
117
|
"mate_proposal.payload_json", "mate_proposal.outcome_json",
|
|
121
118
|
];
|