@vistagenic/vista 0.2.16 → 0.3.2

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 (153) hide show
  1. package/bin/vista.js +184 -177
  2. package/dist/ai/agent.d.ts +37 -0
  3. package/dist/ai/agent.js +385 -0
  4. package/dist/ai/embeddings.d.ts +11 -0
  5. package/dist/ai/embeddings.js +71 -0
  6. package/dist/ai/index.d.ts +10 -0
  7. package/dist/ai/index.js +26 -0
  8. package/dist/ai/memory.d.ts +16 -0
  9. package/dist/ai/memory.js +39 -0
  10. package/dist/ai/observability.d.ts +21 -0
  11. package/dist/ai/observability.js +69 -0
  12. package/dist/ai/providers/anthropic.d.ts +2 -0
  13. package/dist/ai/providers/anthropic.js +190 -0
  14. package/dist/ai/providers/base.d.ts +7 -0
  15. package/dist/ai/providers/base.js +85 -0
  16. package/dist/ai/providers/gemini.d.ts +2 -0
  17. package/dist/ai/providers/gemini.js +194 -0
  18. package/dist/ai/providers/index.d.ts +5 -0
  19. package/dist/ai/providers/index.js +21 -0
  20. package/dist/ai/providers/mock.d.ts +8 -0
  21. package/dist/ai/providers/mock.js +77 -0
  22. package/dist/ai/providers/openai.d.ts +2 -0
  23. package/dist/ai/providers/openai.js +211 -0
  24. package/dist/ai/rag.d.ts +35 -0
  25. package/dist/ai/rag.js +110 -0
  26. package/dist/ai/react/index.d.ts +1 -0
  27. package/dist/ai/react/index.js +17 -0
  28. package/dist/ai/react/react-server.d.ts +1 -0
  29. package/dist/ai/react/react-server.js +17 -0
  30. package/dist/ai/react/use-agent.d.ts +23 -0
  31. package/dist/ai/react/use-agent.js +138 -0
  32. package/dist/ai/stream.d.ts +24 -0
  33. package/dist/ai/stream.js +109 -0
  34. package/dist/ai/tool.d.ts +11 -0
  35. package/dist/ai/tool.js +47 -0
  36. package/dist/ai/types.d.ts +117 -0
  37. package/dist/ai/types.js +5 -0
  38. package/dist/auth/core.d.ts +140 -0
  39. package/dist/auth/core.js +165 -0
  40. package/dist/auth/index.d.ts +20 -8
  41. package/dist/auth/index.js +369 -16
  42. package/dist/auth/react-server.d.ts +1 -0
  43. package/dist/auth/react-server.js +10 -0
  44. package/dist/auth/react.d.ts +18 -0
  45. package/dist/auth/react.js +71 -0
  46. package/dist/bin/build-rsc.js +602 -604
  47. package/dist/bin/build.js +389 -388
  48. package/dist/bin/deploy-output.d.ts +2 -7
  49. package/dist/bin/deploy-output.js +3 -76
  50. package/dist/bin/deploy.d.ts +7 -0
  51. package/dist/bin/deploy.js +102 -0
  52. package/dist/bin/dev-error-overlay-snippet.js +778 -552
  53. package/dist/bin/devtools-indicator-snippet.js +387 -387
  54. package/dist/bin/generate.js +510 -248
  55. package/dist/build/manifest.d.ts +169 -139
  56. package/dist/build/manifest.js +423 -367
  57. package/dist/build/rsc/client-manifest.d.ts +62 -52
  58. package/dist/build/rsc/client-manifest.js +295 -193
  59. package/dist/build/rsc/client-reference-plugin.d.ts +37 -37
  60. package/dist/build/rsc/client-reference-plugin.js +160 -160
  61. package/dist/build/rsc/native-scanner.d.ts +135 -123
  62. package/dist/build/rsc/native-scanner.js +203 -170
  63. package/dist/build/rsc/react-client-reference-manifest.d.ts +28 -22
  64. package/dist/build/rsc/react-client-reference-manifest.js +240 -219
  65. package/dist/build/rsc/rsc-renderer.d.ts +99 -99
  66. package/dist/build/rsc/rsc-renderer.js +263 -263
  67. package/dist/build/rsc/server-component-loader.d.ts +19 -19
  68. package/dist/build/rsc/server-component-loader.js +91 -91
  69. package/dist/build/rsc/server-manifest.d.ts +17 -0
  70. package/dist/build/rsc/server-manifest.js +20 -0
  71. package/dist/build/standalone.js +337 -334
  72. package/dist/build/webpack/plugins/vista-flight-plugin.js +5 -5
  73. package/dist/client/dynamic.react-server.d.ts +2 -0
  74. package/dist/client/dynamic.react-server.js +23 -0
  75. package/dist/client/link.react-server.d.ts +2 -0
  76. package/dist/client/link.react-server.js +11 -0
  77. package/dist/client/navigation.react-server.d.ts +1 -0
  78. package/dist/client/navigation.react-server.js +17 -0
  79. package/dist/client/router.react-server.d.ts +1 -0
  80. package/dist/client/router.react-server.js +17 -0
  81. package/dist/client/rsc-router.react-server.d.ts +1 -0
  82. package/dist/client/rsc-router.react-server.js +17 -0
  83. package/dist/client/script.react-server.d.ts +2 -0
  84. package/dist/client/script.react-server.js +23 -0
  85. package/dist/components/client-island.d.ts +34 -34
  86. package/dist/components/client-island.js +75 -75
  87. package/dist/config.d.ts +17 -0
  88. package/dist/config.js +60 -1
  89. package/dist/deploy/adapters/cloudflare.d.ts +2 -0
  90. package/dist/deploy/adapters/cloudflare.js +124 -0
  91. package/dist/deploy/adapters/docker.d.ts +2 -0
  92. package/dist/deploy/adapters/docker.js +112 -0
  93. package/dist/deploy/adapters/index.d.ts +15 -0
  94. package/dist/deploy/adapters/index.js +24 -0
  95. package/dist/deploy/adapters/netlify.d.ts +2 -0
  96. package/dist/deploy/adapters/netlify.js +115 -0
  97. package/dist/deploy/adapters/render.d.ts +2 -0
  98. package/dist/deploy/adapters/render.js +95 -0
  99. package/dist/deploy/adapters/vercel.d.ts +7 -0
  100. package/dist/deploy/adapters/vercel.js +164 -0
  101. package/dist/deploy/cli-runner.d.ts +8 -0
  102. package/dist/deploy/cli-runner.js +58 -0
  103. package/dist/deploy/detect.d.ts +6 -0
  104. package/dist/deploy/detect.js +77 -0
  105. package/dist/deploy/index.d.ts +24 -0
  106. package/dist/deploy/index.js +112 -0
  107. package/dist/deploy/preflight.d.ts +8 -0
  108. package/dist/deploy/preflight.js +80 -0
  109. package/dist/deploy/types.d.ts +48 -0
  110. package/dist/deploy/types.js +2 -0
  111. package/dist/deploy/utils.d.ts +18 -0
  112. package/dist/deploy/utils.js +70 -0
  113. package/dist/dev-error.d.ts +14 -0
  114. package/dist/dev-error.js +1763 -705
  115. package/dist/index.d.ts +23 -21
  116. package/dist/index.js +61 -57
  117. package/dist/server/cookie-parse.d.ts +4 -0
  118. package/dist/server/cookie-parse.js +14 -0
  119. package/dist/server/engine.js +7 -26
  120. package/dist/server/index.d.ts +109 -102
  121. package/dist/server/index.js +315 -286
  122. package/dist/server/middleware-runner.d.ts +125 -57
  123. package/dist/server/middleware-runner.js +615 -218
  124. package/dist/server/middleware-security.d.ts +36 -0
  125. package/dist/server/middleware-security.js +183 -0
  126. package/dist/server/module-compile-hook.js +695 -662
  127. package/dist/server/route-handler-registry.d.ts +65 -0
  128. package/dist/server/route-handler-registry.js +195 -0
  129. package/dist/server/route-patterns.d.ts +67 -0
  130. package/dist/server/route-patterns.js +186 -0
  131. package/dist/server/rsc-engine.js +75 -92
  132. package/dist/server/rsc-module-system.d.ts +33 -33
  133. package/dist/server/rsc-module-system.js +87 -87
  134. package/dist/server/rsc-upstream.js +892 -888
  135. package/dist/server/static-generator.js +10 -10
  136. package/dist/server/typed-api-runtime.d.ts +18 -0
  137. package/dist/server/typed-api-runtime.js +635 -507
  138. package/dist/server/vista-import-map.js +134 -123
  139. package/dist/stack/index.d.ts +34 -32
  140. package/dist/stack/index.js +49 -45
  141. package/dist/stack/server/caller.d.ts +13 -0
  142. package/dist/stack/server/caller.js +42 -0
  143. package/dist/stack/server/executor.d.ts +40 -36
  144. package/dist/stack/server/executor.js +222 -174
  145. package/dist/stack/server/index.d.ts +11 -10
  146. package/dist/stack/server/index.js +24 -23
  147. package/dist/stack/server/procedure.d.ts +20 -18
  148. package/dist/stack/server/procedure.js +66 -58
  149. package/dist/stack/server/types.d.ts +113 -100
  150. package/dist/theme/react-server.d.ts +10 -0
  151. package/dist/theme/react-server.js +16 -0
  152. package/package.json +28 -3
  153. package/LICENSE +0 -21
