@invana/assistant 0.0.32
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/README.md +103 -0
- package/dist/index.cjs +2007 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1468 -0
- package/dist/index.d.ts +1468 -0
- package/dist/index.js +1892 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1468 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TraceStep, AnswerKind, Tone, AnswerOptionsByKind, ActionOption, AskState, AskSpec, AskKind, AskOptionsByKind, BlockPatch, PatchSource as PatchSource$1, PatchChunk as PatchChunk$1, PatchScript as PatchScript$1, ScriptStep as ScriptStep$1, EventSourceOptions, PlayOptions, PageSpec } from '@invana/blocks';
|
|
3
|
+
export { ANSWER_KINDS, ASK_KINDS, ActionOption, AnswerKind, AnswerOptionsByKind, ApprovalOptions, AskKind, AskOptionsByKind, AskSpec, AskState, AskText, AskValueByKind, BLOCKS, BlockKind, BlockOptionsByKind, CannotOptions, CaveatNoteOptions, CaveatOptions, CaveatTone, Cell, ChoiceFigure, ChoiceOption, CitationSource, CitationsOptions, Column, ConfirmCard, ConfirmCardProps, ConfirmCost, ConfirmOptions, CostFigure, EntityOptions, EventSourceOptions, Figure, FileItem, ForkOptions, FormOptions, HypothesisOptions, InterpretationOptions, LongOptions, MethodOptions, MetricOptions, ModelSpecOptions, MultiOptions, MultistepOptions, NarrativeOptions, NumberOptions, PeriodOptions, Placeholder, PlaceholderProps, PlanOptions, PlayOptions, ProposalOptions, QuickOptions, QuickPick, RangeOptions, RecordRow, ScaleOptions, ScopeOptions, ScopePart, ShortOptions, SingleOptions, SuggestionChips, SuggestionChipsProps, SuggestionsOptions, Tone, TraceIoRow, TraceOptions, TraceStep, TypedValue, WeightsOptions, scriptLength } from '@invana/blocks';
|
|
4
|
+
import * as _invana_ui from '@invana/ui';
|
|
5
|
+
import { ChatSessionActivityRow as ChatSessionActivityRow$1, ChatSessionActivitySubLine as ChatSessionActivitySubLine$1, ChatSessionCaret as ChatSessionCaret$1, ChatSessionComposer as ChatSessionComposer$1, ChatSessionContextChip as ChatSessionContextChip$1, ChatSessionDisclosure as ChatSessionDisclosure$1, ChatSessionDisclosureCode as ChatSessionDisclosureCode$1, ChatSessionDisclosureSteps as ChatSessionDisclosureSteps$1, ChatSession as ChatSession$1, ChatSessionMessage as ChatSessionMessage$1, ChatSessionMessageOptions as ChatSessionMessageOptions$1, ChatSessionProgressLine as ChatSessionProgressLine$1, ChatSessionPromptRow as ChatSessionPromptRow$1, ChatSessionStatusBar as ChatSessionStatusBar$1, ChatSessionTaskGroup as ChatSessionTaskGroup$1, ChatSessionTaskRow as ChatSessionTaskRow$1 } from '@invana/ui';
|
|
6
|
+
export { ChatSessionActivityRowProps, ChatSessionActivityStatus, ChatSessionActivitySubLineProps, ChatSessionComposerProps, ChatSessionContextChipProps, ChatSessionDisclosureProps, ChatSessionDisclosureStepsProps, ChatSessionProps as ChatSessionFrameProps, ChatSessionMessageAction, ChatSessionMessageOptionsProps, ChatSessionMessageProps, ChatSessionMessageRole, ChatSessionMessageStatus, ChatSessionProgressLineProps, ChatSessionPromptRowProps, ChatSessionStatusBarProps, ChatSessionTaskGroupProps, ChatSessionTaskRowProps, ChatSessionTaskStatus, ClarifyActionsProps, ClarifyCardProps, ClarifyFootnoteProps, ClarifyOption, ClarifyState, EmissionCardProps, EmissionHeaderProps, EmissionKind, TemplateOption, TemplatePickerProps } from '@invana/ui';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Everything the analyst can do, as data. The component never acts on a
|
|
10
|
+
* conversation itself: it reports an event, and the API answers with patches.
|
|
11
|
+
*
|
|
12
|
+
* Every event but `prompt`, `stop` and `setting` names the turn it came from.
|
|
13
|
+
*/
|
|
14
|
+
type ConversationEvent =
|
|
15
|
+
/**
|
|
16
|
+
* A prompt. `settings` is what the composer's controls held — `{ mode: "nl",
|
|
17
|
+
* model: "qwen" }`; `files` what was attached, as the browser gave them.
|
|
18
|
+
*/
|
|
19
|
+
{
|
|
20
|
+
type: "prompt";
|
|
21
|
+
text: string;
|
|
22
|
+
context?: string[];
|
|
23
|
+
settings?: Record<string, string>;
|
|
24
|
+
files?: File[];
|
|
25
|
+
}
|
|
26
|
+
/** An ask was answered. `value` has the type its block fixes. */
|
|
27
|
+
| {
|
|
28
|
+
type: "reply";
|
|
29
|
+
turn: string;
|
|
30
|
+
value: unknown;
|
|
31
|
+
}
|
|
32
|
+
/** An ask was skipped; its default is used and recorded. */
|
|
33
|
+
| {
|
|
34
|
+
type: "skip";
|
|
35
|
+
turn: string;
|
|
36
|
+
}
|
|
37
|
+
/** An answered ask was changed. Re-runs from that turn, not from scratch. */
|
|
38
|
+
| {
|
|
39
|
+
type: "change";
|
|
40
|
+
turn: string;
|
|
41
|
+
value: unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An action the answer's spec declares — `approve`, `create-drafts` — or one a
|
|
45
|
+
* block names with what it carries: `select` with a table row's key,
|
|
46
|
+
* `download` with a file's digest.
|
|
47
|
+
*/
|
|
48
|
+
| {
|
|
49
|
+
type: "action";
|
|
50
|
+
turn: string;
|
|
51
|
+
action: string;
|
|
52
|
+
value?: unknown;
|
|
53
|
+
}
|
|
54
|
+
/** One part of an answer's scope line was edited. */
|
|
55
|
+
| {
|
|
56
|
+
type: "scope";
|
|
57
|
+
turn: string;
|
|
58
|
+
part: number;
|
|
59
|
+
value: unknown;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Open a block's records in full — the rows a table previews. `block` is its
|
|
63
|
+
* index in the turn's `blocks`.
|
|
64
|
+
*/
|
|
65
|
+
| {
|
|
66
|
+
type: "open";
|
|
67
|
+
turn: string;
|
|
68
|
+
block: number;
|
|
69
|
+
}
|
|
70
|
+
/** Render the same records as another block. */
|
|
71
|
+
| {
|
|
72
|
+
type: "template";
|
|
73
|
+
turn: string;
|
|
74
|
+
kind: string;
|
|
75
|
+
}
|
|
76
|
+
/** Change the current answer in place — `by-region`. */
|
|
77
|
+
| {
|
|
78
|
+
type: "refine";
|
|
79
|
+
turn: string;
|
|
80
|
+
refine: string;
|
|
81
|
+
} | {
|
|
82
|
+
type: "rate";
|
|
83
|
+
turn: string;
|
|
84
|
+
value: number;
|
|
85
|
+
} | {
|
|
86
|
+
type: "stop";
|
|
87
|
+
} | {
|
|
88
|
+
type: "retry";
|
|
89
|
+
turn: string;
|
|
90
|
+
}
|
|
91
|
+
/** Open the whole run behind an answer — its elapsed time was clicked. `step` when one step was. */
|
|
92
|
+
| {
|
|
93
|
+
type: "open-run";
|
|
94
|
+
turn: string;
|
|
95
|
+
step?: string;
|
|
96
|
+
}
|
|
97
|
+
/** A composer control changed — the mode, the model, the timeout. */
|
|
98
|
+
| {
|
|
99
|
+
type: "setting";
|
|
100
|
+
id: string;
|
|
101
|
+
value: string;
|
|
102
|
+
}
|
|
103
|
+
/** An answer's words were copied, as `text`. */
|
|
104
|
+
| {
|
|
105
|
+
type: "copy";
|
|
106
|
+
turn: string;
|
|
107
|
+
text: string;
|
|
108
|
+
}
|
|
109
|
+
/** An answer's steps were opened or folded. */
|
|
110
|
+
| {
|
|
111
|
+
type: "toggle-steps";
|
|
112
|
+
turn: string;
|
|
113
|
+
open: boolean;
|
|
114
|
+
};
|
|
115
|
+
type ConversationEventType = ConversationEvent["type"];
|
|
116
|
+
/** The event types, in the grammar's order. `grammar.test.ts` checks the union against it. */
|
|
117
|
+
declare const EVENT_TYPES: readonly ["prompt", "reply", "skip", "change", "action", "scope", "open", "template", "refine", "rate", "stop", "retry", "open-run", "setting", "copy", "toggle-steps"];
|
|
118
|
+
|
|
119
|
+
/** The seven stages every flow walks some of, in order. */
|
|
120
|
+
declare const STAGES: readonly [{
|
|
121
|
+
readonly id: "frame";
|
|
122
|
+
readonly name: "Frame";
|
|
123
|
+
}, {
|
|
124
|
+
readonly id: "scope";
|
|
125
|
+
readonly name: "Scope";
|
|
126
|
+
}, {
|
|
127
|
+
readonly id: "check";
|
|
128
|
+
readonly name: "Check data";
|
|
129
|
+
}, {
|
|
130
|
+
readonly id: "analyse";
|
|
131
|
+
readonly name: "Analyse";
|
|
132
|
+
}, {
|
|
133
|
+
readonly id: "explain";
|
|
134
|
+
readonly name: "Explain";
|
|
135
|
+
}, {
|
|
136
|
+
readonly id: "act";
|
|
137
|
+
readonly name: "Act";
|
|
138
|
+
}, {
|
|
139
|
+
readonly id: "monitor";
|
|
140
|
+
readonly name: "Monitor";
|
|
141
|
+
}];
|
|
142
|
+
type StageId = (typeof STAGES)[number]["id"];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Answer patterns: which blocks an answer has, in order. The flow picks the
|
|
146
|
+
* pattern, and `validate()` checks each answer against it.
|
|
147
|
+
*/
|
|
148
|
+
declare const PATTERNS: readonly [{
|
|
149
|
+
readonly id: "snapshot";
|
|
150
|
+
readonly name: "KPI snapshot";
|
|
151
|
+
readonly blocks: readonly ["grid", "timeseries", "narrative", "scope"];
|
|
152
|
+
}, {
|
|
153
|
+
readonly id: "bridge";
|
|
154
|
+
readonly name: "Change explanation";
|
|
155
|
+
readonly blocks: readonly ["narrative", "waterfall", "ranked", "citations"];
|
|
156
|
+
}, {
|
|
157
|
+
readonly id: "comparison";
|
|
158
|
+
readonly name: "Comparison";
|
|
159
|
+
readonly blocks: readonly ["bars", "table", "caveat"];
|
|
160
|
+
}, {
|
|
161
|
+
readonly id: "ranking";
|
|
162
|
+
readonly name: "Ranked list";
|
|
163
|
+
readonly blocks: readonly ["ranked", "table"];
|
|
164
|
+
}, {
|
|
165
|
+
readonly id: "profile";
|
|
166
|
+
readonly name: "Segment profile";
|
|
167
|
+
readonly blocks: readonly ["table", "bars", "narrative"];
|
|
168
|
+
}, {
|
|
169
|
+
readonly id: "cohort";
|
|
170
|
+
readonly name: "Cohort matrix";
|
|
171
|
+
readonly blocks: readonly ["matrix", "narrative"];
|
|
172
|
+
}, {
|
|
173
|
+
readonly id: "forecast";
|
|
174
|
+
readonly name: "Forecast";
|
|
175
|
+
readonly blocks: readonly ["timeseries", "record", "caveat"];
|
|
176
|
+
}, {
|
|
177
|
+
readonly id: "anomaly";
|
|
178
|
+
readonly name: "Anomaly report";
|
|
179
|
+
readonly blocks: readonly ["timeseries", "timeline", "ranked"];
|
|
180
|
+
}, {
|
|
181
|
+
readonly id: "drivers";
|
|
182
|
+
readonly name: "Driver ranking";
|
|
183
|
+
readonly blocks: readonly ["ranked", "narrative", "caveat"];
|
|
184
|
+
}, {
|
|
185
|
+
readonly id: "readout";
|
|
186
|
+
readonly name: "Experiment readout";
|
|
187
|
+
readonly blocks: readonly ["metric", "record", "caveat", "proposal"];
|
|
188
|
+
}, {
|
|
189
|
+
readonly id: "scenariot";
|
|
190
|
+
readonly name: "Scenario table";
|
|
191
|
+
readonly blocks: readonly ["record", "table", "ranked"];
|
|
192
|
+
}, {
|
|
193
|
+
readonly id: "funnelv";
|
|
194
|
+
readonly name: "Funnel";
|
|
195
|
+
readonly blocks: readonly ["funnel", "table"];
|
|
196
|
+
}, {
|
|
197
|
+
readonly id: "spread";
|
|
198
|
+
readonly name: "Distribution";
|
|
199
|
+
readonly blocks: readonly ["histogram", "table"];
|
|
200
|
+
}, {
|
|
201
|
+
readonly id: "quality";
|
|
202
|
+
readonly name: "Quality report";
|
|
203
|
+
readonly blocks: readonly ["checks", "table", "files"];
|
|
204
|
+
}, {
|
|
205
|
+
readonly id: "e360";
|
|
206
|
+
readonly name: "Entity 360";
|
|
207
|
+
readonly blocks: readonly ["record", "timeline", "table"];
|
|
208
|
+
}, {
|
|
209
|
+
readonly id: "relmap";
|
|
210
|
+
readonly name: "Relationship map";
|
|
211
|
+
readonly blocks: readonly ["subgraph", "ranked"];
|
|
212
|
+
}, {
|
|
213
|
+
readonly id: "memo";
|
|
214
|
+
readonly name: "Findings memo";
|
|
215
|
+
readonly blocks: readonly ["narrative", "citations", "caveat"];
|
|
216
|
+
}, {
|
|
217
|
+
readonly id: "recommend";
|
|
218
|
+
readonly name: "Recommendation";
|
|
219
|
+
readonly blocks: readonly ["table", "ranked", "proposal"];
|
|
220
|
+
}, {
|
|
221
|
+
readonly id: "delivery";
|
|
222
|
+
readonly name: "Scheduled delivery";
|
|
223
|
+
readonly blocks: readonly ["files", "proposal", "record"];
|
|
224
|
+
}, {
|
|
225
|
+
readonly id: "shortlist";
|
|
226
|
+
readonly name: "Candidate shortlist";
|
|
227
|
+
readonly blocks: readonly ["attr", "histogram", "caveat", "proposal"];
|
|
228
|
+
}, {
|
|
229
|
+
readonly id: "significance";
|
|
230
|
+
readonly name: "Significance test";
|
|
231
|
+
readonly blocks: readonly ["test", "box", "evidence", "caveat"];
|
|
232
|
+
}, {
|
|
233
|
+
readonly id: "effects";
|
|
234
|
+
readonly name: "Effect estimates";
|
|
235
|
+
readonly blocks: readonly ["coef", "forest", "method", "caveat"];
|
|
236
|
+
}, {
|
|
237
|
+
readonly id: "association";
|
|
238
|
+
readonly name: "Association";
|
|
239
|
+
readonly blocks: readonly ["correlation", "scatter", "caveat"];
|
|
240
|
+
}, {
|
|
241
|
+
readonly id: "spc";
|
|
242
|
+
readonly name: "Control report";
|
|
243
|
+
readonly blocks: readonly ["control", "pareto", "decomposition"];
|
|
244
|
+
}, {
|
|
245
|
+
readonly id: "timeto";
|
|
246
|
+
readonly name: "Time to event";
|
|
247
|
+
readonly blocks: readonly ["survival", "quantiles", "dumbbell", "caveat"];
|
|
248
|
+
}, {
|
|
249
|
+
readonly id: "modelcheck";
|
|
250
|
+
readonly name: "Model check";
|
|
251
|
+
readonly blocks: readonly ["modeleval", "profile", "pivot", "tornado"];
|
|
252
|
+
}];
|
|
253
|
+
type PatternId = (typeof PATTERNS)[number]["id"];
|
|
254
|
+
|
|
255
|
+
/** The things the assistant asks back, each on one block. */
|
|
256
|
+
declare const ASK_INTENTS: readonly [{
|
|
257
|
+
readonly id: "clarify";
|
|
258
|
+
readonly name: "Clarify what was meant";
|
|
259
|
+
readonly stage: "frame";
|
|
260
|
+
readonly kind: "single";
|
|
261
|
+
}, {
|
|
262
|
+
readonly id: "measure";
|
|
263
|
+
readonly name: "Choose the measure";
|
|
264
|
+
readonly stage: "frame";
|
|
265
|
+
readonly kind: "single";
|
|
266
|
+
}, {
|
|
267
|
+
readonly id: "definition";
|
|
268
|
+
readonly name: "Confirm a definition";
|
|
269
|
+
readonly stage: "frame";
|
|
270
|
+
readonly kind: "confirm";
|
|
271
|
+
}, {
|
|
272
|
+
readonly id: "hunch";
|
|
273
|
+
readonly name: "Share a hunch";
|
|
274
|
+
readonly stage: "frame";
|
|
275
|
+
readonly kind: "long";
|
|
276
|
+
}, {
|
|
277
|
+
readonly id: "window";
|
|
278
|
+
readonly name: "Time window";
|
|
279
|
+
readonly stage: "scope";
|
|
280
|
+
readonly kind: "period";
|
|
281
|
+
}, {
|
|
282
|
+
readonly id: "baseline";
|
|
283
|
+
readonly name: "Compare against";
|
|
284
|
+
readonly stage: "scope";
|
|
285
|
+
readonly kind: "single";
|
|
286
|
+
}, {
|
|
287
|
+
readonly id: "filter";
|
|
288
|
+
readonly name: "Filter and segment";
|
|
289
|
+
readonly stage: "scope";
|
|
290
|
+
readonly kind: "multi";
|
|
291
|
+
}, {
|
|
292
|
+
readonly id: "granularity";
|
|
293
|
+
readonly name: "Granularity";
|
|
294
|
+
readonly stage: "scope";
|
|
295
|
+
readonly kind: "quick";
|
|
296
|
+
}, {
|
|
297
|
+
readonly id: "entities";
|
|
298
|
+
readonly name: "Pick entities";
|
|
299
|
+
readonly stage: "scope";
|
|
300
|
+
readonly kind: "entity";
|
|
301
|
+
}, {
|
|
302
|
+
readonly id: "threshold";
|
|
303
|
+
readonly name: "Set a threshold";
|
|
304
|
+
readonly stage: "scope";
|
|
305
|
+
readonly kind: "number";
|
|
306
|
+
}, {
|
|
307
|
+
readonly id: "ambiguity";
|
|
308
|
+
readonly name: "Resolve ambiguity";
|
|
309
|
+
readonly stage: "check";
|
|
310
|
+
readonly kind: "single";
|
|
311
|
+
}, {
|
|
312
|
+
readonly id: "dataissue";
|
|
313
|
+
readonly name: "Handle a data issue";
|
|
314
|
+
readonly stage: "check";
|
|
315
|
+
readonly kind: "single";
|
|
316
|
+
}, {
|
|
317
|
+
readonly id: "cost";
|
|
318
|
+
readonly name: "Approve an expensive run";
|
|
319
|
+
readonly stage: "check";
|
|
320
|
+
readonly kind: "confirm";
|
|
321
|
+
}, {
|
|
322
|
+
readonly id: "method";
|
|
323
|
+
readonly name: "Choose a method";
|
|
324
|
+
readonly stage: "analyse";
|
|
325
|
+
readonly kind: "single";
|
|
326
|
+
}, {
|
|
327
|
+
readonly id: "assumptions";
|
|
328
|
+
readonly name: "Confirm assumptions";
|
|
329
|
+
readonly stage: "analyse";
|
|
330
|
+
readonly kind: "multi";
|
|
331
|
+
}, {
|
|
332
|
+
readonly id: "confidence";
|
|
333
|
+
readonly name: "Confidence level";
|
|
334
|
+
readonly stage: "analyse";
|
|
335
|
+
readonly kind: "quick";
|
|
336
|
+
}, {
|
|
337
|
+
readonly id: "objectives";
|
|
338
|
+
readonly name: "Weigh objectives";
|
|
339
|
+
readonly stage: "analyse";
|
|
340
|
+
readonly kind: "weights";
|
|
341
|
+
}, {
|
|
342
|
+
readonly id: "scenario";
|
|
343
|
+
readonly name: "Scenario inputs";
|
|
344
|
+
readonly stage: "analyse";
|
|
345
|
+
readonly kind: "form";
|
|
346
|
+
}, {
|
|
347
|
+
readonly id: "format";
|
|
348
|
+
readonly name: "Choose the output";
|
|
349
|
+
readonly stage: "explain";
|
|
350
|
+
readonly kind: "quick";
|
|
351
|
+
}, {
|
|
352
|
+
readonly id: "rate";
|
|
353
|
+
readonly name: "Rate the answer";
|
|
354
|
+
readonly stage: "explain";
|
|
355
|
+
readonly kind: "scale";
|
|
356
|
+
}, {
|
|
357
|
+
readonly id: "next";
|
|
358
|
+
readonly name: "Suggest what's next";
|
|
359
|
+
readonly stage: "explain";
|
|
360
|
+
readonly kind: "suggestions";
|
|
361
|
+
}, {
|
|
362
|
+
readonly id: "approve";
|
|
363
|
+
readonly name: "Approve an action";
|
|
364
|
+
readonly stage: "act";
|
|
365
|
+
readonly kind: "approval";
|
|
366
|
+
}, {
|
|
367
|
+
readonly id: "schedule";
|
|
368
|
+
readonly name: "Schedule and share";
|
|
369
|
+
readonly stage: "monitor";
|
|
370
|
+
readonly kind: "multistep";
|
|
371
|
+
}, {
|
|
372
|
+
readonly id: "reading";
|
|
373
|
+
readonly name: "Check my reading";
|
|
374
|
+
readonly stage: "frame";
|
|
375
|
+
readonly kind: "interpretation";
|
|
376
|
+
}, {
|
|
377
|
+
readonly id: "fork";
|
|
378
|
+
readonly name: "Pick a reading";
|
|
379
|
+
readonly stage: "frame";
|
|
380
|
+
readonly kind: "fork";
|
|
381
|
+
}, {
|
|
382
|
+
readonly id: "range";
|
|
383
|
+
readonly name: "Set a range";
|
|
384
|
+
readonly stage: "scope";
|
|
385
|
+
readonly kind: "range";
|
|
386
|
+
}, {
|
|
387
|
+
readonly id: "model";
|
|
388
|
+
readonly name: "Specify the model";
|
|
389
|
+
readonly stage: "analyse";
|
|
390
|
+
readonly kind: "modelspec";
|
|
391
|
+
}, {
|
|
392
|
+
readonly id: "plan";
|
|
393
|
+
readonly name: "Review the plan";
|
|
394
|
+
readonly stage: "analyse";
|
|
395
|
+
readonly kind: "plan";
|
|
396
|
+
}, {
|
|
397
|
+
readonly id: "hypothesis";
|
|
398
|
+
readonly name: "State the hypothesis";
|
|
399
|
+
readonly stage: "analyse";
|
|
400
|
+
readonly kind: "hypothesis";
|
|
401
|
+
}];
|
|
402
|
+
type AskIntentId = (typeof ASK_INTENTS)[number]["id"];
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* What an answer tells, each drawn by one or more blocks. The answer
|
|
406
|
+
* half of {@link ASK_INTENTS}: an intent is an id and a name, the block is the
|
|
407
|
+
* drawing, and several intents may share one block with different options.
|
|
408
|
+
*/
|
|
409
|
+
declare const ANSWER_INTENTS: readonly [{
|
|
410
|
+
readonly id: "say";
|
|
411
|
+
readonly name: "Say it in words";
|
|
412
|
+
readonly kinds: readonly ["narrative"];
|
|
413
|
+
}, {
|
|
414
|
+
readonly id: "figure";
|
|
415
|
+
readonly name: "One number, or a few";
|
|
416
|
+
readonly kinds: readonly ["metric", "grid"];
|
|
417
|
+
}, {
|
|
418
|
+
readonly id: "trend";
|
|
419
|
+
readonly name: "Change over time";
|
|
420
|
+
readonly kinds: readonly ["timeseries", "control"];
|
|
421
|
+
}, {
|
|
422
|
+
readonly id: "compare";
|
|
423
|
+
readonly name: "Groups side by side";
|
|
424
|
+
readonly kinds: readonly ["bars", "dumbbell", "matrix", "funnel"];
|
|
425
|
+
}, {
|
|
426
|
+
readonly id: "rank";
|
|
427
|
+
readonly name: "Leaders and laggards";
|
|
428
|
+
readonly kinds: readonly ["ranked", "pareto", "tornado"];
|
|
429
|
+
}, {
|
|
430
|
+
readonly id: "explain-change";
|
|
431
|
+
readonly name: "What moved the total";
|
|
432
|
+
readonly kinds: readonly ["waterfall", "decomposition"];
|
|
433
|
+
}, {
|
|
434
|
+
readonly id: "records";
|
|
435
|
+
readonly name: "Rows, or one entity";
|
|
436
|
+
readonly kinds: readonly ["table", "record", "attr", "pivot", "profile"];
|
|
437
|
+
}, {
|
|
438
|
+
readonly id: "sequence";
|
|
439
|
+
readonly name: "What happened when";
|
|
440
|
+
readonly kinds: readonly ["timeline", "heatstrip"];
|
|
441
|
+
}, {
|
|
442
|
+
readonly id: "spread";
|
|
443
|
+
readonly name: "The shape of the values";
|
|
444
|
+
readonly kinds: readonly ["histogram", "box", "quantiles", "survival"];
|
|
445
|
+
}, {
|
|
446
|
+
readonly id: "relate";
|
|
447
|
+
readonly name: "How things connect";
|
|
448
|
+
readonly kinds: readonly ["scatter", "correlation", "subgraph"];
|
|
449
|
+
}, {
|
|
450
|
+
readonly id: "stats";
|
|
451
|
+
readonly name: "Test and model results";
|
|
452
|
+
readonly kinds: readonly ["test", "coef", "forest", "evidence", "modeleval"];
|
|
453
|
+
}, {
|
|
454
|
+
readonly id: "trust";
|
|
455
|
+
readonly name: "Method, sources, scope and limits";
|
|
456
|
+
readonly kinds: readonly ["method", "citations", "scope", "caveat", "cannot", "checks"];
|
|
457
|
+
}, {
|
|
458
|
+
readonly id: "act";
|
|
459
|
+
readonly name: "A proposed action, or a file";
|
|
460
|
+
readonly kinds: readonly ["proposal", "files"];
|
|
461
|
+
}, {
|
|
462
|
+
readonly id: "run.steps";
|
|
463
|
+
readonly name: "What the run did, in order";
|
|
464
|
+
readonly kinds: readonly ["trace", "gantt"];
|
|
465
|
+
}, {
|
|
466
|
+
readonly id: "run.activity";
|
|
467
|
+
readonly name: "Which layers were busy";
|
|
468
|
+
readonly kinds: readonly ["activity"];
|
|
469
|
+
}];
|
|
470
|
+
type AnswerIntentId = (typeof ANSWER_INTENTS)[number]["id"];
|
|
471
|
+
|
|
472
|
+
/** The research flows: the shapes of question analysts bring. */
|
|
473
|
+
declare const FLOWS: readonly [{
|
|
474
|
+
readonly id: "kpi";
|
|
475
|
+
readonly name: "KPI check";
|
|
476
|
+
readonly template: "How is {measure} tracking against {baseline}?";
|
|
477
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
478
|
+
readonly asks: readonly ["measure", "window", "baseline"];
|
|
479
|
+
readonly pattern: "snapshot";
|
|
480
|
+
}, {
|
|
481
|
+
readonly id: "diagnose";
|
|
482
|
+
readonly name: "Root cause";
|
|
483
|
+
readonly template: "Why did {measure} change in {period}?";
|
|
484
|
+
readonly stages: readonly ["frame", "scope", "check", "analyse", "explain", "act"];
|
|
485
|
+
readonly asks: readonly ["measure", "window", "baseline", "hunch"];
|
|
486
|
+
readonly pattern: "bridge";
|
|
487
|
+
}, {
|
|
488
|
+
readonly id: "compare";
|
|
489
|
+
readonly name: "Comparison & benchmark";
|
|
490
|
+
readonly template: "How does {A} compare with {B} on {measures}?";
|
|
491
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
492
|
+
readonly asks: readonly ["entities", "measure", "confidence"];
|
|
493
|
+
readonly pattern: "comparison";
|
|
494
|
+
}, {
|
|
495
|
+
readonly id: "rank";
|
|
496
|
+
readonly name: "Top-N ranking";
|
|
497
|
+
readonly template: "Which {entities} lead or lag on {measure}?";
|
|
498
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain", "act"];
|
|
499
|
+
readonly asks: readonly ["measure", "filter", "threshold"];
|
|
500
|
+
readonly pattern: "ranking";
|
|
501
|
+
}, {
|
|
502
|
+
readonly id: "segment";
|
|
503
|
+
readonly name: "Segmentation";
|
|
504
|
+
readonly template: "What groups exist within {population}, and how do they differ?";
|
|
505
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
506
|
+
readonly asks: readonly ["filter", "method", "assumptions"];
|
|
507
|
+
readonly pattern: "profile";
|
|
508
|
+
}, {
|
|
509
|
+
readonly id: "cohort";
|
|
510
|
+
readonly name: "Cohort & retention";
|
|
511
|
+
readonly template: "How do {cohorts} behave over time?";
|
|
512
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
513
|
+
readonly asks: readonly ["definition", "window", "granularity"];
|
|
514
|
+
readonly pattern: "cohort";
|
|
515
|
+
}, {
|
|
516
|
+
readonly id: "forecast";
|
|
517
|
+
readonly name: "Trend & forecast";
|
|
518
|
+
readonly template: "Where is {measure} heading?";
|
|
519
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain", "monitor"];
|
|
520
|
+
readonly asks: readonly ["window", "granularity", "method", "assumptions"];
|
|
521
|
+
readonly pattern: "forecast";
|
|
522
|
+
}, {
|
|
523
|
+
readonly id: "anomaly";
|
|
524
|
+
readonly name: "Anomaly & monitoring";
|
|
525
|
+
readonly template: "Tell me when {measure} behaves unusually.";
|
|
526
|
+
readonly stages: readonly ["scope", "analyse", "act", "monitor"];
|
|
527
|
+
readonly asks: readonly ["measure", "threshold", "approve", "schedule"];
|
|
528
|
+
readonly pattern: "anomaly";
|
|
529
|
+
}, {
|
|
530
|
+
readonly id: "drivers";
|
|
531
|
+
readonly name: "Driver analysis";
|
|
532
|
+
readonly template: "What moves {measure}?";
|
|
533
|
+
readonly stages: readonly ["frame", "analyse", "explain"];
|
|
534
|
+
readonly asks: readonly ["measure", "method", "assumptions"];
|
|
535
|
+
readonly pattern: "drivers";
|
|
536
|
+
}, {
|
|
537
|
+
readonly id: "experiment";
|
|
538
|
+
readonly name: "Experiment readout";
|
|
539
|
+
readonly template: "Did {change} work?";
|
|
540
|
+
readonly stages: readonly ["frame", "check", "analyse", "explain", "act"];
|
|
541
|
+
readonly asks: readonly ["entities", "definition", "confidence"];
|
|
542
|
+
readonly pattern: "readout";
|
|
543
|
+
}, {
|
|
544
|
+
readonly id: "scenario";
|
|
545
|
+
readonly name: "Scenario & what-if";
|
|
546
|
+
readonly template: "What happens to {outcome} if {input} changes?";
|
|
547
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain", "act"];
|
|
548
|
+
readonly asks: readonly ["scenario", "assumptions"];
|
|
549
|
+
readonly pattern: "scenariot";
|
|
550
|
+
}, {
|
|
551
|
+
readonly id: "funnel";
|
|
552
|
+
readonly name: "Funnel & journey";
|
|
553
|
+
readonly template: "Where do {entities} drop out of {process}?";
|
|
554
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
555
|
+
readonly asks: readonly ["definition", "window", "filter"];
|
|
556
|
+
readonly pattern: "funnelv";
|
|
557
|
+
}, {
|
|
558
|
+
readonly id: "distribution";
|
|
559
|
+
readonly name: "Distribution & outliers";
|
|
560
|
+
readonly template: "What does the spread of {measure} look like, and what sits outside it?";
|
|
561
|
+
readonly stages: readonly ["scope", "analyse", "explain"];
|
|
562
|
+
readonly asks: readonly ["measure", "filter", "threshold"];
|
|
563
|
+
readonly pattern: "spread";
|
|
564
|
+
}, {
|
|
565
|
+
readonly id: "audit";
|
|
566
|
+
readonly name: "Data audit & reconciliation";
|
|
567
|
+
readonly template: "Can I trust {dataset}? Do {A} and {B} agree?";
|
|
568
|
+
readonly stages: readonly ["check", "analyse", "explain", "act"];
|
|
569
|
+
readonly asks: readonly ["definition", "dataissue", "cost"];
|
|
570
|
+
readonly pattern: "quality";
|
|
571
|
+
}, {
|
|
572
|
+
readonly id: "entity";
|
|
573
|
+
readonly name: "Entity lookup (360)";
|
|
574
|
+
readonly template: "Tell me everything about {entity}.";
|
|
575
|
+
readonly stages: readonly ["frame", "check", "explain"];
|
|
576
|
+
readonly asks: readonly ["ambiguity", "entities"];
|
|
577
|
+
readonly pattern: "e360";
|
|
578
|
+
}, {
|
|
579
|
+
readonly id: "network";
|
|
580
|
+
readonly name: "Relationships & networks";
|
|
581
|
+
readonly template: "How are {entities} connected?";
|
|
582
|
+
readonly stages: readonly ["frame", "scope", "check", "analyse", "explain"];
|
|
583
|
+
readonly asks: readonly ["entities", "threshold", "cost"];
|
|
584
|
+
readonly pattern: "relmap";
|
|
585
|
+
}, {
|
|
586
|
+
readonly id: "qual";
|
|
587
|
+
readonly name: "Qualitative synthesis";
|
|
588
|
+
readonly template: "What are people saying about {topic}?";
|
|
589
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
590
|
+
readonly asks: readonly ["filter", "window", "hunch"];
|
|
591
|
+
readonly pattern: "memo";
|
|
592
|
+
}, {
|
|
593
|
+
readonly id: "recommend";
|
|
594
|
+
readonly name: "Recommendation & priority";
|
|
595
|
+
readonly template: "What should we do about {problem}, and in what order?";
|
|
596
|
+
readonly stages: readonly ["analyse", "explain", "act"];
|
|
597
|
+
readonly asks: readonly ["assumptions", "method", "approve"];
|
|
598
|
+
readonly pattern: "recommend";
|
|
599
|
+
}, {
|
|
600
|
+
readonly id: "report";
|
|
601
|
+
readonly name: "Report & schedule";
|
|
602
|
+
readonly template: "Send me {analysis} every {cadence}.";
|
|
603
|
+
readonly stages: readonly ["explain", "act", "monitor"];
|
|
604
|
+
readonly asks: readonly ["format", "schedule", "approve"];
|
|
605
|
+
readonly pattern: "delivery";
|
|
606
|
+
}, {
|
|
607
|
+
readonly id: "combine";
|
|
608
|
+
readonly name: "Combination design";
|
|
609
|
+
readonly template: "Which combination of {candidates} best meets {objectives}?";
|
|
610
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain", "act"];
|
|
611
|
+
readonly asks: readonly ["entities", "objectives", "threshold", "assumptions"];
|
|
612
|
+
readonly pattern: "shortlist";
|
|
613
|
+
}, {
|
|
614
|
+
readonly id: "significance";
|
|
615
|
+
readonly name: "Significance test";
|
|
616
|
+
readonly template: "Is the difference in {measure} between {A} and {B} real?";
|
|
617
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
618
|
+
readonly asks: readonly ["hypothesis", "confidence", "assumptions"];
|
|
619
|
+
readonly pattern: "significance";
|
|
620
|
+
}, {
|
|
621
|
+
readonly id: "effects";
|
|
622
|
+
readonly name: "Effect estimation";
|
|
623
|
+
readonly template: "How much does each {factor} change {outcome}, holding the others fixed?";
|
|
624
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
625
|
+
readonly asks: readonly ["model", "plan", "assumptions"];
|
|
626
|
+
readonly pattern: "effects";
|
|
627
|
+
}, {
|
|
628
|
+
readonly id: "association";
|
|
629
|
+
readonly name: "Correlation & association";
|
|
630
|
+
readonly template: "Which {measures} move together, and how strongly?";
|
|
631
|
+
readonly stages: readonly ["frame", "scope", "check", "analyse", "explain"];
|
|
632
|
+
readonly asks: readonly ["reading", "filter", "range"];
|
|
633
|
+
readonly pattern: "association";
|
|
634
|
+
}, {
|
|
635
|
+
readonly id: "spc";
|
|
636
|
+
readonly name: "Process control";
|
|
637
|
+
readonly template: "Is {process} in control, and what causes most of the defects?";
|
|
638
|
+
readonly stages: readonly ["scope", "analyse", "explain", "monitor"];
|
|
639
|
+
readonly asks: readonly ["window", "granularity", "range"];
|
|
640
|
+
readonly pattern: "spc";
|
|
641
|
+
}, {
|
|
642
|
+
readonly id: "timeto";
|
|
643
|
+
readonly name: "Time to event";
|
|
644
|
+
readonly template: "How long until {event}, and does it differ by {group}?";
|
|
645
|
+
readonly stages: readonly ["frame", "scope", "analyse", "explain"];
|
|
646
|
+
readonly asks: readonly ["definition", "fork", "window"];
|
|
647
|
+
readonly pattern: "timeto";
|
|
648
|
+
}, {
|
|
649
|
+
readonly id: "modelcheck";
|
|
650
|
+
readonly name: "Model check";
|
|
651
|
+
readonly template: "How well does {model} predict {outcome}, and where does it fail?";
|
|
652
|
+
readonly stages: readonly ["check", "analyse", "explain", "act"];
|
|
653
|
+
readonly asks: readonly ["model", "range", "plan"];
|
|
654
|
+
readonly pattern: "modelcheck";
|
|
655
|
+
}];
|
|
656
|
+
type FlowId = (typeof FLOWS)[number]["id"];
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* A conversation is **data**, like a board. Everything in this file is
|
|
660
|
+
* JSON-serialisable: the API sends a {@link ConversationSpec}, then patches;
|
|
661
|
+
* the component renders whatever spec it is given and sends events back.
|
|
662
|
+
*
|
|
663
|
+
* The shapes are fixed by the Design Kit Spec. An block fixes the type of
|
|
664
|
+
* the value that comes back; a block fixes the options it reads; a
|
|
665
|
+
* pattern fixes which blocks an answer has. A screen that needs more is a
|
|
666
|
+
* grammar change or a new block, never an extra field here.
|
|
667
|
+
*/
|
|
668
|
+
/** Everything a block carries apart from its options. */
|
|
669
|
+
interface BlockBase {
|
|
670
|
+
/** The line under a block — `kg/ha per step of each trait`. */
|
|
671
|
+
caption?: string;
|
|
672
|
+
/** `warn` when the line is a warning — `North rests on 9 stores · indicative`. */
|
|
673
|
+
captionTone?: Tone;
|
|
674
|
+
/**
|
|
675
|
+
* `loading` draws the block's skeleton while its data is on the way; `empty`
|
|
676
|
+
* says there is nothing to draw, in `emptyText`. The card's header stays in both.
|
|
677
|
+
*/
|
|
678
|
+
status?: "loading" | "empty";
|
|
679
|
+
/** What is missing, said out loud — `No renewals fell due in September`. */
|
|
680
|
+
emptyText?: string;
|
|
681
|
+
/** Follow-ups under an empty block that would find something — `Search “Acme”`. */
|
|
682
|
+
emptySuggestions?: string[];
|
|
683
|
+
}
|
|
684
|
+
type BlockSpec = {
|
|
685
|
+
[P in AnswerKind]: BlockBase & {
|
|
686
|
+
kind: P;
|
|
687
|
+
} & AnswerOptionsByKind[P];
|
|
688
|
+
}[AnswerKind];
|
|
689
|
+
/**
|
|
690
|
+
* What every analytic answer states, in the same place. These sit on the
|
|
691
|
+
* answer, never as free blocks, so no answer can forget one or move it.
|
|
692
|
+
*/
|
|
693
|
+
interface Envelope {
|
|
694
|
+
/** Period, filters and population, exactly as applied. */
|
|
695
|
+
scope?: string[];
|
|
696
|
+
/** How many records the answer rests on. Zero is said, never left out. */
|
|
697
|
+
grounding?: {
|
|
698
|
+
records: number;
|
|
699
|
+
noun: string;
|
|
700
|
+
};
|
|
701
|
+
/** When the data was last loaded — `28 Sep 06:00`. Shown as `as of …`. */
|
|
702
|
+
freshness?: string;
|
|
703
|
+
/** The formula, query or model behind the figure. */
|
|
704
|
+
method?: string;
|
|
705
|
+
caveats?: {
|
|
706
|
+
label: string;
|
|
707
|
+
text: string;
|
|
708
|
+
}[];
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* `running` is being produced; `partial` is answered in part — settled, the
|
|
712
|
+
* rest in the background or not to be had; `stopped` was interrupted.
|
|
713
|
+
*/
|
|
714
|
+
type AnswerState = "running" | "partial" | "complete" | "cannot" | "error" | "stopped";
|
|
715
|
+
interface AnalystTurn {
|
|
716
|
+
id: string;
|
|
717
|
+
role: "analyst";
|
|
718
|
+
text: string;
|
|
719
|
+
/** What the prompt was about — carried scope, a selection. */
|
|
720
|
+
context?: string[];
|
|
721
|
+
/** When it was sent, as an ISO 8601 time. */
|
|
722
|
+
at?: string;
|
|
723
|
+
}
|
|
724
|
+
interface AskTurn {
|
|
725
|
+
id: string;
|
|
726
|
+
role: "assistant";
|
|
727
|
+
kind: "ask";
|
|
728
|
+
stage: StageId;
|
|
729
|
+
state: AskState;
|
|
730
|
+
ask: AskSpec;
|
|
731
|
+
/** The analyst's reply, once answered. Its type is fixed by the block. */
|
|
732
|
+
value?: unknown;
|
|
733
|
+
/** When it was answered, as an ISO 8601 time. Shown as `just now`, `2 min ago`. */
|
|
734
|
+
answeredAt?: string;
|
|
735
|
+
/** How long a pending ask has been left, already worded — `parked 1 min`. */
|
|
736
|
+
waiting?: string;
|
|
737
|
+
}
|
|
738
|
+
interface AnswerTurn {
|
|
739
|
+
id: string;
|
|
740
|
+
role: "assistant";
|
|
741
|
+
kind: "answer";
|
|
742
|
+
state: AnswerState;
|
|
743
|
+
flow?: FlowId;
|
|
744
|
+
pattern?: PatternId;
|
|
745
|
+
/** The word on the card's header strip — `chart`, `ranked`. */
|
|
746
|
+
label?: string;
|
|
747
|
+
/** What the card shows — `P&L attribution, £M`. */
|
|
748
|
+
title?: string;
|
|
749
|
+
/** The right of the header strip when nothing is cited — `3 files · 166 KB`. */
|
|
750
|
+
aside?: string;
|
|
751
|
+
envelope?: Envelope;
|
|
752
|
+
/** Streamed while the answer runs; kept as the record of what was done. */
|
|
753
|
+
trace?: TraceStep[];
|
|
754
|
+
blocks: BlockSpec[];
|
|
755
|
+
/** When the run started, as an ISO 8601 time. A running answer counts up from it. */
|
|
756
|
+
startedAt?: string;
|
|
757
|
+
/** When it settled, as an ISO 8601 time. */
|
|
758
|
+
at?: string;
|
|
759
|
+
/** How long the run took, in ms — `Answered in 1.4 s`. */
|
|
760
|
+
duration?: number;
|
|
761
|
+
/** The run's facts in one line — `local · qwen3-27b · 14 rows · query 1.4 s`. */
|
|
762
|
+
meta?: string;
|
|
763
|
+
/** What the run produced, outside the thread, and what can be done with it. */
|
|
764
|
+
outcome?: Outcome;
|
|
765
|
+
/** How the analyst rated it — `1` good, `-1` not what they wanted. Sent as a `rate` event. */
|
|
766
|
+
rating?: number;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* What a run produced, outside the thread — `14 nodes · 212 relationships`
|
|
770
|
+
* with `Load to canvas`; or, when it failed, what to do next. Each action is
|
|
771
|
+
* sent as an `action` event.
|
|
772
|
+
*/
|
|
773
|
+
interface Outcome {
|
|
774
|
+
text?: string;
|
|
775
|
+
actions?: ActionOption[];
|
|
776
|
+
}
|
|
777
|
+
type Turn = AnalystTurn | AskTurn | AnswerTurn;
|
|
778
|
+
interface ConversationSpec {
|
|
779
|
+
id: string;
|
|
780
|
+
title?: string;
|
|
781
|
+
/**
|
|
782
|
+
* What the analyst is called in this thread — `Planner`, `Researcher`. When
|
|
783
|
+
* set, their prompts and the assistant's asks are labelled with who is
|
|
784
|
+
* speaking; answers are cards and need no label.
|
|
785
|
+
*/
|
|
786
|
+
analyst?: string;
|
|
787
|
+
/** What the assistant is called in this thread — `Analyst`. Labels its turns where speakers are labelled. */
|
|
788
|
+
assistant?: string;
|
|
789
|
+
/** Scope carried by the whole thread, until a turn changes it. */
|
|
790
|
+
scope?: Record<string, string>;
|
|
791
|
+
/**
|
|
792
|
+
* Who is answering, what it can reach, what it may spend and the rules it
|
|
793
|
+
* runs under — sent with the spec for the host's header (`AgentHeader`,
|
|
794
|
+
* passed as `header`). The session itself draws none of them.
|
|
795
|
+
*/
|
|
796
|
+
agent?: AgentSpec;
|
|
797
|
+
/** The data this session can reach. Set when the session starts; never changed by a turn. */
|
|
798
|
+
access?: AccessSpec;
|
|
799
|
+
/** Tokens spent in this session, of the budget it was given. Tokens, never money. */
|
|
800
|
+
budget?: {
|
|
801
|
+
used: number;
|
|
802
|
+
limit: number;
|
|
803
|
+
};
|
|
804
|
+
/** The rules the session runs under — read-only here; changed in the host's settings. */
|
|
805
|
+
governance?: GovernanceSpec;
|
|
806
|
+
/** What the composer offers besides the text — mode, model, timeout, files. */
|
|
807
|
+
composer?: ComposerSpec;
|
|
808
|
+
turns: Turn[];
|
|
809
|
+
}
|
|
810
|
+
interface AgentSpec {
|
|
811
|
+
/** `Analyst`. */
|
|
812
|
+
name: string;
|
|
813
|
+
/** `v2`. */
|
|
814
|
+
version?: string;
|
|
815
|
+
/** `sonnet-5.5`. */
|
|
816
|
+
model?: string;
|
|
817
|
+
}
|
|
818
|
+
/** One published model, and what this session may do with it. */
|
|
819
|
+
interface AccessModel {
|
|
820
|
+
id: string;
|
|
821
|
+
name: string;
|
|
822
|
+
/**
|
|
823
|
+
* Records this session can see, after its slice. Left out while the count is
|
|
824
|
+
* on its way; the API keeps it current with `set-records`.
|
|
825
|
+
*/
|
|
826
|
+
records?: number | null;
|
|
827
|
+
/** `["read"]`, `["read", "write"]`, or `"denied"`. */
|
|
828
|
+
access: string[] | "denied";
|
|
829
|
+
/** What the session's view is narrowed to — `time 2019 → now · axis announced_at`. */
|
|
830
|
+
slice?: string;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* The data a session can reach. `world` is the whole graph the session opened
|
|
834
|
+
* on; `group` is an access group's share of it, named in `label`.
|
|
835
|
+
*/
|
|
836
|
+
interface AccessSpec {
|
|
837
|
+
kind: "world" | "group";
|
|
838
|
+
/** `Accounts graph`, `Finance-EU`. */
|
|
839
|
+
label: string;
|
|
840
|
+
models?: AccessModel[];
|
|
841
|
+
}
|
|
842
|
+
interface GovernanceSpec {
|
|
843
|
+
/** The strictest rule in force, as the badge says it — `Read-only`, `Governed`. */
|
|
844
|
+
summary: string;
|
|
845
|
+
/** The rules, in order — `Permissions: read-only`, `Retention: 30 days`. */
|
|
846
|
+
rules?: {
|
|
847
|
+
label: string;
|
|
848
|
+
value: string;
|
|
849
|
+
}[];
|
|
850
|
+
/** Where data may leave to, per destination, and what may go. */
|
|
851
|
+
egress?: {
|
|
852
|
+
to: string;
|
|
853
|
+
classes?: string[];
|
|
854
|
+
}[];
|
|
855
|
+
}
|
|
856
|
+
/** One choice of a composer control. */
|
|
857
|
+
interface ComposerOption {
|
|
858
|
+
value: string;
|
|
859
|
+
label: string;
|
|
860
|
+
/** The composer's placeholder while this is picked — `MATCH (n) WHERE … RETURN n`. */
|
|
861
|
+
placeholder?: string;
|
|
862
|
+
/** Set the prompt in mono while this is picked — a query language. */
|
|
863
|
+
mono?: boolean;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* A select in the composer's toolbar — `Natural Language`, `local · qwen3-27b`,
|
|
867
|
+
* `2m`. What is picked is sent with every prompt, under its `id`.
|
|
868
|
+
*/
|
|
869
|
+
interface ComposerControl {
|
|
870
|
+
id: string;
|
|
871
|
+
/** Its accessible name and tooltip — `Model`, `LLM + query timeout`. */
|
|
872
|
+
label: string;
|
|
873
|
+
options: ComposerOption[];
|
|
874
|
+
/** Picked at first. Defaults to the first option. */
|
|
875
|
+
default?: string;
|
|
876
|
+
/** `start` sits with the text controls; `end` beside send. @default "start" */
|
|
877
|
+
align?: "start" | "end";
|
|
878
|
+
/** An icon before the value: the path data of a 16×16 stroked icon. */
|
|
879
|
+
icon?: string;
|
|
880
|
+
/** Muted: a setting, not the mode. */
|
|
881
|
+
quiet?: boolean;
|
|
882
|
+
}
|
|
883
|
+
interface ComposerSpec {
|
|
884
|
+
placeholder?: string;
|
|
885
|
+
controls?: ComposerControl[];
|
|
886
|
+
/** Offer attaching files; `accept` is the input's accept list. */
|
|
887
|
+
attach?: boolean | {
|
|
888
|
+
accept?: string;
|
|
889
|
+
multiple?: boolean;
|
|
890
|
+
};
|
|
891
|
+
/** Keyboard hints under the composer — `↵ send`, `esc stop`. @default true */
|
|
892
|
+
hints?: boolean;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
interface AskRendererProps<P extends AskKind = AskKind> {
|
|
896
|
+
turn: AskTurn;
|
|
897
|
+
/** The ask's options, already narrowed to its block. */
|
|
898
|
+
options: AskOptionsByKind[P];
|
|
899
|
+
onEvent: (event: ConversationEvent) => void;
|
|
900
|
+
}
|
|
901
|
+
interface BlockRendererProps<P extends AnswerKind = AnswerKind> {
|
|
902
|
+
turn: AnswerTurn;
|
|
903
|
+
/** The block's options, already narrowed to its block. */
|
|
904
|
+
block: BlockBase & AnswerOptionsByKind[P];
|
|
905
|
+
onEvent: (event: ConversationEvent) => void;
|
|
906
|
+
}
|
|
907
|
+
type AskRenderer<P extends AskKind = any> = React.ComponentType<AskRendererProps<P>>;
|
|
908
|
+
type BlockRenderer<P extends AnswerKind = any> = React.ComponentType<BlockRendererProps<P>>;
|
|
909
|
+
/**
|
|
910
|
+
* Every block the grammar names, and what renders it. `null` is a block
|
|
911
|
+
* not built yet: it renders as a labelled placeholder, so the number of `null`s
|
|
912
|
+
* is the work left and a session story shows exactly where.
|
|
913
|
+
*
|
|
914
|
+
* Keyed by the grammar's ids, so a block added to the grammar and not here is
|
|
915
|
+
* a compile error, and `grammar.test.ts` checks the same at runtime.
|
|
916
|
+
*/
|
|
917
|
+
type AskRegistry = {
|
|
918
|
+
[P in AskKind]: AskRenderer<P> | null;
|
|
919
|
+
};
|
|
920
|
+
type BlockRegistry = {
|
|
921
|
+
[P in AnswerKind]: BlockRenderer<P> | null;
|
|
922
|
+
};
|
|
923
|
+
declare const BUILT_IN_ASKS: AskRegistry;
|
|
924
|
+
declare const BUILT_IN_BLOCKS: BlockRegistry;
|
|
925
|
+
/**
|
|
926
|
+
* How an ask sits in the thread, apart from what its renderer draws.
|
|
927
|
+
*
|
|
928
|
+
* `frame: "card"` draws it in the ask card, with its state, the stage that
|
|
929
|
+
* asked and when it was answered; `"none"` draws the renderer alone — chips
|
|
930
|
+
* that show their own pick. `kind` is the card's header word while it waits.
|
|
931
|
+
*/
|
|
932
|
+
interface AskTraits {
|
|
933
|
+
frame?: "card" | "none";
|
|
934
|
+
kind?: string;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* How a block sits in an answer. `"card"` is inside the answer card with the
|
|
938
|
+
* rest of the evidence; `"own"` is a card of its own under it — a proposal is
|
|
939
|
+
* something to approve, not part of the evidence.
|
|
940
|
+
*/
|
|
941
|
+
interface BlockTraits {
|
|
942
|
+
placement?: "card" | "own";
|
|
943
|
+
}
|
|
944
|
+
/** Traits of the built-in blocks; every block not named takes the defaults. */
|
|
945
|
+
declare const BUILT_IN_ASK_TRAITS: Partial<Record<string, AskTraits>>;
|
|
946
|
+
declare const BUILT_IN_BLOCK_TRAITS: Partial<Record<string, BlockTraits>>;
|
|
947
|
+
/**
|
|
948
|
+
* Renderers a consumer adds or replaces — `{ blocks: { subgraph: CanvasBlock } }`
|
|
949
|
+
* — with their traits. Consumer entries win over the built-ins, as in the
|
|
950
|
+
* board, so a template of your own sits in the thread exactly as you say.
|
|
951
|
+
*/
|
|
952
|
+
interface RegistryOverrides {
|
|
953
|
+
asks?: Partial<Record<string, AskRenderer>>;
|
|
954
|
+
blocks?: Partial<Record<string, BlockRenderer>>;
|
|
955
|
+
askTraits?: Partial<Record<string, AskTraits>>;
|
|
956
|
+
blockTraits?: Partial<Record<string, BlockTraits>>;
|
|
957
|
+
}
|
|
958
|
+
interface ResolvedRegistry {
|
|
959
|
+
asks: Record<string, AskRenderer | null | undefined>;
|
|
960
|
+
blocks: Record<string, BlockRenderer | null | undefined>;
|
|
961
|
+
askTraits: (kind: string) => Required<Pick<AskTraits, "frame">> & AskTraits;
|
|
962
|
+
blockTraits: (kind: string) => Required<BlockTraits>;
|
|
963
|
+
}
|
|
964
|
+
declare function resolveRegistry(extra?: RegistryOverrides): ResolvedRegistry;
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* How a spec changes while an answer streams. The API sends one of these at a
|
|
968
|
+
* time; {@link applyPatch} returns a new spec and never mutates the old one, so
|
|
969
|
+
* a controlled `<ChatSession spec>` re-renders exactly what changed.
|
|
970
|
+
*/
|
|
971
|
+
type ConversationPatch = {
|
|
972
|
+
op: "add-turn";
|
|
973
|
+
turn: Turn;
|
|
974
|
+
}
|
|
975
|
+
/** Move a turn through its states. An answered ask carries its `value`. */
|
|
976
|
+
| {
|
|
977
|
+
op: "set-state";
|
|
978
|
+
turn: string;
|
|
979
|
+
state: AskState | AnswerState;
|
|
980
|
+
value?: unknown;
|
|
981
|
+
} | {
|
|
982
|
+
op: "add-block";
|
|
983
|
+
turn: string;
|
|
984
|
+
block: BlockSpec;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Stream a block: one {@link BlockPatch} — the same patch a board or a page
|
|
988
|
+
* streams the block by. `block` is its index, the last block when left out.
|
|
989
|
+
*/
|
|
990
|
+
| {
|
|
991
|
+
op: "patch-block";
|
|
992
|
+
turn: string;
|
|
993
|
+
block?: number;
|
|
994
|
+
patch: BlockPatch;
|
|
995
|
+
}
|
|
996
|
+
/** Change a block in place — its rows arriving, a loading block settling. `block` is its index. A `set` block patch. */
|
|
997
|
+
| {
|
|
998
|
+
op: "update-block";
|
|
999
|
+
turn: string;
|
|
1000
|
+
block: number;
|
|
1001
|
+
fields: Record<string, unknown>;
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Stream words into a block: `text` is appended to its string `field`
|
|
1005
|
+
* (default `text`). `block` is its index, the last block when left out — so
|
|
1006
|
+
* a stream sends `add-block` with the field empty, then its words. An
|
|
1007
|
+
* `append` block patch.
|
|
1008
|
+
*/
|
|
1009
|
+
| {
|
|
1010
|
+
op: "append-text";
|
|
1011
|
+
turn: string;
|
|
1012
|
+
text: string;
|
|
1013
|
+
block?: number;
|
|
1014
|
+
field?: string;
|
|
1015
|
+
} | {
|
|
1016
|
+
op: "add-trace-step";
|
|
1017
|
+
turn: string;
|
|
1018
|
+
step: TraceStep;
|
|
1019
|
+
}
|
|
1020
|
+
/** Change a step in place, by id — its detail counting up, its state settling. */
|
|
1021
|
+
| {
|
|
1022
|
+
op: "update-trace-step";
|
|
1023
|
+
turn: string;
|
|
1024
|
+
step: string;
|
|
1025
|
+
fields: Partial<TraceStep>;
|
|
1026
|
+
}
|
|
1027
|
+
/** Stream a step's reasoning: `text` is appended to its `thinking`. */
|
|
1028
|
+
| {
|
|
1029
|
+
op: "append-thinking";
|
|
1030
|
+
turn: string;
|
|
1031
|
+
step: string;
|
|
1032
|
+
text: string;
|
|
1033
|
+
}
|
|
1034
|
+
/** Anything else on a turn — its envelope once known, its outcome, its duration. */
|
|
1035
|
+
| {
|
|
1036
|
+
op: "update-turn";
|
|
1037
|
+
turn: string;
|
|
1038
|
+
fields: Record<string, unknown>;
|
|
1039
|
+
}
|
|
1040
|
+
/** A model's record count, as it changes — the live count behind the header's data reach. */
|
|
1041
|
+
| {
|
|
1042
|
+
op: "set-records";
|
|
1043
|
+
model: string;
|
|
1044
|
+
records: number;
|
|
1045
|
+
}
|
|
1046
|
+
/** The conversation's own fields — its title, its composer. Never its turns. */
|
|
1047
|
+
| {
|
|
1048
|
+
op: "update-spec";
|
|
1049
|
+
fields: Partial<Omit<ConversationSpec, "id" | "turns">>;
|
|
1050
|
+
};
|
|
1051
|
+
type ConversationPatchOp = ConversationPatch["op"];
|
|
1052
|
+
declare class PatchError extends Error {
|
|
1053
|
+
}
|
|
1054
|
+
declare function applyPatch(spec: ConversationSpec, patch: ConversationPatch): ConversationSpec;
|
|
1055
|
+
/** Apply patches in order — a recorded stream, replayed. */
|
|
1056
|
+
declare function applyPatches(spec: ConversationSpec, patches: ConversationPatch[]): ConversationSpec;
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* A conversation arrives as a spec, then as patches — by the same transport
|
|
1060
|
+
* every block streams by (`@invana/blocks`), carrying {@link ConversationPatch}.
|
|
1061
|
+
* These are the ways the patches can arrive — one at a time or in batches,
|
|
1062
|
+
* from a fetch body, an EventSource, a generator, or a recorded script — all
|
|
1063
|
+
* read the same way by `<ChatSession stream>` and `useChatSession().stream()`.
|
|
1064
|
+
*/
|
|
1065
|
+
type PatchChunk = PatchChunk$1<ConversationPatch>;
|
|
1066
|
+
type PatchSource = PatchSource$1<ConversationPatch>;
|
|
1067
|
+
/** A patch and when it lands, in ms from the start of the script. */
|
|
1068
|
+
type ScriptStep = ScriptStep$1<ConversationPatch>;
|
|
1069
|
+
/** A recorded run: plain JSON, replayed by {@link playScript}. */
|
|
1070
|
+
type PatchScript = PatchScript$1<ConversationPatch>;
|
|
1071
|
+
|
|
1072
|
+
/** Every patch of a source, flattened, in order. */
|
|
1073
|
+
declare const patchesOf: (source: PatchSource) => AsyncGenerator<ConversationPatch[], any, any>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Patches from a newline-delimited JSON body: one patch, or an array of them,
|
|
1076
|
+
* per line. Pass the `Response` of a streaming `fetch`, or its body.
|
|
1077
|
+
*/
|
|
1078
|
+
declare const fromNdjson: (input: Response | ReadableStream<Uint8Array>) => AsyncGenerator<PatchChunk$1<ConversationPatch>, any, any>;
|
|
1079
|
+
/** Patches from Server-Sent Events: each event's `data` is a patch, or an array of them. */
|
|
1080
|
+
declare const fromEventSource: (source: EventSource, options?: EventSourceOptions) => AsyncGenerator<PatchChunk$1<ConversationPatch>, any, any>;
|
|
1081
|
+
/**
|
|
1082
|
+
* A script as a stream: each step is yielded when it is due. Steps due at the
|
|
1083
|
+
* same moment are yielded together; aborting ends the stream where it stands.
|
|
1084
|
+
*/
|
|
1085
|
+
declare const playScript: (script: PatchScript, options?: PlayOptions) => AsyncGenerator<ConversationPatch[], any, any>;
|
|
1086
|
+
/** Shift every step of a script by `ms` — to chain scripts one after another. */
|
|
1087
|
+
declare const offsetScript: (script: PatchScript, ms: number) => PatchScript;
|
|
1088
|
+
|
|
1089
|
+
interface DeltaOptions {
|
|
1090
|
+
/** When the first delta lands, in ms. @default 0 */
|
|
1091
|
+
from?: number;
|
|
1092
|
+
/** The gap between deltas, in ms. @default 40 */
|
|
1093
|
+
every?: number;
|
|
1094
|
+
/** Stream word by word, or a few characters at a time. @default "word" */
|
|
1095
|
+
by?: "word" | "char";
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* A block's words, streamed: `append-text` steps, one per word, into `field`
|
|
1099
|
+
* (default `text`) of block `block` (default the last).
|
|
1100
|
+
*/
|
|
1101
|
+
declare function textDeltas(turn: string, text: string, { from, every, by, block, field }?: DeltaOptions & {
|
|
1102
|
+
block?: number;
|
|
1103
|
+
field?: string;
|
|
1104
|
+
}): PatchScript;
|
|
1105
|
+
/** A step's reasoning, streamed: `append-thinking` steps, one per word. */
|
|
1106
|
+
declare function thinkingDeltas(turn: string, step: string, text: string, { from, every, by }?: DeltaOptions): PatchScript;
|
|
1107
|
+
/**
|
|
1108
|
+
* Whether an answer is still being produced. `partial` is not: it is an
|
|
1109
|
+
* answer given in part — the rest in the background, or not to be had.
|
|
1110
|
+
*/
|
|
1111
|
+
declare const isLive: (turn: AnswerTurn) => boolean;
|
|
1112
|
+
/** Whether anything in the conversation is still running. */
|
|
1113
|
+
declare function isRunning(spec: ConversationSpec): boolean;
|
|
1114
|
+
/**
|
|
1115
|
+
* What stopping does, as patches: each running answer is marked `stopped`,
|
|
1116
|
+
* its running step `stopped` with the time it had run, the steps after it left
|
|
1117
|
+
* as they were — so the record shows how far it got. `now` is in ms.
|
|
1118
|
+
*/
|
|
1119
|
+
declare function stopPatches(spec: ConversationSpec, now?: number): ConversationPatch[];
|
|
1120
|
+
|
|
1121
|
+
/** `cli` is the console: caret prompts, status-dotted replies, step rows, a Tasks view. `web` is the chat: labelled turns, answer cards. */
|
|
1122
|
+
type ChatSessionVariant = "cli" | "web";
|
|
1123
|
+
/** The event of one type — `ChatSessionEventOf<"reply">` is `{ type: "reply"; turn; value }`. */
|
|
1124
|
+
type ChatSessionEventOf<T extends ConversationEventType> = Extract<ConversationEvent, {
|
|
1125
|
+
type: T;
|
|
1126
|
+
}>;
|
|
1127
|
+
type Camel<S extends string> = S extends `${infer Head}-${infer Rest}` ? `${Head}${Capitalize<Camel<Rest>>}` : S;
|
|
1128
|
+
/**
|
|
1129
|
+
* One typed callback per event: `onPrompt`, `onReply`, `onAction`,
|
|
1130
|
+
* `onOpenRun`, `onRate`, `onStop`, … Each receives exactly its event. They are
|
|
1131
|
+
* derived from {@link ConversationEvent}, so an event added to the protocol
|
|
1132
|
+
* gets its callback here with no other change.
|
|
1133
|
+
*/
|
|
1134
|
+
type ChatSessionHandlers = {
|
|
1135
|
+
[T in ConversationEventType as `on${Capitalize<Camel<T>>}`]?: (event: ChatSessionEventOf<T>) => void;
|
|
1136
|
+
};
|
|
1137
|
+
/**
|
|
1138
|
+
* The glyphs the session draws. The kit ships no icon set: pass your own nodes
|
|
1139
|
+
* (`{ send: <ArrowUp /> }`); anything left out falls back to a text glyph.
|
|
1140
|
+
*/
|
|
1141
|
+
interface ChatSessionIcons {
|
|
1142
|
+
send: React.ReactNode;
|
|
1143
|
+
stop: React.ReactNode;
|
|
1144
|
+
attach: React.ReactNode;
|
|
1145
|
+
close: React.ReactNode;
|
|
1146
|
+
retry: React.ReactNode;
|
|
1147
|
+
copy: React.ReactNode;
|
|
1148
|
+
steps: React.ReactNode;
|
|
1149
|
+
rateUp: React.ReactNode;
|
|
1150
|
+
rateDown: React.ReactNode;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* The actions on a settled answer, beside its time. `retry` is sent as
|
|
1154
|
+
* `retry`, `copy` as `copy` (and written to the clipboard), `steps` as
|
|
1155
|
+
* `toggle-steps`, `rate` as `rate`.
|
|
1156
|
+
*/
|
|
1157
|
+
type ChatSessionBuiltInAction = "retry" | "copy" | "steps" | "rate";
|
|
1158
|
+
/** An action of your own on a settled answer, sent as an `action` event with its `id`. */
|
|
1159
|
+
interface ChatSessionCustomAction {
|
|
1160
|
+
id: string;
|
|
1161
|
+
/** Its accessible name and tooltip. */
|
|
1162
|
+
label: string;
|
|
1163
|
+
icon: React.ReactNode;
|
|
1164
|
+
/** Only on answers in these states. Every settled state when left out. */
|
|
1165
|
+
states?: AnswerState[];
|
|
1166
|
+
}
|
|
1167
|
+
type ChatSessionAnswerAction = ChatSessionBuiltInAction | ChatSessionCustomAction;
|
|
1168
|
+
declare const DEFAULT_ANSWER_ACTIONS: ChatSessionAnswerAction[];
|
|
1169
|
+
/** What the CLI variant shows: the thread, or every step of every reply. */
|
|
1170
|
+
type ChatSessionView = "chat" | "tasks";
|
|
1171
|
+
interface ChatSessionProps extends ChatSessionHandlers {
|
|
1172
|
+
/**
|
|
1173
|
+
* The whole conversation, as JSON — what the API sends. Controlled: apply
|
|
1174
|
+
* patches to it (`applyPatch`, `useChatSession`) and pass the result, or
|
|
1175
|
+
* hand the patches over as `stream`.
|
|
1176
|
+
*/
|
|
1177
|
+
spec: ConversationSpec;
|
|
1178
|
+
/** @default "web" */
|
|
1179
|
+
variant?: ChatSessionVariant;
|
|
1180
|
+
/**
|
|
1181
|
+
* Every event, whatever its type, after its own callback — the one place to
|
|
1182
|
+
* forward everything to an API.
|
|
1183
|
+
*/
|
|
1184
|
+
onEvent?: (event: ConversationEvent) => void;
|
|
1185
|
+
/**
|
|
1186
|
+
* Patches to apply as they arrive — a streaming fetch (`fromNdjson`), an
|
|
1187
|
+
* EventSource (`fromEventSource`), a generator, or a recorded script
|
|
1188
|
+
* (`playScript`). The session draws `spec` with them applied; a new `spec`
|
|
1189
|
+
* starts over from it. Stopping ends the stream and records how far it got.
|
|
1190
|
+
*
|
|
1191
|
+
* Pass a function, `(signal) => source`, to open the source afresh each time
|
|
1192
|
+
* the session mounts — a generator can be read only once. Keep it stable
|
|
1193
|
+
* (module scope, `useCallback`): a new one starts a new stream.
|
|
1194
|
+
*/
|
|
1195
|
+
stream?: PatchSource | ((signal: AbortSignal) => PatchSource) | null;
|
|
1196
|
+
/** The stream ended; `spec` is the conversation as it left it. */
|
|
1197
|
+
onStreamEnd?: (spec: ConversationSpec) => void;
|
|
1198
|
+
/** A patch did not apply, or the source failed. The stream stops there. */
|
|
1199
|
+
onStreamError?: (error: unknown) => void;
|
|
1200
|
+
/** Renderers and traits of your own asks and blocks, merged over the built-ins. */
|
|
1201
|
+
registry?: RegistryOverrides;
|
|
1202
|
+
icons?: Partial<ChatSessionIcons>;
|
|
1203
|
+
/**
|
|
1204
|
+
* The actions beside a settled answer's time, in order — the built-ins by
|
|
1205
|
+
* name, yours as `{ id, label, icon }`. `[]` shows none.
|
|
1206
|
+
* @default ["retry", "copy", "steps", "rate"]
|
|
1207
|
+
*/
|
|
1208
|
+
actions?: ChatSessionAnswerAction[];
|
|
1209
|
+
/**
|
|
1210
|
+
* The clock, in ms. Left out, the session ticks while anything runs so
|
|
1211
|
+
* elapsed times move; a story passes a fixed one to read the same every run.
|
|
1212
|
+
*/
|
|
1213
|
+
now?: number;
|
|
1214
|
+
/** Shows a close control in the header. */
|
|
1215
|
+
onClose?: () => void;
|
|
1216
|
+
/**
|
|
1217
|
+
* The header. `true` draws the session's own — title, turn count, close;
|
|
1218
|
+
* `false` draws none; any node is drawn in its place, so a host composes
|
|
1219
|
+
* its own header from whatever it needs. @default true when the spec has a title
|
|
1220
|
+
*/
|
|
1221
|
+
header?: boolean | React.ReactNode;
|
|
1222
|
+
/** Shown when the spec has no turns yet. */
|
|
1223
|
+
emptyState?: React.ReactNode;
|
|
1224
|
+
/** The CLI's view, controlled. */
|
|
1225
|
+
view?: ChatSessionView;
|
|
1226
|
+
/** @default "chat" */
|
|
1227
|
+
defaultView?: ChatSessionView;
|
|
1228
|
+
onViewChange?: (view: ChatSessionView) => void;
|
|
1229
|
+
className?: string;
|
|
1230
|
+
}
|
|
1231
|
+
/** What a parent can do to a session it holds a ref to. */
|
|
1232
|
+
interface ChatSessionHandle {
|
|
1233
|
+
/** Scroll a turn into view. */
|
|
1234
|
+
scrollToTurn: (turnId: string) => void;
|
|
1235
|
+
/** Open or fold an answer's steps. */
|
|
1236
|
+
showSteps: (turnId: string, open?: boolean) => void;
|
|
1237
|
+
/** Open one step's record — what went in and came out. */
|
|
1238
|
+
openStep: (turnId: string, stepId: string) => void;
|
|
1239
|
+
setView: (view: ChatSessionView) => void;
|
|
1240
|
+
/** Focus the composer. */
|
|
1241
|
+
focusComposer: () => void;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* A conversation with the assistant, drawn from JSON alone, in one of two
|
|
1246
|
+
* variants: `cli`, the console, or `web`, the chat.
|
|
1247
|
+
*
|
|
1248
|
+
* The API sends a {@link ConversationSpec}, then patches — pass the patched
|
|
1249
|
+
* spec, or the patches themselves as `stream`. Every ask and block is drawn by
|
|
1250
|
+
* the block registry, so templates of your own draw exactly like the
|
|
1251
|
+
* built-ins; the session itself knows no block. Everything the analyst does
|
|
1252
|
+
* comes back as a typed event: to its own callback (`onReply`, `onAction`,
|
|
1253
|
+
* `onOpenRun`, …) and then to `onEvent`.
|
|
1254
|
+
*/
|
|
1255
|
+
declare const ChatSession: React.ForwardRefExoticComponent<ChatSessionProps & React.RefAttributes<ChatSessionHandle>>;
|
|
1256
|
+
|
|
1257
|
+
interface UseChatSession {
|
|
1258
|
+
/** The conversation as it stands — pass it to `<ChatSession spec>`. */
|
|
1259
|
+
spec: ConversationSpec;
|
|
1260
|
+
/** Apply a patch, or several in order. */
|
|
1261
|
+
apply: (patch: ConversationPatch | ConversationPatch[]) => void;
|
|
1262
|
+
/**
|
|
1263
|
+
* Apply a stream of patches as they arrive — `fromNdjson(await fetch(…))`,
|
|
1264
|
+
* `fromEventSource(…)`, a generator. Resolves with the spec where it ended.
|
|
1265
|
+
* A stream started while another runs runs beside it; `stop()` ends both.
|
|
1266
|
+
*/
|
|
1267
|
+
stream: (source: PatchSource) => Promise<ConversationSpec>;
|
|
1268
|
+
/** Replay a recorded script, on its own timing. */
|
|
1269
|
+
play: (script: PatchScript, options?: {
|
|
1270
|
+
speed?: number;
|
|
1271
|
+
}) => Promise<ConversationSpec>;
|
|
1272
|
+
/** End every stream, and mark what was running as stopped where it stood. */
|
|
1273
|
+
stop: () => void;
|
|
1274
|
+
/** Start over from a spec, ending every stream. */
|
|
1275
|
+
reset: (spec: ConversationSpec) => void;
|
|
1276
|
+
/** Whether a stream is still arriving. */
|
|
1277
|
+
streaming: boolean;
|
|
1278
|
+
/** Whether anything in the spec is still running. */
|
|
1279
|
+
running: boolean;
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* A conversation's state for a host that drives it: the spec, and the ways
|
|
1283
|
+
* patches reach it. The session draws; this holds.
|
|
1284
|
+
*
|
|
1285
|
+
* ```tsx
|
|
1286
|
+
* const chat = useChatSession(initial)
|
|
1287
|
+
* <ChatSession spec={chat.spec} onPrompt={(e) => chat.stream(fromNdjson(await ask(e.text)))} onStop={chat.stop} />
|
|
1288
|
+
* ```
|
|
1289
|
+
*/
|
|
1290
|
+
declare function useChatSession(initial: ConversationSpec | (() => ConversationSpec)): UseChatSession;
|
|
1291
|
+
|
|
1292
|
+
interface ChatSessionTurnProps {
|
|
1293
|
+
turn: Turn;
|
|
1294
|
+
onEvent?: (event: ConversationEvent) => void;
|
|
1295
|
+
registry?: RegistryOverrides;
|
|
1296
|
+
/** The clock an answered ask's time is read against, in ms. Defaults to the time of render. */
|
|
1297
|
+
now?: number;
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* One turn on its own, as the web variant draws it — the analyst's prompt,
|
|
1301
|
+
* an ask in its frame, or an answer's cards — without the thread around it.
|
|
1302
|
+
* For a block's board, where each cell is one turn.
|
|
1303
|
+
*/
|
|
1304
|
+
declare function ChatSessionTurn({ turn, onEvent, registry, now }: ChatSessionTurnProps): React.JSX.Element;
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* How a thread writes time. Every function takes the clock it reads against,
|
|
1308
|
+
* so a story or a test reads the same every run.
|
|
1309
|
+
*/
|
|
1310
|
+
/** `912ms`, `1.4s`, `2m 5s`, `1h 20m` — `spaced` writes `1.4 s`, as a sentence does. */
|
|
1311
|
+
declare function formatDuration(ms: number, { spaced }?: {
|
|
1312
|
+
spaced?: boolean;
|
|
1313
|
+
}): string;
|
|
1314
|
+
/** ms since an ISO time, never below zero; `undefined` when there is no time. */
|
|
1315
|
+
declare function elapsedSince(iso: string | undefined, now: number): number | undefined;
|
|
1316
|
+
/** `09:02` — the time a turn was sent, on a 24-hour clock. */
|
|
1317
|
+
declare function clockTime(iso: string | undefined): string | undefined;
|
|
1318
|
+
/** `Today · Wed 30 Sep`, `Yesterday · Tue 29 Sep`, `Mon 28 Sep`. */
|
|
1319
|
+
declare function dayLabel(iso: string, now: number): string;
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* The view model both variants draw from. Nothing here knows a kind: it
|
|
1323
|
+
* reads only the protocol's own fields — roles, kinds, states, the trace —
|
|
1324
|
+
* so an ask or a block of your own flows through exactly like a built-in.
|
|
1325
|
+
*/
|
|
1326
|
+
type AssistantTurn = AskTurn | AnswerTurn;
|
|
1327
|
+
/** A prompt and everything the assistant said back to it, in order. */
|
|
1328
|
+
interface Exchange {
|
|
1329
|
+
/** Stable across patches: the prompt's id, or the first reply's. */
|
|
1330
|
+
id: string;
|
|
1331
|
+
prompt?: AnalystTurn;
|
|
1332
|
+
replies: AssistantTurn[];
|
|
1333
|
+
}
|
|
1334
|
+
/** The thread as exchanges. Replies before any prompt form an exchange of their own. */
|
|
1335
|
+
declare function exchangesOf(spec: ConversationSpec): Exchange[];
|
|
1336
|
+
/** The step the run is on — running, retrying, or waiting on the analyst. */
|
|
1337
|
+
declare function currentStep(answer: AnswerTurn): TraceStep | undefined;
|
|
1338
|
+
/** A step's time: counting up while it runs, its duration once settled. */
|
|
1339
|
+
declare function stepTime(step: TraceStep, now: number): number | undefined;
|
|
1340
|
+
/**
|
|
1341
|
+
* An answer's time: counting up while it runs; once settled its `duration`,
|
|
1342
|
+
* else the span from `startedAt` to `at`, else the sum of its steps.
|
|
1343
|
+
*/
|
|
1344
|
+
declare function answerTime(answer: AnswerTurn, now: number): number | undefined;
|
|
1345
|
+
type RunOutcome = "live" | "waiting" | "done" | "failed" | "stopped";
|
|
1346
|
+
/** Where an answer's run stands, from its state and its steps. */
|
|
1347
|
+
declare function runOutcome(answer: AnswerTurn): RunOutcome;
|
|
1348
|
+
/**
|
|
1349
|
+
* Whether an ask holds the thread until it is answered. The session passes
|
|
1350
|
+
* the registry's answer — an ask drawn in the question card does; bare
|
|
1351
|
+
* follow-up chips do not — so no block is named here.
|
|
1352
|
+
*/
|
|
1353
|
+
type BlocksThread = (ask: AskTurn) => boolean;
|
|
1354
|
+
/** The counts a status bar shows: what runs, what waits, how many steps in all. */
|
|
1355
|
+
declare function threadCounts(spec: ConversationSpec, blocks?: BlocksThread): {
|
|
1356
|
+
running: number;
|
|
1357
|
+
waiting: number;
|
|
1358
|
+
steps: number;
|
|
1359
|
+
};
|
|
1360
|
+
/**
|
|
1361
|
+
* The words of a turn, for Copy: every string field named `text` on its
|
|
1362
|
+
* blocks, in order. Read by field, not by block, so a block of your own that
|
|
1363
|
+
* says something in `text` is copied too.
|
|
1364
|
+
*/
|
|
1365
|
+
declare function plainText(answer: AnswerTurn): string;
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* The frame a session is drawn in: a scrolling stack that sticks to the
|
|
1369
|
+
* latest, with a fixed footer. `ChatSession` is the conversation itself, drawn
|
|
1370
|
+
* from JSON; this is only its layout.
|
|
1371
|
+
*/
|
|
1372
|
+
declare const ChatSessionFrame: typeof ChatSession$1;
|
|
1373
|
+
/** The assistant's turn, with running, stopped, error and idle states. */
|
|
1374
|
+
declare const ChatSessionMessage: typeof ChatSessionMessage$1;
|
|
1375
|
+
/** Actions under a message: copy, retry, rate. */
|
|
1376
|
+
declare const ChatSessionMessageOptions: typeof ChatSessionMessageOptions$1;
|
|
1377
|
+
/** Prompt input with start and end slots, and send or stop. */
|
|
1378
|
+
declare const ChatSessionComposer: typeof ChatSessionComposer$1;
|
|
1379
|
+
/** A console row with the shared gutter glyph. */
|
|
1380
|
+
declare const ChatSessionActivityRow: typeof ChatSessionActivityRow$1;
|
|
1381
|
+
/** The indented line under an activity row. */
|
|
1382
|
+
declare const ChatSessionActivitySubLine: typeof ChatSessionActivitySubLine$1;
|
|
1383
|
+
/** The gutter every console row shares, so bodies line up. */
|
|
1384
|
+
declare const chatSessionGutterClass = "w-3.5 shrink-0 flex justify-center";
|
|
1385
|
+
/** The analyst's turn, on the shared gutter. */
|
|
1386
|
+
declare const ChatSessionPromptRow: typeof ChatSessionPromptRow$1;
|
|
1387
|
+
/** One-line status while work is in flight. */
|
|
1388
|
+
declare const ChatSessionProgressLine: typeof ChatSessionProgressLine$1;
|
|
1389
|
+
/** The cursor at the end of text still being written. */
|
|
1390
|
+
declare const ChatSessionCaret: typeof ChatSessionCaret$1;
|
|
1391
|
+
/** Collapsible detail under a row: query, preview, context. */
|
|
1392
|
+
declare const ChatSessionDisclosure: typeof ChatSessionDisclosure$1;
|
|
1393
|
+
/** The code a disclosure opens onto, keywords marked, when it opens onto more than code. */
|
|
1394
|
+
declare const ChatSessionDisclosureCode: typeof ChatSessionDisclosureCode$1;
|
|
1395
|
+
/** A method of several steps, numbered, each with its count or time. */
|
|
1396
|
+
declare const ChatSessionDisclosureSteps: typeof ChatSessionDisclosureSteps$1;
|
|
1397
|
+
/** A background task with its lifecycle. */
|
|
1398
|
+
declare const ChatSessionTaskRow: typeof ChatSessionTaskRow$1;
|
|
1399
|
+
/** A group of background tasks under one heading. */
|
|
1400
|
+
declare const ChatSessionTaskGroup: typeof ChatSessionTaskGroup$1;
|
|
1401
|
+
/** Slim bar under the composer: mode, counts, hints. */
|
|
1402
|
+
declare const ChatSessionStatusBar: typeof ChatSessionStatusBar$1;
|
|
1403
|
+
/** What the next question is about, bound from a selection. */
|
|
1404
|
+
declare const ChatSessionContextChip: typeof ChatSessionContextChip$1;
|
|
1405
|
+
|
|
1406
|
+
interface TurnLabelProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
1407
|
+
/** Who is speaking — the analyst's name, or `Assistant`. */
|
|
1408
|
+
children: React.ReactNode;
|
|
1409
|
+
/** `end` over the analyst's prompt, which sits at the right; `start` over an ask. */
|
|
1410
|
+
align?: "start" | "end";
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Who is speaking, over the turn they spoke — `RESEARCHER`, `ASSISTANT`.
|
|
1414
|
+
*
|
|
1415
|
+
* Drawn over the analyst's prompts and the assistant's asks, the two kinds of
|
|
1416
|
+
* turn that address someone. An answer is a card with its own header and needs
|
|
1417
|
+
* no label. Mono, small and spaced, so it reads as a tag on the turn rather than
|
|
1418
|
+
* a heading of the thread.
|
|
1419
|
+
*/
|
|
1420
|
+
declare const TurnLabel: React.ForwardRefExoticComponent<TurnLabelProps & React.RefAttributes<HTMLDivElement>>;
|
|
1421
|
+
|
|
1422
|
+
/** The ask, through its whole life: pending, answered, skipped, superseded, expired. */
|
|
1423
|
+
declare const ClarifyCard: React.ForwardRefExoticComponent<_invana_ui.ClarifyCardProps & React.RefAttributes<HTMLDivElement>>;
|
|
1424
|
+
/** The line under an ask: why these options, or where a default came from. */
|
|
1425
|
+
declare const ClarifyFootnote: React.ForwardRefExoticComponent<_invana_ui.ClarifyFootnoteProps & React.RefAttributes<HTMLParagraphElement>>;
|
|
1426
|
+
/** The row of controls that answers, skips or changes an ask. */
|
|
1427
|
+
declare const ClarifyActions: React.ForwardRefExoticComponent<_invana_ui.ClarifyActionsProps & React.RefAttributes<HTMLDivElement>>;
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* An answer opened as a page: the blocks `@invana/blocks` draws, in order,
|
|
1431
|
+
* under the answer's title. What only a conversation shows — citations,
|
|
1432
|
+
* caveats, the trace — stays in the thread.
|
|
1433
|
+
*/
|
|
1434
|
+
declare function answerToPage(turn: AnswerTurn): PageSpec;
|
|
1435
|
+
|
|
1436
|
+
/** The answer card. An answer is its blocks inside this card. */
|
|
1437
|
+
declare const EmissionCard: React.ForwardRefExoticComponent<_invana_ui.EmissionCardProps & React.RefAttributes<HTMLDivElement>>;
|
|
1438
|
+
/** The card's body: its blocks in one padded column. */
|
|
1439
|
+
declare const EmissionBody: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
1440
|
+
/** The strip that says what an answer is and what it is grounded in. */
|
|
1441
|
+
declare const EmissionHeader: React.ForwardRefExoticComponent<_invana_ui.EmissionHeaderProps & React.RefAttributes<HTMLDivElement>>;
|
|
1442
|
+
/** The superscript that ties a clause to the records behind it. */
|
|
1443
|
+
declare const CitationMarker: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLElement> & React.RefAttributes<HTMLElement>>;
|
|
1444
|
+
/** Re-render the same records as another block. */
|
|
1445
|
+
declare const TemplatePicker: React.ForwardRefExoticComponent<_invana_ui.TemplatePickerProps & React.RefAttributes<HTMLDivElement>>;
|
|
1446
|
+
|
|
1447
|
+
/**
|
|
1448
|
+
* What the compiler cannot see: a spec that arrived off the wire.
|
|
1449
|
+
*
|
|
1450
|
+
* `error` means the spec breaks the contract — an unknown block, a turn with
|
|
1451
|
+
* no id, an envelope field sent as a free block. `warning` means the spec is
|
|
1452
|
+
* valid but an answer does not match its pattern, which is how a change
|
|
1453
|
+
* explanation without a bridge gets noticed in fixtures and in development.
|
|
1454
|
+
*/
|
|
1455
|
+
interface ValidationIssue {
|
|
1456
|
+
level: "error" | "warning";
|
|
1457
|
+
/** The turn the issue is on, when there is one. */
|
|
1458
|
+
turn?: string;
|
|
1459
|
+
message: string;
|
|
1460
|
+
}
|
|
1461
|
+
interface ValidateOptions {
|
|
1462
|
+
/** Kinds a consumer registered beyond the grammar's. */
|
|
1463
|
+
extraAsks?: string[];
|
|
1464
|
+
extraBlocks?: string[];
|
|
1465
|
+
}
|
|
1466
|
+
declare function validate(spec: ConversationSpec, options?: ValidateOptions): ValidationIssue[];
|
|
1467
|
+
|
|
1468
|
+
export { ANSWER_INTENTS, ASK_INTENTS, type AccessModel, type AccessSpec, type AgentSpec, type AnalystTurn, type AnswerIntentId, type AnswerState, type AnswerTurn, type AskIntentId, type AskRegistry, type AskRenderer, type AskRendererProps, type AskTraits, type AskTurn, BUILT_IN_ASKS, BUILT_IN_ASK_TRAITS, BUILT_IN_BLOCKS, BUILT_IN_BLOCK_TRAITS, type BlockBase, type BlockRegistry, type BlockRenderer, type BlockRendererProps, type BlockSpec, type BlockTraits, ChatSession, ChatSessionActivityRow, ChatSessionActivitySubLine, type ChatSessionAnswerAction, type ChatSessionBuiltInAction, ChatSessionCaret, ChatSessionComposer, ChatSessionContextChip, type ChatSessionCustomAction, ChatSessionDisclosure, ChatSessionDisclosureCode, ChatSessionDisclosureSteps, type ChatSessionEventOf, ChatSessionFrame, type ChatSessionHandle, type ChatSessionHandlers, type ChatSessionIcons, ChatSessionMessage, ChatSessionMessageOptions, ChatSessionProgressLine, ChatSessionPromptRow, type ChatSessionProps, ChatSessionStatusBar, ChatSessionTaskGroup, ChatSessionTaskRow, ChatSessionTurn, type ChatSessionTurnProps, type ChatSessionVariant, type ChatSessionView, CitationMarker, ClarifyActions, ClarifyCard, ClarifyFootnote, type ComposerControl, type ComposerOption, type ComposerSpec, type ConversationEvent, type ConversationEventType, type ConversationPatch, type ConversationPatchOp, type ConversationSpec, DEFAULT_ANSWER_ACTIONS, type DeltaOptions, EVENT_TYPES, EmissionBody, EmissionCard, EmissionHeader, type Envelope, type Exchange, FLOWS, type FlowId, type GovernanceSpec, type Outcome, PATTERNS, type PatchChunk, PatchError, type PatchScript, type PatchSource, type PatternId, type RegistryOverrides, type ResolvedRegistry, type RunOutcome, STAGES, type ScriptStep, type StageId, TemplatePicker, type Turn, TurnLabel, type TurnLabelProps, type UseChatSession, type ValidateOptions, type ValidationIssue, answerTime, answerToPage, applyPatch, applyPatches, chatSessionGutterClass, clockTime, currentStep, dayLabel, elapsedSince, exchangesOf, formatDuration, fromEventSource, fromNdjson, isLive, isRunning, offsetScript, patchesOf, plainText, playScript, resolveRegistry, runOutcome, stepTime, stopPatches, textDeltas, thinkingDeltas, threadCounts, useChatSession, validate };
|