soma-core 2.1.5 → 2.2.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 (96) hide show
  1. package/README.md +2 -2
  2. package/bin/soma.cjs +1 -1
  3. package/bin/soma.ts +64 -15
  4. package/core/build/compiler/soma-precompile.js +11 -1
  5. package/core/client/base/SomaHttpClient.ts +85 -12
  6. package/core/client/data/data-object-resolver.ts +12 -1
  7. package/core/client/engine/event-engine.ts +3 -3
  8. package/core/client/engine/soma-bootstrap.ts +30 -30
  9. package/core/client/host-bridge/load-host-domain-class.ts +74 -20
  10. package/core/client/host-bridge/resolve-host-bootstrap.ts +125 -23
  11. package/core/client/infra/http/IHttpClient.ts +3 -1
  12. package/core/client/infra/http/SomaHttpService.ts +15 -6
  13. package/core/client/parser/data-config-parser.ts +6 -1
  14. package/core/server/api/dispatch-service-api.ts +212 -0
  15. package/core/server/api/load-host-service.ts +230 -56
  16. package/core/server/api/service-path.ts +78 -14
  17. package/core/server/engines/style/candidate-guard.ts +57 -0
  18. package/core/server/engines/style/index.ts +1 -1
  19. package/core/server/engines/style/tailwind-adapter.ts +83 -16
  20. package/core/server/host/source-packages.cjs +96 -30
  21. package/core/server/host/source-packages.ts +12 -5
  22. package/core/server/index.ts +39 -17
  23. package/core/server/infra/cache/ServerFileCache.ts +138 -25
  24. package/core/server/node.ts +32 -8
  25. package/core/shared/registry-generated/error-codes.ts +5 -0
  26. package/core/shared/registry-generated/limits.ts +5 -0
  27. package/core/shared/types/data-config.types.ts +2 -0
  28. package/dist/browser/soma-runtime.js +197 -49
  29. package/dist/cli/soma.js +68 -14
  30. package/dist/core/index.cjs +284 -64
  31. package/dist/host-native/aot-builder.cjs +850 -0
  32. package/dist/host-native/native-server.cjs +15338 -0
  33. package/dist/lsp/component-tree.cjs +11 -1
  34. package/dist/types/client/base/SomaHttpClient.d.ts +1 -8
  35. package/dist/types/client/data/data-object-resolver.d.ts +1 -0
  36. package/dist/types/client/engine/event-engine.d.ts +2 -2
  37. package/dist/types/client/engine/soma-bootstrap.d.ts +3 -2
  38. package/dist/types/client/host-bridge/load-host-domain-class.d.ts +1 -0
  39. package/dist/types/client/host-bridge/resolve-host-bootstrap.d.ts +20 -0
  40. package/dist/types/client/infra/http/IHttpClient.d.ts +2 -0
  41. package/dist/types/server/api/dispatch-service-api.d.ts +18 -0
  42. package/dist/types/server/api/load-host-service.d.ts +7 -2
  43. package/dist/types/server/api/service-path.d.ts +21 -1
  44. package/dist/types/server/engines/style/candidate-guard.d.ts +10 -0
  45. package/dist/types/server/engines/style/index.d.ts +1 -1
  46. package/dist/types/server/engines/style/tailwind-adapter.d.ts +12 -0
  47. package/dist/types/server/host/source-packages.d.cts +13 -1
  48. package/dist/types/server/host/source-packages.d.ts +7 -4
  49. package/dist/types/server/index.d.ts +18 -17
  50. package/dist/types/server/infra/cache/ServerFileCache.d.ts +28 -5
  51. package/dist/types/server/node.d.ts +10 -7
  52. package/dist/types/shared/registry-generated/error-codes.d.ts +4 -0
  53. package/dist/types/shared/registry-generated/limits.d.ts +4 -0
  54. package/dist/types/shared/types/data-config.types.d.ts +2 -0
  55. package/host-native/bin/host-native.cjs +204 -0
  56. package/host-native/client/browser-entry.ts +499 -0
  57. package/{host-next/app → host-native/client}/page-access.ts +12 -0
  58. package/host-native/client/router-bridge.ts +120 -0
  59. package/host-native/src/aot-builder.ts +486 -0
  60. package/host-native/src/csp-headers.ts +75 -0
  61. package/host-native/src/host-prepare.ts +123 -0
  62. package/{host-next/app/soma/manifest/route.ts → host-native/src/manifest-http.ts} +10 -10
  63. package/host-native/src/native-server.ts +691 -0
  64. package/host-native/src/page-http.ts +223 -0
  65. package/host-native/src/public-packages.cjs +167 -0
  66. package/{host-next/app/api/soma-registry/[...path]/route.ts → host-native/src/registry-handler.ts} +17 -19
  67. package/{host-next → host-native}/src/shell-routes.cjs +23 -13
  68. package/host-native/src/static-file.ts +172 -0
  69. package/host-native/src/workspace.ts +185 -0
  70. package/{host-next/app → host-native/styles}/globals.css +2 -2
  71. package/package.json +13 -32
  72. package/tsconfig.json +1 -1
  73. package/host-next/app/SomaPageClient.tsx +0 -359
  74. package/host-next/app/[...path]/page.tsx +0 -22
  75. package/host-next/app/api/[...path]/route.ts +0 -98
  76. package/host-next/app/components/SomaHostPage.tsx +0 -128
  77. package/host-next/app/components/SomaHydrationShell.tsx +0 -20
  78. package/host-next/app/components/SomaPageClientBoundary.tsx +0 -13
  79. package/host-next/app/components/SomaPageForbidden.tsx +0 -19
  80. package/host-next/app/favicon.ico/route.ts +0 -13
  81. package/host-next/app/layout.tsx +0 -27
  82. package/host-next/app/page.tsx +0 -9
  83. package/host-next/app/router-bridge.ts +0 -42
  84. package/host-next/app/soma/[...path]/route.ts +0 -9
  85. package/host-next/app/soma/_shared/host-prepare.ts +0 -33
  86. package/host-next/app/soma/_shared/page-http.ts +0 -86
  87. package/host-next/app/soma/page/route.ts +0 -36
  88. package/host-next/app/soma/route.ts +0 -9
  89. package/host-next/app/soma-runtime/[...file]/route.ts +0 -21
  90. package/host-next/app/soma-runtime/_shared/static-file.ts +0 -89
  91. package/host-next/bin/host-next.cjs +0 -60
  92. package/host-next/instrumentation.ts +0 -18
  93. package/host-next/next-env.d.ts +0 -7
  94. package/host-next/next.config.js +0 -410
  95. package/host-next/proxy.ts +0 -43
  96. package/host-next/src/workspace.ts +0 -543
