yaml-flow 8.2.0 → 8.2.1

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.
Files changed (107) hide show
  1. package/browser/asset-integrity.json +3 -3
  2. package/browser/board-livecards-client.js +1 -1
  3. package/browser/board-livecards-localstorage.js +4 -6
  4. package/cli/{board-live-cards-lib-tjYsPt5U.d.ts → board-live-cards-lib-Iq_XAC09.d.ts} +1 -1
  5. package/cli/browser-api/board-live-cards-browser-adapter.d.ts +4 -3
  6. package/cli/browser-api/board-live-cards-browser-adapter.js +2 -2
  7. package/cli/browser-api/card-store-browser-api.d.ts +1 -1
  8. package/cli/node/artifacts-store-cli.js +8 -8
  9. package/cli/node/board-live-cards-cli.js +8 -8
  10. package/cli/node/fs-board-adapter.d.ts +6 -33
  11. package/cli/node/fs-board-adapter.js +10 -8
  12. package/cli/node/step-machine-cli.js +2 -2
  13. package/cli/{types-CSiGbY__.d.ts → types--rXGWbSR.d.ts} +76 -4
  14. package/examples/board/.board-ws/cards/store/_index.json +17 -0
  15. package/examples/board/.board-ws/cards/store/card-market-prices.json +80 -0
  16. package/examples/board/.board-ws/cards/store/card-portfolio-value.json +90 -0
  17. package/examples/board/.board-ws/cards/store/card-portfolio.json +78 -0
  18. package/examples/board/cards/cardT-market-prices.json +6 -4
  19. package/examples/board/cards/cardT-portfolio-value.json +10 -38
  20. package/examples/board/cards/cardT-portfolio.json +9 -4
  21. package/examples/board/demo-shell-with-server.html +3 -3
  22. package/examples/board/server/board-server.js +593 -0
  23. package/examples/board/server/board-worker/source-def-flows/mock-handler/mock-db.js +13 -0
  24. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/.retain/compliance.db +0 -0
  25. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/.retain/optimus.db +0 -0
  26. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/query.cjs +51 -0
  27. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/seed-cpm.cjs +197 -0
  28. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/seed-cpmV2.cjs +128 -0
  29. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/seed-optimus.cjs +352 -0
  30. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/sqlite-config.json +3 -0
  31. package/examples/board/server/board-worker/source-def-flows/sqlite-handler/sqlite-handler.js +84 -0
  32. package/examples/board/{source-def-flows/url.flow.json → server/board-worker/source-def-flows/sqlite.flow.json} +7 -7
  33. package/examples/board/{source-def-handlers → server/board-worker/source-def-flows/url-handler}/http-source-handler.js +29 -21
  34. package/examples/board/server/board-worker/source-def-flows/url.flow.json +73 -0
  35. package/examples/board/{source_def_flows.json → server/board-worker/source_def_flows.json} +61 -115
  36. package/examples/board/server/board-worker/task-executor.js +475 -0
  37. package/examples/board/server/chat-flow/chat-clear-processing.js +41 -0
  38. package/examples/board/server/chat-flow/chat-open-turn.js +144 -0
  39. package/examples/board/server/chat-flow/chat-write-assistant.js +44 -0
  40. package/examples/board/server/chat-flow/copilot-chat/assistant.js +253 -0
  41. package/examples/board/server/chat-flow/echo-probe/assistant.js +28 -0
  42. package/examples/board/server/chat-flow/flow-steps.json +167 -0
  43. package/examples/board/server-config.json +22 -0
  44. package/examples/board/test/server-http-test.js +707 -0
  45. package/examples/board/test/{portfolio-tracker-sse-worker.js → sse-worker.js} +9 -8
  46. package/examples/board-local/demo-shell-localstorage.html +3 -3
  47. package/lib/{artifacts-store-lib-public-DfU9t5-S.d.cts → artifacts-store-lib-public-C5UL5tyG.d.cts} +3 -31
  48. package/lib/{artifacts-store-lib-public-BPW_C15z.d.ts → artifacts-store-lib-public-GD4H-fFp.d.ts} +3 -31
  49. package/lib/artifacts-store-public.d.cts +3 -3
  50. package/lib/artifacts-store-public.d.ts +3 -3
  51. package/lib/board-live-cards-node.cjs +10 -8
  52. package/lib/board-live-cards-node.d.cts +9 -8
  53. package/lib/board-live-cards-node.d.ts +9 -8
  54. package/lib/board-live-cards-node.js +10 -8
  55. package/lib/{board-live-cards-public-W2zK59m0.d.cts → board-live-cards-public-BLXbcBNk.d.cts} +1 -1
  56. package/lib/{board-live-cards-public-B8b_0k_j.d.ts → board-live-cards-public-BZaNb2mi.d.ts} +1 -1
  57. package/lib/board-live-cards-public.d.cts +2 -2
  58. package/lib/board-live-cards-public.d.ts +2 -2
  59. package/lib/board-live-cards-server-runtime.cjs +4 -6
  60. package/lib/board-live-cards-server-runtime.d.cts +3 -3
  61. package/lib/board-live-cards-server-runtime.d.ts +3 -3
  62. package/lib/board-live-cards-server-runtime.js +4 -6
  63. package/lib/board-livegraph-runtime/index.cjs +2 -2
  64. package/lib/board-livegraph-runtime/index.js +2 -2
  65. package/lib/card-store-public.d.cts +2 -2
  66. package/lib/card-store-public.d.ts +2 -2
  67. package/lib/execution-refs.cjs +1 -1
  68. package/lib/execution-refs.js +1 -1
  69. package/lib/index.cjs +1 -1
  70. package/lib/index.d.cts +1 -1
  71. package/lib/index.d.ts +1 -1
  72. package/lib/index.js +1 -1
  73. package/lib/server-runtime/index.cjs +4 -6
  74. package/lib/server-runtime/index.d.cts +4 -4
  75. package/lib/server-runtime/index.d.ts +4 -4
  76. package/lib/server-runtime/index.js +4 -6
  77. package/lib/step-machine-public/index.d.cts +1 -1
  78. package/lib/step-machine-public/index.d.ts +1 -1
  79. package/lib/{storage-interface-BhAON-gW.d.cts → storage-interface-B6ecOulj.d.cts} +25 -3
  80. package/lib/{storage-interface-BhAON-gW.d.ts → storage-interface-B6ecOulj.d.ts} +25 -3
  81. package/lib/stores/index.d.cts +1 -1
  82. package/lib/stores/index.d.ts +1 -1
  83. package/lib/stores/kv.d.cts +1 -1
  84. package/lib/stores/kv.d.ts +1 -1
  85. package/lib/{types-seTI8zta.d.cts → types-Bztd1KoK.d.cts} +55 -3
  86. package/lib/{types-Bm7IFD7r.d.ts → types-D-xVWPdY.d.ts} +55 -3
  87. package/package.json +1 -1
  88. package/examples/board/demo-chat-copilot.flow.json +0 -38
  89. package/examples/board/demo-chat-copilot.js +0 -185
  90. package/examples/board/demo-chat-echo.flow.json +0 -38
  91. package/examples/board/demo-chat-echo.js +0 -92
  92. package/examples/board/demo-server-config.copilot-chat.json +0 -10
  93. package/examples/board/demo-server-config.json +0 -10
  94. package/examples/board/demo-server.js +0 -629
  95. package/examples/board/demo-task-executor.js +0 -721
  96. package/examples/board/gandalf-cards/card-source-kinds.json +0 -36
  97. package/examples/board/gandalf-cards/cards/_index.json +0 -7
  98. package/examples/board/gandalf-cards/cards/card-source-kinds.json +0 -64
  99. package/examples/board/scripts/copilot_wrapper.bat +0 -157
  100. package/examples/board/scripts/copilot_wrapper_helper.ps1 +0 -190
  101. package/examples/board/scripts/workiq_wrapper.mjs +0 -66
  102. package/examples/board/source-def-flows/copilot.flow.json +0 -33
  103. package/examples/board/source-def-flows/url-list.flow.json +0 -33
  104. package/examples/board/source-def-flows/workiq.flow.json +0 -34
  105. package/examples/board/source-def-handlers/copilot-source-handler.js +0 -141
  106. package/examples/board/test/demo-http-test.js +0 -362
  107. /package/examples/board/{source-def-flows → server/board-worker/source-def-flows}/mock.flow.json +0 -0
