@g9tm/aiassistant 0.0.0-stage → 1.1.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/dist/api.js ADDED
@@ -0,0 +1,134 @@
1
+ /** The typed HTTP client of the assistant's API. fetch comes from the host. */
2
+ import { timer } from "./host.js";
3
+ export class ApiError extends Error {
4
+ constructor(status, code, body) {
5
+ super("assistant api: " + String(status) + " " + code);
6
+ this.status = status;
7
+ this.code = code;
8
+ this.body = body;
9
+ }
10
+ }
11
+ export function obj(v) {
12
+ return v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
13
+ }
14
+ export function str(v, fallback = "") {
15
+ return typeof v === "string" ? v : fallback;
16
+ }
17
+ export function num(v, fallback = 0) {
18
+ return typeof v === "number" && Number.isFinite(v) ? v : fallback;
19
+ }
20
+ export function arr(v) {
21
+ return Array.isArray(v) ? v : [];
22
+ }
23
+ export class AssistantApi {
24
+ constructor(host, base = "/api/assistant/") {
25
+ this.host = host;
26
+ this.base = base;
27
+ /** The time one request may take (a long poll waits up to 25 s on the server). */
28
+ this.timeoutMs = 60000;
29
+ }
30
+ async request(method, path, body, raw) {
31
+ const headers = { Accept: "application/json", "Accept-Language": this.host.locale };
32
+ let payload;
33
+ if (raw) {
34
+ headers["Content-Type"] = "application/octet-stream";
35
+ payload = raw.bytes;
36
+ }
37
+ else if (body !== undefined || method !== "GET") {
38
+ headers["Content-Type"] = "application/json";
39
+ payload = JSON.stringify(body ?? {});
40
+ }
41
+ const t = timer(this.host);
42
+ let handle;
43
+ const timeout = new Promise((_, reject) => {
44
+ handle = t.set(() => reject(new ApiError(0, "timeout", null)), this.timeoutMs);
45
+ });
46
+ const init = payload === undefined ? { method, headers } : { method, headers, body: payload };
47
+ try {
48
+ const response = await Promise.race([this.host.fetch(this.base + path, init), timeout]); // AbortController is not on Lynx
49
+ const text = await response.text();
50
+ let parsed = null;
51
+ if (text.length > 0) {
52
+ try {
53
+ parsed = JSON.parse(text);
54
+ }
55
+ catch {
56
+ parsed = text;
57
+ }
58
+ }
59
+ if (!response.ok) {
60
+ const e = obj(parsed)["error"];
61
+ throw new ApiError(response.status, typeof e === "string" ? e : str(obj(e)["code"], "error"), parsed);
62
+ }
63
+ return parsed;
64
+ }
65
+ finally {
66
+ t.clear(handle);
67
+ }
68
+ }
69
+ send(input) {
70
+ const path = input.conversationId ? "conversations/" + encodeURIComponent(input.conversationId) + "/messages" : "conversations/messages";
71
+ const body = { text: input.text };
72
+ if (input.files && input.files.length > 0)
73
+ body["files"] = input.files;
74
+ if (input.page)
75
+ body["page"] = input.page;
76
+ return this.request("POST", path, body).then((r) => ({ conversationId: str(obj(r)["conversationId"]), runId: str(obj(r)["runId"]) }));
77
+ }
78
+ async events(runId, after, wait) {
79
+ const r = obj(await this.request("GET", "runs/" + encodeURIComponent(runId) + "/events?after=" + String(after) + "&wait=" + String(wait)));
80
+ return { events: arr(r["events"]).map(toRawEvent), last: num(r["last"], after), finished: r["finished"] === true };
81
+ }
82
+ async ticket(runId) {
83
+ return str(obj(await this.request("POST", "runs/" + encodeURIComponent(runId) + "/ticket"))["ticket"]);
84
+ }
85
+ streamUrl(runId, after, ticket) {
86
+ return this.base + "runs/" + encodeURIComponent(runId) + "/events?after=" + String(after) + "&ticket=" + encodeURIComponent(ticket);
87
+ }
88
+ cancel(runId) { return this.request("POST", "runs/" + encodeURIComponent(runId) + "/cancel"); }
89
+ confirm(planId, hash, code, skip) {
90
+ return this.request("POST", "plans/" + encodeURIComponent(planId) + "/confirm", { hash, code, skip });
91
+ }
92
+ refuse(planId) { return this.request("POST", "plans/" + encodeURIComponent(planId) + "/refuse"); }
93
+ undo(planId) { return this.request("POST", "plans/" + encodeURIComponent(planId) + "/undo"); }
94
+ answer(runId, picked, text) {
95
+ return this.request("POST", "asks/" + encodeURIComponent(runId) + "/answer", { picked, text });
96
+ }
97
+ lock() { return this.request("POST", "lock"); }
98
+ conversations() { return this.request("GET", "conversations"); }
99
+ messages(conversationId, after) {
100
+ return this.request("GET", "conversations/" + encodeURIComponent(conversationId) + "/messages" + (after ? "?after=" + encodeURIComponent(after) : ""));
101
+ }
102
+ state() { return this.request("GET", "state"); }
103
+ capabilities() { return this.request("GET", "capabilities"); }
104
+ feedback(conversationId, messageId, good, note) {
105
+ return this.request("POST", "feedback", note === undefined ? { conversationId, messageId, good } : { conversationId, messageId, good, note });
106
+ }
107
+ card(kind, id, verb) {
108
+ return this.request("POST", kind + "/" + encodeURIComponent(id) + "/" + verb);
109
+ }
110
+ async upload(name, bytes) {
111
+ const r = obj(await this.request("POST", "files?name=" + encodeURIComponent(name), undefined, { bytes, type: "application/octet-stream" }));
112
+ const out = { id: str(r["id"]), kind: str(r["kind"]), name: str(r["name"]) };
113
+ if (typeof r["rows"] === "number")
114
+ out.rows = r["rows"];
115
+ return out;
116
+ }
117
+ /** Dictation: audio to text on the server (the audio is not kept). */
118
+ async speech(bytes, mime) {
119
+ return str(obj(await this.request("POST", "speech?mime=" + encodeURIComponent(mime), undefined, { bytes, type: "application/octet-stream" }))["text"]);
120
+ }
121
+ removeFile(id) { return this.request("DELETE", "files/" + encodeURIComponent(id)); }
122
+ transcript(conversationId) { return this.request("GET", "conversations/" + encodeURIComponent(conversationId) + "/transcript"); }
123
+ documentLink(conversationId) { return this.request("GET", "conversations/" + encodeURIComponent(conversationId) + "/document"); }
124
+ /** Any other endpoint (admin pages, findings, gates...). */
125
+ get(path) { return this.request("GET", path); }
126
+ post(path, body) { return this.request("POST", path, body); }
127
+ put(path, body) { return this.request("PUT", path, body); }
128
+ patch(path, body) { return this.request("PATCH", path, body); }
129
+ delete(path) { return this.request("DELETE", path); }
130
+ }
131
+ export function toRawEvent(v) {
132
+ const e = obj(v);
133
+ return { seq: num(e["seq"]), type: str(e["type"]), at: str(e["at"]), body: obj(e["body"]) };
134
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The assistant for a renderer: all behaviour lives here and every component reads its view model from
3
+ * it. A host's own component therefore cannot skip a rule: text stays escaped, a card answers once and only with its
4
+ * plan's hash, a second send while a run is working is refused, a secret field is sent as an answer and never shown.
5
+ */
6
+ import { AssistantApi } from "./api.js";
7
+ import type { SendInput } from "./api.js";
8
+ import type { MessageView } from "./conversation.js";
9
+ import type { AssistantHost } from "./host.js";
10
+ import type { Texts } from "./i18n.js";
11
+ import { AnsweredCards } from "./plan.js";
12
+ import type { PlanView } from "./plan.js";
13
+ import { Watched } from "./reveal.js";
14
+ import type { RunView } from "./run.js";
15
+ import { StateWatch } from "./state.js";
16
+ import type { AssistantState } from "./state.js";
17
+ export interface AssistantOptions {
18
+ base?: string;
19
+ sse?: boolean;
20
+ sync?: boolean;
21
+ texts?: Readonly<Record<string, string>>;
22
+ /** Custom block types (x:*) the host draws. */
23
+ customBlocks?: readonly string[];
24
+ }
25
+ export interface AssistantSnapshot {
26
+ conversationId: string | null;
27
+ messages: MessageView[];
28
+ run: RunView | null;
29
+ busy: boolean;
30
+ plans: ReadonlyMap<string, PlanView>;
31
+ attachments: {
32
+ id: string;
33
+ name: string;
34
+ kind: string;
35
+ }[];
36
+ state: AssistantState;
37
+ error: string | null;
38
+ }
39
+ export declare class Assistant {
40
+ readonly host: AssistantHost;
41
+ readonly api: AssistantApi;
42
+ readonly texts: Texts;
43
+ readonly watched: Watched;
44
+ readonly answered: AnsweredCards;
45
+ readonly stateWatch: StateWatch;
46
+ readonly customBlocks: ReadonlySet<string>;
47
+ private readonly store;
48
+ private readonly transport;
49
+ private readonly listeners;
50
+ private run;
51
+ private stopFollowing;
52
+ private readonly plans;
53
+ /** Plans whose confirmation is in flight: no second confirmation and no refusal until it answers. */
54
+ private readonly confirming;
55
+ private attachments;
56
+ private error;
57
+ private stateNow;
58
+ constructor(host: AssistantHost, options?: AssistantOptions);
59
+ /** Listens to every change; returns the function that stops listening. */
60
+ subscribe(listener: (s: AssistantSnapshot) => void): () => void;
61
+ snapshot(): AssistantSnapshot;
62
+ private emit;
63
+ /** Opens a conversation from its history (from the end; history never animates). */
64
+ open(conversationId: string): Promise<void>;
65
+ /** A new conversation. */
66
+ fresh(): void;
67
+ /** Sends a question; refused while a run is working (the button is "stop" then). */
68
+ send(text: string, page?: SendInput["page"]): Promise<boolean>;
69
+ /** Follows a run (null stops following). */
70
+ follow(runId: string | null, after?: number): void;
71
+ /** Stops the run that is working. */
72
+ stop(): Promise<void>;
73
+ private notePlan;
74
+ /** Ticks or unticks a step of a plan card. */
75
+ tick(planId: string, index: number): void;
76
+ /** Confirms a plan card with the server's hash (a card without it never confirms). */
77
+ confirm(planId: string, code?: string | null, tries?: number): Promise<boolean>;
78
+ refuse(planId: string): Promise<void>;
79
+ undo(planId: string): Promise<unknown>;
80
+ /** Answers a question card once (a secret is sent, never kept in the client's state). */
81
+ answer(runId: string, cardId: string, picked: string[], text: string | null): Promise<boolean>;
82
+ /** Answers a "learn this?" or "make it a routine?" card once. */
83
+ choose(kind: "knowledge" | "learned", cardId: string, verb: string): Promise<boolean>;
84
+ attach(name: string, bytes: Uint8Array): Promise<void>;
85
+ detach(id: string): void;
86
+ notRight(messageId: string): Promise<void>;
87
+ /** The conversation's text for "copy all". */
88
+ transcript(): string;
89
+ copyAll(): Promise<boolean>;
90
+ dispose(): void;
91
+ }
92
+ export declare function createAssistant(host: AssistantHost, options?: AssistantOptions): Assistant;
@@ -0,0 +1,265 @@
1
+ /**
2
+ * The assistant for a renderer: all behaviour lives here and every component reads its view model from
3
+ * it. A host's own component therefore cannot skip a rule: text stays escaped, a card answers once and only with its
4
+ * plan's hash, a second send while a run is working is refused, a secret field is sent as an answer and never shown.
5
+ */
6
+ import { ApiError, AssistantApi } from "./api.js";
7
+ import { ConversationStore } from "./conversation.js";
8
+ import { timer } from "./host.js";
9
+ import { createTexts } from "./i18n.js";
10
+ import { AnsweredCards, WAITING, afterConfirm, confirmation, planView, toggle } from "./plan.js";
11
+ import { Watched } from "./reveal.js";
12
+ import { emptyRun, finished, reduceRun } from "./run.js";
13
+ import { StateWatch } from "./state.js";
14
+ import { transcript } from "./transcript.js";
15
+ import { pickTransport } from "./transport.js";
16
+ export class Assistant {
17
+ constructor(host, options = {}) {
18
+ this.host = host;
19
+ this.watched = new Watched();
20
+ this.answered = new AnsweredCards();
21
+ this.store = new ConversationStore();
22
+ this.listeners = new Set();
23
+ this.run = null;
24
+ this.stopFollowing = null;
25
+ this.plans = new Map();
26
+ /** Plans whose confirmation is in flight: no second confirmation and no refusal until it answers. */
27
+ this.confirming = new Set();
28
+ this.attachments = [];
29
+ this.error = null;
30
+ this.api = new AssistantApi(host, options.base);
31
+ this.texts = createTexts(host.locale, options.texts);
32
+ this.transport = pickTransport(this.api, host, options);
33
+ this.customBlocks = new Set(options.customBlocks ?? []);
34
+ this.stateWatch = new StateWatch(this.api, host);
35
+ this.stateNow = this.stateWatch.state;
36
+ this.stateWatch.subscribe((s) => { this.stateNow = s; this.emit(); });
37
+ }
38
+ /** Listens to every change; returns the function that stops listening. */
39
+ subscribe(listener) {
40
+ this.listeners.add(listener);
41
+ listener(this.snapshot());
42
+ return () => this.listeners.delete(listener);
43
+ }
44
+ snapshot() {
45
+ return {
46
+ conversationId: this.store.id,
47
+ messages: this.store.messages,
48
+ run: this.run,
49
+ busy: this.run !== null && !finished(this.run) && this.run.state !== "waiting-confirm" && this.run.state !== "waiting-answer",
50
+ plans: new Map(this.plans),
51
+ attachments: [...this.attachments],
52
+ state: this.stateNow,
53
+ error: this.error,
54
+ };
55
+ }
56
+ emit() {
57
+ const s = this.snapshot();
58
+ for (const l of this.listeners)
59
+ l(s);
60
+ }
61
+ /** Opens a conversation from its history (from the end; history never animates). */
62
+ async open(conversationId) {
63
+ this.follow(null);
64
+ this.store.reset(conversationId);
65
+ const r = await this.api.messages(conversationId);
66
+ const raw = Array.isArray(r) ? r : Array.isArray(r.messages) ? r.messages : [];
67
+ const added = this.store.merge(raw);
68
+ this.watched.history(added.map((m) => m.id));
69
+ for (const m of added)
70
+ this.notePlan(m);
71
+ this.emit();
72
+ }
73
+ /** A new conversation. */
74
+ fresh() {
75
+ this.follow(null);
76
+ this.store.reset(null);
77
+ this.plans.clear();
78
+ this.attachments = [];
79
+ this.emit();
80
+ }
81
+ /** Sends a question; refused while a run is working (the button is "stop" then). */
82
+ async send(text, page) {
83
+ const trimmed = text.trim();
84
+ if (trimmed.length === 0)
85
+ return false;
86
+ if (this.snapshot().busy) {
87
+ this.error = "error.busy";
88
+ this.emit();
89
+ return false;
90
+ }
91
+ this.error = null;
92
+ this.store.optimistic(trimmed, new Date(timer(this.host).now()).toISOString());
93
+ this.emit();
94
+ const input = { text: trimmed };
95
+ if (this.store.id)
96
+ input.conversationId = this.store.id;
97
+ if (this.attachments.length > 0)
98
+ input.files = this.attachments.map((a) => a.id);
99
+ if (page)
100
+ input.page = page;
101
+ try {
102
+ const t = await this.api.send(input);
103
+ this.store.id = t.conversationId;
104
+ this.attachments = [];
105
+ this.follow(t.runId);
106
+ return true;
107
+ }
108
+ catch (e) {
109
+ this.error = e instanceof ApiError ? e.code : "error.network";
110
+ this.emit();
111
+ return false;
112
+ }
113
+ }
114
+ /** Follows a run (null stops following). */
115
+ follow(runId, after = 0) {
116
+ this.stopFollowing?.();
117
+ this.stopFollowing = null;
118
+ if (runId === null)
119
+ return;
120
+ this.run = emptyRun(runId);
121
+ this.emit();
122
+ this.stopFollowing = this.transport.follow(runId, after, {
123
+ onEvent: (e) => {
124
+ if (!this.run || this.run.runId !== runId)
125
+ return;
126
+ this.run = reduceRun(this.run, e, timer(this.host).now());
127
+ if (e.type === "message") {
128
+ const added = this.store.merge([e.body.message]);
129
+ for (const m of added)
130
+ this.notePlan(m);
131
+ if (added.some((m) => m.role === "assistant"))
132
+ this.host.onAnswerShown?.();
133
+ }
134
+ this.emit();
135
+ },
136
+ onEnd: () => this.emit(),
137
+ });
138
+ }
139
+ /** Stops the run that is working. */
140
+ async stop() {
141
+ if (!this.run || finished(this.run))
142
+ return;
143
+ try {
144
+ await this.api.cancel(this.run.runId);
145
+ }
146
+ catch {
147
+ // the run may have finished meanwhile
148
+ }
149
+ }
150
+ notePlan(m) {
151
+ if (m.card?.kind === "plan" && !this.plans.has(m.card.id))
152
+ this.plans.set(m.card.id, planView({ ...m.card.body, id: m.card.id }));
153
+ }
154
+ /** Ticks or unticks a step of a plan card. */
155
+ tick(planId, index) {
156
+ const p = this.plans.get(planId);
157
+ if (!p)
158
+ return;
159
+ this.plans.set(planId, toggle(p, index));
160
+ this.emit();
161
+ }
162
+ /** Confirms a plan card with the server's hash (a card without it never confirms). */
163
+ async confirm(planId, code = null, tries = 0) {
164
+ const p = this.plans.get(planId);
165
+ const c = p && !this.confirming.has(planId) ? confirmation(p, code) : null;
166
+ if (!p || !c)
167
+ return false;
168
+ this.confirming.add(planId);
169
+ try {
170
+ const answer = await this.api.confirm(c.planId, c.hash, c.code, c.skip);
171
+ const next = afterConfirm(p, true, answer);
172
+ this.plans.set(planId, next);
173
+ this.emit();
174
+ if (next.failCode === WAITING) {
175
+ // Approved on another device: ask again in a few seconds (a typed code is asked of the person again instead).
176
+ if (p.method === "remote" && tries < 60)
177
+ timer(this.host).set(() => void this.confirm(planId, code, tries + 1), 3000);
178
+ return false;
179
+ }
180
+ if (this.run)
181
+ this.follow(this.run.runId, this.run.seq);
182
+ return true;
183
+ }
184
+ catch (e) {
185
+ this.plans.set(planId, afterConfirm(p, false, e instanceof ApiError ? e.body : null));
186
+ this.emit();
187
+ return false;
188
+ }
189
+ finally {
190
+ this.confirming.delete(planId);
191
+ }
192
+ }
193
+ async refuse(planId) {
194
+ const p = this.plans.get(planId);
195
+ if (!p || p.answered || this.confirming.has(planId))
196
+ return;
197
+ this.plans.set(planId, { ...p, answered: "refused" });
198
+ this.emit();
199
+ await this.api.refuse(planId).catch(() => undefined);
200
+ if (this.run)
201
+ this.follow(this.run.runId, this.run.seq);
202
+ }
203
+ async undo(planId) {
204
+ return this.api.undo(planId);
205
+ }
206
+ /** Answers a question card once (a secret is sent, never kept in the client's state). */
207
+ async answer(runId, cardId, picked, text) {
208
+ if (!this.answered.answer(cardId, picked.join(",") || "text"))
209
+ return false;
210
+ this.emit();
211
+ await this.api.answer(runId, picked, text);
212
+ if (this.run && this.run.runId === runId)
213
+ this.follow(runId, this.run.seq);
214
+ return true;
215
+ }
216
+ /** Answers a "learn this?" or "make it a routine?" card once. */
217
+ async choose(kind, cardId, verb) {
218
+ if (!this.answered.answer(cardId, verb))
219
+ return false;
220
+ this.emit();
221
+ await this.api.card(kind, cardId, verb);
222
+ return true;
223
+ }
224
+ async attach(name, bytes) {
225
+ try {
226
+ const f = await this.api.upload(name, bytes);
227
+ this.attachments = [...this.attachments, { id: f.id, name: f.name, kind: f.kind }];
228
+ }
229
+ catch (e) {
230
+ this.error = e instanceof ApiError ? e.code : "error.network";
231
+ }
232
+ this.emit();
233
+ }
234
+ detach(id) {
235
+ this.attachments = this.attachments.filter((a) => a.id !== id);
236
+ this.emit();
237
+ void this.api.removeFile(id).catch(() => undefined);
238
+ }
239
+ async notRight(messageId) {
240
+ if (!this.store.id)
241
+ return;
242
+ const r = await this.api.feedback(this.store.id, messageId, false);
243
+ const runId = r?.runId;
244
+ if (typeof runId === "string")
245
+ this.follow(runId);
246
+ }
247
+ /** The conversation's text for "copy all". */
248
+ transcript() {
249
+ return transcript(this.store.messages, this.texts);
250
+ }
251
+ async copyAll() {
252
+ if (!this.host.copy)
253
+ return false;
254
+ await this.host.copy(this.transcript());
255
+ return true;
256
+ }
257
+ dispose() {
258
+ this.follow(null);
259
+ this.stateWatch.stop();
260
+ this.listeners.clear();
261
+ }
262
+ }
263
+ export function createAssistant(host, options) {
264
+ return new Assistant(host, options);
265
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Blocks as view models: each block is read with type checks only, so a stored null never breaks it; a
3
+ * type no renderer knows shows its fallback text; and the display rules live here, once, for both renderers: a wide or
4
+ * wordy table becomes cards, a long one folds after 8 rows, a ranking is horizontal bars (at most 10), a line only on a
5
+ * time axis, and too little data shows no percentages or averages.
6
+ */
7
+ export interface Column {
8
+ name: string;
9
+ kind: "text" | "number" | "money" | "percent" | "date" | "day" | "id";
10
+ label: string;
11
+ }
12
+ export type BlockView = {
13
+ type: "text";
14
+ text: string;
15
+ fallbackText: string;
16
+ } | {
17
+ type: "callout";
18
+ text: string;
19
+ tone: "info" | "warn" | "ok" | "danger" | "neutral";
20
+ fallbackText: string;
21
+ } | {
22
+ type: "table";
23
+ title?: string;
24
+ columns: Column[];
25
+ rows: string[][];
26
+ asCards: boolean;
27
+ shown: number;
28
+ more: number;
29
+ truncated: boolean;
30
+ fallbackText: string;
31
+ } | {
32
+ type: "chart";
33
+ title?: string;
34
+ kind: "hbars" | "bars" | "line" | "lines" | "stacked" | "donut";
35
+ series: ChartSeries[];
36
+ labels: string[];
37
+ fewData: boolean;
38
+ fallbackText: string;
39
+ } | {
40
+ type: "kpi";
41
+ items: {
42
+ label: string;
43
+ value: string;
44
+ }[];
45
+ fallbackText: string;
46
+ } | {
47
+ type: "steps";
48
+ items: {
49
+ text: string;
50
+ state: string;
51
+ }[];
52
+ fallbackText: string;
53
+ } | {
54
+ type: "actions";
55
+ items: {
56
+ label: string;
57
+ send: string;
58
+ suggested: boolean;
59
+ }[];
60
+ fallbackText: string;
61
+ } | {
62
+ type: "flow";
63
+ line: string;
64
+ fallbackText: string;
65
+ } | {
66
+ type: "image";
67
+ fileIds: string[];
68
+ fallbackText: string;
69
+ } | {
70
+ type: "open";
71
+ pageId: string;
72
+ fallbackText: string;
73
+ } | {
74
+ type: "export";
75
+ title?: string;
76
+ format: string;
77
+ columns: Column[];
78
+ rows: string[][];
79
+ fallbackText: string;
80
+ } | {
81
+ type: "custom";
82
+ name: string;
83
+ data: Record<string, unknown>;
84
+ fallbackText: string;
85
+ } | {
86
+ type: "fallback";
87
+ fallbackText: string;
88
+ };
89
+ export interface ChartSeries {
90
+ name: string;
91
+ values: number[];
92
+ }
93
+ /** A table with more columns than this, or long texts, shows each row as a card. */
94
+ export declare const CARD_COLUMNS = 4;
95
+ /** Rows shown before a long table folds. */
96
+ export declare const FOLD_ROWS = 8;
97
+ /** Bars in a ranking. */
98
+ export declare const RANK_BARS = 10;
99
+ /** Fewer data points than this show no percentages or averages. */
100
+ export declare const FEW_DATA = 3;
101
+ /** One cell as the person reads it: numbers in the locale's digits and separators. */
102
+ export declare function cell(v: unknown, kind: Column["kind"], locale: "fa" | "en"): string;
103
+ /** The view model of a stored block; anything unreadable is its fallback text. */
104
+ export declare function blockView(raw: unknown, locale: "fa" | "en", custom?: ReadonlySet<string>): BlockView;
105
+ /** Bar lengths as shares of the largest value (0..1), for the built-in chart. */
106
+ export declare function shares(values: readonly number[]): number[];