@ibgib/web-gib 0.0.1

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 (372) hide show
  1. package/.ibgibignore +30 -0
  2. package/.vscode/ibgib-snippets.code-snippets +309 -0
  3. package/.vscode/launch.json +25 -0
  4. package/.vscode/settings.json +68 -0
  5. package/.vscode/tasks.json +38 -0
  6. package/CHANGELOG.md +427 -0
  7. package/README.md +66 -0
  8. package/dist/agent-texts/common-agent-texts.d.mts +14 -0
  9. package/dist/agent-texts/common-agent-texts.d.mts.map +1 -0
  10. package/dist/agent-texts/common-agent-texts.mjs +51 -0
  11. package/dist/agent-texts/common-agent-texts.mjs.map +1 -0
  12. package/dist/agent-texts/primary-agent-texts.d.mts +16 -0
  13. package/dist/agent-texts/primary-agent-texts.d.mts.map +1 -0
  14. package/dist/agent-texts/primary-agent-texts.mjs +27 -0
  15. package/dist/agent-texts/primary-agent-texts.mjs.map +1 -0
  16. package/dist/agent-texts/project-agent-texts.d.mts +8 -0
  17. package/dist/agent-texts/project-agent-texts.d.mts.map +1 -0
  18. package/dist/agent-texts/project-agent-texts.mjs +29 -0
  19. package/dist/agent-texts/project-agent-texts.mjs.map +1 -0
  20. package/dist/agent-texts/project-child-text-agent-texts.d.mts +5 -0
  21. package/dist/agent-texts/project-child-text-agent-texts.d.mts.map +1 -0
  22. package/dist/agent-texts/project-child-text-agent-texts.mjs +26 -0
  23. package/dist/agent-texts/project-child-text-agent-texts.mjs.map +1 -0
  24. package/dist/agent-texts/projects-agent-texts.d.mts +4 -0
  25. package/dist/agent-texts/projects-agent-texts.d.mts.map +1 -0
  26. package/dist/agent-texts/projects-agent-texts.mjs +15 -0
  27. package/dist/agent-texts/projects-agent-texts.mjs.map +1 -0
  28. package/dist/agent-texts/raw-agent-texts.d.mts +4 -0
  29. package/dist/agent-texts/raw-agent-texts.d.mts.map +1 -0
  30. package/dist/agent-texts/raw-agent-texts.mjs +17 -0
  31. package/dist/agent-texts/raw-agent-texts.mjs.map +1 -0
  32. package/dist/agent-texts/text-editor-agent-texts.d.mts +6 -0
  33. package/dist/agent-texts/text-editor-agent-texts.d.mts.map +1 -0
  34. package/dist/agent-texts/text-editor-agent-texts.mjs +19 -0
  35. package/dist/agent-texts/text-editor-agent-texts.mjs.map +1 -0
  36. package/dist/api/api-constants.d.mts +9 -0
  37. package/dist/api/api-constants.d.mts.map +1 -0
  38. package/dist/api/api-constants.mjs +9 -0
  39. package/dist/api/api-constants.mjs.map +1 -0
  40. package/dist/api/api-index.d.mts +10 -0
  41. package/dist/api/api-index.d.mts.map +1 -0
  42. package/dist/api/api-index.mjs +121 -0
  43. package/dist/api/api-index.mjs.map +1 -0
  44. package/dist/api/api-types.d.mts +36 -0
  45. package/dist/api/api-types.d.mts.map +1 -0
  46. package/dist/api/api-types.mjs +2 -0
  47. package/dist/api/api-types.mjs.map +1 -0
  48. package/dist/api/commands/chat/chat-index.d.mts +3 -0
  49. package/dist/api/commands/chat/chat-index.d.mts.map +1 -0
  50. package/dist/api/commands/chat/chat-index.mjs +9 -0
  51. package/dist/api/commands/chat/chat-index.mjs.map +1 -0
  52. package/dist/api/commands/chat/get-context-info.d.mts +71 -0
  53. package/dist/api/commands/chat/get-context-info.d.mts.map +1 -0
  54. package/dist/api/commands/chat/get-context-info.mjs +130 -0
  55. package/dist/api/commands/chat/get-context-info.mjs.map +1 -0
  56. package/dist/api/commands/chat/hello-world.d.mts +63 -0
  57. package/dist/api/commands/chat/hello-world.d.mts.map +1 -0
  58. package/dist/api/commands/chat/hello-world.mjs +132 -0
  59. package/dist/api/commands/chat/hello-world.mjs.map +1 -0
  60. package/dist/api/commands/chat/tell-user.d.mts +57 -0
  61. package/dist/api/commands/chat/tell-user.d.mts.map +1 -0
  62. package/dist/api/commands/chat/tell-user.mjs +199 -0
  63. package/dist/api/commands/chat/tell-user.mjs.map +1 -0
  64. package/dist/api/commands/command-constants.d.mts +22 -0
  65. package/dist/api/commands/command-constants.d.mts.map +1 -0
  66. package/dist/api/commands/command-constants.mjs +17 -0
  67. package/dist/api/commands/command-constants.mjs.map +1 -0
  68. package/dist/api/commands/command-helpers.d.mts +47 -0
  69. package/dist/api/commands/command-helpers.d.mts.map +1 -0
  70. package/dist/api/commands/command-helpers.mjs +76 -0
  71. package/dist/api/commands/command-helpers.mjs.map +1 -0
  72. package/dist/api/commands/command-service-v1.d.mts +28 -0
  73. package/dist/api/commands/command-service-v1.d.mts.map +1 -0
  74. package/dist/api/commands/command-service-v1.mjs +122 -0
  75. package/dist/api/commands/command-service-v1.mjs.map +1 -0
  76. package/dist/api/commands/command-service.respec.d.mts +7 -0
  77. package/dist/api/commands/command-service.respec.d.mts.map +1 -0
  78. package/dist/api/commands/command-service.respec.mjs +66 -0
  79. package/dist/api/commands/command-service.respec.mjs.map +1 -0
  80. package/dist/api/commands/command-types.d.mts +48 -0
  81. package/dist/api/commands/command-types.d.mts.map +1 -0
  82. package/dist/api/commands/command-types.mjs +12 -0
  83. package/dist/api/commands/command-types.mjs.map +1 -0
  84. package/dist/api/commands/ibgib/get-ibgibs.d.mts +94 -0
  85. package/dist/api/commands/ibgib/get-ibgibs.d.mts.map +1 -0
  86. package/dist/api/commands/ibgib/get-ibgibs.mjs +219 -0
  87. package/dist/api/commands/ibgib/get-ibgibs.mjs.map +1 -0
  88. package/dist/api/commands/ibgib/ibgib-index.d.mts +3 -0
  89. package/dist/api/commands/ibgib/ibgib-index.d.mts.map +1 -0
  90. package/dist/api/commands/ibgib/ibgib-index.mjs +7 -0
  91. package/dist/api/commands/ibgib/ibgib-index.mjs.map +1 -0
  92. package/dist/api/commands/ibgib/mut8-ibgib.d.mts +135 -0
  93. package/dist/api/commands/ibgib/mut8-ibgib.d.mts.map +1 -0
  94. package/dist/api/commands/ibgib/mut8-ibgib.mjs +318 -0
  95. package/dist/api/commands/ibgib/mut8-ibgib.mjs.map +1 -0
  96. package/dist/api/commands/templates/api-function-info.template.d.mts +73 -0
  97. package/dist/api/commands/templates/api-function-info.template.d.mts.map +1 -0
  98. package/dist/api/commands/templates/api-function-info.template.mjs +161 -0
  99. package/dist/api/commands/templates/api-function-info.template.mjs.map +1 -0
  100. package/dist/api/commands/text/text-edit.d.mts +54 -0
  101. package/dist/api/commands/text/text-edit.d.mts.map +1 -0
  102. package/dist/api/commands/text/text-edit.mjs +170 -0
  103. package/dist/api/commands/text/text-edit.mjs.map +1 -0
  104. package/dist/api/commands/text/text-index.d.mts +3 -0
  105. package/dist/api/commands/text/text-index.d.mts.map +1 -0
  106. package/dist/api/commands/text/text-index.mjs +5 -0
  107. package/dist/api/commands/text/text-index.mjs.map +1 -0
  108. package/dist/api/commands/ui/ui-index.d.mts +3 -0
  109. package/dist/api/commands/ui/ui-index.d.mts.map +1 -0
  110. package/dist/api/commands/ui/ui-index.mjs +5 -0
  111. package/dist/api/commands/ui/ui-index.mjs.map +1 -0
  112. package/dist/api/commands/ui/update-css-variables.d.mts +48 -0
  113. package/dist/api/commands/ui/update-css-variables.d.mts.map +1 -0
  114. package/dist/api/commands/ui/update-css-variables.mjs +145 -0
  115. package/dist/api/commands/ui/update-css-variables.mjs.map +1 -0
  116. package/dist/api/function-infos.web.d.mts +15 -0
  117. package/dist/api/function-infos.web.d.mts.map +1 -0
  118. package/dist/api/function-infos.web.mjs +63 -0
  119. package/dist/api/function-infos.web.mjs.map +1 -0
  120. package/dist/assumptions.respec.d.mts +2 -0
  121. package/dist/assumptions.respec.d.mts.map +1 -0
  122. package/dist/assumptions.respec.mjs +41 -0
  123. package/dist/assumptions.respec.mjs.map +1 -0
  124. package/dist/common/project/project-constants.d.mts +38 -0
  125. package/dist/common/project/project-constants.d.mts.map +1 -0
  126. package/dist/common/project/project-constants.mjs +71 -0
  127. package/dist/common/project/project-constants.mjs.map +1 -0
  128. package/dist/common/project/project-helper.d.mts +127 -0
  129. package/dist/common/project/project-helper.d.mts.map +1 -0
  130. package/dist/common/project/project-helper.mjs +683 -0
  131. package/dist/common/project/project-helper.mjs.map +1 -0
  132. package/dist/common/project/project-types.d.mts +91 -0
  133. package/dist/common/project/project-types.d.mts.map +1 -0
  134. package/dist/common/project/project-types.mjs +31 -0
  135. package/dist/common/project/project-types.mjs.map +1 -0
  136. package/dist/common/prompt-functions.web.d.mts +90 -0
  137. package/dist/common/prompt-functions.web.d.mts.map +1 -0
  138. package/dist/common/prompt-functions.web.mjs +426 -0
  139. package/dist/common/prompt-functions.web.mjs.map +1 -0
  140. package/dist/common/settings/settings-constants.d.mts +33 -0
  141. package/dist/common/settings/settings-constants.d.mts.map +1 -0
  142. package/dist/common/settings/settings-constants.mjs +54 -0
  143. package/dist/common/settings/settings-constants.mjs.map +1 -0
  144. package/dist/common/settings/settings-helpers.d.mts +59 -0
  145. package/dist/common/settings/settings-helpers.d.mts.map +1 -0
  146. package/dist/common/settings/settings-helpers.mjs +253 -0
  147. package/dist/common/settings/settings-helpers.mjs.map +1 -0
  148. package/dist/common/settings/settings-types.d.mts +118 -0
  149. package/dist/common/settings/settings-types.d.mts.map +1 -0
  150. package/dist/common/settings/settings-types.mjs +13 -0
  151. package/dist/common/settings/settings-types.mjs.map +1 -0
  152. package/dist/constants.d.mts +34 -0
  153. package/dist/constants.d.mts.map +1 -0
  154. package/dist/constants.mjs +35 -0
  155. package/dist/constants.mjs.map +1 -0
  156. package/dist/foo.d.mts +2 -0
  157. package/dist/foo.d.mts.map +1 -0
  158. package/dist/foo.mjs +19 -0
  159. package/dist/foo.mjs.map +1 -0
  160. package/dist/helpers.d.mts +137 -0
  161. package/dist/helpers.d.mts.map +1 -0
  162. package/dist/helpers.mjs +514 -0
  163. package/dist/helpers.mjs.map +1 -0
  164. package/dist/helpers.web.d.mts +324 -0
  165. package/dist/helpers.web.d.mts.map +1 -0
  166. package/dist/helpers.web.mjs +1133 -0
  167. package/dist/helpers.web.mjs.map +1 -0
  168. package/dist/helpers.web.respec.d.mts +2 -0
  169. package/dist/helpers.web.respec.d.mts.map +1 -0
  170. package/dist/helpers.web.respec.mjs +12 -0
  171. package/dist/helpers.web.respec.mjs.map +1 -0
  172. package/dist/index.d.mts +2 -0
  173. package/dist/index.d.mts.map +1 -0
  174. package/dist/index.mjs +3 -0
  175. package/dist/index.mjs.map +1 -0
  176. package/dist/respec-gib.node.d.mts +2 -0
  177. package/dist/respec-gib.node.d.mts.map +1 -0
  178. package/dist/respec-gib.node.mjs +211 -0
  179. package/dist/respec-gib.node.mjs.map +1 -0
  180. package/dist/spec-helper.node.respec.d.mts +13 -0
  181. package/dist/spec-helper.node.respec.d.mts.map +1 -0
  182. package/dist/spec-helper.node.respec.mjs +50 -0
  183. package/dist/spec-helper.node.respec.mjs.map +1 -0
  184. package/dist/storage/storage-helpers.web.d.mts +108 -0
  185. package/dist/storage/storage-helpers.web.d.mts.map +1 -0
  186. package/dist/storage/storage-helpers.web.mjs +757 -0
  187. package/dist/storage/storage-helpers.web.mjs.map +1 -0
  188. package/dist/storage/storage-types.web.d.mts +30 -0
  189. package/dist/storage/storage-types.web.d.mts.map +1 -0
  190. package/dist/storage/storage-types.web.mjs +2 -0
  191. package/dist/storage/storage-types.web.mjs.map +1 -0
  192. package/dist/types.web.d.mts +42 -0
  193. package/dist/types.web.d.mts.map +1 -0
  194. package/dist/types.web.mjs +2 -0
  195. package/dist/types.web.mjs.map +1 -0
  196. package/dist/ui/component/component-types.d.mts +225 -0
  197. package/dist/ui/component/component-types.d.mts.map +1 -0
  198. package/dist/ui/component/component-types.mjs +2 -0
  199. package/dist/ui/component/component-types.mjs.map +1 -0
  200. package/dist/ui/component/ibgib-component-service.d.mts +70 -0
  201. package/dist/ui/component/ibgib-component-service.d.mts.map +1 -0
  202. package/dist/ui/component/ibgib-component-service.mjs +201 -0
  203. package/dist/ui/component/ibgib-component-service.mjs.map +1 -0
  204. package/dist/ui/component/ibgib-dynamic-component-bases.d.mts +338 -0
  205. package/dist/ui/component/ibgib-dynamic-component-bases.d.mts.map +1 -0
  206. package/dist/ui/component/ibgib-dynamic-component-bases.mjs +1304 -0
  207. package/dist/ui/component/ibgib-dynamic-component-bases.mjs.map +1 -0
  208. package/dist/ui/ui-constants.d.mts +12 -0
  209. package/dist/ui/ui-constants.d.mts.map +1 -0
  210. package/dist/ui/ui-constants.mjs +93 -0
  211. package/dist/ui/ui-constants.mjs.map +1 -0
  212. package/dist/ui/ui-helpers.d.mts +42 -0
  213. package/dist/ui/ui-helpers.d.mts.map +1 -0
  214. package/dist/ui/ui-helpers.mjs +198 -0
  215. package/dist/ui/ui-helpers.mjs.map +1 -0
  216. package/dist/ui/ui-types.d.mts +13 -0
  217. package/dist/ui/ui-types.d.mts.map +1 -0
  218. package/dist/ui/ui-types.mjs +2 -0
  219. package/dist/ui/ui-types.mjs.map +1 -0
  220. package/dist/witness/agent/agent-constants.d.mts +97 -0
  221. package/dist/witness/agent/agent-constants.d.mts.map +1 -0
  222. package/dist/witness/agent/agent-constants.mjs +98 -0
  223. package/dist/witness/agent/agent-constants.mjs.map +1 -0
  224. package/dist/witness/agent/agent-helpers.d.mts +106 -0
  225. package/dist/witness/agent/agent-helpers.d.mts.map +1 -0
  226. package/dist/witness/agent/agent-helpers.mjs +601 -0
  227. package/dist/witness/agent/agent-helpers.mjs.map +1 -0
  228. package/dist/witness/agent/agent-one-file.app.d.mts +2 -0
  229. package/dist/witness/agent/agent-one-file.app.d.mts.map +1 -0
  230. package/dist/witness/agent/agent-one-file.app.mjs +8 -0
  231. package/dist/witness/agent/agent-one-file.app.mjs.map +1 -0
  232. package/dist/witness/agent/agent-one-file.d.mts +478 -0
  233. package/dist/witness/agent/agent-one-file.d.mts.map +1 -0
  234. package/dist/witness/agent/agent-one-file.mjs +1462 -0
  235. package/dist/witness/agent/agent-one-file.mjs.map +1 -0
  236. package/dist/witness/agent/agent-types.d.mts +83 -0
  237. package/dist/witness/agent/agent-types.d.mts.map +1 -0
  238. package/dist/witness/agent/agent-types.mjs +2 -0
  239. package/dist/witness/agent/agent-types.mjs.map +1 -0
  240. package/dist/witness/agent/agents-service-v1.d.mts +99 -0
  241. package/dist/witness/agent/agents-service-v1.d.mts.map +1 -0
  242. package/dist/witness/agent/agents-service-v1.mjs +453 -0
  243. package/dist/witness/agent/agents-service-v1.mjs.map +1 -0
  244. package/dist/witness/agent/function-info/function-info-one-file.d.mts +192 -0
  245. package/dist/witness/agent/function-info/function-info-one-file.d.mts.map +1 -0
  246. package/dist/witness/agent/function-info/function-info-one-file.mjs +192 -0
  247. package/dist/witness/agent/function-info/function-info-one-file.mjs.map +1 -0
  248. package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts +51 -0
  249. package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts.map +1 -0
  250. package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs +928 -0
  251. package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs.map +1 -0
  252. package/dist/witness/agent/gemini/gemini-agent-factory.d.mts +27 -0
  253. package/dist/witness/agent/gemini/gemini-agent-factory.d.mts.map +1 -0
  254. package/dist/witness/agent/gemini/gemini-agent-factory.mjs +144 -0
  255. package/dist/witness/agent/gemini/gemini-agent-factory.mjs.map +1 -0
  256. package/dist/witness/agent/gemini/gemini-constants.d.mts +36 -0
  257. package/dist/witness/agent/gemini/gemini-constants.d.mts.map +1 -0
  258. package/dist/witness/agent/gemini/gemini-constants.mjs +47 -0
  259. package/dist/witness/agent/gemini/gemini-constants.mjs.map +1 -0
  260. package/dist/witness/agent/gemini/gemini-helpers.d.mts +58 -0
  261. package/dist/witness/agent/gemini/gemini-helpers.d.mts.map +1 -0
  262. package/dist/witness/agent/gemini/gemini-helpers.mjs +210 -0
  263. package/dist/witness/agent/gemini/gemini-helpers.mjs.map +1 -0
  264. package/dist/witness/agent/gemini/gemini-types.d.mts +82 -0
  265. package/dist/witness/agent/gemini/gemini-types.d.mts.map +1 -0
  266. package/dist/witness/agent/gemini/gemini-types.mjs +3 -0
  267. package/dist/witness/agent/gemini/gemini-types.mjs.map +1 -0
  268. package/dist/witness/live-proxy-ibgib/live-proxy-ibgib-one-file.d.mts +136 -0
  269. package/dist/witness/live-proxy-ibgib/live-proxy-ibgib-one-file.d.mts.map +1 -0
  270. package/dist/witness/live-proxy-ibgib/live-proxy-ibgib-one-file.mjs +334 -0
  271. package/dist/witness/live-proxy-ibgib/live-proxy-ibgib-one-file.mjs.map +1 -0
  272. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace-helper.d.mts +35 -0
  273. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace-helper.d.mts.map +1 -0
  274. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace-helper.mjs +267 -0
  275. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace-helper.mjs.map +1 -0
  276. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace.d.mts +134 -0
  277. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace.d.mts.map +1 -0
  278. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace.mjs +389 -0
  279. package/dist/witness/space/metaspace/metaspace-webspace/metaspace-webspace.mjs.map +1 -0
  280. package/dist/witness/space/web-filesystem-space/web-filesystem-space-constants.d.mts +2 -0
  281. package/dist/witness/space/web-filesystem-space/web-filesystem-space-constants.d.mts.map +1 -0
  282. package/dist/witness/space/web-filesystem-space/web-filesystem-space-constants.mjs +2 -0
  283. package/dist/witness/space/web-filesystem-space/web-filesystem-space-constants.mjs.map +1 -0
  284. package/dist/witness/space/web-filesystem-space/web-filesystem-space-helper.d.mts +104 -0
  285. package/dist/witness/space/web-filesystem-space/web-filesystem-space-helper.d.mts.map +1 -0
  286. package/dist/witness/space/web-filesystem-space/web-filesystem-space-helper.mjs +457 -0
  287. package/dist/witness/space/web-filesystem-space/web-filesystem-space-helper.mjs.map +1 -0
  288. package/dist/witness/space/web-filesystem-space/web-filesystem-space-types.d.mts +93 -0
  289. package/dist/witness/space/web-filesystem-space/web-filesystem-space-types.d.mts.map +1 -0
  290. package/dist/witness/space/web-filesystem-space/web-filesystem-space-types.mjs +98 -0
  291. package/dist/witness/space/web-filesystem-space/web-filesystem-space-types.mjs.map +1 -0
  292. package/dist/witness/space/web-filesystem-space/web-filesystem-space-v1.d.mts +73 -0
  293. package/dist/witness/space/web-filesystem-space/web-filesystem-space-v1.d.mts.map +1 -0
  294. package/dist/witness/space/web-filesystem-space/web-filesystem-space-v1.mjs +650 -0
  295. package/dist/witness/space/web-filesystem-space/web-filesystem-space-v1.mjs.map +1 -0
  296. package/generate-version-file.js +29 -0
  297. package/package.json +60 -0
  298. package/src/agent-texts/common-agent-texts.mts +61 -0
  299. package/src/agent-texts/primary-agent-texts.mts +32 -0
  300. package/src/agent-texts/project-agent-texts.mts +29 -0
  301. package/src/agent-texts/project-child-text-agent-texts.mts +30 -0
  302. package/src/agent-texts/projects-agent-texts.mts +17 -0
  303. package/src/agent-texts/raw-agent-texts.mts +18 -0
  304. package/src/agent-texts/text-editor-agent-texts.mts +20 -0
  305. package/src/api/api-constants.mts +8 -0
  306. package/src/api/api-index.mts +110 -0
  307. package/src/api/api-types.mts +36 -0
  308. package/src/api/commands/chat/chat-index.mts +10 -0
  309. package/src/api/commands/chat/get-context-info.mts +196 -0
  310. package/src/api/commands/chat/hello-world.mts +183 -0
  311. package/src/api/commands/chat/tell-user.mts +241 -0
  312. package/src/api/commands/command-constants.mts +17 -0
  313. package/src/api/commands/command-helpers.mts +105 -0
  314. package/src/api/commands/command-service-v1.mts +136 -0
  315. package/src/api/commands/command-service.respec.mts +72 -0
  316. package/src/api/commands/command-types.mts +71 -0
  317. package/src/api/commands/ibgib/get-ibgibs.mts +269 -0
  318. package/src/api/commands/ibgib/ibgib-index.mts +8 -0
  319. package/src/api/commands/ibgib/mut8-ibgib.mts +418 -0
  320. package/src/api/commands/templates/api-function-info.template.mts +212 -0
  321. package/src/api/commands/text/text-edit.mts +217 -0
  322. package/src/api/commands/text/text-index.mts +6 -0
  323. package/src/api/commands/ui/ui-index.mts +6 -0
  324. package/src/api/commands/ui/update-css-variables.mts +187 -0
  325. package/src/api/function-infos.web.mts +66 -0
  326. package/src/assets/fullscreen-dialog.html +18 -0
  327. package/src/assumptions.respec.mts +51 -0
  328. package/src/common/project/project-constants.mts +83 -0
  329. package/src/common/project/project-helper.mts +730 -0
  330. package/src/common/project/project-types.mts +121 -0
  331. package/src/common/prompt-functions.web.mts +447 -0
  332. package/src/common/settings/settings-constants.mts +72 -0
  333. package/src/common/settings/settings-helpers.mts +280 -0
  334. package/src/common/settings/settings-types.mts +137 -0
  335. package/src/constants.mts +39 -0
  336. package/src/foo.mts +13 -0
  337. package/src/helpers.mts +574 -0
  338. package/src/helpers.web.mts +1277 -0
  339. package/src/helpers.web.respec.mts +16 -0
  340. package/src/index.mts +3 -0
  341. package/src/respec-gib.node.mts +199 -0
  342. package/src/spec-helper.node.respec.mts +50 -0
  343. package/src/storage/storage-helpers.web.mts +728 -0
  344. package/src/storage/storage-types.web.mts +29 -0
  345. package/src/types.web.mts +42 -0
  346. package/src/ui/component/component-types.mts +241 -0
  347. package/src/ui/component/ibgib-component-service.mts +201 -0
  348. package/src/ui/component/ibgib-dynamic-component-bases.mts +1369 -0
  349. package/src/ui/ui-constants.mts +101 -0
  350. package/src/ui/ui-helpers.mts +222 -0
  351. package/src/ui/ui-types.mts +11 -0
  352. package/src/witness/agent/agent-constants.mts +122 -0
  353. package/src/witness/agent/agent-helpers.mts +681 -0
  354. package/src/witness/agent/agent-one-file.app.mts +8 -0
  355. package/src/witness/agent/agent-one-file.mts +1665 -0
  356. package/src/witness/agent/agent-types.mts +92 -0
  357. package/src/witness/agent/agents-service-v1.mts +482 -0
  358. package/src/witness/agent/function-info/function-info-one-file.mts +362 -0
  359. package/src/witness/agent/gemini/agent-witness-gemini-v1.mts +910 -0
  360. package/src/witness/agent/gemini/gemini-agent-factory.mts +135 -0
  361. package/src/witness/agent/gemini/gemini-constants.mts +79 -0
  362. package/src/witness/agent/gemini/gemini-helpers.mts +216 -0
  363. package/src/witness/agent/gemini/gemini-types.mts +88 -0
  364. package/src/witness/live-proxy-ibgib/live-proxy-ibgib-one-file.mts +321 -0
  365. package/src/witness/space/metaspace/metaspace-webspace/metaspace-webspace-helper.mts +290 -0
  366. package/src/witness/space/metaspace/metaspace-webspace/metaspace-webspace.mts +407 -0
  367. package/src/witness/space/web-filesystem-space/web-filesystem-space-constants.mts +1 -0
  368. package/src/witness/space/web-filesystem-space/web-filesystem-space-helper.mts +491 -0
  369. package/src/witness/space/web-filesystem-space/web-filesystem-space-types.mts +172 -0
  370. package/src/witness/space/web-filesystem-space/web-filesystem-space-v1.mts +670 -0
  371. package/tsconfig.json +17 -0
  372. package/tsconfig.test.json +10 -0
