@hansenexus/hud 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +603 -9
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
  5. package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
  6. package/dist/access-panel-CEfTr9ZI.js +123 -0
  7. package/dist/adapter-BYoxPYTI.d.ts +33 -0
  8. package/dist/adapter-hcwmJtNx.js +65 -0
  9. package/dist/auto/runtime.d.ts +65 -0
  10. package/dist/auto/runtime.js +50 -0
  11. package/dist/auto.d.ts +15 -0
  12. package/dist/auto.js +33 -0
  13. package/dist/capabilities-rDSKjXpq.js +110 -0
  14. package/dist/capture-CwrIwLqi.js +300 -0
  15. package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
  16. package/dist/cli.d.ts +1 -0
  17. package/dist/cli.js +275 -0
  18. package/dist/data-panel-DhxAmP91.js +817 -0
  19. package/dist/data-store-ChF1td_P.js +164 -0
  20. package/dist/define-hud-CHPedaQ5.d.ts +50 -0
  21. package/dist/design-D0kGgPoP.js +87 -0
  22. package/dist/detect-BxHZ0pxW.d.ts +25 -0
  23. package/dist/detect-CHZiSeZs.js +63 -0
  24. package/dist/dispatch-panel-B-xr_Giy.js +279 -0
  25. package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
  26. package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
  27. package/dist/file-xdSaQ2uR.js +103 -0
  28. package/dist/flags-DVtaJ8pQ.d.ts +58 -0
  29. package/dist/flags.d.ts +2 -0
  30. package/dist/flags.js +82 -0
  31. package/dist/force-state-panel-_otVYh9i.js +97 -0
  32. package/dist/generate-C8lQl3Eh.js +53 -0
  33. package/dist/handler-BpVhxEmU.js +106 -0
  34. package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
  35. package/dist/index-BAV_1W8a.d.ts +43 -0
  36. package/dist/index-BJ26pse9.d.ts +70 -0
  37. package/dist/index-BnQ0dTZf.d.ts +19 -0
  38. package/dist/index-CwfX-W87.d.ts +72 -0
  39. package/dist/index-DcH9V3cU.d.ts +48 -0
  40. package/dist/index-DqOyNf1u.d.ts +65 -0
  41. package/dist/index-DstI_ike.d.ts +66 -0
  42. package/dist/index-Dxz4fn4j.d.ts +42 -0
  43. package/dist/index-Hhh7OXzU.d.ts +129 -0
  44. package/dist/index-ReFbhQ9p.d.ts +25 -0
  45. package/dist/index-RgXfMBuW.d.ts +48 -0
  46. package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.js +710 -69
  49. package/dist/inspect-C9Ft8fqn.js +142 -0
  50. package/dist/inspect-root-BkaupBMp.js +429 -0
  51. package/dist/meta-Bv0sEao3.js +6 -0
  52. package/dist/meta-C_G7MB5w.d.ts +49 -0
  53. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  54. package/dist/mocks-ESiRqk9o.js +150 -0
  55. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  56. package/dist/next/config.d.ts +52 -0
  57. package/dist/next/config.js +78 -0
  58. package/dist/next.d.ts +14 -4
  59. package/dist/next.js +5 -3
  60. package/dist/observe-CdDnDBRP.js +89 -0
  61. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  62. package/dist/ops-panel-CEqDe_UT.js +234 -0
  63. package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
  64. package/dist/plugins/a11y.d.ts +2 -0
  65. package/dist/plugins/a11y.js +2 -0
  66. package/dist/plugins/access/server.d.ts +5 -5
  67. package/dist/plugins/access/server.js +4 -3
  68. package/dist/plugins/access.d.ts +5 -5
  69. package/dist/plugins/access.js +16 -215
  70. package/dist/plugins/agent/server.d.ts +3 -38
  71. package/dist/plugins/agent/server.js +47 -21
  72. package/dist/plugins/agent.d.ts +4 -4
  73. package/dist/plugins/agent.js +6 -348
  74. package/dist/plugins/capture/server.d.ts +92 -0
  75. package/dist/plugins/capture/server.js +248 -0
  76. package/dist/plugins/capture.d.ts +24 -0
  77. package/dist/plugins/capture.js +70 -0
  78. package/dist/plugins/data/msw-browser.d.ts +2 -0
  79. package/dist/plugins/data/msw-browser.js +39 -0
  80. package/dist/plugins/data/msw-node.d.ts +36 -0
  81. package/dist/plugins/data/msw-node.js +68 -0
  82. package/dist/plugins/data/server.d.ts +257 -0
  83. package/dist/plugins/data/server.js +717 -0
  84. package/dist/plugins/data.d.ts +6 -0
  85. package/dist/plugins/data.js +51 -0
  86. package/dist/plugins/design/server.d.ts +54 -0
  87. package/dist/plugins/design/server.js +198 -0
  88. package/dist/plugins/design.d.ts +4 -124
  89. package/dist/plugins/design.js +4 -619
  90. package/dist/plugins/inspect/convex.d.ts +2 -0
  91. package/dist/plugins/inspect/convex.js +486 -0
  92. package/dist/plugins/inspect/react-query.d.ts +2 -0
  93. package/dist/plugins/inspect/react-query.js +225 -0
  94. package/dist/plugins/inspect/sockets.d.ts +51 -0
  95. package/dist/plugins/inspect/sockets.js +397 -0
  96. package/dist/plugins/inspect/swr.d.ts +2 -0
  97. package/dist/plugins/inspect/swr.js +218 -0
  98. package/dist/plugins/inspect.d.ts +4 -0
  99. package/dist/plugins/inspect.js +3 -0
  100. package/dist/plugins/observe.d.ts +4 -64
  101. package/dist/plugins/observe.js +1 -616
  102. package/dist/plugins/ops/server.d.ts +1 -1
  103. package/dist/plugins/ops/server.js +2 -1
  104. package/dist/plugins/ops.d.ts +2 -1
  105. package/dist/plugins/ops.js +15 -336
  106. package/dist/plugins/routes/server.d.ts +88 -0
  107. package/dist/plugins/routes/server.js +62 -0
  108. package/dist/plugins/routes.d.ts +3 -0
  109. package/dist/plugins/routes.js +216 -0
  110. package/dist/plugins/seo.d.ts +2 -0
  111. package/dist/plugins/seo.js +2 -0
  112. package/dist/plugins/vitals.d.ts +2 -25
  113. package/dist/plugins/vitals.js +3 -2
  114. package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
  115. package/dist/poll-CjKsWZi8.js +89 -0
  116. package/dist/requests-BwD6MKEq.js +282 -0
  117. package/dist/requests-CJrUf465.d.ts +50 -0
  118. package/dist/review.js +2 -2
  119. package/dist/same-origin-BGet22CC.js +21 -0
  120. package/dist/scan-DzJNXqOk.js +165 -0
  121. package/dist/seo-Dq9q_QkO.js +551 -0
  122. package/dist/seo-panel-CfiY-TnT.js +124 -0
  123. package/dist/server.d.ts +2 -2
  124. package/dist/server.js +2 -105
  125. package/dist/sessions-panel-COvhPAzv.js +98 -0
  126. package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
  127. package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
  128. package/dist/store/convex.d.ts +33 -0
  129. package/dist/store/convex.js +52 -0
  130. package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
  131. package/dist/store-Ync9eb1G.js +67 -0
  132. package/dist/store.d.ts +76 -0
  133. package/dist/store.js +188 -0
  134. package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
  135. package/dist/styles-DKU_P8MH.js +139 -0
  136. package/dist/styles-DPpDPmzi.js +68 -0
  137. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  138. package/dist/types-B-ulf2Jp.js +8 -0
  139. package/dist/types-BIgGf-0C.d.ts +25 -0
  140. package/dist/types-BIkI-qN8.js +30 -0
  141. package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
  142. package/dist/types-DIdPfjtV.js +6 -0
  143. package/dist/types-DaJcsEjO.d.ts +44 -0
  144. package/dist/types-Dn68psVz.d.ts +118 -0
  145. package/dist/types-szkr2QOF.d.ts +39 -0
  146. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  147. package/dist/variant-groups-TIfO3NIj.js +137 -0
  148. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  149. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  150. package/dist/variants-types-CcRf119M.d.ts +63 -0
  151. package/dist/variants.d.ts +43 -0
  152. package/dist/variants.js +83 -0
  153. package/dist/vitals-panel-BCmMUntW.js +30 -0
  154. package/dist/vite.d.ts +37 -0
  155. package/dist/vite.js +134 -0
  156. package/package.json +65 -5
  157. package/dist/define-hud-BBzsSl8b.d.ts +0 -36
