@inf-minds/jobs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifact-cleanup.d.ts +30 -0
- package/dist/artifact-cleanup.d.ts.map +1 -0
- package/dist/artifact-cleanup.js +44 -0
- package/dist/artifact-cleanup.js.map +1 -0
- package/dist/artifact-manager.d.ts +41 -0
- package/dist/artifact-manager.d.ts.map +1 -0
- package/dist/artifact-manager.js +254 -0
- package/dist/artifact-manager.js.map +1 -0
- package/dist/artifact-materializer.d.ts +21 -0
- package/dist/artifact-materializer.d.ts.map +1 -0
- package/dist/artifact-materializer.js +33 -0
- package/dist/artifact-materializer.js.map +1 -0
- package/dist/artifact-router.d.ts +131 -0
- package/dist/artifact-router.d.ts.map +1 -0
- package/dist/artifact-router.js +4 -0
- package/dist/artifact-router.js.map +1 -0
- package/dist/default-artifact-router.d.ts +26 -0
- package/dist/default-artifact-router.d.ts.map +1 -0
- package/dist/default-artifact-router.js +125 -0
- package/dist/default-artifact-router.js.map +1 -0
- package/dist/event-appender.d.ts +23 -0
- package/dist/event-appender.d.ts.map +1 -0
- package/dist/event-appender.js +120 -0
- package/dist/event-appender.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/job-context.d.ts +58 -0
- package/dist/job-context.d.ts.map +1 -0
- package/dist/job-context.js +133 -0
- package/dist/job-context.js.map +1 -0
- package/dist/job-manager.d.ts +23 -0
- package/dist/job-manager.d.ts.map +1 -0
- package/dist/job-manager.js +145 -0
- package/dist/job-manager.js.map +1 -0
- package/dist/job-runner.d.ts +32 -0
- package/dist/job-runner.d.ts.map +1 -0
- package/dist/job-runner.js +187 -0
- package/dist/job-runner.js.map +1 -0
- package/dist/job-worker.d.ts +79 -0
- package/dist/job-worker.d.ts.map +1 -0
- package/dist/job-worker.js +134 -0
- package/dist/job-worker.js.map +1 -0
- package/dist/mind-worker.d.ts +63 -0
- package/dist/mind-worker.d.ts.map +1 -0
- package/dist/mind-worker.js +99 -0
- package/dist/mind-worker.js.map +1 -0
- package/dist/schema.d.ts +1143 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +225 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +434 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/drizzle/0001_create_jobs_tables.sql +70 -0
- package/drizzle/0002_coordinator_tables.sql +78 -0
- package/drizzle/0003_artifacts.sql +24 -0
- package/drizzle/0004_kernel.sql +28 -0
- package/drizzle/0005_artifact_routing.sql +29 -0
- package/package.json +48 -0
- package/src/artifact-cleanup.ts +85 -0
- package/src/artifact-manager.ts +346 -0
- package/src/artifact-materializer.ts +64 -0
- package/src/artifact-router.ts +151 -0
- package/src/default-artifact-router.ts +186 -0
- package/src/event-appender.ts +158 -0
- package/src/index.ts +136 -0
- package/src/job-context.ts +195 -0
- package/src/job-manager.ts +179 -0
- package/src/job-runner.ts +260 -0
- package/src/job-worker.ts +252 -0
- package/src/mind-worker.ts +152 -0
- package/src/schema.ts +290 -0
- package/src/types.ts +542 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;CAQb,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE3E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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O,mBAAmB,CAAC,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,YAAY,CAAC;AAC3C,MAAM,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,YAAY,CAAC;AAC9C,MAAM,MAAM,QAAQ,GAAG,OAAO,SAAS,CAAC,YAAY,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,OAAO,SAAS,CAAC,YAAY,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC,YAAY,CAAC;AACvD,MAAM,MAAM,YAAY,GAAG,OAAO,UAAU,CAAC,YAAY,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,OAAO,eAAe,CAAC,YAAY,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG,OAAO,eAAe,CAAC,YAAY,CAAC;AACnE,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,YAAY,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,OAAO,YAAY,CAAC,YAAY,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// ABOUTME: Drizzle ORM schema for jobs and job_events tables
|
|
2
|
+
// ABOUTME: Defines PostgreSQL tables for job management and event streaming
|
|
3
|
+
import { pgTable, uuid, text, timestamp, jsonb, real, bigserial, index, integer, boolean, unique, bigint, } from 'drizzle-orm/pg-core';
|
|
4
|
+
/**
|
|
5
|
+
* Job status enum values.
|
|
6
|
+
*/
|
|
7
|
+
export const JOB_STATUS = {
|
|
8
|
+
PENDING: 'pending',
|
|
9
|
+
QUEUED: 'queued',
|
|
10
|
+
BLOCKED: 'blocked',
|
|
11
|
+
RUNNING: 'running',
|
|
12
|
+
COMPLETED: 'completed',
|
|
13
|
+
FAILED: 'failed',
|
|
14
|
+
CANCELLED: 'cancelled',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Job priority levels.
|
|
18
|
+
* Lower number = higher priority.
|
|
19
|
+
*/
|
|
20
|
+
export const JOB_PRIORITY = {
|
|
21
|
+
URGENT: 0,
|
|
22
|
+
HIGH: 25,
|
|
23
|
+
NORMAL: 50,
|
|
24
|
+
LOW: 75,
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Jobs table - tracks background job execution.
|
|
28
|
+
*/
|
|
29
|
+
export const jobs = pgTable('jobs', {
|
|
30
|
+
/** Unique job identifier */
|
|
31
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
32
|
+
/** Job type (e.g., 'ai-organize', 'haiku-build') */
|
|
33
|
+
type: text('type').notNull(),
|
|
34
|
+
/** Current job status */
|
|
35
|
+
status: text('status').notNull().default(JOB_STATUS.PENDING),
|
|
36
|
+
/** Account this job belongs to */
|
|
37
|
+
accountId: uuid('account_id').notNull(),
|
|
38
|
+
/** Job-specific input data */
|
|
39
|
+
input: jsonb('input'),
|
|
40
|
+
/** Job result (on completion) */
|
|
41
|
+
output: jsonb('output'),
|
|
42
|
+
/** Error message (on failure) */
|
|
43
|
+
error: text('error'),
|
|
44
|
+
/** Progress from 0.0 to 1.0 */
|
|
45
|
+
progress: real('progress'),
|
|
46
|
+
/** ID of worker processing this job (legacy) */
|
|
47
|
+
workerId: text('worker_id'),
|
|
48
|
+
/** When job started processing */
|
|
49
|
+
startedAt: timestamp('started_at', { withTimezone: true }),
|
|
50
|
+
/** When job completed (success or failure) */
|
|
51
|
+
completedAt: timestamp('completed_at', { withTimezone: true }),
|
|
52
|
+
/** When job was created */
|
|
53
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
54
|
+
/** When job was last updated */
|
|
55
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
|
56
|
+
// Coordinator columns
|
|
57
|
+
/** Priority: 0=urgent, 25=high, 50=normal, 75=low */
|
|
58
|
+
priority: integer('priority').default(JOB_PRIORITY.NORMAL),
|
|
59
|
+
/** Lease expiration for running jobs */
|
|
60
|
+
leaseUntil: timestamp('lease_until', { withTimezone: true }),
|
|
61
|
+
/** Current attempt number (0-indexed) */
|
|
62
|
+
attempt: integer('attempt').default(0),
|
|
63
|
+
/** Maximum retry attempts */
|
|
64
|
+
maxAttempts: integer('max_attempts').default(5),
|
|
65
|
+
/** When job should next be considered for dispatch */
|
|
66
|
+
nextRunAt: timestamp('next_run_at', { withTimezone: true }).defaultNow(),
|
|
67
|
+
/** ID of assigned worker from coordinator */
|
|
68
|
+
assignedWorkerId: text('assigned_worker_id'),
|
|
69
|
+
/** Distributed tracing ID */
|
|
70
|
+
traceId: text('trace_id'),
|
|
71
|
+
// Kernel orchestration columns
|
|
72
|
+
/** Links child mind-execution jobs to their parent kernel-session job */
|
|
73
|
+
parentJobId: uuid('parent_job_id'),
|
|
74
|
+
/** Tracks which graph node this mind-execution job corresponds to */
|
|
75
|
+
nodeId: text('node_id'),
|
|
76
|
+
/** Stores execution graph state (active nodes, completed nodes, outputs) */
|
|
77
|
+
graphState: jsonb('graph_state'),
|
|
78
|
+
/** Root path for this sessions materialized artifact paths */
|
|
79
|
+
artifactBasePath: text('artifact_base_path'),
|
|
80
|
+
}, (table) => [
|
|
81
|
+
index('jobs_account_id_idx').on(table.accountId),
|
|
82
|
+
index('jobs_status_idx').on(table.status),
|
|
83
|
+
index('jobs_type_status_idx').on(table.type, table.status),
|
|
84
|
+
// Scheduler index
|
|
85
|
+
index('idx_jobs_scheduler').on(table.accountId, table.status, table.priority, table.nextRunAt),
|
|
86
|
+
// Lease recovery index
|
|
87
|
+
index('idx_jobs_lease').on(table.status, table.leaseUntil),
|
|
88
|
+
// Status lookup for dependency resolution
|
|
89
|
+
index('idx_jobs_status_lookup').on(table.id, table.status),
|
|
90
|
+
// Kernel orchestration indexes
|
|
91
|
+
index('idx_jobs_parent').on(table.parentJobId),
|
|
92
|
+
index('idx_jobs_kernel_session').on(table.id, table.accountId),
|
|
93
|
+
index('idx_jobs_mind_execution').on(table.parentJobId, table.nodeId),
|
|
94
|
+
]);
|
|
95
|
+
/**
|
|
96
|
+
* Job events table - append-only event log for each job.
|
|
97
|
+
*
|
|
98
|
+
* Uses BIGSERIAL for offset encoding (lexicographically sortable).
|
|
99
|
+
*/
|
|
100
|
+
export const jobEvents = pgTable('job_events', {
|
|
101
|
+
/** Sequential event ID (used for offset encoding) */
|
|
102
|
+
id: bigserial('id', { mode: 'bigint' }).primaryKey(),
|
|
103
|
+
/** Job this event belongs to */
|
|
104
|
+
jobId: uuid('job_id')
|
|
105
|
+
.notNull()
|
|
106
|
+
.references(() => jobs.id, { onDelete: 'cascade' }),
|
|
107
|
+
/** Event type (e.g., 'status', 'progress', 'log', 'result', 'error', 'complete') */
|
|
108
|
+
eventType: text('event_type').notNull(),
|
|
109
|
+
/** Event payload data */
|
|
110
|
+
payload: jsonb('payload').notNull(),
|
|
111
|
+
/** When event was created */
|
|
112
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
113
|
+
}, (table) => [
|
|
114
|
+
index('job_events_job_id_idx').on(table.jobId),
|
|
115
|
+
index('job_events_job_id_id_idx').on(table.jobId, table.id),
|
|
116
|
+
]);
|
|
117
|
+
/**
|
|
118
|
+
* Job workers table - tracks registered job workers.
|
|
119
|
+
*/
|
|
120
|
+
export const jobWorkers = pgTable('job_workers', {
|
|
121
|
+
/** Unique worker record identifier */
|
|
122
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
123
|
+
/** Worker identifier (e.g., 'ai-worker-1') */
|
|
124
|
+
workerId: text('worker_id').notNull().unique(),
|
|
125
|
+
/** Job types this worker handles (e.g., ['ai-organize', 'ai-summarize']) */
|
|
126
|
+
jobTypes: text('job_types').array().notNull(),
|
|
127
|
+
/** Callback URL or relay client ID */
|
|
128
|
+
callbackUrl: text('callback_url').notNull(),
|
|
129
|
+
/** Whether callbacks should be routed through relay */
|
|
130
|
+
callbackViaRelay: boolean('callback_via_relay').default(true),
|
|
131
|
+
/** Maximum concurrent jobs this worker can handle */
|
|
132
|
+
capacity: integer('capacity').default(10),
|
|
133
|
+
/** Current number of active jobs */
|
|
134
|
+
currentLoad: integer('current_load').default(0),
|
|
135
|
+
/** Last heartbeat timestamp */
|
|
136
|
+
lastHeartbeatAt: timestamp('last_heartbeat_at', { withTimezone: true }).defaultNow().notNull(),
|
|
137
|
+
/** When worker was first registered */
|
|
138
|
+
registeredAt: timestamp('registered_at', { withTimezone: true }).defaultNow().notNull(),
|
|
139
|
+
/** Additional worker metadata */
|
|
140
|
+
metadata: jsonb('metadata'),
|
|
141
|
+
}, (table) => [
|
|
142
|
+
index('idx_job_workers_heartbeat').on(table.lastHeartbeatAt),
|
|
143
|
+
]);
|
|
144
|
+
/**
|
|
145
|
+
* Job dependencies table - tracks job-to-job dependencies.
|
|
146
|
+
* Job A depends on Job B means A cannot run until B completes.
|
|
147
|
+
*/
|
|
148
|
+
export const jobDependencies = pgTable('job_dependencies', {
|
|
149
|
+
/** Unique dependency record identifier */
|
|
150
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
151
|
+
/** Job that has the dependency (waits for depends_on_job to complete) */
|
|
152
|
+
jobId: uuid('job_id')
|
|
153
|
+
.notNull()
|
|
154
|
+
.references(() => jobs.id, { onDelete: 'cascade' }),
|
|
155
|
+
/** Job that must complete first */
|
|
156
|
+
dependsOnJobId: uuid('depends_on_job_id')
|
|
157
|
+
.notNull()
|
|
158
|
+
.references(() => jobs.id, { onDelete: 'cascade' }),
|
|
159
|
+
/** When dependency was created */
|
|
160
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
161
|
+
}, (table) => [
|
|
162
|
+
index('idx_job_deps_job').on(table.jobId),
|
|
163
|
+
index('idx_job_deps_depends').on(table.dependsOnJobId),
|
|
164
|
+
unique('job_dependency_unique').on(table.jobId, table.dependsOnJobId),
|
|
165
|
+
]);
|
|
166
|
+
/**
|
|
167
|
+
* Artifact visibility scope values.
|
|
168
|
+
*/
|
|
169
|
+
export const ARTIFACT_VISIBILITY = {
|
|
170
|
+
/** Only visible to the creating job/mind */
|
|
171
|
+
PRIVATE: 'private',
|
|
172
|
+
/** Visible to all jobs/minds within the kernel session */
|
|
173
|
+
SESSION: 'session',
|
|
174
|
+
/** Persisted beyond session lifetime */
|
|
175
|
+
PERSISTENT: 'persistent',
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Job artifacts table - stores files produced by jobs.
|
|
179
|
+
* Text artifacts stored in JSONB content column.
|
|
180
|
+
* Binary artifacts reference external storage (R2).
|
|
181
|
+
*/
|
|
182
|
+
export const jobArtifacts = pgTable('job_artifacts', {
|
|
183
|
+
/** Unique artifact identifier */
|
|
184
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
185
|
+
/** Job that owns this artifact */
|
|
186
|
+
jobId: uuid('job_id')
|
|
187
|
+
.notNull()
|
|
188
|
+
.references(() => jobs.id, { onDelete: 'cascade' }),
|
|
189
|
+
/** Artifact name (path within job scope) */
|
|
190
|
+
name: text('name').notNull(),
|
|
191
|
+
/** MIME type */
|
|
192
|
+
mimeType: text('mime_type').notNull(),
|
|
193
|
+
/** Storage type: 'postgres' for text, 'external' for binaries */
|
|
194
|
+
storageType: text('storage_type').notNull(),
|
|
195
|
+
/** Content for postgres-stored artifacts */
|
|
196
|
+
content: jsonb('content'),
|
|
197
|
+
/** External storage key (R2 object key) */
|
|
198
|
+
externalKey: text('external_key'),
|
|
199
|
+
/** Size in bytes */
|
|
200
|
+
sizeBytes: bigint('size_bytes', { mode: 'number' }).notNull(),
|
|
201
|
+
/** Custom metadata */
|
|
202
|
+
metadata: jsonb('metadata').default({}),
|
|
203
|
+
/** When artifact expires (null = no expiration) */
|
|
204
|
+
expiresAt: timestamp('expires_at', { withTimezone: true }),
|
|
205
|
+
/** When artifact was created */
|
|
206
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
207
|
+
// Artifact routing columns (for kernel orchestration)
|
|
208
|
+
/** Visibility scope: private, session, or persistent */
|
|
209
|
+
visibility: text('visibility').default(ARTIFACT_VISIBILITY.SESSION),
|
|
210
|
+
/** Kernel session this artifact belongs to (NULL for non-kernel jobs) */
|
|
211
|
+
sessionId: uuid('session_id'),
|
|
212
|
+
/** Named channels this artifact is published to */
|
|
213
|
+
channels: text('channels').array(),
|
|
214
|
+
/** Graph node that created this artifact */
|
|
215
|
+
nodeId: text('node_id'),
|
|
216
|
+
}, (table) => [
|
|
217
|
+
index('idx_job_artifacts_job').on(table.jobId),
|
|
218
|
+
index('idx_job_artifacts_expires').on(table.expiresAt),
|
|
219
|
+
unique('job_artifact_unique').on(table.jobId, table.name),
|
|
220
|
+
// Artifact routing indexes
|
|
221
|
+
index('idx_artifacts_session').on(table.sessionId),
|
|
222
|
+
index('idx_artifacts_visibility').on(table.visibility),
|
|
223
|
+
index('idx_artifacts_node').on(table.sessionId, table.nodeId),
|
|
224
|
+
]);
|
|
225
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,4EAA4E;AAE5E,OAAO,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAK,EACL,OAAO,EACP,OAAO,EACP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
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import type { Job, JobStatus } from './schema.js';
|
|
2
|
+
import type { ArtifactManager } from './artifact-manager.js';
|
|
3
|
+
import type { ArtifactMaterializer } from './artifact-materializer.js';
|
|
4
|
+
/**
|
|
5
|
+
* Well-known job types for kernel orchestration.
|
|
6
|
+
*/
|
|
7
|
+
export declare const JOB_TYPE: {
|
|
8
|
+
/** Parent session that orchestrates mind execution graph */
|
|
9
|
+
readonly KERNEL_SESSION: "kernel-session";
|
|
10
|
+
/** Child job executing a single mind/node in the graph */
|
|
11
|
+
readonly MIND_EXECUTION: "mind-execution";
|
|
12
|
+
};
|
|
13
|
+
export type KernelJobType = (typeof JOB_TYPE)[keyof typeof JOB_TYPE];
|
|
14
|
+
/**
|
|
15
|
+
* State of a node in the execution graph.
|
|
16
|
+
*/
|
|
17
|
+
export interface GraphNodeState {
|
|
18
|
+
/** Node ID from the coordination mode definition */
|
|
19
|
+
nodeId: string;
|
|
20
|
+
/** Current execution status */
|
|
21
|
+
status: 'pending' | 'active' | 'completed' | 'failed' | 'skipped';
|
|
22
|
+
/** Job ID if execution has started */
|
|
23
|
+
jobId?: string;
|
|
24
|
+
/** Output data if completed */
|
|
25
|
+
output?: unknown;
|
|
26
|
+
/** Error message if failed */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** When the node started execution */
|
|
29
|
+
startedAt?: string;
|
|
30
|
+
/** When the node completed */
|
|
31
|
+
completedAt?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Execution state for a kernel session's graph.
|
|
35
|
+
* Stored in jobs.graph_state for kernel-session jobs.
|
|
36
|
+
*/
|
|
37
|
+
export interface GraphState {
|
|
38
|
+
/** All nodes and their current states */
|
|
39
|
+
nodes: Record<string, GraphNodeState>;
|
|
40
|
+
/** IDs of nodes currently executing */
|
|
41
|
+
activeNodes: string[];
|
|
42
|
+
/** IDs of nodes that have completed successfully */
|
|
43
|
+
completedNodes: string[];
|
|
44
|
+
/** IDs of nodes that failed */
|
|
45
|
+
failedNodes: string[];
|
|
46
|
+
/** IDs of nodes that were skipped (condition not met) */
|
|
47
|
+
skippedNodes: string[];
|
|
48
|
+
/** Session start time */
|
|
49
|
+
startedAt: string;
|
|
50
|
+
/** Session end time (when all nodes complete or fatal failure) */
|
|
51
|
+
completedAt?: string;
|
|
52
|
+
/** Overall session status */
|
|
53
|
+
status: 'running' | 'completed' | 'failed';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Options for creating a new job.
|
|
57
|
+
*/
|
|
58
|
+
export interface CreateJobOptions<TInput = unknown> {
|
|
59
|
+
/** Job type identifier */
|
|
60
|
+
type: string;
|
|
61
|
+
/** Account ID this job belongs to */
|
|
62
|
+
accountId: string;
|
|
63
|
+
/** Job-specific input data */
|
|
64
|
+
input?: TInput;
|
|
65
|
+
/** Parent job ID (for mind-execution jobs linked to a kernel-session) */
|
|
66
|
+
parentJobId?: string;
|
|
67
|
+
/** Graph node ID (for mind-execution jobs) */
|
|
68
|
+
nodeId?: string;
|
|
69
|
+
/** Initial graph state (for kernel-session jobs) */
|
|
70
|
+
graphState?: GraphState;
|
|
71
|
+
/** Base path for artifact materialization */
|
|
72
|
+
artifactBasePath?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Options for listing jobs.
|
|
76
|
+
*/
|
|
77
|
+
export interface ListJobsOptions {
|
|
78
|
+
/** Filter by account ID (required) */
|
|
79
|
+
accountId: string;
|
|
80
|
+
/** Filter by job type */
|
|
81
|
+
type?: string;
|
|
82
|
+
/** Filter by status */
|
|
83
|
+
status?: JobStatus;
|
|
84
|
+
/** Maximum number of jobs to return */
|
|
85
|
+
limit?: number;
|
|
86
|
+
/** Number of jobs to skip */
|
|
87
|
+
offset?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Result of listing jobs.
|
|
91
|
+
*/
|
|
92
|
+
export interface ListJobsResult {
|
|
93
|
+
/** Jobs matching the query */
|
|
94
|
+
jobs: Job[];
|
|
95
|
+
/** Total count (for pagination) */
|
|
96
|
+
total?: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Job manager interface for CRUD operations.
|
|
100
|
+
*/
|
|
101
|
+
export interface JobManager {
|
|
102
|
+
/**
|
|
103
|
+
* Create a new job.
|
|
104
|
+
*/
|
|
105
|
+
create<TInput = unknown>(options: CreateJobOptions<TInput>): Promise<Job>;
|
|
106
|
+
/**
|
|
107
|
+
* Get a job by ID.
|
|
108
|
+
*/
|
|
109
|
+
get(jobId: string): Promise<Job | null>;
|
|
110
|
+
/**
|
|
111
|
+
* List jobs with filtering and pagination.
|
|
112
|
+
*/
|
|
113
|
+
list(options: ListJobsOptions): Promise<ListJobsResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Cancel a job (only if pending or running).
|
|
116
|
+
*/
|
|
117
|
+
cancel(jobId: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Update job progress.
|
|
120
|
+
*/
|
|
121
|
+
updateProgress(jobId: string, progress: number): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Mark job as completed with output.
|
|
124
|
+
*/
|
|
125
|
+
complete<TOutput = unknown>(jobId: string, output?: TOutput): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Mark job as failed with error message.
|
|
128
|
+
*/
|
|
129
|
+
fail(jobId: string, error: string): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Database client interface (subset of Drizzle).
|
|
133
|
+
*/
|
|
134
|
+
export interface DbClient {
|
|
135
|
+
insert: (table: unknown) => {
|
|
136
|
+
values: (values: unknown) => {
|
|
137
|
+
returning: () => Promise<unknown[]>;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
select: (fields?: unknown) => {
|
|
141
|
+
from: (table: unknown) => {
|
|
142
|
+
where: (condition: unknown) => DbQueryChain;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
update: (table: unknown) => {
|
|
146
|
+
set: (values: unknown) => {
|
|
147
|
+
where: (condition: unknown) => Promise<unknown[]>;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Chainable query result type.
|
|
153
|
+
*/
|
|
154
|
+
export interface DbQueryChain extends Promise<unknown[]> {
|
|
155
|
+
orderBy: (order: unknown) => {
|
|
156
|
+
limit: (n: number) => Promise<unknown[]> & {
|
|
157
|
+
offset: (n: number) => Promise<unknown[]>;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Options for appending an event.
|
|
163
|
+
*/
|
|
164
|
+
export interface AppendEventOptions<TPayload = unknown> {
|
|
165
|
+
/** Job ID this event belongs to */
|
|
166
|
+
jobId: string;
|
|
167
|
+
/** Event type (e.g., 'progress', 'log', 'error') */
|
|
168
|
+
type: string;
|
|
169
|
+
/** Event payload data */
|
|
170
|
+
payload: TPayload;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Result of appending an event.
|
|
174
|
+
*/
|
|
175
|
+
export interface AppendEventResult {
|
|
176
|
+
/** Encoded offset of the appended event */
|
|
177
|
+
offset: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Options for getting events.
|
|
181
|
+
*/
|
|
182
|
+
export interface GetEventsOptions {
|
|
183
|
+
/** Job ID to get events for */
|
|
184
|
+
jobId: string;
|
|
185
|
+
/** Starting offset (default: '-1' for beginning) */
|
|
186
|
+
offset?: string;
|
|
187
|
+
/** Maximum number of events to return (default: 100) */
|
|
188
|
+
limit?: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Result of getting events.
|
|
192
|
+
*/
|
|
193
|
+
export interface GetEventsResult<TPayload = unknown> {
|
|
194
|
+
/** Events matching the query */
|
|
195
|
+
events: Array<{
|
|
196
|
+
id: string;
|
|
197
|
+
type: string;
|
|
198
|
+
payload: TPayload;
|
|
199
|
+
createdAt: Date;
|
|
200
|
+
}>;
|
|
201
|
+
/** Next offset to use for pagination */
|
|
202
|
+
nextOffset: string;
|
|
203
|
+
/** True when caught up to current tail */
|
|
204
|
+
upToDate: boolean;
|
|
205
|
+
/** True when stream is permanently closed */
|
|
206
|
+
closed: boolean;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* EventAppender interface for event streaming.
|
|
210
|
+
*/
|
|
211
|
+
export interface EventAppender {
|
|
212
|
+
/**
|
|
213
|
+
* Append an event to a job's event stream.
|
|
214
|
+
*/
|
|
215
|
+
append<TPayload = unknown>(options: AppendEventOptions<TPayload>): Promise<AppendEventResult>;
|
|
216
|
+
/**
|
|
217
|
+
* Get events from a job's event stream.
|
|
218
|
+
*/
|
|
219
|
+
getEvents<TPayload = unknown>(options: GetEventsOptions): Promise<GetEventsResult<TPayload>>;
|
|
220
|
+
/**
|
|
221
|
+
* Check if a job's stream is closed (job completed/failed/cancelled).
|
|
222
|
+
*/
|
|
223
|
+
isStreamClosed(jobId: string): Promise<boolean>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Options for saving an artifact.
|
|
227
|
+
*/
|
|
228
|
+
export interface SaveArtifactOptions {
|
|
229
|
+
/** MIME type (auto-detected from name if not provided) */
|
|
230
|
+
mimeType?: string;
|
|
231
|
+
/** Custom metadata */
|
|
232
|
+
metadata?: Record<string, unknown>;
|
|
233
|
+
/** Expiry in seconds from now (overrides job default) */
|
|
234
|
+
expiresIn?: number;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Reference to a stored artifact.
|
|
238
|
+
*/
|
|
239
|
+
export interface ArtifactRef {
|
|
240
|
+
/** Artifact name (path within job) */
|
|
241
|
+
name: string;
|
|
242
|
+
/** MIME type */
|
|
243
|
+
mimeType: string;
|
|
244
|
+
/** Size in bytes */
|
|
245
|
+
sizeBytes: number;
|
|
246
|
+
/** Storage location */
|
|
247
|
+
storageType: 'postgres' | 'external';
|
|
248
|
+
/** Custom metadata */
|
|
249
|
+
metadata: Record<string, unknown>;
|
|
250
|
+
/** Creation timestamp */
|
|
251
|
+
createdAt: Date;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Artifact with content.
|
|
255
|
+
*/
|
|
256
|
+
export interface ArtifactContent extends ArtifactRef {
|
|
257
|
+
/** Artifact content */
|
|
258
|
+
content: string | Buffer;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Default TTL values for artifact retention.
|
|
262
|
+
*/
|
|
263
|
+
export declare const ARTIFACT_TTL: {
|
|
264
|
+
/** Completed jobs: 365 days */
|
|
265
|
+
readonly COMPLETED: number;
|
|
266
|
+
/** Failed jobs: 28 days */
|
|
267
|
+
readonly FAILED: number;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Context provided to job handlers for emitting events and controlling execution.
|
|
271
|
+
*/
|
|
272
|
+
export interface JobContext<TInput = unknown> {
|
|
273
|
+
/** The job being processed */
|
|
274
|
+
readonly job: Job;
|
|
275
|
+
/** Typed input data */
|
|
276
|
+
readonly input: TInput;
|
|
277
|
+
/** Abort signal for cancellation */
|
|
278
|
+
readonly signal: AbortSignal;
|
|
279
|
+
/**
|
|
280
|
+
* Emit a custom event to the job's stream.
|
|
281
|
+
*/
|
|
282
|
+
emit<TPayload = unknown>(type: string, payload: TPayload): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Update job progress (0.0 - 1.0) with optional message.
|
|
285
|
+
*/
|
|
286
|
+
progress(value: number, message?: string): Promise<void>;
|
|
287
|
+
/**
|
|
288
|
+
* Log a message to the job's stream.
|
|
289
|
+
*/
|
|
290
|
+
log(message: string, level?: 'info' | 'warn' | 'error'): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Save an artifact.
|
|
293
|
+
*/
|
|
294
|
+
saveArtifact(name: string, content: string | Buffer, options?: SaveArtifactOptions): Promise<ArtifactRef>;
|
|
295
|
+
/**
|
|
296
|
+
* Load an artifact from this job.
|
|
297
|
+
*/
|
|
298
|
+
loadArtifact(name: string): Promise<ArtifactContent | null>;
|
|
299
|
+
/**
|
|
300
|
+
* Load an artifact from a dependency job.
|
|
301
|
+
*/
|
|
302
|
+
loadDependencyArtifact(path: string): Promise<ArtifactContent | null>;
|
|
303
|
+
/**
|
|
304
|
+
* List all artifacts for this job.
|
|
305
|
+
*/
|
|
306
|
+
listArtifacts(): Promise<ArtifactRef[]>;
|
|
307
|
+
/**
|
|
308
|
+
* Get signed URL for external artifact.
|
|
309
|
+
*/
|
|
310
|
+
getArtifactUrl(name: string, expiresIn?: number): Promise<string | null>;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Handler function that processes a job.
|
|
314
|
+
*/
|
|
315
|
+
export type JobHandler<TInput = unknown, TOutput = unknown> = (ctx: JobContext<TInput>) => Promise<TOutput>;
|
|
316
|
+
/**
|
|
317
|
+
* Options for creating a JobRunner.
|
|
318
|
+
*/
|
|
319
|
+
export interface JobRunnerOptions {
|
|
320
|
+
/** JobManager instance for job lifecycle */
|
|
321
|
+
jobManager: JobManager;
|
|
322
|
+
/** EventAppender instance for event streaming */
|
|
323
|
+
eventAppender: EventAppender;
|
|
324
|
+
/** Optional: Relay callback URL for real-time push */
|
|
325
|
+
relayCallbackUrl?: string;
|
|
326
|
+
/** Optional: Fetch function for relay callbacks (for CF Worker compatibility) */
|
|
327
|
+
fetch?: typeof globalThis.fetch;
|
|
328
|
+
/** ArtifactManager for artifact operations (optional) */
|
|
329
|
+
artifactManager?: ArtifactManager;
|
|
330
|
+
/** ArtifactMaterializer for dependency artifacts (optional) */
|
|
331
|
+
artifactMaterializer?: ArtifactMaterializer;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Options for running a job.
|
|
335
|
+
*/
|
|
336
|
+
export interface RunJobOptions<TInput = unknown> {
|
|
337
|
+
/** Job type identifier */
|
|
338
|
+
type: string;
|
|
339
|
+
/** Account ID */
|
|
340
|
+
accountId: string;
|
|
341
|
+
/** Job input data */
|
|
342
|
+
input: TInput;
|
|
343
|
+
/** Optional: existing job ID to resume */
|
|
344
|
+
jobId?: string;
|
|
345
|
+
/** Optional: abort signal from request */
|
|
346
|
+
signal?: AbortSignal;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Result of running a job.
|
|
350
|
+
*/
|
|
351
|
+
export interface RunJobResult<TOutput = unknown> {
|
|
352
|
+
/** The job record */
|
|
353
|
+
job: Job;
|
|
354
|
+
/** Job output (if completed successfully) */
|
|
355
|
+
output?: TOutput;
|
|
356
|
+
/** Error message (if failed) */
|
|
357
|
+
error?: string;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* JobRunner for direct execution of jobs.
|
|
361
|
+
*/
|
|
362
|
+
export interface JobRunner {
|
|
363
|
+
/**
|
|
364
|
+
* Run a job with the given handler.
|
|
365
|
+
* Creates the job, executes the handler, and marks complete/failed.
|
|
366
|
+
*/
|
|
367
|
+
run<TInput = unknown, TOutput = unknown>(options: RunJobOptions<TInput>, handler: JobHandler<TInput, TOutput>): Promise<RunJobResult<TOutput>>;
|
|
368
|
+
/**
|
|
369
|
+
* Resume a job that was previously started.
|
|
370
|
+
* Useful for Durable Object alarm-based execution.
|
|
371
|
+
*/
|
|
372
|
+
resume<TInput = unknown, TOutput = unknown>(jobId: string, handler: JobHandler<TInput, TOutput>, signal?: AbortSignal): Promise<RunJobResult<TOutput>>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Extended context for mind-execution jobs with parent session awareness.
|
|
376
|
+
*/
|
|
377
|
+
export interface MindJobContext<TInput = unknown> extends JobContext<TInput> {
|
|
378
|
+
/** Parent kernel session job ID */
|
|
379
|
+
readonly parentJobId: string;
|
|
380
|
+
/** This mind's node ID in the graph */
|
|
381
|
+
readonly nodeId: string;
|
|
382
|
+
/**
|
|
383
|
+
* Load an artifact from a sibling node in the same session.
|
|
384
|
+
* @param nodeId - Node ID of the sibling
|
|
385
|
+
* @param name - Artifact name
|
|
386
|
+
*/
|
|
387
|
+
loadSiblingArtifact(nodeId: string, name: string): Promise<ArtifactContent | null>;
|
|
388
|
+
/**
|
|
389
|
+
* Load all artifacts from a sibling node.
|
|
390
|
+
* @param nodeId - Node ID of the sibling
|
|
391
|
+
*/
|
|
392
|
+
listSiblingArtifacts(nodeId: string): Promise<ArtifactRef[]>;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Options for creating a mind-execution child job.
|
|
396
|
+
*/
|
|
397
|
+
export interface CreateMindJobOptions<TInput = unknown> {
|
|
398
|
+
/** Node ID in the graph */
|
|
399
|
+
nodeId: string;
|
|
400
|
+
/** Mind-specific input data */
|
|
401
|
+
input: TInput;
|
|
402
|
+
/** Optional priority override */
|
|
403
|
+
priority?: number;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Context for kernel-session jobs to manage graph execution.
|
|
407
|
+
*/
|
|
408
|
+
export interface KernelSessionContext<TInput = unknown> extends JobContext<TInput> {
|
|
409
|
+
/** Current graph execution state */
|
|
410
|
+
readonly graphState: GraphState;
|
|
411
|
+
/** Base path for artifact materialization */
|
|
412
|
+
readonly artifactBasePath: string;
|
|
413
|
+
/**
|
|
414
|
+
* Create a child mind-execution job for a graph node.
|
|
415
|
+
*/
|
|
416
|
+
createMindJob<TNodeInput = unknown>(options: CreateMindJobOptions<TNodeInput>): Promise<Job>;
|
|
417
|
+
/**
|
|
418
|
+
* Update the graph state (active nodes, completed nodes, etc.).
|
|
419
|
+
*/
|
|
420
|
+
updateGraphState(update: Partial<GraphState>): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Mark a node as completed with output.
|
|
423
|
+
*/
|
|
424
|
+
completeNode(nodeId: string, output?: unknown): Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* Mark a node as failed with error.
|
|
427
|
+
*/
|
|
428
|
+
failNode(nodeId: string, error: string): Promise<void>;
|
|
429
|
+
/**
|
|
430
|
+
* Mark a node as skipped (condition not met).
|
|
431
|
+
*/
|
|
432
|
+
skipNode(nodeId: string, reason?: string): Promise<void>;
|
|
433
|
+
}
|
|
434
|
+
//# sourceMappingURL=types.d.ts.map
|