@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,15 @@
1
+ import { describe, it, expect } from 'bun:test';
2
+ import { BM25 } from '../search';
3
+
4
+ describe('BM25 search', () => {
5
+ it('indexes documents and finds matches', () => {
6
+ const docs = [
7
+ { text: 'hello world' },
8
+ { text: 'another document' },
9
+ { text: 'world of javascript' },
10
+ ];
11
+ const bm = new BM25(docs, { fieldBoosts: { text: 1 } });
12
+ const results = bm.search('world');
13
+ expect(results[0].index).toBe(0);
14
+ });
15
+ });
@@ -0,0 +1,204 @@
1
+ import { describe, it, expect, beforeEach } from 'bun:test';
2
+ import { AgentRuntime } from '../runtime';
3
+ import { ServiceType, UUID } from '../types';
4
+ import { Service } from '../types/service';
5
+ import { IAgentRuntime } from '../types/runtime';
6
+ import { v4 as uuidv4 } from 'uuid';
7
+
8
+ // Mock service classes for testing
9
+ class MockWalletService1 extends Service {
10
+ static override readonly serviceType = ServiceType.WALLET;
11
+ readonly capabilityDescription = 'Mock wallet service 1';
12
+
13
+ constructor(runtime: IAgentRuntime) {
14
+ super(runtime);
15
+ }
16
+
17
+ static async start(runtime: IAgentRuntime): Promise<MockWalletService1> {
18
+ return new MockWalletService1(runtime);
19
+ }
20
+
21
+ async stop(): Promise<void> {
22
+ // Mock stop implementation
23
+ }
24
+ }
25
+
26
+ class MockWalletService2 extends Service {
27
+ static override readonly serviceType = ServiceType.WALLET;
28
+ readonly capabilityDescription = 'Mock wallet service 2';
29
+
30
+ constructor(runtime: IAgentRuntime) {
31
+ super(runtime);
32
+ }
33
+
34
+ static async start(runtime: IAgentRuntime): Promise<MockWalletService2> {
35
+ return new MockWalletService2(runtime);
36
+ }
37
+
38
+ async stop(): Promise<void> {
39
+ // Mock stop implementation
40
+ }
41
+ }
42
+
43
+ class MockPdfService extends Service {
44
+ static override readonly serviceType = ServiceType.PDF;
45
+ readonly capabilityDescription = 'Mock PDF service';
46
+
47
+ constructor(runtime: IAgentRuntime) {
48
+ super(runtime);
49
+ }
50
+
51
+ static async start(runtime: IAgentRuntime): Promise<MockPdfService> {
52
+ return new MockPdfService(runtime);
53
+ }
54
+
55
+ async stop(): Promise<void> {
56
+ // Mock stop implementation
57
+ }
58
+ }
59
+
60
+ describe('Service Type System', () => {
61
+ let runtime: AgentRuntime;
62
+
63
+ beforeEach(() => {
64
+ runtime = new AgentRuntime({
65
+ agentId: uuidv4() as UUID,
66
+ character: {
67
+ name: 'Test Agent',
68
+ username: 'test',
69
+ clients: [],
70
+ },
71
+ });
72
+ });
73
+
74
+ describe('Multiple services of same type', () => {
75
+ it('should allow registering multiple services of the same type', async () => {
76
+ // Register two wallet services
77
+ await runtime.registerService(MockWalletService1);
78
+ await runtime.registerService(MockWalletService2);
79
+
80
+ // Both should be registered
81
+ expect(runtime.hasService(ServiceType.WALLET)).toBe(true);
82
+
83
+ // Get all wallet services
84
+ const walletServices = runtime.getServicesByType(ServiceType.WALLET);
85
+ expect(walletServices).toHaveLength(2);
86
+
87
+ // Check that both service instances are different
88
+ expect(walletServices[0]).toBeInstanceOf(MockWalletService1);
89
+ expect(walletServices[1]).toBeInstanceOf(MockWalletService2);
90
+ });
91
+
92
+ it('should return first service when using getService', async () => {
93
+ // Register two wallet services
94
+ await runtime.registerService(MockWalletService1);
95
+ await runtime.registerService(MockWalletService2);
96
+
97
+ // getService should return the first registered service
98
+ const firstService = runtime.getService(ServiceType.WALLET);
99
+ expect(firstService).toBeInstanceOf(MockWalletService1);
100
+ });
101
+
102
+ it('should return empty array for non-existent service type', () => {
103
+ const services = runtime.getServicesByType('non-existent-type');
104
+ expect(services).toHaveLength(0);
105
+ });
106
+
107
+ it('should return null for non-existent service type with getService', () => {
108
+ const service = runtime.getService('non-existent-type');
109
+ expect(service).toBe(null);
110
+ });
111
+ });
112
+
113
+ describe('Mixed service types', () => {
114
+ it('should handle multiple service types correctly', async () => {
115
+ // Register services of different types
116
+ await runtime.registerService(MockWalletService1);
117
+ await runtime.registerService(MockWalletService2);
118
+ await runtime.registerService(MockPdfService);
119
+
120
+ // Check wallet services
121
+ const walletServices = runtime.getServicesByType(ServiceType.WALLET);
122
+ expect(walletServices).toHaveLength(2);
123
+
124
+ // Check PDF services
125
+ const pdfServices = runtime.getServicesByType(ServiceType.PDF);
126
+ expect(pdfServices).toHaveLength(1);
127
+ expect(pdfServices[0]).toBeInstanceOf(MockPdfService);
128
+
129
+ // Check non-existent service type
130
+ const videoServices = runtime.getServicesByType(ServiceType.VIDEO);
131
+ expect(videoServices).toHaveLength(0);
132
+ });
133
+
134
+ it('should return correct services with getAllServices', async () => {
135
+ await runtime.registerService(MockWalletService1);
136
+ await runtime.registerService(MockWalletService2);
137
+ await runtime.registerService(MockPdfService);
138
+
139
+ const allServices = runtime.getAllServices();
140
+
141
+ // Should have 2 service types
142
+ expect(allServices.size).toBe(2);
143
+
144
+ // Wallet type should have 2 services
145
+ expect(allServices.get(ServiceType.WALLET)).toHaveLength(2);
146
+
147
+ // PDF type should have 1 service
148
+ expect(allServices.get(ServiceType.PDF)).toHaveLength(1);
149
+ });
150
+ });
151
+
152
+ describe('Service type validation', () => {
153
+ it('should handle hasService correctly with multiple services', async () => {
154
+ expect(runtime.hasService(ServiceType.WALLET)).toBe(false);
155
+
156
+ await runtime.registerService(MockWalletService1);
157
+ expect(runtime.hasService(ServiceType.WALLET)).toBe(true);
158
+
159
+ await runtime.registerService(MockWalletService2);
160
+ expect(runtime.hasService(ServiceType.WALLET)).toBe(true);
161
+ });
162
+
163
+ it('should return correct service types with getRegisteredServiceTypes', async () => {
164
+ await runtime.registerService(MockWalletService1);
165
+ await runtime.registerService(MockPdfService);
166
+
167
+ const serviceTypes = runtime.getRegisteredServiceTypes();
168
+ expect(serviceTypes).toContain(ServiceType.WALLET);
169
+ expect(serviceTypes).toContain(ServiceType.PDF);
170
+ expect(serviceTypes).toHaveLength(2);
171
+ });
172
+ });
173
+
174
+ describe('Service lifecycle', () => {
175
+ it('should stop all services of all types', async () => {
176
+ await runtime.registerService(MockWalletService1);
177
+ await runtime.registerService(MockWalletService2);
178
+ await runtime.registerService(MockPdfService);
179
+
180
+ // Mock the stop methods to track calls
181
+ const stopCalls: string[] = [];
182
+
183
+ const walletServices = runtime.getServicesByType(ServiceType.WALLET);
184
+ const pdfServices = runtime.getServicesByType(ServiceType.PDF);
185
+
186
+ walletServices[0].stop = async () => {
187
+ stopCalls.push('wallet1');
188
+ };
189
+ walletServices[1].stop = async () => {
190
+ stopCalls.push('wallet2');
191
+ };
192
+ pdfServices[0].stop = async () => {
193
+ stopCalls.push('pdf');
194
+ };
195
+
196
+ await runtime.stop();
197
+
198
+ expect(stopCalls).toContain('wallet1');
199
+ expect(stopCalls).toContain('wallet2');
200
+ expect(stopCalls).toContain('pdf');
201
+ expect(stopCalls).toHaveLength(3);
202
+ });
203
+ });
204
+ });
@@ -0,0 +1,136 @@
1
+ import { describe, it, expect, mock } from 'bun:test';
2
+ import { createService, defineService } from '../services';
3
+ import { Service } from '../types';
4
+ import type { IAgentRuntime } from '../types';
5
+
6
+ describe('service builder', () => {
7
+ // Mock runtime
8
+ const mockRuntime = {} as IAgentRuntime;
9
+
10
+ it('createService builds custom class', async () => {
11
+ const Builder = createService('TEST')
12
+ .withDescription('d')
13
+ .withStart(
14
+ async () =>
15
+ new (class extends Service {
16
+ capabilityDescription = 'Test service';
17
+ async stop() {}
18
+ })()
19
+ )
20
+ .build();
21
+ const instance = await (Builder as any).start(mockRuntime);
22
+ expect(instance).toBeInstanceOf(Service);
23
+ await instance.stop();
24
+ });
25
+
26
+ it('defineService builds from definition', async () => {
27
+ const Def = defineService({
28
+ serviceType: 'DEF' as any,
29
+ description: 'desc',
30
+ start: async () =>
31
+ new (class extends Service {
32
+ capabilityDescription = 'Definition service';
33
+ async stop() {}
34
+ })(),
35
+ });
36
+ const instance = await (Def as any).start(mockRuntime);
37
+ expect(instance).toBeInstanceOf(Service);
38
+ await instance.stop();
39
+ });
40
+
41
+ it('should throw error when start function is not defined', async () => {
42
+ // This test covers lines 59-60 - error when startFn is not defined
43
+ const Builder = createService('NO_START').withDescription('Service without start').build();
44
+
45
+ await expect((Builder as any).start(mockRuntime)).rejects.toThrow(
46
+ 'Start function not defined for service NO_START'
47
+ );
48
+ });
49
+
50
+ it('should call custom stop function when provided', async () => {
51
+ // This test covers lines 65-68 - custom stopFn execution
52
+ const stopFn = mock().mockResolvedValue(undefined);
53
+
54
+ const Builder = createService('WITH_STOP')
55
+ .withDescription('Service with custom stop')
56
+ .withStart(
57
+ async () =>
58
+ new (class extends Service {
59
+ capabilityDescription = 'Service with stop';
60
+ async stop() {}
61
+ })()
62
+ )
63
+ .withStop(stopFn)
64
+ .build();
65
+
66
+ await (Builder as any).start(mockRuntime);
67
+ const builtInstance = new Builder();
68
+ await builtInstance.stop();
69
+
70
+ expect(stopFn).toHaveBeenCalled();
71
+ });
72
+
73
+ it('should handle service without stop function', async () => {
74
+ // This test ensures the else branch (no stopFn) is covered
75
+ const Builder = createService('NO_STOP')
76
+ .withDescription('Service without custom stop')
77
+ .withStart(
78
+ async () =>
79
+ new (class extends Service {
80
+ capabilityDescription = 'Service without stop';
81
+ async stop() {}
82
+ })()
83
+ )
84
+ .build();
85
+
86
+ const builtInstance = new Builder();
87
+ // Should not throw when no stopFn is provided
88
+ await expect(builtInstance.stop()).resolves.toBeUndefined();
89
+ });
90
+
91
+ it('defineService should provide default stop function', async () => {
92
+ // This test covers the default stop function in defineService
93
+ const Def = defineService({
94
+ serviceType: 'DEF_NO_STOP' as any,
95
+ description: 'Definition without stop',
96
+ start: async () =>
97
+ new (class extends Service {
98
+ capabilityDescription = 'Definition without stop';
99
+ async stop() {}
100
+ })(),
101
+ // Note: no stop function provided
102
+ });
103
+
104
+ await (Def as any).start(mockRuntime);
105
+ const defInstance = new Def();
106
+ // Should not throw when using default stop
107
+ expect(defInstance.stop()).resolves.toBeUndefined();
108
+ });
109
+
110
+ it('should set all properties correctly with chaining', () => {
111
+ // Test the full builder chain
112
+ const description = 'Test service description';
113
+ const serviceType = 'CHAINED_SERVICE';
114
+
115
+ const builder = createService(serviceType);
116
+ const withDesc = builder.withDescription(description);
117
+
118
+ // Verify chaining returns the same instance
119
+ expect(withDesc).toBe(builder);
120
+
121
+ const startFn = async () =>
122
+ new (class extends Service {
123
+ capabilityDescription = 'Chained service';
124
+ async stop() {}
125
+ })();
126
+ const withStart = withDesc.withStart(startFn);
127
+ expect(withStart).toBe(builder);
128
+
129
+ const stopFn = async () => {};
130
+ const withStop = withStart.withStop(stopFn);
131
+ expect(withStop).toBe(builder);
132
+
133
+ const BuiltClass = withStop.build();
134
+ expect((BuiltClass as any).serviceType).toBe(serviceType);
135
+ });
136
+ });