soma-core 2.1.4 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/build/compiler/soma-precompile.js +11 -1
- package/core/client/base/SomaHttpClient.ts +85 -12
- package/core/client/data/data-object-resolver.ts +12 -1
- package/core/client/engine/event-engine.ts +3 -3
- package/core/client/engine/soma-bootstrap.ts +30 -30
- package/core/client/host-bridge/load-host-domain-class.ts +74 -20
- package/core/client/host-bridge/resolve-host-bootstrap.ts +125 -23
- package/core/client/infra/http/IHttpClient.ts +3 -1
- package/core/client/infra/http/SomaHttpService.ts +15 -6
- package/core/client/parser/data-config-parser.ts +6 -1
- package/core/shared/registry-generated/error-codes.ts +5 -0
- package/core/shared/registry-generated/limits.ts +5 -0
- package/core/shared/types/data-config.types.ts +2 -0
- package/dist/browser/soma-runtime.js +197 -49
- package/dist/core/index.cjs +284 -64
- package/dist/lsp/component-tree.cjs +11 -1
- package/dist/types/client/base/SomaHttpClient.d.ts +1 -8
- package/dist/types/client/data/data-object-resolver.d.ts +1 -0
- package/dist/types/client/engine/event-engine.d.ts +2 -2
- package/dist/types/client/engine/soma-bootstrap.d.ts +3 -2
- package/dist/types/client/host-bridge/load-host-domain-class.d.ts +1 -0
- package/dist/types/client/host-bridge/resolve-host-bootstrap.d.ts +20 -0
- package/dist/types/client/infra/http/IHttpClient.d.ts +2 -0
- package/dist/types/shared/registry-generated/error-codes.d.ts +4 -0
- package/dist/types/shared/registry-generated/limits.d.ts +4 -0
- package/dist/types/shared/types/data-config.types.d.ts +2 -0
- package/host-next/next.config.js +10 -0
- package/package.json +2 -2
|
@@ -7826,6 +7826,11 @@ var SOMA_PIPELINE_LIMITS = {
|
|
|
7826
7826
|
"module": "soma-lite",
|
|
7827
7827
|
"file": "src/app/server/provenance-limit.ts",
|
|
7828
7828
|
"symbol": "SOMA_PIPELINE_LIMITS"
|
|
7829
|
+
},
|
|
7830
|
+
{
|
|
7831
|
+
"module": "soma-robot",
|
|
7832
|
+
"file": "src/common/limits.ts",
|
|
7833
|
+
"symbol": "SOMA_PIPELINE_LIMITS_AI_ROBOT"
|
|
7829
7834
|
}
|
|
7830
7835
|
],
|
|
7831
7836
|
"registry": {
|
|
@@ -8136,8 +8141,13 @@ function parseSource(raw, path, objectNames, selfName, deps) {
|
|
|
8136
8141
|
source.failWhen = value;
|
|
8137
8142
|
} else if (key === "messagePath") {
|
|
8138
8143
|
source.messagePath = value;
|
|
8144
|
+
} else if (key === "dataPath") {
|
|
8145
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
8146
|
+
throw new SomaDataConfigError(`dataPath \u5FC5\u987B\u662F\u975E\u7A7A\u7684\u54CD\u5E94\u4F53\u70B9\u8DEF\u5F84`, `${path}.dataPath`);
|
|
8147
|
+
}
|
|
8148
|
+
source.dataPath = value.trim();
|
|
8139
8149
|
} else {
|
|
8140
|
-
throw new SomaDataConfigError(`\u672A\u77E5\u7684\u6765\u6E90\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: api / params / into / require / failWhen / messagePath\uFF09`, `${path}.${key}`);
|
|
8150
|
+
throw new SomaDataConfigError(`\u672A\u77E5\u7684\u6765\u6E90\u5B57\u6BB5 "${key}"\uFF08\u652F\u6301: api / params / into / require / failWhen / messagePath / dataPath\uFF09`, `${path}.${key}`);
|
|
8141
8151
|
}
|
|
8142
8152
|
}
|
|
8143
8153
|
if (source.failWhen !== void 0 || source.messagePath !== void 0) {
|
|
@@ -25,24 +25,97 @@ const ERROR_BODY_MAX_LENGTH = 500;
|
|
|
25
25
|
* 只留 statusText 等于把它整条丢掉。正文也可能是 HTML 错误页或空串,
|
|
26
26
|
* 因此 JSON 解析必须容错——解析失败只是"没有结构化字段",不该把请求变成另一种崩法。
|
|
27
27
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const CANDIDATE_KEYS = [
|
|
29
|
+
"error",
|
|
30
|
+
"message",
|
|
31
|
+
"msg",
|
|
32
|
+
"errMsg",
|
|
33
|
+
"err_msg",
|
|
34
|
+
"errmsg",
|
|
35
|
+
"reason",
|
|
36
|
+
"detail",
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
function pickMessageField(record: Record<string, unknown>): string | undefined {
|
|
40
|
+
for (const key of CANDIDATE_KEYS) {
|
|
41
|
+
const val = record[key];
|
|
42
|
+
if (typeof val === "string" && val.trim() !== "") {
|
|
43
|
+
return val.trim();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function extractHtmlTitle(text: string): string | undefined {
|
|
50
|
+
const match = text.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
|
|
51
|
+
if (!match) return undefined;
|
|
52
|
+
const plain = match[1].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
|
|
53
|
+
if (plain === "") return undefined;
|
|
54
|
+
return plain.length > 120 ? `${plain.slice(0, 120)}…` : plain;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function describeHttpErrorBody(body: string, statusText: string, status?: number): string {
|
|
58
|
+
const text = (body ?? "").trim();
|
|
59
|
+
const fallbackStatus = statusText.trim() || (status ? `请求失败(HTTP ${status})` : "请求失败");
|
|
60
|
+
|
|
61
|
+
if (text === "") return fallbackStatus;
|
|
31
62
|
|
|
32
|
-
|
|
63
|
+
// 3. 拦截 HTML 错误页源码外泄(忽略大小写和前导空白)
|
|
64
|
+
if (/^\s*<(?:!doctype\s+html|html)/i.test(text)) {
|
|
65
|
+
const title = extractHtmlTitle(text);
|
|
66
|
+
if (title) return title;
|
|
67
|
+
return statusText.trim() || (status ? `服务异常(HTTP ${status})` : "服务异常");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 1 & 2. 尝试 JSON 解析
|
|
33
71
|
try {
|
|
34
72
|
const parsed = JSON.parse(text);
|
|
35
|
-
if (parsed && typeof parsed ===
|
|
36
|
-
|
|
37
|
-
|
|
73
|
+
if (parsed && typeof parsed === "object") {
|
|
74
|
+
if (!Array.isArray(parsed)) {
|
|
75
|
+
const obj = parsed as Record<string, unknown>;
|
|
76
|
+
// 顶层候选字段
|
|
77
|
+
const top = pickMessageField(obj);
|
|
78
|
+
if (top) return truncate(top);
|
|
79
|
+
|
|
80
|
+
// 嵌套一层 error 对象
|
|
81
|
+
if (obj.error && typeof obj.error === "object" && !Array.isArray(obj.error)) {
|
|
82
|
+
const nested = pickMessageField(obj.error as Record<string, unknown>);
|
|
83
|
+
if (nested) return truncate(nested);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 嵌套一层 data 对象
|
|
87
|
+
if (obj.data && typeof obj.data === "object" && !Array.isArray(obj.data)) {
|
|
88
|
+
const nested = pickMessageField(obj.data as Record<string, unknown>);
|
|
89
|
+
if (nested) return truncate(nested);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 若存在短字符串 code(如 {"ret":502,"code":"BAD_GATEWAY"})可作为可读提示
|
|
93
|
+
if (typeof obj.code === "string" && obj.code.trim() !== "" && obj.code.trim().length <= 40) {
|
|
94
|
+
return truncate(obj.code.trim());
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 拦截裸 JSON 信封外泄:合法 JSON 对象/数组但无可读描述字段,绝不把原始 JSON 返回
|
|
99
|
+
return fallbackStatus;
|
|
38
100
|
}
|
|
39
101
|
} catch {
|
|
40
|
-
// 非 JSON
|
|
102
|
+
// 非 JSON:若以 < 开头(如未带完整 html 根的网页片段),防标签源码外泄
|
|
103
|
+
if (text.startsWith("<")) {
|
|
104
|
+
const title = extractHtmlTitle(text);
|
|
105
|
+
if (title) return title;
|
|
106
|
+
return statusText.trim() || (status ? `服务异常(HTTP ${status})` : "服务异常");
|
|
107
|
+
}
|
|
108
|
+
// 普通纯文本正文
|
|
109
|
+
return truncate(text);
|
|
41
110
|
}
|
|
42
111
|
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
112
|
+
return fallbackStatus;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function truncate(msg: string): string {
|
|
116
|
+
return msg.length > ERROR_BODY_MAX_LENGTH
|
|
117
|
+
? `${msg.slice(0, ERROR_BODY_MAX_LENGTH)}…`
|
|
118
|
+
: msg;
|
|
46
119
|
}
|
|
47
120
|
|
|
48
121
|
/**
|
|
@@ -149,7 +222,7 @@ export class SomaHttpClient {
|
|
|
149
222
|
const errorBody = typeof res.text === 'function'
|
|
150
223
|
? await res.text().catch(() => '')
|
|
151
224
|
: '';
|
|
152
|
-
throw new Error(`HTTP ${res.status}: ${describeHttpErrorBody(errorBody, res.statusText)}`);
|
|
225
|
+
throw new Error(`HTTP ${res.status}: ${describeHttpErrorBody(errorBody, res.statusText, res.status)}`);
|
|
153
226
|
}
|
|
154
227
|
|
|
155
228
|
return (await res.json()) as T;
|
|
@@ -1051,14 +1051,25 @@ export class SomaDataObjectResolver {
|
|
|
1051
1051
|
});
|
|
1052
1052
|
}
|
|
1053
1053
|
|
|
1054
|
+
private pickDotted(root: unknown, path: string): unknown {
|
|
1055
|
+
let current: unknown = root;
|
|
1056
|
+
for (const segment of path.split('.')) {
|
|
1057
|
+
if (segment === '') continue;
|
|
1058
|
+
if (current === null || typeof current !== 'object') return undefined;
|
|
1059
|
+
current = (current as Record<string, unknown>)[segment];
|
|
1060
|
+
}
|
|
1061
|
+
return current;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1054
1064
|
/** 聚合来源结果:into 写入子键;缺省先解开宿主信封,再浅合并进根(数组整体替换) */
|
|
1055
1065
|
mergeSource(current: unknown, source: SomaDataSourceConfig, data: unknown): unknown {
|
|
1056
|
-
const payload = source.into ? data : unwrapHostPayload(data);
|
|
1057
1066
|
if (source.into) {
|
|
1058
1067
|
const target = isPlainObject(current) ? current : {};
|
|
1059
1068
|
target[source.into] = data;
|
|
1060
1069
|
return target;
|
|
1061
1070
|
}
|
|
1071
|
+
const rawData = source.dataPath ? this.pickDotted(data, source.dataPath) : data;
|
|
1072
|
+
const payload = unwrapHostPayload(rawData);
|
|
1062
1073
|
if (isPlainObject(payload)) {
|
|
1063
1074
|
if (isPlainObject(current)) {
|
|
1064
1075
|
Object.assign(current, payload);
|
|
@@ -46,7 +46,7 @@ export interface SomaEventEngineOptions<TContext extends Record<string, unknown>
|
|
|
46
46
|
container: HTMLElement;
|
|
47
47
|
adapter: IContainerAdapter;
|
|
48
48
|
/**
|
|
49
|
-
* 分级确认执行口(R-23
|
|
49
|
+
* 分级确认执行口(R-23):注入时全级别(plain / consent / typed)交给它(通知服务 -> 渲染端口);未注入时安全回退 `adapter.confirm(spec.text)`。
|
|
50
50
|
* 返回 false = 用户取消。
|
|
51
51
|
*/
|
|
52
52
|
confirmGraded?: (spec: SomaConfirmSpec) => boolean | Promise<boolean>;
|
|
@@ -689,9 +689,9 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
|
|
|
689
689
|
return undefined;
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
-
/**
|
|
692
|
+
/** 分级确认的唯一出口:注入了执行口 -> 执行口(plain / consent / typed 全级别);否则安全回退 adapter.confirm(spec.text) */
|
|
693
693
|
private askConfirm(spec: SomaConfirmSpec): boolean | Promise<boolean> {
|
|
694
|
-
if (
|
|
694
|
+
if (this.confirmGraded) return this.confirmGraded(spec);
|
|
695
695
|
return this.adapter.confirm(spec.text);
|
|
696
696
|
}
|
|
697
697
|
|
|
@@ -43,10 +43,15 @@ import type { SomaIdentityProvider } from '../infra/identity/identity-port';
|
|
|
43
43
|
import { getBrowserUrlPath, readQueryParam } from '../infra/router/router-path';
|
|
44
44
|
import { parseDataYaml } from '../parser/data-config-parser';
|
|
45
45
|
import { createDataWriteActions } from '../data/data-write-actions';
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
SomaDataObjectResolver,
|
|
48
|
+
createSomaDataPort,
|
|
49
|
+
createDataPortHostState,
|
|
50
|
+
type SomaDataPortHostState,
|
|
51
|
+
} from '../data/data-object-resolver';
|
|
47
52
|
import { attachDataSubscriptions, type SomaDataSubscriptionHandle } from '../data/data-subscriptions';
|
|
48
53
|
import { attachDataPolling, type SomaDataPollingHandle } from '../data/data-polling';
|
|
49
|
-
import {
|
|
54
|
+
import type { SomaWriteOutcomeStore } from '../data/write-outcome-store';
|
|
50
55
|
import type { SomaDataPort } from '../../shared/types/data-config.types';
|
|
51
56
|
import type { SomaDataConfig, SomaDataDicts } from '../../shared/types/data-config.types';
|
|
52
57
|
import type { WatchCallback, WatcherOptions } from '../../shared/types/watcher.types';
|
|
@@ -684,8 +689,11 @@ export class SomaBootstrap {
|
|
|
684
689
|
private dataResolver: SomaDataObjectResolver | null = null;
|
|
685
690
|
private dataLoadEpoch = 0;
|
|
686
691
|
private dataOwnerEpoch = 0;
|
|
687
|
-
/**
|
|
688
|
-
private readonly
|
|
692
|
+
/** 数据端口宿主状态(单一真源):持有写入结果存储与写入事件执行口,端口重建同寿 */
|
|
693
|
+
private readonly dataPortHostState: SomaDataPortHostState = createDataPortHostState();
|
|
694
|
+
private get writeOutcomeStore(): SomaWriteOutcomeStore {
|
|
695
|
+
return this.dataPortHostState.writeOutcomes();
|
|
696
|
+
}
|
|
689
697
|
/** 快捷键注册中心(C-r18):唯一一份,`services.shortcuts` 直通 */
|
|
690
698
|
private shortcutsInstance!: SomaShortcutRegistry;
|
|
691
699
|
private componentStyleNonce?: string | null;
|
|
@@ -1930,38 +1938,27 @@ export class SomaBootstrap {
|
|
|
1930
1938
|
*/
|
|
1931
1939
|
private createStableDataPort(): SomaDataPort {
|
|
1932
1940
|
const owner = this.dataOwnerEpoch;
|
|
1933
|
-
const current = (): SomaDataObjectResolver | null => owner === this.dataOwnerEpoch ? this.dataResolver : null;
|
|
1934
|
-
const
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
submit: async (name: string, model: Record<string, unknown>, mode: 'create' | 'update', options?: Parameters<SomaDataObjectResolver['submit']>[3]) => {
|
|
1943
|
-
const resolver = current();
|
|
1944
|
-
if (!resolver) return notReady(`提交 "${name}"`);
|
|
1945
|
-
const result = await resolver.submit(name, model, mode, options);
|
|
1946
|
-
this.dataPolling?.arm(); // 写入后的重取可能带来新的进行中记录
|
|
1941
|
+
const current = (): SomaDataObjectResolver | null => (owner === this.dataOwnerEpoch ? this.dataResolver : null);
|
|
1942
|
+
const base = createSomaDataPort(current, this.dataPortHostState);
|
|
1943
|
+
return {
|
|
1944
|
+
...base,
|
|
1945
|
+
submit: async (name, model, mode, options) => {
|
|
1946
|
+
const result = await base.submit(name, model, mode, options);
|
|
1947
|
+
if (current()) {
|
|
1948
|
+
this.dataPolling?.arm(); // 写入后的重取可能带来新的进行中记录
|
|
1949
|
+
}
|
|
1947
1950
|
return result;
|
|
1948
1951
|
},
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
+
reload: async (names) => {
|
|
1953
|
+
await base.reload(names);
|
|
1954
|
+
this.dataPolling?.arm();
|
|
1952
1955
|
},
|
|
1953
|
-
|
|
1954
|
-
|
|
1956
|
+
dispatch: async (name, payload) => {
|
|
1957
|
+
if (owner !== this.dataOwnerEpoch) return;
|
|
1958
|
+
await base.dispatch(name, payload);
|
|
1955
1959
|
this.dataPolling?.arm();
|
|
1956
1960
|
},
|
|
1957
|
-
validate: (name: string, model: Record<string, unknown>, trigger?: Parameters<SomaDataObjectResolver['validate']>[2]) =>
|
|
1958
|
-
current()?.validate(name, model, trigger) ?? {},
|
|
1959
|
-
writeOutcome: (scope: string) => this.writeOutcomeStore.get(scope),
|
|
1960
|
-
onWriteOutcome: (listener: (scope: string) => void) => this.writeOutcomeStore.subscribe(listener),
|
|
1961
|
-
clearWriteOptimistic: (scope: string, key?: string) => this.writeOutcomeStore.clearOptimistic(scope, key),
|
|
1962
|
-
clearOutcome: (scope: string) => this.writeOutcomeStore.clear(scope),
|
|
1963
1961
|
};
|
|
1964
|
-
return port as unknown as SomaDataPort;
|
|
1965
1962
|
}
|
|
1966
1963
|
|
|
1967
1964
|
/** 推送失效 → 刷新:对象 reload(依赖它的下游随 DAG 一起重取) */
|
|
@@ -2207,6 +2204,7 @@ export class SomaBootstrap {
|
|
|
2207
2204
|
if (!this.container || !this.domainInstance) return;
|
|
2208
2205
|
|
|
2209
2206
|
this.stopDeclarativeTimers();
|
|
2207
|
+
this.dataPortHostState.setActionDispatcher(undefined);
|
|
2210
2208
|
this.eventEngine?.destroy();
|
|
2211
2209
|
this.renderEngine?.destroy();
|
|
2212
2210
|
this.styleBinder?.destroy();
|
|
@@ -2247,6 +2245,7 @@ export class SomaBootstrap {
|
|
|
2247
2245
|
const writeEngine = this.eventEngine;
|
|
2248
2246
|
const builtinActions = createDataWriteActions({ resolver: () => this.dataResolver, store: this.writeOutcomeStore });
|
|
2249
2247
|
writeEngine.setBuiltinActions(builtinActions);
|
|
2248
|
+
this.dataPortHostState.setActionDispatcher((name, payload) => writeEngine.dispatchAction(name, payload));
|
|
2250
2249
|
this.eventEngine.setScopeHandler(this.createScopeEventHandler());
|
|
2251
2250
|
this.eventEngine.setRoleGate((roles) => this.domainInstance?._services?.permission?.hasAnyRole([...roles]) === true);
|
|
2252
2251
|
this.assertNamedActionsResolvable(parsed.eventConfig, this.domainInstance, builtinActions);
|
|
@@ -2416,6 +2415,7 @@ export class SomaBootstrap {
|
|
|
2416
2415
|
this.componentManager?.destroy();
|
|
2417
2416
|
this.componentManager = null;
|
|
2418
2417
|
this.proxy?.dispose();
|
|
2418
|
+
this.dataPortHostState.setActionDispatcher(undefined);
|
|
2419
2419
|
this.eventEngine?.destroy();
|
|
2420
2420
|
this.renderEngine?.destroy();
|
|
2421
2421
|
this.styleBinder?.destroy();
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
type SomaDomainLoaderModule,
|
|
10
10
|
type SomaDomainModule,
|
|
11
11
|
} from './soma-domain-loaders';
|
|
12
|
+
import { isOptionalEntryAbsent, unwrapLoaderError } from './resolve-host-bootstrap';
|
|
13
|
+
|
|
14
|
+
const HOST_DOMAIN_LOADERS_MODULE = '@soma-host/bootstrap/soma-domain-loaders';
|
|
12
15
|
|
|
13
16
|
export type SomaDomainConstructor = new () => SomaPageRoot;
|
|
14
17
|
|
|
@@ -44,16 +47,39 @@ const domainModulePromises = new Map<string, Promise<SomaDomainModule>>();
|
|
|
44
47
|
|
|
45
48
|
export async function loadHostDomainClass(
|
|
46
49
|
context: SomaDomainLoadContext,
|
|
47
|
-
options: {
|
|
50
|
+
options: {
|
|
51
|
+
allowLocaleOnlyFallback?: boolean;
|
|
52
|
+
loadFallbackModule?: (base: string) => Promise<SomaDomainModule>;
|
|
53
|
+
} = {},
|
|
48
54
|
): Promise<SomaDomainConstructor> {
|
|
49
55
|
let registryFailure: unknown;
|
|
50
56
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
let registry: SomaDomainLoaderModule | null = null;
|
|
58
|
+
try {
|
|
59
|
+
registry = await import(
|
|
60
|
+
/* webpackChunkName: "soma-host-domain-loaders" */
|
|
61
|
+
'@soma-host/bootstrap/soma-domain-loaders'
|
|
62
|
+
) as SomaDomainLoaderModule;
|
|
63
|
+
} catch (rawErr) {
|
|
64
|
+
const err = unwrapLoaderError(rawErr);
|
|
65
|
+
if (isOptionalEntryAbsent(err, HOST_DOMAIN_LOADERS_MODULE)) {
|
|
66
|
+
registry = null;
|
|
67
|
+
} else {
|
|
68
|
+
console.error('[soma-core][引擎] 加载 soma-domain-loaders 失败:', err);
|
|
69
|
+
if (context.sourcePackage) {
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
registryFailure = err;
|
|
73
|
+
registry = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (registry) {
|
|
78
|
+
const module = await loadSomaDomainModuleFromRegistry(registry, context);
|
|
79
|
+
if (module) {
|
|
80
|
+
const label = (context.sourcePackage ?? 'host') + ':' + context.base + 'Class';
|
|
81
|
+
return resolveSomaDomainConstructor(module, label);
|
|
82
|
+
}
|
|
57
83
|
}
|
|
58
84
|
} catch (error) {
|
|
59
85
|
registryFailure = error;
|
|
@@ -69,27 +95,55 @@ export async function loadHostDomainClass(
|
|
|
69
95
|
);
|
|
70
96
|
}
|
|
71
97
|
|
|
98
|
+
const entrySpecifier = `@soma-host/domain/ui/${context.base}Class.ts`;
|
|
99
|
+
let module: SomaDomainModule;
|
|
72
100
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
if (options.loadFallbackModule) {
|
|
102
|
+
module = await options.loadFallbackModule(context.base);
|
|
103
|
+
} else {
|
|
104
|
+
let promise = domainModulePromises.get(context.base);
|
|
105
|
+
if (!promise) {
|
|
106
|
+
promise = import(
|
|
107
|
+
/* webpackInclude: /\/domain\/ui\/.*Class\.ts$/ */
|
|
108
|
+
`@soma-host/domain/ui/${context.base}Class.ts`
|
|
109
|
+
) as Promise<SomaDomainModule>;
|
|
110
|
+
domainModulePromises.set(context.base, promise);
|
|
111
|
+
}
|
|
112
|
+
module = await promise;
|
|
80
113
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} catch (error) {
|
|
114
|
+
} catch (rawImportError) {
|
|
115
|
+
const importError = unwrapLoaderError(rawImportError);
|
|
84
116
|
domainModulePromises.delete(context.base);
|
|
117
|
+
const isAbsent = isOptionalEntryAbsent(importError, entrySpecifier);
|
|
85
118
|
if (options.allowLocaleOnlyFallback !== false) {
|
|
119
|
+
if (!isAbsent) {
|
|
120
|
+
console.error(`[soma-core][引擎] 加载页面领域类 ${context.base}Class 失败,已降级为空页面根:`, importError);
|
|
121
|
+
}
|
|
86
122
|
return SomaLocaleOnlyPageRoot;
|
|
87
123
|
}
|
|
88
|
-
const detail =
|
|
89
|
-
?
|
|
124
|
+
const detail = importError instanceof Error
|
|
125
|
+
? importError.message
|
|
90
126
|
: registryFailure instanceof Error
|
|
91
127
|
? registryFailure.message
|
|
92
|
-
: String(
|
|
128
|
+
: String(importError);
|
|
129
|
+
throw new SomaDomainLoadError(
|
|
130
|
+
context,
|
|
131
|
+
'Domain class missing: ' + context.base + 'Class (' + detail + ')',
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
return resolveSomaDomainConstructor(module, context.base + 'Class');
|
|
137
|
+
} catch (rawResolveError) {
|
|
138
|
+
const resolveError = unwrapLoaderError(rawResolveError);
|
|
139
|
+
if (options.allowLocaleOnlyFallback !== false) {
|
|
140
|
+
console.error(`[soma-core][引擎] 加载页面领域类 ${context.base}Class 失败,已降级为空页面根:`, resolveError);
|
|
141
|
+
return SomaLocaleOnlyPageRoot;
|
|
142
|
+
}
|
|
143
|
+
if (resolveError instanceof SomaDomainLoadError) {
|
|
144
|
+
throw resolveError;
|
|
145
|
+
}
|
|
146
|
+
const detail = resolveError instanceof Error ? resolveError.message : String(resolveError);
|
|
93
147
|
throw new SomaDomainLoadError(
|
|
94
148
|
context,
|
|
95
149
|
'Domain class missing: ' + context.base + 'Class (' + detail + ')',
|
|
@@ -6,21 +6,111 @@ export type SomaBootstrapConfigurator = (ctx: {
|
|
|
6
6
|
getServices: () => SomaRuntimeServices | undefined;
|
|
7
7
|
}) => Partial<SomaBootstrapOptions>;
|
|
8
8
|
|
|
9
|
+
export const HOST_BOOTSTRAP_MODULE = '@soma-host/bootstrap/soma-bootstrap';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 解包测试运行器或装载器可能附加的包装错误(如 Error.cause)。
|
|
13
|
+
*/
|
|
14
|
+
export function unwrapLoaderError(error: unknown): unknown {
|
|
15
|
+
if (typeof error === 'object' && error !== null && 'cause' in error) {
|
|
16
|
+
const cause = (error as { cause?: unknown }).cause;
|
|
17
|
+
if (cause !== undefined && cause !== null) {
|
|
18
|
+
return cause;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return error;
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* 宿主钩子是可选的,缺模块是正常情形,静默跳过;模块在却在执行时抛错(`configureSomaBootstrap` 里的配方与
|
|
13
|
-
* foundation 取值域漂开、宿主自己的 bug……)不是正常情形,必须留痕——否则返回 `{}` 之后页面不带组件表、
|
|
14
|
-
* 不带主题,生成区域一片错误提示,而原因被抹得干干净净。
|
|
15
|
-
* 判据按各打包器的缺模块错误形态:CJS / webpack 的 `code: 'MODULE_NOT_FOUND'`、Node ESM 的 `ERR_MODULE_NOT_FOUND`,
|
|
16
|
-
* 以及消息里的 `Cannot find module` / `Module not found`。
|
|
17
|
-
* 局限:缺的若是宿主钩子**内部**依赖的模块,错误形态与「钩子本身缺失」相同,同样按缺模块静默。
|
|
25
|
+
* 这个异常是否具备「模块未找到」的特征(CJS/ESM/Webpack/Vite 等运行时形态)。
|
|
18
26
|
*/
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
export function hasModuleNotFoundSignature(error: unknown): boolean {
|
|
28
|
+
const unwrapped = unwrapLoaderError(error);
|
|
29
|
+
if (typeof unwrapped !== 'object' || unwrapped === null) return false;
|
|
30
|
+
const { code, message } = unwrapped as { code?: unknown; message?: unknown };
|
|
22
31
|
if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') return true;
|
|
23
|
-
return typeof message === 'string' && /Cannot find module|Module not found
|
|
32
|
+
return typeof message === 'string' && /Cannot find module|Module not found|Can't resolve|Unknown variable dynamic import/i.test(message);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 从缺模块错误信息中提取被引用的说明符(如 'X' 或 "X")。
|
|
37
|
+
*/
|
|
38
|
+
export function extractMissingModuleSpecifier(message: string): string | null {
|
|
39
|
+
if (!message || typeof message !== 'string') return null;
|
|
40
|
+
// 支持 Vite 等基于 import.meta.glob 抛出的 Unknown variable dynamic import: <path>
|
|
41
|
+
const viteMatch = message.match(/Unknown variable dynamic import:\s*(.+)$/i);
|
|
42
|
+
if (viteMatch && viteMatch[1]) {
|
|
43
|
+
return viteMatch[1].trim();
|
|
44
|
+
}
|
|
45
|
+
const primaryMatch = message.match(
|
|
46
|
+
/(?:Cannot find (?:module|package)|Can't resolve|Failed to resolve import)\s+['"]([^'"]+)['"]/i,
|
|
47
|
+
);
|
|
48
|
+
if (primaryMatch && primaryMatch[1]) {
|
|
49
|
+
return primaryMatch[1];
|
|
50
|
+
}
|
|
51
|
+
const quoteMatch = message.match(/['"]([^'"]+)['"]/);
|
|
52
|
+
if (quoteMatch && quoteMatch[1]) {
|
|
53
|
+
return quoteMatch[1];
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 校验 spec 是否指向 expected 入口本身。
|
|
60
|
+
*/
|
|
61
|
+
function matchesEntrySpecifier(spec: string, expected: string): boolean {
|
|
62
|
+
if (spec === expected) return true;
|
|
63
|
+
|
|
64
|
+
const normalizedExpected = expected.replace(/\.(?:ts|js|mjs|cjs)$/, '');
|
|
65
|
+
const normalizedSpec = spec.replace(/\.(?:ts|js|mjs|cjs)$/, '');
|
|
66
|
+
if (normalizedSpec === normalizedExpected) return true;
|
|
67
|
+
|
|
68
|
+
const expectedSegments = normalizedExpected.split('/');
|
|
69
|
+
const expectedBase = expectedSegments[expectedSegments.length - 1];
|
|
70
|
+
if (!expectedBase) return false;
|
|
71
|
+
|
|
72
|
+
// 检查 spec 是否以 expectedBase (加上可选扩展名) 作为路径结尾
|
|
73
|
+
const baseRegex = new RegExp(`(?:^|[\\\\/])${expectedBase}(?:\\.(?:ts|js|mjs|cjs))?$`);
|
|
74
|
+
if (!baseRegex.test(spec)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 若 expected 有父级路径(例如 bootstrap/soma-bootstrap 或 domain/ui/XClass),且 spec 中含有路径分隔符,则父级也必须匹配
|
|
79
|
+
if (expectedSegments.length > 1) {
|
|
80
|
+
const parentSegment = expectedSegments[expectedSegments.length - 2];
|
|
81
|
+
if (normalizedSpec.includes('/') || normalizedSpec.includes('\\')) {
|
|
82
|
+
const parentRegex = new RegExp(`(?:^|[\\\\/])${parentSegment}[\\\\/]${expectedBase}$`);
|
|
83
|
+
return parentRegex.test(normalizedSpec);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 精确判定异常是否为「目标可选入口模块自身不存在」。
|
|
92
|
+
* - 若不具备缺模块特征 -> false
|
|
93
|
+
* - 若从 message 中提取出具体说明符 spec -> 仅当 spec 指向 expectedSpecifiers 时返回 true,否则(子依赖缺失)返回 false
|
|
94
|
+
* - 若没有引号包裹的具体模块名(无引号泛化缺模块错误) -> 视为入口自身缺失返回 true
|
|
95
|
+
*/
|
|
96
|
+
export function isOptionalEntryAbsent(
|
|
97
|
+
error: unknown,
|
|
98
|
+
expectedSpecifiers: string | readonly string[],
|
|
99
|
+
): boolean {
|
|
100
|
+
const unwrapped = unwrapLoaderError(error);
|
|
101
|
+
if (!hasModuleNotFoundSignature(unwrapped)) return false;
|
|
102
|
+
|
|
103
|
+
const message = typeof (unwrapped as { message?: unknown })?.message === 'string'
|
|
104
|
+
? (unwrapped as { message: string }).message
|
|
105
|
+
: '';
|
|
106
|
+
|
|
107
|
+
const spec = extractMissingModuleSpecifier(message);
|
|
108
|
+
if (spec === null) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const list = Array.isArray(expectedSpecifiers) ? expectedSpecifiers : [expectedSpecifiers];
|
|
113
|
+
return list.some((expected) => matchesEntrySpecifier(spec, expected));
|
|
24
114
|
}
|
|
25
115
|
|
|
26
116
|
/** 分片加载失败的重试退避(由 Host 装配注入,值取自 soma-design 限值表 hostDefaults.chunkLoadBackoffMs;core 不留数字) */
|
|
@@ -45,20 +135,21 @@ export async function resolveHostBootstrapOptions(
|
|
|
45
135
|
if (bootstrapResolvingPromise) return bootstrapResolvingPromise;
|
|
46
136
|
bootstrapResolvingPromise = (async () => {
|
|
47
137
|
try {
|
|
138
|
+
let mod: { configureSomaBootstrap?: SomaBootstrapConfigurator } | null = null;
|
|
48
139
|
for (let attempt = 0; attempt < 5; attempt++) {
|
|
49
140
|
try {
|
|
50
|
-
|
|
141
|
+
mod = await import(
|
|
51
142
|
/* webpackChunkName: "soma-host-bootstrap" */
|
|
52
143
|
'@soma-host/bootstrap/soma-bootstrap'
|
|
53
144
|
) as { configureSomaBootstrap?: SomaBootstrapConfigurator };
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
145
|
+
break;
|
|
146
|
+
} catch (rawError) {
|
|
147
|
+
const error = unwrapLoaderError(rawError);
|
|
148
|
+
if (hasModuleNotFoundSignature(error)) {
|
|
149
|
+
if (isOptionalEntryAbsent(error, HOST_BOOTSTRAP_MODULE)) {
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
console.error('[soma-core][引擎] 宿主引导模块内部依赖缺失,宿主装配被整体跳过:', error);
|
|
62
153
|
return {};
|
|
63
154
|
}
|
|
64
155
|
const isChunkError = error instanceof Error
|
|
@@ -68,13 +159,24 @@ export async function resolveHostBootstrapOptions(
|
|
|
68
159
|
continue;
|
|
69
160
|
}
|
|
70
161
|
console.error('[soma-core][引擎] configureSomaBootstrap 抛出异常,宿主装配被整体跳过:', error);
|
|
71
|
-
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (mod && typeof mod.configureSomaBootstrap === 'function') {
|
|
167
|
+
try {
|
|
168
|
+
const opts = mod.configureSomaBootstrap({ getServices }) ?? {};
|
|
169
|
+
bootstrapOptionsCache = opts;
|
|
170
|
+
return opts;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error('[soma-core][引擎] configureSomaBootstrap 抛出异常,宿主装配被整体跳过:', error);
|
|
173
|
+
return {};
|
|
72
174
|
}
|
|
73
175
|
}
|
|
176
|
+
return {};
|
|
74
177
|
} finally {
|
|
75
178
|
bootstrapResolvingPromise = null;
|
|
76
179
|
}
|
|
77
|
-
return {};
|
|
78
180
|
})();
|
|
79
181
|
return bootstrapResolvingPromise;
|
|
80
182
|
}
|
|
@@ -4,7 +4,9 @@ export interface HttpRequestConfig {
|
|
|
4
4
|
timeout?: number;
|
|
5
5
|
signal?: AbortSignal;
|
|
6
6
|
/** 响应成功(2xx)后回调一次,带回 HTTP 状态码(C-r18:数据端口据此识别 202 受理);失败走抛错,不回调 */
|
|
7
|
-
onResponse?: (info: { readonly status: number }) => void;
|
|
7
|
+
onResponse?: (info: { readonly status: number }) => void;
|
|
8
|
+
/** 为 true 时非 2xx 响应只抛异常、不触发全局 onHttpError 提示,供上层自带语义错误处理的调用方按需抑制重复弹窗 */
|
|
9
|
+
silentErrorToast?: boolean;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export interface UploadOptions {
|