@elizaos/core 1.5.1 → 1.5.2

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 (88) hide show
  1. package/dist/browser/index.browser.js +120 -120
  2. package/dist/browser/index.browser.js.map +5 -21
  3. package/dist/browser/index.d.ts +3 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +1 -5
  6. package/dist/node/index.d.ts +3 -1
  7. package/package.json +10 -4
  8. package/src/__tests__/action-chaining-simple.test.ts +203 -0
  9. package/src/__tests__/actions.test.ts +218 -0
  10. package/src/__tests__/buffer.test.ts +337 -0
  11. package/src/__tests__/character-validation.test.ts +309 -0
  12. package/src/__tests__/database.test.ts +750 -0
  13. package/src/__tests__/entities.test.ts +727 -0
  14. package/src/__tests__/env.test.ts +23 -0
  15. package/src/__tests__/environment.test.ts +285 -0
  16. package/src/__tests__/logger-browser-node.test.ts +716 -0
  17. package/src/__tests__/logger.test.ts +403 -0
  18. package/src/__tests__/messages.test.ts +196 -0
  19. package/src/__tests__/mockCharacter.ts +544 -0
  20. package/src/__tests__/parsing.test.ts +58 -0
  21. package/src/__tests__/prompts.test.ts +159 -0
  22. package/src/__tests__/roles.test.ts +331 -0
  23. package/src/__tests__/runtime-embedding.test.ts +343 -0
  24. package/src/__tests__/runtime.test.ts +978 -0
  25. package/src/__tests__/search.test.ts +15 -0
  26. package/src/__tests__/services-by-type.test.ts +204 -0
  27. package/src/__tests__/services.test.ts +136 -0
  28. package/src/__tests__/settings.test.ts +810 -0
  29. package/src/__tests__/utils.test.ts +1105 -0
  30. package/src/__tests__/uuid.test.ts +94 -0
  31. package/src/actions.ts +122 -0
  32. package/src/database.ts +579 -0
  33. package/src/entities.ts +406 -0
  34. package/src/index.browser.ts +48 -0
  35. package/src/index.node.ts +39 -0
  36. package/src/index.ts +50 -0
  37. package/src/logger.ts +527 -0
  38. package/src/prompts.ts +243 -0
  39. package/src/roles.ts +85 -0
  40. package/src/runtime.ts +2514 -0
  41. package/src/schemas/character.ts +149 -0
  42. package/src/search.ts +1543 -0
  43. package/src/sentry/instrument.browser.ts +65 -0
  44. package/src/sentry/instrument.node.ts +57 -0
  45. package/src/sentry/instrument.ts +82 -0
  46. package/src/services.ts +105 -0
  47. package/src/settings.ts +409 -0
  48. package/src/test_resources/constants.ts +12 -0
  49. package/src/test_resources/testSetup.ts +21 -0
  50. package/src/test_resources/types.ts +22 -0
  51. package/src/types/agent.ts +112 -0
  52. package/src/types/browser.ts +145 -0
  53. package/src/types/components.ts +184 -0
  54. package/src/types/database.ts +348 -0
  55. package/src/types/email.ts +162 -0
  56. package/src/types/environment.ts +129 -0
  57. package/src/types/events.ts +249 -0
  58. package/src/types/index.ts +29 -0
  59. package/src/types/knowledge.ts +65 -0
  60. package/src/types/lp.ts +124 -0
  61. package/src/types/memory.ts +228 -0
  62. package/src/types/message.ts +233 -0
  63. package/src/types/messaging.ts +57 -0
  64. package/src/types/model.ts +359 -0
  65. package/src/types/pdf.ts +77 -0
  66. package/src/types/plugin.ts +78 -0
  67. package/src/types/post.ts +271 -0
  68. package/src/types/primitives.ts +97 -0
  69. package/src/types/runtime.ts +190 -0
  70. package/src/types/service.ts +198 -0
  71. package/src/types/settings.ts +30 -0
  72. package/src/types/state.ts +60 -0
  73. package/src/types/task.ts +72 -0
  74. package/src/types/tee.ts +107 -0
  75. package/src/types/testing.ts +30 -0
  76. package/src/types/token.ts +96 -0
  77. package/src/types/transcription.ts +133 -0
  78. package/src/types/video.ts +108 -0
  79. package/src/types/wallet.ts +56 -0
  80. package/src/types/web-search.ts +146 -0
  81. package/src/utils/__tests__/buffer.test.ts +80 -0
  82. package/src/utils/__tests__/environment.test.ts +58 -0
  83. package/src/utils/__tests__/stringToUuid.test.ts +88 -0
  84. package/src/utils/buffer.ts +312 -0
  85. package/src/utils/environment.ts +316 -0
  86. package/src/utils/server-health.ts +117 -0
  87. package/src/utils.ts +1076 -0
  88. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,94 @@
