@gntik-ai/chat 0.9.0 → 0.11.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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { Children, Component, createRef, isValidElement, memo, useCallback, useEffect, useId, useRef, useState } from "react";
3
- import { Alert, Avatar, Badge, Button, Card, Checkbox, Collapsible, CollapsiblePanel, CollapsibleTrigger, Heading, IconButton, Input, Link, Popover, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger, Radio, RadioGroup, Select, SelectContent, SelectGroup, SelectGroupLabel, SelectItem, SelectTrigger, SimpleSelect, SimpleTooltip, Spinner, Stack, StatusTag, Text, Textarea, TooltipProvider, cn, fileKind, getInitials, interpolate, useI18n } from "@gntik-ai/ui";
3
+ import { Alert, Avatar, Badge, Button, Card, Checkbox, Collapsible, CollapsiblePanel, CollapsibleTrigger, Heading, IconButton, Input, Link, Popover, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger, Radio, RadioGroup, Select, SelectContent, SelectGroup, SelectGroupLabel, SelectItem, SelectTrigger, SimpleSelect, SimpleTooltip, Spinner, Stack, StatusTag, Text, Textarea, TooltipProvider, cn, fileKind, formatBytes, getInitials, interpolate, useI18n } from "@gntik-ai/ui";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { AlertCircle, ArrowDown, ArrowUp, Check, CircleAlert, Copy, ExternalLink, File, FileArchive, FileAudio, FileCode, FileImage, FileSpreadsheet, FileText, FileVideo, Globe, Paperclip, RefreshCw, RotateCcw, Sparkles, Square, ThumbsDown, ThumbsUp, Upload, Wrench, X } from "lucide-react";
6
6
  import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
@@ -1010,38 +1010,6 @@ const doc = {
1010
1010
  ]
1011
1011
  };
1012
1012
  //#endregion
1013
- //#region src/utils/format.ts
1014
- /** "840 ms" below a second, "2.4 s" below a minute, "1 m 05 s" above. */
1015
- function formatDuration(ms) {
1016
- if (ms < 1e3) return `${Math.round(ms)} ms`;
1017
- if (ms < 6e4) return `${(ms / 1e3).toFixed(1)} s`;
1018
- const m = Math.floor(ms / 6e4);
1019
- const s = Math.round(ms % 6e4 / 1e3);
1020
- return `${m} m ${String(s).padStart(2, "0")} s`;
1021
- }
1022
- /** "12 KB", "3.4 MB". */
1023
- function formatBytes(bytes) {
1024
- if (bytes < 1024) return `${bytes} B`;
1025
- if (bytes < 1048576) return `${Math.round(bytes / 1024)} KB`;
1026
- return `${(bytes / 1048576).toFixed(1)} MB`;
1027
- }
1028
- /** Short local time ("14:05") for a message timestamp. */
1029
- function formatTime(date) {
1030
- return date.toLocaleTimeString(void 0, {
1031
- hour: "2-digit",
1032
- minute: "2-digit"
1033
- });
1034
- }
1035
- /** Pretty-prints any value as JSON; falls back to String() for cyclic or exotic values. */
1036
- function toJson(value) {
1037
- if (typeof value === "string") return value;
1038
- try {
1039
- return JSON.stringify(value, null, 2) ?? String(value);
1040
- } catch {
1041
- return String(value);
1042
- }
1043
- }
1044
- //#endregion
1045
1013
  //#region src/Attachment/attachment.variants.ts
1046
1014
  /** Slot classes for AttachmentChip / AttachmentList. */
