@ -1,5 +1,6 @@
|
||||
export enum IntegrationBlockType {
|
||||
GOOGLE_SHEETS = 'Google Sheets',
|
||||
OPEN_AI = 'OpenAI',
|
||||
GOOGLE_ANALYTICS = 'Google Analytics',
|
||||
WEBHOOK = 'Webhook',
|
||||
EMAIL = 'Email',
|
||||
|
@ -2,7 +2,7 @@ import { z } from 'zod'
|
||||
import { ComparisonOperators, LogicalOperator } from '../../logic/condition'
|
||||
import { IntegrationBlockType } from '../enums'
|
||||
import { GoogleSheetsAction } from './enums'
|
||||
import { blockBaseSchema } from '../../baseSchemas'
|
||||
import { blockBaseSchema, credentialsBaseSchema } from '../../baseSchemas'
|
||||
|
||||
const cellSchema = z.object({
|
||||
column: z.string().optional(),
|
||||
@ -69,6 +69,20 @@ export const googleSheetsBlockSchema = blockBaseSchema.and(
|
||||
})
|
||||
)
|
||||
|
||||
export const googleSheetsCredentialsSchema = z
|
||||
.object({
|
||||
type: z.literal('google sheets'),
|
||||
data: z.object({
|
||||
refresh_token: z.string().nullish(),
|
||||
expiry_date: z.number().nullish(),
|
||||
access_token: z.string().nullish(),
|
||||
token_type: z.string().nullish(),
|
||||
id_token: z.string().nullish(),
|
||||
scope: z.string().optional(),
|
||||
}),
|
||||
})
|
||||
.merge(credentialsBaseSchema)
|
||||
|
||||
export const defaultGoogleSheetsOptions: GoogleSheetsOptions = {}
|
||||
|
||||
export const defaultGoogleSheetsGetOptions = (
|
||||
@ -129,3 +143,6 @@ export type GoogleSheetsUpdateRowOptions = z.infer<
|
||||
export type Cell = z.infer<typeof cellSchema>
|
||||
export type ExtractingCell = z.infer<typeof extractingCellSchema>
|
||||
export type RowsFilterComparison = z.infer<typeof rowsFilterComparisonSchema>
|
||||
export type GoogleSheetsCredentials = z.infer<
|
||||
typeof googleSheetsCredentialsSchema
|
||||
>
|
||||
|
114
packages/models/features/blocks/integrations/openai.ts
Normal file
114
packages/models/features/blocks/integrations/openai.ts
Normal file
@ -0,0 +1,114 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema, credentialsBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
|
||||
export const openAITasks = ['Create chat completion', 'Create image'] as const
|
||||
|
||||
export const chatCompletionModels = [
|
||||
'gpt-3.5-turbo',
|
||||
'gpt-3.5-turbo-0301',
|
||||
] as const
|
||||
|
||||
export const chatCompletionMessageRoles = [
|
||||
'system',
|
||||
'user',
|
||||
'assistant',
|
||||
] as const
|
||||
|
||||
export const chatCompletionResponseValues = [
|
||||
'Message content',
|
||||
'Total tokens',
|
||||
] as const
|
||||
|
||||
const openAIBaseOptionsSchema = z.object({
|
||||
credentialsId: z.string().optional(),
|
||||
})
|
||||
|
||||
const initialOptionsSchema = z
|
||||
.object({
|
||||
task: z.undefined(),
|
||||
})
|
||||
.merge(openAIBaseOptionsSchema)
|
||||
|
||||
const chatCompletionMessageSchema = z.object({
|
||||
id: z.string(),
|
||||
role: z.enum(chatCompletionMessageRoles).optional(),
|
||||
content: z.string().optional(),
|
||||
})
|
||||
|
||||
const chatCompletionOptionsSchema = z
|
||||
.object({
|
||||
task: z.literal(openAITasks[0]),
|
||||
model: z.enum(chatCompletionModels),
|
||||
messages: z.array(chatCompletionMessageSchema),
|
||||
responseMapping: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
valueToExtract: z.enum(chatCompletionResponseValues),
|
||||
variableId: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.merge(openAIBaseOptionsSchema)
|
||||
|
||||
const createImageOptionsSchema = z
|
||||
.object({
|
||||
task: z.literal(openAITasks[1]),
|
||||
prompt: z.string().optional(),
|
||||
advancedOptions: z.object({
|
||||
size: z.enum(['256x256', '512x512', '1024x1024']).optional(),
|
||||
}),
|
||||
responseMapping: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
valueToExtract: z.enum(['Image URL']),
|
||||
variableId: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.merge(openAIBaseOptionsSchema)
|
||||
|
||||
export const openAIBlockSchema = blockBaseSchema.merge(
|
||||
z.object({
|
||||
type: z.enum([IntegrationBlockType.OPEN_AI]),
|
||||
options: z.discriminatedUnion('task', [
|
||||
initialOptionsSchema,
|
||||
chatCompletionOptionsSchema,
|
||||
createImageOptionsSchema,
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
export const openAICredentialsSchema = z
|
||||
.object({
|
||||
type: z.literal('openai'),
|
||||
data: z.object({
|
||||
apiKey: z.string(),
|
||||
}),
|
||||
})
|
||||
.merge(credentialsBaseSchema)
|
||||
|
||||
export const defaultChatCompletionOptions = (
|
||||
createId: () => string
|
||||
): ChatCompletionOpenAIOptions => ({
|
||||
task: 'Create chat completion',
|
||||
messages: [
|
||||
{
|
||||
id: createId(),
|
||||
},
|
||||
],
|
||||
responseMapping: [
|
||||
{
|
||||
id: createId(),
|
||||
valueToExtract: 'Message content',
|
||||
},
|
||||
],
|
||||
model: 'gpt-3.5-turbo',
|
||||
})
|
||||
|
||||
export type OpenAICredentials = z.infer<typeof openAICredentialsSchema>
|
||||
export type OpenAIBlock = z.infer<typeof openAIBlockSchema>
|
||||
export type ChatCompletionOpenAIOptions = z.infer<
|
||||
typeof chatCompletionOptionsSchema
|
||||
>
|
||||
export type CreateImageOpenAIOptions = z.infer<typeof createImageOptionsSchema>
|
@ -1,25 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
import { chatwootBlockSchema, chatwootOptionsSchema } from './chatwoot'
|
||||
import {
|
||||
googleAnalyticsOptionsSchema,
|
||||
googleAnalyticsBlockSchema,
|
||||
} from './googleAnalytics'
|
||||
import {
|
||||
googleSheetsOptionsSchema,
|
||||
googleSheetsBlockSchema,
|
||||
} from './googleSheets/schemas'
|
||||
import { chatwootBlockSchema } from './chatwoot'
|
||||
import { googleAnalyticsBlockSchema } from './googleAnalytics'
|
||||
import { googleSheetsBlockSchema } from './googleSheets/schemas'
|
||||
import { makeComBlockSchema } from './makeCom'
|
||||
import { openAIBlockSchema } from './openai'
|
||||
import { pabblyConnectBlockSchema } from './pabblyConnect'
|
||||
import { sendEmailOptionsSchema, sendEmailBlockSchema } from './sendEmail'
|
||||
import { webhookOptionsSchema, webhookBlockSchema } from './webhook'
|
||||
import { sendEmailBlockSchema } from './sendEmail'
|
||||
import { webhookBlockSchema } from './webhook'
|
||||
import { zapierBlockSchema } from './zapier'
|
||||
|
||||
const integrationBlockOptionsSchema = googleSheetsOptionsSchema
|
||||
.or(googleAnalyticsOptionsSchema)
|
||||
.or(webhookOptionsSchema)
|
||||
.or(sendEmailOptionsSchema)
|
||||
.or(chatwootOptionsSchema)
|
||||
|
||||
export const integrationBlockSchema = googleSheetsBlockSchema
|
||||
.or(googleAnalyticsBlockSchema)
|
||||
.or(webhookBlockSchema)
|
||||
@ -28,8 +17,7 @@ export const integrationBlockSchema = googleSheetsBlockSchema
|
||||
.or(makeComBlockSchema)
|
||||
.or(pabblyConnectBlockSchema)
|
||||
.or(chatwootBlockSchema)
|
||||
.or(openAIBlockSchema)
|
||||
|
||||
export type IntegrationBlock = z.infer<typeof integrationBlockSchema>
|
||||
export type IntegrationBlockOptions = z.infer<
|
||||
typeof integrationBlockOptionsSchema
|
||||
>
|
||||
export type IntegrationBlockOptions = IntegrationBlock['options']
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
import { blockBaseSchema } from '../baseSchemas'
|
||||
import { blockBaseSchema, credentialsBaseSchema } from '../baseSchemas'
|
||||
import { IntegrationBlockType } from './enums'
|
||||
|
||||
export const sendEmailOptionsSchema = z.object({
|
||||
@ -22,6 +22,23 @@ export const sendEmailBlockSchema = blockBaseSchema.and(
|
||||
})
|
||||
)
|
||||
|
||||
export const smtpCredentialsSchema = z
|
||||
.object({
|
||||
type: z.literal('smtp'),
|
||||
data: z.object({
|
||||
host: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
isTlsEnabled: z.boolean().optional(),
|
||||
port: z.number(),
|
||||
from: z.object({
|
||||
email: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.merge(credentialsBaseSchema)
|
||||
|
||||
export const defaultSendEmailOptions: SendEmailOptions = {
|
||||
credentialsId: 'default',
|
||||
isCustomBody: false,
|
||||
@ -30,3 +47,4 @@ export const defaultSendEmailOptions: SendEmailOptions = {
|
||||
|
||||
export type SendEmailBlock = z.infer<typeof sendEmailBlockSchema>
|
||||
export type SendEmailOptions = z.infer<typeof sendEmailOptionsSchema>
|
||||
export type SmtpCredentials = z.infer<typeof smtpCredentialsSchema>
|
||||
|
Reference in New Issue
Block a user