@namzu/sdk 45.0.0 → 45.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.
Files changed (230) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/authorization/gate.d.ts.map +1 -1
  3. package/dist/authorization/gate.js +12 -2
  4. package/dist/authorization/gate.js.map +1 -1
  5. package/dist/authorization/rules.d.ts.map +1 -1
  6. package/dist/authorization/rules.js +37 -6
  7. package/dist/authorization/rules.js.map +1 -1
  8. package/dist/authorization/shell-lexer.d.ts +14 -0
  9. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  10. package/dist/authorization/shell-lexer.js +19 -6
  11. package/dist/authorization/shell-lexer.js.map +1 -1
  12. package/dist/bridge/a2a/mapper.d.ts.map +1 -1
  13. package/dist/bridge/a2a/mapper.js +2 -0
  14. package/dist/bridge/a2a/mapper.js.map +1 -1
  15. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  16. package/dist/bridge/sse/mapper.js +1 -0
  17. package/dist/bridge/sse/mapper.js.map +1 -1
  18. package/dist/directory/types.d.ts +2 -0
  19. package/dist/directory/types.d.ts.map +1 -1
  20. package/dist/directory/types.js.map +1 -1
  21. package/dist/manager/resident/outbox.d.ts +4 -4
  22. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  23. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  24. package/dist/prompt/coding-agent-doctrine.js +1 -0
  25. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  26. package/dist/public-runtime.d.ts +4 -1
  27. package/dist/public-runtime.d.ts.map +1 -1
  28. package/dist/public-runtime.js +11 -1
  29. package/dist/public-runtime.js.map +1 -1
  30. package/dist/public-tools.d.ts +4 -0
  31. package/dist/public-tools.d.ts.map +1 -1
  32. package/dist/public-tools.js +10 -0
  33. package/dist/public-tools.js.map +1 -1
  34. package/dist/public-types.d.ts +7 -1
  35. package/dist/public-types.d.ts.map +1 -1
  36. package/dist/runtime/query/declined.d.ts +12 -0
  37. package/dist/runtime/query/declined.d.ts.map +1 -0
  38. package/dist/runtime/query/declined.js +12 -0
  39. package/dist/runtime/query/declined.js.map +1 -0
  40. package/dist/runtime/query/executor.d.ts +3 -1
  41. package/dist/runtime/query/executor.d.ts.map +1 -1
  42. package/dist/runtime/query/executor.js +14 -2
  43. package/dist/runtime/query/executor.js.map +1 -1
  44. package/dist/runtime/query/index.d.ts.map +1 -1
  45. package/dist/runtime/query/index.js +1 -0
  46. package/dist/runtime/query/index.js.map +1 -1
  47. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  48. package/dist/runtime/query/iteration/index.js +7 -0
  49. package/dist/runtime/query/iteration/index.js.map +1 -1
  50. package/dist/runtime/query/iteration/phases/context.d.ts +6 -0
  51. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  52. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  53. package/dist/runtime/query/iteration/phases/handoff.d.ts +22 -0
  54. package/dist/runtime/query/iteration/phases/handoff.d.ts.map +1 -0
  55. package/dist/runtime/query/iteration/phases/handoff.js +65 -0
  56. package/dist/runtime/query/iteration/phases/handoff.js.map +1 -0
  57. package/dist/runtime/query/iteration/phases/index.d.ts +1 -0
  58. package/dist/runtime/query/iteration/phases/index.d.ts.map +1 -1
  59. package/dist/runtime/query/iteration/phases/index.js +1 -0
  60. package/dist/runtime/query/iteration/phases/index.js.map +1 -1
  61. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  62. package/dist/runtime/query/iteration/phases/tool-review.js +8 -3
  63. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  64. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  65. package/dist/runtime/query/resume-pending.js +3 -2
  66. package/dist/runtime/query/resume-pending.js.map +1 -1
  67. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  68. package/dist/runtime/query/review-policy.js +4 -3
  69. package/dist/runtime/query/review-policy.js.map +1 -1
  70. package/dist/schedules/cron.d.ts +21 -0
  71. package/dist/schedules/cron.d.ts.map +1 -0
  72. package/dist/schedules/cron.js +167 -0
  73. package/dist/schedules/cron.js.map +1 -0
  74. package/dist/schedules/describe.d.ts +14 -0
  75. package/dist/schedules/describe.d.ts.map +1 -0
  76. package/dist/schedules/describe.js +133 -0
  77. package/dist/schedules/describe.js.map +1 -0
  78. package/dist/schedules/errors.d.ts +11 -0
  79. package/dist/schedules/errors.d.ts.map +1 -0
  80. package/dist/schedules/errors.js +15 -0
  81. package/dist/schedules/errors.js.map +1 -0
  82. package/dist/schedules/evaluate.d.ts +35 -0
  83. package/dist/schedules/evaluate.d.ts.map +1 -0
  84. package/dist/schedules/evaluate.js +158 -0
  85. package/dist/schedules/evaluate.js.map +1 -0
  86. package/dist/schedules/index.d.ts +11 -0
  87. package/dist/schedules/index.d.ts.map +1 -0
  88. package/dist/schedules/index.js +8 -0
  89. package/dist/schedules/index.js.map +1 -0
  90. package/dist/schedules/next-fire.d.ts +50 -0
  91. package/dist/schedules/next-fire.d.ts.map +1 -0
  92. package/dist/schedules/next-fire.js +250 -0
  93. package/dist/schedules/next-fire.js.map +1 -0
  94. package/dist/schedules/spec.d.ts +30 -0
  95. package/dist/schedules/spec.d.ts.map +1 -0
  96. package/dist/schedules/spec.js +169 -0
  97. package/dist/schedules/spec.js.map +1 -0
  98. package/dist/schedules/types.d.ts +144 -0
  99. package/dist/schedules/types.d.ts.map +1 -0
  100. package/dist/schedules/types.js +11 -0
  101. package/dist/schedules/types.js.map +1 -0
  102. package/dist/schedules/tz.d.ts +44 -0
  103. package/dist/schedules/tz.d.ts.map +1 -0
  104. package/dist/schedules/tz.js +141 -0
  105. package/dist/schedules/tz.js.map +1 -0
  106. package/dist/skills/index.d.ts +1 -1
  107. package/dist/skills/index.d.ts.map +1 -1
  108. package/dist/skills/index.js +1 -1
  109. package/dist/skills/index.js.map +1 -1
  110. package/dist/skills/loader.d.ts +16 -3
  111. package/dist/skills/loader.d.ts.map +1 -1
  112. package/dist/skills/loader.js +48 -4
  113. package/dist/skills/loader.js.map +1 -1
  114. package/dist/tools/builtins/browser-url.d.ts +83 -0
  115. package/dist/tools/builtins/browser-url.d.ts.map +1 -0
  116. package/dist/tools/builtins/browser-url.js +240 -0
  117. package/dist/tools/builtins/browser-url.js.map +1 -0
  118. package/dist/tools/builtins/browser.d.ts +367 -0
  119. package/dist/tools/builtins/browser.d.ts.map +1 -0
  120. package/dist/tools/builtins/browser.js +704 -0
  121. package/dist/tools/builtins/browser.js.map +1 -0
  122. package/dist/tools/builtins/skill.d.ts.map +1 -1
  123. package/dist/tools/builtins/skill.js +15 -0
  124. package/dist/tools/builtins/skill.js.map +1 -1
  125. package/dist/tools/defineTool.d.ts +2 -0
  126. package/dist/tools/defineTool.d.ts.map +1 -1
  127. package/dist/tools/defineTool.js +1 -0
  128. package/dist/tools/defineTool.js.map +1 -1
  129. package/dist/tools/schedules/index.d.ts +5 -0
  130. package/dist/tools/schedules/index.d.ts.map +1 -0
  131. package/dist/tools/schedules/index.js +4 -0
  132. package/dist/tools/schedules/index.js.map +1 -0
  133. package/dist/tools/schedules/loop-tool.d.ts +14 -0
  134. package/dist/tools/schedules/loop-tool.d.ts.map +1 -0
  135. package/dist/tools/schedules/loop-tool.js +81 -0
  136. package/dist/tools/schedules/loop-tool.js.map +1 -0
  137. package/dist/tools/schedules/present.d.ts +16 -0
  138. package/dist/tools/schedules/present.d.ts.map +1 -0
  139. package/dist/tools/schedules/present.js +69 -0
  140. package/dist/tools/schedules/present.js.map +1 -0
  141. package/dist/tools/schedules/prompt-scan.d.ts +17 -0
  142. package/dist/tools/schedules/prompt-scan.d.ts.map +1 -0
  143. package/dist/tools/schedules/prompt-scan.js +92 -0
  144. package/dist/tools/schedules/prompt-scan.js.map +1 -0
  145. package/dist/tools/schedules/schedule-tool.d.ts +16 -0
  146. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -0
  147. package/dist/tools/schedules/schedule-tool.js +327 -0
  148. package/dist/tools/schedules/schedule-tool.js.map +1 -0
  149. package/dist/tools/schedules/types.d.ts +184 -0
  150. package/dist/tools/schedules/types.d.ts.map +1 -0
  151. package/dist/tools/schedules/types.js +11 -0
  152. package/dist/tools/schedules/types.js.map +1 -0
  153. package/dist/types/authorization/index.d.ts +86 -9
  154. package/dist/types/authorization/index.d.ts.map +1 -1
  155. package/dist/types/authorization/index.js +11 -1
  156. package/dist/types/authorization/index.js.map +1 -1
  157. package/dist/types/browser/index.d.ts +280 -0
  158. package/dist/types/browser/index.d.ts.map +1 -0
  159. package/dist/types/browser/index.js +12 -0
  160. package/dist/types/browser/index.js.map +1 -0
  161. package/dist/types/session/events.d.ts +6 -0
  162. package/dist/types/session/events.d.ts.map +1 -1
  163. package/dist/types/session/events.js.map +1 -1
  164. package/dist/types/session/records.d.ts +23 -0
  165. package/dist/types/session/records.d.ts.map +1 -1
  166. package/dist/types/session/records.js +9 -0
  167. package/dist/types/session/records.js.map +1 -1
  168. package/dist/types/tool/index.d.ts +41 -0
  169. package/dist/types/tool/index.d.ts.map +1 -1
  170. package/dist/types/tool/index.js.map +1 -1
  171. package/dist/types/tool/presentation.d.ts +7 -0
  172. package/dist/types/tool/presentation.d.ts.map +1 -1
  173. package/dist/utils/frontmatter.d.ts +18 -2
  174. package/dist/utils/frontmatter.d.ts.map +1 -1
  175. package/dist/utils/frontmatter.js +13 -3
  176. package/dist/utils/frontmatter.js.map +1 -1
  177. package/dist/utils/id.d.ts +8 -0
  178. package/dist/utils/id.d.ts.map +1 -1
  179. package/dist/utils/id.js +12 -0
  180. package/dist/utils/id.js.map +1 -1
  181. package/package.json +1 -1
  182. package/src/authorization/gate.ts +14 -2
  183. package/src/authorization/rules.ts +37 -7
  184. package/src/authorization/shell-lexer.ts +36 -6
  185. package/src/bridge/a2a/mapper.ts +2 -0
  186. package/src/bridge/sse/mapper.ts +1 -0
  187. package/src/directory/types.ts +2 -0
  188. package/src/prompt/coding-agent-doctrine.ts +1 -0
  189. package/src/public-runtime.ts +28 -0
  190. package/src/public-tools.ts +35 -0
  191. package/src/public-types.ts +50 -0
  192. package/src/runtime/query/declined.ts +12 -0
  193. package/src/runtime/query/executor.ts +17 -1
  194. package/src/runtime/query/index.ts +1 -0
  195. package/src/runtime/query/iteration/index.ts +8 -0
  196. package/src/runtime/query/iteration/phases/context.ts +6 -0
  197. package/src/runtime/query/iteration/phases/handoff.ts +74 -0
  198. package/src/runtime/query/iteration/phases/index.ts +1 -0
  199. package/src/runtime/query/iteration/phases/tool-review.ts +11 -4
  200. package/src/runtime/query/resume-pending.ts +3 -2
  201. package/src/runtime/query/review-policy.ts +4 -3
  202. package/src/schedules/cron.ts +202 -0
  203. package/src/schedules/describe.ts +138 -0
  204. package/src/schedules/errors.ts +15 -0
  205. package/src/schedules/evaluate.ts +178 -0
  206. package/src/schedules/index.ts +18 -0
  207. package/src/schedules/next-fire.ts +257 -0
  208. package/src/schedules/spec.ts +210 -0
  209. package/src/schedules/types.ts +163 -0
  210. package/src/schedules/tz.ts +155 -0
  211. package/src/skills/index.ts +1 -1
  212. package/src/skills/loader.ts +55 -4
  213. package/src/tools/builtins/browser-url.ts +251 -0
  214. package/src/tools/builtins/browser.ts +817 -0
  215. package/src/tools/builtins/skill.ts +18 -0
  216. package/src/tools/defineTool.ts +3 -0
  217. package/src/tools/schedules/index.ts +4 -0
  218. package/src/tools/schedules/loop-tool.ts +85 -0
  219. package/src/tools/schedules/present.ts +86 -0
  220. package/src/tools/schedules/prompt-scan.ts +96 -0
  221. package/src/tools/schedules/schedule-tool.ts +376 -0
  222. package/src/tools/schedules/types.ts +197 -0
  223. package/src/types/authorization/index.ts +60 -2
  224. package/src/types/browser/index.ts +341 -0
  225. package/src/types/session/events.ts +6 -0
  226. package/src/types/session/records.ts +10 -0
  227. package/src/types/tool/index.ts +42 -0
  228. package/src/types/tool/presentation.ts +7 -0
  229. package/src/utils/frontmatter.ts +29 -3
  230. package/src/utils/id.ts +14 -0
