@graview/tools 0.1.29 → 0.1.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.
@@ -0,0 +1,203 @@
1
+ /**
2
+ * `@graview/tools/inline-ai` — THE INLINE AI: A PICK AMONG WHAT THE APP
3
+ * ALREADY KNOWS, PREVIEWED BEFORE IT IS KEPT (Roadmap f-ai-candidate-catalog).
4
+ *
5
+ * Pointed at something, the inline AI asks a model to choose among the
6
+ * catalog's candidates (`catalogOf`, `@graview/core/catalog`) over the
7
+ * state the viewer may see (`aiContextOf`) — never to invent an act, a
8
+ * field or a record:
9
+ *
10
+ * - `suggestHere` asks which few candidates the person most likely wants
11
+ * there: the Fast slot as one typed Choice, else the Thinking slot for
12
+ * JSON naming candidates;
13
+ * - `fillHere` asks a Choice per field the record could be filled in on,
14
+ * in one call, and answers the fills as proposals;
15
+ * - `panelHere` asks the Thinking slot (else the Fast one) which panel to
16
+ * draw, and answers its recipe, which `@graview/tools/draft` draws and
17
+ * "Keep as a lens" keeps;
18
+ * - `answerHere` answers words asked from the command bar or on an answer
19
+ * card (the quick ask): the host's Answer slot, else the Thinking slot,
20
+ * for prose and the candidates that act on it, else the Fast slot's
21
+ * pick among the candidates.
22
+ *
23
+ * A proposed change is a GHOST (`ghostOf`): each call rehearsed as the
24
+ * person and said in the act's own sentence, applied only when they accept
25
+ * all of it or some (`acceptGhost`) — as one batch, so one undo takes it
26
+ * back, whose ops carry lineage `interaction: <id>` and come through
27
+ * `ai:<interaction>`. Every call to a model reports its tier, model and
28
+ * tokens, to the interaction's entry and to the host's `meter`.
29
+ *
30
+ * The slots are the host's (`HostAi.fast`, `HostAi.thinking`): Jev
31
+ * (`jevFast`) for the Fast one, any language model for the Thinking one,
32
+ * and stubs (`stubFast`, `stubThinking`) for tests and a dev app. Fetched
33
+ * when the inline AI is first opened: a page whose reader never right-
34
+ * clicks carries none of it.
35
+ */
36
+ import { type AnySchema, type Author, type MutationCall, type Principal, type Store } from "@graview/core";
37
+ import { type AiCandidate, type AiInteraction, type AiPanel, type AiTarget, type CatalogAct, type CatalogPlace } from "@graview/core/catalog";
38
+ import type { AnswerProvider, FastProvider, HostAi, ThinkingProvider } from "./ai.js";
39
+ import { type JevOptions } from "./providers/jev.js";
40
+ /** The Fast slot as the host filled it, else its `decide` behind it. */
41
+ export declare function fastOf(ai: HostAi): FastProvider | undefined;
42
+ /** The Thinking slot as the host filled it, else its `complete` (or its `turn`, with no tools) behind it. */
43
+ export declare function thinkingOf(ai: HostAi): ThinkingProvider | undefined;
44
+ /** JEV IN THE FAST SLOT: `jevDecide` with its model and its price, for a host that holds a TypeSafe key or a bridge to one. */
45
+ export declare function jevFast(options?: JevOptions): FastProvider;
46
+ /** Where the inline AI was opened, and as whom. */
47
+ export interface InlineAsk<S extends AnySchema = AnySchema> {
48
+ readonly store: Store<S>;
49
+ readonly target: AiTarget;
50
+ readonly principal: Principal;
51
+ /** Who the entry says asked, when not the principal itself. */
52
+ readonly by?: Author;
53
+ /** The acts the derivation offers here, when the face has them. */
54
+ readonly acts?: readonly CatalogAct[];
55
+ readonly places?: readonly CatalogPlace[];
56
+ /** The place the viewer is on, and what else is selected. */
57
+ readonly place?: string;
58
+ readonly selection?: readonly string[];
59
+ /** Words the person typed, for a panel or an ask. */
60
+ readonly said?: string;
61
+ /** The interaction's id, when the face made one; else one is made. */
62
+ readonly interaction?: string;
63
+ }
64
+ /** One proposed change, as a ghost draws it and an acceptance applies it. */
65
+ export interface Proposal {
66
+ /** The candidate it came from. */
67
+ readonly id: string;
68
+ readonly label: string;
69
+ /** What accepting it does, in the act's own sentence. */
70
+ readonly said: string;
71
+ readonly call: MutationCall;
72
+ readonly confidence?: number;
73
+ readonly record?: string;
74
+ readonly field?: string;
75
+ }
76
+ /** CHANGES PROPOSED AND NOT MADE: previewed for the person, who accepts all of them, some, or none. */
77
+ export interface Ghost {
78
+ readonly interaction: string;
79
+ readonly target: AiTarget;
80
+ /** What was asked, in words: the lineage's basis when it is kept. */
81
+ readonly basis: string;
82
+ readonly model?: string;
83
+ readonly proposals: readonly Proposal[];
84
+ }
85
+ /** What an ask came to: the entry, and what it offers — suggestions, a ghost, a panel, or an answer in words. */
86
+ export interface InlineResult {
87
+ readonly interaction: AiInteraction;
88
+ /** The candidates picked, best first, each ready to take with one press. */
89
+ readonly offers: readonly AiCandidate[];
90
+ readonly ghost?: Ghost;
91
+ readonly panel?: AiPanel;
92
+ /** A quick ask's answer, in words. */
93
+ readonly answer?: string;
94
+ }
95
+ /** A fresh interaction id: `ai-` and something unique enough for one app's history. */
96
+ export declare const interactionId: () => string;
97
+ /** The target in words: a record's name, a kind's plural, a place's title. */
98
+ export declare function targetWords<S extends AnySchema>(store: Store<S>, target: AiTarget, places?: readonly CatalogPlace[]): string;
99
+ /**
100
+ * WHAT THE PERSON MOST LIKELY WANTS HERE: the Fast slot's pick among the
101
+ * candidates one press takes (a fill, an act that asks nothing, a panel, a
102
+ * place, a record), its top few kept; or the Thinking slot's, as JSON
103
+ * naming candidate ids, when there is no Fast one. Nothing is changed.
104
+ */
105
+ export declare function suggestHere<S extends AnySchema>(ai: HostAi, ask: InlineAsk<S>, most?: number): Promise<InlineResult>;
106
+ /**
107
+ * THE RECORD FILLED IN: one typed Choice per field or relation the catalog
108
+ * offers values for, asked in one call of the Fast slot (else the Thinking
109
+ * slot, for JSON naming one candidate per field), answered as a ghost of
110
+ * the chosen fills, each with its confidence. Nothing is changed.
111
+ */
112
+ export declare function fillHere<S extends AnySchema>(ai: HostAi, ask: InlineAsk<S>): Promise<InlineResult>;
113
+ /**
114
+ * A RECORD PROPOSED: the Thinking slot fills in the arguments of one of
115
+ * the catalog's acts that makes a record (one that still asks for words),
116
+ * and the call is a ghost like any fill — previewed, accepted or not, kept
117
+ * as one batch. The model fills only what the act asks; the act, its
118
+ * subject and everything the target settled stay the catalog's.
119
+ */
120
+ export declare function recordHere<S extends AnySchema>(ai: HostAi, ask: InlineAsk<S>): Promise<InlineResult>;
121
+ /**
122
+ * A PANEL DRAWN FOR THE TARGET: the Thinking slot names one of the
123
+ * catalog's panels and a title (else the Fast slot picks one). Answered as
124
+ * its recipe, which `recipeDraft` (`@graview/tools/draft`) draws exactly
125
+ * as a view the seat drew, and "Keep as a lens" keeps.
126
+ */
127
+ export declare function panelHere<S extends AnySchema>(ai: HostAi, ask: InlineAsk<S>): Promise<InlineResult>;
128
+ /** The Answer slot as the host filled it; else none, and the Thinking or Fast slot answers. */
129
+ export declare function answerOf(ai: HostAi): AnswerProvider | undefined;
130
+ /** A quick ask: the inline ask, with the ask it follows on the same card. */
131
+ export interface QuickAsk<S extends AnySchema = AnySchema> extends InlineAsk<S> {
132
+ readonly said: string;
133
+ /** The ask before this one on the card, and what it was answered: a follow-up, not a thread. */
134
+ readonly follows?: {
135
+ readonly said: string;
136
+ readonly answer: string;
137
+ };
138
+ }
139
+ /**
140
+ * WORDS ASKED ABOUT WHAT THE PERSON IS ON (the quick ask): answered in a
141
+ * few sentences, with the catalog's candidates that act on the answer —
142
+ * a change among them is a ghost, previewed as the person and kept only
143
+ * when accepted; a place, a record or a panel is one press on the card.
144
+ * The host's Answer slot answers when given; else the Thinking slot, as
145
+ * JSON; else the Fast slot picks the candidates that fit the words. A
146
+ * follow-up carries the ask before it and its answer, and nothing older.
147
+ */
148
+ export declare function answerHere<S extends AnySchema>(ai: HostAi, ask: QuickAsk<S>): Promise<InlineResult>;
149
+ /**
150
+ * PROPOSALS, PREVIEWED AS THE PERSON: each call rehearsed as they would
151
+ * make it and said in the act's own sentence; one the store would refuse
152
+ * them is dropped, never shown as something they could accept.
153
+ */
154
+ export declare function ghostOf<S extends AnySchema>(store: Store<S>, ghost: Ghost, principal: Principal): Ghost;
155
+ /** A proposal as one press of the menu takes it: a fill, or an act that asks nothing. */
156
+ export declare function proposalOf(candidate: AiCandidate): Proposal | undefined;
157
+ /**
158
+ * ACCEPT A GHOST, ALL OF IT OR SOME (`ids`): the chosen calls applied as
159
+ * the person, as one batch — one undo takes it back — carrying lineage
160
+ * `{ basis: what was asked, model, confidence, interaction }` and coming
161
+ * through `ai:<interaction>`. Answers the batch, or a sentence when the
162
+ * store refused it.
163
+ */
164
+ export declare function acceptGhost<S extends AnySchema>(store: Store<S>, ghost: Ghost, options: {
165
+ readonly author: Principal;
166
+ readonly ids?: readonly string[];
167
+ }): {
168
+ readonly ok: true;
169
+ readonly batch: string;
170
+ readonly accepted: readonly string[];
171
+ } | {
172
+ readonly ok: false;
173
+ readonly refused: string;
174
+ };
175
+ /** The entry after a ghost was accepted, in whole or in part. */
176
+ export declare function acceptedEntry(entry: AiInteraction, accepted: readonly string[], batch: string): AiInteraction;
177
+ /** The entry after its offer was put away. */
178
+ export declare const dismissedEntry: (entry: AiInteraction) => AiInteraction;
179
+ /**
180
+ * A FAST SLOT FOR TESTS AND A DEV APP: no network, the same shape as Jev.
181
+ * Each Choice is answered with the option whose words `prefer` matches
182
+ * first (else the first option), sure in proportion to its rank; a Noul
183
+ * with yes; a Score with its middle. It reports tokens as Jev would be
184
+ * metered for the request.
185
+ */
186
+ export declare function stubFast(options?: {
187
+ readonly model?: string;
188
+ readonly prefer?: readonly RegExp[];
189
+ }): FastProvider;
190
+ /**
191
+ * A THINKING SLOT FOR TESTS AND A DEV APP: answers each of the inline AI's
192
+ * requests from its catalog alone — a quick ask's answer "About <the
193
+ * target>: an answer to “<the words>”, as drafted." with its first three
194
+ * candidates one press takes, the first panel grouped by a choice
195
+ * (else the first panel) titled "<label>, as drafted", the first act that
196
+ * asks for words with each one "A new <argument>, as drafted", the first
197
+ * candidates it was offered, one fill per field — and reports tokens by
198
+ * length.
199
+ */
200
+ export declare function stubThinking(options?: {
201
+ readonly model?: string;
202
+ }): ThinkingProvider;
203
+ //# sourceMappingURL=inline-ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-ai.d.ts","sourceRoot":"","sources":["../src/inline-ai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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