ft-scout 9.5.5 → 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.
Files changed (92) hide show
  1. package/README.md +1 -1
  2. package/bin/src/engine/agent/computerUseLoop.d.ts +107 -0
  3. package/bin/src/engine/agent/computerUseLoop.js +413 -0
  4. package/bin/src/engine/agent/index.d.ts +2 -0
  5. package/bin/src/engine/agent/index.js +2 -0
  6. package/bin/src/engine/agent/recovery/index.d.ts +4 -0
  7. package/bin/src/engine/agent/recovery/index.js +4 -0
  8. package/bin/src/engine/agent/recovery/loopDetector.d.ts +26 -0
  9. package/bin/src/engine/agent/recovery/loopDetector.js +126 -0
  10. package/bin/src/engine/agent/recovery/recoveryManager.d.ts +43 -0
  11. package/bin/src/engine/agent/recovery/recoveryManager.js +271 -0
  12. package/bin/src/engine/agent/recovery/types.d.ts +48 -0
  13. package/bin/src/engine/agent/recovery/types.js +4 -0
  14. package/bin/src/engine/agent/verification/index.d.ts +3 -0
  15. package/bin/src/engine/agent/verification/index.js +3 -0
  16. package/bin/src/engine/agent/verification/stateChangeVerifier.d.ts +22 -0
  17. package/bin/src/engine/agent/verification/stateChangeVerifier.js +282 -0
  18. package/bin/src/engine/agent/verification/types.d.ts +28 -0
  19. package/bin/src/engine/agent/verification/types.js +4 -0
  20. package/bin/src/engine/agentEngine.d.ts +2 -1
  21. package/bin/src/engine/agentEngine.js +2 -1
  22. package/bin/src/engine/agentState.d.ts +41 -1
  23. package/bin/src/engine/agentState.js +45 -0
  24. package/bin/src/engine/browser/actions/actionEngine.d.ts +41 -0
  25. package/bin/src/engine/browser/actions/actionEngine.js +707 -0
  26. package/bin/src/engine/browser/actions/index.d.ts +4 -0
  27. package/bin/src/engine/browser/actions/index.js +4 -0
  28. package/bin/src/engine/browser/actions/reliability.d.ts +41 -0
  29. package/bin/src/engine/browser/actions/reliability.js +170 -0
  30. package/bin/src/engine/browser/actions/types.d.ts +50 -0
  31. package/bin/src/engine/browser/actions/types.js +2 -0
  32. package/bin/src/engine/browser/browserController.d.ts +18 -0
  33. package/bin/src/engine/browser/browserController.js +44 -12
  34. package/bin/src/engine/browser/index.d.ts +2 -0
  35. package/bin/src/engine/browser/index.js +2 -0
  36. package/bin/src/engine/browser/observer/accessibilityTree.d.ts +14 -0
  37. package/bin/src/engine/browser/observer/accessibilityTree.js +214 -0
  38. package/bin/src/engine/browser/observer/browserObserver.d.ts +29 -0
  39. package/bin/src/engine/browser/observer/browserObserver.js +204 -0
  40. package/bin/src/engine/browser/observer/domExtractor.d.ts +30 -0
  41. package/bin/src/engine/browser/observer/domExtractor.js +407 -0
  42. package/bin/src/engine/browser/observer/index.d.ts +5 -0
  43. package/bin/src/engine/browser/observer/index.js +5 -0
  44. package/bin/src/engine/browser/observer/types.d.ts +163 -0
  45. package/bin/src/engine/browser/observer/types.js +8 -0
  46. package/bin/src/engine/computer/computerController.d.ts +43 -0
  47. package/bin/src/engine/computer/computerController.js +111 -0
  48. package/bin/src/engine/computer/mockComputer.d.ts +6 -1
  49. package/bin/src/engine/computer/mockComputer.js +58 -0
  50. package/bin/src/engine/models/harpProvider.d.ts +32 -0
  51. package/bin/src/engine/models/harpProvider.js +124 -0
  52. package/bin/src/engine/models/index.d.ts +6 -0
  53. package/bin/src/engine/models/index.js +6 -0
  54. package/bin/src/engine/models/localModelProvider.d.ts +11 -0
  55. package/bin/src/engine/models/localModelProvider.js +48 -0
  56. package/bin/src/engine/models/openaiProvider.d.ts +11 -0
  57. package/bin/src/engine/models/openaiProvider.js +50 -0
  58. package/bin/src/engine/models/reasoningOrchestrator.d.ts +17 -0
  59. package/bin/src/engine/models/reasoningOrchestrator.js +75 -0
  60. package/bin/src/engine/models/types.d.ts +63 -0
  61. package/bin/src/engine/models/types.js +2 -0
  62. package/bin/src/engine/production/index.d.ts +3 -0
  63. package/bin/src/engine/production/index.js +3 -0
  64. package/bin/src/engine/production/taskReplay.d.ts +37 -0
  65. package/bin/src/engine/production/taskReplay.js +81 -0
  66. package/bin/src/engine/production/telemetry.d.ts +43 -0
  67. package/bin/src/engine/production/telemetry.js +68 -0
  68. package/bin/src/engine/runtime/agentRuntime.d.ts +1 -1
  69. package/bin/src/engine/safety/index.d.ts +3 -0
  70. package/bin/src/engine/safety/index.js +3 -0
  71. package/bin/src/engine/safety/policyEngine.d.ts +40 -0
  72. package/bin/src/engine/safety/policyEngine.js +282 -0
  73. package/bin/src/engine/safety/types.d.ts +24 -0
  74. package/bin/src/engine/safety/types.js +2 -0
  75. package/bin/src/engine/safety.d.ts +1 -0
  76. package/bin/src/engine/safety.js +1 -0
  77. package/bin/src/engine/toolRegistry.d.ts +4 -0
  78. package/bin/src/engine/toolRegistry.js +9 -0
  79. package/bin/src/engine/tools/domainHandlers.d.ts +61 -0
  80. package/bin/src/engine/tools/domainHandlers.js +458 -0
  81. package/bin/src/engine/tools/index.d.ts +4 -0
  82. package/bin/src/engine/tools/index.js +4 -0
  83. package/bin/src/engine/tools/types.d.ts +56 -0
  84. package/bin/src/engine/tools/types.js +2 -0
  85. package/bin/src/engine/tools/unifiedRouter.d.ts +29 -0
  86. package/bin/src/engine/tools/unifiedRouter.js +426 -0
  87. package/bin/src/index.js +4 -4
  88. package/bin/src/mcp/client.js +1 -1
  89. package/bin/src/utils/branding.js +1 -1
  90. package/bin/src/utils/qrBridge.js +1 -1
  91. package/bin/src/utils/support.js +1 -1
  92. package/package.json +2 -2
