### Package Metadata File Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md An example JSON5 file illustrating the structure of package metadata, including package hashes, installed packages, resources, and subscriptions. ```json5 { packagesHash: { "essay-templates": { packageId: "essay-templates", name: "Essay Templates", version: "1.0.0", description: "Collection of essay writing templates", author: "Template Author", installed: true, type: "template" } }, installedPackagesHash: { "essay-templates": { packageId: "essay-templates", version: "1.0.0", prompts: [ { promptId: "intro-paragraph", id: "intro", name: "Introduction", path: "textgenerator/templates/essays/intro.md" } ] } }, resources: {}, subscriptions: [] } ``` -------------------------------- ### PackageManager Example Usage Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Demonstrates common operations with the PackageManager, including loading, fetching, installing, updating, and uninstalling packages, as well as retrieving resources and paths. ```typescript // Load packages from vault await packageManager.load(); // Fetch available packages const allPackages = await packageManager.fetchPackageRegistry(); // Install a package await packageManager.installPackage("essay-templates"); // Get installed packages const installed = packageManager.getInstalledPackages(); // Get package info const info = packageManager.getPackageInfo("essay-templates"); console.log(info.author); // Update a package await packageManager.updatePackage("essay-templates"); // Uninstall a package await packageManager.uninstallPackage("essay-templates"); // Get templates directory const templatesPath = packageManager.getPromptsPath(); // Get resources const resources = packageManager.getResources(); ``` -------------------------------- ### Load LLM Provider Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Examples demonstrating how to load LLM providers by their slug or ID. ```typescript await requestHandler.loadllm("Claude"); // Load by slug ``` ```typescript await requestHandler.loadllm("claude-langchain"); // Load by ID ``` -------------------------------- ### Install Dependencies Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/README.md Install the necessary project dependencies using pnpm before building the plugin. ```bash pnpm install ``` -------------------------------- ### Install handlebars-async-helpers Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/src/lib/async-handlebars-helper/README.md Install the library using npm. This command adds the package to your project's dependencies. ```shell npm install handlerbars-async-helpers ``` -------------------------------- ### Clone Repository for Manual Installation Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/README.md Use this command to clone the plugin repository for manual installation or to use the latest development version. ```bash git clone https://github.com/nhaouari/obsidian-textgenerator-plugin.git ``` -------------------------------- ### installPackage Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Installs a template package from the registry. ```APIDOC ## installPackage ### Description Install a template package. ### Parameters #### Path Parameters - **packageId** (string) - Required - Package identifier - **version** (string) - Optional - Specific version to install ### Returns Promise ### Behavior 1. Download package from registry 2. Extract to templates directory 3. Update configuration with installed package info 4. Show success notification ``` -------------------------------- ### Get List of Installed Packages Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Retrieves an array containing information about all currently installed template packages. ```typescript getInstalledPackages(): InstalledPackage[] ``` -------------------------------- ### Output Template Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md Provides an example of an output template for a 'tg' block, using Handlebars syntax to display the generated content when the user clicks the generate button. ```handlebars # Result Generated text: {{generated_output}} ``` -------------------------------- ### ContentManager Example Usage Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Demonstrates common ContentManager operations including getting editor content, selection, cursor position, inserting text, streaming text, replacing content, and accessing the active file. ```typescript // Get current view and compile editor const activeView = await plugin.getActiveView(); const editor = ContentManagerCls.compile(activeView, plugin); // Get content const fullContent = await editor.getValue(); // Get selection const selected = await editor.getSelection(); // Get cursor position const cursor = editor.getCursor("to"); // Insert text at cursor await editor.insertText("Generated text", cursor, "insert"); // Stream text (for real-time output) const stream = await editor.insertStream(cursor, "stream"); for (const token of tokens) { stream.insert(token); } stream.end(); // Replace selection await editor.insertText("Replacement", editor.getCursor("from"), "replace"); // Get file const file = editor.getActiveFile(); console.log(file?.path); ``` -------------------------------- ### Add LLM Clone Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Example of adding a custom LLM provider clone, specifying its ID, name, and the provider it extends. ```typescript await requestHandler.addLLMCloneInRegistry({ id: "my-gpt4", name: "My Custom GPT-4", extends: "gpt-4-langchain", extendsDataFrom: "gpt-4-langchain" }); ``` -------------------------------- ### Simple Summary Block Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md A basic 'tg' block example that generates a summary of the note content. It uses the `generated_output` variable in its output template. ```markdown ```tg --- outputToBlockQuote: false --- # Auto-Summary Generate a concise summary of this note. --- ## Summary {{generated_output}} ``` ``` -------------------------------- ### Install Template Package Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Installs a specified template package. Optionally, a specific version can be provided. The package is downloaded, extracted, and configuration is updated. ```typescript async installPackage(packageId: string, version?: string): Promise ``` -------------------------------- ### Create and Use LLMProviderRegistry Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Demonstrates how to create a registry with providers, load them, and look them up by ID or slug. Also shows how to get a list of all provider IDs. ```typescript const providers = { "gpt-4-langchain": GPT4Provider, "claude-langchain": ClaudeProvider, ... }; const registry = new LLMProviderRegistry(providers); // Load indices registry.load(); // Lookup by slug const claude = registry.get("Claude"); // Lookup by ID const gpt4 = registry.get("gpt-4-langchain"); // List all const allIds = registry.getList(); // Check slug const providerSlug = registry.UnProviderSlugs["gpt-4-langchain"]; // "GPT-4" ``` -------------------------------- ### Input Template Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md Shows an example of an input template within a 'tg' block, utilizing Handlebars syntax to access note title and content variables for immediate rendering. ```handlebars Generate a title for: {{title}} Current content: {{substring content 0 200}} ``` -------------------------------- ### getSettings Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Get current plugin settings. ```APIDOC ## getSettings ### Description Get current plugin settings. ### Method GET ### Endpoint /settings ### Parameters #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **settings** (TextGeneratorSettings) - Current plugin settings object #### Response Example ```json { "max_tokens": 1000, "temperature": 0.7 } ``` ``` -------------------------------- ### AutoSuggest Setup Method Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/AutoSuggest.md Initializes auto-suggest services, including registering suggestion providers and setting up key listeners. This method is called automatically during construction. ```typescript private setup(): void ``` -------------------------------- ### Template-Based Generation Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/README.md This example demonstrates generating content using a specified template file and custom parameters. Ensure the 'contentManager' is correctly set up. ```typescript await textGenerator.generateFromTemplate({ params: { temperature: 0.5 }, templatePath: "templates/essay.md", editor: contentManager }); ``` -------------------------------- ### Complete Plugin Service API Integration Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md This example shows a full Obsidian plugin that uses the Text Generator plugin's API to generate a title, switch to a different provider, and list available providers. It requires importing the 'pluginApi' and 'Notice' from 'obsidian'. ```typescript import { Plugin, Notice } from "obsidian"; import { pluginApi } from "@vanakat/plugin-api"; export default class MyPlugin extends Plugin { async onload() { // Get Text Generator API const tgPlugin = await pluginApi.getPlugin( "obsidian-textgenerator-plugin" ); const api = tgPlugin.pluginAPIService; // Add a command that uses Text Generator this.addCommand({ id: "my-generate-title", name: "Generate Title using Text Generator", callback: async () => { try { const prompt = `Generate a concise title for a note with this content: {{content}}`; const title = await api.gen(prompt, { max_tokens: 50, temperature: 0.5 }); new Notice(`Generated title: ${title}`); } catch (error) { new Notice(`Error: ${error}`); } } }); // Switch to a different provider this.addCommand({ id: "my-switch-to-claude", name: "Switch to Claude", callback: async () => { try { await api.selectProvider("Claude"); new Notice("Switched to Claude"); } catch (error) { new Notice(`Error switching provider: ${error}`); } } }); // List available providers this.addCommand({ id: "my-list-providers", name: "List available providers", callback: async () => { const providers = await api.getListOfProviders(); new Notice(`Available providers:\n${providers.join("\n")}`); } }); } } ``` -------------------------------- ### Metadata-Based Block Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md A 'tg' block example that includes metadata like `includeMetadata: true` and accesses frontmatter variables such as `frontmatter.tags` within its template. ```markdown ```tg --- outputToBlockQuote: false includeMetadata: true --- Generate content based on: - Title: {{title}} - Tags: {{frontmatter.tags}} --- ``` -------------------------------- ### ContextManager.md Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/README.md Reference for the template context manager, detailing methods for getting context from various sources, metadata extraction, and content retrieval. It documents all 20+ available context variables with comprehensive examples. ```APIDOC ## ContextManager.md ### Description This document provides a comprehensive reference for the ContextManager, responsible for managing template contexts. It details methods for retrieving context from various sources, extracting metadata and content, and processing templates with Handlebars helpers. All 20+ available context variables are documented with extensive examples. ### API Surface - `getContext()` - `getContextFromFiles()` - `getTemplateContext()` - `getMetaData()` - `getHeadingContent()` - `getChildrenContent()` - `getExtractions()` - `getHighlights()` - `getMentions()` - Template processing - Handlebars helpers - 20+ available context variables ``` -------------------------------- ### RequestHandler Initialization and Usage Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Provides a comprehensive example of initializing the RequestHandler, loading LLM providers, creating custom providers, generating text, and cancelling requests. ```typescript // Initialize const requestHandler = new RequestHandler(plugin); await requestHandler.load(); // Get current provider const provider = requestHandler.LLMProvider; // Switch provider await requestHandler.loadllm("Claude"); // Create custom provider await requestHandler.addLLMCloneInRegistry({ id: "my-gpt4", name: "My GPT-4 Config", extends: "gpt-4-langchain" }); // Generate text const result = await requestHandler.gen("Hello world", { max_tokens: 100 }); // Cancel request requestHandler.signalController?.abort(); ``` -------------------------------- ### getInstalledPackages Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Retrieves a list of all installed template packages. ```APIDOC ## getInstalledPackages ### Description Get list of installed packages. ### Returns InstalledPackage[] ``` -------------------------------- ### Get Text Generator Plugin API Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Import the pluginApi and retrieve the Text Generator plugin service. This is the initial setup required to use the PluginServiceAPI from an external plugin. ```typescript import { pluginApi } from "@vanakat/plugin-api"; // Get the Text Generator plugin API const textGenPlugin = await pluginApi.getPlugin( "obsidian-textgenerator-plugin" ); const api = textGenPlugin.pluginAPIService; ``` -------------------------------- ### Three-Part TG Block Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md Demonstrates a 'tg' block with YAML metadata, an input template for immediate rendering, and an output template for interactive generation. ```markdown ```tg --- outputToBlockQuote: false --- # Summary Generate a summary for: {{content}} --- ## Generated Summary Click the button below to generate: {{#if generated}} {{generated}} {{else}} _Summary will appear here_ {{/if}} ``` ``` -------------------------------- ### InstalledPackage Type Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Defines the structure for an installed package, including its version and associated prompts. ```typescript type InstalledPackage = { packageId: string; version?: string; prompts?: PromptTemplate[]; installedPrompts?: installedPrompts[]; } ``` -------------------------------- ### ProviderSlugsList Array Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Shows a flat array containing all registered provider slugs. ```typescript ["Claude", "GPT-4", "Gemini", ...] ``` -------------------------------- ### getProvidersOptions Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Get configuration options for a specific provider. ```APIDOC ## getProvidersOptions ### Description Get configuration options for a specific provider. ### Method GET ### Endpoint /providers/{slug}/options ### Parameters #### Path Parameters - **slug** (string) - Required - Provider ID or slug ### Request Example ```json {} ``` ### Response #### Success Response (200) - **options** (Record) - Options object for the provider #### Response Example ```json { "api_key": "sk-xxxxxxxxxxxxxxxxxxxx", "model": "gpt-4" } ``` ``` -------------------------------- ### ProxyService Usage Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Shows how to control the local proxy server using the proxyService. This is useful for providers like Ollama that may require a local proxy. ```typescript await this.proxyService.start(); // Start proxy server await this.proxyService.stop(); // Stop proxy server ``` -------------------------------- ### getPromptsPath Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Gets the file system path where templates are stored. ```APIDOC ## getPromptsPath ### Description Get the path where templates are stored. ### Returns string - Path string (from `plugin.settings.promptsPath`) ``` -------------------------------- ### Context Access Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md Demonstrates how to access the plugin's context manager to retrieve context variables, such as editor state and file path, which can be passed to templates. ```typescript const context = await this.plugin.contextManager.getContext({ editor: CM, filePath: activeView?.file?.path, templateContent: inputContent, }); ``` -------------------------------- ### ProviderSlugs Map Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Illustrates the mapping from provider slugs to their corresponding IDs, used for quick lookup by a user-friendly name. ```typescript { "Claude": "claude-langchain", "GPT-4": "gpt-4-langchain", "Gemini": "gemini-langchain", ... } ``` -------------------------------- ### getListOfProviders Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Get list of available LLM providers. ```APIDOC ## getListOfProviders ### Description Get list of available LLM providers. ### Method GET ### Endpoint /providers ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **providers** (string[]) - Array of provider IDs/slugs #### Response Example ```json [ "OpenAI Chat (Langchain)", "Claude", "Gemini" ] ``` ``` -------------------------------- ### UnProviderNames Map Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Illustrates the mapping from provider IDs to their full display names, providing a more descriptive name for each provider. ```typescript { "claude-langchain": "Anthropic Chat (Langchain)", "gpt-4-langchain": "OpenAI Chat (Langchain)", ... } ``` -------------------------------- ### Blockquote Wrapping Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Illustrates how generated text is wrapped in a blockquote when the 'wrapInBlockQuote' option is enabled. ```markdown > Generated text > appears here > as blockquote ``` -------------------------------- ### AutoSuggest.md Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/README.md Reference for text auto-suggestions, covering methods like getGPTSuggestions() and setup(), configuration details, and sub-components. It explains trigger phrases, debouncing, and template variables for suggestions. ```APIDOC ## AutoSuggest.md ### Description This document provides reference for the AutoSuggest feature, including methods like `getGPTSuggestions()` and `setup()`, along with configuration details. It covers the InlineSuggest and ListSuggest sub-components, trigger phrases, debouncing, and the use of template variables for suggestions. ### API Surface - `getGPTSuggestions()` - `setup()` - Configuration - InlineSuggest sub-component - ListSuggest sub-component - Trigger phrases - Debouncing - Template variables for suggestions ``` -------------------------------- ### Example Usage of TextGeneratorPlugin API Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TextGeneratorPlugin.md Demonstrates how to access and use the TextGeneratorPlugin's services from another plugin using the @vanakat/plugin-api. This includes generating text, retrieving settings, and selecting an LLM provider. ```typescript // Access from another plugin using @vanakat/plugin-api import { pluginApi } from "@vanakat/plugin-api"; const textGenPlugin = await pluginApi.getPlugin("obsidian-textgenerator-plugin"); // Generate text const result = await textGenPlugin.pluginAPIService.gen( "Create a title for my document", { max_tokens: 100 } ); // Get settings const settings = await textGenPlugin.pluginAPIService.getSettings(); // Select a different LLM provider await textGenPlugin.pluginAPIService.selectProvider("Claude"); ``` -------------------------------- ### UnProviderSlugs Map Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Demonstrates the reverse mapping from provider IDs to their slugs, useful for finding the slug associated with a given ID. ```typescript { "claude-langchain": "Claude", "gpt-4-langchain": "GPT-4", "gemini-langchain": "Gemini", ... } ``` -------------------------------- ### ReqFormatter Usage Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Demonstrates how to access and use the reqFormatter instance to format requests for LLM providers. This includes API key handling, parameter formatting, and template compilation. ```typescript const formatter = this.reqFormatter; // Formats: // - API keys (with encryption) // - Request parameters // - Handlebars template compilation // - Message formatting per provider ``` -------------------------------- ### Load Package Configuration Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Loads package configuration from the vault. Initializes a default configuration file if it doesn't exist. Parses installed packages and migrates old formats. ```typescript async load(): Promise ``` -------------------------------- ### Get Prompts Directory Path Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Returns the file system path where all template prompts are stored. This path is derived from the plugin's settings. ```typescript getPromptsPath(): string ``` -------------------------------- ### Request Cancellation Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Illustrates how to abort pending LLM generation requests using the signalController. A new AbortController can be created for subsequent requests. ```typescript // Abort current generation requestHandler.signalController?.abort(); // Create new controller for next request requestHandler.signalController = new AbortController(); ``` -------------------------------- ### Get Cursor Position Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the current cursor position within the editor. Specify 'from' or 'to' to get the start or end of a selection. ```typescript getCursor(pos?: "from" | "to"): EditorPosition ``` -------------------------------- ### Get Resources Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Retrieves all registered resources, returned as an object mapping resource IDs to Resource objects. ```typescript getResources(): Record ``` -------------------------------- ### Navigate to Plugin Directory Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/README.md After cloning the repository, navigate into the plugin's directory using this command. ```bash cd obsidian-textgenerator-plugin ``` -------------------------------- ### Get Package Configuration File Path Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Returns the absolute path to the package configuration file within the vault. This is a private helper method. ```typescript private getConfigPath(): string ``` -------------------------------- ### PackageManager.md Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/README.md Documentation for template package management, including methods for loading, installing, uninstalling, and updating packages. It covers fetching package registries and configuration management. ```APIDOC ## PackageManager.md ### Description This reference details the PackageManager, responsible for managing template packages. It includes methods for loading, installing, uninstalling, and updating packages, as well as fetching package registries. Configuration management for packages is also covered. ### API Surface - `load()` - `installPackage()` - `uninstallPackage()` - `updatePackage()` - `fetchPackageRegistry()` - `fetchCorePackageRegistry()` - Configuration management (`getConfigPath`, `saveConfiguration`) - Resource and subscription management ``` -------------------------------- ### Handle Provider Not Found Error Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Demonstrates how to handle cases where a requested provider is not found in the registry. The `get` method returns `undefined` in such scenarios. ```typescript const provider = registry.get("InvalidProvider"); if (!provider) { console.error("Provider not found"); } ``` -------------------------------- ### Get Mentions in File Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Fetches referenced pages and links within a given file. If no file path is specified, it targets the active note. ```typescript async getMentions(filePath?: string): Promise ``` -------------------------------- ### Get Context for Multiple Files Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Fetches context data for an array of specified files. Use this when you need to process multiple notes with the same template. ```typescript async getContextFromFiles( files: TFile[], templatePath: string, additionalProps?: any ): Promise ``` -------------------------------- ### Build the Plugin Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/README.md Build the plugin for production use with this command. ```bash pnpm run build ``` -------------------------------- ### PluginServiceAPI.md Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/README.md Documentation for the public API exposed to external plugins, including methods for settings, generation, metadata retrieval, and provider selection. Provides a complete example for external plugin integration. ```APIDOC ## PluginServiceAPI.md ### Description This reference details the public API provided for external plugins, enabling them to interact with the Text Generator plugin. It exposes methods for accessing settings, initiating text generation, retrieving metadata, and managing provider selection. A complete example for external plugin integration is included. ### API Surface - `getSettings()` - `gen()` - `getMetadata()` - `getChildrensOf()` - `getListOfProviders()` - `getProvidersOptions()` - `selectProvider()` - Complete example for external plugin integration ``` -------------------------------- ### Get Specific Package Information Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Retrieves metadata for a single package based on its identifier. Returns null if the package is not found. ```typescript getPackageInfo(packageId: string): PackageTemplate | null ``` -------------------------------- ### load() Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Asynchronously loads the LLM provider system on plugin initialization. ```APIDOC ## load() ### Description Asynchronously loads the LLM provider system on plugin initialization. ### Behavior 1. Loads LLM provider registry 2. Loads initial LLM provider from settings ### Returns Promise ``` -------------------------------- ### Update Installed Package Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Updates a previously installed template package to its latest available version. Requires the package identifier. ```typescript async updatePackage(packageId: string): Promise ``` -------------------------------- ### Get Provider Configuration Options Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Retrieve the specific configuration options for a given LLM provider slug. This allows inspection of parameters like API keys or model names. ```typescript const openaiOptions = await apiService.getProvidersOptions("OpenAI Chat (Langchain)"); console.log(openaiOptions.api_key); ``` -------------------------------- ### load Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Loads package configuration from the vault, initializing default configuration if the file does not exist. ```APIDOC ## load ### Description Load package configuration from vault. Initializes default configuration if file doesn't exist. ### Returns Promise ### Behavior 1. Reads configuration from `textgenerator/config.json5` 2. Creates file if it doesn't exist 3. Parses installed packages 4. Migrates old format to new hash-based format ``` -------------------------------- ### Title Generator Block Example Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md An example 'tg' block that generates a title for the note. It wraps the output in a blockquote as specified by `outputToBlockQuote: true`. ```markdown ```tg --- outputToBlockQuote: true --- # Generate Title What would be a good title for a note containing: {{substring content 0 100}} --- ## Your Generated Title {{generated_output}} ``` ``` -------------------------------- ### Constructor Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Initializes a new instance of the PackageManager class. ```APIDOC ## Constructor PackageManager ### Description Initializes a new instance of the PackageManager class. ### Parameters #### Path Parameters - **app** (App) - Required - Obsidian App instance - **plugin** (TextGeneratorPlugin) - Required - Plugin instance ``` -------------------------------- ### Initialize Default Configuration File Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Creates a default configuration file for package management if one does not already exist. This is a private helper method. ```typescript private async initConfigFlie(): Promise ``` -------------------------------- ### get(name: string): T | undefined Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Retrieves a provider instance by its ID or slug. It first attempts to find the provider by slug and falls back to a direct ID lookup. ```APIDOC ## get(name: string): T | undefined ### Description Get a provider by ID or slug. ### Parameters * **name** (string) - Required - Provider ID or slug. ### Returns Provider instance or undefined if not found ### Behavior 1. First tries to look up by slug using ProviderSlugs 2. Falls back to direct ID lookup 3. Returns matching provider or undefined ### Example ```typescript const provider = registry.get("Claude"); // Lookup by slug const provider2 = registry.get("claude-langchain"); // Lookup by ID ``` ``` -------------------------------- ### getMetadata Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Get metadata/frontmatter for a note. ```APIDOC ## getMetadata ### Description Get metadata/frontmatter for a note. ### Method GET ### Endpoint /metadata/{path} ### Parameters #### Path Parameters - **path** (string) - Required - Path to note file ### Request Example ```json {} ``` ### Response #### Success Response (200) - **metadata** (CachedMetadata | null) - CachedMetadata object or null if file not found #### Response Example ```json { "frontmatter": { "tags": ["example", "note"], "date": "2023-10-27" } } ``` ``` -------------------------------- ### getChildrensOf Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Get content of child notes. ```APIDOC ## getChildrensOf ### Description Get content of child notes. ### Method GET ### Endpoint /children/{path} ### Parameters #### Path Parameters - **path** (string) - Required - Path to parent note ### Request Example ```json {} ``` ### Response #### Success Response (200) - **children** (Array) - Array of child note contents #### Response Example ```json [ "Content of child note 1", "Content of child note 2" ] ``` ``` -------------------------------- ### loadLLMRegistry() Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Asynchronously loads and initializes the LLM provider registry. ```APIDOC ## loadLLMRegistry() ### Description Asynchronously loads and initializes the LLM provider registry. ### Behavior 1. Imports default providers from `src/LLMProviders/` 2. Merges with custom provider clones from settings 3. Creates LLMProviderRegistry with all providers 4. Calls registry.load() to index providers ### Returns Promise ``` -------------------------------- ### LLMProviderRegistry Constructor Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Initializes a new LLMProviderRegistry instance. It can optionally take an initial set of plugins to populate the registry. ```APIDOC ## Constructor LLMProviderRegistry ### Description Initializes a new LLMProviderRegistry instance. It can optionally take an initial set of plugins to populate the registry. ### Parameters * **plugins** (Record) - Optional - Initial providers map. `T` must extend `{slug?: any; id: any; displayName?: string}`. ``` -------------------------------- ### Constructor Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/AutoSuggest.md Initializes the AutoSuggest service with the Obsidian App instance and the TextGeneratorPlugin instance. ```APIDOC ## Constructor ```typescript constructor(app: App, plugin: TextGeneratorPlugin) ``` ### Parameters - **app** (App) - Required - Obsidian App instance - **plugin** (TextGeneratorPlugin) - Required - Plugin instance ``` -------------------------------- ### Get Subscriptions Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Retrieves all registered subscriptions as an array of Subscription objects. ```typescript getSubscriptions(): Subscription[] ``` -------------------------------- ### Get Current Selection Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the text that is currently selected by the user in the editor. ```typescript getSelection(): Promise ``` -------------------------------- ### selectProvider Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Switch to a different LLM provider. ```APIDOC ## selectProvider ### Description Switch to a different LLM provider. ### Method POST ### Endpoint /providers/select ### Parameters #### Query Parameters None #### Request Body - **slug** (string) - Required - Provider ID or slug to activate ### Request Example ```json { "slug": "Claude" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message #### Response Example ```json { "message": "Provider Claude selected successfully." } ``` ``` -------------------------------- ### load() Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Initializes the registry indices by building mappings for provider slugs, IDs, and display names. This method must be called after construction and before using lookup methods. ```APIDOC ## load() ### Description Initializes the registry indices. Must be called after construction before using lookup methods. ### Behavior 1. Clears previous indices 2. Iterates through all providers 3. Builds slug → ID mappings 4. Builds ID → slug reverse mappings 5. Builds ID → display name mappings ### Returns void ### Example ```typescript const registry = new LLMProviderRegistry(providers); registry.load(); // Index providers ``` ``` -------------------------------- ### Get PackageManager UI Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Provides access to the PackageManager UI component for rendering. ```typescript getPackageManagerUI(): PackageManagerUI ``` -------------------------------- ### Configure Custom Instruction Template Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/AutoSuggest.md Enables custom instructions for auto-suggestions and defines the template to be used. The {{query}} placeholder will be replaced with user input. ```typescript // Custom instruction template plugin.settings.autoSuggestOptions.customInstructEnabled = true; plugin.settings.autoSuggestOptions.customInstruct = " Complete this: {{query}} "; ``` -------------------------------- ### Constructor Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Initializes a new instance of the RequestHandler class. ```APIDOC ## Constructor ### Description Initializes a new instance of the RequestHandler class. ### Parameters - **plugin** (TextGeneratorPlugin) - Required - Plugin instance for settings access ``` -------------------------------- ### Get All Selections Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve all selected text segments if multiple selections exist in the editor. ```typescript getSelections(): Promise ``` -------------------------------- ### Create and Register a Custom Command Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/Commands.md Shows how to extend the static `Commands.commands` array with a new custom command and then register it with the plugin. ```typescript const commands = new Commands(plugin); // Extend static commands array Commands.commands.push({ id: "my-custom-command", name: "My Custom Command", callback() { const self: Commands = this as any; console.log("Custom command executed"); } }); // Register plugin.addCommand(Commands.commands[Commands.commands.length - 1]); ``` -------------------------------- ### Get Text in Range Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the text content located between two specified cursor positions. ```typescript getRange(from?: any, to?: any): string ``` -------------------------------- ### Get Active File Object Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the file object associated with the currently active view in Obsidian. ```typescript getActiveFile(): Promise | TFile | undefined ``` -------------------------------- ### Build Plugin for Development (Hot Reload) Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/README.md Use this command to build the plugin for development, enabling hot-reloading without restarting Obsidian. ```bash pnpm run dev ``` -------------------------------- ### Get Current Line Text Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the complete text content of the line where the cursor is currently located. ```typescript getCurrentLine(): string ``` -------------------------------- ### register(name: string, plugin: T) Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Registers a new LLM provider in the registry. After registration, `load()` must be called to update the registry indices. ```APIDOC ## register(name: string, plugin: T) ### Description Register a new provider in the registry. ### Parameters * **name** (string) - Required - Provider ID. * **plugin** (T) - Required - Provider instance. ### Returns void ### Note Call `load()` after registering to rebuild indices. ``` -------------------------------- ### TextGeneratorConfiguration Type Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Defines the structure of the TextGenerator configuration, including package hashes, installed packages, resources, and subscriptions. ```typescript type TextGeneratorConfiguration = { packagesHash: Record; installedPackagesHash: Record; resources: Record; subscriptions: Subscription[]; } ``` -------------------------------- ### Get Heading Structure from a Note Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Extracts the heading hierarchy from a specified note. Optionally filter headings by their level. ```typescript async getHeadingContent( headingLevel?: number, filePath?: string ): Promise ``` -------------------------------- ### fetchCorePackageRegistry Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Fetches core/official template packages from the registry. ```APIDOC ## fetchCorePackageRegistry ### Description Fetch core/official packages from registry. ### Returns Promise ### Source `https://raw.githubusercontent.com/text-gen/text-generator-packages/master/core-packages.json` ``` -------------------------------- ### Get Last Character Before Cursor Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the single character immediately preceding the cursor's current position. ```typescript getLastLetterBeforeCursor(): string ``` -------------------------------- ### Get List of Registered Provider IDs Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Retrieves an array containing the IDs of all currently registered LLM providers. ```typescript getList(): string[] ``` ```typescript const ids = registry.getList(); // Returns: ["gpt-4-langchain", "claude-langchain", ...] ``` -------------------------------- ### Get Plugin Settings Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Retrieve the current settings of the Text Generator plugin. This is useful for understanding or modifying generation parameters. ```typescript const settings = await apiService.getSettings(); console.log(settings.max_tokens); ``` -------------------------------- ### Get Full Content Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve the entire content of the current editor view. This is useful for operations that require the complete text. ```typescript const content = await editor.getValue(); ``` -------------------------------- ### Load LLM Registry Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Asynchronously loads and initializes the LLM provider registry by importing default providers, merging custom ones from settings, and indexing them. ```typescript async loadLLMRegistry(): Promise ``` -------------------------------- ### Get Current Timestamp Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/configuration.md The 'now' helper returns the current timestamp. This can be used for logging or time-based operations within templates. ```handlebars {{now}} ``` -------------------------------- ### getRange Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Extracts the text content within a specified range defined by start and end positions. Both positions can be optionally provided. ```APIDOC ## getRange ### Description Get text between two positions. ### Method `getRange(from?: any, to?: any): string` ### Parameters - **from** (any) - Optional - Start position. - **to** (any) - Optional - End position. ### Returns Text in range. ``` -------------------------------- ### Context Configuration with Handlebars Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/configuration.md Define custom context templates using Handlebars variables for dynamic content inclusion. ```yaml context: customInstructEnabled: true includeClipboard: true customInstruct: | Title: {{title}} Starred Blocks: {{starredBlocks}} {{tg_selection}} contextTemplate: | Title: {{title}} Starred Blocks: {{starredBlocks}} {{tg_selection}} ``` -------------------------------- ### getCursor Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieves the current cursor position within the editor. It can return the starting ('from') or ending ('to') position of a selection. ```APIDOC ## getCursor ### Description Get cursor position. ### Method `getCursor(pos?: "from" | "to"): EditorPosition` ### Parameters - **pos** ("from" | "to") - Optional - "from" for start, "to" for end of selection. ### Returns EditorPosition with `line` and `ch` properties. ``` -------------------------------- ### TextGeneratorPlugin loadSettings Method Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TextGeneratorPlugin.md Asynchronous method to load plugin settings from vault data. It initializes settings with defaults if none are found. ```typescript async loadSettings(): Promise ``` -------------------------------- ### TextGeneratorPlugin startProcessing Method Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TextGeneratorPlugin.md Sets the processing state of the plugin, which controls the visibility of the loading spinner. ```typescript startProcessing(value: boolean): void ``` -------------------------------- ### Package Manager Command Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/Commands.md Registers the 'Package Manager' command. This command opens the package manager interface for installing and managing templates. ```typescript id: "packageManager" name: "Package Manager" ``` -------------------------------- ### fetchPackageRegistry Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Fetches available template packages from the community registry. ```APIDOC ## fetchPackageRegistry ### Description Fetch available packages from community registry. ### Returns Promise ### Source `https://raw.githubusercontent.com/text-gen/text-generator-packages/master/community-packages.json` ``` -------------------------------- ### loadllm(name?: string) Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Asynchronously loads a specific LLM provider instance by name. ```APIDOC ## loadllm(name?: string) ### Description Asynchronously loads a specific LLM provider instance by name. ### Parameters - **name** (string) - Optional - Provider ID or slug (uses selectedProvider if empty) ### Returns Initialized LLMProviderInterface instance ### Behavior 1. Looks up provider from registry 2. Creates new instance if not already loaded 3. Calls provider.load() to initialize 4. Validates mobile compatibility 5. Sets as current LLMProvider ### Throws - Provider not found error - Mobile not supported error ### Example ```typescript await requestHandler.loadllm("Claude"); // Load by slug await requestHandler.loadllm("claude-langchain"); // Load by ID ``` ``` -------------------------------- ### Get Template Context Variables Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Retrieves all available context variables for template processing. This is useful for understanding what data can be injected into templates. ```typescript async getTemplateContext(options: any): Promise ``` -------------------------------- ### Get Note Metadata Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Retrieve the metadata, including frontmatter, for a specific note using its path. Returns null if the file is not found. ```typescript const metadata = apiService.getMetadata("My Note.md"); console.log(metadata?.frontmatter); ``` -------------------------------- ### Initialize LLMProviderRegistry in RequestHandler Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Shows how the RequestHandler class initializes and loads the LLMProviderRegistry with provided LLM providers. ```typescript // In RequestHandler this.LLMRegestry = new LLMProviderRegistry(llmProviders); await this.LLMRegestry.load(); // Load provider by name const provider = this.LLMRegestry.get("Claude"); ``` -------------------------------- ### Extract Substring Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/configuration.md Use the 'substring' helper to extract a portion of text. Specify the content, the starting index, and the desired length of the substring. ```handlebars {{substring content start length}} ``` -------------------------------- ### getGPTSuggestions Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/AutoSuggest.md Generates AI-powered text suggestions based on the current editor context. It extracts text, processes instructions, sends the request to the configured LLM provider, and formats the suggestions. ```APIDOC ## getGPTSuggestions(context: EditorSuggestContext): Promise ### Description Generate suggestions based on current editor context. ### Parameters #### Path Parameters - **context** (EditorSuggestContext) - Required - Editor context from Obsidian ### Returns Array of Completion objects ### Example Completion ```typescript { label: "suggestion text", value: "full suggestion to insert" } ``` ``` -------------------------------- ### Register Custom Provider Clone Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Illustrates how to create and register a custom provider clone with the registry. Remember to reload the registry after registration. ```typescript // When user creates a custom clone const clone = class extends OriginalProvider { static id = "my-claude"; static slug = "My Claude"; }; registry.register("my-claude", clone); registry.load(); // Rebuild indices ``` -------------------------------- ### Get Highlights from File Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Retrieves highlighted or starred blocks from a specified file. If no file path is provided, it defaults to the currently active note. ```typescript async getHighlights(filePath?: string): Promise ``` -------------------------------- ### Template Helper: Special Functions Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/README.md Utilize special template helpers for getting the current time, running other templates, or accessing clipboard content. ```handlebars {{now "format"}} ``` ```handlebars {{runTemplate templateId}} ``` ```handlebars {{clipboard}} ``` -------------------------------- ### Add Resource Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Adds a resource to the configuration. Requires a Resource object containing id, name, size, types, and metadata. ```typescript async addResource(resource: Resource): Promise ``` -------------------------------- ### Slash Suggest Configuration Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/configuration.md Configure options for slash command suggestions, including enabling the feature and setting the trigger phrase. ```typescript slashSuggestOptions: { isEnabled: false, triggerPhrase: "/", } ``` -------------------------------- ### TextGeneratorPlugin.md Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/README.md Documentation for the main plugin class, covering its lifecycle methods, properties, error handling, and API key management. It includes over 400 lines of complete method signatures. ```APIDOC ## TextGeneratorPlugin.md ### Description Provides documentation for the main plugin class, detailing its lifecycle methods (onload, onunload, loadSettings, saveSettings), properties such as services and UI elements, state management, error handling, encryption, and API key management. This reference includes over 400 lines of complete method signatures. ### API Surface - Plugin lifecycle methods - Properties: services, UI elements, state - Error handling - Encryption - API key management ``` -------------------------------- ### Get LLM Provider by ID or Slug Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/LLMProviderRegistry.md Retrieves a provider instance by its ID or its user-friendly slug. The lookup prioritizes slugs for a more flexible search. ```typescript get(name: string): T | undefined ``` ```typescript const provider = registry.get("Claude"); // Lookup by slug const provider2 = registry.get("claude-langchain"); // Lookup by ID ``` -------------------------------- ### addTGMenu Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TGBlock.md Adds an interactive menu to the rendered TGBlock, including buttons for generating text, copying to clipboard, and opening in a modal. ```APIDOC ## addTGMenu ### Description Adds an interactive menu to a rendered block. ### Method `private addTGMenu(el: HTMLElement, markdown: string, source: string, outputTemplate: Function): void` ### Parameters * **el** (HTMLElement) - Required - Container element. * **markdown** (string) - Required - Rendered markdown content. * **source** (string) - Required - Block source code. * **outputTemplate** (Function) - Required - Compiled output template function. ### Returns void ### Creates buttons for - Generate text - Copy to clipboard - Open in modal ``` -------------------------------- ### Open Template as Tool Command Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/Commands.md Registers the 'Templates: Open As Tool' command. This command opens a template in a side panel, making it available as a reusable tool. ```typescript id: "open-template-as-tool" name: "Templates: Open As Tool" ``` -------------------------------- ### TextGeneratorPlugin onload Method Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/TextGeneratorPlugin.md Asynchronous method called when the plugin is loaded. It handles initialization of services, command registration, UI setup, and API integration. ```typescript async onload(): Promise ``` -------------------------------- ### Write Data to File Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/configuration.md Use the 'write' helper to write data to a specified file. This operation will overwrite existing content. Ensure the path is correct and data is provided. ```handlebars {{write path data}} ``` -------------------------------- ### Default Custom Instruction Template Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/AutoSuggest.md The default template used for generating custom instructions to the LLM. It includes variables for note title, query text, and selection. ```handlebars Continue the following text: Title: {{title}} {{query}} ``` -------------------------------- ### Fetch Core Package Registry Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Fetches a list of core or official template packages from a dedicated registry. The source is a remote JSON file. ```typescript async fetchCorePackageRegistry(): Promise ``` -------------------------------- ### PluginServiceAPI - selectProvider() Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/README.md Allows external plugins to programmatically select the LLM provider to be used for subsequent generation requests. This is useful for dynamic provider switching based on specific needs. ```APIDOC ## PluginServiceAPI - selectProvider() ### Description Selects the LLM provider to be used for subsequent text generation requests. ### Method `selectProvider(providerId)` ### Parameters #### Request Body - **providerId** (string) - Required - The unique identifier of the LLM provider to select. ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the provider was successfully selected. #### Response Example ```json { "message": "Provider 'openai' selected successfully." } ``` ``` -------------------------------- ### Get Content of Child Notes Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Retrieves the content of notes that are considered children of a given parent note, based on its metadata. Useful for building hierarchical content. ```typescript async getChildrenContent( metadata: CachedMetadata, options?: any ): Promise ``` -------------------------------- ### Get Cached Metadata for a File Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContextManager.md Retrieves the cached metadata for a given file path. This method is efficient for accessing file metadata without re-reading the file. ```typescript getMetaData(filePath: string): CachedMetadata | null ``` -------------------------------- ### Fetch Community Package Registry Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PackageManager.md Fetches a list of available template packages from the community registry. The source is a remote JSON file. ```typescript async fetchPackageRegistry(): Promise ``` -------------------------------- ### Get Child Notes Content Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/PluginServiceAPI.md Retrieve the content of child notes for a given parent note path. This can be used to process or aggregate information from related notes. ```typescript const children = await apiService.getChildrensOf("Parent Note.md"); ``` -------------------------------- ### gen(prompt, settings) Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/RequestHandler.md Generates text from a given prompt using the current LLM provider, with optional settings overrides. It processes the prompt through Handlebars, calls the LLMProvider.generate method, and returns the generated text. ```APIDOC ## gen(prompt, settings) ### Description Generates text from a prompt using the current LLM provider. This method first processes the prompt through Handlebars, then calls the LLMProvider.generate() method, and finally returns the generated text. ### Method `async gen(prompt: string, settings?: Partial): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **prompt** (string) - Required - User prompt text - **settings** (Partial) - Optional - Override settings for this request ### Request Example ```typescript // Assuming requestHandler is an instance of RequestHandler const result = await requestHandler.gen("Hello world", { max_tokens: 100 }); ``` ### Response #### Success Response - **Generated text** (string) - The text generated by the LLM. #### Response Example ```json { "example": "Generated text string" } ``` ``` -------------------------------- ### Get Text Bounded by TG Delimiter Source: https://github.com/nhaouari/obsidian-textgenerator-plugin/blob/master/_autodocs/api-reference/ContentManager.md Retrieve text selection specifically bounded by a TextGenerator plugin delimiter. A custom regex can be provided to define the boundary. ```typescript getTgSelection(tgSelectionLimiter?: string): Promise | string ```