fnloom 0.3.0 → 0.4.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 (587) hide show
  1. package/README.md +27 -20
  2. package/package.json +14 -11
  3. package/packages/build/package.json +2 -2
  4. package/packages/build/src/tests.ts +2 -2
  5. package/packages/cli/package.json +1 -1
  6. package/packages/cli/src/cli.ts +2 -2
  7. package/packages/cli/src/command.ts +2 -2
  8. package/packages/cli/src/commands/install.ts +1 -1
  9. package/packages/cli/src/commands/mcp.ts +6 -6
  10. package/packages/cli/src/commands/store.ts +3 -3
  11. package/packages/cli/src/hub.ts +25 -25
  12. package/packages/cli/src/index.ts +1 -1
  13. package/packages/cli/src/io.ts +2 -2
  14. package/packages/cli/src/local.ts +7 -7
  15. package/packages/cli/src/premade.ts +1 -1
  16. package/packages/core/package.json +4 -4
  17. package/packages/core/src/auto-pair.ts +1 -1
  18. package/packages/core/src/connections.ts +1 -14
  19. package/packages/core/src/context-graph.ts +1 -1
  20. package/packages/core/src/data.ts +1 -1
  21. package/packages/core/src/https.ts +2 -2
  22. package/packages/core/src/identity.ts +1 -1
  23. package/packages/core/src/image-embeddings.ts +1 -1
  24. package/packages/core/src/index.ts +5 -7
  25. package/packages/core/src/link.ts +1 -1
  26. package/packages/core/src/manifest.ts +2 -2
  27. package/packages/core/src/mention-search.ts +1 -1
  28. package/packages/core/src/model-calls.ts +1 -1
  29. package/packages/core/src/package.ts +1 -1
  30. package/packages/core/src/ports.ts +2 -2
  31. package/packages/core/src/query.ts +1 -1
  32. package/packages/core/src/records/chat.ts +1 -1
  33. package/packages/core/src/records/runs.ts +1 -1
  34. package/packages/core/src/records/spend.ts +4 -0
  35. package/packages/core/src/registries.ts +9 -3
  36. package/packages/core/src/sso.ts +2 -2
  37. package/packages/core/src/stores.ts +1 -1
  38. package/packages/core/src/suggestions.ts +2 -2
  39. package/packages/core/src/system-pages.ts +32 -6
  40. package/packages/core/src/tables.ts +233 -0
  41. package/packages/core/src/visuals.ts +47 -139
  42. package/packages/core/src/web.ts +2 -2
  43. package/packages/core/src/widgets-v1.ts +78 -1
  44. package/packages/hub/package.json +13 -11
  45. package/packages/hub/src/api/admin-ops.ts +5 -5
  46. package/packages/hub/src/api/auth.ts +2 -2
  47. package/packages/hub/src/api/https.ts +6 -6
  48. package/packages/hub/src/api/identities.ts +1 -1
  49. package/packages/hub/src/api/reads.ts +1 -1
  50. package/packages/hub/src/api/secrets.ts +1 -1
  51. package/packages/hub/src/api/serve.ts +2 -2
  52. package/packages/hub/src/api/sso-route.ts +2 -2
  53. package/packages/hub/src/api/sso.ts +6 -6
  54. package/packages/hub/src/api/testing/rig.ts +1 -1
  55. package/packages/hub/src/api/tls.ts +2 -2
  56. package/packages/hub/src/api/web/auth.ts +1 -1
  57. package/packages/hub/src/api/web/find.ts +1 -1
  58. package/packages/hub/src/api/web/pages.ts +4 -3
  59. package/packages/hub/src/api/web/pickers.ts +4 -4
  60. package/packages/hub/src/boot/env.ts +82 -78
  61. package/packages/hub/src/boot/hub-fns.ts +1 -1
  62. package/packages/hub/src/boot/identity.ts +2 -2
  63. package/packages/hub/src/boot/index.ts +1 -1
  64. package/packages/hub/src/boot/info.ts +1 -1
  65. package/packages/hub/src/boot/keys.ts +6 -6
  66. package/packages/hub/src/boot/log.ts +4 -4
  67. package/packages/hub/src/boot/modules.ts +4 -4
  68. package/packages/hub/src/boot/services.ts +9 -9
  69. package/packages/hub/src/boot/start.ts +23 -23
  70. package/packages/hub/src/chat/cache.ts +1 -1
  71. package/packages/hub/src/chat/chat.ts +1 -1
  72. package/packages/hub/src/chat/compare.ts +2 -2
  73. package/packages/hub/src/chat/deliveries.ts +1 -1
  74. package/packages/hub/src/chat/deps.ts +3 -3
  75. package/packages/hub/src/chat/enrich.ts +7 -7
  76. package/packages/hub/src/chat/env.ts +20 -20
  77. package/packages/hub/src/chat/mention-requests.ts +1 -1
  78. package/packages/hub/src/chat/mention-search.ts +1 -1
  79. package/packages/hub/src/chat/mentions.ts +3 -3
  80. package/packages/hub/src/chat/notifications.ts +2 -2
  81. package/packages/hub/src/chat/presence.ts +2 -2
  82. package/packages/hub/src/chat/sessions.ts +2 -2
  83. package/packages/hub/src/chat/suggestions.ts +8 -8
  84. package/packages/hub/src/chat/testing.ts +1 -1
  85. package/packages/hub/src/chat/turns.ts +6 -6
  86. package/packages/hub/src/chat/undo.ts +1 -1
  87. package/packages/hub/src/connections/create.ts +1 -1
  88. package/packages/hub/src/connections/env.ts +2 -2
  89. package/packages/hub/src/connections/service.ts +5 -9
  90. package/packages/hub/src/contextor/contextors.ts +9 -9
  91. package/packages/hub/src/contextor/crawl.ts +1 -1
  92. package/packages/hub/src/contextor/create.ts +5 -5
  93. package/packages/hub/src/contextor/dynamic.ts +5 -5
  94. package/packages/hub/src/contextor/env.ts +46 -46
  95. package/packages/hub/src/contextor/injected.ts +1 -1
  96. package/packages/hub/src/contextor/limits.ts +9 -9
  97. package/packages/hub/src/contextor/planner.ts +11 -11
  98. package/packages/hub/src/contextor/testing.ts +1 -1
  99. package/packages/hub/src/data/env.ts +3 -3
  100. package/packages/hub/src/data/service.ts +5 -5
  101. package/packages/hub/src/execution/agent.ts +8 -8
  102. package/packages/hub/src/execution/ai.ts +7 -7
  103. package/packages/hub/src/execution/create.ts +11 -6
  104. package/packages/hub/src/execution/env.ts +16 -16
  105. package/packages/hub/src/execution/executors.ts +2 -2
  106. package/packages/hub/src/execution/gateway.ts +1 -1
  107. package/packages/hub/src/execution/index.ts +1 -1
  108. package/packages/hub/src/execution/ledger.ts +2 -2
  109. package/packages/hub/src/execution/limits.ts +2 -2
  110. package/packages/hub/src/execution/models.ts +2 -2
  111. package/packages/hub/src/execution/ports.ts +1 -1
  112. package/packages/hub/src/execution/providers.ts +55 -11
  113. package/packages/hub/src/execution/queues.ts +6 -6
  114. package/packages/hub/src/execution/runs.ts +10 -10
  115. package/packages/hub/src/execution/stream-guard.ts +2 -2
  116. package/packages/hub/src/execution/testing.ts +5 -5
  117. package/packages/hub/src/execution/wire.ts +3 -3
  118. package/packages/hub/src/fns/auto.ts +2 -2
  119. package/packages/hub/src/fns/client-logs.ts +2 -2
  120. package/packages/hub/src/fns/create.ts +2 -2
  121. package/packages/hub/src/fns/decided.ts +2 -2
  122. package/packages/hub/src/fns/env.ts +14 -14
  123. package/packages/hub/src/fns/examples.ts +3 -3
  124. package/packages/hub/src/fns/facts.ts +5 -5
  125. package/packages/hub/src/fns/search.ts +5 -5
  126. package/packages/hub/src/graph/graph.ts +1 -1
  127. package/packages/hub/src/index/context-sections.ts +1 -1
  128. package/packages/hub/src/index/embedders.ts +3 -3
  129. package/packages/hub/src/index/env.ts +12 -12
  130. package/packages/hub/src/index/index.ts +1 -1
  131. package/packages/hub/src/index/indexer.ts +4 -4
  132. package/packages/hub/src/index/search.ts +1 -1
  133. package/packages/hub/src/index/testing.ts +2 -2
  134. package/packages/hub/src/link/build.ts +32 -32
  135. package/packages/hub/src/link/env.ts +14 -14
  136. package/packages/hub/src/link/grants.ts +10 -10
  137. package/packages/hub/src/link/lifecycle.ts +4 -4
  138. package/packages/hub/src/link/migrate-api.ts +55 -15
  139. package/packages/hub/src/link/pairing.ts +1 -1
  140. package/packages/hub/src/link/process.ts +1 -1
  141. package/packages/hub/src/link/rig.ts +12 -12
  142. package/packages/hub/src/link/supervisor.ts +1 -1
  143. package/packages/hub/src/mcp/calls.ts +6 -6
  144. package/packages/hub/src/mcp/create.ts +5 -5
  145. package/packages/hub/src/mcp/env.ts +6 -6
  146. package/packages/hub/src/mcp/fns.ts +2 -2
  147. package/packages/hub/src/mcp/index.ts +2 -2
  148. package/packages/hub/src/mcp/sources.ts +3 -3
  149. package/packages/hub/src/mcp/tokens.ts +1 -1
  150. package/packages/hub/src/models/create.ts +1 -1
  151. package/packages/hub/src/models/decide.ts +2 -2
  152. package/packages/hub/src/models/index.ts +1 -1
  153. package/packages/hub/src/models/roles.ts +12 -12
  154. package/packages/hub/src/query/env.ts +5 -5
  155. package/packages/hub/src/query/sources.ts +3 -3
  156. package/packages/hub/src/questions/plans.ts +1 -1
  157. package/packages/hub/src/questions/worker.ts +2 -2
  158. package/packages/hub/src/resources/context.ts +3 -3
  159. package/packages/hub/src/resources/converters.ts +2 -2
  160. package/packages/hub/src/resources/create.ts +6 -6
  161. package/packages/hub/src/resources/env.ts +15 -15
  162. package/packages/hub/src/resources/fetch.ts +5 -5
  163. package/packages/hub/src/resources/forms.ts +5 -5
  164. package/packages/hub/src/resources/index.ts +1 -1
  165. package/packages/hub/src/resources/library.ts +2 -2
  166. package/packages/hub/src/resources/raw.ts +1 -1
  167. package/packages/hub/src/resources/reader.ts +2 -2
  168. package/packages/hub/src/resources/sqlite-files.ts +1 -1
  169. package/packages/hub/src/resources/storage.ts +5 -5
  170. package/packages/hub/src/resources/testing.ts +6 -6
  171. package/packages/hub/src/store/env.ts +4 -4
  172. package/packages/hub/src/store/hybrid.ts +4 -4
  173. package/packages/hub/src/store/sqlite.ts +3 -3
  174. package/packages/hub/src/stores/drivers.ts +2 -2
  175. package/packages/hub/src/stores/host.ts +3 -3
  176. package/packages/hub/src/stores/moves.ts +2 -2
  177. package/packages/hub/src/stores/service.ts +2 -2
  178. package/packages/hub/src/tables/env.ts +3 -3
  179. package/packages/hub/src/tables/index.ts +5 -5
  180. package/packages/hub/src/tables/service.ts +7 -7
  181. package/packages/sdk/AUTHORING.md +1206 -881
  182. package/packages/sdk/package.json +11 -8
  183. package/packages/sdk/src/agent.ts +1 -1
  184. package/packages/sdk/src/app-parts.ts +95 -0
  185. package/packages/sdk/src/authored.ts +26 -0
  186. package/packages/sdk/src/authoring.ts +13 -30
  187. package/packages/sdk/src/client-runtime.ts +24 -1
  188. package/packages/sdk/src/client-ui/AddServiceDialog.vue +43 -0
  189. package/packages/sdk/src/client-ui/InstanceNameField.vue +29 -0
  190. package/packages/sdk/src/client-ui/PairRowsEditor.vue +74 -0
  191. package/packages/sdk/src/client-ui/RemoteAuthFields.vue +95 -0
  192. package/packages/sdk/src/client-ui/ServiceRows.vue +57 -0
  193. package/packages/sdk/src/client-ui/draft.ts +10 -0
  194. package/packages/sdk/src/client-ui/host.ts +37 -0
  195. package/packages/sdk/src/client-ui/index.ts +19 -0
  196. package/packages/sdk/src/client-ui/loaded.ts +69 -0
  197. package/packages/sdk/src/client-ui/problems.ts +98 -0
  198. package/packages/sdk/src/client-ui/remote-config.ts +199 -0
  199. package/packages/sdk/src/client-ui/service-rows.ts +25 -0
  200. package/packages/sdk/src/client-ui/state.ts +14 -0
  201. package/packages/sdk/src/client-ui/testing.ts +147 -0
  202. package/packages/sdk/src/client-ui/vue-shim.d.ts +13 -0
  203. package/packages/sdk/src/client.ts +82 -11
  204. package/packages/sdk/src/hub.ts +4 -4
  205. package/packages/sdk/src/index.ts +13 -9
  206. package/packages/sdk/src/page-parts.ts +4 -0
  207. package/packages/sdk/src/program/env.ts +7 -7
  208. package/packages/sdk/src/program/runtime.ts +5 -5
  209. package/packages/sdk/src/program/tools.ts +3 -3
  210. package/packages/sdk/src/remote-auth.ts +128 -7
  211. package/packages/sdk/src/server/context-files.ts +1 -1
  212. package/packages/sdk/src/server/env.ts +36 -36
  213. package/packages/sdk/src/server/fake-hub-widgets.ts +7 -6
  214. package/packages/sdk/src/server/host.ts +28 -28
  215. package/packages/sdk/src/server/index.ts +2 -2
  216. package/packages/sdk/src/server/live.ts +4 -4
  217. package/packages/sdk/src/server/llm-wire.ts +4 -4
  218. package/packages/sdk/src/server/pairing.ts +1 -1
  219. package/packages/sdk/src/server/results.ts +4 -4
  220. package/packages/sdk/src/server/socket-guard.ts +1 -1
  221. package/packages/sdk/src/server/start-gate.ts +2 -2
  222. package/packages/sdk/src/server/store/engines.ts +2 -2
  223. package/packages/sdk/src/server/store/keeper.ts +2 -2
  224. package/packages/sdk/src/server/supervise.ts +4 -4
  225. package/packages/sdk/src/testing/env.ts +6 -6
  226. package/packages/sdk/src/testing/hub.ts +3 -1
  227. package/packages/sdk/src/testing/models.ts +3 -3
  228. package/packages/sdk/src/testing/openrouter.ts +3 -2
  229. package/packages/sdk/src/testing/preview.ts +7 -7
  230. package/packages/sdk/src/widgets.ts +21 -136
  231. package/packages/sdk/tsconfig.json +2 -2
  232. package/packages/web/dist/assets/{ActorSettingsView-v2k7v454.js → ActorSettingsView-CDszUbHz.js} +2 -2
  233. package/packages/web/dist/assets/AdminLayout-CFIz4GsQ.js +2 -0
  234. package/packages/web/dist/assets/{AdminLayout-1hbRPV3d.css → AdminLayout-ggcdQGlQ.css} +1 -1
  235. package/packages/web/dist/assets/{AppPage-CFmKZS8G.js → AppPage-BvoVTk6h.js} +2 -2
  236. package/packages/web/dist/assets/{AutoPairPicker-C61gihmh.js → AutoPairPicker-CLjD-muP.js} +2 -2
  237. package/packages/web/dist/assets/{BrowserFrame-Sq9EmQRT.js → BrowserFrame-BcN-A76X.js} +2 -2
  238. package/packages/web/dist/assets/ChatPage-DhTpAyM2.js +4 -0
  239. package/packages/web/dist/assets/{ChatPage-CbsRmktV.css → ChatPage-DjPv238m.css} +1 -1
  240. package/packages/web/dist/assets/{CodeViewer-tUNXZB77.js → CodeViewer-K9jrTmFO.js} +2 -2
  241. package/packages/web/dist/assets/ConfigWithCustom-BvrvSVIp.js +3 -0
  242. package/packages/web/dist/assets/{ConfirmDialog-Dd3E4sJt.js → ConfirmDialog-BDvLleYf.js} +2 -2
  243. package/packages/web/dist/assets/{ConnectPage-CX9acyQH.js → ConnectPage-Dg6IPNNh.js} +2 -2
  244. package/packages/web/dist/assets/ContextItemPage-qisBQetR.js +2 -0
  245. package/packages/web/dist/assets/ContextPage-DXa6Yqk-.js +3 -0
  246. package/packages/web/dist/assets/{ContextRow-DrtPumZ5.js → ContextRow-DDYnYRaL.js} +2 -2
  247. package/packages/web/dist/assets/{DataPage-DDSsxHro.js → DataPage-DOE_pKAY.js} +2 -2
  248. package/packages/web/dist/assets/DataTypePage-BnP_JELT.js +2 -0
  249. package/packages/web/dist/assets/{DataTypePage-Cr238Hx_.css → DataTypePage-CWrWvUPs.css} +1 -1
  250. package/packages/web/dist/assets/{DesignPage-6e0XbOFC.js → DesignPage-B9MJbF10.js} +3 -3
  251. package/packages/web/dist/assets/{ExplorePage-B7ND0W0l.js → ExplorePage-cRDQZRea.js} +2 -2
  252. package/packages/web/dist/assets/{FnPill-Cp3KuLmP.js → FnPill-CbLZCXYM.js} +2 -2
  253. package/packages/web/dist/assets/{FnView-C0XZdnsS.js → FnView-CG_wBKTP.js} +2 -2
  254. package/packages/web/dist/assets/{FnsView-GTH3p7a0.js → FnsView-BybyK12w.js} +2 -2
  255. package/packages/web/dist/assets/{GinExprView-DGxns6lH.js → GinExprView-BYCKSD_n.js} +2 -2
  256. package/packages/web/dist/assets/{GinForm-BDBUzuDP.js → GinForm-CXjYVf2_.js} +2 -2
  257. package/packages/web/dist/assets/{GinTypeView-CUsymbVf.js → GinTypeView-Bmbmx9e_.js} +2 -2
  258. package/packages/web/dist/assets/{GinValueView-jsKIfiEA.js → GinValueView-CWUzS7ti.js} +2 -2
  259. package/packages/web/dist/assets/{GraphPage-BCcPPsHu.js → GraphPage-D6OhckfJ.js} +2 -2
  260. package/packages/web/dist/assets/GraphPanel-BTitgA-K.js +2 -0
  261. package/packages/web/dist/assets/{HubPicker-EoOErgmk.js → HubPicker-DVly8dLD.js} +2 -2
  262. package/packages/web/dist/assets/{InboxApprovals-Dkq7DFp_.js → InboxApprovals-BF84edZU.js} +2 -2
  263. package/packages/web/dist/assets/{InboxPage-CHhslePq.js → InboxPage-DohZ9EDP.js} +2 -2
  264. package/packages/web/dist/assets/InjectedList-e6qr1kdU.js +2 -0
  265. package/packages/web/dist/assets/{InstallDialog-D-VwfZYF.js → InstallDialog-JJCKYs2s.js} +2 -2
  266. package/packages/web/dist/assets/InstanceTypes-BqUzx87o.js +2 -0
  267. package/packages/web/dist/assets/InstanceView-C73pev7A.js +2 -0
  268. package/packages/web/dist/assets/{ItemHistory-NQAP69ma.js → ItemHistory-dbGgOZsw.js} +2 -2
  269. package/packages/web/dist/assets/LimitsView-Ddp5WakY.js +2 -0
  270. package/packages/web/dist/assets/{ListSearch-BunVrDO0.js → ListSearch-CYNNAuMB.js} +2 -2
  271. package/packages/web/dist/assets/{LlmCallDetails-BoVNDTVs.js → LlmCallDetails-C9H5Hc2J.js} +2 -2
  272. package/packages/web/dist/assets/{LlmCallsView-BGpV92RC.js → LlmCallsView-CBqyZ8Cj.js} +2 -2
  273. package/packages/web/dist/assets/{LoadState-h-K9bTYc.js → LoadState-B2YhZlyC.js} +2 -2
  274. package/packages/web/dist/assets/McpDialog-DhlLklIq.js +2 -0
  275. package/packages/web/dist/assets/{McpView-GPXdCMne.js → McpView-D_ZmNO56.js} +2 -2
  276. package/packages/web/dist/assets/{McpsView-DJIR2JX5.js → McpsView-9_gwBuzw.js} +2 -2
  277. package/packages/web/dist/assets/{MemoryDialog-BTeIHQyA.js → MemoryDialog-pTHIxKEX.js} +2 -2
  278. package/packages/web/dist/assets/{ModelCallsView-DMcnwF2S.js → ModelCallsView-FHv2XWRX.js} +2 -2
  279. package/packages/web/dist/assets/{ModelPicker-CgkMFxSO.js → ModelPicker-EqOuvVnE.js} +2 -2
  280. package/packages/web/dist/assets/ModelsView-D9UaL4PX.js +2 -0
  281. package/packages/web/dist/assets/{NotFoundPage-Tk92K7HN.js → NotFoundPage-BsuJysan.js} +2 -2
  282. package/packages/web/dist/assets/{PairPage-D0BK8CCw.js → PairPage-B_ZXsbL4.js} +2 -2
  283. package/packages/web/dist/assets/{PanelHost-C-gKrxAk.js → PanelHost-Dx-vNNl5.js} +2 -2
  284. package/packages/web/dist/assets/PeopleView-D6dmEgMs.js +2 -0
  285. package/packages/web/dist/assets/{PeopleView-CJ8yArTh.css → PeopleView-DBxdbT1C.css} +1 -1
  286. package/packages/web/dist/assets/{PoliciesView-BRi-QAuo.js → PoliciesView-Bn4rm-ao.js} +2 -2
  287. package/packages/web/dist/assets/{RefusalList-DVO0bmeB.js → RefusalList-aosRD1ie.js} +2 -2
  288. package/packages/web/dist/assets/RendererHost-Ym_SMkhp.css +1 -0
  289. package/packages/web/dist/assets/RendererHost-rjnpSgyQ.js +2 -0
  290. package/packages/web/dist/assets/{ResourceViewer-Do0chYxU.js → ResourceViewer-C4tRColf.js} +2 -2
  291. package/packages/web/dist/assets/ResourcesPage-7mCLBORZ.js +2 -0
  292. package/packages/web/dist/assets/ResultGrid-CL2WSYQH.css +1 -0
  293. package/packages/web/dist/assets/ResultGrid-GIMoQUAr.js +2 -0
  294. package/packages/web/dist/assets/{ReviewSummaryStrip-DO3p64Qj.js → ReviewSummaryStrip-Bvjn3Iq8.js} +2 -2
  295. package/packages/web/dist/assets/ReviewView-DIqsUedT.js +3 -0
  296. package/packages/web/dist/assets/{RuleRow-DX9v4iGP.js → RuleRow-zRg-e8Vj.js} +2 -2
  297. package/packages/web/dist/assets/RunCard-C7wOGaw8.js +2 -0
  298. package/packages/web/dist/assets/RunCard-CSDiz-Nt.css +1 -0
  299. package/packages/web/dist/assets/{RunDetails-DjR206q6.js → RunDetails-W4GbE6AE.js} +2 -2
  300. package/packages/web/dist/assets/{RunDot-lHRICdM5.js → RunDot-C46uzzNM.js} +2 -2
  301. package/packages/web/dist/assets/{RunPage-CbAQ_WPR.js → RunPage-DPLtZpeB.js} +2 -2
  302. package/packages/web/dist/assets/{RunProgress-C3-B4tQf.js → RunProgress-Cr_6TBaF.js} +2 -2
  303. package/packages/web/dist/assets/{RunsView-DMkPmkqX.js → RunsView-tU350TPK.js} +2 -2
  304. package/packages/web/dist/assets/SettingsPage-B8QmmMN3.js +3 -0
  305. package/packages/web/dist/assets/{SettingsPage-t03BqXw8.css → SettingsPage-BTl3Ie4F.css} +1 -1
  306. package/packages/web/dist/assets/SignInPage-CXxLf7Rp.css +1 -0
  307. package/packages/web/dist/assets/{SignInPage-ByqGEZfj.js → SignInPage-DTwdqlnB.js} +2 -2
  308. package/packages/web/dist/assets/{StatusBadge-CXne0sRZ.js → StatusBadge-D7wKMAcD.js} +2 -2
  309. package/packages/web/dist/assets/{StorePlacementStep-B6SwTmdM.js → StorePlacementStep-C04nRU-u.js} +2 -2
  310. package/packages/web/dist/assets/{SystemConfig-vQDL_eUl.js → SystemConfig-CE3keXWq.js} +2 -2
  311. package/packages/web/dist/assets/SystemPageHost-CEhz4li8.js +2 -0
  312. package/packages/web/dist/assets/SystemPageHost-DX7LrFoN.css +1 -0
  313. package/packages/web/dist/assets/SystemView-CBFzEGfm.js +2 -0
  314. package/packages/web/dist/assets/SystemsView-0G8JntMV.js +2 -0
  315. package/packages/web/dist/assets/TableView-BK0uwLHl.js +3 -0
  316. package/packages/web/dist/assets/TableView-B_4MViVb.css +1 -0
  317. package/packages/web/dist/assets/{TableViewer-Boxx86f5.js → TableViewer-nbMInGJJ.js} +3 -3
  318. package/packages/web/dist/assets/{ThemePicker-CIg_oRQX.js → ThemePicker-fZpVSYqG.js} +2 -2
  319. package/packages/web/dist/assets/{TurnTree-Ecm0yA5g.js → TurnTree-Co-iBqhT.js} +2 -2
  320. package/packages/web/dist/assets/{UserMessage-BtECa8ka.css → UserMessage-B63G9sxC.css} +1 -1
  321. package/packages/web/dist/assets/{UserMessage-BlnqZDVU.js → UserMessage-CDjUxKY0.js} +6 -6
  322. package/packages/web/dist/assets/{ValueVisual-C-MWpp7c.js → ValueVisual-EJnCKgSy.js} +2 -2
  323. package/packages/web/dist/assets/{fn-modal-B98MR7JN.js → fn-modal-DtE65mFt.js} +2 -2
  324. package/packages/web/dist/assets/{fn-notices-CfTa1E8y.js → fn-notices-CCZ-DFbi.js} +2 -2
  325. package/packages/web/dist/assets/{formats-JwoKfXIq.js → formats-CyHV2siv.js} +2 -2
  326. package/packages/web/dist/assets/index-BY7M8QUk.css +1 -0
  327. package/packages/web/dist/assets/index-OZS2EluT.js +4 -0
  328. package/packages/web/dist/assets/{labels-BFbk11BE.js → labels-CT7_K0Pt.js} +2 -2
  329. package/packages/web/dist/assets/{layout-D1gf481r.js → layout-B6fBDg80.js} +2 -2
  330. package/packages/web/dist/assets/loaded-LaPjk6mK.js +2 -0
  331. package/packages/web/dist/assets/{metrics-CBPX3W5Y.js → metrics-9n8bKI7u.js} +2 -2
  332. package/packages/web/dist/assets/problems--AW4igVY.js +2 -0
  333. package/packages/web/dist/assets/{push-payload-BeU1ADYt.js → push-payload-B3EcrsVz.js} +64 -64
  334. package/packages/web/dist/assets/record-edits-B-FWAbxR.js +2 -0
  335. package/packages/web/dist/assets/{review-fP-l9D6H.js → review-uLESCEz1.js} +3 -3
  336. package/packages/web/dist/assets/routes-B7Zmt8wh.js +4 -0
  337. package/packages/web/dist/assets/{runs-CveC2kKo.js → runs-CUb2PTFg.js} +2 -2
  338. package/packages/web/dist/assets/{shared-LbaIHjbV.js → shared-Bxhw_9et.js} +2 -2
  339. package/packages/web/dist/assets/{sources-VPrtgLIi.js → sources-YgkjgFLe.js} +2 -2
  340. package/packages/web/dist/assets/src-DY1fSFJS.js +43 -0
  341. package/packages/web/dist/assets/state-ChQDWWj-.js +2 -0
  342. package/packages/web/dist/assets/{systems-BqE3WTSF.js → systems-CjwjRySu.js} +2 -2
  343. package/packages/web/dist/assets/table-host-B_D9dmCz.js +2 -0
  344. package/packages/web/dist/assets/tables-CaxIuHdw.js +2 -0
  345. package/packages/web/dist/assets/{ui-BzgWquIU.js → ui-DWjytmDS.js} +5 -5
  346. package/packages/web/dist/assets/{url-DKGcECT1.js → url-DbGOI14W.js} +2 -2
  347. package/packages/web/dist/index.html +49 -47
  348. package/packages/web/dist/sw.js +1 -1
  349. package/packages/web/package.json +2 -4
  350. package/premade/claude.zip +0 -0
  351. package/premade/database.zip +0 -0
  352. package/premade/web.zip +0 -0
  353. package/scripts/dev-env.ts +9 -9
  354. package/scripts/run-stack.ts +15 -15
  355. package/scripts/stack.ts +3 -3
  356. package/scripts/start.ts +18 -18
  357. package/systems/api/client/ApiServiceForm.vue +55 -0
  358. package/systems/api/client/ServiceList.vue +90 -0
  359. package/systems/api/client/ServicePage.vue +142 -0
  360. package/systems/api/client/ServicesPage.vue +32 -0
  361. package/systems/api/client/index.ts +15 -0
  362. package/systems/api/client/logic.ts +140 -0
  363. package/systems/api/client/state.ts +92 -0
  364. package/systems/api/package.json +9 -6
  365. package/systems/api/server/authoring.ts +2 -1
  366. package/systems/api/server/env.ts +1 -1
  367. package/systems/api/server/guard.ts +1 -1
  368. package/systems/api/server/http.ts +3 -2
  369. package/systems/api/server/impl.ts +3 -2
  370. package/systems/api/server/main.ts +11 -7
  371. package/systems/api/server/openapi.ts +1 -1
  372. package/systems/api/server/program.ts +2 -1
  373. package/systems/api/server/services.ts +2 -1
  374. package/systems/api/shared/http.ts +2 -1
  375. package/systems/api/shared/index.ts +15 -5
  376. package/{packages/core/src/programs.ts → systems/api/shared/services.ts} +7 -51
  377. package/systems/api/system.json +2 -1
  378. package/systems/api/tsconfig.json +2 -2
  379. package/systems/code/package.json +4 -3
  380. package/systems/code/server/authoring.ts +2 -1
  381. package/systems/code/server/impl.ts +2 -1
  382. package/systems/code/server/main.ts +5 -5
  383. package/systems/code/shared/index.ts +2 -3
  384. package/systems/code/shared/program.ts +23 -0
  385. package/systems/embedder/package.json +1 -1
  386. package/systems/embedder/server/env.ts +1 -1
  387. package/systems/embedder/server/main.ts +5 -5
  388. package/systems/embedder/shared/index.ts +1 -1
  389. package/systems/fs/client/machines/fakes.ts +1 -1
  390. package/systems/fs/client/machines/files/fakes.ts +1 -1
  391. package/systems/fs/client/machines/palette.ts +3 -2
  392. package/systems/fs/context/authoring/parts/client.md +23 -5
  393. package/systems/fs/context/authoring/parts/client.reference/client.md +7 -16
  394. package/systems/fs/context/authoring/parts/client.reference/pageinbox.md +524 -0
  395. package/systems/fs/context/authoring/parts/client.reference/{resultview.md → visuals.md} +85 -116
  396. package/systems/fs/context/authoring/parts/client.reference.md +8 -8
  397. package/systems/fs/context/authoring/parts/context.md +1 -1
  398. package/systems/fs/context/authoring/parts/contract.md +1 -1
  399. package/systems/fs/context/authoring/parts/core-types/admin-ts.md +2 -2
  400. package/systems/fs/context/authoring/parts/core-types/connections-ts.md +12 -1
  401. package/systems/fs/context/authoring/parts/core-types/context-files-ts.md +2 -2
  402. package/systems/fs/context/authoring/parts/core-types/context-graph-ts.md +2 -2
  403. package/systems/fs/context/authoring/parts/core-types/contextdecl.md +2 -2
  404. package/systems/fs/context/authoring/parts/core-types/lifecycle-ts.md +27 -2
  405. package/systems/fs/context/authoring/parts/core-types/manifest.md +27 -2
  406. package/systems/fs/context/authoring/parts/core-types/manifestpatch.md +26 -2
  407. package/systems/fs/context/authoring/parts/core-types/modes-ts.md +3 -3
  408. package/systems/fs/context/authoring/parts/core-types/records-systems-ts.md +145 -1
  409. package/systems/fs/context/authoring/parts/core-types/registries-ts.md +98 -2
  410. package/systems/fs/context/authoring/parts/core-types/run-ts.md +2 -2
  411. package/systems/fs/context/authoring/parts/core-types/system-pages-ts.md +4 -2
  412. package/systems/fs/context/authoring/parts/core-types/system-providers-ts.md +2 -2
  413. package/systems/fs/context/authoring/parts/core-types/tables-ts.md +91 -0
  414. package/systems/fs/context/authoring/parts/core-types/web-ts.md +1 -2
  415. package/systems/fs/context/authoring/parts/core-types.md +5 -8
  416. package/systems/fs/context/authoring/parts/examples/server-main-ts.md +4 -4
  417. package/systems/fs/context/authoring/parts/examples/systems-fs-shared-index-ts-lines-568-660.md +1 -1
  418. package/systems/fs/context/authoring/parts/fns.md +1 -1
  419. package/systems/fs/context/authoring/parts/folder.md +6 -6
  420. package/systems/fs/context/authoring/parts/hub/hub-ctx-from-resource.md +2 -2
  421. package/systems/fs/context/authoring/parts/hub/hub-install-package.md +2 -2
  422. package/systems/fs/context/authoring/parts/hub.reference.md +3 -3
  423. package/systems/fs/context/authoring/parts/internals/manifestof.md +2 -2
  424. package/systems/fs/context/authoring/parts/internals/permissionargs.md +4 -4
  425. package/systems/fs/context/authoring/parts/kinds-agents.md +1 -1
  426. package/systems/fs/context/authoring/parts/kinds-agents.reference/authoringsession.md +7 -5
  427. package/systems/fs/context/authoring/parts/kinds-agents.reference/kind.md +4 -4
  428. package/systems/fs/context/authoring/parts/outcomes.md +2 -2
  429. package/systems/fs/context/authoring/parts/outcomes.reference.md +2 -2
  430. package/systems/fs/context/authoring/parts/packaging.md +4 -4
  431. package/systems/fs/context/authoring/parts/remote.md +5 -5
  432. package/systems/fs/context/authoring/parts/remote.reference.md +201 -17
  433. package/systems/fs/context/authoring/parts/server.md +7 -7
  434. package/systems/fs/context/authoring/parts/server.reference.md +15 -15
  435. package/systems/fs/context/authoring/parts/testing.reference/equal.md +3 -3
  436. package/systems/fs/context/authoring/parts/testing.reference/fakehub.md +1 -1
  437. package/systems/fs/context/authoring/parts/testing.reference/kindprops.md +22 -10
  438. package/systems/fs/context/authoring/parts/testing.reference/{openmemorystore.md → storeconnection.md} +7 -19
  439. package/systems/fs/context/authoring/parts/testing.reference.md +5 -5
  440. package/systems/fs/context/authoring/parts/widgets.md +32 -22
  441. package/systems/fs/context/authoring/parts/widgets.reference.md +503 -9
  442. package/systems/fs/package.json +3 -3
  443. package/systems/fs/server/hosting.ts +10 -10
  444. package/systems/fs/server/main.ts +8 -8
  445. package/systems/fs/server/shell.ts +1 -1
  446. package/systems/fs/shared/index.ts +1 -1
  447. package/systems/google-calendar/package.json +1 -1
  448. package/systems/google-calendar/server/main.ts +4 -4
  449. package/systems/input/package.json +3 -3
  450. package/systems/input/server/main.ts +6 -6
  451. package/systems/mcp/client/McpServerForm.vue +99 -0
  452. package/systems/mcp/client/ServerList.vue +78 -0
  453. package/systems/mcp/client/ServerPage.vue +194 -0
  454. package/systems/mcp/client/ServersPage.vue +32 -0
  455. package/systems/mcp/client/index.ts +15 -0
  456. package/systems/mcp/client/logic.ts +224 -0
  457. package/systems/mcp/client/state.ts +128 -0
  458. package/systems/mcp/package.json +9 -6
  459. package/systems/mcp/server/dial.ts +1 -1
  460. package/systems/mcp/server/impl.ts +2 -1
  461. package/systems/mcp/server/instance.ts +3 -5
  462. package/systems/mcp/server/main.ts +10 -6
  463. package/systems/mcp/server/mirror.ts +2 -3
  464. package/systems/mcp/server/oauth.ts +2 -1
  465. package/systems/mcp/server/server-link.ts +2 -1
  466. package/systems/mcp/shared/index.ts +15 -2
  467. package/{packages/core/src/mcp-servers.ts → systems/mcp/shared/servers.ts} +6 -5
  468. package/systems/mcp/system.json +2 -1
  469. package/systems/mcp/tsconfig.json +2 -2
  470. package/systems/ollama/package.json +3 -3
  471. package/systems/ollama/server/main.ts +5 -5
  472. package/systems/schedule/package.json +3 -3
  473. package/systems/schedule/server/main.ts +6 -6
  474. package/systems/template/README.md +2 -2
  475. package/systems/template/package.json +1 -1
  476. package/systems/template/server/main.ts +4 -4
  477. package/systems/widgets/client/ChipRow.vue +22 -0
  478. package/systems/widgets/client/ProposalCard.vue +6 -5
  479. package/systems/widgets/client/SavedWidget.vue +11 -8
  480. package/systems/widgets/client/WidgetChips.vue +137 -0
  481. package/systems/widgets/client/WidgetView.vue +32 -0
  482. package/systems/widgets/client/charts/ChartVisual.vue +157 -0
  483. package/systems/widgets/client/charts/chart-data.ts +230 -0
  484. package/systems/widgets/client/charts/echarts-setup.ts +69 -0
  485. package/systems/widgets/client/charts/export.ts +36 -0
  486. package/systems/widgets/client/charts/families/calendar.ts +105 -0
  487. package/systems/widgets/client/charts/families/category.ts +186 -0
  488. package/systems/widgets/client/charts/families/crosstab.ts +113 -0
  489. package/systems/widgets/client/charts/families/distribution.ts +160 -0
  490. package/systems/widgets/client/charts/families/finance.ts +96 -0
  491. package/systems/widgets/client/charts/families/gauge.ts +75 -0
  492. package/systems/widgets/client/charts/families/hierarchy.ts +166 -0
  493. package/systems/widgets/client/charts/families/index.ts +21 -0
  494. package/systems/widgets/client/charts/families/network.ts +140 -0
  495. package/systems/widgets/client/charts/families/part.ts +61 -0
  496. package/systems/widgets/client/charts/families/profile.ts +30 -0
  497. package/systems/widgets/client/charts/families/progress.ts +76 -0
  498. package/systems/widgets/client/charts/families/range.ts +107 -0
  499. package/systems/widgets/client/charts/families/time.ts +177 -0
  500. package/systems/widgets/client/charts/families/timeline.ts +114 -0
  501. package/systems/widgets/client/charts/families/wide.ts +41 -0
  502. package/systems/widgets/client/charts/index.ts +37 -0
  503. package/systems/widgets/client/charts/maths.ts +139 -0
  504. package/systems/widgets/client/charts/size.ts +39 -0
  505. package/systems/widgets/client/chips.ts +150 -0
  506. package/systems/widgets/client/index.ts +18 -5
  507. package/systems/widgets/client/proposal.ts +2 -1
  508. package/systems/widgets/package.json +7 -4
  509. package/systems/widgets/server/authoring.ts +13 -7
  510. package/systems/widgets/server/env.ts +1 -1
  511. package/systems/widgets/server/impl.ts +10 -6
  512. package/systems/widgets/server/main.ts +6 -6
  513. package/systems/widgets/server/run.ts +16 -9
  514. package/systems/widgets/server/upgrade.ts +34 -0
  515. package/systems/widgets/shared/args.ts +137 -0
  516. package/systems/widgets/shared/charts.ts +243 -0
  517. package/systems/widgets/shared/index.ts +12 -3
  518. package/{packages/sdk/src → systems/widgets/shared}/relative-dates.ts +2 -1
  519. package/systems/widgets/shared/spec.ts +208 -0
  520. package/{packages/sdk/src → systems/widgets/shared}/widget-check.ts +7 -9
  521. package/{packages/sdk/src → systems/widgets/shared}/widget-schema.ts +4 -4
  522. package/packages/core/src/remote-auth.ts +0 -111
  523. package/packages/core/src/widgets.ts +0 -427
  524. package/packages/web/dist/assets/AdminLayout-B6Jrc_4W.js +0 -2
  525. package/packages/web/dist/assets/ApiServiceForm-BxprSaAq.css +0 -1
  526. package/packages/web/dist/assets/ApiServiceForm-CuuQgOJc.js +0 -2
  527. package/packages/web/dist/assets/ApiServiceView-7bTHSO_Z.js +0 -2
  528. package/packages/web/dist/assets/ApiServiceView-BVmdRCjR.css +0 -1
  529. package/packages/web/dist/assets/ApiServicesView-BTLV6c8n.css +0 -1
  530. package/packages/web/dist/assets/ApiServicesView-BXi24n49.js +0 -2
  531. package/packages/web/dist/assets/ChartVisual-BnFG9aFi.css +0 -1
  532. package/packages/web/dist/assets/ChartVisual-C4mgw4wh.js +0 -11
  533. package/packages/web/dist/assets/ChatPage-CAhHE03Z.js +0 -4
  534. package/packages/web/dist/assets/ConfigWithCustom-D_-rY66L.js +0 -3
  535. package/packages/web/dist/assets/ContextItemPage-rUI3-T_L.js +0 -2
  536. package/packages/web/dist/assets/ContextPage-CtefzyKg.js +0 -3
  537. package/packages/web/dist/assets/DataTypePage-BW9fWaz8.js +0 -2
  538. package/packages/web/dist/assets/FnList-BCnb4kOB.css +0 -1
  539. package/packages/web/dist/assets/FnList-Bx6H-kux.js +0 -2
  540. package/packages/web/dist/assets/GraphPanel-9tztGHmu.js +0 -2
  541. package/packages/web/dist/assets/InjectedList-CSWqRiON.js +0 -2
  542. package/packages/web/dist/assets/InstanceTypes-D3rAEiE7.js +0 -2
  543. package/packages/web/dist/assets/InstanceView-DoH8C-1j.js +0 -2
  544. package/packages/web/dist/assets/LimitsView-DY2C9nYS.js +0 -2
  545. package/packages/web/dist/assets/McpDialog-DhOCk6_E.js +0 -2
  546. package/packages/web/dist/assets/McpServerForm-Cor3fI7s.js +0 -2
  547. package/packages/web/dist/assets/McpServerForm-DsHaf5Um.css +0 -1
  548. package/packages/web/dist/assets/McpServerView-7I76EznB.css +0 -1
  549. package/packages/web/dist/assets/McpServerView-ewXRPEmZ.js +0 -2
  550. package/packages/web/dist/assets/McpServersView-Dd0xmfws.js +0 -2
  551. package/packages/web/dist/assets/ModelsView-cMHygeiK.js +0 -2
  552. package/packages/web/dist/assets/PeopleView-DRfeNWK5.js +0 -2
  553. package/packages/web/dist/assets/RemoteAuthFields-CgiufuqQ.js +0 -2
  554. package/packages/web/dist/assets/RemoteAuthFields-Dm44vz2t.css +0 -1
  555. package/packages/web/dist/assets/ResourcesPage-BBx2u2mw.js +0 -2
  556. package/packages/web/dist/assets/ResultGrid-Bj-0I5HY.js +0 -2
  557. package/packages/web/dist/assets/ResultGrid-CuUQyTjW.css +0 -1
  558. package/packages/web/dist/assets/ReviewView-DZF9E1hb.js +0 -3
  559. package/packages/web/dist/assets/RunCard-BnrtK2Yp.js +0 -2
  560. package/packages/web/dist/assets/RunCard-CfyRaDLS.css +0 -1
  561. package/packages/web/dist/assets/ServiceRows-4WythFpF.js +0 -2
  562. package/packages/web/dist/assets/ServiceRows-HPQ0pN6b.css +0 -1
  563. package/packages/web/dist/assets/SettingsPage-BN4oSzoL.js +0 -3
  564. package/packages/web/dist/assets/SignInPage-Djx-M-0U.css +0 -1
  565. package/packages/web/dist/assets/SystemPageHost-BeZ-6N0-.css +0 -1
  566. package/packages/web/dist/assets/SystemPageHost-DrMrEPyh.js +0 -2
  567. package/packages/web/dist/assets/SystemView-Be6TBM4j.js +0 -2
  568. package/packages/web/dist/assets/SystemsView-DZtT3laz.js +0 -2
  569. package/packages/web/dist/assets/WidgetView-DQUDeFkB.css +0 -1
  570. package/packages/web/dist/assets/WidgetView-DX4ejNb6.js +0 -3
  571. package/packages/web/dist/assets/export-BwFkEtcm.js +0 -15
  572. package/packages/web/dist/assets/index-6ScWTFy2.js +0 -4
  573. package/packages/web/dist/assets/index-CEslGcrX.css +0 -1
  574. package/packages/web/dist/assets/problems-t1E_ovSz.js +0 -2
  575. package/packages/web/dist/assets/record-edits-Bfsi4lU3.js +0 -2
  576. package/packages/web/dist/assets/remote-config-BNQhSDzB.js +0 -2
  577. package/packages/web/dist/assets/routes-DV4IJpwe.js +0 -4
  578. package/packages/web/dist/assets/size-Bh__w5aI.js +0 -2
  579. package/packages/web/dist/assets/src-CT3TeFaM.js +0 -43
  580. package/packages/web/dist/assets/state-xfQqaQPX.js +0 -2
  581. package/packages/web/dist/assets/widget-host-B87MTaTn.js +0 -2
  582. package/packages/web/dist/assets/widgets-BBCuSS6E.js +0 -2
  583. package/systems/fs/context/authoring/parts/client.reference/textareaprops.md +0 -195
  584. package/systems/fs/context/authoring/parts/core-types/remote-auth-ts.md +0 -64
  585. package/systems/fs/context/authoring/parts/core-types/widgets-ts.md +0 -303
  586. package/systems/fs/context/authoring/parts/widgets.reference/hub-visuals.md +0 -627
  587. package/systems/fs/context/authoring/parts/widgets.reference/sourcecompatible.md +0 -154
