Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit f986bb1

Browse files
author
SIN-Agent
committed
P1: Vision-LLM fallback + P2: vitest coverage gate
1 parent 9892ace commit f986bb1

3 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/commands/vision-fallback.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { createAI } from 'ai';
2+
import { openai } from '@ai-sdk/openai';
3+
4+
export interface VisionDecision {
5+
action: 'click' | 'type' | 'scroll' | 'drag' | 'wait' | 'done';
6+
elementIndex?: number;
7+
text?: string;
8+
confidence: number;
9+
reasoning: string;
10+
}
11+
12+
export async function visionFallback(
13+
screenshotPath: string,
14+
instruction: string,
15+
apiKey: string
16+
): Promise<VisionDecision> {
17+
const fs = await import('fs');
18+
const imgB64 = fs.readFileSync(screenshotPath).toString('base64');
19+
const { text } = await createAI({ model: openai('gpt-4o') }).generateText({
20+
messages: [{
21+
role: 'user',
22+
content: [
23+
{ type: 'text', text: `GUI agent. ${instruction}\nJSON: {"action":"...","elementIndex":int|null,"confidence":float,"reasoning":"..."}` },
24+
{ type: 'image', image: imgB64 }
25+
]
26+
}],
27+
maxTokens: 200
28+
});
29+
return JSON.parse(text);
30+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ export { microJitter, humanPause, jitterMs, sleep, randomInt } from './utils/jit
7272
export { preScan } from './commands/pre-scan.js';
7373
export type { PreScanResult, PreScanElement } from './commands/pre-scan.js';
7474
export { ScreenshotTimeline } from "./commands/screenshot-timeline.js";
75+
export { visionFallback } from "./commands/vision-fallback.js";
76+
export type { VisionDecision } from "./commands/vision-fallback.js";

vitest.config.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
11
import { defineConfig } from 'vitest/config';
2-
3-
export default defineConfig({
4-
test: {
5-
globals: false,
6-
environment: 'node',
7-
include: ['tests/**/*.test.ts'],
8-
coverage: {
9-
reporter: ['text', 'html', 'json'],
10-
include: ['src/**/*.ts'],
11-
exclude: ['src/cli.ts', 'src/**/*.d.ts'],
12-
},
13-
testTimeout: 30_000,
14-
},
15-
});
2+
export default defineConfig({ test: { coverage: { provider: 'v8', reporter: ['text', 'json'], thresholds: { statements: 75, branches: 70, functions: 75, lines: 75 } } } });

0 commit comments

Comments
 (0)