soma-core 1.0.2 → 1.1.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.
Files changed (93) hide show
  1. package/app/SomaPageClient.tsx +11 -20
  2. package/app/[...path]/page.tsx +21 -0
  3. package/app/api/[...path]/route.ts +86 -77
  4. package/app/components/SomaHostPage.tsx +133 -0
  5. package/app/components/SomaHydrationShell.tsx +1 -1
  6. package/app/favicon.ico/route.ts +13 -0
  7. package/app/layout.tsx +10 -6
  8. package/app/page.tsx +7 -18
  9. package/app/soma/[...path]/route.ts +9 -0
  10. package/app/{api/soma-manifest → soma/manifest}/route.ts +3 -3
  11. package/app/soma/page/route.ts +29 -0
  12. package/app/soma/page-object/route.ts +158 -0
  13. package/app/soma/route.ts +9 -0
  14. package/bin/soma-mock.mjs +38 -0
  15. package/bin/soma.cjs +1 -1
  16. package/core/api/load-host-service.ts +5 -2
  17. package/core/base/SomaHttpClient.ts +5 -3
  18. package/core/compiler/full-manifest-builder.ts +84 -69
  19. package/core/compiler/host-config-sync.cjs +32 -6
  20. package/core/compiler/page-base-resolver.ts +3 -0
  21. package/core/compiler/soma-manifest-webpack-plugin.js +160 -10
  22. package/core/engine/dom-renderer.ts +160 -24
  23. package/core/engine/soma-headless-page.ts +86 -0
  24. package/core/host/app-config-composer.ts +90 -0
  25. package/core/host/app-config.stub.ts +2 -0
  26. package/core/host/host-config-paths.cjs +100 -0
  27. package/core/host/host-config-paths.ts +132 -0
  28. package/core/host/invoke-host-request-hook.ts +37 -0
  29. package/core/host/load-host-domain-class.ts +87 -0
  30. package/core/host/locale.stub.ts +2 -0
  31. package/core/host/page-response-mode.cjs +96 -0
  32. package/core/host/page-response-request.ts +35 -0
  33. package/core/host/request-origin.ts +18 -0
  34. package/core/host/resolve-host-request-hook.ts +29 -0
  35. package/core/host/server-page-assets.ts +193 -0
  36. package/core/host/soma-domain-loaders.stub.ts +6 -0
  37. package/core/host/soma-domain-loaders.ts +69 -0
  38. package/core/host/soma-request-hook-host.stub.ts +4 -0
  39. package/core/host/source-packages.ts +153 -0
  40. package/core/index.ts +22 -0
  41. package/core/infra/http/SomaHttpService.ts +23 -14
  42. package/core/infra/http/soma-server-request-context.ts +126 -0
  43. package/core/mock/node/catch-all.mjs +35 -0
  44. package/core/mock/node/cli.d.mts +58 -0
  45. package/core/mock/node/cli.mjs +243 -0
  46. package/core/mock/node/context.mjs +167 -0
  47. package/core/mock/node/environment-policy.mjs +52 -0
  48. package/core/mock/node/plugin-loader.mjs +212 -0
  49. package/core/mock/node/preload.mjs +91 -0
  50. package/core/mock/node/process-lifecycle.mjs +236 -0
  51. package/core/mock/node/public.d.mts +110 -0
  52. package/core/mock/node/public.mjs +4 -0
  53. package/core/mock/node/registry.mjs +336 -0
  54. package/core/mock/node/schema-generator.mjs +1310 -0
  55. package/core/mock/testing/host-harness.d.mts +66 -0
  56. package/core/mock/testing/host-harness.mjs +276 -0
  57. package/core/mock/testing/host-runtime.mjs +48 -0
  58. package/core/runtime/SomaRuntimeServices.ts +5 -1
  59. package/core/runtime/serialize-page-state.ts +152 -0
  60. package/dist/cli/soma.js +375 -4
  61. package/dist/core/index.cjs +2957 -2387
  62. package/dist/tsconfig.types.tsbuildinfo +1 -1
  63. package/dist/types/base/SomaHttpClient.d.ts +2 -0
  64. package/dist/types/compiler/full-manifest-builder.d.ts +2 -0
  65. package/dist/types/engine/dom-renderer.d.ts +6 -0
  66. package/dist/types/engine/soma-headless-page.d.ts +10 -0
  67. package/dist/types/host/app-config-composer.d.ts +6 -0
  68. package/dist/types/host/app-config.stub.d.ts +3 -0
  69. package/dist/types/host/host-config-paths.d.ts +23 -0
  70. package/dist/types/host/invoke-host-request-hook.d.ts +8 -0
  71. package/dist/types/host/load-host-domain-class.d.ts +12 -0
  72. package/dist/types/host/locale.stub.d.ts +3 -0
  73. package/dist/types/host/page-response-request.d.ts +9 -0
  74. package/dist/types/host/request-origin.d.ts +1 -0
  75. package/dist/types/host/resolve-host-request-hook.d.ts +16 -0
  76. package/dist/types/host/server-page-assets.d.ts +29 -0
  77. package/dist/types/host/soma-domain-loaders.d.ts +19 -0
  78. package/dist/types/host/soma-domain-loaders.stub.d.ts +4 -0
  79. package/dist/types/host/soma-request-hook-host.stub.d.ts +2 -0
  80. package/dist/types/host/source-packages.d.ts +12 -0
  81. package/dist/types/index.d.ts +3 -0
  82. package/dist/types/infra/http/SomaHttpService.d.ts +2 -0
  83. package/dist/types/infra/http/soma-server-request-context.d.ts +5 -0
  84. package/dist/types/runtime/serialize-page-state.d.ts +10 -0
  85. package/docs//351/241/265/351/235/242JSON/346/250/241/345/274/217/346/216/245/345/205/245/346/214/207/345/215/227.md +141 -0
  86. package/global.d.ts +74 -33
  87. package/middleware.ts +33 -0
  88. package/next.config.js +166 -16
  89. package/package.json +47 -13
  90. package/tailwind.config.ts +21 -17
  91. package/tsconfig.json +1 -5
  92. package/app/api/page/route.ts +0 -99
  93. package/app/loading.tsx +0 -5
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { usePathname, useRouter, useSearchParams } from 'next/navigation';
5
5
  import { SomaHydrationShell } from './components/SomaHydrationShell';
