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