@tbox.cn/app-contracts 0.10.0 → 0.12.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.
@@ -2,18 +2,20 @@
2
2
  * 统一用户授权鉴权契约(006):身份 / Token / 换发 / 运行上下文。
3
3
  * TIER0 types-only(+ 错误码常量),双端共享:服务端签发/校验、客户端消费。
4
4
  *
5
- * 设计要点(006 §2 / D1-D4):
5
+ * 设计要点(006 §2 / D1-D4 + 2026-09 四源修订):
6
6
  * - 自有 JWT 唯一形态;外部一律内置换发(三态收敛),原始 token 嵌 `external` claim。
7
- * - userId 命名(006 D4 修订):local/dev 由模板生成,前缀 local_/dev_;**external 原样保留
8
- * (外部系统自管命名空间,不加前缀/不归一化)**;anonymous 服务端生成、不签发 JWT。
7
+ * - userId 命名:local/guest 由平台生成,强制前缀 local_/guest_(guest = 服务端随机访客身份,
8
+ * `guest_<32hex>`);**external 原样保留(外部系统自管命名空间,不加前缀/不归一化)**;
9
+ * anonymous 服务端生成、不签发 JWT。
10
+ * - 身份唯一服务端决定:客户端不产生身份(会话 β 前提)。
9
11
  * - RequestContext 单一运行上下文(identity + conversationId + credentials + attributes),
10
12
  * 显式通道读取(0.11.0 上下文统一化:handle 第四参 / 工具 execute 第二参读取器——ctx.auth 已拆除)。
11
13
  */
