soma-core 2.2.8 → 2.2.10
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/full-manifest-builder.ts +1 -1
- package/core/build/compiler/host-config-sync.cjs +1 -1
- package/core/build/compiler/soma-manifest-webpack-plugin.js +2 -6
- package/core/build/compiler/soma-precompile.js +84 -4
- package/core/client/a11y/announcer.ts +2 -16
- package/core/client/base/SomaPageRootBase.ts +2 -2
- package/core/client/base/defineSomaView.ts +11 -2
- package/core/client/base/runtime-services.types.ts +57 -0
- package/core/client/data/role-gate.ts +2 -8
- package/core/client/engine/event-engine.ts +1 -0
- package/core/client/engines/diff/adapter-jsdiff.ts +27 -8
- package/core/client/engines/diff/code.ts +205 -0
- package/core/client/engines/diff/index.ts +107 -6
- package/core/client/engines/diff/items.ts +212 -0
- package/core/client/engines/diff/port.ts +215 -3
- package/core/client/engines/diff/prose.ts +443 -0
- package/core/client/engines/engine-adapters.ts +6 -0
- package/core/client/engines/highlight/adapter-lezer.ts +109 -0
- package/core/client/engines/highlight/index.ts +135 -0
- package/core/client/engines/highlight/port.ts +92 -0
- package/core/client/engines/markdown/adapter-markdown-it.ts +65 -0
- package/core/client/engines/markdown/blocks.ts +335 -0
- package/core/client/engines/markdown/index.ts +51 -0
- package/core/client/engines/markdown/port.ts +94 -0
- package/core/client/engines/markdown/vendor-modules.d.ts +6 -0
- package/core/client/engines/structured/adapter-js-yaml.ts +33 -0
- package/core/client/engines/structured/index.ts +139 -0
- package/core/client/engines/structured/port.ts +59 -0
- package/core/client/infra/http/SomaHttpService.ts +2 -4
- package/core/client/infra/notify/DefaultNotifyService.ts +2 -3
- package/core/client/infra/permission/SomaPermission.ts +1 -1
- package/core/client/render-ports/notify-renderer.ts +2 -46
- package/core/client/runtime/SomaRuntimeServices.ts +16 -45
- package/core/server/host/app-config-composer.ts +6 -52
- package/core/server/host/host-config-paths.cjs +2 -100
- package/core/server/host/precompiled-manifest.ts +69 -0
- package/core/server/host/source-packages.cjs +3 -0
- package/core/server/infra/host-config-paths.cjs +100 -0
- package/core/server/page-assets.ts +2 -70
- package/core/server/runtime-space/bindings.ts +33 -4
- package/core/server/runtime-space/store.ts +16 -1
- package/core/shared/app-config-merge.ts +59 -0
- package/core/shared/registry-generated/limits.ts +84 -4
- package/core/shared/types/announcer.types.ts +18 -0
- package/core/shared/types/notify.types.ts +26 -0
- package/core/shared/types/role-gate.types.ts +11 -0
- package/dist/browser/runtime-bundle.manifest.json +51 -7
- package/dist/browser/soma-runtime.js +120952 -104762
- package/dist/core/index.cjs +113613 -97412
- package/dist/host-native/aot-builder.cjs +582 -371
- package/dist/host-native/native-server.cjs +203 -72
- package/dist/lsp/component-tree.cjs +84 -4
- package/dist/types/build/compiler/full-manifest-builder.d.ts +1 -1
- package/dist/types/client/a11y/announcer.d.ts +2 -14
- package/dist/types/client/base/SomaPageRootBase.d.ts +2 -2
- package/dist/types/client/base/runtime-services.types.d.ts +50 -0
- package/dist/types/client/data/role-gate.d.ts +2 -8
- package/dist/types/client/engines/diff/code.d.ts +27 -0
- package/dist/types/client/engines/diff/index.d.ts +2 -1
- package/dist/types/client/engines/diff/items.d.ts +24 -0
- package/dist/types/client/engines/diff/port.d.ts +201 -2
- package/dist/types/client/engines/diff/prose.d.ts +80 -0
- package/dist/types/client/engines/engine-adapters.d.ts +6 -0
- package/dist/types/client/engines/highlight/adapter-lezer.d.ts +6 -0
- package/dist/types/client/engines/highlight/index.d.ts +15 -0
- package/dist/types/client/engines/highlight/port.d.ts +64 -0
- package/dist/types/client/engines/markdown/adapter-markdown-it.d.ts +6 -0
- package/dist/types/client/engines/markdown/blocks.d.ts +29 -0
- package/dist/types/client/engines/markdown/index.d.ts +9 -0
- package/dist/types/client/engines/markdown/port.d.ts +166 -0
- package/dist/types/client/engines/structured/adapter-js-yaml.d.ts +6 -0
- package/dist/types/client/engines/structured/index.d.ts +29 -0
- package/dist/types/client/engines/structured/port.d.ts +45 -0
- package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
- package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +2 -3
- package/dist/types/client/infra/permission/SomaPermission.d.ts +1 -1
- package/dist/types/client/render-ports/notify-renderer.d.ts +1 -56
- package/dist/types/client/runtime/SomaRuntimeServices.d.ts +9 -44
- package/dist/types/server/host/app-config-composer.d.ts +2 -3
- package/dist/types/server/host/host-config-paths.d.cts +2 -7
- package/dist/types/server/host/precompiled-manifest.d.ts +5 -0
- package/dist/types/server/host/source-packages.d.cts +5 -0
- package/dist/types/server/infra/host-config-paths.d.cts +7 -0
- package/dist/types/server/page-assets.d.ts +2 -5
- package/dist/types/server/runtime-space/store.d.ts +4 -0
- package/dist/types/shared/app-config-merge.d.ts +3 -0
- package/dist/types/shared/registry-generated/limits.d.ts +82 -4
- package/dist/types/shared/types/announcer.types.d.ts +14 -0
- package/dist/types/shared/types/notify.types.d.ts +36 -0
- package/dist/types/shared/types/role-gate.types.d.ts +8 -0
- package/host-native/src/aot-builder.ts +159 -96
- package/host-native/src/dev-chunk-gc.ts +104 -0
- package/host-native/src/host-prepare.ts +1 -1
- package/host-native/src/manifest-http.ts +1 -1
- package/host-native/src/page-http.ts +2 -67
- package/host-native/src/page-payload-cache.ts +68 -0
- package/host-native/src/public-packages.cjs +147 -50
- package/package.json +16 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Markdown 解析端口:`createMarkdownPort(adapter?, options?)`;缺省 markdown-it 适配器(动态加载)。
|
|
2
|
+
// 端口在适配器之上做:输入校验、上限(design `limits.json#contentEngines.markdown`)、令牌 → 块树(blocks.ts)与降级。
|
|
3
|
+
// 不新增 soma-core 的 exports 子路径:kit 与 soma-ai 经 `services.engines.markdown` 取用。
|
|
4
|
+
export type {
|
|
5
|
+
MdAlign, MdBlock, MdFailure, MdInline, MdListItem, MdMeta, MdParseOptions, MdResult, MdSrc, MdToken, SomaMarkdownAdapter, SomaMarkdownPort,
|
|
6
|
+
} from './port';
|
|
7
|
+
export { assertMarkdownAdapter } from './port';
|
|
8
|
+
export { buildMarkdown, inlineText, mdSlug, plainOf, safeMdHref, safeMdImage, softBreakJoiner } from './blocks';
|
|
9
|
+
|
|
10
|
+
import { SomaEngineError } from '../../../shared/engines/engine-error';
|
|
11
|
+
import { SOMA_PIPELINE_LIMITS } from '../../../shared/registry-generated/limits';
|
|
12
|
+
import type { EngineLoadTelemetry } from '../load';
|
|
13
|
+
import { createMarkdownItAdapter } from './adapter-markdown-it';
|
|
14
|
+
import { buildMarkdown } from './blocks';
|
|
15
|
+
import { assertMarkdownAdapter, type MdParseOptions, type MdResult, type SomaMarkdownAdapter, type SomaMarkdownPort } from './port';
|
|
16
|
+
|
|
17
|
+
export interface MarkdownPortOptions { readonly telemetry?: EngineLoadTelemetry }
|
|
18
|
+
|
|
19
|
+
const LIMITS = SOMA_PIPELINE_LIMITS.contentEngines.markdown;
|
|
20
|
+
|
|
21
|
+
const capOr = (v: unknown, ceiling: number): number => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.min(v, ceiling) : ceiling);
|
|
22
|
+
const now = (): number => (typeof performance !== 'undefined' && typeof performance.now === 'function' ? performance.now() : Date.now());
|
|
23
|
+
|
|
24
|
+
export function createMarkdownPort(adapter?: SomaMarkdownAdapter, options: MarkdownPortOptions = {}): SomaMarkdownPort {
|
|
25
|
+
const impl = adapter ?? createMarkdownItAdapter({ telemetry: options.telemetry });
|
|
26
|
+
assertMarkdownAdapter(impl);
|
|
27
|
+
return {
|
|
28
|
+
async parse(source: string, parseOptions?: MdParseOptions): Promise<MdResult> {
|
|
29
|
+
if (typeof source !== 'string') throw new SomaEngineError('CORE-ENGINE-ADAPTER', 'markdown', 'Markdown 原文必须是字符串');
|
|
30
|
+
const maxChars = capOr(parseOptions?.maxChars, LIMITS.maxChars);
|
|
31
|
+
const maxBlocks = capOr(parseOptions?.maxBlocks, LIMITS.maxBlocks);
|
|
32
|
+
if (source.length > maxChars) return { ok: false, reason: 'too-long', plainText: source.slice(0, maxChars) };
|
|
33
|
+
const started = now();
|
|
34
|
+
let tokens;
|
|
35
|
+
try {
|
|
36
|
+
tokens = await impl.tokenize(source, { footnotes: parseOptions?.footnotes !== false });
|
|
37
|
+
} catch (e) {
|
|
38
|
+
const load = e instanceof SomaEngineError && e.code === 'CORE-ENGINE-LOAD';
|
|
39
|
+
return { ok: false, reason: load ? 'engine-load-failed' : 'parse-error', plainText: source };
|
|
40
|
+
}
|
|
41
|
+
let built;
|
|
42
|
+
try {
|
|
43
|
+
built = buildMarkdown(tokens, source, { maxBlocks, summaryChars: LIMITS.summaryChars });
|
|
44
|
+
} catch {
|
|
45
|
+
return { ok: false, reason: 'parse-error', plainText: source };
|
|
46
|
+
}
|
|
47
|
+
options.telemetry?.record('engine.markdown.parse', now() - started);
|
|
48
|
+
return { ok: true, blocks: built.blocks, meta: built.meta };
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Markdown 解析端口(内容展示批次 ④;端口标准形式见 docs/03 soma-core 类设计 §4「引擎端口的标准形式」)。
|
|
2
|
+
// 缺省适配器 markdown-it 15 + markdown-it-cjk-friendly(+ markdown-it-footnote),动态 import。
|
|
3
|
+
// 输出:可序列化的块树(闭集),不出 HTML、不带样式;组件按节点类型 createElement / textContent 出 DOM,不用 innerHTML。
|
|
4
|
+
// 端口在令牌之上自己做:令牌 → 块树、原始 HTML 按文字保留并计数、URL 白名单、任务列表、CJK 软换行、标题 id(`md-` 前缀、去重)、上限。
|
|
5
|
+
// 失败语义:超长、解析失败、引擎加载失败 → 不抛,返回 `{ ok: false, reason, plainText }`(组件按纯文本降级)。
|
|
6
|
+
|
|
7
|
+
import { assertAdapterMethods } from '../../../shared/engines/engine-error';
|
|
8
|
+
|
|
9
|
+
export type MdAlign = 'left' | 'center' | 'right' | null;
|
|
10
|
+
/** 源码行区间 [起, 止),0 起;取不到为 [-1, -1] */
|
|
11
|
+
export type MdSrc = readonly [number, number];
|
|
12
|
+
|
|
13
|
+
export type MdInline =
|
|
14
|
+
| { readonly t: 'text'; readonly v: string }
|
|
15
|
+
| { readonly t: 'strong'; readonly c: readonly MdInline[] }
|
|
16
|
+
| { readonly t: 'em'; readonly c: readonly MdInline[] }
|
|
17
|
+
| { readonly t: 'del'; readonly c: readonly MdInline[] }
|
|
18
|
+
| { readonly t: 'code'; readonly v: string }
|
|
19
|
+
| { readonly t: 'br' }
|
|
20
|
+
/** href 已过白名单;不合格的链接降为它的文字 */
|
|
21
|
+
| { readonly t: 'link'; readonly href: string; readonly external: boolean; readonly title?: string; readonly c: readonly MdInline[] }
|
|
22
|
+
/** src 已过白名单;不合格的图片降为 alt 文字 */
|
|
23
|
+
| { readonly t: 'image'; readonly src: string; readonly alt: string; readonly title?: string }
|
|
24
|
+
| { readonly t: 'fnref'; readonly id: string; readonly n: number };
|
|
25
|
+
|
|
26
|
+
export interface MdListItem { readonly task: boolean | null; readonly blocks: readonly MdBlock[] }
|
|
27
|
+
|
|
28
|
+
export type MdBlock =
|
|
29
|
+
| { readonly t: 'heading'; readonly depth: 1 | 2 | 3 | 4 | 5 | 6; readonly id: string; readonly inline: readonly MdInline[]; readonly src: MdSrc }
|
|
30
|
+
/** tight = 紧凑列表里的段落(列表项内不留段距) */
|
|
31
|
+
| { readonly t: 'paragraph'; readonly inline: readonly MdInline[]; readonly tight: boolean; readonly src: MdSrc }
|
|
32
|
+
| { readonly t: 'list'; readonly ordered: boolean; readonly start?: number; readonly items: readonly MdListItem[]; readonly src: MdSrc }
|
|
33
|
+
| { readonly t: 'quote'; readonly blocks: readonly MdBlock[]; readonly src: MdSrc }
|
|
34
|
+
/** lang = 围栏信息串的第一个词(原样;语言归一交给代码高亮端口的 resolveLanguage);closed = 围栏已闭合(流式时末尾围栏可能未闭合) */
|
|
35
|
+
| { readonly t: 'code'; readonly lang: string; readonly text: string; readonly closed: boolean; readonly src: MdSrc }
|
|
36
|
+
| { readonly t: 'table'; readonly align: readonly MdAlign[]; readonly head: readonly (readonly MdInline[])[]; readonly rows: readonly (readonly (readonly MdInline[])[])[]; readonly src: MdSrc }
|
|
37
|
+
| { readonly t: 'hr'; readonly src: MdSrc }
|
|
38
|
+
/** 原始 HTML 块:不渲染,按原文文字显示 */
|
|
39
|
+
| { readonly t: 'html'; readonly text: string; readonly src: MdSrc }
|
|
40
|
+
| { readonly t: 'footnotes'; readonly items: readonly { readonly id: string; readonly n: number; readonly blocks: readonly MdBlock[] }[]; readonly src: MdSrc };
|
|
41
|
+
|
|
42
|
+
export interface MdMeta {
|
|
43
|
+
/** 标题大纲(id 一律 `md-` 前缀) */
|
|
44
|
+
readonly outline: readonly { readonly depth: 1 | 2 | 3 | 4 | 5 | 6; readonly text: string; readonly id: string }[];
|
|
45
|
+
/** 去标记全文(供摘要、搜索、差异) */
|
|
46
|
+
readonly plainText: string;
|
|
47
|
+
/** 前 N 字(N 取 design limits.json#contentEngines.markdown.summaryChars) */
|
|
48
|
+
readonly summary: string;
|
|
49
|
+
readonly counts: { readonly chars: number; readonly blocks: number; readonly images: number; readonly links: number; readonly codeBlocks: number; readonly tables: number };
|
|
50
|
+
/** 被按文字保留的原始 HTML 与被拒的不安全地址数(> 0 时组件给一条提示) */
|
|
51
|
+
readonly dropped: { readonly html: number; readonly unsafeUrls: number };
|
|
52
|
+
/** 块数超过上限被截断 */
|
|
53
|
+
readonly truncated: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type MdFailure = 'too-long' | 'parse-error' | 'engine-load-failed';
|
|
57
|
+
export type MdResult =
|
|
58
|
+
| { readonly ok: true; readonly blocks: readonly MdBlock[]; readonly meta: MdMeta }
|
|
59
|
+
| { readonly ok: false; readonly reason: MdFailure; readonly plainText: string };
|
|
60
|
+
|
|
61
|
+
export interface MdParseOptions {
|
|
62
|
+
/** 脚注语法(缺省开) */
|
|
63
|
+
readonly footnotes?: boolean;
|
|
64
|
+
/** 缺省取 design `limits.json#contentEngines.markdown`;调用方只能更小 */
|
|
65
|
+
readonly maxChars?: number;
|
|
66
|
+
readonly maxBlocks?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 适配器输出的令牌(markdown-it Token 的可序列化子集) */
|
|
70
|
+
export interface MdToken {
|
|
71
|
+
readonly type: string;
|
|
72
|
+
readonly tag: string;
|
|
73
|
+
readonly nesting: number;
|
|
74
|
+
readonly content: string;
|
|
75
|
+
readonly info: string;
|
|
76
|
+
readonly markup: string;
|
|
77
|
+
readonly map: readonly [number, number] | null;
|
|
78
|
+
readonly attrs: readonly (readonly [string, string])[] | null;
|
|
79
|
+
readonly hidden: boolean;
|
|
80
|
+
readonly meta: unknown;
|
|
81
|
+
readonly children: readonly MdToken[] | null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface SomaMarkdownAdapter {
|
|
85
|
+
tokenize(source: string, options: { readonly footnotes: boolean }): Promise<readonly MdToken[]>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SomaMarkdownPort {
|
|
89
|
+
parse(source: string, options?: MdParseOptions): Promise<MdResult>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function assertMarkdownAdapter(adapter: unknown): void {
|
|
93
|
+
assertAdapterMethods('markdown', adapter, ['tokenize']);
|
|
94
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// js-yaml 缺省适配器(内容展示批次 ③ 后半):结构化文本端口里唯一 import `js-yaml` 的文件,只用动态 import()。
|
|
2
|
+
// 模式 = CORE_SCHEMA(YAML 1.2 核心:null / bool / int / float / str / seq / map)+ 合并键 `<<`;
|
|
3
|
+
// 不认 !!js/*、时间戳(日期保持原文字符串,不转成带时区的时间)、二进制,产出值天然接近 JSON。
|
|
4
|
+
|
|
5
|
+
import { loadEngineModule, type EngineLoadTelemetry } from '../load';
|
|
6
|
+
import type { SomaStructuredAdapter } from './port';
|
|
7
|
+
|
|
8
|
+
interface JsYamlSchema { extend?(types: { implicit?: readonly unknown[] }): JsYamlSchema }
|
|
9
|
+
interface JsYamlModule {
|
|
10
|
+
load(text: string, options?: { schema?: unknown; json?: boolean }): unknown;
|
|
11
|
+
CORE_SCHEMA: JsYamlSchema;
|
|
12
|
+
types?: { merge?: unknown };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface JsYamlAdapterOptions { readonly telemetry?: EngineLoadTelemetry }
|
|
16
|
+
|
|
17
|
+
export function createJsYamlAdapter(options: JsYamlAdapterOptions = {}): SomaStructuredAdapter {
|
|
18
|
+
let schema: unknown = null;
|
|
19
|
+
const load = (): Promise<JsYamlModule> => loadEngineModule<JsYamlModule>('structured', async () => {
|
|
20
|
+
const mod = (await import('js-yaml')) as unknown as JsYamlModule & { default?: JsYamlModule };
|
|
21
|
+
return typeof mod.load === 'function' ? mod : (mod.default as JsYamlModule);
|
|
22
|
+
}, { telemetry: options.telemetry, key: 'yaml' });
|
|
23
|
+
return {
|
|
24
|
+
async parseYaml(text) {
|
|
25
|
+
const yaml = await load();
|
|
26
|
+
schema ??= yaml.types?.merge !== undefined && typeof yaml.CORE_SCHEMA.extend === 'function'
|
|
27
|
+
? yaml.CORE_SCHEMA.extend({ implicit: [yaml.types.merge] })
|
|
28
|
+
: yaml.CORE_SCHEMA;
|
|
29
|
+
// json: true —— 重复键取后者(与 JSON.parse 一致),不抛
|
|
30
|
+
return yaml.load(text, { schema, json: true });
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// 结构化文本端口:`createStructuredPort(adapter?, options?)`;缺省 js-yaml 适配器(动态加载)。
|
|
2
|
+
// 端口在适配器之上做:格式推断(确定性)、输入校验、上限(design `limits.json#contentEngines.structured`)、
|
|
3
|
+
// 值归一(YAML → 纯 JSON 值:别名展开计数、循环引用替换、非有限数 / 非字符串键转字符串)与降级。
|
|
4
|
+
// 不新增 soma-core 的 exports 子路径:kit 经 `services.engines.structured` 取用。
|
|
5
|
+
export type {
|
|
6
|
+
SomaStructuredAdapter, SomaStructuredPort, StructuredFailure, StructuredFormat, StructuredParseFail, StructuredParseOk,
|
|
7
|
+
StructuredParseOptions, StructuredParseResult,
|
|
8
|
+
} from './port';
|
|
9
|
+
export { assertStructuredAdapter } from './port';
|
|
10
|
+
|
|
11
|
+
import { SomaEngineError } from '../../../shared/engines/engine-error';
|
|
12
|
+
import { SOMA_PIPELINE_LIMITS } from '../../../shared/registry-generated/limits';
|
|
13
|
+
import type { EngineLoadTelemetry } from '../load';
|
|
14
|
+
import { createJsYamlAdapter } from './adapter-js-yaml';
|
|
15
|
+
import {
|
|
16
|
+
assertStructuredAdapter, type SomaStructuredAdapter, type SomaStructuredPort, type StructuredFormat, type StructuredParseOptions,
|
|
17
|
+
type StructuredParseResult,
|
|
18
|
+
} from './port';
|
|
19
|
+
|
|
20
|
+
export interface StructuredPortOptions { readonly telemetry?: EngineLoadTelemetry }
|
|
21
|
+
|
|
22
|
+
const LIMITS = SOMA_PIPELINE_LIMITS.contentEngines.structured;
|
|
23
|
+
|
|
24
|
+
const capOr = (v: unknown, ceiling: number): number => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.min(v, ceiling) : ceiling);
|
|
25
|
+
const now = (): number => (typeof performance !== 'undefined' && typeof performance.now === 'function' ? performance.now() : Date.now());
|
|
26
|
+
|
|
27
|
+
/** 循环引用的占位文字(数据里出现同样的字符串不受影响:它只在 cycles > 0 时有意义) */
|
|
28
|
+
export const STRUCTURED_CYCLE_MARK = '[循环引用]';
|
|
29
|
+
|
|
30
|
+
/** 确定性格式推断(纯函数) */
|
|
31
|
+
export function detectStructuredFormat(text: string, hint: { readonly format?: string; readonly filename?: string } = {}): StructuredFormat {
|
|
32
|
+
const f = typeof hint.format === 'string' ? hint.format.trim().toLowerCase() : '';
|
|
33
|
+
if (f === 'json') return 'json';
|
|
34
|
+
if (f === 'yaml' || f === 'yml') return 'yaml';
|
|
35
|
+
const file = typeof hint.filename === 'string' ? hint.filename.trim().toLowerCase() : '';
|
|
36
|
+
if (file.endsWith('.json')) return 'json';
|
|
37
|
+
if (file.endsWith('.yaml') || file.endsWith('.yml')) return 'yaml';
|
|
38
|
+
// 以 { / [ 开头按 JSON(解析失败时报 JSON 的行列,比静默按 YAML 流式写法解析更有用;YAML 流式文档请显式 format: yaml)
|
|
39
|
+
const t = typeof text === 'string' ? text.trimStart() : '';
|
|
40
|
+
return t.startsWith('{') || t.startsWith('[') ? 'json' : 'yaml';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** JSON.parse 的错误位置:新版 V8 给 (line L column C),旧版给 position N;都取不到返回空 */
|
|
44
|
+
export function jsonErrorPosition(text: string, message: string): { line?: number; column?: number } {
|
|
45
|
+
const lc = /line (\d+) column (\d+)/u.exec(message);
|
|
46
|
+
if (lc) return { line: Number(lc[1]), column: Number(lc[2]) };
|
|
47
|
+
const pos = /position (\d+)/u.exec(message);
|
|
48
|
+
if (!pos) return {};
|
|
49
|
+
const at = Math.min(Number(pos[1]), text.length);
|
|
50
|
+
const before = text.slice(0, at);
|
|
51
|
+
const line = before.split('\n').length;
|
|
52
|
+
return { line, column: at - before.lastIndexOf('\n') };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 原始值 → 纯 JSON 值(纯函数):节点超过 maxNodes 返回 null(调用方按 too-many-nodes 降级)。
|
|
57
|
+
* 只在祖先链上判循环(共享别名照常展开、计入节点数,防「十亿笑声」靠节点上限)。
|
|
58
|
+
*/
|
|
59
|
+
export function normalizeStructured(raw: unknown, maxNodes: number): { value: unknown; nodes: number; cycles: number } | null {
|
|
60
|
+
let nodes = 0;
|
|
61
|
+
let cycles = 0;
|
|
62
|
+
const path = new Set<object>();
|
|
63
|
+
const walk = (v: unknown): unknown => {
|
|
64
|
+
nodes += 1;
|
|
65
|
+
if (nodes > maxNodes) throw OVER;
|
|
66
|
+
if (v === null || typeof v === 'string' || typeof v === 'boolean') return v;
|
|
67
|
+
if (typeof v === 'number') return Number.isFinite(v) ? v : String(v);
|
|
68
|
+
if (typeof v === 'bigint') return v.toString();
|
|
69
|
+
if (typeof v !== 'object') return v === undefined ? null : String(v);
|
|
70
|
+
if (v instanceof Date) return Number.isNaN(v.getTime()) ? null : v.toISOString();
|
|
71
|
+
if (path.has(v)) { cycles += 1; return STRUCTURED_CYCLE_MARK; }
|
|
72
|
+
path.add(v);
|
|
73
|
+
try {
|
|
74
|
+
if (Array.isArray(v)) return v.map(walk);
|
|
75
|
+
const out: Record<string, unknown> = {};
|
|
76
|
+
const entries = v instanceof Map ? Array.from(v.entries()) : Object.entries(v as Record<string, unknown>);
|
|
77
|
+
for (const [k, x] of entries) out[typeof k === 'string' ? k : JSON.stringify(k) ?? String(k)] = walk(x);
|
|
78
|
+
return out;
|
|
79
|
+
} finally {
|
|
80
|
+
path.delete(v);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const value = walk(raw);
|
|
85
|
+
return { value, nodes, cycles };
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (e === OVER) return null;
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const OVER = Symbol('structured-over');
|
|
92
|
+
|
|
93
|
+
/** 「是结构」= 对象或数组(单个标量不当结构:纯文本也是合法 YAML) */
|
|
94
|
+
const isStructure = (v: unknown): boolean => v !== null && typeof v === 'object';
|
|
95
|
+
|
|
96
|
+
export function createStructuredPort(adapter?: SomaStructuredAdapter, options: StructuredPortOptions = {}): SomaStructuredPort {
|
|
97
|
+
const impl = adapter ?? createJsYamlAdapter({ telemetry: options.telemetry });
|
|
98
|
+
assertStructuredAdapter(impl);
|
|
99
|
+
return {
|
|
100
|
+
detect: (text, hint) => detectStructuredFormat(text, hint ?? {}),
|
|
101
|
+
async parse(text: string, format: StructuredFormat | 'auto' = 'auto', parseOptions?: StructuredParseOptions): Promise<StructuredParseResult> {
|
|
102
|
+
if (typeof text !== 'string') throw new SomaEngineError('CORE-ENGINE-ADAPTER', 'structured', '原文必须是字符串');
|
|
103
|
+
if (format !== 'auto' && format !== 'json' && format !== 'yaml') throw new SomaEngineError('CORE-ENGINE-ADAPTER', 'structured', `未知格式:${String(format)}`);
|
|
104
|
+
const fmt: StructuredFormat = format === 'auto' ? detectStructuredFormat(text) : format;
|
|
105
|
+
const maxChars = capOr(parseOptions?.maxChars, LIMITS.maxChars);
|
|
106
|
+
const maxNodes = capOr(parseOptions?.maxNodes, LIMITS.maxNodes);
|
|
107
|
+
if (text.length > maxChars) return { ok: false, format: fmt, reason: 'too-large' };
|
|
108
|
+
const started = now();
|
|
109
|
+
let raw: unknown;
|
|
110
|
+
if (fmt === 'json') {
|
|
111
|
+
try {
|
|
112
|
+
raw = JSON.parse(text);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
115
|
+
return { ok: false, format: fmt, reason: 'syntax', message, ...jsonErrorPosition(text, message) };
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
try {
|
|
119
|
+
raw = await impl.parseYaml(text);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
if (e instanceof SomaEngineError && e.code === 'CORE-ENGINE-LOAD') return { ok: false, format: fmt, reason: 'engine-load-failed' };
|
|
122
|
+
const mark = (e as { mark?: { line?: unknown; column?: unknown } } | null)?.mark;
|
|
123
|
+
const reason = (e as { reason?: unknown } | null)?.reason;
|
|
124
|
+
const message = typeof reason === 'string' ? reason : e instanceof Error ? e.message.split('\n', 1)[0]! : String(e);
|
|
125
|
+
return {
|
|
126
|
+
ok: false, format: fmt, reason: 'syntax', message,
|
|
127
|
+
...(typeof mark?.line === 'number' ? { line: mark.line + 1 } : {}),
|
|
128
|
+
...(typeof mark?.column === 'number' ? { column: mark.column + 1 } : {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
options.telemetry?.record('engine.structured.parse', now() - started);
|
|
133
|
+
if (!isStructure(raw)) return { ok: false, format: fmt, reason: 'not-structured' };
|
|
134
|
+
const norm = normalizeStructured(raw, maxNodes);
|
|
135
|
+
if (norm === null) return { ok: false, format: fmt, reason: 'too-many-nodes' };
|
|
136
|
+
return { ok: true, format: fmt, value: norm.value, nodes: norm.nodes, cycles: norm.cycles };
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// 结构化文本端口(内容展示批次 ③ 后半;端口标准形式见 docs/03 soma-core 类设计 §4「引擎端口的标准形式」)。
|
|
2
|
+
// 把 JSON / YAML 原文解析成「纯 JSON 值」(对象 / 数组 / 字符串 / 有限数 / 布尔 / null),给 kit 的结构化查看组件用。
|
|
3
|
+
// 缺省适配器 js-yaml(core 已有依赖,动态 import;CORE_SCHEMA:不产出日期、二进制、函数等 JSON 以外的类型)。JSON 用运行时 JSON.parse,不经适配器。
|
|
4
|
+
// 失败语义:语法错误、超长、节点过多(含 YAML 别名展开)、引擎加载失败、原文不是结构(YAML 解析成单个标量)→ 不抛,返回 `{ ok: false, reason, … }`。
|
|
5
|
+
|
|
6
|
+
import { assertAdapterMethods } from '../../../shared/engines/engine-error';
|
|
7
|
+
|
|
8
|
+
export type StructuredFormat = 'json' | 'yaml';
|
|
9
|
+
|
|
10
|
+
/** 解析失败的原因闭集 */
|
|
11
|
+
export type StructuredFailure = 'syntax' | 'too-large' | 'too-many-nodes' | 'not-structured' | 'engine-load-failed';
|
|
12
|
+
|
|
13
|
+
export interface StructuredParseOptions {
|
|
14
|
+
/** 缺省取 design `limits.json#contentEngines.structured`;调用方只能更小 */
|
|
15
|
+
readonly maxChars?: number;
|
|
16
|
+
readonly maxNodes?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface StructuredParseOk {
|
|
20
|
+
readonly ok: true;
|
|
21
|
+
readonly format: StructuredFormat;
|
|
22
|
+
/** 纯 JSON 值(可序列化;YAML 的共享别名已展开、循环引用替换成字符串 `[循环引用]` 并计入 `cycles`) */
|
|
23
|
+
readonly value: unknown;
|
|
24
|
+
/** 值里的节点总数(对象 / 数组 / 叶子各计 1) */
|
|
25
|
+
readonly nodes: number;
|
|
26
|
+
/** YAML 文档里被替换掉的循环引用数(JSON 恒为 0) */
|
|
27
|
+
readonly cycles: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface StructuredParseFail {
|
|
31
|
+
readonly ok: false;
|
|
32
|
+
readonly format: StructuredFormat;
|
|
33
|
+
readonly reason: StructuredFailure;
|
|
34
|
+
/** 语法错误的位置(1 起);取不到时缺省 */
|
|
35
|
+
readonly line?: number;
|
|
36
|
+
readonly column?: number;
|
|
37
|
+
/** 引擎给的原话(仅 syntax;不可信字符串,组件只能 textContent 写入) */
|
|
38
|
+
readonly message?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type StructuredParseResult = StructuredParseOk | StructuredParseFail;
|
|
42
|
+
|
|
43
|
+
/** 适配器只做 YAML 文本 → 原始值;语法错误抛带 `mark { line, column }`(0 起)的错误 */
|
|
44
|
+
export interface SomaStructuredAdapter {
|
|
45
|
+
parseYaml(text: string): Promise<unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface SomaStructuredPort {
|
|
49
|
+
/**
|
|
50
|
+
* 确定性的格式推断(同步、纯函数):显式 format 优先;文件名扩展名 .json / .yaml / .yml;
|
|
51
|
+
* 去掉开头空白后以 `{` / `[` 开头 → json(解析失败报 JSON 行列);否则 yaml(由 parse 判定它是不是结构)。
|
|
52
|
+
*/
|
|
53
|
+
detect(text: string, hint?: { readonly format?: string; readonly filename?: string }): StructuredFormat;
|
|
54
|
+
parse(text: string, format?: StructuredFormat | 'auto', options?: StructuredParseOptions): Promise<StructuredParseResult>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function assertStructuredAdapter(adapter: unknown): void {
|
|
58
|
+
assertAdapterMethods('structured', adapter, ['parseYaml']);
|
|
59
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// Use the
|
|
2
|
-
|
|
3
|
-
// internal alias here would leak into every Host's typecheck.
|
|
4
|
-
import { SomaHttpClient, SomaHttpClientConfig, describeHttpErrorBody } from 'soma-core/base';
|
|
1
|
+
// Use relative import within the foundation layer (CORE-L03) rather than package self-reference.
|
|
2
|
+
import { SomaHttpClient, describeHttpErrorBody, type SomaHttpClientConfig } from '../../base/SomaHttpClient';
|
|
5
3
|
import { SOMA_PIPELINE_HOST_HTTP_REQUEST_TIMEOUT_MS } from 'soma-foundation/values';
|
|
6
4
|
import { IHttpClient, HttpRequestConfig, UploadOptions } from './IHttpClient';
|
|
7
5
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Announcer } from '
|
|
2
|
-
import type { NotifyRenderer } from '../../render-ports/notify-renderer';
|
|
1
|
+
import type { Announcer } from '../../../shared/types/announcer.types';
|
|
3
2
|
import type { SomaConfirmSpec } from '../../../shared/types/event.types';
|
|
4
|
-
import type { INotifyService, NotifyOptions } from '../../../shared/types/notify.types';
|
|
3
|
+
import type { INotifyService, NotifyOptions, NotifyRenderer } from '../../../shared/types/notify.types';
|
|
5
4
|
import type { SomaChoiceConfirmOutcome, SomaChoiceConfirmSpec } from '../../../shared/types/choice-confirm.types';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -1,46 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { NotifyAction, NotifyCarrier } from '../../shared/types/notify.types';
|
|
4
|
-
import type { SomaChoiceConfirmOutcome, SomaChoiceConfirmSpec } from '../../shared/types/choice-confirm.types';
|
|
5
|
-
|
|
6
|
-
/** 交给渲染器的一条通知;`duration` 只透传调用方给的值,未给则不带字段,由渲染器决定停留 */
|
|
7
|
-
export interface NotifyEntry {
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly level: NotifyLevel;
|
|
10
|
-
readonly message: string;
|
|
11
|
-
readonly title?: string;
|
|
12
|
-
readonly duration?: number;
|
|
13
|
-
/** 呈现载体偏好;未给则渲染器按级别与动作自定 */
|
|
14
|
-
readonly carrier?: NotifyCarrier;
|
|
15
|
-
/** 附带动作;未给则无 */
|
|
16
|
-
readonly action?: NotifyAction;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 通知渲染端口(UI 体系注入,经 `SomaBootstrap` 选项 `renderPorts.notify`)。
|
|
21
|
-
* core 不带可见实现:停留、动效、位置、模态呈现全在渲染器里。
|
|
22
|
-
*/
|
|
23
|
-
export interface NotifyRenderer {
|
|
24
|
-
show(entry: NotifyEntry): { dismiss(): void };
|
|
25
|
-
/**
|
|
26
|
-
* 确认。`spec` 只在 typed / consent 级或 `tone: 'danger'` 时出现(plain 且无语气不带),`message` 恒等于 `spec.text`,不认识分级的渲染器照旧显示一句话。
|
|
27
|
-
* `spec.tone === 'danger'`(破坏性确认):渲染器应给确认钮警示呈现,并把初始焦点放在「取消」;typed / consent 的放行规则不变。
|
|
28
|
-
* 认识分级的渲染器必须用 `confirmSatisfied(spec, { typed, consented })` 决定确认钮此刻能不能点:
|
|
29
|
-
* typed 要键入 `phrase`、consent 要先勾选同意(`impact` 是勾选旁的影响说明);
|
|
30
|
-
* 键入框里输入法组字(`isImeProcessing`)期间的 Enter 是选词,不算确认;取消 / Esc / 点遮罩一律 resolve(false)。
|
|
31
|
-
*/
|
|
32
|
-
confirm(req: { message: string; title?: string; spec?: SomaConfirmSpec }): Promise<boolean>;
|
|
33
|
-
alert(req: { message: string; title?: string }): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* 选择型确认(C37 / C43,删除前转移):可选。实现了它,`services.notify.confirmChoice` 才存在(`DefaultNotifyService` 原样转发);
|
|
36
|
-
* 没实现,通知服务不暴露该成员,行删除确认管道按「宿主不支持选择型确认」处理。取消 / Esc / 点遮罩一律 `{ accepted: false }`;
|
|
37
|
-
* `required` 为真时没选不能确认;`value` 必须是 `candidates[].id` 之一。
|
|
38
|
-
*/
|
|
39
|
-
confirmChoice?(spec: SomaChoiceConfirmSpec): Promise<SomaChoiceConfirmOutcome>;
|
|
40
|
-
/**
|
|
41
|
-
* 读屏播报(`NOTIFY | announce`,S7):可选。渲染器自己持有 live region 宿主,
|
|
42
|
-
* 仅在通知服务没有接统一播报通道(`soma-core/a11y` 的页面级 Announcer)时才被调用;通道在场则由通道投递,不再走渲染器。
|
|
43
|
-
*/
|
|
44
|
-
announce?(req: { message: string; politeness: 'polite' | 'assertive' }): void;
|
|
45
|
-
dispose(): void;
|
|
46
|
-
}
|
|
1
|
+
// 通知渲染端口类型重导出(CORE-L01:真源已下沉至 shared/types/notify.types.ts,此处原样重导出保持兼容)。
|
|
2
|
+
export type { NotifyEntry, NotifyRenderer } from '../../shared/types/notify.types';
|
|
@@ -29,6 +29,12 @@ import { createDiffPort } from '../engines/diff';
|
|
|
29
29
|
import type { SomaDiffPort } from '../engines/diff';
|
|
30
30
|
import { createQrPort } from '../engines/qrcode';
|
|
31
31
|
import type { SomaQrPort } from '../engines/qrcode';
|
|
32
|
+
import { createHighlightPort } from '../engines/highlight';
|
|
33
|
+
import type { SomaHighlightPort } from '../engines/highlight';
|
|
34
|
+
import { createStructuredPort } from '../engines/structured';
|
|
35
|
+
import type { SomaStructuredPort } from '../engines/structured';
|
|
36
|
+
import { createMarkdownPort } from '../engines/markdown';
|
|
37
|
+
import type { SomaMarkdownPort } from '../engines/markdown';
|
|
32
38
|
import { SomaPermission } from '../infra/permission/SomaPermission';
|
|
33
39
|
import { SomaRouter } from '../infra/router/SomaRouter';
|
|
34
40
|
import { parseA11yAppConfig } from '../a11y/a11y-config';
|
|
@@ -41,15 +47,17 @@ import { SomaRealtimeService } from '../infra/realtime/SomaRealtimeService';
|
|
|
41
47
|
import type { IRealtimeService } from '../infra/realtime/IRealtimeService';
|
|
42
48
|
import type { SomaNavPort } from '../../shared/types/nav.types';
|
|
43
49
|
import { createNavHistory, type SomaNavHistory } from './nav-history';
|
|
44
|
-
import type {
|
|
50
|
+
import type { SomaRuntimeServicesShape, SomaUiService } from '../base/runtime-services.types';
|
|
45
51
|
import { createIdentityPort, type SomaIdentityPort, type SomaIdentityProvider } from '../infra/identity/identity-port';
|
|
46
52
|
import { createAppConfigPort, type SomaAppConfigPort } from '../infra/config/feature-flags';
|
|
47
53
|
import { createShortcutRegistry, shortcutsDesign } from './shortcuts';
|
|
48
54
|
import type { SomaShortcutRegistry } from '../../shared/types/write-runtime.types';
|
|
49
55
|
import { SOMA_PIPELINE_HOST_HTTP_REQUEST_TIMEOUT_MS } from 'soma-foundation/values';
|
|
50
56
|
|
|
57
|
+
export type { SomaRuntimeServicesShape, SomaUiService };
|
|
58
|
+
|
|
51
59
|
/** Runtime infrastructure injected into domain instances by bootstrap */
|
|
52
|
-
export interface SomaRuntimeServices extends
|
|
60
|
+
export interface SomaRuntimeServices extends SomaRuntimeServicesShape<SomaEnginePorts, SomaNavHistory> {
|
|
53
61
|
router: SomaRouter;
|
|
54
62
|
notify: DefaultNotifyService;
|
|
55
63
|
logger: ConsoleLogger;
|
|
@@ -63,51 +71,13 @@ export interface SomaRuntimeServices extends SomaRuntimeServicesBase {
|
|
|
63
71
|
permission: SomaPermission;
|
|
64
72
|
i18n: SomaLocaleCatalog;
|
|
65
73
|
realtime: IRealtimeService;
|
|
66
|
-
/**
|
|
67
|
-
* 界面中途提交:把此刻改过的页面状态立刻上屏,**不结束**当前事件事务。
|
|
68
|
-
*
|
|
69
|
-
* 存在的理由:一次事件 = 一次原子提交是刻意的设计(避免中间态闪烁、出错整体回滚),
|
|
70
|
-
* 代价是**长任务里的中途进展播不出去**——实测 AI 生成 P50 约 40 秒,期间 Domain
|
|
71
|
-
* 改多少次状态,界面一次都不动,连"生成中"都看不到。
|
|
72
|
-
*
|
|
73
|
-
* 它是**自愿**的:不调用,行为与过去逐字节一致;调用了,就等于声明
|
|
74
|
-
* "已上屏的这部分不再享有失败回滚"。这个取舍只能由业务自己做。
|
|
75
|
-
* 引擎未接线时(纯 Node 单测、无渲染宿主)为空操作,调用方不必判空。
|
|
76
|
-
*/
|
|
77
74
|
ui: SomaUiService;
|
|
78
|
-
/**
|
|
79
|
-
* 通用观测通道(06e AD-CORE-06):数据组件 / 层栈上报 `adaptive` / `overlays` 流。
|
|
80
|
-
* 未开观测时是空操作实现(`NOOP_OBSERVATION_CHANNEL`);开启时 bootstrap 换成真实采集器。
|
|
81
|
-
*/
|
|
82
75
|
observation: SomaObservationChannel;
|
|
83
|
-
/**
|
|
84
|
-
* 引擎端口表(core 引擎端口设计 §1.2):`SomaBootstrapOptions.engines` 给出的适配器在这里变成端口,
|
|
85
|
-
* 未给的槽位用各端口的缺省适配器。端口按需惰性构造(首次读取才建,缺省适配器首次使用才动态加载)。
|
|
86
|
-
* 组件须在契约 `services` 白名单里声明 `engines` 才可见。
|
|
87
|
-
*/
|
|
88
76
|
readonly engines: SomaEnginePorts;
|
|
89
|
-
/**
|
|
90
|
-
* 导航目录(E4,只读):服务端随页面下发的、按请求身份裁剪过的目录。外壳(顶栏、框架菜单)读它渲染。
|
|
91
|
-
* 由 bootstrap 在创建页面根时接上;单测替身可以不给,所以是可选成员。
|
|
92
|
-
*/
|
|
93
77
|
nav?: SomaNavPort;
|
|
94
|
-
/**
|
|
95
|
-
* 当前用户身份(K8,只读):值来自 Host 注入的 `identity` 函数,每次现读;查询里的 `$user.id` / `$user.team` 经它解析。
|
|
96
|
-
* 没注入时什么字段都不提供(引用 `$user.*` 的查询按无结果处理)。
|
|
97
|
-
*/
|
|
98
78
|
readonly identity: SomaIdentityPort;
|
|
99
|
-
/**
|
|
100
|
-
* 返回栈(C48,K53):`back(fallback, opts) / resolveBack / visit / settle / go / originOfCurrent / entries`。
|
|
101
|
-
* 栈由 bootstrap 持有唯一一份(跨页面根同一份),路由端口来自宿主注入的 `navHistory`,没注入退化为浏览器历史。
|
|
102
|
-
* 单测替身可不给。
|
|
103
|
-
*/
|
|
104
79
|
readonly navHistory?: SomaNavHistory;
|
|
105
|
-
/** 部署层只读端口(K30):页面 / 组件只读;`createDefaultRuntimeServices` 造的服务表一定带,单测替身可不给 */
|
|
106
80
|
readonly appConfig?: SomaAppConfigPort;
|
|
107
|
-
/**
|
|
108
|
-
* 应用级快捷键注册中心(C56 K81,`app.shortcuts`):`register / on / pushScope / handle / helpTable`;每个服务表一份。
|
|
109
|
-
* 序列键位的间隔取 design `shortcuts.sequenceTimeoutMs`;修饰键本平台映射由 `SomaBootstrapOptions.shortcutsModKey` 给。单测替身可不给。
|
|
110
|
-
*/
|
|
111
81
|
readonly shortcuts?: SomaShortcutRegistry;
|
|
112
82
|
}
|
|
113
83
|
|
|
@@ -120,6 +90,9 @@ export interface SomaEnginePorts {
|
|
|
120
90
|
readonly dnd: SomaDragPort;
|
|
121
91
|
readonly diff: SomaDiffPort;
|
|
122
92
|
readonly qrcode: SomaQrPort;
|
|
93
|
+
readonly highlight: SomaHighlightPort;
|
|
94
|
+
readonly structured: SomaStructuredPort;
|
|
95
|
+
readonly markdown: SomaMarkdownPort;
|
|
123
96
|
temporal(options: { readonly timeZone: string; readonly locale: string }): SomaTemporalPort;
|
|
124
97
|
}
|
|
125
98
|
|
|
@@ -142,15 +115,13 @@ export function createEnginePorts(
|
|
|
142
115
|
get dnd() { return lazy('dnd', () => createDragPort(adapters.dnd, opts)); },
|
|
143
116
|
get diff() { return lazy('diff', () => createDiffPort(adapters.diff, opts)); },
|
|
144
117
|
get qrcode() { return lazy('qrcode', () => createQrPort(adapters.qrcode, opts)); },
|
|
118
|
+
get highlight() { return lazy('highlight', () => createHighlightPort(adapters.highlight, opts)); },
|
|
119
|
+
get structured() { return lazy('structured', () => createStructuredPort(adapters.structured, opts)); },
|
|
120
|
+
get markdown() { return lazy('markdown', () => createMarkdownPort(adapters.markdown, opts)); },
|
|
145
121
|
temporal: (options) => createTemporalPort({ ...options, adapter: adapters.temporal }, opts),
|
|
146
122
|
};
|
|
147
123
|
}
|
|
148
124
|
|
|
149
|
-
/** 界面中途提交服务(见 SomaRuntimeServices.ui) */
|
|
150
|
-
export interface SomaUiService {
|
|
151
|
-
publish(): Promise<void>;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
125
|
/** 缺省实现:引擎未接线时的空操作(纯 Node 单测、无渲染宿主) */
|
|
155
126
|
function createNoopUiService(): SomaUiService {
|
|
156
127
|
return { publish: async () => undefined };
|