@@ -6437,6 +6437,11 @@ var SOMA_PIPELINE_LIMITS = {
6437
6437
  "module": "soma-lite",
6438
6438
  "file": "src/app/server/provenance-limit.ts",
6439
6439
  "symbol": "SOMA_PIPELINE_LIMITS"
6440
+ },
6441
+ {
6442
+ "module": "soma-robot",
6443
+ "file": "src/common/limits.ts",
6444
+ "symbol": "SOMA_PIPELINE_LIMITS_AI_ROBOT"
6440
6445
  }
6441
6446
  ],
6442
6447
  "registry": {
@@ -10380,8 +10385,13 @@ function parseSource(raw, path, objectNames, selfName, deps) {
10380
10385
  source.failWhen = value2;
10381
10386
  } else if (key === "messagePath") {
10382
10387
  source.messagePath = value2;
10388
+ } else if (key === "dataPath") {
10389
+ if (typeof value2 !== "string" || value2.trim() === "") {
10390
+ throw new SomaDataConfigError(`dataPath \u5FC5\u987B\u662F\u975E\u7A7A\u7684\u54CD\u5E94\u4F53\u70B9\u8DEF\u5F84`, `${path}.dataPath`);
10391
+ }
10392
+ source.dataPath = value2.trim();
10383
10393
  } else {
10384
- throw new SomaDataConfigError(`\u672A\u77E5\u7684\u6765\u6E90\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: api / params / into / require / failWhen / messagePath\uFF09`, `${path}.${key}`);
10394
+ throw new SomaDataConfigError(`\u672A\u77E5\u7684\u6765\u6E90\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: api / params / into / require / failWhen / messagePath / dataPath\uFF09`, `${path}.${key}`);
10385
10395
  }
10386
10396
  }