12
- export type UserIdSource = 'local' | 'external' | 'dev' | 'anonymous';
14
+ export type UserIdSource = 'local' | 'external' | 'guest' | 'anonymous';
13
15
  export interface Identity {
14
- /** 全局唯一 userId,四前缀命名空间(见文件头) */
16
+ /** 全局唯一 userId(local_/guest_ 强制前缀;external 原样;anonymous 不签发) */
15
17
  userId: string;
16
- /** 来源(主区分;local/external/dev 都可能带名字与头像) */
18
+ /** 来源(主区分;local/external/guest 都可能带名字与头像) */
17
19
  source: UserIdSource;
18
20
  displayName?: string;
19
21
  avatar?: string;
@@ -59,30 +61,44 @@ export interface RequestContext {
59
61
  attributes?: Record<string, unknown>;
60
62
  }
61
63
  /**
62
- * 换码器接口:code → ExchangeResult(identity + 可选外部凭据)。
64
+ * 换发请求(0.11.0 对象化,append-only 永久扩展点):
65
+ * - 新字段恒可选;实现方宽容未知字段(禁全量校验,只取所需键);
66
+ * - previousIdentity:previousToken 已验签的上一身份(续签轨;code 轨透传——mock 换码器
67
+ * 复用身份,真实厂商忽略,authCode 即真相)。
68
+ */
69
+ export interface ExchangeRequest {
70
+ /** 授权码(必填;browser 轨不经过本接口) */
71
+ code: string;
72
+ /** 换码路由键(缺省 'alipay';registry 按 provider 键 + scoped 谓词路由) */
73
+ platform?: string;
74
+ /** 域中性业务上下文槽位(对齐 HelloEvent.context 先例:消费方自定键,TIER0 零领域语义) */
75
+ context?: Readonly<Record<string, unknown>>;
76
+ /** 已验签的上一身份(续签透传;实现方可选消费) */
77
+ previousIdentity?: Identity;
78
+ }
79
+ /**
80
+ * 换码器接口:ExchangeRequest → ExchangeResult(identity + 可选外部凭据)。
63
81
  * 本地实现(支付宝/微信)与外部实现(ExternalIdentityExchange)均实现本接口。
64
82
  */
65
83
  export interface IdentityExchange {
66
84
  readonly provider: string;
67
- /**
68
- * code → ExchangeResult。
69
- * @param context 域中性业务上下文槽位(对齐 HelloEvent.context 先例:消费方自定键,TIER0 零领域语义;
70
- * 路由层保证 plain object 且体积约束,实现方可宽松读取所需键)
71
- */
72
- exchangeByCode(code: string, platform?: string, context?: Readonly<Record<string, unknown>>): Promise<ExchangeResult>;
85
+ /** 换发(对象化请求;调用方保证 code 必填、context 归一化 plain object) */
86
+ exchangeByCode(request: ExchangeRequest): Promise<ExchangeResult>;
73
87
  }
74
88
  export declare const AUTH_ERROR_CODES: {
75
89
  /** 401:凭证缺失/非法 */
76
90
  readonly UNAUTHORIZED: "AUTH_UNAUTHORIZED";
77
91
  /** 401:token 过期(客户端应重登录后重试) */
78
92
  readonly TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED";
79
- /** 403:身份不足以执行(匿名写操作 / dev-login 关闭等) */
93
+ /** 403:身份不足以执行(匿名写操作等) */
80
94
  readonly FORBIDDEN: "AUTH_FORBIDDEN";
81
- /** 403:dev-login 在生产/关闭态被禁 */
82
- readonly DEV_LOGIN_DISABLED: "AUTH_DEV_LOGIN_DISABLED";
95
+ /** 400:登录请求缺 method 判别('code'|'browser') */
96
+ readonly METHOD_REQUIRED: "AUTH_METHOD_REQUIRED";
97
+ /** 403:browser 轴被禁(off 档 / prod mock 档 / auto 无可用形态) */
98
+ readonly BROWSER_LOGIN_DISABLED: "AUTH_BROWSER_LOGIN_DISABLED";
83
99
  /** 502:外部 provider 错误 */
84
100
  readonly EXTERNAL_ERROR: "AUTH_EXTERNAL_ERROR";
85
- /** 503:密钥链缺失(prod fail-fast) */
101
+ /** 503:密钥链缺失(prod fail-fast)/ 登录槽配置缺失(显式 mock 档无物料) */
86
102
  readonly MISSING_SECRET: "AUTH_MISSING_SECRET";
87
103
  };
88
104
  export type AuthErrorCode = (typeof AUTH_ERROR_CODES)[keyof typeof AUTH_ERROR_CODES];
@@ -10,6 +10,13 @@ type RunScopedErrorEvent = RunErrorEvent & {
10
10
  threadId?: string;
11
11
  runId?: string;
12
12
  };
13
+ /**
14
+ * 会话未建立严格拒绝(会话 β):连接无当前会话时收到 RUN → 本错误终态(不自动修复、
15
+ * 不静默建会话——协议不变量「无会话即拒」,防不落库审计绕过)。
16
+ */
17
+ type RunNotEstablishedErrorEvent = RunErrorEvent & {
18
+ code: 'CONVERSATION_NOT_ESTABLISHED';
19
+ };
13
20
  /**
14
21
  * 工具执行失败终态(2026-09-03 tool-error 断链修复):
15
22
  * - isError: true 标记该 RESULT 为错误终态(模型路径工具 execute 抛错 / 模块工具
@@ -23,7 +30,7 @@ type ToolCallResultErrorEvent = ToolCallResultEvent & {
23
30
  errorMessage?: string;
24
31
  };
25
32
  /** 所有服务端 → 客户端事件 */
26
- export type ServerEvent = RunStartedEvent | RunFinishedEvent | RunScopedErrorEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultErrorEvent | ReasoningStartEvent | ReasoningMessageStartEvent | ReasoningMessageContentEvent | ReasoningMessageEndEvent | ReasoningEndEvent | StateSnapshotEvent | StateDeltaEvent | CustomEvent
33
+ export type ServerEvent = RunStartedEvent | RunFinishedEvent | RunScopedErrorEvent | RunNotEstablishedErrorEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultErrorEvent | ReasoningStartEvent | ReasoningMessageStartEvent | ReasoningMessageContentEvent | ReasoningMessageEndEvent | ReasoningEndEvent | StateSnapshotEvent | StateDeltaEvent | CustomEvent
27
34
  /** HELLO 鉴权成功应答(011 F4) */
28
35
  | HelloAckEvent
29
36
  /** 传输层业务保活(双向对称;连接级事件,无身份/顺序语义) */
@@ -35,15 +42,14 @@ export interface SendMessageMediaItem {
35
42
  mimeType?: string;
36
43
  }
37
44
  /**
38
- * 客户端 → 服务端会话键:conversationId 是唯一会话键(006 D5,运行+持久化统一)。
39
- * - 有会话(local/external/dev):携带 /api/conversation/create 返回的 conversationId;
40
- * - 匿名(optional 模式,未签发 JWT、不可建会话):缺省该字段,服务端按连接级
41
- * fallback 键(连接级身份 + 本轮 run)处理,不落库。
45
+ * 客户端 → 服务端会话键(会话 β 改造):conversationId 从客户端协议面退役——
46
+ * 会话由服务端建立(NEW/RESUME)并绑定为连接当前会话,运行/持久化/取消恒取连接当前会话。
47
+ * 历史字段保留一个发布周期(@deprecated ignore 化):服务端一律忽略,客户端不提供即不可伪造。
42
48
  */
43
49
  export interface SendMessageEvent {
44
50
  type: 'SEND_MESSAGE';
45
51
  content: string;
46
- /** 会话 ID(唯一会话键,运行 + 持久化统一);匿名对话可缺省 */
52
+ /** @deprecated 会话 β:服务端恒取连接当前会话,本字段忽略(一个发布周期后删除) */
47
53
  conversationId?: string;
48
54
  /** 用户上传的媒体文件(仅携带 fileId,SDK 直传后的引用) */
49
55
  mediaItems?: SendMessageMediaItem[];
@@ -52,11 +58,24 @@ export interface SendMessageEvent {
52
58
  }
53
59
  export interface CancelRunEvent {
54
60
  type: 'CANCEL_RUN';
55
- /** 会话 ID(同 SEND_MESSAGE.conversationId);匿名对话可缺省(服务端按连接最近 run 定位) */
61
+ /** @deprecated 会话 β:服务端恒取连接当前会话,本字段忽略(一个发布周期后删除) */
56
62
  conversationId?: string;
57
63
  /** 当前 runId,用于避免迟到的取消事件误取消同会话的下一轮回答 */
58
64
  runId?: string;
59
65
  }
66
+ /**
67
+ * 会话建立指令(会话 β:「不提供即不可伪造」——conversationId 从客户端协议面整体退役):
68
+ * - NEW_CONVERSATION:bootstrap 恒发。服务端建新会话(防御性取消在飞 run)并绑定为
69
+ * 连接当前会话;失败走 notice 通道。无 ACK——串行队列已保序(后续 RUN 恒晚于本事件处理)。
70
+ * - RESUME_CONVERSATION:同页重连续接。服务端 getOrCreate(连接身份) 绑定连接当前会话。
71
+ * - 裸 RUN 无会话 → RUN_ERROR{code:'CONVERSATION_NOT_ESTABLISHED'} 严格拒绝(不自动修复)。
72
+ */
73
+ export interface NewConversationEvent {
74
+ type: 'NEW_CONVERSATION';
75
+ }
76
+ export interface ResumeConversationEvent {
77
+ type: 'RESUME_CONVERSATION';
78
+ }
60
79
  /**
61
80
  * WS 连接握手事件。客户端在 onOpen 时发送一次,**只做鉴权**(006 D6/D12):
62
81
  * - 携带自有 JWT(消息体传输,不拼 URL,防泄漏);
@@ -147,7 +166,7 @@ export type UiClientAction = {
147
166
  };
148
167
  export interface UiActionEvent {
149
168
  type: 'UI_ACTION';
150
- /** 会话 ID(同 SEND_MESSAGE.conversationId) */
169
+ /** @deprecated 会话 β:服务端恒取连接当前会话,本字段忽略(一个发布周期后删除) */
151
170
  conversationId?: string;
152
171
  /** 卡片实例 id(协议字段名沿用历史 surfaceId) */
153
172
  surfaceId: string;
@@ -155,7 +174,7 @@ export interface UiActionEvent {
155
174
  /** submitForm 时携带的表单数据(由 client React 卡片构造) */
156
175
  formData?: Record<string, unknown>;
157
176
  }
158
- export type ClientEvent = SendMessageEvent | CancelRunEvent | UiActionEvent | HelloEvent | PingEvent | PongEvent;
177
+ export type ClientEvent = SendMessageEvent | CancelRunEvent | UiActionEvent | NewConversationEvent | ResumeConversationEvent | HelloEvent | PingEvent | PongEvent;
159
178
  /** 保活漏检上限:timeout = intervalMs × KEEPALIVE_MISS_LIMIT(对齐 nextAuthFailState 的 max=3 惯例) */
160
179
  export declare const KEEPALIVE_MISS_LIMIT = 3;
161
180
  export type KeepaliveAction = 'none' | 'ping' | 'dead';
@@ -158,14 +158,17 @@ export interface ConfiguredService {
158
158
  instances?: Record<string, ServiceInstanceConfig>;
159
159
  }
160
160
  /**
161
- * 模块域全局配置(键 = 槽位域前缀,moduleDomainOf 派生;域 ≠ 模块名——auth 域由登录链消费)。
162
- * 域 ≠ 部署边界:单应用单厂商部署门禁不因 domains 表达力放开(混绑 die 原样)。
161
+ * 模块资源配置(integrations v6:modules 节 = 模块集成位——provider 绑定默认 + config
162
+ * 级联层 + v5 资源节三键合一;键 = install id(.tbox/app.json entry.id / packages/ 目录名;
163
+ * 仓内家族包恒等 manifest name 属规约)。provider/config 至少其一(空节点无意义)。
163
164
  */
164
- export interface DomainConfig {
165
- /** 域级默认厂商(implementation 恒派生——域层无精确绑定语义) */
165
+ export interface ModuleConfig {
166
+ /** 模块级默认厂商(v6 绑定组继承层——作用于该模块 declare.owns 的全部服务槽) */
166
167
  provider?: string;
167
- /** 域级共享配置(该域全部槽合并进 config 级联,与绑定来源层无关) */
168
+ /** 模块级共享配置(config 五层级联第三层:root ByInstance 之后、slot 之前) */
168
169
  config?: Record<string, unknown>;
170
+ /** resourceId → 类型化资源声明(resourceId 词汇真源 = 模块 manifest declare.resources) */
171
+ resources?: Record<string, ResourceSpec>;
169
172
  }
170
173
  /**
171
174
  * 部署实例(业务主体拓扑条目;root instances 注册表元素——v4 参考表)。
@@ -213,15 +216,12 @@ export interface IntegrationsConfig {
213
216
  credentialRef?: string;
214
217
  /** 部署级 per-instance 默认凭据表(键 = instanceId;商户级凭据主写位) */
215
218
  credentialRefByInstance?: Record<string, string>;
216
- /** 模块域全局层(键 = moduleDomainOf(service);无 ByInstance——全链唯一 ByInstance 层恒 root) */
217
- domains?: Record<string, DomainConfig>;
218
219
  /** 部署实例注册表(参考表);缺席 = 无参考表;空数组非法(zod 拒——无表 = 键缺席唯一写法) */
219
220
  instances?: DeploymentInstance[];
220
221
  /** 默认实例 id(单实例免填;∈instances ids;无表时独立在场 = 动态默认形态) */
221
222
  defaultInstanceId?: string | null;
222
- /** 模块资源绑定(v5 新轴——与 domains 正交:domains = provider 绑定默认,modules = 资源绑定;
223
- * 键 = install id(.tbox/app.json entry.id / packages/ 目录名;仓内家族包恒等 manifest name 属规约);
224
- * 无 per-instance 层(扩展位词汇预选 resourcesByInstance——instances 词恒属 services 激活语义) */
223
+ /** 模块集成位(v6:provider 绑定默认 + config 级联层 + v5 资源节三键合一;
224
+ * 顶层 domains 键已退役——旧键经 zod 防线拒收并指引 migrate 至 modules[owner]) */
225
225
  modules?: Record<string, ModuleConfig>;
226
226
  services: Record<string, ConfiguredService>;
227
227
  }
@@ -229,7 +229,7 @@ export interface IntegrationsConfig {
229
229
  export interface EffectiveService {
230
230
  provider: string | InlineVendorDeclaration;
231
231
  implementation: string;
232
- /** 五层浅合并一层:root.config → root.configByInstance[k] → domain.config → slot.config → inst.config */
232
+ /** 五层浅合并一层:root.config → root.configByInstance[k] → modules[owner].config → slot.config → inst.config */
233
233
  config: Readonly<Record<string, unknown>>;
234
234
  credentialRef?: string;
235
235
  }
@@ -252,26 +252,40 @@ export type EffectiveServiceResolution = {
252
252
  * ('*' 字面量与 doctor 谓词文件内联一致;语义由双侧包测试交叉锁死。)
253
253
  */
254
254
  export declare const WILDCARD_INSTANCE_KEY = "*";
255
- /** 槽位域前缀(domains 键控轴):首个点号前段;无点号取整串。域 ≠ 模块名(auth 域由登录链消费)。 */
255
+ /**
256
+ * integrations v6 形状标记:resolveEffectiveService 接受 ownerOf 第五参、modules 节承载
257
+ * provider/config(模块所有权模型)。app-toolkit assertContractsUsable 经出口在场性探测
258
+ * 本标记——v5 contracts + v6 toolkit 偏斜组合 → 503 第四分支(P1 标记门;防静默忽略 ownerOf)。
259
+ */
260
+ export declare const OWNERSHIP_BINDING_V6: true;
261
+ /**
262
+ * 槽位域前缀(首个点号前段;无点号取整串)。**v6 起退出级联**(modules[ownerOf] 取代
263
+ * domains 键控)——保留导出仅供词汇组织用途(guard/doctor 诊断消息按域聚合展示)。
264
+ * 域 ≠ 模块名(auth 域由登录链消费);归属语义唯一真源 = 模块 manifest declare.owns。
265
+ * @deprecated 级联键控已退役(v6 ownership 模型);新消费方禁用——归属查询走 ownerOf。
266
+ */
256
267
  export declare function moduleDomainOf(service: string): string;
257
268
  /** 派生查表(buildSupplyLookup 产物):键 `${provider}\u0000${service}` → implementation 清单('id@version')。 */
258
269
  export type SupplyLookup = Record<string, readonly string[]>;
259
270
  /**
260
271
  * 级联细则(一句话:层序优先于 scope 特异度;层内 per-instance 胜标量):
261
- * - 绑定组(provider + implementation):最特异层整组取(inst > slot > domain > root)——
272
+ * - 绑定组(provider + implementation):最特异层整组取(inst > slot > modules[owner] > root)——
262
273
  * 独立 `??` 继承会产生跨层非法组合(inst.provider=wanda + 继承 slot 的 joycity impl),
263
274
  * 故组不可拆;组内 implementation 缺席 → supplies 派生(唯一命中;
264
275
  * 零命中/歧义/未注入查表 → binding-unresolved);双字段显式在场 = 显式即真值(不派生,
265
276
  * 存量全显式文件零影响)。内联声明仅槽级且必带 implementation(防御分支兜底)。
266
- * - config 五层浅合并:root.config → root.configByInstance[k] → domain.config → slot.config →
267
- * inst.config(service 标量胜 root ByInstance[k]——层序优先于 scope 特异度;
268
- * domain.config 恒参与该域全部槽,与绑定来源层无关)
277
+ * - ownerOf(v6):service → moduleId 归属表(buildOwnershipMap 产物,装配期显式注入)。
278
+ * 服务无主 → 跳过 modules 层(≡ 平台槽语义);ownerOf 缺席且文件含 modules 级
279
+ * 绑定/配置 → binding-unresolved fail-visible(装配偏斜防线——防静默丢模块层语义)。
280
+ * - config 五层浅合并:root.config → root.configByInstance[k] → modules[owner].config →
281
+ * slot.config → inst.config(service 标量胜 root ByInstance[k]——层序优先于 scope 特异度;
282
+ * modules[owner].config 恒参与该模块 owns 全部服务槽,与绑定来源层无关)
269
283
  * - credentialRef:inst ?? slot ?? root.credentialRefByInstance[k] ?? root.credentialRef(v3 零改动;
270
- * domain 层无 credentialRef——链位预留 slot 后、root ByInstance 前)
284
+ * module 层无 credentialRef——链位预留 slot 后、root ByInstance 前)
271
285
  * 不抛领域错误;status 由 SDK registry 映射 PROVIDER_* 错误码
272
286
  * (binding-unresolved → PROVIDER_BINDING_UNRESOLVED;hasProviderBinding 点查 status !== 'ok' → false)。
273
287
  */
274
- export declare function resolveEffectiveService(integrations: IntegrationsConfig, service: string, instanceId: string, supplies?: SupplyLookup): EffectiveServiceResolution;
288
+ export declare function resolveEffectiveService(integrations: IntegrationsConfig, service: string, instanceId: string, supplies?: SupplyLookup, ownerOf?: Record<string, string>): EffectiveServiceResolution;
275
289
  /**
276
290
  * root 部署实例注册表归一化(v4 wire → 消费形态单源):
277
291
  * - instances 缺席 = 空表(无参考表——wanda 动态形态;空数组已在 zod 拒,此处纯防御);
@@ -282,7 +296,7 @@ export declare function resolveEffectiveService(integrations: IntegrationsConfig
282
296
  */
283
297
  export declare function normalizeInstances(config: Pick<IntegrationsConfig, 'instances' | 'defaultInstanceId'>): NormalizedInstances;
284
298
  /**
285
- * provider manifest 单槽供给声明(tbox.module.json contributes.providers.slots 元素)。
299
+ * provider manifest 单槽供给声明(tbox.module.json declare.providers.slots 元素)。
286
300
  * provider = 厂商名(= 档位名 = provider 包轴);implementation = 'id@version' 形态。
287
301
  */
288
302
  export interface ProviderManifestSlot {
@@ -320,7 +334,7 @@ export interface CatalogProviderEntry {
320
334
  /** 供给槽清单(service id) */
321
335
  services: string[];
322
336
  }
323
- /** catalog 需求侧聚合条目(模块 manifest contributes.services 元素聚合;services 键 = service id) */
337
+ /** catalog 需求侧聚合条目(模块 manifest declare.consumes 元素聚合;services 键 = service id) */
324
338
  export interface CatalogServiceEntry {
325
339
  /** 可选槽(未配置不 error——doctor warning 级) */
326
340
  optional: boolean;
@@ -367,8 +381,3 @@ export interface KnowledgeResourceSpec {
367
381
  }
368
382
  /** 资源声明(discriminated by type;SDK zod / CLI doctor / 未来 app-toolkit 共用 wire 形状) */
369
383
  export type ResourceSpec = KnowledgeResourceSpec;
370
- /** 模块资源配置(modules 节元素;strict 单字段——provider/config/instances 进 modules 即非法,防与 domains 双写位) */
371
- export interface ModuleConfig {
372
- /** resourceId → 类型化资源声明(resourceId 词汇真源 = 模块 manifest contributes.resources) */
373
- resources: Record<string, ResourceSpec>;
374
- }
package/dist/runtime.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  export { EventType } from '@ag-ui/core';
7
7
  export { TBOX_CARD_EVENT_NAME, TBOX_CARD_UPDATE_EVENT_NAME, TBOX_NOTICE_EVENT_NAME, } from './cards';
8
8
  export { AUTH_ERROR_CODES, authCodeToStatus } from './identity';
9
- export { stableSerializeScope, PROVIDER_ERROR_CODES, resolveEffectiveService, WILDCARD_INSTANCE_KEY, moduleDomainOf, buildSupplyLookup, normalizeInstances, isExpectedProviderAbsence, RESOURCE_TYPE_IDS, } from './providers';
9
+ export { stableSerializeScope, PROVIDER_ERROR_CODES, resolveEffectiveService, WILDCARD_INSTANCE_KEY, moduleDomainOf, buildSupplyLookup, normalizeInstances, isExpectedProviderAbsence, RESOURCE_TYPE_IDS, OWNERSHIP_BINDING_V6, } from './providers';
10
10
  export { parseIntegrationsConfig } from './integrations-config';
11
11
  export { assertNoInlineSecrets } from './no-inline-secrets';
12
12
  export { defineContextSlot } from './context-slot';
package/dist/runtime.js CHANGED
@@ -12,13 +12,15 @@ var AUTH_ERROR_CODES = {
12
12
  UNAUTHORIZED: "AUTH_UNAUTHORIZED",
13
13
  /** 401:token 过期(客户端应重登录后重试) */
14
14
  TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED",
15
- /** 403:身份不足以执行(匿名写操作 / dev-login 关闭等) */
15
+ /** 403:身份不足以执行(匿名写操作等) */
16
16
  FORBIDDEN: "AUTH_FORBIDDEN",
17
- /** 403:dev-login 在生产/关闭态被禁 */
18
- DEV_LOGIN_DISABLED: "AUTH_DEV_LOGIN_DISABLED",
17
+ /** 400:登录请求缺 method 判别('code'|'browser') */
18
+ METHOD_REQUIRED: "AUTH_METHOD_REQUIRED",
19
+ /** 403:browser 轴被禁(off 档 / prod mock 档 / auto 无可用形态) */
20
+ BROWSER_LOGIN_DISABLED: "AUTH_BROWSER_LOGIN_DISABLED",
19
21
  /** 502:外部 provider 错误 */
20
22
  EXTERNAL_ERROR: "AUTH_EXTERNAL_ERROR",
21
- /** 503:密钥链缺失(prod fail-fast) */
23
+ /** 503:密钥链缺失(prod fail-fast)/ 登录槽配置缺失(显式 mock 档无物料) */
22
24
  MISSING_SECRET: "AUTH_MISSING_SECRET"
23
25
  };
24
26
  function authCodeToStatus(code) {
@@ -27,8 +29,10 @@ function authCodeToStatus(code) {
27
29
  case AUTH_ERROR_CODES.TOKEN_EXPIRED:
28
30
  return 401;
29
31
  case AUTH_ERROR_CODES.FORBIDDEN:
30
- case AUTH_ERROR_CODES.DEV_LOGIN_DISABLED:
32
+ case AUTH_ERROR_CODES.BROWSER_LOGIN_DISABLED:
31
33
  return 403;
34
+ case AUTH_ERROR_CODES.METHOD_REQUIRED:
35
+ return 400;
32
36
  case AUTH_ERROR_CODES.EXTERNAL_ERROR:
33
37
  return 502;
34
38
  case AUTH_ERROR_CODES.MISSING_SECRET:
@@ -74,6 +78,7 @@ function isExpectedProviderAbsence(e) {
74
78
  return code === PROVIDER_ERROR_CODES.SERVICE_NOT_CONFIGURED || code === PROVIDER_ERROR_CODES.INSTANCE_NOT_FOUND || code === PROVIDER_ERROR_CODES.INSTANCE_DISABLED;
75
79
  }
76
80
  var WILDCARD_INSTANCE_KEY = "*";
81
+ var OWNERSHIP_BINDING_V6 = true;
77
82
  function moduleDomainOf(service) {
78
83
  const i = service.indexOf(".");
79
84
  return i === -1 ? service : service.slice(0, i);
@@ -81,20 +86,33 @@ function moduleDomainOf(service) {
81
86
  function unresolved(service, instanceId, detail) {
82
87
  return { status: "binding-unresolved", message: `${service}@${instanceId}\uFF1A${detail}` };
83
88
  }
84
- function resolveEffectiveService(integrations, service, instanceId, supplies) {
89
+ function hasModuleBindingNodes(integrations) {
90
+ return Object.values(integrations.modules ?? {}).some(
91
+ (m) => m.provider != null || m.config != null
92
+ );
93
+ }
94
+ function resolveEffectiveService(integrations, service, instanceId, supplies, ownerOf) {
85
95
  const slot = integrations.services[service];
86
96
  if (!slot) return { status: "service-not-configured" };
87
97
  const instances = slot.instances ?? { [WILDCARD_INSTANCE_KEY]: {} };
88
98
  const inst = instances[instanceId] ?? instances[WILDCARD_INSTANCE_KEY];
89
99
  if (!inst) return { status: "instance-not-found" };
90
100
  if (inst.enabled === false) return { status: "instance-disabled" };
91
- const domain = integrations.domains?.[moduleDomainOf(service)];
92
- const head = inst.provider != null ? { src: "instance", provider: inst.provider, impl: inst.implementation } : slot.provider != null ? { src: "slot", provider: slot.provider, impl: slot.implementation } : domain?.provider != null ? { src: "domain", provider: domain.provider, impl: void 0 } : integrations.provider != null ? { src: "root", provider: integrations.provider, impl: void 0 } : void 0;
101
+ if (ownerOf == null && hasModuleBindingNodes(integrations)) {
102
+ return unresolved(
103
+ service,
104
+ instanceId,
105
+ "integrations.json \u542B modules \u7EA7\u7ED1\u5B9A/\u914D\u7F6E\uFF0C\u4F46\u88C5\u914D\u671F\u672A\u6CE8\u5165 ownership map\uFF08buildOwnershipMap \u4EA7\u7269\u7ECF createIntegrationsRegistry ownerOf \u6CE8\u5165\uFF09\u2014\u2014\u5347\u7EA7\u88C5\u914D\u9762"
106
+ );
107
+ }
108
+ const owner = ownerOf?.[service];
109
+ const mod = owner != null ? integrations.modules?.[owner] : void 0;
110
+ const head = inst.provider != null ? { src: "instance", provider: inst.provider, impl: inst.implementation } : slot.provider != null ? { src: "slot", provider: slot.provider, impl: slot.implementation } : mod?.provider != null ? { src: "module", provider: mod.provider, impl: void 0 } : integrations.provider != null ? { src: "root", provider: integrations.provider, impl: void 0 } : void 0;
93
111
  if (!head) {
94
112
  return unresolved(
95
113
  service,
96
114
  instanceId,
97
- "\u65E0\u4EFB\u4F55\u5C42 provider \u58F0\u660E\uFF08root/domains/\u69FD\u7EA7/\u5B9E\u4F8B\u7EA7\uFF09\u2014\u2014\u914D\u7F6E\u7ED1\u5B9A\u6216 provider use \u8865\u58F0\u660E"
115
+ "\u65E0\u4EFB\u4F55\u5C42 provider \u58F0\u660E\uFF08root/modules/\u69FD\u7EA7/\u5B9E\u4F8B\u7EA7\uFF09\u2014\u2014\u914D\u7F6E\u7ED1\u5B9A\u6216 provider use \u8865\u58F0\u660E"
98
116
  );
99
117
  }
100
118
  let implementation = head.impl;
@@ -129,7 +147,7 @@ function resolveEffectiveService(integrations, service, instanceId, supplies) {
129
147
  const config = {
130
148
  ...integrations.config,
131
149
  ...integrations.configByInstance?.[instanceId] ?? {},
132
- ...domain?.config ?? {},
150
+ ...mod?.config ?? {},
133
151
  ...slot.config,
134
152
  ...inst.config
135
153
  };
@@ -190,12 +208,6 @@ var inlineVendorSchema = z.strictObject({
190
208
  credentialType: z.string().min(1),
191
209
  configSchema: z.string().optional()
192
210
  });
193
- var domainSchema = z.strictObject({
194
- provider: z.string().min(1).optional(),
195
- config: z.record(z.string(), z.unknown()).optional()
196
- }).refine((d) => d.provider !== void 0 || d.config !== void 0, {
197
- message: "\u57DF\u914D\u7F6E provider/config \u81F3\u5C11\u5176\u4E00"
198
- });
199
211
  var instanceSchema = z.strictObject({
200
212
  provider: z.string().optional(),
201
213
  implementation: z.string().optional(),
@@ -232,7 +244,11 @@ var resourceSpecSchema = z.discriminatedUnion("type", [knowledgeSpecSchema]).ref
232
244
  message: "knowledge \u8D44\u6E90 datasetId/ref \u81F3\u5C11\u5176\u4E00"
233
245
  });
234
246
  var moduleConfigSchema = z.strictObject({
235
- resources: z.record(z.string(), resourceSpecSchema)
247
+ provider: z.string().min(1).optional(),
248
+ config: z.record(z.string(), z.unknown()).optional(),
249
+ resources: z.record(z.string(), resourceSpecSchema).optional()
250
+ }).refine((m) => m.provider !== void 0 || m.config !== void 0 || m.resources !== void 0, {
251
+ message: "modules \u8282\u70B9 provider/config/resources \u81F3\u5C11\u5176\u4E00\uFF08\u7A7A\u8282\u70B9\u65E0\u610F\u4E49\u2014\u2014\u5220\u9664\u8BE5\u952E\uFF09"
236
252
  });
237
253
  var integrationsSchema = z.strictObject({
238
254
  provider: z.string().min(1).optional(),
@@ -240,7 +256,6 @@ var integrationsSchema = z.strictObject({
240
256
  configByInstance: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
241
257
  credentialRef: z.string().optional(),
242
258
  credentialRefByInstance: z.record(z.string(), z.string()).optional(),
243
- domains: z.record(z.string(), domainSchema).optional(),
244
259
  instances: z.array(deploymentInstanceSchema).optional(),
245
260
  defaultInstanceId: z.string().min(1).nullable().optional(),
246
261
  modules: z.record(z.string(), moduleConfigSchema).optional(),
@@ -281,19 +296,20 @@ var integrationsSchema = z.strictObject({
281
296
  });
282
297
  }
283
298
  });
284
- var LEGACY_BY_SCOPE_KEYS = ["configByScope", "credentialRefByScope"];
285
- function assertNoLegacyByScopeKeys(raw) {
299
+ var LEGACY_KEY_MESSAGES = {
300
+ configByScope: "\u8BF7\u66F4\u540D configByInstance\uFF08scope\u2192instance \u8BCD\u6C47\u76F4\u5207\uFF0C\u65E7\u952E\u4E0D\u518D\u63A5\u53D7\uFF09",
301
+ credentialRefByScope: "\u8BF7\u66F4\u540D credentialRefByInstance\uFF08scope\u2192instance \u8BCD\u6C47\u76F4\u5207\uFF0C\u65E7\u952E\u4E0D\u518D\u63A5\u53D7\uFF09",
302
+ domains: "v6 \u5DF2\u9000\u5F79\u2014\u2014\u5F52\u5C5E\u8BED\u4E49\u8FC1\u79FB\u81F3\u6A21\u5757 manifest declare.owns + modules[owner] \u96C6\u6210\u4F4D\uFF08provider migrate \u81EA\u52A8\u8FC1\u79FB\uFF0C\u6216\u624B\u6539\uFF1Adomains.<d> \u2192 modules[<ownerId>]\uFF09"
303
+ };
304
+ function assertNoLegacyKeys(raw) {
286
305
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return;
287
- const keys = Object.keys(raw);
288
- const legacy = keys.filter((k) => LEGACY_BY_SCOPE_KEYS.includes(k));
289
- if (legacy.length > 0) {
290
- throw new Error(
291
- `integrations.json \u542B 0.9.0 \u5DF2\u66F4\u540D\u5B57\u6BB5\uFF1A${legacy.join("\u3001")}\u2014\u2014\u8BF7\u66F4\u540D configByInstance / credentialRefByInstance\uFF08scope\u2192instance \u8BCD\u6C47\u76F4\u5207\uFF0C\u65E7\u952E\u4E0D\u518D\u63A5\u53D7\uFF09`
292
- );
306
+ for (const k of Object.keys(raw)) {
307
+ const msg = LEGACY_KEY_MESSAGES[k];
308
+ if (msg) throw new Error(`integrations.json \u542B\u5DF2\u9000\u5F79\u5B57\u6BB5\uFF1A${k}\u2014\u2014${msg}`);
293
309
  }
294
310
  }
295
311
  function parseIntegrationsConfig(raw) {
296
- assertNoLegacyByScopeKeys(raw);
312
+ assertNoLegacyKeys(raw);
297
313
  assertNoInlineSecrets(raw);
298
314
  return integrationsSchema.parse(raw);
299
315
  }
@@ -519,6 +535,7 @@ export {
519
535
  MEMORY_RECORD_PREVIEW_MAX_CHARS,
520
536
  MEMORY_REMINDER_ATTR,
521
537
  MEMORY_TOOL_CALL_NAME,
538
+ OWNERSHIP_BINDING_V6,
522
539
  PRE_TOOL_CALL_NAME,
523
540
  PRE_TOOL_NAME_PATTERN,
524
541
  PROVIDER_ERROR_CODES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-contracts",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "平台契约(TIER0,types-only 为主 + 协议常量运行时值):卡片协议 / SDK adapter / 平台 DTO。",
6
6
  "exports": {
@@ -29,6 +29,7 @@ exports[`integrations-config 迁移等价锁(C1-5) > P1 wanda 素材 parse
29
29
  "instances": {
30
30
  "*": {
31
31
  "config": {
32
+ "browserLogin": "<VAR>",
32
33
  "mockAuth": "<VAR>",
33
34
  "mockMemberId": "<VAR>",
34
35
  "mockOpenId": "<VAR>",
@@ -73,9 +73,20 @@ describe('integrations-config 迁移等价锁(C1-5)', () => {
73
73
  ).toThrow(/credentialRefByInstance/);
74
74
  });
75
75
 
76
+ it('P5b v6 顶层 domains 键退役 → 拒绝 + migrate 指引(集成位迁 modules[owner])', () => {
77
+ expect(() =>
78
+ parseIntegrationsConfig({
79
+ services: {},
80
+ domains: { member: { provider: 'wanda', config: { baseUrl: 'x' } } },
81
+ }),
82
+ ).toThrow(/modules\[<ownerId>\]/);
83
+ });
84
+
76
85
  it('P4 搬移完整性:assertNoInlineSecrets 与 parse 同源自 contracts 公开面', async () => {
77
86
  const mod = await import('../src/index');
78
87
  expect(typeof mod.parseIntegrationsConfig).toBe('function');
79
88
  expect(typeof mod.assertNoInlineSecrets).toBe('function');
89
+ // v6 形状标记(P1 标记门探测目标):出口在场性
90
+ expect(mod.OWNERSHIP_BINDING_V6).toBe(true);
80
91
  });
81
92
  });
@@ -215,9 +215,21 @@ describe('parseIntegrationsConfig v5:modules 节(资源绑定轴)', () =>
215
215
  expect(() => parseIntegrationsConfig(raw)).toThrow();
216
216
  });
217
217
 
218
- it('模块层混入 provider 键 → 拒(防与 domains 双写位)', () => {
218
+ it('模块层 provider 键合法(v6 反转:modules = 集成位——provider/config/resources 三键)', () => {
219
219
  const raw = withModules({ 'module-a': { resources: {}, provider: 'wanda' } });
220
- expect(() => parseIntegrationsConfig(raw)).toThrow();
220
+ const cfg = parseIntegrationsConfig(raw);
221
+ expect(cfg.modules?.['module-a']?.provider).toBe('wanda');
222
+ });
223
+
224
+ it('模块层 config 键合法(v6 级联第三层)', () => {
225
+ const raw = withModules({ 'module-a': { config: { baseUrl: 'https://x' } } });
226
+ const cfg = parseIntegrationsConfig(raw);
227
+ expect(cfg.modules?.['module-a']?.config).toEqual({ baseUrl: 'https://x' });
228
+ });
229
+
230
+ it('空节点拒(provider/config/resources 至少其一)', () => {
231
+ const raw = withModules({ 'module-a': {} });
232
+ expect(() => parseIntegrationsConfig(raw)).toThrow(/至少其一/);
221
233
  });
222
234
 
223
235
  it('模块层混入 instances 键 → 拒(词边界:instances 恒属 services 激活语义)', () => {
@@ -246,8 +258,7 @@ describe('parseIntegrationsConfig v5:modules 节(资源绑定轴)', () =>
246
258
  });
247
259
  });
248
260
 
249
- describe('assertNoInlineSecrets(011 L2 迁移;自 component-config.test.ts 移入)', () => {
250
- it('豁免集 credentialType/credentialRef/credentialVersion/credentialRefByInstance 不拒', () => {
261
+ describe('assertNoInlineSecrets(011 L2 迁移;自 component-config.test.ts 移入)', () => { it('豁免集 credentialType/credentialRef/credentialVersion/credentialRefByInstance 不拒', () => {
251
262
  expect(() =>
252
263
  assertNoInlineSecrets({
253
264
  providerInstances: [