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.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +235 -225
  4. package/dist/client.d.ts +25 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +103 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/endpoint.d.ts +102 -0
  9. package/dist/endpoint.d.ts.map +1 -0
  10. package/dist/endpoint.js +96 -0
  11. package/dist/endpoint.js.map +1 -0
  12. package/dist/entities/billing.d.ts +60 -0
  13. package/dist/entities/billing.d.ts.map +1 -0
  14. package/dist/entities/billing.js +954 -0
  15. package/dist/entities/billing.js.map +1 -0
  16. package/dist/entities/customers.d.ts +45 -0
  17. package/dist/entities/customers.d.ts.map +1 -0
  18. package/dist/entities/customers.js +679 -0
  19. package/dist/entities/customers.js.map +1 -0
  20. package/dist/entities/delivery.d.ts +59 -0
  21. package/dist/entities/delivery.d.ts.map +1 -0
  22. package/dist/entities/delivery.js +890 -0
  23. package/dist/entities/delivery.js.map +1 -0
  24. package/dist/entities/index.d.ts +114 -0
  25. package/dist/entities/index.d.ts.map +1 -0
  26. package/dist/entities/index.js +89 -0
  27. package/dist/entities/index.js.map +1 -0
  28. package/dist/entities/operations.d.ts +59 -0
  29. package/dist/entities/operations.d.ts.map +1 -0
  30. package/dist/entities/operations.js +1010 -0
  31. package/dist/entities/operations.js.map +1 -0
  32. package/dist/entities/orchestration.d.ts +52 -0
  33. package/dist/entities/orchestration.d.ts.map +1 -0
  34. package/dist/entities/orchestration.js +883 -0
  35. package/dist/entities/orchestration.js.map +1 -0
  36. package/dist/entities/services.d.ts +50 -0
  37. package/dist/entities/services.d.ts.map +1 -0
  38. package/dist/entities/services.js +805 -0
  39. package/dist/entities/services.js.map +1 -0
  40. package/dist/helpers.d.ts +362 -0
  41. package/dist/helpers.d.ts.map +1 -0
  42. package/dist/helpers.js +400 -0
  43. package/dist/helpers.js.map +1 -0
  44. package/dist/index.d.ts +17 -215
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +18 -172
  47. package/dist/index.js.map +1 -0
  48. package/dist/provider.d.ts +85 -0
  49. package/dist/provider.d.ts.map +1 -0
  50. package/dist/provider.js +158 -0
  51. package/dist/provider.js.map +1 -0
  52. package/dist/service.d.ts +43 -0
  53. package/dist/service.d.ts.map +1 -0
  54. package/dist/service.js +206 -0
  55. package/dist/service.js.map +1 -0
  56. package/dist/types.d.ts +469 -0
  57. package/dist/types.d.ts.map +1 -0
  58. package/dist/types.js +5 -0
  59. package/dist/types.js.map +1 -0
  60. package/examples/client-usage.ts +82 -0
  61. package/examples/translation-service.ts +227 -0
  62. package/package.json +24 -38
  63. package/src/client.ts +132 -0
  64. package/src/endpoint.ts +144 -0
  65. package/src/entities/billing.ts +1037 -0
  66. package/src/entities/customers.ts +740 -0
  67. package/src/entities/delivery.ts +974 -0
  68. package/src/entities/index.ts +157 -0
  69. package/src/entities/operations.ts +1099 -0
  70. package/src/entities/orchestration.ts +956 -0
  71. package/src/entities/services.ts +872 -0
  72. package/src/helpers.ts +474 -0
  73. package/src/index.ts +97 -0
  74. package/src/provider.ts +183 -0
  75. package/src/service.test.ts +195 -0
  76. package/src/service.ts +266 -0
  77. package/src/types.ts +543 -0
  78. package/tsconfig.json +9 -0
