-
-
Notifications
You must be signed in to change notification settings - Fork 8
Home
(Made with https://www.openrepowiki.xyz)
The src folder is the core of the Obsidian InlineAI plugin, enabling AI-assisted editing within the Obsidian editor. It integrates AI-generated responses, editor state management, and user interactions through key modules like AIExtension.ts, SelectionState.ts, and WidgetExtension.ts. The ChatApiManager in api.ts manages interactions with AI APIs like OpenAI and Ollama. The main.ts file initializes the plugin and registers editor extensions, while settings.ts handles user-configurable settings for the AI provider and model. Key components include the FloatingWidget for AI interactions and the ChangeContentWidget for diff visualization. The folder depends on CodeMirror for editor integration and external libraries like @langchain/openai for AI interactions.
The src folder is the core of the Obsidian InlineAI plugin, providing AI-assisted editing capabilities within the Obsidian editor. It integrates AI-generated responses, editor state management, and user interactions through modules like AIExtension.ts, SelectionState.ts, and WidgetExtension.ts. The folder also includes the ChatApiManager in api.ts, which manages interactions with AI APIs like OpenAI and Ollama. The main.ts file serves as the entry point, initializing the plugin and registering editor extensions, while settings.ts handles user-configurable settings for the AI provider and model. Key components include the FloatingWidget for AI interactions and the ChangeContentWidget for diff visualization. The folder depends on CodeMirror for editor integration and external libraries like @langchain/openai for AI interactions.
The api.ts file is responsible for managing interactions with different chat APIs, specifically OpenAI and Ollama, within the Obsidian InlineAI plugin. It provides a centralized class, ChatApiManager, which handles the initialization of the chat client based on user settings and facilitates API calls. The class includes methods like callApi for sending messages to the chat API and handleEditorUpdate for updating the editor with the AI-generated response. Additionally, it supports specific use cases like callCursor for cursor-based interactions and callSelection for transforming selected text. The file depends on external libraries like @langchain/openai, @langchain/ollama, and @langchain/core/messages, as well as internal modules like settings and AIExtension.
The main.ts file serves as the entry point for the Obsidian plugin, initializing and managing the plugin's core functionalities. It sets up the plugin's settings, registers editor extensions, and handles commands for interacting with the editor. The file integrates various modules such as FloatingTooltipExtension, ChatApiManager, and SelectionState to provide features like tooltips, AI-generated responses, and text selection handling. Key components include the MyPlugin class, which extends the Obsidian Plugin class, and the onload method, which initializes the plugin and registers editor extensions. The file also manages settings through the loadSettings and saveSettings methods.
The settings.ts file is responsible for managing the settings of the Obsidian plugin, allowing users to configure the AI provider, model, and API key. It defines the settings interface MyPluginSettings and provides default values DEFAULT_SETTINGS. The MyPluginSettingTab class extends Obsidian's PluginSettingTab to create a user interface for modifying these settings. The file handles dynamic UI updates, such as showing or hiding the API key field based on the selected provider.
The src/modules folder contains core functionality for managing AI-generated responses, editor state, and user interactions within the Obsidian InlineAI plugin. It integrates AI capabilities with the CodeMirror editor, handling text selection, widget rendering, and diff visualization. Key modules include AIExtension.ts for managing AI responses, SelectionState.ts for tracking and highlighting text selections, WidgetExtension.ts for rendering a floating widget for AI interactions, and diffExtension.ts for visualizing and applying AI-generated text differences. These modules work together to provide a seamless AI-assisted editing experience, with dependencies on CodeMirror's state management and the ChatApiManager for AI interactions. Important components include the AIResponse Interface, the FloatingWidget class, and the ChangeContentWidget for diff visualization.
The AIExtension.ts file is responsible for managing AI-generated responses within the Obsidian InlineAI plugin. It defines a custom interface AIResponse to structure the AI's response and prompt, and uses CodeMirror's state management to handle the response state. The file introduces a state effect setGeneratedResponseEffect to update the AI response and a state field generatedResponseState to store it. The state field also handles clearing the response when a dismiss tooltip effect is triggered. This module plays a crucial role in integrating AI-generated content into the editor's state, ensuring seamless interaction between the AI and the user interface.
Key components include:
-
AIResponseInterface: Defines the structure for AI responses. -
setGeneratedResponseEffectState Effect: Updates the AI response in the state. -
generatedResponseStateState Field: Manages the storage and updates of the AI response.
The SelectionState.ts file is responsible for managing the selection state within the CodeMirror editor in the Obsidian InlineAI plugin. It defines interfaces, effects, and state fields to handle text selection, highlighting, and tooltip interactions. The file primarily deals with tracking the current selection range and text, and applying decorations to highlight the selected text in the editor.
Key components include:
-
SelectionInfoInterface: Describes the selection range and text. -
setSelectionInfoEffect: Effect to set or clear the selection info. -
currentSelectionState: State field that holds the most recent selection info. -
buildSelectionHighlightState: Manages the decoration set for highlighting the selected text.
The WidgetExtension.ts file is responsible for managing a floating widget that appears over text selections in an editor, allowing users to interact with an AI (likely a copilot-like feature) to process or modify the selected text. The widget includes input fields, submit buttons, and action buttons (Accept, Discard) to handle AI responses. The file integrates with the ChatApiManager for AI interactions and uses EditorState and EditorView from CodeMirror for rendering and state management.
The diffExtension.ts file is responsible for visualizing and applying differences between AI-generated text and the current editor context in an Obsidian plugin. It uses the diff-match-patch library to compute and display differences, and provides a widget-based visualization for added or removed content. The file defines a ChangeContentWidget class for rendering these changes with accessibility considerations, and a generateDiffView function to create a DecorationSet representing the diff. The diffDecorationState field manages the state of these decorations, and the applyDiffPlugin handles applying AI-suggested changes when triggered.
Key components include:
-
ChangeContentWidgetClass: Renders AI-suggested content differences. -
generateDiffViewFunction: Creates aDecorationSetfor visualizing text diffs.