From 3b4fc37359bea855df9dbafcd1b5b7cef9872b73 Mon Sep 17 00:00:00 2001 From: Chris Lettieri Date: Tue, 15 Apr 2025 16:26:35 -0400 Subject: [PATCH] initial plugin --- README.md | 2 +- main.ts | 187 +++++++++++++++++---------------------------------- package.json | 10 ++- 3 files changed, 70 insertions(+), 129 deletions(-) diff --git a/README.md b/README.md index 3c0381a..7d50f1e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Open Augi +# OpenAugi ## Voice to Self-Organizing Second Brain for Obsidian Unlock the power of voice capture and go faster. diff --git a/main.ts b/main.ts index 2d07212..708a8ab 100644 --- a/main.ts +++ b/main.ts @@ -1,134 +1,71 @@ -import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian'; +import { Plugin, TFile } from 'obsidian'; +import OpenAI from 'openai'; +import * as dotenv from 'dotenv'; -// Remember to rename these classes and interfaces! +dotenv.config(); -interface MyPluginSettings { - mySetting: string; +export default class TranscriptParserPlugin extends Plugin { + async onload() { + this.watchFolder("transcripts"); + } + + watchFolder(folderPath: string) { + this.registerEvent(this.app.vault.on('create', async (file: TFile) => { + if (file.path.startsWith(folderPath)) { + const content = await this.app.vault.read(file); + await this.parseAndOutput(file.basename, content); + } + })); + } + + async parseAndOutput(filename: string, content: string) { + const openai = new OpenAI({ + apiKey: process.env.OPENAI_API_KEY + }); + + const prompt = `You will receive a raw transcript from voice notes. Identify all commands that start with the special token "AUGI" and parse them clearly. + +Example commands: +- "AUGI create note titled XYZ" → Create a new note with title XYZ. +- "AUGI summarize this" → Summarize preceding context. +- "AUGI add task ABC" → Create a new task item. + +Return strictly JSON: +{ + "summary": "Short summary (ignoring commands)", + "notes": [{"title": "Note Title", "content": "Content"}], + "tasks": ["task 1", "task 2"] } -const DEFAULT_SETTINGS: MyPluginSettings = { - mySetting: 'default' -} +Transcript:\n${content}`; -export default class MyPlugin extends Plugin { - settings: MyPluginSettings; + const response = await openai.chat.completions.create({ + model: "gpt-4-turbo", + messages: [{ role: 'user', content: prompt }] + }); - async onload() { - await this.loadSettings(); + const messageContent = response.choices[0].message.content; + if (!messageContent) { + throw new Error('No response content received from OpenAI'); + } + const structuredData = JSON.parse(messageContent); - // This creates an icon in the left ribbon. - const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => { - // Called when the user clicks the icon. - new Notice('This is a notice!'); - }); - // Perform additional things with the ribbon - ribbonIconEl.addClass('my-plugin-ribbon-class'); + // Output Summary + await this.app.vault.create(`Parsed_Notes/summaries/${filename}_summary.md`, structuredData.summary); - // This adds a status bar item to the bottom of the app. Does not work on mobile apps. - const statusBarItemEl = this.addStatusBarItem(); - statusBarItemEl.setText('Status Bar Text'); + // Output Notes + for (const note of structuredData.notes) { + await this.app.vault.create(`Parsed_Notes/notes/${note.title}.md`, note.content); + } - // This adds a simple command that can be triggered anywhere - this.addCommand({ - id: 'open-sample-modal-simple', - name: 'Open sample modal (simple)', - callback: () => { - new SampleModal(this.app).open(); - } - }); - // This adds an editor command that can perform some operation on the current editor instance - this.addCommand({ - id: 'sample-editor-command', - name: 'Sample editor command', - editorCallback: (editor: Editor, view: MarkdownView) => { - console.log(editor.getSelection()); - editor.replaceSelection('Sample Editor Command'); - } - }); - // This adds a complex command that can check whether the current state of the app allows execution of the command - this.addCommand({ - id: 'open-sample-modal-complex', - name: 'Open sample modal (complex)', - checkCallback: (checking: boolean) => { - // Conditions to check - const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView); - if (markdownView) { - // If checking is true, we're simply "checking" if the command can be run. - // If checking is false, then we want to actually perform the operation. - if (!checking) { - new SampleModal(this.app).open(); - } - - // This command will only show up in Command Palette when the check function returns true - return true; - } - } - }); - - // This adds a settings tab so the user can configure various aspects of the plugin - this.addSettingTab(new SampleSettingTab(this.app, this)); - - // If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin) - // Using this function will automatically remove the event listener when this plugin is disabled. - this.registerDomEvent(document, 'click', (evt: MouseEvent) => { - console.log('click', evt); - }); - - // When registering intervals, this function will automatically clear the interval when the plugin is disabled. - this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000)); - } - - onunload() { - - } - - async loadSettings() { - this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); - } - - async saveSettings() { - await this.saveData(this.settings); - } -} - -class SampleModal extends Modal { - constructor(app: App) { - super(app); - } - - onOpen() { - const {contentEl} = this; - contentEl.setText('Woah!'); - } - - onClose() { - const {contentEl} = this; - contentEl.empty(); - } -} - -class SampleSettingTab extends PluginSettingTab { - plugin: MyPlugin; - - constructor(app: App, plugin: MyPlugin) { - super(app, plugin); - this.plugin = plugin; - } - - display(): void { - const {containerEl} = this; - - containerEl.empty(); - - new Setting(containerEl) - .setName('Setting #1') - .setDesc('It\'s a secret') - .addText(text => text - .setPlaceholder('Enter your secret') - .setValue(this.plugin.settings.mySetting) - .onChange(async (value) => { - this.plugin.settings.mySetting = value; - await this.plugin.saveSettings(); - })); - } -} + // Append Tasks + const tasksFile = this.app.vault.getAbstractFileByPath("Parsed_Notes/tasks.md"); + if (tasksFile instanceof TFile) { + let existingTasks = await this.app.vault.read(tasksFile); + existingTasks += '\n' + structuredData.tasks.map((task: string) => `- [ ] ${task}`).join('\n'); + await this.app.vault.modify(tasksFile, existingTasks); + } else { + await this.app.vault.create("Parsed_Notes/tasks.md", structuredData.tasks.map((task: string) => `- [ ] ${task}`).join('\n')); + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6a00766..f94efa4 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,17 @@ "author": "", "license": "MIT", "devDependencies": { - "@types/node": "^16.11.6", + "@types/node": "^16.18.126", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", "builtin-modules": "3.3.0", "esbuild": "0.17.3", - "obsidian": "latest", + "obsidian": "^1.8.7", "tslib": "2.4.0", - "typescript": "4.7.4" + "typescript": "^4.7.4" + }, + "dependencies": { + "dotenv": "^16.5.0", + "openai": "^4.94.0" } }