@tbox.cn/app-toolkit 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/chunk-WUULQDOV.js +1 -0
  2. package/dist/contracts-resolver-PS2UH2G6.js +1 -0
  3. package/dist/index.d.ts +382 -129
  4. package/dist/index.js +9 -8
  5. package/package.json +2 -2
  6. package/src/assembly/provider-catalog.ts +1 -1
  7. package/src/assembly/resolve-key.ts +75 -0
  8. package/src/assembly/walk-manifests.ts +216 -96
  9. package/src/core/contracts-expected.ts +2 -2
  10. package/src/core/contracts-resolver.ts +12 -1
  11. package/src/core/env-expansion.ts +14 -12
  12. package/src/core/module-schema.ts +88 -12
  13. package/src/dto.ts +53 -25
  14. package/src/factory.ts +62 -18
  15. package/src/index.ts +18 -7
  16. package/src/integrations/evaluate-app.ts +41 -0
  17. package/src/integrations/mock-bindings.ts +1 -1
  18. package/src/integrations/module-binding.ts +60 -0
  19. package/src/integrations/predicate-io.ts +26 -5
  20. package/src/integrations/predicate.ts +97 -57
  21. package/src/integrations/prune-bindings.ts +205 -0
  22. package/src/integrations/write.ts +43 -27
  23. package/src/views/app.ts +8 -4
  24. package/src/views/context.ts +26 -7
  25. package/src/views/integration-schemas.ts +61 -17
  26. package/src/views/modules.ts +45 -27
  27. package/src/views/providers.ts +13 -1
  28. package/src/views/service-detail.ts +5 -3
  29. package/src/views/service-resolutions.ts +14 -13
  30. package/tests/credentials-view.test.ts +2 -2
  31. package/tests/demo-app.ts +34 -5
  32. package/tests/dev-manifest-catalog.test.ts +86 -6
  33. package/tests/file-cache.test.ts +5 -5
  34. package/tests/module-schema.test.ts +117 -16
  35. package/tests/resolve-key.test.ts +154 -0
  36. package/tests/vendor-schema-keywords.test.ts +86 -0
  37. package/tests/views.test.ts +425 -139
  38. package/tests/write-core.test.ts +83 -0
  39. package/dist/chunk-KPD3LUH4.js +0 -1
  40. package/dist/contracts-resolver-E4SECBOG.js +0 -1
  41. package/src/integrations/domain-binding.ts +0 -81
@@ -1,16 +1,30 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  /**
4
- * tbox.module.json schema v1(001 §3.6 字段名,003 §4.1 schema v1 定版)。
4
+ * tbox.module.json schema v1(001 §3.6 字段名,003 §4.1 schema v1 定版;v6 声明面翻转)。
5
5
  * app-toolkit 单一校验源(自 CLI module-schema.ts 迁入;CLI 经 re-export 消费)。
6
6
  *
7
7
  * 迁移改造(ai-build C2-5):
8
8
  * - resourceNeedContribSchema 的 type 由 `z.enum(RESOURCE_TYPE_IDS)` 放宽为 `z.string()`——
9
9
  * 词汇校验移谓词、经 contracts 动态解析取 RESOURCE_TYPE_IDS(比静态 enum 更忠实应用版本);
10
- * - demand meta additive:serviceNeedContribSchematitle?/description?(服务展示元数据,
10
+ * - demand meta additive:serviceConsumeContribSchemaname?/description?(服务展示元数据,
11
11
  * manifest demand 侧 additive 扩展,catalog 聚合顺带携带——api.md ServiceDemand 对齐);
12
12
  * - 安全钉子(H9b):provider 名与 instance id 进凭据 stem 派生,字符集 pattern
13
13
  * `/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/` 为第一道防线(stem 派生处另有断言防线——纵深防御)。
14
+ *
15
+ * v6 声明面翻转(integrations v6 所有权模型):
16
+ * - `contributes` → `declare`(声明/行为分离——owns/consumes 语义对仗);
17
+ * - `declare.services` → `declare.consumes`(无向"服务" → 消费关系,多对多);
18
+ * - += `declare.owns`:薄数组(strictObject 单键——互斥事实无元数据;元数据恒在
19
+ * consumes 防双数组漂移)。服务归属唯一真源;双 owner = walk OWNERSHIP_CONFLICT;
20
+ * - 旧键 `contributes` / `declare.services`:parseModuleDescriptor 定向检测(N1——
21
+ * 报错含三路径升级指引,拒 loose 静默兜底)。
22
+ *
23
+ * v7 词汇统一(标识/展示名分轴,对齐实例轴 DeploymentInstance {id, name}):
24
+ * - 根键 `name` → `id`(标识键:唯一、寻址);根键 `title` → `name`(展示名:中文、可选);
25
+ * - `declare.consumes[].title` → `name`(demand meta 同步跟随);
26
+ * - 旧键 parseModuleDescriptor 定向检测(legacy? 标志——walk 据此拒 loose 兜底、
27
+ * CLI sync 据此拒装配改写)。
14
28
  */
15
29
 
16
30
  /** 输入字符集(安全钉子①):provider 名 / instanceId 恒经此 pattern(进凭据 stem 派生的输入) */
@@ -39,7 +53,7 @@ export const moduleDependencySchema = z.object({
39
53
  required: z.boolean().default(true),
40
54
  });
41
55
 
42
- /** provider 供给槽声明(integrations v2:contributes.providers.slots 元素;
56
+ /** provider 供给槽声明(integrations v2:declare.providers.slots 元素;
43
57
  * provider = 厂商名(catalog 嵌套第一轴)、implementation = 'id@version'(第二轴)) */
