@g9tm/aiassistant-react 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.
Files changed (2) hide show
  1. package/dist/parts.js +16 -2
  2. package/package.json +2 -2
package/dist/parts.js CHANGED
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
5
5
  */
6
6
  import { useEffect, useRef, useState } from "react";
7
7
  import { can, finished, LONG_RUNNING_MS, obj, REVEAL_MS, str, visibleText, windowView } from "@g9tm/aiassistant";
8
- import { askAgain, atWord, chatOf, composerOf, editLast, matchQuick, pageCalls, pageTexts, pickRefs, putPick, readModels, refsIn, slashQuery, statusOf } from "@g9tm/aiassistant/pages";
8
+ import { askAgain, atWord, chatOf, composerOf, editLast, FEEDBACK_REASONS, matchQuick, pageCalls, pageTexts, pickRefs, putPick, rateAnswer, ratingsOf, readModels, refsIn, slashQuery, statusOf } from "@g9tm/aiassistant/pages";
9
9
  import { BlockView, TextView } from "./blocks.js";
10
10
  import { ApprovalCard, Cards } from "./cards.js";
11
11
  import { cls, override, sty, swappable, useSnapshot, useUi } from "./context.js";
@@ -93,7 +93,21 @@ export function Message(props) {
93
93
  const Approval = override(ui, "ApprovalCard") ?? ApprovalCard;
94
94
  const Other = override(ui, "Card") ?? Cards;
95
95
  const plan = m.card?.kind === "plan" ? props.plans.get(m.card.id) : undefined;
96
- return (_jsx("div", { className: cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant"), "data-kind": m.kind, "data-pending": m.pending, children: m.card ? (plan ? _jsx(Approval, { plan: plan }) : m.card.kind !== "plan" ? _jsx(Other, { card: m.card, runId: props.runId }) : null) : (_jsxs(_Fragment, { children: [m.text.length > 0 ? _jsx("div", { className: cls(ui, "message.text"), children: _jsx(RevealText, { text: m.text, reveal: reveal }) }) : null, m.blocks.map((b, i) => _jsx(BlockView, { block: b, at: m.id + ":" + String(i) }, i)), m.next.length > 0 ? _jsx("div", { className: cls(ui, "block.actions"), children: m.next.map((n) => _jsx("button", { type: "button", className: cls(ui, "block.action"), "data-role": "next", onClick: () => void ui.assistant.send(n), children: n }, n)) }) : null, m.role === "assistant" ? (_jsxs("div", { className: cls(ui, "message.feedback"), children: [_jsx(Small, { kind: "provenance", provenance: m.provenance }), ui.assistant.host.copy ? _jsx("button", { type: "button", "data-role": "copy", onClick: () => { void ui.assistant.host.copy?.(m.text); setCopied(true); }, children: copied ? "✓" : t("feedback.copy") }) : null, m.provenance === "learned" ? _jsx("button", { type: "button", "data-role": "feedback", onClick: () => void ui.assistant.notRight(m.id), children: t("feedback.not_right") }) : null, props.last && chatOf(ui.assistant).again && !m.pending ? _jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-role": "again", onClick: () => void askAgain(ui.assistant), children: pageTexts(ui.texts).t("message.again") }), _jsx("button", { type: "button", "data-role": "edit", onClick: () => editLast(ui.assistant), children: pageTexts(ui.texts).t("message.edit") })] }) : null] })) : null] })) }));
96
+ return (_jsx("div", { className: cls(ui, "message") + " " + cls(ui, m.role === "user" ? "message.user" : "message.assistant"), "data-kind": m.kind, "data-pending": m.pending, children: m.card ? (plan ? _jsx(Approval, { plan: plan }) : m.card.kind !== "plan" ? _jsx(Other, { card: m.card, runId: props.runId }) : null) : (_jsxs(_Fragment, { children: [m.text.length > 0 ? _jsx("div", { className: cls(ui, "message.text"), children: _jsx(RevealText, { text: m.text, reveal: reveal }) }) : null, m.blocks.map((b, i) => _jsx(BlockView, { block: b, at: m.id + ":" + String(i) }, i)), m.next.length > 0 ? _jsx("div", { className: cls(ui, "block.actions"), children: m.next.map((n) => _jsx("button", { type: "button", className: cls(ui, "block.action"), "data-role": "next", onClick: () => void ui.assistant.send(n), children: n }, n)) }) : null, m.role === "assistant" ? (_jsxs("div", { className: cls(ui, "message.feedback"), children: [_jsx(Small, { kind: "provenance", provenance: m.provenance }), ui.assistant.host.copy ? _jsx("button", { type: "button", "data-role": "copy", onClick: () => { void ui.assistant.host.copy?.(m.text); setCopied(true); }, children: copied ? "✓" : t("feedback.copy") }) : null, m.provenance === "learned" ? _jsx("button", { type: "button", "data-role": "feedback", onClick: () => void ui.assistant.notRight(m.id), children: t("feedback.not_right") }) : null, props.last && chatOf(ui.assistant).again && !m.pending ? _jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-role": "again", onClick: () => void askAgain(ui.assistant), children: pageTexts(ui.texts).t("message.again") }), _jsx("button", { type: "button", "data-role": "edit", onClick: () => editLast(ui.assistant), children: pageTexts(ui.texts).t("message.edit") })] }) : null] })) : null, m.role === "assistant" && chatOf(ui.assistant).feedback && !m.pending && m.id ? _jsx(RateRow, { message: m }) : null] })) }));
97
+ }
98
+ /** «Helpful?» under an answer (`chat.feedback`): 👍 / 👎, a 👎's reasons in the same row, then thanks. */
99
+ function RateRow(props) {
100
+ const ui = useUi();
101
+ const t = pageTexts(ui.texts).t;
102
+ const ratings = ratingsOf(ui.assistant);
103
+ const [rating, setRating] = useState(() => ratings.of(props.message.id));
104
+ useEffect(() => ratings.subscribe(() => setRating(ratings.of(props.message.id))), [ratings, props.message.id]);
105
+ if (rating === "good" || rating === "bad")
106
+ return _jsx("div", { className: cls(ui, "message.rate"), children: _jsx("span", { children: t("feedback.thanks") }) });
107
+ if (rating === "asking") {
108
+ return (_jsxs("div", { className: cls(ui, "message.rate"), children: [_jsx("span", { children: t("feedback.why") }), FEEDBACK_REASONS.map((r) => _jsx("button", { type: "button", "data-role": "reason", onClick: () => void rateAnswer(ui.assistant, props.message, false, r), children: t("feedback.reason." + r) }, r)), _jsx("button", { type: "button", "data-role": "reason", onClick: () => void rateAnswer(ui.assistant, props.message, false, null), children: t("feedback.skip") })] }));
109
+ }
110
+ return (_jsxs("div", { className: cls(ui, "message.rate"), children: [_jsx("span", { children: t("feedback.ask") }), _jsx("button", { type: "button", "data-role": "good", "aria-label": t("feedback.good"), onClick: () => void rateAnswer(ui.assistant, props.message, true), children: "\uD83D\uDC4D" }), _jsx("button", { type: "button", "data-role": "bad", "aria-label": t("feedback.bad"), onClick: () => void rateAnswer(ui.assistant, props.message, false), children: "\uD83D\uDC4E" })] }));
97
111
  }
98
112
  /** The composer: input, attach (only when the host can pick a file), mic (only when the host or the server can dictate), send or stop. */
99
113
  export function Composer(props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant-react",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "React DOM components for the G9 AI assistant, fully customisable (layouts, tokens, per-part classes, overrides, parts).",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@g9tm/aiassistant": "1.9.0"
32
+ "@g9tm/aiassistant": "1.9.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/react": "19.3.0",