@@ -0,0 +1,974 @@
1
+ /**
2
+ * AI Delivery Entity Types (Nouns)
3
+ *
4
+ * AI delivery mechanics: AgentDelivery, AutonomyLevel, EscalationRule, ConfidenceThreshold, HumanHandoff, QualityGate
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ import type { Noun } from 'ai-database'
10
+
11
+ // =============================================================================
12
+ // AgentDelivery
13
+ // =============================================================================
14
+
15
+ /**
16
+ * AgentDelivery entity
17
+ *
18
+ * AI agent configuration for autonomous service delivery.
19
+ */
20
+ export const AgentDelivery: Noun = {
21
+ singular: 'agent-delivery',
22
+ plural: 'agent-deliveries',
23
+ description: 'AI agent configuration for autonomous service delivery',
24
+
25
+ properties: {
26
+ // Identity
27
+ name: {
28
+ type: 'string',
29
+ description: 'Agent name',
30
+ },
31
+ description: {
32
+ type: 'string',
33
+ optional: true,
34
+ description: 'Agent description',
35
+ },
36
+
37
+ // Model
38
+ model: {
39
+ type: 'string',
40
+ description: 'AI model identifier',
41
+ examples: ['gpt-4', 'claude-3', 'gemini-pro', 'llama-3', 'custom'],
42
+ },
43
+ modelProvider: {
44
+ type: 'string',
45
+ optional: true,
46
+ description: 'Model provider',
47
+ examples: ['openai', 'anthropic', 'google', 'meta', 'custom'],
48
+ },
49
+ modelConfig: {
50
+ type: 'json',
51
+ optional: true,
52
+ description: 'Model configuration',
53
+ },
54
+
55
+ // Prompt
56
+ systemPrompt: {
57
+ type: 'string',
58
+ optional: true,
59
+ description: 'System prompt',
60
+ },
61
+ contextTemplate: {
62
+ type: 'string',
63
+ optional: true,
64
+ description: 'Context template',
65
+ },
66
+
67
+ // Capabilities
68
+ tools: {
69
+ type: 'string',
70
+ array: true,
71
+ optional: true,
72
+ description: 'Available tools',
73
+ },
74
+ capabilities: {
75
+ type: 'string',
76
+ array: true,
77
+ optional: true,
78
+ description: 'Agent capabilities',
79
+ },
80
+
81
+ // Autonomy
82
+ autonomyLevel: {
83
+ type: 'string',
84
+ description: 'Level of autonomous operation',
85
+ examples: ['full', 'supervised', 'assisted', 'advisory'],
86
+ },
87
+ autonomyScore: {
88
+ type: 'number',
89
+ optional: true,
90
+ description: 'Autonomy score (1-5)',
91
+ },
92
+
93
+ // Confidence
94
+ confidenceThreshold: {
95
+ type: 'number',
96
+ description: 'Min confidence for autonomous action (0-1)',
97
+ },
98
+ lowConfidenceAction: {
99
+ type: 'string',
100
+ optional: true,
101
+ description: 'Action when below threshold',
102
+ examples: ['escalate', 'queue', 'retry', 'fail'],
103
+ },
104
+
105
+ // Execution
106
+ maxIterations: {
107
+ type: 'number',
108
+ optional: true,
109
+ description: 'Max iterations per execution',
110
+ },
111
+ maxTokens: {
112
+ type: 'number',
113
+ optional: true,
114
+ description: 'Max tokens per execution',
115
+ },
116
+ timeoutMs: {
117
+ type: 'number',
118
+ optional: true,
119
+ description: 'Execution timeout',
120
+ },
121
+
122
+ // Safety
123
+ guardrails: {
124
+ type: 'string',
125
+ array: true,
126
+ optional: true,
127
+ description: 'Safety guardrails',
128
+ },
129
+ prohibitedActions: {
130
+ type: 'string',
131
+ array: true,
132
+ optional: true,
133
+ description: 'Prohibited actions',
134
+ },
135
+
136
+ // Escalation
137
+ escalationTriggers: {
138
+ type: 'string',
139
+ array: true,
140
+ optional: true,
141
+ description: 'Conditions that trigger escalation',
142
+ },
143
+
144
+ // Metrics
145
+ avgConfidence: {
146
+ type: 'number',
147
+ optional: true,
148
+ description: 'Average confidence score',
149
+ },
150
+ successRate: {
151
+ type: 'number',
152
+ optional: true,
153
+ description: 'Success rate (0-1)',
154
+ },
155
+ escalationRate: {
156
+ type: 'number',
157
+ optional: true,
158
+ description: 'Escalation rate (0-1)',
159
+ },
160
+
161
+ // Status
162
+ status: {
163
+ type: 'string',
164
+ description: 'Agent status',
165
+ examples: ['active', 'paused', 'training', 'deprecated'],
166
+ },
167
+ },
168
+
169
+ relationships: {
170
+ service: {
171
+ type: 'ProductizedService',
172
+ description: 'Parent service',
173
+ },
174
+ escalationRules: {
175
+ type: 'EscalationRule[]',
176
+ description: 'Escalation rules',
177
+ },
178
+ qualityGates: {
179
+ type: 'QualityGate[]',
180
+ description: 'Quality gates',
181
+ },
182
+ confidenceThresholds: {
183
+ type: 'ConfidenceThreshold[]',
184
+ description: 'Confidence thresholds',
185
+ },
186
+ },
187
+
188
+ actions: [
189
+ 'create',
190
+ 'update',
191
+ 'activate',
192
+ 'pause',
193
+ 'train',
194
+ 'evaluate',
195
+ 'escalate',
196
+ 'deprecate',
197
+ ],
198
+
199
+ events: [
200
+ 'created',
201
+ 'updated',
202
+ 'activated',
203
+ 'paused',
204
+ 'trained',
205
+ 'evaluated',
206
+ 'escalated',
207
+ 'deprecated',
208
+ ],
209
+ }
210
+
211
+ // =============================================================================
212
+ // AutonomyLevel
213
+ // =============================================================================
214
+
215
+ /**
216
+ * AutonomyLevel entity
217
+ *
218
+ * Defines a level of autonomous operation.
219
+ */
220
+ export const AutonomyLevel: Noun = {
221
+ singular: 'autonomy-level',
222
+ plural: 'autonomy-levels',
223
+ description: 'A defined level of autonomous operation',
224
+
225
+ properties: {
226
+ // Identity
227
+ name: {
228
+ type: 'string',
229
+ description: 'Level name',
230
+ },
231
+ description: {
232
+ type: 'string',
233
+ optional: true,
234
+ description: 'Level description',
235
+ },
236
+
237
+ // Level
238
+ level: {
239
+ type: 'number',
240
+ description: 'Numeric level (1-5)',
241
+ },
242
+ code: {
243
+ type: 'string',
244
+ description: 'Level code',
245
+ examples: ['full', 'supervised', 'assisted', 'advisory', 'manual'],
246
+ },
247
+
248
+ // Permissions
249
+ allowedActions: {
250
+ type: 'string',
251
+ array: true,
252
+ optional: true,
253
+ description: 'Allowed autonomous actions',
254
+ },
255
+ restrictedActions: {
256
+ type: 'string',
257
+ array: true,
258
+ optional: true,
259
+ description: 'Actions requiring approval',
260
+ },
261
+ prohibitedActions: {
262
+ type: 'string',
263
+ array: true,
264
+ optional: true,
265
+ description: 'Prohibited actions',
266
+ },
267
+
268
+ // Thresholds
269
+ confidenceRequired: {
270
+ type: 'number',
271
+ optional: true,
272
+ description: 'Min confidence for autonomous action',
273
+ },
274
+ maxRiskTolerance: {
275
+ type: 'number',
276
+ optional: true,
277
+ description: 'Max risk score allowed',
278
+ },
279
+ maxImpactScore: {
280
+ type: 'number',
281
+ optional: true,
282
+ description: 'Max impact score allowed',
283
+ },
284
+
285
+ // Human Involvement
286
+ humanApprovalRequired: {
287
+ type: 'boolean',
288
+ optional: true,
289
+ description: 'Requires human approval',
290
+ },
291
+ humanReviewFrequency: {
292
+ type: 'string',
293
+ optional: true,
294
+ description: 'How often humans review',
295
+ examples: ['always', 'sampled', 'periodic', 'on-error', 'never'],
296
+ },
297
+ reviewSampleRate: {
298
+ type: 'number',
299
+ optional: true,
300
+ description: 'Percentage of tasks reviewed (0-100)',
301
+ },
302
+
303
+ // Status
304
+ status: {
305
+ type: 'string',
306
+ description: 'Level status',
307
+ examples: ['active', 'deprecated'],
308
+ },
309
+ },
310
+
311
+ relationships: {
312
+ agents: {
313
+ type: 'AgentDelivery[]',
314
+ description: 'Agents at this level',
315
+ },
316
+ escalationRules: {
317
+ type: 'EscalationRule[]',
318
+ description: 'Associated escalation rules',
319
+ },
320
+ },
321
+
322
+ actions: [
323
+ 'create',
324
+ 'update',
325
+ 'activate',
326
+ 'deprecate',
327
+ ],
328
+
329
+ events: [
330
+ 'created',
331
+ 'updated',
332
+ 'activated',
333
+ 'deprecated',
334
+ ],
335
+ }
336
+
337
+ // =============================================================================
338
+ // EscalationRule
339
+ // =============================================================================
340
+
341
+ /**
342
+ * EscalationRule entity
343
+ *
344
+ * Rules for escalating to human intervention.
345
+ */
346
+ export const EscalationRule: Noun = {
347
+ singular: 'escalation-rule',
348
+ plural: 'escalation-rules',
349
+ description: 'A rule defining when to escalate to human intervention',
350
+
351
+ properties: {
352
+ // Identity
353
+ name: {
354
+ type: 'string',
355
+ description: 'Rule name',
356
+ },
357
+ description: {
358
+ type: 'string',
359
+ optional: true,
360
+ description: 'Rule description',
361
+ },
362
+
363
+ // Trigger
364
+ triggerType: {
365
+ type: 'string',
366
+ description: 'Trigger type',
367
+ examples: ['confidence', 'error', 'timeout', 'risk', 'keyword', 'pattern', 'manual', 'custom'],
368
+ },
369
+ condition: {
370
+ type: 'string',
371
+ optional: true,
372
+ description: 'Trigger condition expression',
373
+ },
374
+
375
+ // Confidence Triggers
376
+ confidenceThreshold: {
377
+ type: 'number',
378
+ optional: true,
379
+ description: 'Confidence below this triggers escalation',
380
+ },
381
+ confidenceField: {
382
+ type: 'string',
383
+ optional: true,
384
+ description: 'Field to check for confidence',
385
+ },
386
+
387
+ // Error Triggers
388
+ errorTypes: {
389
+ type: 'string',
390
+ array: true,
391
+ optional: true,
392
+ description: 'Error types that trigger escalation',
393
+ },
394
+ maxRetries: {
395
+ type: 'number',
396
+ optional: true,
397
+ description: 'Retries before escalation',
398
+ },
399
+
400
+ // Risk Triggers
401
+ riskThreshold: {
402
+ type: 'number',
403
+ optional: true,
404
+ description: 'Risk score threshold',
405
+ },
406
+ sensitivePatterns: {
407
+ type: 'string',
408
+ array: true,
409
+ optional: true,
410
+ description: 'Patterns indicating sensitive content',
411
+ },
412
+
413
+ // Escalation Target
414
+ escalateTo: {
415
+ type: 'string',
416
+ description: 'Escalation target',
417
+ examples: ['queue', 'team', 'individual', 'on-call', 'manager'],
418
+ },
419
+ targetId: {
420
+ type: 'string',
421
+ optional: true,
422
+ description: 'Target team/person ID',
423
+ },
424
+
425
+ // Timing
426
+ responseTimeTarget: {
427
+ type: 'number',
428
+ optional: true,
429
+ description: 'Target response time (seconds)',
430
+ },
431
+ autoEscalateAfter: {
432
+ type: 'number',
433
+ optional: true,
434
+ description: 'Auto-escalate to next level after (seconds)',
435
+ },
436
+
437
+ // Priority
438
+ priority: {
439
+ type: 'string',
440
+ optional: true,
441
+ description: 'Escalation priority',
442
+ examples: ['low', 'medium', 'high', 'critical'],
443
+ },
444
+
445
+ // Status
446
+ status: {
447
+ type: 'string',
448
+ description: 'Rule status',
449
+ examples: ['active', 'disabled', 'testing'],
450
+ },
451
+ },
452
+
453
+ relationships: {
454
+ agent: {
455
+ type: 'AgentDelivery',
456
+ required: false,
457
+ description: 'Parent agent',
458
+ },
459
+ service: {
460
+ type: 'ProductizedService',
461
+ required: false,
462
+ description: 'Parent service',
463
+ },
464
+ handoffs: {
465
+ type: 'HumanHandoff[]',
466
+ description: 'Resulting handoffs',
467
+ },
468
+ },
469
+
470
+ actions: [
471
+ 'create',
472
+ 'update',
473
+ 'enable',
474
+ 'disable',
475
+ 'test',
476
+ 'trigger',
477
+ ],
478
+
479
+ events: [
480
+ 'created',
481
+ 'updated',
482
+ 'enabled',
483
+ 'disabled',
484
+ 'tested',
485
+ 'triggered',
486
+ ],
487
+ }
488
+
489
+ // =============================================================================
490
+ // ConfidenceThreshold
491
+ // =============================================================================
492
+
493
+ /**
494
+ * ConfidenceThreshold entity
495
+ *
496
+ * Confidence-based decision rules.
497
+ */
498
+ export const ConfidenceThreshold: Noun = {
499
+ singular: 'confidence-threshold',
500
+ plural: 'confidence-thresholds',
501
+ description: 'A confidence-based decision rule',
502
+
503
+ properties: {
504
+ // Identity
505
+ name: {
506
+ type: 'string',
507
+ description: 'Threshold name',
508
+ },
509
+ description: {
510
+ type: 'string',
511
+ optional: true,
512
+ description: 'Threshold description',
513
+ },
514
+
515
+ // Threshold
516
+ minConfidence: {
517
+ type: 'number',
518
+ description: 'Minimum confidence (0-1)',
519
+ },
520
+ maxConfidence: {
521
+ type: 'number',
522
+ optional: true,
523
+ description: 'Maximum confidence (0-1)',
524
+ },
525
+
526
+ // Context
527
+ context: {
528
+ type: 'string',
529
+ optional: true,
530
+ description: 'Application context',
531
+ examples: ['classification', 'generation', 'extraction', 'decision', 'any'],
532
+ },
533
+ taskTypes: {
534
+ type: 'string',
535
+ array: true,
536
+ optional: true,
537
+ description: 'Applicable task types',
538
+ },
539
+
540
+ // Action
541
+ action: {
542
+ type: 'string',
543
+ description: 'Action when threshold met',
544
+ examples: ['proceed', 'review', 'escalate', 'retry', 'fail'],
545
+ },
546
+ requiresHumanReview: {
547
+ type: 'boolean',
548
+ optional: true,
549
+ description: 'Requires human review',
550
+ },
551
+ allowOverride: {
552
+ type: 'boolean',
553
+ optional: true,
554
+ description: 'Allows human override',
555
+ },
556
+
557
+ // Risk Adjustment
558
+ riskMultiplier: {
559
+ type: 'number',
560
+ optional: true,
561
+ description: 'Risk-adjusted multiplier',
562
+ },
563
+ adjustForDomain: {
564
+ type: 'boolean',
565
+ optional: true,
566
+ description: 'Adjust based on domain',
567
+ },
568
+
569
+ // Learning
570
+ adaptive: {
571
+ type: 'boolean',
572
+ optional: true,
573
+ description: 'Threshold adapts over time',
574
+ },
575
+ learningRate: {
576
+ type: 'number',
577
+ optional: true,
578
+ description: 'Adaptation learning rate',
579
+ },
580
+
581
+ // Status
582
+ status: {
583
+ type: 'string',
584
+ description: 'Threshold status',
585
+ examples: ['active', 'disabled', 'testing'],
586
+ },
587
+ },
588
+
589
+ relationships: {
590
+ agent: {
591
+ type: 'AgentDelivery',
592
+ required: false,
593
+ description: 'Parent agent',
594
+ },
595
+ service: {
596
+ type: 'ProductizedService',
597
+ required: false,
598
+ description: 'Parent service',
599
+ },
600
+ },
601
+
602
+ actions: [
603
+ 'create',
604
+ 'update',
605
+ 'enable',
606
+ 'disable',
607
+ 'adjust',
608
+ 'test',
609
+ ],
610
+
611
+ events: [
612
+ 'created',
613
+ 'updated',
614
+ 'enabled',
615
+ 'disabled',
616
+ 'adjusted',
617
+ 'tested',
618
+ ],
619
+ }
620
+
621
+ // =============================================================================
622
+ // HumanHandoff
623
+ // =============================================================================
624
+
625
+ /**
626
+ * HumanHandoff entity
627
+ *
628
+ * A point where AI hands off to human.
629
+ */
630
+ export const HumanHandoff: Noun = {
631
+ singular: 'human-handoff',
632
+ plural: 'human-handoffs',
633
+ description: 'A point where AI hands off to human intervention',
634
+
635
+ properties: {
636
+ // Identity
637
+ id: {
638
+ type: 'string',
639
+ description: 'Handoff ID',
640
+ },
641
+
642
+ // Trigger
643
+ triggerReason: {
644
+ type: 'string',
645
+ description: 'Why handoff was triggered',
646
+ examples: ['low-confidence', 'error', 'escalation-rule', 'user-request', 'safety', 'complexity'],
647
+ },
648
+ triggerDetails: {
649
+ type: 'string',
650
+ optional: true,
651
+ description: 'Detailed trigger explanation',
652
+ },
653
+
654
+ // Context
655
+ context: {
656
+ type: 'json',
657
+ optional: true,
658
+ description: 'Execution context at handoff',
659
+ },
660
+ conversationHistory: {
661
+ type: 'json',
662
+ optional: true,
663
+ description: 'Conversation history',
664
+ },
665
+ agentOutput: {
666
+ type: 'json',
667
+ optional: true,
668
+ description: 'Agent output before handoff',
669
+ },
670
+ confidence: {
671
+ type: 'number',
672
+ optional: true,
673
+ description: 'Confidence at handoff',
674
+ },
675
+
676
+ // Assignment
677
+ assignedTo: {
678
+ type: 'string',
679
+ optional: true,
680
+ description: 'Assigned human/team',
681
+ },
682
+ assignedAt: {
683
+ type: 'date',
684
+ optional: true,
685
+ description: 'Assignment time',
686
+ },
687
+
688
+ // Priority
689
+ priority: {
690
+ type: 'string',
691
+ description: 'Handoff priority',
692
+ examples: ['low', 'medium', 'high', 'critical'],
693
+ },
694
+ dueBy: {
695
+ type: 'date',
696
+ optional: true,
697
+ description: 'Due date/time',
698
+ },
699
+
700
+ // Resolution
701
+ resolution: {
702
+ type: 'string',
703
+ optional: true,
704
+ description: 'Resolution type',
705
+ examples: ['completed', 'returned-to-ai', 'cancelled', 'escalated-further'],
706
+ },
707
+ resolutionNotes: {
708
+ type: 'string',
709
+ optional: true,
710
+ description: 'Resolution notes',
711
+ },
712
+ humanOutput: {
713
+ type: 'json',
714
+ optional: true,
715
+ description: 'Human-provided output',
716
+ },
717
+
718
+ // Timing
719
+ createdAt: {
720
+ type: 'date',
721
+ optional: true,
722
+ description: 'Creation time',
723
+ },
724
+ resolvedAt: {
725
+ type: 'date',
726
+ optional: true,
727
+ description: 'Resolution time',
728
+ },
729
+ waitTimeMs: {
730
+ type: 'number',
731
+ optional: true,
732
+ description: 'Wait time in ms',
733
+ },
734
+ handlingTimeMs: {
735
+ type: 'number',
736
+ optional: true,
737
+ description: 'Handling time in ms',
738
+ },
739
+
740
+ // Feedback
741
+ feedbackProvided: {
742
+ type: 'boolean',
743
+ optional: true,
744
+ description: 'Feedback was provided',
745
+ },
746
+ feedbackUsedForTraining: {
747
+ type: 'boolean',
748
+ optional: true,
749
+ description: 'Used for AI training',
750
+ },
751
+
752
+ // Status
753
+ status: {
754
+ type: 'string',
755
+ description: 'Handoff status',
756
+ examples: ['pending', 'assigned', 'in-progress', 'resolved', 'expired'],
757
+ },
758
+ },
759
+
760
+ relationships: {
761
+ execution: {
762
+ type: 'ServiceExecution',
763
+ description: 'Related execution',
764
+ },
765
+ escalationRule: {
766
+ type: 'EscalationRule',
767
+ required: false,
768
+ description: 'Triggering rule',
769
+ },
770
+ agent: {
771
+ type: 'AgentDelivery',
772
+ required: false,
773
+ description: 'Agent that handed off',
774
+ },
775
+ },
776
+
777
+ actions: [
778
+ 'create',
779
+ 'assign',
780
+ 'start',
781
+ 'resolve',
782
+ 'returnToAI',
783
+ 'escalate',
784
+ 'expire',
785
+ ],
786
+
787
+ events: [
788
+ 'created',
789
+ 'assigned',
790
+ 'started',
791
+ 'resolved',
792
+ 'returnedToAI',
793
+ 'escalated',
794
+ 'expired',
795
+ ],
796
+ }
797
+
798
+ // =============================================================================
799
+ // QualityGate
800
+ // =============================================================================
801
+
802
+ /**
803
+ * QualityGate entity
804
+ *
805
+ * Quality assurance checkpoint.
806
+ */
807
+ export const QualityGate: Noun = {
808
+ singular: 'quality-gate',
809
+ plural: 'quality-gates',
810
+ description: 'A quality assurance checkpoint in service delivery',
811
+
812
+ properties: {
813
+ // Identity
814
+ name: {
815
+ type: 'string',
816
+ description: 'Gate name',
817
+ },
818
+ description: {
819
+ type: 'string',
820
+ optional: true,
821
+ description: 'Gate description',
822
+ },
823
+
824
+ // Position
825
+ stage: {
826
+ type: 'string',
827
+ description: 'Pipeline stage',
828
+ examples: ['input', 'processing', 'output', 'delivery'],
829
+ },
830
+ order: {
831
+ type: 'number',
832
+ optional: true,
833
+ description: 'Gate order in stage',
834
+ },
835
+
836
+ // Criteria
837
+ criteriaType: {
838
+ type: 'string',
839
+ description: 'Type of criteria',
840
+ examples: ['rule', 'model', 'human', 'automated', 'hybrid'],
841
+ },
842
+ criteria: {
843
+ type: 'json',
844
+ optional: true,
845
+ description: 'Quality criteria definition',
846
+ },
847
+
848
+ // Thresholds
849
+ passThreshold: {
850
+ type: 'number',
851
+ optional: true,
852
+ description: 'Score to pass (0-1)',
853
+ },
854
+ warnThreshold: {
855
+ type: 'number',
856
+ optional: true,
857
+ description: 'Score for warning (0-1)',
858
+ },
859
+
860
+ // Actions
861
+ onPass: {
862
+ type: 'string',
863
+ optional: true,
864
+ description: 'Action on pass',
865
+ examples: ['continue', 'log', 'notify'],
866
+ },
867
+ onFail: {
868
+ type: 'string',
869
+ optional: true,
870
+ description: 'Action on fail',
871
+ examples: ['block', 'escalate', 'retry', 'warn'],
872
+ },
873
+ onWarn: {
874
+ type: 'string',
875
+ optional: true,
876
+ description: 'Action on warning',
877
+ examples: ['continue', 'flag', 'review'],
878
+ },
879
+
880
+ // Review
881
+ requiresReview: {
882
+ type: 'boolean',
883
+ optional: true,
884
+ description: 'Requires human review',
885
+ },
886
+ reviewSampleRate: {
887
+ type: 'number',
888
+ optional: true,
889
+ description: 'Sample rate for review (0-100)',
890
+ },
891
+
892
+ // Metrics
893
+ passRate: {
894
+ type: 'number',
895
+ optional: true,
896
+ description: 'Historical pass rate',
897
+ },
898
+ avgScore: {
899
+ type: 'number',
900
+ optional: true,
901
+ description: 'Average quality score',
902
+ },
903
+ evaluationsCount: {
904
+ type: 'number',
905
+ optional: true,
906
+ description: 'Total evaluations',
907
+ },
908
+
909
+ // Status
910
+ status: {
911
+ type: 'string',
912
+ description: 'Gate status',
913
+ examples: ['active', 'disabled', 'testing'],
914
+ },
915
+ },
916
+
917
+ relationships: {
918
+ agent: {
919
+ type: 'AgentDelivery',
920
+ required: false,
921
+ description: 'Parent agent',
922
+ },
923
+ service: {
924
+ type: 'ProductizedService',
925
+ required: false,
926
+ description: 'Parent service',
927
+ },
928
+ workflow: {
929
+ type: 'ServiceWorkflow',
930
+ required: false,
931
+ description: 'Parent workflow',
932
+ },
933
+ },
934
+
935
+ actions: [
936
+ 'create',
937
+ 'update',
938
+ 'enable',
939
+ 'disable',
940
+ 'evaluate',
941
+ 'adjustThreshold',
942
+ ],
943
+
944
+ events: [
945
+ 'created',
946
+ 'updated',
947
+ 'enabled',
948
+ 'disabled',
949
+ 'evaluated',
950
+ 'passed',
951
+ 'failed',
952
+ 'warned',
953
+ ],
954
+ }
955
+
956
+ // =============================================================================
957
+ // Exports
958
+ // =============================================================================
959
+
960
+ export const DeliveryEntities = {
961
+ AgentDelivery,
962
+ AutonomyLevel,
963
+ EscalationRule,
964
+ ConfidenceThreshold,
965
+ HumanHandoff,
966
+ QualityGate,
967
+ }
968
+
969
+ export const DeliveryCategories = {
970
+ agents: ['AgentDelivery'],
971
+ autonomy: ['AutonomyLevel', 'ConfidenceThreshold'],
972
+ escalation: ['EscalationRule', 'HumanHandoff'],
973
+ quality: ['QualityGate'],
974
+ } as const