@namzu/sdk 45.0.0 → 46.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.
Files changed (281) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/dist/authorization/gate.d.ts +5 -2
  3. package/dist/authorization/gate.d.ts.map +1 -1
  4. package/dist/authorization/gate.js +35 -4
  5. package/dist/authorization/gate.js.map +1 -1
  6. package/dist/authorization/rules.d.ts.map +1 -1
  7. package/dist/authorization/rules.js +56 -6
  8. package/dist/authorization/rules.js.map +1 -1
  9. package/dist/authorization/shell-lexer.d.ts +38 -0
  10. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  11. package/dist/authorization/shell-lexer.js +88 -57
  12. package/dist/authorization/shell-lexer.js.map +1 -1
  13. package/dist/bridge/a2a/mapper.d.ts.map +1 -1
  14. package/dist/bridge/a2a/mapper.js +2 -0
  15. package/dist/bridge/a2a/mapper.js.map +1 -1
  16. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  17. package/dist/bridge/sse/mapper.js +1 -0
  18. package/dist/bridge/sse/mapper.js.map +1 -1
  19. package/dist/directory/types.d.ts +2 -0
  20. package/dist/directory/types.d.ts.map +1 -1
  21. package/dist/directory/types.js.map +1 -1
  22. package/dist/manager/resident/outbox.d.ts +4 -4
  23. package/dist/pricing/catalogue.generated.d.ts.map +1 -1
  24. package/dist/pricing/catalogue.generated.js +28 -4
  25. package/dist/pricing/catalogue.generated.js.map +1 -1
  26. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  27. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  28. package/dist/prompt/coding-agent-doctrine.js +1 -0
  29. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  30. package/dist/public-runtime.d.ts +6 -3
  31. package/dist/public-runtime.d.ts.map +1 -1
  32. package/dist/public-runtime.js +14 -2
  33. package/dist/public-runtime.js.map +1 -1
  34. package/dist/public-tools.d.ts +7 -2
  35. package/dist/public-tools.d.ts.map +1 -1
  36. package/dist/public-tools.js +15 -2
  37. package/dist/public-tools.js.map +1 -1
  38. package/dist/public-types.d.ts +8 -2
  39. package/dist/public-types.d.ts.map +1 -1
  40. package/dist/registry/tool/callable.d.ts +22 -0
  41. package/dist/registry/tool/callable.d.ts.map +1 -0
  42. package/dist/registry/tool/callable.js +29 -0
  43. package/dist/registry/tool/callable.js.map +1 -0
  44. package/dist/registry/tool/execute.d.ts.map +1 -1
  45. package/dist/registry/tool/execute.js +8 -1
  46. package/dist/registry/tool/execute.js.map +1 -1
  47. package/dist/runtime/query/declined.d.ts +12 -0
  48. package/dist/runtime/query/declined.d.ts.map +1 -0
  49. package/dist/runtime/query/declined.js +12 -0
  50. package/dist/runtime/query/declined.js.map +1 -0
  51. package/dist/runtime/query/executor/tool-call-admission.d.ts +37 -11
  52. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  53. package/dist/runtime/query/executor/tool-call-admission.js +38 -12
  54. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  55. package/dist/runtime/query/executor.d.ts +7 -3
  56. package/dist/runtime/query/executor.d.ts.map +1 -1
  57. package/dist/runtime/query/executor.js +32 -7
  58. package/dist/runtime/query/executor.js.map +1 -1
  59. package/dist/runtime/query/index.d.ts.map +1 -1
  60. package/dist/runtime/query/index.js +1 -0
  61. package/dist/runtime/query/index.js.map +1 -1
  62. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  63. package/dist/runtime/query/iteration/index.js +7 -0
  64. package/dist/runtime/query/iteration/index.js.map +1 -1
  65. package/dist/runtime/query/iteration/phases/context.d.ts +6 -0
  66. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  67. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  68. package/dist/runtime/query/iteration/phases/handoff.d.ts +22 -0
  69. package/dist/runtime/query/iteration/phases/handoff.d.ts.map +1 -0
  70. package/dist/runtime/query/iteration/phases/handoff.js +65 -0
  71. package/dist/runtime/query/iteration/phases/handoff.js.map +1 -0
  72. package/dist/runtime/query/iteration/phases/index.d.ts +1 -0
  73. package/dist/runtime/query/iteration/phases/index.d.ts.map +1 -1
  74. package/dist/runtime/query/iteration/phases/index.js +1 -0
  75. package/dist/runtime/query/iteration/phases/index.js.map +1 -1
  76. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  77. package/dist/runtime/query/iteration/phases/tool-review.js +8 -3
  78. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  79. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  80. package/dist/runtime/query/resume-pending.js +3 -2
  81. package/dist/runtime/query/resume-pending.js.map +1 -1
  82. package/dist/runtime/query/review-policy.d.ts +43 -0
  83. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  84. package/dist/runtime/query/review-policy.js +63 -19
  85. package/dist/runtime/query/review-policy.js.map +1 -1
  86. package/dist/schedules/cron.d.ts +21 -0
  87. package/dist/schedules/cron.d.ts.map +1 -0
  88. package/dist/schedules/cron.js +167 -0
  89. package/dist/schedules/cron.js.map +1 -0
  90. package/dist/schedules/describe.d.ts +14 -0
  91. package/dist/schedules/describe.d.ts.map +1 -0
  92. package/dist/schedules/describe.js +133 -0
  93. package/dist/schedules/describe.js.map +1 -0
  94. package/dist/schedules/errors.d.ts +11 -0
  95. package/dist/schedules/errors.d.ts.map +1 -0
  96. package/dist/schedules/errors.js +15 -0
  97. package/dist/schedules/errors.js.map +1 -0
  98. package/dist/schedules/evaluate.d.ts +35 -0
  99. package/dist/schedules/evaluate.d.ts.map +1 -0
  100. package/dist/schedules/evaluate.js +158 -0
  101. package/dist/schedules/evaluate.js.map +1 -0
  102. package/dist/schedules/index.d.ts +11 -0
  103. package/dist/schedules/index.d.ts.map +1 -0
  104. package/dist/schedules/index.js +8 -0
  105. package/dist/schedules/index.js.map +1 -0
  106. package/dist/schedules/next-fire.d.ts +50 -0
  107. package/dist/schedules/next-fire.d.ts.map +1 -0
  108. package/dist/schedules/next-fire.js +250 -0
  109. package/dist/schedules/next-fire.js.map +1 -0
  110. package/dist/schedules/spec.d.ts +30 -0
  111. package/dist/schedules/spec.d.ts.map +1 -0
  112. package/dist/schedules/spec.js +169 -0
  113. package/dist/schedules/spec.js.map +1 -0
  114. package/dist/schedules/types.d.ts +144 -0
  115. package/dist/schedules/types.d.ts.map +1 -0
  116. package/dist/schedules/types.js +11 -0
  117. package/dist/schedules/types.js.map +1 -0
  118. package/dist/schedules/tz.d.ts +44 -0
  119. package/dist/schedules/tz.d.ts.map +1 -0
  120. package/dist/schedules/tz.js +141 -0
  121. package/dist/schedules/tz.js.map +1 -0
  122. package/dist/skills/index.d.ts +1 -1
  123. package/dist/skills/index.d.ts.map +1 -1
  124. package/dist/skills/index.js +1 -1
  125. package/dist/skills/index.js.map +1 -1
  126. package/dist/skills/loader.d.ts +16 -3
  127. package/dist/skills/loader.d.ts.map +1 -1
  128. package/dist/skills/loader.js +48 -4
  129. package/dist/skills/loader.js.map +1 -1
  130. package/dist/skills/registry.d.ts +6 -0
  131. package/dist/skills/registry.d.ts.map +1 -1
  132. package/dist/skills/registry.js +1 -0
  133. package/dist/skills/registry.js.map +1 -1
  134. package/dist/tools/builtins/browser-url.d.ts +83 -0
  135. package/dist/tools/builtins/browser-url.d.ts.map +1 -0
  136. package/dist/tools/builtins/browser-url.js +240 -0
  137. package/dist/tools/builtins/browser-url.js.map +1 -0
  138. package/dist/tools/builtins/browser.d.ts +367 -0
  139. package/dist/tools/builtins/browser.d.ts.map +1 -0
  140. package/dist/tools/builtins/browser.js +704 -0
  141. package/dist/tools/builtins/browser.js.map +1 -0
  142. package/dist/tools/builtins/computer-use-coordinates.d.ts +65 -0
  143. package/dist/tools/builtins/computer-use-coordinates.d.ts.map +1 -0
  144. package/dist/tools/builtins/computer-use-coordinates.js +123 -0
  145. package/dist/tools/builtins/computer-use-coordinates.js.map +1 -0
  146. package/dist/tools/builtins/computer-use-image.d.ts +77 -0
  147. package/dist/tools/builtins/computer-use-image.d.ts.map +1 -0
  148. package/dist/tools/builtins/computer-use-image.js +223 -0
  149. package/dist/tools/builtins/computer-use-image.js.map +1 -0
  150. package/dist/tools/builtins/computer-use.d.ts +519 -14
  151. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  152. package/dist/tools/builtins/computer-use.js +1188 -183
  153. package/dist/tools/builtins/computer-use.js.map +1 -1
  154. package/dist/tools/builtins/index.d.ts +2 -1
  155. package/dist/tools/builtins/index.d.ts.map +1 -1
  156. package/dist/tools/builtins/index.js +1 -1
  157. package/dist/tools/builtins/index.js.map +1 -1
  158. package/dist/tools/builtins/skill.d.ts +74 -0
  159. package/dist/tools/builtins/skill.d.ts.map +1 -1
  160. package/dist/tools/builtins/skill.js +214 -159
  161. package/dist/tools/builtins/skill.js.map +1 -1
  162. package/dist/tools/defineTool.d.ts +4 -0
  163. package/dist/tools/defineTool.d.ts.map +1 -1
  164. package/dist/tools/defineTool.js +8 -0
  165. package/dist/tools/defineTool.js.map +1 -1
  166. package/dist/tools/schedules/index.d.ts +5 -0
  167. package/dist/tools/schedules/index.d.ts.map +1 -0
  168. package/dist/tools/schedules/index.js +4 -0
  169. package/dist/tools/schedules/index.js.map +1 -0
  170. package/dist/tools/schedules/loop-tool.d.ts +14 -0
  171. package/dist/tools/schedules/loop-tool.d.ts.map +1 -0
  172. package/dist/tools/schedules/loop-tool.js +81 -0
  173. package/dist/tools/schedules/loop-tool.js.map +1 -0
  174. package/dist/tools/schedules/present.d.ts +16 -0
  175. package/dist/tools/schedules/present.d.ts.map +1 -0
  176. package/dist/tools/schedules/present.js +71 -0
  177. package/dist/tools/schedules/present.js.map +1 -0
  178. package/dist/tools/schedules/prompt-scan.d.ts +17 -0
  179. package/dist/tools/schedules/prompt-scan.d.ts.map +1 -0
  180. package/dist/tools/schedules/prompt-scan.js +92 -0
  181. package/dist/tools/schedules/prompt-scan.js.map +1 -0
  182. package/dist/tools/schedules/schedule-tool.d.ts +17 -0
  183. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -0
  184. package/dist/tools/schedules/schedule-tool.js +418 -0
  185. package/dist/tools/schedules/schedule-tool.js.map +1 -0
  186. package/dist/tools/schedules/types.d.ts +252 -0
  187. package/dist/tools/schedules/types.d.ts.map +1 -0
  188. package/dist/tools/schedules/types.js +11 -0
  189. package/dist/tools/schedules/types.js.map +1 -0
  190. package/dist/types/authorization/index.d.ts +107 -9
  191. package/dist/types/authorization/index.d.ts.map +1 -1
  192. package/dist/types/authorization/index.js +16 -1
  193. package/dist/types/authorization/index.js.map +1 -1
  194. package/dist/types/browser/index.d.ts +280 -0
  195. package/dist/types/browser/index.d.ts.map +1 -0
  196. package/dist/types/browser/index.js +12 -0
  197. package/dist/types/browser/index.js.map +1 -0
  198. package/dist/types/computer-use/index.d.ts +176 -0
  199. package/dist/types/computer-use/index.d.ts.map +1 -1
  200. package/dist/types/computer-use/index.js.map +1 -1
  201. package/dist/types/session/events.d.ts +6 -0
  202. package/dist/types/session/events.d.ts.map +1 -1
  203. package/dist/types/session/events.js.map +1 -1
  204. package/dist/types/session/records.d.ts +23 -0
  205. package/dist/types/session/records.d.ts.map +1 -1
  206. package/dist/types/session/records.js +9 -0
  207. package/dist/types/session/records.js.map +1 -1
  208. package/dist/types/tool/index.d.ts +60 -0
  209. package/dist/types/tool/index.d.ts.map +1 -1
  210. package/dist/types/tool/index.js.map +1 -1
  211. package/dist/types/tool/presentation.d.ts +7 -0
  212. package/dist/types/tool/presentation.d.ts.map +1 -1
  213. package/dist/utils/frontmatter.d.ts +18 -2
  214. package/dist/utils/frontmatter.d.ts.map +1 -1
  215. package/dist/utils/frontmatter.js +13 -3
  216. package/dist/utils/frontmatter.js.map +1 -1
  217. package/dist/utils/id.d.ts +8 -0
  218. package/dist/utils/id.d.ts.map +1 -1
  219. package/dist/utils/id.js +12 -0
  220. package/dist/utils/id.js.map +1 -1
  221. package/package.json +3 -1
  222. package/src/authorization/gate.ts +37 -4
  223. package/src/authorization/rules.ts +55 -7
  224. package/src/authorization/shell-lexer.ts +109 -51
  225. package/src/bridge/a2a/mapper.ts +2 -0
  226. package/src/bridge/sse/mapper.ts +1 -0
  227. package/src/directory/types.ts +2 -0
  228. package/src/pricing/catalogue.generated.ts +28 -4
  229. package/src/pricing/rates.source.json +27 -6
  230. package/src/prompt/coding-agent-doctrine.ts +1 -0
  231. package/src/public-runtime.ts +43 -1
  232. package/src/public-tools.ts +54 -1
  233. package/src/public-types.ts +55 -0
  234. package/src/registry/tool/callable.ts +37 -0
  235. package/src/registry/tool/execute.ts +8 -1
  236. package/src/runtime/query/declined.ts +12 -0
  237. package/src/runtime/query/executor/tool-call-admission.ts +60 -16
  238. package/src/runtime/query/executor.ts +36 -5
  239. package/src/runtime/query/index.ts +1 -0
  240. package/src/runtime/query/iteration/index.ts +8 -0
  241. package/src/runtime/query/iteration/phases/context.ts +6 -0
  242. package/src/runtime/query/iteration/phases/handoff.ts +74 -0
  243. package/src/runtime/query/iteration/phases/index.ts +1 -0
  244. package/src/runtime/query/iteration/phases/tool-review.ts +11 -4
  245. package/src/runtime/query/resume-pending.ts +3 -2
  246. package/src/runtime/query/review-policy.ts +107 -18
  247. package/src/schedules/cron.ts +202 -0
  248. package/src/schedules/describe.ts +138 -0
  249. package/src/schedules/errors.ts +15 -0
  250. package/src/schedules/evaluate.ts +178 -0
  251. package/src/schedules/index.ts +18 -0
  252. package/src/schedules/next-fire.ts +257 -0
  253. package/src/schedules/spec.ts +210 -0
  254. package/src/schedules/types.ts +163 -0
  255. package/src/schedules/tz.ts +155 -0
  256. package/src/skills/index.ts +1 -1
  257. package/src/skills/loader.ts +55 -4
  258. package/src/skills/registry.ts +8 -0
  259. package/src/tools/builtins/browser-url.ts +251 -0
  260. package/src/tools/builtins/browser.ts +817 -0
  261. package/src/tools/builtins/computer-use-coordinates.ts +144 -0
  262. package/src/tools/builtins/computer-use-image.ts +278 -0
  263. package/src/tools/builtins/computer-use.ts +1485 -191
  264. package/src/tools/builtins/index.ts +7 -1
  265. package/src/tools/builtins/skill.ts +304 -156
  266. package/src/tools/defineTool.ts +13 -0
  267. package/src/tools/schedules/index.ts +4 -0
  268. package/src/tools/schedules/loop-tool.ts +85 -0
  269. package/src/tools/schedules/present.ts +88 -0
  270. package/src/tools/schedules/prompt-scan.ts +96 -0
  271. package/src/tools/schedules/schedule-tool.ts +482 -0
  272. package/src/tools/schedules/types.ts +265 -0
  273. package/src/types/authorization/index.ts +81 -2
  274. package/src/types/browser/index.ts +341 -0
  275. package/src/types/computer-use/index.ts +202 -0
  276. package/src/types/session/events.ts +6 -0
  277. package/src/types/session/records.ts +10 -0
  278. package/src/types/tool/index.ts +61 -0
  279. package/src/types/tool/presentation.ts +7 -0
  280. package/src/utils/frontmatter.ts +29 -3
  281. package/src/utils/id.ts +14 -0
