@axlsdk/studio 0.2.0
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 +190 -0
- package/README.md +196 -0
- package/dist/chunk-WI54GZA6.js +730 -0
- package/dist/chunk-WI54GZA6.js.map +1 -0
- package/dist/cli.cjs +880 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +133 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/assets/index-DDlRZgfC.js +150 -0
- package/dist/client/assets/index-djsvilkt.css +1 -0
- package/dist/client/index.html +13 -0
- package/dist/server/index.cjs +756 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +111 -0
- package/dist/server/index.d.ts +111 -0
- package/dist/server/index.js +11 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/server/index.ts
|
|
21
|
+
var server_exports = {};
|
|
22
|
+
__export(server_exports, {
|
|
23
|
+
ConnectionManager: () => ConnectionManager,
|
|
24
|
+
CostAggregator: () => CostAggregator,
|
|
25
|
+
createServer: () => createServer
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(server_exports);
|
|
28
|
+
var import_hono12 = require("hono");
|
|
29
|
+
var import_cors = require("hono/cors");
|
|
30
|
+
var import_serve_static = require("@hono/node-server/serve-static");
|
|
31
|
+
|
|
32
|
+
// src/server/middleware/error-handler.ts
|
|
33
|
+
async function errorHandler(c, next) {
|
|
34
|
+
try {
|
|
35
|
+
await next();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
38
|
+
const code = err.code ?? "INTERNAL_ERROR";
|
|
39
|
+
let status = 500;
|
|
40
|
+
if ("status" in err) {
|
|
41
|
+
const errStatus = err.status;
|
|
42
|
+
if (typeof errStatus === "number" && errStatus >= 400 && errStatus < 600) {
|
|
43
|
+
status = errStatus;
|
|
44
|
+
}
|
|
45
|
+
} else if (code === "NOT_FOUND" || message.includes("not found") || message.includes("not registered")) {
|
|
46
|
+
status = 404;
|
|
47
|
+
} else if (code === "VALIDATION_ERROR" || message.includes("Expected") || message.includes("invalid")) {
|
|
48
|
+
status = 400;
|
|
49
|
+
}
|
|
50
|
+
const body = {
|
|
51
|
+
ok: false,
|
|
52
|
+
error: { code, message }
|
|
53
|
+
};
|
|
54
|
+
return c.json(body, status);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/server/ws/connection-manager.ts
|
|
59
|
+
var ConnectionManager = class {
|
|
60
|
+
/** channel -> set of WS connections */
|
|
61
|
+
channels = /* @__PURE__ */ new Map();
|
|
62
|
+
/** ws -> set of subscribed channels (for cleanup) */
|
|
63
|
+
connections = /* @__PURE__ */ new Map();
|
|
64
|
+
/** Register a new WS connection. */
|
|
65
|
+
add(ws) {
|
|
66
|
+
this.connections.set(ws, /* @__PURE__ */ new Set());
|
|
67
|
+
}
|
|
68
|
+
/** Remove a WS connection and all its subscriptions. */
|
|
69
|
+
remove(ws) {
|
|
70
|
+
const channels = this.connections.get(ws);
|
|
71
|
+
if (channels) {
|
|
72
|
+
for (const ch of channels) {
|
|
73
|
+
this.channels.get(ch)?.delete(ws);
|
|
74
|
+
if (this.channels.get(ch)?.size === 0) {
|
|
75
|
+
this.channels.delete(ch);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this.connections.delete(ws);
|
|
80
|
+
}
|
|
81
|
+
/** Subscribe a connection to a channel. */
|
|
82
|
+
subscribe(ws, channel) {
|
|
83
|
+
let subs = this.channels.get(channel);
|
|
84
|
+
if (!subs) {
|
|
85
|
+
subs = /* @__PURE__ */ new Set();
|
|
86
|
+
this.channels.set(channel, subs);
|
|
87
|
+
}
|
|
88
|
+
subs.add(ws);
|
|
89
|
+
this.connections.get(ws)?.add(channel);
|
|
90
|
+
}
|
|
91
|
+
/** Unsubscribe a connection from a channel. */
|
|
92
|
+
unsubscribe(ws, channel) {
|
|
93
|
+
this.channels.get(channel)?.delete(ws);
|
|
94
|
+
if (this.channels.get(channel)?.size === 0) {
|
|
95
|
+
this.channels.delete(channel);
|
|
96
|
+
}
|
|
97
|
+
this.connections.get(ws)?.delete(channel);
|
|
98
|
+
}
|
|
99
|
+
/** Broadcast data to all subscribers of a channel. */
|
|
100
|
+
broadcast(channel, data) {
|
|
101
|
+
const subs = this.channels.get(channel);
|
|
102
|
+
if (!subs || subs.size === 0) return;
|
|
103
|
+
const msg = JSON.stringify({ type: "event", channel, data });
|
|
104
|
+
for (const ws of [...subs]) {
|
|
105
|
+
try {
|
|
106
|
+
ws.send(msg);
|
|
107
|
+
} catch {
|
|
108
|
+
this.remove(ws);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Broadcast to channel and all wildcard subscribers (e.g., trace:* matches trace:abc). */
|
|
113
|
+
broadcastWithWildcard(channel, data) {
|
|
114
|
+
this.broadcast(channel, data);
|
|
115
|
+
const colonIdx = channel.indexOf(":");
|
|
116
|
+
if (colonIdx > 0) {
|
|
117
|
+
const wildcardChannel = channel.substring(0, colonIdx) + ":*";
|
|
118
|
+
this.broadcast(wildcardChannel, data);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Get the number of active connections. */
|
|
122
|
+
get connectionCount() {
|
|
123
|
+
return this.connections.size;
|
|
124
|
+
}
|
|
125
|
+
/** Check if any connections are subscribed to a channel. */
|
|
126
|
+
hasSubscribers(channel) {
|
|
127
|
+
return (this.channels.get(channel)?.size ?? 0) > 0;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/server/ws/handler.ts
|
|
132
|
+
function createWsHandlers(connMgr) {
|
|
133
|
+
return {
|
|
134
|
+
onOpen(_event, ws) {
|
|
135
|
+
connMgr.add(ws);
|
|
136
|
+
},
|
|
137
|
+
onMessage(event, ws) {
|
|
138
|
+
let msg;
|
|
139
|
+
try {
|
|
140
|
+
msg = JSON.parse(String(event.data));
|
|
141
|
+
} catch {
|
|
142
|
+
const err = { type: "error", message: "Invalid JSON" };
|
|
143
|
+
ws.send(JSON.stringify(err));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
switch (msg.type) {
|
|
147
|
+
case "subscribe": {
|
|
148
|
+
connMgr.subscribe(ws, msg.channel);
|
|
149
|
+
const reply = { type: "subscribed", channel: msg.channel };
|
|
150
|
+
ws.send(JSON.stringify(reply));
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "unsubscribe": {
|
|
154
|
+
connMgr.unsubscribe(ws, msg.channel);
|
|
155
|
+
const reply = { type: "unsubscribed", channel: msg.channel };
|
|
156
|
+
ws.send(JSON.stringify(reply));
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case "ping": {
|
|
160
|
+
const reply = { type: "pong" };
|
|
161
|
+
ws.send(JSON.stringify(reply));
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
default: {
|
|
165
|
+
const err = { type: "error", message: `Unknown message type` };
|
|
166
|
+
ws.send(JSON.stringify(err));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
onClose(_event, ws) {
|
|
171
|
+
connMgr.remove(ws);
|
|
172
|
+
},
|
|
173
|
+
onError(_event, ws) {
|
|
174
|
+
connMgr.remove(ws);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/server/cost-aggregator.ts
|
|
180
|
+
var CostAggregator = class {
|
|
181
|
+
constructor(connMgr) {
|
|
182
|
+
this.connMgr = connMgr;
|
|
183
|
+
}
|
|
184
|
+
data = {
|
|
185
|
+
totalCost: 0,
|
|
186
|
+
totalTokens: { input: 0, output: 0, reasoning: 0 },
|
|
187
|
+
byAgent: {},
|
|
188
|
+
byModel: {},
|
|
189
|
+
byWorkflow: {}
|
|
190
|
+
};
|
|
191
|
+
/** Process a trace event and update cost data. */
|
|
192
|
+
onTrace(event) {
|
|
193
|
+
if (!event.cost && !event.tokens) return;
|
|
194
|
+
const cost = event.cost ?? 0;
|
|
195
|
+
const tokens = event.tokens ?? {};
|
|
196
|
+
this.data.totalCost += cost;
|
|
197
|
+
this.data.totalTokens.input += tokens.input ?? 0;
|
|
198
|
+
this.data.totalTokens.output += tokens.output ?? 0;
|
|
199
|
+
this.data.totalTokens.reasoning += tokens.reasoning ?? 0;
|
|
200
|
+
if (event.agent) {
|
|
201
|
+
const entry = this.data.byAgent[event.agent] ?? { cost: 0, calls: 0 };
|
|
202
|
+
entry.cost += cost;
|
|
203
|
+
entry.calls += 1;
|
|
204
|
+
this.data.byAgent[event.agent] = entry;
|
|
205
|
+
}
|
|
206
|
+
if (event.model) {
|
|
207
|
+
const entry = this.data.byModel[event.model] ?? {
|
|
208
|
+
cost: 0,
|
|
209
|
+
calls: 0,
|
|
210
|
+
tokens: { input: 0, output: 0 }
|
|
211
|
+
};
|
|
212
|
+
entry.cost += cost;
|
|
213
|
+
entry.calls += 1;
|
|
214
|
+
entry.tokens.input += tokens.input ?? 0;
|
|
215
|
+
entry.tokens.output += tokens.output ?? 0;
|
|
216
|
+
this.data.byModel[event.model] = entry;
|
|
217
|
+
}
|
|
218
|
+
if (event.workflow) {
|
|
219
|
+
const entry = this.data.byWorkflow[event.workflow] ?? { cost: 0, executions: 0 };
|
|
220
|
+
entry.cost += cost;
|
|
221
|
+
if (event.type === "workflow_start") entry.executions += 1;
|
|
222
|
+
this.data.byWorkflow[event.workflow] = entry;
|
|
223
|
+
}
|
|
224
|
+
this.connMgr.broadcast("costs", this.data);
|
|
225
|
+
}
|
|
226
|
+
/** Get current aggregated cost data. */
|
|
227
|
+
getData() {
|
|
228
|
+
return this.data;
|
|
229
|
+
}
|
|
230
|
+
/** Reset all accumulated data. */
|
|
231
|
+
reset() {
|
|
232
|
+
this.data = {
|
|
233
|
+
totalCost: 0,
|
|
234
|
+
totalTokens: { input: 0, output: 0, reasoning: 0 },
|
|
235
|
+
byAgent: {},
|
|
236
|
+
byModel: {},
|
|
237
|
+
byWorkflow: {}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/server/routes/health.ts
|
|
243
|
+
var import_hono = require("hono");
|
|
244
|
+
var app = new import_hono.Hono();
|
|
245
|
+
app.get("/health", (c) => {
|
|
246
|
+
const runtime = c.get("runtime");
|
|
247
|
+
return c.json({
|
|
248
|
+
ok: true,
|
|
249
|
+
data: {
|
|
250
|
+
status: "healthy",
|
|
251
|
+
workflows: runtime.getWorkflowNames().length,
|
|
252
|
+
agents: runtime.getAgents().length,
|
|
253
|
+
tools: runtime.getTools().length
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
var health_default = app;
|
|
258
|
+
|
|
259
|
+
// src/server/routes/workflows.ts
|
|
260
|
+
var import_hono2 = require("hono");
|
|
261
|
+
var import_axl = require("@axlsdk/axl");
|
|
262
|
+
function createWorkflowRoutes(connMgr) {
|
|
263
|
+
const app8 = new import_hono2.Hono();
|
|
264
|
+
app8.get("/workflows", (c) => {
|
|
265
|
+
const runtime = c.get("runtime");
|
|
266
|
+
const workflows = runtime.getWorkflows().map((w) => ({
|
|
267
|
+
name: w.name,
|
|
268
|
+
hasInputSchema: !!w.inputSchema,
|
|
269
|
+
hasOutputSchema: !!w.outputSchema
|
|
270
|
+
}));
|
|
271
|
+
return c.json({ ok: true, data: workflows });
|
|
272
|
+
});
|
|
273
|
+
app8.get("/workflows/:name", (c) => {
|
|
274
|
+
const runtime = c.get("runtime");
|
|
275
|
+
const name = c.req.param("name");
|
|
276
|
+
const workflow = runtime.getWorkflow(name);
|
|
277
|
+
if (!workflow) {
|
|
278
|
+
return c.json(
|
|
279
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Workflow "${name}" not found` } },
|
|
280
|
+
404
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
return c.json({
|
|
284
|
+
ok: true,
|
|
285
|
+
data: {
|
|
286
|
+
name: workflow.name,
|
|
287
|
+
inputSchema: workflow.inputSchema ? (0, import_axl.zodToJsonSchema)(workflow.inputSchema) : null,
|
|
288
|
+
outputSchema: workflow.outputSchema ? (0, import_axl.zodToJsonSchema)(workflow.outputSchema) : null
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
app8.post("/workflows/:name/execute", async (c) => {
|
|
293
|
+
const runtime = c.get("runtime");
|
|
294
|
+
const name = c.req.param("name");
|
|
295
|
+
const workflow = runtime.getWorkflow(name);
|
|
296
|
+
if (!workflow) {
|
|
297
|
+
return c.json(
|
|
298
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Workflow "${name}" not found` } },
|
|
299
|
+
404
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
const body = await c.req.json();
|
|
303
|
+
if (body.stream) {
|
|
304
|
+
const stream = runtime.stream(name, body.input ?? {}, { metadata: body.metadata });
|
|
305
|
+
const executionId = `stream-${Date.now()}`;
|
|
306
|
+
(async () => {
|
|
307
|
+
try {
|
|
308
|
+
for await (const event of stream) {
|
|
309
|
+
connMgr.broadcastWithWildcard(`execution:${executionId}`, event);
|
|
310
|
+
}
|
|
311
|
+
} catch (err) {
|
|
312
|
+
connMgr.broadcastWithWildcard(`execution:${executionId}`, {
|
|
313
|
+
type: "error",
|
|
314
|
+
message: err instanceof Error ? err.message : "Stream error"
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
})();
|
|
318
|
+
return c.json({ ok: true, data: { executionId, streaming: true } });
|
|
319
|
+
}
|
|
320
|
+
const result = await runtime.execute(name, body.input ?? {}, { metadata: body.metadata });
|
|
321
|
+
return c.json({ ok: true, data: { result } });
|
|
322
|
+
});
|
|
323
|
+
return app8;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/server/routes/executions.ts
|
|
327
|
+
var import_hono3 = require("hono");
|
|
328
|
+
var app2 = new import_hono3.Hono();
|
|
329
|
+
app2.get("/executions", (c) => {
|
|
330
|
+
const runtime = c.get("runtime");
|
|
331
|
+
const executions = runtime.getExecutions();
|
|
332
|
+
return c.json({ ok: true, data: executions });
|
|
333
|
+
});
|
|
334
|
+
app2.get("/executions/:id", async (c) => {
|
|
335
|
+
const runtime = c.get("runtime");
|
|
336
|
+
const id = c.req.param("id");
|
|
337
|
+
const execution = await runtime.getExecution(id);
|
|
338
|
+
if (!execution) {
|
|
339
|
+
return c.json(
|
|
340
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Execution "${id}" not found` } },
|
|
341
|
+
404
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
return c.json({ ok: true, data: execution });
|
|
345
|
+
});
|
|
346
|
+
app2.post("/executions/:id/abort", (c) => {
|
|
347
|
+
const runtime = c.get("runtime");
|
|
348
|
+
const id = c.req.param("id");
|
|
349
|
+
runtime.abort(id);
|
|
350
|
+
return c.json({ ok: true, data: { aborted: true } });
|
|
351
|
+
});
|
|
352
|
+
var executions_default = app2;
|
|
353
|
+
|
|
354
|
+
// src/server/routes/sessions.ts
|
|
355
|
+
var import_hono4 = require("hono");
|
|
356
|
+
function createSessionRoutes(connMgr) {
|
|
357
|
+
const app8 = new import_hono4.Hono();
|
|
358
|
+
app8.get("/sessions", async (c) => {
|
|
359
|
+
const runtime = c.get("runtime");
|
|
360
|
+
const store = runtime.getStateStore();
|
|
361
|
+
if (!store.listSessions) {
|
|
362
|
+
return c.json({ ok: true, data: [] });
|
|
363
|
+
}
|
|
364
|
+
const ids = await store.listSessions();
|
|
365
|
+
const sessions = [];
|
|
366
|
+
for (const id of ids) {
|
|
367
|
+
const history = await store.getSession(id);
|
|
368
|
+
sessions.push({ id, messageCount: history.length });
|
|
369
|
+
}
|
|
370
|
+
return c.json({ ok: true, data: sessions });
|
|
371
|
+
});
|
|
372
|
+
app8.get("/sessions/:id", async (c) => {
|
|
373
|
+
const runtime = c.get("runtime");
|
|
374
|
+
const store = runtime.getStateStore();
|
|
375
|
+
const id = c.req.param("id");
|
|
376
|
+
const history = await store.getSession(id);
|
|
377
|
+
const handoffHistory = await store.getSessionMeta(id, "handoffHistory");
|
|
378
|
+
return c.json({ ok: true, data: { id, history, handoffHistory: handoffHistory ?? [] } });
|
|
379
|
+
});
|
|
380
|
+
app8.post("/sessions/:id/send", async (c) => {
|
|
381
|
+
const runtime = c.get("runtime");
|
|
382
|
+
const id = c.req.param("id");
|
|
383
|
+
const body = await c.req.json();
|
|
384
|
+
const session = runtime.session(id);
|
|
385
|
+
const result = await session.send(body.workflow, body.message);
|
|
386
|
+
return c.json({ ok: true, data: { result } });
|
|
387
|
+
});
|
|
388
|
+
app8.post("/sessions/:id/stream", async (c) => {
|
|
389
|
+
const runtime = c.get("runtime");
|
|
390
|
+
const id = c.req.param("id");
|
|
391
|
+
const body = await c.req.json();
|
|
392
|
+
const session = runtime.session(id);
|
|
393
|
+
const stream = await session.stream(body.workflow, body.message);
|
|
394
|
+
const executionId = `session-${id}-${Date.now()}`;
|
|
395
|
+
(async () => {
|
|
396
|
+
try {
|
|
397
|
+
for await (const event of stream) {
|
|
398
|
+
connMgr.broadcastWithWildcard(`execution:${executionId}`, event);
|
|
399
|
+
}
|
|
400
|
+
} catch (err) {
|
|
401
|
+
connMgr.broadcastWithWildcard(`execution:${executionId}`, {
|
|
402
|
+
type: "error",
|
|
403
|
+
message: err instanceof Error ? err.message : "Stream error"
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
})();
|
|
407
|
+
return c.json({ ok: true, data: { executionId, streaming: true } });
|
|
408
|
+
});
|
|
409
|
+
app8.delete("/sessions/:id", async (c) => {
|
|
410
|
+
const runtime = c.get("runtime");
|
|
411
|
+
const store = runtime.getStateStore();
|
|
412
|
+
const id = c.req.param("id");
|
|
413
|
+
await store.deleteSession(id);
|
|
414
|
+
return c.json({ ok: true, data: { deleted: true } });
|
|
415
|
+
});
|
|
416
|
+
return app8;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/server/routes/agents.ts
|
|
420
|
+
var import_hono5 = require("hono");
|
|
421
|
+
var import_axl2 = require("@axlsdk/axl");
|
|
422
|
+
var app3 = new import_hono5.Hono();
|
|
423
|
+
app3.get("/agents", (c) => {
|
|
424
|
+
const runtime = c.get("runtime");
|
|
425
|
+
const agents = runtime.getAgents().map((a) => ({
|
|
426
|
+
name: a._name,
|
|
427
|
+
model: a.resolveModel(),
|
|
428
|
+
system: a.resolveSystem(),
|
|
429
|
+
tools: a._config.tools?.map((t) => t.name) ?? [],
|
|
430
|
+
handoffs: a._config.handoffs?.map((h) => h.agent._name) ?? [],
|
|
431
|
+
maxTurns: a._config.maxTurns,
|
|
432
|
+
temperature: a._config.temperature
|
|
433
|
+
}));
|
|
434
|
+
return c.json({ ok: true, data: agents });
|
|
435
|
+
});
|
|
436
|
+
app3.get("/agents/:name", (c) => {
|
|
437
|
+
const runtime = c.get("runtime");
|
|
438
|
+
const name = c.req.param("name");
|
|
439
|
+
const agent = runtime.getAgent(name);
|
|
440
|
+
if (!agent) {
|
|
441
|
+
return c.json(
|
|
442
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Agent "${name}" not found` } },
|
|
443
|
+
404
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
const cfg = agent._config;
|
|
447
|
+
return c.json({
|
|
448
|
+
ok: true,
|
|
449
|
+
data: {
|
|
450
|
+
name: agent._name,
|
|
451
|
+
model: agent.resolveModel(),
|
|
452
|
+
system: agent.resolveSystem(),
|
|
453
|
+
tools: cfg.tools?.map((t) => ({
|
|
454
|
+
name: t.name,
|
|
455
|
+
description: t.description,
|
|
456
|
+
inputSchema: (0, import_axl2.zodToJsonSchema)(t.inputSchema)
|
|
457
|
+
})) ?? [],
|
|
458
|
+
handoffs: cfg.handoffs?.map((h) => ({
|
|
459
|
+
agent: h.agent._name,
|
|
460
|
+
description: h.description,
|
|
461
|
+
mode: h.mode ?? "oneway"
|
|
462
|
+
})) ?? [],
|
|
463
|
+
maxTurns: cfg.maxTurns,
|
|
464
|
+
temperature: cfg.temperature,
|
|
465
|
+
timeout: cfg.timeout,
|
|
466
|
+
maxContext: cfg.maxContext,
|
|
467
|
+
version: cfg.version,
|
|
468
|
+
mcp: cfg.mcp,
|
|
469
|
+
mcpTools: cfg.mcpTools,
|
|
470
|
+
hasGuardrails: !!cfg.guardrails,
|
|
471
|
+
guardrails: cfg.guardrails ? {
|
|
472
|
+
hasInput: !!cfg.guardrails.input,
|
|
473
|
+
hasOutput: !!cfg.guardrails.output,
|
|
474
|
+
onBlock: cfg.guardrails.onBlock ?? "throw",
|
|
475
|
+
maxRetries: cfg.guardrails.maxRetries
|
|
476
|
+
} : null
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
var agents_default = app3;
|
|
481
|
+
|
|
482
|
+
// src/server/routes/tools.ts
|
|
483
|
+
var import_hono6 = require("hono");
|
|
484
|
+
var import_axl3 = require("@axlsdk/axl");
|
|
485
|
+
var app4 = new import_hono6.Hono();
|
|
486
|
+
app4.get("/tools", (c) => {
|
|
487
|
+
const runtime = c.get("runtime");
|
|
488
|
+
const tools = runtime.getTools().map((t) => ({
|
|
489
|
+
name: t.name,
|
|
490
|
+
description: t.description,
|
|
491
|
+
inputSchema: t.inputSchema ? (0, import_axl3.zodToJsonSchema)(t.inputSchema) : {},
|
|
492
|
+
sensitive: t.sensitive ?? false,
|
|
493
|
+
requireApproval: t.requireApproval ?? false
|
|
494
|
+
}));
|
|
495
|
+
return c.json({ ok: true, data: tools });
|
|
496
|
+
});
|
|
497
|
+
app4.get("/tools/:name", (c) => {
|
|
498
|
+
const runtime = c.get("runtime");
|
|
499
|
+
const name = c.req.param("name");
|
|
500
|
+
const tool = runtime.getTool(name);
|
|
501
|
+
if (!tool) {
|
|
502
|
+
return c.json(
|
|
503
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Tool "${name}" not found` } },
|
|
504
|
+
404
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
return c.json({
|
|
508
|
+
ok: true,
|
|
509
|
+
data: {
|
|
510
|
+
name: tool.name,
|
|
511
|
+
description: tool.description,
|
|
512
|
+
inputSchema: tool.inputSchema ? (0, import_axl3.zodToJsonSchema)(tool.inputSchema) : {},
|
|
513
|
+
sensitive: tool.sensitive,
|
|
514
|
+
requireApproval: tool.requireApproval,
|
|
515
|
+
retry: tool.retry,
|
|
516
|
+
hasHooks: !!tool.hooks,
|
|
517
|
+
hooks: tool.hooks ? {
|
|
518
|
+
hasBefore: !!tool.hooks.before,
|
|
519
|
+
hasAfter: !!tool.hooks.after
|
|
520
|
+
} : null
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
app4.post("/tools/:name/test", async (c) => {
|
|
525
|
+
const runtime = c.get("runtime");
|
|
526
|
+
const name = c.req.param("name");
|
|
527
|
+
const tool = runtime.getTool(name);
|
|
528
|
+
if (!tool) {
|
|
529
|
+
return c.json(
|
|
530
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Tool "${name}" not found` } },
|
|
531
|
+
404
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
const body = await c.req.json();
|
|
535
|
+
const result = await tool._execute(body.input);
|
|
536
|
+
return c.json({ ok: true, data: { result } });
|
|
537
|
+
});
|
|
538
|
+
var tools_default = app4;
|
|
539
|
+
|
|
540
|
+
// src/server/routes/memory.ts
|
|
541
|
+
var import_hono7 = require("hono");
|
|
542
|
+
var app5 = new import_hono7.Hono();
|
|
543
|
+
app5.get("/memory/:scope", async (c) => {
|
|
544
|
+
const runtime = c.get("runtime");
|
|
545
|
+
const store = runtime.getStateStore();
|
|
546
|
+
const scope = c.req.param("scope");
|
|
547
|
+
if (!store.getAllMemory) {
|
|
548
|
+
return c.json({ ok: true, data: [] });
|
|
549
|
+
}
|
|
550
|
+
const entries = await store.getAllMemory(scope);
|
|
551
|
+
return c.json({ ok: true, data: entries });
|
|
552
|
+
});
|
|
553
|
+
app5.get("/memory/:scope/:key", async (c) => {
|
|
554
|
+
const runtime = c.get("runtime");
|
|
555
|
+
const store = runtime.getStateStore();
|
|
556
|
+
const scope = c.req.param("scope");
|
|
557
|
+
const key = c.req.param("key");
|
|
558
|
+
if (!store.getMemory) {
|
|
559
|
+
return c.json(
|
|
560
|
+
{ ok: false, error: { code: "NOT_SUPPORTED", message: "Memory not supported" } },
|
|
561
|
+
501
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
const value = await store.getMemory(scope, key);
|
|
565
|
+
if (value === null) {
|
|
566
|
+
return c.json(
|
|
567
|
+
{ ok: false, error: { code: "NOT_FOUND", message: `Memory "${scope}/${key}" not found` } },
|
|
568
|
+
404
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
return c.json({ ok: true, data: { key, value } });
|
|
572
|
+
});
|
|
573
|
+
app5.put("/memory/:scope/:key", async (c) => {
|
|
574
|
+
const runtime = c.get("runtime");
|
|
575
|
+
const store = runtime.getStateStore();
|
|
576
|
+
const scope = c.req.param("scope");
|
|
577
|
+
const key = c.req.param("key");
|
|
578
|
+
if (!store.saveMemory) {
|
|
579
|
+
return c.json(
|
|
580
|
+
{ ok: false, error: { code: "NOT_SUPPORTED", message: "Memory not supported" } },
|
|
581
|
+
501
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
const body = await c.req.json();
|
|
585
|
+
await store.saveMemory(scope, key, body.value);
|
|
586
|
+
return c.json({ ok: true, data: { saved: true } });
|
|
587
|
+
});
|
|
588
|
+
app5.delete("/memory/:scope/:key", async (c) => {
|
|
589
|
+
const runtime = c.get("runtime");
|
|
590
|
+
const store = runtime.getStateStore();
|
|
591
|
+
const scope = c.req.param("scope");
|
|
592
|
+
const key = c.req.param("key");
|
|
593
|
+
if (!store.deleteMemory) {
|
|
594
|
+
return c.json(
|
|
595
|
+
{ ok: false, error: { code: "NOT_SUPPORTED", message: "Memory not supported" } },
|
|
596
|
+
501
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
await store.deleteMemory(scope, key);
|
|
600
|
+
return c.json({ ok: true, data: { deleted: true } });
|
|
601
|
+
});
|
|
602
|
+
app5.post("/memory/search", async (c) => {
|
|
603
|
+
return c.json({
|
|
604
|
+
ok: true,
|
|
605
|
+
data: { results: [], message: "Semantic search requires MemoryManager with vector store" }
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
var memory_default = app5;
|
|
609
|
+
|
|
610
|
+
// src/server/routes/decisions.ts
|
|
611
|
+
var import_hono8 = require("hono");
|
|
612
|
+
var app6 = new import_hono8.Hono();
|
|
613
|
+
app6.get("/decisions", async (c) => {
|
|
614
|
+
const runtime = c.get("runtime");
|
|
615
|
+
const decisions = await runtime.getPendingDecisions();
|
|
616
|
+
return c.json({ ok: true, data: decisions });
|
|
617
|
+
});
|
|
618
|
+
app6.post("/decisions/:executionId/resolve", async (c) => {
|
|
619
|
+
const runtime = c.get("runtime");
|
|
620
|
+
const executionId = c.req.param("executionId");
|
|
621
|
+
const body = await c.req.json();
|
|
622
|
+
await runtime.resolveDecision(executionId, body);
|
|
623
|
+
return c.json({ ok: true, data: { resolved: true } });
|
|
624
|
+
});
|
|
625
|
+
var decisions_default = app6;
|
|
626
|
+
|
|
627
|
+
// src/server/routes/costs.ts
|
|
628
|
+
var import_hono9 = require("hono");
|
|
629
|
+
function createCostRoutes(costAggregator) {
|
|
630
|
+
const app8 = new import_hono9.Hono();
|
|
631
|
+
app8.get("/costs", (c) => {
|
|
632
|
+
return c.json({ ok: true, data: costAggregator.getData() });
|
|
633
|
+
});
|
|
634
|
+
app8.post("/costs/reset", (c) => {
|
|
635
|
+
costAggregator.reset();
|
|
636
|
+
return c.json({ ok: true, data: { reset: true } });
|
|
637
|
+
});
|
|
638
|
+
return app8;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// src/server/routes/evals.ts
|
|
642
|
+
var import_hono10 = require("hono");
|
|
643
|
+
var app7 = new import_hono10.Hono();
|
|
644
|
+
app7.get("/evals", async (c) => {
|
|
645
|
+
return c.json({ ok: true, data: { message: "Eval discovery requires @axlsdk/eval" } });
|
|
646
|
+
});
|
|
647
|
+
app7.post("/evals/run", async (c) => {
|
|
648
|
+
const runtime = c.get("runtime");
|
|
649
|
+
const body = await c.req.json();
|
|
650
|
+
try {
|
|
651
|
+
const result = await runtime.eval(body);
|
|
652
|
+
return c.json({ ok: true, data: result });
|
|
653
|
+
} catch (err) {
|
|
654
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
655
|
+
return c.json({ ok: false, error: { code: "EVAL_ERROR", message } }, 400);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
app7.post("/evals/compare", async (c) => {
|
|
659
|
+
const runtime = c.get("runtime");
|
|
660
|
+
const body = await c.req.json();
|
|
661
|
+
try {
|
|
662
|
+
const result = await runtime.evalCompare(body.baseline, body.candidate);
|
|
663
|
+
return c.json({ ok: true, data: result });
|
|
664
|
+
} catch (err) {
|
|
665
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
666
|
+
return c.json({ ok: false, error: { code: "EVAL_ERROR", message } }, 400);
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
var evals_default = app7;
|
|
670
|
+
|
|
671
|
+
// src/server/routes/playground.ts
|
|
672
|
+
var import_hono11 = require("hono");
|
|
673
|
+
function createPlaygroundRoutes(connMgr) {
|
|
674
|
+
const app8 = new import_hono11.Hono();
|
|
675
|
+
app8.post("/playground/chat", async (c) => {
|
|
676
|
+
const runtime = c.get("runtime");
|
|
677
|
+
const body = await c.req.json();
|
|
678
|
+
const workflowName = body.workflow ?? runtime.getWorkflowNames()[0];
|
|
679
|
+
if (!workflowName) {
|
|
680
|
+
return c.json(
|
|
681
|
+
{ ok: false, error: { code: "NO_WORKFLOW", message: "No workflows registered" } },
|
|
682
|
+
400
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
const sessionId = body.sessionId ?? `playground-${Date.now()}`;
|
|
686
|
+
const session = runtime.session(sessionId);
|
|
687
|
+
const stream = await session.stream(workflowName, body.message);
|
|
688
|
+
const executionId = `playground-${sessionId}-${Date.now()}`;
|
|
689
|
+
(async () => {
|
|
690
|
+
try {
|
|
691
|
+
for await (const event of stream) {
|
|
692
|
+
connMgr.broadcastWithWildcard(`execution:${executionId}`, event);
|
|
693
|
+
}
|
|
694
|
+
} catch (err) {
|
|
695
|
+
connMgr.broadcastWithWildcard(`execution:${executionId}`, {
|
|
696
|
+
type: "error",
|
|
697
|
+
message: err instanceof Error ? err.message : "Stream error"
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
})();
|
|
701
|
+
return c.json({
|
|
702
|
+
ok: true,
|
|
703
|
+
data: { sessionId, executionId, streaming: true }
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
return app8;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/server/index.ts
|
|
710
|
+
function createServer(options) {
|
|
711
|
+
const { runtime, staticRoot } = options;
|
|
712
|
+
const app8 = new import_hono12.Hono();
|
|
713
|
+
const connMgr = new ConnectionManager();
|
|
714
|
+
const costAggregator = new CostAggregator(connMgr);
|
|
715
|
+
app8.use("*", (0, import_cors.cors)());
|
|
716
|
+
app8.use("*", errorHandler);
|
|
717
|
+
app8.use("*", async (c, next) => {
|
|
718
|
+
c.set("runtime", runtime);
|
|
719
|
+
await next();
|
|
720
|
+
});
|
|
721
|
+
const api = new import_hono12.Hono();
|
|
722
|
+
api.route("/", health_default);
|
|
723
|
+
api.route("/", createWorkflowRoutes(connMgr));
|
|
724
|
+
api.route("/", executions_default);
|
|
725
|
+
api.route("/", createSessionRoutes(connMgr));
|
|
726
|
+
api.route("/", agents_default);
|
|
727
|
+
api.route("/", tools_default);
|
|
728
|
+
api.route("/", memory_default);
|
|
729
|
+
api.route("/", decisions_default);
|
|
730
|
+
api.route("/", createCostRoutes(costAggregator));
|
|
731
|
+
api.route("/", evals_default);
|
|
732
|
+
api.route("/", createPlaygroundRoutes(connMgr));
|
|
733
|
+
app8.route("/api", api);
|
|
734
|
+
runtime.on("trace", (event) => {
|
|
735
|
+
const traceEvent = event;
|
|
736
|
+
if (traceEvent.executionId) {
|
|
737
|
+
connMgr.broadcastWithWildcard(`trace:${traceEvent.executionId}`, traceEvent);
|
|
738
|
+
}
|
|
739
|
+
costAggregator.onTrace(traceEvent);
|
|
740
|
+
if (traceEvent.type === "await_human") {
|
|
741
|
+
connMgr.broadcast("decisions", traceEvent);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
if (staticRoot) {
|
|
745
|
+
app8.use("/*", (0, import_serve_static.serveStatic)({ root: staticRoot }));
|
|
746
|
+
app8.get("*", (0, import_serve_static.serveStatic)({ root: staticRoot, path: "/index.html" }));
|
|
747
|
+
}
|
|
748
|
+
return { app: app8, connMgr, costAggregator, createWsHandlers: () => createWsHandlers(connMgr) };
|
|
749
|
+
}
|
|
750
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
751
|
+
0 && (module.exports = {
|
|
752
|
+
ConnectionManager,
|
|
753
|
+
CostAggregator,
|
|
754
|
+
createServer
|
|
755
|
+
});
|
|
756
|
+
//# sourceMappingURL=index.cjs.map
|