@@ -0,0 +1,240 @@
1
+ /**
2
+ * One spelling per address, decided before anyone judges the address.
3
+ *
4
+ * The browser tools' `url` and `origin` arguments are canonicalised by their
5
+ * input schema, and the registry hands the gate and the reviewer the schema's
6
+ * OUTPUT (`ToolRegistry.prepareExecution`). So a site rule written as
7
+ * `^https://github\.com(?:[/?#]|$)` is tested against the one spelling the
8
+ * browser will load, never against `HTTPS://GitHub.com:443/`,
9
+ * `https://github.com./` or `https://%67ithub.com/`, which name the same page
10
+ * and would each slip past a deny written for the plain form.
11
+ *
12
+ * The canonical form is the WHATWG URL serialisation (`new URL(x).href`),
13
+ * which already lowercases the scheme and host, converts an internationalised
14
+ * host to punycode, drops a default port, decodes percent-encoded host bytes
15
+ * and reads every IPv4 spelling (`2852039166`, `0xA9FEA9FE`,
16
+ * `0251.0376.0251.0376`, `169.254.43518`) as dotted-quad. On top of that:
17
+ *
18
+ * - trailing dots on the host are removed (`github.com.` is `github.com` to
19
+ * DNS and to a person, and a different string to a pattern);
20
+ * - only `http:` and `https:` are accepted, plus the literal `about:blank`;
21
+ * - an address carrying a user name or password is refused — it is how
22
+ * `https://github.com@evil.example/` reads as GitHub to a person;
23
+ * - cloud metadata endpoints are refused outright, in every spelling the
24
+ * parser folds into them. This is a floor, not the site policy: a private
25
+ * or loopback address is left to the operator's site rules, and a DNS name
26
+ * that RESOLVES to a metadata address is the host's to catch after the
27
+ * navigation lands.
28
+ */
29
+ /** Longest address the tools accept. Longer is not a page anyone meant to name. */
30
+ export const BROWSER_URL_MAX_LENGTH = 8192;
31
+ const ABOUT_BLANK = 'about:blank';
32
+ /** Host names of cloud metadata services. Compared after lowercasing and trailing-dot removal. */
33
+ const METADATA_HOSTNAMES = new Set(['metadata.google.internal', 'metadata', 'metadata.goog']);
34
+ /**
35
+ * IPv4 metadata endpoints: AWS, GCP, Azure, Oracle and DigitalOcean
36
+ * (169.254.169.254), and Alibaba Cloud (100.100.100.200).
37
+ */
38
+ const METADATA_IPV4 = new Set(['169.254.169.254', '100.100.100.200']);
39
+ /** IPv6 metadata endpoints, in the parser's compressed form. AWS Nitro. */
40
+ const METADATA_IPV6 = new Set(['fd00:ec2::254']);
41
+ function stripTrailingDots(hostname) {
42
+ return hostname.replace(/\.+$/, '');
43
+ }
44
+ /** Eight hextets of a compressed IPv6 literal, or undefined if it is not one. */
45
+ function expandIpv6(address) {
46
+ const halves = address.split('::');
47
+ if (halves.length > 2)
48
+ return undefined;
49
+ const parse = (part) => {
50
+ if (part === undefined || part === '')
51
+ return [];
52
+ const out = [];
53
+ for (const piece of part.split(':')) {
54
+ if (!/^[0-9a-f]{1,4}$/.test(piece))
55
+ return undefined;
56
+ out.push(Number.parseInt(piece, 16));
57
+ }
58
+ return out;
59
+ };
60
+ const head = parse(halves[0]);
61
+ const tail = parse(halves[1]);
62
+ if (!head || !tail)
63
+ return undefined;
64
+ if (halves.length === 1)
65
+ return head.length === 8 ? head : undefined;
66
+ const fill = 8 - head.length - tail.length;
67
+ if (fill < 1)
68
+ return undefined;
69
+ return [...head, ...new Array(fill).fill(0), ...tail];
70
+ }
71
+ function ipv4Of(high, low) {
72
+ return `${high >>> 8}.${high & 0xff}.${low >>> 8}.${low & 0xff}`;
73
+ }
74
+ /**
75
+ * IPv4 addresses an IPv6 literal carries in a well-known embedding: mapped
76
+ * (`::ffff:a.b.c.d`), compatible (`::a.b.c.d`), SIIT (`::ffff:0:a.b.c.d`),
77
+ * NAT64 (`64:ff9b::/96`, `64:ff9b:1::/48`) and 6to4 (`2002:AABB:CCDD::`).
78
+ * Each is a way to reach the IPv4 address from an IPv6 spelling.
79
+ */
80
+ function embeddedIpv4(h) {
81
+ const out = [];
82
+ const zero = (from, to) => h.slice(from, to).every((x) => x === 0);
83
+ const last = ipv4Of(h[6] ?? 0, h[7] ?? 0);
84
+ if (zero(0, 5) && (h[5] === 0xffff || h[5] === 0))
85
+ out.push(last);
86
+ if (zero(0, 4) && h[4] === 0xffff && h[5] === 0)
87
+ out.push(last);
88
+ if (h[0] === 0x64 && h[1] === 0xff9b)
89
+ out.push(last);
90
+ if (h[0] === 0x2002)
91
+ out.push(ipv4Of(h[1] ?? 0, h[2] ?? 0));
92
+ return out;
93
+ }
94
+ /**
95
+ * Is this host a cloud metadata endpoint, in any spelling the URL parser
96
+ * folds into one? `hostname` is a URL's `hostname` (IPv6 in brackets) or a
97
+ * bare name or address.
98
+ */
99
+ export function isCloudMetadataHost(hostname) {
100
+ let host = stripTrailingDots(hostname.trim().toLowerCase());
101
+ if (host === '')
102
+ return false;
103
+ // Let the WHATWG parser fold every IPv4 and IPv6 spelling into one.
104
+ const bracketed = host.startsWith('[') ? host : host.includes(':') ? `[${host}]` : host;
105
+ try {
106
+ host = stripTrailingDots(new URL(`http://${bracketed}/`).hostname);
107
+ }
108
+ catch {
109
+ return false;
110
+ }
111
+ if (METADATA_HOSTNAMES.has(host) || METADATA_IPV4.has(host))
112
+ return true;
113
+ if (!host.startsWith('['))
114
+ return false;
115
+ const v6 = host.slice(1, -1);
116
+ if (METADATA_IPV6.has(v6))
117
+ return true;
118
+ const hextets = expandIpv6(v6);
119
+ if (!hextets)
120
+ return false;
121
+ return embeddedIpv4(hextets).some((v4) => METADATA_IPV4.has(v4));
122
+ }
123
+ /**
124
+ * The one spelling of an address the browser may be sent to, or why not.
125
+ *
126
+ * Accepts absolute `http:` and `https:` URLs and `about:blank`. See the
127
+ * module comment for what is folded and what is refused.
128
+ */
129
+ export function canonicalizeBrowserUrl(raw) {
130
+ if (typeof raw !== 'string' || raw.trim() === '')
131
+ return { ok: false, reason: 'the address is empty' };
132
+ if (raw.length > BROWSER_URL_MAX_LENGTH)
133
+ return { ok: false, reason: `the address is longer than ${BROWSER_URL_MAX_LENGTH} characters` };
134
+ let url;
135
+ try {
136
+ url = new URL(raw.trim());
137
+ }
138
+ catch {
139
+ return {
140
+ ok: false,
141
+ reason: 'the address is not an absolute URL; give the full https:// address',
142
+ };
143
+ }
144
+ if (url.protocol === 'about:') {
145
+ if (url.pathname.toLowerCase() === 'blank' && url.search === '' && url.hash === '')
146
+ return { ok: true, url: ABOUT_BLANK, origin: 'null' };
147
+ return { ok: false, reason: 'only about:blank is allowed among about: addresses' };
148
+ }
149
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
150
+ return {
151
+ ok: false,
152
+ reason: `the scheme "${url.protocol}" is not allowed; only http and https addresses (and about:blank) can be opened`,
153
+ };
154
+ }
155
+ if (url.username !== '' || url.password !== '') {
156
+ return {
157
+ ok: false,
158
+ reason: 'the address carries a user name or password (user@host); credentials never go in an address — open the site and let the user sign in',
159
+ };
160
+ }
161
+ const host = stripTrailingDots(url.hostname);
162
+ if (host === '')
163
+ return { ok: false, reason: 'the address has no host' };
164
+ if (host !== url.hostname) {
165
+ url.hostname = host;
166
+ // The setter re-parses; a host that did not survive is not one to open.
167
+ if (stripTrailingDots(url.hostname) !== host)
168
+ return { ok: false, reason: 'the address host could not be canonicalised' };
169
+ }
170
+ if (isCloudMetadataHost(url.hostname)) {
171
+ return {
172
+ ok: false,
173
+ reason: `${url.hostname} is a cloud metadata endpoint, which the browser never opens`,
174
+ };
175
+ }
176
+ return { ok: true, url: url.href, origin: url.origin };
177
+ }
178
+ /**
179
+ * The canonical origin (`scheme://host[:port]`) a `browser_act` call names,
180
+ * or why it is not one. A trailing `/` is accepted; a path, query or fragment
181
+ * is not — the argument is an origin, copied from the snapshot header.
182
+ */
183
+ export function canonicalizeBrowserOrigin(raw) {
184
+ const verdict = canonicalizeBrowserUrl(raw);
185
+ if (!verdict.ok)
186
+ return verdict;
187
+ if (verdict.url === ABOUT_BLANK)
188
+ return { ok: false, reason: 'about:blank has no origin to act on; open a page first' };
189
+ const url = new URL(verdict.url);
190
+ if (url.pathname !== '/' || url.search !== '' || url.hash !== '') {
191
+ return {
192
+ ok: false,
193
+ reason: `"${raw}" is a URL, not an origin; copy the origin from the snapshot header (${url.origin})`,
194
+ };
195
+ }
196
+ return { ok: true, origin: verdict.origin };
197
+ }
198
+ /**
199
+ * The canonical spelling of a site key an operator or a job grants —
200
+ * `https://github.com`, `https://*.example.com`, `http://localhost:*` — or
201
+ * why it is not one.
202
+ *
203
+ * The scheme is literal (`http` or `https`). The host may begin with `*.`,
204
+ * meaning one or more labels in front of the rest. The port may be `*`, any
205
+ * port; a default port is dropped. The host is lowercased and punycoded like
206
+ * a URL's. A bare `*`, a path, credentials and metadata hosts are refused.
207
+ */
208
+ export function canonicalizeBrowserSitePattern(raw) {
209
+ const trimmed = typeof raw === 'string' ? raw.trim() : '';
210
+ const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/(\*\.)?([^/:?#@]+)(?::(\d{1,5}|\*))?\/?$/.exec(trimmed);
211
+ if (!match) {
212
+ return {
213
+ ok: false,
214
+ reason: `"${raw}" is not a site; write scheme://host, optionally *.host and :port or :*, with no path`,
215
+ };
216
+ }
217
+ if ((match[3] ?? '').includes('*')) {
218
+ return {
219
+ ok: false,
220
+ reason: `"${raw}" has a wildcard inside the host; a wildcard may only be a leading *. before a domain`,
221
+ };
222
+ }
223
+ const scheme = (match[1] ?? '').toLowerCase();
224
+ const wildcard = match[2] !== undefined;
225
+ const port = match[4];
226
+ if (scheme !== 'http' && scheme !== 'https')
227
+ return { ok: false, reason: `the scheme "${scheme}:" is not allowed; only http and https` };
228
+ const probe = canonicalizeBrowserOrigin(`${scheme}://${match[3]}${port !== undefined && port !== '*' ? `:${port}` : ''}`);
229
+ if (!probe.ok)
230
+ return { ok: false, reason: probe.reason };
231
+ const probeUrl = new URL(probe.origin);
232
+ if (wildcard &&
233
+ (probeUrl.hostname.startsWith('[') || /^\d+(?:\.\d+){3}$/.test(probeUrl.hostname))) {
234
+ return { ok: false, reason: 'a wildcard cannot precede an IP address' };
235
+ }
236
+ const host = `${wildcard ? '*.' : ''}${probeUrl.hostname}`;
237
+ const portPart = port === '*' ? ':*' : probeUrl.port !== '' ? `:${probeUrl.port}` : '';
238
+ return { ok: true, pattern: `${scheme}://${host}${portPart}` };
239
+ }
240
+ //# sourceMappingURL=browser-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EACjF,CAAC;QACF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,yCAAyC,EAAE,CAAA;IACxE,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAA;IAC1D,MAAM,QAAQ,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,IAAI,GAAG,QAAQ,EAAE,EAAE,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,367 @@
1
+ import { z } from 'zod';
2
+ import type { BrowserHost, BrowserHostError, BrowserPageInfo } from '../../types/browser/index.js';
3
+ import type { ToolDefinition } from '../../types/tool/index.js';
4
+ export declare const BROWSER_TOOL_NAME: "browser";
5
+ export declare const BROWSER_ACT_TOOL_NAME: "browser_act";
6
+ declare const observeSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"action", [z.ZodObject<{
7
+ action: z.ZodLiteral<"navigate">;
8
+ url: z.ZodEffects<z.ZodString, string, string>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ action: "navigate";
11
+ url: string;
12
+ }, {
13
+ action: "navigate";
14
+ url: string;
15
+ }>, z.ZodObject<{
16
+ action: z.ZodLiteral<"back">;
17
+ }, "strip", z.ZodTypeAny, {
18
+ action: "back";
19
+ }, {
20
+ action: "back";
21
+ }>, z.ZodObject<{
22
+ action: z.ZodLiteral<"forward">;
23
+ }, "strip", z.ZodTypeAny, {
24
+ action: "forward";
25
+ }, {
26
+ action: "forward";
27
+ }>, z.ZodObject<{
28
+ action: z.ZodLiteral<"reload">;
29
+ }, "strip", z.ZodTypeAny, {
30
+ action: "reload";
31
+ }, {
32
+ action: "reload";
33
+ }>, z.ZodObject<{
34
+ action: z.ZodLiteral<"snapshot">;
35
+ ref: z.ZodOptional<z.ZodString>;
36
+ cursor: z.ZodOptional<z.ZodString>;
37
+ }, "strip", z.ZodTypeAny, {
38
+ action: "snapshot";
39
+ cursor?: string | undefined;
40
+ ref?: string | undefined;
41
+ }, {
42
+ action: "snapshot";
43
+ cursor?: string | undefined;
44
+ ref?: string | undefined;
45
+ }>, z.ZodObject<{
46
+ action: z.ZodLiteral<"screenshot">;
47
+ ref: z.ZodOptional<z.ZodString>;
48
+ fullPage: z.ZodOptional<z.ZodBoolean>;
49
+ }, "strip", z.ZodTypeAny, {
50
+ action: "screenshot";
51
+ ref?: string | undefined;
52
+ fullPage?: boolean | undefined;
53
+ }, {
54
+ action: "screenshot";
55
+ ref?: string | undefined;
56
+ fullPage?: boolean | undefined;
57
+ }>, z.ZodObject<{
58
+ action: z.ZodLiteral<"scroll">;
59
+ direction: z.ZodEnum<["up", "down", "left", "right"]>;
60
+ ref: z.ZodOptional<z.ZodString>;
61
+ amount: z.ZodOptional<z.ZodNumber>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ action: "scroll";
64
+ direction: "left" | "right" | "up" | "down";
65
+ amount?: number | undefined;
66
+ ref?: string | undefined;
67
+ }, {
68
+ action: "scroll";
69
+ direction: "left" | "right" | "up" | "down";
70
+ amount?: number | undefined;
71
+ ref?: string | undefined;
72
+ }>, z.ZodObject<{
73
+ action: z.ZodLiteral<"wait_for">;
74
+ text: z.ZodOptional<z.ZodString>;
75
+ textGone: z.ZodOptional<z.ZodString>;
76
+ timeMs: z.ZodOptional<z.ZodNumber>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ action: "wait_for";
79
+ text?: string | undefined;
80
+ textGone?: string | undefined;
81
+ timeMs?: number | undefined;
82
+ }, {
83
+ action: "wait_for";
84
+ text?: string | undefined;
85
+ textGone?: string | undefined;
86
+ timeMs?: number | undefined;
87
+ }>, z.ZodObject<{
88
+ action: z.ZodLiteral<"tabs">;
89
+ op: z.ZodEnum<["list", "select", "close", "new"]>;
90
+ tab: z.ZodOptional<z.ZodString>;
91
+ url: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
92
+ }, "strip", z.ZodTypeAny, {
93
+ action: "tabs";
94
+ op: "close" | "list" | "select" | "new";
95
+ url?: string | undefined;
96
+ tab?: string | undefined;
97
+ }, {
98
+ action: "tabs";
99
+ op: "close" | "list" | "select" | "new";
100
+ url?: string | undefined;
101
+ tab?: string | undefined;
102
+ }>]>, {
103
+ action: "navigate";
104
+ url: string;
105
+ } | {
106
+ action: "back";
107
+ } | {
108
+ action: "forward";
109
+ } | {
110
+ action: "reload";
111
+ } | {
112
+ action: "snapshot";
113
+ cursor?: string | undefined;
114
+ ref?: string | undefined;
115
+ } | {
116
+ action: "screenshot";
117
+ ref?: string | undefined;
118
+ fullPage?: boolean | undefined;
119
+ } | {
120
+ action: "scroll";
121
+ direction: "left" | "right" | "up" | "down";
122
+ amount?: number | undefined;
123
+ ref?: string | undefined;
124
+ } | {
125
+ action: "wait_for";
126
+ text?: string | undefined;
127
+ textGone?: string | undefined;
128
+ timeMs?: number | undefined;
129
+ } | {
130
+ action: "tabs";
131
+ op: "close" | "list" | "select" | "new";
132
+ url?: string | undefined;
133
+ tab?: string | undefined;
134
+ }, {
135
+ action: "navigate";
136
+ url: string;
137
+ } | {
138
+ action: "back";
139
+ } | {
140
+ action: "forward";
141
+ } | {
142
+ action: "reload";
143
+ } | {
144
+ action: "snapshot";
145
+ cursor?: string | undefined;
146
+ ref?: string | undefined;
147
+ } | {
148
+ action: "screenshot";
149
+ ref?: string | undefined;
150
+ fullPage?: boolean | undefined;
151
+ } | {
152
+ action: "scroll";
153
+ direction: "left" | "right" | "up" | "down";
154
+ amount?: number | undefined;
155
+ ref?: string | undefined;
156
+ } | {
157
+ action: "wait_for";
158
+ text?: string | undefined;
159
+ textGone?: string | undefined;
160
+ timeMs?: number | undefined;
161
+ } | {
162
+ action: "tabs";
163
+ op: "close" | "list" | "select" | "new";
164
+ url?: string | undefined;
165
+ tab?: string | undefined;
166
+ }>;
167
+ declare const actSchema: z.ZodDiscriminatedUnion<"action", [z.ZodObject<{
168
+ origin: z.ZodEffects<z.ZodString, string, string>;
169
+ snapshot: z.ZodOptional<z.ZodBoolean>;
170
+ action: z.ZodLiteral<"click">;
171
+ ref: z.ZodString;
172
+ doubleClick: z.ZodOptional<z.ZodBoolean>;
173
+ }, "strip", z.ZodTypeAny, {
174
+ origin: string;
175
+ action: "click";
176
+ ref: string;
177
+ snapshot?: boolean | undefined;
178
+ doubleClick?: boolean | undefined;
179
+ }, {
180
+ origin: string;
181
+ action: "click";
182
+ ref: string;
183
+ snapshot?: boolean | undefined;
184
+ doubleClick?: boolean | undefined;
185
+ }>, z.ZodObject<{
186
+ origin: z.ZodEffects<z.ZodString, string, string>;
187
+ snapshot: z.ZodOptional<z.ZodBoolean>;
188
+ action: z.ZodLiteral<"type">;
189
+ ref: z.ZodString;
190
+ text: z.ZodString;
191
+ submit: z.ZodOptional<z.ZodBoolean>;
192
+ }, "strip", z.ZodTypeAny, {
193
+ text: string;
194
+ origin: string;
195
+ action: "type";
196
+ ref: string;
197
+ snapshot?: boolean | undefined;
198
+ submit?: boolean | undefined;
199
+ }, {
200
+ text: string;
201
+ origin: string;
202
+ action: "type";
203
+ ref: string;
204
+ snapshot?: boolean | undefined;
205
+ submit?: boolean | undefined;
206
+ }>, z.ZodObject<{
207
+ origin: z.ZodEffects<z.ZodString, string, string>;
208
+ snapshot: z.ZodOptional<z.ZodBoolean>;
209
+ action: z.ZodLiteral<"fill_form">;
210
+ fields: z.ZodArray<z.ZodObject<{
211
+ ref: z.ZodString;
212
+ value: z.ZodString;
213
+ }, "strip", z.ZodTypeAny, {
214
+ value: string;
215
+ ref: string;
216
+ }, {
217
+ value: string;
218
+ ref: string;
219
+ }>, "many">;
220
+ }, "strip", z.ZodTypeAny, {
221
+ origin: string;
222
+ action: "fill_form";
223
+ fields: {
224
+ value: string;
225
+ ref: string;
226
+ }[];
227
+ snapshot?: boolean | undefined;
228
+ }, {
229
+ origin: string;
230
+ action: "fill_form";
231
+ fields: {
232
+ value: string;
233
+ ref: string;
234
+ }[];
235
+ snapshot?: boolean | undefined;
236
+ }>, z.ZodObject<{
237
+ origin: z.ZodEffects<z.ZodString, string, string>;
238
+ snapshot: z.ZodOptional<z.ZodBoolean>;
239
+ action: z.ZodLiteral<"select">;
240
+ ref: z.ZodString;
241
+ values: z.ZodArray<z.ZodString, "many">;
242
+ }, "strip", z.ZodTypeAny, {
243
+ values: string[];
244
+ origin: string;
245
+ action: "select";
246
+ ref: string;
247
+ snapshot?: boolean | undefined;
248
+ }, {
249
+ values: string[];
250
+ origin: string;
251
+ action: "select";
252
+ ref: string;
253
+ snapshot?: boolean | undefined;
254
+ }>, z.ZodObject<{
255
+ origin: z.ZodEffects<z.ZodString, string, string>;
256
+ snapshot: z.ZodOptional<z.ZodBoolean>;
257
+ action: z.ZodLiteral<"press">;
258
+ key: z.ZodString;
259
+ ref: z.ZodOptional<z.ZodString>;
260
+ }, "strip", z.ZodTypeAny, {
261
+ key: string;
262
+ origin: string;
263
+ action: "press";
264
+ snapshot?: boolean | undefined;
265
+ ref?: string | undefined;
266
+ }, {
267
+ key: string;
268
+ origin: string;
269
+ action: "press";
270
+ snapshot?: boolean | undefined;
271
+ ref?: string | undefined;
272
+ }>, z.ZodObject<{
273
+ origin: z.ZodEffects<z.ZodString, string, string>;
274
+ snapshot: z.ZodOptional<z.ZodBoolean>;
275
+ action: z.ZodLiteral<"hover">;
276
+ ref: z.ZodString;
277
+ }, "strip", z.ZodTypeAny, {
278
+ origin: string;
279
+ action: "hover";
280
+ ref: string;
281
+ snapshot?: boolean | undefined;
282
+ }, {
283
+ origin: string;
284
+ action: "hover";
285
+ ref: string;
286
+ snapshot?: boolean | undefined;
287
+ }>, z.ZodObject<{
288
+ origin: z.ZodEffects<z.ZodString, string, string>;
289
+ snapshot: z.ZodOptional<z.ZodBoolean>;
290
+ action: z.ZodLiteral<"upload">;
291
+ ref: z.ZodString;
292
+ path: z.ZodString;
293
+ }, "strip", z.ZodTypeAny, {
294
+ path: string;
295
+ origin: string;
296
+ action: "upload";
297
+ ref: string;
298
+ snapshot?: boolean | undefined;
299
+ }, {
300
+ path: string;
301
+ origin: string;
302
+ action: "upload";
303
+ ref: string;
304
+ snapshot?: boolean | undefined;
305
+ }>, z.ZodObject<{
306
+ origin: z.ZodEffects<z.ZodString, string, string>;
307
+ snapshot: z.ZodOptional<z.ZodBoolean>;
308
+ action: z.ZodLiteral<"dialog">;
309
+ accept: z.ZodBoolean;
310
+ promptText: z.ZodOptional<z.ZodString>;
311
+ }, "strip", z.ZodTypeAny, {
312
+ origin: string;
313
+ action: "dialog";
314
+ accept: boolean;
315
+ snapshot?: boolean | undefined;
316
+ promptText?: string | undefined;
317
+ }, {
318
+ origin: string;
319
+ action: "dialog";
320
+ accept: boolean;
321
+ snapshot?: boolean | undefined;
322
+ promptText?: string | undefined;
323
+ }>]>;
324
+ /** The `browser` tool's input after canonicalisation. */
325
+ export type BrowserToolInput = z.infer<typeof observeSchema>;
326
+ /** The `browser_act` tool's input after canonicalisation. */
327
+ export type BrowserActToolInput = z.infer<typeof actSchema>;
328
+ /**
329
+ * Whether a `browser` call only observes. Navigation, history moves, reload
330
+ * and opening a tab change what the browser has loaded, and are what a site
331
+ * rule on `url` decides; looking, scrolling, waiting and moving between or
332
+ * closing tabs the browser already holds do not.
333
+ */
334
+ export declare function isBrowserCallReadOnly(input: BrowserToolInput): boolean;
335
+ /**
336
+ * `Page: <origin> — "<title>" (tab t1)`.
337
+ *
338
+ * The origin is the host's and canonical; the model copies it into
339
+ * `browser_act`. The title is the page's, so it is quoted, cut to one line
340
+ * and stripped of the envelope's delimiter.
341
+ */
342
+ export declare function formatBrowserPageHeader(page: BrowserPageInfo): string;
343
+ /**
344
+ * The structural error a browser host threw, or undefined. Recognised by
345
+ * shape, so a separately installed host and SDK need not share a class.
346
+ */
347
+ export declare function browserHostErrorOf(value: unknown): BrowserHostError | undefined;
348
+ /**
349
+ * The browser tools over a {@link BrowserHost}: `browser` (observe and
350
+ * navigate) and `browser_act` (change the page).
351
+ *
352
+ * The split is what makes the gate useful. `browser` calls that only look
353
+ * are read-only; `navigate` and `tabs new` carry a canonical `url` a site
354
+ * rule can match; every `browser_act` call carries the canonical `origin`
355
+ * it means to act on, which a site rule can match and which the host checks
356
+ * against the live page before acting.
357
+ *
358
+ * @example
359
+ * ```ts sketch
360
+ * import { createBrowserTools } from '@namzu/sdk'
361
+ *
362
+ * for (const tool of createBrowserTools(host)) registry.register(tool)
363
+ * ```
364
+ */
365
+ export declare function createBrowserTools(host: BrowserHost): [ToolDefinition<BrowserToolInput>, ToolDefinition<BrowserActToolInput>];
366
+ export {};
367
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,KAAK,EAKX,WAAW,EACX,gBAAgB,EAIhB,eAAe,EAGf,MAAM,8BAA8B,CAAA;AAOrC,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,2BAA2B,CAAA;AAO3E,eAAO,MAAM,iBAAiB,EAAG,SAAkB,CAAA;AACnD,eAAO,MAAM,qBAAqB,EAAG,aAAsB,CAAA;AAmC3D,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDhB,CAAA;AAOH,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