@fnet/cli 0.119.3 → 0.120.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/package.json +1 -1
- package/template/fnet/bun/src/default/blocks/call.js.njk +2 -1
- package/template/fnet/bun/src/default/blocks/for.js.njk +1 -1
- package/template/fnet/bun/src/default/blocks/raise.js.njk +1 -1
- package/template/fnet/bun/src/default/blocks/steps.js.njk +2 -2
- package/template/fnet/bun/src/default/blocks/switch.js.njk +33 -37
- package/template/fnet/bun/src/default/blocks/tryexcept.js.njk +15 -1
- package/template/fnet/bun/src/default/macros/block-body-header.js.njk +1 -1
- package/template/fnet/bun/src/default/macros/block-next.js.njk +1 -0
- package/template/fnet/node/src/default/blocks/call.js.njk +2 -1
- package/template/fnet/node/src/default/blocks/for.js.njk +1 -1
- package/template/fnet/node/src/default/blocks/raise.js.njk +1 -1
- package/template/fnet/node/src/default/blocks/steps.js.njk +2 -2
- package/template/fnet/node/src/default/blocks/switch.js.njk +1 -1
- package/template/fnet/node/src/default/blocks/tryexcept.js.njk +17 -13
- package/template/fnet/node/src/default/macros/block-body-header.js.njk +1 -1
- package/template/fnet/node/src/default/macros/block-next.js.njk +1 -0
- package/template/fnode/node/src/cli/index.js.njk +27 -0
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@ export default function Block(context) {
|
|
|
57
57
|
if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
|
|
58
58
|
return resolve(nextBlock);
|
|
59
59
|
|
|
60
|
-
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c});
|
|
60
|
+
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, onError, error });
|
|
61
61
|
currentArgs=nextBlock.withArgs;
|
|
62
62
|
|
|
63
63
|
} while(true);
|
|
@@ -15,7 +15,7 @@ export default function Block(context){
|
|
|
15
15
|
|
|
16
16
|
const raise = {{context.transform.raise | safe}};
|
|
17
17
|
|
|
18
|
-
reject(new Error(raise?.message||raise||"Unknown error"));
|
|
18
|
+
onError? onError(new Error(raise?.message||raise||"Unknown error")) : reject(new Error(raise?.message||raise||"Unknown error"));
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -21,7 +21,7 @@ export default function Block(context){
|
|
|
21
21
|
const { default: {{context.next.codeKey}} } = await import("./{{context.next.codeKey}}");
|
|
22
22
|
{% endif %}
|
|
23
23
|
|
|
24
|
-
let current=new {{context.next.codeKey}}({ parent:_this, engine, flow, caller:c });
|
|
24
|
+
let current=new {{context.next.codeKey}}({ parent:_this, engine, flow, caller:c ,onError, error });
|
|
25
25
|
let currentArgs=args;
|
|
26
26
|
|
|
27
27
|
do {
|
|
@@ -39,7 +39,7 @@ export default function Block(context){
|
|
|
39
39
|
if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
|
|
40
40
|
return resolve(nextBlock);
|
|
41
41
|
|
|
42
|
-
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c});
|
|
42
|
+
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, onError, error });
|
|
43
43
|
currentArgs=nextBlock.withArgs;
|
|
44
44
|
|
|
45
45
|
} while(true);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
|
|
1
2
|
{% include "src/default/macros/block-header.js.njk" %}
|
|
2
3
|
|
|
3
|
-
{%
|
|
4
|
-
{% include "src/default/macros/block-next-header.js.njk" %}
|
|
5
|
-
{% endif %}
|
|
4
|
+
{# {% include "src/default/macros/block-next-header.js.njk" %} #}
|
|
6
5
|
|
|
7
6
|
{% include "src/default/macros/block-modules-header.js.njk" %}
|
|
8
7
|
|
|
@@ -16,56 +15,53 @@
|
|
|
16
15
|
export default function Block(context) {
|
|
17
16
|
|
|
18
17
|
{% include "src/default/macros/block-body-header.js.njk" %}
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
this.run= function (){
|
|
21
20
|
|
|
22
21
|
const args=Array.from(arguments);
|
|
23
22
|
|
|
24
23
|
return new Promise(async (resolve,reject)=>{
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
{% include "src/default/macros/block-run-header.js.njk" %}
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
{% include "src/default/macros/page.js.njk" %}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
else if ({{child.context.transform.condition | safe}})
|
|
38
|
-
{% else %}
|
|
39
|
-
else
|
|
40
|
-
{% endif %}
|
|
41
|
-
{% endif %}
|
|
42
|
-
{
|
|
43
|
-
{% if child.definition.dynamic %}
|
|
44
|
-
// CHILD: {{child.indexKey}}
|
|
45
|
-
const { default: {{child.codeKey}} } = await import("./{{child.codeKey}}");
|
|
29
|
+
{% include "src/default/macros/block-modules.js.njk" %}
|
|
30
|
+
|
|
31
|
+
try{
|
|
32
|
+
|
|
33
|
+
const onError=error=>{
|
|
34
|
+
{% if context.except.definition.dynamic %}
|
|
35
|
+
const { default: {{context.except.codeKey}} } = await import("./{{context.except.codeKey}}");
|
|
46
36
|
{% endif %}
|
|
47
37
|
|
|
48
|
-
const current=new {{
|
|
38
|
+
const current=new {{context.except.codeKey}}({ parent:_this, engine, flow, caller:c , error });
|
|
49
39
|
|
|
50
40
|
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
51
41
|
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
52
42
|
{% endif %}
|
|
53
43
|
|
|
54
|
-
return resolve(await current.run.apply(current,args));
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
{# return resolve(await current.run.apply(current,args)); #}
|
|
45
|
+
current.run.apply(current,args).then(resolve);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
{% if context.try.definition.dynamic %}
|
|
49
|
+
const { default: {{context.try.codeKey}} } = await import("./{{context.try.codeKey}}");
|
|
50
|
+
{% endif %}
|
|
51
|
+
|
|
52
|
+
const current=new {{context.try.codeKey}}({ parent:_this, engine, flow, caller:c ,onError, error });
|
|
53
|
+
|
|
54
|
+
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
55
|
+
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
56
|
+
{% endif %}
|
|
57
|
+
|
|
58
|
+
return resolve(await current.run.apply(current,args));
|
|
59
|
+
}
|
|
60
|
+
catch({{context.except.context.transform.as | safe}}){
|
|
61
|
+
throw new Error('Error must not reach here!');
|
|
62
|
+
}
|
|
67
63
|
});
|
|
68
|
-
}
|
|
64
|
+
}
|
|
69
65
|
|
|
70
66
|
Object.freeze(this);
|
|
71
67
|
}
|
|
@@ -29,7 +29,21 @@ export default function Block(context) {
|
|
|
29
29
|
{% include "src/default/macros/block-modules.js.njk" %}
|
|
30
30
|
|
|
31
31
|
try{
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
const onError=error=>{
|
|
34
|
+
{% if context.except.definition.dynamic %}
|
|
35
|
+
const { default: {{context.except.codeKey}} } = await import("./{{context.except.codeKey}}");
|
|
36
|
+
{% endif %}
|
|
37
|
+
|
|
38
|
+
const current=new {{context.except.codeKey}}({ parent:_this, engine, flow, caller:c, onError });
|
|
39
|
+
|
|
40
|
+
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
41
|
+
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
42
|
+
{% endif %}
|
|
43
|
+
|
|
44
|
+
return resolve(await current.run.apply(current,args));
|
|
45
|
+
};
|
|
46
|
+
|
|
33
47
|
{% if context.try.definition.dynamic %}
|
|
34
48
|
const { default: {{context.try.codeKey}} } = await import("./{{context.try.codeKey}}");
|
|
35
49
|
{% endif %}
|
|
@@ -57,7 +57,7 @@ export default function Block(context) {
|
|
|
57
57
|
if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
|
|
58
58
|
return resolve(nextBlock);
|
|
59
59
|
|
|
60
|
-
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c});
|
|
60
|
+
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, onError, error });
|
|
61
61
|
currentArgs=nextBlock.withArgs;
|
|
62
62
|
|
|
63
63
|
} while(true);
|
|
@@ -15,7 +15,7 @@ export default function Block(context){
|
|
|
15
15
|
|
|
16
16
|
const raise = {{context.transform.raise | safe}};
|
|
17
17
|
|
|
18
|
-
reject(new Error(raise?.message||raise||"Unknown error"));
|
|
18
|
+
onError? onError(new Error(raise?.message||raise||"Unknown error")) : reject(new Error(raise?.message||raise||"Unknown error"));
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -21,7 +21,7 @@ export default function Block(context){
|
|
|
21
21
|
const { default: {{context.next.codeKey}} } = await import("./{{context.next.codeKey}}");
|
|
22
22
|
{% endif %}
|
|
23
23
|
|
|
24
|
-
let current=new {{context.next.codeKey}}({ parent:_this, engine, flow, caller:c });
|
|
24
|
+
let current=new {{context.next.codeKey}}({ parent:_this, engine, flow, caller:c ,onError, error });
|
|
25
25
|
let currentArgs=args;
|
|
26
26
|
|
|
27
27
|
do {
|
|
@@ -39,7 +39,7 @@ export default function Block(context){
|
|
|
39
39
|
if(nextBlock.toType.ParentTypeId!==_this.constructor.TypeId)
|
|
40
40
|
return resolve(nextBlock);
|
|
41
41
|
|
|
42
|
-
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c});
|
|
42
|
+
current=new nextBlock.toType({ parent:_this, engine, flow, caller:c, onError, error });
|
|
43
43
|
currentArgs=nextBlock.withArgs;
|
|
44
44
|
|
|
45
45
|
} while(true);
|
|
@@ -45,7 +45,7 @@ export default function Block(context) {
|
|
|
45
45
|
const { default: {{child.codeKey}} } = await import("./{{child.codeKey}}");
|
|
46
46
|
{% endif %}
|
|
47
47
|
|
|
48
|
-
const current=new {{child.codeKey}}({ parent:_this, engine, flow, caller:c });
|
|
48
|
+
const current=new {{child.codeKey}}({ parent:_this, engine, flow, caller:c, onError });
|
|
49
49
|
|
|
50
50
|
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
51
51
|
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
@@ -30,11 +30,26 @@ export default function Block(context) {
|
|
|
30
30
|
|
|
31
31
|
try{
|
|
32
32
|
|
|
33
|
+
const onError=error=>{
|
|
34
|
+
{% if context.except.definition.dynamic %}
|
|
35
|
+
const { default: {{context.except.codeKey}} } = await import("./{{context.except.codeKey}}");
|
|
36
|
+
{% endif %}
|
|
37
|
+
|
|
38
|
+
const current=new {{context.except.codeKey}}({ parent:_this, engine, flow, caller:c , error });
|
|
39
|
+
|
|
40
|
+
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
41
|
+
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
42
|
+
{% endif %}
|
|
43
|
+
|
|
44
|
+
{# return resolve(await current.run.apply(current,args)); #}
|
|
45
|
+
current.run.apply(current,args).then(resolve);
|
|
46
|
+
};
|
|
47
|
+
|
|
33
48
|
{% if context.try.definition.dynamic %}
|
|
34
49
|
const { default: {{context.try.codeKey}} } = await import("./{{context.try.codeKey}}");
|
|
35
50
|
{% endif %}
|
|
36
51
|
|
|
37
|
-
const current=new {{context.try.codeKey}}({ parent:_this, engine, flow, caller:c });
|
|
52
|
+
const current=new {{context.try.codeKey}}({ parent:_this, engine, flow, caller:c ,onError, error });
|
|
38
53
|
|
|
39
54
|
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
40
55
|
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
@@ -43,18 +58,7 @@ export default function Block(context) {
|
|
|
43
58
|
return resolve(await current.run.apply(current,args));
|
|
44
59
|
}
|
|
45
60
|
catch({{context.except.context.transform.as | safe}}){
|
|
46
|
-
|
|
47
|
-
{% if context.except.definition.dynamic %}
|
|
48
|
-
const { default: {{context.except.codeKey}} } = await import("./{{context.except.codeKey}}");
|
|
49
|
-
{% endif %}
|
|
50
|
-
|
|
51
|
-
const current=new {{context.except.codeKey}}({ parent:_this, engine, flow, caller:c });
|
|
52
|
-
|
|
53
|
-
{% if workflow.parent.context.atom.doc.features.print_runners %}
|
|
54
|
-
console.log(new Date().toLocaleString(),' * ',_this.constructor.IndexKey,' -> ',current.constructor.IndexKey);
|
|
55
|
-
{% endif %}
|
|
56
|
-
|
|
57
|
-
return resolve(await current.run.apply(current,args));
|
|
61
|
+
throw new Error('Error must not reach here!');
|
|
58
62
|
}
|
|
59
63
|
});
|
|
60
64
|
}
|
|
@@ -79,6 +79,14 @@
|
|
|
79
79
|
const port = args['cli-port'] || args.cli_port || 3000;
|
|
80
80
|
const host = args['cli-host'] || args.cli_host || '0.0.0.0';
|
|
81
81
|
const mcpEndpoint = '/mcp';
|
|
82
|
+
const verbose = args['cli-verbose'] || args.cli_verbose || false;
|
|
83
|
+
|
|
84
|
+
// Verbose logging helper
|
|
85
|
+
const log = (...args) => {
|
|
86
|
+
if (verbose) {
|
|
87
|
+
console.log('[MCP]', new Date().toISOString(), ...args);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
82
90
|
|
|
83
91
|
// Map to store transports by session ID
|
|
84
92
|
const transports = {};
|
|
@@ -87,14 +95,21 @@
|
|
|
87
95
|
app.post(mcpEndpoint, async (req, res) => {
|
|
88
96
|
// Check for existing session ID
|
|
89
97
|
const sessionId = req.get('Mcp-Session-Id');
|
|
98
|
+
|
|
99
|
+
log('POST request received');
|
|
100
|
+
log('Session ID:', sessionId || 'none');
|
|
101
|
+
log('Request body:', JSON.stringify(req.body, null, 2));
|
|
102
|
+
|
|
90
103
|
let transport;
|
|
91
104
|
|
|
92
105
|
if (sessionId && transports[sessionId]) {
|
|
93
106
|
// Reuse existing transport
|
|
107
|
+
log('Reusing existing transport for session:', sessionId);
|
|
94
108
|
transport = transports[sessionId];
|
|
95
109
|
} else if (!sessionId && req.body && (req.body.method === 'initialize' ||
|
|
96
110
|
(Array.isArray(req.body) && req.body.some(item => item.method === 'initialize')))) {
|
|
97
111
|
// New initialization request
|
|
112
|
+
log('Creating new transport for initialization');
|
|
98
113
|
transport = new StreamableHTTPServerTransport({
|
|
99
114
|
sessionIdGenerator: () => {
|
|
100
115
|
// Generate cryptographically secure session ID
|
|
@@ -102,6 +117,7 @@
|
|
|
102
117
|
},
|
|
103
118
|
onsessioninitialized: (sessionId) => {
|
|
104
119
|
// Store the transport by session ID
|
|
120
|
+
log('Session initialized:', sessionId);
|
|
105
121
|
transports[sessionId] = transport;
|
|
106
122
|
}
|
|
107
123
|
});
|
|
@@ -109,14 +125,17 @@
|
|
|
109
125
|
// Clean up transport when closed
|
|
110
126
|
transport.onclose = () => {
|
|
111
127
|
if (transport.sessionId) {
|
|
128
|
+
log('Transport closed, cleaning up session:', transport.sessionId);
|
|
112
129
|
delete transports[transport.sessionId];
|
|
113
130
|
}
|
|
114
131
|
};
|
|
115
132
|
|
|
116
133
|
// Connect to the MCP server
|
|
117
134
|
await server.connect(transport);
|
|
135
|
+
log('Server connected to transport');
|
|
118
136
|
} else {
|
|
119
137
|
// Invalid request
|
|
138
|
+
log('Invalid request - no valid session ID');
|
|
120
139
|
return res.status(400).json({
|
|
121
140
|
jsonrpc: '2.0',
|
|
122
141
|
error: {
|
|
@@ -128,17 +147,22 @@
|
|
|
128
147
|
}
|
|
129
148
|
|
|
130
149
|
// Handle the request
|
|
150
|
+
log('Handling request with transport');
|
|
131
151
|
await transport.handleRequest(req, res, req.body);
|
|
132
152
|
});
|
|
133
153
|
|
|
134
154
|
// Reusable handler for GET and DELETE requests
|
|
135
155
|
const handleSessionRequest = async (req, res) => {
|
|
136
156
|
const sessionId = req.get('Mcp-Session-Id');
|
|
157
|
+
log(`${req.method} request received for session:`, sessionId || 'none');
|
|
158
|
+
|
|
137
159
|
if (!sessionId || !transports[sessionId]) {
|
|
160
|
+
log('Invalid or missing session ID');
|
|
138
161
|
return res.status(400).send('Invalid or missing session ID');
|
|
139
162
|
}
|
|
140
163
|
|
|
141
164
|
const transport = transports[sessionId];
|
|
165
|
+
log('Handling request with existing transport');
|
|
142
166
|
await transport.handleRequest(req, res);
|
|
143
167
|
};
|
|
144
168
|
|
|
@@ -152,6 +176,9 @@
|
|
|
152
176
|
console.log(`MCP server started with Streamable HTTP transport`);
|
|
153
177
|
console.log(`Endpoint: http://${host}:${port}${mcpEndpoint}`);
|
|
154
178
|
console.log(`Listening on ${host}:${port}`);
|
|
179
|
+
if (verbose) {
|
|
180
|
+
console.log(`Verbose logging enabled`);
|
|
181
|
+
}
|
|
155
182
|
});
|
|
156
183
|
|
|
157
184
|
return;
|