@wenathlan/devthink 2.0.12 → 2.0.14

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 (444) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/accounts.ts +2087 -0
  3. package/agent.ts +2331 -0
  4. package/antigravity.ts +2139 -0
  5. package/apifreeze.ts +4146 -0
  6. package/auth.ts +642 -0
  7. package/background.ts +16837 -0
  8. package/bridge.ts +2080 -0
  9. package/build.ts +54 -0
  10. package/bun.ts +26 -0
  11. package/capture.ts +1614 -0
  12. package/checksecrets.ts +72 -0
  13. package/cjs.ts +9 -0
  14. package/cli.ts +3500 -0
  15. package/commands.ts +1101 -0
  16. package/companion.ts +450 -0
  17. package/compatibility.ts +37 -0
  18. package/config.ts +3137 -0
  19. package/constants.ts +943 -0
  20. package/core.ts +1473 -0
  21. package/crossbrowser.ts +1359 -0
  22. package/dashdone.ts +605 -0
  23. package/data.ts +943 -0
  24. package/database.ts +133 -0
  25. package/debug.ts +850 -0
  26. package/deno.ts +27 -0
  27. package/devthink.ts +707 -0
  28. package/dist/accounts.d.ts +409 -0
  29. package/dist/agent.d.ts +837 -0
  30. package/dist/antigravity.d.ts +380 -0
  31. package/dist/apifreeze.d.ts +113 -0
  32. package/dist/auth.d.ts +224 -0
  33. package/{bridge.d.ts → dist/bridge.d.ts} +1 -1
  34. package/dist/capture.d.ts +595 -0
  35. package/dist/cjs.d.ts +6 -0
  36. package/{cli.js → dist/cli.js} +2 -2
  37. package/dist/commands.d.ts +310 -0
  38. package/dist/compatibility.d.ts +17 -0
  39. package/dist/config.d.ts +1853 -0
  40. package/dist/constants.d.ts +637 -0
  41. package/dist/core.d.ts +361 -0
  42. package/dist/data.d.ts +330 -0
  43. package/dist/database.d.ts +24 -0
  44. package/dist/debug.d.ts +270 -0
  45. package/dist/engine.d.ts +74 -0
  46. package/dist/environments.d.ts +244 -0
  47. package/dist/evidence.d.ts +277 -0
  48. package/dist/export.d.ts +311 -0
  49. package/dist/fingerprint.d.ts +594 -0
  50. package/dist/flow.d.ts +300 -0
  51. package/dist/gates.d.ts +103 -0
  52. package/dist/identity.d.ts +51 -0
  53. package/dist/ids.d.ts +7 -0
  54. package/dist/llm.d.ts +652 -0
  55. package/dist/models.d.ts +1807 -0
  56. package/dist/net.d.ts +325 -0
  57. package/dist/neutral.d.ts +41 -0
  58. package/dist/oauth.d.ts +703 -0
  59. package/dist/page.d.ts +1166 -0
  60. package/dist/perf.d.ts +481 -0
  61. package/dist/plan.d.ts +134 -0
  62. package/dist/project.d.ts +395 -0
  63. package/dist/providers.d.ts +37 -0
  64. package/dist/quota.d.ts +453 -0
  65. package/dist/recovery.d.ts +621 -0
  66. package/dist/request.d.ts +1492 -0
  67. package/dist/run.d.ts +779 -0
  68. package/dist/runtime.d.ts +212 -0
  69. package/dist/search.d.ts +375 -0
  70. package/dist/security.d.ts +534 -0
  71. package/dist/serve.d.ts +136 -0
  72. package/dist/session.d.ts +296 -0
  73. package/dist/storage.d.ts +53 -0
  74. package/dist/streaming.d.ts +1119 -0
  75. package/dist/swarm.d.ts +328 -0
  76. package/dist/tools.d.ts +170 -0
  77. package/dist/types.d.ts +8357 -0
  78. package/dist/utils.d.ts +82 -0
  79. package/dist/version.d.ts +7 -0
  80. package/dist/versionregistry.d.ts +406 -0
  81. package/dist/views.d.ts +579 -0
  82. package/dist/workbenchsession.d.ts +69 -0
  83. package/dist/workflow.d.ts +649 -0
  84. package/docs/readme.md +92 -0
  85. package/docs/schemas/antigravity.json +192 -0
  86. package/engine.ts +1524 -0
  87. package/environments.ts +1005 -0
  88. package/evidence.ts +643 -0
  89. package/export.ts +889 -0
  90. package/fingerprint.ts +1458 -0
  91. package/flow.ts +1190 -0
  92. package/gates.ts +307 -0
  93. package/gateway.ts +34 -0
  94. package/hardening.ts +191 -0
  95. package/headless.ts +369 -0
  96. package/http.ts +2110 -0
  97. package/identity.ts +246 -0
  98. package/ids.ts +26 -0
  99. package/index.ts +369 -0
  100. package/llm.ts +2682 -0
  101. package/mcp.ts +1835 -0
  102. package/{memory.js → memory.ts} +3834 -2310
  103. package/models.ts +3805 -0
  104. package/modes.ts +43 -0
  105. package/net.ts +1214 -0
  106. package/neutral.ts +362 -0
  107. package/node.ts +26 -0
  108. package/oauth.ts +2216 -0
  109. package/offscreen.ts +170 -0
  110. package/pack.ts +956 -0
  111. package/package.json +175 -82
  112. package/page.ts +7824 -0
  113. package/pagebridge.ts +1116 -0
  114. package/perf.ts +957 -0
  115. package/plan.ts +672 -0
  116. package/plugin.ts +76 -0
  117. package/{policy.js → policy.ts} +5073 -4679
  118. package/prisma.config.ts +27 -0
  119. package/progress.ts +1308 -0
  120. package/project.ts +1291 -0
  121. package/protocol.ts +4187 -0
  122. package/providers.ts +246 -0
  123. package/quota.ts +1887 -0
  124. package/recovery.ts +2433 -0
  125. package/request.ts +4482 -0
  126. package/run.ts +2135 -0
  127. package/runtime.ts +526 -0
  128. package/search.ts +1760 -0
  129. package/security.ts +1673 -0
  130. package/serve.ts +419 -0
  131. package/server.ts +5538 -0
  132. package/session.ts +1162 -0
  133. package/storage.ts +182 -0
  134. package/streaming.ts +4101 -0
  135. package/swarm.ts +884 -0
  136. package/sync.ts +56 -0
  137. package/tests/agentcert.test.ts +128 -0
  138. package/tests/agentfleet.test.ts +214 -0
  139. package/tests/agentreview.test.ts +241 -0
  140. package/tests/agentstream.test.ts +335 -0
  141. package/tests/agentwork.test.ts +356 -0
  142. package/tests/apifreeze.test.ts +290 -0
  143. package/tests/apimap.test.ts +112 -0
  144. package/tests/approvalgate.test.ts +175 -0
  145. package/tests/artifactmanifest.test.ts +204 -0
  146. package/tests/attentionfeed.test.ts +163 -0
  147. package/tests/backgroundruns.test.ts +100 -0
  148. package/tests/batchscheduling.test.ts +131 -0
  149. package/tests/blackboard.test.ts +238 -0
  150. package/tests/bridge.test.ts +1088 -0
  151. package/tests/browsercoverage.test.ts +134 -0
  152. package/tests/browserpolyfills.test.ts +124 -0
  153. package/tests/build.mjs +1260 -0
  154. package/tests/clientauth.test.ts +223 -0
  155. package/tests/clitools.test.ts +578 -0
  156. package/tests/confirmgates.test.ts +190 -0
  157. package/tests/containerpack.test.ts +143 -0
  158. package/tests/controlflow.test.ts +2120 -0
  159. package/tests/coordination.test.ts +345 -0
  160. package/tests/copyscreen.test.ts +139 -0
  161. package/tests/core.test.ts +417 -0
  162. package/tests/costcert.test.ts +95 -0
  163. package/tests/crossbrowser.test.ts +115 -0
  164. package/tests/cspaudit.test.ts +79 -0
  165. package/tests/dashdone.test.ts +615 -0
  166. package/tests/datagrid.test.ts +137 -0
  167. package/tests/doccheck.test.ts +107 -0
  168. package/tests/dombatch.test.ts +109 -0
  169. package/tests/emulation.test.ts +282 -0
  170. package/tests/environments.test.ts +259 -0
  171. package/tests/evidenceviews.test.ts +88 -0
  172. package/tests/exporttools.test.ts +185 -0
  173. package/tests/firefoxprep.test.ts +134 -0
  174. package/tests/flowlibrary.test.ts +242 -0
  175. package/tests/flowrun.test.ts +303 -0
  176. package/tests/forensics.test.ts +439 -0
  177. package/tests/gateway.test.ts +939 -0
  178. package/tests/headlesslib.test.ts +171 -0
  179. package/tests/httpstream.test.ts +277 -0
  180. package/tests/immutablelog.test.ts +157 -0
  181. package/tests/inboundguard.test.ts +177 -0
  182. package/tests/lazyload.test.ts +72 -0
  183. package/tests/librarymodes.test.ts +623 -0
  184. package/tests/llm.test.ts +696 -0
  185. package/tests/manifest.test.ts +226 -0
  186. package/tests/maskinputs.test.ts +150 -0
  187. package/tests/matrixverify.test.ts +111 -0
  188. package/tests/mavenpack.test.ts +75 -0
  189. package/tests/mcpserver.test.ts +704 -0
  190. package/tests/memory.test.ts +4155 -0
  191. package/tests/memorycare.test.ts +230 -0
  192. package/tests/migrateplan.test.ts +349 -0
  193. package/tests/minimization.test.ts +414 -0
  194. package/tests/modelroute.test.ts +112 -0
  195. package/tests/multiagent.test.ts +440 -0
  196. package/tests/nativebridge.test.ts +807 -0
  197. package/tests/navigation.test.ts +284 -0
  198. package/tests/nugetpack.test.ts +83 -0
  199. package/tests/orchestration.test.ts +449 -0
  200. package/tests/originpolicy.test.ts +405 -0
  201. package/tests/outputcompare.test.ts +97 -0
  202. package/tests/package.test.ts +91 -0
  203. package/tests/pagebridge.test.ts +5909 -0
  204. package/tests/pentest.test.ts +75 -0
  205. package/tests/perfrecords.test.ts +257 -0
  206. package/tests/permdiff.test.ts +85 -0
  207. package/tests/phishguard.test.ts +128 -0
  208. package/tests/pickerviews.test.ts +155 -0
  209. package/tests/pipelines.test.ts +381 -0
  210. package/tests/planlint.test.ts +240 -0
  211. package/tests/planreview.test.ts +383 -0
  212. package/tests/platformtargets.test.ts +56 -0
  213. package/tests/policy.test.ts +8284 -0
  214. package/tests/portability.test.ts +96 -0
  215. package/tests/progress.test.ts +1036 -0
  216. package/tests/promptlibrary.test.ts +116 -0
  217. package/tests/protocol.test.ts +4793 -0
  218. package/tests/publishingpipeline.test.ts +314 -0
  219. package/tests/quickactions.test.ts +164 -0
  220. package/tests/readiness.test.ts +78 -0
  221. package/tests/recipes.test.ts +163 -0
  222. package/tests/redactshots.test.ts +216 -0
  223. package/tests/registernvidiakeys.ts +51 -0
  224. package/tests/relayserve.test.ts +304 -0
  225. package/tests/releasenotes.test.ts +276 -0
  226. package/tests/resilience.test.ts +467 -0
  227. package/tests/resourceaware.test.ts +187 -0
  228. package/tests/runbudget.test.ts +125 -0
  229. package/tests/runhistory.test.ts +299 -0
  230. package/tests/runreplay.test.ts +113 -0
  231. package/tests/runresume.test.ts +184 -0
  232. package/tests/runstate.test.ts +288 -0
  233. package/tests/runtimeadapters.test.ts +251 -0
  234. package/tests/safariskeleton.test.ts +115 -0
  235. package/tests/sandboxframe.test.ts +196 -0
  236. package/tests/sbom.test.ts +105 -0
  237. package/tests/secretvault.test.ts +188 -0
  238. package/tests/selcache.test.ts +111 -0
  239. package/tests/sessioninterface.test.ts +791 -0
  240. package/tests/sessions.test.ts +591 -0
  241. package/tests/siteprefs.test.ts +228 -0
  242. package/tests/snapshotdelta.test.ts +165 -0
  243. package/tests/statusviews.test.ts +237 -0
  244. package/tests/stepmeter.test.ts +200 -0
  245. package/tests/streamparse.test.ts +163 -0
  246. package/tests/stylepruning.test.ts +90 -0
  247. package/tests/surfaces.test.ts +282 -0
  248. package/tests/sweep.test.ts +78 -0
  249. package/tests/syncbridge.test.ts +164 -0
  250. package/tests/taskqueue.test.ts +206 -0
  251. package/tests/toolcalls.test.ts +336 -0
  252. package/tests/toolcatalog.test.ts +201 -0
  253. package/tests/torture-agent.test.ts +706 -0
  254. package/tests/torture-auth.test.ts +461 -0
  255. package/tests/torture-commands.test.ts +895 -0
  256. package/tests/torture-data.test.ts +923 -0
  257. package/tests/torture-environments.test.ts +285 -0
  258. package/tests/torture-export.test.ts +263 -0
  259. package/tests/torture-http.test.ts +1379 -0
  260. package/tests/torture-llm.test.ts +808 -0
  261. package/tests/torture-memory.test.ts +1084 -0
  262. package/tests/torture-plan.test.ts +829 -0
  263. package/tests/torture-run.test.ts +626 -0
  264. package/tests/torture-session.test.ts +928 -0
  265. package/tests/torture-swarm.test.ts +1245 -0
  266. package/tests/torture-tools.test.ts +964 -0
  267. package/tests/torture-workflow.test.ts +2354 -0
  268. package/tests/tourviews.test.ts +52 -0
  269. package/tests/transparency.test.ts +147 -0
  270. package/tests/trigger.test.ts +941 -0
  271. package/tests/v1sunset.test.ts +428 -0
  272. package/tests/virtlist.test.ts +94 -0
  273. package/tests/vision.test.ts +540 -0
  274. package/tests/vsixpack.test.ts +145 -0
  275. package/tests/webapi.test.ts +523 -0
  276. package/tests/workflow.test.ts +1785 -0
  277. package/tests/workfloweditor.test.ts +759 -0
  278. package/tests/xpipack.test.ts +128 -0
  279. package/tools.ts +734 -0
  280. package/types.ts +9908 -0
  281. package/umd.ts +9 -0
  282. package/utils.ts +249 -0
  283. package/version.ts +8 -0
  284. package/versionregistry.ts +1310 -0
  285. package/views.ts +2153 -0
  286. package/vitest.config.ts +12 -0
  287. package/web/App.tsx +78 -0
  288. package/web/README.md +47 -0
  289. package/web/capacitor.config.ts +46 -0
  290. package/web/const.ts +19 -0
  291. package/web/control.shell.tsx +66 -0
  292. package/web/dashboardpage.ts +554 -0
  293. package/web/db.ts +493 -0
  294. package/web/design.html +541 -0
  295. package/web/gatewayview/Gateway.tsx +345 -0
  296. package/web/gatewayview/config.ts +1042 -0
  297. package/web/gatewayview/definition.ts +174 -0
  298. package/web/icons.ts +15 -0
  299. package/{manifest.json → web/manifest.json} +1 -1
  300. package/web/optionspage.ts +691 -0
  301. package/web/popup.ts +1651 -0
  302. package/web/schema.prisma +176 -0
  303. package/web/sidepanel.ts +7941 -0
  304. package/web/sitemanifest.json +13 -0
  305. package/web/terminal-ui.tsx +622 -0
  306. package/web/transparencypage.ts +541 -0
  307. package/web/vite.config.ts +39 -0
  308. package/web/workspace.ts +23 -0
  309. package/workbenchmemory.ts +104 -0
  310. package/workbenchsession.ts +304 -0
  311. package/workflow.ts +4495 -0
  312. package/bridge.d.ts.map +0 -1
  313. package/bridge.js +0 -1877
  314. package/bun.d.ts.map +0 -1
  315. package/bun.js +0 -52329
  316. package/caps/background.json +0 -712
  317. package/caps/cli.json +0 -360
  318. package/caps/library.json +0 -3611
  319. package/caps/mcp.json +0 -126
  320. package/caps/pagebridge.json +0 -377
  321. package/caps/popup.json +0 -51
  322. package/caps/sidepanel.json +0 -522
  323. package/checksums.txt +0 -142
  324. package/cli.d.ts.map +0 -1
  325. package/companion.d.ts.map +0 -1
  326. package/companion.js +0 -389
  327. package/crossbrowser.d.ts.map +0 -1
  328. package/crossbrowser.js +0 -1191
  329. package/dashdone.d.ts.map +0 -1
  330. package/dashdone.js +0 -368
  331. package/deno.d.ts.map +0 -1
  332. package/deno.js +0 -52325
  333. package/devthink.umd.js +0 -52346
  334. package/fixtures/bun.ts +0 -7
  335. package/fixtures/cjs.js +0 -6
  336. package/fixtures/deno.ts +0 -6
  337. package/fixtures/example-org-pagestate.json +0 -22
  338. package/fixtures/importers/automa-workflow.json +0 -18
  339. package/fixtures/importers/selenium-side.json +0 -20
  340. package/fixtures/importers/tabular-plan.csv +0 -7
  341. package/fixtures/importers/uivision-macro.json +0 -10
  342. package/fixtures/importers/v1-plan.json +0 -13
  343. package/fixtures/mcp-client.mjs +0 -14
  344. package/fixtures/pages/checkout.html +0 -192
  345. package/fixtures/pages/dashboard.html +0 -110
  346. package/fixtures/pages/feed.html +0 -113
  347. package/fixtures/pages/product-grid.html +0 -150
  348. package/fixtures/plans/form-inventory-plan.json +0 -11
  349. package/fixtures/plans/release-notes-plan.json +0 -11
  350. package/fixtures/recipes/agentscompete.json +0 -11
  351. package/fixtures/recipes/agentsforms.json +0 -11
  352. package/fixtures/recipes/agentsmonitor.json +0 -11
  353. package/fixtures/recipes/agentsreview.json +0 -29
  354. package/fixtures/recipes/agentswarm.json +0 -11
  355. package/fixtures/recipes/fillcalendar.json +0 -12
  356. package/fixtures/recipes/fillcheckout.json +0 -13
  357. package/fixtures/recipes/filldependentdropdowns.json +0 -12
  358. package/fixtures/recipes/fillfromcsv.json +0 -13
  359. package/fixtures/recipes/fillloginform.json +0 -12
  360. package/fixtures/recipes/fillmultistepwizard.json +0 -13
  361. package/fixtures/recipes/fillregistration.json +0 -12
  362. package/fixtures/recipes/fillsearchfilters.json +0 -12
  363. package/fixtures/recipes/filltypeahead.json +0 -11
  364. package/fixtures/recipes/monitoralerts.json +0 -12
  365. package/fixtures/recipes/monitoravailability.json +0 -11
  366. package/fixtures/recipes/monitornetworkquiet.json +0 -12
  367. package/fixtures/recipes/monitorpagechanges.json +0 -11
  368. package/fixtures/recipes/monitorpricechange.json +0 -11
  369. package/fixtures/recipes/monitorschedule.json +0 -12
  370. package/fixtures/recipes/scrapedynamicprices.json +0 -13
  371. package/fixtures/recipes/scrapeimagegallery.json +0 -12
  372. package/fixtures/recipes/scrapeinfinitefeed.json +0 -13
  373. package/fixtures/recipes/scrapenestedlists.json +0 -12
  374. package/fixtures/recipes/scrapeproductgrid.json +0 -12
  375. package/fixtures/recipes/scrapereviews.json +0 -12
  376. package/fixtures/recipes/scrapesearchresults.json +0 -12
  377. package/fixtures/recipes/scrapetablepagination.json +0 -12
  378. package/fixtures/recipes/testaccessibility.json +0 -34
  379. package/fixtures/recipes/testconsoleerrors.json +0 -12
  380. package/fixtures/recipes/testdeeplinks.json +0 -12
  381. package/fixtures/recipes/testformvalidation.json +0 -13
  382. package/fixtures/recipes/testlayoutshift.json +0 -12
  383. package/fixtures/recipes/testlinkcheck.json +0 -12
  384. package/fixtures/recipes/testloadtiming.json +0 -12
  385. package/fixtures/recipes/testvisualdiff.json +0 -12
  386. package/fixtures/workflows/changelog-digest-workflow.json +0 -13
  387. package/fixtures/workflows/form-survey-workflow.json +0 -13
  388. package/gallery.json +0 -706
  389. package/hardening.d.ts.map +0 -1
  390. package/hardening.js +0 -188
  391. package/headless.d.ts.map +0 -1
  392. package/headless.js +0 -11522
  393. package/http.d.ts.map +0 -1
  394. package/http.js +0 -2165
  395. package/index.cjs +0 -54682
  396. package/index.d.ts.map +0 -1
  397. package/index.js +0 -52310
  398. package/index.neutral.js +0 -46343
  399. package/mcp.d.ts.map +0 -1
  400. package/mcp.js +0 -20515
  401. package/memory.d.ts.map +0 -1
  402. package/nativehost.template.json +0 -10
  403. package/node.cjs +0 -54686
  404. package/node.d.ts.map +0 -1
  405. package/pack.d.ts.map +0 -1
  406. package/pack.js +0 -805
  407. package/policy.d.ts.map +0 -1
  408. package/progress.d.ts.map +0 -1
  409. package/progress.js +0 -645
  410. package/protocol.d.ts.map +0 -1
  411. package/protocol.js +0 -8334
  412. package/schemas/audit.schema.json +0 -226
  413. package/schemas/capability.schema.json +0 -113
  414. package/schemas/envelope.schema.json +0 -162
  415. package/schemas/memory.schema.json +0 -51
  416. package/schemas/observation.schema.json +0 -113
  417. package/schemas/plan.schema.json +0 -208
  418. package/schemas/progress.schema.json +0 -126
  419. package/schemas/proposal.schema.json +0 -68
  420. package/schemas/session.schema.json +0 -82
  421. package/schemas/tool.schema.json +0 -94
  422. package/server.d.ts.map +0 -1
  423. package/server.js +0 -28877
  424. package/umd-example.html +0 -18
  425. package/umd.d.ts.map +0 -1
  426. /package/{bun.d.ts → dist/bun.d.ts} +0 -0
  427. /package/{cli.d.ts → dist/cli.d.ts} +0 -0
  428. /package/{companion.d.ts → dist/companion.d.ts} +0 -0
  429. /package/{crossbrowser.d.ts → dist/crossbrowser.d.ts} +0 -0
  430. /package/{dashdone.d.ts → dist/dashdone.d.ts} +0 -0
  431. /package/{deno.d.ts → dist/deno.d.ts} +0 -0
  432. /package/{hardening.d.ts → dist/hardening.d.ts} +0 -0
  433. /package/{headless.d.ts → dist/headless.d.ts} +0 -0
  434. /package/{http.d.ts → dist/http.d.ts} +0 -0
  435. /package/{index.d.ts → dist/index.d.ts} +0 -0
  436. /package/{mcp.d.ts → dist/mcp.d.ts} +0 -0
  437. /package/{memory.d.ts → dist/memory.d.ts} +0 -0
  438. /package/{node.d.ts → dist/node.d.ts} +0 -0
  439. /package/{pack.d.ts → dist/pack.d.ts} +0 -0
  440. /package/{policy.d.ts → dist/policy.d.ts} +0 -0
  441. /package/{progress.d.ts → dist/progress.d.ts} +0 -0
  442. /package/{protocol.d.ts → dist/protocol.d.ts} +0 -0
  443. /package/{server.d.ts → dist/server.d.ts} +0 -0
  444. /package/{umd.d.ts → dist/umd.d.ts} +0 -0