@@ -8,6 +8,39 @@ const __dirname = path.dirname(__filename);
8
8
  const execAsync = promisify(exec);
9
9
  const execFileAsync = promisify(execFile);
10
10
  import { OperatorHud } from './operatorHud.js';
11
+ export function classifyAppType(windowTitleOrApp) {
12
+ const lower = (windowTitleOrApp || '').toLowerCase().trim();
13
+ if (/chrome|edge|msedge|brave|firefox|opera|browser|safari|github/i.test(lower)) {
14
+ return 'browser';
15
+ }
16
+ if (/terminal|wt|windows\s*terminal|powershell|pwsh|cmd|bash|wsl|command\s*prompt|zsh|git\s*bash/i.test(lower)) {
17
+ return 'terminal';
18
+ }
19
+ if (/code|cursor|notepad|sublime|atom|vim|neovim|ide|editor/i.test(lower)) {
20
+ return 'editor';
21
+ }
22
+ if (/explorer|file\s*explorer|finder|nautilus|dolphin|files/i.test(lower)) {
23
+ return 'file_manager';
24
+ }
25
+ return 'other';
26
+ }
27
+ export function getDesktopActionRiskLevel(action) {
28
+ const act = action.toLowerCase().trim();
29
+ // Level 0: Read-only inspection
30
+ if (['screenshot', 'active_window', 'activewindow', 'application_state', 'applicationstate', 'inspectui', 'getmouseposition', 'diagnostic', 'position'].includes(act)) {
31
+ return 0;
32
+ }
33
+ // Level 1: Reversible input modification
34
+ if (['move', 'move_mouse', 'movemouse', 'mousemove', 'type', 'key_press', 'keypress', 'click', 'leftclick', 'rightclick', 'doubleclick', 'drag', 'scroll', 'switchwindow', 'switch_to_app', 'switchtoapp'].includes(act)) {
35
+ return 1;
36
+ }
37
+ // Level 2: External side effects / process launching
38
+ if (['openapplication', 'closeapplication', 'hotkey'].includes(act)) {
39
+ return 2;
40
+ }
41
+ // Level 3: High impact / destructive
42
+ return 3;
43
+ }
11
44
  export class SystemComputerController {
12
45
  workspaceDir;
13
46
  screenshotsDir;
@@ -440,6 +473,9 @@ if ($act -eq "move") {
440
473
  coordinates: { x, y },
441
474
  };
442
475
  }
