@elizaos/core 1.5.3-beta.3 → 1.5.5-alpha.10
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/actions.d.ts +23 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/browser/index.browser.js +172 -179
- package/dist/browser/index.browser.js.map +6 -197
- package/dist/browser/index.d.ts +2 -2
- package/dist/database.d.ts +481 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/entities.d.ts +49 -0
- package/dist/entities.d.ts.map +1 -0
- package/{src/index.browser.ts → dist/index.browser.d.ts} +9 -21
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +27 -3
- package/dist/index.d.ts.map +1 -0
- package/{src/index.node.ts → dist/index.node.d.ts} +3 -16
- package/dist/index.node.d.ts.map +1 -0
- package/dist/logger.d.ts +47 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.node.js +15514 -439
- package/dist/node/index.node.js.map +139 -8
- package/dist/prompts.d.ts +8 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/roles.d.ts +30 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/runtime.d.ts +328 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/schemas/character.d.ts +228 -0
- package/dist/schemas/character.d.ts.map +1 -0
- package/dist/search.d.ts +317 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/sentry/instrument.browser.d.ts +12 -0
- package/dist/sentry/instrument.browser.d.ts.map +1 -0
- package/dist/sentry/instrument.d.ts +12 -0
- package/dist/sentry/instrument.d.ts.map +1 -0
- package/dist/sentry/instrument.node.d.ts +11 -0
- package/dist/sentry/instrument.node.d.ts.map +1 -0
- package/dist/services.d.ts +49 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/settings.d.ts +87 -0
- package/dist/settings.d.ts.map +1 -0
- package/{src/types/agent.ts → dist/types/agent.d.ts} +60 -74
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/browser.d.ts +127 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/components.d.ts +135 -0
- package/dist/types/components.d.ts.map +1 -0
- package/dist/types/database.d.ts +278 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/email.d.ts +143 -0
- package/dist/types/email.d.ts.map +1 -0
- package/dist/types/environment.d.ts +109 -0
- package/dist/types/environment.d.ts.map +1 -0
- package/dist/types/events.d.ts +207 -0
- package/dist/types/events.d.ts.map +1 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{src/types/knowledge.ts → dist/types/knowledge.d.ts} +18 -23
- package/dist/types/knowledge.d.ts.map +1 -0
- package/dist/types/lp.d.ts +115 -0
- package/dist/types/lp.d.ts.map +1 -0
- package/{src/types/memory.ts → dist/types/memory.d.ts} +69 -132
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/message.d.ts +202 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/messaging.d.ts +45 -0
- package/dist/types/messaging.d.ts.map +1 -0
- package/dist/types/model.d.ts +319 -0
- package/dist/types/model.d.ts.map +1 -0
- package/dist/types/pdf.d.ts +68 -0
- package/dist/types/pdf.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +64 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/post.d.ts +242 -0
- package/dist/types/post.d.ts.map +1 -0
- package/dist/types/primitives.d.ts +72 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/runtime.d.ts +106 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/{src/types/service.ts → dist/types/service.d.ts} +69 -120
- package/dist/types/service.d.ts.map +1 -0
- package/dist/types/settings.d.ts +30 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/{src/types/state.ts → dist/types/state.d.ts} +18 -19
- package/dist/types/state.d.ts.map +1 -0
- package/dist/types/task.d.ts +68 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/tee.d.ts +97 -0
- package/dist/types/tee.d.ts.map +1 -0
- package/dist/types/testing.d.ts +29 -0
- package/dist/types/testing.d.ts.map +1 -0
- package/dist/types/token.d.ts +73 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/transcription.d.ts +108 -0
- package/dist/types/transcription.d.ts.map +1 -0
- package/dist/types/video.d.ts +93 -0
- package/dist/types/video.d.ts.map +1 -0
- package/dist/types/wallet.d.ts +49 -0
- package/dist/types/wallet.d.ts.map +1 -0
- package/dist/types/web-search.d.ts +112 -0
- package/dist/types/web-search.d.ts.map +1 -0
- package/dist/utils/buffer.d.ts +105 -0
- package/dist/utils/buffer.d.ts.map +1 -0
- package/dist/utils/environment.d.ts +106 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/server-health.d.ts +23 -0
- package/dist/utils/server-health.d.ts.map +1 -0
- package/dist/utils.d.ts +177 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/__tests__/action-chaining-simple.test.ts +0 -203
- package/src/__tests__/actions.test.ts +0 -218
- package/src/__tests__/buffer.test.ts +0 -337
- package/src/__tests__/character-validation.test.ts +0 -309
- package/src/__tests__/database.test.ts +0 -750
- package/src/__tests__/entities.test.ts +0 -727
- package/src/__tests__/env.test.ts +0 -23
- package/src/__tests__/environment.test.ts +0 -285
- package/src/__tests__/logger-browser-node.test.ts +0 -716
- package/src/__tests__/logger.test.ts +0 -403
- package/src/__tests__/messages.test.ts +0 -196
- package/src/__tests__/mockCharacter.ts +0 -544
- package/src/__tests__/parsing.test.ts +0 -58
- package/src/__tests__/prompts.test.ts +0 -159
- package/src/__tests__/roles.test.ts +0 -331
- package/src/__tests__/runtime-embedding.test.ts +0 -343
- package/src/__tests__/runtime.test.ts +0 -978
- package/src/__tests__/search.test.ts +0 -15
- package/src/__tests__/services-by-type.test.ts +0 -204
- package/src/__tests__/services.test.ts +0 -136
- package/src/__tests__/settings.test.ts +0 -810
- package/src/__tests__/utils.test.ts +0 -1105
- package/src/__tests__/uuid.test.ts +0 -94
- package/src/actions.ts +0 -122
- package/src/database.ts +0 -579
- package/src/entities.ts +0 -406
- package/src/index.ts +0 -50
- package/src/logger.ts +0 -527
- package/src/prompts.ts +0 -243
- package/src/roles.ts +0 -85
- package/src/runtime.ts +0 -2514
- package/src/schemas/character.ts +0 -149
- package/src/search.ts +0 -1543
- package/src/sentry/instrument.browser.ts +0 -65
- package/src/sentry/instrument.node.ts +0 -57
- package/src/sentry/instrument.ts +0 -82
- package/src/services.ts +0 -105
- package/src/settings.ts +0 -409
- package/src/test_resources/constants.ts +0 -12
- package/src/test_resources/testSetup.ts +0 -21
- package/src/test_resources/types.ts +0 -22
- package/src/types/browser.ts +0 -145
- package/src/types/components.ts +0 -184
- package/src/types/database.ts +0 -348
- package/src/types/email.ts +0 -162
- package/src/types/environment.ts +0 -129
- package/src/types/events.ts +0 -249
- package/src/types/lp.ts +0 -124
- package/src/types/message.ts +0 -233
- package/src/types/messaging.ts +0 -57
- package/src/types/model.ts +0 -359
- package/src/types/pdf.ts +0 -77
- package/src/types/plugin.ts +0 -78
- package/src/types/post.ts +0 -271
- package/src/types/primitives.ts +0 -97
- package/src/types/runtime.ts +0 -190
- package/src/types/settings.ts +0 -30
- package/src/types/task.ts +0 -72
- package/src/types/tee.ts +0 -107
- package/src/types/testing.ts +0 -30
- package/src/types/token.ts +0 -96
- package/src/types/transcription.ts +0 -133
- package/src/types/video.ts +0 -108
- package/src/types/wallet.ts +0 -56
- package/src/types/web-search.ts +0 -146
- package/src/utils/__tests__/buffer.test.ts +0 -80
- package/src/utils/__tests__/environment.test.ts +0 -58
- package/src/utils/__tests__/stringToUuid.test.ts +0 -88
- package/src/utils/buffer.ts +0 -312
- package/src/utils/environment.ts +0 -316
- package/src/utils/server-health.ts +0 -117
- package/src/utils.ts +0 -1076
package/src/utils/environment.ts
DELETED
|
@@ -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 };
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server health check utilities for waiting for servers to be ready
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface ServerHealthOptions {
|
|
6
|
-
port: number;
|
|
7
|
-
endpoint?: string;
|
|
8
|
-
maxWaitTime?: number;
|
|
9
|
-
pollInterval?: number;
|
|
10
|
-
requestTimeout?: number;
|
|
11
|
-
host?: string;
|
|
12
|
-
protocol?: 'http' | 'https';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Wait for server to be ready by polling health endpoint
|
|
17
|
-
* @param options - Configuration options for server health check
|
|
18
|
-
*/
|
|
19
|
-
export async function waitForServerReady(options: ServerHealthOptions): Promise<void> {
|
|
20
|
-
const {
|
|
21
|
-
port,
|
|
22
|
-
endpoint = '/api/agents',
|
|
23
|
-
maxWaitTime = 30000, // 30 seconds default
|
|
24
|
-
pollInterval = 1000, // 1 second
|
|
25
|
-
requestTimeout = 2000, // 2 seconds
|
|
26
|
-
host = 'localhost',
|
|
27
|
-
protocol = 'http',
|
|
28
|
-
} = options;
|
|
29
|
-
|
|
30
|
-
const url = `${protocol}://${host}:${port}${endpoint}`;
|
|
31
|
-
const startTime = Date.now();
|
|
32
|
-
|
|
33
|
-
while (Date.now() - startTime < maxWaitTime) {
|
|
34
|
-
let controller: AbortController | undefined;
|
|
35
|
-
let timeoutId: NodeJS.Timeout | undefined;
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
controller = new AbortController();
|
|
39
|
-
timeoutId = setTimeout(() => {
|
|
40
|
-
if (controller) {
|
|
41
|
-
controller.abort();
|
|
42
|
-
}
|
|
43
|
-
}, requestTimeout);
|
|
44
|
-
|
|
45
|
-
const response = await fetch(url, {
|
|
46
|
-
signal: controller.signal,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (timeoutId) {
|
|
50
|
-
clearTimeout(timeoutId);
|
|
51
|
-
timeoutId = undefined;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (response.ok) {
|
|
55
|
-
// Server is ready, give it one more second to stabilize
|
|
56
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
// Server not ready yet, continue polling
|
|
61
|
-
} finally {
|
|
62
|
-
// Ensure cleanup happens even if there's an exception
|
|
63
|
-
if (timeoutId) {
|
|
64
|
-
clearTimeout(timeoutId);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
throw new Error(`Server failed to become ready at ${url} within ${maxWaitTime}ms`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Simple ping check for server availability (no stabilization wait)
|
|
76
|
-
* @param options - Configuration options for server ping
|
|
77
|
-
*/
|
|
78
|
-
export async function pingServer(options: ServerHealthOptions): Promise<boolean> {
|
|
79
|
-
const {
|
|
80
|
-
port,
|
|
81
|
-
endpoint = '/api/agents',
|
|
82
|
-
requestTimeout = 2000,
|
|
83
|
-
host = 'localhost',
|
|
84
|
-
protocol = 'http',
|
|
85
|
-
} = options;
|
|
86
|
-
|
|
87
|
-
const url = `${protocol}://${host}:${port}${endpoint}`;
|
|
88
|
-
let controller: AbortController | undefined;
|
|
89
|
-
let timeoutId: NodeJS.Timeout | undefined;
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
controller = new AbortController();
|
|
93
|
-
timeoutId = setTimeout(() => {
|
|
94
|
-
if (controller) {
|
|
95
|
-
controller.abort();
|
|
96
|
-
}
|
|
97
|
-
}, requestTimeout);
|
|
98
|
-
|
|
99
|
-
const response = await fetch(url, {
|
|
100
|
-
signal: controller.signal,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (timeoutId) {
|
|
104
|
-
clearTimeout(timeoutId);
|
|
105
|
-
timeoutId = undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return response.ok;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
return false;
|
|
111
|
-
} finally {
|
|
112
|
-
// Ensure cleanup happens even if there's an exception
|
|
113
|
-
if (timeoutId) {
|
|
114
|
-
clearTimeout(timeoutId);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|