@ibgib/web-gib 0.0.4 → 0.0.6

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 (57) hide show
  1. package/dist/api/commands/chat/tell-user.d.mts.map +1 -1
  2. package/dist/api/commands/chat/tell-user.mjs +1 -1
  3. package/dist/api/commands/chat/tell-user.mjs.map +1 -1
  4. package/dist/common/settings/settings-constants.d.mts.map +1 -1
  5. package/dist/common/settings/settings-constants.mjs.map +1 -1
  6. package/dist/helpers.d.mts +7 -0
  7. package/dist/helpers.d.mts.map +1 -1
  8. package/dist/helpers.mjs +25 -0
  9. package/dist/helpers.mjs.map +1 -1
  10. package/dist/helpers.web.d.mts +22 -0
  11. package/dist/helpers.web.d.mts.map +1 -1
  12. package/dist/helpers.web.mjs +22 -0
  13. package/dist/helpers.web.mjs.map +1 -1
  14. package/dist/witness/agent/agent-helpers.d.mts +81 -3
  15. package/dist/witness/agent/agent-helpers.d.mts.map +1 -1
  16. package/dist/witness/agent/agent-helpers.mjs +211 -2
  17. package/dist/witness/agent/agent-helpers.mjs.map +1 -1
  18. package/dist/witness/agent/agent-one-file.d.mts +1 -264
  19. package/dist/witness/agent/agent-one-file.d.mts.map +1 -1
  20. package/dist/witness/agent/agent-one-file.mjs +4 -242
  21. package/dist/witness/agent/agent-one-file.mjs.map +1 -1
  22. package/dist/witness/agent/agent-types.d.mts +189 -1
  23. package/dist/witness/agent/agent-types.d.mts.map +1 -1
  24. package/dist/witness/agent/agent-types.mjs +30 -1
  25. package/dist/witness/agent/agent-types.mjs.map +1 -1
  26. package/dist/witness/agent/agents-service-v1.d.mts +1 -1
  27. package/dist/witness/agent/agents-service-v1.d.mts.map +1 -1
  28. package/dist/witness/agent/agents-service-v1.mjs +1 -2
  29. package/dist/witness/agent/agents-service-v1.mjs.map +1 -1
  30. package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts +4 -3
  31. package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts.map +1 -1
  32. package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs +162 -88
  33. package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs.map +1 -1
  34. package/dist/witness/agent/gemini/gemini-agent-factory.d.mts +2 -1
  35. package/dist/witness/agent/gemini/gemini-agent-factory.d.mts.map +1 -1
  36. package/dist/witness/agent/gemini/gemini-agent-factory.mjs +1 -1
  37. package/dist/witness/agent/gemini/gemini-agent-factory.mjs.map +1 -1
  38. package/dist/witness/agent/gemini/gemini-helpers.d.mts +11 -4
  39. package/dist/witness/agent/gemini/gemini-helpers.d.mts.map +1 -1
  40. package/dist/witness/agent/gemini/gemini-helpers.mjs +7 -3
  41. package/dist/witness/agent/gemini/gemini-helpers.mjs.map +1 -1
  42. package/dist/witness/agent/gemini/gemini-types.d.mts +21 -13
  43. package/dist/witness/agent/gemini/gemini-types.d.mts.map +1 -1
  44. package/dist/witness/agent/gemini/gemini-types.mjs.map +1 -1
  45. package/package.json +2 -2
  46. package/src/api/commands/chat/tell-user.mts +1 -3
  47. package/src/common/settings/settings-constants.mts +4 -1
  48. package/src/helpers.mts +24 -0
  49. package/src/helpers.web.mts +22 -0
  50. package/src/witness/agent/agent-helpers.mts +243 -5
  51. package/src/witness/agent/agent-one-file.mts +8 -473
  52. package/src/witness/agent/agent-types.mts +228 -3
  53. package/src/witness/agent/agents-service-v1.mts +3 -2
  54. package/src/witness/agent/gemini/agent-witness-gemini-v1.mts +193 -96
  55. package/src/witness/agent/gemini/gemini-agent-factory.mts +2 -1
  56. package/src/witness/agent/gemini/gemini-helpers.mts +16 -6
  57. package/src/witness/agent/gemini/gemini-types.mts +39 -13
