services-as-software 0.1.0 → 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/README.md +235 -225
- package/dist/client.d.ts +25 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +103 -0
- package/dist/client.js.map +1 -0
- package/dist/endpoint.d.ts +102 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/endpoint.js +96 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/entities/billing.d.ts +60 -0
- package/dist/entities/billing.d.ts.map +1 -0
- package/dist/entities/billing.js +954 -0
- package/dist/entities/billing.js.map +1 -0
- package/dist/entities/customers.d.ts +45 -0
- package/dist/entities/customers.d.ts.map +1 -0
- package/dist/entities/customers.js +679 -0
- package/dist/entities/customers.js.map +1 -0
- package/dist/entities/delivery.d.ts +59 -0
- package/dist/entities/delivery.d.ts.map +1 -0
- package/dist/entities/delivery.js +890 -0
- package/dist/entities/delivery.js.map +1 -0
- package/dist/entities/index.d.ts +114 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +89 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/operations.d.ts +59 -0
- package/dist/entities/operations.d.ts.map +1 -0
- package/dist/entities/operations.js +1010 -0
- package/dist/entities/operations.js.map +1 -0
- package/dist/entities/orchestration.d.ts +52 -0
- package/dist/entities/orchestration.d.ts.map +1 -0
- package/dist/entities/orchestration.js +883 -0
- package/dist/entities/orchestration.js.map +1 -0
- package/dist/entities/services.d.ts +50 -0
- package/dist/entities/services.d.ts.map +1 -0
- package/dist/entities/services.js +805 -0
- package/dist/entities/services.js.map +1 -0
- package/dist/helpers.d.ts +362 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +400 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +17 -215
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -172
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +85 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +158 -0
- package/dist/provider.js.map +1 -0
- package/dist/service.d.ts +43 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +206 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +469 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/examples/client-usage.ts +82 -0
- package/examples/translation-service.ts +227 -0
- package/package.json +24 -38
- package/src/client.ts +132 -0
- package/src/endpoint.ts +144 -0
- package/src/entities/billing.ts +1037 -0
- package/src/entities/customers.ts +740 -0
- package/src/entities/delivery.ts +974 -0
- package/src/entities/index.ts +157 -0
- package/src/entities/operations.ts +1099 -0
- package/src/entities/orchestration.ts +956 -0
- package/src/entities/services.ts +872 -0
- package/src/helpers.ts +474 -0
- package/src/index.ts +97 -0
- package/src/provider.ts +183 -0
- package/src/service.test.ts +195 -0
- package/src/service.ts +266 -0
- package/src/types.ts +543 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,956 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orchestration Entity Types (Nouns)
|
|
3
|
+
*
|
|
4
|
+
* Service orchestration: ServiceWorkflow, WorkflowStep, ServiceTask, ServiceQueue, ServiceWorker
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Noun } from 'ai-database'
|
|
10
|
+
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// ServiceWorkflow
|
|
13
|
+
// =============================================================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ServiceWorkflow entity
|
|
17
|
+
*
|
|
18
|
+
* Multi-step service workflow.
|
|
19
|
+
*/
|
|
20
|
+
export const ServiceWorkflow: Noun = {
|
|
21
|
+
singular: 'service-workflow',
|
|
22
|
+
plural: 'service-workflows',
|
|
23
|
+
description: 'A multi-step workflow for service delivery',
|
|
24
|
+
|
|
25
|
+
properties: {
|
|
26
|
+
// Identity
|
|
27
|
+
name: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Workflow name',
|
|
30
|
+
},
|
|
31
|
+
slug: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
optional: true,
|
|
34
|
+
description: 'URL-friendly identifier',
|
|
35
|
+
},
|
|
36
|
+
description: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
optional: true,
|
|
39
|
+
description: 'Workflow description',
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// Type
|
|
43
|
+
type: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
description: 'Workflow type',
|
|
46
|
+
examples: ['sequential', 'parallel', 'conditional', 'loop', 'dag'],
|
|
47
|
+
},
|
|
48
|
+
trigger: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
optional: true,
|
|
51
|
+
description: 'What triggers workflow',
|
|
52
|
+
examples: ['api', 'schedule', 'event', 'manual', 'condition'],
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
// Configuration
|
|
56
|
+
config: {
|
|
57
|
+
type: 'json',
|
|
58
|
+
optional: true,
|
|
59
|
+
description: 'Workflow configuration',
|
|
60
|
+
},
|
|
61
|
+
inputSchema: {
|
|
62
|
+
type: 'json',
|
|
63
|
+
optional: true,
|
|
64
|
+
description: 'Input schema',
|
|
65
|
+
},
|
|
66
|
+
outputSchema: {
|
|
67
|
+
type: 'json',
|
|
68
|
+
optional: true,
|
|
69
|
+
description: 'Output schema',
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// Execution
|
|
73
|
+
timeout: {
|
|
74
|
+
type: 'number',
|
|
75
|
+
optional: true,
|
|
76
|
+
description: 'Workflow timeout (ms)',
|
|
77
|
+
},
|
|
78
|
+
maxRetries: {
|
|
79
|
+
type: 'number',
|
|
80
|
+
optional: true,
|
|
81
|
+
description: 'Max retry attempts',
|
|
82
|
+
},
|
|
83
|
+
retryBackoff: {
|
|
84
|
+
type: 'string',
|
|
85
|
+
optional: true,
|
|
86
|
+
description: 'Retry backoff strategy',
|
|
87
|
+
examples: ['fixed', 'exponential', 'linear'],
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// Concurrency
|
|
91
|
+
maxConcurrent: {
|
|
92
|
+
type: 'number',
|
|
93
|
+
optional: true,
|
|
94
|
+
description: 'Max concurrent executions',
|
|
95
|
+
},
|
|
96
|
+
queueBehavior: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
optional: true,
|
|
99
|
+
description: 'Queue behavior when at limit',
|
|
100
|
+
examples: ['queue', 'reject', 'replace'],
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// Versioning
|
|
104
|
+
version: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
optional: true,
|
|
107
|
+
description: 'Workflow version',
|
|
108
|
+
},
|
|
109
|
+
isLatest: {
|
|
110
|
+
type: 'boolean',
|
|
111
|
+
optional: true,
|
|
112
|
+
description: 'Is latest version',
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
// Metrics
|
|
116
|
+
avgDurationMs: {
|
|
117
|
+
type: 'number',
|
|
118
|
+
optional: true,
|
|
119
|
+
description: 'Average duration',
|
|
120
|
+
},
|
|
121
|
+
successRate: {
|
|
122
|
+
type: 'number',
|
|
123
|
+
optional: true,
|
|
124
|
+
description: 'Success rate (0-1)',
|
|
125
|
+
},
|
|
126
|
+
totalExecutions: {
|
|
127
|
+
type: 'number',
|
|
128
|
+
optional: true,
|
|
129
|
+
description: 'Total executions',
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// Status
|
|
133
|
+
status: {
|
|
134
|
+
type: 'string',
|
|
135
|
+
description: 'Workflow status',
|
|
136
|
+
examples: ['draft', 'active', 'paused', 'deprecated', 'archived'],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
relationships: {
|
|
141
|
+
service: {
|
|
142
|
+
type: 'ProductizedService',
|
|
143
|
+
description: 'Parent service',
|
|
144
|
+
},
|
|
145
|
+
steps: {
|
|
146
|
+
type: 'WorkflowStep[]',
|
|
147
|
+
description: 'Workflow steps',
|
|
148
|
+
},
|
|
149
|
+
executions: {
|
|
150
|
+
type: 'ServiceExecution[]',
|
|
151
|
+
description: 'Workflow executions',
|
|
152
|
+
},
|
|
153
|
+
qualityGates: {
|
|
154
|
+
type: 'QualityGate[]',
|
|
155
|
+
description: 'Quality gates',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
actions: [
|
|
160
|
+
'create',
|
|
161
|
+
'update',
|
|
162
|
+
'publish',
|
|
163
|
+
'execute',
|
|
164
|
+
'pause',
|
|
165
|
+
'resume',
|
|
166
|
+
'deprecate',
|
|
167
|
+
'archive',
|
|
168
|
+
],
|
|
169
|
+
|
|
170
|
+
events: [
|
|
171
|
+
'created',
|
|
172
|
+
'updated',
|
|
173
|
+
'published',
|
|
174
|
+
'executed',
|
|
175
|
+
'paused',
|
|
176
|
+
'resumed',
|
|
177
|
+
'deprecated',
|
|
178
|
+
'archived',
|
|
179
|
+
],
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// =============================================================================
|
|
183
|
+
// WorkflowStep
|
|
184
|
+
// =============================================================================
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* WorkflowStep entity
|
|
188
|
+
*
|
|
189
|
+
* Individual step in a workflow.
|
|
190
|
+
*/
|
|
191
|
+
export const WorkflowStep: Noun = {
|
|
192
|
+
singular: 'workflow-step',
|
|
193
|
+
plural: 'workflow-steps',
|
|
194
|
+
description: 'An individual step in a service workflow',
|
|
195
|
+
|
|
196
|
+
properties: {
|
|
197
|
+
// Identity
|
|
198
|
+
name: {
|
|
199
|
+
type: 'string',
|
|
200
|
+
description: 'Step name',
|
|
201
|
+
},
|
|
202
|
+
description: {
|
|
203
|
+
type: 'string',
|
|
204
|
+
optional: true,
|
|
205
|
+
description: 'Step description',
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
// Position
|
|
209
|
+
order: {
|
|
210
|
+
type: 'number',
|
|
211
|
+
description: 'Step order',
|
|
212
|
+
},
|
|
213
|
+
phase: {
|
|
214
|
+
type: 'string',
|
|
215
|
+
optional: true,
|
|
216
|
+
description: 'Workflow phase',
|
|
217
|
+
examples: ['setup', 'process', 'validate', 'deliver', 'cleanup'],
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
// Type
|
|
221
|
+
type: {
|
|
222
|
+
type: 'string',
|
|
223
|
+
description: 'Step type',
|
|
224
|
+
examples: ['action', 'decision', 'wait', 'parallel', 'loop', 'human', 'ai'],
|
|
225
|
+
},
|
|
226
|
+
actionType: {
|
|
227
|
+
type: 'string',
|
|
228
|
+
optional: true,
|
|
229
|
+
description: 'Type of action',
|
|
230
|
+
examples: ['function', 'api-call', 'ai-inference', 'human-task', 'notification', 'delay'],
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
// Configuration
|
|
234
|
+
config: {
|
|
235
|
+
type: 'json',
|
|
236
|
+
optional: true,
|
|
237
|
+
description: 'Step configuration',
|
|
238
|
+
},
|
|
239
|
+
inputMapping: {
|
|
240
|
+
type: 'json',
|
|
241
|
+
optional: true,
|
|
242
|
+
description: 'Input mapping from workflow',
|
|
243
|
+
},
|
|
244
|
+
outputMapping: {
|
|
245
|
+
type: 'json',
|
|
246
|
+
optional: true,
|
|
247
|
+
description: 'Output mapping to workflow',
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
// AI Configuration
|
|
251
|
+
aiEnabled: {
|
|
252
|
+
type: 'boolean',
|
|
253
|
+
optional: true,
|
|
254
|
+
description: 'Uses AI for execution',
|
|
255
|
+
},
|
|
256
|
+
aiModel: {
|
|
257
|
+
type: 'string',
|
|
258
|
+
optional: true,
|
|
259
|
+
description: 'AI model to use',
|
|
260
|
+
},
|
|
261
|
+
aiPrompt: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
optional: true,
|
|
264
|
+
description: 'AI prompt template',
|
|
265
|
+
},
|
|
266
|
+
confidenceRequired: {
|
|
267
|
+
type: 'number',
|
|
268
|
+
optional: true,
|
|
269
|
+
description: 'Min confidence for auto-proceed',
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
// Execution
|
|
273
|
+
timeout: {
|
|
274
|
+
type: 'number',
|
|
275
|
+
optional: true,
|
|
276
|
+
description: 'Step timeout (ms)',
|
|
277
|
+
},
|
|
278
|
+
retryable: {
|
|
279
|
+
type: 'boolean',
|
|
280
|
+
optional: true,
|
|
281
|
+
description: 'Step can be retried',
|
|
282
|
+
},
|
|
283
|
+
maxRetries: {
|
|
284
|
+
type: 'number',
|
|
285
|
+
optional: true,
|
|
286
|
+
description: 'Max retry attempts',
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
// Conditions
|
|
290
|
+
condition: {
|
|
291
|
+
type: 'string',
|
|
292
|
+
optional: true,
|
|
293
|
+
description: 'Execution condition',
|
|
294
|
+
},
|
|
295
|
+
skipCondition: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
optional: true,
|
|
298
|
+
description: 'Skip condition',
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
// Error Handling
|
|
302
|
+
onError: {
|
|
303
|
+
type: 'string',
|
|
304
|
+
optional: true,
|
|
305
|
+
description: 'Error handling',
|
|
306
|
+
examples: ['fail', 'retry', 'skip', 'fallback', 'escalate'],
|
|
307
|
+
},
|
|
308
|
+
fallbackStep: {
|
|
309
|
+
type: 'string',
|
|
310
|
+
optional: true,
|
|
311
|
+
description: 'Fallback step name',
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
// Human Tasks
|
|
315
|
+
requiresHuman: {
|
|
316
|
+
type: 'boolean',
|
|
317
|
+
optional: true,
|
|
318
|
+
description: 'Requires human',
|
|
319
|
+
},
|
|
320
|
+
humanTaskType: {
|
|
321
|
+
type: 'string',
|
|
322
|
+
optional: true,
|
|
323
|
+
description: 'Human task type',
|
|
324
|
+
examples: ['approval', 'review', 'input', 'decision'],
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
// Status
|
|
328
|
+
status: {
|
|
329
|
+
type: 'string',
|
|
330
|
+
description: 'Step status',
|
|
331
|
+
examples: ['active', 'disabled', 'deprecated'],
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
relationships: {
|
|
336
|
+
workflow: {
|
|
337
|
+
type: 'ServiceWorkflow',
|
|
338
|
+
description: 'Parent workflow',
|
|
339
|
+
},
|
|
340
|
+
nextSteps: {
|
|
341
|
+
type: 'WorkflowStep[]',
|
|
342
|
+
description: 'Next steps',
|
|
343
|
+
},
|
|
344
|
+
previousSteps: {
|
|
345
|
+
type: 'WorkflowStep[]',
|
|
346
|
+
description: 'Previous steps',
|
|
347
|
+
},
|
|
348
|
+
qualityGate: {
|
|
349
|
+
type: 'QualityGate',
|
|
350
|
+
required: false,
|
|
351
|
+
description: 'Quality gate at this step',
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
actions: [
|
|
356
|
+
'create',
|
|
357
|
+
'update',
|
|
358
|
+
'enable',
|
|
359
|
+
'disable',
|
|
360
|
+
'execute',
|
|
361
|
+
'skip',
|
|
362
|
+
'retry',
|
|
363
|
+
],
|
|
364
|
+
|
|
365
|
+
events: [
|
|
366
|
+
'created',
|
|
367
|
+
'updated',
|
|
368
|
+
'enabled',
|
|
369
|
+
'disabled',
|
|
370
|
+
'started',
|
|
371
|
+
'completed',
|
|
372
|
+
'failed',
|
|
373
|
+
'skipped',
|
|
374
|
+
'retried',
|
|
375
|
+
],
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// =============================================================================
|
|
379
|
+
// ServiceTask
|
|
380
|
+
// =============================================================================
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* ServiceTask entity
|
|
384
|
+
*
|
|
385
|
+
* Task within service execution.
|
|
386
|
+
*/
|
|
387
|
+
export const ServiceTask: Noun = {
|
|
388
|
+
singular: 'service-task',
|
|
389
|
+
plural: 'service-tasks',
|
|
390
|
+
description: 'A task within a service execution',
|
|
391
|
+
|
|
392
|
+
properties: {
|
|
393
|
+
// Identity
|
|
394
|
+
id: {
|
|
395
|
+
type: 'string',
|
|
396
|
+
description: 'Task ID',
|
|
397
|
+
},
|
|
398
|
+
name: {
|
|
399
|
+
type: 'string',
|
|
400
|
+
optional: true,
|
|
401
|
+
description: 'Task name',
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
// Type
|
|
405
|
+
type: {
|
|
406
|
+
type: 'string',
|
|
407
|
+
description: 'Task type',
|
|
408
|
+
examples: ['automated', 'ai', 'human', 'approval', 'review', 'external'],
|
|
409
|
+
},
|
|
410
|
+
priority: {
|
|
411
|
+
type: 'string',
|
|
412
|
+
optional: true,
|
|
413
|
+
description: 'Task priority',
|
|
414
|
+
examples: ['low', 'normal', 'high', 'urgent'],
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
// Input/Output
|
|
418
|
+
input: {
|
|
419
|
+
type: 'json',
|
|
420
|
+
optional: true,
|
|
421
|
+
description: 'Task input',
|
|
422
|
+
},
|
|
423
|
+
output: {
|
|
424
|
+
type: 'json',
|
|
425
|
+
optional: true,
|
|
426
|
+
description: 'Task output',
|
|
427
|
+
},
|
|
428
|
+
context: {
|
|
429
|
+
type: 'json',
|
|
430
|
+
optional: true,
|
|
431
|
+
description: 'Task context',
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
// Assignment
|
|
435
|
+
assignedTo: {
|
|
436
|
+
type: 'string',
|
|
437
|
+
optional: true,
|
|
438
|
+
description: 'Assigned worker/agent',
|
|
439
|
+
},
|
|
440
|
+
assignedAt: {
|
|
441
|
+
type: 'date',
|
|
442
|
+
optional: true,
|
|
443
|
+
description: 'Assignment time',
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
// AI Execution
|
|
447
|
+
aiExecuted: {
|
|
448
|
+
type: 'boolean',
|
|
449
|
+
optional: true,
|
|
450
|
+
description: 'Executed by AI',
|
|
451
|
+
},
|
|
452
|
+
aiConfidence: {
|
|
453
|
+
type: 'number',
|
|
454
|
+
optional: true,
|
|
455
|
+
description: 'AI confidence',
|
|
456
|
+
},
|
|
457
|
+
aiIterations: {
|
|
458
|
+
type: 'number',
|
|
459
|
+
optional: true,
|
|
460
|
+
description: 'AI iterations used',
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
// Human Execution
|
|
464
|
+
humanRequired: {
|
|
465
|
+
type: 'boolean',
|
|
466
|
+
optional: true,
|
|
467
|
+
description: 'Human required',
|
|
468
|
+
},
|
|
469
|
+
humanExecuted: {
|
|
470
|
+
type: 'boolean',
|
|
471
|
+
optional: true,
|
|
472
|
+
description: 'Executed by human',
|
|
473
|
+
},
|
|
474
|
+
humanNotes: {
|
|
475
|
+
type: 'string',
|
|
476
|
+
optional: true,
|
|
477
|
+
description: 'Human notes',
|
|
478
|
+
},
|
|
479
|
+
|
|
480
|
+
// Timing
|
|
481
|
+
scheduledAt: {
|
|
482
|
+
type: 'date',
|
|
483
|
+
optional: true,
|
|
484
|
+
description: 'Scheduled time',
|
|
485
|
+
},
|
|
486
|
+
startedAt: {
|
|
487
|
+
type: 'date',
|
|
488
|
+
optional: true,
|
|
489
|
+
description: 'Start time',
|
|
490
|
+
},
|
|
491
|
+
completedAt: {
|
|
492
|
+
type: 'date',
|
|
493
|
+
optional: true,
|
|
494
|
+
description: 'Completion time',
|
|
495
|
+
},
|
|
496
|
+
dueAt: {
|
|
497
|
+
type: 'date',
|
|
498
|
+
optional: true,
|
|
499
|
+
description: 'Due date',
|
|
500
|
+
},
|
|
501
|
+
durationMs: {
|
|
502
|
+
type: 'number',
|
|
503
|
+
optional: true,
|
|
504
|
+
description: 'Duration (ms)',
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
// Retries
|
|
508
|
+
attempt: {
|
|
509
|
+
type: 'number',
|
|
510
|
+
optional: true,
|
|
511
|
+
description: 'Current attempt number',
|
|
512
|
+
},
|
|
513
|
+
maxAttempts: {
|
|
514
|
+
type: 'number',
|
|
515
|
+
optional: true,
|
|
516
|
+
description: 'Max attempts allowed',
|
|
517
|
+
},
|
|
518
|
+
lastError: {
|
|
519
|
+
type: 'string',
|
|
520
|
+
optional: true,
|
|
521
|
+
description: 'Last error message',
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
// Status
|
|
525
|
+
status: {
|
|
526
|
+
type: 'string',
|
|
527
|
+
description: 'Task status',
|
|
528
|
+
examples: ['pending', 'queued', 'assigned', 'running', 'waiting', 'completed', 'failed', 'cancelled'],
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
relationships: {
|
|
533
|
+
execution: {
|
|
534
|
+
type: 'ServiceExecution',
|
|
535
|
+
description: 'Parent execution',
|
|
536
|
+
},
|
|
537
|
+
workflowStep: {
|
|
538
|
+
type: 'WorkflowStep',
|
|
539
|
+
required: false,
|
|
540
|
+
description: 'Workflow step',
|
|
541
|
+
},
|
|
542
|
+
queue: {
|
|
543
|
+
type: 'ServiceQueue',
|
|
544
|
+
required: false,
|
|
545
|
+
description: 'Task queue',
|
|
546
|
+
},
|
|
547
|
+
worker: {
|
|
548
|
+
type: 'ServiceWorker',
|
|
549
|
+
required: false,
|
|
550
|
+
description: 'Assigned worker',
|
|
551
|
+
},
|
|
552
|
+
parentTask: {
|
|
553
|
+
type: 'ServiceTask',
|
|
554
|
+
required: false,
|
|
555
|
+
description: 'Parent task',
|
|
556
|
+
},
|
|
557
|
+
subtasks: {
|
|
558
|
+
type: 'ServiceTask[]',
|
|
559
|
+
description: 'Subtasks',
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
actions: [
|
|
564
|
+
'create',
|
|
565
|
+
'queue',
|
|
566
|
+
'assign',
|
|
567
|
+
'start',
|
|
568
|
+
'complete',
|
|
569
|
+
'fail',
|
|
570
|
+
'retry',
|
|
571
|
+
'cancel',
|
|
572
|
+
'escalate',
|
|
573
|
+
],
|
|
574
|
+
|
|
575
|
+
events: [
|
|
576
|
+
'created',
|
|
577
|
+
'queued',
|
|
578
|
+
'assigned',
|
|
579
|
+
'started',
|
|
580
|
+
'completed',
|
|
581
|
+
'failed',
|
|
582
|
+
'retried',
|
|
583
|
+
'cancelled',
|
|
584
|
+
'escalated',
|
|
585
|
+
],
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// =============================================================================
|
|
589
|
+
// ServiceQueue
|
|
590
|
+
// =============================================================================
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* ServiceQueue entity
|
|
594
|
+
*
|
|
595
|
+
* Queue for service tasks.
|
|
596
|
+
*/
|
|
597
|
+
export const ServiceQueue: Noun = {
|
|
598
|
+
singular: 'service-queue',
|
|
599
|
+
plural: 'service-queues',
|
|
600
|
+
description: 'A queue for service tasks',
|
|
601
|
+
|
|
602
|
+
properties: {
|
|
603
|
+
// Identity
|
|
604
|
+
name: {
|
|
605
|
+
type: 'string',
|
|
606
|
+
description: 'Queue name',
|
|
607
|
+
},
|
|
608
|
+
description: {
|
|
609
|
+
type: 'string',
|
|
610
|
+
optional: true,
|
|
611
|
+
description: 'Queue description',
|
|
612
|
+
},
|
|
613
|
+
|
|
614
|
+
// Type
|
|
615
|
+
type: {
|
|
616
|
+
type: 'string',
|
|
617
|
+
description: 'Queue type',
|
|
618
|
+
examples: ['fifo', 'lifo', 'priority', 'fair', 'round-robin'],
|
|
619
|
+
},
|
|
620
|
+
taskTypes: {
|
|
621
|
+
type: 'string',
|
|
622
|
+
array: true,
|
|
623
|
+
optional: true,
|
|
624
|
+
description: 'Allowed task types',
|
|
625
|
+
},
|
|
626
|
+
|
|
627
|
+
// Configuration
|
|
628
|
+
maxSize: {
|
|
629
|
+
type: 'number',
|
|
630
|
+
optional: true,
|
|
631
|
+
description: 'Max queue size',
|
|
632
|
+
},
|
|
633
|
+
maxConcurrent: {
|
|
634
|
+
type: 'number',
|
|
635
|
+
optional: true,
|
|
636
|
+
description: 'Max concurrent processing',
|
|
637
|
+
},
|
|
638
|
+
processingTimeout: {
|
|
639
|
+
type: 'number',
|
|
640
|
+
optional: true,
|
|
641
|
+
description: 'Processing timeout (ms)',
|
|
642
|
+
},
|
|
643
|
+
|
|
644
|
+
// Behavior
|
|
645
|
+
onFull: {
|
|
646
|
+
type: 'string',
|
|
647
|
+
optional: true,
|
|
648
|
+
description: 'Behavior when full',
|
|
649
|
+
examples: ['reject', 'drop-oldest', 'wait'],
|
|
650
|
+
},
|
|
651
|
+
retryFailed: {
|
|
652
|
+
type: 'boolean',
|
|
653
|
+
optional: true,
|
|
654
|
+
description: 'Retry failed tasks',
|
|
655
|
+
},
|
|
656
|
+
deadLetterQueue: {
|
|
657
|
+
type: 'string',
|
|
658
|
+
optional: true,
|
|
659
|
+
description: 'Dead letter queue name',
|
|
660
|
+
},
|
|
661
|
+
|
|
662
|
+
// Workers
|
|
663
|
+
minWorkers: {
|
|
664
|
+
type: 'number',
|
|
665
|
+
optional: true,
|
|
666
|
+
description: 'Minimum workers',
|
|
667
|
+
},
|
|
668
|
+
maxWorkers: {
|
|
669
|
+
type: 'number',
|
|
670
|
+
optional: true,
|
|
671
|
+
description: 'Maximum workers',
|
|
672
|
+
},
|
|
673
|
+
autoScale: {
|
|
674
|
+
type: 'boolean',
|
|
675
|
+
optional: true,
|
|
676
|
+
description: 'Auto-scale workers',
|
|
677
|
+
},
|
|
678
|
+
|
|
679
|
+
// Current State
|
|
680
|
+
pendingCount: {
|
|
681
|
+
type: 'number',
|
|
682
|
+
optional: true,
|
|
683
|
+
description: 'Pending task count',
|
|
684
|
+
},
|
|
685
|
+
processingCount: {
|
|
686
|
+
type: 'number',
|
|
687
|
+
optional: true,
|
|
688
|
+
description: 'Processing task count',
|
|
689
|
+
},
|
|
690
|
+
completedCount: {
|
|
691
|
+
type: 'number',
|
|
692
|
+
optional: true,
|
|
693
|
+
description: 'Completed task count',
|
|
694
|
+
},
|
|
695
|
+
failedCount: {
|
|
696
|
+
type: 'number',
|
|
697
|
+
optional: true,
|
|
698
|
+
description: 'Failed task count',
|
|
699
|
+
},
|
|
700
|
+
|
|
701
|
+
// Metrics
|
|
702
|
+
avgWaitTime: {
|
|
703
|
+
type: 'number',
|
|
704
|
+
optional: true,
|
|
705
|
+
description: 'Average wait time (ms)',
|
|
706
|
+
},
|
|
707
|
+
avgProcessingTime: {
|
|
708
|
+
type: 'number',
|
|
709
|
+
optional: true,
|
|
710
|
+
description: 'Average processing time (ms)',
|
|
711
|
+
},
|
|
712
|
+
throughput: {
|
|
713
|
+
type: 'number',
|
|
714
|
+
optional: true,
|
|
715
|
+
description: 'Tasks per minute',
|
|
716
|
+
},
|
|
717
|
+
|
|
718
|
+
// Status
|
|
719
|
+
status: {
|
|
720
|
+
type: 'string',
|
|
721
|
+
description: 'Queue status',
|
|
722
|
+
examples: ['active', 'paused', 'draining', 'stopped'],
|
|
723
|
+
},
|
|
724
|
+
},
|
|
725
|
+
|
|
726
|
+
relationships: {
|
|
727
|
+
service: {
|
|
728
|
+
type: 'ProductizedService',
|
|
729
|
+
description: 'Parent service',
|
|
730
|
+
},
|
|
731
|
+
tasks: {
|
|
732
|
+
type: 'ServiceTask[]',
|
|
733
|
+
description: 'Queued tasks',
|
|
734
|
+
},
|
|
735
|
+
workers: {
|
|
736
|
+
type: 'ServiceWorker[]',
|
|
737
|
+
description: 'Queue workers',
|
|
738
|
+
},
|
|
739
|
+
},
|
|
740
|
+
|
|
741
|
+
actions: [
|
|
742
|
+
'create',
|
|
743
|
+
'update',
|
|
744
|
+
'pause',
|
|
745
|
+
'resume',
|
|
746
|
+
'drain',
|
|
747
|
+
'clear',
|
|
748
|
+
'scale',
|
|
749
|
+
],
|
|
750
|
+
|
|
751
|
+
events: [
|
|
752
|
+
'created',
|
|
753
|
+
'updated',
|
|
754
|
+
'paused',
|
|
755
|
+
'resumed',
|
|
756
|
+
'draining',
|
|
757
|
+
'drained',
|
|
758
|
+
'cleared',
|
|
759
|
+
'scaled',
|
|
760
|
+
],
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// =============================================================================
|
|
764
|
+
// ServiceWorker
|
|
765
|
+
// =============================================================================
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* ServiceWorker entity
|
|
769
|
+
*
|
|
770
|
+
* Worker processing tasks.
|
|
771
|
+
*/
|
|
772
|
+
export const ServiceWorker: Noun = {
|
|
773
|
+
singular: 'service-worker',
|
|
774
|
+
plural: 'service-workers',
|
|
775
|
+
description: 'A worker processing service tasks',
|
|
776
|
+
|
|
777
|
+
properties: {
|
|
778
|
+
// Identity
|
|
779
|
+
id: {
|
|
780
|
+
type: 'string',
|
|
781
|
+
description: 'Worker ID',
|
|
782
|
+
},
|
|
783
|
+
name: {
|
|
784
|
+
type: 'string',
|
|
785
|
+
optional: true,
|
|
786
|
+
description: 'Worker name',
|
|
787
|
+
},
|
|
788
|
+
|
|
789
|
+
// Type
|
|
790
|
+
type: {
|
|
791
|
+
type: 'string',
|
|
792
|
+
description: 'Worker type',
|
|
793
|
+
examples: ['ai', 'human', 'automated', 'hybrid'],
|
|
794
|
+
},
|
|
795
|
+
|
|
796
|
+
// Capabilities
|
|
797
|
+
capabilities: {
|
|
798
|
+
type: 'string',
|
|
799
|
+
array: true,
|
|
800
|
+
optional: true,
|
|
801
|
+
description: 'Worker capabilities',
|
|
802
|
+
},
|
|
803
|
+
taskTypes: {
|
|
804
|
+
type: 'string',
|
|
805
|
+
array: true,
|
|
806
|
+
optional: true,
|
|
807
|
+
description: 'Task types handled',
|
|
808
|
+
},
|
|
809
|
+
|
|
810
|
+
// Configuration
|
|
811
|
+
concurrency: {
|
|
812
|
+
type: 'number',
|
|
813
|
+
optional: true,
|
|
814
|
+
description: 'Max concurrent tasks',
|
|
815
|
+
},
|
|
816
|
+
pollInterval: {
|
|
817
|
+
type: 'number',
|
|
818
|
+
optional: true,
|
|
819
|
+
description: 'Poll interval (ms)',
|
|
820
|
+
},
|
|
821
|
+
|
|
822
|
+
// AI Configuration
|
|
823
|
+
aiModel: {
|
|
824
|
+
type: 'string',
|
|
825
|
+
optional: true,
|
|
826
|
+
description: 'AI model used',
|
|
827
|
+
},
|
|
828
|
+
aiConfig: {
|
|
829
|
+
type: 'json',
|
|
830
|
+
optional: true,
|
|
831
|
+
description: 'AI configuration',
|
|
832
|
+
},
|
|
833
|
+
|
|
834
|
+
// Current State
|
|
835
|
+
currentTask: {
|
|
836
|
+
type: 'string',
|
|
837
|
+
optional: true,
|
|
838
|
+
description: 'Current task ID',
|
|
839
|
+
},
|
|
840
|
+
tasksInProgress: {
|
|
841
|
+
type: 'number',
|
|
842
|
+
optional: true,
|
|
843
|
+
description: 'Tasks in progress',
|
|
844
|
+
},
|
|
845
|
+
lastActiveAt: {
|
|
846
|
+
type: 'date',
|
|
847
|
+
optional: true,
|
|
848
|
+
description: 'Last activity time',
|
|
849
|
+
},
|
|
850
|
+
heartbeatAt: {
|
|
851
|
+
type: 'date',
|
|
852
|
+
optional: true,
|
|
853
|
+
description: 'Last heartbeat',
|
|
854
|
+
},
|
|
855
|
+
|
|
856
|
+
// Metrics
|
|
857
|
+
tasksCompleted: {
|
|
858
|
+
type: 'number',
|
|
859
|
+
optional: true,
|
|
860
|
+
description: 'Tasks completed',
|
|
861
|
+
},
|
|
862
|
+
tasksFailed: {
|
|
863
|
+
type: 'number',
|
|
864
|
+
optional: true,
|
|
865
|
+
description: 'Tasks failed',
|
|
866
|
+
},
|
|
867
|
+
avgProcessingTime: {
|
|
868
|
+
type: 'number',
|
|
869
|
+
optional: true,
|
|
870
|
+
description: 'Avg processing time (ms)',
|
|
871
|
+
},
|
|
872
|
+
successRate: {
|
|
873
|
+
type: 'number',
|
|
874
|
+
optional: true,
|
|
875
|
+
description: 'Success rate (0-1)',
|
|
876
|
+
},
|
|
877
|
+
|
|
878
|
+
// Resource
|
|
879
|
+
memoryUsage: {
|
|
880
|
+
type: 'number',
|
|
881
|
+
optional: true,
|
|
882
|
+
description: 'Memory usage (MB)',
|
|
883
|
+
},
|
|
884
|
+
cpuUsage: {
|
|
885
|
+
type: 'number',
|
|
886
|
+
optional: true,
|
|
887
|
+
description: 'CPU usage (%)',
|
|
888
|
+
},
|
|
889
|
+
|
|
890
|
+
// Status
|
|
891
|
+
status: {
|
|
892
|
+
type: 'string',
|
|
893
|
+
description: 'Worker status',
|
|
894
|
+
examples: ['idle', 'busy', 'paused', 'draining', 'offline', 'error'],
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
|
|
898
|
+
relationships: {
|
|
899
|
+
queue: {
|
|
900
|
+
type: 'ServiceQueue',
|
|
901
|
+
description: 'Assigned queue',
|
|
902
|
+
},
|
|
903
|
+
currentTasks: {
|
|
904
|
+
type: 'ServiceTask[]',
|
|
905
|
+
description: 'Current tasks',
|
|
906
|
+
},
|
|
907
|
+
agent: {
|
|
908
|
+
type: 'AgentDelivery',
|
|
909
|
+
required: false,
|
|
910
|
+
description: 'AI agent (if AI worker)',
|
|
911
|
+
},
|
|
912
|
+
},
|
|
913
|
+
|
|
914
|
+
actions: [
|
|
915
|
+
'start',
|
|
916
|
+
'stop',
|
|
917
|
+
'pause',
|
|
918
|
+
'resume',
|
|
919
|
+
'drain',
|
|
920
|
+
'assignTask',
|
|
921
|
+
'completeTask',
|
|
922
|
+
'failTask',
|
|
923
|
+
],
|
|
924
|
+
|
|
925
|
+
events: [
|
|
926
|
+
'started',
|
|
927
|
+
'stopped',
|
|
928
|
+
'paused',
|
|
929
|
+
'resumed',
|
|
930
|
+
'draining',
|
|
931
|
+
'drained',
|
|
932
|
+
'taskAssigned',
|
|
933
|
+
'taskCompleted',
|
|
934
|
+
'taskFailed',
|
|
935
|
+
'error',
|
|
936
|
+
],
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// =============================================================================
|
|
940
|
+
// Exports
|
|
941
|
+
// =============================================================================
|
|
942
|
+
|
|
943
|
+
export const OrchestrationEntities = {
|
|
944
|
+
ServiceWorkflow,
|
|
945
|
+
WorkflowStep,
|
|
946
|
+
ServiceTask,
|
|
947
|
+
ServiceQueue,
|
|
948
|
+
ServiceWorker,
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
export const OrchestrationCategories = {
|
|
952
|
+
workflows: ['ServiceWorkflow', 'WorkflowStep'],
|
|
953
|
+
tasks: ['ServiceTask'],
|
|
954
|
+
queues: ['ServiceQueue'],
|
|
955
|
+
workers: ['ServiceWorker'],
|
|
956
|
+
} as const
|