@tbox.cn/app-toolkit 0.7.4 → 0.8.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.
- package/dist/index.d.ts +1181 -1111
- package/dist/index.js +9 -9
- package/package.json +2 -2
- package/src/assembly/walk-manifests.ts +48 -10
- package/src/core/module-schema.ts +6 -0
- package/src/dto.ts +89 -68
- package/src/factory.ts +44 -57
- package/src/index.ts +10 -4
- package/src/integrations/predicate.ts +5 -9
- package/src/integrations/provider-binding.ts +83 -0
- package/src/views/app.ts +3 -1
- package/src/views/credential-types.ts +0 -1
- package/src/views/credentials.ts +3 -2
- package/src/views/integration-schemas.ts +17 -42
- package/src/views/modules.ts +14 -4
- package/src/views/provider-supply.ts +51 -0
- package/src/views/providers.ts +15 -49
- package/src/views/service-detail.ts +4 -5
- package/src/views/service-resolutions.ts +34 -12
- package/tests/credentials-view.test.ts +1 -3
- package/tests/demo-app.ts +31 -2
- package/tests/naming-alignment.test.ts +1 -1
- package/tests/provider-binding-supply.test.ts +508 -0
- package/tests/resolve-key.test.ts +4 -4
- package/tests/views.test.ts +48 -622
|
@@ -20,7 +20,6 @@ export function loadCredentialTypesView(snapshot: ViewSnapshot, provider?: strin
|
|
|
20
20
|
const entry = snapshot.catalog.credentialTypes[t];
|
|
21
21
|
return {
|
|
22
22
|
credentialType: t,
|
|
23
|
-
owner: entry?.owner ?? '',
|
|
24
23
|
credentialSchema: entry ? readSchemaRef(snapshot.appDir, entry.packageDir, entry.credentialSchema) : null,
|
|
25
24
|
};
|
|
26
25
|
}),
|
package/src/views/credentials.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CredentialBindingEcho, CredentialEcho, CredentialsView } from '../dto.js';
|
|
2
|
-
import { maskCredentialValues, readCredentialFile
|
|
2
|
+
import { maskCredentialValues, readCredentialFile } from '../core/credential-format.js';
|
|
3
3
|
import type { ViewSnapshot } from './context.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -7,6 +7,7 @@ import type { ViewSnapshot } from './context.js';
|
|
|
7
7
|
* 绑定位全量掩码回显——应用状态轴(随配置失效、零求值零 contracts、永不 503)。
|
|
8
8
|
* GET 永无真值(仅 ref/masked);掩码单源 maskCredentialValues;echoForRef 自
|
|
9
9
|
* service-resolutions 迁入共享(求值单体 instances[].credential 已删净——求值路径零凭据 I/O)。
|
|
10
|
+
* v8:file 字段删净(ref → config/credentials/{stem}.json 确定性派生——stemToFilePath 公开导出)。
|
|
10
11
|
*
|
|
11
12
|
* 键集 = 文件语义忠实镜像(api.md §0「键域不对称」):
|
|
12
13
|
* app.byInstance = 注册表 ids ∩ 有 ref(无 ref 的注册实例不出现;未注册 ref 跳过不虚报)
|
|
@@ -21,7 +22,7 @@ export function echoForRef(appDir: string, ref: string | undefined): CredentialE
|
|
|
21
22
|
const stem = ref.slice('secret://'.length);
|
|
22
23
|
const file = readCredentialFile(appDir, stem);
|
|
23
24
|
if (!file) return undefined;
|
|
24
|
-
return { type: file.type, ref,
|
|
25
|
+
return { type: file.type, ref, masked: maskCredentialValues(file.values) };
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export function loadCredentialsView(snapshot: ViewSnapshot): CredentialsView {
|
|
@@ -85,10 +85,7 @@ function mergeFieldSources(sources: ReadonlyArray<{ subschema: unknown }>): obje
|
|
|
85
85
|
* fields 收集零过滤(布尔/非对象子 schema 入列,判定全权归 mergeFieldSources—— 互证等式由
|
|
86
86
|
* 收集定义结构性闭合);schemaless 仅 configSchema === null(布尔/畸形整 schema 防御跳过——
|
|
87
87
|
* 不入 schemaless、零参与聚合; 运行时畸形,非契约面)。 */
|
|
88
|
-
export function buildIntegrationFieldRegistry(
|
|
89
|
-
layer: LayerIntegrationSchemas,
|
|
90
|
-
o?: { unsupplied?: string[] },
|
|
91
|
-
): IntegrationFieldRegistryView {
|
|
88
|
+
export function buildIntegrationFieldRegistry(layer: LayerIntegrationSchemas): IntegrationFieldRegistryView {
|
|
92
89
|
const schemaless: string[] = [];
|
|
93
90
|
let additionalPropertiesAllowed = true;
|
|
94
91
|
const buckets = new Map<string, Array<{ service: string; subschema: unknown; required: boolean }>>();
|
|
@@ -128,23 +125,18 @@ export function buildIntegrationFieldRegistry(
|
|
|
128
125
|
return {
|
|
129
126
|
provider: layer.provider,
|
|
130
127
|
schemaless,
|
|
131
|
-
unsupplied: [...(o?.unsupplied ?? [])],
|
|
132
128
|
additionalPropertiesAllowed,
|
|
133
129
|
fields,
|
|
134
130
|
};
|
|
135
131
|
}
|
|
136
132
|
|
|
137
|
-
/**
|
|
138
|
-
* 空串归一(I3)单点;module 轴 v6 零归属 → null(override 不豁免——预览服务于保存)。 */
|
|
133
|
+
/** 生效厂商解析单源(v8——轴参退场,纯实际解析)。module 轴 v6 零归属 → null。 */
|
|
139
134
|
export function formProviderOf(
|
|
140
135
|
axis: 'app' | 'module',
|
|
141
136
|
snapshot: ViewSnapshot,
|
|
142
137
|
moduleId?: string,
|
|
143
|
-
override?: string,
|
|
144
138
|
): string | null {
|
|
145
|
-
const ovr = typeof override === 'string' && override.length > 0 ? override : undefined;
|
|
146
139
|
if (axis === 'app') {
|
|
147
|
-
if (ovr !== undefined) return ovr;
|
|
148
140
|
const p = (snapshot.integrations as { provider?: unknown } | null)?.provider;
|
|
149
141
|
return typeof p === 'string' && p.length > 0 ? p : null;
|
|
150
142
|
}
|
|
@@ -152,7 +144,6 @@ export function formProviderOf(
|
|
|
152
144
|
if (!mod) return null; // 视图已先行 404,此处防御
|
|
153
145
|
const w = moduleOwnershipWritable(snapshot.walk, mod);
|
|
154
146
|
if (!w.writable) return null; // v6 零归属不豁免
|
|
155
|
-
if (ovr !== undefined) return ovr;
|
|
156
147
|
return resolveModuleBinding(snapshot.integrations, mod.id).provider;
|
|
157
148
|
}
|
|
158
149
|
|
|
@@ -167,41 +158,36 @@ const NULL_FORM_VIEWS: LayerFormViews = { integrationSchemas: null, integrationF
|
|
|
167
158
|
|
|
168
159
|
/** G 批表单收窄(消费投影单点):app/module 轴 registry.fields 只留 global===true——
|
|
169
160
|
* 未声明键落 ExtraFields 语义(复合可见面:layer.properties 仍全量,字段级代数不受扰)。
|
|
170
|
-
* schemaless/
|
|
161
|
+
* schemaless/additionalPropertiesAllowed 描述服务/Schema 面,不随字段过滤(unsupplied 已删——
|
|
162
|
+
* 供给判定归 /providers/:p/supply,v8)。 */
|
|
171
163
|
function narrowToGlobal(registry: IntegrationFieldRegistryView): IntegrationFieldRegistryView {
|
|
172
164
|
return { ...registry, fields: registry.fields.filter((f) => f.global) };
|
|
173
165
|
}
|
|
174
166
|
|
|
175
167
|
/** app 轴装配:scope = 供给足迹全量(≠ AppView.services——root.config 流向包括模块服务在内的所有服务);
|
|
176
|
-
*
|
|
177
|
-
export function loadAppFormViews(snapshot: ViewSnapshot
|
|
178
|
-
const provider = formProviderOf('app', snapshot
|
|
168
|
+
* 未知厂商/零足迹 → 非 null 空集(镜像 mock 语义)。 */
|
|
169
|
+
export function loadAppFormViews(snapshot: ViewSnapshot): LayerFormViews {
|
|
170
|
+
const provider = formProviderOf('app', snapshot);
|
|
179
171
|
if (provider === null) return NULL_FORM_VIEWS;
|
|
180
172
|
const layer = resolveLayerIntegrationSchemas(snapshot, provider, providerFootprint(snapshot.catalog, provider));
|
|
181
173
|
return { integrationSchemas: layer, integrationFieldRegistry: narrowToGlobal(buildIntegrationFieldRegistry(layer)) };
|
|
182
174
|
}
|
|
183
175
|
|
|
184
176
|
/** module 轴装配:仅 writable(v6 owns>0);scope = ownedServices ∩ 该厂商供给(v6——模块
|
|
185
|
-
* config
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const provider = formProviderOf('module', snapshot, moduleId, moduleProvider);
|
|
177
|
+
* config 流向归属服务)。 */
|
|
178
|
+
export function loadModuleFormViews(snapshot: ViewSnapshot, moduleId: string): LayerFormViews {
|
|
179
|
+
const provider = formProviderOf('module', snapshot, moduleId);
|
|
189
180
|
const mod = snapshot.walk.modules.find((m) => m.id === moduleId);
|
|
190
181
|
if (provider === null || !mod) return NULL_FORM_VIEWS;
|
|
191
182
|
const owned = (mod.descriptor.declare.owns ?? []).map((o) => o.service);
|
|
192
|
-
const
|
|
193
|
-
const layer = resolveLayerIntegrationSchemas(snapshot, provider, owned.filter(supplied));
|
|
183
|
+
const layer = resolveLayerIntegrationSchemas(snapshot, provider, owned.filter((s) => isSupplied(snapshot.catalog, provider, s)));
|
|
194
184
|
return {
|
|
195
185
|
integrationSchemas: layer,
|
|
196
|
-
integrationFieldRegistry: narrowToGlobal(
|
|
197
|
-
buildIntegrationFieldRegistry(layer, {
|
|
198
|
-
unsupplied: [...new Set(owned.filter((s) => !supplied(s)))],
|
|
199
|
-
}),
|
|
200
|
-
),
|
|
186
|
+
integrationFieldRegistry: narrowToGlobal(buildIntegrationFieldRegistry(layer)),
|
|
201
187
|
};
|
|
202
188
|
}
|
|
203
189
|
|
|
204
|
-
/** app 级 loader(v4.6
|
|
190
|
+
/** app 级 loader(v4.6 委托化——公开面保持) */
|
|
205
191
|
export function loadAppIntegrationSchemas(snapshot: ViewSnapshot): LayerIntegrationSchemas | null {
|
|
206
192
|
return loadAppFormViews(snapshot).integrationSchemas;
|
|
207
193
|
}
|
|
@@ -230,21 +216,12 @@ function serviceLevelBindingProvider(snapshot: ViewSnapshot, service: string): s
|
|
|
230
216
|
* (H9 逃逸 400 照抛——readInlineSchema 共享路径)
|
|
231
217
|
* ④ 其余(null/数组/原始值/坏对象)→ 整字段 null(≡ 谓词 #5 INLINE_PROVIDER_INVALID 同判——
|
|
232
218
|
* 不放行域级联,防错误 schema 污染坏节点)
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* 任一原分支改写 provider 为 X 后实读都进 bare 分支,同构承诺 by construction)。短路在节点读取之前——
|
|
236
|
-
* 豁免链三分支(与 四分支的有意分歧:预览与坏文件解耦):malformed(分支④)不污染假想 /
|
|
237
|
-
* 内联 ref 不读取(假想态无 H9 逃逸 400;catalog 命中的 manifest 声明路径照读,与节点声明的
|
|
238
|
-
* 用户可控路径不同性)/ 全链未绑定时假想仍非 null(服务轴恒可写,无 module 轴零归属对应物)。 */
|
|
219
|
+
* v8:服务轴假想绑定轴参(serviceProvider)退场——切换预览归 /providers/:p/supply,
|
|
220
|
+
* 本函数纯实际解析。 */
|
|
239
221
|
export function loadServiceIntegrationSchemas(
|
|
240
222
|
snapshot: ViewSnapshot,
|
|
241
223
|
service: string,
|
|
242
|
-
serviceProvider?: string,
|
|
243
224
|
): ServiceIntegrationSchemas | null {
|
|
244
|
-
const ovr = typeof serviceProvider === 'string' && serviceProvider.length > 0 ? serviceProvider : undefined;
|
|
245
|
-
if (ovr !== undefined) {
|
|
246
|
-
return { provider: ovr, configSchema: resolveServiceConfigSchema(snapshot, ovr, service) };
|
|
247
|
-
}
|
|
248
225
|
const p = (snapshot.integrations as { services?: Record<string, { provider?: unknown }> } | null)
|
|
249
226
|
?.services?.[service]?.provider;
|
|
250
227
|
if (p === undefined || p === '') {
|
|
@@ -267,14 +244,12 @@ export function loadServiceIntegrationSchemas(
|
|
|
267
244
|
* 伪层 {provider, services: {[s]: {configSchema}}} → buildIntegrationFieldRegistry——
|
|
268
245
|
* fields = 该 schema 全部字段带 global 旗标;configSchema null → schemaless=[service]
|
|
269
246
|
* 非 null 空集;schemas 整体 null(全链未绑定/坏节点)→ registry null——镜像 语义)。
|
|
270
|
-
*
|
|
271
|
-
* 轴参仅重定向表单层投影,global 旗标全量透传语义不变)。 */
|
|
247
|
+
* v8:服务轴假想绑定轴参退场(同 loadServiceIntegrationSchemas)。 */
|
|
272
248
|
export function loadServiceFieldRegistry(
|
|
273
249
|
snapshot: ViewSnapshot,
|
|
274
250
|
service: string,
|
|
275
|
-
serviceProvider?: string,
|
|
276
251
|
): IntegrationFieldRegistryView | null {
|
|
277
|
-
const schemas = loadServiceIntegrationSchemas(snapshot, service
|
|
252
|
+
const schemas = loadServiceIntegrationSchemas(snapshot, service);
|
|
278
253
|
if (schemas === null) return null;
|
|
279
254
|
const layer: LayerIntegrationSchemas = {
|
|
280
255
|
provider: schemas.provider,
|
package/src/views/modules.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import type { ModuleDeclaration,
|
|
3
|
+
import type { ModuleDeclaration, ModuleDetailView, ModuleResourceEcho, ModuleResourcesEcho, ServiceDemand } from '../dto.js';
|
|
4
4
|
import { AppToolkitError } from '../core/errors.js';
|
|
5
|
-
import { moduleOwnershipWritable
|
|
5
|
+
import { moduleOwnershipWritable } from '../integrations/module-binding.js';
|
|
6
|
+
import { moduleProviderBinding } from '../integrations/provider-binding.js';
|
|
6
7
|
import { resolveServiceDisplay, type ViewSnapshot } from './context.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -142,7 +143,16 @@ export function loadModuleDetailView(snapshot: ViewSnapshot, moduleId: string):
|
|
|
142
143
|
: {}),
|
|
143
144
|
}
|
|
144
145
|
: null;
|
|
145
|
-
|
|
146
|
+
// v8 三轴同构:configured/effective/inherited(moduleProviderBinding 单源);
|
|
147
|
+
// legacy provider/layer 双写仅本视图发射(旧读者保护——0.9.0 删,双写一致性断言锁定)
|
|
148
|
+
const binding = moduleProviderBinding(snapshot.integrations, moduleId);
|
|
149
|
+
const bindingView = {
|
|
150
|
+
configured: binding.configured,
|
|
151
|
+
effective: binding.effective,
|
|
152
|
+
inherited: binding.inherited,
|
|
153
|
+
provider: binding.effective.provider,
|
|
154
|
+
layer: binding.effective.layer,
|
|
155
|
+
};
|
|
146
156
|
return {
|
|
147
157
|
// v7 词汇统一:name = 展示名(兜底与 /modules 同语义——manifest name ?? id)
|
|
148
158
|
name: mod.descriptor.name ?? mod.descriptor.id,
|
|
@@ -153,7 +163,7 @@ export function loadModuleDetailView(snapshot: ViewSnapshot, moduleId: string):
|
|
|
153
163
|
integration,
|
|
154
164
|
// 模块资源只读镜像(N2 读半边——knowledge.json 台账 ref 展开态随行)
|
|
155
165
|
resources: resourcesOf(snapshot, moduleId, modulesNode),
|
|
156
|
-
binding:
|
|
166
|
+
binding: bindingView,
|
|
157
167
|
configEditable: w.writable,
|
|
158
168
|
services,
|
|
159
169
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ProviderSupplyScope, ProviderSupplyView } from '../dto.js';
|
|
2
|
+
import { AppToolkitError } from '../core/errors.js';
|
|
3
|
+
import { moduleOwnershipWritable, providerFootprint } from '../integrations/module-binding.js';
|
|
4
|
+
import { resolutionKeys } from './service-resolutions.js';
|
|
5
|
+
import { resolveServiceDisplay, type ViewSnapshot } from './context.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 供给判定投影(views/provider-supply;v8——切换预览唯一判定源,前端零供给关系计算)。
|
|
9
|
+
* 判定关系单源 = catalog 供给关系((provider, service) ∈ 已装 provider 包槽声明 +
|
|
10
|
+
* `declare.providers.id` 零槽自声明厂商——与求值轴 resolution.supplied 同一关系)。
|
|
11
|
+
*
|
|
12
|
+
* scope 三轴 = 该层绑定实际作用的服务集合(api.md §7):
|
|
13
|
+
* app → resolutionKeys 单源(在册服务全集——root 级联全域可达,与批量求值键集恒等)
|
|
14
|
+
* module → 归属服务(declare.owns 展平——moduleOwnershipWritable 单源 ≡ detail.ownedServices;
|
|
15
|
+
* 跨模块消费服务不入 scope——其绑定跟随各自 owner,与本模块绑定无关)
|
|
16
|
+
* service → 自身(任意 id 恒 200——判定非寻址,supplied:false 表达未供给)
|
|
17
|
+
*
|
|
18
|
+
* surplus(作用域外供给)不表达。判定非寻址:已知厂商 + 不在足迹的 service → 200 +
|
|
19
|
+
* supplied:false(与组合单体 SUPPLY_NOT_FOUND 404 的有意分歧);厂商 ∉ catalog → 404。
|
|
20
|
+
* 静态零 contracts——contracts 不可用时判定仍可用(降级态「数据来源」功能存活)。
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export function loadProviderSupplyView(
|
|
24
|
+
snapshot: ViewSnapshot,
|
|
25
|
+
provider: string,
|
|
26
|
+
scope: ProviderSupplyScope,
|
|
27
|
+
): ProviderSupplyView {
|
|
28
|
+
if (!(provider in snapshot.catalog.providers)) {
|
|
29
|
+
throw new AppToolkitError('PROVIDER_NOT_FOUND', 404, `厂商 ${provider} 不 ∈ catalog(内联声明厂商无包级档案——判定归求值轴 resolution.supplied)`);
|
|
30
|
+
}
|
|
31
|
+
let services: string[];
|
|
32
|
+
if (scope.kind === 'app') {
|
|
33
|
+
services = resolutionKeys(snapshot);
|
|
34
|
+
} else if (scope.kind === 'module') {
|
|
35
|
+
const mod = snapshot.walk.modules.find((m) => m.id === scope.module);
|
|
36
|
+
if (!mod) throw new AppToolkitError('MODULE_NOT_FOUND', 404, `模块 ${scope.module} 非已装模块`);
|
|
37
|
+
services = moduleOwnershipWritable(snapshot.walk, mod).ownedServices;
|
|
38
|
+
} else {
|
|
39
|
+
services = [scope.service];
|
|
40
|
+
}
|
|
41
|
+
const footprint = new Set(providerFootprint(snapshot.catalog, provider));
|
|
42
|
+
return {
|
|
43
|
+
provider,
|
|
44
|
+
scope,
|
|
45
|
+
services: services.map((service) => ({
|
|
46
|
+
service,
|
|
47
|
+
name: resolveServiceDisplay(snapshot.walk, service).name,
|
|
48
|
+
supplied: footprint.has(service),
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
}
|
package/src/views/providers.ts
CHANGED
|
@@ -1,71 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderEntry, ProviderServiceDetail, ProvidersView } from '../dto.js';
|
|
2
2
|
import { AppToolkitError } from '../core/errors.js';
|
|
3
3
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
4
|
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import type { ViewSnapshot } from './context.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* 供给轴投影(views/providers;C4
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* 供给轴投影(views/providers;C4)。v8 后供给面 = 名单(/providers,vendorMeta 单源含
|
|
9
|
+
* 零槽自声明厂商)· 判定(/providers/:p/supply——见 provider-supply.ts)·
|
|
10
|
+
* 表单(组合单体 /providers/:p/services/:s——configSchema 唯一暴露面)。
|
|
11
11
|
* 静态端点零求值(铁律 #3)。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
/** GET /providers
|
|
14
|
+
/** GET /providers:厂商基本信息(vendorMeta 单源——slots 厂商 + 零槽自声明厂商同路径;
|
|
15
|
+
* 零槽厂商 = 空 impl map + 自声明 meta(supply 判定「厂商在、供给空」语义) */
|
|
15
16
|
export function loadProvidersView(snapshot: ViewSnapshot): ProvidersView {
|
|
16
17
|
const providers: ProviderEntry[] = [];
|
|
17
18
|
for (const [provider, impls] of Object.entries(snapshot.catalog.providers)) {
|
|
18
19
|
const entries = Object.values(impls);
|
|
19
|
-
|
|
20
|
+
const meta = snapshot.catalog.vendorMeta[provider];
|
|
21
|
+
if (entries.length === 0 && !meta) continue;
|
|
20
22
|
providers.push({
|
|
21
23
|
provider,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
...(entries[0].name ? { name: entries[0].name } : {}),
|
|
26
|
-
...(entries[0].description ? { description: entries[0].description } : {}),
|
|
24
|
+
// 零槽厂商(空 entries)非 local(local 旗标语义 = 供给实现级聚合——空集无实现可聚合)
|
|
25
|
+
local: entries.length > 0 && entries.every((e) => e.local === true),
|
|
26
|
+
...(meta?.name ? { name: meta.name } : entries[0]?.name ? { name: entries[0].name } : {}),
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
return { providers: providers.sort((a, b) => a.provider.localeCompare(b.provider)) };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/** GET /providers/:provider:供给足迹(implementations 恒数组——H1 多实现钉版数据源;
|
|
33
|
-
* v4.4 include=integrationSchemas 切换态批量——services[s] += { configSchema }(纯 config)) */
|
|
34
|
-
export function loadProviderDetailView(snapshot: ViewSnapshot, provider: string, include?: ReadonlySet<string>): ProviderDetail {
|
|
35
|
-
const impls = snapshot.catalog.providers[provider];
|
|
36
|
-
if (!impls) {
|
|
37
|
-
throw new AppToolkitError('PROVIDER_NOT_FOUND', 404, `厂商 ${provider} 不 ∈ catalog(内联声明厂商无包级档案——身份与表单经组合端点暴露)`);
|
|
38
|
-
}
|
|
39
|
-
const services: ProviderDetail['services'] = {};
|
|
40
|
-
for (const entry of Object.values(impls)) {
|
|
41
|
-
for (const service of entry.services) {
|
|
42
|
-
const bucket = (services[service] ??= { implementations: [] });
|
|
43
|
-
bucket.implementations.push({ implementation: entry.implementation, credentialType: entry.credentialType });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// 服务展示名走链(B1):词汇 meta > demand meta > id(name 恒发)
|
|
47
|
-
for (const [service, bucket] of Object.entries(services)) {
|
|
48
|
-
const display = resolveServiceDisplay(snapshot.walk, service);
|
|
49
|
-
bucket.name = display.name;
|
|
50
|
-
if (display.description !== undefined) bucket.description = display.description;
|
|
51
|
-
}
|
|
52
|
-
if (include?.has('integrationSchemas')) {
|
|
53
|
-
for (const [service, bucket] of Object.entries(services)) {
|
|
54
|
-
bucket.integrationSchemas = { configSchema: resolveServiceConfigSchema(snapshot, provider, service) };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const entries = Object.values(impls);
|
|
58
|
-
return {
|
|
59
|
-
provider,
|
|
60
|
-
local: entries.every((e) => e.local === true),
|
|
61
|
-
owner: entries[0].owner,
|
|
62
|
-
// 厂商展示元数据(B1 walk 层传播——首条目透传;v7 title→name)
|
|
63
|
-
...(entries[0].name ? { name: entries[0].name } : {}),
|
|
64
|
-
...(entries[0].description ? { description: entries[0].description } : {}),
|
|
65
|
-
services,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
32
|
/** 组合单体(GET /providers/:p/services/:s):catalog 供给与槽级内联声明统一解析(/) */
|
|
70
33
|
export function loadProviderServiceDetailView(
|
|
71
34
|
snapshot: ViewSnapshot,
|
|
@@ -118,6 +81,9 @@ export function loadProviderServiceDetailView(
|
|
|
118
81
|
provider,
|
|
119
82
|
service,
|
|
120
83
|
implementations,
|
|
84
|
+
// v8 拍平(唯一推荐读取位)
|
|
85
|
+
configSchema,
|
|
86
|
+
// @deprecated 0.8.0 双写(单键包裹残留——旧读者保护,0.9.0 删)
|
|
121
87
|
integrationSchemas: { configSchema },
|
|
122
88
|
};
|
|
123
89
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ServiceDetail } from '../dto.js';
|
|
2
2
|
import { AppToolkitError } from '../core/errors.js';
|
|
3
3
|
import { isKnownService } from '../integrations/read.js';
|
|
4
|
-
import {
|
|
4
|
+
import { serviceProviderBinding } from '../integrations/provider-binding.js';
|
|
5
|
+
import { resolveServiceDisplay, type ViewSnapshot } from './context.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 服务静态单体投影(views/service-detail;C4)。求值数据不在此(→ /service-resolutions/:service)。
|
|
@@ -25,10 +26,8 @@ export function loadServiceDetailView(snapshot: ViewSnapshot, service: string):
|
|
|
25
26
|
name: display.name,
|
|
26
27
|
...(display.description !== undefined ? { description: display.description } : {}),
|
|
27
28
|
required: demand ? !demand.optional : false,
|
|
28
|
-
// defaults 唯一落位(manifest 预填)
|
|
29
|
-
defaults: demand ? demand.defaults.map((d) => ({ ...d })) : [],
|
|
30
29
|
integration,
|
|
31
|
-
//
|
|
32
|
-
|
|
30
|
+
// v8:binding 恒在场(service 轴单源——node 级口径;inherited = 上级绑定)
|
|
31
|
+
binding: serviceProviderBinding(snapshot.integrations, snapshot.walk, service),
|
|
33
32
|
};
|
|
34
33
|
}
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
EffectiveBinding,
|
|
5
5
|
IntegrationIssue,
|
|
6
6
|
ResolvedInstance,
|
|
7
|
+
ResolvedProvider,
|
|
7
8
|
ServiceResolution,
|
|
8
9
|
ServiceResolutionEntry,
|
|
9
10
|
ServiceResolutionsView,
|
|
@@ -12,6 +13,7 @@ import type {
|
|
|
12
13
|
} from '../dto.js';
|
|
13
14
|
import { AppToolkitError, contractsNotResolvedMessage } from '../core/errors.js';
|
|
14
15
|
import { resolveModuleBinding } from '../integrations/module-binding.js';
|
|
16
|
+
import { serviceProviderBinding } from '../integrations/provider-binding.js';
|
|
15
17
|
import type { ResolvedContracts } from '../core/contracts-resolver.js';
|
|
16
18
|
import type { WalkCatalog } from '../assembly/walk-manifests.js';
|
|
17
19
|
import { isSupplied, type ViewSnapshot } from './context.js';
|
|
@@ -147,16 +149,18 @@ interface EffectiveResolutionShape {
|
|
|
147
149
|
message?: string;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
/** 单源摘要函数:/service-resolutions map 值 ≡ /service-resolutions/:s 的 resolution
|
|
152
|
+
/** 单源摘要函数:/service-resolutions map 值 ≡ /service-resolutions/:s 的 resolution 摘要基。
|
|
153
|
+
* precomputed = 调用方已求值的默认实例产物(求值单体复用——消默认实例重复求值,B4)。 */
|
|
151
154
|
export function resolveServiceSummary(
|
|
152
155
|
service: string,
|
|
153
156
|
snapshot: ViewSnapshot,
|
|
157
|
+
precomputed?: { evaluation: InstanceEvaluation; supplies: unknown },
|
|
154
158
|
): ServiceResolutionEntry {
|
|
155
159
|
const contracts = evaluationContracts(snapshot);
|
|
156
160
|
const { integrations, catalog } = snapshot;
|
|
157
161
|
|
|
158
|
-
// 供给查表(buildSupplyLookup 动态派生——应用自身 contracts
|
|
159
|
-
const supplies = contracts.buildSupplyLookup(catalog as never);
|
|
162
|
+
// 供给查表(buildSupplyLookup 动态派生——应用自身 contracts;precomputed 复用)
|
|
163
|
+
const supplies = precomputed?.supplies ?? contracts.buildSupplyLookup(catalog as never);
|
|
160
164
|
|
|
161
165
|
// 默认实例 = 应用自身 normalizeInstances 委托(null → '*' 通配口径)
|
|
162
166
|
const cfg = integrations as { instances?: unknown; defaultInstanceId?: unknown } | null;
|
|
@@ -167,10 +171,10 @@ export function resolveServiceSummary(
|
|
|
167
171
|
const defaultInstanceId = normalized.defaultInstanceId ?? '*';
|
|
168
172
|
|
|
169
173
|
// 跨实例求值异常聚合(statusMessage 直投)
|
|
170
|
-
const evaluation = evaluateInstance(snapshot, contracts, service, defaultInstanceId, supplies);
|
|
174
|
+
const evaluation = precomputed?.evaluation ?? evaluateInstance(snapshot, contracts, service, defaultInstanceId, supplies);
|
|
171
175
|
|
|
172
176
|
// v4.4 layer = provider 字段来源声明层(默认实例口径,与 status 同轴);
|
|
173
|
-
// 未配置(provider 缺席)→ 双缺席——layer 单独在场即「无 provider 的孤儿层」,违
|
|
177
|
+
// 未配置(provider 缺席)→ 双缺席——layer 单独在场即「无 provider 的孤儿层」,违 孤儿层口径
|
|
174
178
|
const layer = deriveBindingLayer(snapshot, service, defaultInstanceId);
|
|
175
179
|
|
|
176
180
|
// provider:effective 求值厂商(最特异声明层——跨层事实);缺席 = 未配置/未解析
|
|
@@ -180,6 +184,11 @@ export function resolveServiceSummary(
|
|
|
180
184
|
evaluation.provider ??
|
|
181
185
|
(typeof declaredProvider === 'string' ? declaredProvider : typeof declaredProvider === 'object' && declaredProvider ? String((declaredProvider as { provider?: string }).provider) : undefined);
|
|
182
186
|
|
|
187
|
+
// v8 N1:binding 双写(恒在场——未配置 = {null, null};默认实例口径 layer 可 'instance';
|
|
188
|
+
// 与静态三视图 binding.effective 同概念同形状——「binding 一词到底」;
|
|
189
|
+
// 双写一致性断言锁定 provider/layer ≡ binding 投影)
|
|
190
|
+
const binding: ResolvedProvider = { provider: provider ?? null, layer: layer ?? null };
|
|
191
|
+
|
|
183
192
|
// supplied 点查:provider ∈ 厂商集合时在场(true 供给 / false 显式绑定未供给——「AI 实施中」);
|
|
184
193
|
// provider ∉(自定义 API)或缺席时缺席
|
|
185
194
|
const knownVendors = new Set(Object.keys(snapshot.catalog.providers));
|
|
@@ -199,6 +208,7 @@ export function resolveServiceSummary(
|
|
|
199
208
|
return {
|
|
200
209
|
status: evaluation.status,
|
|
201
210
|
...(evaluation.statusMessage ? { statusMessage: evaluation.statusMessage } : {}),
|
|
211
|
+
binding,
|
|
202
212
|
...(provider !== undefined ? { provider } : {}),
|
|
203
213
|
...(provider !== undefined && layer !== null ? { layer } : {}),
|
|
204
214
|
...(supplied !== undefined ? { supplied } : {}),
|
|
@@ -213,8 +223,9 @@ function isSuppliedCheck(catalog: WalkCatalog, provider: string, service: string
|
|
|
213
223
|
|
|
214
224
|
/** 批量键集(求值轴/降级轴共用单源:服务词汇 ∪ 需求侧 ∪ 已配置 ∪ 归属)。
|
|
215
225
|
* v6.1 += 归属键——owned 服务恒可求值(embed 自足前置:迭代基不是 filter,
|
|
216
|
-
* 缺此键则 owned ∖ 词汇服务在内嵌轴静默丢键,fail-visible 破功)。
|
|
217
|
-
|
|
226
|
+
* 缺此键则 owned ∖ 词汇服务在内嵌轴静默丢键,fail-visible 破功)。
|
|
227
|
+
* v8 起导出:app 轴供给判定作用域(provider-supply)同源消费——键集恒等断言防第二实现漂移。 */
|
|
228
|
+
export function resolutionKeys(snapshot: ViewSnapshot): string[] {
|
|
218
229
|
const keys = new Set<string>([
|
|
219
230
|
...snapshot.walk.vocabulary,
|
|
220
231
|
...Object.keys(snapshot.catalog.services),
|
|
@@ -239,7 +250,8 @@ export function loadServiceResolutionsView(
|
|
|
239
250
|
return { contracts: toContractsResolution(snapshot.contracts), resolutions, issues };
|
|
240
251
|
}
|
|
241
252
|
|
|
242
|
-
/** 求值单体(完整结构 instances + inheritance + 过滤 issues; extends
|
|
253
|
+
/** 求值单体(完整结构 instances + inheritance + 过滤 issues; extends 结构保证)。
|
|
254
|
+
* v8 B4 修复:默认实例求值结果复用入摘要(原 resolveServiceSummary 独立重算 = 重复求值)。 */
|
|
243
255
|
export function loadServiceResolutionDetail(
|
|
244
256
|
service: string,
|
|
245
257
|
snapshot: ViewSnapshot,
|
|
@@ -261,10 +273,12 @@ export function loadServiceResolutionDetail(
|
|
|
261
273
|
const slotKeys = slot?.instances ? Object.keys(slot.instances) : undefined;
|
|
262
274
|
const instanceIds = enumerateInstanceIds(slotKeys, declaredIds);
|
|
263
275
|
|
|
264
|
-
//
|
|
276
|
+
// 逐实例求值一次(Map 复用——默认实例产物直入摘要,消重复求值)
|
|
277
|
+
const evals = new Map<string, InstanceEvaluation>();
|
|
278
|
+
for (const id of instanceIds) evals.set(id, evaluateInstance(snapshot, contracts, service, id, supplies));
|
|
265
279
|
|
|
266
280
|
const instances: ResolvedInstance[] = instanceIds.map((id) => {
|
|
267
|
-
const evalResult =
|
|
281
|
+
const evalResult = evals.get(id)!;
|
|
268
282
|
// v4.4 instances[].credential 删净(凭据掩码回显归 GET /credentials——求值路径零凭据文件 I/O)
|
|
269
283
|
return {
|
|
270
284
|
instanceId: id,
|
|
@@ -277,7 +291,13 @@ export function loadServiceResolutionDetail(
|
|
|
277
291
|
// inheritance 四层(app → module → service → instance——effective 链声明位投影)
|
|
278
292
|
const inheritance = buildInheritance(snapshot, service, normalized.defaultInstanceId ?? '*');
|
|
279
293
|
|
|
280
|
-
const summary = resolveServiceSummary(
|
|
294
|
+
const summary = resolveServiceSummary(
|
|
295
|
+
service,
|
|
296
|
+
snapshot,
|
|
297
|
+
evals.has(normalized.defaultInstanceId ?? '*')
|
|
298
|
+
? { evaluation: evals.get(normalized.defaultInstanceId ?? '*')!, supplies }
|
|
299
|
+
: undefined,
|
|
300
|
+
);
|
|
281
301
|
const resolution: ServiceResolution = {
|
|
282
302
|
...summary,
|
|
283
303
|
instances,
|
|
@@ -356,13 +376,15 @@ export function contractsEvaluable(contracts: ResolvedContracts): boolean {
|
|
|
356
376
|
}
|
|
357
377
|
|
|
358
378
|
/** 降级单条目(静态可算字段:module = walk.ownership(v6 归属单源,install id 轴)/
|
|
359
|
-
* required = OR 聚合;
|
|
379
|
+
* required = OR 聚合;v8 N1:binding = node 级静态投影(serviceProviderBinding 单源,
|
|
380
|
+
* 零 contracts)——「数据来源」展示在降级态存活;provider/layer 求值产物仍不投)。 */
|
|
360
381
|
function degradeEntry(snapshot: ViewSnapshot, service: string, message: string): ServiceResolutionEntry {
|
|
361
382
|
const demand = snapshot.catalog.services[service];
|
|
362
383
|
const owner = snapshot.walk.ownership[service];
|
|
363
384
|
return {
|
|
364
385
|
status: 'evaluation-unavailable',
|
|
365
386
|
statusMessage: message,
|
|
387
|
+
binding: serviceProviderBinding(snapshot.integrations, snapshot.walk, service).effective,
|
|
366
388
|
...(owner !== undefined ? { module: owner } : {}),
|
|
367
389
|
...(demand !== undefined ? { required: !demand.optional } : {}),
|
|
368
390
|
};
|
|
@@ -83,7 +83,6 @@ describe('v4.4 D33 凭据域(F6)', () => {
|
|
|
83
83
|
expect(view.app.credential).toEqual({
|
|
84
84
|
type: 'wanda-c-signed-v1',
|
|
85
85
|
ref: 'secret://wanda-global',
|
|
86
|
-
file: 'config/credentials/wanda-global.json',
|
|
87
86
|
masked: { appKey: 'KE****', salt: 'SA****' },
|
|
88
87
|
});
|
|
89
88
|
// app.byInstance:mall-bj-01(无 ref)不出现;ghost-id(未注册 ref)跳过不虚报;mall-sh-01 在场
|
|
@@ -101,7 +100,6 @@ describe('v4.4 D33 凭据域(F6)', () => {
|
|
|
101
100
|
expect(view.services['parking.payment']!.credential).toEqual({
|
|
102
101
|
type: 'wanda-c-signed-v1',
|
|
103
102
|
ref: 'secret://wanda-parking.payment',
|
|
104
|
-
file: 'config/credentials/wanda-parking.payment.json',
|
|
105
103
|
masked: { appKey: 'SV****' },
|
|
106
104
|
});
|
|
107
105
|
expect(view.services['parking.payment']!.byInstance['*']).toBeNull(); // 无 ref → null
|
|
@@ -128,7 +126,7 @@ describe('v4.4 D33 凭据域(F6)', () => {
|
|
|
128
126
|
expect(wanda.types).toHaveLength(1);
|
|
129
127
|
expect(wanda.types[0]).toEqual({
|
|
130
128
|
credentialType: 'wanda-c-signed-v1',
|
|
131
|
-
|
|
129
|
+
|
|
132
130
|
credentialSchema: { type: 'object', properties: { appKey: { type: 'string' } } },
|
|
133
131
|
});
|
|
134
132
|
expect((await tk.loadCredentialTypes('mock')).types.map((t) => t.credentialType)).toEqual(['-']);
|
package/tests/demo-app.ts
CHANGED
|
@@ -18,6 +18,33 @@ export interface TempApp {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/** 临时应用树:.tbox/app.json + apps/server + packages/ + config/(最小可解析布局) */
|
|
21
|
+
/** v8 级联 resolve 实现(真语义:slot 缺席 not-configured / 四层 head / supplies 派生失败
|
|
22
|
+
* binding-unresolved——binding/supply 新族测试基座用;默认 fake 仍恒 not-configured 不动) */
|
|
23
|
+
export const CASCADE_RESOLVE_BODY = [
|
|
24
|
+
'const slot = integrations && integrations.services && integrations.services[service];',
|
|
25
|
+
'if (!slot) return { status: "service-not-configured" };',
|
|
26
|
+
'const inst = slot.instances && (slot.instances[instanceId] || slot.instances["*"]);',
|
|
27
|
+
'const modOwner = ownerOf && ownerOf[service];',
|
|
28
|
+
'const mod = integrations.modules && modOwner ? integrations.modules[modOwner] : undefined;',
|
|
29
|
+
'const prov = inst && inst.provider != null ? inst.provider : slot.provider != null ? slot.provider : mod && mod.provider != null ? mod.provider : integrations.provider != null ? integrations.provider : null;',
|
|
30
|
+
'if (prov == null) return { status: "service-not-configured" };',
|
|
31
|
+
'const cands = supplies ? supplies[prov + "\\u0000" + service] : undefined;',
|
|
32
|
+
'if (!cands || !cands.length) return { status: "binding-unresolved", message: "provider " + prov + " 未供给 " + service };',
|
|
33
|
+
'if (cands.length > 1) return { status: "binding-unresolved", message: "多实现需显式 implementation" };',
|
|
34
|
+
'return { status: "ok", effective: { provider: prov, implementation: slot.implementation || cands[0], config: {} } };',
|
|
35
|
+
].join(' ');
|
|
36
|
+
|
|
37
|
+
/** v8 供给聚合 buildSupplyLookup 实现(catalog 展开——与 TIER0 语义同构) */
|
|
38
|
+
export const SUPPLY_AGGREGATE_BODY = [
|
|
39
|
+
'const out = {};',
|
|
40
|
+
'for (const [v, impls] of Object.entries((catalog && catalog.providers) || {})) {',
|
|
41
|
+
' for (const [impl, e] of Object.entries(impls)) {',
|
|
42
|
+
' for (const s of e.services || []) { (out[v + "\\u0000" + s] ??= []).push(impl); }',
|
|
43
|
+
' }',
|
|
44
|
+
'}',
|
|
45
|
+
'return out;',
|
|
46
|
+
].join(' ');
|
|
47
|
+
|
|
21
48
|
export function createTempApp(prefix = 'tbox-toolkit-'): TempApp {
|
|
22
49
|
const appDir = mkdtempSync(join(tmpdir(), prefix));
|
|
23
50
|
mkdirSync(join(appDir, '.tbox'), { recursive: true });
|
|
@@ -53,6 +80,8 @@ export interface FakeContractsOptions {
|
|
|
53
80
|
withMarker?: boolean;
|
|
54
81
|
/** service-slots.json 词汇(P9 身份判据/求值键集;缺省不物化 = 词汇空) */
|
|
55
82
|
slots?: string[];
|
|
83
|
+
/** buildSupplyLookup 实现(缺省恒 {}——v8 供给判定/级联派生用例传聚合实现,见 supplyAggregateBody) */
|
|
84
|
+
supplyBody?: string;
|
|
56
85
|
/** 词汇 meta 节(per-service {name,description}——B1 展示名链 fixture) */
|
|
57
86
|
meta?: Record<string, { name?: string; description?: string }>;
|
|
58
87
|
/** service-slots.json 落位:'root' = 包根(缺省——夹具/旧布局形态);
|
|
@@ -66,7 +95,7 @@ export interface FakeContractsOptions {
|
|
|
66
95
|
/** 假 contracts 包:package.json exports 形态逐字段复刻发布面(types+import 双条件、无 require/default)
|
|
67
96
|
* ——resolver 不经 exports 解析(包根直探),该形态为 E4 类错误的机械防线。 */
|
|
68
97
|
export function writeFakeContractsPackage(packageRoot: string, opts: FakeContractsOptions = {}): void {
|
|
69
|
-
const { version = '0.9.0', withStrict = true, withDist = true, brokenDist = false, missingEvaluationExports = false, rejectMarker, resolveBody, withMarker = true, slots, meta, slotsLayout = 'root', zodRejectPaths } = opts;
|
|
98
|
+
const { version = '0.9.0', withStrict = true, withDist = true, brokenDist = false, missingEvaluationExports = false, rejectMarker, resolveBody, supplyBody, withMarker = true, slots, meta, slotsLayout = 'root', zodRejectPaths } = opts;
|
|
70
99
|
const strictBody = withStrict
|
|
71
100
|
? `export function parseIntegrationsConfig(raw) { ${
|
|
72
101
|
rejectMarker ? `if (JSON.stringify(raw).includes(${JSON.stringify(rejectMarker)})) throw new Error("fake strict reject"); ` : ''
|
|
@@ -84,7 +113,7 @@ export function writeFakeContractsPackage(packageRoot: string, opts: FakeContrac
|
|
|
84
113
|
? `export const marker = 1;\n${strictBody}`
|
|
85
114
|
: [
|
|
86
115
|
resolveLine,
|
|
87
|
-
|
|
116
|
+
`export function buildSupplyLookup(catalog) { ${supplyBody ?? 'return {};'} }`,
|
|
88
117
|
'export function moduleDomainOf(service) { return String(service).split(".")[0] ?? ""; }',
|
|
89
118
|
'export function normalizeInstances(config) { return { instances: (config && config.instances) || [], defaultInstanceId: (config && config.defaultInstanceId) ?? null }; }',
|
|
90
119
|
'export const RESOURCE_TYPE_IDS = ["knowledge"];',
|
|
@@ -14,7 +14,7 @@ export const URL_METHOD_MAP: ReadonlyArray<{ method: string; url: string }> = [
|
|
|
14
14
|
{ method: 'loadApp', url: 'GET /app' },
|
|
15
15
|
{ method: 'loadService', url: 'GET /services/:service' },
|
|
16
16
|
{ method: 'loadProviders', url: 'GET /providers' },
|
|
17
|
-
{ method: '
|
|
17
|
+
{ method: 'loadProviderSupply', url: 'GET /providers/:provider/supply' },
|
|
18
18
|
{ method: 'loadProviderService', url: 'GET /providers/:provider/services/:service' },
|
|
19
19
|
// ── 求值(2)──
|
|
20
20
|
{ method: 'loadServiceResolutions', url: 'GET /service-resolutions' },
|