@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.
Files changed (154) hide show
  1. package/README.md +5 -10
  2. package/dist/assumptions.respec.d.mts +2 -0
  3. package/dist/assumptions.respec.d.mts.map +1 -0
  4. package/dist/assumptions.respec.mjs +41 -0
  5. package/dist/assumptions.respec.mjs.map +1 -0
  6. package/dist/core-constants.d.mts +0 -2
  7. package/dist/core-constants.d.mts.map +1 -1
  8. package/dist/core-constants.mjs +0 -2
  9. package/dist/core-constants.mjs.map +1 -1
  10. package/dist/core-helper.respec.d.mts +2 -0
  11. package/dist/core-helper.respec.d.mts.map +1 -0
  12. package/dist/core-helper.respec.mjs +53 -0
  13. package/dist/core-helper.respec.mjs.map +1 -0
  14. package/dist/core-types.d.mts +22 -0
  15. package/dist/core-types.d.mts.map +1 -1
  16. package/dist/respec-gib.node.d.mts +2 -0
  17. package/dist/respec-gib.node.d.mts.map +1 -0
  18. package/dist/respec-gib.node.mjs +211 -0
  19. package/dist/respec-gib.node.mjs.map +1 -0
  20. package/dist/spec-helper.node.respec.d.mts +12 -0
  21. package/dist/spec-helper.node.respec.d.mts.map +1 -0
  22. package/dist/spec-helper.node.respec.mjs +43 -0
  23. package/dist/spec-helper.node.respec.mjs.map +1 -0
  24. package/dist/witness/app/app-base-v1.d.mts +2 -2
  25. package/dist/witness/app/app-base-v1.d.mts.map +1 -1
  26. package/dist/witness/app/app-base-v1.mjs +23 -141
  27. package/dist/witness/app/app-base-v1.mjs.map +1 -1
  28. package/dist/witness/app/app-constants.d.mts +2 -0
  29. package/dist/witness/app/app-constants.d.mts.map +1 -1
  30. package/dist/witness/app/app-constants.mjs +2 -0
  31. package/dist/witness/app/app-constants.mjs.map +1 -1
  32. package/dist/witness/app/app-helper.d.mts.map +1 -1
  33. package/dist/witness/app/app-helper.mjs +2 -1
  34. package/dist/witness/app/app-helper.mjs.map +1 -1
  35. package/dist/witness/app/app-types.d.mts +2 -1
  36. package/dist/witness/app/app-types.d.mts.map +1 -1
  37. package/dist/witness/robbot/robbot-base-v1.d.mts +12 -164
  38. package/dist/witness/robbot/robbot-base-v1.d.mts.map +1 -1
  39. package/dist/witness/robbot/robbot-base-v1.mjs +41 -657
  40. package/dist/witness/robbot/robbot-base-v1.mjs.map +1 -1
  41. package/dist/witness/robbot/robbot-helper.mjs +3 -3
  42. package/dist/witness/robbot/robbot-helper.mjs.map +1 -1
  43. package/dist/witness/robbot/robbot-helper.respec.d.mts +2 -0
  44. package/dist/witness/robbot/robbot-helper.respec.d.mts.map +1 -0
  45. package/dist/witness/robbot/robbot-helper.respec.mjs +106 -0
  46. package/dist/witness/robbot/robbot-helper.respec.mjs.map +1 -0
  47. package/dist/witness/robbot/robbot-types.d.mts +6 -3
  48. package/dist/witness/robbot/robbot-types.d.mts.map +1 -1
  49. package/dist/witness/robbot/robbot-types.mjs +1 -0
  50. package/dist/witness/robbot/robbot-types.mjs.map +1 -1
  51. package/dist/witness/space/filesystem-space/filesystem-space-v1.d.mts +1 -1
  52. package/dist/witness/space/filesystem-space/filesystem-space-v1.d.mts.map +1 -1
  53. package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.d.mts +2 -0
  54. package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.d.mts.map +1 -0
  55. package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.mjs +107 -0
  56. package/dist/witness/space/filesystem-space/filesystem-space-v1.respec.mjs.map +1 -0
  57. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.d.mts.map +1 -1
  58. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.mjs +1 -1
  59. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.mjs.map +1 -1
  60. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.d.mts +2 -0
  61. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.d.mts.map +1 -0
  62. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.mjs +129 -0
  63. package/dist/witness/space/filesystem-space/node-filesystem-space-v1.node.respec.mjs.map +1 -0
  64. package/dist/witness/space/inner-space/inner-space-v1.respec.d.mts +2 -0
  65. package/dist/witness/space/inner-space/inner-space-v1.respec.d.mts.map +1 -0
  66. package/dist/witness/space/inner-space/inner-space-v1.respec.mjs +56 -0
  67. package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -0
  68. package/dist/witness/space/metaspace/metaspace-base.d.mts +795 -0
  69. package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -0
  70. package/dist/witness/space/metaspace/metaspace-base.mjs +3251 -0
  71. package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -0
  72. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts +4 -0
  73. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts.map +1 -0
  74. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs +117 -0
  75. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs.map +1 -0
  76. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.d.mts +34 -0
  77. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.d.mts.map +1 -0
  78. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs +76 -0
  79. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs.map +1 -0
  80. package/dist/witness/space/metaspace/metaspace-types.d.mts +580 -0
  81. package/dist/witness/space/metaspace/metaspace-types.d.mts.map +1 -0
  82. package/dist/witness/space/metaspace/metaspace-types.mjs +6 -0
  83. package/dist/witness/space/metaspace/metaspace-types.mjs.map +1 -0
  84. package/dist/witness/space/space-helper.d.mts.map +1 -1
  85. package/dist/witness/space/space-helper.mjs +2 -1
  86. package/dist/witness/space/space-helper.mjs.map +1 -1
  87. package/dist/witness/space/{space-spec-helper.d.mts → space-respec-helper.d.mts} +15 -5
  88. package/dist/witness/space/space-respec-helper.d.mts.map +1 -0
  89. package/dist/witness/space/space-respec-helper.mjs +186 -0
  90. package/dist/witness/space/space-respec-helper.mjs.map +1 -0
  91. package/dist/witness/space/space-types.d.mts +2 -1
  92. package/dist/witness/space/space-types.d.mts.map +1 -1
  93. package/dist/witness/space/space-types.mjs.map +1 -1
  94. package/dist/witness/witness-base-v1.d.mts.map +1 -1
  95. package/dist/witness/witness-base-v1.mjs +7 -7
  96. package/dist/witness/witness-base-v1.mjs.map +1 -1
  97. package/dist/witness/witness-cmd/witness-cmd-types.d.mts +31 -0
  98. package/dist/witness/witness-cmd/witness-cmd-types.d.mts.map +1 -0
  99. package/dist/witness/witness-cmd/witness-cmd-types.mjs +2 -0
  100. package/dist/witness/witness-cmd/witness-cmd-types.mjs.map +1 -0
  101. package/dist/witness/witness-helper.d.mts +8 -0
  102. package/dist/witness/witness-helper.d.mts.map +1 -1
  103. package/dist/witness/witness-helper.mjs +30 -0
  104. package/dist/witness/witness-helper.mjs.map +1 -1
  105. package/dist/witness/witness-types.d.mts +26 -36
  106. package/dist/witness/witness-types.d.mts.map +1 -1
  107. package/dist/witness/witness-with-context/witness-with-context-base-v1.d.mts +235 -0
  108. package/dist/witness/witness-with-context/witness-with-context-base-v1.d.mts.map +1 -0
  109. package/dist/witness/witness-with-context/witness-with-context-base-v1.mjs +742 -0
  110. package/dist/witness/witness-with-context/witness-with-context-base-v1.mjs.map +1 -0
  111. package/dist/witness/witness-with-context/witness-with-context-types.d.mts +17 -0
  112. package/dist/witness/witness-with-context/witness-with-context-types.d.mts.map +1 -0
  113. package/dist/witness/witness-with-context/witness-with-context-types.mjs +2 -0
  114. package/dist/witness/witness-with-context/witness-with-context-types.mjs.map +1 -0
  115. package/package.json +12 -15
  116. package/src/{assumptions.spec.mts → assumptions.respec.mts} +11 -5
  117. package/src/core-constants.mts +0 -2
  118. package/src/core-helper.respec.mts +71 -0
  119. package/src/core-types.mts +20 -0
  120. package/src/respec-gib.node.mts +199 -0
  121. package/src/witness/app/app-base-v1.mts +19 -212
  122. package/src/witness/app/app-constants.mts +3 -0
  123. package/src/witness/app/app-helper.mts +2 -1
  124. package/src/witness/app/app-types.mts +1 -1
  125. package/src/witness/robbot/robbot-base-v1.mts +39 -690
  126. package/src/witness/robbot/robbot-helper.mts +1 -1
  127. package/src/witness/robbot/{robbot-helper.spec.mts → robbot-helper.respec.mts} +39 -33
  128. package/src/witness/robbot/robbot-types.mts +5 -3
  129. package/src/witness/space/filesystem-space/filesystem-space-v1.mts +1 -1
  130. package/src/witness/space/filesystem-space/{filesystem-space-v1.spec.mts → filesystem-space-v1.respec.mts} +17 -8
  131. package/src/witness/space/filesystem-space/node-filesystem-space-v1.mts +3 -11
  132. package/src/witness/space/filesystem-space/{node-filesystem-space-v1.node.spec.mts → node-filesystem-space-v1.node.respec.mts} +18 -14
  133. package/src/witness/space/inner-space/{inner-space-v1.spec.mts → inner-space-v1.respec.mts} +17 -8
  134. package/src/witness/space/metaspace/metaspace-base.mts +3702 -0
  135. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mts +116 -0
  136. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mts +88 -0
  137. package/src/witness/space/metaspace/metaspace-types.mts +614 -0
  138. package/src/witness/space/space-helper.mts +2 -1
  139. package/src/witness/space/{space-spec-helper.mts → space-respec-helper.mts} +76 -57
  140. package/src/witness/space/space-types.mts +2 -1
  141. package/src/witness/witness-base-v1.mts +8 -6
  142. package/src/witness/witness-cmd/witness-cmd-types.mts +38 -0
  143. package/src/witness/witness-helper.mts +31 -0
  144. package/src/witness/witness-types.mts +31 -41
  145. package/src/witness/witness-with-context/witness-with-context-base-v1.mts +809 -0
  146. package/src/witness/witness-with-context/witness-with-context-types.mts +24 -0
  147. package/tsconfig.json +1 -0
  148. package/dist/witness/space/space-spec-helper.d.mts.map +0 -1
  149. package/dist/witness/space/space-spec-helper.mjs +0 -179
  150. package/dist/witness/space/space-spec-helper.mjs.map +0 -1
  151. package/jasmine-browser.json +0 -18
  152. package/jasmine.json +0 -6
  153. package/src/core-helper.spec.mts +0 -64
  154. /package/src/{spec-helper.node.spec.mts → spec-helper.node.respec.mts} +0 -0
