@timo9378/flow2code 0.1.2 → 0.1.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 (49) hide show
  1. package/CHANGELOG.md +56 -56
  2. package/LICENSE +21 -21
  3. package/README.md +230 -223
  4. package/dist/cli.js +70 -5
  5. package/dist/compiler.cjs +9 -3
  6. package/dist/compiler.js +9 -3
  7. package/dist/server.d.ts +27 -27
  8. package/dist/server.js +882 -4
  9. package/out/404.html +1 -1
  10. package/out/__next.__PAGE__.txt +4 -4
  11. package/out/__next._full.txt +13 -13
  12. package/out/__next._head.txt +4 -4
  13. package/out/__next._index.txt +6 -6
  14. package/out/__next._tree.txt +2 -2
  15. package/out/_next/static/chunks/2be31674b47c1089.js +49 -0
  16. package/out/_next/static/chunks/{41ec06cb3e44c96a.js → 5f1a9fec0e69c483.js} +2 -2
  17. package/out/_next/static/chunks/6b84376656bd9887.js +1 -0
  18. package/out/_next/static/chunks/83ab8820627f8bfe.css +1 -0
  19. package/out/_next/static/chunks/a6dad97d9634a72d.js.map +1 -1
  20. package/out/_next/static/chunks/ab8888d4b78b94be.js +5 -0
  21. package/out/_next/static/chunks/acf223168ac429f7.js +1 -0
  22. package/out/_next/static/chunks/{8486af13ea541d4d.js → b112c2f519e4b429.js} +1 -1
  23. package/out/_next/static/chunks/{4b43c69e91d19eee.js → b163b5d7cccbcf42.js} +1 -1
  24. package/out/_next/static/chunks/b6e8711267bccbbd.js +1 -0
  25. package/out/_next/static/chunks/fbca595129527827.js +1 -0
  26. package/out/_next/static/chunks/{turbopack-b95472a0b02a2729.js → turbopack-576234c945ffdc44.js} +1 -1
  27. package/out/_not-found/__next._full.txt +11 -11
  28. package/out/_not-found/__next._head.txt +4 -4
  29. package/out/_not-found/__next._index.txt +6 -6
  30. package/out/_not-found/{__next._not-found.__PAGE__.txt → __next._not-found/__PAGE__.txt} +2 -2
  31. package/out/_not-found/__next._not-found.txt +3 -3
  32. package/out/_not-found/__next._tree.txt +2 -2
  33. package/out/_not-found.html +1 -1
  34. package/out/_not-found.txt +11 -11
  35. package/out/index.html +2 -2
  36. package/out/index.txt +13 -13
  37. package/package.json +124 -121
  38. package/scripts/postinstall.cjs +23 -0
  39. package/out/_next/static/chunks/324e22de375c241a.css +0 -1
  40. package/out/_next/static/chunks/3638bc7cb3d72bbe.js +0 -379
  41. package/out/_next/static/chunks/46e882944a7f3aed.js +0 -1
  42. package/out/_next/static/chunks/59b058cf94cc555e.js +0 -1
  43. package/out/_next/static/chunks/6e36daee8960e188.js +0 -5
  44. package/out/_next/static/chunks/80a5431d4e78c469.js +0 -1
  45. package/out/_next/static/chunks/8a38426c5ed81587.js +0 -1
  46. package/out/_next/static/chunks/edbd80df6004e249.js +0 -52
  47. /package/out/_next/static/{dSD-EjLFfv3PUm7xo33fg → OIo5LFjdea8u6u4evHHQo}/_buildManifest.js +0 -0
  48. /package/out/_next/static/{dSD-EjLFfv3PUm7xo33fg → OIo5LFjdea8u6u4evHHQo}/_clientMiddlewareManifest.json +0 -0
  49. /package/out/_next/static/{dSD-EjLFfv3PUm7xo33fg → OIo5LFjdea8u6u4evHHQo}/_ssgManifest.js +0 -0
package/dist/cli.js CHANGED
@@ -2840,9 +2840,13 @@ function buildEdges(ctx) {
2840
2840
  }
2841
2841
  }
2842
2842
  }
