Skip to content

Commit

Permalink
lint: single quote
Browse files Browse the repository at this point in the history
  • Loading branch information
longy2k committed Feb 23, 2024
1 parent c808a41 commit 31d3fa8
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 226 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off"
"@typescript-eslint/no-empty-function": "off",
"quotes": ["error", "single"]
}
}
46 changes: 23 additions & 23 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import esbuild from 'esbuild';
import process from 'process';
import builtins from 'builtin-modules';

const banner =
`/*
Expand All @@ -9,35 +9,35 @@ if you want to view the source, please visit the github repository of this plugi
*/
`;

const prod = (process.argv[2] === "production");
const prod = (process.argv[2] === 'production');

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["./src/main.ts"],
entryPoints: ['./src/main.ts'],
bundle: true,
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: "main.js",
outfile: 'main.js',
});

if (prod) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/FetchModelEditor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { requestUrl } from "obsidian";
import OpenAI from "openai";
import { BMOSettings } from "src/main";
import { requestUrl } from 'obsidian';
import OpenAI from 'openai';
import { BMOSettings } from 'src/main';

// Fetch OpenAI-Based API Editor
export async function fetchOpenAIBaseAPIDataEditor(settings: BMOSettings, selectionString: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/FetchModelList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { requestUrl } from "obsidian";
import OpenAI from "openai";
import BMOGPT from "src/main";
import { requestUrl } from 'obsidian';
import OpenAI from 'openai';
import BMOGPT from 'src/main';

export async function fetchOpenAIBaseModels(plugin: BMOGPT) {
const openai = new OpenAI({
Expand Down
74 changes: 37 additions & 37 deletions src/components/FetchModelResponse.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Notice, requestUrl } from "obsidian";
import { BMOSettings } from "../main";
import { messageHistory } from "../view";
import OpenAI from "openai";
import { ChatCompletionMessageParam } from "openai/resources/chat";
import { marked } from "marked";
import { prismHighlighting } from "src/components/PrismaHighlighting";
import { addMessage, addParagraphBreaks } from "./chat/Message";
import { codeBlockCopyButton } from "./chat/Buttons";
import { getPrompt } from "./chat/Prompt";
import { displayLoadingBotMessage } from "./chat/BotMessage";
import { getActiveFileContent, getCurrentNoteContent } from "./editor/ReferenceCurrentNote";
import { Notice, requestUrl } from 'obsidian';
import { BMOSettings } from '../main';
import { messageHistory } from '../view';
import OpenAI from 'openai';
import { ChatCompletionMessageParam } from 'openai/resources/chat';
import { marked } from 'marked';
import { prismHighlighting } from 'src/components/PrismaHighlighting';
import { addMessage, addParagraphBreaks } from './chat/Message';
import { codeBlockCopyButton } from './chat/Buttons';
import { getPrompt } from './chat/Prompt';
import { displayLoadingBotMessage } from './chat/BotMessage';
import { getActiveFileContent, getCurrentNoteContent } from './editor/ReferenceCurrentNote';

let abortController = new AbortController();

Expand Down Expand Up @@ -59,7 +59,7 @@ export async function fetchOpenAIAPIData(settings: BMOSettings, index: number) {
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function fetchOpenAIAPIDataStream(settings: BMOSettings, index: num
if (messageContainerEl) {

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -180,15 +180,15 @@ export async function fetchOpenAIAPIDataStream(settings: BMOSettings, index: num
} catch (error) {
const messageContainerEl = document.querySelector('#messageContainer');
if (messageContainerEl) {
const botMessages = messageContainerEl.querySelectorAll(".botMessage");
const botMessages = messageContainerEl.querySelectorAll('.botMessage');
const lastBotMessage = botMessages[botMessages.length - 1];
const messageBlock = lastBotMessage.querySelector('.messageBlock');
if (messageBlock) {
messageBlock.innerHTML = marked(error.response?.data?.error || error.message);
addMessage(messageBlock.innerHTML, 'botMessage', settings, index);
const targetUserMessage = messageContainerElDivs[index ?? messageHistory.length - 1];
const targetBotMessage = targetUserMessage.nextElementSibling;
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');
if (loadingEl) {
targetBotMessage?.removeChild(loadingEl);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ export async function fetchOllamaData(settings: BMOSettings, index: number) {
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -341,7 +341,7 @@ export async function fetchOllamaDataStream(settings: BMOSettings, index: number
}

if (!response.body) {
new Notice(`Response body is null or undefined.`);
new Notice('Response body is null or undefined.');
throw new Error('Response body is null or undefined.');
}

Expand All @@ -356,7 +356,7 @@ export async function fetchOllamaDataStream(settings: BMOSettings, index: number
break;
}

const chunk = decoder.decode(value, { stream: true }) || "";
const chunk = decoder.decode(value, { stream: true }) || '';
// Splitting the chunk to parse JSON messages separately
const parts = chunk.split('\n');
for (const part of parts.filter(Boolean)) { // Filter out empty parts
Expand All @@ -380,7 +380,7 @@ export async function fetchOllamaDataStream(settings: BMOSettings, index: number
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -474,7 +474,7 @@ export async function fetchRESTAPIURLData(settings: BMOSettings, index: number)
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -570,7 +570,7 @@ export async function fetchRESTAPIURLDataStream(settings: BMOSettings, index: nu
}

if (!response.body) {
new Notice(`Response body is null or undefined.`);
new Notice('Response body is null or undefined.');
throw new Error('Response body is null or undefined.');
}

Expand All @@ -585,10 +585,10 @@ export async function fetchRESTAPIURLDataStream(settings: BMOSettings, index: nu
break;
}

const chunk = decoder.decode(value, { stream: false }) || "";
const chunk = decoder.decode(value, { stream: false }) || '';

// Check if chunk contains 'data: [DONE]'
if (chunk.includes("data: [DONE]")) {
if (chunk.includes('data: [DONE]')) {
break;
}

Expand Down Expand Up @@ -618,7 +618,7 @@ export async function fetchRESTAPIURLDataStream(settings: BMOSettings, index: nu
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -704,7 +704,7 @@ export async function fetchMistralData(settings: BMOSettings, index: number) {
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -786,7 +786,7 @@ export async function fetchMistralDataStream(settings: BMOSettings, index: numbe
}

if (!response.body) {
new Notice(`Response body is null or undefined.`);
new Notice('Response body is null or undefined.');
throw new Error('Response body is null or undefined.');
}

Expand All @@ -801,7 +801,7 @@ export async function fetchMistralDataStream(settings: BMOSettings, index: numbe
break;
}

const chunk = decoder.decode(value, { stream: false }) || "";
const chunk = decoder.decode(value, { stream: false }) || '';

// console.log("chunk",chunk);

Expand All @@ -811,7 +811,7 @@ export async function fetchMistralDataStream(settings: BMOSettings, index: numbe

for (const part of parts.filter(Boolean)) { // Filter out empty parts
// Check if chunk contains 'data: [DONE]'
if (part.includes("data: [DONE]")) {
if (part.includes('data: [DONE]')) {
break;
}

Expand All @@ -835,7 +835,7 @@ export async function fetchMistralDataStream(settings: BMOSettings, index: numbe
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -900,17 +900,17 @@ export async function fetchGoogleGeminiData(settings: BMOSettings, index: number

// Find the last user message index
const lastUserMessageIndex = modifiedMessageHistory.map((message, index) => ({ role: message.role, index }))
.filter(message => message.role === "user")
.filter(message => message.role === 'user')
.map(message => message.index)
.pop();

// Append referenceCurrentNoteContent to the last user message, if found
if (lastUserMessageIndex !== undefined) {
modifiedMessageHistory[lastUserMessageIndex].content += "\n\n" + referenceCurrentNoteContent + "\n\n" + settings.general.system_role + "\n\n" + prompt;
modifiedMessageHistory[lastUserMessageIndex].content += '\n\n' + referenceCurrentNoteContent + '\n\n' + settings.general.system_role + '\n\n' + prompt;
}

const contents = modifiedMessageHistory.map(({ role, content }) => ({
role: role === "assistant" ? "model" : role, // Convert "assistant" to "model"
role: role === 'assistant' ? 'model' : role, // Convert "assistant" to "model"
parts: [{ text: content }]
}));

Expand Down Expand Up @@ -952,7 +952,7 @@ export async function fetchGoogleGeminiData(settings: BMOSettings, index: number
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand Down Expand Up @@ -1044,7 +1044,7 @@ export async function fetchAnthropicAPIData(settings: BMOSettings, index: number
const targetBotMessage = targetUserMessage.nextElementSibling;

const messageBlock = targetBotMessage?.querySelector('.messageBlock');
const loadingEl = targetBotMessage?.querySelector("#loading");
const loadingEl = targetBotMessage?.querySelector('#loading');

if (messageBlock) {
if (loadingEl) {
Expand All @@ -1064,7 +1064,7 @@ export async function fetchAnthropicAPIData(settings: BMOSettings, index: number
} catch (error) {
const messageContainerEl = document.querySelector('#messageContainer');
if (messageContainerEl) {
const botMessages = messageContainerEl.querySelectorAll(".botMessage");
const botMessages = messageContainerEl.querySelectorAll('.botMessage');
const lastBotMessage = botMessages[botMessages.length - 1];
const messageBlock = lastBotMessage.querySelector('.messageBlock');

Expand All @@ -1073,7 +1073,7 @@ export async function fetchAnthropicAPIData(settings: BMOSettings, index: number
messageBlock.innerHTML = 'Max tokens overflow. Please reduce max_tokens or clear chat messages. We recommend clearing max_tokens for best results.';
addMessage(messageBlock.innerHTML, 'botMessage', settings, index);

const loadingEl = lastBotMessage.querySelector("#loading");
const loadingEl = lastBotMessage.querySelector('#loading');
if (loadingEl) {
loadingEl.scrollIntoView({ behavior: 'smooth', block: 'end' });
lastBotMessage.removeChild(loadingEl);
Expand Down
4 changes: 2 additions & 2 deletions src/components/PrismaHighlighting.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { loadPrism } from "obsidian";
import { loadPrism } from 'obsidian';

// Handle Prisma Highlighting for code blocks
export function prismHighlighting(messageBlock: { querySelectorAll: (arg0: string) => NodeListOf<HTMLElement>; }) {
loadPrism().then((Prism) => {
const codeBlocks = messageBlock?.querySelectorAll('.messageBlock pre code');

codeBlocks?.forEach((codeBlock: HTMLElement) => {
const language = codeBlock.className.replace("language-", "");
const language = codeBlock.className.replace('language-', '');
const code = codeBlock.textContent;

if (language && Prism.languages[language]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Setting, SettingTab, setIcon } from "obsidian";
import BMOGPT from "src/main";
import { Setting, SettingTab, setIcon } from 'obsidian';
import BMOGPT from 'src/main';

export function addAnthropicConnectionSettings(containerEl: HTMLElement, plugin: BMOGPT, SettingTab: SettingTab) {
const toggleSettingContainer = containerEl.createDiv({ cls: 'toggleSettingContainer' });
Expand Down Expand Up @@ -34,7 +34,7 @@ export function addAnthropicConnectionSettings(containerEl: HTMLElement, plugin:
.setDesc('Insert Anthropic API Key.')
.addText(text => text
.setPlaceholder('insert-api-key')
.setValue(plugin.settings.APIConnections.anthropic.APIKey ? `${plugin.settings.APIConnections.anthropic.APIKey.slice(0, 6)}-...${plugin.settings.APIConnections.anthropic.APIKey.slice(-4)}` : "")
.setValue(plugin.settings.APIConnections.anthropic.APIKey ? `${plugin.settings.APIConnections.anthropic.APIKey.slice(0, 6)}-...${plugin.settings.APIConnections.anthropic.APIKey.slice(-4)}` : '')
.onChange(async (value) => {
plugin.settings.APIConnections.anthropic.APIKey = value;
await plugin.saveSettings();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Setting, SettingTab, setIcon } from "obsidian";
import BMOGPT from "src/main";
import { Setting, SettingTab, setIcon } from 'obsidian';
import BMOGPT from 'src/main';

export function addGoogleGeminiConnectionSettings(containerEl: HTMLElement, plugin: BMOGPT, SettingTab: SettingTab) {
const toggleSettingContainer = containerEl.createDiv({ cls: 'toggleSettingContainer' });
Expand Down Expand Up @@ -34,7 +34,7 @@ export function addGoogleGeminiConnectionSettings(containerEl: HTMLElement, plug
.setDesc('Insert Google Gemini API Key.')
.addText(text => text
.setPlaceholder('insert-api-key')
.setValue(plugin.settings.APIConnections.googleGemini.APIKey ? `${plugin.settings.APIConnections.googleGemini.APIKey.slice(0, 6)}-...${plugin.settings.APIConnections.googleGemini.APIKey.slice(-4)}` : "")
.setValue(plugin.settings.APIConnections.googleGemini.APIKey ? `${plugin.settings.APIConnections.googleGemini.APIKey.slice(0, 6)}-...${plugin.settings.APIConnections.googleGemini.APIKey.slice(-4)}` : '')
.onChange(async (value) => {
plugin.settings.APIConnections.googleGemini.APIKey = value;
await plugin.saveSettings();
Expand Down
Loading

0 comments on commit 31d3fa8

Please sign in to comment.