@superinterface/react 1.0.5 → 1.1.1

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.
Files changed (43) hide show
  1. package/dist/index-LPUEY9WE.d.ts +5 -0
  2. package/dist/index.d.ts +135 -130
  3. package/dist/index.js +940 -750
  4. package/dist/index.js.map +1 -1
  5. package/dist/mutationFns.d.ts +9 -4
  6. package/dist/mutationFns.js +21 -19
  7. package/dist/mutationFns.js.map +1 -1
  8. package/dist/queryFns.d.ts +6 -3
  9. package/dist/queryFns.js +29 -24
  10. package/dist/queryFns.js.map +1 -1
  11. package/dist/utils.d.ts +24 -0
  12. package/dist/{lib/index.js → utils.js} +48 -5
  13. package/dist/utils.js.map +1 -0
  14. package/package.json +2 -3
  15. package/dist/chunk-DP5XKPRM.mjs +0 -8
  16. package/dist/chunk-DP5XKPRM.mjs.map +0 -1
  17. package/dist/chunk-E4KDALPU.mjs +0 -11
  18. package/dist/chunk-E4KDALPU.mjs.map +0 -1
  19. package/dist/chunk-QPW4QQ26.mjs +0 -49
  20. package/dist/chunk-QPW4QQ26.mjs.map +0 -1
  21. package/dist/index.d.mts +0 -561
  22. package/dist/index.mjs +0 -1899
  23. package/dist/index.mjs.map +0 -1
  24. package/dist/lib/index.d.mts +0 -3
  25. package/dist/lib/index.d.ts +0 -3
  26. package/dist/lib/index.js.map +0 -1
  27. package/dist/lib/index.mjs +0 -7
  28. package/dist/lib/index.mjs.map +0 -1
  29. package/dist/mutationFns.d.mts +0 -31
  30. package/dist/mutationFns.mjs +0 -84
  31. package/dist/mutationFns.mjs.map +0 -1
  32. package/dist/queryFns.d.mts +0 -15
  33. package/dist/queryFns.mjs +0 -126
  34. package/dist/queryFns.mjs.map +0 -1
  35. package/dist/queryKeys.d.mts +0 -5
  36. package/dist/queryKeys.d.ts +0 -5
  37. package/dist/queryKeys.js +0 -38
  38. package/dist/queryKeys.js.map +0 -1
  39. package/dist/queryKeys.mjs +0 -9
  40. package/dist/queryKeys.mjs.map +0 -1
  41. package/dist/types/index.d.mts +0 -33
  42. package/dist/types/index.mjs +0 -1
  43. package/dist/types/index.mjs.map +0 -1
