@hmharness/environments 0.19.0 → 0.19.2
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/bridges.d.ts +11 -0
- package/dist/bridges.js +51 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BrowserEnvOptions, DesktopEnvOptions } from './adapters.js';
|
|
2
|
+
export type ToolExecute = (toolName: string, args: Record<string, unknown>) => Promise<{
|
|
3
|
+
output: string;
|
|
4
|
+
isError?: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
/** Browser act bridge: navigate→browser_open, click/type→desktop trio. */
|
|
7
|
+
export declare function browserActBridge(execute: ToolExecute, opts?: {
|
|
8
|
+
cdpBase?: string;
|
|
9
|
+
}): NonNullable<BrowserEnvOptions['act']>;
|
|
10
|
+
/** Desktop act bridge: click/type/hotkey → the desktop trio. */
|
|
11
|
+
export declare function desktopActBridge(execute: ToolExecute): NonNullable<DesktopEnvOptions['act']>;
|
package/dist/bridges.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function toResult(action, started) {
|
|
2
|
+
return (r) => ({
|
|
3
|
+
actionId: action.id,
|
|
4
|
+
outcome: r.isError ? 'failure' : 'success',
|
|
5
|
+
error: r.isError ? { code: 'E_TOOL', message: r.output.slice(0, 300) } : undefined,
|
|
6
|
+
output: r.output.slice(0, 2_000),
|
|
7
|
+
durationMs: Date.now() - started,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** Browser act bridge: navigate→browser_open, click/type→desktop trio. */
|
|
11
|
+
export function browserActBridge(execute, opts) {
|
|
12
|
+
return async (action, _tabId) => {
|
|
13
|
+
const started = Date.now();
|
|
14
|
+
const done = toResult(action, started);
|
|
15
|
+
switch (action.type) {
|
|
16
|
+
case 'navigate':
|
|
17
|
+
return done(await execute('browser_open', { url: String(action.args.url ?? '') }));
|
|
18
|
+
case 'click':
|
|
19
|
+
// visible-browser workflow: coordinate click through the desktop trio
|
|
20
|
+
return done(await execute('desktop_click', { x: Number(action.args.x ?? 0), y: Number(action.args.y ?? 0) }));
|
|
21
|
+
case 'type':
|
|
22
|
+
return done(await execute('desktop_type', { text: String(action.args.text ?? '') }));
|
|
23
|
+
default:
|
|
24
|
+
return { outcome: 'failure', error: { code: 'E_UNKNOWN_ACTION', message: `unknown browser action ${action.type}` } };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Desktop act bridge: click/type/hotkey → the desktop trio. */
|
|
29
|
+
export function desktopActBridge(execute) {
|
|
30
|
+
return async (action) => {
|
|
31
|
+
const started = Date.now();
|
|
32
|
+
const done = toResult(action, started);
|
|
33
|
+
switch (action.type) {
|
|
34
|
+
case 'desktop-click':
|
|
35
|
+
return done(await execute('desktop_click', { x: Number(action.args.x ?? 0), y: Number(action.args.y ?? 0) }));
|
|
36
|
+
case 'desktop-type':
|
|
37
|
+
return done(await execute('desktop_type', { text: String(action.args.text ?? '') }));
|
|
38
|
+
case 'desktop-hotkey': {
|
|
39
|
+
// the trio has no hotkey primitive; compose: type with modifiers is
|
|
40
|
+
// tool-specific, so route plain text and reject combos honestly
|
|
41
|
+
const combo = String(action.args.combo ?? '');
|
|
42
|
+
if (combo.includes('+')) {
|
|
43
|
+
return { outcome: 'failure', error: { code: 'E_UNSUPPORTED', message: `hotkey combos need a dedicated tool; got ${combo}` } };
|
|
44
|
+
}
|
|
45
|
+
return done(await execute('desktop_type', { text: combo }));
|
|
46
|
+
}
|
|
47
|
+
default:
|
|
48
|
+
return { outcome: 'failure', error: { code: 'E_UNKNOWN_ACTION', message: `unknown desktop action ${action.type}` } };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,3 +12,5 @@ export { HarmonyOsEnvironment } from './harmonyos.js';
|
|
|
12
12
|
export type { HarmonyOsEnvOptions } from './harmonyos.js';
|
|
13
13
|
export { BrowserEnvironment, DesktopEnvironment, Arc3Environment } from './adapters.js';
|
|
14
14
|
export type { BrowserEnvOptions, DesktopEnvOptions, Arc3EnvOptions } from './adapters.js';
|
|
15
|
+
export { browserActBridge, desktopActBridge } from './bridges.js';
|
|
16
|
+
export type { ToolExecute } from './bridges.js';
|
package/dist/index.js
CHANGED
|
@@ -9,3 +9,4 @@
|
|
|
9
9
|
export { TerminalEnvironment, runShell } from "./terminal.js";
|
|
10
10
|
export { HarmonyOsEnvironment } from "./harmonyos.js";
|
|
11
11
|
export { BrowserEnvironment, DesktopEnvironment, Arc3Environment } from "./adapters.js";
|
|
12
|
+
export { browserActBridge, desktopActBridge } from "./bridges.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/environments",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.2",
|
|
4
4
|
"description": "HMH Cognitive OS environment adapters: Terminal (native), HarmonyOS (via domain-harmony), Browser/Desktop (via host automation bridge), ARC3 (external adapter). Every adapter implements the @hmharness/cognitive Environment protocol and must pass the shared conformance test.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"node": ">=22"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@hmharness/kernel": "0.19.
|
|
30
|
-
"@hmharness/cognitive": "0.19.
|
|
29
|
+
"@hmharness/kernel": "0.19.2",
|
|
30
|
+
"@hmharness/cognitive": "0.19.2"
|
|
31
31
|
}
|
|
32
32
|
}
|