@@ -20,6 +20,8 @@ import {
20
20
  DEFAULT_ROBBOT_LEX_DATA,
21
21
  DEFAULT_HUMAN_LEX_DATA,
22
22
  SemanticHandlerResult,
23
+ ROBBOT_INTERACTION_ATOM,
24
+ ROBBOT_ATOM,
23
25
  } from './robbot-types.mjs';
24
26
  import { WitnessBase_V1, } from '../witness-base-v1.mjs';
25
27
  import { CommentIbGib_V1 } from '../../common/comment/comment-types.mjs';
@@ -35,9 +37,17 @@ import { createCommentIbGib, parseCommentIb } from '../../common/comment/comment
35
37
  import { getFromSpace, getLatestAddrs } from '../space/space-helper.mjs';
36
38
  import { getTjpAddr } from '../../common/other/ibgib-helper.mjs';
37
39
  import { IbGibTimelineUpdateInfo } from '../../common/other/other-types.mjs';
40
+ import { WitnessWithContextBase_V1 } from '../witness-with-context/witness-with-context-base-v1.mjs';
41
+ import { WitnessArgIbGib } from '../witness-types.mjs';
38
42
 
39
43
  const logalot = GLOBAL_LOG_A_LOT || true;
40
44
 
45
+ export interface RobbotBaseParseMetadataResult {
46
+ robbotClassnameIsh?: string;
47
+ robbotNameIsh?: string;
48
+ robbotIdIsh?: string;
49
+ }
50
+
41
51
  /**
42
52
  * ## distinguishing characteristics of robbots
43
53
  *
@@ -98,7 +108,7 @@ export abstract class RobbotBase_V1<
98
108
  TData extends RobbotData_V1 = RobbotData_V1,
99
109
  TRel8ns extends RobbotRel8ns_V1 = RobbotRel8ns_V1,
100
110
  >
101
- extends WitnessBase_V1<
111
+ extends WitnessWithContextBase_V1<
102
112
  TOptionsData, TOptionsRel8ns, TOptionsIbGib,
103
113
  TResultData, TResultRel8ns, TResultIbGib,
104
114
  TData, TRel8ns>
@@ -111,34 +121,27 @@ export abstract class RobbotBase_V1<
111
121
  */
112
122
  protected lc: string = `[${RobbotBase_V1.name}]`;
113
123
 
114
- /**
115
- * Reference to the local ibgibs service, which is one way at getting at the
116
- * local user space.
117
- */
118
- public ibgibsSvc: IbGibLocalSpaceService_AllPowerful | undefined;
119
-
120
124
  /**
121
125
  * When the robbot has to get some ibgibs, might as well store them here so
122
126
  * we don't have to get them again from storage.
123
127
  */
124
128
  protected _cacheIbGibs: { [addr: string]: IbGib_V1 } = {};
125
129
 
130
+ protected _semanticHandlers: { [semanticId: string]: SemanticHandler[] } = {};
126
131
 