1047
1015
  const attachmentStyles = {
@@ -1087,7 +1055,7 @@ function attachmentStatus(a) {
1087
1055
  * (a progressbar), error with retry, and a remove button.
1088
1056
  */
1089
1057
  function AttachmentChip({ attachment: a, variant = "chip", onRemove, onRetry, disabled = false, className, ref }) {
1090
- const { t, tc } = useChatI18n();
1058
+ const { t, tc, locale } = useChatI18n();
1091
1059
  const status = attachmentStatus(a);
1092
1060
  const kind = fileKind(a.name, a.type);
1093
1061
  const Icon = status === "error" ? AlertCircle : ICONS[kind];
@@ -1113,7 +1081,7 @@ function AttachmentChip({ attachment: a, variant = "chip", onRemove, onRetry, di
1113
1081
  children: pct === null ? t("common.loading") : `${pct}%`
1114
1082
  }) : a.size !== void 0 ? /* @__PURE__ */ jsx("span", {
1115
1083
  className: attachmentStyles.meta,
1116
- children: formatBytes(a.size)
1084
+ children: formatBytes(a.size, locale)
1117
1085
  }) : null;
1118
1086
  const buttons = /* @__PURE__ */ jsxs(Fragment, { children: [status === "error" && onRetry && /* @__PURE__ */ jsx("button", {
1119
1087
  type: "button",
@@ -1283,7 +1251,7 @@ const chatComposerStyles = {
1283
1251
  * streams the send button becomes Stop (Escape also stops).
1284
1252
  */
1285
1253
  function ChatComposer({ value, defaultValue = "", onValueChange, onSubmit, streaming = false, onStop, disabled = false, placeholder: placeholderProp, label: labelProp, maxLength, attachments = [], onAttach, onRemoveAttachment, onRetryAttachment, accept, maxSize, maxFiles, onReject, modelPicker, tools, hint, className, ref }) {
1286
- const { t, tc } = useChatI18n();
1254
+ const { t, tc, locale } = useChatI18n();
1287
1255
  const placeholder = placeholderProp ?? t("chat.placeholder");
1288
1256
  const label = labelProp ?? t("chat.messageLabel");
1289
1257
  const id = useId();
@@ -1329,7 +1297,7 @@ function ChatComposer({ value, defaultValue = "", onValueChange, onSubmit, strea
1329
1297
  reason,
1330
1298
  message: reason === "type" ? tc("chat.fileTypeNotAllowed", { name: file.name }) : reason === "size" ? tc("chat.fileTooLarge", {
1331
1299
  name: file.name,
1332
- max: formatBytes(maxSize ?? 0)
1300
+ max: formatBytes(maxSize ?? 0, locale)
1333
1301
  }) : tc("chat.tooManyFiles", { max: maxFiles ?? 0 })
1334
1302
  }));
1335
1303
  setErrors([...new Set(rejections.map((r) => r.message))]);
@@ -1593,6 +1561,32 @@ const doc$12 = {
1593
1561
  tokens: ["muted-foreground"]
1594
1562
  };
1595
1563
  //#endregion
1564
+ //#region src/utils/format.ts
1565
+ /** "840 ms" below a second, "2.4 s" below a minute, "1 m 05 s" above. */
1566
+ function formatDuration(ms) {
1567
+ if (ms < 1e3) return `${Math.round(ms)} ms`;
1568
+ if (ms < 6e4) return `${(ms / 1e3).toFixed(1)} s`;
1569
+ const m = Math.floor(ms / 6e4);
1570
+ const s = Math.round(ms % 6e4 / 1e3);
1571
+ return `${m} m ${String(s).padStart(2, "0")} s`;
1572
+ }
1573
+ /** Short local time ("14:05") for a message timestamp. */
1574
+ function formatTime(date) {
1575
+ return date.toLocaleTimeString(void 0, {
1576
+ hour: "2-digit",
1577
+ minute: "2-digit"
1578
+ });
1579
+ }
1580
+ /** Pretty-prints any value as JSON; falls back to String() for cyclic or exotic values. */
1581
+ function toJson(value) {
1582
+ if (typeof value === "string") return value;
1583
+ try {
1584
+ return JSON.stringify(value, null, 2) ?? String(value);
1585
+ } catch {
1586
+ return String(value);
1587
+ }
1588
+ }
1589
+ //#endregion
1596
1590
  //#region src/ChatMessage/chatMessage.variants.ts
1597
1591
  /** Slot classes for ChatMessage, per role. */
1598
1592
  const chatMessageStyles = {
@@ -3163,7 +3157,7 @@ function ChatDemo({ withPanel = true, tickMs = 30, className }) {
3163
3157
  onAttach: attach,
3164
3158
  onRemoveAttachment: (id) => setFiles((all) => all.filter((f) => f.id !== id)),
3165
3159
  accept: ".pdf,.csv,.md,.txt,.json,image/*",
3166
- maxSize: 10485760,
3160
+ maxSize: 1e7,
3167
3161
  maxFiles: 5,
3168
3162
  modelPicker: /* @__PURE__ */ jsx(ModelPicker, {
3169
3163
  compact: true,