@agentic-surfaces/server 0.1.29 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor/assets/{index-HQKltIcN.css → index-D-uLRZZ-.css} +1 -1
- package/dist/editor/assets/index-Vur7bXRy.js +298 -0
- package/dist/editor/index.html +2 -2
- package/dist/http.d.ts +7 -0
- package/dist/http.js +74 -14
- package/dist/serve.d.ts +2 -0
- package/dist/serve.js +7 -2
- package/dist/streaming-observer.d.ts +10 -1
- package/dist/streaming-observer.js +47 -5
- package/package.json +2 -2
- package/dist/editor/assets/index-kTJFLfkQ.js +0 -298
package/dist/editor/index.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>agentic-surfaces — workflow editor</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-Vur7bXRy.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-D-uLRZZ-.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
package/dist/http.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ export interface ServerOptions {
|
|
|
56
56
|
};
|
|
57
57
|
/** Best-effort claude.ai plan usage provider, surfaced (cached) at GET /api/usage. */
|
|
58
58
|
planUsage?: () => Promise<PlanUsage | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Hot-reload hook (POST /api/reload). Re-scans the workflows + agents dirs and project config,
|
|
61
|
+
* rebuilds the in-memory workflow map, and re-registers the scheduler in place. Returns the new
|
|
62
|
+
* workflow set so the server can serve it from /api/workflows and /api/run without a restart.
|
|
63
|
+
* When omitted, POST /api/reload is 405 (reload not available in this mode, e.g. run-once).
|
|
64
|
+
*/
|
|
65
|
+
onReload?: () => Promise<Workflow[]> | Workflow[];
|
|
59
66
|
}
|
|
60
67
|
/** Build an http.Server that serves the workflow-engine API and optional static files. */
|
|
61
68
|
export declare function createServer(opts: ServerOptions): http.Server;
|
package/dist/http.js
CHANGED
|
@@ -13,6 +13,14 @@ function json(res, data, status = 200) {
|
|
|
13
13
|
function notFound(res) {
|
|
14
14
|
json(res, { error: "not found" }, 404);
|
|
15
15
|
}
|
|
16
|
+
/** Max characters of an agent's instructions body we put on the wire — bounded so a long
|
|
17
|
+
* definition can't bloat the payload (mirrors streaming-observer's OUTPUT_PREVIEW_CAP). */
|
|
18
|
+
const AGENT_BODY_CAP = 16_000;
|
|
19
|
+
function capBody(s) {
|
|
20
|
+
return s.length > AGENT_BODY_CAP
|
|
21
|
+
? `${s.slice(0, AGENT_BODY_CAP)}\n…(${s.length - AGENT_BODY_CAP} more chars truncated)`
|
|
22
|
+
: s;
|
|
23
|
+
}
|
|
16
24
|
function sseHeaders(res) {
|
|
17
25
|
res.writeHead(200, {
|
|
18
26
|
"Content-Type": "text/event-stream",
|
|
@@ -26,8 +34,15 @@ function writeEvent(res, event) {
|
|
|
26
34
|
}
|
|
27
35
|
/** Build an http.Server that serves the workflow-engine API and optional static files. */
|
|
28
36
|
export function createServer(opts) {
|
|
29
|
-
const { observer,
|
|
30
|
-
|
|
37
|
+
const { observer, staticDir, onRun, config, agents = [], cache, pause, planUsage, onReload, } = opts;
|
|
38
|
+
// Live workflow set — mutable so POST /api/reload (+ the fs.watch reload path) can swap it in
|
|
39
|
+
// place without a server restart. /api/workflows, /api/run, and the graph view all read from here.
|
|
40
|
+
let workflows = opts.workflows ?? [];
|
|
41
|
+
let workflowByName = new Map(workflows.map((w) => [w.name, w]));
|
|
42
|
+
function setWorkflows(next) {
|
|
43
|
+
workflows = next;
|
|
44
|
+
workflowByName = new Map(next.map((w) => [w.name, w]));
|
|
45
|
+
}
|
|
31
46
|
// Cache plan usage briefly — the experimental SDK call spins up a session, so don't hit it per request.
|
|
32
47
|
let usageCache = null;
|
|
33
48
|
const PLAN_USAGE_TTL_MS = 5 * 60_000;
|
|
@@ -92,7 +107,9 @@ export function createServer(opts) {
|
|
|
92
107
|
json: "application/json",
|
|
93
108
|
woff2: "font/woff2",
|
|
94
109
|
};
|
|
95
|
-
res.writeHead(200, {
|
|
110
|
+
res.writeHead(200, {
|
|
111
|
+
"Content-Type": mime[ext] ?? "application/octet-stream",
|
|
112
|
+
});
|
|
96
113
|
res.end(buf);
|
|
97
114
|
return true;
|
|
98
115
|
}
|
|
@@ -105,7 +122,10 @@ export function createServer(opts) {
|
|
|
105
122
|
const pathname = url.pathname;
|
|
106
123
|
// CORS preflight
|
|
107
124
|
if (req.method === "OPTIONS") {
|
|
108
|
-
res.writeHead(204, {
|
|
125
|
+
res.writeHead(204, {
|
|
126
|
+
"Access-Control-Allow-Origin": "*",
|
|
127
|
+
"Access-Control-Allow-Headers": "*",
|
|
128
|
+
});
|
|
109
129
|
res.end();
|
|
110
130
|
return;
|
|
111
131
|
}
|
|
@@ -116,6 +136,8 @@ export function createServer(opts) {
|
|
|
116
136
|
return {
|
|
117
137
|
name: w.name,
|
|
118
138
|
title: w.title ?? w.name,
|
|
139
|
+
// Sidebar grouping (explicit `group:` field or the file's subdir path; undefined = ungrouped).
|
|
140
|
+
group: w.group,
|
|
119
141
|
nodeCount: w.nodes.length,
|
|
120
142
|
triggerType,
|
|
121
143
|
// Full graph so the editor can render each workflow without a second fetch.
|
|
@@ -129,6 +151,25 @@ export function createServer(opts) {
|
|
|
129
151
|
}));
|
|
130
152
|
return;
|
|
131
153
|
}
|
|
154
|
+
// Hot-reload the workflow set (re-scan dirs, rebuild map, re-register the scheduler) without a
|
|
155
|
+
// restart. The CLI supplies onReload; it returns the freshly-loaded workflows, which we swap into
|
|
156
|
+
// the live set and broadcast to connected dashboards so they re-fetch.
|
|
157
|
+
if (pathname === "/api/reload" && req.method === "POST") {
|
|
158
|
+
if (!onReload) {
|
|
159
|
+
json(res, { error: "reload is not enabled on this server" }, 405);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const next = await onReload();
|
|
164
|
+
setWorkflows(next);
|
|
165
|
+
observer.notifyWorkflowsChanged();
|
|
166
|
+
json(res, { reloaded: next.length, workflows: next.map((w) => w.name) }, 200);
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
json(res, { error: err instanceof Error ? err.message : String(err) }, 500);
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
132
173
|
// Trigger a run from the UI. Fire-and-forget: progress streams via /api/events.
|
|
133
174
|
if (pathname === "/api/run" && req.method === "POST") {
|
|
134
175
|
if (!onRun) {
|
|
@@ -136,7 +177,9 @@ export function createServer(opts) {
|
|
|
136
177
|
return;
|
|
137
178
|
}
|
|
138
179
|
let body = "";
|
|
139
|
-
req.on("data", (c) => {
|
|
180
|
+
req.on("data", (c) => {
|
|
181
|
+
body += c;
|
|
182
|
+
});
|
|
140
183
|
req.on("end", () => {
|
|
141
184
|
let parsed;
|
|
142
185
|
try {
|
|
@@ -153,18 +196,25 @@ export function createServer(opts) {
|
|
|
153
196
|
}
|
|
154
197
|
// Don't await — the run streams over SSE; a thrown error is reported
|
|
155
198
|
// there (and logged by the runner), so the server keeps serving.
|
|
156
|
-
Promise.resolve(onRun(name, parsed.payload)).catch(() => {
|
|
199
|
+
Promise.resolve(onRun(name, parsed.payload)).catch(() => {
|
|
200
|
+
/* surfaced via observer */
|
|
201
|
+
});
|
|
157
202
|
json(res, { started: name }, 202);
|
|
158
203
|
});
|
|
159
204
|
return;
|
|
160
205
|
}
|
|
161
206
|
// Platform-wide play/pause. GET reports state; POST /api/pause|resume toggles the scheduler.
|
|
162
|
-
if (pathname === "/api/state" &&
|
|
163
|
-
|
|
207
|
+
if (pathname === "/api/state" &&
|
|
208
|
+
(req.method === "GET" || req.method === undefined)) {
|
|
209
|
+
json(res, {
|
|
210
|
+
paused: pause ? pause.isPaused() : false,
|
|
211
|
+
controllable: Boolean(pause),
|
|
212
|
+
});
|
|
164
213
|
return;
|
|
165
214
|
}
|
|
166
215
|
// Best-effort claude.ai plan usage (session + weekly windows) for the spend/balance box.
|
|
167
|
-
if (pathname === "/api/usage" &&
|
|
216
|
+
if (pathname === "/api/usage" &&
|
|
217
|
+
(req.method === "GET" || req.method === undefined)) {
|
|
168
218
|
const data = await getCachedPlanUsage();
|
|
169
219
|
json(res, data ?? { available: false });
|
|
170
220
|
return;
|
|
@@ -188,7 +238,8 @@ export function createServer(opts) {
|
|
|
188
238
|
return;
|
|
189
239
|
}
|
|
190
240
|
// Inspect / clear the engine seen-cache (debugging dedup state).
|
|
191
|
-
if (pathname === "/api/cache" &&
|
|
241
|
+
if (pathname === "/api/cache" &&
|
|
242
|
+
(req.method === "GET" || req.method === undefined)) {
|
|
192
243
|
json(res, cache ? cache.entries() : { seen: [], cursors: [] });
|
|
193
244
|
return;
|
|
194
245
|
}
|
|
@@ -198,7 +249,9 @@ export function createServer(opts) {
|
|
|
198
249
|
return;
|
|
199
250
|
}
|
|
200
251
|
let body = "";
|
|
201
|
-
req.on("data", (c) => {
|
|
252
|
+
req.on("data", (c) => {
|
|
253
|
+
body += c;
|
|
254
|
+
});
|
|
202
255
|
req.on("end", () => {
|
|
203
256
|
let key;
|
|
204
257
|
try {
|
|
@@ -222,10 +275,17 @@ export function createServer(opts) {
|
|
|
222
275
|
return;
|
|
223
276
|
}
|
|
224
277
|
if (pathname === "/api/agents") {
|
|
225
|
-
// Metadata
|
|
278
|
+
// Metadata + parsed frontmatter + the instructions body (capped), so the
|
|
279
|
+
// node-detail view can show an agent node's full definition file.
|
|
226
280
|
json(res, agents.map((a) => ({
|
|
227
|
-
name: a.name,
|
|
228
|
-
|
|
281
|
+
name: a.name,
|
|
282
|
+
model: a.model,
|
|
283
|
+
effort: a.effort,
|
|
284
|
+
profile: a.profile ?? null,
|
|
285
|
+
commands: a.commands ?? null,
|
|
286
|
+
fallback: a.fallback ?? null,
|
|
287
|
+
mcpServers: a.mcpServers ?? null,
|
|
288
|
+
instructions: capBody(a.instructions ?? ""),
|
|
229
289
|
})));
|
|
230
290
|
return;
|
|
231
291
|
}
|
package/dist/serve.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface ServeOptions {
|
|
|
46
46
|
};
|
|
47
47
|
/** Best-effort claude.ai plan usage provider, surfaced (cached) at GET /api/usage. */
|
|
48
48
|
planUsage?: () => Promise<import("@agentic-surfaces/core").PlanUsage | null>;
|
|
49
|
+
/** Hot-reload hook (POST /api/reload): re-scan + rebuild the workflow set + scheduler in place. */
|
|
50
|
+
onReload?: () => Promise<Workflow[]> | Workflow[];
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Locate the built editor assets to serve. Checks, in order:
|
package/dist/serve.js
CHANGED
|
@@ -31,7 +31,10 @@ export function serve(opts = {}) {
|
|
|
31
31
|
const host = opts.host ?? "127.0.0.1";
|
|
32
32
|
const staticDir = opts.staticDir ?? resolveEditorDir();
|
|
33
33
|
const server = createServer({
|
|
34
|
-
observer,
|
|
34
|
+
observer,
|
|
35
|
+
port,
|
|
36
|
+
host,
|
|
37
|
+
staticDir,
|
|
35
38
|
workflows: opts.workflows,
|
|
36
39
|
onRun: opts.onRun,
|
|
37
40
|
config: opts.config,
|
|
@@ -39,6 +42,7 @@ export function serve(opts = {}) {
|
|
|
39
42
|
cache: opts.cache,
|
|
40
43
|
pause: opts.pause,
|
|
41
44
|
planUsage: opts.planUsage,
|
|
45
|
+
onReload: opts.onReload,
|
|
42
46
|
});
|
|
43
47
|
server.listen(port, host, () => {
|
|
44
48
|
console.log(`[flow-server] listening on http://${host}:${port}`);
|
|
@@ -53,7 +57,8 @@ export function serve(opts = {}) {
|
|
|
53
57
|
// Only run when executed directly as a script (not when imported as a module).
|
|
54
58
|
const isMain = typeof process !== "undefined" &&
|
|
55
59
|
process.argv[1] != null &&
|
|
56
|
-
(process.argv[1].endsWith("serve.js") ||
|
|
60
|
+
(process.argv[1].endsWith("serve.js") ||
|
|
61
|
+
process.argv[1].endsWith("flow-server"));
|
|
57
62
|
if (isMain) {
|
|
58
63
|
const port = parseInt(process.env["PORT"] ?? "4000", 10);
|
|
59
64
|
const staticDir = process.env["STATIC_DIR"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RunObserver } from "@agentic-surfaces/core";
|
|
2
2
|
/** A single SSE-ready event that the HTTP layer will broadcast. */
|
|
3
3
|
export interface RunEvent {
|
|
4
|
-
type: "run:start" | "node:start" | "node:finish" | "node:activity" | "run:finish";
|
|
4
|
+
type: "run:start" | "node:start" | "node:finish" | "node:activity" | "run:finish" | "workflows:changed";
|
|
5
5
|
workflow: string;
|
|
6
6
|
/** Which run this event belongs to (from the executor) — lets the UI separate concurrent runs. */
|
|
7
7
|
runId?: string;
|
|
@@ -29,6 +29,15 @@ export declare class StreamingObserver implements RunObserver {
|
|
|
29
29
|
private events;
|
|
30
30
|
private listeners;
|
|
31
31
|
private emit;
|
|
32
|
+
/** Deliver an event to every listener, isolating bad listeners. */
|
|
33
|
+
private fanout;
|
|
34
|
+
/**
|
|
35
|
+
* Notify connected clients that the loaded workflow set changed (after a reload),
|
|
36
|
+
* so the dashboard re-fetches /api/workflows + refreshes the open graph. This is a
|
|
37
|
+
* transient signal, NOT part of the run history, so it is fanned out live but NOT
|
|
38
|
+
* pushed onto the buffer (it must not replay on every SSE reconnect).
|
|
39
|
+
*/
|
|
40
|
+
notifyWorkflowsChanged(): void;
|
|
32
41
|
/** Subscribe to all future events. Returns an unsubscribe function. */
|
|
33
42
|
subscribe(listener: (event: RunEvent) => void): () => void;
|
|
34
43
|
/** Return a snapshot of all buffered events (safe to call at any time). */
|
|
@@ -24,7 +24,9 @@ function runLabel(payload) {
|
|
|
24
24
|
function extractUsage(output) {
|
|
25
25
|
if (output && typeof output === "object" && "usage" in output) {
|
|
26
26
|
const u = output.usage;
|
|
27
|
-
if (u &&
|
|
27
|
+
if (u &&
|
|
28
|
+
typeof u === "object" &&
|
|
29
|
+
typeof u.totalTokens === "number") {
|
|
28
30
|
return u;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
@@ -57,6 +59,10 @@ export class StreamingObserver {
|
|
|
57
59
|
listeners = [];
|
|
58
60
|
emit(event) {
|
|
59
61
|
this.events.push(event);
|
|
62
|
+
this.fanout(event);
|
|
63
|
+
}
|
|
64
|
+
/** Deliver an event to every listener, isolating bad listeners. */
|
|
65
|
+
fanout(event) {
|
|
60
66
|
for (const listener of this.listeners) {
|
|
61
67
|
try {
|
|
62
68
|
listener(event);
|
|
@@ -66,6 +72,15 @@ export class StreamingObserver {
|
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Notify connected clients that the loaded workflow set changed (after a reload),
|
|
77
|
+
* so the dashboard re-fetches /api/workflows + refreshes the open graph. This is a
|
|
78
|
+
* transient signal, NOT part of the run history, so it is fanned out live but NOT
|
|
79
|
+
* pushed onto the buffer (it must not replay on every SSE reconnect).
|
|
80
|
+
*/
|
|
81
|
+
notifyWorkflowsChanged() {
|
|
82
|
+
this.fanout({ type: "workflows:changed", workflow: "", ts: Date.now() });
|
|
83
|
+
}
|
|
69
84
|
/** Subscribe to all future events. Returns an unsubscribe function. */
|
|
70
85
|
subscribe(listener) {
|
|
71
86
|
this.listeners.push(listener);
|
|
@@ -83,15 +98,34 @@ export class StreamingObserver {
|
|
|
83
98
|
}
|
|
84
99
|
// ── RunObserver interface ──────────────────────────────────────────────────
|
|
85
100
|
onRunStart(workflow, payload, runId) {
|
|
86
|
-
this.emit({
|
|
101
|
+
this.emit({
|
|
102
|
+
type: "run:start",
|
|
103
|
+
workflow,
|
|
104
|
+
runId,
|
|
105
|
+
label: runLabel(payload),
|
|
106
|
+
ts: Date.now(),
|
|
107
|
+
});
|
|
87
108
|
}
|
|
88
109
|
onNodeStart(nodeId, runId) {
|
|
89
110
|
// workflow name is unknown at this call-site in the core interface;
|
|
90
111
|
// emit a placeholder so the shape stays consistent.
|
|
91
|
-
this.emit({
|
|
112
|
+
this.emit({
|
|
113
|
+
type: "node:start",
|
|
114
|
+
workflow: "",
|
|
115
|
+
runId,
|
|
116
|
+
nodeId,
|
|
117
|
+
ts: Date.now(),
|
|
118
|
+
});
|
|
92
119
|
}
|
|
93
120
|
onNodeActivity(nodeId, activity, runId) {
|
|
94
|
-
this.emit({
|
|
121
|
+
this.emit({
|
|
122
|
+
type: "node:activity",
|
|
123
|
+
workflow: "",
|
|
124
|
+
runId,
|
|
125
|
+
nodeId,
|
|
126
|
+
meta: activity,
|
|
127
|
+
ts: Date.now(),
|
|
128
|
+
});
|
|
95
129
|
}
|
|
96
130
|
onNodeFinish(nodeId, status, meta, runId) {
|
|
97
131
|
// Normalize meta to { output?, error? }. `output` is the node's result (capped for the
|
|
@@ -103,7 +137,15 @@ export class StreamingObserver {
|
|
|
103
137
|
output: "output" in m ? previewOutput(m.output) : undefined,
|
|
104
138
|
usage: extractUsage(m.output),
|
|
105
139
|
};
|
|
106
|
-
this.emit({
|
|
140
|
+
this.emit({
|
|
141
|
+
type: "node:finish",
|
|
142
|
+
workflow: "",
|
|
143
|
+
runId,
|
|
144
|
+
nodeId,
|
|
145
|
+
status,
|
|
146
|
+
meta: wireMeta,
|
|
147
|
+
ts: Date.now(),
|
|
148
|
+
});
|
|
107
149
|
}
|
|
108
150
|
onRunFinish(workflow, status, runId) {
|
|
109
151
|
this.emit({ type: "run:finish", workflow, runId, status, ts: Date.now() });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-surfaces/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@agentic-surfaces/core": "0.1.
|
|
25
|
+
"@agentic-surfaces/core": "0.1.30"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|