@theoremjs/studio 0.0.0-stage → 0.3.2

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 (473) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -2
  3. package/agreement.d.ts +14 -0
  4. package/agreement.js +80 -0
  5. package/asks.d.ts +47 -0
  6. package/asks.js +54 -0
  7. package/browser-connection.d.ts +49 -0
  8. package/browser-connection.js +215 -0
  9. package/browser-engine.d.ts +11 -0
  10. package/browser-engine.js +11 -0
  11. package/browser-execution.d.ts +6 -0
  12. package/browser-execution.js +18 -0
  13. package/browser-live.d.ts +4 -0
  14. package/browser-live.js +132 -0
  15. package/browser-transport.d.ts +33 -0
  16. package/browser-transport.js +229 -0
  17. package/browser.d.ts +4 -0
  18. package/browser.js +4 -0
  19. package/canonical.d.ts +10 -0
  20. package/canonical.js +25 -0
  21. package/compile-workspace.d.ts +28 -0
  22. package/compile-workspace.js +295 -0
  23. package/compile.d.ts +65 -0
  24. package/compile.js +1605 -0
  25. package/concierge-demo.d.ts +17 -0
  26. package/concierge-demo.js +1230 -0
  27. package/conversation-key.d.ts +5 -0
  28. package/conversation-key.js +10 -0
  29. package/decision-example-images.d.ts +30 -0
  30. package/decision-example-images.js +30 -0
  31. package/deno.json +3 -0
  32. package/draft.d.ts +407 -0
  33. package/draft.js +505 -0
  34. package/editors.d.ts +29 -0
  35. package/editors.js +51 -0
  36. package/example-embedding-files.d.ts +11 -0
  37. package/example-embedding-files.js +20 -0
  38. package/example.d.ts +36 -0
  39. package/example.js +357 -0
  40. package/guardrail-probe.d.ts +100 -0
  41. package/guardrail-probe.js +722 -0
  42. package/held-credentials.d.ts +28 -0
  43. package/held-credentials.js +87 -0
  44. package/installed.mjs +40 -0
  45. package/lent-keys.d.ts +122 -0
  46. package/lent-keys.js +47 -0
  47. package/line-diff.d.ts +15 -0
  48. package/line-diff.js +41 -0
  49. package/live-connection.d.ts +22 -0
  50. package/live-connection.js +27 -0
  51. package/live-session-bridge.d.ts +15 -0
  52. package/live-session-bridge.js +202 -0
  53. package/map-line.d.ts +19 -0
  54. package/map-line.js +42 -0
  55. package/map.d.ts +154 -0
  56. package/map.js +525 -0
  57. package/media-accept.d.ts +19 -0
  58. package/media-accept.js +65 -0
  59. package/mod.d.ts +39 -0
  60. package/mod.js +33 -0
  61. package/origins.d.ts +52 -0
  62. package/origins.js +165 -0
  63. package/package.json +85 -4
  64. package/page/assets/Banner-BISz3nXA.js +2 -0
  65. package/page/assets/BottomSheet-BwfBDtje.js +1 -0
  66. package/page/assets/Card-Lp-0P5eL.js +1 -0
  67. package/page/assets/CardWall-CBRLdDZW.js +1 -0
  68. package/page/assets/Center-nHS1JSux.js +1 -0
  69. package/page/assets/CheckboxInput-Cj5pk-KI.js +2 -0
  70. package/page/assets/CodeBlock-C7XJ4ioE.js +51 -0
  71. package/page/assets/CollapsibleGroup-N7_SOjbm.js +2 -0
  72. package/page/assets/ContextMenu-CBu9H-9H.js +2 -0
  73. package/page/assets/DateInput-BGrQ5tPC.js +1 -0
  74. package/page/assets/Dialog-DELWQo-v.js +1 -0
  75. package/page/assets/EmptyState-C8W4JKBZ.js +1 -0
  76. package/page/assets/HoverCard-D1Y1ltWQ.js +1 -0
  77. package/page/assets/Icon-JrysT8aU.js +3 -0
  78. package/page/assets/IconAlertTriangle-BqAEqqdU.js +1 -0
  79. package/page/assets/IconButton-DlOGzJIX.js +1 -0
  80. package/page/assets/IconEye-BB5aY-wQ.js +1 -0
  81. package/page/assets/IconFileText-6zOFKKrF.js +1 -0
  82. package/page/assets/IconSearch-BTx66a40.js +1 -0
  83. package/page/assets/IconShield-DDOh7Gr5.js +1 -0
  84. package/page/assets/ItemSwipeLayer-Ckn4X6h9.js +1 -0
  85. package/page/assets/PaneState-BvA2tLQg.js +1 -0
  86. package/page/assets/PaneState-eUzUkNE8.css +1 -0
  87. package/page/assets/ScrollableArea-Ckugdj1N.js +1 -0
  88. package/page/assets/Section-DJ97F7QE.js +1 -0
  89. package/page/assets/SegmentedControlItem-h-aaXzyS.js +1 -0
  90. package/page/assets/SidePanel-BL32abk8.js +1 -0
  91. package/page/assets/StackItem-CQviqAfM.js +1 -0
  92. package/page/assets/Text-bum6zWWx.js +2 -0
  93. package/page/assets/TimestampHoverCard-DQIG0RZF.js +1 -0
  94. package/page/assets/ToolResultCharts-CgshSv9Q.js +1 -0
  95. package/page/assets/Tooltip-BH9xiRMl.js +1 -0
  96. package/page/assets/TraceInspector-_yZiz05W.js +1 -0
  97. package/page/assets/TraceOverview-BPO-HIYK.js +57 -0
  98. package/page/assets/VStack-CkVMcNiK.js +1 -0
  99. package/page/assets/_virtual_studio-type-sources-ByxqQaOG.js +12936 -0
  100. package/page/assets/arrive-DvbqpeRS.js +1 -0
  101. package/page/assets/browser-engine-CYq9DQAM.js +9 -0
  102. package/page/assets/browser-transport-D-2jDYe7.js +47 -0
  103. package/page/assets/codicon-DF1abBS2.ttf +0 -0
  104. package/page/assets/compile-egress-BSxOdX4K.js +23 -0
  105. package/page/assets/container.stylex-BmOi-8DQ.js +1 -0
  106. package/page/assets/createReactComponent-CZwsv6DD.js +1 -0
  107. package/page/assets/decision-example-images-CZGr7YIT.js +1 -0
  108. package/page/assets/devWarning-DxuplmRl.js +1 -0
  109. package/page/assets/editor-DjpsE8to.css +1 -0
  110. package/page/assets/editor.api-Cd3ViPQa.js +908 -0
  111. package/page/assets/editor.worker-6GY8RhDc.js +1 -0
  112. package/page/assets/editor.worker-BmdWdrHZ.js +33 -0
  113. package/page/assets/editors-BJX_S59A.js +1 -0
  114. package/page/assets/egress-automata-B5ZGE1mT.js +1 -0
  115. package/page/assets/embedding-space-view-CfQBPDxD.js +140 -0
  116. package/page/assets/encode-files-Bc3HJyAh.js +1 -0
  117. package/page/assets/export-agent-C3yyzXH8.js +43 -0
  118. package/page/assets/figtree-latin-400-normal-BD4aNku5.woff +0 -0
  119. package/page/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
  120. package/page/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
  121. package/page/assets/figtree-latin-500-normal-B_yy1phn.woff +0 -0
  122. package/page/assets/figtree-latin-600-normal-BM_oTo4n.woff +0 -0
  123. package/page/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
  124. package/page/assets/figtree-latin-700-normal-BCCt2T1q.woff +0 -0
  125. package/page/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
  126. package/page/assets/focusOutline.stylex-BT0kfa4t.js +1 -0
  127. package/page/assets/focusableSelector-DXZeMU85.js +1 -0
  128. package/page/assets/groupStyles-C7Ter7zC.js +1 -0
  129. package/page/assets/guardrail-tester-Gut5xK4a.js +9 -0
  130. package/page/assets/host-patterns-C9RMP16Q.js +1 -0
  131. package/page/assets/index-CvvmFKgS.js +105 -0
  132. package/page/assets/index-DOaHlqBo.css +1 -0
  133. package/page/assets/isRtlElement-BG33-k_H.js +1 -0
  134. package/page/assets/labels-provider-4TIWDvsE.js +3 -0
  135. package/page/assets/lent-keys-C32ems-I.js +1 -0
  136. package/page/assets/live-ingress-lDUGPwth.js +1 -0
  137. package/page/assets/live-messages-CnkL4GWi.js +1 -0
  138. package/page/assets/mergeProps-ptS-gIMz.js +1 -0
  139. package/page/assets/padding.stylex-B76907Zf.js +1 -0
  140. package/page/assets/preload-helper-DpV6A1kQ.js +1 -0
  141. package/page/assets/reader-BOCCYaRp.js +7 -0
  142. package/page/assets/register-CDgivxvX.js +2 -0
  143. package/page/assets/rolldown-runtime-hePW80VL.js +1 -0
  144. package/page/assets/schemas-BQ9Jydzb.js +56 -0
  145. package/page/assets/shaped-data-BcarWqd5.js +16 -0
  146. package/page/assets/sharedResizeObserver-4U9Xq5Oq.js +1 -0
  147. package/page/assets/stub-DhdcU_Ew.js +471 -0
  148. package/page/assets/studio-code-pane-C_SAbcOa.js +8 -0
  149. package/page/assets/studio-console-DZwlEsvr.js +3 -0
  150. package/page/assets/studio-decision-B0FnCAXA.js +1 -0
  151. package/page/assets/studio-embedding-CmA51HVo.js +2 -0
  152. package/page/assets/studio-host-console-By7hqu2l.js +2 -0
  153. package/page/assets/studio-live-BrcVQcyV.js +1 -0
  154. package/page/assets/studio-map-B_xSia-z.js +1 -0
  155. package/page/assets/studio-map-Bb06Tw1F.css +1 -0
  156. package/page/assets/studio-monaco-CbKf90i6.css +1 -0
  157. package/page/assets/studio-monaco-xfyfezQS.js +34 -0
  158. package/page/assets/studio-ts.worker-B-EXG4Sv.js +67741 -0
  159. package/page/assets/studio-ts.worker-BXtW3z-O.js +1 -0
  160. package/page/assets/studio-type-checker-BOvxudki.js +23 -0
  161. package/page/assets/themeProps-3IqahpCr.js +1 -0
  162. package/page/assets/tokens.stylex-DkHf0P9C.js +1 -0
  163. package/page/assets/tool-schema-idaOe2nI.js +18 -0
  164. package/page/assets/trace-patterns-DnYJa0nI.js +1 -0
  165. package/page/assets/trace-record-C3zNksA_.js +1 -0
  166. package/page/assets/trace-schema-9CdEyG6Q.js +1 -0
  167. package/page/assets/tree-DqyAMsbI.js +3 -0
  168. package/page/assets/turn-client-Du3Um3Mg.js +2 -0
  169. package/page/assets/types-BhfXQCLx.js +1 -0
  170. package/page/assets/typescript-20GgZ8PJ.js +1 -0
  171. package/page/assets/use-one-call-Hcs8YBp1.js +1 -0
  172. package/page/assets/useAdaptivePresentation-BzmPCddb.js +1 -0
  173. package/page/assets/useClipboard-BgGRxRMJ.js +1 -0
  174. package/page/assets/useContainerReveal-BFy8N_QU.js +1 -0
  175. package/page/assets/useDevWarning-Z9SoixOP.js +1 -0
  176. package/page/assets/useLayerDismissal-B_G7IWpC.js +1 -0
  177. package/page/assets/useMediaQuery-BCT0NUeZ.js +1 -0
  178. package/page/assets/useScrollLock-Dyf6PHJt.js +1 -0
  179. package/page/assets/useScrollableArea-0NzdiBCq.js +1 -0
  180. package/page/assets/useTooltip-CJM_xhLB.js +1 -0
  181. package/page/assets/workspace-DZALqEDX.js +1 -0
  182. package/page/assets/zip-DTcEfps6.js +1 -0
  183. package/page/index.html +90 -0
  184. package/page.mjs +49 -0
  185. package/people.d.ts +87 -0
  186. package/people.js +110 -0
  187. package/policy.d.ts +43 -0
  188. package/policy.js +102 -0
  189. package/ports.d.mts +32 -0
  190. package/ports.mjs +85 -0
  191. package/probe-battery.d.ts +13 -0
  192. package/probe-battery.js +404 -0
  193. package/providers.d.ts +149 -0
  194. package/providers.js +306 -0
  195. package/read-source.d.ts +48 -0
  196. package/read-source.js +1301 -0
  197. package/read-steps.d.ts +23 -0
  198. package/read-steps.js +2 -0
  199. package/reader.d.ts +11 -0
  200. package/reader.js +11 -0
  201. package/registrations.d.ts +83 -0
  202. package/registrations.js +1 -0
  203. package/requirements.d.ts +22 -0
  204. package/requirements.js +38 -0
  205. package/run-payload-core.d.ts +28 -0
  206. package/run-payload-core.js +123 -0
  207. package/run-payload.d.ts +32 -0
  208. package/run-payload.js +26 -0
  209. package/runtime-scope.d.ts +84 -0
  210. package/runtime-scope.js +308 -0
  211. package/runtime.d.ts +84 -0
  212. package/runtime.js +387 -0
  213. package/section-notes.d.ts +33 -0
  214. package/section-notes.js +38 -0
  215. package/serve-page.mjs +96 -0
  216. package/server/draft-decide.d.ts +72 -0
  217. package/server/draft-decide.js +111 -0
  218. package/server/draft-embedding.d.ts +3 -0
  219. package/server/draft-embedding.js +35 -0
  220. package/server/draft-handler.d.ts +82 -0
  221. package/server/draft-handler.js +213 -0
  222. package/server/draft-probe.d.ts +14 -0
  223. package/server/draft-probe.js +61 -0
  224. package/server/draft-replies.d.ts +22 -0
  225. package/server/draft-replies.js +46 -0
  226. package/server/edited-session.d.ts +28 -0
  227. package/server/edited-session.js +83 -0
  228. package/server/edits.d.ts +38 -0
  229. package/server/edits.js +195 -0
  230. package/server/handler.d.ts +133 -0
  231. package/server/handler.js +598 -0
  232. package/server/lent-draft.d.ts +19 -0
  233. package/server/lent-draft.js +23 -0
  234. package/server/live.d.ts +15 -0
  235. package/server/live.js +96 -0
  236. package/server/open-editor.d.ts +63 -0
  237. package/server/open-editor.js +115 -0
  238. package/server/origins.d.ts +18 -0
  239. package/server/origins.js +330 -0
  240. package/server/project-source.d.ts +208 -0
  241. package/server/project-source.js +1042 -0
  242. package/server/project.d.ts +22 -0
  243. package/server/project.js +56 -0
  244. package/server/run-traces.d.ts +20 -0
  245. package/server/run-traces.js +96 -0
  246. package/server/save-new.d.ts +29 -0
  247. package/server/save-new.js +514 -0
  248. package/server/save-plan.d.ts +46 -0
  249. package/server/save-plan.js +1134 -0
  250. package/server/save-remove.d.ts +21 -0
  251. package/server/save-remove.js +528 -0
  252. package/server/save-session.d.ts +96 -0
  253. package/server/save-session.js +418 -0
  254. package/server/save-wire.d.ts +235 -0
  255. package/server/save-wire.js +8 -0
  256. package/server/save.d.ts +52 -0
  257. package/server/save.js +209 -0
  258. package/server/serve.d.ts +23 -0
  259. package/server/serve.js +413 -0
  260. package/server/test-connection.d.ts +17 -0
  261. package/server/test-connection.js +362 -0
  262. package/server/test-key.d.ts +2 -0
  263. package/server/test-key.js +83 -0
  264. package/server/watch.d.ts +28 -0
  265. package/server/watch.js +93 -0
  266. package/server/zod-edit.d.ts +74 -0
  267. package/server/zod-edit.js +558 -0
  268. package/server.d.ts +8 -0
  269. package/server.js +8 -0
  270. package/setups.mjs +170 -0
  271. package/shared-carry.d.ts +114 -0
  272. package/shared-carry.js +523 -0
  273. package/shared-settings.d.ts +34 -0
  274. package/shared-settings.js +70 -0
  275. package/source.d.ts +75 -0
  276. package/source.js +414 -0
  277. package/start.mjs +169 -0
  278. package/stream-lines.d.ts +9 -0
  279. package/stream-lines.js +27 -0
  280. package/stub.d.ts +6 -0
  281. package/stub.js +33 -0
  282. package/surface.d.ts +53 -0
  283. package/surface.js +631 -0
  284. package/system-markup.d.ts +20 -0
  285. package/system-markup.js +51 -0
  286. package/tool-schema.d.ts +23 -0
  287. package/tool-schema.js +69 -0
  288. package/tools.d.ts +16 -0
  289. package/tools.js +91 -0
  290. package/traces.d.ts +24 -0
  291. package/traces.js +29 -0
  292. package/transport.d.ts +57 -0
  293. package/transport.js +187 -0
  294. package/tree.d.ts +32 -0
  295. package/tree.js +83 -0
  296. package/types.d.ts +62 -0
  297. package/types.js +6 -0
  298. package/ui/acting-as-button.d.ts +2 -0
  299. package/ui/acting-as-button.js +16 -0
  300. package/ui/add-provider.d.ts +13 -0
  301. package/ui/add-provider.js +20 -0
  302. package/ui/boot-mark.css +53 -0
  303. package/ui/boot-mark.d.ts +19 -0
  304. package/ui/boot-mark.js +128 -0
  305. package/ui/boot-paint.d.ts +8 -0
  306. package/ui/boot-paint.js +8 -0
  307. package/ui/brand-icons.d.ts +57 -0
  308. package/ui/brand-icons.js +148 -0
  309. package/ui/built/theme.css +830 -0
  310. package/ui/built/theme.css.d.ts +9 -0
  311. package/ui/built/theorem-studio.d.ts +13 -0
  312. package/ui/built/theorem-studio.js +705 -0
  313. package/ui/built/theorem-studio.variants.d.ts +28 -0
  314. package/ui/code/monaco-contributions.d.ts +45 -0
  315. package/ui/code/studio-code.d.ts +7 -0
  316. package/ui/code/studio-code.js +253 -0
  317. package/ui/code/studio-monaco.d.ts +44 -0
  318. package/ui/code/studio-monaco.js +48 -0
  319. package/ui/code/studio-ts.worker.d.ts +1 -0
  320. package/ui/code/studio-ts.worker.js +16 -0
  321. package/ui/code/studio-type-checker.d.ts +12 -0
  322. package/ui/code/studio-type-checker.js +308 -0
  323. package/ui/code/studio-type-sources.d.ts +26 -0
  324. package/ui/confirm-write.d.ts +12 -0
  325. package/ui/confirm-write.js +45 -0
  326. package/ui/diff-block.d.ts +21 -0
  327. package/ui/diff-block.js +17 -0
  328. package/ui/figtree.css +59 -0
  329. package/ui/file-place.d.ts +4 -0
  330. package/ui/file-place.js +26 -0
  331. package/ui/guardrail-tester.d.ts +18 -0
  332. package/ui/guardrail-tester.js +248 -0
  333. package/ui/inspector-context.d.ts +119 -0
  334. package/ui/inspector-context.js +84 -0
  335. package/ui/inspector.d.ts +247 -0
  336. package/ui/inspector.js +284 -0
  337. package/ui/lib/acting-as.d.ts +25 -0
  338. package/ui/lib/acting-as.js +90 -0
  339. package/ui/lib/boot-sequence.d.ts +32 -0
  340. package/ui/lib/boot-sequence.js +57 -0
  341. package/ui/lib/export-agent.d.ts +11 -0
  342. package/ui/lib/export-agent.js +335 -0
  343. package/ui/lib/facet-icons.d.ts +20 -0
  344. package/ui/lib/facet-icons.js +21 -0
  345. package/ui/lib/panel-motion.d.ts +8 -0
  346. package/ui/lib/panel-motion.js +74 -0
  347. package/ui/lib/project-address.d.ts +14 -0
  348. package/ui/lib/project-address.js +24 -0
  349. package/ui/lib/project-starting.d.ts +13 -0
  350. package/ui/lib/project-starting.js +30 -0
  351. package/ui/lib/project-traces.d.ts +17 -0
  352. package/ui/lib/project-traces.js +54 -0
  353. package/ui/lib/read-map.d.ts +30 -0
  354. package/ui/lib/read-map.js +173 -0
  355. package/ui/lib/read-progress.d.ts +14 -0
  356. package/ui/lib/read-progress.js +12 -0
  357. package/ui/lib/refusal-lines.d.ts +3 -0
  358. package/ui/lib/refusal-lines.js +8 -0
  359. package/ui/lib/studio-activity.d.ts +5 -0
  360. package/ui/lib/studio-activity.js +17 -0
  361. package/ui/lib/studio-console.d.ts +27 -0
  362. package/ui/lib/studio-console.js +9 -0
  363. package/ui/lib/studio-conversation.d.ts +20 -0
  364. package/ui/lib/studio-conversation.js +130 -0
  365. package/ui/lib/studio-examples.d.ts +31 -0
  366. package/ui/lib/studio-examples.js +25 -0
  367. package/ui/lib/studio-labels.d.ts +6 -0
  368. package/ui/lib/studio-labels.js +13 -0
  369. package/ui/lib/studio-map-kept.d.ts +17 -0
  370. package/ui/lib/studio-map-kept.js +48 -0
  371. package/ui/lib/studio-open.d.ts +22 -0
  372. package/ui/lib/studio-open.js +54 -0
  373. package/ui/lib/studio-page.d.ts +33 -0
  374. package/ui/lib/studio-page.js +121 -0
  375. package/ui/lib/studio-prefs.d.ts +26 -0
  376. package/ui/lib/studio-prefs.js +87 -0
  377. package/ui/lib/studio-project.d.ts +106 -0
  378. package/ui/lib/studio-project.js +177 -0
  379. package/ui/lib/studio-restore.d.ts +49 -0
  380. package/ui/lib/studio-restore.js +251 -0
  381. package/ui/lib/studio-run-open.d.ts +15 -0
  382. package/ui/lib/studio-run-open.js +16 -0
  383. package/ui/lib/studio-session.d.ts +34 -0
  384. package/ui/lib/studio-session.js +17 -0
  385. package/ui/lib/studio-settings.d.ts +15 -0
  386. package/ui/lib/studio-settings.js +48 -0
  387. package/ui/lib/studio-store.d.ts +64 -0
  388. package/ui/lib/studio-store.js +391 -0
  389. package/ui/lib/studio-watch.d.ts +12 -0
  390. package/ui/lib/studio-watch.js +27 -0
  391. package/ui/lib/tab-fills.d.ts +6 -0
  392. package/ui/lib/tab-fills.js +14 -0
  393. package/ui/lib/tool-credentials.d.ts +3 -0
  394. package/ui/lib/tool-credentials.js +23 -0
  395. package/ui/lib/tool-probe.d.ts +19 -0
  396. package/ui/lib/tool-probe.js +104 -0
  397. package/ui/lib/type-icons.d.ts +35 -0
  398. package/ui/lib/type-icons.js +38 -0
  399. package/ui/lib/when-idle.d.ts +5 -0
  400. package/ui/lib/when-idle.js +14 -0
  401. package/ui/lib/zip.d.ts +5 -0
  402. package/ui/lib/zip.js +8 -0
  403. package/ui/map-token.css +11 -0
  404. package/ui/map-token.d.ts +17 -0
  405. package/ui/map-token.js +29 -0
  406. package/ui/mcp-icon.d.ts +6 -0
  407. package/ui/mcp-icon.js +8 -0
  408. package/ui/motion.css +113 -0
  409. package/ui/pan.d.ts +32 -0
  410. package/ui/pan.js +90 -0
  411. package/ui/profile-editor.d.ts +33 -0
  412. package/ui/profile-editor.js +2638 -0
  413. package/ui/provider-editor.d.ts +15 -0
  414. package/ui/provider-editor.js +92 -0
  415. package/ui/read-map.css +48 -0
  416. package/ui/read-map.d.ts +7 -0
  417. package/ui/read-map.js +163 -0
  418. package/ui/refusal-detail.d.ts +4 -0
  419. package/ui/refusal-detail.js +21 -0
  420. package/ui/shared-change.d.ts +9 -0
  421. package/ui/shared-change.js +28 -0
  422. package/ui/shell-motion.css +121 -0
  423. package/ui/shell-motion.d.ts +73 -0
  424. package/ui/shell-motion.js +194 -0
  425. package/ui/studio-code-pane.d.ts +19 -0
  426. package/ui/studio-code-pane.js +44 -0
  427. package/ui/studio-compare.d.ts +80 -0
  428. package/ui/studio-compare.js +326 -0
  429. package/ui/studio-conflicts.d.ts +17 -0
  430. package/ui/studio-conflicts.js +87 -0
  431. package/ui/studio-connection.d.ts +64 -0
  432. package/ui/studio-connection.js +286 -0
  433. package/ui/studio-decision.d.ts +6 -0
  434. package/ui/studio-decision.js +49 -0
  435. package/ui/studio-embedding.d.ts +6 -0
  436. package/ui/studio-embedding.js +30 -0
  437. package/ui/studio-host-console.d.ts +6 -0
  438. package/ui/studio-host-console.js +17 -0
  439. package/ui/studio-host.d.ts +73 -0
  440. package/ui/studio-host.js +12 -0
  441. package/ui/studio-live.d.ts +17 -0
  442. package/ui/studio-live.js +26 -0
  443. package/ui/studio-map.css +273 -0
  444. package/ui/studio-map.d.ts +17 -0
  445. package/ui/studio-map.js +397 -0
  446. package/ui/studio-nav.d.ts +24 -0
  447. package/ui/studio-nav.js +17 -0
  448. package/ui/studio-no-project.d.ts +5 -0
  449. package/ui/studio-no-project.js +9 -0
  450. package/ui/studio-run.css +76 -0
  451. package/ui/studio-run.d.ts +14 -0
  452. package/ui/studio-run.js +119 -0
  453. package/ui/studio-runner.d.ts +45 -0
  454. package/ui/studio-runner.js +187 -0
  455. package/ui/studio-save.d.ts +49 -0
  456. package/ui/studio-save.js +307 -0
  457. package/ui/studio-screen.d.ts +61 -0
  458. package/ui/studio-screen.js +2078 -0
  459. package/ui/studio-settings.d.ts +31 -0
  460. package/ui/studio-settings.js +288 -0
  461. package/ui/studio-shell.css +27 -0
  462. package/ui/studio-shell.d.ts +43 -0
  463. package/ui/studio-shell.js +87 -0
  464. package/ui/studio-theme.d.ts +7 -0
  465. package/ui/studio-theme.js +94 -0
  466. package/ui/studio.css +427 -0
  467. package/ui/theorem-mark.css +84 -0
  468. package/ui/theorem-mark.d.ts +22 -0
  469. package/ui/theorem-mark.js +21 -0
  470. package/vite.d.mts +30 -0
  471. package/vite.mjs +277 -0
  472. package/workspace.d.ts +230 -0
  473. package/workspace.js +1054 -0
