1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
/**
* Vision handoff service — the imperative shell that performs the universal,
* provider-agnostic vision handoff.
*
* Two capabilities:
* 1. **prepareForProvider** (`prepareForProvider`): when a user message carries
* images but the active model cannot see them, this replaces each image chunk
* with a numbered placeholder (telling the model to call `consult_vision`)
* and registers the image data in a per-conversation registry for tool
* access. Vision-capable models pass through unchanged (images flow natively).
* 2. **consult_vision tool** (`consultVision`): opens a NEW conversation tab with
* a vision-capable model (resolved from the catalog — any provider), attaches
* the image(s) + the model's specific question, waits for the response, and
* returns the conversation ID + the vision model's answer. The model (e.g.
* GLM 5.2) directs the analysis — asking exactly what it needs — instead of
* receiving a pre-emptive generic dump. Follow-up questions go through the
* dispatch CLI (the conversation ID is the bridge), not another tool call.
*
* Effects (credential store, orchestrator, filesystem) are injected. The pure
* decisions live in `pure.ts`. This shell wires them.
*/
import type { CredentialStore } from "@dispatch/credential-store";
import type {
AgentEvent,
ChatMessage,
Chunk,
ImageInput,
Logger,
ModelInfo,
ProviderContract,
} from "@dispatch/kernel";
import { defineService, type ServiceHandle } from "@dispatch/kernel";
import {
collectTextFromStream,
findVisionModelName,
formatConsultationTitle,
formatConsultResult,
formatImagePlaceholder,
formatNoVisionPlaceholder,
isVisionCapable,
} from "./pure.js";
/**
* Minimal orchestrator interface the service needs to start vision consultation
* turns. Defined locally (not imported from session-orchestrator) to avoid a
* compile-time dependency — resolved lazily at runtime via a local handle keyed
* to the same service ID.
*/
export interface OrchestratorForVision {
readonly handleMessage: (input: {
readonly conversationId: string;
readonly text: string;
readonly onEvent: (event: AgentEvent) => void;
readonly modelName?: string;
readonly cwd?: string;
readonly images?: readonly ImageInput[];
readonly systemPrompt?: string;
}) => Promise<void>;
}
/** Local handle for the session-orchestrator service (same ID, no import dep). */
export const orchestratorLocalHandle: ServiceHandle<OrchestratorForVision> =
defineService<OrchestratorForVision>("session-orchestrator/orchestrator");
/**
* Resolved vision model — a provider + its model id, ready to stream from.
*/
export interface ResolvedVisionModel {
readonly provider: ProviderContract;
readonly model: string;
readonly modelName: string;
}
/** A registered image (looked up by the consult_vision tool via imageId). */
interface RegisteredImage {
readonly url: string;
readonly mimeType?: string;
}
/**
* Dependencies the service needs — all injected (no ambient state).
*/
export interface VisionHandoffDeps {
readonly credentialStore: CredentialStore;
/** Resolve a `<credentialName>/<model>` → its provider + model id. */
readonly resolveModel: (
modelName: string,
) => { provider: ProviderContract; model: string } | undefined;
/**
* Read a file from disk as a base64 data URL. Injected so the shell controls
* the filesystem edge. Returns the data URL, or throws on error.
*/
readonly readFileAsDataUrl: (path: string, cwd?: string) => Promise<string>;
/**
* Lazily resolve the session-orchestrator (for starting vision consultation
* turns). Returns `undefined` when not available — `consult_vision` degrades
* with an error. Lazy so activation order doesn't matter.
*/
readonly resolveOrchestrator?: () => OrchestratorForVision | undefined;
/**
* Get the per-conversation cached image transcriptions (imageUrl → text).
* Used to avoid re-transcribing old images that were compacted to text on a
* previous turn. Optional — when absent, compaction still works but
* re-transcribes every turn (no caching).
*/
readonly getImageTranscriptions?: (
conversationId: string,
) => Promise<ReadonlyMap<string, string>>;
/**
* Upsert a single image transcription into the per-conversation cache.
* Optional — paired with getImageTranscriptions.
*/
readonly setImageTranscription?: (
conversationId: string,
imageUrl: string,
transcription: string,
) => Promise<void>;
/**
* Save an image data URL to a tmp file and return a compact URL
* (`/images/<conversationId>/<imageId>.<ext>`) that can be persisted in the
* conversation store instead of the full data URL (which would be megabytes).
* The frontend serves the image via `GET /images/...`; the provider resolves
* it back to a data URL via {@link resolveImageUrl} at runtime. When `undefined`,
* data URLs pass through unchanged (images persist in SQLite — the large-DB
* path, for environments without tmp file support).
*/
readonly saveImageToTmp?: (
conversationId: string,
dataUrl: string,
mimeType?: string,
) => Promise<string>;
/**
* Resolve a compact URL (`/images/...`) back to a data URL by reading the tmp
* file. Data URLs and HTTP URLs pass through unchanged. Paired with
* {@link saveImageToTmp}.
*/
readonly resolveImageUrl?: (url: string) => Promise<string>;
/**
* Delete a tmp image file (after it has been compacted to text — the
* transcription is cached, the raw image is no longer needed). Best-effort:
* errors are logged, not thrown.
*/
readonly deleteTmpImage?: (compactUrl: string) => Promise<void>;
/**
* Delete all tmp images for a conversation (on conversation close).
* Best-effort.
*/
readonly deleteConversationImages?: (conversationId: string) => Promise<void>;
/**
* Set the human-readable title of a conversation. Used to label vision
* consultation tabs with an `"IMAGE - "` prefix so they're visually
* distinguishable from normal conversation tabs. Backed by the conversation
* store's `setConversationTitle`. Optional — when absent, consultation tabs
* keep their default (question-derived) title.
*/
readonly setConversationTitle?: (conversationId: string, title: string) => Promise<void>;
/** Generate a new conversation ID for a consultation. Defaults to crypto.randomUUID. */
readonly generateId?: () => string;
readonly logger?: Logger;
}
export interface VisionHandoffService {
/**
* Whether a given model (by catalog name) is vision-capable. Uses the
* credential store's ModelInfo + the name heuristic.
*/
readonly isVisionCapable: (modelName: string | undefined) => Promise<boolean>;
/**
* Store images to tmp files and return compact URLs. Each input image's data
* URL is saved to `/tmp/dispatch/images/<conversationId>/<uuid>.<ext>` and
* replaced with a compact HTTP path (`/images/<conversationId>/<uuid>.<ext>`)
* so the persisted conversation store holds a tiny string, not megabytes of
* base64. When `saveImageToTmp` is not configured, data URLs pass through
* unchanged (backward compatible).
*/
readonly storeImages: (
conversationId: string,
images: readonly ImageInput[],
) => Promise<readonly ImageInput[]>;
/**
* Delete all tmp images for a conversation (on close). Best-effort.
*/
readonly purgeConversationImages: (conversationId: string) => Promise<void>;
/**
* Resolve a vision-capable model from the catalog (any provider). Returns
* `undefined` when none is available.
*/
readonly resolveVisionModel: (excludeName?: string) => Promise<ResolvedVisionModel | undefined>;
/**
* Transform a message list for the provider: if the active model is
* vision-capable, return messages unchanged (images pass through natively).
* If NOT vision-capable, replace every `image` chunk with a numbered
* placeholder (telling the model to call `consult_vision`) and register the
* image data in the per-conversation registry for tool access. The PERSISTED
* history is NOT modified — only what the provider sees. Never throws.
*/
readonly prepareForProvider: (
messages: readonly ChatMessage[],
currentModelName: string | undefined,
opts?: {
readonly conversationId?: string;
readonly imageLimit?: number;
readonly signal?: AbortSignal;
readonly logger?: Logger;
},
) => Promise<readonly ChatMessage[]>;
/**
* Look up a registered image by conversation ID + image ID. Returns
* `undefined` when the image isn't registered (e.g. after a server restart).
*/
readonly getRegisteredImage: (
conversationId: string,
imageId: number,
) => RegisteredImage | undefined;
/**
* Open a NEW vision consultation conversation: attach image(s) + the model's
* question to a vision-capable model, wait for the response, and return the
* conversation ID + the vision model's answer. The model drives the analysis
* — it asks exactly what it needs. Follow-ups go through the dispatch CLI.
*
* @returns The conversation ID + the vision model's response text, or an
* error string (never throws — the tool surfaces it).
*/
readonly consultVision: (
question: string,
opts: {
readonly conversationId: string;
readonly imageIds?: readonly number[];
readonly path?: string;
readonly cwd?: string;
readonly signal?: AbortSignal;
readonly logger?: Logger;
},
) => Promise<
{ readonly conversationId: string; readonly response: string } | { readonly error: string }
>;
}
export const visionHandoffHandle: ServiceHandle<VisionHandoffService> =
defineService<VisionHandoffService>("vision-handoff/service");
/** Whether a message list contains any image chunks. Pure. */
function hasImageChunks(messages: readonly ChatMessage[]): boolean {
return messages.some((m) => m.chunks.some((c) => c.type === "image"));
}
export function createVisionHandoffService(deps: VisionHandoffDeps): VisionHandoffService {
const log = deps.logger;
const generateId = deps.generateId ?? (() => crypto.randomUUID());
// Per-conversation image registry: conversationId → (imageId → image data).
// Populated by prepareForProvider; consulted by the consult_vision tool.
// In-memory only (cleared on restart — the user re-pastes if needed).
const imageRegistry = new Map<string, Map<number, RegisteredImage>>();
async function getInfo(modelName: string): Promise<ModelInfo | undefined> {
return deps.credentialStore.getModelInfo(modelName);
}
async function resolveVisionModel(
excludeName?: string,
): Promise<ResolvedVisionModel | undefined> {
const catalog = await deps.credentialStore.listCatalog();
const name = await findVisionModelName(catalog, getInfo, excludeName);
if (name === undefined) return undefined;
const resolved = deps.resolveModel(name);
if (resolved === undefined) return undefined;
return { provider: resolved.provider, model: resolved.model, modelName: name };
}
/**
* Compact images for a vision-capable model: when the conversation has more
* image chunks than the limit, the oldest images are transcribed to text
* (one-time, cached in the conversation store) and stripped from the
* provider messages. Recent images (within the limit) stay native.
*
* The persisted history is NOT modified — only the provider's view.
* Transcriptions are cached so they're reused on subsequent turns (no
* re-transcription). When no caching deps are available, it still works but
* re-transcribes every turn.
*/
async function compactImagesForVisionModel(
messages: readonly ChatMessage[],
opts:
| {
readonly conversationId?: string;
readonly imageLimit?: number;
readonly signal?: AbortSignal;
readonly logger?: Logger;
}
| undefined,
currentModelName: string | undefined,
): Promise<readonly ChatMessage[]> {
void currentModelName; // reserved for future model-specific compaction logic
const limit = opts?.imageLimit;
// No limit or limit <= 0 → pass all images through (compaction disabled).
if (limit === undefined || limit <= 0) return messages;
// Collect all image chunks in order (oldest first, across all messages).
const imageEntries: { msgIdx: number; chunkIdx: number; url: string }[] = [];
for (const [mi, msg] of messages.entries()) {
for (const [ci, chunk] of msg.chunks.entries()) {
if (chunk.type === "image") {
imageEntries.push({ msgIdx: mi, chunkIdx: ci, url: chunk.url });
}
}
}
// If within the limit, pass everything through natively.
if (imageEntries.length <= limit) return messages;
// The oldest (imageEntries.length - limit) images need transcription.
const toTranscribeCount = imageEntries.length - limit;
const toTranscribe = imageEntries.slice(0, toTranscribeCount);
// Load cached transcriptions.
const convId = opts?.conversationId;
const cache =
convId !== undefined && deps.getImageTranscriptions !== undefined
? await deps.getImageTranscriptions(convId)
: new Map<string, string>();
// Transcribe any that aren't cached yet (via the vision model).
const transcriptions = new Map<string, string>(cache);
const vision = await resolveVisionModel();
for (const entry of toTranscribe) {
if (transcriptions.has(entry.url)) continue;
if (vision === undefined) {
// No vision model available for transcription — use a placeholder.
transcriptions.set(
entry.url,
"[Image was compacted — no vision model available to transcribe it.]",
);
continue;
}
try {
const prompt =
"Describe this image in detail. Include visible text (transcribe verbatim), " +
"key objects, layout, and notable details. This description will replace " +
"the image in a conversation history, so be thorough.";
const userMessage: ChatMessage = {
role: "user",
chunks: [
{ type: "text", text: prompt },
{ type: "image", url: entry.url },
],
};
const stream = vision.provider.stream([userMessage], [], {
model: vision.model,
systemPrompt:
"You are a vision assistant. Describe images faithfully and thoroughly. " +
"Do not use any tools — just use your vision to see the image and describe it directly.",
});
const description = (await collectTextFromStream(stream)).trim();
const text =
description.length > 0 ? description : "[Image transcription produced no output.]";
transcriptions.set(entry.url, text);
// Cache it in the conversation store (if available).
if (convId !== undefined && deps.setImageTranscription !== undefined) {
await deps.setImageTranscription(convId, entry.url, text);
}
// The image has been transcribed to text — delete the tmp file
// (the transcription is cached, the raw image is no longer needed).
if (deps.deleteTmpImage !== undefined) {
try {
await deps.deleteTmpImage(entry.url);
} catch {
// Best-effort — don't let cleanup failure break the turn.
}
}
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
log?.warn("vision-handoff: image compaction transcription failed", { error: msg });
transcriptions.set(entry.url, `[Image transcription failed: ${msg}]`);
}
}
// Build the provider messages: replace transcribed images with text,
// keep recent images (within the limit) native.
const transcribedUrls = new Set(toTranscribe.map((e) => e.url));
const result: ChatMessage[] = [];
for (const msg of messages) {
if (!msg.chunks.some((c) => c.type === "image")) {
result.push(msg);
continue;
}
const newChunks: Chunk[] = [];
for (const chunk of msg.chunks) {
if (chunk.type === "image" && transcribedUrls.has(chunk.url)) {
const transcription = transcriptions.get(chunk.url);
if (transcription !== undefined) {
newChunks.push({ type: "text", text: `[Compacted image]: ${transcription}` });
} else {
newChunks.push(chunk); // fallback: keep the image
}
} else {
newChunks.push(chunk);
}
}
result.push({ role: msg.role, chunks: newChunks });
}
return result;
}
async function resolveImageUrlsInMessages(
messages: readonly ChatMessage[],
): Promise<readonly ChatMessage[]> {
if (deps.resolveImageUrl === undefined) return messages;
let hasCompact = false;
for (const msg of messages) {
if (msg.chunks.some((c) => c.type === "image")) {
hasCompact = true;
break;
}
}
if (!hasCompact) return messages;
const result: ChatMessage[] = [];
for (const msg of messages) {
if (!msg.chunks.some((c) => c.type === "image")) {
result.push(msg);
continue;
}
const newChunks: Chunk[] = [];
for (const chunk of msg.chunks) {
if (chunk.type === "image") {
const dataUrl = await deps.resolveImageUrl!(chunk.url);
newChunks.push({
type: "image",
url: dataUrl,
...(chunk.mimeType !== undefined ? { mimeType: chunk.mimeType } : {}),
});
} else {
newChunks.push(chunk);
}
}
result.push({ role: msg.role, chunks: newChunks });
}
return result;
}
const service: VisionHandoffService = {
async isVisionCapable(modelName: string | undefined): Promise<boolean> {
if (modelName === undefined) return false;
const info = await getInfo(modelName);
return isVisionCapable(modelName, info);
},
async storeImages(
conversationId: string,
images: readonly ImageInput[],
): Promise<readonly ImageInput[]> {
if (deps.saveImageToTmp === undefined) return images;
const result: ImageInput[] = [];
for (const img of images) {
if (img.url.startsWith("data:")) {
const compactUrl = await deps.saveImageToTmp(conversationId, img.url, img.mimeType);
result.push({
url: compactUrl,
...(img.mimeType !== undefined ? { mimeType: img.mimeType } : {}),
});
} else {
result.push(img);
}
}
return result;
},
async purgeConversationImages(conversationId: string): Promise<void> {
if (deps.deleteConversationImages === undefined) return;
try {
await deps.deleteConversationImages(conversationId);
} catch (err) {
log?.warn("vision-handoff: failed to purge conversation images", {
conversationId,
error: err instanceof Error ? err.message : String(err),
});
}
},
resolveVisionModel,
async prepareForProvider(
messages: readonly ChatMessage[],
currentModelName: string | undefined,
opts?: {
readonly conversationId?: string;
readonly imageLimit?: number;
readonly signal?: AbortSignal;
readonly logger?: Logger;
},
): Promise<readonly ChatMessage[]> {
// Fast path: no images anywhere → nothing to do.
if (!hasImageChunks(messages)) return messages;
// Resolve compact URLs (/images/...) → data URLs for the provider.
// The persisted chunks store compact URLs (tiny strings); the provider
// needs data URLs (read from tmp files at runtime).
const resolved = await resolveImageUrlsInMessages(messages);
const isCapable =
currentModelName !== undefined &&
(await isVisionCapable(currentModelName, await getInfo(currentModelName)));
// ── Vision-capable model: image compaction ──────────────────────────
// When the conversation has more images than the limit, the oldest images
// are transcribed to text (one-time, cached) and stripped from the
// provider messages. Recent images (within the limit) stay native.
if (isCapable) {
return compactImagesForVisionModel(resolved, opts, currentModelName);
}
// ── Non-vision model: placeholders + consult_vision ──────────────────
const vision = await resolveVisionModel();
const convId = opts?.conversationId;
const placeholderFn =
vision !== undefined && convId !== undefined
? (id: number) => formatImagePlaceholder(id)
: () => formatNoVisionPlaceholder();
// Replace each image chunk with a numbered placeholder. Assign sequential
// 1-based IDs across all messages and register each image in the
// per-conversation registry so the consult_vision tool can look it up.
let seqId = 0;
const result: ChatMessage[] = [];
for (const msg of resolved) {
if (!msg.chunks.some((c) => c.type === "image")) {
result.push(msg);
continue;
}
const newChunks: Chunk[] = [];
for (const chunk of msg.chunks) {
if (chunk.type === "image") {
seqId++;
if (convId !== undefined && vision !== undefined) {
let convImages = imageRegistry.get(convId);
if (convImages === undefined) {
convImages = new Map();
imageRegistry.set(convId, convImages);
}
convImages.set(seqId, {
url: chunk.url,
...(chunk.mimeType !== undefined ? { mimeType: chunk.mimeType } : {}),
});
}
newChunks.push({ type: "text", text: placeholderFn(seqId) });
} else {
newChunks.push(chunk);
}
}
result.push({ role: msg.role, chunks: newChunks });
}
return result;
},
getRegisteredImage(conversationId: string, imageId: number): RegisteredImage | undefined {
return imageRegistry.get(conversationId)?.get(imageId);
},
async consultVision(
question: string,
opts: {
readonly conversationId: string;
readonly imageIds?: readonly number[];
readonly path?: string;
readonly cwd?: string;
readonly signal?: AbortSignal;
readonly logger?: Logger;
},
): Promise<
{ readonly conversationId: string; readonly response: string } | { readonly error: string }
> {
const orchestrator = deps.resolveOrchestrator?.();
if (orchestrator === undefined) {
return {
error: "The session orchestrator is not available — cannot start a vision consultation.",
};
}
const vision = await resolveVisionModel();
if (vision === undefined) {
return {
error:
"No vision-capable model is available in the catalog. Install or configure one (e.g. kimi) to enable image analysis.",
};
}
// Collect image data URLs to attach.
const images: ImageInput[] = [];
if (opts.imageIds !== undefined) {
for (const id of opts.imageIds) {
const img = service.getRegisteredImage(opts.conversationId, id);
if (img === undefined) {
return {
error: `Image ${id} is not registered. It may have been lost after a server restart — ask the user to re-paste the image.`,
};
}
images.push({
url: img.url,
...(img.mimeType !== undefined ? { mimeType: img.mimeType } : {}),
});
}
}
if (opts.path !== undefined) {
try {
const dataUrl = await deps.readFileAsDataUrl(opts.path, opts.cwd);
images.push({ url: dataUrl });
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
return { error: `Failed to read image file "${opts.path}": ${msg}` };
}
}
if (images.length === 0) {
return {
error:
"No image to consult about. Provide imageIds (for pasted images) or path (for a file).",
};
}
// Start a NEW conversation with the vision model.
const consultationId = generateId();
log?.info("vision-handoff: starting consultation", {
consultationId,
visionModel: vision.modelName,
imageCount: images.length,
fromConversation: opts.conversationId,
});
// Label the consultation tab with an "IMAGE - " prefix so it's visually
// distinguishable from normal conversation tabs. Set BEFORE the turn
// starts so the tab shows the correct title from the first moment (the
// store keeps a non-"Untitled" title on first message append).
if (deps.setConversationTitle !== undefined) {
try {
await deps.setConversationTitle(consultationId, formatConsultationTitle(question));
} catch (err) {
// Best-effort — don't let a title-write failure break the consultation.
log?.warn("vision-handoff: failed to set consultation title", {
consultationId,
error: err instanceof Error ? err.message : String(err),
});
}
}
let responseText = "";
let errorMessage = "";
try {
await orchestrator.handleMessage({
conversationId: consultationId,
text: question,
images,
modelName: vision.modelName,
...(opts.cwd !== undefined ? { cwd: opts.cwd } : {}),
systemPrompt:
"You are a vision assistant. A developer who cannot see images is asking you specific " +
"questions about an image they attached. Answer their question precisely and thoroughly. " +
"Do not use any tools unless specifically asked to — just use your vision to see the " +
"image and describe it directly.",
onEvent: (event: AgentEvent) => {
if (event.type === "text-delta") {
responseText += event.delta;
} else if (event.type === "error") {
errorMessage = event.message;
}
},
});
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
return { error: `Vision consultation failed: ${msg}` };
}
if (errorMessage.length > 0 && responseText.trim().length === 0) {
return { error: `Vision consultation failed: ${errorMessage}` };
}
const response = formatConsultResult(consultationId, responseText);
return { conversationId: consultationId, response };
},
};
return service;
}
|