@invana/assistant 0.0.34 → 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 +225 -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 +224 -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
|
|
@@ -390,9 +390,9 @@ function stopPatches(spec, now = Date.now()) {
|
|
|
390
390
|
}
|
|
391
391
|
return patches;
|
|
392
392
|
}
|
|
393
|
-
var ChatSessionContext =
|
|
393
|
+
var ChatSessionContext = React7__namespace.createContext(null);
|
|
394
394
|
function useChatSessionContext() {
|
|
395
|
-
const value =
|
|
395
|
+
const value = React7__namespace.useContext(ChatSessionContext);
|
|
396
396
|
if (!value) throw new Error("A ChatSession part was rendered outside <ChatSession>.");
|
|
397
397
|
return value;
|
|
398
398
|
}
|
|
@@ -408,32 +408,32 @@ var DEFAULT_ICONS = {
|
|
|
408
408
|
rateDown: "\u22121"
|
|
409
409
|
};
|
|
410
410
|
function useViewState() {
|
|
411
|
-
const [steps, setSteps] =
|
|
412
|
-
const [records, setRecords] =
|
|
413
|
-
const [ratings, setRatings] =
|
|
414
|
-
const stepsOpen =
|
|
415
|
-
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(
|
|
416
416
|
(turnId, open) => setSteps((prev) => ({ ...prev, [turnId]: open ?? !(prev[turnId] ?? false) })),
|
|
417
417
|
[]
|
|
418
418
|
);
|
|
419
|
-
const recordOpen =
|
|
419
|
+
const recordOpen = React7__namespace.useCallback(
|
|
420
420
|
(turnId, stepId) => !!records[`${turnId}/${stepId}`],
|
|
421
421
|
[records]
|
|
422
422
|
);
|
|
423
|
-
const toggleRecord =
|
|
423
|
+
const toggleRecord = React7__namespace.useCallback((turnId, stepId, open) => {
|
|
424
424
|
const key = `${turnId}/${stepId}`;
|
|
425
425
|
setRecords((prev) => ({ ...prev, [key]: open ?? !prev[key] }));
|
|
426
426
|
}, []);
|
|
427
|
-
const rating =
|
|
428
|
-
const setRating =
|
|
427
|
+
const rating = React7__namespace.useCallback((turnId) => ratings[turnId], [ratings]);
|
|
428
|
+
const setRating = React7__namespace.useCallback(
|
|
429
429
|
(turnId, value) => setRatings((prev) => ({ ...prev, [turnId]: value })),
|
|
430
430
|
[]
|
|
431
431
|
);
|
|
432
432
|
return { stepsOpen, toggleSteps, recordOpen, toggleRecord, rating, setRating };
|
|
433
433
|
}
|
|
434
434
|
function useClock(fixed, live, every = 250) {
|
|
435
|
-
const [now, setNow] =
|
|
436
|
-
|
|
435
|
+
const [now, setNow] = React7__namespace.useState(() => fixed ?? Date.now());
|
|
436
|
+
React7__namespace.useEffect(() => {
|
|
437
437
|
if (fixed !== void 0 || !live) return;
|
|
438
438
|
const timer = setInterval(() => setNow(Date.now()), every);
|
|
439
439
|
return () => clearInterval(timer);
|
|
@@ -656,7 +656,7 @@ function KeyHints({ running }) {
|
|
|
656
656
|
] });
|
|
657
657
|
}
|
|
658
658
|
function useStopKey(running, stop) {
|
|
659
|
-
|
|
659
|
+
React7__namespace.useEffect(() => {
|
|
660
660
|
if (!running) return;
|
|
661
661
|
const onKey = (e) => {
|
|
662
662
|
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
@@ -667,7 +667,175 @@ function useStopKey(running, stop) {
|
|
|
667
667
|
return () => document.removeEventListener("keydown", onKey);
|
|
668
668
|
}, [running, stop]);
|
|
669
669
|
}
|
|
670
|
-
|
|
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;
|
|
671
839
|
var ClarifyFootnote = ui.ClarifyFootnote;
|
|
672
840
|
var ClarifyActions = ui.ClarifyActions;
|
|
673
841
|
|
|
@@ -815,7 +983,7 @@ function AskView({ turn, registry, onEvent, now }) {
|
|
|
815
983
|
}
|
|
816
984
|
const time = turn.state === "answered" && turn.answeredAt ? relativeTime(turn.answeredAt, now) : void 0;
|
|
817
985
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
818
|
-
|
|
986
|
+
ClarifyCard2,
|
|
819
987
|
{
|
|
820
988
|
state: turn.state,
|
|
821
989
|
kind: traits.kind,
|
|
@@ -1021,15 +1189,15 @@ function ComposerBar({ isRunning: isRunning2, onStop }) {
|
|
|
1021
1189
|
const { spec, emit, icons, setComposer } = useChatSessionContext();
|
|
1022
1190
|
const composer = spec.composer;
|
|
1023
1191
|
const controls = composer?.controls ?? [];
|
|
1024
|
-
const [draft, setDraft] =
|
|
1025
|
-
const [files, setFiles] =
|
|
1026
|
-
const [picks, setPicks] =
|
|
1192
|
+
const [draft, setDraft] = React7__namespace.useState("");
|
|
1193
|
+
const [files, setFiles] = React7__namespace.useState([]);
|
|
1194
|
+
const [picks, setPicks] = React7__namespace.useState({});
|
|
1027
1195
|
const settings = initialSettings(composer);
|
|
1028
1196
|
for (const c of controls) {
|
|
1029
1197
|
const pick = picks[c.id];
|
|
1030
1198
|
if (pick !== void 0 && c.options.some((o) => o.value === pick)) settings[c.id] = pick;
|
|
1031
1199
|
}
|
|
1032
|
-
const fileInput =
|
|
1200
|
+
const fileInput = React7__namespace.useRef(null);
|
|
1033
1201
|
const picked = controls.map((c) => c.options.find((o) => o.value === settings[c.id])).filter(Boolean);
|
|
1034
1202
|
const placeholder = picked.find((o) => o?.placeholder)?.placeholder ?? composer?.placeholder;
|
|
1035
1203
|
const mono = picked.some((o) => o?.mono);
|
|
@@ -1410,7 +1578,7 @@ function CliSession({ running, onStop, header, onClose, emptyState, className })
|
|
|
1410
1578
|
|
|
1411
1579
|
// src/styles/types.ts
|
|
1412
1580
|
var DEFAULT_ANSWER_ACTIONS = ["retry", "copy", "steps", "rate"];
|
|
1413
|
-
var TurnLabel =
|
|
1581
|
+
var TurnLabel = React7__namespace.forwardRef(
|
|
1414
1582
|
({ align = "start", className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1415
1583
|
"div",
|
|
1416
1584
|
{
|
|
@@ -1543,7 +1711,7 @@ function WebSession({ running, onStop, header, onClose, emptyState, className })
|
|
|
1543
1711
|
] });
|
|
1544
1712
|
}
|
|
1545
1713
|
var handlerName = (type) => `on${type.replace(/(^|-)([a-z])/g, (_, __, c) => c.toUpperCase())}`;
|
|
1546
|
-
var ChatSession =
|
|
1714
|
+
var ChatSession = React7__namespace.forwardRef(function ChatSession2(props, ref) {
|
|
1547
1715
|
const {
|
|
1548
1716
|
spec,
|
|
1549
1717
|
variant = "web",
|
|
@@ -1568,49 +1736,49 @@ var ChatSession = React6__namespace.forwardRef(function ChatSession2(props, ref)
|
|
|
1568
1736
|
});
|
|
1569
1737
|
const running = live.turns.some((t) => isAnswer(t) && runOutcome(t) === "live");
|
|
1570
1738
|
const now = useClock(fixedNow, running);
|
|
1571
|
-
const resolved =
|
|
1572
|
-
const resolvedIcons =
|
|
1739
|
+
const resolved = React7__namespace.useMemo(() => resolveRegistry(registry), [registry]);
|
|
1740
|
+
const resolvedIcons = React7__namespace.useMemo(() => ({ ...DEFAULT_ICONS, ...icons }), [icons]);
|
|
1573
1741
|
const viewState = useViewState();
|
|
1574
|
-
const [uncontrolledView, setUncontrolledView] =
|
|
1742
|
+
const [uncontrolledView, setUncontrolledView] = React7__namespace.useState(defaultView);
|
|
1575
1743
|
const view = controlledView ?? uncontrolledView;
|
|
1576
|
-
const root =
|
|
1577
|
-
const composer =
|
|
1578
|
-
const setComposer =
|
|
1744
|
+
const root = React7__namespace.useRef(null);
|
|
1745
|
+
const composer = React7__namespace.useRef(null);
|
|
1746
|
+
const setComposer = React7__namespace.useCallback((element) => {
|
|
1579
1747
|
composer.current = element;
|
|
1580
1748
|
}, []);
|
|
1581
|
-
const latest =
|
|
1582
|
-
const liveRef =
|
|
1583
|
-
|
|
1749
|
+
const latest = React7__namespace.useRef(props);
|
|
1750
|
+
const liveRef = React7__namespace.useRef(live);
|
|
1751
|
+
React7__namespace.useLayoutEffect(() => {
|
|
1584
1752
|
latest.current = props;
|
|
1585
1753
|
liveRef.current = live;
|
|
1586
1754
|
});
|
|
1587
|
-
const emit =
|
|
1755
|
+
const emit = React7__namespace.useCallback((event) => {
|
|
1588
1756
|
const handler = latest.current[handlerName(event.type)];
|
|
1589
1757
|
if (typeof handler === "function") handler(event);
|
|
1590
1758
|
latest.current.onEvent?.(event);
|
|
1591
1759
|
}, []);
|
|
1592
|
-
const stop =
|
|
1760
|
+
const stop = React7__namespace.useCallback(() => {
|
|
1593
1761
|
stopStream();
|
|
1594
1762
|
emit({ type: "stop" });
|
|
1595
1763
|
}, [stopStream, emit]);
|
|
1596
1764
|
useStopKey(running, stop);
|
|
1597
|
-
const setView =
|
|
1765
|
+
const setView = React7__namespace.useCallback(
|
|
1598
1766
|
(next) => {
|
|
1599
1767
|
if (latest.current.view === void 0) setUncontrolledView(next);
|
|
1600
1768
|
latest.current.onViewChange?.(next);
|
|
1601
1769
|
},
|
|
1602
1770
|
[]
|
|
1603
1771
|
);
|
|
1604
|
-
const scrollToTurn =
|
|
1772
|
+
const scrollToTurn = React7__namespace.useCallback((turnId) => {
|
|
1605
1773
|
setTimeout(() => {
|
|
1606
1774
|
const id = turnDomId(liveRef.current, turnId);
|
|
1607
1775
|
root.current?.querySelector(`[id="${CSS.escape(id)}"]`)?.scrollIntoView({ block: "start", behavior: "smooth" });
|
|
1608
1776
|
}, 80);
|
|
1609
1777
|
}, []);
|
|
1610
|
-
const focusComposer =
|
|
1778
|
+
const focusComposer = React7__namespace.useCallback(() => {
|
|
1611
1779
|
composer.current?.querySelector("textarea")?.focus();
|
|
1612
1780
|
}, []);
|
|
1613
|
-
|
|
1781
|
+
React7__namespace.useImperativeHandle(
|
|
1614
1782
|
ref,
|
|
1615
1783
|
() => ({
|
|
1616
1784
|
scrollToTurn,
|
|
@@ -1660,19 +1828,19 @@ var ChatSession = React6__namespace.forwardRef(function ChatSession2(props, ref)
|
|
|
1660
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 }) }) });
|
|
1661
1829
|
});
|
|
1662
1830
|
function useChatSession(initial) {
|
|
1663
|
-
const [spec, setSpec] =
|
|
1664
|
-
const current =
|
|
1665
|
-
const controllers =
|
|
1666
|
-
const [streams, setStreams] =
|
|
1667
|
-
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) => {
|
|
1668
1836
|
current.current = next;
|
|
1669
1837
|
setSpec(next);
|
|
1670
1838
|
}, []);
|
|
1671
|
-
const apply =
|
|
1839
|
+
const apply = React7__namespace.useCallback(
|
|
1672
1840
|
(patch) => set2(applyPatches(current.current, Array.isArray(patch) ? patch : [patch])),
|
|
1673
1841
|
[set2]
|
|
1674
1842
|
);
|
|
1675
|
-
const run =
|
|
1843
|
+
const run = React7__namespace.useCallback(
|
|
1676
1844
|
async (open) => {
|
|
1677
1845
|
const controller = new AbortController();
|
|
1678
1846
|
controllers.current.add(controller);
|
|
@@ -1690,8 +1858,8 @@ function useChatSession(initial) {
|
|
|
1690
1858
|
},
|
|
1691
1859
|
[set2]
|
|
1692
1860
|
);
|
|
1693
|
-
const stream =
|
|
1694
|
-
const play =
|
|
1861
|
+
const stream = React7__namespace.useCallback((source) => run(() => source), [run]);
|
|
1862
|
+
const play = React7__namespace.useCallback(
|
|
1695
1863
|
(script, options) => run((signal) => playScript(script, { ...options, signal })),
|
|
1696
1864
|
[run]
|
|
1697
1865
|
);
|
|
@@ -1699,25 +1867,25 @@ function useChatSession(initial) {
|
|
|
1699
1867
|
for (const c of controllers.current) c.abort();
|
|
1700
1868
|
controllers.current.clear();
|
|
1701
1869
|
};
|
|
1702
|
-
const stop =
|
|
1870
|
+
const stop = React7__namespace.useCallback(() => {
|
|
1703
1871
|
abortAll();
|
|
1704
1872
|
set2(applyPatches(current.current, stopPatches(current.current)));
|
|
1705
1873
|
}, [set2]);
|
|
1706
|
-
const reset =
|
|
1874
|
+
const reset = React7__namespace.useCallback(
|
|
1707
1875
|
(next) => {
|
|
1708
1876
|
abortAll();
|
|
1709
1877
|
set2(next);
|
|
1710
1878
|
},
|
|
1711
1879
|
[set2]
|
|
1712
1880
|
);
|
|
1713
|
-
|
|
1881
|
+
React7__namespace.useEffect(() => () => abortAll(), []);
|
|
1714
1882
|
return { spec, apply, stream, play, stop, reset, streaming: streams > 0, running: isRunning(spec) };
|
|
1715
1883
|
}
|
|
1716
1884
|
function ChatSessionTurn({ turn, onEvent, registry, now }) {
|
|
1717
|
-
const resolved =
|
|
1885
|
+
const resolved = React7__namespace.useMemo(() => resolveRegistry(registry), [registry]);
|
|
1718
1886
|
const view = useViewState();
|
|
1719
|
-
const [clock] =
|
|
1720
|
-
const emit =
|
|
1887
|
+
const [clock] = React7__namespace.useState(() => now ?? Date.now());
|
|
1888
|
+
const emit = React7__namespace.useCallback((event) => onEvent?.(event), [onEvent]);
|
|
1721
1889
|
const context = {
|
|
1722
1890
|
spec: { id: `turn-${turn.id}`, turns: [turn] },
|
|
1723
1891
|
registry: resolved,
|
|
@@ -1964,7 +2132,8 @@ exports.ChatSessionTaskRow = ChatSessionTaskRow;
|
|
|
1964
2132
|
exports.ChatSessionTurn = ChatSessionTurn;
|
|
1965
2133
|
exports.CitationMarker = CitationMarker;
|
|
1966
2134
|
exports.ClarifyActions = ClarifyActions;
|
|
1967
|
-
exports.ClarifyCard =
|
|
2135
|
+
exports.ClarifyCard = ClarifyCard2;
|
|
2136
|
+
exports.ClarifyCardGroup = ClarifyCardGroup;
|
|
1968
2137
|
exports.ClarifyFootnote = ClarifyFootnote;
|
|
1969
2138
|
exports.DEFAULT_ANSWER_ACTIONS = DEFAULT_ANSWER_ACTIONS;
|
|
1970
2139
|
exports.EVENT_TYPES = EVENT_TYPES;
|