ft-scout 9.5.4 → 9.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/src/commands/agent.d.ts +5 -0
- package/bin/src/commands/agent.js +45 -3
- package/bin/src/commands/support.d.ts +9 -0
- package/bin/src/commands/support.js +227 -0
- package/bin/src/engine/agent/computerUseLoop.d.ts +107 -0
- package/bin/src/engine/agent/computerUseLoop.js +413 -0
- package/bin/src/engine/agent/index.d.ts +2 -0
- package/bin/src/engine/agent/index.js +2 -0
- package/bin/src/engine/agent/recovery/index.d.ts +4 -0
- package/bin/src/engine/agent/recovery/index.js +4 -0
- package/bin/src/engine/agent/recovery/loopDetector.d.ts +26 -0
- package/bin/src/engine/agent/recovery/loopDetector.js +126 -0
- package/bin/src/engine/agent/recovery/recoveryManager.d.ts +43 -0
- package/bin/src/engine/agent/recovery/recoveryManager.js +271 -0
- package/bin/src/engine/agent/recovery/types.d.ts +48 -0
- package/bin/src/engine/agent/recovery/types.js +4 -0
- package/bin/src/engine/agent/verification/index.d.ts +3 -0
- package/bin/src/engine/agent/verification/index.js +3 -0
- package/bin/src/engine/agent/verification/stateChangeVerifier.d.ts +22 -0
- package/bin/src/engine/agent/verification/stateChangeVerifier.js +282 -0
- package/bin/src/engine/agent/verification/types.d.ts +28 -0
- package/bin/src/engine/agent/verification/types.js +4 -0
- package/bin/src/engine/agentEngine.d.ts +2 -1
- package/bin/src/engine/agentEngine.js +98 -7
- package/bin/src/engine/agentState.d.ts +41 -1
- package/bin/src/engine/agentState.js +45 -0
- package/bin/src/engine/browser/actions/actionEngine.d.ts +41 -0
- package/bin/src/engine/browser/actions/actionEngine.js +707 -0
- package/bin/src/engine/browser/actions/index.d.ts +4 -0
- package/bin/src/engine/browser/actions/index.js +4 -0
- package/bin/src/engine/browser/actions/reliability.d.ts +41 -0
- package/bin/src/engine/browser/actions/reliability.js +170 -0
- package/bin/src/engine/browser/actions/types.d.ts +50 -0
- package/bin/src/engine/browser/actions/types.js +2 -0
- package/bin/src/engine/browser/browserController.d.ts +18 -0
- package/bin/src/engine/browser/browserController.js +44 -12
- package/bin/src/engine/browser/index.d.ts +2 -0
- package/bin/src/engine/browser/index.js +2 -0
- package/bin/src/engine/browser/observer/accessibilityTree.d.ts +14 -0
- package/bin/src/engine/browser/observer/accessibilityTree.js +214 -0
- package/bin/src/engine/browser/observer/browserObserver.d.ts +29 -0
- package/bin/src/engine/browser/observer/browserObserver.js +204 -0
- package/bin/src/engine/browser/observer/domExtractor.d.ts +30 -0
- package/bin/src/engine/browser/observer/domExtractor.js +407 -0
- package/bin/src/engine/browser/observer/index.d.ts +5 -0
- package/bin/src/engine/browser/observer/index.js +5 -0
- package/bin/src/engine/browser/observer/types.d.ts +163 -0
- package/bin/src/engine/browser/observer/types.js +8 -0
- package/bin/src/engine/computer/computerController.d.ts +49 -0
- package/bin/src/engine/computer/computerController.js +249 -104
- package/bin/src/engine/computer/mockComputer.d.ts +6 -1
- package/bin/src/engine/computer/mockComputer.js +58 -0
- package/bin/src/engine/computer/scoutDriver.cs +84 -2
- package/bin/src/engine/llm.js +16 -0
- package/bin/src/engine/models/harpProvider.d.ts +32 -0
- package/bin/src/engine/models/harpProvider.js +124 -0
- package/bin/src/engine/models/index.d.ts +6 -0
- package/bin/src/engine/models/index.js +6 -0
- package/bin/src/engine/models/localModelProvider.d.ts +11 -0
- package/bin/src/engine/models/localModelProvider.js +48 -0
- package/bin/src/engine/models/openaiProvider.d.ts +11 -0
- package/bin/src/engine/models/openaiProvider.js +50 -0
- package/bin/src/engine/models/reasoningOrchestrator.d.ts +17 -0
- package/bin/src/engine/models/reasoningOrchestrator.js +75 -0
- package/bin/src/engine/models/types.d.ts +63 -0
- package/bin/src/engine/models/types.js +2 -0
- package/bin/src/engine/planner.js +64 -34
- package/bin/src/engine/production/index.d.ts +3 -0
- package/bin/src/engine/production/index.js +3 -0
- package/bin/src/engine/production/taskReplay.d.ts +37 -0
- package/bin/src/engine/production/taskReplay.js +81 -0
- package/bin/src/engine/production/telemetry.d.ts +43 -0
- package/bin/src/engine/production/telemetry.js +68 -0
- package/bin/src/engine/runtime/agentRuntime.d.ts +1 -1
- package/bin/src/engine/runtime/agentRuntime.js +99 -0
- package/bin/src/engine/safety/index.d.ts +3 -0
- package/bin/src/engine/safety/index.js +3 -0
- package/bin/src/engine/safety/policyEngine.d.ts +40 -0
- package/bin/src/engine/safety/policyEngine.js +282 -0
- package/bin/src/engine/safety/types.d.ts +24 -0
- package/bin/src/engine/safety/types.js +2 -0
- package/bin/src/engine/safety.d.ts +1 -0
- package/bin/src/engine/safety.js +1 -0
- package/bin/src/engine/subagents/subagentManager.js +2 -2
- package/bin/src/engine/toolRegistry.d.ts +4 -0
- package/bin/src/engine/toolRegistry.js +9 -0
- package/bin/src/engine/tools/domainHandlers.d.ts +61 -0
- package/bin/src/engine/tools/domainHandlers.js +458 -0
- package/bin/src/engine/tools/index.d.ts +4 -0
- package/bin/src/engine/tools/index.js +4 -0
- package/bin/src/engine/tools/types.d.ts +56 -0
- package/bin/src/engine/tools/types.js +2 -0
- package/bin/src/engine/tools/unifiedRouter.d.ts +29 -0
- package/bin/src/engine/tools/unifiedRouter.js +426 -0
- package/bin/src/index.js +26 -6
- package/bin/src/mcp/client.js +1 -1
- package/bin/src/server/server.js +136 -0
- package/bin/src/utils/branding.js +1 -1
- package/bin/src/utils/qrBridge.js +1 -1
- package/bin/src/utils/session.d.ts +5 -1
- package/bin/src/utils/session.js +36 -3
- package/bin/src/utils/support.d.ts +63 -0
- package/bin/src/utils/support.js +182 -0
- package/package.json +2 -2
|
@@ -559,9 +559,91 @@ namespace Scout.ComputerControl
|
|
|
559
559
|
{
|
|
560
560
|
string targetApp = appName.Trim();
|
|
561
561
|
string targetArgs = appArgs ?? "";
|
|
562
|
+
string lowerApp = targetApp.ToLowerInvariant();
|
|
562
563
|
|
|
563
|
-
|
|
564
|
-
|
|
564
|
+
if (lowerApp == "calc" || lowerApp == "calculator" || lowerApp == "wincalc")
|
|
565
|
+
{
|
|
566
|
+
targetApp = "calc.exe";
|
|
567
|
+
}
|
|
568
|
+
else if (lowerApp == "vscode" || lowerApp == "vs code" || lowerApp == "code" || lowerApp == "visual studio code")
|
|
569
|
+
{
|
|
570
|
+
targetApp = "code";
|
|
571
|
+
}
|
|
572
|
+
else if (lowerApp == "notepad" || lowerApp == "text editor" || lowerApp == "editor")
|
|
573
|
+
{
|
|
574
|
+
targetApp = "notepad.exe";
|
|
575
|
+
}
|
|
576
|
+
else if (lowerApp == "chrome" || lowerApp == "google chrome" || lowerApp == "google-chrome")
|
|
577
|
+
{
|
|
578
|
+
string localApp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
579
|
+
string[] chromeCandidates = new string[]
|
|
580
|
+
{
|
|
581
|
+
@"C:\Program Files\Google\Chrome\Application\chrome.exe",
|
|
582
|
+
@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
|
|
583
|
+
Path.Combine(localApp, @"Google\Chrome\Application\chrome.exe")
|
|
584
|
+
};
|
|
585
|
+
foreach (string cPath in chromeCandidates)
|
|
586
|
+
{
|
|
587
|
+
if (File.Exists(cPath)) { targetApp = cPath; break; }
|
|
588
|
+
}
|
|
589
|
+
if (targetApp.IndexOf("chrome", StringComparison.OrdinalIgnoreCase) < 0) targetApp = "chrome.exe";
|
|
590
|
+
}
|
|
591
|
+
else if (lowerApp == "edge" || lowerApp == "msedge" || lowerApp == "microsoft edge")
|
|
592
|
+
{
|
|
593
|
+
string[] edgeCandidates = new string[]
|
|
594
|
+
{
|
|
595
|
+
@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
|
|
596
|
+
@"C:\Program Files\Microsoft\Edge\Application\msedge.exe"
|
|
597
|
+
};
|
|
598
|
+
foreach (string ePath in edgeCandidates)
|
|
599
|
+
{
|
|
600
|
+
if (File.Exists(ePath)) { targetApp = ePath; break; }
|
|
601
|
+
}
|
|
602
|
+
if (targetApp.IndexOf("msedge", StringComparison.OrdinalIgnoreCase) < 0) targetApp = "msedge.exe";
|
|
603
|
+
}
|
|
604
|
+
else if (lowerApp == "brave" || lowerApp == "brave browser")
|
|
605
|
+
{
|
|
606
|
+
string localApp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
607
|
+
string[] braveCandidates = new string[]
|
|
608
|
+
{
|
|
609
|
+
@"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe",
|
|
610
|
+
Path.Combine(localApp, @"BraveSoftware\Brave-Browser\Application\brave.exe")
|
|
611
|
+
};
|
|
612
|
+
foreach (string bPath in braveCandidates)
|
|
613
|
+
{
|
|
614
|
+
if (File.Exists(bPath)) { targetApp = bPath; break; }
|
|
615
|
+
}
|
|
616
|
+
if (targetApp.IndexOf("brave", StringComparison.OrdinalIgnoreCase) < 0) targetApp = "brave.exe";
|
|
617
|
+
}
|
|
618
|
+
else if (lowerApp == "explorer" || lowerApp == "file explorer" || lowerApp == "files")
|
|
619
|
+
{
|
|
620
|
+
targetApp = "explorer.exe";
|
|
621
|
+
if (string.IsNullOrEmpty(targetArgs)) targetArgs = ".";
|
|
622
|
+
}
|
|
623
|
+
else if (lowerApp == "terminal" || lowerApp == "wt" || lowerApp == "windows terminal")
|
|
624
|
+
{
|
|
625
|
+
targetApp = "wt.exe";
|
|
626
|
+
}
|
|
627
|
+
else if (lowerApp == "cmd" || lowerApp == "command prompt")
|
|
628
|
+
{
|
|
629
|
+
targetApp = "cmd.exe";
|
|
630
|
+
}
|
|
631
|
+
else if (lowerApp == "powershell" || lowerApp == "pwsh")
|
|
632
|
+
{
|
|
633
|
+
targetApp = "powershell.exe";
|
|
634
|
+
}
|
|
635
|
+
else if (lowerApp == "paint" || lowerApp == "mspaint")
|
|
636
|
+
{
|
|
637
|
+
targetApp = "mspaint.exe";
|
|
638
|
+
}
|
|
639
|
+
else if (lowerApp == "spotify")
|
|
640
|
+
{
|
|
641
|
+
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
642
|
+
string sPath = Path.Combine(appData, @"Spotify\Spotify.exe");
|
|
643
|
+
if (File.Exists(sPath)) targetApp = sPath;
|
|
644
|
+
else targetApp = "spotify.exe";
|
|
645
|
+
}
|
|
646
|
+
else if (targetApp.IndexOf("blender", StringComparison.OrdinalIgnoreCase) >= 0)
|
|
565
647
|
{
|
|
566
648
|
string[] blenderCandidates = new string[]
|
|
567
649
|
{
|
package/bin/src/engine/llm.js
CHANGED
|
@@ -15,6 +15,8 @@ dotenv.config({ quiet: true });
|
|
|
15
15
|
const openaiApiKey = process.env.OPENAI_API_KEY;
|
|
16
16
|
const geminiApiKey = process.env.GEMINI_API_KEY;
|
|
17
17
|
const nvidiaApiKey = process.env.NVIDIA_API_KEY || process.env.NVCF_API_KEY;
|
|
18
|
+
const ftApiKey = process.env.FRONTTERRAIN_API_KEY || process.env.FT_API_KEY;
|
|
19
|
+
const ftApiBase = process.env.FRONTTERRAIN_API_BASE || process.env.FT_API_BASE || 'https://api.frontterrain.com/v1';
|
|
18
20
|
const authConfig = loadAuthConfig();
|
|
19
21
|
const byokApiKey = authConfig.byokEnabled ? authConfig.customApiKey?.trim() : undefined;
|
|
20
22
|
const byokProvider = authConfig.customLlmProvider?.trim().toLowerCase();
|
|
@@ -22,6 +24,7 @@ const byokDefaultBaseUrls = {
|
|
|
22
24
|
openai: 'https://api.openai.com/v1',
|
|
23
25
|
gemini: 'https://generativelanguage.googleapis.com/v1beta/openai',
|
|
24
26
|
nvidia: 'https://integrate.api.nvidia.com/v1',
|
|
27
|
+
frontterrain: ftApiBase,
|
|
25
28
|
};
|
|
26
29
|
const byokBaseUrl = byokApiKey
|
|
27
30
|
? authConfig.customBaseUrl?.trim() || byokDefaultBaseUrls[byokProvider || '']
|
|
@@ -36,6 +39,15 @@ export function getClientForModel(modelName) {
|
|
|
36
39
|
return clientCache.get('byok');
|
|
37
40
|
}
|
|
38
41
|
const modelLower = (modelName || '').toLowerCase();
|
|
42
|
+
// FrontTerrain Native Custom Models (Plug & Play when trained/hosted)
|
|
43
|
+
if (modelLower.startsWith('frontterrain/') || modelLower.startsWith('ft/') || modelLower.includes('frontterrain')) {
|
|
44
|
+
const key = ftApiKey || authConfig.customApiKey || nvidiaApiKey || 'ft-native';
|
|
45
|
+
const base = ftApiBase;
|
|
46
|
+
if (!clientCache.has('frontterrain')) {
|
|
47
|
+
clientCache.set('frontterrain', new OpenAI({ apiKey: key, baseURL: base, timeout: 60000 }));
|
|
48
|
+
}
|
|
49
|
+
return clientCache.get('frontterrain');
|
|
50
|
+
}
|
|
39
51
|
if ((modelLower.startsWith('nvidia/') || modelLower.startsWith('meta/') || modelLower.includes('nemotron') || modelLower.startsWith('deepseek-ai/') || modelLower.startsWith('poolside/') || modelLower.startsWith('mistralai/')) && nvidiaApiKey) {
|
|
40
52
|
if (!clientCache.has('nvidia')) {
|
|
41
53
|
clientCache.set('nvidia', new OpenAI({ apiKey: nvidiaApiKey, baseURL: 'https://integrate.api.nvidia.com/v1', timeout: 60000 }));
|
|
@@ -101,6 +113,10 @@ export const openai = new Proxy({}, {
|
|
|
101
113
|
}
|
|
102
114
|
});
|
|
103
115
|
export const AGENT_MODEL_FALLBACKS = [
|
|
116
|
+
...(ftApiKey || byokProvider === 'frontterrain' ? [
|
|
117
|
+
'frontterrain/scout-code-1',
|
|
118
|
+
'frontterrain/scout-reasoner-1',
|
|
119
|
+
] : []),
|
|
104
120
|
...(nvidiaApiKey || byokProvider === 'nvidia' ? [
|
|
105
121
|
'nvidia/nemotron-3.5-bolt-e4b',
|
|
106
122
|
'nvidia/nemotron-3.5-lightning-30b-a3b',
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type IReasoningProvider, type ProviderType, type ReasoningRequest, type ReasoningResponse, type Message, type ToolCall, type VisualGroundingRequest, type VisualGroundingResult } from './types.js';
|
|
2
|
+
export type ModelInvoker = (request: ReasoningRequest) => Promise<{
|
|
3
|
+
content: string;
|
|
4
|
+
thought?: string | undefined;
|
|
5
|
+
toolCalls?: ToolCall[] | undefined;
|
|
6
|
+
usage?: {
|
|
7
|
+
promptTokens: number;
|
|
8
|
+
completionTokens: number;
|
|
9
|
+
totalTokens: number;
|
|
10
|
+
} | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
export declare class HarpReasoningProvider implements IReasoningProvider {
|
|
13
|
+
readonly providerName: ProviderType;
|
|
14
|
+
readonly defaultModel: string;
|
|
15
|
+
private customInvoker?;
|
|
16
|
+
constructor(customInvoker?: ModelInvoker | undefined);
|
|
17
|
+
generateReasoning(request: ReasoningRequest): Promise<ReasoningResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Context Compression:
|
|
20
|
+
* Compresses older conversational history into a compact high-density context summary,
|
|
21
|
+
* maintaining token efficiency for lightweight models like HARP-1B.
|
|
22
|
+
*/
|
|
23
|
+
compressContext(messages: Message[], maxTokens?: number): Promise<Message[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Visual Grounding:
|
|
26
|
+
* Maps semantic descriptions or targets to screen/viewport coordinates.
|
|
27
|
+
*/
|
|
28
|
+
groundVisualCoordinates(request: VisualGroundingRequest): Promise<VisualGroundingResult | null>;
|
|
29
|
+
private estimateTokens;
|
|
30
|
+
private parseStructuredToolOrThought;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=harpProvider.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
export class HarpReasoningProvider {
|
|
3
|
+
providerName = 'harp';
|
|
4
|
+
defaultModel = 'harp-1b-instruct';
|
|
5
|
+
customInvoker;
|
|
6
|
+
constructor(customInvoker) {
|
|
7
|
+
this.customInvoker = customInvoker;
|
|
8
|
+
}
|
|
9
|
+
async generateReasoning(request) {
|
|
10
|
+
const startTime = Date.now();
|
|
11
|
+
const activeModel = request.model || this.defaultModel;
|
|
12
|
+
if (this.customInvoker) {
|
|
13
|
+
const rawRes = await this.customInvoker(request);
|
|
14
|
+
const latencyMs = Date.now() - startTime;
|
|
15
|
+
return {
|
|
16
|
+
thought: rawRes.thought,
|
|
17
|
+
content: rawRes.content,
|
|
18
|
+
toolCalls: rawRes.toolCalls || [],
|
|
19
|
+
model: activeModel,
|
|
20
|
+
provider: this.providerName,
|
|
21
|
+
usage: rawRes.usage || {
|
|
22
|
+
promptTokens: this.estimateTokens(request.messages),
|
|
23
|
+
completionTokens: this.estimateTokens([{ role: 'assistant', content: rawRes.content }]),
|
|
24
|
+
totalTokens: this.estimateTokens(request.messages) + this.estimateTokens([{ role: 'assistant', content: rawRes.content }]),
|
|
25
|
+
},
|
|
26
|
+
latencyMs,
|
|
27
|
+
finishReason: (rawRes.toolCalls && rawRes.toolCalls.length > 0) ? 'tool_calls' : 'stop',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Native HARP inference engine simulation / structured generator
|
|
31
|
+
const latencyMs = Date.now() - startTime;
|
|
32
|
+
const lastMsg = request.messages[request.messages.length - 1]?.content || '';
|
|
33
|
+
const parsed = this.parseStructuredToolOrThought(lastMsg, request.tools);
|
|
34
|
+
return {
|
|
35
|
+
thought: parsed.thought,
|
|
36
|
+
content: parsed.content,
|
|
37
|
+
toolCalls: parsed.toolCalls,
|
|
38
|
+
model: activeModel,
|
|
39
|
+
provider: this.providerName,
|
|
40
|
+
usage: {
|
|
41
|
+
promptTokens: this.estimateTokens(request.messages),
|
|
42
|
+
completionTokens: this.estimateTokens([{ role: 'assistant', content: parsed.content }]),
|
|
43
|
+
totalTokens: this.estimateTokens(request.messages) + 20,
|
|
44
|
+
},
|
|
45
|
+
latencyMs,
|
|
46
|
+
finishReason: parsed.toolCalls.length > 0 ? 'tool_calls' : 'stop',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Context Compression:
|
|
51
|
+
* Compresses older conversational history into a compact high-density context summary,
|
|
52
|
+
* maintaining token efficiency for lightweight models like HARP-1B.
|
|
53
|
+
*/
|
|
54
|
+
async compressContext(messages, maxTokens = 2048) {
|
|
55
|
+
if (messages.length <= 4)
|
|
56
|
+
return messages;
|
|
57
|
+
const systemMessages = messages.filter(m => m.role === 'system');
|
|
58
|
+
const nonSystem = messages.filter(m => m.role !== 'system');
|
|
59
|
+
const estimated = this.estimateTokens(messages);
|
|
60
|
+
if (estimated <= maxTokens) {
|
|
61
|
+
return messages;
|
|
62
|
+
}
|
|
63
|
+
// Keep the latest 3 interactions intact
|
|
64
|
+
const recent = nonSystem.slice(-3);
|
|
65
|
+
const older = nonSystem.slice(0, -3);
|
|
66
|
+
const summaryText = older
|
|
67
|
+
.map(m => `[${m.role.toUpperCase()}]: ${m.content.slice(0, 100)}...`)
|
|
68
|
+
.join(' | ');
|
|
69
|
+
const compressedSystem = {
|
|
70
|
+
role: 'system',
|
|
71
|
+
content: `Summary of previous task history: ${summaryText}`,
|
|
72
|
+
};
|
|
73
|
+
return [...systemMessages, compressedSystem, ...recent];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Visual Grounding:
|
|
77
|
+
* Maps semantic descriptions or targets to screen/viewport coordinates.
|
|
78
|
+
*/
|
|
79
|
+
async groundVisualCoordinates(request) {
|
|
80
|
+
const desc = request.targetDescription.toLowerCase();
|
|
81
|
+
const width = request.viewport?.width || 1920;
|
|
82
|
+
const height = request.viewport?.height || 1080;
|
|
83
|
+
// Semantic heuristics for common UI positions
|
|
84
|
+
if (desc.includes('top left') || desc.includes('logo') || desc.includes('menu')) {
|
|
85
|
+
return { x: Math.round(width * 0.05), y: Math.round(height * 0.05), confidence: 0.9 };
|
|
86
|
+
}
|
|
87
|
+
if (desc.includes('center') || desc.includes('main') || desc.includes('submit')) {
|
|
88
|
+
return { x: Math.round(width * 0.5), y: Math.round(height * 0.5), confidence: 0.85 };
|
|
89
|
+
}
|
|
90
|
+
if (desc.includes('bottom right') || desc.includes('save') || desc.includes('next')) {
|
|
91
|
+
return { x: Math.round(width * 0.9), y: Math.round(height * 0.9), confidence: 0.88 };
|
|
92
|
+
}
|
|
93
|
+
// Generic fallback grounding
|
|
94
|
+
return {
|
|
95
|
+
x: Math.round(width / 2),
|
|
96
|
+
y: Math.round(height / 2),
|
|
97
|
+
confidence: 0.75,
|
|
98
|
+
box: { x: Math.round(width / 4), y: Math.round(height / 4), width: Math.round(width / 2), height: Math.round(height / 2) },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
estimateTokens(messages) {
|
|
102
|
+
const text = messages.map(m => m.content).join(' ');
|
|
103
|
+
return Math.ceil(text.length / 4);
|
|
104
|
+
}
|
|
105
|
+
parseStructuredToolOrThought(input, tools) {
|
|
106
|
+
const thought = `HARP-1B analyzed task objective: "${input.slice(0, 50)}". Formulating structured plan.`;
|
|
107
|
+
const toolCalls = [];
|
|
108
|
+
// Check if an available tool matches the input intent
|
|
109
|
+
if (tools && tools.length > 0) {
|
|
110
|
+
const firstTool = tools[0];
|
|
111
|
+
toolCalls.push({
|
|
112
|
+
id: `call_${Date.now()}_harp`,
|
|
113
|
+
name: firstTool.name || 'browser_inspect',
|
|
114
|
+
arguments: {},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
thought,
|
|
119
|
+
content: `HARP completed reasoning for: ${input.slice(0, 80)}`,
|
|
120
|
+
toolCalls,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=harpProvider.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IReasoningProvider, type ProviderType, type ReasoningRequest, type ReasoningResponse, type Message, type VisualGroundingRequest, type VisualGroundingResult } from './types.js';
|
|
2
|
+
export declare class LocalModelReasoningProvider implements IReasoningProvider {
|
|
3
|
+
readonly providerName: ProviderType;
|
|
4
|
+
readonly defaultModel: string;
|
|
5
|
+
private customInvoker?;
|
|
6
|
+
constructor(customInvoker?: ((request: ReasoningRequest) => Promise<any>) | undefined);
|
|
7
|
+
generateReasoning(request: ReasoningRequest): Promise<ReasoningResponse>;
|
|
8
|
+
compressContext(messages: Message[], maxTokens?: number): Promise<Message[]>;
|
|
9
|
+
groundVisualCoordinates(request: VisualGroundingRequest): Promise<VisualGroundingResult | null>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=localModelProvider.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
export class LocalModelReasoningProvider {
|
|
3
|
+
providerName = 'local';
|
|
4
|
+
defaultModel = 'llama-3.2-3b';
|
|
5
|
+
customInvoker;
|
|
6
|
+
constructor(customInvoker) {
|
|
7
|
+
this.customInvoker = customInvoker;
|
|
8
|
+
}
|
|
9
|
+
async generateReasoning(request) {
|
|
10
|
+
const startTime = Date.now();
|
|
11
|
+
const activeModel = request.model || this.defaultModel;
|
|
12
|
+
if (this.customInvoker) {
|
|
13
|
+
const raw = await this.customInvoker(request);
|
|
14
|
+
const latencyMs = Date.now() - startTime;
|
|
15
|
+
return {
|
|
16
|
+
thought: raw.thought,
|
|
17
|
+
content: raw.content || '',
|
|
18
|
+
toolCalls: raw.toolCalls || [],
|
|
19
|
+
model: activeModel,
|
|
20
|
+
provider: this.providerName,
|
|
21
|
+
usage: raw.usage || { promptTokens: 60, completionTokens: 30, totalTokens: 90 },
|
|
22
|
+
latencyMs,
|
|
23
|
+
finishReason: raw.toolCalls?.length > 0 ? 'tool_calls' : 'stop',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const latencyMs = Date.now() - startTime;
|
|
27
|
+
return {
|
|
28
|
+
content: `Local model executed: ${request.objective}`,
|
|
29
|
+
toolCalls: [],
|
|
30
|
+
model: activeModel,
|
|
31
|
+
provider: this.providerName,
|
|
32
|
+
usage: { promptTokens: 50, completionTokens: 25, totalTokens: 75 },
|
|
33
|
+
latencyMs,
|
|
34
|
+
finishReason: 'stop',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async compressContext(messages, maxTokens = 2048) {
|
|
38
|
+
return messages.slice(-6);
|
|
39
|
+
}
|
|
40
|
+
async groundVisualCoordinates(request) {
|
|
41
|
+
return {
|
|
42
|
+
x: Math.round((request.viewport?.width || 1920) / 2),
|
|
43
|
+
y: Math.round((request.viewport?.height || 1080) / 2),
|
|
44
|
+
confidence: 0.7,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=localModelProvider.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IReasoningProvider, type ProviderType, type ReasoningRequest, type ReasoningResponse, type Message, type VisualGroundingRequest, type VisualGroundingResult } from './types.js';
|
|
2
|
+
export declare class OpenAIReasoningProvider implements IReasoningProvider {
|
|
3
|
+
readonly providerName: ProviderType;
|
|
4
|
+
readonly defaultModel: string;
|
|
5
|
+
private customInvoker?;
|
|
6
|
+
constructor(customInvoker?: ((request: ReasoningRequest) => Promise<any>) | undefined);
|
|
7
|
+
generateReasoning(request: ReasoningRequest): Promise<ReasoningResponse>;
|
|
8
|
+
compressContext(messages: Message[], maxTokens?: number): Promise<Message[]>;
|
|
9
|
+
groundVisualCoordinates(request: VisualGroundingRequest): Promise<VisualGroundingResult | null>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=openaiProvider.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
export class OpenAIReasoningProvider {
|
|
3
|
+
providerName = 'openai';
|
|
4
|
+
defaultModel = 'gpt-4o';
|
|
5
|
+
customInvoker;
|
|
6
|
+
constructor(customInvoker) {
|
|
7
|
+
this.customInvoker = customInvoker;
|
|
8
|
+
}
|
|
9
|
+
async generateReasoning(request) {
|
|
10
|
+
const startTime = Date.now();
|
|
11
|
+
const activeModel = request.model || this.defaultModel;
|
|
12
|
+
if (this.customInvoker) {
|
|
13
|
+
const raw = await this.customInvoker(request);
|
|
14
|
+
const latencyMs = Date.now() - startTime;
|
|
15
|
+
return {
|
|
16
|
+
thought: raw.thought,
|
|
17
|
+
content: raw.content || '',
|
|
18
|
+
toolCalls: raw.toolCalls || [],
|
|
19
|
+
model: activeModel,
|
|
20
|
+
provider: this.providerName,
|
|
21
|
+
usage: raw.usage || { promptTokens: 100, completionTokens: 50, totalTokens: 150 },
|
|
22
|
+
latencyMs,
|
|
23
|
+
finishReason: raw.toolCalls?.length > 0 ? 'tool_calls' : 'stop',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const latencyMs = Date.now() - startTime;
|
|
27
|
+
return {
|
|
28
|
+
content: `OpenAI response for: ${request.objective}`,
|
|
29
|
+
toolCalls: [],
|
|
30
|
+
model: activeModel,
|
|
31
|
+
provider: this.providerName,
|
|
32
|
+
usage: { promptTokens: 100, completionTokens: 40, totalTokens: 140 },
|
|
33
|
+
latencyMs,
|
|
34
|
+
finishReason: 'stop',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async compressContext(messages, maxTokens = 4096) {
|
|
38
|
+
if (messages.length <= 4)
|
|
39
|
+
return messages;
|
|
40
|
+
return messages.slice(-10); // Standard sliding window
|
|
41
|
+
}
|
|
42
|
+
async groundVisualCoordinates(request) {
|
|
43
|
+
return {
|
|
44
|
+
x: Math.round((request.viewport?.width || 1920) / 2),
|
|
45
|
+
y: Math.round((request.viewport?.height || 1080) / 2),
|
|
46
|
+
confidence: 0.8,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=openaiProvider.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type IReasoningProvider, type ProviderType, type ReasoningRequest, type ReasoningResponse } from './types.js';
|
|
2
|
+
export declare class ReasoningOrchestrator {
|
|
3
|
+
private providers;
|
|
4
|
+
private activeProviderName;
|
|
5
|
+
private fallbackOrder;
|
|
6
|
+
constructor(customProviders?: IReasoningProvider[] | undefined);
|
|
7
|
+
registerProvider(provider: IReasoningProvider): void;
|
|
8
|
+
getProvider(name?: ProviderType | undefined): IReasoningProvider | undefined;
|
|
9
|
+
setActiveProvider(name: ProviderType): void;
|
|
10
|
+
getActiveProviderName(): ProviderType;
|
|
11
|
+
setFallbackOrder(order: ProviderType[]): void;
|
|
12
|
+
/**
|
|
13
|
+
* Executes reasoning using the active provider with automatic fallback if configured.
|
|
14
|
+
*/
|
|
15
|
+
reason(request: ReasoningRequest): Promise<ReasoningResponse>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=reasoningOrchestrator.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {} from './types.js';
|
|
2
|
+
import { HarpReasoningProvider } from './harpProvider.js';
|
|
3
|
+
import { OpenAIReasoningProvider } from './openaiProvider.js';
|
|
4
|
+
import { LocalModelReasoningProvider } from './localModelProvider.js';
|
|
5
|
+
export class ReasoningOrchestrator {
|
|
6
|
+
providers = new Map();
|
|
7
|
+
activeProviderName = 'harp';
|
|
8
|
+
fallbackOrder = ['harp', 'openai', 'local'];
|
|
9
|
+
constructor(customProviders) {
|
|
10
|
+
if (customProviders && customProviders.length > 0) {
|
|
11
|
+
for (const p of customProviders) {
|
|
12
|
+
this.providers.set(p.providerName, p);
|
|
13
|
+
}
|
|
14
|
+
this.activeProviderName = customProviders[0].providerName;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// Default built-in providers
|
|
18
|
+
this.providers.set('harp', new HarpReasoningProvider());
|
|
19
|
+
this.providers.set('openai', new OpenAIReasoningProvider());
|
|
20
|
+
this.providers.set('local', new LocalModelReasoningProvider());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
registerProvider(provider) {
|
|
24
|
+
this.providers.set(provider.providerName, provider);
|
|
25
|
+
}
|
|
26
|
+
getProvider(name) {
|
|
27
|
+
return this.providers.get(name || this.activeProviderName);
|
|
28
|
+
}
|
|
29
|
+
setActiveProvider(name) {
|
|
30
|
+
if (!this.providers.has(name)) {
|
|
31
|
+
throw new Error(`Provider "${name}" is not registered in ReasoningOrchestrator.`);
|
|
32
|
+
}
|
|
33
|
+
this.activeProviderName = name;
|
|
34
|
+
}
|
|
35
|
+
getActiveProviderName() {
|
|
36
|
+
return this.activeProviderName;
|
|
37
|
+
}
|
|
38
|
+
setFallbackOrder(order) {
|
|
39
|
+
this.fallbackOrder = order;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Executes reasoning using the active provider with automatic fallback if configured.
|
|
43
|
+
*/
|
|
44
|
+
async reason(request) {
|
|
45
|
+
const activeProvider = this.providers.get(this.activeProviderName);
|
|
46
|
+
if (!activeProvider) {
|
|
47
|
+
throw new Error(`Active provider "${this.activeProviderName}" not found.`);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return await activeProvider.generateReasoning(request);
|
|
51
|
+
}
|
|
52
|
+
catch (primaryErr) {
|
|
53
|
+
// Attempt fallback providers
|
|
54
|
+
for (const fallbackName of this.fallbackOrder) {
|
|
55
|
+
if (fallbackName === this.activeProviderName)
|
|
56
|
+
continue;
|
|
57
|
+
const fallbackProvider = this.providers.get(fallbackName);
|
|
58
|
+
if (fallbackProvider) {
|
|
59
|
+
try {
|
|
60
|
+
const fallbackRes = await fallbackProvider.generateReasoning(request);
|
|
61
|
+
return {
|
|
62
|
+
...fallbackRes,
|
|
63
|
+
content: `[Fallback from ${this.activeProviderName} to ${fallbackName}]: ${fallbackRes.content}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Continue to next fallback
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`Reasoning failed across all providers: ${primaryErr.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=reasoningOrchestrator.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type ProviderType = 'harp' | 'openai' | 'local' | 'gemini' | 'anthropic' | 'custom';
|
|
2
|
+
export interface Message {
|
|
3
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
4
|
+
content: string;
|
|
5
|
+
name?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface ToolCall {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
arguments: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface VisualGroundingRequest {
|
|
13
|
+
screenshotBase64?: string | undefined;
|
|
14
|
+
targetDescription: string;
|
|
15
|
+
viewport?: {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
} | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface VisualGroundingResult {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
confidence: number;
|
|
24
|
+
box?: {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
} | undefined;
|
|
30
|
+
}
|
|
31
|
+
export interface ReasoningRequest {
|
|
32
|
+
objective: string;
|
|
33
|
+
messages: Message[];
|
|
34
|
+
tools?: any[] | undefined;
|
|
35
|
+
systemInstruction?: string | undefined;
|
|
36
|
+
temperature?: number | undefined;
|
|
37
|
+
maxTokens?: number | undefined;
|
|
38
|
+
model?: string | undefined;
|
|
39
|
+
visualGrounding?: VisualGroundingRequest | undefined;
|
|
40
|
+
}
|
|
41
|
+
export interface TokenUsage {
|
|
42
|
+
promptTokens: number;
|
|
43
|
+
completionTokens: number;
|
|
44
|
+
totalTokens: number;
|
|
45
|
+
}
|
|
46
|
+
export interface ReasoningResponse {
|
|
47
|
+
thought?: string | undefined;
|
|
48
|
+
content: string;
|
|
49
|
+
toolCalls: ToolCall[];
|
|
50
|
+
model: string;
|
|
51
|
+
provider: ProviderType;
|
|
52
|
+
usage: TokenUsage;
|
|
53
|
+
latencyMs: number;
|
|
54
|
+
finishReason: string;
|
|
55
|
+
}
|
|
56
|
+
export interface IReasoningProvider {
|
|
57
|
+
readonly providerName: ProviderType;
|
|
58
|
+
readonly defaultModel: string;
|
|
59
|
+
generateReasoning(request: ReasoningRequest): Promise<ReasoningResponse>;
|
|
60
|
+
compressContext(messages: Message[], maxTokens?: number): Promise<Message[]>;
|
|
61
|
+
groundVisualCoordinates?(request: VisualGroundingRequest): Promise<VisualGroundingResult | null>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|