476
+ async move_mouse(x, y) {
477
+ return this.move(x, y);
478
+ }
443
479
  async drag(startX, startY, endX, endY) {
444
480
  if (process.platform === 'win32') {
445
481
  const res = await this.runDriverAction('drag', [startX, startY, endX, endY]);
@@ -564,6 +600,9 @@ if ($act -eq "move") {
564
600
  }
565
601
  return { success: true, output: `Simulated key press: ${key}`, action: 'key_press' };
566
602
  }
603
+ async key_press(key) {
604
+ return this.keyPress(key);
605
+ }
567
606
  async hotkey(keys) {
568
607
  if (!keys || keys.length === 0) {
569
608
  return { success: false, output: 'No keys provided for hotkey', action: 'hotkey', error: 'No keys provided' };
@@ -910,5 +949,77 @@ if ($result) { Write-Output "OK" } else { Write-Output "NOT_FOUND" }
910
949
  }
911
950
  return { activeWindow: 'Desktop', windows: ['Desktop', 'Terminal'] };
912
951
  }
952
+ async active_window() {
953
+ const ui = await this.inspectUI();
954
+ const title = ui.activeWindow || this.activeWindow || 'Desktop';
955
+ const appType = classifyAppType(title);
956
+ let bounds;
957
+ try {
958
+ const b = await this.getWindowBounds(title);
959
+ if (b)
960
+ bounds = b;
961
+ }
962
+ catch { }
963
+ return {
964
+ title,
965
+ appName: title.split(/[-—·]/)[0]?.trim() || title,
966
+ appType,
967
+ bounds: bounds || undefined,
968
+ isResponding: true,
969
+ };
970
+ }
971
+ async application_state(appName) {
972
+ const ui = await this.inspectUI();
973
+ const activeWin = ui.activeWindow || 'Desktop';
974
+ const states = [];
975
+ for (const win of ui.windows) {
976
+ if (!win || win === 'Desktop')
977
+ continue;
978
+ const appType = classifyAppType(win);
979
+ const isFocused = win.toLowerCase() === activeWin.toLowerCase() ||
980
+ (activeWin !== 'Desktop' && win.toLowerCase().includes(activeWin.toLowerCase()));
981
+ if (appName && !win.toLowerCase().includes(appName.toLowerCase())) {
982
+ continue;
983
+ }
984
+ let bounds;
985
+ try {
986
+ const b = await this.getWindowBounds(win);
987
+ if (b)
988
+ bounds = b;
989
+ }
990
+ catch { }
991
+ states.push({
992
+ appName: win.split(/[-—·]/)[0]?.trim() || win,
993
+ appType,
994
+ isRunning: true,
995
+ isFocused,
996
+ windowTitle: win,
997
+ bounds: bounds || undefined,
998
+ canAcceptInput: true,
999
+ });
1000
+ }
1001
+ return states;
1002
+ }
1003
+ async switch_to_app(appType) {
1004
+ const target = appType.toLowerCase().trim();
1005
+ const ui = await this.inspectUI();
1006
+ // 1. Check if an application of this type is already open
1007
+ const openMatch = ui.windows.find(w => classifyAppType(w) === target || w.toLowerCase().includes(target));
1008
+ if (openMatch) {
1009
+ return await this.switchWindow(openMatch);
1010
+ }
1011
+ // 2. Not running: Launch canonical default application for this category
1012
+ let defaultApp = target;
1013
+ if (target === 'browser')
1014
+ defaultApp = 'chrome';
1015
+ else if (target === 'terminal')
1016
+ defaultApp = 'wt';
1017
+ else if (target === 'editor')
1018
+ defaultApp = 'notepad';
1019
+ else if (target === 'file_manager')
1020
+ defaultApp = 'explorer';
1021
+ return await this.openApplication(defaultApp);
1022
+ }
913
1023
  }
1024
+ export const ComputerController = SystemComputerController;
914
1025
  //# sourceMappingURL=computerController.js.map