2843
+ const resolveTargetPort = (targetNodeId, fallback) => {
2844
+ const tgt = ctx.nodes.get(targetNodeId);
2845
+ return tgt?.inputs?.[0]?.id ?? fallback;
2846
+ };
2843
2847
  for (const [parentId, children] of ctx.controlFlowChildren) {
2844
2848
  for (const child of children) {
2845
- addEdge(parentId, child.portId, child.nodeId, "input");
2849
+ addEdge(parentId, child.portId, child.nodeId, resolveTargetPort(child.nodeId, "input"));
2846
2850
  connectedTargets.add(child.nodeId);
2847
2851
  }
2848
2852
  }
@@ -2851,7 +2855,7 @@ function buildEdges(ctx) {
2851
2855
  const predNode = ctx.nodes.get(predId);
2852
2856
  if (!predNode) continue;
2853
2857
  const sourcePort = predNode.outputs[0]?.id ?? "output";
2854
- addEdge(predId, sourcePort, nodeId, "input");
2858
+ addEdge(predId, sourcePort, nodeId, resolveTargetPort(nodeId, "input"));
2855
2859
  }
2856
2860
  }
2857
2861
  function computeAuditHints(ctx) {
@@ -2983,7 +2987,9 @@ function trackVariableUses(nodeId, expression, ctx) {
2983
2987
  if (seen.has(ident)) continue;
2984
2988
  seen.add(ident);
2985
2989
  if (ctx.varDefs.has(ident)) {
2986
- uses.push({ nodeId, portId: "input", varName: ident });
2990
+ const targetNode = ctx.nodes.get(nodeId);
2991
+ const portId = targetNode?.inputs?.[0]?.id ?? "input";
2992
+ uses.push({ nodeId, portId, varName: ident });
2987
2993
  }
2988
2994
  }
2989
2995
  if (uses.length > 0) {
@@ -3792,10 +3798,55 @@ function handleImportOpenAPI(body) {
3792
3798
  };
3793
3799
  }
3794
3800
  }
