@elizaos/api-client 1.0.12
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/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/index.d.ts +776 -0
- package/dist/index.js +721 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,721 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/lib/base-client.ts
|
|
4
|
+
var ApiError = class extends Error {
|
|
5
|
+
constructor(code, message, details, status) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.details = details;
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.name = "ApiError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var BaseApiClient = class {
|
|
14
|
+
baseUrl;
|
|
15
|
+
apiKey;
|
|
16
|
+
timeout;
|
|
17
|
+
defaultHeaders;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
20
|
+
this.apiKey = config.apiKey;
|
|
21
|
+
this.timeout = config.timeout || 3e4;
|
|
22
|
+
this.defaultHeaders = {
|
|
23
|
+
"Content-Type": "application/json",
|
|
24
|
+
...config.headers
|
|
25
|
+
};
|
|
26
|
+
if (this.apiKey) {
|
|
27
|
+
this.defaultHeaders["X-API-KEY"] = this.apiKey;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async request(method, path, options) {
|
|
31
|
+
let url;
|
|
32
|
+
if (this.baseUrl) {
|
|
33
|
+
url = new URL(`${this.baseUrl}${path}`);
|
|
34
|
+
} else if (typeof window !== "undefined" && window.location) {
|
|
35
|
+
url = new URL(path, window.location.origin);
|
|
36
|
+
} else {
|
|
37
|
+
url = new URL(path, "http://localhost:3000");
|
|
38
|
+
}
|
|
39
|
+
if (options?.params) {
|
|
40
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
41
|
+
if (value !== void 0 && value !== null) {
|
|
42
|
+
url.searchParams.append(key, String(value));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
48
|
+
try {
|
|
49
|
+
const headers = {
|
|
50
|
+
...this.defaultHeaders,
|
|
51
|
+
...options?.config?.headers,
|
|
52
|
+
...options?.headers
|
|
53
|
+
};
|
|
54
|
+
if (options?.body instanceof FormData) {
|
|
55
|
+
delete headers["Content-Type"];
|
|
56
|
+
}
|
|
57
|
+
const response = await fetch(url.toString(), {
|
|
58
|
+
method,
|
|
59
|
+
headers,
|
|
60
|
+
body: options?.body instanceof FormData ? options.body : options?.body ? JSON.stringify(options.body) : void 0,
|
|
61
|
+
signal: controller.signal
|
|
62
|
+
});
|
|
63
|
+
clearTimeout(timeoutId);
|
|
64
|
+
const data = await response.json();
|
|
65
|
+
if (!response.ok || !data.success) {
|
|
66
|
+
const error = "error" in data ? data.error : {
|
|
67
|
+
code: "UNKNOWN_ERROR",
|
|
68
|
+
message: "An unknown error occurred"
|
|
69
|
+
};
|
|
70
|
+
throw new ApiError(error.code, error.message, error.details, response.status);
|
|
71
|
+
}
|
|
72
|
+
return data.data;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
clearTimeout(timeoutId);
|
|
75
|
+
if (error instanceof ApiError) {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
if (error instanceof Error) {
|
|
79
|
+
if (error.name === "AbortError") {
|
|
80
|
+
throw new ApiError("TIMEOUT", "Request timed out");
|
|
81
|
+
}
|
|
82
|
+
throw new ApiError("NETWORK_ERROR", error.message);
|
|
83
|
+
}
|
|
84
|
+
throw new ApiError("UNKNOWN_ERROR", "An unknown error occurred");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async get(path, options) {
|
|
88
|
+
return this.request("GET", path, options);
|
|
89
|
+
}
|
|
90
|
+
async post(path, body, options) {
|
|
91
|
+
return this.request("POST", path, { ...options, body });
|
|
92
|
+
}
|
|
93
|
+
async put(path, body, options) {
|
|
94
|
+
return this.request("PUT", path, { ...options, body });
|
|
95
|
+
}
|
|
96
|
+
async patch(path, body, options) {
|
|
97
|
+
return this.request("PATCH", path, { ...options, body });
|
|
98
|
+
}
|
|
99
|
+
async delete(path, options) {
|
|
100
|
+
return this.request("DELETE", path, options);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/services/agents.ts
|
|
105
|
+
var AgentsService = class extends BaseApiClient {
|
|
106
|
+
/**
|
|
107
|
+
* List all agents with minimal details
|
|
108
|
+
*/
|
|
109
|
+
async listAgents() {
|
|
110
|
+
return this.get("/api/agents");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get specific agent details
|
|
114
|
+
*/
|
|
115
|
+
async getAgent(agentId) {
|
|
116
|
+
return this.get(`/api/agents/${agentId}`);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a new agent
|
|
120
|
+
*/
|
|
121
|
+
async createAgent(params) {
|
|
122
|
+
return this.post("/api/agents", params);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Update an existing agent
|
|
126
|
+
*/
|
|
127
|
+
async updateAgent(agentId, params) {
|
|
128
|
+
return this.patch(`/api/agents/${agentId}`, params);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Delete an agent
|
|
132
|
+
*/
|
|
133
|
+
async deleteAgent(agentId) {
|
|
134
|
+
return this.delete(`/api/agents/${agentId}`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Start an existing agent
|
|
138
|
+
*/
|
|
139
|
+
async startAgent(agentId) {
|
|
140
|
+
return this.post(`/api/agents/${agentId}/start`);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Stop a running agent
|
|
144
|
+
*/
|
|
145
|
+
async stopAgent(agentId) {
|
|
146
|
+
return this.post(`/api/agents/${agentId}/stop`);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get all available worlds
|
|
150
|
+
*/
|
|
151
|
+
async getWorlds() {
|
|
152
|
+
return this.get("/api/agents/worlds");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Add agent to a world
|
|
156
|
+
*/
|
|
157
|
+
async addAgentToWorld(agentId, worldId) {
|
|
158
|
+
return this.post(`/api/agents/${agentId}/worlds`, { worldId });
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Update agent's world settings
|
|
162
|
+
*/
|
|
163
|
+
async updateAgentWorldSettings(agentId, worldId, settings) {
|
|
164
|
+
return this.patch(`/api/agents/${agentId}/worlds/${worldId}`, { settings });
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get agent's plugin panels
|
|
168
|
+
*/
|
|
169
|
+
async getAgentPanels(agentId) {
|
|
170
|
+
return this.get(`/api/agents/${agentId}/panels`);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get agent logs
|
|
174
|
+
*/
|
|
175
|
+
async getAgentLogs(agentId, params) {
|
|
176
|
+
return this.get(`/api/agents/${agentId}/logs`, { params });
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Delete a specific log entry
|
|
180
|
+
*/
|
|
181
|
+
async deleteAgentLog(agentId, logId) {
|
|
182
|
+
return this.delete(`/api/agents/${agentId}/logs/${logId}`);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/services/messaging.ts
|
|
187
|
+
var MessagingService = class extends BaseApiClient {
|
|
188
|
+
/**
|
|
189
|
+
* Submit agent replies or system messages
|
|
190
|
+
*/
|
|
191
|
+
async submitMessage(params) {
|
|
192
|
+
return this.post("/api/messaging/submit", params);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Notify message completion
|
|
196
|
+
*/
|
|
197
|
+
async completeMessage(params) {
|
|
198
|
+
return this.post("/api/messaging/complete", params);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Ingest messages from external platforms
|
|
202
|
+
*/
|
|
203
|
+
async ingestExternalMessages(params) {
|
|
204
|
+
return this.post("/api/messaging/ingest-external", params);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Create a new channel
|
|
208
|
+
*/
|
|
209
|
+
async createChannel(params) {
|
|
210
|
+
return this.post("/api/messaging/channels", params);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create a group channel
|
|
214
|
+
*/
|
|
215
|
+
async createGroupChannel(params) {
|
|
216
|
+
return this.post("/api/messaging/central-channels", params);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Find or create a DM channel
|
|
220
|
+
*/
|
|
221
|
+
async getOrCreateDmChannel(params) {
|
|
222
|
+
return this.get("/api/messaging/dm-channel", { params });
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get channel details
|
|
226
|
+
*/
|
|
227
|
+
async getChannelDetails(channelId) {
|
|
228
|
+
return this.get(`/api/messaging/central-channels/${channelId}/details`);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get channel participants
|
|
232
|
+
*/
|
|
233
|
+
async getChannelParticipants(channelId) {
|
|
234
|
+
return this.get(
|
|
235
|
+
`/api/messaging/central-channels/${channelId}/participants`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Add agent to channel
|
|
240
|
+
*/
|
|
241
|
+
async addAgentToChannel(channelId, agentId) {
|
|
242
|
+
return this.post(`/api/messaging/central-channels/${channelId}/agents`, {
|
|
243
|
+
agentId
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Remove agent from channel
|
|
248
|
+
*/
|
|
249
|
+
async removeAgentFromChannel(channelId, agentId) {
|
|
250
|
+
return this.delete(
|
|
251
|
+
`/api/messaging/central-channels/${channelId}/agents/${agentId}`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Delete a channel
|
|
256
|
+
*/
|
|
257
|
+
async deleteChannel(channelId) {
|
|
258
|
+
return this.delete(`/api/messaging/channels/${channelId}`);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Clear channel history
|
|
262
|
+
*/
|
|
263
|
+
async clearChannelHistory(channelId) {
|
|
264
|
+
return this.post(`/api/messaging/channels/${channelId}/clear`);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Post a new message to a channel
|
|
268
|
+
*/
|
|
269
|
+
async postMessage(channelId, content, metadata) {
|
|
270
|
+
return this.post(`/api/messaging/central-channels/${channelId}/messages`, {
|
|
271
|
+
content,
|
|
272
|
+
metadata
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get channel messages
|
|
277
|
+
*/
|
|
278
|
+
async getChannelMessages(channelId, params) {
|
|
279
|
+
return this.get(
|
|
280
|
+
`/api/messaging/central-channels/${channelId}/messages`,
|
|
281
|
+
{ params }
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get a specific message
|
|
286
|
+
*/
|
|
287
|
+
async getMessage(messageId) {
|
|
288
|
+
return this.get(`/api/messaging/messages/${messageId}`);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Delete a message
|
|
292
|
+
*/
|
|
293
|
+
async deleteMessage(messageId) {
|
|
294
|
+
return this.delete(`/api/messaging/messages/${messageId}`);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Update a message
|
|
298
|
+
*/
|
|
299
|
+
async updateMessage(messageId, content) {
|
|
300
|
+
return this.patch(`/api/messaging/messages/${messageId}`, { content });
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Search messages
|
|
304
|
+
*/
|
|
305
|
+
async searchMessages(params) {
|
|
306
|
+
return this.post("/api/messaging/messages/search", params);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* List all message servers
|
|
310
|
+
*/
|
|
311
|
+
async listServers() {
|
|
312
|
+
return this.get("/api/messaging/central-servers");
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get server channels
|
|
316
|
+
*/
|
|
317
|
+
async getServerChannels(serverId) {
|
|
318
|
+
return this.get(
|
|
319
|
+
`/api/messaging/central-servers/${serverId}/channels`
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Create a new server
|
|
324
|
+
*/
|
|
325
|
+
async createServer(params) {
|
|
326
|
+
return this.post("/api/messaging/servers", params);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Sync server channels
|
|
330
|
+
*/
|
|
331
|
+
async syncServerChannels(serverId, params) {
|
|
332
|
+
return this.post(
|
|
333
|
+
`/api/messaging/servers/${serverId}/sync-channels`,
|
|
334
|
+
params
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Delete a server
|
|
339
|
+
*/
|
|
340
|
+
async deleteServer(serverId) {
|
|
341
|
+
return this.delete(`/api/messaging/servers/${serverId}`);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/services/memory.ts
|
|
346
|
+
var MemoryService = class extends BaseApiClient {
|
|
347
|
+
/**
|
|
348
|
+
* Get agent memories
|
|
349
|
+
*/
|
|
350
|
+
async getAgentMemories(agentId, params) {
|
|
351
|
+
return this.get(`/api/memory/${agentId}/memories`, { params });
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Get room-specific memories
|
|
355
|
+
*/
|
|
356
|
+
async getRoomMemories(agentId, roomId, params) {
|
|
357
|
+
return this.get(`/api/memory/${agentId}/rooms/${roomId}/memories`, {
|
|
358
|
+
params
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Update a memory
|
|
363
|
+
*/
|
|
364
|
+
async updateMemory(agentId, memoryId, params) {
|
|
365
|
+
return this.patch(`/api/memory/${agentId}/memories/${memoryId}`, params);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Clear all agent memories
|
|
369
|
+
*/
|
|
370
|
+
async clearAgentMemories(agentId) {
|
|
371
|
+
return this.delete(`/api/memory/${agentId}/memories`);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Clear room memories
|
|
375
|
+
*/
|
|
376
|
+
async clearRoomMemories(agentId, roomId) {
|
|
377
|
+
return this.delete(`/api/memory/${agentId}/memories/all/${roomId}`);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* List agent's rooms
|
|
381
|
+
*/
|
|
382
|
+
async listAgentRooms(agentId) {
|
|
383
|
+
return this.get(`/api/memory/${agentId}/rooms`);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Get room details
|
|
387
|
+
*/
|
|
388
|
+
async getRoom(agentId, roomId) {
|
|
389
|
+
return this.get(`/api/memory/${agentId}/rooms/${roomId}`);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Create a room
|
|
393
|
+
*/
|
|
394
|
+
async createRoom(agentId, params) {
|
|
395
|
+
return this.post(`/api/memory/${agentId}/rooms`, params);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Create world from server
|
|
399
|
+
*/
|
|
400
|
+
async createWorldFromServer(serverId, params) {
|
|
401
|
+
return this.post(`/api/memory/groups/${serverId}`, params);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Delete a world
|
|
405
|
+
*/
|
|
406
|
+
async deleteWorld(serverId) {
|
|
407
|
+
return this.delete(`/api/memory/groups/${serverId}`);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Clear world memories
|
|
411
|
+
*/
|
|
412
|
+
async clearWorldMemories(serverId) {
|
|
413
|
+
return this.delete(`/api/memory/groups/${serverId}/memories`);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// src/services/audio.ts
|
|
418
|
+
var AudioService = class extends BaseApiClient {
|
|
419
|
+
/**
|
|
420
|
+
* Convert audio input to appropriate FormData value
|
|
421
|
+
*/
|
|
422
|
+
processAudioInput(audio) {
|
|
423
|
+
if (audio instanceof Blob) {
|
|
424
|
+
return audio;
|
|
425
|
+
}
|
|
426
|
+
if (typeof audio === "string") {
|
|
427
|
+
if (audio.startsWith("data:")) {
|
|
428
|
+
try {
|
|
429
|
+
const [header, base64Data] = audio.split(",");
|
|
430
|
+
const mimeMatch = header.match(/data:([^;]+)/);
|
|
431
|
+
const mimeType = mimeMatch ? mimeMatch[1] : "audio/wav";
|
|
432
|
+
const binaryString = atob(base64Data);
|
|
433
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
434
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
435
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
436
|
+
}
|
|
437
|
+
return new Blob([bytes], { type: mimeType });
|
|
438
|
+
} catch (error) {
|
|
439
|
+
throw new Error(
|
|
440
|
+
`Invalid base64 data URL: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (this.isBase64String(audio)) {
|
|
445
|
+
try {
|
|
446
|
+
const binaryString = atob(audio);
|
|
447
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
448
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
449
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
450
|
+
}
|
|
451
|
+
return new Blob([bytes], { type: "audio/wav" });
|
|
452
|
+
} catch (error) {
|
|
453
|
+
return audio;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return audio;
|
|
457
|
+
}
|
|
458
|
+
if (this.isBuffer(audio)) {
|
|
459
|
+
return new Blob([audio], { type: "audio/wav" });
|
|
460
|
+
}
|
|
461
|
+
const audioAsAny = audio;
|
|
462
|
+
if (audioAsAny instanceof ArrayBuffer) {
|
|
463
|
+
return new Blob([audioAsAny], { type: "audio/wav" });
|
|
464
|
+
}
|
|
465
|
+
if (audioAsAny && typeof audioAsAny === "object" && "buffer" in audioAsAny && audioAsAny.buffer instanceof ArrayBuffer) {
|
|
466
|
+
return new Blob([audioAsAny.buffer], { type: "audio/wav" });
|
|
467
|
+
}
|
|
468
|
+
throw new Error(
|
|
469
|
+
`Unsupported audio input type: ${typeof audio}. Expected Blob, Buffer, ArrayBuffer, or string.`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Check if a string appears to be base64 encoded
|
|
474
|
+
*/
|
|
475
|
+
isBase64String(str) {
|
|
476
|
+
const base64Pattern = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
477
|
+
if (str.length < 4 || str.length % 4 !== 0) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
return base64Pattern.test(str);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Safe check for Buffer type (works in both Node.js and browser environments)
|
|
484
|
+
*/
|
|
485
|
+
isBuffer(obj) {
|
|
486
|
+
return obj != null && typeof obj === "object" && typeof obj.constructor === "function" && obj.constructor.name === "Buffer" && typeof obj.readUInt8 === "function";
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Handle speech conversation
|
|
490
|
+
*/
|
|
491
|
+
async speechConversation(agentId, params) {
|
|
492
|
+
const formData = new FormData();
|
|
493
|
+
const processedAudio = this.processAudioInput(params.audio);
|
|
494
|
+
if (processedAudio instanceof Blob) {
|
|
495
|
+
formData.append("audio", processedAudio);
|
|
496
|
+
} else {
|
|
497
|
+
formData.append("audio", processedAudio);
|
|
498
|
+
}
|
|
499
|
+
if (params.format) formData.append("format", params.format);
|
|
500
|
+
if (params.language) formData.append("language", params.language);
|
|
501
|
+
if (params.metadata) formData.append("metadata", JSON.stringify(params.metadata));
|
|
502
|
+
return this.request("POST", `/api/audio/${agentId}/speech/conversation`, {
|
|
503
|
+
body: formData
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Generate speech from text
|
|
508
|
+
*/
|
|
509
|
+
async generateSpeech(agentId, params) {
|
|
510
|
+
return this.post(
|
|
511
|
+
`/api/audio/${agentId}/speech/generate`,
|
|
512
|
+
params
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Synthesize audio message
|
|
517
|
+
*/
|
|
518
|
+
async synthesizeAudioMessage(agentId, params) {
|
|
519
|
+
return this.post(
|
|
520
|
+
`/api/audio/${agentId}/audio-messages/synthesize`,
|
|
521
|
+
params
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Transcribe audio to text
|
|
526
|
+
*/
|
|
527
|
+
async transcribe(agentId, params) {
|
|
528
|
+
const formData = new FormData();
|
|
529
|
+
const processedAudio = this.processAudioInput(params.audio);
|
|
530
|
+
if (processedAudio instanceof Blob) {
|
|
531
|
+
formData.append("audio", processedAudio);
|
|
532
|
+
} else {
|
|
533
|
+
formData.append("audio", processedAudio);
|
|
534
|
+
}
|
|
535
|
+
if (params.format) formData.append("format", params.format);
|
|
536
|
+
if (params.language) formData.append("language", params.language);
|
|
537
|
+
return this.request("POST", `/api/audio/${agentId}/transcribe`, {
|
|
538
|
+
body: formData
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Process speech input
|
|
543
|
+
*/
|
|
544
|
+
async processSpeech(agentId, audio, metadata) {
|
|
545
|
+
const formData = new FormData();
|
|
546
|
+
const processedAudio = this.processAudioInput(audio);
|
|
547
|
+
if (processedAudio instanceof Blob) {
|
|
548
|
+
formData.append("audio", processedAudio);
|
|
549
|
+
} else {
|
|
550
|
+
formData.append("audio", processedAudio);
|
|
551
|
+
}
|
|
552
|
+
if (metadata) formData.append("metadata", JSON.stringify(metadata));
|
|
553
|
+
return this.request("POST", `/api/audio/${agentId}/speech`, {
|
|
554
|
+
body: formData
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/services/media.ts
|
|
560
|
+
var MediaService = class extends BaseApiClient {
|
|
561
|
+
/**
|
|
562
|
+
* Upload media for an agent
|
|
563
|
+
*/
|
|
564
|
+
async uploadAgentMedia(agentId, params) {
|
|
565
|
+
const formData = new FormData();
|
|
566
|
+
formData.append("file", params.file, params.filename);
|
|
567
|
+
if (params.contentType) formData.append("contentType", params.contentType);
|
|
568
|
+
if (params.metadata) formData.append("metadata", JSON.stringify(params.metadata));
|
|
569
|
+
return this.request("POST", `/api/media/${agentId}/upload-media`, {
|
|
570
|
+
body: formData
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Upload files to a channel
|
|
575
|
+
*/
|
|
576
|
+
async uploadChannelFiles(channelId, params) {
|
|
577
|
+
const formData = new FormData();
|
|
578
|
+
params.files.forEach((file, index) => {
|
|
579
|
+
formData.append(`files[${index}]`, file);
|
|
580
|
+
});
|
|
581
|
+
if (params.messageId) formData.append("messageId", params.messageId);
|
|
582
|
+
if (params.metadata) formData.append("metadata", JSON.stringify(params.metadata));
|
|
583
|
+
return this.request(
|
|
584
|
+
"POST",
|
|
585
|
+
`/api/media/central-channels/${channelId}/upload`,
|
|
586
|
+
{
|
|
587
|
+
body: formData
|
|
588
|
+
}
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
// src/services/server.ts
|
|
594
|
+
var ServerService = class extends BaseApiClient {
|
|
595
|
+
/**
|
|
596
|
+
* Health check
|
|
597
|
+
*/
|
|
598
|
+
async checkHealth() {
|
|
599
|
+
return this.get("/api/server/health");
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Simple ping
|
|
603
|
+
*/
|
|
604
|
+
async ping() {
|
|
605
|
+
return this.get("/api/server/ping");
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Hello endpoint
|
|
609
|
+
*/
|
|
610
|
+
async hello() {
|
|
611
|
+
return this.get("/api/server/hello");
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Get server status
|
|
615
|
+
*/
|
|
616
|
+
async getStatus() {
|
|
617
|
+
return this.get("/api/server/status");
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Stop the server
|
|
621
|
+
*/
|
|
622
|
+
async stopServer() {
|
|
623
|
+
return this.post("/api/server/stop");
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Get runtime debug info
|
|
627
|
+
*/
|
|
628
|
+
async getDebugInfo() {
|
|
629
|
+
return this.get("/api/server/servers");
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Submit logs
|
|
633
|
+
*/
|
|
634
|
+
async submitLogs(logs) {
|
|
635
|
+
return this.post("/api/server/logs", { logs });
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Clear logs
|
|
639
|
+
*/
|
|
640
|
+
async clearLogs() {
|
|
641
|
+
return this.delete("/api/server/logs");
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// src/services/system.ts
|
|
646
|
+
var SystemService = class extends BaseApiClient {
|
|
647
|
+
/**
|
|
648
|
+
* Retrieve the local environment variables from the ElizaOS server.
|
|
649
|
+
*
|
|
650
|
+
* Server route (packages/server/src/api/system):
|
|
651
|
+
* GET /api/system/env/local -> { success: true, data: Record<string,string> }
|
|
652
|
+
*/
|
|
653
|
+
async getEnvironment() {
|
|
654
|
+
return this.get("/api/system/env/local");
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Update (overwrite or merge) the local .env file on the ElizaOS server.
|
|
658
|
+
*
|
|
659
|
+
* Server route (packages/server/src/api/system):
|
|
660
|
+
* POST /api/system/env/local -> { success: true, message: string }
|
|
661
|
+
* Body: { content: Record<string,string> }
|
|
662
|
+
*
|
|
663
|
+
* For developer-ergonomics we accept several shapes:
|
|
664
|
+
* 1. { variables: Record<string,string>; merge?: boolean }
|
|
665
|
+
* 2. { content: Record<string,string> } (server-native)
|
|
666
|
+
* 3. Record<string,string> (shorthand)
|
|
667
|
+
*/
|
|
668
|
+
async updateLocalEnvironment(params) {
|
|
669
|
+
if (!params || typeof params !== "object") {
|
|
670
|
+
throw new Error("updateLocalEnvironment requires a configuration object");
|
|
671
|
+
}
|
|
672
|
+
let body;
|
|
673
|
+
if ("variables" in params) {
|
|
674
|
+
body = { content: params.variables };
|
|
675
|
+
} else if ("content" in params) {
|
|
676
|
+
body = { content: params.content };
|
|
677
|
+
} else {
|
|
678
|
+
body = { content: params };
|
|
679
|
+
}
|
|
680
|
+
return this.post("/api/system/env/local", body);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// src/client.ts
|
|
685
|
+
var ElizaClient = class _ElizaClient {
|
|
686
|
+
agents;
|
|
687
|
+
messaging;
|
|
688
|
+
memory;
|
|
689
|
+
audio;
|
|
690
|
+
media;
|
|
691
|
+
server;
|
|
692
|
+
system;
|
|
693
|
+
constructor(config) {
|
|
694
|
+
this.agents = new AgentsService(config);
|
|
695
|
+
this.messaging = new MessagingService(config);
|
|
696
|
+
this.memory = new MemoryService(config);
|
|
697
|
+
this.audio = new AudioService(config);
|
|
698
|
+
this.media = new MediaService(config);
|
|
699
|
+
this.server = new ServerService(config);
|
|
700
|
+
this.system = new SystemService(config);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Create a new ElizaClient instance
|
|
704
|
+
*/
|
|
705
|
+
static create(config) {
|
|
706
|
+
return new _ElizaClient(config);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
export {
|
|
710
|
+
AgentsService,
|
|
711
|
+
ApiError,
|
|
712
|
+
AudioService,
|
|
713
|
+
BaseApiClient,
|
|
714
|
+
ElizaClient,
|
|
715
|
+
MediaService,
|
|
716
|
+
MemoryService,
|
|
717
|
+
MessagingService,
|
|
718
|
+
ServerService,
|
|
719
|
+
SystemService
|
|
720
|
+
};
|
|
721
|
+
//# sourceMappingURL=index.js.map
|