@yaks/extension 0.0.0-stage → 0.2.36

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 (78) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +275 -2
  3. package/_dist/act.d.ts +12 -0
  4. package/_dist/act.d.ts.map +1 -0
  5. package/_dist/answer.d.ts +42 -0
  6. package/_dist/answer.d.ts.map +1 -0
  7. package/_dist/build.d.ts +3 -0
  8. package/_dist/build.d.ts.map +1 -0
  9. package/_dist/connect.d.ts +22 -0
  10. package/_dist/connect.d.ts.map +1 -0
  11. package/_dist/consent.d.ts +16 -0
  12. package/_dist/consent.d.ts.map +1 -0
  13. package/_dist/manifest.d.ts +22 -0
  14. package/_dist/manifest.d.ts.map +1 -0
  15. package/_dist/mod.d.ts +12 -0
  16. package/_dist/mod.d.ts.map +1 -0
  17. package/_dist/read.d.ts +11 -0
  18. package/_dist/read.d.ts.map +1 -0
  19. package/_dist/screen.d.ts +22 -0
  20. package/_dist/screen.d.ts.map +1 -0
  21. package/_dist/signin.d.ts +27 -0
  22. package/_dist/signin.d.ts.map +1 -0
  23. package/_dist/tools.d.ts +23 -0
  24. package/_dist/tools.d.ts.map +1 -0
  25. package/_dist/touch.d.ts +32 -0
  26. package/_dist/touch.d.ts.map +1 -0
  27. package/_dist/wire.d.ts +33 -0
  28. package/_dist/wire.d.ts.map +1 -0
  29. package/act.js +41 -0
  30. package/act.js.map +1 -0
  31. package/act.ts +67 -0
  32. package/answer.js +157 -0
  33. package/answer.js.map +1 -0
  34. package/answer.ts +269 -0
  35. package/background.ts +190 -0
  36. package/build.js +67 -0
  37. package/build.js.map +1 -0
  38. package/build.ts +71 -0
  39. package/chrome.ts +76 -0
  40. package/connect.js +59 -0
  41. package/connect.js.map +1 -0
  42. package/connect.ts +85 -0
  43. package/consent.js +50 -0
  44. package/consent.js.map +1 -0
  45. package/consent.ts +67 -0
  46. package/deno.json +1 -0
  47. package/give.ts +124 -0
  48. package/icon.js +60 -0
  49. package/icon.js.map +1 -0
  50. package/icon.ts +53 -0
  51. package/manifest.js +50 -0
  52. package/manifest.js.map +1 -0
  53. package/manifest.ts +53 -0
  54. package/mod.js +15 -0
  55. package/mod.js.map +1 -0
  56. package/mod.ts +15 -0
  57. package/package.json +36 -4
  58. package/popup.css +117 -0
  59. package/popup.html +5 -0
  60. package/popup.ts +89 -0
  61. package/read.js +61 -0
  62. package/read.js.map +1 -0
  63. package/read.ts +80 -0
  64. package/screen.js +41 -0
  65. package/screen.js.map +1 -0
  66. package/screen.ts +125 -0
  67. package/signin.js +77 -0
  68. package/signin.js.map +1 -0
  69. package/signin.ts +94 -0
  70. package/tools.js +183 -0
  71. package/tools.js.map +1 -0
  72. package/tools.ts +192 -0
  73. package/touch.js +216 -0
  74. package/touch.js.map +1 -0
  75. package/touch.ts +259 -0
  76. package/wire.js +66 -0
  77. package/wire.js.map +1 -0
  78. package/wire.ts +91 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,276 @@