3801
+ function handleDecompile(body) {
3802
+ try {
3803
+ const { code, fileName, functionName } = body;
3804
+ if (!code || typeof code !== "string") {
3805
+ return { status: 400, body: { success: false, error: "Missing 'code' string in request body" } };
3806
+ }
3807
+ if (code.trim().length === 0) {
3808
+ return { status: 400, body: { success: false, error: "Code is empty" } };
3809
+ }
3810
+ const result = decompile(code, {
3811
+ fileName: fileName ?? "input.ts",
3812
+ functionName,
3813
+ audit: true
3814
+ });
3815
+ if (!result.success) {
3816
+ return {
3817
+ status: 422,
3818
+ body: {
3819
+ success: false,
3820
+ errors: result.errors ?? ["Decompile failed"],
3821
+ confidence: result.confidence
3822
+ }
3823
+ };
3824
+ }
3825
+ return {
3826
+ status: 200,
3827
+ body: {
3828
+ success: true,
3829
+ ir: result.ir,
3830
+ confidence: result.confidence,
3831
+ errors: result.errors ?? [],
3832
+ audit: result.audit ?? []
3833
+ }
3834
+ };
3835
+ } catch (err) {
3836
+ return {
3837
+ status: 500,
3838
+ body: {
3839
+ success: false,
3840
+ error: `Decompile error: ${err instanceof Error ? err.message : String(err)}`
3841
+ }
3842
+ };
3843
+ }
3844
+ }
3795
3845
  var init_handlers = __esm({
3796
3846
  "src/server/handlers.ts"() {
3797
3847
  "use strict";
3798
3848
  init_compiler();
3849
+ init_decompiler();
3799
3850
  init_validator();
3800
3851
  init_security();
3801
3852
  init_converter();
@@ -3807,6 +3858,7 @@ var init_handlers = __esm({
3807
3858
  var server_exports = {};
3808
3859
  __export(server_exports, {
3809
3860
  handleCompile: () => handleCompile,
3861
+ handleDecompile: () => handleDecompile,
3810
3862
  handleGenerate: () => handleGenerate,
3811
3863
  handleImportOpenAPI: () => handleImportOpenAPI,
3812
3864
  startServer: () => startServer
@@ -3956,6 +4008,11 @@ async function handleRequest(req, res, staticDir, projectRoot) {
3956
4008
  sendJson(res, result.status, result.body);
3957
4009
  return;
3958
4010
  }
4011
+ if (pathname === "/api/decompile") {
4012
+ const result = handleDecompile(body);
4013
+ sendJson(res, result.status, result.body);
4014
+ return;
4015
+ }
3959
4016
  sendJson(res, 404, { error: `Unknown API route: ${pathname}` });
3960
4017
  return;
3961
4018
  }
@@ -3983,6 +4040,7 @@ function startServer(options = {}) {
3983
4040
  res.end("Internal Server Error");
3984
4041
  });
3985
4042
  });
4043
+ const hasUI = existsSync3(join3(staticDir, "index.html"));
3986
4044
  server.listen(port, host, () => {
3987
4045
  const url = `http://localhost:${port}`;
3988
4046
  if (options.onReady) {
@@ -3993,8 +4051,15 @@ function startServer(options = {}) {
3993
4051
  console.log(` \u251C\u2500 Local: ${url}`);
3994
4052
  console.log(` \u251C\u2500 API: ${url}/api/compile`);
3995
4053
  console.log(` \u251C\u2500 Static: ${staticDir}`);
3996
- console.log(` \u2514\u2500 Project: ${projectRoot}
3997
- `);
4054
+ console.log(` \u2514\u2500 Project: ${projectRoot}`);
4055
+ if (!hasUI) {
4056
+ console.log();
4057
+ console.log(` \u26A0\uFE0F UI files not found (out/index.html missing).`);
4058
+ console.log(` The API endpoints still work, but the visual editor won't load.`);
4059
+ console.log(` To fix: run "pnpm build:ui" in the flow2code source directory,`);
4060
+ console.log(` or reinstall from npm: npm i @timo9378/flow2code@latest`);
4061
+ }
4062
+ console.log();
3998
4063
  }
3999
4064
  });
4000
4065
  return server;
package/dist/compiler.cjs CHANGED
@@ -2960,9 +2960,13 @@ function buildEdges(ctx) {
2960
2960
  }
2961
2961
  }
2962
2962
  }
2963
+ const resolveTargetPort = (targetNodeId, fallback) => {
2964
+ const tgt = ctx.nodes.get(targetNodeId);
2965
+ return tgt?.inputs?.[0]?.id ?? fallback;
2966
+ };
2963
2967
  for (const [parentId, children] of ctx.controlFlowChildren) {
2964
2968
  for (const child of children) {
2965
- addEdge(parentId, child.portId, child.nodeId, "input");
2969
+ addEdge(parentId, child.portId, child.nodeId, resolveTargetPort(child.nodeId, "input"));
2966
2970
  connectedTargets.add(child.nodeId);
2967
2971
  }
2968
2972
  }
@@ -2971,7 +2975,7 @@ function buildEdges(ctx) {
2971
2975
  const predNode = ctx.nodes.get(predId);
2972
2976
  if (!predNode) continue;
2973
2977
  const sourcePort = predNode.outputs[0]?.id ?? "output";
2974
- addEdge(predId, sourcePort, nodeId, "input");
2978
+ addEdge(predId, sourcePort, nodeId, resolveTargetPort(nodeId, "input"));
2975
2979
  }
2976
2980
  }
2977
2981
  function computeAuditHints(ctx) {
@@ -3103,7 +3107,9 @@ function trackVariableUses(nodeId, expression, ctx) {
3103
3107
  if (seen.has(ident)) continue;
3104
3108
  seen.add(ident);
3105
3109
  if (ctx.varDefs.has(ident)) {
3106
- uses.push({ nodeId, portId: "input", varName: ident });
3110
+ const targetNode = ctx.nodes.get(nodeId);
3111
+ const portId = targetNode?.inputs?.[0]?.id ?? "input";
3112
+ uses.push({ nodeId, portId, varName: ident });
3107
3113
  }
3108
3114
  }
3109
3115
  if (uses.length > 0) {
package/dist/compiler.js CHANGED
@@ -2896,9 +2896,13 @@ function buildEdges(ctx) {
2896
2896
  }
2897
2897
  }
2898
2898
  }
2899
+ const resolveTargetPort = (targetNodeId, fallback) => {
2900
+ const tgt = ctx.nodes.get(targetNodeId);
2901
+ return tgt?.inputs?.[0]?.id ?? fallback;
2902
+ };
2899
2903
  for (const [parentId, children] of ctx.controlFlowChildren) {
2900
2904
  for (const child of children) {
2901
- addEdge(parentId, child.portId, child.nodeId, "input");
2905
+ addEdge(parentId, child.portId, child.nodeId, resolveTargetPort(child.nodeId, "input"));
2902
2906
  connectedTargets.add(child.nodeId);
2903
2907
  }
2904
2908
  }
@@ -2907,7 +2911,7 @@ function buildEdges(ctx) {
2907
2911
  const predNode = ctx.nodes.get(predId);
2908
2912
  if (!predNode) continue;
2909
2913
  const sourcePort = predNode.outputs[0]?.id ?? "output";
2910
- addEdge(predId, sourcePort, nodeId, "input");
2914
+ addEdge(predId, sourcePort, nodeId, resolveTargetPort(nodeId, "input"));
2911
2915
  }
2912
2916
  }
