@ibgib/web-gib 0.0.3 → 0.0.5
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/dist/api/commands/chat/tell-user.d.mts.map +1 -1
- package/dist/api/commands/chat/tell-user.mjs +1 -1
- package/dist/api/commands/chat/tell-user.mjs.map +1 -1
- package/dist/common/settings/settings-constants.d.mts.map +1 -1
- package/dist/common/settings/settings-constants.mjs.map +1 -1
- package/dist/helpers.d.mts +30 -2
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +157 -2
- package/dist/helpers.mjs.map +1 -1
- package/dist/helpers.web.d.mts +22 -23
- package/dist/helpers.web.d.mts.map +1 -1
- package/dist/helpers.web.mjs +25 -133
- package/dist/helpers.web.mjs.map +1 -1
- package/dist/ui/component/ibgib-dynamic-component-bases.d.mts.map +1 -1
- package/dist/ui/component/ibgib-dynamic-component-bases.mjs +2 -2
- package/dist/ui/component/ibgib-dynamic-component-bases.mjs.map +1 -1
- package/dist/witness/agent/agent-helpers.d.mts +81 -3
- package/dist/witness/agent/agent-helpers.d.mts.map +1 -1
- package/dist/witness/agent/agent-helpers.mjs +211 -2
- package/dist/witness/agent/agent-helpers.mjs.map +1 -1
- package/dist/witness/agent/agent-one-file.d.mts +1 -264
- package/dist/witness/agent/agent-one-file.d.mts.map +1 -1
- package/dist/witness/agent/agent-one-file.mjs +4 -242
- package/dist/witness/agent/agent-one-file.mjs.map +1 -1
- package/dist/witness/agent/agent-types.d.mts +189 -1
- package/dist/witness/agent/agent-types.d.mts.map +1 -1
- package/dist/witness/agent/agent-types.mjs +30 -1
- package/dist/witness/agent/agent-types.mjs.map +1 -1
- package/dist/witness/agent/agents-service-v1.d.mts +1 -1
- package/dist/witness/agent/agents-service-v1.d.mts.map +1 -1
- package/dist/witness/agent/agents-service-v1.mjs +1 -2
- package/dist/witness/agent/agents-service-v1.mjs.map +1 -1
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts +2 -1
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.d.mts.map +1 -1
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs +2 -1
- package/dist/witness/agent/gemini/agent-witness-gemini-v1.mjs.map +1 -1
- package/dist/witness/agent/gemini/gemini-agent-factory.d.mts +2 -1
- package/dist/witness/agent/gemini/gemini-agent-factory.d.mts.map +1 -1
- package/dist/witness/agent/gemini/gemini-agent-factory.mjs +1 -1
- package/dist/witness/agent/gemini/gemini-agent-factory.mjs.map +1 -1
- package/dist/witness/agent/gemini/gemini-helpers.d.mts +1 -1
- package/dist/witness/agent/gemini/gemini-helpers.d.mts.map +1 -1
- package/dist/witness/agent/gemini/gemini-types.d.mts +1 -1
- package/dist/witness/agent/gemini/gemini-types.d.mts.map +1 -1
- package/package.json +1 -1
- package/src/api/commands/chat/tell-user.mts +1 -3
- package/src/common/settings/settings-constants.mts +4 -1
- package/src/helpers.mts +168 -4
- package/src/helpers.web.mts +28 -147
- package/src/ui/component/ibgib-dynamic-component-bases.mts +5 -3
- package/src/witness/agent/agent-helpers.mts +243 -5
- package/src/witness/agent/agent-one-file.mts +8 -473
- package/src/witness/agent/agent-types.mts +228 -3
- package/src/witness/agent/agents-service-v1.mts +3 -2
- package/src/witness/agent/gemini/agent-witness-gemini-v1.mts +5 -2
- package/src/witness/agent/gemini/gemini-agent-factory.mts +2 -1
- package/src/witness/agent/gemini/gemini-helpers.mts +1 -1
- package/src/witness/agent/gemini/gemini-types.mts +1 -1
package/src/helpers.web.mts
CHANGED
|
@@ -6,10 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { delay, extractErrorMsg, pretty, } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
8
8
|
import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { GIB } from "@ibgib/ts-gib/dist/V1/constants.mjs";
|
|
12
|
-
import { getGibInfo, isPrimitive } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
|
|
9
|
+
import { getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
10
|
+
import { isPrimitive } from "@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs";
|
|
13
11
|
import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
|
|
14
12
|
import { MetaspaceService } from "@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs";
|
|
15
13
|
import { RawExportIbGib_V1 } from "@ibgib/core-gib/dist/common/import-export/import-export-types.mjs";
|
|
@@ -19,13 +17,13 @@ import { getRawExportIbGib } from "@ibgib/core-gib/dist/common/import-export/imp
|
|
|
19
17
|
import { IbGibSpaceAny } from "@ibgib/core-gib/dist/witness/space/space-base-v1.mjs";
|
|
20
18
|
|
|
21
19
|
import {
|
|
22
|
-
GLOBAL_LOG_A_LOT,
|
|
23
|
-
DEFAULT_IBGIB_TRANSLUCENT, GEMINI_API_KEY_REGEXP,
|
|
20
|
+
GLOBAL_LOG_A_LOT, GEMINI_API_KEY_REGEXP,
|
|
24
21
|
CONFIG_OPTION_GEMINI_API_KEY_LOCATION_HELP
|
|
25
22
|
} from "./constants.mjs";
|
|
26
23
|
import { showFullscreenDialog } from "./ui/ui-helpers.mjs";
|
|
27
|
-
import {
|
|
28
|
-
|
|
24
|
+
import {
|
|
25
|
+
initializeStorage, storageCreateStoreIfNotExist, storageDBExists, storagePut
|
|
26
|
+
} from "./storage/storage-helpers.web.mjs";
|
|
29
27
|
import { getIbGibGlobalThis_IbGib } from "./helpers.mjs";
|
|
30
28
|
|
|
31
29
|
|
|
@@ -254,6 +252,28 @@ export async function shareContent({
|
|
|
254
252
|
* This is causing a problem though when testing inside an iframe in Project
|
|
255
253
|
* IDX...I guess I'll have to whitelist embedded sites like link-gib
|
|
256
254
|
*
|
|
255
|
+
* ## usage
|
|
256
|
+
*
|
|
257
|
+
* Put something like this in the html in <head>:
|
|
258
|
+
* ```html
|
|
259
|
+
* <meta name="ibgib-app-id-yo" content="0f73bca49d2856a446044768fbab8d25" />
|
|
260
|
+
* ```
|
|
261
|
+
* Then create constants like this (I put them in a constants file):
|
|
262
|
+
*
|
|
263
|
+
* ```typescript
|
|
264
|
+
* export const HTML_META_APP_ID_NAME = "ibgib-app-id-yo";
|
|
265
|
+
* export const HTML_META_APP_ID_CONTENT = "0f73bca49d2856a446044768fbab8d25";
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* Then you can call this like this:
|
|
269
|
+
*
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const isInWebAppProper = isExecutingInBlankGibWebAppProper({
|
|
272
|
+
* metaName_appId: HTML_META_APP_ID_NAME,
|
|
273
|
+
* metaContent_appId: HTML_META_APP_ID_CONTENT
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
257
277
|
* @returns true if we are executing in an iframe, false otherwise.
|
|
258
278
|
*/
|
|
259
279
|
export function isExecutingInBlankGibWebAppProper({
|
|
@@ -755,145 +775,6 @@ export async function unhighlightElement({
|
|
|
755
775
|
}
|
|
756
776
|
}
|
|
757
777
|
|
|
758
|
-
/**
|
|
759
|
-
* builds a color schema based on the gib.
|
|
760
|
-
*
|
|
761
|
-
* note that the alpha drives the translucent property, but the solid color is
|
|
762
|
-
* always built
|
|
763
|
-
*/
|
|
764
|
-
export function getDeterministicColorInfo({
|
|
765
|
-
ibGibAddr,
|
|
766
|
-
gib,
|
|
767
|
-
ibGib,
|
|
768
|
-
translucentAlpha = 10,
|
|
769
|
-
}: {
|
|
770
|
-
ibGibAddr?: IbGibAddr,
|
|
771
|
-
gib?: Gib,
|
|
772
|
-
ibGib?: IbGib_V1,
|
|
773
|
-
/**
|
|
774
|
-
* drives the translucent color.
|
|
775
|
-
*
|
|
776
|
-
* @default 10
|
|
777
|
-
*/
|
|
778
|
-
translucentAlpha?: number
|
|
779
|
-
}): GibColorInfo {
|
|
780
|
-
const lc = `[${getDeterministicColorInfo.name}]`;
|
|
781
|
-
try {
|
|
782
|
-
if (logalot) { console.log(`${lc} starting... (I: 3b70af42d1c4f6ae91870f3a15c6c625)`); }
|
|
783
|
-
if (!ibGibAddr && !gib && !ibGib) { gib = GIB; }
|
|
784
|
-
gib ??= ibGib?.gib ?? getIbAndGib({ ibGibAddr }).gib;
|
|
785
|
-
const gibInfo = getGibInfo({ gib });
|
|
786
|
-
translucentAlpha ??= 10;
|
|
787
|
-
/**
|
|
788
|
-
* we want to color coordinate according to timeline if possible, i.e.,
|
|
789
|
-
* by tjpGib.
|
|
790
|
-
*/
|
|
791
|
-
let drivingHash = '';
|
|
792
|
-
if (gibInfo.isPrimitive) {
|
|
793
|
-
return {
|
|
794
|
-
gib,
|
|
795
|
-
gibInfo,
|
|
796
|
-
punctiliarColor: DEFAULT_IBGIB_COLOR,
|
|
797
|
-
punctiliarColorTranslucent: DEFAULT_IBGIB_TRANSLUCENT,
|
|
798
|
-
punctiliarColorContrast: DEFAULT_IBGIB_COLOR_CONTRAST,
|
|
799
|
-
}; /* <<<< returns early */
|
|
800
|
-
} else {
|
|
801
|
-
drivingHash = gibInfo.tjpGib ?? gibInfo.punctiliarHash ?? gib; // hmm, gib should be punctiliar but meh
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* gets the color string
|
|
808
|
-
*/
|
|
809
|
-
// const fnGetColorStr = (drivingHash: string) => {
|
|
810
|
-
// function getContrastColor(hexcolor: string) {
|
|
811
|
-
// const c = hexcolor.concat().replace("#", "");
|
|
812
|
-
// var r = parseInt(c.substr(0, 2), 16);
|
|
813
|
-
// var g = parseInt(c.substr(2, 2), 16);
|
|
814
|
-
// var b = parseInt(c.substr(4, 2), 16);
|
|
815
|
-
// var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
|
|
816
|
-
// return (yiq >= 128) ? '#000000' : '#FFFFFF';
|
|
817
|
-
// }
|
|
818
|
-
// let alphaStr = '';
|
|
819
|
-
// if (translucentAlpha || translucentAlpha === 0) {
|
|
820
|
-
// if (translucentAlpha < 0 || translucentAlpha > 100) {
|
|
821
|
-
// throw new Error(`alpha must be between 0 and 100 (E: c78faeb1477482c739b03dd32d2e1825)`);
|
|
822
|
-
// }
|
|
823
|
-
// if (translucentAlpha === 100) {
|
|
824
|
-
// alphaStr = '';
|
|
825
|
-
// } else if (translucentAlpha >= 0 && translucentAlpha < 10) {
|
|
826
|
-
// // single digit
|
|
827
|
-
// alphaStr = `0${translucentAlpha}`;
|
|
828
|
-
// } else {
|
|
829
|
-
// alphaStr = translucentAlpha.toString();
|
|
830
|
-
// }
|
|
831
|
-
// }
|
|
832
|
-
// const color = `#${drivingHash.substring(0, 6)}`;
|
|
833
|
-
// const colorTranslucent = `#${drivingHash.substring(0, 6)}${alphaStr}`;
|
|
834
|
-
// const colorContrast = getContrastColor(color);
|
|
835
|
-
// return [color, colorTranslucent, colorContrast];
|
|
836
|
-
// };
|
|
837
|
-
|
|
838
|
-
const [punctiliarColor, punctiliarColorTranslucent, punctiliarColorContrast] = getColorStrings(translucentAlpha, gibInfo.punctiliarHash ?? gib);
|
|
839
|
-
const [tjpColor, tjpColorTranslucent, tjpColorContrast] = !!gibInfo.tjpGib ?
|
|
840
|
-
getColorStrings(translucentAlpha, gibInfo.tjpGib) :
|
|
841
|
-
[undefined, undefined, undefined];
|
|
842
|
-
|
|
843
|
-
return {
|
|
844
|
-
gib,
|
|
845
|
-
gibInfo,
|
|
846
|
-
punctiliarColor, punctiliarColorTranslucent, punctiliarColorContrast,
|
|
847
|
-
tjpColor, tjpColorTranslucent, tjpColorContrast,
|
|
848
|
-
};
|
|
849
|
-
} catch (error) {
|
|
850
|
-
const errorMsg = `${lc} ${extractErrorMsg(error)}`;
|
|
851
|
-
console.error(errorMsg);
|
|
852
|
-
return {
|
|
853
|
-
gib: gib ?? GIB,
|
|
854
|
-
gibInfo: { isPrimitive: true },
|
|
855
|
-
punctiliarColor: '#ff0000', // red
|
|
856
|
-
punctiliarColorTranslucent: '#ff000010', // translucent red
|
|
857
|
-
punctiliarColorContrast: '#ffffff', // black
|
|
858
|
-
errorMsg,
|
|
859
|
-
};
|
|
860
|
-
} finally {
|
|
861
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* gets the color, colorTranslucent and colorContrast
|
|
867
|
-
*/
|
|
868
|
-
export function getColorStrings(translucentAlpha: number, drivingHash: string): [string, string, string] {
|
|
869
|
-
function getContrastColor(hexcolor: string) {
|
|
870
|
-
const c = hexcolor.concat().replace("#", "");
|
|
871
|
-
var r = parseInt(c.substr(0, 2), 16);
|
|
872
|
-
var g = parseInt(c.substr(2, 2), 16);
|
|
873
|
-
var b = parseInt(c.substr(4, 2), 16);
|
|
874
|
-
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
|
|
875
|
-
return (yiq >= 128) ? '#000000' : '#FFFFFF';
|
|
876
|
-
}
|
|
877
|
-
let alphaStr = '';
|
|
878
|
-
if (translucentAlpha || translucentAlpha === 0) {
|
|
879
|
-
if (translucentAlpha < 0 || translucentAlpha > 100) {
|
|
880
|
-
throw new Error(`alpha must be between 0 and 100 (E: c78faeb1477482c739b03dd32d2e1825)`);
|
|
881
|
-
}
|
|
882
|
-
if (translucentAlpha === 100) {
|
|
883
|
-
alphaStr = '';
|
|
884
|
-
} else if (translucentAlpha >= 0 && translucentAlpha < 10) {
|
|
885
|
-
// single digit
|
|
886
|
-
alphaStr = `0${translucentAlpha}`;
|
|
887
|
-
} else {
|
|
888
|
-
alphaStr = translucentAlpha.toString();
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
const color = `#${drivingHash.substring(0, 6)}`;
|
|
892
|
-
const colorTranslucent = `#${drivingHash.substring(0, 6)}${alphaStr}`;
|
|
893
|
-
const colorContrast = getContrastColor(color);
|
|
894
|
-
return [color, colorTranslucent, colorContrast];
|
|
895
|
-
};
|
|
896
|
-
|
|
897
778
|
/**
|
|
898
779
|
* Takes an incoming string. Assumes it's invalid. Does best effort at validating this.
|
|
899
780
|
* Gets the raw export ibgib if it can. If so, and if it is compressed, decompresses the
|
|
@@ -37,8 +37,11 @@ import { mut8Timeline } from "@ibgib/core-gib/dist/timeline/timeline-api.mjs";
|
|
|
37
37
|
|
|
38
38
|
import { GLOBAL_LOG_A_LOT } from "../../constants.mjs";
|
|
39
39
|
import {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
coupleDomainIbGibWithLocalIbGibViaIndex, getLocalCoupledIbGibForDomainIbGib,
|
|
41
|
+
getDeterministicColorInfo,
|
|
42
|
+
} from "../../helpers.mjs";
|
|
43
|
+
import {
|
|
44
|
+
exportIbGib, getRawExportIbGibAndGraphFromJsonString
|
|
42
45
|
} from "../../helpers.web.mjs";
|
|
43
46
|
import { LiveProxyIbGib } from "../../witness/live-proxy-ibgib/live-proxy-ibgib-one-file.mjs";
|
|
44
47
|
import { AgentWitnessAny, } from "../../witness/agent/agent-one-file.mjs";
|
|
@@ -48,7 +51,6 @@ import { getAgentForDomainIbGib } from "../../witness/agent/agent-helpers.mjs";
|
|
|
48
51
|
import { createSettings, getSectionName, getSettingsScope, getSettingsSection } from "../../common/settings/settings-helpers.mjs";
|
|
49
52
|
import { IbGibSettings, SettingsIbGib_V1, SettingsWithTabs } from "../../common/settings/settings-types.mjs";
|
|
50
53
|
import { SettingsType } from "../../common/settings/settings-constants.mjs";
|
|
51
|
-
import { coupleDomainIbGibWithLocalIbGibViaIndex, getLocalCoupledIbGibForDomainIbGib } from "../../helpers.mjs";
|
|
52
54
|
|
|
53
55
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
54
56
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { extractErrorMsg, } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
1
|
+
import { extractErrorMsg, getTimestampInTicks, pickRandom_Letters, } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
2
2
|
import { getIbAndGib, getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
3
|
-
import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
|
|
3
|
+
import { Ib, IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
|
|
4
4
|
import { IbGib_V1, } from "@ibgib/ts-gib/dist/V1/types.mjs";
|
|
5
5
|
import { MetaspaceService } from "@ibgib/core-gib/dist/witness/space/metaspace/metaspace-types.mjs";
|
|
6
6
|
import { SpaceId } from "@ibgib/core-gib/dist/witness/space/space-types.mjs";
|
|
@@ -15,15 +15,18 @@ import {
|
|
|
15
15
|
GLOBAL_LOG_A_LOT, TAG_AGENT_DESCRIPTION, TAG_AGENT_IB, TAG_AGENT_ICON,
|
|
16
16
|
TAG_AGENT_TEXT,
|
|
17
17
|
} from "../../constants.mjs";
|
|
18
|
-
import { AgentWitnessAny,
|
|
19
|
-
import { AGENT_REL8N_NAME } from "./agent-constants.mjs";
|
|
18
|
+
import { AgentWitnessAny, } from "./agent-one-file.mjs";
|
|
19
|
+
import { AGENT_ATOM, AGENT_REL8N_NAME, isTextSource, TEXT_SOURCE_VALUES, TextSource } from "./agent-constants.mjs";
|
|
20
20
|
import {
|
|
21
21
|
coupleDomainIbGibWithLocalIbGibViaIndex, getIndexNameFromIbGib,
|
|
22
22
|
getLocalCoupledIbGibForDomainIbGib, getTagsIbGib
|
|
23
23
|
} from "../../helpers.mjs";
|
|
24
24
|
import { getAgentsSvc } from "./agents-service-v1.mjs";
|
|
25
|
-
import { CreateConcreteAgentWitnessFactory, CreateNewAgentArg } from "./agent-types.mjs";
|
|
25
|
+
import { AddlMetadataTextForAgentTextInfo, AgentIbInfo, AgentWitnessData_V1, AgentWitnessIbGib_V1, CreateConcreteAgentWitnessFactory, CreateNewAgentArg } from "./agent-types.mjs";
|
|
26
26
|
import { CreateConcreteAgentWitnessFactory_Gemini } from "./gemini/gemini-agent-factory.mjs";
|
|
27
|
+
import { CommentIbGib_V1 } from "@ibgib/core-gib/dist/common/comment/comment-types.mjs";
|
|
28
|
+
import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
|
|
29
|
+
import { isComment, parseCommentIb } from "@ibgib/core-gib/dist/common/comment/comment-helper.mjs";
|
|
27
30
|
// import { updateSpecialIndex } from "../../api/timeline/timeline-api.mjs";
|
|
28
31
|
|
|
29
32
|
const logalot = GLOBAL_LOG_A_LOT; // change this when you want to turn off verbose logging
|
|
@@ -679,3 +682,238 @@ export function getConcreteAgentFactory(arg: CreateNewAgentArg): CreateConcreteA
|
|
|
679
682
|
if (logalot) { console.log(`${lc} complete.`); }
|
|
680
683
|
}
|
|
681
684
|
}
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* creates a begin/end tag composed of the {@link tagText} paired with an
|
|
689
|
+
* optional random id around the given {@link contentText}. The begin/end tags
|
|
690
|
+
* will be on their own line with {@link contentText} on the lines between.
|
|
691
|
+
*
|
|
692
|
+
* @example
|
|
693
|
+
* [MY_TAG|XBDWZ begin]
|
|
694
|
+
* contentText
|
|
695
|
+
* [MY_TAG|XBDWZ end]
|
|
696
|
+
* @returns
|
|
697
|
+
*/
|
|
698
|
+
export function taggifyForPrompt({
|
|
699
|
+
tagText,
|
|
700
|
+
contentText,
|
|
701
|
+
randomIdLength,
|
|
702
|
+
}: {
|
|
703
|
+
/**
|
|
704
|
+
* the tag itself
|
|
705
|
+
*/
|
|
706
|
+
tagText: string,
|
|
707
|
+
/**
|
|
708
|
+
* text to be surrounded by the tags' begin and end markers.
|
|
709
|
+
*/
|
|
710
|
+
contentText: string,
|
|
711
|
+
/**
|
|
712
|
+
* length of random characters to pair with tag. if 0 or undefined, then no
|
|
713
|
+
* id will be generated.
|
|
714
|
+
*/
|
|
715
|
+
randomIdLength?: number | undefined,
|
|
716
|
+
}): string {
|
|
717
|
+
const lc = `[${taggifyForPrompt.name}]`;
|
|
718
|
+
try {
|
|
719
|
+
if (logalot) { console.log(`${lc} starting... (I: 94104ec059c89d4ba458d96580791d25)`); }
|
|
720
|
+
const fullTagText = !!randomIdLength ?
|
|
721
|
+
`${tagText}|${pickRandom_Letters({ count: randomIdLength })}` :
|
|
722
|
+
tagText;
|
|
723
|
+
return [
|
|
724
|
+
`[${fullTagText} begin]`,
|
|
725
|
+
contentText,
|
|
726
|
+
`[${fullTagText} end]`,
|
|
727
|
+
].join('\n');
|
|
728
|
+
} catch (error) {
|
|
729
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
730
|
+
throw error;
|
|
731
|
+
} finally {
|
|
732
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* ATOW we specify if the text is from ai or human, as well as timestampInTicks.
|
|
738
|
+
* @returns metadata text to be included in the comment ibgib's ib.
|
|
739
|
+
* @see {@link parseAddlMetadataTextForAgentText}
|
|
740
|
+
*/
|
|
741
|
+
export function getAddlMetadataTextForAgentText({
|
|
742
|
+
textSrc,
|
|
743
|
+
other,
|
|
744
|
+
}: {
|
|
745
|
+
/**
|
|
746
|
+
* @see {@link AddTextInfo.textSrc}
|
|
747
|
+
*/
|
|
748
|
+
textSrc: TextSource,
|
|
749
|
+
/**
|
|
750
|
+
* if you have other underscore-delimited text, include that here.
|
|
751
|
+
*/
|
|
752
|
+
other?: string,
|
|
753
|
+
}): string {
|
|
754
|
+
const lc = `[${getAddlMetadataTextForAgentText.name}]`;
|
|
755
|
+
/**
|
|
756
|
+
* get and parse functions must **ALWAYS** match must match. If this array
|
|
757
|
+
* changes, change the other one.
|
|
758
|
+
*/
|
|
759
|
+
return !!other ?
|
|
760
|
+
[textSrc, getTimestampInTicks(), other].join('_') :
|
|
761
|
+
[textSrc, getTimestampInTicks()].join('_');
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* ATOW we specify if the text is from ai or human, as well as timestampInTicks.
|
|
766
|
+
* @returns metadata text to be included in the comment ibgib's ib.
|
|
767
|
+
* @see {@link getAddlMetadataTextForAgentText}
|
|
768
|
+
*/
|
|
769
|
+
export function parseAddlMetadataTextForAgentText({
|
|
770
|
+
addlMetadataText,
|
|
771
|
+
ifError = 'warn',
|
|
772
|
+
}: {
|
|
773
|
+
addlMetadataText: string,
|
|
774
|
+
ifError: 'throw' | 'warn' | 'ignore',
|
|
775
|
+
}): AddlMetadataTextForAgentTextInfo {
|
|
776
|
+
const lc = `[${getAddlMetadataTextForAgentText.name}]`;
|
|
777
|
+
try {
|
|
778
|
+
if (logalot) { console.log(`${lc} starting... (I: 89b8b19a8d785b945fe0f816df762d25)`); }
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* get and parse functions must **ALWAYS** match must match. If this
|
|
782
|
+
* array changes, change the other one.
|
|
783
|
+
*/
|
|
784
|
+
const [
|
|
785
|
+
textSrc,
|
|
786
|
+
timestampInTicksStr,
|
|
787
|
+
...other
|
|
788
|
+
] = addlMetadataText.split('_');
|
|
789
|
+
if (!textSrc) { throw new Error(`addlMetadataText.textSrc falsy (E: 40bbec4269c1688ab1390fa5d5440325)`); }
|
|
790
|
+
if (!isTextSource(textSrc)) { throw new Error(`addlMetadataText.textSrc (${textSrc}) is unexpected value. Expected one of ${TEXT_SOURCE_VALUES} (E: 02bae41275a39210e5737548747bd825)`); }
|
|
791
|
+
if (!timestampInTicksStr) { throw new Error(`addlMetadataText.timestampInTicks falsy (E: 03cbbc7515a1cff1fc7c12e3947c6825)`); }
|
|
792
|
+
const timestampInTicks = Number.parseInt(timestampInTicksStr);
|
|
793
|
+
if (Number.isNaN(timestampInTicks)) { throw new Error(`invalid timestampInTicks (${timestampInTicksStr}): value should be an integer but parse is NaN (E: 9d31e3563d972c02553ce18a19a19b25)`); }
|
|
794
|
+
return {
|
|
795
|
+
textSrc,
|
|
796
|
+
timestampInTicks,
|
|
797
|
+
other: other.length > 0 ? other : undefined,
|
|
798
|
+
};
|
|
799
|
+
} catch (error) {
|
|
800
|
+
const errorMsg = `${lc} ${extractErrorMsg(error)}`;
|
|
801
|
+
switch (ifError) {
|
|
802
|
+
case 'ignore':
|
|
803
|
+
return {
|
|
804
|
+
textSrc: TextSource.UNKNOWN,
|
|
805
|
+
timestampInTicks: 0,
|
|
806
|
+
errorMsg: extractErrorMsg(error)
|
|
807
|
+
};
|
|
808
|
+
case 'warn':
|
|
809
|
+
console.warn(`${lc} ${errorMsg} (W: 3e1f4a98ad6461c9bd96462841c31b25)`)
|
|
810
|
+
return {
|
|
811
|
+
textSrc: TextSource.UNKNOWN,
|
|
812
|
+
timestampInTicks: 0,
|
|
813
|
+
errorMsg: extractErrorMsg(error)
|
|
814
|
+
};
|
|
815
|
+
default:
|
|
816
|
+
console.error(`${lc} ${errorMsg} (E: 6396ed44947c52adf85788e1adc22825)`);
|
|
817
|
+
throw new Error(errorMsg);
|
|
818
|
+
}
|
|
819
|
+
} finally {
|
|
820
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* builds the agent witness' ib based on given {@link data}
|
|
826
|
+
* @see {@link parseAgentIb}
|
|
827
|
+
*/
|
|
828
|
+
export function getAgentIb({
|
|
829
|
+
data,
|
|
830
|
+
}: {
|
|
831
|
+
/** agent data, should be valid */
|
|
832
|
+
data: AgentWitnessData_V1,
|
|
833
|
+
}): string {
|
|
834
|
+
const lc = `[${getAgentIb.name}]`;
|
|
835
|
+
const { name, uuid, type } = data;
|
|
836
|
+
if (!name) { throw new Error(`${lc} data.name falsy (E: 4c172c5b8a110ae26479b8c4006f3225)`); }
|
|
837
|
+
if (!uuid) { throw new Error(`${lc} data.uuid falsy (E: 67d2c79ac39e70e5ecfd1745e1fd3525)`); }
|
|
838
|
+
if (!type) { throw new Error(`${lc} data.type falsy (E: 53bf1f9a145a16be81296437682a7a25)`); }
|
|
839
|
+
const fields: string[] = [name, uuid, type];
|
|
840
|
+
if (fields.some(x => x.includes(' '))) { throw new Error(`invalid data. ib must not contain spaces in name, uuid, type. (E: 36a56e4685163848458be06f51d4ad25)`); }
|
|
841
|
+
/** getAgentIb must match parseAgentIb. If this array changes, change the other one. */
|
|
842
|
+
return [
|
|
843
|
+
AGENT_ATOM,
|
|
844
|
+
name,
|
|
845
|
+
uuid,
|
|
846
|
+
type,
|
|
847
|
+
// what else?
|
|
848
|
+
].join(' ');
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* @returns parsed info from an ib
|
|
853
|
+
* @see {@link getAgentIb}
|
|
854
|
+
*/
|
|
855
|
+
export function parseAgentIb({
|
|
856
|
+
ib,
|
|
857
|
+
}: {
|
|
858
|
+
ib: Ib,
|
|
859
|
+
}): AgentIbInfo {
|
|
860
|
+
/** getAgentIb must match parseAgentIb. If this array changes, change the other one. */
|
|
861
|
+
const [
|
|
862
|
+
atom,
|
|
863
|
+
name,
|
|
864
|
+
uuid,
|
|
865
|
+
type,
|
|
866
|
+
] = ib.split(' ');
|
|
867
|
+
if (atom !== AGENT_ATOM) { throw new Error(`invalid ib. first term expected to e an atom: ${AGENT_ATOM} (E: 3c01d42035d2e32c4bfd5c1bf363f725)`); }
|
|
868
|
+
if (!name) { throw new Error(`invalid ib. name falsy in agent ib (E: 8b494c544f05b8ef9c866078b761a725)`); }
|
|
869
|
+
if (!uuid) { throw new Error(`invalid ib. uuid falsy in agent ib (E: aba195db3ddcb000324ebed15351b725)`); }
|
|
870
|
+
if (!type) { throw new Error(`invalid ib. type falsy in agent ib (E: 8c814772394ae76342f95e885570c325)`); }
|
|
871
|
+
return { atom, name, uuid, type };
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Validates a comment ibgib to ensure that it is usable in an agent witness
|
|
876
|
+
* context, especially that it includes the expected metadata format in its
|
|
877
|
+
* `ib`.
|
|
878
|
+
*
|
|
879
|
+
* @param {CommentIbGib_V1} ibGib - The comment ibgib to validate.
|
|
880
|
+
* @returns {string[]} An array of error messages if validation fails, or an empty array if no errors.
|
|
881
|
+
*/
|
|
882
|
+
export async function validateAgentWitnessCommentIbGib({
|
|
883
|
+
ibGib,
|
|
884
|
+
}: {
|
|
885
|
+
ibGib: CommentIbGib_V1,
|
|
886
|
+
}): Promise<string[]> {
|
|
887
|
+
const lc = `[${validateAgentWitnessCommentIbGib.name}]`;
|
|
888
|
+
try {
|
|
889
|
+
if (logalot) { console.log(`${lc} starting... (I: f9a733a5a05b7f7494836d86a79e2d25)`); }
|
|
890
|
+
|
|
891
|
+
const errors: string[] = await validateIbGibIntrinsically({ ibGib }) ?? [];
|
|
892
|
+
|
|
893
|
+
if (!isComment({ ibGib })) {
|
|
894
|
+
errors.push(`${lc} not a comment ibgib (E: 08676d94c698c6e42e6c35e94a58f125)`);
|
|
895
|
+
return errors; /* returns early */
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
const { safeIbCommentMetadataText: addlMetadataText } = parseCommentIb({ ib: ibGib.ib });
|
|
899
|
+
|
|
900
|
+
if (addlMetadataText) {
|
|
901
|
+
const addlMetaInfo = parseAddlMetadataTextForAgentText({
|
|
902
|
+
addlMetadataText,
|
|
903
|
+
ifError: 'warn'
|
|
904
|
+
});
|
|
905
|
+
if (addlMetaInfo.errorMsg) {
|
|
906
|
+
errors.push(`${lc} could not parse addlMetadataText: ${addlMetaInfo.errorMsg} (E: e178265c33e5e94947a02c1f9d6a7425)`);
|
|
907
|
+
}
|
|
908
|
+
} else {
|
|
909
|
+
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)`);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
return errors;
|
|
913
|
+
} catch (error) {
|
|
914
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
915
|
+
throw error;
|
|
916
|
+
} finally {
|
|
917
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
918
|
+
}
|
|
919
|
+
}
|