export type PlatformActionParams = Readonly>; export type PlatformActionHandler = (context: TContext, params: PlatformActionParams) => Promise; /** 兼顾精确动作联合类型与动态字符串探测的只读集合。 */ export type PlatformActionSet = Omit, "has"> & { has(action: string): action is TAction; }; export interface PlatformActionRegistry { /** 由 handler 表生成的不可变动作集合。 */ readonly actions: PlatformActionSet; has(action: string): action is TAction; execute(context: TContext, action: string, params: PlatformActionParams): Promise; } export type PlatformActionParameterMap>> = { readonly [TAction in Extract]: readonly string[]; }; export interface PlatformActionContractErrors { unsupported(action: string): Error; unexpectedParameter(action: string, parameter: string): Error; } export type UnexpectedPlatformActionParameter = (action: string, parameter: string) => Error; type AnyPlatformActionHandler = PlatformActionHandler; type HandlerContext = T extends PlatformActionHandler ? TContext : never; type UnionToIntersection = (T extends unknown ? (value: T) => void : never) extends (value: infer TIntersection) => void ? TIntersection : never; type RegistryContext>> = UnionToIntersection>; /** * 用单一 handler 表同时驱动能力发现与执行。 * * 动作集合在运行时同样不可变,调用方不能绕过 ReadonlySet 类型修改注册结果。 */ export declare function definePlatformActions>>(handlers: THandlers, unsupported: (action: string) => Error): PlatformActionRegistry, Extract>; /** * 在单一 handler 表之上闭合平台动作的顶层参数契约。 * * 复杂官方请求体仍可作为一个参数无损透传;这里仅拒绝拼错、废弃或夹带的顶层字段。 * 参数集合在定义时编译并校验,避免每次执行临时创建 Set,也避免动作表与契约表漂移。 */ export declare function definePlatformActionContract>>(handlers: THandlers, parameters: PlatformActionParameterMap, errors: PlatformActionContractErrors): PlatformActionRegistry, Extract>; /** * 为可组合的 handler 子表编译顶层参数契约,并保留原始精确动作类型。 * * 适配器可先分别声明消息、内容、管理等领域动作,再把多个闭合子表合并进同一注册表。 */ export declare function definePlatformActionHandlers>>(handlers: THandlers, parameters: PlatformActionParameterMap, unexpectedParameter: UnexpectedPlatformActionParameter): THandlers; export {};