( params: ChatDeployPayload )
| 44 | * `deploy_chat` tool must use this function. |
| 45 | */ |
| 46 | export async function performChatDeploy( |
| 47 | params: ChatDeployPayload |
| 48 | ): Promise<PerformChatDeployResult> { |
| 49 | const { |
| 50 | workflowId, |
| 51 | userId, |
| 52 | identifier, |
| 53 | title, |
| 54 | description = '', |
| 55 | authType = 'public', |
| 56 | password, |
| 57 | allowedEmails = [], |
| 58 | outputConfigs = [], |
| 59 | } = params |
| 60 | |
| 61 | const customizations = { |
| 62 | primaryColor: params.customizations?.primaryColor || 'var(--brand-hover)', |
| 63 | welcomeMessage: params.customizations?.welcomeMessage || 'Hi there! How can I help you today?', |
| 64 | ...(params.customizations?.imageUrl ? { imageUrl: params.customizations.imageUrl } : {}), |
| 65 | } |
| 66 | |
| 67 | const deployResult = await performFullDeploy({ |
| 68 | workflowId, |
| 69 | userId, |
| 70 | versionDescription: params.versionDescription, |
| 71 | versionName: params.versionName, |
| 72 | }) |
| 73 | if (!deployResult.success) { |
| 74 | return { success: false, error: deployResult.error || 'Failed to deploy workflow' } |
| 75 | } |
| 76 | |
| 77 | let encryptedPassword: string | null = null |
| 78 | if (authType === 'password' && password) { |
| 79 | const { encrypted } = await encryptSecret(password) |
| 80 | encryptedPassword = encrypted |
| 81 | } |
| 82 | |
| 83 | const [existingDeployment] = await db |
| 84 | .select() |
| 85 | .from(chat) |
| 86 | .where(and(eq(chat.workflowId, workflowId), isNull(chat.archivedAt))) |
| 87 | .limit(1) |
| 88 | |
| 89 | let chatId: string |
| 90 | if (existingDeployment) { |
| 91 | chatId = existingDeployment.id |
| 92 | |
| 93 | let passwordToStore: string | null |
| 94 | if (authType === 'password') { |
| 95 | passwordToStore = encryptedPassword || existingDeployment.password |
| 96 | } else { |
| 97 | passwordToStore = null |
| 98 | } |
| 99 | |
| 100 | await db |
| 101 | .update(chat) |
| 102 | .set({ |
| 103 | identifier, |
no test coverage detected