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