From 09bfb486d62c72c9cea713757648867efdc93b53 Mon Sep 17 00:00:00 2001 From: WFH Brian Date: Wed, 26 Jun 2024 08:40:24 -0400 Subject: [PATCH] prevent existing codeblock registration from preventing startup --- build/views.json | 7 +------ src/index.js | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/build/views.json b/build/views.json index 4afc1529..dcfc4bb4 100644 --- a/build/views.json +++ b/build/views.json @@ -3,14 +3,9 @@ "sc_change": "
\n
\n
\n \n
\n
\n
\n \n
\n
\n Time saved: <%= time_saved %>\n <%- this.attribution %>\n
\n
\n\n", "smart_chat": "
\n
\n \" placeholder=\"Chat Name\">\n \n \n \n \n \n
\n
\n
\n
\n
\n
\n \n Hi there, welcome to the Smart Chat. Ask me a question about your notes and I'll try to answer it.\n \n
\n
\n <%- messages %>\n
\n
\n
\n \n
\n <%- this.get_icon('square') %>\n \n
\n
\n
\n<%- this.attribution %>\n ", "smart_chat_msg": "
\">\n
\">\n <%= content %>\n <%- this.get_icon('copy') %>\n \n \n
\n
", - "smart_chat_options": "

Smart Actions

\n
\n \n <% for(let action of actions.filter(a => a.name !== 'multi')) { %>\n <%\n // TEMP: hide non-notes actions in the default preset\n if (this.env.main.settings.preset === 'default' && !action.name.includes('note')) continue;\n %>\n
\"\n data-description=\"<%= action.json.function.description %>\"\n data-type=\"toggle\"\n data-setting=\"actions.<%= action.json.function.name %>\"\n data-btn=\"Edit prompt\"\n data-btn-disabled=\"true\"\n data-callback=\"toggled_action\"\n <%- !['default', 'actions'].includes(action.group) ? `data-tag=\"${action.group}\"` : '' %>\n >
\n <% } %>", "smart_chat_settings": "
`data-option-${i + 1}=\"${platform.key}|${platform.description}\"`).join('\\n') %>\n data-callback=\"changed_smart_chat_model\"\n>
\n<% if(chat_platform?.fetch_models) { %>\n <% if(settings[settings.chat_model_platform_key]?.api_key) { %>\n
.model_name\"\n data-callback=\"changed_smart_chat_model\"\n <%- platform_chat_models.map((model, i) => `data-option-${i}=\"${model.key}|${model.model_name} (${model.description})\"`).join('\\n') %>\n >
\n <% } %>\n <% if(!platform_chat_models.length) { %>\n
\n <% } %>\n
API Key\"\n data-type=\"text\"\n data-setting=\"<%= settings.chat_model_platform_key %>.api_key\"\n <% if(chat_platform.signup_url) { %>\n data-description=\"Get API Key for <%= chat_platform.description %>.\"\n <% } else { %>\n data-description=\"API Key for <%= chat_platform.description %>.\"\n <% } %>\n data-placeholder=\"Enter an API Key\"\n data-button=\"Save\"\n data-callback=\"test_chat_api_key\"\n >
\n<% } %>\n<% if (settings.chat_model_platform_key.startsWith('custom_local')) { %>\n

Custom Local Model

\n
\n
\n
\n
\n
\n
\n
\n<% } else if(settings.chat_model_platform_key.startsWith('custom_api')) { %>\n

Custom Server

\n
\n
\n
\n
\n
\n
\n
\n<% } %>", "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
  • \" data-collection=\"<%= result.collection_name %>\">
  • \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_note_inspect": "

Blocks

