@fractal-solutions/qflow 1.0.83 → 2.0.0-canary.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/LICENSE +21 -504
  3. package/MIGRATION.md +1130 -0
  4. package/README.md +1432 -823
  5. package/dist/agent/agent.d.ts +4 -22
  6. package/dist/agent/agent.js +4 -364
  7. package/dist/agent/base_agent.d.ts +8 -20
  8. package/dist/agent/base_agent.js +8 -205
  9. package/dist/agent/control_nodes.d.ts +61 -0
  10. package/dist/agent/control_nodes.js +164 -0
  11. package/dist/agent/engine.d.ts +45 -0
  12. package/dist/agent/engine.js +415 -0
  13. package/dist/agent/flow.d.ts +77 -0
  14. package/dist/agent/flow.js +148 -0
  15. package/dist/agent/index.d.ts +12 -0
  16. package/dist/agent/index.js +12 -0
  17. package/dist/agent/lpavrl_agent.d.ts +1 -2
  18. package/dist/agent/lpavrl_agent.js +2 -175
  19. package/dist/agent/ooda_agent.d.ts +1 -2
  20. package/dist/agent/ooda_agent.js +2 -164
  21. package/dist/agent/pema_agent.d.ts +1 -2
  22. package/dist/agent/pema_agent.js +2 -168
  23. package/dist/agent/raor_agent.d.ts +1 -2
  24. package/dist/agent/raor_agent.js +2 -161
  25. package/dist/agent/strategies.d.ts +126 -0
  26. package/dist/agent/strategies.js +159 -0
  27. package/dist/agent/tools.d.ts +1 -0
  28. package/dist/agent/tools.js +42 -24
  29. package/dist/approval.d.ts +42 -0
  30. package/dist/approval.js +86 -0
  31. package/dist/budget.d.ts +103 -0
  32. package/dist/budget.js +133 -0
  33. package/dist/bun_nodes.d.ts +119 -0
  34. package/dist/bun_nodes.js +331 -0
  35. package/dist/contracts.d.ts +30 -0
  36. package/dist/contracts.js +103 -0
  37. package/dist/durable.d.ts +278 -0
  38. package/dist/durable.js +730 -0
  39. package/dist/eval.d.ts +165 -0
  40. package/dist/eval.js +263 -0
  41. package/dist/graph.d.ts +157 -0
  42. package/dist/graph.js +330 -0
  43. package/dist/llm/index.d.ts +359 -0
  44. package/dist/llm/index.js +924 -0
  45. package/dist/logger.js +7 -3
  46. package/dist/mcp/client.d.ts +55 -0
  47. package/dist/mcp/client.js +145 -0
  48. package/dist/mcp/index.d.ts +2 -0
  49. package/dist/mcp/index.js +2 -0
  50. package/dist/mcp/server.d.ts +106 -0
  51. package/dist/mcp/server.js +154 -0
  52. package/dist/mcp/stdio.d.ts +2 -0
  53. package/dist/mcp/stdio.js +3 -0
  54. package/dist/memory.d.ts +101 -0
  55. package/dist/memory.js +217 -0
  56. package/dist/nodes/browser_control.js +5 -4
  57. package/dist/nodes/data_extractor.js +2 -1
  58. package/dist/nodes/data_validation.d.ts +3 -3
  59. package/dist/nodes/data_validation.js +19 -5
  60. package/dist/nodes/database.d.ts +2 -1
  61. package/dist/nodes/database.js +71 -58
  62. package/dist/nodes/gis.js +1 -1
  63. package/dist/nodes/git.d.ts +1 -1
  64. package/dist/nodes/git.js +65 -51
  65. package/dist/nodes/github.d.ts +1 -0
  66. package/dist/nodes/hardware_interaction.d.ts +2 -4
  67. package/dist/nodes/hardware_interaction.js +4 -3
  68. package/dist/nodes/http.d.ts +1 -7
  69. package/dist/nodes/http.js +46 -33
  70. package/dist/nodes/image_gallery.js +45 -45
  71. package/dist/nodes/index.d.ts +8 -0
  72. package/dist/nodes/index.js +8 -0
  73. package/dist/nodes/interactive_webview.d.ts +1 -2
  74. package/dist/nodes/interactive_webview.js +217 -216
  75. package/dist/nodes/multimedia_processing.js +1 -1
  76. package/dist/nodes/navigator.d.ts +7 -0
  77. package/dist/nodes/navigator.js +48 -8
  78. package/dist/nodes/pdf_processor.js +2 -1
  79. package/dist/nodes/remote_execution.js +2 -2
  80. package/dist/nodes/s3.d.ts +1 -0
  81. package/dist/nodes/scheduler.js +2 -2
  82. package/dist/nodes/search.d.ts +1 -1
  83. package/dist/nodes/search.js +3 -2
  84. package/dist/nodes/speech_synthesis.js +2 -1
  85. package/dist/nodes/spreadsheet.d.ts +1 -7
  86. package/dist/nodes/spreadsheet.js +2 -1
  87. package/dist/nodes/streaming_llm.d.ts +51 -0
  88. package/dist/nodes/streaming_llm.js +120 -0
  89. package/dist/nodes/webhook.d.ts +1 -5
  90. package/dist/nodes/webhook.js +106 -93
  91. package/dist/nodes/websockets.js +5 -3
  92. package/dist/nodes/webview.js +3 -2
  93. package/dist/optional.d.ts +32 -0
  94. package/dist/optional.js +61 -0
  95. package/dist/qflow.d.ts +25 -14
  96. package/dist/qflow.js +140 -49
  97. package/dist/schedule.d.ts +41 -0
  98. package/dist/schedule.js +149 -0
  99. package/dist/side_effects.d.ts +50 -0
  100. package/dist/side_effects.js +94 -0
  101. package/dist/streaming.d.ts +35 -0
  102. package/dist/streaming.js +199 -0
  103. package/dist/testing.d.ts +47 -0
  104. package/dist/testing.js +130 -0
  105. package/dist/tool_spec.d.ts +76 -0
  106. package/dist/tool_spec.js +321 -0
  107. package/dist/trace.d.ts +28 -0
  108. package/dist/trace.js +190 -0
  109. package/dist/util.d.ts +57 -0
  110. package/dist/util.js +122 -0
  111. package/package.json +153 -67
  112. package/qflow.config.js +18 -18
  113. package/scripts/postinstall.js +50 -0
  114. package/scripts/verify-package.js +114 -0