@@ -1,6 +1,56 @@
1
- import { d as BoardPlatformAdapter, a as CommandResult } from './board-live-cards-public-W2zK59m0.cjs';
1
+ import { d as BoardPlatformAdapter, a as CommandResult } from './board-live-cards-public-BLXbcBNk.cjs';
2
2
  import { ExecutionRef } from './execution-refs.cjs';
3
- import { a as KindValueRef } from './storage-interface-BhAON-gW.cjs';
3
+ import { J as JournalStorage, K as KVStorage, a as KindValueRef } from './storage-interface-B6ecOulj.cjs';
4
+
5
+ /**
6
+ * chat-storage-lib.ts
7
+ *
8
+ * ChatStorage interface + factories backed by JournalStorage (history) and
9
+ * KVStorage (processing state and config).
10
+ *
11
+ * Platform-free — no node:fs or node:crypto imports.
12
+ */
13
+
14
+ interface ChatRecord {
15
+ /** Journal entry id — also used as SSE cursor. */
16
+ id: string;
17
+ role: string;
18
+ text: string;
19
+ files: unknown[];
20
+ updated_at: string;
21
+ }
22
+ interface ChatConfig {
23
+ systemPrompt?: string;
24
+ }
25
+ interface ChatReadAfterResult {
26
+ records: ChatRecord[];
27
+ /** Pass as cursor on the next call. Null when the journal is empty. */
28
+ cursor: string | null;
29
+ }
30
+ interface ChatStorage {
31
+ /** Append a message; returns the new entry id (usable as a cursor). */
32
+ append(cardId: string, role: string, text: string, files?: unknown[]): string;
33
+ /** Read all messages in insertion order. */
34
+ readAll(cardId: string): ChatRecord[];
35
+ /**
36
+ * Read messages appended after cursor.
37
+ * Pass null to read from the beginning.
38
+ */
39
+ readAfter(cardId: string, cursor: string | null): ChatReadAfterResult;
40
+ /** Remove all messages for this card. */
41
+ clear(cardId: string): void;
42
+ setProcessing(cardId: string, active: boolean): void;
43
+ isProcessing(cardId: string): boolean;
44
+ getConfig(cardId: string): ChatConfig;
45
+ setConfig(cardId: string, patch: Partial<ChatConfig>): void;
46
+ }
47
+ /**
48
+ * Create a ChatStorage backed by:
49
+ * - journalFactory(cardId) → JournalStorage (one per-card journal for history)
50
+ * - kv → KVStorage (shared processing flags + config)
51
+ */
52
+ declare function createChatStorage(journalFactory: (cardId: string) => JournalStorage, kv: KVStorage): ChatStorage;
53
+ declare function createInMemoryChatStorage(): ChatStorage;
4
54
 
