@0xmaxma/claude-gateway 2.1.8 → 2.1.10
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/agent/runner.d.ts +25 -4
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +4 -0
- package/dist/agent/runner.js.map +1 -1
- package/dist/api/connectors-router.d.ts.map +1 -1
- package/dist/api/connectors-router.js +27 -3
- package/dist/api/connectors-router.js.map +1 -1
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +14 -0
- package/dist/api/router.js.map +1 -1
- package/dist/automation/browser-outcome.d.ts +3 -1
- package/dist/automation/browser-outcome.d.ts.map +1 -1
- package/dist/automation/browser-outcome.js +2 -2
- package/dist/automation/browser-outcome.js.map +1 -1
- package/dist/automation/browser-trace.d.ts +1 -1
- package/dist/automation/command-speech.d.ts +9 -1
- package/dist/automation/command-speech.d.ts.map +1 -1
- package/dist/automation/command-speech.js +18 -0
- package/dist/automation/command-speech.js.map +1 -1
- package/dist/automation/command-steps.d.ts +2 -0
- package/dist/automation/command-steps.d.ts.map +1 -1
- package/dist/automation/command-steps.js +34 -2
- package/dist/automation/command-steps.js.map +1 -1
- package/dist/automation/computer-command.d.ts +1 -0
- package/dist/automation/computer-command.d.ts.map +1 -1
- package/dist/automation/computer-command.js +31 -5
- package/dist/automation/computer-command.js.map +1 -1
- package/dist/automation/computer-outcome.d.ts +26 -3
- package/dist/automation/computer-outcome.d.ts.map +1 -1
- package/dist/automation/computer-outcome.js +183 -13
- package/dist/automation/computer-outcome.js.map +1 -1
- package/dist/automation/computer-policy.d.ts +10 -1
- package/dist/automation/computer-policy.d.ts.map +1 -1
- package/dist/automation/computer-policy.js +20 -6
- package/dist/automation/computer-policy.js.map +1 -1
- package/dist/automation/computer-use.d.ts +34 -0
- package/dist/automation/computer-use.d.ts.map +1 -1
- package/dist/automation/computer-use.js +211 -17
- package/dist/automation/computer-use.js.map +1 -1
- package/dist/automation/direct-command.d.ts +8 -0
- package/dist/automation/direct-command.d.ts.map +1 -1
- package/dist/automation/direct-command.js +12 -0
- package/dist/automation/direct-command.js.map +1 -1
- package/dist/automation/model-choice-evaluator.d.ts +3 -0
- package/dist/automation/model-choice-evaluator.d.ts.map +1 -1
- package/dist/automation/model-choice-evaluator.js +3 -1
- package/dist/automation/model-choice-evaluator.js.map +1 -1
- package/dist/automation/vision-decider.d.ts +4 -2
- package/dist/automation/vision-decider.d.ts.map +1 -1
- package/dist/automation/vision-decider.js +69 -15
- package/dist/automation/vision-decider.js.map +1 -1
- package/dist/build-provenance.json +4 -4
- package/dist/connectors/custom-connectors-store.d.ts.map +1 -1
- package/dist/connectors/custom-connectors-store.js +6 -1
- package/dist/connectors/custom-connectors-store.js.map +1 -1
- package/dist/connectors/custom.d.ts +14 -0
- package/dist/connectors/custom.d.ts.map +1 -1
- package/dist/connectors/custom.js +43 -2
- package/dist/connectors/custom.js.map +1 -1
- package/dist/connectors/proxy.d.ts +8 -0
- package/dist/connectors/proxy.d.ts.map +1 -1
- package/dist/connectors/proxy.js +53 -5
- package/dist/connectors/proxy.js.map +1 -1
- package/dist/connectors/resolve.d.ts.map +1 -1
- package/dist/connectors/resolve.js +16 -2
- package/dist/connectors/resolve.js.map +1 -1
- package/dist/connectors/sidecar.d.ts +131 -0
- package/dist/connectors/sidecar.d.ts.map +1 -0
- package/dist/connectors/sidecar.js +768 -0
- package/dist/connectors/sidecar.js.map +1 -0
- package/dist/connectors/token-env.d.ts +2 -0
- package/dist/connectors/token-env.d.ts.map +1 -1
- package/dist/connectors/token-env.js +16 -0
- package/dist/connectors/token-env.js.map +1 -1
- package/dist/connectors/types.d.ts +4 -0
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/connectors/uv-runtime.d.ts +37 -0
- package/dist/connectors/uv-runtime.d.ts.map +1 -0
- package/dist/connectors/uv-runtime.js +236 -0
- package/dist/connectors/uv-runtime.js.map +1 -0
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/jev/browser-contract.d.ts +3 -0
- package/dist/jev/browser-contract.d.ts.map +1 -1
- package/dist/jev/browser-contract.js +6 -0
- package/dist/jev/browser-contract.js.map +1 -1
- package/dist/jev/browser-evidence-summary.d.ts +1 -1
- package/dist/orchestration/agent-tool-schemas.d.ts +18 -0
- package/dist/orchestration/agent-tool-schemas.d.ts.map +1 -1
- package/dist/orchestration/agent-tool-schemas.js +11 -3
- package/dist/orchestration/agent-tool-schemas.js.map +1 -1
- package/dist/orchestration/bridge.d.ts.map +1 -1
- package/dist/orchestration/bridge.js +25 -5
- package/dist/orchestration/bridge.js.map +1 -1
- package/dist/orchestration/browser-routing.d.ts.map +1 -1
- package/dist/orchestration/browser-routing.js +2 -1
- package/dist/orchestration/browser-routing.js.map +1 -1
- package/dist/orchestration/computer-decisions.d.ts +1 -1
- package/dist/orchestration/computer-decisions.d.ts.map +1 -1
- package/dist/orchestration/computer-decisions.js +21 -7
- package/dist/orchestration/computer-decisions.js.map +1 -1
- package/dist/orchestration/computer-live.d.ts +62 -0
- package/dist/orchestration/computer-live.d.ts.map +1 -0
- package/dist/orchestration/computer-live.js +126 -0
- package/dist/orchestration/computer-live.js.map +1 -0
- package/dist/orchestration/connector-context.d.ts +17 -0
- package/dist/orchestration/connector-context.d.ts.map +1 -0
- package/dist/orchestration/connector-context.js +56 -0
- package/dist/orchestration/connector-context.js.map +1 -0
- package/dist/orchestration/container-tool-schemas.d.ts.map +1 -1
- package/dist/orchestration/container-tool-schemas.js +3 -0
- package/dist/orchestration/container-tool-schemas.js.map +1 -1
- package/dist/orchestration/decisions.d.ts +3 -1
- package/dist/orchestration/decisions.d.ts.map +1 -1
- package/dist/orchestration/decisions.js +4 -2
- package/dist/orchestration/decisions.js.map +1 -1
- package/dist/orchestration/gateway-tasks/browser.d.ts +1 -1
- package/dist/orchestration/gateway-tasks/browser.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/browser.js +4 -3
- package/dist/orchestration/gateway-tasks/browser.js.map +1 -1
- package/dist/orchestration/gateway-tasks/computer-context.d.ts +4 -1
- package/dist/orchestration/gateway-tasks/computer-context.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/computer-context.js +3 -1
- package/dist/orchestration/gateway-tasks/computer-context.js.map +1 -1
- package/dist/orchestration/gateway-tasks/computer.d.ts +78 -15
- package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/computer.js +298 -31
- package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
- package/dist/orchestration/gateway-tasks/controller.d.ts +14 -2
- package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/controller.js +63 -2
- package/dist/orchestration/gateway-tasks/controller.js.map +1 -1
- package/dist/orchestration/notification-mailbox.js +3 -3
- package/dist/orchestration/notification-mailbox.js.map +1 -1
- package/dist/orchestration/process-turn.d.ts.map +1 -1
- package/dist/orchestration/process-turn.js +4 -1
- package/dist/orchestration/process-turn.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +22 -1
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +87 -7
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/task-controls.d.ts +8 -0
- package/dist/orchestration/task-controls.d.ts.map +1 -1
- package/dist/orchestration/task-controls.js +3 -2
- package/dist/orchestration/task-controls.js.map +1 -1
- package/dist/orchestration/tasks/automation-session.d.ts +42 -11
- package/dist/orchestration/tasks/automation-session.d.ts.map +1 -1
- package/dist/orchestration/tasks/automation-session.js +101 -21
- package/dist/orchestration/tasks/automation-session.js.map +1 -1
- package/dist/orchestration/tasks/driver.d.ts.map +1 -1
- package/dist/orchestration/tasks/driver.js +4 -0
- package/dist/orchestration/tasks/driver.js.map +1 -1
- package/dist/orchestration/tasks/service.d.ts +23 -0
- package/dist/orchestration/tasks/service.d.ts.map +1 -1
- package/dist/orchestration/tasks/service.js +120 -12
- package/dist/orchestration/tasks/service.js.map +1 -1
- package/dist/orchestration/telegram-tool-status.d.ts.map +1 -1
- package/dist/orchestration/telegram-tool-status.js +2 -0
- package/dist/orchestration/telegram-tool-status.js.map +1 -1
- package/dist/orchestration/types.d.ts +19 -0
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/types.js.map +1 -1
- package/dist/session/managed-connectors.d.ts +2 -0
- package/dist/session/managed-connectors.d.ts.map +1 -1
- package/dist/session/managed-connectors.js +9 -4
- package/dist/session/managed-connectors.js.map +1 -1
- package/dist/session/process.d.ts +3 -0
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +21 -3
- package/dist/session/process.js.map +1 -1
- package/dist/session/runtime-profile.d.ts +2 -0
- package/dist/session/runtime-profile.d.ts.map +1 -1
- package/dist/session/runtime-profile.js.map +1 -1
- package/dist/ui/voice-call-client.d.ts +3 -0
- package/dist/ui/voice-call-client.d.ts.map +1 -1
- package/dist/ui/voice-call-client.js +10 -1
- package/dist/ui/voice-call-client.js.map +1 -1
- package/dist/voice/errors.d.ts +1 -1
- package/dist/voice/errors.js +1 -1
- package/dist/voice/errors.js.map +1 -1
- package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -1
- package/dist/voice/providers/elevenlabs-tts.js +17 -1
- package/dist/voice/providers/elevenlabs-tts.js.map +1 -1
- package/dist/voice/providers/socket.js +25 -6
- package/dist/voice/providers/socket.js.map +1 -1
- package/dist/voice/session.js +3 -2
- package/dist/voice/session.js.map +1 -1
- package/mcp/fixtures/workspace-mcp-tools.json +260 -0
- package/mcp/lazy-tools.test.ts +137 -1
- package/mcp/lazy-tools.ts +40 -7
- package/mcp/server.ts +1 -1
- package/mcp/tools/tasks/module.ts +2 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.confirmationTarget = exports.jevValidationReason = exports.ComputerObservation = exports.STANDARD_SHORTCUTS = exports.COMPUTER_USE_CONTRACT_VERSION = void 0;
|
|
3
|
+
exports.confirmationTarget = exports.DEVICE_RECONNECT_GRACE_MS = exports.jevValidationReason = exports.ComputerObservation = exports.STANDARD_SHORTCUTS = exports.COMPUTER_USE_CONTRACT_VERSION = void 0;
|
|
4
|
+
exports.reconnecting = reconnecting;
|
|
5
|
+
exports.namedApp = namedApp;
|
|
4
6
|
exports.confirmationReply = confirmationReply;
|
|
5
7
|
exports.runComputerUse = runComputerUse;
|
|
6
8
|
const computer_command_1 = require("./computer-command");
|
|
@@ -14,6 +16,13 @@ const zod_1 = require("zod");
|
|
|
14
16
|
const index_cjs_1 = require("../../lib/automation/index.cjs");
|
|
15
17
|
exports.COMPUTER_USE_CONTRACT_VERSION = 1;
|
|
16
18
|
const REDECIDE_MAX = 2, REDECIDE_DELAY_MS = 1000;
|
|
19
|
+
/** After a fast path submits an address or navigates, the page is looked at again this often, up to this long, until
|
|
20
|
+
* its title (or the application) differs from before: Chrome still showed the old page 1.5 s after Enter
|
|
21
|
+
* (pod-jinawong r10, task f40127bd: GOAL_REACHED on "Download History" while Steam loaded). */
|
|
22
|
+
const NAVIGATION_POLL_MS = 500, NAVIGATION_SETTLE_MS = 6000;
|
|
23
|
+
/** Internal loop guards of a run with no action limit, from its time budget: a cycle (observe and decide) and a
|
|
24
|
+
* thinking call each take at least this long, so the run's own timeout ends it first. */
|
|
25
|
+
const MIN_CYCLE_MS = 500, MIN_THINKING_MS = 5000;
|
|
17
26
|
// Relay errors raised before an operation is recorded (getpod-computer-use
|
|
18
27
|
// relay.ts execute). DEVICE_OFFLINE can also follow the record, so it becomes
|
|
19
28
|
// not_executed only when the receipt lookup confirms no operation exists.
|
|
@@ -37,7 +46,11 @@ const contractMajor = (value) => typeof value === 'number' ? Math.trunc(value) :
|
|
|
37
46
|
const ControlBounds = zod_1.z.object({ x: zod_1.z.number().finite().min(0).max(1), y: zod_1.z.number().finite().min(0).max(1), width: zod_1.z.number().finite().positive().max(1), height: zod_1.z.number().finite().positive().max(1) }).refine(b => b.x + b.width <= 1.000001 && b.y + b.height <= 1.000001);
|
|
38
47
|
const Control = zod_1.z.object({ identity: zod_1.z.string().uuid().optional(), bounds: ControlBounds.optional(), ref: zod_1.z.string().min(1).max(100), label: nativeText(500), context: nativeText(500).optional(), role: zod_1.z.string().max(100), value: nativeText(2000).optional(), focused: zod_1.z.boolean().optional(), actions: known(['press', 'type']), sensitive: zod_1.z.boolean().optional() });
|
|
39
48
|
const ScrollArea = zod_1.z.object({ ref: zod_1.z.string().min(1).max(100), label: nativeText(500), bounds: zod_1.z.object({ x: zod_1.z.number().finite().min(0).max(1), y: zod_1.z.number().finite().min(0).max(1), width: zod_1.z.number().finite().positive().max(1), height: zod_1.z.number().finite().positive().max(1) }).refine(b => b.x + b.width <= 1.000001 && b.y + b.height <= 1.000001) });
|
|
40
|
-
exports.ComputerObservation = zod_1.z.object({ contractVersion: zod_1.z.union([zod_1.z.number(), zod_1.z.string().max(20)]).optional().catch(undefined), capabilities: zod_1.z.object({ standardCommands: zod_1.z.array(zod_1.z.string().max(100)).max(64).optional(), keys: zod_1.z.array(zod_1.z.string().max(40)).max(64).optional() }).optional().catch(undefined), standardCommand: zod_1.z.enum(['scroll:up', 'scroll:down', 'close:window', ...exports.STANDARD_SHORTCUTS]).optional().catch(undefined), scrollAreas: zod_1.z.array(ScrollArea).max(16).refine(rows => new Set(rows.map(r => r.ref)).size === rows.length).optional(), supportedActions: known(['scroll:up', 'scroll:down', 'navigate:back', 'navigate:forward'], 4).optional(), screenshotAvailable: zod_1.z.boolean().optional(), screenshotRestriction: zod_1.z.string().max(100).optional(),
|
|
49
|
+
exports.ComputerObservation = zod_1.z.object({ contractVersion: zod_1.z.union([zod_1.z.number(), zod_1.z.string().max(20)]).optional().catch(undefined), capabilities: zod_1.z.object({ standardCommands: zod_1.z.array(zod_1.z.string().max(100)).max(64).optional(), keys: zod_1.z.array(zod_1.z.string().max(40)).max(64).optional() }).optional().catch(undefined), standardCommand: zod_1.z.enum(['scroll:up', 'scroll:down', 'close:window', ...exports.STANDARD_SHORTCUTS]).optional().catch(undefined), scrollAreas: zod_1.z.array(ScrollArea).max(16).refine(rows => new Set(rows.map(r => r.ref)).size === rows.length).optional(), supportedActions: known(['scroll:up', 'scroll:down', 'navigate:back', 'navigate:forward'], 4).optional(), screenshotAvailable: zod_1.z.boolean().optional(), screenshotRestriction: zod_1.z.string().max(100).optional(),
|
|
50
|
+
// GetPod Desktop withholds the screen while a protected app (GetPod itself, where the user types) is frontmost:
|
|
51
|
+
// application "unapproved", no controls, and these two fields saying why. Kept so neither the model nor the
|
|
52
|
+
// agent reads it as the target app not being approved (pod-jinawong, task 2f65b7cf: "Spotify is not approved").
|
|
53
|
+
frontmostProtected: zod_1.z.boolean().optional().catch(undefined), reason: zod_1.z.string().max(300).optional().catch(undefined), observationStats: zod_1.z.object({ visited: zod_1.z.number().int().nonnegative(), candidates: zod_1.z.number().int().nonnegative(), exported: zod_1.z.number().int().nonnegative(), incomplete: zod_1.z.boolean() }).optional(), generation: zod_1.z.string().min(1), application: zod_1.z.string(), controls: zod_1.z.array(Control).max(150), focusedControl: zod_1.z.object({ ref: zod_1.z.string().max(100).optional(), role: zod_1.z.string().max(100), label: nativeText(500), sensitive: zod_1.z.boolean().optional() }).optional(), windowTitle: nativeText(500).optional(), text: zod_1.z.array(nativeText(300)).max(80).optional(), truncated: zod_1.z.boolean(), platform: zod_1.z.object({ os: zod_1.z.string(), osVersion: zod_1.z.string(), appVersion: zod_1.z.string().optional(), helperVersion: zod_1.z.string().max(100).optional(), helperBuild: zod_1.z.string().max(100).optional(), helperCommit: zod_1.z.string().max(100).optional() }).optional(), apps: zod_1.z.array(zod_1.z.object({ id: zod_1.z.string(), name: zod_1.z.string() })).max(100) }).transform(state => {
|
|
41
54
|
// A helper that reports a different major contract cannot be driven safely.
|
|
42
55
|
if (state.contractVersion !== undefined && contractMajor(state.contractVersion) !== exports.COMPUTER_USE_CONTRACT_VERSION)
|
|
43
56
|
throw Error('COMPUTER_CONTRACT_UNSUPPORTED');
|
|
@@ -47,9 +60,71 @@ exports.ComputerObservation = zod_1.z.object({ contractVersion: zod_1.z.union([z
|
|
|
47
60
|
const jevValidationReason = (error) => error instanceof types_1.JevError && typeof error.metadata.validationReason === 'string' && /^[A-Z][A-Z_]{0,39}$/.test(error.metadata.validationReason) ? error.metadata.validationReason : undefined;
|
|
48
61
|
exports.jevValidationReason = jevValidationReason;
|
|
49
62
|
const PreparedInput = zod_1.z.object({ application: zod_1.z.string().min(1).max(200), label: zod_1.z.string().min(1).max(500), text: zod_1.z.string().max(2000), role: zod_1.z.string().max(100).optional(), windowTitle: nativeText(500).optional() }).strict();
|
|
50
|
-
const Input = zod_1.z.object({ interactionContext: zod_1.z.string().max(8000).optional(), yieldAfterAction: zod_1.z.boolean().default(false), yieldAfterInteraction: zod_1.z.boolean().default(false), runToGoal: zod_1.z.boolean().default(false), resumeGoal: zod_1.z.number().int().min(1).max(100).optional(), readRequest: zod_1.z.boolean().default(false), agentCommand: zod_1.z.boolean().default(false), sessionStart: zod_1.z.boolean().default(false), confirmation: zod_1.z.object({ command: zod_1.z.string().min(1).max(2000), label: zod_1.z.string().max(250), target: zod_1.z.string().regex(/^[0-9a-f]{32}$/).optional(), reply: zod_1.z.enum(['YES', 'NO']).optional() }).strict().optional(), preparedInputs: zod_1.z.array(PreparedInput).max(30).default([]), goal: zod_1.z.string().min(1).max(16000), revision: zod_1.z.number().int().positive().default(1),
|
|
63
|
+
const Input = zod_1.z.object({ interactionContext: zod_1.z.string().max(8000).optional(), yieldAfterAction: zod_1.z.boolean().default(false), yieldAfterInteraction: zod_1.z.boolean().default(false), runToGoal: zod_1.z.boolean().default(false), resumeGoal: zod_1.z.union([zod_1.z.literal(true), zod_1.z.number().int().min(1).max(100)]).optional(), readRequest: zod_1.z.boolean().default(false), agentCommand: zod_1.z.boolean().default(false), sessionStart: zod_1.z.boolean().default(false), confirmation: zod_1.z.object({ command: zod_1.z.string().min(1).max(2000), label: zod_1.z.string().max(250), target: zod_1.z.string().regex(/^[0-9a-f]{32}$/).optional(), reply: zod_1.z.enum(['YES', 'NO']).optional() }).strict().optional(), preparedInputs: zod_1.z.array(PreparedInput).max(30).default([]), goal: zod_1.z.string().min(1).max(16000), revision: zod_1.z.number().int().positive().default(1),
|
|
64
|
+
/** An action limit; a goal run has none (its round time and the no-progress check end it), other runs default to 30. */
|
|
65
|
+
maxSteps: zod_1.z.number().int().min(1).max(100).optional(), timeoutMs: zod_1.z.number().int().min(1).max(600000).default(120000),
|
|
66
|
+
/** The task's last approved target application: a round that starts with a protected app (GetPod, where the user
|
|
67
|
+
* typed) in front opens it again first, so the screen is not withheld. Never the protected app itself. */
|
|
68
|
+
reactivate: zod_1.z.object({ id: zod_1.z.string().min(1).max(200), name: zod_1.z.string().max(200) }).strict().optional() }).strict();
|
|
51
69
|
const fingerprint = (s) => JSON.stringify([s.application, s.windowTitle, s.text, s.supportedActions, s.focusedControl && { role: s.focusedControl.role, label: s.focusedControl.label }, s.controls.map(({ ref, ...c }) => c), s.scrollAreas?.map(({ ref, ...area }) => area), s.truncated]);
|
|
52
70
|
const identity = (state, action) => { const field = state.controls.find(c => c.ref === action.ref), area = state.scrollAreas?.find(a => a.ref === action.ref); return JSON.stringify([state.application, state.windowTitle, action.kind, action.key, action.direction, action.app_id, field?.label, field?.role, area?.label, area?.bounds]); };
|
|
71
|
+
/** The page in front shows the site a goal's web address names: its title carries the host's main label. */
|
|
72
|
+
const urlShown = (state, web) => (state.windowTitle ?? '').toLocaleLowerCase().includes(web.label);
|
|
73
|
+
/** GetPod Desktop opens a new relay socket 3 s after one closes (its desktop-client.ts): a lease or a look that met the
|
|
74
|
+
* gap asks again for this long before the round says the computer is offline. Pod-jinawong r11, task ec82ed05: the
|
|
75
|
+
* socket closed at 04:31:11Z while computer_acquire waited, the app was back 4 s later, and the task had already failed
|
|
76
|
+
* as "the computer went offline". Reads only (the lease, an observation): an action is never sent twice. */
|
|
77
|
+
exports.DEVICE_RECONNECT_GRACE_MS = 12000;
|
|
78
|
+
const DEVICE_RECONNECT_RETRY_MS = 1000;
|
|
79
|
+
const RECONNECT_READS = new Set(['computer_acquire', 'computer_observe']);
|
|
80
|
+
async function reconnecting(name, read, signal, graceMs = exports.DEVICE_RECONNECT_GRACE_MS) {
|
|
81
|
+
const until = Date.now() + graceMs;
|
|
82
|
+
for (;;) {
|
|
83
|
+
try {
|
|
84
|
+
return await read();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (!RECONNECT_READS.has(name) || !(error instanceof Error) || error.message !== 'DEVICE_OFFLINE' || Date.now() + DEVICE_RECONNECT_RETRY_MS > until)
|
|
88
|
+
throw error;
|
|
89
|
+
await new Promise((resolve, reject) => { const stop = () => { clearTimeout(t); reject(error); }; const t = setTimeout(() => { signal.removeEventListener('abort', stop); resolve(); }, DEVICE_RECONNECT_RETRY_MS); signal.addEventListener('abort', stop, { once: true }); if (signal.aborted)
|
|
90
|
+
stop(); });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** The shape of a screen without its values: application, title and each control's identity, role and label. A chart's
|
|
95
|
+
* live price or a clock changes the text and values, not this. */
|
|
96
|
+
const structure = (s) => JSON.stringify([s.application, s.windowTitle, s.controls.map(c => [c.identity, c.role, c.label])]);
|
|
97
|
+
/** The one approved application a command names, for a round that starts with a protected app in front and no target
|
|
98
|
+
* from an earlier round: an app's name as a whole word, as it is cased (any case only for a name whose casing is
|
|
99
|
+
* distinctive: an inner capital, a digit or several words, e.g. TradingView, not Maps), else its bundle id. Two apps
|
|
100
|
+
* named, or one name inside another's match, picks the longer; still two is none. Structural: the device's own app
|
|
101
|
+
* list, no word list. */
|
|
102
|
+
function namedApp(text, apps) {
|
|
103
|
+
const edge = (c) => /[A-Za-z0-9]/.test(c) ? '[A-Za-z0-9]' : '[\\p{L}\\p{N}]';
|
|
104
|
+
const escape = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
105
|
+
const spans = [];
|
|
106
|
+
for (const app of apps) {
|
|
107
|
+
const name = app.name.trim();
|
|
108
|
+
if (name.length < 3 || name.length > 80)
|
|
109
|
+
continue;
|
|
110
|
+
const distinctive = /[A-Z0-9]/.test(name.slice(1)) || /\s/.test(name);
|
|
111
|
+
for (const [needle, flags] of [[name, 'gu'], ...(distinctive ? [[name, 'giu']] : []), [app.id, 'giu']]) {
|
|
112
|
+
if (!needle || needle.length < 3)
|
|
113
|
+
continue;
|
|
114
|
+
const re = new RegExp(`(?<!${edge(needle[0])})${escape(needle)}(?!${edge(needle.at(-1))})`, flags);
|
|
115
|
+
let hit = false;
|
|
116
|
+
for (const m of text.matchAll(re)) {
|
|
117
|
+
spans.push({ app, from: m.index, to: m.index + m[0].length });
|
|
118
|
+
hit = true;
|
|
119
|
+
}
|
|
120
|
+
if (hit)
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const kept = spans.filter(a => !spans.some(b => b !== a && b.app.id !== a.app.id && b.from <= a.from && b.to >= a.to && b.to - b.from > a.to - a.from));
|
|
125
|
+
const ids = new Set(kept.map(s => s.app.id));
|
|
126
|
+
return ids.size === 1 ? kept[0].app : undefined;
|
|
127
|
+
}
|
|
53
128
|
/** A high-impact action's exact target (kind, window, control and position), hashed: a yes covers only this. The vision
|
|
54
129
|
* loop hashes a click on an Accessibility control as its press, so a yes carries over when a run falls back here. */
|
|
55
130
|
const confirmationTarget = (state, action, planned) => { const control = state.controls.find(c => c.ref === planned?.ref); return (0, node_crypto_1.createHash)('sha256').update(JSON.stringify([action.split(':')[0], identity(state, planned ?? { kind: action }), control?.identity, control?.bounds, control?.context])).digest('hex').slice(0, 32); };
|
|
@@ -80,7 +155,7 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
80
155
|
deps.confirmed?.(reply);
|
|
81
156
|
// A yes to a goal's high-impact step resumes that goal, with a fresh step budget.
|
|
82
157
|
if (reply === 'YES')
|
|
83
|
-
input = { ...input, goal: input.confirmation.command, ...(input.resumeGoal ? { runToGoal: true, maxSteps: input.resumeGoal } : {}) };
|
|
158
|
+
input = { ...input, goal: input.confirmation.command, ...(input.resumeGoal ? { runToGoal: true, maxSteps: input.resumeGoal === true ? undefined : input.resumeGoal } : {}) };
|
|
84
159
|
// The resumed goal continues a run that already reached an action (the confirmed one):
|
|
85
160
|
// its step count restarts here, but it is past its first decision.
|
|
86
161
|
const resumed = reply === 'YES' && input.resumeGoal !== undefined;
|
|
@@ -109,6 +184,8 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
109
184
|
// at again after a second, up to twice, before the command returns unexecuted.
|
|
110
185
|
// Only while nothing of this command has run: a planned follow-up is never re-decided.
|
|
111
186
|
let redecided = 0;
|
|
187
|
+
// The screen's structure at the first WAIT of a run of WAITs (see `structure`).
|
|
188
|
+
let waitedOn;
|
|
112
189
|
const settleDelay = () => new Promise((resolve, reject) => { const stop = () => { clearTimeout(t); reject(Error('CANCELLED')); }; const t = setTimeout(() => { runSignal.removeEventListener('abort', stop); resolve(); }, REDECIDE_DELAY_MS); runSignal.addEventListener('abort', stop, { once: true }); });
|
|
113
190
|
// The re-decided command is planned again from scratch: a plan made for the
|
|
114
191
|
// rejected first input (remaining digits, Backspaces, a submit) must not resume.
|
|
@@ -121,6 +198,14 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
121
198
|
// next step is decided afresh on a new observation, impact- and
|
|
122
199
|
// confidence-gated, until DONE, a stop, or input.maxSteps actions.
|
|
123
200
|
const goalRun = direct && input.runToGoal;
|
|
201
|
+
// A goal run has no action limit; another run keeps its 30.
|
|
202
|
+
const stepCap = input.maxSteps ?? (goalRun ? undefined : 30);
|
|
203
|
+
// The page title (and application) before a fast path's address submit or navigation (see NAVIGATION_SETTLE_MS).
|
|
204
|
+
let navigationFrom;
|
|
205
|
+
// A web address the goal names: a DONE is checked against the page in front (see urlShown).
|
|
206
|
+
const webAddress = goalRun ? (0, direct_command_1.goalWebAddress)(input.goal) : undefined;
|
|
207
|
+
let addressTyped = false, addressRetried = false;
|
|
208
|
+
let reactivated = false;
|
|
124
209
|
// Fast paths match the whole command text, so they run only before the goal's
|
|
125
210
|
// first model-decided action (or while their own plan continues): a later
|
|
126
211
|
// step never re-runs the same grammar match.
|
|
@@ -185,7 +270,7 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
185
270
|
noProgress = 0;
|
|
186
271
|
goal = zod_1.z.object({ revision: zod_1.z.number().int().positive(), goal: zod_1.z.string().min(1).max(16000) }).parse(n);
|
|
187
272
|
} };
|
|
188
|
-
const call = async (name, args = {}) => { check(); return deps.call(name, { ...args, ...(lease ? { lease_token: lease } : {}) }, runSignal); };
|
|
273
|
+
const call = async (name, args = {}) => reconnecting(name, () => { check(); return deps.call(name, { ...args, ...(lease ? { lease_token: lease } : {}) }, runSignal); }, runSignal);
|
|
189
274
|
const summary = (action, state = last) => { const field = state?.controls.find(c => c.ref === action.ref); return { targetGeneration: state?.generation, application: state?.application, ...(typeof action.app_id === 'string' ? { appId: action.app_id } : {}), action: action.kind, ...(typeof action.key === 'string' ? { key: action.key } : {}), ...(field ? { ref: field.ref, role: field.role, focused: field.focused } : action.kind === 'key' && state?.focusedControl ? { role: state.focusedControl.role, focused: true } : {}) }; };
|
|
190
275
|
try {
|
|
191
276
|
(0, interrupt_1.checkInterruption)(deps.interruptSignal);
|
|
@@ -198,8 +283,8 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
198
283
|
}
|
|
199
284
|
lease = zod_1.z.object({ lease_token: zod_1.z.string().min(1) }).parse(acquisition).lease_token;
|
|
200
285
|
return await (0, index_cjs_1.runLoop)({
|
|
201
|
-
signal: runSignal, maxCycles:
|
|
202
|
-
thinking: !direct && deps.thinking ? (r, s) => (0, interrupt_1.interruptible)(child => deps.thinking(r, child), s, deps.interruptSignal) : undefined, maxThinkingCalls: input.
|
|
286
|
+
signal: runSignal, maxCycles: stepCap ? stepCap * 3 + 5 : Math.ceil(input.timeoutMs / MIN_CYCLE_MS) + 5, stageTimeoutMs: input.timeoutMs,
|
|
287
|
+
thinking: !direct && deps.thinking ? (r, s) => (0, interrupt_1.interruptible)(child => deps.thinking(r, child), s, deps.interruptSignal) : undefined, maxThinkingCalls: stepCap ?? Math.ceil(input.timeoutMs / MIN_THINKING_MS), thinkingTimeoutMs: 60000,
|
|
203
288
|
observe: async (ctx) => {
|
|
204
289
|
round = ctx.cycle + 1;
|
|
205
290
|
check();
|
|
@@ -256,6 +341,19 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
256
341
|
await capture();
|
|
257
342
|
return { result: waitForCommand('CONFIRMATION_DECLINED') };
|
|
258
343
|
}
|
|
344
|
+
// A protected app (GetPod, where the user typed) in front withholds the screen: the task's last approved target
|
|
345
|
+
// application is opened again first, once, before anything is decided on it. Pod-jinawong r10, task 457a4930: GetPod
|
|
346
|
+
// stayed in front, and the agent's next command worked in Chrome's Steam tab instead of TradingView.
|
|
347
|
+
// The app named by this command wins over the remembered target, using this computer's approved apps.
|
|
348
|
+
const named = state.frontmostProtected === true ? namedApp(goal.goal, state.apps) : undefined;
|
|
349
|
+
const mentionsOtherApp = state.frontmostProtected === true && state.apps.some(app => app.id !== input.reactivate?.id && namedApp(goal.goal, [app]));
|
|
350
|
+
const target = state.frontmostProtected === true ? named ?? (mentionsOtherApp ? undefined : input.reactivate) : undefined;
|
|
351
|
+
if (target && !reactivated && state.frontmostProtected === true && state.apps.some(app => app.id === target.id)) {
|
|
352
|
+
reactivated = true;
|
|
353
|
+
const action = { kind: 'open', app_id: target.id };
|
|
354
|
+
emit('decided', { ...summary(action, state), reason: 'REACTIVATE_TARGET' });
|
|
355
|
+
return { action: { action: 'reactivate', generation: state.generation, revision, targets: new Map([['reactivate', action]]), observedContinuation: true } };
|
|
356
|
+
}
|
|
259
357
|
// The agent's command reaches Jev on every path, so its impact is judged before any action.
|
|
260
358
|
const fast = !input.agentCommand;
|
|
261
359
|
const requestStandard = (command) => { standardRequest = command; return { action: { action: 'STANDARD_OBSERVE', generation: state.generation, revision, targets: new Map() } }; };
|
|
@@ -396,14 +494,17 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
396
494
|
}
|
|
397
495
|
const address = addressPending ?? (fastFailed ? undefined : appThenAddress ?? (named && (!named.app || browser) ? named.address : undefined));
|
|
398
496
|
appThenAddress = undefined;
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (address && !
|
|
497
|
+
// The browser's own address bar takes the address (address:focus) whenever the helper offers it: a field inside the
|
|
498
|
+
// page that looks like one is never guessed (pod-jinawong r10, task 457a4930: a URL typed into Steam's store search).
|
|
499
|
+
if (address && !addressPending && supports(state, 'address:focus')) {
|
|
402
500
|
addressPending = address;
|
|
403
501
|
return requestStandard('address:focus');
|
|
404
502
|
}
|
|
503
|
+
const fields = address && !addressPending ? (0, computer_command_1.addressFields)(state) : [];
|
|
504
|
+
let bar = addressPending ? (0, computer_safety_1.focusedTextField)(state) : fields.length === 1 ? fields[0] : undefined;
|
|
405
505
|
if (addressPending && !bar)
|
|
406
506
|
fastFailed = true;
|
|
507
|
+
const focusedBar = !!addressPending && !!bar;
|
|
407
508
|
addressPending = undefined;
|
|
408
509
|
if (address && !bar && fields.length > 1) {
|
|
409
510
|
const criteria = { NONE: 'None of these fields is the browser address bar' };
|
|
@@ -422,6 +523,8 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
422
523
|
}
|
|
423
524
|
if (address && bar) {
|
|
424
525
|
fastCommand = true;
|
|
526
|
+
navigationFrom = { title: state.windowTitle, application: state.application };
|
|
527
|
+
addressTyped || (addressTyped = focusedBar);
|
|
425
528
|
const action = { kind: 'type', ref: bar.ref };
|
|
426
529
|
emit('decided', summary(action, state));
|
|
427
530
|
return { action: { action: 'address', generation: state.generation, revision, targets: new Map([['address', action]]), literal: address, submit: true, observedContinuation: true } };
|
|
@@ -440,6 +543,7 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
440
543
|
const navigation = direct && asIssued ? (0, computer_command_1.standardNavigationCommand)(goal.goal) : undefined;
|
|
441
544
|
if (navigation && state.supportedActions?.includes(navigation)) {
|
|
442
545
|
fastCommand = true;
|
|
546
|
+
navigationFrom = { title: state.windowTitle, application: state.application };
|
|
443
547
|
const action = { kind: 'navigate', direction: navigation.split(':')[1] };
|
|
444
548
|
emit('decided', summary(action, state));
|
|
445
549
|
return { action: { action: 'navigate', generation: state.generation, revision, targets: new Map([['navigate', action]]), observedContinuation: true } };
|
|
@@ -504,9 +608,11 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
504
608
|
else
|
|
505
609
|
offer(id, kind === 'scroll' ? 'Scroll the observed area ' + direction : direction === 'back' ? 'Go back to the previous location in the current application' : 'Go forward to the next location in the current application history', { kind, direction });
|
|
506
610
|
}
|
|
611
|
+
// Three looks without a change, or a loop: the run pauses for the user (a goal round is not failed for it).
|
|
507
612
|
if (cycling || noProgress >= 3) {
|
|
613
|
+
emit('waiting', { reason: 'NO_PROGRESS' });
|
|
508
614
|
await capture();
|
|
509
|
-
return { result: result('needs_input', '
|
|
615
|
+
return { result: result('needs_input', 'NO_PROGRESS') };
|
|
510
616
|
}
|
|
511
617
|
if (submitAfterType) {
|
|
512
618
|
const expected = submitAfterType;
|
|
@@ -547,14 +653,21 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
547
653
|
// The screen was still changing: look again shortly and let Jev decide afresh.
|
|
548
654
|
fastCommand = false;
|
|
549
655
|
if (selected.action === 'WAIT') {
|
|
656
|
+
waitedOn ?? (waitedOn = structure(state));
|
|
550
657
|
if ((steps === 0 || goalRun) && redecided < REDECIDE_MAX) {
|
|
551
658
|
redecided++;
|
|
552
659
|
await settleDelay();
|
|
553
660
|
return { action: { action: 'STANDARD_OBSERVE', generation: state.generation, revision, targets: new Map() } };
|
|
554
661
|
}
|
|
662
|
+
// Nothing on the screen moved while it waited (its values may: a chart's price, a clock): there was no step it
|
|
663
|
+
// could take, as BLOCKED, and a goal round goes on from the screenshot (vision fallback). Pod-jinawong r11, task
|
|
664
|
+
// ec82ed05: three WAITs on a TradingView chart whose controls never changed ended as "the screen was still changing".
|
|
665
|
+
const still = waitedOn === structure(state);
|
|
666
|
+
waitedOn = undefined;
|
|
555
667
|
await capture();
|
|
556
|
-
return { result: waitForCommand('UI_NOT_READY') };
|
|
668
|
+
return { result: waitForCommand(still ? 'NO_SUPPORTED_ACTION' : 'UI_NOT_READY', still && input.yieldAfterInteraction && input.readRequest ? { decisionMode: mode() } : {}) };
|
|
557
669
|
}
|
|
670
|
+
waitedOn = undefined;
|
|
558
671
|
// Jev gave up on a single direct command (decisionMode jev marks it): the gateway may hand it to the agent once.
|
|
559
672
|
if (selected.action === 'BLOCKED' || selected.action === 'UNCLEAR') {
|
|
560
673
|
await capture();
|
|
@@ -660,6 +773,20 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
660
773
|
return direct ? result('cancelled', 'REVISION_SUPERSEDED') : undefined;
|
|
661
774
|
// A goal run's confident DONE ends the goal: the agent hears the result and
|
|
662
775
|
// the session closes. It is the model's judgement from the screen, not a verification.
|
|
776
|
+
// A goal that names a web address is done in a browser only when the page in front shows that site, or this run
|
|
777
|
+
// put the address into the browser's own address bar. Pod-jinawong r10, task 457a4930 rev5: the URL went into
|
|
778
|
+
// Steam's store search and "Steam Search, 0 results" was judged done (0.95). The address bar takes it instead, once.
|
|
779
|
+
if (goalRun && steps > 0 && webAddress && !addressTyped && (0, computer_command_1.frontIsBrowser)(last) && !urlShown(last, webAddress)) {
|
|
780
|
+
if (!addressRetried && supports(last, 'address:focus')) {
|
|
781
|
+
addressRetried = true;
|
|
782
|
+
asIssued = true;
|
|
783
|
+
addressPending = webAddress.address;
|
|
784
|
+
standardRequest = 'address:focus';
|
|
785
|
+
emit('waiting', { reason: 'ADDRESS_NOT_SHOWN' });
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
return waitForCommand('ADDRESS_NOT_SHOWN');
|
|
789
|
+
}
|
|
663
790
|
if (last.truncated || !deps.verify)
|
|
664
791
|
return goalRun && steps > 0 ? result('succeeded', 'GOAL_REACHED') : result('needs_verification', 'COMPLETION_CANDIDATE');
|
|
665
792
|
const verified = await (0, interrupt_1.interruptible)(verifySignal => deps.verify(last, goal.goal, verifySignal), runSignal, deps.interruptSignal);
|
|
@@ -672,7 +799,7 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
672
799
|
throw Error('INVALID_VERIFICATION');
|
|
673
800
|
return result(verified ? 'succeeded' : 'needs_verification', verified ? 'VERIFIED' : 'VERIFICATION_FAILED');
|
|
674
801
|
}
|
|
675
|
-
if (steps >=
|
|
802
|
+
if (stepCap !== undefined && steps >= stepCap)
|
|
676
803
|
return result('blocked', 'ACTION_BUDGET');
|
|
677
804
|
const action = { ...d.targets.get(d.action) };
|
|
678
805
|
if (action.kind === 'type') {
|
|
@@ -701,6 +828,13 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
701
828
|
}
|
|
702
829
|
// Direct voice/text commands follow jev-voice-browser's candidate-only
|
|
703
830
|
// executor. Never invoke a generative writer or capture an image to do so.
|
|
831
|
+
// Pod-jinawong 2.0.21 (fa17f432): an agent goal run reached the shell with no
|
|
832
|
+
// text to type. As a bare COMMAND_WAITING_INPUT nobody was asked for it; name
|
|
833
|
+
// the field so the agent is asked for the value (gateway-tasks/computer.ts inspect).
|
|
834
|
+
if (goalRun && prepared.length !== 1 && literal === undefined && target) {
|
|
835
|
+
await capture();
|
|
836
|
+
return { ...result('needs_input', 'FIELD_TEXT_REQUIRED'), fieldRequest: { label: target.label.slice(0, 250) || 'the selected field', ...(last?.application ? { application: last.application } : {}), ...(last?.windowTitle ? { windowTitle: last.windowTitle } : {}), role: target.role, reason: 'missing' } };
|
|
837
|
+
}
|
|
704
838
|
if (direct && prepared.length !== 1 && literal === undefined)
|
|
705
839
|
return waitForCommand('FIELD_TEXT_REQUIRED');
|
|
706
840
|
if (prepared.length !== 1 && literal === undefined && !deps.thinking) {
|
|
@@ -797,8 +931,13 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
797
931
|
const Receipt = zod_1.z.object({ state: zod_1.z.enum(['completed', 'not_executed', 'unknown']), error: zod_1.z.string().optional() });
|
|
798
932
|
let receipt;
|
|
799
933
|
let rejected;
|
|
934
|
+
// The helper stopped on an unconfirmed operation and takes the next command without replaying it (continuation_ready).
|
|
935
|
+
let continuable = false;
|
|
936
|
+
const ready = (body) => { continuable || (continuable = body?.continuation_ready === true); };
|
|
800
937
|
try {
|
|
801
|
-
|
|
938
|
+
const body = await call('computer_action', { ...action, generation: d.generation, operation_id: operationId });
|
|
939
|
+
ready(body);
|
|
940
|
+
receipt = Receipt.parse(body);
|
|
802
941
|
}
|
|
803
942
|
catch (error) {
|
|
804
943
|
receipt = { state: 'unknown' };
|
|
@@ -811,6 +950,7 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
811
950
|
for (let retry = 0; retry < 3 && receipt.state === 'unknown'; retry++) {
|
|
812
951
|
check();
|
|
813
952
|
const status = await deps.call('computer_operation_status', { operation_id: operationId }, runSignal).catch(() => undefined);
|
|
953
|
+
ready(status);
|
|
814
954
|
const parsed = zod_1.z.object({ operation_id: zod_1.z.literal(operationId), state: zod_1.z.enum(['completed', 'not_executed', 'unknown']), error: zod_1.z.string().optional(), owner_acknowledged: zod_1.z.boolean().optional() }).safeParse(status);
|
|
815
955
|
if (parsed.success) {
|
|
816
956
|
if (parsed.data.owner_acknowledged)
|
|
@@ -838,6 +978,21 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
838
978
|
await capture();
|
|
839
979
|
}
|
|
840
980
|
catch { /* Keep the unknown outcome and operation ID. */ }
|
|
981
|
+
// An open the helper could not confirm (APPLICATION_LAUNCH_UNCONFIRMED) whose application is in front now did
|
|
982
|
+
// what it was for: a goal (or the reopened target) goes on from this screen; the operation is never replayed.
|
|
983
|
+
// Pod-jinawong r10, task 457a4930 rev3: TradingView's open went unconfirmed and the round ended with 0 actions.
|
|
984
|
+
if (continuable && action.kind === 'open' && (goalRun || d.action === 'reactivate') && last?.application === action.app_id && last.frontmostProtected !== true) {
|
|
985
|
+
pending = undefined;
|
|
986
|
+
previous = { state: structuredClone(last), signature: fingerprint(last), identity: identity(last, action), action };
|
|
987
|
+
emit('waiting', { reason: 'OPEN_UNCONFIRMED_APP_IN_FRONT' });
|
|
988
|
+
if (d.action === 'reactivate')
|
|
989
|
+
return;
|
|
990
|
+
steps++;
|
|
991
|
+
lastAction = { kind: 'open', appId: String(action.app_id), appName: last.apps.find(app => app.id === action.app_id)?.name };
|
|
992
|
+
asIssued = false;
|
|
993
|
+
redecided = 0;
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
841
996
|
return result('needs_reconciliation', 'OUTCOME_UNKNOWN');
|
|
842
997
|
}
|
|
843
998
|
pending = undefined;
|
|
@@ -882,11 +1037,16 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
882
1037
|
return result('blocked', receipt.error && /^[A-Z][A-Z_0-9]{0,79}$/.test(receipt.error) ? receipt.error : 'ACTION_REJECTED');
|
|
883
1038
|
}
|
|
884
1039
|
previous = { state: structuredClone(last), signature: fingerprint(last), identity: identity(last, action), action, field: last?.controls.find(c => c.ref === action.ref) };
|
|
1040
|
+
// Reopening the target is no step of the command: nothing it asked for has happened yet.
|
|
1041
|
+
if (d.action === 'reactivate') {
|
|
1042
|
+
emit('acted', { ...summary(action), operationId, outcome: 'completed', reason: 'REACTIVATE_TARGET', elapsedMs: Date.now() - started });
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
885
1045
|
steps++;
|
|
886
1046
|
emit('acted', { ...summary(action), operationId, outcome: 'completed', elapsedMs: Date.now() - started });
|
|
887
1047
|
{
|
|
888
1048
|
const control = previous.field;
|
|
889
|
-
lastAction = { kind: erasing !== undefined ? 'erase' : String(action.kind), ...(control && !control.sensitive ? { label: control.label.slice(0, 200), role: control.role } : {}), ...(typeof action.key === 'string' ? { key: action.key } : {}), ...(typeof action.direction === 'string' ? { direction: action.direction } : {}), ...(typeof action.app_id === 'string' ? { appId: action.app_id } : {}), ...(erasing !== undefined ? { count: erasing } : {}) };
|
|
1049
|
+
lastAction = { kind: erasing !== undefined ? 'erase' : String(action.kind), ...(control && !control.sensitive ? { label: control.label.slice(0, 200), role: control.role } : {}), ...(typeof action.key === 'string' ? { key: action.key } : {}), ...(typeof action.direction === 'string' ? { direction: action.direction } : {}), ...(typeof action.app_id === 'string' ? { appId: action.app_id, ...(last?.apps.find(app => app.id === action.app_id) ? { appName: last.apps.find(app => app.id === action.app_id).name.slice(0, 200) } : {}) } : {}), ...(erasing !== undefined ? { count: erasing } : {}) };
|
|
890
1050
|
if (d.action === 'label' && labelPlanned > 1 && control) {
|
|
891
1051
|
labelPressed.push(control.label.slice(0, 20));
|
|
892
1052
|
lastAction = { ...lastAction, sequence: [...labelPressed], planned: labelPlanned };
|
|
@@ -921,8 +1081,42 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
921
1081
|
emit('waiting', { reason: 'GOAL_EVIDENCE_UNAVAILABLE' });
|
|
922
1082
|
}
|
|
923
1083
|
};
|
|
924
|
-
//
|
|
1084
|
+
// The page in front after an address submit or a navigation: looked at again until it is another page than before
|
|
1085
|
+
// (title or application), at most NAVIGATION_SETTLE_MS. True once it changed or shows the goal's site. A read that
|
|
1086
|
+
// fails is no evidence either way: ask the decision model on a later fresh observation.
|
|
1087
|
+
const navigated = async () => {
|
|
1088
|
+
const from = navigationFrom;
|
|
1089
|
+
navigationFrom = undefined;
|
|
1090
|
+
if (!from)
|
|
1091
|
+
return true;
|
|
1092
|
+
for (const until = Date.now() + NAVIGATION_SETTLE_MS;;) {
|
|
1093
|
+
try {
|
|
1094
|
+
last = exports.ComputerObservation.parse(await call('computer_observe'));
|
|
1095
|
+
check();
|
|
1096
|
+
deps.observation?.(last);
|
|
1097
|
+
if (last.windowTitle !== from.title || last.application !== from.application || webAddress && urlShown(last, webAddress))
|
|
1098
|
+
return true;
|
|
1099
|
+
}
|
|
1100
|
+
catch {
|
|
1101
|
+
check();
|
|
1102
|
+
(0, interrupt_1.checkInterruption)(deps.interruptSignal);
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
if (Date.now() >= until)
|
|
1106
|
+
return false;
|
|
1107
|
+
await new Promise((resolve, reject) => { const stop = () => { clearTimeout(t); reject(Error('CANCELLED')); }; const t = setTimeout(() => { runSignal.removeEventListener('abort', stop); resolve(); }, NAVIGATION_POLL_MS); runSignal.addEventListener('abort', stop, { once: true }); });
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
// A fast path matched the whole goal text: running it to its end reaches the goal, once the page it opened is in
|
|
1111
|
+
// front. A page that did not change in time goes to the decision model, which sees it and decides (WAIT, DONE...).
|
|
925
1112
|
if (goalRun && !continuing && fastCommand) {
|
|
1113
|
+
if (!(await navigated())) {
|
|
1114
|
+
asIssued = false;
|
|
1115
|
+
fastCommand = false;
|
|
1116
|
+
redecided = 0;
|
|
1117
|
+
emit('waiting', { reason: 'NAVIGATION_PENDING' });
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
926
1120
|
await goalEvidence();
|
|
927
1121
|
return result('succeeded', 'GOAL_REACHED');
|
|
928
1122
|
}
|
|
@@ -930,7 +1124,7 @@ async function runComputerUse(raw, deps, signal) {
|
|
|
930
1124
|
asIssued = false;
|
|
931
1125
|
redecided = 0;
|
|
932
1126
|
// Out of budget before DONE: a stop the agent hears, not a wait for a command.
|
|
933
|
-
if (steps >=
|
|
1127
|
+
if (stepCap !== undefined && steps >= stepCap) {
|
|
934
1128
|
await goalEvidence();
|
|
935
1129
|
return result('blocked', 'STEP_LIMIT');
|
|
936
1130
|
}
|