@galaxycore/ai-chat 0.6.0 → 0.8.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/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/dist/{appearance-BUtKwRL5.d.ts → appearance-Bcj6SrBr.d.ts} +2 -2
- package/dist/appearance.d.ts +1 -1
- package/dist/appearance.js +1 -1
- package/dist/{labels-D8smv23O.d.ts → branches-4UjruXJV.d.ts} +104 -3
- package/dist/branches-MrtWHEkd.js +332 -0
- package/dist/branches-MrtWHEkd.js.map +1 -0
- package/dist/context.js +1 -1
- package/dist/headless.d.ts +2 -2
- package/dist/headless.js +2 -2
- package/dist/index.d.ts +24 -3
- package/dist/index.js +300 -99
- package/dist/index.js.map +1 -1
- package/dist/styles.css +9 -0
- package/dist/{ui-primitives-BCbe9Ds8.js → ui-primitives-BJFXxysT.js} +5 -2
- package/dist/{ui-primitives-BCbe9Ds8.js.map → ui-primitives-BJFXxysT.js.map} +1 -1
- package/docs/api-reference.md +2 -1
- package/docs/publishing.md +6 -6
- package/docs/streaming.md +27 -1
- package/docs/validation.md +13 -0
- package/package.json +1 -1
- package/dist/labels-BM5o9a9K.js +0 -116
- package/dist/labels-BM5o9a9K.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import { a as ChatIconName, c as Icon, i as ChatAppearanceProviderProps, n as ChatIconButtonProps, o as ChatIconOverrides, r as ChatAppearanceProvider, s as ChatIconProps, t as ChatIconButton } from "./appearance-
|
|
2
|
+
import { a as ChatIconName, c as Icon, i as ChatAppearanceProviderProps, n as ChatIconButtonProps, o as ChatIconOverrides, r as ChatAppearanceProvider, s as ChatIconProps, t as ChatIconButton } from "./appearance-Bcj6SrBr.js";
|
|
3
3
|
import { ChatContextAdapter, ChatContextController, ChatContextItem, ChatContextOptions, ChatContextValue, ChatRequestContext, ContextTray, ContextTrayLabels, ContextTrayProps, SelectedChatContextItem, TextSelectionAdapterOptions, createTextSelectionAdapter, useChatContext } from "./context.js";
|
|
4
4
|
import { SpeechInputAdapter, SpeechInputController, SpeechInputError, SpeechInputErrorCode, SpeechInputLabels, SpeechInputOptions, SpeechInputResult, SpeechInputSession, SpeechInputStartOptions, SpeechInputState, SpeechInputSupport, UseSpeechInputOptions, createBrowserSpeechAdapter, defaultSpeechInputLabels, useSpeechInput } from "./voice.js";
|
|
5
|
-
import { C as
|
|
5
|
+
import { A as ToolPresentationResolver, C as ChatScrollHandle, D as TextRenderer, E as PartRenderers, O as ToolPart, S as ChatPanelProps, T as PartRendererProps, _ as ChatBranchInfo, a as projectChatBranches, b as ChatMessageActionContext, c as zhCN, f as useAiChat, g as AttachmentOptions, h as AiChatProps, i as ProjectChatBranchesOptions, j as ToolRenderers, k as ToolPresentation, m as AiChatOptions, n as ChatBranchesController, o as useChatBranches, p as AiChatController, r as ChatBranchesState, s as enUS, t as ChatBranchProjection, u as getMessageText, v as ChatComposerProps, w as ChatSuggestedAction, x as ChatMessagesProps, y as ChatLabels } from "./branches-4UjruXJV.js";
|
|
6
6
|
import { ActiveMarquee, ChatTargetHit, ChatTargetKind, ChatTargetRect, ChatTargetingController, ChatTargetingLabels, ChatTargetingOverlay, ChatTargetingOverlayProps, PendingChatTarget, UseChatTargetingOptions, enUSTargetingLabels, toChatContextItem, useChatTargeting, zhCNTargetingLabels } from "./targeting.js";
|
|
7
7
|
import { HTMLAttributes, ReactNode } from "react";
|
|
8
8
|
import { UIMessage } from "ai";
|
|
@@ -60,5 +60,26 @@ export declare function ChatHistoryMenu({ conversations, currentId, onSelect, on
|
|
|
60
60
|
/** Drafts and upload requests are isolated by conversation id. */
|
|
61
61
|
export declare function ChatComposer<M extends UIMessage = UIMessage>(props: ChatComposerProps<M>): import("react").JSX.Element;
|
|
62
62
|
//#endregion
|
|
63
|
-
|
|
63
|
+
//#region src/branch-switcher.d.ts
|
|
64
|
+
interface ChatBranchSwitcherProps {
|
|
65
|
+
branch: ChatBranchInfo;
|
|
66
|
+
onSelect: (messageId: string) => void;
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
labels?: Partial<ChatLabels>;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
/** Compact `< 2 / 3 >` sibling-branch navigation control. */
|
|
72
|
+
export declare function ChatBranchSwitcher({ branch, onSelect, disabled, labels: overrides, className }: ChatBranchSwitcherProps): import("react").JSX.Element | null;
|
|
73
|
+
interface ChatCheckpointBannerProps {
|
|
74
|
+
message?: ReactNode;
|
|
75
|
+
onRestore?: () => void;
|
|
76
|
+
restoreLabel?: string;
|
|
77
|
+
disabled?: boolean;
|
|
78
|
+
labels?: Partial<ChatLabels>;
|
|
79
|
+
className?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Cursor-style checkpoint status bar shown when reverted before a message, with one-click Restore. */
|
|
82
|
+
export declare function ChatCheckpointBanner({ message, onRestore, restoreLabel, disabled, labels: overrides, className }: ChatCheckpointBannerProps): import("react").JSX.Element;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { type ActiveMarquee, type AiChatController, type AiChatOptions, type AiChatProps, type AttachmentOptions, ChatAppearanceProvider, type ChatAppearanceProviderProps, type ChatBranchInfo, type ChatBranchProjection, type ChatBranchSwitcherProps, type ChatBranchesController, type ChatBranchesState, type ChatCheckpointBannerProps, type ChatComposerProps, type ChatContextAdapter, type ChatContextController, type ChatContextItem, type ChatContextOptions, type ChatContextValue, type ChatHistoryItem, type ChatHistoryLabels, type ChatHistoryMenuProps, Icon as ChatIcon, ChatIconButton, type ChatIconButtonProps, type ChatIconName, type ChatIconOverrides, type ChatIconProps, type ChatLabels, type ChatMessageActionContext, type ChatMessagesProps, type ChatPanelProps, type ChatRequestContext, type ChatScrollHandle, type ChatSuggestedAction, type ChatTargetHit, type ChatTargetKind, type ChatTargetRect, type ChatTargetingController, type ChatTargetingLabels, ChatTargetingOverlay, type ChatTargetingOverlayProps, ContextTray, type ContextTrayLabels, type ContextTrayProps, type PartRendererProps, type PartRenderers, type PendingChatTarget, type ProjectChatBranchesOptions, type SelectedChatContextItem, type SpeechInputAdapter, type SpeechInputController, SpeechInputError, type SpeechInputErrorCode, type SpeechInputLabels, type SpeechInputOptions, type SpeechInputResult, type SpeechInputSession, type SpeechInputStartOptions, type SpeechInputState, type SpeechInputSupport, type TextRenderer, type TextSelectionAdapterOptions, type ToolPart, type ToolPresentation, type ToolPresentationResolver, type ToolRenderers, type UseChatTargetingOptions, type UseSpeechInputOptions, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, enUS, enUSTargetingLabels, getMessageText, projectChatBranches, toChatContextItem, useAiChat, useChatBranches, useChatContext, useChatTargeting, useSpeechInput, zhCN, zhCNTargetingLabels };
|
|
64
85
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
"use client";
|
|
3
|
-
import { i as
|
|
4
|
-
import { n as ChatAppearanceProvider, r as Icon, t as ChatIconButton } from "./ui-primitives-
|
|
3
|
+
import { a as zhCN, i as resolveLabels, n as useChatBranches, o as useAiChat, r as enUS, t as projectChatBranches } from "./branches-MrtWHEkd.js";
|
|
4
|
+
import { n as ChatAppearanceProvider, r as Icon, t as ChatIconButton } from "./ui-primitives-BJFXxysT.js";
|
|
5
5
|
import { i as safeUrl, n as asError, r as getMessageText, t as acceptsFile } from "./utils-DqBGBYA1.js";
|
|
6
6
|
import { SpeechInputError, createBrowserSpeechAdapter, defaultSpeechInputLabels, useSpeechInput } from "./voice.js";
|
|
7
7
|
import { MarkdownResponse } from "./markdown.js";
|
|
8
8
|
import { ContextTray, createTextSelectionAdapter, useChatContext } from "./context.js";
|
|
9
9
|
import "./appearance.js";
|
|
10
10
|
import { ChatTargetingOverlay, enUSTargetingLabels, toChatContextItem, useChatTargeting, zhCNTargetingLabels } from "./targeting.js";
|
|
11
|
-
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
11
|
+
import { useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
12
12
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { isToolUIPart } from "ai";
|
|
14
14
|
//#region src/chat-composer.tsx
|
|
@@ -375,6 +375,76 @@ function fitTextarea(element) {
|
|
|
375
375
|
element.style.height = `${Math.min(Math.max(element.getBoundingClientRect().height, element.scrollHeight), 180)}px`;
|
|
376
376
|
}
|
|
377
377
|
//#endregion
|
|
378
|
+
//#region src/branch-switcher.tsx
|
|
379
|
+
function formatPosition(template, index, count) {
|
|
380
|
+
return template.replace("{current}", String(index)).replace("{total}", String(count));
|
|
381
|
+
}
|
|
382
|
+
/** Compact `< 2 / 3 >` sibling-branch navigation control. */
|
|
383
|
+
function ChatBranchSwitcher({ branch, onSelect, disabled = false, labels: overrides, className }) {
|
|
384
|
+
if (branch.count <= 1) return null;
|
|
385
|
+
const labels = resolveLabels(overrides);
|
|
386
|
+
const status = formatPosition(labels.branchPosition, branch.index, branch.count);
|
|
387
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
388
|
+
className: ["gc-chat__branch-switcher", className].filter(Boolean).join(" "),
|
|
389
|
+
role: "group",
|
|
390
|
+
"aria-label": status,
|
|
391
|
+
children: [
|
|
392
|
+
/* @__PURE__ */ jsx(ChatIconButton, {
|
|
393
|
+
size: "sm",
|
|
394
|
+
icon: "chevronLeft",
|
|
395
|
+
label: labels.previousBranch,
|
|
396
|
+
disabled: disabled || !branch.prevId,
|
|
397
|
+
onClick: () => {
|
|
398
|
+
if (branch.prevId) onSelect(branch.prevId);
|
|
399
|
+
}
|
|
400
|
+
}),
|
|
401
|
+
/* @__PURE__ */ jsxs("span", {
|
|
402
|
+
className: "gc-chat__branch-count",
|
|
403
|
+
"aria-live": "polite",
|
|
404
|
+
children: [
|
|
405
|
+
branch.index,
|
|
406
|
+
"/",
|
|
407
|
+
branch.count
|
|
408
|
+
]
|
|
409
|
+
}),
|
|
410
|
+
/* @__PURE__ */ jsx(ChatIconButton, {
|
|
411
|
+
size: "sm",
|
|
412
|
+
icon: "chevron",
|
|
413
|
+
label: labels.nextBranch,
|
|
414
|
+
disabled: disabled || !branch.nextId,
|
|
415
|
+
onClick: () => {
|
|
416
|
+
if (branch.nextId) onSelect(branch.nextId);
|
|
417
|
+
}
|
|
418
|
+
})
|
|
419
|
+
]
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
/** Cursor-style checkpoint status bar shown when reverted before a message, with one-click Restore. */
|
|
423
|
+
function ChatCheckpointBanner({ message, onRestore, restoreLabel, disabled = false, labels: overrides, className }) {
|
|
424
|
+
const labels = resolveLabels(overrides);
|
|
425
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
426
|
+
className: ["gc-chat__checkpoint-banner", className].filter(Boolean).join(" "),
|
|
427
|
+
role: "status",
|
|
428
|
+
children: [
|
|
429
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
430
|
+
name: "undo",
|
|
431
|
+
className: "gc-chat__checkpoint-icon"
|
|
432
|
+
}),
|
|
433
|
+
/* @__PURE__ */ jsx("span", {
|
|
434
|
+
className: "gc-chat__checkpoint-text",
|
|
435
|
+
children: message ?? labels.revertedBanner
|
|
436
|
+
}),
|
|
437
|
+
onRestore && /* @__PURE__ */ jsx("button", {
|
|
438
|
+
type: "button",
|
|
439
|
+
className: "gc-chat__checkpoint-restore",
|
|
440
|
+
disabled,
|
|
441
|
+
onClick: onRestore,
|
|
442
|
+
children: restoreLabel ?? labels.restoreBranch
|
|
443
|
+
})
|
|
444
|
+
]
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
378
448
|
//#region src/tool-activity.tsx
|
|
379
449
|
function readableValue(value) {
|
|
380
450
|
if (typeof value === "string") return value;
|
|
@@ -556,8 +626,8 @@ function useMessageScroll(messages) {
|
|
|
556
626
|
const frame = useRef(void 0);
|
|
557
627
|
const previousTime = useRef(void 0);
|
|
558
628
|
const lastTop = useRef(0);
|
|
559
|
-
const lastMaximum = useRef(0);
|
|
560
629
|
const writtenTop = useRef(void 0);
|
|
630
|
+
const endScrollbarGesture = useRef(void 0);
|
|
561
631
|
const touchY = useRef(void 0);
|
|
562
632
|
const previousMessages = useRef(messages.map(({ id }) => id));
|
|
563
633
|
const [awayFromBottom, setAwayFromBottom] = useState(false);
|
|
@@ -571,7 +641,6 @@ function useMessageScroll(messages) {
|
|
|
571
641
|
if (!element) return;
|
|
572
642
|
if (Math.abs(element.scrollTop - top) > .5) element.scrollTop = top;
|
|
573
643
|
writtenTop.current = lastTop.current = element.scrollTop;
|
|
574
|
-
lastMaximum.current = Math.max(0, element.scrollHeight - element.clientHeight);
|
|
575
644
|
}, []);
|
|
576
645
|
const schedule = useCallback(() => {
|
|
577
646
|
if (!following.current || frame.current !== void 0) return;
|
|
@@ -607,15 +676,39 @@ function useMessageScroll(messages) {
|
|
|
607
676
|
cancel();
|
|
608
677
|
setAwayFromBottom(true);
|
|
609
678
|
}, [cancel]);
|
|
679
|
+
const reveal = useCallback((target) => {
|
|
680
|
+
const element = scroller.current;
|
|
681
|
+
const node = "commonAncestorContainer" in target ? target.commonAncestorContainer : target;
|
|
682
|
+
if (!element || !content.current?.contains(node) || !element.offsetHeight) return false;
|
|
683
|
+
const viewport = element.getBoundingClientRect();
|
|
684
|
+
const bounds = target.getBoundingClientRect();
|
|
685
|
+
const scale = viewport.height / element.offsetHeight;
|
|
686
|
+
if (!scale || bounds.height <= 0) return false;
|
|
687
|
+
const viewportTop = viewport.top + element.clientTop * scale;
|
|
688
|
+
const viewportHeight = element.clientHeight * scale;
|
|
689
|
+
if (bounds.top >= viewportTop && bounds.bottom <= viewportTop + viewportHeight) return false;
|
|
690
|
+
const centerOffset = Math.max(0, (viewportHeight - bounds.height) / 2);
|
|
691
|
+
const previousTop = element.scrollTop;
|
|
692
|
+
const desiredTop = previousTop + (bounds.top - viewportTop - centerOffset) / scale;
|
|
693
|
+
const top = Math.max(0, Math.min(desiredTop, element.scrollHeight - element.clientHeight));
|
|
694
|
+
if (Math.abs(top - previousTop) <= .5) return false;
|
|
695
|
+
write(top);
|
|
696
|
+
if (element.scrollTop === previousTop) return false;
|
|
697
|
+
pause();
|
|
698
|
+
return true;
|
|
699
|
+
}, [pause, write]);
|
|
610
700
|
useClientLayoutEffect(() => {
|
|
611
701
|
scrollToLatest();
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
702
|
+
let observer;
|
|
703
|
+
if (scroller.current && content.current && typeof ResizeObserver !== "undefined") {
|
|
704
|
+
observer = new ResizeObserver(schedule);
|
|
705
|
+
observer.observe(content.current);
|
|
706
|
+
observer.observe(scroller.current);
|
|
707
|
+
}
|
|
616
708
|
return () => {
|
|
617
|
-
observer
|
|
709
|
+
observer?.disconnect();
|
|
618
710
|
cancel();
|
|
711
|
+
endScrollbarGesture.current?.();
|
|
619
712
|
};
|
|
620
713
|
}, [
|
|
621
714
|
scrollToLatest,
|
|
@@ -644,15 +737,9 @@ function useMessageScroll(messages) {
|
|
|
644
737
|
lastTop.current = top;
|
|
645
738
|
if (writtenTop.current !== void 0 && Math.abs(top - writtenTop.current) < 1) return;
|
|
646
739
|
writtenTop.current = void 0;
|
|
647
|
-
const maximum = Math.max(0, element.scrollHeight - element.clientHeight);
|
|
648
|
-
if (following.current && maximum < lastMaximum.current && top >= maximum - 1) {
|
|
649
|
-
lastMaximum.current = maximum;
|
|
650
|
-
schedule();
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
lastMaximum.current = maximum;
|
|
654
740
|
if (top < previous - 1) {
|
|
655
|
-
pause();
|
|
741
|
+
if (endScrollbarGesture.current) pause();
|
|
742
|
+
else schedule();
|
|
656
743
|
return;
|
|
657
744
|
}
|
|
658
745
|
if (top > previous && element.scrollHeight - top - element.clientHeight <= 4) {
|
|
@@ -661,6 +748,29 @@ function useMessageScroll(messages) {
|
|
|
661
748
|
schedule();
|
|
662
749
|
}
|
|
663
750
|
}
|
|
751
|
+
function onPointerDown(event) {
|
|
752
|
+
if (event.target !== event.currentTarget || event.button !== 0 || event.pointerType === "touch") return;
|
|
753
|
+
endScrollbarGesture.current?.();
|
|
754
|
+
const document = event.currentTarget.ownerDocument;
|
|
755
|
+
const view = document.defaultView;
|
|
756
|
+
const pointerId = event.pointerId;
|
|
757
|
+
let releaseFrame;
|
|
758
|
+
const cleanup = () => {
|
|
759
|
+
document.removeEventListener("pointerup", release, true);
|
|
760
|
+
document.removeEventListener("pointercancel", release, true);
|
|
761
|
+
view?.removeEventListener("blur", cleanup);
|
|
762
|
+
if (releaseFrame !== void 0) cancelAnimationFrame(releaseFrame);
|
|
763
|
+
endScrollbarGesture.current = void 0;
|
|
764
|
+
};
|
|
765
|
+
const release = (event) => {
|
|
766
|
+
if (event.pointerId !== pointerId || releaseFrame !== void 0) return;
|
|
767
|
+
releaseFrame = requestAnimationFrame(cleanup);
|
|
768
|
+
};
|
|
769
|
+
endScrollbarGesture.current = cleanup;
|
|
770
|
+
document.addEventListener("pointerup", release, true);
|
|
771
|
+
document.addEventListener("pointercancel", release, true);
|
|
772
|
+
view?.addEventListener("blur", cleanup);
|
|
773
|
+
}
|
|
664
774
|
function consumedByNestedScroll(event) {
|
|
665
775
|
let target = event.target instanceof Element ? event.target : null;
|
|
666
776
|
while (target && target !== event.currentTarget) {
|
|
@@ -694,8 +804,10 @@ function useMessageScroll(messages) {
|
|
|
694
804
|
content,
|
|
695
805
|
awayFromBottom,
|
|
696
806
|
scrollToLatest,
|
|
807
|
+
reveal,
|
|
697
808
|
scrollEvents: {
|
|
698
809
|
onScroll,
|
|
810
|
+
onPointerDown,
|
|
699
811
|
onWheel,
|
|
700
812
|
onTouchStart,
|
|
701
813
|
onTouchMove,
|
|
@@ -797,9 +909,10 @@ function StreamingText({ text, isStreaming, enabled = true, renderText }) {
|
|
|
797
909
|
function ChatMessages(props) {
|
|
798
910
|
return /* @__PURE__ */ jsx(Messages, { ...props }, props.chat.id);
|
|
799
911
|
}
|
|
800
|
-
function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming = true, renderers, tools, toolPresentation, suggestedActions, suggestionsTitle, suggestionsDescription, renderMessageActions, renderMessageHeader, empty, className, requestOptions, onActionError, capabilities }) {
|
|
912
|
+
function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming = true, scrollRef, renderers, tools, toolPresentation, suggestedActions, suggestionsTitle, suggestionsDescription, renderMessageActions, renderUserMessageFooter, branches, onSelectBranch, onRevertMessage, onBranchMessage, renderMessageHeader, empty, className, requestOptions, onActionError, capabilities }) {
|
|
801
913
|
const labels = resolveLabels(labelOverrides);
|
|
802
|
-
const { scroller, content, awayFromBottom, scrollToLatest, scrollEvents } = useMessageScroll(chat.messages);
|
|
914
|
+
const { scroller, content, awayFromBottom, scrollToLatest, reveal, scrollEvents } = useMessageScroll(chat.messages);
|
|
915
|
+
useImperativeHandle(scrollRef, () => ({ reveal }), [reveal]);
|
|
803
916
|
const copyTimeout = useRef(void 0);
|
|
804
917
|
const actionInFlight = useRef(false);
|
|
805
918
|
const [copiedId, setCopiedId] = useState();
|
|
@@ -840,6 +953,44 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
840
953
|
setActionPending(false);
|
|
841
954
|
}
|
|
842
955
|
}
|
|
956
|
+
async function revertMessage(message) {
|
|
957
|
+
if (chat.isBusy || actionInFlight.current || !onRevertMessage) return;
|
|
958
|
+
setActionError(void 0);
|
|
959
|
+
try {
|
|
960
|
+
const pending = onRevertMessage(message);
|
|
961
|
+
if (pending && typeof pending === "object" && "then" in pending) {
|
|
962
|
+
actionInFlight.current = true;
|
|
963
|
+
setActionPending(true);
|
|
964
|
+
await pending;
|
|
965
|
+
}
|
|
966
|
+
} catch (cause) {
|
|
967
|
+
reportError(cause);
|
|
968
|
+
} finally {
|
|
969
|
+
if (actionInFlight.current) {
|
|
970
|
+
actionInFlight.current = false;
|
|
971
|
+
setActionPending(false);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
async function branchMessage(message) {
|
|
976
|
+
if (chat.isBusy || actionInFlight.current || !onBranchMessage) return;
|
|
977
|
+
setActionError(void 0);
|
|
978
|
+
try {
|
|
979
|
+
const pending = onBranchMessage(message);
|
|
980
|
+
if (pending && typeof pending === "object" && "then" in pending) {
|
|
981
|
+
actionInFlight.current = true;
|
|
982
|
+
setActionPending(true);
|
|
983
|
+
await pending;
|
|
984
|
+
}
|
|
985
|
+
} catch (cause) {
|
|
986
|
+
reportError(cause);
|
|
987
|
+
} finally {
|
|
988
|
+
if (actionInFlight.current) {
|
|
989
|
+
actionInFlight.current = false;
|
|
990
|
+
setActionPending(false);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
843
994
|
function focusComposer() {
|
|
844
995
|
content.current?.closest(".gc-chat")?.querySelector(".gc-chat__input")?.focus();
|
|
845
996
|
}
|
|
@@ -1014,87 +1165,131 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
1014
1165
|
/* @__PURE__ */ jsx("p", { children: labels.emptyDescription })
|
|
1015
1166
|
]
|
|
1016
1167
|
})),
|
|
1017
|
-
visibleMessages.map((message) =>
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
message.role
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
className: "gc-chat__message-body",
|
|
1037
|
-
children: message.parts.map((part, partIndex) => /* @__PURE__ */ jsx("div", {
|
|
1038
|
-
className: "gc-chat__part",
|
|
1039
|
-
"data-part": isToolUIPart(part) ? "tool" : part.type,
|
|
1040
|
-
children: renderPart(part, message, chat.status === "streaming" && message === last)
|
|
1041
|
-
}, isToolUIPart(part) ? `tool-${part.toolCallId}` : `${part.type}-${partIndex}`))
|
|
1042
|
-
}),
|
|
1043
|
-
message === last && message.role === "assistant" && !chat.isBusy && /* @__PURE__ */ jsxs(Fragment, { children: [actions.length > 0 && /* @__PURE__ */ jsxs("section", {
|
|
1044
|
-
className: "gc-chat__suggestions",
|
|
1045
|
-
"aria-label": labels.suggestions ?? "Suggested next steps",
|
|
1046
|
-
"aria-busy": pendingSuggestion !== void 0,
|
|
1047
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
1048
|
-
className: "gc-chat__suggestions-heading",
|
|
1049
|
-
children: [/* @__PURE__ */ jsx("h3", { children: suggestionsTitle ?? labels.suggestions ?? "Suggested next steps" }), suggestionsDescription != null && /* @__PURE__ */ jsx("span", {
|
|
1050
|
-
className: "gc-chat__suggestions-reason",
|
|
1051
|
-
children: suggestionsDescription
|
|
1168
|
+
visibleMessages.map((message) => {
|
|
1169
|
+
const branch = branches?.[message.id];
|
|
1170
|
+
const hasBranchSwitcher = Boolean(branch && branch.count > 1 && onSelectBranch);
|
|
1171
|
+
return /* @__PURE__ */ jsxs("article", {
|
|
1172
|
+
className: `gc-chat__message gc-chat__message--${message.role}`,
|
|
1173
|
+
"aria-label": message.role === "user" ? labels.user : labels.assistant,
|
|
1174
|
+
children: [
|
|
1175
|
+
message.role === "assistant" && (renderMessageHeader ? renderMessageHeader({
|
|
1176
|
+
message,
|
|
1177
|
+
isStreaming: chat.status === "streaming" && message === last,
|
|
1178
|
+
chat
|
|
1179
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
1180
|
+
className: "gc-chat__message-heading",
|
|
1181
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1182
|
+
className: "gc-chat__assistant-mark",
|
|
1183
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "sparkle" })
|
|
1184
|
+
}), /* @__PURE__ */ jsx("strong", {
|
|
1185
|
+
className: "gc-chat__assistant-name",
|
|
1186
|
+
children: labels.assistant
|
|
1052
1187
|
})]
|
|
1053
|
-
}),
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
className: "gc-
|
|
1058
|
-
"data-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1188
|
+
})),
|
|
1189
|
+
/* @__PURE__ */ jsx("div", {
|
|
1190
|
+
className: "gc-chat__message-body",
|
|
1191
|
+
children: message.parts.map((part, partIndex) => /* @__PURE__ */ jsx("div", {
|
|
1192
|
+
className: "gc-chat__part",
|
|
1193
|
+
"data-part": isToolUIPart(part) ? "tool" : part.type,
|
|
1194
|
+
children: renderPart(part, message, chat.status === "streaming" && message === last)
|
|
1195
|
+
}, isToolUIPart(part) ? `tool-${part.toolCallId}` : `${part.type}-${partIndex}`))
|
|
1196
|
+
}),
|
|
1197
|
+
message.role === "user" && (renderUserMessageFooter ? renderUserMessageFooter({
|
|
1198
|
+
message,
|
|
1199
|
+
chat,
|
|
1200
|
+
focusComposer
|
|
1201
|
+
}) : (hasBranchSwitcher || onRevertMessage) && /* @__PURE__ */ jsx("div", {
|
|
1202
|
+
className: "gc-chat__message-footer gc-chat__message-footer--user",
|
|
1203
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1204
|
+
className: "gc-chat__message-actions",
|
|
1205
|
+
role: "group",
|
|
1206
|
+
"aria-label": labels.user,
|
|
1207
|
+
children: [hasBranchSwitcher && /* @__PURE__ */ jsx(ChatBranchSwitcher, {
|
|
1208
|
+
branch,
|
|
1209
|
+
onSelect: onSelectBranch,
|
|
1210
|
+
disabled: chat.isBusy || actionPending,
|
|
1211
|
+
labels: labelOverrides
|
|
1212
|
+
}), onRevertMessage && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1213
|
+
size: "sm",
|
|
1214
|
+
label: labels.revert,
|
|
1215
|
+
icon: "undo",
|
|
1216
|
+
disabled: chat.isBusy || actionPending,
|
|
1217
|
+
onClick: () => void revertMessage(message)
|
|
1218
|
+
})]
|
|
1219
|
+
})
|
|
1220
|
+
})),
|
|
1221
|
+
message === last && message.role === "assistant" && !chat.isBusy && /* @__PURE__ */ jsxs(Fragment, { children: [actions.length > 0 && /* @__PURE__ */ jsxs("section", {
|
|
1222
|
+
className: "gc-chat__suggestions",
|
|
1223
|
+
"aria-label": labels.suggestions ?? "Suggested next steps",
|
|
1224
|
+
"aria-busy": pendingSuggestion !== void 0,
|
|
1225
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1226
|
+
className: "gc-chat__suggestions-heading",
|
|
1227
|
+
children: [/* @__PURE__ */ jsx("h3", { children: suggestionsTitle ?? labels.suggestions ?? "Suggested next steps" }), suggestionsDescription != null && /* @__PURE__ */ jsx("span", {
|
|
1228
|
+
className: "gc-chat__suggestions-reason",
|
|
1229
|
+
children: suggestionsDescription
|
|
1230
|
+
})]
|
|
1231
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1232
|
+
className: "gc-chat__suggestions-actions",
|
|
1233
|
+
children: actions.map((action, index) => /* @__PURE__ */ jsxs("button", {
|
|
1234
|
+
type: "button",
|
|
1235
|
+
className: "gc-chat__suggestion",
|
|
1236
|
+
"data-emphasis": action.emphasis === "recommended" && index !== recommendedIndex ? "secondary" : action.emphasis ?? "secondary",
|
|
1237
|
+
"data-pending": pendingSuggestion === action.id || void 0,
|
|
1238
|
+
disabled: actionPending || action.disabled,
|
|
1239
|
+
onClick: () => void selectSuggestion(action, message),
|
|
1240
|
+
children: [
|
|
1241
|
+
action.icon,
|
|
1242
|
+
pendingSuggestion === action.id ? action.pendingLabel ?? action.label : action.label,
|
|
1243
|
+
action.trailingIcon
|
|
1244
|
+
]
|
|
1245
|
+
}, action.id))
|
|
1246
|
+
})]
|
|
1247
|
+
}), renderMessageActions?.({
|
|
1248
|
+
message,
|
|
1249
|
+
chat,
|
|
1250
|
+
focusComposer
|
|
1251
|
+
})] }),
|
|
1252
|
+
message.role === "assistant" && /* @__PURE__ */ jsx("div", {
|
|
1253
|
+
className: "gc-chat__message-footer",
|
|
1254
|
+
children: showThinking && message === last ? thinking : /* @__PURE__ */ jsxs("div", {
|
|
1255
|
+
className: "gc-chat__message-actions",
|
|
1256
|
+
role: "group",
|
|
1257
|
+
"aria-label": labels.assistant,
|
|
1062
1258
|
children: [
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1259
|
+
hasBranchSwitcher && /* @__PURE__ */ jsx(ChatBranchSwitcher, {
|
|
1260
|
+
branch,
|
|
1261
|
+
onSelect: onSelectBranch,
|
|
1262
|
+
disabled: chat.isBusy || actionPending,
|
|
1263
|
+
labels: labelOverrides
|
|
1264
|
+
}),
|
|
1265
|
+
getMessageText(message) && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1266
|
+
size: "sm",
|
|
1267
|
+
label: copiedId === message.id ? labels.copied : labels.copy,
|
|
1268
|
+
icon: copiedId === message.id ? "check" : "copy",
|
|
1269
|
+
"data-copied": copiedId === message.id || void 0,
|
|
1270
|
+
disabled: chat.isBusy && message === last,
|
|
1271
|
+
onClick: () => void copy(message)
|
|
1272
|
+
}),
|
|
1273
|
+
onBranchMessage && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1274
|
+
size: "sm",
|
|
1275
|
+
label: labels.branch,
|
|
1276
|
+
icon: "branch",
|
|
1277
|
+
disabled: chat.isBusy || actionPending,
|
|
1278
|
+
onClick: () => void branchMessage(message)
|
|
1279
|
+
}),
|
|
1280
|
+
message === last && capabilities?.regenerate !== false && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1281
|
+
size: "sm",
|
|
1282
|
+
label: labels.regenerate,
|
|
1283
|
+
icon: "refresh",
|
|
1284
|
+
disabled: chat.isBusy || actionPending,
|
|
1285
|
+
onClick: () => void regenerate(message)
|
|
1286
|
+
})
|
|
1066
1287
|
]
|
|
1067
|
-
}
|
|
1068
|
-
})]
|
|
1069
|
-
}), renderMessageActions?.({
|
|
1070
|
-
message,
|
|
1071
|
-
chat,
|
|
1072
|
-
focusComposer
|
|
1073
|
-
})] }),
|
|
1074
|
-
message.role === "assistant" && /* @__PURE__ */ jsx("div", {
|
|
1075
|
-
className: "gc-chat__message-footer",
|
|
1076
|
-
children: showThinking && message === last ? thinking : /* @__PURE__ */ jsxs("div", {
|
|
1077
|
-
className: "gc-chat__message-actions",
|
|
1078
|
-
role: "group",
|
|
1079
|
-
"aria-label": labels.assistant,
|
|
1080
|
-
children: [getMessageText(message) && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1081
|
-
size: "sm",
|
|
1082
|
-
label: copiedId === message.id ? labels.copied : labels.copy,
|
|
1083
|
-
icon: copiedId === message.id ? "check" : "copy",
|
|
1084
|
-
"data-copied": copiedId === message.id || void 0,
|
|
1085
|
-
disabled: chat.isBusy && message === last,
|
|
1086
|
-
onClick: () => void copy(message)
|
|
1087
|
-
}), message === last && capabilities?.regenerate !== false && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1088
|
-
size: "sm",
|
|
1089
|
-
label: labels.regenerate,
|
|
1090
|
-
icon: "refresh",
|
|
1091
|
-
disabled: chat.isBusy || actionPending,
|
|
1092
|
-
onClick: () => void regenerate(message)
|
|
1093
|
-
})]
|
|
1288
|
+
})
|
|
1094
1289
|
})
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
}
|
|
1290
|
+
]
|
|
1291
|
+
}, message.id);
|
|
1292
|
+
}),
|
|
1098
1293
|
showThinking && last?.role !== "assistant" && /* @__PURE__ */ jsx("article", {
|
|
1099
1294
|
className: "gc-chat__message gc-chat__message--assistant",
|
|
1100
1295
|
"aria-label": labels.assistant,
|
|
@@ -1135,7 +1330,7 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
1135
1330
|
function ChatPanel(props) {
|
|
1136
1331
|
return /* @__PURE__ */ jsx(Panel, { ...props }, props.chat.id);
|
|
1137
1332
|
}
|
|
1138
|
-
function Panel({ chat, labels: labelOverrides, title, subtitle, headerIcon, header, headerActions, footer, composer, composerProps, theme = "auto", variant = "panel", density = "comfortable", capabilities, className, renderText, smoothStreaming, renderers, tools, toolPresentation, suggestedActions, suggestionsTitle, suggestionsDescription, renderMessageActions, renderMessageHeader, empty, requestOptions, onActionError, ...elementProps }) {
|
|
1333
|
+
function Panel({ chat, labels: labelOverrides, title, subtitle, headerIcon, header, headerActions, footer, composer, composerProps, theme = "auto", variant = "panel", density = "comfortable", capabilities, className, renderText, smoothStreaming, scrollRef, renderers, tools, toolPresentation, suggestedActions, suggestionsTitle, suggestionsDescription, renderMessageActions, renderUserMessageFooter, branches, onSelectBranch, onRevertMessage, onBranchMessage, renderMessageHeader, empty, requestOptions, onActionError, ...elementProps }) {
|
|
1139
1334
|
const labels = resolveLabels(labelOverrides);
|
|
1140
1335
|
const [retrying, setRetrying] = useState(false);
|
|
1141
1336
|
const [retryError, setRetryError] = useState();
|
|
@@ -1198,6 +1393,7 @@ function Panel({ chat, labels: labelOverrides, title, subtitle, headerIcon, head
|
|
|
1198
1393
|
labels: labelOverrides,
|
|
1199
1394
|
renderText,
|
|
1200
1395
|
smoothStreaming,
|
|
1396
|
+
scrollRef,
|
|
1201
1397
|
renderers,
|
|
1202
1398
|
tools,
|
|
1203
1399
|
toolPresentation,
|
|
@@ -1205,6 +1401,11 @@ function Panel({ chat, labels: labelOverrides, title, subtitle, headerIcon, head
|
|
|
1205
1401
|
suggestionsTitle,
|
|
1206
1402
|
suggestionsDescription,
|
|
1207
1403
|
renderMessageActions,
|
|
1404
|
+
renderUserMessageFooter,
|
|
1405
|
+
branches,
|
|
1406
|
+
onSelectBranch,
|
|
1407
|
+
onRevertMessage,
|
|
1408
|
+
onBranchMessage,
|
|
1208
1409
|
renderMessageHeader,
|
|
1209
1410
|
empty,
|
|
1210
1411
|
requestOptions,
|
|
@@ -1433,6 +1634,6 @@ function ChatHistoryMenu({ conversations, currentId, onSelect, onNewChat, disabl
|
|
|
1433
1634
|
});
|
|
1434
1635
|
}
|
|
1435
1636
|
//#endregion
|
|
1436
|
-
export { AiChat, ChatAppearanceProvider, ChatComposer, ChatHistoryMenu, Icon as ChatIcon, ChatIconButton, ChatMessages, ChatPanel, ChatTargetingOverlay, ContextTray, SpeechInputError, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, enUS, enUSTargetingLabels, getMessageText, toChatContextItem, useAiChat, useChatContext, useChatTargeting, useSpeechInput, zhCN, zhCNTargetingLabels };
|
|
1637
|
+
export { AiChat, ChatAppearanceProvider, ChatBranchSwitcher, ChatCheckpointBanner, ChatComposer, ChatHistoryMenu, Icon as ChatIcon, ChatIconButton, ChatMessages, ChatPanel, ChatTargetingOverlay, ContextTray, SpeechInputError, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, enUS, enUSTargetingLabels, getMessageText, projectChatBranches, toChatContextItem, useAiChat, useChatBranches, useChatContext, useChatTargeting, useSpeechInput, zhCN, zhCNTargetingLabels };
|
|
1437
1638
|
|
|
1438
1639
|
//# sourceMappingURL=index.js.map
|