@backendkit-labs/agent-core 0.42.0 → 0.44.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.
Files changed (84) hide show
  1. package/README.md +60 -1
  2. package/dist/flow/adapter.d.ts +20 -0
  3. package/dist/flow/adapter.d.ts.map +1 -0
  4. package/dist/flow/adapter.js +81 -0
  5. package/dist/flow/adapter.js.map +1 -0
  6. package/dist/flow/approval-handler.d.ts +59 -0
  7. package/dist/flow/approval-handler.d.ts.map +1 -0
  8. package/dist/flow/approval-handler.js +79 -0
  9. package/dist/flow/approval-handler.js.map +1 -0
  10. package/dist/flow/approval.d.ts +39 -0
  11. package/dist/flow/approval.d.ts.map +1 -0
  12. package/dist/flow/approval.js +58 -0
  13. package/dist/flow/approval.js.map +1 -0
  14. package/dist/flow/condition.d.ts +6 -0
  15. package/dist/flow/condition.d.ts.map +1 -0
  16. package/dist/flow/condition.js +30 -0
  17. package/dist/flow/condition.js.map +1 -0
  18. package/dist/flow/convert.d.ts +44 -0
  19. package/dist/flow/convert.d.ts.map +1 -0
  20. package/dist/flow/convert.js +34 -0
  21. package/dist/flow/convert.js.map +1 -0
  22. package/dist/flow/file-journal.d.ts +34 -0
  23. package/dist/flow/file-journal.d.ts.map +1 -0
  24. package/dist/flow/file-journal.js +176 -0
  25. package/dist/flow/file-journal.js.map +1 -0
  26. package/dist/flow/handler.d.ts +35 -0
  27. package/dist/flow/handler.d.ts.map +1 -0
  28. package/dist/flow/handler.js +51 -0
  29. package/dist/flow/handler.js.map +1 -0
  30. package/dist/flow/host.d.ts +79 -0
  31. package/dist/flow/host.d.ts.map +1 -0
  32. package/dist/flow/host.js +148 -0
  33. package/dist/flow/host.js.map +1 -0
  34. package/dist/flow/index.d.ts +27 -0
  35. package/dist/flow/index.d.ts.map +1 -0
  36. package/dist/flow/index.js +55 -0
  37. package/dist/flow/index.js.map +1 -0
  38. package/dist/flow/interpolate.d.ts +6 -0
  39. package/dist/flow/interpolate.d.ts.map +1 -0
  40. package/dist/flow/interpolate.js +18 -0
  41. package/dist/flow/interpolate.js.map +1 -0
  42. package/dist/flow/journal.d.ts +105 -0
  43. package/dist/flow/journal.d.ts.map +1 -0
  44. package/dist/flow/journal.js +89 -0
  45. package/dist/flow/journal.js.map +1 -0
  46. package/dist/flow/limiter.d.ts +21 -0
  47. package/dist/flow/limiter.d.ts.map +1 -0
  48. package/dist/flow/limiter.js +45 -0
  49. package/dist/flow/limiter.js.map +1 -0
  50. package/dist/flow/loader.d.ts +24 -0
  51. package/dist/flow/loader.d.ts.map +1 -0
  52. package/dist/flow/loader.js +185 -0
  53. package/dist/flow/loader.js.map +1 -0
  54. package/dist/flow/planner.d.ts +50 -0
  55. package/dist/flow/planner.d.ts.map +1 -0
  56. package/dist/flow/planner.js +131 -0
  57. package/dist/flow/planner.js.map +1 -0
  58. package/dist/flow/run.d.ts +115 -0
  59. package/dist/flow/run.d.ts.map +1 -0
  60. package/dist/flow/run.js +417 -0
  61. package/dist/flow/run.js.map +1 -0
  62. package/dist/flow/tools.d.ts +27 -0
  63. package/dist/flow/tools.d.ts.map +1 -0
  64. package/dist/flow/tools.js +71 -0
  65. package/dist/flow/tools.js.map +1 -0
  66. package/dist/flow/types.d.ts +139 -0
  67. package/dist/flow/types.d.ts.map +1 -0
  68. package/dist/flow/types.js +80 -0
  69. package/dist/flow/types.js.map +1 -0
  70. package/dist/index.d.ts +17 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +46 -2
  73. package/dist/index.js.map +1 -1
  74. package/dist/learning/index.d.ts +1 -1
  75. package/dist/learning/index.d.ts.map +1 -1
  76. package/dist/learning/index.js +104 -42
  77. package/dist/learning/index.js.map +1 -1
  78. package/dist/learning/signal.d.ts +32 -14
  79. package/dist/learning/signal.d.ts.map +1 -1
  80. package/dist/learning/signal.js +95 -30
  81. package/dist/learning/signal.js.map +1 -1
  82. package/dist/learning/types.d.ts +60 -0
  83. package/dist/learning/types.d.ts.map +1 -1
  84. package/package.json +6 -1
