2023-12-13 10:22:02 +01:00
|
|
|
import { createBlock } from '@typebot.io/forge'
|
|
|
|
import { ZemanticAiLogo } from './logo'
|
2024-04-05 09:01:16 +02:00
|
|
|
import ky from 'ky'
|
2023-12-13 10:22:02 +01:00
|
|
|
import { searchDocuments } from './actions/searchDocuments'
|
|
|
|
import { auth } from './auth'
|
|
|
|
import { baseOptions } from './baseOptions'
|
|
|
|
|
2024-03-18 16:09:19 +01:00
|
|
|
export const zemanticAiBlock = createBlock({
|
2023-12-13 10:22:02 +01:00
|
|
|
id: 'zemantic-ai',
|
|
|
|
name: 'Zemantic AI',
|
|
|
|
tags: [],
|
|
|
|
LightLogo: ZemanticAiLogo,
|
|
|
|
auth,
|
|
|
|
options: baseOptions,
|
|
|
|
fetchers: [
|
|
|
|
{
|
|
|
|
id: 'fetchProjects',
|
|
|
|
dependencies: [],
|
2024-05-21 16:08:35 +02:00
|
|
|
fetch: async ({ credentials }) => {
|
|
|
|
if (!credentials?.apiKey) return []
|
|
|
|
|
2023-12-13 10:22:02 +01:00
|
|
|
const url = 'https://api.zemantic.ai/v1/projects'
|
|
|
|
|
2024-04-05 09:01:16 +02:00
|
|
|
const response = await ky
|
2023-12-13 10:22:02 +01:00
|
|
|
.get(url, {
|
|
|
|
headers: {
|
2024-05-21 16:08:35 +02:00
|
|
|
Authorization: `Bearer ${credentials.apiKey}`,
|
2023-12-13 10:22:02 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
.json()
|
|
|
|
|
|
|
|
const projectsData = response as {
|
|
|
|
id: string
|
|
|
|
name: string
|
|
|
|
}[]
|
|
|
|
|
|
|
|
return projectsData.map((project) => ({
|
|
|
|
label: project.name,
|
|
|
|
value: project.id,
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
actions: [searchDocuments],
|
|
|
|
})
|