ai-workflow-contract 0.1.3 → 0.1.4
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/package.json +3 -3
- package/src/index.ts +234 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-workflow-contract",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared AI workflow contracts over WorkCtrlFlow and EagerDataFlow substrates",
|
|
6
6
|
"type": "module",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
".": "./src/index.ts"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"eager-data-flow-contract": "0.1.
|
|
12
|
+
"eager-data-flow-contract": "0.1.1",
|
|
13
13
|
"halfcode-compiler.xnl": "0.2.2",
|
|
14
|
-
"work-ctrl-flow-contract": "0.1.
|
|
14
|
+
"work-ctrl-flow-contract": "0.1.1"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"src"
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,31 @@ import type {
|
|
|
8
8
|
ResourceValue,
|
|
9
9
|
Sha256Digest,
|
|
10
10
|
} from 'halfcode-compiler.xnl/resource-core';
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
FlowBundleSpec,
|
|
13
|
+
FlowClosedObject,
|
|
14
|
+
FlowClosedValue,
|
|
15
|
+
FlowRunCheckpoint,
|
|
16
|
+
FlowRunCheckpointKey,
|
|
17
|
+
FlowRunCheckpointRuntime as GenericFlowRunCheckpointRuntime,
|
|
18
|
+
WorkCtrlFlowRuntime,
|
|
19
|
+
} from 'work-ctrl-flow-contract';
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
FLOW_INSTANCE_SCHEMA_VERSION,
|
|
23
|
+
FLOW_RUN_CHECKPOINT_SCHEMA_VERSION,
|
|
24
|
+
type FlowClosedArray,
|
|
25
|
+
type FlowClosedObject,
|
|
26
|
+
type FlowClosedPrimitive,
|
|
27
|
+
type FlowClosedValue,
|
|
28
|
+
type FlowDefinitionArtifactIdentity,
|
|
29
|
+
type FlowDefinitionProvenance,
|
|
30
|
+
type FlowInstanceDescriptor,
|
|
31
|
+
type FlowRunCheckpoint,
|
|
32
|
+
type FlowRunCheckpointCommit,
|
|
33
|
+
type FlowRunCheckpointKey,
|
|
34
|
+
type FlowRunCheckpointStore,
|
|
35
|
+
} from 'work-ctrl-flow-contract';
|
|
12
36
|
|
|
13
37
|
export type AIWorkflowKind = 'AICtrlWorkflow' | 'AIDataWorkflow';
|
|
14
38
|
|
|
@@ -221,6 +245,15 @@ export interface AIWorkflowRunResourceFreezeReceipt {
|
|
|
221
245
|
readonly semanticFingerprint: Sha256Digest;
|
|
222
246
|
}
|
|
223
247
|
|
|
248
|
+
/** In-memory proof projected only from an admitted run-resource freeze receipt. */
|
|
249
|
+
export interface FrozenAIAgentTaskBinding {
|
|
250
|
+
readonly schemaVersion: 'ai-workflow.frozen-agent-task-binding/v1';
|
|
251
|
+
readonly task: AIWorkflowAgentTaskRef;
|
|
252
|
+
readonly semanticFingerprint: Sha256Digest;
|
|
253
|
+
readonly snapshotRevision: Sha256Digest;
|
|
254
|
+
readonly closureResourceIds: readonly string[];
|
|
255
|
+
}
|
|
256
|
+
|
|
224
257
|
export type AIWorkflowNodeType =
|
|
225
258
|
| 'agent'
|
|
226
259
|
| 'data'
|
|
@@ -348,6 +381,184 @@ export interface AIWorkflowRunState {
|
|
|
348
381
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
349
382
|
}
|
|
350
383
|
|
|
384
|
+
export interface WorkCtrlFlowRunProfileState<Snapshot = FlowClosedObject> {
|
|
385
|
+
readonly kind: 'WorkCtrlFlow';
|
|
386
|
+
readonly snapshot: Snapshot;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export const AI_AGENT_CHECKPOINT_STATE_SCHEMA_VERSION = 'depa.ai-agent-state/v1' as const;
|
|
390
|
+
|
|
391
|
+
/** Opaque identity owned by an external agent/runtime authority. */
|
|
392
|
+
export interface AIWorkflowExternalRuntimeReference {
|
|
393
|
+
readonly authority: string;
|
|
394
|
+
readonly instanceId: string;
|
|
395
|
+
readonly instanceName?: string;
|
|
396
|
+
readonly sessionId?: string;
|
|
397
|
+
readonly agentDefinitionRef?: `resource://${string}`;
|
|
398
|
+
readonly metadata?: FlowClosedObject;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Audit linkage without copying external conversation or execution history. */
|
|
402
|
+
export interface AIWorkflowExecutionReceipt {
|
|
403
|
+
readonly nodeId: string;
|
|
404
|
+
readonly externalRuntimeRef: string;
|
|
405
|
+
readonly metadata?: FlowClosedObject;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export type AIAgentSelector =
|
|
409
|
+
| { readonly byInstanceId: string; readonly byInstanceName?: never }
|
|
410
|
+
| { readonly byInstanceName: string; readonly byInstanceId?: never };
|
|
411
|
+
|
|
412
|
+
export interface AIAgentInvocation<Input extends FlowClosedValue = FlowClosedValue> {
|
|
413
|
+
readonly kind: 'ai.agent';
|
|
414
|
+
readonly payload: Input;
|
|
415
|
+
readonly metadata?: FlowClosedObject;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export interface AIAgentEffectConfig {
|
|
419
|
+
readonly agentDefinitionRef: `resource://${string}`;
|
|
420
|
+
readonly instanceName?: string;
|
|
421
|
+
readonly materialRefs?: readonly string[];
|
|
422
|
+
readonly effectPolicy?: FlowClosedObject;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface AIAgentInstanceReference {
|
|
426
|
+
readonly authority: string;
|
|
427
|
+
readonly instanceId: string;
|
|
428
|
+
readonly instanceName?: string;
|
|
429
|
+
readonly sessionId?: string;
|
|
430
|
+
readonly agentDefinitionRef: `resource://${string}`;
|
|
431
|
+
readonly metadata?: FlowClosedObject;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface AIAgentInvocationReceipt {
|
|
435
|
+
readonly invocationKey: string;
|
|
436
|
+
readonly nodeId: string;
|
|
437
|
+
readonly status: 'pending' | 'completed';
|
|
438
|
+
readonly mode: 'new' | 'targeted';
|
|
439
|
+
readonly agentDefinitionRef: `resource://${string}`;
|
|
440
|
+
readonly instanceName?: string;
|
|
441
|
+
readonly instanceId?: string;
|
|
442
|
+
readonly generation?: number;
|
|
443
|
+
readonly input: FlowClosedValue;
|
|
444
|
+
/** Exact static/invocation semantics bound to this idempotency key. */
|
|
445
|
+
readonly semanticFacts: FlowClosedObject;
|
|
446
|
+
readonly metadata?: FlowClosedObject;
|
|
447
|
+
readonly output?: FlowClosedValue;
|
|
448
|
+
readonly hostReceipt?: FlowClosedObject;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface AIAgentRunResult<Output extends FlowClosedValue = FlowClosedValue> {
|
|
452
|
+
readonly output: Output;
|
|
453
|
+
readonly instance: AIAgentInstanceReference;
|
|
454
|
+
readonly receipt: {
|
|
455
|
+
readonly invocationKey: string;
|
|
456
|
+
readonly nodeId: string;
|
|
457
|
+
readonly status: 'pending' | 'completed';
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export interface AIAgentHostRunRequest<Input extends FlowClosedValue = FlowClosedValue> {
|
|
462
|
+
readonly invocationKey: string;
|
|
463
|
+
readonly flowInstanceId: string;
|
|
464
|
+
readonly runId: string;
|
|
465
|
+
readonly nodeId: string;
|
|
466
|
+
readonly generation?: number;
|
|
467
|
+
readonly input: Input;
|
|
468
|
+
readonly agentDefinitionRef: `resource://${string}`;
|
|
469
|
+
readonly instanceName?: string;
|
|
470
|
+
readonly materialRefs?: readonly string[];
|
|
471
|
+
readonly effectPolicy?: FlowClosedObject;
|
|
472
|
+
readonly signal?: AbortSignal;
|
|
473
|
+
readonly metadata?: FlowClosedObject;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export interface AIAgentHostTargetedRunRequest<Input extends FlowClosedValue = FlowClosedValue>
|
|
477
|
+
extends AIAgentHostRunRequest<Input> {
|
|
478
|
+
readonly instance: AIAgentInstanceReference;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface AIAgentHostRunResult<Output extends FlowClosedValue = FlowClosedValue> {
|
|
482
|
+
readonly output: Output;
|
|
483
|
+
readonly instance: Omit<AIAgentInstanceReference, 'agentDefinitionRef'> & {
|
|
484
|
+
readonly agentDefinitionRef?: `resource://${string}`;
|
|
485
|
+
};
|
|
486
|
+
readonly hostReceipt?: FlowClosedObject;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Host-owned typed effect boundary. It is deliberately not a generic dispatcher. */
|
|
490
|
+
export interface AIAgentHostEffectPort {
|
|
491
|
+
runAgent(request: AIAgentHostRunRequest): Promise<AIAgentHostRunResult>;
|
|
492
|
+
runTargetedAgent(request: AIAgentHostTargetedRunRequest): Promise<AIAgentHostRunResult>;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export interface AIAgentProcessorRuntime {
|
|
496
|
+
readonly checkpointRuntime: FlowRunCheckpointRuntime;
|
|
497
|
+
readonly checkpointKey: FlowRunCheckpointKey;
|
|
498
|
+
readonly nodeId: string;
|
|
499
|
+
readonly invocationKey: string;
|
|
500
|
+
readonly workflowKind: AIWorkflowDefinitionResourceKind;
|
|
501
|
+
readonly workflowRef: `resource://${string}`;
|
|
502
|
+
readonly taskBinding: AIWorkflowAgentTaskRef;
|
|
503
|
+
readonly generation?: number;
|
|
504
|
+
readonly effects: AIAgentHostEffectPort;
|
|
505
|
+
readonly signal?: AbortSignal;
|
|
506
|
+
readonly metadata?: FlowClosedObject;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export interface AIWorkflowAuthoredEffects {
|
|
510
|
+
runAgent<Input extends FlowClosedValue = FlowClosedValue, Output extends FlowClosedValue = FlowClosedValue>(
|
|
511
|
+
input: Input,
|
|
512
|
+
config: AIAgentEffectConfig,
|
|
513
|
+
): Promise<AIAgentRunResult<Output>>;
|
|
514
|
+
runTargetedAgent<Input extends FlowClosedValue = FlowClosedValue, Output extends FlowClosedValue = FlowClosedValue>(
|
|
515
|
+
selector: AIAgentSelector,
|
|
516
|
+
invocation: AIAgentInvocation<Input>,
|
|
517
|
+
config: AIAgentEffectConfig,
|
|
518
|
+
): Promise<AIAgentRunResult<Output>>;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** Closed durable AI profile state stored inside the Flow checkpoint owner. */
|
|
522
|
+
export interface AIWorkflowProfileDurableState {
|
|
523
|
+
readonly schemaVersion: typeof AI_AGENT_CHECKPOINT_STATE_SCHEMA_VERSION;
|
|
524
|
+
readonly instancesById: Readonly<Record<string, AIAgentInstanceReference>>;
|
|
525
|
+
readonly instanceIdByName: Readonly<Record<string, string>>;
|
|
526
|
+
readonly invocationsByKey: Readonly<Record<string, AIAgentInvocationReceipt>>;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Explicit read-only input accepted only by the one-way legacy upgrade helper. */
|
|
530
|
+
export interface LegacyAIWorkflowProfileDurableState {
|
|
531
|
+
readonly externalRuntimeRefs: Readonly<Record<string, AIWorkflowExternalRuntimeReference>>;
|
|
532
|
+
readonly receipts: readonly AIWorkflowExecutionReceipt[];
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export interface AICtrlWorkflowRunProfileState<
|
|
536
|
+
Snapshot = FlowClosedObject,
|
|
537
|
+
AIState = AIWorkflowProfileDurableState,
|
|
538
|
+
> {
|
|
539
|
+
readonly kind: 'AICtrlWorkflow';
|
|
540
|
+
readonly snapshot: Snapshot;
|
|
541
|
+
readonly ai: AIState;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export interface AIDataWorkflowRunProfileState<
|
|
545
|
+
RunGraph = FlowClosedObject,
|
|
546
|
+
AIState = AIWorkflowProfileDurableState,
|
|
547
|
+
> {
|
|
548
|
+
readonly kind: 'AIDataWorkflow';
|
|
549
|
+
readonly runGraph: RunGraph;
|
|
550
|
+
readonly ai: AIState;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export type FlowRunProfileState =
|
|
554
|
+
| WorkCtrlFlowRunProfileState
|
|
555
|
+
| AICtrlWorkflowRunProfileState
|
|
556
|
+
| AIDataWorkflowRunProfileState;
|
|
557
|
+
|
|
558
|
+
export type AIWorkflowFlowRunCheckpoint = FlowRunCheckpoint<FlowRunProfileState>;
|
|
559
|
+
|
|
560
|
+
export type FlowRunCheckpointRuntime = GenericFlowRunCheckpointRuntime<FlowRunProfileState>;
|
|
561
|
+
|
|
351
562
|
export interface AIWorkflowReusableNodeResultRequest {
|
|
352
563
|
readonly run: AIWorkflowRunRef;
|
|
353
564
|
readonly nodeId: string;
|
|
@@ -356,15 +567,23 @@ export interface AIWorkflowReusableNodeResultRequest {
|
|
|
356
567
|
readonly policy: AIWorkflowEffectiveReusePolicy;
|
|
357
568
|
}
|
|
358
569
|
|
|
359
|
-
|
|
570
|
+
/** Read-only, rebuildable view over canonical FlowRunCheckpoint facts. */
|
|
571
|
+
export interface AIWorkflowStateProjection {
|
|
360
572
|
loadRunState(ref: AIWorkflowRunRef): Promise<AIWorkflowRunState | undefined>;
|
|
361
|
-
saveRunState(state: AIWorkflowRunState): Promise<void>;
|
|
362
|
-
appendRunEvent(ref: AIWorkflowRunRef, event: AIWorkflowRunEvent): Promise<void>;
|
|
363
573
|
findReusableNodeResult?(
|
|
364
574
|
request: AIWorkflowReusableNodeResultRequest,
|
|
365
575
|
): Promise<AIWorkflowNodeResult | undefined>;
|
|
366
576
|
}
|
|
367
577
|
|
|
578
|
+
/**
|
|
579
|
+
* @deprecated Writable legacy/derived projection compatibility only. Canonical
|
|
580
|
+
* Ctrl/Data execution writes exclusively through FlowRunCheckpointStore.
|
|
581
|
+
*/
|
|
582
|
+
export interface AIWorkflowStateStore extends AIWorkflowStateProjection {
|
|
583
|
+
saveRunState(state: AIWorkflowRunState): Promise<void>;
|
|
584
|
+
appendRunEvent(ref: AIWorkflowRunRef, event: AIWorkflowRunEvent): Promise<void>;
|
|
585
|
+
}
|
|
586
|
+
|
|
368
587
|
export interface AIWorkflowEffectRequest<Input = unknown> {
|
|
369
588
|
readonly effectId: string;
|
|
370
589
|
readonly operation: string;
|
|
@@ -420,25 +639,30 @@ export interface AIWorkflowEffectResult<Output = unknown> {
|
|
|
420
639
|
}
|
|
421
640
|
|
|
422
641
|
export interface AIWorkflowRuntimeContext<
|
|
423
|
-
Effects extends AIWorkflowEffectProvider = AIWorkflowEffectProvider,
|
|
424
|
-
Store extends
|
|
642
|
+
Effects extends AIWorkflowEffectProvider | AIWorkflowAuthoredEffects = AIWorkflowEffectProvider,
|
|
643
|
+
Store extends AIWorkflowStateProjection = AIWorkflowStateProjection,
|
|
425
644
|
> {
|
|
426
645
|
readonly roots: AIWorkflowRuntimeRoots;
|
|
427
646
|
readonly effects: Effects;
|
|
647
|
+
/** Historical field name; canonical runtimes expose a read-only projection here. */
|
|
428
648
|
readonly stateStore: Store;
|
|
429
649
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
430
650
|
}
|
|
431
651
|
|
|
652
|
+
/** Authored code surface; generic infrastructure dispatch is intentionally absent. */
|
|
653
|
+
export type AIWorkflowAuthoredRuntimeContext<Store extends AIWorkflowStateProjection = AIWorkflowStateProjection> =
|
|
654
|
+
AIWorkflowRuntimeContext<AIWorkflowAuthoredEffects, Store>;
|
|
655
|
+
|
|
432
656
|
export interface AICtrlWorkflowRuntime<
|
|
433
|
-
Effects extends AIWorkflowEffectProvider = AIWorkflowEffectProvider,
|
|
434
|
-
Store extends
|
|
657
|
+
Effects extends AIWorkflowEffectProvider | AIWorkflowAuthoredEffects = AIWorkflowEffectProvider,
|
|
658
|
+
Store extends AIWorkflowStateProjection = AIWorkflowStateProjection,
|
|
435
659
|
> extends WorkCtrlFlowRuntime {
|
|
436
660
|
readonly ai: AIWorkflowRuntimeContext<Effects, Store>;
|
|
437
661
|
}
|
|
438
662
|
|
|
439
663
|
export interface AIDataWorkflowRuntime<
|
|
440
|
-
Effects extends AIWorkflowEffectProvider = AIWorkflowEffectProvider,
|
|
441
|
-
Store extends
|
|
664
|
+
Effects extends AIWorkflowEffectProvider | AIWorkflowAuthoredEffects = AIWorkflowEffectProvider,
|
|
665
|
+
Store extends AIWorkflowStateProjection = AIWorkflowStateProjection,
|
|
442
666
|
> {
|
|
443
667
|
readonly ai: AIWorkflowRuntimeContext<Effects, Store>;
|
|
444
668
|
}
|