nudge-ui 0.2.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 (510) hide show
  1. package/README.md +66 -0
  2. package/bin/nudge-ui.mjs +7 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/client.mjs +261 -0
  5. package/dist/compiler/ast.d.ts +18 -0
  6. package/dist/compiler/ast.js +75 -0
  7. package/dist/compiler/componentContractTypes.d.ts +19 -0
  8. package/dist/compiler/componentContractTypes.js +1 -0
  9. package/dist/compiler/componentContracts.d.ts +2 -0
  10. package/dist/compiler/componentContracts.js +260 -0
  11. package/dist/compiler/componentInstrumentation.d.ts +32 -0
  12. package/dist/compiler/componentInstrumentation.js +140 -0
  13. package/dist/compiler/componentPolicyResolution.d.ts +71 -0
  14. package/dist/compiler/componentPolicyResolution.js +388 -0
  15. package/dist/compiler/index.d.ts +9 -0
  16. package/dist/compiler/index.js +9 -0
  17. package/dist/compiler/packageComponentContracts.d.ts +32 -0
  18. package/dist/compiler/packageComponentContracts.js +308 -0
  19. package/dist/compiler/reactComponentProtocols.d.ts +145 -0
  20. package/dist/compiler/reactComponentProtocols.js +47 -0
  21. package/dist/compiler/reactIdentity.d.ts +15 -0
  22. package/dist/compiler/reactIdentity.js +339 -0
  23. package/dist/compiler/sourcePaths.d.ts +12 -0
  24. package/dist/compiler/sourcePaths.js +27 -0
  25. package/dist/css/dialects/index.d.ts +62 -0
  26. package/dist/css/dialects/index.js +103 -0
  27. package/dist/css/dialects/tailwind.d.ts +46 -0
  28. package/dist/css/dialects/tailwind.js +119 -0
  29. package/dist/css/dialects/vanillaExtract.d.ts +20 -0
  30. package/dist/css/dialects/vanillaExtract.js +32 -0
  31. package/dist/css/index.d.ts +10 -0
  32. package/dist/css/index.js +10 -0
  33. package/dist/css/model/index.d.ts +190 -0
  34. package/dist/css/model/index.js +10 -0
  35. package/dist/css/token-inventory/index.d.ts +26 -0
  36. package/dist/css/token-inventory/index.js +24 -0
  37. package/dist/css/token-inventory/inventory.d.ts +8 -0
  38. package/dist/css/token-inventory/inventory.js +421 -0
  39. package/dist/css/token-inventory/parseStylesheet.d.ts +16 -0
  40. package/dist/css/token-inventory/parseStylesheet.js +155 -0
  41. package/dist/css/token-inventory/policy.d.ts +47 -0
  42. package/dist/css/token-inventory/policy.js +50 -0
  43. package/dist/css/token-inventory/types.d.ts +97 -0
  44. package/dist/css/token-inventory/types.js +1 -0
  45. package/dist/css/value-semantics/borderSemantics.d.ts +28 -0
  46. package/dist/css/value-semantics/borderSemantics.js +91 -0
  47. package/dist/css/value-semantics/boxSemantics.d.ts +37 -0
  48. package/dist/css/value-semantics/boxSemantics.js +71 -0
  49. package/dist/css/value-semantics/colorSemantics.d.ts +99 -0
  50. package/dist/css/value-semantics/colorSemantics.js +526 -0
  51. package/dist/css/value-semantics/cssSyntax.d.ts +19 -0
  52. package/dist/css/value-semantics/cssSyntax.js +111 -0
  53. package/dist/css/value-semantics/fontSemantics.d.ts +35 -0
  54. package/dist/css/value-semantics/fontSemantics.js +131 -0
  55. package/dist/css/value-semantics/index.d.ts +20 -0
  56. package/dist/css/value-semantics/index.js +15 -0
  57. package/dist/css/value-semantics/propertyPolicy.d.ts +118 -0
  58. package/dist/css/value-semantics/propertyPolicy.js +356 -0
  59. package/dist/css/value-semantics/stringMaps.d.ts +2 -0
  60. package/dist/css/value-semantics/stringMaps.js +1 -0
  61. package/dist/css/value-semantics/structuredValues.d.ts +64 -0
  62. package/dist/css/value-semantics/structuredValues.js +250 -0
  63. package/dist/css/value-semantics/tokenInterpretation.d.ts +90 -0
  64. package/dist/css/value-semantics/tokenInterpretation.js +193 -0
  65. package/dist/css/virtual-design-tokens.d.ts +17 -0
  66. package/dist/hosts/astro/astroRuntimeConfig.d.ts +12 -0
  67. package/dist/hosts/astro/astroRuntimeConfig.js +26 -0
  68. package/dist/hosts/astro/clientAsset.d.ts +12 -0
  69. package/dist/hosts/astro/clientAsset.js +51 -0
  70. package/dist/hosts/astro/clientTransport.d.ts +3 -0
  71. package/dist/hosts/astro/clientTransport.js +57 -0
  72. package/dist/hosts/astro/index.d.ts +3 -0
  73. package/dist/hosts/astro/index.js +2 -0
  74. package/dist/hosts/astro/integration.d.ts +35 -0
  75. package/dist/hosts/astro/integration.js +96 -0
  76. package/dist/hosts/astro/middleware.d.ts +13 -0
  77. package/dist/hosts/astro/middleware.js +22 -0
  78. package/dist/hosts/astro/projectContext.d.ts +11 -0
  79. package/dist/hosts/astro/projectContext.js +34 -0
  80. package/dist/hosts/astro/responseInstrumentation.d.ts +41 -0
  81. package/dist/hosts/astro/responseInstrumentation.js +80 -0
  82. package/dist/hosts/next/index.d.ts +4 -0
  83. package/dist/hosts/next/index.js +7 -0
  84. package/dist/hosts/next/loader.d.ts +66 -0
  85. package/dist/hosts/next/loader.js +346 -0
  86. package/dist/hosts/next/loaders/identity-loader.cjs +228257 -0
  87. package/dist/hosts/next/loaders/loader-plugin.cjs +228257 -0
  88. package/dist/hosts/next/manifest.d.ts +38 -0
  89. package/dist/hosts/next/manifest.js +30 -0
  90. package/dist/hosts/next/mount.d.ts +12 -0
  91. package/dist/hosts/next/mount.js +23 -0
  92. package/dist/hosts/next/repositoryScope.d.ts +20 -0
  93. package/dist/hosts/next/repositoryScope.js +33 -0
  94. package/dist/hosts/next/sidecar.d.ts +27 -0
  95. package/dist/hosts/next/sidecar.js +526 -0
  96. package/dist/hosts/next/wrapper.d.ts +67 -0
  97. package/dist/hosts/next/wrapper.js +310 -0
  98. package/dist/hosts/static/cli.d.ts +12 -0
  99. package/dist/hosts/static/cli.js +77 -0
  100. package/dist/hosts/static/html/bootstrap.d.ts +27 -0
  101. package/dist/hosts/static/html/bootstrap.js +93 -0
  102. package/dist/hosts/static/index.d.ts +4 -0
  103. package/dist/hosts/static/index.js +4 -0
  104. package/dist/hosts/static/manifest.d.ts +18 -0
  105. package/dist/hosts/static/manifest.js +51 -0
  106. package/dist/hosts/static/server.d.ts +72 -0
  107. package/dist/hosts/static/server.js +554 -0
  108. package/dist/hosts/vite/index.d.ts +20 -0
  109. package/dist/hosts/vite/index.js +48 -0
  110. package/dist/hosts/vite/react.d.ts +67 -0
  111. package/dist/hosts/vite/react.js +231 -0
  112. package/dist/hosts/vite/tokens/activeStylesheets.d.ts +28 -0
  113. package/dist/hosts/vite/tokens/activeStylesheets.js +70 -0
  114. package/dist/hosts/vite/tokens/fileMap.d.ts +2 -0
  115. package/dist/hosts/vite/tokens/fileMap.js +1 -0
  116. package/dist/hosts/vite/tokens/viteStylesheetArtifacts.d.ts +46 -0
  117. package/dist/hosts/vite/tokens/viteStylesheetArtifacts.js +104 -0
  118. package/dist/hosts/vite/virtual/design-tokens.d.ts +9 -0
  119. package/dist/hosts/vite/virtual/design-tokens.js +7 -0
  120. package/dist/hosts/vite/virtual-design-tokens.d.ts +1 -0
  121. package/dist/hosts/vite/vite.d.ts +62 -0
  122. package/dist/hosts/vite/vite.js +854 -0
  123. package/dist/html/dom.d.ts +13 -0
  124. package/dist/html/dom.js +46 -0
  125. package/dist/html/identity.d.ts +40 -0
  126. package/dist/html/identity.js +196 -0
  127. package/dist/html/insertions.d.ts +26 -0
  128. package/dist/html/insertions.js +59 -0
  129. package/dist/inspector/agent/McpConnectionDialog.d.ts +26 -0
  130. package/dist/inspector/agent/McpConnectionDialog.js +135 -0
  131. package/dist/inspector/agent/client.d.ts +98 -0
  132. package/dist/inspector/agent/client.js +728 -0
  133. package/dist/inspector/agent/connectionStatus.d.ts +13 -0
  134. package/dist/inspector/agent/connectionStatus.js +35 -0
  135. package/dist/inspector/agent/httpTransport.d.ts +21 -0
  136. package/dist/inspector/agent/httpTransport.js +347 -0
  137. package/dist/inspector/agent/protocol.d.ts +95 -0
  138. package/dist/inspector/agent/protocol.js +9 -0
  139. package/dist/inspector/agent/verification.d.ts +39 -0
  140. package/dist/inspector/agent/verification.js +207 -0
  141. package/dist/inspector/canvas/CanvasCard.d.ts +10 -0
  142. package/dist/inspector/canvas/CanvasCard.js +275 -0
  143. package/dist/inspector/canvas/CanvasElementOverlay.d.ts +2 -0
  144. package/dist/inspector/canvas/CanvasElementOverlay.js +301 -0
  145. package/dist/inspector/canvas/CanvasWorkspace.d.ts +2 -0
  146. package/dist/inspector/canvas/CanvasWorkspace.js +301 -0
  147. package/dist/inspector/canvas/LockedWorkspaceNotice.d.ts +6 -0
  148. package/dist/inspector/canvas/LockedWorkspaceNotice.js +17 -0
  149. package/dist/inspector/canvas/StaleChangeIndicator.d.ts +7 -0
  150. package/dist/inspector/canvas/StaleChangeIndicator.js +43 -0
  151. package/dist/inspector/canvas/agentPresentation.d.ts +87 -0
  152. package/dist/inspector/canvas/agentPresentation.js +421 -0
  153. package/dist/inspector/canvas/canvasGestures.d.ts +12 -0
  154. package/dist/inspector/canvas/canvasGestures.js +21 -0
  155. package/dist/inspector/canvas/canvasStore.d.ts +108 -0
  156. package/dist/inspector/canvas/canvasStore.js +448 -0
  157. package/dist/inspector/canvas/frameProtocol.d.ts +231 -0
  158. package/dist/inspector/canvas/frameProtocol.js +165 -0
  159. package/dist/inspector/canvas/linkEligibility.d.ts +8 -0
  160. package/dist/inspector/canvas/linkEligibility.js +68 -0
  161. package/dist/inspector/canvas/measurementProjection.d.ts +8 -0
  162. package/dist/inspector/canvas/measurementProjection.js +16 -0
  163. package/dist/inspector/canvas/normalizeUrl.d.ts +7 -0
  164. package/dist/inspector/canvas/normalizeUrl.js +27 -0
  165. package/dist/inspector/canvas/projection.d.ts +41 -0
  166. package/dist/inspector/canvas/projection.js +232 -0
  167. package/dist/inspector/canvas/rendererBootstrap.d.ts +4 -0
  168. package/dist/inspector/canvas/rendererBootstrap.js +410 -0
  169. package/dist/inspector/canvas/rendererCidIndex.d.ts +11 -0
  170. package/dist/inspector/canvas/rendererCidIndex.js +21 -0
  171. package/dist/inspector/canvas/rendererElementSelector.d.ts +2 -0
  172. package/dist/inspector/canvas/rendererElementSelector.js +378 -0
  173. package/dist/inspector/canvas/rendererSelectionProxy.d.ts +2 -0
  174. package/dist/inspector/canvas/rendererSelectionProxy.js +61 -0
  175. package/dist/inspector/canvas/rendererStylesheet.d.ts +16 -0
  176. package/dist/inspector/canvas/rendererStylesheet.js +221 -0
  177. package/dist/inspector/canvas/resizeHandleScale.d.ts +13 -0
  178. package/dist/inspector/canvas/resizeHandleScale.js +20 -0
  179. package/dist/inspector/canvas/roleDetection.d.ts +5 -0
  180. package/dist/inspector/canvas/roleDetection.js +21 -0
  181. package/dist/inspector/canvas/sessionStore.d.ts +71 -0
  182. package/dist/inspector/canvas/sessionStore.js +453 -0
  183. package/dist/inspector/canvas/staleChangeDetector.d.ts +11 -0
  184. package/dist/inspector/canvas/staleChangeDetector.js +217 -0
  185. package/dist/inspector/canvas/toolbarScale.d.ts +7 -0
  186. package/dist/inspector/canvas/toolbarScale.js +11 -0
  187. package/dist/inspector/canvas/workspaceLease.d.ts +26 -0
  188. package/dist/inspector/canvas/workspaceLease.js +214 -0
  189. package/dist/inspector/changes/changesLog.d.ts +46 -0
  190. package/dist/inspector/changes/changesLog.js +209 -0
  191. package/dist/inspector/changes/codecs.d.ts +98 -0
  192. package/dist/inspector/changes/codecs.js +389 -0
  193. package/dist/inspector/changes/editModel.d.ts +74 -0
  194. package/dist/inspector/changes/editModel.js +120 -0
  195. package/dist/inspector/changes/managedStyleProjection.d.ts +6 -0
  196. package/dist/inspector/changes/managedStyleProjection.js +109 -0
  197. package/dist/inspector/changes/model.d.ts +13 -0
  198. package/dist/inspector/changes/model.js +163 -0
  199. package/dist/inspector/changes/presentation.d.ts +14 -0
  200. package/dist/inspector/changes/presentation.js +81 -0
  201. package/dist/inspector/changes/previewDiagnostics.d.ts +39 -0
  202. package/dist/inspector/changes/previewDiagnostics.js +172 -0
  203. package/dist/inspector/changes/structuralTypes.d.ts +35 -0
  204. package/dist/inspector/changes/structuralTypes.js +1 -0
  205. package/dist/inspector/changes/types.d.ts +76 -0
  206. package/dist/inspector/changes/types.js +16 -0
  207. package/dist/inspector/changes/workspaceChanges.d.ts +43 -0
  208. package/dist/inspector/changes/workspaceChanges.js +239 -0
  209. package/dist/inspector/clientManifest.d.ts +24 -0
  210. package/dist/inspector/clientManifest.js +69 -0
  211. package/dist/inspector/componentSemantics/ComponentPropsSection.d.ts +5 -0
  212. package/dist/inspector/componentSemantics/ComponentPropsSection.js +44 -0
  213. package/dist/inspector/componentSemantics/adapterRegistry.d.ts +11 -0
  214. package/dist/inspector/componentSemantics/adapterRegistry.js +75 -0
  215. package/dist/inspector/componentSemantics/boundaries.d.ts +2 -0
  216. package/dist/inspector/componentSemantics/boundaries.js +10 -0
  217. package/dist/inspector/componentSemantics/changeAction.d.ts +3 -0
  218. package/dist/inspector/componentSemantics/changeAction.js +6 -0
  219. package/dist/inspector/componentSemantics/changeModel.d.ts +8 -0
  220. package/dist/inspector/componentSemantics/changeModel.js +60 -0
  221. package/dist/inspector/componentSemantics/index.d.ts +4 -0
  222. package/dist/inspector/componentSemantics/index.js +2 -0
  223. package/dist/inspector/componentSemantics/reactRuntime.d.ts +10 -0
  224. package/dist/inspector/componentSemantics/reactRuntime.js +186 -0
  225. package/dist/inspector/componentSemantics/runtimeBridge.d.ts +25 -0
  226. package/dist/inspector/componentSemantics/runtimeBridge.js +161 -0
  227. package/dist/inspector/componentSemantics/runtimeTypes.d.ts +2 -0
  228. package/dist/inspector/componentSemantics/runtimeTypes.js +1 -0
  229. package/dist/inspector/componentSemantics/textBinding.d.ts +69 -0
  230. package/dist/inspector/componentSemantics/textBinding.js +514 -0
  231. package/dist/inspector/componentSemantics/types.d.ts +96 -0
  232. package/dist/inspector/componentSemantics/types.js +5 -0
  233. package/dist/inspector/conformance/borderCases.d.ts +7 -0
  234. package/dist/inspector/conformance/borderCases.js +428 -0
  235. package/dist/inspector/conformance/colorCases.d.ts +8 -0
  236. package/dist/inspector/conformance/colorCases.js +470 -0
  237. package/dist/inspector/conformance/fixture.d.ts +68 -0
  238. package/dist/inspector/conformance/fixture.js +153 -0
  239. package/dist/inspector/conformance/projection.d.ts +2 -0
  240. package/dist/inspector/conformance/projection.js +3 -0
  241. package/dist/inspector/conformance/spacingCases.d.ts +6 -0
  242. package/dist/inspector/conformance/spacingCases.js +417 -0
  243. package/dist/inspector/conformance/typographyCases.d.ts +7 -0
  244. package/dist/inspector/conformance/typographyCases.js +174 -0
  245. package/dist/inspector/editScope.d.ts +4 -0
  246. package/dist/inspector/editScope.js +5 -0
  247. package/dist/inspector/index.d.ts +20 -0
  248. package/dist/inspector/index.js +236 -0
  249. package/dist/inspector/inline-text/inlineTextEditor.d.ts +74 -0
  250. package/dist/inspector/inline-text/inlineTextEditor.js +1207 -0
  251. package/dist/inspector/inline-text/inlineTextLifecycle.d.ts +2 -0
  252. package/dist/inspector/inline-text/inlineTextLifecycle.js +17 -0
  253. package/dist/inspector/inline-text/textChangeBoundary.d.ts +6 -0
  254. package/dist/inspector/inline-text/textChangeBoundary.js +1 -0
  255. package/dist/inspector/inspection/bridge.d.ts +72 -0
  256. package/dist/inspector/inspection/bridge.js +134 -0
  257. package/dist/inspector/inspection/browserCssInspection.d.ts +74 -0
  258. package/dist/inspector/inspection/browserCssInspection.js +317 -0
  259. package/dist/inspector/inspection/browserCssInspectionRegistry.d.ts +12 -0
  260. package/dist/inspector/inspection/browserCssInspectionRegistry.js +66 -0
  261. package/dist/inspector/inspection/selectionProperty.d.ts +32 -0
  262. package/dist/inspector/inspection/selectionProperty.js +33 -0
  263. package/dist/inspector/inspection/useBrowserCssInspection.d.ts +20 -0
  264. package/dist/inspector/inspection/useBrowserCssInspection.js +159 -0
  265. package/dist/inspector/overlay/DropGuideOverlay.d.ts +17 -0
  266. package/dist/inspector/overlay/DropGuideOverlay.js +17 -0
  267. package/dist/inspector/overlay/InspectorOverlay.d.ts +5 -0
  268. package/dist/inspector/overlay/InspectorOverlay.js +328 -0
  269. package/dist/inspector/overlay/MeasurementGuideOverlay.d.ts +19 -0
  270. package/dist/inspector/overlay/MeasurementGuideOverlay.js +40 -0
  271. package/dist/inspector/overlay/clickPolicy.d.ts +7 -0
  272. package/dist/inspector/overlay/clickPolicy.js +13 -0
  273. package/dist/inspector/overlay/dropGuide.d.ts +22 -0
  274. package/dist/inspector/overlay/dropGuide.js +48 -0
  275. package/dist/inspector/overlay/elementSelector.d.ts +1 -0
  276. package/dist/inspector/overlay/elementSelector.js +100 -0
  277. package/dist/inspector/overlay/frameThrottle.d.ts +10 -0
  278. package/dist/inspector/overlay/frameThrottle.js +38 -0
  279. package/dist/inspector/overlay/interactionStyles.d.ts +3 -0
  280. package/dist/inspector/overlay/interactionStyles.js +70 -0
  281. package/dist/inspector/overlay/measurementGeometry.d.ts +25 -0
  282. package/dist/inspector/overlay/measurementGeometry.js +104 -0
  283. package/dist/inspector/overlay/overlayGeometry.d.ts +40 -0
  284. package/dist/inspector/overlay/overlayGeometry.js +59 -0
  285. package/dist/inspector/overlay/selectedGeometry.d.ts +7 -0
  286. package/dist/inspector/overlay/selectedGeometry.js +51 -0
  287. package/dist/inspector/overlay/structuralGestures.d.ts +28 -0
  288. package/dist/inspector/overlay/structuralGestures.js +180 -0
  289. package/dist/inspector/projection/cssEscapes.d.ts +3 -0
  290. package/dist/inspector/projection/cssEscapes.js +20 -0
  291. package/dist/inspector/projection/managedStylesheet.d.ts +33 -0
  292. package/dist/inspector/projection/managedStylesheet.js +240 -0
  293. package/dist/inspector/projection/renderedInstance.d.ts +56 -0
  294. package/dist/inspector/projection/renderedInstance.js +306 -0
  295. package/dist/inspector/projection/structuralProjection.d.ts +93 -0
  296. package/dist/inspector/projection/structuralProjection.js +560 -0
  297. package/dist/inspector/projection/structuralProjectionBoundary.d.ts +5 -0
  298. package/dist/inspector/projection/structuralProjectionBoundary.js +65 -0
  299. package/dist/inspector/projection/textProjection.d.ts +53 -0
  300. package/dist/inspector/projection/textProjection.js +705 -0
  301. package/dist/inspector/projection/workspaceProjection.d.ts +43 -0
  302. package/dist/inspector/projection/workspaceProjection.js +58 -0
  303. package/dist/inspector/prompt/PromptSettingsDialog.d.ts +15 -0
  304. package/dist/inspector/prompt/PromptSettingsDialog.js +17 -0
  305. package/dist/inspector/prompt/clipboardHandoff.d.ts +34 -0
  306. package/dist/inspector/prompt/clipboardHandoff.js +212 -0
  307. package/dist/inspector/prompt/copyToClipboard.d.ts +1 -0
  308. package/dist/inspector/prompt/copyToClipboard.js +34 -0
  309. package/dist/inspector/prompt/detectFramework.d.ts +6 -0
  310. package/dist/inspector/prompt/detectFramework.js +4 -0
  311. package/dist/inspector/prompt/generatePrompt.d.ts +7 -0
  312. package/dist/inspector/prompt/generatePrompt.js +391 -0
  313. package/dist/inspector/prompt/promptSettings.d.ts +8 -0
  314. package/dist/inspector/prompt/promptSettings.js +28 -0
  315. package/dist/inspector/runtime/devFlag.d.ts +28 -0
  316. package/dist/inspector/runtime/devFlag.js +50 -0
  317. package/dist/inspector/runtime/documentStylesheetOrder.d.ts +19 -0
  318. package/dist/inspector/runtime/documentStylesheetOrder.js +89 -0
  319. package/dist/inspector/runtime/domRealm.d.ts +4 -0
  320. package/dist/inspector/runtime/domRealm.js +11 -0
  321. package/dist/inspector/runtime/runtimeConfig.d.ts +119 -0
  322. package/dist/inspector/runtime/runtimeConfig.js +276 -0
  323. package/dist/inspector/runtime/staticHtmlRuntimeIdentity.d.ts +32 -0
  324. package/dist/inspector/runtime/staticHtmlRuntimeIdentity.js +149 -0
  325. package/dist/inspector/runtime/useRuntimeConfig.d.ts +10 -0
  326. package/dist/inspector/runtime/useRuntimeConfig.js +13 -0
  327. package/dist/inspector/selection/editScope.d.ts +32 -0
  328. package/dist/inspector/selection/editScope.js +140 -0
  329. package/dist/inspector/selection/editTarget.d.ts +8 -0
  330. package/dist/inspector/selection/editTarget.js +11 -0
  331. package/dist/inspector/selection/hierarchy.d.ts +7 -0
  332. package/dist/inspector/selection/hierarchy.js +42 -0
  333. package/dist/inspector/selection/resolveSelection.d.ts +10 -0
  334. package/dist/inspector/selection/resolveSelection.js +60 -0
  335. package/dist/inspector/selection/selectionStore.d.ts +41 -0
  336. package/dist/inspector/selection/selectionStore.js +262 -0
  337. package/dist/inspector/selection/selectionTarget.d.ts +5 -0
  338. package/dist/inspector/selection/selectionTarget.js +50 -0
  339. package/dist/inspector/selection/sourceSite.d.ts +2 -0
  340. package/dist/inspector/selection/sourceSite.js +12 -0
  341. package/dist/inspector/selection/styleSelection.d.ts +22 -0
  342. package/dist/inspector/selection/styleSelection.js +104 -0
  343. package/dist/inspector/session/index.d.ts +3 -0
  344. package/dist/inspector/session/index.js +2 -0
  345. package/dist/inspector/session/lifecycle.d.ts +22 -0
  346. package/dist/inspector/session/lifecycle.js +63 -0
  347. package/dist/inspector/session/sessionContext.d.ts +21 -0
  348. package/dist/inspector/session/sessionContext.js +28 -0
  349. package/dist/inspector/session/sessionFactory.d.ts +29 -0
  350. package/dist/inspector/session/sessionFactory.js +73 -0
  351. package/dist/inspector/settings/SettingsDialog.d.ts +12 -0
  352. package/dist/inspector/settings/SettingsDialog.js +46 -0
  353. package/dist/inspector/shell/AppShell.d.ts +2 -0
  354. package/dist/inspector/shell/AppShell.js +9 -0
  355. package/dist/inspector/shell/ChangesLog.d.ts +6 -0
  356. package/dist/inspector/shell/ChangesLog.js +92 -0
  357. package/dist/inspector/shell/CopyPromptButton.d.ts +9 -0
  358. package/dist/inspector/shell/CopyPromptButton.js +159 -0
  359. package/dist/inspector/shell/DomNavigation.d.ts +8 -0
  360. package/dist/inspector/shell/DomNavigation.js +30 -0
  361. package/dist/inspector/shell/EmptyState.d.ts +2 -0
  362. package/dist/inspector/shell/EmptyState.js +15 -0
  363. package/dist/inspector/shell/InspectorShell.d.ts +11 -0
  364. package/dist/inspector/shell/InspectorShell.js +268 -0
  365. package/dist/inspector/shell/openStore.d.ts +6 -0
  366. package/dist/inspector/shell/openStore.js +29 -0
  367. package/dist/inspector/shell/panelLayout.d.ts +2 -0
  368. package/dist/inspector/shell/panelLayout.js +29 -0
  369. package/dist/inspector/shell/shortcuts.d.ts +3 -0
  370. package/dist/inspector/shell/shortcuts.js +25 -0
  371. package/dist/inspector/shell/stateValue.d.ts +3 -0
  372. package/dist/inspector/shell/stateValue.js +34 -0
  373. package/dist/inspector/shell/styleState.d.ts +7 -0
  374. package/dist/inspector/shell/styleState.js +13 -0
  375. package/dist/inspector/spacing/projection.d.ts +43 -0
  376. package/dist/inspector/spacing/projection.js +136 -0
  377. package/dist/inspector/styleEditors/AppearanceSection.d.ts +13 -0
  378. package/dist/inspector/styleEditors/AppearanceSection.js +6 -0
  379. package/dist/inspector/styleEditors/AspectRatioField.d.ts +17 -0
  380. package/dist/inspector/styleEditors/AspectRatioField.js +10 -0
  381. package/dist/inspector/styleEditors/BorderEditor.d.ts +13 -0
  382. package/dist/inspector/styleEditors/BorderEditor.js +295 -0
  383. package/dist/inspector/styleEditors/BorderRadiusEditor.d.ts +14 -0
  384. package/dist/inspector/styleEditors/BorderRadiusEditor.js +108 -0
  385. package/dist/inspector/styleEditors/BoxShadowEditor.d.ts +13 -0
  386. package/dist/inspector/styleEditors/BoxShadowEditor.js +13 -0
  387. package/dist/inspector/styleEditors/ColorPicker.d.ts +15 -0
  388. package/dist/inspector/styleEditors/ColorPicker.js +73 -0
  389. package/dist/inspector/styleEditors/GapField.d.ts +17 -0
  390. package/dist/inspector/styleEditors/GapField.js +12 -0
  391. package/dist/inspector/styleEditors/GridChildSection.d.ts +14 -0
  392. package/dist/inspector/styleEditors/GridChildSection.js +91 -0
  393. package/dist/inspector/styleEditors/GridPicker.d.ts +13 -0
  394. package/dist/inspector/styleEditors/GridPicker.js +179 -0
  395. package/dist/inspector/styleEditors/GridSection.d.ts +17 -0
  396. package/dist/inspector/styleEditors/GridSection.js +27 -0
  397. package/dist/inspector/styleEditors/GridValueField.d.ts +17 -0
  398. package/dist/inspector/styleEditors/GridValueField.js +70 -0
  399. package/dist/inspector/styleEditors/InsetSection.d.ts +15 -0
  400. package/dist/inspector/styleEditors/InsetSection.js +15 -0
  401. package/dist/inspector/styleEditors/LayoutBlockedIndicator.d.ts +6 -0
  402. package/dist/inspector/styleEditors/LayoutBlockedIndicator.js +6 -0
  403. package/dist/inspector/styleEditors/LayoutComboField.d.ts +18 -0
  404. package/dist/inspector/styleEditors/LayoutComboField.js +138 -0
  405. package/dist/inspector/styleEditors/LayoutDropdown.d.ts +14 -0
  406. package/dist/inspector/styleEditors/LayoutDropdown.js +34 -0
  407. package/dist/inspector/styleEditors/LayoutSection.d.ts +13 -0
  408. package/dist/inspector/styleEditors/LayoutSection.js +342 -0
  409. package/dist/inspector/styleEditors/OpacityEditor.d.ts +13 -0
  410. package/dist/inspector/styleEditors/OpacityEditor.js +34 -0
  411. package/dist/inspector/styleEditors/PositionInsets.d.ts +15 -0
  412. package/dist/inspector/styleEditors/PositionInsets.js +12 -0
  413. package/dist/inspector/styleEditors/SpacingBox.d.ts +29 -0
  414. package/dist/inspector/styleEditors/SpacingBox.js +189 -0
  415. package/dist/inspector/styleEditors/Typography.d.ts +13 -0
  416. package/dist/inspector/styleEditors/Typography.js +137 -0
  417. package/dist/inspector/styleEditors/completeCssValue.d.ts +8 -0
  418. package/dist/inspector/styleEditors/completeCssValue.js +34 -0
  419. package/dist/inspector/styleEditors/gridChildModel.d.ts +74 -0
  420. package/dist/inspector/styleEditors/gridChildModel.js +138 -0
  421. package/dist/inspector/styleEditors/layoutValue.d.ts +24 -0
  422. package/dist/inspector/styleEditors/layoutValue.js +103 -0
  423. package/dist/inspector/styleEditors/nudgeValue.d.ts +8 -0
  424. package/dist/inspector/styleEditors/nudgeValue.js +71 -0
  425. package/dist/inspector/styleEditors/rowLookup.d.ts +11 -0
  426. package/dist/inspector/styleEditors/rowLookup.js +13 -0
  427. package/dist/inspector/styleEditors/stringRecord.d.ts +4 -0
  428. package/dist/inspector/styleEditors/stringRecord.js +1 -0
  429. package/dist/inspector/styleEditors/valuePolicy.d.ts +20 -0
  430. package/dist/inspector/styleEditors/valuePolicy.js +82 -0
  431. package/dist/inspector/testing.d.ts +10 -0
  432. package/dist/inspector/testing.js +9 -0
  433. package/dist/inspector/tokens/TokenChip.d.ts +24 -0
  434. package/dist/inspector/tokens/TokenChip.js +23 -0
  435. package/dist/inspector/tokens/TokenDropdown.d.ts +13 -0
  436. package/dist/inspector/tokens/TokenDropdown.js +59 -0
  437. package/dist/inspector/tokens/TokenField.d.ts +68 -0
  438. package/dist/inspector/tokens/TokenField.js +485 -0
  439. package/dist/inspector/tokens/TokenLabel.d.ts +7 -0
  440. package/dist/inspector/tokens/TokenLabel.js +23 -0
  441. package/dist/inspector/tokens/TokensPanel.d.ts +5 -0
  442. package/dist/inspector/tokens/TokensPanel.js +47 -0
  443. package/dist/inspector/tokens/catalog.d.ts +51 -0
  444. package/dist/inspector/tokens/catalog.js +184 -0
  445. package/dist/inspector/tokens/editActions.d.ts +35 -0
  446. package/dist/inspector/tokens/editActions.js +164 -0
  447. package/dist/inspector/tokens/resolution/cascade.d.ts +14 -0
  448. package/dist/inspector/tokens/resolution/cascade.js +31 -0
  449. package/dist/inspector/tokens/resolution/cssomCollector.d.ts +43 -0
  450. package/dist/inspector/tokens/resolution/cssomCollector.js +528 -0
  451. package/dist/inspector/tokens/resolution/selectorSemantics.d.ts +12 -0
  452. package/dist/inspector/tokens/resolution/selectorSemantics.js +106 -0
  453. package/dist/inspector/tokens/resolution.d.ts +56 -0
  454. package/dist/inspector/tokens/resolution.js +1401 -0
  455. package/dist/inspector/tokens/tokenEdits.d.ts +3 -0
  456. package/dist/inspector/tokens/tokenEdits.js +22 -0
  457. package/dist/inspector/tokens/valueSemanticsAdapter.d.ts +6 -0
  458. package/dist/inspector/tokens/valueSemanticsAdapter.js +68 -0
  459. package/dist/inspector/ui/AtRuleContext.d.ts +18 -0
  460. package/dist/inspector/ui/AtRuleContext.js +54 -0
  461. package/dist/inspector/ui/Button.d.ts +9 -0
  462. package/dist/inspector/ui/Button.js +4 -0
  463. package/dist/inspector/ui/ColorSwatch.d.ts +7 -0
  464. package/dist/inspector/ui/ColorSwatch.js +6 -0
  465. package/dist/inspector/ui/ControlSurface.d.ts +14 -0
  466. package/dist/inspector/ui/ControlSurface.js +10 -0
  467. package/dist/inspector/ui/FieldRow.d.ts +14 -0
  468. package/dist/inspector/ui/FieldRow.js +15 -0
  469. package/dist/inspector/ui/IconButton.d.ts +14 -0
  470. package/dist/inspector/ui/IconButton.js +5 -0
  471. package/dist/inspector/ui/InspectorPopover.d.ts +17 -0
  472. package/dist/inspector/ui/InspectorPopover.js +13 -0
  473. package/dist/inspector/ui/PopoverListbox.d.ts +37 -0
  474. package/dist/inspector/ui/PopoverListbox.js +21 -0
  475. package/dist/inspector/ui/SegmentedControl.d.ts +24 -0
  476. package/dist/inspector/ui/SegmentedControl.js +16 -0
  477. package/dist/inspector/ui/Select.d.ts +25 -0
  478. package/dist/inspector/ui/Select.js +56 -0
  479. package/dist/inspector/ui/SideValuesField.d.ts +44 -0
  480. package/dist/inspector/ui/SideValuesField.js +76 -0
  481. package/dist/inspector/ui/StatusCallout.d.ts +9 -0
  482. package/dist/inspector/ui/StatusCallout.js +4 -0
  483. package/dist/inspector/ui/TextInput.d.ts +12 -0
  484. package/dist/inspector/ui/TextInput.js +5 -0
  485. package/dist/inspector/ui/ToggleButton.d.ts +11 -0
  486. package/dist/inspector/ui/ToggleButton.js +6 -0
  487. package/dist/inspector/ui/assets/grid.svg +14 -0
  488. package/dist/inspector/ui/css.d.ts +9 -0
  489. package/dist/inspector/ui/labels.d.ts +1 -0
  490. package/dist/inspector/ui/labels.js +7 -0
  491. package/dist/inspector/ui/styles.d.ts +1 -0
  492. package/dist/inspector/ui/styles.js +68 -0
  493. package/dist/inspector/virtual-modules.d.ts +7 -0
  494. package/dist/inspector/vite-env.d.ts +10 -0
  495. package/dist/internal/agent-protocol.d.ts +232 -0
  496. package/dist/internal/agent-protocol.js +237 -0
  497. package/dist/nudge-ui.mjs +15722 -0
  498. package/dist/project/files.d.ts +19 -0
  499. package/dist/project/files.js +226 -0
  500. package/dist/project/identity.d.ts +6 -0
  501. package/dist/project/identity.js +19 -0
  502. package/dist/project/pathPolicy.d.ts +8 -0
  503. package/dist/project/pathPolicy.js +12 -0
  504. package/dist/project/tokens.d.ts +36 -0
  505. package/dist/project/tokens.js +223 -0
  506. package/dist/transport/index.d.ts +8 -0
  507. package/dist/transport/index.js +8 -0
  508. package/dist/transport/routes.d.ts +13 -0
  509. package/dist/transport/routes.js +16 -0
  510. package/package.json +137 -0
