@invana/assistant 0.0.33 → 0.0.35
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/index.cjs +227 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -3
- package/dist/index.d.ts +51 -3
- package/dist/index.js +226 -56
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React7 = require('react');
|
|
4
4
|
var blocks = require('@invana/blocks');
|
|
5
5
|
var ui = require('@invana/ui');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -24,7 +24,7 @@ function _interopNamespace(e) {
|
|
|
24
24
|
return Object.freeze(n);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var React7__namespace = /*#__PURE__*/_interopNamespace(React7);
|
|
28
28
|
|
|
29
29
|
// src/styles/chat-session.tsx
|
|
30
30
|
function answerToPage(turn) {
|
|
@@ -69,7 +69,7 @@ function subscribe(listener) {
|
|
|
69
69
|
return () => listeners.delete(listener);
|
|
70
70
|
}
|
|
71
71
|
function useCiteFocus(turn, initial) {
|
|
72
|
-
const pointed =
|
|
72
|
+
const pointed = React7__namespace.useSyncExternalStore(
|
|
73
73
|
subscribe,
|
|
74
74
|
() => focus.get(turn),
|
|
75
75
|
() => void 0
|
|
@@ -106,6 +106,7 @@ function answerBlock(kind) {
|
|
|
106
106
|
Renderer,
|
|
107
107
|
{
|
|
108
108
|
spec: block,
|
|
109
|
+
seamless: true,
|
|
109
110
|
onAction: (action, value) => {
|
|
110
111
|
const event = toEvent(turn.id, action, value, index);
|
|
111
112
|
if (event) onEvent(event);
|
|
@@ -126,6 +127,7 @@ function askBlock(kind) {
|
|
|
126
127
|
state: turn.state,
|
|
127
128
|
value: turn.value,
|
|
128
129
|
id: turn.id,
|
|
130
|
+
seamless: true,
|
|
129
131
|
onAction: (action, value) => {
|
|
130
132
|
const event = toEvent(turn.id, action, value, -1);
|
|
131
133
|
if (event) onEvent(event);
|
|
@@ -388,9 +390,9 @@ function stopPatches(spec, now = Date.now()) {
|
|
|
388
390
|
}
|
|
389
391
|
return patches;
|
|
390
392
|
}
|
|
391
|
-
var ChatSessionContext =
|
|
393
|
+
var ChatSessionContext = React7__namespace.createContext(null);
|
|
392
394
|
function useChatSessionContext() {
|
|
393
|
-
const value =
|
|
395
|
+
const value = React7__namespace.useContext(ChatSessionContext);
|
|
394
396
|
if (!value) throw new Error("A ChatSession part was rendered outside <ChatSession>.");
|
|
395
397
|
return value;
|
|
396
398
|
}
|
|
@@ -406,32 +408,32 @@ var DEFAULT_ICONS = {
|
|
|
406
408
|
rateDown: "\u22121"
|
|
407
409
|
};
|
|
408
410
|
function useViewState() {
|
|
409
|
-
const [steps, setSteps] =
|
|
410
|
-
const [records, setRecords] =
|
|
411
|
-
const [ratings, setRatings] =
|
|
412
|
-
const stepsOpen =
|
|
413
|
-
const toggleSteps =
|
|
411
|
+
const [steps, setSteps] = React7__namespace.useState({});
|
|
412
|
+
const [records, setRecords] = React7__namespace.useState({});
|
|
413
|
+
const [ratings, setRatings] = React7__namespace.useState({});
|
|
414
|
+
const stepsOpen = React7__namespace.useCallback((turnId, live) => steps[turnId] ?? live, [steps]);
|
|
415
|
+
const toggleSteps = React7__namespace.useCallback(
|
|
414
416
|
(turnId, open) => setSteps((prev) => ({ ...prev, [turnId]: open ?? !(prev[turnId] ?? false) })),
|
|
415
417
|
[]
|
|
416
418
|
);
|
|
417
|
-
const recordOpen =
|
|
419
|
+
const recordOpen = React7__namespace.useCallback(
|
|
418
420
|
(turnId, stepId) => !!records[`${turnId}/${stepId}`],
|
|
419
421
|
[records]
|
|
420
422
|
);
|
|
421
|
-
const toggleRecord =
|
|
423
|
+
const toggleRecord = React7__namespace.useCallback((turnId, stepId, open) => {
|
|
422
424
|
const key = `${turnId}/${stepId}`;
|
|
423
425
|
setRecords((prev) => ({ ...prev, [key]: open ?? !prev[key] }));
|
|
424
426
|
}, []);
|
|
425
|
-
const rating =
|
|
426
|
-
const setRating =
|
|
427
|
+
const rating = React7__namespace.useCallback((turnId) => ratings[turnId], [ratings]);
|
|
428
|
+
const setRating = React7__namespace.useCallback(
|
|
427
429
|
(turnId, value) => setRatings((prev) => ({ ...prev, [turnId]: value })),
|
|
428
430
|
[]
|
|
429
431
|
);
|
|
430
432
|
return { stepsOpen, toggleSteps, recordOpen, toggleRecord, rating, setRating };
|
|
431
433
|
}
|
|
432
434
|
function useClock(fixed, live, every = 250) {
|
|
433
|
-
const [now, setNow] =
|
|
434
|
-
|
|
435
|
+
const [now, setNow] = React7__namespace.useState(() => fixed ?? Date.now());
|
|
436
|
+
React7__namespace.useEffect(() => {
|
|
435
437
|
if (fixed !== void 0 || !live) return;
|
|
436
438
|
const timer = setInterval(() => setNow(Date.now()), every);
|
|
437
439
|
return () => clearInterval(timer);
|
|
@@ -654,7 +656,7 @@ function KeyHints({ running }) {
|
|
|
654
656
|
] });
|
|
655
657
|
}
|
|
656
658
|
function useStopKey(running, stop) {
|
|
657
|
-
|
|
659
|
+
React7__namespace.useEffect(() => {
|
|
658
660
|
if (!running) return;
|
|
659
661
|
const onKey = (e) => {
|
|
660
662
|
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
@@ -665,7 +667,175 @@ function useStopKey(running, stop) {
|
|
|
665
667
|
return () => document.removeEventListener("keydown", onKey);
|
|
666
668
|
}, [running, stop]);
|
|
667
669
|
}
|
|
668
|
-
|
|
670
|
+
function Answered(props) {
|
|
671
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
672
|
+
"svg",
|
|
673
|
+
{
|
|
674
|
+
"aria-hidden": "true",
|
|
675
|
+
viewBox: "0 0 24 24",
|
|
676
|
+
fill: "none",
|
|
677
|
+
stroke: "currentColor",
|
|
678
|
+
strokeWidth: 2.5,
|
|
679
|
+
strokeLinecap: "round",
|
|
680
|
+
strokeLinejoin: "round",
|
|
681
|
+
...props,
|
|
682
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 6 9 17l-5-5" })
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
var ClarifyCardGroup = React7__namespace.forwardRef(
|
|
687
|
+
({
|
|
688
|
+
state = "pending",
|
|
689
|
+
kind = "questions",
|
|
690
|
+
step,
|
|
691
|
+
questions,
|
|
692
|
+
answers: given,
|
|
693
|
+
onSubmit,
|
|
694
|
+
typePlaceholder = "Or type your own",
|
|
695
|
+
collapsible = true,
|
|
696
|
+
defaultOpen = false,
|
|
697
|
+
className,
|
|
698
|
+
...props
|
|
699
|
+
}, ref) => {
|
|
700
|
+
const settled = state !== "pending";
|
|
701
|
+
const [answers, setAnswers] = React7__namespace.useState(given ?? {});
|
|
702
|
+
const isAnswered = (q) => !!answers[q.name]?.trim();
|
|
703
|
+
const [active, setActive] = React7__namespace.useState(
|
|
704
|
+
() => (questions.find((q) => !given?.[q.name]) ?? questions[0])?.name ?? ""
|
|
705
|
+
);
|
|
706
|
+
if (settled) {
|
|
707
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
708
|
+
ui.ClarifyCard,
|
|
709
|
+
{
|
|
710
|
+
ref,
|
|
711
|
+
variant: "inline",
|
|
712
|
+
state,
|
|
713
|
+
kind,
|
|
714
|
+
step,
|
|
715
|
+
collapsible,
|
|
716
|
+
defaultOpen,
|
|
717
|
+
className,
|
|
718
|
+
questions: questions.map((q) => {
|
|
719
|
+
const a = given?.[q.name];
|
|
720
|
+
const picked = q.options?.some((o) => o.value === a);
|
|
721
|
+
return { ...q, value: picked ? a : void 0, answer: picked ? void 0 : a };
|
|
722
|
+
}),
|
|
723
|
+
...props
|
|
724
|
+
}
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
const index = Math.max(
|
|
728
|
+
0,
|
|
729
|
+
questions.findIndex((q) => q.name === active)
|
|
730
|
+
);
|
|
731
|
+
const current = questions[index];
|
|
732
|
+
const answeredCount = questions.filter(isAnswered).length;
|
|
733
|
+
const ready = questions.every((q) => q.required === false || isAnswered(q));
|
|
734
|
+
const last = index === questions.length - 1;
|
|
735
|
+
const answer = (name, value, advance) => {
|
|
736
|
+
const next = { ...answers, [name]: value };
|
|
737
|
+
setAnswers(next);
|
|
738
|
+
if (!advance) return;
|
|
739
|
+
const after = [...questions.slice(index + 1), ...questions.slice(0, index)];
|
|
740
|
+
const open = after.find((q) => !next[q.name]?.trim());
|
|
741
|
+
if (open) setActive(open.name);
|
|
742
|
+
};
|
|
743
|
+
const tabs = questions.map((q, i) => ({
|
|
744
|
+
key: q.name,
|
|
745
|
+
name: typeof q.title === "string" ? q.title : `Question ${i + 1}`,
|
|
746
|
+
label: q.title ?? `Q${i + 1}`,
|
|
747
|
+
icon: isAnswered(q) ? Answered : void 0,
|
|
748
|
+
iconClassName: "size-3 text-primary"
|
|
749
|
+
}));
|
|
750
|
+
const typed = current ? !current.options?.some((o) => o.value === answers[current.name]) : false;
|
|
751
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
752
|
+
"div",
|
|
753
|
+
{
|
|
754
|
+
ref,
|
|
755
|
+
"data-state": state,
|
|
756
|
+
className: ui.cn("flex min-w-0 flex-col gap-2", className),
|
|
757
|
+
...props,
|
|
758
|
+
children: [
|
|
759
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-1.5", children: [
|
|
760
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 font-medium first-letter:uppercase", children: kind }),
|
|
761
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "min-w-0 truncate text-muted-foreground first-letter:uppercase", children: [
|
|
762
|
+
step != null ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
763
|
+
step,
|
|
764
|
+
" \xB7 "
|
|
765
|
+
] }) : null,
|
|
766
|
+
answeredCount,
|
|
767
|
+
" of ",
|
|
768
|
+
questions.length,
|
|
769
|
+
" answered"
|
|
770
|
+
] })
|
|
771
|
+
] }),
|
|
772
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
773
|
+
ui.NavItems,
|
|
774
|
+
{
|
|
775
|
+
items: tabs,
|
|
776
|
+
selectionMode: "tabs",
|
|
777
|
+
variant: "underline",
|
|
778
|
+
overflow: true,
|
|
779
|
+
activeKey: current?.name,
|
|
780
|
+
onActiveChange: setActive,
|
|
781
|
+
className: "border-b border-border"
|
|
782
|
+
}
|
|
783
|
+
),
|
|
784
|
+
current ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1.5", children: [
|
|
785
|
+
current.question != null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium", children: current.question }) : null,
|
|
786
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Questionnaire, { onSubmit: (e) => e.preventDefault(), children: /* @__PURE__ */ jsxRuntime.jsxs(ui.QuestionnaireItem, { name: current.name, children: [
|
|
787
|
+
current.options?.length ? /* @__PURE__ */ jsxRuntime.jsx(ui.QuestionnaireChoices, { children: current.options.map((o) => {
|
|
788
|
+
const checked = answers[current.name] === o.value;
|
|
789
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
790
|
+
ui.QuestionnaireChoice,
|
|
791
|
+
{
|
|
792
|
+
value: o.value,
|
|
793
|
+
detail: o.detail,
|
|
794
|
+
disabled: o.disabled,
|
|
795
|
+
checked,
|
|
796
|
+
onChange: () => answer(current.name, o.value, true),
|
|
797
|
+
className: "border-transparent",
|
|
798
|
+
children: [
|
|
799
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.QuestionnaireChoiceTitle, { children: o.label }),
|
|
800
|
+
o.description != null ? /* @__PURE__ */ jsxRuntime.jsx(ui.QuestionnaireChoiceDescription, { children: o.description }) : null
|
|
801
|
+
]
|
|
802
|
+
},
|
|
803
|
+
o.value
|
|
804
|
+
);
|
|
805
|
+
}) }) : null,
|
|
806
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
807
|
+
ui.QuestionnaireInput,
|
|
808
|
+
{
|
|
809
|
+
"aria-label": `${typeof current.title === "string" ? current.title : "Answer"} \u2014 your own words`,
|
|
810
|
+
placeholder: current.options?.length ? typePlaceholder : "Type your answer",
|
|
811
|
+
value: typed ? answers[current.name] ?? "" : "",
|
|
812
|
+
onChange: (e) => answer(current.name, e.currentTarget.value, false)
|
|
813
|
+
}
|
|
814
|
+
)
|
|
815
|
+
] }) })
|
|
816
|
+
] }) : null,
|
|
817
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
818
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
819
|
+
ui.Button,
|
|
820
|
+
{
|
|
821
|
+
size: "xs",
|
|
822
|
+
variant: "ghost",
|
|
823
|
+
disabled: index === 0,
|
|
824
|
+
onClick: () => setActive(questions[index - 1]?.name ?? active),
|
|
825
|
+
children: "Back"
|
|
826
|
+
}
|
|
827
|
+
),
|
|
828
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1" }),
|
|
829
|
+
!last ? /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "xs", variant: "outline", onClick: () => setActive(questions[index + 1]?.name ?? active), children: "Next" }) : null,
|
|
830
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "xs", disabled: !ready, onClick: () => onSubmit?.(answers), children: "Submit" })
|
|
831
|
+
] })
|
|
832
|
+
]
|
|
833
|
+
}
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
ClarifyCardGroup.displayName = "ClarifyCardGroup";
|
|
838
|
+
var ClarifyCard2 = ui.ClarifyCard;
|
|
669
839
|
var ClarifyFootnote = ui.ClarifyFootnote;
|
|
670
840
|
var ClarifyActions = ui.ClarifyActions;
|
|
671
841
|
|
|
@@ -813,7 +983,7 @@ function AskView({ turn, registry, onEvent, now }) {
|
|
|
813
983
|
}
|
|
814
984
|
const time = turn.state === "answered" && turn.answeredAt ? relativeTime(turn.answeredAt, now) : void 0;
|
|
815
985
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
816
|
-
|
|
986
|
+
ClarifyCard2,
|
|
817
987
|
{
|
|
818
988
|
state: turn.state,
|
|
819
989
|
kind: traits.kind,
|
|
@@ -1019,15 +1189,15 @@ function ComposerBar({ isRunning: isRunning2, onStop }) {
|
|
|
1019
1189
|
const { spec, emit, icons, setComposer } = useChatSessionContext();
|
|
1020
1190
|
const composer = spec.composer;
|
|
1021
1191
|
const controls = composer?.controls ?? [];
|
|
1022
|
-
const [draft, setDraft] =
|
|
1023
|
-
const [files, setFiles] =
|
|
1024
|
-
const [picks, setPicks] =
|
|
1192
|
+
const [draft, setDraft] = React7__namespace.useState("");
|
|
1193
|
+
const [files, setFiles] = React7__namespace.useState([]);
|
|
1194
|
+
const [picks, setPicks] = React7__namespace.useState({});
|
|
1025
1195
|
const settings = initialSettings(composer);
|
|
1026
1196
|
for (const c of controls) {
|
|
1027
1197
|
const pick = picks[c.id];
|
|
1028
1198
|
if (pick !== void 0 && c.options.some((o) => o.value === pick)) settings[c.id] = pick;
|
|
1029
1199
|
}
|
|
1030
|
-
const fileInput =
|
|
1200
|
+
const fileInput = React7__namespace.useRef(null);
|
|
1031
1201
|
const picked = controls.map((c) => c.options.find((o) => o.value === settings[c.id])).filter(Boolean);
|
|
1032
1202
|
const placeholder = picked.find((o) => o?.placeholder)?.placeholder ?? composer?.placeholder;
|
|
1033
1203
|
const mono = picked.some((o) => o?.mono);
|
|
@@ -1408,7 +1578,7 @@ function CliSession({ running, onStop, header, onClose, emptyState, className })
|
|
|
1408
1578
|
|
|
1409
1579
|
// src/styles/types.ts
|
|
1410
1580
|
var DEFAULT_ANSWER_ACTIONS = ["retry", "copy", "steps", "rate"];
|
|
1411
|
-
var TurnLabel =
|
|
1581
|
+
var TurnLabel = React7__namespace.forwardRef(
|
|
1412
1582
|
({ align = "start", className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1413
1583
|
"div",
|
|
1414
1584
|
{
|
|
@@ -1541,7 +1711,7 @@ function WebSession({ running, onStop, header, onClose, emptyState, className })
|
|
|
1541
1711
|
] });
|
|
1542
1712
|
}
|
|
1543
1713
|
var handlerName = (type) => `on${type.replace(/(^|-)([a-z])/g, (_, __, c) => c.toUpperCase())}`;
|
|
1544
|
-
var ChatSession =
|
|
1714
|
+
var ChatSession = React7__namespace.forwardRef(function ChatSession2(props, ref) {
|
|
1545
1715
|
const {
|
|
1546
1716
|
spec,
|
|
1547
1717
|
variant = "web",
|
|
@@ -1566,49 +1736,49 @@ var ChatSession = React6__namespace.forwardRef(function ChatSession2(props, ref)
|
|
|
1566
1736
|
});
|
|
1567
1737
|
const running = live.turns.some((t) => isAnswer(t) && runOutcome(t) === "live");
|
|
1568
1738
|
const now = useClock(fixedNow, running);
|
|
1569
|
-
const resolved =
|
|
1570
|
-
const resolvedIcons =
|
|
1739
|
+
const resolved = React7__namespace.useMemo(() => resolveRegistry(registry), [registry]);
|
|
1740
|
+
const resolvedIcons = React7__namespace.useMemo(() => ({ ...DEFAULT_ICONS, ...icons }), [icons]);
|
|
1571
1741
|
const viewState = useViewState();
|
|
1572
|
-
const [uncontrolledView, setUncontrolledView] =
|
|
1742
|
+
const [uncontrolledView, setUncontrolledView] = React7__namespace.useState(defaultView);
|
|
1573
1743
|
const view = controlledView ?? uncontrolledView;
|
|
1574
|
-
const root =
|
|
1575
|
-
const composer =
|
|
1576
|
-
const setComposer =
|
|
1744
|
+
const root = React7__namespace.useRef(null);
|
|
1745
|
+
const composer = React7__namespace.useRef(null);
|
|
1746
|
+
const setComposer = React7__namespace.useCallback((element) => {
|
|
1577
1747
|
composer.current = element;
|
|
1578
1748
|
}, []);
|
|
1579
|
-
const latest =
|
|
1580
|
-
const liveRef =
|
|
1581
|
-
|
|
1749
|
+
const latest = React7__namespace.useRef(props);
|
|
1750
|
+
const liveRef = React7__namespace.useRef(live);
|
|
1751
|
+
React7__namespace.useLayoutEffect(() => {
|
|
1582
1752
|
latest.current = props;
|
|
1583
1753
|
liveRef.current = live;
|
|
1584
1754
|
});
|
|
1585
|
-
const emit =
|
|
1755
|
+
const emit = React7__namespace.useCallback((event) => {
|
|
1586
1756
|
const handler = latest.current[handlerName(event.type)];
|
|
1587
1757
|
if (typeof handler === "function") handler(event);
|
|
1588
1758
|
latest.current.onEvent?.(event);
|
|
1589
1759
|
}, []);
|
|
1590
|
-
const stop =
|
|
1760
|
+
const stop = React7__namespace.useCallback(() => {
|
|
1591
1761
|
stopStream();
|
|
1592
1762
|
emit({ type: "stop" });
|
|
1593
1763
|
}, [stopStream, emit]);
|
|
1594
1764
|
useStopKey(running, stop);
|
|
1595
|
-
const setView =
|
|
1765
|
+
const setView = React7__namespace.useCallback(
|
|
1596
1766
|
(next) => {
|
|
1597
1767
|
if (latest.current.view === void 0) setUncontrolledView(next);
|
|
1598
1768
|
latest.current.onViewChange?.(next);
|
|
1599
1769
|
},
|
|
1600
1770
|
[]
|
|
1601
1771
|
);
|
|
1602
|
-
const scrollToTurn =
|
|
1772
|
+
const scrollToTurn = React7__namespace.useCallback((turnId) => {
|
|
1603
1773
|
setTimeout(() => {
|
|
1604
1774
|
const id = turnDomId(liveRef.current, turnId);
|
|
1605
1775
|
root.current?.querySelector(`[id="${CSS.escape(id)}"]`)?.scrollIntoView({ block: "start", behavior: "smooth" });
|
|
1606
1776
|
}, 80);
|
|
1607
1777
|
}, []);
|
|
1608
|
-
const focusComposer =
|
|
1778
|
+
const focusComposer = React7__namespace.useCallback(() => {
|
|
1609
1779
|
composer.current?.querySelector("textarea")?.focus();
|
|
1610
1780
|
}, []);
|
|
1611
|
-
|
|
1781
|
+
React7__namespace.useImperativeHandle(
|
|
1612
1782
|
ref,
|
|
1613
1783
|
() => ({
|
|
1614
1784
|
scrollToTurn,
|
|
@@ -1658,19 +1828,19 @@ var ChatSession = React6__namespace.forwardRef(function ChatSession2(props, ref)
|
|
|
1658
1828
|
return /* @__PURE__ */ jsxRuntime.jsx(ChatSessionContext.Provider, { value: context, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: root, "data-variant": variant, className: "contents", children: variant === "cli" ? /* @__PURE__ */ jsxRuntime.jsx(CliSession, { ...shared }) : /* @__PURE__ */ jsxRuntime.jsx(WebSession, { ...shared }) }) });
|
|
1659
1829
|
});
|
|
1660
1830
|
function useChatSession(initial) {
|
|
1661
|
-
const [spec, setSpec] =
|
|
1662
|
-
const current =
|
|
1663
|
-
const controllers =
|
|
1664
|
-
const [streams, setStreams] =
|
|
1665
|
-
const set2 =
|
|
1831
|
+
const [spec, setSpec] = React7__namespace.useState(initial);
|
|
1832
|
+
const current = React7__namespace.useRef(spec);
|
|
1833
|
+
const controllers = React7__namespace.useRef(/* @__PURE__ */ new Set());
|
|
1834
|
+
const [streams, setStreams] = React7__namespace.useState(0);
|
|
1835
|
+
const set2 = React7__namespace.useCallback((next) => {
|
|
1666
1836
|
current.current = next;
|
|
1667
1837
|
setSpec(next);
|
|
1668
1838
|
}, []);
|
|
1669
|
-
const apply =
|
|
1839
|
+
const apply = React7__namespace.useCallback(
|
|
1670
1840
|
(patch) => set2(applyPatches(current.current, Array.isArray(patch) ? patch : [patch])),
|
|
1671
1841
|
[set2]
|
|
1672
1842
|
);
|
|
1673
|
-
const run =
|
|
1843
|
+
const run = React7__namespace.useCallback(
|
|
1674
1844
|
async (open) => {
|
|
1675
1845
|
const controller = new AbortController();
|
|
1676
1846
|
controllers.current.add(controller);
|
|
@@ -1688,8 +1858,8 @@ function useChatSession(initial) {
|
|
|
1688
1858
|
},
|
|
1689
1859
|
[set2]
|
|
1690
1860
|
);
|
|
1691
|
-
const stream =
|
|
1692
|
-
const play =
|
|
1861
|
+
const stream = React7__namespace.useCallback((source) => run(() => source), [run]);
|
|
1862
|
+
const play = React7__namespace.useCallback(
|
|
1693
1863
|
(script, options) => run((signal) => playScript(script, { ...options, signal })),
|
|
1694
1864
|
[run]
|
|
1695
1865
|
);
|
|
@@ -1697,25 +1867,25 @@ function useChatSession(initial) {
|
|
|
1697
1867
|
for (const c of controllers.current) c.abort();
|
|
1698
1868
|
controllers.current.clear();
|
|
1699
1869
|
};
|
|
1700
|
-
const stop =
|
|
1870
|
+
const stop = React7__namespace.useCallback(() => {
|
|
1701
1871
|
abortAll();
|
|
1702
1872
|
set2(applyPatches(current.current, stopPatches(current.current)));
|
|
1703
1873
|
}, [set2]);
|
|
1704
|
-
const reset =
|
|
1874
|
+
const reset = React7__namespace.useCallback(
|
|
1705
1875
|
(next) => {
|
|
1706
1876
|
abortAll();
|
|
1707
1877
|
set2(next);
|
|
1708
1878
|
},
|
|
1709
1879
|
[set2]
|
|
1710
1880
|
);
|
|
1711
|
-
|
|
1881
|
+
React7__namespace.useEffect(() => () => abortAll(), []);
|
|
1712
1882
|
return { spec, apply, stream, play, stop, reset, streaming: streams > 0, running: isRunning(spec) };
|
|
1713
1883
|
}
|
|
1714
1884
|
function ChatSessionTurn({ turn, onEvent, registry, now }) {
|
|
1715
|
-
const resolved =
|
|
1885
|
+
const resolved = React7__namespace.useMemo(() => resolveRegistry(registry), [registry]);
|
|
1716
1886
|
const view = useViewState();
|
|
1717
|
-
const [clock] =
|
|
1718
|
-
const emit =
|
|
1887
|
+
const [clock] = React7__namespace.useState(() => now ?? Date.now());
|
|
1888
|
+
const emit = React7__namespace.useCallback((event) => onEvent?.(event), [onEvent]);
|
|
1719
1889
|
const context = {
|
|
1720
1890
|
spec: { id: `turn-${turn.id}`, turns: [turn] },
|
|
1721
1891
|
registry: resolved,
|
|
@@ -1962,7 +2132,8 @@ exports.ChatSessionTaskRow = ChatSessionTaskRow;
|
|
|
1962
2132
|
exports.ChatSessionTurn = ChatSessionTurn;
|
|
1963
2133
|
exports.CitationMarker = CitationMarker;
|
|
1964
2134
|
exports.ClarifyActions = ClarifyActions;
|
|
1965
|
-
exports.ClarifyCard =
|
|
2135
|
+
exports.ClarifyCard = ClarifyCard2;
|
|
2136
|
+
exports.ClarifyCardGroup = ClarifyCardGroup;
|
|
1966
2137
|
exports.ClarifyFootnote = ClarifyFootnote;
|
|
1967
2138
|
exports.DEFAULT_ANSWER_ACTIONS = DEFAULT_ANSWER_ACTIONS;
|
|
1968
2139
|
exports.EVENT_TYPES = EVENT_TYPES;
|