@@ -0,0 +1,341 @@
1
+ // ---------------------------------------------------------------------------
2
+ // The browser contract: what a browser host does for the `browser` and
3
+ // `browser_act` tools. The SDK owns the model-facing tools and this
4
+ // interface; a host package (for example `@namzu/browser`) owns the engine.
5
+ // ---------------------------------------------------------------------------
6
+
7
+ /** Every action the `browser` tool (observe and navigate) can ask for. */
8
+ export type BrowserObserveActionName =
9
+ | 'navigate'
10
+ | 'back'
11
+ | 'forward'
12
+ | 'reload'
13
+ | 'snapshot'
14
+ | 'screenshot'
15
+ | 'scroll'
16
+ | 'wait_for'
17
+ | 'tabs'
18
+
19
+ /** Every action the `browser_act` tool (change the page) can ask for. */
20
+ export type BrowserActActionName =
21
+ | 'click'
22
+ | 'type'
23
+ | 'fill_form'
24
+ | 'select'
25
+ | 'press'
26
+ | 'hover'
27
+ | 'upload'
28
+ | 'dialog'
29
+
30
+ export type BrowserActionName = BrowserObserveActionName | BrowserActActionName
31
+
32
+ export type BrowserScrollDirection = 'up' | 'down' | 'left' | 'right'
33
+
34
+ export type BrowserTabsOp = 'list' | 'select' | 'close' | 'new'
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // Capabilities — frozen at host construction; the model reads them through
38
+ // the tools' descriptions and schemas.
39
+ // ---------------------------------------------------------------------------
40
+
41
+ export interface BrowserCapabilities {
42
+ /** Which engine drives the browser, in words: `local-chromium`, `windows-cdp`. */
43
+ readonly engine: string
44
+ /** The browser window is not shown. */
45
+ readonly headless: boolean
46
+ /** `screenshot` can return an image. */
47
+ readonly screenshot: boolean
48
+ /** `upload` can attach a local file to a file input. */
49
+ readonly upload: boolean
50
+ /**
51
+ * Exact action subset when known. Absent: every action whose broad flag
52
+ * above allows it. Actions outside the subset are removed from the model
53
+ * schema and refused before the host is called.
54
+ */
55
+ readonly supportedActions?: readonly BrowserActionName[]
56
+ /**
57
+ * The most snapshot text one call returns. The tool cuts anything longer.
58
+ * Absent: {@link BROWSER_SNAPSHOT_MAX_CHARS}.
59
+ */
60
+ readonly snapshotMaxChars?: number
61
+ /**
62
+ * Why the browser cannot be used at all — the engine is not installed,
63
+ * the profile is missing. Present, both tools stay mounted, say this in
64
+ * their descriptions and refuse every call with it, so the model reads
65
+ * the reason once and tells the user instead of retrying.
66
+ */
67
+ readonly unavailableReason?: string
68
+ }
69
+
70
+ /** Default and ceiling of snapshot text per call, in characters. */
71
+ export const BROWSER_SNAPSHOT_MAX_CHARS = 20_000
72
+
73
+ /** Longest `wait_for` the tool accepts, in milliseconds. */
74
+ export const BROWSER_WAIT_MAX_MS = 30_000
75
+
76
+ /** Most fields one `fill_form` call may set. */
77
+ export const BROWSER_FILL_FORM_MAX_FIELDS = 20
78
+
79
+ // ---------------------------------------------------------------------------
80
+ // Actions
81
+ // ---------------------------------------------------------------------------
82
+
83
+ /**
84
+ * What the `browser` tool asks of the host. Every URL here has already been
85
+ * canonicalised by the tool (see `canonicalizeBrowserUrl`): only http, https
86
+ * or `about:blank`, no credentials, never a cloud metadata address.
87
+ */
88
+ export type BrowserObserveAction =
89
+ | { readonly action: 'navigate'; readonly url: string }
90
+ | { readonly action: 'back' }
91
+ | { readonly action: 'forward' }
92
+ | { readonly action: 'reload' }
93
+ | { readonly action: 'snapshot'; readonly ref?: string; readonly cursor?: string }
94
+ | { readonly action: 'screenshot'; readonly ref?: string; readonly fullPage?: boolean }
95
+ | {
96
+ readonly action: 'scroll'
97
+ readonly direction: BrowserScrollDirection
98
+ readonly ref?: string
99
+ /** Screens to scroll; the host's default when absent. */
100
+ readonly amount?: number
101
+ }
102
+ | {
103
+ readonly action: 'wait_for'
104
+ readonly text?: string
105
+ readonly textGone?: string
106
+ readonly timeMs?: number
107
+ }
108
+ | {
109
+ readonly action: 'tabs'
110
+ readonly op: BrowserTabsOp
111
+ /** `select` and `close`: the tab id from `list` or a page header. */
112
+ readonly tab?: string
113
+ /** `new`: the address to open; `about:blank` when absent. */
114
+ readonly url?: string
115
+ }
116
+
117
+ export interface BrowserFormField {
118
+ readonly ref: string
119
+ /** Text for a text box; `true`/`false` for a checkbox; the option's label for a select. */
120
+ readonly value: string
121
+ }
122
+
123
+ /** The change a `browser_act` call makes. */
124
+ export type BrowserActOperation =
125
+ | { readonly action: 'click'; readonly ref: string; readonly doubleClick?: boolean }
126
+ | {
127
+ readonly action: 'type'
128
+ readonly ref: string
129
+ readonly text: string
130
+ /** Press Enter after typing. */
131
+ readonly submit?: boolean
132
+ }
133
+ | { readonly action: 'fill_form'; readonly fields: readonly BrowserFormField[] }
134
+ | { readonly action: 'select'; readonly ref: string; readonly values: readonly string[] }
135
+ | { readonly action: 'press'; readonly key: string; readonly ref?: string }
136
+ | { readonly action: 'hover'; readonly ref: string }
137
+ | { readonly action: 'upload'; readonly ref: string; readonly path: string }
138
+ | { readonly action: 'dialog'; readonly accept: boolean; readonly promptText?: string }
139
+
140
+ /**
141
+ * What the `browser_act` tool asks of the host.
142
+ *
143
+ * `origin` is the page origin the model read from the snapshot header
144
+ * (`Page: <origin> — …`), canonicalised by the tool. **The host MUST compare
145
+ * it with the live origin of the page it is about to act on, immediately
146
+ * before acting, and throw a {@link BrowserOriginMismatch} without acting
147
+ * when they differ.** That comparison is what binds an approval of "click
148
+ * Place order on shop.example.com" to shop.example.com: a redirect between
149
+ * the snapshot and the click must not carry the click to another site.
150
+ */
151
+ export type BrowserActAction = BrowserActOperation & {
152
+ readonly origin: string
153
+ /** Return a snapshot of the page after the action. */
154
+ readonly snapshot?: boolean
155
+ }
156
+
157
+ // ---------------------------------------------------------------------------
158
+ // Results
159
+ // ---------------------------------------------------------------------------
160
+
161
+ /** The page an action left the browser on, as the host observed it. */
162
+ export interface BrowserPageInfo {
163
+ /** Canonical origin (`https://github.com`), or `null` for `about:blank`. */
164
+ readonly origin: string
165
+ readonly url: string
166
+ /** The document title. Page-controlled: the tool quotes and cuts it. */
167
+ readonly title: string
168
+ /** The tab's id, e.g. `t1`. */
169
+ readonly tab: string
170
+ }
171
+
172
+ export interface BrowserTabInfo extends BrowserPageInfo {
173
+ readonly active: boolean
174
+ }
175
+
176
+ export interface BrowserSnapshot {
177
+ readonly page: BrowserPageInfo
178
+ /**
179
+ * The accessibility tree as text, one element per line, each actionable
180
+ * element carrying `[ref=eN]`. Page-controlled: the tool wraps it as
181
+ * untrusted content.
182
+ */
183
+ readonly text: string
184
+ /** Present when more text follows; pass it back as `cursor`. */
185
+ readonly nextCursor?: string
186
+ }
187
+
188
+ export interface BrowserScreenshot {
189
+ readonly page: BrowserPageInfo
190
+ readonly data: Uint8Array
191
+ readonly mimeType: 'image/png' | 'image/jpeg'
192
+ readonly width: number
193
+ readonly height: number
194
+ }
195
+
196
+ /**
197
+ * What an action produced. Every field is optional because actions differ;
198
+ * the tool renders whichever are present.
199
+ */
200
+ export interface BrowserResult {
201
+ /** The page after the action. */
202
+ readonly page?: BrowserPageInfo
203
+ /**
204
+ * The host's own note, in the host's words — "download of report.pdf
205
+ * cancelled", "dialog accepted". Never page text: the tool shows it
206
+ * outside the untrusted envelope.
207
+ */
208
+ readonly message?: string
209
+ readonly snapshot?: BrowserSnapshot
210
+ readonly screenshot?: BrowserScreenshot
211
+ readonly tabs?: readonly BrowserTabInfo[]
212
+ }
213
+
214
+ /** What a snapshot said about one ref, for labelling a call before it runs. */
215
+ export interface BrowserRefDescription {
216
+ /** ARIA role: `button`, `link`, `textbox`. */
217
+ readonly role: string
218
+ /** Accessible name. Page-controlled. */
219
+ readonly name?: string
220
+ }
221
+
222
+ /** Who and where, for labels and reviews. May change between calls. */
223
+ export interface BrowserSessionInfo {
224
+ /** The profile the browser runs under. */
225
+ readonly profile?: string
226
+ /** Canonical origin of the active tab, when the host knows it. */
227
+ readonly origin?: string
228
+ }
229
+
230
+ // ---------------------------------------------------------------------------
231
+ // Structural errors. Hosts throw values carrying these shapes; the tools
232
+ // recognise them by shape, so a separately installed host and SDK need not
233
+ // share an error class.
234
+ // ---------------------------------------------------------------------------
235
+
236
+ /** The live page is not on the origin a `browser_act` call named. Nothing was done. */
237
+ export interface BrowserOriginMismatch {
238
+ readonly code: 'browser_origin_mismatch'
239
+ readonly expected: string
240
+ readonly actual: string
241
+ readonly message: string
242
+ }
243
+
244
+ /** The ref is not on the current page: it came from an older snapshot. Nothing was done. */
245
+ export interface BrowserStaleRef {
246
+ readonly code: 'browser_stale_ref'
247
+ readonly ref: string
248
+ readonly message: string
249
+ }
250
+
251
+ /** Why the page needs a person. */
252
+ export type BrowserHumanRequiredReason =
253
+ | 'sign-in'
254
+ | 'two-factor'
255
+ | 'captcha'
256
+ | 'bot-block'
257
+ | 'http-auth'
258
+ | 'credential-field'
259
+
260
+ /**
261
+ * The page needs a person: a sign-in, a second factor, a CAPTCHA, a bot
262
+ * wall, or a field that takes a password or one-time code. The agent must
263
+ * stop and hand over; it never signs in, solves or types a credential.
264
+ */
265
+ export interface BrowserHumanRequired {
266
+ readonly code: 'browser_human_required'
267
+ readonly reason: BrowserHumanRequiredReason
268
+ readonly origin: string
269
+ readonly message: string
270
+ readonly profile?: string
271
+ /** The command that opens a visible window on this profile, e.g. `namzu browser login work https://…`. */
272
+ readonly loginCommand?: string
273
+ }
274
+
275
+ /**
276
+ * A page-changing action started and did not report a clean completion. The
277
+ * page may already have changed, so replaying it is unsafe.
278
+ */
279
+ export interface BrowserOutcomeUnknown {
280
+ readonly code: 'browser_outcome_unknown'
281
+ readonly action: BrowserActionName
282
+ readonly outcome: 'unknown'
283
+ readonly retrySafety: 'unsafe'
284
+ readonly message: string
285
+ }
286
+
287
+ /** The site policy does not allow this origin at the level the call needs. */
288
+ export interface BrowserSiteDenied {
289
+ readonly code: 'browser_site_denied'
290
+ readonly origin: string
291
+ readonly message: string
292
+ }
293
+
294
+ export type BrowserHostError =
295
+ | BrowserOriginMismatch
296
+ | BrowserStaleRef
297
+ | BrowserHumanRequired
298
+ | BrowserOutcomeUnknown
299
+ | BrowserSiteDenied
300
+
301
+ // ---------------------------------------------------------------------------
302
+ // Host
303
+ // ---------------------------------------------------------------------------
304
+
305
+ export interface BrowserCallOptions {
306
+ /** Fires when the call is cancelled or times out. */
307
+ readonly signal?: AbortSignal
308
+ }
309
+
310
+ /**
311
+ * A browser the tools drive. Implementations live outside `@namzu/sdk`.
312
+ *
313
+ * The host is where the site policy is enforced after the fact: whatever the
314
+ * gate approved, the host re-checks the page a navigation, redirect or popup
315
+ * actually landed on, and the live origin before every `act`.
316
+ */
317
+ export interface BrowserHost {
318
+ readonly id: string
319
+ readonly capabilities: BrowserCapabilities
320
+
321
+ /** Observe or navigate. Throws a {@link BrowserHostError} shape to refuse. */
322
+ observe(action: BrowserObserveAction, options?: BrowserCallOptions): Promise<BrowserResult>
323
+ /**
324
+ * Change the page. MUST check `action.origin` against the live page first
325
+ * (see {@link BrowserActAction}). Throws a {@link BrowserHostError} shape
326
+ * to refuse.
327
+ */
328
+ act(action: BrowserActAction, options?: BrowserCallOptions): Promise<BrowserResult>
329
+
330
+ /**
331
+ * What the most recent snapshot said about `ref`, synchronously and
332
+ * without touching the page, for the label a person approves. Undefined
333
+ * when the ref is unknown.
334
+ */
335
+ describeRef?(ref: string): BrowserRefDescription | undefined
336
+ /** The current profile and page, synchronously, for labels. */
337
+ session?(): BrowserSessionInfo
338
+
339
+ initialize?(): Promise<void>
340
+ dispose?(): Promise<void>
341
+ }
@@ -44,10 +44,41 @@ export interface ComputerUseCapabilities {
44
44
  * model reads the reason once and does not try again.
45
45
  */
46
46
  readonly unavailableReason?: string
47
+ /**
48
+ * The host implements {@link ComputerUseHost.listWindows} and
49
+ * {@link ComputerUseHost.focusWindow}. Absent or false, the tool does not
50
+ * offer `list_windows` or `focus_window`, even when the methods exist.
51
+ */
52
+ readonly windows?: boolean
53
+ /**
54
+ * The host implements {@link ComputerUseHost.captureRegion}. Absent or
55
+ * false, `zoom` still works: the tool crops a full capture instead, which
56
+ * costs one whole-display capture per zoom.
57
+ */
58
+ readonly regionCapture?: boolean
59
+ /**
60
+ * The host implements {@link ComputerUseHost.uiSnapshot} and
61
+ * {@link ComputerUseHost.uiAct}: an accessibility tree (Windows UI
62
+ * Automation, macOS AX, AT-SPI, or a driver that wraps one) whose
63
+ * elements can be acted on by reference instead of by pixel.
64
+ *
65
+ * @experimental The UI-tree surface is reserved for the host packages that
66
+ * implement it; its shape may still change in a minor release.
67
+ */
68
+ readonly uiTree?: boolean
47
69
  }
