yaml-flow 6.0.0 → 7.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.
- package/board-live-cards-cli.js +4 -4
- package/browser/asset-integrity.json +3 -3
- package/browser/board-livecards-client.js +2 -0
- package/browser/board-livecards-client.js.map +1 -0
- package/browser/board-livecards-localstorage.js +10 -0
- package/browser/board-livecards-localstorage.js.map +1 -0
- package/browser/board-livegraph-engine.js +2 -2
- package/browser/board-livegraph-engine.js.map +1 -1
- package/browser/card-compute.js +28 -28
- package/browser/compute-jsonata.js +5 -0
- package/browser/compute-jsonata.js.map +1 -0
- package/browser/live-cards.js +261 -150
- package/card-store.js +4 -4
- package/dist/{board-live-cards-public-CltXYgaY.d.cts → board-live-cards-public-CW5074xr.d.cts} +9 -5
- package/dist/{board-live-cards-public-f-E-FAyp.d.ts → board-live-cards-public-hnZo0mAf.d.ts} +9 -5
- package/dist/board-livegraph-runtime/index.cjs +2 -2
- package/dist/board-livegraph-runtime/index.cjs.map +1 -1
- package/dist/board-livegraph-runtime/index.d.cts +11 -9
- package/dist/board-livegraph-runtime/index.d.ts +11 -9
- package/dist/board-livegraph-runtime/index.js +2 -2
- package/dist/board-livegraph-runtime/index.js.map +1 -1
- package/dist/board-livegraph-runtime/jsonata-sync.cjs +37 -1
- package/dist/card-compute/index.cjs +4 -4
- package/dist/card-compute/index.cjs.map +1 -1
- package/dist/card-compute/index.d.cts +5 -1
- package/dist/card-compute/index.d.ts +5 -1
- package/dist/card-compute/index.js +4 -4
- package/dist/card-compute/index.js.map +1 -1
- package/dist/card-compute/jsonata-sync.cjs +37 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs +2 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs.map +1 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.d.cts +27 -14
- package/dist/cli/browser-api/board-live-cards-browser-adapter.d.ts +27 -14
- package/dist/cli/browser-api/board-live-cards-browser-adapter.js +2 -1
- package/dist/cli/browser-api/board-live-cards-browser-adapter.js.map +1 -1
- package/dist/cli/browser-api/card-store-browser-api.cjs +1 -1
- package/dist/cli/browser-api/card-store-browser-api.cjs.map +1 -1
- package/dist/cli/browser-api/card-store-browser-api.js +1 -1
- package/dist/cli/browser-api/card-store-browser-api.js.map +1 -1
- package/dist/cli/browser-api/jsonata-sync.cjs +37 -1
- package/dist/cli/node/artifacts-store-cli.cjs +8 -8
- package/dist/cli/node/artifacts-store-cli.cjs.map +1 -1
- package/dist/cli/node/artifacts-store-cli.js +8 -8
- package/dist/cli/node/artifacts-store-cli.js.map +1 -1
- package/dist/cli/node/board-live-cards-cli.cjs +7 -7
- package/dist/cli/node/board-live-cards-cli.cjs.map +1 -1
- package/dist/cli/node/board-live-cards-cli.js +7 -7
- package/dist/cli/node/board-live-cards-cli.js.map +1 -1
- package/dist/cli/node/card-store-cli.cjs +5 -5
- package/dist/cli/node/card-store-cli.cjs.map +1 -1
- package/dist/cli/node/card-store-cli.js +5 -5
- package/dist/cli/node/card-store-cli.js.map +1 -1
- package/dist/cli/node/execution-adapter.cjs +3 -0
- package/dist/cli/node/execution-adapter.cjs.map +1 -0
- package/dist/cli/node/execution-adapter.d.cts +174 -0
- package/dist/cli/node/execution-adapter.d.ts +174 -0
- package/dist/cli/node/execution-adapter.js +3 -0
- package/dist/cli/node/execution-adapter.js.map +1 -0
- package/dist/cli/node/fs-board-adapter.cjs +7 -7
- package/dist/cli/node/fs-board-adapter.cjs.map +1 -1
- package/dist/cli/node/fs-board-adapter.d.cts +2 -2
- package/dist/cli/node/fs-board-adapter.d.ts +2 -2
- package/dist/cli/node/fs-board-adapter.js +7 -7
- package/dist/cli/node/fs-board-adapter.js.map +1 -1
- package/dist/cli/node/jsonata-sync.cjs +37 -1
- package/dist/cli/node/source-cli-task-executor.cjs +4 -4
- package/dist/cli/node/source-cli-task-executor.cjs.map +1 -1
- package/dist/cli/node/source-cli-task-executor.js +4 -4
- package/dist/cli/node/source-cli-task-executor.js.map +1 -1
- package/dist/continuous-event-graph/index.cjs +2 -2
- package/dist/continuous-event-graph/index.cjs.map +1 -1
- package/dist/continuous-event-graph/index.js +2 -2
- package/dist/continuous-event-graph/index.js.map +1 -1
- package/dist/continuous-event-graph/jsonata-sync.cjs +37 -1
- package/dist/execution-refs.cjs +2 -1
- package/dist/execution-refs.cjs.map +1 -1
- package/dist/execution-refs.d.cts +49 -11
- package/dist/execution-refs.d.ts +49 -11
- package/dist/execution-refs.js +2 -1
- package/dist/execution-refs.js.map +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/jsonata-sync.cjs +37 -1
- package/dist/server-runtime/index.cjs +9 -0
- package/dist/server-runtime/index.cjs.map +1 -0
- package/dist/server-runtime/index.d.cts +31 -0
- package/dist/server-runtime/index.d.ts +31 -0
- package/dist/server-runtime/index.js +9 -0
- package/dist/server-runtime/index.js.map +1 -0
- package/dist/server-runtime/jsonata-sync.cjs +7623 -0
- package/dist/step-machine-public/index.cjs +2 -0
- package/dist/step-machine-public/index.cjs.map +1 -0
- package/dist/step-machine-public/index.d.cts +159 -0
- package/dist/step-machine-public/index.d.ts +159 -0
- package/dist/step-machine-public/index.js +2 -0
- package/dist/step-machine-public/index.js.map +1 -0
- package/dist/step-machine-public/jsonata-sync.cjs +7623 -0
- package/dist/storage-refs.cjs +2 -2
- package/dist/storage-refs.cjs.map +1 -1
- package/dist/storage-refs.d.cts +7 -6
- package/dist/storage-refs.d.ts +7 -6
- package/dist/storage-refs.js +2 -2
- package/dist/storage-refs.js.map +1 -1
- package/dist/types-B1ZRa4aI.d.ts +147 -0
- package/dist/types-BxEFcVK9.d.cts +147 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-t4.js +9 -10
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.js +357 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-public.js +9 -10
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.js +300 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.py +617 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker-sse-worker.js +48 -0
- package/examples/browser/boards/portfolio-tracker/portfolio-tracker.py +11 -10
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +19 -4
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +4 -8
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +6 -10
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/poll-status-cli.js +8 -16
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +2 -6
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +4 -8
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +3 -7
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +4 -8
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +7 -16
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +2 -6
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/_board_pycli.py +13 -3
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/add-cards.py +2 -1
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/init-board.py +2 -1
- package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/poll-status.py +2 -1
- package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +20 -24
- package/examples/cli/step-machine-cli/portfolio-tracker/run-inline-python-demo-pycli.py +0 -3
- package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +8 -13
- package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +33 -9
- package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +3 -1
- package/examples/cli/step-machine-demo/step2-double-cli.js +6 -12
- package/examples/cli/step-machine-demo/two-step-math.flow.yaml +66 -4
- package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +13 -5
- package/examples/example-board/cards/_index.json +47 -0
- package/examples/example-board/cards/card-market-prices.json +33 -9
- package/examples/example-board/cards/card-my-identity.json +30 -6
- package/examples/example-board/cards/card-portfolio-action.json +24 -6
- package/examples/example-board/cards/card-portfolio-intelligence.json +97 -0
- package/examples/example-board/cards/card-portfolio-risks.json +24 -6
- package/examples/example-board/cards/card-portfolio-value.json +38 -10
- package/examples/example-board/cards/card-portfolio.json +57 -13
- package/examples/example-board/cards/card-rebalance-impact.json +22 -6
- package/examples/example-board/cards/card-rebalance-sim.json +66 -15
- package/examples/example-board/demo-server.js +360 -69
- package/examples/example-board/demo-shell-localstorage.html +774 -0
- package/examples/example-board/demo-shell-with-server.html +18 -36
- package/examples/example-board/demo-shell.html +5 -4
- package/examples/example-board/demo-task-executor.js +217 -265
- package/package.json +15 -13
- package/step-machine-cli.js +43 -310
- package/board-livecards-server-runtime.js +0 -1513
- package/browser/board-livecards-runtime-client.js +0 -263
- package/dist/pycli/quickjs-board-runtime.global.js +0 -9
- package/dist/pycli/quickjs-board-runtime.global.js.map +0 -1
- package/dist/pycli/quickjs-step-machine-runtime.global.js +0 -5
- package/dist/pycli/quickjs-step-machine-runtime.global.js.map +0 -1
- package/examples/cli/step-machine-demo/two-step-math-handlers.js +0 -32
- package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +0 -24
- package/examples/example-board/demo-shell-browser.html +0 -675
|
@@ -4,15 +4,22 @@ import http from 'node:http';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import os from 'node:os';
|
|
7
|
+
import net from 'node:net';
|
|
7
8
|
import { spawnSync, spawn } from 'node:child_process';
|
|
8
9
|
import { fileURLToPath } from 'node:url';
|
|
9
10
|
import { createRequire } from 'node:module';
|
|
10
11
|
|
|
11
12
|
import {
|
|
12
13
|
createMultiBoardServerRuntime,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
createSingleBoardServerRuntime,
|
|
15
|
+
} from 'yaml-flow/server-runtime';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
createFsBoardPlatformAdapter,
|
|
19
|
+
createArtifactsStore,
|
|
20
|
+
parseRef,
|
|
21
|
+
serializeRef,
|
|
22
|
+
} from 'yaml-flow/board-live-cards-node';
|
|
16
23
|
|
|
17
24
|
const __filename = fileURLToPath(import.meta.url);
|
|
18
25
|
const __dirname = path.dirname(__filename);
|
|
@@ -27,6 +34,11 @@ function resolveYamlFlowDir() {
|
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
const _yamlFlowDir = resolveYamlFlowDir();
|
|
37
|
+
|
|
38
|
+
// cliDir must point to the yaml-flow root so buildBoardCliInvocation finds
|
|
39
|
+
// board-live-cards-cli.js for task-executor completion callbacks.
|
|
40
|
+
// demo-src/example-board is 2 levels below the yaml-flow root.
|
|
41
|
+
const YAML_FLOW_CLI_DIR = _yamlFlowDir || path.resolve(__dirname, '..', '..');
|
|
30
42
|
const _pkgStepMachineCli = _yamlFlowDir ? path.join(_yamlFlowDir, 'step-machine-cli.js') : null;
|
|
31
43
|
|
|
32
44
|
function loadServerConfig() {
|
|
@@ -49,11 +61,17 @@ function resolveFromConfig(configValue) {
|
|
|
49
61
|
function resolveKindRefFromConfig(configValue) {
|
|
50
62
|
if (typeof configValue !== 'string' || !configValue.trim()) return null;
|
|
51
63
|
const trimmed = configValue.trim();
|
|
52
|
-
if (!trimmed.startsWith('
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
if (!trimmed.startsWith('b64:')) return trimmed;
|
|
65
|
+
try {
|
|
66
|
+
const parsed = parseRef(trimmed);
|
|
67
|
+
if (parsed.kind !== 'fs-path') return trimmed;
|
|
68
|
+
const rawPath = parsed.value.trim();
|
|
69
|
+
if (!rawPath) return null;
|
|
70
|
+
const resolved = path.isAbsolute(rawPath) ? rawPath : path.resolve(__dirname, rawPath);
|
|
71
|
+
return serializeRef({ kind: 'fs-path', value: resolved });
|
|
72
|
+
} catch {
|
|
73
|
+
return trimmed;
|
|
74
|
+
}
|
|
57
75
|
}
|
|
58
76
|
|
|
59
77
|
const serverConfig = loadServerConfig();
|
|
@@ -87,23 +105,293 @@ const CORS_HEADERS = {
|
|
|
87
105
|
'Access-Control-Allow-Methods': 'GET,POST,PATCH,OPTIONS',
|
|
88
106
|
};
|
|
89
107
|
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// Setup directory & defaults
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
const setupDir = path.resolve(
|
|
113
|
+
process.env.DEMO_SETUP_DIR || path.join(__dirname, '.demo-setup'),
|
|
114
|
+
);
|
|
115
|
+
fs.mkdirSync(setupDir, { recursive: true });
|
|
116
|
+
|
|
117
|
+
const defaultCardsDir = path.resolve(
|
|
118
|
+
process.env.DEMO_CARDS_DIR || configuredCardsDir || path.join(__dirname, 'cards'),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const defaultTaskExecutorPath = process.env.DEMO_TASK_EXECUTOR_PATH || configuredTaskExecutorPath || null;
|
|
122
|
+
const defaultChatHandlerPath = process.env.DEMO_CHAT_HANDLER_PATH || configuredChatHandlerPath || null;
|
|
123
|
+
const defaultInferenceAdapterPath = process.env.DEMO_INFERENCE_ADAPTER_PATH || configuredInferenceAdapterPath || null;
|
|
124
|
+
const defaultStepMachineCliPath = process.env.DEMO_STEP_MACHINE_CLI_PATH || configuredStepMachineCliPath || null;
|
|
125
|
+
const defaultGandalfCardsDir = process.env.DEMO_GANDALF_CARDS_DIR || configuredGandalfCardsDir || null;
|
|
126
|
+
const defaultGandalfTaskExecutorPath = process.env.DEMO_GANDALF_TASK_EXECUTOR_PATH || configuredGandalfTaskExecutorPath || null;
|
|
127
|
+
const defaultGandalfChatHandlerPath = process.env.DEMO_GANDALF_CHAT_HANDLER_PATH || configuredGandalfChatHandlerPath || null;
|
|
128
|
+
const defaultGandalfInferenceAdapterPath = process.env.DEMO_GANDALF_INFERENCE_ADAPTER_PATH || configuredGandalfInferenceAdapterPath || null;
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Host adapter factories — Node-specific implementations injected into the
|
|
132
|
+
// platform-free server runtime.
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
function createFsCardSource(cardsDir) {
|
|
136
|
+
return {
|
|
137
|
+
listCards() {
|
|
138
|
+
if (!fs.existsSync(cardsDir)) return [];
|
|
139
|
+
return fs.readdirSync(cardsDir)
|
|
140
|
+
.filter(f => f.endsWith('.json'))
|
|
141
|
+
.map(f => {
|
|
142
|
+
try { return JSON.parse(fs.readFileSync(path.join(cardsDir, f), 'utf-8')); }
|
|
143
|
+
catch { return null; }
|
|
144
|
+
})
|
|
145
|
+
.filter(Boolean);
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function namedPipePath(pipeName) {
|
|
151
|
+
if (process.platform === 'win32') return `\\\\.\\pipe\\${pipeName}`;
|
|
152
|
+
return path.join(os.tmpdir(), `${pipeName}.sock`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function makeExecutionRef(scriptPath, meta) {
|
|
156
|
+
if (!scriptPath) return undefined;
|
|
157
|
+
const resolved = path.isAbsolute(scriptPath) ? scriptPath : path.resolve(process.cwd(), scriptPath);
|
|
158
|
+
return { howToRun: 'local-node', whatToRun: serializeRef({ kind: 'fs-path', value: resolved }), meta };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function createNodeSpawnInvocationAdapter() {
|
|
162
|
+
return {
|
|
163
|
+
async invoke(ref, args) {
|
|
164
|
+
if (ref.howToRun !== 'local-node') {
|
|
165
|
+
return { dispatched: false, error: `unsupported howToRun: ${ref.howToRun}` };
|
|
166
|
+
}
|
|
167
|
+
const whatToRun = String(ref.whatToRun || '');
|
|
168
|
+
let scriptPath = '';
|
|
169
|
+
if (whatToRun.startsWith('b64:')) {
|
|
170
|
+
try {
|
|
171
|
+
const parsed = parseRef(whatToRun);
|
|
172
|
+
if (parsed.kind === 'fs-path') scriptPath = parsed.value;
|
|
173
|
+
} catch {
|
|
174
|
+
scriptPath = '';
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
scriptPath = whatToRun;
|
|
178
|
+
}
|
|
179
|
+
if (!scriptPath) {
|
|
180
|
+
return { dispatched: false, error: `no script path in whatToRun: ${whatToRun}` };
|
|
181
|
+
}
|
|
182
|
+
// Resolve chatsKeyPrefix (blob key prefix) to absolute FS chatDir for handlers
|
|
183
|
+
const finalArgs = { ...args };
|
|
184
|
+
if (finalArgs.chatsKeyPrefix && finalArgs.chatsBlobBasePath) {
|
|
185
|
+
const cardPart = String(finalArgs.chatsKeyPrefix).split('/')[0];
|
|
186
|
+
finalArgs.chatDir = path.join(String(finalArgs.chatsBlobBasePath), cardPart);
|
|
187
|
+
}
|
|
188
|
+
delete finalArgs.chatsKeyPrefix;
|
|
189
|
+
delete finalArgs.chatsBlobBasePath;
|
|
190
|
+
const extra = Buffer.from(JSON.stringify(finalArgs)).toString('base64');
|
|
191
|
+
try {
|
|
192
|
+
const proc = spawn(process.execPath, [
|
|
193
|
+
scriptPath,
|
|
194
|
+
'--boardId', String(args.boardId || ''),
|
|
195
|
+
'--cardId', String(args.cardId || ''),
|
|
196
|
+
'--extraEncJson', extra,
|
|
197
|
+
], { stdio: 'ignore', windowsHide: true });
|
|
198
|
+
proc.unref();
|
|
199
|
+
return { dispatched: true };
|
|
200
|
+
} catch (err) {
|
|
201
|
+
return { dispatched: false, error: err?.message || String(err) };
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
async describe(ref) {
|
|
205
|
+
if (ref.howToRun !== 'local-node') return null;
|
|
206
|
+
const whatToRun = String(ref.whatToRun || '');
|
|
207
|
+
let scriptPath = '';
|
|
208
|
+
if (whatToRun.startsWith('b64:')) {
|
|
209
|
+
try {
|
|
210
|
+
const parsed = parseRef(whatToRun);
|
|
211
|
+
if (parsed.kind === 'fs-path') scriptPath = parsed.value;
|
|
212
|
+
} catch {
|
|
213
|
+
scriptPath = '';
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
scriptPath = whatToRun;
|
|
217
|
+
}
|
|
218
|
+
if (!scriptPath) return null;
|
|
219
|
+
try {
|
|
220
|
+
const result = spawnSync(process.execPath, [scriptPath, 'describe'], {
|
|
221
|
+
timeout: 5000, encoding: 'utf-8', windowsHide: true,
|
|
222
|
+
});
|
|
223
|
+
if (result.status !== 0) return null;
|
|
224
|
+
return JSON.parse(String(result.stdout).trim());
|
|
225
|
+
} catch { return null; }
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function createNamedPipeNotificationTransport() {
|
|
231
|
+
return {
|
|
232
|
+
async subscribe(ref, onEvent) {
|
|
233
|
+
if (ref.kind !== 'named-pipe') {
|
|
234
|
+
console.warn(`[notification] unsupported transport kind: ${ref.kind}`);
|
|
235
|
+
return () => {};
|
|
236
|
+
}
|
|
237
|
+
const pipePath = ref.value;
|
|
238
|
+
if (process.platform !== 'win32' && fs.existsSync(pipePath)) {
|
|
239
|
+
try { fs.rmSync(pipePath, { force: true }); } catch { /* best-effort */ }
|
|
240
|
+
}
|
|
241
|
+
const server = net.createServer((socket) => {
|
|
242
|
+
let buf = '';
|
|
243
|
+
socket.on('data', (chunk) => {
|
|
244
|
+
buf += chunk.toString('utf-8');
|
|
245
|
+
while (true) {
|
|
246
|
+
const i = buf.indexOf('\n');
|
|
247
|
+
if (i < 0) break;
|
|
248
|
+
const line = buf.slice(0, i).trim();
|
|
249
|
+
buf = buf.slice(i + 1);
|
|
250
|
+
if (!line) continue;
|
|
251
|
+
try {
|
|
252
|
+
const msg = JSON.parse(line);
|
|
253
|
+
onEvent(msg?.notification ?? msg);
|
|
254
|
+
} catch { /* ignore malformed lines */ }
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
await new Promise((resolve, reject) => {
|
|
259
|
+
server.once('error', reject);
|
|
260
|
+
server.listen(pipePath, () => resolve());
|
|
261
|
+
});
|
|
262
|
+
return () => {
|
|
263
|
+
server.close();
|
|
264
|
+
if (process.platform !== 'win32') {
|
|
265
|
+
try { fs.rmSync(pipePath, { force: true }); } catch { /* best-effort */ }
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
// Server meta store (multi-board registry)
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
|
|
276
|
+
const serverMetaRef = process.env.DEMO_SERVER_META_STORE_REF || configuredServerMetaStoreRef || serializeRef({ kind: 'fs-path', value: setupDir });
|
|
277
|
+
const serverMetaAdapter = createFsBoardPlatformAdapter(
|
|
278
|
+
parseRef(serverMetaRef), YAML_FLOW_CLI_DIR, { suppressSpawn: true },
|
|
279
|
+
);
|
|
280
|
+
const serverMetaStore = createArtifactsStore(serverMetaAdapter.blobStorage('server-meta'));
|
|
281
|
+
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// Build multi-board runtime
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
|
|
286
|
+
const apiBasePath = '/api/boards';
|
|
287
|
+
const invocationAdapter = createNodeSpawnInvocationAdapter();
|
|
288
|
+
const notificationTransport = createNamedPipeNotificationTransport();
|
|
289
|
+
const logger = { info: console.log, warn: console.warn, error: console.error };
|
|
290
|
+
|
|
291
|
+
// Track per-board host config for demo-setup (FS paths are host concerns, not runtime concerns)
|
|
292
|
+
const boardHostConfig = new Map();
|
|
293
|
+
|
|
294
|
+
function buildBoardContextConfig(label, boardDir, cardsDir, taskExecPath, chatHandlerPath, infAdapterPath, boardId) {
|
|
295
|
+
fs.mkdirSync(boardDir, { recursive: true });
|
|
296
|
+
|
|
297
|
+
const notifyChannel = `yaml-flow-server-${label}-${boardId}-${process.pid}`;
|
|
298
|
+
const baseRef = parseRef(serializeRef({ kind: 'fs-path', value: boardDir }));
|
|
299
|
+
const boardAdapter = createFsBoardPlatformAdapter(baseRef, YAML_FLOW_CLI_DIR, {
|
|
300
|
+
notifyChannel,
|
|
301
|
+
});
|
|
302
|
+
// In the server context the drain loop is driven in-process; suppress the
|
|
303
|
+
// detached CLI spawn that the FS adapter would otherwise fire as a continuation.
|
|
304
|
+
boardAdapter.requestProcessAccumulated = () => {};
|
|
305
|
+
// Separate artifacts adapter rooted at cardsDir (preserves old FS layout where
|
|
306
|
+
// chats/files live under cardsDir rather than boardDir)
|
|
307
|
+
const artifactsRef = parseRef(serializeRef({ kind: 'fs-path', value: cardsDir }));
|
|
308
|
+
const artifactsAdapter = createFsBoardPlatformAdapter(artifactsRef, YAML_FLOW_CLI_DIR, { suppressSpawn: true });
|
|
309
|
+
|
|
310
|
+
const cardStoreRef = serializeRef({ kind: 'fs-path', value: cardsDir });
|
|
311
|
+
|
|
312
|
+
return {
|
|
313
|
+
label,
|
|
314
|
+
boardAdapter,
|
|
315
|
+
artifactsAdapter,
|
|
316
|
+
baseRef,
|
|
317
|
+
cardStoreRef,
|
|
318
|
+
outputsStoreRef: serializeRef({ kind: 'fs-path', value: path.join(path.dirname(boardDir), 'runtime-out', '.outputs') }),
|
|
319
|
+
notifyRef: { kind: 'named-pipe', value: namedPipePath(notifyChannel) },
|
|
320
|
+
taskExecutorRef: makeExecutionRef(taskExecPath, 'task-executor'),
|
|
321
|
+
chatHandlerRef: makeExecutionRef(chatHandlerPath, 'chat-handler'),
|
|
322
|
+
inferenceAdapterRef: makeExecutionRef(infAdapterPath, 'inference-adapter'),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
90
326
|
const runtime = createMultiBoardServerRuntime({
|
|
91
|
-
apiBasePath
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
327
|
+
apiBasePath,
|
|
328
|
+
serverMetaStore,
|
|
329
|
+
logger,
|
|
330
|
+
boardRuntimeFactory: (boardId, entry) => {
|
|
331
|
+
const cardsDir = typeof entry.cardsDir === 'string' ? path.resolve(entry.cardsDir) : defaultCardsDir;
|
|
332
|
+
const boardRoot = path.join(setupDir, `board-${boardId}`);
|
|
333
|
+
const boardDir = path.join(boardRoot, 'runtime');
|
|
334
|
+
|
|
335
|
+
const taskExecPath = typeof entry.taskExecutorPath === 'string' ? entry.taskExecutorPath : defaultTaskExecutorPath;
|
|
336
|
+
const chatHandlerPath_ = typeof entry.chatHandlerPath === 'string' ? entry.chatHandlerPath : defaultChatHandlerPath;
|
|
337
|
+
const infAdapterPath = typeof entry.inferenceAdapterPath === 'string' ? entry.inferenceAdapterPath : defaultInferenceAdapterPath;
|
|
338
|
+
const stepMachinePath = typeof entry.stepMachineCliPath === 'string' ? entry.stepMachineCliPath : defaultStepMachineCliPath;
|
|
339
|
+
|
|
340
|
+
const gandalfCardsDir_ = typeof entry.gandalfCardsDir === 'string' ? path.resolve(entry.gandalfCardsDir) : defaultGandalfCardsDir;
|
|
341
|
+
const gandalfTaskExecPath = typeof entry.gandalfTaskExecutorPath === 'string' ? entry.gandalfTaskExecutorPath : defaultGandalfTaskExecutorPath;
|
|
342
|
+
const gandalfChatPath = typeof entry.gandalfChatHandlerPath === 'string' ? entry.gandalfChatHandlerPath : defaultGandalfChatHandlerPath;
|
|
343
|
+
const gandalfInfPath = typeof entry.gandalfInferenceAdapterPath === 'string' ? entry.gandalfInferenceAdapterPath : defaultGandalfInferenceAdapterPath;
|
|
344
|
+
|
|
345
|
+
const baseCfg = buildBoardContextConfig('base', boardDir, cardsDir, taskExecPath, chatHandlerPath_, infAdapterPath, boardId);
|
|
346
|
+
|
|
347
|
+
const boards = [baseCfg];
|
|
348
|
+
if (gandalfCardsDir_ && gandalfTaskExecPath) {
|
|
349
|
+
const gandalfBoardDir = path.join(boardRoot, 'gandalf-runtime');
|
|
350
|
+
const gandalfCfg = buildBoardContextConfig('gandalf', gandalfBoardDir, gandalfCardsDir_, gandalfTaskExecPath, gandalfChatPath, gandalfInfPath, boardId);
|
|
351
|
+
// Fix gandalf outputsStoreRef
|
|
352
|
+
gandalfCfg.outputsStoreRef = serializeRef({ kind: 'fs-path', value: path.join(boardRoot, 'gandalf-runtime-out', '.outputs') });
|
|
353
|
+
boards.push(gandalfCfg);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Store host config for demo-setup (FS paths are host concerns)
|
|
357
|
+
boardHostConfig.set(boardId, { cardsDir, gandalfCardsDir: gandalfCardsDir_, boardDir, boardRoot });
|
|
358
|
+
|
|
359
|
+
// Auto-run demo-setup (write copilot-instructions.md) at board init time,
|
|
360
|
+
// so clients no longer need a separate /demo-setup request before bootstrapping.
|
|
361
|
+
demoPrepSetup(boardId);
|
|
362
|
+
|
|
363
|
+
const singleBoardRuntime = createSingleBoardServerRuntime({
|
|
364
|
+
apiBasePath: `${apiBasePath}/${boardId}`,
|
|
365
|
+
boardId,
|
|
366
|
+
boards,
|
|
367
|
+
invocationAdapter,
|
|
368
|
+
notificationTransport,
|
|
369
|
+
logger,
|
|
370
|
+
serverUrl: `http://127.0.0.1:${PORT}`,
|
|
371
|
+
executionExtra: {
|
|
372
|
+
boardSetupRoot: boardRoot,
|
|
373
|
+
chatsBlobBasePath: path.join(cardsDir, 'chats'),
|
|
374
|
+
...(stepMachinePath ? { stepMachineCliPath: stepMachinePath } : {}),
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Host concern (Part A): seed card store from FS source only if empty
|
|
379
|
+
const existing = singleBoardRuntime.cardStore.get({});
|
|
380
|
+
const isEmpty = existing.status !== 'success' || !existing.data?.cards?.length;
|
|
381
|
+
if (isEmpty) {
|
|
382
|
+
const cards = createFsCardSource(cardsDir).listCards();
|
|
383
|
+
if (cards.length) singleBoardRuntime.cardStore.set({ body: cards });
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return singleBoardRuntime;
|
|
387
|
+
},
|
|
103
388
|
});
|
|
104
389
|
|
|
390
|
+
// ---------------------------------------------------------------------------
|
|
391
|
+
// Reset
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
|
|
105
394
|
function resetRuntime() {
|
|
106
|
-
const setupDir = runtime.setupDir;
|
|
107
395
|
if (fs.existsSync(setupDir)) {
|
|
108
396
|
fs.rmSync(setupDir, { recursive: true, force: true });
|
|
109
397
|
console.log(`[demo-server] reset: wiped ${setupDir}`);
|
|
@@ -121,33 +409,24 @@ if (RESET_ON_START) {
|
|
|
121
409
|
resetRuntime();
|
|
122
410
|
}
|
|
123
411
|
|
|
124
|
-
const dispatch = createRuntimeRequestDispatcher(runtime);
|
|
125
|
-
|
|
126
|
-
// Board-id segment regex: /api/boards/:boardId/...
|
|
127
|
-
const BOARD_SEG_RE = /^\/api\/boards\/([^/]+)\/(.+)$/;
|
|
128
|
-
|
|
129
|
-
function jsonReply(res, status, payload) {
|
|
130
|
-
const body = JSON.stringify(payload);
|
|
131
|
-
res.writeHead(status, { ...CORS_HEADERS, 'Content-Type': 'application/json; charset=utf-8' });
|
|
132
|
-
res.end(body);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
412
|
// ---------------------------------------------------------------------------
|
|
136
|
-
//
|
|
137
|
-
// Writes
|
|
138
|
-
// Cards are served directly from cardsDir (no tmp copy needed).
|
|
413
|
+
// Demo-setup — host-level concern (not a runtime concern).
|
|
414
|
+
// Writes concatenated copilot-instructions.md at the board setup root.
|
|
139
415
|
// ---------------------------------------------------------------------------
|
|
140
416
|
|
|
141
|
-
const
|
|
417
|
+
const BOARD_SEG_RE = /^\/api\/boards\/([^/]+)\/(.+)$/;
|
|
418
|
+
const _demoPrepSetupDone = new Map();
|
|
142
419
|
|
|
143
|
-
function isDemoSetupDone(boardId
|
|
144
|
-
|
|
420
|
+
function isDemoSetupDone(boardId) {
|
|
421
|
+
const cfg = boardHostConfig.get(boardId);
|
|
422
|
+
return _demoPrepSetupDone.get(boardId) === true && cfg && fs.existsSync(cfg.cardsDir);
|
|
145
423
|
}
|
|
146
424
|
|
|
147
|
-
function demoPrepSetup(boardId
|
|
148
|
-
const
|
|
425
|
+
function demoPrepSetup(boardId) {
|
|
426
|
+
const cfg = boardHostConfig.get(boardId);
|
|
427
|
+
if (!cfg) return;
|
|
428
|
+
const { cardsDir, gandalfCardsDir, boardDir } = cfg;
|
|
149
429
|
|
|
150
|
-
// Concatenate agent-instructions*.md into copilot-instructions.md at boardSetupRoot.
|
|
151
430
|
const boardSetupRoot = path.dirname(boardDir);
|
|
152
431
|
fs.mkdirSync(boardSetupRoot, { recursive: true });
|
|
153
432
|
const srcDir = path.dirname(cardsDir);
|
|
@@ -164,22 +443,28 @@ function demoPrepSetup(boardId, service) {
|
|
|
164
443
|
_demoPrepSetupDone.set(boardId, true);
|
|
165
444
|
}
|
|
166
445
|
|
|
446
|
+
function jsonReply(res, status, payload) {
|
|
447
|
+
const body = JSON.stringify(payload);
|
|
448
|
+
res.writeHead(status, { ...CORS_HEADERS, 'Content-Type': 'application/json; charset=utf-8' });
|
|
449
|
+
res.end(body);
|
|
450
|
+
}
|
|
451
|
+
|
|
167
452
|
async function handleDemoSetup(req, res, boardId) {
|
|
168
453
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
setupPerformed = true;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
jsonReply(res, 200, { ok: true, setupPerformed });
|
|
454
|
+
// requireBoardService triggers the factory which runs demoPrepSetup automatically.
|
|
455
|
+
// This endpoint is kept for backward compatibility but setup is now done at board
|
|
456
|
+
// init time inside boardRuntimeFactory — no extra work needed here.
|
|
457
|
+
runtime.requireBoardService(boardId);
|
|
458
|
+
jsonReply(res, 200, { ok: true, setupPerformed: false });
|
|
178
459
|
} catch (err) {
|
|
179
460
|
jsonReply(res, err.statusCode || 500, { error: String((err && err.message) || err) });
|
|
180
461
|
}
|
|
181
462
|
}
|
|
182
463
|
|
|
464
|
+
// ---------------------------------------------------------------------------
|
|
465
|
+
// WorkIQ proxy — host-level concern
|
|
466
|
+
// ---------------------------------------------------------------------------
|
|
467
|
+
|
|
183
468
|
async function handleWorkiqAsk(req, res) {
|
|
184
469
|
let body = '';
|
|
185
470
|
for await (const chunk of req) body += chunk;
|
|
@@ -201,8 +486,6 @@ async function handleWorkiqAsk(req, res) {
|
|
|
201
486
|
return jsonReply(res, 503, { error: `WorkIQ CLI not found at: ${workiqJs}` });
|
|
202
487
|
}
|
|
203
488
|
|
|
204
|
-
// Server has TTY on stdin — workiq can produce output.
|
|
205
|
-
// Use async spawn (not spawnSync) to avoid blocking the event loop during the call.
|
|
206
489
|
await new Promise((resolve) => {
|
|
207
490
|
let stdout = '';
|
|
208
491
|
let stderr = '';
|
|
@@ -243,9 +526,14 @@ async function handleWorkiqAsk(req, res) {
|
|
|
243
526
|
});
|
|
244
527
|
}
|
|
245
528
|
|
|
529
|
+
// ---------------------------------------------------------------------------
|
|
530
|
+
// HTTP server
|
|
531
|
+
// ---------------------------------------------------------------------------
|
|
532
|
+
|
|
246
533
|
const server = http.createServer((req, res) => {
|
|
247
534
|
const method = req.method || 'GET';
|
|
248
|
-
const
|
|
535
|
+
const url = new URL(req.url || '/', 'http://localhost');
|
|
536
|
+
const pathname = url.pathname;
|
|
249
537
|
|
|
250
538
|
if (method === 'OPTIONS') {
|
|
251
539
|
res.writeHead(204, CORS_HEADERS);
|
|
@@ -266,26 +554,29 @@ const server = http.createServer((req, res) => {
|
|
|
266
554
|
return;
|
|
267
555
|
}
|
|
268
556
|
|
|
269
|
-
// All other /api/boards routes are handled by the
|
|
270
|
-
|
|
557
|
+
// All other /api/boards routes are handled by the platform-free runtime
|
|
558
|
+
runtime.handleApi(req, res, url).then((handled) => {
|
|
559
|
+
if (!handled) {
|
|
560
|
+
jsonReply(res, 404, { error: 'Not found' });
|
|
561
|
+
}
|
|
562
|
+
});
|
|
271
563
|
});
|
|
272
564
|
|
|
273
565
|
server.listen(PORT, '127.0.0.1', () => {
|
|
274
566
|
console.log(`[demo-server] listening on http://127.0.0.1:${PORT}`);
|
|
275
|
-
console.log(`[demo-server] setup dir: ${
|
|
276
|
-
console.log(`[demo-server] server-meta store: ${
|
|
277
|
-
console.log(`[demo-server] boards registry key: server-meta/${runtime.boardsRegistryKey}`);
|
|
567
|
+
console.log(`[demo-server] setup dir: ${setupDir}`);
|
|
568
|
+
console.log(`[demo-server] server-meta store: ${serverMetaRef}`);
|
|
278
569
|
console.log('[demo-server] endpoints:');
|
|
279
|
-
console.log(` GET ${
|
|
280
|
-
console.log(` POST ${
|
|
281
|
-
console.log(` GET ${
|
|
282
|
-
console.log(` GET ${
|
|
283
|
-
console.log(` GET ${
|
|
284
|
-
console.log(` GET ${
|
|
285
|
-
console.log(` PATCH ${
|
|
286
|
-
console.log(` POST ${
|
|
287
|
-
console.log(` POST ${
|
|
288
|
-
console.log(` GET ${
|
|
289
|
-
console.log(` GET ${
|
|
570
|
+
console.log(` GET ${apiBasePath} <- list boards`);
|
|
571
|
+
console.log(` POST ${apiBasePath} {id, label?} <- register board`);
|
|
572
|
+
console.log(` GET ${apiBasePath}/:boardId/demo-setup (no-op; setup now runs at board init)`);
|
|
573
|
+
console.log(` GET ${apiBasePath}/:boardId/init-board`);
|
|
574
|
+
console.log(` GET ${apiBasePath}/:boardId/sse`);
|
|
575
|
+
console.log(` GET ${apiBasePath}/:boardId/board-status`);
|
|
576
|
+
console.log(` PATCH ${apiBasePath}/:boardId/cards/:id`);
|
|
577
|
+
console.log(` POST ${apiBasePath}/:boardId/cards/:id/actions`);
|
|
578
|
+
console.log(` POST ${apiBasePath}/:boardId/cards/:id/files`);
|
|
579
|
+
console.log(` GET ${apiBasePath}/:boardId/cards/:id/files/:idx`);
|
|
580
|
+
console.log(` GET ${apiBasePath}/:boardId/cards/:id/chats`);
|
|
290
581
|
console.log(` POST /api/workiq/ask {query} <- WorkIQ (M365 Copilot) proxy`);
|
|
291
582
|
});
|