@dudko.dev/agent-web-ui 0.0.0 → 0.0.2

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 (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +316 -5
  3. package/dist/canvas.cjs +266 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.cts +105 -0
  6. package/dist/canvas.d.ts +105 -0
  7. package/dist/canvas.js +200 -0
  8. package/dist/canvas.js.map +1 -0
  9. package/dist/chunk-7O64ZI6Z.js +125 -0
  10. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  11. package/dist/chunk-EL2YCROY.js +127 -0
  12. package/dist/chunk-EL2YCROY.js.map +1 -0
  13. package/dist/chunk-GB7RZJMG.js +98 -0
  14. package/dist/chunk-GB7RZJMG.js.map +1 -0
  15. package/dist/chunk-KZQB35LS.js +22 -0
  16. package/dist/chunk-KZQB35LS.js.map +1 -0
  17. package/dist/chunk-SVYHDLAZ.js +348 -0
  18. package/dist/chunk-SVYHDLAZ.js.map +1 -0
  19. package/dist/chunk-VCR7LU7J.js +348 -0
  20. package/dist/chunk-VCR7LU7J.js.map +1 -0
  21. package/dist/chunk-WFM6B7CL.js +406 -0
  22. package/dist/chunk-WFM6B7CL.js.map +1 -0
  23. package/dist/chunk-WZ7K7JIP.js +348 -0
  24. package/dist/chunk-WZ7K7JIP.js.map +1 -0
  25. package/dist/chunk-ZBHESK6V.js +1440 -0
  26. package/dist/chunk-ZBHESK6V.js.map +1 -0
  27. package/dist/controller.cjs +1891 -0
  28. package/dist/controller.cjs.map +1 -0
  29. package/dist/controller.d.cts +253 -0
  30. package/dist/controller.d.ts +253 -0
  31. package/dist/controller.js +482 -0
  32. package/dist/controller.js.map +1 -0
  33. package/dist/en-Dg2MtzcJ.d.cts +348 -0
  34. package/dist/en-Dg2MtzcJ.d.ts +348 -0
  35. package/dist/index.cjs +4276 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +997 -0
  38. package/dist/index.d.ts +997 -0
  39. package/dist/index.js +2494 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/labels-B5xpIGf_.d.cts +25 -0
  42. package/dist/labels-B5xpIGf_.d.ts +25 -0
  43. package/dist/labels-CmiTBLWD.d.cts +1176 -0
  44. package/dist/labels-DH1ESUtm.d.ts +1176 -0
  45. package/dist/locales/be.cjs +806 -0
  46. package/dist/locales/be.cjs.map +1 -0
  47. package/dist/locales/be.d.cts +16 -0
  48. package/dist/locales/be.d.ts +16 -0
  49. package/dist/locales/be.js +380 -0
  50. package/dist/locales/be.js.map +1 -0
  51. package/dist/locales/bg.cjs +759 -0
  52. package/dist/locales/bg.cjs.map +1 -0
  53. package/dist/locales/bg.d.cts +16 -0
  54. package/dist/locales/bg.d.ts +16 -0
  55. package/dist/locales/bg.js +333 -0
  56. package/dist/locales/bg.js.map +1 -0
  57. package/dist/locales/ca.cjs +785 -0
  58. package/dist/locales/ca.cjs.map +1 -0
  59. package/dist/locales/ca.d.cts +16 -0
  60. package/dist/locales/ca.d.ts +16 -0
  61. package/dist/locales/ca.js +359 -0
  62. package/dist/locales/ca.js.map +1 -0
  63. package/dist/locales/cs.cjs +806 -0
  64. package/dist/locales/cs.cjs.map +1 -0
  65. package/dist/locales/cs.d.cts +16 -0
  66. package/dist/locales/cs.d.ts +16 -0
  67. package/dist/locales/cs.js +380 -0
  68. package/dist/locales/cs.js.map +1 -0
  69. package/dist/locales/da.cjs +759 -0
  70. package/dist/locales/da.cjs.map +1 -0
  71. package/dist/locales/da.d.cts +16 -0
  72. package/dist/locales/da.d.ts +16 -0
  73. package/dist/locales/da.js +333 -0
  74. package/dist/locales/da.js.map +1 -0
  75. package/dist/locales/de.cjs +768 -0
  76. package/dist/locales/de.cjs.map +1 -0
  77. package/dist/locales/de.d.cts +16 -0
  78. package/dist/locales/de.d.ts +16 -0
  79. package/dist/locales/de.js +342 -0
  80. package/dist/locales/de.js.map +1 -0
  81. package/dist/locales/el.cjs +768 -0
  82. package/dist/locales/el.cjs.map +1 -0
  83. package/dist/locales/el.d.cts +16 -0
  84. package/dist/locales/el.d.ts +16 -0
  85. package/dist/locales/el.js +342 -0
  86. package/dist/locales/el.js.map +1 -0
  87. package/dist/locales/en.cjs +765 -0
  88. package/dist/locales/en.cjs.map +1 -0
  89. package/dist/locales/en.d.cts +12 -0
  90. package/dist/locales/en.d.ts +12 -0
  91. package/dist/locales/en.js +339 -0
  92. package/dist/locales/en.js.map +1 -0
  93. package/dist/locales/es-419.cjs +793 -0
  94. package/dist/locales/es-419.cjs.map +1 -0
  95. package/dist/locales/es-419.d.cts +18 -0
  96. package/dist/locales/es-419.d.ts +18 -0
  97. package/dist/locales/es-419.js +26 -0
  98. package/dist/locales/es-419.js.map +1 -0
  99. package/dist/locales/es.cjs +781 -0
  100. package/dist/locales/es.cjs.map +1 -0
  101. package/dist/locales/es.d.cts +16 -0
  102. package/dist/locales/es.d.ts +16 -0
  103. package/dist/locales/es.js +14 -0
  104. package/dist/locales/es.js.map +1 -0
  105. package/dist/locales/fi.cjs +765 -0
  106. package/dist/locales/fi.cjs.map +1 -0
  107. package/dist/locales/fi.d.cts +16 -0
  108. package/dist/locales/fi.d.ts +16 -0
  109. package/dist/locales/fi.js +339 -0
  110. package/dist/locales/fi.js.map +1 -0
  111. package/dist/locales/fr-CA.cjs +789 -0
  112. package/dist/locales/fr-CA.cjs.map +1 -0
  113. package/dist/locales/fr-CA.d.cts +19 -0
  114. package/dist/locales/fr-CA.d.ts +19 -0
  115. package/dist/locales/fr-CA.js +22 -0
  116. package/dist/locales/fr-CA.js.map +1 -0
  117. package/dist/locales/fr.cjs +781 -0
  118. package/dist/locales/fr.cjs.map +1 -0
  119. package/dist/locales/fr.d.cts +16 -0
  120. package/dist/locales/fr.d.ts +16 -0
  121. package/dist/locales/fr.js +14 -0
  122. package/dist/locales/fr.js.map +1 -0
  123. package/dist/locales/gn.cjs +762 -0
  124. package/dist/locales/gn.cjs.map +1 -0
  125. package/dist/locales/gn.d.cts +18 -0
  126. package/dist/locales/gn.d.ts +18 -0
  127. package/dist/locales/gn.js +336 -0
  128. package/dist/locales/gn.js.map +1 -0
  129. package/dist/locales/hr.cjs +781 -0
  130. package/dist/locales/hr.cjs.map +1 -0
  131. package/dist/locales/hr.d.cts +16 -0
  132. package/dist/locales/hr.d.ts +16 -0
  133. package/dist/locales/hr.js +355 -0
  134. package/dist/locales/hr.js.map +1 -0
  135. package/dist/locales/ht.cjs +762 -0
  136. package/dist/locales/ht.cjs.map +1 -0
  137. package/dist/locales/ht.d.cts +18 -0
  138. package/dist/locales/ht.d.ts +18 -0
  139. package/dist/locales/ht.js +336 -0
  140. package/dist/locales/ht.js.map +1 -0
  141. package/dist/locales/hu.cjs +765 -0
  142. package/dist/locales/hu.cjs.map +1 -0
  143. package/dist/locales/hu.d.cts +16 -0
  144. package/dist/locales/hu.d.ts +16 -0
  145. package/dist/locales/hu.js +339 -0
  146. package/dist/locales/hu.js.map +1 -0
  147. package/dist/locales/index.cjs +543 -0
  148. package/dist/locales/index.cjs.map +1 -0
  149. package/dist/locales/index.d.cts +40 -0
  150. package/dist/locales/index.d.ts +40 -0
  151. package/dist/locales/index.js +105 -0
  152. package/dist/locales/index.js.map +1 -0
  153. package/dist/locales/it.cjs +789 -0
  154. package/dist/locales/it.cjs.map +1 -0
  155. package/dist/locales/it.d.cts +16 -0
  156. package/dist/locales/it.d.ts +16 -0
  157. package/dist/locales/it.js +363 -0
  158. package/dist/locales/it.js.map +1 -0
  159. package/dist/locales/nb.cjs +759 -0
  160. package/dist/locales/nb.cjs.map +1 -0
  161. package/dist/locales/nb.d.cts +16 -0
  162. package/dist/locales/nb.d.ts +16 -0
  163. package/dist/locales/nb.js +333 -0
  164. package/dist/locales/nb.js.map +1 -0
  165. package/dist/locales/nl.cjs +765 -0
  166. package/dist/locales/nl.cjs.map +1 -0
  167. package/dist/locales/nl.d.cts +16 -0
  168. package/dist/locales/nl.d.ts +16 -0
  169. package/dist/locales/nl.js +339 -0
  170. package/dist/locales/nl.js.map +1 -0
  171. package/dist/locales/pl.cjs +806 -0
  172. package/dist/locales/pl.cjs.map +1 -0
  173. package/dist/locales/pl.d.cts +16 -0
  174. package/dist/locales/pl.d.ts +16 -0
  175. package/dist/locales/pl.js +380 -0
  176. package/dist/locales/pl.js.map +1 -0
  177. package/dist/locales/pt-BR.cjs +785 -0
  178. package/dist/locales/pt-BR.cjs.map +1 -0
  179. package/dist/locales/pt-BR.d.cts +16 -0
  180. package/dist/locales/pt-BR.d.ts +16 -0
  181. package/dist/locales/pt-BR.js +359 -0
  182. package/dist/locales/pt-BR.js.map +1 -0
  183. package/dist/locales/pt.cjs +789 -0
  184. package/dist/locales/pt.cjs.map +1 -0
  185. package/dist/locales/pt.d.cts +16 -0
  186. package/dist/locales/pt.d.ts +16 -0
  187. package/dist/locales/pt.js +363 -0
  188. package/dist/locales/pt.js.map +1 -0
  189. package/dist/locales/qu.cjs +768 -0
  190. package/dist/locales/qu.cjs.map +1 -0
  191. package/dist/locales/qu.d.cts +18 -0
  192. package/dist/locales/qu.d.ts +18 -0
  193. package/dist/locales/qu.js +342 -0
  194. package/dist/locales/qu.js.map +1 -0
  195. package/dist/locales/ro.cjs +781 -0
  196. package/dist/locales/ro.cjs.map +1 -0
  197. package/dist/locales/ro.d.cts +16 -0
  198. package/dist/locales/ro.d.ts +16 -0
  199. package/dist/locales/ro.js +355 -0
  200. package/dist/locales/ro.js.map +1 -0
  201. package/dist/locales/ru.cjs +801 -0
  202. package/dist/locales/ru.cjs.map +1 -0
  203. package/dist/locales/ru.d.cts +16 -0
  204. package/dist/locales/ru.d.ts +16 -0
  205. package/dist/locales/ru.js +375 -0
  206. package/dist/locales/ru.js.map +1 -0
  207. package/dist/locales/sk.cjs +806 -0
  208. package/dist/locales/sk.cjs.map +1 -0
  209. package/dist/locales/sk.d.cts +16 -0
  210. package/dist/locales/sk.d.ts +16 -0
  211. package/dist/locales/sk.js +380 -0
  212. package/dist/locales/sk.js.map +1 -0
  213. package/dist/locales/sq.cjs +765 -0
  214. package/dist/locales/sq.cjs.map +1 -0
  215. package/dist/locales/sq.d.cts +16 -0
  216. package/dist/locales/sq.d.ts +16 -0
  217. package/dist/locales/sq.js +339 -0
  218. package/dist/locales/sq.js.map +1 -0
  219. package/dist/locales/sr-Latn.cjs +853 -0
  220. package/dist/locales/sr-Latn.cjs.map +1 -0
  221. package/dist/locales/sr-Latn.d.cts +19 -0
  222. package/dist/locales/sr-Latn.d.ts +19 -0
  223. package/dist/locales/sr-Latn.js +86 -0
  224. package/dist/locales/sr-Latn.js.map +1 -0
  225. package/dist/locales/sr.cjs +781 -0
  226. package/dist/locales/sr.cjs.map +1 -0
  227. package/dist/locales/sr.d.cts +16 -0
  228. package/dist/locales/sr.d.ts +16 -0
  229. package/dist/locales/sr.js +14 -0
  230. package/dist/locales/sr.js.map +1 -0
  231. package/dist/locales/sv.cjs +765 -0
  232. package/dist/locales/sv.cjs.map +1 -0
  233. package/dist/locales/sv.d.cts +16 -0
  234. package/dist/locales/sv.d.ts +16 -0
  235. package/dist/locales/sv.js +339 -0
  236. package/dist/locales/sv.js.map +1 -0
  237. package/dist/locales/tr.cjs +762 -0
  238. package/dist/locales/tr.cjs.map +1 -0
  239. package/dist/locales/tr.d.cts +16 -0
  240. package/dist/locales/tr.d.ts +16 -0
  241. package/dist/locales/tr.js +336 -0
  242. package/dist/locales/tr.js.map +1 -0
  243. package/dist/locales/uk.cjs +806 -0
  244. package/dist/locales/uk.cjs.map +1 -0
  245. package/dist/locales/uk.d.cts +16 -0
  246. package/dist/locales/uk.d.ts +16 -0
  247. package/dist/locales/uk.js +380 -0
  248. package/dist/locales/uk.js.map +1 -0
  249. package/dist/markdown.cjs +620 -0
  250. package/dist/markdown.cjs.map +1 -0
  251. package/dist/markdown.d.cts +153 -0
  252. package/dist/markdown.d.ts +153 -0
  253. package/dist/markdown.js +573 -0
  254. package/dist/markdown.js.map +1 -0
  255. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  256. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  257. package/dist/mcp-app-sandbox.cjs +323 -0
  258. package/dist/mcp-app-sandbox.cjs.map +1 -0
  259. package/dist/mcp-app-sandbox.d.cts +70 -0
  260. package/dist/mcp-app-sandbox.d.ts +70 -0
  261. package/dist/mcp-app-sandbox.js +209 -0
  262. package/dist/mcp-app-sandbox.js.map +1 -0
  263. package/dist/mcp-app.cjs +980 -0
  264. package/dist/mcp-app.cjs.map +1 -0
  265. package/dist/mcp-app.d.cts +491 -0
  266. package/dist/mcp-app.d.ts +491 -0
  267. package/dist/mcp-app.js +816 -0
  268. package/dist/mcp-app.js.map +1 -0
  269. package/dist/pipeline.cjs +845 -0
  270. package/dist/pipeline.cjs.map +1 -0
  271. package/dist/pipeline.css +1407 -0
  272. package/dist/pipeline.d.cts +348 -0
  273. package/dist/pipeline.d.ts +348 -0
  274. package/dist/pipeline.js +778 -0
  275. package/dist/pipeline.js.map +1 -0
  276. package/dist/questions-Dw--IEjT.d.cts +100 -0
  277. package/dist/questions-Dw--IEjT.d.ts +100 -0
  278. package/dist/styles.css +4109 -0
  279. package/dist/types-CQquuZpl.d.cts +19 -0
  280. package/dist/types-CXZfZVP5.d.ts +19 -0
  281. package/dist/types-DnBCok3z.d.cts +994 -0
  282. package/dist/types-DnBCok3z.d.ts +994 -0
  283. package/package.json +165 -8
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Siarhei Dudko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,9 +1,320 @@
1
1
  # @dudko.dev/agent-web-ui
2
2
 
3
- The framework-free UI core of @dudko.dev/agent-web: the chat state reducer, labels, styles and the MCP Apps / sandbox security core.
3
+ [![npm](https://img.shields.io/npm/v/@dudko.dev/agent-web-ui.svg)](https://www.npmjs.com/package/@dudko.dev/agent-web-ui)
4
+ [![license](https://img.shields.io/npm/l/@dudko.dev/agent-web-ui.svg)](https://github.com/dudko-dev/agents/blob/main/LICENSE)
5
+ [![last commit](https://img.shields.io/github/last-commit/dudko-dev/agents.svg?path=packages%2Fagent-web-ui)](https://github.com/dudko-dev/agents/commits/main/packages/agent-web-ui)
4
6
 
5
- **Placeholder.** This version (0.0.0) holds no code. The package is built in
6
- [dudko-dev/agents](https://github.com/dudko-dev/agents) (`packages/agent-web-ui`), and its releases are
7
- published from there.
7
+ **[agent.dudko.dev](https://agent.dudko.dev)** · [live demo](https://agent.dudko.dev/demo/) · [source](https://github.com/dudko-dev/agents/tree/main/packages/agent-web-ui)
8
8
 
9
- MIT
9
+ The UI logic of [`@dudko.dev/agent-web`](https://www.npmjs.com/package/@dudko.dev/agent-web), the
10
+ in-browser LLM agent, **with no framework**. It is the part of
11
+ [`@dudko.dev/agent-web-react`](https://www.npmjs.com/package/@dudko.dev/agent-web-react) that never
12
+ needed React: what the chat shows, worked out as plain functions and data. Build a front end for
13
+ any framework on it - a web component, Vue, Angular, Svelte, plain DOM - or use it on a server.
14
+
15
+ - **The headless reducer** - `agentStateReducer` folds the core's `AgentEvent`s into an
16
+ `AgentUiState`: the plan, the steps and their tool calls, the streamed answer, the transcript,
17
+ usage, consent requests, a server's questions, the model's questions, subagents, files written,
18
+ MCP Apps. Pure: no clock, no randomness, no DOM.
19
+ - **Every UI string** - `AgentLabels` / `defaultLabels` / `mergeLabels` (and the pipeline editor's
20
+ `PipelineLabels`): one object to translate or reword.
21
+ - **The pure helpers** behind the chat: the message box (slash commands, attachments and their
22
+ refusals, the long-text rule), the files an answer names, the scroll that follows an answer, the
23
+ consent queue, the question queues, image downscaling, file kinds, formatting.
24
+ - **Voice** - recording over `getUserMedia` + `MediaRecorder` (every track stopped when it ends),
25
+ a recording as a speech recognizer, reading aloud with the device's voices or a provider's.
26
+ - **Saved chats** - `ChatHistoryStore` (IndexedDB, memory fallback) and the merge of two tabs'
27
+ saves of one chat.
28
+ - **The security cores**, as strings and plain objects: the sandboxed frame for untrusted HTML,
29
+ the MCP Apps frame (its policy, its shell, the extension's JSON-RPC bridge) and the MCP Apps
30
+ sandbox page a server serves on an origin of its own.
31
+ - **The stylesheets** - `styles.css` (the chat) and `pipeline.css` (the pipeline editor): plain
32
+ CSS, `awr-` classes and `--awr-*` custom properties, light and dark.
33
+
34
+ It ships no agent logic (the core does that) and draws nothing: a front end draws, this package
35
+ says what to draw. `@dudko.dev/agent-web-react` is built on it and re-exports everything it used to
36
+ export, so a React app keeps importing from the React package.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ npm i @dudko.dev/agent-web-ui @dudko.dev/agent-web
42
+ ```
43
+
44
+ `@dudko.dev/agent-web` is a peer dependency (one core per page; the type imports and the few
45
+ runtime helpers this package uses come from it). There is no other dependency. A React app does
46
+ not install this package itself: `@dudko.dev/agent-web-react` depends on it.
47
+
48
+ ## Entries
49
+
50
+ | Import | What | Imports |
51
+ | --- | --- | --- |
52
+ | `@dudko.dev/agent-web-ui` | the reducer and its types, the labels, the pure helpers, voice, saved chats, the sandboxed frame | the core |
53
+ | `@dudko.dev/agent-web-ui/mcp-app` | MCP Apps on the page's side: the frame's policy and shell, the bridge, the link to a sandbox page, an app's requests | the core |
54
+ | `@dudko.dev/agent-web-ui/mcp-app-sandbox` | the MCP Apps sandbox page for a SERVER (a Worker, Node, Deno, Bun): the page, its headers, a `Request` → `Response` handler | nothing |
55
+ | `@dudko.dev/agent-web-ui/pipeline` | the pipeline editor's logic: the reducer of a pipeline run, the editing helpers, the code generator, the editor's strings | the core |
56
+ | `@dudko.dev/agent-web-ui/canvas` | the generic canvas's maths (viewport, curves, hit tests, layout order) and its strings | nothing |
57
+ | `@dudko.dev/agent-web-ui/controller` | the agent as a store any front end wraps: `createAgentController` (see [Controller](#controller)) | the core (its `createAgent`) |
58
+ | `@dudko.dev/agent-web-ui/markdown` | the answers' Markdown as a tree any front end draws: the parser, the parser of an answer still being written, `safeHref`, the renderer's helpers (see [Markdown](#markdown)) | nothing |
59
+ | `@dudko.dev/agent-web-ui/locales` | the chat's labels in your language, loaded on demand: `loadAgentLabels(tag)`, the list of tags, `labelsFromCatalog` | nothing |
60
+ | `@dudko.dev/agent-web-ui/locales/<tag>` | one language's labels (`labels`) and its catalog (`catalog`) | nothing |
61
+ | `@dudko.dev/agent-web-ui/styles.css` | the chat's stylesheet | - |
62
+ | `@dudko.dev/agent-web-ui/pipeline.css` | the pipeline editor's stylesheet (stands on its own) | - |
63
+
64
+ The main entry also carries the DOM-root helpers a front end needs when its chat may live in a
65
+ shadow root (a web component): `rootOf`, `activeElementOf`, `deepActiveElement`, `nothingFocused`,
66
+ `isEventInside`, `eventTargetOf`, `deepElementFromPoint`, `composedContains`, `shadowRootsAround`,
67
+ `listenScrollAround`, `portalHostOf`. From the document, everything inside a shadow root is its
68
+ host (the focus, a click's target, the element under a point); these ask the component's own root,
69
+ and in the light DOM answer exactly what the `document` call does.
70
+
71
+ Every entry is ESM and CommonJS with types. The main entry never mentions the core's
72
+ `./mcp` subpath, the MCP SDK, the pipeline code, the Markdown parser, the controller (the core's
73
+ `createAgent`) or the MCP Apps frame - not in itself and not in a
74
+ chunk it loads - so a host that uses none of them carries none of them (`tests/entries.test.ts`
75
+ reads the built files).
76
+
77
+ ## The reducer is the seam
78
+
79
+ Everything a chat shows is a function of the events the agent emitted. Keep a state, fold every
80
+ event into it, draw the state:
81
+
82
+ ```ts
83
+ import { createAgent } from '@dudko.dev/agent-web'
84
+ import { agentStateReducer, createInitialAgentState, defaultLabels } from '@dudko.dev/agent-web-ui'
85
+
86
+ let state = createInitialAgentState()
87
+ const render = () => {
88
+ // your framework here: state.status, state.steps, state.messages, state.approvals, …
89
+ document.querySelector('#status')!.textContent = defaultLabels.status[state.status]
90
+ }
91
+
92
+ const agent = await createAgent(config)
93
+ await agent.run(goal, {
94
+ onEvent: (event) => {
95
+ state = agentStateReducer(state, { type: 'event', event, at: Date.now() })
96
+ render()
97
+ },
98
+ })
99
+ ```
100
+
101
+ The reducer never mutates the state it is given: each action gives a new state object, which
102
+ suits any framework's change detection. The actions besides
103
+ `event` are what the host did (`AgentAction`): a status, a reset, a saved chat loaded, the
104
+ notebook, messages that never reached the model, a text sent to a run in another tab. The run's
105
+ own start, steps and end are events (`run.start`, …). `at` is the only clock: the reducer reads
106
+ none of its own. The state is made of plain, exported view types (`StepView`,
107
+ `ToolCallView`, `ApprovalView`, `ElicitationView`, `QuestionView`, `SubagentView`, `ChatMessage`,
108
+ `AppView`, …): see the React package's [docs/chat.md](https://github.com/dudko-dev/agents/blob/main/packages/agent-web-react/docs/chat.md) for what each
109
+ field means - the React components draw exactly these.
110
+
111
+ What the reducer guarantees, for a UI of your own too: a person's own words given to the model's
112
+ `ask_user` never stay in the steps or a saved chat (`withoutOwnWords`), a server's form and an MCP
113
+ skill's text are never mirrored onto a saved message, and a consent request of an MCP App outlives
114
+ the run that showed it.
115
+
116
+ ## Controller
117
+
118
+ `@dudko.dev/agent-web-ui/controller` is everything `useAgent` of the React package does that is not
119
+ React, as a store: it builds the agent, folds its events into the state above, runs, stops and
120
+ steers it, keeps the consent and question queues, follows a run of the conversation in another
121
+ tab, and keeps the usage. React's `useAgent` is this controller and `useSyncExternalStore`; a web
122
+ component, Vue, Angular or Svelte wraps the same controller and re-implements none of it.
123
+
124
+ The contract:
125
+
126
+ - `createAgentController(config, options?)` builds the agent at once (unless `autoStart: false`, or
127
+ the config has no `model` yet) and starts following other tabs. Make one when the view appears.
128
+ - `getSnapshot()` is everything the view draws: the `AgentUiState`, `status`, `isReady`,
129
+ `isRunning`, `pendingApprovals`, `pendingQuestions`, `approvalMode`, `sessionId`. It is frozen,
130
+ the same object while nothing changes and a new one after every change.
131
+ - `subscribe(listener)` calls `listener` after every change - never at once - and returns the
132
+ unsubscribe (React's `useSyncExternalStore` contract).
133
+ - The methods: `run`, `stop`, `send`, `stopSubagent`, `sendRemote`, `stopRemote`,
134
+ `sendUndelivered`, `discardUndelivered`, `reset`, `reload`, `loadChat`, `approve`, `deny`,
135
+ `answerQuestion`, `setApprovalMode`, `approveAppToolCall`, `sampleForApp`, `compact`,
136
+ `forgetSkill`, and the `agent` getter (the built agent, once ready). They are what `useAgent`
137
+ returns, with the same meaning: see the React package's README.
138
+ - `update(config, { options?, rebuild? })` takes a new config: by default it builds a new agent
139
+ (a `deps` change of `useAgent`), the transcript kept; `rebuild: false` only takes the latest
140
+ config and options and applies what is live (a new `toolApproval.mode`, another store to follow
141
+ other tabs through).
142
+ - `dispose()` tears it all down: the run aborted, its consent requests denied and its questions
143
+ declined ("the view was closed"), an MCP App's waiting request denied, a build in progress
144
+ dropped, the other-tab channels closed, pending timers cleared, every listener let go. The
145
+ snapshot stays as it was and every method is then a no-op. Call it when the view goes away.
146
+
147
+ Options (`AgentControllerOptions`): `onEvent`, `autoStart`, `maxEvents`, `appToolGrants`,
148
+ `approvals`, `questions`, `followUp`, `watch` - the options of `useAgent` without `deps`.
149
+ `createInitialAgentSnapshot(config)` is the snapshot before any controller exists (a first
150
+ render that must not make one, a server render).
151
+
152
+ A custom UI in plain JS:
153
+
154
+ ```js
155
+ import { createAgentController } from '@dudko.dev/agent-web-ui/controller'
156
+
157
+ const chat = createAgentController({ model, credentials, toolApproval: { mode: 'ask-writes' } })
158
+ const render = () => {
159
+ const s = chat.getSnapshot()
160
+ status.textContent = s.status
161
+ log.textContent = s.messages.map((m) => `${m.role}: ${m.content}`).join('\n')
162
+ allow.hidden = s.pendingApprovals.length === 0
163
+ }
164
+ const off = chat.subscribe(render)
165
+ render()
166
+ send.onclick = () => (chat.getSnapshot().isRunning ? chat.send(input.value) : chat.run(input.value))
167
+ stop.onclick = () => chat.stop()
168
+ allow.onclick = () => chat.approve(chat.getSnapshot().pendingApprovals[0].id)
169
+ // when the view goes away: off(); chat.dispose()
170
+ ```
171
+
172
+ ## Labels
173
+
174
+ `defaultLabels` is every string the chat shows; counted phrases are functions so that languages
175
+ with several plural forms can say them. `mergeLabels(defaultLabels, overrides)` merges the nested
176
+ groups key by key. The React package's `<AgentLabelsProvider>` / `useLabels` are this object in a
177
+ React context; a web component or a Vue plugin can do the same with its own mechanism.
178
+
179
+ ## Markdown
180
+
181
+ `./markdown` turns a model's Markdown into a small tree - blocks (`p`, `h`, `code`, `quote`, `hr`,
182
+ `list`, `table`) of inline runs (`text`, `br`, `code`, `strong`, `em`, `del`, `link`, `file`) - that
183
+ a renderer of any front end draws as elements, never as HTML. The React package's `<Markdown>`
184
+ (`@dudko.dev/agent-web-react/markdown`) is one; a web component or a Vue / Svelte component draws
185
+ the same tree the same way.
186
+
187
+ ```ts
188
+ import {
189
+ parseMarkdownCached, // a finished text (cached by its text)
190
+ parseMarkdownStreaming, // a text still being written, given the parse of what it was before
191
+ emptyMarkdownStream,
192
+ markdownCellIsLong,
193
+ type MarkdownBlock,
194
+ } from '@dudko.dev/agent-web-ui/markdown'
195
+
196
+ let stream = emptyMarkdownStream()
197
+ const blocksOf = (text: string, pending: boolean): MarkdownBlock[] =>
198
+ pending ? (stream = parseMarkdownStreaming(stream, text)).blocks : parseMarkdownCached(text)
199
+ ```
200
+
201
+ What it reads: paragraphs with their line breaks, headings, lists (nested, at most 9 levels),
202
+ fenced code (at any indentation), quotes, rules, GFM tables, `**bold**`, `*italic*`,
203
+ `~~struck~~`, `` `code` ``, links and bare `http(s)` URLs. While an answer is written
204
+ (`parseMarkdownStreaming`) nothing already drawn changes its kind or gets shorter: the last line
205
+ waits while it is only markers, emphasis open at the end is drawn closed, a link is its words
206
+ until its address is whole, and the finished blocks are kept as the same objects.
207
+
208
+ It is a security boundary for a host - the text is the model's:
209
+
210
+ - **Raw HTML is text**: `<script>`, `<img onerror>`, entities - the characters as written. There is
211
+ no node that is markup or carries an attribute.
212
+ - **A link only to `http(s)` or `mailto`** (`safeHref`): anything else - `javascript:`, `data:`,
213
+ `vbscript:`, `file:`, `//host`, a relative address, and their obfuscated forms (entities, which
214
+ are never decoded, percent-encoding, blanks inside, case) - stays text.
215
+ - **A link to a workspace file** is `{ t: 'file', path }` only when its destination,
216
+ percent-decoded first, is a workspace path by `workspacePathOf` (absolute, no `..` / `.` /
217
+ empty segment, no `//host`, no backslash or control character) - `%2e%2e`, `%2F%2Fhost`, `%5C`
218
+ are refused; a whole code span that is one carries `path`. A renderer draws it as a control that
219
+ opens the file in the page, never as `<a href>`. A link's words hold no link of their own.
220
+ - **No picture** is loaded from an answer: `![a](…)` is its `!` and a link (or a file link).
221
+ - **Linear on any text**: one pass for code spans, lookups for brackets and destinations, one
222
+ opener stack per kind of emphasis, list nesting bounded - long runs of `*`, `_`, `[`, backticks,
223
+ `>`, `|` or ever-deeper lists cost what plain text does (`tests/markdown.test.ts` times them).
224
+
225
+ ## In your language
226
+
227
+ The chat's labels come translated into 33 languages - the same 33 as the app at
228
+ https://agent.dudko.dev/app/, whose translations they are:
229
+
230
+ `en`, `ru`, `uk`, `be`, `pl`, `cs`, `sk`, `hr`, `sr`, `sr-Latn`, `bg`, `ro`, `hu`, `de`, `fr`, `it`,
231
+ `es`, `pt`, `nl`, `da`, `sv`, `nb`, `fi`, `el`, `sq`, `ca`, `tr`, `es-419`, `pt-BR`, `fr-CA`, `ht`,
232
+ `qu`, `gn`.
233
+
234
+ ```ts
235
+ import { loadAgentLabels } from '@dudko.dev/agent-web-ui/locales'
236
+ import { defaultLabels, mergeLabels } from '@dudko.dev/agent-web-ui'
237
+
238
+ const labels = mergeLabels(defaultLabels, await loadAgentLabels(navigator.language))
239
+ ```
240
+
241
+ - **One language, one file.** Each language is an entry of its own
242
+ (`@dudko.dev/agent-web-ui/locales/<tag>`), and `loadAgentLabels` loads it with a literal
243
+ `import()`, so a bundler makes a chunk of each: a page in Russian downloads Russian only (about
244
+ 27 KB, 7 KB gzipped), plus the builder every language shares (5 KB gzipped). The variants carry their
245
+ base too: `es-419` is Spanish with the words of the Americas, `fr-CA` French with Québec's
246
+ punctuation, `sr-Latn` the Cyrillic catalog transliterated letter for letter. To have one
247
+ language in your main bundle instead, import it: `import { labels } from
248
+ '@dudko.dev/agent-web-ui/locales/de'`.
249
+ - **Which language.** `loadAgentLabels(tag)` takes any BCP 47 tag: the exact tag (`pt-BR`), then its
250
+ language and script (`sr-Latn-RS` → `sr-Latn`), then its language (`de-AT` → `de`, `es-MX` →
251
+ `es`, `no` → `nb`), then English - also for a tag that is not one. `agentLabelLocaleOf(tag)`
252
+ tells which it picks; `AGENT_LABEL_LOCALES` is the list. Choosing `es-419` for `es-MX` is the
253
+ host's call: pass the tag you mean.
254
+ - **What is not translated stays English.** The labels are an `AgentLabelsOverride`: the chat's
255
+ strings the app shows. What they do not cover yet (a few parts of `AgentLabels` the app does
256
+ not mount, and `emptyState`, which is the host's own words) falls back to `defaultLabels` once
257
+ merged.
258
+ - **Plurals and numbers** are the language's own: a counted phrase picks its form with
259
+ `Intl.PluralRules(tag)` (Russian: 1 шаг, 2 шага, 5 шагов, 21 шаг) and writes its number with
260
+ `Intl.NumberFormat(tag)` (1 234 in Russian, 1.234 in German); sizes and token counts are
261
+ `Intl.NumberFormat`'s units and compact form. No library.
262
+ - **Your own wording or language.** `labelsFromCatalog(tag, catalog)` builds the labels from a
263
+ catalog of the same keys (`AgentLabelCatalog`; plural entries as `{ one, few, many, other }` -
264
+ the categories of the language - with `{count}`): take a language's `catalog`, change what you
265
+ like, or translate English's.
266
+ - **Machine-made, not reviewed:** `ht` (Kreyòl ayisyen), `qu` (Runa Simi) and `gn` (Avañe'ẽ) were
267
+ written with care but have not been read by a native speaker yet - the app marks them the same
268
+ way. Corrections are welcome. The other 30 are reviewed.
269
+
270
+ ## Security boundaries
271
+
272
+ Four parts of this package are security boundaries. Each guard has a `guard …` test here
273
+ (`tests/files.test.ts`, `tests/apps*.test.ts`, `tests/app-prompts.test.ts`, `tests/markdown.test.ts`), the React package's
274
+ browser tests run hostile pages and a hostile MCP App against them, and a change needs a mutation
275
+ check.
276
+
277
+ - **The sandboxed frame** (`buildSandboxedDocument`, `sandboxedCsp`, `sandboxTokens`): untrusted
278
+ HTML goes into `<iframe sandbox>` WITHOUT `allow-same-origin`, under a policy with no network
279
+ source, framed by a document of ours whose `frame-src 'none'` is what stops it navigating itself.
280
+ Never render a workspace file by `blob:` / `data:` URL or as markup.
281
+ - **The MCP Apps frame** (`./mcp-app`): the app's policy from its resource's declared origins ONLY
282
+ (frames, workers and `<base>` never granted; `'wasm-unsafe-eval'` always, `'unsafe-eval'` never),
283
+ one inner `sandbox="allow-scripts"` frame, and `McpAppBridge` - an allow-list of methods, their
284
+ parameters checked, nothing but `ping` before `ui/initialize`.
285
+ - **The sandbox page** (`./mcp-app-sandbox`, for a server): an app on an origin of its own. It
286
+ binds to the first ancestor on an allowed host that sends `sandbox-resource-ready`, once, relays
287
+ to exact origins only, and ignores a `sandbox`, `csp` or `permissions` the host sends: the
288
+ header is the policy, and `frame-ancestors` names the hosts.
289
+ - **The Markdown parser** (`./markdown`): raw HTML is text, links only to `http(s)` / `mailto`, a
290
+ file link only to a workspace path (decoded first), no picture, linear on any text - see
291
+ [Markdown](#markdown).
292
+
293
+ ```ts
294
+ // A Cloudflare Worker serving the sandbox page
295
+ import { mcpAppSandboxResponse } from '@dudko.dev/agent-web-ui/mcp-app-sandbox'
296
+
297
+ export default {
298
+ fetch: (request: Request, env: { HOSTS?: string }) =>
299
+ mcpAppSandboxResponse(request, { path: '/sandbox/v1', hosts: env.HOSTS }),
300
+ }
301
+ ```
302
+
303
+ How an app runs and what the two modes trade: the React package's
304
+ [docs/chat.md](https://github.com/dudko-dev/agents/blob/main/packages/agent-web-react/docs/chat.md#an-app-on-an-origin-of-its-own).
305
+
306
+ ## Who uses it
307
+
308
+ - [`@dudko.dev/agent-web-react`](https://github.com/dudko-dev/agents/blob/main/packages/agent-web-react/README.md) - the hook, the context and the components; it
309
+ imports this package (one copy on a page) and re-exports its names, and ships its stylesheets at
310
+ `@dudko.dev/agent-web-react/styles.css` and `/pipeline.css`, copied from here.
311
+ - [`apps/app`](https://github.com/dudko-dev/agents/tree/main/apps/app) and
312
+ [`apps/demo`](https://github.com/dudko-dev/agents/tree/main/apps/demo) draw their answers'
313
+ Markdown with `./markdown`, through the React package's `<Markdown>`.
314
+ - [`apps/app-sandbox`](https://github.com/dudko-dev/agents/tree/main/apps/app-sandbox) - the demo's
315
+ and the app's MCP Apps sandbox page on Cloudflare, `./mcp-app-sandbox` and nothing else.
316
+ - A web component, Vue / Angular / Svelte bindings: built on this package, not on React.
317
+
318
+ ## License
319
+
320
+ MIT © Siarhei Dudko
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/canvas/index.ts
21
+ var canvas_exports = {};
22
+ __export(canvas_exports, {
23
+ DEFAULT_MAX_ZOOM: () => DEFAULT_MAX_ZOOM,
24
+ DEFAULT_MIN_ZOOM: () => DEFAULT_MIN_ZOOM,
25
+ IDENTITY_VIEWPORT: () => IDENTITY_VIEWPORT,
26
+ boundsOf: () => boundsOf,
27
+ centerOn: () => centerOn,
28
+ clamp: () => clamp,
29
+ curvePath: () => curvePath,
30
+ curvePoint: () => curvePoint,
31
+ defaultCanvasLabels: () => defaultCanvasLabels,
32
+ distanceToCurve: () => distanceToCurve,
33
+ edgeCurve: () => edgeCurve,
34
+ fitViewport: () => fitViewport,
35
+ hitEdge: () => hitEdge,
36
+ hitNode: () => hitNode,
37
+ inputAnchor: () => inputAnchor,
38
+ isRectVisible: () => isRectVisible,
39
+ outputAnchor: () => outputAnchor,
40
+ panBy: () => panBy,
41
+ pinchViewport: () => pinchViewport,
42
+ readingOrder: () => readingOrder,
43
+ rectContains: () => rectContains,
44
+ screenToWorld: () => screenToWorld,
45
+ snapPoint: () => snapPoint,
46
+ snapTo: () => snapTo,
47
+ worldToScreen: () => worldToScreen,
48
+ zoomAt: () => zoomAt
49
+ });
50
+ module.exports = __toCommonJS(canvas_exports);
51
+
52
+ // src/canvas/labels.ts
53
+ var defaultCanvasLabels = {
54
+ canvas: "Canvas",
55
+ help: "Tab moves between nodes and their connections. Arrow keys move the selected node, Enter opens it, Delete removes it, C starts a connection, Escape clears the selection. On the canvas itself the arrow keys pan, plus and minus zoom, 0 fits everything.",
56
+ node: "node",
57
+ edge: (from, to, description) => `Connection from ${from} to ${to}${description ? `: ${description}` : ""}`,
58
+ port: (node, port) => `Connect ${node}${port ? ` (${port})` : ""} to another node`,
59
+ connectsTo: (names) => `Connects to: ${names}.`,
60
+ receivesFrom: (names) => `Receives from: ${names}.`,
61
+ zoomIn: "Zoom in",
62
+ zoomOut: "Zoom out",
63
+ fit: "Fit to view",
64
+ zoomLevel: (percent) => `${percent}%`,
65
+ connectHint: (from) => `Pick the node to connect ${from} to`,
66
+ cancel: "Cancel",
67
+ connected: (from, to) => `Connected ${from} to ${to}`
68
+ };
69
+
70
+ // src/canvas/geometry.ts
71
+ var DEFAULT_MIN_ZOOM = 0.25;
72
+ var DEFAULT_MAX_ZOOM = 2;
73
+ var IDENTITY_VIEWPORT = { x: 0, y: 0, zoom: 1 };
74
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
75
+ var screenToWorld = (point, viewport) => ({
76
+ x: (point.x - viewport.x) / viewport.zoom,
77
+ y: (point.y - viewport.y) / viewport.zoom
78
+ });
79
+ var worldToScreen = (point, viewport) => ({
80
+ x: point.x * viewport.zoom + viewport.x,
81
+ y: point.y * viewport.zoom + viewport.y
82
+ });
83
+ var panBy = (viewport, dx, dy) => ({
84
+ ...viewport,
85
+ x: viewport.x + dx,
86
+ y: viewport.y + dy
87
+ });
88
+ var zoomAt = (viewport, zoom, anchor, minZoom = DEFAULT_MIN_ZOOM, maxZoom = DEFAULT_MAX_ZOOM) => {
89
+ const next = clamp(zoom, minZoom, maxZoom);
90
+ if (next === viewport.zoom) return viewport;
91
+ const world = screenToWorld(anchor, viewport);
92
+ return { zoom: next, x: anchor.x - world.x * next, y: anchor.y - world.y * next };
93
+ };
94
+ var pinchViewport = (viewport, before, after, minZoom = DEFAULT_MIN_ZOOM, maxZoom = DEFAULT_MAX_ZOOM) => {
95
+ const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
96
+ const middle = (a, b) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
97
+ const was = distance(before[0], before[1]);
98
+ const is = distance(after[0], after[1]);
99
+ const zoom = clamp(was > 0 ? viewport.zoom * is / was : viewport.zoom, minZoom, maxZoom);
100
+ const world = screenToWorld(middle(before[0], before[1]), viewport);
101
+ const at = middle(after[0], after[1]);
102
+ return { zoom, x: at.x - world.x * zoom, y: at.y - world.y * zoom };
103
+ };
104
+ var boundsOf = (rects) => {
105
+ if (rects.length === 0) return void 0;
106
+ let left = Infinity;
107
+ let top = Infinity;
108
+ let right = -Infinity;
109
+ let bottom = -Infinity;
110
+ for (const r of rects) {
111
+ left = Math.min(left, r.x);
112
+ top = Math.min(top, r.y);
113
+ right = Math.max(right, r.x + r.width);
114
+ bottom = Math.max(bottom, r.y + r.height);
115
+ }
116
+ return { x: left, y: top, width: right - left, height: bottom - top };
117
+ };
118
+ var fitAxis = (start, length, room, zoom, padding) => length * zoom <= room - padding * 2 + 0.5 ? (room - length * zoom) / 2 - start * zoom : padding - start * zoom;
119
+ var fitViewport = (rects, size, options = {}) => {
120
+ const bounds = boundsOf(rects);
121
+ if (!bounds || size.width <= 0 || size.height <= 0) return IDENTITY_VIEWPORT;
122
+ const { minZoom = DEFAULT_MIN_ZOOM, maxZoom = 1 } = options;
123
+ const padding = Math.min(options.padding ?? 48, size.width / 8, size.height / 8);
124
+ const zoom = clamp(
125
+ Math.min(
126
+ (size.width - padding * 2) / Math.max(bounds.width, 1),
127
+ (size.height - padding * 2) / Math.max(bounds.height, 1)
128
+ ),
129
+ minZoom,
130
+ maxZoom
131
+ );
132
+ return {
133
+ zoom,
134
+ x: fitAxis(bounds.x, bounds.width, size.width, zoom, padding),
135
+ y: fitAxis(bounds.y, bounds.height, size.height, zoom, padding)
136
+ };
137
+ };
138
+ var centerOn = (rect, size, zoom) => ({
139
+ zoom,
140
+ x: size.width / 2 - (rect.x + rect.width / 2) * zoom,
141
+ y: size.height / 2 - (rect.y + rect.height / 2) * zoom
142
+ });
143
+ var isRectVisible = (rect, size, viewport) => {
144
+ const a = worldToScreen(rect, viewport);
145
+ const b = worldToScreen({ x: rect.x + rect.width, y: rect.y + rect.height }, viewport);
146
+ return b.x > 0 && b.y > 0 && a.x < size.width && a.y < size.height;
147
+ };
148
+ var snapTo = (value, grid) => (
149
+ // `+ 0`: a rounded-away negative is 0, not -0.
150
+ grid > 0 ? Math.round(value / grid) * grid + 0 : value
151
+ );
152
+ var snapPoint = (point, grid) => ({
153
+ x: snapTo(point.x, grid),
154
+ y: snapTo(point.y, grid)
155
+ });
156
+ var rectContains = (rect, point) => point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
157
+ var hitNode = (nodes, point) => {
158
+ for (let i = nodes.length - 1; i >= 0; i--) {
159
+ if (rectContains(nodes[i], point)) return nodes[i].id;
160
+ }
161
+ return void 0;
162
+ };
163
+ var inputAnchor = (rect) => ({ x: rect.x, y: rect.y + rect.height / 2 });
164
+ var outputAnchor = (rect, index = 0, count = 1) => ({
165
+ x: rect.x + rect.width,
166
+ y: rect.y + rect.height * (index + 1) / (Math.max(count, 1) + 1)
167
+ });
168
+ var edgeCurve = (from, to, options = {}) => {
169
+ const dx = to.x - from.x;
170
+ const dy = to.y - from.y;
171
+ if (dx >= 40) {
172
+ const reach2 = Math.max(dx / 2, 40);
173
+ return {
174
+ p0: from,
175
+ p1: { x: from.x + reach2, y: from.y },
176
+ p2: { x: to.x - reach2, y: to.y },
177
+ p3: to
178
+ };
179
+ }
180
+ const reach = clamp(60 + Math.abs(dx) / 4, 60, 220);
181
+ const clearance = options.clearance ?? 90;
182
+ const swing = Math.abs(dy) < clearance ? clearance + Math.abs(dy) / 2 : 0;
183
+ return {
184
+ p0: from,
185
+ p1: { x: from.x + reach, y: from.y + swing },
186
+ p2: { x: to.x - reach, y: to.y + swing },
187
+ p3: to
188
+ };
189
+ };
190
+ var round = (n) => Math.round(n * 100) / 100;
191
+ var curvePath = ({ p0, p1, p2, p3 }) => `M ${round(p0.x)} ${round(p0.y)} C ${round(p1.x)} ${round(p1.y)}, ${round(p2.x)} ${round(p2.y)}, ${round(p3.x)} ${round(p3.y)}`;
192
+ var curvePoint = ({ p0, p1, p2, p3 }, t) => {
193
+ const u = 1 - t;
194
+ const a = u * u * u;
195
+ const b = 3 * u * u * t;
196
+ const c = 3 * u * t * t;
197
+ const d = t * t * t;
198
+ return {
199
+ x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,
200
+ y: a * p0.y + b * p1.y + c * p2.y + d * p3.y
201
+ };
202
+ };
203
+ var distanceToSegment = (p, a, b) => {
204
+ const dx = b.x - a.x;
205
+ const dy = b.y - a.y;
206
+ const length = dx * dx + dy * dy;
207
+ const t = length === 0 ? 0 : clamp(((p.x - a.x) * dx + (p.y - a.y) * dy) / length, 0, 1);
208
+ return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
209
+ };
210
+ var distanceToCurve = (curve, point, samples = 24) => {
211
+ let best = Infinity;
212
+ let previous = curve.p0;
213
+ for (let i = 1; i <= samples; i++) {
214
+ const next = curvePoint(curve, i / samples);
215
+ best = Math.min(best, distanceToSegment(point, previous, next));
216
+ previous = next;
217
+ }
218
+ return best;
219
+ };
220
+ var hitEdge = (edges, point, tolerance = 8) => {
221
+ let best;
222
+ let bestDistance = Infinity;
223
+ for (const edge of edges) {
224
+ const distance = distanceToCurve(edge.curve, point);
225
+ if (distance <= tolerance && distance < bestDistance) {
226
+ best = edge.id;
227
+ bestDistance = distance;
228
+ }
229
+ }
230
+ return best;
231
+ };
232
+ var readingOrder = (nodes, column = 40) => nodes.map((node, index) => ({ node, index })).sort((a, b) => {
233
+ const ax = Math.round(a.node.x / column);
234
+ const bx = Math.round(b.node.x / column);
235
+ return ax - bx || a.node.y - b.node.y || a.index - b.index;
236
+ }).map(({ node }) => node.id);
237
+ // Annotate the CommonJS export names for ESM import in node:
238
+ 0 && (module.exports = {
239
+ DEFAULT_MAX_ZOOM,
240
+ DEFAULT_MIN_ZOOM,
241
+ IDENTITY_VIEWPORT,
242
+ boundsOf,
243
+ centerOn,
244
+ clamp,
245
+ curvePath,
246
+ curvePoint,
247
+ defaultCanvasLabels,
248
+ distanceToCurve,
249
+ edgeCurve,
250
+ fitViewport,
251
+ hitEdge,
252
+ hitNode,
253
+ inputAnchor,
254
+ isRectVisible,
255
+ outputAnchor,
256
+ panBy,
257
+ pinchViewport,
258
+ readingOrder,
259
+ rectContains,
260
+ screenToWorld,
261
+ snapPoint,
262
+ snapTo,
263
+ worldToScreen,
264
+ zoomAt
265
+ });
266
+ //# sourceMappingURL=canvas.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/canvas/index.ts","../src/canvas/labels.ts","../src/canvas/geometry.ts"],"sourcesContent":["// The generic canvas's maths (pure functions) and its strings: nothing of agents, no React, no\n// import at all. The React canvas (`@dudko.dev/agent-web-react/pipeline`'s `Canvas`) draws with it;\n// another framework's canvas can too.\nexport { defaultCanvasLabels } from './labels.js'\nexport type { CanvasLabels } from './labels.js'\nexport {\n boundsOf,\n centerOn,\n clamp,\n curvePath,\n curvePoint,\n DEFAULT_MAX_ZOOM,\n DEFAULT_MIN_ZOOM,\n distanceToCurve,\n edgeCurve,\n fitViewport,\n hitEdge,\n hitNode,\n IDENTITY_VIEWPORT,\n inputAnchor,\n isRectVisible,\n outputAnchor,\n panBy,\n pinchViewport,\n readingOrder,\n rectContains,\n screenToWorld,\n snapPoint,\n snapTo,\n worldToScreen,\n zoomAt,\n} from './geometry.js'\nexport type {\n Curve,\n EdgeCurveOptions,\n FitOptions,\n Point,\n Rect,\n Size,\n Viewport,\n} from './geometry.js'\n","// The canvas's strings: what it shows and says to a screen reader. Generic - nothing of agents.\n\n/** Every string the canvas shows or says. */\nexport interface CanvasLabels {\n /** The canvas's own name for a screen reader. */\n canvas: string\n /** How to use it with a keyboard; read once, when the canvas is focused. */\n help: string\n /** `aria-roledescription` of a node. */\n node: string\n edge: (from: string, to: string, description?: string) => string\n port: (node: string, port?: string) => string\n connectsTo: (names: string) => string\n receivesFrom: (names: string) => string\n zoomIn: string\n zoomOut: string\n fit: string\n zoomLevel: (percent: number) => string\n /** Shown (and announced) while a connection is being made without dragging. */\n connectHint: (from: string) => string\n cancel: string\n connected: (from: string, to: string) => string\n}\n\nexport const defaultCanvasLabels: CanvasLabels = {\n canvas: 'Canvas',\n help: 'Tab moves between nodes and their connections. Arrow keys move the selected node, Enter opens it, Delete removes it, C starts a connection, Escape clears the selection. On the canvas itself the arrow keys pan, plus and minus zoom, 0 fits everything.',\n node: 'node',\n edge: (from, to, description) =>\n `Connection from ${from} to ${to}${description ? `: ${description}` : ''}`,\n port: (node, port) => `Connect ${node}${port ? ` (${port})` : ''} to another node`,\n connectsTo: (names) => `Connects to: ${names}.`,\n receivesFrom: (names) => `Receives from: ${names}.`,\n zoomIn: 'Zoom in',\n zoomOut: 'Zoom out',\n fit: 'Fit to view',\n zoomLevel: (percent) => `${percent}%`,\n connectHint: (from) => `Pick the node to connect ${from} to`,\n cancel: 'Cancel',\n connected: (from, to) => `Connected ${from} to ${to}`,\n}\n","// The canvas's maths: viewport transforms, fitting, hit testing and the shape of an edge.\n// Pure functions over plain numbers - no DOM, no React - so they are unit-tested as they are.\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Size {\n width: number\n height: number\n}\n\nexport interface Rect extends Point, Size {}\n\n/**\n * Where the world sits on the screen: a world point `p` is drawn at\n * `p * zoom + (x, y)`, in pixels from the canvas's top-left corner.\n */\nexport interface Viewport {\n x: number\n y: number\n zoom: number\n}\n\n/** The four control points of a cubic Bezier curve. */\nexport interface Curve {\n p0: Point\n p1: Point\n p2: Point\n p3: Point\n}\n\nexport const DEFAULT_MIN_ZOOM = 0.25\nexport const DEFAULT_MAX_ZOOM = 2\nexport const IDENTITY_VIEWPORT: Viewport = { x: 0, y: 0, zoom: 1 }\n\nexport const clamp = (value: number, min: number, max: number): number =>\n Math.min(max, Math.max(min, value))\n\nexport const screenToWorld = (point: Point, viewport: Viewport): Point => ({\n x: (point.x - viewport.x) / viewport.zoom,\n y: (point.y - viewport.y) / viewport.zoom,\n})\n\nexport const worldToScreen = (point: Point, viewport: Viewport): Point => ({\n x: point.x * viewport.zoom + viewport.x,\n y: point.y * viewport.zoom + viewport.y,\n})\n\nexport const panBy = (viewport: Viewport, dx: number, dy: number): Viewport => ({\n ...viewport,\n x: viewport.x + dx,\n y: viewport.y + dy,\n})\n\n/** Set the zoom, keeping the world point under `anchor` (a screen point) where it is. */\nexport const zoomAt = (\n viewport: Viewport,\n zoom: number,\n anchor: Point,\n minZoom = DEFAULT_MIN_ZOOM,\n maxZoom = DEFAULT_MAX_ZOOM,\n): Viewport => {\n const next = clamp(zoom, minZoom, maxZoom)\n if (next === viewport.zoom) return viewport\n const world = screenToWorld(anchor, viewport)\n return { zoom: next, x: anchor.x - world.x * next, y: anchor.y - world.y * next }\n}\n\n/**\n * Two fingers moved from `before` to `after` (screen points): zoom by how far apart they went,\n * and keep the world point that was between them under the point that is between them now.\n */\nexport const pinchViewport = (\n viewport: Viewport,\n before: [Point, Point],\n after: [Point, Point],\n minZoom = DEFAULT_MIN_ZOOM,\n maxZoom = DEFAULT_MAX_ZOOM,\n): Viewport => {\n const distance = (a: Point, b: Point) => Math.hypot(a.x - b.x, a.y - b.y)\n const middle = (a: Point, b: Point): Point => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 })\n const was = distance(before[0], before[1])\n const is = distance(after[0], after[1])\n const zoom = clamp(was > 0 ? (viewport.zoom * is) / was : viewport.zoom, minZoom, maxZoom)\n const world = screenToWorld(middle(before[0], before[1]), viewport)\n const at = middle(after[0], after[1])\n return { zoom, x: at.x - world.x * zoom, y: at.y - world.y * zoom }\n}\n\n/** The smallest rectangle around all of `rects`; undefined when there are none. */\nexport const boundsOf = (rects: Rect[]): Rect | undefined => {\n if (rects.length === 0) return undefined\n let left = Infinity\n let top = Infinity\n let right = -Infinity\n let bottom = -Infinity\n for (const r of rects) {\n left = Math.min(left, r.x)\n top = Math.min(top, r.y)\n right = Math.max(right, r.x + r.width)\n bottom = Math.max(bottom, r.y + r.height)\n }\n return { x: left, y: top, width: right - left, height: bottom - top }\n}\n\nexport interface FitOptions {\n /** Free space kept around the content, in screen pixels (default 48). */\n padding?: number\n minZoom?: number\n /** Fitting never zooms in past this (default 1: a small graph is not blown up). */\n maxZoom?: number\n}\n\n// One axis of a fit: centred when the content fits, from its start (the padding kept) when it\n// does not - a graph too large for the canvas at the smallest zoom shows where it begins.\nconst fitAxis = (start: number, length: number, room: number, zoom: number, padding: number) =>\n length * zoom <= room - padding * 2 + 0.5\n ? (room - length * zoom) / 2 - start * zoom\n : padding - start * zoom\n\n/**\n * The viewport that shows all of `rects` centred in a canvas of `size`. When they do not fit at\n * `minZoom`, it shows them from their top-left corner at that zoom instead.\n */\nexport const fitViewport = (rects: Rect[], size: Size, options: FitOptions = {}): Viewport => {\n const bounds = boundsOf(rects)\n if (!bounds || size.width <= 0 || size.height <= 0) return IDENTITY_VIEWPORT\n const { minZoom = DEFAULT_MIN_ZOOM, maxZoom = 1 } = options\n // A narrow canvas cannot afford the padding a wide one has.\n const padding = Math.min(options.padding ?? 48, size.width / 8, size.height / 8)\n const zoom = clamp(\n Math.min(\n (size.width - padding * 2) / Math.max(bounds.width, 1),\n (size.height - padding * 2) / Math.max(bounds.height, 1),\n ),\n minZoom,\n maxZoom,\n )\n return {\n zoom,\n x: fitAxis(bounds.x, bounds.width, size.width, zoom, padding),\n y: fitAxis(bounds.y, bounds.height, size.height, zoom, padding),\n }\n}\n\n/** The viewport with `rect` in the middle of a canvas of `size`, at the zoom given. */\nexport const centerOn = (rect: Rect, size: Size, zoom: number): Viewport => ({\n zoom,\n x: size.width / 2 - (rect.x + rect.width / 2) * zoom,\n y: size.height / 2 - (rect.y + rect.height / 2) * zoom,\n})\n\n/** Is any part of `rect` (world) inside a canvas of `size` under `viewport`? */\nexport const isRectVisible = (rect: Rect, size: Size, viewport: Viewport): boolean => {\n const a = worldToScreen(rect, viewport)\n const b = worldToScreen({ x: rect.x + rect.width, y: rect.y + rect.height }, viewport)\n return b.x > 0 && b.y > 0 && a.x < size.width && a.y < size.height\n}\n\nexport const snapTo = (value: number, grid: number): number =>\n // `+ 0`: a rounded-away negative is 0, not -0.\n grid > 0 ? Math.round(value / grid) * grid + 0 : value\n\nexport const snapPoint = (point: Point, grid: number): Point => ({\n x: snapTo(point.x, grid),\n y: snapTo(point.y, grid),\n})\n\nexport const rectContains = (rect: Rect, point: Point): boolean =>\n point.x >= rect.x &&\n point.x <= rect.x + rect.width &&\n point.y >= rect.y &&\n point.y <= rect.y + rect.height\n\n/** The id of the node under `point` (world). Later nodes are drawn on top, so they win. */\nexport const hitNode = <T extends Rect & { id: string }>(\n nodes: T[],\n point: Point,\n): string | undefined => {\n for (let i = nodes.length - 1; i >= 0; i--) {\n if (rectContains(nodes[i], point)) return nodes[i].id\n }\n return undefined\n}\n\n/** Where an edge enters a node: the middle of its left side. */\nexport const inputAnchor = (rect: Rect): Point => ({ x: rect.x, y: rect.y + rect.height / 2 })\n\n/** Where an edge leaves a node that has `count` output ports: spread down its right side. */\nexport const outputAnchor = (rect: Rect, index = 0, count = 1): Point => ({\n x: rect.x + rect.width,\n y: rect.y + (rect.height * (index + 1)) / (Math.max(count, 1) + 1),\n})\n\nexport interface EdgeCurveOptions {\n /**\n * How far an edge that runs backwards (its target is to the left of its source) swings below\n * the two nodes so that it does not cross them (default 90).\n */\n clearance?: number\n}\n\n/**\n * The curve of an edge that leaves `from` to the right and enters `to` from the left. A forward\n * edge is a plain S; a backward one (a loop) swings out and around.\n */\nexport const edgeCurve = (from: Point, to: Point, options: EdgeCurveOptions = {}): Curve => {\n const dx = to.x - from.x\n const dy = to.y - from.y\n if (dx >= 40) {\n const reach = Math.max(dx / 2, 40)\n return {\n p0: from,\n p1: { x: from.x + reach, y: from.y },\n p2: { x: to.x - reach, y: to.y },\n p3: to,\n }\n }\n const reach = clamp(60 + Math.abs(dx) / 4, 60, 220)\n const clearance = options.clearance ?? 90\n // Nearly level: go around below. Otherwise the height difference already keeps it clear.\n const swing = Math.abs(dy) < clearance ? clearance + Math.abs(dy) / 2 : 0\n return {\n p0: from,\n p1: { x: from.x + reach, y: from.y + swing },\n p2: { x: to.x - reach, y: to.y + swing },\n p3: to,\n }\n}\n\nconst round = (n: number): number => Math.round(n * 100) / 100\n\n/** The SVG path data of a curve. */\nexport const curvePath = ({ p0, p1, p2, p3 }: Curve): string =>\n `M ${round(p0.x)} ${round(p0.y)} C ${round(p1.x)} ${round(p1.y)}, ${round(p2.x)} ${round(p2.y)}, ${round(p3.x)} ${round(p3.y)}`\n\n/** The point of a curve at `t` in 0..1. */\nexport const curvePoint = ({ p0, p1, p2, p3 }: Curve, t: number): Point => {\n const u = 1 - t\n const a = u * u * u\n const b = 3 * u * u * t\n const c = 3 * u * t * t\n const d = t * t * t\n return {\n x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,\n y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,\n }\n}\n\nconst distanceToSegment = (p: Point, a: Point, b: Point): number => {\n const dx = b.x - a.x\n const dy = b.y - a.y\n const length = dx * dx + dy * dy\n const t = length === 0 ? 0 : clamp(((p.x - a.x) * dx + (p.y - a.y) * dy) / length, 0, 1)\n return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy))\n}\n\n/** How far `point` is from a curve (the curve is walked in `samples` straight pieces). */\nexport const distanceToCurve = (curve: Curve, point: Point, samples = 24): number => {\n let best = Infinity\n let previous = curve.p0\n for (let i = 1; i <= samples; i++) {\n const next = curvePoint(curve, i / samples)\n best = Math.min(best, distanceToSegment(point, previous, next))\n previous = next\n }\n return best\n}\n\n/** The id of the edge within `tolerance` of `point`, the nearest one when several are. */\nexport const hitEdge = (\n edges: { id: string; curve: Curve }[],\n point: Point,\n tolerance = 8,\n): string | undefined => {\n let best: string | undefined\n let bestDistance = Infinity\n for (const edge of edges) {\n const distance = distanceToCurve(edge.curve, point)\n if (distance <= tolerance && distance < bestDistance) {\n best = edge.id\n bestDistance = distance\n }\n }\n return best\n}\n\n/**\n * The order a keyboard walks the nodes in: left to right, then top to bottom - the direction a\n * graph that flows from its entry to its end is read in. Nodes in the same column (within\n * `column` pixels) count as level.\n */\nexport const readingOrder = <T extends Point & { id: string }>(nodes: T[], column = 40): string[] =>\n nodes\n .map((node, index) => ({ node, index }))\n .sort((a, b) => {\n const ax = Math.round(a.node.x / column)\n const bx = Math.round(b.node.x / column)\n return ax - bx || a.node.y - b.node.y || a.index - b.index\n })\n .map(({ node }) => node.id)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwBO,IAAM,sBAAoC;AAAA,EAC/C,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM,CAAC,MAAM,IAAI,gBACf,mBAAmB,IAAI,OAAO,EAAE,GAAG,cAAc,KAAK,WAAW,KAAK,EAAE;AAAA,EAC1E,MAAM,CAAC,MAAM,SAAS,WAAW,IAAI,GAAG,OAAO,KAAK,IAAI,MAAM,EAAE;AAAA,EAChE,YAAY,CAAC,UAAU,gBAAgB,KAAK;AAAA,EAC5C,cAAc,CAAC,UAAU,kBAAkB,KAAK;AAAA,EAChD,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,KAAK;AAAA,EACL,WAAW,CAAC,YAAY,GAAG,OAAO;AAAA,EAClC,aAAa,CAAC,SAAS,4BAA4B,IAAI;AAAA,EACvD,QAAQ;AAAA,EACR,WAAW,CAAC,MAAM,OAAO,aAAa,IAAI,OAAO,EAAE;AACrD;;;ACPO,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AACzB,IAAM,oBAA8B,EAAE,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE;AAE1D,IAAM,QAAQ,CAAC,OAAe,KAAa,QAChD,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK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