@namzu/sdk 69.0.0 → 69.2.0
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/CHANGELOG.md +68 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +2 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/authorization/skill-grant.d.ts.map +1 -1
- package/dist/authorization/skill-grant.js +1 -0
- package/dist/authorization/skill-grant.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +10 -0
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +1 -0
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +29 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +59 -2
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/errors.d.ts +7 -0
- package/dist/connector/mcp/errors.d.ts.map +1 -1
- package/dist/connector/mcp/errors.js +14 -0
- package/dist/connector/mcp/errors.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +5 -1
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +3 -1
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/skill-source.d.ts +144 -0
- package/dist/connector/mcp/skill-source.d.ts.map +1 -0
- package/dist/connector/mcp/skill-source.js +375 -0
- package/dist/connector/mcp/skill-source.js.map +1 -0
- package/dist/connector/mcp/skills.d.ts +137 -0
- package/dist/connector/mcp/skills.d.ts.map +1 -0
- package/dist/connector/mcp/skills.js +303 -0
- package/dist/connector/mcp/skills.js.map +1 -0
- package/dist/network/audit.d.ts +1 -1
- package/dist/network/audit.d.ts.map +1 -1
- package/dist/network/audit.js +2 -0
- package/dist/network/audit.js.map +1 -1
- package/dist/network/computer.d.ts +107 -0
- package/dist/network/computer.d.ts.map +1 -0
- package/dist/network/computer.js +250 -0
- package/dist/network/computer.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/index.js +1 -0
- package/dist/network/index.js.map +1 -1
- package/dist/network/join.d.ts +3 -1
- package/dist/network/join.d.ts.map +1 -1
- package/dist/network/join.js +6 -3
- package/dist/network/join.js.map +1 -1
- package/dist/network/roster.d.ts +5 -0
- package/dist/network/roster.d.ts.map +1 -1
- package/dist/network/roster.js.map +1 -1
- package/dist/network/service.d.ts +12 -2
- package/dist/network/service.d.ts.map +1 -1
- package/dist/network/service.js +377 -52
- package/dist/network/service.js.map +1 -1
- package/dist/network/store.d.ts +10 -0
- package/dist/network/store.d.ts.map +1 -1
- package/dist/network/store.js +25 -3
- package/dist/network/store.js.map +1 -1
- package/dist/network/wire.d.ts +2 -0
- package/dist/network/wire.d.ts.map +1 -1
- package/dist/network/wire.js +5 -0
- package/dist/network/wire.js.map +1 -1
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +7 -1
- package/dist/persona/assembler.js.map +1 -1
- package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
- package/dist/plugin/shell-hook-tool-names.js +1 -0
- package/dist/plugin/shell-hook-tool-names.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +8 -3
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +132 -7
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +4 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +3 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/model-window-suffix.d.ts.map +1 -1
- package/dist/provider/model-window-suffix.js +1 -0
- package/dist/provider/model-window-suffix.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +3 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +9 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +11 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +7 -4
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +9 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +3 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +10 -1
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +12 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +43 -9
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +4 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +32 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +2 -2
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +2 -2
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
- package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
- package/dist/runtime/query/shell-line-escalation.js +38 -0
- package/dist/runtime/query/shell-line-escalation.js.map +1 -0
- package/dist/runtime/query/tooling.d.ts +7 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +2 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +11 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +3 -1
- package/dist/scheduler/local.js.map +1 -1
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +2 -0
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +103 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -0
- package/dist/skills/inline-shell-host.js +238 -0
- package/dist/skills/inline-shell-host.js.map +1 -0
- package/dist/skills/inline-shell.d.ts +176 -0
- package/dist/skills/inline-shell.d.ts.map +1 -0
- package/dist/skills/inline-shell.js +646 -0
- package/dist/skills/inline-shell.js.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/task/file.d.ts +124 -0
- package/dist/store/task/file.d.ts.map +1 -0
- package/dist/store/task/file.js +498 -0
- package/dist/store/task/file.js.map +1 -0
- package/dist/teams/backend.d.ts +28 -0
- package/dist/teams/backend.d.ts.map +1 -0
- package/dist/teams/backend.js +2 -0
- package/dist/teams/backend.js.map +1 -0
- package/dist/teams/fs-sync.d.ts +19 -0
- package/dist/teams/fs-sync.d.ts.map +1 -0
- package/dist/teams/fs-sync.js +81 -0
- package/dist/teams/fs-sync.js.map +1 -0
- package/dist/teams/index.d.ts +14 -0
- package/dist/teams/index.d.ts.map +1 -0
- package/dist/teams/index.js +11 -0
- package/dist/teams/index.js.map +1 -0
- package/dist/teams/names.d.ts +15 -0
- package/dist/teams/names.d.ts.map +1 -0
- package/dist/teams/names.js +43 -0
- package/dist/teams/names.js.map +1 -0
- package/dist/teams/store.d.ts +133 -0
- package/dist/teams/store.d.ts.map +1 -0
- package/dist/teams/store.js +536 -0
- package/dist/teams/store.js.map +1 -0
- package/dist/teams/types.d.ts +97 -0
- package/dist/teams/types.d.ts.map +1 -0
- package/dist/teams/types.js +70 -0
- package/dist/teams/types.js.map +1 -0
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +9 -1
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/atomic-write-file.d.ts +19 -3
- package/dist/tools/builtins/atomic-write-file.d.ts.map +1 -1
- package/dist/tools/builtins/atomic-write-file.js +56 -3
- package/dist/tools/builtins/atomic-write-file.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +56 -2
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +604 -90
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -1
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +31 -0
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +232 -88
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/task/create.d.ts.map +1 -1
- package/dist/tools/task/create.js +11 -2
- package/dist/tools/task/create.js.map +1 -1
- package/dist/tools/task/get.d.ts +8 -0
- package/dist/tools/task/get.d.ts.map +1 -0
- package/dist/tools/task/get.js +51 -0
- package/dist/tools/task/get.js.map +1 -0
- package/dist/tools/task/index.d.ts +7 -0
- package/dist/tools/task/index.d.ts.map +1 -1
- package/dist/tools/task/index.js +10 -2
- package/dist/tools/task/index.js.map +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js +10 -2
- package/dist/tools/task/list.js.map +1 -1
- package/dist/tools/task/number.d.ts +13 -0
- package/dist/tools/task/number.d.ts.map +1 -0
- package/dist/tools/task/number.js +30 -0
- package/dist/tools/task/number.js.map +1 -0
- package/dist/tools/task/present.d.ts.map +1 -1
- package/dist/tools/task/present.js +17 -3
- package/dist/tools/task/present.js.map +1 -1
- package/dist/tools/task/update.d.ts +2 -1
- package/dist/tools/task/update.d.ts.map +1 -1
- package/dist/tools/task/update.js +86 -19
- package/dist/tools/task/update.js.map +1 -1
- package/dist/types/acp/index.d.ts +10 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/agent/base.d.ts +4 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +9 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +7 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +10 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/permission/index.d.ts +20 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +25 -0
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +47 -3
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +4 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/interface.d.ts +6 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/skills/index.d.ts +7 -0
- package/dist/types/skills/index.d.ts.map +1 -1
- package/dist/types/skills/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +28 -2
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +4 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +2 -0
- package/src/authorization/skill-grant.ts +1 -0
- package/src/bridge/acp/permission.ts +11 -1
- package/src/bridge/acp/server.ts +1 -0
- package/src/connector/index.ts +27 -0
- package/src/connector/mcp/client.ts +71 -2
- package/src/connector/mcp/errors.ts +14 -0
- package/src/connector/mcp/index.ts +36 -0
- package/src/connector/mcp/skill-source.ts +499 -0
- package/src/connector/mcp/skills.ts +367 -0
- package/src/network/audit.ts +2 -0
- package/src/network/computer.ts +347 -0
- package/src/network/index.ts +20 -0
- package/src/network/join.ts +4 -2
- package/src/network/roster.ts +5 -0
- package/src/network/service.ts +492 -75
- package/src/network/store.ts +29 -3
- package/src/network/wire.ts +5 -0
- package/src/persona/assembler.ts +7 -1
- package/src/plugin/shell-hook-tool-names.ts +1 -0
- package/src/plugin/shell-hook.ts +144 -7
- package/src/provider/fallback.ts +4 -0
- package/src/provider/idle-timeout.ts +3 -0
- package/src/provider/model-window-suffix.ts +1 -0
- package/src/provider/retry.ts +3 -0
- package/src/public-runtime.ts +99 -0
- package/src/public-tools.ts +15 -0
- package/src/public-types.ts +28 -0
- package/src/runtime/query/executor/tool-call-admission.ts +10 -1
- package/src/runtime/query/executor.ts +57 -8
- package/src/runtime/query/index.ts +43 -0
- package/src/runtime/query/review-policy.ts +7 -1
- package/src/runtime/query/shell-line-escalation.ts +49 -0
- package/src/runtime/query/tooling.ts +6 -0
- package/src/runtime/query/turn/outcome-ledger.ts +11 -0
- package/src/scheduler/local.ts +3 -1
- package/src/skills/index.ts +43 -0
- package/src/skills/inline-shell-host.ts +303 -0
- package/src/skills/inline-shell.ts +765 -0
- package/src/store/index.ts +8 -0
- package/src/store/task/file.ts +641 -0
- package/src/teams/backend.ts +29 -0
- package/src/teams/fs-sync.ts +91 -0
- package/src/teams/index.ts +47 -0
- package/src/teams/names.ts +49 -0
- package/src/teams/store.ts +607 -0
- package/src/teams/types.ts +102 -0
- package/src/tools/admit-facts.ts +9 -1
- package/src/tools/builtins/atomic-write-file.ts +73 -5
- package/src/tools/builtins/computer-use.ts +689 -95
- package/src/tools/builtins/index.ts +1 -0
- package/src/tools/builtins/skill.ts +291 -95
- package/src/tools/task/create.ts +11 -2
- package/src/tools/task/get.ts +53 -0
- package/src/tools/task/index.ts +14 -2
- package/src/tools/task/list.ts +10 -2
- package/src/tools/task/number.ts +32 -0
- package/src/tools/task/present.ts +18 -3
- package/src/tools/task/update.ts +93 -19
- package/src/types/acp/index.ts +11 -1
- package/src/types/agent/base.ts +6 -0
- package/src/types/agent/scheduler.ts +9 -0
- package/src/types/computer-use/index.ts +7 -0
- package/src/types/connector/mcp.ts +10 -0
- package/src/types/permission/index.ts +29 -0
- package/src/types/plugin/index.ts +95 -39
- package/src/types/provider/interface.ts +7 -0
- package/src/types/skills/index.ts +8 -0
- package/src/types/tool/index.ts +23 -2
- package/src/types/tool/presentation.ts +2 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
import { modelReadsImages, resolveProviderCapabilities } from '../../provider/capabilities.js'
|
|
3
4
|
import type {
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
} from './computer-use-coordinates.js'
|
|
39
40
|
import {
|
|
40
41
|
type FittedImage,
|
|
42
|
+
HIGH_RES_SCREENSHOT_LIMITS,
|
|
41
43
|
STANDARD_SCREENSHOT_LIMITS,
|
|
42
44
|
type ScreenshotLimits,
|
|
43
45
|
cropAndFitPng,
|
|
@@ -53,6 +55,26 @@ export {
|
|
|
53
55
|
} from './computer-use-image.js'
|
|
54
56
|
export type { ImageSize, ScreenshotLimits } from './computer-use-image.js'
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The limits to fit a screenshot to for `model`: the high-resolution tier for
|
|
60
|
+
* a model known to read it (the 4.7 and later models of the vendor behind that
|
|
61
|
+
* tier, with or without a vendor prefix or a dated suffix), the standard tier for every
|
|
62
|
+
* other model, including one the table does not know. A wrong "high" costs a
|
|
63
|
+
* rejected tool result; a wrong "standard" only costs detail, so an unknown
|
|
64
|
+
* model gets the standard tier.
|
|
65
|
+
*/
|
|
66
|
+
export function screenshotLimitsForModel(model: string | undefined): ScreenshotLimits {
|
|
67
|
+
if (model === undefined) return STANDARD_SCREENSHOT_LIMITS
|
|
68
|
+
const match = /claude-(?:opus|sonnet|haiku|fable)-(\d+)(?:[-.](\d{1,2})(?!\d))?/i.exec(model)
|
|
69
|
+
if (!match) return STANDARD_SCREENSHOT_LIMITS
|
|
70
|
+
const major = Number(match[1])
|
|
71
|
+
const minor = match[2] === undefined ? 0 : Number(match[2])
|
|
72
|
+
// A dated id such as `claude-sonnet-4-20250514` has no minor: the date is not one.
|
|
73
|
+
return major > 4 || (major === 4 && minor >= 7)
|
|
74
|
+
? HIGH_RES_SCREENSHOT_LIMITS
|
|
75
|
+
: STANDARD_SCREENSHOT_LIMITS
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
export const COMPUTER_USE_TOOL_NAME = 'computer_use' as const
|
|
57
79
|
|
|
58
80
|
const DEFAULT_SETTLE_MS = 500
|
|
@@ -87,8 +109,12 @@ async function settleAfterActions(
|
|
|
87
109
|
await sleep(settleMs, signal)
|
|
88
110
|
}
|
|
89
111
|
const MAX_LISTED_WINDOWS = 50
|
|
90
|
-
/**
|
|
91
|
-
const
|
|
112
|
+
/** Steps after which a batch may end with the window's controls instead of a picture. */
|
|
113
|
+
const TREE_ENDING_STEPS: ReadonlySet<string> = new Set(['ui_act', 'ui_do', 'type_text', 'key'])
|
|
114
|
+
/** Steps that aim at a pixel of a screenshot. */
|
|
115
|
+
const PIXEL_STEPS: ReadonlySet<string> = new Set(['mouse_click', 'mouse_drag', 'scroll'])
|
|
116
|
+
/** The most of a ui_snapshot the model is shown, in characters (about 7 000 tokens). */
|
|
117
|
+
const MAX_UI_SNAPSHOT_CHARS = 24_000
|
|
92
118
|
/** The refs of earlier snapshots the tool still resolves for the host. */
|
|
93
119
|
const MAX_HELD_UI_REFS = 4_000
|
|
94
120
|
|
|
@@ -162,9 +188,11 @@ export interface ComputerUseToolOptions {
|
|
|
162
188
|
* What every screenshot and zoom image is fitted to before the model sees
|
|
163
189
|
* it. Default {@link STANDARD_SCREENSHOT_LIMITS}, which every current vision
|
|
164
190
|
* model takes without a further resize; {@link HIGH_RES_SCREENSHOT_LIMITS}
|
|
165
|
-
* only when every model the session can reach is on that tier.
|
|
191
|
+
* only when every model the session can reach is on that tier. A function
|
|
192
|
+
* is asked before every capture, for a session whose model changes between
|
|
193
|
+
* turns; see {@link screenshotLimitsForModel}.
|
|
166
194
|
*/
|
|
167
|
-
readonly screenshotLimits?: ScreenshotLimits
|
|
195
|
+
readonly screenshotLimits?: ScreenshotLimits | (() => ScreenshotLimits)
|
|
168
196
|
/**
|
|
169
197
|
* Milliseconds to wait after an action before the screenshot it returns,
|
|
170
198
|
* so a menu has opened or a page has started to paint. Default 500.
|
|
@@ -207,6 +235,62 @@ export interface ComputerUseToolOptions {
|
|
|
207
235
|
* tell where it would land. Absent or empty: no application is off limits.
|
|
208
236
|
*/
|
|
209
237
|
readonly deniedApps?: readonly string[]
|
|
238
|
+
/**
|
|
239
|
+
* What the tool does in a browser window (`computerUse.browserWindows`). `look`, the default
|
|
240
|
+
* here, only looks: a page is the browser tool's. `act` clicks and types there like in any other
|
|
241
|
+
* application. `ask` looks until a person allows it: the first action aimed at a browser window
|
|
242
|
+
* puts {@link askBrowserWindow} to them, and only their answer grants it, for that browser and
|
|
243
|
+
* for the life of this tool (one conversation). Nothing else grants it, no permission mode
|
|
244
|
+
* included; a function is read at every call, and a switch to `look` takes every grant back; without `askBrowserWindow` (a scheduled or unattended run) `ask` stays `look`.
|
|
245
|
+
*/
|
|
246
|
+
readonly browserWindows?: BrowserWindowsSetting | (() => BrowserWindowsSetting)
|
|
247
|
+
/**
|
|
248
|
+
* Puts the question "may Namzu click and type in this browser in this conversation?" to a
|
|
249
|
+
* person. `allow` grants it, `deny` is "not now", `unavailable` means nobody can answer.
|
|
250
|
+
*/
|
|
251
|
+
readonly askBrowserWindow?: (
|
|
252
|
+
question: BrowserWindowQuestion,
|
|
253
|
+
signal?: AbortSignal,
|
|
254
|
+
) => Promise<BrowserWindowAnswer>
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** `computerUse.browserWindows`: how far the tool works in a browser window. */
|
|
258
|
+
export type BrowserWindowsSetting = 'look' | 'ask' | 'act'
|
|
259
|
+
/** The person's answer to {@link ComputerUseToolOptions.askBrowserWindow}. */
|
|
260
|
+
export type BrowserWindowAnswer = 'allow' | 'deny' | 'unavailable'
|
|
261
|
+
/** The browser the question is about: the host's name for it and how a person reads it. */
|
|
262
|
+
export interface BrowserWindowQuestion {
|
|
263
|
+
readonly app: string
|
|
264
|
+
readonly name: string
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** How a browser is told apart in a grant: trimmed, lower case, spaces joined, without `.exe`. */
|
|
268
|
+
function browserKey(app: string): string {
|
|
269
|
+
return deniedAppKey(app).replace(/\s+/g, '-')
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The three ways forward after a browser window was not acted in, in the words the model offers
|
|
274
|
+
* the person. `own` names the first: the setting to change when it is `look`, the question when
|
|
275
|
+
* it is `ask`.
|
|
276
|
+
*/
|
|
277
|
+
function browserWaysForward(name: string, setting: BrowserWindowsSetting): string {
|
|
278
|
+
const first =
|
|
279
|
+
setting === 'look'
|
|
280
|
+
? `change Browser windows in Settings (computerUse.browserWindows) to Ask, so Namzu may click and type in ${name} once they allow it`
|
|
281
|
+
: `allow Namzu to click and type in ${name} for this conversation`
|
|
282
|
+
return `Ways forward to offer the person, in plain words: ${first}; or continue in Namzu's own browser (the browser tool), where they sign in once; or they click in ${name} themselves while you guide them from screenshots.`
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** What the tool says about browser windows, one paragraph, for its description. */
|
|
286
|
+
export function browserWindowsGuidance(setting: BrowserWindowsSetting): string {
|
|
287
|
+
const care =
|
|
288
|
+
'Even where it is allowed, stop and ask the person before you type into a password field, submit payment or personal data, send or post something, delete, accept terms, or change organisation-wide admin settings.'
|
|
289
|
+
if (setting === 'act')
|
|
290
|
+
return `Browser windows are worked like any other application. The browser tool is Namzu's own browser, where the person signs in once; the person's own open browser is here. ${care}`
|
|
291
|
+
if (setting === 'ask')
|
|
292
|
+
return `A browser window is only looked at until the person allows more: the first action aimed at one asks them whether Namzu may click and type in that browser for this conversation, and only their answer allows it. If it is refused or not asked yet, offer the person the ways forward in plain words: allow it for this conversation; continue in Namzu's own browser (the browser tool), where they sign in once; or they click while you guide them from screenshots. ${care}`
|
|
293
|
+
return "A browser window is only looked at: act on a page with the browser tool, which is Namzu's own browser, where the person signs in once. To work in the browser window the person already has open, they can allow it in Settings (Browser windows), or click there themselves while you guide them from screenshots."
|
|
210
294
|
}
|
|
211
295
|
|
|
212
296
|
/** How an application name is compared: trimmed, lower case, without a trailing `.exe`. */
|
|
@@ -357,6 +441,10 @@ const uiSnapshotSchema = z.object({
|
|
|
357
441
|
offset: z.number().int().min(0).max(1_000_000).optional(),
|
|
358
442
|
/** Only controls whose text contains this, with the elements above them. */
|
|
359
443
|
query: z.string().min(1).max(200).optional(),
|
|
444
|
+
/** Only controls of this role (comma-separated for several), with the elements above them. */
|
|
445
|
+
role: z.string().min(1).max(120).optional(),
|
|
446
|
+
/** Show the whole tree even where the window was read before (the default shows what changed). */
|
|
447
|
+
full: z.boolean().optional(),
|
|
360
448
|
})
|
|
361
449
|
const WAIT_FOR_CONDITIONS = [
|
|
362
450
|
'element_appears',
|
|
@@ -536,7 +624,7 @@ const TERMINAL_APPS =
|
|
|
536
624
|
* through the browser tool.
|
|
537
625
|
*/
|
|
538
626
|
const BROWSER_APPS =
|
|
539
|
-
/^(chrome|google-chrome(-stable|-beta|-unstable)?|chromium(-browser)?|msedge|microsoft-edge(-stable|-beta|-dev)?|firefox(-esr|-bin)?|brave(-browser)?|opera|vivaldi(-stable)?|arc-browser|safari|librewolf|waterfox|zen-browser|navigator|tor browser|iexplore|duckduckgo|yandex-?browser|thorium)$/i
|
|
627
|
+
/^(chrome|google-chrome(-stable|-beta|-unstable|-canary|-dev)?|chromium(-browser)?|msedge|microsoft-edge(-stable|-beta|-dev)?|firefox(-esr|-bin)?|brave(-browser)?|opera|vivaldi(-stable)?|arc-browser|safari|librewolf|waterfox|zen-browser|navigator|tor browser|iexplore|duckduckgo|yandex-?browser|thorium)$/i
|
|
540
628
|
|
|
541
629
|
/**
|
|
542
630
|
* Editors and development environments, by process name. Like a terminal,
|
|
@@ -544,20 +632,35 @@ const BROWSER_APPS =
|
|
|
544
632
|
* shell and the edit tools do that work without a screen.
|
|
545
633
|
*/
|
|
546
634
|
const IDE_APPS =
|
|
547
|
-
/^(code(-insiders|-oss)?|cursor|windsurf|zed|devenv|idea(64)?|pycharm(64)?|webstorm(64)?|goland(64)?|clion(64)?|rider(64)?|phpstorm(64)?|rubymine(64)?|datagrip(64)?|studio64|android-studio|jetbrains-[a-z-]+|sublime_text|subl|atom-editor|eclipse|netbeans(64)?|xcode|nova-editor|vscodium|codium|kate|gedit|vim|gvim|nvim-qt|emacs|lapce|jetbrains-fleet)$/i
|
|
635
|
+
/^(code(-insiders|-oss)?|visual-studio-code(-insiders)?|intellij-idea(-ce)?|cursor|windsurf|zed|devenv|idea(64)?|pycharm(64)?|webstorm(64)?|goland(64)?|clion(64)?|rider(64)?|phpstorm(64)?|rubymine(64)?|datagrip(64)?|studio64|android-studio|jetbrains-[a-z-]+|sublime_text|subl|atom-editor|eclipse|netbeans(64)?|xcode|nova-editor|vscodium|codium|kate|gedit|vim|gvim|nvim-qt|emacs|lapce|jetbrains-fleet)$/i
|
|
548
636
|
|
|
549
637
|
/** How far the tool works in an application: only looks, looks and clicks, or everything. */
|
|
550
638
|
export type AppTier = 'view' | 'click' | 'full'
|
|
551
639
|
|
|
552
640
|
/** The tier of an application by the name a host reports for its window. */
|
|
553
641
|
export function appTier(app: string): AppTier {
|
|
642
|
+
// Arc's macOS display name is the bare word; as a lower-case process name it is too generic.
|
|
643
|
+
if (appIs(BROWSER_APPS, app) || app.trim() === 'Arc') return 'view'
|
|
644
|
+
if (appIs(TERMINAL_APPS, app) || appIs(IDE_APPS, app)) return 'click'
|
|
645
|
+
return 'full'
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Whether an application name matches a family pattern. Hosts name a window's
|
|
650
|
+
* application differently: a process name on Windows and Linux (`msedge`,
|
|
651
|
+
* `sublime_text`), the display name on macOS (`Microsoft Edge`, `Sublime Text`).
|
|
652
|
+
* The name is tried as given and with its spaces joined by `-` and by `_`.
|
|
653
|
+
*/
|
|
654
|
+
function appIs(pattern: RegExp, app: string): boolean {
|
|
554
655
|
const name = app
|
|
555
656
|
.trim()
|
|
556
657
|
.replace(/\.exe$/i, '')
|
|
557
658
|
.replace(/^.*[\\/]/, '')
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
659
|
+
return (
|
|
660
|
+
pattern.test(name) ||
|
|
661
|
+
pattern.test(name.replace(/\s+/g, '-')) ||
|
|
662
|
+
pattern.test(name.replace(/\s+/g, '_'))
|
|
663
|
+
)
|
|
561
664
|
}
|
|
562
665
|
|
|
563
666
|
/** Keys that only move a page: allowed in a view-only application. */
|
|
@@ -738,6 +841,7 @@ function buildDescription(
|
|
|
738
841
|
caps: ComputerUseCapabilities,
|
|
739
842
|
settings: ResolvedSettings,
|
|
740
843
|
advisor?: ComputerUseAdvisor,
|
|
844
|
+
browser: BrowserWindowsSetting = 'look',
|
|
741
845
|
): string {
|
|
742
846
|
const available = availableActions(host, caps, advisor)
|
|
743
847
|
const unavailable = unavailableHostActions(host, caps)
|
|
@@ -767,20 +871,20 @@ function buildDescription(
|
|
|
767
871
|
)
|
|
768
872
|
lines.push(
|
|
769
873
|
'Coordinates: every x/y you send is a pixel of the most recent screenshot this tool returned — origin at its top-left, x to the right, y down — never a screen pixel. Each screenshot states its id and size (for example "s3: 1456x819"); stay inside it. Display screenshots map onto the display. To aim at an earlier display screenshot, pass its id as screenshot_id.',
|
|
770
|
-
'
|
|
771
|
-
|
|
874
|
+
'Click coordinates need a screenshot to refer to; any action that changes something already returns one, so take one yourself only when none has been shown yet.',
|
|
875
|
+
`Look at the screen before you say what state an application is in. ${browser === 'look' ? "Never click links with computer use: a page is the browser tool's." : 'Prefer the browser tool for a page; click in a browser window with computer use only where the browser rule allows it.'} Prefer a connected tool or a command line to the screen when one does the job.`,
|
|
772
876
|
)
|
|
773
877
|
if (settings.screenshotAfterActions)
|
|
774
878
|
lines.push(
|
|
775
|
-
`After any action that changes something, the tool waits ${settings.settleMs} ms and returns
|
|
879
|
+
`After any action that changes something, the tool itself waits for the window to stop changing (at most ${settings.settleMs} ms) and then returns the result — do not add a wait or call screenshot after acting.`,
|
|
776
880
|
)
|
|
777
881
|
lines.push(
|
|
778
|
-
|
|
882
|
+
`zoom returns a closer, sharper view of region {x, y, width, height} of the screenshot; your coordinates still refer to the screenshot, not to the zoomed image. It is for reading small text that ${available.includes('ui_snapshot') ? "the window's controls do not name" : 'the screenshot shows too small'}, not a step to take before acting: act on what you can already see.`,
|
|
779
883
|
`wait pauses for ms milliseconds (at most ${settings.maxWaitMs} per call, a batch's waits together) and then shows the screen.${available.includes('wait_for') ? ' Prefer wait_for to a fixed wait whenever you know what you are waiting for.' : ''}`,
|
|
780
884
|
)
|
|
781
885
|
if (available.includes('batch'))
|
|
782
886
|
lines.push(
|
|
783
|
-
`batch: {"type":"batch","actions":[...]} runs up to ${settings.maxBatchActions} actions in order, stops at the first one that fails, and
|
|
887
|
+
`batch: {"type":"batch","actions":[...]} runs up to ${settings.maxBatchActions} actions in order, stops at the first one that fails (a ref that cannot be found or is ambiguous included, so nothing after it runs), and ends with what changed in the window's controls when you have read that window, or else one screenshot. The tool settles after each action, so a batch needs no wait between steps. Every call costs a model round trip of several seconds, so put the steps you can already predict into one batch (click a field, type, press ENTER) rather than one call each — but end the batch at any step that should bring up a new window, and look before typing into it. A batch cannot contain screenshot${available.includes('ui_snapshot') ? ', zoom or ui_snapshot' : ' or zoom'}.`,
|
|
784
888
|
)
|
|
785
889
|
if (
|
|
786
890
|
caps.displayServer === 'win32' &&
|
|
@@ -800,11 +904,11 @@ function buildDescription(
|
|
|
800
904
|
)
|
|
801
905
|
if (windowCaptureAvailable(host, caps))
|
|
802
906
|
lines.push(
|
|
803
|
-
`When the user names an application or window, ${available.includes('list_windows') ? 'use list_windows then screenshot {window_id}' : 'use screenshot {window_id} with a host-provided window id'} to capture pixels for that window. Its x/y are pixels of that window image; clicks, drags, typing and keys target that window. Window pointer input is sent in the background first. If a click or drag is refused, inspect a fresh image before any other action; where the host can use the screen it may repeat a refused click once on the screen, and the result says so. ${caps.windowScroll === false ? `Window pixel scrolling is unavailable on this host; ${hostActionAvailable(caps, 'screenshot') ? 'deliberately take a display screenshot for display scrolling' : 'scroll by another means'}. ` : ''}Foreground text may briefly bring the verified window to the front: the host waits until the user has been still for a moment, puts their window back afterwards, and reports it as not delivered (safe to try again later) when the screen stays busy. ${host.beginTurn ? 'A result that says the user pressed Escape means stop: end your turn and say what is left undone. ' : ''}
|
|
907
|
+
`When the user names an application or window, ${available.includes('list_windows') ? 'use list_windows then screenshot {window_id}' : 'use screenshot {window_id} with a host-provided window id'} to capture pixels for that window. Its x/y are pixels of that window image; clicks, drags, typing and keys target that window. Window pointer input is sent in the background first. If a click or drag is refused, inspect a fresh image before any other action; where the host can use the screen it may repeat a refused click once on the screen, and the result says so. ${caps.windowScroll === false ? `Window pixel scrolling is unavailable on this host; ${hostActionAvailable(caps, 'screenshot') ? 'deliberately take a display screenshot for display scrolling' : 'scroll by another means'}. ` : ''}Foreground text may briefly bring the verified window to the front: the host waits until the user has been still for a moment, puts their window back afterwards, and reports it as not delivered (safe to try again later) when the screen stays busy. ${host.beginTurn ? 'A result that says the user pressed Escape means stop: end your turn and say what is left undone. ' : ''}${browserWindowsGuidance(browser)} A stale or moved window is refused; take a fresh window screenshot. ${hostActionAvailable(caps, 'screenshot') ? 'Plain screenshot still shows the display. ' : 'screenshot requires window_id on this host. '}Browser permission bubbles outside the window may be absent. If the window image is blank or shows another window, do not click it; focus the target and capture it again.`,
|
|
804
908
|
)
|
|
805
909
|
if (available.includes('ui_snapshot'))
|
|
806
910
|
lines.push(
|
|
807
|
-
`ui_snapshot {window_id} reads a window's controls (its accessibility tree) as text, each control you can act on with a ref such as e12; without window_id it reads the window in front. A large window comes back as an outline: a region ends with "(+N more inside)" and has a ref; ui_snapshot {root: <that ref>} reads that region alone (a long one in pages: offset) and keeps every other ref usable, and ui_snapshot {query: <text>} lists only the controls whose text matches. ui_act {ref, action, value} acts on one control: invoke (press a button, open a menu item), set_value (replace a field's text with value), toggle, select, expand, collapse. A batch of ui_act steps (for example pressing several buttons) runs in one call. A ref names its control and stays usable after later snapshots and after you act: the control is found again by its id, its place and its name before anything is sent. If it cannot be found the step fails with STALE_REF, and if several controls fit it fails with AMBIGUOUS_TARGET; in both nothing was sent, so take a ui_snapshot and choose again.`,
|
|
911
|
+
`ui_snapshot {window_id} reads a window's controls (its accessibility tree) as text, each control you can act on with a ref such as e12; without window_id it reads the window in front. A large window comes back as an outline: a region ends with "(+N more inside)" and has a ref; ui_snapshot {root: <that ref>} reads that region alone (a long one in pages: offset) and keeps every other ref usable, and ui_snapshot {query: <text>} lists only the controls whose text matches, and ui_snapshot {role: "Button"} only those of that type (both keep the elements above them). A window you have read before comes back as what changed since (+ added, ~ changed, - gone, or "no change"), with every earlier ref still usable; ui_snapshot {full: true} lists the whole tree. The result ends with the focused control and any selected text. A window screenshot of a window not yet read comes with its controls. ui_act {ref, action, value} acts on one control: invoke (press a button, open a menu item), set_value (replace a field's text with value), toggle, select, expand, collapse. A batch of ui_act steps (for example pressing several buttons) runs in one call. A ref names its control and stays usable after later snapshots and after you act: the control is found again by its id, its place and its name before anything is sent. If it cannot be found the step fails with STALE_REF, and if several controls fit it fails with AMBIGUOUS_TARGET; in both nothing was sent, so take a ui_snapshot and choose again.`,
|
|
808
912
|
'Each ui_act says what is known. "done, verified" means the control was read back and matches. "sent, not confirmed" means the input went out and nothing could check it: look (ui_snapshot, or a window screenshot) before repeating it, because repeating can act twice. A failure that says "not delivered" means nothing reached the control, so trying again, or another way, is safe. set_value on a control that does not take the value fails with that reason instead of being typed in; select on a list row selects it without opening it (invoke opens it).',
|
|
809
913
|
...(available.includes('wait_for')
|
|
810
914
|
? [
|
|
@@ -889,7 +993,7 @@ const ACTION_REQUIREMENTS: Readonly<Record<ToolActionType, string>> = {
|
|
|
889
993
|
list_windows: 'list_windows needs no other fields',
|
|
890
994
|
focus_window: 'focus_window needs window_id',
|
|
891
995
|
ui_snapshot:
|
|
892
|
-
'ui_snapshot takes an optional window_id, root (a ref to open)
|
|
996
|
+
'ui_snapshot takes an optional window_id, root (a ref to open), query (text to find), role (a control type to list) and full (the whole tree instead of what changed)',
|
|
893
997
|
wait_for: 'wait_for needs until and match; role, window_id and timeout_ms are optional',
|
|
894
998
|
ui_act: 'ui_act needs ref and action, and value for set_value',
|
|
895
999
|
ui_do: 'ui_do needs target (the control, in words) and action, and value for set_value',
|
|
@@ -1004,6 +1108,16 @@ function hostModelSchema(
|
|
|
1004
1108
|
description:
|
|
1005
1109
|
'For ui_snapshot: list only the controls whose text contains this (case-insensitive), with the elements above them.',
|
|
1006
1110
|
}
|
|
1111
|
+
fields.role = {
|
|
1112
|
+
type: 'string',
|
|
1113
|
+
description:
|
|
1114
|
+
'For ui_snapshot: list only controls of this role, such as Button or Edit (comma-separated for several), with the elements above them. Combines with query.',
|
|
1115
|
+
}
|
|
1116
|
+
fields.full = {
|
|
1117
|
+
type: 'boolean',
|
|
1118
|
+
description:
|
|
1119
|
+
'For ui_snapshot: true shows the whole tree. By default a window read before shows only what changed since that read.',
|
|
1120
|
+
}
|
|
1007
1121
|
}
|
|
1008
1122
|
if (!forItems && present.includes('wait_for')) {
|
|
1009
1123
|
fields.until = {
|
|
@@ -1280,7 +1394,7 @@ function batchLabel(
|
|
|
1280
1394
|
// ---------------------------------------------------------------------------
|
|
1281
1395
|
|
|
1282
1396
|
interface ResolvedSettings {
|
|
1283
|
-
readonly limits: ScreenshotLimits
|
|
1397
|
+
readonly limits: () => ScreenshotLimits
|
|
1284
1398
|
readonly settleMs: number
|
|
1285
1399
|
readonly screenshotAfterActions: boolean
|
|
1286
1400
|
readonly maxBatchActions: number
|
|
@@ -1294,18 +1408,22 @@ function resolveSettings(options: ComputerUseToolOptions): ResolvedSettings {
|
|
|
1294
1408
|
throw new RangeError(`createComputerUseTool: ${name} must be an integer ≥ ${min}`)
|
|
1295
1409
|
return value
|
|
1296
1410
|
}
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
throw new RangeError(
|
|
1305
|
-
'createComputerUseTool: screenshotLimits needs an integer maxLongEdge ≥ 28 and maxTiles ≥ 1',
|
|
1411
|
+
const source = options.screenshotLimits ?? STANDARD_SCREENSHOT_LIMITS
|
|
1412
|
+
const check = (limits: ScreenshotLimits): ScreenshotLimits => {
|
|
1413
|
+
if (
|
|
1414
|
+
!Number.isSafeInteger(limits.maxLongEdge) ||
|
|
1415
|
+
!Number.isSafeInteger(limits.maxTiles) ||
|
|
1416
|
+
limits.maxLongEdge < 28 ||
|
|
1417
|
+
limits.maxTiles < 1
|
|
1306
1418
|
)
|
|
1419
|
+
throw new RangeError(
|
|
1420
|
+
'createComputerUseTool: screenshotLimits needs an integer maxLongEdge ≥ 28 and maxTiles ≥ 1',
|
|
1421
|
+
)
|
|
1422
|
+
return limits
|
|
1423
|
+
}
|
|
1424
|
+
check(typeof source === 'function' ? source() : source)
|
|
1307
1425
|
return {
|
|
1308
|
-
limits,
|
|
1426
|
+
limits: () => check(typeof source === 'function' ? source() : source),
|
|
1309
1427
|
settleMs: count(options.settleMs, DEFAULT_SETTLE_MS, 0, 'settleMs'),
|
|
1310
1428
|
screenshotAfterActions: options.screenshotAfterActions ?? true,
|
|
1311
1429
|
maxBatchActions: count(
|
|
@@ -1514,21 +1632,58 @@ export interface ComputerUseTool extends ToolDefinition<ActionInput> {
|
|
|
1514
1632
|
* ordinary action. A reading of the call's own words, not of the screen.
|
|
1515
1633
|
*/
|
|
1516
1634
|
consequence(input: unknown): string | undefined
|
|
1635
|
+
/** The browsers a person allowed Namzu to click and type in during this conversation, as named. */
|
|
1636
|
+
browserGrants(): string[]
|
|
1637
|
+
/** Takes a browser back (by any name the host gives it). Returns whether it was allowed. */
|
|
1638
|
+
revokeBrowserGrant(app: string): boolean
|
|
1639
|
+
/**
|
|
1640
|
+
* Whether an action in this application would put the browser question to a person: it is a
|
|
1641
|
+
* browser, the setting is `ask`, somebody can be asked, and nobody has allowed it yet. A host
|
|
1642
|
+
* that draws its own application card uses it to ask once, in the browser's words, not twice.
|
|
1643
|
+
*/
|
|
1644
|
+
browserQuestionPending(app: string): boolean
|
|
1645
|
+
/**
|
|
1646
|
+
* Of the applications a call works on, the browsers the engine will put its question about for
|
|
1647
|
+
* THIS call. A call that only looks (a picture, a list of windows) puts no question, so it names
|
|
1648
|
+
* none: its card would grant click-and-type, and a no would refuse a harmless look.
|
|
1649
|
+
*/
|
|
1650
|
+
browserAsk(input: unknown, apps: readonly string[]): string[]
|
|
1517
1651
|
}
|
|
1518
1652
|
|
|
1519
1653
|
const CONSEQUENTIAL_KEYS =
|
|
1520
1654
|
/(^|\+)(alt\+f4|ctrl\+q|cmd\+q|super\+q|ctrl\+w|ctrl\+shift\+delete|shift\+delete|ctrl\+enter|cmd\+enter|delete)$/i
|
|
1521
1655
|
const CONSEQUENTIAL_WORDS =
|
|
1522
|
-
/(?<!\p{L})(delete|remove|erase|discard|don'?t save|do not save|close|quit|exit|send|submit|pay|purchase|buy|order|sign out|log ?out|empty|format|uninstall|kaydetme|sil|gönder|kapat|çık|çıkış|satın al|öde)(?!\p{L})/iu
|
|
1656
|
+
/(?<!\p{L})(delete|remove|erase|discard|don'?t save|do not save|close|quit|exit|send|submit|pay|purchase|buy|order|sign out|log ?out|empty|format|uninstall|accept|agree|post|publish|confirm|password|passcode|card number|cvv|iban|kaydetme|sil|gönder|kapat|çık|çıkış|satın al|öde)(?!\p{L})/iu
|
|
1657
|
+
|
|
1658
|
+
/** Browsers whose process name is not how a person says it. */
|
|
1659
|
+
const KNOWN_BROWSER_NAMES: Record<string, string> = {
|
|
1660
|
+
'brave-browser': 'Brave',
|
|
1661
|
+
brave: 'Brave',
|
|
1662
|
+
'google-chrome': 'Chrome',
|
|
1663
|
+
chrome: 'Chrome',
|
|
1664
|
+
msedge: 'Microsoft Edge',
|
|
1665
|
+
'microsoft-edge': 'Microsoft Edge',
|
|
1666
|
+
firefox: 'Firefox',
|
|
1667
|
+
}
|
|
1523
1668
|
|
|
1524
1669
|
/** An application as a person reads it: no `.exe`, and a lowercase process name starts with a capital. */
|
|
1525
1670
|
function applicationName(name: string): string {
|
|
1526
1671
|
const bare = name.trim().replace(/\.exe$/i, '')
|
|
1672
|
+
const known = KNOWN_BROWSER_NAMES[bare.toLowerCase()]
|
|
1673
|
+
if (known) return known
|
|
1527
1674
|
return bare && bare === bare.toLowerCase()
|
|
1528
1675
|
? `${bare.charAt(0).toUpperCase()}${bare.slice(1)}`
|
|
1529
1676
|
: bare
|
|
1530
1677
|
}
|
|
1531
1678
|
|
|
1679
|
+
/** A control that takes a secret: a password field, by its state, role or name. */
|
|
1680
|
+
function isSecretElement(element: UiElement): boolean {
|
|
1681
|
+
const states = (element.states ?? []).map((state) => state.toLowerCase())
|
|
1682
|
+
if (states.some((state) => state === 'password' || state === 'protected' || state === 'secure'))
|
|
1683
|
+
return true
|
|
1684
|
+
return /password|passcode|passwort|parola|şifre|sifre/i.test(`${element.role} ${element.name}`)
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1532
1687
|
/** Words that make a control's name or an intent one a person should answer for. */
|
|
1533
1688
|
function consequentialWords(text: string | undefined): boolean {
|
|
1534
1689
|
return text !== undefined && CONSEQUENTIAL_WORDS.test(text)
|
|
@@ -1638,6 +1793,22 @@ export function createComputerUseTool(
|
|
|
1638
1793
|
const frames = new ScreenshotFrames()
|
|
1639
1794
|
const available = new Set<string>(availableActions(host, caps, options.advisor))
|
|
1640
1795
|
const advisor = options.advisor
|
|
1796
|
+
// Browser windows: the setting, and the browsers a person allowed in this conversation. Only the
|
|
1797
|
+
// person's answer to `askBrowserWindow` adds one; `ask` with nobody to ask is `look`.
|
|
1798
|
+
const readBrowserSetting = (): BrowserWindowsSetting =>
|
|
1799
|
+
typeof options.browserWindows === 'function'
|
|
1800
|
+
? options.browserWindows()
|
|
1801
|
+
: (options.browserWindows ?? 'look')
|
|
1802
|
+
const browserSetting: BrowserWindowsSetting = readBrowserSetting()
|
|
1803
|
+
const browserGranted = new Map<string, string>()
|
|
1804
|
+
const browserDeclined = new Map<string, string>()
|
|
1805
|
+
const browserActionsAllowed = (app: string): boolean => {
|
|
1806
|
+
const setting = readBrowserSetting()
|
|
1807
|
+
if (setting === 'look') browserGranted.clear()
|
|
1808
|
+
return setting === 'act' || (setting === 'ask' && browserGranted.has(browserKey(app)))
|
|
1809
|
+
}
|
|
1810
|
+
// Whether the control in focus in the latest ui_snapshot is a secret field (a password).
|
|
1811
|
+
let focusedSecret = false
|
|
1641
1812
|
|
|
1642
1813
|
// The controls of the latest ui_snapshot, by the ref the model was shown.
|
|
1643
1814
|
// A ref names a control, not one reading of it: the same host ref keeps the
|
|
@@ -1647,6 +1818,19 @@ export function createComputerUseTool(
|
|
|
1647
1818
|
const uiRefByHost = new Map<string, string>()
|
|
1648
1819
|
// The refs the latest reading of each window showed, so an advisor is asked about what is there now.
|
|
1649
1820
|
const shownRefs = new Map<string, Set<string>>()
|
|
1821
|
+
// The last whole-window read of each window, for showing only what changed next time.
|
|
1822
|
+
const uiSnapshotMemory = new Map<
|
|
1823
|
+
string,
|
|
1824
|
+
{
|
|
1825
|
+
readonly id: string
|
|
1826
|
+
readonly entries:
|
|
1827
|
+
| readonly {
|
|
1828
|
+
readonly hostRef: string | undefined
|
|
1829
|
+
readonly text: string
|
|
1830
|
+
}[]
|
|
1831
|
+
| undefined
|
|
1832
|
+
}
|
|
1833
|
+
>()
|
|
1650
1834
|
let uiSnapshots = 0
|
|
1651
1835
|
let uiRefCount = 0
|
|
1652
1836
|
let uiSnapshotWindowId: string | undefined
|
|
@@ -1714,12 +1898,14 @@ export function createComputerUseTool(
|
|
|
1714
1898
|
windowId,
|
|
1715
1899
|
callSignal,
|
|
1716
1900
|
)
|
|
1717
|
-
const image = await fitPng(shot.data, settings.limits)
|
|
1901
|
+
const image = await fitPng(shot.data, settings.limits())
|
|
1718
1902
|
if (image.sourceWidth !== shot.width || image.sourceHeight !== shot.height)
|
|
1719
1903
|
throw new StepFailure(
|
|
1720
1904
|
'the window PNG dimensions changed during capture; take a new screenshot',
|
|
1721
1905
|
)
|
|
1722
|
-
|
|
1906
|
+
const frame = frames.recordWindow(image, shot)
|
|
1907
|
+
noteDigest(frame, image)
|
|
1908
|
+
return { frame, image }
|
|
1723
1909
|
}
|
|
1724
1910
|
if (!hostActionAvailable(caps, 'screenshot'))
|
|
1725
1911
|
throw new StepFailure(
|
|
@@ -1729,9 +1915,57 @@ export function createComputerUseTool(
|
|
|
1729
1915
|
if (result.type !== 'screenshot')
|
|
1730
1916
|
throw new Error(`computer_use: the host answered a screenshot with "${result.type}"`)
|
|
1731
1917
|
const shot = result.result
|
|
1732
|
-
const image = await fitPng(shot.data, settings.limits)
|
|
1918
|
+
const image = await fitPng(shot.data, settings.limits())
|
|
1733
1919
|
const display = shot.display ?? assumedDisplay(image.sourceWidth, image.sourceHeight)
|
|
1734
|
-
|
|
1920
|
+
const frame = frames.record(image, display)
|
|
1921
|
+
noteDigest(frame, image)
|
|
1922
|
+
return { frame, image }
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* Before a click, drag or scroll on a window screenshot: the window must still be where that
|
|
1927
|
+
* picture was taken. A moved or resized window turns every coordinate into a different control,
|
|
1928
|
+
* and a closed one has nothing left to click. Nothing is sent. A host that cannot list windows
|
|
1929
|
+
* leaves the check to its own.
|
|
1930
|
+
*/
|
|
1931
|
+
const refuseMovedWindow = async (frame: ScreenshotFrame): Promise<void> => {
|
|
1932
|
+
const shown = frame.window?.window
|
|
1933
|
+
if (!shown || typeof host.listWindows !== 'function') return
|
|
1934
|
+
let windows: readonly WindowInfo[]
|
|
1935
|
+
try {
|
|
1936
|
+
windows = rememberWindows(await host.listWindows(callSignal))
|
|
1937
|
+
} catch {
|
|
1938
|
+
if (callSignal?.aborted) throw new StepFailure('cancelled')
|
|
1939
|
+
return
|
|
1940
|
+
}
|
|
1941
|
+
const now = windows.find((window) => window.id === shown.id)
|
|
1942
|
+
const where = `window ${visibleWindowId(shown.id)}`
|
|
1943
|
+
let why: string | undefined
|
|
1944
|
+
if (!now) why = `${where} is no longer open`
|
|
1945
|
+
else if (now.minimized) why = `${where} is minimized now`
|
|
1946
|
+
else if (
|
|
1947
|
+
now.bounds.x !== shown.bounds.x ||
|
|
1948
|
+
now.bounds.y !== shown.bounds.y ||
|
|
1949
|
+
now.bounds.width !== shown.bounds.width ||
|
|
1950
|
+
now.bounds.height !== shown.bounds.height
|
|
1951
|
+
)
|
|
1952
|
+
why = `${where} moved or was resized since ${frame.id} was taken (${shown.bounds.width}x${shown.bounds.height} at ${shown.bounds.x},${shown.bounds.y}, now ${now.bounds.width}x${now.bounds.height} at ${now.bounds.x},${now.bounds.y})`
|
|
1953
|
+
if (why)
|
|
1954
|
+
throw deliveryFailure({
|
|
1955
|
+
delivery: 'not_delivered',
|
|
1956
|
+
retrySafety: 'safe',
|
|
1957
|
+
detail: `${why}, so nothing was clicked: the coordinates of ${frame.id} no longer point at what they did. Take a new window screenshot (or read its controls with ui_snapshot) and choose the target again.`,
|
|
1958
|
+
})
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
/** A fingerprint of each frame's picture, to tell a click that changed nothing from one that did. */
|
|
1962
|
+
const frameDigest = new Map<string, string>()
|
|
1963
|
+
const noteDigest = (frame: ScreenshotFrame, image: FittedImage): void => {
|
|
1964
|
+
frameDigest.set(frame.id, createHash('sha1').update(image.data).digest('hex'))
|
|
1965
|
+
// Only the few newest are ever compared.
|
|
1966
|
+
if (frameDigest.size > 16)
|
|
1967
|
+
for (const key of [...frameDigest.keys()].slice(0, frameDigest.size - 16))
|
|
1968
|
+
frameDigest.delete(key)
|
|
1735
1969
|
}
|
|
1736
1970
|
|
|
1737
1971
|
const frameFor = (id: string | undefined): ScreenshotFrame => {
|
|
@@ -1864,6 +2098,7 @@ export function createComputerUseTool(
|
|
|
1864
2098
|
const frame = frameFor(frameId)
|
|
1865
2099
|
const at = mapPoint(frame, item.at, 'at')
|
|
1866
2100
|
return step(async () => {
|
|
2101
|
+
await refuseMovedWindow(frame)
|
|
1867
2102
|
const outcome = await runHost(
|
|
1868
2103
|
{
|
|
1869
2104
|
type: 'mouse_click',
|
|
@@ -1893,7 +2128,10 @@ export function createComputerUseTool(
|
|
|
1893
2128
|
const frame = frameFor(frameId)
|
|
1894
2129
|
const from = mapPoint(frame, item.from, 'from')
|
|
1895
2130
|
const to = mapPoint(frame, item.to, 'to')
|
|
1896
|
-
return step(() =>
|
|
2131
|
+
return step(async () => {
|
|
2132
|
+
await refuseMovedWindow(frame)
|
|
2133
|
+
return runHost({ type: 'mouse_drag', from, to, button: item.button }, frame)
|
|
2134
|
+
})
|
|
1897
2135
|
}
|
|
1898
2136
|
case 'scroll': {
|
|
1899
2137
|
const frame = frameFor(frameId)
|
|
@@ -1906,8 +2144,9 @@ export function createComputerUseTool(
|
|
|
1906
2144
|
'window pixel scrolling is unavailable on this host; take a deliberate display screenshot before display scrolling, or use the browser tool for a page',
|
|
1907
2145
|
)
|
|
1908
2146
|
const at = mapPoint(frame, item.at, 'at')
|
|
1909
|
-
return step(() =>
|
|
1910
|
-
|
|
2147
|
+
return step(async () => {
|
|
2148
|
+
await refuseMovedWindow(frame)
|
|
2149
|
+
return runHost(
|
|
1911
2150
|
{
|
|
1912
2151
|
type: 'scroll',
|
|
1913
2152
|
at,
|
|
@@ -1915,8 +2154,8 @@ export function createComputerUseTool(
|
|
|
1915
2154
|
amount: item.amount,
|
|
1916
2155
|
},
|
|
1917
2156
|
frame,
|
|
1918
|
-
)
|
|
1919
|
-
)
|
|
2157
|
+
)
|
|
2158
|
+
})
|
|
1920
2159
|
}
|
|
1921
2160
|
case 'type_text': {
|
|
1922
2161
|
if (item.at)
|
|
@@ -1927,7 +2166,7 @@ export function createComputerUseTool(
|
|
|
1927
2166
|
const frame = frameFor(frameId)
|
|
1928
2167
|
if (item.delivery_mode && !frame.window)
|
|
1929
2168
|
throw new StepFailure('type_text delivery_mode requires a window screenshot')
|
|
1930
|
-
if (frame.window && TERMINAL_APPS
|
|
2169
|
+
if (frame.window && appIs(TERMINAL_APPS, frame.window.window.app))
|
|
1931
2170
|
throw new StepFailure(
|
|
1932
2171
|
'computer_use never types into a terminal window; use the shell tool for a command',
|
|
1933
2172
|
)
|
|
@@ -1953,7 +2192,7 @@ export function createComputerUseTool(
|
|
|
1953
2192
|
throw new StepFailure(
|
|
1954
2193
|
'key delivery_mode requires a window screenshot; take one with screenshot {window_id}',
|
|
1955
2194
|
)
|
|
1956
|
-
if (frame.window && TERMINAL_APPS
|
|
2195
|
+
if (frame.window && appIs(TERMINAL_APPS, frame.window.window.app))
|
|
1957
2196
|
throw new StepFailure(
|
|
1958
2197
|
'computer_use never sends keys to a terminal window; use the shell tool for a command',
|
|
1959
2198
|
)
|
|
@@ -2131,6 +2370,7 @@ export function createComputerUseTool(
|
|
|
2131
2370
|
...(rootRef ? { root: rootRef.hostRef } : {}),
|
|
2132
2371
|
...(rootRef && input.offset !== undefined ? { offset: input.offset } : {}),
|
|
2133
2372
|
...(input.query !== undefined ? { query: input.query } : {}),
|
|
2373
|
+
...(input.role !== undefined ? { role: input.role } : {}),
|
|
2134
2374
|
}
|
|
2135
2375
|
try {
|
|
2136
2376
|
snapshot = await (host.uiSnapshot as NonNullable<ComputerUseHost['uiSnapshot']>)(
|
|
@@ -2141,7 +2381,17 @@ export function createComputerUseTool(
|
|
|
2141
2381
|
} catch (error) {
|
|
2142
2382
|
throw new StepFailure(errorText(error))
|
|
2143
2383
|
}
|
|
2144
|
-
return showUiSnapshot(snapshot, windowId, [], input.root
|
|
2384
|
+
return showUiSnapshot(snapshot, windowId, [], input.root, {
|
|
2385
|
+
...(input.full === true ? { full: true } : {}),
|
|
2386
|
+
...(input.query !== undefined || input.role !== undefined
|
|
2387
|
+
? {
|
|
2388
|
+
filter: [
|
|
2389
|
+
...(input.role !== undefined ? [`role ${quotedText(input.role)}`] : []),
|
|
2390
|
+
...(input.query !== undefined ? [`text ${quotedText(input.query)}`] : []),
|
|
2391
|
+
].join(' and '),
|
|
2392
|
+
}
|
|
2393
|
+
: {}),
|
|
2394
|
+
})
|
|
2145
2395
|
}
|
|
2146
2396
|
|
|
2147
2397
|
/** Number a read tree's controls and show it; this snapshot's refs replace the last one's. */
|
|
@@ -2150,6 +2400,7 @@ export function createComputerUseTool(
|
|
|
2150
2400
|
requestedWindowId: string | undefined,
|
|
2151
2401
|
preface: readonly string[] = [],
|
|
2152
2402
|
openedRef?: string,
|
|
2403
|
+
mode: { readonly full?: boolean; readonly filter?: string } = {},
|
|
2153
2404
|
): ToolResult => {
|
|
2154
2405
|
uiSnapshots += 1
|
|
2155
2406
|
const id = `u${uiSnapshots}`
|
|
@@ -2162,6 +2413,13 @@ export function createComputerUseTool(
|
|
|
2162
2413
|
let shown = 0
|
|
2163
2414
|
let total = 0
|
|
2164
2415
|
let cut = false
|
|
2416
|
+
// What was listed, for the diff against the next read of this window.
|
|
2417
|
+
const entries: {
|
|
2418
|
+
readonly hostRef: string | undefined
|
|
2419
|
+
readonly text: string
|
|
2420
|
+
}[] = []
|
|
2421
|
+
let focusedLine: string | undefined
|
|
2422
|
+
let focusedSecretNow = false
|
|
2165
2423
|
const visit = (element: UiElement, depth: number): void => {
|
|
2166
2424
|
total += 1
|
|
2167
2425
|
const actionable = element.ref.length > 0
|
|
@@ -2179,6 +2437,14 @@ export function createComputerUseTool(
|
|
|
2179
2437
|
cut = true
|
|
2180
2438
|
} else {
|
|
2181
2439
|
lines.push(line)
|
|
2440
|
+
entries.push({
|
|
2441
|
+
hostRef: actionable ? element.ref : undefined,
|
|
2442
|
+
text: line.trim(),
|
|
2443
|
+
})
|
|
2444
|
+
if (focusedLine === undefined && element.states?.includes('focused') === true) {
|
|
2445
|
+
focusedLine = line.trim()
|
|
2446
|
+
focusedSecretNow = isSecretElement(element)
|
|
2447
|
+
}
|
|
2182
2448
|
chars += line.length + 1
|
|
2183
2449
|
shown += 1
|
|
2184
2450
|
if (ref) {
|
|
@@ -2196,6 +2462,7 @@ export function createComputerUseTool(
|
|
|
2196
2462
|
// Refs shown now replace what they name; the rest stay as they were, so a
|
|
2197
2463
|
// region opened by itself leaves the refs outside it usable.
|
|
2198
2464
|
for (const [ref, entry] of refs) uiRefs.set(ref, entry)
|
|
2465
|
+
focusedSecret = focusedSecretNow
|
|
2199
2466
|
if (uiRefs.size > MAX_HELD_UI_REFS) {
|
|
2200
2467
|
for (const ref of [...uiRefs.keys()].slice(0, uiRefs.size - MAX_HELD_UI_REFS)) {
|
|
2201
2468
|
const gone = uiRefs.get(ref)
|
|
@@ -2215,16 +2482,6 @@ export function createComputerUseTool(
|
|
|
2215
2482
|
const window =
|
|
2216
2483
|
snapshot.windowId && /^[\w.:-]{1,64}$/.test(snapshot.windowId) ? snapshot.windowId : undefined
|
|
2217
2484
|
const opened = openedRef !== undefined && /^e\d{1,6}$/.test(openedRef) ? openedRef : undefined
|
|
2218
|
-
const summaryLine = `UI snapshot ${id}${window ? ` of window ${window}` : ''}${snapshot.region ? `${opened ? `, region ${opened}` : ', one region'}` : ''}: ${shown} controls shown${snapshot.total !== undefined && snapshot.total > shown ? ` of ${snapshot.total}` : ''}, ${refs.size} with a ref you can pass to ui_act. A ref names its control and stays usable after later snapshots; if the control has gone or several fit, ui_act says so (STALE_REF, AMBIGUOUS_TARGET) and nothing is sent.`
|
|
2219
|
-
const header = [
|
|
2220
|
-
...preface,
|
|
2221
|
-
summaryLine,
|
|
2222
|
-
...(frame && !frame.window
|
|
2223
|
-
? [
|
|
2224
|
-
`@(x, y) is a control's centre on screenshot ${frame.id}, for a click when ui_act cannot reach it.`,
|
|
2225
|
-
]
|
|
2226
|
-
: []),
|
|
2227
|
-
]
|
|
2228
2485
|
// The window's title and application, when the tree's own root does not
|
|
2229
2486
|
// already say them; inside the frame, since an application sets both.
|
|
2230
2487
|
const about = [
|
|
@@ -2233,42 +2490,120 @@ export function createComputerUseTool(
|
|
|
2233
2490
|
? [`Window title ${quotedText(snapshot.title)}`]
|
|
2234
2491
|
: []),
|
|
2235
2492
|
]
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
const
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2493
|
+
// A window read before shows what changed since, unless the whole tree is
|
|
2494
|
+
// asked for, the read is a region or a filtered one, or either read was cut.
|
|
2495
|
+
const whole = !snapshot.region && mode.filter === undefined
|
|
2496
|
+
const key = windowKey(uiSnapshotWindowId)
|
|
2497
|
+
const before = whole ? uiSnapshotMemory.get(key) : undefined
|
|
2498
|
+
if (whole) uiSnapshotMemory.set(key, { id, entries: cut ? undefined : entries })
|
|
2499
|
+
let changes: { added: string[]; changed: string[]; removed: string[] } | undefined
|
|
2500
|
+
if (before?.entries && !cut && mode.full !== true) {
|
|
2501
|
+
const prevByRef = new Map<string, string>()
|
|
2502
|
+
const prevCounts = new Map<string, number>()
|
|
2503
|
+
for (const entry of before.entries) {
|
|
2504
|
+
if (entry.hostRef) prevByRef.set(entry.hostRef, entry.text)
|
|
2505
|
+
else prevCounts.set(entry.text, (prevCounts.get(entry.text) ?? 0) + 1)
|
|
2506
|
+
}
|
|
2507
|
+
const added: string[] = []
|
|
2508
|
+
const changed: string[] = []
|
|
2509
|
+
const seenRefs = new Set<string>()
|
|
2510
|
+
const left = new Map(prevCounts)
|
|
2511
|
+
for (const entry of entries) {
|
|
2512
|
+
if (entry.hostRef) {
|
|
2513
|
+
seenRefs.add(entry.hostRef)
|
|
2514
|
+
const was = prevByRef.get(entry.hostRef)
|
|
2515
|
+
if (was === undefined) added.push(entry.text)
|
|
2516
|
+
else if (was !== entry.text) changed.push(entry.text)
|
|
2517
|
+
} else {
|
|
2518
|
+
const count = left.get(entry.text) ?? 0
|
|
2519
|
+
if (count > 0) left.set(entry.text, count - 1)
|
|
2520
|
+
else added.push(entry.text)
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
const removed: string[] = []
|
|
2524
|
+
for (const [hostRef, text] of prevByRef) if (!seenRefs.has(hostRef)) removed.push(text)
|
|
2525
|
+
for (const [text, count] of left) for (let i = 0; i < count; i++) removed.push(text)
|
|
2526
|
+
// A window that mostly changed is shorter, and clearer, read whole.
|
|
2527
|
+
if (added.length + changed.length + removed.length < entries.length)
|
|
2528
|
+
changes = { added, changed, removed }
|
|
2529
|
+
}
|
|
2530
|
+
const trailer = [
|
|
2531
|
+
...(focusedLine !== undefined ? [`Focused: ${focusedLine}`] : []),
|
|
2532
|
+
...(snapshot.selectedText !== undefined
|
|
2251
2533
|
? [
|
|
2252
|
-
`
|
|
2534
|
+
`Selected text: ${neutralizeEnvelopeDelimiter(JSON.stringify(snapshot.selectedText.slice(0, 500)))}`,
|
|
2253
2535
|
]
|
|
2254
2536
|
: []),
|
|
2255
|
-
|
|
2537
|
+
]
|
|
2538
|
+
const body = changes
|
|
2539
|
+
? [
|
|
2540
|
+
...about,
|
|
2541
|
+
...changes.added.map((line) => `+ ${line}`),
|
|
2542
|
+
...changes.changed.map((line) => `~ ${line}`),
|
|
2543
|
+
...changes.removed.map((line) => `- ${line}`),
|
|
2544
|
+
...trailer,
|
|
2545
|
+
].join('\n')
|
|
2546
|
+
: [...about, ...lines, ...trailer].join('\n')
|
|
2547
|
+
const noChange =
|
|
2548
|
+
changes !== undefined &&
|
|
2549
|
+
changes.added.length + changes.changed.length + changes.removed.length === 0
|
|
2550
|
+
const where = `${window ? ` of window ${window}` : ''}${snapshot.region ? `${opened ? `, region ${opened}` : ', one region'}` : ''}${mode.filter ? `, only ${mode.filter}` : ''}`
|
|
2551
|
+
const counts = `${shown} controls shown${snapshot.total !== undefined ? ` of the ${snapshot.total} the window holds` : ''}, ${refs.size} with a ref you can pass to ui_act`
|
|
2552
|
+
const summaryLine = changes
|
|
2553
|
+
? noChange
|
|
2554
|
+
? `UI snapshot ${id}${where}: no change since ${before ? before.id : 'the last read'} (${counts}). Refs from that read are used while the host still has them.`
|
|
2555
|
+
: `UI snapshot ${id}${where}: ${changes.added.length} added (+), ${changes.changed.length} changed (~), ${changes.removed.length} gone (-) since ${before ? before.id : 'the last read'}; ${counts}. Refs from that read are used while the host still has them. ui_snapshot {full: true} lists the whole tree.`
|
|
2556
|
+
: `UI snapshot ${id}${where}: ${counts}. A ref names its control and stays usable after later snapshots; if the control has gone or several fit, ui_act says so (STALE_REF, AMBIGUOUS_TARGET) and nothing is sent.${mode.filter && shown <= 1 ? ' Nothing matched the filter.' : ''}`
|
|
2557
|
+
const header = [
|
|
2558
|
+
...preface,
|
|
2559
|
+
summaryLine,
|
|
2560
|
+
...(frame && !frame.window
|
|
2256
2561
|
? [
|
|
2257
|
-
|
|
2562
|
+
`@(x, y) is a control's centre on screenshot ${frame.id}, for a click when ui_act cannot reach it.`,
|
|
2258
2563
|
]
|
|
2259
2564
|
: []),
|
|
2260
2565
|
]
|
|
2566
|
+
const drill =
|
|
2567
|
+
'Open a region with ui_snapshot {root: <its ref>}, or find a control by its text with ui_snapshot {query}.'
|
|
2568
|
+
const footer = changes
|
|
2569
|
+
? []
|
|
2570
|
+
: [
|
|
2571
|
+
...(snapshot.next !== undefined && opened
|
|
2572
|
+
? [
|
|
2573
|
+
`This is one page of a long region. Next page: ui_snapshot {root: "${opened}", offset: ${snapshot.next}}.`,
|
|
2574
|
+
]
|
|
2575
|
+
: []),
|
|
2576
|
+
...(snapshot.outline
|
|
2577
|
+
? [
|
|
2578
|
+
`This is an outline: regions marked "(+N more inside)" hold controls that are not listed. ${drill}`,
|
|
2579
|
+
]
|
|
2580
|
+
: []),
|
|
2581
|
+
...(cut
|
|
2582
|
+
? [
|
|
2583
|
+
`The listing was cut at ${MAX_UI_SNAPSHOT_CHARS} characters after ${shown} of ${total} controls. Drill into the region you need: ${drill}`,
|
|
2584
|
+
]
|
|
2585
|
+
: []),
|
|
2586
|
+
...(snapshot.truncated
|
|
2587
|
+
? [
|
|
2588
|
+
`The host stopped reading the tree before it ended, so some controls are missing. Drill into the region you need: ${drill} A window screenshot shows the rest.`,
|
|
2589
|
+
]
|
|
2590
|
+
: []),
|
|
2591
|
+
]
|
|
2261
2592
|
const text = [
|
|
2262
2593
|
...header,
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2594
|
+
...(noChange && body.length === 0
|
|
2595
|
+
? []
|
|
2596
|
+
: [
|
|
2597
|
+
wrapUntrusted(
|
|
2598
|
+
{
|
|
2599
|
+
kind: 'desktop-ui',
|
|
2600
|
+
...(window ? { attributes: { window } } : {}),
|
|
2601
|
+
provenance:
|
|
2602
|
+
"The accessibility tree of a window on the user's desktop, as the host read it. Names and values are whatever the application shows, which can include text anyone wrote.",
|
|
2603
|
+
},
|
|
2604
|
+
body,
|
|
2605
|
+
),
|
|
2606
|
+
]),
|
|
2272
2607
|
...footer,
|
|
2273
2608
|
].join('\n')
|
|
2274
2609
|
return {
|
|
@@ -2283,6 +2618,7 @@ export function createComputerUseTool(
|
|
|
2283
2618
|
refs: refs.size,
|
|
2284
2619
|
truncated: cut || snapshot.truncated === true,
|
|
2285
2620
|
...(snapshot.outline ? { outline: true } : {}),
|
|
2621
|
+
...(changes ? { diff: noChange ? ('none' as const) : ('changes' as const) } : {}),
|
|
2286
2622
|
...(snapshot.total !== undefined ? { total: snapshot.total } : {}),
|
|
2287
2623
|
},
|
|
2288
2624
|
},
|
|
@@ -2439,15 +2775,15 @@ export function createComputerUseTool(
|
|
|
2439
2775
|
)
|
|
2440
2776
|
}
|
|
2441
2777
|
const front = windows.find((window) => window.focused)
|
|
2442
|
-
if (front && appTier(front.app) === 'view')
|
|
2778
|
+
if (front && appTier(front.app) === 'view' && !browserActionsAllowed(front.app))
|
|
2443
2779
|
throw new StepFailure(
|
|
2444
|
-
`a browser is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use
|
|
2780
|
+
`a browser is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use does not type in a browser unless the person allowed it. Use the browser tool to act on a page, or bring the window you mean to the front (focus_window, or click it) and try again. ${browserWaysForward(applicationName(front.app), readBrowserSetting())}`,
|
|
2445
2781
|
)
|
|
2446
|
-
if (front && IDE_APPS
|
|
2782
|
+
if (front && appIs(IDE_APPS, front.app))
|
|
2447
2783
|
throw new StepFailure(
|
|
2448
2784
|
`an editor is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use clicks in an editor but does not type there. Use the edit tools for a file and the shell tool for a command, or bring the window you mean to the front (focus_window, or click it) and try again`,
|
|
2449
2785
|
)
|
|
2450
|
-
if (front && TERMINAL_APPS
|
|
2786
|
+
if (front && appIs(TERMINAL_APPS, front.app))
|
|
2451
2787
|
throw new StepFailure(
|
|
2452
2788
|
`a terminal is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use never sends keys or text to a terminal. Bring the window you mean to the front (focus_window, or click it) and try again; for a command, use a shell tool instead`,
|
|
2453
2789
|
)
|
|
@@ -2521,7 +2857,11 @@ export function createComputerUseTool(
|
|
|
2521
2857
|
const shrink = display.width / frame.imageWidth
|
|
2522
2858
|
const shrunkNote =
|
|
2523
2859
|
shrink >= 2
|
|
2524
|
-
? ` The display is ${Math.round(shrink * 10) / 10} times larger than this image, so small text is hard to read here
|
|
2860
|
+
? ` The display is ${Math.round(shrink * 10) / 10} times larger than this image, so small text is hard to read here.${
|
|
2861
|
+
windowCaptureAvailable(host, caps)
|
|
2862
|
+
? ' For the application you are working in, take a window screenshot (list_windows, then screenshot with its window_id): it is close to full size.'
|
|
2863
|
+
: ''
|
|
2864
|
+
}`
|
|
2525
2865
|
: ''
|
|
2526
2866
|
return scaled
|
|
2527
2867
|
? `Screenshot ${frame.id}: ${frame.imageWidth}x${frame.imageHeight} pixels, showing the ${display.width}x${display.height} display. Send coordinates in this image's pixels (x 0–${frame.imageWidth - 1}, y 0–${frame.imageHeight - 1}); the tool maps them onto the display.${shrunkNote}`
|
|
@@ -2585,6 +2925,53 @@ export function createComputerUseTool(
|
|
|
2585
2925
|
workingState: pin(shot.frame),
|
|
2586
2926
|
})
|
|
2587
2927
|
|
|
2928
|
+
/**
|
|
2929
|
+
* The first look at a window carries its controls with the picture, so the
|
|
2930
|
+
* model starts from names, not pixels. Later looks are the picture alone
|
|
2931
|
+
* (ui_snapshot shows what changed). A host that cannot read the tree, or a
|
|
2932
|
+
* read that fails, leaves the screenshot as it was.
|
|
2933
|
+
*/
|
|
2934
|
+
const firstLookWithTree = async (
|
|
2935
|
+
shot: Capture,
|
|
2936
|
+
windowId: string | undefined,
|
|
2937
|
+
): Promise<ToolResult> => {
|
|
2938
|
+
const result = screenshotResult(shot)
|
|
2939
|
+
if (
|
|
2940
|
+
!shot.frame.window ||
|
|
2941
|
+
windowId === undefined ||
|
|
2942
|
+
!available.has('ui_snapshot') ||
|
|
2943
|
+
uiSnapshotMemory.has(windowKey(windowId))
|
|
2944
|
+
)
|
|
2945
|
+
return result
|
|
2946
|
+
try {
|
|
2947
|
+
const snapshot = await (host.uiSnapshot as NonNullable<ComputerUseHost['uiSnapshot']>)(
|
|
2948
|
+
windowId,
|
|
2949
|
+
undefined,
|
|
2950
|
+
callSignal,
|
|
2951
|
+
)
|
|
2952
|
+
const tree = showUiSnapshot(snapshot, windowId)
|
|
2953
|
+
const treeBlocks = Array.isArray(tree.content) ? tree.content : []
|
|
2954
|
+
const treeText = treeBlocks.find((block) => block.type === 'text')
|
|
2955
|
+
if (!treeText || treeText.type !== 'text') return result
|
|
2956
|
+
const [head, ...rest] = Array.isArray(result.content) ? result.content : []
|
|
2957
|
+
return {
|
|
2958
|
+
...result,
|
|
2959
|
+
content: [
|
|
2960
|
+
...(head ? [head] : []),
|
|
2961
|
+
{
|
|
2962
|
+
type: 'text',
|
|
2963
|
+
text: `The window's controls, read with this screenshot (ui_act on a ref; pixels only for what the controls do not name):\n${treeText.text}`,
|
|
2964
|
+
},
|
|
2965
|
+
...rest,
|
|
2966
|
+
],
|
|
2967
|
+
data: { ...(result.data as object), ...(tree.data as object) },
|
|
2968
|
+
}
|
|
2969
|
+
} catch (error) {
|
|
2970
|
+
if (callSignal?.aborted) throw error
|
|
2971
|
+
return result
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2588
2975
|
const zoom = async (input: Extract<ActionInput, { type: 'zoom' }>): Promise<ToolResult> => {
|
|
2589
2976
|
const frame = frameFor(input.screenshot_id)
|
|
2590
2977
|
const { region } = input
|
|
@@ -2603,10 +2990,10 @@ export function createComputerUseTool(
|
|
|
2603
2990
|
if (frame.window) {
|
|
2604
2991
|
if (!frame.window.data)
|
|
2605
2992
|
throw new StepFailure(`window screenshot ${frame.id} is stale; capture the window again`)
|
|
2606
|
-
fitted = await cropAndFitPng(frame.window.data, rect, settings.limits)
|
|
2993
|
+
fitted = await cropAndFitPng(frame.window.data, rect, settings.limits())
|
|
2607
2994
|
} else if (caps.regionCapture === true && typeof host.captureRegion === 'function') {
|
|
2608
2995
|
const piece = await host.captureRegion(rect, callSignal)
|
|
2609
|
-
fitted = await fitPng(piece.data, settings.limits)
|
|
2996
|
+
fitted = await fitPng(piece.data, settings.limits())
|
|
2610
2997
|
} else {
|
|
2611
2998
|
const result = await host.execute({ type: 'screenshot' }, callSignal)
|
|
2612
2999
|
if (result.type !== 'screenshot')
|
|
@@ -2631,7 +3018,7 @@ export function createComputerUseTool(
|
|
|
2631
3018
|
width: Math.max(1, Math.min(size.width, Math.ceil((rect.x + rect.width) * sx)) - left),
|
|
2632
3019
|
height: Math.max(1, Math.min(size.height, Math.ceil((rect.y + rect.height) * sy)) - top),
|
|
2633
3020
|
},
|
|
2634
|
-
settings.limits,
|
|
3021
|
+
settings.limits(),
|
|
2635
3022
|
)
|
|
2636
3023
|
}
|
|
2637
3024
|
const detail = fitted.width / onImage.width
|
|
@@ -2692,6 +3079,24 @@ export function createComputerUseTool(
|
|
|
2692
3079
|
const unsent: readonly BatchItem[] = blockedAt >= 0 ? items.slice(blockedAt) : []
|
|
2693
3080
|
const toPlan: readonly BatchItem[] = blockedAt >= 0 ? items.slice(0, blockedAt) : items
|
|
2694
3081
|
const actionFrame = frameId ? frames.get(frameId) : frames.latest()
|
|
3082
|
+
// What the model last saw, to tell afterwards whether a pixel action changed it.
|
|
3083
|
+
const frameBefore = frames.latest()
|
|
3084
|
+
// The baseline for "a new window opened" is the host's list right now, never the last list the
|
|
3085
|
+
// model asked for, which may be old. A list that fails leaves no baseline, so no note.
|
|
3086
|
+
let windowsBefore: readonly WindowInfo[] = []
|
|
3087
|
+
if (
|
|
3088
|
+
typeof host.listWindows === 'function' &&
|
|
3089
|
+
typeof host.uiSnapshot === 'function' &&
|
|
3090
|
+
toPlan.length > 0 &&
|
|
3091
|
+
toPlan.every((item) => TREE_ENDING_STEPS.has(item.type)) &&
|
|
3092
|
+
[...treeUsable.values()].includes(true)
|
|
3093
|
+
) {
|
|
3094
|
+
try {
|
|
3095
|
+
windowsBefore = rememberWindows(await host.listWindows(callSignal))
|
|
3096
|
+
} catch {
|
|
3097
|
+
if (callSignal?.aborted) throw new Error('cancelled')
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
2695
3100
|
const explicitDisplayFrame =
|
|
2696
3101
|
frameId !== undefined && actionFrame !== undefined && !actionFrame.window
|
|
2697
3102
|
if (
|
|
@@ -2842,14 +3247,108 @@ export function createComputerUseTool(
|
|
|
2842
3247
|
!signal?.aborted
|
|
2843
3248
|
let shot: Capture | undefined = frameShot
|
|
2844
3249
|
let shotError: string | undefined
|
|
2845
|
-
|
|
3250
|
+
// A batch of element and keyboard steps on a window whose controls were read ends with what
|
|
3251
|
+
// changed there, not a picture: the model acts on the next refs, and the text is far cheaper.
|
|
3252
|
+
const executed = planned.filter((_, index) => records[index]?.status === 'done')
|
|
3253
|
+
let treeText: string | undefined
|
|
3254
|
+
let treeData: unknown
|
|
3255
|
+
let windowClosed: string | undefined
|
|
3256
|
+
let newWindows: readonly WindowInfo[] = []
|
|
3257
|
+
const treeEnding =
|
|
3258
|
+
looks &&
|
|
3259
|
+
!failure &&
|
|
3260
|
+
frameShot === undefined &&
|
|
3261
|
+
frameId === undefined &&
|
|
3262
|
+
postWindowId !== undefined &&
|
|
3263
|
+
available.has('ui_snapshot') &&
|
|
3264
|
+
typeof host.uiSnapshot === 'function' &&
|
|
3265
|
+
treeUsable.get(windowKey(postWindowId)) === true &&
|
|
3266
|
+
executed.length > 0 &&
|
|
3267
|
+
executed.every((step) => TREE_ENDING_STEPS.has(step.item.type))
|
|
3268
|
+
/** Whether a window is gone from the host's list: the action closed it. */
|
|
3269
|
+
const isGone = async (id: string): Promise<boolean> => {
|
|
3270
|
+
if (typeof host.listWindows !== 'function') return false
|
|
3271
|
+
try {
|
|
3272
|
+
const listed = rememberWindows(await host.listWindows(callSignal))
|
|
3273
|
+
return !listed.some((window) => window.id === id)
|
|
3274
|
+
} catch {
|
|
3275
|
+
return false
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
if (treeEnding && postWindowId !== undefined) {
|
|
3279
|
+
try {
|
|
3280
|
+
await settleAfterActions(host, postWindowId, settings.settleMs, signal)
|
|
3281
|
+
const read = await uiSnapshot({
|
|
3282
|
+
type: 'ui_snapshot',
|
|
3283
|
+
window_id: postWindowId,
|
|
3284
|
+
} as Extract<ActionInput, { type: 'ui_snapshot' }>)
|
|
3285
|
+
const block = Array.isArray(read.content)
|
|
3286
|
+
? read.content.find((entry) => entry.type === 'text')
|
|
3287
|
+
: undefined
|
|
3288
|
+
treeText = block?.type === 'text' ? block.text : read.output
|
|
3289
|
+
treeData = read.data
|
|
3290
|
+
if (windowsBefore.length > 0 && typeof host.listWindows === 'function') {
|
|
3291
|
+
try {
|
|
3292
|
+
const listed = rememberWindows(await host.listWindows(callSignal))
|
|
3293
|
+
newWindows = listed.filter(
|
|
3294
|
+
(window) =>
|
|
3295
|
+
!windowsBefore.some((old) => old.id === window.id) &&
|
|
3296
|
+
!deniedKeys.has(deniedAppKey(window.app)),
|
|
3297
|
+
)
|
|
3298
|
+
} catch {
|
|
3299
|
+
// A list that fails says nothing; the tree above stands.
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
} catch {
|
|
3303
|
+
// Fall back to the picture below; a cancelled call stops there too.
|
|
3304
|
+
if (signal?.aborted) shotError = 'cancelled'
|
|
3305
|
+
else if (await isGone(postWindowId)) windowClosed = postWindowId
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
if (looks && treeText === undefined && windowClosed === undefined) {
|
|
2846
3309
|
try {
|
|
2847
3310
|
await settleAfterActions(host, postWindowId, settings.settleMs, signal)
|
|
2848
3311
|
shot = await capture(postWindowId)
|
|
2849
3312
|
} catch (error) {
|
|
2850
3313
|
shotError = signal?.aborted ? 'cancelled' : errorText(error)
|
|
3314
|
+
if (!signal?.aborted && postWindowId !== undefined && (await isGone(postWindowId)))
|
|
3315
|
+
windowClosed = postWindowId
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
// The window is gone: show what is left of the screen, when the host can.
|
|
3319
|
+
if (
|
|
3320
|
+
windowClosed !== undefined &&
|
|
3321
|
+
shot === undefined &&
|
|
3322
|
+
!signal?.aborted &&
|
|
3323
|
+
hostActionAvailable(caps, 'screenshot')
|
|
3324
|
+
) {
|
|
3325
|
+
try {
|
|
3326
|
+
shot = await capture()
|
|
3327
|
+
shotError = undefined
|
|
3328
|
+
} catch (error) {
|
|
3329
|
+
shotError = errorText(error)
|
|
2851
3330
|
}
|
|
2852
3331
|
}
|
|
3332
|
+
const closedLine =
|
|
3333
|
+
windowClosed !== undefined
|
|
3334
|
+
? `Window ${visibleWindowId(windowClosed)} is no longer open: the action closed it (or the application did). This is a result, not a failure of the tool; list_windows shows what is open now.${shot ? ' The display screenshot follows.' : ''}`
|
|
3335
|
+
: undefined
|
|
3336
|
+
// A pixel action after which the picture is identical to the one before it did nothing visible.
|
|
3337
|
+
const pixelActed = executed.some((step) => PIXEL_STEPS.has(step.item.type))
|
|
3338
|
+
const noVisibleChange =
|
|
3339
|
+
pixelActed &&
|
|
3340
|
+
shot !== undefined &&
|
|
3341
|
+
frameShot === undefined &&
|
|
3342
|
+
frameBefore !== undefined &&
|
|
3343
|
+
shot.frame !== frameBefore &&
|
|
3344
|
+
(frameBefore.window?.window.id ?? null) === (shot.frame.window?.window.id ?? null) &&
|
|
3345
|
+
frameBefore.imageWidth === shot.frame.imageWidth &&
|
|
3346
|
+
frameBefore.imageHeight === shot.frame.imageHeight &&
|
|
3347
|
+
frameDigest.get(frameBefore.id) !== undefined &&
|
|
3348
|
+
frameDigest.get(frameBefore.id) === frameDigest.get(shot.frame.id)
|
|
3349
|
+
const noChangeLine = noVisibleChange
|
|
3350
|
+
? `No visible change: the screen looks the same after the settle wait as in ${frameBefore?.id}. The click may have landed without showing it, or it may have missed; check with a fresh look or a control by ref.`
|
|
3351
|
+
: undefined
|
|
2853
3352
|
|
|
2854
3353
|
const summary = (record: StepRecord, index: number): string => {
|
|
2855
3354
|
const n = single ? '' : `${index + 1}. `
|
|
@@ -2881,10 +3380,33 @@ export function createComputerUseTool(
|
|
|
2881
3380
|
? [`The screenshot after acting failed: ${shotError}. Take one before acting again.`]
|
|
2882
3381
|
: []
|
|
2883
3382
|
const unknownLines = failure?.unknown ? [failure.unknown.message] : []
|
|
2884
|
-
const
|
|
3383
|
+
const afterLines = [
|
|
3384
|
+
...(closedLine ? [closedLine] : []),
|
|
3385
|
+
...(noChangeLine ? [noChangeLine] : []),
|
|
3386
|
+
...(treeText !== undefined ? [treeText] : []),
|
|
3387
|
+
...(newWindows.length > 0
|
|
3388
|
+
? [
|
|
3389
|
+
`A new window opened during the batch; read it with ui_snapshot {window_id}:\n${wrapUntrusted(
|
|
3390
|
+
{
|
|
3391
|
+
kind: 'desktop-windows',
|
|
3392
|
+
provenance:
|
|
3393
|
+
"Windows that opened on the user's desktop during the batch, as the host listed them. Titles are whatever each application shows, which can include text anyone wrote.",
|
|
3394
|
+
},
|
|
3395
|
+
newWindows
|
|
3396
|
+
.slice(0, 5)
|
|
3397
|
+
.map((window) => `- ${window.id} · ${JSON.stringify(window.title)} · ${window.app}`)
|
|
3398
|
+
.join('\n'),
|
|
3399
|
+
)}`,
|
|
3400
|
+
]
|
|
3401
|
+
: []),
|
|
3402
|
+
]
|
|
3403
|
+
const text = [...header, ...stepLines, ...unknownLines, ...afterLines, ...shotLines].join('\n')
|
|
2885
3404
|
const output = [
|
|
2886
3405
|
...header,
|
|
2887
3406
|
...stepLines,
|
|
3407
|
+
...(closedLine ? [closedLine] : []),
|
|
3408
|
+
...(noChangeLine ? [noChangeLine] : []),
|
|
3409
|
+
...(treeText !== undefined ? ['Window controls after the batch follow.'] : []),
|
|
2888
3410
|
...(shot
|
|
2889
3411
|
? [`Screenshot ${shot.frame.id} (${shot.frame.imageWidth}x${shot.frame.imageHeight}).`]
|
|
2890
3412
|
: []),
|
|
@@ -2910,6 +3432,9 @@ export function createComputerUseTool(
|
|
|
2910
3432
|
: { label: record.label, status: record.status },
|
|
2911
3433
|
),
|
|
2912
3434
|
...(shot ? { screenshot: frameData(shot.frame) } : {}),
|
|
3435
|
+
...(treeData && typeof treeData === 'object' ? treeData : {}),
|
|
3436
|
+
...(windowClosed !== undefined ? { windowClosed } : {}),
|
|
3437
|
+
...(noVisibleChange ? { noVisibleChange: true } : {}),
|
|
2913
3438
|
...(failure?.unknown
|
|
2914
3439
|
? {
|
|
2915
3440
|
code: failure.unknown.code,
|
|
@@ -3163,6 +3688,44 @@ export function createComputerUseTool(
|
|
|
3163
3688
|
return `computer_use does not act in ${applicationName(app)}: the person put it off limits. Nothing was done. Use another application, or tell the person you need it and let them change the list.`
|
|
3164
3689
|
}
|
|
3165
3690
|
|
|
3691
|
+
/**
|
|
3692
|
+
* Why an action aimed at a browser window may not run, or undefined when it may. `act` allows
|
|
3693
|
+
* it; `ask` allows it once a person has said yes for this browser in this conversation, asking
|
|
3694
|
+
* them the first time. Nobody to ask, or a no, leaves the window look-only and says what the
|
|
3695
|
+
* person can do instead. A no holds for the rest of the turn so one turn does not ask twice.
|
|
3696
|
+
*/
|
|
3697
|
+
const browserWindowRefusal = async (
|
|
3698
|
+
app: string,
|
|
3699
|
+
name: string,
|
|
3700
|
+
context: ToolContext,
|
|
3701
|
+
): Promise<string | undefined> => {
|
|
3702
|
+
if (browserActionsAllowed(app)) return undefined
|
|
3703
|
+
const key = browserKey(app)
|
|
3704
|
+
const ways = (setting: BrowserWindowsSetting) => browserWaysForward(name, setting)
|
|
3705
|
+
if (readBrowserSetting() === 'look')
|
|
3706
|
+
return `computer_use only looks at ${name}, a browser: it does not click, type or press keys there. Use the browser tool to act on a page; take a screenshot to see what the window shows. Nothing was done. ${ways('look')}`
|
|
3707
|
+
if (!options.askBrowserWindow)
|
|
3708
|
+
return `computer_use only looks at ${name}, a browser, in this session: acting there needs a person's yes and nobody can be asked here. Nothing was done. Use the browser tool, or tell the person what is left for them. ${ways('ask')}`
|
|
3709
|
+
if (browserDeclined.get(key) === String(context.turnId))
|
|
3710
|
+
return `The person said not now to clicking and typing in ${name} in this turn. Nothing was done. Do not ask again this turn. ${ways('ask')}`
|
|
3711
|
+
let answer: BrowserWindowAnswer
|
|
3712
|
+
try {
|
|
3713
|
+
answer = await options.askBrowserWindow({ app, name }, context.abortSignal)
|
|
3714
|
+
} catch {
|
|
3715
|
+
answer = 'unavailable'
|
|
3716
|
+
}
|
|
3717
|
+
if (answer === 'allow') {
|
|
3718
|
+
browserGranted.set(key, name)
|
|
3719
|
+
browserDeclined.delete(key)
|
|
3720
|
+
return undefined
|
|
3721
|
+
}
|
|
3722
|
+
if (answer === 'deny') {
|
|
3723
|
+
browserDeclined.set(key, String(context.turnId))
|
|
3724
|
+
return `The person said not now to clicking and typing in ${name}. Nothing was done. ${ways('ask')}`
|
|
3725
|
+
}
|
|
3726
|
+
return `computer_use only looks at ${name}, a browser: the question whether Namzu may act there was not answered. Nothing was done. ${ways('ask')}`
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3166
3729
|
/**
|
|
3167
3730
|
* Why this call may not run because of the kind of application it would act in, or undefined:
|
|
3168
3731
|
* a browser window is only looked at, a terminal or an editor is clicked but not typed into.
|
|
@@ -3214,9 +3777,22 @@ export function createComputerUseTool(
|
|
|
3214
3777
|
const tier = appTier(app)
|
|
3215
3778
|
const name = applicationName(app)
|
|
3216
3779
|
if (tier === 'view' && type === 'key' && onlyScrollKeys(item.keys)) continue
|
|
3217
|
-
if (tier === 'view')
|
|
3218
|
-
|
|
3219
|
-
|
|
3780
|
+
if (tier === 'view') {
|
|
3781
|
+
const refused = await browserWindowRefusal(app, name, context)
|
|
3782
|
+
if (refused) return refused
|
|
3783
|
+
// A granted browser still never gets a secret typed by the tool: the person types it.
|
|
3784
|
+
const ref = typeof item.ref === 'string' ? uiRefs.get(item.ref) : undefined
|
|
3785
|
+
if (
|
|
3786
|
+
(type === 'type_text' && focusedSecret) ||
|
|
3787
|
+
(setsValue && ref !== undefined && isSecretElement(ref.element))
|
|
3788
|
+
)
|
|
3789
|
+
return `computer_use does not type into a password field in ${name}. Nothing was done. Ask the person to type it themselves, then continue.`
|
|
3790
|
+
}
|
|
3791
|
+
if (
|
|
3792
|
+
tier === 'click' &&
|
|
3793
|
+
!appIs(TERMINAL_APPS, app) &&
|
|
3794
|
+
(TYPING_ACTIONS.has(type) || setsValue)
|
|
3795
|
+
)
|
|
3220
3796
|
return `computer_use clicks in ${name} but does not type or press keys there. Use the shell tool for a command and the edit tools for a file. Nothing was done.`
|
|
3221
3797
|
}
|
|
3222
3798
|
}
|
|
@@ -3241,7 +3817,7 @@ export function createComputerUseTool(
|
|
|
3241
3817
|
try {
|
|
3242
3818
|
switch (input.type) {
|
|
3243
3819
|
case 'screenshot':
|
|
3244
|
-
return
|
|
3820
|
+
return await firstLookWithTree(await capture(input.window_id), input.window_id)
|
|
3245
3821
|
case 'zoom':
|
|
3246
3822
|
return await zoom(input)
|
|
3247
3823
|
case 'ui_snapshot':
|
|
@@ -3270,7 +3846,7 @@ export function createComputerUseTool(
|
|
|
3270
3846
|
|
|
3271
3847
|
const tool = defineTool({
|
|
3272
3848
|
name: COMPUTER_USE_TOOL_NAME,
|
|
3273
|
-
description: buildDescription(host, caps, settings, options.advisor),
|
|
3849
|
+
description: buildDescription(host, caps, settings, options.advisor, browserSetting),
|
|
3274
3850
|
inputSchema: actionSchema,
|
|
3275
3851
|
modelInputSchema: hostModelSchema(host, caps, settings, options.advisor),
|
|
3276
3852
|
validationErrorHint: `Action requirements: ${ALL_ACTIONS.map((action) => actionRequirement(action, host, caps)).join('; ')}. A batch is {"type":"batch","actions":[...]} with at most ${settings.maxBatchActions} actions and no screenshot, zoom, ui_snapshot or batch inside.`,
|
|
@@ -3316,11 +3892,29 @@ export function createComputerUseTool(
|
|
|
3316
3892
|
const result = await runAction(input, context)
|
|
3317
3893
|
if (app && result.success !== false && !appsUsed.has(app) && !isReadOnlyInput(input)) {
|
|
3318
3894
|
appsUsed.add(app)
|
|
3319
|
-
result.data = {
|
|
3895
|
+
result.data = {
|
|
3896
|
+
...(isRecord(result.data) ? result.data : {}),
|
|
3897
|
+
firstUseOf: app,
|
|
3898
|
+
}
|
|
3320
3899
|
}
|
|
3321
3900
|
await observe(input, before, result, context.toolUseId, app)
|
|
3322
3901
|
return result
|
|
3323
3902
|
},
|
|
3324
3903
|
})
|
|
3325
|
-
|
|
3904
|
+
const browserQuestionPending = (app: string): boolean =>
|
|
3905
|
+
appTier(app) === 'view' &&
|
|
3906
|
+
readBrowserSetting() === 'ask' &&
|
|
3907
|
+
options.askBrowserWindow !== undefined &&
|
|
3908
|
+
!browserGranted.has(browserKey(app))
|
|
3909
|
+
return Object.assign(tool, {
|
|
3910
|
+
describeUiRef,
|
|
3911
|
+
appOf,
|
|
3912
|
+
appsOf,
|
|
3913
|
+
consequence,
|
|
3914
|
+
browserGrants: (): string[] => [...browserGranted.values()],
|
|
3915
|
+
revokeBrowserGrant: (app: string): boolean => browserGranted.delete(browserKey(app)),
|
|
3916
|
+
browserQuestionPending,
|
|
3917
|
+
browserAsk: (input: unknown, apps: readonly string[]): string[] =>
|
|
3918
|
+
isReadOnlyInput(input) ? [] : apps.filter((app) => browserQuestionPending(app)),
|
|
3919
|
+
})
|
|
3326
3920
|
}
|