laif-ds 0.1.99 → 0.2.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.
@@ -1,228 +1,259 @@
1
1
  "use client";
2
- import { jsxs as C, jsx as t, Fragment as j } from "react/jsx-runtime";
3
- import { forwardRef as g, useRef as L, useCallback as N, useState as z } from "react";
4
- import { cn as B } from "../../lib/utils.js";
5
- import { useAutoScroll as D } from "../../hooks/use-auto-scroll.js";
6
- import { Button as x } from "./button.js";
7
- import { CopyButton as T } from "./copy-button.js";
8
- import { MessageInput as P } from "./message-input.js";
9
- import { MessageList as U } from "./message-list.js";
10
- import { PromptSuggestions as E } from "./prompt-suggestions.js";
11
- import O from "../../node_modules/lucide-react/dist/esm/icons/thumbs-up.js";
12
- import q from "../../node_modules/lucide-react/dist/esm/icons/thumbs-down.js";
13
- import H from "../../node_modules/lucide-react/dist/esm/icons/arrow-down.js";
14
- function J({
15
- messages: e,
16
- handleSubmit: n,
2
+ import { jsxs as N, Fragment as T, jsx as t } from "react/jsx-runtime";
3
+ import { forwardRef as g, useRef as U, useCallback as I, useState as E } from "react";
4
+ import { cn as M } from "../../lib/utils.js";
5
+ import { useAutoScroll as O } from "../../hooks/use-auto-scroll.js";
6
+ import { Button as w } from "./button.js";
7
+ import { CopyButton as k } from "./copy-button.js";
8
+ import { MessageInput as q } from "./message-input.js";
9
+ import { MessageList as H } from "./message-list.js";
10
+ import { PromptSuggestions as J } from "./prompt-suggestions.js";
11
+ import S from "../../node_modules/lucide-react/dist/esm/icons/save.js";
12
+ import K from "../../node_modules/lucide-react/dist/esm/icons/thumbs-up.js";
13
+ import Q from "../../node_modules/lucide-react/dist/esm/icons/thumbs-down.js";
14
+ import V from "../../node_modules/lucide-react/dist/esm/icons/arrow-down.js";
15
+ function W({
16
+ messages: o,
17
+ handleSubmit: r,
17
18
  input: i,
18
19
  handleInputChange: u,
19
- stop: s,
20
+ stop: a,
20
21
  isGenerating: c,
21
- append: d,
22
- suggestions: f,
23
- className: w,
24
- onRateResponse: p,
25
- setMessages: v,
26
- transcribeAudio: M
22
+ append: f,
23
+ suggestions: m,
24
+ className: v,
25
+ onRateResponse: b,
26
+ setMessages: C,
27
+ transcribeAudio: F,
28
+ allowAttachments: _ = !1,
29
+ onEdit: j,
30
+ onMessageSave: d
27
31
  }) {
28
- const k = e.at(-1), A = e.length === 0, y = k?.role === "user", b = L(e);
29
- b.current = e;
30
- const F = N(() => {
31
- if (s?.(), !v) return;
32
- const r = [...b.current], l = r.findLast(
33
- (a) => a.role === "assistant"
32
+ const L = o.at(-1), B = o.length === 0, y = L?.role === "user", x = U(o);
33
+ x.current = o;
34
+ const D = I(() => {
35
+ if (a?.(), !C) return;
36
+ const e = [...x.current], l = e.findLast(
37
+ (s) => s.role === "assistant"
34
38
  );
35
39
  if (!l) return;
36
- let m = !1, h = { ...l };
40
+ let h = !1, p = { ...l };
37
41
  if (l.toolInvocations) {
38
- const a = l.toolInvocations.map(
39
- (o) => o.state === "call" ? (m = !0, {
40
- ...o,
42
+ const s = l.toolInvocations.map(
43
+ (n) => n.state === "call" ? (h = !0, {
44
+ ...n,
41
45
  state: "result",
42
46
  result: {
43
47
  content: "Tool execution was cancelled",
44
48
  __cancelled: !0
45
49
  // Special marker to indicate cancellation
46
50
  }
47
- }) : o
51
+ }) : n
48
52
  );
49
- m && (h = {
50
- ...h,
51
- toolInvocations: a
53
+ h && (p = {
54
+ ...p,
55
+ toolInvocations: s
52
56
  });
53
57
  }
54
58
  if (l.parts && l.parts.length > 0) {
55
- const a = l.parts.map((o) => o.type === "tool-invocation" && o.toolInvocation && o.toolInvocation.state === "call" ? (m = !0, {
56
- ...o,
59
+ const s = l.parts.map((n) => n.type === "tool-invocation" && n.toolInvocation && n.toolInvocation.state === "call" ? (h = !0, {
60
+ ...n,
57
61
  toolInvocation: {
58
- ...o.toolInvocation,
62
+ ...n.toolInvocation,
59
63
  state: "result",
60
64
  result: {
61
65
  content: "Tool execution was cancelled",
62
66
  __cancelled: !0
63
67
  }
64
68
  }
65
- }) : o);
66
- m && (h = {
67
- ...h,
68
- parts: a
69
+ }) : n);
70
+ h && (p = {
71
+ ...p,
72
+ parts: s
69
73
  });
70
74
  }
71
- if (m) {
72
- const a = r.findIndex(
73
- (o) => o.id === l.id
75
+ if (h) {
76
+ const s = e.findIndex(
77
+ (n) => n.id === l.id
74
78
  );
75
- a !== -1 && (r[a] = h, v(r));
79
+ s !== -1 && (e[s] = p, C(e));
76
80
  }
77
- }, [s, v, b]), _ = N(
78
- (r) => ({
79
- actions: p ? /* @__PURE__ */ C(j, { children: [
81
+ }, [a, C, x]), P = I(
82
+ (e) => ({
83
+ actions: b ? /* @__PURE__ */ N(T, { children: [
80
84
  /* @__PURE__ */ t("div", { className: "border-d-border border-r pr-1", children: /* @__PURE__ */ t(
81
- T,
85
+ k,
82
86
  {
83
- content: r.content,
87
+ content: e.content,
84
88
  copyMessage: "Copied response to clipboard!"
85
89
  }
86
90
  ) }),
91
+ d && /* @__PURE__ */ t("div", { className: "border-d-border border-r pr-1", children: /* @__PURE__ */ t(
92
+ w,
93
+ {
94
+ size: "icon",
95
+ variant: "ghost",
96
+ className: "h-6 w-6",
97
+ onClick: () => d(e.id, e.content),
98
+ title: "Save message",
99
+ children: /* @__PURE__ */ t(S, { className: "h-4 w-4" })
100
+ }
101
+ ) }),
87
102
  /* @__PURE__ */ t(
88
- x,
103
+ w,
89
104
  {
90
105
  size: "icon",
91
106
  variant: "ghost",
92
107
  className: "h-6 w-6",
93
- onClick: () => p(r.id, "thumbs-up"),
94
- children: /* @__PURE__ */ t(O, { className: "h-4 w-4" })
108
+ onClick: () => b(e.id, "thumbs-up"),
109
+ children: /* @__PURE__ */ t(K, { className: "h-4 w-4" })
95
110
  }
96
111
  ),
97
112
  /* @__PURE__ */ t(
98
- x,
113
+ w,
99
114
  {
100
115
  size: "icon",
101
116
  variant: "ghost",
102
117
  className: "h-6 w-6",
103
- onClick: () => p(r.id, "thumbs-down"),
104
- children: /* @__PURE__ */ t(q, { className: "h-4 w-4" })
118
+ onClick: () => b(e.id, "thumbs-down"),
119
+ children: /* @__PURE__ */ t(Q, { className: "h-4 w-4" })
105
120
  }
106
121
  )
107
- ] }) : /* @__PURE__ */ t(
108
- T,
109
- {
110
- content: r.content,
111
- copyMessage: "Copied response to clipboard!"
112
- }
113
- )
122
+ ] }) : /* @__PURE__ */ N(T, { children: [
123
+ /* @__PURE__ */ t(
124
+ k,
125
+ {
126
+ content: e.content,
127
+ copyMessage: "Copied response to clipboard!"
128
+ }
129
+ ),
130
+ d && /* @__PURE__ */ t("div", { className: "border-d-border border-l pl-1", children: /* @__PURE__ */ t(
131
+ w,
132
+ {
133
+ size: "icon",
134
+ variant: "ghost",
135
+ className: "h-6 w-6",
136
+ onClick: () => d(e.id, e.content),
137
+ title: "Save message",
138
+ children: /* @__PURE__ */ t(S, { className: "h-4 w-4" })
139
+ }
140
+ ) })
141
+ ] }),
142
+ onMessageSave: d
114
143
  }),
115
- [p]
144
+ [b, d]
116
145
  );
117
- return /* @__PURE__ */ C(S, { className: w, children: [
118
- A && d && f ? /* @__PURE__ */ t(
119
- E,
146
+ return /* @__PURE__ */ N(z, { className: v, children: [
147
+ B && f && m ? /* @__PURE__ */ t(
148
+ J,
120
149
  {
121
150
  label: "Try these prompts ✨",
122
- append: d,
123
- suggestions: f
151
+ append: f,
152
+ suggestions: m
124
153
  }
125
154
  ) : null,
126
- e.length > 0 ? /* @__PURE__ */ t(K, { messages: e, children: /* @__PURE__ */ t(
127
- U,
155
+ o.length > 0 ? /* @__PURE__ */ t(X, { messages: o, children: /* @__PURE__ */ t(
156
+ H,
128
157
  {
129
- messages: e,
158
+ messages: o,
130
159
  isTyping: y,
131
- messageOptions: _
160
+ messageOptions: P,
161
+ onEdit: j,
162
+ onMessageSave: d
132
163
  }
133
164
  ) }) : null,
134
165
  /* @__PURE__ */ t(
135
- I,
166
+ A,
136
167
  {
137
168
  className: "flex-shrink-0",
138
169
  isPending: c || y,
139
- handleSubmit: n,
140
- children: ({ files: r, setFiles: l }) => /* @__PURE__ */ t(
141
- P,
170
+ handleSubmit: r,
171
+ children: ({ files: e, setFiles: l }) => /* @__PURE__ */ t(
172
+ q,
142
173
  {
143
174
  value: i,
144
175
  onChange: u,
145
- allowAttachments: !0,
146
- files: r,
176
+ allowAttachments: _,
177
+ files: e,
147
178
  setFiles: l,
148
- stop: F,
179
+ stop: D,
149
180
  isGenerating: c,
150
- transcribeAudio: M
181
+ transcribeAudio: F
151
182
  }
152
183
  )
153
184
  }
154
185
  )
155
186
  ] });
156
187
  }
157
- J.displayName = "Chat";
158
- function K({
159
- messages: e,
160
- children: n
188
+ W.displayName = "Chat";
189
+ function X({
190
+ messages: o,
191
+ children: r
161
192
  }) {
162
193
  const {
163
194
  containerRef: i,
164
195
  scrollToBottom: u,
165
- handleScroll: s,
196
+ handleScroll: a,
166
197
  shouldAutoScroll: c,
167
- handleTouchStart: d
168
- } = D([e]);
169
- return /* @__PURE__ */ C(
198
+ handleTouchStart: f
199
+ } = O([o]);
200
+ return /* @__PURE__ */ N(
170
201
  "div",
171
202
  {
172
203
  className: "relative flex-1 overflow-y-auto pb-4",
173
204
  ref: i,
174
- onScroll: s,
175
- onTouchStart: d,
205
+ onScroll: a,
206
+ onTouchStart: f,
176
207
  children: [
177
- /* @__PURE__ */ t("div", { className: "max-w-full", children: n }),
208
+ /* @__PURE__ */ t("div", { className: "max-w-full", children: r }),
178
209
  !c && /* @__PURE__ */ t("div", { className: "pointer-events-none absolute right-0 bottom-0 left-0 flex items-end justify-end", children: /* @__PURE__ */ t("div", { className: "sticky bottom-0 left-0 flex w-full justify-end", children: /* @__PURE__ */ t(
179
- x,
210
+ w,
180
211
  {
181
212
  onClick: u,
182
213
  className: "animate-in fade-in-0 slide-in-from-bottom-1 pointer-events-auto h-8 w-8 rounded-full ease-in-out",
183
214
  size: "icon",
184
215
  variant: "ghost",
185
- children: /* @__PURE__ */ t(H, { className: "h-4 w-4" })
216
+ children: /* @__PURE__ */ t(V, { className: "h-4 w-4" })
186
217
  }
187
218
  ) }) })
188
219
  ]
189
220
  }
190
221
  );
191
222
  }
192
- const S = g(({ className: e, ...n }, i) => /* @__PURE__ */ t(
223
+ const z = g(({ className: o, ...r }, i) => /* @__PURE__ */ t(
193
224
  "div",
194
225
  {
195
226
  ref: i,
196
- className: B("flex h-full max-h-full w-full flex-col", e),
197
- ...n
227
+ className: M("flex h-full max-h-full w-full flex-col", o),
228
+ ...r
198
229
  }
199
230
  ));
200
- S.displayName = "ChatContainer";
201
- const I = g(
202
- ({ children: e, handleSubmit: n, className: i }, u) => {
203
- const [s, c] = z(null);
204
- return /* @__PURE__ */ t("form", { ref: u, onSubmit: (f) => {
205
- if (!s) {
206
- n(f);
231
+ z.displayName = "ChatContainer";
232
+ const A = g(
233
+ ({ children: o, handleSubmit: r, className: i }, u) => {
234
+ const [a, c] = E(null);
235
+ return /* @__PURE__ */ t("form", { ref: u, onSubmit: (m) => {
236
+ if (!a) {
237
+ r(m);
207
238
  return;
208
239
  }
209
- const w = Q(s);
210
- n(f, { experimental_attachments: w }), c(null);
211
- }, className: i, children: e({ files: s, setFiles: c }) });
240
+ const v = Y(a);
241
+ r(m, { experimental_attachments: v }), c(null);
242
+ }, className: i, children: o({ files: a, setFiles: c }) });
212
243
  }
213
244
  );
214
- I.displayName = "ChatForm";
215
- function Q(e) {
245
+ A.displayName = "ChatForm";
246
+ function Y(o) {
216
247
  if (typeof window > "u")
217
248
  return {};
218
- const n = new DataTransfer();
219
- for (const i of Array.from(e))
220
- n.items.add(i);
221
- return n.files;
249
+ const r = new DataTransfer();
250
+ for (const i of Array.from(o))
251
+ r.items.add(i);
252
+ return r.files;
222
253
  }
223
254
  export {
224
- J as Chat,
225
- S as ChatContainer,
226
- I as ChatForm,
227
- K as ChatMessages
255
+ W as Chat,
256
+ z as ChatContainer,
257
+ A as ChatForm,
258
+ X as ChatMessages
228
259
  };
@@ -127,7 +127,7 @@ function ie({
127
127
  onPaste: K,
128
128
  onKeyDown: U,
129
129
  className: C(
130
- "border-d-input bg-d-background ring-offset-d-background placeholder:text-d-secondary-foreground focus-visible:border-d-primary z-10 w-full grow resize-none rounded-xl border p-3 pr-24 text-sm transition-[border] focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
130
+ "border-d-input bg-d-input ring-offset-d-background placeholder:text-d-muted-foreground focus-visible:border-d-primary z-10 w-full grow resize-none rounded-xl border p-3 pr-24 text-sm transition-[border] focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
131
131
  z && "pb-16",
132
132
  n
133
133
  ),
@@ -1,29 +1,33 @@
1
1
  "use client";
2
- import { jsxs as c, jsx as o } from "react/jsx-runtime";
3
- import { ChatMessage as f } from "./chat-message.js";
4
- import { TypingIndicator as p } from "./typing-indicator.js";
5
- function d({
6
- messages: r,
2
+ import { jsxs as l, jsx as r } from "react/jsx-runtime";
3
+ import { ChatMessage as s } from "./chat-message.js";
4
+ import { TypingIndicator as m } from "./typing-indicator.js";
5
+ function x({
6
+ messages: n,
7
7
  showTimeStamps: e = !0,
8
- isTyping: n = !1,
9
- messageOptions: t
8
+ isTyping: a = !1,
9
+ messageOptions: i,
10
+ onEdit: t,
11
+ onMessageSave: c
10
12
  }) {
11
- return /* @__PURE__ */ c("div", { className: "space-y-4 overflow-visible", children: [
12
- r.map((i, a) => {
13
- const s = typeof t == "function" ? t(i) : t;
14
- return /* @__PURE__ */ o(
15
- f,
13
+ return /* @__PURE__ */ l("div", { className: "space-y-4 overflow-visible", children: [
14
+ n.map((o, f) => {
15
+ const p = typeof i == "function" ? i(o) : i;
16
+ return /* @__PURE__ */ r(
17
+ s,
16
18
  {
17
19
  showTimeStamp: e,
18
- ...i,
19
- ...s
20
+ ...o,
21
+ ...p,
22
+ onEdit: t ? (d) => t(o.id, d) : void 0,
23
+ onMessageSave: c
20
24
  },
21
- a
25
+ f
22
26
  );
23
27
  }),
24
- n && /* @__PURE__ */ o(p, {})
28
+ a && /* @__PURE__ */ r(m, {})
25
29
  ] });
26
30
  }
27
31
  export {
28
- d as MessageList
32
+ x as MessageList
29
33
  };
package/dist/index.d.ts CHANGED
@@ -436,7 +436,7 @@ export declare function ChartTooltipContent({ active, payload, className, indica
436
436
  labelKey?: string;
437
437
  } & React_2.HTMLAttributes<HTMLDivElement>): JSX.Element | null;
438
438
 
439
- export declare function Chat({ messages, handleSubmit, input, handleInputChange, stop, isGenerating, append, suggestions, className, onRateResponse, setMessages, transcribeAudio, }: ChatProps): JSX.Element;
439
+ export declare function Chat({ messages, handleSubmit, input, handleInputChange, stop, isGenerating, append, suggestions, className, onRateResponse, setMessages, transcribeAudio, allowAttachments, onEdit, onMessageSave, }: ChatProps): JSX.Element;
440
440
 
441
441
  export declare namespace Chat {
442
442
  var displayName: string;
@@ -471,6 +471,8 @@ export declare interface ChatMessageProps extends Message {
471
471
  showTimeStamp?: boolean;
472
472
  animation?: Animation_2;
473
473
  actions?: default_3.ReactNode;
474
+ onEdit?: (newContent: string) => void;
475
+ onMessageSave?: (messageId: string, content: string) => void;
474
476
  }
475
477
 
476
478
  export declare function ChatMessages({ messages, children, }: React.PropsWithChildren<{
@@ -494,6 +496,9 @@ declare interface ChatPropsBase {
494
496
  onRateResponse?: (messageId: string, rating: "thumbs-up" | "thumbs-down") => void;
495
497
  setMessages?: (messages: any[]) => void;
496
498
  transcribeAudio?: (blob: Blob) => Promise<string>;
499
+ allowAttachments?: boolean;
500
+ onEdit?: (messageId: string, newContent: string) => void;
501
+ onMessageSave?: (messageId: string, content: string) => void;
497
502
  }
498
503
 
499
504
  declare interface ChatPropsWithoutSuggestions extends ChatPropsBase {
@@ -1173,13 +1178,15 @@ declare interface MessageInputWithoutAttachmentProps extends MessageInputBasePro
1173
1178
  allowAttachments?: false;
1174
1179
  }
1175
1180
 
1176
- export declare function MessageList({ messages, showTimeStamps, isTyping, messageOptions, }: MessageListProps): JSX.Element;
1181
+ export declare function MessageList({ messages, showTimeStamps, isTyping, messageOptions, onEdit, onMessageSave, }: MessageListProps): JSX.Element;
1177
1182
 
1178
1183
  declare interface MessageListProps {
1179
1184
  messages: Message[];
1180
1185
  showTimeStamps?: boolean;
1181
1186
  isTyping?: boolean;
1182
1187
  messageOptions?: AdditionalMessageOptions | ((message: Message) => AdditionalMessageOptions);
1188
+ onEdit?: (messageId: string, newContent: string) => void;
1189
+ onMessageSave?: (messageId: string, content: string) => void;
1183
1190
  }
1184
1191
 
1185
1192
  declare type MessagePart = TextPart | ReasoningPart | ToolInvocationPart | SourcePart;