@@ -0,0 +1,230 @@
1
+ /**
2
+ * What every chart family builds from, and the small reshaping they share: a table's cells as ECharts values, bound
3
+ * columns by channel, rows split by a key, long rows pivoted wide. None of it aggregates; the maths that does
4
+ * (histogram bins, quartiles, a pie's "Other") is in `maths.ts` and runs only over a whole result.
5
+ */
6
+ import { labelFor, type ColumnFacts, type Json, type ResultFacts, type ResultTable, type VisualBinding } from '@harness/core';
7
+ import type { ChartOption } from './echarts-setup.ts';
8
+ import type { VisualPalette as ChartPalette } from '@harness/sdk';
9
+
10
+ /** One cell as ECharts reads it: numbers and text as they are, a boolean as Yes/No, anything else as JSON. */
11
+ export type ChartValue = number | string | null;
12
+
13
+ /** What a family is drawn from. */
14
+ export interface ChartInput {
15
+ readonly table: ResultTable;
16
+ readonly facts: ResultFacts;
17
+ /** Channel → columns: the ranking's default binding with the widget's own over it. */
18
+ readonly bind: VisualBinding;
19
+ readonly style: string;
20
+ readonly palette: ChartPalette;
21
+ /** Drawn narrower than 600px: legends at the bottom, fewer labels, no zoom slider. */
22
+ readonly phone: boolean;
23
+ /** How many periods back from the latest a paged family (the calendar) shows; 0 is the latest. */
24
+ readonly shift: number;
25
+ }
26
+
27
+ /** The part of an ECharts click a family maps back to a row. */
28
+ export interface ChartClick {
29
+ readonly seriesIndex?: number | undefined;
30
+ readonly dataIndex?: number | undefined;
31
+ readonly dataType?: string | undefined;
32
+ readonly name?: string | undefined;
33
+ }
34
+
35
+ /** The axis a zoom (or a calendar's period) sets a widget's range from. */
36
+ export interface RangeAxis {
37
+ /** `time`: zoom values are instants; `category`: indexes into `values`. */
38
+ readonly kind: 'time' | 'category';
39
+ readonly values: readonly ChartValue[];
40
+ /** A calendar day, written back as `YYYY-MM-DD`. */
41
+ readonly day: boolean;
42
+ }
43
+
44
+ /** The period a paged family shows, with what it sets the range to. */
45
+ export interface ChartPeriod {
46
+ readonly label: string;
47
+ readonly from: string;
48
+ readonly to: string;
49
+ /** Whether there is data before or after it. */
50
+ readonly before: boolean;
51
+ readonly after: boolean;
52
+ }
53
+
54
+ /** A family's drawing: its option, how a click maps to a row, and the axis a zoom sets the range from. */
55
+ export interface ChartDraw {
56
+ readonly option: ChartOption;
57
+ /** The row (index in `table.rows`) a click lands on; `undefined` for marks that stand for many rows. */
58
+ rowOf?(click: ChartClick): number | undefined;
59
+ readonly range?: RangeAxis | undefined;
60
+ readonly period?: ChartPeriod | undefined;
61
+ /** How many marks it draws, for picking the renderer. */
62
+ readonly points: number;
63
+ /** Its height in pixels, when not the chart's usual. */
64
+ readonly height?: number | undefined;
65
+ }
66
+
67
+ /** Why a family can't draw this data after all (a cycle a flow chart can't lay out); shown instead of the chart. */
68
+ export interface ChartProblem {
69
+ readonly problem: string;
70
+ }
71
+
72
+ /** A family's option builder. */
73
+ export type ChartBuilder = (input: ChartInput) => ChartDraw | ChartProblem;
74
+
75
+ /** One cell as ECharts reads it. */
76
+ export function chartValue(value: Json | undefined): ChartValue {
77
+ if (value === undefined || value === null) { return null; }
78
+ if (typeof value === 'number' || typeof value === 'string') { return value; }
79
+ if (typeof value === 'boolean') { return value ? 'Yes' : 'No'; }
80
+ return JSON.stringify(value);
81
+ }
82
+
83
+ /** A cell as a number, or `null` for anything that is not one. */
84
+ export function numberOf(value: Json | undefined): number | null {
85
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
86
+ }
87
+
88
+ /** The column bound to a channel (its first), with its index and facts; `undefined` when the channel is unbound. */
89
+ export interface BoundColumn {
90
+ readonly name: string;
91
+ readonly index: number;
92
+ readonly facts: ColumnFacts | undefined;
93
+ /** What a person reads for it (axis names, series names, tooltips): its own label, else its name humanized. */
94
+ readonly label: string;
95
+ }
96
+
97
+ /** Every column bound to a channel, in order. */
98
+ export function boundAll(input: Pick<ChartInput, 'table' | 'facts' | 'bind'>, channel: string): BoundColumn[] {
99
+ return (input.bind[channel] ?? []).flatMap((name) => {
100
+ const index = input.table.columns.findIndex((column) => column.name === name);
101
+ const column = input.table.columns[index];
102
+ if (column === undefined) { return []; }
103
+ return [{ name, index, facts: input.facts.columns.find((c) => c.name === name), label: labelFor(column) }];
104
+ });
105
+ }
106
+
107
+ /** The column bound to a channel. */
108
+ export function bound(input: Pick<ChartInput, 'table' | 'facts' | 'bind'>, channel: string): BoundColumn | undefined {
109
+ return boundAll(input, channel)[0];
110
+ }
111
+
112
+ /** The column bound to a required channel; ranking never offers a family without it, so its absence is a bug. */
113
+ export function needed(input: Pick<ChartInput, 'table' | 'facts' | 'bind'>, channel: string): BoundColumn {
114
+ const column = bound(input, channel);
115
+ if (column === undefined) { throw new Error(`The ${channel} channel is not bound.`); }
116
+ return column;
117
+ }
118
+
119
+ /** A dataset dimension: named for `encode`, with the words a tooltip shows for it (`displayName`). */
120
+ export interface Dimension {
121
+ readonly name: string;
122
+ readonly displayName: string;
123
+ }
124
+
125
+ /** The dimension of a bound column: its name for `encode`, its label for the tooltip. */
126
+ export function dimension(column: Pick<BoundColumn, 'name' | 'label'>, name = column.name): Dimension {
127
+ return { name, displayName: column.label };
128
+ }
129
+
130
+ /** The whole table as a dataset: a dimension per column (by name, so `encode` names columns; its label for tooltips) and a row per row. */
131
+ export function dataset(table: ResultTable): { dimensions: Dimension[]; source: ChartValue[][] } {
132
+ return { dimensions: table.columns.map((column) => ({ name: column.name, displayName: labelFor(column) })), source: table.rows.map((row) => row.map(chartValue)) };
133
+ }
134
+
135
+ /** The distinct values of a column, in the order they first appear. */
136
+ export function distinctValues(table: ResultTable, index: number): ChartValue[] {
137
+ const seen = new Map<string, ChartValue>();
138
+ for (const row of table.rows) {
139
+ const value = chartValue(row[index]);
140
+ const key = JSON.stringify(value);
141
+ if (!seen.has(key)) { seen.set(key, value); }
142
+ }
143
+ return [...seen.values()];
144
+ }
145
+
146
+ /** Rows split by a key column's value, each group keeping its rows' indexes. */
147
+ export interface RowGroup {
148
+ readonly key: ChartValue;
149
+ readonly rows: readonly number[];
150
+ }
151
+
152
+ /** The rows of each value of a key column, in first-appearance order. */
153
+ export function splitRows(table: ResultTable, index: number): RowGroup[] {
154
+ const groups = new Map<string, { key: ChartValue; rows: number[] }>();
155
+ table.rows.forEach((row, at) => {
156
+ const key = chartValue(row[index]);
157
+ const id = JSON.stringify(key);
158
+ const group = groups.get(id) ?? { key, rows: [] };
159
+ group.rows.push(at);
160
+ groups.set(id, group);
161
+ });
162
+ return [...groups.values()];
163
+ }
164
+
165
+ /** Long rows (key, series, value) pivoted wide: a row per key, a column per series value, and where each cell came from. */
166
+ export interface Pivot {
167
+ readonly keys: ChartValue[];
168
+ readonly series: ChartValue[];
169
+ /** `[key, value per series…]` per key. */
170
+ readonly source: ChartValue[][];
171
+ /** The row a (key index, series index) cell came from. */
172
+ rowAt(key: number, series: number): number | undefined;
173
+ }
174
+
175
+ /** Pivot a measure by a key and a series column. When a key and series repeat, the last row's value is drawn. */
176
+ export function pivot(table: ResultTable, key: number, series: number, value: number): Pivot {
177
+ const keys = distinctValues(table, key);
178
+ const names = distinctValues(table, series);
179
+ const keyAt = new Map(keys.map((k, i) => [JSON.stringify(k), i]));
180
+ const seriesAt = new Map(names.map((s, i) => [JSON.stringify(s), i]));
181
+ const source = keys.map((k): ChartValue[] => [k, ...names.map((): ChartValue => null)]);
182
+ const from = new Map<string, number>();
183
+ table.rows.forEach((row, at) => {
184
+ const k = keyAt.get(JSON.stringify(chartValue(row[key])));
185
+ const s = seriesAt.get(JSON.stringify(chartValue(row[series])));
186
+ const line = k === undefined ? undefined : source[k];
187
+ if (k === undefined || s === undefined || line === undefined) { return; }
188
+ line[s + 1] = numberOf(row[value]);
189
+ from.set(`${String(k)}:${String(s)}`, at);
190
+ });
191
+ return { keys, series: names, source, rowAt: (k, s) => from.get(`${String(k)}:${String(s)}`) };
192
+ }
193
+
194
+ /** A label for a value on a legend or axis. */
195
+ export function labelOf(value: ChartValue): string {
196
+ return value === null ? '(empty)' : String(value);
197
+ }
198
+
199
+ /**
200
+ * How every smoothed line bends: control points level with each point (`smoothMonotone: 'x'`), so a curve never
201
+ * swings past its neighbours: never below the lower or above the higher of two points it joins.
202
+ */
203
+ export const SMOOTH = { smooth: 0.35, smoothMonotone: 'x' } as const;
204
+
205
+ /** The legend every multi-series family uses: scrollable, at the bottom, so it never covers the plot on a phone. */
206
+ export function legend(show: boolean): NonNullable<ChartOption['legend']> {
207
+ return { show, type: 'scroll', bottom: 0, left: 'center', icon: 'roundRect', itemWidth: 12, itemHeight: 8 };
208
+ }
209
+
210
+ /** The tooltip, kept inside the chart; ECharts shows it on tap as well as hover (its default `triggerOn`), so nothing is hover-only. */
211
+ export function tooltip(trigger: 'item' | 'axis'): { trigger: 'item' | 'axis'; confine: true; axisPointer?: { type: 'shadow' } } {
212
+ return { trigger, confine: true, ...(trigger === 'axis' ? { axisPointer: { type: 'shadow' } } : {}) };
213
+ }
214
+
215
+ /** The plot grid: labels contained (outer bounds, not the deprecated containLabel), room at the bottom for a legend or zoom. */
216
+ export function plotGrid(bottom: number): NonNullable<ChartOption['grid']> {
217
+ return { left: 8, right: 16, top: 24, bottom, outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' };
218
+ }
219
+
220
+ /** Pinch and wheel zoom on an axis, with a slider under it on a wide screen. */
221
+ export function zoom(phone: boolean, axes: { readonly xAxisIndex?: number[]; readonly yAxisIndex?: number[] } = {}): NonNullable<ChartOption['dataZoom']> {
222
+ const inside = { type: 'inside' as const, ...axes };
223
+ return phone || axes.yAxisIndex !== undefined ? [inside] : [inside, { type: 'slider' as const, height: 18, bottom: 28, ...axes }];
224
+ }
225
+
226
+ /** An ISO day or instant for a zoom end: a day column gets `YYYY-MM-DD`, anything else the full ISO time. */
227
+ export function isoOf(time: number, day: boolean): string {
228
+ const iso = new Date(time).toISOString();
229
+ return day ? iso.slice(0, 10) : iso;
230
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * ECharts, tree-shaken: only the charts, components and renderers the widgets system's chart families draw (every
3
+ * series ECharts 6.1.0 has but `map`), registered once with `echarts/core`. It ships in the widgets system's client
4
+ * bundle, never in the web app's. Also the option type every family builds and the theme object a palette becomes.
5
+ */
6
+ import {
7
+ BarChart, BoxplotChart, CandlestickChart, ChordChart, CustomChart, EffectScatterChart, FunnelChart, GaugeChart, GraphChart, HeatmapChart, LineChart, LinesChart,
8
+ ParallelChart, PictorialBarChart, PieChart, RadarChart, SankeyChart, ScatterChart, SunburstChart, ThemeRiverChart, TreeChart, TreemapChart,
9
+ } from 'echarts/charts';
10
+ import {
11
+ AriaComponent, CalendarComponent, DataZoomComponent, DatasetComponent, GridComponent, LegendComponent, MarkLineComponent, MarkPointComponent, MatrixComponent, ParallelComponent, PolarComponent,
12
+ RadarComponent, SingleAxisComponent, TitleComponent, TooltipComponent, TransformComponent, VisualMapComponent,
13
+ } from 'echarts/components';
14
+ import type { EChartsOption } from 'echarts';
15
+ import { use } from 'echarts/core';
16
+ import { CanvasRenderer, SVGRenderer } from 'echarts/renderers';
17
+ import type { VisualPalette as ChartPalette } from '@harness/sdk';
18
+
19
+ use([
20
+ BarChart, BoxplotChart, CandlestickChart, ChordChart, CustomChart, EffectScatterChart, FunnelChart, GaugeChart, GraphChart, HeatmapChart, LineChart, LinesChart,
21
+ ParallelChart, PictorialBarChart, PieChart, RadarChart, SankeyChart, ScatterChart, SunburstChart, ThemeRiverChart, TreeChart, TreemapChart,
22
+ AriaComponent, CalendarComponent, DataZoomComponent, DatasetComponent, GridComponent, LegendComponent, MarkLineComponent, MarkPointComponent, MatrixComponent, ParallelComponent, PolarComponent,
23
+ RadarComponent, SingleAxisComponent, TitleComponent, TooltipComponent, TransformComponent, VisualMapComponent,
24
+ CanvasRenderer, SVGRenderer,
25
+ ]);
26
+
27
+ /**
28
+ * Every option a built-in family draws. Typed as ECharts' full option (a type only: it costs nothing in the bundle), since
29
+ * `ComposeOption`'s dependency index signature rejects exact optional props; the `use` list above is what is drawable.
30
+ */
31
+ export type ChartOption = EChartsOption;
32
+
33
+ /** An ECharts theme object: the parts of a theme a palette sets (passed to `setTheme`, never registered by name). */
34
+ export interface ChartTheme {
35
+ readonly color: readonly string[];
36
+ readonly backgroundColor: string;
37
+ readonly textStyle: { readonly color: string; readonly fontFamily: string };
38
+ readonly [part: string]: unknown;
39
+ }
40
+
41
+ /** The axis look every cartesian, polar and single axis shares. */
42
+ function axis(palette: ChartPalette): Readonly<Record<string, unknown>> {
43
+ return {
44
+ axisLine: { lineStyle: { color: palette.grid } }, axisTick: { lineStyle: { color: palette.grid } },
45
+ // labels that would run into each other are left out (a day axis on a phone)
46
+ axisLabel: { color: palette.muted, hideOverlap: true }, splitLine: { lineStyle: { color: palette.grid } }, nameTextStyle: { color: palette.muted },
47
+ };
48
+ }
49
+
50
+ /** The ECharts theme of a palette: series colours, text, axes, legend, tooltip and zoom in the theme's colours. */
51
+ export function chartTheme(palette: ChartPalette): ChartTheme {
52
+ const axes = axis(palette);
53
+ return {
54
+ color: palette.series,
55
+ backgroundColor: 'transparent',
56
+ textStyle: { color: palette.text, fontFamily: palette.font },
57
+ markPoint: { label: { color: palette.surface } },
58
+ title: { textStyle: { color: palette.text }, subtextStyle: { color: palette.muted } },
59
+ legend: { textStyle: { color: palette.muted }, pageTextStyle: { color: palette.muted }, pageIconColor: palette.text, pageIconInactiveColor: palette.grid },
60
+ tooltip: { backgroundColor: palette.surface, borderColor: palette.grid, textStyle: { color: palette.text } },
61
+ categoryAxis: axes, valueAxis: axes, timeAxis: axes, logAxis: axes,
62
+ radar: { axisName: { color: palette.muted }, axisLine: { lineStyle: { color: palette.grid } }, splitLine: { lineStyle: { color: palette.grid } }, splitArea: { show: false } },
63
+ dataZoom: { textStyle: { color: palette.muted }, borderColor: palette.grid, fillerColor: `${palette.series[0] ?? palette.text}22`, handleStyle: { color: palette.surface, borderColor: palette.muted } },
64
+ visualMap: { textStyle: { color: palette.muted } },
65
+ calendar: { dayLabel: { color: palette.muted }, monthLabel: { color: palette.muted }, yearLabel: { color: palette.muted }, itemStyle: { color: palette.surface, borderColor: palette.grid }, splitLine: { lineStyle: { color: palette.grid } } },
66
+ candlestick: { itemStyle: { color: palette.up, color0: palette.down, borderColor: palette.up, borderColor0: palette.down } },
67
+ graph: { lineStyle: { color: palette.grid }, label: { color: palette.text } },
68
+ };
69
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A chart as an image (look-export): PNG from an off-screen canvas instance, SVG from a server-side-rendered SVG
3
+ * instance, both drawn from the same option and theme as the chart shown, without animation, at its size. The result
4
+ * view's Export image saves what this gives (the sdk's `VISUAL_IMAGE` slot).
5
+ */
6
+ import type { VisualImageKind } from '@harness/sdk';
7
+ import { init } from 'echarts/core';
8
+ import type { ChartOption, ChartTheme } from './echarts-setup.ts';
9
+
10
+ /** What an image is drawn from. */
11
+ export interface ImageSource {
12
+ readonly option: ChartOption;
13
+ readonly theme: ChartTheme;
14
+ readonly width: number;
15
+ readonly height: number;
16
+ /** The ground a PNG is filled with (a transparent chart reads badly in an image viewer). */
17
+ readonly background: string;
18
+ }
19
+
20
+ /** The chart as a data URL of the kind asked for. */
21
+ export function chartImage(source: ImageSource, kind: VisualImageKind): string {
22
+ const size = { width: Math.max(1, Math.round(source.width)), height: Math.max(1, Math.round(source.height)) };
23
+ const option = { ...source.option, animation: false };
24
+ if (kind === 'svg') {
25
+ const chart = init(null, source.theme, { renderer: 'svg', ssr: true, ...size });
26
+ try {
27
+ chart.setOption({ ...option, backgroundColor: source.background });
28
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(chart.renderToSVGString())}`;
29
+ } finally { chart.dispose(); }
30
+ }
31
+ const chart = init(document.createElement('div'), source.theme, { renderer: 'canvas', ...size });
32
+ try {
33
+ chart.setOption(option);
34
+ return chart.getDataURL({ type: 'png', pixelRatio: 2, backgroundColor: source.background });
35
+ } finally { chart.dispose(); }
36
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Days on a calendar: a month (a week per row, each day numbered by a `custom` series) or a year (`calendar`
3
+ * coordinate), shaded by a measure (`heatmap`), a month of dots sized by it (`scatter`), or marked (`scatter`) when
4
+ * there is none. It shows one period at a time, the latest first; moving to another sets the
5
+ * widget's from/to args to that period.
6
+ */
7
+ import type { CustomSeriesRenderItem } from 'echarts';
8
+ import { bound, chartValue, labelOf, needed, numberOf, tooltip, type ChartBuilder, type ChartPeriod } from '../chart-data.ts';
9
+
10
+ /** A value's calendar day, `YYYY-MM-DD`, or `undefined` when it is not a date. */
11
+ export function dayOf(value: unknown): string | undefined {
12
+ if (typeof value !== 'string' && typeof value !== 'number') { return undefined; }
13
+ const ms = typeof value === 'number' ? value : Date.parse(value.length === 10 ? `${value}T00:00:00Z` : value);
14
+ return Number.isNaN(ms) ? undefined : new Date(ms).toISOString().slice(0, 10);
15
+ }
16
+
17
+ /** The period `shift` steps back from the latest day: a month (`YYYY-MM`) or a year. */
18
+ export function periodOf(latest: string, year: boolean, shift: number): { readonly range: string; readonly from: string; readonly to: string; readonly label: string } {
19
+ const y = Number(latest.slice(0, 4)); const m = Number(latest.slice(5, 7)) - 1;
20
+ if (year) {
21
+ const shown = y - shift;
22
+ return { range: String(shown), from: `${String(shown)}-01-01`, to: `${String(shown)}-12-31`, label: String(shown) };
23
+ }
24
+ const first = new Date(Date.UTC(y, m - shift, 1));
25
+ const last = new Date(Date.UTC(first.getUTCFullYear(), first.getUTCMonth() + 1, 0));
26
+ const from = first.toISOString().slice(0, 10);
27
+ return { range: from.slice(0, 7), from, to: last.toISOString().slice(0, 10), label: first.toLocaleDateString(undefined, { month: 'long', year: 'numeric', timeZone: 'UTC' }) };
28
+ }
29
+
30
+ export const calendar: ChartBuilder = (input) => {
31
+ const time = needed(input, 'time');
32
+ const value = bound(input, 'value');
33
+ const label = bound(input, 'label');
34
+ const days = input.table.rows.map((row) => dayOf(row[time.index]));
35
+ const known = days.filter((day): day is string => day !== undefined).sort();
36
+ const latest = known.at(-1) ?? new Date().toISOString().slice(0, 10);
37
+ const year = input.style === 'year';
38
+ const shown = periodOf(latest, year, input.shift);
39
+ const rows = days.flatMap((day, at) => (day !== undefined && day >= shown.from && day <= shown.to ? [at] : []));
40
+ const period: ChartPeriod = { label: shown.label, from: shown.from, to: shown.to, before: (known[0] ?? latest) < shown.from, after: latest > shown.to };
41
+ const data = rows.map((at) => {
42
+ const row = input.table.rows[at] ?? [];
43
+ return [days[at] ?? '', value === undefined ? 1 : numberOf(row[value.index]), label === undefined ? '' : labelOf(chartValue(row[label.index]))];
44
+ });
45
+ const numbers = data.flatMap((d) => (typeof d[1] === 'number' ? [d[1]] : []));
46
+ // dots: a month with a dot per day sized by the value, no shading scale
47
+ const dots = input.style === 'dots';
48
+ const most = Math.max(1, ...numbers);
49
+ const least = Math.min(0, ...numbers);
50
+ const accent = input.palette.series[0] ?? input.palette.text;
51
+ const shaded = value !== undefined && !dots;
52
+ // a month reads like a wall calendar: a column per weekday, a row per week, each day numbered in its corner; a year
53
+ // stays a strip of weeks, a column per week
54
+ const yearCells: (number | 'auto')[] = ['auto', input.phone ? 9 : 14];
55
+ const monthCells: (number | 'auto')[] = ['auto', 'auto'];
56
+ const calendarBox = year
57
+ ? {
58
+ range: shown.range, top: 28, left: input.phone ? 8 : 32, right: 8, bottom: shaded ? 44 : 8, cellSize: yearCells,
59
+ orient: 'horizontal' as const, splitLine: { show: false }, yearLabel: { show: false }, dayLabel: { firstDay: 1, nameMap: input.phone ? 'EN' : 'en' },
60
+ itemStyle: { color: 'transparent', borderColor: input.palette.grid, borderWidth: 1 },
61
+ }
62
+ : {
63
+ range: shown.range, top: 28, left: 8, right: 8, bottom: shaded ? 44 : 8, cellSize: monthCells,
64
+ orient: 'vertical' as const, splitLine: { show: false }, yearLabel: { show: false }, monthLabel: { show: false },
65
+ dayLabel: { firstDay: 1, position: 'start' as const, nameMap: input.phone ? 'EN' : 'en', color: input.palette.muted, margin: 8 },
66
+ itemStyle: { color: 'transparent', borderColor: input.palette.grid, borderWidth: 1 },
67
+ };
68
+ // every day of a shown month, numbered in its cell's top-left corner (silent: a click lands on the day's mark)
69
+ const monthDays = year ? [] : Array.from({ length: Number(shown.to.slice(8, 10)) }, (_, i) => `${shown.range}-${String(i + 1).padStart(2, '0')}`);
70
+ const dayNumbers: CustomSeriesRenderItem = (params, api) => {
71
+ const day = monthDays[params.dataIndex] ?? '';
72
+ const [x = 0, y = 0] = api.coord(day);
73
+ const box = params.coordSys;
74
+ const width = 'cellWidth' in box && typeof box.cellWidth === 'number' ? box.cellWidth : 0;
75
+ const height = 'cellHeight' in box && typeof box.cellHeight === 'number' ? box.cellHeight : 0;
76
+ return {
77
+ type: 'text', silent: true, x: x - width / 2 + 4, y: y - height / 2 + 3,
78
+ style: { text: String(Number(day.slice(8, 10))), fill: input.palette.muted, fontSize: input.phone ? 9 : 11, fontFamily: input.palette.font, align: 'left', verticalAlign: 'top' },
79
+ };
80
+ };
81
+ const numbered = year ? [] : [{ type: 'custom' as const, coordinateSystem: 'calendar', data: monthDays.map((day) => [day]), renderItem: dayNumbers, silent: true, z: 5, tooltip: { show: false } }];
82
+ return {
83
+ option: {
84
+ useUTC: true,
85
+ tooltip: tooltip('item'),
86
+ calendar: calendarBox,
87
+ ...(shaded ? {
88
+ visualMap: {
89
+ type: 'continuous', dimension: 1, min: numbers.length === 0 ? 0 : least, max: numbers.length === 0 ? 1 : most, orient: 'horizontal', left: 'center', bottom: 0, seriesIndex: 0,
90
+ itemHeight: 140, itemWidth: 10, inRange: { color: [accent], colorAlpha: [0.15, 1] },
91
+ },
92
+ } : {}),
93
+ series: [
94
+ value === undefined
95
+ ? { type: 'scatter', coordinateSystem: 'calendar', data, symbolSize: year ? 6 : 12, itemStyle: { color: accent } }
96
+ : dots
97
+ ? { type: 'scatter', coordinateSystem: 'calendar', data, symbolSize: (point: readonly (number | string | null)[]) => 4 + Math.sqrt(Math.max(0, typeof point[1] === 'number' ? point[1] : 0) / most) * (input.phone ? 18 : 28), itemStyle: { color: accent, opacity: 0.85 } }
98
+ : { type: 'heatmap', coordinateSystem: 'calendar', data },
99
+ ...numbered,
100
+ ],
101
+ },
102
+ rowOf: (click) => (click.dataIndex === undefined || (click.seriesIndex ?? 0) !== 0 ? undefined : rows[click.dataIndex]),
103
+ period, points: data.length + monthDays.length, height: year ? (input.phone ? 150 : 200) : (input.phone ? 300 : 340),
104
+ };
105
+ };
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Measures per category: bars, stacked, 100% stacked, horizontal, stacked horizontal, bars with values (`bar`), line,
3
+ * smooth line and area (`line`), radar (`radar`), polar and radial bars (`bar` on `polar`), pictorial bars
4
+ * (`pictorialBar`), lollipops (`bar` stems with `scatter` heads), a waterfall (stacked `bar` over an invisible base), a
5
+ * pareto (sorted `bar` with a cumulative-share `line` on a second axis) and bars with a line (the first measure as bars,
6
+ * the rest as lines). Many categories zoom (pinch on a phone).
7
+ */
8
+ import type { BarSeriesOption, LineSeriesOption, PictorialBarSeriesOption, ScatterSeriesOption } from 'echarts/charts';
9
+ import { legend, plotGrid, SMOOTH, tooltip, zoom, type ChartBuilder, type ChartClick, type ChartInput, type ChartValue } from '../chart-data.ts';
10
+ import { asPercent, wide, type Wide } from './wide.ts';
11
+
12
+ /** Past this many categories the axis zooms instead of squeezing every label in. */
13
+ export const CATEGORY_ZOOM_AFTER = 20;
14
+
15
+ /** A cell as a number for maths (empty is 0). */
16
+ function num(value: ChartValue | undefined): number {
17
+ return typeof value === 'number' ? value : 0;
18
+ }
19
+
20
+ /**
21
+ * A waterfall's bars: each value as a step from the running total before it, on an invisible base (`base` is where the
22
+ * step starts, `rise` and `fall` its height), and a final total bar.
23
+ */
24
+ export function waterfallSteps(values: readonly number[]): { readonly base: number[]; readonly rise: (number | null)[]; readonly fall: (number | null)[]; readonly total: number } {
25
+ const base: number[] = []; const rise: (number | null)[] = []; const fall: (number | null)[] = [];
26
+ let running = 0;
27
+ for (const value of values) {
28
+ const next = running + value;
29
+ base.push(Math.min(running, next));
30
+ rise.push(value >= 0 ? value : null);
31
+ fall.push(value < 0 ? -value : null);
32
+ running = next;
33
+ }
34
+ return { base, rise, fall, total: running };
35
+ }
36
+
37
+ /** A pareto's order and running share: the categories largest first, and each one's cumulative percentage of the total. */
38
+ export function paretoOf(values: readonly number[]): { readonly order: number[]; readonly share: number[] } {
39
+ const order = values.map((_, i) => i).sort((a, b) => (values[b] ?? 0) - (values[a] ?? 0));
40
+ const total = values.reduce((sum, value) => sum + value, 0);
41
+ let running = 0;
42
+ const share = order.map((i) => { running += values[i] ?? 0; return total === 0 ? 0 : (running / total) * 100; });
43
+ return { order, share };
44
+ }
45
+
46
+ /** The largest total of one category's values (its stacked bar's length), at least 1. */
47
+ function radialMax(source: readonly (readonly ChartValue[])[]): number {
48
+ return Math.max(1, ...source.map((row) => row.slice(1).reduce<number>((sum, value) => sum + Math.abs(num(value)), 0)));
49
+ }
50
+
51
+ /** The category and value axes, swapped for horizontal styles (categories read top to bottom). */
52
+ function axes(input: ChartInput, count: number, horizontal: boolean, percent = false): { xAxis: object; yAxis: object } {
53
+ const categoryAxis = { type: 'category' as const, axisLabel: { hideOverlap: true, ...(horizontal ? {} : { rotate: input.phone && count > 6 ? 30 : 0 }) } };
54
+ const valueAxis = { type: 'value' as const, ...(percent ? { max: 100, axisLabel: { formatter: '{value}%' } } : {}) };
55
+ return horizontal ? { xAxis: valueAxis, yAxis: { ...categoryAxis, inverse: true } } : { xAxis: categoryAxis, yAxis: valueAxis };
56
+ }
57
+
58
+ /** A waterfall: a step per category from the running total, rises and falls in the theme's colours, then the total. */
59
+ function waterfall(input: ChartInput, data: Wide): ReturnType<ChartBuilder> {
60
+ const keys = data.source.map((row) => String(row[0] ?? ''));
61
+ const steps = waterfallSteps(data.source.map((row) => num(row[1])));
62
+ const name = data.names[0] ?? '';
63
+ const total = 'Total';
64
+ const stack = { stack: 'steps', barMaxWidth: 40 } as const;
65
+ return {
66
+ option: {
67
+ // per bar, so the invisible base never shows in a tooltip
68
+ tooltip: tooltip('item'), legend: legend(false), grid: plotGrid(8),
69
+ xAxis: { type: 'category', data: [...keys, total], axisLabel: { hideOverlap: true, rotate: input.phone && keys.length > 6 ? 30 : 0 } }, yAxis: { type: 'value' },
70
+ series: [
71
+ { ...stack, type: 'bar', name: 'base', data: [...steps.base, 0], itemStyle: { color: 'transparent' }, tooltip: { show: false }, silent: true },
72
+ { ...stack, type: 'bar', name, data: [...steps.rise, steps.total >= 0 ? steps.total : null], itemStyle: { color: input.palette.up, borderRadius: 2 } },
73
+ { ...stack, type: 'bar', name: `${name} (down)`, data: [...steps.fall, steps.total < 0 ? -steps.total : null], itemStyle: { color: input.palette.down, borderRadius: 2 } },
74
+ ],
75
+ },
76
+ rowOf: (click) => (click.dataIndex === undefined || click.dataIndex >= keys.length || (click.seriesIndex ?? 0) === 0 ? undefined : data.rowAt(click.dataIndex, 0)),
77
+ points: keys.length + 1,
78
+ };
79
+ }
80
+
81
+ /** A pareto: bars largest first, with the running share of the total as a line on a 0–100% axis. */
82
+ function pareto(input: ChartInput, data: Wide): ReturnType<ChartBuilder> {
83
+ const values = data.source.map((row) => num(row[1]));
84
+ const { order, share } = paretoOf(values);
85
+ const keys = order.map((i) => String(data.source[i]?.[0] ?? ''));
86
+ return {
87
+ option: {
88
+ tooltip: tooltip('axis'), legend: legend(true), grid: plotGrid(36),
89
+ xAxis: { type: 'category', data: keys, axisLabel: { hideOverlap: true, rotate: input.phone && keys.length > 6 ? 30 : 0 } },
90
+ yAxis: [{ type: 'value' }, { type: 'value', max: 100, axisLabel: { formatter: '{value}%' }, splitLine: { show: false } }],
91
+ series: [
92
+ { type: 'bar', name: data.names[0] ?? '', data: order.map((i) => values[i] ?? 0), barMaxWidth: 36, itemStyle: { borderRadius: 3 } },
93
+ { type: 'line', name: 'Cumulative %', yAxisIndex: 1, data: share.map((s) => Math.round(s * 10) / 10), symbolSize: 6, itemStyle: { color: input.palette.series[1] ?? input.palette.text } },
94
+ ],
95
+ },
96
+ rowOf: (click) => (click.dataIndex === undefined || (click.seriesIndex ?? 0) !== 0 ? undefined : data.rowAt(order[click.dataIndex] ?? -1, 0)),
97
+ points: keys.length * 2,
98
+ };
99
+ }
100
+
101
+ export const category: ChartBuilder = (input) => {
102
+ const data = wide(input, 'x');
103
+ const percent = input.style === 'percent';
104
+ const source = percent ? asPercent(data.source) : data.source;
105
+ const dims = ['key', ...data.names.map((_, i) => `s${String(i)}`)];
106
+ const many = data.names.length > 1;
107
+ const rowOf = (click: ChartClick): number | undefined => (click.dataIndex === undefined ? undefined : data.rowAt(click.dataIndex, click.seriesIndex ?? 0));
108
+ const points = source.length * data.names.length;
109
+
110
+ if (input.style === 'waterfall') { return waterfall(input, data); }
111
+ if (input.style === 'pareto') { return pareto(input, data); }
112
+
113
+ if (input.style === 'radar') {
114
+ const max = Math.max(0, ...source.flatMap((row) => row.slice(1).map((value) => (typeof value === 'number' ? value : 0))));
115
+ return {
116
+ option: {
117
+ tooltip: tooltip('item'), legend: legend(many),
118
+ radar: { indicator: source.map((row) => ({ name: String(row[0] ?? ''), max: max === 0 ? 1 : max })), radius: input.phone ? '58%' : '66%', center: ['50%', '48%'] },
119
+ series: [{ type: 'radar', data: data.names.map((name, s) => ({ name, value: source.map((row) => (typeof row[s + 1] === 'number' ? Number(row[s + 1]) : 0)) })), areaStyle: { opacity: 0.12 } }],
120
+ },
121
+ points,
122
+ };
123
+ }
124
+
125
+ const dataset = { dimensions: dims, source };
126
+ if (input.style === 'polar' || input.style === 'radial') {
127
+ // polar: categories round the circle, bars outwards; radial: categories as rings, bars round the circle
128
+ const radial = input.style === 'radial';
129
+ return {
130
+ option: {
131
+ dataset, tooltip: tooltip('item'), legend: legend(many), polar: { radius: radial ? ['16%', '76%'] : ['12%', '72%'], center: ['50%', many ? '46%' : '50%'] },
132
+ // radial: the largest total takes three quarters of the circle, so each ring's name at its start stays clear of the others' ends
133
+ angleAxis: radial ? { type: 'value', startAngle: 90, max: radialMax(source) * 4 / 3, splitLine: { show: false }, axisLabel: { show: false }, axisTick: { show: false }, axisLine: { show: false } } : { type: 'category' },
134
+ radiusAxis: radial ? { type: 'category', z: 10, axisLabel: { interval: 0, fontSize: input.phone ? 10 : 12, color: input.palette.text }, axisTick: { show: false }, axisLine: { show: false } } : { type: 'value' },
135
+ series: data.names.map((name, s) => ({
136
+ type: 'bar' as const, name, coordinateSystem: 'polar' as const, stack: 'total', ...(radial ? { roundCap: true, barWidth: '60%' } : {}),
137
+ encode: radial ? { radius: 'key', angle: dims[s + 1] ?? 's0' } : { angle: 'key', radius: dims[s + 1] ?? 's0' },
138
+ })),
139
+ },
140
+ rowOf, points,
141
+ };
142
+ }
143
+
144
+ const horizontal = input.style === 'horizontal' || input.style === 'stacked-horizontal';
145
+ const stacked = input.style === 'stacked' || input.style === 'stacked-horizontal' || percent;
146
+ const series = data.names.flatMap((name, s): (BarSeriesOption | LineSeriesOption | PictorialBarSeriesOption | ScatterSeriesOption)[] => {
147
+ const value = dims[s + 1] ?? 's0';
148
+ const encode = horizontal ? { y: 'key', x: value } : { x: 'key', y: value };
149
+ switch (input.style) {
150
+ case 'line': case 'area': case 'smooth':
151
+ return [{ type: 'line', name, encode, showSymbol: source.length <= 30, ...(input.style === 'area' ? { areaStyle: { opacity: 0.16 } } : {}), ...(input.style === 'smooth' ? SMOOTH : {}) }];
152
+ case 'pictorial':
153
+ // a pictorial bar overlaps the one before it by default (barGap -100%): each series takes its own slot instead
154
+ return [{ type: 'pictorialBar', name, encode, symbol: 'roundRect', symbolRepeat: true, symbolSize: ['80%', 6], symbolMargin: 2, barGap: '12%', barCategoryGap: many ? '28%' : '40%' }];
155
+ case 'lollipop': {
156
+ const color = input.palette.series[s % input.palette.series.length] ?? input.palette.text;
157
+ return [
158
+ { type: 'bar', name, encode, barWidth: 2, itemStyle: { color }, tooltip: { show: false } },
159
+ { type: 'scatter', name, encode, symbolSize: 12, itemStyle: { color }, z: 3 },
160
+ ];
161
+ }
162
+ case 'mixed':
163
+ return [s === 0
164
+ ? { type: 'bar', name, encode, barMaxWidth: 36, itemStyle: { borderRadius: 3 } }
165
+ : { type: 'line', name, encode, yAxisIndex: 1, showSymbol: source.length <= 30, ...SMOOTH }];
166
+ default:
167
+ return [{
168
+ type: 'bar', name, encode, ...(stacked ? { stack: 'total' } : {}), barMaxWidth: 36, itemStyle: { borderRadius: stacked ? 0 : 3 },
169
+ ...(input.style === 'labels' ? { label: { show: true, position: horizontal ? 'right' as const : 'top' as const, color: input.palette.text, fontSize: 11 } } : {}),
170
+ }];
171
+ }
172
+ });
173
+ const zoomed = source.length > CATEGORY_ZOOM_AFTER;
174
+ const legendRoom = many ? 28 : 0;
175
+ const { xAxis, yAxis } = axes(input, source.length, horizontal, percent);
176
+ const lollipop = input.style === 'lollipop';
177
+ return {
178
+ option: {
179
+ dataset, tooltip: tooltip(lollipop ? 'item' : 'axis'), legend: legend(many && !lollipop), grid: plotGrid(legendRoom + (zoomed && !input.phone && !horizontal ? 36 : 8)),
180
+ xAxis, yAxis: input.style === 'mixed' ? [yAxis, { type: 'value', splitLine: { show: false } }] : yAxis,
181
+ ...(zoomed ? { dataZoom: zoom(input.phone, horizontal ? { yAxisIndex: [0] } : { xAxisIndex: [0] }) } : {}),
182
+ series,
183
+ },
184
+ rowOf: lollipop ? (click) => (click.dataIndex === undefined ? undefined : data.rowAt(click.dataIndex, 0)) : rowOf, points,
185
+ };
186
+ };