48
70
 
49
71
  // ---------------------------------------------------------------------------
50
72
  // Geometry + screenshot payload
73
+ //
74
+ // Units, once for the whole file: every coordinate and size a host accepts or
75
+ // returns is in PHYSICAL pixels — the pixels of the captured bitmap, not
76
+ // logical points or DPI-scaled units. A 3440x1440 monitor at 150 % scaling is
77
+ // 3440x1440 here. A point a host is asked to act on is relative to the
78
+ // top-left of the display it last captured (the primary display until a host
79
+ // offers display selection); the host adds that display's origin itself.
80
+ // Window and UI-element bounds are the exception and say so: they are in
81
+ // virtual-desktop physical pixels, because a window can span displays.
51
82
  // ---------------------------------------------------------------------------
52
83
 
53
84
  export interface DisplayGeometry {
@@ -56,11 +87,144 @@ export interface DisplayGeometry {
56
87
  readonly scaleFactor: number
57
88
  }
58
89
 
90
+ /**
91
+ * The display a capture shows.
92
+ *
93
+ * `x`/`y` place it in the virtual desktop (a monitor left of the primary has
94
+ * a negative `x`); `width`/`height` are its physical size. `scaleFactor` is
95
+ * physical pixels per logical pixel — 1 at 96 DPI on Windows, 1.5 at 150 %,
96
+ * 2 on a Retina panel — reported for the host UI and for diagnosis; the tool
97
+ * never multiplies by it, because every coordinate crossing this interface
98
+ * is already physical.
99
+ */
100
+ export interface DisplayInfo {
101
+ /** Stable for the host's lifetime; what a host would accept to select this display. */
102
+ readonly id: string
103
+ readonly x: number
104
+ readonly y: number
105
+ readonly width: number
106
+ readonly height: number
107
+ readonly scaleFactor: number
108
+ /** True for the display the operating system calls primary. */
109
+ readonly primary?: boolean
110
+ }
111
+
59
112
  export interface ScreenshotResult {
60
113
  readonly data: Buffer
61
114
  readonly mimeType: 'image/png'
115
+ /** Physical pixel width of `data`. */
62
116
  readonly width: number
117
+ /** Physical pixel height of `data`. */
63
118
  readonly height: number
119
+ /**
120
+ * The display this capture shows. A host should always set it; one written
121
+ * before it existed does not, and the tool then assumes a single display at
122
+ * the origin whose size is the capture's own, with a scale factor of 1.
123
+ */
124
+ readonly display?: DisplayInfo
125
+ }
126
+
127
+ /** A rectangle in physical pixels. What its origin is relative to depends on where it appears. */
128
+ export interface Rect {
129
+ readonly x: number
130
+ readonly y: number
131
+ readonly width: number
132
+ readonly height: number
133
+ }
134
+
135
+ /** One top-level window, as {@link ComputerUseHost.listWindows} reports it. */
136
+ export interface WindowInfo {
137
+ /** Opaque and host-defined (an HWND in hex, a CGWindowID, an X11 window id); valid for {@link ComputerUseHost.focusWindow}. */
138
+ readonly id: string
139
+ readonly title: string
140
+ /** Application or process name, e.g. `msedge`, `Teams`, `Code`. */
141
+ readonly app: string
142
+ readonly pid: number
143
+ /** Virtual-desktop physical pixels — not display-relative. */
144
+ readonly bounds: Rect
145
+ readonly focused: boolean
146
+ readonly minimized: boolean
147
+ }
148
+
149
+ /**
150
+ * What {@link ComputerUseHost.focusWindow} achieved. Bringing a window to
151
+ * the front is a request the operating system can refuse (Windows'
152
+ * foreground lock is the common case), so a host reports the window that is
153
+ * actually in front afterwards rather than assuming its request held.
154
+ */
155
+ export interface FocusWindowResult {
156
+ /** True only when `focusedId` is the requested window. */
157
+ readonly ok: boolean
158
+ /** The window in front after the attempt, or null when none could be read. */
159
+ readonly focusedId: string | null
160
+ }
161
+
162
+ /**
163
+ * An action an accessibility element can take by reference.
164
+ *
165
+ * @experimental See {@link ComputerUseCapabilities.uiTree}.
166
+ */
167
+ export type UiElementAction =
168
+ | 'invoke'
169
+ | 'focus'
170
+ | 'set_value'
171
+ | 'toggle'
172
+ | 'select'
173
+ | 'expand'
174
+ | 'collapse'
175
+ | 'scroll_into_view'
176
+
177
+ /**
178
+ * One accessibility element.
179
+ *
180
+ * @experimental See {@link ComputerUseCapabilities.uiTree}.
181
+ */
182
+ export interface UiElement {
183
+ /**
184
+ * Opaque reference for {@link ComputerUseHost.uiAct}, valid until the
185
+ * host's next snapshot. Empty for an element the host cannot act on (a
186
+ * label, a group), which is in the tree for what it says.
187
+ */
188
+ readonly ref: string
189
+ /** Platform role, e.g. `Button`, `Edit`, `ListItem` (UIA ControlType) or `AXButton`. */
190
+ readonly role: string
191
+ readonly name: string
192
+ readonly value?: string
193
+ /** A platform automation id, when the element has one. */
194
+ readonly automationId?: string
195
+ /** Virtual-desktop physical pixels, when the element is on screen. */
196
+ readonly bounds?: Rect
197
+ /** Element states such as `focused`, `disabled`, `selected`, `checked`, `expanded`. */
198
+ readonly states?: readonly string[]
199
+ readonly actions?: readonly UiElementAction[]
200
+ readonly children?: readonly UiElement[]
201
+ }
202
+
203
+ /**
204
+ * An accessibility tree for one window.
205
+ *
206
+ * @experimental See {@link ComputerUseCapabilities.uiTree}.
207
+ */
208
+ export interface UiSnapshot {
209
+ readonly windowId?: string
210
+ /** The window's title, as its application sets it. */
211
+ readonly title?: string
212
+ /** The owning application or process name, as in {@link WindowInfo.app}. */
213
+ readonly app?: string
214
+ readonly root: UiElement
215
+ /** True when the host stopped walking the tree before it ended (a size or time bound). */
216
+ readonly truncated?: boolean
217
+ }
218
+
219
+ /**
220
+ * What {@link ComputerUseHost.uiAct} did.
221
+ *
222
+ * @experimental See {@link ComputerUseCapabilities.uiTree}.
223
+ */
224
+ export interface UiActResult {
225
+ readonly ok: boolean
226
+ /** Why it did not, in words the model can act on (a stale ref, a disabled element). */
227
+ readonly detail?: string
64
228
  }
65
229
 
66
230
  export interface Point {
@@ -152,8 +316,46 @@ export interface ComputerUseHost {
152
316
  readonly capabilities: ComputerUseCapabilities
153
317
 
154
318
  getDisplayGeometry(): Promise<DisplayGeometry>
319
+ /**
320
+ * Points in `action` are physical pixels relative to the display of the
321
+ * most recent capture; a `screenshot` result carries that display in
322
+ * {@link ScreenshotResult.display}.
323
+ */
155
324
  execute(action: ComputerUseAction): Promise<ComputerUseResult>
156
325
 
326
+ /**
327
+ * The visible, titled top-level windows, front to back where the platform
328
+ * knows the order. Offered to the model only with
329
+ * {@link ComputerUseCapabilities.windows}.
330
+ */
331
+ listWindows?(): Promise<readonly WindowInfo[]>
332
+ /**
333
+ * Bring a window to the front, restoring it when minimized. Offered only
334
+ * with {@link ComputerUseCapabilities.windows}.
335
+ */
336
+ focusWindow?(id: string): Promise<FocusWindowResult>
337
+ /**
338
+ * Capture one region of the current display at full physical resolution.
339
+ * `rect` is display-relative physical pixels; the result's `width` and
340
+ * `height` are the region's. Used by `zoom` when
341
+ * {@link ComputerUseCapabilities.regionCapture} is set.
342
+ */
343
+ captureRegion?(rect: Rect): Promise<ScreenshotResult>
344
+ /**
345
+ * The accessibility tree of one window, or of the focused window when
346
+ * `windowId` is omitted. Offered only with {@link ComputerUseCapabilities.uiTree}.
347
+ *
348
+ * @experimental
349
+ */
350
+ uiSnapshot?(windowId?: string): Promise<UiSnapshot>
351
+ /**
352
+ * Act on an element from the latest {@link uiSnapshot}. `value` is the text
353
+ * for `set_value`. Offered only with {@link ComputerUseCapabilities.uiTree}.
354
+ *
355
+ * @experimental
356
+ */
357
+ uiAct?(ref: string, action: UiElementAction, value?: string): Promise<UiActResult>
358
+
157
359
  initialize?(): Promise<void>
158
360
  dispose?(): Promise<void>
159
361
  }
@@ -534,6 +534,12 @@ type CoreSessionEvent =
534
534
  providerError?: import('../provider/error.js').ProviderErrorInfo
535
535
  /** Curated operator copy, absent when no catalog rule matched. */
536
536
  explanation?: { id: string; message: string; hint: string }
537
+ /**
538
+ * Present when a tool asked for a person: its `ToolResult.handoff`.
539
+ * The results of the batch are already committed; resuming the turn
540
+ * calls the model with them.
541
+ */
542
+ handoff?: import('../tool/index.js').ToolHandoff
537
543
  }
538
544
  /** A paused turn continues from its checkpoint, under the same `turnId`. */
539
545
  | {
@@ -201,6 +201,15 @@ const providerError = z
201
201
 
202
202
  const explanation = z.object({ id: text, message: text, hint: text }).strict()
203
203
 
204
+ /** A tool's request for a person, as `turn_paused` carries it. */
205
+ const toolHandoff = z
206
+ .object({
207
+ kind: z.literal('human-required'),
208
+ reason: text,
209
+ detail: z.record(text).optional(),
210
+ })
211
+ .strict()
212
+
204
213
  const stopReason = z.enum([
205
214
  'end_turn',
206
215
  'token_budget',
@@ -361,6 +370,7 @@ export const TurnPausedRecordSchema = inTurn('turn_paused', {
361
370
  providerError: providerError.optional(),
362
371
  explanation: explanation.optional(),
363
372
  budget: tokenBudgetSummary.optional(),
373
+ handoff: toolHandoff.optional(),
364
374
  })
365
375
 
366
376
  export const TurnResumingRecordSchema = inTurn('turn_resuming', {