@superinterface/react 2.0.0 → 2.0.2

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
@@ -286,7 +286,7 @@ var merge = function(obj) {
286
286
  // src/contexts/core/SuperinterfaceContext/index.tsx
287
287
  import { createContext } from "react";
288
288
  var SuperinterfaceContext = createContext({
289
- baseUrl: "http://localhost:3000/api/cloud",
289
+ baseUrl: "https://superinterface.ai/api/cloud",
290
290
  variables: {},
291
291
  defaultOptions: {
292
292
  queries: {},
@@ -317,169 +317,9 @@ var SuperinterfaceProvider = function(param) {
317
317
  children: children
318
318
  });
319
319
  };
320
- // src/components/threads/Thread/index.tsx
321
- import { Flex as Flex14 } from "@radix-ui/themes";
322
- // src/components/threadMessages/ThreadMessages/index.tsx
323
- import { Flex as Flex12 } from "@radix-ui/themes";
324
- // src/hooks/misc/useInfiniteScroll/index.tsx
325
- import { useRef as useRef2 } from "react";
326
- import { useInView } from "react-intersection-observer";
327
- // src/hooks/misc/useThrottledEffect/index.tsx
328
- import _3 from "lodash";
329
- import { useRef, useEffect, useCallback } from "react";
330
- var useThrottledEffect = function(cb, delay, additionalDeps) {
331
- var _cbRef;
332
- var cbRef = useRef(cb);
333
- var throttledCb = useCallback(_3.throttle(function() {
334
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
335
- args[_key] = arguments[_key];
336
- }
337
- return (_cbRef = cbRef).current.apply(_cbRef, _to_consumable_array(args));
338
- }, delay, {
339
- leading: true,
340
- trailing: true
341
- }), [
342
- delay
343
- ]);
344
- useEffect(function() {
345
- cbRef.current = cb;
346
- });
347
- useEffect(throttledCb, [
348
- throttledCb
349
- ].concat(_to_consumable_array(additionalDeps)));
350
- };
351
- // src/hooks/misc/useInfiniteScroll/index.tsx
352
- var useInfiniteScroll = function(param) {
353
- var isFetchingNextPage = param.isFetchingNextPage, hasNextPage = param.hasNextPage, fetchNextPage = param.fetchNextPage;
354
- var containerRef = useRef2(null);
355
- var _useInView = useInView({
356
- root: containerRef.current,
357
- rootMargin: "0px",
358
- threshold: 0.1
359
- }), loaderRef = _useInView.ref, inView = _useInView.inView;
360
- useThrottledEffect(function() {
361
- if (isFetchingNextPage) return;
362
- if (!inView) return;
363
- if (!hasNextPage) return;
364
- console.log("Fetching next page");
365
- fetchNextPage();
366
- }, 500, [
367
- inView,
368
- isFetchingNextPage,
369
- hasNextPage,
370
- fetchNextPage
371
- ]);
372
- return {
373
- containerRef: containerRef,
374
- loaderRef: loaderRef,
375
- inView: inView
376
- };
377
- };
378
- // src/components/skeletons/ThreadMessagesSkeleton/index.tsx
379
- import { forwardRef as forwardRef2 } from "react";
380
- import { Flex as Flex4, Avatar, Box } from "@radix-ui/themes";
381
- // src/components/skeletons/Skeleton/index.tsx
382
- import { Flex } from "@radix-ui/themes";
383
- import { jsx as jsx2 } from "react/jsx-runtime";
384
- var Skeleton = function(_param) {
385
- var height = _param.height, style = _param.style, rest = _object_without_properties(_param, [
386
- "height",
387
- "style"
388
- ]);
389
- return(// @ts-ignore-next-line
390
- /* @__PURE__ */ jsx2(Flex, _object_spread({
391
- style: _object_spread({
392
- animation: "pulse 2s cubic-bezier(.4,0,.6,1) infinite",
393
- borderRadius: "var(--radius-3)",
394
- backgroundColor: "var(--gray-5)",
395
- height: "var(--space-".concat(height, ")")
396
- }, style)
397
- }, rest)));
398
- };
399
- // src/components/threadMessageGroups/ThreadMessagesGroupBase/index.tsx
400
- import { forwardRef } from "react";
401
- import { Flex as Flex2, Container } from "@radix-ui/themes";
402
- import { jsx as jsx3 } from "react/jsx-runtime";
403
- var ThreadMessagesGroupBase = forwardRef(function ThreadMessagesGroupBase2(param, ref) {
404
- var children = param.children;
405
- return /* @__PURE__ */ jsx3(Container, {
406
- ref: ref,
407
- size: "2",
408
- grow: "0",
409
- children: /* @__PURE__ */ jsx3(Flex2, {
410
- shrink: "0",
411
- gap: "3",
412
- children: children
413
- })
414
- });
415
- });
416
- // src/components/threadMessageGroups/ThreadMessagesGroupBase/Name.tsx
417
- import { Flex as Flex3, Text } from "@radix-ui/themes";
418
- import { jsx as jsx4 } from "react/jsx-runtime";
419
- var Name = function(param) {
420
- var children = param.children;
421
- return /* @__PURE__ */ jsx4(Flex3, {
422
- align: "center",
423
- style: {
424
- height: "var(--space-5)"
425
- },
426
- children: /* @__PURE__ */ jsx4(Text, {
427
- size: "2",
428
- weight: "bold",
429
- children: children
430
- })
431
- });
432
- };
433
- // src/components/skeletons/ThreadMessagesSkeleton/index.tsx
434
- import { jsx as jsx5, jsxs } from "react/jsx-runtime";
435
- var ThreadMessagesSkeleton = forwardRef2(function ThreadMessagesSkeleton2(_props, ref) {
436
- return /* @__PURE__ */ jsxs(ThreadMessagesGroupBase, {
437
- ref: ref,
438
- children: [
439
- /* @__PURE__ */ jsx5(Avatar, {
440
- fallback: /* @__PURE__ */ jsx5(Flex4, {}),
441
- size: "1",
442
- style: {
443
- animation: "pulse 2s cubic-bezier(.4,0,.6,1) infinite"
444
- }
445
- }),
446
- /* @__PURE__ */ jsxs(Box, {
447
- pb: "3",
448
- children: [
449
- /* @__PURE__ */ jsx5(Name, {
450
- children: /* @__PURE__ */ jsx5(Skeleton, {
451
- height: "1",
452
- style: {
453
- width: "128px"
454
- }
455
- })
456
- }),
457
- /* @__PURE__ */ jsx5(Skeleton, {
458
- height: "2",
459
- style: {
460
- width: "256px"
461
- }
462
- }),
463
- /* @__PURE__ */ jsx5(Skeleton, {
464
- height: "2",
465
- style: {
466
- width: "256px",
467
- marginTop: "var(--space-2)"
468
- }
469
- }),
470
- /* @__PURE__ */ jsx5(Skeleton, {
471
- height: "2",
472
- style: {
473
- width: "256px",
474
- marginTop: "var(--space-2)"
475
- }
476
- })
477
- ]
478
- })
479
- ]
480
- });
481
- });
482
- // src/hooks/threadMessages/useThreadMessages/index.tsx
320
+ // src/components/threads/Thread/Messages/index.tsx
321
+ import { Flex as Flex13 } from "@radix-ui/themes";
322
+ // src/hooks/messages/useMessages/index.tsx
483
323
  import { useMemo } from "react";
484
324
  import { useInfiniteQuery, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
485
325
  // src/lib/threads/queryOptions/index.ts
@@ -502,9 +342,13 @@ var queryOptions = function(param) {
502
342
  } : {}, variables));