@@ -0,0 +1,728 @@
1
+ import { useEffect, useMemo, useSyncExternalStore } from "react";
2
+ import { isNudgeUiDev } from "../runtime/devFlag.js";
3
+ import { isDemoRuntime } from "../runtime/runtimeConfig.js";
4
+ import { HttpAgentBridgeTransport } from "./httpTransport.js";
5
+ import { AGENT_PROTOCOL_VERSION, } from "./protocol.js";
6
+ const DISABLED_SNAPSHOT = Object.freeze({
7
+ state: "disabled",
8
+ connection: "offline",
9
+ listenerActive: false,
10
+ companionReachable: false,
11
+ paired: false,
12
+ request: null,
13
+ });
14
+ const DEFAULT_DISCOVERY_INTERVAL_MS = 2_000;
15
+ const SESSION_STORAGE_PREFIX = "nudge-ui-agent-session:";
16
+ function randomId(prefix) {
17
+ const random = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function"
18
+ ? crypto.randomUUID()
19
+ : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
20
+ return `${prefix}-${random}`;
21
+ }
22
+ function errorMessage(error, fallback) {
23
+ return error instanceof Error && error.message ? error.message : fallback;
24
+ }
25
+ function sessionStorageKey(projectId) {
26
+ return `${SESSION_STORAGE_PREFIX}${encodeURIComponent(projectId)}`;
27
+ }
28
+ function readStoredSession(projectId, origin) {
29
+ if (typeof localStorage === "undefined")
30
+ return null;
31
+ try {
32
+ const raw = localStorage.getItem(sessionStorageKey(projectId));
33
+ if (!raw)
34
+ return null;
35
+ const parsed = JSON.parse(raw);
36
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
37
+ return null;
38
+ // SAFETY: The typeof/Array.isArray guard above proves parsed is a non-array object with string keys.
39
+ const value = parsed;
40
+ if (value.projectId !== projectId || value.origin !== origin || typeof value.sessionToken !== "string" || value.sessionToken.length === 0) {
41
+ localStorage.removeItem(sessionStorageKey(projectId));
42
+ return null;
43
+ }
44
+ return value.sessionToken;
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ }
50
+ function writeStoredSession(session) {
51
+ if (typeof localStorage === "undefined")
52
+ return;
53
+ try {
54
+ localStorage.setItem(sessionStorageKey(session.projectId), JSON.stringify(session));
55
+ }
56
+ catch {
57
+ // Storage can be disabled by browser privacy settings. The in-memory
58
+ // pairing remains valid for this document in that case.
59
+ }
60
+ }
61
+ function clearStoredSession(projectId) {
62
+ if (typeof localStorage === "undefined")
63
+ return;
64
+ try {
65
+ localStorage.removeItem(sessionStorageKey(projectId));
66
+ }
67
+ catch {
68
+ // Ignore storage failures; disconnect still clears the live connection.
69
+ }
70
+ }
71
+ function statusForConnection(status) {
72
+ if (status.connection === "working" || status.request?.status === "working")
73
+ return "working";
74
+ if (status.paired)
75
+ return "paired";
76
+ if (status.listenerActive)
77
+ return "listening";
78
+ return "offline";
79
+ }
80
+ function hashRevision(value) {
81
+ // FNV-1a is sufficient here: the revision is an opaque, bounded identity
82
+ // used to prevent a later browser edit from being mistaken for the sent
83
+ // canonical change set. Keep it in the safe-integer range accepted by the
84
+ // companion protocol.
85
+ let hash = 2_166_136_261;
86
+ for (let index = 0; index < value.length; index += 1) {
87
+ hash ^= value.charCodeAt(index);
88
+ hash = Math.imul(hash, 16_777_619);
89
+ }
90
+ return (hash >>> 0) & 0x7fff_ffff;
91
+ }
92
+ /** Creates a stable numeric revision for one prompt snapshot. */
93
+ export function createPromptRevision(changes, structuralChanges = []) {
94
+ let serialized;
95
+ try {
96
+ serialized = JSON.stringify({ changes, structuralChanges }) ?? "";
97
+ }
98
+ catch {
99
+ serialized = `${changes.length}:${structuralChanges.length}`;
100
+ }
101
+ return hashRevision(serialized);
102
+ }
103
+ /**
104
+ * Browser-side companion client.
105
+ *
106
+ * Discovery is deliberately started by `start()`, which is guarded by the
107
+ * dev-only flag. Constructing this class never opens a socket or performs a
108
+ * network request, so importing the inspector remains inert in production.
109
+ */
110
+ export class AgentClient {
111
+ projectId;
112
+ origin;
113
+ transport;
114
+ discoveryIntervalMs;
115
+ enabled;
116
+ canvasCommandHandler;
117
+ listeners = new Set();
118
+ snapshot;
119
+ sessionToken = null;
120
+ activeRequest = null;
121
+ discoveryTimer = null;
122
+ discoveryAbort = null;
123
+ pairingAbort = null;
124
+ dispatchAbort = null;
125
+ eventSubscription = null;
126
+ started = false;
127
+ connection = "offline";
128
+ listenerActive = false;
129
+ companionReachable = false;
130
+ paired = false;
131
+ lastError;
132
+ constructor(options) {
133
+ this.projectId = options.projectId;
134
+ this.origin = options.origin ?? (typeof window !== "undefined" ? window.location.origin : "http://localhost");
135
+ this.transport = options.transport ?? new HttpAgentBridgeTransport(options.endpoint);
136
+ this.discoveryIntervalMs = options.discoveryIntervalMs ?? DEFAULT_DISCOVERY_INTERVAL_MS;
137
+ this.canvasCommandHandler = options.canvasCommandHandler;
138
+ // The public demo renders the real inspector but intentionally keeps the
139
+ // local MCP/agent bridge inert.
140
+ this.enabled = isNudgeUiDev() && !isDemoRuntime();
141
+ this.snapshot = this.enabled ? this.makeSnapshot() : DISABLED_SNAPSHOT;
142
+ }
143
+ /** Installs the controller callback used to acknowledge Canvas commands. */
144
+ setCanvasCommandHandler(handler) {
145
+ this.canvasCommandHandler = handler;
146
+ }
147
+ getSnapshot = () => this.snapshot;
148
+ subscribe = (listener) => {
149
+ this.listeners.add(listener);
150
+ return () => this.listeners.delete(listener);
151
+ };
152
+ /** Starts loopback discovery. Calling it repeatedly is idempotent. */
153
+ start() {
154
+ if (!this.enabled || this.started)
155
+ return;
156
+ this.started = true;
157
+ void this.restoreOrDiscover();
158
+ }
159
+ /** Stops discovery and closes the browser event stream. */
160
+ stop() {
161
+ if (!this.started && !this.eventSubscription)
162
+ return;
163
+ this.started = false;
164
+ if (this.discoveryTimer !== null) {
165
+ clearTimeout(this.discoveryTimer);
166
+ this.discoveryTimer = null;
167
+ }
168
+ this.discoveryAbort?.abort();
169
+ this.discoveryAbort = null;
170
+ this.pairingAbort?.abort();
171
+ this.pairingAbort = null;
172
+ this.dispatchAbort?.abort();
173
+ this.dispatchAbort = null;
174
+ this.eventSubscription?.close();
175
+ this.eventSubscription = null;
176
+ // `stop` is used by React effect cleanup and page remounts. Keep the
177
+ // request and ephemeral token in memory/storage so a still-running
178
+ // companion can be resumed; explicit `disconnect()` is the revocation
179
+ // and interruption path.
180
+ this.connection = "offline";
181
+ this.listenerActive = false;
182
+ this.companionReachable = false;
183
+ this.paired = false;
184
+ this.publish();
185
+ }
186
+ async restoreOrDiscover() {
187
+ if (!this.started || !this.enabled || this.pairingAbort)
188
+ return;
189
+ const token = this.sessionToken ?? readStoredSession(this.projectId, this.origin);
190
+ if (token && this.transport.restore) {
191
+ const abortController = new AbortController();
192
+ this.discoveryAbort?.abort();
193
+ this.discoveryAbort = abortController;
194
+ try {
195
+ const status = await this.transport.restore({
196
+ projectId: this.projectId,
197
+ origin: this.origin,
198
+ sessionToken: token,
199
+ }, abortController.signal);
200
+ if (!this.started || abortController.signal.aborted)
201
+ return;
202
+ if (status?.paired) {
203
+ this.sessionToken = token;
204
+ this.connection = "paired";
205
+ this.paired = true;
206
+ this.openEvents(token);
207
+ this.applyStatus(status);
208
+ return;
209
+ }
210
+ clearStoredSession(this.projectId);
211
+ this.sessionToken = null;
212
+ this.resetForDiscovery();
213
+ }
214
+ catch (error) {
215
+ if (abortController.signal.aborted || !this.started)
216
+ return;
217
+ // A stale or revoked token is not a connection error. Clearing it
218
+ // lets the normal listener discovery path offer a fresh pairing.
219
+ clearStoredSession(this.projectId);
220
+ this.sessionToken = null;
221
+ this.resetForDiscovery();
222
+ void error;
223
+ }
224
+ finally {
225
+ if (this.discoveryAbort === abortController)
226
+ this.discoveryAbort = null;
227
+ }
228
+ }
229
+ await this.discover();
230
+ }
231
+ /** Runs an immediate authenticated restore or companion discovery probe. */
232
+ async checkConnection() {
233
+ if (!this.enabled)
234
+ return;
235
+ if (!this.started)
236
+ this.start();
237
+ if (!this.started || this.pairingAbort)
238
+ return;
239
+ if (this.discoveryTimer !== null) {
240
+ clearTimeout(this.discoveryTimer);
241
+ this.discoveryTimer = null;
242
+ }
243
+ this.lastError = undefined;
244
+ this.publish();
245
+ await this.restoreOrDiscover();
246
+ }
247
+ /** Triggers a new discovery probe after a connection loss. */
248
+ reconnect() {
249
+ if (!this.enabled)
250
+ return;
251
+ if (!this.started) {
252
+ this.start();
253
+ return;
254
+ }
255
+ this.eventSubscription?.close();
256
+ this.eventSubscription = null;
257
+ this.discoveryAbort?.abort();
258
+ this.pairingAbort?.abort();
259
+ this.pairingAbort = null;
260
+ this.connection = "offline";
261
+ this.listenerActive = false;
262
+ this.companionReachable = false;
263
+ this.paired = false;
264
+ this.lastError = undefined;
265
+ this.publish();
266
+ void this.restoreOrDiscover();
267
+ }
268
+ /** Pairs the browser with a reachable companion, including an idle agent. */
269
+ async connect() {
270
+ if (!this.enabled || !this.started || this.pairingAbort || this.paired || !this.companionReachable)
271
+ return false;
272
+ if (this.connection === "working" || this.activeRequest?.status === "working")
273
+ return false;
274
+ const idleListenerActive = this.listenerActive;
275
+ const idleCompanionReachable = this.companionReachable;
276
+ this.connection = idleListenerActive ? "listening" : "offline";
277
+ this.lastError = undefined;
278
+ this.publish("pairing");
279
+ const request = {
280
+ projectId: this.projectId,
281
+ origin: this.origin,
282
+ ...(typeof window !== "undefined" ? { pageUrl: window.location.href } : {}),
283
+ };
284
+ const abortController = new AbortController();
285
+ this.discoveryAbort?.abort();
286
+ this.pairingAbort = abortController;
287
+ try {
288
+ const pairing = await this.transport.pair(request, abortController.signal);
289
+ if (!this.started || abortController.signal.aborted)
290
+ return false;
291
+ if (pairing.protocolVersion !== undefined && pairing.protocolVersion !== AGENT_PROTOCOL_VERSION) {
292
+ throw new Error("Agent bridge protocol version is not supported.");
293
+ }
294
+ if (pairing.projectId !== this.projectId)
295
+ throw new Error("Agent bridge returned a different project.");
296
+ if (pairing.status.projectId !== this.projectId || pairing.status.protocolVersion !== AGENT_PROTOCOL_VERSION || !pairing.status.paired) {
297
+ throw new Error("Agent bridge returned an invalid pairing status.");
298
+ }
299
+ this.sessionToken = pairing.sessionToken;
300
+ writeStoredSession({ projectId: this.projectId, origin: this.origin, sessionToken: pairing.sessionToken });
301
+ this.connection = "paired";
302
+ this.listenerActive = pairing.status.listenerActive;
303
+ this.paired = true;
304
+ if (this.discoveryTimer !== null) {
305
+ clearTimeout(this.discoveryTimer);
306
+ this.discoveryTimer = null;
307
+ }
308
+ this.applyStatus(pairing.status);
309
+ this.openEvents(pairing.sessionToken);
310
+ this.publish();
311
+ return true;
312
+ }
313
+ catch (error) {
314
+ if (abortController.signal.aborted || !this.started)
315
+ return false;
316
+ this.lastError = errorMessage(error, "The agent could not be connected.");
317
+ this.sessionToken = null;
318
+ this.companionReachable = idleCompanionReachable;
319
+ this.listenerActive = idleListenerActive;
320
+ this.connection = idleListenerActive ? "listening" : "offline";
321
+ this.paired = false;
322
+ this.publish(idleListenerActive ? "available" : "disconnected");
323
+ return false;
324
+ }
325
+ finally {
326
+ if (this.pairingAbort === abortController) {
327
+ this.pairingAbort = null;
328
+ this.scheduleDiscovery();
329
+ }
330
+ }
331
+ }
332
+ openEvents(sessionToken) {
333
+ this.eventSubscription?.close();
334
+ const eventsRequest = {
335
+ projectId: this.projectId,
336
+ origin: this.origin,
337
+ sessionToken,
338
+ };
339
+ try {
340
+ this.eventSubscription = this.transport.openEvents(eventsRequest, {
341
+ onEvent: (event) => this.handleEvent(event),
342
+ onDisconnect: (reason) => this.handleDisconnect(reason),
343
+ });
344
+ }
345
+ catch (error) {
346
+ this.handleDisconnect(errorMessage(error, "The agent event stream could not be opened."));
347
+ }
348
+ }
349
+ /**
350
+ * Dispatches one immutable prompt revision. The request enters `working`
351
+ * synchronously, before the transport promise resolves, so the UI cannot
352
+ * issue a second prompt while the first one is in flight.
353
+ */
354
+ async dispatchPrompt(prompt, changeRevision) {
355
+ if (!this.enabled || !this.started || !this.paired || !this.listenerActive || !this.sessionToken)
356
+ return null;
357
+ if (!prompt || this.activeRequest?.status === "working")
358
+ return null;
359
+ const localRequestId = randomId("request");
360
+ const request = {
361
+ projectId: this.projectId,
362
+ sessionToken: this.sessionToken,
363
+ prompt,
364
+ ...(changeRevision === undefined ? {} : { changeRevision }),
365
+ };
366
+ this.activeRequest = {
367
+ localRequestId,
368
+ requestId: localRequestId,
369
+ prompt,
370
+ ...(changeRevision === undefined ? {} : { changeRevision }),
371
+ status: "working",
372
+ };
373
+ this.connection = "working";
374
+ this.lastError = undefined;
375
+ this.publish();
376
+ const abortController = new AbortController();
377
+ this.dispatchAbort = abortController;
378
+ try {
379
+ const response = await this.transport.dispatch(request, abortController.signal);
380
+ if (abortController.signal.aborted)
381
+ return null;
382
+ if (response?.request?.requestId) {
383
+ this.activeRequest = this.activeRequest && this.activeRequest.localRequestId === localRequestId
384
+ ? { ...this.activeRequest, requestId: response.request.requestId }
385
+ : this.activeRequest;
386
+ }
387
+ if (response?.status && response.status !== "working") {
388
+ this.applyRequestStatus(response.status, response.request.requestId);
389
+ }
390
+ return response ?? null;
391
+ }
392
+ catch (error) {
393
+ if (!abortController.signal.aborted && this.activeRequest?.localRequestId === localRequestId) {
394
+ this.activeRequest = { ...this.activeRequest, status: "failed", error: errorMessage(error, "The agent did not accept the prompt.") };
395
+ this.connection = this.paired ? "paired" : this.listenerActive ? "listening" : "offline";
396
+ this.lastError = this.activeRequest.error;
397
+ this.publish();
398
+ }
399
+ return null;
400
+ }
401
+ finally {
402
+ if (this.dispatchAbort === abortController)
403
+ this.dispatchAbort = null;
404
+ }
405
+ }
406
+ /** Interrupts local request state and asks the companion to revoke pairing. */
407
+ disconnect(reason = "browser_disconnected") {
408
+ const token = this.sessionToken;
409
+ const active = this.activeRequest;
410
+ if (active?.status === "working") {
411
+ this.activeRequest = { ...active, status: "interrupted", error: reason };
412
+ }
413
+ this.dispatchAbort?.abort();
414
+ this.discoveryAbort?.abort();
415
+ this.discoveryAbort = null;
416
+ this.pairingAbort?.abort();
417
+ this.pairingAbort = null;
418
+ this.eventSubscription?.close();
419
+ this.eventSubscription = null;
420
+ this.sessionToken = null;
421
+ clearStoredSession(this.projectId);
422
+ this.connection = "offline";
423
+ this.listenerActive = false;
424
+ this.paired = false;
425
+ this.lastError = reason === "reconnect" || reason === "browser_disconnected" ? undefined : reason;
426
+ this.publish();
427
+ if (token) {
428
+ const request = {
429
+ projectId: this.projectId,
430
+ origin: this.origin,
431
+ sessionToken: token,
432
+ };
433
+ const disconnectResult = this.transport.disconnect?.(request);
434
+ void disconnectResult?.catch(() => undefined);
435
+ }
436
+ }
437
+ async discover() {
438
+ if (!this.started || !this.enabled || this.pairingAbort)
439
+ return;
440
+ const abortController = new AbortController();
441
+ this.discoveryAbort?.abort();
442
+ this.discoveryAbort = abortController;
443
+ try {
444
+ const request = { projectId: this.projectId, origin: this.origin };
445
+ const status = await this.transport.discover(request, abortController.signal);
446
+ if (!this.started || abortController.signal.aborted)
447
+ return;
448
+ if (status) {
449
+ if (status.protocolVersion !== AGENT_PROTOCOL_VERSION || status.projectId !== this.projectId) {
450
+ this.companionReachable = false;
451
+ this.lastError = "The agent bridge project or protocol does not match this page.";
452
+ this.publish();
453
+ }
454
+ else {
455
+ this.companionReachable = true;
456
+ if (this.connection !== "paired" && this.connection !== "working" && !this.pairingAbort) {
457
+ this.applyStatus(status);
458
+ }
459
+ }
460
+ }
461
+ else if (this.connection !== "paired" && this.connection !== "working" && !this.pairingAbort) {
462
+ this.connection = "offline";
463
+ this.listenerActive = false;
464
+ this.companionReachable = false;
465
+ this.paired = false;
466
+ this.lastError = undefined;
467
+ this.publish();
468
+ }
469
+ }
470
+ catch (error) {
471
+ if (!abortController.signal.aborted && this.started && this.connection !== "paired" && this.connection !== "working" && !this.pairingAbort) {
472
+ this.connection = "offline";
473
+ this.listenerActive = false;
474
+ this.companionReachable = false;
475
+ this.paired = false;
476
+ // Discovery failures are expected while the companion is not running;
477
+ // retain a quiet disconnected state rather than flashing an error.
478
+ this.lastError = undefined;
479
+ this.publish();
480
+ }
481
+ void error;
482
+ }
483
+ finally {
484
+ if (this.discoveryAbort === abortController)
485
+ this.discoveryAbort = null;
486
+ this.scheduleDiscovery();
487
+ }
488
+ }
489
+ scheduleDiscovery() {
490
+ if (!this.started || this.paired || this.pairingAbort || this.discoveryIntervalMs <= 0 || this.discoveryTimer !== null)
491
+ return;
492
+ this.discoveryTimer = setTimeout(() => {
493
+ this.discoveryTimer = null;
494
+ void this.discover();
495
+ }, this.discoveryIntervalMs);
496
+ }
497
+ scheduleReconnect() {
498
+ if (!this.started || this.pairingAbort || this.discoveryIntervalMs <= 0 || this.discoveryTimer !== null)
499
+ return;
500
+ this.discoveryTimer = setTimeout(() => {
501
+ this.discoveryTimer = null;
502
+ void this.restoreOrDiscover();
503
+ }, this.discoveryIntervalMs);
504
+ }
505
+ handleEvent(event) {
506
+ if (event.type === "status" || event.type === "connected") {
507
+ if (event.status.projectId !== this.projectId || event.status.protocolVersion !== AGENT_PROTOCOL_VERSION) {
508
+ this.handleDisconnect("The agent bridge project or protocol does not match this page.");
509
+ return;
510
+ }
511
+ this.applyStatus(event.status);
512
+ return;
513
+ }
514
+ if (event.type === "disconnected") {
515
+ this.handleDisconnect(event.reason);
516
+ return;
517
+ }
518
+ if (event.type === "canvas-command") {
519
+ void this.acknowledgeCanvasCommand(event.command);
520
+ }
521
+ }
522
+ async acknowledgeCanvasCommand(command) {
523
+ const handler = this.canvasCommandHandler;
524
+ const sessionToken = this.sessionToken;
525
+ if (!handler || !this.transport.acknowledgeCanvasCommand || !sessionToken)
526
+ return;
527
+ let acknowledgement;
528
+ try {
529
+ acknowledgement = await handler(command);
530
+ }
531
+ catch (error) {
532
+ acknowledgement = {
533
+ commandId: command.commandId,
534
+ ok: false,
535
+ error: {
536
+ code: "controller_error",
537
+ message: errorMessage(error, "The Canvas controller could not apply the command."),
538
+ },
539
+ };
540
+ }
541
+ if (acknowledgement.commandId !== command.commandId) {
542
+ acknowledgement = {
543
+ commandId: command.commandId,
544
+ ok: false,
545
+ error: { code: "command_mismatch", message: "The Canvas controller acknowledged a different command." },
546
+ };
547
+ }
548
+ const request = {
549
+ projectId: this.projectId,
550
+ origin: this.origin,
551
+ sessionToken,
552
+ acknowledgement,
553
+ };
554
+ try {
555
+ await this.transport.acknowledgeCanvasCommand(request);
556
+ }
557
+ catch {
558
+ // A command acknowledgement is best effort. The companion owns the
559
+ // bounded timeout and reports any expired command to its agent host.
560
+ }
561
+ }
562
+ applyStatus(status) {
563
+ this.companionReachable = true;
564
+ this.lastError = undefined;
565
+ this.listenerActive = status.listenerActive;
566
+ this.paired = status.paired;
567
+ this.connection = statusForConnection(status);
568
+ if (status.paired && this.discoveryTimer !== null) {
569
+ clearTimeout(this.discoveryTimer);
570
+ this.discoveryTimer = null;
571
+ }
572
+ if (status.request) {
573
+ this.applyRequestStatus(status.request.status, status.request.requestId, status.request.summary, status.request.error, status.request.changeRevision);
574
+ }
575
+ else if (status.listenerActive && status.paired && this.activeRequest?.status !== "working") {
576
+ // A re-armed MCP listen call is the lifecycle boundary for the previous
577
+ // terminal request. Drop only that terminal status; newer edits remain
578
+ // in the inspector's canonical change log.
579
+ this.activeRequest = null;
580
+ }
581
+ else if (this.activeRequest?.status === "working" && status.connection !== "working") {
582
+ // The bridge may omit a request during a brief re-arm transition. Do
583
+ // not mark a local request interrupted until the stream disconnects.
584
+ this.connection = "working";
585
+ }
586
+ if (!status.paired && this.sessionToken) {
587
+ this.handleDisconnect("The agent bridge pairing expired.");
588
+ return;
589
+ }
590
+ this.publish();
591
+ }
592
+ resetForDiscovery() {
593
+ this.eventSubscription?.close();
594
+ this.eventSubscription = null;
595
+ this.connection = "offline";
596
+ this.listenerActive = false;
597
+ this.companionReachable = false;
598
+ this.paired = false;
599
+ this.publish();
600
+ }
601
+ applyRequestStatus(status, requestId, summary, error, changeRevision) {
602
+ const active = this.activeRequest;
603
+ if (active && active.requestId !== requestId && active.localRequestId !== requestId) {
604
+ // A fresh server id can arrive before the POST response. Associate it
605
+ // with the one local request that was just marked working.
606
+ if (active.status !== "working")
607
+ return;
608
+ this.activeRequest = { ...active, requestId };
609
+ }
610
+ if (!this.activeRequest) {
611
+ this.activeRequest = {
612
+ localRequestId: requestId,
613
+ requestId,
614
+ prompt: "",
615
+ ...(changeRevision === undefined ? {} : { changeRevision }),
616
+ status,
617
+ ...(summary === undefined ? {} : { summary }),
618
+ ...(error === undefined ? {} : { error }),
619
+ };
620
+ }
621
+ else {
622
+ this.activeRequest = {
623
+ ...this.activeRequest,
624
+ requestId,
625
+ status,
626
+ ...(changeRevision === undefined ? {} : { changeRevision }),
627
+ ...(summary === undefined ? {} : { summary }),
628
+ ...(error === undefined ? {} : { error }),
629
+ };
630
+ }
631
+ if (status === "working")
632
+ this.connection = "working";
633
+ else if (this.paired)
634
+ this.connection = "paired";
635
+ }
636
+ handleDisconnect(reason = "The agent connection was lost.") {
637
+ this.eventSubscription?.close();
638
+ this.eventSubscription = null;
639
+ // An SSE disconnect is not proof that the coding request stopped. Keep
640
+ // its last known state until an authenticated status restore says
641
+ // otherwise. Explicit browser disconnect remains the interruption path.
642
+ this.connection = "offline";
643
+ this.listenerActive = false;
644
+ this.companionReachable = false;
645
+ this.paired = false;
646
+ this.lastError = reason;
647
+ this.publish();
648
+ this.scheduleReconnect();
649
+ }
650
+ makeSnapshot(stateOverride) {
651
+ const request = this.activeRequest;
652
+ const state = stateOverride ?? this.deriveState();
653
+ return {
654
+ state,
655
+ connection: this.connection,
656
+ listenerActive: this.listenerActive,
657
+ companionReachable: this.companionReachable,
658
+ paired: this.paired,
659
+ request: request ? {
660
+ requestId: request.requestId,
661
+ ...(request.changeRevision === undefined ? {} : { changeRevision: request.changeRevision }),
662
+ status: request.status,
663
+ ...(request.summary === undefined ? {} : { summary: request.summary }),
664
+ ...(request.error === undefined ? {} : { error: request.error }),
665
+ } : null,
666
+ ...(this.lastError === undefined ? {} : { error: this.lastError }),
667
+ };
668
+ }
669
+ deriveState() {
670
+ if (!this.enabled)
671
+ return "disabled";
672
+ if (this.connection === "offline")
673
+ return "disconnected";
674
+ if (this.connection === "listening")
675
+ return "available";
676
+ if (this.connection === "working" || this.activeRequest?.status === "working")
677
+ return "working";
678
+ if (this.activeRequest?.status === "completed")
679
+ return "completed";
680
+ if (this.activeRequest?.status === "failed")
681
+ return "failed";
682
+ if (this.activeRequest?.status === "interrupted")
683
+ return "interrupted";
684
+ return "connected";
685
+ }
686
+ publish(stateOverride) {
687
+ this.snapshot = Object.freeze(this.makeSnapshot(stateOverride));
688
+ for (const listener of this.listeners)
689
+ listener();
690
+ }
691
+ }
692
+ let configuredTransport;
693
+ const clients = new Map();
694
+ /** Sets a host/test transport for subsequently created project clients. */
695
+ export function configureAgentBridgeTransport(transport) {
696
+ for (const client of clients.values())
697
+ client.stop();
698
+ clients.clear();
699
+ configuredTransport = transport;
700
+ }
701
+ /** Clears cached clients and their active streams. */
702
+ export function resetAgentClients() {
703
+ for (const client of clients.values())
704
+ client.stop();
705
+ clients.clear();
706
+ }
707
+ export function createAgentClient(options) {
708
+ return new AgentClient({ ...options, transport: options.transport ?? configuredTransport });
709
+ }
710
+ export function getAgentClient(projectId, options = {}) {
711
+ const origin = options.origin ?? (typeof window !== "undefined" ? window.location.origin : "http://localhost");
712
+ const key = `${projectId}\u0000${origin}`;
713
+ let client = clients.get(key);
714
+ if (!client) {
715
+ client = createAgentClient({ ...options, projectId, origin });
716
+ clients.set(key, client);
717
+ }
718
+ return client;
719
+ }
720
+ /** React hook used by the inspector handoff control. */
721
+ export function useAgentClient(projectId, suppliedClient) {
722
+ const client = useMemo(() => suppliedClient ?? getAgentClient(projectId), [projectId, suppliedClient]);
723
+ useEffect(() => {
724
+ client.start();
725
+ return () => client.stop();
726
+ }, [client]);
727
+ return useSyncExternalStore(client.subscribe, client.getSnapshot, client.getSnapshot);
728
+ }