2
0

♻️ Include forged blocks schema in typebot schema

Closes #1364
This commit is contained in:
Baptiste Arnaud
2024-03-18 16:09:19 +01:00
parent 26a9282c20
commit ed5096e2b6
93 changed files with 8599 additions and 4965 deletions

View File

@ -44,7 +44,6 @@
"@typebot.io/env": "workspace:*",
"@typebot.io/forge": "workspace:*",
"@typebot.io/forge-repository": "workspace:*",
"@typebot.io/forge-schemas": "workspace:*",
"@typebot.io/lib": "workspace:*",
"@typebot.io/schemas": "workspace:*",
"@typebot.io/tsconfig": "workspace:*",

View File

@ -5,7 +5,7 @@ import { StreamingTextResponse } from 'ai'
import OpenAI from 'openai'
import { NextResponse } from 'next/dist/server/web/spec-extension/response'
import { getBlockById } from '@typebot.io/schemas/helpers'
import { forgedBlocks } from '@typebot.io/forge-schemas'
import { forgedBlocks } from '@typebot.io/forge-repository/definitions'
import { decryptV2 } from '@typebot.io/lib/api/encryption/decryptV2'
import { ReadOnlyVariableStore } from '@typebot.io/forge'
import {
@ -15,6 +15,7 @@ import {
import { IntegrationBlockType } from '@typebot.io/schemas/features/blocks/integrations/constants'
import { getChatCompletionStream } from '@typebot.io/bot-engine/blocks/integrations/legacy/openai/getChatCompletionStream'
import { ChatCompletionOpenAIOptions } from '@typebot.io/schemas/features/blocks/integrations/openai/schema'
import { isForgedBlockType } from '@typebot.io/schemas/features/blocks/forged/helpers'
export const runtime = 'edge'
export const preferredRegion = 'lhr1'
@ -109,7 +110,13 @@ export async function POST(req: Request) {
}
}
}
const blockDef = forgedBlocks.find((b) => b.id === block.type)
if (!isForgedBlockType(block.type))
return NextResponse.json(
{ message: 'Invalid forged block id' },
{ status: 400, headers: responseHeaders }
)
const blockDef = forgedBlocks[block.type]
const action = blockDef?.actions.find((a) => a.name === block.options?.action)
if (!action || !action.run?.stream)