127
- protected _contextChangesSubscription: Subscription | undefined;
128
- protected _currentWorkingContextIbGib: IbGib_V1 | undefined;
129
132
  /**
130
- * when we get an update to the context, we want to know what the _new_
131
- * children are in order to interpret comments from the user that may be
132
- * directed at us.
133
- *
134
- * So we will get an initial snapshot of children that we will diff against.
135
- * We could go via the dna, but ultimately a diff is what is needed.
133
+ * lex that the robbot uses to speak.
136
134
  */
137
- protected _currentWorkingContextIbGib_PriorChildrenAddrs: IbGibAddr[] = [];
138
-
139
- protected _updatingContext: boolean = false;
135
+ protected _robbotLex: Lex<TLexPropsData> | undefined;
136
+ /**
137
+ * lex that the robbot uses to interpret humans.
138
+ */
139
+ protected _userLex: Lex<TLexPropsData> | undefined;
140
140
 
141
- protected _semanticHandlers: { [semanticId: string]: SemanticHandler[] } = {};
141
+ constructor(initialData?: TData, initialRel8ns?: TRel8ns) {
142
+ super(initialData, initialRel8ns);
143
+ this.initialized = this.initialize();
144
+ }
142
145
 
143
146
  protected async handleSemanticDefault(info: SemanticInfo): Promise<SemanticHandlerResult> {
144
147
  const lc = `${this.lc}[${this.handleSemanticDefault.name}]`;
@@ -166,42 +169,6 @@ export abstract class RobbotBase_V1<
166
169
  }
167
170
  }
168
171
 
169
- /**
170
- * lex that the robbot uses to speak.
171
- */
172
- protected _robbotLex: Lex<TLexPropsData> | undefined;
173
- /**
174
- * lex that the robbot uses to interpret humans.
175
- */
176
- protected _userLex: Lex<TLexPropsData> | undefined;
177
-
178
- /**
179
- * This should be awaited before dealing with the robbot.
180
- *
181
- * I'm keeping this named `ready` as a shout out to
182
- * https://stackoverflow.com/a/45070748/3897838
183
- * (https://stackoverflow.com/questions/35743426/async-constructor-functions-in-typescript).
184
- *
185
- * ## comments
186
- *
187
- * I've been considering going forward whether or not to have robbots'
188
- * properties all be observables to allow for subscribing to events or
189
- * similar in the future. But this may fight against the single `witness`
190
- * point of contact, which of course itself is somewhat experimental. One
191
- * grand experiment.
192
- *
193
- * I do have an observable as a property for the aws sync space saga
194
- * updates. This kind of observable can be passed around while still using
195
- * the single `witness` access point, but of course these runtime aspects
196
- * won't be memoized if storing the ibgib.
197
- */
198
- public initialized: Promise<void>;
199
-
200
- constructor(initialData?: TData, initialRel8ns?: TRel8ns) {
201
- super(initialData, initialRel8ns);
202
- this.initialized = this.initialize();
203
- }
204
-
205
172
  // #region initialize
206
173
 
