refactor: use standalone tool run executor

This commit is contained in:
2026-08-24 06:53:18 +05:00
parent 474c1156aa
commit 1b3bad46d1
2 changed files with 19 additions and 3 deletions
+3 -3
View File
@@ -10,6 +10,7 @@
import ToolSearch from './search/ToolSearch.svelte';
import ChainToolBlock from './chain/ChainToolBlock.svelte';
import { createAutoRunner } from '$lib/tools/auto-run';
import { executeStep } from '$lib/tools/executor';
import ParamsCard from './tool/ParamsCard.svelte';
import ResultCard from './tool/ResultCard.svelte';
import SourceCard from './tool/SourceCard.svelte';
@@ -146,9 +147,8 @@
} else if (isSourceless) {
next = await tool.generate!(sanitized);
} else {
next = await tool.run!(source!, sanitized);
next = await executeStep(tool, source!, sanitized);
}
let nextPreview: PixelImage | null = null;
if (tool.preview && source) {
try {
@@ -173,7 +173,7 @@
continue;
}
try {
current = await stepTool.run(current, sanitizeParams(stepTool, step.values));
current = await executeStep(stepTool, current, sanitizeParams(stepTool, step.values));
} catch (e) {
const message = e instanceof Error ? e.message : String(e);
throw new Error(`Шаг ${i + 1} (${stepTool.title}): ${message}`);
+16
View File
@@ -0,0 +1,16 @@
import type { PixelImage } from '../core/types';
type MaybeRunnable = {
run?: (img: PixelImage, params: Record<string, unknown>) => Promise<PixelImage> | PixelImage;
};
export async function executeStep(
tool: MaybeRunnable,
img: PixelImage,
params: Record<string, unknown>
): Promise<PixelImage> {
if (!tool.run) {
throw new Error('Этот инструмент не обрабатывает изображения');
}
return await tool.run(img, params);
}