toiljs 0.0.116 → 0.0.118

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 (337) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +16 -7
  3. package/build/backend/.tsbuildinfo +1 -1
  4. package/build/cli/.tsbuildinfo +1 -1
  5. package/build/cli/index.js +2375 -258
  6. package/build/client/.tsbuildinfo +1 -1
  7. package/build/client/auth.d.ts +3 -0
  8. package/build/client/auth.js +19 -10
  9. package/build/client/dev/devtools.js +1 -1
  10. package/build/client/dev/error-overlay.js +1 -1
  11. package/build/client/index.d.ts +1 -1
  12. package/build/client/index.js +1 -1
  13. package/build/client/navigation/navigation.js +28 -3
  14. package/build/client/routing/Router.js +5 -2
  15. package/build/client/routing/mount.js +1 -1
  16. package/build/compiler/.tsbuildinfo +1 -1
  17. package/build/compiler/auth-emails.js +7 -3
  18. package/build/compiler/emails.js +1 -1
  19. package/build/compiler/index.d.ts +1 -0
  20. package/build/compiler/index.js +26 -5
  21. package/build/compiler/pages.js +2 -3
  22. package/build/compiler/prerender.d.ts +3 -8
  23. package/build/compiler/prerender.js +88 -127
  24. package/build/compiler/ssg.js +3 -4
  25. package/build/compiler/template-build.js +3 -4
  26. package/build/compiler/toil-docs.generated.js +8 -7
  27. package/build/compiler/vite.js +4 -6
  28. package/build/devserver/.tsbuildinfo +1 -1
  29. package/build/devserver/db/database.js +7 -3
  30. package/build/devserver/db/types.js +1 -1
  31. package/build/devserver/production.js +4 -3
  32. package/build/devserver/runtime/crypto.d.ts +1 -1
  33. package/build/io/.tsbuildinfo +1 -1
  34. package/build/logger/.tsbuildinfo +1 -1
  35. package/build/shared/.tsbuildinfo +1 -1
  36. package/examples/basic/client/routes/analytics.tsx +7 -5
  37. package/examples/basic/client/routes/pq.tsx +2 -1
  38. package/examples/basic/server/tsconfig.json +1 -3
  39. package/package.json +45 -44
  40. package/presets/no-uint8array-tostring.js +120 -153
  41. package/presets/oxlint.d.ts +5 -0
  42. package/presets/oxlint.js +224 -0
  43. package/server/auth/AuthController.ts +53 -14
  44. package/server/auth/FactorSettings.ts +41 -0
  45. package/server/auth/SessionEpochs.ts +58 -0
  46. package/server/auth/SessionRevocations.ts +13 -0
  47. package/server/globals/auth.ts +27 -2
  48. package/server/runtime/tsconfig.json +1 -3
  49. package/tsconfig.json +2 -11
  50. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  51. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  52. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  53. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  54. package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
  55. package/.github/changelog-config.json +0 -45
  56. package/.github/dependabot.yml +0 -27
  57. package/.github/workflows/ci.yml +0 -222
  58. package/.vscode/settings.json +0 -10
  59. package/docs/README.md +0 -107
  60. package/docs/auth/README.md +0 -104
  61. package/docs/auth/configuration.md +0 -105
  62. package/docs/auth/emails.md +0 -92
  63. package/docs/auth/extending.md +0 -202
  64. package/docs/auth/how-it-works.md +0 -138
  65. package/docs/auth/usage.md +0 -188
  66. package/docs/backend/README.md +0 -143
  67. package/docs/backend/data.md +0 -351
  68. package/docs/backend/rest.md +0 -402
  69. package/docs/backend/rpc.md +0 -226
  70. package/docs/background/README.md +0 -114
  71. package/docs/background/daemons.md +0 -276
  72. package/docs/background/derive.md +0 -179
  73. package/docs/cli/README.md +0 -379
  74. package/docs/concepts/ai-guide.md +0 -132
  75. package/docs/concepts/config.md +0 -416
  76. package/docs/concepts/decorators.md +0 -127
  77. package/docs/concepts/security.md +0 -108
  78. package/docs/concepts/tiers.md +0 -166
  79. package/docs/concepts/types.md +0 -216
  80. package/docs/database/README.md +0 -143
  81. package/docs/database/capacity.md +0 -350
  82. package/docs/database/counters.md +0 -174
  83. package/docs/database/documents.md +0 -277
  84. package/docs/database/events.md +0 -307
  85. package/docs/database/membership.md +0 -246
  86. package/docs/database/setup.md +0 -155
  87. package/docs/database/unique.md +0 -216
  88. package/docs/database/views.md +0 -246
  89. package/docs/frontend/README.md +0 -104
  90. package/docs/frontend/components.md +0 -286
  91. package/docs/frontend/data-fetching.md +0 -260
  92. package/docs/frontend/images.md +0 -148
  93. package/docs/frontend/metadata.md +0 -344
  94. package/docs/frontend/navigation.md +0 -296
  95. package/docs/frontend/rendering.md +0 -236
  96. package/docs/frontend/routing.md +0 -346
  97. package/docs/frontend/scripts.md +0 -118
  98. package/docs/frontend/search.md +0 -191
  99. package/docs/frontend/styling.md +0 -147
  100. package/docs/frontend/toil-global.md +0 -216
  101. package/docs/getting-started/README.md +0 -81
  102. package/docs/getting-started/create-project.md +0 -131
  103. package/docs/getting-started/deploy.md +0 -101
  104. package/docs/getting-started/first-app.md +0 -215
  105. package/docs/getting-started/installation.md +0 -124
  106. package/docs/getting-started/migrating.md +0 -125
  107. package/docs/getting-started/project-structure.md +0 -163
  108. package/docs/introduction/README.md +0 -66
  109. package/docs/introduction/design-principles.md +0 -81
  110. package/docs/introduction/distributed.md +0 -91
  111. package/docs/introduction/how-it-works.md +0 -121
  112. package/docs/introduction/hyperscale.md +0 -70
  113. package/docs/introduction/modern-stack.md +0 -85
  114. package/docs/introduction/vs-other-frameworks.md +0 -64
  115. package/docs/introduction/why-toil.md +0 -99
  116. package/docs/llms.txt +0 -95
  117. package/docs/realtime/README.md +0 -102
  118. package/docs/realtime/channels.md +0 -211
  119. package/docs/realtime/streams.md +0 -369
  120. package/docs/services/README.md +0 -60
  121. package/docs/services/analytics.md +0 -279
  122. package/docs/services/caching.md +0 -175
  123. package/docs/services/cookies.md +0 -235
  124. package/docs/services/crypto.md +0 -209
  125. package/docs/services/email.md +0 -289
  126. package/docs/services/environment.md +0 -141
  127. package/docs/services/ratelimit.md +0 -174
  128. package/docs/services/time.md +0 -85
  129. package/eslint.config.js +0 -57
  130. package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
  131. package/presets/eslint.js +0 -88
  132. package/src/backend/index.ts +0 -204
  133. package/src/cli/configure.ts +0 -363
  134. package/src/cli/create.ts +0 -924
  135. package/src/cli/db.ts +0 -158
  136. package/src/cli/diagnostics.ts +0 -665
  137. package/src/cli/doctor.ts +0 -982
  138. package/src/cli/features.ts +0 -170
  139. package/src/cli/index.ts +0 -326
  140. package/src/cli/notify.ts +0 -120
  141. package/src/cli/proc.ts +0 -56
  142. package/src/cli/ui.ts +0 -169
  143. package/src/cli/update.ts +0 -248
  144. package/src/cli/updates.ts +0 -92
  145. package/src/cli/validate.ts +0 -31
  146. package/src/cli/version-check.ts +0 -125
  147. package/src/client/auth.ts +0 -869
  148. package/src/client/channel/channel.ts +0 -146
  149. package/src/client/components/Form.tsx +0 -65
  150. package/src/client/components/Image.tsx +0 -160
  151. package/src/client/components/Script.tsx +0 -113
  152. package/src/client/components/Slot.tsx +0 -21
  153. package/src/client/dev/devtools.tsx +0 -1089
  154. package/src/client/dev/error-overlay.tsx +0 -225
  155. package/src/client/errors.ts +0 -11
  156. package/src/client/head/head.ts +0 -182
  157. package/src/client/head/metadata.ts +0 -110
  158. package/src/client/index.ts +0 -130
  159. package/src/client/navigation/Link.tsx +0 -108
  160. package/src/client/navigation/NavLink.tsx +0 -86
  161. package/src/client/navigation/navigation.ts +0 -235
  162. package/src/client/navigation/prefetch.ts +0 -169
  163. package/src/client/navigation/scroll.ts +0 -53
  164. package/src/client/routing/Router.tsx +0 -216
  165. package/src/client/routing/action.ts +0 -122
  166. package/src/client/routing/error-boundary.tsx +0 -43
  167. package/src/client/routing/hooks.ts +0 -140
  168. package/src/client/routing/lazy.ts +0 -77
  169. package/src/client/routing/loader.ts +0 -381
  170. package/src/client/routing/match.ts +0 -47
  171. package/src/client/routing/mount.tsx +0 -90
  172. package/src/client/routing/params-context.ts +0 -10
  173. package/src/client/routing/slot-context.ts +0 -7
  174. package/src/client/rpc.ts +0 -97
  175. package/src/client/search/search.ts +0 -189
  176. package/src/client/search/use-page-search.ts +0 -73
  177. package/src/client/ssr/markers.tsx +0 -172
  178. package/src/client/stream/client.ts +0 -237
  179. package/src/client/types.ts +0 -73
  180. package/src/compiler/auth-emails.ts +0 -312
  181. package/src/compiler/config.ts +0 -369
  182. package/src/compiler/docs.ts +0 -127
  183. package/src/compiler/email-preview.ts +0 -314
  184. package/src/compiler/emails.ts +0 -404
  185. package/src/compiler/fonts.ts +0 -89
  186. package/src/compiler/generate.ts +0 -471
  187. package/src/compiler/image-blur.ts +0 -42
  188. package/src/compiler/image-report.ts +0 -88
  189. package/src/compiler/index.ts +0 -1362
  190. package/src/compiler/pages.ts +0 -49
  191. package/src/compiler/plugin.ts +0 -391
  192. package/src/compiler/prerender.ts +0 -263
  193. package/src/compiler/routes.ts +0 -170
  194. package/src/compiler/seo.ts +0 -415
  195. package/src/compiler/sri.ts +0 -144
  196. package/src/compiler/ssg.ts +0 -177
  197. package/src/compiler/ssr-codegen.ts +0 -85
  198. package/src/compiler/template-build.ts +0 -676
  199. package/src/compiler/template.ts +0 -262
  200. package/src/compiler/toil-docs.generated.ts +0 -77
  201. package/src/compiler/vite.ts +0 -245
  202. package/src/devserver/analytics/index.ts +0 -317
  203. package/src/devserver/config/dotenv.ts +0 -102
  204. package/src/devserver/config/env.ts +0 -30
  205. package/src/devserver/config/ratelimit.ts +0 -123
  206. package/src/devserver/daemon/catalog.ts +0 -120
  207. package/src/devserver/daemon/cron.ts +0 -87
  208. package/src/devserver/daemon/host.ts +0 -134
  209. package/src/devserver/daemon/index.ts +0 -369
  210. package/src/devserver/daemon/runtime.ts +0 -48
  211. package/src/devserver/db/catalog.ts +0 -109
  212. package/src/devserver/db/database.ts +0 -1834
  213. package/src/devserver/db/derives.ts +0 -121
  214. package/src/devserver/db/index.ts +0 -20
  215. package/src/devserver/db/routeKinds.ts +0 -191
  216. package/src/devserver/db/types.ts +0 -168
  217. package/src/devserver/email/caps.ts +0 -0
  218. package/src/devserver/email/config.ts +0 -141
  219. package/src/devserver/email/console.ts +0 -348
  220. package/src/devserver/email/index.ts +0 -155
  221. package/src/devserver/email/providers.ts +0 -131
  222. package/src/devserver/email/status.ts +0 -23
  223. package/src/devserver/email/validate.ts +0 -37
  224. package/src/devserver/email/wire.ts +0 -55
  225. package/src/devserver/http/cache.ts +0 -0
  226. package/src/devserver/http/envelope.ts +0 -157
  227. package/src/devserver/http/proxy.ts +0 -172
  228. package/src/devserver/http/runtime.ts +0 -387
  229. package/src/devserver/index.ts +0 -43
  230. package/src/devserver/production-ipc.ts +0 -63
  231. package/src/devserver/production-worker.ts +0 -83
  232. package/src/devserver/production.ts +0 -718
  233. package/src/devserver/runtime/crypto.ts +0 -587
  234. package/src/devserver/runtime/host.ts +0 -427
  235. package/src/devserver/runtime/module.ts +0 -442
  236. package/src/devserver/server.ts +0 -251
  237. package/src/devserver/ssr.ts +0 -208
  238. package/src/devserver/stream/catalog.ts +0 -106
  239. package/src/devserver/stream/host.ts +0 -42
  240. package/src/devserver/stream/index.ts +0 -301
  241. package/src/devserver/stream/manager.ts +0 -167
  242. package/src/devserver/stream/router.ts +0 -101
  243. package/src/devserver/stream/wire.ts +0 -58
  244. package/src/devserver/stream/ws.ts +0 -78
  245. package/src/devserver/wasm/sections.ts +0 -59
  246. package/src/devserver/wasm/surface.ts +0 -115
  247. package/src/io/FastMap.ts +0 -151
  248. package/src/io/FastSet.ts +0 -113
  249. package/src/io/codec.ts +0 -362
  250. package/src/io/index.ts +0 -10
  251. package/src/io/lengths.ts +0 -14
  252. package/src/io/types.ts +0 -19
  253. package/src/logger/index.ts +0 -22
  254. package/src/shared/index.ts +0 -46
  255. package/test/analytics-dev.test.ts +0 -113
  256. package/test/assembly/aspect-shim.ts +0 -33
  257. package/test/assembly/cookie.spec.ts +0 -303
  258. package/test/assembly/example.spec.ts +0 -22
  259. package/test/assembly/ssr.spec.ts +0 -95
  260. package/test/assembly.test.ts +0 -59
  261. package/test/auth-emails.test.ts +0 -118
  262. package/test/built-ssr.test.ts +0 -148
  263. package/test/channel.test.ts +0 -21
  264. package/test/config-host-port.test.ts +0 -59
  265. package/test/configure.test.ts +0 -94
  266. package/test/daemon-build.test.ts +0 -278
  267. package/test/daemon-catalog.test.ts +0 -349
  268. package/test/daemon-emulation.test.ts +0 -256
  269. package/test/db.test.ts +0 -0
  270. package/test/devserver-database.test.ts +0 -1102
  271. package/test/devserver-email.test.ts +0 -306
  272. package/test/devserver-pqauth.test.ts +0 -93
  273. package/test/devserver-secrets.test.ts +0 -63
  274. package/test/devserver.test.ts +0 -259
  275. package/test/doctor.test.ts +0 -298
  276. package/test/dom/Image.test.tsx +0 -144
  277. package/test/dom/Link.test.tsx +0 -67
  278. package/test/dom/NavLink.test.tsx +0 -37
  279. package/test/dom/Script.test.tsx +0 -48
  280. package/test/dom/action.test.tsx +0 -146
  281. package/test/dom/error-overlay.test.tsx +0 -44
  282. package/test/dom/loader.test.tsx +0 -121
  283. package/test/dom/navigation.test.ts +0 -59
  284. package/test/dom/revalidate.test.tsx +0 -38
  285. package/test/dom/route-head.test.tsx +0 -56
  286. package/test/dom/router-loading.test.tsx +0 -44
  287. package/test/dom/scroll.test.ts +0 -56
  288. package/test/dom/slot.test.tsx +0 -131
  289. package/test/dom/use-metadata.test.tsx +0 -58
  290. package/test/dom/view-transitions.test.tsx +0 -53
  291. package/test/dynamic-routing.test.ts +0 -132
  292. package/test/email-console.test.ts +0 -86
  293. package/test/email-preview.test.ts +0 -73
  294. package/test/emails.test.ts +0 -58
  295. package/test/errors.test.ts +0 -21
  296. package/test/example-guestbook.test.ts +0 -123
  297. package/test/features.test.ts +0 -149
  298. package/test/fixtures/bignum-wire/spec.ts +0 -25
  299. package/test/fixtures/daemon-app.ts +0 -65
  300. package/test/fixtures/stream-echo.ts +0 -26
  301. package/test/fixtures/stream-gate.ts +0 -28
  302. package/test/fixtures/stream-trap.ts +0 -18
  303. package/test/fixtures/stream-typed.ts +0 -41
  304. package/test/fonts.test.ts +0 -28
  305. package/test/global-setup.ts +0 -17
  306. package/test/head.test.ts +0 -42
  307. package/test/image-blur.test.ts +0 -50
  308. package/test/io.test.ts +0 -117
  309. package/test/metadata.test.ts +0 -40
  310. package/test/navlink.test.ts +0 -28
  311. package/test/pages.test.ts +0 -105
  312. package/test/placeholder.test.ts +0 -9
  313. package/test/pqauth-e2e.test.ts +0 -216
  314. package/test/pqauth-email.test.ts +0 -801
  315. package/test/prerender.test.ts +0 -116
  316. package/test/prettier-plugin.test.ts +0 -46
  317. package/test/routes.test.ts +0 -76
  318. package/test/rpc-bignum-wire.test.ts +0 -164
  319. package/test/rpc-dispatch.test.ts +0 -132
  320. package/test/rpc-kinds.test.ts +0 -18
  321. package/test/rpc.test.ts +0 -66
  322. package/test/search.test.ts +0 -114
  323. package/test/seo.test.ts +0 -175
  324. package/test/slot-layouts.test.ts +0 -69
  325. package/test/sri.test.ts +0 -129
  326. package/test/ssg.test.ts +0 -36
  327. package/test/ssr-hydration.test.tsx +0 -122
  328. package/test/ssr-render.test.ts +0 -197
  329. package/test/ssr-template.test.tsx +0 -482
  330. package/test/stream-emulation.test.ts +0 -479
  331. package/test/ui.test.ts +0 -40
  332. package/test/update.test.ts +0 -58
  333. package/test/validate.test.ts +0 -42
  334. package/test/version-check.test.ts +0 -130
  335. package/tests/data-parity/generated-parity.ts +0 -99
  336. package/tests/data-parity/parity.ts +0 -80
  337. package/tests/data-parity/spec.ts +0 -46