207
174
  /**
@@ -211,6 +178,7 @@ export abstract class RobbotBase_V1<
211
178
  const lc = `${this.lc}[${this.initialize.name}]`;
212
179
  try {
213
180
  if (logalot) { console.log(`${lc} starting... (I: f0e65ab0f80046a59668ddfbf9f47a4a5)`); }
181
+ await super.initialize();
214
182
 
215
183
  await this.initialize_semanticHandlers();
216
184
  await this.initialize_lex();
@@ -287,35 +255,6 @@ export abstract class RobbotBase_V1<
287
255
 
288
256
  // #endregion initialize
289
257
 
290
- protected async loadNewerSelfIfAvailable(): Promise<void> {
291
- const lc = `${this.lc}[${this.loadNewerSelfIfAvailable.name}]`;
292
- try {
293
- if (logalot) { console.log(`${lc} starting... (I: 94755c3131f4dfa12d20fa38e2926522)`); }
294
- if (this.ibgibsSvc) {
295
- // check for newer version of self locally before executing
296
- const robbotAddr = getIbGibAddr({ ibGib: this });
297
- const latestAddr = await this.ibgibsSvc.getLatestAddr({ ibGib: this });
298
- if (latestAddr && latestAddr !== robbotAddr) {
299
- // robbot has a newer ibgib in its timeline
300
- let resGet = await this.ibgibsSvc.get({ addr: latestAddr });
301
- if (!resGet || !resGet?.success || (resGet?.ibGibs ?? []).length === 0) {
302
- throw new Error(`could not get newer robbot ibgib (E: 15fa346c8ac17edb96e4b0870104c122)`);
303
- }
304
- await this.loadIbGibDto(resGet.ibGibs![0] as IbGib_V1<TData, TRel8ns>);
305
- const validationErrors = await this.validateThis();
306
- if (validationErrors?.length > 0) { throw new Error(`validationErrors when loading newer version: ${pretty(validationErrors)} (E: 0d9f0684a1ff6af44e20a57130e3ac22)`); }
307
- }
308
- } else {
309
- console.warn(`${lc} this.ibgibsSvc undefined (W: 44cc5bf1b14b4695b8de4c589787be06)`);
310
- }
311
-
312
- } catch (error) {
313
- console.error(`${lc} ${error.message}`);
314
- throw error;
315
- } finally {
316
- if (logalot) { console.log(`${lc} complete.`); }
317
- }
318
- }
319
258
  /**
320
259
  * At this point in time, the arg has already been intrinsically validated,
321
260
  * as well as the internal state of this robbot. so whatever this robbot's
@@ -331,7 +270,10 @@ export abstract class RobbotBase_V1<
331
270
 
332
271
  await this.loadNewerSelfIfAvailable();
333
272
 
334
- return this.routeAndDoArg({ arg });
273
+ let result = await this.routeAndDoArg({ arg });
274
+ if (!result) { result = await this.doDefault({ ibGib: arg }); }
275
+ if (!result) { console.warn(`${lc} result falsy...Could not produce result? Was doDefault implemented in concrete class? (W: 67f5fc5e6e864a13b0053fb54cfba100)`); }
276
+ return result;
335
277
  } catch (error) {
336
278
  console.error(`${lc} ${error.message}`);
337
279
  throw error;
@@ -483,7 +425,10 @@ export abstract class RobbotBase_V1<
483
425
  if (!arg) { throw new Error(`arg required (E: 9cddabc6dc96ddb37846807feb093423)`); }
484
426
 
485
427
  if (arg.ibGibs?.length ?? 0 > 0) {
486
- await this.initializeContext({ arg });
428
+ await this.initializeContext({
429
+ arg: arg as WitnessArgIbGib<IbGib_V1, TData, TRel8ns>,
430
+ rel8nName: ROBBOT_CONTEXT_REL8N_NAME,
431
+ });
487
432
  }
488
433
 
489
434
  const result = await this.resulty({
@@ -510,7 +455,9 @@ export abstract class RobbotBase_V1<
510
455
  if (logalot) { console.log(`${lc} starting... (I: d453593a295d4cdbae2acb71d9f6de35)`); }
511
456
  await this.initialized;
512
457
 
513
- await this.finalizeContext({ arg });
458
+ await this.finalizeContext({
459
+ arg: arg as WitnessArgIbGib<IbGib_V1, TData, TRel8ns>,
460
+ });
514
461
 
515
462
  const result = await this.resulty({
516
463
  resultData: {
@@ -595,148 +542,6 @@ export abstract class RobbotBase_V1<
595
542
 
596
543
  // #endregion other stubbed do functions (doPic, doComment, doDefault)
597
544
 
598
- /**
599
- * By default, this...
600
- *
601
- * * performs the raw {@link rel8} transform to the given `ibGib`.
602
- * * persists the new ibgib's transform result in the given space.
603
- * * registers the newer version of this robbot ibgib with the ibgibs svc.
604
- *
605
- * @see {@link ibGibs}
606
- * @see {@link rel8nName}
607
- * @see {@link ibgibsSvc}
608
- * @see {@link space}
609
- *
610
- * ## notes
611
- *
612
- * * If there is no given `space`, then we will use the `ibgibsSvc` to get
613
- * the local user space. If none, then we skip persistence.
614
- * * If there is no `ibgibsSvc`, we won't register the new ibgibs locally.
615
- */
616
- protected async rel8To({
617
- ibGibs,
618
- rel8nName,
619
- linked,
620
- ibgibsSvc,
621
- // space,
622
- }: {
623
- /**
624
- * The ibgib to which we are relating.
625
- */
626
- ibGibs: IbGib_V1[],
627
- /**
628
- * If given, will use this as the rel8n name when performing the `rel8`
629
- * transform.
630
- *
631
- * If not given, will use the `robbot.data`'s {@link RobbotData_V1.defaultRel8nName} value.
632
- */
633
- rel8nName?: string,
634
- /**
635
- * If true, will include the `rel8nName` as a linked rel8n in the `rel8`
636
- * transform.
637
- */
638
- linked?: boolean,
639
- /**
640
- * If provided, will register the newly created ibgib.
641
- */
642
- ibgibsSvc?: IbGibLocalSpaceService_AllPowerful,
643
- // /**
644
- // * If given (which atow is most likely the case), then the {@link TransformResult} will
645
- // * be persisted in this `space`.
646
- // */
647
- // space?: IbGibSpaceAny,
648
- }): Promise<void> {
649
- const lc = `${this.lc}[${this.rel8To.name}]`;
650
- try {
651
- if (logalot) { console.log(`${lc} starting...`); }
652
-
653
- // #region initialize, validate args and this
654
-
655
- if ((ibGibs ?? []).length === 0) { throw new Error(`ibGibs required (E: 2fd13de0f025b170885bede4d7a50922)`); }
656
-
657
- rel8nName = rel8nName || this.data?.defaultRel8nName;
658
- if (!rel8nName) { throw new Error(`rel8nName required either as an arg or in this.data.defaultRel8nName (E: 43ab8ae63694a2a82cd8a70ed6b6b522)`); }
659
-
660
- const thisValidationErrors = await this.validateThis();
661
- if (thisValidationErrors?.length > 0) { throw new Error(`this is an invalid ibGib. thisValidationErrors: ${thisValidationErrors.join('|')} (E: 8f08716866cd13bf254222ee9e6a6722)`); }
662
-
663
- ibgibsSvc = ibgibsSvc ?? this.ibgibsSvc;
664
-
665
- if (!ibgibsSvc) {
666
- // if (this.ibgibsSvc) {
667
- // if (logalot) { console.log(`${lc} ibgibsSvc arg falsy, but we have a reference on this object, which we will use. (I: ee0d39a47ee8aee8ffd797721fea4322)`); }
668
- // ibgibsSvc = this.ibgibsSvc;
669
- // }
670
- throw new Error(`either ibgibsSvc or this.ibgibsSvc required (E: b5f9453ddb394a2b76dec74c7304df22)`);
671
- }
672
-
673
- // if (!space) {
674
- // if (ibgibsSvc) {
675
- // if (logalot) { console.log(`${lc} space arg falsy, but ibgibsSvc truthy, so we'll use ibgibsSvc's local user space for persistence. (I: 37a4b4c1406556cb23831671755b0d22)`); }
676
- // space = await ibgibsSvc.getLocalUserSpace({ lock: true });
677
- // }
678
- // }
679
-
680
- // if (!space) { throw new Error(`(UNEXPECTED) space required and ibgibsSvc couldn't get it? (E: a3b9f9b72f6f6f18883199a19d38c622)`); }
681
-
682
- // #endregion initialize, validate args and this
683
-
684
- // we want to rel8 only to the ibGibs whose timelines we're not
685
- // already related to. So we look to see if we already have the tjpGib
686
- // per our rel8nName.
687
- // if (!this.rel8ns) { this.rel8ns = {} as any };
688
- const alreadyRel8dAddrs = this.rel8ns ? this.rel8ns[rel8nName] ?? [] : [];
689
- const alreadyRel8dTjpGibs = alreadyRel8dAddrs.map(x => getGibInfo({ ibGibAddr: x }).tjpGib);
690
- const ibGibsNotYetRel8dByTjp = ibGibs.filter(x => {
691
- const tjpGib = getGibInfo({ ibGibAddr: getIbGibAddr({ ibGib: x }) }).tjpGib;
692
- return !alreadyRel8dTjpGibs.includes(tjpGib);
693
- });
694
-
695
- if (ibGibsNotYetRel8dByTjp.length === 0) {
696
- if (logalot) { console.log(`${lc} already rel8d to all incoming ibGib(s) via tjp. (I: 5e9d94a98ba262f146c0c0b765157922)`); }
697
- return; /* <<<< returns early */
698
- }
699
-
700
- // perform the raw ibgib rel8 transform
701
- const addrs = ibGibsNotYetRel8dByTjp.map(x => getIbGibAddr({ ibGib: x }));
702
- const resNewRobbot = await V1.rel8({
703
- src: this.toIbGibDto(),
704
- rel8nsToAddByAddr: { [rel8nName]: addrs },
705
- linkedRel8ns: linked ? ["past", "ancestor", rel8nName] : ["past", "ancestor"],
706
- dna: true,
707
- nCounter: true,
708
- });
709
- const newRobbotIbGib = resNewRobbot.newIbGib as any as IbGib_V1<TData, TRel8ns>;
710
- const newRobbotValidationErrors =
711
- await validateIbGibIntrinsically({ ibGib: newRobbotIbGib as any });
712
- if (newRobbotValidationErrors?.length ?? 0 > 0) { throw new Error(`new robbot would have validation errors. aborting. newRobbotValidationErrors: ${newRobbotValidationErrors!.join('|')} (E: eb816a27156c246c121ef55e37d59322)`); }
713
-
714
- // if space is given, perform the persistence
715
- // if (space) {
716
- await ibgibsSvc.persistTransformResult({ resTransform: resNewRobbot });
717
- // } else {
718
- // if (logalot) { console.log(`${lc} space falsy, skipping persistence (I: 90aa3553e92ad1d02bce61f83648ea22)`); }
719
- // }
720
-
721
- // if ibgibs svc is given, register the new ibgib
722
- // (in the future, need to revisit the ibgibs service to the idea of locality/ies).
723
- // if (ibgibsSvc) {
724
- await ibgibsSvc.registerNewIbGib({ ibGib: newRobbotIbGib });
725
- // } else {
726
- // if (logalot) { console.log(`${lc} ibgibsSvc falsy so skipping registerNewIbGib for new robbot (I: eda4f68fffaf2435eba25cd39d4f2922)`); }
727
- // }
728
-
729
- // update this witness' primary ibGib properties (ib, gib, data, rel8ns).
730
- // override `loadIbGibDto` to update secondary/derivative properties
731
- await this.loadIbGibDto(newRobbotIbGib);
732
- } catch (error) {
733
- console.error(`${lc} ${error.message}`);
734
- throw error;
735
- } finally {
736
- if (logalot) { console.log(`${lc} complete.`); }
737
- }
738
- }
739
-
740
545
  /**
741
546
  * validates against common robbot qualities.
742
547
  *
@@ -823,131 +628,11 @@ export abstract class RobbotBase_V1<
823
628
  return result;
824
629
  }
825
630
 
826
- protected async rel8ToContextIbGib({
827
- ibGibToRel8,
828
- ibGibAddrToRel8,
829
- contextIbGib,
830
- rel8nNames,
831
- // space,
832
- }: {
833
- ibGibToRel8?: IbGib_V1,
834
- ibGibAddrToRel8?: IbGibAddr,
835
- contextIbGib: IbGib_V1,
836
- rel8nNames: string[],
837
- // space?: IbGibSpaceAny,
838
- }): Promise<void> {
839
- const lc = `${this.lc}[${this.rel8ToContextIbGib.name}]`;
840
- try {
841
- if (!ibGibToRel8 && !ibGibAddrToRel8) { throw new Error(`ibGibToRel8 or ibGibAddrToRel8 required (E: 3ee14659fd22355a5ba0e537a477be22)`); }
842
- if (!contextIbGib) { throw new Error(`contextIbGib required (E: 85f27c7cbf713704c21084c141cd8822)`); }
843
- if (!this.ibgibsSvc) { throw new Error(`this.ibgibsSvc required (E: 6a38c4274bdefc8d44cafd2d6faaa222)`); }
844
-
845
- // space = space ?? await this.ibgibsSvc.getLocalUserSpace({ lock: true });
846
- // if (!space) { throw new Error(`space required (E: 267ad87c148942cda641349df0bbbd22)`); }
847
-
848
- if ((rel8nNames ?? []).length === 0) {
849
- if (!this.data?.defaultRel8nName) { throw new Error(`either rel8nNames or this.data.defaultRel8nName required (E: a14ab4b3e479d9274c61bc5a30bc2222)`); }
850
- rel8nNames = [this.data.defaultRel8nName];
851
- }
852
-
853
- // set up the rel8ns to add
854
- const rel8nsToAddByAddr: IbGibRel8ns_V1 = {};
855
- ibGibAddrToRel8 = ibGibAddrToRel8 || getIbGibAddr({ ibGib: ibGibToRel8 });
856
- rel8nNames.forEach((rel8nName) => { rel8nsToAddByAddr[rel8nName] = [ibGibAddrToRel8!]; });
857
-
858
- // perform the rel8 transform and...
859
- const resRel8ToContext =
860
- await V1.rel8({
861
- src: contextIbGib,
862
- rel8nsToAddByAddr,
863
- dna: true,
864
- nCounter: true
865
- });
866
-
867
- // ...persist it...
868
- await this.ibgibsSvc.persistTransformResult({ resTransform: resRel8ToContext });
869
-
870
- // ...register the context.
871
- const { newIbGib: newContext } = resRel8ToContext;
872
- await this.ibgibsSvc.registerNewIbGib({ ibGib: newContext });
873
- } catch (error) {
874
- console.error(`${lc} ${error.message}`);
875
- throw error;
876
- }
877
- }
878
-
879
- protected async createCommentAndRel8ToContextIbGib({
880
- text,
881
- contextIbGib,
882
- }: {
883
- text: string,
884
- contextIbGib: IbGib_V1,
885
- ibgibsSvc?: IbGibLocalSpaceService_AllPowerful,
886
- }): Promise<void> {
887
- const lc = `${this.lc}[${this.createCommentAndRel8ToContextIbGib.name}]`;
888
- try {
889
- if (logalot) { console.log(`${lc} starting... (I: c3a005f7d323468a5b4e1b2710901d22)`); }
890
-
891
- if (!this.ibgibsSvc) { throw new Error(`this.ibgibsSvc required (E: 5dbb1a7f0ff5469b8ce3cb1be175e521)`); }
892
-
893
- // space = space ?? await this.ibgibsSvc.getLocalUserSpace({ lock: true });
894
- // if (!space) { throw new Error(`(UNEXPECTED) space required and wasn't able to get it from ibgibsSvc? (E: 7159f9893a66c28a7e09b61384545622)`); }
895
- let space = await this.ibgibsSvc.getLocalUserSpace({ lock: true });
896
-
897
- /** tag this comment with metadata to show it came from this robbot */
898
- let resComment = await createCommentIbGib({ text, addlMetadataText: this.getAddlMetadata(), saveInSpace: true, space });
899
-
900
- // get again to be sure it's the latest space.
901
- space = await this.ibgibsSvc.getLocalUserSpace({ lock: true });
902
-
903
- const commentIbGib = resComment.newIbGib as CommentIbGib_V1;
904
- if (!commentIbGib) { throw new Error(`(UNEXPECTED) failed to create comment? (E: 6d668f4e55198e654324622eabaac922)`); }
905
- await this.ibgibsSvc.registerNewIbGib({ ibGib: commentIbGib });
906
-
907
- await this.rel8ToContextIbGib({ ibGibToRel8: commentIbGib, contextIbGib, rel8nNames: ['comment'] });
908
- await this.rel8To({
909
- ibGibs: [commentIbGib],
910
- rel8nName: ROBBOT_MY_COMMENTS_REL8N_NAME,
911
- });
912
- } catch (error) {
913
- console.error(`${lc} ${error.message}`);
914
- throw error;
915
- } finally {
916
- if (logalot) { console.log(`${lc} complete.`); }
917
- }
631
+ protected getThisAtom(): string {
632
+ return ROBBOT_ATOM; // "robbot" atow
918
633
  }