1
- # Temporary Holding Version
1
+ # @yaks/extension
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A browser extension that lends the tab a person is on to their agent. The agent
4
+ calls a browser tool, the host sends the call down a socket to the extension,
5
+ and the extension answers from the tab: its address and title, its visible text,
6
+ what the person selected, a screenshot, or its links, buttons and fields; and it
7
+ clicks, types and navigates there. Nothing is read or done on a site until the
8
+ person allows that site, and a step that sends, buys, posts or deletes waits for
9
+ the person to press **Do it**.
10
+
11
+ The package is the extension's core and knows no host. A host is a
12
+ **configuration**, given as data, and `build.ts` makes an unpacked Chrome
13
+ extension (Manifest V3) for it.
14
+
15
+ ## Terms
16
+
17
+ - A **configuration** (`Config`) is the host an extension is made for:
18
+ `{name, origin, description?}`, such as
19
+ `{"name": "yaks.app", "origin": "https://yaks.app"}`.
20
+ - A **space** is where the person's agent runs on the host, served at
21
+ `<space>.<host>`. The extension holds one socket, to one space.
22
+ - A **call** is a tool call the host sends the browser, and an **answer** is
23
+ what the browser sends back with the call's id: text, an image beside it, or
24
+ an error (`./wire`).
25
+ - A **site** is a page's origin, `https://example.com`. **Consent** is the list
26
+ of sites the person allowed, and the one site the agent is asking about.
27
+
28
+ ## Example
29
+
30
+ A call for the page's text, answered from a page the person allowed:
31
+
32
+ ````ts
33
+ import { equal } from '@yaks/testing'
34
+ import { answering, call, callOf } from '@yaks/extension'
35
+
36
+ let asked = callOf(call('c1', 'browser_text'))!
37
+ let page = {
38
+ url: 'https://example.com/',
39
+ title: 'Example',
40
+ text: 'Hello.',
41
+ selection: '',
42
+ }
43
+ let { answer } = answering(asked, { url: page.url, allowed: true, page })
44
+ equal(answer.id, 'c1')
45
+ equal(answer.text?.endsWith('```\nHello.\n```'), true)
46
+
47
+ // The same call on a site the person has not allowed is refused, and says
48
+ // the extension is asking them.
49
+ let refused = answering(asked, { url: page.url, allowed: false }).answer
50
+ equal(refused.error?.startsWith('The person has not allowed you'), true)
51
+ ````
52
+
53
+ ## Exports
54
+
55
+ | Import | What it offers |
56
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
57
+ | `@yaks/extension` | everything below except the build |
58
+ | `@yaks/extension/wire` | `call`, `answer`, `callOf`, `answerOf`, `PING`, and `protocols` and `bearerOf` for the socket's bearer |
59
+ | `@yaks/extension/tools` | `TOOLS`, `toolOf` and `PERSON`: the browser tools a host declares to its model, and how long one that `waits` may wait on the person |
60
+ | `@yaks/extension/build` | `build(config, dir)`: the unpacked extension |
61
+
62
+ From `@yaks/extension`:
63
+
64
+ - `read(doc?, selected?, limit?)` is the `Page` a document shows:
65
+ `{url, title, text, selection}`, and `touch(t, doc?, held?)` lists its
66
+ controls or acts on one.
67
+ - `confirms(call, control)`, `weighty`, `named`, `aims` and `doing` decide a
68
+ step.
69
+ - `answering(call, seen)`, `needs(tool)`, `asks(call, seen)`,
70
+ `lends(call, seen)`, `unlent(failed)` and `line(control)` decide an answer
71
+ from what the tab gave.
72
+ - `site`, `allow`, `revoke`, `allowed`, `ask`, `dismiss` and `pattern` are
73
+ consent.
74
+ - `configOf`, `socket`, `spaceOf` and `spaceHost` are the connection.
75
+ - `registration`, `register`, `provider` and `kept` are signing in.
76
+ - `manifest(config)` is the extension's `manifest.json`,
77
+ `screen(config,
78
+ state)` the popup's HTML, and `asked(state)` whether its
79
+ badge shows.
80
+
81
+ ## The host's side
82
+
83
+ A host declares `TOOLS` to its model, sends each call with
84
+ `call(id, tool,
85
+ args)`, and reads answers with `answerOf`. The socket is the
86
+ host's: the extension opens the configuration's `socket`, `{space}` replaced by
87
+ the person's space, with two subprotocols, a plain `yaks` and
88
+ `bearer.<base64url of the token>`, because a browser's WebSocket can set no
89
+ header. `bearerOf` reads the token back out of the `sec-websocket-protocol`
90
+ header, and the host answers with `yaks`. The extension sends `PING` every 20
91
+ seconds, which the host ignores, so neither the socket nor the browser's service
92
+ worker goes idle.
93
+
94
+ ```ts
95
+ import { equal } from '@yaks/testing'
96
+ import { bearerOf, socket } from '@yaks/extension'
97
+
98
+ let { url, protocols } = socket(
99
+ {
100
+ name: 'yaks.app',
101
+ origin: 'https://yaks.app',
102
+ socket: 'wss://yaks.app/manage/{space}/operator?browser=1',
103
+ },
104
+ { token: 'secret', space: 'jeff' },
105
+ )
106
+ equal(url, 'wss://yaks.app/manage/jeff/operator?browser=1')
107
+ equal(bearerOf(protocols.join(', ')), 'secret')
108
+ ```
109
+
110
+ ## Reading a page
111
+
112
+ `read` runs inside the page: the extension hands it to
113
+ `chrome.scripting.executeScript({func: read})`, which sends the function's
114
+ source to the tab, so it closes over nothing in its module. It skips scripts,
115
+ styles, form fields and hidden elements (the `hidden` attribute,
116
+ `aria-hidden="true"`, an inline `display: none` or `visibility: hidden`, and in
117
+ a browser whatever `checkVisibility()` says is hidden), collapses whitespace,
118
+ puts each block on its own line and keeps a `pre` as it is. The text and the
119
+ selection are each cut at 50,000 characters, with a line saying where.
120
+
121
+ ```ts
122
+ import { equal } from '@yaks/testing'
123
+ import { parseHTML } from 'linkedom'
124
+ import { read } from '@yaks/extension'
125
+
126
+ let { document } = parseHTML(
127
+ '<html><head><title>Notes</title></head><body><h1>Rain</h1>' +
128
+ '<p>falls on <b>the</b> plain</p><script>track()</script>' +
129
+ '<p hidden>draft</p></body></html>',
130
+ )
131
+ let page = read(document, 'the plain')
132
+ equal([page.title, page.text, page.selection], [
133
+ 'Notes',
134
+ 'Rain\nfalls on the plain',
135
+ 'the plain',
136
+ ])
137
+ ```
138
+
139
+ Every word the page wrote reaches the model between backtick fences longer than
140
+ any run of backticks inside it, introduced as written by the site.
141
+
142
+ ## Consent
143
+
144
+ Every call waits for the site it aims at to be allowed: the tab's site, or for
145
+ `browser_navigate` the site it goes to (`aims`). On a site the person has not
146
+ allowed, the extension raises its badge, opens its popup when the window is
147
+ focused (`chrome.action.openPopup`), and asks **Allow on example.com?**; the
148
+ browser grants a site's permission only during a click
149
+ (`chrome.permissions.request` with `pattern(site)`). The call waits for their
150
+ answer, at most `PERSON` (two minutes), and is then answered: what it asked for,
151
+ or that they said no or did not answer. Allowed sites are listed in the popup,
152
+ each with a button to remove it. Every tool is declared with `waits`, so a host
153
+ waits `PERSON` longer than it would for the browser alone.
154
+
155
+ ```ts
156
+ import { equal } from '@yaks/testing'
157
+ import { allow, allowed, ask, NONE, revoke } from '@yaks/extension'
158
+
159
+ let asking = ask('https://example.com')(NONE)
160
+ equal(asking, { sites: [], asking: 'https://example.com' })
161
+ let yes = allow('https://example.com')(asking)
162
+ equal(allowed('https://example.com')(yes), true)
163
+ equal(revoke('https://example.com')(yes), { sites: [] })
164
+ ```
165
+
166
+ ## Screenshots
167
+
168
+ Chrome's `chrome.tabs.captureVisibleTab` captures a tab only under `activeTab`
169
+ or the permission for every site (`<all_urls>`); a site's own permission is not
170
+ enough. `activeTab` is what the person grants a tab by clicking the extension's
171
+ button on it, and it lasts while that tab stays on the same site. So a
172
+ screenshot keeps per-site consent: when Chrome refuses one (`unlent`), the
173
+ extension waits for the person's click, at most `PERSON`, with its badge raised
174
+ and the popup saying where to click. Opening the popup is the click, and the
175
+ screenshot is taken then. A person who does not click is an answer telling the
176
+ agent to ask them to.
177
+
178
+ ## Controlling the tab
179
+
180
+ `browser_elements` lists the links, buttons and fields on the tab, each named by
181
+ a **ref** (`e1`, `e2`, …). `browser_click` and `browser_type` take a ref and the
182
+ element's name as it was listed, and `browser_navigate` takes an address. The
183
+ name is what the conversation's step shows the person ("Clicked Place order"),
184
+ and a name that is no longer the ref's element is refused, so a step names what
185
+ it did.
186
+
187
+ `touch` runs inside the page, as `read` does. The elements a listing named are
188
+ held in the extension's isolated world for the page, which the page's scripts
189
+ can't see, so a page can't move a ref onto another element.
190
+
191
+ ```ts
192
+ import { equal } from '@yaks/testing'
193
+ import { parseHTML } from 'linkedom'
194
+ import { touch } from '@yaks/extension'
195
+
196
+ let { document } = parseHTML(
197
+ '<body><form><input aria-label="To"><button>Send</button></form></body>',
198
+ )
199
+ let held = {}
200
+ let { controls } = touch({ op: 'list' }, document, held)
201
+ equal(controls.map((c) => [c.ref, c.role, c.name, !!c.submits]), [
202
+ ['e1', 'textbox', 'To', false],
203
+ ['e2', 'button', 'Send', true],
204
+ ])
205
+ ```
206
+
207
+ ### Do it
208
+
209
+ A step that sends, buys, posts or deletes waits for the person to press **Do
210
+ it** in the popup, which opens itself when the window is focused. The rule is
211
+ the extension's own (`confirms`), read from the element and the action:
212
+
213
+ - a click on a submit button, or on an element whose name has a word such as
214
+ send, buy, pay, order, post, publish, delete or confirm (`weighty`);
215
+ - Enter typed into a field, unless the field is a search whose name has none of
216
+ those words;
217
+ - any step the agent passed `confirm: true`.
218
+
219
+ The agent's `confirm` only adds a question: `confirm: false` removes none, and
220
+ nothing else a page says reaches the rule. A person who presses **Don't**, or
221
+ does not answer within `PERSON`, is an answer the agent reads, and nothing is
222
+ done.
223
+
224
+ ```ts
225
+ import { equal } from '@yaks/testing'
226
+ import { confirms } from '@yaks/extension'
227
+
228
+ let send = { ref: 'e2', role: 'button', name: 'Send', submits: true }
229
+ let click = (args = {}) => ({ id: 'c', tool: 'browser_click', args })
230
+ equal(confirms(click(), send), true)
231
+ equal(confirms(click({ confirm: false }), send), true)
232
+ equal(confirms(click(), { ref: 'e3', role: 'link', name: 'Next' }), false)
233
+ ```
234
+
235
+ ## Signing in
236
+
237
+ The extension registers itself with the host as a public OAuth client
238
+ (`POST <origin>/oauth/register`, `token_endpoint_auth_method: 'none'`) for its
239
+ browser redirect, `https://<id>.chromiumapp.org/`. It then signs in with the
240
+ authorization-code flow and PKCE through `chrome.identity.launchWebAuthFlow`,
241
+ asking for scope `graph` at `<origin>/oauth/authorize` and trading the code at
242
+ `<origin>/oauth/token`. `provider(config, client)` is that door as a
243
+ [@yaks/oauth](../oauth/README.md) provider, which runs the flow and refreshes
244
+ the grant; `kept(area)` keeps the grant in `chrome.storage.local`.
245
+
246
+ The host's sign-in names no space, so after signing in the person types their
247
+ space's name, or pastes its address (`spaceOf`).
248
+
249
+ ## Building
250
+
251
+ ```sh
252
+ deno run -A packages/extension/build.ts <config.json> <outdir>
253
+ ```
254
+
255
+ writes `manifest.json`, `background.js` and `popup.js` (bundled by esbuild with
256
+ the configuration in them), `popup.html`, `popup.css` and icons drawn by code.
257
+ Load the directory at `chrome://extensions` with Developer mode on, through
258
+ **Load unpacked**.
259
+
260
+ The manifest asks for `activeTab`, `scripting`, `storage`, `identity`, `tabs`
261
+ and `alarms` (which wakes the service worker each minute to reconnect). It may
262
+ reach the host and its spaces (`https://<host>/*`, `https://*.<host>/*`), and
263
+ every other site is an optional permission (`*://*/*`), asked for one site at a
264
+ time.
265
+
266
+ ## Limits
267
+
268
+ - Chrome only: the glue (`background.ts`, `popup.ts`) uses `chrome.*`.
269
+ - It uses the top frame of the active tab in the last focused window; frames
270
+ inside the page and shadow roots are neither read nor touched, and `read`
271
+ skips form fields, which `browser_elements` lists.
272
+ - A screenshot of a tab needs the person's click on the extension's button on
273
+ it, once per tab and site (see Screenshots).
274
+ - A click is the element's `click()`, and typing sets its value and sends
275
+ `input` and `change` events; a page that only listens for trusted key presses
276
+ or pointer events may not respond.
package/_dist/act.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { Control } from "./touch.js";
2
+ import type { Call } from "./wire.js";
3
+ /** Whether words name a step that sends, buys, posts or deletes. */ export declare let weighty: (words: string) => boolean;
4
+ /** The address a call acts on, whose site needs the person's consent: where
5
+ * a navigation goes, and the tab's own address for everything else. */ export declare let aims: (call: Call['call'], url: string) => string;
6
+ /** Whether the name an agent gave is the element's, as it was listed: a ref
7
+ * from an older listing, or a page that changed, names something else. */ export declare let named: (given: unknown, c: Control) => boolean;
8
+ /** Whether a step waits for the person's Do it: a click that submits a form
9
+ * or whose words are weighty, Enter in a field that is not a search, or a
10
+ * search whose words are, and anything the agent asked to confirm. */ export declare let confirms: (call: Call['call'], c?: Control) => boolean;
11
+ /** What a step does, as the person is asked about it. */ export declare let doing: (call: Call['call'], c?: Control) => string;
12
+ //# sourceMappingURL=act.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"act.d.ts","sources":["../act.ts"],"names":[],"mappings":"AAQA,cAAc,OAAO,qBAAoB;AACzC,cAAc,IAAI,oBAAmB;AAWrC,kEAAkE,GAClE,OAAO,YAAI,UAAW,OAAO,MAAM,KAAG,OAAO,CAAuB;AAIpE;qEACqE,GACrE,OAAO,YAAI,OAAQ,MAAM,KAAK,SAAS,KAAK,MAAM,KAAG,MAAM,CACU;AAOrE;wEACwE,GACxE,OAAO,YAAI,QAAS,OAAO,OAAO,EAAE,GAAG,YAAU,OAAO,CACG;AAE3D;;oEAEoE,GACpE,OAAO,YAAI,WAAY,MAAM,KAAK,SAAS,IAAI,YAAU,OAAO,CAQ/D;AAID,uDAAuD,GACvD,OAAO,YAAI,QAAS,MAAM,KAAK,SAAS,IAAI,YAAU,MAAM,CAU3D"}
@@ -0,0 +1,42 @@
1
+ import type { Page } from "./read.js";
2
+ import type { Control } from "./touch.js";
3
+ import type { Answer, Call, Shot } from "./wire.js";
4
+ /** How the person answered a question a call waited on, when it was not yes:
5
+ * they said no, or nothing in time. */ export type Answered = 'no' | 'none';
6
+ /** What the tab gave for one call: its address and title, whether the person
7
+ * allowed the site the call aims at (./act.ts `aims`), and what the tool
8
+ * needed, or why that failed. */ export type Seen = {
9
+ url: string;
10
+ title?: string;
11
+ allowed: boolean;
12
+ /** The person's answer when asked to allow the site, or to press Do it. */ answered?: Answered;
13
+ page?: Page;
14
+ /** A screenshot, as the `data:` URL the browser captures. */ shot?: string;
15
+ /** The controls a listing found, or the one a step acts on. */ controls?: Control[];
16
+ /** Why a listing is not the whole page. */ more?: string;
17
+ /** Where the tab is after a step, and whether the person allowed its
18
+ * site, without which nothing of it is said. */ now?: {
19
+ url: string;
20
+ title?: string;
21
+ allowed: boolean;
22
+ };
23
+ failed?: string;
24
+ };
25
+ /** Whether a screenshot failed because Chrome wants the person's click: it
26
+ * captures a tab only under `activeTab`, which a click on the extension's
27
+ * button grants for that tab, or under every site's permission, which a
28
+ * site allowed on its own is not (Chromium's `CanCaptureVisiblePage`). */ export declare let unlent: (failed?: string) => boolean;
29
+ /** What a tool needs from the tab beyond its address and title: the page
30
+ * read, a screenshot, the page's controls, a step on one, or a navigation. */ export type Need = 'page' | 'shot' | 'list' | 'act' | 'go';
31
+ /** Text between backtick fences longer than any run inside it, so nothing the
32
+ * text says can close the fence early. */ export declare let fence: (text: string) => string;
33
+ /** The image a `data:` URL holds. */ export declare let shot: (url: string) => Shot | undefined;
34
+ /** One control as the agent reads it in a listing. */ export declare let line: (c: Control) => string;
35
+ /** What a tool needs the tab to give, if anything. */ export declare let needs: (tool: string) => Need | undefined;
36
+ /** The answer to a call, from what the tab gave. */ export declare let answering: (call: Call['call'], seen: Seen) => Answer;
37
+ /** Whether a call waits on the person's consent for the site it aims at: the
38
+ * glue keeps the question for the popup, and waits for their answer. */ export declare let asks: (call: Call['call'], seen: Seen) => string | null;
39
+ /** Whether a screenshot waits on the person's click on the extension's
40
+ * button, on the site it names: the glue keeps it for the popup, and takes it
41
+ * again once the popup opens. */ export declare let lends: (call: Call['call'], seen: Seen) => string | null;
42
+ //# sourceMappingURL=answer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer.d.ts","sources":["../answer.ts"],"names":[],"mappings":"AAMA,cAAc,IAAI,oBAAmB;AACrC,cAAc,OAAO,qBAAoB;AACzC,cAAc,MAAM,EAAE,IAAI,EAAE,IAAI,oBAAmB;AAInD;qCACqC,GACrC,YAAY,WAAW,OAAO;AAE9B;;+BAE+B,GAC/B,YAAY;EACV,KAAK,MAAM;EACX,QAAQ,MAAM;EACd,SAAS,OAAO;EAChB,yEAAyE,GACzE,WAAW;EACX,OAAO;EACP,2DAA2D,GAC3D,OAAO,MAAM;EACb,6DAA6D,GAC7D,WAAW;EACX,yCAAyC,GACzC,OAAO,MAAM;EACb;gDAC8C,GAC9C;IAAQ,KAAK,MAAM;IAAE,QAAQ,MAAM;IAAE,SAAS,OAAO;;EACrD,SAAS,MAAM;;AAKjB;;;wEAGwE,GACxE,OAAO,YAAI,SAAU,oBAAc,OAAO,CAA8B;AAExE;4EAC4E,GAC5E,YAAY,OAAO,SAAS,SAAS,SAAS,QAAQ;AAKtD;wCACwC,GACxC,OAAO,YAAI,QAAS,MAAM,MAAM,KAAG,MAAM,CAIxC;AAQD,mCAAmC,GACnC,OAAO,YAAI,OAAQ,KAAK,MAAM,KAAG,OAAO,SAAS,CAGhD;AAOD,oDAAoD,GACpD,OAAO,YAAI,OAAQ,GAAG,YAAU,MAAM,CAYT;AAwE7B,oDAAoD,GACpD,OAAO,YAAI,QAAS,MAAM,MAAM,KAAG,OAAO,SAAS,CAAqB;AAgFxE,kDAAkD,GAClD,OAAO,YAAI,YAAa,MAAM,KAAK,SAAS,MAAM,SAAO,OAQxD;AAED;sEACsE,GACtE,OAAO,YAAI,OAAQ,MAAM,KAAK,SAAS,MAAM,SAAO,MAAM,GAAG,IAAI,CAGhE;AAED;;+BAE+B,GAC/B,OAAO,YAAI,QAAS,MAAM,KAAK,SAAS,MAAM,SAAO,MAAM,GAAG,IAAI,CAGjE"}
@@ -0,0 +1,3 @@
1
+ import { type Config } from "./connect.js";
2
+ /** Write the unpacked extension for a configuration to `dir`. */ export declare let build: (config: Config, dir: string) => Promise<string[]>;
3
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sources":["../build.ts"],"names":[],"mappings":"AAQA,SAAS,KAAK,MAAM,uBAAgC;AA4BpD,+DAA+D,GAC/D,OAAO,YAAI,QAAe,QAAQ,QAAQ,KAAK,MAAM,KAAG,QAAQ,MAAM,IAkBrE"}
@@ -0,0 +1,22 @@
1
+ /** The host an extension is made for. */ export type Config = {
2
+ /** What the person knows the host as, such as `yaks.app`. */ name: string;
3
+ /** Where it signs in, such as `https://yaks.app`. */ origin: string;
4
+ /** The socket a space's agent is reached on, `{space}` standing for the
5
+ * space, such as `wss://yaks.app/manage/{space}/operator?browser=1`. */ socket: string;
6
+ /** One line saying what the extension does, for the browser's listing. */ description?: string;
7
+ };
8
+ /** A person signed in, with the space they chose. */ export type Signed = {
9
+ token: string;
10
+ space: string;
11
+ };
12
+ /** The configuration a JSON value holds, or a sentence saying what is wrong
13
+ * with it. */ export declare let configOf: (v: unknown) => Config | string;
14
+ /** The space a person typed, as its name or its address, or null when it
15
+ * names none. */ export declare let spaceOf: (config: Pick<Config, 'origin'>, typed: string) => string | null;
16
+ /** Where a space is served. */ export declare let spaceHost: (config: Pick<Config, 'origin'>, space: string) => string;
17
+ /** The socket's address and subprotocols: the configured door for the
18
+ * person's space, with the bearer token in the subprotocols (./wire.ts). */ export declare let socket: (config: Config, signed: Signed) => {
19
+ url: string;
20
+ protocols: string[];
21
+ };
22
+ //# sourceMappingURL=connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.d.ts","sources":["../connect.ts"],"names":[],"mappings":"AAQA,uCAAuC,GACvC,YAAY;EACV,2DAA2D,GAC3D,MAAM,MAAM;EACZ,mDAAmD,GACnD,QAAQ,MAAM;EACd;wEACsE,GACtE,QAAQ,MAAM;EACd,wEAAwE,GACxE,cAAc,MAAM;;AAGtB,mDAAmD,GACnD,YAAY;EAAW,OAAO,MAAM;EAAE,OAAO,MAAM;;AAEnD;YACY,GACZ,OAAO,YAAI,WAAY,GAAG,OAAO,KAAG,SAAS,MAAM,CAqBlD;AASD;eACe,GACf,OAAO,YAAI,UACT,QAAQ,KAAK,QAAQ,WACrB,OAAO,MAAM,KACZ,MAAM,GAAG,IAAI,CAMf;AAGD,6BAA6B,GAC7B,OAAO,YAAI,YACT,QAAQ,KAAK,QAAQ,WACrB,OAAO,MAAM,KACZ,MAAM,CAA6C;AAEtD;0EAC0E,GAC1E,OAAO,YAAI,SACT,QAAQ,QACR,QAAQ;EACL,KAAK,MAAM;EAAE,WAAW,MAAM;EAGjC"}
@@ -0,0 +1,16 @@
1
+ /** The sites allowed, and the site the agent is waiting on, if any. */ export type Consent = {
2
+ sites: string[];
3
+ asking?: string;
4
+ };
5
+ /** Nothing allowed, nothing asked. */ export declare let NONE: Consent;
6
+ /** The site a page's address is on, or null for a page that is not on the
7
+ * web (the browser's own pages, files, extensions). */ export declare let site: (url: string) => string | null;
8
+ /** A site as a person reads it. */ export declare let host: (site: string) => string;
9
+ /** The match pattern the browser grants a site's permission under. */ export declare let pattern: (site: string) => string;
10
+ /** Whether the person allowed a site. */ export declare let allowed: (site: string) => any;
11
+ /** The agent asked about a site: it is the one the person is asked about,
12
+ * unless they already allowed it. */ export declare let ask: (site: string) => any;
13
+ /** The person allowed a site; a question about it is answered. */ export declare let allow: (site: string) => any;
14
+ /** The person took a site back. */ export declare let revoke: (site: string) => any;
15
+ /** The person said not now: nothing is asked until the agent asks again. */ export declare let dismiss: (c: Consent) => Consent;
16
+ //# sourceMappingURL=consent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.d.ts","sources":["../consent.ts"],"names":[],"mappings":"AAOA,qEAAqE,GACrE,YAAY;EAAY,OAAO,MAAM;EAAI,SAAS,MAAM;;AAExD,oCAAoC,GACpC,OAAO,YAAI,MAAM,QAAuB;AAKxC;qDACqD,GACrD,OAAO,YAAI,OAAQ,KAAK,MAAM,KAAG,MAAM,GAAG,IAAI,CAO7C;AAGD,iCAAiC,GACjC,OAAO,YAAI,OAAQ,MAAM,MAAM,KAAG,MAAM,CAAsB;AAG9D,oEAAoE,GACpE,OAAO,YAAI,UAAW,MAAM,MAAM,KAAG,MAAM,CAAe;AAI1D,uCAAuC,GACvC,OAAO,YAAI,UAAW,MAAM,MAAM,SACV;AAOxB;mCACmC,GACnC,OAAO,YAAI,MAAO,MAAM,MAAM,SACgB;AAG9C,gEAAgE,GAChE,OAAO,YAAI,QAAS,MAAM,MAAM,SAI7B;AAGH,iCAAiC,GACjC,OAAO,YAAI,SAAU,MAAM,MAAM,SACmB;AAGpD,0EAA0E,GAC1E,OAAO,YAAI,UAAW,GAAG,YAAU,QAA0B"}
@@ -0,0 +1,22 @@
1
+ import type { Config } from "./connect.js";
2
+ /** The sizes the icons are drawn at, as the browser asks for them. */ export declare let SIZES: readonly [number, number, number, number];
3
+ /** A Manifest V3 `manifest.json`, as far as this extension fills it in. */ export type Manifest = {
4
+ manifest_version: 3;
5
+ name: string;
6
+ version: string;
7
+ description: string;
8
+ icons: Record<string, string>;
9
+ action: {
10
+ default_popup: string;
11
+ default_icon: Record<string, string>;
12
+ };
13
+ background: {
14
+ service_worker: string;
15
+ type: 'module';
16
+ };
17
+ permissions: string[];
18
+ host_permissions: string[];
19
+ optional_host_permissions: string[];
20
+ };
21
+ /** The manifest for a configuration. */ export declare let manifest: (config: Config) => Manifest;
22
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sources":["../manifest.ts"],"names":[],"mappings":"AAKA,cAAc,MAAM,uBAAsB;AAE1C,oEAAoE,GACpE,OAAO,YAAI,iDAAyB;AAIpC,yEAAyE,GACzE,YAAY;EACV,kBAAkB;EAClB,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,aAAa,MAAM;EACnB,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B;IAAU,eAAe,MAAM;IAAE,cAAc,OAAO,MAAM,EAAE,MAAM;;EACpE;IAAc,gBAAgB,MAAM;IAAE,MAAM;;EAC5C,aAAa,MAAM;EACnB,kBAAkB,MAAM;EACxB,2BAA2B,MAAM;;AAGnC,sCAAsC,GACtC,OAAO,YAAI,WAAY,QAAQ,WAAS,SAyBvC"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from "./wire.js";
2
+ export * from "./tools.js";
3
+ export * from "./read.js";
4
+ export * from "./touch.js";
5
+ export * from "./act.js";
6
+ export * from "./answer.js";
7
+ export * from "./consent.js";
8
+ export * from "./connect.js";
9
+ export * from "./signin.js";
10
+ export * from "./manifest.js";
11
+ export * from "./screen.js";
12
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAIA,0BAAyB;AACzB,2BAA0B;AAC1B,0BAAyB;AACzB,2BAA0B;AAC1B,yBAAwB;AACxB,4BAA2B;AAC3B,6BAA4B;AAC5B,6BAA4B;AAC5B,4BAA2B;AAC3B,8BAA6B;AAC7B,4BAA2B"}