Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Load vision clients only when a vision request begins
wyt3adcc62ea336
diff --git a/src/main/features/library_image_describer.ts b/src/main/features/library_image_describer.tsindex 1c3460be..b7a4f674 100644--- a/src/main/features/library_image_describer.ts+++ b/src/main/features/library_image_describer.ts@@ -1,7 +1,6 @@import * as crypto from 'node:crypto';import { createLogger } from '../logger';-import { chatWithModel } from '../model/client';import { prompts } from '../prompts/loader';import {LIBRARY_IMAGE_TRANSFORM_OPTIONS,@@ -53,7 +52,9 @@ export async function describeLibraryImage(source_name_json: JSON.stringify(cleanName),});- const modelCall: Promise<VisionResult> = chatWithModel({+ // Index/catalog startup must not load the model runtime before an image+ // actually needs description. Include first-use loading in the deadline.+ const modelCall: Promise<VisionResult> = import('../model/client').then(({ chatWithModel }) => chatWithModel({userId,sessionId,message,@@ -64,7 +65,7 @@ export async function describeLibraryImage(requireImageInput: true,idleTimeout: Math.ceil(timeoutMs / 1000),abortSignal: controller.signal,- }).catch((err) => ({+ })).catch((err) => ({ok: false,text: '',error: (err as Error).message || String(err),diff --git a/src/main/features/video_vision.ts b/src/main/features/video_vision.tsindex 3658b5dd..ed12c431 100644--- a/src/main/features/video_vision.ts+++ b/src/main/features/video_vision.ts@@ -29,7 +29,7 @@import * as fs from 'node:fs/promises';-import { chatWithModel } from '../model/client';+import type { chatWithModel } from '../model/client';import { toCompressedJpeg } from '../util/image-transform';import { createLogger } from '../logger';import { logErrorSummary, logPathRef } from '../util/log-redact';@@ -172,7 +172,6 @@ export async function analyzeFrames(params: AnalyzeFramesParams): Promise<Analyzreturn { ok: false, reason: 'no-frames', message: 'all frames failed to load' };}- const chat = params.chat ?? chatWithModel;const controller = new AbortController();const abortFromCaller = () => controller.abort();if (params.signal) {@@ -188,8 +187,11 @@ export async function analyzeFrames(params: AnalyzeFramesParams): Promise<Analyz});try {- const call = Promise.resolve(- chat({+ // Loading the review surface or finding no readable frames must not load+ // the model runtime. First-use loading shares the call's timeout/error path.+ const call = Promise.resolve().then(async () => {+ const chat = params.chat ?? (await import('../model/client')).chatWithModel;+ return chat({userId: params.userId,message: buildVisionMessage(params.question, loaded.length),images: loaded,@@ -198,8 +200,8 @@ export async function analyzeFrames(params: AnalyzeFramesParams): Promise<AnalyzabortSignal: controller.signal,...(params.sessionId ? { sessionId: params.sessionId } : {}),...(params.agentId ? { agentId: params.agentId } : {}),- }),- ).catch((err) => ({ ok: false, text: '', error: (err as Error).message || String(err), aborted: false }));+ });+ }).catch((err) => ({ ok: false, text: '', error: (err as Error).message || String(err), aborted: false }));const res = await Promise.race([call, timeout]);diff --git a/test/main/features/vision-lazy-loading.test.ts b/test/main/features/vision-lazy-loading.test.tsnew file mode 100644index 00000000..ffaf67fd--- /dev/null+++ b/test/main/features/vision-lazy-loading.test.ts@@ -0,0 +1,29 @@+import { expect, it, vi } from 'vitest';++const runtime = vi.hoisted(() => ({ loads: 0, calls: vi.fn() }));+vi.mock('../../../src/main/model/client', () => {+ runtime.loads++;+ return { chatWithModel: runtime.calls };+});+vi.mock('../../../src/main/util/image-transform', () => ({+ LIBRARY_IMAGE_TRANSFORM_OPTIONS: {},+ toCompressedJpeg: async () => ({ buf: Buffer.from('jpeg') }),+}));+vi.mock('../../../src/main/prompts/loader', () => ({ prompts: { load: () => 'describe image' } }));++import { describeLibraryImage } from '../../../src/main/features/library_image_describer';+import { analyzeFrames } from '../../../src/main/features/video_vision';++it('keeps image/video surfaces usable without loading the model until real vision input arrives', async () => {+ expect(runtime.loads).toBe(0);+ expect(await analyzeFrames({ userId: 'u', framePaths: [], question: 'describe' }))+ .toMatchObject({ ok: false, reason: 'no-frames' });+ expect(runtime.loads).toBe(0);+ runtime.calls.mockResolvedValue({ ok: true, text: 'Visible image', error: '', aborted: false });+ expect(await describeLibraryImage('u', 'image.png', Buffer.from('image'))).toBe('Visible image');+ expect(await analyzeFrames({ userId: 'u', framePaths: ['frame.png'], question: 'describe',+ loadFrames: async () => [{ data: 'anBlZw==', mediaType: 'image/jpeg' }] }))+ .toMatchObject({ ok: true, text: 'Visible image', framesUsed: 1 });+ expect(runtime.loads).toBe(1);+ expect(runtime.calls).toHaveBeenCalledTimes(2);+});