diff --git a/build/views.json b/build/views.json index a9416462..38843724 100644 --- a/build/views.json +++ b/build/views.json @@ -7,5 +7,5 @@ "smart_chat_system_msg": "
\">\n
\">\n <%= content %>\n
\n
", "smart_connections": "
\n

\n <%- current_path %>\n <%- this.notes_ct %> (<%- this.blocks_ct %>)\n

\n \n \n \n \n
\n
\n
\n <% for (let result of results) { %>\n
\" data-path=\"<%- result.path %>\">\n \n <%- this.get_icon('right-triangle') %>\n \" draggable=\"true\">\n <%- [result.score?.toFixed(2), result.name].join(' | ') %>\n \n \n \n
\n <% } %>\n
\n<%- this.attribution %>", "smart_embed_settings": "
`data-option-${i + 1}=\"${model.key}|${model.name} (${model.description})\"`).join('\\n') %>\n data-callback=\"restart_plugin\"\n>
\n
`data-option-${i + 1}=\"${model.key}|${model.name} (${model.description})\"`).join('\\n') %>\n data-callback=\"restart_plugin\"\n>
\n
\n<% if(!settings.smart_notes_embed_model.includes('/') || !settings.smart_blocks_embed_model.includes('/')) { %>\n
\n<% } %>\n<% if(settings.smart_notes_embed_model.includes('/') || settings.smart_blocks_embed_model.includes('/')) { %>\n
\n\n
Smart Connect is free to use for faster local embeddings.\"\n data-type=\"button\"\n data-callback=\"connect_to_smart_connect\"\n>
\n<% } %>\n
", - "smart_settings": "

Smart Connections

\n<% if(this.env.plugin.EARLY_ACCESS && this.env.plugin.obsidian.Platform.isMobile && !this.env.plugin.settings.enable_mobile) { %>\n
\n
\n
\n \n \n \n \n \n
\n
Mobile is DISABLED.
\n
\n
\n

Toggle \"Enable mobile\" setting to activate mobile.

\n
\n
\n<% } %>\n\n
\n
\n
\n \n \n \n
\n

User Agreement: By using Smart Connections you agree to share how it helps you with at least one other person 😊🌴

\n
\n
\n
\n

Supporter Community

\n <% if(!this.env.plugin.EARLY_ACCESS){ %>\n

The success of Smart Connections is a direct result of our community of supporters who generously fund and evaluate new features. Their unwavering commitment to our privacy-focused, open-source software benefits all. Together, we can continue to innovate and make a positive impact on the world.

\n

Supporter benefits include:

\n \n <% } %>\n
\n
\n
\n data-setting=\"enable_mobile\"\n data-callback=\"toggle_mobile\"\n >
\n
\n <% if(!this.env.plugin.EARLY_ACCESS){ %>\n
\n
\n <% } %>\n
\n

Smart View & Embeddings

\n

Notes about embedding models:

\n\n<%- smart_embed_settings %>\n

Smart Chat

\n<%- smart_chat_settings %>\n

System Prompts

\n
\n
\nCurrent: my, I, me, mine, our, ours, us, we\n

Exclusions

\n

Included files: <%= included_files %> / Total files: <%= total_files %>

\n
\n
\n
\n
\n

Data Management

\n
\n
\n
\n

Force Refresh

\n
\n

Muted Notices

\n<% if(muted_notices && Object.keys(muted_notices).length) { %>\n <% for(const notice in muted_notices) { %>\n
\"\n data-setting=\"muted_notices.<%= notice %>\"\n data-type=\"button\"\n data-btn-text=\"Unmute\"\n data-callback=\"unmute_notice\"\n >
\n <% } %>\n<% } else { %>\n

No muted notices.

\n<% } %>\n
\n
The Original Smart Connections GPT
\n
\n
\n
\n \n \n \n
\n

The original v1 ChatGPT integration is no longer available. See this for more details.
You can still use the Smart Connect - Notes GPT for more advanced features like creating notes and embedding search without uploading your notes to the cloud.

\n
\n
\n
\n<% if(this.env.plugin.EARLY_ACCESS){ %>\n
\n<% } %>\n" + "smart_settings": "

Smart Connections

