@namzu/sdk 48.2.0 → 48.3.1

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  3. package/dist/runtime/jobs/registry.js +15 -7
  4. package/dist/runtime/jobs/registry.js.map +1 -1
  5. package/dist/tools/builtins/computer-use-coordinates.d.ts +13 -1
  6. package/dist/tools/builtins/computer-use-coordinates.d.ts.map +1 -1
  7. package/dist/tools/builtins/computer-use-coordinates.js +46 -0
  8. package/dist/tools/builtins/computer-use-coordinates.js.map +1 -1
  9. package/dist/tools/builtins/computer-use.d.ts +135 -0
  10. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  11. package/dist/tools/builtins/computer-use.js +255 -54
  12. package/dist/tools/builtins/computer-use.js.map +1 -1
  13. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
  14. package/dist/tools/builtins/wait-for-job-bounds.js +4 -0
  15. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
  16. package/dist/tools/coordinator/wait-with-idle-bound.d.ts.map +1 -1
  17. package/dist/tools/coordinator/wait-with-idle-bound.js +4 -0
  18. package/dist/tools/coordinator/wait-with-idle-bound.js.map +1 -1
  19. package/dist/types/computer-use/index.d.ts +56 -1
  20. package/dist/types/computer-use/index.d.ts.map +1 -1
  21. package/dist/types/computer-use/index.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/runtime/jobs/registry.ts +14 -7
  24. package/src/tools/builtins/computer-use-coordinates.ts +58 -1
  25. package/src/tools/builtins/computer-use.ts +336 -54
  26. package/src/tools/builtins/wait-for-job-bounds.ts +3 -0
  27. package/src/tools/coordinator/wait-with-idle-bound.ts +3 -0
  28. package/src/types/computer-use/index.ts +65 -7
@@ -1,4 +1,9 @@
1
- import type { DisplayInfo, Point, Rect } from '../../types/computer-use/index.js'
1
+ import type {
2
+ DisplayInfo,
3
+ Point,
4
+ Rect,
5
+ WindowScreenshotResult,
6
+ } from '../../types/computer-use/index.js'
2
7
 
3
8
  /**
4
9
  * One screenshot the model was shown: its id, the size of the image it saw,
@@ -12,6 +17,8 @@ export interface ScreenshotFrame {
12
17
  readonly imageHeight: number
13
18
  /** Physical size and virtual-desktop origin of what the image shows. */
14
19
  readonly display: DisplayInfo
20
+ /** Present only for an explicit capture of one window. */
21
+ readonly window?: Omit<WindowScreenshotResult, 'data'> & { readonly data?: Buffer }
15
22
  }
16
23
 
17
24
  /**
@@ -28,7 +35,16 @@ export class ScreenshotFrames {
28
35
 
29
36
  constructor(private readonly capacity = 32) {}
30
37
 
38
+ /** Only the newest window PNG is needed for zoom; older tokens cannot act. */
39
+ private discardOldWindowPixels(): void {
40
+ for (const [id, frame] of this.frames) {
41
+ if (frame.window?.data)
42
+ this.frames.set(id, { ...frame, window: { ...frame.window, data: undefined } })
43
+ }
44
+ }
45
+
31
46
  record(image: { width: number; height: number }, display: DisplayInfo): ScreenshotFrame {
47
+ this.discardOldWindowPixels()
32
48
  this.counter += 1
33
49
  const frame: ScreenshotFrame = {
34
50
  id: `s${this.counter}`,
@@ -46,6 +62,38 @@ export class ScreenshotFrames {
46
62
  return frame
47
63
  }
48
64
 
65
+ recordWindow(
66
+ image: { width: number; height: number },
67
+ window: WindowScreenshotResult,
68
+ ): ScreenshotFrame {
69
+ this.discardOldWindowPixels()
70
+ this.counter += 1
71
+ const frame: ScreenshotFrame = {
72
+ id: `s${this.counter}`,
73
+ imageWidth: image.width,
74
+ imageHeight: image.height,
75
+ // Kept only for the common image-size helpers; a window frame never
76
+ // enters a display-coordinate action or virtual-desktop projection.
77
+ display: {
78
+ id: window.window.id,
79
+ x: window.window.bounds.x,
80
+ y: window.window.bounds.y,
81
+ width: window.width,
82
+ height: window.height,
83
+ scaleFactor: 1,
84
+ },
85
+ window,
86
+ }
87
+ this.frames.set(frame.id, frame)
88
+ this.newest = frame
89
+ while (this.frames.size > this.capacity) {
90
+ const oldest = this.frames.keys().next().value
91
+ if (oldest === undefined) break
92
+ this.frames.delete(oldest)
93
+ }
94
+ return frame
95
+ }
96
+
49
97
  latest(): ScreenshotFrame | undefined {
50
98
  return this.newest
51
99
  }
@@ -96,6 +144,15 @@ export function toDisplayPoint(frame: ScreenshotFrame, point: Point): Point {
96
144
  }
97
145
  }
98
146
 
147
+ /** Model image pixels to the exact PNG pixel space accepted by the window driver. */
148
+ export function toWindowPoint(frame: ScreenshotFrame, point: Point): Point {
149
+ if (!frame.window) throw new Error('computer_use: expected a window screenshot')
150
+ return {
151
+ x: axisToDisplay(point.x, frame.imageWidth, frame.window.width),
152
+ y: axisToDisplay(point.y, frame.imageHeight, frame.window.height),
153
+ }
154
+ }
155
+
99
156
  /** A display-relative physical pixel as the image pixel of `frame` that shows it. */
100
157
  export function toImagePoint(frame: ScreenshotFrame, point: Point): Point {
101
158
  return {