@@ -0,0 +1,34 @@
1
+ import type { JournalRun, JournalRunStatus, NewJournalRun, RunJournal, RunPatch, StepPatch } from './journal';
2
+ /**
3
+ * A run journal in a directory, with the technique of `FileApprovalStore`: every file is written under a temporary name and
4
+ * published with a hard link, which fails if the target exists. So each write is atomic and exclusive across processes sharing
5
+ * the directory, and a crash never leaves a half-written file under a final name.
6
+ *
7
+ * - `<runId>.ev.<seq>.json`: the events of the run, append-only; the run is rebuilt by folding them in order.
8
+ * - `<runId>.claim.<n>.json`: the claims. The current one is the highest `n`; taking over an expired one means publishing
9
+ * `n+1`, which only one contender can do. Nothing is ever deleted or overwritten, so no lock is needed.
10
+ */
11
+ export declare class FileRunJournal implements RunJournal {
12
+ private readonly dir;
13
+ private ready?;
14
+ constructor(dir: string);
15
+ begin(run: NewJournalRun): Promise<void>;
16
+ step(runId: string, stepId: string, patch: StepPatch): Promise<void>;
17
+ update(runId: string, patch: RunPatch): Promise<void>;
18
+ claim(runId: string, owner: string, ttlMs: number): Promise<(() => Promise<void>) | null>;
19
+ get(runId: string): Promise<JournalRun | undefined>;
20
+ list(filter?: {
21
+ status?: JournalRunStatus[];
22
+ flow?: string;
23
+ tenantId?: string;
24
+ }): Promise<JournalRun[]>;
25
+ private checkId;
26
+ private file;
27
+ private names;
28
+ private seqs;
29
+ private append;
30
+ private readJson;
31
+ /** Write to a unique temporary file, then hard-link it under the final name (fails if it exists). */
32
+ private publish;
33
+ }
34
+ //# sourceMappingURL=file-journal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-journal.d.ts","sourceRoot":"","sources":["../../src/flow/file-journal.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAgB,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAK5H;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,UAAU;IAGjC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,KAAK,CAAC,CAAmB;gBAEJ,GAAG,EAAE,MAAM;IAElC,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAwBzF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAUnD,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAkB7G,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,IAAI;YAIE,KAAK;YAOL,IAAI;YAQJ,MAAM;YAgBN,QAAQ;IAItB,qGAAqG;YACvF,OAAO;CAcxB"}
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileRunJournal = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_path_1 = require("node:path");
7
+ const journal_1 = require("./journal");
8
+ const ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
9
+ const SEQ_WIDTH = 8;
10
+ /**
11
+ * A run journal in a directory, with the technique of `FileApprovalStore`: every file is written under a temporary name and
12
+ * published with a hard link, which fails if the target exists. So each write is atomic and exclusive across processes sharing
13
+ * the directory, and a crash never leaves a half-written file under a final name.
14
+ *
15
+ * - `<runId>.ev.<seq>.json`: the events of the run, append-only; the run is rebuilt by folding them in order.
16
+ * - `<runId>.claim.<n>.json`: the claims. The current one is the highest `n`; taking over an expired one means publishing
17
+ * `n+1`, which only one contender can do. Nothing is ever deleted or overwritten, so no lock is needed.
18
+ */
19
+ class FileRunJournal {
20
+ dir;
21
+ ready;
22
+ constructor(dir) {
23
+ this.dir = dir;
24
+ }
25
+ async begin(run) {
26
+ this.checkId(run.runId);
27
+ const existing = await this.names(run.runId, 'ev');
28
+ if (existing.length > 0)
29
+ throw new Error(`run "${run.runId}" already exists`);
30
+ const ev = { kind: 'begin', at: new Date().toISOString(), run };
31
+ try {
32
+ await this.publish(this.file(run.runId, 'ev', 0), JSON.stringify(ev));
33
+ }
34
+ catch (err) {
35
+ if (err.alreadyExists)
36
+ throw new Error(`run "${run.runId}" already exists`);
37
+ throw err;
38
+ }
39
+ }
40
+ async step(runId, stepId, patch) {
41
+ await this.append(runId, { kind: 'step', at: new Date().toISOString(), stepId, patch });
42
+ }
43
+ async update(runId, patch) {
44
+ await this.append(runId, { kind: 'update', at: new Date().toISOString(), patch });
45
+ }
46
+ async claim(runId, owner, ttlMs) {
47
+ this.checkId(runId);
48
+ for (let attempt = 0; attempt < 5; attempt++) {
49
+ const seqs = await this.seqs(runId, 'claim');
50
+ const n = seqs.length ? seqs[seqs.length - 1] : -1;
51
+ if (n >= 0) {
52
+ const cur = await this.readJson(this.file(runId, 'claim', n));
53
+ if (cur && cur.owner !== null && cur.expiresAt > Date.now() && cur.owner !== owner)
54
+ return null;
55
+ }
56
+ const next = n + 1;
57
+ try {
58
+ await this.publish(this.file(runId, 'claim', next), JSON.stringify({ owner, expiresAt: Date.now() + ttlMs }));
59
+ }
60
+ catch (err) {
61
+ if (err.alreadyExists)
62
+ continue; // someone took n+1 first: look again
63
+ throw err;
64
+ }
65
+ return async () => {
66
+ // Release = a newer claim with no owner. If someone already took over, publishing fails and we lost it anyway.
67
+ await this.publish(this.file(runId, 'claim', next + 1), JSON.stringify({ owner: null, expiresAt: 0 })).catch(() => undefined);
68
+ };
69
+ }
70
+ return null;
71
+ }
72
+ async get(runId) {
73
+ this.checkId(runId);
74
+ const events = [];
75
+ for (const seq of await this.seqs(runId, 'ev')) {
76
+ const ev = await this.readJson(this.file(runId, 'ev', seq));
77
+ if (ev)
78
+ events.push(ev);
79
+ }
80
+ return (0, journal_1.foldEvents)(events);
81
+ }
82
+ async list(filter) {
83
+ let names;
84
+ try {
85
+ names = await (0, promises_1.readdir)(this.dir);
86
+ }
87
+ catch {
88
+ return [];
89
+ }
90
+ const ids = new Set();
91
+ for (const n of names) {
92
+ const m = /^(.+)\.ev\.\d+\.json$/.exec(n);
93
+ if (m)
94
+ ids.add(m[1]);
95
+ }
96
+ const out = [];
97
+ for (const id of ids) {
98
+ const r = await this.get(id);
99
+ if (r && (0, journal_1.matches)(r, filter))
100
+ out.push(r);
101
+ }
102
+ return out.sort((a, b) => a.startedAt.localeCompare(b.startedAt));
103
+ }
104
+ // ── internals ────────────────────────────────────────────────────────────
105
+ checkId(id) {
106
+ if (!ID.test(id))
107
+ throw new Error(`invalid run id "${id}"`);
108
+ }
109
+ file(runId, kind, seq) {
110
+ return (0, node_path_1.join)(this.dir, `${runId}.${kind}.${String(seq).padStart(SEQ_WIDTH, '0')}.json`);
111
+ }
112
+ async names(runId, kind) {
113
+ let names;
114
+ try {
115
+ names = await (0, promises_1.readdir)(this.dir);
116
+ }
117
+ catch {
118
+ return [];
119
+ }
120
+ const prefix = `${runId}.${kind}.`;
121
+ return names.filter(n => n.startsWith(prefix) && n.endsWith('.json'));
122
+ }
123
+ async seqs(runId, kind) {
124
+ const prefix = `${runId}.${kind}.`;
125
+ return (await this.names(runId, kind))
126
+ .map(n => Number(n.slice(prefix.length, -'.json'.length)))
127
+ .filter(n => Number.isInteger(n))
128
+ .sort((a, b) => a - b);
129
+ }
130
+ async append(runId, ev) {
131
+ this.checkId(runId);
132
+ for (let attempt = 0; attempt < 20; attempt++) {
133
+ const seqs = await this.seqs(runId, 'ev');
134
+ if (seqs.length === 0)
135
+ throw new Error(`run "${runId}" does not exist`);
136
+ try {
137
+ await this.publish(this.file(runId, 'ev', seqs[seqs.length - 1] + 1), JSON.stringify(ev));
138
+ return;
139
+ }
140
+ catch (err) {
141
+ if (err.alreadyExists)
142
+ continue; // another writer took that number
143
+ throw err;
144
+ }
145
+ }
146
+ throw new Error(`could not append to run "${runId}": too much contention`);
147
+ }
148
+ async readJson(path) {
149
+ try {
150
+ return JSON.parse(await (0, promises_1.readFile)(path, 'utf8'));
151
+ }
152
+ catch {
153
+ return undefined;
154
+ }
155
+ }
156
+ /** Write to a unique temporary file, then hard-link it under the final name (fails if it exists). */
157
+ async publish(target, content) {
158
+ this.ready ??= (0, promises_1.mkdir)(this.dir, { recursive: true });
159
+ await this.ready;
160
+ const tmp = (0, node_path_1.join)(this.dir, `.${process.pid}.${(0, node_crypto_1.randomBytes)(6).toString('hex')}.tmp`);
161
+ await (0, promises_1.writeFile)(tmp, content, { flag: 'wx' });
162
+ try {
163
+ await (0, promises_1.link)(tmp, target);
164
+ }
165
+ catch (err) {
166
+ if (err.code === 'EEXIST')
167
+ throw Object.assign(new Error('exists'), { alreadyExists: true });
168
+ throw err;
169
+ }
170
+ finally {
171
+ await (0, promises_1.unlink)(tmp).catch(() => undefined);
172
+ }
173
+ }
174
+ }
175
+ exports.FileRunJournal = FileRunJournal;
176
+ //# sourceMappingURL=file-journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-journal.js","sourceRoot":"","sources":["../../src/flow/file-journal.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,+CAAqF;AACrF,yCAAiC;AACjC,uCAAgD;AAGhD,MAAM,EAAE,GAAG,mCAAmC,CAAC;AAC/C,MAAM,SAAS,GAAG,CAAC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I,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACxH,MAAM,GAAG,CAAC;QACd,CAAC;gBAAS,CAAC;YACP,MAAM,IAAA,iBAAM,EAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;CACJ;AAxID,wCAwIC"}
@@ -0,0 +1,35 @@
1
+ import { FlowHost, type FlowInfo, type FlowRunView, type InProcessFlow } from './host';
2
+ /**
3
+ * The surface `AgentServer` takes as `flowHandler` (`FlowHandler` of `@backendkit-labs/agent-protocol`, protocol 1.1), declared here
4
+ * with the same shape so that core depends on no transport. A supervisor elsewhere starts, watches, pauses, resumes and cancels
5
+ * the flows through it.
6
+ */
7
+ export interface FlowHandlerPort {
8
+ flows(): Array<FlowInfo>;
9
+ start(flow: string, input: Record<string, unknown>, context?: unknown): Promise<{
10
+ flowRunId: string;
11
+ }>;
12
+ status(flowRunId: string): Promise<FlowRunView>;
13
+ pause(flowRunId: string): Promise<FlowRunView>;
14
+ resume(flowRunId: string): Promise<FlowRunView>;
15
+ cancel(flowRunId: string): Promise<FlowRunView>;
16
+ }
17
+ /** A refusal with a protocol code. `AgentServer` recognises it by `name` and `code`, the way it does `EngineControlError`. */
18
+ export declare class FlowControlError extends Error {
19
+ readonly code: 'TASK_NOT_FOUND' | 'CAPABILITY_NOT_FOUND';
20
+ constructor(code: 'TASK_NOT_FOUND' | 'CAPABILITY_NOT_FOUND', message: string);
21
+ }
22
+ /**
23
+ * The flows of an agent as the `flowHandler` an `AgentServer` takes (SPEC-0023 F4). A run the host does not know is a
24
+ * `TASK_NOT_FOUND` to the caller (a restarted supervisor reads that as "lost"); a flow it does not host is `CAPABILITY_NOT_FOUND`.
25
+ *
26
+ * const { handler, host } = createFlowHandler({ 'close-month': { steps: ['collect', 'report'], run: async (input, ctl) => { ... } } });
27
+ * new AgentServer({ ..., flowHandler: handler, controlApiKey });
28
+ */
29
+ export declare function createFlowHandler(flows: Record<string, InProcessFlow>, options?: {
30
+ cancelGraceMs?: number;
31
+ }): {
32
+ handler: FlowHandlerPort;
33
+ host: FlowHost;
34
+ };
35
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/flow/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvF;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC5B,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAChD,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAChD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD;AAED,8HAA8H;AAC9H,qBAAa,gBAAiB,SAAQ,KAAK;IAC3B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,sBAAsB;gBAA/C,IAAI,EAAE,gBAAgB,GAAG,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAIxF;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG;IAAE,OAAO,EAAE,eAAe,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAuB9J"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowControlError = void 0;
4
+ exports.createFlowHandler = createFlowHandler;
5
+ const host_1 = require("./host");
6
+ /** A refusal with a protocol code. `AgentServer` recognises it by `name` and `code`, the way it does `EngineControlError`. */
7
+ class FlowControlError extends Error {
8
+ code;
9
+ constructor(code, message) {
10
+ super(message);
11
+ this.code = code;
12
+ this.name = 'ControlError';
13
+ }
14
+ }
15
+ exports.FlowControlError = FlowControlError;
16
+ /**
17
+ * The flows of an agent as the `flowHandler` an `AgentServer` takes (SPEC-0023 F4). A run the host does not know is a
18
+ * `TASK_NOT_FOUND` to the caller (a restarted supervisor reads that as "lost"); a flow it does not host is `CAPABILITY_NOT_FOUND`.
19
+ *
20
+ * const { handler, host } = createFlowHandler({ 'close-month': { steps: ['collect', 'report'], run: async (input, ctl) => { ... } } });
21
+ * new AgentServer({ ..., flowHandler: handler, controlApiKey });
22
+ */
23
+ function createFlowHandler(flows, options = {}) {
24
+ const host = new host_1.FlowHost(flows, options.cancelGraceMs);
25
+ const known = async (fn) => {
26
+ try {
27
+ return await fn();
28
+ }
29
+ catch (err) {
30
+ const code = err.code;
31
+ if (code === 'RUN_NOT_FOUND')
32
+ throw new FlowControlError('TASK_NOT_FOUND', err.message);
33
+ if (code === 'CAPABILITY_NOT_FOUND')
34
+ throw new FlowControlError('CAPABILITY_NOT_FOUND', err.message);
35
+ throw err;
36
+ }
37
+ };
38
+ const descriptors = Object.entries(flows).map(([name, f]) => ({ name, ...(f.description ? { description: f.description } : {}), ...(f.steps ? { steps: f.steps } : {}) }));
39
+ return {
40
+ host,
41
+ handler: {
42
+ flows: () => descriptors,
43
+ start: (flow, input) => known(() => host.start(flow, input)),
44
+ status: id => known(() => host.status(id)),
45
+ pause: id => known(() => host.pause(id)),
46
+ resume: id => known(() => host.resume(id)),
47
+ cancel: id => known(() => host.cancel(id)),
48
+ },
49
+ };
50
+ }
51
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/flow/handler.ts"],"names":[],"mappings":";;;AA+BA,8CAuBC;AAtDD,iCAAuF;AAgBvF,8HAA8H;AAC9H,MAAa,gBAAiB,SAAQ,KAAK;IAClB;IAArB,YAAqB,IAA+C,EAAE,OAAe;QACjF,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAA2C;QAEhE,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC/B,CAAC;CACJ;AALD,4CAKC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,KAAoC,EAAE,UAAsC,EAAE;IAC5G,MAAM,IAAI,GAAG,IAAI,eAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACxD,MAAM,KAAK,GAAG,KAAK,EAAK,EAAoB,EAAc,EAAE;QACxD,IAAI,CAAC;YAAC,OAAO,MAAM,EAAE,EAAE,CAAC;QAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,GAAI,GAAyB,CAAC,IAAI,CAAC;YAC7C,IAAI,IAAI,KAAK,eAAe;gBAAE,MAAM,IAAI,gBAAgB,CAAC,gBAAgB,EAAG,GAAa,CAAC,OAAO,CAAC,CAAC;YACnG,IAAI,IAAI,KAAK,sBAAsB;gBAAE,MAAM,IAAI,gBAAgB,CAAC,sBAAsB,EAAG,GAAa,CAAC,OAAO,CAAC,CAAC;YACh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agent hosts, with a state a supervisor can see and steer (SPEC-0023 F4). The shapes are those of
3
+ * `FlowRunState` and `FlowHandler` of `@backendkit-labs/agent-protocol` (protocol 1.1), declared here so that core depends on no
4
+ * transport: a handler built from this host plugs into `AgentServer` and a supervisor such as Hermes controls it.
5
+ */
6
+ /** `awaiting_approval` and `lost` are protocol 1.2 states; `FlowHost` itself only produces the first five. */
7
+ export type FlowStatus = 'running' | 'paused' | 'awaiting_approval' | 'done' | 'failed' | 'cancelled' | 'lost';
8
+ export interface FlowStepView {
9
+ name: string;
10
+ status: 'pending' | 'running' | 'done' | 'failed' | 'skipped' | 'awaiting_approval' | 'interrupted';
11
+ detail?: string;
12
+ }
13
+ /** A flow run seen from outside: where it is, step by step. */
14
+ export interface FlowRunView {
15
+ flowRunId: string;
16
+ flow: string;
17
+ status: FlowStatus;
18
+ currentStep?: string;
19
+ steps: FlowStepView[];
20
+ startedAt: string;
21
+ finishedAt?: string;
22
+ output?: string;
23
+ error?: string;
24
+ }
25
+ export interface FlowInfo {
26
+ name: string;
27
+ description?: string;
28
+ steps?: string[];
29
+ }
30
+ /** What a flow gets to cooperate with its supervisor: stop when cancelled, wait while paused, and say which step it is on. */
31
+ export interface FlowControl {
32
+ /** Aborted when the flow is cancelled. */
33
+ readonly signal: AbortSignal;
34
+ /** Starts a step: waits here while the flow is paused and throws if it was cancelled. The previous step is marked done. */
35
+ step(name: string, detail?: string): Promise<void>;
36
+ /** A point where a flow with no named steps can wait while paused or notice a cancel. */
37
+ checkpoint(): Promise<void>;
38
+ /** Sets a step's status directly, for flows that run steps in parallel (`step()` assumes one at a time). */
39
+ mark(name: string, status: FlowStepView['status'], detail?: string): void;
40
+ }
41
+ export interface InProcessFlow {
42
+ description?: string;
43
+ /** Step names in order, if known up front; steps that `step()` names later are added as they start. */
44
+ steps?: string[];
45
+ /** Does the work. Return its result; a throw is a failed flow (unless it was cancelled). */
46
+ run(input: Record<string, unknown>, control: FlowControl): Promise<unknown>;
47
+ }
48
+ export declare class FlowCancelled extends Error {
49
+ constructor();
50
+ }
51
+ /** `RUN_NOT_FOUND` (no such run) or `CAPABILITY_NOT_FOUND` (no such flow). `createFlowHandler` turns them into protocol codes. */
52
+ export declare class FlowHostError extends Error {
53
+ readonly code: 'RUN_NOT_FOUND' | 'CAPABILITY_NOT_FOUND';
54
+ constructor(code: 'RUN_NOT_FOUND' | 'CAPABILITY_NOT_FOUND', message: string);
55
+ }
56
+ /**
57
+ * Runs the flows of an agent and lets a supervisor see, pause, resume and cancel them. Control is cooperative: a flow
58
+ * pauses or stops at its next `step()` / `checkpoint()`, so it never stops half-way through a step. Cancelling does not
59
+ * wait forever for a flow that never reaches one: after `cancelGraceMs` it is reported cancelled and its result ignored.
60
+ */
61
+ export declare class FlowHost {
62
+ private readonly flows;
63
+ private readonly cancelGraceMs;
64
+ private readonly runs;
65
+ constructor(flows: Record<string, InProcessFlow>, cancelGraceMs?: number);
66
+ list(): Promise<FlowInfo[]>;
67
+ start(flow: string, input: Record<string, unknown>): Promise<{
68
+ flowRunId: string;
69
+ }>;
70
+ private finish;
71
+ private live;
72
+ status(flowRunId: string): Promise<FlowRunView>;
73
+ pause(flowRunId: string): Promise<FlowRunView>;
74
+ resume(flowRunId: string): Promise<FlowRunView>;
75
+ cancel(flowRunId: string): Promise<FlowRunView>;
76
+ /** Stops every flow still going (the agent leaves the fleet). */
77
+ close(): Promise<void>;
78
+ }
79
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/flow/host.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,8GAA8G;AAC9G,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,mBAAmB,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAE/G,MAAM,WAAW,YAAY;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,M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EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/E;AAED,qBAAa,aAAc,SAAQ,KAAK;;CAEvC;AAED,kIAAkI;AAClI,qBAAa,aAAc,SAAQ,KAAK;IACxB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,sBAAsB;gBAA9C,IAAI,EAAE,eAAe,GAAG,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAIvF;AAUD;;;;GAIG;AACH,qBAAa,QAAQ;IAGL,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAiC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAFjG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;gBAEnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAAmB,aAAa,SAAO;IAElG,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAI3B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAgDzF,OAAO,CAAC,MAAM;IAad,OAAO,CAAC,IAAI;IAMN,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAK/C,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAM9C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAO/C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAcrD,iEAAiE;IAC3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowHost = exports.FlowHostError = exports.FlowCancelled = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ class FlowCancelled extends Error {
6
+ constructor() { super('flow cancelled'); this.name = 'FlowCancelled'; }
7
+ }
8
+ exports.FlowCancelled = FlowCancelled;
9
+ /** `RUN_NOT_FOUND` (no such run) or `CAPABILITY_NOT_FOUND` (no such flow). `createFlowHandler` turns them into protocol codes. */
10
+ class FlowHostError extends Error {
11
+ code;
12
+ constructor(code, message) {
13
+ super(message);
14
+ this.code = code;
15
+ this.name = 'FlowHostError';
16
+ }
17
+ }
18
+ exports.FlowHostError = FlowHostError;
19
+ /**
20
+ * Runs the flows of an agent and lets a supervisor see, pause, resume and cancel them. Control is cooperative: a flow
21
+ * pauses or stops at its next `step()` / `checkpoint()`, so it never stops half-way through a step. Cancelling does not
22
+ * wait forever for a flow that never reaches one: after `cancelGraceMs` it is reported cancelled and its result ignored.
23
+ */
24
+ class FlowHost {
25
+ flows;
26
+ cancelGraceMs;
27
+ runs = new Map();
28
+ constructor(flows, cancelGraceMs = 2000) {
29
+ this.flows = flows;
30
+ this.cancelGraceMs = cancelGraceMs;
31
+ }
32
+ async list() {
33
+ return Object.entries(this.flows).map(([name, f]) => ({ name, ...(f.description ? { description: f.description } : {}), ...(f.steps ? { steps: f.steps } : {}) }));
34
+ }
35
+ async start(flow, input) {
36
+ const def = this.flows[flow];
37
+ if (!def)
38
+ throw new FlowHostError('CAPABILITY_NOT_FOUND', `flow "${flow}" not found`);
39
+ const controller = new AbortController();
40
+ const state = {
41
+ flowRunId: (0, node_crypto_1.randomUUID)(), flow, status: 'running', startedAt: new Date().toISOString(),
42
+ steps: (def.steps ?? []).map((name) => ({ name, status: 'pending' })),
43
+ };
44
+ const live = { state, controller, paused: false, settled: Promise.resolve() };
45
+ const checkpoint = async () => {
46
+ while (live.paused && !controller.signal.aborted) {
47
+ await new Promise(resolve => { live.resume = resolve; });
48
+ }
49
+ if (controller.signal.aborted)
50
+ throw new FlowCancelled();
51
+ };
52
+ const control = {
53
+ signal: controller.signal,
54
+ checkpoint,
55
+ mark: (name, status, detail) => {
56
+ let entry = state.steps.find(s => s.name === name);
57
+ if (!entry) {
58
+ entry = { name, status };
59
+ state.steps.push(entry);
60
+ }
61
+ entry.status = status;
62
+ if (detail)
63
+ entry.detail = detail;
64
+ const running = state.steps.find(s => s.status === 'running');
65
+ if (running)
66
+ state.currentStep = running.name;
67
+ else
68
+ delete state.currentStep;
69
+ },
70
+ step: async (name, detail) => {
71
+ await checkpoint();
72
+ for (const s of state.steps)
73
+ if (s.status === 'running')
74
+ s.status = 'done';
75
+ let entry = state.steps.find(s => s.name === name);
76
+ if (!entry) {
77
+ entry = { name, status: 'pending' };
78
+ state.steps.push(entry);
79
+ }
80
+ entry.status = 'running';
81
+ if (detail)
82
+ entry.detail = detail;
83
+ state.currentStep = name;
84
+ },
85
+ };
86
+ live.settled = Promise.resolve()
87
+ .then(() => def.run(input, control))
88
+ .then(output => controller.signal.aborted ? this.finish(live, 'cancelled', {}) : this.finish(live, 'done', { output: typeof output === 'string' ? output : JSON.stringify(output) ?? '' }), err => this.finish(live, controller.signal.aborted ? 'cancelled' : 'failed', controller.signal.aborted ? {} : { error: err instanceof Error ? err.message : String(err) }));
89
+ this.runs.set(state.flowRunId, live);
90
+ return { flowRunId: state.flowRunId };
91
+ }
92
+ finish(live, status, extra) {
93
+ const { state } = live;
94
+ if (state.status === 'cancelled' || state.status === 'done' || state.status === 'failed')
95
+ return;
96
+ for (const s of state.steps) {
97
+ if (s.status === 'running')
98
+ s.status = status === 'done' ? 'done' : status === 'failed' ? 'failed' : 'skipped';
99
+ else if (s.status === 'pending' && status !== 'done')
100
+ s.status = 'skipped';
101
+ }
102
+ delete state.currentStep;
103
+ state.status = status;
104
+ state.finishedAt = new Date().toISOString();
105
+ Object.assign(state, extra);
106
+ }
107
+ live(id) {
108
+ const live = this.runs.get(id);
109
+ if (!live)
110
+ throw new FlowHostError('RUN_NOT_FOUND', `flow run ${id} not found`);
111
+ return live;
112
+ }
113
+ async status(flowRunId) {
114
+ const { state, paused } = this.live(flowRunId);
115
+ return { ...state, status: paused && state.status === 'running' ? 'paused' : state.status, steps: state.steps.map(s => ({ ...s })) };
116
+ }
117
+ async pause(flowRunId) {
118
+ const live = this.live(flowRunId);
119
+ if (live.state.status === 'running')
120
+ live.paused = true;
121
+ return this.status(flowRunId);
122
+ }
123
+ async resume(flowRunId) {
124
+ const live = this.live(flowRunId);
125
+ live.paused = false;
126
+ live.resume?.();
127
+ return this.status(flowRunId);
128
+ }
129
+ async cancel(flowRunId) {
130
+ const live = this.live(flowRunId);
131
+ if (live.state.status === 'running') {
132
+ live.controller.abort();
133
+ live.paused = false;
134
+ live.resume?.();
135
+ let timer;
136
+ await Promise.race([live.settled, new Promise(r => { timer = setTimeout(r, this.cancelGraceMs); })]);
137
+ clearTimeout(timer);
138
+ this.finish(live, 'cancelled', {});
139
+ }
140
+ return this.status(flowRunId);
141
+ }
142
+ /** Stops every flow still going (the agent leaves the fleet). */
143
+ async close() {
144
+ await Promise.allSettled([...this.runs.values()].filter(l => l.state.status === 'running').map(l => this.cancel(l.state.flowRunId)));
145
+ }
146
+ }
147
+ exports.FlowHost = FlowHost;
148
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/flow/host.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAgDzC,MAAa,aAAc,SAAQ,KAAK;IACpC,gBAAgB,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC;CAC1E;AAFD,sCAEC;AAED,kIAAkI;AAClI,MAAa,aAAc,SAAQ,KAAK;IACf;IAArB,YAAqB,IAA8C,EAAE,OAAe;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAA0C;QAE/D,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAChC,CAAC;CACJ;AALD,sCAKC;AAUD;;;;GAIG;AACH,MAAa,QAAQ;IAGY;IAAuD;IAFnE,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ateSchema, FlowStepSchema, FlowCompensationSchema, FlowDefinitionSchema, } from './types';
2
+ export type { FlowTrigger, FlowGate, FlowCondition, FlowStep, FlowCompensation, FlowDefinition, FlowTransition, FlowTransitionEvent } from './types';
3
+ export { parseFlow, loadFlow, loadFlowsFromDir, validateFlow, FlowLoadError } from './loader';
4
+ export { FlowHost, FlowCancelled, FlowHostError } from './host';
5
+ export type { FlowControl, FlowInfo, FlowRunView, FlowStatus, FlowStepView, InProcessFlow } from './host';
6
+ export { createFlowHandler, FlowControlError } from './handler';
7
+ export type { FlowHandlerPort } from './handler';
8
+ export { runFlow, FlowClaimError } from './run';
9
+ export type { StepExecutor, StepInput, StepOutput, FlowResult, FlowStepResult, FlowCompensationResult, FlowRunStatus, GateContext, RunFlowOptions, } from './run';
10
+ export { KeyedConcurrencyLimiter } from './limiter';
11
+ export type { ConcurrencyLimiter, KeyedLimiterOptions } from './limiter';
12
+ export { interpolate } from './interpolate';
13
+ export { MemoryRunJournal, foldEvents, matches as journalMatches } from './journal';
14
+ export type { JournalEvent, RunJournal, JournalRun, JournalStep, JournalStepStatus, JournalRunStatus, NewJournalRun, StepPatch, RunPatch, } from './journal';
15
+ export { FileRunJournal } from './file-journal';
16
+ export { flowFromDefinition, flowRunView } from './adapter';
17
+ export { decideStepApproval, stepApprovalId } from './approval';
18
+ export type { FlowApprovals, StepApproval } from './approval';
19
+ export { flowFromTaskPlan, flowFromStaticFlow } from './convert';
20
+ export type { TaskPlanLike, PlanStepLike, StaticFlowLike } from './convert';
21
+ export { createApprovalHandler, summarizeApproval, ApprovalControlError } from './approval-handler';
22
+ export type { ApprovalHandlerPort, ApprovalHandlerOptions, ApprovalSummaryView, ApprovalDecisionInput } from './approval-handler';
23
+ export { createFlowTools } from './tools';
24
+ export type { FlowToolsOptions } from './tools';
25
+ export { planFlow, PLANNER_SYSTEM, UNRESOLVED_AGENT } from './planner';
26
+ export type { PlannerAgent, PlanFlowOptions, PlannedFlow } from './planner';
27
+ //# sourceMappingURL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