@g9tm/aiassistant 1.8.2 → 1.9.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.d.ts +6 -0
- package/dist/api.js +2 -0
- package/dist/assistant.d.ts +26 -3
- package/dist/assistant.js +7 -4
- package/dist/blocks.d.ts +7 -0
- package/dist/blocks.js +10 -1
- package/dist/chat.d.ts +69 -0
- package/dist/chat.js +117 -0
- package/dist/guide.d.ts +91 -0
- package/dist/guide.js +123 -0
- package/dist/host.d.ts +56 -4
- package/dist/pages.d.ts +4 -0
- package/dist/pages.js +36 -0
- package/dist/types.d.ts +9 -1
- package/dist/types.js +1 -0
- package/package.json +3 -3
package/dist/api.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface SendInput {
|
|
|
19
19
|
};
|
|
20
20
|
/** The model a person picked (`id` or `id@effort`), kept on the conversation; the host must let them choose. */
|
|
21
21
|
model?: string;
|
|
22
|
+
/** Things the person picked with `@` (kind, id, the words seen): the model is told them, so it does not search. */
|
|
23
|
+
refs?: {
|
|
24
|
+
kind: string;
|
|
25
|
+
id: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
}[];
|
|
22
28
|
}
|
|
23
29
|
export interface EventPage {
|
|
24
30
|
events: RawEvent[];
|
package/dist/api.js
CHANGED
|
@@ -80,6 +80,8 @@ export class AssistantApi {
|
|
|
80
80
|
}
|
|
81
81
|
if (input.model)
|
|
82
82
|
body["model"] = input.model;
|
|
83
|
+
if (input.refs?.length)
|
|
84
|
+
body["refs"] = input.refs;
|
|
83
85
|
return this.request("POST", path, body).then((r) => ({ conversationId: str(obj(r)["conversationId"]), runId: str(obj(r)["runId"]) }));
|
|
84
86
|
}
|
|
85
87
|
async events(runId, after, wait) {
|
package/dist/assistant.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { SendInput } from "./api.js";
|
|
|
8
8
|
import type { MessageView } from "./conversation.js";
|
|
9
9
|
import type { AssistantHost } from "./host.js";
|
|
10
10
|
import { DeviceFlows } from "./flows.js";
|
|
11
|
+
import type { PickedRef } from "./host.js";
|
|
11
12
|
import type { DeviceTools } from "./flows.js";
|
|
12
13
|
import type { Texts } from "./i18n.js";
|
|
13
14
|
import { AnsweredCards } from "./plan.js";
|
|
@@ -27,6 +28,26 @@ export interface AssistantOptions {
|
|
|
27
28
|
deviceTools?: DeviceTools;
|
|
28
29
|
/** Device flows (with `deviceTools`): questions the device answers itself, without a model or a connection. Default on. */
|
|
29
30
|
flows?: boolean;
|
|
31
|
+
/** How the conversation reads and writes (every renderer follows it). */
|
|
32
|
+
chat?: ChatOptions;
|
|
33
|
+
}
|
|
34
|
+
/** How the conversation reads and writes; every option has a safe default for every host. */
|
|
35
|
+
export interface ChatOptions {
|
|
36
|
+
/** An answer's text can be selected and copied by dragging or a long press (default on). */
|
|
37
|
+
selectable?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Enter sends and Shift+Enter breaks a line (true), or Enter breaks a line and the button sends (false). Not set: each
|
|
40
|
+
* renderer as before (Svelte and React send on Enter; the Lynx field does not).
|
|
41
|
+
*/
|
|
42
|
+
enterSends?: boolean;
|
|
43
|
+
/** The lines the composer grows to before it scrolls (default 1: the one-line field as before; 4 to 6 suits a desk). */
|
|
44
|
+
maxLines?: number;
|
|
45
|
+
/** «Again» and «edit the question» under the last answer (default off). */
|
|
46
|
+
again?: boolean;
|
|
47
|
+
/** Copy one piece: a table (as cells a spreadsheet pastes), a number, and a paragraph by a long press where text is not selectable (default off). */
|
|
48
|
+
copyParts?: boolean;
|
|
49
|
+
/** One line in words of what the run does now («reading stock levels…», the tool's own title) on the work card (default off). */
|
|
50
|
+
status?: boolean;
|
|
30
51
|
}
|
|
31
52
|
/** Where `ask` sent a question. */
|
|
32
53
|
export type AskedVia = "device" | "offline" | "server" | "refused";
|
|
@@ -71,6 +92,8 @@ export declare class Assistant {
|
|
|
71
92
|
private readonly deviceTools;
|
|
72
93
|
/** `client.call`s already answered (a replayed event never runs a tool twice). */
|
|
73
94
|
private readonly answeredCalls;
|
|
95
|
+
/** The conversation's reading and writing options as given (`chatOf` in "@g9tm/aiassistant/pages" resolves the defaults). */
|
|
96
|
+
readonly chat: ChatOptions;
|
|
74
97
|
constructor(host: AssistantHost, options?: AssistantOptions);
|
|
75
98
|
/** Listens to every change; returns the function that stops listening. */
|
|
76
99
|
subscribe(listener: (s: AssistantSnapshot) => void): () => void;
|
|
@@ -80,15 +103,15 @@ export declare class Assistant {
|
|
|
80
103
|
open(conversationId: string): Promise<void>;
|
|
81
104
|
/** A new conversation. */
|
|
82
105
|
fresh(): void;
|
|
83
|
-
/** Sends a question; refused while a run is working (the button is "stop" then). */
|
|
84
|
-
send(text: string, page?: SendInput["page"]): Promise<boolean>;
|
|
106
|
+
/** Sends a question; refused while a run is working (the button is "stop" then). With `refs`, the things picked by `@`. */
|
|
107
|
+
send(text: string, page?: SendInput["page"], refs?: readonly PickedRef[]): Promise<boolean>;
|
|
85
108
|
/** Follows a run (null stops following). */
|
|
86
109
|
follow(runId: string | null, after?: number): void;
|
|
87
110
|
/**
|
|
88
111
|
* Asks: a device flow first (no model, no connection), then — offline — says the question needs a connection, else the
|
|
89
112
|
* server. Returns where it went.
|
|
90
113
|
*/
|
|
91
|
-
ask(text: string, page?: SendInput["page"]): Promise<AskedVia>;
|
|
114
|
+
ask(text: string, page?: SendInput["page"], refs?: readonly PickedRef[]): Promise<AskedVia>;
|
|
92
115
|
/** Fetches a newer flow pack and sends the queued flow outcomes (online only; a failure waits for the next time). */
|
|
93
116
|
syncDevice(): Promise<boolean>;
|
|
94
117
|
/** Runs a run's `client.call` on the device once and answers the server. */
|
package/dist/assistant.js
CHANGED
|
@@ -41,6 +41,7 @@ export class Assistant {
|
|
|
41
41
|
this.devices = options.deviceTools && options.flows !== false ? new DeviceFlows(this.api, host, options.deviceTools) : null;
|
|
42
42
|
this.stateWatch = new StateWatch(this.api, host);
|
|
43
43
|
this.stateNow = this.stateWatch.state;
|
|
44
|
+
this.chat = options.chat ?? {};
|
|
44
45
|
this.stateWatch.subscribe((s) => { this.stateNow = s; this.emit(); });
|
|
45
46
|
}
|
|
46
47
|
/** Listens to every change; returns the function that stops listening. */
|
|
@@ -86,8 +87,8 @@ export class Assistant {
|
|
|
86
87
|
this.attachments = [];
|
|
87
88
|
this.emit();
|
|
88
89
|
}
|
|
89
|
-
/** Sends a question; refused while a run is working (the button is "stop" then). */
|
|
90
|
-
async send(text, page) {
|
|
90
|
+
/** Sends a question; refused while a run is working (the button is "stop" then). With `refs`, the things picked by `@`. */
|
|
91
|
+
async send(text, page, refs) {
|
|
91
92
|
const trimmed = text.trim();
|
|
92
93
|
if (trimmed.length === 0)
|
|
93
94
|
return false;
|
|
@@ -109,6 +110,8 @@ export class Assistant {
|
|
|
109
110
|
input.page = where;
|
|
110
111
|
if (this.model)
|
|
111
112
|
input.model = this.model;
|
|
113
|
+
if (refs?.length)
|
|
114
|
+
input.refs = refs.slice(0, 5).map(({ kind, id, label }) => ({ kind, id, label }));
|
|
112
115
|
try {
|
|
113
116
|
const t = await this.api.send(input);
|
|
114
117
|
this.store.id = t.conversationId;
|
|
@@ -156,7 +159,7 @@ export class Assistant {
|
|
|
156
159
|
* Asks: a device flow first (no model, no connection), then — offline — says the question needs a connection, else the
|
|
157
160
|
* server. Returns where it went.
|
|
158
161
|
*/
|
|
159
|
-
async ask(text, page) {
|
|
162
|
+
async ask(text, page, refs) {
|
|
160
163
|
const trimmed = text.trim();
|
|
161
164
|
if (trimmed.length === 0 || this.snapshot().busy)
|
|
162
165
|
return "refused";
|
|
@@ -181,7 +184,7 @@ export class Assistant {
|
|
|
181
184
|
this.emit();
|
|
182
185
|
return "offline";
|
|
183
186
|
}
|
|
184
|
-
return (await this.send(trimmed, page)) ? "server" : "refused";
|
|
187
|
+
return (await this.send(trimmed, page, refs)) ? "server" : "refused";
|
|
185
188
|
}
|
|
186
189
|
/** Fetches a newer flow pack and sends the queued flow outcomes (online only; a failure waits for the next time). */
|
|
187
190
|
async syncDevice() {
|
package/dist/blocks.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
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
5
|
* time axis, and too little data shows no percentages or averages.
|
|
6
6
|
*/
|
|
7
|
+
import type { GuideSubject } from "./host.js";
|
|
7
8
|
export interface Column {
|
|
8
9
|
name: string;
|
|
9
10
|
kind: "text" | "number" | "money" | "percent" | "date" | "day" | "id";
|
|
@@ -69,6 +70,9 @@ export type BlockView = {
|
|
|
69
70
|
} | {
|
|
70
71
|
type: "open";
|
|
71
72
|
pageId: string;
|
|
73
|
+
subject: GuideSubject | null;
|
|
74
|
+
target: string | null;
|
|
75
|
+
label: string | null;
|
|
72
76
|
fallbackText: string;
|
|
73
77
|
} | {
|
|
74
78
|
type: "export";
|
|
@@ -98,6 +102,9 @@ export declare const FOLD_ROWS = 8;
|
|
|
98
102
|
export declare const RANK_BARS = 10;
|
|
99
103
|
/** Fewer data points than this show no percentages or averages. */
|
|
100
104
|
export declare const FEW_DATA = 3;
|
|
105
|
+
/** A block's `subject` ({kind, id}; an id that is a number becomes text), or null. */
|
|
106
|
+
export declare function subjectOf(v: unknown): GuideSubject | null;
|
|
107
|
+
export declare function strOrNull(v: unknown): string | null;
|
|
101
108
|
/** One cell as the person reads it: numbers in the locale's digits and separators. */
|
|
102
109
|
export declare function cell(v: unknown, kind: Column["kind"], locale: "fa" | "en"): string;
|
|
103
110
|
/** The view model of a stored block; anything unreadable is its fallback text. */
|
package/dist/blocks.js
CHANGED
|
@@ -15,6 +15,15 @@ export const RANK_BARS = 10;
|
|
|
15
15
|
/** Fewer data points than this show no percentages or averages. */
|
|
16
16
|
export const FEW_DATA = 3;
|
|
17
17
|
const KNOWN = new Set(["text", "callout", "table", "chart", "kpi", "steps", "actions", "flow", "image", "open", "export", "gallery", "items", "compare", "gauge", "timeline"]);
|
|
18
|
+
/** A block's `subject` ({kind, id}; an id that is a number becomes text), or null. */
|
|
19
|
+
export function subjectOf(v) {
|
|
20
|
+
const s = obj(v);
|
|
21
|
+
const id = typeof s["id"] === "number" ? String(s["id"]) : str(s["id"]);
|
|
22
|
+
return str(s["kind"]).length > 0 && id.length > 0 ? { kind: str(s["kind"]), id } : null;
|
|
23
|
+
}
|
|
24
|
+
export function strOrNull(v) {
|
|
25
|
+
return typeof v === "string" && v.length > 0 ? v : null;
|
|
26
|
+
}
|
|
18
27
|
function columns(v) {
|
|
19
28
|
const kinds = new Set(["text", "number", "money", "percent", "date", "day", "id"]);
|
|
20
29
|
return arr(v).map(obj).map((c) => ({ name: str(c["name"]), kind: (kinds.has(str(c["kind"])) ? str(c["kind"]) : "text"), label: str(c["label"], str(c["name"])) }));
|
|
@@ -72,7 +81,7 @@ export function blockView(raw, locale, custom = new Set()) {
|
|
|
72
81
|
case "flow": return { type: "flow", line: str(b["line"], fallbackText), fallbackText };
|
|
73
82
|
case "image":
|
|
74
83
|
case "gallery": return { type: "image", fileIds: arr(b["fileIds"]).filter((x) => typeof x === "string"), fallbackText };
|
|
75
|
-
case "open": return str(b["pageId"]).length > 0 ? { type: "open", pageId: str(b["pageId"]), fallbackText } : { type: "fallback", fallbackText };
|
|
84
|
+
case "open": return str(b["pageId"]).length > 0 ? { type: "open", pageId: str(b["pageId"]), subject: subjectOf(b["subject"]), target: strOrNull(b["target"]), label: strOrNull(b["label"]), fallbackText } : { type: "fallback", fallbackText };
|
|
76
85
|
case "export": {
|
|
77
86
|
// every row and column, as raw text: the file is for a spreadsheet, not for reading here
|
|
78
87
|
const cols = columns(b["columns"]);
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The conversation's helpers that only the panel needs (part of the "@g9tm/aiassistant/pages" entry, so the core every
|
|
3
|
+
* surface loads stays inside its budget): the composer's `/` and `@`, copying one piece of an answer, and the run's
|
|
4
|
+
* state in words.
|
|
5
|
+
*/
|
|
6
|
+
import type { AssistantApi } from "./api.js";
|
|
7
|
+
import type { Assistant } from "./assistant.js";
|
|
8
|
+
import type { MessageView } from "./conversation.js";
|
|
9
|
+
import type { PickedRef, QuickRequest } from "./host.js";
|
|
10
|
+
import type { RunView } from "./run.js";
|
|
11
|
+
import type { TextBlock } from "./text.js";
|
|
12
|
+
/** The conversation's options with their defaults (every renderer reads them through this). */
|
|
13
|
+
export interface ChatView {
|
|
14
|
+
selectable: boolean;
|
|
15
|
+
enterSends: boolean | null;
|
|
16
|
+
maxLines: number;
|
|
17
|
+
again: boolean;
|
|
18
|
+
copyParts: boolean;
|
|
19
|
+
status: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** An assistant's chat options resolved: selectable on; Enter as each renderer had it; one line; again, copy and status off. */
|
|
22
|
+
export declare function chatOf(assistant: Assistant): ChatView;
|
|
23
|
+
/** The words after a leading `/` (empty right after it), or null when the text does not start with one. */
|
|
24
|
+
export declare function slashQuery(text: string): string | null;
|
|
25
|
+
/** The ready requests matching what follows `/` (at most eight). */
|
|
26
|
+
export declare function matchQuick(all: readonly QuickRequest[], query: string): QuickRequest[];
|
|
27
|
+
/** The word after a trailing `@` (1 to 30 letters, no space), or null. */
|
|
28
|
+
export declare function atWord(text: string): string | null;
|
|
29
|
+
/** The text with its trailing `@word` replaced by what was picked. */
|
|
30
|
+
export declare function putPick(text: string, picked: PickedRef): string;
|
|
31
|
+
/** The picks still named in the text when it is sent (a pick whose words were deleted is not sent). */
|
|
32
|
+
export declare function refsIn(text: string, picks: readonly PickedRef[]): PickedRef[];
|
|
33
|
+
/** The host's things of a kind matching the words after `@` (the server's `GET pick`, as the routine wizard uses it). */
|
|
34
|
+
export declare function pickRefs(api: AssistantApi, kind: string, q: string): Promise<PickedRef[]>;
|
|
35
|
+
/** The text a composer starts from (a question to edit, a ready request); `epoch` grows each time it is set. */
|
|
36
|
+
export interface ComposerText {
|
|
37
|
+
text: string;
|
|
38
|
+
epoch: number;
|
|
39
|
+
}
|
|
40
|
+
/** An assistant's composer text, which a renderer's composer redraws from (`composerOf(a).set(text)`). */
|
|
41
|
+
export declare class ComposerBox {
|
|
42
|
+
private now;
|
|
43
|
+
private readonly listeners;
|
|
44
|
+
get value(): ComposerText;
|
|
45
|
+
/** Listens; returns the function that stops listening. */
|
|
46
|
+
subscribe(listener: (c: ComposerText) => void): () => void;
|
|
47
|
+
/** Puts a text in the composer (it redraws with it). */
|
|
48
|
+
set(text: string): void;
|
|
49
|
+
}
|
|
50
|
+
/** The composer text of an assistant (one per assistant). */
|
|
51
|
+
export declare function composerOf(assistant: Assistant): ComposerBox;
|
|
52
|
+
/** The person's last question, or null. */
|
|
53
|
+
export declare function lastQuestion(assistant: Assistant): MessageView | null;
|
|
54
|
+
/** Asks the last question again (the answer's «again»). */
|
|
55
|
+
export declare function askAgain(assistant: Assistant): Promise<boolean>;
|
|
56
|
+
/** Puts the last question in the composer to edit and send again (the answer's «edit»). */
|
|
57
|
+
export declare function editLast(assistant: Assistant): void;
|
|
58
|
+
/** A table as tab-separated lines (a spreadsheet pastes it as cells): the labels, then the rows. */
|
|
59
|
+
export declare function tableText(labels: readonly string[], rows: readonly (readonly string[])[]): string;
|
|
60
|
+
/** One paragraph's or one list's plain text (copying a piece of an answer). */
|
|
61
|
+
export declare function blockText(block: TextBlock): string;
|
|
62
|
+
/**
|
|
63
|
+
* The run's state in words, for one status line: the tool working now (its title from the host's catalogue), else the
|
|
64
|
+
* progress line, else the stage that is on, else null. A renderer writes it as "{what}…".
|
|
65
|
+
*/
|
|
66
|
+
export declare function statusOf(view: RunView): {
|
|
67
|
+
key: string;
|
|
68
|
+
args?: Record<string, string>;
|
|
69
|
+
} | null;
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The conversation's helpers that only the panel needs (part of the "@g9tm/aiassistant/pages" entry, so the core every
|
|
3
|
+
* surface loads stays inside its budget): the composer's `/` and `@`, copying one piece of an answer, and the run's
|
|
4
|
+
* state in words.
|
|
5
|
+
*/
|
|
6
|
+
import { arr, item, obj, str } from "./api.js";
|
|
7
|
+
import { plainText } from "./text.js";
|
|
8
|
+
/** An assistant's chat options resolved: selectable on; Enter as each renderer had it; one line; again, copy and status off. */
|
|
9
|
+
export function chatOf(assistant) {
|
|
10
|
+
const c = assistant.chat;
|
|
11
|
+
return { selectable: c.selectable ?? true, enterSends: c.enterSends ?? null, maxLines: Math.max(1, Math.min(12, c.maxLines ?? 1)), again: c.again === true, copyParts: c.copyParts === true, status: c.status === true };
|
|
12
|
+
}
|
|
13
|
+
/** The words after a leading `/` (empty right after it), or null when the text does not start with one. */
|
|
14
|
+
export function slashQuery(text) {
|
|
15
|
+
return text.startsWith("/") ? text.slice(1).trim().toLowerCase() : null;
|
|
16
|
+
}
|
|
17
|
+
/** The ready requests matching what follows `/` (at most eight). */
|
|
18
|
+
export function matchQuick(all, query) {
|
|
19
|
+
return all.filter((q) => query.length === 0 || q.label.toLowerCase().includes(query)).slice(0, 8);
|
|
20
|
+
}
|
|
21
|
+
/** The word after a trailing `@` (1 to 30 letters, no space), or null. */
|
|
22
|
+
export function atWord(text) {
|
|
23
|
+
const m = /@([^\s@]{1,30})$/u.exec(text);
|
|
24
|
+
return m ? (m[1] ?? null) : null;
|
|
25
|
+
}
|
|
26
|
+
/** The text with its trailing `@word` replaced by what was picked. */
|
|
27
|
+
export function putPick(text, picked) {
|
|
28
|
+
return text.replace(/@[^\s@]{1,30}$/u, picked.label + " ");
|
|
29
|
+
}
|
|
30
|
+
/** The picks still named in the text when it is sent (a pick whose words were deleted is not sent). */
|
|
31
|
+
export function refsIn(text, picks) {
|
|
32
|
+
return picks.filter((p) => text.includes(p.label));
|
|
33
|
+
}
|
|
34
|
+
/** The host's things of a kind matching the words after `@` (the server's `GET pick`, as the routine wizard uses it). */
|
|
35
|
+
export async function pickRefs(api, kind, q) {
|
|
36
|
+
try {
|
|
37
|
+
const r = obj(await api.get("pick?kind=" + encodeURIComponent(kind) + "&q=" + encodeURIComponent(q)));
|
|
38
|
+
return arr(r["items"]).map(obj).map((x) => ({ kind, id: str(x["id"]), label: str(x["text"], str(x["id"])) })).filter((x) => x.id.length > 0).slice(0, 12);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** An assistant's composer text, which a renderer's composer redraws from (`composerOf(a).set(text)`). */
|
|
45
|
+
export class ComposerBox {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.now = { text: "", epoch: 0 };
|
|
48
|
+
this.listeners = new Set();
|
|
49
|
+
}
|
|
50
|
+
get value() {
|
|
51
|
+
return this.now;
|
|
52
|
+
}
|
|
53
|
+
/** Listens; returns the function that stops listening. */
|
|
54
|
+
subscribe(listener) {
|
|
55
|
+
this.listeners.add(listener);
|
|
56
|
+
return () => this.listeners.delete(listener);
|
|
57
|
+
}
|
|
58
|
+
/** Puts a text in the composer (it redraws with it). */
|
|
59
|
+
set(text) {
|
|
60
|
+
this.now = { text, epoch: this.now.epoch + 1 };
|
|
61
|
+
for (const l of this.listeners)
|
|
62
|
+
l(this.now);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const boxes = new WeakMap();
|
|
66
|
+
/** The composer text of an assistant (one per assistant). */
|
|
67
|
+
export function composerOf(assistant) {
|
|
68
|
+
let b = boxes.get(assistant);
|
|
69
|
+
if (!b) {
|
|
70
|
+
b = new ComposerBox();
|
|
71
|
+
boxes.set(assistant, b);
|
|
72
|
+
}
|
|
73
|
+
return b;
|
|
74
|
+
}
|
|
75
|
+
/** The person's last question, or null. */
|
|
76
|
+
export function lastQuestion(assistant) {
|
|
77
|
+
const ms = assistant.snapshot().messages;
|
|
78
|
+
for (let i = ms.length - 1; i >= 0; i--) {
|
|
79
|
+
const m = item(ms, i);
|
|
80
|
+
if (m && m.role === "user" && m.text.length > 0)
|
|
81
|
+
return m;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/** Asks the last question again (the answer's «again»). */
|
|
86
|
+
export async function askAgain(assistant) {
|
|
87
|
+
const q = lastQuestion(assistant);
|
|
88
|
+
return q ? assistant.send(q.text) : false;
|
|
89
|
+
}
|
|
90
|
+
/** Puts the last question in the composer to edit and send again (the answer's «edit»). */
|
|
91
|
+
export function editLast(assistant) {
|
|
92
|
+
const q = lastQuestion(assistant);
|
|
93
|
+
if (q)
|
|
94
|
+
composerOf(assistant).set(q.text);
|
|
95
|
+
}
|
|
96
|
+
/** A table as tab-separated lines (a spreadsheet pastes it as cells): the labels, then the rows. */
|
|
97
|
+
export function tableText(labels, rows) {
|
|
98
|
+
const cell = (c) => c.replace(/[\t\r\n]+/gu, " ");
|
|
99
|
+
return [labels, ...rows].map((r) => r.map(cell).join("\t")).join("\n");
|
|
100
|
+
}
|
|
101
|
+
/** One paragraph's or one list's plain text (copying a piece of an answer). */
|
|
102
|
+
export function blockText(block) {
|
|
103
|
+
return plainText([block]);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The run's state in words, for one status line: the tool working now (its title from the host's catalogue), else the
|
|
107
|
+
* progress line, else the stage that is on, else null. A renderer writes it as "{what}…".
|
|
108
|
+
*/
|
|
109
|
+
export function statusOf(view) {
|
|
110
|
+
const tool = [...view.tools].reverse().find((t) => t.state === "start");
|
|
111
|
+
if (tool)
|
|
112
|
+
return tool.title.key.length > 0 ? tool.title : { key: tool.name };
|
|
113
|
+
if (view.progress)
|
|
114
|
+
return view.progress;
|
|
115
|
+
const stage = [...view.stages].reverse().find((s) => s.state === "on");
|
|
116
|
+
return stage ? (stage.role ? { key: "stage.role", args: { role: stage.role } } : { key: "stage." + stage.id }) : null;
|
|
117
|
+
}
|
package/dist/guide.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guiding the person (part of the "@g9tm/aiassistant/pages" entry): an `open` names a page, maybe what it is about and
|
|
3
|
+
* a control inside it; a tour shows its steps one at a time; a draft opens a host form with values for the person to
|
|
4
|
+
* save. The library only carries and checks them: what "open", "highlight" and "a form" look like is the host's
|
|
5
|
+
* (`navigate`, `openDraft`). Without them a tour is a numbered list and a draft is its label, never an error.
|
|
6
|
+
*/
|
|
7
|
+
import type { Assistant } from "./assistant.js";
|
|
8
|
+
import type { AssistantHost, GuideSubject } from "./host.js";
|
|
9
|
+
/** One step of a tour: its words, and maybe a page, what it is about, a control to light and a signal that moves on. */
|
|
10
|
+
export interface TourStepView {
|
|
11
|
+
text: string;
|
|
12
|
+
page: string | null;
|
|
13
|
+
subject: GuideSubject | null;
|
|
14
|
+
target: string | null;
|
|
15
|
+
advanceOn: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The guide's blocks as view models (the core's `blockView` shows them as their fallback text): a tour (at most twelve
|
|
19
|
+
* steps), a draft (a host form with values; the server showed it only after the host's check), and the things an
|
|
20
|
+
* answer named.
|
|
21
|
+
*/
|
|
22
|
+
export type GuideBlockView = {
|
|
23
|
+
type: "tour";
|
|
24
|
+
title?: string;
|
|
25
|
+
steps: TourStepView[];
|
|
26
|
+
fallbackText: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "draft";
|
|
29
|
+
kind: string;
|
|
30
|
+
values: Record<string, unknown>;
|
|
31
|
+
page: string | null;
|
|
32
|
+
subject: GuideSubject | null;
|
|
33
|
+
label: string | null;
|
|
34
|
+
fallbackText: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "entities";
|
|
37
|
+
items: {
|
|
38
|
+
text: string;
|
|
39
|
+
kind: string;
|
|
40
|
+
id: string;
|
|
41
|
+
}[];
|
|
42
|
+
fallbackText: string;
|
|
43
|
+
};
|
|
44
|
+
export type TourView = Extract<GuideBlockView, {
|
|
45
|
+
type: "tour";
|
|
46
|
+
}>;
|
|
47
|
+
/** A stored block as a guide view model, or null when it is no guide block (or a broken one: its fallback shows). */
|
|
48
|
+
export declare function guideBlock(raw: unknown): GuideBlockView | null;
|
|
49
|
+
/** The tour the person is walking through. */
|
|
50
|
+
export interface TourState {
|
|
51
|
+
/** The message and block the tour came from (a second tour replaces the first). */
|
|
52
|
+
key: string;
|
|
53
|
+
title: string | null;
|
|
54
|
+
steps: TourStepView[];
|
|
55
|
+
/** The step shown, from 0. */
|
|
56
|
+
index: number;
|
|
57
|
+
/** Whether the person finished it (the last step's "done"). */
|
|
58
|
+
done: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** Shows a step through the host: its page, what it is about, the control to light and the sentence to say there. */
|
|
61
|
+
export declare function showStep(host: AssistantHost, step: TourStepView, index: number, count: number): boolean;
|
|
62
|
+
/** Opens an `open` block's page through the host (its subject and target too). */
|
|
63
|
+
export declare function openPage(host: AssistantHost, v: {
|
|
64
|
+
pageId: string;
|
|
65
|
+
subject: GuideSubject | null;
|
|
66
|
+
target: string | null;
|
|
67
|
+
}): boolean;
|
|
68
|
+
/** The person's tour: start, next, back, end, and a host's signal that the step was done. */
|
|
69
|
+
export declare class Guide {
|
|
70
|
+
private readonly host;
|
|
71
|
+
private current;
|
|
72
|
+
private readonly listeners;
|
|
73
|
+
constructor(host: AssistantHost);
|
|
74
|
+
get tour(): TourState | null;
|
|
75
|
+
/** Listens to the tour; returns the function that stops listening. */
|
|
76
|
+
subscribe(listener: (tour: TourState | null) => void): () => void;
|
|
77
|
+
/** Starts a tour at its first step (the host opens the step's page and lights its control). */
|
|
78
|
+
start(key: string, tour: TourView): void;
|
|
79
|
+
next(): void;
|
|
80
|
+
back(): void;
|
|
81
|
+
end(): void;
|
|
82
|
+
/**
|
|
83
|
+
* The host says the person did something (`saved`, `form.open`...): a step waiting for that signal moves on by itself.
|
|
84
|
+
* Returns whether it moved.
|
|
85
|
+
*/
|
|
86
|
+
signal(name: string): boolean;
|
|
87
|
+
private show;
|
|
88
|
+
private set;
|
|
89
|
+
}
|
|
90
|
+
/** The tour of an assistant (one per assistant): its renderers show it, the host signals it (`guideOf(a).signal("saved")`). */
|
|
91
|
+
export declare function guideOf(assistant: Assistant): Guide;
|
package/dist/guide.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guiding the person (part of the "@g9tm/aiassistant/pages" entry): an `open` names a page, maybe what it is about and
|
|
3
|
+
* a control inside it; a tour shows its steps one at a time; a draft opens a host form with values for the person to
|
|
4
|
+
* save. The library only carries and checks them: what "open", "highlight" and "a form" look like is the host's
|
|
5
|
+
* (`navigate`, `openDraft`). Without them a tour is a numbered list and a draft is its label, never an error.
|
|
6
|
+
*/
|
|
7
|
+
import { arr, item, obj, str } from "./api.js";
|
|
8
|
+
import { strOrNull, subjectOf } from "./blocks.js";
|
|
9
|
+
/** A stored block as a guide view model, or null when it is no guide block (or a broken one: its fallback shows). */
|
|
10
|
+
export function guideBlock(raw) {
|
|
11
|
+
const b = obj(raw);
|
|
12
|
+
const fallbackText = str(b["fallbackText"]);
|
|
13
|
+
switch (b["type"]) {
|
|
14
|
+
case "tour": {
|
|
15
|
+
const steps = arr(b["steps"]).map(obj).filter((s) => str(s["text"]).length > 0).slice(0, 12)
|
|
16
|
+
.map((s) => ({ text: str(s["text"]), page: strOrNull(s["page"]), subject: subjectOf(s["subject"]), target: strOrNull(s["target"]), advanceOn: strOrNull(s["advanceOn"]) }));
|
|
17
|
+
if (steps.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
return typeof b["title"] === "string" ? { type: "tour", title: b["title"], steps, fallbackText } : { type: "tour", steps, fallbackText };
|
|
20
|
+
}
|
|
21
|
+
case "draft":
|
|
22
|
+
return str(b["kind"]).length > 0
|
|
23
|
+
? { type: "draft", kind: str(b["kind"]), values: obj(b["values"]), page: strOrNull(b["page"]), subject: subjectOf(b["subject"]), label: strOrNull(b["label"]), fallbackText }
|
|
24
|
+
: null;
|
|
25
|
+
case "entities":
|
|
26
|
+
return { type: "entities", items: arr(b["items"]).map(obj).map((e) => ({ text: str(e["text"]), kind: str(e["kind"]), id: str(e["id"]) })).filter((e) => e.text.length > 0 && e.kind.length > 0 && e.id.length > 0).slice(0, 12), fallbackText };
|
|
27
|
+
default:
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Shows a step through the host: its page, what it is about, the control to light and the sentence to say there. */
|
|
32
|
+
export function showStep(host, step, index, count) {
|
|
33
|
+
if (!step.page || !host.navigate)
|
|
34
|
+
return false;
|
|
35
|
+
host.navigate(step.page, step.subject ?? undefined, { ...(step.target ? { target: step.target } : {}), say: step.text, step: { index, count } });
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/** Opens an `open` block's page through the host (its subject and target too). */
|
|
39
|
+
export function openPage(host, v) {
|
|
40
|
+
if (!host.navigate)
|
|
41
|
+
return false;
|
|
42
|
+
host.navigate(v.pageId, v.subject ?? undefined, v.target ? { target: v.target } : undefined);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/** The person's tour: start, next, back, end, and a host's signal that the step was done. */
|
|
46
|
+
export class Guide {
|
|
47
|
+
constructor(host) {
|
|
48
|
+
this.host = host;
|
|
49
|
+
this.current = null;
|
|
50
|
+
this.listeners = new Set();
|
|
51
|
+
}
|
|
52
|
+
get tour() {
|
|
53
|
+
return this.current;
|
|
54
|
+
}
|
|
55
|
+
/** Listens to the tour; returns the function that stops listening. */
|
|
56
|
+
subscribe(listener) {
|
|
57
|
+
this.listeners.add(listener);
|
|
58
|
+
listener(this.current);
|
|
59
|
+
return () => this.listeners.delete(listener);
|
|
60
|
+
}
|
|
61
|
+
/** Starts a tour at its first step (the host opens the step's page and lights its control). */
|
|
62
|
+
start(key, tour) {
|
|
63
|
+
if (tour.steps.length === 0)
|
|
64
|
+
return;
|
|
65
|
+
this.current = { key, title: tour.title ?? null, steps: tour.steps, index: 0, done: false };
|
|
66
|
+
this.show();
|
|
67
|
+
}
|
|
68
|
+
next() {
|
|
69
|
+
const t = this.current;
|
|
70
|
+
if (!t)
|
|
71
|
+
return;
|
|
72
|
+
if (t.index >= t.steps.length - 1) {
|
|
73
|
+
this.set({ ...t, done: true });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.current = { ...t, index: t.index + 1 };
|
|
77
|
+
this.show();
|
|
78
|
+
}
|
|
79
|
+
back() {
|
|
80
|
+
const t = this.current;
|
|
81
|
+
if (!t || t.index === 0)
|
|
82
|
+
return;
|
|
83
|
+
this.current = { ...t, index: t.index - 1, done: false };
|
|
84
|
+
this.show();
|
|
85
|
+
}
|
|
86
|
+
end() {
|
|
87
|
+
this.set(null);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The host says the person did something (`saved`, `form.open`...): a step waiting for that signal moves on by itself.
|
|
91
|
+
* Returns whether it moved.
|
|
92
|
+
*/
|
|
93
|
+
signal(name) {
|
|
94
|
+
const t = this.current;
|
|
95
|
+
const step = t ? item(t.steps, t.index) : undefined;
|
|
96
|
+
if (!t || t.done || !step || step.advanceOn !== name)
|
|
97
|
+
return false;
|
|
98
|
+
this.next();
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
show() {
|
|
102
|
+
const t = this.current;
|
|
103
|
+
const step = t ? item(t.steps, t.index) : undefined;
|
|
104
|
+
if (t && step)
|
|
105
|
+
showStep(this.host, step, t.index, t.steps.length);
|
|
106
|
+
this.set(t);
|
|
107
|
+
}
|
|
108
|
+
set(tour) {
|
|
109
|
+
this.current = tour;
|
|
110
|
+
for (const l of this.listeners)
|
|
111
|
+
l(tour);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const guides = new WeakMap();
|
|
115
|
+
/** The tour of an assistant (one per assistant): its renderers show it, the host signals it (`guideOf(a).signal("saved")`). */
|
|
116
|
+
export function guideOf(assistant) {
|
|
117
|
+
let g = guides.get(assistant);
|
|
118
|
+
if (!g) {
|
|
119
|
+
g = new Guide(assistant.host);
|
|
120
|
+
guides.set(assistant, g);
|
|
121
|
+
}
|
|
122
|
+
return g;
|
|
123
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -26,6 +26,49 @@ export interface HostFile {
|
|
|
26
26
|
type: string;
|
|
27
27
|
bytes: Uint8Array;
|
|
28
28
|
}
|
|
29
|
+
/** What a page, a step or a draft is about: the host's kind and id. */
|
|
30
|
+
export interface GuideSubject {
|
|
31
|
+
kind: string;
|
|
32
|
+
id: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* What else an `open` asks of the host: a control inside the page to scroll to and light (`target`, a name the host
|
|
36
|
+
* gave it), the sentence to show beside it (`say`, a tour step's words), and where a tour stands (`step`). How long a
|
|
37
|
+
* light stays and how it looks are the host's.
|
|
38
|
+
*/
|
|
39
|
+
export interface NavigateExtra {
|
|
40
|
+
target?: string;
|
|
41
|
+
say?: string;
|
|
42
|
+
step?: {
|
|
43
|
+
index: number;
|
|
44
|
+
count: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** A form for the person to save in the host's own screen, with the host's own permissions (the server checked it first). */
|
|
48
|
+
export interface DraftView {
|
|
49
|
+
kind: string;
|
|
50
|
+
values: Record<string, unknown>;
|
|
51
|
+
page?: string;
|
|
52
|
+
subject?: GuideSubject;
|
|
53
|
+
label?: string;
|
|
54
|
+
}
|
|
55
|
+
/** A thing of the host an answer named (`entities`), for the person to open. */
|
|
56
|
+
export interface EntityRef {
|
|
57
|
+
kind: string;
|
|
58
|
+
id: string;
|
|
59
|
+
text: string;
|
|
60
|
+
}
|
|
61
|
+
/** A ready request for the composer's `/` list. */
|
|
62
|
+
export interface QuickRequest {
|
|
63
|
+
label: string;
|
|
64
|
+
send: string;
|
|
65
|
+
}
|
|
66
|
+
/** A thing for the composer's `@` pick (a host's kind and id, and the words the person sees). */
|
|
67
|
+
export interface PickedRef {
|
|
68
|
+
kind: string;
|
|
69
|
+
id: string;
|
|
70
|
+
label: string;
|
|
71
|
+
}
|
|
29
72
|
/** Design tokens in three levels: base, semantic and per component (layer 2). */
|
|
30
73
|
export interface AssistantTheme {
|
|
31
74
|
mode: "light" | "dark";
|
|
@@ -56,10 +99,19 @@ export interface AssistantHost {
|
|
|
56
99
|
share?(text: string): Promise<void>;
|
|
57
100
|
haptic?(kind: "tick" | "ok" | "warn"): void;
|
|
58
101
|
play?(sound: "reveal" | "done"): void;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Opens a page of the host: maybe about one thing (`subject`), maybe lighting a control in it (`extra.target`) with a
|
|
104
|
+
* sentence (`extra.say`). A host that only opens pages may ignore the third argument.
|
|
105
|
+
*/
|
|
106
|
+
navigate?(pageId: string, subject?: GuideSubject, extra?: NavigateExtra): void;
|
|
107
|
+
/** Opens a host form with a draft's values (a draft block's button); without it a draft shows only its label. */
|
|
108
|
+
openDraft?(draft: DraftView): void;
|
|
109
|
+
/** Opens a thing an answer named (an `entities` block); without it names are plain text. */
|
|
110
|
+
openEntity?(entity: EntityRef): void;
|
|
111
|
+
/** The ready requests of the composer's `/` list (none: no list). */
|
|
112
|
+
quickRequests?(): readonly QuickRequest[] | Promise<readonly QuickRequest[]>;
|
|
113
|
+
/** The kinds the composer's `@` may pick (each is searched through the server's `GET pick`); none: no `@`. */
|
|
114
|
+
pickKinds?: readonly string[];
|
|
63
115
|
pageName?(pageId: string): string | undefined;
|
|
64
116
|
dictate?(): Promise<string | null>;
|
|
65
117
|
/** Starts recording audio; the returned function stops it and gives the audio (the server turns it into text). */
|
package/dist/pages.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { AssistantApi } from "./api.js";
|
|
2
2
|
import type { Assistant } from "./assistant.js";
|
|
3
3
|
import type { Texts } from "./i18n.js";
|
|
4
|
+
export * from "./chat.js";
|
|
4
5
|
export * from "./csv.js";
|
|
6
|
+
export * from "./guide.js";
|
|
5
7
|
export * from "./history.js";
|
|
6
8
|
export * from "./routine.js";
|
|
7
9
|
/** The calls of the person's pages, over the API's plain verbs. */
|
|
8
10
|
export declare const pageCalls: {
|
|
9
11
|
/** Pins or unpins a conversation (pinned ones come first in the list). */
|
|
10
12
|
pin: (api: AssistantApi, conversationId: string, pinned: boolean) => Promise<unknown>;
|
|
13
|
+
/** The person's conversations whose title holds the words, searched on the server past the first page. */
|
|
14
|
+
search: (api: AssistantApi, q: string) => Promise<unknown>;
|
|
11
15
|
/** Deletes a conversation of the person. */
|
|
12
16
|
remove: (api: AssistantApi, conversationId: string) => Promise<unknown>;
|
|
13
17
|
/** The routines the person may run, with their slots (`gaps`). */
|
package/dist/pages.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createTexts } from "./i18n.js";
|
|
2
|
+
export * from "./chat.js";
|
|
2
3
|
export * from "./csv.js";
|
|
4
|
+
export * from "./guide.js";
|
|
3
5
|
export * from "./history.js";
|
|
4
6
|
export * from "./routine.js";
|
|
5
7
|
const enc = encodeURIComponent;
|
|
@@ -7,6 +9,8 @@ const enc = encodeURIComponent;
|
|
|
7
9
|
export const pageCalls = {
|
|
8
10
|
/** Pins or unpins a conversation (pinned ones come first in the list). */
|
|
9
11
|
pin: (api, conversationId, pinned) => api.patch("conversations/" + enc(conversationId), { pinned }),
|
|
12
|
+
/** The person's conversations whose title holds the words, searched on the server past the first page. */
|
|
13
|
+
search: (api, q) => api.get("conversations?q=" + enc(q.trim())),
|
|
10
14
|
/** Deletes a conversation of the person. */
|
|
11
15
|
remove: (api, conversationId) => api.delete("conversations/" + enc(conversationId)),
|
|
12
16
|
/** The routines the person may run, with their slots (`gaps`). */
|
|
@@ -36,6 +40,22 @@ export async function runCapability(assistant, id, options = {}) {
|
|
|
36
40
|
}
|
|
37
41
|
/** The words of the person's pages (history, routine wizard) and of a refused confirmation, both languages, kept out of the core every surface loads. */
|
|
38
42
|
const PAGE_FA = {
|
|
43
|
+
"guide.open": "باز کن",
|
|
44
|
+
"guide.show": "نشانم بده",
|
|
45
|
+
"tour.start": "نشانم بده، گامبهگام",
|
|
46
|
+
"tour.step": "گام {n} از {count}",
|
|
47
|
+
"tour.next": "بعدی",
|
|
48
|
+
"tour.back": "قبلی",
|
|
49
|
+
"tour.done": "تمام",
|
|
50
|
+
"draft.open": "باز کردن فرم",
|
|
51
|
+
"message.again": "دوباره",
|
|
52
|
+
"message.edit": "ویرایش پرسش",
|
|
53
|
+
"messages.newest": "تازهترین",
|
|
54
|
+
"copy.table": "کپی جدول",
|
|
55
|
+
"copy.done": "کپی شد",
|
|
56
|
+
"work.status": "{what}…",
|
|
57
|
+
"composer.quick": "کارهای آماده",
|
|
58
|
+
"composer.pick": "انتخاب",
|
|
39
59
|
"history.tabs": "گفتوگوها",
|
|
40
60
|
"history.empty": "چیزی اینجا نیست",
|
|
41
61
|
"history.untitled": "بینام",
|
|
@@ -84,6 +104,22 @@ const PAGE_FA = {
|
|
|
84
104
|
"confirm.remote_refused": "روی گوشی رد شد",
|
|
85
105
|
};
|
|
86
106
|
const PAGE_EN = {
|
|
107
|
+
"guide.open": "Open",
|
|
108
|
+
"guide.show": "Show me",
|
|
109
|
+
"tour.start": "Show me step by step",
|
|
110
|
+
"tour.step": "Step {n} of {count}",
|
|
111
|
+
"tour.next": "Next",
|
|
112
|
+
"tour.back": "Back",
|
|
113
|
+
"tour.done": "Done",
|
|
114
|
+
"draft.open": "Open the form",
|
|
115
|
+
"message.again": "Again",
|
|
116
|
+
"message.edit": "Edit the question",
|
|
117
|
+
"messages.newest": "To the newest",
|
|
118
|
+
"copy.table": "Copy the table",
|
|
119
|
+
"copy.done": "Copied",
|
|
120
|
+
"work.status": "{what}…",
|
|
121
|
+
"composer.quick": "Ready requests",
|
|
122
|
+
"composer.pick": "Pick",
|
|
87
123
|
"history.tabs": "Conversations",
|
|
88
124
|
"history.empty": "Nothing here",
|
|
89
125
|
"history.untitled": "Untitled",
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,15 @@ export declare const DEFAULT_THRESHOLDS: LayoutThresholds;
|
|
|
12
12
|
/** The layout "auto" picks for a container width. */
|
|
13
13
|
export declare function pickLayout(layout: Layout, containerWidth: number, thresholds?: LayoutThresholds): Exclude<Layout, "auto">;
|
|
14
14
|
/** The stable part names hosts style and replace (layer 3): part of the public, versioned contract. */
|
|
15
|
-
export declare const PARTS: readonly ["panel", "panel.header", "panel.body", "panel.footer", "hero", "bar-button", "ask-about", "chat", "messages", "message", "message.user", "message.assistant", "message.text", "message.provenance", "message.feedback", "composer", "composer.input", "composer.attach", "composer.mic", "composer.send", "composer.stop", "file-chips", "file-chip", "work", "work.stage", "work.progress", "work.tool", "work.elapsed", "card.approval", "card.approval.step", "card.approval.fact", "card.approval.code", "card.approval.confirm", "card.approval.refuse", "card.undo", "card.ask", "card.choice", "secret-field", "block", "block.text", "block.callout", "block.table", "block.table.card", "block.chart", "block.chart.bar", "block.chart.line", "block.kpi", "block.steps", "block.actions", "block.action", "block.flow", "block.image", "block.open", "block.fallback", "mode-banner", "usage-chip", "thinking-orb", "stages-thinking", "reveal-text", "model-picker"];
|
|
15
|
+
export declare const PARTS: readonly ["panel", "panel.header", "panel.body", "panel.footer", "hero", "bar-button", "ask-about", "chat", "messages", "message", "message.user", "message.assistant", "message.text", "message.provenance", "message.feedback", "composer", "composer.input", "composer.attach", "composer.mic", "composer.send", "composer.stop", "file-chips", "file-chip", "work", "work.stage", "work.progress", "work.tool", "work.elapsed", "card.approval", "card.approval.step", "card.approval.fact", "card.approval.code", "card.approval.confirm", "card.approval.refuse", "card.undo", "card.ask", "card.choice", "secret-field", "block", "block.text", "block.callout", "block.table", "block.table.card", "block.chart", "block.chart.bar", "block.chart.line", "block.kpi", "block.steps", "block.actions", "block.action", "block.flow", "block.image", "block.open", "block.fallback", "mode-banner", "usage-chip", "thinking-orb", "stages-thinking", "reveal-text", "model-picker", "block.tour", "block.tour.step", "block.draft", "block.entities", "messages.newest", "work.status", "composer.menu"];
|
|
16
|
+
/**
|
|
17
|
+
* What a button is for, given to the `Button` slot with its part, so a host draws each its own way: a follow-up
|
|
18
|
+
* suggestion (`next`), a block's action (`action`), opening a page (`open`) or lighting a control in it (`show`), a
|
|
19
|
+
* draft's form (`draft`), a tour's steps (`tour`), a thing an answer named (`entity`), the message's small actions
|
|
20
|
+
* (`copy`, `again`, `edit`, `feedback`), the newest-message jump (`newest`), the composer's own (`send`, `stop`,
|
|
21
|
+
* `attach`, `quick`, `pick`), a card's (`confirm`, `refuse`, `card`) and a page's (`page`).
|
|
22
|
+
*/
|
|
23
|
+
export type ButtonRole = "next" | "action" | "open" | "show" | "draft" | "tour" | "entity" | "copy" | "again" | "edit" | "feedback" | "newest" | "send" | "stop" | "attach" | "quick" | "pick" | "confirm" | "refuse" | "card" | "page";
|
|
16
24
|
export type PartName = (typeof PARTS)[number];
|
|
17
25
|
/** Per-part classes and styles from the host (layer 3). */
|
|
18
26
|
export interface PartStyles {
|
package/dist/types.js
CHANGED
|
@@ -19,6 +19,7 @@ export const PARTS = [
|
|
|
19
19
|
"block", "block.text", "block.callout", "block.table", "block.table.card", "block.chart", "block.chart.bar", "block.chart.line",
|
|
20
20
|
"block.kpi", "block.steps", "block.actions", "block.action", "block.flow", "block.image", "block.open", "block.fallback",
|
|
21
21
|
"mode-banner", "usage-chip", "thinking-orb", "stages-thinking", "reveal-text", "model-picker",
|
|
22
|
+
"block.tour", "block.tour.step", "block.draft", "block.entities", "messages.newest", "work.status", "composer.menu",
|
|
22
23
|
];
|
|
23
24
|
/** The class of a part: the library's stable class plus the host's. */
|
|
24
25
|
export function partClass(part, styles, unstyled = false) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g9tm/aiassistant",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Headless client of the G9 AI assistant: API client, run state, transports, block view models, safe text and Persian helpers. No DOM, no framework.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@g9tm/aiassistant-contracts": "1.
|
|
36
|
+
"@g9tm/aiassistant-contracts": "1.9.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "tsc -p tsconfig.json",
|
|
39
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
|
|
40
40
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
41
41
|
}
|
|
42
42
|
}
|