@ddwang/magnitude-core 0.3.1-ddwang.1
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/dist/actions/desktopActions.d.ts +58 -0
- package/dist/actions/desktopActions.js +154 -0
- package/dist/actions/index.d.ts +26 -0
- package/dist/actions/index.js +11 -0
- package/dist/actions/taskActions.d.ts +8 -0
- package/dist/actions/taskActions.js +27 -0
- package/dist/actions/types.d.ts +31 -0
- package/dist/actions/types.js +5 -0
- package/dist/actions/util.d.ts +20 -0
- package/dist/actions/util.js +297 -0
- package/dist/actions/webActions.d.ts +79 -0
- package/dist/actions/webActions.js +190 -0
- package/dist/agent/browserAgent.d.ts +29 -0
- package/dist/agent/browserAgent.js +122 -0
- package/dist/agent/errors.d.ts +8 -0
- package/dist/agent/errors.js +68 -0
- package/dist/agent/index.d.ts +53 -0
- package/dist/agent/index.js +377 -0
- package/dist/agent/narrator.d.ts +4 -0
- package/dist/agent/narrator.js +63 -0
- package/dist/agent/pause.test.d.ts +1 -0
- package/dist/agent/pause.test.js +194 -0
- package/dist/ai/baml_client/async_client.d.ts +73 -0
- package/dist/ai/baml_client/async_client.js +152 -0
- package/dist/ai/baml_client/async_request.d.ts +35 -0
- package/dist/ai/baml_client/async_request.js +98 -0
- package/dist/ai/baml_client/config.d.ts +11 -0
- package/dist/ai/baml_client/config.js +20 -0
- package/dist/ai/baml_client/globals.d.ts +16 -0
- package/dist/ai/baml_client/globals.js +37 -0
- package/dist/ai/baml_client/index.d.ts +16 -0
- package/dist/ai/baml_client/index.js +41 -0
- package/dist/ai/baml_client/inlinedbaml.d.ts +19 -0
- package/dist/ai/baml_client/inlinedbaml.js +31 -0
- package/dist/ai/baml_client/parser.d.ts +53 -0
- package/dist/ai/baml_client/parser.js +86 -0
- package/dist/ai/baml_client/partial_types.d.ts +61 -0
- package/dist/ai/baml_client/partial_types.js +10 -0
- package/dist/ai/baml_client/sync_client.d.ts +50 -0
- package/dist/ai/baml_client/sync_client.js +100 -0
- package/dist/ai/baml_client/sync_request.d.ts +35 -0
- package/dist/ai/baml_client/sync_request.js +98 -0
- package/dist/ai/baml_client/tracing.d.ts +16 -0
- package/dist/ai/baml_client/tracing.js +18 -0
- package/dist/ai/baml_client/type_builder.d.ts +38 -0
- package/dist/ai/baml_client/type_builder.js +96 -0
- package/dist/ai/baml_client/types.d.ts +69 -0
- package/dist/ai/baml_client/types.js +15 -0
- package/dist/ai/claudeCode.d.ts +1 -0
- package/dist/ai/claudeCode.js +186 -0
- package/dist/ai/modelHarness.d.ts +39 -0
- package/dist/ai/modelHarness.js +189 -0
- package/dist/ai/multiModelHarness.d.ts +27 -0
- package/dist/ai/multiModelHarness.js +52 -0
- package/dist/ai/types.d.ts +90 -0
- package/dist/ai/types.js +5 -0
- package/dist/ai/util.d.ts +13 -0
- package/dist/ai/util.js +165 -0
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +3 -0
- package/dist/common/actions.d.ts +0 -0
- package/dist/common/actions.js +14 -0
- package/dist/common/events.d.ts +15 -0
- package/dist/common/events.js +3 -0
- package/dist/common/failure.d.ts +68 -0
- package/dist/common/failure.js +1 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/retry.d.ts +16 -0
- package/dist/common/retry.js +30 -0
- package/dist/common/util.d.ts +23 -0
- package/dist/common/util.js +132 -0
- package/dist/connectors/browserConnector.d.ts +40 -0
- package/dist/connectors/browserConnector.js +127 -0
- package/dist/connectors/desktopConnector.d.ts +58 -0
- package/dist/connectors/desktopConnector.js +68 -0
- package/dist/connectors/index.d.ts +10 -0
- package/dist/connectors/index.js +2 -0
- package/dist/index.cjs +6143 -0
- package/dist/index.d.cts +825 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +26 -0
- package/dist/index.mjs +6097 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.js +15 -0
- package/dist/memory/agentMemory.d.ts +37 -0
- package/dist/memory/agentMemory.js +121 -0
- package/dist/memory/image.d.ts +26 -0
- package/dist/memory/image.js +106 -0
- package/dist/memory/index.d.ts +3 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/masking.d.ts +7 -0
- package/dist/memory/masking.js +141 -0
- package/dist/memory/masking.test.d.ts +1 -0
- package/dist/memory/masking.test.js +117 -0
- package/dist/memory/observation.d.ts +38 -0
- package/dist/memory/observation.js +79 -0
- package/dist/memory/rendering/index.d.ts +10 -0
- package/dist/memory/rendering/index.js +13 -0
- package/dist/memory/rendering/renderJsonParts.d.ts +3 -0
- package/dist/memory/rendering/renderJsonParts.js +115 -0
- package/dist/memory/rendering/renderJsonParts.test.d.ts +1 -0
- package/dist/memory/rendering/renderJsonParts.test.js +217 -0
- package/dist/memory/rendering/renderXmlParts.d.ts +7 -0
- package/dist/memory/rendering/renderXmlParts.js +127 -0
- package/dist/memory/serde.d.ts +20 -0
- package/dist/memory/serde.js +81 -0
- package/dist/memory/util.d.ts +2 -0
- package/dist/memory/util.js +17 -0
- package/dist/telemetry/events.d.ts +9 -0
- package/dist/telemetry/events.js +80 -0
- package/dist/telemetry/index.d.ts +6 -0
- package/dist/telemetry/index.js +91 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.js +1 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +12 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/web/browserProvider.d.ts +23 -0
- package/dist/web/browserProvider.js +153 -0
- package/dist/web/harness.d.ts +102 -0
- package/dist/web/harness.js +340 -0
- package/dist/web/stability.d.ts +57 -0
- package/dist/web/stability.js +316 -0
- package/dist/web/tabs.d.ts +58 -0
- package/dist/web/tabs.js +293 -0
- package/dist/web/transformer.d.ts +7 -0
- package/dist/web/transformer.js +41 -0
- package/dist/web/types.d.ts +32 -0
- package/dist/web/types.js +2 -0
- package/dist/web/util.d.ts +3 -0
- package/dist/web/util.js +81 -0
- package/dist/web/visualizer/cursor.d.ts +16 -0
- package/dist/web/visualizer/cursor.js +152 -0
- package/dist/web/visualizer/index.d.ts +22 -0
- package/dist/web/visualizer/index.js +47 -0
- package/dist/web/visualizer/mouseEffects.d.ts +18 -0
- package/dist/web/visualizer/mouseEffects.js +287 -0
- package/dist/web/visualizer/typeEffects.d.ts +10 -0
- package/dist/web/visualizer/typeEffects.js +190 -0
- package/package.json +71 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
//import { Observation, BamlRenderable } from "@/memory";
|
|
2
|
+
import { WebHarness } from "@/web/harness";
|
|
3
|
+
import { webActions } from '@/actions/webActions';
|
|
4
|
+
import { BrowserProvider } from "@/web/browserProvider";
|
|
5
|
+
import logger from "@/logger";
|
|
6
|
+
import { Observation } from "@/memory/observation";
|
|
7
|
+
// export type BrowserOptions = ({ instance: Browser } | { launchOptions?: LaunchOptions }) & {
|
|
8
|
+
// contextOptions?: BrowserContextOptions;
|
|
9
|
+
// };
|
|
10
|
+
// const foo: BrowserOptions = {
|
|
11
|
+
// launchOptions: {},
|
|
12
|
+
// instance: {},
|
|
13
|
+
// }
|
|
14
|
+
// Changed back to 3 - too many situations where the amnesia of having only 1 is very problematic and makes agent act stupidly
|
|
15
|
+
// With caching, using 3 is relatively ok tradeoff
|
|
16
|
+
// Maybe try 2 for now, or could do 3 when prompt caching available else 2
|
|
17
|
+
const DEFAULT_MIN_RETAINED_SCREENSHOTS = 2;
|
|
18
|
+
export class BrowserConnector {
|
|
19
|
+
id = "web";
|
|
20
|
+
harness;
|
|
21
|
+
options;
|
|
22
|
+
browser;
|
|
23
|
+
context;
|
|
24
|
+
logger;
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
// console.log("options", options)
|
|
27
|
+
// console.log("options.screenshotMemoryLimit", options.screenshotMemoryLimit)
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.logger = logger.child({
|
|
30
|
+
name: `connectors.${this.id}`
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async onStart() {
|
|
34
|
+
this.logger.info("Starting...");
|
|
35
|
+
this.logger.info("Creating new browser context.");
|
|
36
|
+
this.context = await BrowserProvider.getInstance().newContext(this.options.browser);
|
|
37
|
+
//const contextOptions = this.options.browser && 'contextOptions' in this.options.browser ? this.options.browser.contextOptions : {};
|
|
38
|
+
this.harness = new WebHarness(this.context, {
|
|
39
|
+
//fallbackViewportDimensions: contextOptions?.viewport ?? { width: 1024, height: 768 },
|
|
40
|
+
virtualScreenDimensions: this.options.virtualScreenDimensions,
|
|
41
|
+
visuals: this.options.visuals
|
|
42
|
+
});
|
|
43
|
+
await this.harness.start();
|
|
44
|
+
this.logger.info("WebHarness started.");
|
|
45
|
+
if (this.options.url) {
|
|
46
|
+
this.logger.info(`Navigating to initial URL: ${this.options.url}`);
|
|
47
|
+
await this.harness.navigate(this.options.url);
|
|
48
|
+
//await this.harness.waitForStability();
|
|
49
|
+
}
|
|
50
|
+
this.logger.info("Started successfully.");
|
|
51
|
+
}
|
|
52
|
+
async onStop() {
|
|
53
|
+
this.logger.info("Stopping...");
|
|
54
|
+
if (this.harness) {
|
|
55
|
+
await this.harness.stop();
|
|
56
|
+
this.logger.info("WebHarness cleaned up.");
|
|
57
|
+
}
|
|
58
|
+
if (this.context) {
|
|
59
|
+
await this.context.close();
|
|
60
|
+
this.logger.info("Browser context closed.");
|
|
61
|
+
}
|
|
62
|
+
// Note: We don't close this.browser here if obtained from BrowserProvider,
|
|
63
|
+
// as BrowserProvider manages the singleton browser lifecycle.
|
|
64
|
+
// If this.options.browser was provided, its lifecycle is managed externally.
|
|
65
|
+
this.logger.info("Stopped successfully.");
|
|
66
|
+
}
|
|
67
|
+
getActionSpace() {
|
|
68
|
+
return [...webActions];
|
|
69
|
+
}
|
|
70
|
+
// public get page(): Page {
|
|
71
|
+
// if (!this.harness || !this.harness.page) {
|
|
72
|
+
// throw new Error("WebInteractionConnector: Harness or Page is not available. Ensure onStart has completed.");
|
|
73
|
+
// }
|
|
74
|
+
// return this.harness.page;
|
|
75
|
+
// }
|
|
76
|
+
getHarness() {
|
|
77
|
+
if (!this.harness) {
|
|
78
|
+
throw new Error("WebInteractionConnector: Harness is not available. Ensure onStart has completed.");
|
|
79
|
+
}
|
|
80
|
+
return this.harness;
|
|
81
|
+
}
|
|
82
|
+
async captureCurrentState() {
|
|
83
|
+
if (!this.harness || !this.harness.page) {
|
|
84
|
+
throw new Error("WebInteractionConnector: Harness or Page is not available for capturing state.");
|
|
85
|
+
}
|
|
86
|
+
const [screenshot, tabs] = await Promise.all([
|
|
87
|
+
this.harness.screenshot(),
|
|
88
|
+
this.harness.retrieveTabState()
|
|
89
|
+
]);
|
|
90
|
+
//const resizedScreenshot = await screenshot.resize()
|
|
91
|
+
// if (this.options.autoResize) {
|
|
92
|
+
// return { screenshot: await screenshot.resize(this.options.autoResize.width, this.options.autoResize.height), tabs: tabs };
|
|
93
|
+
// }
|
|
94
|
+
return { screenshot: await this.transformScreenshot(screenshot), tabs: tabs };
|
|
95
|
+
}
|
|
96
|
+
async transformScreenshot(screenshot) {
|
|
97
|
+
if (this.options.virtualScreenDimensions) {
|
|
98
|
+
return await screenshot.resize(this.options.virtualScreenDimensions.width, this.options.virtualScreenDimensions.height);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return screenshot;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async getLastScreenshot() {
|
|
105
|
+
//return { image: "", dimensions: { width: 0, height: 0 } };
|
|
106
|
+
// TODO: better to use last
|
|
107
|
+
return (await this.captureCurrentState()).screenshot;
|
|
108
|
+
}
|
|
109
|
+
async collectObservations() {
|
|
110
|
+
const currentState = await this.captureCurrentState();
|
|
111
|
+
const observations = [];
|
|
112
|
+
const currentTabs = currentState.tabs;
|
|
113
|
+
let tabInfo = "Open Tabs:\n";
|
|
114
|
+
currentTabs.tabs.forEach((tab, index) => {
|
|
115
|
+
tabInfo += `${index === currentTabs.activeTab ? '[ACTIVE] ' : ''}${tab.title} (${tab.url})`;
|
|
116
|
+
});
|
|
117
|
+
//console.log("this.options.screenshotMemoryLimit", this.options.screenshotMemoryLimit);
|
|
118
|
+
const screenshotLimit = this.options.minScreenshots ?? DEFAULT_MIN_RETAINED_SCREENSHOTS;
|
|
119
|
+
//console.log("screenshotLimit:", screenshotLimit);
|
|
120
|
+
observations.push(Observation.fromConnector(this.id, await this.transformScreenshot(currentState.screenshot), { type: 'screenshot', limit: screenshotLimit, dedupe: true }));
|
|
121
|
+
observations.push(Observation.fromConnector(this.id, tabInfo, { type: 'tabinfo', limit: 1 }));
|
|
122
|
+
return observations;
|
|
123
|
+
}
|
|
124
|
+
async getInstructions() {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AgentConnector } from ".";
|
|
2
|
+
import { ActionDefinition } from '@/actions';
|
|
3
|
+
import { Observation } from "@/memory/observation";
|
|
4
|
+
/**
|
|
5
|
+
* Generic desktop automation interface.
|
|
6
|
+
* Implementations can use any desktop automation technology
|
|
7
|
+
* (Lume, PyAutoGUI, Windows UI Automation, etc.)
|
|
8
|
+
*/
|
|
9
|
+
export interface DesktopInterface {
|
|
10
|
+
click(x: number, y: number): Promise<void>;
|
|
11
|
+
rightClick(x: number, y: number): Promise<void>;
|
|
12
|
+
doubleClick(x: number, y: number): Promise<void>;
|
|
13
|
+
moveCursor(x: number, y: number): Promise<void>;
|
|
14
|
+
drag(fromX: number, fromY: number, toX: number, toY: number): Promise<void>;
|
|
15
|
+
scroll(x: number, y: number, deltaX: number, deltaY: number): Promise<void>;
|
|
16
|
+
type(text: string): Promise<void>;
|
|
17
|
+
key(key: string): Promise<void>;
|
|
18
|
+
hotkey(keys: string[]): Promise<void>;
|
|
19
|
+
screenshot(): Promise<Buffer>;
|
|
20
|
+
getScreenSize(): Promise<{
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}>;
|
|
24
|
+
navigate?(url: string): Promise<void>;
|
|
25
|
+
getActiveWindow?(): Promise<{
|
|
26
|
+
title: string;
|
|
27
|
+
app: string;
|
|
28
|
+
}>;
|
|
29
|
+
getOpenWindows?(): Promise<Array<{
|
|
30
|
+
title: string;
|
|
31
|
+
app: string;
|
|
32
|
+
isActive: boolean;
|
|
33
|
+
}>>;
|
|
34
|
+
focusWindow?(title: string): Promise<void>;
|
|
35
|
+
openApplication?(name: string): Promise<void>;
|
|
36
|
+
closeApplication?(name: string): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export interface DesktopConnectorOptions {
|
|
39
|
+
desktopInterface: DesktopInterface;
|
|
40
|
+
virtualScreenDimensions?: {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
};
|
|
44
|
+
minScreenshots?: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class DesktopConnector implements AgentConnector {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
private desktopInterface;
|
|
49
|
+
private options;
|
|
50
|
+
private logger;
|
|
51
|
+
constructor(options: DesktopConnectorOptions);
|
|
52
|
+
onStart(): Promise<void>;
|
|
53
|
+
onStop(): Promise<void>;
|
|
54
|
+
getActionSpace(): ActionDefinition<any>[];
|
|
55
|
+
collectObservations(): Promise<Observation[]>;
|
|
56
|
+
private formatWindowInfo;
|
|
57
|
+
getInterface(): DesktopInterface;
|
|
58
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { desktopActions } from '@/actions/desktopActions';
|
|
2
|
+
import { Observation } from "@/memory/observation";
|
|
3
|
+
import { Image } from "@/memory/image";
|
|
4
|
+
import logger from "@/logger";
|
|
5
|
+
import sharp from 'sharp';
|
|
6
|
+
export class DesktopConnector {
|
|
7
|
+
id = "desktop";
|
|
8
|
+
desktopInterface;
|
|
9
|
+
options;
|
|
10
|
+
logger;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.desktopInterface = options.desktopInterface;
|
|
14
|
+
this.logger = logger.child({
|
|
15
|
+
name: `connectors.${this.id}`
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async onStart() {
|
|
19
|
+
// Desktop interface should already be initialized by the service
|
|
20
|
+
this.logger.info("Desktop connector started");
|
|
21
|
+
}
|
|
22
|
+
async onStop() {
|
|
23
|
+
// Cleanup handled by the interface provider
|
|
24
|
+
this.logger.info("Desktop connector stopped");
|
|
25
|
+
}
|
|
26
|
+
getActionSpace() {
|
|
27
|
+
return desktopActions;
|
|
28
|
+
}
|
|
29
|
+
async collectObservations() {
|
|
30
|
+
const observations = [];
|
|
31
|
+
// Always collect screenshot
|
|
32
|
+
const screenshot = await this.desktopInterface.screenshot();
|
|
33
|
+
const sharpImage = sharp(screenshot);
|
|
34
|
+
const image = new Image(sharpImage);
|
|
35
|
+
// Apply virtual screen dimensions if configured
|
|
36
|
+
const transformedImage = this.options.virtualScreenDimensions
|
|
37
|
+
? await image.resize(this.options.virtualScreenDimensions.width, this.options.virtualScreenDimensions.height)
|
|
38
|
+
: image;
|
|
39
|
+
observations.push(Observation.fromConnector(this.id, transformedImage, {
|
|
40
|
+
type: 'screenshot',
|
|
41
|
+
limit: this.options.minScreenshots ?? 2,
|
|
42
|
+
dedupe: true
|
|
43
|
+
}));
|
|
44
|
+
// Optional: Window information
|
|
45
|
+
if (this.desktopInterface.getOpenWindows) {
|
|
46
|
+
try {
|
|
47
|
+
const windows = await this.desktopInterface.getOpenWindows();
|
|
48
|
+
const windowInfo = this.formatWindowInfo(windows);
|
|
49
|
+
observations.push(Observation.fromConnector(this.id, windowInfo, { type: 'window-info', limit: 1 }));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.logger.warn('Failed to get window information', error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return observations;
|
|
56
|
+
}
|
|
57
|
+
formatWindowInfo(windows) {
|
|
58
|
+
let info = "Open Windows:\n";
|
|
59
|
+
windows.forEach(window => {
|
|
60
|
+
info += `${window.isActive ? '[ACTIVE] ' : ''}${window.title} (${window.app})\n`;
|
|
61
|
+
});
|
|
62
|
+
return info;
|
|
63
|
+
}
|
|
64
|
+
// Expose interface for actions to use
|
|
65
|
+
getInterface() {
|
|
66
|
+
return this.desktopInterface;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionDefinition } from '@/actions';
|
|
2
|
+
import { Observation } from '@/memory/observation';
|
|
3
|
+
export interface AgentConnector {
|
|
4
|
+
id: string;
|
|
5
|
+
onStart?(): Promise<void>;
|
|
6
|
+
onStop?(): Promise<void>;
|
|
7
|
+
getActionSpace?(): ActionDefinition<any>[];
|
|
8
|
+
collectObservations?(): Promise<Observation[]>;
|
|
9
|
+
getInstructions?(): Promise<void | string>;
|
|
10
|
+
}
|