@@ -0,0 +1,94 @@
1
+ import { AsyncNode } from './qflow.js';
2
+ import { stableHash, resolveTemplate, SideEffectClaimedError, SideEffectUncertainError } from './util.js';
3
+ export { SideEffectClaimedError, SideEffectUncertainError };
4
+ export async function resolveOperationId(operationId, { params = {}, shared = {}, kind = 'side_effect' } = {}) {
5
+ if (typeof operationId === 'function') {
6
+ return String(await operationId({ params, shared, kind }));
7
+ }
8
+ if (operationId === true || operationId == null) {
9
+ return `${kind}:${stableHash({ params, shared })}`;
10
+ }
11
+ const rendered = resolveTemplate(String(operationId), { ...shared, ...params, params, shared });
12
+ return rendered.trim() ? `${kind}:${rendered}` : `${kind}:${stableHash({ params, shared })}`;
13
+ }
14
+ /**
15
+ * Run an external side effect at most once per operation ID per durable run.
16
+ * Completed operations return their recorded result; reserved-but-unfinished
17
+ * operations raise `SideEffectUncertainError` instead of running twice.
18
+ */
19
+ export async function withReplaySafeSideEffect({ params = {}, shared = {}, observer = {}, execute, kind = 'side_effect', operationId = null, onPending = 'error', workerId = null, leaseMs = null, }) {
20
+ if (typeof execute !== 'function')
21
+ throw new Error('withReplaySafeSideEffect requires an execute function.');
22
+ const checkpointer = params.checkpointer ?? observer.checkpointer;
23
+ const runId = params.runId ?? observer.runId;
24
+ if (!checkpointer || !runId || !operationId) {
25
+ return { result: await execute(), replayed: false, operationId: null, status: 'executed' };
26
+ }
27
+ if (typeof checkpointer.runSideEffect !== 'function') {
28
+ throw new Error('Replay-safe side effects require a checkpointer with runSideEffect().');
29
+ }
30
+ const id = await resolveOperationId(operationId, { params, shared, kind });
31
+ const outcome = await checkpointer.runSideEffect({
32
+ runId,
33
+ operationId: id,
34
+ kind,
35
+ onPending,
36
+ workerId: workerId ?? params.workerId ?? observer.workerId,
37
+ leaseMs: leaseMs ?? params.leaseMs ?? observer.leaseMs,
38
+ execute,
39
+ });
40
+ if (outcome.replayed) {
41
+ observer.emit?.('side_effect:replay', {
42
+ runId,
43
+ operationId: id,
44
+ kind,
45
+ status: outcome.status,
46
+ });
47
+ }
48
+ else {
49
+ observer.emit?.('side_effect:committed', {
50
+ runId,
51
+ operationId: id,
52
+ kind,
53
+ status: outcome.status,
54
+ });
55
+ }
56
+ return outcome;
57
+ }
58
+ /** Generic node wrapper for any side effect that should be replay-safe. */
59
+ export class ReplaySafeNode extends AsyncNode {
60
+ constructor({ execute, operationId = true, kind = 'side_effect', resultKey = 'replaySafeResult', inputKey = 'input', onPending = 'error', workerId = null, leaseMs = null, maxRetries = 1, wait = 0, } = {}) {
61
+ super(maxRetries, wait);
62
+ if (typeof execute !== 'function')
63
+ throw new Error('ReplaySafeNode requires an execute function.');
64
+ this.execute = execute;
65
+ this.operationId = operationId;
66
+ this.kind = kind;
67
+ this.resultKey = resultKey;
68
+ this.inputKey = inputKey;
69
+ this.onPending = onPending;
70
+ this.workerId = workerId;
71
+ this.leaseMs = leaseMs;
72
+ }
73
+ async prepAsync(shared = {}) {
74
+ return shared[this.inputKey] ?? this.params.input ?? null;
75
+ }
76
+ async execAsync(prepRes, shared = {}, observer = {}) {
77
+ const outcome = await withReplaySafeSideEffect({
78
+ params: this.params,
79
+ shared,
80
+ observer,
81
+ kind: this.kind,
82
+ operationId: this.params.operationId ?? this.operationId,
83
+ onPending: this.params.onPendingSideEffect ?? this.onPending,
84
+ workerId: this.params.workerId ?? this.workerId,
85
+ leaseMs: this.params.leaseMs ?? this.leaseMs,
86
+ execute: () => this.execute({ input: prepRes, params: this.params, shared, observer }),
87
+ });
88
+ return outcome.result;
89
+ }
90
+ async postAsync(shared, prepRes, execRes) {
91
+ shared[this.resultKey] = execRes;
92
+ return Object.keys(this.successors).length ? 'default' : execRes;
93
+ }
94
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Stream an OpenAI-compatible chat completion and report each text delta.
3
+ *
4
+ * Works with OpenAI, DeepSeek, OpenRouter and the Hugging Face router because
5
+ * they all speak the same `/chat/completions` SSE dialect. Returns the same
6
+ * final string a non-streaming node would return.
7
+ */
8
+ export function streamChatCompletions({ url, apiKey, model, messages, headers, body, signal, onDelta, onReasoning, }: {
9
+ url: any;
10
+ apiKey: any;
11
+ model: any;
12
+ messages: any;
13
+ headers?: {} | undefined;
14
+ body?: {} | undefined;
15
+ signal: any;
16
+ onDelta: any;
17
+ onReasoning: any;
18
+ }): Promise<{
19
+ text: any;
20
+ reasoning: string;
21
+ finishReason: any;
22
+ usage: any;
23
+ toolCalls: {
24
+ index: any;
25
+ id: any;
26
+ type: any;
27
+ function: {
28
+ name: any;
29
+ arguments: any;
30
+ };
31
+ }[];
32
+ }>;
33
+ export const LLM_DELTA_EVENT: "llm:delta";
34
+ export const LLM_REASONING_EVENT: "llm:reasoning";
35
+ export const LLM_DONE_EVENT: "llm:done";
@@ -0,0 +1,199 @@
1
+ export const LLM_DELTA_EVENT = 'llm:delta';
2
+ export const LLM_REASONING_EVENT = 'llm:reasoning';
3
+ export const LLM_DONE_EVENT = 'llm:done';
4
+ function parseErrorPayload(payload) {
5
+ if (typeof payload === 'string')
6
+ return payload;
7
+ if (payload?.error?.message)
8
+ return payload.error.message;
9
+ return JSON.stringify(payload);
10
+ }
11
+ function extractText(chunk) {
12
+ const choice = chunk?.choices?.[0];
13
+ if (typeof choice?.delta?.content === 'string')
14
+ return choice.delta.content;
15
+ if (typeof choice?.text === 'string')
16
+ return choice.text;
17
+ if (typeof choice?.message?.content === 'string')
18
+ return choice.message.content;
19
+ return '';
20
+ }
21
+ function extractReasoning(chunk) {
22
+ const delta = chunk?.choices?.[0]?.delta ?? {};
23
+ if (typeof delta.reasoning_content === 'string')
24
+ return delta.reasoning_content;
25
+ if (typeof delta.reasoning === 'string')
26
+ return delta.reasoning;
27
+ return '';
28
+ }
29
+ function normalizeToolCalls(calls = []) {
30
+ return calls
31
+ .filter(call => call?.function?.name || call?.id)
32
+ .map(call => ({
33
+ index: call.index ?? 0,
34
+ id: call.id ?? null,
35
+ type: call.type ?? 'function',
36
+ function: {
37
+ name: call.function?.name ?? '',
38
+ arguments: typeof call.function?.arguments === 'string' ? call.function.arguments : JSON.stringify(call.function?.arguments ?? {}),
39
+ },
40
+ }));
41
+ }
42
+ function collectToolCalls(chunk, collected) {
43
+ const calls = chunk?.choices?.[0]?.delta?.tool_calls ?? chunk?.choices?.[0]?.message?.tool_calls ?? [];
44
+ for (const call of calls) {
45
+ const index = call.index ?? 0;
46
+ const existing = collected.find(entry => entry.index === index);
47
+ if (!existing) {
48
+ collected.push({
49
+ index,
50
+ id: call.id ?? null,
51
+ type: call.type ?? 'function',
52
+ function: {
53
+ name: call.function?.name ?? '',
54
+ arguments: typeof call.function?.arguments === 'string' ? call.function.arguments : '',
55
+ },
56
+ });
57
+ continue;
58
+ }
59
+ if (call.id)
60
+ existing.id = call.id;
61
+ if (call.function?.name)
62
+ existing.function.name = call.function.name;
63
+ if (typeof call.function?.arguments === 'string')
64
+ existing.function.arguments += call.function.arguments;
65
+ }
66
+ }
67
+ /**
68
+ * Stream an OpenAI-compatible chat completion and report each text delta.
69
+ *
70
+ * Works with OpenAI, DeepSeek, OpenRouter and the Hugging Face router because
71
+ * they all speak the same `/chat/completions` SSE dialect. Returns the same
72
+ * final string a non-streaming node would return.
73
+ */
74
+ export async function streamChatCompletions({ url, apiKey, model, messages, headers = {}, body = {}, signal, onDelta, onReasoning, }) {
75
+ if (!url)
76
+ throw new Error('streamChatCompletions requires a URL.');
77
+ if (!model)
78
+ throw new Error('streamChatCompletions requires a model.');
79
+ if (!Array.isArray(messages))
80
+ throw new Error('streamChatCompletions requires a messages array.');
81
+ const response = await fetch(url, {
82
+ method: 'POST',
83
+ headers: {
84
+ 'Content-Type': 'application/json',
85
+ ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
86
+ ...headers,
87
+ },
88
+ body: JSON.stringify({ model, messages, stream: true, ...body }),
89
+ signal,
90
+ });
91
+ if (!response.ok) {
92
+ let detail;
93
+ try {
94
+ detail = await response.json();
95
+ }
96
+ catch {
97
+ detail = await response.text();
98
+ }
99
+ throw new Error(`Streaming LLM request failed (${response.status}): ${parseErrorPayload(detail)}`);
100
+ }
101
+ const contentType = response.headers.get('content-type') ?? '';
102
+ if (!response.body || !contentType.includes('text/event-stream')) {
103
+ const data = await response.json();
104
+ const text = extractText({ choices: [{ message: data?.choices?.[0]?.message }] });
105
+ onDelta?.({ delta: text, text, index: 0, raw: data });
106
+ return {
107
+ text,
108
+ reasoning: '',
109
+ finishReason: data?.choices?.[0]?.finish_reason ?? null,
110
+ usage: data?.usage ?? null,
111
+ toolCalls: normalizeToolCalls(data?.choices?.[0]?.message?.tool_calls ?? []),
112
+ };
113
+ }
114
+ const reader = response.body.getReader();
115
+ const decoder = new TextDecoder();
116
+ const result = {
117
+ text: '',
118
+ reasoning: '',
119
+ finishReason: null,
120
+ usage: null,
121
+ toolCalls: [],
122
+ };
123
+ let buffer = '';
124
+ let deltaIndex = 0;
125
+ let doneReceived = false;
126
+ const handleLine = line => {
127
+ if (!line.startsWith('data:'))
128
+ return;
129
+ const data = line.slice(5).trim();
130
+ if (!data)
131
+ return;
132
+ if (data === '[DONE]') {
133
+ doneReceived = true;
134
+ return;
135
+ }
136
+ let chunk;
137
+ try {
138
+ chunk = JSON.parse(data);
139
+ }
140
+ catch {
141
+ return;
142
+ }
143
+ if (chunk.error) {
144
+ throw new Error(`Streaming LLM error: ${parseErrorPayload(chunk)}`);
145
+ }
146
+ result.finishReason = chunk.choices?.[0]?.finish_reason ?? result.finishReason;
147
+ result.usage = chunk.usage ?? result.usage;
148
+ collectToolCalls(chunk, result.toolCalls);
149
+ const delta = extractText(chunk);
150
+ if (delta) {
151
+ const entry = {
152
+ delta,
153
+ text: result.text + delta,
154
+ index: deltaIndex++,
155
+ raw: chunk,
156
+ };
157
+ result.text += delta;
158
+ onDelta?.(entry);
159
+ }
160
+ const reasoningDelta = extractReasoning(chunk);
161
+ if (reasoningDelta) {
162
+ result.reasoning += reasoningDelta;
163
+ onReasoning?.({
164
+ delta: reasoningDelta,
165
+ text: result.reasoning,
166
+ raw: chunk,
167
+ });
168
+ }
169
+ };
170
+ const consume = (value, { final = false } = {}) => {
171
+ buffer += decoder.decode(value, { stream: !final }).replace(/\r\n/g, '\n');
172
+ let newlineIndex;
173
+ while (!doneReceived && (newlineIndex = buffer.indexOf('\n')) !== -1) {
174
+ const line = buffer.slice(0, newlineIndex).trim();
175
+ buffer = buffer.slice(newlineIndex + 1);
176
+ handleLine(line);
177
+ }
178
+ if (final && !doneReceived && buffer.trim()) {
179
+ handleLine(buffer.trim());
180
+ buffer = '';
181
+ }
182
+ };
183
+ try {
184
+ while (!doneReceived) {
185
+ const { done, value } = await reader.read();
186
+ if (done)
187
+ break;
188
+ consume(value);
189
+ }
190
+ if (!doneReceived)
191
+ consume(undefined, { final: true });
192
+ }
193
+ finally {
194
+ if (doneReceived)
195
+ await reader.cancel().catch(() => { });
196
+ reader.releaseLock?.();
197
+ }
198
+ return result;
199
+ }
@@ -0,0 +1,47 @@
1
+ /** Attach to a flow and collect a normalized, snapshot-friendly event trace. */
2
+ export function recordFlow(flow: any): {
3
+ events: any[];
4
+ snapshot(options: any): any[];
5
+ clear(): {
6
+ events: any[];
7
+ snapshot(options: any): any[];
8
+ clear(): /*elided*/ any;
9
+ };
10
+ };
11
+ /** Convert captured events into deterministic snapshots for `expect(...).toMatchSnapshot()`. */
12
+ export function createTraceSnapshot(events?: any[], { includeTiming, includeIds }?: {
13
+ includeTiming?: boolean | undefined;
14
+ includeIds?: boolean | undefined;
15
+ }): any[];
16
+ /**
17
+ * AsyncNode with queued responses and a record of every execution.
18
+ *
19
+ * `postAction` controls the flow action returned from `postAsync`; it defaults
20
+ * to the exec result, which is what most standalone/mock nodes want.
21
+ */
22
+ export class MockNode extends AsyncNode {
23
+ constructor({ name, responses, error, postAction, maxRetries, wait, }?: {
24
+ name?: string | undefined;
25
+ responses?: never[] | undefined;
26
+ error?: null | undefined;
27
+ postAction?: ((execRes: any) => any) | undefined;
28
+ maxRetries?: number | undefined;
29
+ wait?: number | undefined;
30
+ });
31
+ mockName: string;
32
+ responses: any[];
33
+ error: any;
34
+ postAction: (execRes: any) => any;
35
+ calls: any[];
36
+ results: any[];
37
+ execAsync(prepRes: any, shared: any, observer?: {}): Promise<any>;
38
+ postAsync(shared: any, prepRes: any, execRes: any, observer?: {}): Promise<any>;
39
+ reset({ responses }?: {}): this;
40
+ }
41
+ /** A MockNode that mimics the LLM nodes used by agents. */
42
+ export class MockLLMNode extends MockNode {
43
+ constructor(options?: {});
44
+ }
45
+ export { AsyncFlow };
46
+ import { AsyncNode } from './qflow.js';
47
+ import { AsyncFlow } from './qflow.js';
@@ -0,0 +1,130 @@
1
+ import { AsyncNode, AsyncFlow } from './qflow.js';
2
+ function clone(value) {
3
+ try {
4
+ return structuredClone(value);
5
+ }
6
+ catch {
7
+ try {
8
+ return JSON.parse(JSON.stringify(value));
9
+ }
10
+ catch {
11
+ return String(value);
12
+ }
13
+ }
14
+ }
15
+ function stableId(map, prefix, value) {
16
+ if (!map.has(value))
17
+ map.set(value, `${prefix}:${map.size + 1}`);
18
+ return map.get(value);
19
+ }
20
+ const VOLATILE_KEYS = new Set(['startTime', 'endTime', 'duration', 'timestamp', 'stack']);
21
+ /**
22
+ * AsyncNode with queued responses and a record of every execution.
23
+ *
24
+ * `postAction` controls the flow action returned from `postAsync`; it defaults
25
+ * to the exec result, which is what most standalone/mock nodes want.
26
+ */
27
+ export class MockNode extends AsyncNode {
28
+ constructor({ name = 'MockNode', responses = [], error = null, postAction = execRes => execRes, maxRetries = 1, wait = 0, } = {}) {
29
+ super(maxRetries, wait);
30
+ this.mockName = name;
31
+ this.responses = [...responses];
32
+ this.error = error;
33
+ this.postAction = postAction;
34
+ this.calls = [];
35
+ this.results = [];
36
+ }
37
+ async execAsync(prepRes, shared, observer = {}) {
38
+ this.calls.push({
39
+ index: this.calls.length,
40
+ prepRes: clone(prepRes),
41
+ shared: clone(shared),
42
+ params: clone(this.params),
43
+ flowId: observer.flowId,
44
+ });
45
+ if (this.error) {
46
+ const failure = typeof this.error === 'function'
47
+ ? await this.error(prepRes, shared, observer)
48
+ : this.error;
49
+ throw failure instanceof Error ? failure : new Error(String(failure));
50
+ }
51
+ if (this.responses.length === 0)
52
+ return undefined;
53
+ const response = this.responses.shift();
54
+ return typeof response === 'function'
55
+ ? await response(prepRes, shared, observer)
56
+ : response;
57
+ }
58
+ async postAsync(shared, prepRes, execRes, observer = {}) {
59
+ this.results.push(clone(execRes));
60
+ return typeof this.postAction === 'function'
61
+ ? await this.postAction(execRes, shared, prepRes, observer)
62
+ : this.postAction;
63
+ }
64
+ reset({ responses } = {}) {
65
+ this.calls = [];
66
+ this.results = [];
67
+ if (responses)
68
+ this.responses = [...responses];
69
+ return this;
70
+ }
71
+ }
72
+ /** A MockNode that mimics the LLM nodes used by agents. */
73
+ export class MockLLMNode extends MockNode {
74
+ constructor(options = {}) {
75
+ super({ name: 'MockLLMNode', postAction: execRes => execRes, ...options });
76
+ }
77
+ }
78
+ /** Attach to a flow and collect a normalized, snapshot-friendly event trace. */
79
+ export function recordFlow(flow) {
80
+ const events = [];
81
+ flow.onAny(entry => events.push({ event: entry.event, payload: entry.payload }));
82
+ return {
83
+ events,
84
+ snapshot(options) {
85
+ return createTraceSnapshot(events, options);
86
+ },
87
+ clear() {
88
+ events.length = 0;
89
+ return this;
90
+ },
91
+ };
92
+ }
93
+ /** Convert captured events into deterministic snapshots for `expect(...).toMatchSnapshot()`. */
94
+ export function createTraceSnapshot(events = [], { includeTiming = false, includeIds = false } = {}) {
95
+ const flowIds = new Map();
96
+ const runIds = new Map();
97
+ const clean = (value, key) => {
98
+ if (!includeIds && (key === 'flowId' || key === 'parentFlowId') && value != null) {
99
+ return stableId(flowIds, 'flow', String(value));
100
+ }
101
+ if (!includeIds && key === 'runId' && value != null) {
102
+ return stableId(runIds, 'run', String(value));
103
+ }
104
+ if (value instanceof Error) {
105
+ return { name: value.name, message: value.message };
106
+ }
107
+ if (typeof value === 'function') {
108
+ return '[Function]';
109
+ }
110
+ if (Array.isArray(value)) {
111
+ return value.map(item => clean(item));
112
+ }
113
+ if (value && typeof value === 'object') {
114
+ const result = {};
115
+ for (const [childKey, childValue] of Object.entries(value)) {
116
+ if (!includeTiming && VOLATILE_KEYS.has(childKey))
117
+ continue;
118
+ result[childKey] = clean(childValue, childKey);
119
+ }
120
+ return result;
121
+ }
122
+ return value;
123
+ };
124
+ return events.map(entry => {
125
+ const event = entry.event;
126
+ const payload = entry.payload ?? entry;
127
+ return { event, ...clean(payload) };
128
+ });
129
+ }
130
+ export { AsyncFlow };
@@ -0,0 +1,76 @@
1
+ export function toolSpecFromNode(nodeOrClass: any, overrides?: {}): ToolSpec;
2
+ export function generateToolDocs(registry: any, { title }?: {
3
+ title?: string | undefined;
4
+ }): string;
5
+ /**
6
+ * Provider-neutral tool description. The same object can produce agent tool
7
+ * definitions, MCP tools, LLM tool calls, and Markdown documentation.
8
+ */
9
+ export class ToolSpec {
10
+ constructor(spec?: {});
11
+ name: any;
12
+ namespace: any;
13
+ description: any;
14
+ parameters: any;
15
+ capabilities: Set<any>;
16
+ permissions: Set<any>;
17
+ idempotencyKey: any;
18
+ timeoutMs: any;
19
+ dryRun: any;
20
+ sideEffect: any;
21
+ node: any;
22
+ execute: any;
23
+ hidden: boolean;
24
+ metadata: any;
25
+ get qualifiedName(): any;
26
+ has(capability: any): boolean;
27
+ hasAll(capabilities?: any[]): boolean;
28
+ definition(): {
29
+ name: any;
30
+ description: any;
31
+ parameters: any;
32
+ capabilities: any[];
33
+ permissions: any[];
34
+ sideEffect: any;
35
+ idempotencyKey: any;
36
+ timeoutMs: any;
37
+ dryRun: boolean;
38
+ };
39
+ toJSONSchema(): any;
40
+ toMCPTool(): {
41
+ name: any;
42
+ description: any;
43
+ inputSchema: any;
44
+ };
45
+ toLLMTool(): {
46
+ type: string;
47
+ function: {
48
+ name: any;
49
+ description: any;
50
+ parameters: any;
51
+ };
52
+ };
53
+ validate(args?: {}): string[];
54
+ }
55
+ /** Namespaced, capability-filtered registry shared by agents, MCP and docs. */
56
+ export class ToolRegistry {
57
+ constructor({ tools, grantedCapabilities, grantedPermissions, idempotencyStore, }?: {
58
+ tools?: never[] | undefined;
59
+ grantedCapabilities?: null | undefined;
60
+ grantedPermissions?: null | undefined;
61
+ idempotencyStore?: Map<any, any> | undefined;
62
+ });
63
+ tools: Map<any, any>;
64
+ grantedCapabilities: Set<any> | null;
65
+ grantedPermissions: Set<any> | null;
66
+ idempotencyStore: Map<any, any>;
67
+ register(tool: any, overrides?: {}): ToolSpec;
68
+ unregister(name: any): boolean;
69
+ allowed(spec: any, options?: {}): boolean;
70
+ list(options?: {}): any[];
71
+ get(name: any): any;
72
+ definitions(options?: {}): any[];
73
+ mcpTools(options?: {}): any[];
74
+ llmTools(options?: {}): any[];
75
+ execute(name: any, args?: {}, options?: {}): Promise<any>;
76
+ }