@agentic-surfaces/core 0.1.26 → 0.1.28
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/executor.js +14 -6
- package/dist/handlers/agent.js +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pause.d.ts +21 -0
- package/dist/pause.js +26 -0
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.js +3 -0
- package/dist/scheduler.d.ts +6 -1
- package/dist/scheduler.js +20 -9
- package/dist/types.d.ts +7 -5
- package/package.json +2 -2
package/dist/executor.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { withRetry } from "./policy.js";
|
|
2
|
+
// Process-global, monotonic run-id counter. Each runWorkflow() call (top-level or a foreach
|
|
3
|
+
// sub-run) gets a distinct id so the dashboard can attribute every event to its own run.
|
|
4
|
+
let runSeq = 0;
|
|
5
|
+
function newRunId() {
|
|
6
|
+
return `run_${(++runSeq).toString(16).padStart(6, "0")}`;
|
|
7
|
+
}
|
|
2
8
|
export async function runWorkflow(opts) {
|
|
3
9
|
const { workflow, triggerNodeId, registry, services, payload, observer } = opts;
|
|
4
10
|
const byId = new Map(workflow.nodes.map(n => [n.id, n]));
|
|
@@ -10,9 +16,11 @@ export async function runWorkflow(opts) {
|
|
|
10
16
|
services,
|
|
11
17
|
observer,
|
|
12
18
|
};
|
|
19
|
+
const runId = newRunId();
|
|
20
|
+
ctx.runId = runId; // so handlers (agent.run) can tag their activity with this run
|
|
13
21
|
const queue = [triggerNodeId];
|
|
14
22
|
const visited = new Set();
|
|
15
|
-
observer?.onRunStart?.(workflow.name, ctx.triggerPayload);
|
|
23
|
+
observer?.onRunStart?.(workflow.name, ctx.triggerPayload, runId);
|
|
16
24
|
while (queue.length > 0) {
|
|
17
25
|
const id = queue.shift();
|
|
18
26
|
if (visited.has(id))
|
|
@@ -22,7 +30,7 @@ export async function runWorkflow(opts) {
|
|
|
22
30
|
if (!node)
|
|
23
31
|
throw new Error(`workflow references missing node: ${id}`);
|
|
24
32
|
const handler = registry.get(node.type);
|
|
25
|
-
observer?.onNodeStart?.(id);
|
|
33
|
+
observer?.onNodeStart?.(id, runId);
|
|
26
34
|
let result;
|
|
27
35
|
let nodeErrored = false;
|
|
28
36
|
try {
|
|
@@ -32,12 +40,12 @@ export async function runWorkflow(opts) {
|
|
|
32
40
|
nodeErrored = true;
|
|
33
41
|
const message = err instanceof Error ? err.message : String(err);
|
|
34
42
|
services.logger?.error?.(`node ${node.id} failed`, { workflow: workflow.name, error: message });
|
|
35
|
-
observer?.onNodeFinish?.(id, "failed", { error: message });
|
|
43
|
+
observer?.onNodeFinish?.(id, "failed", { error: message }, runId);
|
|
36
44
|
if (node.onError === "continue") {
|
|
37
45
|
result = { output: { error: message } };
|
|
38
46
|
}
|
|
39
47
|
else {
|
|
40
|
-
observer?.onRunFinish?.(workflow.name, "failed");
|
|
48
|
+
observer?.onRunFinish?.(workflow.name, "failed", runId);
|
|
41
49
|
throw err;
|
|
42
50
|
}
|
|
43
51
|
}
|
|
@@ -45,7 +53,7 @@ export async function runWorkflow(opts) {
|
|
|
45
53
|
// Surface the node's output so observers (e.g. the live UI) can show what each
|
|
46
54
|
// node produced/fetched — the data is what you need when debugging a run.
|
|
47
55
|
if (!nodeErrored)
|
|
48
|
-
observer?.onNodeFinish?.(id, "success", { output: result.output });
|
|
56
|
+
observer?.onNodeFinish?.(id, "success", { output: result.output }, runId);
|
|
49
57
|
const branches = result.branches;
|
|
50
58
|
for (const edge of workflow.edges) {
|
|
51
59
|
if (edge.from !== id)
|
|
@@ -55,6 +63,6 @@ export async function runWorkflow(opts) {
|
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
|
-
observer?.onRunFinish?.(workflow.name, "success");
|
|
66
|
+
observer?.onRunFinish?.(workflow.name, "success", runId);
|
|
59
67
|
return ctx.outputs;
|
|
60
68
|
}
|
package/dist/handlers/agent.js
CHANGED
|
@@ -64,8 +64,8 @@ export const agentHandler = {
|
|
|
64
64
|
cwd: ctx.services.projectDir,
|
|
65
65
|
dryRun: ctx.services.dryRun,
|
|
66
66
|
log: (m) => ctx.services.logger?.info?.(m),
|
|
67
|
-
// Stream the agent's reasoning + tool/MCP calls to the run observer, tagged with
|
|
68
|
-
onActivity: (a) => ctx.observer?.onNodeActivity?.(node.id, a),
|
|
67
|
+
// Stream the agent's reasoning + tool/MCP calls to the run observer, tagged with node + run.
|
|
68
|
+
onActivity: (a) => ctx.observer?.onNodeActivity?.(node.id, a, ctx.runId),
|
|
69
69
|
});
|
|
70
70
|
// Decision agent: guarantee the chosen command is on the allowlist (else use
|
|
71
71
|
// the fallback), and surface it at the top level so task.branch can route.
|
|
@@ -79,11 +79,11 @@ export const agentHandler = {
|
|
|
79
79
|
else
|
|
80
80
|
throw new Error(`agent ${cfg.agent} returned an off-allowlist command: ${String(raw)}`);
|
|
81
81
|
}
|
|
82
|
-
return { output: { command, text: result.text, skillsUsed: result.skillsUsed, toolsUsed: result.toolsUsed } };
|
|
82
|
+
return { output: { command, text: result.text, skillsUsed: result.skillsUsed, toolsUsed: result.toolsUsed, usage: result.usage } };
|
|
83
83
|
}
|
|
84
84
|
// Inline decision schema: surface its fields at the top level (0.1.7 behaviour).
|
|
85
85
|
if (cfg.decision && result.data && typeof result.data === "object" && !Array.isArray(result.data)) {
|
|
86
|
-
return { output: { ...result.data, text: result.text, skillsUsed: result.skillsUsed, toolsUsed: result.toolsUsed } };
|
|
86
|
+
return { output: { ...result.data, text: result.text, skillsUsed: result.skillsUsed, toolsUsed: result.toolsUsed, usage: result.usage } };
|
|
87
87
|
}
|
|
88
88
|
return { output: result };
|
|
89
89
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./cache.js";
|
|
|
7
7
|
export * from "./observer.js";
|
|
8
8
|
export * from "./secrets.js";
|
|
9
9
|
export * from "./project-config.js";
|
|
10
|
+
export * from "./pause.js";
|
|
10
11
|
export * from "./agents.js";
|
|
11
12
|
export * from "./handlers/foreach.js";
|
|
12
13
|
export * from "./handlers/run-workflow.js";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./cache.js";
|
|
|
7
7
|
export * from "./observer.js";
|
|
8
8
|
export * from "./secrets.js";
|
|
9
9
|
export * from "./project-config.js";
|
|
10
|
+
export * from "./pause.js";
|
|
10
11
|
export * from "./agents.js";
|
|
11
12
|
export * from "./handlers/foreach.js";
|
|
12
13
|
export * from "./handlers/run-workflow.js";
|
package/dist/pause.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A platform-wide play/pause switch. When paused, the scheduler stops firing cron workflows
|
|
3
|
+
* (in-flight runs finish; new scheduled fires are skipped). It's a master switch for the
|
|
4
|
+
* autonomous loop — manual dashboard runs still work.
|
|
5
|
+
*/
|
|
6
|
+
export interface PauseState {
|
|
7
|
+
isPaused(): boolean;
|
|
8
|
+
pause(): void;
|
|
9
|
+
resume(): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* File-backed pause state: the presence of a sentinel file (default `.flow-paused`) means paused.
|
|
13
|
+
* A file (not in-memory) so the state survives a `start --watch` restart and is inspectable.
|
|
14
|
+
*/
|
|
15
|
+
export declare class FilePauseState implements PauseState {
|
|
16
|
+
private readonly path;
|
|
17
|
+
constructor(path?: string);
|
|
18
|
+
isPaused(): boolean;
|
|
19
|
+
pause(): void;
|
|
20
|
+
resume(): void;
|
|
21
|
+
}
|
package/dist/pause.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync, writeFileSync, rmSync } from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* File-backed pause state: the presence of a sentinel file (default `.flow-paused`) means paused.
|
|
4
|
+
* A file (not in-memory) so the state survives a `start --watch` restart and is inspectable.
|
|
5
|
+
*/
|
|
6
|
+
export class FilePauseState {
|
|
7
|
+
path;
|
|
8
|
+
constructor(path = ".flow-paused") {
|
|
9
|
+
this.path = path;
|
|
10
|
+
}
|
|
11
|
+
isPaused() {
|
|
12
|
+
return existsSync(this.path);
|
|
13
|
+
}
|
|
14
|
+
pause() {
|
|
15
|
+
if (!this.isPaused())
|
|
16
|
+
writeFileSync(this.path, `paused ${new Date().toISOString()}\n`);
|
|
17
|
+
}
|
|
18
|
+
resume() {
|
|
19
|
+
try {
|
|
20
|
+
rmSync(this.path);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* already gone — nothing to do */
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/project-config.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ declare const ProjectConfigSchema: z.ZodObject<{
|
|
|
32
32
|
}, z.core.$strip>>;
|
|
33
33
|
}, z.core.$strip>>;
|
|
34
34
|
workflows: z.ZodOptional<z.ZodString>;
|
|
35
|
+
atlassianSite: z.ZodOptional<z.ZodString>;
|
|
35
36
|
}, z.core.$strip>;
|
|
36
37
|
export type ProjectConfig = z.infer<typeof ProjectConfigSchema>;
|
|
37
38
|
/**
|
package/dist/project-config.js
CHANGED
|
@@ -28,6 +28,9 @@ const ProjectConfigSchema = z.object({
|
|
|
28
28
|
})
|
|
29
29
|
.default({ runner: "claude", model: "claude-opus-4-8" }),
|
|
30
30
|
workflows: z.string().optional(), // relative subdir; omitted = use dir itself
|
|
31
|
+
// Atlassian site host (e.g. "sojournii.atlassian.net") — lets the dashboard build browse/wiki
|
|
32
|
+
// links to the issues/pages a run touched. Optional; links also come from MCP tool results.
|
|
33
|
+
atlassianSite: z.string().optional(),
|
|
31
34
|
});
|
|
32
35
|
const CONFIG_FILENAME = "agentic-surfaces.config.yaml";
|
|
33
36
|
/**
|
package/dist/scheduler.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HandlerRegistry } from "./registry.js";
|
|
2
|
+
import type { PauseState } from "./pause.js";
|
|
2
3
|
import type { RunObserver, Services, Workflow } from "./types.js";
|
|
3
4
|
export declare function defaultRegistry(): HandlerRegistry;
|
|
4
5
|
export declare function runWorkflowOnce(workflow: Workflow, opts: {
|
|
@@ -19,11 +20,15 @@ export declare class Scheduler {
|
|
|
19
20
|
private services;
|
|
20
21
|
private registry;
|
|
21
22
|
private observer;
|
|
23
|
+
/** When set + paused, scheduled cron fires are skipped (the platform-wide play/pause switch). */
|
|
24
|
+
private pause?;
|
|
22
25
|
private crons;
|
|
23
26
|
private active;
|
|
24
27
|
private pending;
|
|
25
28
|
private workflows;
|
|
26
|
-
constructor(services: Services, registry?: HandlerRegistry, observer?: RunObserver
|
|
29
|
+
constructor(services: Services, registry?: HandlerRegistry, observer?: RunObserver,
|
|
30
|
+
/** When set + paused, scheduled cron fires are skipped (the platform-wide play/pause switch). */
|
|
31
|
+
pause?: PauseState | undefined);
|
|
27
32
|
add(workflow: Workflow): void;
|
|
28
33
|
start(): void;
|
|
29
34
|
private enqueue;
|
package/dist/scheduler.js
CHANGED
|
@@ -58,14 +58,18 @@ export class Scheduler {
|
|
|
58
58
|
services;
|
|
59
59
|
registry;
|
|
60
60
|
observer;
|
|
61
|
+
pause;
|
|
61
62
|
crons = [];
|
|
62
63
|
active = 0;
|
|
63
64
|
pending = [];
|
|
64
65
|
workflows = [];
|
|
65
|
-
constructor(services, registry = defaultRegistry(), observer = new ConsoleObserver()
|
|
66
|
+
constructor(services, registry = defaultRegistry(), observer = new ConsoleObserver(),
|
|
67
|
+
/** When set + paused, scheduled cron fires are skipped (the platform-wide play/pause switch). */
|
|
68
|
+
pause) {
|
|
66
69
|
this.services = services;
|
|
67
70
|
this.registry = registry;
|
|
68
71
|
this.observer = observer;
|
|
72
|
+
this.pause = pause;
|
|
69
73
|
}
|
|
70
74
|
add(workflow) { this.workflows.push(workflow); }
|
|
71
75
|
start() {
|
|
@@ -74,14 +78,21 @@ export class Scheduler {
|
|
|
74
78
|
if (node.type !== "trigger.cron")
|
|
75
79
|
continue;
|
|
76
80
|
const pattern = String(node.config.cron);
|
|
77
|
-
this.crons.push(new Cron(pattern, () =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
this.crons.push(new Cron(pattern, () => {
|
|
82
|
+
// Platform-wide pause: skip this scheduled fire (in-flight runs are unaffected).
|
|
83
|
+
if (this.pause?.isPaused()) {
|
|
84
|
+
this.services.logger?.info?.(`paused — skipping scheduled run of ${wf.name}`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.enqueue(() => runWorkflowOnce(wf, { registry: this.registry, services: this.services, triggerNodeId: node.id, observer: this.observer })
|
|
88
|
+
.then(() => { })
|
|
89
|
+
// A failed scheduled run must not crash the scheduler (unhandled
|
|
90
|
+
// rejection). The failure is already reported to the observer; log
|
|
91
|
+
// and carry on so the next trigger still fires.
|
|
92
|
+
.catch((err) => this.services.logger?.error?.("scheduled run failed", {
|
|
93
|
+
workflow: wf.name, error: err instanceof Error ? err.message : String(err),
|
|
94
|
+
})));
|
|
95
|
+
}));
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
98
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface Services {
|
|
|
72
72
|
}
|
|
73
73
|
export interface RunContext {
|
|
74
74
|
workflow: Workflow;
|
|
75
|
+
/** Unique id for this run, set by the executor — handlers tag their observer activity with it. */
|
|
76
|
+
runId?: string;
|
|
75
77
|
outputs: Map<string, unknown>;
|
|
76
78
|
triggerNodeId: string;
|
|
77
79
|
triggerPayload?: unknown;
|
|
@@ -88,10 +90,10 @@ export interface NodeHandler {
|
|
|
88
90
|
execute(node: WorkflowNode, ctx: RunContext): Promise<NodeResult>;
|
|
89
91
|
}
|
|
90
92
|
export interface RunObserver {
|
|
91
|
-
onRunStart?(workflow: string, payload?: unknown): void;
|
|
92
|
-
onNodeStart?(nodeId: string): void;
|
|
93
|
-
onNodeFinish?(nodeId: string, status: "success" | "failed", meta?: unknown): void;
|
|
93
|
+
onRunStart?(workflow: string, payload?: unknown, runId?: string): void;
|
|
94
|
+
onNodeStart?(nodeId: string, runId?: string): void;
|
|
95
|
+
onNodeFinish?(nodeId: string, status: "success" | "failed", meta?: unknown, runId?: string): void;
|
|
94
96
|
/** A live step of an agent node's work (reasoning, a tool/MCP call, or a result). */
|
|
95
|
-
onNodeActivity?(nodeId: string, activity: AgentActivity): void;
|
|
96
|
-
onRunFinish?(workflow: string, status: "success" | "failed"): void;
|
|
97
|
+
onNodeActivity?(nodeId: string, activity: AgentActivity, runId?: string): void;
|
|
98
|
+
onRunFinish?(workflow: string, status: "success" | "failed", runId?: string): void;
|
|
97
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-surfaces/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"jsonata": "^2.2.1",
|
|
25
25
|
"yaml": "^2.9.0",
|
|
26
26
|
"zod": "^4.4.3",
|
|
27
|
-
"@agentic-surfaces/agent": "0.1.
|
|
27
|
+
"@agentic-surfaces/agent": "0.1.28"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/better-sqlite3": "^7.6.13",
|