digital-tasks 2.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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +10 -0
- package/dist/function-task.d.ts +319 -0
- package/dist/function-task.d.ts.map +1 -0
- package/dist/function-task.js +286 -0
- package/dist/function-task.js.map +1 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.d.ts +112 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +510 -0
- package/dist/markdown.js.map +1 -0
- package/dist/project.d.ts +259 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +397 -0
- package/dist/project.js.map +1 -0
- package/dist/queue.d.ts +17 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +347 -0
- package/dist/queue.js.map +1 -0
- package/dist/task.d.ts +69 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +321 -0
- package/dist/task.js.map +1 -0
- package/dist/types.d.ts +292 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +161 -0
- package/src/markdown.ts +622 -0
- package/src/project.ts +571 -0
- package/src/queue.ts +424 -0
- package/src/task.ts +389 -0
- package/src/types.ts +403 -0
- package/test/markdown.test.ts +550 -0
- package/test/project.test.ts +562 -0
- package/test/queue.test.ts +482 -0
- package/test/task.test.ts +464 -0
- package/tsconfig.json +20 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for digital-tasks
|
|
3
|
+
*
|
|
4
|
+
* Task = Function + metadata (status, progress, assignment, dependencies)
|
|
5
|
+
*
|
|
6
|
+
* Every task is a function call. The function can be:
|
|
7
|
+
* - Code: generates executable code
|
|
8
|
+
* - Generative: AI generates content (no tools)
|
|
9
|
+
* - Agentic: AI with tools in a loop
|
|
10
|
+
* - Human: requires human input
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
FunctionDefinition,
|
|
17
|
+
CodeFunctionDefinition,
|
|
18
|
+
GenerativeFunctionDefinition,
|
|
19
|
+
AgenticFunctionDefinition,
|
|
20
|
+
HumanFunctionDefinition,
|
|
21
|
+
} from 'ai-functions'
|
|
22
|
+
|
|
23
|
+
// Re-export function types for convenience
|
|
24
|
+
export type {
|
|
25
|
+
FunctionDefinition,
|
|
26
|
+
CodeFunctionDefinition,
|
|
27
|
+
GenerativeFunctionDefinition,
|
|
28
|
+
AgenticFunctionDefinition,
|
|
29
|
+
HumanFunctionDefinition,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Task Status and Priority
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Task lifecycle status
|
|
38
|
+
*/
|
|
39
|
+
export type TaskStatus =
|
|
40
|
+
| 'pending' // Created but not started
|
|
41
|
+
| 'queued' // In queue waiting for worker
|
|
42
|
+
| 'assigned' // Assigned to a worker
|
|
43
|
+
| 'in_progress' // Being worked on
|
|
44
|
+
| 'blocked' // Waiting on dependency
|
|
45
|
+
| 'review' // Awaiting review
|
|
46
|
+
| 'completed' // Successfully finished
|
|
47
|
+
| 'failed' // Failed with error
|
|
48
|
+
| 'cancelled' // Cancelled
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Task priority levels
|
|
52
|
+
*/
|
|
53
|
+
export type TaskPriority = 'low' | 'normal' | 'high' | 'urgent' | 'critical'
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Worker Assignment
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Who can work on this task
|
|
61
|
+
*/
|
|
62
|
+
export type WorkerType = 'agent' | 'human' | 'team' | 'any'
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Worker reference
|
|
66
|
+
*/
|
|
67
|
+
export interface WorkerRef {
|
|
68
|
+
type: WorkerType
|
|
69
|
+
id: string
|
|
70
|
+
name?: string
|
|
71
|
+
role?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Task assignment
|
|
76
|
+
*/
|
|
77
|
+
export interface TaskAssignment {
|
|
78
|
+
worker: WorkerRef
|
|
79
|
+
assignedAt: Date
|
|
80
|
+
assignedBy?: string
|
|
81
|
+
notes?: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Dependencies
|
|
86
|
+
// ============================================================================
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Dependency type
|
|
90
|
+
*/
|
|
91
|
+
export type DependencyType =
|
|
92
|
+
| 'blocks' // This task blocks another
|
|
93
|
+
| 'blocked_by' // This task is blocked by another
|
|
94
|
+
| 'related_to' // Related but not blocking
|
|
95
|
+
| 'parent' // Parent task
|
|
96
|
+
| 'child' // Child subtask
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Task dependency
|
|
100
|
+
*/
|
|
101
|
+
export interface TaskDependency {
|
|
102
|
+
type: DependencyType
|
|
103
|
+
taskId: string
|
|
104
|
+
satisfied?: boolean
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// Progress and Events
|
|
109
|
+
// ============================================================================
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Task progress
|
|
113
|
+
*/
|
|
114
|
+
export interface TaskProgress {
|
|
115
|
+
percent: number
|
|
116
|
+
step?: string
|
|
117
|
+
totalSteps?: number
|
|
118
|
+
currentStep?: number
|
|
119
|
+
estimatedTimeRemaining?: number
|
|
120
|
+
updatedAt: Date
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Task event for history
|
|
125
|
+
*/
|
|
126
|
+
export interface TaskEvent {
|
|
127
|
+
id: string
|
|
128
|
+
type: 'created' | 'assigned' | 'started' | 'progress' | 'blocked' | 'unblocked' | 'completed' | 'failed' | 'cancelled' | 'comment'
|
|
129
|
+
timestamp: Date
|
|
130
|
+
actor?: WorkerRef
|
|
131
|
+
data?: unknown
|
|
132
|
+
message?: string
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Core Task Interface
|
|
137
|
+
// ============================================================================
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Task = Function + metadata
|
|
141
|
+
*
|
|
142
|
+
* A task wraps a function (code, generative, agentic, or human)
|
|
143
|
+
* with lifecycle management, assignment, and dependencies.
|
|
144
|
+
*/
|
|
145
|
+
export interface Task<TInput = unknown, TOutput = unknown> {
|
|
146
|
+
/** Unique task ID */
|
|
147
|
+
id: string
|
|
148
|
+
|
|
149
|
+
/** The function this task executes */
|
|
150
|
+
function: FunctionDefinition<TInput, TOutput>
|
|
151
|
+
|
|
152
|
+
/** Current status */
|
|
153
|
+
status: TaskStatus
|
|
154
|
+
|
|
155
|
+
/** Priority level */
|
|
156
|
+
priority: TaskPriority
|
|
157
|
+
|
|
158
|
+
// Input/Output
|
|
159
|
+
/** Input value (resolved from function.args) */
|
|
160
|
+
input?: TInput
|
|
161
|
+
|
|
162
|
+
/** Output value (when completed) */
|
|
163
|
+
output?: TOutput
|
|
164
|
+
|
|
165
|
+
/** Error (when failed) */
|
|
166
|
+
error?: string
|
|
167
|
+
|
|
168
|
+
// Assignment
|
|
169
|
+
/** Who can work on this */
|
|
170
|
+
allowedWorkers?: WorkerType[]
|
|
171
|
+
|
|
172
|
+
/** Current assignment */
|
|
173
|
+
assignment?: TaskAssignment
|
|
174
|
+
|
|
175
|
+
// Dependencies
|
|
176
|
+
/** Task dependencies */
|
|
177
|
+
dependencies?: TaskDependency[]
|
|
178
|
+
|
|
179
|
+
// Progress
|
|
180
|
+
/** Current progress */
|
|
181
|
+
progress?: TaskProgress
|
|
182
|
+
|
|
183
|
+
// Timing
|
|
184
|
+
/** When created */
|
|
185
|
+
createdAt: Date
|
|
186
|
+
|
|
187
|
+
/** Scheduled start time */
|
|
188
|
+
scheduledFor?: Date
|
|
189
|
+
|
|
190
|
+
/** Deadline */
|
|
191
|
+
deadline?: Date
|
|
192
|
+
|
|
193
|
+
/** When started */
|
|
194
|
+
startedAt?: Date
|
|
195
|
+
|
|
196
|
+
/** When completed */
|
|
197
|
+
completedAt?: Date
|
|
198
|
+
|
|
199
|
+
/** Timeout in ms */
|
|
200
|
+
timeout?: number
|
|
201
|
+
|
|
202
|
+
// Hierarchy
|
|
203
|
+
/** Parent task ID */
|
|
204
|
+
parentId?: string
|
|
205
|
+
|
|
206
|
+
/** Project ID */
|
|
207
|
+
projectId?: string
|
|
208
|
+
|
|
209
|
+
// Metadata
|
|
210
|
+
/** Tags */
|
|
211
|
+
tags?: string[]
|
|
212
|
+
|
|
213
|
+
/** Custom metadata */
|
|
214
|
+
metadata?: Record<string, unknown>
|
|
215
|
+
|
|
216
|
+
/** Event history */
|
|
217
|
+
events?: TaskEvent[]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Any task (for collections)
|
|
222
|
+
*/
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
|
+
export type AnyTask = Task<any, any>
|
|
225
|
+
|
|
226
|
+
// ============================================================================
|
|
227
|
+
// Task Creation
|
|
228
|
+
// ============================================================================
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Create task from a Code function
|
|
232
|
+
*/
|
|
233
|
+
export interface CodeTaskOptions<TInput = unknown, TOutput = unknown> {
|
|
234
|
+
function: CodeFunctionDefinition<TInput, TOutput>
|
|
235
|
+
input?: TInput
|
|
236
|
+
priority?: TaskPriority
|
|
237
|
+
assignTo?: WorkerRef
|
|
238
|
+
dependencies?: string[]
|
|
239
|
+
deadline?: Date
|
|
240
|
+
tags?: string[]
|
|
241
|
+
parentId?: string
|
|
242
|
+
projectId?: string
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Create task from a Generative function
|
|
247
|
+
*/
|
|
248
|
+
export interface GenerativeTaskOptions<TInput = unknown, TOutput = unknown> {
|
|
249
|
+
function: GenerativeFunctionDefinition<TInput, TOutput>
|
|
250
|
+
input?: TInput
|
|
251
|
+
priority?: TaskPriority
|
|
252
|
+
assignTo?: WorkerRef
|
|
253
|
+
dependencies?: string[]
|
|
254
|
+
deadline?: Date
|
|
255
|
+
tags?: string[]
|
|
256
|
+
parentId?: string
|
|
257
|
+
projectId?: string
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Create task from an Agentic function
|
|
262
|
+
*/
|
|
263
|
+
export interface AgenticTaskOptions<TInput = unknown, TOutput = unknown> {
|
|
264
|
+
function: AgenticFunctionDefinition<TInput, TOutput>
|
|
265
|
+
input?: TInput
|
|
266
|
+
priority?: TaskPriority
|
|
267
|
+
assignTo?: WorkerRef
|
|
268
|
+
dependencies?: string[]
|
|
269
|
+
deadline?: Date
|
|
270
|
+
tags?: string[]
|
|
271
|
+
parentId?: string
|
|
272
|
+
projectId?: string
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Create task from a Human function
|
|
277
|
+
*/
|
|
278
|
+
export interface HumanTaskOptions<TInput = unknown, TOutput = unknown> {
|
|
279
|
+
function: HumanFunctionDefinition<TInput, TOutput>
|
|
280
|
+
input?: TInput
|
|
281
|
+
priority?: TaskPriority
|
|
282
|
+
assignTo?: WorkerRef
|
|
283
|
+
dependencies?: string[]
|
|
284
|
+
deadline?: Date
|
|
285
|
+
tags?: string[]
|
|
286
|
+
parentId?: string
|
|
287
|
+
projectId?: string
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Generic task creation options
|
|
292
|
+
*/
|
|
293
|
+
export interface CreateTaskOptions<TInput = unknown, TOutput = unknown> {
|
|
294
|
+
function: FunctionDefinition<TInput, TOutput>
|
|
295
|
+
input?: TInput
|
|
296
|
+
priority?: TaskPriority
|
|
297
|
+
allowedWorkers?: WorkerType[]
|
|
298
|
+
assignTo?: WorkerRef
|
|
299
|
+
dependencies?: string[]
|
|
300
|
+
scheduledFor?: Date
|
|
301
|
+
deadline?: Date
|
|
302
|
+
timeout?: number
|
|
303
|
+
tags?: string[]
|
|
304
|
+
parentId?: string
|
|
305
|
+
projectId?: string
|
|
306
|
+
metadata?: Record<string, unknown>
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Task update options
|
|
311
|
+
*/
|
|
312
|
+
export interface UpdateTaskOptions {
|
|
313
|
+
status?: TaskStatus
|
|
314
|
+
progress?: Partial<TaskProgress>
|
|
315
|
+
assignment?: TaskAssignment
|
|
316
|
+
priority?: TaskPriority
|
|
317
|
+
event?: Omit<TaskEvent, 'id' | 'timestamp'>
|
|
318
|
+
metadata?: Record<string, unknown>
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ============================================================================
|
|
322
|
+
// Task Queue
|
|
323
|
+
// ============================================================================
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Task query options
|
|
327
|
+
*/
|
|
328
|
+
export interface TaskQuery {
|
|
329
|
+
status?: TaskStatus | TaskStatus[]
|
|
330
|
+
priority?: TaskPriority | TaskPriority[]
|
|
331
|
+
functionType?: 'code' | 'generative' | 'agentic' | 'human'
|
|
332
|
+
assignedTo?: string
|
|
333
|
+
tags?: string[]
|
|
334
|
+
projectId?: string
|
|
335
|
+
parentId?: string
|
|
336
|
+
search?: string
|
|
337
|
+
sortBy?: 'createdAt' | 'priority' | 'deadline' | 'status'
|
|
338
|
+
sortOrder?: 'asc' | 'desc'
|
|
339
|
+
limit?: number
|
|
340
|
+
offset?: number
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Task queue options
|
|
345
|
+
*/
|
|
346
|
+
export interface TaskQueueOptions {
|
|
347
|
+
name?: string
|
|
348
|
+
concurrency?: number
|
|
349
|
+
defaultTimeout?: number
|
|
350
|
+
persistent?: boolean
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Task queue interface
|
|
355
|
+
*/
|
|
356
|
+
export interface TaskQueue {
|
|
357
|
+
add(task: AnyTask): Promise<void>
|
|
358
|
+
get(id: string): Promise<AnyTask | undefined>
|
|
359
|
+
update(id: string, options: UpdateTaskOptions): Promise<AnyTask | undefined>
|
|
360
|
+
remove(id: string): Promise<boolean>
|
|
361
|
+
query(options: TaskQuery): Promise<AnyTask[]>
|
|
362
|
+
getNextForWorker(worker: WorkerRef): Promise<AnyTask | undefined>
|
|
363
|
+
claim(taskId: string, worker: WorkerRef): Promise<boolean>
|
|
364
|
+
complete(taskId: string, output: unknown): Promise<void>
|
|
365
|
+
fail(taskId: string, error: string): Promise<void>
|
|
366
|
+
stats(): Promise<TaskQueueStats>
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Task queue stats
|
|
371
|
+
*/
|
|
372
|
+
export interface TaskQueueStats {
|
|
373
|
+
total: number
|
|
374
|
+
byStatus: Record<TaskStatus, number>
|
|
375
|
+
byPriority: Record<TaskPriority, number>
|
|
376
|
+
byFunctionType?: Record<string, number>
|
|
377
|
+
avgWaitTime?: number
|
|
378
|
+
avgCompletionTime?: number
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ============================================================================
|
|
382
|
+
// Task Result
|
|
383
|
+
// ============================================================================
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Task execution result
|
|
387
|
+
*/
|
|
388
|
+
export interface TaskResult<TOutput = unknown> {
|
|
389
|
+
taskId: string
|
|
390
|
+
success: boolean
|
|
391
|
+
output?: TOutput
|
|
392
|
+
error?: {
|
|
393
|
+
code: string
|
|
394
|
+
message: string
|
|
395
|
+
details?: unknown
|
|
396
|
+
}
|
|
397
|
+
metadata?: {
|
|
398
|
+
duration: number
|
|
399
|
+
startedAt: Date
|
|
400
|
+
completedAt: Date
|
|
401
|
+
worker?: WorkerRef
|
|
402
|
+
}
|
|
403
|
+
}
|