package/dist/index.mjs DELETED
@@ -1,1899 +0,0 @@
1
- import {
2
- queryKey,
3
- queryKey2
4
- } from "./chunk-E4KDALPU.mjs";
5
- import {
6
- optimisticId
7
- } from "./chunk-DP5XKPRM.mjs";
8
-
9
- // src/components/messages/Messages/index.tsx
10
- import {
11
- Flex as Flex12
12
- } from "@radix-ui/themes";
13
-
14
- // src/hooks/misc/useInfiniteScroll/index.tsx
15
- import { useRef as useRef2 } from "react";
16
- import { useInView } from "react-intersection-observer";
17
-
18
- // src/hooks/misc/useThrottledEffect/index.tsx
19
- import _ from "lodash";
20
- import { useRef, useEffect, useCallback } from "react";
21
- var useThrottledEffect = (cb, delay, additionalDeps) => {
22
- const cbRef = useRef(cb);
23
- const throttledCb = useCallback(
24
- _.throttle((...args) => cbRef.current(...args), delay, {
25
- leading: true,
26
- trailing: true
27
- }),
28
- [delay]
29
- );
30
- useEffect(() => {
31
- cbRef.current = cb;
32
- });
33
- useEffect(throttledCb, [throttledCb, ...additionalDeps]);
34
- };
35
-
36
- // src/hooks/misc/useInfiniteScroll/index.tsx
37
- var useInfiniteScroll = ({
38
- isFetchingNextPage,
39
- hasNextPage,
40
- fetchNextPage
41
- }) => {
42
- const containerRef = useRef2(null);
43
- const { ref: loaderRef, inView } = useInView({
44
- root: containerRef.current,
45
- rootMargin: "0px",
46
- threshold: 0.1
47
- });
48
- useThrottledEffect(
49
- () => {
50
- if (isFetchingNextPage)
51
- return;
52
- if (!inView)
53
- return;
54
- if (!hasNextPage)
55
- return;
56
- console.log("Fetching next page");
57
- fetchNextPage();
58
- },
59
- 500,
60
- [inView, isFetchingNextPage, hasNextPage, fetchNextPage]
61
- );
62
- return {
63
- containerRef,
64
- loaderRef,
65
- inView
66
- };
67
- };
68
-
69
- // src/components/skeletons/MessagesSkeleton/index.tsx
70
- import { forwardRef as forwardRef2 } from "react";
71
- import {
72
- Flex as Flex4,
73
- Avatar,
74
- Box
75
- } from "@radix-ui/themes";
76
-
77
- // src/components/skeletons/Skeleton/index.tsx
78
- import { Flex } from "@radix-ui/themes";
79
- import { jsx } from "react/jsx-runtime";
80
- var Skeleton = ({
81
- className,
82
- ...rest
83
- }) => (
84
- // @ts-ignore-next-line
85
- /* @__PURE__ */ jsx(
86
- Flex,
87
- {
88
- className: `animate-pulse rounded-3 bg-gray-5 ${className}`,
89
- ...rest
90
- }
91
- )
92
- );
93
-
94
- // src/components/messageGroups/MessagesGroupBase/index.tsx
95
- import { forwardRef } from "react";
96
- import {
97
- Flex as Flex2,
98
- Container
99
- } from "@radix-ui/themes";
100
- import { jsx as jsx2 } from "react/jsx-runtime";
101
- var MessagesGroupBase = forwardRef(function MessagesGroupBase2({
102
- children
103
- }, ref) {
104
- return /* @__PURE__ */ jsx2(
105
- Container,
106
- {
107
- ref,
108
- size: "2",
109
- grow: "0",
110
- children: /* @__PURE__ */ jsx2(
111
- Flex2,
112
- {
113
- shrink: "0",
114
- gap: "3",
115
- children
116
- }
117
- )
118
- }
119
- );
120
- });
121
-
122
- // src/components/messageGroups/MessagesGroupBase/Name.tsx
123
- import {
124
- Flex as Flex3,
125
- Text
126
- } from "@radix-ui/themes";
127
- import { jsx as jsx3 } from "react/jsx-runtime";
128
- var Name = ({
129
- children
130
- }) => /* @__PURE__ */ jsx3(
131
- Flex3,
132
- {
133
- height: "5",
134
- align: "center",
135
- children: /* @__PURE__ */ jsx3(
136
- Text,
137
- {
138
- size: "2",
139
- weight: "bold",
140
- children
141
- }
142
- )
143
- }
144
- );
145
-
146
- // src/components/skeletons/MessagesSkeleton/index.tsx
147
- import { jsx as jsx4, jsxs } from "react/jsx-runtime";
148
- var MessagesSkeleton = forwardRef2(function MessagesSkeleton2(_props, ref) {
149
- return /* @__PURE__ */ jsxs(
150
- MessagesGroupBase,
151
- {
152
- ref,
153
- children: [
154
- /* @__PURE__ */ jsx4(
155
- Avatar,
156
- {
157
- fallback: /* @__PURE__ */ jsx4(Flex4, {}),
158
- size: "1",
159
- className: "animate-pulse"
160
- }
161
- ),
162
- /* @__PURE__ */ jsxs(
163
- Box,
164
- {
165
- pb: "3",
166
- children: [
167
- /* @__PURE__ */ jsx4(Name, { children: /* @__PURE__ */ jsx4(
168
- Skeleton,
169
- {
170
- height: "1",
171
- className: "w-[128px]"
172
- }
173
- ) }),
174
- /* @__PURE__ */ jsx4(
175
- Skeleton,
176
- {
177
- height: "2",
178
- className: "w-[256px]"
179
- }
180
- ),
181
- /* @__PURE__ */ jsx4(
182
- Skeleton,
183
- {
184
- height: "2",
185
- className: "w-[256px] mt-2"
186
- }
187
- ),
188
- /* @__PURE__ */ jsx4(
189
- Skeleton,
190
- {
191
- height: "2",
192
- className: "w-[256px] mt-2"
193
- }
194
- )
195
- ]
196
- }
197
- )
198
- ]
199
- }
200
- );
201
- });
202
-
203
- // src/hooks/messages/useMessages/index.tsx
204
- import { useMemo } from "react";
205
- import {
206
- useInfiniteQuery
207
- } from "@tanstack/react-query";
208
-
209
- // src/hooks/messages/useMessages/lib/queryOptions/index.ts
210
- var queryOptions = {
211
- queryKey: queryKey(),
212
- // queryFn: ({
213
- // pageParam,
214
- // }: { pageParam?: string }) => (
215
- // queryFn({
216
- // ...(pageParam ? { cursor: pageParam } : {}),
217
- // })
218
- // ),
219
- initialPageParam: void 0,
220
- getNextPageParam: (lastPage) => {
221
- if (!lastPage.hasNextPage)
222
- return null;
223
- return lastPage.lastId;
224
- }
225
- };
226
-
227
- // src/hooks/messages/useMessages/index.tsx
228
- var messages = ({
229
- props
230
- }) => {
231
- if (!props.data)
232
- return [];
233
- return props.data.pages.reduce((acc, page) => acc.concat(page.data), []);
234
- };
235
- var useMessages = ({
236
- messagesQueryOptions
237
- }) => {
238
- const props = useInfiniteQuery({
239
- ...queryOptions,
240
- ...messagesQueryOptions
241
- });
242
- return useMemo(() => ({
243
- ...props,
244
- messages: messages({ props })
245
- }), [props]);
246
- };
247
-
248
- // src/hooks/runs/useManageRuns/index.tsx
249
- import { useEffect as useEffect2 } from "react";
250
-
251
- // src/hooks/messages/useLatestMessage/index.ts
252
- import { useMemo as useMemo2 } from "react";
253
- var useLatestMessage = (args) => {
254
- const props = useMessages(args);
255
- return useMemo2(() => ({
256
- ...props,
257
- latestMessage: props.messages[0] || null
258
- }), [props]);
259
- };
260
-
261
- // src/hooks/runs/useLatestRun/index.ts
262
- import { useMemo as useMemo4 } from "react";
263
-
264
- // src/hooks/runs/useRuns/index.tsx
265
- import { useMemo as useMemo3 } from "react";
266
- import {
267
- useInfiniteQuery as useInfiniteQuery2
268
- } from "@tanstack/react-query";
269
-
270
- // src/hooks/runs/useRuns/lib/queryOptions/index.ts
271
- var queryOptions2 = {
272
- queryKey: queryKey2(),
273
- // queryFn: ({
274
- // pageParam,
275
- // }: { pageParam?: string }) => (
276
- // queryFn({
277
- // assistantConversationId,
278
- // })
279
- // ),
280
- initialPageParam: void 0,
281
- getNextPageParam: (lastPage) => {
282
- if (!lastPage.hasNextPage)
283
- return null;
284
- return lastPage.lastId;
285
- },
286
- limit: 10
287
- };
288
-
289
- // src/hooks/runs/useRuns/lib/getRuns.ts
290
- var getRuns = ({
291
- data: data2
292
- }) => {
293
- if (!data2)
294
- return [];
295
- return data2.pages.reduce((acc, page) => acc.concat(page.data), []);
296
- };
297
-
298
- // src/hooks/runs/useRuns/index.tsx
299
- var useRuns = ({
300
- runsQueryOptions
301
- }) => {
302
- const props = useInfiniteQuery2({
303
- ...queryOptions2,
304
- ...runsQueryOptions
305
- });
306
- return useMemo3(() => ({
307
- ...props,
308
- runs: getRuns({ data: props.data })
309
- }), [props]);
310
- };
311
-
312
- // src/hooks/runs/useLatestRun/index.ts
313
- var useLatestRun = (args) => {
314
- const props = useRuns(args);
315
- return useMemo4(() => ({
316
- ...props,
317
- latestRun: props.runs[0]
318
- }), [props]);
319
- };
320
-
321
- // src/hooks/runs/useCreateRun/index.ts
322
- import {
323
- useMutation,
324
- useQueryClient
325
- } from "@tanstack/react-query";
326
-
327
- // src/hooks/runs/useCreateRun/lib/mutationOptions/onSuccess.ts
328
- var onSuccess = ({
329
- queryClient
330
- }) => (response) => queryClient.setQueryData(
331
- queryKey2(),
332
- (prevData) => {
333
- if (!prevData) {
334
- return {
335
- pageParams: [],
336
- pages: [
337
- {
338
- data: [response.run],
339
- hasNextPage: false,
340
- lastId: response.run.id
341
- }
342
- ]
343
- };
344
- }
345
- const [latestPage, ...pagesRest] = prevData.pages;
346
- return {
347
- ...prevData,
348
- pages: [
349
- {
350
- ...latestPage,
351
- data: [
352
- response.run,
353
- ...latestPage.data
354
- ]
355
- },
356
- ...pagesRest
357
- ]
358
- };
359
- }
360
- );
361
-
362
- // src/hooks/runs/useCreateRun/lib/mutationOptions/onSettled.ts
363
- var onSettled = ({
364
- queryClient
365
- }) => (response) => {
366
- if (!response) {
367
- throw new Error("useCreateRun onSettled: response is undefined");
368
- }
369
- queryClient.invalidateQueries({
370
- queryKey: queryKey()
371
- });
372
- queryClient.invalidateQueries({
373
- queryKey: queryKey2()
374
- });
375
- };
376
-
377
- // src/hooks/runs/useCreateRun/lib/mutationOptions/index.ts
378
- var mutationOptions = ({
379
- queryClient
380
- }) => ({
381
- // mutationFn,
382
- onSuccess: onSuccess({ queryClient }),
383
- onSettled: onSettled({ queryClient })
384
- });
385
-
386
- // src/hooks/runs/useCreateRun/index.ts
387
- var useCreateRun = ({
388
- createRunMutationOptions
389
- }) => {
390
- const queryClient = useQueryClient();
391
- const mutationProps = useMutation({
392
- ...mutationOptions({
393
- queryClient
394
- }),
395
- ...createRunMutationOptions
396
- });
397
- return {
398
- ...mutationProps,
399
- createRun: mutationProps.mutate
400
- };
401
- };
402
-
403
- // src/lib/optimistic/isOptimistic.ts
404
- import _2 from "lodash";
405
- var isOptimistic = ({
406
- id
407
- }) => _2.startsWith(id, "-");
408
-
409
- // src/hooks/runs/useManageRuns/index.tsx
410
- var useManageRuns = ({
411
- messagesQueryOptions,
412
- runsQueryOptions,
413
- createRunMutationOptions
414
- }) => {
415
- const latestRunProps = useLatestRun({
416
- runsQueryOptions
417
- });
418
- const latestMessageProps = useLatestMessage({
419
- messagesQueryOptions
420
- });
421
- const createRunProps = useCreateRun({
422
- createRunMutationOptions
423
- });
424
- useEffect2(() => {
425
- if (createRunProps.isPending)
426
- return;
427
- if (latestRunProps.isFetching)
428
- return;
429
- if (latestMessageProps.isFetching)
430
- return;
431
- if (!latestMessageProps.latestMessage)
432
- return;
433
- if (latestMessageProps.latestMessage.role !== "user")
434
- return;
435
- if (isOptimistic({ id: latestMessageProps.latestMessage.id }))
436
- return;
437
- if (!latestRunProps.latestRun || latestMessageProps.latestMessage.created_at > latestRunProps.latestRun.created_at) {
438
- createRunProps.createRun();
439
- }
440
- }, [
441
- createRunProps,
442
- latestRunProps,
443
- latestMessageProps
444
- ]);
445
- return null;
446
- };
447
-
448
- // src/hooks/runs/usePolling/index.tsx
449
- import {
450
- useQueryClient as useQueryClient2
451
- } from "@tanstack/react-query";
452
-
453
- // src/hooks/runs/useIsRunActive/index.tsx
454
- import { useMemo as useMemo5 } from "react";
455
- import { useIsMutating } from "@tanstack/react-query";
456
-
457
- // src/lib/runs/isRunEditingMessage/index.ts
458
- import _3 from "lodash";
459
- var isRunEditingMessage = ({
460
- message
461
- }) => {
462
- if (!message)
463
- return false;
464
- if (message.role === "user")
465
- return false;
466
- if (!message.run_id)
467
- return false;
468
- const hasContent = _3.some(message.content, (content) => {
469
- var _a;
470
- return content.type !== "text" || content.type === "text" && ((_a = content.text) == null ? void 0 : _a.value) !== "";
471
- });
472
- return !hasContent;
473
- };
474
-
475
- // src/hooks/runs/useIsRunActive/index.tsx
476
- var statuses = [
477
- "queued",
478
- // 'completed',
479
- "in_progress",
480
- "cancelling",
481
- "requires_action"
482
- ];
483
- var isRunActive = ({
484
- latestRunProps,
485
- latestMessageProps,
486
- isMutating
487
- }) => {
488
- var _a, _b;
489
- if ((_b = (_a = latestMessageProps.latestMessage) == null ? void 0 : _a.metadata) == null ? void 0 : _b.isBlocking)
490
- return false;
491
- if (isMutating > 0)
492
- return true;
493
- if (!latestRunProps.latestRun)
494
- return false;
495
- if (statuses.includes(latestRunProps.latestRun.status))
496
- return true;
497
- return isRunEditingMessage({ message: latestMessageProps.latestMessage });
498
- };
499
- var useIsRunActive = ({
500
- messagesQueryOptions,
501
- runsQueryOptions
502
- }) => {
503
- const latestRunProps = useLatestRun({
504
- runsQueryOptions
505
- });
506
- const latestMessageProps = useLatestMessage({
507
- messagesQueryOptions
508
- });
509
- const isMutating = useIsMutating();
510
- return useMemo5(() => ({
511
- ...latestRunProps,
512
- isRunActive: isRunActive({
513
- latestRunProps,
514
- latestMessageProps,
515
- isMutating
516
- })
517
- }), [latestRunProps, latestMessageProps, isMutating]);
518
- };
519
-
520
- // src/hooks/runs/usePolling/index.tsx
521
- import { useInterval } from "react-use";
522
-
523
- // src/hooks/runs/usePolling/lib/refetch.ts
524
- var refetch = async ({
525
- queryClient,
526
- latestRun
527
- }) => {
528
- await queryClient.invalidateQueries({
529
- queryKey: queryKey()
530
- });
531
- await queryClient.invalidateQueries({
532
- queryKey: queryKey2()
533
- });
534
- };
535
-
536
- // src/hooks/runs/usePolling/index.tsx
537
- var usePolling = ({
538
- messagesQueryOptions,
539
- runsQueryOptions
540
- }) => {
541
- const queryClient = useQueryClient2();
542
- const isRunActiveProps = useIsRunActive({
543
- messagesQueryOptions,
544
- runsQueryOptions
545
- });
546
- useInterval(
547
- () => {
548
- refetch({
549
- queryClient,
550
- latestRun: isRunActiveProps.latestRun
551
- });
552
- console.log("poll refetched");
553
- },
554
- isRunActiveProps.isRunActive ? 3e3 : null
555
- );
556
- return null;
557
- };
558
-
559
- // src/hooks/actions/useManageActions/index.tsx
560
- import { useEffect as useEffect3 } from "react";
561
-
562
- // src/hooks/actions/useHandleAction/index.tsx
563
- import {
564
- useMutation as useMutation2,
565
- useQueryClient as useQueryClient3
566
- } from "@tanstack/react-query";
567
-
568
- // src/hooks/actions/useHandleAction/lib/mutationOptions/onSettled.ts
569
- var onSettled2 = ({
570
- queryClient
571
- }) => (response) => {
572
- if (!response) {
573
- throw new Error("useHandleAction onSettled: response is undefined");
574
- }
575
- queryClient.invalidateQueries({
576
- queryKey: queryKey()
577
- });
578
- queryClient.invalidateQueries({
579
- queryKey: queryKey2()
580
- });
581
- };
582
-
583
- // src/hooks/actions/useHandleAction/lib/mutationOptions/index.ts
584
- var mutationOptions2 = ({
585
- queryClient
586
- }) => ({
587
- // mutationFn,
588
- onSettled: onSettled2({ queryClient })
589
- });
590
-
591
- // src/hooks/actions/useHandleAction/index.tsx
592
- var useHandleAction = ({
593
- handleActionMutationOptions
594
- }) => {
595
- const queryClient = useQueryClient3();
596
- const mutationProps = useMutation2({
597
- ...mutationOptions2({
598
- queryClient
599
- }),
600
- ...handleActionMutationOptions
601
- });
602
- return {
603
- ...mutationProps,
604
- handleAction: mutationProps.mutate
605
- };
606
- };
607
-
608
- // src/hooks/actions/useManageActions/index.tsx
609
- var useManageActions = ({
610
- runsQueryOptions,
611
- handleActionMutationOptions
612
- }) => {
613
- const latestRunProps = useLatestRun({
614
- runsQueryOptions
615
- });
616
- const handleActionProps = useHandleAction({
617
- handleActionMutationOptions
618
- });
619
- useEffect3(() => {
620
- if (handleActionProps.isPending)
621
- return;
622
- if (latestRunProps.isFetching)
623
- return;
624
- if (!latestRunProps.latestRun)
625
- return;
626
- if (latestRunProps.latestRun.status !== "requires_action")
627
- return;
628
- console.log("requires action", {
629
- latestRunProps
630
- });
631
- handleActionProps.handleAction({ latestRun: latestRunProps.latestRun });
632
- }, [handleActionProps, latestRunProps]);
633
- return null;
634
- };
635
-
636
- // src/hooks/threads/useThreadLifecycles/index.tsx
637
- var useThreadLifecycles = ({
638
- messagesQueryOptions,
639
- runsQueryOptions,
640
- createRunMutationOptions,
641
- handleActionMutationOptions
642
- }) => {
643
- useManageRuns({
644
- messagesQueryOptions,
645
- runsQueryOptions,
646
- createRunMutationOptions
647
- });
648
- useManageActions({
649
- runsQueryOptions,
650
- handleActionMutationOptions
651
- });
652
- usePolling({
653
- messagesQueryOptions,
654
- runsQueryOptions
655
- });
656
- return null;
657
- };
658
-
659
- // src/hooks/messageGroups/useMessageGroups/index.ts
660
- import { useMemo as useMemo6 } from "react";
661
-
662
- // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/index.ts
663
- import _4 from "lodash";
664
- import { last } from "radash";
665
-
666
- // src/lib/messages/order.ts
667
- import { sort } from "radash";
668
- var order = ({ messages: messages2 }) => sort(messages2, (m) => m.created_at, true);
669
-
670
- // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/newGroup/newGroupItem.ts
671
- var newGroupItem = ({ message }) => ({
672
- id: message.id,
673
- role: message.role,
674
- createdAt: message.created_at,
675
- messages: [message]
676
- });
677
-
678
- // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/newGroup/index.ts
679
- var newGroup = ({ groups, message }) => [
680
- ...groups,
681
- newGroupItem({
682
- message
683
- })
684
- ];
685
-
686
- // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/index.ts
687
- var messageGroups = ({
688
- messages: messages2
689
- }) => _4.reduce(
690
- order({ messages: messages2 }),
691
- (groups, message) => {
692
- const group = last(groups);
693
- if (!group)
694
- return newGroup({ groups, message });
695
- if (group.role !== message.role) {
696
- return newGroup({
697
- groups,
698
- message
699
- });
700
- }
701
- return [
702
- ..._4.dropRight(groups),
703
- {
704
- ...group,
705
- messages: [...group.messages, message]
706
- }
707
- ];
708
- },
709
- []
710
- );
711
-
712
- // src/hooks/messageGroups/useMessageGroups/index.ts
713
- var useMessageGroups = ({
714
- messages: messages2
715
- }) => useMemo6(
716
- () => ({
717
- messageGroups: messageGroups({ messages: messages2 })
718
- }),
719
- [messages2]
720
- );
721
-
722
- // src/components/messages/Messages/Content/MessageGroup/index.tsx
723
- import { useContext as useContext3 } from "react";
724
- import {
725
- Box as Box8,
726
- Avatar as Avatar3
727
- } from "@radix-ui/themes";
728
- import {
729
- PersonIcon
730
- } from "@radix-ui/react-icons";
731
-
732
- // src/components/messageGroups/MessagesGroupBase/AssistantAvatar.tsx
733
- import { useContext } from "react";
734
- import {
735
- Flex as Flex5
736
- } from "@radix-ui/themes";
737
-
738
- // src/contexts/avatars/AssistantAvatarContext/index.tsx
739
- import { createContext } from "react";
740
- import {
741
- Avatar as Avatar2
742
- } from "@radix-ui/themes";
743
- import {
744
- LightningBoltIcon
745
- } from "@radix-ui/react-icons";
746
- import { jsx as jsx5 } from "react/jsx-runtime";
747
- var AssistantAvatarContext = createContext(
748
- /* @__PURE__ */ jsx5(
749
- Avatar2,
750
- {
751
- fallback: /* @__PURE__ */ jsx5(LightningBoltIcon, {}),
752
- size: "1"
753
- }
754
- )
755
- );
756
-
757
- // src/components/messageGroups/MessagesGroupBase/AssistantAvatar.tsx
758
- import { jsx as jsx6 } from "react/jsx-runtime";
759
- var AssistantAvatar = () => {
760
- const AssistantAvatarContextValue = useContext(AssistantAvatarContext);
761
- return /* @__PURE__ */ jsx6(
762
- Flex5,
763
- {
764
- shrink: "0",
765
- className: "rounded-3 overflow-hidden h-[24px] w-[24px]",
766
- children: AssistantAvatarContextValue
767
- }
768
- );
769
- };
770
-
771
- // src/contexts/assistants/AssistantNameContext/index.tsx
772
- import { createContext as createContext2 } from "react";
773
- var AssistantNameContext = createContext2("Assistant");
774
-
775
- // src/components/messages/Messages/Content/MessageGroup/Content/index.tsx
776
- import { Flex as Flex11 } from "@radix-ui/themes";
777
-
778
- // src/components/messages/Message/index.tsx
779
- import { useMemo as useMemo8 } from "react";
780
- import {
781
- Box as Box7
782
- } from "@radix-ui/themes";
783
-
784
- // src/components/runSteps/RunSteps/index.tsx
785
- import { Flex as Flex10 } from "@radix-ui/themes";
786
-
787
- // src/components/runSteps/RunStep/ToolCalls/index.tsx
788
- import {
789
- Flex as Flex9
790
- } from "@radix-ui/themes";
791
-
792
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx
793
- import {
794
- Flex as Flex8
795
- } from "@radix-ui/themes";
796
-
797
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Availabilities/index.tsx
798
- import {
799
- PopoverRoot,
800
- PopoverContent
801
- } from "@radix-ui/themes";
802
-
803
- // src/components/toolCalls/ToolCallBase/index.tsx
804
- import { forwardRef as forwardRef3 } from "react";
805
- import {
806
- Flex as Flex6,
807
- Button,
808
- PopoverTrigger
809
- } from "@radix-ui/themes";
810
- import { jsx as jsx7 } from "react/jsx-runtime";
811
- var ToolCallBase = forwardRef3(function ToolCallBase2({
812
- children
813
- }, ref) {
814
- return /* @__PURE__ */ jsx7(
815
- Flex6,
816
- {
817
- py: "1",
818
- ml: "-2",
819
- children: /* @__PURE__ */ jsx7(PopoverTrigger, { children: /* @__PURE__ */ jsx7(
820
- Button,
821
- {
822
- size: "1",
823
- color: "gold",
824
- variant: "outline",
825
- style: {
826
- boxShadow: "none"
827
- },
828
- children
829
- }
830
- ) })
831
- }
832
- );
833
- });
834
-
835
- // src/components/toolCalls/ToolCallBase/ToolCallTitle.tsx
836
- import {
837
- Text as Text2
838
- } from "@radix-ui/themes";
839
- import { jsx as jsx8 } from "react/jsx-runtime";
840
- var ToolCallTitle = ({
841
- children
842
- }) => /* @__PURE__ */ jsx8(
843
- Text2,
844
- {
845
- weight: "regular",
846
- children
847
- }
848
- );
849
-
850
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Icon.tsx
851
- import {
852
- CircleIcon,
853
- CircleBackslashIcon,
854
- CheckCircledIcon
855
- } from "@radix-ui/react-icons";
856
- import { jsx as jsx9 } from "react/jsx-runtime";
857
- var Icon = ({
858
- runStep
859
- }) => {
860
- if (runStep.completed_at) {
861
- return /* @__PURE__ */ jsx9(CheckCircledIcon, {});
862
- } else if (runStep.cancelled_at) {
863
- return /* @__PURE__ */ jsx9(CircleBackslashIcon, {});
864
- } else {
865
- return /* @__PURE__ */ jsx9(CircleIcon, {});
866
- }
867
- };
868
-
869
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Content/index.tsx
870
- import { useMemo as useMemo7 } from "react";
871
- import { Code, Box as Box2 } from "@radix-ui/themes";
872
- import { jsx as jsx10, jsxs as jsxs2 } from "react/jsx-runtime";
873
- var Content = ({
874
- fn
875
- }) => {
876
- const args = useMemo7(() => {
877
- let result = null;
878
- try {
879
- result = JSON.parse(fn.arguments);
880
- } catch (error) {
881
- console.error(error);
882
- }
883
- return result;
884
- }, [fn]);
885
- const output = useMemo7(() => {
886
- if (!fn.output) {
887
- return null;
888
- }
889
- let result = null;
890
- try {
891
- result = JSON.parse(fn.output);
892
- } catch (error) {
893
- console.error(error);
894
- }
895
- return result;
896
- }, [fn]);
897
- if (!args) {
898
- return null;
899
- }
900
- return /* @__PURE__ */ jsxs2(
901
- Code,
902
- {
903
- variant: "ghost",
904
- color: "gold",
905
- className: "whitespace-pre break-words",
906
- children: [
907
- /* @__PURE__ */ jsx10(Box2, { children: args && JSON.stringify(args, null, 2) }),
908
- /* @__PURE__ */ jsx10(Box2, { children: output && JSON.stringify(output, null, 2) })
909
- ]
910
- }
911
- );
912
- };
913
-
914
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Availabilities/Title.tsx
915
- import { Fragment, jsx as jsx11 } from "react/jsx-runtime";
916
- var Title = ({
917
- runStep
918
- }) => {
919
- if (runStep.completed_at) {
920
- return /* @__PURE__ */ jsx11(Fragment, { children: "Finished getting domains availability" });
921
- } else if (runStep.cancelled_at) {
922
- return /* @__PURE__ */ jsx11(Fragment, { children: "Cancelled getting domains availability" });
923
- } else {
924
- return /* @__PURE__ */ jsx11(Fragment, { children: "Getting domains availability" });
925
- }
926
- };
927
-
928
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Availabilities/index.tsx
929
- import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
930
- var Availabilities = ({
931
- fn,
932
- runStep
933
- }) => /* @__PURE__ */ jsxs3(PopoverRoot, { children: [
934
- /* @__PURE__ */ jsxs3(ToolCallBase, { children: [
935
- /* @__PURE__ */ jsx12(Icon, { runStep }),
936
- /* @__PURE__ */ jsx12(ToolCallTitle, { children: /* @__PURE__ */ jsx12(Title, { runStep }) })
937
- ] }),
938
- /* @__PURE__ */ jsx12(
939
- PopoverContent,
940
- {
941
- className: "max-h-[500px]",
942
- children: /* @__PURE__ */ jsx12(Content, { fn })
943
- }
944
- )
945
- ] });
946
-
947
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Scores/index.tsx
948
- import {
949
- PopoverRoot as PopoverRoot2,
950
- PopoverContent as PopoverContent2
951
- } from "@radix-ui/themes";
952
-
953
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Scores/Title.tsx
954
- import { Fragment as Fragment2, jsx as jsx13 } from "react/jsx-runtime";
955
- var Title2 = ({
956
- runStep
957
- }) => {
958
- if (runStep.completed_at) {
959
- return /* @__PURE__ */ jsx13(Fragment2, { children: "Finished getting domains scores" });
960
- } else if (runStep.cancelled_at) {
961
- return /* @__PURE__ */ jsx13(Fragment2, { children: "Cancelled getting domains scores" });
962
- } else {
963
- return /* @__PURE__ */ jsx13(Fragment2, { children: "Getting domains scores" });
964
- }
965
- };
966
-
967
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Scores/index.tsx
968
- import { jsx as jsx14, jsxs as jsxs4 } from "react/jsx-runtime";
969
- var Scores = ({
970
- fn,
971
- runStep
972
- }) => /* @__PURE__ */ jsxs4(PopoverRoot2, { children: [
973
- /* @__PURE__ */ jsxs4(ToolCallBase, { children: [
974
- /* @__PURE__ */ jsx14(Icon, { runStep }),
975
- /* @__PURE__ */ jsx14(ToolCallTitle, { children: /* @__PURE__ */ jsx14(Title2, { runStep }) })
976
- ] }),
977
- /* @__PURE__ */ jsx14(
978
- PopoverContent2,
979
- {
980
- className: "max-h-[500px]",
981
- children: /* @__PURE__ */ jsx14(Content, { fn })
982
- }
983
- )
984
- ] });
985
-
986
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/index.tsx
987
- import { jsx as jsx15 } from "react/jsx-runtime";
988
- var Fn = ({
989
- fn,
990
- runStep
991
- }) => {
992
- if (fn.name === "getAvailabilities") {
993
- return /* @__PURE__ */ jsx15(
994
- Availabilities,
995
- {
996
- fn,
997
- runStep
998
- }
999
- );
1000
- } else if (fn.name === "getScores") {
1001
- return /* @__PURE__ */ jsx15(
1002
- Scores,
1003
- {
1004
- fn,
1005
- runStep
1006
- }
1007
- );
1008
- }
1009
- return null;
1010
- };
1011
-
1012
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/CodeInterpreter/index.tsx
1013
- import {
1014
- Flex as Flex7
1015
- } from "@radix-ui/themes";
1016
- import { jsx as jsx16 } from "react/jsx-runtime";
1017
- var CodeInterpreter = ({
1018
- codeInterpreter
1019
- }) => /* @__PURE__ */ jsx16(Flex7, { children: codeInterpreter.input });
1020
-
1021
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx
1022
- import { jsx as jsx17 } from "react/jsx-runtime";
1023
- var ToolCall = ({
1024
- toolCall,
1025
- runStep
1026
- }) => {
1027
- if (toolCall.type === "function") {
1028
- return /* @__PURE__ */ jsx17(
1029
- Fn,
1030
- {
1031
- fn: toolCall.function,
1032
- runStep
1033
- }
1034
- );
1035
- }
1036
- if (toolCall.type === "code_interpreter") {
1037
- return /* @__PURE__ */ jsx17(
1038
- CodeInterpreter,
1039
- {
1040
- codeInterpreter: toolCall.code_interpreter,
1041
- runStep
1042
- }
1043
- );
1044
- }
1045
- return /* @__PURE__ */ jsx17(Flex8, { children: toolCall.type });
1046
- };
1047
-
1048
- // src/components/runSteps/RunStep/ToolCalls/Starting/index.tsx
1049
- import {
1050
- PopoverRoot as PopoverRoot3,
1051
- PopoverContent as PopoverContent3,
1052
- Text as Text3
1053
- } from "@radix-ui/themes";
1054
- import {
1055
- CircleIcon as CircleIcon2
1056
- } from "@radix-ui/react-icons";
1057
- import { jsx as jsx18, jsxs as jsxs5 } from "react/jsx-runtime";
1058
- var Starting = () => /* @__PURE__ */ jsxs5(PopoverRoot3, { children: [
1059
- /* @__PURE__ */ jsxs5(ToolCallBase, { children: [
1060
- /* @__PURE__ */ jsx18(CircleIcon2, {}),
1061
- /* @__PURE__ */ jsx18(ToolCallTitle, { children: "Starting actions" })
1062
- ] }),
1063
- /* @__PURE__ */ jsx18(
1064
- PopoverContent3,
1065
- {
1066
- className: "max-h-[500px]",
1067
- children: /* @__PURE__ */ jsx18(Text3, { children: "Getting ready to connect to domain API" })
1068
- }
1069
- )
1070
- ] });
1071
-
1072
- // src/components/runSteps/RunStep/ToolCalls/index.tsx
1073
- import { jsx as jsx19, jsxs as jsxs6 } from "react/jsx-runtime";
1074
- var ToolCalls = ({
1075
- stepDetails,
1076
- runStep
1077
- }) => /* @__PURE__ */ jsxs6(
1078
- Flex9,
1079
- {
1080
- direction: "column",
1081
- children: [
1082
- !stepDetails.tool_calls.length && /* @__PURE__ */ jsx19(Starting, {}),
1083
- stepDetails.tool_calls.map((toolCall) => /* @__PURE__ */ jsx19(
1084
- ToolCall,
1085
- {
1086
- toolCall,
1087
- runStep
1088
- },
1089
- toolCall.id
1090
- ))
1091
- ]
1092
- }
1093
- );
1094
-
1095
- // src/components/runSteps/RunStep/index.tsx
1096
- import { jsx as jsx20 } from "react/jsx-runtime";
1097
- var RunStep = ({
1098
- runStep
1099
- }) => {
1100
- if (runStep.step_details.type === "tool_calls") {
1101
- return /* @__PURE__ */ jsx20(
1102
- ToolCalls,
1103
- {
1104
- stepDetails: runStep.step_details,
1105
- runStep
1106
- }
1107
- );
1108
- }
1109
- return null;
1110
- };
1111
-
1112
- // src/components/runSteps/RunSteps/index.tsx
1113
- import { jsx as jsx21 } from "react/jsx-runtime";
1114
- var RunSteps = ({
1115
- runSteps
1116
- }) => /* @__PURE__ */ jsx21(
1117
- Flex10,
1118
- {
1119
- direction: "column-reverse",
1120
- children: runSteps.map((runStep) => /* @__PURE__ */ jsx21(
1121
- RunStep,
1122
- {
1123
- runStep
1124
- },
1125
- runStep.id
1126
- ))
1127
- }
1128
- );
1129
-
1130
- // src/components/messages/Message/TextContent/index.tsx
1131
- import { useContext as useContext2 } from "react";
1132
- import Markdown from "react-markdown";
1133
-
1134
- // src/contexts/markdown/MarkdownContext/index.ts
1135
- import { createContext as createContext3 } from "react";
1136
-
1137
- // src/contexts/markdown/MarkdownContext/lib/components/Paragraph.tsx
1138
- import {
1139
- Box as Box3,
1140
- Text as Text4
1141
- } from "@radix-ui/themes";
1142
- import { jsx as jsx22 } from "react/jsx-runtime";
1143
- var Paragraph = ({ children }) => /* @__PURE__ */ jsx22(
1144
- Box3,
1145
- {
1146
- pb: "3",
1147
- children: /* @__PURE__ */ jsx22(
1148
- Text4,
1149
- {
1150
- size: "3",
1151
- className: "whitespace-pre-line break-words",
1152
- children
1153
- }
1154
- )
1155
- }
1156
- );
1157
-
1158
- // src/contexts/markdown/MarkdownContext/lib/components/Link.tsx
1159
- import {
1160
- Link as RadixLink
1161
- } from "@radix-ui/themes";
1162
- import { jsx as jsx23 } from "react/jsx-runtime";
1163
- var Link = ({ children, href }) => /* @__PURE__ */ jsx23(
1164
- RadixLink,
1165
- {
1166
- href,
1167
- children
1168
- }
1169
- );
1170
-
1171
- // src/contexts/markdown/MarkdownContext/lib/components/UnorderedList.tsx
1172
- import {
1173
- Box as Box4
1174
- } from "@radix-ui/themes";
1175
- import { jsx as jsx24 } from "react/jsx-runtime";
1176
- var UnorderedList = ({ children }) => /* @__PURE__ */ jsx24(
1177
- Box4,
1178
- {
1179
- pb: "3",
1180
- asChild: true,
1181
- children: /* @__PURE__ */ jsx24(
1182
- "ul",
1183
- {
1184
- className: "list-inside",
1185
- children
1186
- }
1187
- )
1188
- }
1189
- );
1190
-
1191
- // src/contexts/markdown/MarkdownContext/lib/components/OrderedList.tsx
1192
- import {
1193
- Box as Box5
1194
- } from "@radix-ui/themes";
1195
- import { jsx as jsx25 } from "react/jsx-runtime";
1196
- var OrderedList = ({ children }) => /* @__PURE__ */ jsx25(
1197
- Box5,
1198
- {
1199
- pb: "3",
1200
- asChild: true,
1201
- children: /* @__PURE__ */ jsx25(
1202
- "ol",
1203
- {
1204
- className: "list-inside",
1205
- children
1206
- }
1207
- )
1208
- }
1209
- );
1210
-
1211
- // src/contexts/markdown/MarkdownContext/lib/components/ListItem.tsx
1212
- import {
1213
- Box as Box6
1214
- } from "@radix-ui/themes";
1215
- import { jsx as jsx26 } from "react/jsx-runtime";
1216
- var ListItem = ({ children }) => /* @__PURE__ */ jsx26(
1217
- Box6,
1218
- {
1219
- pb: "1",
1220
- children: /* @__PURE__ */ jsx26("li", { children })
1221
- }
1222
- );
1223
-
1224
- // src/contexts/markdown/MarkdownContext/lib/components/Strong.tsx
1225
- import {
1226
- Strong as RadixStrong
1227
- } from "@radix-ui/themes";
1228
- import { jsx as jsx27 } from "react/jsx-runtime";
1229
- var Strong = ({ children }) => /* @__PURE__ */ jsx27(RadixStrong, { children });
1230
-
1231
- // src/contexts/markdown/MarkdownContext/lib/components/index.tsx
1232
- var components = {
1233
- p: Paragraph,
1234
- a: Link,
1235
- strong: Strong,
1236
- ul: UnorderedList,
1237
- ol: OrderedList,
1238
- li: ListItem
1239
- };
1240
-
1241
- // src/contexts/markdown/MarkdownContext/index.ts
1242
- var MarkdownContext = createContext3({
1243
- remarkPlugins: [],
1244
- components
1245
- });
1246
-
1247
- // src/components/messages/Message/TextContent/index.tsx
1248
- import { jsx as jsx28 } from "react/jsx-runtime";
1249
- var TextContent = ({
1250
- content
1251
- }) => {
1252
- const markdownContext = useContext2(MarkdownContext);
1253
- return /* @__PURE__ */ jsx28(
1254
- Markdown,
1255
- {
1256
- ...markdownContext,
1257
- children: content.text.value
1258
- }
1259
- );
1260
- };
1261
-
1262
- // src/components/messages/Message/index.tsx
1263
- import { jsx as jsx29, jsxs as jsxs7 } from "react/jsx-runtime";
1264
- var Message = ({
1265
- message
1266
- }) => {
1267
- const [olderRunSteps, laterRunSteps] = useMemo8(() => {
1268
- if (!message.runSteps.length)
1269
- return [[], []];
1270
- const messageCreationRunStepIndex = message.runSteps.findIndex((runStep) => {
1271
- if (runStep.step_details.type !== "message_creation")
1272
- return;
1273
- return runStep.step_details.message_creation.message_id === message.id;
1274
- });
1275
- let nextRunStepIndex = message.runSteps.slice(0, messageCreationRunStepIndex).findLastIndex((runStep) => runStep.step_details.type === "message_creation");
1276
- if (nextRunStepIndex === -1) {
1277
- nextRunStepIndex = 0;
1278
- }
1279
- const laterRunSteps2 = message.runSteps.slice(nextRunStepIndex, messageCreationRunStepIndex);
1280
- const prevRunStepIndex = message.runSteps.slice(messageCreationRunStepIndex + 1).findIndex((runStep) => runStep.step_details.type === "message_creation");
1281
- let olderRunSteps2;
1282
- if (prevRunStepIndex === -1) {
1283
- olderRunSteps2 = message.runSteps.slice(messageCreationRunStepIndex + 1);
1284
- } else {
1285
- olderRunSteps2 = message.runSteps.slice(messageCreationRunStepIndex + 1, messageCreationRunStepIndex + prevRunStepIndex);
1286
- }
1287
- return [olderRunSteps2, laterRunSteps2];
1288
- }, [message]);
1289
- return /* @__PURE__ */ jsxs7(Box7, { children: [
1290
- /* @__PURE__ */ jsx29(
1291
- RunSteps,
1292
- {
1293
- runSteps: olderRunSteps
1294
- }
1295
- ),
1296
- message.content.map((content, index) => /* @__PURE__ */ jsx29(
1297
- Box7,
1298
- {
1299
- children: content.type === "text" && /* @__PURE__ */ jsx29(TextContent, { content })
1300
- },
1301
- index
1302
- )),
1303
- /* @__PURE__ */ jsx29(
1304
- RunSteps,
1305
- {
1306
- runSteps: laterRunSteps
1307
- }
1308
- )
1309
- ] });
1310
- };
1311
-
1312
- // src/components/messages/Messages/Content/MessageGroup/Content/index.tsx
1313
- import { jsx as jsx30 } from "react/jsx-runtime";
1314
- var Content2 = ({
1315
- messageGroup
1316
- }) => /* @__PURE__ */ jsx30(
1317
- Flex11,
1318
- {
1319
- direction: "column-reverse",
1320
- children: messageGroup.messages.map((message) => /* @__PURE__ */ jsx30(
1321
- Message,
1322
- {
1323
- message
1324
- },
1325
- message.id
1326
- ))
1327
- }
1328
- );
1329
-
1330
- // src/components/messages/Messages/Content/MessageGroup/index.tsx
1331
- import { jsx as jsx31, jsxs as jsxs8 } from "react/jsx-runtime";
1332
- var MessageGroup = ({
1333
- messageGroup
1334
- }) => {
1335
- const assistantNameContext = useContext3(AssistantNameContext);
1336
- return /* @__PURE__ */ jsxs8(MessagesGroupBase, { children: [
1337
- messageGroup.role === "user" ? /* @__PURE__ */ jsx31(
1338
- Avatar3,
1339
- {
1340
- fallback: /* @__PURE__ */ jsx31(PersonIcon, {}),
1341
- size: "1"
1342
- }
1343
- ) : /* @__PURE__ */ jsx31(AssistantAvatar, {}),
1344
- /* @__PURE__ */ jsxs8(Box8, { children: [
1345
- /* @__PURE__ */ jsx31(Name, { children: messageGroup.role === "user" ? "You" : assistantNameContext }),
1346
- /* @__PURE__ */ jsx31(
1347
- Content2,
1348
- {
1349
- messageGroup
1350
- }
1351
- )
1352
- ] })
1353
- ] });
1354
- };
1355
-
1356
- // src/components/messages/Messages/Content/index.tsx
1357
- import { Fragment as Fragment3, jsx as jsx32 } from "react/jsx-runtime";
1358
- var Content3 = ({
1359
- messages: messages2
1360
- }) => {
1361
- const { messageGroups: messageGroups2 } = useMessageGroups({
1362
- messages: messages2
1363
- });
1364
- return /* @__PURE__ */ jsx32(Fragment3, { children: messageGroups2.map((messageGroup) => /* @__PURE__ */ jsx32(
1365
- MessageGroup,
1366
- {
1367
- messageGroup
1368
- },
1369
- messageGroup.id
1370
- )) });
1371
- };
1372
-
1373
- // src/components/messages/Messages/ProgressMessage/index.tsx
1374
- import { Box as Box11 } from "@radix-ui/themes";
1375
-
1376
- // src/components/skeletons/StartingContentSkeleton/index.tsx
1377
- import {
1378
- Box as Box9
1379
- } from "@radix-ui/themes";
1380
- import { jsx as jsx33 } from "react/jsx-runtime";
1381
- var StartingContentSkeleton = () => /* @__PURE__ */ jsx33(
1382
- Box9,
1383
- {
1384
- height: "4",
1385
- width: "4",
1386
- shrink: "0",
1387
- mt: "1",
1388
- className: "animate-pulse bg-gray-12 rounded-3"
1389
- }
1390
- );
1391
-
1392
- // src/components/skeletons/StartingSkeleton/index.tsx
1393
- import { useContext as useContext4 } from "react";
1394
- import { Box as Box10 } from "@radix-ui/themes";
1395
- import { jsx as jsx34, jsxs as jsxs9 } from "react/jsx-runtime";
1396
- var StartingSkeleton = ({
1397
- children
1398
- }) => {
1399
- const assistantNameContext = useContext4(AssistantNameContext);
1400
- return /* @__PURE__ */ jsxs9(MessagesGroupBase, { children: [
1401
- /* @__PURE__ */ jsx34(AssistantAvatar, {}),
1402
- /* @__PURE__ */ jsxs9(Box10, { children: [
1403
- /* @__PURE__ */ jsx34(Name, { children: assistantNameContext }),
1404
- children,
1405
- /* @__PURE__ */ jsx34(StartingContentSkeleton, {})
1406
- ] })
1407
- ] });
1408
- };
1409
-
1410
- // src/components/messages/Messages/ProgressMessage/index.tsx
1411
- import { jsx as jsx35, jsxs as jsxs10 } from "react/jsx-runtime";
1412
- var ProgressMessage = ({
1413
- latestMessage,
1414
- isRunActive: isRunActive2
1415
- }) => {
1416
- if (!latestMessage)
1417
- return null;
1418
- if (!isRunActive2)
1419
- return null;
1420
- if (latestMessage.role === "user") {
1421
- return /* @__PURE__ */ jsx35(StartingSkeleton, {});
1422
- }
1423
- return /* @__PURE__ */ jsxs10(MessagesGroupBase, { children: [
1424
- /* @__PURE__ */ jsx35(Box11, { pl: "5" }),
1425
- /* @__PURE__ */ jsx35(StartingContentSkeleton, {})
1426
- ] });
1427
- };
1428
-
1429
- // src/components/messages/Messages/index.tsx
1430
- import { jsx as jsx36, jsxs as jsxs11 } from "react/jsx-runtime";
1431
- var Messages = ({
1432
- messagesQueryOptions,
1433
- runsQueryOptions,
1434
- createRunMutationOptions,
1435
- handleActionMutationOptions,
1436
- children
1437
- }) => {
1438
- const {
1439
- messages: messages2,
1440
- isFetchingNextPage,
1441
- hasNextPage,
1442
- fetchNextPage
1443
- } = useMessages({
1444
- messagesQueryOptions
1445
- });
1446
- useThreadLifecycles({
1447
- messagesQueryOptions,
1448
- runsQueryOptions,
1449
- createRunMutationOptions,
1450
- handleActionMutationOptions
1451
- });
1452
- const { containerRef, loaderRef } = useInfiniteScroll({
1453
- isFetchingNextPage,
1454
- hasNextPage,
1455
- fetchNextPage
1456
- });
1457
- const { isRunActive: isRunActive2 } = useIsRunActive({
1458
- messagesQueryOptions,
1459
- runsQueryOptions
1460
- });
1461
- const { latestMessage } = useLatestMessage({
1462
- messagesQueryOptions
1463
- });
1464
- return /* @__PURE__ */ jsxs11(
1465
- Flex12,
1466
- {
1467
- ref: containerRef,
1468
- direction: "column-reverse",
1469
- className: "overflow-auto",
1470
- grow: "1",
1471
- p: "2",
1472
- children: [
1473
- /* @__PURE__ */ jsx36(
1474
- Flex12,
1475
- {
1476
- shrink: "0",
1477
- height: "1"
1478
- }
1479
- ),
1480
- /* @__PURE__ */ jsx36(
1481
- ProgressMessage,
1482
- {
1483
- latestMessage,
1484
- isRunActive: isRunActive2
1485
- }
1486
- ),
1487
- children,
1488
- /* @__PURE__ */ jsx36(
1489
- Content3,
1490
- {
1491
- messages: messages2
1492
- }
1493
- ),
1494
- hasNextPage && /* @__PURE__ */ jsx36(
1495
- MessagesSkeleton,
1496
- {
1497
- ref: loaderRef
1498
- }
1499
- ),
1500
- /* @__PURE__ */ jsx36(
1501
- Flex12,
1502
- {
1503
- shrink: "0",
1504
- grow: "1"
1505
- }
1506
- )
1507
- ]
1508
- }
1509
- );
1510
- };
1511
-
1512
- // src/components/messages/Form/index.tsx
1513
- import {
1514
- Container as Container2,
1515
- Flex as Flex13,
1516
- Text as Text5
1517
- } from "@radix-ui/themes";
1518
- import { useRef as useRef3, useEffect as useEffect4, useMemo as useMemo9, useContext as useContext5 } from "react";
1519
- import { useForm } from "react-hook-form";
1520
- import { z } from "zod";
1521
- import { zodResolver } from "@hookform/resolvers/zod";
1522
- import { usePrevious } from "react-use";
1523
-
1524
- // src/components/textareas/TextareaBase/index.tsx
1525
- import { forwardRef as forwardRef4 } from "react";
1526
- import TextareaAutosize from "react-textarea-autosize";
1527
- import { jsx as jsx37 } from "react/jsx-runtime";
1528
- var UPSCALE_RATIO = 16 / 14;
1529
- var TextareaBase = forwardRef4(function TextareaBase2(props, ref) {
1530
- return /* @__PURE__ */ jsx37(
1531
- TextareaAutosize,
1532
- {
1533
- ref,
1534
- className: "textarea-base",
1535
- style: {
1536
- resize: "none",
1537
- fontSize: `${14 * UPSCALE_RATIO}px`,
1538
- lineHeight: `${24 * UPSCALE_RATIO}px`,
1539
- transform: `scale(${1 / UPSCALE_RATIO})`,
1540
- margin: `0 ${(-100 * UPSCALE_RATIO + 100) / 2}%`,
1541
- width: `${100 * UPSCALE_RATIO}%`,
1542
- maxWidth: `${100 * UPSCALE_RATIO}%`,
1543
- flexGrow: 1,
1544
- display: "flex"
1545
- },
1546
- ...props
1547
- }
1548
- );
1549
- });
1550
-
1551
- // src/hooks/messages/useCreateMessage/index.ts
1552
- import {
1553
- useMutation as useMutation3,
1554
- useQueryClient as useQueryClient4
1555
- } from "@tanstack/react-query";
1556
-
1557
- // src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/data.ts
1558
- var data = ({
1559
- newMessage
1560
- }) => (prevData) => {
1561
- const message = {
1562
- id: optimisticId(),
1563
- role: "user",
1564
- created_at: +/* @__PURE__ */ new Date(),
1565
- object: "thread.message",
1566
- content: [
1567
- {
1568
- type: "text",
1569
- text: {
1570
- annotations: [],
1571
- value: newMessage.content
1572
- }
1573
- }
1574
- ],
1575
- run_id: null,
1576
- assistant_id: null,
1577
- thread_id: null,
1578
- file_ids: [],
1579
- metadata: {},
1580
- runSteps: []
1581
- };
1582
- if (!prevData) {
1583
- return {
1584
- pageParams: [],
1585
- pages: [
1586
- {
1587
- data: [message],
1588
- hasNextPage: false,
1589
- lastId: message.id
1590
- }
1591
- ]
1592
- };
1593
- }
1594
- const [latestPage, ...pagesRest] = prevData.pages;
1595
- return {
1596
- ...prevData,
1597
- pages: [
1598
- {
1599
- ...latestPage,
1600
- data: [
1601
- message,
1602
- ...latestPage.data
1603
- ]
1604
- },
1605
- ...pagesRest
1606
- ]
1607
- };
1608
- };
1609
-
1610
- // src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/index.ts
1611
- var onMutate = ({
1612
- queryClient
1613
- }) => async (newMessage) => {
1614
- await queryClient.cancelQueries(queryKey());
1615
- const prevMessages = queryClient.getQueryData(queryKey());
1616
- queryClient.setQueryData(
1617
- queryKey(),
1618
- data({ newMessage })
1619
- );
1620
- return {
1621
- prevMessages,
1622
- newMessage
1623
- };
1624
- };
1625
-
1626
- // src/hooks/messages/useCreateMessage/lib/mutationOptions/onError.ts
1627
- var onError = ({
1628
- queryClient
1629
- }) => async (_error, newMessage, context) => {
1630
- if (!context) {
1631
- return;
1632
- }
1633
- queryClient.setQueryData(
1634
- queryKey(),
1635
- context.prevMessages
1636
- );
1637
- };
1638
-
1639
- // src/hooks/messages/useCreateMessage/lib/mutationOptions/onSettled.ts
1640
- var onSettled3 = ({
1641
- queryClient
1642
- }) => async (response) => {
1643
- if (!response)
1644
- return;
1645
- await queryClient.invalidateQueries({
1646
- queryKey: queryKey()
1647
- });
1648
- };
1649
-
1650
- // src/hooks/messages/useCreateMessage/lib/mutationOptions/index.ts
1651
- var mutationOptions3 = ({
1652
- queryClient
1653
- }) => ({
1654
- // mutationFn,
1655
- onMutate: onMutate({
1656
- queryClient
1657
- }),
1658
- onError: onError({
1659
- queryClient
1660
- }),
1661
- onSettled: onSettled3({
1662
- queryClient
1663
- })
1664
- });
1665
-
1666
- // src/hooks/messages/useCreateMessage/index.ts
1667
- var useCreateMessage = ({
1668
- createMessageMutationOptions
1669
- }) => {
1670
- const queryClient = useQueryClient4();
1671
- const mutationProps = useMutation3({
1672
- ...mutationOptions3({
1673
- queryClient
1674
- }),
1675
- ...createMessageMutationOptions
1676
- });
1677
- return {
1678
- ...mutationProps,
1679
- createMessage: mutationProps.mutateAsync
1680
- };
1681
- };
1682
-
1683
- // src/components/messages/Form/Submit/index.tsx
1684
- import {
1685
- ArrowUpIcon
1686
- } from "@radix-ui/react-icons";
1687
- import {
1688
- Button as Button2
1689
- } from "@radix-ui/themes";
1690
-
1691
- // src/components/spinners/Spinner/index.tsx
1692
- import { jsx as jsx38 } from "react/jsx-runtime";
1693
- var Spinner = (props) => /* @__PURE__ */ jsx38(
1694
- "svg",
1695
- {
1696
- xmlns: "http://www.w3.org/2000/svg",
1697
- width: "24",
1698
- height: "24",
1699
- viewBox: "0 0 24 24",
1700
- fill: "none",
1701
- stroke: "currentColor",
1702
- strokeWidth: "2",
1703
- strokeLinecap: "round",
1704
- strokeLinejoin: "round",
1705
- className: "h-4 w-4 animate-spin",
1706
- ...props,
1707
- children: /* @__PURE__ */ jsx38("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
1708
- }
1709
- );
1710
-
1711
- // src/components/messages/Form/Submit/index.tsx
1712
- import { jsx as jsx39 } from "react/jsx-runtime";
1713
- var Submit = ({
1714
- isLoading,
1715
- isDisabled
1716
- }) => /* @__PURE__ */ jsx39(
1717
- Button2,
1718
- {
1719
- type: "submit",
1720
- color: "gray",
1721
- highContrast: true,
1722
- radius: "large",
1723
- disabled: isLoading || isDisabled,
1724
- children: isLoading ? /* @__PURE__ */ jsx39(Spinner, {}) : /* @__PURE__ */ jsx39(ArrowUpIcon, {})
1725
- }
1726
- );
1727
-
1728
- // src/components/messages/Form/index.tsx
1729
- import { jsx as jsx40, jsxs as jsxs12 } from "react/jsx-runtime";
1730
- var schema = z.object({
1731
- content: z.string().min(1).max(300)
1732
- });
1733
- var Form = ({
1734
- messagesQueryOptions,
1735
- runsQueryOptions,
1736
- createMessageMutationOptions
1737
- }) => {
1738
- const {
1739
- register,
1740
- handleSubmit,
1741
- formState: { errors, isSubmitting },
1742
- reset
1743
- } = useForm({
1744
- resolver: zodResolver(schema)
1745
- });
1746
- const { isRunActive: isRunActive2 } = useIsRunActive({
1747
- messagesQueryOptions,
1748
- runsQueryOptions
1749
- });
1750
- const isLoading = useMemo9(() => isRunActive2 || isSubmitting, [
1751
- isRunActive2,
1752
- isSubmitting
1753
- ]);
1754
- const {
1755
- createMessage
1756
- } = useCreateMessage({
1757
- createMessageMutationOptions
1758
- });
1759
- const onSubmit = async (data2) => {
1760
- reset();
1761
- await createMessage({
1762
- content: data2.content
1763
- });
1764
- };
1765
- const { latestMessage } = useLatestMessage({
1766
- messagesQueryOptions
1767
- });
1768
- const isDisabled = useMemo9(() => {
1769
- var _a;
1770
- return (
1771
- // @ts-ignore-next-line
1772
- (_a = latestMessage == null ? void 0 : latestMessage.metadata) == null ? void 0 : _a.isBlocking
1773
- );
1774
- }, [latestMessage, isLoading]);
1775
- const isInputDisabled = useMemo9(() => isLoading || isDisabled || false, [isLoading, isDisabled]);
1776
- const isInputDisabledPrevious = usePrevious(isInputDisabled);
1777
- const textareaRef = useRef3(null);
1778
- const textareaProps = register("content");
1779
- useEffect4(() => {
1780
- if (isInputDisabled)
1781
- return;
1782
- if (!isInputDisabledPrevious)
1783
- return;
1784
- if (!textareaRef.current)
1785
- return;
1786
- textareaRef.current.focus();
1787
- }, [isInputDisabled, isInputDisabledPrevious, textareaProps]);
1788
- const assistantNameContext = useContext5(AssistantNameContext);
1789
- return /* @__PURE__ */ jsx40(
1790
- Container2,
1791
- {
1792
- size: "2",
1793
- px: "2",
1794
- grow: "0",
1795
- children: /* @__PURE__ */ jsx40(
1796
- Flex13,
1797
- {
1798
- direction: "column",
1799
- shrink: "0",
1800
- children: /* @__PURE__ */ jsx40(
1801
- Flex13,
1802
- {
1803
- direction: "column",
1804
- shrink: "0",
1805
- className: "bg-gray-1",
1806
- pb: "4",
1807
- children: /* @__PURE__ */ jsx40(
1808
- "form",
1809
- {
1810
- onSubmit: handleSubmit(onSubmit),
1811
- children: /* @__PURE__ */ jsxs12(
1812
- Flex13,
1813
- {
1814
- className: `rounded-3 border-gray-5 border border-solid ${errors.content ? "border-red-9 bg-red-2" : ""}`,
1815
- p: "2",
1816
- pl: "4",
1817
- children: [
1818
- /* @__PURE__ */ jsx40(
1819
- Text5,
1820
- {
1821
- size: "2",
1822
- className: "grow",
1823
- children: /* @__PURE__ */ jsx40(
1824
- Flex13,
1825
- {
1826
- grow: "1",
1827
- direction: "column",
1828
- children: /* @__PURE__ */ jsx40(
1829
- TextareaBase,
1830
- {
1831
- minRows: 1,
1832
- placeholder: `Message ${assistantNameContext}...`,
1833
- disabled: isLoading || isDisabled,
1834
- onKeyDown: (e) => {
1835
- if (e.key === "Enter" && !e.shiftKey) {
1836
- e.preventDefault();
1837
- handleSubmit(onSubmit)();
1838
- }
1839
- },
1840
- autoFocus: true,
1841
- ...textareaProps,
1842
- ref: (e) => {
1843
- textareaProps.ref(e);
1844
- textareaRef.current = e;
1845
- }
1846
- }
1847
- )
1848
- }
1849
- )
1850
- }
1851
- ),
1852
- /* @__PURE__ */ jsx40(
1853
- Flex13,
1854
- {
1855
- shrink: "0",
1856
- align: "end",
1857
- children: /* @__PURE__ */ jsx40(
1858
- Submit,
1859
- {
1860
- isLoading,
1861
- isDisabled
1862
- }
1863
- )
1864
- }
1865
- )
1866
- ]
1867
- }
1868
- )
1869
- }
1870
- )
1871
- }
1872
- )
1873
- }
1874
- )
1875
- }
1876
- );
1877
- };
1878
-
1879
- // src/index.ts
1880
- import {
1881
- QueryClient,
1882
- QueryClientProvider,
1883
- useQueryClient as useQueryClient5,
1884
- useQuery
1885
- } from "@tanstack/react-query";
1886
- export {
1887
- Form,
1888
- Messages,
1889
- QueryClient,
1890
- QueryClientProvider,
1891
- useCreateMessage,
1892
- useIsRunActive,
1893
- useLatestMessage,
1894
- useMessages,
1895
- useQuery,
1896
- useQueryClient5 as useQueryClient,
1897
- useThreadLifecycles
1898
- };
1899
- //# sourceMappingURL=index.mjs.map