@agentic-surfaces/server 0.1.26 → 0.1.27

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.
@@ -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-B8bv4dx-.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index-Cjovr7EX.css">
7
+ <script type="module" crossorigin src="/assets/index-CS8llYsy.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/assets/index-CQwBaAEq.css">
9
9
  </head>
10
10
  <body>
11
11
  <div id="root"></div>
package/dist/http.d.ts CHANGED
@@ -47,6 +47,12 @@ export interface ServerOptions {
47
47
  };
48
48
  forget(key: string): void;
49
49
  };
50
+ /** Platform-wide play/pause switch, surfaced at GET /api/state and toggled via POST /api/pause|resume. */
51
+ pause?: {
52
+ isPaused(): boolean;
53
+ pause(): void;
54
+ resume(): void;
55
+ };
50
56
  }
51
57
  /** Build an http.Server that serves the workflow-engine API and optional static files. */
52
58
  export declare function createServer(opts: ServerOptions): http.Server;
package/dist/http.js CHANGED
@@ -26,7 +26,7 @@ function writeEvent(res, event) {
26
26
  }
27
27
  /** Build an http.Server that serves the workflow-engine API and optional static files. */
28
28
  export function createServer(opts) {
29
- const { observer, workflows = [], staticDir, onRun, config, agents = [], cache } = opts;
29
+ const { observer, workflows = [], staticDir, onRun, config, agents = [], cache, pause } = opts;
30
30
  const workflowByName = new Map(workflows.map((w) => [w.name, w]));
31
31
  // In-memory run registry — populated by listening to the observer.
32
32
  const runs = new Map();
@@ -140,6 +140,29 @@ export function createServer(opts) {
140
140
  });
141
141
  return;
142
142
  }
143
+ // Platform-wide play/pause. GET reports state; POST /api/pause|resume toggles the scheduler.
144
+ if (pathname === "/api/state" && (req.method === "GET" || req.method === undefined)) {
145
+ json(res, { paused: pause ? pause.isPaused() : false, controllable: Boolean(pause) });
146
+ return;
147
+ }
148
+ if (pathname === "/api/pause" && req.method === "POST") {
149
+ if (!pause) {
150
+ json(res, { error: "pause not available" }, 405);
151
+ return;
152
+ }
153
+ pause.pause();
154
+ json(res, { paused: true });
155
+ return;
156
+ }
157
+ if (pathname === "/api/resume" && req.method === "POST") {
158
+ if (!pause) {
159
+ json(res, { error: "pause not available" }, 405);
160
+ return;
161
+ }
162
+ pause.resume();
163
+ json(res, { paused: false });
164
+ return;
165
+ }
143
166
  // Inspect / clear the engine seen-cache (debugging dedup state).
144
167
  if (pathname === "/api/cache" && (req.method === "GET" || req.method === undefined)) {
145
168
  json(res, cache ? cache.entries() : { seen: [], cursors: [] });
package/dist/serve.d.ts CHANGED
@@ -37,6 +37,12 @@ export interface ServeOptions {
37
37
  };
38
38
  forget(key: string): void;
39
39
  };
40
+ /** Platform-wide play/pause switch, surfaced at GET /api/state and POST /api/pause|resume. */
41
+ pause?: {
42
+ isPaused(): boolean;
43
+ pause(): void;
44
+ resume(): void;
45
+ };
40
46
  }
41
47
  /**
42
48
  * Locate the built editor assets to serve. Checks, in order:
package/dist/serve.js CHANGED
@@ -37,6 +37,7 @@ export function serve(opts = {}) {
37
37
  config: opts.config,
38
38
  agents: opts.agents,
39
39
  cache: opts.cache,
40
+ pause: opts.pause,
40
41
  });
41
42
  server.listen(port, host, () => {
42
43
  console.log(`[flow-server] listening on http://${host}:${port}`);
@@ -10,6 +10,15 @@ export interface RunEvent {
10
10
  meta?: unknown;
11
11
  ts: number;
12
12
  }
13
+ /** Token usage + cost for one agent node (mirrors the engine's RunUsage). */
14
+ export interface NodeUsage {
15
+ inputTokens: number;
16
+ outputTokens: number;
17
+ cacheReadTokens: number;
18
+ cacheCreationTokens: number;
19
+ totalTokens: number;
20
+ costUsd: number;
21
+ }
13
22
  /**
14
23
  * StreamingObserver implements RunObserver and buffers events so the HTTP
15
24
  * layer can retrieve them by run or stream them to connected SSE clients.
@@ -20,6 +20,16 @@ function runLabel(payload) {
20
20
  return undefined;
21
21
  }
22
22
  }
23
+ /** Lift a structured `usage` block out of an agent node's output (undefined for non-agent nodes). */
24
+ function extractUsage(output) {
25
+ if (output && typeof output === "object" && "usage" in output) {
26
+ const u = output.usage;
27
+ if (u && typeof u === "object" && typeof u.totalTokens === "number") {
28
+ return u;
29
+ }
30
+ }
31
+ return undefined;
32
+ }
23
33
  /** Max characters of a node's output we put on the wire — enough to debug, bounded
24
34
  * so a large HTTP response (e.g. a full comment thread) can't bloat the SSE stream. */
25
35
  const OUTPUT_PREVIEW_CAP = 16_000;
@@ -86,10 +96,12 @@ export class StreamingObserver {
86
96
  onNodeFinish(nodeId, status, meta) {
87
97
  // Normalize meta to { output?, error? }. `output` is the node's result (capped for the
88
98
  // wire) so the UI can show what each node fetched/produced; `error` carries failures.
99
+ // `usage` is lifted out as a structured field (agent nodes only) so the UI can sum a run total.
89
100
  const m = (meta ?? {});
90
101
  const wireMeta = {
91
102
  error: m.error,
92
103
  output: "output" in m ? previewOutput(m.output) : undefined,
104
+ usage: extractUsage(m.output),
93
105
  };
94
106
  this.emit({ type: "node:finish", workflow: "", nodeId, status, meta: wireMeta, ts: Date.now() });
95
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentic-surfaces/server",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
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.26"
25
+ "@agentic-surfaces/core": "0.1.27"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",