@namzu/sdk 65.0.0 → 65.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/agents/explore.d.ts +1 -1
  3. package/dist/agents/explore.d.ts.map +1 -1
  4. package/dist/agents/explore.js +2 -1
  5. package/dist/agents/explore.js.map +1 -1
  6. package/dist/agents/plan.d.ts +1 -1
  7. package/dist/agents/plan.d.ts.map +1 -1
  8. package/dist/agents/plan.js +2 -1
  9. package/dist/agents/plan.js.map +1 -1
  10. package/dist/provider/errors.d.ts +10 -0
  11. package/dist/provider/errors.d.ts.map +1 -1
  12. package/dist/provider/errors.js +29 -1
  13. package/dist/provider/errors.js.map +1 -1
  14. package/dist/provider/token-budget.d.ts.map +1 -1
  15. package/dist/provider/token-budget.js +9 -1
  16. package/dist/provider/token-budget.js.map +1 -1
  17. package/dist/public-tools.d.ts +1 -1
  18. package/dist/public-tools.d.ts.map +1 -1
  19. package/dist/public-tools.js +1 -1
  20. package/dist/public-tools.js.map +1 -1
  21. package/dist/runtime/query/iteration/index.d.ts +2 -0
  22. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  23. package/dist/runtime/query/iteration/index.js +45 -6
  24. package/dist/runtime/query/iteration/index.js.map +1 -1
  25. package/dist/runtime/query/turn/stall-monitor.d.ts +5 -0
  26. package/dist/runtime/query/turn/stall-monitor.d.ts.map +1 -1
  27. package/dist/runtime/query/turn/stall-monitor.js +5 -0
  28. package/dist/runtime/query/turn/stall-monitor.js.map +1 -1
  29. package/dist/tools/builtins/browser-stall.d.ts +59 -0
  30. package/dist/tools/builtins/browser-stall.d.ts.map +1 -0
  31. package/dist/tools/builtins/browser-stall.js +141 -0
  32. package/dist/tools/builtins/browser-stall.js.map +1 -0
  33. package/dist/tools/builtins/browser.d.ts +33 -4
  34. package/dist/tools/builtins/browser.d.ts.map +1 -1
  35. package/dist/tools/builtins/browser.js +292 -24
  36. package/dist/tools/builtins/browser.js.map +1 -1
  37. package/dist/types/browser/index.d.ts +130 -8
  38. package/dist/types/browser/index.d.ts.map +1 -1
  39. package/dist/types/browser/index.js +2 -0
  40. package/dist/types/browser/index.js.map +1 -1
  41. package/dist/types/provider/error.d.ts +7 -1
  42. package/dist/types/provider/error.d.ts.map +1 -1
  43. package/dist/types/provider/errors.d.ts.map +1 -1
  44. package/dist/types/provider/errors.js +5 -0
  45. package/dist/types/provider/errors.js.map +1 -1
  46. package/dist/types/session/records.d.ts +6 -0
  47. package/dist/types/session/records.d.ts.map +1 -1
  48. package/dist/types/session/records.js +11 -1
  49. package/dist/types/session/records.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/agents/explore.ts +2 -1
  52. package/src/agents/plan.ts +2 -1
  53. package/src/provider/errors.ts +32 -1
  54. package/src/provider/token-budget.ts +9 -1
  55. package/src/public-tools.ts +1 -0
  56. package/src/runtime/query/iteration/index.ts +49 -5
  57. package/src/runtime/query/turn/stall-monitor.ts +7 -0
  58. package/src/tools/builtins/browser-stall.ts +172 -0
  59. package/src/tools/builtins/browser.ts +371 -33
  60. package/src/types/browser/index.ts +136 -3
  61. package/src/types/provider/error.ts +6 -0
  62. package/src/types/provider/errors.ts +5 -0
  63. package/src/types/session/records.ts +11 -1
@@ -15,6 +15,7 @@ export type BrowserObserveActionName =
15
15
  | 'scroll'
16
16
  | 'wait_for'
17
17
  | 'tabs'
18
+ | 'value'
18
19
 
19
20
  /** Every action the `browser_act` tool (change the page) can ask for. */
20
21
  export type BrowserActActionName =
@@ -33,6 +34,9 @@ export type BrowserScrollDirection = 'up' | 'down' | 'left' | 'right'
33
34
 