44
58
  export const providerSlotContribSchema = z.object({
45
59
  service: z.string(),
@@ -51,8 +65,8 @@ export const providerSlotContribSchema = z.object({
51
65
  credentialSchema: z.string().optional(),
52
66
  });
53
67
 
54
- /** 服务需求槽声明(contributes.services 元素;业务模块声明消费——catalog 需求侧聚合源) */
55
- export const serviceNeedContribSchema = z.object({
68
+ /** 服务消费槽声明(declare.consumes 元素;业务模块声明消费——catalog 需求侧聚合源) */
69
+ export const serviceConsumeContribSchema = z.object({
56
70
  service: z.string(),
57
71
  optional: z.boolean().default(true),
58
72
  defaults: z
@@ -64,11 +78,19 @@ export const serviceNeedContribSchema = z.object({
64
78
  )
65
79
  .default([]),
66
80
  // demand meta additive(api.md ServiceDemand):服务展示元数据,缺席 UI 回退 service id
67
- title: z.string().optional(),
81
+ // (v7 词汇统一:title → name)
82
+ name: z.string().optional(),
68
83
  description: z.string().optional(),
69
84
  });
70
85
 
71
- /** 资源需求声明(contributes.resources 元素;type 放宽为 string——词汇校验移谓词经 resolver 取词表) */
86
+ /** 服务归属声明(declare.owns 元素;v6 薄形状——互斥事实无元数据,strict 单键防双数组漂移) */
87
+ export const serviceOwnContribSchema = z
88
+ .object({
89
+ service: z.string(),
90
+ })
91
+ .strict();
92
+
93
+ /** 资源需求声明(declare.resources 元素;type 放宽为 string——词汇校验移谓词经 resolver 取词表) */
72
94
  export const resourceNeedContribSchema = z.object({
73
95
  id: z.string(),
74
96
  type: z.string(),
@@ -77,7 +99,11 @@ export const resourceNeedContribSchema = z.object({
77
99
  export const moduleDescriptorSchema = z
78
100
  .object({
79
101
  schemaVersion: z.number().default(1),
80
- name: z.string(),
102
+ // v7 词汇统一(标识/展示名分轴):id = 标识键(唯一、寻址,键 = install id 规约形态);
103
+ // name = 展示名(中文、可选)——回退归视图层(name ?? id),schema 不灌值
104
+ id: z.string(),
105
+ name: z.string().optional(),
106
+ description: z.string().optional(),
81
107
  version: z.string().default('0.0.0'),
82
108
  kind: z.enum(['platform', 'business', 'third-party']).default('business'),
83
109
  risk: z
@@ -91,7 +117,7 @@ export const moduleDescriptorSchema = z
91
117
  defaultMode: z.enum(['hybrid', 'sdk', 'codegen', 'local']).default('codegen'),
92
118
  })
93
119
  .default({}),
94
- contributes: z
120
+ declare: z
95
121
  .object({
96
122
  handlers: z.array(z.string()).default([]),
97
123
  tools: z.array(z.string()).default([]),
@@ -104,7 +130,8 @@ export const moduleDescriptorSchema = z
104
130
  slots: z.array(providerSlotContribSchema).default([]),
105
131
  })
106
132
  .default({}),
107
- services: z.array(serviceNeedContribSchema).default([]),
133
+ owns: z.array(serviceOwnContribSchema).default([]),
134
+ consumes: z.array(serviceConsumeContribSchema).default([]),
108
135
  resources: z.array(resourceNeedContribSchema).default([]),
109
136
  })
110
137
  .default({}),
@@ -120,14 +147,63 @@ export const moduleDescriptorSchema = z
120
147
  export type ModuleDescriptor = z.infer<typeof moduleDescriptorSchema>;
121
148
  export type CardContrib = z.infer<typeof cardContribSchema>;
122
149
  export type ProviderSlotContrib = z.infer<typeof providerSlotContribSchema>;
123
- export type ServiceNeedContrib = z.infer<typeof serviceNeedContribSchema>;
150
+ export type ServiceConsumeContrib = z.infer<typeof serviceConsumeContribSchema>;
151
+ export type ServiceOwnContrib = z.infer<typeof serviceOwnContribSchema>;
124
152
  export type ResourceNeedContrib = z.infer<typeof resourceNeedContribSchema>;
125
153
 
126
154
  export type ParseModuleResult =
127
155
  | { ok: true; value: ModuleDescriptor }
128
- | { ok: false; errors: string[] };
156
+ | { ok: false; errors: string[]; legacy?: true };
157
+
158
+ /** 旧键检测(N1):命中 → 定向错误(含三路径升级指引),不走 loose 静默兜底。
159
+ * v6 分支:声明面翻转键(contributes / declare.services);v7 分支:词汇统一翻转键
160
+ * (标识 `name`→`id`、展示名 `title`→`name`)。doctor descriptor-schema 规则以错误文本
161
+ * 「已更名」嗅探透传 OLD_MANIFEST_KEY——新增分支消息必须保持该词。 */
162
+ function legacyManifestKeys(raw: unknown): string[] {
163
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return [];
164
+ const errors: string[] = [];
165
+ const obj = raw as Record<string, unknown>;
166
+ if ('contributes' in obj) {
167
+ errors.push(
168
+ '(root): manifest 旧键 `contributes` 已更名 `declare`(v6 声明面)——' +
169
+ 'codegen 副本经 `module update --source` 重新生成 / sdk 模式升级模块包 / 手改两键',
170
+ );
171
+ }
172
+ const declare = obj.declare;
173
+ if (declare && typeof declare === 'object' && !Array.isArray(declare)
174
+ && 'services' in (declare as Record<string, unknown>)) {
175
+ errors.push(
176
+ 'declare: manifest 旧键 `declare.services` 已更名 `declare.consumes`(消费关系定向化)——' +
177
+ '同上三路径升级',
178
+ );
179
+ }
180
+ // v7 词汇统一(标识/展示名分轴):`name`→`id`(标识)、`title`→`name`(展示)。
181
+ // 判据以 `id` 在场性消解同名键歧义:无 id 有 name = v6 旧态;有 id 有 title = 半迁移。
182
+ if (!('id' in obj) && 'name' in obj) {
183
+ errors.push(
184
+ '(root): manifest 标识键 `name` 已更名 `id`(v7 词汇统一)——' +
185
+ 'codegen 副本经 `module update --source` 重新生成 / sdk 模式升级模块包 / 手改两键',
186
+ );
187
+ }
188
+ const declareObj = declare && typeof declare === 'object' && !Array.isArray(declare)
189
+ ? (declare as Record<string, unknown>)
190
+ : undefined;
191
+ const consumeHasTitle = Array.isArray(declareObj?.consumes)
192
+ && (declareObj.consumes as unknown[]).some(
193
+ (c) => c !== null && typeof c === 'object' && 'title' in (c as Record<string, unknown>),
194
+ );
195
+ if ('title' in obj || consumeHasTitle) {
196
+ errors.push(
197
+ '(root): manifest 展示名键 `title` 已更名 `name`(v7 词汇统一;declare.consumes[].title 同步改 name)——'
198
+ + '同上三路径升级',
199
+ );
200
+ }
201
+ return errors;
202
+ }
129
203
 
130
204
  export function parseModuleDescriptor(raw: unknown): ParseModuleResult {
205
+ const legacy = legacyManifestKeys(raw);
206
+ if (legacy.length > 0) return { ok: false, errors: legacy, legacy: true };
131
207
  const result = moduleDescriptorSchema.safeParse(raw);
132
208
  if (result.success) return { ok: true, value: result.data };
133
209
  return {
package/src/dto.ts CHANGED
@@ -3,6 +3,11 @@
3
3
  * agtcodingbox / tbox-ai-coding 经 `import type` 消费(L2 DTO 单源——API 层零类型镜像)。
4
4
  * 词汇七概念:app / module / service / instance / provider / integration / resolution。
5
5
  * 弃用词汇清单见 api.md §3 尾(component/slot/scope/configMode/…——防复活)。
6
+ *
7
+ * **v7 词汇统一破例声明(一次性收敛,此后恢复 additive-only)**:标识/展示名分轴
8
+ * (id = 标识、name = 展示名、description = 描述——对齐实例轴 {id, name}),
9
+ * title 键全量退役(与 manifest name→id/title→name 同一变更);`.title` 消费方
10
+ * (外部仓 import type / 运行时读)需同窗迁移。
6
11
  */
7
12
 
8
13
  // ===== 词汇基线 =====
@@ -30,17 +35,16 @@ export interface ModulesView {
30
35
  export interface ModuleDeclaration {
31
36
  /** install id(packages/ 目录名 / .tbox/app.json entry.id)——恒业务模块(provider 家族不在本清单) */
32
37
  id: string;
33
- /** 包名 */
38
+ /** 展示名(v7 词汇统一:manifest name ?? id——恒有值) */
34
39
  name: string;
35
- title: string;
36
40
  description: string;
37
41
  }
38
42
 
39
43
  /** 服务需求声明(模块 demand 单元 / 平台服务条目——v4.4 D29 双端点同型;defaults 唯一落位 ServiceDetail) */
40
44
  export interface ServiceDemand {
41
45
  service: string;
42
- /** manifest demand meta;缺席 UI 回退 service id */
43
- title?: string;
46
+ /** manifest demand meta(v7 title→name);缺席 UI 回退 service id */
47
+ name?: string;
44
48
  description?: string;
45
49
  /** demand optional === false(多模块 OR 聚合见 resolution echo;平台服务条目恒 false) */
46
50
  required: boolean;
@@ -50,40 +54,44 @@ export interface ServiceDemand {
50
54
 
51
55
  /** GET /modules/:module(模块静态一站式 · PUT 读对偶) */
52
56
  export interface ModuleDetailView {
53
- /** v4.4 D34:demand 服务首段去重(排序;1..N;零域 = []) */
54
- domainKeys: string[];
55
- /** domains[换算键] 节点原值;未配置 = null;v4.4 D34:仅单域(writable)时在场——多域/零域/共享键无单键落点 */
57
+ /** 模块展示名(v7 词汇统一:manifest name ?? id——恒有值) */
58
+ name: string;
59
+ /** B1 additive:模块 meta 描述(manifest description;兜底 '') */
60
+ description: string;
61
+ /** v6 所有权模型:模块归属服务(declare.owns 展平,排序;零归属 = [])——
62
+ * v5 domainKeys 退役(破坏性更名;面板 presence-detection 双读义务见 api.md §3) */
63
+ ownedServices: string[];
64
+ /** modules[install id] 集成位原值(provider/config;resources 不投影);未配置 = null */
56
65
  integration: ModuleIntegrationNode | null;
57
- /** v4.4 D34:每域一条厂商绑定解析(单域 = 单元素;零域 = [];resolveDomainBinding 单源) */
58
- providerBindings: ProviderBinding[];
59
- /** v4.4 D34:单域 && 域键无跨模块共享(moduleDomainWritable 单源——读标志与写守卫共用) */
66
+ /** v6 单数化(v5 providerBindings[] 退役):模块级厂商绑定解析(resolveModuleBinding 单源;
67
+ * 单值作用于全部 ownedServices) */
68
+ binding: ModuleBinding | null;
69
+ /** v6:owns.length > 0(moduleOwnershipWritable 单源——读标志与写守卫共用) */
60
70
  configEditable: boolean;
61
- /** 本模块 demand(卡片展开 + 编辑器静态上下文自足) */
71
+ /** 本模块 demand(declare.consumes;卡片展开 + 编辑器静态上下文自足) */
62
72
  services: ServiceDemand[];
63
73
  /** v4.4 D31:include=serviceResolutions 内嵌(demand 服务过滤 ≡ 批量 ?service= 语义;<0.9/形态异常 → null——永不 503) */
64
74
  serviceResolutions?: ServiceResolutionsView | null;
65
- /** v4.4 D32:include=integrationSchemas 层级富化(多域/零域/共享键/未绑定 → null) */
75
+ /** v4.4 D32:include=integrationSchemas 层级富化(零归属/未绑定 → null) */
66
76
  integrationSchemas?: LayerIntegrationSchemas | null;
67
77
  /** v4.6 D36:include=integrationFieldRegistry 集成字段注册表(null 语义镜像 integrationSchemas;
68
78
  * 未知厂商/零足迹 → 非 null 空集 + unsupplied 回填——D37 轴参假想计算同此) */
69
79
  integrationFieldRegistry?: IntegrationFieldRegistryView | null;
70
80
  }
71
81
 
72
- /** 模块域厂商绑定解析(v4.4 D34——静态文件事实;规则 ≡ 谓词 #7 域级,resolveDomainBinding 单源) */
73
- export interface ProviderBinding {
74
- /** 域键(= domainKeys 成员;多域模块每域一条) */
75
- domain: string;
76
- /** domains[domain].provider ?? root.provider(双缺 = null) */
77
- effective: string | null;
82
+ /** 模块级厂商绑定解析(v6——静态文件事实;规则 ≡ 谓词 #7 模块层,resolveModuleBinding 单源) */
83
+ export interface ModuleBinding {
84
+ /** modules[install id].provider ?? root.provider(双缺 = null) */
85
+ provider: string | null;
78
86
  /** 生效来源层(双缺 = null) */
79
87
  layer: 'module' | 'app' | null;
80
88
  }
81
89
 
82
90
  /** 层级 config schema 计算(v4.4 D32——静态轴富化,零 contracts) */
83
91
  export interface LayerIntegrationSchemas {
84
- /** 层生效厂商(resolveDomainBinding 单源) */
92
+ /** 层生效厂商(resolveModuleBinding 单源) */
85
93
  provider: string;
86
- /** 模块级 = 本模块 demand ∩ 该厂商供给;应用级 = 供给足迹全量(configSchema = raw draft 2020-12 原文;供给在场未声明 = null) */
94
+ /** 模块级 = 本模块 ownedServices ∩ 该厂商供给;应用级 = 供给足迹全量(configSchema = raw draft 2020-12 原文;供给在场未声明 = null) */
87
95
  services: Record<string, { configSchema: object | null }>;
88
96
  }
89
97
 
@@ -98,13 +106,16 @@ export interface IntegrationFieldRegistryView {
98
106
  unsupplied: string[];
99
107
  /** 作用域内全部非 null schema 的 additionalProperties 均 ≠ false(聚合;空真) */
100
108
  additionalPropertiesAllowed: boolean;
101
- /** 逐 key 合并产物(首声明插入序 = scope 遍历序:app 字母序 / module demand 序) */
109
+ /** 逐 key 合并产物(首声明插入序 = scope 遍历序:app 字母序 / module ownedServices 序) */
102
110
  fields: Array<{
103
111
  key: string;
104
112
  /** null = 类型不可调和(R3/R2 异构/R1 enum 不等——冲突折叠,客户端 RawJson 保真) */
105
113
  schema: object | null;
106
114
  /** required 聚合 = sources.some(s => s.required);conflict 字段照常聚合 */
107
115
  sources: Array<{ service: string; required: boolean }>;
116
+ /** G 批:x-tbox-global 聚合旗标(sources.some——任一来源声明即 true;app/module 轴表单
117
+ * 仅渲染 true 字段,非全局键落 ExtraFields;service 轴全量透传) */
118
+ global: boolean;
108
119
  }>;
109
120
  }
110
121
 
@@ -135,12 +146,15 @@ export interface ServiceDetail extends ServiceDemand {
135
146
  /** v4.7 D38:include=integrationSchemas 生效绑定富化(三态:null 全链未绑定 /
136
147
  * 绑定无可计算 schema / 含 schema;malformed 节点 → null——不放行域级联) */
137
148
  integrationSchemas?: ServiceIntegrationSchemas | null;
149
+ /** G 批:include=integrationFieldRegistry 服务轴注册表(loadServiceFieldRegistry——
150
+ * 四分支链推导复用 D38;fields = 该 schema 全部字段带 global 旗标;null 语义镜像 D38) */
151
+ integrationFieldRegistry?: IntegrationFieldRegistryView | null;
138
152
  }
139
153
 
140
154
  /** 服务级生效绑定 schema(v4.7 D38 静态轴富化——零 contracts,永不 503;实例层无条件排除:
141
155
  * node 级口径 ≠ resolution 默认实例口径,api.md §4.4 注) */
142
156
  export interface ServiceIntegrationSchemas {
143
- /** 生效厂商:显式(含内联声明名)?? domains[首段].provider ?? root.provider */
157
+ /** 生效厂商:显式(含内联声明名)?? modules[ownerOf].provider ?? root.provider */
144
158
  provider: string;
145
159
  /** catalog 复合键(多 impl 声明序首个)> 内联 ref;miss(未知厂商/未供给/内联缺 ref)→ null(富化非门控) */
146
160
  configSchema: object | null;
@@ -207,8 +221,8 @@ export interface AppIntegrationNode {
207
221
  }
208
222
 
209
223
  /** AppIntegrationNode 键集单源(runtime const——write applyApp 全量替换白名单
210
- * (缺席根键删除;services/domains/modules 域不在其中)+ views/app 投影(GET 预填 ≡ PUT body,
211
- * D21/L1——文件含 services/domains 但 root 节点投影只含本键集)) */
224
+ * (缺席根键删除;services/modules 域不在其中;v6 domains 键退役)+ views/app 投影
225
+ * (GET 预填 ≡ PUT body,D21/L1——文件含 services/modules 但 root 节点投影只含本键集)) */
212
226
  export const APP_INTEGRATION_NODE_KEYS = [
213
227
  'provider',
214
228
  'config',
@@ -219,12 +233,17 @@ export const APP_INTEGRATION_NODE_KEYS = [
219
233
  'defaultInstanceId',
220
234
  ] as const;
221
235
 
222
- /** 模块域节点(恒字符串 provider——域层无凭据位,契约事实) */
236
+ /** 模块集成位节点(v6——provider 绑定默认 + config 级联层;resources 不投影不写——
237
+ * 集成位编辑恒保全资源节,N2) */
223
238
  export interface ModuleIntegrationNode {
224
239
  provider?: string;
225
240
  config?: Record<string, unknown>;
226
241
  }
227
242
 
243
+ /** ModuleIntegrationNode 可写键集单源(v6——write applyModule 全量替换白名单
244
+ * (键集外 400;resources 恒随既有节点保全)+ views/modules 投影(GET ≡ PUT,三同构)) */
245
+ export const MODULE_INTEGRATION_NODE_KEYS = ['provider', 'config'] as const;
246
+
228
247
  /** services[s] 整节点 */
229
248
  export interface ServiceIntegrationNode {
230
249
  /** 对象 = 自定义 API(仅槽级,P2) */
@@ -287,6 +306,9 @@ export interface ProviderEntry {
287
306
  local: boolean;
288
307
  /** 供给声明来源包名 */
289
308
  owner: string;
309
+ /** 厂商展示名(v7 title→name:manifest name——多包首声明;缺席 = undefined) */
310
+ name?: string;
311
+ description?: string;
290
312
  }
291
313
 
292
314
  /** GET /providers/:provider:供给足迹 */
@@ -294,12 +316,18 @@ export interface ProviderDetail {
294
316
  provider: string;
295
317
  local: boolean;
296
318
  owner: string;
319
+ /** 厂商展示名(同 ProviderEntry——首声明透传) */
320
+ name?: string;
321
+ description?: string;
297
322
  /** per (provider, service) 保真,同厂商异构合法;★ implementations 恒数组(H1——
298
323
  * 多元素 = 升级窗口,UI 出 impl 选择器,PUT 显式钉版) */
299
324
  services: Record<
300
325
  string,
301
326
  {
302
327
  implementations: Array<{ implementation: string; credentialType: string }>;
328
+ /** 服务展示名(resolveServiceDisplay——词汇 > demand > id;恒发) */
329
+ name?: string;
330
+ description?: string;
303
331
  /** v4.4 F5:include=integrationSchemas 切换态批量(纯 config——凭据结构归 /credential-types) */
304
332
  integrationSchemas?: { configSchema: object | null };
305
333
  }
package/src/factory.ts CHANGED
@@ -19,9 +19,10 @@ import { loadModulesView, loadModuleDetailView } from './views/modules.js';
19
19
  import { loadAppView } from './views/app.js';
20
20
  import { loadServiceDetailView } from './views/service-detail.js';
21
21
  import { loadServiceResolutionsView, loadServiceResolutionDetail } from './views/service-resolutions.js';
22
- import { loadAppFormViews, loadModuleFormViews, loadServiceIntegrationSchemas } from './views/integration-schemas.js';
22
+ import { loadAppFormViews, loadModuleFormViews, loadServiceIntegrationSchemas, loadServiceFieldRegistry } from './views/integration-schemas.js';
23
23
  import { loadCredentialsView } from './views/credentials.js';
24
24
  import { loadCredentialTypesView } from './views/credential-types.js';
25
+ import { resolveModuleKey, resolveServiceKey } from './assembly/resolve-key.js';
25
26
  import type { WalkManifestsResult } from './assembly/walk-manifests.js';
26
27
  import type {
27
28
  AppIntegrationNode,
@@ -67,12 +68,13 @@ export interface AppToolkitOptions {
67
68
 
68
69
  /** include 协议白名单(v4.4 D30/P15——键名 = 产出字段名 1:1;per 端点;注册表 additive-only;
69
70
  * v4.6 D36 += integrationFieldRegistry:app/module 三键,provider 轴不加——YAGNI;
70
- * v4.7 D38 += service 键——服务级生效绑定 schema) */
71
+ * v4.7 D38 += service 键——服务级生效绑定 schema
72
+ * G 批 += service 轴 integrationFieldRegistry——服务轴注册表(x-tbox-global 旗标全量透传)) */
71
73
  const INCLUDE_WHITELIST = {
72
74
  app: ['serviceResolutions', 'integrationSchemas', 'integrationFieldRegistry'],
73
75
  module: ['serviceResolutions', 'integrationSchemas', 'integrationFieldRegistry'],
74
76
  provider: ['integrationSchemas'],
75
- service: ['integrationSchemas'],
77
+ service: ['integrationSchemas', 'integrationFieldRegistry'],
76
78
  } as const;
77
79
 
78
80
  /** include 校验(P15 单点在 toolkit 方法内——壳层仅解析可重复参数,零校验纪律不变):
@@ -113,10 +115,13 @@ function assertAxisProviderUsable(
113
115
  }
114
116
  }
115
117
 
116
- /** ── HTTP 直通面(11 读;L1 镜像律:方法名 = load + URL 资源段;query → 选项字段 L4)── */
118
+ /** ── HTTP 直通面(11 读;L1 镜像律:方法名 = load + URL 资源段;query → 选项字段 L4)──
119
+ * **双键契约(v7 词汇统一)**:资源路径参数双键寻址(id 优先、唯一展示名兜底——resolve-key
120
+ * 单点;多命中 404 带候选);query 过滤参数(loadServiceResolutions services?)恒 id-only。 */
117
121
  export interface AppToolkitRead {
118
122
  loadModules(): Promise<ModulesView>;
119
- /** v4.6 D37:moduleProvider = 轴向假想绑定(缺席/空串 ≡ 按实际配置解析;需与表单 include 键同现) */
123
+ /** v4.6 D37:moduleProvider = 轴向假想绑定(缺席/空串 ≡ 按实际配置解析;需与表单 include 键同现)。
124
+ * moduleId = 双键(id 优先、唯一展示名兜底)。 */
120
125
  loadModule(moduleId: string, o?: { include?: string[]; moduleProvider?: string }): Promise<ModuleDetailView>;
121
126
  /** v4.6 D37:appProvider = 轴向假想绑定(缺席/空串 ≡ 按实际配置解析;需与表单 include 键同现) */
122
127
  loadApp(o?: { include?: string[]; appProvider?: string }): Promise<AppView>;
@@ -132,7 +137,8 @@ export interface AppToolkitRead {
132
137
  loadCredentialTypes(provider?: string): Promise<CredentialTypesView>;
133
138
  }
134
139
 
135
- /** ── HTTP 直通面(4 写;body ≡ 文件节点全量替换;DELETE 无 dryRun/无 options)── */
140
+ /** ── HTTP 直通面(4 写;body ≡ 文件节点全量替换;DELETE 无 dryRun/无 options)──
141
+ * 双键契约(v7):路径键双键寻址(写侧 enqueue 闭包内解析——落盘键恒真实 id)。 */
136
142
  export interface AppToolkitWrite {
137
143
  writeAppIntegration(
138
144
  node: AppIntegrationNode,
@@ -174,11 +180,20 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
174
180
 
175
181
  const viewCtx = { appDir, cache };
176
182
 
177
- /** 门控断言(policy at edge)——strictValidation false → 503(message 三分支 N1) */
183
+ /** 门控断言(policy at edge)——strictValidation false → 503(message 三分支 N1);
184
+ * v6 标记门(P1):ownershipBindingV6 false → 503 第四分支(v5 contracts + v6 toolkit 偏斜
185
+ * ——防静默忽略 ownerOf;门控范围 = 求值 + 写 + migrate 全体,本函数为唯一调用点)。 */
178
186
  function assertContractsUsable(contracts: ResolvedContracts): void {
179
187
  if (!contracts.strictValidation) {
180
188
  throw new AppToolkitError('CONTRACTS_NOT_RESOLVED', 503, contractsNotResolvedMessage(contracts));
181
189
  }
190
+ if (!contracts.ownershipBindingV6) {
191
+ throw new AppToolkitError(
192
+ 'CONTRACTS_NOT_RESOLVED',
193
+ 503,
194
+ `contracts ${contracts.version ?? '(版本未知)'} 不支持 v6 modules 绑定形状(OWNERSHIP_BINDING_V6 标记缺席)——升级应用 @tbox.cn/app-contracts 依赖后可用`,
195
+ );
196
+ }
182
197
  }
183
198
 
184
199
  /** 快照(同步——调用方已 await resolveContracts) */
@@ -186,6 +201,12 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
186
201
  return loadViewSnapshotSync(viewCtx, contracts);
187
202
  }
188
203
 
204
+ /** 服务双键解析的已配置键集(integrations services 节键——宽松形态防御式提取) */
205
+ function configuredServiceKeys(snap: ReturnType<typeof snapshot>): string[] {
206
+ const services = (snap.integrations as { services?: Record<string, unknown> } | null)?.services;
207
+ return services && typeof services === 'object' ? Object.keys(services) : [];
208
+ }
209
+
189
210
  /** 谓词全量 issues(求值轴/写后复查共用——contracts 注入 + buildPredicateAssembly 单源装配,FX-2b:
190
211
  * 与 CLI doctor 规则同装配面——「面板 issues ≡ doctor issues」机制保证) */
191
212
  async function predicateIssues(): Promise<IntegrationServiceIssue[]> {
@@ -196,7 +217,6 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
196
217
  const predicateContracts: PredicateContracts = {
197
218
  resolveEffectiveService: assertFn(contracts.module.resolveEffectiveService, 'resolveEffectiveService'),
198
219
  buildSupplyLookup: assertFn(contracts.module.buildSupplyLookup, 'buildSupplyLookup'),
199
- moduleDomainOf: assertFn(contracts.module.moduleDomainOf, 'moduleDomainOf'),
200
220
  normalizeInstances: assertFn(contracts.module.normalizeInstances, 'normalizeInstances'),
201
221
  RESOURCE_TYPE_IDS: (contracts.module.RESOURCE_TYPE_IDS ?? []) as readonly string[],
202
222
  };
@@ -234,7 +254,9 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
234
254
  assertAxisProviderUsable('moduleProvider', o?.moduleProvider, include); // ①' D37 轴参严检(先于 404)
235
255
  const contracts = await resolveContractsForApp(appDir);
236
256
  const snap = snapshot(contracts);
237
- const view = loadModuleDetailView(snap, moduleId); // MODULE_NOT_FOUND
257
+ // 双键寻址(v7 词汇统一):路径参数 id 优先、唯一展示名兜底 真实 id(404 面)
258
+ const mod = resolveModuleKey(snap.walk, moduleId);
259
+ const view = loadModuleDetailView(snap, mod.id);
238
260
  if (include.has('serviceResolutions')) {
239
261
  view.serviceResolutions = contracts.evaluation && contracts.strictValidation
240
262
  ? await predicateIssues().then((issues) =>
@@ -243,7 +265,7 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
243
265
  }
244
266
  if (include.has('integrationSchemas') || include.has('integrationFieldRegistry')) {
245
267
  // v4.6 D37:表单层双投影同源一次计算(双取单算 + I1——假想重定向天然同步)
246
- const form = loadModuleFormViews(snap, moduleId, o?.moduleProvider);
268
+ const form = loadModuleFormViews(snap, mod.id, o?.moduleProvider);
247
269
  if (include.has('integrationSchemas')) view.integrationSchemas = form.integrationSchemas;
248
270
  if (include.has('integrationFieldRegistry')) view.integrationFieldRegistry = form.integrationFieldRegistry;
249
271
  }
@@ -268,13 +290,19 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
268
290
  return view;
269
291
  },
270
292
  // v4.7 D38:include 镜像 loadModule 三段式——① 输入校验 400 先于 404 ② 视图 ③ 静态富化(永不 503)
293
+ // G 批:service 轴 += integrationFieldRegistry(loadServiceFieldRegistry——D38 四分支链复用)
271
294
  async loadService(service: string, o?: { include?: string[] }): Promise<ServiceDetail> {
272
295
  const include = validateInclude('service', o?.include);
273
296
  const contracts = await resolveContractsForApp(appDir);
274
297
  const snap = snapshot(contracts); // 单快照——detail 与 include 装配共享
275
- const view = loadServiceDetailView(snap, service);
298
+ // 双键寻址(v7):id 优先、唯一展示名兜底 真实 service id(404 面)
299
+ const serviceId = resolveServiceKey(snap.walk, configuredServiceKeys(snap), service);
300
+ const view = loadServiceDetailView(snap, serviceId);
276
301
  if (include.has('integrationSchemas')) {
277
- view.integrationSchemas = loadServiceIntegrationSchemas(snap, service);
302
+ view.integrationSchemas = loadServiceIntegrationSchemas(snap, serviceId);
303
+ }
304
+ if (include.has('integrationFieldRegistry')) {
305
+ view.integrationFieldRegistry = loadServiceFieldRegistry(snap, serviceId);
278
306
  }
279
307
  return view;
280
308
  },
@@ -287,8 +315,10 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
287
315
  async loadServiceResolution(service: string) {
288
316
  const contracts = await resolveContractsForApp(appDir);
289
317
  assertContractsUsable(contracts);
318
+ const snap = snapshot(contracts);
319
+ const serviceId = resolveServiceKey(snap.walk, configuredServiceKeys(snap), service);
290
320
  const issues = await predicateIssues();
291
- return loadServiceResolutionDetail(service, snapshot(contracts), issues);
321
+ return loadServiceResolutionDetail(serviceId, snap, issues);
292
322
  },
293
323
  async loadProviders() {
294
324
  const contracts = await resolveContractsForApp(appDir);
@@ -301,7 +331,10 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
301
331
  },
302
332
  async loadProviderService(provider: string, service: string) {
303
333
  const contracts = await resolveContractsForApp(appDir);
304
- return loadProviderServiceDetailView(snapshot(contracts), provider, service);
334
+ const snap = snapshot(contracts);
335
+ // 服务轴双键寻址(provider 轴不兜底——厂商键即词汇)
336
+ const serviceId = resolveServiceKey(snap.walk, configuredServiceKeys(snap), service);
337
+ return loadProviderServiceDetailView(snap, provider, serviceId);
305
338
  },
306
339
  // v4.4 D33:凭据域双端点(应用状态轴 / 供给轴静态——零门控零求值,永不 503)
307
340
  async loadCredentials(): Promise<CredentialsView> {
@@ -330,19 +363,31 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
330
363
  await core.warmup();
331
364
  const contracts = await resolveContractsForApp(appDir);
332
365
  assertContractsUsable(contracts);
333
- return enqueue(() => core.applyModule(moduleId, node as Record<string, unknown>, o));
366
+ // enqueue 闭包内双键解析(写时新鲜度)——落盘键恒真实 id
367
+ return enqueue(() => {
368
+ const mod = resolveModuleKey(snapshot(contracts).walk, moduleId);
369
+ return core.applyModule(mod.id, node as Record<string, unknown>, o);
370
+ });
334
371
  },
335
372
  async writeServiceIntegration(service: string, node: ServiceIntegrationNode, o?: WriteOptions) {
336
373
  await core.warmup();
337
374
  const contracts = await resolveContractsForApp(appDir);
338
375
  assertContractsUsable(contracts);
339
- return enqueue(() => core.applyService(service, node as Record<string, unknown>, o));
376
+ return enqueue(() => {
377
+ const snap = snapshot(contracts);
378
+ const serviceId = resolveServiceKey(snap.walk, configuredServiceKeys(snap), service);
379
+ return core.applyService(serviceId, node as Record<string, unknown>, o);
380
+ });
340
381
  },
341
382
  async deleteServiceIntegration(service: string) {
342
383
  await core.warmup();
343
384
  const contracts = await resolveContractsForApp(appDir);
344
385
  assertContractsUsable(contracts);
345
- return enqueue(() => core.deleteService(service));
386
+ return enqueue(() => {
387
+ const snap = snapshot(contracts);
388
+ const serviceId = resolveServiceKey(snap.walk, configuredServiceKeys(snap), service);
389
+ return core.deleteService(serviceId);
390
+ });
346
391
  },
347
392
  };
348
393
 
@@ -385,7 +430,6 @@ export function createAppToolkit(appDir: string, options: AppToolkitOptions = {}
385
430
  const predicateContracts: PredicateContracts = {
386
431
  resolveEffectiveService: assertFn(contracts.module.resolveEffectiveService, 'resolveEffectiveService'),
387
432
  buildSupplyLookup: assertFn(contracts.module.buildSupplyLookup, 'buildSupplyLookup'),
388
- moduleDomainOf: assertFn(contracts.module.moduleDomainOf, 'moduleDomainOf'),
389
433
  normalizeInstances: assertFn(contracts.module.normalizeInstances, 'normalizeInstances'),
390
434
  RESOURCE_TYPE_IDS: (contracts.module.RESOURCE_TYPE_IDS ?? []) as readonly string[],
391
435
  };
package/src/index.ts CHANGED
@@ -10,14 +10,16 @@ export {
10
10
  tabContribSchema,
11
11
  moduleDependencySchema,
12
12
  providerSlotContribSchema,
13
- serviceNeedContribSchema,
13
+ serviceConsumeContribSchema,
14
+ serviceOwnContribSchema,
14
15
  resourceNeedContribSchema,
15
16
  } from './core/module-schema.js';
16
17
  export type {
17
18
  ModuleDescriptor,
18
19
  CardContrib,
19
20
  ProviderSlotContrib,
20
- ServiceNeedContrib,
21
+ ServiceConsumeContrib,
22
+ ServiceOwnContrib,
21
23
  ResourceNeedContrib,
22
24
  ParseModuleResult,
23
25
  } from './core/module-schema.js';
@@ -56,16 +58,22 @@ export type {
56
58
  // ── 谓词装配单源(FX-2b/F1:CLI doctor 规则与 toolkit 工厂同装配面——双通道 walkManifests)──
57
59
  export { buildPredicateAssembly, refToEnvKey } from './integrations/predicate-io.js';
58
60
  export type { PredicateAssembly, PredicateIoInputs } from './integrations/predicate-io.js';
61
+ // ── 应用级求值单源(cli-remove-prune-and-new:doctor integration-services 与 prune 同一求值)──
62
+ export { evaluateAppIntegrationIssues } from './integrations/evaluate-app.js';
63
+ export { pruneIntegrationBindings } from './integrations/prune-bindings.js';
64
+ export type { PruneResult } from './integrations/prune-bindings.js';
59
65
 
60
66
  // ── assembly 层(目录知识——walkManifests 四产物 + catalog 双形态 + 组合单体装配)──
61
67
  export { walkManifests } from './assembly/walk-manifests.js';
62
- export type { WalkManifestsResult, WalkModuleInfo, WalkCatalog, WalkProviderEntry } from './assembly/walk-manifests.js';
68
+ // 双键寻址(v7 词汇统一——factory 七方法入口单点消费的解析 helper;纯参数式零 IO)
69
+ export { resolveModuleKey, resolveServiceKey } from './assembly/resolve-key.js';
70
+ export type { WalkManifestsResult, WalkModuleInfo, WalkCatalog, WalkProviderEntry, DeclarationIssue, SlotMeta } from './assembly/walk-manifests.js';
63
71
  export { readAppManifest, writeAppManifest, manifestPath } from './assembly/app-manifest.js';
64
72
  export type { AppManifest, NpmModuleEntry, ModuleMode } from './assembly/app-manifest.js';
65
73
  export { loadProviderCatalog, loadProviderCatalogRaw } from './assembly/provider-catalog.js';
66
74
  export type { BridgeProviderCatalog, ProviderServiceSchemas, ProviderServiceSchemasResult } from './assembly/provider-catalog.js';
67
75
 
68
- // ── integrations 层(领域——读/写核心/凭据双工件/mock 绑定)──
76
+ // ── integrations 层(领域——读/写核心/凭据双工件/mock 绑定;v6 模块绑定单源)──
69
77
  export { readIntegrationsConfig, readIntegrationsStrict } from './integrations/read.js';
70
78
  export type { ReadIntegrationsResult } from './integrations/read.js';
71
79
  export { createWriteCore, deepEqual } from './integrations/write.js';
@@ -74,6 +82,9 @@ export { ensureMockBindings } from './integrations/mock-bindings.js';
74
82
  export type { MockBindingsResult } from './integrations/mock-bindings.js';
75
83
  export { reconcileOrphanCredentials, credentialArtifactExists } from './integrations/credentials.js';
76
84
  export type { AppliedCredential, CredentialInput, OrphanIssue, PlannedCredential } from './integrations/credentials.js';
85
+ // v6 所有权模型单源(module-binding——resolveModuleBinding/写守卫/归属表直通)
86
+ export { buildOwnershipMap, moduleOwnershipWritable, resolveModuleBinding, providerFootprint } from './integrations/module-binding.js';
87
+ export type { ModuleOwnershipWritability } from './integrations/module-binding.js';
77
88
 
78
89
  // ── 错误面(领域 6 码——AppToolkitError;name 字面量约定见 errors.ts)──
79
90
  export { AppToolkitError, contractsNotResolvedMessage } from './core/errors.js';
@@ -85,7 +96,7 @@ export { loadAppView } from './views/app.js';
85
96
  export { loadServiceDetailView } from './views/service-detail.js';
86
97
  export { loadProvidersView, loadProviderDetailView, loadProviderServiceDetailView } from './views/providers.js';
87
98
  export { loadServiceResolutionsView, loadServiceResolutionDetail, resolveServiceSummary } from './views/service-resolutions.js';
88
- export { loadAppIntegrationSchemas, loadModuleIntegrationSchemas, loadServiceIntegrationSchemas, resolveLayerIntegrationSchemas } from './views/integration-schemas.js';
99
+ export { loadAppIntegrationSchemas, loadModuleIntegrationSchemas, loadServiceIntegrationSchemas, loadServiceFieldRegistry, resolveLayerIntegrationSchemas, formProviderOf, buildIntegrationFieldRegistry } from './views/integration-schemas.js';
89
100
  export { echoForRef, loadCredentialsView } from './views/credentials.js';
90
101
  export { loadCredentialTypesView } from './views/credential-types.js';
91
102
  export type { ViewContext, ViewSnapshot } from './views/context.js';
@@ -102,10 +113,10 @@ export type {
102
113
  ModuleDeclaration,
103
114
  ServiceDemand,
104
115
  ModuleDetailView,
116
+ ModuleBinding,
105
117
  AppView,
106
118
  ServiceDetail,
107
119
  ServiceIntegrationSchemas,
108
- ProviderBinding,
109
120
  LayerIntegrationSchemas,
110
121
  IntegrationFieldRegistryView,
111
122
  CredentialsView,
@@ -132,7 +143,7 @@ export type {
132
143
  ContractsResolution,
133
144
  IntegrationIssue,
134
145
  } from './dto.js';
135
- export { APP_INTEGRATION_NODE_KEYS } from './dto.js';
146
+ export { APP_INTEGRATION_NODE_KEYS, MODULE_INTEGRATION_NODE_KEYS } from './dto.js';
136
147
  export {
137
148
  readAppManifestFull,
138
149
  upsertNpmModule,