\n<% if(this.env.plugin.EARLY_ACCESS && !this.env.plugin.app.plugins.enabledPlugins[\"smart-templates\"]){ %>\n
\n
\n
\n \n
\n

Smart Templates: Try out the new Smart Templates.

\n
\n
\n
\n
\n<% } %>\n<% if(this.env.plugin.EARLY_ACCESS && this.env.plugin.obsidian.Platform.isMobile && !this.env.plugin.settings.enable_mobile) { %>\n
\n
\n
\n \n \n \n \n \n
\n
Mobile is DISABLED.
\n
\n
\n

Toggle \"Enable mobile\" setting to activate mobile.

\n
\n
\n<% } %>\n\n
\n
\n
\n \n \n \n
\n

User Agreement: By using Smart Connections you agree to share how it helps you with at least one other person 😊🌴

\n
\n
\n
\n

Supporter Community

\n <% if(!this.env.plugin.EARLY_ACCESS){ %>\n

The success of Smart Connections is a direct result of our community of supporters who generously fund and evaluate new features. Their unwavering commitment to our privacy-focused, open-source software benefits all. Together, we can continue to innovate and make a positive impact on the world.

\n

Supporter benefits include:

\n \n <% } %>\n
\n
\n
\n data-setting=\"enable_mobile\"\n data-callback=\"toggle_mobile\"\n >
\n
\n <% if(!this.env.plugin.EARLY_ACCESS){ %>\n
\n
\n <% } %>\n
\n

Smart View & Embeddings

\n

Notes about embedding models:

\n\n
\n

Smart Chat

\n
\n

System Prompts

\n
\n
\nCurrent: my, I, me, mine, our, ours, us, we\n

Exclusions

\n

Included files: <%= included_files %> / Total files: <%= total_files %>

\n
\n
\n
\n
\n

Data Management

\n
\n
\n
\n

Force Refresh

\n
\n

Muted Notices

\n<% if(muted_notices && Object.keys(muted_notices).length) { %>\n <% for(const notice in muted_notices) { %>\n
\"\n data-setting=\"muted_notices.<%= notice %>\"\n data-type=\"button\"\n data-btn-text=\"Unmute\"\n data-callback=\"unmute_notice\"\n >
\n <% } %>\n<% } else { %>\n

No muted notices.

\n<% } %>\n
\n
The Original Smart Connections GPT
\n
\n
\n
\n \n \n \n
\n

The original v1 ChatGPT integration is no longer available. See this for more details.
You can still use the Smart Connect - Notes GPT for more advanced features like creating notes and embedding search without uploading your notes to the cloud.

\n
\n
\n
\n<% if(this.env.plugin.EARLY_ACCESS){ %>\n
\n<% } %>\n" } \ No newline at end of file diff --git a/src/index.js b/src/index.js index 96ef8d73..98b0896a 100644 --- a/src/index.js +++ b/src/index.js @@ -42,7 +42,13 @@ class SmartConnectionsPlugin extends Plugin { get api() { return this._api; } async load_settings() { Object.assign(this, this.constructor.defaults); // set defaults - Object.assign(this.settings, await this.loadData()); // overwrites defaults with saved settings + const saved_settings = await this.loadData(); + if(!saved_settings){ + this.notices.show("fail-load-settings", "Failed to load settings. Restarting plugin..."); + this.restart_plugin(); + throw new Error("Failed to load settings. Restarting plugin..."); + } + Object.assign(this.settings, saved_settings); // overwrites defaults with saved settings this.handle_deprecated_settings(); // HANDLE DEPRECATED SETTINGS } async onload() { this.app.workspace.onLayoutReady(this.initialize.bind(this)); } // initialize when layout is ready @@ -292,52 +298,6 @@ class SmartConnectionsPlugin extends Plugin { } } // SUPPORTERS - async sync_notes() { - // if license key is not set, return - if(!this.settings.license_key){ - new Notice("Smart Connections: Supporter license key is required to sync notes to the ChatGPT Plugin server."); - return; - } - console.log("syncing notes"); - const files = this.brain.files; - const notes = await this.build_notes_object(files); - // POST notes object to server - const response = await requestUrl({ - url: "https://sync.smartconnections.app/sync", - method: "POST", - headers: { - "Content-Type": "application/json", - }, - contentType: "application/json", - body: JSON.stringify({ - license_key: this.settings.license_key, - notes: notes - }) - }); - console.log(response); - } - async build_notes_object(files) { - let output = {}; - for(let i = 0; i < files.length; i++) { - let file = files[i]; - let parts = file.path.split("/"); - let current = output; - for (let ii = 0; ii < parts.length; ii++) { - let part = parts[ii]; - if (ii === parts.length - 1) { - // This is a file - current[part] = await this.app.vault.cachedRead(file); - } else { - // This is a directory - if (!current[part]) { - current[part] = {}; - } - current = current[part]; - } - } - } - return output; - } async render_code_block(contents, container, ctx) { console.log(container); return this.view.render_nearest((contents.trim().length? contents : ctx.sourcePath), container); diff --git a/src/sc_settings.js b/src/sc_settings.js index 371ec145..e2b97b0a 100644 --- a/src/sc_settings.js +++ b/src/sc_settings.js @@ -7,14 +7,25 @@ const { SmartEmbedSettings } = require("./smart_embed_settings"); class ScSettings extends SmartSettings { constructor(env, container, template_name = "smart_settings") { super(env, container, template_name); - this.chat_settings = new SmartChatSettings(env, container, template_name); - this.embed_settings = new SmartEmbedSettings(env, container, template_name); } update_smart_chat_folder() { this.chat_settings.update_smart_chat_folder(); } async changed_smart_chat_model(){ await this.chat_settings.changed_smart_chat_model(false); this.render(); } + async render(){ + await super.render(); + const chat_settings_elm = this.container.querySelector(".smart-chat-settings"); + if(chat_settings_elm){ + this.chat_settings = new SmartChatSettings(this.env, chat_settings_elm, "smart_chat_settings"); + await this.chat_settings.render(); + } + const embed_settings_elm = this.container.querySelector(".smart-embed-settings"); + if(embed_settings_elm){ + this.embed_settings = new SmartEmbedSettings(this.env, embed_settings_elm, "smart_embed_settings"); + await this.embed_settings.render(); + } + } async test_chat_api_key(){ await this.chat_settings.test_chat_api_key(); } get self_ref_list() { return this.chat_settings.self_ref_list; } @@ -22,9 +33,11 @@ class ScSettings extends SmartSettings { this.env.smart_notes.import(this.env.files, { reset: true }); } reload_env() { this.env.reload(); } // DEPRECATED - restart_plugin() { this.plugin.restart_plugin(); } + restart_plugin() { + this.plugin.notices.show('restarting_for_settings_to_take_effect', "Restarting for settings to take effect...", {timeout: 3000}); + this.plugin.restart_plugin(); + } force_refresh() { this.env.force_refresh(); } - sync_for_chatgpt() { this.plugin.sync_notes(); } update_smart_connections_folder() { this.plugin.update_smart_connections_folder(); } refresh_smart_view() { this.embed_settings.refresh_smart_view(); } async connect_to_smart_connect(){ await this.embed_settings.connect_to_smart_connect(); } @@ -60,8 +73,6 @@ class ScSettings extends SmartSettings { included_files: this.plugin.env.files.length, total_files: this.plugin.env.all_files.length, muted_notices: this.plugin.settings.muted_notices || false, - ...((await this.chat_settings.get_view_data()) || {}), - ...((await this.embed_settings.get_view_data()) || {}), }; return view_data; } diff --git a/src/smart_embed_settings.js b/src/smart_embed_settings.js index 308f7026..ff86101a 100644 --- a/src/smart_embed_settings.js +++ b/src/smart_embed_settings.js @@ -39,7 +39,10 @@ class SmartEmbedSettings extends SmartSettings { } } reload_env() { this.env.reload(); } // DEPRECATED - restart_plugin() { this.plugin.restart_plugin(); } + restart_plugin() { + this.plugin.notices.show('restarting_for_settings_to_take_effect', "Restarting for settings to take effect...", {timeout: 3000}); + this.plugin.restart_plugin(); + } get template() { return this.templates['smart_embed_settings']; } async get_view_data() { const view_data = { diff --git a/src/smart_socket.js b/src/smart_socket.js index 730ae3de..b7334a1f 100644 --- a/src/smart_socket.js +++ b/src/smart_socket.js @@ -23,7 +23,7 @@ class SmartSocket { if(typeof this.is_server_running === 'function'){ const is_running = await this.is_server_running(); if(!is_running){ - console.log("Smart Connect is not running, will try to connect again later"); + // console.log("Smart Connect is not running, will try to connect again later"); this.connect(true); return; } @@ -49,11 +49,11 @@ class SmartSocket { can_attempt_connection(retry) { retry = retry || this.retry; if (this.ws && this.ws.readyState === WebSocket.OPEN) { - console.log("WebSocket is already connected. Aborting new connection attempt."); + // console.log("WebSocket is already connected. Aborting new connection attempt."); return false; } if (retry && this.ws_retries >= 10) { - console.error("Failed to reconnect after 10 attempts"); + console.error("Failed to connect to Smart Connect after 10 attempts"); this.on_fail_to_reconnect(); return false; } @@ -69,7 +69,7 @@ class SmartSocket { if (retry || this.retry) { this.ws_retries += 1; const backoff_time = Math.min(1000 * Math.pow(2, this.ws_retries), 60000); - console.log(`Attempting to reconnect in ${backoff_time / 1000} seconds...`); + // console.log(`Attempting to connect to Smart Connect in ${backoff_time / 1000} seconds...`); return new Promise(resolve => setTimeout(resolve, backoff_time)); } return Promise.resolve(); diff --git a/src/views/smart_settings.ejs b/src/views/smart_settings.ejs index 0f729eeb..242dbe38 100644 --- a/src/views/smart_settings.ejs +++ b/src/views/smart_settings.ejs @@ -1,4 +1,23 @@

Smart Connections

+<% if(this.env.plugin.EARLY_ACCESS && !this.env.plugin.app.plugins.enabledPlugins["smart-templates"]){ %> +
+
+
+ +
+

Smart Templates: Try out the new Smart Templates.

+
+
+
+
+<% } %> <% if(this.env.plugin.EARLY_ACCESS && this.env.plugin.obsidian.Platform.isMobile && !this.env.plugin.settings.enable_mobile) { %>
@@ -124,12 +143,13 @@

Smart View & Embeddings

Notes about embedding models:

-<%- smart_embed_settings %> +

Smart Chat

-<%- smart_chat_settings %> +

System Prompts