@superinterface/react 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +41 -0
- package/src/components/examples/Examples/Example/index.tsx +65 -0
- package/src/components/examples/Examples/index.tsx +85 -0
- package/src/components/messageGroups/MessagesGroupBase/AssistantAvatar.tsx +18 -0
- package/src/components/messageGroups/MessagesGroupBase/Name.tsx +24 -0
- package/src/components/messageGroups/MessagesGroupBase/index.tsx +29 -0
- package/src/components/messages/Form/Submit/index.tsx +29 -0
- package/src/components/messages/Form/index.tsx +150 -0
- package/src/components/messages/Message/TextContent/index.tsx +22 -0
- package/src/components/messages/Message/index.tsx +71 -0
- package/src/components/messages/Messages/Content/MessageGroup/Content/index.tsx +22 -0
- package/src/components/messages/Messages/Content/MessageGroup/index.tsx +47 -0
- package/src/components/messages/Messages/Content/index.tsx +26 -0
- package/src/components/messages/Messages/ProgressMessage/index.tsx +31 -0
- package/src/components/messages/Messages/index.tsx +102 -0
- package/src/components/runSteps/RunStep/ToolCalls/Starting/index.tsx +28 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/CodeInterpreter/index.tsx +17 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Availabilities/Title.tsx +29 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Availabilities/index.tsx +34 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Content/index.tsx +58 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Icon.tsx +28 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Scores/Title.tsx +29 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/Scores/index.tsx +34 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/Fn/index.tsx +31 -0
- package/src/components/runSteps/RunStep/ToolCalls/ToolCall/index.tsx +44 -0
- package/src/components/runSteps/RunStep/ToolCalls/index.tsx +31 -0
- package/src/components/runSteps/RunStep/index.tsx +21 -0
- package/src/components/runSteps/RunSteps/index.tsx +22 -0
- package/src/components/skeletons/MessagesSkeleton/index.tsx +50 -0
- package/src/components/skeletons/RunSkeleton/index.tsx +34 -0
- package/src/components/skeletons/Skeleton/index.tsx +17 -0
- package/src/components/skeletons/StartingContentSkeleton/index.tsx +13 -0
- package/src/components/skeletons/StartingSkeleton/index.tsx +33 -0
- package/src/components/spinners/Spinner/index.tsx +17 -0
- package/src/components/textareas/TextareaBase/index.tsx +28 -0
- package/src/components/toolCalls/ToolCallBase/ToolCallTitle.tsx +17 -0
- package/src/components/toolCalls/ToolCallBase/index.tsx +34 -0
- package/src/contexts/assistants/AssistantNameContext/index.tsx +3 -0
- package/src/contexts/avatars/AssistantAvatarContext/index.tsx +14 -0
- package/src/contexts/markdown/MarkdownContext/index.ts +7 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/Link.tsx +13 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/ListItem.tsx +13 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/OrderedList.tsx +16 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/Paragraph.tsx +17 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/Strong.tsx +9 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/UnorderedList.tsx +16 -0
- package/src/contexts/markdown/MarkdownContext/lib/components/index.tsx +16 -0
- package/src/hooks/actions/useHandleAction/index.tsx +30 -0
- package/src/hooks/actions/useHandleAction/lib/mutationOptions/index.ts +14 -0
- package/src/hooks/actions/useHandleAction/lib/mutationOptions/mutationFn/index.ts +39 -0
- package/src/hooks/actions/useHandleAction/lib/mutationOptions/mutationFn/toolOutput/index.ts +29 -0
- package/src/hooks/actions/useHandleAction/lib/mutationOptions/onSettled.ts +22 -0
- package/src/hooks/actions/useManageActions/index.tsx +43 -0
- package/src/hooks/messageGroups/useMessageGroups/index.ts +18 -0
- package/src/hooks/messageGroups/useMessageGroups/lib/messageGroups/index.ts +37 -0
- package/src/hooks/messageGroups/useMessageGroups/lib/messageGroups/newGroup/index.ts +14 -0
- package/src/hooks/messageGroups/useMessageGroups/lib/messageGroups/newGroup/newGroupItem.ts +12 -0
- package/src/hooks/messages/useCreateMessage/index.ts +30 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/index.ts +24 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn.ts +25 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/onError.ts +27 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/data.ts +62 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/onMutate/index.ts +25 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/onSettled.ts +16 -0
- package/src/hooks/messages/useCreateMessage/lib/mutationOptions/onSuccess.ts +48 -0
- package/src/hooks/messages/useLatestMessage/index.ts +20 -0
- package/src/hooks/messages/useMessages/index.tsx +41 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/index.ts +20 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryFn/data/index.ts +32 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryFn/data/runMessages/getLatestRun.ts +15 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryFn/data/runMessages/index.ts +44 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryFn/hasNextPage.ts +12 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryFn/index.ts +32 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryFn/messagesLimit.ts +1 -0
- package/src/hooks/messages/useMessages/lib/queryOptions/queryKey.ts +3 -0
- package/src/hooks/misc/useInfiniteScroll/index.tsx +42 -0
- package/src/hooks/misc/useThrottledEffect/index.tsx +19 -0
- package/src/hooks/runs/useCreateRun/index.ts +30 -0
- package/src/hooks/runs/useCreateRun/lib/mutationOptions/index.ts +16 -0
- package/src/hooks/runs/useCreateRun/lib/mutationOptions/mutationFn.ts +30 -0
- package/src/hooks/runs/useCreateRun/lib/mutationOptions/onSettled.ts +22 -0
- package/src/hooks/runs/useCreateRun/lib/mutationOptions/onSuccess.ts +44 -0
- package/src/hooks/runs/useIsRunActive/index.tsx +65 -0
- package/src/hooks/runs/useLatestRun/index.ts +20 -0
- package/src/hooks/runs/useManageRuns/index.tsx +55 -0
- package/src/hooks/runs/usePolling/index.tsx +39 -0
- package/src/hooks/runs/usePolling/lib/refetch.ts +20 -0
- package/src/hooks/runs/useRuns/index.tsx +27 -0
- package/src/hooks/runs/useRuns/lib/getRuns.ts +16 -0
- package/src/hooks/runs/useRuns/lib/queryOptions/index.ts +21 -0
- package/src/hooks/runs/useRuns/lib/queryOptions/queryFn.ts +22 -0
- package/src/hooks/runs/useRuns/lib/queryOptions/queryKey.ts +3 -0
- package/src/hooks/threads/useThreadLifecycles/index.tsx +41 -0
- package/src/index.ts +12 -0
- package/src/lib/ai/index.ts +15 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/messages/extendMessage.ts +25 -0
- package/src/lib/messages/order.ts +9 -0
- package/src/lib/optimistic/isOptimistic.ts +11 -0
- package/src/lib/optimistic/optimisticId.ts +5 -0
- package/src/lib/runSteps/getRunSteps/index.ts +18 -0
- package/src/lib/runs/isRunEditingMessage/index.ts +21 -0
- package/src/mutationFns.ts +3 -0
- package/src/queryFns.ts +2 -0
- package/src/queryKeys.ts +2 -0
- package/src/types/index.ts +38 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import {
|
|
3
|
+
UseInfiniteQueryOptions,
|
|
4
|
+
UseMutationOptions,
|
|
5
|
+
InfiniteData,
|
|
6
|
+
} from '@tanstack/react-query'
|
|
7
|
+
import {
|
|
8
|
+
Flex,
|
|
9
|
+
} from '@radix-ui/themes'
|
|
10
|
+
import { useInfiniteScroll } from '@/hooks/misc/useInfiniteScroll'
|
|
11
|
+
import { MessagesSkeleton } from '@/components/skeletons/MessagesSkeleton'
|
|
12
|
+
import { useMessages } from '@/hooks/messages/useMessages'
|
|
13
|
+
import { useThreadLifecycles } from '@/hooks/threads/useThreadLifecycles'
|
|
14
|
+
import { useLatestMessage } from '@/hooks/messages/useLatestMessage'
|
|
15
|
+
import { useIsRunActive } from '@/hooks/runs/useIsRunActive'
|
|
16
|
+
import { Content } from './Content'
|
|
17
|
+
import { ProgressMessage } from './ProgressMessage'
|
|
18
|
+
import { MessagesPage, RunsPage, Run } from '@/types'
|
|
19
|
+
|
|
20
|
+
type Args = {
|
|
21
|
+
messagesQueryOptions: UseInfiniteQueryOptions<InfiniteData<MessagesPage>>
|
|
22
|
+
runsQueryOptions: UseInfiniteQueryOptions<InfiniteData<RunsPage>>
|
|
23
|
+
createRunMutationOptions: UseMutationOptions<{ run: Run }>
|
|
24
|
+
handleActionMutationOptions: UseMutationOptions<{ run: Run }>
|
|
25
|
+
children?: React.ReactNode
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Messages = ({
|
|
29
|
+
messagesQueryOptions,
|
|
30
|
+
runsQueryOptions,
|
|
31
|
+
createRunMutationOptions,
|
|
32
|
+
handleActionMutationOptions,
|
|
33
|
+
children,
|
|
34
|
+
}: Args) => {
|
|
35
|
+
const {
|
|
36
|
+
messages,
|
|
37
|
+
isFetchingNextPage,
|
|
38
|
+
hasNextPage,
|
|
39
|
+
fetchNextPage,
|
|
40
|
+
} = useMessages({
|
|
41
|
+
messagesQueryOptions,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
useThreadLifecycles({
|
|
45
|
+
messagesQueryOptions,
|
|
46
|
+
runsQueryOptions,
|
|
47
|
+
createRunMutationOptions,
|
|
48
|
+
handleActionMutationOptions,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const { containerRef, loaderRef } = useInfiniteScroll({
|
|
52
|
+
isFetchingNextPage,
|
|
53
|
+
hasNextPage,
|
|
54
|
+
fetchNextPage,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const { isRunActive } = useIsRunActive({
|
|
58
|
+
messagesQueryOptions,
|
|
59
|
+
runsQueryOptions,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const { latestMessage } = useLatestMessage({
|
|
63
|
+
messagesQueryOptions,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Flex
|
|
68
|
+
ref={containerRef}
|
|
69
|
+
direction="column-reverse"
|
|
70
|
+
className="overflow-auto"
|
|
71
|
+
grow="1"
|
|
72
|
+
p="2"
|
|
73
|
+
>
|
|
74
|
+
<Flex
|
|
75
|
+
shrink="0"
|
|
76
|
+
height="1"
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
<ProgressMessage
|
|
80
|
+
latestMessage={latestMessage}
|
|
81
|
+
isRunActive={isRunActive}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
{children}
|
|
85
|
+
|
|
86
|
+
<Content
|
|
87
|
+
messages={messages}
|
|
88
|
+
/>
|
|
89
|
+
|
|
90
|
+
{hasNextPage && (
|
|
91
|
+
<MessagesSkeleton
|
|
92
|
+
ref={loaderRef}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
|
|
96
|
+
<Flex
|
|
97
|
+
shrink="0"
|
|
98
|
+
grow="1"
|
|
99
|
+
/>
|
|
100
|
+
</Flex>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PopoverRoot,
|
|
3
|
+
PopoverContent,
|
|
4
|
+
Text,
|
|
5
|
+
} from '@radix-ui/themes'
|
|
6
|
+
import {
|
|
7
|
+
CircleIcon,
|
|
8
|
+
} from '@radix-ui/react-icons'
|
|
9
|
+
import { ToolCallBase } from '@/components/toolCalls/ToolCallBase'
|
|
10
|
+
import { ToolCallTitle } from '@/components/toolCalls/ToolCallBase/ToolCallTitle'
|
|
11
|
+
|
|
12
|
+
export const Starting = () => (
|
|
13
|
+
<PopoverRoot>
|
|
14
|
+
<ToolCallBase>
|
|
15
|
+
<CircleIcon />
|
|
16
|
+
<ToolCallTitle>
|
|
17
|
+
Starting actions
|
|
18
|
+
</ToolCallTitle>
|
|
19
|
+
</ToolCallBase>
|
|
20
|
+
<PopoverContent
|
|
21
|
+
className="max-h-[500px]"
|
|
22
|
+
>
|
|
23
|
+
<Text>
|
|
24
|
+
Getting ready to connect to domain API
|
|
25
|
+
</Text>
|
|
26
|
+
</PopoverContent>
|
|
27
|
+
</PopoverRoot>
|
|
28
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import {
|
|
3
|
+
Flex,
|
|
4
|
+
} from '@radix-ui/themes'
|
|
5
|
+
|
|
6
|
+
type Args = {
|
|
7
|
+
codeInterpreter: OpenAI.Beta.Threads.Runs.CodeToolCall.CodeInterpreter
|
|
8
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const CodeInterpreter = ({
|
|
12
|
+
codeInterpreter,
|
|
13
|
+
}: Args) => (
|
|
14
|
+
<Flex>
|
|
15
|
+
{codeInterpreter.input}
|
|
16
|
+
</Flex>
|
|
17
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
|
|
3
|
+
type Args = {
|
|
4
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const Title = ({
|
|
8
|
+
runStep,
|
|
9
|
+
}: Args) => {
|
|
10
|
+
if (runStep.completed_at) {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
Finished getting domains availability
|
|
14
|
+
</>
|
|
15
|
+
)
|
|
16
|
+
} else if (runStep.cancelled_at) {
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
Cancelled getting domains availability
|
|
20
|
+
</>
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
Getting domains availability
|
|
26
|
+
</>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import {
|
|
3
|
+
PopoverRoot,
|
|
4
|
+
PopoverContent,
|
|
5
|
+
} from '@radix-ui/themes'
|
|
6
|
+
import { ToolCallBase } from '@/components/toolCalls/ToolCallBase'
|
|
7
|
+
import { ToolCallTitle } from '@/components/toolCalls/ToolCallBase/ToolCallTitle'
|
|
8
|
+
import { Icon } from '../Icon'
|
|
9
|
+
import { Content } from '../Content'
|
|
10
|
+
import { Title } from './Title'
|
|
11
|
+
|
|
12
|
+
type Args = {
|
|
13
|
+
fn: OpenAI.Beta.Threads.Runs.FunctionToolCall.Function
|
|
14
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Availabilities = ({
|
|
18
|
+
fn,
|
|
19
|
+
runStep,
|
|
20
|
+
}: Args) => (
|
|
21
|
+
<PopoverRoot>
|
|
22
|
+
<ToolCallBase>
|
|
23
|
+
<Icon runStep={runStep} />
|
|
24
|
+
<ToolCallTitle>
|
|
25
|
+
<Title runStep={runStep} />
|
|
26
|
+
</ToolCallTitle>
|
|
27
|
+
</ToolCallBase>
|
|
28
|
+
<PopoverContent
|
|
29
|
+
className="max-h-[500px]"
|
|
30
|
+
>
|
|
31
|
+
<Content fn={fn} />
|
|
32
|
+
</PopoverContent>
|
|
33
|
+
</PopoverRoot>
|
|
34
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { Code, Box } from '@radix-ui/themes'
|
|
3
|
+
import OpenAI from 'openai'
|
|
4
|
+
|
|
5
|
+
type Args = {
|
|
6
|
+
fn: OpenAI.Beta.Threads.Runs.FunctionToolCall.Function
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const Content = ({
|
|
10
|
+
fn,
|
|
11
|
+
}: Args) => {
|
|
12
|
+
const args = useMemo(() => {
|
|
13
|
+
let result = null
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
result = JSON.parse(fn.arguments)
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error(error)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return result
|
|
22
|
+
}, [fn])
|
|
23
|
+
|
|
24
|
+
const output = useMemo(() => {
|
|
25
|
+
if (!fn.output) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let result = null
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
result = JSON.parse(fn.output)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(error)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result
|
|
38
|
+
}, [fn])
|
|
39
|
+
|
|
40
|
+
if (!args) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Code
|
|
46
|
+
variant="ghost"
|
|
47
|
+
color="gold"
|
|
48
|
+
className="whitespace-pre break-words"
|
|
49
|
+
>
|
|
50
|
+
<Box>
|
|
51
|
+
{args && JSON.stringify(args, null, 2)}
|
|
52
|
+
</Box>
|
|
53
|
+
<Box>
|
|
54
|
+
{output && JSON.stringify(output, null, 2)}
|
|
55
|
+
</Box>
|
|
56
|
+
</Code>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import {
|
|
3
|
+
CircleIcon,
|
|
4
|
+
CircleBackslashIcon,
|
|
5
|
+
CheckCircledIcon,
|
|
6
|
+
} from '@radix-ui/react-icons'
|
|
7
|
+
|
|
8
|
+
type Args = {
|
|
9
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Icon = ({
|
|
13
|
+
runStep,
|
|
14
|
+
}: Args) => {
|
|
15
|
+
if (runStep.completed_at) {
|
|
16
|
+
return (
|
|
17
|
+
<CheckCircledIcon />
|
|
18
|
+
)
|
|
19
|
+
} else if (runStep.cancelled_at) {
|
|
20
|
+
return (
|
|
21
|
+
<CircleBackslashIcon />
|
|
22
|
+
)
|
|
23
|
+
} else {
|
|
24
|
+
return (
|
|
25
|
+
<CircleIcon />
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
|
|
3
|
+
type Args = {
|
|
4
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const Title = ({
|
|
8
|
+
runStep,
|
|
9
|
+
}: Args) => {
|
|
10
|
+
if (runStep.completed_at) {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
Finished getting domains scores
|
|
14
|
+
</>
|
|
15
|
+
)
|
|
16
|
+
} else if (runStep.cancelled_at) {
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
Cancelled getting domains scores
|
|
20
|
+
</>
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
Getting domains scores
|
|
26
|
+
</>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import {
|
|
3
|
+
PopoverRoot,
|
|
4
|
+
PopoverContent,
|
|
5
|
+
} from '@radix-ui/themes'
|
|
6
|
+
import { ToolCallBase } from '@/components/toolCalls/ToolCallBase'
|
|
7
|
+
import { ToolCallTitle } from '@/components/toolCalls/ToolCallBase/ToolCallTitle'
|
|
8
|
+
import { Icon } from '../Icon'
|
|
9
|
+
import { Content } from '../Content'
|
|
10
|
+
import { Title } from './Title'
|
|
11
|
+
|
|
12
|
+
type Args = {
|
|
13
|
+
fn: OpenAI.Beta.Threads.Runs.FunctionToolCall.Function
|
|
14
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Scores = ({
|
|
18
|
+
fn,
|
|
19
|
+
runStep,
|
|
20
|
+
}: Args) => (
|
|
21
|
+
<PopoverRoot>
|
|
22
|
+
<ToolCallBase>
|
|
23
|
+
<Icon runStep={runStep} />
|
|
24
|
+
<ToolCallTitle>
|
|
25
|
+
<Title runStep={runStep} />
|
|
26
|
+
</ToolCallTitle>
|
|
27
|
+
</ToolCallBase>
|
|
28
|
+
<PopoverContent
|
|
29
|
+
className="max-h-[500px]"
|
|
30
|
+
>
|
|
31
|
+
<Content fn={fn} />
|
|
32
|
+
</PopoverContent>
|
|
33
|
+
</PopoverRoot>
|
|
34
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import { Availabilities } from './Availabilities'
|
|
3
|
+
import { Scores } from './Scores'
|
|
4
|
+
|
|
5
|
+
type Args = {
|
|
6
|
+
fn: OpenAI.Beta.Threads.Runs.FunctionToolCall.Function
|
|
7
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Fn = ({
|
|
11
|
+
fn,
|
|
12
|
+
runStep,
|
|
13
|
+
}: Args) => {
|
|
14
|
+
if (fn.name === 'getAvailabilities') {
|
|
15
|
+
return (
|
|
16
|
+
<Availabilities
|
|
17
|
+
fn={fn}
|
|
18
|
+
runStep={runStep}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
} else if (fn.name === 'getScores') {
|
|
22
|
+
return (
|
|
23
|
+
<Scores
|
|
24
|
+
fn={fn}
|
|
25
|
+
runStep={runStep}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import {
|
|
3
|
+
Flex,
|
|
4
|
+
} from '@radix-ui/themes'
|
|
5
|
+
import { Fn } from './Fn'
|
|
6
|
+
import { CodeInterpreter } from './CodeInterpreter'
|
|
7
|
+
|
|
8
|
+
type ToolCall = OpenAI.Beta.Threads.Runs.CodeToolCall
|
|
9
|
+
| OpenAI.Beta.Threads.Runs.RetrievalToolCall
|
|
10
|
+
| OpenAI.Beta.Threads.Runs.FunctionToolCall
|
|
11
|
+
|
|
12
|
+
type Args = {
|
|
13
|
+
toolCall: ToolCall
|
|
14
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ToolCall = ({
|
|
18
|
+
toolCall,
|
|
19
|
+
runStep,
|
|
20
|
+
}: Args) => {
|
|
21
|
+
if (toolCall.type === 'function') {
|
|
22
|
+
return (
|
|
23
|
+
<Fn
|
|
24
|
+
fn={toolCall.function}
|
|
25
|
+
runStep={runStep}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (toolCall.type === 'code_interpreter') {
|
|
31
|
+
return (
|
|
32
|
+
<CodeInterpreter
|
|
33
|
+
codeInterpreter={toolCall.code_interpreter}
|
|
34
|
+
runStep={runStep}
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Flex>
|
|
41
|
+
{toolCall.type}
|
|
42
|
+
</Flex>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import {
|
|
3
|
+
Flex,
|
|
4
|
+
} from '@radix-ui/themes'
|
|
5
|
+
import { ToolCall } from './ToolCall'
|
|
6
|
+
import { Starting } from './Starting'
|
|
7
|
+
|
|
8
|
+
type Args = {
|
|
9
|
+
stepDetails: OpenAI.Beta.Threads.Runs.ToolCallsStepDetails
|
|
10
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ToolCalls = ({
|
|
14
|
+
stepDetails,
|
|
15
|
+
runStep,
|
|
16
|
+
}: Args) => (
|
|
17
|
+
<Flex
|
|
18
|
+
direction="column"
|
|
19
|
+
>
|
|
20
|
+
{!stepDetails.tool_calls.length && (
|
|
21
|
+
<Starting />
|
|
22
|
+
)}
|
|
23
|
+
{stepDetails.tool_calls.map((toolCall) => (
|
|
24
|
+
<ToolCall
|
|
25
|
+
key={toolCall.id}
|
|
26
|
+
toolCall={toolCall}
|
|
27
|
+
runStep={runStep}
|
|
28
|
+
/>
|
|
29
|
+
))}
|
|
30
|
+
</Flex>
|
|
31
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import { ToolCalls } from './ToolCalls'
|
|
3
|
+
|
|
4
|
+
type Args = {
|
|
5
|
+
runStep: OpenAI.Beta.Threads.Runs.RunStep
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const RunStep = ({
|
|
9
|
+
runStep,
|
|
10
|
+
}: Args) => {
|
|
11
|
+
if (runStep.step_details.type === 'tool_calls') {
|
|
12
|
+
return (
|
|
13
|
+
<ToolCalls
|
|
14
|
+
stepDetails={runStep.step_details}
|
|
15
|
+
runStep={runStep}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import { Flex } from '@radix-ui/themes'
|
|
3
|
+
import { RunStep } from '@/components/runSteps/RunStep'
|
|
4
|
+
|
|
5
|
+
type Args = {
|
|
6
|
+
runSteps: OpenAI.Beta.Threads.Runs.RunStep[]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const RunSteps = ({
|
|
10
|
+
runSteps,
|
|
11
|
+
}: Args) => (
|
|
12
|
+
<Flex
|
|
13
|
+
direction="column-reverse"
|
|
14
|
+
>
|
|
15
|
+
{runSteps.map((runStep) => (
|
|
16
|
+
<RunStep
|
|
17
|
+
key={runStep.id}
|
|
18
|
+
runStep={runStep}
|
|
19
|
+
/>
|
|
20
|
+
))}
|
|
21
|
+
</Flex>
|
|
22
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { forwardRef } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Flex,
|
|
4
|
+
Avatar,
|
|
5
|
+
Box,
|
|
6
|
+
} from '@radix-ui/themes'
|
|
7
|
+
import { Skeleton } from '@/components/skeletons/Skeleton'
|
|
8
|
+
import { MessagesGroupBase } from '@/components/messageGroups/MessagesGroupBase'
|
|
9
|
+
import { Name } from '@/components/messageGroups/MessagesGroupBase/Name'
|
|
10
|
+
|
|
11
|
+
export const MessagesSkeleton = forwardRef(function MessagesSkeleton(_props, ref) {
|
|
12
|
+
return (
|
|
13
|
+
<MessagesGroupBase
|
|
14
|
+
// @ts-ignore-next-line
|
|
15
|
+
ref={ref}
|
|
16
|
+
>
|
|
17
|
+
<Avatar
|
|
18
|
+
fallback={<Flex />}
|
|
19
|
+
size="1"
|
|
20
|
+
className="animate-pulse"
|
|
21
|
+
/>
|
|
22
|
+
|
|
23
|
+
<Box
|
|
24
|
+
pb="3"
|
|
25
|
+
>
|
|
26
|
+
<Name>
|
|
27
|
+
<Skeleton
|
|
28
|
+
height="1"
|
|
29
|
+
className="w-[128px]"
|
|
30
|
+
/>
|
|
31
|
+
</Name>
|
|
32
|
+
|
|
33
|
+
<Skeleton
|
|
34
|
+
height="2"
|
|
35
|
+
className="w-[256px]"
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
<Skeleton
|
|
39
|
+
height="2"
|
|
40
|
+
className="w-[256px] mt-2"
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
<Skeleton
|
|
44
|
+
height="2"
|
|
45
|
+
className="w-[256px] mt-2"
|
|
46
|
+
/>
|
|
47
|
+
</Box>
|
|
48
|
+
</MessagesGroupBase>
|
|
49
|
+
)
|
|
50
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Flex,
|
|
3
|
+
Button,
|
|
4
|
+
} from '@radix-ui/themes'
|
|
5
|
+
import {
|
|
6
|
+
CircleIcon,
|
|
7
|
+
} from '@radix-ui/react-icons'
|
|
8
|
+
import { Skeleton } from '@/components/skeletons/Skeleton'
|
|
9
|
+
|
|
10
|
+
export const RunSkeleton = () => (
|
|
11
|
+
<Flex
|
|
12
|
+
py="1"
|
|
13
|
+
ml="-2"
|
|
14
|
+
>
|
|
15
|
+
<Button
|
|
16
|
+
disabled
|
|
17
|
+
size="1"
|
|
18
|
+
color="gold"
|
|
19
|
+
variant="outline"
|
|
20
|
+
style={{
|
|
21
|
+
boxShadow: 'none',
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
<CircleIcon
|
|
25
|
+
className="animate-pulse"
|
|
26
|
+
/>
|
|
27
|
+
|
|
28
|
+
<Skeleton
|
|
29
|
+
height="1"
|
|
30
|
+
className="w-[128px] bg-gold-5"
|
|
31
|
+
/>
|
|
32
|
+
</Button>
|
|
33
|
+
</Flex>
|
|
34
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Flex } from '@radix-ui/themes'
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
height: string
|
|
5
|
+
className: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const Skeleton = ({
|
|
9
|
+
className,
|
|
10
|
+
...rest
|
|
11
|
+
}: Props) => (
|
|
12
|
+
// @ts-ignore-next-line
|
|
13
|
+
<Flex
|
|
14
|
+
className={`animate-pulse rounded-3 bg-gray-5 ${className}`}
|
|
15
|
+
{...rest}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { Box } from '@radix-ui/themes'
|
|
3
|
+
import { StartingContentSkeleton } from '@/components/skeletons/StartingContentSkeleton'
|
|
4
|
+
import { MessagesGroupBase } from '@/components/messageGroups/MessagesGroupBase'
|
|
5
|
+
import { Name } from '@/components/messageGroups/MessagesGroupBase/Name'
|
|
6
|
+
import { AssistantAvatar } from '@/components/messageGroups/MessagesGroupBase/AssistantAvatar'
|
|
7
|
+
import { AssistantNameContext } from '@/contexts/assistants/AssistantNameContext'
|
|
8
|
+
|
|
9
|
+
type Args = {
|
|
10
|
+
children?: React.ReactNode
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const StartingSkeleton = ({
|
|
14
|
+
children,
|
|
15
|
+
}: Args) => {
|
|
16
|
+
const assistantNameContext = useContext(AssistantNameContext)
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<MessagesGroupBase>
|
|
20
|
+
<AssistantAvatar />
|
|
21
|
+
|
|
22
|
+
<Box>
|
|
23
|
+
<Name>
|
|
24
|
+
{assistantNameContext}
|
|
25
|
+
</Name>
|
|
26
|
+
|
|
27
|
+
{children}
|
|
28
|
+
|
|
29
|
+
<StartingContentSkeleton />
|
|
30
|
+
</Box>
|
|
31
|
+
</MessagesGroupBase>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const Spinner = (props: React.SVGProps<SVGSVGElement>) => (
|
|
2
|
+
<svg
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
width="24"
|
|
5
|
+
height="24"
|
|
6
|
+
viewBox="0 0 24 24"
|
|
7
|
+
fill="none"
|
|
8
|
+
stroke="currentColor"
|
|
9
|
+
strokeWidth="2"
|
|
10
|
+
strokeLinecap="round"
|
|
11
|
+
strokeLinejoin="round"
|
|
12
|
+
className="h-4 w-4 animate-spin"
|
|
13
|
+
{...props}
|
|
14
|
+
>
|
|
15
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
16
|
+
</svg>
|
|
17
|
+
)
|