ai-data-workflow-contract 0.1.5 → 0.1.7

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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.ts +467 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-data-workflow-contract",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "private": false,
5
5
  "description": "AI Data Workflow RunGraph contracts backed by EagerDataFlow authoring plans",
6
6
  "type": "module",
@@ -9,8 +9,8 @@
9
9
  ".": "./src/index.ts"
10
10
  },
11
11
  "dependencies": {
12
- "ai-workflow-contract": "0.1.8",
13
- "eager-data-flow-contract": "0.1.3"
12
+ "ai-workflow-contract": "0.1.9",
13
+ "eager-data-flow-contract": "0.1.4"
14
14
  },
15
15
  "files": [
16
16
  "src"
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ import type {
9
9
  AIWorkflowRunRef,
10
10
  AIWorkflowRunStatus,
11
11
  AIWorkflowSemanticFingerprint,
12
+ FlowClosedObject,
12
13
  FlowRunCheckpoint,
13
14
  } from 'ai-workflow-contract';
14
15
  import type {
@@ -44,6 +45,136 @@ export interface AIDataWorkflowInvalidation {
44
45
  readonly atMs?: number;
45
46
  }
46
47
 
48
+ export interface AIDataWorkflowDeclaredSubFlowBinding {
49
+ readonly kind: 'declared';
50
+ readonly flowRef: `eager-data-flow://${string}`;
51
+ }
52
+
53
+ export interface AIDataWorkflowAutonomousSubFlowBinding {
54
+ readonly kind: 'autonomous';
55
+ readonly schemaVersion: 'depa.ai-data-subflow-binding/v1';
56
+ readonly capabilityId: string;
57
+ readonly catalogDigest: string;
58
+ readonly definitionRef: `resource://${string}`;
59
+ readonly flowRef: `eager-data-flow://${string}`;
60
+ readonly contractDigest: string;
61
+ }
62
+
63
+ export type AIDataWorkflowSubFlowBinding =
64
+ | AIDataWorkflowDeclaredSubFlowBinding
65
+ | AIDataWorkflowAutonomousSubFlowBinding;
66
+
67
+ export const AI_DATA_CHILD_INVOCATION_SCHEMA_VERSION = 'depa.ai-data-child-invocation/v1' as const;
68
+
69
+ export interface AIDataWorkflowChildInvocationIdentity {
70
+ readonly schemaVersion: typeof AI_DATA_CHILD_INVOCATION_SCHEMA_VERSION;
71
+ readonly invocationKey: string;
72
+ readonly parentInstanceId: string;
73
+ readonly parentRunId: string;
74
+ readonly parentNodeId: string;
75
+ readonly parentGeneration: number;
76
+ readonly childInstanceId: string;
77
+ readonly childRunId: string;
78
+ readonly subflow: AIDataWorkflowAutonomousSubFlowBinding;
79
+ }
80
+
81
+ /** Immutable proof that the exact child resource closure was resolved before dispatch. */
82
+ export interface AIDataWorkflowChildFreezeReceipt {
83
+ readonly schemaVersion: typeof AI_DATA_CHILD_INVOCATION_SCHEMA_VERSION;
84
+ readonly invocationKey: string;
85
+ readonly childInstanceId: string;
86
+ readonly childRunId: string;
87
+ readonly definitionRef: `resource://${string}`;
88
+ readonly flowRef: `eager-data-flow://${string}`;
89
+ readonly contractDigest: string;
90
+ readonly definitionRevision: string;
91
+ readonly definitionDigest: string;
92
+ }
93
+
94
+ export type AIDataWorkflowChildInvocationStatus =
95
+ | 'Reserved'
96
+ | 'Running'
97
+ | 'Succeeded'
98
+ | 'Failed';
99
+
100
+ /** Read-only child-owner projection. The parent never writes child lifecycle state. */
101
+ export interface AIDataWorkflowChildInvocationObservation {
102
+ readonly schemaVersion: typeof AI_DATA_CHILD_INVOCATION_SCHEMA_VERSION;
103
+ readonly invocationKey: string;
104
+ readonly childInstanceId: string;
105
+ readonly childRunId: string;
106
+ readonly status: AIDataWorkflowChildInvocationStatus;
107
+ }
108
+
109
+ export interface AIDataWorkflowChildSucceededReceipt {
110
+ readonly schemaVersion: typeof AI_DATA_CHILD_INVOCATION_SCHEMA_VERSION;
111
+ readonly invocationKey: string;
112
+ readonly childInstanceId: string;
113
+ readonly childRunId: string;
114
+ readonly definitionRef: `resource://${string}`;
115
+ readonly flowRef: `eager-data-flow://${string}`;
116
+ readonly contractDigest: string;
117
+ readonly status: 'Succeeded';
118
+ readonly output: FlowClosedObject;
119
+ readonly receiptDigest: string;
120
+ }
121
+
122
+ export interface AIDataWorkflowChildFailedReceipt {
123
+ readonly schemaVersion: typeof AI_DATA_CHILD_INVOCATION_SCHEMA_VERSION;
124
+ readonly invocationKey: string;
125
+ readonly childInstanceId: string;
126
+ readonly childRunId: string;
127
+ readonly definitionRef: `resource://${string}`;
128
+ readonly flowRef: `eager-data-flow://${string}`;
129
+ readonly contractDigest: string;
130
+ readonly status: 'Failed';
131
+ readonly failureCode: string;
132
+ readonly failureMessage: string;
133
+ readonly receiptDigest: string;
134
+ }
135
+
136
+ export type AIDataWorkflowChildTerminalReceipt =
137
+ | AIDataWorkflowChildSucceededReceipt
138
+ | AIDataWorkflowChildFailedReceipt;
139
+
140
+ export interface AIDataWorkflowResolveAndFreezeChildRequest {
141
+ readonly identity: AIDataWorkflowChildInvocationIdentity;
142
+ }
143
+
144
+ export interface AIDataWorkflowStartOrContinueChildRequest {
145
+ readonly identity: AIDataWorkflowChildInvocationIdentity;
146
+ readonly freeze: AIDataWorkflowChildFreezeReceipt;
147
+ readonly input: FlowClosedObject;
148
+ }
149
+
150
+ export interface AIDataWorkflowLoadChildRequest {
151
+ readonly identity: AIDataWorkflowChildInvocationIdentity;
152
+ readonly freeze: AIDataWorkflowChildFreezeReceipt;
153
+ }
154
+
155
+ export interface AIDataWorkflowSettleChildRequest extends AIDataWorkflowLoadChildRequest {
156
+ readonly terminalStatus: 'Succeeded' | 'Failed';
157
+ }
158
+
159
+ /**
160
+ * Narrow child-owner port. Every operation is idempotent for one deterministic identity;
161
+ * startOrContinue must continue an existing child rather than create a successor.
162
+ */
163
+ export interface AIDataWorkflowChildInvocationRuntimePort {
164
+ resolveAndFreeze(
165
+ request: AIDataWorkflowResolveAndFreezeChildRequest,
166
+ ): Promise<AIDataWorkflowChildFreezeReceipt>;
167
+ startOrContinue(
168
+ request: AIDataWorkflowStartOrContinueChildRequest,
169
+ ): Promise<AIDataWorkflowChildInvocationObservation>;
170
+ load(
171
+ request: AIDataWorkflowLoadChildRequest,
172
+ ): Promise<AIDataWorkflowChildInvocationObservation>;
173
+ settle(
174
+ request: AIDataWorkflowSettleChildRequest,
175
+ ): Promise<AIDataWorkflowChildTerminalReceipt>;
176
+ }
177
+
47
178
  export interface AIDataWorkflowRunNode {
48
179
  readonly id: string;
49
180
  readonly tag: AIDataWorkflowNodeTag;
@@ -54,6 +185,10 @@ export interface AIDataWorkflowRunNode {
54
185
  readonly inputs: AIDataWorkflowNodeInputs;
55
186
  readonly outputs: readonly string[];
56
187
  readonly config: AIDataWorkflowNodeConfig;
188
+ readonly subflow?: AIDataWorkflowSubFlowBinding;
189
+ readonly childInvocation?: AIDataWorkflowChildInvocationIdentity;
190
+ readonly childFreezeReceipt?: AIDataWorkflowChildFreezeReceipt;
191
+ readonly childTerminalReceipt?: AIDataWorkflowChildTerminalReceipt;
57
192
  readonly dependsOn: readonly string[];
58
193
  readonly dependents: readonly string[];
59
194
  readonly reusePolicy: AIWorkflowEffectiveReusePolicy;
@@ -70,6 +205,7 @@ export interface AIDataWorkflowGraphPatchNodeSpec {
70
205
  readonly inputs?: AIDataWorkflowNodeInputs;
71
206
  readonly outputs?: readonly string[];
72
207
  readonly config?: AIDataWorkflowNodeConfig;
208
+ readonly subflow?: AIDataWorkflowSubFlowBinding;
73
209
  readonly dependsOn?: readonly string[];
74
210
  readonly reusePolicy?: AIWorkflowEffectiveReusePolicy;
75
211
  }
@@ -80,6 +216,7 @@ export interface AIDataWorkflowGraphPatchNodeChanges {
80
216
  readonly inputs?: AIDataWorkflowNodeInputs;
81
217
  readonly outputs?: readonly string[];
82
218
  readonly config?: AIDataWorkflowNodeConfig;
219
+ readonly subflow?: AIDataWorkflowSubFlowBinding | null;
83
220
  readonly dependsOn?: readonly string[];
84
221
  readonly reusePolicy?: AIWorkflowEffectiveReusePolicy;
85
222
  }
@@ -169,3 +306,333 @@ export interface AIDataWorkflowPlanProjection {
169
306
  export type AIDataWorkflowRunCheckpoint = FlowRunCheckpoint<
170
307
  AIDataWorkflowRunProfileState<AIDataWorkflowRunGraph>
171
308
  >;
309
+
310
+ export const AI_DATA_CONTROL_SCHEMA_VERSION = 'depa.ai-data-control/v1' as const;
311
+
312
+ export type AIDataControlSchemaVersion = typeof AI_DATA_CONTROL_SCHEMA_VERSION;
313
+
314
+ export interface AIDataControlGoal {
315
+ readonly schemaVersion: AIDataControlSchemaVersion;
316
+ readonly goalId: string;
317
+ readonly objective: string;
318
+ readonly verifierRef: `resource://${string}`;
319
+ readonly requiredOutputSchemaRef: string;
320
+ }
321
+
322
+ export interface AIDataControlBudgetLimits {
323
+ readonly maxIterations: number;
324
+ readonly maxOperationsPerDecision: number;
325
+ readonly maxNoProgressIterations: number;
326
+ readonly maxTokens?: number;
327
+ readonly deadlineEpochMs?: number;
328
+ }
329
+
330
+ export interface AIDataControlBudgetUsage {
331
+ readonly iteration: number;
332
+ readonly noProgressIterations: number;
333
+ readonly tokensUsed?: number;
334
+ readonly nowEpochMs?: number;
335
+ }
336
+
337
+ export interface AIDataControlBudget {
338
+ readonly schemaVersion: AIDataControlSchemaVersion;
339
+ readonly limits: AIDataControlBudgetLimits;
340
+ readonly usage: AIDataControlBudgetUsage;
341
+ }
342
+
343
+ export interface AIDataControlBudgetProjection {
344
+ readonly iteration: number;
345
+ readonly remainingIterations: number;
346
+ readonly remainingOperations: number;
347
+ readonly noProgressIterations: number;
348
+ readonly remainingNoProgressIterations: number;
349
+ readonly remainingTokens?: number;
350
+ readonly remainingMs?: number;
351
+ }
352
+
353
+ export interface AIDataControlNodeContract {
354
+ readonly protected: boolean;
355
+ readonly inputSchemaRefs: Readonly<Record<string, string>>;
356
+ readonly outputSchemaRefs: Readonly<Record<string, string>>;
357
+ }
358
+
359
+ export interface AIDataControlCodeCapabilityImplementation {
360
+ readonly kind: 'code';
361
+ readonly codeRef: `resource://${string}`;
362
+ }
363
+
364
+ export interface AIDataControlAgentCapabilityImplementation {
365
+ readonly kind: 'agent';
366
+ readonly agentDefinitionRef: `resource://${string}`;
367
+ readonly taskProofRef: `resource://${string}`;
368
+ }
369
+
370
+ export interface AIDataControlSubFlowCapabilityImplementation {
371
+ readonly kind: 'subflow';
372
+ readonly definitionRef: `resource://${string}`;
373
+ readonly flowRef: `eager-data-flow://${string}`;
374
+ readonly contractDigest: string;
375
+ readonly callGraphDigest: string;
376
+ readonly transitiveChildFlowRefs: readonly `eager-data-flow://${string}`[];
377
+ }
378
+
379
+ export type AIDataControlExecutableCapabilityImplementation =
380
+ | AIDataControlCodeCapabilityImplementation
381
+ | AIDataControlAgentCapabilityImplementation;
382
+
383
+ export interface AIDataControlCapabilityBase {
384
+ readonly capabilityId: string;
385
+ readonly inputSchemaRefs: Readonly<Record<string, string>>;
386
+ readonly outputSchemaRefs: Readonly<Record<string, string>>;
387
+ readonly fixedConfig: AIDataWorkflowNodeConfig;
388
+ }
389
+
390
+ export interface AIDataControlExecutableCapability extends AIDataControlCapabilityBase {
391
+ readonly tag: 'TransformNode' | 'SinkNode';
392
+ readonly nodeType: AIWorkflowNodeType;
393
+ readonly implementation: AIDataControlExecutableCapabilityImplementation;
394
+ }
395
+
396
+ export interface AIDataControlSubFlowCapability extends AIDataControlCapabilityBase {
397
+ readonly tag: 'SubFlowNode';
398
+ readonly nodeType: 'subflow';
399
+ readonly implementation: AIDataControlSubFlowCapabilityImplementation;
400
+ }
401
+
402
+ export type AIDataControlCapability =
403
+ | AIDataControlExecutableCapability
404
+ | AIDataControlSubFlowCapability;
405
+
406
+ export interface AIDataControlCapabilityCatalog {
407
+ readonly schemaVersion: AIDataControlSchemaVersion;
408
+ readonly catalogId: string;
409
+ readonly digest: string;
410
+ readonly foundationNodes: Readonly<Record<string, AIDataControlNodeContract>>;
411
+ readonly capabilities: Readonly<Record<string, AIDataControlCapability>>;
412
+ }
413
+
414
+ export type AIDataControlVerifierStatus = 'not-run' | 'passed' | 'failed';
415
+
416
+ export interface AIDataControlDiagnostic {
417
+ readonly code: string;
418
+ readonly message: string;
419
+ readonly nodeId?: string;
420
+ }
421
+
422
+ export interface AIDataControlVerifierFact {
423
+ readonly schemaVersion: AIDataControlSchemaVersion;
424
+ readonly factId: string;
425
+ readonly goalId: string;
426
+ readonly graphGeneration: number;
427
+ readonly status: AIDataControlVerifierStatus;
428
+ readonly verifierRef: `resource://${string}`;
429
+ readonly requiredOutputSchemaRef: string;
430
+ readonly diagnostics: readonly AIDataControlDiagnostic[];
431
+ }
432
+
433
+ export interface AIDataControlObservedNode {
434
+ readonly nodeId: string;
435
+ readonly tag: AIDataWorkflowNodeTag;
436
+ readonly nodeType: AIWorkflowNodeType;
437
+ readonly status: AIDataWorkflowRunNodeStatus;
438
+ readonly protected: boolean;
439
+ readonly capabilityId?: string;
440
+ readonly dependsOn: readonly string[];
441
+ readonly inputSchemaRefs: Readonly<Record<string, string>>;
442
+ readonly outputSchemaRefs: Readonly<Record<string, string>>;
443
+ }
444
+
445
+ export interface AIDataControlGraphObservation {
446
+ readonly runId: string;
447
+ readonly generation: number;
448
+ readonly digest: string;
449
+ readonly nodes: readonly AIDataControlObservedNode[];
450
+ }
451
+
452
+ export type AIDataControlFeedbackCode =
453
+ | 'SCHEMA_VERSION_MISMATCH'
454
+ | 'GOAL_MISMATCH'
455
+ | 'CATALOG_MISMATCH'
456
+ | 'STALE_OBSERVATION'
457
+ | 'BUDGET_EXHAUSTED'
458
+ | 'INVALID_OPERATION_COUNT'
459
+ | 'DUPLICATE_TARGET'
460
+ | 'PROTECTED_NODE'
461
+ | 'UNKNOWN_CAPABILITY'
462
+ | 'UNKNOWN_NODE'
463
+ | 'INPUT_CONTRACT_MISMATCH'
464
+ | 'OUTPUT_CONTRACT_MISMATCH'
465
+ | 'RECURSIVE_SUBFLOW'
466
+ | 'NO_PROGRESS'
467
+ | 'VERIFIER_REQUIRED'
468
+ | 'VERIFIER_MISMATCH'
469
+ | 'INVALID_DECISION';
470
+
471
+ export interface AIDataControlFeedback {
472
+ readonly code: AIDataControlFeedbackCode;
473
+ readonly message: string;
474
+ readonly operationIndex?: number;
475
+ readonly nodeId?: string;
476
+ readonly port?: string;
477
+ }
478
+
479
+ export interface AIDataControlObservation {
480
+ readonly schemaVersion: AIDataControlSchemaVersion;
481
+ readonly observationId: string;
482
+ readonly observationDigest: string;
483
+ readonly goalId: string;
484
+ readonly catalogDigest: string;
485
+ readonly graph: AIDataControlGraphObservation;
486
+ readonly verifier: AIDataControlVerifierFact;
487
+ readonly budget: AIDataControlBudgetProjection;
488
+ readonly feedback: readonly AIDataControlFeedback[];
489
+ }
490
+
491
+ export interface AIDataControlPortInputBinding {
492
+ readonly kind: 'port';
493
+ readonly nodeId: string;
494
+ readonly port: string;
495
+ readonly schemaRef: string;
496
+ }
497
+
498
+ export interface AIDataControlLiteralInputBinding {
499
+ readonly kind: 'literal';
500
+ readonly schemaRef: string;
501
+ readonly value: EagerDataFlowValue;
502
+ }
503
+
504
+ export type AIDataControlInputBinding =
505
+ | AIDataControlPortInputBinding
506
+ | AIDataControlLiteralInputBinding;
507
+
508
+ export interface AIDataControlAddCapabilityOperation {
509
+ readonly op: 'add-capability';
510
+ readonly nodeId: string;
511
+ readonly capabilityId: string;
512
+ readonly inputs: Readonly<Record<string, AIDataControlInputBinding>>;
513
+ readonly dependsOn?: readonly string[];
514
+ }
515
+
516
+ export interface AIDataControlRewireCapabilityOperation {
517
+ readonly op: 'rewire-capability';
518
+ readonly nodeId: string;
519
+ readonly capabilityId: string;
520
+ readonly inputs: Readonly<Record<string, AIDataControlInputBinding>>;
521
+ readonly dependsOn?: readonly string[];
522
+ }
523
+
524
+ export interface AIDataControlAddSubFlowOperation {
525
+ readonly op: 'add-subflow';
526
+ readonly nodeId: string;
527
+ readonly subflowCapabilityId: string;
528
+ readonly inputs: Readonly<Record<string, AIDataControlInputBinding>>;
529
+ readonly dependsOn?: readonly string[];
530
+ }
531
+
532
+ export interface AIDataControlRewireSubFlowOperation {
533
+ readonly op: 'rewire-subflow';
534
+ readonly nodeId: string;
535
+ readonly subflowCapabilityId: string;
536
+ readonly inputs: Readonly<Record<string, AIDataControlInputBinding>>;
537
+ readonly dependsOn?: readonly string[];
538
+ }
539
+
540
+ export interface AIDataControlRemoveNodeOperation {
541
+ readonly op: 'remove-node';
542
+ readonly nodeId: string;
543
+ }
544
+
545
+ export type AIDataControlRevisionOperation =
546
+ | AIDataControlAddCapabilityOperation
547
+ | AIDataControlRewireCapabilityOperation
548
+ | AIDataControlAddSubFlowOperation
549
+ | AIDataControlRewireSubFlowOperation
550
+ | AIDataControlRemoveNodeOperation;
551
+
552
+ interface AIDataControlDecisionBase {
553
+ readonly schemaVersion: AIDataControlSchemaVersion;
554
+ readonly decisionId: string;
555
+ readonly goalId: string;
556
+ readonly observationId: string;
557
+ readonly observationDigest: string;
558
+ readonly catalogDigest: string;
559
+ readonly reason: string;
560
+ }
561
+
562
+ export interface AIDataControlReviseDecision extends AIDataControlDecisionBase {
563
+ readonly kind: 'revise';
564
+ readonly operations: readonly AIDataControlRevisionOperation[];
565
+ }
566
+
567
+ export interface AIDataControlCompleteDecision extends AIDataControlDecisionBase {
568
+ readonly kind: 'complete';
569
+ readonly verifierFactId: string;
570
+ readonly outputNodeId: string;
571
+ readonly outputPort: string;
572
+ readonly outputSchemaRef: string;
573
+ }
574
+
575
+ export type AIDataControlFailureCode =
576
+ | 'CONTROLLER_DECLARED_FAILURE'
577
+ | 'GOAL_UNREACHABLE'
578
+ | 'BUDGET_EXHAUSTED'
579
+ | 'NO_PROGRESS';
580
+
581
+ export interface AIDataControlFailDecision extends AIDataControlDecisionBase {
582
+ readonly kind: 'fail';
583
+ readonly failureCode: AIDataControlFailureCode;
584
+ }
585
+
586
+ export type AIDataControlDecision =
587
+ | AIDataControlReviseDecision
588
+ | AIDataControlCompleteDecision
589
+ | AIDataControlFailDecision;
590
+
591
+ interface AIDataControlAdmissionBase {
592
+ readonly schemaVersion: AIDataControlSchemaVersion;
593
+ readonly decisionId: string;
594
+ readonly decisionDigest: string;
595
+ }
596
+
597
+ export interface AIDataControlPatchAdmission extends AIDataControlAdmissionBase {
598
+ readonly kind: 'patch';
599
+ readonly patch: AIDataWorkflowGraphPatch;
600
+ }
601
+
602
+ export interface AIDataControlCompletionAdmission extends AIDataControlAdmissionBase {
603
+ readonly kind: 'complete';
604
+ readonly verifierFactId: string;
605
+ readonly outputNodeId: string;
606
+ readonly outputPort: string;
607
+ readonly outputSchemaRef: string;
608
+ }
609
+
610
+ export interface AIDataControlFailureAdmission extends AIDataControlAdmissionBase {
611
+ readonly kind: 'fail';
612
+ readonly failureCode: AIDataControlFailureCode;
613
+ readonly reason: string;
614
+ }
615
+
616
+ export interface AIDataControlRejectedAdmission extends AIDataControlAdmissionBase {
617
+ readonly kind: 'rejected';
618
+ readonly feedback: readonly AIDataControlFeedback[];
619
+ readonly terminal: boolean;
620
+ }
621
+
622
+ export type AIDataControlAdmission =
623
+ | AIDataControlPatchAdmission
624
+ | AIDataControlCompletionAdmission
625
+ | AIDataControlFailureAdmission
626
+ | AIDataControlRejectedAdmission;
627
+
628
+ export interface AIDataControlIterationReceipt {
629
+ readonly schemaVersion: AIDataControlSchemaVersion;
630
+ readonly iteration: number;
631
+ readonly observationId: string;
632
+ readonly observationDigest: string;
633
+ readonly decisionId: string;
634
+ readonly decisionDigest: string;
635
+ readonly admissionKind: AIDataControlAdmission['kind'];
636
+ readonly generationBefore: number;
637
+ readonly generationAfter: number;
638
+ }