From 3d89e73692454cb7f2df03352dc408f1682531d5 Mon Sep 17 00:00:00 2001 From: Premprakash Singh Date: Wed, 14 Aug 2024 03:16:57 +0530 Subject: [PATCH 1/3] added deduct credit at start of startProject event and restored in catch block of processConversation --- .../controllers/onboardingToolController.js | 20 +++++++++-------- server/services/onboadingService.js | 22 +++++++++++++++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/server/controllers/onboardingToolController.js b/server/controllers/onboardingToolController.js index efbfe10..66e7269 100644 --- a/server/controllers/onboardingToolController.js +++ b/server/controllers/onboardingToolController.js @@ -4,13 +4,13 @@ const searchService = require("../services/searchService"); const { toKebabCase } = require("../utils/file"); const { insertShip, - getUserProfile, - updateUserProfile, + // getUserProfile, + // updateUserProfile, updateConversation, } = require("../services/dbService"); const { TOOLS } = require("../config/tools"); -const { nanoid } = require('nanoid'); +const { nanoid } = require("nanoid"); const generateProjectFolderName = (projectName) => { return toKebabCase(projectName) + "-" + nanoid(8); @@ -145,12 +145,14 @@ async function handleOnboardingToolUse({ }; const { id } = await insertShip(ship); console.log("Inserted ship", id); - if (mode === 'paid') { - const profile = await getUserProfile(userId); - const { available_ships } = profile; // current - const profilePayload = { available_ships: available_ships - 1 }; // updated - await updateUserProfile(userId, profilePayload); - } + + // removing deduct available ships from here. + // if (mode === 'paid') { + // const profile = await getUserProfile(userId); + // const { available_ships } = profile; // current + // const profilePayload = { available_ships: available_ships - 1 }; // updated + // await updateUserProfile(userId, profilePayload); + // } const convPayload = { ship_id: id, tokens_used: client.tokensUsed, diff --git a/server/services/onboadingService.js b/server/services/onboadingService.js index 825cd9a..43bf4d7 100644 --- a/server/services/onboadingService.js +++ b/server/services/onboadingService.js @@ -13,7 +13,11 @@ const { handleOnboardingToolUse, } = require("../controllers/onboardingToolController"); const { AnthropicService } = require("../services/anthropicService"); -const { getUserProfile, insertMessage } = require("../services/dbService"); +const { + getUserProfile, + insertMessage, + updateUserProfile, +} = require("../services/dbService"); const { SHIP_TYPES, DEFAULT_MESSAGES } = require("./constants"); async function processConversation({ @@ -52,7 +56,6 @@ async function processConversation({ tools.push(searchTool); messages = [{ role: "user", content: message }]; } - } try { @@ -188,7 +191,14 @@ function handleOnboardingSocketEvents(io) { }; abortController = new AbortController(); + const mode = client.isCustomKey ? "self-key" : "paid"; try { + if (mode === "paid") { + const profile = await getUserProfile(userId); + const { available_ships } = profile; // current + const profilePayload = { available_ships: available_ships - 1 }; // updated + await updateUserProfile(userId, profilePayload); + } await processConversation({ client, sendEvent, @@ -206,6 +216,14 @@ function handleOnboardingSocketEvents(io) { sendEvent("creationAborted", { message: "Website creation was aborted", }); + + // revert available ships in case of paid mode + if (mode === "paid") { + const profile = await getUserProfile(userId); + const { available_ships } = profile; + const profilePayload = { available_ships: available_ships + 1 }; // updated + await updateUserProfile(userId, profilePayload); + } } else { console.error("Error in processConversation:", error); } From 8853855572c293d4b5f35ebab12c4d6dee345f01 Mon Sep 17 00:00:00 2001 From: Premprakash Singh Date: Fri, 16 Aug 2024 15:52:50 +0530 Subject: [PATCH 2/3] removed commented code --- server/controllers/onboardingToolController.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/server/controllers/onboardingToolController.js b/server/controllers/onboardingToolController.js index 66e7269..4db635e 100644 --- a/server/controllers/onboardingToolController.js +++ b/server/controllers/onboardingToolController.js @@ -146,13 +146,6 @@ async function handleOnboardingToolUse({ const { id } = await insertShip(ship); console.log("Inserted ship", id); - // removing deduct available ships from here. - // if (mode === 'paid') { - // const profile = await getUserProfile(userId); - // const { available_ships } = profile; // current - // const profilePayload = { available_ships: available_ships - 1 }; // updated - // await updateUserProfile(userId, profilePayload); - // } const convPayload = { ship_id: id, tokens_used: client.tokensUsed, From 12584137cb927b6a4010d40584e042ac81a650d7 Mon Sep 17 00:00:00 2001 From: Premprakash Singh Date: Fri, 16 Aug 2024 15:54:25 +0530 Subject: [PATCH 3/3] removed commented imports --- server/controllers/onboardingToolController.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/server/controllers/onboardingToolController.js b/server/controllers/onboardingToolController.js index 4db635e..b48d288 100644 --- a/server/controllers/onboardingToolController.js +++ b/server/controllers/onboardingToolController.js @@ -2,12 +2,7 @@ const fileService = require("../services/fileService"); const ctoService = require("../services/ctoService"); const searchService = require("../services/searchService"); const { toKebabCase } = require("../utils/file"); -const { - insertShip, - // getUserProfile, - // updateUserProfile, - updateConversation, -} = require("../services/dbService"); +const { insertShip, updateConversation } = require("../services/dbService"); const { TOOLS } = require("../config/tools"); const { nanoid } = require("nanoid");