package/source.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * One serializer writes the values, and each tool's schemas as the Zod expressions
3
+ * `zodFromJsonSchema` would build.
4
+ */
5
+ import type { CompiledStudio } from './compile.ts';
6
+ import type { CompiledWorkspace } from './compile-workspace.ts';
7
+ import { type StudioProvider } from './providers.ts';
8
+ import type { ToolRegistration } from './registrations.ts';
9
+ import type { ProjectOrigins, ProviderPlace } from './server/save-wire.ts';
10
+ /** How a value is laid out: the studio's own files, or a file of the builder's. */
11
+ export interface SourceStyle {
12
+ /** One level of indentation. */
13
+ unit: string;
14
+ /** The indentation of the line the value starts on. */
15
+ base: string;
16
+ /** Text of several lines as a template literal, not as lines joined. */
17
+ template: boolean;
18
+ /** Text of one line as source. Default: the studio's, which escapes what could close a script tag. */
19
+ quote?: (text: string) => string;
20
+ }
21
+ /** A plain value as source, in `style`. */
22
+ export declare function valueSource(value: unknown, style: SourceStyle): string;
23
+ /** The package an exported module imports the kernel from. */
24
+ export declare const AGENTS_PACKAGE = "@theoremjs/agents";
25
+ /**
26
+ * What a project's files hold that an export names where it stands, since the studio does not
27
+ * hold it: each provider's definition, and the settings its profiles set in code.
28
+ */
29
+ export interface ProjectCode {
30
+ /** Where the files define each provider that is still as they define it. */
31
+ providers: readonly ProviderPlace[];
32
+ /** The settings set in code, by profile id. */
33
+ origins: ProjectOrigins['profiles'];
34
+ }
35
+ /**
36
+ * A provider's module: the function `name` that registers it, for the setup to call before every
37
+ * agent. `from` is where the module imports the kernel from. None for a definition that is the
38
+ * project's own.
39
+ */
40
+ export declare function providerModule(provider: StudioProvider, name: string, from?: string): string | undefined;
41
+ /** A provider as the code view shows it: the call that registers it, or why the studio writes none. */
42
+ export declare function providerSource(provider: StudioProvider): string;
43
+ export declare function studioSource(compiled: CompiledStudio): string;
44
+ /** A file of an exported workspace: its path from the folder it lands in, and its text. */
45
+ export interface SourceFile {
46
+ path: string;
47
+ code: string;
48
+ }
49
+ /** Where an agent's module lands, and how `theorem.ts` imports it. */
50
+ export declare function agentModulePath(agentId: string): string;
51
+ /** The import specifier for a module path: relative, without its extension. */
52
+ export declare function importSpecifier(path: string): string;
53
+ /** A camelCase identifier for an id, unique among `taken`; `kind` leads one that starts with a digit. */
54
+ export declare function agentIdentifier(agentId: string, taken: Set<string>, kind?: string): string;
55
+ /**
56
+ * An agent's module: its profile, and its structured reply and questions when it has them.
57
+ * Registers nothing. `from` is where the module imports the kernel from. With `checks` (the
58
+ * settings set in code, by profile id), each item rule is written with its check.
59
+ */
60
+ export declare function agentModule(compiled: CompiledStudio, from?: string, checks?: ProjectOrigins['profiles']): string;
61
+ /**
62
+ * One tool's module: a function that registers it, for the setup to call where the tool belongs
63
+ * in its order. `from` is where the module imports the kernel and `z` from.
64
+ */
65
+ export declare function toolModule(tool: ToolRegistration, register: string, from: {
66
+ agents: string;
67
+ zod: string;
68
+ }): string;
69
+ /**
70
+ * A workspace as source: `tools.ts` with the shared tools, one `agents/<id>.ts`
71
+ * per agent, and `theorem.ts`, which registers them all. Each agent is registered
72
+ * after the agents it names, and each agent tool after the agent it runs, so the
73
+ * order is the one a scope needs and reads in one place.
74
+ */
75
+ export declare function workspaceSource(compiled: CompiledWorkspace, project?: ProjectCode): SourceFile[];
package/source.js ADDED
@@ -0,0 +1,414 @@
1
+ /**
2
+ * One serializer writes the values, and each tool's schemas as the Zod expressions
3
+ * `zodFromJsonSchema` would build.
4
+ */
5
+ import { listsPatterns } from '@theoremjs/agents/guardrails';
6
+ import { withoutStudioFills } from "./policy.js";
7
+ import { definitionFactory, kernelDefinitions } from "./providers.js";
8
+ import { stubOutputFromSchema } from "./stub.js";
9
+ import { keySource, quoteSource } from "./tool-schema.js";
10
+ /** Source text written as-is into the module. */
11
+ class Expr {
12
+ code;
13
+ constructor(code) {
14
+ this.code = code;
15
+ }
16
+ }
17
+ /** Arrays of primitives shorter than this stay on one line. */
18
+ const INLINE_ARRAY_WIDTH = 60;
19
+ const STUDIO_STYLE = { unit: ' ', base: '', template: false };
20
+ /** `text` as a template literal, each line as it is. */
21
+ function templateSource(text) {
22
+ return `\`${text.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('${', '\\${')}\``;
23
+ }
24
+ /** A plain value as source, in `style`. */
25
+ export function valueSource(value, style) {
26
+ return literal(value, 0, style);
27
+ }
28
+ function literal(value, depth, style = STUDIO_STYLE) {
29
+ if (value instanceof Expr)
30
+ return value.code;
31
+ const pad = style.base + style.unit.repeat(depth + 1);
32
+ const close = style.base + style.unit.repeat(depth);
33
+ if (typeof value === 'string') {
34
+ if (!value.includes('\n'))
35
+ return (style.quote ?? quoteSource)(value);
36
+ if (style.template)
37
+ return templateSource(value);
38
+ // One line of the text on each line of the source.
39
+ const lines = value.split('\n').map((line) => `${pad}${quoteSource(line)},`);
40
+ return `[\n${lines.join('\n')}\n${close}].join('\\n')`;
41
+ }
42
+ if (Array.isArray(value)) {
43
+ if (!value.length)
44
+ return '[]';
45
+ const items = value.map((item) => literal(item, depth + 1, style));
46
+ const inline = `[${items.join(', ')}]`;
47
+ const primitive = value.every((item) => item === null || typeof item !== 'object');
48
+ if (primitive && inline.length <= INLINE_ARRAY_WIDTH)
49
+ return inline;
50
+ return `[\n${items.map((item) => `${pad}${item},`).join('\n')}\n${close}]`;
51
+ }
52
+ if (value !== null && typeof value === 'object') {
53
+ const entries = Object.entries(value).filter(([, item]) => item !== undefined);
54
+ if (!entries.length)
55
+ return '{}';
56
+ const lines = entries.map(([key, item]) => `${pad}${keySource(key, style.quote)}: ${literal(item, depth + 1, style)},`);
57
+ return `{\n${lines.join('\n')}\n${close}}`;
58
+ }
59
+ if (value === null || typeof value === 'boolean')
60
+ return String(value);
61
+ if (typeof value === 'number' && Number.isFinite(value))
62
+ return String(value);
63
+ throw new Error(`Studio source cannot write a ${typeof value} value.`);
64
+ }
65
+ /** The package an exported module imports the kernel from. */
66
+ export const AGENTS_PACKAGE = '@theoremjs/agents';
67
+ const COMPILE_IMPORT = `import { compileDetect } from '${AGENTS_PACKAGE}/guardrails/compile';`;
68
+ /**
69
+ * The profile's `defineProfile` call. A detector's own patterns need their compiled table, so
70
+ * `detect` is wrapped in `compileDetect`, which compiles them as the host starts; `compiles`
71
+ * says the module needs its import.
72
+ */
73
+ function profileSource(profile) {
74
+ const { guardrails } = profile;
75
+ const detect = guardrails && 'detect' in guardrails ? guardrails.detect : undefined;
76
+ if (typeof detect !== 'object' || !listsPatterns(detect)) {
77
+ return { code: `defineProfile(${literal(profile, 0)})`, compiles: false };
78
+ }
79
+ const compiled = new Expr(`compileDetect(${literal(detect, 2)})`);
80
+ const written = { ...profile, guardrails: { ...guardrails, detect: compiled } };
81
+ return { code: `defineProfile(${literal(written, 0)})`, compiles: true };
82
+ }
83
+ /**
84
+ * The profile with the check of each list's item rule as the project's files write it. A check is
85
+ * code, so the studio holds none: a rule the files do not place gets a line that says what is owed.
86
+ */
87
+ function withItemChecks(profile, checks) {
88
+ if (!('outputs' in profile))
89
+ return profile;
90
+ const validation = profile.outputs?.validation;
91
+ if (!validation?.items)
92
+ return profile;
93
+ const origins = checks[profile.id] ?? [];
94
+ const items = Object.fromEntries(Object.entries(validation.items).map(([list, rule]) => {
95
+ const path = ['outputs', 'validation', 'items', list, 'check'];
96
+ const at = origins.find((origin) => origin.kind === 'code' &&
97
+ origin.text !== undefined &&
98
+ origin.path.join('\n') === path.join('\n'));
99
+ const check = at?.text !== undefined
100
+ ? `${at.text} /* ${String(at.file)}:${String(at.line)} */`
101
+ : `undefined /* The check of each item of ${quoteSource(list)} is your own code: name it here. */`;
102
+ return [list, { check: new Expr(check), onFail: rule.onFail }];
103
+ }));
104
+ return { ...profile, outputs: { ...profile.outputs, validation: { ...validation, items } } };
105
+ }
106
+ /** A tool's registration, as a call; `indent` places it in a function body. */
107
+ function toolSource(tool, indent = 0) {
108
+ const call = (fields) => {
109
+ const pad = ' '.repeat(indent);
110
+ return `${pad}registerTool(${literal(fields, indent)});\n`;
111
+ };
112
+ const { inputSchema, outputSchema, ...fields } = tool;
113
+ // The kernel fixes an agent tool's schemas.
114
+ if (fields.type === 'agent')
115
+ return call(fields);
116
+ // The schema as it is, read by zod: hand-written zod would keep its shape and lose the rest.
117
+ const read = (schema) => new Expr(`z.fromJSONSchema(${literal(schema, indent + 1)})`);
118
+ const zod = { input: read(inputSchema), output: read(outputSchema) };
119
+ if (fields.type !== 'function')
120
+ return call({ ...fields, ...zod });
121
+ const { stubResponse, ...functionFields } = fields;
122
+ // The page answers the call, so the tool has no handler; the stub is the studio's stand-in.
123
+ if (functionFields.answeredBy === 'page')
124
+ return call({ ...functionFields, ...zod });
125
+ const stub = stubResponse ?? stubOutputFromSchema(outputSchema);
126
+ const handler = new Expr(`() => Promise.resolve(${literal(stub, indent + 1)})`);
127
+ return call({ ...functionFields, ...zod, handler });
128
+ }
129
+ /** The call that registers `provider` from the kernel definition `factory` names, at `indent`. */
130
+ function registrationCall(provider, factory, indent = 0) {
131
+ const pad = ' '.repeat(indent);
132
+ const held = Object.entries(provider.connection ?? {}).map(([key, value]) => `${keySource(key)}: ${quoteSource(value)}`);
133
+ const settings = [
134
+ `id: ${quoteSource(provider.id)}`,
135
+ ...(held.length ? [`connection: { ${held.join(', ')} }`] : []),
136
+ ...['keySlot', 'fallbackKeySlot'].flatMap((slot) => provider[slot] === undefined ? [] : [`${slot}: ${quoteSource(provider[slot])}`]),
137
+ ];
138
+ return `${pad}registerProvider(${factory}, {\n${settings.map((line) => `${pad} ${line},\n`).join('')}${pad}});\n`;
139
+ }
140
+ /**
141
+ * A provider's module: the function `name` that registers it, for the setup to call before every
142
+ * agent. `from` is where the module imports the kernel from. None for a definition that is the
143
+ * project's own.
144
+ */
145
+ export function providerModule(provider, name, from = AGENTS_PACKAGE) {
146
+ const factory = definitionFactory(provider.definition);
147
+ if (!factory)
148
+ return undefined;
149
+ return [
150
+ `import { ${factory}, registerProvider } from ${quoteSource(from)};\n`,
151
+ `/** Registers the provider \`${provider.id}\`. Call it before any agent whose models name it. */\nexport function ${name}(): void {\n${registrationCall(provider, factory, 1)}}\n`,
152
+ ].join('\n');
153
+ }
154
+ /** A provider as the code view shows it: the call that registers it, or why the studio writes none. */
155
+ export function providerSource(provider) {
156
+ const factory = definitionFactory(provider.definition);
157
+ return factory
158
+ ? registrationCall(provider, factory)
159
+ : `// The provider ${quoteSource(provider.id)} registers from your own definition ${quoteSource(provider.definition)}, so it stays in your code.\n`;
160
+ }
161
+ /**
162
+ * The registration of each provider a model of `profiles` names. One the project's files define
163
+ * (`places`) is imported under its own name, by its path from the project's folder, or named by
164
+ * its line when the files do not export it. One whose definition is the project's own is not the
165
+ * studio's to write: the code says so where its registration belongs.
166
+ */
167
+ function providerRegistrations(profiles, providers, places = []) {
168
+ const ids = new Set(profiles.flatMap((profile) => profile.type === 'host'
169
+ ? []
170
+ : Object.values(profile.models).map((binding) => binding.provider)));
171
+ const imports = new Set();
172
+ const own = new Map();
173
+ const code = [];
174
+ for (const id of ids) {
175
+ const place = places.find((held) => held.id === id);
176
+ if (place?.name !== undefined && place.exported) {
177
+ imports.add('registerProvider');
178
+ const from = importSpecifier(place.file);
179
+ own.set(from, [...(own.get(from) ?? []), place.name]);
180
+ code.push(`registerProvider(${place.name});\n`);
181
+ continue;
182
+ }
183
+ if (place) {
184
+ code.push(`// Register the provider ${quoteSource(id)} here, before the agents: ${place.file}:${String(place.line)} defines it and does not export it.\n`);
185
+ continue;
186
+ }
187
+ const provider = providers.find((held) => held.id === id);
188
+ const factory = provider && definitionFactory(provider.definition);
189
+ if (!provider || !factory) {
190
+ code.push(`// Register the provider ${quoteSource(id)} here, before the agents: its definition is the project's own.\n`);
191
+ continue;
192
+ }
193
+ imports.add('registerProvider');
194
+ imports.add(factory);
195
+ code.push(registrationCall(provider, factory));
196
+ }
197
+ return {
198
+ imports: [...imports],
199
+ own: [...own].map(([from, names]) => `import { ${names.join(', ')} } from ${quoteSource(from)};`),
200
+ code,
201
+ };
202
+ }
203
+ export function studioSource(compiled) {
204
+ const { profile, customTools, structured } = compiled;
205
+ const providers = providerRegistrations([profile], compiled.providers);
206
+ const imports = [
207
+ 'defineProfile',
208
+ 'registerProfile',
209
+ ...providers.imports,
210
+ ...(structured ? ['registerStructured'] : []),
211
+ ...(customTools.length ? ['registerTool'] : []),
212
+ ];
213
+ const defined = profileSource(profile);
214
+ const blocks = [
215
+ [
216
+ ...(customTools.length ? [`import { z } from 'zod';`] : []),
217
+ ...(defined.compiles ? [COMPILE_IMPORT] : []),
218
+ `import {\n${[
219
+ ...(compiled.images ? ['type DecisionAsset'] : []),
220
+ ...(compiled.questions ? ['type DecisionQuestion'] : []),
221
+ ...imports,
222
+ ]
223
+ .map((name) => ` ${name},`)
224
+ .join('\n')}\n} from '@theoremjs/agents';\n`,
225
+ ].join('\n'),
226
+ ...providers.code,
227
+ ...customTools.map((tool) => toolSource(tool)),
228
+ ...(structured
229
+ ? [`registerStructured(${quoteSource(structured.id)}, ${literal(structured.spec, 0)});\n`]
230
+ : []),
231
+ `const profile = ${defined.code};\n\nregisterProfile(profile);\n`,
232
+ ...(compiled.questions
233
+ ? [
234
+ `/** What every decision asks about the state, by id. */\nconst questions = ${literal(compiled.questions, 0)} satisfies Record<string, DecisionQuestion>;\n`,
235
+ ]
236
+ : []),
237
+ ...(compiled.images ? [imagesSource(compiled.images, 'const')] : []),
238
+ ];
239
+ return blocks.join('\n');
240
+ }
241
+ function imagesSource(images, declare) {
242
+ return `/** The pictures every decision sends, by the reference its questions write. */\n${declare} images = ${literal(images, 0)} satisfies Record<string, DecisionAsset>;\n`;
243
+ }
244
+ /** Where an agent's module lands, and how `theorem.ts` imports it. */
245
+ export function agentModulePath(agentId) {
246
+ return `agents/${agentId}.ts`;
247
+ }
248
+ /** The import specifier for a module path: relative, without its extension. */
249
+ export function importSpecifier(path) {
250
+ return `./${path.replace(/\.tsx?$/, '')}`;
251
+ }
252
+ /**
253
+ * What no identifier the studio writes may be: a word JavaScript keeps for itself, and a name the
254
+ * modules it writes import beside one, which the identifier would hide.
255
+ */
256
+ const UNNAMEABLE = new Set([
257
+ ...'arguments await break case catch class const continue debugger default delete do else enum eval export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof undefined var void while with yield'.split(' '),
258
+ ...'compileDetect DecisionQuestion defineProfile defineProvider registerProfile registerProvider registerProviders registerStructured registerTool registerToolLibrary z'.split(' '),
259
+ ...kernelDefinitions().flatMap((definition) => definitionFactory(definition) ?? []),
260
+ ]);
261
+ /** A camelCase identifier for an id, unique among `taken`; `kind` leads one that starts with a digit. */
262
+ export function agentIdentifier(agentId, taken, kind = 'agent') {
263
+ const words = agentId.split(/[^A-Za-z0-9]+/).filter(Boolean);
264
+ const joined = words
265
+ .map((word, index) => (index ? word[0].toUpperCase() + word.slice(1) : word.toLowerCase()))
266
+ .join('');
267
+ const base = /^[A-Za-z_$]/.test(joined) ? joined : `${kind}${joined}`;
268
+ let name = base;
269
+ for (let n = 2; taken.has(name) || UNNAMEABLE.has(name); n++)
270
+ name = `${base}${n}`;
271
+ taken.add(name);
272
+ return name;
273
+ }
274
+ /**
275
+ * An agent's module: its profile, and its structured reply and questions when it has them.
276
+ * Registers nothing. `from` is where the module imports the kernel from. With `checks` (the
277
+ * settings set in code, by profile id), each item rule is written with its check.
278
+ */
279
+ export function agentModule(compiled, from = AGENTS_PACKAGE, checks) {
280
+ const { profile, structured, questions, images } = compiled;
281
+ const imports = [
282
+ ...(images ? ['type DecisionAsset'] : []),
283
+ ...(questions ? ['type DecisionQuestion'] : []),
284
+ 'defineProfile',
285
+ ];
286
+ const defined = profileSource(withoutStudioFills(checks ? withItemChecks(profile, checks) : profile));
287
+ const blocks = [
288
+ `import { ${imports.join(', ')} } from ${quoteSource(from)};\n${defined.compiles ? `${COMPILE_IMPORT}\n` : ''}`,
289
+ ...(structured
290
+ ? [
291
+ `/** The reply's shape, registered before the profile. */\nexport const structured = ${literal(structured, 0)};\n`,
292
+ ]
293
+ : []),
294
+ `export const profile = ${defined.code};\n`,
295
+ ...(questions
296
+ ? [
297
+ `/** What every decision asks about the state, by id. */\nexport const questions = ${literal(questions, 0)} satisfies Record<string, DecisionQuestion>;\n`,
298
+ ]
299
+ : []),
300
+ ...(images ? [imagesSource(images, 'export const')] : []),
301
+ ];
302
+ return blocks.join('\n');
303
+ }
304
+ /**
305
+ * One tool's module: a function that registers it, for the setup to call where the tool belongs
306
+ * in its order. `from` is where the module imports the kernel and `z` from.
307
+ */
308
+ export function toolModule(tool, register, from) {
309
+ const zod = tool.type === 'agent' ? undefined : from.zod;
310
+ const imports = zod === from.agents
311
+ ? `import { registerTool, z } from ${quoteSource(from.agents)};\n`
312
+ : `${zod ? `import { z } from ${quoteSource(zod)};\n` : ''}import { registerTool } from ${quoteSource(from.agents)};\n`;
313
+ const order = tool.type === 'agent'
314
+ ? 'Call it after the agent it runs is registered, and before any agent that allows it.'
315
+ : 'Call it before any agent that allows it is registered.';
316
+ // A function tool made in the studio answers with its sample until its handler is written.
317
+ const stands = tool.type === 'function' && tool.answeredBy !== 'page';
318
+ const note = stands
319
+ ? `${order}\n * Its handler returns the studio's sample answer: write the real one here.`
320
+ : order;
321
+ return [
322
+ imports,
323
+ `/**${stands ? '\n *' : ''} Registers \`${tool.name}\`. ${note}${stands ? '\n' : ''} */\nexport function ${register}(): void {\n${toolSource(tool, 1)}}\n`,
324
+ ].join('\n');
325
+ }
326
+ /** The library's function, HTTP, and MCP tools, each once; agent tools wait for their agents. */
327
+ function libraryModule(tools) {
328
+ return [
329
+ `import { z } from 'zod';\nimport { registerTool } from '@theoremjs/agents';\n`,
330
+ `/** Registers the tools the agents share. \`theorem.ts\` calls it before any agent. */\nexport function registerToolLibrary(): void {\n${tools
331
+ .map((tool) => toolSource(tool, 1))
332
+ .join('\n')}}\n`,
333
+ ].join('\n');
334
+ }
335
+ /**
336
+ * A workspace as source: `tools.ts` with the shared tools, one `agents/<id>.ts`
337
+ * per agent, and `theorem.ts`, which registers them all. Each agent is registered
338
+ * after the agents it names, and each agent tool after the agent it runs, so the
339
+ * order is the one a scope needs and reads in one place.
340
+ */
341
+ export function workspaceSource(compiled, project) {
342
+ const library = new Map();
343
+ for (const tool of compiled.agents.flatMap((agent) => agent.customTools)) {
344
+ if (tool.type !== 'agent' && !library.has(tool.name))
345
+ library.set(tool.name, tool);
346
+ }
347
+ const taken = new Set([
348
+ 'registerProfile',
349
+ 'registerStructured',
350
+ 'registerTool',
351
+ 'registerToolLibrary',
352
+ ...(project?.providers ?? []).flatMap((place) => place.name === undefined ? [] : [place.name]),
353
+ ]);
354
+ const agents = compiled.agents.map((agent) => ({
355
+ agent,
356
+ path: agentModulePath(agent.agentId),
357
+ name: agentIdentifier(agent.agentId, taken),
358
+ }));
359
+ const structured = agents.some(({ agent }) => agent.structured);
360
+ const agentTools = agents.some(({ agent }) => agent.customTools.some((tool) => tool.type === 'agent'));
361
+ const registered = new Set();
362
+ const steps = agents.map(({ agent, name }) => {
363
+ const lines = [];
364
+ for (const tool of agent.customTools) {
365
+ if (tool.type !== 'agent' || registered.has(tool.name))
366
+ continue;
367
+ registered.add(tool.name);
368
+ lines.push(toolSource(tool));
369
+ }
370
+ if (agent.structured) {
371
+ lines.push(`registerStructured(${name}.structured.id, ${name}.structured.spec);\n`);
372
+ }
373
+ lines.push(`registerProfile(${name}.profile);\n`);
374
+ return lines.join('\n');
375
+ });
376
+ const providers = providerRegistrations(agents.map(({ agent }) => agent.profile), agents[0]?.agent.providers ?? [], project?.providers);
377
+ const theorem = [
378
+ [
379
+ '/**',
380
+ ' * Registers every agent and tool, server side. Import it once, before any',
381
+ ' * route that runs an agent. Each agent comes after the agents it names, and',
382
+ ' * each agent tool after the agent it runs.',
383
+ ' */',
384
+ `import {\n${[
385
+ 'registerProfile',
386
+ ...providers.imports,
387
+ ...(structured ? ['registerStructured'] : []),
388
+ ...(agentTools ? ['registerTool'] : []),
389
+ ]
390
+ .map((each) => ` ${each},`)
391
+ .join('\n')}\n} from '@theoremjs/agents';`,
392
+ ...(library.size ? [`import { registerToolLibrary } from './tools';`] : []),
393
+ ...agents.map(({ path, name }) => `import * as ${name} from '${importSpecifier(path)}';`),
394
+ ...(providers.own.length
395
+ ? [
396
+ "// The project's own providers, each by its path from the project's folder.",
397
+ ...providers.own,
398
+ ]
399
+ : []),
400
+ '',
401
+ ].join('\n'),
402
+ ...providers.code,
403
+ ...(library.size ? ['registerToolLibrary();\n'] : []),
404
+ ...steps,
405
+ ];
406
+ return [
407
+ ...(library.size ? [{ path: 'tools.ts', code: libraryModule([...library.values()]) }] : []),
408
+ ...agents.map(({ agent, path }) => ({
409
+ path,
410
+ code: agentModule(agent, AGENTS_PACKAGE, project?.origins ?? {}),
411
+ })),
412
+ { path: 'theorem.ts', code: theorem.join('\n') },
413
+ ];
414
+ }
package/start.mjs ADDED
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { existsSync, realpathSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ /**
7
+ * Opens the studio on a project, with one command:
8
+ *
9
+ * theorem-studio [setup] [--editor <command>] [--deno-config <file>] [--no-watch]
10
+ *
11
+ * That is the installed package's command (`npx theorem-studio`); in the repo it is
12
+ * `node studio/start.mjs`.
13
+ *
14
+ * `setup` is a setup's file or its name. A setup is a file named `studio.setup.ts`, named for its
15
+ * folder, or `<name>.studio.setup.ts`. With no `setup` the project's one setup opens, and when the
16
+ * project has several the command asks which. A project gives this a short name of its own:
17
+ * `"studio": "theorem-studio"` in its scripts makes it `npm run studio`.
18
+ *
19
+ * It starts the project's local server (`server/serve.ts`, under Deno, with the project's own
20
+ * permissions) and the studio's page, and stops both together. Only this machine reaches either.
21
+ * `--editor` names the editor the studio opens a line of the project's files in; without it the
22
+ * studio uses `$VISUAL` or `$EDITOR` when that opens a window, and `code` otherwise. When that one
23
+ * does not start, the machine's default editor opens the file.
24
+ * The studio watches the files the setup reads and takes in what the builder's editor changes;
25
+ * `--no-watch` turns that off, and the studio then reads them when the builder comes back to it.
26
+ * The project loads with its own Deno config: the one `--deno-config` names, else the `deno.json`
27
+ * or `deno.jsonc` in the folder the command ran in, else the studio's.
28
+ * A project already open in a studio is not opened twice: the command says where it is. A second
29
+ * project opens beside the first, on the next free pair of ports.
30
+ * The studio is opt-in, so this checks for its install and never installs it.
31
+ */
32
+ import { builtPage } from './installed.mjs';
33
+ import { heldPairs, pageAddress, placeFor, serverAddress } from './ports.mjs';
34
+ import { chooseSetup, findSetups, setupLines, setupsNamed } from './setups.mjs';
35
+
36
+ const here = path.dirname(fileURLToPath(import.meta.url));
37
+
38
+ const USAGE = `usage: ${builtPage ? 'theorem-studio' : 'node studio/start.mjs'} [setup] [--editor <command>] [--deno-config <file>] [--no-watch]`;
39
+ /** The value after each flag that takes one. A flag with none, a second setup, or anything else, is a mistake. */
40
+ const VALUED = ['--editor', '--deno-config'];
41
+ const given = {};
42
+ let wanted;
43
+ let noWatch = false;
44
+ let mistaken = false;
45
+ const args = process.argv.slice(2);
46
+ for (let at = 0; at < args.length; at += 1) {
47
+ const arg = args[at];
48
+ if (arg === '--no-watch') noWatch = true;
49
+ else if (VALUED.includes(arg)) {
50
+ const value = args[at + 1];
51
+ if (!value || value.startsWith('--')) mistaken = true;
52
+ else given[arg] = value;
53
+ at += 1;
54
+ } else if (arg.startsWith('--') || wanted !== undefined) mistaken = true;
55
+ else wanted = arg;
56
+ }
57
+ if (mistaken) {
58
+ console.error(USAGE);
59
+ process.exit(2);
60
+ }
61
+ const editor = given['--editor'];
62
+
63
+ // The setup module is named from where the command was run, which is also the project's name.
64
+ const from = process.env.INIT_CWD ?? process.cwd();
65
+ const setup = await setupToOpen();
66
+
67
+ /** Says why no setup opens, and stops. */
68
+ function refuse(message) {
69
+ console.error(`${message}\n\n${USAGE}`);
70
+ process.exit(2);
71
+ }
72
+
73
+ /** The setup this run opens: the file named, else the one found, else the one the builder picks. */
74
+ async function setupToOpen() {
75
+ if (wanted !== undefined && existsSync(path.resolve(from, wanted))) return wanted;
76
+ const found = findSetups(from);
77
+ const setups = wanted === undefined ? found : setupsNamed(found, wanted);
78
+ if (setups.length === 1) return setups[0].file;
79
+ const why = whyNoSetup(found, setups);
80
+ if (why) refuse(why);
81
+ const chosen = await chooseSetup(setups, process.stdin, process.stdout);
82
+ if (!chosen) process.exit(130);
83
+ return chosen.file;
84
+ }
85
+
86
+ /** Why the builder cannot be asked which setup to open, when that is so. */
87
+ function whyNoSetup(found, setups) {
88
+ if (found.length === 0) {
89
+ return `No setup in ${from}. A setup is a file named studio.setup.ts, or <name>.studio.setup.ts.`;
90
+ }
91
+ if (setups.length === 0) {
92
+ return `No setup is named ${wanted}. This project has:\n\n${setupLines(found).join('\n')}`;
93
+ }
94
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
95
+ return `This project has more than one setup. Name the one to open:\n\n${setupLines(setups).join('\n')}`;
96
+ }
97
+ return undefined;
98
+ }
99
+ const place = placeFor(realpathSync(path.resolve(from, setup)), await heldPairs());
100
+ if (!place) refuse('Too many studios are open on this machine. Stop one, then run this again.');
101
+ const PAGE = pageAddress(place.pair);
102
+ if (place.running) {
103
+ console.log(`theorem studio: already open on ${setup}: ${PAGE}/studio/`);
104
+ process.exit(0);
105
+ }
106
+ if (setup !== wanted) console.log(`theorem studio: opening ${setup}`);
107
+ const ownConfig = ['deno.json', 'deno.jsonc'].map((name) => path.join(from, name)).find(existsSync);
108
+ const projectConfig = given['--deno-config']
109
+ ? path.resolve(from, given['--deno-config'])
110
+ : (ownConfig ?? path.join(here, 'deno.json'));
111
+ const server = spawn(
112
+ 'deno',
113
+ [
114
+ 'run',
115
+ '--config',
116
+ path.join(here, 'deno.json'),
117
+ '-A',
118
+ path.join(here, builtPage ? 'server/serve.js' : 'server/serve.ts'),
119
+ path.resolve(from, setup),
120
+ '--port',
121
+ String(place.pair.server),
122
+ '--page',
123
+ `${PAGE},http://localhost:${String(place.pair.page)}`,
124
+ '--deno-config',
125
+ projectConfig,
126
+ ...(editor ? ['--editor', editor] : []),
127
+ ...(noWatch ? ['--no-watch'] : []),
128
+ ],
129
+ { cwd: from, stdio: ['ignore', 'ignore', 'inherit'] },
130
+ );
131
+ const project = `${serverAddress(place.pair)}/api/studio`;
132
+ // An installed studio serves the page it was built with; the repo's is Vite on the sources.
133
+ const page = builtPage
134
+ ? spawn(
135
+ process.execPath,
136
+ [path.join(here, 'serve-page.mjs'), '--port', String(place.pair.page), '--project', project],
137
+ { stdio: ['ignore', 'ignore', 'inherit'] },
138
+ )
139
+ : spawn(
140
+ process.execPath,
141
+ [
142
+ path.join(here, 'node_modules/vite/bin/vite.js'),
143
+ '--config',
144
+ path.join(here, 'app/vite.config.ts'),
145
+ '--port',
146
+ String(place.pair.page),
147
+ ],
148
+ {
149
+ cwd: here,
150
+ stdio: ['ignore', 'ignore', 'inherit'],
151
+ env: { ...process.env, THEOREM_STUDIO_PROJECT: project },
152
+ },
153
+ );
154
+
155
+ console.log(`theorem studio: ${PAGE}/studio/`);
156
+
157
+ let stopping = false;
158
+ /** Stops both when either ends or the command is interrupted. */
159
+ function stop(code) {
160
+ if (stopping) return;
161
+ stopping = true;
162
+ server.kill();
163
+ page.kill();
164
+ process.exitCode = code;
165
+ }
166
+ server.on('exit', (code) => stop(code ?? 1));
167
+ page.on('exit', (code) => stop(code ?? 1));
168
+ process.on('SIGINT', () => stop(0));
169
+ process.on('SIGTERM', () => stop(0));
@@ -0,0 +1,9 @@
1
+ /** Hands a line on to whoever reads the stream. */
2
+ export type SendLine = (line: string) => void;
3
+ /**
4
+ * A newline-delimited stream read a line at a time: `each` sees every line and sends on the ones
5
+ * it keeps, and `end` runs after the last.
6
+ */
7
+ export declare function eachLine(each: (line: string, send: SendLine) => void, end?: (send: SendLine) => void): TransformStream<Uint8Array, Uint8Array>;
8
+ /** The content type of a run's stream. */
9
+ export declare const NDJSON = "application/x-ndjson";