Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</div>
<div class="chat-preview-body">
{#key refreshKey}
<Chatbox bind:chat persistConversation={false} {workspaceId} />
<Chatbox bind:chat persistConversation={false} preview {workspaceId} />
{/key}
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend-core/src/components/Chatbox/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
workspaceId: string
chat: ChatConversationLike
persistConversation?: boolean
preview?: boolean
conversationStarters?: { prompt: string }[]
onchatsaved?: (_event: {
detail: { chatId?: string; chat: ChatConversationLike }
Expand All @@ -40,6 +41,7 @@
workspaceId,
chat = $bindable(),
persistConversation = true,
preview = false,
conversationStarters = [],
onchatsaved,
}: Props = $props()
Expand Down Expand Up @@ -84,6 +86,7 @@
chatAppId,
agentId: chat?.agentId,
transient: !persistConversation,
preview: preview && !persistConversation,
title: chat?.title,
messages,
},
Expand Down
11 changes: 11 additions & 0 deletions packages/server/src/api/controllers/ai/chatConversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
docIds,
getErrorMessage,
HTTPError,
users,
utils,
} from "@budibase/backend-core"
import { v4 } from "uuid"
import { ai } from "@budibase/pro"
Expand Down Expand Up @@ -203,7 +205,16 @@ export async function agentChatStream(ctx: UserCtx<ChatAgentRequest, void>) {
throw new HTTPError("agentId is required", 400)
}

const workspaceId = context.getWorkspaceId()
const allowPreview =
!!chat.preview &&
!!chat.transient &&
!!workspaceId &&
users.isBuilder(ctx.user, workspaceId) &&
!utils.isClient(ctx)

if (
!allowPreview &&
!chatApp.agents?.some(agent => agent.agentId === agentId && agent.isEnabled)
) {
throw new HTTPError("agentId is not enabled for this chat app", 400)
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/documents/global/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ChatConversationRequest extends Document {
title?: string
messages: UIMessage<AgentMessageMetadata>[]
transient?: boolean
preview?: boolean
}

export type CreateChatConversationRequest = Pick<
Expand Down
Loading