@namzu/computer-use 2.0.2 → 3.1.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.
@@ -30,7 +30,7 @@ export interface McpToolResult {
30
30
  readonly structuredContent?: Record<string, unknown>
31
31
  }
32
32
 
33
- /** The server ran the tool and reported that it failed (`isError: true`). */
33
+ /** A tool refusal from the server, or a local pre-dispatch UI snapshot guard. */
34
34
  export class McpToolError extends Error {
35
35
  override readonly name = 'McpToolError'
36
36
 
@@ -62,6 +62,13 @@ export type McpToolCaller = (
62
62
  timeoutMs?: number,
63
63
  ) => Promise<McpToolResult>
64
64
 
65
+ export interface McpProcessCallOptions {
66
+ /** Refuse before dispatch if a UI token came from another driver process. */
67
+ readonly expectedStarts?: number
68
+ /** Record the process that actually received this call. */
69
+ readonly onProcess?: (starts: number) => void
70
+ }
71
+
65
72
  export interface McpStdioClientOptions {
66
73
  readonly command: string
67
74
  readonly args: readonly string[]
@@ -94,6 +101,7 @@ interface Pending {
94
101
 
95
102
  interface Running {
96
103
  readonly child: ChildProcessWithoutNullStreams
104
+ readonly startOrdinal: number
97
105
  readonly pending: Map<number, Pending>
98
106
  readonly stderr: string[]
99
107
  exited: boolean
@@ -133,8 +141,12 @@ export class McpStdioClient {
133
141
  name: string,
134
142
  args: Record<string, unknown> = {},
135
143
  timeoutMs?: number,
144
+ process?: McpProcessCallOptions,
136
145
  ): Promise<McpToolResult> {
137
146
  const running = await this.ensureStarted()
147
+ if (process?.expectedStarts !== undefined && process.expectedStarts !== running.startOrdinal)
148
+ throw new McpToolError(name, 'stale UI snapshot; take a new one')
149
+ process?.onProcess?.(running.startOrdinal)
138
150
  return this.callOn(running, name, args, timeoutMs)
139
151
  }
140
152
 
@@ -184,10 +196,11 @@ export class McpStdioClient {
184
196
  `Could not start ${command}: ${error instanceof Error ? error.message : String(error)}`,
185
197
  )
186
198
  }
187
- this.startCount++
199
+ const startOrdinal = ++this.startCount
188
200
  let markClosed: () => void = () => undefined
189
201
  const running: Running = {
190
202
  child,
203
+ startOrdinal,
191
204
  pending: new Map(),
192
205
  stderr: [],
193
206
  exited: false,
@@ -352,7 +365,10 @@ export class McpStdioClient {
352
365
  : {
353
366
  jsonrpc: '2.0',
354
367
  id: message.id,
355
- error: { code: -32601, message: `Method not found: ${message.method}` },
368
+ error: {
369
+ code: -32601,
370
+ message: `Method not found: ${message.method}`,
371
+ },
356
372
  }
357
373
  running.child.stdin.write(`${JSON.stringify(reply)}\n`)
358
374
  }
@@ -394,7 +410,13 @@ export class McpStdioClient {
394
410
  : `${command} exited (code ${exitCode ?? 'none'}${signal ? `, ${signal}` : ''}) before it answered ${method}.${tail(running.stderr)}`
395
411
  return new SpawnError(
396
412
  message,
397
- { exitCode: exitCode ?? -1, stdout: Buffer.alloc(0), stderr, timedOut, signal },
413
+ {
414
+ exitCode: exitCode ?? -1,
415
+ stdout: Buffer.alloc(0),
416
+ stderr,
417
+ timedOut,
418
+ signal,
419
+ },
398
420
  command,
399
421
  args,
400
422
  )
@@ -10,6 +10,8 @@ import type {
10
10
  UiElementAction,
11
11
  UiSnapshot,
12
12
  WindowInfo,
13
+ WindowInputAction,
14
+ WindowScreenshotResult,
13
15
  } from '@namzu/sdk'
14
16
 
15
17
  /**
@@ -36,6 +38,10 @@ export interface Adapter {
36
38
  listWindows?(): Promise<readonly WindowInfo[]>
37
39
  /** With `capabilities.windows`. */
38
40
  focusWindow?(id: string): Promise<FocusWindowResult>
41
+ /** With `capabilities.windowCapture`. */
42
+ captureWindow?(id: string): Promise<WindowScreenshotResult>
43
+ /** With `capabilities.windowCapture`. */
44
+ executeWindow?(captureId: string, action: WindowInputAction): Promise<void>
39
45
  /** With `capabilities.regionCapture`. */
40
46
  captureRegion?(rect: Rect): Promise<ScreenshotResult>
41
47
  /** With `capabilities.uiTree`. */