@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,928 @@
|
|
|
1
|
+
import { FunctionCallingMode, GoogleGenerativeAI, } from '@google/generative-ai';
|
|
2
|
+
import { clone, delay, extractErrorMsg, getTimestampInTicks, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
3
|
+
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
4
|
+
import { ROOT_ADDR } from '@ibgib/ts-gib/dist/V1/constants.mjs';
|
|
5
|
+
import { getGibInfo } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
|
|
6
|
+
import { createCommentIbGib, parseCommentIb } from '@ibgib/core-gib/dist/common/comment/comment-helper.mjs';
|
|
7
|
+
import { GLOBAL_LOG_A_LOT } from '../../../constants.mjs';
|
|
8
|
+
import { getAllFunctionInfos, getDeprecatedFunctionInfoNames } from '../../../api/api-index.mjs';
|
|
9
|
+
import { AgentWitness_V1, getAddlMetadataTextForAgentText, parseAddlMetadataTextForAgentText, validateAgentWitnessCommentIbGib } from '../agent-one-file.mjs';
|
|
10
|
+
import { getFunctionCallAndResponseParts, isFunctionCallRequestComment, isPromptInfoGemini, systemPromptEntriesToSystemInstructionContent, textSourceToGeminiRole, } from './gemini-helpers.mjs';
|
|
11
|
+
import { FUNCTION_INFO_REL8N_NAME } from '../function-info/function-info-one-file.mjs';
|
|
12
|
+
import { agentIbGibDtoToWitness } from './gemini-agent-factory.mjs';
|
|
13
|
+
import { getAgentsSvc } from '../agents-service-v1.mjs';
|
|
14
|
+
import { GEMINI_BACKUP_MODEL_STR, GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO, GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY, GEMINI_ERROR_STATUS_MODEL_OVERLOADED, GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED, GEMINI_MAX_TRY_COUNT } from './gemini-constants.mjs';
|
|
15
|
+
import { AGENT_REL8N_NAME, TextSource } from '../agent-constants.mjs';
|
|
16
|
+
// import { appendToTimeline, getLockScope, mut8Timeline, Rel8nInfo } from '../../../api/timeline/timeline-api.mjs';
|
|
17
|
+
import { execInSpaceWithLocking } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
18
|
+
import { appendToTimeline } from '@ibgib/core-gib/dist/timeline/timeline-api.mjs';
|
|
19
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
20
|
+
export class AgentWitnessGemini_V1 extends AgentWitness_V1 {
|
|
21
|
+
// witness(arg: IbGib_V1): Promise<IbGib_V1 | undefined> {
|
|
22
|
+
// throw new Error('Method not implemented.');
|
|
23
|
+
// }
|
|
24
|
+
lc = `[${AgentWitnessGemini_V1.name}]`;
|
|
25
|
+
async validateThis() {
|
|
26
|
+
const lc = `${this.lc}[${this.validateThis.name}]`;
|
|
27
|
+
try {
|
|
28
|
+
if (logalot) {
|
|
29
|
+
console.log(`${lc} starting... (I: 641e211473fc54d5a9ebb4ea44944d25)`);
|
|
30
|
+
}
|
|
31
|
+
const errors = await super.validateThis();
|
|
32
|
+
// todo: refactor this into a non-class-method validation helper function for data
|
|
33
|
+
if (this.data) {
|
|
34
|
+
console.warn(`${lc} do more validation on this concrete class. (W: fb778a84ccca2ebcefd2ca7845543825)`);
|
|
35
|
+
// todo: add validation for available functions
|
|
36
|
+
// todo: add other validation
|
|
37
|
+
// todo: break out data validation and rel8ns validation into separate functions
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// this is already done in the super call
|
|
41
|
+
// errors.push(`this.data falsy (E: f5f151e11b12cad814b37ecad7c74a25)`)
|
|
42
|
+
}
|
|
43
|
+
return errors;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (logalot) {
|
|
51
|
+
console.log(`${lc} complete.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* not implemented at the moment
|
|
57
|
+
*/
|
|
58
|
+
parseAddlMetadataString({ ib }) {
|
|
59
|
+
const lc = `${this.lc}[${this.parseAddlMetadataString.name}]`;
|
|
60
|
+
try {
|
|
61
|
+
if (logalot) {
|
|
62
|
+
console.log(`${lc} starting... (I: 080daf4b73f8bb52c70bf0a8f329be25)`);
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`not implemented...i've just converted agent witness to a full witness with context and this was the only abstract method required. wasn't being used previously? so i'm not sure why this is here. (E: 129e816d3698f3867ec54c34fcc9a225)`);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
if (logalot) {
|
|
72
|
+
console.log(`${lc} complete.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async addTexts(opts) {
|
|
77
|
+
const lc = `${this.lc}[${this.addTexts.name}]`;
|
|
78
|
+
try {
|
|
79
|
+
const agentsSvc = getAgentsSvc();
|
|
80
|
+
/**
|
|
81
|
+
* always update at least in memory latest
|
|
82
|
+
*/
|
|
83
|
+
await agentsSvc.updateOrSetLatestAgent({
|
|
84
|
+
agent: this,
|
|
85
|
+
throwIfNewerFound: false,
|
|
86
|
+
});
|
|
87
|
+
const metaspace = this._metaspace;
|
|
88
|
+
if (!metaspace) {
|
|
89
|
+
throw new Error(`(UNEXPECTED) metaspace falsy? (E: fd92a81901a83e2698ab2c3d4e702f25)`);
|
|
90
|
+
}
|
|
91
|
+
if (opts.infos.length === 0) {
|
|
92
|
+
console.warn(`${lc} opts.infos.length === 0. So we've called addTexts but with an empty array? returning early. (W: 0d42cd3b26aec45874d0e65450b37d25)`);
|
|
93
|
+
return []; /* <<<< returns early */
|
|
94
|
+
}
|
|
95
|
+
const orderedCommentIbGibs_all = [];
|
|
96
|
+
const orderedCommentIbGibs_system = [];
|
|
97
|
+
const orderedCommentIbGibs_chat = [];
|
|
98
|
+
const superSpace = await this.getSuperSpace();
|
|
99
|
+
// const superSpace = await metaspace.getLocalUserSpace({
|
|
100
|
+
// lock: false,
|
|
101
|
+
// localSpaceId: this.data!.superSpaceId
|
|
102
|
+
// });
|
|
103
|
+
// just get the slow damn version in place dude.
|
|
104
|
+
for (const info of opts.infos) {
|
|
105
|
+
const { textSrc, isSystem } = info;
|
|
106
|
+
let { text, commentIbGib, } = info;
|
|
107
|
+
if (text && commentIbGib) {
|
|
108
|
+
throw new Error(`(UNEXPECTED) both text and commentIbGib provided? (E: a3fd590db1a5efc301f3c7e66b322f25)`);
|
|
109
|
+
}
|
|
110
|
+
if (!text && !commentIbGib) {
|
|
111
|
+
throw new Error(`(UNEXPECTED) both text and commentIbGib falsy? one or the other is required (E: e08c7c694a17319085adfb75914b2725)`);
|
|
112
|
+
}
|
|
113
|
+
const addlMetadataText = getAddlMetadataTextForAgentText({ textSrc });
|
|
114
|
+
if (commentIbGib) {
|
|
115
|
+
if (logalot) {
|
|
116
|
+
console.log(`${lc} adding existing commentIbGib (I: 72a3f7aafde92f65b168d27605f94625)`);
|
|
117
|
+
}
|
|
118
|
+
// we have an existing commentIbGib, but there are a couple
|
|
119
|
+
// of points to consider:
|
|
120
|
+
// 1. is the comment valid for use in agent witnesses? does
|
|
121
|
+
// it have the right metadata? ANSWER: we will validate
|
|
122
|
+
// after this if..else block
|
|
123
|
+
// 2. Does the comment (and its dependency graph) exist in
|
|
124
|
+
// the agent's space? A complication for this is what if the
|
|
125
|
+
// comment rel8s to some other (especially large) ibgib graph?
|
|
126
|
+
// or IOW, what if the comment has some potentially huge
|
|
127
|
+
// dependency graph? ANSWER: todo: check superSpace and/or
|
|
128
|
+
// add a flag vouching for the dependency graph to exist in
|
|
129
|
+
// it.
|
|
130
|
+
// 3. also persist dependency graph in agent's subSpace?
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// just passed in raw text, need to create a new comment ibgib
|
|
134
|
+
if (logalot) {
|
|
135
|
+
console.log(`${lc} creating new commentIbGib for text (I: 72a3f7aafde92f65b168d27605f94625)`);
|
|
136
|
+
}
|
|
137
|
+
if (!text) {
|
|
138
|
+
throw new Error(`(UNEXPECTED) text falsy still? at this point it should be guaranteed (E: b2deec458f35f22298ccb664d0685125)`);
|
|
139
|
+
}
|
|
140
|
+
const resCreateComment = await createCommentIbGib({
|
|
141
|
+
text,
|
|
142
|
+
addlMetadataText,
|
|
143
|
+
saveInSpace: true,
|
|
144
|
+
space: superSpace,
|
|
145
|
+
});
|
|
146
|
+
commentIbGib = resCreateComment.newIbGib;
|
|
147
|
+
await metaspace.registerNewIbGib({
|
|
148
|
+
ibGib: commentIbGib,
|
|
149
|
+
space: superSpace,
|
|
150
|
+
});
|
|
151
|
+
// also persist in agent's subSpace?
|
|
152
|
+
// const subSpace = await this.getAgentSpace();
|
|
153
|
+
// await metaspace.persistTransformResult({ resTransform: resCreateComment, space: subSpace });
|
|
154
|
+
// await metaspace.registerNewIbGib({ ibGib: resCreateComment.newIbGib, space: subSpace });
|
|
155
|
+
}
|
|
156
|
+
if (!commentIbGib) {
|
|
157
|
+
throw new Error(`(UNEXPECTED) commentIbGib still falsy? we should have just created one if it didn't exist (E: 9370b19aa207234db185cd74b57be525)`);
|
|
158
|
+
}
|
|
159
|
+
const validationErrors = await validateAgentWitnessCommentIbGib({ ibGib: commentIbGib });
|
|
160
|
+
if (validationErrors.length > 0) {
|
|
161
|
+
throw new Error(`validation errors with trying to add a commentIbGib. errors: ${validationErrors} (E: beee1893050f9bcf9842c66831595225)`);
|
|
162
|
+
}
|
|
163
|
+
orderedCommentIbGibs_all.push(commentIbGib);
|
|
164
|
+
if (isSystem) {
|
|
165
|
+
orderedCommentIbGibs_system.push(commentIbGib);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
orderedCommentIbGibs_chat.push(commentIbGib);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// we now have all of the comment ibgibs prepared. we need to add these
|
|
172
|
+
// to this agent's rel8ns
|
|
173
|
+
const rel8nInfosToAppend = [];
|
|
174
|
+
if (orderedCommentIbGibs_system.length > 0) {
|
|
175
|
+
rel8nInfosToAppend.push({ rel8nName: 'system', ibGibs: orderedCommentIbGibs_system, });
|
|
176
|
+
}
|
|
177
|
+
if (orderedCommentIbGibs_chat.length > 0) {
|
|
178
|
+
rel8nInfosToAppend.push({ rel8nName: 'chat', ibGibs: orderedCommentIbGibs_chat, });
|
|
179
|
+
}
|
|
180
|
+
const newAgentIbGib = await appendToTimeline({
|
|
181
|
+
timeline: this.toIbGibDto(),
|
|
182
|
+
rel8nInfos: rel8nInfosToAppend,
|
|
183
|
+
timelineIndexInfo: {
|
|
184
|
+
rel8nName: AGENT_REL8N_NAME,
|
|
185
|
+
type: this.data.type,
|
|
186
|
+
},
|
|
187
|
+
metaspace,
|
|
188
|
+
space: superSpace,
|
|
189
|
+
});
|
|
190
|
+
// const resRel8 = await rel8({
|
|
191
|
+
// type: 'rel8',
|
|
192
|
+
// src: this.toIbGibDto(),
|
|
193
|
+
// rel8nsToAddByAddr: {
|
|
194
|
+
// ['system']: orderedCommentIbGibs_system.map(x => getIbGibAddr({ ibGib: x })),
|
|
195
|
+
// ['chat']: orderedCommentIbGibs_chat.map(x => getIbGibAddr({ ibGib: x })),
|
|
196
|
+
// },
|
|
197
|
+
// dna: true,
|
|
198
|
+
// nCounter: true,
|
|
199
|
+
// }) as TransformResult<AgentWitnessGemini_V1>;
|
|
200
|
+
// await this._metaspace!.persistTransformResult({
|
|
201
|
+
// resTransform: resRel8,
|
|
202
|
+
// space: superSpace,
|
|
203
|
+
// });
|
|
204
|
+
// const newAgentIbGib = resRel8.newIbGib;
|
|
205
|
+
await this.loadIbGibDto(newAgentIbGib);
|
|
206
|
+
await agentsSvc.updateOrSetLatestAgent({
|
|
207
|
+
agent: this,
|
|
208
|
+
throwIfNewerFound: true, // we **just** created what should be the latest, so throw if this isn't the case
|
|
209
|
+
});
|
|
210
|
+
// await metaspace.registerNewIbGib({
|
|
211
|
+
// ibGib: newAgentIbGib,
|
|
212
|
+
// space: superSpace,
|
|
213
|
+
// });
|
|
214
|
+
// update special index
|
|
215
|
+
// await updateAgentIndex({
|
|
216
|
+
// newAgentIbGib,
|
|
217
|
+
// metaspace,
|
|
218
|
+
// space: superSpace,
|
|
219
|
+
// type: this.data!.type,
|
|
220
|
+
// });
|
|
221
|
+
return orderedCommentIbGibs_all;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async composePromptInfo() {
|
|
229
|
+
const lc = `${this.lc}[${this.composePromptInfo.name}]`;
|
|
230
|
+
try {
|
|
231
|
+
if (logalot) {
|
|
232
|
+
console.log(`${lc} starting... (I: 155774d4811b038034342d5750174325)`);
|
|
233
|
+
}
|
|
234
|
+
if (!this._metaspace) {
|
|
235
|
+
throw new Error(`this.metaspace falsy (E: 7232a3a1b4348d460ed1375b32677125)`);
|
|
236
|
+
}
|
|
237
|
+
const systemPromptEntries = [];
|
|
238
|
+
for (const commentIbGib of this.commentIbGibs_system) {
|
|
239
|
+
const entry = await this.createPromptInfoEntriesFromGeminiComment({ commentIbGib });
|
|
240
|
+
systemPromptEntries.push(...entry);
|
|
241
|
+
}
|
|
242
|
+
const currentContextTjpAddr = this.data?.['@currentContextTjpAddr'] ?? ROOT_ADDR;
|
|
243
|
+
if (currentContextTjpAddr !== ROOT_ADDR) {
|
|
244
|
+
systemPromptEntries.push({
|
|
245
|
+
src: TextSource.HARDCODED,
|
|
246
|
+
// text: commentIbGib.data.text,
|
|
247
|
+
content: {
|
|
248
|
+
role: textSourceToGeminiRole(TextSource.HARDCODED),
|
|
249
|
+
parts: [
|
|
250
|
+
{
|
|
251
|
+
text: getTextPartForCurrentContextTjpAddr({
|
|
252
|
+
currentContextTjpAddr
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (this.commentIbGibs_chat.length === 0) {
|
|
260
|
+
throw new Error(`(UNEXPECTED) this.commentIbGibs_chat.length === 0? why are we composing prompt info? We are assumed at this point to have added at least one comment ibgib to this agent. (E: a4e3d840946ab8e6dc3fde3e25d6b225)`);
|
|
261
|
+
}
|
|
262
|
+
const chatPromptHistoryParts = [];
|
|
263
|
+
const chatCommentIbGibs_history = this.commentIbGibs_chat.length > 1 ? this.commentIbGibs_chat.slice(0, -1) : [];
|
|
264
|
+
for (const commentIbGib of chatCommentIbGibs_history) {
|
|
265
|
+
const entry = await this.createPromptInfoEntriesFromGeminiComment({ commentIbGib });
|
|
266
|
+
chatPromptHistoryParts.push(...entry);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* the most recent may be a regular comment or an FCR. if FCR, then
|
|
270
|
+
* there will be two gemini entries and we need to add the first one
|
|
271
|
+
* (functionCall part) to our history.
|
|
272
|
+
*/
|
|
273
|
+
let chatPromptCurrent;
|
|
274
|
+
const chatCommentIbGib_current = this.commentIbGibs_chat.at(-1); // guaranteed to have at least one element due to previous commentIbGibs_Chat.length check
|
|
275
|
+
const chatPromptCurrent_rawarray = await this.createPromptInfoEntriesFromGeminiComment({ commentIbGib: chatCommentIbGib_current });
|
|
276
|
+
if (chatPromptCurrent_rawarray.length === 1) {
|
|
277
|
+
// regular
|
|
278
|
+
chatPromptCurrent = chatPromptCurrent_rawarray.at(0);
|
|
279
|
+
}
|
|
280
|
+
else if (chatPromptCurrent_rawarray.length === 2) {
|
|
281
|
+
// fcr
|
|
282
|
+
chatPromptHistoryParts.push(chatPromptCurrent_rawarray.at(0)); // functionCall entry
|
|
283
|
+
chatPromptCurrent = chatPromptCurrent_rawarray.at(1); // functionResponse entry;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
throw new Error(`(UNEXPECTED) chatPromptCurrent_rawarray.length !== 1 or 2? We expect at this point either a regular text part or a FCR comment which creates two entries. (E: cd59f978479c20e496da4b0eb86c7d25)`);
|
|
287
|
+
}
|
|
288
|
+
const resPromptInfo = {
|
|
289
|
+
api: 'gemini',
|
|
290
|
+
systemPromptEntries,
|
|
291
|
+
chatPromptHistoryParts,
|
|
292
|
+
chatPromptCurrent,
|
|
293
|
+
};
|
|
294
|
+
if (logalot) {
|
|
295
|
+
console.log(`${lc} resPromptInfo:`, pretty(resPromptInfo), `(I: 8f17a8c45b9a91e20a5c5064d9114a25)`);
|
|
296
|
+
}
|
|
297
|
+
return resPromptInfo;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
if (logalot) {
|
|
305
|
+
console.log(`${lc} complete.`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async callTextAPI(info) {
|
|
310
|
+
const lc = `${this.lc}[${this.callTextAPI.name}]`;
|
|
311
|
+
try {
|
|
312
|
+
if (logalot) {
|
|
313
|
+
console.log(`${lc} starting... (I: 27885f5b14682646542e9658417b2f25)`);
|
|
314
|
+
}
|
|
315
|
+
if (!isPromptInfoGemini(info)) {
|
|
316
|
+
throw new Error(`(UNEXPECTED) info.api !== gemini? we are in the gemini concrete class where this is assumed. (E: 9223647ec96fb3f4eaee32c3fc15d925)`);
|
|
317
|
+
}
|
|
318
|
+
// #region prepare
|
|
319
|
+
if (!this.data) {
|
|
320
|
+
throw new Error(`(UNEXPECTED) this.data falsy? (E: 09224b6688fdac884ce88f196b68a425)`);
|
|
321
|
+
}
|
|
322
|
+
const { api, model } = this.data;
|
|
323
|
+
if (api !== 'gemini') {
|
|
324
|
+
throw new Error(`api not supported: ${api} (E: 7e5c7c17988a666a86e72299630c7f25)`);
|
|
325
|
+
}
|
|
326
|
+
// todo: refactor gemini-specific code into its own descendant class
|
|
327
|
+
if (logalot) {
|
|
328
|
+
console.log(`${lc} calling gemini api with model: ${model} (I: 6208942a419e9041bb037384135a0c25)`);
|
|
329
|
+
}
|
|
330
|
+
const apiKey = await this.fnGetAPIKey();
|
|
331
|
+
if (!apiKey) {
|
|
332
|
+
console.error(`${lc} apiKey falsy. did you set this.fnGetAPIKey (E: d964596b1538c0327209a92e97a54d25)`);
|
|
333
|
+
return {
|
|
334
|
+
text: 'no api key entered so no LLM chat happening. enter a gemini api key and donate/invest!',
|
|
335
|
+
}; /* <<<< returns early */
|
|
336
|
+
}
|
|
337
|
+
this._genAI ??= new GoogleGenerativeAI(apiKey);
|
|
338
|
+
const functionDeclarations = Array.from(this.availableFunctions.values()).map((x) => ({
|
|
339
|
+
name: x.nameOrId,
|
|
340
|
+
description: x.schema?.description,
|
|
341
|
+
parameters: x.schema?.parameters,
|
|
342
|
+
}));
|
|
343
|
+
if (functionDeclarations.some(x => x.parameters === 'undefined')) {
|
|
344
|
+
console.error(`${lc} (UNEXPECTED) function schema parameters not defined for all APIFunctionInfo values. (E: ae7227cdd65c0ab4513c7b282a1e4825)`);
|
|
345
|
+
}
|
|
346
|
+
if (logalot) {
|
|
347
|
+
console.log(`${lc} Gemini functionDeclarations:`);
|
|
348
|
+
console.dir(functionDeclarations);
|
|
349
|
+
}
|
|
350
|
+
// #endregion prepare
|
|
351
|
+
const { systemPromptEntries, chatPromptHistoryParts, chatPromptCurrent } = info;
|
|
352
|
+
/**
|
|
353
|
+
* we may add decompression text parts to the most recent entry
|
|
354
|
+
*/
|
|
355
|
+
const chatPromptCurrent_final = clone(chatPromptCurrent);
|
|
356
|
+
if (logalot) {
|
|
357
|
+
console.log(`chatPromptCurrent_final (before decompression): ${pretty(chatPromptCurrent_final)} (I: bbd4c7b9f3225afe9da1761918d0ac25)`);
|
|
358
|
+
}
|
|
359
|
+
if (logalot) {
|
|
360
|
+
console.warn(`${lc} skipping decompression for the moment. if we add decompression text when the last comment is a function response part, then we'll error out. Need to rethink compression/decompression with the new function call/response workflow. (W: 7478439f9bbbde30a1eab3c5189ea625)`);
|
|
361
|
+
}
|
|
362
|
+
// if (this.transientDecompressionPromptText) {
|
|
363
|
+
// const taggedDecompressionText = taggifyForPrompt({
|
|
364
|
+
// tagText: CONTEXT_DECOMPRESSION_TAG,
|
|
365
|
+
// contentText: this.transientDecompressionPromptText,
|
|
366
|
+
// randomIdLength: 4,
|
|
367
|
+
// });
|
|
368
|
+
// const decompressionTextPart: TextPart = {
|
|
369
|
+
// text: taggedDecompressionText,
|
|
370
|
+
// };
|
|
371
|
+
// // we insert the decompression BEFORE the current part, but only
|
|
372
|
+
// chatPromptCurrent_final.content.parts = [decompressionTextPart, ...chatPromptCurrent_final.content.parts];
|
|
373
|
+
// // `${taggedDecompressionText}\n${chatPromptCurrent}`;
|
|
374
|
+
// this.transientDecompressionPromptText = undefined;
|
|
375
|
+
// }
|
|
376
|
+
let result = undefined;
|
|
377
|
+
/**
|
|
378
|
+
* need to be able to call this function with retries with different
|
|
379
|
+
* models, depending on error code received when generating text.
|
|
380
|
+
*
|
|
381
|
+
* ## driving intent
|
|
382
|
+
*
|
|
383
|
+
* I am getting a 503 error saying the model is overloaded. We need
|
|
384
|
+
* to have a backup model that is hardcoded and updated via source
|
|
385
|
+
* code until we get a more robust model system.
|
|
386
|
+
*
|
|
387
|
+
* @param modelStr to use
|
|
388
|
+
* @param isRetry if true, this indicates this is aleady a retry and should throw if fails
|
|
389
|
+
*/
|
|
390
|
+
const fnGoModel = async (modelStr) => {
|
|
391
|
+
if (!this._genAI) {
|
|
392
|
+
throw new Error(`(UNEXPECTED) this._genAI falsy? (E: 503a0d9e3f729de7653ee3565b017b25)`);
|
|
393
|
+
}
|
|
394
|
+
const genModel = this._genAI.getGenerativeModel({
|
|
395
|
+
model: modelStr,
|
|
396
|
+
systemInstruction: systemPromptEntriesToSystemInstructionContent({ systemPromptEntries }),
|
|
397
|
+
tools: [{ functionDeclarations }],
|
|
398
|
+
toolConfig: {
|
|
399
|
+
functionCallingConfig: {
|
|
400
|
+
// mode: FunctionCallingMode.AUTO, // can be either text or function call, this is the default
|
|
401
|
+
mode: info.overrideFunctionCallingMode ??
|
|
402
|
+
FunctionCallingMode.ANY, // MANDATES a function call. If this is not used, the model gets confused, but maybe this will be fixed after we get better function response feedback in place.
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
/**
|
|
407
|
+
* We start a "chat", _BUT ONLY TO USE THE HISTORY MECHANISM_.
|
|
408
|
+
* Really we use this as a one-off, but we do not know how to mimic
|
|
409
|
+
* the "history" so that the model understands to only respond to
|
|
410
|
+
* the most recent prompt.
|
|
411
|
+
*/
|
|
412
|
+
const chat = genModel.startChat({
|
|
413
|
+
history: chatPromptHistoryParts.map(x => x.content),
|
|
414
|
+
});
|
|
415
|
+
result = await chat.sendMessage(chatPromptCurrent.content.parts);
|
|
416
|
+
return result;
|
|
417
|
+
};
|
|
418
|
+
let tryCount = 0;
|
|
419
|
+
let modelStr = model;
|
|
420
|
+
do {
|
|
421
|
+
tryCount++;
|
|
422
|
+
try {
|
|
423
|
+
result = await fnGoModel(modelStr);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
if (error.status && error.status === GEMINI_ERROR_STATUS_MODEL_OVERLOADED) {
|
|
428
|
+
// model is overloaded, try using the backup
|
|
429
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model. will try using backup model (${GEMINI_BACKUP_MODEL_STR}) for this next call. error (${error.status}): ${extractErrorMsg(error)} (E: a5cd7d174183518058da57cc6d0d8a25)`);
|
|
430
|
+
modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model. error (${error.status}): ${extractErrorMsg(error)} (E: a67d595c8ed313d458369d4d0b3e7f25)`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
await delay(2000); // nothing fancy right now
|
|
437
|
+
} while (!result && tryCount < GEMINI_MAX_TRY_COUNT);
|
|
438
|
+
if (!result) {
|
|
439
|
+
throw new Error(`couldn't get result from model (E: ede013a53f875d99a96a2e257c7e7125)`);
|
|
440
|
+
}
|
|
441
|
+
// const result = await genModel.generateContent(finalChatPrompt);
|
|
442
|
+
const enhancedResult = result.response;
|
|
443
|
+
const functionCalls = enhancedResult.functionCalls();
|
|
444
|
+
if (!functionCalls || functionCalls.length === 0) {
|
|
445
|
+
if (logalot) {
|
|
446
|
+
console.warn(`${lc} no function calls in response, returning text. (W: 3a4b8c940983b9e28e3f04c01a09bb25)`);
|
|
447
|
+
}
|
|
448
|
+
return { text: result.response.text() };
|
|
449
|
+
}
|
|
450
|
+
if (logalot) {
|
|
451
|
+
console.log(`${lc} Gemini function calls:`);
|
|
452
|
+
console.dir(functionCalls);
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
functionCalls: functionCalls.map(x => JSON.stringify(x, null, 2))
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
460
|
+
throw error;
|
|
461
|
+
}
|
|
462
|
+
finally {
|
|
463
|
+
if (logalot) {
|
|
464
|
+
console.log(`${lc} complete.`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
async createPromptInfoEntriesFromGeminiComment({ commentIbGib, }) {
|
|
469
|
+
const lc = `[${this.createPromptInfoEntriesFromGeminiComment.name}]`;
|
|
470
|
+
try {
|
|
471
|
+
if (logalot) {
|
|
472
|
+
console.log(`${lc} starting... (I: 826a9d6b120d96532afbe1f7a22e8d25)`);
|
|
473
|
+
}
|
|
474
|
+
const validationErrors = await validateAgentWitnessCommentIbGib({ ibGib: commentIbGib });
|
|
475
|
+
if (validationErrors.length > 0) {
|
|
476
|
+
throw new Error(`validation errors with commentIbGib. Cannot create a prompt info entry. errors: ${validationErrors} (E: beee1893050f9bcf9842c66831595225)`);
|
|
477
|
+
}
|
|
478
|
+
// we know we have a valid agent witness comment at this point. So we
|
|
479
|
+
// can pull extract the textSrc, etc., from it.
|
|
480
|
+
let { safeIbCommentMetadataText: addlMetadataText } = parseCommentIb({ ib: commentIbGib.ib });
|
|
481
|
+
if (!addlMetadataText) {
|
|
482
|
+
throw new Error(`(UNEXPECTED) addlMetaDataText falsy? we just validated the comment ibgib, so there should be the expected shape of the comment.ib. (E: facf5801f9ba158b1526dd09d0e1b325)`);
|
|
483
|
+
}
|
|
484
|
+
let { textSrc, timestampInTicks, errorMsg, other } = parseAddlMetadataTextForAgentText({ addlMetadataText, ifError: 'warn' });
|
|
485
|
+
if (errorMsg) {
|
|
486
|
+
throw new Error(`(UNEXPECTED) errorMsg is truthy after parse addl metadata from comment.ib? we just validated the comment ibgib, so there should be the expected shape of the comment.ib. (? (E: 7fd7fac50851916f39ceccbe93446425)`);
|
|
487
|
+
}
|
|
488
|
+
if (!commentIbGib.data) {
|
|
489
|
+
throw new Error(`(UNEXPECTED) commentIbGib.data falsy? (E: 8ce54d28219237feddf8f25b5846cc25)`);
|
|
490
|
+
}
|
|
491
|
+
if (!commentIbGib.data.text) {
|
|
492
|
+
throw new Error(`(UNEXPECTED) commentIbGib.data.text falsy? (E: 8556fc95c401d1b5441454fceb8f2f25)`);
|
|
493
|
+
}
|
|
494
|
+
const isFCR = isFunctionCallRequestComment({ ibGib: commentIbGib });
|
|
495
|
+
if (isFCR) {
|
|
496
|
+
// 1. FCR should generate two entries: the function call entry and
|
|
497
|
+
// the function response entry
|
|
498
|
+
// 2. the role of the function call should be "model" and the role for
|
|
499
|
+
// the function response should be "function"
|
|
500
|
+
// 3. The FCR's info ibgibs must be loaded and iterated, with each
|
|
501
|
+
// one containing info for a part of the function call entry and a
|
|
502
|
+
// part for the function response entry.
|
|
503
|
+
const functionInfoIbGibs = await this.getFunctionInfoIbGibs({ fcrCommentIbGib: commentIbGib });
|
|
504
|
+
const functionCallParts = [];
|
|
505
|
+
const functionResponseParts = [];
|
|
506
|
+
for (let functionInfoIbGib of functionInfoIbGibs) {
|
|
507
|
+
let { call, response } = getFunctionCallAndResponseParts({ functionInfoIbGib });
|
|
508
|
+
if (!call) {
|
|
509
|
+
throw new Error(`(UNEXPECTED) call falsy? (E: 5c8f3bd6de3b300e1c105b9603bb7b25)`);
|
|
510
|
+
}
|
|
511
|
+
if (!response) {
|
|
512
|
+
throw new Error(`(UNEXPECTED) response falsy? (E: d0388c838975c93126c1a6d64f781d25)`);
|
|
513
|
+
}
|
|
514
|
+
if (call.functionCall.name !== response.functionResponse.name) {
|
|
515
|
+
throw new Error(`(UNEXPECTED) functionCall.name !== functionResponse.name? (E: e49f0d60093354db2b6ad17fdf86d425)`);
|
|
516
|
+
}
|
|
517
|
+
functionCallParts.push(call);
|
|
518
|
+
functionResponseParts.push(response);
|
|
519
|
+
}
|
|
520
|
+
// at this point we have a collection of one or more function
|
|
521
|
+
// call parts that correspond to a single chat message that the
|
|
522
|
+
// model generated, so these will be role: "model". we also
|
|
523
|
+
// have function response parts that directly correspond to
|
|
524
|
+
// those function call parts one-to-one, in order. So we add two entries to the chat:
|
|
525
|
+
// 1. msg with function call entry/entries from role: "model"
|
|
526
|
+
// 2. msg with function response entry/entries from role: "function"
|
|
527
|
+
const functionCallEntry = {
|
|
528
|
+
src: TextSource.AI,
|
|
529
|
+
content: {
|
|
530
|
+
role: textSourceToGeminiRole('ai'),
|
|
531
|
+
parts: functionCallParts,
|
|
532
|
+
},
|
|
533
|
+
};
|
|
534
|
+
const functionResponseEntry = {
|
|
535
|
+
src: TextSource.FUNCTION,
|
|
536
|
+
// src: TextSource.AI,
|
|
537
|
+
content: {
|
|
538
|
+
// role: textSourceToGeminiRole('function'), // user
|
|
539
|
+
role: textSourceToGeminiRole(TextSource.FUNCTION),
|
|
540
|
+
parts: functionResponseParts,
|
|
541
|
+
},
|
|
542
|
+
};
|
|
543
|
+
return [functionCallEntry, functionResponseEntry];
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
// non-FCR should just generate a single text part entry
|
|
547
|
+
return [{
|
|
548
|
+
src: textSrc,
|
|
549
|
+
// text: commentIbGib.data.text,
|
|
550
|
+
content: {
|
|
551
|
+
role: textSourceToGeminiRole(textSrc),
|
|
552
|
+
parts: [{ text: commentIbGib.data.text }],
|
|
553
|
+
}
|
|
554
|
+
}];
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
finally {
|
|
562
|
+
if (logalot) {
|
|
563
|
+
console.log(`${lc} complete.`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async promptOneOff(opts) {
|
|
568
|
+
const lc = `${this.lc}[${this.promptOneOff.name}]`;
|
|
569
|
+
try {
|
|
570
|
+
if (logalot) {
|
|
571
|
+
console.log(`${lc} starting... (I: genuuid)`);
|
|
572
|
+
}
|
|
573
|
+
const { text, systemInstructions, } = opts;
|
|
574
|
+
if (!text) {
|
|
575
|
+
throw new Error(`(UNEXPECTED) opts.text falsy? (E: genuuid)`);
|
|
576
|
+
}
|
|
577
|
+
if (!this.data) {
|
|
578
|
+
throw new Error(`(UNEXPECTED) this.data falsy? (E: genuuid)`);
|
|
579
|
+
}
|
|
580
|
+
const { api, model } = this.data;
|
|
581
|
+
if (api !== 'gemini') {
|
|
582
|
+
throw new Error(`api not supported: ${api} (E: genuuid)`);
|
|
583
|
+
}
|
|
584
|
+
// todo: refactor gemini-specific code into its own descendant class
|
|
585
|
+
if (logalot) {
|
|
586
|
+
console.log(`${lc} calling gemini api with model: ${model} (I: genuuid)`);
|
|
587
|
+
}
|
|
588
|
+
const apiKey = await this.fnGetAPIKey();
|
|
589
|
+
if (!apiKey) {
|
|
590
|
+
console.error(`${lc} apiKey falsy. did you set this.fnGetAPIKey (E: genuuid)`);
|
|
591
|
+
return undefined; /* <<<< returns early */
|
|
592
|
+
}
|
|
593
|
+
this._genAI ??= new GoogleGenerativeAI(apiKey);
|
|
594
|
+
/**
|
|
595
|
+
* need to be able to call this function with retries with different
|
|
596
|
+
* models, depending on error code received when generating text.
|
|
597
|
+
*
|
|
598
|
+
* ## driving intent
|
|
599
|
+
*
|
|
600
|
+
* I am getting a 503 error saying the model is overloaded. We need
|
|
601
|
+
* to have a backup model that is hardcoded and updated via source
|
|
602
|
+
* code until we get a more robust model system.
|
|
603
|
+
*
|
|
604
|
+
* @param modelStr to use
|
|
605
|
+
* @param isRetry if true, this indicates this is aleady a retry and should throw if fails
|
|
606
|
+
*/
|
|
607
|
+
const fnGoModel = async (modelStr) => {
|
|
608
|
+
if (!this._genAI) {
|
|
609
|
+
throw new Error(`(UNEXPECTED) this._genAI falsy? (E: genuuid)`);
|
|
610
|
+
}
|
|
611
|
+
const genModel = this._genAI.getGenerativeModel({
|
|
612
|
+
model: modelStr,
|
|
613
|
+
systemInstruction: systemInstructions,
|
|
614
|
+
});
|
|
615
|
+
/**
|
|
616
|
+
* We start a "chat", _BUT ONLY TO USE THE HISTORY MECHANISM_.
|
|
617
|
+
* Really we use this as a one-off, but we do not know how to mimic
|
|
618
|
+
* the "history" so that the model understands to only respond to
|
|
619
|
+
* the most recent prompt.
|
|
620
|
+
*/
|
|
621
|
+
// const chat = genModel.startChat({
|
|
622
|
+
// history: chatPromptHistoryParts.map(x => x.content),
|
|
623
|
+
// });
|
|
624
|
+
const result = await genModel.generateContent(text);
|
|
625
|
+
if (result.response) {
|
|
626
|
+
return result.response.text();
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
throw new Error(`not implemented (E: bbf05fe00da23d5b16c223bd200eaa25)`);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
let result = undefined;
|
|
633
|
+
let tryCount = 0;
|
|
634
|
+
let modelStr = model;
|
|
635
|
+
let retryDelayInSeconds = 1;
|
|
636
|
+
do {
|
|
637
|
+
tryCount++;
|
|
638
|
+
retryDelayInSeconds++;
|
|
639
|
+
try {
|
|
640
|
+
let x;
|
|
641
|
+
result = await fnGoModel(modelStr);
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
if (error.status && error.status === GEMINI_ERROR_STATUS_MODEL_OVERLOADED) {
|
|
646
|
+
if (modelStr === GEMINI_BACKUP_MODEL_STR) {
|
|
647
|
+
// already is the backup model, so we just fail
|
|
648
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_MODEL_OVERLOADED ${GEMINI_ERROR_STATUS_MODEL_OVERLOADED}. we are already using the backup model, so SOL here. will try again... error (${error.status}): ${extractErrorMsg(error)} (E: 9bb63cb520b8bd3bb85d2ca20715c825)`);
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
// model is overloaded, try using the backup
|
|
652
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_MODEL_OVERLOADED ${GEMINI_ERROR_STATUS_MODEL_OVERLOADED}. will try using backup model (${GEMINI_BACKUP_MODEL_STR}) for this next call. error (${error.status}): ${extractErrorMsg(error)} (E: b07a041bb97ea95b03cd6f9856f01525)`);
|
|
653
|
+
modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
else if (error.status && error.status === GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED) {
|
|
657
|
+
// quota exceeded, either try backup or wait for retry
|
|
658
|
+
if (modelStr === GEMINI_BACKUP_MODEL_STR) {
|
|
659
|
+
// nothing else to try, wait retry amount if possible
|
|
660
|
+
let errorDetails = error.errorDetails;
|
|
661
|
+
let retryInfo = errorDetails.find(x => x['@type'] === GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO);
|
|
662
|
+
retryDelayInSeconds = 30;
|
|
663
|
+
if (retryInfo && retryInfo[GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY]) {
|
|
664
|
+
// get more accurate wait time
|
|
665
|
+
let retryStr = retryInfo[GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY];
|
|
666
|
+
// retryStr from testing is in seconds, e.g., "41s". IF it's longer than a minute, I don't know/care (too long)
|
|
667
|
+
if (retryStr.match(/^\d+s$/)) {
|
|
668
|
+
// valid retry str in seconds
|
|
669
|
+
retryDelayInSeconds = Number.parseInt(retryStr.substring(0, retryStr.length - 1));
|
|
670
|
+
if (Number.isNaN(retryDelayInSeconds)) {
|
|
671
|
+
retryDelayInSeconds = 30;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
retryDelayInSeconds = 30;
|
|
676
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED ${GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED}. Could not find valid retryInfo (errorDetails with retry info with a ${GEMINI_ERROR_DETAILS_TYPE_RETRY_INFO_RETRY_DELAY_KEY} with an "s"). So we'll just try waiting ${retryDelayInSeconds} seconds: ${extractErrorMsg(error)} (E: 986d9883fc72bf156f1691183e27ee25)`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model: GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED ${GEMINI_ERROR_STATUS_RATE_QUOTA_EXCEEDED}. will try using backup model (${GEMINI_BACKUP_MODEL_STR}) for this next call. error (${error.status}): ${extractErrorMsg(error)} (E: 637ed809c659f55738becab83fc01825)`);
|
|
682
|
+
}
|
|
683
|
+
modelStr = GEMINI_BACKUP_MODEL_STR;
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
console.error(`${lc}[fnGoModel][${modelStr}] error trying to get result from model. error (${error.status}): ${extractErrorMsg(error)} (E: a67d595c8ed313d458369d4d0b3e7f25)`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (tryCount > 1) {
|
|
690
|
+
await delay(retryDelayInSeconds * 1000); // nothing fancy right now
|
|
691
|
+
}
|
|
692
|
+
} while (!result && tryCount < GEMINI_MAX_TRY_COUNT);
|
|
693
|
+
return result;
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
697
|
+
throw error;
|
|
698
|
+
}
|
|
699
|
+
finally {
|
|
700
|
+
if (logalot) {
|
|
701
|
+
console.log(`${lc} complete.`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Gets the function info ibgibs associated with an {@link fcrCommentIbGib}
|
|
707
|
+
* (Function Call Request IbGib) from this agent's superSpace.
|
|
708
|
+
*
|
|
709
|
+
* Note that these are fully loaded ibgibs based on just the addresses of
|
|
710
|
+
* the FCR.
|
|
711
|
+
*
|
|
712
|
+
* @see {@link getSuperSpace}
|
|
713
|
+
*
|
|
714
|
+
* @returns the array of function info ibgibs that correspond to the FCR
|
|
715
|
+
*/
|
|
716
|
+
async getFunctionInfoIbGibs({ fcrCommentIbGib }) {
|
|
717
|
+
const lc = `[${this.getFunctionInfoIbGibs.name}]`;
|
|
718
|
+
try {
|
|
719
|
+
if (logalot) {
|
|
720
|
+
console.log(`${lc} starting... (I: 976a684b7ae58cda523b17fc0c62e325)`);
|
|
721
|
+
}
|
|
722
|
+
let resFunctionInfoIbGibs = [];
|
|
723
|
+
// #region prepare
|
|
724
|
+
if (!fcrCommentIbGib) {
|
|
725
|
+
throw new Error(`${lc} fcrCommentIbGib is falsy. (E: a01c80f415ab8737a81b7b2a2f479f25)`);
|
|
726
|
+
}
|
|
727
|
+
if (!fcrCommentIbGib.data) {
|
|
728
|
+
throw new Error(`${lc} fcrCommentIbGib.data is falsy. (E: a03bc3662a8d6f69c1c077605727a025)`);
|
|
729
|
+
}
|
|
730
|
+
const metaspace = this._metaspace;
|
|
731
|
+
if (!metaspace) {
|
|
732
|
+
throw new Error(`(UNEXPECTED) this.metaspace falsy. (E: 997d071847c5d7e80692f48191244e25)`);
|
|
733
|
+
}
|
|
734
|
+
const superSpace = await this.getSuperSpace(); // Use getSuperSpace to get the agent's super space.
|
|
735
|
+
if (!superSpace) {
|
|
736
|
+
throw new Error(`(UNEXPECTED) superSpace falsy? (E: dd1600f15e1e659c01f73991656a3325)`);
|
|
737
|
+
}
|
|
738
|
+
// #endregion prepare
|
|
739
|
+
const functionInfoAddrs = (fcrCommentIbGib.rel8ns?.[FUNCTION_INFO_REL8N_NAME] ?? []);
|
|
740
|
+
if (functionInfoAddrs.length === 0) {
|
|
741
|
+
if (logalot) {
|
|
742
|
+
console.warn(`${lc} no functionInfoAddrs (I: 5f8965e92c305689c11677a1148b7425)`);
|
|
743
|
+
}
|
|
744
|
+
return []; /* <<<< returns early */
|
|
745
|
+
}
|
|
746
|
+
if (logalot) {
|
|
747
|
+
console.log(`${lc} functionInfoAddrs: ${functionInfoAddrs} (I: e7b1f5a4576c493326b913e48a505e25)`);
|
|
748
|
+
}
|
|
749
|
+
// get those ibgibs that correspond to the addrs in a single call
|
|
750
|
+
// using this agent's metaspace.get and the superSpace
|
|
751
|
+
const resGetFunctionInfos = await metaspace.get({
|
|
752
|
+
addrs: functionInfoAddrs,
|
|
753
|
+
space: superSpace,
|
|
754
|
+
});
|
|
755
|
+
if (!resGetFunctionInfos.success || !resGetFunctionInfos.ibGibs || resGetFunctionInfos.ibGibs.length !== functionInfoAddrs.length) {
|
|
756
|
+
throw new Error(`${lc} could not retrieve function info ibgibs. errorMsg: ${resGetFunctionInfos.errorMsg ?? 'unknown error (E: 164246a6661d49f2b21d1b6769139625)'} (E: 0736d824876e420f91c089925191d425)`);
|
|
757
|
+
}
|
|
758
|
+
resFunctionInfoIbGibs = resGetFunctionInfos.ibGibs;
|
|
759
|
+
if (logalot) {
|
|
760
|
+
console.log(`${lc} resFunctionInfoIbGibs: ${pretty(resFunctionInfoIbGibs.map(x => getIbGibAddr({ ibGib: x })))} (I: a5661b5c449608f0e8d773135a599a25)`);
|
|
761
|
+
}
|
|
762
|
+
return resFunctionInfoIbGibs;
|
|
763
|
+
}
|
|
764
|
+
catch (error) {
|
|
765
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
766
|
+
throw error;
|
|
767
|
+
}
|
|
768
|
+
finally {
|
|
769
|
+
if (logalot) {
|
|
770
|
+
console.log(`${lc} complete.`);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* loads the dto as expected, then sets the class's properties.
|
|
776
|
+
* @param dto with ibgib props (ib,gib,data,rel8ns)
|
|
777
|
+
*/
|
|
778
|
+
async loadIbGibDto(dto) {
|
|
779
|
+
const lc = `[${this.loadIbGibDto.name}]`;
|
|
780
|
+
try {
|
|
781
|
+
if (logalot) {
|
|
782
|
+
console.log(`${lc} starting... (I: cb0b1e9e22fce321ca9a26e7a5d4c825)`);
|
|
783
|
+
}
|
|
784
|
+
await super.loadIbGibDto(dto);
|
|
785
|
+
if (!this.data) {
|
|
786
|
+
throw new Error(`(UNEXPECTED) this.data falsy after load dto? (E: 77aecd066b0bbbd0c66e2658519bdb25)`);
|
|
787
|
+
}
|
|
788
|
+
const metaspace = this._metaspace;
|
|
789
|
+
if (!metaspace) {
|
|
790
|
+
throw new Error(`(UNEXPECTED) metaspace falsy? (E: e5762b1e3f77f84ca338641edc011225)`);
|
|
791
|
+
}
|
|
792
|
+
const superSpace = await this.getSuperSpace();
|
|
793
|
+
// const subSpace = await this.getSubSpace(); // unused now, but will be used once we get subspace mechanism going
|
|
794
|
+
// available functions
|
|
795
|
+
// first prune existing available functions...
|
|
796
|
+
// await this.pruneDeprecatedAvailableFunctions_ifApplicable({
|
|
797
|
+
// dto, metaspace, superSpace,
|
|
798
|
+
// });
|
|
799
|
+
// ...now populate this.availableFunctions
|
|
800
|
+
// we must do this in the timeline lock scope, because if the
|
|
801
|
+
// timeline is updated mid-execution
|
|
802
|
+
const fn = async () => {
|
|
803
|
+
this.availableFunctions = new Map();
|
|
804
|
+
for (const nameOrId of this.data.availableFunctionNameOrIds) {
|
|
805
|
+
if (!nameOrId) {
|
|
806
|
+
throw new Error(`(UNEXPECTED) nameOrId falsy, driven by this.data.availableFunctionNameOrIds? somehow a falsy nameOrId saved? (E: 7b63f177624de2415e1569e96ef8d125)`);
|
|
807
|
+
}
|
|
808
|
+
const info = getAllFunctionInfos().get(nameOrId);
|
|
809
|
+
if (info) {
|
|
810
|
+
this.availableFunctions.set(nameOrId, info);
|
|
811
|
+
}
|
|
812
|
+
else {
|
|
813
|
+
if (getDeprecatedFunctionInfoNames().includes(nameOrId)) {
|
|
814
|
+
if (logalot) {
|
|
815
|
+
console.log(`${lc} function nameOrId (${nameOrId}) found as deprecated. not adding to available functions on agent. (I: 983864ad5cd8af915fb135580e455425)`);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
console.error(`no function info in getAllFunctionInfos() found corresponding to nameOrId (${nameOrId}) and this was not found in getDeprecatedFunctionInfoNames(). this is logged here but we're not throwing. (E: db0da9880cf1e414c3f1078d3e9f0b25)`);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
// comment ibgibs
|
|
824
|
+
// todo: refactor the following two code blocks with a helper function for DRY (would require a lambda for setting the prop I think but this is a lower priority ATOW 01/2024...do this if I revisit this section of code by necessity)
|
|
825
|
+
// todo: implement caching for comment ibgibs
|
|
826
|
+
const rel8dAddrs_system = this.rel8ns?.system ?? [];
|
|
827
|
+
if (rel8dAddrs_system.length > 0) {
|
|
828
|
+
const resGet_systemComments = await metaspace.get({
|
|
829
|
+
addrs: rel8dAddrs_system, space: superSpace,
|
|
830
|
+
});
|
|
831
|
+
if (!resGet_systemComments.success || resGet_systemComments.errorMsg) {
|
|
832
|
+
throw new Error(`couldn't get system comments. error: ${extractErrorMsg(resGet_systemComments.errorMsg ?? 'unknown error (E: c0b4d7aab724bcf58e88ffd496de8825)')} (E: 7925d4b5ec3a8f7a648c109941c38a25)`);
|
|
833
|
+
}
|
|
834
|
+
else if ((resGet_systemComments.ibGibs ?? []).length !== rel8dAddrs_system.length) {
|
|
835
|
+
throw new Error(`(UNEXPECTED) (resGet_systemComments.ibGibs ?? []).length !== rel8dAddrs_system.length, but resGet.success truthy and resGet.errorMsg falsy? (E: 2055553b602e6c2fe49e956a1e423f25)`);
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
this.commentIbGibs_system = resGet_systemComments.ibGibs;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const rel8dAddrs_chat = this.rel8ns?.chat ?? [];
|
|
842
|
+
if (rel8dAddrs_chat.length > 0) {
|
|
843
|
+
const resGet_chatComments = await metaspace.get({
|
|
844
|
+
addrs: rel8dAddrs_chat, space: superSpace,
|
|
845
|
+
});
|
|
846
|
+
if (!resGet_chatComments.success || resGet_chatComments.errorMsg) {
|
|
847
|
+
throw new Error(`couldn't get chat comments. error: ${extractErrorMsg(resGet_chatComments.errorMsg ?? 'unknown error (E: c0b4d7aab724bcf58e88ffd496de8825)')} (E: 7925d4b5ec3a8f7a648c109941c38a25)`);
|
|
848
|
+
}
|
|
849
|
+
else if ((resGet_chatComments.ibGibs ?? []).length !== rel8dAddrs_chat.length) {
|
|
850
|
+
throw new Error(`(UNEXPECTED) (resGet_chatComments.ibGibs ?? []).length !== rel8dAddrs_chat.length, but resGet.success truthy and resGet.errorMsg falsy? (E: 2055553b602e6c2fe49e956a1e423f25)`);
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
this.commentIbGibs_chat = resGet_chatComments.ibGibs;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
// const lockScope = await getLockScope({ timeline: this });
|
|
858
|
+
await execInSpaceWithLocking({
|
|
859
|
+
scope: 'prune',
|
|
860
|
+
secondsValid: 60,
|
|
861
|
+
maxDelayMs: 100,
|
|
862
|
+
maxLockAttempts: 1800,
|
|
863
|
+
space: superSpace,
|
|
864
|
+
callerInstanceId: getTimestampInTicks(),
|
|
865
|
+
fn,
|
|
866
|
+
});
|
|
867
|
+
// todo: load subspace artifacts once we get that mechanism going
|
|
868
|
+
}
|
|
869
|
+
catch (error) {
|
|
870
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
871
|
+
throw error;
|
|
872
|
+
}
|
|
873
|
+
finally {
|
|
874
|
+
if (logalot) {
|
|
875
|
+
console.log(`${lc} complete.`);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
// register the factory function with the agents svc
|
|
881
|
+
setTimeout(() => {
|
|
882
|
+
let agentsSvc = getAgentsSvc();
|
|
883
|
+
agentsSvc.registerFactory({
|
|
884
|
+
classname: AgentWitnessGemini_V1.name,
|
|
885
|
+
fnDtoToAgentWitness: async (dto) => {
|
|
886
|
+
if (!dto.data) {
|
|
887
|
+
return { applies: false, };
|
|
888
|
+
}
|
|
889
|
+
else if (!dto.data.classname) {
|
|
890
|
+
return { applies: false, };
|
|
891
|
+
}
|
|
892
|
+
else if (dto.data.classname === AgentWitnessGemini_V1.name) {
|
|
893
|
+
const agent = await agentIbGibDtoToWitness({
|
|
894
|
+
agentIbGib: dto,
|
|
895
|
+
});
|
|
896
|
+
return { applies: true, agent };
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
return { applies: false, };
|
|
900
|
+
}
|
|
901
|
+
},
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
export function getTextPartForCurrentContextTjpAddr({ currentContextTjpAddr }) {
|
|
905
|
+
const lc = `[${getTextPartForCurrentContextTjpAddr.name}]`;
|
|
906
|
+
try {
|
|
907
|
+
if (logalot) {
|
|
908
|
+
console.log(`${lc} starting... (I: 7edafbba277d57eae51af325cf7eb225)`);
|
|
909
|
+
}
|
|
910
|
+
const info = getGibInfo({ ibGibAddr: currentContextTjpAddr });
|
|
911
|
+
// if (info.isPrimitive) {
|
|
912
|
+
// do I even care at this point? maybe I'll use primitives as some
|
|
913
|
+
// kind of global variable reference or something...commenting out
|
|
914
|
+
// because maybe YAGNI
|
|
915
|
+
// }
|
|
916
|
+
return `Your current context ibGibAddr is ${currentContextTjpAddr}\nIt is very important that you use THIS context address. THIS context address takes precedence over previous contexts in your system chat history, because those chats may be from previous sessions per the user's POV. If there are any doubts, like if you're saying something and the user is not responding, then this may be the reason. You should call the function to get your context to be sure you are talking in the right one.`;
|
|
917
|
+
}
|
|
918
|
+
catch (error) {
|
|
919
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
920
|
+
throw error;
|
|
921
|
+
}
|
|
922
|
+
finally {
|
|
923
|
+
if (logalot) {
|
|
924
|
+
console.log(`${lc} complete.`);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
//# sourceMappingURL=agent-witness-gemini-v1.mjs.map
|