instant-ctrl-flow-logic 0.1.2 → 0.1.3
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 +17 -0
- package/src/loader.ts +23 -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.3",
|
|
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.0",
|
|
16
|
+
"flow-step-space-logic": "0.1.0",
|
|
17
|
+
"instant-ctrl-flow-contract": "0.1.1",
|
|
16
18
|
"xnl-core": "^0.1.8"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|
package/src/filesystem.ts
CHANGED
|
@@ -3,6 +3,7 @@ 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 { assembleDefinitionStepProfileDirectory } from 'flow-step-space-logic/filesystem';
|
|
6
7
|
import { FlowLoadError, runInstantCtrlFlowSpec } from './engine.js';
|
|
7
8
|
import type { InstantCtrlFlowRunOptions } from 'instant-ctrl-flow-contract';
|
|
8
9
|
|
|
@@ -18,6 +19,22 @@ export function loadFlowBundle(dir: string, options: LoadFlowSourcesOptions = {}
|
|
|
18
19
|
content: fs.readFileSync(path.join(absoluteDir, entry.name), 'utf8'),
|
|
19
20
|
}))
|
|
20
21
|
: [];
|
|
22
|
+
for (const profileRoot of ['InstantCtrlFlow', 'WorkCtrlFlow', 'BPCtrlFlow']) {
|
|
23
|
+
const assembled = assembleDefinitionStepProfileDirectory(absoluteDir, profileRoot, options.stepSpace);
|
|
24
|
+
if (assembled.diagnostics.length > 0) {
|
|
25
|
+
return { diagnostics: assembled.diagnostics.map(({ code, message }) => ({ code, message })) };
|
|
26
|
+
}
|
|
27
|
+
if (!assembled.forest) continue;
|
|
28
|
+
const projectedSources = (assembled.sources as readonly ({ readonly ref: string; readonly content: string } | { readonly name: string; readonly content: string })[])
|
|
29
|
+
.map((source) => ({ name: 'name' in source ? source.name : source.ref, content: source.content }));
|
|
30
|
+
const loaded = loadFlowBundleFromSources(projectedSources, {
|
|
31
|
+
...options,
|
|
32
|
+
baseUri: options.baseUri ?? absoluteDir,
|
|
33
|
+
});
|
|
34
|
+
return loaded.spec
|
|
35
|
+
? { ...loaded, spec: { ...loaded.spec, definitionStepForest: assembled.forest } }
|
|
36
|
+
: loaded;
|
|
37
|
+
}
|
|
21
38
|
return loadFlowBundleFromSources(sources, { ...options, baseUri: options.baseUri ?? absoluteDir });
|
|
22
39
|
}
|
|
23
40
|
|
package/src/loader.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* 完整 lint 由 tools/flow-dsl-check 承担;此处只做引擎必需的结构化与硬校验。
|
|
5
5
|
*/
|
|
6
6
|
import { parseXnl } from 'xnl-core';
|
|
7
|
+
import { assembleDefinitionStepProfileSources } from 'flow-step-space-logic';
|
|
8
|
+
import type { DefinitionStepForest } from 'flow-step-space-contract';
|
|
7
9
|
import type {
|
|
8
10
|
FlowBundleSpec,
|
|
9
11
|
CtrlFlowContract,
|
|
@@ -167,9 +169,26 @@ function loadCtrlFlowSources(
|
|
|
167
169
|
}
|
|
168
170
|
};
|
|
169
171
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
let definitionStepForest: DefinitionStepForest | undefined;
|
|
173
|
+
let effectiveSources = sources;
|
|
174
|
+
for (const candidateRoot of profile ? [profile.rootTag] : FORMS) {
|
|
175
|
+
const assembled = assembleDefinitionStepProfileSources(sources, candidateRoot, options.stepSpace);
|
|
176
|
+
if (assembled.diagnostics.length > 0) {
|
|
177
|
+
return { diagnostics: assembled.diagnostics.map(({ code, message }) => ({ code, message })) };
|
|
178
|
+
}
|
|
179
|
+
if (assembled.forest) {
|
|
180
|
+
effectiveSources = assembled.sources as FlowSourceCollection;
|
|
181
|
+
definitionStepForest = assembled.forest;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const sourceEntries = (Array.isArray(effectiveSources)
|
|
187
|
+
? effectiveSources.map((source) => ({
|
|
188
|
+
name: 'name' in source ? source.name : source.ref,
|
|
189
|
+
content: source.content,
|
|
190
|
+
}))
|
|
191
|
+
: Object.entries(effectiveSources).map(([name, content]) => ({ name, content })))
|
|
173
192
|
.filter(({ name }) => name.endsWith('.xnl'))
|
|
174
193
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
175
194
|
const sourceNames = sourceEntries.map(({ name }) => name);
|
|
@@ -408,6 +427,7 @@ function loadCtrlFlowSources(
|
|
|
408
427
|
baseUri: options.baseUri,
|
|
409
428
|
dir: options.baseUri ?? '',
|
|
410
429
|
statements: statementEls.map(toNodeSpec),
|
|
430
|
+
...(definitionStepForest ? { definitionStepForest } : {}),
|
|
411
431
|
flowContract,
|
|
412
432
|
config,
|
|
413
433
|
configDef,
|