@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,1665 @@
1
+ import {
2
+ clone,
3
+ delay,
4
+ extractErrorMsg, getTimestampInTicks, pickRandom_Letters, pretty
5
+ } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
6
+ import { UUID_REGEXP } from '@ibgib/helper-gib/dist/constants.mjs';
7
+ import { Ib, IbGibAddr, TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
8
+ import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
9
+ import { rel8 } from '@ibgib/ts-gib/dist/V1/transforms/rel8.mjs';
10
+ import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
11
+ import { GIB, IB, ROOT, ROOT_ADDR } from '@ibgib/ts-gib/dist/V1/constants.mjs';
12
+ import { mut8 } from '@ibgib/ts-gib/dist/V1/transforms/mut8.mjs';
13
+ import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
14
+ import { getGibInfo } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
15
+ import { WitnessData_V1, WitnessRel8ns_V1, } from '@ibgib/core-gib/dist/witness/witness-types.mjs';
16
+ import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs';
17
+ import { createCommentIbGib, isComment, parseCommentIb } from '@ibgib/core-gib/dist/common/comment/comment-helper.mjs';
18
+ import { LightWitnessBase_V1 } from '@ibgib/core-gib/dist/witness/light-witness-base-v1.mjs';
19
+ import { SpaceId } from '@ibgib/core-gib/dist/witness/space/space-types.mjs';
20
+ import { IbGibSpaceAny } from '@ibgib/core-gib/dist/witness/space/space-base-v1.mjs';
21
+ import { MetaspaceService } from '@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs';
22
+ import { getTjpAddr } from '@ibgib/core-gib/dist/common/other/ibgib-helper.mjs';
23
+ import { fnObs } from '@ibgib/core-gib/dist/common/pubsub/observer/observer-helper.mjs';
24
+ import { execInSpaceWithLocking, } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
25
+
26
+ import { GLOBAL_LOG_A_LOT } from '../../constants.mjs';
27
+ import {
28
+ AGENT_ATOM, AGENT_DESC_REGEXP, AGENT_NAME_REGEXP, AGENT_REL8N_NAME, DEFAULT_DESCRIPTION_AGENT,
29
+ DEFAULT_NAME_AGENT, DEFAULT_UUID_AGENT, FUNCTION_CALL_REQUEST_COMMENT_TAG,
30
+ isTextSource, TEXT_SOURCE_VALUES, TextSource,
31
+ } from './agent-constants.mjs';
32
+ import { APIFunctionInfo } from '../../api/api-types.mjs';
33
+ import { getAllFunctionInfos, } from '../../api/api-index.mjs';
34
+ import { FUNCTION_INFO_REL8N_NAME, FunctionInfoIbGib_V1, createFunctionInfoIbGib } from './function-info/function-info-one-file.mjs';
35
+ import { GeminiModel } from './gemini/gemini-constants.mjs';
36
+ import { PromptAPIResult_Gemini } from './gemini/gemini-types.mjs';
37
+ import { getGlobalMetaspace_waitIfNeeded } from '../../helpers.web.mjs';
38
+ import { updateAgentIndex } from './agent-helpers.mjs';
39
+ import { getAgentsSvc } from './agents-service-v1.mjs';
40
+ import { LiveProxyIbGib } from '../live-proxy-ibgib/live-proxy-ibgib-one-file.mjs';
41
+ import { AgentAPI, AgentModel } from './agent-types.mjs';
42
+ import { AGENT_SPECIAL_IBGIB_TYPE_PRIMARYAGENT } from '../../agent-texts/primary-agent-texts.mjs';
43
+
44
+ const logalot = GLOBAL_LOG_A_LOT;
45
+
46
+ export const DEFAULT_AGENT_DATA_V1: AgentWitnessData_V1 = {
47
+ version: '1',
48
+ uuid: DEFAULT_UUID_AGENT,
49
+ name: DEFAULT_NAME_AGENT,
50
+ description: DEFAULT_DESCRIPTION_AGENT,
51
+ classname: `AgentWitness_V1`,
52
+ icon: 'happy', // arbitrary
53
+ persistOptsAndResultIbGibs: false,
54
+ allowPrimitiveArgs: true,
55
+ catchAllErrors: true,
56
+ trace: false,
57
+
58
+ // agent-specific props
59
+ subSpaceId: '',
60
+ // purpose: '',
61
+ superSpaceId: '',
62
+ availableFunctionNameOrIds: [],
63
+ model: GeminiModel.GEMINI_2_0_FLASH,
64
+ // model: GeminiModel.GEMINI_1_5_PRO,
65
+ api: 'gemini',
66
+ type: AGENT_SPECIAL_IBGIB_TYPE_PRIMARYAGENT,
67
+ "@currentContextTjpAddr": ROOT_ADDR,
68
+ }
69
+ /**
70
+ * don't init with an empty obj. use undefined or factory_v1.firstGen blows up.
71
+ */
72
+ export const DEFAULT_AGENT_REL8NS_V1: AgentWitnessRel8ns_V1 | undefined = undefined;
73
+
74
+
75
+ /**
76
+ * @interface AgentWitnessData - Data interface for the AgentWitness.
77
+ * @extends WitnessData_V1
78
+ */
79
+ export interface AgentWitnessData_V1 extends WitnessData_V1 {
80
+ /**
81
+ * this id corresponds to what space the agent has access to as its own "internal" space.
82
+ *
83
+ * TODO: implement initialization code to create/get this space when the
84
+ * agent is created/initialized.
85
+ *
86
+ * TODO: implement an APIFunctionInfo for the agent
87
+ *
88
+ * it is possible that we will add access to other spaces in the future.
89
+ */
90
+ subSpaceId: SpaceId;
91
+ /**
92
+ * The space in which the agent's ibgib itself is saved. This is often
93
+ * (always?) different than the super space in which the agent itself
94
+ * resides.
95
+ */
96
+ superSpaceId: SpaceId;
97
+ /**
98
+ * nameOrId corresponding to the function info
99
+ */
100
+ availableFunctionNameOrIds: string[];
101
+ /**
102
+ * @see {@link AgentAPI}
103
+ */
104
+ api: AgentAPI;
105
+ /**
106
+ * @see {@link AgentModel}
107
+ */
108
+ model: AgentModel;
109
+ /**
110
+ * A more fine-grained discriminator.
111
+ */
112
+ type: string;
113
+ /**
114
+ * soft link to the current context ibgib. May be out of date, so should use
115
+ * get latest on the space (often can do this via metaspace with this
116
+ * agent's {@link superSpaceId}).
117
+ *
118
+ * This defaults to ib^gib (ROOT_ADDR), so if this is the value, then this
119
+ * has not been initialized yet and the agent needs to have their context
120
+ * set.
121
+ */
122
+ "@currentContextTjpAddr": IbGibAddr; // string
123
+ }
124
+
125
+ /**
126
+ * @interface AgentWitnessRel8ns - Rel8ns interface for the AgentWitness.
127
+ * @extends IbGibRel8ns_V1
128
+ */
129
+ export interface AgentWitnessRel8ns_V1 extends WitnessRel8ns_V1 {
130
+ /**
131
+ * @property chat - Relationships to comment ibgibs representing chat
132
+ * history for this agent.
133
+ *
134
+ * These are expected to be comment ibgibs with special additional metadata
135
+ * text in the ib that pertains to the agents {@link AgentWitness_V1}.
136
+ *
137
+ * @see {@link system}
138
+ */
139
+ chat?: IbGibAddr[];
140
+ /**
141
+ * @property system - Relationships to comment ibgibs representing the
142
+ * system prompt.
143
+ *
144
+ * This is a Gemini-specific construct that I don't know if it exists in
145
+ * other APIs. But the intent is that these are comment ibgibs to be used in
146
+ * composing any meta text that is not part of a "chat" between one or more
147
+ * users and one or more models.
148
+ *
149
+ * These are expected to be comment ibgibs with special additional metadata
150
+ * text in the ib that pertains to the agents {@link AgentWitness_V1}.
151
+ *
152
+ * @see {@link system}
153
+ */
154
+ system?: IbGibAddr[];
155
+ }
156
+
157
+ /**
158
+ * @interface AgentWitnessIbGib_V1 - Interface for an agent ibgib.
159
+ *
160
+ * @see {@link AgentWitness_V1}
161
+ */
162
+ export interface AgentWitnessIbGib_V1 extends IbGib_V1<AgentWitnessData_V1, AgentWitnessRel8ns_V1> {
163
+ }
164
+
165
+ export interface AddTextInfo {
166
+ /**
167
+ * @property text - raw comment text string to add
168
+ * @optional
169
+ */
170
+ text?: string;
171
+ /**
172
+ * @optional @property commentIbGib - existing comment to add
173
+ */
174
+ commentIbGib?: CommentIbGib_V1;
175
+ // textSrc: 'hardcoded' | 'human' | 'ai' | 'unknown';
176
+ textSrc: TextSource;
177
+ /**
178
+ * @property isSystem - If true, adds the text to the system prompt instead of chat history.
179
+ * @default false
180
+ */
181
+ isSystem?: boolean;
182
+ }
183
+
184
+ /**
185
+ * @interface AddTextsOpts - Options for adding multiple text comments.
186
+ */
187
+ export interface AddTextsOpts {
188
+ infos: AddTextInfo[];
189
+ }
190
+
191
+ export interface PromptOneOffOpts {
192
+ text: string;
193
+ /**
194
+ * ad hoc system instructions for the one off call.
195
+ */
196
+ systemInstructions: string;
197
+ }
198
+
199
+ /**
200
+ * an agent can only have one active context at any time.
201
+ *
202
+ * Really this is a timeline, so the key thing of this context ibgib is its
203
+ * temporal junction point (tjp).
204
+ */
205
+ export interface SetActiveContextOpts {
206
+ contextIbGib: IbGib_V1;
207
+ /**
208
+ * for debug purposes
209
+ */
210
+ loggingInfo?: string;
211
+ }
212
+
213
+ /**
214
+ * When composing the prompt to send to the model, this is the information that
215
+ * we build up.
216
+ */
217
+ export interface PromptInfo {
218
+ /**
219
+ * discriminator of what concrete info is contained in this object.
220
+ */
221
+ api: AgentAPI;
222
+ }
223
+
224
+
225
+ /**
226
+ * @interface {@link PromptAPIResult} - shape of the result when calling into an
227
+ * api-specific model. In general, the api will either return a string or a
228
+ * function call request with optional arg(s)
229
+ * @see {@link AgentWitness_V1.callTextAPI}
230
+ */
231
+ export type PromptAPIResult = | PromptAPIResult_Gemini;
232
+
233
+ /**
234
+ * info object containing information in an agent ib schema.
235
+ */
236
+ export interface AgentIbInfo {
237
+ /**
238
+ * should be {@link AGENT_ATOM}
239
+ */
240
+ atom: string,
241
+ name: string,
242
+ uuid: string,
243
+ type: string,
244
+ }
245
+
246
+ /**
247
+ * information encoded in the addlMetadataText part of a comment ibgib that is
248
+ * part of an agent's chat/system text.
249
+ *
250
+ * notes: long name...
251
+ */
252
+ export interface AddlMetadataTextForAgentTextInfo {
253
+ /**
254
+ * @see {@link AddTextInfo.textSrc}
255
+ */
256
+ textSrc: TextSource;
257
+ timestampInTicks: number;
258
+ /**
259
+ * if there are additional underscore-delimited metadata texts, they will be here.
260
+ */
261
+ other?: string[];
262
+ errorMsg?: string;
263
+ }
264
+
265
+ // #region helpers
266
+
267
+ /**
268
+ * creates a begin/end tag composed of the {@link tagText} paired with an
269
+ * optional random id around the given {@link contentText}. The begin/end tags
270
+ * will be on their own line with {@link contentText} on the lines between.
271
+ *
272
+ * @example
273
+ * [MY_TAG|XBDWZ begin]
274
+ * contentText
275
+ * [MY_TAG|XBDWZ end]
276
+ * @returns
277
+ */
278
+ export function taggifyForPrompt({
279
+ tagText,
280
+ contentText,
281
+ randomIdLength,
282
+ }: {
283
+ /**
284
+ * the tag itself
285
+ */
286
+ tagText: string,
287
+ /**
288
+ * text to be surrounded by the tags' begin and end markers.
289
+ */
290
+ contentText: string,
291
+ /**
292
+ * length of random characters to pair with tag. if 0 or undefined, then no
293
+ * id will be generated.
294
+ */
295
+ randomIdLength?: number | undefined,
296
+ }): string {
297
+ const lc = `[${taggifyForPrompt.name}]`;
298
+ try {
299
+ if (logalot) { console.log(`${lc} starting... (I: 94104ec059c89d4ba458d96580791d25)`); }
300
+ const fullTagText = !!randomIdLength ?
301
+ `${tagText}|${pickRandom_Letters({ count: randomIdLength })}` :
302
+ tagText;
303
+ return [
304
+ `[${fullTagText} begin]`,
305
+ contentText,
306
+ `[${fullTagText} end]`,
307
+ ].join('\n');
308
+ } catch (error) {
309
+ console.error(`${lc} ${extractErrorMsg(error)}`);
310
+ throw error;
311
+ } finally {
312
+ if (logalot) { console.log(`${lc} complete.`); }
313
+ }
314
+ }
315
+
316
+ /**
317
+ * ATOW we specify if the text is from ai or human, as well as timestampInTicks.
318
+ * @returns metadata text to be included in the comment ibgib's ib.
319
+ * @see {@link parseAddlMetadataTextForAgentText}
320
+ */
321
+ export function getAddlMetadataTextForAgentText({
322
+ textSrc,
323
+ other,
324
+ }: {
325
+ /**
326
+ * @see {@link AddTextInfo.textSrc}
327
+ */
328
+ textSrc: TextSource,
329
+ /**
330
+ * if you have other underscore-delimited text, include that here.
331
+ */
332
+ other?: string,
333
+ }): string {
334
+ const lc = `[${getAddlMetadataTextForAgentText.name}]`;
335
+ /**
336
+ * get and parse functions must **ALWAYS** match must match. If this array
337
+ * changes, change the other one.
338
+ */
339
+ return !!other ?
340
+ [textSrc, getTimestampInTicks(), other].join('_') :
341
+ [textSrc, getTimestampInTicks()].join('_');
342
+ }
343
+
344
+ /**
345
+ * ATOW we specify if the text is from ai or human, as well as timestampInTicks.
346
+ * @returns metadata text to be included in the comment ibgib's ib.
347
+ * @see {@link getAddlMetadataTextForAgentText}
348
+ */
349
+ export function parseAddlMetadataTextForAgentText({
350
+ addlMetadataText,
351
+ ifError = 'warn',
352
+ }: {
353
+ addlMetadataText: string,
354
+ ifError: 'throw' | 'warn' | 'ignore',
355
+ }): AddlMetadataTextForAgentTextInfo {
356
+ const lc = `[${getAddlMetadataTextForAgentText.name}]`;
357
+ try {
358
+ if (logalot) { console.log(`${lc} starting... (I: 89b8b19a8d785b945fe0f816df762d25)`); }
359
+
360
+ /**
361
+ * get and parse functions must **ALWAYS** match must match. If this
362
+ * array changes, change the other one.
363
+ */
364
+ const [
365
+ textSrc,
366
+ timestampInTicksStr,
367
+ ...other
368
+ ] = addlMetadataText.split('_');
369
+ if (!textSrc) { throw new Error(`addlMetadataText.textSrc falsy (E: 40bbec4269c1688ab1390fa5d5440325)`); }
370
+ if (!isTextSource(textSrc)) { throw new Error(`addlMetadataText.textSrc (${textSrc}) is unexpected value. Expected one of ${TEXT_SOURCE_VALUES} (E: 02bae41275a39210e5737548747bd825)`); }
371
+ if (!timestampInTicksStr) { throw new Error(`addlMetadataText.timestampInTicks falsy (E: 03cbbc7515a1cff1fc7c12e3947c6825)`); }
372
+ const timestampInTicks = Number.parseInt(timestampInTicksStr);
373
+ if (Number.isNaN(timestampInTicks)) { throw new Error(`invalid timestampInTicks (${timestampInTicksStr}): value should be an integer but parse is NaN (E: 9d31e3563d972c02553ce18a19a19b25)`); }
374
+ return {
375
+ textSrc,
376
+ timestampInTicks,
377
+ other: other.length > 0 ? other : undefined,
378
+ };
379
+ } catch (error) {
380
+ const errorMsg = `${lc} ${extractErrorMsg(error)}`;
381
+ switch (ifError) {
382
+ case 'ignore':
383
+ return {
384
+ textSrc: TextSource.UNKNOWN,
385
+ timestampInTicks: 0,
386
+ errorMsg: extractErrorMsg(error)
387
+ };
388
+ case 'warn':
389
+ console.warn(`${lc} ${errorMsg} (W: 3e1f4a98ad6461c9bd96462841c31b25)`)
390
+ return {
391
+ textSrc: TextSource.UNKNOWN,
392
+ timestampInTicks: 0,
393
+ errorMsg: extractErrorMsg(error)
394
+ };
395
+ default:
396
+ console.error(`${lc} ${errorMsg} (E: 6396ed44947c52adf85788e1adc22825)`);
397
+ throw new Error(errorMsg);
398
+ }
399
+ } finally {
400
+ if (logalot) { console.log(`${lc} complete.`); }
401
+ }
402
+ }
403
+
404
+ /**
405
+ * builds the agent witness' ib based on given {@link data}
406
+ * @see {@link parseAgentIb}
407
+ */
408
+ export function getAgentIb({
409
+ data,
410
+ }: {
411
+ /** agent data, should be valid */
412
+ data: AgentWitnessData_V1,
413
+ }): string {
414
+ const lc = `[${getAgentIb.name}]`;
415
+ const { name, uuid, type } = data;
416
+ if (!name) { throw new Error(`${lc} data.name falsy (E: 4c172c5b8a110ae26479b8c4006f3225)`); }
417
+ if (!uuid) { throw new Error(`${lc} data.uuid falsy (E: 67d2c79ac39e70e5ecfd1745e1fd3525)`); }
418
+ if (!type) { throw new Error(`${lc} data.type falsy (E: 53bf1f9a145a16be81296437682a7a25)`); }
419
+ const fields: string[] = [name, uuid, type];
420
+ if (fields.some(x => x.includes(' '))) { throw new Error(`invalid data. ib must not contain spaces in name, uuid, type. (E: 36a56e4685163848458be06f51d4ad25)`); }
421
+ /** getAgentIb must match parseAgentIb. If this array changes, change the other one. */
422
+ return [
423
+ AGENT_ATOM,
424
+ name,
425
+ uuid,
426
+ type,
427
+ // what else?
428
+ ].join(' ');
429
+ }
430
+
431
+ /**
432
+ * @returns parsed info from an ib
433
+ * @see {@link getAgentIb}
434
+ */
435
+ export function parseAgentIb({
436
+ ib,
437
+ }: {
438
+ ib: Ib,
439
+ }): AgentIbInfo {
440
+ /** getAgentIb must match parseAgentIb. If this array changes, change the other one. */
441
+ const [
442
+ atom,
443
+ name,
444
+ uuid,
445
+ type,
446
+ ] = ib.split(' ');
447
+ if (atom !== AGENT_ATOM) { throw new Error(`invalid ib. first term expected to e an atom: ${AGENT_ATOM} (E: 3c01d42035d2e32c4bfd5c1bf363f725)`); }
448
+ if (!name) { throw new Error(`invalid ib. name falsy in agent ib (E: 8b494c544f05b8ef9c866078b761a725)`); }
449
+ if (!uuid) { throw new Error(`invalid ib. uuid falsy in agent ib (E: aba195db3ddcb000324ebed15351b725)`); }
450
+ if (!type) { throw new Error(`invalid ib. type falsy in agent ib (E: 8c814772394ae76342f95e885570c325)`); }
451
+ return { atom, name, uuid, type };
452
+ }
453
+
454
+ /**
455
+ * Validates a comment ibgib to ensure that it is usable in an agent witness
456
+ * context, especially that it includes the expected metadata format in its
457
+ * `ib`.
458
+ *
459
+ * @param {CommentIbGib_V1} ibGib - The comment ibgib to validate.
460
+ * @returns {string[]} An array of error messages if validation fails, or an empty array if no errors.
461
+ */
462
+ export async function validateAgentWitnessCommentIbGib({
463
+ ibGib,
464
+ }: {
465
+ ibGib: CommentIbGib_V1,
466
+ }): Promise<string[]> {
467
+ const lc = `[${validateAgentWitnessCommentIbGib.name}]`;
468
+ try {
469
+ if (logalot) { console.log(`${lc} starting... (I: f9a733a5a05b7f7494836d86a79e2d25)`); }
470
+
471
+ const errors: string[] = await validateIbGibIntrinsically({ ibGib }) ?? [];
472
+
473
+ if (!isComment({ ibGib })) {
474
+ errors.push(`${lc} not a comment ibgib (E: 08676d94c698c6e42e6c35e94a58f125)`);
475
+ return errors; /* returns early */
476
+ }
477
+
478
+ const { safeIbCommentMetadataText: addlMetadataText } = parseCommentIb({ ib: ibGib.ib });
479
+
480
+ if (addlMetadataText) {
481
+ const addlMetaInfo = parseAddlMetadataTextForAgentText({
482
+ addlMetadataText,
483
+ ifError: 'warn'
484
+ });
485
+ if (addlMetaInfo.errorMsg) {
486
+ errors.push(`${lc} could not parse addlMetadataText: ${addlMetaInfo.errorMsg} (E: e178265c33e5e94947a02c1f9d6a7425)`);
487
+ }
488
+ } else {
489
+ errors.push(`${lc} addlMetadataText falsy. this implies something is incorrect with the comment's ib, as we expect agent comments to have certain metadata (e.g. textSrc). See AgentWitness_V1 (and data interface) for more info. (E: 7c3c41c973a67256c432604666106b25)`);
490
+ }
491
+
492
+ return errors;
493
+ } catch (error) {
494
+ console.error(`${lc} ${extractErrorMsg(error)}`);
495
+ throw error;
496
+ } finally {
497
+ if (logalot) { console.log(`${lc} complete.`); }
498
+ }
499
+ }
500
+
501
+
502
+
503
+ // #endregion helpers
504
+
505
+
506
+ /**
507
+ * @extends LightWitnessBase_V1<AgentWitnessData_V1, AgentWitnessRel8ns_V1>
508
+ *
509
+ * ## notes
510
+ *
511
+ * This is far from complete. I don't know about performance, but it feels like
512
+ * what we need to add:
513
+ *
514
+ * * initialization
515
+ * * an agent should have a reference to the ibgib metaspace, as well as the agent's working local space.
516
+ * * if no local space exists yet, one should be created.
517
+ * * we will have to create an index ("special ibgib") that tracks our agents
518
+ */
519
+ export abstract class AgentWitness_V1<TAPIModel, TPromptInfo extends PromptInfo, TPromptResult extends PromptAPIResult>
520
+ extends LightWitnessBase_V1<AgentWitnessData_V1, AgentWitnessRel8ns_V1>
521
+ // extends WitnessWithContextBase_V1<
522
+ // IbGibData_V1, IbGibRel8ns_V1, IbGib_V1, // options
523
+ // IbGibData_V1, IbGibRel8ns_V1, IbGib_V1, // results
524
+ // AgentWitnessData_V1,
525
+ // AgentWitnessRel8ns_V1
526
+ // >
527
+ implements AgentWitnessIbGib_V1 {
528
+ protected lc: string = `[${AgentWitness_V1.name}]`;
529
+
530
+ protected availableFunctions: Map<string, APIFunctionInfo> = new Map();
531
+ protected commentIbGibs_system: CommentIbGib_V1[] = [];
532
+ protected commentIbGibs_chat: CommentIbGib_V1[] = [];
533
+
534
+ protected _metaspace: MetaspaceService | undefined;
535
+ // /**
536
+ // * public helper to set the metaspace
537
+ // * @param metaspace
538
+ // */
539
+ // setMetaspace(metaspace: MetaspaceService): void {
540
+ // if (this._metaspace) { throw new Error(`(UNEXPECTED) this.metaspace already set? (E: 60062ee8c69e773b96f8ddc38f227b25)`); }
541
+ // this._metaspace = metaspace;
542
+ // }
543
+
544
+ /**
545
+ * provider function for api key.
546
+ */
547
+ fnGetAPIKey: () => Promise<string> = () => { return Promise.reject(`not implemented. you need to set this after initializing the agent. (E: a14cbe903d08821126bbbb1d063d9825)`); }
548
+
549
+ /**
550
+ * convenience getter for this.data.name
551
+ */
552
+ get name(): string { return this.data?.name ?? ''; }
553
+
554
+ /**
555
+ * convenience getter for this.data.name
556
+ */
557
+ get uuid(): string { return this.data?.uuid ?? ''; }
558
+
559
+ protected _genAI: TAPIModel | undefined;
560
+
561
+ /**
562
+ * @protected
563
+ * @property transientDecompressionPromptText - A temporary string that is
564
+ * added to the prompt on the next LLM call ONLY, i.e. for a single prompt.
565
+ *
566
+ * This should NOT be part of any text history, but is rather a temporary
567
+ * way of including text in a chat in a one-off manner.
568
+ *
569
+ * ## driving use case
570
+ *
571
+ * We're using this right now in relation with Function Call Requests from
572
+ * this agent's model. We don't want to spam the context window with the
573
+ * details of these function calls, but sometimes the model needs the
574
+ * results of these functions.
575
+ */
576
+ protected transientDecompressionPromptText: string | undefined;
577
+
578
+ /**
579
+ * @property fnOutputText - A property on the AgentWitness_V1 that provides a way to output text.
580
+ *
581
+ * Default implementation to do nothing. This is to avoid a null pointer.
582
+ * ATOW (01/2025) This is a hack right now to get feedback from the agent that is not a function call.
583
+ */
584
+ fnOutputText: (textResponse: string) => void = (tr) => { console.log(`${this.lc}[fnOutputText] this hack does nothing by default. set this to do something when text is returned by the model LLM. textResponse: ${tr} (W: 3007e5d69dafdd7e42157fa7370d7f25)`) }
585
+
586
+ // protected instanceId: string;
587
+
588
+ /**
589
+ * we need this agent witness to basically update as a singleton. enforcing
590
+ * singleton instances of agents is difficult even just locally, but
591
+ * impossible when we consider that we may have multiple tabs/apps sharing
592
+ * some space.
593
+ *
594
+ * So instead, we'll try having multiple witness instances wrapping the
595
+ * proxy.
596
+ */
597
+ protected ibGibProxy: LiveProxyIbGib<AgentWitnessIbGib_V1> | undefined;
598
+
599
+ constructor(initialData?: AgentWitnessData_V1, initialRel8ns?: AgentWitnessRel8ns_V1) {
600
+ super(initialData, initialRel8ns);
601
+ this.instanceId = pickRandom_Letters({ count: 32 });
602
+ }
603
+
604
+ protected override async validateThis(): Promise<string[]> {
605
+ const lc = `${this.lc}[${this.validateThis.name}]`;
606
+ try {
607
+ if (logalot) { console.log(`${lc} starting... (I: 641e211473fc54d5a9ebb4ea44944d25)`); }
608
+ const errors = await super.validateThis();
609
+
610
+ // todo: refactor this into a non-class-method validation helper function for data
611
+ if (this.data) {
612
+ if (!this.data?.subSpaceId) { errors.push(`agent.data.subSpaceId falsy (E: d4ea57fd6b1c5cbc1e18a084de2f7725)`) }
613
+ if (!this.data?.subSpaceId.match(UUID_REGEXP)) {
614
+ errors.push(`agent.data.subSpaceId must match regexp: ${UUID_REGEXP}. (E: f381eff533aa3f4713316f93f7f1dc25)`);
615
+ }
616
+
617
+ if (this.data.name) {
618
+ if (!this.data.name.match(AGENT_NAME_REGEXP)) {
619
+ errors.push(`agent name must match regexp: ${AGENT_NAME_REGEXP}`);
620
+ }
621
+ } else {
622
+ errors.push(`agent name falsy (E: 1351325107e5ac5ea6b7b789b73de125)`);
623
+ }
624
+
625
+ if (this.data.description) {
626
+ if (!this.data.description.match(AGENT_DESC_REGEXP)) {
627
+ errors.push(`agent description must match regexp: ${AGENT_DESC_REGEXP}`);
628
+ }
629
+ }
630
+
631
+ // todo: add validation for available functions
632
+ // todo: add other validation
633
+ // todo: break out data validation and rel8ns validation into separate functions
634
+ } else {
635
+ errors.push(`this.data falsy (E: f5f151e11b12cad814b37ecad7c74a25)`)
636
+ }
637
+
638
+ return errors;
639
+ } catch (error) {
640
+ console.error(`${lc} ${extractErrorMsg(error)}`);
641
+ throw error;
642
+ } finally {
643
+ if (logalot) { console.log(`${lc} complete.`); }
644
+ }
645
+ }
646
+
647
+ protected override async initialize(): Promise<void> {
648
+ const lc = `${this.lc}[${this.initialize.name}]`;
649
+ try {
650
+ if (logalot) { console.log(`${lc} starting... (I: ce38519ac4bef52844a558fe31cda825)`); }
651
+ await super.initialize();
652
+
653
+ // I'm not sure how to handle metaspace init...for now, it is up to
654
+ // a factory function
655
+ this._metaspace = await getGlobalMetaspace_waitIfNeeded();
656
+
657
+
658
+ const ibGibProxy = new LiveProxyIbGib<AgentWitnessIbGib_V1>();
659
+ await ibGibProxy.initialized;
660
+ if (!ibGibProxy.contextUpdated$) {
661
+ throw new Error(`(UNEXPECTED) ibGibProxy.contextUpdated$ falsy? (E: e8840870af18091e6e4d52490ddca825)`);
662
+ }
663
+ ibGibProxy.contextUpdated$.subscribe(fnObs({
664
+ next: async (nextIbGib) => {
665
+ // new agent dto
666
+ const lcNext = `${lc}[ibGibProxy.contextUpdated$][next]`;
667
+ if (logalot) { console.log(`${lcNext} nextIbGib: ${pretty(nextIbGib)} (I: 96c846357b94fda2cefa615aed88c325)`); }
668
+ await this.handleContextUpdated();
669
+ },
670
+ error: async (e) => {
671
+ debugger; // error in component.ibGibProxy.contextUpdated$ observable?
672
+ console.error(`${lc}[ibGibProxy.contextUpdated$][error] what up? ${extractErrorMsg(e)}`);
673
+ },
674
+ }));
675
+
676
+ // while (!this._metaspace) {
677
+ // console.log(`${lc} this.metaspace falsy for instance ${this.instanceId} (W: 3a89c85b6bb34c1c53a92ded9f66a925)`);
678
+ // await delay(30);
679
+ // }
680
+
681
+ // this will populate the properties that are driven by data/rel8ns,
682
+ // e.g., availableFunctions, commentIbGibs_system/chat, etc.
683
+ if (this.ib && this.gib && this.data) {
684
+ const dto = this.toIbGibDto();
685
+ await this.loadIbGibDto(dto);
686
+ const space = await this._metaspace.getLocalUserSpace({
687
+ localSpaceId: dto.data?.superSpaceId,
688
+ });
689
+ if (!space) { throw new Error(`couldn't get local space with agent.data.superSpaceId (${dto.data?.superSpaceId})? (E: 0fc1b8a8ffa26f39d8a15218ec818725)`); }
690
+ await this.ibGibProxy?.setWrappedIbGib({ ibGib: dto, space });
691
+ } else {
692
+ // this happens when you just new up empty ctor, e.g. new
693
+ // AgentWitnessGemini_V1(), so the caller will be responsible
694
+ // for calling loadIbGibDto
695
+ if (logalot) { console.log(`${lc} agent is "empty". not loading dto at this time, caller is responsible for calling loadIbGibDto (I: 06dba19d74d5695fe7d1957889283725)`); }
696
+ }
697
+ } catch (error) {
698
+ console.error(`${lc} ${extractErrorMsg(error)}`);
699
+ throw error;
700
+ } finally {
701
+ if (logalot) { console.log(`${lc} complete.`); }
702
+ }
703
+ }
704
+
705
+ /**
706
+ * loads the new context (agent witness ibgib) if it's different than what
707
+ * is already loaded in this agent instance.
708
+ */
709
+ protected async handleContextUpdated(): Promise<void> {
710
+ const lc = `${this.lc}[${this.handleContextUpdated.name}]`;
711
+ try {
712
+ if (!this.ibGibProxy) { throw new Error(`(UNEXPECTED) this.ibGibProxy falsy but we're within handleContextUpdated handler? (E: a88fa85e8f27bd7f72c207389ebfbc25)`); }
713
+ if (!this.ibGibProxy.ibGib) {
714
+ throw new Error(`(UNEXPECTED) this.ibGibProxy.ibGib falsy but we're within the handleContextUpdated handler? (E: ca60b8f0a60a3e3d652c3018102d1825)`);
715
+ }
716
+ debugger; // want to see this early runs
717
+ if (!this.gib) {
718
+ debugger; // error state? this.gib falsy? want to see this
719
+ console.error(`${lc} not sure if error, but this.gib is falsy when we get a new context down the pipeline? (E: 8501d8aee4db7b8461587f38f0bbb125)`);
720
+ }
721
+ if (getIbGibAddr({ ibGib: this }) !== getIbGibAddr({ ibGib: this.ibGibProxy.ibGib })) {
722
+ const nProxy = this.ibGibProxy!.ibGib!.data!.n ?? 0;
723
+ const nThis = this.data?.n ?? 0;
724
+ if (nProxy <= nThis) {
725
+ debugger; // no change but different address?
726
+ console.error(`${lc} issue with "new" proxy context and the current this.data.n with different addresses. divergent timelines? (E: 15c698eb4488cbae2db0e778fec15825)`)
727
+ }
728
+ // we have not loaded the proxy's new ibGib
729
+ await this.loadIbGibDto(this.ibGibProxy.ibGib);
730
+ await delay(200); // hack to reduce the possibility of the proxy not updating elsewhere
731
+ } else {
732
+ // already loaded this ibGib, i.e., context updated is not new
733
+ console.error(`${lc} ibgibProxy new context is no different than current. this is NOT necessarily an error, I just want to see this when it happens. nothing is being done here, we're just not loading the "new" ibgib dto. (E: eff668b2e858ded448366d58e4dd6825)`)
734
+ }
735
+ } catch (error) {
736
+ console.error(`${lc} ${extractErrorMsg(error)}`);
737
+ throw error;
738
+ }
739
+ }
740
+
741
+ // protected override async handleContextUpdate({ update }: { update: IbGibTimelineUpdateInfo; }): Promise<void> {
742
+ // const lc = `${this.lc}[${this.handleContextUpdate.name}]`;
743
+ // try {
744
+ // if (logalot) { console.log(`${lc} starting... (I: 86abc8464278b3dcb8d078b830853825)`); }
745
+ // // super.handleContextUpdate // to nav into the super function
746
+ // super.handleContextUpdate
747
+ // debugger; // just want to see if this is hit on updates?
748
+ // } catch (error) {
749
+ // console.error(`${lc} ${extractErrorMsg(error)}`);
750
+ // throw error;
751
+ // } finally {
752
+ // if (logalot) { console.log(`${lc} complete.`); }
753
+ // }
754
+ // }
755
+
756
+ /**
757
+ * each agent has access to its own local ibgib space for its internal contents. this gets the local
758
+ * space that corresponds to the agent's spaceId, or if it does not already
759
+ * exist, it creates the space (and updates the bootstrap).
760
+ * @returns space object that the agent will use as its local space.
761
+ *
762
+ * todo: refactor this with options to possibly return other spaces as well (metaspace, subSpace, superSpace). if options is undefined, do existing behavior of getting only the subspace
763
+ */
764
+ protected async getSubSpace(): Promise<IbGibSpaceAny> {
765
+ const lc = `[${this.getSubSpace.name}]`;
766
+ try {
767
+ if (logalot) { console.log(`${lc} starting... (I: a2ec2c5e8f5fdf95c8c571b2b1b9e925)`); }
768
+ // await this.initialized; // what if this fn is called within initialize?
769
+ const { _metaspace: metaspace } = this;
770
+ if (!metaspace) { throw new Error(`(UNEXPECTED) this.metaspace falsy? after init this.metaspace is expected to be set. (E: 4519a8feaf4489389be679598f274425)`); }
771
+ let space = await metaspace.getLocalUserSpace({
772
+ localSpaceId: this.data!.subSpaceId,
773
+ });
774
+ if (!space) {
775
+ const validationErrors = await this.validateThis();
776
+ if (validationErrors.length > 0) { throw new Error(`this agent has validation errors: ${validationErrors} (E: 9a0c6125cf89789ddb1610cf5a752225)`); }
777
+ if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: 06e30e1d53fd4935333c7cf7e10db425)`); }
778
+ space = await metaspace.createLocalSpaceAndUpdateBootstrap({
779
+ allowCancel: false,
780
+ zeroSpace: metaspace.zeroSpace,
781
+ spaceName: this.name + this.uuid.substring(0, 5), // arbitrary
782
+ createBootstrap: false,
783
+ });
784
+ }
785
+ if (!space) { throw new Error(`(UNEXPECTED) space still falsy after creating locally? (E: 037ef1e6f54a675d0367227fdae16525)`); }
786
+ return space;
787
+ } catch (error) {
788
+ console.error(`${lc} ${extractErrorMsg(error)}`);
789
+ throw error;
790
+ } finally {
791
+ if (logalot) { console.log(`${lc} complete.`); }
792
+ }
793
+ }
794
+
795
+ /**
796
+ * helper that retrieves this agent's local space given by
797
+ * this.data.superSpaceId
798
+ */
799
+ protected async getSuperSpace(): Promise<IbGibSpaceAny> {
800
+ const lc = `[${this.getSuperSpace.name}]`;
801
+ try {
802
+ if (logalot) { console.log(`${lc} starting... (I: 55fba9bcaf9539cc2219e03cda200525)`); }
803
+ // await this.initialized; // what if this fn is called within initialize?
804
+ const { _metaspace: metaspace } = this;
805
+ if (!metaspace) { throw new Error(`(UNEXPECTED) this.metaspace falsy? after init this.metaspace is expected to be set. (E: 107f670c99832c573a7e5de18d58c325)`); }
806
+ if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: a4341b8753678fcba7877b6319769b25)`); }
807
+ if (!this.data.superSpaceId) { throw new Error(`(UNEXPECTED) this.data.superSpaceId falsy? (E: 0429fe44df5b56bf2ac67d38cde56325)`); }
808
+
809
+ const space = await metaspace.getLocalUserSpace({
810
+ localSpaceId: this.data!.superSpaceId,
811
+ });
812
+ if (!space) { throw new Error(`(UNEXPECTED) superSpace falsy? this.data.superSpaceId: ${this.data.superSpaceId} (E: fd9435212e8b87e4b60034bf9e797f25)`); }
813
+
814
+ return space;
815
+ } catch (error) {
816
+ console.error(`${lc} ${extractErrorMsg(error)}`);
817
+ throw error;
818
+ } finally {
819
+ if (logalot) { console.log(`${lc} complete.`); }
820
+ }
821
+ }
822
+
823
+ abstract addTexts(opts: AddTextsOpts): Promise<CommentIbGib_V1[]>;
824
+ /**
825
+ * quick and dirty, does not
826
+ */
827
+ abstract promptOneOff(opts: PromptOneOffOpts): Promise<string | undefined>;
828
+
829
+ protected _activeContext: LiveProxyIbGib | undefined = undefined;
830
+
831
+ /**
832
+ * Updates the agent.data to have a soft link to an ibgib's timeline (via
833
+ * its tjp addr) that defines the agent's current context.
834
+ *
835
+ * This is kinda like describing what "directory" the agent is "in", though
836
+ * remember, ibgib's contain both intrinsic meaning (like a file) and
837
+ * extrinsic meaning (like a folder/dir).
838
+ *
839
+ * @see {@link SetActiveContextOpts}
840
+ */
841
+ async setActiveContext(opts: SetActiveContextOpts): Promise<void> {
842
+ const lc = `${this.lc}[${this.setActiveContext.name}]`;
843
+ try {
844
+ if (logalot) { console.log(`${lc} starting... (I: genuuid)`); }
845
+ const { contextIbGib, loggingInfo } = opts;
846
+
847
+ // #region init/validation
848
+
849
+ if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: ab5377fda6bc324638722d9832bab925)`); }
850
+ if (!contextIbGib) { throw new Error(`(UNEXPECTED) contextIbGib falsy? (E: 694525e512cfdd12c14e1213dbaab925)`); }
851
+ if (!contextIbGib.data) { throw new Error(`(UNEXPECTED) contextIbGib.data falsy? (E: f337252a23c822bcbd76144540050825)`); }
852
+ const contextIbGibAddr = getIbGibAddr({ ibGib: contextIbGib });
853
+ const contextTjpAddr = getTjpAddr({ ibGib: contextIbGib });
854
+ if (!contextTjpAddr) { throw new Error(`(UNEXPECTED) contextTjpAddr falsy? contextIbGib (${contextIbGibAddr}) is expected to be a living ibgib with a tjp address (i.e. a timeline). This means it should have a rel8ns.tjp or data.isTjp should be truthy. (E: d756d1e862d2cccfed4a5807737e9a25)`); }
855
+
856
+ // #endregion init/validation
857
+
858
+ // update this agent's internals if applicable
859
+
860
+ if (this.data?.['@currentContextTjpAddr'] === contextTjpAddr) {
861
+ if (logalot) { console.log(`${lc} this.data.@currentContextTjpAddr already set to the same addr. (I: 9f0d58ec65eee3ca2aec528f1328c325)`); }
862
+ // return; /* <<<< returns early */
863
+ } else {
864
+ // we're guaranteed to have a different context
865
+ await this.mut8Self({
866
+ dataToAddOrPatch: {
867
+ "@currentContextTjpAddr": contextTjpAddr,
868
+ }
869
+ });
870
+ }
871
+
872
+ // subscribe to updates to context
873
+ if (!this._activeContext) {
874
+ // create the proxy itself
875
+ const proxy = new LiveProxyIbGib();
876
+ await proxy.initialized;
877
+
878
+ // subscribe to context updates - these are just when newer
879
+ // versions come down the pipe, which i don't think we're too
880
+ // interested in at the moment. we're more interested in the new
881
+ // children
882
+ const lcContextUpdated = `${lc}[contextUpdated]`;
883
+ if (!proxy.contextUpdated$) { throw new Error(`(UNEXPECTED) proxy.contextUpdated$ falsy? (E: 868c5e3bf025baa6d1ae727ab1160c25)`); }
884
+ proxy.contextUpdated$.subscribe(fnObs({
885
+ next: async (nextIbGib) => {
886
+ console.log(`${lcContextUpdated}[next] nextIbGib: ${pretty(nextIbGib)}`);
887
+ },
888
+ complete: async () => {
889
+ debugger; // complete? in agent subscribe context update
890
+ throw new Error(`${lcContextUpdated}[complete] (UNEXPECTED) agent active context subscription complete? i honestly don't know if this hits. (E: 786d26ab23e4313db7ae2e08c70a7425)`);
891
+ },
892
+ error: async (e) => {
893
+ debugger; // error in agent subscribe context update
894
+ console.error(`${lcContextUpdated}[error] ${extractErrorMsg(e)}`);
895
+ },
896
+ }));
897
+
898
+ // subscribe to new children to add text/pics to the agent's
899
+ // awareness (context window/dynamic prompt when next prompt
900
+ // occurs) and act accordingly
901
+ const lcNewContextChild = `${lc}[newContextChild]`;
902
+ if (!proxy.newContextChild$) { throw new Error(`(UNEXPECTED) proxy.newContextChild$ falsy? (E: 123cf5624c3d2a6308aafc0c41f8a925)`); }
903
+ proxy.newContextChild$.subscribe(fnObs({
904
+ next: async (newChild) => {
905
+ // await delay(500); // magic delay temporary hack due to answering before the new child propagates to other event listeners on the timeline. namely, when user inputs text, it adds to the context ibgib. then this agent hears that and then imediately adds to the context ibgib before the chronologys has a chance to answer. shouldn't matter, but what can ya do on no fing funding. looks like this delay still happens
906
+ console.log(`${lcNewContextChild}[next] newChild: ${pretty(newChild)}`);
907
+ if (!newChild.data) { throw new Error(`newChild.data falsy? (E: a654134a2695c176971b0cd1426ced25)`); }
908
+ if (isComment({ ibGib: newChild })) {
909
+ /**
910
+ * idempotent, otherwise we get repeats
911
+ */
912
+ const alreadyDoneCommentTjpAddrs = this.commentIbGibs_chat.map(x => {
913
+ return getTjpAddr({ ibGib: x }) ?? getIbGibAddr({ ibGib: x });
914
+ });
915
+ const newChildTjpAddr = getTjpAddr({ ibGib: newChild }) ?? getIbGibAddr({ ibGib: newChild });
916
+ if (alreadyDoneCommentTjpAddrs.includes(newChildTjpAddr)) {
917
+ console.log(`${lc} already did this comment (${newChildTjpAddr}) (I: bce18642bb9babeb553e6188d7ae2825)`);
918
+ return; /* <<<< returns early */
919
+ }
920
+ const { safeIbCommentMetadataText } = parseCommentIb({ ib: newChild.ib });
921
+
922
+ const { textSrc, } = parseAddlMetadataTextForAgentText({
923
+ addlMetadataText: safeIbCommentMetadataText ?? '',
924
+ ifError: 'warn',
925
+ });
926
+ const isSystem = newChild.data.text.startsWith('system: ');
927
+ await this.addTexts({
928
+ infos: [
929
+ {
930
+ textSrc: textSrc ?? TextSource.UNKNOWN,
931
+ commentIbGib: newChild as CommentIbGib_V1,
932
+ isSystem,
933
+ }
934
+ ]
935
+ });
936
+ // trigger doPrompt? for now we'll just do it when
937
+ // the text comes directly from a human, but in the
938
+ // future we either should pass this through a
939
+ // smaller model or have some defined triggers like
940
+ // if the text contains "@[agent.data.name]"
941
+ if (textSrc === TextSource.HUMAN) {
942
+ if (!isSystem) {
943
+ await this.doPrompt();
944
+ } else {
945
+ console.log(`${lc} system prompt has been modified. (I: d21c26f0a3fa12e2a874925882f39825)`);
946
+ }
947
+ }
948
+ } else {
949
+ console.warn(`${lcNewContextChild} non-comment newChild. probably not a warning proper, but at this stage I'm only expecting comments ignoring... (W: e664834af4791ddcde19bfd4f7063e25)`);
950
+ }
951
+ },
952
+ complete: async () => {
953
+ debugger; // complete? in agent newContextChild
954
+ throw new Error(`${lcNewContextChild}[complete] (UNEXPECTED) agent active context subscription complete? i honestly don't know if this hits. (E: 88202d1f7554330d3dfca0237c2d6525)`);
955
+ },
956
+ error: async (e) => {
957
+ debugger; // error in agent newContextChild
958
+ console.error(`${lcNewContextChild}[error] ${extractErrorMsg(e)}`);
959
+ },
960
+ }));
961
+
962
+ // set the backing property
963
+ this._activeContext = proxy;
964
+
965
+ // is this enough if the proxy changes its internal wrapped ibgib?
966
+ }
967
+ if (!this._activeContext) {
968
+ throw new Error(`(UNEXPECTED) this._activeContext still falsy after we just initialized it? (E: 584f2f672b9ae7c979dde693eafb7a25)`);
969
+ }
970
+ await this._activeContext.setWrappedIbGib({ ibGib: contextIbGib });
971
+
972
+ } catch (error) {
973
+ console.error(`${lc} ${extractErrorMsg(error)}`);
974
+ throw error;
975
+ } finally {
976
+ if (logalot) { console.log(`${lc} complete.`); }
977
+ }
978
+ }
979
+
980
+ // protected async subscribeToContextUpdates(): Promise<void> {
981
+ // const lc = `[${this.subscribeToContextUpdates.name}]`;
982
+ // try {
983
+ // if (logalot) { console.log(`${lc} starting... (I: 871a18a5a0abd7e1177fde3270c12425)`); }
984
+
985
+ // } catch (error) {
986
+ // console.error(`${lc} ${extractErrorMsg(error)}`);
987
+ // throw error;
988
+ // } finally {
989
+ // if (logalot) { console.log(`${lc} complete.`); }
990
+ // }
991
+ // }
992
+
993
+ async updateName({ name }: { name: string }): Promise<void> {
994
+ const lc = `${this.lc}[${this.updateName.name}]`;
995
+ try {
996
+ if (logalot) { console.log(`${lc} starting... (I: genuuid)`); }
997
+
998
+ if (name === this.name) {
999
+ console.warn(`${lc} agent (${this.uuid}) already is named ${name}. returning early... (W: genuuid)`);
1000
+ return; /* <<<< returns early */
1001
+ } else {
1002
+ if (AGENT_NAME_REGEXP.test(name)) {
1003
+ // we're guaranteed to have a different name
1004
+ await this.mut8Self({
1005
+ dataToAddOrPatch: {
1006
+ name: name,
1007
+ }
1008
+ });
1009
+ } else {
1010
+ throw new Error(`invalid name ${name}. must match regexp: ${AGENT_NAME_REGEXP.source} (E: 507a2bfc0aaa60bd7bb608d253239e25)`);
1011
+ }
1012
+ }
1013
+ } catch (error) {
1014
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1015
+ throw error;
1016
+ } finally {
1017
+ if (logalot) { console.log(`${lc} complete.`); }
1018
+ }
1019
+ }
1020
+
1021
+ async updateAvailableFunctions({
1022
+ availableFunctions,
1023
+ }: {
1024
+ availableFunctions: APIFunctionInfo[],
1025
+ }): Promise<void> {
1026
+ const lc = `${this.lc}[${this.updateAvailableFunctions.name}]`;
1027
+ try {
1028
+ if (logalot) { console.log(`${lc} starting... (I: 68f1bfa343925a657f8c0545b191c725)`); }
1029
+
1030
+ // // first prune existing available functions...
1031
+ // await this.pruneDeprecatedAvailableFunctions_ifApplicable({
1032
+ // dto: this.toIbGibDto() as AgentWitnessIbGib_V1,
1033
+ // metaspace: this._metaspace!,
1034
+ // superSpace: await this.getSuperSpace(),
1035
+ // });
1036
+
1037
+ const functionsToAdd: APIFunctionInfo[] = [];
1038
+ // const removedFunctions: string[] = []; // implement later as needed
1039
+
1040
+ for (const incomingFn of availableFunctions) {
1041
+ if (!this.availableFunctions.has(incomingFn.nameOrId)) {
1042
+ const functionInfo = getAllFunctionInfos().get(incomingFn.nameOrId);
1043
+ if (functionInfo) {
1044
+ functionsToAdd.push(functionInfo);
1045
+ } else {
1046
+ console.error(`(UNEXPECTED) ${incomingFn} function not registered with getAllFunctionInfos()? skipping adding this function to the agent... (E: e860fe13c02677b274ac0e7df2587a25)`);
1047
+ continue;
1048
+ }
1049
+ }
1050
+ }
1051
+
1052
+ if (functionsToAdd.length > 0) {
1053
+ console.log(`${lc} adding newly found functions to agent: ${functionsToAdd.map(x => x.nameOrId)}. (I: ab2b0ae6a62b3ced6a5f1e2e8cec4f25)`)
1054
+ await this.addAvailableFunctions(functionsToAdd);
1055
+ }
1056
+ } catch (error) {
1057
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1058
+ throw error;
1059
+ } finally {
1060
+ if (logalot) { console.log(`${lc} complete.`); }
1061
+ }
1062
+ }
1063
+
1064
+ /**
1065
+ * I'm taking this out temporarily because it's non-trivial to figure out
1066
+ * where/when this should happen. We can just do the deprecated list and when
1067
+ * we go to populate the actual availble function infos, we check the
1068
+ * deprecated list and skip the ones that are deprecated. So in the agent's
1069
+ * dto ibgib (data.availableFunctions) the function name will still be
1070
+ * listed, but at runtime it will not be populated.
1071
+ */
1072
+ // protected async pruneDeprecatedAvailableFunctions_ifApplicable({
1073
+ // dto,
1074
+ // metaspace,
1075
+ // superSpace,
1076
+ // }: {
1077
+ // dto: AgentWitnessIbGib_V1,
1078
+ // metaspace: MetaspaceService,
1079
+ // superSpace: IbGibSpaceAny,
1080
+ // }): Promise<void> {
1081
+ // const lc = `${this.lc}[${this.pruneDeprecatedAvailableFunctions_ifApplicable.name}]`;
1082
+ // try {
1083
+ // if (logalot) { console.log(`${lc} starting... (I: e6d5f13a3c4892f5c878239744a00825)`); }
1084
+
1085
+ // if (!dto.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: 83c531982725611401ebe3ecc7d1c825)`); }
1086
+ // if (!dto.data.availableFunctionNameOrIds || dto.data.availableFunctionNameOrIds.length === 0) {
1087
+ // console.warn(`${lc} dto agent (${getIbGibAddr({ ibGib: dto })} has falsy/empty availableFunctionNameOrIds? maybe this is normal, but here writing this code, i think this seems unexpected. (W: 6a15d8e2fdc8e5d38a9045d39bb06825))`);
1088
+ // return; /* <<<< returns early */
1089
+ // }
1090
+
1091
+ // // deprecated, so modify the data and reload the dto
1092
+ // const deprecatedNameOrIds = dto.data.availableFunctionNameOrIds.filter(x => DeprecatedFunctionInfoNames.includes(x));
1093
+ // if (deprecatedNameOrIds.length > 0) {
1094
+ // console.log(`${lc} deprecatedNameOrIds.length > 0, so we're going to mut8 this agent to exclude these.`);
1095
+ // const newAgentIbGibDto = await mut8Timeline({
1096
+ // timeline: dto,
1097
+ // mut8Opts: {
1098
+ // dataToAddOrPatch: {
1099
+ // availableFunctionNameOrIds:
1100
+ // dto.data.availableFunctionNameOrIds.filter(x => !deprecatedNameOrIds.includes(x)),
1101
+ // }
1102
+ // },
1103
+ // metaspace,
1104
+ // space: superSpace,
1105
+ // timelineIndexInfo: {
1106
+ // rel8nName: AGENT_REL8N_NAME,
1107
+ // type: dto.data.type,
1108
+ // },
1109
+ // });
1110
+ // await super.loadIbGibDto(newAgentIbGibDto);
1111
+ // }
1112
+ // } catch (error) {
1113
+ // console.error(`${lc} ${extractErrorMsg(error)}`);
1114
+ // throw error;
1115
+ // } finally {
1116
+ // if (logalot) { console.log(`${lc} complete.`); }
1117
+ // }
1118
+ // }
1119
+
1120
+ /**
1121
+ * Performs the {@link mut8} transform on this agent and does extra
1122
+ * plumbing.
1123
+ */
1124
+ protected async mut8Self<TData extends AgentWitnessData_V1 = AgentWitnessData_V1>({
1125
+ dataToAddOrPatch,
1126
+ }: {
1127
+ dataToAddOrPatch: Partial<TData>,
1128
+ }): Promise<void> {
1129
+ const lc = `${this.lc}[${this.mut8Self.name}]`;
1130
+ try {
1131
+ if (logalot) { console.log(`${lc} starting... (I: f4618832a0fe07ff8c89cea889d20725)`); }
1132
+
1133
+
1134
+ // get lock on self
1135
+ const metaspace = this._metaspace;
1136
+ if (!metaspace) { throw new Error(`(UNEXPECTED) metaspace falsy? (E: genuuid)`); }
1137
+ const superSpace = await metaspace.getLocalUserSpace({
1138
+ lock: false,
1139
+ localSpaceId: this.data!.superSpaceId,
1140
+ });
1141
+ if (!superSpace) { throw new Error(`couldn't get local superSpace given by this.data.superSpaceId (${this.data!.superSpaceId}) (E: genuuid)`); }
1142
+
1143
+ const { tjpGib } = getGibInfo({ gib: this.gib });
1144
+ if (!tjpGib) { throw new Error(`(UNEXPECTED) this.gib (${this.gib}) has no tjpGib? (E: 75b8dcb82b58d3b0db40b39149023e25)`); }
1145
+ await execInSpaceWithLocking({
1146
+ fn: async () => {
1147
+ const agentsSvc = getAgentsSvc();
1148
+ /**
1149
+ * always update at least in memory latest
1150
+ */
1151
+ await agentsSvc.updateOrSetLatestAgent({
1152
+ agent: this,
1153
+ throwIfNewerFound: false,
1154
+ });
1155
+
1156
+ const resMut8 = await mut8({
1157
+ type: 'mut8',
1158
+ src: this.toIbGibDto(),
1159
+ dataToAddOrPatch,
1160
+ dna: true,
1161
+ nCounter: true,
1162
+ }) as TransformResult<AgentWitnessIbGib_V1>;
1163
+
1164
+ await metaspace.persistTransformResult({
1165
+ resTransform: resMut8,
1166
+ space: superSpace,
1167
+ });
1168
+
1169
+ const newAgentIbGib = resMut8.newIbGib;
1170
+ await this.loadIbGibDto(newAgentIbGib);
1171
+ await agentsSvc.updateOrSetLatestAgent({
1172
+ agent: this,
1173
+ throwIfNewerFound: true, // we **just** created what should be the latest, so throw if this isn't the case
1174
+ });
1175
+
1176
+ await metaspace.registerNewIbGib({
1177
+ ibGib: newAgentIbGib,
1178
+ space: superSpace,
1179
+ });
1180
+
1181
+ // update special index
1182
+ // this will do its own locking on the agent's type
1183
+ await updateAgentIndex({
1184
+ newAgentIbGib,
1185
+ metaspace,
1186
+ space: superSpace,
1187
+ type: this.data!.type,
1188
+ });
1189
+ },
1190
+ scope: tjpGib,
1191
+ secondsValid: 60,
1192
+ maxDelayMs: 100,
1193
+ maxLockAttempts: Number.MAX_SAFE_INTEGER, // drive by seconds valid
1194
+ space: superSpace,
1195
+ callerInstanceId: this.instanceId,
1196
+ });
1197
+
1198
+ } catch (error) {
1199
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1200
+ throw error;
1201
+ } finally {
1202
+ if (logalot) { console.log(`${lc} complete.`); }
1203
+ }
1204
+
1205
+ }
1206
+
1207
+ /**
1208
+ * gets a list of api function infos available as tools to this agent, i.e., atow this are available for function calling in Gemini API. implementation is a WIP.
1209
+ *
1210
+ * @returns array of api function infos available as tools to this agent
1211
+ */
1212
+ protected getAvailableFunctions(): readonly APIFunctionInfo[] {
1213
+ return Array.from(this.availableFunctions.values());
1214
+ }
1215
+ protected getComments_System(): readonly CommentIbGib_V1[] {
1216
+ return [...this.commentIbGibs_system];
1217
+ }
1218
+ protected getComments_Chat(): readonly CommentIbGib_V1[] {
1219
+ return [...this.commentIbGibs_chat];
1220
+ }
1221
+
1222
+ // abstract addAvailableFunctions(functionInfos: APIFunctionInfo[]): Promise<void>;
1223
+ // override async addAvailableFunctions(functionInfos: APIFunctionInfo[]): Promise<void> {
1224
+ async addAvailableFunctions(functionInfos: APIFunctionInfo[]): Promise<void> {
1225
+ const lc = `[${this.addAvailableFunctions.name}]`;
1226
+ try {
1227
+ if (logalot) { console.log(`${lc} starting... (I: 273525464ec540fc9cba565e608db925)`); }
1228
+ if (!functionInfos) { throw new Error(`(UNEXPECTED) functionInfos falsy? (E: 19cf2b7c9ee1115f0a3f7f62fbf77825)`); }
1229
+ if (functionInfos.length === 0) {
1230
+ console.warn(`${lc} functionInfos.length === 0? why is this being called with no functions? returning early without doing anything. (W: 86c6dc4fad3c1ddcac697d5636b1eb25)`);
1231
+ return; /* <<<< returns early */
1232
+ }
1233
+ const agentsSvc = getAgentsSvc();
1234
+ /**
1235
+ * always update at least in memory latest
1236
+ */
1237
+ await agentsSvc.updateOrSetLatestAgent({
1238
+ agent: this,
1239
+ throwIfNewerFound: false,
1240
+ });
1241
+ functionInfos.forEach(x => {
1242
+ if (this.availableFunctions.has(x.nameOrId)) {
1243
+ console.warn(`${lc} this.availableFunctions already has an entry for ${x.nameOrId}. replacing anyway. (W: ef2372a27be67174cb3605eac2c85c25)`)
1244
+ }
1245
+ this.availableFunctions.set(x.nameOrId, x);
1246
+ });
1247
+
1248
+ await this.mut8Self({
1249
+ dataToAddOrPatch: {
1250
+ availableFunctionNameOrIds: Array.from(this.availableFunctions.keys()),
1251
+ }
1252
+ })
1253
+ } catch (error) {
1254
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1255
+ throw error;
1256
+ } finally {
1257
+ if (logalot) { console.log(`${lc} complete.`); }
1258
+ }
1259
+ }
1260
+
1261
+
1262
+ /**
1263
+ * Generates the prompt text for the LLM by concatenating system and chat
1264
+ * comments. This method is meant to be overridden by descendant classes if
1265
+ * needed.
1266
+ *
1267
+ * @returns A {@link TPromptInfo} object that will be used to prompt {@link _genAI}
1268
+ * @throws {Error} If there is an error parsing the addlMetadataText, or if no metaspace is set, or if there are no chat comment ibgibs. (why are we prompting?)
1269
+ */
1270
+ abstract composePromptInfo(): Promise<TPromptInfo>;
1271
+
1272
+ /**
1273
+ * Calls the text-based API to get a response based on the given prompt.
1274
+ * This method is meant to be overridden by descendant classes if needed.
1275
+ *
1276
+ * @param {string} prompt - The text prompt to send to the API.
1277
+ * @returns {Promise<PromptAPIResult>} - The response from the API.
1278
+ * @throws {Error} If the api is not supported or if there is an error with the Gemini API call.
1279
+ */
1280
+ protected abstract callTextAPI(info: PromptInfo): Promise<TPromptResult>;
1281
+
1282
+ // #region doPrompt
1283
+
1284
+ /**
1285
+ * Orchestrates the prompting of the agent, combining system and chat history,
1286
+ * and processing any function calling that is returned from the API.
1287
+ * This method is called via the witness function when it receives a ROOT input.
1288
+ * @returns {Promise<void>}
1289
+ * @throws {Error} If there is an error getting the prompt text, calling the text API, or processing the response.
1290
+ */
1291
+ async doPrompt(): Promise<void> {
1292
+ const lc = `[${this.doPrompt.name}]`;
1293
+ try {
1294
+ if (logalot) { console.log(`${lc} starting... (I: e7f1a7845cdf1bdce1f12d74c71a6425)`); }
1295
+
1296
+ if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: 3c528e2376a2f2600b347b2c183a5225)`); }
1297
+
1298
+ const promptTextInfo = await this.composePromptInfo();
1299
+ if (logalot) { console.log(`${lc} promptTextInfo: ${pretty(promptTextInfo)} (I: b769b5f2a47623a99f78210994d90525)`); }
1300
+
1301
+ const apiResult = await this.callTextAPI(promptTextInfo);
1302
+
1303
+ if (logalot) { console.log(`${lc} api result:`, apiResult, `(I: e4d2c767eb3d6e38d83123d684a07425)`); }
1304
+
1305
+ if ("text" in apiResult) {
1306
+ await this.doPrompt_text(apiResult.text);
1307
+ } else {
1308
+ const { functionCalls } = apiResult; // assert here that functionCalls is present
1309
+ await this.doPrompt_functionCalls({ functionCalls }); // will call recursively if applicable
1310
+ }
1311
+
1312
+ } catch (error) {
1313
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1314
+ throw error;
1315
+ } finally {
1316
+ if (logalot) { console.log(`${lc} complete.`); }
1317
+ }
1318
+ }
1319
+
1320
+ /**
1321
+ * handles text when there are no function calls
1322
+ * @param text string
1323
+ */
1324
+ protected async doPrompt_text(text: string): Promise<void> {
1325
+ const lc = `${this.lc}[${this.doPrompt_text.name}]`;
1326
+ try {
1327
+ if (logalot) { console.log(`${lc} starting... (I: a2b9c21f3b2b058d355d16421e2b4425)`); }
1328
+ text ||= '[no text returned from the model]';
1329
+ if (this.fnOutputText) {
1330
+ // this indeed is occasionally hit, including when an agent
1331
+ // hasn't actually been initialized and just text is returned.
1332
+ this.fnOutputText(text);
1333
+ } else {
1334
+ console.log(`${lc} no fnOutputText set. Text Response: ${text} (I: 5936517474b10b214257781a24b10425)`);
1335
+ }
1336
+ } catch (error) {
1337
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1338
+ throw error;
1339
+ } finally {
1340
+ if (logalot) { console.log(`${lc} complete.`); }
1341
+ }
1342
+ }
1343
+ /**
1344
+ * @protected
1345
+ * Handles the prompt function calls when there are one or more calls
1346
+ * requested by the LLM.
1347
+ *
1348
+ * * parses, validates, executes those function calls
1349
+ * * creates associated function info ibgibs
1350
+ * * creates Function Call Request comment ibgib and relates this to this agent
1351
+ * * recursively calls doPrompt if indicated by the LLM (if they want to be
1352
+ * reprompted after the function calls)
1353
+ *
1354
+ * @param {string[]} functionCalls are raw stringified JSON fn calls requested by the LLM
1355
+ */
1356
+ protected async doPrompt_functionCalls({ functionCalls }: { functionCalls: string[] }): Promise<void> {
1357
+ const lc = `${this.lc}[${this.doPrompt_functionCalls.name}]`;
1358
+ try {
1359
+ if (logalot) { console.log(`${lc} starting... (I: a4f1b581517a9c2a9187e9f8f3519925)`); }
1360
+ if (functionCalls.length === 0) {
1361
+ throw new Error(`(UNEXPECTED) functionCalls.length is zero? (E: 6434b8515a435a59b331452b563f4425)`);
1362
+ }
1363
+
1364
+ // we must first create the function info ibgibs, because the FCR
1365
+ // comment ibgib requires the ibgibs' addresses in both the
1366
+ // data.text and rel8ns
1367
+ const functionInfoIbGibs =
1368
+ await this.doPrompt_functionCalls_createFunctionInfoIbGibsAndExecFunctionCalls({ functionCalls });
1369
+ await this.doPrompt_functionCalls_addFunctionCallRequestComment({ functionInfoIbGibs });
1370
+
1371
+ // if the model wants a reprompt on **ANY** of the functions, we set the "decompression" text here
1372
+ const repromptRequested =
1373
+ functionInfoIbGibs.some(x => {
1374
+ return !!x.data?.repromptWithResult &&
1375
+ x.data.fnName !== 'tellUser';
1376
+ },
1377
+ );
1378
+ if (repromptRequested) {
1379
+ const transientDecompressionPromptText = await this.doPrompt_functionCalls_getTransientDecompressionPromptForNextPrompt({ functionInfoIbGibs });
1380
+ if (transientDecompressionPromptText.length > 0) {
1381
+ console.log(`${lc} transientDecompressionPromptText: ${transientDecompressionPromptText} (I: 11c11d544b7c8f8f8e7e5f7c1a9e3625)`);
1382
+ this.transientDecompressionPromptText = transientDecompressionPromptText;
1383
+ await this.rePrompt();
1384
+ } else {
1385
+ console.warn(`${lc} (UNEXPECTED) there is no decompression text? (W: 6ce5da95c1c89a7ec48a00fbc1d11825)`)
1386
+ }
1387
+ } else {
1388
+ if (logalot) { console.log(`${lc} no repromptWithResult. returning early. (I: 9c0113c958c7404534291f6700325925)`); }
1389
+ }
1390
+
1391
+ } catch (error) {
1392
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1393
+ throw error;
1394
+ } finally {
1395
+ if (logalot) { console.log(`${lc} complete.`); }
1396
+ }
1397
+ }
1398
+
1399
+ protected async doPrompt_functionCalls_createFunctionInfoIbGibsAndExecFunctionCalls({
1400
+ functionCalls,
1401
+ }: {
1402
+ functionCalls: string[],
1403
+ }): Promise<FunctionInfoIbGib_V1[]> {
1404
+ const lc = `${this.lc}[${this.doPrompt_functionCalls_createFunctionInfoIbGibsAndExecFunctionCalls.name}]`;
1405
+ try {
1406
+ if (logalot) { console.log(`${lc} starting... (I: adc094bc98cb076a4aaf729f70adce25)`); }
1407
+ if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: d071328283b2cf880ff0ccd499c22b25)`); }
1408
+ if (!this.data.uuid) { throw new Error(`(UNEXPECTED) this.data.uuid falsy? (E: 8acd2f793e4b5a368dbcf1d8d1e6e825)`); }
1409
+ const metaspace = this._metaspace;
1410
+ if (!metaspace) { throw new Error(`(UNEXPECTED) metaspace falsy? (E: acf8a69e853eb8663f1dd0f79a823e25)`); }
1411
+
1412
+ const functionInfoIbGibs: FunctionInfoIbGib_V1[] = [];
1413
+ for (const functionCallStr of functionCalls) {
1414
+ try {
1415
+ if (logalot) { console.log(`${lc} processing functionCall: ${functionCallStr} (I: a0c0b22b3c6b6c4b674a5a9c8c8b9e25)`); }
1416
+
1417
+ let functionInfoIbGib: FunctionInfoIbGib_V1 | undefined = undefined;
1418
+ let functionCallParsedObj: any | undefined = undefined;
1419
+ let parseErrorMsg: string | undefined = undefined;
1420
+ let functionInfo: APIFunctionInfo | undefined = undefined;
1421
+ let functionArgs: any = undefined;
1422
+ let functionName: string = '';
1423
+
1424
+ // #region get functionCallParsedObj
1425
+ // can we turn this into a helper? This doesn't require this agent state, right?
1426
+ try {
1427
+ functionCallParsedObj = JSON.parse(functionCallStr);
1428
+ functionName = functionCallParsedObj?.name ?? '';
1429
+ if (!functionName) { throw new Error(`functionName (functionCallParsedObj.name) falsy (E: e2397d675863a12b7609495b0007a025)`); }
1430
+ if (logalot) { console.log(`${lc} functionCallParsedObj:`, pretty(functionCallParsedObj), `(I: 750f097243b85644d111971e0f929c25)`); }
1431
+
1432
+ functionInfo = getAllFunctionInfos().get(functionCallParsedObj.name);
1433
+ if (!functionInfo) {
1434
+ throw new Error(`no APIFunctionInfo found that matches functionName (${functionName}) (E: 9d36b6472ec5cdf95e4f498292449925)`);
1435
+ }
1436
+ // todo: validate function call json against the OpenAPI parameters defined in the api function
1437
+
1438
+ functionArgs = functionCallParsedObj.args;
1439
+ // todo: validate args of function call
1440
+ if (logalot) { console.log(`${lc} valid params (I: a4d5c13c79a2405c8d20464b42083325)`) };
1441
+ } catch (error: any) {
1442
+ parseErrorMsg = `${lc} invalid functionCallParsedObj. error: ${extractErrorMsg(error)}. functionCallStr: ${functionCallStr}. (E: 1687a24c5a3667d34689a09f8f753125)`;
1443
+ console.error(parseErrorMsg);
1444
+ functionCallParsedObj = undefined;
1445
+ }
1446
+ // #endregion get functionCallParsedObj
1447
+
1448
+ if (functionInfo) {
1449
+ if (logalot) { console.log(`${lc} found functionInfo: ${functionInfo.nameOrId} (I: 837c7a8200689a0b2314b73057812b25)`); }
1450
+ let fnResult: any | undefined = undefined;
1451
+ let fnComplete = false;
1452
+ let execErrorMsg: string | undefined = undefined;
1453
+
1454
+ // #region execute the functionInfo.functionImpl
1455
+ try {
1456
+ if (logalot) { console.log(`${lc} calling function impl for ${functionInfo.nameOrId} (I: b145d08186782089c18564305f0f1125)`); }
1457
+
1458
+ fnResult = await functionInfo.fnViaCmd(functionArgs);
1459
+ fnComplete = true;
1460
+ if (logalot) { console.log(`${lc} functionImpl complete for ${functionInfo.nameOrId}. result:`, pretty(fnResult), `(I: e19d476f489261263165914750472d25)`); }
1461
+ } catch (error) {
1462
+ execErrorMsg = `${lc} could not call functionImpl for ${functionInfo.nameOrId}: ${extractErrorMsg(error)} (E: 9c0e97f29a9290f9d57637b7053f0c25)`;
1463
+ console.error(execErrorMsg);
1464
+ }
1465
+ // #endregion execute the functionInfo.functionImpl
1466
+
1467
+ const resCreate = await createFunctionInfoIbGib({
1468
+ api: this.data.api,
1469
+ model: this.data.model,
1470
+ agentId: this.data.uuid!,
1471
+ fnRawRequest: functionCallStr,
1472
+ fnName: functionName,
1473
+ fnArgs: functionCallParsedObj.args,
1474
+ repromptWithResult: functionCallParsedObj.args?.repromptWithResult ?? false,
1475
+ fnResult,
1476
+ fnComplete,
1477
+ execErrorMsg,
1478
+ parseErrorMsg: undefined,
1479
+ saveInSpace: true,
1480
+ metaspace,
1481
+ space: await this.getSuperSpace(),
1482
+ });
1483
+ functionInfoIbGib = resCreate.newIbGib;
1484
+ } else {
1485
+ const resCreateErrored = await createFunctionInfoIbGib({
1486
+ api: this.data.api,
1487
+ model: this.data.model,
1488
+ agentId: this.data.uuid,
1489
+ fnRawRequest: functionCallStr,
1490
+ fnName: functionName,
1491
+ fnArgs: functionCallParsedObj.args,
1492
+ repromptWithResult: functionCallParsedObj.args?.repromptWithResult ?? false,
1493
+ fnResult: undefined,
1494
+ fnComplete: undefined,
1495
+ execErrorMsg: undefined,
1496
+ parseErrorMsg,
1497
+ saveInSpace: true,
1498
+ metaspace,
1499
+ space: await this.getSuperSpace(),
1500
+ });
1501
+ functionInfoIbGib = resCreateErrored.newIbGib;
1502
+ }
1503
+
1504
+ if (!functionInfoIbGib) { throw new Error(`(UNEXPECTED) functionInfoIbGib falsy? we should have guaranteed to create one at this point. (E: 97c4ce12c7372adfeebfd45181b73f25)`); }
1505
+ functionInfoIbGibs.push(functionInfoIbGib);
1506
+ } catch (error) {
1507
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1508
+ throw error;
1509
+ } finally {
1510
+ if (logalot) { console.log(`${lc} complete.`); }
1511
+ }
1512
+ } // end iterate functionCalls (raw JSON strings)
1513
+
1514
+ if (functionInfoIbGibs.length === 0) {
1515
+ throw new Error(`(UNEXPECTED) functionInfoIbGibs.length === 0? We expect at least one to be created (E: a8f81c56377cdbdeb468af6b21879825)`);
1516
+ }
1517
+
1518
+ return functionInfoIbGibs;
1519
+ } catch (error) {
1520
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1521
+ throw error;
1522
+ } finally {
1523
+ if (logalot) { console.log(`${lc} complete.`); }
1524
+ }
1525
+ }
1526
+
1527
+ protected async doPrompt_functionCalls_addFunctionCallRequestComment({
1528
+ functionInfoIbGibs
1529
+ }: {
1530
+ functionInfoIbGibs: FunctionInfoIbGib_V1[]
1531
+ }): Promise<void> {
1532
+ const lc = `${this.lc}[${this.doPrompt_functionCalls_addFunctionCallRequestComment.name}]`;
1533
+ try {
1534
+ if (logalot) { console.log(`${lc} starting... (I: 5000adac5e8c4a7158a720c38f56b325)`); }
1535
+ const metaspace = this._metaspace;
1536
+ if (!metaspace) { throw new Error(`(UNEXPECTED) metaspace falsy? (E: d7275731461d8d0526af3088553ae525)`); }
1537
+ const superSpace = await this.getSuperSpace();
1538
+
1539
+ // this is the actual data.text string
1540
+ const fcrText = taggifyForPrompt({
1541
+ tagText: FUNCTION_CALL_REQUEST_COMMENT_TAG,
1542
+ contentText: functionInfoIbGibs.map(x => getIbGibAddr({ ibGib: x })).join('\n'),
1543
+ randomIdLength: 4,
1544
+ });
1545
+
1546
+ const addlMetadataText = getAddlMetadataTextForAgentText({ textSrc: 'ai', other: 'functionCallRequest' });
1547
+ const resComment: TransformResult<CommentIbGib_V1> =
1548
+ await createCommentIbGib({
1549
+ text: fcrText,
1550
+ addlMetadataText,
1551
+ saveInSpace: true,
1552
+ space: superSpace,
1553
+ });
1554
+ // now we have the starting comment ibgib, but we want to relate the
1555
+ // actual function info ibgibs via the function info rel8nName.
1556
+ const resRel8FunctionInfosToFCR = await rel8({
1557
+ type: 'rel8',
1558
+ src: resComment.newIbGib,
1559
+ rel8nsToAddByAddr: {
1560
+ [FUNCTION_INFO_REL8N_NAME]: functionInfoIbGibs.map(x => getIbGibAddr({ ibGib: x })),
1561
+ },
1562
+ dna: true,
1563
+ nCounter: true,
1564
+ }) as TransformResult<CommentIbGib_V1>;
1565
+ const functionCallRequestComment = resRel8FunctionInfosToFCR.newIbGib;
1566
+ await metaspace.persistTransformResult({
1567
+ resTransform: resRel8FunctionInfosToFCR,
1568
+ space: superSpace,
1569
+ });
1570
+ await metaspace.registerNewIbGib({
1571
+ ibGib: functionCallRequestComment,
1572
+ space: superSpace,
1573
+ });
1574
+
1575
+ await this.addTexts({ infos: [{ textSrc: 'ai', commentIbGib: functionCallRequestComment }], });
1576
+ } catch (error) {
1577
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1578
+ throw error;
1579
+ } finally {
1580
+ if (logalot) { console.log(`${lc} complete.`); }
1581
+ }
1582
+ }
1583
+
1584
+ protected async doPrompt_functionCalls_getTransientDecompressionPromptForNextPrompt({
1585
+ functionInfoIbGibs
1586
+ }: {
1587
+ functionInfoIbGibs: FunctionInfoIbGib_V1[]
1588
+ }): Promise<string> {
1589
+ const lc = `${this.lc}[${this.doPrompt_functionCalls_getTransientDecompressionPromptForNextPrompt.name}]`;
1590
+ try {
1591
+ if (logalot) { console.log(`${lc} starting... (I: c245f78f6c78a98d62375a9f14b3d625)`); }
1592
+
1593
+ let contentTexts: string[] = [];
1594
+ for (const functionInfoIbGib of functionInfoIbGibs) {
1595
+ try {
1596
+ const functionInfoAddr = getIbGibAddr({ ibGib: functionInfoIbGib });
1597
+ if (!functionInfoIbGib.data) { throw new Error(`(UNEXPECTED) !functionInfoIbGib.data? functionInfoAddr: ${functionInfoAddr} (E: 7815e4854513c26b889517a9bd7e0d25)`); }
1598
+ const { fnRawRequest, fnComplete, fnResult } = functionInfoIbGib.data;
1599
+ const dataSlice = { fnRawRequest, fnComplete, fnResult };
1600
+ const contentText = taggifyForPrompt({
1601
+ tagText: functionInfoAddr,
1602
+ contentText: pretty(dataSlice),
1603
+ randomIdLength: undefined, // don't need an id since we have a unique ibgib addr as the tag
1604
+ });
1605
+ contentTexts.push(contentText);
1606
+ } catch (error) {
1607
+ console.error(`${lc} could not call functionImpl: ${extractErrorMsg(error)} (E: 2a3b8b37e146c524b67119e3a74e3d25)`)
1608
+ }
1609
+ }
1610
+ return contentTexts.join('\n');
1611
+ } catch (error) {
1612
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1613
+ throw error;
1614
+ } finally {
1615
+ if (logalot) { console.log(`${lc} complete.`); }
1616
+ }
1617
+ }
1618
+
1619
+ // #endregion doPrompt
1620
+
1621
+ /**
1622
+ * naive counter for reprompt asked for by the model
1623
+ */
1624
+ repromptCount: number = 0;
1625
+ /**
1626
+ * naive cap for reprompt asked for by the model
1627
+ */
1628
+ repromptMax: number = 12;
1629
+ /**
1630
+ * recursively calls doPrompt depending on {@link repromptCount} and {@link repromptMax}
1631
+ */
1632
+ async rePrompt(): Promise<void> {
1633
+ const lc = `${this.lc}[${this.rePrompt.name}]`;
1634
+ try {
1635
+ if (logalot) { console.log(`${lc} starting... (I: b6af34214acf07f9ca8c1d03c0011525)`); }
1636
+ if (this.repromptCount < this.repromptMax) {
1637
+ this.repromptCount++;
1638
+ await this.doPrompt();
1639
+ } else {
1640
+ console.log(`${lc} already reached repromptMax (${this.repromptMax}). reprompt aborting. $(I: dacefb501dab2a1ee173ce8558657725)`);
1641
+ this.repromptCount = 0;
1642
+ }
1643
+ } catch (error) {
1644
+ console.error(`${lc} ${extractErrorMsg(error)}`);
1645
+ throw error;
1646
+ } finally {
1647
+ if (logalot) { console.log(`${lc} complete.`); }
1648
+ }
1649
+ }
1650
+
1651
+ async witness(arg: IbGib_V1): Promise<IbGib_V1> {
1652
+ if (arg.ib === IB && arg.gib === GIB) {
1653
+ // root called, which in this class is a request to doPrompt.
1654
+ if (this.getComments_Chat().length > 0) {
1655
+ await this.doPrompt();
1656
+ }
1657
+ return ROOT;
1658
+ } else {
1659
+ // TODO: Implement other witness logic for the agent. for now we're just ignoring this, but in the future, we need to redesign this class more towards ibgib style: functions create args that are funneled to this, or at the very least, the functions, if successful, are memoized via this witness function after-the-fact and this witness gets updated. its internal state (`this.data` and `this.rel8ns`) is changed, so therefore `this.gib` needs to be updated and most likely this witness needs to be updated/persisted in its local space. but since we're still feeling out the overall architecture, this would be too much overhead for something that might change in the near future.
1660
+ throw new Error(`arg (${pretty(arg)}) not implemented. only expect ${ROOT} right now to trigger doPrompt. (E: 24da0ad7333b6bbb359d1be425db3c25)`);
1661
+ }
1662
+ }
1663
+ }
1664
+
1665
+ export type AgentWitnessAny = AgentWitness_V1<any, any, any>;