@@ -1,64 +1,7 @@
1
- import { i as parseShortcut, l as useGrab, n as isApplePlatform, s as matchComponentHints, t as formatShortcut } from "../shortcut-U6ftVY06.js";
2
- import { i as definePlugin, n as HudApiError } from "../plugins-DVy_vaYr.js";
3
- import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- //#region src/plugins/agent/styles.ts
6
- /**
7
- * The agent panels' styles. Each panel renders them in a `<style>` inside the
8
- * HUD's shadow root, so the plugin brings its CSS without touching core's.
9
- */
10
- const AGENT_CSS = `
11
- .agent { display: grid; gap: 10px; }
12
- .agent-row { display: flex; align-items: center; gap: 8px; }
13
- .agent-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
14
- .agent-muted { color: var(--hud-fg-muted); }
15
- .agent-mono { font-family: var(--hud-mono); font-size: 11px; }
16
- .hud .agent-btn {
17
- padding: 3px 10px;
18
- border: 1px solid var(--hud-border);
19
- border-radius: 6px;
20
- background: var(--hud-bg-subtle);
21
- }
22
- .hud .agent-btn[data-primary] { background: var(--hud-accent); color: var(--hud-accent-fg); border-color: transparent; }
23
- .hud .agent-btn:disabled { opacity: 0.5; cursor: not-allowed; }
24
- .agent-card {
25
- display: grid;
26
- gap: 2px;
27
- padding: 6px 8px;
28
- border: 1px solid var(--hud-border);
29
- border-radius: 6px;
30
- background: var(--hud-bg-subtle);
31
- }
32
- .agent textarea {
33
- font: inherit;
34
- color: inherit;
35
- background: var(--hud-bg);
36
- border: 1px solid var(--hud-border);
37
- border-radius: 6px;
38
- padding: 6px 8px;
39
- min-height: 56px;
40
- resize: vertical;
41
- }
42
- .agent fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; }
43
- .agent label.agent-target { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }
44
- .agent label.agent-target[data-disabled] { opacity: 0.55; cursor: not-allowed; }
45
- .agent-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
46
- .agent-badge {
47
- flex: none;
48
- padding: 0 6px;
49
- border-radius: 999px;
50
- border: 1px solid currentColor;
51
- font-size: 10px;
52
- line-height: 16px;
53
- color: var(--hud-fg-muted);
54
- }
55
- .agent-badge[data-status="running"], .agent-badge[data-status="dispatched"] { color: var(--hud-good); }
56
- .agent-badge[data-status="sending"], .agent-badge[data-status="queued"] { color: var(--hud-warn); }
57
- .agent-badge[data-status="failed"] { color: var(--hud-poor); }
58
- .agent details pre { max-height: 160px; overflow: auto; margin: 4px 0 0; font-size: 10px; }
59
- `;
60
- //#endregion
61
- //#region src/plugins/agent/dispatch-panel.tsx
1
+ import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
+ import { lazy } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/plugins/agent/run-log.ts
62
5
  /**
63
6
  * Runs dispatched from this page. It outlives the panel (closing it unmounts
64
7
  * the component), so it lives with the plugin instance.
@@ -83,295 +26,10 @@ function createRunLog() {
83
26
  } : run))
84
27
  };
85
28
  }
86
- function errorText(error) {
87
- if (error instanceof HudApiError) return error.body?.error ?? `HTTP ${error.status}`;
88
- return error instanceof Error ? error.message : String(error);
89
- }
90
- function DispatchPanel({ ctx, log, componentHints }) {
91
- const { grabbing, payload } = useGrab(ctx.grab);
92
- const runs = useSyncExternalStore(log.subscribe, log.get, log.get);
93
- const [targets, setTargets] = useState(null);
94
- const [targetsError, setTargetsError] = useState(null);
95
- const [target, setTarget] = useState(null);
96
- const [note, setNote] = useState("");
97
- useEffect(() => {
98
- let cancelled = false;
99
- ctx.api("/targets").then((list) => {
100
- if (cancelled) return;
101
- setTargets(list);
102
- setTarget((current) => current ?? list.find((t) => t.available)?.id ?? null);
103
- }).catch((error) => {
104
- if (!cancelled) setTargetsError(errorText(error));
105
- });
106
- return () => {
107
- cancelled = true;
108
- };
109
- }, [ctx]);
110
- const hints = payload ? matchComponentHints(componentHints, payload.route, payload.anchor.label) : [];
111
- const canSend = target !== null && (payload !== null || note.trim() !== "");
112
- async function send() {
113
- if (!target || !canSend) return;
114
- const id = `${Date.now()}`;
115
- const title = [payload?.anchor.label, note.trim().split("\n")[0]].filter(Boolean).join(" · ");
116
- const body = {
117
- target,
118
- note,
119
- payload,
120
- hints
121
- };
122
- log.add({
123
- id,
124
- title: title || "dispatch",
125
- target,
126
- status: "sending"
127
- });
128
- ctx.grab.clear();
129
- setNote("");
130
- try {
131
- const receipt = await ctx.api("/dispatch", {
132
- method: "POST",
133
- headers: { "content-type": "application/json" },
134
- body: JSON.stringify(body)
135
- });
136
- log.update(id, {
137
- status: "dispatched",
138
- detail: [receipt.runId, receipt.detail].filter(Boolean).join(" · ")
139
- });
140
- } catch (error) {
141
- log.update(id, {
142
- status: "failed",
143
- detail: errorText(error)
144
- });
145
- }
146
- }
147
- return /* @__PURE__ */ jsxs("div", {
148
- className: "agent",
149
- children: [
150
- /* @__PURE__ */ jsx("style", { children: AGENT_CSS }),
151
- payload ? /* @__PURE__ */ jsxs("div", {
152
- className: "agent-card",
153
- children: [
154
- /* @__PURE__ */ jsxs("div", {
155
- className: "agent-row",
156
- children: [/* @__PURE__ */ jsxs("strong", {
157
- className: "agent-grow",
158
- title: payload.anchor.label,
159
- children: [payload.component ? `<${payload.component.name}> ` : "", payload.anchor.label]
160
- }), /* @__PURE__ */ jsx("button", {
161
- type: "button",
162
- className: "agent-btn",
163
- "aria-label": "Discard grab",
164
- onClick: ctx.grab.clear,
165
- children: "✕"
166
- })]
167
- }),
168
- payload.component?.source && /* @__PURE__ */ jsx("span", {
169
- className: "agent-mono agent-muted",
170
- children: payload.component.source
171
- }),
172
- /* @__PURE__ */ jsxs("span", {
173
- className: "agent-mono agent-muted agent-grow",
174
- title: payload.anchor.selector,
175
- children: [
176
- payload.route,
177
- " · ",
178
- payload.anchor.selector || payload.anchor.tag
179
- ]
180
- }),
181
- /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", {
182
- className: "agent-muted",
183
- children: "Payload"
184
- }), /* @__PURE__ */ jsx("pre", {
185
- className: "agent-mono",
186
- children: JSON.stringify({
187
- ...payload,
188
- hints
189
- }, null, 2)
190
- })] })
191
- ]
192
- }) : /* @__PURE__ */ jsxs("div", {
193
- className: "agent-row",
194
- children: [/* @__PURE__ */ jsx("button", {
195
- type: "button",
196
- className: "agent-btn",
197
- "data-primary": "",
198
- "aria-pressed": grabbing,
199
- onClick: grabbing ? ctx.grab.cancel : ctx.grab.start,
200
- children: grabbing ? "Cancel grab" : "⌖ Grab element"
201
- }), /* @__PURE__ */ jsxs("span", {
202
- className: "agent-muted",
203
- children: [
204
- "or ",
205
- formatShortcut(parseShortcut("mod+shift+g"), isApplePlatform()),
206
- ", then click anything on the page"
207
- ]
208
- })]
209
- }),
210
- /* @__PURE__ */ jsx("textarea", {
211
- "aria-label": "Instruction",
212
- placeholder: "Instruction, e.g. the CTA feels heavy, try the ghost variant",
213
- value: note,
214
- onChange: (e) => setNote(e.target.value)
215
- }),
216
- targetsError && /* @__PURE__ */ jsxs("p", {
217
- className: "empty",
218
- children: ["Targets unavailable: ", targetsError]
219
- }),
220
- targets && targets.length === 0 && /* @__PURE__ */ jsx("p", {
221
- className: "empty",
222
- children: "No dispatch provider configured on the server."
223
- }),
224
- targets && targets.length > 0 && /* @__PURE__ */ jsx("fieldset", { children: targets.map((t) => /* @__PURE__ */ jsxs("label", {
225
- className: "agent-target",
226
- ...t.available ? {} : { "data-disabled": "" },
227
- children: [/* @__PURE__ */ jsx("input", {
228
- type: "radio",
229
- name: "agent-target",
230
- checked: target === t.id,
231
- disabled: !t.available,
232
- onChange: () => setTarget(t.id)
233
- }), /* @__PURE__ */ jsxs("span", { children: [
234
- /* @__PURE__ */ jsx("span", { children: t.label }),
235
- /* @__PURE__ */ jsx("br", {}),
236
- /* @__PURE__ */ jsx("span", {
237
- className: "agent-muted",
238
- children: t.available ? t.description ?? t.id : t.reason
239
- })
240
- ] })]
241
- }, t.id)) }),
242
- /* @__PURE__ */ jsx("div", {
243
- className: "agent-row",
244
- children: /* @__PURE__ */ jsx("button", {
245
- type: "button",
246
- className: "agent-btn",
247
- "data-primary": "",
248
- disabled: !canSend,
249
- onClick: send,
250
- children: "Dispatch"
251
- })
252
- }),
253
- runs.length > 0 && /* @__PURE__ */ jsx("ul", {
254
- className: "agent-list",
255
- "aria-label": "Dispatched runs",
256
- children: runs.map((run) => /* @__PURE__ */ jsxs("li", {
257
- className: "agent-row agent-mono",
258
- children: [
259
- /* @__PURE__ */ jsx("span", {
260
- className: "agent-badge",
261
- "data-status": run.status,
262
- children: run.status
263
- }),
264
- /* @__PURE__ */ jsx("span", {
265
- className: "agent-grow",
266
- title: run.title,
267
- children: run.title
268
- }),
269
- /* @__PURE__ */ jsxs("span", {
270
- className: "agent-muted agent-grow",
271
- title: run.detail,
272
- children: [run.target, run.detail ? ` · ${run.detail}` : ""]
273
- })
274
- ]
275
- }, run.id))
276
- })
277
- ]
278
- });
279
- }
280
- //#endregion
281
- //#region src/plugins/agent/sessions-panel.tsx
282
- function age(iso) {
283
- if (!iso) return "";
284
- const seconds = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1e3));
285
- if (seconds < 60) return `${seconds}s`;
286
- if (seconds < 3600) return `${Math.round(seconds / 60)}m`;
287
- if (seconds < 86400) return `${Math.round(seconds / 3600)}h`;
288
- return `${Math.round(seconds / 86400)}d`;
289
- }
290
- function SessionRow({ session }) {
291
- return /* @__PURE__ */ jsxs("li", {
292
- className: "agent-row agent-mono",
293
- title: session.detail ?? session.id,
294
- children: [
295
- /* @__PURE__ */ jsx("span", {
296
- className: "agent-badge",
297
- "data-status": session.status,
298
- children: session.status
299
- }),
300
- /* @__PURE__ */ jsx("span", {
301
- className: "agent-grow",
302
- children: session.title
303
- }),
304
- /* @__PURE__ */ jsxs("span", {
305
- className: "agent-muted",
306
- children: [
307
- session.provider,
308
- " ",
309
- age(session.updatedAt ?? session.startedAt)
310
- ]
311
- })
312
- ]
313
- });
314
- }
315
- function SessionsPanel({ ctx, intervalMs }) {
316
- const [data, setData] = useState(null);
317
- const [error, setError] = useState(null);
318
- const load = useCallback(async () => {
319
- try {
320
- setData(await ctx.api("/sessions"));
321
- setError(null);
322
- } catch (e) {
323
- setError(e instanceof HudApiError ? `HTTP ${e.status}` : String(e));
324
- }
325
- }, [ctx]);
326
- useEffect(() => {
327
- load();
328
- const timer = setInterval(() => {
329
- if (!document.hidden) load();
330
- }, intervalMs);
331
- return () => clearInterval(timer);
332
- }, [load, intervalMs]);
333
- return /* @__PURE__ */ jsxs("div", {
334
- className: "agent",
335
- children: [
336
- /* @__PURE__ */ jsx("style", { children: AGENT_CSS }),
337
- /* @__PURE__ */ jsxs("div", {
338
- className: "agent-row",
339
- children: [/* @__PURE__ */ jsx("span", {
340
- className: "agent-grow agent-muted",
341
- children: data ? `${data.sessions.length} sessions` : "Loading…"
342
- }), /* @__PURE__ */ jsx("button", {
343
- type: "button",
344
- className: "agent-btn",
345
- onClick: () => void load(),
346
- children: "Refresh"
347
- })]
348
- }),
349
- error && /* @__PURE__ */ jsxs("p", {
350
- className: "empty",
351
- children: ["Sessions unavailable: ", error]
352
- }),
353
- data?.errors.map((e) => /* @__PURE__ */ jsxs("p", {
354
- className: "empty",
355
- children: [
356
- e.provider,
357
- ": ",
358
- e.error
359
- ]
360
- }, e.provider)),
361
- data && data.sessions.length === 0 && /* @__PURE__ */ jsx("p", {
362
- className: "empty",
363
- children: "No sessions."
364
- }),
365
- data && data.sessions.length > 0 && /* @__PURE__ */ jsx("ul", {
366
- className: "agent-list",
367
- "aria-label": "Agent sessions",
368
- children: data.sessions.map((session) => /* @__PURE__ */ jsx(SessionRow, { session }, `${session.provider}:${session.id}`))
369
- })
370
- ]
371
- });
372
- }
373
29
  //#endregion