34
35
  export type BrowserTabsOp = 'list' | 'select' | 'close' | 'new'
35
36
 
37
+ /** The shapes a `snapshot` can take; see {@link BrowserObserveAction}. */
38
+ export type BrowserSnapshotView = 'full' | 'interactive' | 'reading' | 'delta'
39
+
36
40
  // ---------------------------------------------------------------------------
37
41
  // Capabilities — frozen at host construction; the model reads them through
38
42
  // the tools' descriptions and schemas.
@@ -73,6 +77,9 @@ export const BROWSER_SNAPSHOT_MAX_CHARS = 20_000
73
77
  /** Longest `wait_for` the tool accepts, in milliseconds. */
74
78
  export const BROWSER_WAIT_MAX_MS = 30_000
75
79
 
80
+ /** Most elements one find (`snapshot` with `query` or `role`) returns. */
81
+ export const BROWSER_FIND_MAX_MATCHES = 20
82
+
76
83
  /** Most fields one `fill_form` call may set. */
77
84
  export const BROWSER_FILL_FORM_MAX_FIELDS = 20
78
85
 
@@ -90,7 +97,22 @@ export type BrowserObserveAction =
90
97
  | { readonly action: 'back' }
91
98
  | { readonly action: 'forward' }
92
99
  | { readonly action: 'reload' }
93
- | { readonly action: 'snapshot'; readonly ref?: string; readonly cursor?: string }
100
+ | {
101
+ readonly action: 'snapshot'
102
+ readonly ref?: string
103
+ readonly cursor?: string
104
+ /**
105
+ * What to return. `full` (default): the page as a tree. `interactive`: only
106
+ * the elements a call can act on, one per line. `reading`: the page's text
107
+ * without markup. `delta`: only the lines added and removed since the last
108
+ * snapshot this tab returned.
109
+ */
110
+ readonly view?: BrowserSnapshotView
111
+ /** Find: elements whose name or text contains this (case-insensitive). Up to {@link BROWSER_FIND_MAX_MATCHES}. */
112
+ readonly query?: string
113
+ /** Find: only elements of this ARIA role; with `query`, the role and the name both must match. */
114
+ readonly role?: string
115
+ }
94
116
  | { readonly action: 'screenshot'; readonly ref?: string; readonly fullPage?: boolean }
95
117
  | {
96
118
  readonly action: 'scroll'
@@ -104,6 +126,13 @@ export type BrowserObserveAction =
104
126
  readonly text?: string
105
127
  readonly textGone?: string
106
128
  readonly timeMs?: number
129
+ /** Wait until the page is quiet: no DOM change and no request in flight for a short window. */
130
+ readonly stable?: boolean
131
+ }
132
+ | {
133
+ /** Read one element's current value and state, without a snapshot. */
134
+ readonly action: 'value'
135
+ readonly ref: string
107
136
  }
