instant-ctrl-flow-logic 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 -2
- package/src/filesystem.ts +25 -0
- package/src/loader.ts +34 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instant-ctrl-flow-logic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "InstantCtrlFlow 引擎:xnl bundle 加载 → 行为树编译 → 无状态单次执行",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"depa-behavior-tree": "0.1.0",
|
|
15
|
-
"
|
|
15
|
+
"flow-step-space-contract": "0.1.1",
|
|
16
|
+
"flow-step-space-logic": "0.1.1",
|
|
17
|
+
"instant-ctrl-flow-contract": "0.1.2",
|
|
16
18
|
"xnl-core": "^0.1.8"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|
package/src/filesystem.ts
CHANGED
|
@@ -3,12 +3,17 @@ import path from 'node:path';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import type { FlowCodeFunction, FlowCodeResolver, LoadFlowSourcesOptions } from 'instant-ctrl-flow-contract';
|
|
5
5
|
import { loadFlowBundleFromSources, type LoadResult } from './loader.js';
|
|
6
|
+
import {
|
|
7
|
+
assembleDefinitionStepProfileDirectory,
|
|
8
|
+
createFilesystemDefinitionStepProfileRuntime,
|
|
9
|
+
} from 'flow-step-space-logic/filesystem';
|
|
6
10
|
import { FlowLoadError, runInstantCtrlFlowSpec } from './engine.js';
|
|
7
11
|
import type { InstantCtrlFlowRunOptions } from 'instant-ctrl-flow-contract';
|
|
8
12
|
|
|
9
13
|
/** Filesystem convenience only; parsing and validation belong to the named-source loader. */
|
|
10
14
|
export function loadFlowBundle(dir: string, options: LoadFlowSourcesOptions = {}): LoadResult {
|
|
11
15
|
const absoluteDir = path.resolve(dir);
|
|
16
|
+
const stepRuntime = createFilesystemDefinitionStepProfileRuntime({ rootDir: absoluteDir });
|
|
12
17
|
const sources = fs.existsSync(absoluteDir)
|
|
13
18
|
? fs.readdirSync(absoluteDir, { withFileTypes: true })
|
|
14
19
|
.filter((entry) => entry.isFile() && entry.name.endsWith('.xnl'))
|
|
@@ -18,6 +23,26 @@ export function loadFlowBundle(dir: string, options: LoadFlowSourcesOptions = {}
|
|
|
18
23
|
content: fs.readFileSync(path.join(absoluteDir, entry.name), 'utf8'),
|
|
19
24
|
}))
|
|
20
25
|
: [];
|
|
26
|
+
for (const profileRoot of ['InstantCtrlFlow', 'WorkCtrlFlow', 'BPCtrlFlow']) {
|
|
27
|
+
const assembled = assembleDefinitionStepProfileDirectory(
|
|
28
|
+
stepRuntime,
|
|
29
|
+
{},
|
|
30
|
+
{ ...(options.stepSpace ?? {}), profileRoot },
|
|
31
|
+
);
|
|
32
|
+
if (assembled.diagnostics.length > 0) {
|
|
33
|
+
return { diagnostics: assembled.diagnostics.map(({ code, message }) => ({ code, message })) };
|
|
34
|
+
}
|
|
35
|
+
if (!assembled.forest) continue;
|
|
36
|
+
const projectedSources = (assembled.sources as readonly ({ readonly ref: string; readonly content: string } | { readonly name: string; readonly content: string })[])
|
|
37
|
+
.map((source) => ({ name: 'name' in source ? source.name : source.ref, content: source.content }));
|
|
38
|
+
const loaded = loadFlowBundleFromSources(projectedSources, {
|
|
39
|
+
...options,
|
|
40
|
+
baseUri: options.baseUri ?? absoluteDir,
|
|
41
|
+
});
|
|
42
|
+
return loaded.spec
|
|
43
|
+
? { ...loaded, spec: { ...loaded.spec, definitionStepForest: assembled.forest } }
|
|
44
|
+
: loaded;
|
|
45
|
+
}
|
|
21
46
|
return loadFlowBundleFromSources(sources, { ...options, baseUri: options.baseUri ?? absoluteDir });
|
|
22
47
|
}
|
|
23
48
|
|
package/src/loader.ts
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* 完整 lint 由 tools/flow-dsl-check 承担;此处只做引擎必需的结构化与硬校验。
|
|
5
5
|
*/
|
|
6
6
|
import { parseXnl } from 'xnl-core';
|
|
7
|
+
import {
|
|
8
|
+
assembleDefinitionStepProfile,
|
|
9
|
+
createDefinitionStepSourceRuntime,
|
|
10
|
+
} from 'flow-step-space-logic';
|
|
11
|
+
import type { DefinitionStepForest, DefinitionStepSourceCollection } from 'flow-step-space-contract';
|
|
7
12
|
import type {
|
|
8
13
|
FlowBundleSpec,
|
|
9
14
|
CtrlFlowContract,
|
|
@@ -167,9 +172,34 @@ function loadCtrlFlowSources(
|
|
|
167
172
|
}
|
|
168
173
|
};
|
|
169
174
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
let definitionStepForest: DefinitionStepForest | undefined;
|
|
176
|
+
let effectiveSources = sources;
|
|
177
|
+
const definitionSources: DefinitionStepSourceCollection = Array.isArray(sources)
|
|
178
|
+
? sources.map((source) => ({ ref: source.name, content: source.content }))
|
|
179
|
+
: Object.entries(sources).map(([ref, content]) => ({ ref, content }));
|
|
180
|
+
const stepRuntime = createDefinitionStepSourceRuntime(definitionSources);
|
|
181
|
+
for (const candidateRoot of profile ? [profile.rootTag] : FORMS) {
|
|
182
|
+
const assembled = assembleDefinitionStepProfile(
|
|
183
|
+
stepRuntime,
|
|
184
|
+
{ sources: definitionSources },
|
|
185
|
+
{ ...(options.stepSpace ?? {}), profileRoot: candidateRoot },
|
|
186
|
+
);
|
|
187
|
+
if (assembled.diagnostics.length > 0) {
|
|
188
|
+
return { diagnostics: assembled.diagnostics.map(({ code, message }) => ({ code, message })) };
|
|
189
|
+
}
|
|
190
|
+
if (assembled.forest) {
|
|
191
|
+
effectiveSources = assembled.sources as FlowSourceCollection;
|
|
192
|
+
definitionStepForest = assembled.forest;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const sourceEntries = (Array.isArray(effectiveSources)
|
|
198
|
+
? effectiveSources.map((source) => ({
|
|
199
|
+
name: 'name' in source ? source.name : source.ref,
|
|
200
|
+
content: source.content,
|
|
201
|
+
}))
|
|
202
|
+
: Object.entries(effectiveSources).map(([name, content]) => ({ name, content })))
|
|
173
203
|
.filter(({ name }) => name.endsWith('.xnl'))
|
|
174
204
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
175
205
|
const sourceNames = sourceEntries.map(({ name }) => name);
|
|
@@ -408,6 +438,7 @@ function loadCtrlFlowSources(
|
|
|
408
438
|
baseUri: options.baseUri,
|
|
409
439
|
dir: options.baseUri ?? '',
|
|
410
440
|
statements: statementEls.map(toNodeSpec),
|
|
441
|
+
...(definitionStepForest ? { definitionStepForest } : {}),
|
|
411
442
|
flowContract,
|
|
412
443
|
config,
|
|
413
444
|
configDef,
|