2913
2917
  function computeAuditHints(ctx) {
@@ -3039,7 +3043,9 @@ function trackVariableUses(nodeId, expression, ctx) {
3039
3043
  if (seen.has(ident)) continue;
3040
3044
  seen.add(ident);
3041
3045
  if (ctx.varDefs.has(ident)) {
3042
- uses.push({ nodeId, portId: "input", varName: ident });
3046
+ const targetNode = ctx.nodes.get(nodeId);
3047
+ const portId = targetNode?.inputs?.[0]?.id ?? "input";
3048
+ uses.push({ nodeId, portId, varName: ident });
3043
3049
  }
3044
3050
  }
3045
3051
  if (uses.length > 0) {
package/dist/server.d.ts CHANGED
@@ -1,27 +1,27 @@
1
- import type { FlowIR } from "./compiler.js";
2
- import type { Server } from "node:http";
3
-
4
- export interface ApiResponse {
5
- status: number;
6
- body: Record<string, unknown>;
7
- }
8
-
9
- export interface CompileRequest {
10
- ir?: FlowIR;
11
- write?: boolean;
12
- }
13
-
14
- export interface ServerOptions {
15
- port?: number;
16
- host?: string;
17
- staticDir?: string;
18
- /** User project root directory (defaults to process.cwd()) */
19
- projectRoot?: string;
20
- /** Callback after server starts */
21
- onReady?: (url: string) => void;
22
- }
23
-
24
- export declare function handleCompile(body: CompileRequest, projectRoot: string): ApiResponse;
25
- export declare function handleGenerate(body: { prompt?: string }): Promise<ApiResponse>;
26
- export declare function handleImportOpenAPI(body: { spec?: unknown; filter?: { tags?: string[]; paths?: string[] } }): ApiResponse;
27
- export declare function startServer(options?: ServerOptions): Server;
1
+ import type { FlowIR } from "./compiler.js";
2
+ import type { Server } from "node:http";
3
+
4
+ export interface ApiResponse {
5
+ status: number;
6
+ body: Record<string, unknown>;
7
+ }
8
+
9
+ export interface CompileRequest {
10
+ ir?: FlowIR;
11
+ write?: boolean;
12
+ }
13
+
14
+ export interface ServerOptions {
15
+ port?: number;
16
+ host?: string;
17
+ staticDir?: string;
18
+ /** User project root directory (defaults to process.cwd()) */
19
+ projectRoot?: string;
20
+ /** Callback after server starts */
21
+ onReady?: (url: string) => void;
22
+ }
23
+
24
+ export declare function handleCompile(body: CompileRequest, projectRoot: string): ApiResponse;
25
+ export declare function handleGenerate(body: { prompt?: string }): Promise<ApiResponse>;
26
+ export declare function handleImportOpenAPI(body: { spec?: unknown; filter?: { tags?: string[]; paths?: string[] } }): ApiResponse;
27
+ export declare function startServer(options?: ServerOptions): Server;