Supabase support: client, auth & SQL
This commit is contained in:
@@ -37,7 +37,7 @@ import { getGitAuthor } from "../utils/git_author";
|
||||
import killPort from "kill-port";
|
||||
import util from "util";
|
||||
import log from "electron-log";
|
||||
import { getSupabaseProjectName } from "../utils/supabase_management_client";
|
||||
import { getSupabaseProjectName } from "../../supabase_admin/supabase_management_client";
|
||||
|
||||
const logger = log.scope("app_handlers");
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@ import { db } from "../../db";
|
||||
import { chats, messages } from "../../db/schema";
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
import { SYSTEM_PROMPT } from "../../prompts/system_prompt";
|
||||
import {
|
||||
SUPABASE_AVAILABLE_SYSTEM_PROMPT,
|
||||
SUPABASE_NOT_AVAILABLE_SYSTEM_PROMPT,
|
||||
} from "../../prompts/supabase_prompt";
|
||||
import { getDyadAppPath } from "../../paths/paths";
|
||||
import { readSettings } from "../../main/settings";
|
||||
import type { ChatResponseEnd, ChatStreamParams } from "../ipc_types";
|
||||
@@ -13,6 +17,10 @@ import { streamTestResponse } from "./testing_chat_handlers";
|
||||
import { getTestResponse } from "./testing_chat_handlers";
|
||||
import { getModelClient } from "../utils/get_model_client";
|
||||
import log from "electron-log";
|
||||
import {
|
||||
getSupabaseContext,
|
||||
getSupabaseClientCode,
|
||||
} from "../../supabase_admin/supabase_context";
|
||||
|
||||
const logger = log.scope("chat_stream_handlers");
|
||||
|
||||
@@ -158,12 +166,23 @@ export function registerChatStreamHandlers() {
|
||||
) {
|
||||
messageHistory.pop();
|
||||
}
|
||||
|
||||
let systemPrompt = SYSTEM_PROMPT;
|
||||
if (updatedChat.app?.supabaseProjectId) {
|
||||
systemPrompt +=
|
||||
"\n\n" +
|
||||
SUPABASE_AVAILABLE_SYSTEM_PROMPT +
|
||||
"\n\n" +
|
||||
(await getSupabaseContext({
|
||||
supabaseProjectId: updatedChat.app.supabaseProjectId,
|
||||
}));
|
||||
} else {
|
||||
systemPrompt += "\n\n" + SUPABASE_NOT_AVAILABLE_SYSTEM_PROMPT;
|
||||
}
|
||||
const { textStream } = streamText({
|
||||
maxTokens: 8_000,
|
||||
temperature: 0,
|
||||
model: modelClient,
|
||||
system: SYSTEM_PROMPT,
|
||||
system: systemPrompt,
|
||||
messages: [
|
||||
...messageHistory,
|
||||
// Add the enhanced user prompt
|
||||
@@ -190,6 +209,18 @@ export function registerChatStreamHandlers() {
|
||||
try {
|
||||
for await (const textPart of textStream) {
|
||||
fullResponse += textPart;
|
||||
if (
|
||||
fullResponse.includes("$$SUPABASE_CLIENT_CODE$$") &&
|
||||
updatedChat.app?.supabaseProjectId
|
||||
) {
|
||||
const supabaseClientCode = await getSupabaseClientCode({
|
||||
projectId: updatedChat.app?.supabaseProjectId,
|
||||
});
|
||||
fullResponse = fullResponse.replace(
|
||||
"$$SUPABASE_CLIENT_CODE$$",
|
||||
supabaseClientCode
|
||||
);
|
||||
}
|
||||
// Store the current partial response
|
||||
partialResponses.set(req.chatId, fullResponse);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
getDyadAddDependencyTags,
|
||||
getDyadChatSummaryTag,
|
||||
getDyadDeleteTags,
|
||||
getDyadExecuteSqlTags,
|
||||
getDyadRenameTags,
|
||||
getDyadWriteTags,
|
||||
processFullResponseActions,
|
||||
@@ -76,7 +77,7 @@ const getProposalHandler = async (
|
||||
const proposalWriteFiles = getDyadWriteTags(messageContent);
|
||||
const proposalRenameFiles = getDyadRenameTags(messageContent);
|
||||
const proposalDeleteFiles = getDyadDeleteTags(messageContent);
|
||||
|
||||
const proposalExecuteSqlQueries = getDyadExecuteSqlTags(messageContent);
|
||||
const packagesAdded = getDyadAddDependencyTags(messageContent);
|
||||
|
||||
const filesChanged = [
|
||||
@@ -108,6 +109,7 @@ const getProposalHandler = async (
|
||||
securityRisks: [], // Keep empty
|
||||
filesChanged,
|
||||
packagesAdded,
|
||||
sqlQueries: proposalExecuteSqlQueries,
|
||||
};
|
||||
logger.log(
|
||||
"Generated code proposal. title=",
|
||||
|
||||
@@ -5,7 +5,7 @@ import log from "electron-log";
|
||||
import { db } from "../../db";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { apps } from "../../db/schema";
|
||||
import { getSupabaseClient } from "../utils/supabase_management_client";
|
||||
import { getSupabaseClient } from "../../supabase_admin/supabase_management_client";
|
||||
|
||||
const logger = log.scope("supabase_handlers");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user