@ibgib/core-gib 0.0.4
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/.vscode/core-gib-snippets.code-snippets +189 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +56 -0
- package/.vscode/tasks.json +37 -0
- package/CHANGELOG.md +11 -0
- package/README.md +215 -0
- package/dist/common/aws-constants.d.mts +7 -0
- package/dist/common/aws-constants.d.mts.map +1 -0
- package/dist/common/aws-constants.mjs +7 -0
- package/dist/common/aws-constants.mjs.map +1 -0
- package/dist/common/bin/bin-types.d.mts +17 -0
- package/dist/common/bin/bin-types.d.mts.map +1 -0
- package/dist/common/bin/bin-types.mjs +3 -0
- package/dist/common/bin/bin-types.mjs.map +1 -0
- package/dist/common/cache/cache-types.d.mts +57 -0
- package/dist/common/cache/cache-types.d.mts.map +1 -0
- package/dist/common/cache/cache-types.mjs +2 -0
- package/dist/common/cache/cache-types.mjs.map +1 -0
- package/dist/common/comment/comment-constants.d.mts +11 -0
- package/dist/common/comment/comment-constants.d.mts.map +1 -0
- package/dist/common/comment/comment-constants.mjs +11 -0
- package/dist/common/comment/comment-constants.mjs.map +1 -0
- package/dist/common/comment/comment-helper.d.mts +59 -0
- package/dist/common/comment/comment-helper.d.mts.map +1 -0
- package/dist/common/comment/comment-helper.mjs +173 -0
- package/dist/common/comment/comment-helper.mjs.map +1 -0
- package/dist/common/comment/comment-types.d.mts +16 -0
- package/dist/common/comment/comment-types.d.mts.map +1 -0
- package/dist/common/comment/comment-types.mjs +2 -0
- package/dist/common/comment/comment-types.mjs.map +1 -0
- package/dist/common/display/display-helper.d.mts +19 -0
- package/dist/common/display/display-helper.d.mts.map +1 -0
- package/dist/common/display/display-helper.mjs +68 -0
- package/dist/common/display/display-helper.mjs.map +1 -0
- package/dist/common/display/display-types.d.mts +97 -0
- package/dist/common/display/display-types.d.mts.map +1 -0
- package/dist/common/display/display-types.mjs +37 -0
- package/dist/common/display/display-types.mjs.map +1 -0
- package/dist/common/encrypt/encrypt-constants.d.mts +27 -0
- package/dist/common/encrypt/encrypt-constants.d.mts.map +1 -0
- package/dist/common/encrypt/encrypt-constants.mjs +27 -0
- package/dist/common/encrypt/encrypt-constants.mjs.map +1 -0
- package/dist/common/encrypt/encrypt-types.d.mts +116 -0
- package/dist/common/encrypt/encrypt-types.d.mts.map +1 -0
- package/dist/common/encrypt/encrypt-types.mjs +9 -0
- package/dist/common/encrypt/encrypt-types.mjs.map +1 -0
- package/dist/common/error/error-constants.d.mts +9 -0
- package/dist/common/error/error-constants.d.mts.map +1 -0
- package/dist/common/error/error-constants.mjs +9 -0
- package/dist/common/error/error-constants.mjs.map +1 -0
- package/dist/common/error/error-helper.d.mts +43 -0
- package/dist/common/error/error-helper.d.mts.map +1 -0
- package/dist/common/error/error-helper.mjs +167 -0
- package/dist/common/error/error-helper.mjs.map +1 -0
- package/dist/common/error/error-types.d.mts +58 -0
- package/dist/common/error/error-types.d.mts.map +1 -0
- package/dist/common/error/error-types.mjs +2 -0
- package/dist/common/error/error-types.mjs.map +1 -0
- package/dist/common/form/form-helper.d.mts +97 -0
- package/dist/common/form/form-helper.d.mts.map +1 -0
- package/dist/common/form/form-helper.mjs +185 -0
- package/dist/common/form/form-helper.mjs.map +1 -0
- package/dist/common/form/form-items.d.mts +229 -0
- package/dist/common/form/form-items.d.mts.map +1 -0
- package/dist/common/form/form-items.mjs +63 -0
- package/dist/common/form/form-items.mjs.map +1 -0
- package/dist/common/import-export/import-export-types.d.mts +18 -0
- package/dist/common/import-export/import-export-types.d.mts.map +1 -0
- package/dist/common/import-export/import-export-types.mjs +2 -0
- package/dist/common/import-export/import-export-types.mjs.map +1 -0
- package/dist/common/legacy/legacy-types.d.mts +2 -0
- package/dist/common/legacy/legacy-types.d.mts.map +1 -0
- package/dist/common/legacy/legacy-types.mjs +2 -0
- package/dist/common/legacy/legacy-types.mjs.map +1 -0
- package/dist/common/link/link-constants.d.mts +2 -0
- package/dist/common/link/link-constants.d.mts.map +1 -0
- package/dist/common/link/link-constants.mjs +2 -0
- package/dist/common/link/link-constants.mjs.map +1 -0
- package/dist/common/link/link-helper.d.mts +37 -0
- package/dist/common/link/link-helper.d.mts.map +1 -0
- package/dist/common/link/link-helper.mjs +143 -0
- package/dist/common/link/link-helper.mjs.map +1 -0
- package/dist/common/link/link-types.d.mts +14 -0
- package/dist/common/link/link-types.d.mts.map +1 -0
- package/dist/common/link/link-types.mjs +2 -0
- package/dist/common/link/link-types.mjs.map +1 -0
- package/dist/common/other/graph-helper.d.mts +166 -0
- package/dist/common/other/graph-helper.d.mts.map +1 -0
- package/dist/common/other/graph-helper.mjs +710 -0
- package/dist/common/other/graph-helper.mjs.map +1 -0
- package/dist/common/other/ibgib-helper.d.mts +245 -0
- package/dist/common/other/ibgib-helper.d.mts.map +1 -0
- package/dist/common/other/ibgib-helper.mjs +641 -0
- package/dist/common/other/ibgib-helper.mjs.map +1 -0
- package/dist/common/other/other-constants.d.mts +53 -0
- package/dist/common/other/other-constants.d.mts.map +1 -0
- package/dist/common/other/other-constants.mjs +67 -0
- package/dist/common/other/other-constants.mjs.map +1 -0
- package/dist/common/other/other-types.d.mts +166 -0
- package/dist/common/other/other-types.d.mts.map +1 -0
- package/dist/common/other/other-types.mjs +30 -0
- package/dist/common/other/other-types.mjs.map +1 -0
- package/dist/common/other/svg-constants.d.mts +2 -0
- package/dist/common/other/svg-constants.d.mts.map +1 -0
- package/dist/common/other/svg-constants.mjs +2 -0
- package/dist/common/other/svg-constants.mjs.map +1 -0
- package/dist/common/other/svg-helper.d.mts +54 -0
- package/dist/common/other/svg-helper.d.mts.map +1 -0
- package/dist/common/other/svg-helper.mjs +170 -0
- package/dist/common/other/svg-helper.mjs.map +1 -0
- package/dist/common/pic/pic-constants.d.mts +13 -0
- package/dist/common/pic/pic-constants.d.mts.map +1 -0
- package/dist/common/pic/pic-constants.mjs +13 -0
- package/dist/common/pic/pic-constants.mjs.map +1 -0
- package/dist/common/pic/pic-helper.d.mts +70 -0
- package/dist/common/pic/pic-helper.d.mts.map +1 -0
- package/dist/common/pic/pic-helper.mjs +235 -0
- package/dist/common/pic/pic-helper.mjs.map +1 -0
- package/dist/common/pic/pic-types.d.mts +23 -0
- package/dist/common/pic/pic-types.d.mts.map +1 -0
- package/dist/common/pic/pic-types.mjs +2 -0
- package/dist/common/pic/pic-types.mjs.map +1 -0
- package/dist/common/root/root-constants.d.mts +40 -0
- package/dist/common/root/root-constants.d.mts.map +1 -0
- package/dist/common/root/root-constants.mjs +40 -0
- package/dist/common/root/root-constants.mjs.map +1 -0
- package/dist/common/root/root-types.d.mts +9 -0
- package/dist/common/root/root-types.d.mts.map +1 -0
- package/dist/common/root/root-types.mjs +2 -0
- package/dist/common/root/root-types.mjs.map +1 -0
- package/dist/common/tag/tag-constants.d.mts +21 -0
- package/dist/common/tag/tag-constants.d.mts.map +1 -0
- package/dist/common/tag/tag-constants.mjs +28 -0
- package/dist/common/tag/tag-constants.mjs.map +1 -0
- package/dist/common/tag/tag-types.d.mts +14 -0
- package/dist/common/tag/tag-types.d.mts.map +1 -0
- package/dist/common/tag/tag-types.mjs +2 -0
- package/dist/common/tag/tag-types.mjs.map +1 -0
- package/dist/core-constants.d.mts +89 -0
- package/dist/core-constants.d.mts.map +1 -0
- package/dist/core-constants.mjs +484 -0
- package/dist/core-constants.mjs.map +1 -0
- package/dist/core-helper.d.mts +6 -0
- package/dist/core-helper.d.mts.map +1 -0
- package/dist/core-helper.mjs +28 -0
- package/dist/core-helper.mjs.map +1 -0
- package/dist/core-types.d.mts +520 -0
- package/dist/core-types.d.mts.map +1 -0
- package/dist/core-types.mjs +2 -0
- package/dist/core-types.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/witness/app/app-base-v1.d.mts +130 -0
- package/dist/witness/app/app-base-v1.d.mts.map +1 -0
- package/dist/witness/app/app-base-v1.mjs +462 -0
- package/dist/witness/app/app-base-v1.mjs.map +1 -0
- package/dist/witness/app/app-constants.d.mts +10 -0
- package/dist/witness/app/app-constants.d.mts.map +1 -0
- package/dist/witness/app/app-constants.mjs +13 -0
- package/dist/witness/app/app-constants.mjs.map +1 -0
- package/dist/witness/app/app-helper.d.mts +85 -0
- package/dist/witness/app/app-helper.d.mts.map +1 -0
- package/dist/witness/app/app-helper.mjs +258 -0
- package/dist/witness/app/app-helper.mjs.map +1 -0
- package/dist/witness/app/app-types.d.mts +211 -0
- package/dist/witness/app/app-types.d.mts.map +1 -0
- package/dist/witness/app/app-types.mjs +49 -0
- package/dist/witness/app/app-types.mjs.map +1 -0
- package/dist/witness/app/chat-app/chat-app-types.d.mts +18 -0
- package/dist/witness/app/chat-app/chat-app-types.d.mts.map +1 -0
- package/dist/witness/app/chat-app/chat-app-types.mjs +25 -0
- package/dist/witness/app/chat-app/chat-app-types.mjs.map +1 -0
- package/dist/witness/app/flash-app/flash-app-types.d.mts +16 -0
- package/dist/witness/app/flash-app/flash-app-types.d.mts.map +1 -0
- package/dist/witness/app/flash-app/flash-app-types.mjs +23 -0
- package/dist/witness/app/flash-app/flash-app-types.mjs.map +1 -0
- package/dist/witness/app/raw-app/raw-app-types.d.mts +18 -0
- package/dist/witness/app/raw-app/raw-app-types.d.mts.map +1 -0
- package/dist/witness/app/raw-app/raw-app-types.mjs +25 -0
- package/dist/witness/app/raw-app/raw-app-types.mjs.map +1 -0
- package/dist/witness/app/todo-app/todo-app-types.d.ts +33 -0
- package/dist/witness/app/todo-app/todo-app-types.d.ts.map +1 -0
- package/dist/witness/app/todo-app/todo-app-types.js +31 -0
- package/dist/witness/app/todo-app/todo-app-types.js.map +1 -0
- package/dist/witness/robbot/robbot-base-v1.d.ts +432 -0
- package/dist/witness/robbot/robbot-base-v1.d.ts.map +1 -0
- package/dist/witness/robbot/robbot-base-v1.js +1407 -0
- package/dist/witness/robbot/robbot-base-v1.js.map +1 -0
- package/dist/witness/robbot/robbot-constants.d.mts +24 -0
- package/dist/witness/robbot/robbot-constants.d.mts.map +1 -0
- package/dist/witness/robbot/robbot-constants.mjs +24 -0
- package/dist/witness/robbot/robbot-constants.mjs.map +1 -0
- package/dist/witness/robbot/robbot-helper.d.mts +152 -0
- package/dist/witness/robbot/robbot-helper.d.mts.map +1 -0
- package/dist/witness/robbot/robbot-helper.mjs +609 -0
- package/dist/witness/robbot/robbot-helper.mjs.map +1 -0
- package/dist/witness/robbot/robbot-types.d.mts +539 -0
- package/dist/witness/robbot/robbot-types.d.mts.map +1 -0
- package/dist/witness/robbot/robbot-types.mjs +294 -0
- package/dist/witness/robbot/robbot-types.mjs.map +1 -0
- package/dist/witness/space/bootstrap/bootstrap-constants.d.mts +14 -0
- package/dist/witness/space/bootstrap/bootstrap-constants.d.mts.map +1 -0
- package/dist/witness/space/bootstrap/bootstrap-constants.mjs +15 -0
- package/dist/witness/space/bootstrap/bootstrap-constants.mjs.map +1 -0
- package/dist/witness/space/inner-space-v1.d.ts +63 -0
- package/dist/witness/space/inner-space-v1.d.ts.map +1 -0
- package/dist/witness/space/inner-space-v1.js +356 -0
- package/dist/witness/space/inner-space-v1.js.map +1 -0
- package/dist/witness/space/outer-space/outer-space-constants.d.mts +2 -0
- package/dist/witness/space/outer-space/outer-space-constants.d.mts.map +1 -0
- package/dist/witness/space/outer-space/outer-space-constants.mjs +2 -0
- package/dist/witness/space/outer-space/outer-space-constants.mjs.map +1 -0
- package/dist/witness/space/outer-space/outer-space-helper.d.mts +28 -0
- package/dist/witness/space/outer-space/outer-space-helper.d.mts.map +1 -0
- package/dist/witness/space/outer-space/outer-space-helper.mjs +87 -0
- package/dist/witness/space/outer-space/outer-space-helper.mjs.map +1 -0
- package/dist/witness/space/outer-space/outer-space-types.d.mts +548 -0
- package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -0
- package/dist/witness/space/outer-space/outer-space-types.mjs +118 -0
- package/dist/witness/space/outer-space/outer-space-types.mjs.map +1 -0
- package/dist/witness/space/space-base-v1.d.mts +147 -0
- package/dist/witness/space/space-base-v1.d.mts.map +1 -0
- package/dist/witness/space/space-base-v1.mjs +350 -0
- package/dist/witness/space/space-base-v1.mjs.map +1 -0
- package/dist/witness/space/space-constants.d.mts +181 -0
- package/dist/witness/space/space-constants.d.mts.map +1 -0
- package/dist/witness/space/space-constants.mjs +192 -0
- package/dist/witness/space/space-constants.mjs.map +1 -0
- package/dist/witness/space/space-helper.d.mts +666 -0
- package/dist/witness/space/space-helper.d.mts.map +1 -0
- package/dist/witness/space/space-helper.mjs +2830 -0
- package/dist/witness/space/space-helper.mjs.map +1 -0
- package/dist/witness/space/space-types.d.mts +422 -0
- package/dist/witness/space/space-types.d.mts.map +1 -0
- package/dist/witness/space/space-types.mjs +52 -0
- package/dist/witness/space/space-types.mjs.map +1 -0
- package/dist/witness/witness-base-v1.d.ts +144 -0
- package/dist/witness/witness-base-v1.d.ts.map +1 -0
- package/dist/witness/witness-base-v1.js +300 -0
- package/dist/witness/witness-base-v1.js.map +1 -0
- package/dist/witness/witness-constants.d.mts +3 -0
- package/dist/witness/witness-constants.d.mts.map +1 -0
- package/dist/witness/witness-constants.mjs +3 -0
- package/dist/witness/witness-constants.mjs.map +1 -0
- package/dist/witness/witness-form-builder.d.mts +45 -0
- package/dist/witness/witness-form-builder.d.mts.map +1 -0
- package/dist/witness/witness-form-builder.mjs +95 -0
- package/dist/witness/witness-form-builder.mjs.map +1 -0
- package/dist/witness/witness-helper.d.mts +89 -0
- package/dist/witness/witness-helper.d.mts.map +1 -0
- package/dist/witness/witness-helper.mjs +229 -0
- package/dist/witness/witness-helper.mjs.map +1 -0
- package/dist/witness/witness-types.d.mts +211 -0
- package/dist/witness/witness-types.d.mts.map +1 -0
- package/dist/witness/witness-types.mjs +2 -0
- package/dist/witness/witness-types.mjs.map +1 -0
- package/jasmine-browser.json +18 -0
- package/jasmine.json +6 -0
- package/package.json +67 -0
- package/src/assumptions.spec.mts +45 -0
- package/src/common/aws-constants.mts +5 -0
- package/src/common/bin/bin-types.mts +17 -0
- package/src/common/cache/cache-types.mts +53 -0
- package/src/common/comment/comment-constants.mts +10 -0
- package/src/common/comment/comment-helper.mts +211 -0
- package/src/common/comment/comment-types.mts +19 -0
- package/src/common/display/display-helper.mts +88 -0
- package/src/common/display/display-types.mts +108 -0
- package/src/common/encrypt/encrypt-constants.mts +28 -0
- package/src/common/encrypt/encrypt-types.mts +130 -0
- package/src/common/error/error-constants.mts +8 -0
- package/src/common/error/error-helper.mts +155 -0
- package/src/common/error/error-types.mts +62 -0
- package/src/common/form/form-helper.mts +253 -0
- package/src/common/form/form-items.mts +236 -0
- package/src/common/import-export/import-export-types.mts +18 -0
- package/src/common/legacy/about-legacy.md +0 -0
- package/src/common/legacy/legacy-types.mts +0 -0
- package/src/common/link/link-constants.mts +1 -0
- package/src/common/link/link-helper.mts +155 -0
- package/src/common/link/link-types.mts +16 -0
- package/src/common/other/graph-helper.mts +853 -0
- package/src/common/other/ibgib-helper.mts +671 -0
- package/src/common/other/other-constants.mts +76 -0
- package/src/common/other/other-types.mts +186 -0
- package/src/common/other/svg-constants.mts +1 -0
- package/src/common/other/svg-helper.mts +238 -0
- package/src/common/pic/pic-constants.mts +13 -0
- package/src/common/pic/pic-helper.mts +295 -0
- package/src/common/pic/pic-types.mts +29 -0
- package/src/common/root/root-constants.mts +41 -0
- package/src/common/root/root-types.mts +8 -0
- package/src/common/tag/tag-constants.mts +34 -0
- package/src/common/tag/tag-types.mts +19 -0
- package/src/core-constants.mts +506 -0
- package/src/core-helper.mts +33 -0
- package/src/core-types.mts +519 -0
- package/src/helper.spec.mts +64 -0
- package/src/index.mts +1 -0
- package/src/witness/app/app-base-v1.mts +584 -0
- package/src/witness/app/app-constants.mts +16 -0
- package/src/witness/app/app-helper.mts +322 -0
- package/src/witness/app/app-types.mts +252 -0
- package/src/witness/app/chat-app/chat-app-types.mts +40 -0
- package/src/witness/app/flash-app/flash-app-types.mts +38 -0
- package/src/witness/app/raw-app/raw-app-types.mts +40 -0
- package/src/witness/app/todo-app/todo-app-types.ts +59 -0
- package/src/witness/robbot/robbot-base-v1.ts +1531 -0
- package/src/witness/robbot/robbot-constants.mts +25 -0
- package/src/witness/robbot/robbot-helper.mts +676 -0
- package/src/witness/robbot/robbot-helper.spec.mts +135 -0
- package/src/witness/robbot/robbot-types.mts +797 -0
- package/src/witness/space/bootstrap/bootstrap-constants.mts +15 -0
- package/src/witness/space/inner-space-v1.ts +372 -0
- package/src/witness/space/outer-space/outer-space-constants.mts +1 -0
- package/src/witness/space/outer-space/outer-space-helper.mts +91 -0
- package/src/witness/space/outer-space/outer-space-types.mts +627 -0
- package/src/witness/space/space-base-v1.mts +414 -0
- package/src/witness/space/space-constants.mts +208 -0
- package/src/witness/space/space-helper.mts +3242 -0
- package/src/witness/space/space-types.mts +476 -0
- package/src/witness/witness-base-v1.ts +325 -0
- package/src/witness/witness-constants.mts +2 -0
- package/src/witness/witness-form-builder.mts +128 -0
- package/src/witness/witness-helper.mts +256 -0
- package/src/witness/witness-types.mts +249 -0
- package/tsconfig.json +15 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,1407 @@
|
|
|
1
|
+
import { filter } from 'rxjs/operators';
|
|
2
|
+
import { V1, getIbGibAddr } from '@ibgib/ts-gib';
|
|
3
|
+
import { getGibInfo } from '@ibgib/ts-gib/dist/V1/index.mjs';
|
|
4
|
+
import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
|
|
5
|
+
import { RobbotCmd, ROBBOT_MY_COMMENTS_REL8N_NAME, ROBBOT_CONTEXT_REL8N_NAME, SemanticId, RobbotInteractionType, DEFAULT_ROBBOT_LEX_DATA, DEFAULT_HUMAN_LEX_DATA, } from './robbot-types.mjs';
|
|
6
|
+
import { WitnessBase_V1, } from '../witness-base-v1';
|
|
7
|
+
import { getInteractionIbGib_V1, validateCommonRobbotData } from './robbot-helper.mjs';
|
|
8
|
+
import { argy_, isArg, resulty_ } from '../witness-helper.mjs';
|
|
9
|
+
import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
|
|
10
|
+
import { Lex, clone, delay, getTimestamp, getUUID, pretty } from '@ibgib/helper-gib';
|
|
11
|
+
import { errorIbGib } from '../../common/error/error-helper.mjs';
|
|
12
|
+
import { createCommentIbGib, parseCommentIb } from '../../common/comment/comment-helper.mjs';
|
|
13
|
+
import { getFromSpace, getLatestAddrs } from '../space/space-helper.mjs';
|
|
14
|
+
import { getTjpAddr } from '../../common/other/ibgib-helper.mjs';
|
|
15
|
+
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
16
|
+
/**
|
|
17
|
+
* ## distinguishing characteristics of robbots
|
|
18
|
+
*
|
|
19
|
+
* With any witness ibgib, we are concerned with interpreting an incoming
|
|
20
|
+
* arg ibgib and producing at least one result ibgib. Most often, there will
|
|
21
|
+
* be additional ibgibs created, either creating "new" ibgibs via `fork`
|
|
22
|
+
* transforms, or changing existing ibgibs through `mut8` and `rel8`
|
|
23
|
+
* transforms. And almost always these will be persisted in at least
|
|
24
|
+
* one space.
|
|
25
|
+
*
|
|
26
|
+
* But Robbots in particular are meant to be increasingly adaptable over time.
|
|
27
|
+
*
|
|
28
|
+
* This results in a couple of notes:
|
|
29
|
+
*
|
|
30
|
+
* 1. They should be able to handle any incoming ibgib, including primitives.
|
|
31
|
+
* 2. If they are learning robbots, then they will mutate internally at some rate.
|
|
32
|
+
* 3. Often robbots' output ibgib(s) will be intended for others'
|
|
33
|
+
* consumption, in service of others - be they humans or other
|
|
34
|
+
* biologically living organisms, other robbots or even later versions of
|
|
35
|
+
* themselves.
|
|
36
|
+
*
|
|
37
|
+
* So for example, one of the simplest robbots is one which simply echos the
|
|
38
|
+
* incoming ibgib arg.
|
|
39
|
+
|
|
40
|
+
* ## architecture
|
|
41
|
+
*
|
|
42
|
+
* At the base, any robbot should be able to handle any incoming ibgib. This is
|
|
43
|
+
* in contrast to, e.g., a Space, which is more rigid in design.
|
|
44
|
+
*
|
|
45
|
+
* Certainly there are robbot's who will be more rigid, but this will be an
|
|
46
|
+
* abstract class on top of this one, and all robbots should be able to react to
|
|
47
|
+
* all incoming ibgibs.
|
|
48
|
+
*
|
|
49
|
+
* Output will default to a simple ok^gib or (ROOT) ib^gib primitive...perhaps
|
|
50
|
+
* we'll go with ack^gib, but whatever it is, it's just an acknowledgement of
|
|
51
|
+
* input received. (I'll put it in the constants file).
|
|
52
|
+
*
|
|
53
|
+
* Side effects should occur in a parallel execution thread, which ideally would
|
|
54
|
+
* work in a completely parallel execution context (like a service worker). But
|
|
55
|
+
* then we have to deal with race conditions and the real solution there is to
|
|
56
|
+
* abstract to the robbot having its own space and the synchronization happening
|
|
57
|
+
* exactly like any other sync space.
|
|
58
|
+
*
|
|
59
|
+
* For now, we'll spin off a promise with some intermittent `await delay`
|
|
60
|
+
* calls if they end up called for, effectively the equivalent of the
|
|
61
|
+
* old-fashioned "ProcessMessages/DoEvents" hack.
|
|
62
|
+
*/
|
|
63
|
+
export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
64
|
+
async handleSemanticDefault(info) {
|
|
65
|
+
const lc = `${this.lc}[${this.handleSemanticDefault.name}]`;
|
|
66
|
+
try {
|
|
67
|
+
if (logalot) {
|
|
68
|
+
console.log(`${lc} starting... (I: 01a2d1781851cc36b674f44b4fb69522)`);
|
|
69
|
+
}
|
|
70
|
+
if (!this._robbotLex) {
|
|
71
|
+
throw new Error(`robbotLex not initialized (E: 7be2a470645eab44ca950e9ec8b72723)`);
|
|
72
|
+
}
|
|
73
|
+
const speech = this._robbotLex.get(SemanticId.unknown, {
|
|
74
|
+
props: (props) => props.semanticId === SemanticId.unknown,
|
|
75
|
+
});
|
|
76
|
+
const data = await this.getRobbotInteractionData({
|
|
77
|
+
type: RobbotInteractionType.info,
|
|
78
|
+
commentText: speech?.text ?? 'hmm, something went wrogn Dave',
|
|
79
|
+
});
|
|
80
|
+
const interaction = await getInteractionIbGib_V1({ data });
|
|
81
|
+
return { interaction };
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error(`${lc} ${error.message}`);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
if (logalot) {
|
|
89
|
+
console.log(`${lc} complete.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
constructor(initialData, initialRel8ns) {
|
|
94
|
+
super(initialData, initialRel8ns);
|
|
95
|
+
/**
|
|
96
|
+
* Log context for convenience with logging. (Ignore if you don't want to use this.)
|
|
97
|
+
*
|
|
98
|
+
* Often used in conjunction with `logalot`.
|
|
99
|
+
*/
|
|
100
|
+
this.lc = `${super.lc}[${RobbotBase_V1.name}]`;
|
|
101
|
+
/**
|
|
102
|
+
* When the robbot has to get some ibgibs, might as well store them here so
|
|
103
|
+
* we don't have to get them again from storage.
|
|
104
|
+
*/
|
|
105
|
+
this._cacheIbGibs = {};
|
|
106
|
+
/**
|
|
107
|
+
* when we get an update to the context, we want to know what the _new_
|
|
108
|
+
* children are in order to interpret comments from the user that may be
|
|
109
|
+
* directed at us.
|
|
110
|
+
*
|
|
111
|
+
* So we will get an initial snapshot of children that we will diff against.
|
|
112
|
+
* We could go via the dna, but ultimately a diff is what is needed.
|
|
113
|
+
*/
|
|
114
|
+
this._currentWorkingContextIbGib_PriorChildrenAddrs = [];
|
|
115
|
+
this._updatingContext = false;
|
|
116
|
+
this._semanticHandlers = {};
|
|
117
|
+
this.initialized = this.initialize();
|
|
118
|
+
}
|
|
119
|
+
// #region initialize
|
|
120
|
+
/**
|
|
121
|
+
* Initializes to default space values.
|
|
122
|
+
*/
|
|
123
|
+
async initialize() {
|
|
124
|
+
const lc = `${this.lc}[${this.initialize.name}]`;
|
|
125
|
+
try {
|
|
126
|
+
if (logalot) {
|
|
127
|
+
console.log(`${lc} starting... (I: f0e65ab0f80046a59668ddfbf9f47a4a5)`);
|
|
128
|
+
}
|
|
129
|
+
await this.initialize_semanticHandlers();
|
|
130
|
+
await this.initialize_lex();
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error(`${lc} ${error.message}`);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
if (logalot) {
|
|
137
|
+
console.log(`${lc} complete.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async initialize_semanticHandlers() {
|
|
142
|
+
const lc = `${this.lc}[${this.initialize_semanticHandlers.name}]`;
|
|
143
|
+
try {
|
|
144
|
+
if (logalot) {
|
|
145
|
+
console.log(`${lc} starting... (I: a0f2a11688963b0156e337e7f8604f22)`);
|
|
146
|
+
}
|
|
147
|
+
this._semanticHandlers = {
|
|
148
|
+
[SemanticId.default]: [
|
|
149
|
+
{
|
|
150
|
+
handlerId: "c8054c0b77fb4b37bff693e54e1f66bd",
|
|
151
|
+
semanticId: SemanticId.default,
|
|
152
|
+
fnCanExec: (info) => Promise.resolve(true),
|
|
153
|
+
fnExec: (info) => { return this.handleSemanticDefault(info); },
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
[SemanticId.unknown]: [
|
|
157
|
+
{
|
|
158
|
+
handlerId: "9eb4c537cddb40d4927c2aa58e4e6f4b",
|
|
159
|
+
semanticId: SemanticId.default,
|
|
160
|
+
fnCanExec: (info) => Promise.resolve(true),
|
|
161
|
+
fnExec: (info) => { return this.handleSemanticDefault(info); },
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error(`${lc} ${error.message}`);
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
if (logalot) {
|
|
172
|
+
console.log(`${lc} complete.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async initialize_lex() {
|
|
177
|
+
const lc = `${this.lc}[${this.initialize_lex.name}]`;
|
|
178
|
+
try {
|
|
179
|
+
if (logalot) {
|
|
180
|
+
console.log(`${lc} starting... (I: a4668a7473027e56df42909c09f70822)`);
|
|
181
|
+
}
|
|
182
|
+
this._robbotLex = new Lex(clone(DEFAULT_ROBBOT_LEX_DATA), {
|
|
183
|
+
defaultPropsMode: 'props',
|
|
184
|
+
defaultKeywordMode: 'all',
|
|
185
|
+
defaultLineConcat: 'paragraph', // outgoing robbot defaults to multiple paragraphs.
|
|
186
|
+
});
|
|
187
|
+
this._robbotLex.data[SemanticId.unknown] = [
|
|
188
|
+
{
|
|
189
|
+
texts: [
|
|
190
|
+
`huh?`, // silly
|
|
191
|
+
],
|
|
192
|
+
props: {
|
|
193
|
+
semanticId: SemanticId.unknown,
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
this._userLex = new Lex(clone(DEFAULT_HUMAN_LEX_DATA), {
|
|
198
|
+
defaultPropsMode: 'props',
|
|
199
|
+
defaultKeywordMode: 'all',
|
|
200
|
+
defaultLineConcat: 'sentence', // incoming user lex defaults to combining sentences.
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
console.error(`${lc} ${error.message}`);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
if (logalot) {
|
|
209
|
+
console.log(`${lc} complete.`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// #endregion initialize
|
|
214
|
+
async loadNewerSelfIfAvailable() {
|
|
215
|
+
const lc = `${this.lc}[${this.loadNewerSelfIfAvailable.name}]`;
|
|
216
|
+
try {
|
|
217
|
+
if (logalot) {
|
|
218
|
+
console.log(`${lc} starting... (I: 94755c3131f4dfa12d20fa38e2926522)`);
|
|
219
|
+
}
|
|
220
|
+
if (this.ibgibsSvc) {
|
|
221
|
+
// check for newer version of self locally before executing
|
|
222
|
+
const robbotAddr = getIbGibAddr({ ibGib: this });
|
|
223
|
+
const latestAddr = await this.ibgibsSvc.getLatestAddr({ ibGib: this });
|
|
224
|
+
if (latestAddr && latestAddr !== robbotAddr) {
|
|
225
|
+
// robbot has a newer ibgib in its timeline
|
|
226
|
+
let resGet = await this.ibgibsSvc.get({ addr: latestAddr });
|
|
227
|
+
if (!resGet || !resGet?.success || (resGet?.ibGibs ?? []).length === 0) {
|
|
228
|
+
throw new Error(`could not get newer robbot ibgib (E: 15fa346c8ac17edb96e4b0870104c122)`);
|
|
229
|
+
}
|
|
230
|
+
await this.loadIbGibDto(resGet.ibGibs[0]);
|
|
231
|
+
const validationErrors = await this.validateThis();
|
|
232
|
+
if (validationErrors?.length > 0) {
|
|
233
|
+
throw new Error(`validationErrors when loading newer version: ${pretty(validationErrors)} (E: 0d9f0684a1ff6af44e20a57130e3ac22)`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
console.warn(`${lc} this.ibgibsSvc undefined (W: 44cc5bf1b14b4695b8de4c589787be06)`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.error(`${lc} ${error.message}`);
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
if (logalot) {
|
|
247
|
+
console.log(`${lc} complete.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* At this point in time, the arg has already been intrinsically validated,
|
|
253
|
+
* as well as the internal state of this robbot. so whatever this robbot's
|
|
254
|
+
* function is, it should be good to go.
|
|
255
|
+
*
|
|
256
|
+
* In the base class, this just returns {@link routeAndDoArg}. If you don't
|
|
257
|
+
* want to route, then override this.
|
|
258
|
+
*/
|
|
259
|
+
async witnessImpl(arg) {
|
|
260
|
+
const lc = `${this.lc}[${this.witnessImpl.name}]`;
|
|
261
|
+
try {
|
|
262
|
+
if (logalot) {
|
|
263
|
+
console.log(`${lc} starting...`);
|
|
264
|
+
}
|
|
265
|
+
await this.loadNewerSelfIfAvailable();
|
|
266
|
+
return this.routeAndDoArg({ arg });
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.error(`${lc} ${error.message}`);
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
if (logalot) {
|
|
274
|
+
console.log(`${lc} complete.`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Base routing executes different if incoming is a cmd options arg, i.e.,
|
|
280
|
+
* if the `data.cmd` is truthy (atow). If {@link isArg} is true, then routes
|
|
281
|
+
* to {@link doCmdArg}; else routes to {@link doDefault}.
|
|
282
|
+
*
|
|
283
|
+
* Override this function to create more advanced custom routing.
|
|
284
|
+
*
|
|
285
|
+
* ## notes
|
|
286
|
+
*
|
|
287
|
+
* I'm not overly thrilled with this, but it's a watered down version of
|
|
288
|
+
* what I've implemented in the space witness hierarchy.
|
|
289
|
+
*
|
|
290
|
+
* @see {@link isArg}
|
|
291
|
+
* @see {@link doCmdArg}
|
|
292
|
+
* @see {@link doDefault}.
|
|
293
|
+
*/
|
|
294
|
+
async routeAndDoArg({ arg, }) {
|
|
295
|
+
const lc = `${this.lc}[${this.routeAndDoArg.name}]`;
|
|
296
|
+
try {
|
|
297
|
+
if (logalot) {
|
|
298
|
+
console.log(`${lc} starting...`);
|
|
299
|
+
}
|
|
300
|
+
if (isArg({ ibGib: arg })) {
|
|
301
|
+
if (arg.data?.cmd) {
|
|
302
|
+
return this.doCmdArg({ arg: arg });
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return this.doDefault({ ibGib: arg });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
console.error(`${lc} ${error.message}`);
|
|
311
|
+
if (this.data?.catchAllErrors) {
|
|
312
|
+
return (await errorIbGib({ rawMsg: error.message }));
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
if (logalot) {
|
|
320
|
+
console.log(`${lc} complete.`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// #region do cmd args
|
|
325
|
+
/**
|
|
326
|
+
* By default, this routes to {@link doCmdIb}, {@link doCmdGib} & {@link doCmdIbgib}.
|
|
327
|
+
* Override this and route to other commands before calling this with `super.doCmdArg`
|
|
328
|
+
* (if you still want to use this function.)
|
|
329
|
+
*
|
|
330
|
+
* You can also override the routing
|
|
331
|
+
*/
|
|
332
|
+
doCmdArg({ arg, }) {
|
|
333
|
+
const lc = `${this.lc}[${this.doCmdArg.name}]`;
|
|
334
|
+
try {
|
|
335
|
+
if (logalot) {
|
|
336
|
+
console.log(`${lc} starting...`);
|
|
337
|
+
}
|
|
338
|
+
if (!arg.data?.cmd) {
|
|
339
|
+
throw new Error(`invalid cmd arg. arg.data.cmd required. (E: aec4dd5bd967fbf36f9c4fad22210222)`);
|
|
340
|
+
}
|
|
341
|
+
if (arg.data.cmd === RobbotCmd.ib) {
|
|
342
|
+
return this.doCmdIb({ arg: arg });
|
|
343
|
+
}
|
|
344
|
+
else if (arg.data.cmd === RobbotCmd.gib) {
|
|
345
|
+
return this.doCmdGib({ arg: arg });
|
|
346
|
+
}
|
|
347
|
+
else if (arg.data.cmd === RobbotCmd.ibgib) {
|
|
348
|
+
return this.doCmdIbgib({ arg: arg });
|
|
349
|
+
}
|
|
350
|
+
else if (arg.data.cmd === RobbotCmd.activate) {
|
|
351
|
+
return this.doCmdActivate({ arg: arg });
|
|
352
|
+
}
|
|
353
|
+
else if (arg.data.cmd === RobbotCmd.deactivate) {
|
|
354
|
+
return this.doCmdDeactivate({ arg: arg });
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
throw new Error(`unknown arg.data.cmd: ${arg.data.cmd} (E: 721fa6a5166327134f9504c1caa3e422)`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
console.error(`${lc} ${error.message}`);
|
|
362
|
+
throw error;
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
if (logalot) {
|
|
366
|
+
console.log(`${lc} complete.`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
doCmdIb({ arg, }) {
|
|
371
|
+
const lc = `${this.lc}[${this.doCmdIb.name}]`;
|
|
372
|
+
try {
|
|
373
|
+
if (logalot) {
|
|
374
|
+
console.log(`${lc} starting...`);
|
|
375
|
+
}
|
|
376
|
+
throw new Error(`not implemented in base class (E: 7298662a2b8f67611d16a8af0e499422)`);
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
console.error(`${lc} ${error.message}`);
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
if (logalot) {
|
|
384
|
+
console.log(`${lc} complete.`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
doCmdGib({ arg, }) {
|
|
389
|
+
const lc = `${this.lc}[${this.doCmdGib.name}]`;
|
|
390
|
+
try {
|
|
391
|
+
if (logalot) {
|
|
392
|
+
console.log(`${lc} starting...`);
|
|
393
|
+
}
|
|
394
|
+
throw new Error(`not implemented in base class (E: b6bf2c788c734051956481be7283d006)`);
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
console.error(`${lc} ${error.message}`);
|
|
398
|
+
throw error;
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
if (logalot) {
|
|
402
|
+
console.log(`${lc} complete.`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
doCmdIbgib({ arg, }) {
|
|
407
|
+
const lc = `${this.lc}[${this.doCmdIbgib.name}]`;
|
|
408
|
+
try {
|
|
409
|
+
if (logalot) {
|
|
410
|
+
console.log(`${lc} starting...`);
|
|
411
|
+
}
|
|
412
|
+
throw new Error(`not implemented in base class (E: 4fee11f05315467abd036cd8555d27db)`);
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
console.error(`${lc} ${error.message}`);
|
|
416
|
+
throw error;
|
|
417
|
+
}
|
|
418
|
+
finally {
|
|
419
|
+
if (logalot) {
|
|
420
|
+
console.log(`${lc} complete.`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async doCmdActivate({ arg, }) {
|
|
425
|
+
const lc = `${this.lc}[${this.doCmdActivate.name}]`;
|
|
426
|
+
try {
|
|
427
|
+
if (logalot) {
|
|
428
|
+
console.log(`${lc} starting... (I: d453593a295d4cdbae2acb71d9f6de35)`);
|
|
429
|
+
}
|
|
430
|
+
await this.initialized;
|
|
431
|
+
if (!arg) {
|
|
432
|
+
throw new Error(`arg required (E: 9cddabc6dc96ddb37846807feb093423)`);
|
|
433
|
+
}
|
|
434
|
+
if (arg.ibGibs?.length ?? 0 > 0) {
|
|
435
|
+
await this.initializeContext({ arg });
|
|
436
|
+
}
|
|
437
|
+
const result = await this.resulty({
|
|
438
|
+
resultData: {
|
|
439
|
+
optsAddr: getIbGibAddr({ ibGib: arg }),
|
|
440
|
+
success: true,
|
|
441
|
+
},
|
|
442
|
+
});
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
console.error(`${lc} ${error.message}`);
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
449
|
+
finally {
|
|
450
|
+
if (logalot) {
|
|
451
|
+
console.log(`${lc} complete.`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async doCmdDeactivate({ arg, }) {
|
|
456
|
+
const lc = `${this.lc}[${this.doCmdDeactivate.name}]`;
|
|
457
|
+
try {
|
|
458
|
+
if (logalot) {
|
|
459
|
+
console.log(`${lc} starting... (I: d453593a295d4cdbae2acb71d9f6de35)`);
|
|
460
|
+
}
|
|
461
|
+
await this.initialized;
|
|
462
|
+
await this.finalizeContext({ arg });
|
|
463
|
+
const result = await this.resulty({
|
|
464
|
+
resultData: {
|
|
465
|
+
optsAddr: getIbGibAddr({ ibGib: arg }),
|
|
466
|
+
success: true,
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
return result;
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
console.error(`${lc} ${error.message}`);
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
finally {
|
|
476
|
+
if (logalot) {
|
|
477
|
+
console.log(`${lc} complete.`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
// #endregion do cmd args
|
|
482
|
+
// #region other stubbed do functions (doPic, doComment, doDefault)
|
|
483
|
+
/**
|
|
484
|
+
* Stubbed in base class for convenience. Doesn't have to be implemented.
|
|
485
|
+
*/
|
|
486
|
+
doPic({ ibGib, }) {
|
|
487
|
+
const lc = `${this.lc}[${this.doPic.name}]`;
|
|
488
|
+
try {
|
|
489
|
+
if (logalot) {
|
|
490
|
+
console.log(`${lc} starting...`);
|
|
491
|
+
}
|
|
492
|
+
throw new Error(`not implemented in base class (E: 16ba889931644d42ad9e476757dd0617)`);
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
console.error(`${lc} ${error.message}`);
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
finally {
|
|
499
|
+
if (logalot) {
|
|
500
|
+
console.log(`${lc} complete.`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Stubbed in base class for convenience. Doesn't have to be implemented.
|
|
506
|
+
*/
|
|
507
|
+
doComment({ ibGib, }) {
|
|
508
|
+
const lc = `${this.lc}[${this.doComment.name}]`;
|
|
509
|
+
try {
|
|
510
|
+
if (logalot) {
|
|
511
|
+
console.log(`${lc} starting...`);
|
|
512
|
+
}
|
|
513
|
+
throw new Error(`not implemented in base class (E: 0486a7864729456d993a1afe246faea4)`);
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
console.error(`${lc} ${error.message}`);
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
finally {
|
|
520
|
+
if (logalot) {
|
|
521
|
+
console.log(`${lc} complete.`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Stubbed in base class for convenience. Doesn't have to be implemented.
|
|
527
|
+
*/
|
|
528
|
+
doDefault({ ibGib, }) {
|
|
529
|
+
const lc = `${this.lc}[${this.doDefault.name}]`;
|
|
530
|
+
try {
|
|
531
|
+
if (logalot) {
|
|
532
|
+
console.log(`${lc} starting...`);
|
|
533
|
+
}
|
|
534
|
+
throw new Error(`not implemented in base class (E: 5038662186617aaf1f0cc698fd1f9622)`);
|
|
535
|
+
// return this.doDefaultImpl({ibGib});
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
console.error(`${lc} ${error.message}`);
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
541
|
+
finally {
|
|
542
|
+
if (logalot) {
|
|
543
|
+
console.log(`${lc} complete.`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// #endregion other stubbed do functions (doPic, doComment, doDefault)
|
|
548
|
+
/**
|
|
549
|
+
* By default, this...
|
|
550
|
+
*
|
|
551
|
+
* * performs the raw {@link rel8} transform to the given `ibGib`.
|
|
552
|
+
* * persists the new ibgib's transform result in the given space.
|
|
553
|
+
* * registers the newer version of this robbot ibgib with the ibgibs svc.
|
|
554
|
+
*
|
|
555
|
+
* @see {@link ibGibs}
|
|
556
|
+
* @see {@link rel8nName}
|
|
557
|
+
* @see {@link ibgibsSvc}
|
|
558
|
+
* @see {@link space}
|
|
559
|
+
*
|
|
560
|
+
* ## notes
|
|
561
|
+
*
|
|
562
|
+
* * If there is no given `space`, then we will use the `ibgibsSvc` to get
|
|
563
|
+
* the local user space. If none, then we skip persistence.
|
|
564
|
+
* * If there is no `ibgibsSvc`, we won't register the new ibgibs locally.
|
|
565
|
+
*/
|
|
566
|
+
async rel8To({ ibGibs, rel8nName, linked, ibgibsSvc,
|
|
567
|
+
// space,
|
|
568
|
+
}) {
|
|
569
|
+
const lc = `${this.lc}[${this.rel8To.name}]`;
|
|
570
|
+
try {
|
|
571
|
+
if (logalot) {
|
|
572
|
+
console.log(`${lc} starting...`);
|
|
573
|
+
}
|
|
574
|
+
// #region initialize, validate args and this
|
|
575
|
+
if ((ibGibs ?? []).length === 0) {
|
|
576
|
+
throw new Error(`ibGibs required (E: 2fd13de0f025b170885bede4d7a50922)`);
|
|
577
|
+
}
|
|
578
|
+
rel8nName = rel8nName || this.data?.defaultRel8nName;
|
|
579
|
+
if (!rel8nName) {
|
|
580
|
+
throw new Error(`rel8nName required either as an arg or in this.data.defaultRel8nName (E: 43ab8ae63694a2a82cd8a70ed6b6b522)`);
|
|
581
|
+
}
|
|
582
|
+
const thisValidationErrors = await this.validateThis();
|
|
583
|
+
if (thisValidationErrors?.length > 0) {
|
|
584
|
+
throw new Error(`this is an invalid ibGib. thisValidationErrors: ${thisValidationErrors.join('|')} (E: 8f08716866cd13bf254222ee9e6a6722)`);
|
|
585
|
+
}
|
|
586
|
+
ibgibsSvc = ibgibsSvc ?? this.ibgibsSvc;
|
|
587
|
+
if (!ibgibsSvc) {
|
|
588
|
+
// if (this.ibgibsSvc) {
|
|
589
|
+
// if (logalot) { console.log(`${lc} ibgibsSvc arg falsy, but we have a reference on this object, which we will use. (I: ee0d39a47ee8aee8ffd797721fea4322)`); }
|
|
590
|
+
// ibgibsSvc = this.ibgibsSvc;
|
|
591
|
+
// }
|
|
592
|
+
throw new Error(`either ibgibsSvc or this.ibgibsSvc required (E: b5f9453ddb394a2b76dec74c7304df22)`);
|
|
593
|
+
}
|
|
594
|
+
// if (!space) {
|
|
595
|
+
// if (ibgibsSvc) {
|
|
596
|
+
// if (logalot) { console.log(`${lc} space arg falsy, but ibgibsSvc truthy, so we'll use ibgibsSvc's local user space for persistence. (I: 37a4b4c1406556cb23831671755b0d22)`); }
|
|
597
|
+
// space = await ibgibsSvc.getLocalUserSpace({ lock: true });
|
|
598
|
+
// }
|
|
599
|
+
// }
|
|
600
|
+
// if (!space) { throw new Error(`(UNEXPECTED) space required and ibgibsSvc couldn't get it? (E: a3b9f9b72f6f6f18883199a19d38c622)`); }
|
|
601
|
+
// #endregion initialize, validate args and this
|
|
602
|
+
// we want to rel8 only to the ibGibs whose timelines we're not
|
|
603
|
+
// already related to. So we look to see if we already have the tjpGib
|
|
604
|
+
// per our rel8nName.
|
|
605
|
+
// if (!this.rel8ns) { this.rel8ns = {} as any };
|
|
606
|
+
const alreadyRel8dAddrs = this.rel8ns ? this.rel8ns[rel8nName] ?? [] : [];
|
|
607
|
+
const alreadyRel8dTjpGibs = alreadyRel8dAddrs.map(x => getGibInfo({ ibGibAddr: x }).tjpGib);
|
|
608
|
+
const ibGibsNotYetRel8dByTjp = ibGibs.filter(x => {
|
|
609
|
+
const tjpGib = getGibInfo({ ibGibAddr: getIbGibAddr({ ibGib: x }) }).tjpGib;
|
|
610
|
+
return !alreadyRel8dTjpGibs.includes(tjpGib);
|
|
611
|
+
});
|
|
612
|
+
if (ibGibsNotYetRel8dByTjp.length === 0) {
|
|
613
|
+
if (logalot) {
|
|
614
|
+
console.log(`${lc} already rel8d to all incoming ibGib(s) via tjp. (I: 5e9d94a98ba262f146c0c0b765157922)`);
|
|
615
|
+
}
|
|
616
|
+
return; /* <<<< returns early */
|
|
617
|
+
}
|
|
618
|
+
// perform the raw ibgib rel8 transform
|
|
619
|
+
const addrs = ibGibsNotYetRel8dByTjp.map(x => getIbGibAddr({ ibGib: x }));
|
|
620
|
+
const resNewRobbot = await V1.rel8({
|
|
621
|
+
src: this.toIbGibDto(),
|
|
622
|
+
rel8nsToAddByAddr: { [rel8nName]: addrs },
|
|
623
|
+
linkedRel8ns: linked ? ["past", "ancestor", rel8nName] : ["past", "ancestor"],
|
|
624
|
+
dna: true,
|
|
625
|
+
nCounter: true,
|
|
626
|
+
});
|
|
627
|
+
const newRobbotIbGib = resNewRobbot.newIbGib;
|
|
628
|
+
const newRobbotValidationErrors = await validateIbGibIntrinsically({ ibGib: newRobbotIbGib });
|
|
629
|
+
if (newRobbotValidationErrors?.length ?? 0 > 0) {
|
|
630
|
+
throw new Error(`new robbot would have validation errors. aborting. newRobbotValidationErrors: ${newRobbotValidationErrors.join('|')} (E: eb816a27156c246c121ef55e37d59322)`);
|
|
631
|
+
}
|
|
632
|
+
// if space is given, perform the persistence
|
|
633
|
+
// if (space) {
|
|
634
|
+
await ibgibsSvc.persistTransformResult({ resTransform: resNewRobbot });
|
|
635
|
+
// } else {
|
|
636
|
+
// if (logalot) { console.log(`${lc} space falsy, skipping persistence (I: 90aa3553e92ad1d02bce61f83648ea22)`); }
|
|
637
|
+
// }
|
|
638
|
+
// if ibgibs svc is given, register the new ibgib
|
|
639
|
+
// (in the future, need to revisit the ibgibs service to the idea of locality/ies).
|
|
640
|
+
// if (ibgibsSvc) {
|
|
641
|
+
await ibgibsSvc.registerNewIbGib({ ibGib: newRobbotIbGib });
|
|
642
|
+
// } else {
|
|
643
|
+
// if (logalot) { console.log(`${lc} ibgibsSvc falsy so skipping registerNewIbGib for new robbot (I: eda4f68fffaf2435eba25cd39d4f2922)`); }
|
|
644
|
+
// }
|
|
645
|
+
// update this witness' primary ibGib properties (ib, gib, data, rel8ns).
|
|
646
|
+
// override `loadIbGibDto` to update secondary/derivative properties
|
|
647
|
+
await this.loadIbGibDto(newRobbotIbGib);
|
|
648
|
+
}
|
|
649
|
+
catch (error) {
|
|
650
|
+
console.error(`${lc} ${error.message}`);
|
|
651
|
+
throw error;
|
|
652
|
+
}
|
|
653
|
+
finally {
|
|
654
|
+
if (logalot) {
|
|
655
|
+
console.log(`${lc} complete.`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* validates against common robbot qualities.
|
|
661
|
+
*
|
|
662
|
+
* Override this with a call to `super.validateThis` for custom validation
|
|
663
|
+
* for descending robbot classes.
|
|
664
|
+
*
|
|
665
|
+
* @returns validation errors common to all robbots, if any errors exist.
|
|
666
|
+
*/
|
|
667
|
+
async validateThis() {
|
|
668
|
+
const lc = `${this.lc}[${this.validateThis.name}]`;
|
|
669
|
+
try {
|
|
670
|
+
if (logalot) {
|
|
671
|
+
console.log(`${lc} starting...`);
|
|
672
|
+
}
|
|
673
|
+
const errors = [
|
|
674
|
+
// ...await super.validateThis(),
|
|
675
|
+
...validateCommonRobbotData({ robbotData: this.data }),
|
|
676
|
+
];
|
|
677
|
+
return errors;
|
|
678
|
+
}
|
|
679
|
+
catch (error) {
|
|
680
|
+
console.error(`${lc} ${error.message}`);
|
|
681
|
+
throw error;
|
|
682
|
+
}
|
|
683
|
+
finally {
|
|
684
|
+
if (logalot) {
|
|
685
|
+
console.log(`${lc} complete.`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* builds an arg ibGib.
|
|
691
|
+
*
|
|
692
|
+
* wrapper convenience to avoid long generic calls.
|
|
693
|
+
*/
|
|
694
|
+
async argy({ argData, ibMetadata, noTimestamp, ibGibs, }) {
|
|
695
|
+
const arg = await argy_({
|
|
696
|
+
argData,
|
|
697
|
+
ibMetadata,
|
|
698
|
+
noTimestamp
|
|
699
|
+
});
|
|
700
|
+
if (ibGibs) {
|
|
701
|
+
arg.ibGibs = ibGibs;
|
|
702
|
+
}
|
|
703
|
+
return arg;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* builds a result ibGib, if indeed a result ibgib is required.
|
|
707
|
+
*
|
|
708
|
+
* This is only useful in robbots that have more structured inputs/outputs.
|
|
709
|
+
* For those that simply accept any ibgib incoming and return a
|
|
710
|
+
* primitive like ib^gib or whatever, then this is unnecessary.
|
|
711
|
+
*
|
|
712
|
+
* wrapper convenience to avoid long generic calls.
|
|
713
|
+
*/
|
|
714
|
+
async resulty({ resultData, ibGibs, }) {
|
|
715
|
+
const result = await resulty_({
|
|
716
|
+
// ibMetadata: getRobbotResultMetadata({space: this}),
|
|
717
|
+
resultData,
|
|
718
|
+
});
|
|
719
|
+
if (ibGibs) {
|
|
720
|
+
result.ibGibs = ibGibs;
|
|
721
|
+
}
|
|
722
|
+
return result;
|
|
723
|
+
}
|
|
724
|
+
async rel8ToContextIbGib({ ibGibToRel8, ibGibAddrToRel8, contextIbGib, rel8nNames,
|
|
725
|
+
// space,
|
|
726
|
+
}) {
|
|
727
|
+
const lc = `${this.lc}[${this.rel8ToContextIbGib.name}]`;
|
|
728
|
+
try {
|
|
729
|
+
if (!ibGibToRel8 && !ibGibAddrToRel8) {
|
|
730
|
+
throw new Error(`ibGibToRel8 or ibGibAddrToRel8 required (E: 3ee14659fd22355a5ba0e537a477be22)`);
|
|
731
|
+
}
|
|
732
|
+
if (!contextIbGib) {
|
|
733
|
+
throw new Error(`contextIbGib required (E: 85f27c7cbf713704c21084c141cd8822)`);
|
|
734
|
+
}
|
|
735
|
+
if (!this.ibgibsSvc) {
|
|
736
|
+
throw new Error(`this.ibgibsSvc required (E: 6a38c4274bdefc8d44cafd2d6faaa222)`);
|
|
737
|
+
}
|
|
738
|
+
// space = space ?? await this.ibgibsSvc.getLocalUserSpace({ lock: true });
|
|
739
|
+
// if (!space) { throw new Error(`space required (E: 267ad87c148942cda641349df0bbbd22)`); }
|
|
740
|
+
if ((rel8nNames ?? []).length === 0) {
|
|
741
|
+
if (!this.data?.defaultRel8nName) {
|
|
742
|
+
throw new Error(`either rel8nNames or this.data.defaultRel8nName required (E: a14ab4b3e479d9274c61bc5a30bc2222)`);
|
|
743
|
+
}
|
|
744
|
+
rel8nNames = [this.data.defaultRel8nName];
|
|
745
|
+
}
|
|
746
|
+
// set up the rel8ns to add
|
|
747
|
+
const rel8nsToAddByAddr = {};
|
|
748
|
+
ibGibAddrToRel8 = ibGibAddrToRel8 || getIbGibAddr({ ibGib: ibGibToRel8 });
|
|
749
|
+
rel8nNames.forEach((rel8nName) => { rel8nsToAddByAddr[rel8nName] = [ibGibAddrToRel8]; });
|
|
750
|
+
// perform the rel8 transform and...
|
|
751
|
+
const resRel8ToContext = await V1.rel8({
|
|
752
|
+
src: contextIbGib,
|
|
753
|
+
rel8nsToAddByAddr,
|
|
754
|
+
dna: true,
|
|
755
|
+
nCounter: true
|
|
756
|
+
});
|
|
757
|
+
// ...persist it...
|
|
758
|
+
await this.ibgibsSvc.persistTransformResult({ resTransform: resRel8ToContext });
|
|
759
|
+
// ...register the context.
|
|
760
|
+
const { newIbGib: newContext } = resRel8ToContext;
|
|
761
|
+
await this.ibgibsSvc.registerNewIbGib({ ibGib: newContext });
|
|
762
|
+
}
|
|
763
|
+
catch (error) {
|
|
764
|
+
console.error(`${lc} ${error.message}`);
|
|
765
|
+
throw error;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
async createCommentAndRel8ToContextIbGib({ text, contextIbGib, }) {
|
|
769
|
+
const lc = `${this.lc}[${this.createCommentAndRel8ToContextIbGib.name}]`;
|
|
770
|
+
try {
|
|
771
|
+
if (logalot) {
|
|
772
|
+
console.log(`${lc} starting... (I: c3a005f7d323468a5b4e1b2710901d22)`);
|
|
773
|
+
}
|
|
774
|
+
if (!this.ibgibsSvc) {
|
|
775
|
+
throw new Error(`this.ibgibsSvc required (E: 5dbb1a7f0ff5469b8ce3cb1be175e521)`);
|
|
776
|
+
}
|
|
777
|
+
// space = space ?? await this.ibgibsSvc.getLocalUserSpace({ lock: true });
|
|
778
|
+
// if (!space) { throw new Error(`(UNEXPECTED) space required and wasn't able to get it from ibgibsSvc? (E: 7159f9893a66c28a7e09b61384545622)`); }
|
|
779
|
+
let space = await this.ibgibsSvc.getLocalUserSpace({ lock: true });
|
|
780
|
+
/** tag this comment with metadata to show it came from this robbot */
|
|
781
|
+
let resComment = await createCommentIbGib({ text, addlMetadataText: this.getAddlMetadata(), saveInSpace: true, space });
|
|
782
|
+
// get again to be sure it's the latest space.
|
|
783
|
+
space = await this.ibgibsSvc.getLocalUserSpace({ lock: true });
|
|
784
|
+
const commentIbGib = resComment.newIbGib;
|
|
785
|
+
if (!commentIbGib) {
|
|
786
|
+
throw new Error(`(UNEXPECTED) failed to create comment? (E: 6d668f4e55198e654324622eabaac922)`);
|
|
787
|
+
}
|
|
788
|
+
await this.ibgibsSvc.registerNewIbGib({ ibGib: commentIbGib });
|
|
789
|
+
await this.rel8ToContextIbGib({ ibGibToRel8: commentIbGib, contextIbGib, rel8nNames: ['comment'] });
|
|
790
|
+
await this.rel8To({
|
|
791
|
+
ibGibs: [commentIbGib],
|
|
792
|
+
rel8nName: ROBBOT_MY_COMMENTS_REL8N_NAME,
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
catch (error) {
|
|
796
|
+
console.error(`${lc} ${error.message}`);
|
|
797
|
+
throw error;
|
|
798
|
+
}
|
|
799
|
+
finally {
|
|
800
|
+
if (logalot) {
|
|
801
|
+
console.log(`${lc} complete.`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* used to identify when comments are made by these robbots.
|
|
807
|
+
*
|
|
808
|
+
* atow this is `robbot_${this.data.classname}_${this.data.name}_${this.data.uuid.slice(0, 8)}`;
|
|
809
|
+
*
|
|
810
|
+
* @returns addlmetadata string to be used in comment ib's
|
|
811
|
+
*/
|
|
812
|
+
getAddlMetadata() {
|
|
813
|
+
const lc = `${this.lc}[${this.getAddlMetadata.name}]`;
|
|
814
|
+
try {
|
|
815
|
+
if (logalot) {
|
|
816
|
+
console.log(`${lc} starting... (I: 7800732facf3783943fdf1b2423b0c22)`);
|
|
817
|
+
}
|
|
818
|
+
if (!this.data) {
|
|
819
|
+
throw new Error(`(UNEXPECTED) this.data falsy? (E: 7cb044b39b2b8e31f363f3b82f256323)`);
|
|
820
|
+
}
|
|
821
|
+
const classnameIsh = this.data.classname?.replace(/[_]/mg, '') || undefined;
|
|
822
|
+
const robbotNameIsh = this.data.name?.slice(0, 8).replace(/[__]/mg, '') || undefined;
|
|
823
|
+
const robbotIdIsh = this.data.uuid?.slice(0, 8) || undefined;
|
|
824
|
+
const addlMetadataText = `robbot_${classnameIsh}_${robbotNameIsh}_${robbotIdIsh}`;
|
|
825
|
+
if (logalot) {
|
|
826
|
+
console.log(`${lc} addlMetadataText: ${addlMetadataText} (I: 53c0044671dc99fb75635367d2e63c22)`);
|
|
827
|
+
}
|
|
828
|
+
return addlMetadataText;
|
|
829
|
+
}
|
|
830
|
+
catch (error) {
|
|
831
|
+
console.error(`${lc} ${error.message}`);
|
|
832
|
+
throw error;
|
|
833
|
+
}
|
|
834
|
+
finally {
|
|
835
|
+
if (logalot) {
|
|
836
|
+
console.log(`${lc} complete.`);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
parseAddlMetadataString({ ib }) {
|
|
841
|
+
const lc = `${this.lc}[${this.parseAddlMetadataString.name}]`;
|
|
842
|
+
try {
|
|
843
|
+
if (logalot) {
|
|
844
|
+
console.log(`${lc} starting... (I: d0cf162bc5f4cbf65bf1f7e29e3bd922)`);
|
|
845
|
+
}
|
|
846
|
+
const { safeIbCommentMetadataText } = parseCommentIb({ ib });
|
|
847
|
+
if (safeIbCommentMetadataText) {
|
|
848
|
+
const [_, robbotClassnameIsh, robbotNameIsh, robbotIdIsh] = safeIbCommentMetadataText.split('__');
|
|
849
|
+
return { robbotClassnameIsh, robbotNameIsh, robbotIdIsh };
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
return { robbotClassnameIsh: undefined, robbotNameIsh: undefined, robbotIdIsh: undefined };
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
catch (error) {
|
|
856
|
+
console.error(`${lc} ${error.message}`);
|
|
857
|
+
throw error;
|
|
858
|
+
}
|
|
859
|
+
finally {
|
|
860
|
+
if (logalot) {
|
|
861
|
+
console.log(`${lc} complete.`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* by default in base class, this compares exactly the metadata string in a comment
|
|
867
|
+
* with this robbot.getaddlmetadata result.
|
|
868
|
+
*/
|
|
869
|
+
isMyComment({ ibGib }) {
|
|
870
|
+
const lc = `${this.lc}[${this.isMyComment.name}]`;
|
|
871
|
+
try {
|
|
872
|
+
if (logalot) {
|
|
873
|
+
console.log(`${lc} starting... (I: 18fc0c7132e2b5297a9c00df7f79e622)`);
|
|
874
|
+
}
|
|
875
|
+
const { safeIbCommentMetadataText } = parseCommentIb({ ib: ibGib.ib });
|
|
876
|
+
const isMine = safeIbCommentMetadataText === this.getAddlMetadata();
|
|
877
|
+
if (logalot) {
|
|
878
|
+
console.log(`${lc} metadata (${safeIbCommentMetadataText ?? 'undefined'}) isMine: ${isMine} (I: 1915fc7fd20e0ee8a2f8b554741b6622)`);
|
|
879
|
+
}
|
|
880
|
+
return isMine;
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
console.error(`${lc} ${error.message}`);
|
|
884
|
+
throw error;
|
|
885
|
+
}
|
|
886
|
+
finally {
|
|
887
|
+
if (logalot) {
|
|
888
|
+
console.log(`${lc} complete.`);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* gets ibgibs to which this robbot is directly rel8d WRT rel8nNames.
|
|
894
|
+
*
|
|
895
|
+
* @returns map of rel8nName -> ibgibs that this robbot is related to.
|
|
896
|
+
*/
|
|
897
|
+
async getRel8dIbGibs({ rel8nNames, }) {
|
|
898
|
+
const lc = `${this.lc}[${this.getRel8dIbGibs.name}]`;
|
|
899
|
+
try {
|
|
900
|
+
if (logalot) {
|
|
901
|
+
console.log(`${lc} starting... (I: f183ca9d23e8f67721b614cf01327b22)`);
|
|
902
|
+
}
|
|
903
|
+
if (!rel8nNames) {
|
|
904
|
+
rel8nNames = this.data?.allRel8nNames ?? [];
|
|
905
|
+
}
|
|
906
|
+
if (!this.data) {
|
|
907
|
+
console.warn(`${lc} (UNEXPECTED) this.data falsy? (W: d9dc3b322da443228c35209621ae96a4)`);
|
|
908
|
+
}
|
|
909
|
+
if (this.data?.defaultRel8nName && !rel8nNames.includes(this.data.defaultRel8nName)) {
|
|
910
|
+
rel8nNames.push(this.data.defaultRel8nName);
|
|
911
|
+
}
|
|
912
|
+
if (rel8nNames.length === 0) {
|
|
913
|
+
throw new Error(`rel8nNames arg required or this.data.allRel8nNames must have at least one rel8nName. (E: 32380232f04f6cb01e0791a754672722)`);
|
|
914
|
+
}
|
|
915
|
+
await this.loadNewerSelfIfAvailable();
|
|
916
|
+
if (!this.ibgibsSvc) {
|
|
917
|
+
throw new Error(`this.ibgibsSvc falsy (E: fd2f9e4384a725122f4de2eb76696923)`);
|
|
918
|
+
}
|
|
919
|
+
const space = await this.ibgibsSvc.getLocalUserSpace({ lock: true });
|
|
920
|
+
const rel8dIbGibs = {};
|
|
921
|
+
// todo: adjust to use the cacheIbGibs (not get them if already have in cache, but still return them in this fn's result)
|
|
922
|
+
for (let i = 0; i < rel8nNames.length; i++) {
|
|
923
|
+
const rel8nName = rel8nNames[i];
|
|
924
|
+
const rel8dAddrs = this.rel8ns ? (this.rel8ns[rel8nName] ?? []) : undefined ?? [];
|
|
925
|
+
if (rel8dAddrs.length > 0) {
|
|
926
|
+
const resGet = await getFromSpace({ addrs: rel8dAddrs, space });
|
|
927
|
+
if (resGet.success && resGet.ibGibs?.length === rel8dAddrs.length) {
|
|
928
|
+
rel8dIbGibs[rel8nName] = resGet.ibGibs.concat();
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
throw new Error(`there was a problem getting this robbot's rel8d ibgibs. ${resGet.errorMsg ?? 'some kinda problem...hmm..'} (E: 81e26309422ab87e5bd6bcf152059622)`);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
rel8dIbGibs[rel8nName] = [];
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return rel8dIbGibs;
|
|
939
|
+
}
|
|
940
|
+
catch (error) {
|
|
941
|
+
console.error(`${lc} ${error.message}`);
|
|
942
|
+
throw error;
|
|
943
|
+
}
|
|
944
|
+
finally {
|
|
945
|
+
if (logalot) {
|
|
946
|
+
console.log(`${lc} complete.`);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* helper function to wrap text in outputPrefix/Suffix
|
|
952
|
+
*
|
|
953
|
+
* @returns wrapped text, depending on param values.
|
|
954
|
+
*/
|
|
955
|
+
async getOutputText({ text, skipPrefix, skipSuffix, prefixOverride, suffixOverride, }) {
|
|
956
|
+
const lc = `${this.lc}[${this.getOutputText.name}]`;
|
|
957
|
+
try {
|
|
958
|
+
if (logalot) {
|
|
959
|
+
console.log(`${lc} starting... (I: 7107ae1bcbee485e96123ea1733cc191)`);
|
|
960
|
+
}
|
|
961
|
+
if (!text) {
|
|
962
|
+
console.error(`${lc} text required. (E: e1f5716c2a5744b5b5ca22dee6af8a85)`);
|
|
963
|
+
text = 'urmm, something went awry...the text is empty at this point.';
|
|
964
|
+
}
|
|
965
|
+
if (!this.data) {
|
|
966
|
+
throw new Error(`(UNEXPECTED) this.data falsy? (E: 0f0aab6b7f258d1a386cfb22349e9923)`);
|
|
967
|
+
}
|
|
968
|
+
let resText = skipPrefix || !this.data.outputPrefix ? text : `${prefixOverride ?? this.data.outputPrefix}\n\n${text}`;
|
|
969
|
+
if (!skipSuffix && this.data.outputSuffix) {
|
|
970
|
+
resText += `\n\n${suffixOverride ?? this.data.outputSuffix}`;
|
|
971
|
+
}
|
|
972
|
+
return resText;
|
|
973
|
+
}
|
|
974
|
+
catch (error) {
|
|
975
|
+
console.error(`${lc} ${error.message}`);
|
|
976
|
+
throw error;
|
|
977
|
+
}
|
|
978
|
+
finally {
|
|
979
|
+
if (logalot) {
|
|
980
|
+
console.log(`${lc} complete.`);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* By default, this rel8s to the given ibgibs via this.data.defaultRel8nName
|
|
986
|
+
*/
|
|
987
|
+
async lookAt({ ibGibs }) {
|
|
988
|
+
const lc = `${this.lc}[${this.lookAt.name}]`;
|
|
989
|
+
try {
|
|
990
|
+
if (logalot) {
|
|
991
|
+
console.log(`${lc} starting... (I: ea0e0ed92756ca339b8c03b700599722)`);
|
|
992
|
+
}
|
|
993
|
+
await this.rel8To({ ibGibs });
|
|
994
|
+
}
|
|
995
|
+
catch (error) {
|
|
996
|
+
console.error(`${lc} ${error.message}`);
|
|
997
|
+
throw error;
|
|
998
|
+
}
|
|
999
|
+
finally {
|
|
1000
|
+
if (logalot) {
|
|
1001
|
+
console.log(`${lc} complete.`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* I originally created this just to extract the context from the arg, but
|
|
1007
|
+
* I'm reusing it to get the latest context from the addr alone.
|
|
1008
|
+
*/
|
|
1009
|
+
async getContextIbGibFromArgOrAddr({ arg, addr, latest, }) {
|
|
1010
|
+
const lc = `${this.lc}[${this.getContextIbGibFromArgOrAddr.name}]`;
|
|
1011
|
+
try {
|
|
1012
|
+
if (logalot) {
|
|
1013
|
+
console.log(`${lc} starting... (I: c13f7cb92133984048f606075efb8a22)`);
|
|
1014
|
+
}
|
|
1015
|
+
let contextIbGib;
|
|
1016
|
+
if (!arg && !addr) {
|
|
1017
|
+
throw new Error(`either arg or addr required. (E: 3f647b65742242fd9ba878521acf7c22)`);
|
|
1018
|
+
}
|
|
1019
|
+
if (!this.ibgibsSvc) {
|
|
1020
|
+
throw new Error(`(UNEXPECTED) this.ibgibsSvc required (E: f0046290b0d66d28c4bbbf83d9d9f523)`);
|
|
1021
|
+
}
|
|
1022
|
+
if (arg) {
|
|
1023
|
+
if ((arg.ibGibs ?? []).length === 0) {
|
|
1024
|
+
throw new Error(`(UNEXPECTED) invalid arg? no context ibgib on arg (E: 89997eb4bdeb3885bee9de5d33ee0f22)`);
|
|
1025
|
+
}
|
|
1026
|
+
if ((arg.ibGibs ?? []).length !== 1) {
|
|
1027
|
+
throw new Error(`(UNEXPECTED) invalid arg? only expected one ibgib on arg.ibGibs (E: 1a1498af668740fe9439f4953a74ea8a)`);
|
|
1028
|
+
}
|
|
1029
|
+
contextIbGib = arg.ibGibs[0];
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
// addr provided
|
|
1033
|
+
const resGet = await this.ibgibsSvc.get({ addr });
|
|
1034
|
+
if (!resGet.success || resGet.ibGibs?.length !== 1) {
|
|
1035
|
+
throw new Error(`could not get context addr (${addr}) (E: 834492313512a45b23a7bebacdc48122)`);
|
|
1036
|
+
}
|
|
1037
|
+
contextIbGib = resGet.ibGibs[0];
|
|
1038
|
+
}
|
|
1039
|
+
if (latest) {
|
|
1040
|
+
const resLatestAddr = await this.ibgibsSvc.getLatestAddr({ ibGib: contextIbGib });
|
|
1041
|
+
if (resLatestAddr !== getIbGibAddr({ ibGib: contextIbGib })) {
|
|
1042
|
+
const resGet = await this.ibgibsSvc.get({ addr: resLatestAddr });
|
|
1043
|
+
if (resGet.success && resGet.ibGibs?.length === 1) {
|
|
1044
|
+
contextIbGib = resGet.ibGibs[0];
|
|
1045
|
+
}
|
|
1046
|
+
else {
|
|
1047
|
+
throw new Error(`unable to get resLatestAddr (${resLatestAddr}) (E: ce1e1297743e9a16c8f082321e52a122)`);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return contextIbGib;
|
|
1052
|
+
}
|
|
1053
|
+
catch (error) {
|
|
1054
|
+
console.error(`${lc} ${error.message}`);
|
|
1055
|
+
throw error;
|
|
1056
|
+
}
|
|
1057
|
+
finally {
|
|
1058
|
+
if (logalot) {
|
|
1059
|
+
console.log(`${lc} complete.`);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* The context is the ibgib where we are interacting with the user(s) (only
|
|
1065
|
+
* singlular atow).
|
|
1066
|
+
*
|
|
1067
|
+
* When we initialize, we are setting state on this robbot as well as subscribing
|
|
1068
|
+
* to the context ibgib's updates in `this.ibgibsSvc`.
|
|
1069
|
+
*
|
|
1070
|
+
* if we already have a context, then this will check the new incoming
|
|
1071
|
+
* context against it. If it's the same timeline, then this won't do
|
|
1072
|
+
* anything. Otherwise, it will finalize the previous context.
|
|
1073
|
+
*/
|
|
1074
|
+
async initializeContext({ arg, }) {
|
|
1075
|
+
const lc = `${this.lc}[${this.initializeContext.name}]`;
|
|
1076
|
+
try {
|
|
1077
|
+
if (logalot) {
|
|
1078
|
+
console.log(`${lc} starting... (I: d93429c85b0a494388f66fba3eece922)`);
|
|
1079
|
+
}
|
|
1080
|
+
// get context from arg just to compare the tjp's so we don't need
|
|
1081
|
+
// the latest at this point
|
|
1082
|
+
const incomingContext_NotLatest = await this.getContextIbGibFromArgOrAddr({ arg, latest: false });
|
|
1083
|
+
if (this._currentWorkingContextIbGib) {
|
|
1084
|
+
let currentTjpAddr = getTjpAddr({ ibGib: this._currentWorkingContextIbGib });
|
|
1085
|
+
const incomingTjpAddr = getTjpAddr({ ibGib: incomingContext_NotLatest });
|
|
1086
|
+
if (currentTjpAddr === incomingTjpAddr) {
|
|
1087
|
+
console.warn(`${lc} initializing context but it's the same timeline (${currentTjpAddr}). (W: 7609f8f51172443183e0c93ad52bfe56)`);
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
await this.finalizeContext({ arg });
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
/** used both now and when context ibgib is updated via observable */
|
|
1095
|
+
const updatePriorChildren = () => {
|
|
1096
|
+
this._currentWorkingContextIbGib_PriorChildrenAddrs = [
|
|
1097
|
+
...this._currentWorkingContextIbGib?.rel8ns?.comment ?? [],
|
|
1098
|
+
...this._currentWorkingContextIbGib?.rel8ns?.pic ?? [],
|
|
1099
|
+
...this._currentWorkingContextIbGib?.rel8ns?.link ?? [],
|
|
1100
|
+
];
|
|
1101
|
+
};
|
|
1102
|
+
// set the props
|
|
1103
|
+
this._currentWorkingContextIbGib = await this.getContextIbGibFromArgOrAddr({ arg, latest: true });
|
|
1104
|
+
updatePriorChildren();
|
|
1105
|
+
// subscribe to context ibgib updates
|
|
1106
|
+
const contextTjpAddr = getTjpAddr({ ibGib: this._currentWorkingContextIbGib });
|
|
1107
|
+
if (!this.ibgibsSvc) {
|
|
1108
|
+
throw new Error(`this.ibgibsSvc falsy...not initialized? (E: 6e38bfdc5c2eb5fef884f0183889e823)`);
|
|
1109
|
+
}
|
|
1110
|
+
this._contextChangesSubscription =
|
|
1111
|
+
this.ibgibsSvc.latestObs.pipe(filter(x => x.tjpAddr === contextTjpAddr)).subscribe(async (update) => {
|
|
1112
|
+
const currentAddr = getIbGibAddr({ ibGib: this._currentWorkingContextIbGib });
|
|
1113
|
+
if (update.latestAddr !== currentAddr) {
|
|
1114
|
+
if (logalot) {
|
|
1115
|
+
console.warn(`${lc} checking if new context is actually new...damn getLatestAddr maybe not working in ionic space... argh (W: 3d1a12154dfafb9c96d07e6f75f7a322)`);
|
|
1116
|
+
}
|
|
1117
|
+
if (update.latestIbGib) {
|
|
1118
|
+
let latestN_Supposedly = update.latestIbGib.data?.n ?? -1;
|
|
1119
|
+
let currentN = this._currentWorkingContextIbGib?.data?.n ?? -2;
|
|
1120
|
+
if (latestN_Supposedly <= currentN) {
|
|
1121
|
+
console.warn(`${lc} latestN is not really the latest. latestN_Supposedly: ${latestN_Supposedly}, currentN: ${currentN} (W: 6792c9a596c44c03b262614ae79a715e)`);
|
|
1122
|
+
return; /* <<<< returns early */
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
if (logalot) {
|
|
1126
|
+
console.log(`${lc} update to context.\ncurrentAddr: ${currentAddr}\nlatestAddr: ${update.latestAddr} (I: d0adcc392e6e974c9917730ebad51322)`);
|
|
1127
|
+
}
|
|
1128
|
+
this._currentWorkingContextIbGib =
|
|
1129
|
+
update.latestIbGib ??
|
|
1130
|
+
await this.getContextIbGibFromArgOrAddr({ addr: update.latestAddr, latest: false }); // already latest
|
|
1131
|
+
if (!this._updatingContext) {
|
|
1132
|
+
await this.handleContextUpdate({ update });
|
|
1133
|
+
updatePriorChildren();
|
|
1134
|
+
}
|
|
1135
|
+
else {
|
|
1136
|
+
if (logalot) {
|
|
1137
|
+
console.log(`${lc} already updating context (I: f856f9414627ab00418dccd285b55822)`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
// rel8 to the context (conversation)
|
|
1143
|
+
await this.rel8To({
|
|
1144
|
+
ibGibs: [this._currentWorkingContextIbGib],
|
|
1145
|
+
rel8nName: ROBBOT_CONTEXT_REL8N_NAME,
|
|
1146
|
+
});
|
|
1147
|
+
// subscribe to receive updates to the context so we can participate
|
|
1148
|
+
// in the conversation (i.e. interpret incoming ibgibs like commands
|
|
1149
|
+
// if needed)
|
|
1150
|
+
// let gibInfo = getGibInfo({ gib: this._currentWorkingContextIbGib.gib });
|
|
1151
|
+
// if (gibInfo.tjpGib) {
|
|
1152
|
+
// this.ibgibsSvc.latestObs
|
|
1153
|
+
// .subscribe(update => {
|
|
1154
|
+
// if (!update.tjpAddr) { return; /* <<<< returns early */ }
|
|
1155
|
+
// if (getIbAndGib({ ibGibAddr: update.tjpAddr }).gib !== gibInfo.tjpGib) { return; /* <<<< returns early */ }
|
|
1156
|
+
// if (update.latestAddr === getIbGibAddr({ ibGib: this._currentWorkingContextIbGib })) {
|
|
1157
|
+
// if (logalot) { console.log(`${lc} already have that context... (I: a6e17ec40d620f0bd5b231db39eaa522)`); }
|
|
1158
|
+
// return; /* <<<< returns early */
|
|
1159
|
+
// }
|
|
1160
|
+
// if (this._updatingContext) {
|
|
1161
|
+
// if (logalot) { console.log(`${lc} already updating context (I: f856f9414627ab00418dccd285b55822)`); }
|
|
1162
|
+
// return; /* <<<< returns early */
|
|
1163
|
+
// }
|
|
1164
|
+
// this.handleContextUpdate({ update });
|
|
1165
|
+
// });
|
|
1166
|
+
// }
|
|
1167
|
+
}
|
|
1168
|
+
catch (error) {
|
|
1169
|
+
console.error(`${lc} ${error.message}`);
|
|
1170
|
+
throw error;
|
|
1171
|
+
}
|
|
1172
|
+
finally {
|
|
1173
|
+
if (logalot) {
|
|
1174
|
+
console.log(`${lc} complete.`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
async finalizeContext({ arg, }) {
|
|
1179
|
+
const lc = `${this.lc}[${this.finalizeContext.name}]`;
|
|
1180
|
+
try {
|
|
1181
|
+
if (logalot) {
|
|
1182
|
+
console.log(`${lc} starting... (I: dd53dfc745864dd19fde5f209ceb82c8)`);
|
|
1183
|
+
}
|
|
1184
|
+
let tries = 0;
|
|
1185
|
+
const maxTries = 100;
|
|
1186
|
+
while (this._updatingContext && tries < maxTries) {
|
|
1187
|
+
await delay(100);
|
|
1188
|
+
tries++;
|
|
1189
|
+
if (tries % 10 === 0) {
|
|
1190
|
+
console.log(`${lc} already updating context and taking a litle while... waiting still. tries: ${tries}/${maxTries} (I: d45ab59af9ea43518432e34ddad95c19)`);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
if (this._updatingContext) {
|
|
1194
|
+
console.error(`${lc} previous call to updatingContext took too long. Ignoring flag and finalizing context. (E: 9a2dc4e1923442fa90fbeae72f358acd)`);
|
|
1195
|
+
}
|
|
1196
|
+
this._updatingContext = true;
|
|
1197
|
+
if (this._contextChangesSubscription) {
|
|
1198
|
+
debugger;
|
|
1199
|
+
this._contextChangesSubscription.unsubscribe();
|
|
1200
|
+
delete this._contextChangesSubscription;
|
|
1201
|
+
}
|
|
1202
|
+
delete this._currentWorkingContextIbGib;
|
|
1203
|
+
if (this._currentWorkingContextIbGib) {
|
|
1204
|
+
await this.createCommentAndRel8ToContextIbGib({
|
|
1205
|
+
text: await this.getOutputText({ text: 'end of line' }),
|
|
1206
|
+
contextIbGib: this._currentWorkingContextIbGib,
|
|
1207
|
+
});
|
|
1208
|
+
delete this._currentWorkingContextIbGib;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
catch (error) {
|
|
1212
|
+
console.error(`${lc} ${error.message}`);
|
|
1213
|
+
throw error;
|
|
1214
|
+
}
|
|
1215
|
+
finally {
|
|
1216
|
+
this._updatingContext = false;
|
|
1217
|
+
if (logalot) {
|
|
1218
|
+
console.log(`${lc} complete.`);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Handles a new ibgib in the current working context.
|
|
1224
|
+
*
|
|
1225
|
+
* If it originated from the robbot him/herself, then we will ignore it.
|
|
1226
|
+
* Otherwise this is interpreted either as a "command" or something to remember.
|
|
1227
|
+
*
|
|
1228
|
+
* ## notes
|
|
1229
|
+
*
|
|
1230
|
+
* If the user says something and we're listening (this is triggered), then
|
|
1231
|
+
* it should be either interpreted as a "command" or ignored. I put
|
|
1232
|
+
* "command" in quotes because the word is a very short-sighted
|
|
1233
|
+
* understanding of the conversational aspect. Or perhaps I speak to the
|
|
1234
|
+
* connotations to current belief's regarding robbots and commands.
|
|
1235
|
+
*
|
|
1236
|
+
* This is complicated by the possibility in the future of multiple robbots
|
|
1237
|
+
* being engaged in a conversation within the same context.
|
|
1238
|
+
*/
|
|
1239
|
+
async handleContextUpdate({ update }) {
|
|
1240
|
+
const lc = `${this.lc}[${this.handleContextUpdate.name}]`;
|
|
1241
|
+
// I don't see this as really being very likely in the near future,
|
|
1242
|
+
// but putting in a wait delay in case there are multiple updates
|
|
1243
|
+
while (this._updatingContext) {
|
|
1244
|
+
console.warn(`${lc} already updating context? delaying... (W: 19d2ebeaaf2340fb91a7d6c717e9cb41)`);
|
|
1245
|
+
await delay(1000);
|
|
1246
|
+
}
|
|
1247
|
+
this._updatingContext = true;
|
|
1248
|
+
try {
|
|
1249
|
+
if (logalot) {
|
|
1250
|
+
console.log(`${lc} starting... (I: 3eeaa40cad49094f125f9f5cd6ff6e22)`);
|
|
1251
|
+
}
|
|
1252
|
+
// if it's caused by this robbot speaking, then we don't really need
|
|
1253
|
+
// it. but if it's from the user, then we want to respond.
|
|
1254
|
+
if (logalot) {
|
|
1255
|
+
console.log(`${lc} update: (I: ad0abae7de472e3b4d3891ea0b937322)`);
|
|
1256
|
+
console.table(update);
|
|
1257
|
+
}
|
|
1258
|
+
if (!update.latestIbGib) {
|
|
1259
|
+
debugger;
|
|
1260
|
+
throw new Error(`(UNEXPECTED) update.latestIbGib falsy? (E: e18a048d7e95757238396ddd84748f22)`);
|
|
1261
|
+
}
|
|
1262
|
+
const newContext = update.latestIbGib;
|
|
1263
|
+
const newChildrenIbGibs = await this.getNewChildrenIbGibs({ newContext });
|
|
1264
|
+
// should normally be just one (would be very edge casey if not atow)
|
|
1265
|
+
let newChild;
|
|
1266
|
+
if (newChildrenIbGibs.length === 1) {
|
|
1267
|
+
newChild = newChildrenIbGibs[0];
|
|
1268
|
+
}
|
|
1269
|
+
else if (newChildrenIbGibs.length > 1) {
|
|
1270
|
+
console.warn(`${lc} (UNEXPECTED) found multiple new children in conversation? Using only the last. (W: 02d82a8f755f418d95fa30f0f52ad58e)`);
|
|
1271
|
+
newChild = newChildrenIbGibs[newChildrenIbGibs.length - 1];
|
|
1272
|
+
}
|
|
1273
|
+
else {
|
|
1274
|
+
// no new children, so maybe the user deleted something or who knows.
|
|
1275
|
+
if (logalot) {
|
|
1276
|
+
console.log(`${lc} no new children in context update. returning early... (I: 31397b04965351ab29bb3f78cb709122)`);
|
|
1277
|
+
}
|
|
1278
|
+
return; /* <<<< returns early */
|
|
1279
|
+
}
|
|
1280
|
+
// we have a new chidl inthe context.
|
|
1281
|
+
await this.handleNewContextChild({ newChild });
|
|
1282
|
+
}
|
|
1283
|
+
catch (error) {
|
|
1284
|
+
console.error(`${lc} ${error.message}`);
|
|
1285
|
+
throw error;
|
|
1286
|
+
}
|
|
1287
|
+
finally {
|
|
1288
|
+
this._updatingContext = false;
|
|
1289
|
+
if (logalot) {
|
|
1290
|
+
console.log(`${lc} complete.`);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
async getNewChildrenIbGibs({ newContext }) {
|
|
1295
|
+
const lc = `${this.lc}[${this.getNewChildrenIbGibs.name}]`;
|
|
1296
|
+
try {
|
|
1297
|
+
if (logalot) {
|
|
1298
|
+
console.log(`${lc} starting... (I: 1b3d1cf908489087fa3b281f55b9a522)`);
|
|
1299
|
+
}
|
|
1300
|
+
// get a diff of the new addrs vs. the old addrs.
|
|
1301
|
+
/** all of the children addrs of the new context */
|
|
1302
|
+
const newContextChildrenAddrs = [
|
|
1303
|
+
...newContext.rel8ns?.comment ?? [],
|
|
1304
|
+
...newContext.rel8ns?.pic ?? [],
|
|
1305
|
+
...newContext.rel8ns?.link ?? [],
|
|
1306
|
+
];
|
|
1307
|
+
/** just the new addrs from the context */
|
|
1308
|
+
const newChildrenAddrs = newContextChildrenAddrs.filter(x => !this._currentWorkingContextIbGib_PriorChildrenAddrs.includes(x));
|
|
1309
|
+
if (newChildrenAddrs.length === 0) {
|
|
1310
|
+
// no new children
|
|
1311
|
+
if (logalot) {
|
|
1312
|
+
console.log(`${lc} no new children addrs in newContext. returning early... (I: 8f9c3658c194c472cb1e2bc19d847b22)`);
|
|
1313
|
+
}
|
|
1314
|
+
return []; /* <<<< returns early */
|
|
1315
|
+
}
|
|
1316
|
+
// get the latest addrs for those children
|
|
1317
|
+
if (!this.ibgibsSvc) {
|
|
1318
|
+
throw new Error(`this.ibgibsSvc falsy. not initialized? (E: 1cc26ca7de7fadcdbaecbd6613350e23)`);
|
|
1319
|
+
}
|
|
1320
|
+
const space = await this.ibgibsSvc.getLocalUserSpace({});
|
|
1321
|
+
if (!space) {
|
|
1322
|
+
throw new Error(`couldn't get local user space? (E: f118f75e5852fc22bba3a6495beec723)`);
|
|
1323
|
+
}
|
|
1324
|
+
const resLatestAddrs = await getLatestAddrs({ addrs: newChildrenAddrs, space, });
|
|
1325
|
+
const latestAddrs = Object.values(resLatestAddrs?.data?.latestAddrsMap ?? {});
|
|
1326
|
+
if (!resLatestAddrs?.data?.success || latestAddrs.length !== newChildrenAddrs.length) {
|
|
1327
|
+
throw new Error(`could not get latest addrs. (E: 2e1619e7e2e166696fe8ff78cb02cc22)`);
|
|
1328
|
+
}
|
|
1329
|
+
// get the addrs' corresponding ibgibs
|
|
1330
|
+
if (latestAddrs.some(x => x === null)) {
|
|
1331
|
+
// some of the addrs were not found in the space
|
|
1332
|
+
throw new Error(`some addrs were not found in the space. (E: 2216d8e5ad7fb600ceb025ed7c90f323)`);
|
|
1333
|
+
}
|
|
1334
|
+
const resGet = await this.ibgibsSvc.get({ addrs: latestAddrs });
|
|
1335
|
+
if (!resGet.success || resGet.ibGibs?.length !== newChildrenAddrs.length) {
|
|
1336
|
+
throw new Error(`failed to get newChildren with addrs: ${newChildrenAddrs.join('|')}. Error: ${resGet.errorMsg ?? 'unknown error 5737bd0996d5445b8bd80975bedc0d57'} (E: 05722e11350ec6ffffdb5c7d0caa2922)`);
|
|
1337
|
+
}
|
|
1338
|
+
return resGet.ibGibs;
|
|
1339
|
+
}
|
|
1340
|
+
catch (error) {
|
|
1341
|
+
console.error(`${lc} ${error.message}`);
|
|
1342
|
+
throw error;
|
|
1343
|
+
}
|
|
1344
|
+
finally {
|
|
1345
|
+
if (logalot) {
|
|
1346
|
+
console.log(`${lc} complete.`);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
async handleNewContextChild({ newChild }) {
|
|
1351
|
+
const lc = `${this.lc}[${this.handleNewContextChild.name}]`;
|
|
1352
|
+
try {
|
|
1353
|
+
throw new Error(`not implemented in base class (E: 833038a17d04e38b9b97be19ed010922)`);
|
|
1354
|
+
}
|
|
1355
|
+
catch (error) {
|
|
1356
|
+
console.error(`${lc} ${error.message}`);
|
|
1357
|
+
throw error;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
async getRobbotInteractionData({ type, commentText, subjectTjpGibs, details, expectingResponse, uuid, timestamp, }) {
|
|
1361
|
+
const lc = `${this.lc}[${this.getRobbotInteractionData.name}]`;
|
|
1362
|
+
try {
|
|
1363
|
+
if (logalot) {
|
|
1364
|
+
console.log(`${lc} starting... (I: b05837a91c6973326fde8cf51aac1922)`);
|
|
1365
|
+
}
|
|
1366
|
+
if (!type) {
|
|
1367
|
+
throw new Error(`type required (E: 737f8ecc21c519d1d61bce2a91fe2d22)`);
|
|
1368
|
+
}
|
|
1369
|
+
if (!this._currentWorkingContextIbGib?.gib) {
|
|
1370
|
+
throw new Error(`this._currentWorkingContextIbGib?.gib is falsy (E: 6489a36ab0c797f1b5d52db709ea0322)`);
|
|
1371
|
+
}
|
|
1372
|
+
uuid = uuid || await getUUID();
|
|
1373
|
+
timestamp = timestamp || getTimestamp();
|
|
1374
|
+
let contextTjpGib = getGibInfo({ gib: this._currentWorkingContextIbGib.gib }).tjpGib;
|
|
1375
|
+
if (!contextTjpGib) {
|
|
1376
|
+
contextTjpGib = this._currentWorkingContextIbGib.gib;
|
|
1377
|
+
if (!contextTjpGib) {
|
|
1378
|
+
throw new Error(`(UNEXPECTED) this._currentWorkingContextIbGib.gib falsy? (E: 50cddb787f1a0af19567531b30bd5522)`);
|
|
1379
|
+
}
|
|
1380
|
+
console.warn(`${lc} contextTjpGib is falsy? This means that the robbot context does not have a timeline. This might be ok, but not expected. contextTjp will be considered the gib of the context (${contextTjpGib}) (W: f2a6f91ef5e44170a5e3d5456f2fb2f2)`);
|
|
1381
|
+
}
|
|
1382
|
+
const data = {
|
|
1383
|
+
uuid,
|
|
1384
|
+
timestamp,
|
|
1385
|
+
type,
|
|
1386
|
+
contextTjpGib,
|
|
1387
|
+
commentText,
|
|
1388
|
+
expectingResponse,
|
|
1389
|
+
subjectTjpGibs,
|
|
1390
|
+
};
|
|
1391
|
+
if (details) {
|
|
1392
|
+
data.details = details;
|
|
1393
|
+
}
|
|
1394
|
+
return data;
|
|
1395
|
+
}
|
|
1396
|
+
catch (error) {
|
|
1397
|
+
console.error(`${lc} ${error.message}`);
|
|
1398
|
+
throw error;
|
|
1399
|
+
}
|
|
1400
|
+
finally {
|
|
1401
|
+
if (logalot) {
|
|
1402
|
+
console.log(`${lc} complete.`);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
//# sourceMappingURL=robbot-base-v1.js.map
|