ai-workflow-logic 0.1.3 → 0.1.5
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 +8 -3
- package/src/agent-invocation.ts +282 -0
- package/src/agent-state.ts +293 -0
- package/src/checkpoint-filesystem.ts +1273 -0
- package/src/checkpoint-sidecar.ts +419 -0
- package/src/checkpoint-store.ts +601 -0
- package/src/index.ts +34 -4
- package/src/run-checkpoint.ts +1666 -0
- package/src/run-freeze.ts +57 -1
package/src/run-freeze.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AIAgentDefinitionProjection,
|
|
3
|
+
FrozenAIAgentTaskBinding,
|
|
3
4
|
AIWorkflowAgentResourceProjection,
|
|
4
5
|
AIWorkflowAgentTaskRef,
|
|
5
6
|
AIWorkflowResourceProjectionDiagnostic,
|
|
@@ -9,11 +10,15 @@ import type {
|
|
|
9
10
|
} from 'ai-workflow-contract';
|
|
10
11
|
import {
|
|
11
12
|
buildResourceDependencySnapshot,
|
|
13
|
+
composeLayeredResourceRegistry,
|
|
14
|
+
loadResourceTree,
|
|
15
|
+
resolveEffectiveResourceContentIdentities,
|
|
12
16
|
sha256Digest,
|
|
13
17
|
type EffectiveResourceRegistry,
|
|
14
18
|
type ResourceContentIdentity,
|
|
15
19
|
type ResourceDependencyEdge,
|
|
16
20
|
} from 'halfcode-compiler.xnl/resource-core';
|
|
21
|
+
import { projectAIWorkflowAgentResources } from './agent-resources.js';
|
|
17
22
|
import { sourceRegistryForAIWorkflowAgentResourceProjection } from './agent-resource-brand.js';
|
|
18
23
|
|
|
19
24
|
export interface FreezeAIWorkflowRunResourcesInput {
|
|
@@ -23,6 +28,22 @@ export interface FreezeAIWorkflowRunResourcesInput {
|
|
|
23
28
|
readonly contentIdentities: ReadonlyMap<string, ResourceContentIdentity>;
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
/** Filesystem adapter that builds an authentic receipt from one complete resource package. */
|
|
32
|
+
export async function freezeAIWorkflowRunResourcesFromDirectory(
|
|
33
|
+
rootDir: string,
|
|
34
|
+
task: AIWorkflowAgentTaskRef,
|
|
35
|
+
): Promise<AIWorkflowRunResourceFreezeReceipt> {
|
|
36
|
+
const tree = await loadResourceTree({ rootDir });
|
|
37
|
+
const layers = [{ id: 'workspace', tree }] as const;
|
|
38
|
+
const registry = composeLayeredResourceRegistry({ layers });
|
|
39
|
+
return freezeAIWorkflowRunResources({
|
|
40
|
+
registry,
|
|
41
|
+
projection: projectAIWorkflowAgentResources(registry),
|
|
42
|
+
task,
|
|
43
|
+
contentIdentities: resolveEffectiveResourceContentIdentities({ registry, layers }),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
26
47
|
export class AIWorkflowRunResourceFreezeError extends Error {
|
|
27
48
|
constructor(public readonly diagnostics: readonly AIWorkflowResourceProjectionDiagnostic[]) {
|
|
28
49
|
super(`AI workflow run resource freeze failed with ${diagnostics.length} diagnostic(s)`);
|
|
@@ -30,6 +51,9 @@ export class AIWorkflowRunResourceFreezeError extends Error {
|
|
|
30
51
|
}
|
|
31
52
|
}
|
|
32
53
|
|
|
54
|
+
const authenticFreezeReceipts = new WeakSet<object>();
|
|
55
|
+
const authenticTaskBindings = new WeakSet<object>();
|
|
56
|
+
|
|
33
57
|
export function freezeAIWorkflowRunResources(
|
|
34
58
|
input: FreezeAIWorkflowRunResourcesInput,
|
|
35
59
|
): AIWorkflowRunResourceFreezeReceipt {
|
|
@@ -85,13 +109,45 @@ export function freezeAIWorkflowRunResources(
|
|
|
85
109
|
dependencySnapshot.closure,
|
|
86
110
|
dependencySnapshot.edges,
|
|
87
111
|
);
|
|
88
|
-
|
|
112
|
+
const receipt = Object.freeze({
|
|
89
113
|
schemaVersion: 'ai-workflow.run-resource-freeze/v1',
|
|
90
114
|
task: frozenTask,
|
|
91
115
|
bindingResourceIds,
|
|
92
116
|
dependencySnapshot,
|
|
93
117
|
semanticFingerprint,
|
|
94
118
|
});
|
|
119
|
+
authenticFreezeReceipts.add(receipt);
|
|
120
|
+
return receipt;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Projects a dispatch proof only from the exact receipt produced by this run-freeze boundary. */
|
|
124
|
+
export function projectFrozenAIAgentTaskBinding(
|
|
125
|
+
receipt: AIWorkflowRunResourceFreezeReceipt,
|
|
126
|
+
): FrozenAIAgentTaskBinding {
|
|
127
|
+
if (!authenticFreezeReceipts.has(receipt as object)) {
|
|
128
|
+
throw new AIWorkflowRunResourceFreezeError(Object.freeze([
|
|
129
|
+
diagnostic('AI_RUN_RESOURCE_FREEZE_RECEIPT_UNTRUSTED', 'run-freeze:receipt', 'Task proof requires the authentic receipt produced by run freeze.'),
|
|
130
|
+
]));
|
|
131
|
+
}
|
|
132
|
+
const binding = Object.freeze({
|
|
133
|
+
schemaVersion: 'ai-workflow.frozen-agent-task-binding/v1' as const,
|
|
134
|
+
task: receipt.task,
|
|
135
|
+
semanticFingerprint: receipt.semanticFingerprint,
|
|
136
|
+
snapshotRevision: receipt.dependencySnapshot.snapshotRevision,
|
|
137
|
+
closureResourceIds: Object.freeze(receipt.dependencySnapshot.closure.map((item) => item.resourceId)),
|
|
138
|
+
});
|
|
139
|
+
authenticTaskBindings.add(binding);
|
|
140
|
+
return binding;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Runtime assertion; a structurally similar literal is not an admitted authority. */
|
|
144
|
+
export function assertFrozenAIAgentTaskBinding(value: FrozenAIAgentTaskBinding): FrozenAIAgentTaskBinding {
|
|
145
|
+
if (!authenticTaskBindings.has(value as object)) {
|
|
146
|
+
throw new AIWorkflowRunResourceFreezeError(Object.freeze([
|
|
147
|
+
diagnostic('AI_RUN_AGENT_TASK_PROOF_UNTRUSTED', 'run-freeze:task-proof', 'Agent task binding was not projected from an authentic run-freeze receipt.'),
|
|
148
|
+
]));
|
|
149
|
+
}
|
|
150
|
+
return value;
|
|
95
151
|
}
|
|
96
152
|
|
|
97
153
|
function validateAndOrderBindings(
|