@veil-runtime/core 0.1.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 (95) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +480 -0
  3. package/dist/index.d.ts +13 -0
  4. package/dist/index.js +21 -0
  5. package/dist/providers/storage/sqlite-job-store.d.ts +10 -0
  6. package/dist/providers/storage/sqlite-job-store.js +89 -0
  7. package/dist/runtime/events/event-bus.d.ts +6 -0
  8. package/dist/runtime/events/event-bus.js +2 -0
  9. package/dist/runtime/events/event-subscriber.d.ts +6 -0
  10. package/dist/runtime/events/event-subscriber.js +2 -0
  11. package/dist/runtime/events/memory-event-bus.d.ts +9 -0
  12. package/dist/runtime/events/memory-event-bus.js +31 -0
  13. package/dist/runtime/events/runtime-event.d.ts +10 -0
  14. package/dist/runtime/events/runtime-event.js +2 -0
  15. package/dist/runtime/execution/console-execution-logger.d.ts +13 -0
  16. package/dist/runtime/execution/console-execution-logger.js +37 -0
  17. package/dist/runtime/execution/execution-context.d.ts +13 -0
  18. package/dist/runtime/execution/execution-context.js +2 -0
  19. package/dist/runtime/execution/execution-logger.d.ts +15 -0
  20. package/dist/runtime/execution/execution-logger.js +2 -0
  21. package/dist/runtime/execution/plan-validator.d.ts +13 -0
  22. package/dist/runtime/execution/plan-validator.js +122 -0
  23. package/dist/runtime/execution/result-reference.d.ts +9 -0
  24. package/dist/runtime/execution/result-reference.js +59 -0
  25. package/dist/runtime/jobs/job-event.d.ts +8 -0
  26. package/dist/runtime/jobs/job-event.js +2 -0
  27. package/dist/runtime/jobs/job-manager.d.ts +17 -0
  28. package/dist/runtime/jobs/job-manager.js +214 -0
  29. package/dist/runtime/jobs/job-memory.d.ts +6 -0
  30. package/dist/runtime/jobs/job-memory.js +70 -0
  31. package/dist/runtime/jobs/job-status.d.ts +1 -0
  32. package/dist/runtime/jobs/job-status.js +2 -0
  33. package/dist/runtime/jobs/job-step.d.ts +10 -0
  34. package/dist/runtime/jobs/job-step.js +2 -0
  35. package/dist/runtime/jobs/job-store.d.ts +15 -0
  36. package/dist/runtime/jobs/job-store.js +52 -0
  37. package/dist/runtime/jobs/job.d.ts +20 -0
  38. package/dist/runtime/jobs/job.js +2 -0
  39. package/dist/runtime/logging/composite-log-sink.d.ts +7 -0
  40. package/dist/runtime/logging/composite-log-sink.js +13 -0
  41. package/dist/runtime/logging/console-log-sink.d.ts +6 -0
  42. package/dist/runtime/logging/console-log-sink.js +28 -0
  43. package/dist/runtime/logging/execution-log-sink.d.ts +4 -0
  44. package/dist/runtime/logging/execution-log-sink.js +2 -0
  45. package/dist/runtime/logging/sqlite-log-sink.d.ts +7 -0
  46. package/dist/runtime/logging/sqlite-log-sink.js +52 -0
  47. package/dist/runtime/modules/capability-module-manifest.d.ts +11 -0
  48. package/dist/runtime/modules/capability-module-manifest.js +2 -0
  49. package/dist/runtime/modules/capability-module.d.ts +6 -0
  50. package/dist/runtime/modules/capability-module.js +2 -0
  51. package/dist/runtime/operator-runtime.d.ts +31 -0
  52. package/dist/runtime/operator-runtime.js +71 -0
  53. package/dist/runtime/permissions/permissions.d.ts +7 -0
  54. package/dist/runtime/permissions/permissions.js +42 -0
  55. package/dist/runtime/planner/planner-definition.d.ts +9 -0
  56. package/dist/runtime/planner/planner-definition.js +2 -0
  57. package/dist/runtime/planner/planner-eligibility.d.ts +7 -0
  58. package/dist/runtime/planner/planner-eligibility.js +20 -0
  59. package/dist/runtime/planner/planner-provider.d.ts +11 -0
  60. package/dist/runtime/planner/planner-provider.js +2 -0
  61. package/dist/runtime/planner/planner-registry.d.ts +40 -0
  62. package/dist/runtime/planner/planner-registry.js +103 -0
  63. package/dist/runtime/planner/planner-router-registry.d.ts +17 -0
  64. package/dist/runtime/planner/planner-router-registry.js +37 -0
  65. package/dist/runtime/planner/planner-router.d.ts +14 -0
  66. package/dist/runtime/planner/planner-router.js +2 -0
  67. package/dist/runtime/planner/planner-runtime-state.d.ts +6 -0
  68. package/dist/runtime/planner/planner-runtime-state.js +2 -0
  69. package/dist/runtime/planner/planner-traits.d.ts +10 -0
  70. package/dist/runtime/planner/planner-traits.js +2 -0
  71. package/dist/runtime/planner/planner.d.ts +29 -0
  72. package/dist/runtime/planner/planner.js +2 -0
  73. package/dist/runtime/planner/strategies/planner-strategy-registry.d.ts +12 -0
  74. package/dist/runtime/planner/strategies/planner-strategy-registry.js +22 -0
  75. package/dist/runtime/planner/strategies/planner-strategy.d.ts +11 -0
  76. package/dist/runtime/planner/strategies/planner-strategy.js +2 -0
  77. package/dist/runtime/registry/capability.d.ts +15 -0
  78. package/dist/runtime/registry/capability.js +2 -0
  79. package/dist/runtime/registry/registry.d.ts +15 -0
  80. package/dist/runtime/registry/registry.js +25 -0
  81. package/dist/sdk/capability/capability-definition.d.ts +19 -0
  82. package/dist/sdk/capability/capability-definition.js +2 -0
  83. package/dist/sdk/capability/capability-middleware.d.ts +5 -0
  84. package/dist/sdk/capability/capability-middleware.js +2 -0
  85. package/dist/sdk/capability/create-capability.d.ts +3 -0
  86. package/dist/sdk/capability/create-capability.js +37 -0
  87. package/dist/sdk/capability/index.d.ts +5 -0
  88. package/dist/sdk/capability/index.js +9 -0
  89. package/dist/sdk/capability/lifecycle-logging-middleware.d.ts +7 -0
  90. package/dist/sdk/capability/lifecycle-logging-middleware.js +35 -0
  91. package/dist/sdk/capability/timeout-middleware.d.ts +7 -0
  92. package/dist/sdk/capability/timeout-middleware.js +43 -0
  93. package/dist/sdk/index.d.ts +1 -0
  94. package/dist/sdk/index.js +17 -0
  95. package/package.json +70 -0
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.operatorRuntime = exports.OperatorRuntime = void 0;
18
+ var operator_runtime_js_1 = require("./runtime/operator-runtime.js");
19
+ Object.defineProperty(exports, "OperatorRuntime", { enumerable: true, get: function () { return operator_runtime_js_1.OperatorRuntime; } });
20
+ Object.defineProperty(exports, "operatorRuntime", { enumerable: true, get: function () { return operator_runtime_js_1.operatorRuntime; } });
21
+ __exportStar(require("./sdk/index.js"), exports);
@@ -0,0 +1,10 @@
1
+ import { Job } from '../../runtime/jobs/job.js';
2
+ import { JobListFilter, JobStore } from '../../runtime/jobs/job-store.js';
3
+ export declare class SQLiteJobStore implements JobStore {
4
+ private readonly db;
5
+ constructor(path?: string);
6
+ create(job: Job): Promise<Job>;
7
+ get(id: string): Promise<Job | undefined>;
8
+ list(filter?: JobListFilter): Promise<Job[]>;
9
+ update(job: Job): Promise<Job>;
10
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SQLiteJobStore = void 0;
7
+ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
8
+ class SQLiteJobStore {
9
+ db;
10
+ constructor(path = './data/operator.db') {
11
+ this.db = new better_sqlite3_1.default(path);
12
+ this.db.exec(`
13
+ CREATE TABLE IF NOT EXISTS jobs (
14
+ id TEXT PRIMARY KEY,
15
+ data TEXT NOT NULL,
16
+ created_at TEXT NOT NULL,
17
+ updated_at TEXT NOT NULL
18
+ )
19
+ `);
20
+ }
21
+ async create(job) {
22
+ const statement = this.db.prepare(`
23
+ INSERT INTO jobs (
24
+ id,
25
+ data,
26
+ created_at,
27
+ updated_at
28
+ )
29
+ VALUES (?, ?, ?, ?)
30
+ `);
31
+ statement.run(job.id, JSON.stringify(job), job.createdAt, job.updatedAt);
32
+ return job;
33
+ }
34
+ async get(id) {
35
+ const row = this.db
36
+ .prepare(`
37
+ SELECT data
38
+ FROM jobs
39
+ WHERE id = ?
40
+ `)
41
+ .get(id);
42
+ if (!row) {
43
+ return undefined;
44
+ }
45
+ return JSON.parse(row.data);
46
+ }
47
+ async list(filter) {
48
+ const rows = this.db
49
+ .prepare(`
50
+ SELECT data
51
+ FROM jobs
52
+ ORDER BY created_at DESC
53
+ `)
54
+ .all();
55
+ let jobs = rows.map((row) => JSON.parse(row.data));
56
+ if (filter?.status) {
57
+ jobs = jobs.filter((job) => job.status === filter.status);
58
+ }
59
+ if (filter?.planner) {
60
+ jobs = jobs.filter((job) => job.planner === filter.planner);
61
+ }
62
+ if (filter?.capability) {
63
+ jobs = jobs.filter((job) => job.steps.some((step) => step.capability === filter.capability));
64
+ }
65
+ if (filter?.goal) {
66
+ const goal = filter.goal.toLowerCase();
67
+ jobs = jobs.filter((job) => job.goal.toLowerCase().includes(goal));
68
+ }
69
+ if (filter?.limit && filter.limit > 0) {
70
+ jobs = jobs.slice(0, filter.limit);
71
+ }
72
+ return jobs;
73
+ }
74
+ async update(job) {
75
+ const statement = this.db.prepare(`
76
+ UPDATE jobs
77
+ SET
78
+ data = ?,
79
+ updated_at = ?
80
+ WHERE id = ?
81
+ `);
82
+ const result = statement.run(JSON.stringify(job), job.updatedAt, job.id);
83
+ if (result.changes === 0) {
84
+ throw new Error(`Job not found: ${job.id}`);
85
+ }
86
+ return job;
87
+ }
88
+ }
89
+ exports.SQLiteJobStore = SQLiteJobStore;
@@ -0,0 +1,6 @@
1
+ import { RuntimeEvent, RuntimeEventType } from './runtime-event.js';
2
+ import { EventSubscriber } from './event-subscriber.js';
3
+ export interface EventBus {
4
+ publish(event: RuntimeEvent): Promise<void>;
5
+ subscribe(type: RuntimeEventType | '*', handler: EventSubscriber): () => void;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { RuntimeEvent, RuntimeEventType } from './runtime-event.js';
2
+ export type EventSubscriber<TEvent extends RuntimeEvent = RuntimeEvent> = (event: TEvent) => Promise<void> | void;
3
+ export interface EventSubscription {
4
+ type: RuntimeEventType | '*';
5
+ handler: EventSubscriber;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { RuntimeEvent, RuntimeEventType } from './runtime-event.js';
2
+ import { EventSubscriber } from './event-subscriber.js';
3
+ import { EventBus } from './event-bus.js';
4
+ export declare class MemoryEventBus implements EventBus {
5
+ private readonly subscribers;
6
+ subscribe(type: RuntimeEventType | '*', handler: EventSubscriber): () => void;
7
+ publish(event: RuntimeEvent): Promise<void>;
8
+ }
9
+ export declare const runtimeEventBus: MemoryEventBus;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runtimeEventBus = exports.MemoryEventBus = void 0;
4
+ class MemoryEventBus {
5
+ subscribers = new Map();
6
+ subscribe(type, handler) {
7
+ const handlers = this.subscribers.get(type) ??
8
+ new Set();
9
+ handlers.add(handler);
10
+ this.subscribers.set(type, handlers);
11
+ return () => {
12
+ handlers.delete(handler);
13
+ if (handlers.size === 0) {
14
+ this.subscribers.delete(type);
15
+ }
16
+ };
17
+ }
18
+ async publish(event) {
19
+ const specific = this.subscribers.get(event.type) ??
20
+ new Set();
21
+ const wildcard = this.subscribers.get('*') ??
22
+ new Set();
23
+ const handlers = [
24
+ ...specific,
25
+ ...wildcard,
26
+ ];
27
+ await Promise.all(handlers.map((handler) => Promise.resolve(handler(event))));
28
+ }
29
+ }
30
+ exports.MemoryEventBus = MemoryEventBus;
31
+ exports.runtimeEventBus = new MemoryEventBus();
@@ -0,0 +1,10 @@
1
+ import { JobEventType } from '../jobs/job-event.js';
2
+ export type RuntimeEventType = JobEventType;
3
+ export interface RuntimeEvent<TData extends Record<string, unknown> = Record<string, unknown>> {
4
+ id: string;
5
+ type: RuntimeEventType;
6
+ timestamp: string;
7
+ jobId?: string;
8
+ stepId?: string;
9
+ data?: TData;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { ExecutionLogger } from './execution-logger.js';
2
+ import { ExecutionLogSink } from '../logging/execution-log-sink.js';
3
+ export declare class ConsoleExecutionLogger implements ExecutionLogger {
4
+ private readonly jobId;
5
+ private readonly stepId;
6
+ private readonly sink;
7
+ constructor(jobId: string, stepId: string, sink: ExecutionLogSink);
8
+ debug(message: string, metadata?: Record<string, unknown>): void;
9
+ info(message: string, metadata?: Record<string, unknown>): void;
10
+ warn(message: string, metadata?: Record<string, unknown>): void;
11
+ error(message: string, metadata?: Record<string, unknown>): void;
12
+ private write;
13
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleExecutionLogger = void 0;
4
+ class ConsoleExecutionLogger {
5
+ jobId;
6
+ stepId;
7
+ sink;
8
+ constructor(jobId, stepId, sink) {
9
+ this.jobId = jobId;
10
+ this.stepId = stepId;
11
+ this.sink = sink;
12
+ }
13
+ debug(message, metadata) {
14
+ this.write('debug', message, metadata);
15
+ }
16
+ info(message, metadata) {
17
+ this.write('info', message, metadata);
18
+ }
19
+ warn(message, metadata) {
20
+ this.write('warn', message, metadata);
21
+ }
22
+ error(message, metadata) {
23
+ this.write('error', message, metadata);
24
+ }
25
+ write(level, message, metadata) {
26
+ const entry = {
27
+ timestamp: new Date().toISOString(),
28
+ level,
29
+ message,
30
+ jobId: this.jobId,
31
+ stepId: this.stepId,
32
+ metadata,
33
+ };
34
+ void this.sink.write(entry);
35
+ }
36
+ }
37
+ exports.ConsoleExecutionLogger = ConsoleExecutionLogger;
@@ -0,0 +1,13 @@
1
+ import { ExecutionLogger } from './execution-logger.js';
2
+ export interface ExecutionCaller {
3
+ readonly subject?: string;
4
+ readonly tenant?: string;
5
+ readonly scopes?: readonly string[];
6
+ readonly metadata?: Readonly<Record<string, unknown>>;
7
+ }
8
+ export interface ExecutionContext {
9
+ readonly jobId: string;
10
+ readonly stepId: string;
11
+ readonly logger: ExecutionLogger;
12
+ readonly caller?: ExecutionCaller;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ export type ExecutionLogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ export interface ExecutionLogEntry {
3
+ timestamp: string;
4
+ level: ExecutionLogLevel;
5
+ message: string;
6
+ jobId: string;
7
+ stepId: string;
8
+ metadata?: Record<string, unknown>;
9
+ }
10
+ export interface ExecutionLogger {
11
+ debug(message: string, metadata?: Record<string, unknown>): void;
12
+ info(message: string, metadata?: Record<string, unknown>): void;
13
+ warn(message: string, metadata?: Record<string, unknown>): void;
14
+ error(message: string, metadata?: Record<string, unknown>): void;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { ExecutionStep } from '../planner/planner.js';
2
+ export interface PlanValidationError {
3
+ stepId: string;
4
+ capability: string;
5
+ field?: string;
6
+ message: string;
7
+ }
8
+ export interface PlanValidationResult {
9
+ valid: boolean;
10
+ errors: PlanValidationError[];
11
+ }
12
+ export declare function validateStepInput(step: ExecutionStep, input: unknown): PlanValidationResult;
13
+ export declare function validatePlan(steps: readonly ExecutionStep[]): PlanValidationResult;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateStepInput = validateStepInput;
4
+ exports.validatePlan = validatePlan;
5
+ const registry_js_1 = require("../registry/registry.js");
6
+ const result_reference_js_1 = require("./result-reference.js");
7
+ const TYPE_CHECKS = {
8
+ string: (value) => typeof value === 'string',
9
+ number: (value) => typeof value === 'number' && Number.isFinite(value),
10
+ boolean: (value) => typeof value === 'boolean',
11
+ object: (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value),
12
+ array: (value) => Array.isArray(value),
13
+ };
14
+ function validateInput(step, capability, allowReferences) {
15
+ const errors = [];
16
+ const input = step.input && typeof step.input === 'object' && !Array.isArray(step.input)
17
+ ? step.input
18
+ : {};
19
+ for (const [field, definition] of Object.entries(capability.inputSchema ?? {})) {
20
+ const value = input[field];
21
+ if (definition.required && (value === undefined || value === null || value === '')) {
22
+ errors.push({
23
+ stepId: step.id,
24
+ capability: step.capability,
25
+ field,
26
+ message: `Required input '${field}' is missing for capability '${step.capability}'`,
27
+ });
28
+ continue;
29
+ }
30
+ if (value === undefined || (allowReferences && (0, result_reference_js_1.isResultReference)(value))) {
31
+ continue;
32
+ }
33
+ const check = TYPE_CHECKS[definition.type];
34
+ if (!check) {
35
+ errors.push({
36
+ stepId: step.id,
37
+ capability: step.capability,
38
+ field,
39
+ message: `Unsupported schema type '${definition.type}' for capability '${step.capability}'`,
40
+ });
41
+ }
42
+ else if (!check(value)) {
43
+ errors.push({
44
+ stepId: step.id,
45
+ capability: step.capability,
46
+ field,
47
+ message: `Input '${field}' must be of type '${definition.type}' for capability '${step.capability}'`,
48
+ });
49
+ }
50
+ }
51
+ return errors;
52
+ }
53
+ function collectReferences(value) {
54
+ if ((0, result_reference_js_1.isResultReference)(value))
55
+ return [value.$ref];
56
+ if (Array.isArray(value))
57
+ return value.flatMap(collectReferences);
58
+ if (value && typeof value === 'object') {
59
+ return Object.values(value).flatMap(collectReferences);
60
+ }
61
+ return [];
62
+ }
63
+ function validateStepInput(step, input) {
64
+ const capability = registry_js_1.capabilityRegistry.get(step.capability);
65
+ if (!capability) {
66
+ return {
67
+ valid: false,
68
+ errors: [{
69
+ stepId: step.id,
70
+ capability: step.capability,
71
+ message: `Unknown capability: ${step.capability}`,
72
+ }],
73
+ };
74
+ }
75
+ const errors = validateInput({ ...step, input }, capability, false);
76
+ return { valid: errors.length === 0, errors };
77
+ }
78
+ function validatePlan(steps) {
79
+ const errors = [];
80
+ const seenStepIds = new Set();
81
+ for (const step of steps) {
82
+ const capability = registry_js_1.capabilityRegistry.get(step.capability);
83
+ if (!capability) {
84
+ errors.push({
85
+ stepId: step.id,
86
+ capability: step.capability,
87
+ message: `Unknown capability: ${step.capability}`,
88
+ });
89
+ seenStepIds.add(step.id);
90
+ continue;
91
+ }
92
+ if (step.capabilityVersion && step.capabilityVersion !== capability.version) {
93
+ errors.push({
94
+ stepId: step.id,
95
+ capability: step.capability,
96
+ message: `Capability version mismatch for '${step.capability}': requested ${step.capabilityVersion}, registered ${capability.version}`,
97
+ });
98
+ }
99
+ errors.push(...validateInput(step, capability, true));
100
+ for (const reference of collectReferences(step.input)) {
101
+ try {
102
+ const { stepId } = (0, result_reference_js_1.parseResultReference)(reference);
103
+ if (!seenStepIds.has(stepId)) {
104
+ errors.push({
105
+ stepId: step.id,
106
+ capability: step.capability,
107
+ message: `Result reference must target an earlier step: ${reference}`,
108
+ });
109
+ }
110
+ }
111
+ catch (error) {
112
+ errors.push({
113
+ stepId: step.id,
114
+ capability: step.capability,
115
+ message: error instanceof Error ? error.message : 'Invalid result reference',
116
+ });
117
+ }
118
+ }
119
+ seenStepIds.add(step.id);
120
+ }
121
+ return { valid: errors.length === 0, errors };
122
+ }
@@ -0,0 +1,9 @@
1
+ import { JobStep } from '../jobs/job-step.js';
2
+ export declare function isResultReference(value: unknown): value is {
3
+ readonly $ref: string;
4
+ };
5
+ export declare function parseResultReference(reference: string): {
6
+ stepId: string;
7
+ path: string[];
8
+ };
9
+ export declare function resolveResultReferences(value: unknown, completedSteps: readonly JobStep[]): unknown;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isResultReference = isResultReference;
4
+ exports.parseResultReference = parseResultReference;
5
+ exports.resolveResultReferences = resolveResultReferences;
6
+ const REFERENCE_PREFIX = 'steps.';
7
+ const RESULT_SEGMENT = '.result';
8
+ function isResultReference(value) {
9
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
10
+ return false;
11
+ }
12
+ const record = value;
13
+ return Object.keys(record).length === 1 && typeof record.$ref === 'string';
14
+ }
15
+ function parseResultReference(reference) {
16
+ if (!reference.startsWith(REFERENCE_PREFIX)) {
17
+ throw new Error(`Invalid result reference: ${reference}`);
18
+ }
19
+ const resultIndex = reference.indexOf(RESULT_SEGMENT);
20
+ if (resultIndex <= REFERENCE_PREFIX.length) {
21
+ throw new Error(`Invalid result reference: ${reference}`);
22
+ }
23
+ const stepId = reference.slice(REFERENCE_PREFIX.length, resultIndex);
24
+ const suffix = reference.slice(resultIndex + RESULT_SEGMENT.length);
25
+ if (suffix && !suffix.startsWith('.')) {
26
+ throw new Error(`Invalid result reference: ${reference}`);
27
+ }
28
+ return {
29
+ stepId,
30
+ path: suffix ? suffix.slice(1).split('.') : [],
31
+ };
32
+ }
33
+ function resolveResultReferences(value, completedSteps) {
34
+ if (isResultReference(value)) {
35
+ const { stepId, path } = parseResultReference(value.$ref);
36
+ const step = completedSteps.find((candidate) => candidate.id === stepId);
37
+ if (!step || step.status !== 'completed') {
38
+ throw new Error(`Result reference requires completed earlier step: ${stepId}`);
39
+ }
40
+ let resolved = step.result;
41
+ for (const segment of path) {
42
+ if (!resolved || typeof resolved !== 'object' || !(segment in resolved)) {
43
+ throw new Error(`Result reference path not found: ${value.$ref}`);
44
+ }
45
+ resolved = resolved[segment];
46
+ }
47
+ return resolved;
48
+ }
49
+ if (Array.isArray(value)) {
50
+ return value.map((item) => resolveResultReferences(item, completedSteps));
51
+ }
52
+ if (value && typeof value === 'object') {
53
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
54
+ key,
55
+ resolveResultReferences(item, completedSteps),
56
+ ]));
57
+ }
58
+ return value;
59
+ }
@@ -0,0 +1,8 @@
1
+ export type JobEventType = 'job.created' | 'planning.started' | 'planning.completed' | 'approval.requested' | 'approval.granted' | 'execution.started' | 'capability.started' | 'capability.completed' | 'capability.failed' | 'job.completed' | 'job.failed' | 'job.cancelled' | 'job.reviewed';
2
+ export interface JobEvent {
3
+ id: string;
4
+ jobId: string;
5
+ type: JobEventType;
6
+ timestamp: string;
7
+ data?: Record<string, unknown>;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import { ExecutionPlan } from '../planner/planner.js';
2
+ import { ExecutionCaller } from '../execution/execution-context.js';
3
+ import { Job, JobOutcome } from './job.js';
4
+ import { JobStatus } from './job-status.js';
5
+ import { JobListFilter } from './job-store.js';
6
+ declare class JobManager {
7
+ executePlan(plan: ExecutionPlan, caller?: ExecutionCaller): Promise<Job>;
8
+ create(goal: string, planner?: string): Promise<Job>;
9
+ get(id: string): Promise<Job | undefined>;
10
+ list(filter?: JobListFilter): Promise<Job[]>;
11
+ setStatus(id: string, status: JobStatus): Promise<Job>;
12
+ execute(id: string, caller?: ExecutionCaller): Promise<Job>;
13
+ review(id: string, outcome: JobOutcome, notes?: string): Promise<Job>;
14
+ private addEvent;
15
+ }
16
+ export declare const jobManager: JobManager;
17
+ export {};