108
137
  | {
109
138
  readonly action: 'tabs'
@@ -120,20 +149,43 @@ export interface BrowserFormField {
120
149
  readonly value: string
121
150
  }
122
151
 
152
+ /**
153
+ * What a `click` or `hover` aims at: a ref from the latest snapshot, or, when
154
+ * the snapshot has no ref for it, the element's role and accessible name, or
155
+ * its visible text. Exactly one of the three forms is set. A host refuses a
156
+ * role/name or text that matches no element or several, and lists the
157
+ * candidates ({@link BrowserTargetUnclear}).
158
+ */
159
+ export interface BrowserTarget {
160
+ readonly ref?: string
161
+ /** With `name`: an ARIA role such as `button` or `menuitem`. */
162
+ readonly role?: string
163
+ /** With `role`: the accessible name, matched as text. */
164
+ readonly name?: string
165
+ /** The element's visible text, matched as text. */
166
+ readonly text?: string
167
+ }
168
+
123
169
  /** The change a `browser_act` call makes. */
124
170
  export type BrowserActOperation =
125
- | { readonly action: 'click'; readonly ref: string; readonly doubleClick?: boolean }
171
+ | ({ readonly action: 'click'; readonly doubleClick?: boolean } & BrowserTarget)
126
172
  | {
127
173
  readonly action: 'type'
128
174
  readonly ref: string
129
175
  readonly text: string
130
176
  /** Press Enter after typing. */
131
177
  readonly submit?: boolean
178
+ /** Send real key events, one key at a time, instead of setting the value. */
179
+ readonly keys?: boolean
180
+ /** Empty the field first. This is also what happens when neither `clear` nor `append` is set. */
181
+ readonly clear?: boolean
182
+ /** Keep what the field holds and add the text after it. */
183
+ readonly append?: boolean
132
184
  }
133
185
  | { readonly action: 'fill_form'; readonly fields: readonly BrowserFormField[] }
134
186
  | { readonly action: 'select'; readonly ref: string; readonly values: readonly string[] }
135
187
  | { readonly action: 'press'; readonly key: string; readonly ref?: string }
136
- | { readonly action: 'hover'; readonly ref: string }
188
+ | ({ readonly action: 'hover' } & BrowserTarget)
137
189
  | { readonly action: 'upload'; readonly ref: string; readonly path: string }
138
190
  | { readonly action: 'dialog'; readonly accept: boolean; readonly promptText?: string }
139
191
 
@@ -147,6 +199,11 @@ export type BrowserActOperation =
147
199
  * when they differ.** That comparison is what binds an approval of "click
148
200
  * Place order on shop.example.com" to shop.example.com: a redirect between
149
201
  * the snapshot and the click must not carry the click to another site.
202
+ *
203
+ * A host MAY go ahead when the live origin differs but the site rules treat
204
+ * the live origin exactly as they treat the named one (both at the level
205
+ * that needs no review), as long as it says so in the result's `message`.
206
+ * Where the rules would differ it MUST refuse.
150
207
  */
151
208
  export type BrowserActAction = BrowserActOperation & {
152
209
  readonly origin: string
@@ -193,6 +250,44 @@ export interface BrowserScreenshot {
193
250
  readonly height: number
194
251
  }
195
252
 
253
+ /**
254
+ * What an action did to the page, worked out by the host from the page before
255
+ * and after it: the one thing a model needs to tell a click that worked from
256
+ * one that did nothing. The counts and `settle` are the host's words; the
257
+ * lines and addresses are page text, so the tool shows them inside the
258
+ * untrusted envelope.
259
+ */
260
+ export interface BrowserEffect {
261
+ /** The page's address before and after, when it changed. Page-controlled. */
262
+ readonly urlChanged?: { readonly from: string; readonly to: string }
263
+ /** How many lines of the page's tree appeared and disappeared. */
264
+ readonly added: number
265
+ readonly removed: number
266
+ /** The first few lines that appeared, and the first few that went. Page text. */
267
+ readonly addedLines: readonly string[]
268
+ readonly removedLines: readonly string[]
269
+ /** A new tab opened and the page the action ran on did not change. */
270
+ readonly newTab?: boolean
271
+ /** Whether the page went quiet before the host looked, and how long it waited. */
272
+ readonly settle?: { readonly quiet: boolean; readonly waitedMs: number; readonly capMs: number }
273
+ }
274
+
275
+ /** One element's current value and state, from `value`. Page-controlled. */
276
+ export interface BrowserValue {
277
+ readonly page: BrowserPageInfo
278
+ readonly ref: string
279
+ readonly role?: string
280
+ readonly name?: string
281
+ /** What the control holds: the text of a field, the chosen option(s) of a select, the position of a slider. Absent when it holds none. */
282
+ readonly value?: string
283
+ /** `checked`, `selected`, `disabled`, `expanded`, `pressed`, `readonly`, `required`, `invalid`, as set. */
284
+ readonly state: readonly string[]
285
+ /** For a select: every option's label, the chosen ones listed in `value`. */
286
+ readonly options?: readonly string[]
287
+ /** The field is a password or one-time code; its value is not shown. */
288
+ readonly hidden?: boolean
289
+ }
290
+
196
291
  /**
197
292
  * What an action produced. Every field is optional because actions differ;
198
293
  * the tool renders whichever are present.
@@ -209,6 +304,10 @@ export interface BrowserResult {
209
304
  readonly snapshot?: BrowserSnapshot
210
305
  readonly screenshot?: BrowserScreenshot
211
306
  readonly tabs?: readonly BrowserTabInfo[]
307
+ /** `browser_act`: what the action did to the page. */
308
+ readonly effect?: BrowserEffect
309
+ /** `value`: the element's value and state. */
310
+ readonly value?: BrowserValue
212
311
  }
213
312
 
214
313
  /** What a snapshot said about one ref, for labelling a call before it runs. */
@@ -284,6 +383,38 @@ export interface BrowserOutcomeUnknown {
284
383
  readonly message: string
285
384
  }
286
385
 
386
+ /**
387
+ * An action failed before it did anything: the element was not reachable
388
+ * (covered, hidden, disabled, not stable) and the page was not touched. The
389
+ * model may take a fresh snapshot and try once more.
390
+ */
391
+ export interface BrowserNoEffect {
392
+ readonly code: 'browser_no_effect'
393
+ readonly action: BrowserActionName
394
+ readonly outcome: 'unchanged'
395
+ readonly retrySafety: 'once-after-snapshot'
396
+ readonly message: string
397
+ }
398
+
399
+ /** One element a role/name or text target could have meant. */
400
+ export interface BrowserTargetCandidate {
401
+ readonly role: string
402
+ readonly name: string
403
+ }
404
+
405
+ /**
406
+ * A role/name or text target matched no element, or more than one. Nothing
407
+ * was done; `candidates` lists what matched (at most a handful).
408
+ */
409
+ export interface BrowserTargetUnclear {
410
+ readonly code: 'browser_target_unclear'
411
+ readonly matches: number
412
+ readonly candidates: readonly BrowserTargetCandidate[]
413
+ /** What the model asked for, in the host's words, e.g. `button "Save"`. */
414
+ readonly wanted: string
415
+ readonly message: string
416
+ }
417
+
287
418
  /** The site policy does not allow this origin at the level the call needs. */
288
419
  export interface BrowserSiteDenied {
289
420
  readonly code: 'browser_site_denied'
@@ -296,6 +427,8 @@ export type BrowserHostError =
296
427
  | BrowserStaleRef
297
428
  | BrowserHumanRequired
298
429
  | BrowserOutcomeUnknown
430
+ | BrowserNoEffect
431
+ | BrowserTargetUnclear
299
432
  | BrowserSiteDenied
300
433
 
301
434
  // ---------------------------------------------------------------------------
@@ -6,6 +6,12 @@ export type ProviderErrorKind =
6
6
  | 'context_overflow'
7
7
  | 'bad_request'
8
8
  | 'server'
9
+ /** HTTP 402: the account has no credit left. Resending cannot help until it is topped up. */
10
+ | 'credits'
11
+ /** HTTP 403 whose body says the input was flagged by moderation, as opposed to a refused key (`auth`). */
12
+ | 'moderation'
13
+ /** HTTP 404 whose body says no host can serve the request (for example "No endpoints found"). */
14
+ | 'no_endpoints'
9
15
 
10
16
  /**
11
17
  * Serializable provider-failure metadata carried by failed turns and events.
@@ -572,6 +572,11 @@ const KIND_TO_CODE: Readonly<Record<string, { code: ProviderErrorCode; retryable
572
572
  auth: { code: 'auth', retryable: false },
573
573
  context_overflow: { code: 'context_length_exceeded', retryable: false },
574
574
  bad_request: { code: 'invalid_request', retryable: false },
575
+ // Spent credit is a spent allowance: the same non-retryable code a host
576
+ // already answers by offering another account.
577
+ credits: { code: 'usage_limit', retryable: false },
578
+ moderation: { code: 'content_filter', retryable: false },
579
+ no_endpoints: { code: 'not_found', retryable: false },
575
580
  }
576
581
 
577
582
  function classifyFromProviderRequestError(
@@ -210,7 +210,17 @@ const platformError = z
210
210
  /** The provider's own classification; its fields are owned by `types/provider/error.ts`. */
211
211
  const providerError = z
212
212
  .object({
213
- kind: z.enum(['throttle', 'network', 'auth', 'context_overflow', 'bad_request', 'server']),
213
+ kind: z.enum([
214
+ 'throttle',
215
+ 'network',
216
+ 'auth',
217
+ 'context_overflow',
218
+ 'bad_request',
219
+ 'server',
220
+ 'credits',
221
+ 'moderation',
222
+ 'no_endpoints',
223
+ ]),
214
224
  providerId: text,
215
225
  })
216
226
  .passthrough()