@ibgib/web-gib 0.0.4 → 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.
Files changed (54) 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 +2 -1
  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 +2 -1
  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 +1 -1
  39. package/dist/witness/agent/gemini/gemini-helpers.d.mts.map +1 -1
  40. package/dist/witness/agent/gemini/gemini-types.d.mts +1 -1
  41. package/dist/witness/agent/gemini/gemini-types.d.mts.map +1 -1
  42. package/package.json +1 -1
  43. package/src/api/commands/chat/tell-user.mts +1 -3
  44. package/src/common/settings/settings-constants.mts +4 -1
  45. package/src/helpers.mts +24 -0
  46. package/src/helpers.web.mts +22 -0
  47. package/src/witness/agent/agent-helpers.mts +243 -5
  48. package/src/witness/agent/agent-one-file.mts +8 -473
  49. package/src/witness/agent/agent-types.mts +228 -3
  50. package/src/witness/agent/agents-service-v1.mts +3 -2
  51. package/src/witness/agent/gemini/agent-witness-gemini-v1.mts +5 -2
  52. package/src/witness/agent/gemini/gemini-agent-factory.mts +2 -1
  53. package/src/witness/agent/gemini/gemini-helpers.mts +1 -1
  54. package/src/witness/agent/gemini/gemini-types.mts +1 -1
@@ -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, AgentWitnessIbGib_V1 } from "./agent-one-file.mjs";
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
+ }