ikoncomponents 1.6.3 → 1.6.4

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.
@@ -0,0 +1,109 @@
1
+ "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { ArrowDownIcon, ArrowUpIcon, CheckIcon, ChevronLeftIcon, ChevronRightIcon, CopyIcon, PencilIcon, RefreshCwIcon, Square, } from "lucide-react";
15
+ import { ActionBarPrimitive, BranchPickerPrimitive, ComposerPrimitive, ErrorPrimitive, MessagePrimitive, ThreadPrimitive, } from "@assistant-ui/react";
16
+ import { LazyMotion, MotionConfig, domAnimation } from "motion/react";
17
+ import * as m from "motion/react-m";
18
+ import { Button } from "../../shadcn/button";
19
+ import { MarkdownText } from "../assistant-ui/markdown-text";
20
+ import { ToolFallback } from "../assistant-ui/tool-fallback";
21
+ import { TooltipIconButton } from "../assistant-ui/tooltip-icon-button";
22
+ import { ComposerAddAttachment, ComposerAttachments, UserMessageAttachments, } from "../assistant-ui/attachment";
23
+ import { cn } from "../../utils/cn";
24
+ export const Thread = ({ currentUserDetails, }) => {
25
+ return (_jsx(LazyMotion, { features: domAnimation, children: _jsx(MotionConfig, { reducedMotion: "user", children: _jsx(ThreadPrimitive.Root, { className: "aui-root aui-thread-root @container flex h-full flex-col bg-background", style: {
26
+ ["--thread-max-width"]: "44rem",
27
+ }, children: _jsxs(ThreadPrimitive.Viewport, { turnAnchor: "top", className: "aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4", children: [_jsx(ThreadPrimitive.If, { empty: true, children: _jsx(ThreadWelcome, { currentUserDetails: currentUserDetails }) }), _jsx(ThreadPrimitive.Messages, { components: {
28
+ UserMessage,
29
+ EditComposer,
30
+ AssistantMessage,
31
+ } }), _jsxs(ThreadPrimitive.ViewportFooter, { className: "aui-thread-viewport-footer sticky bottom-0 mx-auto mt-4 flex w-full max-w-[var(--thread-max-width)] flex-col gap-4 overflow-visible rounded-t-3xl bg-background pb-4 md:pb-6", children: [_jsx(ThreadScrollToBottom, {}), _jsx(Composer, {})] })] }) }) }) }));
32
+ };
33
+ const ThreadScrollToBottom = () => {
34
+ return (_jsx(ThreadPrimitive.ScrollToBottom, { asChild: true, children: _jsx(TooltipIconButton, { tooltip: "Scroll to bottom", variant: "outline", className: "aui-thread-scroll-to-bottom absolute -top-12 z-10 self-center rounded-full p-4 disabled:invisible dark:bg-background dark:hover:bg-accent", children: _jsx(ArrowDownIcon, {}) }) }));
35
+ };
36
+ const ThreadWelcome = ({ currentUserDetails, }) => {
37
+ const now = new Date();
38
+ const hours = now.getHours();
39
+ let greeting = "";
40
+ if (hours >= 5 && hours < 12) {
41
+ greeting = "Good Morning";
42
+ }
43
+ else if (hours >= 12 && hours < 17) {
44
+ greeting = "Good Afternoon";
45
+ }
46
+ else if (hours >= 17 && hours < 21) {
47
+ greeting = "Good Evening";
48
+ }
49
+ else {
50
+ greeting = "Good Night";
51
+ }
52
+ console.log(greeting);
53
+ return (_jsxs("div", { className: "aui-thread-welcome-root mx-auto my-auto flex w-full max-w-[var(--thread-max-width)] flex-grow flex-col", children: [_jsx("div", { className: "aui-thread-welcome-center flex w-full flex-grow flex-col items-center justify-center", children: _jsxs("div", { className: "aui-thread-welcome-message flex size-full flex-col justify-center px-8", children: [_jsx(m.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 10 }, className: "aui-thread-welcome-message-motion-1 text-2xl font-semibold", children: `${greeting} ${currentUserDetails.userName.split(" ")[0]}` }), _jsx(m.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 10 }, transition: { delay: 0.1 }, className: "aui-thread-welcome-message-motion-2 text-2xl text-muted-foreground/65", children: "How can I help you today?" })] }) }), _jsx(ThreadSuggestions, {})] }));
54
+ };
55
+ const ThreadSuggestions = () => {
56
+ return (_jsx("div", { className: "aui-thread-welcome-suggestions grid w-full gap-2 pb-4 @md:grid-cols-2", children: [
57
+ {
58
+ title: "What's the weather",
59
+ label: "in San Francisco?",
60
+ action: "What's the weather in San Francisco?",
61
+ },
62
+ {
63
+ title: "Explain React hooks",
64
+ label: "like useState and useEffect",
65
+ action: "Explain React hooks like useState and useEffect",
66
+ },
67
+ {
68
+ title: "Write a SQL query",
69
+ label: "to find top customers",
70
+ action: "Write a SQL query to find top customers",
71
+ },
72
+ {
73
+ title: "Create a meal plan",
74
+ label: "for healthy weight loss",
75
+ action: "Create a meal plan for healthy weight loss",
76
+ },
77
+ ].map((suggestedAction, index) => (_jsx(m.div, { initial: { opacity: 0, y: 20 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 20 }, transition: { delay: 0.05 * index }, className: "aui-thread-welcome-suggestion-display [&:nth-child(n+3)]:hidden @md:[&:nth-child(n+3)]:block", children: _jsx(ThreadPrimitive.Suggestion, { prompt: suggestedAction.action, send: true, asChild: true, children: _jsxs(Button, { variant: "ghost", className: "aui-thread-welcome-suggestion h-auto w-full flex-1 flex-wrap items-start justify-start gap-1 rounded-3xl border px-5 py-4 text-left text-sm @md:flex-col dark:hover:bg-accent/60", "aria-label": suggestedAction.action, children: [_jsx("span", { className: "aui-thread-welcome-suggestion-text-1 font-medium", children: suggestedAction.title }), _jsx("span", { className: "aui-thread-welcome-suggestion-text-2 text-muted-foreground", children: suggestedAction.label })] }) }) }, `suggested-action-${suggestedAction.title}-${index}`))) }));
78
+ };
79
+ const Composer = () => {
80
+ return (_jsx(ComposerPrimitive.Root, { className: "aui-composer-root relative flex w-full flex-col", children: _jsxs(ComposerPrimitive.AttachmentDropzone, { className: "aui-composer-attachment-dropzone group/input-group flex w-full flex-col rounded-3xl border border-input bg-background px-1 pt-2 shadow-xs transition-[color,box-shadow] outline-none has-[textarea:focus-visible]:border-ring has-[textarea:focus-visible]:ring-[3px] has-[textarea:focus-visible]:ring-ring/50 data-[dragging=true]:border-dashed data-[dragging=true]:border-ring data-[dragging=true]:bg-accent/50 dark:bg-background", children: [_jsx(ComposerAttachments, {}), _jsx(ComposerPrimitive.Input, { placeholder: "Send a message...", className: "aui-composer-input mb-1 max-h-32 min-h-16 w-full resize-none bg-transparent px-3.5 pt-1.5 pb-3 text-base outline-none placeholder:text-muted-foreground focus-visible:ring-0", rows: 1, autoFocus: true, "aria-label": "Message input" }), _jsx(ComposerAction, {})] }) }));
81
+ };
82
+ const ComposerAction = () => {
83
+ return (_jsxs("div", { className: "aui-composer-action-wrapper relative mx-1 mt-2 mb-2 flex items-center justify-between", children: [_jsx(ComposerAddAttachment, {}), _jsx(ThreadPrimitive.If, { running: false, children: _jsx(ComposerPrimitive.Send, { asChild: true, children: _jsx(TooltipIconButton, { tooltip: "Send message", side: "bottom", type: "submit", variant: "default", size: "icon", className: "aui-composer-send size-[34px] rounded-full p-1", "aria-label": "Send message", children: _jsx(ArrowUpIcon, { className: "aui-composer-send-icon size-5" }) }) }) }), _jsx(ThreadPrimitive.If, { running: true, children: _jsx(ComposerPrimitive.Cancel, { asChild: true, children: _jsx(Button, { type: "button", variant: "default", size: "icon", className: "aui-composer-cancel size-[34px] rounded-full border border-muted-foreground/60 hover:bg-primary/75 dark:border-muted-foreground/90", "aria-label": "Stop generating", children: _jsx(Square, { className: "aui-composer-cancel-icon size-3.5 fill-white dark:fill-black" }) }) }) })] }));
84
+ };
85
+ const MessageError = () => {
86
+ return (_jsx(MessagePrimitive.Error, { children: _jsx(ErrorPrimitive.Root, { className: "aui-message-error-root mt-2 rounded-md border border-destructive bg-destructive/10 p-3 text-sm text-destructive dark:bg-destructive/5 dark:text-red-200", children: _jsx(ErrorPrimitive.Message, { className: "aui-message-error-message line-clamp-2" }) }) }));
87
+ };
88
+ const AssistantMessage = () => {
89
+ return (_jsxs(MessagePrimitive.Root, { className: "aui-assistant-message-root relative mx-auto w-full max-w-[var(--thread-max-width)] animate-in py-4 duration-150 ease-out fade-in slide-in-from-bottom-1", "data-role": "assistant", children: [_jsxs("div", { className: "aui-assistant-message-content mx-2 leading-7 break-words text-foreground", children: [_jsx(MessagePrimitive.Parts, { components: {
90
+ Text: MarkdownText,
91
+ tools: { Fallback: ToolFallback },
92
+ } }), _jsx(MessageError, {})] }), _jsxs("div", { className: "aui-assistant-message-footer mt-2 ml-2 flex", children: [_jsx(BranchPicker, {}), _jsx(AssistantActionBar, {})] })] }));
93
+ };
94
+ const AssistantActionBar = () => {
95
+ return (_jsxs(ActionBarPrimitive.Root, { hideWhenRunning: true, autohide: "not-last", autohideFloat: "single-branch", className: "aui-assistant-action-bar-root col-start-3 row-start-2 -ml-1 flex gap-1 text-muted-foreground data-floating:absolute data-floating:rounded-md data-floating:border data-floating:bg-background data-floating:p-1 data-floating:shadow-sm", children: [_jsx(ActionBarPrimitive.Copy, { asChild: true, children: _jsxs(TooltipIconButton, { tooltip: "Copy", children: [_jsx(MessagePrimitive.If, { copied: true, children: _jsx(CheckIcon, {}) }), _jsx(MessagePrimitive.If, { copied: false, children: _jsx(CopyIcon, {}) })] }) }), _jsx(ActionBarPrimitive.Reload, { asChild: true, children: _jsx(TooltipIconButton, { tooltip: "Refresh", children: _jsx(RefreshCwIcon, {}) }) })] }));
96
+ };
97
+ const UserMessage = () => {
98
+ return (_jsxs(MessagePrimitive.Root, { className: "aui-user-message-root mx-auto grid w-full max-w-[var(--thread-max-width)] animate-in auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] content-start gap-y-2 px-2 py-4 duration-150 ease-out fade-in slide-in-from-bottom-1 [&:where(>*)]:col-start-2", "data-role": "user", children: [_jsx(UserMessageAttachments, {}), _jsxs("div", { className: "aui-user-message-content-wrapper relative col-start-2 min-w-0", children: [_jsx("div", { className: "aui-user-message-content rounded-3xl bg-muted px-5 py-2.5 break-words text-foreground", children: _jsx(MessagePrimitive.Parts, {}) }), _jsx("div", { className: "aui-user-action-bar-wrapper absolute top-1/2 left-0 -translate-x-full -translate-y-1/2 pr-2", children: _jsx(UserActionBar, {}) })] }), _jsx(BranchPicker, { className: "aui-user-branch-picker col-span-full col-start-1 row-start-3 -mr-1 justify-end" })] }));
99
+ };
100
+ const UserActionBar = () => {
101
+ return (_jsx(ActionBarPrimitive.Root, { hideWhenRunning: true, autohide: "not-last", className: "aui-user-action-bar-root flex flex-col items-end", children: _jsx(ActionBarPrimitive.Edit, { asChild: true, children: _jsx(TooltipIconButton, { tooltip: "Edit", className: "aui-user-action-edit p-4", children: _jsx(PencilIcon, {}) }) }) }));
102
+ };
103
+ const EditComposer = () => {
104
+ return (_jsx(MessagePrimitive.Root, { className: "aui-edit-composer-wrapper mx-auto flex w-full max-w-[var(--thread-max-width)] flex-col gap-4 px-2", children: _jsxs(ComposerPrimitive.Root, { className: "aui-edit-composer-root ml-auto flex w-full max-w-7/8 flex-col rounded-xl bg-muted", children: [_jsx(ComposerPrimitive.Input, { className: "aui-edit-composer-input flex min-h-[60px] w-full resize-none bg-transparent p-4 text-foreground outline-none", autoFocus: true }), _jsxs("div", { className: "aui-edit-composer-footer mx-3 mb-3 flex items-center justify-center gap-2 self-end", children: [_jsx(ComposerPrimitive.Cancel, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "sm", "aria-label": "Cancel edit", children: "Cancel" }) }), _jsx(ComposerPrimitive.Send, { asChild: true, children: _jsx(Button, { size: "sm", "aria-label": "Update message", children: "Update" }) })] })] }) }));
105
+ };
106
+ const BranchPicker = (_a) => {
107
+ var { className } = _a, rest = __rest(_a, ["className"]);
108
+ return (_jsxs(BranchPickerPrimitive.Root, Object.assign({ hideWhenSingleBranch: true, className: cn("aui-branch-picker-root mr-2 -ml-2 inline-flex items-center text-xs text-muted-foreground", className) }, rest, { children: [_jsx(BranchPickerPrimitive.Previous, { asChild: true, children: _jsx(TooltipIconButton, { tooltip: "Previous", children: _jsx(ChevronLeftIcon, {}) }) }), _jsxs("span", { className: "aui-branch-picker-state font-medium", children: [_jsx(BranchPickerPrimitive.Number, {}), " / ", _jsx(BranchPickerPrimitive.Count, {})] }), _jsx(BranchPickerPrimitive.Next, { asChild: true, children: _jsx(TooltipIconButton, { tooltip: "Next", children: _jsx(ChevronRightIcon, {}) }) })] })));
109
+ };
@@ -0,0 +1,2 @@
1
+ import type { ToolCallMessagePartComponent } from "@assistant-ui/react";
2
+ export declare const ToolFallback: ToolCallMessagePartComponent;
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { CheckIcon, ChevronDownIcon, ChevronUpIcon, XCircleIcon, } from "lucide-react";
4
+ import { useState } from "react";
5
+ import { Button } from "../../shadcn/button";
6
+ import { cn } from "../../utils/cn";
7
+ export const ToolFallback = ({ toolName, argsText, result, status, }) => {
8
+ const [isCollapsed, setIsCollapsed] = useState(true);
9
+ const isCancelled = (status === null || status === void 0 ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
10
+ const cancelledReason = isCancelled && status.error
11
+ ? typeof status.error === "string"
12
+ ? status.error
13
+ : JSON.stringify(status.error)
14
+ : null;
15
+ return (_jsxs("div", { className: cn("aui-tool-fallback-root mb-4 flex w-full flex-col gap-3 rounded-lg border py-3", isCancelled && "border-muted-foreground/30 bg-muted/30"), children: [_jsxs("div", { className: "aui-tool-fallback-header flex items-center gap-2 px-4", children: [isCancelled ? (_jsx(XCircleIcon, { className: "aui-tool-fallback-icon size-4 text-muted-foreground" })) : (_jsx(CheckIcon, { className: "aui-tool-fallback-icon size-4" })), _jsxs("p", { className: cn("aui-tool-fallback-title grow", isCancelled && "text-muted-foreground line-through"), children: [isCancelled ? "Cancelled tool: " : "Used tool: ", _jsx("b", { children: toolName })] }), _jsx(Button, { onClick: () => setIsCollapsed(!isCollapsed), children: isCollapsed ? _jsx(ChevronUpIcon, {}) : _jsx(ChevronDownIcon, {}) })] }), !isCollapsed && (_jsxs("div", { className: "aui-tool-fallback-content flex flex-col gap-2 border-t pt-2", children: [cancelledReason && (_jsxs("div", { className: "aui-tool-fallback-cancelled-root px-4", children: [_jsx("p", { className: "aui-tool-fallback-cancelled-header font-semibold text-muted-foreground", children: "Cancelled reason:" }), _jsx("p", { className: "aui-tool-fallback-cancelled-reason text-muted-foreground", children: cancelledReason })] })), _jsx("div", { className: cn("aui-tool-fallback-args-root px-4", isCancelled && "opacity-60"), children: _jsx("pre", { className: "aui-tool-fallback-args-value whitespace-pre-wrap", children: argsText }) }), !isCancelled && result !== undefined && (_jsxs("div", { className: "aui-tool-fallback-result-root border-t border-dashed px-4 pt-2", children: [_jsx("p", { className: "aui-tool-fallback-result-header font-semibold", children: "Result:" }), _jsx("pre", { className: "aui-tool-fallback-result-content whitespace-pre-wrap", children: typeof result === "string"
16
+ ? result
17
+ : JSON.stringify(result, null, 2) })] }))] }))] }));
18
+ };
@@ -0,0 +1,7 @@
1
+ import { ComponentPropsWithRef } from "react";
2
+ import { Button } from "../../shadcn/button";
3
+ export type TooltipIconButtonProps = ComponentPropsWithRef<typeof Button> & {
4
+ tooltip: string;
5
+ side?: "top" | "bottom" | "left" | "right";
6
+ };
7
+ export declare const TooltipIconButton: import("react").ForwardRefExoticComponent<Omit<TooltipIconButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { forwardRef } from "react";
15
+ import { Slottable } from "@radix-ui/react-slot";
16
+ import { Tooltip, TooltipContent, TooltipTrigger, } from "../../shadcn/tooltip";
17
+ import { Button } from "../../shadcn/button";
18
+ import { cn } from "../../utils/cn";
19
+ export const TooltipIconButton = forwardRef((_a, ref) => {
20
+ var { children, tooltip, side = "bottom", className } = _a, rest = __rest(_a, ["children", "tooltip", "side", "className"]);
21
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs(Button, Object.assign({ variant: "ghost", size: "icon" }, rest, { className: cn("aui-button-icon size-6 p-1", className), ref: ref, children: [_jsx(Slottable, { children: children }), _jsx("span", { className: "aui-sr-only sr-only", children: tooltip })] })) }), _jsx(TooltipContent, { side: side, children: tooltip })] }));
22
+ });
23
+ TooltipIconButton.displayName = "TooltipIconButton";
@@ -1,4 +1,3 @@
1
- "use client";
2
1
  import { jsx as _jsx } from "react/jsx-runtime";
3
2
  import { createContext, useContext, useState, useCallback } from 'react';
4
3
  const RefreshContext = createContext(undefined);
package/dist/index.d.ts CHANGED
@@ -136,3 +136,5 @@ export { getValidAccessToken, refreshAccessToken, decodeAccessToken, logOut } fr
136
136
  export type { TokenResponse } from "./utils/token-management/types";
137
137
  export { useIsMobile } from "./hooks/use-mobile";
138
138
  export { useRefresh } from "./ikoncomponents/main-layout/RefreshContext";
139
+ export { AssistantComponent } from "./ikoncomponents/assistant-ui/Assistant";
140
+ export type { UserData } from "./utils/userType";
package/dist/index.js CHANGED
@@ -114,3 +114,4 @@ export { setCookieSession, getCookieSession, clearCookieSession, clearAllCookieS
114
114
  export { getValidAccessToken, refreshAccessToken, decodeAccessToken, logOut } from "./utils/token-management";
115
115
  export { useIsMobile } from "./hooks/use-mobile";
116
116
  export { useRefresh } from "./ikoncomponents/main-layout/RefreshContext";
117
+ export { AssistantComponent } from "./ikoncomponents/assistant-ui/Assistant";