@automatalabs/workflows 0.1.2 → 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/README.md +59 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -208,6 +208,60 @@ testable without a live agent — pass a stub runner.
|
|
|
208
208
|
|
|
209
209
|
---
|
|
210
210
|
|
|
211
|
+
## Listening in on the live ACP stream (events)
|
|
212
|
+
|
|
213
|
+
`createAcpRunner()` returns an `AcpAgentRunner` with a **typed event bus**. Subscribe with
|
|
214
|
+
`runner.on(name, listener)` to observe the live ACP stream of every run on that runner — streaming
|
|
215
|
+
assistant text, tool calls, usage, permissions — without touching the `run()` return value or the
|
|
216
|
+
`AgentRunner` seam.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import { createAcpRunner } from "@automatalabs/workflows";
|
|
220
|
+
|
|
221
|
+
const runner = createAcpRunner();
|
|
222
|
+
|
|
223
|
+
// ACP `sessionUpdate` discriminants are the event names; the listener payload is typed to each.
|
|
224
|
+
runner.on("agent_message_chunk", (e) => {
|
|
225
|
+
if (e.content.type === "text") process.stdout.write(e.content.text); // stream tokens as they land
|
|
226
|
+
});
|
|
227
|
+
runner.on("tool_call", (e) => console.error(`[${e.label}] tool: ${e.title}`));
|
|
228
|
+
runner.on("usage_update", (e) => console.error(`ctx ${e.used}/${e.size} tokens`));
|
|
229
|
+
|
|
230
|
+
// One catch-all for "everything": fires for EVERY session/update, carrying the raw update.
|
|
231
|
+
const off = runner.on("session_update", (e) => console.error(e.update.sessionUpdate));
|
|
232
|
+
|
|
233
|
+
await runner.run("Refactor this module and run the tests.", { label: "refactor", cwd });
|
|
234
|
+
off(); // on()/once() return an unsubscribe thunk; off(name, listener) and removeAllListeners() also exist
|
|
235
|
+
await runner.dispose();
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Event names.** The ACP `sessionUpdate` discriminants verbatim — `user_message_chunk`,
|
|
239
|
+
`agent_message_chunk`, `agent_thought_chunk`, `tool_call`, `tool_call_update`, `plan`,
|
|
240
|
+
`plan_update`, `plan_removed`, `available_commands_update`, `current_mode_update`,
|
|
241
|
+
`config_option_update`, `session_info_update`, `usage_update` — plus a few cross-cutting events:
|
|
242
|
+
|
|
243
|
+
| event | payload |
|
|
244
|
+
|-------|---------|
|
|
245
|
+
| `session_update` | `{ update }` — catch-all for **every** update, regardless of kind |
|
|
246
|
+
| `permission_request` | `{ request, outcome }` — a tool permission the runner auto-answered |
|
|
247
|
+
| `raw_message` | `{ method, message }` — a vendor extension notification (e.g. Claude `_claude/sdkMessage`) |
|
|
248
|
+
| `session_open` / `session_close` | a session opened / was released on a pooled connection |
|
|
249
|
+
| `backend_error` | `{ backendId, error }` — a pooled backend process crashed |
|
|
250
|
+
|
|
251
|
+
**Context envelope.** A pooled runner multiplexes many concurrent runs over one process, so every
|
|
252
|
+
event (except `backend_error`) carries `{ sessionId, backendId, label?, runId? }` — filter by
|
|
253
|
+
`label`/`runId` (from the run's `RunOptions`) to attribute an event to a specific run.
|
|
254
|
+
|
|
255
|
+
**Best-effort.** Listeners are observers: a throwing listener is isolated and never breaks the run,
|
|
256
|
+
the update drain, or sibling listeners.
|
|
257
|
+
|
|
258
|
+
**With `runDynamicWorkflow` / `WorkflowManager`.** Construct the runner yourself, subscribe, then
|
|
259
|
+
inject it: `runDynamicWorkflow(script, { runner })` or `new WorkflowManager({ agent: runner })`.
|
|
260
|
+
Every `agent()` call in the script then streams through your listeners (filter by `label` to tell
|
|
261
|
+
agents apart).
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
211
265
|
## The in-script DSL
|
|
212
266
|
|
|
213
267
|
The orchestration primitives are **not importable symbols**. They are **globals injected into the
|
|
@@ -310,11 +364,12 @@ parseWorkflowScript, // parse a script's meta + body
|
|
|
310
364
|
WorkflowManager, // stateful / resumable run manager
|
|
311
365
|
|
|
312
366
|
// ── ACP backend ──
|
|
313
|
-
createAcpRunner, // () => AcpAgentRunner (the default AgentRunner)
|
|
367
|
+
createAcpRunner, // () => AcpAgentRunner (the default AgentRunner; has .on(...) events)
|
|
314
368
|
AcpAgentRunner, // class — implements AgentRunner over ACP
|
|
315
369
|
selectBackend, // pick Claude vs Codex from a model/tier spec
|
|
316
370
|
ClaudeBackend, CodexBackend, // the concrete backends
|
|
317
371
|
toJsonSchema, toStrictJsonSchema,
|
|
372
|
+
TypedEventEmitter, // the tiny typed emitter backing runner.on(...)
|
|
318
373
|
|
|
319
374
|
// ── Errors ──
|
|
320
375
|
WorkflowError, WorkflowErrorCode, isWorkflowError, isProviderUsageLimit,
|
|
@@ -323,6 +378,9 @@ WorkflowError, WorkflowErrorCode, isWorkflowError, isProviderUsageLimit,
|
|
|
323
378
|
RunDynamicWorkflowOptions, WorkflowRunOptions, AgentOptions, ExecOptions,
|
|
324
379
|
WorkflowManagerOptions, CheckpointOptions, WorkflowRunResult, WorkflowSnapshot,
|
|
325
380
|
AcpPoolOptions, AgentRunner, RunOptions, AgentResult, AgentUsage, JournalEntry,
|
|
381
|
+
// ACP events: the runner.on(...) surface
|
|
382
|
+
AcpRunnerEventMap, AcpEventName, AcpEventListener, AcpEventContext,
|
|
383
|
+
AcpSessionUpdate, AcpUpdateKind, AcpPermissionEvent, AcpRawMessageEvent, AcpBackendErrorEvent,
|
|
326
384
|
```
|
|
327
385
|
|
|
328
386
|
(The DSL globals — `agent`, `parallel`, `pipeline`, … — are **not** exported; they are realm
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type { WorkflowRunOptions, AgentOptions, ExecOptions, WorkflowManagerOpti
|
|
|
5
5
|
export { WorkflowError, WorkflowErrorCode, isWorkflowError, isProviderUsageLimit, } from "@automatalabs/workflow-engine";
|
|
6
6
|
export { createAcpRunner, AcpAgentRunner, selectBackend, ClaudeBackend, CodexBackend, toJsonSchema, toStrictJsonSchema, } from "@automatalabs/acp-agents";
|
|
7
7
|
export type { AcpPoolOptions } from "@automatalabs/acp-agents";
|
|
8
|
+
export { TypedEventEmitter } from "@automatalabs/acp-agents";
|
|
9
|
+
export type { AcpRunnerEventMap, AcpEventName, AcpEventListener, AcpEventContext, AcpSessionUpdate, AcpUpdateKind, AcpPermissionEvent, AcpRawMessageEvent, AcpBackendErrorEvent, } from "@automatalabs/acp-agents";
|
|
8
10
|
export type { AgentRunner, RunOptions, AgentResult, AgentUsage } from "@automatalabs/shared-types";
|
|
9
11
|
export type { JournalEntry } from "@automatalabs/shared-types";
|
|
10
12
|
/** Options for {@link runDynamicWorkflow}. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAIjF,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAClG,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EACL,eAAe,EACf,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+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5B"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,11 @@ export { WorkflowError, WorkflowErrorCode, isWorkflowError, isProviderUsageLimit
|
|
|
18
18
|
// ── ACP backend: the default AgentRunner implementation, backend selection, the
|
|
19
19
|
// concrete backends, the pool options, and the JSON-Schema helpers. ──
|
|
20
20
|
export { createAcpRunner, AcpAgentRunner, selectBackend, ClaudeBackend, CodexBackend, toJsonSchema, toStrictJsonSchema, } from "@automatalabs/acp-agents";
|
|
21
|
+
// ── Live ACP events: `createAcpRunner().on("tool_call", evt => …)` to listen in on the
|
|
22
|
+
// stream of a run. The event map keys are ACP `sessionUpdate` discriminants plus a few
|
|
23
|
+
// cross-cutting events; each payload carries a `{ sessionId, backendId, label?, runId? }`
|
|
24
|
+
// context envelope so a pooled runner's concurrent runs are disambiguable. ──
|
|
25
|
+
export { TypedEventEmitter } from "@automatalabs/acp-agents";
|
|
21
26
|
/**
|
|
22
27
|
* Run a dynamic workflow script to a TERMINAL result, with the AgentRunner seam
|
|
23
28
|
* defaulted to the ACP backend.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automatalabs/workflows",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@automatalabs/shared-types": "0.1.2",
|
|
28
27
|
"@automatalabs/workflow-engine": "0.1.2",
|
|
29
|
-
"@automatalabs/
|
|
28
|
+
"@automatalabs/shared-types": "0.1.2",
|
|
29
|
+
"@automatalabs/acp-agents": "0.2.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc -b",
|