503
343
  return [
504
344
  2,
505
- fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), {
345
+ fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({
506
346
  credentials: "include"
507
- }).then(function() {
347
+ }, superinterfaceContext.publicApiKey ? {
348
+ headers: {
349
+ Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
350
+ }
351
+ } : {})).then(function() {
508
352
  var _ref = _async_to_generator(function(response) {
509
353
  var errorResponse, error;
510
354
  return _ts_generator(this, function(_state) {
@@ -561,23 +405,23 @@ var queryOptions = function(param) {
561
405
  queryKey: queryKey
562
406
  }), threadContext.defaultOptions.queries));
563
407
  };
564
- // src/hooks/threadMessages/useThreadMessages/index.tsx
565
- var threadMessages = function(param) {
408
+ // src/hooks/messages/useMessages/index.tsx
409
+ var messages = function(param) {
566
410
  var props = param.props;
567
411
  if (!props.data) return [];
568
412
  return props.data.pages.reduce(function(acc, page) {
569
413
  return acc.concat(page.data);
570
414
  }, []);
571
415
  };
572
- var useThreadMessages = function() {
416
+ var useMessages = function() {
573
417
  var queryClient = useQueryClient2();
574
418
  var threadContext = useSuperinterfaceContext();
575
419
  var superinterfaceContext = useSuperinterfaceContext();
576
420
  var props = useInfiniteQuery(queryOptions({
577
421
  queryKeyBase: [
578
- "threadMessages"
422
+ "messages"
579
423
  ],
580
- path: "/thread-messages",
424
+ path: "/messages",
581
425
  queryClient: queryClient,
582
426
  threadContext: threadContext,
583
427
  superinterfaceContext: superinterfaceContext
@@ -585,7 +429,7 @@ var useThreadMessages = function() {
585
429
  return useMemo(function() {
586
430
  return _object_spread_props(_object_spread({}, props), {
587
431
  // @ts-ignore-next-line
588
- threadMessages: threadMessages({
432
+ messages: messages({
589
433
  props: props
590
434
  })
591
435
  });
@@ -593,1354 +437,1562 @@ var useThreadMessages = function() {
593
437
  props
594
438
  ]);
595
439
  };
596
- // src/hooks/runs/useManageRuns/index.tsx
597
- import { useQueryClient as useQueryClient5 } from "@tanstack/react-query";
598
- import { useEffect as useEffect2 } from "react";
599
- // src/hooks/threadMessages/useLatestThreadMessage/index.ts
440
+ // src/hooks/messageGroups/useMessageGroups/index.ts
600
441
  import { useMemo as useMemo2 } from "react";
601
- var useLatestThreadMessage = function() {
602
- var props = useThreadMessages();
603
- return useMemo2(function() {
604
- return _object_spread_props(_object_spread({}, props), {
605
- latestThreadMessage: props.threadMessages[0] || null
606
- });
607
- }, [
608
- props
442
+ // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/index.ts
443
+ import _3 from "lodash";
444
+ import { last } from "radash";
445
+ // src/lib/messages/order.ts
446
+ import { sort } from "radash";
447
+ var order = function(param) {
448
+ var messages2 = param.messages;
449
+ return sort(messages2, function(m) {
450
+ return m.created_at;
451
+ }, true);
452
+ };
453
+ // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/newGroup/newGroupItem.ts
454
+ var newGroupItem = function(param) {
455
+ var message = param.message;
456
+ return {
457
+ id: message.id,
458
+ role: message.role,
459
+ createdAt: message.created_at,
460
+ messages: [
461
+ message
462
+ ]
463
+ };
464
+ };
465
+ // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/newGroup/index.ts
466
+ var newGroup = function(param) {
467
+ var groups = param.groups, message = param.message;
468
+ return _to_consumable_array(groups).concat([
469
+ newGroupItem({
470
+ message: message
471
+ })
609
472
  ]);
610
473
  };
611
- // src/hooks/runs/useLatestRun/index.ts
612
- import { useMemo as useMemo4 } from "react";
613
- // src/hooks/runs/useRuns/index.tsx
614
- import { useMemo as useMemo3 } from "react";
615
- import { useInfiniteQuery as useInfiniteQuery2, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
616
- // src/hooks/runs/useRuns/lib/getRuns.ts
617
- var getRuns = function(param) {
618
- var data3 = param.data;
619
- if (!data3) return [];
620
- return data3.pages.reduce(function(acc, page) {
621
- return acc.concat(page.data);
474
+ // src/hooks/messageGroups/useMessageGroups/lib/messageGroups/index.ts
475
+ var messageGroups = function(param) {
476
+ var messages2 = param.messages;
477
+ return _3.reduce(order({
478
+ messages: messages2
479
+ }), function(groups, message) {
480
+ var group = last(groups);
481
+ if (!group) return newGroup({
482
+ groups: groups,
483
+ message: message
484
+ });
485
+ if (group.role !== message.role) {
486
+ return newGroup({
487
+ groups: groups,
488
+ message: message
489
+ });
490
+ }
491
+ return _to_consumable_array(_3.dropRight(groups)).concat([
492
+ _object_spread_props(_object_spread({}, group), {
493
+ messages: _to_consumable_array(group.messages).concat([
494
+ message
495
+ ])
496
+ })
497
+ ]);
622
498
  }, []);
623
499
  };
624
- // src/hooks/runs/useRuns/index.tsx
625
- var useRuns = function() {
626
- var queryClient = useQueryClient3();
627
- var superinterfaceContext = useSuperinterfaceContext();
628
- var threadContext = useSuperinterfaceContext();
629
- var props = useInfiniteQuery2(queryOptions({
630
- queryKeyBase: [
631
- "runs"
632
- ],
633
- path: "/runs",
634
- queryClient: queryClient,
635
- threadContext: threadContext,
636
- superinterfaceContext: superinterfaceContext
637
- }));
638
- return useMemo3(function() {
639
- return _object_spread_props(_object_spread({}, props), {
640
- // @ts-ignore-next-line
641
- runs: getRuns({
642
- data: props.data
500
+ // src/hooks/messageGroups/useMessageGroups/index.ts
501
+ var useMessageGroups = function(param) {
502
+ var messages2 = param.messages;
503
+ return useMemo2(function() {
504
+ return {
505
+ messageGroups: messageGroups({
506
+ messages: messages2
643
507
  })
644
- });
508
+ };
645
509
  }, [
646
- props
510
+ messages2
647
511
  ]);
648
512
  };
649
- // src/hooks/runs/useLatestRun/index.ts
650
- var useLatestRun = function() {
651
- var props = useRuns();
652
- return useMemo4(function() {
653
- return _object_spread_props(_object_spread({}, props), {
654
- latestRun: props.runs[0]
655
- });
656
- }, [
657
- props
513
+ // src/components/skeletons/MessagesSkeleton/index.tsx
514
+ import { forwardRef as forwardRef2 } from "react";
515
+ import { Flex as Flex4, Avatar, Box } from "@radix-ui/themes";
516
+ // src/components/skeletons/Skeleton/index.tsx
517
+ import { Flex } from "@radix-ui/themes";
518
+ import { jsx as jsx2 } from "react/jsx-runtime";
519
+ var Skeleton = function(_param) {
520
+ var height = _param.height, style = _param.style, rest = _object_without_properties(_param, [
521
+ "height",
522
+ "style"
658
523
  ]);
524
+ return /* @__PURE__ */ jsx2(Flex, _object_spread({
525
+ height: "var(--space-".concat(height, ")"),
526
+ style: _object_spread({
527
+ animation: "pulse 2s cubic-bezier(.4,0,.6,1) infinite",
528
+ borderRadius: "var(--radius-3)",
529
+ backgroundColor: "var(--gray-5)"
530
+ }, style)
531
+ }, rest));
659
532
  };
660
- // src/hooks/runs/useCreateRun/index.ts
661
- import { partob } from "radash";
662
- import { useMutation, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
663
- // src/lib/threads/mutationOptions/index.ts
664
- var mutationOptions = function(param) {
665
- var mutationKeyBase = param.mutationKeyBase, path = param.path, queryClient = param.queryClient, threadContext = param.threadContext, superinterfaceContext = param.superinterfaceContext;
666
- var mutationKey = _to_consumable_array(mutationKeyBase).concat([
667
- threadContext.variables
668
- ]);
669
- return _object_spread(_object_spread_props(_object_spread({
670
- mutationFn: function(variables) {
671
- return fetch("".concat(superinterfaceContext.baseUrl).concat(path), {
672
- method: "POST",
673
- body: JSON.stringify(variables),
674
- credentials: "include"
675
- }).then(function() {
676
- var _ref = _async_to_generator(function(response) {
677
- var errorResponse, error;
678
- return _ts_generator(this, function(_state) {
679
- switch(_state.label){
680
- case 0:
681
- if (!(response.status !== 200)) return [
682
- 3,
683
- 4
684
- ];
685
- _state.label = 1;
686
- case 1:
687
- _state.trys.push([
688
- 1,
689
- 3,
690
- ,
691
- 4
692
- ]);
693
- return [
694
- 4,
695
- response.json()
696
- ];
697
- case 2:
698
- errorResponse = _state.sent();
699
- throw new Error(errorResponse.error);
700
- case 3:
701
- error = _state.sent();
702
- throw new Error("Failed to fetch");
703
- case 4:
704
- return [
705
- 2,
706
- response.json()
707
- ];
708
- }
709
- });
710
- });
711
- return function(response) {
712
- return _ref.apply(this, arguments);
713
- };
714
- }());
715
- }
716
- }, queryClient.getMutationDefaults(mutationKey)), {
717
- mutationKey: mutationKey
718
- }), threadContext.defaultOptions.mutations);
533
+ // src/components/messageGroups/MessageGroupBase/index.tsx
534
+ import { forwardRef } from "react";
535
+ import { Flex as Flex2, Container } from "@radix-ui/themes";
536
+ import { jsx as jsx3 } from "react/jsx-runtime";
537
+ var MessageGroupBase = forwardRef(function MessageGroupBase2(param, ref) {
538
+ var children = param.children;
539
+ return /* @__PURE__ */ jsx3(Container, {
540
+ ref: ref,
541
+ size: "2",
542
+ flexGrow: "0",
543
+ children: /* @__PURE__ */ jsx3(Flex2, {
544
+ flexShrink: "0",
545
+ gap: "3",
546
+ children: children
547
+ })
548
+ });
549
+ });
550
+ // src/components/messageGroups/MessageGroupBase/Name.tsx
551
+ import { Flex as Flex3, Text } from "@radix-ui/themes";
552
+ import { jsx as jsx4 } from "react/jsx-runtime";
553
+ var Name = function(param) {
554
+ var children = param.children;
555
+ return /* @__PURE__ */ jsx4(Flex3, {
556
+ align: "center",
557
+ height: "var(--space-5)",
558
+ children: /* @__PURE__ */ jsx4(Text, {
559
+ size: "2",
560
+ weight: "bold",
561
+ children: children
562
+ })
563
+ });
719
564
  };
720
- // src/hooks/runs/useCreateRun/lib/onSuccess.ts
721
- var onSuccess = function(param) {
722
- var queryClient = param.queryClient;
723
- return function() {
724
- var _ref = _async_to_generator(function(data3, variables) {
725
- return _ts_generator(this, function(_state) {
726
- return [
727
- 2,
728
- queryClient.setQueryData([
729
- "runs",
730
- variables
731
- ], function(prevData) {
732
- if (!prevData) {
733
- return {
734
- pageParams: [],
735
- pages: [
736
- {
737
- data: [
738
- data3.run
739
- ],
740
- hasNextPage: false,
741
- lastId: data3.run.id
742
- }
743
- ]
744
- };
565
+ // src/components/skeletons/MessagesSkeleton/index.tsx
566
+ import { jsx as jsx5, jsxs } from "react/jsx-runtime";
567
+ var MessagesSkeleton = forwardRef2(function MessagesSkeleton2(_props, ref) {
568
+ return /* @__PURE__ */ jsxs(MessageGroupBase, {
569
+ ref: ref,
570
+ children: [
571
+ /* @__PURE__ */ jsx5(Avatar, {
572
+ fallback: /* @__PURE__ */ jsx5(Flex4, {}),
573
+ size: "1",
574
+ style: {
575
+ animation: "pulse 2s cubic-bezier(.4,0,.6,1) infinite"
576
+ }
577
+ }),
578
+ /* @__PURE__ */ jsxs(Box, {
579
+ pb: "3",
580
+ children: [
581
+ /* @__PURE__ */ jsx5(Name, {
582
+ children: /* @__PURE__ */ jsx5(Skeleton, {
583
+ height: "1",
584
+ style: {
585
+ width: "128px"
586
+ }
587
+ })
588
+ }),
589
+ /* @__PURE__ */ jsx5(Skeleton, {
590
+ height: "2",
591
+ style: {
592
+ width: "256px"
593
+ }
594
+ }),
595
+ /* @__PURE__ */ jsx5(Skeleton, {
596
+ height: "2",
597
+ style: {
598
+ width: "256px",
599
+ marginTop: "var(--space-2)"
600
+ }
601
+ }),
602
+ /* @__PURE__ */ jsx5(Skeleton, {
603
+ height: "2",
604
+ style: {
605
+ width: "256px",
606
+ marginTop: "var(--space-2)"
745
607
  }
746
- var _prevData_pages = _to_array(prevData.pages), latestPage = _prevData_pages[0], pagesRest = _prevData_pages.slice(1);
747
- return _object_spread_props(_object_spread({}, prevData), {
748
- pages: [
749
- _object_spread_props(_object_spread({}, latestPage), {
750
- data: [
751
- data3.run
752
- ].concat(_to_consumable_array(latestPage.data))
753
- })
754
- ].concat(_to_consumable_array(pagesRest))
755
- });
756
608
  })
757
- ];
758
- });
759
- });
760
- return function(data3, variables) {
761
- return _ref.apply(this, arguments);
762
- };
763
- }();
764
- };
765
- // src/hooks/runs/useCreateRun/lib/onSettled.ts
766
- var onSettled = function(param) {
767
- var queryClient = param.queryClient;
768
- return function() {
769
- var _ref = _async_to_generator(function(_data, _error, variables) {
770
- return _ts_generator(this, function(_state) {
771
- switch(_state.label){
772
- case 0:
773
- return [
774
- 4,
775
- queryClient.invalidateQueries({
776
- queryKey: [
777
- "threadMessages",
778
- variables
779
- ]
780
- })
781
- ];
782
- case 1:
783
- _state.sent();
784
- return [
785
- 4,
786
- queryClient.invalidateQueries({
787
- queryKey: [
788
- "runs",
789
- variables
790
- ]
791
- })
792
- ];
793
- case 2:
794
- _state.sent();
795
- return [
796
- 2
797
- ];
798
- }
799
- });
800
- });
801
- return function(_data, _error, variables) {
802
- return _ref.apply(this, arguments);
803
- };
804
- }();
805
- };
806
- // src/lib/optimistic/optimisticId.ts
807
- import { uid } from "radash";
808
- var optimisticId = function() {
809
- return "-".concat(uid(24));
810
- };
811
- // src/hooks/runs/useCreateRun/lib/onMutate/data.ts
812
- var data = function(prevData) {
813
- var run = {
814
- id: optimisticId(),
815
- object: "thread.run",
816
- created_at: +/* @__PURE__ */ new Date(),
817
- assistant_id: null,
818
- thread_id: null,
819
- status: "in_progress",
820
- expires_at: +/* @__PURE__ */ new Date() + 1e3 * 60 * 60 * 24,
821
- cancelled_at: null,
822
- failed_at: null,
823
- completed_at: null,
824
- required_action: null,
825
- last_error: null,
826
- model: null,
827
- instructions: null,
828
- tools: [],
829
- file_ids: [],
830
- metadata: {},
831
- usage: null
832
- };
833
- if (!prevData) {
834
- return {
835
- pageParams: [],
836
- pages: [
837
- {
838
- data: [
839
- run
840
- ],
841
- hasNextPage: false,
842
- lastId: run.id
843
- }
844
- ]
845
- };
846
- }
847
- var _prevData_pages = _to_array(prevData.pages), latestPage = _prevData_pages[0], pagesRest = _prevData_pages.slice(1);
848
- return _object_spread_props(_object_spread({}, prevData), {
849
- pages: [
850
- _object_spread_props(_object_spread({}, latestPage), {
851
- data: [
852
- run
853
- ].concat(_to_consumable_array(latestPage.data))
609
+ ]
854
610
  })
855
- ].concat(_to_consumable_array(pagesRest))
611
+ ]
612
+ });
613
+ });
614
+ // src/components/threads/Thread/Messages/Content/MessageGroup/index.tsx
615
+ import { useContext as useContext5 } from "react";
616
+ import { Box as Box8, Avatar as Avatar3 } from "@radix-ui/themes";
617
+ import { PersonIcon } from "@radix-ui/react-icons";
618
+ // src/components/messageGroups/MessageGroupBase/AssistantAvatar.tsx
619
+ import { useContext as useContext2 } from "react";
620
+ import { Flex as Flex5 } from "@radix-ui/themes";
621
+ // src/contexts/assistants/AssistantAvatarContext/index.tsx
622
+ import { createContext as createContext2 } from "react";
623
+ import { Avatar as Avatar2 } from "@radix-ui/themes";
624
+ import { LightningBoltIcon } from "@radix-ui/react-icons";
625
+ import { jsx as jsx6 } from "react/jsx-runtime";
626
+ var AssistantAvatarContext = createContext2(/* @__PURE__ */ jsx6(Avatar2, {
627
+ fallback: /* @__PURE__ */ jsx6(LightningBoltIcon, {}),
628
+ size: "1"
629
+ }));
630
+ // src/components/messageGroups/MessageGroupBase/AssistantAvatar.tsx
631
+ import { jsx as jsx7 } from "react/jsx-runtime";
632
+ var AssistantAvatar = function() {
633
+ var AssistantAvatarContextValue = useContext2(AssistantAvatarContext);
634
+ return /* @__PURE__ */ jsx7(Flex5, {
635
+ flexShrink: "0",
636
+ height: "24px",
637
+ width: "24px",
638
+ style: {
639
+ borderRadius: "var(--radius-3)",
640
+ overflow: "hidden"
641
+ },
642
+ children: AssistantAvatarContextValue
856
643
  });
857
644
  };
858
- // src/hooks/runs/useCreateRun/lib/onMutate/index.ts
859
- var onMutate = function(param) {
860
- var queryClient = param.queryClient;
861
- return function() {
862
- var _ref = _async_to_generator(function(variables) {
863
- var queryKey, prevRuns;
864
- return _ts_generator(this, function(_state) {
865
- switch(_state.label){
866
- case 0:
867
- queryKey = [
868
- "runs",
869
- variables
870
- ];
871
- return [
872
- 4,
873
- queryClient.cancelQueries({
874
- queryKey: queryKey
875
- })
876
- ];
877
- case 1:
878
- _state.sent();
879
- prevRuns = queryClient.getQueryData(queryKey);
880
- queryClient.setQueryData(queryKey, data);
881
- return [
882
- 2,
883
- {
884
- prevRuns: prevRuns,
885
- variables: variables
886
- }
887
- ];
888
- }
889
- });
890
- });
891
- return function(variables) {
892
- return _ref.apply(this, arguments);
893
- };
894
- }();
895
- };
896
- // src/hooks/runs/useCreateRun/index.ts
897
- var useCreateRun = function() {
898
- var queryClient = useQueryClient4();
899
- var superinterfaceContext = useSuperinterfaceContext();
900
- var threadContext = useSuperinterfaceContext();
901
- var props = useMutation(_object_spread({
902
- onSuccess: onSuccess({
903
- queryClient: queryClient
904
- }),
905
- onSettled: onSettled({
906
- queryClient: queryClient
907
- }),
908
- onMutate: onMutate({
909
- queryClient: queryClient
645
+ // src/contexts/assistants/AssistantNameContext/index.tsx
646
+ import { createContext as createContext3 } from "react";
647
+ var AssistantNameContext = createContext3("Assistant");
648
+ // src/components/threads/Thread/Messages/Content/MessageGroup/Content/index.tsx
649
+ import { Flex as Flex11 } from "@radix-ui/themes";
650
+ // src/components/threads/Thread/Message/index.tsx
651
+ import { useMemo as useMemo4 } from "react";
652
+ import { Box as Box7 } from "@radix-ui/themes";
653
+ // src/components/runSteps/RunSteps/index.tsx
654
+ import { Flex as Flex10 } from "@radix-ui/themes";
655
+ // src/components/runSteps/RunStep/ToolCalls/index.tsx
656
+ import { Flex as Flex9 } from "@radix-ui/themes";
657
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx
658
+ import { Flex as Flex8 } from "@radix-ui/themes";
659
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/index.tsx
660
+ import { useContext as useContext3 } from "react";
661
+ // src/contexts/functions/FunctionComponentsContext/index.tsx
662
+ import { createContext as createContext4 } from "react";
663
+ var FunctionComponentsContext = createContext4({});
664
+ // src/components/functions/FunctionBase/index.tsx
665
+ import { PopoverRoot, PopoverContent } from "@radix-ui/themes";
666
+ // src/components/toolCalls/ToolCallBase/index.tsx
667
+ import { Flex as Flex6, Button, PopoverTrigger } from "@radix-ui/themes";
668
+ import { jsx as jsx8 } from "react/jsx-runtime";
669
+ var ToolCallBase = function(param) {
670
+ var children = param.children;
671
+ return /* @__PURE__ */ jsx8(Flex6, {
672
+ py: "1",
673
+ ml: "-2",
674
+ children: /* @__PURE__ */ jsx8(PopoverTrigger, {
675
+ children: /* @__PURE__ */ jsx8(Button, {
676
+ size: "1",
677
+ color: "gold",
678
+ variant: "outline",
679
+ style: {
680
+ boxShadow: "none"
681
+ },
682
+ children: children
683
+ })
910
684
  })
911
- }, mutationOptions({
912
- mutationKeyBase: [
913
- "createRun"
914
- ],
915
- path: "/runs",
916
- queryClient: queryClient,
917
- threadContext: threadContext,
918
- superinterfaceContext: superinterfaceContext
919
- })));
920
- return _object_spread_props(_object_spread({}, props), {
921
- createRun: partob(props.mutate, threadContext.variables)
922
685
  });
923
686
  };
924
- // src/lib/optimistic/isOptimistic.ts
925
- import _4 from "lodash";
926
- var isOptimistic = function(param) {
927
- var id = param.id;
928
- return _4.startsWith(id, "-");
687
+ // src/components/toolCalls/ToolCallBase/ToolCallTitle.tsx
688
+ import { Text as Text2 } from "@radix-ui/themes";
689
+ import { jsx as jsx9 } from "react/jsx-runtime";
690
+ var ToolCallTitle = function(param) {
691
+ var children = param.children;
692
+ return /* @__PURE__ */ jsx9(Text2, {
693
+ weight: "regular",
694
+ children: children
695
+ });
929
696
  };
930
- // src/hooks/runs/useManageRuns/index.tsx
931
- var useManageRuns = function() {
932
- var queryClient = useQueryClient5();
933
- var latestRunProps = useLatestRun();
934
- var latestThreadMessageProps = useLatestThreadMessage();
935
- var createRunProps = useCreateRun();
936
- var threadContext = useSuperinterfaceContext();
937
- useEffect2(function() {
938
- if (createRunProps.isPending) return;
939
- if (latestRunProps.isFetching) return;
940
- if (latestThreadMessageProps.isFetching) return;
941
- if (!latestThreadMessageProps.latestThreadMessage) return;
942
- if (latestThreadMessageProps.latestThreadMessage.role !== "user") return;
943
- if (isOptimistic({
944
- id: latestThreadMessageProps.latestThreadMessage.id
945
- })) return;
946
- if (latestRunProps.latestRun && latestRunProps.latestRun.created_at > latestThreadMessageProps.latestThreadMessage.created_at) {
947
- return;
697
+ // src/components/functions/FunctionBase/Icon.tsx
698
+ import { CircleIcon, CircleBackslashIcon, CheckCircledIcon } from "@radix-ui/react-icons";
699
+ import { jsx as jsx10 } from "react/jsx-runtime";
700
+ var Icon = function(param) {
701
+ var runStep = param.runStep;
702
+ if (runStep.completed_at) {
703
+ return /* @__PURE__ */ jsx10(CheckCircledIcon, {});
704
+ } else if (runStep.cancelled_at || runStep.failed_at || runStep.status === "expired") {
705
+ return /* @__PURE__ */ jsx10(CircleBackslashIcon, {});
706
+ } else {
707
+ return /* @__PURE__ */ jsx10(CircleIcon, {});
708
+ }
709
+ };
710
+ // src/components/functions/FunctionBase/Content.tsx
711
+ import { useMemo as useMemo3 } from "react";
712
+ import { Code, Box as Box2 } from "@radix-ui/themes";
713
+ import { jsx as jsx11, jsxs as jsxs2 } from "react/jsx-runtime";
714
+ var Content = function(param) {
715
+ var fn = param.fn;
716
+ var args = useMemo3(function() {
717
+ var result = null;
718
+ try {
719
+ result = JSON.parse(fn.arguments);
720
+ } catch (error) {
721
+ console.error(error);
948
722
  }
949
- var isMutating = queryClient.isMutating({
950
- mutationKey: [
951
- "createRun",
952
- threadContext.variables
953
- ]
954
- });
955
- if (isMutating) return;
956
- createRunProps.createRun();
723
+ return result;
957
724
  }, [
958
- threadContext,
959
- queryClient,
960
- createRunProps,
961
- latestRunProps,
962
- latestThreadMessageProps
725
+ fn
963
726
  ]);
964
- return null;
965
- };
966
- // src/hooks/runs/usePolling/index.tsx
967
- import { useQueryClient as useQueryClient6 } from "@tanstack/react-query";
968
- import { useInterval } from "react-use";
969
- // src/hooks/runs/useIsRunActive/index.tsx
970
- import { useMemo as useMemo5 } from "react";
971
- import { useIsMutating } from "@tanstack/react-query";
972
- // src/lib/runs/isRunEditingThreadMessage/index.ts
973
- import _5 from "lodash";
974
- var isRunEditingThreadMessage = function(param) {
975
- var threadMessage = param.threadMessage;
976
- if (!threadMessage) return false;
977
- if (threadMessage.role === "user") return false;
978
- if (!threadMessage.run_id) return false;
979
- var hasContent = _5.some(threadMessage.content, function(content) {
980
- var _content_text;
981
- return content.type !== "text" || content.type === "text" && ((_content_text = content.text) === null || _content_text === void 0 ? void 0 : _content_text.value) !== "";
982
- });
983
- return !hasContent;
984
- };
985
- // src/hooks/runs/useIsRunActive/index.tsx
986
- var progressStatuses = [
987
- "queued",
988
- "in_progress",
989
- "cancelling",
990
- "requires_action"
991
- ];
992
- var stoppedStatuses = [
993
- "expired",
994
- "cancelled",
995
- "failed"
996
- ];
997
- var isRunActive = function(param) {
998
- var latestRunProps = param.latestRunProps, latestThreadMessageProps = param.latestThreadMessageProps, isMutating = param.isMutating;
999
- var _latestThreadMessageProps_latestThreadMessage_metadata, _latestThreadMessageProps_latestThreadMessage;
1000
- if ((_latestThreadMessageProps_latestThreadMessage = latestThreadMessageProps.latestThreadMessage) === null || _latestThreadMessageProps_latestThreadMessage === void 0 ? void 0 : (_latestThreadMessageProps_latestThreadMessage_metadata = _latestThreadMessageProps_latestThreadMessage.metadata) === null || _latestThreadMessageProps_latestThreadMessage_metadata === void 0 ? void 0 : _latestThreadMessageProps_latestThreadMessage_metadata.isBlocking) return false;
1001
- if (isMutating) return true;
1002
- if (!latestRunProps.latestRun) return false;
1003
- if (progressStatuses.includes(latestRunProps.latestRun.status)) return true;
1004
- if (stoppedStatuses.includes(latestRunProps.latestRun.status)) return false;
1005
- return isRunEditingThreadMessage({
1006
- threadMessage: latestThreadMessageProps.latestThreadMessage
1007
- });
1008
- };
1009
- var useIsRunActive = function() {
1010
- var latestRunProps = useLatestRun();
1011
- var latestThreadMessageProps = useLatestThreadMessage();
1012
- var threadContext = useSuperinterfaceContext();
1013
- var isMutatingCreateRun = useIsMutating({
1014
- mutationKey: [
1015
- "createRun",
1016
- threadContext.variables
1017
- ]
1018
- });
1019
- var isMutatingCreateThreadMessage = useIsMutating({
1020
- mutationKey: [
1021
- "createThreadMessage",
1022
- threadContext.variables
727
+ var output = useMemo3(function() {
728
+ if (!fn.output) {
729
+ return null;
730
+ }
731
+ var result = null;
732
+ try {
733
+ result = JSON.parse(fn.output);
734
+ } catch (error) {
735
+ console.error(error);
736
+ }
737
+ return result;
738
+ }, [
739
+ fn
740
+ ]);
741
+ if (!args) {
742
+ return null;
743
+ }
744
+ return /* @__PURE__ */ jsxs2(Code, {
745
+ variant: "ghost",
746
+ color: "gold",
747
+ style: {
748
+ whiteSpace: "pre",
749
+ wordBreak: "break-word"
750
+ },
751
+ children: [
752
+ /* @__PURE__ */ jsx11(Box2, {
753
+ children: args && JSON.stringify(args, null, 2)
754
+ }),
755
+ /* @__PURE__ */ jsx11(Box2, {
756
+ children: output && JSON.stringify(output, null, 2)
757
+ })
1023
758
  ]
1024
759
  });
1025
- var isMutatingCreateHandleAction = useIsMutating({
1026
- mutationKey: [
1027
- "handleAction",
1028
- threadContext.variables
760
+ };
761
+ // src/components/functions/FunctionBase/index.tsx
762
+ import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
763
+ var FunctionBase = function(param) {
764
+ var fn = param.fn, runStep = param.runStep, title2 = param.title;
765
+ return /* @__PURE__ */ jsxs3(PopoverRoot, {
766
+ children: [
767
+ /* @__PURE__ */ jsxs3(ToolCallBase, {
768
+ children: [
769
+ /* @__PURE__ */ jsx12(Icon, {
770
+ runStep: runStep
771
+ }),
772
+ /* @__PURE__ */ jsx12(ToolCallTitle, {
773
+ children: title2
774
+ })
775
+ ]
776
+ }),
777
+ /* @__PURE__ */ jsx12(PopoverContent, {
778
+ style: {
779
+ maxHeight: "500px"
780
+ },
781
+ children: /* @__PURE__ */ jsx12(Content, {
782
+ fn: fn
783
+ })
784
+ })
1029
785
  ]
1030
786
  });
1031
- return useMemo5(function() {
1032
- return _object_spread_props(_object_spread({}, latestRunProps), {
1033
- isRunActive: isRunActive({
1034
- latestRunProps: latestRunProps,
1035
- latestThreadMessageProps: latestThreadMessageProps,
1036
- isMutating: isMutatingCreateRun > 0 || isMutatingCreateThreadMessage > 0 || isMutatingCreateHandleAction > 0
1037
- })
1038
- });
1039
- }, [
1040
- latestRunProps,
1041
- latestThreadMessageProps,
1042
- isMutatingCreateRun,
1043
- isMutatingCreateThreadMessage,
1044
- isMutatingCreateHandleAction
1045
- ]);
1046
787
  };
1047
- // src/hooks/runs/usePolling/lib/refetch.ts
1048
- var refetch = function() {
1049
- var _ref = _async_to_generator(function(param) {
1050
- var queryClient, threadContext, _threadContext_defaultOptions_queries_queryKey, _threadContext_defaultOptions_queries_queryKey1;
1051
- return _ts_generator(this, function(_state) {
1052
- switch(_state.label){
1053
- case 0:
1054
- queryClient = param.queryClient, threadContext = param.threadContext;
1055
- return [
1056
- 4,
1057
- queryClient.invalidateQueries({
1058
- queryKey: (_threadContext_defaultOptions_queries_queryKey = threadContext.defaultOptions.queries.queryKey) !== null && _threadContext_defaultOptions_queries_queryKey !== void 0 ? _threadContext_defaultOptions_queries_queryKey : [
1059
- "threadMessages",
1060
- threadContext.variables
1061
- ]
1062
- })
1063
- ];
1064
- case 1:
1065
- _state.sent();
1066
- return [
1067
- 4,
1068
- queryClient.invalidateQueries({
1069
- queryKey: (_threadContext_defaultOptions_queries_queryKey1 = threadContext.defaultOptions.queries.queryKey) !== null && _threadContext_defaultOptions_queries_queryKey1 !== void 0 ? _threadContext_defaultOptions_queries_queryKey1 : [
1070
- "runs",
1071
- threadContext.variables
1072
- ]
1073
- })
1074
- ];
1075
- case 2:
1076
- _state.sent();
1077
- return [
1078
- 2
1079
- ];
1080
- }
1081
- });
788
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/DefaultFunction/lib/title.ts
789
+ var title = function(param) {
790
+ var fn = param.fn, runStep = param.runStep;
791
+ if (runStep.completed_at) {
792
+ return "Finished ".concat(fn.name);
793
+ } else if (runStep.cancelled_at) {
794
+ return "Cancelled ".concat(fn.name);
795
+ } else {
796
+ return "Calling ".concat(fn.name);
797
+ }
798
+ };
799
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/DefaultFunction/index.tsx
800
+ import { jsx as jsx13 } from "react/jsx-runtime";
801
+ var DefaultFunction = function(param) {
802
+ var fn = param.fn, runStep = param.runStep;
803
+ return /* @__PURE__ */ jsx13(FunctionBase, {
804
+ fn: fn,
805
+ runStep: runStep,
806
+ title: title({
807
+ runStep: runStep,
808
+ fn: fn
809
+ })
1082
810
  });
1083
- return function refetch(_) {
1084
- return _ref.apply(this, arguments);
1085
- };
1086
- }();
1087
- // src/hooks/runs/usePolling/index.tsx
1088
- var usePolling = function() {
1089
- var threadContext = useSuperinterfaceContext();
1090
- var queryClient = useQueryClient6();
1091
- var isRunActiveProps = useIsRunActive();
1092
- useInterval(function() {
1093
- refetch({
1094
- queryClient: queryClient,
1095
- threadContext: threadContext
1096
- });
1097
- console.log("poll refetched");
1098
- }, isRunActiveProps.isRunActive ? 3e3 : null);
1099
- return null;
1100
811
  };
1101
- // src/hooks/actions/useManageActions/index.tsx
1102
- import { useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1103
- import { useEffect as useEffect3 } from "react";
1104
- // src/hooks/actions/useHandleAction/index.tsx
1105
- import { partob as partob2 } from "radash";
1106
- import { useMutation as useMutation2, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
1107
- // src/hooks/actions/useHandleAction/lib/onSettled.ts
1108
- var onSettled2 = function(param) {
1109
- var queryClient = param.queryClient;
1110
- return function() {
1111
- var _ref = _async_to_generator(function(_data, _error, variables) {
1112
- return _ts_generator(this, function(_state) {
1113
- switch(_state.label){
1114
- case 0:
1115
- return [
1116
- 4,
1117
- queryClient.invalidateQueries({
1118
- queryKey: [
1119
- "threadMessages",
1120
- variables
1121
- ]
1122
- })
1123
- ];
1124
- case 1:
1125
- _state.sent();
1126
- return [
1127
- 4,
1128
- queryClient.invalidateQueries({
1129
- queryKey: [
1130
- "runs",
1131
- variables
1132
- ]
1133
- })
1134
- ];
1135
- case 2:
1136
- _state.sent();
1137
- return [
1138
- 2
1139
- ];
1140
- }
1141
- });
1142
- });
1143
- return function(_data, _error, variables) {
1144
- return _ref.apply(this, arguments);
1145
- };
1146
- }();
812
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/index.tsx
813
+ import { jsx as jsx14 } from "react/jsx-runtime";
814
+ var Fn = function(param) {
815
+ var fn = param.fn, runStep = param.runStep;
816
+ var functionComponentsContext = useContext3(FunctionComponentsContext);
817
+ var Component = functionComponentsContext[fn.name] || DefaultFunction;
818
+ return(// @ts-ignore-next-line
819
+ /* @__PURE__ */ jsx14(Component, {
820
+ fn: fn,
821
+ runStep: runStep
822
+ }));
1147
823
  };
1148
- // src/hooks/actions/useHandleAction/index.tsx
1149
- var useHandleAction = function() {
1150
- var queryClient = useQueryClient7();
1151
- var superinterfaceContext = useSuperinterfaceContext();
1152
- var threadContext = useSuperinterfaceContext();
1153
- var props = useMutation2(_object_spread({
1154
- onSettled: onSettled2({
1155
- queryClient: queryClient
1156
- })
1157
- }, mutationOptions({
1158
- mutationKeyBase: [
1159
- "handleAction"
1160
- ],
1161
- path: "/actions",
1162
- queryClient: queryClient,
1163
- threadContext: threadContext,
1164
- superinterfaceContext: superinterfaceContext
1165
- })));
1166
- return _object_spread_props(_object_spread({}, props), {
1167
- handleAction: partob2(props.mutate, threadContext.variables)
824
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/CodeInterpreter/index.tsx
825
+ import { Flex as Flex7 } from "@radix-ui/themes";
826
+ import { jsx as jsx15 } from "react/jsx-runtime";
827
+ var CodeInterpreter = function(param) {
828
+ var codeInterpreter = param.codeInterpreter;
829
+ return /* @__PURE__ */ jsx15(Flex7, {
830
+ children: codeInterpreter.input
1168
831
  });
1169
832
  };
1170
- // src/hooks/actions/useManageActions/index.tsx
1171
- var useManageActions = function() {
1172
- var queryClient = useQueryClient8();
1173
- var threadContext = useSuperinterfaceContext();
1174
- var latestRunProps = useLatestRun();
1175
- var handleActionProps = useHandleAction();
1176
- useEffect3(function() {
1177
- if (handleActionProps.isPending) return;
1178
- if (latestRunProps.isFetching) return;
1179
- if (!latestRunProps.latestRun) return;
1180
- if (latestRunProps.latestRun.status !== "requires_action") return;
1181
- var isMutating = queryClient.isMutating({
1182
- mutationKey: [
1183
- "handleAction",
1184
- threadContext.variables
1185
- ]
1186
- });
1187
- if (isMutating) return;
1188
- console.log("requires action", {
1189
- latestRunProps: latestRunProps
833
+ // src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx
834
+ import { jsx as jsx16 } from "react/jsx-runtime";
835
+ var ToolCall = function(param) {
836
+ var toolCall = param.toolCall, runStep = param.runStep;
837
+ if (toolCall.type === "function") {
838
+ return /* @__PURE__ */ jsx16(Fn, {
839
+ fn: toolCall.function,
840
+ runStep: runStep
1190
841
  });
1191
- handleActionProps.handleAction({
1192
- latestRun: latestRunProps.latestRun
842
+ }
843
+ if (toolCall.type === "code_interpreter") {
844
+ return /* @__PURE__ */ jsx16(CodeInterpreter, {
845
+ codeInterpreter: toolCall.code_interpreter,
846
+ runStep: runStep
1193
847
  });
1194
- }, [
1195
- handleActionProps,
1196
- latestRunProps
1197
- ]);
1198
- return null;
848
+ }
849
+ return /* @__PURE__ */ jsx16(Flex8, {
850
+ children: toolCall.type
851
+ });
852
+ };
853
+ // src/components/runSteps/RunStep/ToolCalls/Starting/index.tsx
854
+ import { PopoverRoot as PopoverRoot2, PopoverContent as PopoverContent2, Text as Text3 } from "@radix-ui/themes";
855
+ import { CircleIcon as CircleIcon2 } from "@radix-ui/react-icons";
856
+ import { jsx as jsx17, jsxs as jsxs4 } from "react/jsx-runtime";
857
+ var Starting = function() {
858
+ return /* @__PURE__ */ jsxs4(PopoverRoot2, {
859
+ children: [
860
+ /* @__PURE__ */ jsxs4(ToolCallBase, {
861
+ children: [
862
+ /* @__PURE__ */ jsx17(CircleIcon2, {}),
863
+ /* @__PURE__ */ jsx17(ToolCallTitle, {
864
+ children: "Starting actions"
865
+ })
866
+ ]
867
+ }),
868
+ /* @__PURE__ */ jsx17(PopoverContent2, {
869
+ style: {
870
+ maxHeight: "500px"
871
+ },
872
+ children: /* @__PURE__ */ jsx17(Text3, {
873
+ children: "Getting ready to connect to domain API"
874
+ })
875
+ })
876
+ ]
877
+ });
878
+ };
879
+ // src/components/runSteps/RunStep/ToolCalls/index.tsx
880
+ import { jsx as jsx18, jsxs as jsxs5 } from "react/jsx-runtime";
881
+ var ToolCalls = function(param) {
882
+ var stepDetails = param.stepDetails, runStep = param.runStep;
883
+ return /* @__PURE__ */ jsxs5(Flex9, {
884
+ direction: "column",
885
+ children: [
886
+ !stepDetails.tool_calls.length && /* @__PURE__ */ jsx18(Starting, {}),
887
+ stepDetails.tool_calls.map(function(toolCall) {
888
+ return /* @__PURE__ */ jsx18(ToolCall, {
889
+ toolCall: toolCall,
890
+ runStep: runStep
891
+ }, toolCall.id);
892
+ })
893
+ ]
894
+ });
1199
895
  };
1200
- // src/hooks/threads/useThreadLifecycles/index.tsx
1201
- var useThreadLifecycles = function() {
1202
- useManageRuns();
1203
- useManageActions();
1204
- usePolling();
896
+ // src/components/runSteps/RunStep/index.tsx
897
+ import { jsx as jsx19 } from "react/jsx-runtime";
898
+ var RunStep = function(param) {
899
+ var runStep = param.runStep;
900
+ if (runStep.step_details.type === "tool_calls") {
901
+ return /* @__PURE__ */ jsx19(ToolCalls, {
902
+ stepDetails: runStep.step_details,
903
+ runStep: runStep
904
+ });
905
+ }
1205
906
  return null;
1206
907
  };
1207
- // src/hooks/threadMessageGroups/useThreadMessageGroups/index.ts
1208
- import { useMemo as useMemo6 } from "react";
1209
- // src/hooks/threadMessageGroups/useThreadMessageGroups/lib/threadMessageGroups/index.ts
1210
- import _6 from "lodash";
1211
- import { last } from "radash";
1212
- // src/lib/threadMessages/order.ts
1213
- import { sort } from "radash";
1214
- var order = function(param) {
1215
- var threadMessages2 = param.threadMessages;
1216
- return sort(threadMessages2, function(tm) {
1217
- return tm.created_at;
1218
- }, true);
1219
- };
1220
- // src/hooks/threadMessageGroups/useThreadMessageGroups/lib/threadMessageGroups/newGroup/newGroupItem.ts
1221
- var newGroupItem = function(param) {
1222
- var threadMessage = param.threadMessage;
1223
- return {
1224
- id: threadMessage.id,
1225
- role: threadMessage.role,
1226
- createdAt: threadMessage.created_at,
1227
- threadMessages: [
1228
- threadMessage
1229
- ]
1230
- };
908
+ // src/components/runSteps/RunSteps/index.tsx
909
+ import { jsx as jsx20 } from "react/jsx-runtime";
910
+ var RunSteps = function(param) {
911
+ var runSteps = param.runSteps;
912
+ return /* @__PURE__ */ jsx20(Flex10, {
913
+ direction: "column-reverse",
914
+ children: runSteps.map(function(runStep) {
915
+ return /* @__PURE__ */ jsx20(RunStep, {
916
+ runStep: runStep
917
+ }, runStep.id);
918
+ })
919
+ });
1231
920
  };
1232
- // src/hooks/threadMessageGroups/useThreadMessageGroups/lib/threadMessageGroups/newGroup/index.ts
1233
- var newGroup = function(param) {
1234
- var groups = param.groups, threadMessage = param.threadMessage;
1235
- return _to_consumable_array(groups).concat([
1236
- newGroupItem({
1237
- threadMessage: threadMessage
921
+ // src/components/threads/Thread/Message/TextContent/index.tsx
922
+ import { useContext as useContext4 } from "react";
923
+ import { useRemarkSync } from "react-remark";
924
+ // src/contexts/markdown/MarkdownContext/index.ts
925
+ import { createContext as createContext5 } from "react";
926
+ // src/contexts/markdown/MarkdownContext/lib/components/Paragraph.tsx
927
+ import { Box as Box3, Text as Text4 } from "@radix-ui/themes";
928
+ import { jsx as jsx21 } from "react/jsx-runtime";
929
+ var Paragraph = function(param) {
930
+ var children = param.children;
931
+ return /* @__PURE__ */ jsx21(Box3, {
932
+ pb: "3",
933
+ children: /* @__PURE__ */ jsx21(Text4, {
934
+ size: "3",
935
+ style: {
936
+ whiteSpace: "pre-line",
937
+ wordBreak: "break-word"
938
+ },
939
+ children: children
1238
940
  })
1239
- ]);
941
+ });
1240
942
  };
1241
- // src/hooks/threadMessageGroups/useThreadMessageGroups/lib/threadMessageGroups/index.ts
1242
- var threadMessageGroups = function(param) {
1243
- var threadMessages2 = param.threadMessages;
1244
- return _6.reduce(order({
1245
- threadMessages: threadMessages2
1246
- }), function(groups, threadMessage) {
1247
- var group = last(groups);
1248
- if (!group) return newGroup({
1249
- groups: groups,
1250
- threadMessage: threadMessage
1251
- });
1252
- if (group.role !== threadMessage.role) {
1253
- return newGroup({
1254
- groups: groups,
1255
- threadMessage: threadMessage
1256
- });
1257
- }
1258
- return _to_consumable_array(_6.dropRight(groups)).concat([
1259
- _object_spread_props(_object_spread({}, group), {
1260
- threadMessages: _to_consumable_array(group.threadMessages).concat([
1261
- threadMessage
1262
- ])
1263
- })
1264
- ]);
1265
- }, []);
943
+ // src/contexts/markdown/MarkdownContext/lib/components/Link.tsx
944
+ import { Link as RadixLink } from "@radix-ui/themes";
945
+ import { jsx as jsx22 } from "react/jsx-runtime";
946
+ var Link = function(param) {
947
+ var children = param.children, href = param.href;
948
+ return /* @__PURE__ */ jsx22(RadixLink, {
949
+ href: href,
950
+ children: children
951
+ });
1266
952
  };
1267
- // src/hooks/threadMessageGroups/useThreadMessageGroups/index.ts
1268
- var useThreadMessageGroups = function(param) {
1269
- var threadMessages2 = param.threadMessages;
1270
- return useMemo6(function() {
1271
- return {
1272
- threadMessageGroups: threadMessageGroups({
1273
- threadMessages: threadMessages2
1274
- })
1275
- };
1276
- }, [
1277
- threadMessages2
1278
- ]);
953
+ // src/contexts/markdown/MarkdownContext/lib/components/UnorderedList.tsx
954
+ import { Box as Box4 } from "@radix-ui/themes";
955
+ import { jsx as jsx23 } from "react/jsx-runtime";
956
+ var UnorderedList = function(param) {
957
+ var children = param.children;
958
+ return /* @__PURE__ */ jsx23(Box4, {
959
+ pb: "3",
960
+ asChild: true,
961
+ children: /* @__PURE__ */ jsx23("ul", {
962
+ style: {
963
+ listStylePosition: "inside"
964
+ },
965
+ children: children
966
+ })
967
+ });
1279
968
  };
1280
- // src/components/threadMessages/ThreadMessages/Content/ThreadMessageGroup/index.tsx
1281
- import { useContext as useContext5 } from "react";
1282
- import { Box as Box8, Avatar as Avatar3 } from "@radix-ui/themes";
1283
- import { PersonIcon } from "@radix-ui/react-icons";
1284
- // src/components/threadMessageGroups/ThreadMessagesGroupBase/AssistantAvatar.tsx
1285
- import { useContext as useContext2 } from "react";
1286
- import { Flex as Flex5 } from "@radix-ui/themes";
1287
- // src/contexts/assistants/AssistantAvatarContext/index.tsx
1288
- import { createContext as createContext2 } from "react";
1289
- import { Avatar as Avatar2 } from "@radix-ui/themes";
1290
- import { LightningBoltIcon } from "@radix-ui/react-icons";
1291
- import { jsx as jsx6 } from "react/jsx-runtime";
1292
- var AssistantAvatarContext = createContext2(/* @__PURE__ */ jsx6(Avatar2, {
1293
- fallback: /* @__PURE__ */ jsx6(LightningBoltIcon, {}),
1294
- size: "1"
1295
- }));
1296
- // src/components/threadMessageGroups/ThreadMessagesGroupBase/AssistantAvatar.tsx
1297
- import { jsx as jsx7 } from "react/jsx-runtime";
1298
- var AssistantAvatar = function() {
1299
- var AssistantAvatarContextValue = useContext2(AssistantAvatarContext);
1300
- return /* @__PURE__ */ jsx7(Flex5, {
1301
- shrink: "0",
1302
- style: {
1303
- borderRadius: "var(--radius-3)",
1304
- overflow: "hidden",
1305
- height: "24px",
1306
- width: "24px"
1307
- },
1308
- children: AssistantAvatarContextValue
969
+ // src/contexts/markdown/MarkdownContext/lib/components/OrderedList.tsx
970
+ import { Box as Box5 } from "@radix-ui/themes";
971
+ import { jsx as jsx24 } from "react/jsx-runtime";
972
+ var OrderedList = function(param) {
973
+ var children = param.children;
974
+ return /* @__PURE__ */ jsx24(Box5, {
975
+ pb: "3",
976
+ asChild: true,
977
+ children: /* @__PURE__ */ jsx24("ol", {
978
+ style: {
979
+ listStylePosition: "inside"
980
+ },
981
+ children: children
982
+ })
1309
983
  });
1310
984
  };
1311
- // src/contexts/assistants/AssistantNameContext/index.tsx
1312
- import { createContext as createContext3 } from "react";
1313
- var AssistantNameContext = createContext3("Assistant");
1314
- // src/components/threadMessages/ThreadMessages/Content/ThreadMessageGroup/Content/index.tsx
1315
- import { Flex as Flex11 } from "@radix-ui/themes";
1316
- // src/components/ThreadMessages/ThreadMessage/index.tsx
1317
- import { useMemo as useMemo8 } from "react";
1318
- import { Box as Box7 } from "@radix-ui/themes";
1319
- // src/components/runSteps/RunSteps/index.tsx
1320
- import { Flex as Flex10 } from "@radix-ui/themes";
1321
- // src/components/runSteps/RunStep/ToolCalls/index.tsx
1322
- import { Flex as Flex9 } from "@radix-ui/themes";
1323
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx
1324
- import { Flex as Flex8 } from "@radix-ui/themes";
1325
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/index.tsx
1326
- import { useContext as useContext3 } from "react";
1327
- // src/contexts/functions/FunctionComponentsContext/index.tsx
1328
- import { createContext as createContext4 } from "react";
1329
- var FunctionComponentsContext = createContext4({});
1330
- // src/components/functions/FunctionBase/index.tsx
1331
- import { PopoverRoot, PopoverContent } from "@radix-ui/themes";
1332
- // src/components/toolCalls/ToolCallBase/index.tsx
1333
- import { Flex as Flex6, Button, PopoverTrigger } from "@radix-ui/themes";
1334
- import { jsx as jsx8 } from "react/jsx-runtime";
1335
- var ToolCallBase = function(param) {
985
+ // src/contexts/markdown/MarkdownContext/lib/components/ListItem.tsx
986
+ import { Box as Box6 } from "@radix-ui/themes";
987
+ import { jsx as jsx25 } from "react/jsx-runtime";
988
+ var ListItem = function(param) {
1336
989
  var children = param.children;
1337
- return /* @__PURE__ */ jsx8(Flex6, {
1338
- py: "1",
1339
- ml: "-2",
1340
- children: /* @__PURE__ */ jsx8(PopoverTrigger, {
1341
- children: /* @__PURE__ */ jsx8(Button, {
1342
- size: "1",
1343
- color: "gold",
1344
- variant: "outline",
1345
- style: {
1346
- boxShadow: "none"
1347
- },
1348
- children: children
1349
- })
990
+ return /* @__PURE__ */ jsx25(Box6, {
991
+ pb: "1",
992
+ children: /* @__PURE__ */ jsx25("li", {
993
+ children: children
1350
994
  })
1351
995
  });
1352
996
  };
1353
- // src/components/toolCalls/ToolCallBase/ToolCallTitle.tsx
1354
- import { Text as Text2 } from "@radix-ui/themes";
1355
- import { jsx as jsx9 } from "react/jsx-runtime";
1356
- var ToolCallTitle = function(param) {
997
+ // src/contexts/markdown/MarkdownContext/lib/components/Strong.tsx
998
+ import { Strong as RadixStrong } from "@radix-ui/themes";
999
+ import { jsx as jsx26 } from "react/jsx-runtime";
1000
+ var Strong = function(param) {
1357
1001
  var children = param.children;
1358
- return /* @__PURE__ */ jsx9(Text2, {
1359
- weight: "regular",
1002
+ return /* @__PURE__ */ jsx26(RadixStrong, {
1360
1003
  children: children
1361
1004
  });
1362
1005
  };
1363
- // src/components/functions/FunctionBase/Icon.tsx
1364
- import { CircleIcon, CircleBackslashIcon, CheckCircledIcon } from "@radix-ui/react-icons";
1365
- import { jsx as jsx10 } from "react/jsx-runtime";
1366
- var Icon = function(param) {
1367
- var runStep = param.runStep;
1368
- if (runStep.completed_at) {
1369
- return /* @__PURE__ */ jsx10(CheckCircledIcon, {});
1370
- } else if (runStep.cancelled_at || runStep.failed_at || runStep.status === "expired") {
1371
- return /* @__PURE__ */ jsx10(CircleBackslashIcon, {});
1372
- } else {
1373
- return /* @__PURE__ */ jsx10(CircleIcon, {});
1006
+ // src/contexts/markdown/MarkdownContext/lib/components/index.tsx
1007
+ var components = {
1008
+ p: Paragraph,
1009
+ a: Link,
1010
+ strong: Strong,
1011
+ ul: UnorderedList,
1012
+ ol: OrderedList,
1013
+ li: ListItem
1014
+ };
1015
+ // src/contexts/markdown/MarkdownContext/index.ts
1016
+ var MarkdownContext = createContext5({
1017
+ remarkPlugins: [],
1018
+ rehypeReactOptions: {
1019
+ components: components
1374
1020
  }
1021
+ });
1022
+ // src/components/threads/Thread/Message/TextContent/index.tsx
1023
+ var TextContent = function(param) {
1024
+ var content = param.content;
1025
+ var markdownContext = useContext4(MarkdownContext);
1026
+ return useRemarkSync(content.text.value, markdownContext);
1375
1027
  };
1376
- // src/components/functions/FunctionBase/Content.tsx
1377
- import { useMemo as useMemo7 } from "react";
1378
- import { Code, Box as Box2 } from "@radix-ui/themes";
1379
- import { jsx as jsx11, jsxs as jsxs2 } from "react/jsx-runtime";
1380
- var Content = function(param) {
1381
- var fn = param.fn;
1382
- var args = useMemo7(function() {
1383
- var result = null;
1384
- try {
1385
- result = JSON.parse(fn.arguments);
1386
- } catch (error) {
1387
- console.error(error);
1388
- }
1389
- return result;
1390
- }, [
1391
- fn
1392
- ]);
1393
- var output = useMemo7(function() {
1394
- if (!fn.output) {
1395
- return null;
1028
+ // src/components/threads/Thread/Message/index.tsx
1029
+ import { jsx as jsx27, jsxs as jsxs6 } from "react/jsx-runtime";
1030
+ var Message = function(param) {
1031
+ var message = param.message;
1032
+ var _useMemo4 = _sliced_to_array(useMemo4(function() {
1033
+ if (!message.runSteps.length) return [
1034
+ [],
1035
+ []
1036
+ ];
1037
+ var messageCreationRunStepIndex = message.runSteps.findIndex(function(runStep) {
1038
+ if (runStep.step_details.type !== "message_creation") return;
1039
+ return runStep.step_details.message_creation.message_id === message.id;
1040
+ });
1041
+ var nextRunStepIndex = message.runSteps.slice(0, messageCreationRunStepIndex).findLastIndex(function(runStep) {
1042
+ return runStep.step_details.type === "message_creation";
1043
+ });
1044
+ if (nextRunStepIndex === -1) {
1045
+ nextRunStepIndex = 0;
1396
1046
  }
1397
- var result = null;
1398
- try {
1399
- result = JSON.parse(fn.output);
1400
- } catch (error) {
1401
- console.error(error);
1047
+ var laterRunSteps2 = message.runSteps.slice(nextRunStepIndex, messageCreationRunStepIndex);
1048
+ var prevRunStepIndex = message.runSteps.slice(messageCreationRunStepIndex + 1).findIndex(function(runStep) {
1049
+ return runStep.step_details.type === "message_creation";
1050
+ });
1051
+ var olderRunSteps2;
1052
+ if (prevRunStepIndex === -1) {
1053
+ olderRunSteps2 = message.runSteps.slice(messageCreationRunStepIndex + 1);
1054
+ } else {
1055
+ olderRunSteps2 = message.runSteps.slice(messageCreationRunStepIndex + 1, messageCreationRunStepIndex + prevRunStepIndex);
1402
1056
  }
1403
- return result;
1057
+ return [
1058
+ olderRunSteps2,
1059
+ laterRunSteps2
1060
+ ];
1404
1061
  }, [
1405
- fn
1406
- ]);
1407
- if (!args) {
1408
- return null;
1409
- }
1410
- return /* @__PURE__ */ jsxs2(Code, {
1411
- variant: "ghost",
1412
- color: "gold",
1413
- style: {
1414
- whiteSpace: "pre",
1415
- wordBreak: "break-word"
1416
- },
1062
+ message
1063
+ ]), 2), olderRunSteps = _useMemo4[0], laterRunSteps = _useMemo4[1];
1064
+ return /* @__PURE__ */ jsxs6(Box7, {
1417
1065
  children: [
1418
- /* @__PURE__ */ jsx11(Box2, {
1419
- children: args && JSON.stringify(args, null, 2)
1066
+ /* @__PURE__ */ jsx27(RunSteps, {
1067
+ runSteps: olderRunSteps
1420
1068
  }),
1421
- /* @__PURE__ */ jsx11(Box2, {
1422
- children: output && JSON.stringify(output, null, 2)
1069
+ message.content.map(function(content, index) {
1070
+ return /* @__PURE__ */ jsx27(Box7, {
1071
+ children: content.type === "text" && /* @__PURE__ */ jsx27(TextContent, {
1072
+ content: content
1073
+ })
1074
+ }, index);
1075
+ }),
1076
+ /* @__PURE__ */ jsx27(RunSteps, {
1077
+ runSteps: laterRunSteps
1423
1078
  })
1424
1079
  ]
1425
1080
  });
1426
1081
  };
1427
- // src/components/functions/FunctionBase/index.tsx
1428
- import { jsx as jsx12, jsxs as jsxs3 } from "react/jsx-runtime";
1429
- var FunctionBase = function(param) {
1430
- var fn = param.fn, runStep = param.runStep, title2 = param.title;
1431
- return /* @__PURE__ */ jsxs3(PopoverRoot, {
1082
+ // src/components/threads/Thread/Messages/Content/MessageGroup/Content/index.tsx
1083
+ import { jsx as jsx28 } from "react/jsx-runtime";
1084
+ var Content2 = function(param) {
1085
+ var messageGroup = param.messageGroup;
1086
+ return /* @__PURE__ */ jsx28(Flex11, {
1087
+ direction: "column-reverse",
1088
+ children: messageGroup.messages.map(function(message) {
1089
+ return /* @__PURE__ */ jsx28(Message, {
1090
+ message: message
1091
+ }, message.id);
1092
+ })
1093
+ });
1094
+ };
1095
+ // src/components/threads/Thread/Messages/Content/MessageGroup/index.tsx
1096
+ import { jsx as jsx29, jsxs as jsxs7 } from "react/jsx-runtime";
1097
+ var MessageGroup = function(param) {
1098
+ var messageGroup = param.messageGroup;
1099
+ var assistantNameContext = useContext5(AssistantNameContext);
1100
+ return /* @__PURE__ */ jsxs7(MessageGroupBase, {
1432
1101
  children: [
1433
- /* @__PURE__ */ jsxs3(ToolCallBase, {
1102
+ messageGroup.role === "user" ? /* @__PURE__ */ jsx29(Avatar3, {
1103
+ fallback: /* @__PURE__ */ jsx29(PersonIcon, {}),
1104
+ size: "1"
1105
+ }) : /* @__PURE__ */ jsx29(AssistantAvatar, {}),
1106
+ /* @__PURE__ */ jsxs7(Box8, {
1107
+ flexGrow: "1",
1434
1108
  children: [
1435
- /* @__PURE__ */ jsx12(Icon, {
1436
- runStep: runStep
1109
+ /* @__PURE__ */ jsx29(Name, {
1110
+ children: messageGroup.role === "user" ? "You" : assistantNameContext
1437
1111
  }),
1438
- /* @__PURE__ */ jsx12(ToolCallTitle, {
1439
- children: title2
1112
+ /* @__PURE__ */ jsx29(Content2, {
1113
+ messageGroup: messageGroup
1440
1114
  })
1441
1115
  ]
1442
- }),
1443
- /* @__PURE__ */ jsx12(PopoverContent, {
1444
- style: {
1445
- maxHeight: "500px"
1446
- },
1447
- children: /* @__PURE__ */ jsx12(Content, {
1448
- fn: fn
1449
- })
1450
1116
  })
1451
1117
  ]
1452
1118
  });
1453
1119
  };
1454
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/DefaultFunction/lib/title.ts
1455
- var title = function(param) {
1456
- var fn = param.fn, runStep = param.runStep;
1457
- if (runStep.completed_at) {
1458
- return "Finished ".concat(fn.name);
1459
- } else if (runStep.cancelled_at) {
1460
- return "Cancelled ".concat(fn.name);
1461
- } else {
1462
- return "Calling ".concat(fn.name);
1120
+ // src/components/threads/Thread/Messages/Content/index.tsx
1121
+ import { Fragment, jsx as jsx30 } from "react/jsx-runtime";
1122
+ var Content3 = function() {
1123
+ var _useMessages = useMessages(), messages2 = _useMessages.messages, isLoading = _useMessages.isLoading, isLoadingError = _useMessages.isLoadingError;
1124
+ var _useMessageGroups = useMessageGroups({
1125
+ messages: messages2
1126
+ }), messageGroups2 = _useMessageGroups.messageGroups;
1127
+ if (isLoading || isLoadingError) {
1128
+ return /* @__PURE__ */ jsx30(MessagesSkeleton, {});
1463
1129
  }
1464
- };
1465
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/DefaultFunction/index.tsx
1466
- import { jsx as jsx13 } from "react/jsx-runtime";
1467
- var DefaultFunction = function(param) {
1468
- var fn = param.fn, runStep = param.runStep;
1469
- return /* @__PURE__ */ jsx13(FunctionBase, {
1470
- fn: fn,
1471
- runStep: runStep,
1472
- title: title({
1473
- runStep: runStep,
1474
- fn: fn
1130
+ return /* @__PURE__ */ jsx30(Fragment, {
1131
+ children: messageGroups2.map(function(messageGroup) {
1132
+ return /* @__PURE__ */ jsx30(MessageGroup, {
1133
+ messageGroup: messageGroup
1134
+ }, messageGroup.id);
1475
1135
  })
1476
1136
  });
1477
1137
  };
1478
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/index.tsx
1479
- import { jsx as jsx14 } from "react/jsx-runtime";
1480
- var Fn = function(param) {
1481
- var fn = param.fn, runStep = param.runStep;
1482
- var functionComponentsContext = useContext3(FunctionComponentsContext);
1483
- var Component = functionComponentsContext[fn.name] || DefaultFunction;
1484
- return(// @ts-ignore-next-line
1485
- /* @__PURE__ */ jsx14(Component, {
1486
- fn: fn,
1487
- runStep: runStep
1488
- }));
1138
+ // src/components/threads/Thread/Messages/Progress/index.tsx
1139
+ import { Box as Box11 } from "@radix-ui/themes";
1140
+ // src/components/skeletons/StartingContentSkeleton/index.tsx
1141
+ import { Box as Box9 } from "@radix-ui/themes";
1142
+ import { jsx as jsx31 } from "react/jsx-runtime";
1143
+ var StartingContentSkeleton = function() {
1144
+ return /* @__PURE__ */ jsx31(Box9, {
1145
+ flexShrink: "0",
1146
+ mt: "1",
1147
+ height: "var(--space-4)",
1148
+ width: "var(--space-4)",
1149
+ style: {
1150
+ animation: "pulse 2s cubic-bezier(.4,0,.6,1) infinite",
1151
+ borderRadius: "var(--radius-3)",
1152
+ backgroundColor: "var(--gray-12)"
1153
+ }
1154
+ });
1489
1155
  };
1490
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/CodeInterpreter/index.tsx
1491
- import { Flex as Flex7 } from "@radix-ui/themes";
1492
- import { jsx as jsx15 } from "react/jsx-runtime";
1493
- var CodeInterpreter = function(param) {
1494
- var codeInterpreter = param.codeInterpreter;
1495
- return /* @__PURE__ */ jsx15(Flex7, {
1496
- children: codeInterpreter.input
1156
+ // src/components/skeletons/StartingSkeleton/index.tsx
1157
+ import { useContext as useContext6 } from "react";
1158
+ import { Box as Box10 } from "@radix-ui/themes";
1159
+ import { jsx as jsx32, jsxs as jsxs8 } from "react/jsx-runtime";
1160
+ var StartingSkeleton = function(param) {
1161
+ var children = param.children;
1162
+ var assistantNameContext = useContext6(AssistantNameContext);
1163
+ return /* @__PURE__ */ jsxs8(MessageGroupBase, {
1164
+ children: [
1165
+ /* @__PURE__ */ jsx32(AssistantAvatar, {}),
1166
+ /* @__PURE__ */ jsxs8(Box10, {
1167
+ children: [
1168
+ /* @__PURE__ */ jsx32(Name, {
1169
+ children: assistantNameContext
1170
+ }),
1171
+ children,
1172
+ /* @__PURE__ */ jsx32(StartingContentSkeleton, {})
1173
+ ]
1174
+ })
1175
+ ]
1497
1176
  });
1498
1177
  };
1499
- // src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx
1500
- import { jsx as jsx16 } from "react/jsx-runtime";
1501
- var ToolCall = function(param) {
1502
- var toolCall = param.toolCall, runStep = param.runStep;
1503
- if (toolCall.type === "function") {
1504
- return /* @__PURE__ */ jsx16(Fn, {
1505
- fn: toolCall.function,
1506
- runStep: runStep
1178
+ // src/hooks/messages/useLatestMessage/index.ts
1179
+ import { useMemo as useMemo5 } from "react";
1180
+ var useLatestMessage = function() {
1181
+ var props = useMessages();
1182
+ return useMemo5(function() {
1183
+ return _object_spread_props(_object_spread({}, props), {
1184
+ latestMessage: props.messages[0] || null
1507
1185
  });
1508
- }
1509
- if (toolCall.type === "code_interpreter") {
1510
- return /* @__PURE__ */ jsx16(CodeInterpreter, {
1511
- codeInterpreter: toolCall.code_interpreter,
1512
- runStep: runStep
1186
+ }, [
1187
+ props
1188
+ ]);
1189
+ };
1190
+ // src/hooks/runs/useIsRunActive/index.tsx
1191
+ import { useMemo as useMemo8 } from "react";
1192
+ import { useIsMutating } from "@tanstack/react-query";
1193
+ // src/hooks/runs/useLatestRun/index.ts
1194
+ import { useMemo as useMemo7 } from "react";
1195
+ // src/hooks/runs/useRuns/index.tsx
1196
+ import { useMemo as useMemo6 } from "react";
1197
+ import { useInfiniteQuery as useInfiniteQuery2, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
1198
+ // src/hooks/runs/useRuns/lib/getRuns.ts
1199
+ var getRuns = function(param) {
1200
+ var data3 = param.data;
1201
+ if (!data3) return [];
1202
+ return data3.pages.reduce(function(acc, page) {
1203
+ return acc.concat(page.data);
1204
+ }, []);
1205
+ };
1206
+ // src/hooks/runs/useRuns/index.tsx
1207
+ var useRuns = function() {
1208
+ var queryClient = useQueryClient3();
1209
+ var superinterfaceContext = useSuperinterfaceContext();
1210
+ var threadContext = useSuperinterfaceContext();
1211
+ var props = useInfiniteQuery2(queryOptions({
1212
+ queryKeyBase: [
1213
+ "runs"
1214
+ ],
1215
+ path: "/runs",
1216
+ queryClient: queryClient,
1217
+ threadContext: threadContext,
1218
+ superinterfaceContext: superinterfaceContext
1219
+ }));
1220
+ return useMemo6(function() {
1221
+ return _object_spread_props(_object_spread({}, props), {
1222
+ // @ts-ignore-next-line
1223
+ runs: getRuns({
1224
+ data: props.data
1225
+ })
1513
1226
  });
1514
- }
1515
- return /* @__PURE__ */ jsx16(Flex8, {
1516
- children: toolCall.type
1227
+ }, [
1228
+ props
1229
+ ]);
1230
+ };
1231
+ // src/hooks/runs/useLatestRun/index.ts
1232
+ var useLatestRun = function() {
1233
+ var props = useRuns();
1234
+ return useMemo7(function() {
1235
+ return _object_spread_props(_object_spread({}, props), {
1236
+ latestRun: props.runs[0]
1237
+ });
1238
+ }, [
1239
+ props
1240
+ ]);
1241
+ };
1242
+ // src/lib/runs/isRunEditingMessage/index.ts
1243
+ import _4 from "lodash";
1244
+ var isRunEditingMessage = function(param) {
1245
+ var message = param.message;
1246
+ if (!message) return false;
1247
+ if (message.role === "user") return false;
1248
+ if (!message.run_id) return false;
1249
+ var hasContent = _4.some(message.content, function(content) {
1250
+ var _content_text;
1251
+ return content.type !== "text" || content.type === "text" && ((_content_text = content.text) === null || _content_text === void 0 ? void 0 : _content_text.value) !== "";
1252
+ });
1253
+ return !hasContent;
1254
+ };
1255
+ // src/hooks/runs/useIsRunActive/index.tsx
1256
+ var progressStatuses = [
1257
+ "queued",
1258
+ "in_progress",
1259
+ "cancelling",
1260
+ "requires_action"
1261
+ ];
1262
+ var stoppedStatuses = [
1263
+ "expired",
1264
+ "cancelled",
1265
+ "failed"
1266
+ ];
1267
+ var isRunActive = function(param) {
1268
+ var latestRunProps = param.latestRunProps, latestMessageProps = param.latestMessageProps, isMutating = param.isMutating;
1269
+ var _latestMessageProps_latestMessage_metadata, _latestMessageProps_latestMessage;
1270
+ if ((_latestMessageProps_latestMessage = latestMessageProps.latestMessage) === null || _latestMessageProps_latestMessage === void 0 ? void 0 : (_latestMessageProps_latestMessage_metadata = _latestMessageProps_latestMessage.metadata) === null || _latestMessageProps_latestMessage_metadata === void 0 ? void 0 : _latestMessageProps_latestMessage_metadata.isBlocking) return false;
1271
+ if (isMutating) return true;
1272
+ if (!latestRunProps.latestRun) return false;
1273
+ if (progressStatuses.includes(latestRunProps.latestRun.status)) return true;
1274
+ if (stoppedStatuses.includes(latestRunProps.latestRun.status)) return false;
1275
+ return isRunEditingMessage({
1276
+ message: latestMessageProps.latestMessage
1277
+ });
1278
+ };
1279
+ var useIsRunActive = function() {
1280
+ var latestRunProps = useLatestRun();
1281
+ var latestMessageProps = useLatestMessage();
1282
+ var threadContext = useSuperinterfaceContext();
1283
+ var isMutatingCreateRun = useIsMutating({
1284
+ mutationKey: [
1285
+ "createRun",
1286
+ threadContext.variables
1287
+ ]
1288
+ });
1289
+ var isMutatingCreateMessage = useIsMutating({
1290
+ mutationKey: [
1291
+ "createMessage",
1292
+ threadContext.variables
1293
+ ]
1294
+ });
1295
+ var isMutatingCreateHandleAction = useIsMutating({
1296
+ mutationKey: [
1297
+ "handleAction",
1298
+ threadContext.variables
1299
+ ]
1517
1300
  });
1301
+ return useMemo8(function() {
1302
+ return _object_spread_props(_object_spread({}, latestRunProps), {
1303
+ isRunActive: isRunActive({
1304
+ latestRunProps: latestRunProps,
1305
+ latestMessageProps: latestMessageProps,
1306
+ isMutating: isMutatingCreateRun > 0 || isMutatingCreateMessage > 0 || isMutatingCreateHandleAction > 0
1307
+ })
1308
+ });
1309
+ }, [
1310
+ latestRunProps,
1311
+ latestMessageProps,
1312
+ isMutatingCreateRun,
1313
+ isMutatingCreateMessage,
1314
+ isMutatingCreateHandleAction
1315
+ ]);
1518
1316
  };
1519
- // src/components/runSteps/RunStep/ToolCalls/Starting/index.tsx
1520
- import { PopoverRoot as PopoverRoot2, PopoverContent as PopoverContent2, Text as Text3 } from "@radix-ui/themes";
1521
- import { CircleIcon as CircleIcon2 } from "@radix-ui/react-icons";
1522
- import { jsx as jsx17, jsxs as jsxs4 } from "react/jsx-runtime";
1523
- var Starting = function() {
1524
- return /* @__PURE__ */ jsxs4(PopoverRoot2, {
1317
+ // src/components/threads/Thread/Messages/Progress/index.tsx
1318
+ import { jsx as jsx33, jsxs as jsxs9 } from "react/jsx-runtime";
1319
+ var Progress = function() {
1320
+ var _useIsRunActive = useIsRunActive(), isRunActive2 = _useIsRunActive.isRunActive;
1321
+ var latestMessage = useLatestMessage().latestMessage;
1322
+ if (!latestMessage) return null;
1323
+ if (!isRunActive2) return null;
1324
+ if (latestMessage.role === "user") {
1325
+ return /* @__PURE__ */ jsx33(StartingSkeleton, {});
1326
+ }
1327
+ return /* @__PURE__ */ jsxs9(MessageGroupBase, {
1525
1328
  children: [
1526
- /* @__PURE__ */ jsxs4(ToolCallBase, {
1527
- children: [
1528
- /* @__PURE__ */ jsx17(CircleIcon2, {}),
1529
- /* @__PURE__ */ jsx17(ToolCallTitle, {
1530
- children: "Starting actions"
1531
- })
1532
- ]
1329
+ /* @__PURE__ */ jsx33(Box11, {
1330
+ pl: "5"
1533
1331
  }),
1534
- /* @__PURE__ */ jsx17(PopoverContent2, {
1535
- style: {
1536
- maxHeight: "500px"
1537
- },
1538
- children: /* @__PURE__ */ jsx17(Text3, {
1539
- children: "Getting ready to connect to domain API"
1540
- })
1541
- })
1332
+ /* @__PURE__ */ jsx33(StartingContentSkeleton, {})
1542
1333
  ]
1543
1334
  });
1544
1335
  };
1545
- // src/components/runSteps/RunStep/ToolCalls/index.tsx
1546
- import { jsx as jsx18, jsxs as jsxs5 } from "react/jsx-runtime";
1547
- var ToolCalls = function(param) {
1548
- var stepDetails = param.stepDetails, runStep = param.runStep;
1549
- return /* @__PURE__ */ jsxs5(Flex9, {
1550
- direction: "column",
1551
- children: [
1552
- !stepDetails.tool_calls.length && /* @__PURE__ */ jsx18(Starting, {}),
1553
- stepDetails.tool_calls.map(function(toolCall) {
1554
- return /* @__PURE__ */ jsx18(ToolCall, {
1555
- toolCall: toolCall,
1556
- runStep: runStep
1557
- }, toolCall.id);
1558
- })
1559
- ]
1336
+ // src/components/threads/Thread/Messages/Root/index.tsx
1337
+ import { Flex as Flex12 } from "@radix-ui/themes";
1338
+ // src/hooks/misc/useInfiniteScroll/index.tsx
1339
+ import { useRef as useRef2 } from "react";
1340
+ import { useInView } from "react-intersection-observer";
1341
+ // src/hooks/misc/useThrottledEffect/index.tsx
1342
+ import _5 from "lodash";
1343
+ import { useRef, useEffect, useCallback } from "react";
1344
+ var useThrottledEffect = function(cb, delay, additionalDeps) {
1345
+ var _cbRef;
1346
+ var cbRef = useRef(cb);
1347
+ var throttledCb = useCallback(_5.throttle(function() {
1348
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1349
+ args[_key] = arguments[_key];
1350
+ }
1351
+ return (_cbRef = cbRef).current.apply(_cbRef, _to_consumable_array(args));
1352
+ }, delay, {
1353
+ leading: true,
1354
+ trailing: true
1355
+ }), [
1356
+ delay
1357
+ ]);
1358
+ useEffect(function() {
1359
+ cbRef.current = cb;
1560
1360
  });
1361
+ useEffect(throttledCb, [
1362
+ throttledCb
1363
+ ].concat(_to_consumable_array(additionalDeps)));
1561
1364
  };
1562
- // src/components/runSteps/RunStep/index.tsx
1563
- import { jsx as jsx19 } from "react/jsx-runtime";
1564
- var RunStep = function(param) {
1565
- var runStep = param.runStep;
1566
- if (runStep.step_details.type === "tool_calls") {
1567
- return /* @__PURE__ */ jsx19(ToolCalls, {
1568
- stepDetails: runStep.step_details,
1569
- runStep: runStep
1365
+ // src/hooks/misc/useInfiniteScroll/index.tsx
1366
+ var useInfiniteScroll = function(param) {
1367
+ var isFetchingNextPage = param.isFetchingNextPage, hasNextPage = param.hasNextPage, fetchNextPage = param.fetchNextPage;
1368
+ var containerRef = useRef2(null);
1369
+ var _useInView = useInView({
1370
+ root: containerRef.current,
1371
+ rootMargin: "0px",
1372
+ threshold: 0.1
1373
+ }), loaderRef = _useInView.ref, inView = _useInView.inView;
1374
+ useThrottledEffect(function() {
1375
+ if (isFetchingNextPage) return;
1376
+ if (!inView) return;
1377
+ if (!hasNextPage) return;
1378
+ console.log("Fetching next page");
1379
+ fetchNextPage();
1380
+ }, 500, [
1381
+ inView,
1382
+ isFetchingNextPage,
1383
+ hasNextPage,
1384
+ fetchNextPage
1385
+ ]);
1386
+ return {
1387
+ containerRef: containerRef,
1388
+ loaderRef: loaderRef,
1389
+ inView: inView
1390
+ };
1391
+ };
1392
+ // src/hooks/runs/useManageRuns/index.tsx
1393
+ import { useQueryClient as useQueryClient5 } from "@tanstack/react-query";
1394
+ import { useEffect as useEffect2 } from "react";
1395
+ // src/hooks/runs/useCreateRun/index.ts
1396
+ import { partob } from "radash";
1397
+ import { useMutation, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
1398
+ // src/lib/threads/mutationOptions/index.ts
1399
+ var mutationOptions = function(param) {
1400
+ var mutationKeyBase = param.mutationKeyBase, path = param.path, queryClient = param.queryClient, threadContext = param.threadContext, superinterfaceContext = param.superinterfaceContext;
1401
+ var mutationKey = _to_consumable_array(mutationKeyBase).concat([
1402
+ threadContext.variables
1403
+ ]);
1404
+ return _object_spread(_object_spread_props(_object_spread({
1405
+ mutationFn: function(variables) {
1406
+ return fetch("".concat(superinterfaceContext.baseUrl).concat(path), _object_spread({
1407
+ method: "POST",
1408
+ body: JSON.stringify(variables),
1409
+ credentials: "include"
1410
+ }, superinterfaceContext.publicApiKey ? {
1411
+ headers: {
1412
+ Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
1413
+ }
1414
+ } : {})).then(function() {
1415
+ var _ref = _async_to_generator(function(response) {
1416
+ var errorResponse, error;
1417
+ return _ts_generator(this, function(_state) {
1418
+ switch(_state.label){
1419
+ case 0:
1420
+ if (!(response.status !== 200)) return [
1421
+ 3,
1422
+ 4
1423
+ ];
1424
+ _state.label = 1;
1425
+ case 1:
1426
+ _state.trys.push([
1427
+ 1,
1428
+ 3,
1429
+ ,
1430
+ 4
1431
+ ]);
1432
+ return [
1433
+ 4,
1434
+ response.json()
1435
+ ];
1436
+ case 2:
1437
+ errorResponse = _state.sent();
1438
+ throw new Error(errorResponse.error);
1439
+ case 3:
1440
+ error = _state.sent();
1441
+ throw new Error("Failed to fetch");
1442
+ case 4:
1443
+ return [
1444
+ 2,
1445
+ response.json()
1446
+ ];
1447
+ }
1448
+ });
1449
+ });
1450
+ return function(response) {
1451
+ return _ref.apply(this, arguments);
1452
+ };
1453
+ }());
1454
+ }
1455
+ }, queryClient.getMutationDefaults(mutationKey)), {
1456
+ mutationKey: mutationKey
1457
+ }), threadContext.defaultOptions.mutations);
1458
+ };
1459
+ // src/hooks/runs/useCreateRun/lib/onSuccess.ts
1460
+ var onSuccess = function(param) {
1461
+ var queryClient = param.queryClient;
1462
+ return function() {
1463
+ var _ref = _async_to_generator(function(data3, variables) {
1464
+ return _ts_generator(this, function(_state) {
1465
+ return [
1466
+ 2,
1467
+ queryClient.setQueryData([
1468
+ "runs",
1469
+ variables
1470
+ ], function(prevData) {
1471
+ if (!prevData) {
1472
+ return {
1473
+ pageParams: [],
1474
+ pages: [
1475
+ {
1476
+ data: [
1477
+ data3.run
1478
+ ],
1479
+ hasNextPage: false,
1480
+ lastId: data3.run.id
1481
+ }
1482
+ ]
1483
+ };
1484
+ }
1485
+ var _prevData_pages = _to_array(prevData.pages), latestPage = _prevData_pages[0], pagesRest = _prevData_pages.slice(1);
1486
+ return _object_spread_props(_object_spread({}, prevData), {
1487
+ pages: [
1488
+ _object_spread_props(_object_spread({}, latestPage), {
1489
+ data: [
1490
+ data3.run
1491
+ ].concat(_to_consumable_array(latestPage.data))
1492
+ })
1493
+ ].concat(_to_consumable_array(pagesRest))
1494
+ });
1495
+ })
1496
+ ];
1497
+ });
1498
+ });
1499
+ return function(data3, variables) {
1500
+ return _ref.apply(this, arguments);
1501
+ };
1502
+ }();
1503
+ };
1504
+ // src/hooks/runs/useCreateRun/lib/onSettled.ts
1505
+ var onSettled = function(param) {
1506
+ var queryClient = param.queryClient;
1507
+ return function() {
1508
+ var _ref = _async_to_generator(function(_data, _error, variables) {
1509
+ return _ts_generator(this, function(_state) {
1510
+ switch(_state.label){
1511
+ case 0:
1512
+ return [
1513
+ 4,
1514
+ queryClient.invalidateQueries({
1515
+ queryKey: [
1516
+ "messages",
1517
+ variables
1518
+ ]
1519
+ })
1520
+ ];
1521
+ case 1:
1522
+ _state.sent();
1523
+ return [
1524
+ 4,
1525
+ queryClient.invalidateQueries({
1526
+ queryKey: [
1527
+ "runs",
1528
+ variables
1529
+ ]
1530
+ })
1531
+ ];
1532
+ case 2:
1533
+ _state.sent();
1534
+ return [
1535
+ 2
1536
+ ];
1537
+ }
1538
+ });
1570
1539
  });
1571
- }
1572
- return null;
1573
- };
1574
- // src/components/runSteps/RunSteps/index.tsx
1575
- import { jsx as jsx20 } from "react/jsx-runtime";
1576
- var RunSteps = function(param) {
1577
- var runSteps = param.runSteps;
1578
- return /* @__PURE__ */ jsx20(Flex10, {
1579
- direction: "column-reverse",
1580
- children: runSteps.map(function(runStep) {
1581
- return /* @__PURE__ */ jsx20(RunStep, {
1582
- runStep: runStep
1583
- }, runStep.id);
1584
- })
1585
- });
1586
- };
1587
- // src/components/ThreadMessages/ThreadMessage/TextContent/index.tsx
1588
- import { useContext as useContext4 } from "react";
1589
- import { useRemarkSync } from "react-remark";
1590
- // src/contexts/markdown/MarkdownContext/index.ts
1591
- import { createContext as createContext5 } from "react";
1592
- // src/contexts/markdown/MarkdownContext/lib/components/Paragraph.tsx
1593
- import { Box as Box3, Text as Text4 } from "@radix-ui/themes";
1594
- import { jsx as jsx21 } from "react/jsx-runtime";
1595
- var Paragraph = function(param) {
1596
- var children = param.children;
1597
- return /* @__PURE__ */ jsx21(Box3, {
1598
- pb: "3",
1599
- children: /* @__PURE__ */ jsx21(Text4, {
1600
- size: "3",
1601
- style: {
1602
- whiteSpace: "pre-line",
1603
- wordBreak: "break-word"
1604
- },
1605
- children: children
1606
- })
1607
- });
1540
+ return function(_data, _error, variables) {
1541
+ return _ref.apply(this, arguments);
1542
+ };
1543
+ }();
1608
1544
  };
1609
- // src/contexts/markdown/MarkdownContext/lib/components/Link.tsx
1610
- import { Link as RadixLink } from "@radix-ui/themes";
1611
- import { jsx as jsx22 } from "react/jsx-runtime";
1612
- var Link = function(param) {
1613
- var children = param.children, href = param.href;
1614
- return /* @__PURE__ */ jsx22(RadixLink, {
1615
- href: href,
1616
- children: children
1617
- });
1545
+ // src/lib/optimistic/optimisticId.ts
1546
+ import { uid } from "radash";
1547
+ var optimisticId = function() {
1548
+ return "-".concat(uid(24));
1618
1549
  };
1619
- // src/contexts/markdown/MarkdownContext/lib/components/UnorderedList.tsx
1620
- import { Box as Box4 } from "@radix-ui/themes";
1621
- import { jsx as jsx23 } from "react/jsx-runtime";
1622
- var UnorderedList = function(param) {
1623
- var children = param.children;
1624
- return /* @__PURE__ */ jsx23(Box4, {
1625
- pb: "3",
1626
- asChild: true,
1627
- children: /* @__PURE__ */ jsx23("ul", {
1628
- style: {
1629
- listStylePosition: "inside"
1630
- },
1631
- children: children
1632
- })
1550
+ // src/hooks/runs/useCreateRun/lib/onMutate/data.ts
1551
+ var data = function(prevData) {
1552
+ var run = {
1553
+ id: optimisticId(),
1554
+ object: "thread.run",
1555
+ created_at: +/* @__PURE__ */ new Date(),
1556
+ assistant_id: null,
1557
+ thread_id: null,
1558
+ status: "in_progress",
1559
+ expires_at: +/* @__PURE__ */ new Date() + 1e3 * 60 * 60 * 24,
1560
+ cancelled_at: null,
1561
+ failed_at: null,
1562
+ completed_at: null,
1563
+ required_action: null,
1564
+ last_error: null,
1565
+ model: null,
1566
+ instructions: null,
1567
+ tools: [],
1568
+ file_ids: [],
1569
+ metadata: {},
1570
+ usage: null
1571
+ };
1572
+ if (!prevData) {
1573
+ return {
1574
+ pageParams: [],
1575
+ pages: [
1576
+ {
1577
+ data: [
1578
+ run
1579
+ ],
1580
+ hasNextPage: false,
1581
+ lastId: run.id
1582
+ }
1583
+ ]
1584
+ };
1585
+ }
1586
+ var _prevData_pages = _to_array(prevData.pages), latestPage = _prevData_pages[0], pagesRest = _prevData_pages.slice(1);
1587
+ return _object_spread_props(_object_spread({}, prevData), {
1588
+ pages: [
1589
+ _object_spread_props(_object_spread({}, latestPage), {
1590
+ data: [
1591
+ run
1592
+ ].concat(_to_consumable_array(latestPage.data))
1593
+ })
1594
+ ].concat(_to_consumable_array(pagesRest))
1633
1595
  });
1634
1596
  };
1635
- // src/contexts/markdown/MarkdownContext/lib/components/OrderedList.tsx
1636
- import { Box as Box5 } from "@radix-ui/themes";
1637
- import { jsx as jsx24 } from "react/jsx-runtime";
1638
- var OrderedList = function(param) {
1639
- var children = param.children;
1640
- return /* @__PURE__ */ jsx24(Box5, {
1641
- pb: "3",
1642
- asChild: true,
1643
- children: /* @__PURE__ */ jsx24("ol", {
1644
- style: {
1645
- listStylePosition: "inside"
1646
- },
1647
- children: children
1648
- })
1649
- });
1597
+ // src/hooks/runs/useCreateRun/lib/onMutate/index.ts
1598
+ var onMutate = function(param) {
1599
+ var queryClient = param.queryClient;
1600
+ return function() {
1601
+ var _ref = _async_to_generator(function(variables) {
1602
+ var queryKey, prevRuns;
1603
+ return _ts_generator(this, function(_state) {
1604
+ switch(_state.label){
1605
+ case 0:
1606
+ queryKey = [
1607
+ "runs",
1608
+ variables
1609
+ ];
1610
+ return [
1611
+ 4,
1612
+ queryClient.cancelQueries({
1613
+ queryKey: queryKey
1614
+ })
1615
+ ];
1616
+ case 1:
1617
+ _state.sent();
1618
+ prevRuns = queryClient.getQueryData(queryKey);
1619
+ queryClient.setQueryData(queryKey, data);
1620
+ return [
1621
+ 2,
1622
+ {
1623
+ prevRuns: prevRuns,
1624
+ variables: variables
1625
+ }
1626
+ ];
1627
+ }
1628
+ });
1629
+ });
1630
+ return function(variables) {
1631
+ return _ref.apply(this, arguments);
1632
+ };
1633
+ }();
1650
1634
  };
1651
- // src/contexts/markdown/MarkdownContext/lib/components/ListItem.tsx
1652
- import { Box as Box6 } from "@radix-ui/themes";
1653
- import { jsx as jsx25 } from "react/jsx-runtime";
1654
- var ListItem = function(param) {
1655
- var children = param.children;
1656
- return /* @__PURE__ */ jsx25(Box6, {
1657
- pb: "1",
1658
- children: /* @__PURE__ */ jsx25("li", {
1659
- children: children
1635
+ // src/hooks/runs/useCreateRun/index.ts
1636
+ var useCreateRun = function() {
1637
+ var queryClient = useQueryClient4();
1638
+ var superinterfaceContext = useSuperinterfaceContext();
1639
+ var threadContext = useSuperinterfaceContext();
1640
+ var props = useMutation(_object_spread({
1641
+ onSuccess: onSuccess({
1642
+ queryClient: queryClient
1643
+ }),
1644
+ onSettled: onSettled({
1645
+ queryClient: queryClient
1646
+ }),
1647
+ onMutate: onMutate({
1648
+ queryClient: queryClient
1660
1649
  })
1650
+ }, mutationOptions({
1651
+ mutationKeyBase: [
1652
+ "createRun"
1653
+ ],
1654
+ path: "/runs",
1655
+ queryClient: queryClient,
1656
+ threadContext: threadContext,
1657
+ superinterfaceContext: superinterfaceContext
1658
+ })));
1659
+ return _object_spread_props(_object_spread({}, props), {
1660
+ createRun: partob(props.mutate, threadContext.variables)
1661
1661
  });
1662
1662
  };
1663
- // src/contexts/markdown/MarkdownContext/lib/components/Strong.tsx
1664
- import { Strong as RadixStrong } from "@radix-ui/themes";
1665
- import { jsx as jsx26 } from "react/jsx-runtime";
1666
- var Strong = function(param) {
1667
- var children = param.children;
1668
- return /* @__PURE__ */ jsx26(RadixStrong, {
1669
- children: children
1670
- });
1671
- };
1672
- // src/contexts/markdown/MarkdownContext/lib/components/index.tsx
1673
- var components = {
1674
- p: Paragraph,
1675
- a: Link,
1676
- strong: Strong,
1677
- ul: UnorderedList,
1678
- ol: OrderedList,
1679
- li: ListItem
1680
- };
1681
- // src/contexts/markdown/MarkdownContext/index.ts
1682
- var MarkdownContext = createContext5({
1683
- remarkPlugins: [],
1684
- rehypeReactOptions: {
1685
- components: components
1686
- }
1687
- });
1688
- // src/components/ThreadMessages/ThreadMessage/TextContent/index.tsx
1689
- var TextContent = function(param) {
1690
- var content = param.content;
1691
- var markdownContext = useContext4(MarkdownContext);
1692
- return useRemarkSync(content.text.value, markdownContext);
1663
+ // src/lib/optimistic/isOptimistic.ts
1664
+ import _6 from "lodash";
1665
+ var isOptimistic = function(param) {
1666
+ var id = param.id;
1667
+ return _6.startsWith(id, "-");
1693
1668
  };
1694
- // src/components/ThreadMessages/ThreadMessage/index.tsx
1695
- import { jsx as jsx27, jsxs as jsxs6 } from "react/jsx-runtime";
1696
- var ThreadMessage = function(param) {
1697
- var threadMessage = param.threadMessage;
1698
- var _useMemo8 = _sliced_to_array(useMemo8(function() {
1699
- if (!threadMessage.runSteps.length) return [
1700
- [],
1701
- []
1702
- ];
1703
- var messageCreationRunStepIndex = threadMessage.runSteps.findIndex(function(runStep) {
1704
- if (runStep.step_details.type !== "message_creation") return;
1705
- return runStep.step_details.message_creation.message_id === threadMessage.id;
1706
- });
1707
- var nextRunStepIndex = threadMessage.runSteps.slice(0, messageCreationRunStepIndex).findLastIndex(function(runStep) {
1708
- return runStep.step_details.type === "message_creation";
1709
- });
1710
- if (nextRunStepIndex === -1) {
1711
- nextRunStepIndex = 0;
1669
+ // src/hooks/runs/useManageRuns/index.tsx
1670
+ var useManageRuns = function() {
1671
+ var queryClient = useQueryClient5();
1672
+ var latestRunProps = useLatestRun();
1673
+ var latestMessageProps = useLatestMessage();
1674
+ var createRunProps = useCreateRun();
1675
+ var threadContext = useSuperinterfaceContext();
1676
+ useEffect2(function() {
1677
+ if (createRunProps.isPending) return;
1678
+ if (latestRunProps.isFetching) return;
1679
+ if (latestMessageProps.isFetching) return;
1680
+ if (!latestMessageProps.latestMessage) return;
1681
+ if (latestMessageProps.latestMessage.role !== "user") return;
1682
+ if (isOptimistic({
1683
+ id: latestMessageProps.latestMessage.id
1684
+ })) return;
1685
+ if (latestRunProps.latestRun && latestRunProps.latestRun.created_at > latestMessageProps.latestMessage.created_at) {
1686
+ return;
1712
1687
  }
1713
- var laterRunSteps2 = threadMessage.runSteps.slice(nextRunStepIndex, messageCreationRunStepIndex);
1714
- var prevRunStepIndex = threadMessage.runSteps.slice(messageCreationRunStepIndex + 1).findIndex(function(runStep) {
1715
- return runStep.step_details.type === "message_creation";
1688
+ var isMutating = queryClient.isMutating({
1689
+ mutationKey: [
1690
+ "createRun",
1691
+ threadContext.variables
1692
+ ]
1716
1693
  });
1717
- var olderRunSteps2;
1718
- if (prevRunStepIndex === -1) {
1719
- olderRunSteps2 = threadMessage.runSteps.slice(messageCreationRunStepIndex + 1);
1720
- } else {
1721
- olderRunSteps2 = threadMessage.runSteps.slice(messageCreationRunStepIndex + 1, messageCreationRunStepIndex + prevRunStepIndex);
1722
- }
1723
- return [
1724
- olderRunSteps2,
1725
- laterRunSteps2
1726
- ];
1694
+ if (isMutating) return;
1695
+ createRunProps.createRun();
1727
1696
  }, [
1728
- threadMessage
1729
- ]), 2), olderRunSteps = _useMemo8[0], laterRunSteps = _useMemo8[1];
1730
- return /* @__PURE__ */ jsxs6(Box7, {
1731
- children: [
1732
- /* @__PURE__ */ jsx27(RunSteps, {
1733
- runSteps: olderRunSteps
1734
- }),
1735
- threadMessage.content.map(function(content, index) {
1736
- return /* @__PURE__ */ jsx27(Box7, {
1737
- children: content.type === "text" && /* @__PURE__ */ jsx27(TextContent, {
1738
- content: content
1739
- })
1740
- }, index);
1741
- }),
1742
- /* @__PURE__ */ jsx27(RunSteps, {
1743
- runSteps: laterRunSteps
1744
- })
1745
- ]
1746
- });
1697
+ threadContext,
1698
+ queryClient,
1699
+ createRunProps,
1700
+ latestRunProps,
1701
+ latestMessageProps
1702
+ ]);
1703
+ return null;
1747
1704
  };
1748
- // src/components/threadMessages/ThreadMessages/Content/ThreadMessageGroup/Content/index.tsx
1749
- import { jsx as jsx28 } from "react/jsx-runtime";
1750
- var Content2 = function(param) {
1751
- var threadMessageGroup = param.threadMessageGroup;
1752
- return /* @__PURE__ */ jsx28(Flex11, {
1753
- direction: "column-reverse",
1754
- children: threadMessageGroup.threadMessages.map(function(threadMessage) {
1755
- return /* @__PURE__ */ jsx28(ThreadMessage, {
1756
- threadMessage: threadMessage
1757
- }, threadMessage.id);
1758
- })
1705
+ // src/hooks/runs/usePolling/index.tsx
1706
+ import { useQueryClient as useQueryClient6 } from "@tanstack/react-query";
1707
+ import { useInterval } from "react-use";
1708
+ // src/hooks/runs/usePolling/lib/refetch.ts
1709
+ var refetch = function() {
1710
+ var _ref = _async_to_generator(function(param) {
1711
+ var queryClient, threadContext, _threadContext_defaultOptions_queries_queryKey, _threadContext_defaultOptions_queries_queryKey1;
1712
+ return _ts_generator(this, function(_state) {
1713
+ switch(_state.label){
1714
+ case 0:
1715
+ queryClient = param.queryClient, threadContext = param.threadContext;
1716
+ return [
1717
+ 4,
1718
+ queryClient.invalidateQueries({
1719
+ queryKey: (_threadContext_defaultOptions_queries_queryKey = threadContext.defaultOptions.queries.queryKey) !== null && _threadContext_defaultOptions_queries_queryKey !== void 0 ? _threadContext_defaultOptions_queries_queryKey : [
1720
+ "messages",
1721
+ threadContext.variables
1722
+ ]
1723
+ })
1724
+ ];
1725
+ case 1:
1726
+ _state.sent();
1727
+ return [
1728
+ 4,
1729
+ queryClient.invalidateQueries({
1730
+ queryKey: (_threadContext_defaultOptions_queries_queryKey1 = threadContext.defaultOptions.queries.queryKey) !== null && _threadContext_defaultOptions_queries_queryKey1 !== void 0 ? _threadContext_defaultOptions_queries_queryKey1 : [
1731
+ "runs",
1732
+ threadContext.variables
1733
+ ]
1734
+ })
1735
+ ];
1736
+ case 2:
1737
+ _state.sent();
1738
+ return [
1739
+ 2
1740
+ ];
1741
+ }
1742
+ });
1759
1743
  });
1744
+ return function refetch(_) {
1745
+ return _ref.apply(this, arguments);
1746
+ };
1747
+ }();
1748
+ // src/hooks/runs/usePolling/index.tsx
1749
+ var usePolling = function() {
1750
+ var threadContext = useSuperinterfaceContext();
1751
+ var queryClient = useQueryClient6();
1752
+ var isRunActiveProps = useIsRunActive();
1753
+ useInterval(function() {
1754
+ refetch({
1755
+ queryClient: queryClient,
1756
+ threadContext: threadContext
1757
+ });
1758
+ console.log("poll refetched");
1759
+ }, isRunActiveProps.isRunActive ? 3e3 : null);
1760
+ return null;
1760
1761
  };
1761
- // src/components/threadMessages/ThreadMessages/Content/ThreadMessageGroup/index.tsx
1762
- import { jsx as jsx29, jsxs as jsxs7 } from "react/jsx-runtime";
1763
- var ThreadMessageGroup = function(param) {
1764
- var threadMessageGroup = param.threadMessageGroup;
1765
- var assistantNameContext = useContext5(AssistantNameContext);
1766
- return /* @__PURE__ */ jsxs7(ThreadMessagesGroupBase, {
1767
- children: [
1768
- threadMessageGroup.role === "user" ? /* @__PURE__ */ jsx29(Avatar3, {
1769
- fallback: /* @__PURE__ */ jsx29(PersonIcon, {}),
1770
- size: "1"
1771
- }) : /* @__PURE__ */ jsx29(AssistantAvatar, {}),
1772
- /* @__PURE__ */ jsxs7(Box8, {
1773
- grow: "1",
1774
- children: [
1775
- /* @__PURE__ */ jsx29(Name, {
1776
- children: threadMessageGroup.role === "user" ? "You" : assistantNameContext
1777
- }),
1778
- /* @__PURE__ */ jsx29(Content2, {
1779
- threadMessageGroup: threadMessageGroup
1780
- })
1781
- ]
1782
- })
1783
- ]
1784
- });
1762
+ // src/hooks/actions/useManageActions/index.tsx
1763
+ import { useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1764
+ import { useEffect as useEffect3 } from "react";
1765
+ // src/hooks/actions/useHandleAction/index.tsx
1766
+ import { partob as partob2 } from "radash";
1767
+ import { useMutation as useMutation2, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
1768
+ // src/hooks/actions/useHandleAction/lib/onSettled.ts
1769
+ var onSettled2 = function(param) {
1770
+ var queryClient = param.queryClient;
1771
+ return function() {
1772
+ var _ref = _async_to_generator(function(_data, _error, variables) {
1773
+ return _ts_generator(this, function(_state) {
1774
+ switch(_state.label){
1775
+ case 0:
1776
+ return [
1777
+ 4,
1778
+ queryClient.invalidateQueries({
1779
+ queryKey: [
1780
+ "messages",
1781
+ variables
1782
+ ]
1783
+ })
1784
+ ];
1785
+ case 1:
1786
+ _state.sent();
1787
+ return [
1788
+ 4,
1789
+ queryClient.invalidateQueries({
1790
+ queryKey: [
1791
+ "runs",
1792
+ variables
1793
+ ]
1794
+ })
1795
+ ];
1796
+ case 2:
1797
+ _state.sent();
1798
+ return [
1799
+ 2
1800
+ ];
1801
+ }
1802
+ });
1803
+ });
1804
+ return function(_data, _error, variables) {
1805
+ return _ref.apply(this, arguments);
1806
+ };
1807
+ }();
1785
1808
  };
1786
- // src/components/threadMessages/ThreadMessages/Content/index.tsx
1787
- import { Fragment, jsx as jsx30 } from "react/jsx-runtime";
1788
- var Content3 = function(param) {
1789
- var threadMessages2 = param.threadMessages, isLoading = param.isLoading, isLoadingError = param.isLoadingError;
1790
- var _useThreadMessageGroups = useThreadMessageGroups({
1791
- threadMessages: threadMessages2
1792
- }), threadMessageGroups2 = _useThreadMessageGroups.threadMessageGroups;
1793
- if (isLoading || isLoadingError) {
1794
- return /* @__PURE__ */ jsx30(ThreadMessagesSkeleton, {});
1795
- }
1796
- return /* @__PURE__ */ jsx30(Fragment, {
1797
- children: threadMessageGroups2.map(function(threadMessageGroup) {
1798
- return /* @__PURE__ */ jsx30(ThreadMessageGroup, {
1799
- threadMessageGroup: threadMessageGroup
1800
- }, threadMessageGroup.id);
1809
+ // src/hooks/actions/useHandleAction/index.tsx
1810
+ var useHandleAction = function() {
1811
+ var queryClient = useQueryClient7();
1812
+ var superinterfaceContext = useSuperinterfaceContext();
1813
+ var threadContext = useSuperinterfaceContext();
1814
+ var props = useMutation2(_object_spread({
1815
+ onSettled: onSettled2({
1816
+ queryClient: queryClient
1801
1817
  })
1818
+ }, mutationOptions({
1819
+ mutationKeyBase: [
1820
+ "handleAction"
1821
+ ],
1822
+ path: "/actions",
1823
+ queryClient: queryClient,
1824
+ threadContext: threadContext,
1825
+ superinterfaceContext: superinterfaceContext
1826
+ })));
1827
+ return _object_spread_props(_object_spread({}, props), {
1828
+ handleAction: partob2(props.mutate, threadContext.variables)
1802
1829
  });
1803
1830
  };
1804
- // src/components/threadMessages/ThreadMessages/Progress/index.tsx
1805
- import { Box as Box11 } from "@radix-ui/themes";
1806
- // src/components/skeletons/StartingContentSkeleton/index.tsx
1807
- import { Box as Box9 } from "@radix-ui/themes";
1808
- import { jsx as jsx31 } from "react/jsx-runtime";
1809
- var StartingContentSkeleton = function() {
1810
- return /* @__PURE__ */ jsx31(Box9, {
1811
- shrink: "0",
1812
- mt: "1",
1813
- style: {
1814
- animation: "pulse 2s cubic-bezier(.4,0,.6,1) infinite",
1815
- borderRadius: "var(--radius-3)",
1816
- backgroundColor: "var(--gray-12)",
1817
- height: "var(--space-4)",
1818
- width: "var(--space-4)"
1819
- }
1820
- });
1821
- };
1822
- // src/components/skeletons/StartingSkeleton/index.tsx
1823
- import { useContext as useContext6 } from "react";
1824
- import { Box as Box10 } from "@radix-ui/themes";
1825
- import { jsx as jsx32, jsxs as jsxs8 } from "react/jsx-runtime";
1826
- var StartingSkeleton = function(param) {
1827
- var children = param.children;
1828
- var assistantNameContext = useContext6(AssistantNameContext);
1829
- return /* @__PURE__ */ jsxs8(ThreadMessagesGroupBase, {
1830
- children: [
1831
- /* @__PURE__ */ jsx32(AssistantAvatar, {}),
1832
- /* @__PURE__ */ jsxs8(Box10, {
1833
- children: [
1834
- /* @__PURE__ */ jsx32(Name, {
1835
- children: assistantNameContext
1836
- }),
1837
- children,
1838
- /* @__PURE__ */ jsx32(StartingContentSkeleton, {})
1839
- ]
1840
- })
1841
- ]
1842
- });
1843
- };
1844
- // src/components/threadMessages/ThreadMessages/Progress/index.tsx
1845
- import { jsx as jsx33, jsxs as jsxs9 } from "react/jsx-runtime";
1846
- var Progress = function(param) {
1847
- var latestThreadMessage = param.latestThreadMessage, isRunActive2 = param.isRunActive;
1848
- if (!latestThreadMessage) return null;
1849
- if (!isRunActive2) return null;
1850
- if (latestThreadMessage.role === "user") {
1851
- return /* @__PURE__ */ jsx33(StartingSkeleton, {});
1852
- }
1853
- return /* @__PURE__ */ jsxs9(ThreadMessagesGroupBase, {
1854
- children: [
1855
- /* @__PURE__ */ jsx33(Box11, {
1856
- pl: "5"
1857
- }),
1858
- /* @__PURE__ */ jsx33(StartingContentSkeleton, {})
1859
- ]
1860
- });
1831
+ // src/hooks/actions/useManageActions/index.tsx
1832
+ var useManageActions = function() {
1833
+ var queryClient = useQueryClient8();
1834
+ var threadContext = useSuperinterfaceContext();
1835
+ var latestRunProps = useLatestRun();
1836
+ var handleActionProps = useHandleAction();
1837
+ useEffect3(function() {
1838
+ if (handleActionProps.isPending) return;
1839
+ if (latestRunProps.isFetching) return;
1840
+ if (!latestRunProps.latestRun) return;
1841
+ if (latestRunProps.latestRun.status !== "requires_action") return;
1842
+ var isMutating = queryClient.isMutating({
1843
+ mutationKey: [
1844
+ "handleAction",
1845
+ threadContext.variables
1846
+ ]
1847
+ });
1848
+ if (isMutating) return;
1849
+ console.log("requires action", {
1850
+ latestRunProps: latestRunProps
1851
+ });
1852
+ handleActionProps.handleAction({
1853
+ latestRun: latestRunProps.latestRun
1854
+ });
1855
+ }, [
1856
+ handleActionProps,
1857
+ latestRunProps
1858
+ ]);
1859
+ return null;
1860
+ };
1861
+ // src/hooks/threads/useLifecycle/index.tsx
1862
+ var useLifecycle = function() {
1863
+ useManageRuns();
1864
+ useManageActions();
1865
+ usePolling();
1866
+ return null;
1861
1867
  };
1862
- // src/components/threadMessages/ThreadMessages/index.tsx
1868
+ // src/components/threads/Thread/Messages/Root/index.tsx
1863
1869
  import { jsx as jsx34, jsxs as jsxs10 } from "react/jsx-runtime";
1864
- var ThreadMessages = function(param) {
1870
+ var Root = function(param) {
1865
1871
  var children = param.children, _param_style = param.style, style = _param_style === void 0 ? {} : _param_style;
1866
- var _useThreadMessages = useThreadMessages(), threadMessages2 = _useThreadMessages.threadMessages, isFetchingNextPage = _useThreadMessages.isFetchingNextPage, hasNextPage = _useThreadMessages.hasNextPage, fetchNextPage = _useThreadMessages.fetchNextPage, isLoading = _useThreadMessages.isLoading, isLoadingError = _useThreadMessages.isLoadingError;
1867
- useThreadLifecycles();
1872
+ var _useMessages = useMessages(), isFetchingNextPage = _useMessages.isFetchingNextPage, hasNextPage = _useMessages.hasNextPage, fetchNextPage = _useMessages.fetchNextPage;
1873
+ useLifecycle();
1868
1874
  var _useInfiniteScroll = useInfiniteScroll({
1869
1875
  isFetchingNextPage: isFetchingNextPage,
1870
1876
  hasNextPage: hasNextPage,
1871
1877
  fetchNextPage: fetchNextPage
1872
1878
  }), containerRef = _useInfiniteScroll.containerRef, loaderRef = _useInfiniteScroll.loaderRef;
1873
- var _useIsRunActive = useIsRunActive(), isRunActive2 = _useIsRunActive.isRunActive;
1874
- var latestThreadMessage = useLatestThreadMessage().latestThreadMessage;
1875
1879
  return /* @__PURE__ */ jsxs10(Flex12, {
1876
1880
  ref: containerRef,
1877
1881
  direction: "column-reverse",
1878
- grow: "1",
1882
+ flexGrow: "1",
1879
1883
  style: _object_spread_props(_object_spread({}, style), {
1880
1884
  overflow: "auto"
1881
1885
  }),
1882
1886
  children: [
1883
- /* @__PURE__ */ jsx34(Flex12, {
1884
- shrink: "0",
1885
- style: {
1886
- height: "var(--space-3)"
1887
- }
1888
- }),
1889
- /* @__PURE__ */ jsx34(Progress, {
1890
- latestThreadMessage: latestThreadMessage,
1891
- isRunActive: isRunActive2
1892
- }),
1893
1887
  children,
1894
- /* @__PURE__ */ jsx34(Content3, {
1895
- threadMessages: threadMessages2,
1896
- isLoading: isLoading,
1897
- isLoadingError: isLoadingError
1898
- }),
1899
- hasNextPage && /* @__PURE__ */ jsx34(ThreadMessagesSkeleton, {
1888
+ hasNextPage && /* @__PURE__ */ jsx34(Flex12, {
1900
1889
  ref: loaderRef
1901
1890
  }),
1902
1891
  /* @__PURE__ */ jsx34(Flex12, {
1903
- shrink: "0",
1904
- grow: "1"
1892
+ flexShrink: "0",
1893
+ flexGrow: "1"
1905
1894
  })
1906
1895
  ]
1907
1896
  });
1908
1897
  };
1909
- // src/components/threadMessages/ThreadMessageForm/index.tsx
1910
- import { Container as Container2, Flex as Flex13, Text as Text5 } from "@radix-ui/themes";
1911
- import { useRef as useRef3, useEffect as useEffect4, useMemo as useMemo9, useContext as useContext7 } from "react";
1912
- import { useForm } from "react-hook-form";
1913
- import { usePrevious } from "react-use";
1914
- // src/components/textareas/TextareaBase/index.tsx
1915
- import { forwardRef as forwardRef3 } from "react";
1916
- import TextareaAutosize from "react-textarea-autosize";
1898
+ // src/components/threads/Thread/Messages/NextPageSkeleton.tsx
1917
1899
  import { jsx as jsx35 } from "react/jsx-runtime";
1918
- var UPSCALE_RATIO = 16 / 14;
1919
- var TextareaBase = forwardRef3(function TextareaBase2(props, ref) {
1920
- return /* @__PURE__ */ jsx35(TextareaAutosize, _object_spread({
1921
- ref: ref,
1922
- className: "textarea-base",
1900
+ var NextPageSkeleton = function() {
1901
+ var hasNextPage = useMessages().hasNextPage;
1902
+ if (!hasNextPage) {
1903
+ return null;
1904
+ }
1905
+ return /* @__PURE__ */ jsx35(MessagesSkeleton, {});
1906
+ };
1907
+ // src/components/threads/Thread/Messages/index.tsx
1908
+ import { jsx as jsx36, jsxs as jsxs11 } from "react/jsx-runtime";
1909
+ var Messages = function(param) {
1910
+ var children = param.children, _param_style = param.style, style = _param_style === void 0 ? {} : _param_style;
1911
+ return /* @__PURE__ */ jsxs11(Root, {
1912
+ style: style,
1913
+ children: [
1914
+ /* @__PURE__ */ jsx36(Flex13, {
1915
+ flexShrink: "0",
1916
+ height: "var(--space-3)"
1917
+ }),
1918
+ /* @__PURE__ */ jsx36(Progress, {}),
1919
+ children,
1920
+ /* @__PURE__ */ jsx36(Content3, {}),
1921
+ /* @__PURE__ */ jsx36(NextPageSkeleton, {}),
1922
+ /* @__PURE__ */ jsx36(Flex13, {
1923
+ flexShrink: "0",
1924
+ flexGrow: "1"
1925
+ })
1926
+ ]
1927
+ });
1928
+ };
1929
+ Messages.Root = Root;
1930
+ Messages.Message = Message;
1931
+ Messages.NextPageSkeleton = NextPageSkeleton;
1932
+ // src/components/threads/Thread/MessageForm/index.tsx
1933
+ import { Flex as Flex15, Text as Text5 } from "@radix-ui/themes";
1934
+ // src/components/threads/Thread/MessageForm/Submit/index.tsx
1935
+ import { ArrowUpIcon } from "@radix-ui/react-icons";
1936
+ import { Button as Button2 } from "@radix-ui/themes";
1937
+ // src/components/spinners/Spinner/index.tsx
1938
+ import { jsx as jsx37 } from "react/jsx-runtime";
1939
+ var Spinner = function(props) {
1940
+ return /* @__PURE__ */ jsx37("svg", _object_spread_props(_object_spread({
1941
+ xmlns: "http://www.w3.org/2000/svg",
1942
+ width: "24",
1943
+ height: "24",
1944
+ viewBox: "0 0 24 24",
1945
+ fill: "none",
1946
+ stroke: "currentColor",
1947
+ strokeWidth: "2",
1948
+ strokeLinecap: "round",
1949
+ strokeLinejoin: "round",
1923
1950
  style: {
1924
- resize: "none",
1925
- fontSize: "".concat(14 * UPSCALE_RATIO, "px"),
1926
- lineHeight: "".concat(24 * UPSCALE_RATIO, "px"),
1927
- transform: "scale(".concat(1 / UPSCALE_RATIO, ")"),
1928
- margin: "0 ".concat((-100 * UPSCALE_RATIO + 100) / 2, "%"),
1929
- width: "".concat(100 * UPSCALE_RATIO, "%"),
1930
- maxWidth: "".concat(100 * UPSCALE_RATIO, "%"),
1931
- flexGrow: 1,
1932
- display: "flex"
1951
+ height: "var(--space-4)",
1952
+ width: "var(--space-4)",
1953
+ animation: "spin 1s linear infinite"
1933
1954
  }
1934
- }, props));
1955
+ }, props), {
1956
+ children: /* @__PURE__ */ jsx37("path", {
1957
+ d: "M21 12a9 9 0 1 1-6.219-8.56"
1958
+ })
1959
+ }));
1960
+ };
1961
+ // src/hooks/messages/useMessageFormContext/index.ts
1962
+ import { useContext as useContext7 } from "react";
1963
+ // src/contexts/messages/MessageFormContext/index.ts
1964
+ import { createContext as createContext6 } from "react";
1965
+ var MessageFormContext = createContext6({
1966
+ isDisabled: false,
1967
+ isLoading: false,
1968
+ submit: function() {}
1935
1969
  });
1936
- // src/hooks/threadMessages/useCreateThreadMessage/index.ts
1970
+ // src/hooks/messages/useMessageFormContext/index.ts
1971
+ var useMessageFormContext = function() {
1972
+ return useContext7(MessageFormContext);
1973
+ };
1974
+ // src/components/threads/Thread/MessageForm/Submit/index.tsx
1975
+ import { jsx as jsx38 } from "react/jsx-runtime";
1976
+ var Submit = function() {
1977
+ var _useMessageFormContext = useMessageFormContext(), isDisabled = _useMessageFormContext.isDisabled, isLoading = _useMessageFormContext.isLoading;
1978
+ return /* @__PURE__ */ jsx38(Button2, {
1979
+ type: "submit",
1980
+ radius: "large",
1981
+ disabled: isDisabled,
1982
+ children: isLoading ? /* @__PURE__ */ jsx38(Spinner, {}) : /* @__PURE__ */ jsx38(ArrowUpIcon, {})
1983
+ });
1984
+ };
1985
+ // src/components/threads/Thread/MessageForm/Root/index.tsx
1986
+ import { useMemo as useMemo9 } from "react";
1987
+ import { useForm, FormProvider } from "react-hook-form";
1988
+ // src/hooks/messages/useCreateMessage/index.ts
1937
1989
  import { partob as partob3 } from "radash";
1938
1990
  import { useMutation as useMutation3, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
1939
- // src/hooks/threadMessages/useCreateThreadMessage/lib/mutationOptions/onMutate/index.ts
1991
+ // src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/index.ts
1940
1992
  import { omit } from "radash";
1941
- // src/hooks/threadMessages/useCreateThreadMessage/lib/mutationOptions/onMutate/data.ts
1993
+ // src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/data.ts
1942
1994
  var data2 = function(param) {
1943
- var newThreadMessage = param.newThreadMessage;
1995
+ var newMessage = param.newMessage;
1944
1996
  return function(prevData) {
1945
1997
  var message = {
1946
1998
  id: optimisticId(),
@@ -1952,7 +2004,7 @@ var data2 = function(param) {
1952
2004
  type: "text",
1953
2005
  text: {
1954
2006
  annotations: [],
1955
- value: newThreadMessage.content
2007
+ value: newMessage.content
1956
2008
  }
1957
2009
  }
1958
2010
  ],
@@ -1989,18 +2041,18 @@ var data2 = function(param) {
1989
2041
  });
1990
2042
  };
1991
2043
  };
1992
- // src/hooks/threadMessages/useCreateThreadMessage/lib/mutationOptions/onMutate/index.ts
2044
+ // src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/index.ts
1993
2045
  var onMutate2 = function(param) {
1994
2046
  var queryClient = param.queryClient;
1995
2047
  return function() {
1996
- var _ref = _async_to_generator(function(newThreadMessage) {
1997
- var queryKey, prevThreadMessages;
2048
+ var _ref = _async_to_generator(function(newMessage) {
2049
+ var queryKey, prevMessages;
1998
2050
  return _ts_generator(this, function(_state) {
1999
2051
  switch(_state.label){
2000
2052
  case 0:
2001
2053
  queryKey = [
2002
- "threadMessages",
2003
- omit(newThreadMessage, [
2054
+ "messages",
2055
+ omit(newMessage, [
2004
2056
  "content"
2005
2057
  ])
2006
2058
  ];
@@ -2012,26 +2064,26 @@ var onMutate2 = function(param) {
2012
2064
  ];
2013
2065
  case 1:
2014
2066
  _state.sent();
2015
- prevThreadMessages = queryClient.getQueryData(queryKey);
2067
+ prevMessages = queryClient.getQueryData(queryKey);
2016
2068
  queryClient.setQueryData(queryKey, data2({
2017
- newThreadMessage: newThreadMessage
2069
+ newMessage: newMessage
2018
2070
  }));
2019
2071
  return [
2020
2072
  2,
2021
2073
  {
2022
- prevThreadMessages: prevThreadMessages,
2023
- newThreadMessage: newThreadMessage
2074
+ prevMessages: prevMessages,
2075
+ newMessage: newMessage
2024
2076
  }
2025
2077
  ];
2026
2078
  }
2027
2079
  });
2028
2080
  });
2029
- return function(newThreadMessage) {
2081
+ return function(newMessage) {
2030
2082
  return _ref.apply(this, arguments);
2031
2083
  };
2032
2084
  }();
2033
2085
  };
2034
- // src/hooks/threadMessages/useCreateThreadMessage/lib/mutationOptions/onSettled.ts
2086
+ // src/hooks/messages/useCreateMessage/lib/mutationOptions/onSettled.ts
2035
2087
  import { omit as omit2 } from "radash";
2036
2088
  var onSettled3 = function(param) {
2037
2089
  var queryClient = param.queryClient;
@@ -2044,7 +2096,7 @@ var onSettled3 = function(param) {
2044
2096
  4,
2045
2097
  queryClient.invalidateQueries({
2046
2098
  queryKey: [
2047
- "threadMessages",
2099
+ "messages",
2048
2100
  omit2(variables, [
2049
2101
  "content"
2050
2102
  ])
@@ -2077,8 +2129,8 @@ var onSettled3 = function(param) {
2077
2129
  };
2078
2130
  }();
2079
2131
  };
2080
- // src/hooks/threadMessages/useCreateThreadMessage/index.ts
2081
- var useCreateThreadMessage = function() {
2132
+ // src/hooks/messages/useCreateMessage/index.ts
2133
+ var useCreateMessage = function() {
2082
2134
  var queryClient = useQueryClient9();
2083
2135
  var superinterfaceContext = useSuperinterfaceContext();
2084
2136
  var threadContext = useSuperinterfaceContext();
@@ -2091,69 +2143,32 @@ var useCreateThreadMessage = function() {
2091
2143
  })
2092
2144
  }, mutationOptions({
2093
2145
  mutationKeyBase: [
2094
- "createThreadMessage"
2146
+ "createMessage"
2095
2147
  ],
2096
- path: "/thread-messages",
2148
+ path: "/messages",
2097
2149
  queryClient: queryClient,
2098
2150
  threadContext: threadContext,
2099
2151
  superinterfaceContext: superinterfaceContext
2100
2152
  })));
2101
2153
  return _object_spread_props(_object_spread({}, props), {
2102
- createThreadMessage: partob3(props.mutateAsync, threadContext.variables)
2103
- });
2104
- };
2105
- // src/components/threadMessages/ThreadMessageForm/Submit/index.tsx
2106
- import { ArrowUpIcon } from "@radix-ui/react-icons";
2107
- import { Button as Button2 } from "@radix-ui/themes";
2108
- // src/components/spinners/Spinner/index.tsx
2109
- import { jsx as jsx36 } from "react/jsx-runtime";
2110
- var Spinner = function(props) {
2111
- return /* @__PURE__ */ jsx36("svg", _object_spread_props(_object_spread({
2112
- xmlns: "http://www.w3.org/2000/svg",
2113
- width: "24",
2114
- height: "24",
2115
- viewBox: "0 0 24 24",
2116
- fill: "none",
2117
- stroke: "currentColor",
2118
- strokeWidth: "2",
2119
- strokeLinecap: "round",
2120
- strokeLinejoin: "round",
2121
- style: {
2122
- height: "var(--space-4)",
2123
- width: "var(--space-4)",
2124
- animation: "spin 1s linear infinite"
2125
- }
2126
- }, props), {
2127
- children: /* @__PURE__ */ jsx36("path", {
2128
- d: "M21 12a9 9 0 1 1-6.219-8.56"
2129
- })
2130
- }));
2131
- };
2132
- // src/components/threadMessages/ThreadMessageForm/Submit/index.tsx
2133
- import { jsx as jsx37 } from "react/jsx-runtime";
2134
- var Submit = function(param) {
2135
- var isLoading = param.isLoading, isDisabled = param.isDisabled;
2136
- return /* @__PURE__ */ jsx37(Button2, {
2137
- type: "submit",
2138
- radius: "large",
2139
- disabled: isDisabled,
2140
- children: isLoading ? /* @__PURE__ */ jsx37(Spinner, {}) : /* @__PURE__ */ jsx37(ArrowUpIcon, {})
2154
+ createMessage: partob3(props.mutateAsync, threadContext.variables)
2141
2155
  });
2142
2156
  };
2143
- // src/components/threadMessages/ThreadMessageForm/lib/useFormProps/index.ts
2157
+ // src/components/threads/Thread/MessageForm/Root/lib/formOptions.ts
2144
2158
  import { z } from "zod";
2145
2159
  import { zodResolver } from "@hookform/resolvers/zod";
2146
2160
  var schema = z.object({
2147
2161
  content: z.string().min(1)
2148
2162
  });
2149
- var useFormProps = {
2163
+ var formOptions = {
2150
2164
  resolver: zodResolver(schema)
2151
2165
  };
2152
- // src/components/threadMessages/ThreadMessageForm/index.tsx
2153
- import { jsx as jsx38, jsxs as jsxs11 } from "react/jsx-runtime";
2154
- var ThreadMessageForm = function() {
2155
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, children = _ref.children, tmp = _ref.useFormProps, useFormProps2 = tmp === void 0 ? useFormProps : tmp, _ref_style = _ref.style, style = _ref_style === void 0 ? {} : _ref_style;
2156
- var _useForm = useForm(useFormProps2), register = _useForm.register, handleSubmit = _useForm.handleSubmit, _useForm_formState = _useForm.formState, errors = _useForm_formState.errors, isSubmitting = _useForm_formState.isSubmitting, reset = _useForm.reset;
2166
+ // src/components/threads/Thread/MessageForm/Root/index.tsx
2167
+ import { jsx as jsx39 } from "react/jsx-runtime";
2168
+ var Root2 = function(param) {
2169
+ var children = param.children;
2170
+ var formProps = useForm(formOptions);
2171
+ var handleSubmit = formProps.handleSubmit, isSubmitting = formProps.formState.isSubmitting, reset = formProps.reset;
2157
2172
  var _useIsRunActive = useIsRunActive(), isRunActive2 = _useIsRunActive.isRunActive;
2158
2173
  var isLoading = useMemo9(function() {
2159
2174
  return isRunActive2 || isSubmitting;
@@ -2161,7 +2176,7 @@ var ThreadMessageForm = function() {
2161
2176
  isRunActive2,
2162
2177
  isSubmitting
2163
2178
  ]);
2164
- var createThreadMessage = useCreateThreadMessage().createThreadMessage;
2179
+ var createMessage = useCreateMessage().createMessage;
2165
2180
  var onSubmit = function() {
2166
2181
  var _ref = _async_to_generator(function(data3) {
2167
2182
  return _ts_generator(this, function(_state) {
@@ -2170,7 +2185,7 @@ var ThreadMessageForm = function() {
2170
2185
  reset();
2171
2186
  return [
2172
2187
  4,
2173
- createThreadMessage({
2188
+ createMessage({
2174
2189
  content: data3.content
2175
2190
  })
2176
2191
  ];
@@ -2186,16 +2201,92 @@ var ThreadMessageForm = function() {
2186
2201
  return _ref.apply(this, arguments);
2187
2202
  };
2188
2203
  }();
2189
- var latestThreadMessage = useLatestThreadMessage().latestThreadMessage;
2204
+ var latestMessage = useLatestMessage().latestMessage;
2190
2205
  var isDisabled = useMemo9(function() {
2191
2206
  var // @ts-ignore-next-line
2192
- _latestThreadMessage_metadata;
2193
- return latestThreadMessage === null || latestThreadMessage === void 0 ? void 0 : (_latestThreadMessage_metadata = latestThreadMessage.metadata) === null || _latestThreadMessage_metadata === void 0 ? void 0 : _latestThreadMessage_metadata.isBlocking;
2207
+ _latestMessage_metadata;
2208
+ return latestMessage === null || latestMessage === void 0 ? void 0 : (_latestMessage_metadata = latestMessage.metadata) === null || _latestMessage_metadata === void 0 ? void 0 : _latestMessage_metadata.isBlocking;
2194
2209
  }, [
2195
- latestThreadMessage,
2210
+ latestMessage,
2196
2211
  isLoading
2197
2212
  ]);
2198
- var isSubmitDisabled = useMemo9(function() {
2213
+ return /* @__PURE__ */ jsx39(MessageFormContext.Provider, {
2214
+ value: {
2215
+ isDisabled: isDisabled,
2216
+ isLoading: isLoading,
2217
+ submit: handleSubmit(onSubmit)
2218
+ },
2219
+ children: /* @__PURE__ */ jsx39(FormProvider, _object_spread_props(_object_spread({}, formProps), {
2220
+ children: /* @__PURE__ */ jsx39("form", {
2221
+ onSubmit: handleSubmit(onSubmit),
2222
+ children: children
2223
+ })
2224
+ }))
2225
+ });
2226
+ };
2227
+ // src/components/threads/Thread/MessageForm/Field/index.tsx
2228
+ import { usePrevious } from "react-use";
2229
+ import { useContext as useContext8, useMemo as useMemo10, useRef as useRef3, useEffect as useEffect4 } from "react";
2230
+ // src/components/textareas/TextareaBase/index.tsx
2231
+ import { forwardRef as forwardRef3 } from "react";
2232
+ import TextareaAutosize from "react-textarea-autosize";
2233
+ import { jsx as jsx40 } from "react/jsx-runtime";
2234
+ var UPSCALE_RATIO = 16 / 14;
2235
+ var TextareaBase = forwardRef3(function TextareaBase2(props, ref) {
2236
+ return /* @__PURE__ */ jsx40(TextareaAutosize, _object_spread({
2237
+ ref: ref,
2238
+ className: "textarea-base",
2239
+ style: {
2240
+ resize: "none",
2241
+ fontSize: "".concat(14 * UPSCALE_RATIO, "px"),
2242
+ lineHeight: "".concat(24 * UPSCALE_RATIO, "px"),
2243
+ transform: "scale(".concat(1 / UPSCALE_RATIO, ")"),
2244
+ margin: "0 ".concat((-100 * UPSCALE_RATIO + 100) / 2, "%"),
2245
+ width: "".concat(100 * UPSCALE_RATIO, "%"),
2246
+ maxWidth: "".concat(100 * UPSCALE_RATIO, "%"),
2247
+ flexGrow: 1,
2248
+ display: "flex"
2249
+ }
2250
+ }, props));
2251
+ });
2252
+ // src/components/threads/Thread/MessageForm/Field/index.tsx
2253
+ import { useFormContext } from "react-hook-form";
2254
+ import { Container as Container2, Flex as Flex14 } from "@radix-ui/themes";
2255
+ import { jsx as jsx41 } from "react/jsx-runtime";
2256
+ var Root3 = function(param) {
2257
+ var children = param.children;
2258
+ var _useFormContext = useFormContext(), errors = _useFormContext.formState.errors;
2259
+ return /* @__PURE__ */ jsx41(Container2, {
2260
+ size: "2",
2261
+ flexGrow: "0",
2262
+ children: /* @__PURE__ */ jsx41(Flex14, {
2263
+ direction: "column",
2264
+ flexShrink: "0",
2265
+ children: /* @__PURE__ */ jsx41(Flex14, {
2266
+ direction: "column",
2267
+ flexShrink: "0",
2268
+ children: /* @__PURE__ */ jsx41(Flex14, {
2269
+ style: _object_spread({
2270
+ borderRadius: "var(--radius-2)",
2271
+ borderWidth: "1px",
2272
+ borderStyle: "solid",
2273
+ borderColor: errors.content ? "var(--red-9)" : "var(--gray-5)"
2274
+ }, errors.content ? {
2275
+ backgroundColor: "var(--red-2)"
2276
+ } : {}),
2277
+ p: "2",
2278
+ pl: "4",
2279
+ children: children
2280
+ })
2281
+ })
2282
+ })
2283
+ });
2284
+ };
2285
+ var Control = function() {
2286
+ var assistantNameContext = useContext8(AssistantNameContext);
2287
+ var register = useFormContext().register;
2288
+ var _useMessageFormContext = useMessageFormContext(), isDisabled = _useMessageFormContext.isDisabled, isLoading = _useMessageFormContext.isLoading, submit = _useMessageFormContext.submit;
2289
+ var isSubmitDisabled = useMemo10(function() {
2199
2290
  return isDisabled || isLoading;
2200
2291
  }, [
2201
2292
  isDisabled,
@@ -2214,123 +2305,108 @@ var ThreadMessageForm = function() {
2214
2305
  isDisabledPrevious,
2215
2306
  textareaProps
2216
2307
  ]);
2217
- var assistantNameContext = useContext7(AssistantNameContext);
2218
- return /* @__PURE__ */ jsxs11(Container2, {
2219
- size: "2",
2220
- grow: "0",
2221
- style: style,
2222
- children: [
2223
- children,
2224
- /* @__PURE__ */ jsx38(Flex13, {
2225
- direction: "column",
2226
- shrink: "0",
2227
- children: /* @__PURE__ */ jsx38(Flex13, {
2228
- direction: "column",
2229
- shrink: "0",
2230
- children: /* @__PURE__ */ jsx38("form", {
2231
- onSubmit: handleSubmit(onSubmit),
2232
- children: /* @__PURE__ */ jsxs11(Flex13, {
2233
- style: _object_spread({
2234
- borderRadius: "var(--radius-2)",
2235
- borderWidth: "1px",
2236
- borderStyle: "solid",
2237
- borderColor: errors.content ? "var(--red-9)" : "var(--gray-5)"
2238
- }, errors.content ? {
2239
- backgroundColor: "var(--red-2)"
2240
- } : {}),
2241
- p: "2",
2242
- pl: "4",
2243
- children: [
2244
- /* @__PURE__ */ jsx38(Text5, {
2245
- size: "2",
2246
- style: {
2247
- flexGrow: 1
2248
- },
2249
- children: /* @__PURE__ */ jsx38(Flex13, {
2250
- grow: "1",
2251
- direction: "column",
2252
- children: /* @__PURE__ */ jsx38(TextareaBase, _object_spread_props(_object_spread({
2253
- minRows: 1,
2254
- placeholder: "Message ".concat(assistantNameContext, "..."),
2255
- disabled: isDisabled,
2256
- onKeyDown: function(e) {
2257
- if (e.key === "Enter" && !e.shiftKey) {
2258
- e.preventDefault();
2259
- if (isSubmitDisabled) return;
2260
- handleSubmit(onSubmit)();
2261
- }
2262
- },
2263
- autoFocus: true
2264
- }, textareaProps), {
2265
- ref: function(e) {
2266
- textareaProps.ref(e);
2267
- textareaRef.current = e;
2268
- }
2269
- }))
2270
- })
2271
- }),
2272
- /* @__PURE__ */ jsx38(Flex13, {
2273
- shrink: "0",
2274
- align: "end",
2275
- children: /* @__PURE__ */ jsx38(Submit, {
2276
- isLoading: isLoading,
2277
- isDisabled: isSubmitDisabled
2278
- })
2279
- })
2280
- ]
2281
- })
2282
- })
2283
- })
2284
- })
2285
- ]
2286
- });
2308
+ return /* @__PURE__ */ jsx41(TextareaBase, _object_spread_props(_object_spread({
2309
+ minRows: 1,
2310
+ placeholder: "Message ".concat(assistantNameContext, "..."),
2311
+ disabled: isDisabled,
2312
+ onKeyDown: function(e) {
2313
+ if (e.key === "Enter" && !e.shiftKey) {
2314
+ e.preventDefault();
2315
+ if (isSubmitDisabled) return;
2316
+ submit();
2317
+ }
2318
+ },
2319
+ autoFocus: true
2320
+ }, textareaProps), {
2321
+ ref: function(e) {
2322
+ textareaProps.ref(e);
2323
+ textareaRef.current = e;
2324
+ }
2325
+ }));
2287
2326
  };
2288
- // src/components/threads/Thread/index.tsx
2289
- import { jsx as jsx39, jsxs as jsxs12 } from "react/jsx-runtime";
2290
- var Thread = function(props) {
2291
- return /* @__PURE__ */ jsx39(SuperinterfaceProvider, _object_spread_props(_object_spread({}, props), {
2292
- children: /* @__PURE__ */ jsxs12(Flex14, {
2293
- direction: "column",
2294
- grow: "1",
2327
+ var Field = {
2328
+ Root: Root3,
2329
+ Control: Control
2330
+ };
2331
+ // src/components/threads/Thread/MessageForm/index.tsx
2332
+ import { jsx as jsx42, jsxs as jsxs12 } from "react/jsx-runtime";
2333
+ var MessageForm = function() {
2334
+ return /* @__PURE__ */ jsx42(Root2, {
2335
+ children: /* @__PURE__ */ jsxs12(Field.Root, {
2295
2336
  children: [
2296
- /* @__PURE__ */ jsx39(ThreadMessages, {
2337
+ /* @__PURE__ */ jsx42(Text5, {
2338
+ size: "2",
2297
2339
  style: {
2298
- padding: "var(--space-5)"
2299
- }
2340
+ flexGrow: 1
2341
+ },
2342
+ children: /* @__PURE__ */ jsx42(Flex15, {
2343
+ flexGrow: "1",
2344
+ direction: "column",
2345
+ children: /* @__PURE__ */ jsx42(Field.Control, {})
2346
+ })
2300
2347
  }),
2301
- /* @__PURE__ */ jsx39(ThreadMessageForm, {
2302
- style: {
2303
- paddingLeft: "var(--space-5)",
2304
- paddingRight: "var(--space-5)",
2305
- paddingBottom: "var(--space-5)"
2306
- }
2348
+ /* @__PURE__ */ jsx42(Flex15, {
2349
+ flexShrink: "0",
2350
+ align: "end",
2351
+ children: /* @__PURE__ */ jsx42(Submit, {})
2307
2352
  })
2308
2353
  ]
2309
2354
  })
2355
+ });
2356
+ };
2357
+ MessageForm.Root = Root2;
2358
+ MessageForm.Field = Field;
2359
+ MessageForm.Submit = Submit;
2360
+ // src/components/threads/Thread/Root/index.tsx
2361
+ import { Flex as Flex16 } from "@radix-ui/themes";
2362
+ import { jsx as jsx43 } from "react/jsx-runtime";
2363
+ var Root4 = function(_param) {
2364
+ var children = _param.children, rest = _object_without_properties(_param, [
2365
+ "children"
2366
+ ]);
2367
+ return /* @__PURE__ */ jsx43(SuperinterfaceProvider, _object_spread_props(_object_spread({}, rest), {
2368
+ children: /* @__PURE__ */ jsx43(Flex16, {
2369
+ direction: "column",
2370
+ flexGrow: "1",
2371
+ children: children
2372
+ })
2373
+ }));
2374
+ };
2375
+ // src/components/threads/Thread/index.tsx
2376
+ import { jsx as jsx44, jsxs as jsxs13 } from "react/jsx-runtime";
2377
+ var Thread = function(props) {
2378
+ return /* @__PURE__ */ jsxs13(Root4, _object_spread_props(_object_spread({}, props), {
2379
+ children: [
2380
+ /* @__PURE__ */ jsx44(Messages, {}),
2381
+ /* @__PURE__ */ jsx44(MessageForm, {})
2382
+ ]
2310
2383
  }));
2311
2384
  };
2385
+ Thread.Root = Root4;
2386
+ Thread.Messages = Messages;
2387
+ Thread.MessageForm = MessageForm;
2312
2388
  // src/components/threads/ThreadDialog/Root/index.tsx
2313
- import { Flex as Flex15 } from "@radix-ui/themes";
2389
+ import { Flex as Flex17 } from "@radix-ui/themes";
2314
2390
  // src/components/threads/ThreadDialog/Provider/index.tsx
2315
2391
  import { useState } from "react";
2316
2392
  // src/contexts/threads/ThreadDialogContext/index.ts
2317
- import { createContext as createContext6 } from "react";
2318
- var ThreadDialogContext = createContext6({
2393
+ import { createContext as createContext7 } from "react";
2394
+ var ThreadDialogContext = createContext7({
2319
2395
  isOpen: false,
2320
2396
  setIsOpen: function() {}
2321
2397
  });
2322
2398
  // src/hooks/threads/useThreadDialogContext/index.ts
2323
- import { useContext as useContext8 } from "react";
2399
+ import { useContext as useContext9 } from "react";
2324
2400
  var useThreadDialogContext = function() {
2325
- return useContext8(ThreadDialogContext);
2401
+ return useContext9(ThreadDialogContext);
2326
2402
  };
2327
2403
  // src/components/threads/ThreadDialog/Provider/index.tsx
2328
- import { jsx as jsx40 } from "react/jsx-runtime";
2404
+ import { jsx as jsx45 } from "react/jsx-runtime";
2329
2405
  var Provider = function(param) {
2330
2406
  var children = param.children;
2331
2407
  var threadDialogContext = useThreadDialogContext();
2332
2408
  var _useState = _sliced_to_array(useState(threadDialogContext.isOpen), 2), isOpen = _useState[0], setIsOpen = _useState[1];
2333
- return /* @__PURE__ */ jsx40(ThreadDialogContext.Provider, {
2409
+ return /* @__PURE__ */ jsx45(ThreadDialogContext.Provider, {
2334
2410
  value: {
2335
2411
  isOpen: isOpen,
2336
2412
  setIsOpen: setIsOpen
@@ -2339,11 +2415,11 @@ var Provider = function(param) {
2339
2415
  });
2340
2416
  };
2341
2417
  // src/components/threads/ThreadDialog/Root/index.tsx
2342
- import { jsx as jsx41 } from "react/jsx-runtime";
2343
- var Root = function(param) {
2418
+ import { jsx as jsx46 } from "react/jsx-runtime";
2419
+ var Root5 = function(param) {
2344
2420
  var children = param.children, _param_style = param.style, style = _param_style === void 0 ? {} : _param_style;
2345
- return /* @__PURE__ */ jsx41(Provider, {
2346
- children: /* @__PURE__ */ jsx41(Flex15, {
2421
+ return /* @__PURE__ */ jsx46(Provider, {
2422
+ children: /* @__PURE__ */ jsx46(Flex17, {
2347
2423
  direction: "column",
2348
2424
  justify: "end",
2349
2425
  align: "end",
@@ -2359,94 +2435,107 @@ var Root = function(param) {
2359
2435
  });
2360
2436
  };
2361
2437
  // src/components/threads/ThreadDialog/Trigger/index.tsx
2362
- import { Flex as Flex16 } from "@radix-ui/themes";
2363
- import { jsx as jsx42 } from "react/jsx-runtime";
2438
+ import { Flex as Flex18 } from "@radix-ui/themes";
2439
+ import { jsx as jsx47 } from "react/jsx-runtime";
2364
2440
  var Trigger = function(param) {
2365
2441
  var children = param.children;
2366
2442
  var setIsOpen = useThreadDialogContext().setIsOpen;
2367
- return /* @__PURE__ */ jsx42(Flex16, {
2443
+ return /* @__PURE__ */ jsx47(Flex18, {
2368
2444
  onClick: function() {
2369
2445
  return setIsOpen(function(prev) {
2370
2446
  return !prev;
2371
2447
  });
2372
2448
  },
2373
2449
  direction: "column",
2374
- shrink: "0",
2450
+ flexShrink: "0",
2375
2451
  children: children
2376
2452
  });
2377
2453
  };
2378
2454
  // src/components/threads/ThreadDialog/Button/index.tsx
2379
2455
  import { IconButton } from "@radix-ui/themes";
2380
2456
  import { ChatBubbleIcon } from "@radix-ui/react-icons";
2381
- import { jsx as jsx43 } from "react/jsx-runtime";
2457
+ import { jsx as jsx48 } from "react/jsx-runtime";
2382
2458
  var Button3 = function() {
2383
- return /* @__PURE__ */ jsx43(IconButton, {
2459
+ return /* @__PURE__ */ jsx48(IconButton, {
2384
2460
  size: "4",
2385
2461
  radius: "full",
2386
- children: /* @__PURE__ */ jsx43(ChatBubbleIcon, {})
2462
+ children: /* @__PURE__ */ jsx48(ChatBubbleIcon, {})
2387
2463
  });
2388
2464
  };
2389
2465
  // src/components/threads/ThreadDialog/Content/index.tsx
2390
- import { Card, Inset } from "@radix-ui/themes";
2391
- import { Fragment as Fragment2, jsx as jsx44, jsxs as jsxs13 } from "react/jsx-runtime";
2392
- var Content4 = function(param) {
2466
+ import { Card, Inset, Flex as Flex19 } from "@radix-ui/themes";
2467
+ import { jsx as jsx49, jsxs as jsxs14 } from "react/jsx-runtime";
2468
+ var Root6 = function(param) {
2393
2469
  var children = param.children;
2394
2470
  var isOpen = useThreadDialogContext().isOpen;
2395
2471
  if (!isOpen) return null;
2396
- return /* @__PURE__ */ jsxs13(Fragment2, {
2397
- children: [
2398
- /* @__PURE__ */ jsx44("style", {
2399
- children: ".superinterface-thread-dialog-card .rt-CardInner { display: flex; }"
2400
- }),
2401
- /* @__PURE__ */ jsx44(Card, {
2402
- className: "superinterface-thread-dialog-card",
2403
- mb: "3",
2404
- style: {
2405
- flexGrow: 1,
2406
- width: "100vw",
2407
- maxWidth: "400px",
2408
- maxHeight: "720px"
2409
- },
2410
- children: /* @__PURE__ */ jsx44(Inset, {
2411
- clip: "padding-box",
2412
- side: "all",
2413
- pb: "current",
2472
+ return /* @__PURE__ */ jsx49(Card, {
2473
+ mb: "3",
2474
+ style: {
2475
+ display: "flex",
2476
+ flexGrow: 1,
2477
+ width: "100vw",
2478
+ maxWidth: "400px",
2479
+ maxHeight: "720px"
2480
+ },
2481
+ children: /* @__PURE__ */ jsx49(Inset, {
2482
+ clip: "padding-box",
2483
+ side: "all",
2484
+ pb: "current",
2485
+ style: {
2486
+ display: "flex",
2487
+ flexGrow: 1
2488
+ },
2489
+ children: children
2490
+ })
2491
+ });
2492
+ };
2493
+ var Content4 = function() {
2494
+ return /* @__PURE__ */ jsx49(Root6, {
2495
+ children: /* @__PURE__ */ jsxs14(Thread.Root, {
2496
+ children: [
2497
+ /* @__PURE__ */ jsx49(Thread.Messages, {
2414
2498
  style: {
2415
- display: "flex",
2416
- flexGrow: 1
2417
- },
2418
- children: children
2499
+ padding: "var(--space-5)"
2500
+ }
2501
+ }),
2502
+ /* @__PURE__ */ jsx49(Flex19, {
2503
+ direction: "column",
2504
+ pl: "5",
2505
+ pr: "5",
2506
+ pb: "3",
2507
+ flexShrink: "0",
2508
+ children: /* @__PURE__ */ jsx49(Thread.MessageForm, {})
2419
2509
  })
2420
- })
2421
- ]
2510
+ ]
2511
+ })
2422
2512
  });
2423
2513
  };
2514
+ Content4.Root = Root6;
2424
2515
  // src/components/threads/ThreadDialog/index.tsx
2425
- import { jsx as jsx45, jsxs as jsxs14 } from "react/jsx-runtime";
2516
+ import { jsx as jsx50, jsxs as jsxs15 } from "react/jsx-runtime";
2426
2517
  var ThreadDialog = function() {
2427
- return /* @__PURE__ */ jsxs14(Root, {
2518
+ return /* @__PURE__ */ jsxs15(Root5, {
2428
2519
  children: [
2429
- /* @__PURE__ */ jsx45(Content4, {
2430
- children: /* @__PURE__ */ jsx45(Thread, {})
2431
- }),
2432
- /* @__PURE__ */ jsx45(Trigger, {
2433
- children: /* @__PURE__ */ jsx45(Button3, {})
2520
+ /* @__PURE__ */ jsx50(Content4, {}),
2521
+ /* @__PURE__ */ jsx50(Trigger, {
2522
+ children: /* @__PURE__ */ jsx50(Button3, {})
2434
2523
  })
2435
2524
  ]
2436
2525
  });
2437
2526
  };
2438
- ThreadDialog.Root = Root;
2527
+ ThreadDialog.Root = Root5;
2439
2528
  ThreadDialog.Trigger = Trigger;
2440
2529
  ThreadDialog.Button = Button3;
2441
2530
  ThreadDialog.Content = Content4;
2442
2531
  // src/components/threads/AudioThread/Root/index.tsx
2443
2532
  import "regenerator-runtime/runtime";
2444
2533
  import { useEffect as useEffect7, useRef as useRef6 } from "react";
2445
- import { Flex as Flex17 } from "@radix-ui/themes";
2534
+ import { Flex as Flex20 } from "@radix-ui/themes";
2446
2535
  import SpeechRecognition, { useSpeechRecognition } from "react-speech-recognition";
2447
2536
  // src/contexts/threads/AudioThreadContext/index.ts
2448
- import { createContext as createContext7 } from "react";
2449
- var AudioThreadContext = createContext7({
2537
+ import { createContext as createContext8 } from "react";
2538
+ var AudioThreadContext = createContext8({
2450
2539
  status: "idle",
2451
2540
  recorderProps: {
2452
2541
  status: "idle",
@@ -2504,13 +2593,13 @@ var AudioThreadContext = createContext7({
2504
2593
  // src/components/threads/AudioThread/Root/index.tsx
2505
2594
  import { usePermission } from "react-use";
2506
2595
  // src/hooks/audioThreads/useStatus/index.ts
2507
- import { useMemo as useMemo10 } from "react";
2596
+ import { useMemo as useMemo11 } from "react";
2508
2597
  var useStatus = function(param) {
2509
- var messageAudioProps = param.messageAudioProps, recorderProps = param.recorderProps, createThreadMessageProps = param.createThreadMessageProps;
2598
+ var messageAudioProps = param.messageAudioProps, recorderProps = param.recorderProps, createMessageProps = param.createMessageProps;
2510
2599
  var isRunActiveProps = useIsRunActive();
2511
- var status = useMemo10(function() {
2600
+ var status = useMemo11(function() {
2512
2601
  if (recorderProps.status === "recording") return "recording";
2513
- if (createThreadMessageProps.isPending) return "creatingMessage";
2602
+ if (createMessageProps.isPending) return "creatingMessage";
2514
2603
  if (isRunActiveProps.isRunActive) return "runActive";
2515
2604
  if (messageAudioProps.playing) return "playing";
2516
2605
  if (messageAudioProps.paused) return "playerPaused";
@@ -2521,7 +2610,7 @@ var useStatus = function(param) {
2521
2610
  }, [
2522
2611
  messageAudioProps,
2523
2612
  recorderProps,
2524
- createThreadMessageProps,
2613
+ createMessageProps,
2525
2614
  isRunActiveProps
2526
2615
  ]);
2527
2616
  return {
@@ -2531,7 +2620,7 @@ var useStatus = function(param) {
2531
2620
  // src/hooks/audioThreads/useRecorder/index.ts
2532
2621
  import dayjs from "dayjs";
2533
2622
  import { useAudioCapture } from "use-audio-capture";
2534
- import { useMemo as useMemo11, useRef as useRef4, useState as useState2, useCallback as useCallback2, useEffect as useEffect5 } from "react";
2623
+ import { useMemo as useMemo12, useRef as useRef4, useState as useState2, useCallback as useCallback2, useEffect as useEffect5 } from "react";
2535
2624
  import { useAudioPlayer } from "react-use-audio-player";
2536
2625
  import { useInterval as useInterval2 } from "react-use";
2537
2626
  var useRecorder = function(param) {
@@ -2624,7 +2713,7 @@ var useRecorder = function(param) {
2624
2713
  isInited,
2625
2714
  mediaStream
2626
2715
  ]);
2627
- var visualizationAnalyser = useMemo11(function() {
2716
+ var visualizationAnalyser = useMemo12(function() {
2628
2717
  if (!audioEngine) return null;
2629
2718
  var result = audioEngine.audioContext.createAnalyser();
2630
2719
  audioEngine.source.connect(result);
@@ -2632,7 +2721,7 @@ var useRecorder = function(param) {
2632
2721
  }, [
2633
2722
  audioEngine
2634
2723
  ]);
2635
- var silenceAnalyser = useMemo11(function() {
2724
+ var silenceAnalyser = useMemo12(function() {
2636
2725
  if (!audioEngine) return null;
2637
2726
  var result = audioEngine.audioContext.createAnalyser();
2638
2727
  result.minDecibels = -45;
@@ -2687,14 +2776,14 @@ var useRecorder = function(param) {
2687
2776
  });
2688
2777
  };
2689
2778
  // src/hooks/audioThreads/useMessageAudio/index.ts
2690
- import { useMemo as useMemo12, useRef as useRef5, useState as useState3, useEffect as useEffect6 } from "react";
2779
+ import { useMemo as useMemo13, useRef as useRef5, useState as useState3, useEffect as useEffect6 } from "react";
2691
2780
  import { Howler } from "howler";
2692
2781
  import { useAudioPlayer as useAudioPlayer2 } from "react-use-audio-player";
2693
2782
  // src/hooks/audioThreads/useMessageAudio/lib/input.ts
2694
2783
  import { isEmpty } from "radash";
2695
2784
  var input = function(param) {
2696
- var threadMessage = param.threadMessage;
2697
- var textContents = threadMessage.content.filter(function(c) {
2785
+ var message = param.message;
2786
+ var textContents = message.content.filter(function(c) {
2698
2787
  return c.type === "text";
2699
2788
  });
2700
2789
  var result = textContents.map(function(c) {
@@ -2716,19 +2805,19 @@ var useMessageAudio = function(param) {
2716
2805
  var _useState3 = _sliced_to_array(useState3([]), 2), playedMessageIds = _useState3[0], setPlayedMessageIds = _useState3[1];
2717
2806
  var audioPlayer = useAudioPlayer2();
2718
2807
  var superinterfaceContext = useSuperinterfaceContext();
2719
- var latestThreadMessageProps = useLatestThreadMessage();
2808
+ var latestMessageProps = useLatestMessage();
2720
2809
  useEffect6(function() {
2721
2810
  if (audioPlayer.playing) return;
2722
- if (!latestThreadMessageProps.latestThreadMessage) return;
2723
- if (latestThreadMessageProps.latestThreadMessage.role !== "assistant") return;
2724
- if (playedMessageIds.includes(latestThreadMessageProps.latestThreadMessage.id)) return;
2811
+ if (!latestMessageProps.latestMessage) return;
2812
+ if (latestMessageProps.latestMessage.role !== "assistant") return;
2813
+ if (playedMessageIds.includes(latestMessageProps.latestMessage.id)) return;
2725
2814
  var input2 = input({
2726
- threadMessage: latestThreadMessageProps.latestThreadMessage
2815
+ message: latestMessageProps.latestMessage
2727
2816
  });
2728
2817
  if (!input2) return;
2729
2818
  setPlayedMessageIds(function(prev) {
2730
2819
  return _to_consumable_array(prev).concat([
2731
- latestThreadMessageProps.latestThreadMessage.id
2820
+ latestMessageProps.latestMessage.id
2732
2821
  ]);
2733
2822
  });
2734
2823
  audioPlayer.load("".concat(superinterfaceContext.baseUrl, "/tts?input=").concat(input2), {
@@ -2739,7 +2828,7 @@ var useMessageAudio = function(param) {
2739
2828
  });
2740
2829
  }, [
2741
2830
  superinterfaceContext,
2742
- latestThreadMessageProps,
2831
+ latestMessageProps,
2743
2832
  audioPlayer,
2744
2833
  playedMessageIds,
2745
2834
  onEnd
@@ -2767,7 +2856,7 @@ var useMessageAudio = function(param) {
2767
2856
  audioPlayer,
2768
2857
  isInited
2769
2858
  ]);
2770
- var visualizationAnalyser = useMemo12(function() {
2859
+ var visualizationAnalyser = useMemo13(function() {
2771
2860
  if (!audioEngine) return null;
2772
2861
  var result = audioEngine.audioContext.createAnalyser();
2773
2862
  audioEngine.source.connect(audioEngine.audioContext.destination);
@@ -2781,17 +2870,12 @@ var useMessageAudio = function(param) {
2781
2870
  });
2782
2871
  };
2783
2872
  // src/components/threads/AudioThread/Root/index.tsx
2784
- import { jsx as jsx46 } from "react/jsx-runtime";
2785
- var Root2 = function(param) {
2873
+ import { jsx as jsx51 } from "react/jsx-runtime";
2874
+ var Root7 = function(param) {
2786
2875
  var children = param.children;
2787
- useThreadLifecycles();
2788
- var createThreadMessageProps = useCreateThreadMessage();
2789
- var _useSpeechRecognition = useSpeechRecognition(), transcript = _useSpeechRecognition.transcript, listening = _useSpeechRecognition.listening, resetTranscript = _useSpeechRecognition.resetTranscript, browserSupportsSpeechRecognition = _useSpeechRecognition.browserSupportsSpeechRecognition, rest = _object_without_properties(_useSpeechRecognition, [
2790
- "transcript",
2791
- "listening",
2792
- "resetTranscript",
2793
- "browserSupportsSpeechRecognition"
2794
- ]);
2876
+ useLifecycle();
2877
+ var createMessageProps = useCreateMessage();
2878
+ var _useSpeechRecognition = useSpeechRecognition(), transcript = _useSpeechRecognition.transcript, resetTranscript = _useSpeechRecognition.resetTranscript;
2795
2879
  var transcriptRef = useRef6(transcript);
2796
2880
  useEffect7(function() {
2797
2881
  transcriptRef.current = transcript;
@@ -2813,20 +2897,21 @@ var Root2 = function(param) {
2813
2897
  });
2814
2898
  }),
2815
2899
  onStop: function() {
2816
- var _ref = _async_to_generator(function(_event, chunks) {
2900
+ var _ref = _async_to_generator(function(_event, _chunks) {
2817
2901
  return _ts_generator(this, function(_state) {
2818
2902
  console.log({
2819
2903
  transcript: transcriptRef.current
2820
2904
  });
2821
2905
  return [
2822
2906
  2,
2823
- createThreadMessageProps.createThreadMessage({
2907
+ createMessageProps.createMessage({
2908
+ // @ts-ignore-next-line
2824
2909
  content: transcriptRef.current
2825
2910
  })
2826
2911
  ];
2827
2912
  });
2828
2913
  });
2829
- return function(_event, chunks) {
2914
+ return function(_event, _chunks) {
2830
2915
  return _ref.apply(this, arguments);
2831
2916
  };
2832
2917
  }()
@@ -2843,47 +2928,47 @@ var Root2 = function(param) {
2843
2928
  });
2844
2929
  var status = useStatus({
2845
2930
  recorderProps: recorderProps,
2846
- createThreadMessageProps: createThreadMessageProps,
2931
+ createMessageProps: createMessageProps,
2847
2932
  messageAudioProps: messageAudioProps
2848
2933
  }).status;
2849
- return /* @__PURE__ */ jsx46(AudioThreadContext.Provider, {
2934
+ return /* @__PURE__ */ jsx51(AudioThreadContext.Provider, {
2850
2935
  value: {
2851
2936
  status: status,
2852
2937
  recorderProps: recorderProps,
2853
2938
  messageAudioProps: messageAudioProps
2854
2939
  },
2855
- children: /* @__PURE__ */ jsx46(Flex17, {
2940
+ children: /* @__PURE__ */ jsx51(Flex20, {
2856
2941
  direction: "column",
2857
- grow: "1",
2942
+ flexGrow: "1",
2858
2943
  p: "5",
2859
2944
  children: children
2860
2945
  })
2861
2946
  });
2862
2947
  };
2863
2948
  // src/components/threads/AudioThread/Visualization/index.tsx
2864
- import { Flex as Flex18 } from "@radix-ui/themes";
2949
+ import { Flex as Flex21 } from "@radix-ui/themes";
2865
2950
  // src/hooks/threads/useAudioThreadContext/index.ts
2866
- import { useContext as useContext9 } from "react";
2951
+ import { useContext as useContext10 } from "react";
2867
2952
  var useAudioThreadContext = function() {
2868
- return useContext9(AudioThreadContext);
2953
+ return useContext10(AudioThreadContext);
2869
2954
  };
2870
2955
  // src/components/threads/AudioThread/Visualization/index.tsx
2871
- import { jsx as jsx47 } from "react/jsx-runtime";
2956
+ import { jsx as jsx52 } from "react/jsx-runtime";
2872
2957
  var Visualization = function() {
2873
2958
  var audioThreadContext = useAudioThreadContext();
2874
- return /* @__PURE__ */ jsx47(Flex18, {
2959
+ return /* @__PURE__ */ jsx52(Flex21, {
2875
2960
  direction: "column",
2876
2961
  align: "center",
2877
2962
  justify: "center",
2878
2963
  mb: "3",
2879
- grow: "1",
2880
- children: /* @__PURE__ */ jsx47(Flex18, {
2964
+ flexGrow: "1",
2965
+ children: /* @__PURE__ */ jsx52(Flex21, {
2881
2966
  align: "center",
2882
2967
  justify: "center",
2968
+ height: "200px",
2969
+ width: "200px",
2883
2970
  style: {
2884
2971
  backgroundColor: "var(--".concat(audioThreadContext.status === "playing" ? "mint" : "gray", "-4)"),
2885
- height: "200px",
2886
- width: "200px",
2887
2972
  borderRadius: "9999px"
2888
2973
  }
2889
2974
  })
@@ -2891,13 +2976,13 @@ var Visualization = function() {
2891
2976
  };
2892
2977
  // src/components/threads/AudioThread/Form/index.tsx
2893
2978
  import { SpeakerModerateIcon } from "@radix-ui/react-icons";
2894
- import { Flex as Flex21 } from "@radix-ui/themes";
2979
+ import { Flex as Flex24 } from "@radix-ui/themes";
2895
2980
  // src/components/threads/AudioThread/Form/Visualizer/index.tsx
2896
2981
  import _7 from "lodash";
2897
- import { Flex as Flex19, Grid } from "@radix-ui/themes";
2898
- import { useState as useState4, useEffect as useEffect8, useCallback as useCallback4 } from "react";
2982
+ import { Flex as Flex22, Grid } from "@radix-ui/themes";
2983
+ import { useState as useState4, useEffect as useEffect8, useCallback as useCallback3 } from "react";
2899
2984
  import { cluster } from "radash";
2900
- import { jsx as jsx48 } from "react/jsx-runtime";
2985
+ import { jsx as jsx53 } from "react/jsx-runtime";
2901
2986
  var barCount = 4;
2902
2987
  var Visualizer = function() {
2903
2988
  var audioThreadContext = useAudioThreadContext();
@@ -2906,7 +2991,7 @@ var Visualizer = function() {
2906
2991
  return new AudioContext().createAnalyser();
2907
2992
  }), 1), emptyVisualizer = _useState4[0];
2908
2993
  var _useState41 = _sliced_to_array(useState4([]), 2), barHeights = _useState41[0], setBarHeights = _useState41[1];
2909
- var draw = useCallback4(function(param) {
2994
+ var draw = useCallback3(function(param) {
2910
2995
  var visualizationAnalyser2 = param.visualizationAnalyser;
2911
2996
  var frequencyData = new Uint8Array(visualizationAnalyser2.frequencyBinCount / 15);
2912
2997
  visualizationAnalyser2.getByteFrequencyData(frequencyData);
@@ -2929,7 +3014,7 @@ var Visualizer = function() {
2929
3014
  visualizationAnalyser,
2930
3015
  emptyVisualizer
2931
3016
  ]);
2932
- return /* @__PURE__ */ jsx48(Grid, {
3017
+ return /* @__PURE__ */ jsx53(Grid, {
2933
3018
  columns: "".concat(barCount),
2934
3019
  gap: "1",
2935
3020
  width: "auto",
@@ -2938,21 +3023,19 @@ var Visualizer = function() {
2938
3023
  gridTemplateColumns: "repeat(4, minmax(0, 1fr))"
2939
3024
  },
2940
3025
  children: barHeights.map(function(barHeight, index) {
2941
- return /* @__PURE__ */ jsx48(Flex19, {
3026
+ return /* @__PURE__ */ jsx53(Flex22, {
2942
3027
  direction: "column",
2943
3028
  align: "center",
2944
3029
  justify: "center",
2945
- style: {
2946
- height: "20px"
2947
- },
2948
- children: /* @__PURE__ */ jsx48(Flex19, {
3030
+ height: "20px",
3031
+ children: /* @__PURE__ */ jsx53(Flex22, {
3032
+ minHeight: "50%",
3033
+ maxHeight: "100%",
3034
+ height: "".concat(barHeight + 20, "%"),
3035
+ width: "12px",
2949
3036
  style: {
2950
3037
  backgroundColor: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-11)"),
2951
- borderRadius: "var(--radius-6)",
2952
- height: "".concat(barHeight + 20, "%"),
2953
- minHeight: "50%",
2954
- maxHeight: "100%",
2955
- width: "12px"
3038
+ borderRadius: "var(--radius-6)"
2956
3039
  }
2957
3040
  })
2958
3041
  }, index);
@@ -2960,31 +3043,31 @@ var Visualizer = function() {
2960
3043
  });
2961
3044
  };
2962
3045
  // src/components/threads/AudioThread/Form/ActionButton/index.tsx
2963
- import { Flex as Flex20, IconButton as IconButton2, Tooltip } from "@radix-ui/themes";
3046
+ import { Flex as Flex23, IconButton as IconButton2, Tooltip } from "@radix-ui/themes";
2964
3047
  import { PauseIcon, ArrowUpIcon as ArrowUpIcon2, ResumeIcon } from "@radix-ui/react-icons";
2965
- import { jsx as jsx49, jsxs as jsxs15 } from "react/jsx-runtime";
3048
+ import { jsx as jsx54, jsxs as jsxs16 } from "react/jsx-runtime";
2966
3049
  var ActionButton = function() {
2967
3050
  var audioThreadContext = useAudioThreadContext();
2968
3051
  if (audioThreadContext.status === "recording") {
2969
- return /* @__PURE__ */ jsxs15(Flex20, {
3052
+ return /* @__PURE__ */ jsxs16(Flex23, {
2970
3053
  align: "center",
2971
3054
  children: [
2972
- /* @__PURE__ */ jsx49(Flex20, {
3055
+ /* @__PURE__ */ jsx54(Flex23, {
2973
3056
  mr: "3",
2974
3057
  ml: "-7",
2975
- children: /* @__PURE__ */ jsx49(IconButton2, {
3058
+ children: /* @__PURE__ */ jsx54(IconButton2, {
2976
3059
  onClick: audioThreadContext.recorderProps.pause,
2977
3060
  color: "gray",
2978
3061
  radius: "full",
2979
3062
  size: "1",
2980
- children: /* @__PURE__ */ jsx49(PauseIcon, {})
3063
+ children: /* @__PURE__ */ jsx54(PauseIcon, {})
2981
3064
  })
2982
3065
  }),
2983
- /* @__PURE__ */ jsx49(Tooltip, {
3066
+ /* @__PURE__ */ jsx54(Tooltip, {
2984
3067
  open: true,
2985
3068
  content: "Send your message",
2986
3069
  side: "bottom",
2987
- children: /* @__PURE__ */ jsx49(IconButton2, {
3070
+ children: /* @__PURE__ */ jsx54(IconButton2, {
2988
3071
  onClick: audioThreadContext.recorderProps.stop,
2989
3072
  color: "gray",
2990
3073
  highContrast: true,
@@ -2993,14 +3076,14 @@ var ActionButton = function() {
2993
3076
  style: {
2994
3077
  border: "2px solid var(--gray-8)"
2995
3078
  },
2996
- children: /* @__PURE__ */ jsx49(ArrowUpIcon2, {})
3079
+ children: /* @__PURE__ */ jsx54(ArrowUpIcon2, {})
2997
3080
  })
2998
3081
  })
2999
3082
  ]
3000
3083
  });
3001
3084
  }
3002
3085
  if (audioThreadContext.status === "recorderPaused") {
3003
- return /* @__PURE__ */ jsx49(IconButton2, {
3086
+ return /* @__PURE__ */ jsx54(IconButton2, {
3004
3087
  onClick: audioThreadContext.recorderProps.resume,
3005
3088
  color: "red",
3006
3089
  radius: "full",
@@ -3008,11 +3091,11 @@ var ActionButton = function() {
3008
3091
  style: {
3009
3092
  border: "2px solid var(--gray-8)"
3010
3093
  },
3011
- children: /* @__PURE__ */ jsx49(ResumeIcon, {})
3094
+ children: /* @__PURE__ */ jsx54(ResumeIcon, {})
3012
3095
  });
3013
3096
  }
3014
3097
  if (audioThreadContext.status === "idle") {
3015
- return /* @__PURE__ */ jsx49(IconButton2, {
3098
+ return /* @__PURE__ */ jsx54(IconButton2, {
3016
3099
  onClick: function() {
3017
3100
  return audioThreadContext.recorderProps.start();
3018
3101
  },
@@ -3025,7 +3108,7 @@ var ActionButton = function() {
3025
3108
  });
3026
3109
  }
3027
3110
  if (audioThreadContext.status === "playing") {
3028
- return /* @__PURE__ */ jsx49(IconButton2, {
3111
+ return /* @__PURE__ */ jsx54(IconButton2, {
3029
3112
  onClick: function() {
3030
3113
  return audioThreadContext.messageAudioProps.pause();
3031
3114
  },
@@ -3035,11 +3118,11 @@ var ActionButton = function() {
3035
3118
  style: {
3036
3119
  border: "2px solid var(--gray-8)"
3037
3120
  },
3038
- children: /* @__PURE__ */ jsx49(PauseIcon, {})
3121
+ children: /* @__PURE__ */ jsx54(PauseIcon, {})
3039
3122
  });
3040
3123
  }
3041
3124
  if (audioThreadContext.status === "playerPaused") {
3042
- return /* @__PURE__ */ jsx49(IconButton2, {
3125
+ return /* @__PURE__ */ jsx54(IconButton2, {
3043
3126
  onClick: function() {
3044
3127
  return audioThreadContext.messageAudioProps.play();
3045
3128
  },
@@ -3049,10 +3132,10 @@ var ActionButton = function() {
3049
3132
  style: {
3050
3133
  border: "2px solid var(--gray-8)"
3051
3134
  },
3052
- children: /* @__PURE__ */ jsx49(ResumeIcon, {})
3135
+ children: /* @__PURE__ */ jsx54(ResumeIcon, {})
3053
3136
  });
3054
3137
  }
3055
- return /* @__PURE__ */ jsx49(IconButton2, {
3138
+ return /* @__PURE__ */ jsx54(IconButton2, {
3056
3139
  size: "4",
3057
3140
  color: "red",
3058
3141
  radius: "full",
@@ -3063,140 +3146,141 @@ var ActionButton = function() {
3063
3146
  });
3064
3147
  };
3065
3148
  // src/components/threads/AudioThread/Form/index.tsx
3066
- import { jsx as jsx50, jsxs as jsxs16 } from "react/jsx-runtime";
3149
+ import { jsx as jsx55, jsxs as jsxs17 } from "react/jsx-runtime";
3067
3150
  var Form = function() {
3068
3151
  var audioThreadContext = useAudioThreadContext();
3069
- return /* @__PURE__ */ jsxs16(Flex21, {
3152
+ return /* @__PURE__ */ jsxs17(Flex24, {
3070
3153
  direction: "column",
3071
3154
  align: "center",
3072
3155
  children: [
3073
- /* @__PURE__ */ jsxs16(Flex21, {
3156
+ /* @__PURE__ */ jsxs17(Flex24, {
3074
3157
  pb: "3",
3075
3158
  align: "center",
3076
3159
  children: [
3077
- /* @__PURE__ */ jsx50(Flex21, {
3160
+ /* @__PURE__ */ jsx55(Flex24, {
3078
3161
  ml: "-5",
3079
3162
  mr: "2",
3080
3163
  align: "center",
3081
- children: /* @__PURE__ */ jsx50(SpeakerModerateIcon, {
3164
+ children: /* @__PURE__ */ jsx55(SpeakerModerateIcon, {
3082
3165
  style: {
3083
3166
  color: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-12)")
3084
3167
  }
3085
3168
  })
3086
3169
  }),
3087
- /* @__PURE__ */ jsx50(Flex21, {
3170
+ /* @__PURE__ */ jsx55(Flex24, {
3088
3171
  px: "2",
3089
3172
  py: "1",
3090
3173
  style: {
3091
3174
  backgroundColor: "var(--".concat(audioThreadContext.status === "recording" ? "mint" : "gray", "-4)"),
3092
3175
  borderRadius: "var(--radius-6)"
3093
3176
  },
3094
- children: /* @__PURE__ */ jsx50(Visualizer, {})
3177
+ children: /* @__PURE__ */ jsx55(Visualizer, {})
3095
3178
  })
3096
3179
  ]
3097
3180
  }),
3098
- /* @__PURE__ */ jsx50(ActionButton, {})
3181
+ /* @__PURE__ */ jsx55(ActionButton, {})
3099
3182
  ]
3100
3183
  });
3101
3184
  };
3102
3185
  // src/components/threads/AudioThread/index.tsx
3103
- import { jsx as jsx51, jsxs as jsxs17 } from "react/jsx-runtime";
3186
+ import { jsx as jsx56, jsxs as jsxs18 } from "react/jsx-runtime";
3104
3187
  var AudioThread = function(props) {
3105
- return /* @__PURE__ */ jsxs17(Root2, _object_spread_props(_object_spread({}, props), {
3188
+ return /* @__PURE__ */ jsxs18(Root7, _object_spread_props(_object_spread({}, props), {
3106
3189
  children: [
3107
- /* @__PURE__ */ jsx51(Visualization, {}),
3108
- /* @__PURE__ */ jsx51(Form, {})
3190
+ /* @__PURE__ */ jsx56(Visualization, {}),
3191
+ /* @__PURE__ */ jsx56(Form, {})
3109
3192
  ]
3110
3193
  }));
3111
3194
  };
3112
- AudioThread.Root = Root2;
3195
+ AudioThread.Root = Root7;
3113
3196
  AudioThread.Visualization = Visualization;
3114
3197
  AudioThread.Form = Form;
3115
3198
  // src/components/threads/AudioThreadDialog/index.tsx
3116
- import { jsx as jsx52, jsxs as jsxs18 } from "react/jsx-runtime";
3199
+ import { jsx as jsx57, jsxs as jsxs19 } from "react/jsx-runtime";
3117
3200
  var AudioThreadDialog = function() {
3118
- return /* @__PURE__ */ jsxs18(Root, {
3201
+ return /* @__PURE__ */ jsxs19(Root5, {
3119
3202
  children: [
3120
- /* @__PURE__ */ jsx52(Content4, {
3121
- children: /* @__PURE__ */ jsx52(AudioThread, {})
3203
+ /* @__PURE__ */ jsx57(Content4.Root, {
3204
+ children: /* @__PURE__ */ jsx57(AudioThread, {})
3122
3205
  }),
3123
- /* @__PURE__ */ jsx52(Trigger, {
3124
- children: /* @__PURE__ */ jsx52(Button3, {})
3206
+ /* @__PURE__ */ jsx57(Trigger, {
3207
+ children: /* @__PURE__ */ jsx57(Button3, {})
3125
3208
  })
3126
3209
  ]
3127
3210
  });
3128
3211
  };
3129
- AudioThreadDialog.Root = Root;
3212
+ AudioThreadDialog.Root = Root5;
3130
3213
  AudioThreadDialog.Trigger = Trigger;
3131
3214
  AudioThreadDialog.Button = Button3;
3132
3215
  AudioThreadDialog.Content = Content4;
3133
3216
  // src/components/suggestions/Suggestions/index.tsx
3134
- import { useMemo as useMemo13 } from "react";
3135
- import { Flex as Flex22 } from "@radix-ui/themes";
3217
+ import { useMemo as useMemo14 } from "react";
3218
+ import { Flex as Flex25 } from "@radix-ui/themes";
3136
3219
  // src/components/suggestions/Suggestion/index.tsx
3137
3220
  import { ArrowUpIcon as ArrowUpIcon3 } from "@radix-ui/react-icons";
3138
3221
  import { Text as Text6, Button as Button4 } from "@radix-ui/themes";
3139
- import { jsx as jsx53, jsxs as jsxs19 } from "react/jsx-runtime";
3222
+ import { jsx as jsx58, jsxs as jsxs20 } from "react/jsx-runtime";
3140
3223
  var Suggestion = function(param) {
3141
3224
  var suggestion = param.suggestion;
3142
- var createThreadMessage = useCreateThreadMessage().createThreadMessage;
3225
+ var createMessage = useCreateMessage().createMessage;
3143
3226
  var _useIsRunActive = useIsRunActive(), isRunActive2 = _useIsRunActive.isRunActive;
3144
- return /* @__PURE__ */ jsxs19(Button4, {
3227
+ return /* @__PURE__ */ jsxs20(Button4, {
3145
3228
  variant: "soft",
3146
3229
  style: {
3147
3230
  justifyContent: "space-between"
3148
3231
  },
3149
3232
  onClick: function() {
3150
- createThreadMessage({
3233
+ createMessage({
3234
+ // @ts-ignore-next-line
3151
3235
  content: suggestion
3152
3236
  });
3153
3237
  },
3154
3238
  disabled: isRunActive2,
3155
3239
  children: [
3156
- /* @__PURE__ */ jsx53(Text6, {
3240
+ /* @__PURE__ */ jsx58(Text6, {
3157
3241
  size: "1",
3158
3242
  weight: "regular",
3159
3243
  children: suggestion
3160
3244
  }),
3161
- /* @__PURE__ */ jsx53(ArrowUpIcon3, {})
3245
+ /* @__PURE__ */ jsx58(ArrowUpIcon3, {})
3162
3246
  ]
3163
3247
  });
3164
3248
  };
3165
3249
  // src/components/suggestions/Suggestions/index.tsx
3166
- import { jsx as jsx54 } from "react/jsx-runtime";
3250
+ import { jsx as jsx59 } from "react/jsx-runtime";
3167
3251
  var Suggestions = function(param) {
3168
3252
  var _param_emptyStateSuggestions = param.emptyStateSuggestions, emptyStateSuggestions = _param_emptyStateSuggestions === void 0 ? [] : _param_emptyStateSuggestions, _param_suggestions = param.suggestions, suggestions = _param_suggestions === void 0 ? [] : _param_suggestions;
3169
- var latestThreadMessageProps = useLatestThreadMessage();
3253
+ var latestMessageProps = useLatestMessage();
3170
3254
  var isRunActiveProps = useIsRunActive();
3171
- var isDisabled = useMemo13(function() {
3255
+ var isDisabled = useMemo14(function() {
3172
3256
  var // @ts-ignore-next-line
3173
- _latestThreadMessageProps_latestThreadMessage_metadata, _latestThreadMessageProps_latestThreadMessage;
3174
- return ((_latestThreadMessageProps_latestThreadMessage = latestThreadMessageProps.latestThreadMessage) === null || _latestThreadMessageProps_latestThreadMessage === void 0 ? void 0 : (_latestThreadMessageProps_latestThreadMessage_metadata = _latestThreadMessageProps_latestThreadMessage.metadata) === null || _latestThreadMessageProps_latestThreadMessage_metadata === void 0 ? void 0 : _latestThreadMessageProps_latestThreadMessage_metadata.isBlocking) || isRunActiveProps.isRunActive;
3257
+ _latestMessageProps_latestMessage_metadata, _latestMessageProps_latestMessage;
3258
+ return ((_latestMessageProps_latestMessage = latestMessageProps.latestMessage) === null || _latestMessageProps_latestMessage === void 0 ? void 0 : (_latestMessageProps_latestMessage_metadata = _latestMessageProps_latestMessage.metadata) === null || _latestMessageProps_latestMessage_metadata === void 0 ? void 0 : _latestMessageProps_latestMessage_metadata.isBlocking) || isRunActiveProps.isRunActive;
3175
3259
  }, [
3176
- latestThreadMessageProps,
3260
+ latestMessageProps,
3177
3261
  isRunActiveProps
3178
3262
  ]);
3179
- if (latestThreadMessageProps.isLoading) return null;
3263
+ if (latestMessageProps.isLoading) return null;
3180
3264
  if (isDisabled) return null;
3181
- if (!latestThreadMessageProps.latestThreadMessage && emptyStateSuggestions.length > 0) {
3182
- return /* @__PURE__ */ jsx54(Flex22, {
3265
+ if (!latestMessageProps.latestMessage && emptyStateSuggestions.length > 0) {
3266
+ return /* @__PURE__ */ jsx59(Flex25, {
3183
3267
  gap: "2",
3184
3268
  py: "2",
3185
3269
  wrap: "wrap",
3186
3270
  children: emptyStateSuggestions.map(function(suggestion) {
3187
- return /* @__PURE__ */ jsx54(Suggestion, {
3271
+ return /* @__PURE__ */ jsx59(Suggestion, {
3188
3272
  suggestion: suggestion
3189
3273
  }, suggestion);
3190
3274
  })
3191
3275
  });
3192
3276
  }
3193
- if (latestThreadMessageProps.latestThreadMessage.role === "assistant") {
3194
- return /* @__PURE__ */ jsx54(Flex22, {
3277
+ if (latestMessageProps.latestMessage.role === "assistant") {
3278
+ return /* @__PURE__ */ jsx59(Flex25, {
3195
3279
  gap: "2",
3196
3280
  py: "2",
3197
3281
  wrap: "wrap",
3198
3282
  children: suggestions.map(function(suggestion) {
3199
- return /* @__PURE__ */ jsx54(Suggestion, {
3283
+ return /* @__PURE__ */ jsx59(Suggestion, {
3200
3284
  suggestion: suggestion
3201
3285
  }, suggestion);
3202
3286
  })
@@ -3205,9 +3289,9 @@ var Suggestions = function(param) {
3205
3289
  return null;
3206
3290
  };
3207
3291
  // src/hooks/markdown/useMarkdownContext/index.ts
3208
- import { useContext as useContext10 } from "react";
3292
+ import { useContext as useContext11 } from "react";
3209
3293
  var useMarkdownContext = function() {
3210
- return useContext10(MarkdownContext);
3294
+ return useContext11(MarkdownContext);
3211
3295
  };
3212
- export { AssistantAvatarContext, AssistantNameContext, AudioThread, AudioThreadDialog, FunctionBase, FunctionComponentsContext, MarkdownContext, Suggestion, Suggestions, SuperinterfaceProvider, Thread, ThreadDialog, ThreadMessageForm, ThreadMessages, SuperinterfaceProvider as ThreadProvider, useCreateRun, useCreateThreadMessage, useIsRunActive, useLatestRun, useLatestThreadMessage, useMarkdownContext, useRuns, useSuperinterfaceContext, useSuperinterfaceContext as useThreadContext, useThreadLifecycles, useThreadMessages };
3296
+ export { AssistantAvatarContext, AssistantNameContext, AudioThread, AudioThreadDialog, FunctionBase, FunctionComponentsContext, MarkdownContext, Suggestion, Suggestions, SuperinterfaceProvider, Thread, ThreadDialog, ThreadDialogContext, useCreateMessage, useCreateRun, useIsRunActive, useLatestMessage, useLatestRun, useLifecycle, useMarkdownContext, useMessages, useRuns, useSuperinterfaceContext, useSuperinterfaceContext as useThreadContext };
3213
3297
  //# sourceMappingURL=index.js.map