@g9tm/aiassistant 1.9.0 → 1.9.1
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/assistant.d.ts +5 -0
- package/dist/chat.d.ts +23 -1
- package/dist/chat.js +67 -1
- package/dist/host.d.ts +14 -0
- package/dist/pages.js +20 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -0
- package/package.json +2 -2
package/dist/assistant.d.ts
CHANGED
|
@@ -48,6 +48,11 @@ export interface ChatOptions {
|
|
|
48
48
|
copyParts?: boolean;
|
|
49
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
50
|
status?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* «Helpful?» 👍 / 👎 under every answer (default off): a 👎 asks one reason (wrong, incomplete, not what was meant, or
|
|
53
|
+
* none). Each goes to the server's `feedback` (its learning) and to the host's `onFeedback` (its own review).
|
|
54
|
+
*/
|
|
55
|
+
feedback?: boolean;
|
|
51
56
|
}
|
|
52
57
|
/** Where `ask` sent a question. */
|
|
53
58
|
export type AskedVia = "device" | "offline" | "server" | "refused";
|
package/dist/chat.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import type { AssistantApi } from "./api.js";
|
|
7
7
|
import type { Assistant } from "./assistant.js";
|
|
8
8
|
import type { MessageView } from "./conversation.js";
|
|
9
|
-
import type { PickedRef, QuickRequest } from "./host.js";
|
|
9
|
+
import type { FeedbackReason, PickedRef, QuickRequest } from "./host.js";
|
|
10
10
|
import type { RunView } from "./run.js";
|
|
11
11
|
import type { TextBlock } from "./text.js";
|
|
12
12
|
/** The conversation's options with their defaults (every renderer reads them through this). */
|
|
@@ -17,9 +17,31 @@ export interface ChatView {
|
|
|
17
17
|
again: boolean;
|
|
18
18
|
copyParts: boolean;
|
|
19
19
|
status: boolean;
|
|
20
|
+
feedback: boolean;
|
|
20
21
|
}
|
|
21
22
|
/** An assistant's chat options resolved: selectable on; Enter as each renderer had it; one line; again, copy and status off. */
|
|
22
23
|
export declare function chatOf(assistant: Assistant): ChatView;
|
|
24
|
+
/** The reasons a 👎 offers, in order. */
|
|
25
|
+
export declare const FEEDBACK_REASONS: readonly FeedbackReason[];
|
|
26
|
+
/** One answer's rating as the conversation shows it: not yet, asking the reason of a 👎, or given. */
|
|
27
|
+
export type Rating = "asking" | "good" | "bad";
|
|
28
|
+
/** The ratings of an assistant's answers (per message id), with listeners: every renderer draws the row from it. */
|
|
29
|
+
export declare class Ratings {
|
|
30
|
+
private readonly given;
|
|
31
|
+
private readonly listeners;
|
|
32
|
+
of(messageId: string): Rating | null;
|
|
33
|
+
subscribe(listener: () => void): () => void;
|
|
34
|
+
set(messageId: string, rating: Rating): void;
|
|
35
|
+
}
|
|
36
|
+
/** The ratings of an assistant (one per assistant). */
|
|
37
|
+
export declare function ratingsOf(assistant: Assistant): Ratings;
|
|
38
|
+
/** The question an answer was to: the nearest person's message before it. */
|
|
39
|
+
export declare function questionOf(messages: readonly MessageView[], messageId: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Rates an answer: 👍 at once; 👎 first asks its reason (`reason` undefined → the row shows the reasons), then sends.
|
|
42
|
+
* The server's feedback (its learning) and the host's `onFeedback` (its review) both get it; neither failing throws.
|
|
43
|
+
*/
|
|
44
|
+
export declare function rateAnswer(assistant: Assistant, message: MessageView, good: boolean, reason?: FeedbackReason | null): Promise<void>;
|
|
23
45
|
/** The words after a leading `/` (empty right after it), or null when the text does not start with one. */
|
|
24
46
|
export declare function slashQuery(text: string): string | null;
|
|
25
47
|
/** The ready requests matching what follows `/` (at most eight). */
|
package/dist/chat.js
CHANGED
|
@@ -8,7 +8,73 @@ import { plainText } from "./text.js";
|
|
|
8
8
|
/** An assistant's chat options resolved: selectable on; Enter as each renderer had it; one line; again, copy and status off. */
|
|
9
9
|
export function chatOf(assistant) {
|
|
10
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 };
|
|
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, feedback: c.feedback === true };
|
|
12
|
+
}
|
|
13
|
+
/** The reasons a 👎 offers, in order. */
|
|
14
|
+
export const FEEDBACK_REASONS = ["wrong", "incomplete", "not_meant"];
|
|
15
|
+
/** The ratings of an assistant's answers (per message id), with listeners: every renderer draws the row from it. */
|
|
16
|
+
export class Ratings {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.given = new Map();
|
|
19
|
+
this.listeners = new Set();
|
|
20
|
+
}
|
|
21
|
+
of(messageId) {
|
|
22
|
+
return this.given.get(messageId) ?? null;
|
|
23
|
+
}
|
|
24
|
+
subscribe(listener) {
|
|
25
|
+
this.listeners.add(listener);
|
|
26
|
+
return () => this.listeners.delete(listener);
|
|
27
|
+
}
|
|
28
|
+
set(messageId, rating) {
|
|
29
|
+
this.given.set(messageId, rating);
|
|
30
|
+
for (const l of this.listeners)
|
|
31
|
+
l();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const ratings = new WeakMap();
|
|
35
|
+
/** The ratings of an assistant (one per assistant). */
|
|
36
|
+
export function ratingsOf(assistant) {
|
|
37
|
+
let r = ratings.get(assistant);
|
|
38
|
+
if (!r) {
|
|
39
|
+
r = new Ratings();
|
|
40
|
+
ratings.set(assistant, r);
|
|
41
|
+
}
|
|
42
|
+
return r;
|
|
43
|
+
}
|
|
44
|
+
/** The question an answer was to: the nearest person's message before it. */
|
|
45
|
+
export function questionOf(messages, messageId) {
|
|
46
|
+
const i = messages.findIndex((m) => m.id === messageId);
|
|
47
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
48
|
+
const m = messages[j];
|
|
49
|
+
if (m && m.role === "user")
|
|
50
|
+
return m.text;
|
|
51
|
+
}
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Rates an answer: 👍 at once; 👎 first asks its reason (`reason` undefined → the row shows the reasons), then sends.
|
|
56
|
+
* The server's feedback (its learning) and the host's `onFeedback` (its review) both get it; neither failing throws.
|
|
57
|
+
*/
|
|
58
|
+
export async function rateAnswer(assistant, message, good, reason) {
|
|
59
|
+
const r = ratingsOf(assistant);
|
|
60
|
+
if (!good && reason === undefined) {
|
|
61
|
+
r.set(message.id, "asking");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
r.set(message.id, good ? "good" : "bad");
|
|
65
|
+
const s = assistant.snapshot();
|
|
66
|
+
const verdict = {
|
|
67
|
+
conversationId: s.conversationId, messageId: message.id, good, reason: good ? null : (reason ?? null),
|
|
68
|
+
question: questionOf(s.messages, message.id), answer: message.text,
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
assistant.host.onFeedback?.(verdict);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// the host's review is a side road
|
|
75
|
+
}
|
|
76
|
+
if (s.conversationId)
|
|
77
|
+
await assistant.api.feedback(s.conversationId, message.id, good, verdict.reason ?? undefined).catch(() => undefined);
|
|
12
78
|
}
|
|
13
79
|
/** The words after a leading `/` (empty right after it), or null when the text does not start with one. */
|
|
14
80
|
export function slashQuery(text) {
|
package/dist/host.d.ts
CHANGED
|
@@ -63,6 +63,18 @@ export interface QuickRequest {
|
|
|
63
63
|
label: string;
|
|
64
64
|
send: string;
|
|
65
65
|
}
|
|
66
|
+
/** Why a person said an answer did not help (or null: no reason given). */
|
|
67
|
+
export type FeedbackReason = "wrong" | "incomplete" | "not_meant";
|
|
68
|
+
/** A person's verdict on one answer, for the host's own review (`AssistantHost.onFeedback`). */
|
|
69
|
+
export interface AnswerFeedback {
|
|
70
|
+
conversationId: string | null;
|
|
71
|
+
messageId: string;
|
|
72
|
+
good: boolean;
|
|
73
|
+
reason: FeedbackReason | null;
|
|
74
|
+
/** The question the answer was to, and the answer's words (the host scrubs before keeping them). */
|
|
75
|
+
question: string;
|
|
76
|
+
answer: string;
|
|
77
|
+
}
|
|
66
78
|
/** A thing for the composer's `@` pick (a host's kind and id, and the words the person sees). */
|
|
67
79
|
export interface PickedRef {
|
|
68
80
|
kind: string;
|
|
@@ -114,6 +126,8 @@ export interface AssistantHost {
|
|
|
114
126
|
pickKinds?: readonly string[];
|
|
115
127
|
pageName?(pageId: string): string | undefined;
|
|
116
128
|
dictate?(): Promise<string | null>;
|
|
129
|
+
/** A person rated an answer (`chat.feedback`): the host keeps it for its own review; the server's feedback is sent too. */
|
|
130
|
+
onFeedback?(feedback: AnswerFeedback): void;
|
|
117
131
|
/** Starts recording audio; the returned function stops it and gives the audio (the server turns it into text). */
|
|
118
132
|
record?(): Promise<() => Promise<{
|
|
119
133
|
bytes: Uint8Array;
|
package/dist/pages.js
CHANGED
|
@@ -50,6 +50,16 @@ const PAGE_FA = {
|
|
|
50
50
|
"draft.open": "باز کردن فرم",
|
|
51
51
|
"message.again": "دوباره",
|
|
52
52
|
"message.edit": "ویرایش پرسش",
|
|
53
|
+
"feedback.ask": "کمک کرد؟",
|
|
54
|
+
"feedback.good": "کمک کرد",
|
|
55
|
+
"feedback.bad": "کمک نکرد",
|
|
56
|
+
"feedback.why": "چه کم بود؟",
|
|
57
|
+
"feedback.reason.wrong": "اشتباه بود",
|
|
58
|
+
"feedback.reason.incomplete": "ناقص بود",
|
|
59
|
+
"feedback.reason.not_meant": "منظورم این نبود",
|
|
60
|
+
"feedback.skip": "بیدلیل",
|
|
61
|
+
"feedback.thanks": "ممنون، ثبت شد",
|
|
62
|
+
"composer.listening": "در حال شنیدن…",
|
|
53
63
|
"messages.newest": "تازهترین",
|
|
54
64
|
"copy.table": "کپی جدول",
|
|
55
65
|
"copy.done": "کپی شد",
|
|
@@ -114,6 +124,16 @@ const PAGE_EN = {
|
|
|
114
124
|
"draft.open": "Open the form",
|
|
115
125
|
"message.again": "Again",
|
|
116
126
|
"message.edit": "Edit the question",
|
|
127
|
+
"feedback.ask": "Helpful?",
|
|
128
|
+
"feedback.good": "Helpful",
|
|
129
|
+
"feedback.bad": "Not helpful",
|
|
130
|
+
"feedback.why": "What was missing?",
|
|
131
|
+
"feedback.reason.wrong": "It was wrong",
|
|
132
|
+
"feedback.reason.incomplete": "It was incomplete",
|
|
133
|
+
"feedback.reason.not_meant": "Not what I meant",
|
|
134
|
+
"feedback.skip": "Skip",
|
|
135
|
+
"feedback.thanks": "Thanks, noted",
|
|
136
|
+
"composer.listening": "Listening…",
|
|
117
137
|
"messages.newest": "To the newest",
|
|
118
138
|
"copy.table": "Copy the table",
|
|
119
139
|
"copy.done": "Copied",
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ 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", "block.tour", "block.tour.step", "block.draft", "block.entities", "messages.newest", "work.status", "composer.menu"];
|
|
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", "message.rate"];
|
|
16
16
|
/**
|
|
17
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
18
|
* suggestion (`next`), a block's action (`action`), opening a page (`open`) or lighting a control in it (`show`), a
|
|
@@ -20,7 +20,7 @@ export declare const PARTS: readonly ["panel", "panel.header", "panel.body", "pa
|
|
|
20
20
|
* (`copy`, `again`, `edit`, `feedback`), the newest-message jump (`newest`), the composer's own (`send`, `stop`,
|
|
21
21
|
* `attach`, `quick`, `pick`), a card's (`confirm`, `refuse`, `card`) and a page's (`page`).
|
|
22
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";
|
|
23
|
+
export type ButtonRole = "next" | "action" | "open" | "show" | "draft" | "tour" | "entity" | "copy" | "again" | "edit" | "feedback" | "good" | "bad" | "reason" | "newest" | "send" | "stop" | "attach" | "mic" | "quick" | "pick" | "confirm" | "refuse" | "card" | "page";
|
|
24
24
|
export type PartName = (typeof PARTS)[number];
|
|
25
25
|
/** Per-part classes and styles from the host (layer 3). */
|
|
26
26
|
export interface PartStyles {
|
package/dist/types.js
CHANGED
|
@@ -20,6 +20,7 @@ export const PARTS = [
|
|
|
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
22
|
"block.tour", "block.tour.step", "block.draft", "block.entities", "messages.newest", "work.status", "composer.menu",
|
|
23
|
+
"message.rate",
|
|
23
24
|
];
|
|
24
25
|
/** The class of a part: the library's stable class plus the host's. */
|
|
25
26
|
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.9.
|
|
3
|
+
"version": "1.9.1",
|
|
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,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@g9tm/aiassistant-contracts": "1.9.
|
|
36
|
+
"@g9tm/aiassistant-contracts": "1.9.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
|