@@ -1,1089 +0,0 @@
1
- /**
2
- * Development-only dev toolbar. A floating badge (bottom corner) that expands into a tabbed panel
3
- * showing the matched route, build/config info, captured errors, and preferences, with live feature
4
- * toggles, click-to-navigate, and open-in-editor. Rendered as a sibling at the app root in dev only
5
- * (see `mount`), behind `isDevMode()`, so the whole module is dead-code-eliminated in production.
6
- *
7
- * It stays decoupled from the Router (it computes the current match itself via `matchRoute`) so it
8
- * renders even when the app tree has crashed.
9
- */
10
- import { type ReactNode, useEffect, useState, useSyncExternalStore } from 'react';
11
-
12
- import { type DevError, getErrorLog, subscribeErrors } from './error-overlay.js';
13
- import {
14
- isNavigationPending,
15
- navigate,
16
- setTransitions,
17
- setViewTransitions,
18
- subscribeLocation,
19
- subscribePending,
20
- } from '../navigation/navigation.js';
21
- import {
22
- clearLoaderData,
23
- inspectLoaderCache,
24
- type LoaderCacheSnapshot,
25
- loaderKey,
26
- revalidate,
27
- subscribeLoaderCache,
28
- } from '../routing/loader.js';
29
- import { matchRoute } from '../routing/match.js';
30
- import { getPages } from '../search/search.js';
31
- import type { Href, RouteDef } from '../types.js';
32
-
33
- type Tab = 'route' | 'data' | 'head' | 'build' | 'errors' | 'ai' | 'prefs';
34
-
35
- /** Base URL for the quick-doc links (the project homepage's docs section). */
36
- const DOCS_BASE = 'https://toil.org/docs';
37
-
38
- /** The toiljs brand mark (inlined from assets/logo.svg; unique gradient ids to avoid collisions). */
39
- function ToilLogo({ size = 16 }: { size?: number }): ReactNode {
40
- return (
41
- <svg
42
- width={size}
43
- height={size}
44
- viewBox="0 0 500 500"
45
- aria-hidden="true"
46
- style={{ display: 'block', flex: '0 0 auto' }}>
47
- <defs>
48
- <linearGradient
49
- id="toilDtA"
50
- x1="43.27"
51
- y1="43.27"
52
- x2="467.12"
53
- y2="467.12"
54
- gradientUnits="userSpaceOnUse">
55
- <stop
56
- offset="0"
57
- stopColor="#6990ff"
58
- />
59
- <stop
60
- offset=".28"
61
- stopColor="#521be0"
62
- />
63
- <stop
64
- offset=".66"
65
- stopColor="#6900f4"
66
- />
67
- <stop
68
- offset="1"
69
- stopColor="#7f00f6"
70
- />
71
- </linearGradient>
72
- <linearGradient
73
- id="toilDtB"
74
- x1="149.99"
75
- y1="355.49"
76
- x2="149.99"
77
- y2="0"
78
- gradientUnits="userSpaceOnUse">
79
- <stop
80
- offset=".15"
81
- stopColor="#6990ff"
82
- stopOpacity=".6"
83
- />
84
- <stop
85
- offset=".55"
86
- stopColor="#531ae1"
87
- />
88
- </linearGradient>
89
- </defs>
90
- <rect
91
- width="500"
92
- height="500"
93
- rx="130"
94
- ry="130"
95
- fill="url(#toilDtA)"
96
- />
97
- <path
98
- d="M299.98,0L0,355.49v-225.49C0,58.2,58.2,0,130,0h169.98Z"
99
- fill="url(#toilDtB)"
100
- />
101
- <path
102
- d="M106.17,111.11h285.24c9.9,0,16.7,9.96,13.09,19.18l-17.98,45.96c-2.11,5.39-7.31,8.94-13.09,8.94h-74.65c-7.76,0-14.06,6.29-14.06,14.06v214.94c0,7.76-6.29,14.06-14.06,14.06h-45.96c-7.76,0-14.06-6.29-14.06-14.06v-217.25c0-7.76-6.29-14.06-14.06-14.06h-73.66c-5.82,0-11.04-3.59-13.12-9.02l-16.76-43.64c-3.54-9.21,3.26-19.1,13.12-19.1Z"
103
- fill="#fff"
104
- />
105
- </svg>
106
- );
107
- }
108
-
109
- /** Anthropic / Claude brand mark. */
110
- function ClaudeLogo({ size = 16 }: { size?: number }): ReactNode {
111
- return (
112
- <svg
113
- width={size}
114
- height={size}
115
- viewBox="0 0 92 65"
116
- aria-hidden="true"
117
- style={{ display: 'block', flex: '0 0 auto' }}>
118
- <path
119
- fill="#d97757"
120
- d="M66.5 0H52.4L78 65h14.1L66.5 0zM25.6 0L0 65h14.4l5.2-13.6h26.8L51.6 65H66L40.4 0H25.6zm-1.2 39.3l8.8-22.8 8.8 22.8H24.4z"
121
- />
122
- </svg>
123
- );
124
- }
125
-
126
- /** OpenAI / ChatGPT brand mark. */
127
- function ChatGptLogo({ size = 16 }: { size?: number }): ReactNode {
128
- return (
129
- <svg
130
- width={size}
131
- height={size}
132
- viewBox="0 0 24 24"
133
- aria-hidden="true"
134
- style={{ display: 'block', flex: '0 0 auto' }}>
135
- <path
136
- fill="#10a37f"
137
- d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997z"
138
- />
139
- </svg>
140
- );
141
- }
142
-
143
- /** Build/config info served by the dev server at `/__toil/devinfo`. */
144
- interface DevInfo {
145
- readonly toiljs: string;
146
- readonly vite: string;
147
- readonly react: string;
148
- readonly port: number;
149
- readonly enabled: boolean;
150
- readonly flags: Record<string, boolean>;
151
- readonly routes: Record<string, string>; // pattern -> absolute file
152
- readonly ai: boolean;
153
- }
154
-
155
- // --- persisted panel state (localStorage) --------------------------------------------------------
156
-
157
- interface Prefs {
158
- open: boolean;
159
- tab: Tab;
160
- side: 'left' | 'right';
161
- }
162
- const PREFS_KEY = 'toil.devtools';
163
- const defaultPrefs: Prefs = { open: false, tab: 'route', side: 'left' };
164
-
165
- function loadPrefs(): Prefs {
166
- try {
167
- const raw = localStorage.getItem(PREFS_KEY);
168
- return raw ? { ...defaultPrefs, ...(JSON.parse(raw) as Partial<Prefs>) } : defaultPrefs;
169
- } catch {
170
- return defaultPrefs;
171
- }
172
- }
173
-
174
- // Gate on `window`, not `localStorage`: the devtools are browser-only, and merely
175
- // touching the bare `localStorage` global under SSR/Node trips its experimental-API
176
- // warning ("localStorage is not available because --localstorage-file ..."). In the
177
- // browser `loadPrefs()` reads it; under SSR we keep the defaults and never touch it.
178
- let prefs: Prefs = typeof window !== 'undefined' ? loadPrefs() : defaultPrefs;
179
- const prefListeners = new Set<() => void>();
180
- function setPrefs(next: Partial<Prefs>): void {
181
- prefs = { ...prefs, ...next };
182
- try {
183
- localStorage.setItem(PREFS_KEY, JSON.stringify(prefs));
184
- } catch {
185
- /* ignore */
186
- }
187
- for (const l of prefListeners) l();
188
- }
189
- function usePrefs(): Prefs {
190
- return useSyncExternalStore(
191
- (l) => {
192
- prefListeners.add(l);
193
- return () => prefListeners.delete(l);
194
- },
195
- () => prefs,
196
- () => defaultPrefs,
197
- );
198
- }
199
-
200
- // --- live location + nav + errors ----------------------------------------------------------------
201
-
202
- function useCurrentUrl(): string {
203
- return useSyncExternalStore(
204
- subscribeLocation,
205
- () => window.location.pathname + window.location.search,
206
- () => '/',
207
- );
208
- }
209
- function usePending(): boolean {
210
- return useSyncExternalStore(subscribePending, isNavigationPending, () => false);
211
- }
212
- function useErrors(): readonly DevError[] {
213
- return useSyncExternalStore(subscribeErrors, getErrorLog, () => getErrorLog());
214
- }
215
- function useLoaderCache(): readonly LoaderCacheSnapshot[] {
216
- return useSyncExternalStore(subscribeLoaderCache, inspectLoaderCache, inspectLoaderCache);
217
- }
218
-
219
- /** JSON.stringify that won't throw on cyclic/odd data. */
220
- function safeJson(value: unknown): string {
221
- try {
222
- return JSON.stringify(value, null, 2) ?? String(value);
223
- } catch {
224
- return String(value);
225
- }
226
- }
227
-
228
- /** Reads the current document head's meta + link tags (live). */
229
- function readHead(): {
230
- metas: { name: string; content: string }[];
231
- links: { rel: string; href: string }[];
232
- } {
233
- const metas: { name: string; content: string }[] = [];
234
- const links: { rel: string; href: string }[] = [];
235
- if (typeof document === 'undefined') return { metas, links };
236
- document.head.querySelectorAll('meta').forEach((m) => {
237
- const name = m.getAttribute('name') ?? m.getAttribute('property');
238
- const content = m.getAttribute('content');
239
- if (name && content) metas.push({ name, content });
240
- });
241
- document.head.querySelectorAll('link[rel]').forEach((l) => {
242
- links.push({ rel: l.getAttribute('rel') ?? '', href: l.getAttribute('href') ?? '' });
243
- });
244
- return { metas, links };
245
- }
246
-
247
- // --- styles (injected once) ----------------------------------------------------------------------
248
-
249
- const STYLE_ID = 'toil-devtools-style';
250
- const CSS = `
251
- .toil-dt{position:fixed;bottom:12px;z-index:2147483646;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:#e7e9f0}
252
- .toil-dt.left{left:12px}.toil-dt.right{right:12px}
253
- .toil-dt-badge{display:flex;align-items:center;gap:7px;background:#15151c;border:1px solid #2c2c38;border-radius:999px;padding:5px 11px 5px 8px;cursor:pointer;box-shadow:0 4px 16px rgba(0,0,0,.35);user-select:none}
254
- .toil-dt-badge:hover{border-color:#3a3a48}
255
- .toil-dt-dot{width:8px;height:8px;border-radius:50%;background:#22e3ab;box-shadow:0 0 6px #22e3ab}
256
- .toil-dt-dot.pending{background:#f7b93e;box-shadow:0 0 6px #f7b93e;animation:toil-dt-pulse 1s infinite}
257
- .toil-dt-dot.error{background:#ef4444;box-shadow:0 0 6px #ef4444}
258
- @keyframes toil-dt-pulse{0%,100%{opacity:1}50%{opacity:.4}}
259
- .toil-dt-logo{font-weight:700;background:linear-gradient(90deg,#2563ff,#7c3aed,#22e3ab);-webkit-background-clip:text;background-clip:text;color:transparent}
260
- .toil-dt-panel{width:380px;max-width:calc(100vw - 24px);max-height:min(70vh,560px);background:#101016;border:1px solid #2c2c38;border-radius:12px;box-shadow:0 16px 56px rgba(0,0,0,.55);display:flex;flex-direction:column;overflow:hidden}
261
- .toil-dt-tabs{display:flex;border-bottom:1px solid #23232e;flex:0 0 auto}
262
- .toil-dt-tab{flex:1;padding:8px 4px;background:none;border:0;color:#8b90a4;font:inherit;cursor:pointer;border-bottom:2px solid transparent}
263
- .toil-dt-tab.active{color:#e7e9f0;border-bottom-color:#2563ff}
264
- .toil-dt-tab:hover{color:#c8cee0}
265
- .toil-dt-body{padding:12px 14px;overflow:auto}
266
- .toil-dt-head{display:flex;align-items:center;justify-content:space-between;padding:8px 12px;border-bottom:1px solid #23232e;flex:0 0 auto}
267
- .toil-dt-x{background:none;border:0;color:#8b90a4;cursor:pointer;font:inherit;font-size:14px}
268
- .toil-dt-row{display:flex;justify-content:space-between;gap:10px;padding:3px 0;border-bottom:1px solid #1b1b24}
269
- .toil-dt-k{color:#8b90a4}
270
- .toil-dt-v{color:#e7e9f0;text-align:right;word-break:break-all}
271
- .toil-dt-tag{display:inline-block;padding:1px 6px;border-radius:5px;background:#23232e;color:#a8b0c8;margin:1px 3px 1px 0;font-size:11px}
272
- .toil-dt-rt{display:flex;align-items:center;gap:6px;padding:3px 0}
273
- .toil-dt-rt a{color:#7aa2ff;text-decoration:none;cursor:pointer}.toil-dt-rt a:hover{text-decoration:underline}
274
- .toil-dt-rt .dyn{color:#c8cee0;cursor:default}
275
- .toil-dt-edit{margin-left:auto;background:none;border:0;color:#5b6178;cursor:pointer;font:inherit}.toil-dt-edit:hover{color:#7aa2ff}
276
- .toil-dt-sec{margin:0 0 6px;color:#6b7088;text-transform:uppercase;letter-spacing:.05em;font-size:10px}
277
- .toil-dt-sw{display:flex;align-items:center;justify-content:space-between;padding:5px 0}
278
- .toil-dt-btn{font:inherit;color:#e7e9f0;background:#23232e;border:1px solid #33333f;border-radius:6px;padding:3px 9px;cursor:pointer}
279
- .toil-dt-btn:hover{border-color:#454556}
280
- .toil-dt-err{padding:6px 0;border-bottom:1px solid #1b1b24}
281
- .toil-dt-err .msg{color:#ff8a8a;word-break:break-word}
282
- .toil-dt-empty{color:#6b7088;padding:8px 0}
283
- .toil-dt-pre{background:#0a0a0e;border:1px solid #1b1b24;border-radius:6px;padding:8px;max-height:200px;overflow:auto;white-space:pre-wrap;word-break:break-word;color:#c8cee0;margin:6px 0 0;font-size:11px}
284
- .toil-dt-chk{display:flex;gap:8px;align-items:center;padding:3px 0}
285
- .toil-dt-ok{color:#22e3ab}.toil-dt-bad{color:#ef4444}
286
- .toil-dt-og{display:flex;gap:8px;border:1px solid #23232e;border-radius:8px;overflow:hidden;background:#0d0d13}
287
- .toil-dt-og-img{width:72px;height:72px;object-fit:cover;flex:0 0 auto}
288
- .toil-dt-og-body{padding:6px 8px;min-width:0}
289
- .toil-dt-og-title{color:#e7e9f0;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
290
- .toil-dt-og-desc{color:#8b90a4;font-size:11px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
291
- .toil-dt-ta{width:100%;box-sizing:border-box;background:#0a0a0e;border:1px solid #23232e;border-radius:6px;color:#e7e9f0;font:inherit;padding:7px 8px;resize:vertical;min-height:54px}
292
- .toil-dt-ta:focus{outline:none;border-color:#2563ff}
293
- .toil-dt-ai-btns{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0}
294
- .toil-dt-ai-btn{display:flex;align-items:center;gap:6px;font:inherit;color:#e7e9f0;background:#23232e;border:1px solid #33333f;border-radius:6px;padding:5px 10px;cursor:pointer}
295
- .toil-dt-ai-btn:hover{border-color:#454556}
296
- .toil-dt-doc{display:block;color:#7aa2ff;text-decoration:none;padding:3px 0}.toil-dt-doc:hover{text-decoration:underline}
297
- .toil-dt-pal-wrap{position:fixed;inset:0;z-index:2147483647;display:flex;align-items:flex-start;justify-content:center;background:rgba(0,0,0,.45);padding-top:14vh}
298
- .toil-dt-pal{width:440px;max-width:calc(100vw - 24px);background:#101016;border:1px solid #2c2c38;border-radius:12px;box-shadow:0 16px 56px rgba(0,0,0,.6);overflow:hidden;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:#e7e9f0}
299
- .toil-dt-pal input{width:100%;box-sizing:border-box;background:none;border:0;border-bottom:1px solid #23232e;color:#e7e9f0;font:inherit;padding:11px 14px}
300
- .toil-dt-pal input:focus{outline:none}
301
- .toil-dt-pal-list{max-height:340px;overflow:auto;padding:4px}
302
- .toil-dt-pal-item{display:flex;gap:8px;align-items:center;padding:7px 10px;border-radius:6px;cursor:pointer;color:#c8cee0}
303
- .toil-dt-pal-item.sel{background:#1c1c26;color:#e7e9f0}
304
- .toil-dt-pal-kind{color:#6b7088;font-size:11px;margin-left:auto}
305
- `;
306
- function injectStyles(): void {
307
- if (typeof document === 'undefined' || document.getElementById(STYLE_ID)) return;
308
- const el = document.createElement('style');
309
- el.id = STYLE_ID;
310
- el.textContent = CSS;
311
- document.head.appendChild(el);
312
- }
313
-
314
- // --- helpers -------------------------------------------------------------------------------------
315
-
316
- function isDynamic(pattern: string): boolean {
317
- return /[:*]/.test(pattern);
318
- }
319
-
320
- function openInEditor(file: string): void {
321
- void fetch(`/__toil/open?file=${encodeURIComponent(file)}`).catch(() => undefined);
322
- }
323
-
324
- function Row({ k, children }: { k: string; children: ReactNode }): ReactNode {
325
- return (
326
- <div className="toil-dt-row">
327
- <span className="toil-dt-k">{k}</span>
328
- <span className="toil-dt-v">{children}</span>
329
- </div>
330
- );
331
- }
332
-
333
- // --- tabs ----------------------------------------------------------------------------------------
334
-
335
- function RouteTab({
336
- routes,
337
- slots,
338
- info,
339
- }: {
340
- routes: RouteDef[];
341
- slots: Record<string, RouteDef[]>;
342
- info: DevInfo | null;
343
- }): ReactNode {
344
- const url = useCurrentUrl();
345
- const pending = usePending();
346
- const pathname = url.split('?')[0];
347
- const search = url.slice(pathname.length);
348
-
349
- let matched: { route: RouteDef; params: Record<string, string | string[]> } | null = null;
350
- for (const r of routes) {
351
- const params = matchRoute(r.pattern, pathname);
352
- if (params) {
353
- matched = { route: r, params };
354
- break;
355
- }
356
- }
357
- const activeSlots: string[] = [];
358
- for (const [name, defs] of Object.entries(slots)) {
359
- if (defs.some((d) => matchRoute(d.pattern, pathname))) activeSlots.push(name);
360
- }
361
-
362
- const has = (r: RouteDef): string =>
363
- [
364
- r.loading ? 'loading' : '',
365
- r.errorComponent ? 'error' : '',
366
- r.templates?.length ? 'template' : '',
367
- r.layouts?.length ? `${String(r.layouts.length)} layout` : '',
368
- ]
369
- .filter(Boolean)
370
- .join(', ') || 'none';
371
-
372
- return (
373
- <div className="toil-dt-body">
374
- <Row k="path">{pathname || '/'}</Row>
375
- <Row k="match">{matched ? matched.route.pattern : 'no match (404)'}</Row>
376
- {search && <Row k="query">{search}</Row>}
377
- {matched && Object.keys(matched.params).length > 0 && (
378
- <Row k="params">{JSON.stringify(matched.params)}</Row>
379
- )}
380
- {matched && <Row k="boundaries">{has(matched.route)}</Row>}
381
- <Row k="slots">{activeSlots.length ? activeSlots.join(', ') : 'none'}</Row>
382
- <Row k="navigating">{pending ? 'yes' : 'no'}</Row>
383
-
384
- <p
385
- className="toil-dt-sec"
386
- style={{ marginTop: 12 }}>
387
- Routes ({routes.length})
388
- </p>
389
- {routes.map((r) => {
390
- const file = info?.routes[r.pattern];
391
- return (
392
- <div
393
- className="toil-dt-rt"
394
- key={r.pattern}>
395
- {isDynamic(r.pattern) ? (
396
- <span className="dyn">{r.pattern}</span>
397
- ) : (
398
- <a
399
- onClick={() => {
400
- navigate(r.pattern as Href);
401
- }}>
402
- {r.pattern}
403
- </a>
404
- )}
405
- {file && (
406
- <button
407
- className="toil-dt-edit"
408
- title={`open ${file}`}
409
- onClick={() => {
410
- openInEditor(file);
411
- }}>
412
- edit
413
- </button>
414
- )}
415
- </div>
416
- );
417
- })}
418
- </div>
419
- );
420
- }
421
-
422
- function DataTab(): ReactNode {
423
- const url = useCurrentUrl();
424
- const entries = useLoaderCache();
425
- const pathname = url.split('?')[0];
426
- const key = loaderKey(pathname, url.slice(pathname.length));
427
- const entry = entries.find((e) => e.key === key);
428
- return (
429
- <div className="toil-dt-body">
430
- {!entry && <p className="toil-dt-empty">No cached loader data for this route.</p>}
431
- {entry && (
432
- <>
433
- <Row k="status">{entry.status}</Row>
434
- <Row k="has loader">{entry.hasLoader ? 'yes' : 'no'}</Row>
435
- <Row k="revalidate">
436
- {entry.revalidate === false ? 'never' : `${String(entry.revalidate)}s`}
437
- </Row>
438
- <Row k="loaded">
439
- {entry.loadedAt ? new Date(entry.loadedAt).toLocaleTimeString() : '-'}
440
- </Row>
441
- {entry.hasLoader ? (
442
- <>
443
- <div style={{ margin: '8px 0' }}>
444
- <button
445
- className="toil-dt-btn"
446
- onClick={() => {
447
- revalidate();
448
- }}>
449
- Revalidate
450
- </button>{' '}
451
- <button
452
- className="toil-dt-btn"
453
- onClick={() => {
454
- clearLoaderData();
455
- }}>
456
- Clear cache
457
- </button>
458
- </div>
459
- {entry.data === undefined ? (
460
- <p className="toil-dt-empty">Loader returned no data.</p>
461
- ) : (
462
- <pre className="toil-dt-pre">{safeJson(entry.data)}</pre>
463
- )}
464
- </>
465
- ) : (
466
- <p className="toil-dt-empty">
467
- This route has no loader, so there is no data to inspect.
468
- </p>
469
- )}
470
- </>
471
- )}
472
- <p
473
- className="toil-dt-sec"
474
- style={{ marginTop: 12 }}>
475
- Cache ({entries.length})
476
- </p>
477
- {entries.map((e) => (
478
- <Row
479
- k={e.key}
480
- key={e.key}>
481
- {e.status}
482
- </Row>
483
- ))}
484
- </div>
485
- );
486
- }
487
-
488
- function Check({ ok, label }: { ok: boolean; label: string }): ReactNode {
489
- return (
490
- <div className="toil-dt-chk">
491
- <span className={ok ? 'toil-dt-ok' : 'toil-dt-bad'}>{ok ? '✓' : '✗'}</span>
492
- <span>{label}</span>
493
- </div>
494
- );
495
- }
496
-
497
- function HeadTab(): ReactNode {
498
- useCurrentUrl(); // re-read the DOM head on navigation
499
- const title = typeof document !== 'undefined' ? document.title : '';
500
- const { metas, links } = readHead();
501
- const meta = (n: string): string | undefined => metas.find((m) => m.name === n)?.content;
502
- const og = {
503
- title: meta('og:title') ?? title,
504
- description: meta('og:description') ?? meta('description'),
505
- image: meta('og:image'),
506
- };
507
- const pages = getPages();
508
- const described = pages.filter((p) => p.metadata.description !== undefined).length;
509
-
510
- return (
511
- <div className="toil-dt-body">
512
- <Row k="title">{title || '(none)'}</Row>
513
-
514
- <p
515
- className="toil-dt-sec"
516
- style={{ marginTop: 10 }}>
517
- OpenGraph preview
518
- </p>
519
- <div className="toil-dt-og">
520
- {og.image && (
521
- <img
522
- src={og.image}
523
- alt=""
524
- className="toil-dt-og-img"
525
- />
526
- )}
527
- <div className="toil-dt-og-body">
528
- <div className="toil-dt-og-title">{og.title || '(no title)'}</div>
529
- <div className="toil-dt-og-desc">{og.description ?? '(no description)'}</div>
530
- </div>
531
- </div>
532
-
533
- <p
534
- className="toil-dt-sec"
535
- style={{ marginTop: 10 }}>
536
- SEO checklist
537
- </p>
538
- <Check
539
- ok={Boolean(title)}
540
- label="Has a title"
541
- />
542
- <Check
543
- ok={meta('description') !== undefined}
544
- label="Has a meta description"
545
- />
546
- <Check
547
- ok={og.image !== undefined}
548
- label="Has an og:image"
549
- />
550
- <Check
551
- ok={links.some((l) => l.rel === 'canonical')}
552
- label="Has a canonical link"
553
- />
554
- <Check
555
- ok={pages.length === 0 || described === pages.length}
556
- label={`Pages with a description: ${String(described)}/${String(pages.length)}`}
557
- />
558
-
559
- <p
560
- className="toil-dt-sec"
561
- style={{ marginTop: 10 }}>
562
- Meta ({metas.length})
563
- </p>
564
- {metas.map((m, i) => (
565
- <Row
566
- k={m.name}
567
- key={`${m.name}:${String(i)}`}>
568
- {m.content}
569
- </Row>
570
- ))}
571
- </div>
572
- );
573
- }
574
-
575
- function BuildTab({ info }: { info: DevInfo | null }): ReactNode {
576
- return (
577
- <div className="toil-dt-body">
578
- {!info && <p className="toil-dt-empty">Loading dev info...</p>}
579
- {info && (
580
- <>
581
- <Row k="toiljs">{info.toiljs}</Row>
582
- <Row k="vite">{info.vite}</Row>
583
- <Row k="react">{info.react}</Row>
584
- <Row k="dev server">{`localhost:${String(info.port)}`}</Row>
585
- <p
586
- className="toil-dt-sec"
587
- style={{ marginTop: 12 }}>
588
- Config
589
- </p>
590
- {Object.entries(info.flags).map(([k, v]) => (
591
- <Row
592
- k={k}
593
- key={k}>
594
- {v ? 'on' : 'off'}
595
- </Row>
596
- ))}
597
- <Row k="ai">{info.ai ? 'configured' : 'hand-off only'}</Row>
598
- </>
599
- )}
600
- </div>
601
- );
602
- }
603
-
604
- function ErrorsTab(): ReactNode {
605
- const errors = useErrors();
606
- if (errors.length === 0)
607
- return <p className="toil-dt-empty toil-dt-body">No errors captured.</p>;
608
- return (
609
- <div className="toil-dt-body">
610
- {[...errors].reverse().map((e, i) => (
611
- <div
612
- className="toil-dt-err"
613
- key={`${String(e.time)}:${String(i)}`}>
614
- <div className="msg">
615
- {e.error.name}: {e.error.message}
616
- </div>
617
- <div className="toil-dt-k">
618
- {e.source}, {new Date(e.time).toLocaleTimeString()}
619
- </div>
620
- </div>
621
- ))}
622
- </div>
623
- );
624
- }
625
-
626
- /** Builds a context string about the current page for AI hand-off / inline ask. */
627
- function buildAiContext(): string {
628
- if (typeof window === 'undefined') return '';
629
- const where = window.location.pathname + window.location.search;
630
- const title = document.title;
631
- const desc = readHead().metas.find((m) => m.name === 'description')?.content;
632
- const lines = [
633
- 'I am working on a toiljs app (React with file-based routing, backend in toilscript/WASM).',
634
- `Current page: ${where}`,
635
- ];
636
- if (title) lines.push(`Page title: ${title}`);
637
- if (desc) lines.push(`Meta description: ${desc}`);
638
- return lines.join('\n');
639
- }
640
-
641
- const DOC_LINKS: { label: string; slug: string }[] = [
642
- { label: 'Routing and file conventions', slug: 'routing' },
643
- { label: 'Loaders and data', slug: 'loaders' },
644
- { label: 'Metadata and SEO', slug: 'metadata' },
645
- { label: 'Parallel routes and slots', slug: 'slots' },
646
- ];
647
-
648
- /** Max chars of route source to inline into the prompt (keeps the hand-off URL usable). */
649
- const AI_CODE_MAX = 8000;
650
-
651
- function AiTab({ info, routes }: { info: DevInfo | null; routes: RouteDef[] }): ReactNode {
652
- const url = useCurrentUrl(); // rebuild page context + refetch source on navigation
653
- const [question, setQuestion] = useState('');
654
- const [answer, setAnswer] = useState<string | null>(null);
655
- const [busy, setBusy] = useState(false);
656
- const [source, setSource] = useState<{ file: string; code: string } | null>(null);
657
- const configured = info?.ai === true;
658
-
659
- // Resolve the current route's source file (pattern -> absolute path from the dev server).
660
- const pathname = url.split('?')[0];
661
- let file: string | undefined;
662
- for (const r of routes) {
663
- if (matchRoute(r.pattern, pathname)) {
664
- file = info?.routes[r.pattern];
665
- break;
666
- }
667
- }
668
-
669
- useEffect(() => {
670
- if (!file) {
671
- setSource(null);
672
- return;
673
- }
674
- let cancelled = false;
675
- void fetch(`/__toil/source?file=${encodeURIComponent(file)}`)
676
- .then((r) => (r.ok ? r.text() : null))
677
- .then((code) => {
678
- if (!cancelled) setSource(code !== null ? { file, code } : null);
679
- })
680
- .catch(() => {
681
- if (!cancelled) setSource(null);
682
- });
683
- return () => {
684
- cancelled = true;
685
- };
686
- }, [file]);
687
-
688
- const prompt = (): string => {
689
- const q = question.trim() || 'Explain this page and suggest improvements.';
690
- const parts = [buildAiContext()];
691
- if (source) {
692
- const code = source.code.slice(0, AI_CODE_MAX);
693
- const cut = source.code.length > AI_CODE_MAX ? '\n... (truncated)' : '';
694
- parts.push(`\nPage source (${source.file}):\n\`\`\`tsx\n${code}${cut}\n\`\`\``);
695
- }
696
- parts.push(`\nQuestion: ${q}`);
697
- return parts.join('\n');
698
- };
699
- const handOff = (base: string): void => {
700
- window.open(`${base}${encodeURIComponent(prompt())}`, '_blank', 'noopener');
701
- };
702
- const copy = (): void => {
703
- void navigator.clipboard.writeText(prompt()).catch(() => undefined);
704
- };
705
- const askInline = (): void => {
706
- setBusy(true);
707
- setAnswer(null);
708
- void fetch('/__toil/ai', {
709
- method: 'POST',
710
- headers: { 'content-type': 'application/json' },
711
- body: JSON.stringify({ prompt: prompt() }),
712
- })
713
- .then((r) =>
714
- r.ok
715
- ? (r.json() as Promise<{ text?: string }>)
716
- : Promise.reject(new Error(`HTTP ${String(r.status)}`)),
717
- )
718
- .then((d) => {
719
- setAnswer(d.text ?? '(empty response)');
720
- })
721
- .catch((e: unknown) => {
722
- setAnswer(`Error: ${e instanceof Error ? e.message : String(e)}`);
723
- })
724
- .finally(() => {
725
- setBusy(false);
726
- });
727
- };
728
-
729
- return (
730
- <div className="toil-dt-body">
731
- <p className="toil-dt-sec">Ask about this page</p>
732
- <textarea
733
- className="toil-dt-ta"
734
- placeholder="Ask about the current route, or leave blank for a summary..."
735
- value={question}
736
- onChange={(e) => {
737
- setQuestion(e.target.value);
738
- }}
739
- />
740
- <div className="toil-dt-ai-btns">
741
- <button
742
- className="toil-dt-ai-btn"
743
- onClick={() => {
744
- handOff('https://claude.ai/new?q=');
745
- }}>
746
- <ClaudeLogo size={14} /> Claude
747
- </button>
748
- <button
749
- className="toil-dt-ai-btn"
750
- onClick={() => {
751
- handOff('https://chatgpt.com/?q=');
752
- }}>
753
- <ChatGptLogo size={14} /> ChatGPT
754
- </button>
755
- <button
756
- className="toil-dt-ai-btn"
757
- onClick={copy}>
758
- Copy
759
- </button>
760
- {configured && (
761
- <button
762
- className="toil-dt-ai-btn"
763
- disabled={busy}
764
- onClick={askInline}>
765
- {busy ? 'Asking...' : 'Ask inline'}
766
- </button>
767
- )}
768
- </div>
769
- {source && (
770
- <p className="toil-dt-k">
771
- Prompt includes this route&apos;s source ({source.file.split('/').pop()}).
772
- </p>
773
- )}
774
- {!configured && (
775
- <p className="toil-dt-k">
776
- Inline answers are off. Set <span className="toil-dt-tag">devtools.ai</span> in
777
- your config to proxy a provider; the API key stays server-side.
778
- </p>
779
- )}
780
- {answer !== null && <pre className="toil-dt-pre">{answer}</pre>}
781
-
782
- <p
783
- className="toil-dt-sec"
784
- style={{ marginTop: 12 }}>
785
- Quick docs
786
- </p>
787
- {DOC_LINKS.map((d) => (
788
- <a
789
- key={d.slug}
790
- className="toil-dt-doc"
791
- href={`${DOCS_BASE}/${d.slug}`}
792
- target="_blank"
793
- rel="noreferrer">
794
- {d.label}
795
- </a>
796
- ))}
797
- </div>
798
- );
799
- }
800
-
801
- /** A cmd/ctrl+K command palette: jump to a route or run a dev action. */
802
- function Palette({ routes, onClose }: { routes: RouteDef[]; onClose: () => void }): ReactNode {
803
- const [q, setQ] = useState('');
804
- const [sel, setSel] = useState(0);
805
-
806
- const items: { label: string; kind: string; run: () => void }[] = [];
807
- for (const r of routes) {
808
- if (!isDynamic(r.pattern)) {
809
- items.push({
810
- label: r.pattern,
811
- kind: 'route',
812
- run: () => {
813
- navigate(r.pattern as Href);
814
- onClose();
815
- },
816
- });
817
- }
818
- }
819
- items.push(
820
- {
821
- label: 'Revalidate current route',
822
- kind: 'action',
823
- run: () => {
824
- revalidate();
825
- onClose();
826
- },
827
- },
828
- {
829
- label: 'Clear loader cache',
830
- kind: 'action',
831
- run: () => {
832
- clearLoaderData();
833
- onClose();
834
- },
835
- },
836
- {
837
- label: 'Ask AI about this page',
838
- kind: 'action',
839
- run: () => {
840
- setPrefs({ open: true, tab: 'ai' });
841
- onClose();
842
- },
843
- },
844
- {
845
- label: 'Open preferences',
846
- kind: 'action',
847
- run: () => {
848
- setPrefs({ open: true, tab: 'prefs' });
849
- onClose();
850
- },
851
- },
852
- );
853
-
854
- const needle = q.toLowerCase();
855
- const filtered = items.filter((it) => it.label.toLowerCase().includes(needle));
856
- const clamped = Math.min(sel, Math.max(0, filtered.length - 1));
857
-
858
- return (
859
- <div
860
- className="toil-dt-pal-wrap"
861
- onClick={onClose}>
862
- <div
863
- className="toil-dt-pal"
864
- onClick={(e) => {
865
- e.stopPropagation();
866
- }}>
867
- <input
868
- autoFocus
869
- placeholder="Go to a route or run an action..."
870
- value={q}
871
- onChange={(e) => {
872
- setQ(e.target.value);
873
- setSel(0);
874
- }}
875
- onKeyDown={(e) => {
876
- if (e.key === 'ArrowDown') {
877
- e.preventDefault();
878
- setSel((s) => Math.min(s + 1, filtered.length - 1));
879
- } else if (e.key === 'ArrowUp') {
880
- e.preventDefault();
881
- setSel((s) => Math.max(s - 1, 0));
882
- } else if (e.key === 'Enter') {
883
- e.preventDefault();
884
- filtered[clamped]?.run();
885
- } else if (e.key === 'Escape') {
886
- onClose();
887
- }
888
- }}
889
- />
890
- <div className="toil-dt-pal-list">
891
- {filtered.length === 0 && <div className="toil-dt-pal-item">No matches</div>}
892
- {filtered.map((it, i) => (
893
- <div
894
- key={`${it.kind}:${it.label}`}
895
- className={`toil-dt-pal-item ${i === clamped ? 'sel' : ''}`}
896
- onMouseEnter={() => {
897
- setSel(i);
898
- }}
899
- onClick={it.run}>
900
- <span>{it.label}</span>
901
- <span className="toil-dt-pal-kind">{it.kind}</span>
902
- </div>
903
- ))}
904
- </div>
905
- </div>
906
- </div>
907
- );
908
- }
909
-
910
- function PrefsTab(): ReactNode {
911
- const p = usePrefs();
912
- const [flags, setFlags] = useState({ viewTransitions: false, transitions: false });
913
- const toggle = (key: 'viewTransitions' | 'transitions'): void => {
914
- const next = !flags[key];
915
- setFlags((f) => ({ ...f, [key]: next }));
916
- if (key === 'viewTransitions') setViewTransitions(next);
917
- else setTransitions(next);
918
- };
919
- return (
920
- <div className="toil-dt-body">
921
- <div className="toil-dt-sw">
922
- <span>View transitions</span>
923
- <button
924
- className="toil-dt-btn"
925
- onClick={() => {
926
- toggle('viewTransitions');
927
- }}>
928
- {flags.viewTransitions ? 'on' : 'off'}
929
- </button>
930
- </div>
931
- <div className="toil-dt-sw">
932
- <span>Loader transition</span>
933
- <button
934
- className="toil-dt-btn"
935
- onClick={() => {
936
- toggle('transitions');
937
- }}>
938
- {flags.transitions ? 'on' : 'off'}
939
- </button>
940
- </div>
941
- <div className="toil-dt-sw">
942
- <span>Toolbar side</span>
943
- <button
944
- className="toil-dt-btn"
945
- onClick={() => {
946
- setPrefs({ side: p.side === 'left' ? 'right' : 'left' });
947
- }}>
948
- {p.side}
949
- </button>
950
- </div>
951
- </div>
952
- );
953
- }
954
-
955
- const TABS: { id: Tab; label: string }[] = [
956
- { id: 'route', label: 'Route' },
957
- { id: 'data', label: 'Data' },
958
- { id: 'head', label: 'Head' },
959
- { id: 'build', label: 'Build' },
960
- { id: 'errors', label: 'Errors' },
961
- { id: 'ai', label: 'AI' },
962
- { id: 'prefs', label: 'Prefs' },
963
- ];
964
-
965
- /** The dev toolbar. Rendered once at the app root in dev mode (see `mount`). */
966
- export function DevToolbar({
967
- routes,
968
- slots,
969
- }: {
970
- routes: RouteDef[];
971
- slots: Record<string, RouteDef[]>;
972
- }): ReactNode {
973
- const p = usePrefs();
974
- const pending = usePending();
975
- const errors = useErrors();
976
- const [info, setInfo] = useState<DevInfo | null>(null);
977
- const [palette, setPalette] = useState(false);
978
-
979
- useEffect(() => {
980
- injectStyles();
981
- void fetch('/__toil/devinfo')
982
- .then((r) => (r.ok ? (r.json() as Promise<DevInfo>) : null))
983
- .then((data) => {
984
- if (data) setInfo(data);
985
- })
986
- .catch(() => undefined);
987
- }, []);
988
-
989
- useEffect(() => {
990
- const onKey = (e: KeyboardEvent): void => {
991
- if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
992
- e.preventDefault();
993
- setPalette((v) => !v);
994
- }
995
- };
996
- window.addEventListener('keydown', onKey);
997
- return () => {
998
- window.removeEventListener('keydown', onKey);
999
- };
1000
- }, []);
1001
-
1002
- if (info && !info.enabled) return null;
1003
-
1004
- const dotClass = errors.length > 0 ? 'error' : pending ? 'pending' : '';
1005
- const pal = palette ? (
1006
- <Palette
1007
- routes={routes}
1008
- onClose={() => {
1009
- setPalette(false);
1010
- }}
1011
- />
1012
- ) : null;
1013
-
1014
- if (!p.open) {
1015
- return (
1016
- <>
1017
- <div className={`toil-dt ${p.side}`}>
1018
- <div
1019
- className="toil-dt-badge"
1020
- onClick={() => {
1021
- setPrefs({ open: true });
1022
- }}
1023
- title="toiljs devtools (cmd+K)">
1024
- <ToilLogo size={16} />
1025
- <span className={`toil-dt-dot ${dotClass}`} />
1026
- </div>
1027
- </div>
1028
- {pal}
1029
- </>
1030
- );
1031
- }
1032
-
1033
- return (
1034
- <>
1035
- <div className={`toil-dt ${p.side}`}>
1036
- <div className="toil-dt-panel">
1037
- <div className="toil-dt-head">
1038
- <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
1039
- <ToilLogo size={14} />
1040
- <span className="toil-dt-logo">toiljs</span> devtools
1041
- <span className={`toil-dt-dot ${dotClass}`} />
1042
- </span>
1043
- <button
1044
- className="toil-dt-x"
1045
- onClick={() => {
1046
- setPrefs({ open: false });
1047
- }}>
1048
- ✕
1049
- </button>
1050
- </div>
1051
- <div className="toil-dt-tabs">
1052
- {TABS.map((t) => (
1053
- <button
1054
- key={t.id}
1055
- className={`toil-dt-tab ${p.tab === t.id ? 'active' : ''}`}
1056
- onClick={() => {
1057
- setPrefs({ tab: t.id });
1058
- }}>
1059
- {t.label}
1060
- {t.id === 'errors' && errors.length > 0
1061
- ? ` (${String(errors.length)})`
1062
- : ''}
1063
- </button>
1064
- ))}
1065
- </div>
1066
- {p.tab === 'route' && (
1067
- <RouteTab
1068
- routes={routes}
1069
- slots={slots}
1070
- info={info}
1071
- />
1072
- )}
1073
- {p.tab === 'data' && <DataTab />}
1074
- {p.tab === 'head' && <HeadTab />}
1075
- {p.tab === 'build' && <BuildTab info={info} />}
1076
- {p.tab === 'errors' && <ErrorsTab />}
1077
- {p.tab === 'ai' && (
1078
- <AiTab
1079
- info={info}
1080
- routes={routes}
1081
- />
1082
- )}
1083
- {p.tab === 'prefs' && <PrefsTab />}
1084
- </div>
1085
- </div>
1086
- {pal}
1087
- </>
1088
- );
1089
- }