@@ -1,16 +1,11 @@
1
- import {
2
- clone,
3
- delay,
4
- extractErrorMsg, getTimestampInTicks, pickRandom_Letters, pretty
5
- } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
1
+ import { delay, extractErrorMsg, pickRandom_Letters, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
6
2
  import { UUID_REGEXP } from '@ibgib/helper-gib/dist/constants.mjs';
7
- import { Ib, IbGibAddr, TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
8
- import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
3
+ import { IbGibAddr, TransformResult } from '@ibgib/ts-gib/dist/types.mjs';
4
+ import { IbGib_V1, } from '@ibgib/ts-gib/dist/V1/types.mjs';
9
5
  import { rel8 } from '@ibgib/ts-gib/dist/V1/transforms/rel8.mjs';
10
6
  import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
11
7
  import { GIB, IB, ROOT, ROOT_ADDR } from '@ibgib/ts-gib/dist/V1/constants.mjs';
12
8
  import { mut8 } from '@ibgib/ts-gib/dist/V1/transforms/mut8.mjs';
13
- import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
14
9
  import { getGibInfo } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
15
10
  import { WitnessData_V1, WitnessRel8ns_V1, } from '@ibgib/core-gib/dist/witness/witness-types.mjs';
16
11
  import { CommentIbGib_V1 } from '@ibgib/core-gib/dist/common/comment/comment-types.mjs';
@@ -25,9 +20,9 @@ import { execInSpaceWithLocking, } from '@ibgib/core-gib/dist/witness/space/spac
25
20
 
26
21
  import { GLOBAL_LOG_A_LOT } from '../../constants.mjs';
27
22
  import {
28
- AGENT_ATOM, AGENT_DESC_REGEXP, AGENT_NAME_REGEXP, AGENT_REL8N_NAME, DEFAULT_DESCRIPTION_AGENT,
29
- DEFAULT_NAME_AGENT, DEFAULT_UUID_AGENT, FUNCTION_CALL_REQUEST_COMMENT_TAG,
30
- isTextSource, TEXT_SOURCE_VALUES, TextSource,
23
+ AGENT_ATOM, AGENT_DESC_REGEXP, AGENT_NAME_REGEXP,
24
+ DEFAULT_DESCRIPTION_AGENT, DEFAULT_NAME_AGENT, DEFAULT_UUID_AGENT,
25
+ FUNCTION_CALL_REQUEST_COMMENT_TAG, TextSource,
31
26
  } from './agent-constants.mjs';
32
27
  import { APIFunctionInfo } from '../../api/api-types.mjs';
33
28
  import { getAllFunctionInfos, } from '../../api/api-index.mjs';
@@ -35,474 +30,14 @@ import { FUNCTION_INFO_REL8N_NAME, FunctionInfoIbGib_V1, createFunctionInfoIbGib
35
30
  import { GeminiModel } from './gemini/gemini-constants.mjs';
36
31
  import { PromptAPIResult_Gemini } from './gemini/gemini-types.mjs';
37
32
  import { getGlobalMetaspace_waitIfNeeded } from '../../helpers.mjs';
38
- import { updateAgentIndex } from './agent-helpers.mjs';
33
+ import { getAddlMetadataTextForAgentText, parseAddlMetadataTextForAgentText, taggifyForPrompt, updateAgentIndex } from './agent-helpers.mjs';
39
34
  import { getAgentsSvc } from './agents-service-v1.mjs';
40
35
  import { LiveProxyIbGib } from '../live-proxy-ibgib/live-proxy-ibgib-one-file.mjs';
41
- import { AgentAPI, AgentModel } from './agent-types.mjs';
36
+ import { AddTextsOpts, AgentAPI, AgentModel, AgentWitnessData_V1, AgentWitnessIbGib_V1, AgentWitnessRel8ns_V1, PromptAPIResult, PromptInfo, PromptOneOffOpts, SetActiveContextOpts } from './agent-types.mjs';
42
37
  import { AGENT_SPECIAL_IBGIB_TYPE_PRIMARYAGENT } from '../../agent-texts/primary-agent-texts.mjs';
43
38
 
44
39
  const logalot = GLOBAL_LOG_A_LOT;
45
40
 
46
- export const DEFAULT_AGENT_DATA_V1: AgentWitnessData_V1 = {
47
- version: '1',
48
- uuid: DEFAULT_UUID_AGENT,
49
- name: DEFAULT_NAME_AGENT,
50
- description: DEFAULT_DESCRIPTION_AGENT,
51
- classname: `AgentWitness_V1`,
52
- icon: 'happy', // arbitrary
53
- persistOptsAndResultIbGibs: false,
54
- allowPrimitiveArgs: true,
55
- catchAllErrors: true,
56
- trace: false,
57
-
58
- // agent-specific props
59
- subSpaceId: '',
60
- // purpose: '',
61
- superSpaceId: '',
62
- availableFunctionNameOrIds: [],
63
- model: GeminiModel.GEMINI_2_0_FLASH,
64
- // model: GeminiModel.GEMINI_1_5_PRO,
65
- api: 'gemini',
66
- type: AGENT_SPECIAL_IBGIB_TYPE_PRIMARYAGENT,
67
- "@currentContextTjpAddr": ROOT_ADDR,
68
- }
69
- /**
70
- * don't init with an empty obj. use undefined or factory_v1.firstGen blows up.
71
- */
72
- export const DEFAULT_AGENT_REL8NS_V1: AgentWitnessRel8ns_V1 | undefined = undefined;
73
-
74
-
75
- /**
76
- * @interface AgentWitnessData - Data interface for the AgentWitness.
77
- * @extends WitnessData_V1
78
- */
79
- export interface AgentWitnessData_V1 extends WitnessData_V1 {
80
- /**
81
- * this id corresponds to what space the agent has access to as its own "internal" space.
82
- *
83
- * TODO: implement initialization code to create/get this space when the
84
- * agent is created/initialized.
85
- *
86
- * TODO: implement an APIFunctionInfo for the agent
87
- *
88
- * it is possible that we will add access to other spaces in the future.
89
- */
90
- subSpaceId: SpaceId;
91
- /**
92
- * The space in which the agent's ibgib itself is saved. This is often
93
- * (always?) different than the super space in which the agent itself
94
- * resides.
95
- */
96
- superSpaceId: SpaceId;
97
- /**
98
- * nameOrId corresponding to the function info
99
- */
100
- availableFunctionNameOrIds: string[];
101
- /**
102
- * @see {@link AgentAPI}
103
- */
104
- api: AgentAPI;
105
- /**
106
- * @see {@link AgentModel}
107
- */
108
- model: AgentModel;
109
- /**
110
- * A more fine-grained discriminator.
111
- */
112
- type: string;
113
- /**
114
- * soft link to the current context ibgib. May be out of date, so should use
115
- * get latest on the space (often can do this via metaspace with this
116
- * agent's {@link superSpaceId}).
117
- *
118
- * This defaults to ib^gib (ROOT_ADDR), so if this is the value, then this
119
- * has not been initialized yet and the agent needs to have their context
120
- * set.
121
- */
122
- "@currentContextTjpAddr": IbGibAddr; // string
123
- }
124
-
125
- /**
126
- * @interface AgentWitnessRel8ns - Rel8ns interface for the AgentWitness.
127
- * @extends IbGibRel8ns_V1
128
- */
129
- export interface AgentWitnessRel8ns_V1 extends WitnessRel8ns_V1 {
130
- /**
131
- * @property chat - Relationships to comment ibgibs representing chat
132
- * history for this agent.
133
- *
134
- * These are expected to be comment ibgibs with special additional metadata
135
- * text in the ib that pertains to the agents {@link AgentWitness_V1}.
136
- *
137
- * @see {@link system}
138
- */
139
- chat?: IbGibAddr[];
140
- /**
141
- * @property system - Relationships to comment ibgibs representing the
142
- * system prompt.
143
- *
144
- * This is a Gemini-specific construct that I don't know if it exists in
145
- * other APIs. But the intent is that these are comment ibgibs to be used in
146
- * composing any meta text that is not part of a "chat" between one or more
147
- * users and one or more models.
148
- *
149
- * These are expected to be comment ibgibs with special additional metadata
150
- * text in the ib that pertains to the agents {@link AgentWitness_V1}.
151
- *
152
- * @see {@link system}
153
- */
154
- system?: IbGibAddr[];
155
- }
156
-
157
- /**
158
- * @interface AgentWitnessIbGib_V1 - Interface for an agent ibgib.
159
- *
160
- * @see {@link AgentWitness_V1}
161
- */
162
- export interface AgentWitnessIbGib_V1 extends IbGib_V1<AgentWitnessData_V1, AgentWitnessRel8ns_V1> {
163
- }
164
-
165
- export interface AddTextInfo {
166
- /**
167
- * @property text - raw comment text string to add
168
- * @optional
169
- */
170
- text?: string;
171
- /**
172
- * @optional @property commentIbGib - existing comment to add
173
- */
174
- commentIbGib?: CommentIbGib_V1;
175
- // textSrc: 'hardcoded' | 'human' | 'ai' | 'unknown';
176
- textSrc: TextSource;
177
- /**
178
- * @property isSystem - If true, adds the text to the system prompt instead of chat history.
179
- * @default false
180
- */
181
- isSystem?: boolean;
182
- }
183
-
184
- /**
185
- * @interface AddTextsOpts - Options for adding multiple text comments.
186
- */
187
- export interface AddTextsOpts {
188
- infos: AddTextInfo[];
189
- }
190
-
191
- export interface PromptOneOffOpts {
192
- text: string;
193
- /**
194
- * ad hoc system instructions for the one off call.
195
- */
196
- systemInstructions: string;
197
- }
198
-
199
- /**
200
- * an agent can only have one active context at any time.
201
- *
202
- * Really this is a timeline, so the key thing of this context ibgib is its
203
- * temporal junction point (tjp).
204
- */
205
- export interface SetActiveContextOpts {
206
- contextIbGib: IbGib_V1;
207
- /**
208
- * for debug purposes
209
- */
210
- loggingInfo?: string;
211
- }
212
-
213
- /**
214
- * When composing the prompt to send to the model, this is the information that
215
- * we build up.
216
- */
217
- export interface PromptInfo {
218
- /**
219
- * discriminator of what concrete info is contained in this object.
220
- */
221
- api: AgentAPI;
222
- }
223
-
224
-
225
- /**
226
- * @interface {@link PromptAPIResult} - shape of the result when calling into an
227
- * api-specific model. In general, the api will either return a string or a
228
- * function call request with optional arg(s)
229
- * @see {@link AgentWitness_V1.callTextAPI}
230
- */
231
- export type PromptAPIResult = | PromptAPIResult_Gemini;
232
-
233
- /**
234
- * info object containing information in an agent ib schema.
235
- */
236
- export interface AgentIbInfo {
237
- /**
238
- * should be {@link AGENT_ATOM}
239
- */
240
- atom: string,
241
- name: string,
242
- uuid: string,
243
- type: string,
244
- }
245
-
246
- /**
247
- * information encoded in the addlMetadataText part of a comment ibgib that is
248
- * part of an agent's chat/system text.
249
- *
250
- * notes: long name...
251
- */
252
- export interface AddlMetadataTextForAgentTextInfo {
253
- /**
254
- * @see {@link AddTextInfo.textSrc}
255
- */
256
- textSrc: TextSource;
257
- timestampInTicks: number;
258
- /**
259
- * if there are additional underscore-delimited metadata texts, they will be here.
260
- */
261
- other?: string[];
262
- errorMsg?: string;
263
- }
264
-
265
- // #region helpers
266
-
267
- /**
268
- * creates a begin/end tag composed of the {@link tagText} paired with an
269
- * optional random id around the given {@link contentText}. The begin/end tags
270
- * will be on their own line with {@link contentText} on the lines between.
271
- *
272
- * @example
273
- * [MY_TAG|XBDWZ begin]
274
- * contentText
275
- * [MY_TAG|XBDWZ end]
276
- * @returns
277
- */
278
- export function taggifyForPrompt({
279
- tagText,
280
- contentText,
281
- randomIdLength,
282
- }: {
283
- /**
284
- * the tag itself
285
- */
286
- tagText: string,
287
- /**
288
- * text to be surrounded by the tags' begin and end markers.
289
- */
290
- contentText: string,
291
- /**
292
- * length of random characters to pair with tag. if 0 or undefined, then no
293
- * id will be generated.
294
- */
295
- randomIdLength?: number | undefined,
296
- }): string {
297
- const lc = `[${taggifyForPrompt.name}]`;
298
- try {
299
- if (logalot) { console.log(`${lc} starting... (I: 94104ec059c89d4ba458d96580791d25)`); }
300
- const fullTagText = !!randomIdLength ?
301
- `${tagText}|${pickRandom_Letters({ count: randomIdLength })}` :
302
- tagText;
303
- return [
304
- `[${fullTagText} begin]`,
305
- contentText,
306
- `[${fullTagText} end]`,
307
- ].join('\n');
308
- } catch (error) {
309
- console.error(`${lc} ${extractErrorMsg(error)}`);
310
- throw error;
311
- } finally {
312
- if (logalot) { console.log(`${lc} complete.`); }
313
- }
314
- }
315
-
316
- /**
317
- * ATOW we specify if the text is from ai or human, as well as timestampInTicks.
318
- * @returns metadata text to be included in the comment ibgib's ib.
319
- * @see {@link parseAddlMetadataTextForAgentText}
320
- */
321
- export function getAddlMetadataTextForAgentText({
322
- textSrc,
323
- other,
324
- }: {
325
- /**
326
- * @see {@link AddTextInfo.textSrc}
327
- */
328
- textSrc: TextSource,
329
- /**
330
- * if you have other underscore-delimited text, include that here.
331
- */
332
- other?: string,
333
- }): string {
334
- const lc = `[${getAddlMetadataTextForAgentText.name}]`;
335
- /**
336
- * get and parse functions must **ALWAYS** match must match. If this array
337
- * changes, change the other one.
338
- */
339
- return !!other ?
340
- [textSrc, getTimestampInTicks(), other].join('_') :
341
- [textSrc, getTimestampInTicks()].join('_');
342
- }
343
-
344
- /**
345
- * ATOW we specify if the text is from ai or human, as well as timestampInTicks.
346
- * @returns metadata text to be included in the comment ibgib's ib.
347
- * @see {@link getAddlMetadataTextForAgentText}
348
- */
349
- export function parseAddlMetadataTextForAgentText({
350
- addlMetadataText,
351
- ifError = 'warn',
352
- }: {
353
- addlMetadataText: string,
354
- ifError: 'throw' | 'warn' | 'ignore',
355
- }): AddlMetadataTextForAgentTextInfo {
356
- const lc = `[${getAddlMetadataTextForAgentText.name}]`;
357
- try {
358
- if (logalot) { console.log(`${lc} starting... (I: 89b8b19a8d785b945fe0f816df762d25)`); }
359
-
360
- /**
361
- * get and parse functions must **ALWAYS** match must match. If this
362
- * array changes, change the other one.
363
- */
364
- const [
365
- textSrc,
366
- timestampInTicksStr,
367
- ...other
368
- ] = addlMetadataText.split('_');
369
- if (!textSrc) { throw new Error(`addlMetadataText.textSrc falsy (E: 40bbec4269c1688ab1390fa5d5440325)`); }
370
- if (!isTextSource(textSrc)) { throw new Error(`addlMetadataText.textSrc (${textSrc}) is unexpected value. Expected one of ${TEXT_SOURCE_VALUES} (E: 02bae41275a39210e5737548747bd825)`); }
371
- if (!timestampInTicksStr) { throw new Error(`addlMetadataText.timestampInTicks falsy (E: 03cbbc7515a1cff1fc7c12e3947c6825)`); }
372
- const timestampInTicks = Number.parseInt(timestampInTicksStr);
373
- if (Number.isNaN(timestampInTicks)) { throw new Error(`invalid timestampInTicks (${timestampInTicksStr}): value should be an integer but parse is NaN (E: 9d31e3563d972c02553ce18a19a19b25)`); }
374
- return {
375
- textSrc,
376
- timestampInTicks,
377
- other: other.length > 0 ? other : undefined,
378
- };
379
- } catch (error) {
380
- const errorMsg = `${lc} ${extractErrorMsg(error)}`;
381
- switch (ifError) {
382
- case 'ignore':
383
- return {
384
- textSrc: TextSource.UNKNOWN,
385
- timestampInTicks: 0,
386
- errorMsg: extractErrorMsg(error)
387
- };
388
- case 'warn':
389
- console.warn(`${lc} ${errorMsg} (W: 3e1f4a98ad6461c9bd96462841c31b25)`)
390
- return {
391
- textSrc: TextSource.UNKNOWN,
392
- timestampInTicks: 0,
393
- errorMsg: extractErrorMsg(error)
394
- };
395
- default:
396
- console.error(`${lc} ${errorMsg} (E: 6396ed44947c52adf85788e1adc22825)`);
397
- throw new Error(errorMsg);
398
- }
399
- } finally {
400
- if (logalot) { console.log(`${lc} complete.`); }
401
- }
402
- }
403
-
404
- /**
405
- * builds the agent witness' ib based on given {@link data}
406
- * @see {@link parseAgentIb}
407
- */
408
- export function getAgentIb({
409
- data,
410
- }: {
411
- /** agent data, should be valid */
412
- data: AgentWitnessData_V1,
413
- }): string {
414
- const lc = `[${getAgentIb.name}]`;
415
- const { name, uuid, type } = data;
416
- if (!name) { throw new Error(`${lc} data.name falsy (E: 4c172c5b8a110ae26479b8c4006f3225)`); }
417
- if (!uuid) { throw new Error(`${lc} data.uuid falsy (E: 67d2c79ac39e70e5ecfd1745e1fd3525)`); }
418
- if (!type) { throw new Error(`${lc} data.type falsy (E: 53bf1f9a145a16be81296437682a7a25)`); }
419
- const fields: string[] = [name, uuid, type];
420
- if (fields.some(x => x.includes(' '))) { throw new Error(`invalid data. ib must not contain spaces in name, uuid, type. (E: 36a56e4685163848458be06f51d4ad25)`); }
421
- /** getAgentIb must match parseAgentIb. If this array changes, change the other one. */
422
- return [
423
- AGENT_ATOM,
424
- name,
425
- uuid,
426
- type,
427
- // what else?
428
- ].join(' ');
429
- }
430
-
431
- /**
432
- * @returns parsed info from an ib
433
- * @see {@link getAgentIb}
434
- */
435
- export function parseAgentIb({
436
- ib,
437
- }: {
438
- ib: Ib,
439
- }): AgentIbInfo {
440
- /** getAgentIb must match parseAgentIb. If this array changes, change the other one. */
441
- const [
442
- atom,
443
- name,
444
- uuid,
445
- type,
446
- ] = ib.split(' ');
447
- if (atom !== AGENT_ATOM) { throw new Error(`invalid ib. first term expected to e an atom: ${AGENT_ATOM} (E: 3c01d42035d2e32c4bfd5c1bf363f725)`); }
448
- if (!name) { throw new Error(`invalid ib. name falsy in agent ib (E: 8b494c544f05b8ef9c866078b761a725)`); }
449
- if (!uuid) { throw new Error(`invalid ib. uuid falsy in agent ib (E: aba195db3ddcb000324ebed15351b725)`); }
450
- if (!type) { throw new Error(`invalid ib. type falsy in agent ib (E: 8c814772394ae76342f95e885570c325)`); }
451
- return { atom, name, uuid, type };
452
- }
453
-
454
- /**
455
- * Validates a comment ibgib to ensure that it is usable in an agent witness
456
- * context, especially that it includes the expected metadata format in its
457
- * `ib`.
458
- *
459
- * @param {CommentIbGib_V1} ibGib - The comment ibgib to validate.
460
- * @returns {string[]} An array of error messages if validation fails, or an empty array if no errors.
461
- */
462
- export async function validateAgentWitnessCommentIbGib({
463
- ibGib,
464
- }: {
465
- ibGib: CommentIbGib_V1,
466
- }): Promise<string[]> {
467
- const lc = `[${validateAgentWitnessCommentIbGib.name}]`;
468
- try {
469
- if (logalot) { console.log(`${lc} starting... (I: f9a733a5a05b7f7494836d86a79e2d25)`); }
470
-
471
- const errors: string[] = await validateIbGibIntrinsically({ ibGib }) ?? [];
472
-
473
- if (!isComment({ ibGib })) {
474
- errors.push(`${lc} not a comment ibgib (E: 08676d94c698c6e42e6c35e94a58f125)`);
475
- return errors; /* returns early */
476
- }
477
-
478
- const { safeIbCommentMetadataText: addlMetadataText } = parseCommentIb({ ib: ibGib.ib });
479
-
480
- if (addlMetadataText) {
481
- const addlMetaInfo = parseAddlMetadataTextForAgentText({
482
- addlMetadataText,
483
- ifError: 'warn'
484
- });
485
- if (addlMetaInfo.errorMsg) {
486
- errors.push(`${lc} could not parse addlMetadataText: ${addlMetaInfo.errorMsg} (E: e178265c33e5e94947a02c1f9d6a7425)`);
487
- }
488
- } else {
489
- errors.push(`${lc} addlMetadataText falsy. this implies something is incorrect with the comment's ib, as we expect agent comments to have certain metadata (e.g. textSrc). See AgentWitness_V1 (and data interface) for more info. (E: 7c3c41c973a67256c432604666106b25)`);
490
- }
491
-
492
- return errors;
493
- } catch (error) {
494
- console.error(`${lc} ${extractErrorMsg(error)}`);
495
- throw error;
496
- } finally {
497
- if (logalot) { console.log(`${lc} complete.`); }
498
- }
499
- }
500
-
501
-
502
-
503
- // #endregion helpers
504
-
505
-
506
41
  /**
507
42
  * @extends LightWitnessBase_V1<AgentWitnessData_V1, AgentWitnessRel8ns_V1>
508
43
  *