@crasi/bisque-spec 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +23 -2
- package/dist/index.js +1404 -0
- package/dist/index.js.map +7 -0
- package/dist/types/adjust.d.ts +31 -0
- package/dist/types/args.d.ts +11 -0
- package/dist/types/artifact.d.ts +33 -0
- package/dist/types/automation.d.ts +336 -0
- package/dist/types/catalog.d.ts +7 -0
- package/dist/types/describe.d.ts +32 -0
- package/dist/types/diagnostics.d.ts +50 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/migrate.d.ts +8 -0
- package/dist/types/protocol.d.ts +1025 -0
- package/dist/types/schema.d.ts +2536 -0
- package/dist/types/template.d.ts +870 -0
- package/dist/types/theme.d.ts +33 -0
- package/dist/types/validate.d.ts +36 -0
- package/package.json +47 -3
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Problem, type Role } from "@crasi/bisque-core";
|
|
3
|
+
import { type ContractManifest } from "@crasi/bisque-contract";
|
|
4
|
+
import { type Column, type IR, type QueryResult, type Row } from "@crasi/bisque-ir";
|
|
5
|
+
import { type ArgExpr, type Draft } from "./schema.js";
|
|
6
|
+
/**
|
|
7
|
+
* Automations: saved rules the host runs on its own server, on a schedule.
|
|
8
|
+
* "Every morning, email me critical cards that have been open for more than
|
|
9
|
+
* a week." An automation is data, like a spec: a query (what to look for),
|
|
10
|
+
* a schedule (when to look), and what to do: tell the owner on a channel the
|
|
11
|
+
* host declared, call an intent the host marked `automate`, or a short
|
|
12
|
+
* workflow of several intents per row followed by one message.
|
|
13
|
+
*
|
|
14
|
+
* Custody is unchanged. The model proposes the rule from the contract; the
|
|
15
|
+
* host's scheduler loads rows, runs the query and delivers, and the rows
|
|
16
|
+
* never leave the host. Delivery is always to the automation's owner: the
|
|
17
|
+
* rule names a channel, never an address.
|
|
18
|
+
*/
|
|
19
|
+
export declare const WEEKDAYS: readonly ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
20
|
+
export type Weekday = (typeof WEEKDAYS)[number];
|
|
21
|
+
export declare const ScheduleSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
22
|
+
every: z.ZodLiteral<"hour">;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
every: z.ZodLiteral<"day">;
|
|
25
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
27
|
+
every: z.ZodLiteral<"weekday">;
|
|
28
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
30
|
+
every: z.ZodLiteral<"week">;
|
|
31
|
+
on: z.ZodEnum<{
|
|
32
|
+
fri: "fri";
|
|
33
|
+
mon: "mon";
|
|
34
|
+
sat: "sat";
|
|
35
|
+
sun: "sun";
|
|
36
|
+
thu: "thu";
|
|
37
|
+
tue: "tue";
|
|
38
|
+
wed: "wed";
|
|
39
|
+
}>;
|
|
40
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
42
|
+
every: z.ZodLiteral<"month">;
|
|
43
|
+
day: z.ZodNumber;
|
|
44
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
}, z.core.$strict>], "every">;
|
|
46
|
+
export type Schedule = z.infer<typeof ScheduleSchema>;
|
|
47
|
+
export declare const AutomationActionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
48
|
+
notify: z.ZodString;
|
|
49
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
50
|
+
intent: z.ZodString;
|
|
51
|
+
args: z.ZodRecord<z.ZodString, z.ZodType<ArgExpr, unknown, z.core.$ZodTypeInternals<ArgExpr, unknown>>>;
|
|
52
|
+
}, z.core.$strict>]>;
|
|
53
|
+
export type AutomationAction = z.infer<typeof AutomationActionSchema>;
|
|
54
|
+
/** Most steps in one workflow. */
|
|
55
|
+
export declare const MAX_STEPS = 4;
|
|
56
|
+
/**
|
|
57
|
+
* One action, or a workflow: intents run in order for each row, a row moves
|
|
58
|
+
* on only when the step before it succeeded, and an optional last `notify`
|
|
59
|
+
* reports the rows that made it through every step.
|
|
60
|
+
*/
|
|
61
|
+
export declare const AutomationThenSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
|
|
62
|
+
notify: z.ZodString;
|
|
63
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
64
|
+
intent: z.ZodString;
|
|
65
|
+
args: z.ZodRecord<z.ZodString, z.ZodType<ArgExpr, unknown, z.core.$ZodTypeInternals<ArgExpr, unknown>>>;
|
|
66
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
67
|
+
notify: z.ZodString;
|
|
68
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
69
|
+
intent: z.ZodString;
|
|
70
|
+
args: z.ZodRecord<z.ZodString, z.ZodType<ArgExpr, unknown, z.core.$ZodTypeInternals<ArgExpr, unknown>>>;
|
|
71
|
+
}, z.core.$strict>]>>]>;
|
|
72
|
+
/** An automation's steps as a list, whichever form `then` was written in. */
|
|
73
|
+
export declare function automationSteps(a: Pick<Automation, "then">): AutomationAction[];
|
|
74
|
+
export declare const AutomationSchema: z.ZodObject<{
|
|
75
|
+
kind: z.ZodLiteral<"automation">;
|
|
76
|
+
title: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
77
|
+
schedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
78
|
+
every: z.ZodLiteral<"hour">;
|
|
79
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
80
|
+
every: z.ZodLiteral<"day">;
|
|
81
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
83
|
+
every: z.ZodLiteral<"weekday">;
|
|
84
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
86
|
+
every: z.ZodLiteral<"week">;
|
|
87
|
+
on: z.ZodEnum<{
|
|
88
|
+
fri: "fri";
|
|
89
|
+
mon: "mon";
|
|
90
|
+
sat: "sat";
|
|
91
|
+
sun: "sun";
|
|
92
|
+
thu: "thu";
|
|
93
|
+
tue: "tue";
|
|
94
|
+
wed: "wed";
|
|
95
|
+
}>;
|
|
96
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
98
|
+
every: z.ZodLiteral<"month">;
|
|
99
|
+
day: z.ZodNumber;
|
|
100
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
101
|
+
}, z.core.$strict>], "every">;
|
|
102
|
+
data: z.ZodObject<{
|
|
103
|
+
scan: z.ZodString;
|
|
104
|
+
join: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
105
|
+
on: z.ZodString;
|
|
106
|
+
to: z.ZodString;
|
|
107
|
+
}, z.core.$strict>>>;
|
|
108
|
+
where: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodTuple<[z.ZodString, z.ZodEnum<{
|
|
109
|
+
"!=": "!=";
|
|
110
|
+
"<": "<";
|
|
111
|
+
"<=": "<=";
|
|
112
|
+
"=": "=";
|
|
113
|
+
">": ">";
|
|
114
|
+
">=": ">=";
|
|
115
|
+
in: "in";
|
|
116
|
+
match: "match";
|
|
117
|
+
notIn: "notIn";
|
|
118
|
+
}>, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, z.ZodObject<{
|
|
119
|
+
param: z.ZodString;
|
|
120
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
121
|
+
today: z.ZodNumber;
|
|
122
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, z.ZodObject<{
|
|
123
|
+
param: z.ZodString;
|
|
124
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
125
|
+
today: z.ZodNumber;
|
|
126
|
+
}, z.core.$strict>]>>]>], null>, z.ZodTuple<[z.ZodString, z.ZodEnum<{
|
|
127
|
+
isNull: "isNull";
|
|
128
|
+
notNull: "notNull";
|
|
129
|
+
}>], null>]>>>;
|
|
130
|
+
groupBy: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
131
|
+
measures: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
132
|
+
as: z.ZodString;
|
|
133
|
+
sum: z.ZodString;
|
|
134
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
135
|
+
as: z.ZodString;
|
|
136
|
+
avg: z.ZodString;
|
|
137
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
138
|
+
as: z.ZodString;
|
|
139
|
+
min: z.ZodString;
|
|
140
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
141
|
+
as: z.ZodString;
|
|
142
|
+
max: z.ZodString;
|
|
143
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
144
|
+
as: z.ZodString;
|
|
145
|
+
count: z.ZodString;
|
|
146
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
147
|
+
as: z.ZodString;
|
|
148
|
+
countDistinct: z.ZodString;
|
|
149
|
+
}, z.core.$strict>]>>>;
|
|
150
|
+
select: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
151
|
+
orderBy: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodEnum<{
|
|
152
|
+
asc: "asc";
|
|
153
|
+
desc: "desc";
|
|
154
|
+
}>], null>>>;
|
|
155
|
+
limit: z.ZodNumber;
|
|
156
|
+
}, z.core.$strict>;
|
|
157
|
+
when: z.ZodEnum<{
|
|
158
|
+
always: "always";
|
|
159
|
+
rows: "rows";
|
|
160
|
+
}>;
|
|
161
|
+
repeat: z.ZodEnum<{
|
|
162
|
+
all: "all";
|
|
163
|
+
new: "new";
|
|
164
|
+
}>;
|
|
165
|
+
key: z.ZodOptional<z.ZodString>;
|
|
166
|
+
columns: z.ZodArray<z.ZodObject<{
|
|
167
|
+
field: z.ZodString;
|
|
168
|
+
label: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
169
|
+
format: z.ZodOptional<z.ZodEnum<{
|
|
170
|
+
date: "date";
|
|
171
|
+
money: "money";
|
|
172
|
+
month: "month";
|
|
173
|
+
number: "number";
|
|
174
|
+
percent: "percent";
|
|
175
|
+
text: "text";
|
|
176
|
+
}>>;
|
|
177
|
+
}, z.core.$strict>>;
|
|
178
|
+
then: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
|
|
179
|
+
notify: z.ZodString;
|
|
180
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
181
|
+
intent: z.ZodString;
|
|
182
|
+
args: z.ZodRecord<z.ZodString, z.ZodType<ArgExpr, unknown, z.core.$ZodTypeInternals<ArgExpr, unknown>>>;
|
|
183
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
184
|
+
notify: z.ZodString;
|
|
185
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
186
|
+
intent: z.ZodString;
|
|
187
|
+
args: z.ZodRecord<z.ZodString, z.ZodType<ArgExpr, unknown, z.core.$ZodTypeInternals<ArgExpr, unknown>>>;
|
|
188
|
+
}, z.core.$strict>]>>]>;
|
|
189
|
+
manifest: z.ZodObject<{
|
|
190
|
+
reads: z.ZodArray<z.ZodString>;
|
|
191
|
+
acts: z.ZodArray<z.ZodString>;
|
|
192
|
+
channels: z.ZodArray<z.ZodString>;
|
|
193
|
+
}, z.core.$strict>;
|
|
194
|
+
}, z.core.$strict>;
|
|
195
|
+
export type Automation = z.infer<typeof AutomationSchema>;
|
|
196
|
+
export type AutomationValidation = {
|
|
197
|
+
ok: boolean;
|
|
198
|
+
problems: Problem[];
|
|
199
|
+
automation?: Automation;
|
|
200
|
+
columns: Record<string, Column>;
|
|
201
|
+
};
|
|
202
|
+
/** Most rows one run reports or acts on; the rest wait for the next run (`repeat: "new"`) or are counted. */
|
|
203
|
+
export declare const MAX_REPORTED_ROWS = 50;
|
|
204
|
+
/**
|
|
205
|
+
* The host-side validator for automations: same authority as
|
|
206
|
+
* `validateDraft` (Invariant 3). The conductor runs it for its repair turn;
|
|
207
|
+
* the composer runs it before Apply; the host's runner runs it again before
|
|
208
|
+
* every run, against the contract and the owner's role as they are then.
|
|
209
|
+
*/
|
|
210
|
+
export declare function validateAutomation(input: unknown, m: ContractManifest, opts: {
|
|
211
|
+
role: Role;
|
|
212
|
+
}): AutomationValidation;
|
|
213
|
+
/** "Every Monday at 09:00 (Europe/Bucharest)", "Every weekday morning". */
|
|
214
|
+
export declare function describeSchedule(s: Schedule, m: ContractManifest): string;
|
|
215
|
+
/** The automation's query as a table: for the card text and the composer's preview. */
|
|
216
|
+
export declare function automationAsDraft(a: Automation): Draft;
|
|
217
|
+
export type AutomationDescription = {
|
|
218
|
+
title: string;
|
|
219
|
+
lines: string[];
|
|
220
|
+
reads: string[];
|
|
221
|
+
changes: string[];
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* The card text, generated by code (Invariant 4): what it looks for, when,
|
|
225
|
+
* and what it does. The model never writes it.
|
|
226
|
+
*/
|
|
227
|
+
export declare function describeAutomation(a: Automation, m: ContractManifest, opts?: {
|
|
228
|
+
locale?: string;
|
|
229
|
+
}): AutomationDescription;
|
|
230
|
+
/** `YYYY-MM-DDTHH` of the most recent scheduled run at or before `now`, in the host's zone. */
|
|
231
|
+
export declare function lastSlot(s: Schedule, now: Date, timeZone?: string): string;
|
|
232
|
+
/**
|
|
233
|
+
* Whether an automation should run now: its most recent slot is later than
|
|
234
|
+
* its last run (or, before its first run, than when it was created). A
|
|
235
|
+
* scheduler that ticks late or misses a tick catches up once, not once per
|
|
236
|
+
* missed slot.
|
|
237
|
+
*/
|
|
238
|
+
export declare function isDue(s: Schedule, opts: {
|
|
239
|
+
now: Date;
|
|
240
|
+
lastRunAt?: string | null;
|
|
241
|
+
createdAt: string;
|
|
242
|
+
timeZone?: string;
|
|
243
|
+
}): boolean;
|
|
244
|
+
/** What the host keeps per automation between runs. */
|
|
245
|
+
export type AutomationState = {
|
|
246
|
+
lastRunAt?: string;
|
|
247
|
+
/** Keys already reported, newest last; bounded. */
|
|
248
|
+
seen?: string[];
|
|
249
|
+
lastStatus?: "sent" | "acted" | "quiet" | "broken" | "error";
|
|
250
|
+
lastMessage?: string;
|
|
251
|
+
lastCount?: number;
|
|
252
|
+
/** Workflow rows that stopped at a failed step: row key → index of the step to resume at. */
|
|
253
|
+
progress?: Record<string, number>;
|
|
254
|
+
/** Runs in a row that ended in "error"; reset by any run that does not. */
|
|
255
|
+
failures?: number;
|
|
256
|
+
};
|
|
257
|
+
/** Runs in a row that must fail before the owner is told. */
|
|
258
|
+
export declare const ALERT_AFTER_FAILURES = 3;
|
|
259
|
+
/**
|
|
260
|
+
* Something the owner should hear about, returned once per episode: when a
|
|
261
|
+
* rule turns broken, and when it has failed ALERT_AFTER_FAILURES runs in a
|
|
262
|
+
* row. The host delivers it to the owner however it likes (it is not the
|
|
263
|
+
* automation's own channel, which an intent-only rule does not have).
|
|
264
|
+
*/
|
|
265
|
+
export type AutomationAlert = {
|
|
266
|
+
kind: "broken" | "failing";
|
|
267
|
+
automationId: string;
|
|
268
|
+
title: string;
|
|
269
|
+
message: string;
|
|
270
|
+
};
|
|
271
|
+
/** One delivery, for the host's channel to render. Rows are the host's own, and go only to the owner. */
|
|
272
|
+
export type AutomationMessage = {
|
|
273
|
+
channel: string;
|
|
274
|
+
automationId: string;
|
|
275
|
+
title: string;
|
|
276
|
+
/** The card text, so the message says why it was sent. */
|
|
277
|
+
lines: string[];
|
|
278
|
+
columns: {
|
|
279
|
+
field: string;
|
|
280
|
+
label: string;
|
|
281
|
+
format?: string;
|
|
282
|
+
}[];
|
|
283
|
+
rows: Row[];
|
|
284
|
+
/** Matching rows in all, before `repeat` and the per-run cap. */
|
|
285
|
+
matched: number;
|
|
286
|
+
/** Rows not shown because of the per-run cap. */
|
|
287
|
+
more: number;
|
|
288
|
+
};
|
|
289
|
+
export type RunnableAutomation = {
|
|
290
|
+
id: string;
|
|
291
|
+
/** The owner's role at run time, from the host, never from the automation. */
|
|
292
|
+
role: Role;
|
|
293
|
+
automation: unknown;
|
|
294
|
+
createdAt: string;
|
|
295
|
+
state?: AutomationState;
|
|
296
|
+
};
|
|
297
|
+
export type RunAutomationOptions = {
|
|
298
|
+
manifest: ContractManifest;
|
|
299
|
+
now?: Date;
|
|
300
|
+
/** Rows of one resource for the owner, scoped and capped by the host, as for `serveQuery`. Give this or `query`. */
|
|
301
|
+
load?: (resource: string) => Promise<Row[]>;
|
|
302
|
+
/**
|
|
303
|
+
* Runs the automation's validated query as the owner, in place of `load`,
|
|
304
|
+
* for hosts whose data is in a database: `(ir, { today }) => runSql(ir, { ...db, manifest, today })`
|
|
305
|
+
* with `runSql` from @crasi/bisque-sql. `today` is the owner's date in the contract's time zone.
|
|
306
|
+
*/
|
|
307
|
+
query?: (ir: IR, opts: {
|
|
308
|
+
today: string;
|
|
309
|
+
}) => Promise<QueryResult>;
|
|
310
|
+
/** Delivers a message on one of the contract's channels, to the owner. */
|
|
311
|
+
notify?: (message: AutomationMessage) => Promise<void>;
|
|
312
|
+
/** Calls an intent as the owner, through the host's own write path. */
|
|
313
|
+
act?: (intent: string, args: Record<string, unknown>) => Promise<{
|
|
314
|
+
ok: boolean;
|
|
315
|
+
message?: string;
|
|
316
|
+
}>;
|
|
317
|
+
/** Run even if not due (a "Run now" button). */
|
|
318
|
+
force?: boolean;
|
|
319
|
+
locale?: string;
|
|
320
|
+
};
|
|
321
|
+
export type RunOutcome = {
|
|
322
|
+
ran: boolean;
|
|
323
|
+
state: AutomationState;
|
|
324
|
+
problems?: Problem[];
|
|
325
|
+
alert?: AutomationAlert;
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Runs one automation if it is due, on the host's server. Re-validates it
|
|
329
|
+
* against the contract and role as they are now; a rule that no longer
|
|
330
|
+
* fits is marked broken and does nothing. Returns the state to store.
|
|
331
|
+
*/
|
|
332
|
+
export declare function runAutomation(r: RunnableAutomation, opts: RunAutomationOptions): Promise<RunOutcome>;
|
|
333
|
+
/** Text for the conductor's prompt: the automation format. Only sent to hosts that declare automations. */
|
|
334
|
+
export declare const AUTOMATION_GUIDE = "## Automation format (propose_automation.automation)\n\n{\n \"kind\": \"automation\",\n \"title\": { \"<locale>\": \"\u226480 chars\", ... },\n \"schedule\": { \"every\": \"day\" } | { \"every\": \"weekday\" } | { \"every\": \"week\", \"on\": \"mon\"|\"tue\"|\"wed\"|\"thu\"|\"fri\"|\"sat\"|\"sun\" } | { \"every\": \"month\", \"day\": 1-28 } | { \"every\": \"hour\" },\n // add \"at\": 0-23 (hour) only when the reference says automations are checked every hour\n \"data\": <query>, // same query format as a spec; no params: use { \"today\": n } for relative dates\n \"when\": \"rows\" | \"always\", // rows: only when there is something to report; always: a digest every time (notify only)\n \"repeat\": \"new\" | \"all\", // new: report each row once, the first time it matches; all: every matching row every time\n \"key\": \"<output column that identifies a row, e.g. id>\", // required for repeat \"new\"\n \"columns\": [{ \"field\": col, \"label\"?: {..}, \"format\"?: \"number\"|\"money\"|\"percent\"|\"date\"|\"month\"|\"text\" }], // what the message shows, 1-8\n \"then\": <step> | [<step>, ...], // one step, or a workflow of up to 4: intents run in order per row, then at most one notify, last\n // <step>: { \"notify\": \"<channel>\" } | { \"intent\": \"<automatable intent>\", \"args\": { \"<arg>\": <argExpr without input/param> } }\n \"manifest\": { \"reads\": [resources the query touches], \"acts\": [the intents the steps call, in order, no repeats], \"channels\": [the notify step's channel, if any] }\n}\nNotifications always go to the user who owns the automation; never ask for or write an address.\n\"for more than N days\" on a date field is [\"<field>\", \"<\", { \"today\": -N }]. Prefer repeat \"new\" with key \"id\" for alerts, so the user is told once per row.\n\"Do X, then email me\" is a workflow: [{ \"intent\": \"x\", ... }, { \"notify\": \"email\" }]; the message lists the rows every intent step succeeded for.";
|
|
335
|
+
/** Equality of two automations as saved data (for "no change" checks). */
|
|
336
|
+
export declare function sameAutomation(a: Automation, b: Automation): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The L1 catalog as the model sees it. Kept next to the schema it documents
|
|
3
|
+
* so the two change together; the conductor puts it in the cached system
|
|
4
|
+
* prompt.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CATALOG_LINE = "catalog: sankey(source,target,value,otherBucket) bar(x,y,series,stacked) line(x,y,series) area(x,y,series) table(columns) kpi(value) grid(rowKey,columns[edit\u2192intent]) actionTable(rowKey,columns,inputs,action\u2192intent) params(bind host.context.*|slider|select|toggle)";
|
|
7
|
+
export declare const SPEC_GUIDE = "## Spec format (propose_spec.draft)\n\n{\n \"kind\": \"spec\",\n \"body\": {\n \"component\": \"sankey\" | \"bar\" | \"line\" | \"area\" | \"table\" | \"kpi\" | \"grid\" | \"actionTable\",\n \"title\": { \"<locale>\": \"\u226480 chars\", ... one entry per host locale },\n \"data\": <query>,\n \"encode\": <per component, below>,\n \"params\": { \"<name>\": { \"bind\": \"host.context.<key>\" } | { \"control\": \"slider\", \"label\": {..}, \"min\": n, \"max\": n, \"step\": n, \"default\": n } | { \"control\": \"select\", \"label\": {..}, \"options\": [{ \"value\": v, \"label\": {..} }], \"default\": v } | { \"control\": \"toggle\", \"label\": {..}, \"default\": bool } },\n \"onClick\": { \"navigate\": \"<navigation name>\", \"args\": { \"<arg>\": <argExpr> } },\n \"otherBucket\": { \"maxTargets\": n } // sankey only; bar uses { \"maxCategories\": n }\n },\n \"manifest\": { \"reads\": [exactly the resources the query touches], \"acts\": [exactly the intents the spec invokes] },\n \"placement\": { \"slot\": \"<slot id>\", \"label\": { \"<locale>\": \"\u226440 chars\" } } // label only for page slots such as nav.primary\n}\n\n<query>:\n{\n \"scan\": \"<resource>\",\n \"join\": [{ \"on\": \"<field of scan, or resource.field of an already joined resource>\", \"to\": \"<the resource that field references>\" }],\n \"where\": [[\"<field>\", \"=\" | \"!=\" | \"<\" | \"<=\" | \">\" | \">=\" | \"in\" | \"notIn\", <value>], [\"<field>\", \"match\", [\"Name\", ...]], [\"<field>\", \"isNull\" | \"notNull\"]],\n \"groupBy\": [\"<field>\", ...],\n \"measures\": [{ \"sum\" | \"avg\" | \"min\" | \"max\" | \"count\" | \"countDistinct\": \"<field>\" | \"*\" (count only), \"as\": \"<name>\" }],\n \"select\": [\"<field>\", ...], // instead of groupBy/measures, for plain row lists\n \"orderBy\": [[\"<output column>\", \"asc\" | \"desc\"]],\n \"limit\": <integer, required, \u2264 the resource's row cap>\n}\nField names: unqualified = field of scan; fields of joined resources are qualified (\"products.name\").\nJoins may only follow declared references (fields shown as \"-> resource\"). Each resource joins once.\n<value>: a literal, a list of literals, { \"param\": \"<name>\" } (declared in params), or { \"today\": <days offset> } for dates.\n\"match\" filters take the user's own words for names (e.g. [\"Metro\", \"TABAC\"]); the host resolves them to its real values and asks the user if a name is ambiguous. Use match for any name the user mentions; never guess ids.\nOutput columns are named exactly as written in groupBy/select, plus each measure's \"as\".\n\nencode by component (every referenced name must be an output column):\n- sankey: { \"source\": col, \"target\": col, \"value\": number col, \"label\": \"value\" | \"share-of-source\" | \"share-of-total\" }\n- bar: { \"x\": col, \"y\": number col | [number cols], \"series\": col?, \"stacked\": bool?, \"horizontal\": bool? }\n- line, area: { \"x\": col, \"y\": number col | [number cols], \"series\": col? }\n- table: { \"columns\": [{ \"field\": col, \"label\": {..}?, \"format\": \"number\"|\"money\"|\"percent\"|\"date\"|\"month\"|\"text\"? }] }\n- kpi: { \"value\": number col } \u2014 query has measures and no groupBy\n- grid: { \"rowKey\": col, \"columns\": [{ \"field\": col, \"label\"?, \"format\"?, \"edit\": { \"intent\": \"<intent>\", \"value\": \"<arg that receives the edited value>\", \"args\": { \"<arg>\": <argExpr> } }? }] }\n- actionTable: { \"rowKey\": col, \"columns\": [...], \"inputs\": [{ \"name\": id, \"label\": {..}, \"type\": \"number\"|\"text\", \"default\"?, \"min\"?, \"max\"? }], \"action\": { \"intent\": \"<intent>\", \"label\": {..}, \"args\": { \"<arg>\": <argExpr> } } }\n One intent call per selected row; the host shows one confirmation for the whole batch.\n\n<argExpr>: { \"field\": col } | { \"input\": \"<row input name>\" } | { \"param\": \"<name>\" } | { \"literal\": v | [v] } | { \"today\": days } | { \"template\": \"text with {col} placeholders\" } | { \"list\": [<argExpr>, ...] }\n\nNever put HTML, CSS, URLs or scripts in any string. Do not write descriptions: the host generates the card text from the spec.";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ContractManifest } from "@crasi/bisque-contract";
|
|
2
|
+
import type { Draft } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* The plain-language card text (Fig. 8b), generated from the spec by code.
|
|
5
|
+
* The model never writes descriptions (Invariant 4), so what the card says
|
|
6
|
+
* cannot drift from what the chart does.
|
|
7
|
+
*
|
|
8
|
+
* Templates are English in v1; other locales get the spec's own localized
|
|
9
|
+
* title and English sentences.
|
|
10
|
+
*/
|
|
11
|
+
export type Description = {
|
|
12
|
+
title: string;
|
|
13
|
+
/** "Sum of sales value (RON) in October 2026, from each key account to each product." */
|
|
14
|
+
lines: string[];
|
|
15
|
+
reads: string[];
|
|
16
|
+
changes: string[];
|
|
17
|
+
placed: string;
|
|
18
|
+
};
|
|
19
|
+
export type DescribeOptions = {
|
|
20
|
+
locale?: string;
|
|
21
|
+
/** Current values of host context, so "in the month being viewed" can become "in October 2026". */
|
|
22
|
+
context?: Record<string, unknown>;
|
|
23
|
+
/** Current param values (control defaults if absent). */
|
|
24
|
+
params?: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
export declare function localize(text: Record<string, string> | undefined, locale: string, fallback: string): string;
|
|
27
|
+
export declare function describeDraft(d: Draft, m: ContractManifest, opts?: DescribeOptions): Description;
|
|
28
|
+
/**
|
|
29
|
+
* Diff lines for a refinement (Flow A step A5): "Measure: sales value (RON) →
|
|
30
|
+
* pieces", "Filter: + Metro, TABAC". Computed from the two specs.
|
|
31
|
+
*/
|
|
32
|
+
export declare function diffDrafts(a: Draft, b: Draft, m: ContractManifest, opts?: DescribeOptions): string[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { QueryResult } from "@crasi/bisque-ir";
|
|
3
|
+
import type { Spec } from "./schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Render diagnostics (issue I1, §6.8): the shape of a preview, never its
|
|
6
|
+
* values. This is the only thing derived from records that crosses to the
|
|
7
|
+
* conductor (P1 exception b), so the schema is strict: buckets, rounded
|
|
8
|
+
* shares, fixed error codes, and column names taken from the spec.
|
|
9
|
+
*/
|
|
10
|
+
export declare const RENDER_ERRORS: readonly ["empty", "too_many_categories", "all_null", "unresolved_names", "ambiguous_names", "component_error"];
|
|
11
|
+
export declare const DiagnosticsSchema: z.ZodObject<{
|
|
12
|
+
proposal: z.ZodString;
|
|
13
|
+
valid: z.ZodBoolean;
|
|
14
|
+
rows: z.ZodEnum<{
|
|
15
|
+
0: "0";
|
|
16
|
+
1: "1";
|
|
17
|
+
"13-50": "13-50";
|
|
18
|
+
"2-12": "2-12";
|
|
19
|
+
">50": ">50";
|
|
20
|
+
}>;
|
|
21
|
+
distinct: z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
22
|
+
0: "0";
|
|
23
|
+
1: "1";
|
|
24
|
+
"13-50": "13-50";
|
|
25
|
+
"2-12": "2-12";
|
|
26
|
+
">50": ">50";
|
|
27
|
+
}>>;
|
|
28
|
+
nullShare: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
29
|
+
otherBucket: z.ZodEnum<{
|
|
30
|
+
applied: "applied";
|
|
31
|
+
"not needed": "not needed";
|
|
32
|
+
"not set": "not set";
|
|
33
|
+
}>;
|
|
34
|
+
truncated: z.ZodBoolean;
|
|
35
|
+
renderErrors: z.ZodArray<z.ZodEnum<{
|
|
36
|
+
all_null: "all_null";
|
|
37
|
+
ambiguous_names: "ambiguous_names";
|
|
38
|
+
component_error: "component_error";
|
|
39
|
+
empty: "empty";
|
|
40
|
+
too_many_categories: "too_many_categories";
|
|
41
|
+
unresolved_names: "unresolved_names";
|
|
42
|
+
}>>;
|
|
43
|
+
}, z.core.$strict>;
|
|
44
|
+
export type Diagnostics = z.infer<typeof DiagnosticsSchema>;
|
|
45
|
+
export declare function renderDiagnostics(proposal: string, spec: Spec, res: QueryResult, opts: {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
renderError?: boolean;
|
|
48
|
+
}): Diagnostics;
|
|
49
|
+
/** Whether diagnostics justify the one repair turn (and what to tell the model). */
|
|
50
|
+
export declare function repairReason(d: Diagnostics): string | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./schema.js";
|
|
2
|
+
export * from "./validate.js";
|
|
3
|
+
export * from "./describe.js";
|
|
4
|
+
export * from "./adjust.js";
|
|
5
|
+
export * from "./diagnostics.js";
|
|
6
|
+
export * from "./args.js";
|
|
7
|
+
export * from "./migrate.js";
|
|
8
|
+
export * from "./catalog.js";
|
|
9
|
+
export * from "./artifact.js";
|
|
10
|
+
export * from "./protocol.js";
|
|
11
|
+
export * from "./theme.js";
|
|
12
|
+
export * from "./template.js";
|
|
13
|
+
export * from "./automation.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContractDiff } from "@crasi/bisque-contract";
|
|
2
|
+
import type { Draft } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* Applies `renamedFrom` renames to a saved artifact without a model (issue
|
|
5
|
+
* I13). Rewrites field references in the query and every column name that
|
|
6
|
+
* was a field. Returns null when nothing changed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function migrateDraft(d: Draft, renames: ContractDiff["renames"]): Draft | null;
|