@ibgib/core-gib 0.0.8 → 0.0.11
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/README.md +5 -10
- 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/core-constants.d.mts +0 -2
- package/dist/core-constants.d.mts.map +1 -1
- package/dist/core-constants.mjs +0 -2
- package/dist/core-constants.mjs.map +1 -1
- package/dist/core-helper.respec.d.mts +2 -0
- package/dist/core-helper.respec.d.mts.map +1 -0
- package/dist/core-helper.respec.mjs +53 -0
- package/dist/core-helper.respec.mjs.map +1 -0
- package/dist/core-types.d.mts +22 -0
- package/dist/core-types.d.mts.map +1 -1
- 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 +12 -0
- package/dist/spec-helper.node.respec.d.mts.map +1 -0
- package/dist/spec-helper.node.respec.mjs +43 -0
- package/dist/spec-helper.node.respec.mjs.map +1 -0
- package/dist/witness/app/app-base-v1.d.mts +2 -2
- package/dist/witness/app/app-base-v1.d.mts.map +1 -1
- package/dist/witness/app/app-base-v1.mjs +23 -141
- package/dist/witness/app/app-base-v1.mjs.map +1 -1
- package/dist/witness/app/app-constants.d.mts +2 -0
- package/dist/witness/app/app-constants.d.mts.map +1 -1
- package/dist/witness/app/app-constants.mjs +2 -0
- package/dist/witness/app/app-constants.mjs.map +1 -1
- package/dist/witness/app/app-helper.d.mts.map +1 -1
- package/dist/witness/app/app-helper.mjs +2 -1
- package/dist/witness/app/app-helper.mjs.map +1 -1
- package/dist/witness/app/app-types.d.mts +2 -1
- package/dist/witness/app/app-types.d.mts.map +1 -1
- package/dist/witness/robbot/robbot-base-v1.d.mts +12 -164
- package/dist/witness/robbot/robbot-base-v1.d.mts.map +1 -1
- package/dist/witness/robbot/robbot-base-v1.mjs +41 -657
- package/dist/witness/robbot/robbot-base-v1.mjs.map +1 -1
- package/dist/witness/robbot/robbot-helper.mjs +3 -3
- package/dist/witness/robbot/robbot-helper.mjs.map +1 -1
- package/dist/witness/robbot/robbot-helper.respec.d.mts +2 -0
- package/dist/witness/robbot/robbot-helper.respec.d.mts.map +1 -0
- package/dist/witness/robbot/robbot-helper.respec.mjs +106 -0
- package/dist/witness/robbot/robbot-helper.respec.mjs.map +1 -0
- package/dist/witness/robbot/robbot-types.d.mts +6 -3
- package/dist/witness/robbot/robbot-types.d.mts.map +1 -1
- package/dist/witness/robbot/robbot-types.mjs +1 -0
- package/dist/witness/robbot/robbot-types.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/filesystem-space-v1.d.mts +1 -1
- package/dist/witness/space/filesystem-space/filesystem-space-v1.d.mts.map +1 -1
- package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.d.mts +2 -0
- package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.d.mts.map +1 -0
- package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.mjs +107 -0
- package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.mjs.map +1 -0
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.d.mts.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.mjs +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.mjs.map +1 -1
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.d.mts +2 -0
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.d.mts.map +1 -0
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.mjs +129 -0
- package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.mjs.map +1 -0
- package/dist/witness/space/inner-space/inner-space-v1.respec.d.mts +2 -0
- package/dist/witness/space/inner-space/inner-space-v1.respec.d.mts.map +1 -0
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs +56 -0
- package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -0
- package/dist/witness/space/metaspace/metaspace-base.d.mts +795 -0
- package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -0
- package/dist/witness/space/metaspace/metaspace-base.mjs +3251 -0
- package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts +4 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts.map +1 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs +117 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs.map +1 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.d.mts +34 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.d.mts.map +1 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs +76 -0
- package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs.map +1 -0
- package/dist/witness/space/metaspace/metaspace-types.d.mts +580 -0
- package/dist/witness/space/metaspace/metaspace-types.d.mts.map +1 -0
- package/dist/witness/space/metaspace/metaspace-types.mjs +6 -0
- package/dist/witness/space/metaspace/metaspace-types.mjs.map +1 -0
- package/dist/witness/space/space-helper.d.mts.map +1 -1
- package/dist/witness/space/space-helper.mjs +2 -1
- package/dist/witness/space/space-helper.mjs.map +1 -1
- package/dist/witness/space/{space-spec-helper.d.mts → space-respec-helper.d.mts} +15 -5
- package/dist/witness/space/space-respec-helper.d.mts.map +1 -0
- package/dist/witness/space/space-respec-helper.mjs +186 -0
- package/dist/witness/space/space-respec-helper.mjs.map +1 -0
- package/dist/witness/space/space-types.d.mts +2 -1
- package/dist/witness/space/space-types.d.mts.map +1 -1
- package/dist/witness/space/space-types.mjs.map +1 -1
- package/dist/witness/witness-base-v1.d.mts.map +1 -1
- package/dist/witness/witness-base-v1.mjs +7 -7
- package/dist/witness/witness-base-v1.mjs.map +1 -1
- package/dist/witness/witness-cmd/witness-cmd-types.d.mts +31 -0
- package/dist/witness/witness-cmd/witness-cmd-types.d.mts.map +1 -0
- package/dist/witness/witness-cmd/witness-cmd-types.mjs +2 -0
- package/dist/witness/witness-cmd/witness-cmd-types.mjs.map +1 -0
- package/dist/witness/witness-helper.d.mts +8 -0
- package/dist/witness/witness-helper.d.mts.map +1 -1
- package/dist/witness/witness-helper.mjs +30 -0
- package/dist/witness/witness-helper.mjs.map +1 -1
- package/dist/witness/witness-types.d.mts +26 -36
- package/dist/witness/witness-types.d.mts.map +1 -1
- package/dist/witness/witness-with-context/witness-with-context-base-v1.d.mts +235 -0
- package/dist/witness/witness-with-context/witness-with-context-base-v1.d.mts.map +1 -0
- package/dist/witness/witness-with-context/witness-with-context-base-v1.mjs +742 -0
- package/dist/witness/witness-with-context/witness-with-context-base-v1.mjs.map +1 -0
- package/dist/witness/witness-with-context/witness-with-context-types.d.mts +17 -0
- package/dist/witness/witness-with-context/witness-with-context-types.d.mts.map +1 -0
- package/dist/witness/witness-with-context/witness-with-context-types.mjs +2 -0
- package/dist/witness/witness-with-context/witness-with-context-types.mjs.map +1 -0
- package/package.json +12 -15
- package/src/{assumptions.spec.mts → assumptions.respec.mts} +11 -5
- package/src/core-constants.mts +0 -2
- package/src/core-helper.respec.mts +71 -0
- package/src/core-types.mts +20 -0
- package/src/respec-gib.node.mts +199 -0
- package/src/witness/app/app-base-v1.mts +19 -212
- package/src/witness/app/app-constants.mts +3 -0
- package/src/witness/app/app-helper.mts +2 -1
- package/src/witness/app/app-types.mts +1 -1
- package/src/witness/robbot/robbot-base-v1.mts +39 -690
- package/src/witness/robbot/robbot-helper.mts +1 -1
- package/src/witness/robbot/{robbot-helper.spec.mts → robbot-helper.respec.mts} +39 -33
- package/src/witness/robbot/robbot-types.mts +5 -3
- package/src/witness/space/filesystem-space/filesystem-space-v1.mts +1 -1
- package/src/witness/space/filesystem-space/{filesystem-space-v1.spec.mts → filesystem-space-v1.respec.mts} +17 -8
- package/src/witness/space/filesystem-space/node-filesystem-space-v1.mts +3 -11
- package/src/witness/space/filesystem-space/{node-filesystem-space-v1.node.spec.mts → node-filesystem-space-v1.node.respec.mts} +18 -14
- package/src/witness/space/inner-space/{inner-space-v1.spec.mts → inner-space-v1.respec.mts} +17 -8
- package/src/witness/space/metaspace/metaspace-base.mts +3702 -0
- package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mts +116 -0
- package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mts +88 -0
- package/src/witness/space/metaspace/metaspace-types.mts +614 -0
- package/src/witness/space/space-helper.mts +2 -1
- package/src/witness/space/{space-spec-helper.mts → space-respec-helper.mts} +76 -57
- package/src/witness/space/space-types.mts +2 -1
- package/src/witness/witness-base-v1.mts +8 -6
- package/src/witness/witness-cmd/witness-cmd-types.mts +38 -0
- package/src/witness/witness-helper.mts +31 -0
- package/src/witness/witness-types.mts +31 -41
- package/src/witness/witness-with-context/witness-with-context-base-v1.mts +809 -0
- package/src/witness/witness-with-context/witness-with-context-types.mts +24 -0
- package/tsconfig.json +1 -0
- package/dist/witness/space/space-spec-helper.d.mts.map +0 -1
- package/dist/witness/space/space-spec-helper.mjs +0 -179
- package/dist/witness/space/space-spec-helper.mjs.map +0 -1
- package/jasmine-browser.json +0 -18
- package/jasmine.json +0 -6
- package/src/core-helper.spec.mts +0 -64
- /package/src/{spec-helper.node.spec.mts → spec-helper.node.respec.mts} +0 -0
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { V1, getIbGibAddr } from '@ibgib/ts-gib';
|
|
1
|
+
import { getIbGibAddr } from '@ibgib/ts-gib';
|
|
3
2
|
import { getGibInfo } from '@ibgib/ts-gib/dist/V1/index.mjs';
|
|
4
3
|
import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
|
|
5
|
-
import { RobbotCmd,
|
|
6
|
-
import { WitnessBase_V1, } from '../witness-base-v1.mjs';
|
|
4
|
+
import { RobbotCmd, ROBBOT_CONTEXT_REL8N_NAME, SemanticId, RobbotInteractionType, DEFAULT_ROBBOT_LEX_DATA, DEFAULT_HUMAN_LEX_DATA, ROBBOT_ATOM, } from './robbot-types.mjs';
|
|
7
5
|
import { getInteractionIbGib_V1, validateCommonRobbotData } from './robbot-helper.mjs';
|
|
8
6
|
import { argy_, isArg, resulty_ } from '../witness-helper.mjs';
|
|
9
|
-
import {
|
|
10
|
-
import { Lex, clone, delay, getTimestamp, getUUID, pretty } from '@ibgib/helper-gib';
|
|
7
|
+
import { Lex, clone, getTimestamp, getUUID } from '@ibgib/helper-gib';
|
|
11
8
|
import { errorIbGib } from '../../common/error/error-helper.mjs';
|
|
12
|
-
import {
|
|
13
|
-
import { getFromSpace
|
|
14
|
-
import {
|
|
9
|
+
import { parseCommentIb } from '../../common/comment/comment-helper.mjs';
|
|
10
|
+
import { getFromSpace } from '../space/space-helper.mjs';
|
|
11
|
+
import { WitnessWithContextBase_V1 } from '../witness-with-context/witness-with-context-base-v1.mjs';
|
|
15
12
|
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
16
13
|
/**
|
|
17
14
|
* ## distinguishing characteristics of robbots
|
|
@@ -60,7 +57,23 @@ const logalot = GLOBAL_LOG_A_LOT || true;
|
|
|
60
57
|
* calls if they end up called for, effectively the equivalent of the
|
|
61
58
|
* old-fashioned "ProcessMessages/DoEvents" hack.
|
|
62
59
|
*/
|
|
63
|
-
export class RobbotBase_V1 extends
|
|
60
|
+
export class RobbotBase_V1 extends WitnessWithContextBase_V1 {
|
|
61
|
+
constructor(initialData, initialRel8ns) {
|
|
62
|
+
super(initialData, initialRel8ns);
|
|
63
|
+
/**
|
|
64
|
+
* Log context for convenience with logging. (Ignore if you don't want to use this.)
|
|
65
|
+
*
|
|
66
|
+
* Often used in conjunction with `logalot`.
|
|
67
|
+
*/
|
|
68
|
+
this.lc = `[${RobbotBase_V1.name}]`;
|
|
69
|
+
/**
|
|
70
|
+
* When the robbot has to get some ibgibs, might as well store them here so
|
|
71
|
+
* we don't have to get them again from storage.
|
|
72
|
+
*/
|
|
73
|
+
this._cacheIbGibs = {};
|
|
74
|
+
this._semanticHandlers = {};
|
|
75
|
+
this.initialized = this.initialize();
|
|
76
|
+
}
|
|
64
77
|
async handleSemanticDefault(info) {
|
|
65
78
|
const lc = `${this.lc}[${this.handleSemanticDefault.name}]`;
|
|
66
79
|
try {
|
|
@@ -90,32 +103,6 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
90
103
|
}
|
|
91
104
|
}
|
|
92
105
|
}
|
|
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 = `[${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
106
|
// #region initialize
|
|
120
107
|
/**
|
|
121
108
|
* Initializes to default space values.
|
|
@@ -126,6 +113,7 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
126
113
|
if (logalot) {
|
|
127
114
|
console.log(`${lc} starting... (I: f0e65ab0f80046a59668ddfbf9f47a4a5)`);
|
|
128
115
|
}
|
|
116
|
+
await super.initialize();
|
|
129
117
|
await this.initialize_semanticHandlers();
|
|
130
118
|
await this.initialize_lex();
|
|
131
119
|
}
|
|
@@ -211,43 +199,6 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
211
199
|
}
|
|
212
200
|
}
|
|
213
201
|
// #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
202
|
/**
|
|
252
203
|
* At this point in time, the arg has already been intrinsically validated,
|
|
253
204
|
* as well as the internal state of this robbot. so whatever this robbot's
|
|
@@ -263,7 +214,14 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
263
214
|
console.log(`${lc} starting...`);
|
|
264
215
|
}
|
|
265
216
|
await this.loadNewerSelfIfAvailable();
|
|
266
|
-
|
|
217
|
+
let result = await this.routeAndDoArg({ arg });
|
|
218
|
+
if (!result) {
|
|
219
|
+
result = await this.doDefault({ ibGib: arg });
|
|
220
|
+
}
|
|
221
|
+
if (!result) {
|
|
222
|
+
console.warn(`${lc} result falsy...Could not produce result? Was doDefault implemented in concrete class? (W: 67f5fc5e6e864a13b0053fb54cfba100)`);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
267
225
|
}
|
|
268
226
|
catch (error) {
|
|
269
227
|
console.error(`${lc} ${error.message}`);
|
|
@@ -432,7 +390,10 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
432
390
|
throw new Error(`arg required (E: 9cddabc6dc96ddb37846807feb093423)`);
|
|
433
391
|
}
|
|
434
392
|
if (arg.ibGibs?.length ?? 0 > 0) {
|
|
435
|
-
await this.initializeContext({
|
|
393
|
+
await this.initializeContext({
|
|
394
|
+
arg: arg,
|
|
395
|
+
rel8nName: ROBBOT_CONTEXT_REL8N_NAME,
|
|
396
|
+
});
|
|
436
397
|
}
|
|
437
398
|
const result = await this.resulty({
|
|
438
399
|
resultData: {
|
|
@@ -459,7 +420,9 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
459
420
|
console.log(`${lc} starting... (I: d453593a295d4cdbae2acb71d9f6de35)`);
|
|
460
421
|
}
|
|
461
422
|
await this.initialized;
|
|
462
|
-
await this.finalizeContext({
|
|
423
|
+
await this.finalizeContext({
|
|
424
|
+
arg: arg,
|
|
425
|
+
});
|
|
463
426
|
const result = await this.resulty({
|
|
464
427
|
resultData: {
|
|
465
428
|
optsAddr: getIbGibAddr({ ibGib: arg }),
|
|
@@ -545,117 +508,6 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
545
508
|
}
|
|
546
509
|
}
|
|
547
510
|
// #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
511
|
/**
|
|
660
512
|
* validates against common robbot qualities.
|
|
661
513
|
*
|
|
@@ -721,121 +573,8 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
721
573
|
}
|
|
722
574
|
return result;
|
|
723
575
|
}
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
}
|
|
576
|
+
getThisAtom() {
|
|
577
|
+
return ROBBOT_ATOM; // "robbot" atow
|
|
839
578
|
}
|
|
840
579
|
parseAddlMetadataString({ ib }) {
|
|
841
580
|
const lc = `${this.lc}[${this.parseAddlMetadataString.name}]`;
|
|
@@ -1002,361 +741,6 @@ export class RobbotBase_V1 extends WitnessBase_V1 {
|
|
|
1002
741
|
}
|
|
1003
742
|
}
|
|
1004
743
|
}
|
|
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
744
|
async getRobbotInteractionData({ type, commentText, subjectTjpGibs, details, expectingResponse, uuid, timestamp, }) {
|
|
1361
745
|
const lc = `${this.lc}[${this.getRobbotInteractionData.name}]`;
|
|
1362
746
|
try {
|