The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
refactor(chat): workflow tools register lightly, the executors load on the first call (C60-S5)
purplec677d170d640
diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.tsindex fd6a071c..adff7f04 100644--- a/src/api/mcp/builtin-tools.ts+++ b/src/api/mcp/builtin-tools.ts@@ -9,7 +9,7 @@ import type { ToolRegistry } from './tool-registry'import { reserveCreateTools } from './create-tools'import { registerSettingsTools } from './settings-tools'import { registerSelfControlTools } from './self-control-tools'-import { registerWorkflowTools } from './workflow-tools'+import { registerWorkflowTools } from './workflow-defs'import { WORKFLOW_TOOL_NAMES } from '../../lib/workflow-tool-names'import { SETTINGS_TOOL_NAMES, SELF_CONTROL_ACTION_NAMES } from '../../lib/settings-tool-names'import { v4 as uuid } from 'uuid'diff --git a/src/api/mcp/workflow-defs.ts b/src/api/mcp/workflow-defs.tsnew file mode 100644index 00000000..3552cf21--- /dev/null+++ b/src/api/mcp/workflow-defs.ts@@ -0,0 +1,82 @@+// The workflow tools as the registry sees them (C60-S5): schemas and the+// registration. Nothing heavy is imported here: the registry loads this with+// the app, and the stores, ComfyUI and download code behind the tools would+// run their import-time code in every module that only registers tools (the+// same split as self-control-defs.ts). The executors load on the first call.++import type { MCPToolDefinition } from './types'+import type { ToolRegistry } from './tool-registry'+import { WORKFLOW_ASSIGN, WORKFLOW_FIND, WORKFLOW_INSPECT, WORKFLOW_INSTALL } from '../../lib/workflow-tool-names'++export const WORKFLOW_TOOLS: MCPToolDefinition[] = [+ {+ name: WORKFLOW_FIND,+ brief: 'Find ComfyUI workflows (local, CivitAI, GitHub).',+ description: 'Find ComfyUI workflows: LU\'s own, ComfyUI templates, CivitAI and GitHub repos of the Comfy Registry. '+ + 'Read only. Returns ids for workflow_inspect. Pass url only when the user sent a link.',+ inputSchema: {+ type: 'object',+ properties: {+ query: { type: 'string', description: 'What the workflow does, e.g. "flux upscale" or "wan 2.2 image to video".' },+ source: { type: 'string', enum: ['all', 'local', 'civitai', 'github'], description: 'Default all.' },+ url: { type: 'string', description: 'A workflow link the user wrote in their message (e.g. OpenArt, GitHub).' },+ },+ required: [],+ },+ category: 'system',+ source: 'builtin',+ },+ {+ name: WORKFLOW_INSPECT,+ brief: 'Traffic light check of a found workflow.',+ description: 'Check one found workflow: nodes, models, size, license, risks, traffic light green/yellow/red. Read only.',+ inputSchema: {+ type: 'object',+ properties: { id: { type: 'string', description: 'Id from workflow_find.' } },+ required: ['id'],+ },+ category: 'system',+ source: 'builtin',+ },+ {+ name: WORKFLOW_INSTALL,+ brief: "Install a checked workflow after the user's card.",+ description: 'Install a checked green or yellow workflow into LU (Create). The user confirms on a card. '+ + 'Optionally assign it to a model. Red is refused.',+ inputSchema: {+ type: 'object',+ properties: {+ id: { type: 'string', description: 'Id from workflow_find, checked with workflow_inspect.' },+ model: { type: 'string', description: 'Optional: image or video model file the workflow should be used for.' },+ },+ required: ['id'],+ },+ category: 'system',+ source: 'builtin',+ },+ {+ name: WORKFLOW_ASSIGN,+ brief: 'Use an installed workflow for a model.',+ description: 'Make an installed workflow the one a model generates with. The user confirms on a card.',+ inputSchema: {+ type: 'object',+ properties: {+ workflow: { type: 'string', description: 'Name or id of an installed workflow.' },+ model: { type: 'string', description: 'Model file name as ComfyUI lists it.' },+ },+ required: ['workflow', 'model'],+ },+ category: 'system',+ source: 'builtin',+ },+]+++const load = () => import('./workflow-tools')++export function registerWorkflowTools(registry: ToolRegistry): void {+ registry.registerBuiltin(WORKFLOW_TOOLS[0], async (a, run) => (await load()).executeWorkflowFind(a, run))+ registry.registerBuiltin(WORKFLOW_TOOLS[1], async (a) => (await load()).executeWorkflowInspect(a))+ registry.registerBuiltin(WORKFLOW_TOOLS[2], async (a, run, signal) => (await load()).executeWorkflowInstall(a, run, signal))+ registry.registerBuiltin(WORKFLOW_TOOLS[3], async (a, run, signal) => (await load()).executeWorkflowAssign(a, run, signal))+}diff --git a/src/api/mcp/workflow-mark.ts b/src/api/mcp/workflow-mark.tsnew file mode 100644index 00000000..3f04bf20--- /dev/null+++ b/src/api/mcp/workflow-mark.ts@@ -0,0 +1,26 @@+// The mark a workflow install or assignment leaves under its result (C60-S5),+// so the card can show what was done and undo the assignment, also after a+// restart. Pure: the chat UI and the tool registry import it without pulling+// the stores behind the tools.++export const WORKFLOW_MARK = /<!-- lu-workflow (\{.*\}) -->/++export interface WorkflowInstallMark {+ workflowId: string+ name: string+ model?: string+ /** The model's assignment before, to put back with Undo. */+ before?: string+}++export function parseWorkflowMark(result: string | null | undefined): WorkflowInstallMark | null {+ const m = typeof result === 'string' ? WORKFLOW_MARK.exec(result) : null+ if (!m) return null+ try {+ const v = JSON.parse(m[1]) as Partial<WorkflowInstallMark>+ return typeof v.workflowId === 'string' && typeof v.name === 'string' ? v as WorkflowInstallMark : null+ } catch {+ return null+ }+}+diff --git a/src/api/mcp/workflow-tools.ts b/src/api/mcp/workflow-tools.tsindex 907f4655..dd5cea23 100644--- a/src/api/mcp/workflow-tools.ts+++ b/src/api/mcp/workflow-tools.ts@@ -17,8 +17,7 @@// the strong card: only when the user's own last message asks for an install,// and not after the run read foreign content from somewhere else.import { v4 as uuid } from 'uuid'-import type { MCPToolDefinition, ToolArgs } from './types'-import type { ToolRegistry } from './tool-registry'+import type { ToolArgs } from './types'import type { AgentRunContext } from '../agent-context'import { backendCall } from '../backend'import { startModelDownload } from '../discover'@@ -33,7 +32,7 @@ import {} from '../workflow-find'import { cleanName, reportForAgent, type InspectReport } from '../../lib/workflow-inspect'import {- WORKFLOW_ASSIGN, WORKFLOW_FIND, WORKFLOW_INSPECT, WORKFLOW_INSTALL, userAskedToAssign, userAskedToInstall,+ userAskedToAssign, userAskedToInstall,} from '../../lib/workflow-tool-names'import { useChatStore } from '../../stores/chatStore'import { useModelStore } from '../../stores/modelStore'@@ -44,69 +43,6 @@ import { useWorkflowStore } from '../../stores/workflowStore'import { useWorkflowCardStore } from '../../stores/workflowInstallConfirmStore'import type { WorkflowTemplate } from '../../types/workflows'-export const WORKFLOW_TOOLS: MCPToolDefinition[] = [- {- name: WORKFLOW_FIND,- brief: 'Find ComfyUI workflows (local, CivitAI, GitHub).',- description: 'Find ComfyUI workflows: LU\'s own, ComfyUI templates, CivitAI and GitHub repos of the Comfy Registry. '- + 'Read only. Returns ids for workflow_inspect. Pass url only when the user sent a link.',- inputSchema: {- type: 'object',- properties: {- query: { type: 'string', description: 'What the workflow does, e.g. "flux upscale" or "wan 2.2 image to video".' },- source: { type: 'string', enum: ['all', 'local', 'civitai', 'github'], description: 'Default all.' },- url: { type: 'string', description: 'A workflow link the user wrote in their message (e.g. OpenArt, GitHub).' },- },- required: [],- },- category: 'system',- source: 'builtin',- },- {- name: WORKFLOW_INSPECT,- brief: 'Traffic light check of a found workflow.',- description: 'Check one found workflow: nodes, models, size, license, risks, traffic light green/yellow/red. Read only.',- inputSchema: {- type: 'object',- properties: { id: { type: 'string', description: 'Id from workflow_find.' } },- required: ['id'],- },- category: 'system',- source: 'builtin',- },- {- name: WORKFLOW_INSTALL,- brief: "Install a checked workflow after the user's card.",- description: 'Install a checked green or yellow workflow into LU (Create). The user confirms on a card. '- + 'Optionally assign it to a model. Red is refused.',- inputSchema: {- type: 'object',- properties: {- id: { type: 'string', description: 'Id from workflow_find, checked with workflow_inspect.' },- model: { type: 'string', description: 'Optional: image or video model file the workflow should be used for.' },- },- required: ['id'],- },- category: 'system',- source: 'builtin',- },- {- name: WORKFLOW_ASSIGN,- brief: 'Use an installed workflow for a model.',- description: 'Make an installed workflow the one a model generates with. The user confirms on a card.',- inputSchema: {- type: 'object',- properties: {- workflow: { type: 'string', description: 'Name or id of an installed workflow.' },- model: { type: 'string', description: 'Model file name as ComfyUI lists it.' },- },- required: ['workflow', 'model'],- },- category: 'system',- source: 'builtin',- },-]-// ── The run and the user ────────────────────────────────────────────────────/** What the user typed last in this conversation: the typed text of a slash@@ -208,26 +144,8 @@ export async function executeWorkflowInspect(args: ToolArgs): Promise<string> {// ── workflow_install ────────────────────────────────────────────────────────-const MARK = /<!-- lu-workflow (\{.*\}) -->/--export interface WorkflowInstallMark {- workflowId: string- name: string- model?: string- /** The model's assignment before, to put back with Undo. */- before?: string-}--export function parseWorkflowMark(result: string | null | undefined): WorkflowInstallMark | null {- const m = typeof result === 'string' ? MARK.exec(result) : null- if (!m) return null- try {- const v = JSON.parse(m[1]) as Partial<WorkflowInstallMark>- return typeof v.workflowId === 'string' && typeof v.name === 'string' ? v as WorkflowInstallMark : null- } catch {- return null- }-}+import { parseWorkflowMark, type WorkflowInstallMark } from './workflow-mark'+export { parseWorkflowMark, type WorkflowInstallMark }async function installedModelNames(): Promise<string[] | null> {try {@@ -477,11 +395,4 @@ export function assignmentState(mark: WorkflowInstallMark): 'applied' | 'undone'return 'moved'}-export function registerWorkflowTools(registry: ToolRegistry): void {- registry.registerBuiltin(WORKFLOW_TOOLS[0], (a, run) => executeWorkflowFind(a, run))- registry.registerBuiltin(WORKFLOW_TOOLS[1], (a) => executeWorkflowInspect(a))- registry.registerBuiltin(WORKFLOW_TOOLS[2], (a, run, signal) => executeWorkflowInstall(a, run, signal))- registry.registerBuiltin(WORKFLOW_TOOLS[3], (a, run, signal) => executeWorkflowAssign(a, run, signal))-}-export { checkedById }diff --git a/src/components/chat/ToolCallBlock.tsx b/src/components/chat/ToolCallBlock.tsxindex 14536ab5..c39d46eb 100644--- a/src/components/chat/ToolCallBlock.tsx+++ b/src/components/chat/ToolCallBlock.tsx@@ -19,7 +19,7 @@ import { parseSettingChanges } from '../../api/mcp/settings-tools'import { parseSelfControlAction } from '../../api/mcp/self-control-tools'import { WorkflowCardAsk, WorkflowCardDone } from './WorkflowInstallCard'import { useWorkflowCardStore, workflowCardForCall } from '../../stores/workflowInstallConfirmStore'-import { parseWorkflowMark } from '../../api/mcp/workflow-tools'+import { parseWorkflowMark } from '../../api/mcp/workflow-mark'import { isSelfControlToolName } from '../../lib/settings-tool-names'import { useChatStore } from '../../stores/chatStore'import { commandIcon } from '../../lib/shell-command-classify'