6
6
  import type { SomaBootstrap as SomaBootstrapType, SomaPageAssets } from '../core/engine/soma-bootstrap';
7
+ import { loadHostDomainClass } from '../core/host/load-host-domain-class';
7
8
 
8
9
  const isDev = process.env.NODE_ENV !== 'production';
9
10
 
@@ -31,24 +32,9 @@ function urlPathToPageBase(urlPath: string): string {
31
32
  return clean || 'index';
32
33
  }
33
34
 
34
- async function loadDomainClass(base: string): Promise<new () => any> {
35
- try {
36
- const mod = await import(
37
- /* webpackInclude: /\/domain\/ui\/.*Class\.ts$/ */
38
- `@soma-host/domain/ui/${base}Class`
39
- );
40
- if (typeof mod.default === 'function') return mod.default;
41
- const ctor = Object.values(mod).find((v) => typeof v === 'function');
42
- if (ctor) return ctor as new () => any;
43
- throw new Error(`domain class missing: ${base}Class`);
44
- } catch {
45
- const { SomaLocaleOnlyPageRoot } = await import('../core/base/SomaLocaleOnlyPageRoot');
46
- return SomaLocaleOnlyPageRoot;
47
- }
48
- }
49
-
50
35
  type PagePayload = {
51
36
  base: string;
37
+ sourcePackage?: string | null;
52
38
  html: string;
53
39
  ui: string;
54
40
  event: string;
@@ -86,7 +72,7 @@ const pageAssetCache = new Map<string, PagePayload>();
86
72
 
87
73
  async function loadPrecompiledFromManifest(base: string, path: string): Promise<PrecompiledAssets | null> {
88
74
  try {
89
- const res = await fetch(`/api/soma-manifest?path=${encodeURIComponent(path)}`);
75
+ const res = await fetch(`/soma/manifest?path=${encodeURIComponent(path)}`);
90
76
  if (!res.ok) return null;
91
77
  const data = await res.json();
92
78
  return {
@@ -236,13 +222,14 @@ function SomaPageRenderer({
236
222
 
237
223
  const { SomaBootstrap } = await import('../core/engine/soma-bootstrap');
238
224
 
239
- const res = await fetch(`/api/page?path=${encodeURIComponent(pagePath)}`);
225
+ const res = await fetch(`/soma/page?path=${encodeURIComponent(pagePath)}`);
240
226
  if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
241
227
  const data = await res.json();
242
228
  if (cancelled) return;
243
229
 
244
230
  const base = (data.base as string) || urlPathToPageBase(pagePath);
245
- const DomainClass = await loadDomainClass(base);
231
+ const sourcePackage = typeof data.sourcePackage === 'string' ? data.sourcePackage : null;
232
+ const DomainClass = await loadHostDomainClass({ base, sourcePackage });
246
233
  const routeAssets = { routerPath };
247
234
 
248
235
  if (!isDev) {
@@ -261,7 +248,10 @@ function SomaPageRenderer({
261
248
 
262
249
  const cached = pageAssetCache.get(routerPath);
263
250
  if (cached) {
264
- const CachedClass = await loadDomainClass(cached.base);
251
+ const CachedClass = await loadHostDomainClass({
252
+ base: cached.base,
253
+ sourcePackage: cached.sourcePackage,
254
+ });
265
255
  await mountInto(CachedClass, SomaBootstrap, {
266
256
  uiYaml: cached.ui,
267
257
  eventYaml: cached.event,
@@ -276,6 +266,7 @@ function SomaPageRenderer({
276
266
 
277
267
  const payload: PagePayload = {
278
268
  base,
269
+ sourcePackage,
279
270
  html: data.html,
280
271
  ui: data.ui,
281
272
  event: data.event,
@@ -0,0 +1,21 @@
1
+ import { SomaHostPage, type SomaPageSearchParams } from '../components/SomaHostPage';
2
+ import { notFound } from 'next/navigation';
3
+
4
+ export default function SomaCatchAllPage({
5
+ params,
6
+ searchParams,
7
+ }: {
8
+ params: { path: string[] };
9
+ searchParams?: SomaPageSearchParams;
10
+ }) {
11
+ const lastSegment = params.path.at(-1) ?? '';
12
+ if (/\.[a-zA-Z0-9]+$/.test(lastSegment) && !/\.html$/i.test(lastSegment)) {
13
+ notFound();
14
+ }
15
+ return (
16
+ <SomaHostPage
17
+ pathname={`/${params.path.join('/')}`}
18
+ searchParams={searchParams}
19
+ />
20
+ );
21
+ }
@@ -1,77 +1,86 @@
1
- import { NextRequest } from 'next/server';
2
- import type { IService } from '@/core/api/IService';
3
- import { loadHostService } from '@/core/api/load-host-service';
4
-
5
- // ─── HTTP 方法分发工厂 ─────────────────────────────────────
6
-
7
- type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
8
-
9
- function createHandler(method: HttpMethod) {
10
- const methodKey = method.toLowerCase() as keyof IService;
11
-
12
- return async function handler(
13
- req: NextRequest,
14
- { params }: { params: { path: string[] } },
15
- ): Promise<Response> {
16
- const segments = params.path || [];
17
-
18
- if (segments.length === 0) {
19
- return Response.json(
20
- { error: 'Missing API path. Expected: /api/{module}/{action}' },
21
- { status: 400 },
22
- );
23
- }
24
-
25
- const service = loadHostService(segments);
26
-
27
- if (!service) {
28
- return Response.json(
29
- { error: `API not found: /api/${segments.join('/')}` },
30
- { status: 404 },
31
- );
32
- }
33
-
34
- const handlerFn = service[methodKey];
35
- if (typeof handlerFn !== 'function') {
36
- return Response.json(
37
- {
38
- error: `Method ${method} not allowed: /api/${segments.join('/')}`,
39
- },
40
- {
41
- status: 405,
42
- headers: { Allow: getAllowHeader(service) },
43
- },
44
- );
45
- }
46
-
47
- try {
48
- return await handlerFn.call(service, req);
49
- } catch (e: unknown) {
50
- const message = e instanceof Error ? e.message : String(e);
51
- console.error(`[soma-api] ${method} /api/${segments.join('/')}:`, message);
52
- return Response.json(
53
- { error: message || 'Internal server error' },
54
- { status: 500 },
55
- );
56
- }
57
- };
58
- }
59
-
60
- /** 生成 Allow 响应头 */
61
- function getAllowHeader(service: IService): string {
62
- const methods: string[] = [];
63
- if (typeof service.get === 'function') methods.push('GET');
64
- if (typeof service.post === 'function') methods.push('POST');
65
- if (typeof service.put === 'function') methods.push('PUT');
66
- if (typeof service.patch === 'function') methods.push('PATCH');
67
- if (typeof service.delete === 'function') methods.push('DELETE');
68
- return methods.join(', ');
69
- }
70
-
71
- // ─── 导出所有 HTTP 方法处理器 ───────────────────────────────
72
-
73
- export const GET = createHandler('GET');
74
- export const POST = createHandler('POST');
75
- export const PUT = createHandler('PUT');
76
- export const PATCH = createHandler('PATCH');
77
- export const DELETE = createHandler('DELETE');
1
+ import { NextRequest } from 'next/server';
2
+ import type { IService } from '../../../core/api/IService';
3
+ import { loadHostService } from '../../../core/api/load-host-service';
4
+ import { invokeHostRequestHook } from '../../../core/host/invoke-host-request-hook';
5
+
6
+ // ─── HTTP 方法分发工厂 ─────────────────────────────────────
7
+
8
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
9
+
10
+ function createHandler(method: HttpMethod) {
11
+ const methodKey = method.toLowerCase() as keyof IService;
12
+
13
+ return async function handler(
14
+ req: NextRequest,
15
+ { params }: { params: { path: string[] } },
16
+ ): Promise<Response> {
17
+ const segments = params.path || [];
18
+
19
+ const rejected = await invokeHostRequestHook(req, {
20
+ kind: 'api',
21
+ path: req.nextUrl.pathname,
22
+ });
23
+ if (rejected) {
24
+ return rejected;
25
+ }
26
+
27
+ if (segments.length === 0) {
28
+ return Response.json(
29
+ { error: 'Missing API path. Expected: /api/{module}/{action}' },
30
+ { status: 400 },
31
+ );
32
+ }
33
+
34
+ const service = loadHostService(segments);
35
+
36
+ if (!service) {
37
+ return Response.json(
38
+ { error: `API not found: /api/${segments.join('/')}` },
39
+ { status: 404 },
40
+ );
41
+ }
42
+
43
+ const handlerFn = service[methodKey];
44
+ if (typeof handlerFn !== 'function') {
45
+ return Response.json(
46
+ {
47
+ error: `Method ${method} not allowed: /api/${segments.join('/')}`,
48
+ },
49
+ {
50
+ status: 405,
51
+ headers: { Allow: getAllowHeader(service) },
52
+ },
53
+ );
54
+ }
55
+
56
+ try {
57
+ return await handlerFn.call(service, req);
58
+ } catch (e: unknown) {
59
+ const message = e instanceof Error ? e.message : String(e);
60
+ console.error(`[soma-api] ${method} /api/${segments.join('/')}:`, message);
61
+ return Response.json(
62
+ { error: message || 'Internal server error' },
63
+ { status: 500 },
64
+ );
65
+ }
66
+ };
67
+ }
68
+
69
+ /** 生成 Allow 响应头 */
70
+ function getAllowHeader(service: IService): string {
71
+ const methods: string[] = [];
72
+ if (typeof service.get === 'function') methods.push('GET');
73
+ if (typeof service.post === 'function') methods.push('POST');
74
+ if (typeof service.put === 'function') methods.push('PUT');
75
+ if (typeof service.patch === 'function') methods.push('PATCH');
76
+ if (typeof service.delete === 'function') methods.push('DELETE');
77
+ return methods.join(', ');
78
+ }
79
+
80
+ // ─── 导出所有 HTTP 方法处理器 ───────────────────────────────
81
+
82
+ export const GET = createHandler('GET');
83
+ export const POST = createHandler('POST');
84
+ export const PUT = createHandler('PUT');
85
+ export const PATCH = createHandler('PATCH');
86
+ export const DELETE = createHandler('DELETE');
@@ -0,0 +1,133 @@
1
+ import dynamic from 'next/dynamic';
2
+ import { headers } from 'next/headers';
3
+ import { redirect } from 'next/navigation';
4
+ import { Suspense } from 'react';
5
+ import { invokeHostRequestHook } from '../../core/host/invoke-host-request-hook';
6
+ import { SomaHydrationShell } from './SomaHydrationShell';
7
+
8
+ const SomaPageClient = dynamic(() => import('../SomaPageClient'), {
9
+ ssr: false,
10
+ loading: () => <SomaHydrationShell />,
11
+ });
12
+
13
+ export type SomaPageSearchParams = Record<string, string | string[] | undefined>;
14
+
15
+ function firstForwardedValue(value: string | null): string {
16
+ return value?.split(',')[0]?.trim() ?? '';
17
+ }
18
+
19
+ function resolveRequestOrigin(requestHeaders: Headers): string {
20
+ const host = firstForwardedValue(requestHeaders.get('x-forwarded-host'))
21
+ || firstForwardedValue(requestHeaders.get('host'))
22
+ || 'localhost';
23
+ const closingBracket = host.indexOf(']');
24
+ const hostname = (host.startsWith('[') && closingBracket > 0
25
+ ? host.slice(1, closingBracket)
26
+ : host.split(':')[0]).toLowerCase();
27
+ const forwardedProtocol = firstForwardedValue(requestHeaders.get('x-forwarded-proto'));
28
+ const protocol = forwardedProtocol === 'http' || forwardedProtocol === 'https'
29
+ ? forwardedProtocol
30
+ : (hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1' ? 'http' : 'https');
31
+ return `${protocol}://${host}`;
32
+ }
33
+
34
+ function appendSearchParams(url: URL, searchParams: SomaPageSearchParams | undefined): void {
35
+ if (!searchParams) return;
36
+ for (const [key, rawValue] of Object.entries(searchParams)) {
37
+ if (Array.isArray(rawValue)) {
38
+ rawValue.forEach((value) => url.searchParams.append(key, value));
39
+ } else if (typeof rawValue === 'string') {
40
+ url.searchParams.set(key, rawValue);
41
+ }
42
+ }
43
+ }
44
+
45
+ async function readRejectedMessage(response: Response): Promise<string> {
46
+ try {
47
+ const payload = await response.clone().json() as { error?: unknown; message?: unknown };
48
+ const message = payload.error ?? payload.message;
49
+ if (typeof message === 'string' && message.trim()) {
50
+ return message.trim();
51
+ }
52
+ } catch {
53
+ // Fall through to text/status when the Host returned a non-JSON response.
54
+ }
55
+
56
+ try {
57
+ const text = await response.clone().text();
58
+ if (text.trim()) return text.trim();
59
+ } catch {
60
+ // Ignore unreadable rejection bodies.
61
+ }
62
+ return response.statusText || 'Request rejected';
63
+ }
64
+
65
+ function isRedirectResponse(response: Response): boolean {
66
+ return response.status >= 300 && response.status < 400 && Boolean(response.headers.get('location'));
67
+ }
68
+
69
+ function isHtmlRejectionResponse(response: Response): boolean {
70
+ return (response.headers.get('content-type') || '').toLowerCase().includes('text/html');
71
+ }
72
+
73
+ /** Prefer the document body when a Host Hook returns a full HTML rejection page. */
74
+ function extractHtmlBodyInner(html: string): string {
75
+ const match = html.match(/<body\b[^>]*>([\s\S]*)<\/body>/i);
76
+ return (match?.[1] ?? html).trim();
77
+ }
78
+
79
+ export async function SomaHostPage({
80
+ pathname,
81
+ searchParams,
82
+ }: {
83
+ pathname: string;
84
+ searchParams?: SomaPageSearchParams;
85
+ }) {
86
+ const incomingHeaders = headers();
87
+ const requestHeaders = new Headers();
88
+ incomingHeaders.forEach((value, key) => requestHeaders.set(key, value));
89
+
90
+ const requestUrl = new URL(pathname, resolveRequestOrigin(requestHeaders));
91
+ appendSearchParams(requestUrl, searchParams);
92
+ const request = new Request(requestUrl, { method: 'GET', headers: requestHeaders });
93
+ const rejected = await invokeHostRequestHook(request, {
94
+ kind: 'page',
95
+ path: requestUrl.pathname,
96
+ pageHref: requestUrl.pathname,
97
+ });
98
+
99
+ if (rejected) {
100
+ if (isRedirectResponse(rejected)) {
101
+ redirect(new URL(rejected.headers.get('location')!, requestUrl).toString());
102
+ }
103
+ if (isHtmlRejectionResponse(rejected)) {
104
+ const html = await rejected.text();
105
+ return (
106
+ <div
107
+ data-soma-request-rejected={rejected.status}
108
+ data-soma-rejection-html="1"
109
+ dangerouslySetInnerHTML={{ __html: extractHtmlBodyInner(html) }}
110
+ />
111
+ );
112
+ }
113
+ const message = await readRejectedMessage(rejected);
114
+ return (
115
+ <main
116
+ className="min-h-screen bg-slate-50 px-6 py-16 text-slate-900"
117
+ data-soma-request-rejected={rejected.status}
118
+ >
119
+ <section className="mx-auto max-w-xl border border-slate-200 bg-white p-6 shadow-sm">
120
+ <p className="text-xs font-semibold uppercase text-slate-500">HTTP {rejected.status}</p>
121
+ <h1 className="mt-2 text-xl font-semibold">Request rejected</h1>
122
+ <p className="mt-3 text-sm leading-6 text-slate-600">{message}</p>
123
+ </section>
124
+ </main>
125
+ );
126
+ }
127
+
128
+ return (
129
+ <Suspense fallback={<SomaHydrationShell />}>
130
+ <SomaPageClient />
131
+ </Suspense>
132
+ );
133
+ }
@@ -16,7 +16,7 @@ export function SomaHydrationShell() {
16
16
  className="mx-auto mb-3 h-8 w-8 animate-spin rounded-full border-2 border-blue-600 border-t-transparent"
17
17
  aria-hidden
18
18
  />
19
- <p className="text-sm text-gray-600">Loading SOMA page…</p>
19
+ <p className="text-sm text-gray-600">Loading page…</p>
20
20
  </div>
21
21
  </div>
22
22
  );
@@ -0,0 +1,13 @@
1
+ const faviconSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
2
+ <rect width="64" height="64" rx="14" fill="#1677ff"/>
3
+ <path d="M18 22h8l6 18 6-18h8L35 48h-6L18 22z" fill="#ffffff"/>
4
+ </svg>`;
5
+
6
+ export function GET(): Response {
7
+ return new Response(faviconSvg, {
8
+ headers: {
9
+ 'content-type': 'image/svg+xml; charset=utf-8',
10
+ 'cache-control': 'public, max-age=86400',
11
+ },
12
+ });
13
+ }
package/app/layout.tsx CHANGED
@@ -1,9 +1,13 @@
1
- import './globals.css';
2
-
3
- export const metadata = {
4
- title: 'SOMA',
5
- description: 'SOMA declarative UI runtime',
6
- };
1
+ import './globals.css';
2
+ import { readHostAppDisplayName } from '../core/host/app-config-composer';
3
+
4
+ export function generateMetadata() {
5
+ const displayName = readHostAppDisplayName();
6
+ return {
7
+ title: displayName || 'SOMA',
8
+ description: displayName || 'SOMA declarative UI runtime',
9
+ };
10
+ }
7
11
 
8
12
  export default function RootLayout({
9
13
  children,
package/app/page.tsx CHANGED
@@ -1,20 +1,9 @@
1
- import dynamic from 'next/dynamic';
2
- import { Suspense } from 'react';
3
- import { SomaHydrationShell } from './components/SomaHydrationShell';
1
+ import { SomaHostPage, type SomaPageSearchParams } from './components/SomaHostPage';
4
2
 
5
- /**
6
- * SSR 边界(8.4):服务端仅渲染占位壳,SOMA 运行时在客户端 mount。
7
- * 避免 window/document 在 SSR 阶段被访问,消除 hydration mismatch。
8
- */
9
- const SomaPageClient = dynamic(() => import('./SomaPageClient'), {
10
- ssr: false,
11
- loading: () => <SomaHydrationShell />,
12
- });
13
-
14
- export default function SomaEntryPage() {
15
- return (
16
- <Suspense fallback={<SomaHydrationShell />}>
17
- <SomaPageClient />
18
- </Suspense>
19
- );
3
+ export default function SomaRootPage({
4
+ searchParams,
5
+ }: {
6
+ searchParams?: SomaPageSearchParams;
7
+ }) {
8
+ return <SomaHostPage pathname="/" searchParams={searchParams} />;
20
9
  }
@@ -0,0 +1,9 @@
1
+ function somaRouteNotFound(): Response {
2
+ return Response.json({ error: 'SOMA internal endpoint not found' }, { status: 404 });
3
+ }
4
+
5
+ export const GET = somaRouteNotFound;
6
+ export const POST = somaRouteNotFound;
7
+ export const PUT = somaRouteNotFound;
8
+ export const PATCH = somaRouteNotFound;
9
+ export const DELETE = somaRouteNotFound;
@@ -1,8 +1,8 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { loadPrecompiledManifest, findPrecompiledPage } from '@/core/compiler/precompiled-manifest-loader';
3
+ import { loadPrecompiledManifest, findPrecompiledPage } from '../../../core/compiler/precompiled-manifest-loader';
4
4
 
5
- /** GET /api/soma-manifest?path=/items — returns precompiled page config */
5
+ /** GET /soma/manifest?path=/items - returns precompiled page config without invoking Host hooks. */
6
6
  export async function GET(request: Request): Promise<Response> {
7
7
  const hostDir = process.env.SOMA_HOST_DIR;
8
8
  if (!hostDir) {
@@ -30,7 +30,7 @@ export async function GET(request: Request): Promise<Response> {
30
30
  timers: page.timers ?? [],
31
31
  styleConfig: page.styleConfig,
32
32
  locale: manifest.locale,
33
- appConfig: manifest.appConfig,
33
+ appConfig: page.appConfig ?? manifest.appConfig,
34
34
  manifestVersion: '1.0.0',
35
35
  generatedAt: fs.existsSync(path.join(hostDir, '.soma', 'manifest.json'))
36
36
  ? fs.statSync(path.join(hostDir, '.soma', 'manifest.json')).mtime.toISOString()
@@ -0,0 +1,29 @@
1
+ import { NextRequest } from 'next/server';
2
+ import {
3
+ loadSomaServerPageAssets,
4
+ SomaPageAssetError,
5
+ } from '../../../core/host/server-page-assets';
6
+
7
+ /** SOMA internal page asset endpoint. Host request hooks must never run here. */
8
+ export async function GET(request: NextRequest) {
9
+ try {
10
+ const assets = loadSomaServerPageAssets({
11
+ hostDir: process.env.SOMA_HOST_DIR,
12
+ urlPath: request.nextUrl.searchParams.get('path') || '/',
13
+ profile: 'render',
14
+ });
15
+ return Response.json(assets);
16
+ } catch (error) {
17
+ if (error instanceof SomaPageAssetError) {
18
+ return Response.json(
19
+ { error: error.message, code: error.code },
20
+ { status: error.status },
21
+ );
22
+ }
23
+ const detail = error instanceof Error ? error.message : String(error);
24
+ return Response.json(
25
+ { error: detail || 'Internal server error', code: 'SOMA_PAGE_ASSET_UNKNOWN' },
26
+ { status: 500 },
27
+ );
28
+ }
29
+ }