5
55
  /**
6
56
  * server-runtime/types.ts
@@ -95,6 +145,8 @@ interface SingleBoardRuntimeOptions {
95
145
  boards: BoardContextConfig[];
96
146
  invocationAdapter: InvocationAdapter;
97
147
  chatFlowRunner?: ChatHandlerFlowRunner;
148
+ /** Chat storage backend. Defaults to an in-memory store when omitted. */
149
+ chatStorage?: ChatStorage;
98
150
  notificationTransport?: NotificationTransport;
99
151
  logger?: RuntimeLogger;
100
152
  serverUrl?: string;
@@ -165,4 +217,4 @@ interface RuntimeResponse {
165
217
  end(data?: string | Buffer): void;
166
218
  }
167
219
 
168
- export type { BoardContextConfig as B, ChatHandlerFlowRunner as C, DescribeEnvelope as D, InvocationAdapter as I, MultiBoardRuntimeOptions as M, NotificationTransport as N, RuntimeLogger as R, SingleBoardRuntimeOptions as S, MultiBoardRuntime as a, SingleBoardRuntime as b, RuntimeRequest as c, RuntimeResponse as d };
220
+ export { type BoardContextConfig as B, type ChatHandlerFlowRunner as C, type DescribeEnvelope as D, type InvocationAdapter as I, type MultiBoardRuntimeOptions as M, type NotificationTransport as N, type RuntimeLogger as R, type SingleBoardRuntimeOptions as S, type MultiBoardRuntime as a, type SingleBoardRuntime as b, type ChatStorage as c, type RuntimeRequest as d, type RuntimeResponse as e, type ChatConfig as f, type ChatRecord as g, createChatStorage as h, createInMemoryChatStorage as i };
@@ -1,6 +1,56 @@
1
- import { d as BoardPlatformAdapter, a as CommandResult } from './board-live-cards-public-B8b_0k_j.js';
1
+ import { d as BoardPlatformAdapter, a as CommandResult } from './board-live-cards-public-BZaNb2mi.js';
2
2
  import { ExecutionRef } from './execution-refs.js';
