From 83843311e6e95160b219d75134eda7c31aa7a777 Mon Sep 17 00:00:00 2001 From: aswanth-c Date: Fri, 4 Oct 2024 10:53:38 +0530 Subject: [PATCH 1/5] add toggle for automatic dependency installation, updated filed db, and run migrations --- packages/api/config.mts | 2 + packages/api/db/schema.mts | 3 + .../0010_add_auto_install_dependency.sql | 1 + packages/api/drizzle/meta/0010_snapshot.json | 200 ++++++++++++++++++ packages/api/drizzle/meta/_journal.json | 9 +- packages/web/src/routes/settings.tsx | 20 +- packages/web/src/types.ts | 1 + 7 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 packages/api/drizzle/0010_add_auto_install_dependency.sql create mode 100644 packages/api/drizzle/meta/0010_snapshot.json diff --git a/packages/api/config.mts b/packages/api/config.mts index d68d4d6d..5104408a 100644 --- a/packages/api/config.mts +++ b/packages/api/config.mts @@ -11,6 +11,7 @@ async function init() { const defaultConfig = { baseDir: HOME_DIR, defaultLanguage: 'typescript', + autoInstallDependencies: true, installId: randomid(), aiConfig: { provider: 'openai', model: 'gpt-4o' } as const, aiProvider: 'openai', @@ -41,6 +42,7 @@ export async function getConfig(): Promise { } export async function updateConfig(attrs: Partial) { + console.log(attrs); return db.update(configs).set(attrs).returning(); } diff --git a/packages/api/db/schema.mts b/packages/api/db/schema.mts index 45eb091f..61537af5 100644 --- a/packages/api/db/schema.mts +++ b/packages/api/db/schema.mts @@ -7,6 +7,9 @@ export const configs = sqliteTable('config', { defaultLanguage: text('default_language').notNull().default('typescript'), openaiKey: text('openai_api_key'), anthropicKey: text('anthropic_api_key'), + autoInstallDependencies: integer('auto_install_dependencies', { mode: 'boolean' }) + .notNull() + .default(true), // TODO: This is deprecated in favor of SRCBOOK_DISABLE_ANALYTICS env variable. Remove this. enabledAnalytics: integer('enabled_analytics', { mode: 'boolean' }).notNull().default(true), // Stable ID for posthog diff --git a/packages/api/drizzle/0010_add_auto_install_dependency.sql b/packages/api/drizzle/0010_add_auto_install_dependency.sql new file mode 100644 index 00000000..6562513a --- /dev/null +++ b/packages/api/drizzle/0010_add_auto_install_dependency.sql @@ -0,0 +1 @@ +ALTER TABLE `config` ADD `auto_install_dependencies` integer DEFAULT true NOT NULL; \ No newline at end of file diff --git a/packages/api/drizzle/meta/0010_snapshot.json b/packages/api/drizzle/meta/0010_snapshot.json new file mode 100644 index 00000000..71242979 --- /dev/null +++ b/packages/api/drizzle/meta/0010_snapshot.json @@ -0,0 +1,200 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "e43d8a2f-9030-437f-a5e8-a4f08501b382", + "prevId": "fd7a01ac-c2a9-4369-a2e6-f47a691ba1a2", + "tables": { + "config": { + "name": "config", + "columns": { + "base_dir": { + "name": "base_dir", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "default_language": { + "name": "default_language", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'typescript'" + }, + "openai_api_key": { + "name": "openai_api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "anthropic_api_key": { + "name": "anthropic_api_key", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "auto_install_dependencies": { + "name": "auto_install_dependencies", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "enabled_analytics": { + "name": "enabled_analytics", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "srcbook_installation_id": { + "name": "srcbook_installation_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'d5fcl7j6uai82mgnmnsroe4oj0'" + }, + "ai_provider": { + "name": "ai_provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'openai'" + }, + "ai_model": { + "name": "ai_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'gpt-4o'" + }, + "ai_base_url": { + "name": "ai_base_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subscription_email": { + "name": "subscription_email", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "secrets": { + "name": "secrets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "secrets_name_unique": { + "name": "secrets_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "secrets_to_sessions": { + "name": "secrets_to_sessions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secret_id": { + "name": "secret_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "secrets_to_sessions_session_id_secret_id_unique": { + "name": "secrets_to_sessions_session_id_secret_id_unique", + "columns": [ + "session_id", + "secret_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "secrets_to_sessions_secret_id_secrets_id_fk": { + "name": "secrets_to_sessions_secret_id_secrets_id_fk", + "tableFrom": "secrets_to_sessions", + "tableTo": "secrets", + "columnsFrom": [ + "secret_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/packages/api/drizzle/meta/_journal.json b/packages/api/drizzle/meta/_journal.json index b8cac8c7..1d4e6adb 100644 --- a/packages/api/drizzle/meta/_journal.json +++ b/packages/api/drizzle/meta/_journal.json @@ -71,6 +71,13 @@ "when": 1726250539939, "tag": "0009_secret_session_unique", "breakpoints": true + }, + { + "idx": 10, + "version": "6", + "when": 1728018080269, + "tag": "0010_add_auto_install_dependency", + "breakpoints": true } ] -} +} \ No newline at end of file diff --git a/packages/web/src/routes/settings.tsx b/packages/web/src/routes/settings.tsx index 8711e5b0..a058f474 100644 --- a/packages/web/src/routes/settings.tsx +++ b/packages/web/src/routes/settings.tsx @@ -26,6 +26,7 @@ function Settings() { updateConfig: updateConfigContext, defaultLanguage, subscriptionEmail, + autoInstallDependencies, } = useSettings(); const isSubscribed = subscriptionEmail && subscriptionEmail !== 'dismissed'; @@ -40,6 +41,10 @@ function Settings() { updateConfigContext({ defaultLanguage: value }); }; + const toggleAutoInstallDependencies = () => { + updateConfigContext({ autoInstallDependencies: !autoInstallDependencies }); + }; + const setAiProvider = (provider: AiProviderType) => { const model = getDefaultModel(provider); setModel(model); @@ -95,7 +100,20 @@ function Settings() { - +
+

Dependency Installation

+ +
+ + +
+

Default Language