@fractal-solutions/qflow 2.0.0-canary.4 → 2.0.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.
@@ -1,114 +1,114 @@
1
- import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
2
- import os from 'node:os';
3
- import path from 'node:path';
4
-
5
- const root = path.resolve(import.meta.dir, '..');
6
- const npmCommand = ['npm'];
7
- const tmp = path.join(os.tmpdir(), `qflow-prepublish-${crypto.randomUUID()}`);
8
- const consumer = path.join(tmp, 'consumer');
9
-
10
- // `npm publish` leaks config such as npm_config_dry_run into lifecycle
11
- // scripts. The verifier must run its own pack/install for real.
12
- function npmEnv() {
13
- const env = { ...process.env };
14
- delete env.npm_config_dry_run;
15
- delete env.npm_config_pack_destination;
16
- return env;
17
- }
18
-
19
- function run(command, args, cwd, { capture = false, env = process.env } = {}) {
20
- const cmd = Array.isArray(command) ? command : [command];
21
- const result = Bun.spawnSync({
22
- cmd: [...cmd, ...args],
23
- cwd,
24
- env,
25
- stdout: capture ? 'pipe' : 'inherit',
26
- stderr: capture ? 'pipe' : 'inherit',
27
- });
28
- const output = {
29
- stdout: result.stdout?.toString() ?? '',
30
- stderr: result.stderr?.toString() ?? '',
31
- };
32
- if (result.exitCode !== 0) {
33
- throw new Error(
34
- `${[...cmd, ...args].join(' ')} failed (exit ${result.exitCode})\n${output.stdout}${output.stderr}`
35
- );
36
- }
37
- return output;
38
- }
39
-
40
- const smokeSource = `
41
- const subpaths = [
42
- ['@fractal-solutions/qflow', ['Node', 'Flow', 'AsyncNode', 'AsyncFlow']],
43
- ['@fractal-solutions/qflow/nodes', ['ReplaySafeNode', 'WaitForApprovalNode', 'ScheduleNode', 'BudgetNode', 'MemoryStoreNode']],
44
- ['@fractal-solutions/qflow/agent', ['AgentNode', 'AgentEngine']],
45
- ['@fractal-solutions/qflow/mcp', ['QFlowMCPServer']],
46
- ['@fractal-solutions/qflow/streaming', ['streamChatCompletions']],
47
- ['@fractal-solutions/qflow/durable', ['DurableFlow', 'SQLiteCheckpointer', 'WaitForApprovalNode', 'BudgetTracker']],
48
- ['@fractal-solutions/qflow/testing', ['recordFlow', 'MockNode']],
49
- ['@fractal-solutions/qflow/graph', ['MapNode', 'BranchNode']],
50
- ['@fractal-solutions/qflow/trace', ['normalizeTrace', 'writeTraceFile']],
51
- ['@fractal-solutions/qflow/optional', ['loadOptional']],
52
- ['@fractal-solutions/qflow/logger', ['log', 'LogLevel']],
53
- ['@fractal-solutions/qflow/llm', ['LLMNode', 'LLMAdapter']],
54
- ['@fractal-solutions/qflow/tool-spec', ['ToolSpec', 'ToolRegistry']],
55
- ['@fractal-solutions/qflow/contracts', ['StateContract', 'defineState']],
56
- ['@fractal-solutions/qflow/side-effects', ['ReplaySafeNode', 'SideEffectClaimedError']],
57
- ['@fractal-solutions/qflow/eval', ['AssertNode', 'ReplayNode']],
58
- ['@fractal-solutions/qflow/bun', ['BunSpawnNode', 'SQLiteQueryNode']],
59
- ['@fractal-solutions/qflow/approval', ['WaitForApprovalNode']],
60
- ['@fractal-solutions/qflow/schedule', ['ScheduleNode', 'nextCronTime']],
61
- ['@fractal-solutions/qflow/budget', ['BudgetTracker', 'BudgetNode', 'BudgetExceededError']],
62
- ['@fractal-solutions/qflow/memory', ['MemoryStoreNode', 'SQLiteMemoryStore']],
63
- ];
64
- for (const [specifier, names] of subpaths) {
65
- const mod = await import(specifier);
66
- const missing = names.filter(name => !(name in mod));
67
- if (missing.length) throw new Error(specifier + ': missing ' + missing.join(', '));
68
- }
69
- console.log('All ' + subpaths.length + ' published subpaths import correctly.');
70
- `;
71
-
72
- try {
73
- console.log('[verify-package] 1/5 tests');
74
- run(process.execPath, ['test', 'tests'], root);
75
-
76
- console.log('[verify-package] 2/5 build');
77
- run(process.execPath, ['run', 'build'], root);
78
-
79
- console.log('[verify-package] 3/5 pack');
80
- mkdirSync(tmp, { recursive: true });
81
- const packed = run(npmCommand, ['pack', '--pack-destination', tmp, '--silent'], root, {
82
- capture: true,
83
- env: npmEnv(),
84
- });
85
- const tarball = packed.stdout.trim().split(/\r?\n/).filter(Boolean).pop();
86
- if (!tarball?.endsWith('.tgz')) throw new Error(`Could not read tarball name from npm pack: ${packed.stdout}`);
87
- console.log(`[verify-package] ${tarball}`);
88
-
89
- console.log('[verify-package] 4/5 install tarball in a clean consumer project (runs postinstall)');
90
- mkdirSync(consumer, { recursive: true });
91
- writeFileSync(
92
- path.join(consumer, 'package.json'),
93
- JSON.stringify({ name: 'qflow-package-smoke', version: '1.0.0', private: true, type: 'module' }, null, 2)
94
- );
95
- run(npmCommand, [
96
- 'install', path.join(tmp, tarball),
97
- '--omit=optional', '--no-audit', '--no-fund',
98
- ], consumer, { env: npmEnv() });
99
- if (existsSync(path.join(consumer, 'node_modules', 'typescript'))) {
100
- throw new Error('typescript was installed for the consumer; it must stay a devDependency.');
101
- }
102
-
103
- console.log('[verify-package] 5/5 import every published subpath');
104
- writeFileSync(path.join(consumer, 'smoke.js'), smokeSource);
105
- run(process.execPath, ['smoke.js'], consumer);
106
-
107
- console.log('[verify-package] Package is ready to publish.');
108
- } finally {
109
- try {
110
- rmSync(tmp, { recursive: true, force: true });
111
- } catch (error) {
112
- console.warn(`[verify-package] Could not remove ${tmp}: ${error.message}`);
113
- }
114
- }
1
+ import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+
5
+ const root = path.resolve(import.meta.dir, '..');
6
+ const npmCommand = ['npm'];
7
+ const tmp = path.join(os.tmpdir(), `qflow-prepublish-${crypto.randomUUID()}`);
8
+ const consumer = path.join(tmp, 'consumer');
9
+
10
+ // `npm publish` leaks config such as npm_config_dry_run into lifecycle
11
+ // scripts. The verifier must run its own pack/install for real.
12
+ function npmEnv() {
13
+ const env = { ...process.env };
14
+ delete env.npm_config_dry_run;
15
+ delete env.npm_config_pack_destination;
16
+ return env;
17
+ }
18
+
19
+ function run(command, args, cwd, { capture = false, env = process.env } = {}) {
20
+ const cmd = Array.isArray(command) ? command : [command];
21
+ const result = Bun.spawnSync({
22
+ cmd: [...cmd, ...args],
23
+ cwd,
24
+ env,
25
+ stdout: capture ? 'pipe' : 'inherit',
26
+ stderr: capture ? 'pipe' : 'inherit',
27
+ });
28
+ const output = {
29
+ stdout: result.stdout?.toString() ?? '',
30
+ stderr: result.stderr?.toString() ?? '',
31
+ };
32
+ if (result.exitCode !== 0) {
33
+ throw new Error(
34
+ `${[...cmd, ...args].join(' ')} failed (exit ${result.exitCode})\n${output.stdout}${output.stderr}`
35
+ );
36
+ }
37
+ return output;
38
+ }
39
+
40
+ const smokeSource = `
41
+ const subpaths = [
42
+ ['@fractal-solutions/qflow', ['Node', 'Flow', 'AsyncNode', 'AsyncFlow']],
43
+ ['@fractal-solutions/qflow/nodes', ['ReplaySafeNode', 'WaitForApprovalNode', 'ScheduleNode', 'BudgetNode', 'MemoryStoreNode']],
44
+ ['@fractal-solutions/qflow/agent', ['AgentNode', 'AgentEngine']],
45
+ ['@fractal-solutions/qflow/mcp', ['QFlowMCPServer']],
46
+ ['@fractal-solutions/qflow/streaming', ['streamChatCompletions']],
47
+ ['@fractal-solutions/qflow/durable', ['DurableFlow', 'SQLiteCheckpointer', 'WaitForApprovalNode', 'BudgetTracker']],
48
+ ['@fractal-solutions/qflow/testing', ['recordFlow', 'MockNode']],
49
+ ['@fractal-solutions/qflow/graph', ['MapNode', 'BranchNode']],
50
+ ['@fractal-solutions/qflow/trace', ['normalizeTrace', 'writeTraceFile']],
51
+ ['@fractal-solutions/qflow/optional', ['loadOptional']],
52
+ ['@fractal-solutions/qflow/logger', ['log', 'LogLevel']],
53
+ ['@fractal-solutions/qflow/llm', ['LLMNode', 'LLMAdapter']],
54
+ ['@fractal-solutions/qflow/tool-spec', ['ToolSpec', 'ToolRegistry']],
55
+ ['@fractal-solutions/qflow/contracts', ['StateContract', 'defineState']],
56
+ ['@fractal-solutions/qflow/side-effects', ['ReplaySafeNode', 'SideEffectClaimedError']],
57
+ ['@fractal-solutions/qflow/eval', ['AssertNode', 'ReplayNode']],
58
+ ['@fractal-solutions/qflow/bun', ['BunSpawnNode', 'SQLiteQueryNode']],
59
+ ['@fractal-solutions/qflow/approval', ['WaitForApprovalNode']],
60
+ ['@fractal-solutions/qflow/schedule', ['ScheduleNode', 'nextCronTime']],
61
+ ['@fractal-solutions/qflow/budget', ['BudgetTracker', 'BudgetNode', 'BudgetExceededError']],
62
+ ['@fractal-solutions/qflow/memory', ['MemoryStoreNode', 'SQLiteMemoryStore']],
63
+ ];
64
+ for (const [specifier, names] of subpaths) {
65
+ const mod = await import(specifier);
66
+ const missing = names.filter(name => !(name in mod));
67
+ if (missing.length) throw new Error(specifier + ': missing ' + missing.join(', '));
68
+ }
69
+ console.log('All ' + subpaths.length + ' published subpaths import correctly.');
70
+ `;
71
+
72
+ try {
73
+ console.log('[verify-package] 1/5 tests');
74
+ run(process.execPath, ['test', 'tests'], root);
75
+
76
+ console.log('[verify-package] 2/5 build');
77
+ run(process.execPath, ['run', 'build'], root);
78
+
79
+ console.log('[verify-package] 3/5 pack');
80
+ mkdirSync(tmp, { recursive: true });
81
+ const packed = run(npmCommand, ['pack', '--pack-destination', tmp, '--silent'], root, {
82
+ capture: true,
83
+ env: npmEnv(),
84
+ });
85
+ const tarball = packed.stdout.trim().split(/\r?\n/).filter(Boolean).pop();
86
+ if (!tarball?.endsWith('.tgz')) throw new Error(`Could not read tarball name from npm pack: ${packed.stdout}`);
87
+ console.log(`[verify-package] ${tarball}`);
88
+
89
+ console.log('[verify-package] 4/5 install tarball in a clean consumer project (runs postinstall)');
90
+ mkdirSync(consumer, { recursive: true });
91
+ writeFileSync(
92
+ path.join(consumer, 'package.json'),
93
+ JSON.stringify({ name: 'qflow-package-smoke', version: '1.0.0', private: true, type: 'module' }, null, 2)
94
+ );
95
+ run(npmCommand, [
96
+ 'install', path.join(tmp, tarball),
97
+ '--omit=optional', '--no-audit', '--no-fund',
98
+ ], consumer, { env: npmEnv() });
99
+ if (existsSync(path.join(consumer, 'node_modules', 'typescript'))) {
100
+ throw new Error('typescript was installed for the consumer; it must stay a devDependency.');
101
+ }
102
+
103
+ console.log('[verify-package] 5/5 import every published subpath');
104
+ writeFileSync(path.join(consumer, 'smoke.js'), smokeSource);
105
+ run(process.execPath, ['smoke.js'], consumer);
106
+
107
+ console.log('[verify-package] Package is ready to publish.');
108
+ } finally {
109
+ try {
110
+ rmSync(tmp, { recursive: true, force: true });
111
+ } catch (error) {
112
+ console.warn(`[verify-package] Could not remove ${tmp}: ${error.message}`);
113
+ }
114
+ }