10387
10397
  if (source.failWhen !== void 0 || source.messagePath !== void 0) {
@@ -9,14 +9,7 @@ export interface SomaHttpClientConfig {
9
9
  /** Generic headers supplied by the host runtime, such as page context. */
10
10
  defaultHeaders?: Record<string, string> | (() => Record<string, string>);
11
11
  }
12
- /**
13
- * 从错误响应正文里提炼一句可读文案。
14
- *
15
- * 服务端精心写的结构化错误(`{ ok: false, error: "未知组件:X" }`)才是调用方要的信息,
16
- * 只留 statusText 等于把它整条丢掉。正文也可能是 HTML 错误页或空串,
17
- * 因此 JSON 解析必须容错——解析失败只是"没有结构化字段",不该把请求变成另一种崩法。
18
- */
19
- export declare function describeHttpErrorBody(body: string, statusText: string): string;
12
+ export declare function describeHttpErrorBody(body: string, statusText: string, status?: number): string;
20
13
  /**
21
14
  * SomaHttpClient — API 请求封装
22
15
  *
@@ -241,6 +241,7 @@ export declare class SomaDataObjectResolver {
241
241
  /** 取一个来源;声明了 `require` 且有必填参数缺(null / undefined / 空串)时不发请求,返回 skipped */
242
242
  private fetchOrSkip;
243
243
  private requestSource;
244
+ private pickDotted;
244
245
  /** 聚合来源结果:into 写入子键;缺省先解开宿主信封,再浅合并进根(数组整体替换) */
245
246
  mergeSource(current: unknown, source: SomaDataSourceConfig, data: unknown): unknown;
246
247
  /** 解析 params:`$` 引用替换为实际值 → 展平为 http query 参数表(空值参数省略) */
@@ -27,7 +27,7 @@ export interface SomaEventEngineOptions<TContext extends Record<string, unknown>
27
27
  container: HTMLElement;
28
28
  adapter: IContainerAdapter;
29
29
  /**
30
- * 分级确认执行口(R-23):typed / consent 级交给它(通知服务 -> 渲染端口);plain 级与未注入时一律走 `adapter.confirm(text)`。
30
+ * 分级确认执行口(R-23):注入时全级别(plain / consent / typed)交给它(通知服务 -> 渲染端口);未注入时安全回退 `adapter.confirm(spec.text)`。
31
31
  * 返回 false = 用户取消。
32
32
  */
33
33
  confirmGraded?: (spec: SomaConfirmSpec) => boolean | Promise<boolean>;
@@ -119,7 +119,7 @@ export declare class SomaEventEngine<TContext extends Record<string, unknown> =
119
119
  */
120
120
  private runNotify;
121
121
  private getContext;
122
- /** 分级确认的唯一出口:typed / consent 且注入了执行口 -> 执行口;否则回落 plain(一句话 `adapter.confirm`) */
122
+ /** 分级确认的唯一出口:注入了执行口 -> 执行口(plain / consent / typed 全级别);否则安全回退 adapter.confirm(spec.text) */
123
123
  private askConfirm;
124
124
  private preCheck;
125
125
  private postAction;
@@ -321,8 +321,9 @@ export declare class SomaBootstrap {
321
321
  private dataResolver;
322
322
  private dataLoadEpoch;
323
323
  private dataOwnerEpoch;
324
- /** 写入结果存储:与 bootstrap 同寿(字段错误、冲突、乐观叠层),`services.data.writeOutcome` 读它 */
325
- private readonly writeOutcomeStore;
324
+ /** 数据端口宿主状态(单一真源):持有写入结果存储与写入事件执行口,端口重建同寿 */
325
+ private readonly dataPortHostState;
326
+ private get writeOutcomeStore();
326
327
  /** 快捷键注册中心(C-r18):唯一一份,`services.shortcuts` 直通 */
327
328
  private shortcutsInstance;
328
329
  private componentStyleNonce?;
@@ -9,4 +9,5 @@ export declare class SomaDomainLoadError extends Error {
9
9
  export declare function resolveSomaDomainConstructor(module: SomaDomainModule, label: string): SomaDomainConstructor;
10
10
  export declare function loadHostDomainClass(context: SomaDomainLoadContext, options?: {
11
11
  allowLocaleOnlyFallback?: boolean;
12
+ loadFallbackModule?: (base: string) => Promise<SomaDomainModule>;
12
13
  }): Promise<SomaDomainConstructor>;
@@ -4,6 +4,26 @@ import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
4
4
  export type SomaBootstrapConfigurator = (ctx: {
5
5
  getServices: () => SomaRuntimeServices | undefined;
6
6
  }) => Partial<SomaBootstrapOptions>;
7
+ export declare const HOST_BOOTSTRAP_MODULE = "@soma-host/bootstrap/soma-bootstrap";
8
+ /**
9
+ * 解包测试运行器或装载器可能附加的包装错误(如 Error.cause)。
10
+ */
11
+ export declare function unwrapLoaderError(error: unknown): unknown;
12
+ /**
13
+ * 这个异常是否具备「模块未找到」的特征(CJS/ESM/Webpack/Vite 等运行时形态)。
14
+ */
15
+ export declare function hasModuleNotFoundSignature(error: unknown): boolean;
16
+ /**
17
+ * 从缺模块错误信息中提取被引用的说明符(如 'X' 或 "X")。
18
+ */
19
+ export declare function extractMissingModuleSpecifier(message: string): string | null;
20
+ /**
21
+ * 精确判定异常是否为「目标可选入口模块自身不存在」。
22
+ * - 若不具备缺模块特征 -> false
23
+ * - 若从 message 中提取出具体说明符 spec -> 仅当 spec 指向 expectedSpecifiers 时返回 true,否则(子依赖缺失)返回 false
24
+ * - 若没有引号包裹的具体模块名(无引号泛化缺模块错误) -> 视为入口自身缺失返回 true
25
+ */
26
+ export declare function isOptionalEntryAbsent(error: unknown, expectedSpecifiers: string | readonly string[]): boolean;
7
27
  /** 分片加载失败的重试退避(由 Host 装配注入,值取自 soma-design 限值表 hostDefaults.chunkLoadBackoffMs;core 不留数字) */
8
28
  export interface HostBootstrapRetry {
9
29
  /** 第 n 次重试等待 chunkLoadBackoffMs × n 毫秒 */
@@ -7,6 +7,8 @@ export interface HttpRequestConfig {
7
7
  onResponse?: (info: {
8
8
  readonly status: number;
9
9
  }) => void;
10
+ /** 为 true 时非 2xx 响应只抛异常、不触发全局 onHttpError 提示,供上层自带语义错误处理的调用方按需抑制重复弹窗 */
11
+ silentErrorToast?: boolean;
10
12
  }
11
13
  export interface UploadOptions {
12
14
  /** multipart 字段名,默认 file */
@@ -0,0 +1,18 @@
1
+ export interface RequestCookie {
2
+ readonly name: string;
3
+ readonly value: string;
4
+ }
5
+ export interface RequestCookiesAdapter {
6
+ get(name: string): RequestCookie | undefined;
7
+ getAll(name?: string): RequestCookie[];
8
+ has(name: string): boolean;
9
+ }
10
+ export interface DispatchHostServiceApiOptions {
11
+ readonly segments?: readonly string[];
12
+ readonly hostDir?: string;
13
+ }
14
+ export declare function polyfillServiceRequest<T extends Request>(request: T): T & {
15
+ nextUrl: URL;
16
+ cookies: RequestCookiesAdapter;
17
+ };
18
+ export declare function dispatchHostServiceApiRequest(request: Request, segmentsOrOptions?: readonly string[] | DispatchHostServiceApiOptions): Promise<Response>;
@@ -1,5 +1,10 @@
1
- import type { IService } from './IService';
1
+ import type { IService } from "./IService";
2
+ export type AotServiceResolver = (routeKey: string, segments: readonly string[]) => unknown | Promise<unknown>;
3
+ export declare function resolveServiceExport(loaded: unknown, filePath?: string): IService | null;
4
+ export declare function registerAotServiceResolver(hostDir: string, resolver: AotServiceResolver | null): void;
5
+ export declare function getAotServiceResolver(hostDir: string): AotServiceResolver | undefined;
6
+ export declare function clearHostServiceCache(hostDir?: string): void;
2
7
  /**
3
- * 按约定从宿主 api/service/ 加载 IService 实例(运行时读盘,无需手写 registry)。
8
+ * 按约定从宿主 apiRoot 加载 IService 实例(运行时按需加载,零手动 registry)。
4
9
  */
5
10
  export declare function loadHostService(segments: string[]): IService | null;
@@ -3,11 +3,31 @@
3
3
  * @example "user-profile" → "UserProfile", "oauth_token" → "OauthToken"
4
4
  */
5
5
  export declare function toPascalCase(str: string): string;
6
+ /**
7
+ * 校验服务路由片段的安全与合法性,并将末段解析为 PascalCase 类名。
8
+ * 拒收:空片段、"." / ".."、以 "_" 起头的私有模块、含 "/" / "\\" / "\0" 的穿越字符。
9
+ */
10
+ export declare function validateServiceSegments(segments: readonly string[]): {
11
+ dirSegments: string[];
12
+ className: string;
13
+ } | null;
6
14
  /**
7
15
  * 从 /api/{...path} 片段解析宿主服务文件绝对路径。
8
16
  *
9
17
  * 规则(与文档 12.4 一致):
10
- * - ["login"] → {host}/api/service/Login.ts
18
+ * - ["products"] → {host}/api/service/Products.ts
11
19
  * - ["user", "profile"] → {host}/api/service/user/Profile.ts
12
20
  */
13
21
  export declare function resolveServiceFilePath(hostDir: string, segments: string[]): string | null;
22
+ export interface ResolveHostServiceCandidateOptions {
23
+ readonly allowDirectRoot?: boolean;
24
+ readonly extensions?: readonly string[];
25
+ }
26
+ /**
27
+ * 在给定后端根 apiRoot 下按顺序探测真实存在的服务文件(默认后缀顺序 [".ts", ".js", ".mjs", ".cjs"]):
28
+ * 1) <apiRoot>/api/service/<...dirSegments>/<ClassName><ext>
29
+ * 2) <apiRoot>/service/<...dirSegments>/<ClassName><ext>
30
+ * 3) 当 options?.allowDirectRoot === true 时额外探测 <apiRoot>/<...dirSegments>/<ClassName><ext>
31
+ * 每一步都必须校验 resolved.startsWith(normalizedAllowedBase + path.sep) 且 fs.statSync(resolved, { throwIfNoEntry: false })?.isFile() === true
32
+ */
33
+ export declare function resolveHostServiceCandidate(apiRoot: string, segments: string[], options?: ResolveHostServiceCandidateOptions): string | null;
@@ -12,3 +12,13 @@ export declare function guardCandidates(candidates: readonly string[], allow: (c
12
12
  export declare function escapeClassName(name: string): string;
13
13
  /** 产出的样式表里是否有以该候选类为类选择器的规则(不把更长的类名当命中) */
14
14
  export declare function hasRuleForCandidate(css: string, candidate: string): boolean;
15
+ /** 从 CSS 选择器片段单遍提取所有类名(已解码转义) */
16
+ export declare function extractClassesFromCss(css: string): Set<string>;
17
+ /**
18
+ * 批量判定编译产物中是否包含指定候选类的规则。
19
+ * O(1) 查表命中 99.9% 候选类,未命中时回退 hasRuleForCandidate 兜底复杂选择器,结果逐字等价。
20
+ */
21
+ export declare function partitionCompiledCandidates(css: string, candidates: readonly string[]): {
22
+ matched: string[];
23
+ unmatched: string[];
24
+ };
@@ -3,7 +3,7 @@ import type { EngineLoadTelemetry } from '../../../client/engines/load';
3
3
  export type { SomaStyleEngine, StyleCompileInput, StyleCompileRejection, StyleCompileResult, } from '../../../shared/engines/style/style-engine.types';
4
4
  export { assertStyleEngineAdapter, assertThemeCss } from './port';
5
5
  export { guardCandidates } from './candidate-guard';
6
- export { createTailwindAdapter } from './tailwind-adapter';
6
+ export { createTailwindAdapter, clearTailwindCompilerCache } from './tailwind-adapter';
7
7
  export interface StyleEnginePortOptions {
8
8
  readonly telemetry?: EngineLoadTelemetry;
9
9
  }
@@ -1,6 +1,18 @@
1
1
  import type { SomaStyleEngine } from '../../../shared/engines/style/style-engine.types';
2
2
  import { type EngineLoadTelemetry } from '../../../client/engines/load';
3
+ export interface TailwindCompiler {
4
+ build(candidates: string[]): string;
5
+ }
6
+ export interface TailwindModule {
7
+ compile(css: string, options?: {
8
+ base?: string;
9
+ }): Promise<TailwindCompiler>;
10
+ }
3
11
  export interface TailwindAdapterOptions {
4
12
  readonly telemetry?: EngineLoadTelemetry;
13
+ readonly base?: string;
14
+ readonly loadTailwind?: () => Promise<TailwindModule>;
5
15
  }
16
+ /** 清除 Tailwind 编译器与模块缓存(供内部测试重置) */
17
+ export declare function clearTailwindCompilerCache(): void;
6
18
  export declare function createTailwindAdapter(adapterOptions?: TailwindAdapterOptions): SomaStyleEngine;
@@ -1,7 +1,18 @@
1
1
  export type SomaEnv = Readonly<Record<string, string | undefined>>;
2
+ export type SomaAssetSourceItem = {
3
+ type: "host" | "package";
4
+ name: string;
5
+ assetRoot: string;
6
+ codeRoot: string;
7
+ apiRoot: string;
8
+ configRoot: string;
9
+ packageName?: string;
10
+ };
2
11
  /** 环境变量:显式声明的源包名(逗号分隔),不论其 package.json 怎么写都当源包 */
3
12
  export const SOMA_SOURCE_PACKAGES_ENV: "SOMA_SOURCE_PACKAGES";
4
- export function getSomaHostSourceRoot(hostDir: any): string;
13
+ export function getSomaHostSourceRoot(hostDir: any, env?: NodeJS.ProcessEnv): string;
14
+ export function getSomaHostApiRoot(hostDir: any, env?: NodeJS.ProcessEnv): string;
15
+ export function clearSomaAssetSourcesCache(): void;
5
16
  /** Host 自己 + 全部源包(依赖里声明的与环境变量显式声明的);Host 恒在第一位 */
6
17
  /** @param {SomaEnv} [env] */
7
18
  export function getSomaAssetSources(hostDir: any, env?: SomaEnv): {
@@ -9,6 +20,7 @@ export function getSomaAssetSources(hostDir: any, env?: SomaEnv): {
9
20
  name: string;
10
21
  assetRoot: string;
11
22
  codeRoot: string;
23
+ apiRoot: string;
12
24
  configRoot: any;
13
25
  }[];
14
26
  /** 源包名清单(next.config 的 transpilePackages 用) */
@@ -1,15 +1,18 @@
1
1
  export interface SomaAssetSource {
2
- type: 'host' | 'package';
2
+ type: "host" | "package";
3
3
  name: string;
4
4
  assetRoot: string;
5
5
  codeRoot: string;
6
+ apiRoot: string;
6
7
  configRoot: string;
7
8
  packageName?: string;
8
9
  }
9
- export { getSomaHostConfigRoot, normalizeSomaEnv, readSomaEnv, resolveAppConfigPath, resolveHostAppConfigPath, resolveHostConfigRoot, } from './host-config-paths';
10
- export type { SomaEnvName } from './host-config-paths';
10
+ export { getSomaHostConfigRoot, normalizeSomaEnv, readSomaEnv, resolveAppConfigPath, resolveHostAppConfigPath, resolveHostConfigRoot, } from "./host-config-paths";
11
+ export type { SomaEnvName } from "./host-config-paths";
11
12
  /** 实现只有 `source-packages.cjs` 一份(RT3 单实现);这里只补类型再导出,不另写第二份。 */
12
- export declare const getSomaHostSourceRoot: (hostDir: string) => string;
13
+ export declare const getSomaHostSourceRoot: (hostDir: string, env?: Readonly<Record<string, string | undefined>>) => string;
14
+ export declare const getSomaHostApiRoot: (hostDir: string, env?: Readonly<Record<string, string | undefined>>) => string;
15
+ export declare const clearSomaAssetSourcesCache: () => void;
13
16
  /** Host 自己 + 全部源包;Host 恒在第一位 */
14
17
  export declare const getSomaAssetSources: (hostDir: string, env?: Readonly<Record<string, string | undefined>>) => SomaAssetSource[];
15
18
  export declare const listSomaSourcePackageNames: (hostDir: string, env?: Readonly<Record<string, string | undefined>>) => string[];
@@ -7,20 +7,21 @@
7
7
  * Public Host imports should keep using `soma-core` / `soma-core/base` for page code.
8
8
  * This entry is additive and optional.
9
9
  */
10
- import 'server-only';
11
- export { ServerFileCache } from './infra/cache/ServerFileCache';
12
- export { withSomaServerRequestContext, type SomaServerRequestContextOptions, } from './infra/http/soma-server-request-context';
13
- export type { IService, SomaServiceRequest } from './api/IService';
14
- export { loadHostService } from './api/load-host-service';
15
- export { resolveServiceFilePath, toPascalCase } from './api/service-path';
16
- export { invokeHostRequestHook } from './host/invoke-host-request-hook';
17
- export { resolveHostRequestHook, type SomaHostRequestContext, type SomaHostRequestKind, type SomaRequestHook, } from './host/resolve-host-request-hook';
18
- export { createSomaCspHeader, createSomaCspNonce, buildSomaCspDirectives, buildSomaCspHeaderValue, resolveSomaCspMode, resolveSomaCspOptionsFromEnv, somaCspHeaderName, SOMA_CSP_MODE_ENV, SOMA_CSP_CONNECT_SRC_ENV, SOMA_CSP_IMG_SRC_ENV, SOMA_CSP_FRAME_SRC_ENV, SOMA_CSP_REPORT_URI_ENV, SOMA_CSP_NONCE_HEADER, type SomaCspMode, type SomaCspOptions, type SomaCspHeader, } from './host/content-security-policy';
19
- export { readSomaCspNonce, somaCspNonceMetadata, type SomaCspHeaderBag, } from './host/csp-nonce-metadata';
20
- export { loadHostAssembly, registerShellRoutes, resolveHostLoginPath, SOMA_HOST_ASSEMBLY_FILE } from './host/host-assembly';
21
- export type { SomaHostAssembly } from '../shared/types/host-assembly.types';
22
- export { loadPageMarkupConfig, renderColorSchemeMeta } from './host/page-markup-config';
23
- export type { SomaPageMarkup } from '../shared/types/component-tree.types';
24
- export { loadSomaServerPageAssets, resolveSomaPageSource, SomaPageAssetError, type SomaServerPageAssets, } from './host/server-page-assets';
25
- export { getSomaAssetSources, getSomaHostSourceRoot, type SomaAssetSource, } from './host/source-packages';
26
- export * from './runtime-space';
10
+ import "server-only";
11
+ export { ServerFileCache } from "./infra/cache/ServerFileCache";
12
+ export { withSomaServerRequestContext, type SomaServerRequestContextOptions, } from "./infra/http/soma-server-request-context";
13
+ export type { IService, SomaServiceRequest } from "./api/IService";
14
+ export { clearHostServiceCache, getAotServiceResolver, loadHostService, registerAotServiceResolver, resolveServiceExport, type AotServiceResolver, } from "./api/load-host-service";
15
+ export { resolveHostServiceCandidate, resolveServiceFilePath, toPascalCase, validateServiceSegments, type ResolveHostServiceCandidateOptions, } from "./api/service-path";
16
+ export { dispatchHostServiceApiRequest, polyfillServiceRequest, type DispatchHostServiceApiOptions, type RequestCookie, type RequestCookiesAdapter, } from "./api/dispatch-service-api";
17
+ export { invokeHostRequestHook } from "./host/invoke-host-request-hook";
18
+ export { resolveHostRequestHook, type SomaHostRequestContext, type SomaHostRequestKind, type SomaRequestHook, } from "./host/resolve-host-request-hook";
19
+ export { createSomaCspHeader, createSomaCspNonce, buildSomaCspDirectives, buildSomaCspHeaderValue, resolveSomaCspMode, resolveSomaCspOptionsFromEnv, somaCspHeaderName, SOMA_CSP_MODE_ENV, SOMA_CSP_CONNECT_SRC_ENV, SOMA_CSP_IMG_SRC_ENV, SOMA_CSP_FRAME_SRC_ENV, SOMA_CSP_REPORT_URI_ENV, SOMA_CSP_NONCE_HEADER, type SomaCspMode, type SomaCspOptions, type SomaCspHeader, } from "./host/content-security-policy";
20
+ export { readSomaCspNonce, somaCspNonceMetadata, type SomaCspHeaderBag, } from "./host/csp-nonce-metadata";
21
+ export { loadHostAssembly, registerShellRoutes, resolveHostLoginPath, SOMA_HOST_ASSEMBLY_FILE } from "./host/host-assembly";
22
+ export type { SomaHostAssembly } from "../shared/types/host-assembly.types";
23
+ export { loadPageMarkupConfig, renderColorSchemeMeta } from "./host/page-markup-config";
24
+ export type { SomaPageMarkup } from "../shared/types/component-tree.types";
25
+ export { loadSomaServerPageAssets, resolveSomaPageSource, SomaPageAssetError, type SomaServerPageAssets, } from "./host/server-page-assets";
26
+ export { clearSomaAssetSourcesCache, getSomaAssetSources, getSomaHostApiRoot, getSomaHostSourceRoot, type SomaAssetSource, } from "./host/source-packages";
27
+ export * from "./runtime-space";
@@ -1,16 +1,30 @@
1
+ export interface ServerFileCacheOptions {
2
+ maxFiles?: number;
3
+ maxFileBytes?: number;
4
+ maxDirs?: number;
5
+ }
1
6
  /**
2
- * 服务端文件缓存单例
7
+ * 服务端文件缓存单例(有界 LRU + 监听去重)
3
8
  *
4
9
  * 将磁盘文件内容和目录列表缓存到内存中,避免每次请求都执行 I/O。
5
- * 支持 fs.watch 监听文件变化,自动失效对应缓存条目。
10
+ * 支持有界文件数、总字节上限与目录缓存上限;支持 fs.watch 监听去重,自动失效对应缓存条目。
6
11
  */
7
12
  export declare class ServerFileCache {
8
13
  private static instance;
14
+ readonly maxFiles: number;
15
+ readonly maxFileBytes: number;
16
+ readonly maxDirs: number;
9
17
  private fileCache;
10
18
  private dirCache;
11
19
  private watchers;
12
- private constructor();
13
- static getInstance(): ServerFileCache;
20
+ private watchedRoots;
21
+ private currentFileBytes;
22
+ constructor(options?: ServerFileCacheOptions);
23
+ static getInstance(options?: ServerFileCacheOptions): ServerFileCache;
24
+ get size(): number;
25
+ get fileBytes(): number;
26
+ get dirSize(): number;
27
+ get watchersCount(): number;
14
28
  /**
15
29
  * 读取文件内容,命中缓存直接返回,未命中则读磁盘并缓存。
16
30
  */
@@ -25,11 +39,20 @@ export declare class ServerFileCache {
25
39
  */
26
40
  readDirFiles(dirPath: string, ext: string): string[];
27
41
  readDirNames(dirPath: string, ext: string): string[];
42
+ private setDirCache;
28
43
  /**
29
44
  * 监听目录变化,自动失效缓存。
30
- * 使用 fs.watch 递归监听。
45
+ * 使用 fs.watch 递归监听;已监听同一目录或其祖先目录时自动去重。
31
46
  */
32
47
  watchAndInvalidate(rootDir: string): void;
48
+ /**
49
+ * 清除所有缓存。
50
+ */
51
+ clear(): void;
52
+ /**
53
+ * 使所有缓存失效。
54
+ */
55
+ invalidate(): void;
33
56
  /**
34
57
  * 清除所有缓存并关闭 watcher。
35
58
  */
@@ -1,16 +1,19 @@
1
1
  /**
2
2
  * Node 安全的服务端子路径(`soma-core/server/node`,R-28 / C9)。
3
3
  *
4
- * 为什么单开一个口:`soma-core/server` 带 `import 'server-only'`,并连带 CSP 这类只在 Next 服务端成立的模块;
4
+ * 为什么单开一个口:`soma-core/server` 带 `import "server-only"`,并连带 CSP 这类只在 Next 服务端成立的模块;
5
5
  * CLI、testkit、经 jiti 在纯 Node 语境加载的 Host 服务一进来就会抛。这里只放「宿主资源定位 / 页面资产 / 块加载 /
6
6
  * Registry 写管线」这类纯 Node 能力,**不 import `server-only`,也不得(经任何传递依赖)加载
7
7
  * `server/host/content-security-policy` / `csp-nonce-metadata`**——由 `tests/unit/server/node-entry-purity.test.ts` 看守。
8
8
  *
9
9
  * 与 `soma-core/server` 的关系:同名导出是同一份实现的再导出,不是第二份;Next 服务端代码继续用 `soma-core/server`。
10
10
  */
11
- export { collectIncludes, collectPageEntries, getSomaAssetSources, getSomaHostConfigRoot, getSomaHostSourceRoot, listSomaSourcePackageNames, normalizeSomaEnv, orderSourcesForOverride, readSomaEnv, resolveAppConfigPath, resolveHostAppConfigPath, resolveHostConfigRoot, type SomaAssetSource, type SomaEnvName, type SomaSourcePageEntry, } from './host/source-packages';
12
- export { loadSomaServerPageAssets, resolveSomaPageSource, SomaPageAssetError, type SomaServerPageAssets, } from './host/server-page-assets';
13
- export { loadPageMarkupConfig, renderColorSchemeMeta } from './host/page-markup-config';
14
- export { resolveServiceFilePath, toPascalCase } from './api/service-path';
15
- export { assertRegistryPublishAddress, bindPublishedRegistryPage, resetRegistryWriteRateLimit, unbindArchivedRegistryPage, } from './registry/registry-write-pipeline';
16
- export { expiresToMinutes } from '../shared/page-envelope';
11
+ export { clearSomaAssetSourcesCache, collectIncludes, collectPageEntries, getSomaAssetSources, getSomaHostApiRoot, getSomaHostConfigRoot, getSomaHostSourceRoot, listSomaSourcePackageNames, normalizeSomaEnv, orderSourcesForOverride, readSomaEnv, resolveAppConfigPath, resolveHostAppConfigPath, resolveHostConfigRoot, type SomaAssetSource, type SomaEnvName, type SomaSourcePageEntry, } from "./host/source-packages";
12
+ export { loadSomaServerPageAssets, resolveSomaPageSource, SomaPageAssetError, type SomaServerPageAssets, } from "./host/server-page-assets";
13
+ export { loadPageMarkupConfig, renderColorSchemeMeta } from "./host/page-markup-config";
14
+ export { resolveHostServiceCandidate, resolveServiceFilePath, toPascalCase, validateServiceSegments, type ResolveHostServiceCandidateOptions, } from "./api/service-path";
15
+ export { clearHostServiceCache, getAotServiceResolver, loadHostService, registerAotServiceResolver, resolveServiceExport, type AotServiceResolver, } from "./api/load-host-service";
16
+ export { dispatchHostServiceApiRequest, polyfillServiceRequest, type DispatchHostServiceApiOptions, type RequestCookie, type RequestCookiesAdapter, } from "./api/dispatch-service-api";
17
+ export type { IService, SomaServiceRequest } from "./api/IService";
18
+ export { assertRegistryPublishAddress, bindPublishedRegistryPage, resetRegistryWriteRateLimit, unbindArchivedRegistryPage, } from "./registry/registry-write-pipeline";
19
+ export { expiresToMinutes } from "../shared/page-envelope";
@@ -25,6 +25,10 @@ export declare const SOMA_PIPELINE_ERROR_CODES: {
25
25
  readonly module: "soma-ai-page";
26
26
  readonly file: "src/versions/errors.ts";
27
27
  readonly symbol: "SOMA_PIPELINE_ERROR_CODES_AI_PAGE";
28
+ }, {
29
+ readonly module: "soma-robot";
30
+ readonly file: "src/common/errors.ts";
31
+ readonly symbol: "SOMA_PIPELINE_ERROR_CODES_AI_ROBOT";
28
32
  }];
29
33
  readonly families: {
30
34
  readonly pageRegistry: {
@@ -349,6 +349,10 @@ export declare const SOMA_PIPELINE_LIMITS: {
349
349
  readonly module: "soma-lite";
350
350
  readonly file: "src/app/server/provenance-limit.ts";
351
351
  readonly symbol: "SOMA_PIPELINE_LIMITS";
352
+ }, {
353
+ readonly module: "soma-robot";
354
+ readonly file: "src/common/limits.ts";
355
+ readonly symbol: "SOMA_PIPELINE_LIMITS_AI_ROBOT";
352
356
  }];
353
357
  readonly registry: {
354
358
  readonly recordMaxBytes: 65536;
@@ -100,6 +100,8 @@ export interface SomaDataSourceConfig {
100
100
  failWhen?: SomaFieldPredicate;
101
101
  /** 命中 failWhen 时,业务错误信息在响应体里的点路径 */
102
102
  messagePath?: string;
103
+ /** 响应体数据点路径(当未指定 into 时,按点路径取出内层载荷并入对象根) */
104
+ dataPath?: string;
103
105
  }
104
106
  /**
105
107
  * 删除端点(`write.delete`):按行删除。`api` 的 `{占位符}` 取自目标记录(只给身份时只能是身份字段),