Skip to content

Commit

Permalink
⬆️ Upgrade AI SDK (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno authored Jul 15, 2024
1 parent a4fb8b6 commit 043f005
Show file tree
Hide file tree
Showing 60 changed files with 2,183 additions and 1,683 deletions.
1 change: 0 additions & 1 deletion apps/builder/public/templates/openai-assistant-chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"options": {
"credentialsId": "clvqq3hey0007pub4almxnhk2",
"action": "Ask Assistant",
"assistantId": "asst_jy7aW39QWtAcVDrLOBr2JSWo",
"threadVariableId": "vf5gxmpqddsy4qugev6o0qs5c",
"message": "{{User last message}}",
"responseMapping": [{ "variableId": "vn8h1gigkjwv40godw2hrgclh" }]
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export const FilmIcon = (props: IconProps) => (
</Icon>
)

export const WebhookIcon = (props: IconProps) => (
export const ThunderIcon = (props: IconProps) => (
<Icon viewBox="0 0 24 24" {...featherIconsBaseProps} {...props}>
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon>
</Icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WebhookIcon } from '@/components/icons'
import { ThunderIcon } from '@/components/icons'
import { IconProps } from '@chakra-ui/react'
import React from 'react'

export const HttpRequestIcon = (props: IconProps) => <WebhookIcon {...props} />
export const HttpRequestIcon = (props: IconProps) => <ThunderIcon {...props} />
4 changes: 2 additions & 2 deletions apps/builder/src/features/editor/components/BlockIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useColorModeValue } from '@chakra-ui/react'
import React from 'react'
import { FlagIcon, SendEmailIcon, WebhookIcon } from '@/components/icons'
import { FlagIcon, SendEmailIcon, ThunderIcon } from '@/components/icons'
import { WaitIcon } from '@/features/blocks/logic/wait/components/WaitIcon'
import { ScriptIcon } from '@/features/blocks/logic/script/components/ScriptIcon'
import { JumpIcon } from '@/features/blocks/logic/jump/components/JumpIcon'
Expand Down Expand Up @@ -103,7 +103,7 @@ export const BlockIcon = ({ type, mt }: BlockIconProps): JSX.Element => {
case IntegrationBlockType.GOOGLE_ANALYTICS:
return <GoogleAnalyticsLogo mt={mt} />
case IntegrationBlockType.WEBHOOK:
return <WebhookIcon mt={mt} />
return <ThunderIcon mt={mt} />
case IntegrationBlockType.ZAPIER:
return <ZapierLogo mt={mt} />
case IntegrationBlockType.MAKE_COM:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
import { SetVariableLabel } from '@/components/SetVariableLabel'
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
import { Stack, Text } from '@chakra-ui/react'
import { Flex, Stack, Text, Tooltip } from '@chakra-ui/react'
import { useForgedBlock } from '../hooks/useForgedBlock'
import { ForgedBlock } from '@typebot.io/forge-repository/types'
import { BlockIndices } from '@typebot.io/schemas'
import { useMemo } from 'react'
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'
import { ThunderIcon } from '@/components/icons'

type Props = {
block: ForgedBlock
indices: BlockIndices
}
export const ForgedBlockNodeContent = ({ block }: Props) => {
export const ForgedBlockNodeContent = ({ block, indices }: Props) => {
const { blockDef, actionDef } = useForgedBlock(
block.type,
block.options?.action
)
const { typebot } = useTypebot()

const isStreamingNextBlock = useMemo(() => {
if (!actionDef?.run?.stream?.getStreamVariableId) return false
const variable = typebot?.variables.find(
(variable) =>
variable.id ===
actionDef.run!.stream!.getStreamVariableId(block.options)
)
if (!variable) return false
const nextBlock =
typebot?.groups[indices.groupIndex]?.blocks[indices.blockIndex + 1]
return (
nextBlock?.type === BubbleBlockType.TEXT &&
nextBlock.content?.richText?.length === 1 &&
nextBlock.content.richText[0].type === 'p' &&
nextBlock.content.richText[0].children.length === 1 &&
nextBlock.content.richText[0].children[0].text === `{{${variable.name}}}`
)
}, [
actionDef?.run,
block.options,
indices.blockIndex,
indices.groupIndex,
typebot?.groups,
typebot?.variables,
])

const setVariableIds = actionDef?.getSetVariableIds?.(block.options) ?? []

const isConfigured =
Expand All @@ -32,6 +63,23 @@ export const ForgedBlockNodeContent = ({ block }: Props) => {
variableId={variableId}
/>
))}
{isStreamingNextBlock && (
<Tooltip label="Text bubble content will be streamed">
<Flex
rounded="full"
p="1"
bgColor="gray.100"
color="purple.500"
borderWidth={1}
pos="absolute"
bottom="-15px"
left="118px"
zIndex={10}
>
<ThunderIcon fontSize="sm" />
</Flex>
</Tooltip>
)}
</Stack>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ import { getZodInnerSchema } from '../../helpers/getZodInnerSchema'
import { TagsInput } from '@/components/TagsInput'
import { PrimitiveList } from '@/components/PrimitiveList'

const parseEnumItems = (
schema: z.ZodTypeAny,
layout?: ZodLayoutMetadata<ZodTypeAny>
) => {
const values = layout?.hiddenItems
? schema._def.values.filter((v: string) => !layout.hiddenItems?.includes(v))
: schema._def.values
if (layout?.toLabels)
return values.map((v: string) => ({
label: layout.toLabels!(v),
value: v,
}))
return values
}

const mdComponents = {
a: ({ href, children }) => (
<a
Expand Down Expand Up @@ -134,13 +149,7 @@ export const ZodFieldLayout = ({
<DropdownList
currentItem={data ?? layout?.defaultValue}
onItemSelect={onDataChange}
items={
layout?.hiddenItems
? innerSchema._def.values.filter(
(v: any) => !layout.hiddenItems.includes(v)
)
: innerSchema._def.values
}
items={parseEnumItems(innerSchema, layout)}
label={layout?.label}
helperText={
layout?.helperText ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const BlockNodeContent = ({
return <ZemanticAiNodeBody options={block.options} />
}
default: {
return <ForgedBlockNodeContent block={block} />
return <ForgedBlockNodeContent block={block} indices={indices} />
}
}
}
4 changes: 2 additions & 2 deletions apps/builder/src/features/preview/components/WebPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WebhookIcon } from '@/components/icons'
import { ThunderIcon } from '@/components/icons'
import { useUser } from '@/features/account/hooks/useUser'
import { useEditor } from '@/features/editor/providers/EditorProvider'
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
Expand All @@ -18,7 +18,7 @@ export const WebPreview = () => {
const handleNewLogs = (logs: ContinueChatResponse['logs']) => {
logs?.forEach((log) => {
showToast({
icon: <WebhookIcon />,
icon: <ThunderIcon />,
status: log.status as 'success' | 'error' | 'info',
title: log.status === 'error' ? 'An error occured' : undefined,
description: log.description,
Expand Down
Loading

0 comments on commit 043f005

Please sign in to comment.