agentxjs 0.0.1
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 +602 -0
- package/dist/index.cjs +1292 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +1283 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/sse/index.cjs +633 -0
- package/dist/runtime/sse/index.cjs.map +1 -0
- package/dist/runtime/sse/index.d.cts +159 -0
- package/dist/runtime/sse/index.d.ts +159 -0
- package/dist/runtime/sse/index.js +621 -0
- package/dist/runtime/sse/index.js.map +1 -0
- package/dist/server/adapters/express.cjs +81 -0
- package/dist/server/adapters/express.cjs.map +1 -0
- package/dist/server/adapters/express.d.cts +75 -0
- package/dist/server/adapters/express.d.ts +75 -0
- package/dist/server/adapters/express.js +78 -0
- package/dist/server/adapters/express.js.map +1 -0
- package/dist/server/adapters/hono.cjs +32 -0
- package/dist/server/adapters/hono.cjs.map +1 -0
- package/dist/server/adapters/hono.d.cts +96 -0
- package/dist/server/adapters/hono.d.ts +96 -0
- package/dist/server/adapters/hono.js +28 -0
- package/dist/server/adapters/hono.js.map +1 -0
- package/dist/server/adapters/index.cjs +135 -0
- package/dist/server/adapters/index.cjs.map +1 -0
- package/dist/server/adapters/index.d.cts +5 -0
- package/dist/server/adapters/index.d.ts +5 -0
- package/dist/server/adapters/index.js +125 -0
- package/dist/server/adapters/index.js.map +1 -0
- package/dist/server/adapters/next.cjs +30 -0
- package/dist/server/adapters/next.cjs.map +1 -0
- package/dist/server/adapters/next.d.cts +107 -0
- package/dist/server/adapters/next.d.ts +107 -0
- package/dist/server/adapters/next.js +25 -0
- package/dist/server/adapters/next.js.map +1 -0
- package/dist/server/index.cjs +1093 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +131 -0
- package/dist/server/index.d.ts +131 -0
- package/dist/server/index.js +1080 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-Cgfcw91r.d.cts +282 -0
- package/dist/types-Cgfcw91r.d.ts +282 -0
- package/dist/types-OVKV6qpE.d.cts +118 -0
- package/dist/types-OVKV6qpE.d.ts +118 -0
- package/package.json +78 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import { createLogger, setLoggerFactory } from '@agentxjs/common';
|
|
2
|
+
import { LogLevel, STREAM_EVENT_TYPE_NAMES } from '@agentxjs/types';
|
|
3
|
+
import ky from 'ky';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
var PersistentSSEConnection = class {
|
|
9
|
+
constructor(serverUrl, agentId, sseParams = {}) {
|
|
10
|
+
this.serverUrl = serverUrl;
|
|
11
|
+
this.agentId = agentId;
|
|
12
|
+
this.sseParams = sseParams;
|
|
13
|
+
__publicField(this, "eventSource", null);
|
|
14
|
+
__publicField(this, "messageQueue", []);
|
|
15
|
+
__publicField(this, "activeIterators", /* @__PURE__ */ new Set());
|
|
16
|
+
__publicField(this, "isDone", false);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Initialize SSE connection
|
|
20
|
+
*/
|
|
21
|
+
connect() {
|
|
22
|
+
if (this.eventSource) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let sseUrl = `${this.serverUrl}/agents/${this.agentId}/sse`;
|
|
26
|
+
if (Object.keys(this.sseParams).length > 0) {
|
|
27
|
+
const params = new URLSearchParams(this.sseParams);
|
|
28
|
+
sseUrl += `?${params.toString()}`;
|
|
29
|
+
}
|
|
30
|
+
this.eventSource = new EventSource(sseUrl);
|
|
31
|
+
const handleEvent = (event) => {
|
|
32
|
+
try {
|
|
33
|
+
const data = JSON.parse(event.data);
|
|
34
|
+
if (this.activeIterators.size > 0) {
|
|
35
|
+
const iterator = this.activeIterators.values().next().value;
|
|
36
|
+
if (iterator) {
|
|
37
|
+
this.activeIterators.delete(iterator);
|
|
38
|
+
iterator.resolve({ value: data, done: false });
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
this.messageQueue.push(data);
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const handleError = () => {
|
|
47
|
+
this.isDone = true;
|
|
48
|
+
this.eventSource?.close();
|
|
49
|
+
this.eventSource = null;
|
|
50
|
+
for (const iterator of this.activeIterators) {
|
|
51
|
+
iterator.reject(new Error("SSE connection error"));
|
|
52
|
+
}
|
|
53
|
+
this.activeIterators.clear();
|
|
54
|
+
};
|
|
55
|
+
for (const eventType of STREAM_EVENT_TYPE_NAMES) {
|
|
56
|
+
this.eventSource.addEventListener(eventType, handleEvent);
|
|
57
|
+
}
|
|
58
|
+
this.eventSource.addEventListener("error", handleEvent);
|
|
59
|
+
this.eventSource.onmessage = handleEvent;
|
|
60
|
+
this.eventSource.onerror = handleError;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create an async iterable for a single receive() call
|
|
64
|
+
*
|
|
65
|
+
* This iterator continues until a final message_stop is received (stopReason !== "tool_use").
|
|
66
|
+
* For tool calls, this means it will span multiple message_start/message_stop cycles.
|
|
67
|
+
* The SSE connection itself remains open for future receive() calls.
|
|
68
|
+
*/
|
|
69
|
+
createIterator() {
|
|
70
|
+
const connection = this;
|
|
71
|
+
return {
|
|
72
|
+
[Symbol.asyncIterator]() {
|
|
73
|
+
let turnComplete = false;
|
|
74
|
+
return {
|
|
75
|
+
async next() {
|
|
76
|
+
if (connection.messageQueue.length > 0) {
|
|
77
|
+
const event = connection.messageQueue.shift();
|
|
78
|
+
if (event.type === "message_stop") {
|
|
79
|
+
const stopReason = event.data.stopReason;
|
|
80
|
+
if (stopReason !== "tool_use") {
|
|
81
|
+
turnComplete = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { value: event, done: false };
|
|
85
|
+
}
|
|
86
|
+
if (turnComplete) {
|
|
87
|
+
return { done: true, value: void 0 };
|
|
88
|
+
}
|
|
89
|
+
if (connection.isDone) {
|
|
90
|
+
return { done: true, value: void 0 };
|
|
91
|
+
}
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const wrappedResolve = (result) => {
|
|
94
|
+
if (!result.done) {
|
|
95
|
+
if (result.value.type === "message_stop") {
|
|
96
|
+
const stopReason = result.value.data.stopReason;
|
|
97
|
+
if (stopReason !== "tool_use") {
|
|
98
|
+
turnComplete = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
resolve(result);
|
|
103
|
+
};
|
|
104
|
+
const iterator = { resolve: wrappedResolve, reject };
|
|
105
|
+
connection.activeIterators.add(iterator);
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
async return() {
|
|
109
|
+
return { done: true, value: void 0 };
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Close the connection
|
|
117
|
+
*/
|
|
118
|
+
close() {
|
|
119
|
+
this.isDone = true;
|
|
120
|
+
if (this.eventSource) {
|
|
121
|
+
this.eventSource.close();
|
|
122
|
+
this.eventSource = null;
|
|
123
|
+
}
|
|
124
|
+
for (const iterator of this.activeIterators) {
|
|
125
|
+
iterator.reject(new Error("Connection closed"));
|
|
126
|
+
}
|
|
127
|
+
this.activeIterators.clear();
|
|
128
|
+
this.messageQueue = [];
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
function createSSEDriver(config) {
|
|
132
|
+
const { serverUrl, agentId, headers = {}, sseParams = {} } = config;
|
|
133
|
+
let connection = null;
|
|
134
|
+
return {
|
|
135
|
+
name: "SSEDriver",
|
|
136
|
+
async *receive(message) {
|
|
137
|
+
if (!connection) {
|
|
138
|
+
connection = new PersistentSSEConnection(serverUrl, agentId, sseParams);
|
|
139
|
+
connection.connect();
|
|
140
|
+
}
|
|
141
|
+
const messageUrl = `${serverUrl}/agents/${agentId}/messages`;
|
|
142
|
+
const response = await fetch(messageUrl, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: {
|
|
145
|
+
"Content-Type": "application/json",
|
|
146
|
+
...headers
|
|
147
|
+
},
|
|
148
|
+
body: JSON.stringify({
|
|
149
|
+
content: typeof message.content === "string" ? message.content : message.content
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
154
|
+
throw new Error(errorBody.error?.message || `HTTP ${response.status}`);
|
|
155
|
+
}
|
|
156
|
+
yield* connection.createIterator();
|
|
157
|
+
},
|
|
158
|
+
interrupt() {
|
|
159
|
+
const interruptUrl = `${serverUrl}/agents/${agentId}/interrupt`;
|
|
160
|
+
fetch(interruptUrl, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: {
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
...headers
|
|
165
|
+
}
|
|
166
|
+
}).catch(() => {
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
var ApiError = class extends Error {
|
|
172
|
+
constructor(code, message, details) {
|
|
173
|
+
super(message);
|
|
174
|
+
this.code = code;
|
|
175
|
+
this.details = details;
|
|
176
|
+
this.name = "ApiError";
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
function createHttpClient(options) {
|
|
180
|
+
return ky.create({
|
|
181
|
+
prefixUrl: options.baseUrl.replace(/\/+$/, ""),
|
|
182
|
+
headers: options.headers,
|
|
183
|
+
timeout: options.timeout || 3e4,
|
|
184
|
+
hooks: {
|
|
185
|
+
afterResponse: [
|
|
186
|
+
async (_request, _options, response) => {
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
const data = await response.json().catch(() => ({}));
|
|
189
|
+
throw new ApiError(
|
|
190
|
+
data.error?.code || "UNKNOWN_ERROR",
|
|
191
|
+
data.error?.message || `Request failed: ${response.status}`,
|
|
192
|
+
data.error?.details
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return response;
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/runtime/sse/repository/RemoteRepository.ts
|
|
203
|
+
var logger = createLogger("agentx/RemoteRepository");
|
|
204
|
+
var RemoteRepository = class {
|
|
205
|
+
constructor(options) {
|
|
206
|
+
__publicField(this, "client");
|
|
207
|
+
this.client = createHttpClient({
|
|
208
|
+
baseUrl: options.serverUrl,
|
|
209
|
+
headers: options.headers
|
|
210
|
+
});
|
|
211
|
+
logger.debug("RemoteRepository created", { serverUrl: options.serverUrl });
|
|
212
|
+
}
|
|
213
|
+
// ==================== Definition ====================
|
|
214
|
+
async saveDefinition(record) {
|
|
215
|
+
await this.client.put(`definitions/${record.name}`, { json: record });
|
|
216
|
+
}
|
|
217
|
+
async findDefinitionByName(name) {
|
|
218
|
+
try {
|
|
219
|
+
const result = await this.client.get(`definitions/${name}`).json();
|
|
220
|
+
return this.parseDefinitionRecord(result);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (this.isNotFound(error)) return null;
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async findAllDefinitions() {
|
|
227
|
+
const result = await this.client.get("definitions").json();
|
|
228
|
+
return result.map((r) => this.parseDefinitionRecord(r));
|
|
229
|
+
}
|
|
230
|
+
async deleteDefinition(name) {
|
|
231
|
+
await this.client.delete(`definitions/${name}`);
|
|
232
|
+
}
|
|
233
|
+
async definitionExists(name) {
|
|
234
|
+
try {
|
|
235
|
+
await this.client.head(`definitions/${name}`);
|
|
236
|
+
return true;
|
|
237
|
+
} catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// ==================== Image ====================
|
|
242
|
+
async saveImage(record) {
|
|
243
|
+
await this.client.put(`images/${record.imageId}`, { json: record });
|
|
244
|
+
}
|
|
245
|
+
async findImageById(imageId) {
|
|
246
|
+
try {
|
|
247
|
+
const result = await this.client.get(`images/${imageId}`).json();
|
|
248
|
+
return this.parseImageRecord(result);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (this.isNotFound(error)) return null;
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async findAllImages() {
|
|
255
|
+
const result = await this.client.get("images").json();
|
|
256
|
+
return result.map((r) => this.parseImageRecord(r));
|
|
257
|
+
}
|
|
258
|
+
async deleteImage(imageId) {
|
|
259
|
+
await this.client.delete(`images/${imageId}`);
|
|
260
|
+
}
|
|
261
|
+
async imageExists(imageId) {
|
|
262
|
+
try {
|
|
263
|
+
await this.client.head(`images/${imageId}`);
|
|
264
|
+
return true;
|
|
265
|
+
} catch {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// ==================== Session ====================
|
|
270
|
+
async saveSession(record) {
|
|
271
|
+
await this.client.put(`sessions/${record.sessionId}`, { json: record });
|
|
272
|
+
}
|
|
273
|
+
async findSessionById(sessionId) {
|
|
274
|
+
try {
|
|
275
|
+
const result = await this.client.get(`sessions/${sessionId}`).json();
|
|
276
|
+
return this.parseSessionRecord(result);
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (this.isNotFound(error)) return null;
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async findSessionsByImageId(imageId) {
|
|
283
|
+
const result = await this.client.get(`images/${imageId}/sessions`).json();
|
|
284
|
+
return result.map((r) => this.parseSessionRecord(r));
|
|
285
|
+
}
|
|
286
|
+
async findSessionsByUserId(userId) {
|
|
287
|
+
const result = await this.client.get(`users/${userId}/sessions`).json();
|
|
288
|
+
return result.map((r) => this.parseSessionRecord(r));
|
|
289
|
+
}
|
|
290
|
+
async findAllSessions() {
|
|
291
|
+
const result = await this.client.get("sessions").json();
|
|
292
|
+
return result.map((r) => this.parseSessionRecord(r));
|
|
293
|
+
}
|
|
294
|
+
async deleteSession(sessionId) {
|
|
295
|
+
await this.client.delete(`sessions/${sessionId}`);
|
|
296
|
+
}
|
|
297
|
+
async deleteSessionsByImageId(imageId) {
|
|
298
|
+
await this.client.delete(`images/${imageId}/sessions`);
|
|
299
|
+
}
|
|
300
|
+
async sessionExists(sessionId) {
|
|
301
|
+
try {
|
|
302
|
+
await this.client.head(`sessions/${sessionId}`);
|
|
303
|
+
return true;
|
|
304
|
+
} catch {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// ==================== Message ====================
|
|
309
|
+
/**
|
|
310
|
+
* Save message - noop in browser
|
|
311
|
+
*
|
|
312
|
+
* Messages are persisted by server-side SessionCollector.
|
|
313
|
+
* Browser-side calls this but it does nothing to avoid duplicate saves.
|
|
314
|
+
*/
|
|
315
|
+
async saveMessage(_record) {
|
|
316
|
+
logger.debug("saveMessage called (noop in browser)");
|
|
317
|
+
}
|
|
318
|
+
async findMessageById(messageId) {
|
|
319
|
+
try {
|
|
320
|
+
const result = await this.client.get(`messages/${messageId}`).json();
|
|
321
|
+
return this.parseMessageRecord(result);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if (this.isNotFound(error)) return null;
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async findMessagesBySessionId(sessionId) {
|
|
328
|
+
const result = await this.client.get(`sessions/${sessionId}/messages`).json();
|
|
329
|
+
return result.map((r) => this.parseMessageRecord(r));
|
|
330
|
+
}
|
|
331
|
+
async deleteMessage(messageId) {
|
|
332
|
+
await this.client.delete(`messages/${messageId}`);
|
|
333
|
+
}
|
|
334
|
+
async deleteMessagesBySessionId(sessionId) {
|
|
335
|
+
await this.client.delete(`sessions/${sessionId}/messages`);
|
|
336
|
+
}
|
|
337
|
+
async countMessagesBySessionId(sessionId) {
|
|
338
|
+
const result = await this.client.get(`sessions/${sessionId}/messages/count`).json();
|
|
339
|
+
return result.count;
|
|
340
|
+
}
|
|
341
|
+
// ==================== Container ====================
|
|
342
|
+
async saveContainer(record) {
|
|
343
|
+
await this.client.put(`containers/${record.containerId}`, { json: record });
|
|
344
|
+
}
|
|
345
|
+
async findContainerById(containerId) {
|
|
346
|
+
try {
|
|
347
|
+
const result = await this.client.get(`containers/${containerId}`).json();
|
|
348
|
+
return this.parseContainerRecord(result);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
if (this.isNotFound(error)) return null;
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async findAllContainers() {
|
|
355
|
+
const result = await this.client.get("containers").json();
|
|
356
|
+
return result.map((r) => this.parseContainerRecord(r));
|
|
357
|
+
}
|
|
358
|
+
async deleteContainer(containerId) {
|
|
359
|
+
await this.client.delete(`containers/${containerId}`);
|
|
360
|
+
}
|
|
361
|
+
async containerExists(containerId) {
|
|
362
|
+
try {
|
|
363
|
+
await this.client.head(`containers/${containerId}`);
|
|
364
|
+
return true;
|
|
365
|
+
} catch {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// ==================== Helpers ====================
|
|
370
|
+
isNotFound(error) {
|
|
371
|
+
return error?.response?.status === 404;
|
|
372
|
+
}
|
|
373
|
+
parseDefinitionRecord(raw) {
|
|
374
|
+
return {
|
|
375
|
+
...raw,
|
|
376
|
+
createdAt: new Date(raw.createdAt),
|
|
377
|
+
updatedAt: new Date(raw.updatedAt)
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
parseImageRecord(raw) {
|
|
381
|
+
return {
|
|
382
|
+
...raw,
|
|
383
|
+
createdAt: new Date(raw.createdAt)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
parseSessionRecord(raw) {
|
|
387
|
+
return {
|
|
388
|
+
...raw,
|
|
389
|
+
createdAt: new Date(raw.createdAt),
|
|
390
|
+
updatedAt: new Date(raw.updatedAt)
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
parseMessageRecord(raw) {
|
|
394
|
+
return {
|
|
395
|
+
...raw,
|
|
396
|
+
createdAt: new Date(raw.createdAt)
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
parseContainerRecord(raw) {
|
|
400
|
+
return {
|
|
401
|
+
...raw
|
|
402
|
+
// ContainerRecord uses number timestamps, no conversion needed
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
var _BrowserLogger = class _BrowserLogger {
|
|
407
|
+
constructor(name, options = {}) {
|
|
408
|
+
__publicField(this, "name");
|
|
409
|
+
__publicField(this, "level");
|
|
410
|
+
__publicField(this, "collapsed");
|
|
411
|
+
this.name = name;
|
|
412
|
+
this.level = options.level ?? LogLevel.INFO;
|
|
413
|
+
this.collapsed = options.collapsed ?? true;
|
|
414
|
+
}
|
|
415
|
+
debug(message, context) {
|
|
416
|
+
if (this.isDebugEnabled()) {
|
|
417
|
+
this.log("DEBUG", message, context);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
info(message, context) {
|
|
421
|
+
if (this.isInfoEnabled()) {
|
|
422
|
+
this.log("INFO", message, context);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
warn(message, context) {
|
|
426
|
+
if (this.isWarnEnabled()) {
|
|
427
|
+
this.log("WARN", message, context);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
error(message, context) {
|
|
431
|
+
if (this.isErrorEnabled()) {
|
|
432
|
+
if (message instanceof Error) {
|
|
433
|
+
this.log("ERROR", message.message, { ...context, stack: message.stack });
|
|
434
|
+
} else {
|
|
435
|
+
this.log("ERROR", message, context);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
isDebugEnabled() {
|
|
440
|
+
return this.level <= LogLevel.DEBUG;
|
|
441
|
+
}
|
|
442
|
+
isInfoEnabled() {
|
|
443
|
+
return this.level <= LogLevel.INFO;
|
|
444
|
+
}
|
|
445
|
+
isWarnEnabled() {
|
|
446
|
+
return this.level <= LogLevel.WARN;
|
|
447
|
+
}
|
|
448
|
+
isErrorEnabled() {
|
|
449
|
+
return this.level <= LogLevel.ERROR;
|
|
450
|
+
}
|
|
451
|
+
log(level, message, context) {
|
|
452
|
+
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
453
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
454
|
+
const badgeStyle = _BrowserLogger.BADGE_STYLES[level];
|
|
455
|
+
const format = `%c${timestamp} %c${level}%c %c[${this.name}]%c ${message}`;
|
|
456
|
+
const styles = [
|
|
457
|
+
_BrowserLogger.STYLES.TIMESTAMP,
|
|
458
|
+
badgeStyle,
|
|
459
|
+
"",
|
|
460
|
+
// reset after badge
|
|
461
|
+
_BrowserLogger.STYLES.NAME,
|
|
462
|
+
_BrowserLogger.STYLES.MESSAGE
|
|
463
|
+
];
|
|
464
|
+
if (context && Object.keys(context).length > 0) {
|
|
465
|
+
const groupMethod = this.collapsed ? console.groupCollapsed : console.group;
|
|
466
|
+
groupMethod.call(console, format, ...styles);
|
|
467
|
+
console.log("Context:", context);
|
|
468
|
+
console.groupEnd();
|
|
469
|
+
} else {
|
|
470
|
+
consoleMethod(format, ...styles);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
getConsoleMethod(level) {
|
|
474
|
+
switch (level) {
|
|
475
|
+
case "DEBUG":
|
|
476
|
+
return console.debug.bind(console);
|
|
477
|
+
case "INFO":
|
|
478
|
+
return console.info.bind(console);
|
|
479
|
+
case "WARN":
|
|
480
|
+
return console.warn.bind(console);
|
|
481
|
+
case "ERROR":
|
|
482
|
+
return console.error.bind(console);
|
|
483
|
+
default:
|
|
484
|
+
return console.log.bind(console);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
// CSS styles for different log levels
|
|
489
|
+
__publicField(_BrowserLogger, "STYLES", {
|
|
490
|
+
DEBUG: "color: #6B7280; font-weight: normal;",
|
|
491
|
+
// gray
|
|
492
|
+
INFO: "color: #10B981; font-weight: normal;",
|
|
493
|
+
// green
|
|
494
|
+
WARN: "color: #F59E0B; font-weight: bold;",
|
|
495
|
+
// amber
|
|
496
|
+
ERROR: "color: #EF4444; font-weight: bold;",
|
|
497
|
+
// red
|
|
498
|
+
TIMESTAMP: "color: #9CA3AF; font-weight: normal;",
|
|
499
|
+
// light gray
|
|
500
|
+
NAME: "color: #8B5CF6; font-weight: normal;",
|
|
501
|
+
// purple
|
|
502
|
+
MESSAGE: "color: inherit; font-weight: normal;"
|
|
503
|
+
});
|
|
504
|
+
// Badge styles for level indicators
|
|
505
|
+
__publicField(_BrowserLogger, "BADGE_STYLES", {
|
|
506
|
+
DEBUG: "background: #E5E7EB; color: #374151; padding: 2px 6px; border-radius: 3px; font-size: 11px;",
|
|
507
|
+
INFO: "background: #D1FAE5; color: #065F46; padding: 2px 6px; border-radius: 3px; font-size: 11px;",
|
|
508
|
+
WARN: "background: #FEF3C7; color: #92400E; padding: 2px 6px; border-radius: 3px; font-size: 11px;",
|
|
509
|
+
ERROR: "background: #FEE2E2; color: #991B1B; padding: 2px 6px; border-radius: 3px; font-size: 11px;"
|
|
510
|
+
});
|
|
511
|
+
var BrowserLogger = _BrowserLogger;
|
|
512
|
+
|
|
513
|
+
// src/runtime/sse/logger/BrowserLoggerFactory.ts
|
|
514
|
+
var BrowserLoggerFactory = class {
|
|
515
|
+
constructor(options = {}) {
|
|
516
|
+
__publicField(this, "options");
|
|
517
|
+
__publicField(this, "loggers", /* @__PURE__ */ new Map());
|
|
518
|
+
this.options = options;
|
|
519
|
+
}
|
|
520
|
+
getLogger(name) {
|
|
521
|
+
if (this.loggers.has(name)) {
|
|
522
|
+
return this.loggers.get(name);
|
|
523
|
+
}
|
|
524
|
+
const logger3 = new BrowserLogger(name, this.options);
|
|
525
|
+
this.loggers.set(name, logger3);
|
|
526
|
+
return logger3;
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
var logger2 = createLogger("agentx/RemoteAgentIdResolver");
|
|
530
|
+
var RemoteAgentIdResolver = class {
|
|
531
|
+
constructor(options) {
|
|
532
|
+
__publicField(this, "client");
|
|
533
|
+
this.client = createHttpClient({
|
|
534
|
+
baseUrl: options.serverUrl,
|
|
535
|
+
headers: options.headers
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
async resolveForRun(imageId, containerId) {
|
|
539
|
+
logger2.debug("Resolving agent ID for run", { imageId, containerId });
|
|
540
|
+
const response = await this.client.post(`images/${imageId}/run`, {
|
|
541
|
+
json: { containerId }
|
|
542
|
+
}).json();
|
|
543
|
+
logger2.info("Agent ID resolved for run", { imageId, agentId: response.agentId });
|
|
544
|
+
return response.agentId;
|
|
545
|
+
}
|
|
546
|
+
async resolveForResume(sessionId, containerId) {
|
|
547
|
+
logger2.debug("Resolving agent ID for resume", { sessionId, containerId });
|
|
548
|
+
const response = await this.client.post(`sessions/${sessionId}/resume`, {
|
|
549
|
+
json: { containerId }
|
|
550
|
+
}).json();
|
|
551
|
+
logger2.info("Agent ID resolved for resume", { sessionId, agentId: response.agentId });
|
|
552
|
+
return response.agentId;
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// src/runtime/sse/SSERuntime.ts
|
|
557
|
+
var noopSandbox = {
|
|
558
|
+
name: "browser-noop",
|
|
559
|
+
workspace: {
|
|
560
|
+
id: "noop",
|
|
561
|
+
name: "noop",
|
|
562
|
+
path: ""
|
|
563
|
+
// Browser has no local workspace
|
|
564
|
+
},
|
|
565
|
+
llm: {
|
|
566
|
+
name: "noop",
|
|
567
|
+
provide: () => ({})
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
var SSERuntime = class {
|
|
571
|
+
constructor(config) {
|
|
572
|
+
__publicField(this, "name", "sse");
|
|
573
|
+
__publicField(this, "repository");
|
|
574
|
+
__publicField(this, "loggerFactory");
|
|
575
|
+
__publicField(this, "agentIdResolver");
|
|
576
|
+
__publicField(this, "serverUrl");
|
|
577
|
+
__publicField(this, "headers");
|
|
578
|
+
__publicField(this, "sseParams");
|
|
579
|
+
this.serverUrl = config.serverUrl.replace(/\/+$/, "");
|
|
580
|
+
this.headers = config.headers ?? {};
|
|
581
|
+
this.sseParams = config.sseParams ?? {};
|
|
582
|
+
this.loggerFactory = new BrowserLoggerFactory({
|
|
583
|
+
collapsed: true
|
|
584
|
+
});
|
|
585
|
+
setLoggerFactory(this.loggerFactory);
|
|
586
|
+
this.repository = new RemoteRepository({
|
|
587
|
+
serverUrl: this.serverUrl,
|
|
588
|
+
headers: this.headers
|
|
589
|
+
});
|
|
590
|
+
this.agentIdResolver = new RemoteAgentIdResolver({
|
|
591
|
+
serverUrl: this.serverUrl,
|
|
592
|
+
headers: this.headers
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
createSandbox(_containerId) {
|
|
596
|
+
return noopSandbox;
|
|
597
|
+
}
|
|
598
|
+
createDriver(_definition, context, _sandbox) {
|
|
599
|
+
const driver = createSSEDriver({
|
|
600
|
+
serverUrl: this.serverUrl,
|
|
601
|
+
agentId: context.agentId,
|
|
602
|
+
headers: this.headers,
|
|
603
|
+
sseParams: this.sseParams
|
|
604
|
+
});
|
|
605
|
+
return {
|
|
606
|
+
...driver,
|
|
607
|
+
sandbox: noopSandbox
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
createLogger(name) {
|
|
611
|
+
return this.loggerFactory.getLogger(name);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
function sseRuntime(config) {
|
|
615
|
+
return new SSERuntime(config);
|
|
616
|
+
}
|
|
617
|
+
var createSSERuntime = sseRuntime;
|
|
618
|
+
|
|
619
|
+
export { BrowserLogger, BrowserLoggerFactory, RemoteRepository, SSERuntime, createSSEDriver, createSSERuntime, sseRuntime };
|
|
620
|
+
//# sourceMappingURL=index.js.map
|
|
621
|
+
//# sourceMappingURL=index.js.map
|