@@ -0,0 +1,1369 @@
1
+ /**
2
+ * @module component-one-file.mts contains all the types, helpers, constants and
3
+ * classes for the **shell** ui component system. the differentiating factor
4
+ * between this system and other front end ui frameworks is that this is
5
+ * ibgib-driven, with especially ibgib addresses driving components' backing
6
+ * model/data.
7
+ *
8
+ * this is not to be confused with "components" that may be dynamically
9
+ * generated within a blank-canvas environment that the canvas agents will
10
+ * build. this is for the old-school html shell.
11
+ *
12
+ * the ui component system is being built piecemeal as we go.
13
+ *
14
+ * ## approach
15
+ *
16
+ * there are two basic pieces to a component: the component metadata declaration
17
+ * and the concrete component instance that that declaration instantiates. these
18
+ * will be tightly coupled per use-case, with the intention that the meta object
19
+ * will not need to be a descendant class, whereas the component instance will
20
+ * most likely be the class that is extended from an abstract base class.
21
+ *
22
+ * @see {@link IbGibDynamicComponentMeta}
23
+ * @see {@link IbGibDynamicComponentInstance}
24
+ */
25
+
26
+ import { delay, extractErrorMsg, pickRandom_Letters, pretty } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
27
+ import { ROOT_ADDR } from "@ibgib/ts-gib/dist/V1/constants.mjs";
28
+ import { Gib, Ib, IbGibAddr, TjpIbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
29
+ import { getGibInfo, isDna, isPrimitive } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
30
+ import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
31
+ import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
32
+ import { Factory_V1 } from "@ibgib/ts-gib/dist/V1/factory.mjs";
33
+ import { fnObs } from "@ibgib/core-gib/dist/common/pubsub/observer/observer-helper.mjs";
34
+ import { getTimelinesGroupedByTjp, getTjpAddr, splitPerTjpAndOrDna, toDto } from "@ibgib/core-gib/dist/common/other/ibgib-helper.mjs";
35
+ import { MetaspaceService } from "@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs";
36
+ import { mut8Timeline } from "@ibgib/core-gib/dist/timeline/timeline-api.mjs";
37
+
38
+ import { GLOBAL_LOG_A_LOT } from "../../constants.mjs";
39
+ import {
40
+ exportIbGib, getDeterministicColorInfo,
41
+ getRawExportIbGibAndGraphFromJsonString
42
+ } from "../../helpers.web.mjs";
43
+ import { LiveProxyIbGib } from "../../witness/live-proxy-ibgib/live-proxy-ibgib-one-file.mjs";
44
+ import { AgentWitnessAny, } from "../../witness/agent/agent-one-file.mjs";
45
+ import { ElementsBase, FnHandleRouteType, IbGibDynamicComponentInstance, IbGibDynamicComponentInstanceInitOpts, IbGibDynamicComponentMeta, ChildInfoBase, IbGibDynamicComponentMetaCtorOpts } from "./component-types.mjs";
46
+ import { getComponentSvc } from "./ibgib-component-service.mjs";
47
+ import { getAgentForDomainIbGib } from "../../witness/agent/agent-helpers.mjs";
48
+ import { createSettings, getSectionName, getSettingsScope, getSettingsSection } from "../../common/settings/settings-helpers.mjs";
49
+ import { IbGibSettings, SettingsIbGib_V1, SettingsWithTabs } from "../../common/settings/settings-types.mjs";
50
+ import { SettingsType } from "../../common/settings/settings-constants.mjs";
51
+ import { coupleDomainIbGibWithLocalIbGibViaIndex, getLocalCoupledIbGibForDomainIbGib } from "../../helpers.mjs";
52
+
53
+ const logalot = GLOBAL_LOG_A_LOT;
54
+
55
+ /**
56
+ * Base class for the ibgib component Meta factory instance.
57
+ *
58
+ * @see {@link IbGibDynamicComponentMeta}
59
+ */
60
+ export abstract class IbGibDynamicComponentMetaBase
61
+ implements IbGibDynamicComponentMeta {
62
+ protected lc: string = `[${IbGibDynamicComponentMetaBase.name}]`;
63
+ componentName: string = '';
64
+ routeRegExp?: RegExp | undefined = undefined;
65
+ fnHandleRoute?: FnHandleRouteType | undefined = undefined;
66
+ fnGetMetaspace: () => Promise<MetaspaceService>;
67
+ bootstrapPromise: Promise<void>;
68
+ abstract createInstance(arg: {
69
+ path: string;
70
+ ibGibAddr: IbGibAddr;
71
+ }): Promise<IbGibDynamicComponentInstance>;
72
+ /**
73
+ * ## usage
74
+ *
75
+ * I'm planning on creating a single ctor opts instance for this with the
76
+ * properties exposed on the consuming app's global ibgib object, which
77
+ * should have references to these properties.
78
+ *
79
+ * Then, the component meta initialization can be the same as it is atow
80
+ * (12/2025), but instead of empty ctors it will just have the `opts` there.
81
+ *
82
+ * ```
83
+ * const opts = {
84
+ * fnGetMetaspace: globalIbGib.getGlobalMetaspace,
85
+ * bootstrapPromise: globalIbGib.bootstrapPromise,
86
+ * }
87
+ *
88
+ * const componentsMeta: IbGibDynamicComponentMeta[] = [
89
+ * new MyComponentMeta1(opts),
90
+ * new MyComponentMeta2(opts),
91
+ * // other components
92
+ * ];
93
+ * ```
94
+ */
95
+ constructor({
96
+ fnGetMetaspace,
97
+ bootstrapPromise,
98
+ }: IbGibDynamicComponentMetaCtorOpts) {
99
+ this.fnGetMetaspace = fnGetMetaspace;
100
+ this.bootstrapPromise = bootstrapPromise
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Base class for common ibgib component. This is the actual web component
106
+ * instance.
107
+ *
108
+ * ## regarding HTMLElement
109
+ *
110
+ * This class extends HTMLElement, so you have access to things, e.g., the
111
+ * parent element via the normal DOM interface.
112
+ *
113
+ * @see {@link IbGibDynamicComponentInstance}
114
+ */
115
+ export abstract class IbGibDynamicComponentInstanceBase<TIbGib extends IbGib_V1 = IbGib_V1, TElements = any>
116
+ extends HTMLElement
117
+ implements IbGibDynamicComponentInstance<TIbGib, TElements> {
118
+ protected lc: string = `[${IbGibDynamicComponentInstanceBase.name}]`;
119
+
120
+ elements: TElements | undefined;
121
+ createdPromise: Promise<void> | undefined;
122
+ settings: LiveProxyIbGib<SettingsIbGib_V1> | undefined;
123
+
124
+ /**
125
+ * main agent for this component
126
+ *
127
+ * atow (04/2025), this is derived from {@link agents}, being the first one
128
+ * in that array. So, other agents may exist for this component, but the
129
+ * first one should be the main one for this component.
130
+ */
131
+ get agent(): AgentWitnessAny | undefined { return this.agents.at(0); }
132
+ /**
133
+ * @see {@link agent}
134
+ */
135
+ agents: AgentWitnessAny[] = [];
136
+
137
+ get ib(): Ib {
138
+ const { ib } = getIbAndGib({ ibGibAddr: this.ibGibAddr ?? ROOT_ADDR });
139
+ return ib;
140
+ }
141
+ get gib(): Gib {
142
+ const { gib } = getIbAndGib({ ibGibAddr: this.ibGibAddr ?? ROOT_ADDR });
143
+ return gib;
144
+ }
145
+ ibGibAddr: IbGibAddr = ROOT_ADDR;
146
+ /**
147
+ * The proxy witness used for updating the backing ibGib.
148
+ */
149
+ ibGibProxy: LiveProxyIbGib<TIbGib> | undefined;
150
+ /**
151
+ * Backing ibgib getter via {@link ibGibProxy.ibGib}
152
+ */
153
+ get ibGib(): TIbGib | undefined {
154
+ const ibGibAddr = this.ibGibAddr ?? ROOT_ADDR;
155
+ const { ib, gib } = getIbAndGib({ ibGibAddr });
156
+ return this.ibGibAddr && !isPrimitive({ gib }) ?
157
+ this.ibGibProxy?.ibGib :
158
+ Factory_V1.primitive({ ib }) as TIbGib;
159
+ // undefined; // should we return undefined?
160
+ }
161
+ get tjpAddr(): TjpIbGibAddr | undefined {
162
+ return this.ibGib ?
163
+ getTjpAddr({ ibGib: this.ibGib, defaultIfNone: "incomingAddr" })! :
164
+ undefined;
165
+ }
166
+
167
+ /**
168
+ * reference to the meta instance that created this component instance.
169
+ */
170
+ meta: IbGibDynamicComponentMeta | undefined;
171
+ html: string | undefined;
172
+ css: string[] | undefined;
173
+
174
+
175
+ /**
176
+ * not really used yet, since we're only testing with web1 which has a
177
+ * static, primitive ibgib address.
178
+ */
179
+ static get observedAttributes() {
180
+ return ['ibGibAddr'];
181
+ }
182
+
183
+ _instanceId: string;
184
+ get instanceId() { return this._instanceId; }
185
+
186
+ /**
187
+ * we can initialize the agent(s) as soon as we load the ibgib, but we don't
188
+ * want to await it immediately.
189
+ */
190
+ agentsInitialized: Promise<void> | undefined;
191
+
192
+ /**
193
+ * @internal number of times {@link connectedCallback} has been called.
194
+ *
195
+ * ## notes
196
+ *
197
+ * I'm making this because when the component is removed
198
+ */
199
+ protected connectedCount = 0;
200
+
201
+ /**
202
+ * override this as needed
203
+ */
204
+ public get isBusy(): boolean { return false; }
205
+
206
+ protected async getMetaspace(): Promise<MetaspaceService> {
207
+ const lc = `${this.lc}[${this.getMetaspace.name}]`;
208
+ try {
209
+ if (logalot) { console.log(`${lc} starting... (I: 956418cf932823bc767ccc6a0fd2b325)`); }
210
+ if (!this.meta) { throw new Error(`(UNEXPECTED) this.meta falsy? (E: dd2bfae6c0e84b1d58c72e2922b51325)`); }
211
+ return await this.meta.fnGetMetaspace();
212
+ } catch (error) {
213
+ console.error(`${lc} ${extractErrorMsg(error)}`);
214
+ throw error;
215
+ } finally {
216
+ if (logalot) { console.log(`${lc} complete.`); }
217
+ }
218
+ }
219
+
220
+ constructor() {
221
+ super();
222
+ this._instanceId = pickRandom_Letters({ count: 8 });
223
+ }
224
+
225
+ async initialize(opts: IbGibDynamicComponentInstanceInitOpts): Promise<void> {
226
+ let { ibGibAddr, meta, html, css } = opts;
227
+
228
+ // maybe remove this try..catch..finally to speed up perf when this is
229
+ // more mature
230
+ const lc = `${this.lc}[${this.initialize.name}]`;
231
+ try {
232
+ if (logalot) { console.log(`${lc} starting... (I: c9b94131bc2f0d20e1397c214dad6725)`); }
233
+
234
+ this.ibGibAddr = ibGibAddr;
235
+ this.meta = meta;
236
+ this.html = html;
237
+ this.css = css;
238
+
239
+ // Attach shadow DOM
240
+ this.attachShadow({ mode: 'open' });
241
+
242
+ await this.meta.bootstrapPromise;
243
+ } catch (error) {
244
+ console.error(`${lc} ${extractErrorMsg(error)}`);
245
+ throw error;
246
+ } finally {
247
+ if (logalot) { console.log(`${lc} complete.`); }
248
+ }
249
+ }
250
+
251
+ protected async initAgents(): Promise<void> {
252
+ const lc = `${this.lc}[${this.initAgents.name}]`;
253
+ if (logalot) { console.log(`${lc} does nothing in base class (I: 0b31a650b942619a0e36a1a7f763e825)`); }
254
+
255
+ }
256
+
257
+ async connectedCallback(): Promise<void> {
258
+ const lc = `${this.lc}[${this.connectedCallback.name}]`;
259
+ try {
260
+ if (logalot) { console.log(`${lc} starting... (I: 01bbbf69f1c75b03a29e7a85ebd2c725)`); }
261
+
262
+ this.connectedCount++;
263
+
264
+ if (this.connectedCount === 1) {
265
+ // first time this component has been created, so do full
266
+ // template/styles/scripts init.
267
+ await this.connectedCallback_initComponent();
268
+ } else {
269
+ await this.connectedCallback_reconnectComponent();
270
+ }
271
+ } catch (error) {
272
+ console.error(`${lc} ${extractErrorMsg(error)}`);
273
+ throw error;
274
+ } finally {
275
+ if (logalot) { console.log(`${lc} complete.`); }
276
+ }
277
+ }
278
+
279
+ protected async connectedCallback_initComponent(): Promise<void> {
280
+ const lc = `${this.lc}[${this.connectedCallback_initComponent.name}]`;
281
+ try {
282
+ if (logalot) { console.log(`${lc} starting... (I: bc4af3f6751d841f51bad19e334efa25)`); }
283
+ if (!this.html) { throw new Error(`(UNEXPECTED) this.html is falsy? (E: a0a0ab7c8f987d78058dd7cad09a5125)`); }
284
+
285
+ // create template element and set innerHTML
286
+ const template = document.createElement('template');
287
+ template.innerHTML = this.css ?
288
+ `
289
+ <style>
290
+ ${this.css.join('\n')}
291
+ </style>
292
+ ${this.html}
293
+ ` :
294
+ this.html;
295
+
296
+ // append content to shadow DOM
297
+ if (!this.shadowRoot) { throw new Error(`(UNEXPECTED) this.shadowRoot is falsy? (E: 1a3cf77d87767aaff37d31657ee73f25)`); }
298
+ this.shadowRoot.appendChild(template.content);
299
+
300
+ this.createdPromise = this.created();
301
+ await this.createdPromise;
302
+
303
+ } catch (error) {
304
+ console.error(`${lc} ${extractErrorMsg(error)}`);
305
+ throw error;
306
+ } finally {
307
+ if (logalot) { console.log(`${lc} complete.`); }
308
+ }
309
+ }
310
+
311
+ protected async connectedCallback_reconnectComponent(): Promise<void> {
312
+ const lc = `${this.lc}[${this.connectedCallback_reconnectComponent.name}]`;
313
+ try {
314
+ if (logalot) { console.log(`${lc} starting... (I: 7fccefbeff68c0dda15642ebaa1eb525)`); }
315
+ console.log(`${lc} does nothing in base class (I: 724bc670d4ccb0fde2b2fa49830cd425)`);
316
+ } catch (error) {
317
+ console.error(`${lc} ${extractErrorMsg(error)}`);
318
+ throw error;
319
+ } finally {
320
+ if (logalot) { console.log(`${lc} complete.`); }
321
+ }
322
+ }
323
+
324
+ async disconnectedCallback(): Promise<void> {
325
+ const lc = `${this.lc}[${this.disconnectedCallback.name}]`;
326
+ try {
327
+ if (logalot) { console.log(`${lc} starting... (I: 6f3b25c23fb874b1ac513e8f0d1f4e25)`); }
328
+
329
+ await this.disconnected();
330
+ } catch (error) {
331
+ console.error(`${lc} ${extractErrorMsg(error)}`);
332
+ throw error;
333
+ } finally {
334
+ if (logalot) { console.log(`${lc} complete.`); }
335
+ }
336
+ }
337
+
338
+ /**
339
+ * untested so far.
340
+ *
341
+ * @param name
342
+ * @param oldValue
343
+ * @param newValue
344
+ */
345
+ public async attributeChangedCallback(name: string, oldValue: any, newValue: any): Promise<void> {
346
+ const lc = `${this.lc}[attributeChangedCallback]`;
347
+ if (logalot) { console.log(`${lc} starting... (I: 33cd68579171582166d25d8898640f25): ${name} ${oldValue} => ${newValue}`); }
348
+ // handle attribute changes if needed
349
+ console.warn(`${lc} nothing done in base class atow (W: 9eb93eb8fde7c0058c79cea841936a25)`);
350
+ }
351
+
352
+ public abstract created(): Promise<void>;
353
+ public abstract disconnected(): Promise<void>;
354
+ /**
355
+ * triggers {@link destroyed} handler
356
+ *
357
+ * Note there are NO web component lifecycles that trigger this. This must
358
+ * be called explicitly in code.
359
+ * @see {@link disconnected}
360
+ * @see {@link disconnectedCallback}
361
+ */
362
+ public async destroy(): Promise<void> {
363
+ const lc = `${this.lc}[${this.destroy.name}]`;
364
+ try {
365
+ if (logalot) { console.log(`${lc} starting... (I: 536989c9491b544105b6d01a688fbb25)`); }
366
+ await this.destroyed();
367
+ } catch (error) {
368
+ console.error(`${lc} ${extractErrorMsg(error)}`);
369
+ throw error;
370
+ } finally {
371
+ if (logalot) { console.log(`${lc} complete.`); }
372
+ }
373
+ }
374
+ public async destroyed(): Promise<void> {
375
+ const lc = `${this.lc}[${this.destroyed.name}]`;
376
+ try {
377
+ if (logalot) { console.log(`${lc} starting... (I: f34f3ca04b06b1e00ebe04df22331125)`); }
378
+ } catch (error) {
379
+ console.error(`${lc} ${extractErrorMsg(error)}`);
380
+ throw error;
381
+ } finally {
382
+ if (logalot) { console.log(`${lc} complete.`); }
383
+ }
384
+ if (logalot) { console.log(`${lc} does nothing in the base class. (I: d9437f962e0aec40d69ad6159e7b5725)`); }
385
+ return Promise.resolve();
386
+ }
387
+
388
+ public async loadIbGib(opts?: { getLatest?: boolean }): Promise<void> {
389
+ const lc = `${this.lc}[${this.loadIbGib.name}]`;
390
+ try {
391
+ if (logalot) { console.log(`${lc} starting... (I: 4dcb1b7a3d86f3415ca7224c07126925)`); }
392
+
393
+ const getLatest = opts?.getLatest ?? false;
394
+
395
+ if (this.ibGib) {
396
+ // this may be because we need to load the ibgib/have access to
397
+ // it before the web component is attached to the DOM (which
398
+ // triggers the component's created event)
399
+ console.warn(`${lc} this.ibGib already loaded. idempotently returning early without doing anything. (W: 15498d346a32e884acec108cb3c8ee25)`);
400
+ return; /* <<<< returns early */
401
+ }
402
+
403
+ if (isPrimitive({ gib: getIbAndGib({ ibGibAddr: this.ibGibAddr ?? ROOT_ADDR }).gib })) {
404
+ if (logalot) { console.log(`${lc} component loading primitive ibgib (I: 3349796ef6139c1e718c8626c7935625)`); }
405
+ // no need to load, this.ibGib will be derived from the primitive addr
406
+ return; /* <<<< returns early */
407
+ }
408
+
409
+ // live or not, we want to get the ibgib record itself.
410
+ const metaspace = await this.getMetaspace();
411
+ /**
412
+ * using default local space as the common shared space atow
413
+ * (04/2025)
414
+ */
415
+ const space = await metaspace.getLocalUserSpace({ lock: false });
416
+ if (!space) { throw new Error(`(UNEXPECTED) local user space falsy? (E: bb093b7e9781064e8db9a4390b63bb25)`); }
417
+
418
+ if (getLatest) {
419
+ const latestAddr = await metaspace.getLatestAddr({ addr: this.ibGibAddr, space });
420
+ if (latestAddr && latestAddr !== this.ibGibAddr) {
421
+ this.ibGibAddr = latestAddr;
422
+ }
423
+ }
424
+ const resGet = await metaspace.get({
425
+ addrs: [this.ibGibAddr],
426
+ space,
427
+ // space: undefined,
428
+ });
429
+ if (!resGet.success || resGet.ibGibs?.length !== 1) {
430
+ throw new Error(`couldn't get ibGib (${this.ibGibAddr}) in space (${space?.ib ?? 'undefined'}) (E: 59c3461bebf3e0065df72bd1bd8dc125)`);
431
+ }
432
+
433
+ // get the initial ibGib and wrap it in the "live" (updating) proxy
434
+ const ibGib = resGet.ibGibs.at(0)!;
435
+ const ibGibProxy = new LiveProxyIbGib<TIbGib>();
436
+ await ibGibProxy.initialized;
437
+ if (!ibGibProxy.contextUpdated$) {
438
+ throw new Error(`(UNEXPECTED) ibGibProxy.contextUpdated$ falsy? (E: 351dfc898d2c3da2d7928079cec14925)`);
439
+ }
440
+ ibGibProxy.contextUpdated$.subscribe(fnObs({
441
+ next: async (nextIbGib) => {
442
+ const lcNext = `${lc}[ibGibProxy.contextUpdated$][next]`;
443
+ if (logalot) { console.log(`${lcNext} nextIbGib: ${pretty(nextIbGib)} (I: 96c846357b94fda2cefa615aed88c325)`); }
444
+ await this.handleContextUpdated();
445
+ },
446
+ error: async (e) => {
447
+ debugger; // error in component.ibGibProxy.contextUpdated$ observable?
448
+ console.error(`${lc}[ibGibProxy.contextUpdated$][error] what up? ${extractErrorMsg(e)}`);
449
+ },
450
+ }));
451
+
452
+ if (!ibGibProxy.newContextChild$) { throw new Error(`(UNEXPECTED) ibGibProxy.newContextChild$ falsy? (E: 2cbde5ab402cc6d81259c74d68bca725)`); }
453
+ ibGibProxy.newContextChild$.subscribe(fnObs({
454
+ next: async (childIbGib) => {
455
+ const lcNext = `${lc}[ibGibProxy.contextUpdated$][next]`;
456
+ if (logalot) { console.log(`${lcNext} childIbGib: ${pretty(childIbGib)} (I: 96c846357b94fda2cefa615aed88c325)`); }
457
+ await this.handleNewContextChild({ childIbGib });
458
+ },
459
+ error: async (e) => {
460
+ debugger; // error in component.ibGibProxy.contextUpdated$ observable?
461
+ console.error(`${lc}[ibGibProxy.contextUpdated$][error] what up? ${extractErrorMsg(e)}`);
462
+ },
463
+ }));
464
+ /**
465
+ * not necessary, I'm just putting this here to remind myself that
466
+ * we can dynamically assign a space (via spaceId) to a proxy ibgib.
467
+ */
468
+ const _ignoredSpace = await ibGibProxy.witness(space);
469
+ const _ignored = await ibGibProxy.witness(ibGib);
470
+ this.ibGibProxy = ibGibProxy;
471
+
472
+ // update the addr in case the proxy is newer than the ibgib addr
473
+ // that we started with.
474
+ this.ibGibAddr = getIbGibAddr({ ibGib: ibGibProxy.ibGib });
475
+ } catch (error) {
476
+ console.error(`${lc} ${extractErrorMsg(error)}`);
477
+ throw error;
478
+ } finally {
479
+ if (logalot) { console.log(`${lc} complete.`); }
480
+ }
481
+ }
482
+
483
+ /**
484
+ * in base class, this sets {@link ibGibAddr} to reflect the {@link nextIbGib}.
485
+ *
486
+ * override this in child classes to do more when next context happens
487
+ *
488
+ * @see {@link handleNewContextChild}
489
+ */
490
+ protected async handleContextUpdated(): Promise<void> {
491
+ const lc = `${this.lc}[${this.handleContextUpdated.name}]`;
492
+ try {
493
+ const { ibGib } = this; // derived from ibGibProxy
494
+ this.ibGibAddr = ibGib ? getIbGibAddr({ ibGib }) : ROOT_ADDR;
495
+ if (logalot) { console.log(`${lc} context updated. this.ibGibAddr (I: 64e5876f58cc54b5af777c94f13a4325)`); }
496
+ } catch (error) {
497
+ console.error(`${lc} ${extractErrorMsg(error)}`);
498
+ throw error;
499
+ }
500
+ }
501
+ /**
502
+ * does nothing (atow 04/2025) in base class
503
+ *
504
+ * override this to handle new children on {@link ibGibProxy}
505
+ * @see {@link handleContextUpdated}
506
+ */
507
+ protected async handleNewContextChild({ childIbGib }: { childIbGib: IbGib_V1 }): Promise<void> {
508
+ const lc = `${this.lc}[${this.handleNewContextChild.name}]`;
509
+ try {
510
+ if (logalot) { console.log(`${lc} child added to contextcontext updated. childIbGib: ${pretty(childIbGib)} (I: 07d02c9182c6629cbbacd39fd0ff7f25)`); }
511
+ console.log(getIbGibAddr({ ibGib: childIbGib })); // debug
512
+ } catch (error) {
513
+ console.error(`${lc} ${extractErrorMsg(error)}`);
514
+ throw error;
515
+ }
516
+ }
517
+
518
+ /**
519
+ * updates and renders the visual part of the component.
520
+ */
521
+ protected async renderUI(): Promise<void> {
522
+ const lc = `${this.lc}[${this.renderUI.name}]`;
523
+ try {
524
+ if (logalot) { console.log(`${lc} starting... (I: 7e5704afe17fb937c8473e7801f56e25)`); }
525
+
526
+ if (this.ibGib) {
527
+ // const color = getUniqueColorInfo({ ibGib: this.ibGib, });
528
+ // this.style.setProperty('--ibgib-color', color);
529
+ const {
530
+ punctiliarColor,
531
+ punctiliarColorTranslucent,
532
+ punctiliarColorContrast,
533
+ tjpColor,
534
+ tjpColorTranslucent,
535
+ tjpColorContrast,
536
+ errorMsg
537
+ } = getDeterministicColorInfo({ ibGib: this.ibGib, translucentAlpha: 10 });
538
+ if (!errorMsg) {
539
+ this.style.setProperty('--ibgib-color', punctiliarColor);
540
+ this.style.setProperty('--ibgib-color-translucent', punctiliarColorTranslucent);
541
+ this.style.setProperty('--ibgib-color-contrast', punctiliarColorContrast);
542
+ this.style.setProperty('--tjp-color', tjpColor ?? punctiliarColor);
543
+ this.style.setProperty('--tjp-color-translucent', tjpColorTranslucent ?? punctiliarColorTranslucent);
544
+ this.style.setProperty('--tjp-color-contrast', tjpColorContrast ?? 'lime');
545
+ } else {
546
+ // don't set anything
547
+ console.error(`${lc} ${errorMsg} (E: 65e0d330d029c1fe39f3d6280dda3725)`);
548
+ }
549
+ }
550
+
551
+ await this.renderUI_busy();
552
+ } catch (error) {
553
+ console.error(`${lc} ${extractErrorMsg(error)}`);
554
+ throw error;
555
+ } finally {
556
+ if (logalot) { console.log(`${lc} complete.`); }
557
+ }
558
+
559
+ }
560
+
561
+ protected async renderUI_busy(): Promise<void> {
562
+ // does nothing in base
563
+ }
564
+
565
+ /**
566
+ * loads the agent(s) coupled to the domain ibgib (this.ibGib), if any.
567
+ */
568
+ protected async loadAgentsCoupledToIbGib({
569
+ dontThrowIfNone,
570
+ }: {
571
+ /**
572
+ * most components have an agent. set this to true if the component is small enough to NOT have an agent.
573
+ */
574
+ dontThrowIfNone?: boolean,
575
+ } = {}): Promise<void> {
576
+ const lc = `${this.lc}[${this.loadAgentsCoupledToIbGib.name}]`;
577
+ try {
578
+ // #region init/validation
579
+ const metaspace = await this.getMetaspace();
580
+ // const { metaspace } = this;
581
+ // if (!metaspace) { throw new Error(`(UNEXPECTED) this.metaspace falsy? (E: 230f36ee774eaaecddabd42540160325)`); }
582
+
583
+ const space = await metaspace.getLocalUserSpace({ lock: false });
584
+ if (!space) { throw new Error(`(UNEXPECTED) space falsy? we couldn't get the default local user space? (E: 06f5be2eec8abaa54d42ad982a155925)`); }
585
+
586
+ // const domainIbGib = this.ibGib as (ProjectIbGib_V1 | undefined);
587
+ // if (!domainIbGib) { throw new Error(`(UNEXPECTED) this.ibGib (projectIbGib) falsy? (E: a0281854c6312eadaa3420015d0d0925)`); }
588
+
589
+ if (!this.ibGib) { throw new Error(`(UNEXPECTED) this.ibGib falsy? (E: 9b24c4b4aa491a21b58fde9185eb9325)`); }
590
+ // #endregion init/validation
591
+
592
+ const agent = await getAgentForDomainIbGib({
593
+ ibGib: this.ibGib,
594
+ metaspace,
595
+ space,
596
+ });
597
+ if (agent) {
598
+ const initialN = agent.data!.n!;
599
+ await agent.setActiveContext({ contextIbGib: this.ibGib, loggingInfo: this.lc }); // maybe too premature?
600
+ await delay(32); // allow update of data.n kluge
601
+ const afterN = agent.data!.n!;
602
+ if (initialN !== afterN) {
603
+ console.warn(`${lc} setting active context for agent changed agent.data.n.\nagent.data: ${pretty(toDto({ ibGib: agent }))}\nibGib.data: ${toDto({ ibGib: this.ibGib })} (W: cb22e8b064d8c2d7b3b2c488ed169225)`)
604
+ // debugger; // dynamic comp base...why did data.n change?
605
+ }
606
+ this.agents = [agent];
607
+ } else {
608
+ // one day come back to visit this idea of mandatory agent per component, as some components seem small enough to warrant not requiring an agent.
609
+ if (dontThrowIfNone) {
610
+ console.warn(`(UNEXPECTED) agent falsy? an agent should have been created and registered with the ibGib (${getIbGibAddr({ ibGib: this.ibGib })}) (W: e4219903462baab438a23c786d714825)`);
611
+ } else {
612
+ throw new Error(`(UNEXPECTED) agent falsy? an agent should have been created and registered with the ibGib (${getIbGibAddr({ ibGib: this.ibGib })}) (E: 7182d1aa070b9578c78a5b8b401d8425)`);
613
+ }
614
+ }
615
+ } catch (error) {
616
+ console.error(`${lc} ${extractErrorMsg(error)}`);
617
+ throw error;
618
+ } finally {
619
+ if (logalot) { console.log(`${lc} complete.`); }
620
+ }
621
+ }
622
+
623
+
624
+ /**
625
+ * Gets the settings section.
626
+ *
627
+ * NOTE: this.settings and this.settings.ibGib must be initialized before
628
+ * calling this, else will throw.
629
+ *
630
+ * @returns settings section corresponding to type/use case or undefined
631
+ *
632
+ * ## notes on settings
633
+ *
634
+ * AFAICT I have made this so that there is one single settings ibgib with
635
+ * individual sections in its data. So use this function to get a section
636
+ * within that settings ibgib that is based on a given domain ibgib (this.ibGib).
637
+ *
638
+ * So a component initializes/activates an ibGib (this.ibGib) and for those
639
+ * components that use the settings, this.initSettings must be called. Then
640
+ * you call getSettings or updateSettings (not implemented yet).
641
+ */
642
+ protected async getSettings<TSettings extends IbGibSettings>({
643
+ settingsType,
644
+ useCase,
645
+ }: {
646
+ settingsType: SettingsType,
647
+ useCase: "current" | string,
648
+ }): Promise<TSettings | undefined> {
649
+ const lc = `${this.lc}[${this.getSettings.name}]`;
650
+ try {
651
+ if (logalot) { console.log(`${lc} starting... (I: 00c8dbedd2e8a8b988cc45f4186efd25)`); }
652
+ if (!this.settings) { throw new Error(`(UNEXPECTED) this.settings falsy? shouldn't this be initialized by now? (E: ceae480e28fab1da38b8def8b1060d25 (E: dc7d984c1c64293a3c3e0628dedadb25)`); }
653
+ if (!this.settings.ibGib) { throw new Error(`(UNEXPECTED) this.settings.ibGib falsy? shouldn't this be initialized by now? especially since this.settings is truthy? (E: faef6878abaf00a4a6a6f6b85ce8c825)`); }
654
+
655
+ const settingsSection = await getSettingsSection({
656
+ sectionName: await getSectionName({ settingsType, useCase, }),
657
+ settingsIbGib: this.settings.ibGib,
658
+ }) as (TSettings | undefined);
659
+
660
+ if (!settingsSection) {
661
+ if (logalot) { console.log(`${lc} settingsSection does not exist. returning undefined. (I: 0462d83f5ae8049708274b88e9b0d825)`) }
662
+ }
663
+ return settingsSection;
664
+ } catch (error) {
665
+ console.error(`${lc} ${extractErrorMsg(error)}`);
666
+ throw error;
667
+ } finally {
668
+ if (logalot) { console.log(`${lc} complete.`); }
669
+ }
670
+ }
671
+
672
+ protected async updateSettings<TSettings extends IbGibSettings>({
673
+ settingsType,
674
+ useCase,
675
+ newSectionInfo,
676
+ }: {
677
+ settingsType: SettingsType,
678
+ useCase: "current" | string,
679
+ newSectionInfo: TSettings,
680
+ }): Promise<void> {
681
+ const lc = `${this.lc}[${this.updateSettings.name}]`;
682
+ try {
683
+ if (logalot) { console.log(`${lc} starting... (I: 80ce98cf386e0c04d30e8b15ac0f2925)`); }
684
+
685
+ const sectionName_current = await getSectionName({
686
+ settingsType,
687
+ useCase,
688
+ });
689
+ const _newSettings = await mut8Timeline({
690
+ timeline: this.settings!.ibGib!,
691
+ metaspace: await this.getMetaspace(),
692
+ mut8Opts: {
693
+ dataToAddOrPatch: {
694
+ sections: {
695
+ [sectionName_current]: newSectionInfo,
696
+ }
697
+ },
698
+ },
699
+ });
700
+ await delay(100); // cheap kluge to allow settings ibgib to update
701
+ } catch (error) {
702
+ console.error(`${lc} ${extractErrorMsg(error)}`);
703
+ throw error;
704
+ } finally {
705
+ if (logalot) { console.log(`${lc} complete.`); }
706
+ }
707
+ }
708
+
709
+ /**
710
+ * if this.ibGib has a coupled settings ibgib indexed in the local space,
711
+ * then {@link settings} should be loaded with it. This is a convenience
712
+ * fn to access the current settings section for the {@link settingsType}.
713
+ */
714
+ protected async getCurrentSettings<TSettings extends IbGibSettings>({ settingsType }: { settingsType: SettingsType }): Promise<TSettings | undefined> {
715
+ const lc = `${this.lc}[${this.getCurrentSettings.name}]`;
716
+ try {
717
+ if (logalot) { console.log(`${lc} starting... (I: da0baee73e386089a8c059f83cc43825)`); }
718
+ if (!this.settings) { return undefined; /* <<<< returns early */ }
719
+ const sectionName = await getSectionName({ settingsType, useCase: 'current' });
720
+ return getSettingsSection({ sectionName, settingsIbGib: this.settings.ibGib! });
721
+ } catch (error) {
722
+ console.error(`${lc} ${extractErrorMsg(error)}`);
723
+ throw error;
724
+ } finally {
725
+ if (logalot) { console.log(`${lc} complete.`); }
726
+ }
727
+ }
728
+ protected async initSettings(): Promise<void> {
729
+ const lc = `${this.lc}[${this.initSettings.name}]`;
730
+ try {
731
+ if (logalot) { console.log(`${lc} starting... (I: acfee8787d32a6075442e2887a386a25)`); }
732
+
733
+ // get the local space settings for this ibgib and update
734
+ // this.lensMode appropriately
735
+ if (!this.ibGib) { throw new Error(`(UNEXPECTED) this.ibGib falsy? (E: 8ce2e73bea87b9330b131778a3981825)`); }
736
+ const metaspace = await this.getMetaspace();
737
+ const space = await metaspace.getLocalUserSpace({ lock: false });
738
+ if (!space) { throw new Error(`(UNEXPECTED) couldn't get default local user space? (E: f77ce7269a6f0d7ad8978349b4c6cd25)`); }
739
+
740
+ if (isPrimitive({ ibGib: this.ibGib })) {
741
+ console.error(`${lc} this.ibGib is primitive, so what are we initializing settings for? (W: 9915089019b81c6935b32ae877095825)`);
742
+ return; /* <<<< returns early */
743
+ }
744
+
745
+ const scope = await getSettingsScope({ ibGib: this.ibGib });
746
+ let settingsIbGib =
747
+ await getLocalCoupledIbGibForDomainIbGib<SettingsIbGib_V1>({
748
+ scope,
749
+ // scope: this.getSettingsScope(),
750
+ // scope: PROJECT_SETTINGS_SCOPE,
751
+ ibGib: this.ibGib,
752
+ metaspace,
753
+ space,
754
+ });
755
+
756
+ // we want to get the *current* general settings to reload. if they
757
+ // do not exist, then we need to init the settings
758
+
759
+ if (!settingsIbGib) {
760
+ // create new project settings and couple to the project ibgib
761
+ // const defaultGeneral = await getDefaultSettings({ settingsType: SettingsType.general });
762
+ // const scope = await getSettingsScope({ ibGib: this.ibGib });
763
+ const resNewSettings = await createSettings({
764
+ scope,
765
+ metaspace,
766
+ space,
767
+ saveInSpace: true,
768
+ });
769
+ settingsIbGib = resNewSettings.newIbGib;
770
+ await coupleDomainIbGibWithLocalIbGibViaIndex({
771
+ scope,
772
+ domainIbGib: this.ibGib,
773
+ localIbGib: settingsIbGib,
774
+ metaspace,
775
+ space,
776
+ });
777
+ }
778
+ if (!settingsIbGib) { throw new Error(`(UNEXPECTED) settings falsy still? should be initialized. (E: a179adcbbab800cff849b8aa95fbe425)`); }
779
+
780
+ const settingsProxy = new LiveProxyIbGib();
781
+ await settingsProxy.setWrappedIbGib({ ibGib: settingsIbGib, space });
782
+ this.settings = settingsProxy as LiveProxyIbGib<SettingsIbGib_V1>;
783
+
784
+ const generalSettings = await this.getCurrentSettings({ settingsType: SettingsType.general });
785
+
786
+ // const sectionName_currentGeneral = await getSectionName({
787
+ // settingsType: SettingsType.general,
788
+ // useCase: 'current',
789
+ // });
790
+ // let generalSettings = await getSettingsSection<Settings_General>({
791
+ // sectionName: sectionName_currentGeneral,
792
+ // settingsIbGib: settingsIbGib,
793
+ // });
794
+ if (!generalSettings) {
795
+ throw new Error(`(UNEXPECTED) no current general settings? the settings should have been updated with this upon creation. (E: d10fd8d42b58d917180293a713009825)`);
796
+ }
797
+
798
+ } catch (error) {
799
+ console.error(`${lc} ${extractErrorMsg(error)}`);
800
+ throw error;
801
+ } finally {
802
+ if (logalot) { console.log(`${lc} complete.`); }
803
+ }
804
+ }
805
+
806
+ /**
807
+ * exports a given ibgib to the default local userspace in the metaspace.
808
+ */
809
+ protected async exportIbGib({
810
+ ibGib,
811
+ compress,
812
+ }: {
813
+ ibGib: IbGib_V1,
814
+ compress: boolean,
815
+ }): Promise<void> {
816
+ const lc = `${this.lc}[${this.exportIbGib.name}]`;
817
+ try {
818
+ if (logalot) { console.log(`${lc} starting... (I: 623d9463d919683be81f749821a95825)`); }
819
+ const metaspace = await this.getMetaspace();
820
+ if (!metaspace) { throw new Error(`(UNEXPECTED) metaspace falsy? (E: 3d15dbd074ac0c15b834a788d0b57d25)`); }
821
+ if (isPrimitive({ ibGib })) {
822
+ throw new Error(`ibGib is primitive. Can't export primitive. (E: dd42c42e9fda0707e81c692af1a2a225)`);
823
+ }
824
+
825
+ const space = await metaspace.getLocalUserSpace({ lock: false });
826
+ if (!space) { throw new Error(`(UNEXPECTED) couldn't get default local user space? (E: 7bb735be58282f1bd7abe5d9ffabb525)`); }
827
+
828
+ // const resGetExport = await getRawExportIbGib({
829
+ // ibGib,
830
+ // live: true,
831
+ // compress,
832
+ // metaspace: metaspace,
833
+ // space,
834
+ // });
835
+
836
+ // maybe can just dynamically add this anchor element with display: none and click it? hmm...i've done this, will test
837
+ // if (!this.shadowRoot) { throw new Error(`(UNEXPECTED) this.shadowRoot falsy? (E: 137f413b39a88fdc58c751c82efd3825)`); }
838
+ // const downloadAnchorElId = 'export-ibgib-anchor';
839
+ // const downloadAnchorEl = this.shadowRoot.getElementById(downloadAnchorElId) as HTMLAnchorElement;
840
+ // if (!downloadAnchorEl) { throw new Error(`(UNEXPECTED) dlAnchorElem falsy? should be an element with id ${downloadAnchorElId}? (E: 51dfe2d823eedeefb8b9c9580090e625)`); }
841
+
842
+ await exportIbGib({
843
+ ibGib,
844
+ compress,
845
+ // downloadAnchorEl,
846
+ metaspace,
847
+ space,
848
+ });
849
+
850
+ // THE FOLLOWING CODE WAS **MOSTLY** PUT INTO THE ABOVE HELPER FUNCTION.
851
+
852
+ // const { rawExportIbGib: exportIbGib, errors } = resGetExport;
853
+ // const exportErrors = resGetExport.errors ?? [];
854
+ // if (exportErrors.length > 0) {
855
+ // throw new Error(`Export had errors: ${exportErrors} (E: 05faf83f25d3449ab809dfd24eeaf825)`);
856
+ // }
857
+
858
+ // // at this point, we have a possibly quite large ibGib whose data includes
859
+ // // every single ibgib that this.ibGib relates to (its dependency graph). This
860
+ // // so now we can save this file and later import from it.
861
+
862
+ // /**
863
+ // * exportIbGib is guaranteed to have a serializable structure, i.e.,
864
+ // * the data has only primitives. (there are no Uint8Array)
865
+ // */
866
+ // const exportIbGibAsString = JSON.stringify(exportIbGib);
867
+
868
+ // // thank you SO, OP and volzotan at https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser
869
+ // // set the anchor's href to a data stream
870
+ // const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(exportIbGibAsString);
871
+
872
+ // // get the filename for the anchor to suggest for the "download"
873
+ // const exportAddr = getIbGibAddr({ ibGib: exportIbGib });
874
+ // const filename = `${exportAddr}.json`;
875
+
876
+ // // // if (this.web) {
877
+ // // trigger the click
878
+ // if (!this.shadowRoot) { throw new Error(`(UNEXPECTED) this.shadowRoot falsy? (E: 137f413b39a88fdc58c751c82efd3825)`); }
879
+ // const downloadAnchorElId = 'export-ibgib-anchor';
880
+ // // const downloadAnchorEl = document.getElementById(downloadAnchorElId);
881
+ // const downloadAnchorEl = this.shadowRoot.getElementById(downloadAnchorElId);
882
+ // if (!downloadAnchorEl) { throw new Error(`(UNEXPECTED) dlAnchorElem falsy? should be an element with id ${downloadAnchorElId}? (E: 51dfe2d823eedeefb8b9c9580090e625)`); }
883
+ // downloadAnchorEl.setAttribute("href", dataStr);
884
+ // downloadAnchorEl.setAttribute("download", filename);
885
+ // downloadAnchorEl.click();
886
+ // // } else {
887
+ // // // let res = await Filesystem.requestPermissions();
888
+ // // await Filesystem.writeFile({
889
+ // // data: dataStr,
890
+ // // directory: Directory.ExternalStorage,
891
+ // // path: `/Download/${filename}`,
892
+ // // encoding: Encoding.UTF8,
893
+ // // recursive: true,
894
+ // // });
895
+ // // }
896
+ // // await Dialog.alert({ title: 'export succeeded', message: 'way to go, the export succeeded' });
897
+ // // throw new Error(`not implemented (E: d17d28b80f2576c6e81298fffc2e7825)`);
898
+ } catch (error) {
899
+ console.error(`${lc} ${extractErrorMsg(error)}`);
900
+ throw error;
901
+ } finally {
902
+ if (logalot) { console.log(`${lc} complete.`); }
903
+ }
904
+ }
905
+
906
+ /**
907
+ * imports a given ibgib into this.ibGib's
908
+ */
909
+ protected async importIbGib({
910
+ exportIbGibJsonString,
911
+ rel8nName,
912
+ force,
913
+ skipRegisterTimelines,
914
+ divergentTimelineStrategy,
915
+ }: {
916
+ /**
917
+ * this is the contents of the export save file which should have been created with {@link exportIbGib}
918
+ */
919
+ exportIbGibJsonString: string,
920
+ /**
921
+ * named edge that we'll rel8 the ibGib in {@link exportIbGibJsonString}
922
+ * to {@link ibGib}.
923
+ */
924
+ rel8nName: string,
925
+ /**
926
+ * if true, will add rel8n even if already rel8d.
927
+ */
928
+ force?: boolean,
929
+ /**
930
+ * if true, will not call metaspace.registerNew on imported timelines.
931
+ *
932
+ * ## notes
933
+ *
934
+ * may be yagni but meh, i see it as a distinct possibility when
935
+ * importing that we just want to bring ibgibs in.
936
+ */
937
+ skipRegisterTimelines?: boolean,
938
+ /**
939
+ * If
940
+ */
941
+ divergentTimelineStrategy: 'supercede-timeline' | 'keep-existing-timeline' | 'optimistic-merge' | 'throw-error',
942
+ }): Promise<void> {
943
+ const lc = `${this.lc}[${this.importIbGib.name}]`;
944
+ try {
945
+
946
+ const metaspace = await this.getMetaspace();
947
+ const space = await metaspace.getLocalUserSpace({ lock: false });
948
+ if (!space) { throw new Error(`(UNEXPECTED) couldn't get default local user space? (E: 947c983e57a91aa00c8c185320354325)`); }
949
+
950
+ let [rawExportIbGib, ibGibGraph] = await getRawExportIbGibAndGraphFromJsonString({ exportIbGibJsonString, metaspace });
951
+ if (!rawExportIbGib.data) { throw new Error(`(UNEXPECTED) rawExportIbGib.data falsy? this is assumed validated at this point. (E: 6bc4e84db08e3c6228b2c40c2ea50825)`); }
952
+ /**
953
+ * this is the actual addr of the ibgib we're importing and should
954
+ * be the root of the export. if this exact addr already exists in the space, then the
955
+ * entire dependency graph is assumed to exist. if force is true, then we'll ignore this step
956
+ */
957
+ const exportRootAddr = rawExportIbGib.data.contextIbGibAddr;
958
+
959
+ let skipImportGraphIntoSpace = false;
960
+ if (!force) {
961
+ // double check to see if the import ibgib already exists in the
962
+ // space. if it does, then we don't need to do any
963
+ // saving/registering of the graph we're importing.
964
+
965
+ const resGetExisting = await metaspace.get({
966
+ addr: exportRootAddr,
967
+ space,
968
+ });
969
+ if (resGetExisting.success && (resGetExisting.ibGibs ?? []).length === 1) {
970
+ console.log(`${lc} export's ibGib addr (${exportRootAddr}) already exists in the space, so we're skipping doing any physical importing of the export's graph. (I: 429b5bdcd0585c697869f568c4673825)`);
971
+ skipImportGraphIntoSpace = true;
972
+ }
973
+ }
974
+
975
+ // before rel8ing the export to this.ibGib via rel8nName, we must
976
+ // save the import in the space.
977
+ if (!skipImportGraphIntoSpace) {
978
+ splitPerTjpAndOrDna
979
+ const graphIbGibs_dna: IbGib_V1[] = [];
980
+ const graphIbGibs_nondna: IbGib_V1[] = [];
981
+ Object.values(ibGibGraph).forEach(x => {
982
+ if (isDna({ ibGib: x })) {
983
+ graphIbGibs_dna.push(x);
984
+ } else {
985
+ graphIbGibs_nondna.push(x);
986
+ }
987
+ });
988
+
989
+ // do the dna first
990
+ const resPutDna = await metaspace.put({
991
+ ibGibs: graphIbGibs_dna,
992
+ isDna: true,
993
+ space, force,
994
+ });
995
+ if (!resPutDna.success || !!resPutDna.errorMsg) {
996
+ throw new Error(`there was an error putting the export's dna ibgibs into the space (${space.ib}). error: ${resPutDna.errorMsg || '[unknown error (E: 7c7ef8d5281399b1d8f3fbeefba1b825)]'} (E: ce3e8b982208afc4889164ba20a31825)`);
997
+ }
998
+
999
+ // dna done, but we still may have stones (non-timeline, i.e.,
1000
+ // no tjp) so do those next (least amount of dependencies, no
1001
+ // need to register timelines)
1002
+ const { mapWithTjp_YesDna, mapWithTjp_NoDna, mapWithoutTjps } = splitPerTjpAndOrDna({ ibGibs: graphIbGibs_nondna });
1003
+ const resPutNonDnaStones = await metaspace.put({
1004
+ ibGibs: Object.values(mapWithoutTjps),
1005
+ space, force,
1006
+ });
1007
+ if (!resPutNonDnaStones.success || !!resPutNonDnaStones.errorMsg) {
1008
+ throw new Error(`there was an error putting the export's non-dna stone ibgibs (no-tjp) into the space (${space.ib}). error: ${resPutNonDnaStones.errorMsg || '[unknown error (E: dc17f8ee7aed5c445f8b827f274b0825)]'} (E: 9561364961e89c132818f6784a607825)`);
1009
+ }
1010
+
1011
+ // at this point, we only have timelines left. With timelines,
1012
+ // we need to not only put them in the space, but also register
1013
+ // the most recent one. (maybe we should register all of them
1014
+ // but that gets complicated.) since these are all imports,
1015
+ // there shouldn't be anything listening specifically for
1016
+ // updates to these timelines.
1017
+
1018
+ const timelineIbGibsMap = { ...mapWithTjp_YesDna, ...mapWithTjp_NoDna, };
1019
+ const timelineIbGibs = Object.values(timelineIbGibsMap);
1020
+
1021
+
1022
+ // first, let's persist them
1023
+ const resPutTimelines = await metaspace.put({
1024
+ ibGibs: timelineIbGibs,
1025
+ space, force,
1026
+ });
1027
+ if (!resPutTimelines.success || !!resPutTimelines.errorMsg) {
1028
+ throw new Error(`there was an error putting the export's timeline ibgibs into the space (${space.ib}). error: ${resPutTimelines.errorMsg || '[unknown error (E: be4a28961574765798c8d3686ae89c25)]'} (E: 066796a23da3c9f748558fd25bfdf525)`);
1029
+ }
1030
+
1031
+ // now we want to register the latest in each timeline, so at
1032
+ // the very least if we call get latest on any of the timeline
1033
+ // ibgibs (at any point in time within one of those timelines),
1034
+ // the metaspace has registered the latest one.
1035
+
1036
+ if (!skipRegisterTimelines) {
1037
+ /**
1038
+ * from getTimelinesGroupedByTjp documentation:
1039
+ * > @returns filtered, sorted map of incoming `ibGibs` [tjpAddr] => timeline [ibgib0 (tjp), ibgib1, ibgib2, ..., ibgibN (latest)]
1040
+ */
1041
+ const timelineMap_groupdByTjp = getTimelinesGroupedByTjp({ ibGibs: timelineIbGibs });
1042
+ const timelines = Object.values(timelineMap_groupdByTjp);
1043
+ for (const timeline of timelines) {
1044
+ // we want to register the latest in the export's
1045
+ // timeline, BUT... there may be a more recent ibgib
1046
+ // already in the given space. ALSO there might even be
1047
+ // a divergent timeline, such that the space has a
1048
+ // different timeline evolutionary path than the one in
1049
+ // the given export's timeline.
1050
+ const latestIbGibInTimeline = timeline.at(-1);
1051
+ if (!latestIbGibInTimeline) { throw new Error(`(UNEXPECTED) latestInTimeline falsy? this would mean that we had an empty timeline, and this doesn't make sense... (E: 3bec09e79768cc39d8029f4fe3af9825)`); }
1052
+ const latestAddr = await metaspace.getLatestAddr({
1053
+ ibGib: latestIbGibInTimeline,
1054
+ space,
1055
+ });
1056
+ let spaceAlreadyHasMoreRecentThanLatest = false;
1057
+ if (latestAddr) {
1058
+
1059
+ } else {
1060
+ // no addrs registered with space, so
1061
+ }
1062
+
1063
+ if (!spaceAlreadyHasMoreRecentThanLatest) {
1064
+ await metaspace.registerNewIbGib({
1065
+ ibGib: latestIbGibInTimeline,
1066
+ space,
1067
+ });
1068
+ }
1069
+ }
1070
+ }
1071
+ }
1072
+
1073
+
1074
+ // what if the export's timeline is already related to this.ibGib via rel8nName?
1075
+ // what if the ibgib already exists in the space?
1076
+
1077
+ // OK, I'm leaving off for the moment, because I need to rethink
1078
+ // this whole strategy. may need to spawn a new local space and
1079
+ // attempt to do it in that space. this may be where we should do
1080
+ // the local merge/sync timelines, because what if the import has
1081
+ // one or more divergent timelines?
1082
+ // so importing requires some more thinking, because an import can
1083
+ // essentially be seen as a merge.
1084
+
1085
+ throw new Error(`not implemented (E: 66c308e420e848c8d7cd01c8fddf8425)`);
1086
+ } catch (error) {
1087
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1088
+ throw error;
1089
+ } finally {
1090
+ if (logalot) { console.log(`${lc} complete.`); }
1091
+ }
1092
+ }
1093
+ }
1094
+
1095
+ /**
1096
+ * Common plumbing for any component that is meant to contain other ibgib
1097
+ * components as children.
1098
+ */
1099
+ export abstract class IbGibDynamicComponentInstanceBase_Parent<TIbGib extends IbGib_V1 = IbGib_V1, TElements extends ElementsBase = any, TChildInfo extends ChildInfoBase<any> = ChildInfoBase<any>>
1100
+ extends IbGibDynamicComponentInstanceBase<TIbGib, TElements> {
1101
+ /**
1102
+ * @internal
1103
+ * @protected method that gets the project tab info for the given addr.
1104
+ *
1105
+ * creates and loads the child ibgib component, which itself loads the
1106
+ * ibgib internally (or throws) if not already loaded.
1107
+ *
1108
+ * @returns TChildInfo with fully loaded component and ibgib.
1109
+ */
1110
+ protected abstract getLoadedChildInfo({
1111
+ addr,
1112
+ ibGib,
1113
+ }: {
1114
+ addr: IbGibAddr,
1115
+ ibGib?: IbGib_V1,
1116
+ }): Promise<TChildInfo>;
1117
+
1118
+ childInfos: TChildInfo[] = [];
1119
+ get activeChildInfo(): TChildInfo | undefined {
1120
+ return this.childInfos.find(x => x.active);
1121
+ }
1122
+
1123
+ /**
1124
+ * Drives loading a child component from an {@link addr} or {@link ibGib}.
1125
+ *
1126
+ * - If a tab is already created for the ibgib and active, then does nothing.
1127
+ * - If it's already created but inactive, then activates tab and loads content
1128
+ * - if no tab, then creates it, activates it, loads content.
1129
+ *
1130
+ * To do this, creates/hydrates a concrete descendant of {@link ChildInfoBase}
1131
+ * and activates it via {@link getLoadedChildInfo}
1132
+ *
1133
+ * @see {@link ChildInfoBase.active}
1134
+ * @see {@link activeChildInfo}
1135
+ */
1136
+ public async activateIbGib({
1137
+ addr,
1138
+ ibGib,
1139
+ }: {
1140
+ addr?: IbGibAddr,
1141
+ ibGib?: IbGib_V1,
1142
+ }): Promise<void> {
1143
+ const lc = `${this.lc}[${this.activateIbGib.name}]`;
1144
+ try {
1145
+ if (logalot) { console.log(`${lc} starting... (I: 05015d78983488496dcca4fa36718725)`); }
1146
+
1147
+ while (!this.createdPromise) {
1148
+ await delay(50);
1149
+ }
1150
+ await this.createdPromise;
1151
+
1152
+ if (!this.elements) { throw new Error(`(UNEXPECTED) this.elements falsy? (E: fa221c138f211ee93c717c9dd0cf3225)`); }
1153
+ const { contentEl } = this.elements;
1154
+
1155
+ // #region init/validate
1156
+ // if (!this.metaspace) { throw new Error(`(UNEXPECTED) this.metaspace falsy? (E: 0ddb82cc0f1550518fd57b65ee5d4625)`); }
1157
+ if (!ibGib && !addr) { throw new Error(`(UNEXPECTED) both ibGib and addr falsy? (E: 529fb88738cdacb10aea87b8450f2525)`); }
1158
+ if (ibGib && addr && getIbGibAddr({ ibGib }) !== addr) { throw new Error(`(UNEXPECTED) addr !== getIbGibAddr({ibGib})? (E: c99a94d8744e3a720cdbc094d53c4e25)`); }
1159
+ addr ??= getIbGibAddr({ ibGib });
1160
+ const componentSvc = await getComponentSvc();
1161
+ // #endregion init/validate
1162
+
1163
+ /**
1164
+ * the point of this function is to populate this and make it active
1165
+ */
1166
+ let childInfo = await this.getLoadedChildInfo({ addr, ibGib });
1167
+
1168
+ if (childInfo.active) {
1169
+ console.log(`${lc} same tab already active. returning early. childInfo.addr: ${childInfo.addr} (user just clicked on the same tab) (I: e67c0d02f3143c49c7a20c82d0730225)`);
1170
+ return; /* <<<< returns early */
1171
+ }
1172
+
1173
+ // at this point, we are guaranteed to have a non-active childInfo, so
1174
+ // deactivate the old, and activate the new
1175
+ const currentlyActive = this.activeChildInfo;
1176
+ if (currentlyActive) {
1177
+ currentlyActive.childBtnEl.classList.remove('active');
1178
+ currentlyActive.active = false;
1179
+ contentEl.innerHTML = '';
1180
+ }
1181
+
1182
+ // activate the new tab
1183
+ childInfo.childBtnEl.classList.add('active');
1184
+ childInfo.childBtnEl.scrollIntoView({ behavior: 'smooth' });
1185
+
1186
+ childInfo.active = true;
1187
+
1188
+ let gib = getIbAndGib({ ibGibAddr: addr }).gib;
1189
+ let gibInfo = getGibInfo({ gib });
1190
+ let tjpGib = gibInfo.tjpGib ?? gib;
1191
+ function tabInfoSharesTjpGib(tabInfo: TChildInfo): boolean {
1192
+ let tabGib = getIbAndGib({ ibGibAddr: tabInfo.addr }).gib;
1193
+ let tabGibInfo = getGibInfo({ gib: tabGib });
1194
+ let tabTjpGib = tabGibInfo.tjpGib ?? tabGib;
1195
+ return tabTjpGib === tjpGib;
1196
+ }
1197
+ // if (!this.childInfos.some(x => x.addr === childInfo.addr)) {
1198
+ if (!this.childInfos.some(x => tabInfoSharesTjpGib(x))) {
1199
+ this.childInfos.push(childInfo);
1200
+ }
1201
+ if (!childInfo.component) { throw new Error(`(UNEXPECTED) childInfo.component falsy? should be populated by this point in code (E: 77abfd1e8cd395605d46716bd087fb25)`); }
1202
+ await componentSvc.inject({
1203
+ parentEl: contentEl,
1204
+ componentToInject: childInfo.component,
1205
+ });
1206
+
1207
+ } catch (error) {
1208
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1209
+ throw error;
1210
+ } finally {
1211
+ if (logalot) { console.log(`${lc} complete.`); }
1212
+ }
1213
+ }
1214
+
1215
+ protected abstract addChild({
1216
+ addr,
1217
+ ibGib,
1218
+ }: {
1219
+ ibGib: IbGib_V1,
1220
+ addr?: IbGibAddr,
1221
+ }): Promise<HTMLElement>;
1222
+
1223
+ }
1224
+
1225
+ export abstract class IbGibDynamicComponentInstanceBase_ParentOfTabs<TSettings extends IbGibSettings & SettingsWithTabs, TIbGib extends IbGib_V1 = IbGib_V1, TElements extends ElementsBase = any, TChildInfo extends ChildInfoBase<any> = ChildInfoBase<any>>
1226
+ extends IbGibDynamicComponentInstanceBase_Parent<TIbGib, TElements, TChildInfo> {
1227
+ protected lc: string = `[${IbGibDynamicComponentInstanceBase_ParentOfTabs.name}]`;
1228
+
1229
+ public get isBusy(): boolean {
1230
+ // add other things to indicate busy
1231
+ return this._reloadingTabs;
1232
+ }
1233
+
1234
+ protected abstract get settingsType(): SettingsType;
1235
+
1236
+ protected _reloadingTabs = false;
1237
+ protected get reloadingTabs(): boolean { return this._reloadingTabs; }
1238
+ protected set reloadingTabs(value: boolean) {
1239
+ const valueIsDifferent = value !== this._reloadingTabs;
1240
+ this._reloadingTabs = value;
1241
+ if (valueIsDifferent) {
1242
+ this.renderUI_busy(); // spins off
1243
+ }
1244
+ }
1245
+
1246
+ protected async closeTab({ ibGib }: { ibGib: IbGib_V1 }): Promise<void> {
1247
+ const lc = `${this.lc}[${this.closeTab.name}]`;
1248
+ try {
1249
+ if (logalot) { console.log(`${lc} starting... (I: e0d5f8ed67b8a7f43822fa3843fd4525)`); }
1250
+ const addrToClose = getIbGibAddr({ ibGib });
1251
+ const tjpAddrToClose = getTjpAddr({ ibGib, defaultIfNone: 'incomingAddr' });
1252
+ if (!tjpAddrToClose) { throw new Error(`(UNEXPECTED) tjpAddr false after incomingAddr default? ibGib: ${pretty(ibGib)} (E: 707988b4d22a27c1287aa5a815d88825)`); }
1253
+ const tabInfoToClose = await this.getLoadedChildInfo({ addr: addrToClose, ibGib });
1254
+
1255
+ // if it's active, activate the tab to the left/right?
1256
+
1257
+ // remove from project open tabs in settings for project ibgib
1258
+ // let projectSettings = await this.getCurrentProjectSettings();
1259
+ const settings_current = await this.getSettings<TSettings>({
1260
+ settingsType: this.settingsType,
1261
+ useCase: 'current',
1262
+ });
1263
+ if (!settings_current) { throw new Error(`(UNEXPECTED) settings_current falsy for this project? this.ibGib: ${pretty(this.ibGib)} (E: ecea08dcacd198bb38cc44a860cc6825)`); }
1264
+
1265
+ if (!settings_current.openChildTjpAddrs.includes(tjpAddrToClose)) {
1266
+ throw new Error(`${lc} (UNEXPECTED) projectSettings didn't have the tjpAddr (${tjpAddrToClose})? projectSettings: ${pretty(settings_current)} (E: genuuid)`);
1267
+ }
1268
+ let newOpenChildTjpAddrs = settings_current.openChildTjpAddrs.filter(x => x !== tjpAddrToClose);
1269
+ let newActiveChildTjpAddr: TjpIbGibAddr | undefined = undefined;
1270
+ // settings_current.openChildTjpAddrs.push(tjpAddrToClose); // ????
1271
+ if (settings_current.activeChildTjpAddr === tjpAddrToClose) {
1272
+ // get the addr just before the current one that we're closing.
1273
+ // if it doesn't exist, use the project's tjpAddr.
1274
+ if (newOpenChildTjpAddrs.length > 0) {
1275
+ // this implies that the old openChildTjpAddrs.length >= 2
1276
+ let newIndex = settings_current.openChildTjpAddrs.indexOf(tjpAddrToClose) - 1;
1277
+ if (newIndex < 0) { newIndex = 0; }
1278
+ newActiveChildTjpAddr = settings_current.openChildTjpAddrs.at(newIndex);
1279
+ } else {
1280
+ newActiveChildTjpAddr = this.tjpAddr!;
1281
+ newOpenChildTjpAddrs.push(this.tjpAddr!);
1282
+ }
1283
+ }
1284
+ const sectionName_current = await getSectionName({
1285
+ settingsType: this.settingsType,
1286
+ useCase: 'current',
1287
+ });
1288
+ const newSectionSettings = {
1289
+ ...settings_current,
1290
+ openChildTjpAddrs: newOpenChildTjpAddrs,
1291
+ };
1292
+ // if (!!newActiveChildTjpAddr) {
1293
+ // newProjectSettings.activeChildTjpAddr = newActiveChildTjpAddr;
1294
+ // }
1295
+ const metaspace = await this.getMetaspace();
1296
+ const _newSettings = await mut8Timeline({
1297
+ timeline: this.settings!.ibGib!,
1298
+ metaspace,
1299
+ mut8Opts: {
1300
+ dataToAddOrPatch: {
1301
+ sections: {
1302
+ [sectionName_current]: newSectionSettings,
1303
+ }
1304
+ },
1305
+ },
1306
+ });
1307
+
1308
+ if (tabInfoToClose.active) {
1309
+ await this.activateIbGib({ addr: newActiveChildTjpAddr });
1310
+ }
1311
+
1312
+ // physically remove component/tab btn
1313
+ this.childInfos = this.childInfos.filter(x => x.addr !== tabInfoToClose.addr);
1314
+ await this.removeTabBtn({ tabInfo: tabInfoToClose });
1315
+ // this.elements!.headerTabsEl!.removeChild(tabInfo.childBtnEl);
1316
+ } catch (error) {
1317
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1318
+ throw error;
1319
+ } finally {
1320
+ if (logalot) { console.log(`${lc} complete.`); }
1321
+ }
1322
+ }
1323
+
1324
+ protected abstract removeTabBtn({
1325
+ tabInfo,
1326
+ }: {
1327
+ tabInfo: TChildInfo,
1328
+ }): Promise<void>;
1329
+
1330
+ protected async reopenOldTabs(): Promise<void> {
1331
+ const lc = `${this.lc}[${this.reopenOldTabs.name}]`;
1332
+ try {
1333
+ if (logalot) { console.log(`${lc} starting... (I: 195e7d34b3f8b761aa78dd384011f825)`); }
1334
+
1335
+ // let settings = await this.getCurrentProjectSettings();
1336
+ const settings = await this.getSettings<TSettings>({
1337
+ settingsType: this.settingsType,
1338
+ useCase: 'current',
1339
+ });
1340
+ if (!settings) { throw new Error(`(UNEXPECTED) settings falsy? these should be initialized before now. (E: 2003ab77e01448d638216fc82aff5f25)`); }
1341
+
1342
+ this.reloadingTabs = true;
1343
+ await this.renderUI_busy();
1344
+ let currentChildTjpAddr: IbGibAddr | undefined;
1345
+ try {
1346
+ for (const childTjpAddr of settings.openChildTjpAddrs) {
1347
+ // slow kluge I think...maybe it's ok I dunno.
1348
+ currentChildTjpAddr = childTjpAddr;
1349
+ await this.activateIbGib({ addr: childTjpAddr });
1350
+ }
1351
+ } catch (error) {
1352
+ console.error(`${lc} error during activating child ibGib tabs. childTjpAddr: ${currentChildTjpAddr ?? '[unset?]'} (E: 0396b2e24d08f42ac94510bb718a1725)`);
1353
+ throw error;
1354
+ } finally {
1355
+ this.reloadingTabs = false;
1356
+ }
1357
+
1358
+ // not reloading, so now we can activate the recently active one
1359
+ await this.activateIbGib({ addr: settings.activeChildTjpAddr });
1360
+
1361
+ // await this.activateLensMode({ lensMode: settings.lensMode, skipInject: false });
1362
+ } catch (error) {
1363
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1364
+ throw error;
1365
+ } finally {
1366
+ if (logalot) { console.log(`${lc} complete.`); }
1367
+ }
1368
+ }
1369
+ }