ai-workflow-contract 0.1.2 → 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 +4 -5
- package/src/index.ts +257 -16
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,15 +9,14 @@
|
|
|
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"
|
|
18
18
|
],
|
|
19
19
|
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
21
|
-
"registry": "https://registry.npmjs.com"
|
|
20
|
+
"access": "public"
|
|
22
21
|
}
|
|
23
22
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,9 +5,34 @@ import type {
|
|
|
5
5
|
ResourceRecord,
|
|
6
6
|
ResourceRegistry,
|
|
7
7
|
ResourceTree,
|
|
8
|
+
ResourceValue,
|
|
8
9
|
Sha256Digest,
|
|
9
10
|
} from 'halfcode-compiler.xnl/resource-core';
|
|
10
|
-
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';
|
|
11
36
|
|
|
12
37
|
export type AIWorkflowKind = 'AICtrlWorkflow' | 'AIDataWorkflow';
|
|
13
38
|
|
|
@@ -144,11 +169,27 @@ export interface AIWorkflowTypedResourceRef {
|
|
|
144
169
|
readonly resource: ResourceRecord;
|
|
145
170
|
}
|
|
146
171
|
|
|
172
|
+
export interface AIWorkflowMessageSchemaProjection extends AIWorkflowTypedResourceRef {
|
|
173
|
+
readonly kind: 'MessageSchema';
|
|
174
|
+
readonly schema: Readonly<Record<string, ResourceValue>>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type AIWorkflowEffectToolMode = 'declared-only' | 'none';
|
|
178
|
+
|
|
179
|
+
export interface AIWorkflowEffectPolicyProjection extends AIWorkflowTypedResourceRef {
|
|
180
|
+
readonly kind: 'EffectPolicy';
|
|
181
|
+
readonly toolMode: AIWorkflowEffectToolMode;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface AIWorkflowMaterialValueProjection extends AIWorkflowTypedResourceRef {
|
|
185
|
+
readonly value: ResourceValue;
|
|
186
|
+
}
|
|
187
|
+
|
|
147
188
|
export interface AIAgentMessageProjection {
|
|
148
189
|
readonly id: string;
|
|
149
190
|
readonly role: AIAgentMessageRole;
|
|
150
191
|
readonly prompt: AIWorkflowTypedResourceRef;
|
|
151
|
-
readonly schema?:
|
|
192
|
+
readonly schema?: AIWorkflowMessageSchemaProjection;
|
|
152
193
|
}
|
|
153
194
|
|
|
154
195
|
export interface MaterialPortProjection {
|
|
@@ -158,7 +199,7 @@ export interface MaterialPortProjection {
|
|
|
158
199
|
readonly materialKind: string;
|
|
159
200
|
readonly required: boolean;
|
|
160
201
|
readonly cardinality: MaterialCardinality;
|
|
161
|
-
readonly schema?:
|
|
202
|
+
readonly schema?: AIWorkflowMessageSchemaProjection;
|
|
162
203
|
}
|
|
163
204
|
|
|
164
205
|
export interface AIAgentDefinitionProjection {
|
|
@@ -166,10 +207,10 @@ export interface AIAgentDefinitionProjection {
|
|
|
166
207
|
readonly fqn: string;
|
|
167
208
|
readonly resource: ResourceRecord;
|
|
168
209
|
readonly messages: readonly AIAgentMessageProjection[];
|
|
169
|
-
readonly inputSchema?:
|
|
170
|
-
readonly outputSchema?:
|
|
210
|
+
readonly inputSchema?: AIWorkflowMessageSchemaProjection;
|
|
211
|
+
readonly outputSchema?: AIWorkflowMessageSchemaProjection;
|
|
171
212
|
readonly tools: readonly AIWorkflowTypedResourceRef[];
|
|
172
|
-
readonly effectPolicy?:
|
|
213
|
+
readonly effectPolicy?: AIWorkflowEffectPolicyProjection;
|
|
173
214
|
readonly materialPorts: readonly AIWorkflowTypedResourceRef[];
|
|
174
215
|
}
|
|
175
216
|
|
|
@@ -186,7 +227,7 @@ export interface MaterialBindingProjection {
|
|
|
186
227
|
readonly resource: ResourceRecord;
|
|
187
228
|
readonly task: AIWorkflowAgentTaskRef;
|
|
188
229
|
readonly port: MaterialPortProjection;
|
|
189
|
-
readonly material:
|
|
230
|
+
readonly material: AIWorkflowMaterialValueProjection;
|
|
190
231
|
}
|
|
191
232
|
|
|
192
233
|
export interface AIWorkflowAgentResourceProjection {
|
|
@@ -204,6 +245,15 @@ export interface AIWorkflowRunResourceFreezeReceipt {
|
|
|
204
245
|
readonly semanticFingerprint: Sha256Digest;
|
|
205
246
|
}
|
|
206
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
|
+
|
|
207
257
|
export type AIWorkflowNodeType =
|
|
208
258
|
| 'agent'
|
|
209
259
|
| 'data'
|
|
@@ -331,6 +381,184 @@ export interface AIWorkflowRunState {
|
|
|
331
381
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
332
382
|
}
|
|
333
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
|
+
|
|
334
562
|
export interface AIWorkflowReusableNodeResultRequest {
|
|
335
563
|
readonly run: AIWorkflowRunRef;
|
|
336
564
|
readonly nodeId: string;
|
|
@@ -339,15 +567,23 @@ export interface AIWorkflowReusableNodeResultRequest {
|
|
|
339
567
|
readonly policy: AIWorkflowEffectiveReusePolicy;
|
|
340
568
|
}
|
|
341
569
|
|
|
342
|
-
|
|
570
|
+
/** Read-only, rebuildable view over canonical FlowRunCheckpoint facts. */
|
|
571
|
+
export interface AIWorkflowStateProjection {
|
|
343
572
|
loadRunState(ref: AIWorkflowRunRef): Promise<AIWorkflowRunState | undefined>;
|
|
344
|
-
saveRunState(state: AIWorkflowRunState): Promise<void>;
|
|
345
|
-
appendRunEvent(ref: AIWorkflowRunRef, event: AIWorkflowRunEvent): Promise<void>;
|
|
346
573
|
findReusableNodeResult?(
|
|
347
574
|
request: AIWorkflowReusableNodeResultRequest,
|
|
348
575
|
): Promise<AIWorkflowNodeResult | undefined>;
|
|
349
576
|
}
|
|
350
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
|
+
|
|
351
587
|
export interface AIWorkflowEffectRequest<Input = unknown> {
|
|
352
588
|
readonly effectId: string;
|
|
353
589
|
readonly operation: string;
|
|
@@ -403,25 +639,30 @@ export interface AIWorkflowEffectResult<Output = unknown> {
|
|
|
403
639
|
}
|
|
404
640
|
|
|
405
641
|
export interface AIWorkflowRuntimeContext<
|
|
406
|
-
Effects extends AIWorkflowEffectProvider = AIWorkflowEffectProvider,
|
|
407
|
-
Store extends
|
|
642
|
+
Effects extends AIWorkflowEffectProvider | AIWorkflowAuthoredEffects = AIWorkflowEffectProvider,
|
|
643
|
+
Store extends AIWorkflowStateProjection = AIWorkflowStateProjection,
|
|
408
644
|
> {
|
|
409
645
|
readonly roots: AIWorkflowRuntimeRoots;
|
|
410
646
|
readonly effects: Effects;
|
|
647
|
+
/** Historical field name; canonical runtimes expose a read-only projection here. */
|
|
411
648
|
readonly stateStore: Store;
|
|
412
649
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
413
650
|
}
|
|
414
651
|
|
|
652
|
+
/** Authored code surface; generic infrastructure dispatch is intentionally absent. */
|
|
653
|
+
export type AIWorkflowAuthoredRuntimeContext<Store extends AIWorkflowStateProjection = AIWorkflowStateProjection> =
|
|
654
|
+
AIWorkflowRuntimeContext<AIWorkflowAuthoredEffects, Store>;
|
|
655
|
+
|
|
415
656
|
export interface AICtrlWorkflowRuntime<
|
|
416
|
-
Effects extends AIWorkflowEffectProvider = AIWorkflowEffectProvider,
|
|
417
|
-
Store extends
|
|
657
|
+
Effects extends AIWorkflowEffectProvider | AIWorkflowAuthoredEffects = AIWorkflowEffectProvider,
|
|
658
|
+
Store extends AIWorkflowStateProjection = AIWorkflowStateProjection,
|
|
418
659
|
> extends WorkCtrlFlowRuntime {
|
|
419
660
|
readonly ai: AIWorkflowRuntimeContext<Effects, Store>;
|
|
420
661
|
}
|
|
421
662
|
|
|
422
663
|
export interface AIDataWorkflowRuntime<
|
|
423
|
-
Effects extends AIWorkflowEffectProvider = AIWorkflowEffectProvider,
|
|
424
|
-
Store extends
|
|
664
|
+
Effects extends AIWorkflowEffectProvider | AIWorkflowAuthoredEffects = AIWorkflowEffectProvider,
|
|
665
|
+
Store extends AIWorkflowStateProjection = AIWorkflowStateProjection,
|
|
425
666
|
> {
|
|
426
667
|
readonly ai: AIWorkflowRuntimeContext<Effects, Store>;
|
|
427
668
|
}
|