1
+ import { beforeEach, describe, expect, it } from 'bun:test';
2
+ import type { UUID } from '../types';
3
+ import { stringToUuid } from '../utils';
4
+
5
+ describe('UUID Module', () => {
6
+ // Helper function to generate test strings
7
+ const generateTestString = (): string => Math.random().toString(36).substring(7);
8
+
9
+ // Test data setup
10
+ let testString: string;
11
+ let testNumber: number;
12
+
13
+ beforeEach(() => {
14
+ testString = generateTestString();
15
+ testNumber = Math.floor(Math.random() * 1000);
16
+ });
17
+
18
+ describe('stringToUuid', () => {
19
+ it('should generate a valid UUID matching the standard format', () => {
20
+ const result = stringToUuid(testString) as UUID;
21
+ expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
22
+ });
23
+
24
+ it('should generate consistent UUIDs for identical inputs', () => {
25
+ const input = testString;
26
+ const uuid1 = stringToUuid(input) as UUID;
27
+ const uuid2 = stringToUuid(input) as UUID;
28
+ expect(uuid1).toBe(uuid2);
29
+ });
30
+
31
+ it('should generate unique UUIDs for different inputs', () => {
32
+ const input1 = testString;
33
+ const input2 = generateTestString();
34
+ const uuid1 = stringToUuid(input1) as UUID;
35
+ const uuid2 = stringToUuid(input2) as UUID;
36
+ expect(uuid1).not.toBe(uuid2);
37
+ });
38
+
39
+ describe('input handling', () => {
40
+ it('should convert number inputs to strings correctly', () => {
41
+ const numberUuid = stringToUuid(testNumber) as UUID;
42
+ const stringUuid = stringToUuid(testNumber.toString()) as UUID;
43
+ expect(numberUuid).toBe(stringUuid);
44
+ });
45
+
46
+ it('should throw TypeError for invalid input types', () => {
47
+ expect(() => stringToUuid(undefined as any)).toThrow(TypeError);
48
+ expect(() => stringToUuid(null as any)).toThrow(TypeError);
49
+ expect(() => stringToUuid({} as any)).toThrow(TypeError);
50
+ });
51
+
52
+ it('should handle empty string input', () => {
53
+ const result = stringToUuid('') as UUID;
54
+ expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
55
+ });
56
+
57
+ it('should handle Unicode characters and emojis consistently', () => {
58
+ const unicodeInput = 'Hello 世界! 🌍';
59
+ const result1 = stringToUuid(unicodeInput) as UUID;
60
+ const result2 = stringToUuid(unicodeInput) as UUID;
61
+ expect(result1).toBe(result2);
62
+ expect(result1).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
63
+ });
64
+ });
65
+
66
+ describe('UUID version and variant bits', () => {
67
+ it('should set correct version bits (version 5)', () => {
68
+ const uuid = stringToUuid(testString) as UUID;
69
+ const versionChar = uuid.split('-')[2][0];
70
+ expect(versionChar).toBe('0');
71
+ });
72
+
73
+ it('should set correct variant bits (RFC4122)', () => {
74
+ const uuid = stringToUuid(testString) as UUID;
75
+ const variantByte = Number.parseInt(uuid.split('-')[3].slice(0, 2), 16);
76
+ expect(variantByte >= 0x80 && variantByte <= 0xbf).toBe(true);
77
+ });
78
+ });
79
+
80
+ describe('encoding handling', () => {
81
+ it('should handle URL-unsafe characters', () => {
82
+ const urlUnsafeInput = 'test?query=value&param=123';
83
+ const result = stringToUuid(urlUnsafeInput) as UUID;
84
+ expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
85
+ });
86
+
87
+ it('should handle very long inputs', () => {
88
+ const longInput = 'a'.repeat(1000);
89
+ const result = stringToUuid(longInput) as UUID;
90
+ expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
91
+ });
92
+ });
93
+ });
94
+ });
package/src/actions.ts ADDED
@@ -0,0 +1,122 @@
1
+ import { names, uniqueNamesGenerator } from 'unique-names-generator';
2
+ import type { Action, ActionExample } from './types';
3
+
4
+ /**
5
+ * Composes a set of example conversations based on provided actions and a specified count.
6
+ * It randomly selects examples from the provided actions and formats them with generated names.
7
+ *
8
+ * @param actionsData - An array of `Action` objects from which to draw examples.
9
+ * @param count - The number of examples to generate.
10
+ * @returns A string containing formatted examples of conversations.
11
+ */
12
+ export const composeActionExamples = (actionsData: Action[], count: number): string => {
13
+ // Handle edge cases
14
+ if (!actionsData.length || count <= 0) {
15
+ return '';
16
+ }
17
+
18
+ // Filter out actions without examples
19
+ const actionsWithExamples = actionsData.filter(
20
+ (action) => action.examples && Array.isArray(action.examples) && action.examples.length > 0
21
+ );
22
+
23
+ // If no actions have examples, return empty string
24
+ if (!actionsWithExamples.length) {
25
+ return '';
26
+ }
27
+
28
+ // Create a working copy of the examples
29
+ const examplesCopy: ActionExample[][][] = actionsWithExamples.map((action) => [
30
+ ...(action.examples || []),
31
+ ]);
32
+
33
+ const selectedExamples: ActionExample[][] = [];
34
+
35
+ // Keep track of actions that still have examples
36
+ let availableActionIndices = examplesCopy
37
+ .map((examples, index) => (examples.length > 0 ? index : -1))
38
+ .filter((index) => index !== -1);
39
+
40
+ // Select examples until we reach the count or run out of examples
41
+ while (selectedExamples.length < count && availableActionIndices.length > 0) {
42
+ // Randomly select an action
43
+ const randomIndex = Math.floor(Math.random() * availableActionIndices.length);
44
+ const actionIndex = availableActionIndices[randomIndex];
45
+ const examples = examplesCopy[actionIndex];
46
+
47
+ // Select a random example from this action
48
+ const exampleIndex = Math.floor(Math.random() * examples.length);
49
+ selectedExamples.push(examples.splice(exampleIndex, 1)[0]);
50
+
51
+ // Remove action if it has no more examples
52
+ if (examples.length === 0) {
53
+ availableActionIndices.splice(randomIndex, 1);
54
+ }
55
+ }
56
+
57
+ // Format the selected examples
58
+ return formatSelectedExamples(selectedExamples);
59
+ };
60
+
61
+ /**
62
+ * Formats selected example conversations with random names.
63
+ */
64
+ const formatSelectedExamples = (examples: ActionExample[][]): string => {
65
+ const MAX_NAME_PLACEHOLDERS = 5;
66
+
67
+ return examples
68
+ .map((example) => {
69
+ // Generate random names for this example
70
+ const randomNames = Array.from({ length: MAX_NAME_PLACEHOLDERS }, () =>
71
+ uniqueNamesGenerator({ dictionaries: [names] })
72
+ );
73
+
74
+ // Format the conversation
75
+ const conversation = example
76
+ .map((message) => {
77
+ // Build the base message - only include the text, no action info
78
+ let messageText = `${message.name}: ${message.content.text}`;
79
+
80
+ // Replace name placeholders
81
+ for (let i = 0; i < randomNames.length; i++) {
82
+ messageText = messageText.replaceAll(`{{name${i + 1}}}`, randomNames[i]);
83
+ }
84
+
85
+ return messageText;
86
+ })
87
+ .join('\n');
88
+
89
+ return `\n${conversation}`;
90
+ })
91
+ .join('\n');
92
+ };
93
+
94
+ /**
95
+ * Formats the names of the provided actions into a comma-separated string.
96
+ * @param actions - An array of `Action` objects from which to extract names.
97
+ * @returns A comma-separated string of action names.
98
+ */
99
+ export function formatActionNames(actions: Action[]): string {
100
+ if (!actions?.length) return '';
101
+
102
+ // Create a shuffled copy instead of mutating the original array
103
+ return [...actions]
104
+ .sort(() => Math.random() - 0.5)
105
+ .map((action) => action.name)
106
+ .join(', ');
107
+ }
108
+
109
+ /**
110
+ * Formats the provided actions into a detailed string listing each action's name and description.
111
+ * @param actions - An array of `Action` objects to format.
112
+ * @returns A detailed string of actions, including names and descriptions.
113
+ */
114
+ export function formatActions(actions: Action[]): string {
115
+ if (!actions?.length) return '';
116
+
117
+ // Create a shuffled copy without mutating the original
118
+ return [...actions]
119
+ .sort(() => Math.random() - 0.5)
120
+ .map((action) => `- **${action.name}**: ${action.description || 'No description available'}`)
121
+ .join('\n');
122
+ }