@exaudeus/workrail 1.9.0 → 1.10.0
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/dist/application/services/compiler/feature-registry.d.ts +19 -0
- package/dist/application/services/compiler/feature-registry.js +37 -0
- package/dist/application/services/compiler/resolve-features.d.ts +12 -0
- package/dist/application/services/compiler/resolve-features.js +65 -0
- package/dist/application/services/workflow-compiler.d.ts +1 -0
- package/dist/application/services/workflow-compiler.js +12 -1
- package/dist/manifest.json +22 -6
- package/dist/types/workflow-definition.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Result } from 'neverthrow';
|
|
2
|
+
import type { PromptValue } from './prompt-blocks.js';
|
|
3
|
+
export interface FeatureDefinition {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly constraints?: readonly PromptValue[];
|
|
6
|
+
readonly procedure?: readonly PromptValue[];
|
|
7
|
+
readonly verify?: readonly PromptValue[];
|
|
8
|
+
}
|
|
9
|
+
export type FeatureResolveError = {
|
|
10
|
+
readonly code: 'UNKNOWN_FEATURE';
|
|
11
|
+
readonly featureId: string;
|
|
12
|
+
readonly message: string;
|
|
13
|
+
};
|
|
14
|
+
export interface FeatureRegistry {
|
|
15
|
+
readonly resolve: (featureId: string) => Result<FeatureDefinition, FeatureResolveError>;
|
|
16
|
+
readonly has: (featureId: string) => boolean;
|
|
17
|
+
readonly knownIds: () => readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export declare function createFeatureRegistry(): FeatureRegistry;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFeatureRegistry = createFeatureRegistry;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
const FEATURE_DEFINITIONS = [
|
|
6
|
+
{
|
|
7
|
+
id: 'wr.features.memory_context',
|
|
8
|
+
constraints: [
|
|
9
|
+
[
|
|
10
|
+
{ kind: 'ref', refId: 'wr.refs.memory_usage' },
|
|
11
|
+
],
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
function createFeatureRegistry() {
|
|
16
|
+
const byId = new Map(FEATURE_DEFINITIONS.map(f => [f.id, f]));
|
|
17
|
+
const knownIds = FEATURE_DEFINITIONS.map(f => f.id);
|
|
18
|
+
return {
|
|
19
|
+
resolve(featureId) {
|
|
20
|
+
const def = byId.get(featureId);
|
|
21
|
+
if (!def) {
|
|
22
|
+
return (0, neverthrow_1.err)({
|
|
23
|
+
code: 'UNKNOWN_FEATURE',
|
|
24
|
+
featureId,
|
|
25
|
+
message: `Unknown feature '${featureId}'. Known features: ${knownIds.join(', ')}`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return (0, neverthrow_1.ok)(def);
|
|
29
|
+
},
|
|
30
|
+
has(featureId) {
|
|
31
|
+
return byId.has(featureId);
|
|
32
|
+
},
|
|
33
|
+
knownIds() {
|
|
34
|
+
return knownIds;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Result } from 'neverthrow';
|
|
2
|
+
import type { FeatureRegistry, FeatureResolveError } from './feature-registry.js';
|
|
3
|
+
import type { WorkflowStepDefinition, LoopStepDefinition } from '../../../types/workflow-definition.js';
|
|
4
|
+
export type ResolveFeaturesPassError = {
|
|
5
|
+
readonly code: 'FEATURE_RESOLVE_ERROR';
|
|
6
|
+
readonly cause: FeatureResolveError;
|
|
7
|
+
} | {
|
|
8
|
+
readonly code: 'FEATURE_ON_RAW_PROMPT_STEP';
|
|
9
|
+
readonly stepId: string;
|
|
10
|
+
readonly message: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function resolveFeaturesPass(steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[], featureIds: readonly string[], registry: FeatureRegistry): Result<readonly (WorkflowStepDefinition | LoopStepDefinition)[], ResolveFeaturesPassError>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveFeaturesPass = resolveFeaturesPass;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
const workflow_definition_js_1 = require("../../../types/workflow-definition.js");
|
|
6
|
+
function appendValues(existing, injected) {
|
|
7
|
+
if (!injected || injected.length === 0)
|
|
8
|
+
return existing;
|
|
9
|
+
if (!existing || existing.length === 0)
|
|
10
|
+
return injected;
|
|
11
|
+
return [...existing, ...injected];
|
|
12
|
+
}
|
|
13
|
+
function applyFeatureToBlocks(blocks, feature) {
|
|
14
|
+
return {
|
|
15
|
+
...blocks,
|
|
16
|
+
constraints: appendValues(blocks.constraints, feature.constraints),
|
|
17
|
+
procedure: appendValues(blocks.procedure, feature.procedure),
|
|
18
|
+
verify: appendValues(blocks.verify, feature.verify),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function applyFeaturesToStep(step, features) {
|
|
22
|
+
if (!step.promptBlocks || features.length === 0)
|
|
23
|
+
return step;
|
|
24
|
+
let blocks = step.promptBlocks;
|
|
25
|
+
for (const feature of features) {
|
|
26
|
+
blocks = applyFeatureToBlocks(blocks, feature);
|
|
27
|
+
}
|
|
28
|
+
return { ...step, promptBlocks: blocks };
|
|
29
|
+
}
|
|
30
|
+
function resolveFeaturesPass(steps, featureIds, registry) {
|
|
31
|
+
if (featureIds.length === 0)
|
|
32
|
+
return (0, neverthrow_1.ok)(steps);
|
|
33
|
+
const features = [];
|
|
34
|
+
for (const id of featureIds) {
|
|
35
|
+
const res = registry.resolve(id);
|
|
36
|
+
if (res.isErr()) {
|
|
37
|
+
return (0, neverthrow_1.err)({ code: 'FEATURE_RESOLVE_ERROR', cause: res.error });
|
|
38
|
+
}
|
|
39
|
+
features.push(res.value);
|
|
40
|
+
}
|
|
41
|
+
const resolved = [];
|
|
42
|
+
for (const step of steps) {
|
|
43
|
+
if ((0, workflow_definition_js_1.isLoopStepDefinition)(step)) {
|
|
44
|
+
const resolvedLoop = applyFeaturesToStep(step, features);
|
|
45
|
+
if (Array.isArray(step.body)) {
|
|
46
|
+
const bodyResolved = step.body.map(bodyStep => applyFeaturesToStep(bodyStep, features));
|
|
47
|
+
resolved.push({
|
|
48
|
+
...step,
|
|
49
|
+
...(resolvedLoop.promptBlocks ? { promptBlocks: resolvedLoop.promptBlocks } : {}),
|
|
50
|
+
body: bodyResolved,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
resolved.push({
|
|
55
|
+
...step,
|
|
56
|
+
...(resolvedLoop.promptBlocks ? { promptBlocks: resolvedLoop.promptBlocks } : {}),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
resolved.push(applyFeaturesToStep(step, features));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return (0, neverthrow_1.ok)(resolved);
|
|
65
|
+
}
|
|
@@ -16,6 +16,7 @@ export interface CompiledWorkflow {
|
|
|
16
16
|
}
|
|
17
17
|
export declare class WorkflowCompiler {
|
|
18
18
|
private readonly refRegistry;
|
|
19
|
+
private readonly featureRegistry;
|
|
19
20
|
compile(workflow: Workflow): Result<CompiledWorkflow, DomainError>;
|
|
20
21
|
private deriveConditionSource;
|
|
21
22
|
private resolveLoopBody;
|
|
@@ -15,12 +15,23 @@ const error_1 = require("../../domain/execution/error");
|
|
|
15
15
|
const prompt_blocks_1 = require("./compiler/prompt-blocks");
|
|
16
16
|
const resolve_refs_1 = require("./compiler/resolve-refs");
|
|
17
17
|
const ref_registry_1 = require("./compiler/ref-registry");
|
|
18
|
+
const resolve_features_1 = require("./compiler/resolve-features");
|
|
19
|
+
const feature_registry_1 = require("./compiler/feature-registry");
|
|
18
20
|
let WorkflowCompiler = class WorkflowCompiler {
|
|
19
21
|
constructor() {
|
|
20
22
|
this.refRegistry = (0, ref_registry_1.createRefRegistry)();
|
|
23
|
+
this.featureRegistry = (0, feature_registry_1.createFeatureRegistry)();
|
|
21
24
|
}
|
|
22
25
|
compile(workflow) {
|
|
23
|
-
const
|
|
26
|
+
const featuresResult = (0, resolve_features_1.resolveFeaturesPass)(workflow.definition.steps, workflow.definition.features ?? [], this.featureRegistry);
|
|
27
|
+
if (featuresResult.isErr()) {
|
|
28
|
+
const e = featuresResult.error;
|
|
29
|
+
const message = e.code === 'FEATURE_RESOLVE_ERROR'
|
|
30
|
+
? `Feature error — ${e.cause.message}`
|
|
31
|
+
: e.message;
|
|
32
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
|
|
33
|
+
}
|
|
34
|
+
const refsResult = (0, resolve_refs_1.resolveRefsPass)(featuresResult.value, this.refRegistry);
|
|
24
35
|
if (refsResult.isErr()) {
|
|
25
36
|
const e = refsResult.error;
|
|
26
37
|
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Step '${e.stepId}': ref resolution error — ${e.cause.message}`));
|
package/dist/manifest.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"distDir": "dist",
|
|
3
3
|
"files": {
|
|
4
|
+
"application/services/compiler/feature-registry.d.ts": {
|
|
5
|
+
"sha256": "0df999218ba4dac5cf3fad34f3291e2b217b662badef01ee20f1258c4d03d13f",
|
|
6
|
+
"bytes": 740
|
|
7
|
+
},
|
|
8
|
+
"application/services/compiler/feature-registry.js": {
|
|
9
|
+
"sha256": "0350c0bd6ab92b1f38f58d12e2d2064af4275b34dfabf7e1677df9eb284d8ba4",
|
|
10
|
+
"bytes": 1124
|
|
11
|
+
},
|
|
4
12
|
"application/services/compiler/prompt-blocks.d.ts": {
|
|
5
13
|
"sha256": "2f40fd7599bd351584505152e9916fdea60891833d22c774c8ac9955f01ccf66",
|
|
6
14
|
"bytes": 1416
|
|
@@ -17,6 +25,14 @@
|
|
|
17
25
|
"sha256": "075b14ab0efd34df85eb9b564362d2415eacffc13f44f1ba54bdc5e8229a7d2e",
|
|
18
26
|
"bytes": 2008
|
|
19
27
|
},
|
|
28
|
+
"application/services/compiler/resolve-features.d.ts": {
|
|
29
|
+
"sha256": "bb5d0719f1156fe5fc92464bc828407b7be1b1149e79e70e71669cf54dce4ddc",
|
|
30
|
+
"bytes": 733
|
|
31
|
+
},
|
|
32
|
+
"application/services/compiler/resolve-features.js": {
|
|
33
|
+
"sha256": "04637806407d1888b8b0d78ee05a92eb08c9bb33f695a3db4ad6373e5666831a",
|
|
34
|
+
"bytes": 2444
|
|
35
|
+
},
|
|
20
36
|
"application/services/compiler/resolve-refs.d.ts": {
|
|
21
37
|
"sha256": "64ed63007495f8b95baeb5f867a6b6ac39f097ad5976803b2642defa80ed31bf",
|
|
22
38
|
"bytes": 581
|
|
@@ -66,12 +82,12 @@
|
|
|
66
82
|
"bytes": 31038
|
|
67
83
|
},
|
|
68
84
|
"application/services/workflow-compiler.d.ts": {
|
|
69
|
-
"sha256": "
|
|
70
|
-
"bytes":
|
|
85
|
+
"sha256": "d175afb550035f44e6e86dde5a1cf2a1ba68eeb61d39590e02b355a9f0e19bf3",
|
|
86
|
+
"bytes": 1062
|
|
71
87
|
},
|
|
72
88
|
"application/services/workflow-compiler.js": {
|
|
73
|
-
"sha256": "
|
|
74
|
-
"bytes":
|
|
89
|
+
"sha256": "7517fe0d70974f770dad82ede863477e0f367a63bb1fde84636eb96596c52dca",
|
|
90
|
+
"bytes": 7269
|
|
75
91
|
},
|
|
76
92
|
"application/services/workflow-interpreter.d.ts": {
|
|
77
93
|
"sha256": "56b5b5ad06d42096deba9f0abe7642c18a355a1e598749aab1730df4e9847674",
|
|
@@ -1082,8 +1098,8 @@
|
|
|
1082
1098
|
"bytes": 395
|
|
1083
1099
|
},
|
|
1084
1100
|
"types/workflow-definition.d.ts": {
|
|
1085
|
-
"sha256": "
|
|
1086
|
-
"bytes":
|
|
1101
|
+
"sha256": "d8fa099c4f2939f27a7fef55b4c6e40161a9bd0a82e2c6137de0eb8210982e9c",
|
|
1102
|
+
"bytes": 3787
|
|
1087
1103
|
},
|
|
1088
1104
|
"types/workflow-definition.js": {
|
|
1089
1105
|
"sha256": "e269d62f27b7f37f870183d6b77800b7aa1e22dabc894374bab8f34db049a55b",
|
|
@@ -79,6 +79,7 @@ export interface WorkflowDefinition {
|
|
|
79
79
|
readonly metaGuidance?: readonly string[];
|
|
80
80
|
readonly functionDefinitions?: readonly FunctionDefinition[];
|
|
81
81
|
readonly recommendedPreferences?: WorkflowRecommendedPreferences;
|
|
82
|
+
readonly features?: readonly string[];
|
|
82
83
|
}
|
|
83
84
|
export declare function isLoopStepDefinition(step: WorkflowStepDefinition | LoopStepDefinition): step is LoopStepDefinition;
|
|
84
85
|
export declare function isWorkflowStepDefinition(step: WorkflowStepDefinition | LoopStepDefinition): step is WorkflowStepDefinition;
|