package/bridge.js DELETED
@@ -1,1877 +0,0 @@
1
- /*! devthink 2.0.12 — consent-first browser agent library — GPL-3.0-only — https://github.com/wenathlan/devthink */
2
-
3
- // version.ts
4
- var packageversion = "2.0.12";
5
- var protocolmajor = 2;
6
-
7
- // types.ts
8
- var protocolversion = packageversion;
9
- var protocolmajorversion = protocolmajor;
10
- var pinnedprotocolversion = Object.freeze({ protocolversion, protocolmajor: protocolmajorversion });
11
- var actionkindids = Object.freeze([
12
- "observe",
13
- "inspect",
14
- "extract",
15
- "wait",
16
- "waitfor",
17
- "waittext",
18
- "readattribute",
19
- "readstyle",
20
- "readgeometry",
21
- "readvalue",
22
- "readtext",
23
- "readhtml",
24
- "countelements",
25
- "readtable",
26
- "readlinks",
27
- "readimages",
28
- "readmeta",
29
- "readforms",
30
- "readstorage",
31
- "highlight",
32
- "tablist",
33
- "windowlist",
34
- "tabsnapshot",
35
- "focus",
36
- "scroll",
37
- "hover",
38
- "clickdeep",
39
- "rightclick",
40
- "doubleclick",
41
- "scrollpage",
42
- "scrollby",
43
- "scrollend",
44
- "scrolltop",
45
- "fullscreen",
46
- "zoomset",
47
- "click",
48
- "type",
49
- "navigate",
50
- "select",
51
- "presskey",
52
- "drag",
53
- "drop",
54
- "upload",
55
- "clear",
56
- "check",
57
- "uncheck",
58
- "toggle",
59
- "submit",
60
- "reload",
61
- "back",
62
- "forward",
63
- "writestorage",
64
- "setattribute",
65
- "removeattribute",
66
- "evaluate",
67
- "tabcreate",
68
- "tabactivate",
69
- "tabclose",
70
- "tabreload",
71
- "windowcreate",
72
- "windowclose",
73
- "windowresize",
74
- "downloadfile",
75
- "movepointer",
76
- "clickpoint",
77
- "shiftclick",
78
- "clicktext",
79
- "clickaria",
80
- "clickname",
81
- "resolvexpath",
82
- "typetime",
83
- "appendtext",
84
- "setvalue",
85
- "typeedit",
86
- "keyhold",
87
- "keyrelease",
88
- "submitsearch",
89
- "selectmulti",
90
- "chooseradio",
91
- "setslider",
92
- "setdate",
93
- "setcolor",
94
- "expanddetails",
95
- "dismissdialog",
96
- "pierceshadow",
97
- "enterframe",
98
- "retryaction",
99
- "mapclicks",
100
- "verifyvisible",
101
- "verifyenabled",
102
- "a11ytree",
103
- "readvisible",
104
- "readertree",
105
- "detectlists",
106
- "detecttables",
107
- "readjson",
108
- "watchmutate",
109
- "waitquiet",
110
- "watchbanner",
111
- "detectinfinitescroll",
112
- "detectvirtual",
113
- "detectlazy",
114
- "readscrollpos",
115
- "readlang",
116
- "readoutline",
117
- "countpages",
118
- "listshadow",
119
- "listframes",
120
- "classifypage",
121
- "fingerprintsection",
122
- "diffsnapshots",
123
- "readselection",
124
- "watchfocus",
125
- "detectsticky",
126
- "detectscrolllock",
127
- "readopengraph",
128
- "detectlanguage",
129
- "deriveselector",
130
- "openlink",
131
- "openprivate",
132
- "reloadcache",
133
- "stopnav",
134
- "waitload",
135
- "waiturl",
136
- "followlink",
137
- "spanav",
138
- "spawait",
139
- "rewritequery",
140
- "setfragment",
141
- "navlist",
142
- "navprofile",
143
- "detecthttp",
144
- "readredirects",
145
- "readfinalurl",
146
- "handleauth",
147
- "printpdf",
148
- "prefetch",
149
- "preconnect",
150
- "deeplink",
151
- "reopentab",
152
- "trailaudit",
153
- "pausenav",
154
- "navintent",
155
- "navrate",
156
- "openclipboard",
157
- "checksafe",
158
- "batchopen",
159
- "querytabs",
160
- "duplicatetab",
161
- "closepattern",
162
- "pintab",
163
- "mutetab",
164
- "movetab",
165
- "movetabwindow",
166
- "grouptabs",
167
- "colorgroup",
168
- "collapsegroup",
169
- "discardtab",
170
- "reloadtabs",
171
- "zoomin",
172
- "zoomout",
173
- "watchtab",
174
- "switchtab",
175
- "maximizewindow",
176
- "minimizewindow",
177
- "restorewindow",
178
- "focuswindow",
179
- "scratchwindow",
180
- "incognitowindow",
181
- "restoretab",
182
- "savelayout",
183
- "restorelayout",
184
- "findclones",
185
- "searchtabs",
186
- "badgetab",
187
- "attachmeta",
188
- "listaudio",
189
- "reopenrun",
190
- "snapshotsession",
191
- "fillform",
192
- "filllabel",
193
- "fillplaceholder",
194
- "detectfields",
195
- "generatevalues",
196
- "saveprofiles",
197
- "asksubmit",
198
- "submitform",
199
- "readerrors",
200
- "retryform",
201
- "runwizard",
202
- "selectchain",
203
- "picktypeahead",
204
- "pickdate",
205
- "attachfile",
206
- "handoffcaptcha",
207
- "fillcard",
208
- "fillcode",
209
- "consentpassword",
210
- "skiphoneypot",
211
- "detectlogin",
212
- "detecttemplate",
213
- "scrapetable",
214
- "exportcsv",
215
- "exportjson",
216
- "exportexcel",
217
- "copytable",
218
- "pushsheets",
219
- "importcsv",
220
- "looprows",
221
- "transformvalues",
222
- "deduperows",
223
- "paginateextract",
224
- "mergepages",
225
- "stamplerows",
226
- "previewgrid",
227
- "streamdisk",
228
- "resumeextract",
229
- "logprovenance",
230
- "batchdownload",
231
- "pausedownload",
232
- "resumedownload",
233
- "verifydownload",
234
- "interceptmime",
235
- "exportnetlog",
236
- "readclipboard",
237
- "writeclipboard",
238
- "copyscreen",
239
- "quarantinedownload",
240
- "scanvirus",
241
- "namecaptures",
242
- "cleanupartifacts",
243
- "shotview",
244
- "shotfullpage",
245
- "shotelement",
246
- "shotregion",
247
- "contactsheet",
248
- "capturepdf",
249
- "recordscreen",
250
- "captureaudio",
251
- "captureframe",
252
- "downloadimages",
253
- "shotcanvas",
254
- "probestream",
255
- "readmedia",
256
- "readassets",
257
- "timelapse",
258
- "convertimage",
259
- "makethumbs",
260
- "fetchurl",
261
- "parsejson",
262
- "parsehtml",
263
- "callrest",
264
- "callgraphql",
265
- "opensocket",
266
- "sendmessage",
267
- "waitmessage",
268
- "watchrequests",
269
- "readheaders",
270
- "capturebodies",
271
- "subscribesse",
272
- "longpoll",
273
- "mapapi",
274
- "extractapi",
275
- "blockrequest",
276
- "mockresponse",
277
- "rewriteheaders",
278
- "setcookies",
279
- "readcookies",
280
- "clearcookies",
281
- "authflow",
282
- "saveapikey",
283
- "routeproxy",
284
- "postform",
285
- "postfiles",
286
- "watchconsole",
287
- "watcherrors",
288
- "watchtasks",
289
- "attachcdp",
290
- "detachcdp",
291
- "cdpcmd",
292
- "watchcdp",
293
- "setbreakpoint",
294
- "stepcode",
295
- "watchexpr",
296
- "overridescript",
297
- "measureflow",
298
- "heapshot",
299
- "trackmemory",
300
- "profilecpu",
301
- "watchshifts",
302
- "traceload",
303
- "annotatetrace",
304
- "replaytrace",
305
- "capturesourcemaps",
306
- "emulatedevice",
307
- "emulatenetwork",
308
- "emulatelocate",
309
- "setuseragent",
310
- "overridepermission",
311
- "blackboxscripts",
312
- "persiststate",
313
- "capturesession",
314
- "restoresession",
315
- "namedsessions",
316
- "diffsessions",
317
- "searchsessions",
318
- "exportsessions",
319
- "importsessions",
320
- "composeworkflow",
321
- "savetemplate",
322
- "runworkflow",
323
- "dryrun",
324
- "delay",
325
- "waitelement",
326
- "compute",
327
- "extractvars",
328
- "listruns",
329
- "condition",
330
- "branch",
331
- "loop",
332
- "repeatuntil",
333
- "whileloop",
334
- "foreach",
335
- "parallel",
336
- "trycatch",
337
- "visitrule",
338
- "urlrule",
339
- "menurule",
340
- "keyrule",
341
- "buttonrule",
342
- "cronrule",
343
- "intervalrule",
344
- "urllistrule",
345
- "webhookrule",
346
- "eventrule"
347
- ]);
348
- var servercontractversion = 1;
349
-
350
- // auth.ts
351
- function pairingcountdown(record, now) {
352
- const secondsleft = Math.max(0, Math.ceil((record.code.expiresat - now) / 1e3));
353
- const expired = now >= record.code.expiresat || record.code.usedat !== void 0;
354
- const minutes = Math.floor(secondsleft / 60);
355
- const seconds = secondsleft % 60;
356
- const label = expired ? `The pairing code ${record.code.code} expired.` : `The pairing code ${record.code.code} expires in ${minutes}m ${String(seconds).padStart(2, "0")}s.`;
357
- return { secondsleft, expired, label };
358
- }
359
-
360
- // serve.ts
361
- function notificationframe(method, params) {
362
- return { jsonrpc: "2.0", method, ...params !== void 0 ? { params } : {} };
363
- }
364
-
365
- // net.ts
366
- function reconnectwaits(attempts, base, ceiling) {
367
- const count = Math.max(0, Math.floor(attempts));
368
- const waits = [];
369
- let wait = Math.max(0, base);
370
- for (let index = 0; index < count; index += 1) {
371
- waits.push(wait);
372
- const next = wait * 2;
373
- wait = ceiling !== void 0 && Number.isFinite(ceiling) && ceiling >= 0 ? Math.min(next, ceiling) : next;
374
- }
375
- return waits;
376
- }
377
-
378
- // bridge.ts
379
- var serveroperations = ["sessioncreate", "sessionjoin", "eventpost", "eventstream"];
380
- var servereventtypes = ["chat", "planproposal", "planreview", "progress"];
381
- var pagecontentkeys = [
382
- "html",
383
- "content",
384
- "body",
385
- "textpreview",
386
- "preview",
387
- "dom",
388
- "markup",
389
- "screenshot",
390
- "pagetext",
391
- "outerhtml",
392
- "innertext"
393
- ];
394
- function contractcapabilities(version = servercontractversion) {
395
- return {
396
- version,
397
- operations: [...serveroperations],
398
- events: [...servereventtypes],
399
- heartbeat: true,
400
- multiplex: true
401
- };
402
- }
403
- function stableopid(seed, sequence) {
404
- const trimmed = seed.trim();
405
- if (trimmed === "")
406
- throw new Error("The operation id names its sender seed; an empty seed never correlates a reply.");
407
- if (!Number.isInteger(sequence) || sequence < 1)
408
- throw new Error("The operation id sequence stays a positive whole number per sender.");
409
- return `op-${trimmed}-${sequence}`;
410
- }
411
- function negotiatecapabilities(ours, theirs) {
412
- if (!Number.isInteger(ours.version) || ours.version < 1 || !Number.isInteger(theirs.version) || theirs.version < 1)
413
- return {
414
- ok: false,
415
- version: 0,
416
- operations: [],
417
- events: [],
418
- heartbeat: false,
419
- multiplex: false,
420
- reason: "The servercontract version stays a positive whole number on both sides of the handshake."
421
- };
422
- const version = Math.min(ours.version, theirs.version);
423
- const operations = serveroperations.filter(
424
- (operation) => ours.operations.includes(operation) && theirs.operations.includes(operation)
425
- );
426
- const events = servereventtypes.filter((event) => ours.events.includes(event) && theirs.events.includes(event));
427
- if (version < 1)
428
- return {
429
- ok: false,
430
- version: 0,
431
- operations: [],
432
- events: [],
433
- heartbeat: false,
434
- multiplex: false,
435
- reason: "The two handshake sides share no servercontract version."
436
- };
437
- if (operations.length === 0)
438
- return {
439
- ok: false,
440
- version,
441
- operations: [],
442
- events: [],
443
- heartbeat: false,
444
- multiplex: false,
445
- reason: "The two handshake sides share no wire operation."
446
- };
447
- if (events.length === 0)
448
- return {
449
- ok: false,
450
- version,
451
- operations: [],
452
- events: [],
453
- heartbeat: false,
454
- multiplex: false,
455
- reason: "The two handshake sides share no event type."
456
- };
457
- return {
458
- ok: true,
459
- version,
460
- operations,
461
- events,
462
- heartbeat: ours.heartbeat === true && theirs.heartbeat === true,
463
- multiplex: ours.multiplex === true && theirs.multiplex === true
464
- };
465
- }
466
- function composeenvelope(input) {
467
- const opid = input.opid.trim();
468
- if (opid === "")
469
- throw new Error("The envelope carries its stable operation id; an empty id never correlates a reply.");
470
- if (!serveroperations.includes(input.op))
471
- throw new Error(`The envelope operation ${input.op} sits outside the servercontract operations.`);
472
- if (!Number.isFinite(input.at)) throw new Error("The envelope carries its timestamp.");
473
- return {
474
- version: input.version ?? servercontractversion,
475
- op: input.op,
476
- opid,
477
- at: input.at,
478
- ...input.sessionid !== void 0 && input.sessionid.trim() !== "" ? { sessionid: input.sessionid.trim() } : {},
479
- ...input.token !== void 0 && input.token.trim() !== "" ? { token: input.token.trim() } : {},
480
- ...input.body !== void 0 ? { body: input.body } : {}
481
- };
482
- }
483
- function parseenvelope(value) {
484
- if (!value || typeof value !== "object" || Array.isArray(value))
485
- throw new Error("The servercontract envelope must be a json object.");
486
- const entry = value;
487
- if (!Number.isInteger(entry.version) || entry.version < 1)
488
- throw new Error("The envelope version must be a positive whole number.");
489
- if (typeof entry.op !== "string" || !serveroperations.includes(entry.op))
490
- throw new Error(`The envelope operation ${String(entry.op)} sits outside the servercontract operations.`);
491
- if (typeof entry.opid !== "string" || entry.opid.trim() === "")
492
- throw new Error("The envelope operation id must be a non-empty string.");
493
- if (entry.sessionid !== void 0 && (typeof entry.sessionid !== "string" || entry.sessionid.trim() === ""))
494
- throw new Error("The envelope session id must be a non-empty string when present.");
495
- if (entry.token !== void 0 && (typeof entry.token !== "string" || entry.token.trim() === ""))
496
- throw new Error("The envelope frame token must be a non-empty string when present.");
497
- if (!Number.isFinite(entry.at)) throw new Error("The envelope timestamp must be a finite number.");
498
- if (entry.body !== void 0 && (!entry.body || typeof entry.body !== "object" || Array.isArray(entry.body)))
499
- throw new Error("The envelope body must be a json object when present.");
500
- return {
501
- version: entry.version,
502
- op: entry.op,
503
- opid: entry.opid.trim(),
504
- at: entry.at,
505
- ...entry.sessionid !== void 0 ? { sessionid: entry.sessionid.trim() } : {},
506
- ...entry.token !== void 0 ? { token: entry.token.trim() } : {},
507
- ...entry.body !== void 0 ? { body: entry.body } : {}
508
- };
509
- }
510
- function envelopeacceptance(value) {
511
- try {
512
- return { ok: true, envelope: parseenvelope(value) };
513
- } catch (error) {
514
- return { ok: false, reason: error instanceof Error ? error.message : String(error) };
515
- }
516
- }
517
- function sessioncreatebody(input) {
518
- const memberid = input.memberid.trim();
519
- if (memberid === "") throw new Error("The sessioncreate body names its member id.");
520
- if (input.role !== "extension" && input.role !== "site")
521
- throw new Error("The sessioncreate role is the extension or the site side.");
522
- return {
523
- role: input.role,
524
- memberid,
525
- capabilities: input.capabilities,
526
- ...input.pairingcode !== void 0 && input.pairingcode.trim() !== "" ? { pairingcode: input.pairingcode.trim() } : {}
527
- };
528
- }
529
- function sessionjoinbody(input) {
530
- const sessionid = (input.sessionid ?? "").trim();
531
- const pairingcode = (input.pairingcode ?? "").trim();
532
- if (sessionid === "" && pairingcode === "")
533
- throw new Error(
534
- "The sessionjoin body names its session id or rides its pairing code; one of the two identifies the join."
535
- );
536
- const memberid = input.memberid.trim();
537
- if (memberid === "") throw new Error("The sessionjoin body names its member id.");
538
- if (input.role !== "extension" && input.role !== "site")
539
- throw new Error("The sessionjoin role is the extension or the site side.");
540
- return {
541
- ...sessionid !== "" ? { sessionid } : {},
542
- role: input.role,
543
- memberid,
544
- capabilities: input.capabilities,
545
- ...pairingcode !== "" ? { pairingcode } : {}
546
- };
547
- }
548
- function eventpostbody(input) {
549
- if (!servereventtypes.includes(input.event.kind))
550
- throw new Error(`The event type ${input.event.kind} sits outside the servercontract event types.`);
551
- const stream = input.event.stream.trim();
552
- if (stream === "") throw new Error("The eventpost body names its multiplexed stream.");
553
- if (!input.event.payload || typeof input.event.payload !== "object" || Array.isArray(input.event.payload))
554
- throw new Error("The eventpost payload must be a json object.");
555
- return { kind: input.event.kind, stream, payload: input.event.payload };
556
- }
557
- function eventstreambody(input) {
558
- const streams = input.streams.map((stream) => stream.trim()).filter((stream) => stream !== "");
559
- if (streams.length === 0) throw new Error("The eventstream body names at least one multiplexed stream.");
560
- if (input.since !== void 0 && !Number.isFinite(input.since))
561
- throw new Error("The eventstream resume timestamp stays a finite number.");
562
- return { streams, ...input.since !== void 0 ? { since: input.since } : {} };
563
- }
564
- function chateventpayload(input) {
565
- const text = input.text.trim();
566
- if (text === "") throw new Error("The chat event carries its task text.");
567
- const from = input.from.trim();
568
- if (from === "") throw new Error("The chat event names its sender.");
569
- return { text, from };
570
- }
571
- function planproposaleventpayload(card) {
572
- const proposalid = card.proposalid.trim();
573
- if (proposalid === "") throw new Error("The plan proposal names its proposal id.");
574
- const title = card.title.trim();
575
- if (title === "") throw new Error("The plan proposal names its plan title.");
576
- if (card.steps.length === 0) throw new Error("The plan proposal carries at least one step of its digest.");
577
- return {
578
- proposalid,
579
- title,
580
- steps: card.steps.map((step) => ({ id: step.id, kind: step.kind, origin: step.origin, sensitive: step.sensitive })),
581
- ...card.timeoutat !== void 0 ? { timeoutat: card.timeoutat } : {}
582
- };
583
- }
584
- function planrevieweventpayload(decision) {
585
- const proposalid = decision.proposalid.trim();
586
- if (proposalid === "") throw new Error("The plan review names its proposal id.");
587
- if (decision.decision !== "approved" && decision.decision !== "changes" && decision.decision !== "refused")
588
- throw new Error("The plan review decision is approved, changes or refused.");
589
- const by = decision.by.trim();
590
- if (by === "") throw new Error("The plan review names its reviewer.");
591
- return {
592
- proposalid,
593
- decision: decision.decision,
594
- by,
595
- ...decision.note !== void 0 && decision.note.trim() !== "" ? { note: decision.note.trim() } : {}
596
- };
597
- }
598
- function progresseventpayload(input) {
599
- const stepid = input.stepid.trim();
600
- if (stepid === "") throw new Error("The progress event names its step id.");
601
- const status = input.status.trim();
602
- if (status === "") throw new Error("The progress event names its status word.");
603
- return { stepid, status };
604
- }
605
- function heartbeatevent(now) {
606
- if (!Number.isFinite(now)) throw new Error("The heartbeat event carries its timestamp.");
607
- return {
608
- kind: "progress",
609
- stream: "heartbeat",
610
- payload: progresseventpayload({ stepid: "heartbeat", status: "alive" })
611
- };
612
- }
613
- function bridgepayload(kind, payload, pageconsent) {
614
- if (kind === "chat") return { payload, held: [] };
615
- const held = [];
616
- const minimized = {};
617
- for (const [key, value] of Object.entries(payload)) {
618
- if (pagecontentkeys.includes(key) && pageconsent !== true) {
619
- held.push(key);
620
- continue;
621
- }
622
- minimized[key] = value;
623
- }
624
- return { payload: minimized, held };
625
- }
626
- function minimalplandigest(plan, statuses = {}) {
627
- const objective = plan.objective.trim();
628
- if (objective === "") throw new Error("The plan digest names its objective.");
629
- return {
630
- title: objective,
631
- steps: plan.steps.map((step) => ({ id: step.id, kind: step.kind, status: statuses[step.id] ?? "pending" }))
632
- };
633
- }
634
- function frameof(envelope) {
635
- return JSON.stringify(envelope);
636
- }
637
- function parsewireframe(text) {
638
- let parsed;
639
- try {
640
- parsed = JSON.parse(text);
641
- } catch {
642
- throw new Error("The wire frame must be json text.");
643
- }
644
- return parseenvelope(parsed);
645
- }
646
- function sitemanifestof(version = servercontractversion) {
647
- return { name: "devthink site", servercontract: version, capabilities: contractcapabilities(version) };
648
- }
649
- function relayorigin(url) {
650
- try {
651
- const parsed = new URL(url.trim());
652
- if (parsed.protocol !== "wss:" && parsed.protocol !== "ws:") return "";
653
- const protocol = parsed.protocol === "wss:" ? "https:" : "http:";
654
- return `${protocol}//${parsed.host}`;
655
- } catch {
656
- return "";
657
- }
658
- }
659
- function newrelayclient(input) {
660
- const memberid = input.memberid.trim();
661
- if (memberid === "") throw new Error("The bridge client names its member id.");
662
- const url = input.url.trim();
663
- if (url !== "" && relayorigin(url) === "") throw new Error("The relay url must be a wss or ws url the user chose.");
664
- return {
665
- url,
666
- origin: relayorigin(url),
667
- sessionid: (input.sessionid ?? "").trim(),
668
- token: (input.token ?? "").trim(),
669
- memberid,
670
- role: input.role,
671
- state: url === "" ? "idle" : "connecting",
672
- attempts: 0,
673
- rotations: 0,
674
- sent: 0,
675
- received: 0,
676
- lastframeat: input.now,
677
- lastheartbeatat: input.now,
678
- streams: {},
679
- acks: [],
680
- queue: [],
681
- capabilities: input.capabilities,
682
- rate: { used: 0, windowstartedat: input.now },
683
- sequence: 0
684
- };
685
- }
686
- function verifyframeauth(envelope, state) {
687
- if (state.sessionid === "" || state.token === "") return false;
688
- return envelope.sessionid === state.sessionid && envelope.token === state.token;
689
- }
690
- function frameauth(envelope, state) {
691
- return { ...envelope, sessionid: state.sessionid, token: state.token };
692
- }
693
- function bridgeframerate(input) {
694
- const window = input.window !== void 0 && Number.isFinite(input.window) && input.window > 0 ? input.window : void 0;
695
- if (window === void 0)
696
- return { allowed: true, used: input.rate.used, windowstartedat: input.rate.windowstartedat };
697
- if (input.now - input.rate.windowstartedat >= window)
698
- return {
699
- allowed: input.cap === void 0 || input.cap >= 1,
700
- used: input.cap === void 0 ? input.rate.used : 1,
701
- windowstartedat: input.now,
702
- resetsat: input.now + window
703
- };
704
- const used = input.rate.used + 1;
705
- if (input.cap !== void 0 && Number.isFinite(input.cap) && input.cap >= 1 && used > input.cap)
706
- return {
707
- allowed: false,
708
- used: input.rate.used,
709
- windowstartedat: input.rate.windowstartedat,
710
- resetsat: input.rate.windowstartedat + window
711
- };
712
- return {
713
- allowed: true,
714
- used,
715
- windowstartedat: input.rate.windowstartedat,
716
- resetsat: input.rate.windowstartedat + window
717
- };
718
- }
719
- function sendframe(state, socket, envelope, now) {
720
- if (state.state !== "connected")
721
- return { state, sent: false, reason: "The bridge socket stays down; the frame waits in the offline queue." };
722
- const stamped = frameauth(envelope, state);
723
- socket.send(frameof(stamped));
724
- return { state: { ...state, sent: state.sent + 1, lastframeat: now }, sent: true };
725
- }
726
- function receiveframe(state, frame, now) {
727
- let envelope;
728
- try {
729
- envelope = parsewireframe(frame);
730
- } catch (error) {
731
- return { state, rejection: error instanceof Error ? error.message : String(error) };
732
- }
733
- if (!verifyframeauth(envelope, state))
734
- return {
735
- state,
736
- rejection: `The frame ${envelope.opid} failed the frame authentication of the session ${state.sessionid}.`
737
- };
738
- if (envelope.op === "eventpost" && envelope.body !== void 0) {
739
- const stream = typeof envelope.body.stream === "string" ? envelope.body.stream.trim() : "";
740
- const kind = typeof envelope.body.kind === "string" ? envelope.body.kind : "";
741
- if (stream !== "") {
742
- const record = {
743
- id: envelope.opid,
744
- sessionid: state.sessionid,
745
- kind,
746
- opid: envelope.opid,
747
- stream,
748
- payload: envelope.body.payload ?? {},
749
- at: envelope.at,
750
- delivered: true
751
- };
752
- const next = {
753
- ...state,
754
- received: state.received + 1,
755
- lastframeat: now,
756
- acks: [...state.acks, envelope],
757
- streams: { ...state.streams, [stream]: [...state.streams[stream] ?? [], record] }
758
- };
759
- return { state: next, envelope };
760
- }
761
- }
762
- return {
763
- state: { ...state, received: state.received + 1, lastframeat: now, acks: [...state.acks, envelope] },
764
- envelope
765
- };
766
- }
767
- function enqueuebridge(state, input) {
768
- if (state.queue.some((record2) => record2.opid === input.opid)) return state;
769
- const record = {
770
- opid: input.opid,
771
- op: input.op,
772
- sessionid: state.sessionid,
773
- body: input.body,
774
- queuedat: input.now,
775
- attempts: 0
776
- };
777
- return { ...state, queue: [...state.queue, record] };
778
- }
779
- function replaybridgequeue(state, socket, now) {
780
- let replayed = 0;
781
- let deduped = 0;
782
- const seen = /* @__PURE__ */ new Set();
783
- const queue = [];
784
- let sent = state.sent;
785
- for (const record of state.queue) {
786
- if (seen.has(record.opid)) {
787
- deduped += 1;
788
- continue;
789
- }
790
- seen.add(record.opid);
791
- if (record.sentat !== void 0 || state.state !== "connected") {
792
- queue.push(record);
793
- continue;
794
- }
795
- socket.send(
796
- frameof(frameauth(composeenvelope({ op: record.op, opid: record.opid, at: now, body: record.body }), state))
797
- );
798
- queue.push({ ...record, attempts: record.attempts + 1, sentat: now });
799
- replayed += 1;
800
- sent += 1;
801
- }
802
- return { state: { ...state, queue, sent, lastframeat: now }, replayed, deduped };
803
- }
804
- function postevent(state, socket, event, now, rate) {
805
- const opid = `op-${state.memberid}-${state.sequence + 1}`;
806
- const body = eventpostbody({ event });
807
- if (state.state !== "connected" || socket === void 0) {
808
- return {
809
- state: enqueuebridge({ ...state, sequence: state.sequence + 1 }, { op: "eventpost", opid, body, now }),
810
- sent: false,
811
- queued: true,
812
- reason: "The bridge socket stays down; the event waits in the offline queue."
813
- };
814
- }
815
- const window = bridgeframerate({
816
- rate: state.rate,
817
- ...rate?.cap !== void 0 ? { cap: rate.cap } : {},
818
- ...rate?.window !== void 0 ? { window: rate.window } : {},
819
- now
820
- });
821
- if (!window.allowed) {
822
- return {
823
- state: enqueuebridge(
824
- {
825
- ...state,
826
- sequence: state.sequence + 1,
827
- rate: { used: window.used, windowstartedat: window.windowstartedat }
828
- },
829
- { op: "eventpost", opid, body, now }
830
- ),
831
- sent: false,
832
- queued: true,
833
- reason: `The bridge rate window holds its ${rate?.cap} frame cap; the event waits for the window reset.`
834
- };
835
- }
836
- const sent = sendframe(
837
- { ...state, sequence: state.sequence + 1, rate: { used: window.used, windowstartedat: window.windowstartedat } },
838
- socket,
839
- composeenvelope({ op: "eventpost", opid, at: now, body }),
840
- now
841
- );
842
- return { state: sent.state, sent: true, queued: false };
843
- }
844
- function heartbeattick(state, socket, now, interval) {
845
- if (state.state !== "connected" || socket === void 0) return { state, beat: false };
846
- if (interval === void 0 || !Number.isFinite(interval) || interval <= 0) return { state, beat: false };
847
- if (now - state.lastheartbeatat < interval) return { state, beat: false };
848
- const event = heartbeatevent(now);
849
- const opid = `op-${state.memberid}-heartbeat-${state.sent + 1}`;
850
- const sent = sendframe(
851
- state,
852
- socket,
853
- composeenvelope({ op: "eventpost", opid, at: now, body: eventpostbody({ event }) }),
854
- now
855
- );
856
- return { state: { ...sent.state, lastheartbeatat: now }, beat: true };
857
- }
858
- function idleexpired(state, now, idlewindow) {
859
- if (idlewindow === void 0 || !Number.isFinite(idlewindow) || idlewindow <= 0) return false;
860
- return now - state.lastframeat >= idlewindow;
861
- }
862
- function disconnectrelay(state, now, reason) {
863
- return { ...state, state: "closed", closedat: now, ...reason !== void 0 ? { lasterror: reason } : {} };
864
- }
865
- function bridgestatusview(state) {
866
- if (state.url === "")
867
- return {
868
- status: "disabled",
869
- paired: false,
870
- queued: state.queue.filter((record) => record.sentat === void 0).length
871
- };
872
- const paired = state.sessionid !== "" && state.token !== "";
873
- if (state.state === "connected")
874
- return { status: "connected", paired, queued: state.queue.filter((record) => record.sentat === void 0).length };
875
- if (paired)
876
- return {
877
- status: "paired",
878
- paired: true,
879
- queued: state.queue.filter((record) => record.sentat === void 0).length
880
- };
881
- return {
882
- status: "offline",
883
- paired: false,
884
- queued: state.queue.filter((record) => record.sentat === void 0).length
885
- };
886
- }
887
- async function connectrelay(input) {
888
- const sleep = input.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, Math.max(0, milliseconds))));
889
- const now = input.now ?? Date.now;
890
- if (input.state.url.trim() === "")
891
- return {
892
- state: {
893
- ...input.state,
894
- state: "idle",
895
- lasterror: "The bridge stays disabled because no relay url is configured; the url is always the user's setting."
896
- },
897
- error: "The bridge stays disabled because no relay url is configured; the url is always the user's setting."
898
- };
899
- const budget = Math.max(1, Math.floor(input.attempts ?? 1));
900
- const waits = reconnectwaits(budget - 1, input.backoffbase ?? 0, input.backoffceiling);
901
- let state = { ...input.state, state: "connecting" };
902
- let lasterror = "";
903
- for (let attempt = 0; attempt < budget; attempt += 1) {
904
- let socket;
905
- try {
906
- socket = await input.open(state.url);
907
- } catch (error) {
908
- lasterror = error instanceof Error ? error.message : String(error);
909
- if (attempt < budget - 1) {
910
- const wait = waits[attempt] ?? 0;
911
- if (wait > 0) await sleep(wait);
912
- state = { ...state, attempts: state.attempts + 1, state: "reconnecting" };
913
- if (input.rotate !== void 0) {
914
- try {
915
- state = { ...state, token: await input.rotate(), rotations: state.rotations + 1 };
916
- } catch {
917
- }
918
- }
919
- }
920
- continue;
921
- }
922
- state = { ...state, state: "authenticating" };
923
- const opid = `op-${state.memberid}-join-${state.attempts + 1}`;
924
- const firstjoin = state.sessionid === "";
925
- const reply = await new Promise((resolve) => {
926
- socket.onmessage = (frame) => resolve({ frame });
927
- socket.onclose = (code) => resolve({
928
- error: `The relay socket closed with code ${code} before the ${firstjoin ? "session create" : "join"} reply.`
929
- });
930
- socket.onerror = (error) => resolve({ error });
931
- const createsession = firstjoin && state.role === "extension";
932
- const body = createsession ? {
933
- role: state.role,
934
- memberid: state.memberid,
935
- capabilities: state.capabilities,
936
- ...input.pairingcode !== void 0 && input.pairingcode.trim() !== "" ? { pairingcode: input.pairingcode.trim() } : {}
937
- } : firstjoin ? {
938
- role: state.role,
939
- memberid: state.memberid,
940
- capabilities: state.capabilities,
941
- ...input.pairingcode !== void 0 && input.pairingcode.trim() !== "" ? { pairingcode: input.pairingcode.trim() } : {}
942
- } : {
943
- sessionid: state.sessionid,
944
- role: state.role,
945
- memberid: state.memberid,
946
- capabilities: state.capabilities
947
- };
948
- socket.send(
949
- frameof(
950
- frameauth(composeenvelope({ op: createsession ? "sessioncreate" : "sessionjoin", opid, at: now(), body }), {
951
- ...state,
952
- token: state.token
953
- })
954
- )
955
- );
956
- });
957
- if (reply.frame === void 0) {
958
- lasterror = reply.error ?? "The relay socket closed before the join reply.";
959
- try {
960
- socket.close(1e3);
961
- } catch {
962
- }
963
- if (attempt < budget - 1) {
964
- const wait = waits[attempt] ?? 0;
965
- if (wait > 0) await sleep(wait);
966
- state = { ...state, attempts: state.attempts + 1, state: "reconnecting" };
967
- if (input.rotate !== void 0) {
968
- try {
969
- state = { ...state, token: await input.rotate(), rotations: state.rotations + 1 };
970
- } catch {
971
- }
972
- }
973
- }
974
- continue;
975
- }
976
- let envelope;
977
- try {
978
- envelope = parsewireframe(reply.frame);
979
- } catch (error) {
980
- lasterror = error instanceof Error ? error.message : String(error);
981
- try {
982
- socket.close(1e3);
983
- } catch {
984
- }
985
- continue;
986
- }
987
- if (envelope.opid !== opid) {
988
- lasterror = `The join reply ${envelope.opid} does not correlate the join request ${opid}.`;
989
- try {
990
- socket.close(1e3);
991
- } catch {
992
- }
993
- continue;
994
- }
995
- if (envelope.body !== void 0 && typeof envelope.body.error === "string" && envelope.body.error.trim() !== "") {
996
- lasterror = envelope.body.error;
997
- try {
998
- socket.close(1e3);
999
- } catch {
1000
- }
1001
- if (attempt < budget - 1) {
1002
- const wait = waits[attempt] ?? 0;
1003
- if (wait > 0) await sleep(wait);
1004
- state = { ...state, attempts: state.attempts + 1, state: "reconnecting" };
1005
- }
1006
- continue;
1007
- }
1008
- const rotatedtoken = envelope.body !== void 0 && typeof envelope.body.token === "string" ? envelope.body.token.trim() : "";
1009
- const sessionid = envelope.body !== void 0 && typeof envelope.body.sessionid === "string" ? envelope.body.sessionid.trim() : state.sessionid;
1010
- state = {
1011
- ...state,
1012
- state: "connected",
1013
- sessionid: sessionid !== "" ? sessionid : state.sessionid,
1014
- token: rotatedtoken !== "" ? rotatedtoken : state.token,
1015
- rotations: rotatedtoken !== "" ? state.rotations + 1 : state.rotations,
1016
- openedat: now(),
1017
- lastframeat: now(),
1018
- lastheartbeatat: now(),
1019
- acks: [...state.acks, envelope]
1020
- };
1021
- return { state, socket };
1022
- }
1023
- return {
1024
- state: { ...state, state: "closed", attempts: state.attempts, closedat: now(), lasterror },
1025
- error: lasterror
1026
- };
1027
- }
1028
- function chatrowsof(events, memberid) {
1029
- return events.filter((event) => event.kind === "chat").map((event) => ({
1030
- from: typeof event.payload.from === "string" ? event.payload.from : "",
1031
- text: typeof event.payload.text === "string" ? event.payload.text : "",
1032
- mine: typeof event.payload.from === "string" && event.payload.from === memberid,
1033
- at: event.at
1034
- }));
1035
- }
1036
- function reviewcardsof(events) {
1037
- return events.filter((event) => event.kind === "planproposal").map((event) => {
1038
- const steps = Array.isArray(event.payload.steps) ? event.payload.steps.filter((step) => typeof step.id === "string" && typeof step.kind === "string").map((step) => ({
1039
- id: String(step.id),
1040
- kind: String(step.kind),
1041
- origin: typeof step.origin === "string" ? step.origin : "",
1042
- sensitive: step.sensitive === true
1043
- })) : [];
1044
- return {
1045
- proposalid: typeof event.payload.proposalid === "string" ? event.payload.proposalid : "",
1046
- title: typeof event.payload.title === "string" ? event.payload.title : "",
1047
- steps,
1048
- ...typeof event.payload.timeoutat === "number" ? { timeoutat: event.payload.timeoutat } : {},
1049
- at: event.at
1050
- };
1051
- }).filter((card) => card.proposalid !== "" && card.title !== "");
1052
- }
1053
- function carddecision(card, decision, by, now, note) {
1054
- if (card.proposalid.trim() === "") throw new Error("The review decision names its proposal.");
1055
- if (decision !== "approved" && decision !== "changes" && decision !== "refused")
1056
- throw new Error("The review decision is approved, changes or refused.");
1057
- const reviewer = by.trim();
1058
- if (reviewer === "") throw new Error("The review decision names its reviewer.");
1059
- return {
1060
- proposalid: card.proposalid,
1061
- decision,
1062
- by: reviewer,
1063
- ...note !== void 0 && note.trim() !== "" ? { note: note.trim() } : {},
1064
- at: now
1065
- };
1066
- }
1067
- function decisionpayload(decision) {
1068
- return planrevieweventpayload(decision);
1069
- }
1070
- function reviewgateoutcome(decision) {
1071
- if (decision.decision === "approved")
1072
- return {
1073
- state: "approved",
1074
- reason: `The site review approved the plan proposal ${decision.proposalid}${decision.note !== void 0 ? ` with the note ${decision.note}` : ""}; the extension review gate resolves as approved and the extension stays the only executor.`
1075
- };
1076
- return {
1077
- state: "refused",
1078
- reason: `The site review returned ${decision.decision} for the plan proposal ${decision.proposalid}${decision.note !== void 0 ? ` with the note ${decision.note}` : ""}; the proposal returns to the review surface and no step executes.`
1079
- };
1080
- }
1081
- function chateventof(text, from) {
1082
- return { kind: "chat", stream: "chat", payload: chateventpayload({ text, from }) };
1083
- }
1084
- function planproposaleventof(card) {
1085
- return { kind: "planproposal", stream: "review", payload: planproposaleventpayload(card) };
1086
- }
1087
- function widgetview(input) {
1088
- const cards = reviewcardsof(input.events);
1089
- const answered = new Set(
1090
- input.events.filter((event) => event.kind === "planreview").map((event) => typeof event.payload.proposalid === "string" ? event.payload.proposalid : "").filter((id) => id !== "")
1091
- );
1092
- return {
1093
- status: input.status,
1094
- rows: chatrowsof(input.events, input.memberid),
1095
- cards,
1096
- pending: cards.filter((card) => !answered.has(card.proposalid)).length
1097
- };
1098
- }
1099
- function pairingpanel(record, now) {
1100
- const countdown = pairingcountdown(record, now);
1101
- return {
1102
- code: record.code.code,
1103
- secondsleft: countdown.secondsleft,
1104
- expired: countdown.expired,
1105
- label: countdown.label
1106
- };
1107
- }
1108
- function sitemanifest() {
1109
- return sitemanifestof();
1110
- }
1111
- function bridgestatuslabel(view) {
1112
- if (view.status === "connected")
1113
- return `Bridge: connected${view.paired ? " and paired" : ""}${view.queued > 0 ? ` \xB7 ${view.queued} queued frame${view.queued === 1 ? "" : "s"}` : ""}.`;
1114
- if (view.status === "paired")
1115
- return `Bridge: paired, socket offline${view.queued > 0 ? ` \xB7 ${view.queued} queued frame${view.queued === 1 ? "" : "s"}` : ""}.`;
1116
- if (view.status === "offline")
1117
- return `Bridge: offline${view.queued > 0 ? ` \xB7 ${view.queued} queued frame${view.queued === 1 ? "" : "s"}` : ""}.`;
1118
- return "Bridge: disabled (no relay url set).";
1119
- }
1120
- var wsbridgelocalhosts = ["127.0.0.1", "localhost", "::1", "[::1]"];
1121
- var wsbridgestreamname = "nativetransport";
1122
- function wsbridgebindcheck(input) {
1123
- const bind = (input.bind ?? "").trim() === "" ? "127.0.0.1" : (input.bind ?? "").trim();
1124
- if (!wsbridgelocalhosts.includes(bind))
1125
- return {
1126
- ok: false,
1127
- bind,
1128
- port: 0,
1129
- reason: `The wsbridge binds a localhost address only; the ${bind} address accepts connections from other machines and the bridge never leaves the machine.`
1130
- };
1131
- const port = input.port ?? 0;
1132
- if (!Number.isInteger(port) || port < 0 || port > 65535)
1133
- return {
1134
- ok: false,
1135
- bind,
1136
- port: 0,
1137
- reason: `The wsbridge port stays a whole number between zero and 65535; the zero port asks the socket for a random free port.`
1138
- };
1139
- return { ok: true, bind, port };
1140
- }
1141
- function wsbridgesessionstart(input) {
1142
- if (!Number.isInteger(input.port) || input.port < 0 || input.port > 65535)
1143
- throw new Error("The wsbridge session port stays a whole number between zero and 65535.");
1144
- const token = input.token.trim();
1145
- if (token === "")
1146
- throw new Error("The wsbridge session carries its per session token; an empty token authenticates nothing.");
1147
- if (input.idlewindow !== void 0 && (!Number.isFinite(input.idlewindow) || input.idlewindow <= 0))
1148
- throw new Error("The wsbridge idle window stays a positive millisecond count the user chose.");
1149
- return {
1150
- id: input.id ?? `wsbridge-${input.now}`,
1151
- port: input.port,
1152
- tokenhash: input.hashof(token),
1153
- boundat: input.now,
1154
- ...input.idlewindow !== void 0 ? { idlewindow: input.idlewindow, expiresat: input.now + input.idlewindow } : {},
1155
- extensionconnected: false,
1156
- connections: 0,
1157
- received: 0,
1158
- sent: 0
1159
- };
1160
- }
1161
- function wsbridgeconnection(session, now) {
1162
- const idlewindow = session.idlewindow;
1163
- return {
1164
- ...session,
1165
- connections: session.connections + 1,
1166
- lastframeat: now,
1167
- ...idlewindow !== void 0 ? { expiresat: now + idlewindow } : {}
1168
- };
1169
- }
1170
- function wsbridgeextensionconnect(session, now) {
1171
- if (session.extensionconnected)
1172
- return {
1173
- refused: `The wsbridge session holds one extension connection at a time; the extension side of the session ${session.id} stays taken.`
1174
- };
1175
- const connected = wsbridgeconnection(session, now);
1176
- return { session: { ...connected, extensionconnected: true } };
1177
- }
1178
- function wsbridgeframeauth(session, token, hashof) {
1179
- const trimmed = (token ?? "").trim();
1180
- if (trimmed === "")
1181
- return {
1182
- ok: false,
1183
- reason: "The wsbridge frame carries its session token; an anonymous frame refuses at the door."
1184
- };
1185
- if (hashof(trimmed) !== session.tokenhash)
1186
- return {
1187
- ok: false,
1188
- reason: `The wsbridge frame token fails the session ${session.id} authentication; a wrong token never reaches the body.`
1189
- };
1190
- return { ok: true };
1191
- }
1192
- function wsbridgeidlesweep(session, now) {
1193
- if (session.idlewindow === void 0 || session.expiresat === void 0) return { expired: false, session };
1194
- if (session.lastframeat !== void 0 && session.lastframeat > session.expiresat - session.idlewindow) {
1195
- const slid = { ...session, expiresat: session.lastframeat + session.idlewindow };
1196
- if (now < slid.expiresat) return { expired: false, session: slid };
1197
- }
1198
- if (now >= session.expiresat)
1199
- return {
1200
- expired: true,
1201
- session,
1202
- reason: `The wsbridge session ${session.id} sat quiet past its ${session.idlewindow} millisecond idle window; the session expired and the token stopped verifying.`
1203
- };
1204
- return { expired: false, session };
1205
- }
1206
- function wsbridgeenvelopeof(input) {
1207
- return composeenvelope({
1208
- op: "eventpost",
1209
- opid: input.opid,
1210
- at: input.at,
1211
- version: input.version ?? servercontractversion,
1212
- ...input.sessionid !== void 0 && input.sessionid !== "" ? { sessionid: input.sessionid } : {},
1213
- ...input.token !== void 0 && input.token !== "" ? { token: input.token } : {},
1214
- body: { kind: "progress", stream: wsbridgestreamname, payload: { frame: input.frame } }
1215
- });
1216
- }
1217
- function wsbridgeframeof(envelope) {
1218
- if (envelope.op !== "eventpost")
1219
- return {
1220
- reason: `The wsbridge envelope carries the eventpost operation; a ${envelope.op} envelope never reaches the native transport.`
1221
- };
1222
- const body = envelope.body ?? {};
1223
- if (body.stream !== wsbridgestreamname)
1224
- return {
1225
- reason: `The wsbridge envelope rides the ${wsbridgestreamname} stream; a ${String(body.stream)} envelope stays outside the native transport.`
1226
- };
1227
- const frame = body.payload;
1228
- if (frame === void 0 || frame === null || typeof frame !== "object" || Array.isArray(frame))
1229
- return { reason: "The wsbridge envelope payload carries the native frame object." };
1230
- const candidate = frame.frame;
1231
- if (candidate === void 0 || candidate === null || typeof candidate !== "object" || Array.isArray(candidate))
1232
- return { reason: "The wsbridge envelope payload wraps its native frame under the frame key." };
1233
- const typed = candidate;
1234
- if (typeof typed.kind !== "string" || typeof typed.correlationid !== "string")
1235
- return { reason: "The wsbridge native frame carries its kind and its correlation id." };
1236
- return {
1237
- frame: {
1238
- kind: typed.kind,
1239
- correlationid: typed.correlationid,
1240
- ...typeof typed.sessionid === "string" ? { sessionid: typed.sessionid } : {},
1241
- ...typed.body !== void 0 && typed.body !== null && typeof typed.body === "object" && !Array.isArray(typed.body) ? { body: typed.body } : {}
1242
- }
1243
- };
1244
- }
1245
- function wsbridgeadvertiseframe(session, token, correlationid) {
1246
- const trimmed = token.trim();
1247
- if (trimmed === "")
1248
- throw new Error("The wsbridge advertisement carries the per session token; an empty token advertises nothing.");
1249
- return {
1250
- kind: "advertisement",
1251
- correlationid,
1252
- body: {
1253
- port: session.port,
1254
- token: trimmed,
1255
- ...session.idlewindow !== void 0 ? { idlewindow: session.idlewindow } : {}
1256
- }
1257
- };
1258
- }
1259
- function wsbridgereport(session, now) {
1260
- const sweep = wsbridgeidlesweep(session, now);
1261
- return {
1262
- id: session.id,
1263
- port: session.port,
1264
- connections: session.connections,
1265
- extensionconnected: session.extensionconnected,
1266
- expired: sweep.expired,
1267
- received: session.received,
1268
- sent: session.sent
1269
- };
1270
- }
1271
- function wsbridgeframecounted(session, direction, now) {
1272
- const idlewindow = session.idlewindow;
1273
- return {
1274
- ...session,
1275
- received: session.received + (direction === "received" ? 1 : 0),
1276
- sent: session.sent + (direction === "sent" ? 1 : 0),
1277
- lastframeat: now,
1278
- ...idlewindow !== void 0 ? { expiresat: now + idlewindow } : {}
1279
- };
1280
- }
1281
- var nativebridgeprotocolmajor = 1;
1282
- var nativehostinstallerversion = protocolversion;
1283
- var nativehostidplaceholder = "__generated_extension_id__";
1284
- var nativemessagingdirname = "NativeMessagingHosts";
1285
- function nativesurfacecatalog() {
1286
- return [
1287
- {
1288
- surface: "osdialog",
1289
- callclass: "sensitive",
1290
- description: "Opens one os dialog on the user desktop; the surface addresses the user directly, so the call class stays sensitive and the surface asks for its own consent grant."
1291
- },
1292
- {
1293
- surface: "notification",
1294
- callclass: "interaction",
1295
- description: "Posts one os notification on the user desktop; the surface writes outside the browser, so the call class stays interaction and the surface asks for its own consent grant."
1296
- }
1297
- ];
1298
- }
1299
- function nativehostcapabilities() {
1300
- return {
1301
- protocol: nativebridgeprotocolmajor,
1302
- surfaces: nativesurfacecatalog().map((entry) => entry.surface),
1303
- heartbeat: true
1304
- };
1305
- }
1306
- function nativehostmanifesttemplate(input) {
1307
- const hostname = input.hostname.trim();
1308
- if (hostname === "") throw new Error("The native host manifest names its host; an empty host name never registers.");
1309
- if (!/^[a-z0-9][a-z0-9._-]*$/.test(hostname))
1310
- throw new Error(
1311
- `The native host name ${hostname} stays a plain dns style token; a name with spaces or capitals never registers.`
1312
- );
1313
- const companionpath = input.companionpath.trim();
1314
- if (companionpath === "")
1315
- throw new Error(
1316
- "The native host manifest carries the companion path the user chose; an empty path never launches a host."
1317
- );
1318
- const extensionid = (input.extensionid ?? "").trim();
1319
- const scheme = "chrome-extension:";
1320
- const origin = extensionid === "" ? `${scheme}//${nativehostidplaceholder}/` : `${scheme}//${extensionid}/`;
1321
- const manifest = {
1322
- name: hostname,
1323
- description: "The devthink companion process: an optional native host that speaks length prefixed json over stdio and never runs until the user installs it.",
1324
- path: companionpath,
1325
- type: "stdio",
1326
- allowed_origins: [origin]
1327
- };
1328
- return { manifest, text: `${JSON.stringify(manifest, null, 2)}
1329
- ` };
1330
- }
1331
- function trailslashes(value) {
1332
- let end = value.length;
1333
- while (end > 0) {
1334
- const last = value.charCodeAt(end - 1);
1335
- if (last !== 47 && last !== 92) break;
1336
- end -= 1;
1337
- }
1338
- return value.slice(0, end);
1339
- }
1340
- function hostmanifestdestination(input) {
1341
- const hostname = input.hostname.trim();
1342
- if (hostname === "")
1343
- return {
1344
- path: "",
1345
- systemwide: false,
1346
- refused: "The host manifest destination names its host; an empty host name never writes."
1347
- };
1348
- const systemwide = input.systemwide === true;
1349
- const profiledir = (input.profiledir ?? "").trim();
1350
- if (!systemwide && profiledir === "")
1351
- return {
1352
- path: "",
1353
- systemwide: false,
1354
- refused: "The installer writes the host manifest into the user profile directory; a system wide install needs the explicit flag and the user never gets one silently."
1355
- };
1356
- if (systemwide) {
1357
- const platform = input.platform ?? "linux";
1358
- const base = platform === "linux" ? "/etc/opt/chrome/native-messaging-hosts" : platform === "macos" ? "/Library/Google/Chrome/NativeMessagingHosts" : "C:\\Program Files\\Google\\Chrome\\Application\\native-messaging-hosts";
1359
- return { path: `${base}/${hostname}.json`, systemwide: true };
1360
- }
1361
- return { path: `${trailslashes(profiledir)}/${nativemessagingdirname}/${hostname}.json`, systemwide: false };
1362
- }
1363
- async function installnativehost(input) {
1364
- if (!input.consent)
1365
- return {
1366
- state: nativedefaultstate(),
1367
- manifestpath: "",
1368
- refused: "The install consent gate explains the scope before any host registration; the installer writes no manifest without the recorded consent."
1369
- };
1370
- const extensionid = input.extensionid.trim();
1371
- if (extensionid === "")
1372
- return {
1373
- state: nativedefaultstate(),
1374
- manifestpath: "",
1375
- refused: "The host manifest allows the origins of one extension id; an empty id never registers a host."
1376
- };
1377
- if (input.systemwide === true && (input.profiledir ?? "").trim() !== "")
1378
- return {
1379
- state: nativedefaultstate(),
1380
- manifestpath: "",
1381
- refused: "The install targets either the user profile directory or, with the explicit flag, the system directory; never both at once."
1382
- };
1383
- const destination = hostmanifestdestination({
1384
- hostname: input.hostname,
1385
- ...input.profiledir !== void 0 ? { profiledir: input.profiledir } : {},
1386
- ...input.systemwide !== void 0 ? { systemwide: input.systemwide } : {},
1387
- ...input.platform !== void 0 ? { platform: input.platform } : {}
1388
- });
1389
- if (destination.refused !== void 0)
1390
- return { state: nativedefaultstate(), manifestpath: "", refused: destination.refused };
1391
- const template = nativehostmanifesttemplate({
1392
- hostname: input.hostname,
1393
- companionpath: input.companionpath,
1394
- extensionid
1395
- });
1396
- const dir = destination.path.slice(0, destination.path.lastIndexOf("/"));
1397
- await input.io.mkdir(dir);
1398
- await input.io.writefile(destination.path, template.text);
1399
- const state = {
1400
- installed: true,
1401
- hostname: template.manifest.name,
1402
- extensionid,
1403
- installerversion: nativehostinstallerversion,
1404
- port: "detached",
1405
- installedat: input.now,
1406
- updatedat: input.now,
1407
- lasterrors: []
1408
- };
1409
- return { state, manifestpath: destination.path };
1410
- }
1411
- async function uninstallnativehost(input) {
1412
- const destination = hostmanifestdestination({
1413
- hostname: input.hostname,
1414
- ...input.profiledir !== void 0 ? { profiledir: input.profiledir } : {},
1415
- ...input.systemwide !== void 0 ? { systemwide: input.systemwide } : {},
1416
- ...input.platform !== void 0 ? { platform: input.platform } : {}
1417
- });
1418
- if (destination.refused !== void 0)
1419
- return { state: nativedefaultstate(), manifestpath: "", removed: false, refused: destination.refused };
1420
- const present = await input.io.exists(destination.path);
1421
- if (present) await input.io.removefile(destination.path);
1422
- return { state: nativedefaultstate(), manifestpath: destination.path, removed: present };
1423
- }
1424
- function nativedefaultstate() {
1425
- return { installed: false, port: "detached", lasterrors: [] };
1426
- }
1427
- function nativechoices(settings) {
1428
- const current = settings ?? {};
1429
- return {
1430
- ...current.nativeinstallconsent !== void 0 ? { nativeinstallconsent: current.nativeinstallconsent } : {},
1431
- ...current.nativetransportconsent !== void 0 ? { nativetransportconsent: current.nativetransportconsent } : {},
1432
- ...current.nativecallclassconsents !== void 0 ? { nativecallclassconsents: current.nativecallclassconsents } : {},
1433
- ...current.nativesurfaceconsents !== void 0 ? { nativesurfaceconsents: current.nativesurfaceconsents } : {},
1434
- ...current.nativeidlewindow !== void 0 ? { nativeidlewindow: current.nativeidlewindow } : {},
1435
- ...current.nativeheartbeatinterval !== void 0 ? { nativeheartbeatinterval: current.nativeheartbeatinterval } : {},
1436
- ...current.nativecallratelimit !== void 0 ? { nativecallratelimit: current.nativecallratelimit } : {},
1437
- ...current.nativecallratewindow !== void 0 ? { nativecallratewindow: current.nativecallratewindow } : {}
1438
- };
1439
- }
1440
- function nativetransportenabled(state, settings) {
1441
- return (state?.installed ?? false) && settings?.nativetransportconsent === true;
1442
- }
1443
- function nativecorrelationid(seed, sequence) {
1444
- const trimmed = seed.trim();
1445
- if (trimmed === "")
1446
- throw new Error("The correlation id names its sender seed; an empty seed never correlates a frame.");
1447
- if (!Number.isInteger(sequence) || sequence < 1)
1448
- throw new Error("The correlation id sequence stays a positive whole number per run.");
1449
- return `run-${trimmed}-${sequence}`;
1450
- }
1451
- function nativeframeof(kind, correlationid, body, sessionid) {
1452
- const trimmed = correlationid.trim();
1453
- if (trimmed === "")
1454
- throw new Error("The native frame carries its correlation id; an empty id never correlates a frame.");
1455
- return {
1456
- kind,
1457
- correlationid: trimmed,
1458
- ...sessionid !== void 0 && sessionid !== "" ? { sessionid } : {},
1459
- ...body !== void 0 ? { body } : {}
1460
- };
1461
- }
1462
- function companionhandshakeframe(correlationid) {
1463
- return nativeframeof("handshake", correlationid, { protocol: nativebridgeprotocolmajor });
1464
- }
1465
- function parsecompanionhandshake(frame, now) {
1466
- if (frame.kind !== "handshake")
1467
- return {
1468
- error: nativeerrorof(
1469
- "handshake",
1470
- `The handshake answer carries the handshake kind; a ${frame.kind} frame never completes a handshake.`,
1471
- "reconnect",
1472
- now
1473
- )
1474
- };
1475
- const body = frame.body ?? {};
1476
- const build = typeof body.build === "string" ? body.build.trim() : "";
1477
- if (build === "")
1478
- return {
1479
- error: nativeerrorof(
1480
- "handshake",
1481
- "The handshake answer carries the companion build version; an empty version never attaches.",
1482
- "reconnect",
1483
- now
1484
- )
1485
- };
1486
- const protocol = typeof body.protocol === "number" ? body.protocol : Number.parseInt(String(body.protocol ?? ""), 10);
1487
- if (!Number.isInteger(protocol) || protocol < 1)
1488
- return {
1489
- error: nativeerrorof(
1490
- "handshake",
1491
- "The handshake answer carries its native bridge protocol version as a positive whole number.",
1492
- "reconnect",
1493
- now
1494
- )
1495
- };
1496
- const surfaces = Array.isArray(body.surfaces) ? body.surfaces.filter(
1497
- (surface) => surface === "osdialog" || surface === "notification"
1498
- ) : [];
1499
- const wsbridgeport = typeof body.wsbridgeport === "number" ? body.wsbridgeport : 0;
1500
- if (!Number.isInteger(wsbridgeport) || wsbridgeport < 0)
1501
- return {
1502
- error: nativeerrorof(
1503
- "handshake",
1504
- "The handshake answer carries the wsbridge port as a whole number; zero keeps the bridge down.",
1505
- "reconnect",
1506
- now
1507
- )
1508
- };
1509
- return { handshake: { build, protocol: String(protocol), surfaces, wsbridgeport } };
1510
- }
1511
- function nativemajorversion(protocol) {
1512
- const value = typeof protocol === "number" ? String(protocol) : protocol.trim();
1513
- const major = Number.parseInt(value.split(/[.\s]/)[0] ?? "", 10);
1514
- return Number.isInteger(major) && major >= 1 ? major : 0;
1515
- }
1516
- function nativeprotocolcompatible(ours, theirs) {
1517
- const ourmajor = nativemajorversion(ours);
1518
- const theirmajor = nativemajorversion(theirs);
1519
- return { ok: ourmajor === theirmajor && ourmajor >= 1, ours: ourmajor, theirs: theirmajor };
1520
- }
1521
- function negotiatenativecapabilities(input) {
1522
- const ours = input.ours ?? nativehostcapabilities();
1523
- const compat = nativeprotocolcompatible(ours.protocol, input.theirs.protocol);
1524
- if (!compat.ok)
1525
- return {
1526
- ok: false,
1527
- protocol: 0,
1528
- surfaces: [],
1529
- heartbeat: false,
1530
- reason: `The companion speaks the native bridge protocol major version ${compat.theirs} while this build speaks ${compat.ours}; the upgrade path keeps compatibility for one major version and the run degrades with the transport off.`
1531
- };
1532
- const order = nativesurfacecatalog().map((entry) => entry.surface);
1533
- const surfaces = order.filter((surface) => input.theirs.surfaces.includes(surface));
1534
- return { ok: true, protocol: compat.ours, surfaces, heartbeat: ours.heartbeat && input.theirs.heartbeat === true };
1535
- }
1536
- function attachnativehost(state, handshake, now) {
1537
- return {
1538
- ...state,
1539
- installed: true,
1540
- port: "attached",
1541
- companionversion: handshake.build,
1542
- companionprotocol: handshake.protocol,
1543
- wsbridgeport: handshake.wsbridgeport,
1544
- attachedat: now,
1545
- updatedat: now
1546
- };
1547
- }
1548
- function crashnativehost(state, now) {
1549
- return {
1550
- ...state,
1551
- port: "crashed",
1552
- updatedat: now,
1553
- lasterrors: [
1554
- nativeerrorof(
1555
- "port",
1556
- "The companion process crashed under the native port; the run stays alive and the extension reattaches on the next host start.",
1557
- "reconnect",
1558
- now
1559
- ),
1560
- ...state.lasterrors ?? []
1561
- ].slice(0, 10)
1562
- };
1563
- }
1564
- function reattachnativehost(state, handshake, now) {
1565
- return { ...attachnativehost(state, handshake, now), updatedat: now };
1566
- }
1567
- function detachnativehost(state, now) {
1568
- return { ...state, port: "detached", updatedat: now };
1569
- }
1570
- function nativeheartbeatframe(correlationid, now) {
1571
- return nativeframeof("heartbeat", correlationid, { at: now });
1572
- }
1573
- function nativeportliveness(input) {
1574
- if (input.interval === void 0)
1575
- return {
1576
- alive: true,
1577
- reason: "The heartbeat interval stays unset; the liveness check never expires a host without the user configured cadence."
1578
- };
1579
- if (input.lastheartbeatat === void 0)
1580
- return {
1581
- alive: false,
1582
- reason: "The native port heard no heartbeat yet; the host stays silent under the configured interval."
1583
- };
1584
- if (input.now - input.lastheartbeatat > input.interval)
1585
- return {
1586
- alive: false,
1587
- reason: `The last heartbeat sits ${input.now - input.lastheartbeatat} milliseconds back, past the ${input.interval} millisecond interval; the host process stays silent and the extension reattaches on its restart.`
1588
- };
1589
- return { alive: true };
1590
- }
1591
- function nativeframecheck(frame, sessionid) {
1592
- if (frame.correlationid.trim() === "")
1593
- return {
1594
- allowed: false,
1595
- reason: "The native frame carries its correlation id; an anonymous frame never reaches the engine."
1596
- };
1597
- if (sessionid.trim() === "")
1598
- return {
1599
- allowed: false,
1600
- reason: "The native transport pairs its frames with the session id; a transport without a session never accepts a frame."
1601
- };
1602
- if (frame.sessionid !== void 0 && frame.sessionid !== sessionid)
1603
- return {
1604
- allowed: false,
1605
- reason: `The native frame session ${frame.sessionid} sits outside the paired session ${sessionid}; the origin and session checks refuse the frame.`
1606
- };
1607
- return { allowed: true };
1608
- }
1609
- var nativesecretkeys = [
1610
- "apikey",
1611
- "api_key",
1612
- "key",
1613
- "token",
1614
- "secret",
1615
- "password",
1616
- "authorization",
1617
- "credential",
1618
- "privatekey"
1619
- ];
1620
- function nativesecretexclusion(frame) {
1621
- const body = frame.body ?? {};
1622
- const held = Object.keys(body).filter(
1623
- (key) => nativesecretkeys.includes(key.toLowerCase().replaceAll(" ", "").replaceAll("-", ""))
1624
- );
1625
- return { ok: held.length === 0, held };
1626
- }
1627
- function redactnativeframe(frame) {
1628
- const body = frame.body ?? {};
1629
- const redacted = {};
1630
- for (const [key, value] of Object.entries(body))
1631
- if (!nativesecretkeys.includes(key.toLowerCase().replaceAll(" ", "").replaceAll("-", ""))) redacted[key] = value;
1632
- return { ...frame, body: redacted };
1633
- }
1634
- function nativeerrorof(family, message, retry, now) {
1635
- return { family, message, retry, at: now };
1636
- }
1637
- function nativefailureof(error) {
1638
- const retryhint = error.retry === "reconnect" ? "retry" : error.retry === "reinstall" ? "wait" : "none";
1639
- return { retryhint, reason: `${error.family} failure: ${error.message}` };
1640
- }
1641
- function nativedegradationof(input) {
1642
- if ((input.state?.installed ?? false) === false)
1643
- return {
1644
- degraded: true,
1645
- reason: "The native host stays absent: nothing installed, the transport disabled and the run alive with every step inside the browser."
1646
- };
1647
- if (input.negotiated !== void 0 && !input.negotiated.ok)
1648
- return {
1649
- degraded: true,
1650
- reason: input.negotiated.reason ?? "The native host speaks another native bridge protocol major version; the run stays alive with the transport off."
1651
- };
1652
- if (input.state?.port === "crashed")
1653
- return {
1654
- degraded: true,
1655
- reason: "The native host crashed under the port; the run stays alive and waits for the reattach on the host restart."
1656
- };
1657
- return {
1658
- degraded: false,
1659
- reason: "The native host sits attached with a negotiated capability set; the transport carries the consented call classes."
1660
- };
1661
- }
1662
- function nativeratecheck(input) {
1663
- if (input.cap === void 0) return { allowed: true, used: input.calls.length };
1664
- if (!Number.isFinite(input.cap) || input.cap < 1)
1665
- return {
1666
- allowed: false,
1667
- used: input.calls.length,
1668
- cap: input.cap,
1669
- reason: `The native transport rate cap of ${String(input.cap)} stays a finite positive count.`
1670
- };
1671
- const window = input.window ?? Number.POSITIVE_INFINITY;
1672
- const used = input.calls.filter(
1673
- (record) => window === Number.POSITIVE_INFINITY || input.now - record.at <= window
1674
- ).length;
1675
- if (used >= input.cap)
1676
- return {
1677
- allowed: false,
1678
- used,
1679
- cap: input.cap,
1680
- reason: `The native transport hit its ${input.cap} call cap with ${used} calls inside the window; the cap stays the user's choice and the session waits.`
1681
- };
1682
- return { allowed: true, used, cap: input.cap };
1683
- }
1684
- function nativecallrecordof(input) {
1685
- return {
1686
- id: input.id,
1687
- correlationid: input.correlationid,
1688
- surface: input.surface,
1689
- callclass: input.callclass,
1690
- outcome: input.outcome,
1691
- ...input.reason !== void 0 && input.reason !== "" ? { reason: input.reason } : {},
1692
- at: input.now
1693
- };
1694
- }
1695
- function recordnativecall(records, record) {
1696
- return [record, ...records.filter((candidate) => candidate.id !== record.id)];
1697
- }
1698
- function nativecallevent(record) {
1699
- return notificationframe("native/call", {
1700
- surface: record.surface,
1701
- callclass: record.callclass,
1702
- outcome: record.outcome,
1703
- correlationid: record.correlationid,
1704
- at: record.at
1705
- });
1706
- }
1707
- function nativesurfacegrant(surface, settings) {
1708
- const known = nativesurfacecatalog().find((entry) => entry.surface === surface);
1709
- if (known === void 0)
1710
- return {
1711
- allowed: false,
1712
- reason: `The native surface ${surface} sits outside the surface catalog; an unknown surface never grants.`
1713
- };
1714
- if ((settings?.nativesurfaceconsents ?? []).includes(known.surface))
1715
- return {
1716
- allowed: true,
1717
- reason: `The user granted the ${known.surface} surface its own consent stamp; the surface runs behind the class gate too.`
1718
- };
1719
- return {
1720
- allowed: false,
1721
- reason: `The native surface ${known.surface} holds no consent grant; a desktop surface never opens from a class grant alone.`
1722
- };
1723
- }
1724
- function nativeclassgrant(callclass, settings) {
1725
- if ((settings?.nativecallclassconsents ?? []).includes(callclass))
1726
- return { allowed: true, reason: `The user consented to the ${callclass} call class over the native transport.` };
1727
- return {
1728
- allowed: false,
1729
- reason: `The ${callclass} call class holds no consent grant over the native transport; the gate asks per class and never widens a read grant.`
1730
- };
1731
- }
1732
- function nativesurfaceresult(input) {
1733
- const catalog = nativesurfacecatalog().find((entry) => entry.surface === input.surface);
1734
- const callclass = catalog?.callclass ?? input.callclass;
1735
- const held = Object.keys(input.details).filter(
1736
- (key) => nativesecretkeys.includes(key.toLowerCase().replaceAll(" ", "").replaceAll("-", ""))
1737
- );
1738
- const details = { ...input.details };
1739
- for (const key of held) delete details[key];
1740
- return { surface: input.surface, callclass, details, at: input.now };
1741
- }
1742
- function nativediagnostics(input) {
1743
- const state = input.state ?? nativedefaultstate();
1744
- const settings = input.settings;
1745
- const sessions = (input.sessions ?? []).map((session) => ({
1746
- port: session.port,
1747
- connections: session.connections,
1748
- expired: session.expiresat !== void 0 && session.expiresat <= input.now
1749
- }));
1750
- return {
1751
- installed: state.installed,
1752
- port: state.port,
1753
- ...state.hostname !== void 0 ? { hostname: state.hostname } : {},
1754
- ...state.extensionid !== void 0 ? { extensionid: state.extensionid } : {},
1755
- ...state.installerversion !== void 0 ? { installerversion: state.installerversion } : {},
1756
- ...state.companionversion !== void 0 ? { companionversion: state.companionversion } : {},
1757
- ...state.companionprotocol !== void 0 ? { companionprotocol: state.companionprotocol } : {},
1758
- ...state.wsbridgeport !== void 0 ? { wsbridgeport: state.wsbridgeport } : {},
1759
- nativebridgeprotocol: nativebridgeprotocolmajor,
1760
- degraded: nativedegradationof({
1761
- state,
1762
- ...input.negotiated !== void 0 ? { negotiated: input.negotiated } : {}
1763
- }),
1764
- transportconsent: settings?.nativetransportconsent === true,
1765
- classconsents: settings?.nativecallclassconsents ?? [],
1766
- surfaceconsents: settings?.nativesurfaceconsents ?? [],
1767
- sessions,
1768
- lasterrors: state.lasterrors ?? []
1769
- };
1770
- }
1771
- export {
1772
- attachnativehost,
1773
- bridgeframerate,
1774
- bridgepayload,
1775
- bridgestatuslabel,
1776
- bridgestatusview,
1777
- carddecision,
1778
- chateventof,
1779
- chateventpayload,
1780
- chatrowsof,
1781
- companionhandshakeframe,
1782
- composeenvelope,
1783
- connectrelay,
1784
- contractcapabilities,
1785
- crashnativehost,
1786
- decisionpayload,
1787
- detachnativehost,
1788
- disconnectrelay,
1789
- enqueuebridge,
1790
- envelopeacceptance,
1791
- eventpostbody,
1792
- eventstreambody,
1793
- frameauth,
1794
- frameof,
1795
- heartbeatevent,
1796
- heartbeattick,
1797
- hostmanifestdestination,
1798
- idleexpired,
1799
- installnativehost,
1800
- minimalplandigest,
1801
- nativebridgeprotocolmajor,
1802
- nativecallevent,
1803
- nativecallrecordof,
1804
- nativechoices,
1805
- nativeclassgrant,
1806
- nativecorrelationid,
1807
- nativedefaultstate,
1808
- nativedegradationof,
1809
- nativediagnostics,
1810
- nativeerrorof,
1811
- nativefailureof,
1812
- nativeframecheck,
1813
- nativeframeof,
1814
- nativeheartbeatframe,
1815
- nativehostcapabilities,
1816
- nativehostidplaceholder,
1817
- nativehostinstallerversion,
1818
- nativehostmanifesttemplate,
1819
- nativemajorversion,
1820
- nativemessagingdirname,
1821
- nativeportliveness,
1822
- nativeprotocolcompatible,
1823
- nativeratecheck,
1824
- nativesecretexclusion,
1825
- nativesecretkeys,
1826
- nativesurfacecatalog,
1827
- nativesurfacegrant,
1828
- nativesurfaceresult,
1829
- nativetransportenabled,
1830
- negotiatecapabilities,
1831
- negotiatenativecapabilities,
1832
- newrelayclient,
1833
- pagecontentkeys,
1834
- pairingpanel,
1835
- parsecompanionhandshake,
1836
- parseenvelope,
1837
- parsewireframe,
1838
- planproposaleventof,
1839
- planproposaleventpayload,
1840
- planrevieweventpayload,
1841
- postevent,
1842
- progresseventpayload,
1843
- reattachnativehost,
1844
- receiveframe,
1845
- recordnativecall,
1846
- redactnativeframe,
1847
- relayorigin,
1848
- replaybridgequeue,
1849
- reviewcardsof,
1850
- reviewgateoutcome,
1851
- sendframe,
1852
- servercontractversion,
1853
- servereventtypes,
1854
- serveroperations,
1855
- sessioncreatebody,
1856
- sessionjoinbody,
1857
- sitemanifest,
1858
- sitemanifestof,
1859
- stableopid,
1860
- uninstallnativehost,
1861
- verifyframeauth,
1862
- widgetview,
1863
- wsbridgeadvertiseframe,
1864
- wsbridgebindcheck,
1865
- wsbridgeconnection,
1866
- wsbridgeenvelopeof,
1867
- wsbridgeextensionconnect,
1868
- wsbridgeframeauth,
1869
- wsbridgeframecounted,
1870
- wsbridgeframeof,
1871
- wsbridgeidlesweep,
1872
- wsbridgelocalhosts,
1873
- wsbridgereport,
1874
- wsbridgesessionstart,
1875
- wsbridgestreamname
1876
- };
1877
- //# sourceMappingURL=bridge.js.map