@hansenexus/hud 0.3.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 (172) hide show
  1. package/README.md +782 -6
  2. package/dist/a11y-B5DUaiCs.js +246 -0
  3. package/dist/a11y-panel-p_t4eD7p.js +207 -0
  4. package/dist/access-C7zlaqj6.js +100 -0
  5. package/dist/access-D_ewAEJG.d.ts +61 -0
  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-CApnbI0r.d.ts +19 -0
  26. package/dist/env-CaiFPIhF.js +31 -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-BaqWsmrf.js +153 -0
  32. package/dist/force-state-CCqoTfVB.d.ts +23 -0
  33. package/dist/force-state-panel-_otVYh9i.js +97 -0
  34. package/dist/generate-C8lQl3Eh.js +53 -0
  35. package/dist/handler-BpVhxEmU.js +106 -0
  36. package/dist/handler-DtYVCZY6.d.ts +39 -0
  37. package/dist/index-BAV_1W8a.d.ts +43 -0
  38. package/dist/index-BJ26pse9.d.ts +70 -0
  39. package/dist/index-BnQ0dTZf.d.ts +19 -0
  40. package/dist/index-CwfX-W87.d.ts +72 -0
  41. package/dist/index-DcH9V3cU.d.ts +48 -0
  42. package/dist/index-DqOyNf1u.d.ts +65 -0
  43. package/dist/index-DstI_ike.d.ts +66 -0
  44. package/dist/index-Dxz4fn4j.d.ts +42 -0
  45. package/dist/index-Hhh7OXzU.d.ts +129 -0
  46. package/dist/index-ReFbhQ9p.d.ts +25 -0
  47. package/dist/index-RgXfMBuW.d.ts +48 -0
  48. package/dist/index-gCZBO53s.d.ts +73 -0
  49. package/dist/index.d.ts +6 -36
  50. package/dist/index.js +798 -240
  51. package/dist/inspect-C9Ft8fqn.js +142 -0
  52. package/dist/inspect-root-BkaupBMp.js +429 -0
  53. package/dist/marker-C66LxOhJ.d.ts +9 -0
  54. package/dist/marker-CMrvxPmS.d.ts +12 -0
  55. package/dist/marker-DjeGvL-F.js +9 -0
  56. package/dist/marker-uZYPOJ4M.js +12 -0
  57. package/dist/markers.d.ts +3 -0
  58. package/dist/markers.js +3 -0
  59. package/dist/meta-Bv0sEao3.js +6 -0
  60. package/dist/meta-C_G7MB5w.d.ts +49 -0
  61. package/dist/mocks-CA-wM2SB.d.ts +109 -0
  62. package/dist/mocks-ESiRqk9o.js +150 -0
  63. package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
  64. package/dist/next/config.d.ts +52 -0
  65. package/dist/next/config.js +78 -0
  66. package/dist/next.d.ts +14 -19
  67. package/dist/next.js +7 -30
  68. package/dist/observe-CdDnDBRP.js +89 -0
  69. package/dist/observe-panel-Cgp1M8oT.js +347 -0
  70. package/dist/ops-panel-CEqDe_UT.js +234 -0
  71. package/dist/payload-MUQ9ciER.d.ts +92 -0
  72. package/dist/plugins/a11y.d.ts +2 -0
  73. package/dist/plugins/a11y.js +2 -0
  74. package/dist/plugins/access/server.d.ts +122 -0
  75. package/dist/plugins/access/server.js +340 -0
  76. package/dist/plugins/access.d.ts +41 -0
  77. package/dist/plugins/access.js +51 -0
  78. package/dist/plugins/agent/server.d.ts +94 -0
  79. package/dist/plugins/agent/server.js +455 -0
  80. package/dist/plugins/agent.d.ts +37 -0
  81. package/dist/plugins/agent.js +69 -0
  82. package/dist/plugins/capture/server.d.ts +92 -0
  83. package/dist/plugins/capture/server.js +248 -0
  84. package/dist/plugins/capture.d.ts +24 -0
  85. package/dist/plugins/capture.js +70 -0
  86. package/dist/plugins/data/msw-browser.d.ts +2 -0
  87. package/dist/plugins/data/msw-browser.js +39 -0
  88. package/dist/plugins/data/msw-node.d.ts +36 -0
  89. package/dist/plugins/data/msw-node.js +68 -0
  90. package/dist/plugins/data/server.d.ts +257 -0
  91. package/dist/plugins/data/server.js +717 -0
  92. package/dist/plugins/data.d.ts +6 -0
  93. package/dist/plugins/data.js +51 -0
  94. package/dist/plugins/design/server.d.ts +54 -0
  95. package/dist/plugins/design/server.js +198 -0
  96. package/dist/plugins/design.d.ts +5 -0
  97. package/dist/plugins/design.js +4 -0
  98. package/dist/plugins/inspect/convex.d.ts +2 -0
  99. package/dist/plugins/inspect/convex.js +486 -0
  100. package/dist/plugins/inspect/react-query.d.ts +2 -0
  101. package/dist/plugins/inspect/react-query.js +225 -0
  102. package/dist/plugins/inspect/sockets.d.ts +51 -0
  103. package/dist/plugins/inspect/sockets.js +397 -0
  104. package/dist/plugins/inspect/swr.d.ts +2 -0
  105. package/dist/plugins/inspect/swr.js +218 -0
  106. package/dist/plugins/inspect.d.ts +4 -0
  107. package/dist/plugins/inspect.js +3 -0
  108. package/dist/plugins/observe.d.ts +4 -0
  109. package/dist/plugins/observe.js +2 -0
  110. package/dist/plugins/ops/server.d.ts +82 -0
  111. package/dist/plugins/ops/server.js +381 -0
  112. package/dist/plugins/ops.d.ts +27 -0
  113. package/dist/plugins/ops.js +41 -0
  114. package/dist/plugins/routes/server.d.ts +88 -0
  115. package/dist/plugins/routes/server.js +62 -0
  116. package/dist/plugins/routes.d.ts +3 -0
  117. package/dist/plugins/routes.js +216 -0
  118. package/dist/plugins/seo.d.ts +2 -0
  119. package/dist/plugins/seo.js +2 -0
  120. package/dist/plugins/vitals.d.ts +2 -25
  121. package/dist/plugins/vitals.js +4 -86
  122. package/dist/plugins-BZvDqGx5.d.ts +144 -0
  123. package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
  124. package/dist/poll-CjKsWZi8.js +89 -0
  125. package/dist/requests-BwD6MKEq.js +282 -0
  126. package/dist/requests-CJrUf465.d.ts +50 -0
  127. package/dist/review.d.ts +181 -0
  128. package/dist/review.js +1017 -0
  129. package/dist/same-origin-BGet22CC.js +21 -0
  130. package/dist/scan-DzJNXqOk.js +165 -0
  131. package/dist/selector-NSYSe7AZ.js +28 -0
  132. package/dist/seo-Dq9q_QkO.js +551 -0
  133. package/dist/seo-panel-CfiY-TnT.js +124 -0
  134. package/dist/server.d.ts +3 -39
  135. package/dist/server.js +2 -105
  136. package/dist/sessions-panel-COvhPAzv.js +98 -0
  137. package/dist/shortcut-s_mjGeU8.js +179 -0
  138. package/dist/state-CjjZPjPJ.js +40 -0
  139. package/dist/state-boundary.d.ts +26 -0
  140. package/dist/state-boundary.js +61 -0
  141. package/dist/store/convex.d.ts +33 -0
  142. package/dist/store/convex.js +52 -0
  143. package/dist/store-CQqIIKTc.js +59 -0
  144. package/dist/store-Ync9eb1G.js +67 -0
  145. package/dist/store.d.ts +76 -0
  146. package/dist/store.js +188 -0
  147. package/dist/styles-BA8ueHoV.js +342 -0
  148. package/dist/styles-DKU_P8MH.js +139 -0
  149. package/dist/styles-DPpDPmzi.js +68 -0
  150. package/dist/tokens-panel-CbMQfasZ.js +142 -0
  151. package/dist/types-B-ulf2Jp.js +8 -0
  152. package/dist/types-BIgGf-0C.d.ts +25 -0
  153. package/dist/types-BIkI-qN8.js +30 -0
  154. package/dist/types-Cxh4twqc.d.ts +50 -0
  155. package/dist/types-DIdPfjtV.js +6 -0
  156. package/dist/types-DaJcsEjO.d.ts +44 -0
  157. package/dist/types-Dn68psVz.d.ts +118 -0
  158. package/dist/types-f3jlNxzw.d.ts +92 -0
  159. package/dist/types-szkr2QOF.d.ts +39 -0
  160. package/dist/unlock-store-4V3vR4Eg.js +96 -0
  161. package/dist/variant-groups-TIfO3NIj.js +137 -0
  162. package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
  163. package/dist/variants-panel-BDoSkwBJ.js +457 -0
  164. package/dist/variants-types-CcRf119M.d.ts +63 -0
  165. package/dist/variants.d.ts +43 -0
  166. package/dist/variants.js +83 -0
  167. package/dist/vitals-panel-BCmMUntW.js +30 -0
  168. package/dist/vite.d.ts +37 -0
  169. package/dist/vite.js +134 -0
  170. package/package.json +85 -5
  171. package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
  172. package/dist/plugins-1QmTmZyL.d.ts +0 -76