\n<% if(note.blocks.length === 0) { %>\n

No blocks

\n<% } %>\n<% for(let block of note.blocks) { %>\n
\n <%- (await block.get_embed_input()).replace(//g, \">\").replace(/\\n/g, \"
\") %>\n
\n
\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
  • Early access to new & experimental features:\n
      \n
    • Early access to new versions enables supporters to help ensure new features are ready for the broader community.
    • \n
    • Available in v2.2 (Early Release):
        \n
      • 🖼️ Multimodal Smart Chat (images)
      • \n
      • 📲 Mobile compatibility
      • \n
    • \n
    • Coming soon:
        \n
      • Re-ranking in the Smart View
      • \n
      • Actions in the Smart Chat
      • \n
      • Advanced filters in the Smart View
      • \n
    • \n
    \n
  • \n
  • Access to the supporter-only private chat:\n
      \n
    • Community:\n
        \n
      • Ask questions and share insights with other supporters.
      • \n
      \n
    • \n
    • Help & Support (priority):\n \n
    • \n
    • Feature Requests (priority):\n
        \n
      • Influence the future of Smart Connections with priority feature requests in the Supporter Chat.
      • \n
      \n
    • \n
    • Insider Updates:\n
        \n
      • Learn about the latest features & improvements before they are announced.
      • \n
      \n
    • \n
    \n
  • \n
  • For a very limited time: Early access to Smart Connect: Use ChatGPT with your notes without uploading your notes to the cloud using Smart Connect - Obsidian GPT.
  • \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_view": "
\n

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

\n \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
  • \" data-collection=\"<%= result.collection_name %>\">
  • \n
\n
\n <% } %>\n
\n<%- this.attribution %>", - "smart_view_filter": "\n
\n<% if(settings.smart_view_filter?.re_rank) { %>\n
\n<% } %>\n\n
\n<% if(settings.smart_view_filter?.include_exclude) { %>\n\n
\n\n
\n<% } %>\n\n", - "smart_view_search": "
\n

Search Smart Connections

\n
\n \n \n
\n

Use semantic (embeddings) search to surface relevant notes. Results are sorted by similarity to your query. Note: returns different results than lexical (keyword) search.

\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
  • Early access to new & experimental features:\n
      \n
    • Early access to new versions enables supporters to help ensure new features are ready for the broader community.
    • \n
    • Available in v2.2 (Early Release):
        \n
      • 🖼️ Multimodal Smart Chat (images)
      • \n
      • 📲 Mobile compatibility
      • \n
    • \n
    • Coming soon:
        \n
      • Re-ranking in the Smart View
      • \n
      • Actions in the Smart Chat
      • \n
      • Advanced filters in the Smart View
      • \n
    • \n
    \n
  • \n
  • Access to the supporter-only private chat:\n
      \n
    • Community:\n
        \n
      • Ask questions and share insights with other supporters.
      • \n
      \n
    • \n
    • Help & Support (priority):\n \n
    • \n
    • Feature Requests (priority):\n
        \n
      • Influence the future of Smart Connections with priority feature requests in the Supporter Chat.
      • \n
      \n
    • \n
    • Insider Updates:\n
        \n
      • Learn about the latest features & improvements before they are announced.
      • \n
      \n
    • \n
    \n
  • \n
  • For a very limited time: Early access to Smart Connect: Use ChatGPT with your notes without uploading your notes to the cloud using Smart Connect - Obsidian GPT.
  • \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" } \ No newline at end of file diff --git a/src/index.js b/src/index.js index ed3ad41b..eebe6d69 100644 --- a/src/index.js +++ b/src/index.js @@ -65,15 +65,26 @@ class SmartConnectionsPlugin extends Plugin { (window["SmartSearch"] = this.api) && this.register(() => delete window["SmartSearch"]); // register API to global window object this.addRibbonIcon("smart-connections", "Open: View Smart Connections", () => { this.open_view(); }); this.addRibbonIcon("message-square", "Open: Smart Chat Conversation", () => { this.open_chat(); }); - this.registerMarkdownCodeBlockProcessor("smart-connections", this.render_code_block.bind(this)); // code-block renderer - this.registerMarkdownCodeBlockProcessor("sc-context", this.render_code_block_context.bind(this)); // code-block renderer - // "AI change" dynamic code block - this.registerMarkdownCodeBlockProcessor("sc-change", this.change_code_block.bind(this)); // DEPRECATED - this.registerMarkdownCodeBlockProcessor("smart-change", this.change_code_block.bind(this)); + this.register_code_blocks(); this.new_user(); await this.load_env(); console.log("Smart Connections v2 loaded"); } + register_code_blocks() { + this.register_code_block("smart-connections", "render_code_block"); // code-block renderer + this.register_code_block("sc-context", "render_code_block_context"); // code-block renderer + // "AI change" dynamic code block + this.register_code_block("sc-change", "change_code_block"); // DEPRECATED + this.register_code_block("smart-change", "change_code_block"); + } + register_code_block(name, callback_name) { + try{ + this.registerMarkdownCodeBlockProcessor(name, this[callback_name].bind(this)); + } catch (error) { + console.warn(`Error registering code block: ${name}`, error); + } + } + async load_env() { this.env = new this.ScEnv(this, {sc_adapter_class: this.sc_adapter_class}); this.brain = this.env; // DEPRECATED (use this.env instead)