@@ -1,4 +1,4 @@
1
- import type { IComputerController, ScreenCaptureResult, ComputerActionResult, UIInspectionResult } from './computerController.js';
1
+ import type { IComputerController, ScreenCaptureResult, ComputerActionResult, UIInspectionResult, ActiveWindowInfo, DesktopApplicationState, SupportedAppType } from './computerController.js';
2
2
  export declare class MockComputerController implements IComputerController {
3
3
  activeWindow: string;
4
4
  expectedApplication: string | null;
@@ -31,10 +31,12 @@ export declare class MockComputerController implements IComputerController {
31
31
  mouseUp(x?: number, y?: number, button?: 'left' | 'right' | 'middle'): Promise<ComputerActionResult>;
32
32
  type(text: string): Promise<ComputerActionResult>;
33
33
  keyPress(key: string): Promise<ComputerActionResult>;
34
+ key_press(key: string): Promise<ComputerActionResult>;
34
35
  hotkey(keys: string[]): Promise<ComputerActionResult>;
35
36
  scroll(deltaX: number, deltaY: number): Promise<ComputerActionResult>;
36
37
  mouseMove(x: number, y: number): Promise<ComputerActionResult>;
37
38
  move(x: number, y: number): Promise<ComputerActionResult>;
39
+ move_mouse(x: number, y: number): Promise<ComputerActionResult>;
38
40
  drag(fromX: number, fromY: number, toX: number, toY: number): Promise<ComputerActionResult>;
39
41
  wait(ms: number): Promise<void>;
40
42
  getMousePosition(): Promise<{
@@ -52,6 +54,9 @@ export declare class MockComputerController implements IComputerController {
52
54
  height: number;
53
55
  } | null>;
54
56
  inspectUI(): Promise<UIInspectionResult>;
57
+ active_window(): Promise<ActiveWindowInfo>;
58
+ application_state(appName?: string): Promise<DesktopApplicationState[]>;
59
+ switch_to_app(appType: SupportedAppType | string): Promise<ComputerActionResult>;
55
60
  getActionLog(): Array<{
56
61
  action: string;
57
62
  args: any;
@@ -1,3 +1,4 @@
1
+ import { classifyAppType } from './computerController.js';
1
2
  export class MockComputerController {
2
3
  activeWindow = 'Desktop';
3
4
  expectedApplication = null;
@@ -139,6 +140,9 @@ export class MockComputerController {
139
140
  this.log('keyPress', { key });
140
141
  return { success: true, output: `Pressed key: ${key}`, action: 'key_press' };
141
142
  }
143
+ async key_press(key) {
144
+ return this.keyPress(key);
145
+ }
142
146
  async hotkey(keys) {
143
147
  this.log('hotkey', { keys });
144
148
  return { success: true, output: `Executed hotkey: ${keys.join('+')}`, action: 'hotkey' };
@@ -162,6 +166,9 @@ export class MockComputerController {
162
166
  activeWindow: this.activeWindow,
163
167
  };
164
168
  }
169
+ async move_mouse(x, y) {
170
+ return this.move(x, y);
171
+ }
165
172
  async drag(fromX, fromY, toX, toY) {
166
173
  this.currentX = toX;
167
174
  this.currentY = toY;
@@ -250,6 +257,57 @@ export class MockComputerController {
250
257
  focusedElement: 'MainView',
251
258
  };
252
259
  }
260
+ async active_window() {
261
+ this.log('active_window', {});
262
+ const appType = classifyAppType(this.activeWindow);
263
+ return {
264
+ title: this.activeWindow,
265
+ appName: this.activeWindow.split(/[-—·]/)[0]?.trim() || this.activeWindow,
266
+ appType,
267
+ bounds: { x: 0, y: 0, width: this.screenWidth, height: this.screenHeight },
268
+ isResponding: true,
269
+ };
270
+ }
271
+ async application_state(appName) {
272
+ this.log('application_state', { appName });
273
+ const states = [];
274
+ for (const win of this.openWindows) {
275
+ if (appName && !win.toLowerCase().includes(appName.toLowerCase())) {
276
+ continue;
277
+ }
278
+ const appType = classifyAppType(win);
279
+ states.push({
280
+ appName: win.split(/[-—·]/)[0]?.trim() || win,
281
+ appType,
282
+ isRunning: true,
283
+ isFocused: win === this.activeWindow,
284
+ windowTitle: win,
285
+ bounds: { x: 0, y: 0, width: this.screenWidth, height: this.screenHeight },
286
+ canAcceptInput: true,
287
+ });
288
+ }
289
+ return states;
290
+ }
291
+ async switch_to_app(appType) {
292
+ this.log('switch_to_app', { appType });
293
+ const target = appType.toLowerCase().trim();
294
+ // 1. Check if an application of this category is open
295
+ const openMatch = this.openWindows.find(w => classifyAppType(w) === target || w.toLowerCase().includes(target));
296
+ if (openMatch) {
297
+ return await this.switchWindow(openMatch);
298
+ }
299
+ // 2. Open default application for this category
300
+ let defaultName = target;
301
+ if (target === 'browser')
302
+ defaultName = 'Google Chrome';
303
+ else if (target === 'terminal')
304
+ defaultName = 'Terminal';
305
+ else if (target === 'editor')
306
+ defaultName = 'VS Code';
307
+ else if (target === 'file_manager')
308
+ defaultName = 'File Explorer';
309
+ return await this.openApplication(defaultName);
310
+ }
253
311
  getActionLog() {
254
312
  return [...this.actionLog];
255
313
  }
@@ -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,6 @@
1
+ export * from './types.js';
2
+ export * from './harpProvider.js';
3
+ export * from './openaiProvider.js';
4
+ export * from './localModelProvider.js';
5
+ export * from './reasoningOrchestrator.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from './types.js';
2
+ export * from './harpProvider.js';
3
+ export * from './openaiProvider.js';
4
+ export * from './localModelProvider.js';
5
+ export * from './reasoningOrchestrator.js';
6
+ //# sourceMappingURL=index.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