@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,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNRESOLVED_AGENT = exports.PLANNER_SYSTEM = exports.planFlow = exports.createFlowTools = exports.ApprovalControlError = exports.summarizeApproval = exports.createApprovalHandler = exports.flowFromStaticFlow = exports.flowFromTaskPlan = exports.stepApprovalId = exports.decideStepApproval = exports.flowRunView = exports.flowFromDefinition = exports.FileRunJournal = exports.journalMatches = exports.foldEvents = exports.MemoryRunJournal = exports.interpolate = exports.KeyedConcurrencyLimiter = exports.FlowClaimError = exports.runFlow = exports.FlowControlError = exports.createFlowHandler = exports.FlowHostError = exports.FlowCancelled = exports.FlowHost = exports.FlowLoadError = exports.validateFlow = exports.loadFlowsFromDir = exports.loadFlow = exports.parseFlow = exports.FlowDefinitionSchema = exports.FlowCompensationSchema = exports.FlowStepSchema = exports.FlowGateSchema = exports.FlowTriggerSchema = void 0;
4
+ var types_1 = require("./types");
5
+ Object.defineProperty(exports, "FlowTriggerSchema", { enumerable: true, get: function () { return types_1.FlowTriggerSchema; } });
6
+ Object.defineProperty(exports, "FlowGateSchema", { enumerable: true, get: function () { return types_1.FlowGateSchema; } });
7
+ Object.defineProperty(exports, "FlowStepSchema", { enumerable: true, get: function () { return types_1.FlowStepSchema; } });
8
+ Object.defineProperty(exports, "FlowCompensationSchema", { enumerable: true, get: function () { return types_1.FlowCompensationSchema; } });
9
+ Object.defineProperty(exports, "FlowDefinitionSchema", { enumerable: true, get: function () { return types_1.FlowDefinitionSchema; } });
10
+ var loader_1 = require("./loader");
11
+ Object.defineProperty(exports, "parseFlow", { enumerable: true, get: function () { return loader_1.parseFlow; } });
12
+ Object.defineProperty(exports, "loadFlow", { enumerable: true, get: function () { return loader_1.loadFlow; } });
13
+ Object.defineProperty(exports, "loadFlowsFromDir", { enumerable: true, get: function () { return loader_1.loadFlowsFromDir; } });
14
+ Object.defineProperty(exports, "validateFlow", { enumerable: true, get: function () { return loader_1.validateFlow; } });
15
+ Object.defineProperty(exports, "FlowLoadError", { enumerable: true, get: function () { return loader_1.FlowLoadError; } });
16
+ var host_1 = require("./host");
17
+ Object.defineProperty(exports, "FlowHost", { enumerable: true, get: function () { return host_1.FlowHost; } });
18
+ Object.defineProperty(exports, "FlowCancelled", { enumerable: true, get: function () { return host_1.FlowCancelled; } });
19
+ Object.defineProperty(exports, "FlowHostError", { enumerable: true, get: function () { return host_1.FlowHostError; } });
20
+ var handler_1 = require("./handler");
21
+ Object.defineProperty(exports, "createFlowHandler", { enumerable: true, get: function () { return handler_1.createFlowHandler; } });
22
+ Object.defineProperty(exports, "FlowControlError", { enumerable: true, get: function () { return handler_1.FlowControlError; } });
23
+ var run_1 = require("./run");
24
+ Object.defineProperty(exports, "runFlow", { enumerable: true, get: function () { return run_1.runFlow; } });
25
+ Object.defineProperty(exports, "FlowClaimError", { enumerable: true, get: function () { return run_1.FlowClaimError; } });
26
+ var limiter_1 = require("./limiter");
27
+ Object.defineProperty(exports, "KeyedConcurrencyLimiter", { enumerable: true, get: function () { return limiter_1.KeyedConcurrencyLimiter; } });
28
+ var interpolate_1 = require("./interpolate");
29
+ Object.defineProperty(exports, "interpolate", { enumerable: true, get: function () { return interpolate_1.interpolate; } });
30
+ var journal_1 = require("./journal");
31
+ Object.defineProperty(exports, "MemoryRunJournal", { enumerable: true, get: function () { return journal_1.MemoryRunJournal; } });
32
+ Object.defineProperty(exports, "foldEvents", { enumerable: true, get: function () { return journal_1.foldEvents; } });
33
+ Object.defineProperty(exports, "journalMatches", { enumerable: true, get: function () { return journal_1.matches; } });
34
+ var file_journal_1 = require("./file-journal");
35
+ Object.defineProperty(exports, "FileRunJournal", { enumerable: true, get: function () { return file_journal_1.FileRunJournal; } });
36
+ var adapter_1 = require("./adapter");
37
+ Object.defineProperty(exports, "flowFromDefinition", { enumerable: true, get: function () { return adapter_1.flowFromDefinition; } });
38
+ Object.defineProperty(exports, "flowRunView", { enumerable: true, get: function () { return adapter_1.flowRunView; } });
39
+ var approval_1 = require("./approval");
40
+ Object.defineProperty(exports, "decideStepApproval", { enumerable: true, get: function () { return approval_1.decideStepApproval; } });
41
+ Object.defineProperty(exports, "stepApprovalId", { enumerable: true, get: function () { return approval_1.stepApprovalId; } });
42
+ var convert_1 = require("./convert");
43
+ Object.defineProperty(exports, "flowFromTaskPlan", { enumerable: true, get: function () { return convert_1.flowFromTaskPlan; } });
44
+ Object.defineProperty(exports, "flowFromStaticFlow", { enumerable: true, get: function () { return convert_1.flowFromStaticFlow; } });
45
+ var approval_handler_1 = require("./approval-handler");
46
+ Object.defineProperty(exports, "createApprovalHandler", { enumerable: true, get: function () { return approval_handler_1.createApprovalHandler; } });
47
+ Object.defineProperty(exports, "summarizeApproval", { enumerable: true, get: function () { return approval_handler_1.summarizeApproval; } });
48
+ Object.defineProperty(exports, "ApprovalControlError", { enumerable: true, get: function () { return approval_handler_1.ApprovalControlError; } });
49
+ var tools_1 = require("./tools");
50
+ Object.defineProperty(exports, "createFlowTools", { enumerable: true, get: function () { return tools_1.createFlowTools; } });
51
+ var planner_1 = require("./planner");
52
+ Object.defineProperty(exports, "planFlow", { enumerable: true, get: function () { return planner_1.planFlow; } });
53
+ Object.defineProperty(exports, "PLANNER_SYSTEM", { enumerable: true, get: function () { return planner_1.PLANNER_SYSTEM; } });
54
+ Object.defineProperty(exports, "UNRESOLVED_AGENT", { enumerable: true, get: function () { return planner_1.UNRESOLVED_AGENT; } });
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/flow/index.ts"],"names":[],"mappings":";;;AAAA,iCAEiB;AADb,0GAAA,iBAAiB,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,+GAAA,sBAAsB,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAGnG,mCAA8F;AAArF,mGAAA,SAAS,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AAC3E,+BAAgE;AAAvD,gGAAA,QAAQ,OAAA;AAAE,qGAAA,aAAa,OAAA;AAAE,qGAAA,aAAa,OAAA;AAE/C,qCAAgE;AAAvD,4GAAA,iBAAiB,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAE5C,6BAAgD;AAAvC,8FAAA,OAAO,OAAA;AAAE,qGAAA,cAAc,OAAA;AAIhC,qCAAoD;AAA3C,kHAAA,uBAAuB,OAAA;AAEhC,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,qCAAoF;AAA3E,2GAAA,gBAAgB,OAAA;AAAE,qGAAA,UAAU,OAAA;AAAE,yGAAA,OAAO,OAAkB;AAIhE,+CAAgD;AAAvC,8GAAA,cAAc,OAAA;AACvB,qCAA4D;AAAnD,6GAAA,kBAAkB,OAAA;AAAE,sGAAA,WAAW,OAAA;AACxC,uCAAgE;AAAvD,8GAAA,kBAAkB,OAAA;AAAE,0GAAA,cAAc,OAAA;AAE3C,qCAAiE;AAAxD,2GAAA,gBAAgB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAE7C,uDAAoG;AAA3F,yHAAA,qBAAqB,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AAAE,wHAAA,oBAAoB,OAAA;AAEvE,iCAA0C;AAAjC,wGAAA,eAAe,OAAA;AAExB,qCAAuE;AAA9D,mGAAA,QAAQ,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,2GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Replaces `{{payload}}` and `{{payload.a.b}}` with values from the payload.
3
+ * Objects are JSON-stringified; missing paths render as `null`.
4
+ */
5
+ export declare function interpolate(template: string, payload: unknown): string;
6
+ //# sourceMappingURL=interpolate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/flow/interpolate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAWtE"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interpolate = interpolate;
4
+ /**
5
+ * Replaces `{{payload}}` and `{{payload.a.b}}` with values from the payload.
6
+ * Objects are JSON-stringified; missing paths render as `null`.
7
+ */
8
+ function interpolate(template, payload) {
9
+ return template.replace(/\{\{\s*payload((?:\.[\w-]+)*)\s*\}\}/g, (_match, pathStr) => {
10
+ const value = pathStr
11
+ ? pathStr.slice(1).split('.').reduce((acc, key) => acc?.[key], payload)
12
+ : payload;
13
+ if (value === undefined || value === null)
14
+ return 'null';
15
+ return typeof value === 'string' ? value : JSON.stringify(value);
16
+ });
17
+ }
18
+ //# sourceMappingURL=interpolate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../src/flow/interpolate.ts"],"names":[],"mappings":";;AAIA,kCAWC;AAfD;;;GAGG;AACH,SAAgB,WAAW,CAAC,QAAgB,EAAE,OAAgB;IAC1D,OAAO,QAAQ,CAAC,OAAO,CAAC,uCAAuC,EAAE,CAAC,MAAM,EAAE,OAAe,EAAE,EAAE;QACzF,MAAM,KAAK,GAAG,OAAO;YACjB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAChC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAE,GAA2C,EAAE,CAAC,GAAG,CAAC,EACjE,OAAO,CACV;YACD,CAAC,CAAC,OAAO,CAAC;QACd,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QACzD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,105 @@
1
+ import type { FlowTransition } from './types';
2
+ /**
3
+ * The durable record of a flow run (SPEC-0023 F3): which step the run is on, what each one produced, who owns the run.
4
+ * It is what lets a restarted process resume without repeating a step that is done.
5
+ *
6
+ * It holds step outputs (the next step needs them to resume), so it is as sensitive as the conversation history. Only the
7
+ * input preview and error texts go through the optional `redact`; the payload itself is NOT stored: whoever resumes a run
8
+ * supplies it again.
9
+ */
10
+ export type JournalStepStatus = 'pending' | 'running' | 'done' | 'failed' | 'skipped' | 'awaiting_approval' | 'interrupted';
11
+ export type JournalRunStatus = 'running' | 'paused' | 'awaiting_approval' | 'done' | 'failed' | 'cancelled' | 'lost';
12
+ export interface JournalStep {
13
+ status: JournalStepStatus;
14
+ output?: string;
15
+ error?: string;
16
+ /** How many times the step has been started (the idempotency key carries it). */
17
+ attempt: number;
18
+ at: string;
19
+ costUsd?: number;
20
+ }
21
+ export interface JournalRun {
22
+ runId: string;
23
+ flow: string;
24
+ tenantId?: string;
25
+ startedAt: string;
26
+ updatedAt: string;
27
+ finishedAt?: string;
28
+ status: JournalRunStatus;
29
+ /** Cut and masked: never the raw payload. */
30
+ inputPreview: string;
31
+ steps: Record<string, JournalStep>;
32
+ waiting?: {
33
+ stepId: string;
34
+ approvalId: string;
35
+ criteria?: string[];
36
+ };
37
+ transitions: FlowTransition[];
38
+ error?: string;
39
+ costUsd?: number;
40
+ }
41
+ export type NewJournalRun = Pick<JournalRun, 'runId' | 'flow' | 'inputPreview'> & {
42
+ tenantId?: string;
43
+ };
44
+ export interface StepPatch extends Partial<Omit<JournalStep, 'at'>> {
45
+ transitions?: FlowTransition[];
46
+ }
47
+ export interface RunPatch {
48
+ status?: JournalRunStatus;
49
+ error?: string;
50
+ costUsd?: number;
51
+ waiting?: JournalRun['waiting'] | null;
52
+ transitions?: FlowTransition[];
53
+ }
54
+ export interface RunJournal {
55
+ /** Creates the run. Fails if the id already exists. */
56
+ begin(run: NewJournalRun): Promise<void>;
57
+ /** Writes the change BEFORE the step runs (`running`) and AFTER (`done`/`failed`). A journal that cannot write throws: the caller must not run the step. */
58
+ step(runId: string, stepId: string, patch: StepPatch): Promise<void>;
59
+ update(runId: string, patch: RunPatch): Promise<void>;
60
+ /** One owner per run, with expiry. Returns the release function, or null if another owner holds it. */
61
+ claim(runId: string, owner: string, ttlMs: number): Promise<(() => Promise<void>) | null>;
62
+ get(runId: string): Promise<JournalRun | undefined>;
63
+ list(filter?: {
64
+ status?: JournalRunStatus[];
65
+ flow?: string;
66
+ tenantId?: string;
67
+ }): Promise<JournalRun[]>;
68
+ }
69
+ export type JournalEvent = {
70
+ kind: 'begin';
71
+ at: string;
72
+ run: NewJournalRun;
73
+ } | {
74
+ kind: 'step';
75
+ at: string;
76
+ stepId: string;
77
+ patch: StepPatch;
78
+ } | {
79
+ kind: 'update';
80
+ at: string;
81
+ patch: RunPatch;
82
+ };
83
+ export declare function foldEvents(events: JournalEvent[]): JournalRun | undefined;
84
+ export declare function matches(run: JournalRun, filter?: {
85
+ status?: JournalRunStatus[];
86
+ flow?: string;
87
+ tenantId?: string;
88
+ }): boolean;
89
+ /** In memory: for tests and for processes whose runs need not outlive them. */
90
+ export declare class MemoryRunJournal implements RunJournal {
91
+ private readonly logs;
92
+ private readonly claims;
93
+ begin(run: NewJournalRun): Promise<void>;
94
+ private log;
95
+ step(runId: string, stepId: string, patch: StepPatch): Promise<void>;
96
+ update(runId: string, patch: RunPatch): Promise<void>;
97
+ claim(runId: string, owner: string, ttlMs: number): Promise<(() => Promise<void>) | null>;
98
+ get(runId: string): Promise<JournalRun | undefined>;
99
+ list(filter?: {
100
+ status?: JournalRunStatus[];
101
+ flow?: string;
102
+ tenantId?: string;
103
+ }): Promise<JournalRun[]>;
104
+ }
105
+ //# sourceMappingURL=journal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.d.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,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAQzF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAKnD,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;CAQhH"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryRunJournal = void 0;
4
+ exports.foldEvents = foldEvents;
5
+ exports.matches = matches;
6
+ const TERMINAL = ['done', 'failed', 'cancelled'];
7
+ function foldEvents(events) {
8
+ let run;
9
+ for (const ev of events) {
10
+ if (ev.kind === 'begin') {
11
+ run = { ...ev.run, startedAt: ev.at, updatedAt: ev.at, status: 'running', steps: {}, transitions: [] };
12
+ continue;
13
+ }
14
+ if (!run)
15
+ continue;
16
+ run.updatedAt = ev.at;
17
+ if (ev.kind === 'step') {
18
+ const { transitions, ...rest } = ev.patch;
19
+ const prev = run.steps[ev.stepId] ?? { status: 'pending', attempt: 0, at: ev.at };
20
+ run.steps[ev.stepId] = { ...prev, ...rest, at: ev.at };
21
+ if (transitions)
22
+ run.transitions.push(...transitions);
23
+ }
24
+ else {
25
+ const { transitions, waiting, ...rest } = ev.patch;
26
+ Object.assign(run, rest);
27
+ if (waiting === null)
28
+ delete run.waiting;
29
+ else if (waiting)
30
+ run.waiting = waiting;
31
+ if (transitions)
32
+ run.transitions.push(...transitions);
33
+ if (rest.status && TERMINAL.includes(rest.status))
34
+ run.finishedAt = ev.at;
35
+ }
36
+ }
37
+ return run;
38
+ }
39
+ function matches(run, filter = {}) {
40
+ return (!filter.status || filter.status.includes(run.status))
41
+ && (!filter.flow || run.flow === filter.flow)
42
+ && (!filter.tenantId || run.tenantId === filter.tenantId);
43
+ }
44
+ /** In memory: for tests and for processes whose runs need not outlive them. */
45
+ class MemoryRunJournal {
46
+ logs = new Map();
47
+ claims = new Map();
48
+ async begin(run) {
49
+ if (this.logs.has(run.runId))
50
+ throw new Error(`run "${run.runId}" already exists`);
51
+ this.logs.set(run.runId, [{ kind: 'begin', at: new Date().toISOString(), run }]);
52
+ }
53
+ log(runId) {
54
+ const l = this.logs.get(runId);
55
+ if (!l)
56
+ throw new Error(`run "${runId}" does not exist`);
57
+ return l;
58
+ }
59
+ async step(runId, stepId, patch) {
60
+ this.log(runId).push({ kind: 'step', at: new Date().toISOString(), stepId, patch });
61
+ }
62
+ async update(runId, patch) {
63
+ this.log(runId).push({ kind: 'update', at: new Date().toISOString(), patch });
64
+ }
65
+ async claim(runId, owner, ttlMs) {
66
+ const cur = this.claims.get(runId);
67
+ if (cur && cur.expiresAt > Date.now() && cur.owner !== owner)
68
+ return null;
69
+ const mine = { owner, expiresAt: Date.now() + ttlMs };
70
+ this.claims.set(runId, mine);
71
+ return async () => { if (this.claims.get(runId) === mine)
72
+ this.claims.delete(runId); };
73
+ }
74
+ async get(runId) {
75
+ const l = this.logs.get(runId);
76
+ return l ? foldEvents(l) : undefined;
77
+ }
78
+ async list(filter) {
79
+ const out = [];
80
+ for (const l of this.logs.values()) {
81
+ const r = foldEvents(l);
82
+ if (r && matches(r, filter))
83
+ out.push(r);
84
+ }
85
+ return out.sort((a, b) => a.startedAt.localeCompare(b.startedAt));
86
+ }
87
+ }
88
+ exports.MemoryRunJournal = MemoryRunJournal;
89
+ //# sourceMappingURL=journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/flow/journal.ts"],"names":[],"mappings":";;;AA4EA,gCAuBC;AAED,0BAIC;AA/BD,MAAM,QAAQ,GAAuB,CAAC,MAAM,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AAE,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI;YAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa;QACnB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAA0E;QACjF,MAAM,GAAG,GAAiB,EAAE,CAAC;QAC7B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACtE,CAAC;CACJ;AA5CD,4CA4CC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A cap on how many things run at once per key (an agent id, a tenant id). In process: a limit shared across processes is
3
+ * the integrator's implementation of the same interface (SPEC-0023 D4).
4
+ */
5
+ export interface ConcurrencyLimiter {
6
+ /** Resolves with a release function once a slot for `key` is free. Rejects if `signal` aborts while waiting. */
7
+ acquire(key: string, signal?: AbortSignal): Promise<() => void>;
8
+ }
9
+ export interface KeyedLimiterOptions {
10
+ /** Slots per key. A function lets each key have its own. Default: unlimited. */
11
+ max?: number | ((key: string) => number | undefined);
12
+ }
13
+ export declare class KeyedConcurrencyLimiter implements ConcurrencyLimiter {
14
+ private readonly opts;
15
+ private readonly active;
16
+ private readonly waiting;
17
+ constructor(opts?: KeyedLimiterOptions);
18
+ private limitFor;
19
+ acquire(key: string, signal?: AbortSignal): Promise<() => void>;
20
+ }
21
+ //# sourceMappingURL=limiter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limiter.d.ts","sourceRoot":"","sources":["../../src/flow/limiter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B,gHAAgH;IAChH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,mBAAmB;IAChC,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC;CACxD;AAED,qBAAa,uBAAwB,YAAW,kBAAkB;IAIlD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;gBAEnC,IAAI,GAAE,mBAAwB;IAE3D,OAAO,CAAC,QAAQ;IAKV,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;CAyBxE"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyedConcurrencyLimiter = void 0;
4
+ class KeyedConcurrencyLimiter {
5
+ opts;
6
+ active = new Map();
7
+ waiting = new Map();
8
+ constructor(opts = {}) {
9
+ this.opts = opts;
10
+ }
11
+ limitFor(key) {
12
+ const m = typeof this.opts.max === 'function' ? this.opts.max(key) : this.opts.max;
13
+ return m === undefined ? Infinity : Math.max(1, m);
14
+ }
15
+ async acquire(key, signal) {
16
+ if (signal?.aborted)
17
+ throw new Error('aborted');
18
+ while ((this.active.get(key) ?? 0) >= this.limitFor(key)) {
19
+ await new Promise((resolve, reject) => {
20
+ const q = this.waiting.get(key) ?? [];
21
+ const wake = () => { signal?.removeEventListener('abort', onAbort); resolve(); };
22
+ const onAbort = () => {
23
+ const i = q.indexOf(wake);
24
+ if (i >= 0)
25
+ q.splice(i, 1);
26
+ reject(new Error('aborted'));
27
+ };
28
+ q.push(wake);
29
+ this.waiting.set(key, q);
30
+ signal?.addEventListener('abort', onAbort, { once: true });
31
+ });
32
+ }
33
+ this.active.set(key, (this.active.get(key) ?? 0) + 1);
34
+ let released = false;
35
+ return () => {
36
+ if (released)
37
+ return;
38
+ released = true;
39
+ this.active.set(key, (this.active.get(key) ?? 1) - 1);
40
+ this.waiting.get(key)?.shift()?.();
41
+ };
42
+ }
43
+ }
44
+ exports.KeyedConcurrencyLimiter = KeyedConcurrencyLimiter;
45
+ //# sourceMappingURL=limiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limiter.js","sourceRoot":"","sources":["../../src/flow/limiter.ts"],"names":[],"mappings":";;;AAcA,MAAa,uBAAuB;IAIH;IAHZ,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnC,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;IAEhE,YAA6B,OAA4B,EAAE;QAA9B,SAAI,GAAJ,IAAI,CAA0B;IAAG,CAAC;IAEvD,QAAQ,CAAC,GAAW;QACxB,MAAM,CAAC,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACnF,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,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C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,OAAO,GAAG,EAAE;YACR,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACtD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QACvC,CAAC,CAAC;IACN,CAAC;CACJ;AApCD,0DAoCC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Flow loader: parses and validates declarative flow YAML (SPEC-0023).
3
+ *
4
+ * Validation happens in two layers:
5
+ * 1. Structural (Zod): shapes, required fields, enums.
6
+ * 2. Semantic: duplicate step ids, unknown `after` references, dependency
7
+ * cycles, trigger coherence, compensation selectors, and the static
8
+ * half of the compliance rule — a gate evaluator can never be the
9
+ * step's own executor (evaluador ≠ ejecutor, ADR-3).
10
+ */
11
+ import { type FlowDefinition } from './types';
12
+ export declare class FlowLoadError extends Error {
13
+ readonly issues: string[];
14
+ constructor(flowName: string, issues: string[]);
15
+ }
16
+ /** Parses a YAML string into a validated FlowDefinition. */
17
+ export declare function parseFlow(yamlContent: string): FlowDefinition;
18
+ /** Loads and validates a single flow file. */
19
+ export declare function loadFlow(filePath: string): Promise<FlowDefinition>;
20
+ /** Loads every `*.yaml` / `*.yml` in a directory. Throws on the first invalid flow. */
21
+ export declare function loadFlowsFromDir(dir: string): Promise<FlowDefinition[]>;
22
+ /** The semantic half of the validation: duplicate ids, unknown or self references, cycles, the trigger and the compensation selectors. */
23
+ export declare function validateFlow(def: FlowDefinition): string[];
24
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/flow/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAEpE,qBAAa,aAAc,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAKjD;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CAsB7D;AAED,8CAA8C;AAC9C,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAGxE;AAED,uFAAuF;AACvF,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAU7E;AAID,0IAA0I;AAC1I,wBAAgB,YAAY,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,EAAE,CA4C1D"}
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ /**
3
+ * Flow loader: parses and validates declarative flow YAML (SPEC-0023).
4
+ *
5
+ * Validation happens in two layers:
6
+ * 1. Structural (Zod): shapes, required fields, enums.
7
+ * 2. Semantic: duplicate step ids, unknown `after` references, dependency
8
+ * cycles, trigger coherence, compensation selectors, and the static
9
+ * half of the compliance rule — a gate evaluator can never be the
10
+ * step's own executor (evaluador ≠ ejecutor, ADR-3).
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.FlowLoadError = void 0;
47
+ exports.parseFlow = parseFlow;
48
+ exports.loadFlow = loadFlow;
49
+ exports.loadFlowsFromDir = loadFlowsFromDir;
50
+ exports.validateFlow = validateFlow;
51
+ const fs = __importStar(require("fs/promises"));
52
+ const path = __importStar(require("path"));
53
+ const yaml = __importStar(require("yaml"));
54
+ const types_1 = require("./types");
55
+ class FlowLoadError extends Error {
56
+ issues;
57
+ constructor(flowName, issues) {
58
+ super(`Invalid flow "${flowName}":\n${issues.map(i => ` - ${i}`).join('\n')}`);
59
+ this.name = 'FlowLoadError';
60
+ this.issues = issues;
61
+ }
62
+ }
63
+ exports.FlowLoadError = FlowLoadError;
64
+ /** Parses a YAML string into a validated FlowDefinition. */
65
+ function parseFlow(yamlContent) {
66
+ let raw;
67
+ try {
68
+ raw = yaml.parse(yamlContent);
69
+ }
70
+ catch (err) {
71
+ throw new FlowLoadError('<unparsed>', [`YAML syntax error: ${err.message}`]);
72
+ }
73
+ const parsed = types_1.FlowDefinitionSchema.safeParse(raw);
74
+ if (!parsed.success) {
75
+ const name = raw?.flow;
76
+ throw new FlowLoadError(typeof name === 'string' ? name : '<unknown>', parsed.error.issues.map(i => `${i.path.join('.')}: ${i.message}`));
77
+ }
78
+ const def = parsed.data;
79
+ const issues = validateFlow(def);
80
+ if (issues.length > 0)
81
+ throw new FlowLoadError(def.flow, issues);
82
+ return def;
83
+ }
84
+ /** Loads and validates a single flow file. */
85
+ async function loadFlow(filePath) {
86
+ const content = await fs.readFile(filePath, 'utf-8');
87
+ return parseFlow(content);
88
+ }
89
+ /** Loads every `*.yaml` / `*.yml` in a directory. Throws on the first invalid flow. */
90
+ async function loadFlowsFromDir(dir) {
91
+ const entries = await fs.readdir(dir);
92
+ const files = entries
93
+ .filter(f => f.endsWith('.yaml') || f.endsWith('.yml'))
94
+ .sort();
95
+ const flows = [];
96
+ for (const file of files) {
97
+ flows.push(await loadFlow(path.join(dir, file)));
98
+ }
99
+ return flows;
100
+ }
101
+ // ── Semantic validation ───────────────────────────────────────────────────────
102
+ /** The semantic half of the validation: duplicate ids, unknown or self references, cycles, the trigger and the compensation selectors. */
103
+ function validateFlow(def) {
104
+ const issues = [];
105
+ const ids = new Set();
106
+ for (const step of def.steps) {
107
+ if (ids.has(step.id))
108
+ issues.push(`duplicate step id "${step.id}"`);
109
+ ids.add(step.id);
110
+ }
111
+ for (const step of def.steps) {
112
+ for (const dep of step.after) {
113
+ if (!ids.has(dep)) {
114
+ issues.push(`step "${step.id}" references unknown step "${dep}" in after`);
115
+ }
116
+ if (dep === step.id) {
117
+ issues.push(`step "${step.id}" cannot depend on itself`);
118
+ }
119
+ }
120
+ if (step.when) {
121
+ if (!step.after.includes(step.when.step)) {
122
+ issues.push(`step "${step.id}": when.step "${step.when.step}" must be one of its after (a condition looks at a step it waits for)`);
123
+ }
124
+ if (step.when.matches !== undefined) {
125
+ try {
126
+ new RegExp(step.when.matches);
127
+ }
128
+ catch {
129
+ issues.push(`step "${step.id}": when.matches is not a valid regular expression`);
130
+ }
131
+ }
132
+ }
133
+ if (step.gate?.evaluator && step.gate.evaluator === step.agent) {
134
+ issues.push(`step "${step.id}": gate evaluator "${step.gate.evaluator}" must differ from the executing agent (evaluador ≠ ejecutor)`);
135
+ }
136
+ }
137
+ issues.push(...detectCycles(def));
138
+ issues.push(...validateTrigger(def));
139
+ for (const comp of def.compensation) {
140
+ const stepId = comp.on.replace(/\.failed$/, '');
141
+ if (!ids.has(stepId)) {
142
+ issues.push(`compensation "on: ${comp.on}" references unknown step "${stepId}"`);
143
+ }
144
+ }
145
+ return issues;
146
+ }
147
+ function detectCycles(def) {
148
+ const depMap = new Map(def.steps.map(s => [s.id, s.after]));
149
+ const visited = new Set();
150
+ const inStack = new Set();
151
+ const issues = [];
152
+ const dfs = (id) => {
153
+ if (inStack.has(id)) {
154
+ issues.push(`dependency cycle detected at step "${id}"`);
155
+ return;
156
+ }
157
+ if (visited.has(id))
158
+ return;
159
+ inStack.add(id);
160
+ for (const dep of depMap.get(id) ?? [])
161
+ dfs(dep);
162
+ inStack.delete(id);
163
+ visited.add(id);
164
+ };
165
+ for (const step of def.steps) {
166
+ if (issues.length > 0)
167
+ break;
168
+ dfs(step.id);
169
+ }
170
+ return issues;
171
+ }
172
+ function validateTrigger(def) {
173
+ const t = def.trigger;
174
+ switch (t.type) {
175
+ case 'queue':
176
+ return t.queue ? [] : ['trigger type "queue" requires a queue name'];
177
+ case 'webhook':
178
+ return t.path ? [] : ['trigger type "webhook" requires a path'];
179
+ case 'cron':
180
+ return t.schedule ? [] : ['trigger type "cron" requires a schedule'];
181
+ case 'manual':
182
+ return [];
183
+ }
184
+ }
185
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/flow/loader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBH,8BAsBC;AAGD,4BAGC;AAGD,4CAUC;A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