3
- import { a as KindValueRef } from './storage-interface-BhAON-gW.js';
3
+ import { J as JournalStorage, K as KVStorage, a as KindValueRef } from './storage-interface-B6ecOulj.js';
4
+
5
+ /**
6
+ * chat-storage-lib.ts
7
+ *
8
+ * ChatStorage interface + factories backed by JournalStorage (history) and
9
+ * KVStorage (processing state and config).
10
+ *
11
+ * Platform-free — no node:fs or node:crypto imports.
12
+ */
13
+
14
+ interface ChatRecord {
15
+ /** Journal entry id — also used as SSE cursor. */
16
+ id: string;
17
+ role: string;
18
+ text: string;
19
+ files: unknown[];
20
+ updated_at: string;
21
+ }
22
+ interface ChatConfig {
23
+ systemPrompt?: string;
24
+ }
25
+ interface ChatReadAfterResult {
26
+ records: ChatRecord[];
27
+ /** Pass as cursor on the next call. Null when the journal is empty. */
28
+ cursor: string | null;
29
+ }
30
+ interface ChatStorage {
31
+ /** Append a message; returns the new entry id (usable as a cursor). */
32
+ append(cardId: string, role: string, text: string, files?: unknown[]): string;
33
+ /** Read all messages in insertion order. */
34
+ readAll(cardId: string): ChatRecord[];
35
+ /**
36
+ * Read messages appended after cursor.
37
+ * Pass null to read from the beginning.
38
+ */
39
+ readAfter(cardId: string, cursor: string | null): ChatReadAfterResult;
40
+ /** Remove all messages for this card. */
41
+ clear(cardId: string): void;
42
+ setProcessing(cardId: string, active: boolean): void;
43
+ isProcessing(cardId: string): boolean;
44
+ getConfig(cardId: string): ChatConfig;
45
+ setConfig(cardId: string, patch: Partial<ChatConfig>): void;
46
+ }
47
+ /**
48
+ * Create a ChatStorage backed by:
49
+ * - journalFactory(cardId) → JournalStorage (one per-card journal for history)
50
+ * - kv → KVStorage (shared processing flags + config)
51
+ */
52
+ declare function createChatStorage(journalFactory: (cardId: string) => JournalStorage, kv: KVStorage): ChatStorage;
53
+ declare function createInMemoryChatStorage(): ChatStorage;
4
54
 
5
55
  /**
6
56
  * server-runtime/types.ts
@@ -95,6 +145,8 @@ interface SingleBoardRuntimeOptions {
95
145
  boards: BoardContextConfig[];
96
146
  invocationAdapter: InvocationAdapter;
97
147
  chatFlowRunner?: ChatHandlerFlowRunner;
148
+ /** Chat storage backend. Defaults to an in-memory store when omitted. */
149
+ chatStorage?: ChatStorage;
98
150
  notificationTransport?: NotificationTransport;
99
151
  logger?: RuntimeLogger;
100
152
  serverUrl?: string;
@@ -165,4 +217,4 @@ interface RuntimeResponse {
165
217
  end(data?: string | Buffer): void;
166
218
  }
167
219
 