919
634
 
920
- /**
921
- * used to identify when comments are made by these robbots.
922
- *
923
- * atow this is `robbot_${this.data.classname}_${this.data.name}_${this.data.uuid.slice(0, 8)}`;
924
- *
925
- * @returns addlmetadata string to be used in comment ib's
926
- */
927
- protected getAddlMetadata(): string {
928
- const lc = `${this.lc}[${this.getAddlMetadata.name}]`;
929
- try {
930
- if (logalot) { console.log(`${lc} starting... (I: 7800732facf3783943fdf1b2423b0c22)`); }
931
- if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: 7cb044b39b2b8e31f363f3b82f256323)`); }
932
- const classnameIsh = this.data.classname?.replace(/[_]/mg, '') || undefined;
933
- const robbotNameIsh = this.data.name?.slice(0, 8).replace(/[__]/mg, '') || undefined;
934
- const robbotIdIsh = this.data.uuid?.slice(0, 8) || undefined;
935
- const addlMetadataText = `robbot_${classnameIsh}_${robbotNameIsh}_${robbotIdIsh}`;
936
- if (logalot) { console.log(`${lc} addlMetadataText: ${addlMetadataText} (I: 53c0044671dc99fb75635367d2e63c22)`); }
937
- return addlMetadataText;
938
- } catch (error) {
939
- console.error(`${lc} ${error.message}`);
940
- throw error;
941
- } finally {
942
- if (logalot) { console.log(`${lc} complete.`); }
943
- }
944
- }
945
-
946
- protected parseAddlMetadataString({ ib }: { ib: Ib }): {
947
- robbotClassnameIsh?: string;
948
- robbotNameIsh?: string;
949
- robbotIdIsh?: string;
950
- } {
635
+ protected parseAddlMetadataString<RobbotBaseParseMetadataResult>({ ib }: { ib: Ib }): RobbotBaseParseMetadataResult {
951
636
  const lc = `${this.lc}[${this.parseAddlMetadataString.name}]`;
952
637
  try {
953
638
  if (logalot) { console.log(`${lc} starting... (I: d0cf162bc5f4cbf65bf1f7e29e3bd922)`); }
@@ -955,9 +640,9 @@ export abstract class RobbotBase_V1<
955
640
 
956
641
  if (safeIbCommentMetadataText) {
957
642
  const [_, robbotClassnameIsh, robbotNameIsh, robbotIdIsh] = safeIbCommentMetadataText.split('__');
958
- return { robbotClassnameIsh, robbotNameIsh, robbotIdIsh };
643
+ return { robbotClassnameIsh, robbotNameIsh, robbotIdIsh } as RobbotBaseParseMetadataResult;
959
644
  } else {
960
- return { robbotClassnameIsh: undefined, robbotNameIsh: undefined, robbotIdIsh: undefined };
645
+ return { robbotClassnameIsh: undefined, robbotNameIsh: undefined, robbotIdIsh: undefined } as RobbotBaseParseMetadataResult;
961
646
  }
962
647
  } catch (error) {
963
648
  console.error(`${lc} ${error.message}`);
@@ -1103,342 +788,6 @@ export abstract class RobbotBase_V1<
1103
788
 
1104
789
  }
1105
790
 
1106
- /**
1107
- * I originally created this just to extract the context from the arg, but
1108
- * I'm reusing it to get the latest context from the addr alone.
1109
- */
1110
- protected async getContextIbGibFromArgOrAddr({
1111
- arg,
1112
- addr,
1113
- latest,
1114
- }: {
1115
- arg?: RobbotCmdIbGib<IbGib_V1, RobbotCmdData, RobbotCmdRel8ns>,
1116
- addr?: IbGibAddr,
1117
- /**
1118
- * if true, after extracting the context from the arg, will get the
1119
- * latest ibgib (if there is a newer version).
1120
- */
1121
- latest?: boolean,
1122
- }): Promise<IbGib_V1> {
1123
- const lc = `${this.lc}[${this.getContextIbGibFromArgOrAddr.name}]`;
1124
- try {
1125
- if (logalot) { console.log(`${lc} starting... (I: c13f7cb92133984048f606075efb8a22)`); }
1126
- let contextIbGib: IbGib_V1;
1127
- if (!arg && !addr) { throw new Error(`either arg or addr required. (E: 3f647b65742242fd9ba878521acf7c22)`); }
1128
- if (!this.ibgibsSvc) { throw new Error(`(UNEXPECTED) this.ibgibsSvc required (E: f0046290b0d66d28c4bbbf83d9d9f523)`); }
1129
- if (arg) {
1130
- if ((arg.ibGibs ?? []).length === 0) { throw new Error(`(UNEXPECTED) invalid arg? no context ibgib on arg (E: 89997eb4bdeb3885bee9de5d33ee0f22)`); }
1131
- if ((arg.ibGibs ?? []).length !== 1) { throw new Error(`(UNEXPECTED) invalid arg? only expected one ibgib on arg.ibGibs (E: 1a1498af668740fe9439f4953a74ea8a)`); }
1132
- contextIbGib = arg.ibGibs![0];
1133
- } else {
1134
- // addr provided
1135
- const resGet = await this.ibgibsSvc.get({ addr });
1136
- if (!resGet.success || resGet.ibGibs?.length !== 1) { throw new Error(`could not get context addr (${addr}) (E: 834492313512a45b23a7bebacdc48122)`); }
1137
- contextIbGib = resGet.ibGibs[0];
1138
- }
1139
-
1140
- if (latest) {
1141
- const resLatestAddr = await this.ibgibsSvc.getLatestAddr({ ibGib: contextIbGib });
1142
- if (resLatestAddr !== getIbGibAddr({ ibGib: contextIbGib })) {
1143
- const resGet = await this.ibgibsSvc.get({ addr: resLatestAddr });
1144
- if (resGet.success && resGet.ibGibs?.length === 1) {
1145
- contextIbGib = resGet.ibGibs[0];
1146
- } else {
1147
- throw new Error(`unable to get resLatestAddr (${resLatestAddr}) (E: ce1e1297743e9a16c8f082321e52a122)`);
1148
- }
1149
- }
1150
- }
1151
- return contextIbGib;
1152
- } catch (error) {
1153
- console.error(`${lc} ${error.message}`);
1154
- throw error;
1155
- } finally {
1156
- if (logalot) { console.log(`${lc} complete.`); }
1157
- }
1158
- }
1159
-
1160
- /**
1161
- * The context is the ibgib where we are interacting with the user(s) (only
1162
- * singlular atow).
1163
- *
1164
- * When we initialize, we are setting state on this robbot as well as subscribing
1165
- * to the context ibgib's updates in `this.ibgibsSvc`.
1166
- *
1167
- * if we already have a context, then this will check the new incoming
1168
- * context against it. If it's the same timeline, then this won't do
1169
- * anything. Otherwise, it will finalize the previous context.
1170
- */
1171
- protected async initializeContext({
1172
- arg,
1173
- }: {
1174
- arg: RobbotCmdIbGib<IbGib_V1, RobbotCmdData, RobbotCmdRel8ns>,
1175
- }): Promise<void> {
1176
- const lc = `${this.lc}[${this.initializeContext.name}]`;
1177
- try {
1178
- if (logalot) { console.log(`${lc} starting... (I: d93429c85b0a494388f66fba3eece922)`); }
1179
-
1180
- // get context from arg just to compare the tjp's so we don't need
1181
- // the latest at this point
1182
- const incomingContext_NotLatest = await this.getContextIbGibFromArgOrAddr({ arg, latest: false });
1183
- if (this._currentWorkingContextIbGib) {
1184
- let currentTjpAddr = getTjpAddr({ ibGib: this._currentWorkingContextIbGib });
1185
- const incomingTjpAddr = getTjpAddr({ ibGib: incomingContext_NotLatest })
1186
- if (currentTjpAddr === incomingTjpAddr) {
1187
- console.warn(`${lc} initializing context but it's the same timeline (${currentTjpAddr}). (W: 7609f8f51172443183e0c93ad52bfe56)`);
1188
- return;
1189
- } else {
1190
- await this.finalizeContext({ arg });
1191
- }
1192
- }
1193
-
1194
- /** used both now and when context ibgib is updated via observable */
1195
- const updatePriorChildren = () => {
1196
- this._currentWorkingContextIbGib_PriorChildrenAddrs = [
1197
- ...this._currentWorkingContextIbGib?.rel8ns?.comment ?? [],
1198
- ...this._currentWorkingContextIbGib?.rel8ns?.pic ?? [],
1199
- ...this._currentWorkingContextIbGib?.rel8ns?.link ?? [],
1200
- ];
1201
- };
1202
-
1203
- // set the props
1204
- this._currentWorkingContextIbGib = await this.getContextIbGibFromArgOrAddr({ arg, latest: true });
1205
- updatePriorChildren();
1206
-
1207
- // subscribe to context ibgib updates
1208
- const contextTjpAddr = getTjpAddr({ ibGib: this._currentWorkingContextIbGib });
1209
- if (!this.ibgibsSvc) { throw new Error(`this.ibgibsSvc falsy...not initialized? (E: 6e38bfdc5c2eb5fef884f0183889e823)`); }
1210
- this._contextChangesSubscription =
1211
- this.ibgibsSvc.latestObs.pipe(filter(x => x.tjpAddr === contextTjpAddr)).subscribe(async (update: any) => {
1212
- const currentAddr = getIbGibAddr({ ibGib: this._currentWorkingContextIbGib });
1213
- if (update.latestAddr !== currentAddr) {
1214
- if (logalot) { console.warn(`${lc} checking if new context is actually new...damn getLatestAddr maybe not working in ionic space... argh (W: 3d1a12154dfafb9c96d07e6f75f7a322)`); }
1215
- if (update.latestIbGib) {
1216
- let latestN_Supposedly = update.latestIbGib.data?.n ?? -1;
1217
- let currentN = this._currentWorkingContextIbGib?.data?.n ?? -2;
1218
- if (latestN_Supposedly <= currentN) {
1219
- console.warn(`${lc} latestN is not really the latest. latestN_Supposedly: ${latestN_Supposedly}, currentN: ${currentN} (W: 6792c9a596c44c03b262614ae79a715e)`)
1220
- return; /* <<<< returns early */
1221
- }
1222
- }
1223
- if (logalot) { console.log(`${lc} update to context.\ncurrentAddr: ${currentAddr}\nlatestAddr: ${update.latestAddr} (I: d0adcc392e6e974c9917730ebad51322)`); }
1224
- this._currentWorkingContextIbGib =
1225
- update.latestIbGib ??
1226
- await this.getContextIbGibFromArgOrAddr({ addr: update.latestAddr, latest: false }); // already latest
1227
- if (!this._updatingContext) {
1228
- await this.handleContextUpdate({ update });
1229
- updatePriorChildren();
1230
- } else {
1231
- if (logalot) { console.log(`${lc} already updating context (I: f856f9414627ab00418dccd285b55822)`); }
1232
- }
1233
- }
1234
- });
1235
-
1236
- // rel8 to the context (conversation)
1237
- await this.rel8To({
1238
- ibGibs: [this._currentWorkingContextIbGib],
1239
- rel8nName: ROBBOT_CONTEXT_REL8N_NAME,
1240
- });
1241
-
1242
- // subscribe to receive updates to the context so we can participate
1243
- // in the conversation (i.e. interpret incoming ibgibs like commands
1244
- // if needed)
1245
- // let gibInfo = getGibInfo({ gib: this._currentWorkingContextIbGib.gib });
1246
- // if (gibInfo.tjpGib) {
1247
- // this.ibgibsSvc.latestObs
1248
- // .subscribe(update => {
1249
- // if (!update.tjpAddr) { return; /* <<<< returns early */ }
1250
- // if (getIbAndGib({ ibGibAddr: update.tjpAddr }).gib !== gibInfo.tjpGib) { return; /* <<<< returns early */ }
1251
- // if (update.latestAddr === getIbGibAddr({ ibGib: this._currentWorkingContextIbGib })) {
1252
- // if (logalot) { console.log(`${lc} already have that context... (I: a6e17ec40d620f0bd5b231db39eaa522)`); }
1253
- // return; /* <<<< returns early */
1254
- // }
1255
- // if (this._updatingContext) {
1256
- // if (logalot) { console.log(`${lc} already updating context (I: f856f9414627ab00418dccd285b55822)`); }
1257
- // return; /* <<<< returns early */
1258
- // }
1259
- // this.handleContextUpdate({ update });
1260
- // });
1261
- // }
1262
- } catch (error) {
1263
- console.error(`${lc} ${error.message}`);
1264
- throw error;
1265
- } finally {
1266
- if (logalot) { console.log(`${lc} complete.`); }
1267
- }
1268
- }
1269
-
1270
- protected async finalizeContext({
1271
- arg,
1272
- }: {
1273
- arg: RobbotCmdIbGib<IbGib_V1, RobbotCmdData, RobbotCmdRel8ns>,
1274
- }): Promise<void> {
1275
- const lc = `${this.lc}[${this.finalizeContext.name}]`;
1276
- try {
1277
- if (logalot) { console.log(`${lc} starting... (I: dd53dfc745864dd19fde5f209ceb82c8)`); }
1278
-
1279
-
1280
- let tries = 0;
1281
- const maxTries = 100;
1282
- while (this._updatingContext && tries < maxTries) {
1283
- await delay(100);
1284
- tries++;
1285
- if (tries % 10 === 0) {
1286
- console.log(`${lc} already updating context and taking a litle while... waiting still. tries: ${tries}/${maxTries} (I: d45ab59af9ea43518432e34ddad95c19)`)
1287
- }
1288
- }
1289
- if (this._updatingContext) {
1290
- console.error(`${lc} previous call to updatingContext took too long. Ignoring flag and finalizing context. (E: 9a2dc4e1923442fa90fbeae72f358acd)`);
1291
- }
1292
-
1293
- this._updatingContext = true;
1294
- if (this._contextChangesSubscription) {
1295
- debugger;
1296
- this._contextChangesSubscription.unsubscribe();
1297
- delete this._contextChangesSubscription;
1298
- }
1299
- delete this._currentWorkingContextIbGib;
1300
-
1301
- if (this._currentWorkingContextIbGib) {
1302
- await this.createCommentAndRel8ToContextIbGib({
1303
- text: await this.getOutputText({ text: 'end of line' }),
1304
- contextIbGib: this._currentWorkingContextIbGib,
1305
- });
1306
- delete this._currentWorkingContextIbGib;
1307
- }
1308
- } catch (error) {
1309
- console.error(`${lc} ${error.message}`);
1310
- throw error;
1311
- } finally {
1312
- this._updatingContext = false;
1313
- if (logalot) { console.log(`${lc} complete.`); }
1314
- }
1315
- }
1316
-
1317
- /**
1318
- * Handles a new ibgib in the current working context.
1319
- *
1320
- * If it originated from the robbot him/herself, then we will ignore it.
1321
- * Otherwise this is interpreted either as a "command" or something to remember.
1322
- *
1323
- * ## notes
1324
- *
1325
- * If the user says something and we're listening (this is triggered), then
1326
- * it should be either interpreted as a "command" or ignored. I put
1327
- * "command" in quotes because the word is a very short-sighted
1328
- * understanding of the conversational aspect. Or perhaps I speak to the
1329
- * connotations to current belief's regarding robbots and commands.
1330
- *
1331
- * This is complicated by the possibility in the future of multiple robbots
1332
- * being engaged in a conversation within the same context.
1333
- */
1334
- private async handleContextUpdate({ update }: { update: IbGibTimelineUpdateInfo }): Promise<void> {
1335
- const lc = `${this.lc}[${this.handleContextUpdate.name}]`;
1336
- // I don't see this as really being very likely in the near future,
1337
- // but putting in a wait delay in case there are multiple updates
1338
- while (this._updatingContext) {
1339
- console.warn(`${lc} already updating context? delaying... (W: 19d2ebeaaf2340fb91a7d6c717e9cb41)`);
1340
- await delay(1000);
1341
- }
1342
- this._updatingContext = true;
1343
- try {
1344
- if (logalot) { console.log(`${lc} starting... (I: 3eeaa40cad49094f125f9f5cd6ff6e22)`); }
1345
-
1346
- // if it's caused by this robbot speaking, then we don't really need
1347
- // it. but if it's from the user, then we want to respond.
1348
- if (logalot) {
1349
- console.log(`${lc} update: (I: ad0abae7de472e3b4d3891ea0b937322)`);
1350
- console.table(update);
1351
- }
1352
- if (!update.latestIbGib) {
1353
- debugger;
1354
- throw new Error(`(UNEXPECTED) update.latestIbGib falsy? (E: e18a048d7e95757238396ddd84748f22)`);
1355
- }
1356
-
1357
- const newContext = update.latestIbGib;
1358
- const newChildrenIbGibs = await this.getNewChildrenIbGibs({ newContext });
1359
- // should normally be just one (would be very edge casey if not atow)
1360
- let newChild: IbGib_V1;
1361
- if (newChildrenIbGibs.length === 1) {
1362
- newChild = newChildrenIbGibs[0];
1363
- } else if (newChildrenIbGibs.length > 1) {
1364
- console.warn(`${lc} (UNEXPECTED) found multiple new children in conversation? Using only the last. (W: 02d82a8f755f418d95fa30f0f52ad58e)`);
1365
- newChild = newChildrenIbGibs[newChildrenIbGibs.length - 1];
1366
- } else {
1367
- // no new children, so maybe the user deleted something or who knows.
1368
- if (logalot) { console.log(`${lc} no new children in context update. returning early... (I: 31397b04965351ab29bb3f78cb709122)`); }
1369
- return; /* <<<< returns early */
1370
- }
1371
-
1372
- // we have a new chidl inthe context.
1373
- await this.handleNewContextChild({ newChild });
1374
-
1375
- } catch (error) {
1376
- console.error(`${lc} ${error.message}`);
1377
- throw error;
1378
- } finally {
1379
- this._updatingContext = false;
1380
- if (logalot) { console.log(`${lc} complete.`); }
1381
- }
1382
- }
1383
-
1384
- async getNewChildrenIbGibs({ newContext }: { newContext: IbGib_V1 }): Promise<IbGib_V1[]> {
1385
- const lc = `${this.lc}[${this.getNewChildrenIbGibs.name}]`;
1386
- try {
1387
- if (logalot) { console.log(`${lc} starting... (I: 1b3d1cf908489087fa3b281f55b9a522)`); }
1388
- // get a diff of the new addrs vs. the old addrs.
1389
- /** all of the children addrs of the new context */
1390
- const newContextChildrenAddrs = [
1391
- ...newContext.rel8ns?.comment ?? [],
1392
- ...newContext.rel8ns?.pic ?? [],
1393
- ...newContext.rel8ns?.link ?? [],
1394
- ];
1395
- /** just the new addrs from the context */
1396
- const newChildrenAddrs = newContextChildrenAddrs.filter(x =>
1397
- !this._currentWorkingContextIbGib_PriorChildrenAddrs.includes(x)
1398
- );
1399
- if (newChildrenAddrs.length === 0) {
1400
- // no new children
1401
- if (logalot) { console.log(`${lc} no new children addrs in newContext. returning early... (I: 8f9c3658c194c472cb1e2bc19d847b22)`); }
1402
- return []; /* <<<< returns early */
1403
- }
1404
-
1405
- // get the latest addrs for those children
1406
- if (!this.ibgibsSvc) { throw new Error(`this.ibgibsSvc falsy. not initialized? (E: 1cc26ca7de7fadcdbaecbd6613350e23)`); }
1407
- const space = await this.ibgibsSvc.getLocalUserSpace({});
1408
- if (!space) { throw new Error(`couldn't get local user space? (E: f118f75e5852fc22bba3a6495beec723)`); }
1409
- const resLatestAddrs = await getLatestAddrs({ addrs: newChildrenAddrs, space, });
1410
- const latestAddrs = Object.values(resLatestAddrs?.data?.latestAddrsMap ?? {});
1411
- if (!resLatestAddrs?.data?.success || latestAddrs.length !== newChildrenAddrs.length) { throw new Error(`could not get latest addrs. (E: 2e1619e7e2e166696fe8ff78cb02cc22)`); }
1412
-
1413
- // get the addrs' corresponding ibgibs
1414
- if (latestAddrs.some(x => x === null)) {
1415
- // some of the addrs were not found in the space
1416
- throw new Error(`some addrs were not found in the space. (E: 2216d8e5ad7fb600ceb025ed7c90f323)`);
1417
- }
1418
- const resGet = await this.ibgibsSvc.get({ addrs: latestAddrs as IbGibAddr[] });
1419
- if (!resGet.success || resGet.ibGibs?.length !== newChildrenAddrs.length) {
1420
- throw new Error(`failed to get newChildren with addrs: ${newChildrenAddrs.join('|')}. Error: ${resGet.errorMsg ?? 'unknown error 5737bd0996d5445b8bd80975bedc0d57'} (E: 05722e11350ec6ffffdb5c7d0caa2922)`);
1421
- }
1422
-
1423
- return resGet.ibGibs;
1424
- } catch (error) {
1425
- console.error(`${lc} ${error.message}`);
1426
- throw error;
1427
- } finally {
1428
- if (logalot) { console.log(`${lc} complete.`); }
1429
- }
1430
- }
1431
-
1432
- protected async handleNewContextChild({ newChild }: { newChild: IbGib_V1 }): Promise<void> {
1433
- const lc = `${this.lc}[${this.handleNewContextChild.name}]`;
1434
- try {
1435
- throw new Error(`not implemented in base class (E: 833038a17d04e38b9b97be19ed010922)`);
1436
- } catch (error) {
1437
- console.error(`${lc} ${error.message}`);
1438
- throw error;
1439
- }
1440
- }
1441
-
1442
791
  protected async getRobbotInteractionData({
1443
792
  type,
1444
793
  commentText,