@fractal-solutions/qflow 1.0.84 → 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
@@ -1,7 +1,5 @@
1
1
  import { AsyncNode } from '../qflow.js';
2
- // You would need to install the 'serialport' library: npm install serialport
3
- import { SerialPort } from 'serialport';
4
- import { ReadlineParser } from '@serialport/parser-readline'; // For reading line-by-line
2
+ import { loadOptional } from '../optional.js';
5
3
  import { log } from '../logger.js';
6
4
  export class HardwareInteractionNode extends AsyncNode {
7
5
  static getToolDefinition() {
@@ -56,6 +54,7 @@ export class HardwareInteractionNode extends AsyncNode {
56
54
  case 'list_ports':
57
55
  // List available serial ports
58
56
  try {
57
+ const { SerialPort } = await loadOptional('serialport');
59
58
  const ports = await SerialPort.list();
60
59
  result = ports.map(p => ({
61
60
  path: p.path,
@@ -76,6 +75,7 @@ export class HardwareInteractionNode extends AsyncNode {
76
75
  throw new Error('For "write" or "read_line" action, `portPath` is required.');
77
76
  }
78
77
  try {
78
+ const { SerialPort } = await loadOptional('serialport');
79
79
  this.port = new SerialPort({ path: portPath, baudRate: baudRate });
80
80
  await new Promise((resolve, reject) => {
81
81
  this.port.on('open', resolve);
@@ -97,6 +97,7 @@ export class HardwareInteractionNode extends AsyncNode {
97
97
  result = { status: 'data_written', data: dataToWrite };
98
98
  }
99
99
  else if (action === 'read_line') {
100
+ const { ReadlineParser } = await loadOptional('@serialport/parser-readline');
100
101
  this.parser = this.port.pipe(new ReadlineParser({ delimiter: '\n' }));
101
102
  result = await new Promise((resolve, reject) => {
102
103
  const timer = setTimeout(() => {
@@ -64,13 +64,7 @@ export class HttpRequestNode extends AsyncNode {
64
64
  required: string[];
65
65
  };
66
66
  };
67
- execAsync(): Promise<{
68
- status: number;
69
- headers: {
70
- [k: string]: string;
71
- };
72
- body: any;
73
- }>;
67
+ execAsync(prepRes: any, shared?: {}, observer?: {}): Promise<any>;
74
68
  parseResponseBody(response: any): Promise<any>;
75
69
  postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
76
70
  }
@@ -1,5 +1,6 @@
1
1
  import { AsyncNode } from '../qflow.js';
2
2
  import { log } from '../logger.js';
3
+ import { withReplaySafeSideEffect } from '../side_effects.js';
3
4
  /**
4
5
  * A flexible node for making generic HTTP requests to any REST API.
5
6
  * @param {object} params - The parameters for the node.
@@ -68,43 +69,55 @@ export class HttpRequestNode extends AsyncNode {
68
69
  }
69
70
  };
70
71
  }
71
- async execAsync() {
72
- const { url, method = 'GET', headers = {}, body, auth } = this.params;
73
- if (!url) {
74
- throw new Error('HttpRequestNode requires a `url` parameter.');
75
- }
76
- const fetchOptions = {
77
- method,
78
- headers: { ...headers }, // Create a mutable copy
79
- };
80
- // Handle Authentication
81
- if (auth) {
82
- if (auth.type === 'bearer' && auth.token) {
83
- fetchOptions.headers['Authorization'] = `Bearer ${auth.token}`;
84
- }
85
- else if (auth.type === 'basic' && auth.username && auth.password) {
86
- const credentials = btoa(`${auth.username}:${auth.password}`);
87
- fetchOptions.headers['Authorization'] = `Basic ${credentials}`;
72
+ async execAsync(prepRes, shared = {}, observer = {}) {
73
+ const execute = async () => {
74
+ const { url, method = 'GET', headers = {}, body, auth } = this.params;
75
+ if (!url) {
76
+ throw new Error('HttpRequestNode requires a `url` parameter.');
88
77
  }
89
- }
90
- // Handle Body
91
- if (body) {
92
- if (typeof body === 'object' && !fetchOptions.headers['Content-Type']) {
93
- fetchOptions.headers['Content-Type'] = 'application/json';
94
- fetchOptions.body = JSON.stringify(body);
78
+ const fetchOptions = {
79
+ method,
80
+ headers: { ...headers }, // Create a mutable copy
81
+ };
82
+ // Handle Authentication
83
+ if (auth) {
84
+ if (auth.type === 'bearer' && auth.token) {
85
+ fetchOptions.headers['Authorization'] = `Bearer ${auth.token}`;
86
+ }
87
+ else if (auth.type === 'basic' && auth.username && auth.password) {
88
+ const credentials = btoa(`${auth.username}:${auth.password}`);
89
+ fetchOptions.headers['Authorization'] = `Basic ${credentials}`;
90
+ }
95
91
  }
96
- else {
97
- fetchOptions.body = body;
92
+ // Handle Body
93
+ if (body) {
94
+ if (typeof body === 'object' && !fetchOptions.headers['Content-Type']) {
95
+ fetchOptions.headers['Content-Type'] = 'application/json';
96
+ fetchOptions.body = JSON.stringify(body);
97
+ }
98
+ else {
99
+ fetchOptions.body = body;
100
+ }
98
101
  }
99
- }
100
- log(`[HTTP] ${method} ${url}`, this.params.logging);
101
- const response = await fetch(url, fetchOptions);
102
- const responseBody = await this.parseResponseBody(response);
103
- return {
104
- status: response.status,
105
- headers: Object.fromEntries(response.headers.entries()),
106
- body: responseBody,
102
+ log(`[HTTP] ${method} ${url}`, this.params.logging);
103
+ const response = await fetch(url, fetchOptions);
104
+ const responseBody = await this.parseResponseBody(response);
105
+ return {
106
+ status: response.status,
107
+ headers: Object.fromEntries(response.headers.entries()),
108
+ body: responseBody,
109
+ };
107
110
  };
111
+ const outcome = await withReplaySafeSideEffect({
112
+ params: this.params,
113
+ shared,
114
+ observer,
115
+ kind: 'http',
116
+ operationId: this.params.operationId,
117
+ onPending: this.params.onPendingSideEffect ?? 'error',
118
+ execute,
119
+ });
120
+ return outcome.result;
108
121
  }
109
122
  async parseResponseBody(response) {
110
123
  const contentType = response.headers.get('content-type') || '';
@@ -1,5 +1,5 @@
1
1
  import { AsyncNode, AsyncFlow } from '../qflow.js';
2
- import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is available
2
+ import { ShellCommandNode } from './shell.js';
3
3
  import path from 'path';
4
4
  import os from 'os';
5
5
  import { promises as fs } from 'fs';
@@ -69,50 +69,50 @@ export class ImageGalleryNode extends AsyncNode {
69
69
  log(`[ImageGalleryNode] Could not copy image ${imagePath}: ${e.message}. Skipping.`, this.params.logging, { type: 'warn' });
70
70
  }
71
71
  }
72
- const htmlContent = `
73
- <!DOCTYPE html>
74
- <html lang="en">
75
- <head>
76
- <meta charset="UTF-8">
77
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
78
- <title>${title}</title>
79
- <style>
80
- body { font-family: sans-serif; margin: 20px; background-color: #f0f0f0; }
81
- h1 { color: #333; }
82
- p { color: #666; }
83
- .gallery-container {
84
- display: grid;
85
- grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
86
- gap: 20px;
87
- padding: 20px;
88
- background-color: #fff;
89
- border-radius: 8px;
90
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
91
- }
92
- .gallery-item {
93
- border: 1px solid #ddd;
94
- border-radius: 4px;
95
- padding: 10px;
96
- text-align: center;
97
- background-color: #f9f9f9;
98
- }
99
- .gallery-item img {
100
- max-width: 100%;
101
- height: auto;
102
- display: block;
103
- margin: 0 auto 10px auto;
104
- border-radius: 4px;
105
- }
106
- </style>
107
- </head>
108
- <body>
109
- <h1>${title}</h1>
110
- <p>${description}</p>
111
- <div class="gallery-container">
112
- ${imageHtml}
113
- </div>
114
- </body>
115
- </html>
72
+ const htmlContent = `
73
+ <!DOCTYPE html>
74
+ <html lang="en">
75
+ <head>
76
+ <meta charset="UTF-8">
77
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
78
+ <title>${title}</title>
79
+ <style>
80
+ body { font-family: sans-serif; margin: 20px; background-color: #f0f0f0; }
81
+ h1 { color: #333; }
82
+ p { color: #666; }
83
+ .gallery-container {
84
+ display: grid;
85
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
86
+ gap: 20px;
87
+ padding: 20px;
88
+ background-color: #fff;
89
+ border-radius: 8px;
90
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
91
+ }
92
+ .gallery-item {
93
+ border: 1px solid #ddd;
94
+ border-radius: 4px;
95
+ padding: 10px;
96
+ text-align: center;
97
+ background-color: #f9f9f9;
98
+ }
99
+ .gallery-item img {
100
+ max-width: 100%;
101
+ height: auto;
102
+ display: block;
103
+ margin: 0 auto 10px auto;
104
+ border-radius: 4px;
105
+ }
106
+ </style>
107
+ </head>
108
+ <body>
109
+ <h1>${title}</h1>
110
+ <p>${description}</p>
111
+ <div class="gallery-container">
112
+ ${imageHtml}
113
+ </div>
114
+ </body>
115
+ </html>
116
116
  `;
117
117
  await fs.writeFile(htmlFilePath, htmlContent);
118
118
  log(`[ImageGalleryNode] Generated HTML gallery at: ${htmlFilePath}`, this.params.logging);
@@ -1,4 +1,12 @@
1
+ export * from "../llm/index.js";
2
+ export * from "../side_effects.js";
3
+ export * from "../bun_nodes.js";
4
+ export * from "../approval.js";
5
+ export * from "../schedule.js";
6
+ export * from "../budget.js";
7
+ export * from "../memory.js";
1
8
  export * from "./llm.js";
9
+ export * from "./streaming_llm.js";
2
10
  export * from "./agent_llm.js";
3
11
  export * from "./data_extractor.js";
4
12
  export * from "./code_interpreter.js";
@@ -1,4 +1,12 @@
1
+ export * from '../llm/index.js';
2
+ export * from '../side_effects.js';
3
+ export * from '../bun_nodes.js';
4
+ export * from '../approval.js';
5
+ export * from '../schedule.js';
6
+ export * from '../budget.js';
7
+ export * from '../memory.js';
1
8
  export * from './llm.js';
9
+ export * from './streaming_llm.js';
2
10
  export * from './agent_llm.js';
3
11
  export * from './data_extractor.js';
4
12
  export * from './code_interpreter.js';
@@ -64,7 +64,7 @@ export class InteractiveWebviewNode extends AsyncNode {
64
64
  };
65
65
  };
66
66
  constructor();
67
- _webviewInstance: Webview | null;
67
+ _webviewInstance: any;
68
68
  execAsync(): Promise<any>;
69
69
  /**
70
70
  * Sends data or executes JavaScript within an open persistent webview.
@@ -75,4 +75,3 @@ export class InteractiveWebviewNode extends AsyncNode {
75
75
  generateHTML(mode: any, params: any): string;
76
76
  }
77
77
  import { AsyncNode } from '../qflow.js';
78
- import { Webview } from 'webview-bun';