@@ -0,0 +1,381 @@
1
+ import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
+ import { a as OPS_CAPABILITY, n as combineStates } from "../../state-CjjZPjPJ.js";
3
+ import { t as TELEMETRY_RANGES } from "../../types-B-ulf2Jp.js";
4
+ //#region src/plugins/ops/errors.ts
5
+ /**
6
+ * A provider failure whose message is safe to send to the client (it names
7
+ * the upstream and its status, never a URL with credentials or a token).
8
+ * The routes answer 502 with it; any other error becomes a generic 502.
9
+ */
10
+ var OpsProviderError = class extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "OpsProviderError";
14
+ }
15
+ };
16
+ /** Upstream calls give up after this, so a dead host never hangs a panel. */
17
+ const UPSTREAM_TIMEOUT_MS = 5e3;
18
+ //#endregion
19
+ //#region src/plugins/ops/env.ts
20
+ /** Reads a server env var. Absent `process` (MSW in a browser) reads as unset. */
21
+ function readEnv(name) {
22
+ if (typeof process === "undefined") return void 0;
23
+ const value = process.env[name];
24
+ return value === "" ? void 0 : value;
25
+ }
26
+ /** `process.cwd()`, or undefined where there is none. */
27
+ function currentDir() {
28
+ const proc = globalThis.process;
29
+ return typeof proc?.cwd === "function" ? proc.cwd() : void 0;
30
+ }
31
+ //#endregion
32
+ //#region src/plugins/ops/git-head.ts
33
+ /**
34
+ * Branch named by a `HEAD` file: `ref: refs/heads/feat/x` → `feat/x`.
35
+ * A detached HEAD (a bare sha) names no branch.
36
+ */
37
+ function parseHead(head) {
38
+ return /^ref:\s*refs\/heads\/(.+)$/.exec(head.trim())?.[1] ?? null;
39
+ }
40
+ /** Git dir a worktree's `.git` file points at: `gitdir: /repo/.git/worktrees/x`. */
41
+ function parseGitFile(content) {
42
+ return /^gitdir:\s*(.+)$/m.exec(content)?.[1]?.trim() ?? null;
43
+ }
44
+ function parents(dir) {
45
+ const parts = dir.replace(/[\\/]+$/, "").split(/[\\/]/);
46
+ const dirs = [];
47
+ for (let i = parts.length; i > 0; i--) dirs.push(parts.slice(0, i).join("/") || "/");
48
+ return dirs;
49
+ }
50
+ /**
51
+ * Branch of the git checkout containing `cwd` (default `process.cwd()`), read
52
+ * from `.git/HEAD` without spawning git. Walks up, so an app inside a monorepo
53
+ * finds the root's `.git`; follows a worktree's `.git` file. Null when there
54
+ * is no checkout, no filesystem (edge runtime, browser) or HEAD is detached.
55
+ */
56
+ async function readGitBranch(cwd = currentDir()) {
57
+ if (!cwd) return null;
58
+ let fs;
59
+ try {
60
+ fs = await import("node:fs/promises");
61
+ } catch {
62
+ return null;
63
+ }
64
+ for (const dir of parents(cwd)) {
65
+ const dotGit = `${dir === "/" ? "" : dir}/.git`;
66
+ try {
67
+ return parseHead(await fs.readFile(`${dotGit}/HEAD`, "utf8"));
68
+ } catch {}
69
+ try {
70
+ const gitDir = parseGitFile(await fs.readFile(dotGit, "utf8"));
71
+ if (gitDir) {
72
+ const absolute = /^([\\/]|[A-Za-z]:)/.test(gitDir) ? gitDir : `${dir}/${gitDir}`;
73
+ return parseHead(await fs.readFile(`${absolute}/HEAD`, "utf8"));
74
+ }
75
+ } catch {}
76
+ }
77
+ return null;
78
+ }
79
+ //#endregion
80
+ //#region src/plugins/ops/github-actions.ts
81
+ const BRANCH_ENV = [
82
+ "HUD_GIT_BRANCH",
83
+ "VERCEL_GIT_COMMIT_REF",
84
+ "GITHUB_HEAD_REF",
85
+ "GITHUB_REF_NAME"
86
+ ];
87
+ const REPO = /^[\w.-]+\/[\w.-]+$/;
88
+ /** GitHub's status + conclusion pair as one state. */
89
+ function githubRunState(status, conclusion) {
90
+ if (status === "in_progress") return "running";
91
+ if (status !== "completed") return "queued";
92
+ switch (conclusion) {
93
+ case "success": return "success";
94
+ case "failure":
95
+ case "timed_out":
96
+ case "startup_failure":
97
+ case "action_required": return "failure";
98
+ case "cancelled":
99
+ case "stale": return "cancelled";
100
+ default: return "neutral";
101
+ }
102
+ }
103
+ function toRun(run) {
104
+ const name = run.name ?? `workflow ${run.workflow_id}`;
105
+ const title = run.display_title ?? run.head_commit?.message.split("\n")[0] ?? name;
106
+ return {
107
+ id: String(run.id),
108
+ name,
109
+ title,
110
+ state: githubRunState(run.status, run.conclusion),
111
+ ...run.head_branch ? { branch: run.head_branch } : {},
112
+ sha: run.head_sha.slice(0, 7),
113
+ url: run.html_url,
114
+ startedAt: run.created_at
115
+ };
116
+ }
117
+ /**
118
+ * State of the newest commit among `runs` (newest first): the latest run of
119
+ * each workflow on that commit, combined.
120
+ */
121
+ function headState(runs) {
122
+ const head = runs[0]?.head_sha;
123
+ if (!head) return {
124
+ sha: null,
125
+ state: null
126
+ };
127
+ const latest = /* @__PURE__ */ new Map();
128
+ for (const run of runs) if (run.head_sha === head && !latest.has(run.workflow_id)) latest.set(run.workflow_id, run);
129
+ const states = [...latest.values()].map((run) => githubRunState(run.status, run.conclusion));
130
+ return {
131
+ sha: head.slice(0, 7),
132
+ state: combineStates(states)
133
+ };
134
+ }
135
+ /**
136
+ * GitHub Actions as the `ops` plugin's CI provider. Server only: the token is
137
+ * read from env on each request and only ever sent to GitHub.
138
+ *
139
+ * ```ts
140
+ * ops({ ci: githubActions({ repo: "hansenexus/hud" }) })
141
+ * ```
142
+ */
143
+ function githubActions(options) {
144
+ const { repo, tokenEnv = "GITHUB_TOKEN", limit = 10, cacheSeconds = 15 } = options;
145
+ if (!REPO.test(repo)) throw new Error(`hud ops: githubActions repo "${repo}" must be owner/name`);
146
+ const apiUrl = (options.apiUrl ?? "https://api.github.com").replace(/\/+$/, "");
147
+ const cache = /* @__PURE__ */ new Map();
148
+ async function resolveBranch() {
149
+ const { branch } = options;
150
+ if (typeof branch === "string") return branch;
151
+ if (typeof branch === "function") return await branch() ?? null;
152
+ for (const name of BRANCH_ENV) {
153
+ const value = readEnv(name);
154
+ if (value) return value;
155
+ }
156
+ return readGitBranch();
157
+ }
158
+ async function fetchRuns(token, branch) {
159
+ const params = new URLSearchParams({ per_page: String(Math.max(limit, 20)) });
160
+ if (branch) params.set("branch", branch);
161
+ let res;
162
+ try {
163
+ res = await fetch(`${apiUrl}/repos/${repo}/actions/runs?${params}`, {
164
+ headers: {
165
+ authorization: `Bearer ${token}`,
166
+ accept: "application/vnd.github+json",
167
+ "x-github-api-version": "2022-11-28"
168
+ },
169
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS)
170
+ });
171
+ } catch {
172
+ throw new OpsProviderError("GitHub unreachable");
173
+ }
174
+ if (!res.ok) throw new OpsProviderError(`GitHub answered ${res.status}`);
175
+ return (await res.json()).workflow_runs ?? [];
176
+ }
177
+ function cachedRuns(token, branch) {
178
+ const key = branch ?? "";
179
+ const hit = cache.get(key);
180
+ if (hit && Date.now() - hit.at < cacheSeconds * 1e3) return hit.value;
181
+ const value = fetchRuns(token, branch);
182
+ cache.set(key, {
183
+ at: Date.now(),
184
+ value
185
+ });
186
+ value.catch(() => cache.delete(key));
187
+ return value;
188
+ }
189
+ return {
190
+ name: "github-actions",
191
+ async snapshot() {
192
+ const branch = await resolveBranch();
193
+ const base = {
194
+ provider: "github-actions",
195
+ repo,
196
+ branch
197
+ };
198
+ const token = readEnv(tokenEnv);
199
+ if (!token) return {
200
+ ...base,
201
+ configured: false,
202
+ missing: tokenEnv,
203
+ state: null,
204
+ sha: null,
205
+ runs: []
206
+ };
207
+ const runs = await cachedRuns(token, branch);
208
+ const head = branch ? headState(runs) : {
209
+ sha: null,
210
+ state: null
211
+ };
212
+ return {
213
+ ...base,
214
+ configured: true,
215
+ ...head,
216
+ runs: runs.slice(0, limit).map(toRun)
217
+ };
218
+ }
219
+ };
220
+ }
221
+ //#endregion
222
+ //#region src/plugins/ops/signoz.ts
223
+ const SERVICE = /^[\w.-]{1,128}$/;
224
+ const RANGE_SECONDS = {
225
+ "1h": 3600,
226
+ "24h": 86400,
227
+ "7d": 604800
228
+ };
229
+ const RANGE_STEP = {
230
+ "1h": "5m",
231
+ "24h": "15m",
232
+ "7d": "1h"
233
+ };
234
+ /** PromQL for the three numbers, from SigNoz's span metrics. */
235
+ function signozQueries(service) {
236
+ const label = `service_name="${service}"`;
237
+ return {
238
+ errorRate: `sum(rate(signoz_calls_total{${label},status_code="STATUS_CODE_ERROR"}[5m]))`,
239
+ p95Ms: `histogram_quantile(0.95, sum(rate(signoz_latency_bucket{${label}}[5m])) by (le))`,
240
+ requestRate: `sum(rate(signoz_calls_total{${label}}[5m]))`
241
+ };
242
+ }
243
+ /** Latest sample of the first series; null when there is none or it is not a number. */
244
+ function latestValue(result) {
245
+ const values = result.data?.result?.[0]?.values;
246
+ const last = values?.[values.length - 1];
247
+ if (!last) return null;
248
+ const value = Number.parseFloat(last[1]);
249
+ return Number.isFinite(value) ? value : null;
250
+ }
251
+ /**
252
+ * SigNoz as the `ops` plugin's telemetry provider: error rate, p95 latency and
253
+ * request rate of one service over its PromQL `query_range` API. Server only:
254
+ * the URL and API key come from env on each request.
255
+ *
256
+ * ```ts
257
+ * ops({ telemetry: signoz({ service: "hansenexus" }) })
258
+ * ```
259
+ */
260
+ function signoz(options) {
261
+ const { service, urlEnv = "SIGNOZ_QUERY_URL", apiKeyEnv = "SIGNOZ_API_KEY" } = options;
262
+ if (!SERVICE.test(service)) throw new Error(`hud ops: signoz service "${service}" is not a valid name`);
263
+ const queries = signozQueries(service);
264
+ async function query(baseUrl, apiKey, promql, range) {
265
+ const end = Math.floor(Date.now() / 1e3);
266
+ const params = new URLSearchParams({
267
+ query: promql,
268
+ start: String(end - RANGE_SECONDS[range]),
269
+ end: String(end),
270
+ step: RANGE_STEP[range]
271
+ });
272
+ const res = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/v1/query_range?${params}`, {
273
+ headers: apiKey ? { "SIGNOZ-API-KEY": apiKey } : {},
274
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS)
275
+ });
276
+ if (!res.ok) throw new OpsProviderError(`SigNoz answered ${res.status}`);
277
+ return latestValue(await res.json());
278
+ }
279
+ return {
280
+ name: "signoz",
281
+ async snapshot(range) {
282
+ const base = {
283
+ provider: "signoz",
284
+ service,
285
+ range
286
+ };
287
+ const url = readEnv(urlEnv);
288
+ if (!url) return {
289
+ ...base,
290
+ configured: false,
291
+ missing: urlEnv,
292
+ errorRate: null,
293
+ p95Ms: null,
294
+ requestRate: null
295
+ };
296
+ const apiKey = readEnv(apiKeyEnv);
297
+ const [errorRate, p95Ms, requestRate] = await Promise.allSettled([
298
+ query(url, apiKey, queries.errorRate, range),
299
+ query(url, apiKey, queries.p95Ms, range),
300
+ query(url, apiKey, queries.requestRate, range)
301
+ ]);
302
+ if (errorRate.status === "rejected" && p95Ms.status === "rejected" && requestRate.status === "rejected") throw errorRate.reason instanceof OpsProviderError ? errorRate.reason : new OpsProviderError("SigNoz unreachable");
303
+ const value = (r) => r.status === "fulfilled" ? r.value : null;
304
+ return {
305
+ ...base,
306
+ configured: true,
307
+ errorRate: value(errorRate),
308
+ p95Ms: value(p95Ms),
309
+ requestRate: value(requestRate)
310
+ };
311
+ }
312
+ };
313
+ }
314
+ //#endregion
315
+ //#region src/plugins/ops/server.ts
316
+ const NO_STORE = { "cache-control": "no-store" };
317
+ function failed(error, what) {
318
+ if (error instanceof OpsProviderError) return Response.json({
319
+ ok: false,
320
+ error: error.message
321
+ }, {
322
+ status: 502,
323
+ headers: NO_STORE
324
+ });
325
+ console.error(`hud ops: ${what} failed`, error);
326
+ return Response.json({
327
+ ok: false,
328
+ error: `${what} failed`
329
+ }, {
330
+ status: 502,
331
+ headers: NO_STORE
332
+ });
333
+ }
334
+ function isRange(value) {
335
+ return TELEMETRY_RANGES.includes(value);
336
+ }
337
+ /**
338
+ * Server half of the `ops` plugin. Pass it to `createHudHandler`; each
339
+ * provider adds its route, so an app without telemetry serves no
340
+ * `/telemetry`. Tokens and keys stay in the providers: responses carry
341
+ * run data, numbers and the name of a missing env var, never a secret.
342
+ */
343
+ function ops({ ci, telemetry } = {}) {
344
+ const routes = {};
345
+ if (ci) routes["/ci"] = { GET: async () => {
346
+ try {
347
+ const [snapshot, deployment] = await Promise.all([ci.snapshot(), ci.deployment?.()]);
348
+ const body = {
349
+ ok: true,
350
+ ...snapshot,
351
+ ...ci.deployment ? { deployment: deployment ?? null } : {}
352
+ };
353
+ return Response.json(body, { headers: NO_STORE });
354
+ } catch (error) {
355
+ return failed(error, ci.name);
356
+ }
357
+ } };
358
+ if (telemetry) routes["/telemetry"] = { GET: async (request) => {
359
+ const range = new URL(request.url).searchParams.get("range") ?? "1h";
360
+ if (!isRange(range)) return Response.json({
361
+ ok: false,
362
+ error: `range must be one of ${TELEMETRY_RANGES.join(", ")}`
363
+ }, { status: 400 });
364
+ try {
365
+ const body = {
366
+ ok: true,
367
+ ...await telemetry.snapshot(range)
368
+ };
369
+ return Response.json(body, { headers: NO_STORE });
370
+ } catch (error) {
371
+ return failed(error, telemetry.name);
372
+ }
373
+ } };
374
+ return definePlugin({
375
+ id: "ops",
376
+ capability: OPS_CAPABILITY,
377
+ routes
378
+ });
379
+ }
380
+ //#endregion
381
+ export { OpsProviderError, githubActions, ops, signoz };
@@ -0,0 +1,27 @@
1
+ import { c as HudPluginProps } from "../plugins-BZvDqGx5.js";
2
+ import { c as TelemetryRange, i as CiRun, l as TelemetryResponse, o as CiState, r as CiResponse, t as CiDeployment } from "../types-f3jlNxzw.js";
3
+ //#region src/plugins/ops/index.d.ts
4
+ declare function OpsPill({ ctx }: HudPluginProps): import("react").JSX.Element;
5
+ export interface OpsOptions {
6
+ /** Show the CI section and the CI state in the pill. Default true. */
7
+ ci?: boolean;
8
+ /** Show the telemetry section. Default true. */
9
+ telemetry?: boolean;
10
+ }
11
+ /**
12
+ * CI and telemetry: the pill shows the CI state of the branch the server runs
13
+ * on, the panel lists recent runs, the deployment (when the CI provider knows
14
+ * it) and error rate, p95 and request rate. Client half; the providers live in
15
+ * the server half, `@hansenexus/hud/plugins/ops/server`, which reads tokens
16
+ * from env and never sends them to the browser.
17
+ */
18
+ export declare function ops({ ci, telemetry }?: OpsOptions): {
19
+ readonly id: "ops";
20
+ readonly title: "Ops";
21
+ readonly capability: "cicd.read";
22
+ readonly panel: ({ ctx }: HudPluginProps) => import("react").JSX.Element;
23
+ readonly pill?: typeof OpsPill;
24
+ readonly pillPriority: 10;
25
+ };
26
+ //#endregion
27
+ export type { CiDeployment, CiResponse, CiRun, CiState, TelemetryRange, TelemetryResponse };
@@ -0,0 +1,41 @@
1
+ import { i as definePlugin } from "../plugins-DVy_vaYr.js";
2
+ import { a as OPS_CAPABILITY, i as stateRating, r as stateLabel, t as CI_POLL_MS } from "../state-CjjZPjPJ.js";
3
+ import { t as usePoll } from "../poll-CjKsWZi8.js";
4
+ import { lazy } from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ //#region src/plugins/ops/index.tsx
7
+ const Panel = lazy(() => import("../ops-panel-CEqDe_UT.js"));
8
+ function OpsPill({ ctx }) {
9
+ const { data, error } = usePoll(ctx, "/ci", CI_POLL_MS);
10
+ const label = !data && error ? "error" : !data ? "–" : !data.configured ? "off" : stateLabel(data.state);
11
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
12
+ className: "dot",
13
+ "data-rating": data ? stateRating(data.state) : void 0
14
+ }), `CI ${label}`] });
15
+ }
16
+ /**
17
+ * CI and telemetry: the pill shows the CI state of the branch the server runs
18
+ * on, the panel lists recent runs, the deployment (when the CI provider knows
19
+ * it) and error rate, p95 and request rate. Client half; the providers live in
20
+ * the server half, `@hansenexus/hud/plugins/ops/server`, which reads tokens
21
+ * from env and never sends them to the browser.
22
+ */
23
+ function ops({ ci = true, telemetry = true } = {}) {
24
+ function OpsPanel({ ctx }) {
25
+ return /* @__PURE__ */ jsx(Panel, {
26
+ ctx,
27
+ ci,
28
+ telemetry
29
+ });
30
+ }
31
+ return definePlugin({
32
+ id: "ops",
33
+ title: "Ops",
34
+ capability: OPS_CAPABILITY,
35
+ panel: OpsPanel,
36
+ ...ci ? { pill: OpsPill } : {},
37
+ pillPriority: 10
38
+ });
39
+ }
40
+ //#endregion
41
+ export { ops };
@@ -0,0 +1,88 @@
1
+ import { a as RouteUrl, i as RouteSegment, n as ROUTES_ID, o as RoutesResponse, r as RouteEntry, t as ROUTES_CAPABILITY } from "../../meta-C_G7MB5w.js";
2
+ //#region src/plugins/routes/scan.d.ts
3
+ /**
4
+ * Pure derivation over a Next `app/` tree: folder names to patterns, patterns
5
+ * to URLs. No clock, no randomness; the filesystem comes in through `ScanFs`,
6
+ * so the walk is testable without a disk.
7
+ */
8
+ /** What the walk needs from the filesystem. `readdir` rejects for a missing directory. */
9
+ interface ScanFs {
10
+ readdir(dir: string): Promise<{
11
+ name: string;
12
+ isDirectory(): boolean;
13
+ isFile(): boolean;
14
+ }[]>;
15
+ }
16
+ interface FixtureContext {
17
+ /** Param name the value is for. */
18
+ param: string;
19
+ /** Folder pattern of the route being resolved. */
20
+ pattern: string;
21
+ }
22
+ /**
23
+ * Value(s) for a dynamic segment: one string, several (one URL each), or a
24
+ * function returning either, called per route. A catch-all takes `a/b`
25
+ * for several segments. The empty string drops the segment, which is how an
26
+ * `as-needed` default locale or an optional catch-all resolves to the parent.
27
+ */
28
+ type FixtureValue = string | readonly string[] | ((ctx: FixtureContext) => string | readonly string[] | Promise<string | readonly string[]>);
29
+ /** Fixture values keyed by param name: `{ slug: ["hello", "welt"], locale: "" }`. */
30
+ type RouteFixtures = Record<string, FixtureValue>;
31
+ /**
32
+ * Every concrete URL of a pattern from its fixture values: one per
33
+ * combination, in fixture order. An optional catch-all without a fixture
34
+ * resolves to the parent path; any other segment without one leaves the
35
+ * route unresolved and `urls` empty.
36
+ */
37
+ export declare function buildUrls(pattern: string, values: Record<string, readonly string[]>): {
38
+ urls: RouteUrl[];
39
+ unresolved: string[];
40
+ };
41
+ interface PageFile {
42
+ /** Folder relative to the app dir; `` for the root page. */
43
+ rel: string;
44
+ /** `page.tsx`, `page.jsx`, ... */
45
+ file: string;
46
+ }
47
+ /** Page files under `dir`, sorted by folder. Skips private, parallel and intercepting folders. */
48
+ export declare function findPages(dir: string, fs: ScanFs): Promise<PageFile[]>;
49
+ interface ScanOptions {
50
+ fixtures?: RouteFixtures;
51
+ exclude?: readonly string[];
52
+ }
53
+ /** Every page under the app directory as a `RouteEntry`, sorted by pattern. */
54
+ export declare function scanRoutes(dir: string, fs: ScanFs, { fixtures, exclude }?: ScanOptions): Promise<RouteEntry[]>;
55
+ //#endregion
56
+ //#region src/plugins/routes/server.d.ts
57
+ export interface RoutesServerOptions {
58
+ /**
59
+ * The Next `app/` directory. Default: `app` or `src/app` under `process.cwd()`,
60
+ * the dev server's root.
61
+ */
62
+ dir?: string;
63
+ /**
64
+ * Values for dynamic segments, keyed by param name: a string, several
65
+ * strings (one URL each) or a function returning either, called per route.
66
+ * A segment without one leaves its route listed but unresolved.
67
+ */
68
+ fixtures?: RouteFixtures;
69
+ /** URL paths or folder patterns to drop: exact, or a trailing `*` prefix. */
70
+ exclude?: readonly string[];
71
+ }
72
+ /**
73
+ * Server half of the `routes` plugin: `GET <basePath>/routes/routes` walks
74
+ * the app directory on every request (development only, like every HUD
75
+ * route) and answers the page routes with their fixture-filled URLs. The
76
+ * `hud sweep` CLI reads the same route.
77
+ */
78
+ export declare function routes(options?: RoutesServerOptions): {
79
+ readonly id: "routes";
80
+ readonly capability: "routes.read";
81
+ readonly routes: {
82
+ "/routes": {
83
+ GET: () => Promise<Response>;
84
+ };
85
+ };
86
+ };
87
+ //#endregion
88
+ export { type FixtureContext, type FixtureValue, ROUTES_CAPABILITY, ROUTES_ID, type RouteEntry, type RouteFixtures, type RouteSegment, type RouteUrl, type RoutesResponse, type ScanFs };
@@ -0,0 +1,62 @@
1
+ import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
2
+ import { n as ROUTES_ID, t as ROUTES_CAPABILITY } from "../../meta-Bv0sEao3.js";
3
+ import { i as scanRoutes, n as findPages, t as buildUrls } from "../../scan-DzJNXqOk.js";
4
+ //#region src/plugins/routes/server.ts
5
+ const NO_STORE = { "cache-control": "no-store" };
6
+ const DEFAULT_DIRS = ["app", "src/app"];
7
+ function currentDir() {
8
+ const proc = globalThis.process;
9
+ return typeof proc?.cwd === "function" ? proc.cwd() : void 0;
10
+ }
11
+ async function nodeFs() {
12
+ try {
13
+ return await import("node:fs/promises");
14
+ } catch {
15
+ return;
16
+ }
17
+ }
18
+ async function findAppDir(fs, cwd) {
19
+ for (const candidate of DEFAULT_DIRS) try {
20
+ if ((await fs.stat(`${cwd}/${candidate}`)).isDirectory()) return candidate;
21
+ } catch {}
22
+ }
23
+ /**
24
+ * Server half of the `routes` plugin: `GET <basePath>/routes/routes` walks
25
+ * the app directory on every request (development only, like every HUD
26
+ * route) and answers the page routes with their fixture-filled URLs. The
27
+ * `hud sweep` CLI reads the same route.
28
+ */
29
+ function routes(options = {}) {
30
+ return definePlugin({
31
+ id: ROUTES_ID,
32
+ capability: ROUTES_CAPABILITY,
33
+ routes: { "/routes": { GET: async () => {
34
+ const fs = await nodeFs();
35
+ if (!fs) return Response.json({
36
+ ok: false,
37
+ error: "routes: no filesystem in this runtime"
38
+ }, {
39
+ status: 500,
40
+ headers: NO_STORE
41
+ });
42
+ const cwd = currentDir() ?? ".";
43
+ const dir = options.dir ?? await findAppDir(fs, cwd);
44
+ if (!dir) return Response.json({
45
+ ok: false,
46
+ error: `routes: no ${DEFAULT_DIRS.join(" or ")} under ${cwd}`
47
+ }, {
48
+ status: 500,
49
+ headers: NO_STORE
50
+ });
51
+ const absolute = /^([\\/]|[A-Za-z]:)/.test(dir) ? dir : `${cwd}/${dir}`;
52
+ const body = {
53
+ ok: true,
54
+ dir,
55
+ routes: await scanRoutes(absolute, { readdir: (path) => fs.readdir(path, { withFileTypes: true }) }, options)
56
+ };
57
+ return Response.json(body, { headers: NO_STORE });
58
+ } } }
59
+ });
60
+ }
61
+ //#endregion
62
+ export { ROUTES_CAPABILITY, ROUTES_ID, buildUrls, findPages, routes, scanRoutes };
@@ -0,0 +1,3 @@
1
+ import { a as RouteUrl, i as RouteSegment, n as ROUTES_ID, o as RoutesResponse, r as RouteEntry, t as ROUTES_CAPABILITY } from "../meta-C_G7MB5w.js";
2
+ import { t as routes } from "../index-BnQ0dTZf.js";
3
+ export { ROUTES_CAPABILITY, ROUTES_ID, type RouteEntry, type RouteSegment, type RouteUrl, type RoutesResponse, routes };