168
- export type { BoardContextConfig as B, ChatHandlerFlowRunner as C, DescribeEnvelope as D, InvocationAdapter as I, MultiBoardRuntimeOptions as M, NotificationTransport as N, RuntimeLogger as R, SingleBoardRuntimeOptions as S, MultiBoardRuntime as a, SingleBoardRuntime as b, RuntimeRequest as c, RuntimeResponse as d };
220
+ export { type BoardContextConfig as B, type ChatHandlerFlowRunner as C, type DescribeEnvelope as D, type InvocationAdapter as I, type MultiBoardRuntimeOptions as M, type NotificationTransport as N, type RuntimeLogger as R, type SingleBoardRuntimeOptions as S, type MultiBoardRuntime as a, type SingleBoardRuntime as b, type ChatStorage as c, type RuntimeRequest as d, type RuntimeResponse as e, type ChatConfig as f, type ChatRecord as g, createChatStorage as h, createInMemoryChatStorage as i };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml-flow",
3
- "version": "8.2.0",
3
+ "version": "8.2.1",
4
4
  "description": "Unified workflow engine: step-machine (sequential) + event-graph (stateless DAG) with pluggable storage",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -1,38 +0,0 @@
1
- {
2
- "id": "demo-chat-copilot",
3
- "settings": {
4
- "start_step": "respond",
5
- "max_total_steps": 5,
6
- "timeout_ms": 120000
7
- },
8
- "steps": {
9
- "respond": {
10
- "description": "Run the Copilot-backed chat responder example",
11
- "handler": {
12
- "type": "ref",
13
- "howToRun": "local-node",
14
- "whatToRun": {
15
- "kind": "fs-path",
16
- "value": "./demo-chat-copilot.js"
17
- },
18
- "meta": "chat-handler"
19
- },
20
- "transitions": {
21
- "success": "completed",
22
- "failure": "failed"
23
- }
24
- }
25
- },
26
- "terminal_states": {
27
- "completed": {
28
- "description": "Copilot chat response completed",
29
- "return_intent": "success",
30
- "return_artifacts": false
31
- },
32
- "failed": {
33
- "description": "Copilot chat response failed",
34
- "return_intent": "failure",
35
- "return_artifacts": false
36
- }
37
- }
38
- }
@@ -1,185 +0,0 @@
1
- /**
2
- * demo-chat-copilot.js - Copilot-backed chat handler example for example-board.
3
- *
4
- * Invoked by reusable-server-runtime after a user message is persisted:
5
- * node demo-chat-copilot.js --boardId <id> --cardId <id> --extraEncJson <base64json>
6
- *
7
- * extraEncJson decodes to:
8
- * boardSetupRoot — absolute path to board root (parent of runtime/, surface/, runtime-out/)
9
- * boardRuntimeDir — relative subdir: 'runtime'
10
- * runtimeStatusDir— relative subdir: 'runtime-out'
11
- * cardsDir — relative subdir: 'surface/tmp-cards'
12
- * chatDir — absolute path to the card's chats directory
13
- * chatProcessingMarkerKey — relative marker key in chats artifacts store (e.g. 'card-portfolio/.processing')
14
- * lastChatFile — filename of the just-written user message, e.g. '001_user.txt'
15
- * serverUrl — base URL of hosting server (e.g. http://127.0.0.1:7799), optional
16
- *
17
- * Invokes copilot_wrapper.bat with a prompt built from conversation history.
18
- * Session dir is per-card: os.tmpdir()/demo-chat-copilot-sessions/<boardId>_<cardId>
19
- */
20
-
21
- import * as fs from 'node:fs';
22
- import * as path from 'node:path';
23
- import * as os from 'node:os';
24
- import { spawnSync } from 'node:child_process';
25
- import { fileURLToPath } from 'node:url';
26
-
27
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
28
-
29
- const args = process.argv.slice(2);
30
- function getArg(name) {
31
- const idx = args.indexOf(name);
32
- return idx !== -1 && args[idx + 1] !== undefined ? args[idx + 1] : null;
33
- }
34
-
35
- const boardId = getArg('--boardId') || '';
36
- const cardId = getArg('--cardId') || '';
37
- const extraStr = getArg('--extraEncJson') || '';
38
-
39
- function readJsonStdin() {
40
- try {
41
- const raw = fs.readFileSync(0, 'utf-8').trim();
42
- if (!raw) return {};
43
- const parsed = JSON.parse(raw);
44
- return parsed && typeof parsed === 'object' ? parsed : {};
45
- } catch {
46
- return {};
47
- }
48
- }
49
-
50
- let extra = {};
51
- if (extraStr) {
52
- try { extra = JSON.parse(Buffer.from(extraStr, 'base64').toString('utf-8')); }
53
- catch { console.error('[demo-chat-copilot] bad --extraEncJson'); process.exit(0); }
54
- } else {
55
- extra = readJsonStdin();
56
- }
57
-
58
- const {
59
- boardSetupRoot,
60
- boardRuntimeDir,
61
- runtimeStatusDir,
62
- cardsDir,
63
- chatDir,
64
- chatsBlobBasePath,
65
- chatsKeyPrefix,
66
- chatProcessingMarkerKey,
67
- lastChatFile,
68
- serverUrl,
69
- } = extra;
70
-
71
- const chatDirAbs = chatDir || (
72
- chatsBlobBasePath && chatsKeyPrefix
73
- ? path.join(String(chatsBlobBasePath), String(chatsKeyPrefix).split('/')[0])
74
- : null
75
- );
76
-
77
- if (!boardSetupRoot || !chatDirAbs || !lastChatFile) {
78
- console.error('[demo-chat-copilot] missing boardSetupRoot/chatDir/lastChatFile');
79
- process.exit(0);
80
- }
81
-
82
- const boardRuntimeDirAbs = path.join(boardSetupRoot, boardRuntimeDir || 'runtime');
83
- const runtimeStatusDirAbs = path.join(boardSetupRoot, runtimeStatusDir || 'runtime-out');
84
- const cardsDirAbs = path.join(boardSetupRoot, cardsDir || path.join('surface', 'tmp-cards'));
85
-
86
- function readHistory(dir) {
87
- try {
88
- return fs.readdirSync(dir)
89
- .filter(f => /^\d+[-_](user|assistant)\.txt$/i.test(f))
90
- .sort()
91
- .map(f => {
92
- const role = /user/i.test(f) ? 'User' : 'Assistant';
93
- let text = '';
94
- try { text = fs.readFileSync(path.join(dir, f), 'utf-8').trim(); } catch {}
95
- return role + ': ' + text;
96
- });
97
- } catch { return []; }
98
- }
99
-
100
- function buildPrompt(cId, bId, history, responseFileRel) {
101
- const cardSetupDirRel = path.join(cardsDir, cId).replace(/\\/g, '/');
102
- const runtimeDirRel = boardRuntimeDir || 'runtime';
103
- const statusDirRel = runtimeStatusDir || 'runtime-out';
104
- const chatDirRel = path.relative(boardSetupRoot, chatDirAbs).replace(/\\/g, '/');
105
- const lastQueryFileRel = path.join(chatDirRel, lastChatFile).replace(/\\/g, '/');
106
-
107
- const contextBlock = [
108
- 'We are currently doing a three way orchestration.',
109
- 'You are the responder who has context of the cards in ' + cardSetupDirRel + ',',
110
- 'card runtime statuses in ' + runtimeDirRel + ',',
111
- 'and computed outputs in ' + statusDirRel + '.',
112
- 'I am just a mediator passing on the query.',
113
- 'The user sees the data available in cards which is rendered, and the status from ' + statusDirRel + '.',
114
- 'Everything else is internal detail not to be exposed to the user.',
115
- 'The conversation history can be found in ' + chatDirRel + ' and the last query is in ' + lastQueryFileRel + '.',
116
- 'Write your response to the user in ' + responseFileRel + ' (relative to your working directory).',
117
- 'Give me only a bare minimum log line on what you did — the response in ' + responseFileRel + ' is what the user will see.',
118
- serverUrl ? 'The host server is available at ' + serverUrl + '.' : '',
119
- ].join(' ');
120
-
121
- return [
122
- contextBlock,
123
- '',
124
- ...history,
125
- 'Assistant:',
126
- ].join('\n');
127
- }
128
-
129
- function runWrapper(prompt, sessionDir, workingDir) {
130
- const wrapperPath = path.join(__dirname, 'scripts', 'copilot_wrapper.bat');
131
- const tmpBase = os.tmpdir();
132
- const ts = Date.now();
133
- const outFile = path.join(tmpBase, 'dcc-out-' + cardId + '-' + ts + '.txt');
134
- const promptFile = path.join(tmpBase, 'dcc-prompt-' + cardId + '-' + ts + '.txt');
135
-
136
- fs.mkdirSync(sessionDir, { recursive: true });
137
- fs.writeFileSync(promptFile, prompt, 'utf-8');
138
-
139
- try {
140
- spawnSync('cmd.exe', [
141
- '/c', wrapperPath,
142
- outFile,
143
- sessionDir,
144
- workingDir,
145
- '@' + promptFile,
146
- 'raw',
147
- 'demo-chat-copilot',
148
- ], { stdio: 'inherit', timeout: 120000 });
149
-
150
- return fs.existsSync(outFile) ? fs.readFileSync(outFile, 'utf-8').trim() : '';
151
- } finally {
152
- try { fs.unlinkSync(promptFile); } catch {}
153
- try { fs.unlinkSync(outFile); } catch {}
154
- }
155
- }
156
-
157
- const serialMatch = String(lastChatFile).match(/^(\d+)/);
158
- const nextSerial = serialMatch ? parseInt(serialMatch[1], 10) + 1 : 1;
159
- const nextName = String(nextSerial).padStart(3, '0') + '-assistant.txt';
160
- const responseFileRel = path.relative(boardSetupRoot, path.join(chatDirAbs, nextName)).replace(/\\/g, '/');
161
-
162
- const history = readHistory(chatDirAbs);
163
- const sessionDir = path.join(os.tmpdir(), 'demo-chat-copilot-sessions', boardId + '_' + cardId);
164
- const workingDir = boardSetupRoot;
165
- const prompt = buildPrompt(cardId, boardId, history, responseFileRel);
166
-
167
- try {
168
- runWrapper(prompt, sessionDir, workingDir);
169
- console.log('[demo-chat-copilot] cardId="' + cardId + '" copilot invoked, response expected at ' + responseFileRel);
170
- } catch (err) {
171
- console.error('[demo-chat-copilot] wrapper failed: ' + (err?.message ?? err));
172
- } finally {
173
- cleanupProcessingMarker();
174
- }
175
-
176
- function cleanupProcessingMarker() {
177
- if (chatProcessingMarkerKey) {
178
- try {
179
- const markerPath = path.join(cardsDirAbs, chatProcessingMarkerKey);
180
- fs.unlinkSync(markerPath);
181
- return;
182
- } catch {}
183
- }
184
- try { fs.unlinkSync(path.join(chatDirAbs, '.processing')); } catch {}
185
- }
@@ -1,38 +0,0 @@
1
- {
2
- "id": "demo-chat-echo",
3
- "settings": {
4
- "start_step": "respond",
5
- "max_total_steps": 5,
6
- "timeout_ms": 10000
7
- },
8
- "steps": {
9
- "respond": {
10
- "description": "Echo the latest chat message back into the card chat log",
11
- "handler": {
12
- "type": "ref",
13
- "howToRun": "local-node",
14
- "whatToRun": {
15
- "kind": "fs-path",
16
- "value": "./demo-chat-echo.js"
17
- },
18
- "meta": "chat-handler"
19
- },
20
- "transitions": {
21
- "success": "completed",
22
- "failure": "failed"
23
- }
24
- }
25
- },
26
- "terminal_states": {
27
- "completed": {
28
- "description": "Echo chat response written",
29
- "return_intent": "success",
30
- "return_artifacts": false
31
- },
32
- "failed": {
33
- "description": "Echo chat response failed",
34
- "return_intent": "failure",
35
- "return_artifacts": false
36
- }
37
- }
38
- }
@@ -1,92 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import {
6
- createArtifactsStore,
7
- createChatArtifactsStore,
8
- createFsBoardPlatformAdapter,
9
- parseRef,
10
- serializeRef,
11
- } from 'yaml-flow/board-live-cards-node';
12
-
13
- function readJsonStdin() {
14
- try {
15
- const raw = fs.readFileSync(0, 'utf-8').trim();
16
- if (!raw) return {};
17
- const parsed = JSON.parse(raw);
18
- return parsed && typeof parsed === 'object' ? parsed : {};
19
- } catch {
20
- return {};
21
- }
22
- }
23
-
24
- function resolveChatDir(extra) {
25
- if (typeof extra.chatDir === 'string' && extra.chatDir.trim()) return extra.chatDir;
26
- if (typeof extra.chatsBlobBasePath === 'string' && typeof extra.chatsKeyPrefix === 'string') {
27
- const cardPart = String(extra.chatsKeyPrefix).split('/')[0];
28
- return path.join(extra.chatsBlobBasePath, cardPart);
29
- }
30
- return '';
31
- }
32
-
33
- function resolveChatStoreContext(extra, chatDir) {
34
- if (typeof extra.chatsBlobBasePath === 'string' && typeof extra.chatsKeyPrefix === 'string') {
35
- return {
36
- chatsRoot: extra.chatsBlobBasePath,
37
- cardPrefix: String(extra.chatsKeyPrefix).split('/')[0],
38
- };
39
- }
40
- if (chatDir) {
41
- return {
42
- chatsRoot: path.dirname(chatDir),
43
- cardPrefix: path.basename(chatDir),
44
- };
45
- }
46
- return { chatsRoot: '', cardPrefix: '' };
47
- }
48
-
49
- const extra = readJsonStdin();
50
- const chatDir = resolveChatDir(extra);
51
- const { chatsRoot, cardPrefix } = resolveChatStoreContext(extra, chatDir);
52
- const lastChatFile = typeof extra.lastChatFile === 'string' ? extra.lastChatFile : '';
53
-
54
- if (!chatDir || !lastChatFile || !chatsRoot || !cardPrefix) {
55
- console.log(JSON.stringify({ result: 'failure', data: {}, error: 'missing chatDir/lastChatFile' }));
56
- process.exit(0);
57
- }
58
-
59
- const lastChatPath = path.join(chatDir, lastChatFile);
60
- let userText = '';
61
- try {
62
- userText = fs.readFileSync(lastChatPath, 'utf-8').trim();
63
- } catch {
64
- console.log(JSON.stringify({ result: 'failure', data: {}, error: 'could not read last chat file' }));
65
- process.exit(0);
66
- }
67
-
68
- const replyText = `Echo: ${userText}`;
69
-
70
- try {
71
- const baseRef = parseRef(serializeRef({ kind: 'fs-path', value: chatsRoot }));
72
- const adapter = createFsBoardPlatformAdapter(baseRef, { suppressSpawn: true });
73
- const artifacts = createArtifactsStore(adapter.blobStorage(''));
74
- const chats = createChatArtifactsStore(artifacts, { indexFileName: '.index.json' });
75
- const serial = chats.nextSerial(cardPrefix);
76
- const storedName = `${String(serial).padStart(3, '0')}_assistant.txt`;
77
-
78
- artifacts.putText(`${cardPrefix}/${storedName}`, replyText + '\n', 'text/plain; charset=utf-8');
79
- chats.appendIndexRecord(cardPrefix, {
80
- serial,
81
- role: 'assistant',
82
- stored_name: storedName,
83
- path: `${cardPrefix}/chats/${storedName}`,
84
- updated_at: new Date().toISOString(),
85
- });
86
- if (typeof extra.chatProcessingMarkerKey === 'string' && extra.chatProcessingMarkerKey.trim()) {
87
- artifacts.remove(extra.chatProcessingMarkerKey.trim());
88
- }
89
- console.log(JSON.stringify({ result: 'success', data: { replyFile: storedName, replyText } }));
90
- } catch (err) {
91
- console.log(JSON.stringify({ result: 'failure', data: {}, error: err instanceof Error ? err.message : String(err) }));
92
- }
@@ -1,10 +0,0 @@
1
- {
2
- "port": 7799,
3
- "cardsDir": "./cards",
4
- "taskExecutorPath": "./demo-task-executor.js",
5
- "chatHandlerFlowPath": "./demo-chat-copilot.flow.json",
6
- "chatSessionsDir": "",
7
- "gandalfCardsDir": "./gandalf-cards",
8
- "gandalfTaskExecutorPath": "./demo-task-executor.js",
9
- "gandalfChatHandlerFlowPath": "./demo-chat-copilot.flow.json"
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "port": 7799,
3
- "cardsDir": "./cards",
4
- "taskExecutorPath": "./demo-task-executor.js",
5
- "chatHandlerFlowPath": "./demo-chat-echo.flow.json",
6
- "chatSessionsDir": "",
7
- "gandalfCardsDir": "./gandalf-cards",
8
- "gandalfTaskExecutorPath": "./demo-task-executor.js",
9
- "gandalfChatHandlerFlowPath": "./demo-chat-echo.flow.json"
10
- }