374
30
  //#region src/plugins/agent/index.tsx
31
+ const DispatchPanel = lazy(() => import("../dispatch-panel-B-xr_Giy.js"));
32
+ const SessionsPanel = lazy(() => import("../sessions-panel-COvhPAzv.js"));
375
33
  /**
376
34
  * Dispatch panel: the last grab plus an instruction, sent to one of the
377
35
  * server's providers (`hermes()`, `claudeCode()`). Mount the server half from
@@ -0,0 +1,92 @@
1
+ import { n as ScreenshotRequest, r as ScreenshotResponse, t as CAPTURE_CAPABILITY } from "../../types-BIgGf-0C.js";
2
+ //#region src/plugins/capture/server.d.ts
3
+ /**
4
+ * The slice of Playwright the route uses, declared structurally so the
5
+ * package's types never depend on `playwright` being installed. A real
6
+ * `Browser` satisfies it; tests pass a fake.
7
+ */
8
+ export interface ScreenshotBrowser {
9
+ newContext(options: {
10
+ viewport: {
11
+ width: number;
12
+ height: number;
13
+ };
14
+ deviceScaleFactor: number;
15
+ }): Promise<ScreenshotContext>;
16
+ close(): Promise<unknown>;
17
+ }
18
+ export interface ScreenshotContext {
19
+ addCookies(cookies: {
20
+ name: string;
21
+ value: string;
22
+ url: string;
23
+ }[]): Promise<unknown>;
24
+ newPage(): Promise<ScreenshotPage>;
25
+ }
26
+ export interface ScreenshotPage {
27
+ goto(url: string, options: {
28
+ waitUntil: "load" | "networkidle";
29
+ timeout: number;
30
+ }): Promise<unknown>;
31
+ addStyleTag(options: {
32
+ content: string;
33
+ }): Promise<unknown>;
34
+ locator(selector: string): ScreenshotLocator;
35
+ screenshot(options: {
36
+ type: "png";
37
+ timeout: number;
38
+ }): Promise<Uint8Array>;
39
+ }
40
+ export interface ScreenshotLocator {
41
+ first(): ScreenshotLocator;
42
+ screenshot(options: {
43
+ type: "png";
44
+ timeout: number;
45
+ }): Promise<Uint8Array>;
46
+ }
47
+ export interface ScreenshotServerOptions {
48
+ /**
49
+ * Starts the browser for one screenshot. Default: `chromium.launch()` from
50
+ * `playwright`, loaded on first use; without the package, or without its
51
+ * Chromium, the route answers 503 with a setup hint.
52
+ */
53
+ launch?: () => Promise<ScreenshotBrowser>;
54
+ /** Page load budget. Default 15 s. */
55
+ loadTimeoutMs?: number;
56
+ /** How long to wait for the grabbed element before falling back to the viewport. Default 5 s. */
57
+ elementTimeoutMs?: number;
58
+ }
59
+ export declare const INSTALL_HINT = "bun add -d playwright && bunx playwright install chromium";
60
+ export declare const BROWSER_HINT = "bunx playwright install chromium";
61
+ /** A screenshot cannot be taken on this server; the hint says what to install. */
62
+ export declare class ScreenshotUnavailable extends Error {
63
+ readonly hint: string;
64
+ constructor(message: string, hint: string);
65
+ }
66
+ /** Same-origin only, http(s) only. */
67
+ export declare function sameOriginUrl(url: string, request: Request): URL | null;
68
+ /** Width and height from a PNG's IHDR chunk; 0×0 when the bytes are not a PNG. */
69
+ export declare function pngSize(png: Uint8Array): {
70
+ width: number;
71
+ height: number;
72
+ };
73
+ /**
74
+ * Server half of the `capture` plugin: `POST /screenshot` renders a
75
+ * same-origin URL in headless Chromium at the grab's viewport, with the
76
+ * request's cookies, crops to the grabbed selector (the viewport when the
77
+ * element is not there) and answers the PNG base64 encoded. Non-same-origin
78
+ * URLs answer 400; a server without Playwright answers 503 with a setup hint,
79
+ * which the Dispatch panel shows while the dispatch itself goes on without
80
+ * an image.
81
+ */
82
+ export declare function screenshot({ launch, loadTimeoutMs, elementTimeoutMs }?: ScreenshotServerOptions): {
83
+ readonly id: "capture";
84
+ readonly capability: "capture.screenshot";
85
+ readonly routes: {
86
+ readonly "/screenshot": {
87
+ readonly POST: (request: Request) => Promise<Response>;
88
+ };
89
+ };
90
+ };
91
+ //#endregion
92
+ export { CAPTURE_CAPABILITY, type ScreenshotRequest, type ScreenshotResponse };
@@ -0,0 +1,248 @@
1
+ import { n as HUD_HOST_TAG } from "../../marker-uZYPOJ4M.js";
2
+ import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
3
+ import { n as CAPTURE_ID, t as CAPTURE_CAPABILITY } from "../../types-DIdPfjtV.js";
4
+ //#region src/plugins/capture/server.ts
5
+ const INSTALL_HINT = "bun add -d playwright && bunx playwright install chromium";
6
+ const BROWSER_HINT = "bunx playwright install chromium";
7
+ /** A screenshot cannot be taken on this server; the hint says what to install. */
8
+ var ScreenshotUnavailable = class extends Error {
9
+ hint;
10
+ constructor(message, hint) {
11
+ super(message);
12
+ this.hint = hint;
13
+ this.name = "ScreenshotUnavailable";
14
+ }
15
+ };
16
+ const MAX_SIDE = 4096;
17
+ const MIN_SIDE = 320;
18
+ const DEFAULT_VIEWPORT = {
19
+ width: 1280,
20
+ height: 800
21
+ };
22
+ function message(error) {
23
+ return error instanceof Error ? error.message : String(error);
24
+ }
25
+ function isMissingModule(error) {
26
+ const code = error?.code;
27
+ if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") return true;
28
+ return /cannot find (module|package)|failed to (resolve|fetch)|not found/i.test(message(error));
29
+ }
30
+ /**
31
+ * `import("playwright")` on first use. A static specifier keeps the import
32
+ * analysable (Next externalises `playwright` on the server by default); the
33
+ * playground aliases it to a stub, as a browser cannot run it anyway.
34
+ */
35
+ async function launchChromium() {
36
+ let playwright;
37
+ try {
38
+ playwright = await import("playwright");
39
+ } catch (error) {
40
+ if (isMissingModule(error)) throw new ScreenshotUnavailable("Playwright is not installed", INSTALL_HINT);
41
+ throw error;
42
+ }
43
+ try {
44
+ return await playwright.chromium.launch();
45
+ } catch (error) {
46
+ throw new ScreenshotUnavailable(`Chromium failed to launch: ${message(error)}`, BROWSER_HINT);
47
+ }
48
+ }
49
+ function isRecord(value) {
50
+ return typeof value === "object" && value !== null && !Array.isArray(value);
51
+ }
52
+ function clampSide(value, fallback) {
53
+ if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
54
+ return Math.min(MAX_SIDE, Math.max(MIN_SIDE, Math.round(value)));
55
+ }
56
+ function parseBody(value) {
57
+ if (!isRecord(value) || typeof value.url !== "string") return null;
58
+ if (value.selector !== void 0 && typeof value.selector !== "string") return null;
59
+ const viewport = isRecord(value.viewport) ? value.viewport : {};
60
+ return {
61
+ url: value.url,
62
+ ...value.selector ? { selector: value.selector } : {},
63
+ viewport: {
64
+ width: clampSide(viewport.width, DEFAULT_VIEWPORT.width),
65
+ height: clampSide(viewport.height, DEFAULT_VIEWPORT.height)
66
+ }
67
+ };
68
+ }
69
+ /**
70
+ * The origins a screenshot may render: the one the request was made to and,
71
+ * when the browser sent it, the page's own `Origin`. Anything else is not
72
+ * this app, and a dev server must not become a headless browser for the web.
73
+ */
74
+ function allowedOrigins(request) {
75
+ const origins = /* @__PURE__ */ new Set();
76
+ try {
77
+ origins.add(new URL(request.url).origin);
78
+ } catch {}
79
+ const origin = request.headers.get("origin");
80
+ if (origin && origin !== "null") origins.add(origin);
81
+ return origins;
82
+ }
83
+ /** Same-origin only, http(s) only. */
84
+ function sameOriginUrl(url, request) {
85
+ let target;
86
+ try {
87
+ target = new URL(url);
88
+ } catch {
89
+ return null;
90
+ }
91
+ if (target.protocol !== "http:" && target.protocol !== "https:") return null;
92
+ return allowedOrigins(request).has(target.origin) ? target : null;
93
+ }
94
+ /** Width and height from a PNG's IHDR chunk; 0×0 when the bytes are not a PNG. */
95
+ function pngSize(png) {
96
+ if (png.length < 24 || [
97
+ 137,
98
+ 80,
99
+ 78,
100
+ 71,
101
+ 13,
102
+ 10,
103
+ 26,
104
+ 10
105
+ ].some((byte, i) => png[i] !== byte)) return {
106
+ width: 0,
107
+ height: 0
108
+ };
109
+ const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
110
+ return {
111
+ width: view.getUint32(16),
112
+ height: view.getUint32(20)
113
+ };
114
+ }
115
+ function toBase64(bytes) {
116
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
117
+ let binary = "";
118
+ for (const byte of bytes) binary += String.fromCharCode(byte);
119
+ return btoa(binary);
120
+ }
121
+ /** The developer's cookies for the page, so the headless render sees the same session. */
122
+ function cookiesFor(request, url) {
123
+ const header = request.headers.get("cookie");
124
+ if (!header) return [];
125
+ const cookies = [];
126
+ for (const pair of header.split(";")) {
127
+ const eq = pair.indexOf("=");
128
+ if (eq <= 0) continue;
129
+ const name = pair.slice(0, eq).trim();
130
+ if (name) cookies.push({
131
+ name,
132
+ value: pair.slice(eq + 1).trim(),
133
+ url: url.origin
134
+ });
135
+ }
136
+ return cookies;
137
+ }
138
+ /**
139
+ * A screenshot renders a page with the developer's cookies, so a page on
140
+ * another origin must not be able to trigger one through the browser. A JSON
141
+ * content type forces a CORS preflight that this route never answers, and
142
+ * `Sec-Fetch-Site` rejects cross-site requests outright where the browser
143
+ * sends it.
144
+ */
145
+ function refuseCrossSite(request) {
146
+ const site = request.headers.get("sec-fetch-site");
147
+ if (site && site !== "same-origin" && site !== "none") return Response.json({
148
+ ok: false,
149
+ error: "cross-site request refused"
150
+ }, { status: 403 });
151
+ if (!request.headers.get("content-type")?.toLowerCase().startsWith("application/json")) return Response.json({
152
+ ok: false,
153
+ error: "expected application/json"
154
+ }, { status: 415 });
155
+ return null;
156
+ }
157
+ const NO_STORE = { "cache-control": "no-store" };
158
+ function fail(status, error, hint) {
159
+ const body = {
160
+ ok: false,
161
+ error,
162
+ ...hint ? { hint } : {}
163
+ };
164
+ return Response.json(body, {
165
+ status,
166
+ headers: NO_STORE
167
+ });
168
+ }
169
+ /**
170
+ * Server half of the `capture` plugin: `POST /screenshot` renders a
171
+ * same-origin URL in headless Chromium at the grab's viewport, with the
172
+ * request's cookies, crops to the grabbed selector (the viewport when the
173
+ * element is not there) and answers the PNG base64 encoded. Non-same-origin
174
+ * URLs answer 400; a server without Playwright answers 503 with a setup hint,
175
+ * which the Dispatch panel shows while the dispatch itself goes on without
176
+ * an image.
177
+ */
178
+ function screenshot({ launch = launchChromium, loadTimeoutMs = 15e3, elementTimeoutMs = 5e3 } = {}) {
179
+ async function render(request, { url, selector, viewport = DEFAULT_VIEWPORT }) {
180
+ const browser = await launch();
181
+ try {
182
+ const context = await browser.newContext({
183
+ viewport,
184
+ deviceScaleFactor: 1
185
+ });
186
+ const target = new URL(url);
187
+ const cookies = cookiesFor(request, target);
188
+ if (cookies.length > 0) await context.addCookies(cookies);
189
+ const page = await context.newPage();
190
+ try {
191
+ await page.goto(target.href, {
192
+ waitUntil: "networkidle",
193
+ timeout: loadTimeoutMs
194
+ });
195
+ } catch (error) {
196
+ if (!/timeout/i.test(message(error))) throw error;
197
+ }
198
+ await page.addStyleTag({ content: `${HUD_HOST_TAG}{display:none!important}` });
199
+ let png;
200
+ let scope = "viewport";
201
+ if (selector) try {
202
+ png = await page.locator(selector).first().screenshot({
203
+ type: "png",
204
+ timeout: elementTimeoutMs
205
+ });
206
+ scope = "element";
207
+ } catch {
208
+ png = void 0;
209
+ }
210
+ png ??= await page.screenshot({
211
+ type: "png",
212
+ timeout: elementTimeoutMs
213
+ });
214
+ const { width, height } = pngSize(png);
215
+ const body = {
216
+ ok: true,
217
+ mime: "image/png",
218
+ base64: toBase64(png),
219
+ width,
220
+ height,
221
+ scope
222
+ };
223
+ return Response.json(body, { headers: NO_STORE });
224
+ } finally {
225
+ await browser.close().catch(() => {});
226
+ }
227
+ }
228
+ return definePlugin({
229
+ id: CAPTURE_ID,
230
+ capability: CAPTURE_CAPABILITY,
231
+ routes: { "/screenshot": { POST: async (request) => {
232
+ const refusal = refuseCrossSite(request);
233
+ if (refusal) return refusal;
234
+ const body = parseBody(await request.json().catch(() => null));
235
+ if (!body) return fail(400, "invalid screenshot request");
236
+ if (!sameOriginUrl(body.url, request)) return fail(400, "url must be same-origin");
237
+ try {
238
+ return await render(request, body);
239
+ } catch (error) {
240
+ if (error instanceof ScreenshotUnavailable) return fail(503, error.message, error.hint);
241
+ console.error("hud capture: screenshot failed", error);
242
+ return fail(502, `screenshot failed: ${message(error)}`);
243
+ }
244
+ } } }
245
+ });
246
+ }
247
+ //#endregion
248
+ export { BROWSER_HINT, CAPTURE_CAPABILITY, INSTALL_HINT, ScreenshotUnavailable, pngSize, sameOriginUrl, screenshot };