@elizaos/core 1.5.4 → 1.5.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 (90) hide show
  1. package/README.md +0 -15
  2. package/dist/index.d.ts +4886 -3
  3. package/dist/index.js +5287 -4
  4. package/package.json +21 -39
  5. package/dist/browser/index.browser.js +0 -1109
  6. package/dist/browser/index.browser.js.map +0 -707
  7. package/dist/browser/index.d.ts +0 -3
  8. package/dist/node/index.d.ts +0 -3
  9. package/dist/node/index.node.js +0 -74530
  10. package/dist/node/index.node.js.map +0 -1027
  11. package/src/__tests__/action-chaining-simple.test.ts +0 -203
  12. package/src/__tests__/actions.test.ts +0 -218
  13. package/src/__tests__/buffer.test.ts +0 -337
  14. package/src/__tests__/character-validation.test.ts +0 -309
  15. package/src/__tests__/database.test.ts +0 -750
  16. package/src/__tests__/entities.test.ts +0 -727
  17. package/src/__tests__/env.test.ts +0 -23
  18. package/src/__tests__/environment.test.ts +0 -285
  19. package/src/__tests__/logger-browser-node.test.ts +0 -716
  20. package/src/__tests__/logger.test.ts +0 -403
  21. package/src/__tests__/messages.test.ts +0 -196
  22. package/src/__tests__/mockCharacter.ts +0 -544
  23. package/src/__tests__/parsing.test.ts +0 -58
  24. package/src/__tests__/prompts.test.ts +0 -159
  25. package/src/__tests__/roles.test.ts +0 -331
  26. package/src/__tests__/runtime-embedding.test.ts +0 -343
  27. package/src/__tests__/runtime.test.ts +0 -978
  28. package/src/__tests__/search.test.ts +0 -15
  29. package/src/__tests__/services-by-type.test.ts +0 -204
  30. package/src/__tests__/services.test.ts +0 -136
  31. package/src/__tests__/settings.test.ts +0 -810
  32. package/src/__tests__/utils.test.ts +0 -1105
  33. package/src/__tests__/uuid.test.ts +0 -94
  34. package/src/actions.ts +0 -122
  35. package/src/database.ts +0 -579
  36. package/src/entities.ts +0 -406
  37. package/src/index.browser.ts +0 -48
  38. package/src/index.node.ts +0 -39
  39. package/src/index.ts +0 -50
  40. package/src/logger.ts +0 -527
  41. package/src/prompts.ts +0 -243
  42. package/src/roles.ts +0 -85
  43. package/src/runtime.ts +0 -2514
  44. package/src/schemas/character.ts +0 -149
  45. package/src/search.ts +0 -1543
  46. package/src/sentry/instrument.browser.ts +0 -65
  47. package/src/sentry/instrument.node.ts +0 -57
  48. package/src/sentry/instrument.ts +0 -82
  49. package/src/services.ts +0 -105
  50. package/src/settings.ts +0 -409
  51. package/src/test_resources/constants.ts +0 -12
  52. package/src/test_resources/testSetup.ts +0 -21
  53. package/src/test_resources/types.ts +0 -22
  54. package/src/types/agent.ts +0 -112
  55. package/src/types/browser.ts +0 -145
  56. package/src/types/components.ts +0 -184
  57. package/src/types/database.ts +0 -348
  58. package/src/types/email.ts +0 -162
  59. package/src/types/environment.ts +0 -129
  60. package/src/types/events.ts +0 -249
  61. package/src/types/index.ts +0 -29
  62. package/src/types/knowledge.ts +0 -65
  63. package/src/types/lp.ts +0 -124
  64. package/src/types/memory.ts +0 -228
  65. package/src/types/message.ts +0 -233
  66. package/src/types/messaging.ts +0 -57
  67. package/src/types/model.ts +0 -359
  68. package/src/types/pdf.ts +0 -77
  69. package/src/types/plugin.ts +0 -78
  70. package/src/types/post.ts +0 -271
  71. package/src/types/primitives.ts +0 -97
  72. package/src/types/runtime.ts +0 -190
  73. package/src/types/service.ts +0 -198
  74. package/src/types/settings.ts +0 -30
  75. package/src/types/state.ts +0 -60
  76. package/src/types/task.ts +0 -72
  77. package/src/types/tee.ts +0 -107
  78. package/src/types/testing.ts +0 -30
  79. package/src/types/token.ts +0 -96
  80. package/src/types/transcription.ts +0 -133
  81. package/src/types/video.ts +0 -108
  82. package/src/types/wallet.ts +0 -56
  83. package/src/types/web-search.ts +0 -146
  84. package/src/utils/__tests__/buffer.test.ts +0 -80
  85. package/src/utils/__tests__/environment.test.ts +0 -58
  86. package/src/utils/__tests__/stringToUuid.test.ts +0 -88
  87. package/src/utils/buffer.ts +0 -312
  88. package/src/utils/environment.ts +0 -316
  89. package/src/utils/server-health.ts +0 -117
  90. package/src/utils.ts +0 -1076
