From 73c25761f6b879d78ebd8ecddac35881848831db Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sun, 29 Mar 2026 17:51:22 +0900 Subject: enable image attachments to the chat --- src/ollama-client.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/ollama-client.ts') diff --git a/src/ollama-client.ts b/src/ollama-client.ts index b778798..f86e5e7 100644 --- a/src/ollama-client.ts +++ b/src/ollama-client.ts @@ -2,6 +2,7 @@ import { Platform, requestUrl, TFile } from "obsidian"; import type { App } from "obsidian"; import type { OllamaToolDefinition } from "./tools"; import { findToolByName } from "./tools"; +import { hasCurrentAttachments } from "./image-attachments"; import systemPromptData from "./context/system-prompt.json"; import markdownRulesData from "./context/obsidian-markdown-rules.json"; @@ -293,6 +294,8 @@ function preValidateTool( return preValidateBatchMoveFile(app, args); case "batch_set_frontmatter": return preValidateBatchSetFrontmatter(app, args); + case "save_image": + return preValidateSaveImage(args); default: return null; } @@ -401,6 +404,19 @@ function preValidateSetFrontmatter(app: App, args: Record): str return null; } +function preValidateSaveImage(args: Record): string | null { + const filePath = typeof args["file_path"] === "string" ? args["file_path"] : ""; + if (filePath === "") { + return "Error: file_path parameter is required."; + } + + if (!hasCurrentAttachments()) { + return "Error: No images are attached to the current message. The user must attach images before you can save them."; + } + + return null; +} + // -- Batch tool validators ----------------------------------------------------- function preValidateBatchEditFile(app: App, args: Record): string | null { -- cgit v1.2.3