@@ -667,21 +667,21 @@ function createHtmlDocument(appHtml, metadataHtml, chunkFiles, rootMode = 'legac
667
667
  html = injectBeforeClosingTag(html, 'body', bodyInjection);
668
668
  return html;
669
669
  }
670
- return `<!DOCTYPE html>
671
- <html lang="en">
672
- <head>
673
- <meta charset="utf-8" />
674
- <meta name="viewport" content="width=device-width, initial-scale=1" />
675
- <style>*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}html,body{height:100%;overflow:hidden}</style>
676
- ${metadataHtml}
677
- ${(0, registry_1.getAllFontHTML)()}
678
- ${getCSSLinks()}
679
- </head>
680
- <body>
681
- <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = false;</script>
682
- <div id="root">${appHtml}</div>
683
- ${scripts}
684
- </body>
670
+ return `<!DOCTYPE html>
671
+ <html lang="en">
672
+ <head>
673
+ <meta charset="utf-8" />
674
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
675
+ <style>*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}html,body{height:100%;overflow:hidden}</style>
676
+ ${metadataHtml}
677
+ ${(0, registry_1.getAllFontHTML)()}
678
+ ${getCSSLinks()}
679
+ </head>
680
+ <body>
681
+ <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = false;</script>
682
+ <div id="root">${appHtml}</div>
683
+ ${scripts}
684
+ </body>
685
685
  </html>`;
686
686
  }
687
687
  function appendVaryHeader(existing, nextValue) {
@@ -696,16 +696,8 @@ function appendVaryHeader(existing, nextValue) {
696
696
  }
697
697
  async function handleApiRoute(req, res, runtimeRoot, isDev, typedApiConfig) {
698
698
  try {
699
- const legacyApiPath = (0, typed_api_runtime_1.resolveLegacyApiRoutePath)(runtimeRoot, req.path);
700
- if (legacyApiPath) {
701
- await (0, typed_api_runtime_1.runLegacyApiRoute)({
702
- req,
703
- res,
704
- apiPath: legacyApiPath,
705
- isDev,
706
- });
707
- return;
708
- }
699
+ // File-based `route.*` handlers are resolved by the caller, for `/api/*` as well
700
+ // as any other path, so only the typed API remains to try here.
709
701
  const typedHandled = await (0, typed_api_runtime_1.runTypedApiRoute)({
710
702
  req,
711
703
  res,
@@ -810,18 +802,18 @@ async function renderFlightToHTMLStream(upstreamOrigin, pathname, search, metada
810
802
  // Inject into <head> if present
811
803
  if (html.includes('</head>')) {
812
804
  const fontHtml = (0, registry_1.getAllFontHTML)();
813
- const headInjection = `
814
- <meta charset="utf-8" />
815
- <meta name="viewport" content="width=device-width, initial-scale=1" />
816
- ${metadataHtml}
817
- ${fontHtml}
805
+ const headInjection = `
806
+ <meta charset="utf-8" />
807
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
808
+ ${metadataHtml}
809
+ ${fontHtml}
818
810
  ${getCSSLinks()}`;
819
811
  html = html.replace('</head>', `${headInjection}\n</head>`);
820
812
  }
821
813
  // Inject scripts before </body>
822
814
  if (html.includes('</body>')) {
823
- const bodyInjection = `
824
- <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = ${rootMode === 'document'};</script>
815
+ const bodyInjection = `
816
+ <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = ${rootMode === 'document'};</script>
825
817
  ${scripts}`;
826
818
  html = html.replace('</body>', `${bodyInjection}\n</body>`);
827
819
  }
@@ -869,21 +861,21 @@ function wrapInDocumentShell(bodyContent, metadataHtml, chunkFiles, rootMode) {
869
861
  html = injectBeforeClosingTag(html, 'body', bodyInjection);
870
862
  return html;
871
863
  }
872
- return `<!DOCTYPE html>
873
- <html lang="en">
874
- <head>
875
- <meta charset="utf-8" />
876
- <meta name="viewport" content="width=device-width, initial-scale=1" />
877
- <style>*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}html,body{height:100%;overflow:hidden}</style>
878
- ${metadataHtml}
879
- ${(0, registry_1.getAllFontHTML)()}
880
- ${getCSSLinks()}
881
- </head>
882
- <body>
883
- <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = false;</script>
884
- <div id="root">${bodyContent}</div>
885
- ${scripts}
886
- </body>
864
+ return `<!DOCTYPE html>
865
+ <html lang="en">
866
+ <head>
867
+ <meta charset="utf-8" />
868
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
869
+ <style>*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}html,body{height:100%;overflow:hidden}</style>
870
+ ${metadataHtml}
871
+ ${(0, registry_1.getAllFontHTML)()}
872
+ ${getCSSLinks()}
873
+ </head>
874
+ <body>
875
+ <script>window.${constants_1.HYDRATE_DOCUMENT_FLAG} = false;</script>
876
+ <div id="root">${bodyContent}</div>
877
+ ${scripts}
878
+ </body>
887
879
  </html>`;
888
880
  }
889
881
  function normalizeWebpackErrors(stats) {
@@ -903,36 +895,36 @@ function normalizeWebpackErrors(stats) {
903
895
  return ['Unknown build error.'];
904
896
  }
905
897
  function renderCompilePendingHTML() {
906
- return `<!DOCTYPE html>
907
- <html lang="en">
908
- <head>
909
- <meta charset="utf-8" />
910
- <meta name="viewport" content="width=device-width, initial-scale=1" />
911
- <title>Compiling...</title>
912
- <style>
913
- html,body{height:100%;margin:0}
914
- body{
915
- display:grid;
916
- place-items:center;
917
- font-family:ui-sans-serif,system-ui,-apple-system,'Segoe UI',sans-serif;
918
- background:#09090b;
919
- color:#f4f4f5;
920
- }
921
- .vista-dev-pending{
922
- padding:20px 24px;
923
- border-radius:14px;
924
- border:1px solid rgba(255,255,255,0.15);
925
- background:rgba(17,17,20,0.92);
926
- box-shadow:0 18px 42px rgba(0,0,0,0.4);
927
- font-size:14px;
928
- letter-spacing:0.01em;
929
- }
930
- </style>
931
- </head>
932
- <body>
933
- <div class="vista-dev-pending">Vista is compiling the client bundle. Retrying...</div>
934
- <script>setTimeout(function(){window.location.reload();},700);</script>
935
- </body>
898
+ return `<!DOCTYPE html>
899
+ <html lang="en">
900
+ <head>
901
+ <meta charset="utf-8" />
902
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
903
+ <title>Compiling...</title>
904
+ <style>
905
+ html,body{height:100%;margin:0}
906
+ body{
907
+ display:grid;
908
+ place-items:center;
909
+ font-family:ui-sans-serif,system-ui,-apple-system,'Segoe UI',sans-serif;
910
+ background:#09090b;
911
+ color:#f4f4f5;
912
+ }
913
+ .vista-dev-pending{
914
+ padding:20px 24px;
915
+ border-radius:14px;
916
+ border:1px solid rgba(255,255,255,0.15);
917
+ background:rgba(17,17,20,0.92);
918
+ box-shadow:0 18px 42px rgba(0,0,0,0.4);
919
+ font-size:14px;
920
+ letter-spacing:0.01em;
921
+ }
922
+ </style>
923
+ </head>
924
+ <body>
925
+ <div class="vista-dev-pending">Vista is compiling the client bundle. Retrying...</div>
926
+ <script>setTimeout(function(){window.location.reload();},700);</script>
927
+ </body>
936
928
  </html>`;
937
929
  }
938
930
  function startRSCServer(options = {}) {
@@ -1439,13 +1431,14 @@ function startRSCServer(options = {}) {
1439
1431
  return;
1440
1432
  }
1441
1433
  }
1442
- const routeHandlerPath = (0, typed_api_runtime_1.resolveLegacyRouteHandlerPath)(runtimeRoot, req.path);
1443
- if (routeHandlerPath) {
1434
+ const routeHandlerMatch = (0, typed_api_runtime_1.resolveRouteHandlerMatch)(runtimeRoot, req.path, { isDev });
1435
+ if (routeHandlerMatch) {
1444
1436
  try {
1445
1437
  await (0, typed_api_runtime_1.runLegacyApiRoute)({
1446
1438
  req,
1447
1439
  res,
1448
- apiPath: routeHandlerPath,
1440
+ apiPath: routeHandlerMatch.filePath,
1441
+ params: routeHandlerMatch.params,
1449
1442
  isDev,
1450
1443
  });
1451
1444
  return;
@@ -1589,12 +1582,7 @@ function startRSCServer(options = {}) {
1589
1582
  // This is much better than falling through to legacy renderToString,
1590
1583
  // which will likely hit the same error (e.g. useState in a server component).
1591
1584
  if (isDev && !res.headersSent) {
1592
- const errorInfo = {
1593
- type: 'runtime',
1594
- message: flightError.message || 'Flight SSR Error',
1595
- stack: flightError.stack,
1596
- };
1597
- res.status(500).send((0, dev_error_1.renderErrorHTML)([errorInfo]));
1585
+ res.status(500).send((0, dev_error_1.renderErrorHTML)([(0, dev_error_1.fromCaughtError)(flightError, { source: 'server' })]));
1598
1586
  return;
1599
1587
  }
1600
1588
  // If headers were already sent (stream was partially flushed),
@@ -1713,12 +1701,7 @@ function startRSCServer(options = {}) {
1713
1701
  }
1714
1702
  console.error('[vista:rsc] Render error:', error);
1715
1703
  if (isDev) {
1716
- const errorInfo = {
1717
- type: 'runtime',
1718
- message: error.message || 'Unknown Server Error',
1719
- stack: error.stack,
1720
- };
1721
- res.status(500).send((0, dev_error_1.renderErrorHTML)([errorInfo]));
1704
+ res.status(500).send((0, dev_error_1.renderErrorHTML)([(0, dev_error_1.fromCaughtError)(error, { source: 'server' })]));
1722
1705
  }
1723
1706
  else {
1724
1707
  res.status(500).send('<h1>Internal Server Error</h1>');
@@ -1,33 +1,33 @@
1
- /**
2
- * Vista RSC Module System
3
- *
4
- * Intercepts require() calls for client components during SSR.
5
- * Client components are replaced with placeholder divs that will be
6
- * hydrated on the client side.
7
- */
8
- export interface ClientReference {
9
- id: string;
10
- mountId: string;
11
- props: Record<string, any>;
12
- chunkUrl: string;
13
- exportName: string;
14
- }
15
- /**
16
- * Initialize the RSC module system
17
- * Must be called BEFORE any app modules are loaded
18
- */
19
- export declare function initializeRSCModuleSystem(manifest: any, cwd?: string): void;
20
- export declare function _getMountId(): number;
21
- export declare function _addReference(ref: ClientReference): void;
22
- /**
23
- * Reset state for new render
24
- */
25
- export declare function resetRSCState(): void;
26
- /**
27
- * Get collected client references
28
- */
29
- export declare function getClientReferences(): ClientReference[];
30
- /**
31
- * Shutdown the RSC module system
32
- */
33
- export declare function shutdownRSCModuleSystem(): void;
1
+ /**
2
+ * Vista RSC Module System
3
+ *
4
+ * Intercepts require() calls for client components during SSR.
5
+ * Client components are replaced with placeholder divs that will be
6
+ * hydrated on the client side.
7
+ */
8
+ export interface ClientReference {
9
+ id: string;
10
+ mountId: string;
11
+ props: Record<string, any>;
12
+ chunkUrl: string;
13
+ exportName: string;
14
+ }
15
+ /**
16
+ * Initialize the RSC module system
17
+ * Must be called BEFORE any app modules are loaded
18
+ */
19
+ export declare function initializeRSCModuleSystem(manifest: any, cwd?: string): void;
20
+ export declare function _getMountId(): number;
21
+ export declare function _addReference(ref: ClientReference): void;
22
+ /**
23
+ * Reset state for new render
24
+ */
25
+ export declare function resetRSCState(): void;
26
+ /**
27
+ * Get collected client references
28
+ */
29
+ export declare function getClientReferences(): ClientReference[];
30
+ /**
31
+ * Shutdown the RSC module system
32
+ */
33
+ export declare function shutdownRSCModuleSystem(): void;
@@ -1,53 +1,53 @@
1
- "use strict";
2
- /**
3
- * Vista RSC Module System
4
- *
5
- * Intercepts require() calls for client components during SSR.
6
- * Client components are replaced with placeholder divs that will be
7
- * hydrated on the client side.
8
- */
9
- var __importDefault = (this && this.__importDefault) || function (mod) {
10
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.initializeRSCModuleSystem = initializeRSCModuleSystem;
14
- exports._getMountId = _getMountId;
15
- exports._addReference = _addReference;
16
- exports.resetRSCState = resetRSCState;
17
- exports.getClientReferences = getClientReferences;
18
- exports.shutdownRSCModuleSystem = shutdownRSCModuleSystem;
19
- const path_1 = __importDefault(require("path"));
20
- const module_1 = __importDefault(require("module"));
21
- // Global state for RSC rendering
22
- let clientManifest = null;
23
- let clientReferences = [];
24
- let mountIdCounter = 0;
25
- let isInitialized = false;
26
- let originalCompile = null;
27
- /**
28
- * Check if file content has 'use client' directive
29
- */
30
- function hasClientDirective(content) {
31
- const trimmed = content.trim();
32
- return trimmed.startsWith("'use client'") || trimmed.startsWith('"use client"');
33
- }
34
- /**
35
- * Initialize the RSC module system
36
- * Must be called BEFORE any app modules are loaded
37
- */
38
- function initializeRSCModuleSystem(manifest, cwd) {
39
- if (isInitialized)
40
- return;
41
- clientManifest = manifest;
42
- isInitialized = true;
43
- // Hook into Module._compile which is called for every loaded module
44
- originalCompile = module_1.default.prototype._compile;
45
- module_1.default.prototype._compile = function (content, filename) {
46
- // Check if this is a TypeScript/JavaScript file with client directive
47
- if (/\.[jt]sx?$/.test(filename) && hasClientDirective(content)) {
48
- const basename = path_1.default.basename(filename, path_1.default.extname(filename));
49
- const componentId = `client:${basename}`;
50
- // This is a client component - return a proxy module that renders a placeholder
1
+ "use strict";
2
+ /**
3
+ * Vista RSC Module System
4
+ *
5
+ * Intercepts require() calls for client components during SSR.
6
+ * Client components are replaced with placeholder divs that will be
7
+ * hydrated on the client side.
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.initializeRSCModuleSystem = initializeRSCModuleSystem;
14
+ exports._getMountId = _getMountId;
15
+ exports._addReference = _addReference;
16
+ exports.resetRSCState = resetRSCState;
17
+ exports.getClientReferences = getClientReferences;
18
+ exports.shutdownRSCModuleSystem = shutdownRSCModuleSystem;
19
+ const path_1 = __importDefault(require("path"));
20
+ const module_1 = __importDefault(require("module"));
21
+ // Global state for RSC rendering
22
+ let clientManifest = null;
23
+ let clientReferences = [];
24
+ let mountIdCounter = 0;
25
+ let isInitialized = false;
26
+ let originalCompile = null;
27
+ /**
28
+ * Check if file content has 'use client' directive
29
+ */
30
+ function hasClientDirective(content) {
31
+ const trimmed = content.trim();
32
+ return trimmed.startsWith("'use client'") || trimmed.startsWith('"use client"');
33
+ }
34
+ /**
35
+ * Initialize the RSC module system
36
+ * Must be called BEFORE any app modules are loaded
37
+ */
38
+ function initializeRSCModuleSystem(manifest, cwd) {
39
+ if (isInitialized)
40
+ return;
41
+ clientManifest = manifest;
42
+ isInitialized = true;
43
+ // Hook into Module._compile which is called for every loaded module
44
+ originalCompile = module_1.default.prototype._compile;
45
+ module_1.default.prototype._compile = function (content, filename) {
46
+ // Check if this is a TypeScript/JavaScript file with client directive
47
+ if (/\.[jt]sx?$/.test(filename) && hasClientDirective(content)) {
48
+ const basename = path_1.default.basename(filename, path_1.default.extname(filename));
49
+ const componentId = `client:${basename}`;
50
+ // This is a client component - return a proxy module that renders a placeholder
51
51
  const proxyCode = `
52
52
  const React = require('react');
53
53
  const clientRefs = require('${__filename.replace(/\\/g, '/')}');
@@ -80,40 +80,40 @@ function initializeRSCModuleSystem(manifest, cwd) {
80
80
  module.exports = ClientComponentProxy;
81
81
  module.exports.default = ClientComponentProxy;
82
82
  module.exports.__esModule = true;
83
- `;
84
- return originalCompile.call(this, proxyCode, filename);
85
- }
86
- return originalCompile.call(this, content, filename);
87
- };
88
- console.log('[Vista RSC] Module interception initialized');
89
- }
90
- // Helper functions exposed for the proxy code
91
- function _getMountId() {
92
- return mountIdCounter++;
93
- }
94
- function _addReference(ref) {
95
- clientReferences.push(ref);
96
- }
97
- /**
98
- * Reset state for new render
99
- */
100
- function resetRSCState() {
101
- clientReferences = [];
102
- mountIdCounter = 0;
103
- }
104
- /**
105
- * Get collected client references
106
- */
107
- function getClientReferences() {
108
- return [...clientReferences];
109
- }
110
- /**
111
- * Shutdown the RSC module system
112
- */
113
- function shutdownRSCModuleSystem() {
114
- if (originalCompile) {
115
- module_1.default.prototype._compile = originalCompile;
116
- }
117
- clientManifest = null;
118
- isInitialized = false;
119
- }
83
+ `;
84
+ return originalCompile.call(this, proxyCode, filename);
85
+ }
86
+ return originalCompile.call(this, content, filename);
87
+ };
88
+ console.log('[Vista RSC] Module interception initialized');
89
+ }
90
+ // Helper functions exposed for the proxy code
91
+ function _getMountId() {
92
+ return mountIdCounter++;
93
+ }
94
+ function _addReference(ref) {
95
+ clientReferences.push(ref);
96
+ }
97
+ /**
98
+ * Reset state for new render
99
+ */
100
+ function resetRSCState() {
101
+ clientReferences = [];
102
+ mountIdCounter = 0;
103
+ }
104
+ /**
105
+ * Get collected client references
106
+ */
107
+ function getClientReferences() {
108
+ return [...clientReferences];
109
+ }
110
+ /**
111
+ * Shutdown the RSC module system
112
+ */
113
+ function shutdownRSCModuleSystem() {
114
+ if (originalCompile) {
115
+ module_1.default.prototype._compile = originalCompile;
116
+ }
117
+ clientManifest = null;
118
+ isInitialized = false;
119
+ }