@@ -1,312 +0,0 @@
1
- /**
2
- * Browser and Node.js compatible buffer abstraction
3
- * This module provides a unified interface for buffer operations
4
- * that works in both browser and Node.js environments.
5
- *
6
- * In browsers, we use Uint8Array as a Buffer replacement.
7
- * In Node.js, we use the native Buffer.
8
- */
9
-
10
- /**
11
- * Type representing a buffer-like object that works in both environments
12
- */
13
- export type BufferLike = Buffer | Uint8Array;
14
-
15
- /**
16
- * Check if we're in a Node.js environment with Buffer support
17
- */
18
- function hasNativeBuffer(): boolean {
19
- return typeof Buffer !== 'undefined' && typeof Buffer.from === 'function';
20
- }
21
-
22
- /**
23
- * Convert a hex string to a buffer-like object
24
- * @param hex - The hexadecimal string to convert
25
- * @returns A BufferLike object
26
- */
27
- export function fromHex(hex: string): BufferLike {
28
- // Clean the hex string to remove non-hex characters
29
- const cleanHex = hex.replace(/[^0-9a-fA-F]/g, '');
30
-
31
- if (hasNativeBuffer()) {
32
- // Use native Buffer in Node.js
33
- return Buffer.from(cleanHex, 'hex');
34
- }
35
-
36
- // Browser implementation using Uint8Array
37
- const bytes = new Uint8Array(cleanHex.length / 2);
38
-
39
- for (let i = 0; i < bytes.length; i++) {
40
- bytes[i] = parseInt(cleanHex.substr(i * 2, 2), 16);
41
- }
42
-
43
- return bytes;
44
- }
45
-
46
- /**
47
- * Convert a string to a buffer-like object
48
- * @param str - The string to convert
49
- * @param encoding - The encoding to use (default: 'utf8')
50
- * @returns A BufferLike object
51
- */
52
- export function fromString(
53
- str: string,
54
- encoding: 'utf8' | 'utf-8' | 'base64' = 'utf8'
55
- ): BufferLike {
56
- if (hasNativeBuffer()) {
57
- // Use native Buffer in Node.js
58
- const enc = encoding === 'utf-8' ? 'utf8' : encoding;
59
- return Buffer.from(str, enc as BufferEncoding);
60
- }
61
-
62
- // Browser implementation
63
- if (encoding === 'base64') {
64
- // Decode base64 string
65
- const binaryString = atob(str);
66
- const bytes = new Uint8Array(binaryString.length);
67
- for (let i = 0; i < binaryString.length; i++) {
68
- bytes[i] = binaryString.charCodeAt(i);
69
- }
70
- return bytes;
71
- }
72
-
73
- // UTF-8 encoding using TextEncoder (standard browser API)
74
- const encoder = new TextEncoder();
75
- return encoder.encode(str);
76
- }
77
-
78
- /**
79
- * Convert a buffer-like object to a hexadecimal string
80
- * @param buffer - The buffer to convert
81
- * @returns A hexadecimal string
82
- */
83
- export function toHex(buffer: BufferLike): string {
84
- if (hasNativeBuffer() && Buffer.isBuffer(buffer)) {
85
- // Use native Buffer method in Node.js
86
- return buffer.toString('hex');
87
- }
88
-
89
- // Browser implementation
90
- const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
91
- let hex = '';
92
- for (let i = 0; i < bytes.length; i++) {
93
- const byte = bytes[i].toString(16);
94
- hex += byte.length === 1 ? '0' + byte : byte;
95
- }
96
- return hex;
97
- }
98
-
99
- /**
100
- * Convert a buffer-like object to a string
101
- * @param buffer - The buffer to convert
102
- * @param encoding - The encoding to use (default: 'utf8')
103
- * @returns A string
104
- */
105
- export function toString(
106
- buffer: BufferLike,
107
- encoding: 'utf8' | 'utf-8' | 'base64' | 'hex' = 'utf8'
108
- ): string {
109
- if (hasNativeBuffer() && Buffer.isBuffer(buffer)) {
110
- // Use native Buffer method in Node.js
111
- const enc = encoding === 'utf-8' ? 'utf8' : encoding;
112
- return buffer.toString(enc as BufferEncoding);
113
- }
114
-
115
- const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
116
-
117
- // Handle different encodings
118
- if (encoding === 'hex') {
119
- return toHex(bytes);
120
- }
121
-
122
- if (encoding === 'base64') {
123
- // Convert to base64
124
- let binaryString = '';
125
- for (let i = 0; i < bytes.length; i++) {
126
- binaryString += String.fromCharCode(bytes[i]);
127
- }
128
- return btoa(binaryString);
129
- }
130
-
131
- // UTF-8 decoding using TextDecoder (standard browser API)
132
- const decoder = new TextDecoder();
133
- return decoder.decode(bytes);
134
- }
135
-
136
- /**
137
- * Check if an object is a Buffer or buffer-like object
138
- * @param obj - The object to check
139
- * @returns True if the object is buffer-like
140
- */
141
- export function isBuffer(obj: any): obj is BufferLike {
142
- if (!obj) {
143
- return false;
144
- }
145
-
146
- if (hasNativeBuffer() && Buffer.isBuffer(obj)) {
147
- return true;
148
- }
149
-
150
- // Check for Uint8Array or similar typed arrays
151
- return (
152
- obj instanceof Uint8Array ||
153
- obj instanceof ArrayBuffer ||
154
- (typeof obj === 'object' &&
155
- obj.buffer instanceof ArrayBuffer &&
156
- typeof obj.byteLength === 'number' &&
157
- !Array.isArray(obj))
158
- );
159
- }
160
-
161
- /**
162
- * Create a buffer of a specific size filled with zeros
163
- * @param size - The size of the buffer
164
- * @returns A BufferLike object
165
- */
166
- export function alloc(size: number): BufferLike {
167
- if (hasNativeBuffer()) {
168
- return Buffer.alloc(size);
169
- }
170
-
171
- return new Uint8Array(size);
172
- }
173
-
174
- /**
175
- * Create a buffer from an array of bytes
176
- * @param bytes - Array of byte values
177
- * @returns A BufferLike object
178
- */
179
- export function fromBytes(bytes: number[] | Uint8Array): BufferLike {
180
- if (hasNativeBuffer()) {
181
- return Buffer.from(bytes);
182
- }
183
-
184
- return new Uint8Array(bytes);
185
- }
186
-
187
- /**
188
- * Concatenate multiple buffers
189
- * @param buffers - Array of buffers to concatenate
190
- * @returns A new BufferLike object
191
- */
192
- export function concat(buffers: BufferLike[]): BufferLike {
193
- if (hasNativeBuffer() && buffers.every((b) => Buffer.isBuffer(b))) {
194
- return Buffer.concat(buffers as Buffer[]);
195
- }
196
-
197
- // Calculate total length
198
- let totalLength = 0;
199
- for (const buffer of buffers) {
200
- totalLength += buffer.length;
201
- }
202
-
203
- // Create result buffer
204
- const result = new Uint8Array(totalLength);
205
- let offset = 0;
206
-
207
- for (const buffer of buffers) {
208
- const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
209
- result.set(bytes, offset);
210
- offset += bytes.length;
211
- }
212
-
213
- return result;
214
- }
215
-
216
- /**
217
- * Slice a buffer to create a new buffer
218
- * @param buffer - The buffer to slice
219
- * @param start - Start index
220
- * @param end - End index (optional)
221
- * @returns A new BufferLike object
222
- */
223
- export function slice(buffer: BufferLike, start: number, end?: number): BufferLike {
224
- if (hasNativeBuffer() && Buffer.isBuffer(buffer)) {
225
- return buffer.slice(start, end);
226
- }
227
-
228
- const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
229
- return bytes.slice(start, end);
230
- }
231
-
232
- /**
233
- * Compare two buffers for equality
234
- * @param a - First buffer
235
- * @param b - Second buffer
236
- * @returns True if buffers are equal
237
- */
238
- export function equals(a: BufferLike, b: BufferLike): boolean {
239
- if (a.length !== b.length) {
240
- return false;
241
- }
242
-
243
- const bytesA = a instanceof Uint8Array ? a : new Uint8Array(a);
244
- const bytesB = b instanceof Uint8Array ? b : new Uint8Array(b);
245
-
246
- for (let i = 0; i < bytesA.length; i++) {
247
- if (bytesA[i] !== bytesB[i]) {
248
- return false;
249
- }
250
- }
251
-
252
- return true;
253
- }
254
-
255
- /**
256
- * Get the byte length of a buffer
257
- * @param buffer - The buffer
258
- * @returns The byte length
259
- */
260
- export function byteLength(buffer: BufferLike): number {
261
- return buffer.length;
262
- }
263
-
264
- /**
265
- * Create a random buffer of specified size
266
- * @param size - The size of the buffer
267
- * @returns A BufferLike object filled with random bytes
268
- */
269
- export function randomBytes(size: number): BufferLike {
270
- if (hasNativeBuffer()) {
271
- // In Node.js, use crypto.randomBytes if available
272
- try {
273
- const crypto = require('crypto');
274
- return crypto.randomBytes(size);
275
- } catch {
276
- // Fall back to manual generation
277
- }
278
- }
279
-
280
- // Browser implementation using crypto.getRandomValues
281
- const bytes = new Uint8Array(size);
282
-
283
- if (typeof globalThis !== 'undefined' && globalThis.crypto && globalThis.crypto.getRandomValues) {
284
- globalThis.crypto.getRandomValues(bytes);
285
- } else {
286
- // Fallback: less secure random generation
287
- for (let i = 0; i < size; i++) {
288
- bytes[i] = Math.floor(Math.random() * 256);
289
- }
290
- }
291
-
292
- return bytes;
293
- }
294
-
295
- // Export a namespace-like object for compatibility
296
- export const BufferUtils = {
297
- fromHex,
298
- fromString,
299
- fromBytes,
300
- toHex,
301
- toString,
302
- isBuffer,
303
- alloc,
304
- concat,
305
- slice,
306
- equals,
307
- byteLength,
308
- randomBytes,
309
- };
310
-
311
- // Export type for use in other modules
312
- export type { BufferLike as Buffer };
@@ -1,316 +0,0 @@
1
- /**
2
- * Browser and Node.js compatible environment variable abstraction
3
- * This module provides a unified interface for accessing environment variables
4
- * that works in both browser and Node.js environments.
5
- */
6
-
7
- /**
8
- * Type representing the runtime environment
9
- */
10
- export type RuntimeEnvironment = 'node' | 'browser' | 'unknown';
11
-
12
- /**
13
- * Interface for environment configuration
14
- */
15
- export interface EnvironmentConfig {
16
- [key: string]: string | boolean | number | undefined;
17
- }
18
-
19
- /**
20
- * Detect the current runtime environment
21
- */
22
- export function detectEnvironment(): RuntimeEnvironment {
23
- // Check for Node.js
24
- if (typeof process !== 'undefined' && process.versions && process.versions.node) {
25
- return 'node';
26
- }
27
-
28
- // Check for browser
29
- if (
30
- typeof globalThis !== 'undefined' &&
31
- typeof (globalThis as any).window !== 'undefined' &&
32
- typeof (globalThis as any).window.document !== 'undefined'
33
- ) {
34
- return 'browser';
35
- }
36
-
37
- return 'unknown';
38
- }
39
-
40
- /**
41
- * Environment variable storage for browser environments
42
- */
43
- class BrowserEnvironmentStore {
44
- private store: EnvironmentConfig = {};
45
-
46
- constructor() {
47
- // Load from window.ENV if available (common pattern for browser apps)
48
- if (
49
- typeof globalThis !== 'undefined' &&
50
- (globalThis as any).window &&
51
- (globalThis as any).window.ENV
52
- ) {
53
- this.store = { ...(globalThis as any).window.ENV };
54
- }
55
-
56
- // Also check for __ENV__ (another common pattern)
57
- if (typeof globalThis !== 'undefined' && (globalThis as any).__ENV__) {
58
- this.store = { ...this.store, ...(globalThis as any).__ENV__ };
59
- }
60
- }
61
-
62
- get(key: string): string | undefined {
63
- const value = this.store[key];
64
- return value !== undefined ? String(value) : undefined;
65
- }
66
-
67
- set(key: string, value: string | boolean | number): void {
68
- this.store[key] = value;
69
- }
70
-
71
- has(key: string): boolean {
72
- return key in this.store;
73
- }
74
-
75
- getAll(): EnvironmentConfig {
76
- return { ...this.store };
77
- }
78
- }
79
-
80
- /**
81
- * Environment abstraction class
82
- */
83
- class Environment {
84
- private runtime: RuntimeEnvironment;
85
- private browserStore?: BrowserEnvironmentStore;
86
- private cache: Map<string, string | undefined> = new Map();
87
-
88
- constructor() {
89
- this.runtime = detectEnvironment();
90
-
91
- if (this.runtime === 'browser') {
92
- this.browserStore = new BrowserEnvironmentStore();
93
- }
94
- }
95
-
96
- /**
97
- * Get the current runtime environment
98
- */
99
- getRuntime(): RuntimeEnvironment {
100
- return this.runtime;
101
- }
102
-
103
- /**
104
- * Check if running in Node.js
105
- */
106
- isNode(): boolean {
107
- return this.runtime === 'node';
108
- }
109
-
110
- /**
111
- * Check if running in browser
112
- */
113
- isBrowser(): boolean {
114
- return this.runtime === 'browser';
115
- }
116
-
117
- /**
118
- * Get an environment variable
119
- */
120
- get(key: string, defaultValue?: string): string | undefined {
121
- // Check cache first
122
- if (this.cache.has(key)) {
123
- const cached = this.cache.get(key);
124
- return cached === undefined && defaultValue !== undefined ? defaultValue : cached;
125
- }
126
-
127
- let value: string | undefined;
128
-
129
- switch (this.runtime) {
130
- case 'node':
131
- // In Node.js, use process.env
132
- if (typeof process !== 'undefined' && process.env) {
133
- value = process.env[key];
134
- }
135
- break;
136
-
137
- case 'browser':
138
- // In browser, use our store
139
- if (this.browserStore) {
140
- value = this.browserStore.get(key);
141
- }
142
- break;
143
-
144
- default:
145
- value = undefined;
146
- }
147
-
148
- // Cache the result
149
- this.cache.set(key, value);
150
-
151
- return value === undefined && defaultValue !== undefined ? defaultValue : value;
152
- }
153
-
154
- /**
155
- * Set an environment variable (mainly for browser/testing)
156
- */
157
- set(key: string, value: string | boolean | number): void {
158
- const stringValue = String(value);
159
-
160
- // Clear cache
161
- this.cache.delete(key);
162
-
163
- switch (this.runtime) {
164
- case 'node':
165
- if (typeof process !== 'undefined' && process.env) {
166
- process.env[key] = stringValue;
167
- }
168
- break;
169
-
170
- case 'browser':
171
- if (this.browserStore) {
172
- this.browserStore.set(key, value);
173
- }
174
- break;
175
- }
176
- }
177
-
178
- /**
179
- * Check if an environment variable exists
180
- */
181
- has(key: string): boolean {
182
- const value = this.get(key);
183
- return value !== undefined;
184
- }
185
-
186
- /**
187
- * Get all environment variables (filtered for safety)
188
- */
189
- getAll(): EnvironmentConfig {
190
- switch (this.runtime) {
191
- case 'node':
192
- if (typeof process !== 'undefined' && process.env) {
193
- return { ...process.env };
194
- }
195
- break;
196
-
197
- case 'browser':
198
- if (this.browserStore) {
199
- return this.browserStore.getAll();
200
- }
201
- break;
202
- }
203
-
204
- return {};
205
- }
206
-
207
- /**
208
- * Get a boolean environment variable
209
- */
210
- getBoolean(key: string, defaultValue = false): boolean {
211
- const value = this.get(key);
212
-
213
- if (value === undefined) {
214
- return defaultValue;
215
- }
216
-
217
- // Common truthy values
218
- return ['true', '1', 'yes', 'on'].includes(value.toLowerCase());
219
- }
220
-
221
- /**
222
- * Get a number environment variable
223
- */
224
- getNumber(key: string, defaultValue?: number): number | undefined {
225
- const value = this.get(key);
226
-
227
- if (value === undefined) {
228
- return defaultValue;
229
- }
230
-
231
- const parsed = Number(value);
232
- return isNaN(parsed) ? defaultValue : parsed;
233
- }
234
-
235
- /**
236
- * Clear the cache (useful for testing)
237
- */
238
- clearCache(): void {
239
- this.cache.clear();
240
- }
241
- }
242
-
243
- /**
244
- * Singleton instance of the Environment class
245
- */
246
- let environmentInstance: Environment | null = null;
247
-
248
- /**
249
- * Get the singleton Environment instance
250
- */
251
- export function getEnvironment(): Environment {
252
- if (!environmentInstance) {
253
- environmentInstance = new Environment();
254
- }
255
- return environmentInstance;
256
- }
257
-
258
- /**
259
- * Convenience function to get an environment variable
260
- */
261
- export function getEnv(key: string, defaultValue?: string): string | undefined {
262
- return getEnvironment().get(key, defaultValue);
263
- }
264
-
265
- /**
266
- * Convenience function to set an environment variable
267
- */
268
- export function setEnv(key: string, value: string | boolean | number): void {
269
- getEnvironment().set(key, value);
270
- }
271
-
272
- /**
273
- * Convenience function to check if an environment variable exists
274
- */
275
- export function hasEnv(key: string): boolean {
276
- return getEnvironment().has(key);
277
- }
278
-
279
- /**
280
- * Convenience function to get a boolean environment variable
281
- */
282
- export function getBooleanEnv(key: string, defaultValue = false): boolean {
283
- return getEnvironment().getBoolean(key, defaultValue);
284
- }
285
-
286
- /**
287
- * Convenience function to get a number environment variable
288
- */
289
- export function getNumberEnv(key: string, defaultValue?: number): number | undefined {
290
- return getEnvironment().getNumber(key, defaultValue);
291
- }
292
-
293
- /**
294
- * Initialize browser environment with config
295
- * This should be called early in browser apps to set up environment
296
- */
297
- export function initBrowserEnvironment(config: EnvironmentConfig): void {
298
- const env = getEnvironment();
299
- if (env.isBrowser()) {
300
- Object.entries(config).forEach(([key, value]) => {
301
- if (value !== undefined) {
302
- env.set(key, value);
303
- }
304
- });
305
- }
306
- }
307
-
308
- /**
309
- * Export the current runtime for convenience
310
- */
311
- export const currentRuntime = detectEnvironment();
312
-
313
- /**
314
- * Re-export the Environment class for advanced usage
315
- */
316
- export { Environment };