@namzu/sdk 75.0.0 → 76.0.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 +38 -0
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +4 -1
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/bridge/acp/update.d.ts.map +1 -1
- package/dist/bridge/acp/update.js +22 -2
- package/dist/bridge/acp/update.js.map +1 -1
- package/dist/peers/record.d.ts +3 -3
- package/dist/public-runtime.d.ts +2 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +10 -1
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +18 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +100 -1
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/session/workspace/index.d.ts +1 -1
- package/dist/session/workspace/index.d.ts.map +1 -1
- package/dist/session/workspace/index.js +1 -1
- package/dist/session/workspace/index.js.map +1 -1
- package/dist/store/checkpoint/contract.d.ts.map +1 -1
- package/dist/store/checkpoint/contract.js +5 -2
- package/dist/store/checkpoint/contract.js.map +1 -1
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +30 -1
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +19 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +9 -7
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.d.ts +2 -2
- package/dist/tools/builtins/browser.d.ts.map +1 -1
- package/dist/tools/builtins/browser.js +15 -3
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +19 -3
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +150 -50
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/coordinator/agent.d.ts.map +1 -1
- package/dist/tools/coordinator/agent.js +6 -0
- package/dist/tools/coordinator/agent.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +6 -0
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/coordinator/progress.d.ts +9 -0
- package/dist/tools/coordinator/progress.d.ts.map +1 -0
- package/dist/tools/coordinator/progress.js +30 -0
- package/dist/tools/coordinator/progress.js.map +1 -0
- package/dist/tools/shell-output-window.d.ts +12 -0
- package/dist/tools/shell-output-window.d.ts.map +1 -0
- package/dist/tools/shell-output-window.js +92 -0
- package/dist/tools/shell-output-window.js.map +1 -0
- package/dist/types/acp/index.d.ts +3 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/browser/index.d.ts +4 -0
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +4 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/session/checkpoint.d.ts +13 -0
- package/dist/types/session/checkpoint.d.ts.map +1 -1
- package/dist/types/session/checkpoint.js +33 -0
- package/dist/types/session/checkpoint.js.map +1 -1
- package/dist/types/session/events.d.ts +3 -0
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/tool/index.d.ts +15 -0
- 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 +8 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/bridge/acp/server.ts +6 -1
- package/src/bridge/acp/update.ts +23 -2
- package/src/public-runtime.ts +2 -0
- package/src/runtime/query/executor.ts +12 -3
- package/src/session/workspace/git-worktree.ts +115 -1
- package/src/session/workspace/index.ts +6 -1
- package/src/store/checkpoint/contract.ts +9 -2
- package/src/store/session-log/core.ts +34 -1
- package/src/tools/admit-facts.ts +20 -0
- package/src/tools/builtins/bash.ts +11 -12
- package/src/tools/builtins/browser.ts +16 -3
- package/src/tools/builtins/computer-use.ts +188 -44
- package/src/tools/coordinator/agent.ts +6 -0
- package/src/tools/coordinator/index.ts +6 -0
- package/src/tools/coordinator/progress.ts +40 -0
- package/src/tools/shell-output-window.ts +97 -0
- package/src/types/acp/index.ts +3 -0
- package/src/types/browser/index.ts +2 -0
- package/src/types/computer-use/index.ts +17 -0
- package/src/types/session/checkpoint.ts +37 -0
- package/src/types/session/events.ts +3 -0
- package/src/types/tool/index.ts +10 -0
- package/src/types/tool/presentation.ts +12 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import type { ComputerUseStageTimes } from '../../types/computer-use/index.js';
|
|
2
3
|
import type { ComputerUseHost } from '../../types/computer-use/index.js';
|
|
3
4
|
import type { LLMProvider } from '../../types/provider/index.js';
|
|
4
|
-
import type { ToolDefinition } from '../../types/tool/index.js';
|
|
5
|
+
import type { ToolContext, ToolDefinition } from '../../types/tool/index.js';
|
|
5
6
|
import { type ScreenshotLimits } from './computer-use-image.js';
|
|
6
7
|
export { HIGH_RES_SCREENSHOT_LIMITS, STANDARD_SCREENSHOT_LIMITS, screenshotTargetSize, } from './computer-use-image.js';
|
|
7
8
|
export type { ImageSize, ScreenshotLimits } from './computer-use-image.js';
|
|
@@ -47,11 +48,26 @@ export interface ComputerUseAdvisor {
|
|
|
47
48
|
readonly acts: boolean;
|
|
48
49
|
pick(request: ComputerUseAdvisorRequest, signal?: AbortSignal): Promise<ComputerUseAdvice | undefined>;
|
|
49
50
|
}
|
|
51
|
+
/** Operator diagnostics for one computer-use call. */
|
|
52
|
+
export interface ComputerUseTimingRecord {
|
|
53
|
+
readonly app?: string;
|
|
54
|
+
readonly elapsedMs: number;
|
|
55
|
+
readonly stages: ComputerUseStageTimes;
|
|
56
|
+
readonly steps: readonly {
|
|
57
|
+
readonly action: string;
|
|
58
|
+
readonly elapsedMs: number;
|
|
59
|
+
readonly stages: ComputerUseStageTimes;
|
|
60
|
+
}[];
|
|
61
|
+
}
|
|
50
62
|
/**
|
|
51
63
|
* How `createComputerUseTool` sizes screenshots, paces actions and bounds a
|
|
52
64
|
* batch. Every field is optional.
|
|
53
65
|
*/
|
|
54
66
|
export interface ComputerUseToolOptions {
|
|
67
|
+
/** Operator-only timing report. Defaults to on. */
|
|
68
|
+
readonly timings?: boolean | (() => boolean);
|
|
69
|
+
/** Receives one timing record after each call, including failures. */
|
|
70
|
+
readonly onTiming?: (record: ComputerUseTimingRecord, context: ToolContext) => void | Promise<void>;
|
|
55
71
|
/**
|
|
56
72
|
* A second opinion on which control an intent names; see
|
|
57
73
|
* {@link ComputerUseAdvisor}. With one that `acts`, the tool offers `ui_do`
|
|
@@ -235,9 +251,9 @@ declare const actionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
235
251
|
y: z.ZodNumber;
|
|
236
252
|
}, z.core.$strip>;
|
|
237
253
|
direction: z.ZodEnum<{
|
|
254
|
+
left: "left";
|
|
238
255
|
up: "up";
|
|
239
256
|
down: "down";
|
|
240
|
-
left: "left";
|
|
241
257
|
right: "right";
|
|
242
258
|
}>;
|
|
243
259
|
amount: z.ZodNumber;
|
|
@@ -388,9 +404,9 @@ declare const actionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
388
404
|
y: z.ZodNumber;
|
|
389
405
|
}, z.core.$strip>;
|
|
390
406
|
direction: z.ZodEnum<{
|
|
407
|
+
left: "left";
|
|
391
408
|
up: "up";
|
|
392
409
|
down: "down";
|
|
393
|
-
left: "left";
|
|
394
410
|
right: "right";
|
|
395
411
|
}>;
|
|
396
412
|
amount: z.ZodNumber;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computer-use.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/computer-use.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computer-use.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/computer-use.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EACX,qBAAqB,EAErB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAKX,eAAe,EAaf,MAAM,mCAAmC,CAAA;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAc,MAAM,2BAA2B,CAAA;AAexF,OAAO,EAGN,KAAK,gBAAgB,EAIrB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,oBAAoB,GACpB,MAAM,yBAAyB,CAAA;AAChC,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAElE,eAAO,MAAM,sBAAsB,EAAG,cAAuB,CAAA;AA4C7D,2DAA2D;AAC3D,MAAM,WAAW,2BAA2B;IAC3C,0CAA0C;IAC1C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,kEAAkE;IAClE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC5B;AAED,+EAA+E;AAC/E,MAAM,WAAW,yBAAyB;IACzC,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,SAAS,2BAA2B,EAAE,CAAA;IAC3D;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,0GAA0G;AAC1G,MAAM,WAAW,iBAAiB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AAC,OAAO,YAAY,CAAC,CAAA;AAwFtD,6FAA6F;AAC7F,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,4EAA4E;AAC5E,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAK5C;AA87BD;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,WAAW,CAAC;IACnE;;;;;;;OAOG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC9C;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAClD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IACzC;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C,mGAAmG;IACnG,aAAa,IAAI,MAAM,EAAE,CAAA;IACzB,4FAA4F;IAC5F,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IACxC;;;;OAIG;IACH,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IAC5C;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAAA;CAC7D;AAmGD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,eAAe,EACrB,OAAO,GAAE,sBAA2B,GAClC,eAAe,CA2rEjB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { modelReadsImages, resolveProviderCapabilities } from '../../provider/capabilities.js';
|
|
@@ -21,7 +22,7 @@ const DEFAULT_WAIT_FOR_MS = 10_000;
|
|
|
21
22
|
* host without it, one that cannot say, or one that fails keeps the fixed
|
|
22
23
|
* `settleMs` it always had. Cancellation is never swallowed.
|
|
23
24
|
*/
|
|
24
|
-
async function settleAfterActions(host, windowId, settleMs, signal) {
|
|
25
|
+
async function settleAfterActions(host, windowId, settleMs, signal, wait) {
|
|
25
26
|
if (settleMs > 0 && typeof host.settle === 'function') {
|
|
26
27
|
try {
|
|
27
28
|
const settled = await host.settle({ budgetMs: settleMs, ...(windowId !== undefined ? { windowId } : {}) }, signal);
|
|
@@ -32,7 +33,7 @@ async function settleAfterActions(host, windowId, settleMs, signal) {
|
|
|
32
33
|
// Fall through to the fixed wait; a cancelled signal makes it reject at once.
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
await sleep(settleMs, signal);
|
|
36
|
+
await wait(() => sleep(settleMs, signal));
|
|
36
37
|
}
|
|
37
38
|
const MAX_LISTED_WINDOWS = 50;
|
|
38
39
|
/** Steps after which a batch may end with the window's controls instead of a picture. */
|
|
@@ -49,6 +50,28 @@ const ADVICE_MIN_CONFIDENCE = 0.85;
|
|
|
49
50
|
const ADVICE_MIN_MARGIN = 0.4;
|
|
50
51
|
/** The most controls an advisor is asked about at once. */
|
|
51
52
|
const MAX_ADVISED_CANDIDATES = 255;
|
|
53
|
+
function timingTail(elapsedMs, stages, steps) {
|
|
54
|
+
const totals = { ...stages };
|
|
55
|
+
for (const step of steps) {
|
|
56
|
+
for (const stage of Object.keys(step.stages)) {
|
|
57
|
+
totals[stage] = (totals[stage] ?? 0) + (step.stages[stage] ?? 0);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const labels = {
|
|
61
|
+
verify_reads: 'verify',
|
|
62
|
+
settle_wait: 'settle',
|
|
63
|
+
ui_snapshot: 'tree',
|
|
64
|
+
capture_encode: 'capture',
|
|
65
|
+
list_windows: 'windows',
|
|
66
|
+
input_delivery: 'input',
|
|
67
|
+
foreground_gate: 'foreground',
|
|
68
|
+
};
|
|
69
|
+
const detail = Object.keys(totals)
|
|
70
|
+
.sort((a, b) => (totals[b] ?? 0) - (totals[a] ?? 0))
|
|
71
|
+
.slice(0, 3)
|
|
72
|
+
.map((stage) => `${labels[stage]} ${((totals[stage] ?? 0) / 1000).toFixed(1)}`);
|
|
73
|
+
return `took ${(elapsedMs / 1000).toFixed(1)}s${detail.length ? ` (${detail.join(', ')})` : ''}`;
|
|
74
|
+
}
|
|
52
75
|
/** How a browser is told apart in a grant: trimmed, lower case, spaces joined, without `.exe`. */
|
|
53
76
|
function browserKey(app) {
|
|
54
77
|
return deniedAppKey(app).replace(/\s+/g, '-');
|
|
@@ -1298,13 +1321,42 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
1298
1321
|
// (`concurrencySafe: false`), so one variable is enough; every host call below
|
|
1299
1322
|
// passes it so an interrupted turn stops waiting for the desktop.
|
|
1300
1323
|
let callSignal;
|
|
1324
|
+
const timing = new AsyncLocalStorage();
|
|
1325
|
+
const measure = async (stage, run) => {
|
|
1326
|
+
const store = timing.getStore();
|
|
1327
|
+
if (!store)
|
|
1328
|
+
return run();
|
|
1329
|
+
const start = performance.now();
|
|
1330
|
+
try {
|
|
1331
|
+
return await run();
|
|
1332
|
+
}
|
|
1333
|
+
finally {
|
|
1334
|
+
store.stages[stage] = (store.stages[stage] ?? 0) + performance.now() - start;
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
const timeStep = async (action, run) => {
|
|
1338
|
+
const store = timing.getStore();
|
|
1339
|
+
if (!store)
|
|
1340
|
+
return run();
|
|
1341
|
+
const stages = {};
|
|
1342
|
+
const start = performance.now();
|
|
1343
|
+
try {
|
|
1344
|
+
return await timing.run({ stages, steps: store.steps }, run);
|
|
1345
|
+
}
|
|
1346
|
+
finally {
|
|
1347
|
+
store.steps.push({ action, elapsedMs: performance.now() - start, stages });
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
const settle = (window, signal) => host.withTiming
|
|
1351
|
+
? settleAfterActions(host, window, settings.settleMs, signal, (wait) => measure('settle_wait', wait))
|
|
1352
|
+
: measure('settle_wait', () => settleAfterActions(host, window, settings.settleMs, signal, (wait) => wait()));
|
|
1301
1353
|
/** Capture the display or one explicitly named window, fit it, and number it. */
|
|
1302
1354
|
const capture = async (windowId) => {
|
|
1303
1355
|
if (windowId !== undefined) {
|
|
1304
1356
|
if (!windowCaptureAvailable(host, caps))
|
|
1305
1357
|
throw new StepFailure('this host cannot capture a named window; no desktop screenshot was taken');
|
|
1306
1358
|
const shot = await host.captureWindow(windowId, callSignal);
|
|
1307
|
-
const image = await fitPng(shot.data, settings.limits());
|
|
1359
|
+
const image = await measure('capture_encode', () => fitPng(shot.data, settings.limits()));
|
|
1308
1360
|
if (image.sourceWidth !== shot.width || image.sourceHeight !== shot.height)
|
|
1309
1361
|
throw new StepFailure('the window PNG dimensions changed during capture; take a new screenshot');
|
|
1310
1362
|
const frame = frames.recordWindow(image, shot);
|
|
@@ -1317,7 +1369,7 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
1317
1369
|
if (result.type !== 'screenshot')
|
|
1318
1370
|
throw new Error(`computer_use: the host answered a screenshot with "${result.type}"`);
|
|
1319
1371
|
const shot = result.result;
|
|
1320
|
-
const image = await fitPng(shot.data, settings.limits());
|
|
1372
|
+
const image = await measure('capture_encode', () => fitPng(shot.data, settings.limits()));
|
|
1321
1373
|
const display = shot.display ?? assumedDisplay(image.sourceWidth, image.sourceHeight);
|
|
1322
1374
|
const frame = frames.record(image, display);
|
|
1323
1375
|
noteDigest(frame, image);
|
|
@@ -2254,7 +2306,7 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
2254
2306
|
}
|
|
2255
2307
|
else if (caps.regionCapture === true && typeof host.captureRegion === 'function') {
|
|
2256
2308
|
const piece = await host.captureRegion(rect, callSignal);
|
|
2257
|
-
fitted = await fitPng(piece.data, settings.limits());
|
|
2309
|
+
fitted = await measure('capture_encode', () => fitPng(piece.data, settings.limits()));
|
|
2258
2310
|
}
|
|
2259
2311
|
else {
|
|
2260
2312
|
const result = await host.execute({ type: 'screenshot' }, callSignal);
|
|
@@ -2392,6 +2444,27 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
2392
2444
|
break;
|
|
2393
2445
|
}
|
|
2394
2446
|
try {
|
|
2447
|
+
await timeStep(step.item.type, runStep);
|
|
2448
|
+
}
|
|
2449
|
+
catch (error) {
|
|
2450
|
+
const unknown = error instanceof StepFailure ? error.unknown : undefined;
|
|
2451
|
+
const delivery = error instanceof StepFailure ? error.delivery : undefined;
|
|
2452
|
+
const retrySafety = error instanceof StepFailure ? error.retrySafety : undefined;
|
|
2453
|
+
const message = signal?.aborted ? 'cancelled' : errorText(error);
|
|
2454
|
+
failure = { index, error: message, ...(unknown ? { unknown } : {}) };
|
|
2455
|
+
records.push({
|
|
2456
|
+
label: step.label,
|
|
2457
|
+
status: 'failed',
|
|
2458
|
+
error: message,
|
|
2459
|
+
...(unknown ? { unknown } : {}),
|
|
2460
|
+
...(delivery ? { delivery } : {}),
|
|
2461
|
+
...(retrySafety ? { retrySafety } : {}),
|
|
2462
|
+
});
|
|
2463
|
+
if (delivery === 'delivered_unverified' || unknown)
|
|
2464
|
+
changed = true;
|
|
2465
|
+
break;
|
|
2466
|
+
}
|
|
2467
|
+
async function runStep() {
|
|
2395
2468
|
const keyboard = step.item.type === 'type_text' || step.item.type === 'key';
|
|
2396
2469
|
if (keyboard && !actionFrame?.window && !frontChecked) {
|
|
2397
2470
|
await refuseTerminalInFront();
|
|
@@ -2422,27 +2495,6 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
2422
2495
|
if (step.mutating)
|
|
2423
2496
|
changed = true;
|
|
2424
2497
|
}
|
|
2425
|
-
catch (error) {
|
|
2426
|
-
const unknown = error instanceof StepFailure ? error.unknown : undefined;
|
|
2427
|
-
const delivery = error instanceof StepFailure ? error.delivery : undefined;
|
|
2428
|
-
const retrySafety = error instanceof StepFailure ? error.retrySafety : undefined;
|
|
2429
|
-
const message = signal?.aborted ? 'cancelled' : errorText(error);
|
|
2430
|
-
failure = { index, error: message, ...(unknown ? { unknown } : {}) };
|
|
2431
|
-
records.push({
|
|
2432
|
-
label: step.label,
|
|
2433
|
-
status: 'failed',
|
|
2434
|
-
error: message,
|
|
2435
|
-
...(unknown ? { unknown } : {}),
|
|
2436
|
-
...(delivery ? { delivery } : {}),
|
|
2437
|
-
...(retrySafety ? { retrySafety } : {}),
|
|
2438
|
-
});
|
|
2439
|
-
// A step that may have acted changed the desktop even though it failed.
|
|
2440
|
-
if (delivery === 'delivered_unverified')
|
|
2441
|
-
changed = true;
|
|
2442
|
-
if (unknown)
|
|
2443
|
-
changed = true;
|
|
2444
|
-
break;
|
|
2445
|
-
}
|
|
2446
2498
|
}
|
|
2447
2499
|
for (const step of planned.slice(records.length))
|
|
2448
2500
|
records.push({ label: step.label, status: 'not run' });
|
|
@@ -2455,7 +2507,7 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
2455
2507
|
if (unsent.length > 0 && !failure && !signal?.aborted) {
|
|
2456
2508
|
try {
|
|
2457
2509
|
if (changed)
|
|
2458
|
-
await
|
|
2510
|
+
await settle(undefined, signal);
|
|
2459
2511
|
frameShot = await capture();
|
|
2460
2512
|
const before = single
|
|
2461
2513
|
? ''
|
|
@@ -2516,7 +2568,7 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
2516
2568
|
};
|
|
2517
2569
|
if (treeEnding && postWindowId !== undefined) {
|
|
2518
2570
|
try {
|
|
2519
|
-
await
|
|
2571
|
+
await settle(postWindowId, signal);
|
|
2520
2572
|
const read = await uiSnapshot({
|
|
2521
2573
|
type: 'ui_snapshot',
|
|
2522
2574
|
window_id: postWindowId,
|
|
@@ -2547,7 +2599,7 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
2547
2599
|
}
|
|
2548
2600
|
if (looks && treeText === undefined && windowClosed === undefined) {
|
|
2549
2601
|
try {
|
|
2550
|
-
await
|
|
2602
|
+
await settle(postWindowId, signal);
|
|
2551
2603
|
shot = await capture(postWindowId);
|
|
2552
2604
|
}
|
|
2553
2605
|
catch (error) {
|
|
@@ -3027,13 +3079,13 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
3027
3079
|
try {
|
|
3028
3080
|
switch (input.type) {
|
|
3029
3081
|
case 'screenshot':
|
|
3030
|
-
return await firstLookWithTree(await capture(input.window_id), input.window_id);
|
|
3082
|
+
return await timeStep(input.type, async () => firstLookWithTree(await capture(input.window_id), input.window_id));
|
|
3031
3083
|
case 'zoom':
|
|
3032
|
-
return await zoom(input);
|
|
3084
|
+
return await timeStep(input.type, () => zoom(input));
|
|
3033
3085
|
case 'ui_snapshot':
|
|
3034
|
-
return await uiSnapshot(input);
|
|
3086
|
+
return await timeStep(input.type, () => uiSnapshot(input));
|
|
3035
3087
|
case 'wait_for':
|
|
3036
|
-
return await waitFor(input, context);
|
|
3088
|
+
return await timeStep(input.type, () => waitFor(input, context));
|
|
3037
3089
|
case 'batch':
|
|
3038
3090
|
return await runSteps(input.actions, input.screenshot_id, context, false);
|
|
3039
3091
|
default: {
|
|
@@ -3079,38 +3131,86 @@ export function createComputerUseTool(host, options = {}) {
|
|
|
3079
3131
|
presentResult: (_input, result) => {
|
|
3080
3132
|
// The first call to work on an application says so, so a person reading the
|
|
3081
3133
|
// conversation can see which applications this conversation has used.
|
|
3082
|
-
const
|
|
3134
|
+
const data = isRecord(result.data) ? result.data : undefined;
|
|
3135
|
+
const first = data?.firstUseOf;
|
|
3136
|
+
const tail = typeof data?.timingTail === 'string' ? data.timingTail : undefined;
|
|
3083
3137
|
if (result.success && typeof first === 'string')
|
|
3084
3138
|
return {
|
|
3085
3139
|
kind: 'generic',
|
|
3086
|
-
label: `Using ${applicationName(first)}`,
|
|
3140
|
+
label: `Using ${applicationName(first)}${tail ? ` · ${tail}` : ''}`,
|
|
3087
3141
|
presentation: 'activity',
|
|
3088
3142
|
};
|
|
3143
|
+
if (tail)
|
|
3144
|
+
return {
|
|
3145
|
+
kind: 'terminal',
|
|
3146
|
+
output: [result.success ? result.output : (result.error ?? result.output), tail]
|
|
3147
|
+
.filter(Boolean)
|
|
3148
|
+
.join('\n'),
|
|
3149
|
+
};
|
|
3089
3150
|
return result.success && ACKNOWLEDGEMENT.test(result.output)
|
|
3090
3151
|
? { kind: 'generic', label: result.output, visibility: 'hidden' }
|
|
3091
3152
|
: undefined;
|
|
3092
3153
|
},
|
|
3093
3154
|
async execute(input, context) {
|
|
3094
|
-
const
|
|
3095
|
-
if (
|
|
3096
|
-
return
|
|
3097
|
-
const
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3155
|
+
const show = typeof options.timings === 'function' ? options.timings() : options.timings !== false;
|
|
3156
|
+
if (!options.onTiming && (!show || !host.withTiming))
|
|
3157
|
+
return execute();
|
|
3158
|
+
const stages = {};
|
|
3159
|
+
const steps = [];
|
|
3160
|
+
const start = performance.now();
|
|
3161
|
+
let elapsedMs;
|
|
3162
|
+
let result;
|
|
3163
|
+
try {
|
|
3164
|
+
result = await timing.run({ stages, steps }, () => host.withTiming?.((stage, ms) => {
|
|
3165
|
+
const current = timing.getStore()?.stages;
|
|
3166
|
+
if (current)
|
|
3167
|
+
current[stage] = (current[stage] ?? 0) + ms;
|
|
3168
|
+
}, execute) ?? execute());
|
|
3169
|
+
}
|
|
3170
|
+
finally {
|
|
3171
|
+
elapsedMs = performance.now() - start;
|
|
3172
|
+
const record = { app: appKnown(input), elapsedMs, stages, steps };
|
|
3173
|
+
try {
|
|
3174
|
+
await options.onTiming?.({
|
|
3175
|
+
...(record.app ? { app: record.app } : {}),
|
|
3176
|
+
elapsedMs,
|
|
3177
|
+
stages,
|
|
3178
|
+
steps,
|
|
3179
|
+
}, context);
|
|
3180
|
+
}
|
|
3181
|
+
catch {
|
|
3182
|
+
// Diagnostics must never change an input's outcome.
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
if (show) {
|
|
3107
3186
|
result.data = {
|
|
3108
3187
|
...(isRecord(result.data) ? result.data : {}),
|
|
3109
|
-
|
|
3188
|
+
timingTail: timingTail(elapsedMs, stages, steps),
|
|
3110
3189
|
};
|
|
3111
3190
|
}
|
|
3112
|
-
await observe(input, before, result, context.toolUseId, app);
|
|
3113
3191
|
return result;
|
|
3192
|
+
async function execute() {
|
|
3193
|
+
const keptOut = await deniedAppRefusal(input, context);
|
|
3194
|
+
if (keptOut)
|
|
3195
|
+
return { success: false, output: '', error: keptOut };
|
|
3196
|
+
const tiered = await appTierRefusal(input, context);
|
|
3197
|
+
if (tiered)
|
|
3198
|
+
return { success: false, output: '', error: tiered };
|
|
3199
|
+
const shotId = 'screenshot_id' in input ? input.screenshot_id : undefined;
|
|
3200
|
+
const before = shotId ? frames.get(shotId) : frames.latest();
|
|
3201
|
+
// Only what is already known: acting must not cost the host a call it would not make.
|
|
3202
|
+
const app = appKnown(input);
|
|
3203
|
+
const result = await runAction(input, context);
|
|
3204
|
+
if (app && result.success !== false && !appsUsed.has(app) && !isReadOnlyInput(input)) {
|
|
3205
|
+
appsUsed.add(app);
|
|
3206
|
+
result.data = {
|
|
3207
|
+
...(isRecord(result.data) ? result.data : {}),
|
|
3208
|
+
firstUseOf: app,
|
|
3209
|
+
};
|
|
3210
|
+
}
|
|
3211
|
+
await observe(input, before, result, context.toolUseId, app);
|
|
3212
|
+
return result;
|
|
3213
|
+
}
|
|
3114
3214
|
},
|
|
3115
3215
|
});
|
|
3116
3216
|
const browserQuestionPending = (app) => appTier(app) === 'view' &&
|