UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

443 lines 21.5 kB
import { r as OpenClawConfig } from "./types.openclaw-BdCLfP4c.js"; import { Ht as ApprovalScope, Vt as CommandExplanationSummary, _ as PluginApprovalResolved, _t as ExecApprovalResolved, a as SystemAgentApprovalRequest, h as PluginApprovalRequest, ht as ExecApprovalRequest, i as SystemAgentApprovalApplicationStatus, mt as ExecApprovalDecision, n as ChannelApprovalKind, s as SystemAgentApprovalResolved, t as ApprovalRequestInput } from "./approval-types-ClyNB7BE.js"; import { h as MessagePresentationButton, p as MessagePresentationAction } from "./payload--vybxo02.js"; //#region src/channels/plugins/approval-native.types.d.ts /** * Native channel surface that can receive approval prompts. */ type ChannelApprovalNativeSurface = "origin" | "approver-dm"; /** * Native channel destination for an approval prompt. */ type ChannelApprovalNativeTarget = { to: string; threadId?: string | number | null; }; /** * Preferred native delivery surface for approval prompts. */ type ChannelApprovalNativeDeliveryPreference = ChannelApprovalNativeSurface | "both"; /** * Approval request shapes supported by native channel approval delivery. */ type ChannelApprovalNativeRequest = ExecApprovalRequest | PluginApprovalRequest | SystemAgentApprovalRequest; /** * Capabilities returned by native channel approval delivery inspection. */ type ChannelApprovalNativeDeliveryCapabilities = { enabled: boolean; preferredSurface: ChannelApprovalNativeDeliveryPreference; supportsOriginSurface: boolean; supportsApproverDmSurface: boolean; notifyOriginWhenDmOnly?: boolean; }; /** * Adapter implemented by channel plugins that support native approval delivery. */ type ChannelApprovalNativeAdapter = { describeDeliveryCapabilities: (params: { cfg: OpenClawConfig; accountId?: string | null; approvalKind: ChannelApprovalKind; request: ChannelApprovalNativeRequest; }) => ChannelApprovalNativeDeliveryCapabilities; resolveOriginTarget?: (params: { cfg: OpenClawConfig; accountId?: string | null; approvalKind: ChannelApprovalKind; request: ChannelApprovalNativeRequest; }) => ChannelApprovalNativeTarget | null | Promise<ChannelApprovalNativeTarget | null>; resolveApproverDmTargets?: (params: { cfg: OpenClawConfig; accountId?: string | null; approvalKind: ChannelApprovalKind; request: ChannelApprovalNativeRequest; }) => ChannelApprovalNativeTarget[] | Promise<ChannelApprovalNativeTarget[]>; }; //#endregion //#region src/infra/approval-native-delivery.d.ts type ApprovalRequest$1 = ExecApprovalRequest | PluginApprovalRequest | SystemAgentApprovalRequest; /** One native approval delivery target selected by the channel adapter plan. */ type ChannelApprovalNativePlannedTarget = { surface: ChannelApprovalNativeSurface; target: ChannelApprovalNativeTarget; reason: "preferred" | "fallback"; }; /** Complete native approval routing plan, including optional origin-chat notice state. */ type ChannelApprovalNativeDeliveryPlan = { targets: ChannelApprovalNativePlannedTarget[]; originTarget: ChannelApprovalNativeTarget | null; notifyOriginWhenDmOnly: boolean; }; /** Resolves the origin and approver-DM targets a channel should use for native approvals. */ declare function resolveChannelNativeApprovalDeliveryPlan(params: { cfg: OpenClawConfig; accountId?: string | null; approvalKind: ChannelApprovalKind; request: ApprovalRequest$1; adapter?: ChannelApprovalNativeAdapter | null; }): Promise<ChannelApprovalNativeDeliveryPlan>; //#endregion //#region src/infra/approval-native-runtime-types.d.ts /** Prepared delivery target plus the stable key used to avoid duplicate native messages. */ type PreparedChannelNativeApprovalTarget<TPreparedTarget> = { dedupeKey: string; target: TPreparedTarget; }; /** Channel hooks that prepare adapter targets and deliver pending approval content. */ type ChannelNativeApprovalTransportSpec<TPendingEntry, TPreparedTarget, TPendingContent, TRequest> = { prepareTarget: (params: { plannedTarget: ChannelApprovalNativePlannedTarget; request: TRequest; approvalKind: ChannelApprovalKind; pendingContent: TPendingContent; }) => PreparedChannelNativeApprovalTarget<TPreparedTarget> | null | Promise<PreparedChannelNativeApprovalTarget<TPreparedTarget> | null>; deliverTarget: (params: { plannedTarget: ChannelApprovalNativePlannedTarget; preparedTarget: TPreparedTarget; request: TRequest; approvalKind: ChannelApprovalKind; pendingContent: TPendingContent; }) => TPendingEntry | null | Promise<TPendingEntry | null>; }; /** Optional observer hooks for per-target native approval delivery outcomes. */ type ChannelNativeApprovalDeliveryCallbacks<TPendingEntry, TPreparedTarget, TPendingContent, TRequest> = { onDeliveryError?: (params: { error: unknown; plannedTarget: ChannelApprovalNativePlannedTarget; request: TRequest; approvalKind: ChannelApprovalKind; pendingContent: TPendingContent; }) => void; onDuplicateSkipped?: (params: { plannedTarget: ChannelApprovalNativePlannedTarget; preparedTarget: PreparedChannelNativeApprovalTarget<TPreparedTarget>; request: TRequest; approvalKind: ChannelApprovalKind; pendingContent: TPendingContent; }) => void; onDelivered?: (params: { plannedTarget: ChannelApprovalNativePlannedTarget; preparedTarget: PreparedChannelNativeApprovalTarget<TPreparedTarget>; request: TRequest; approvalKind: ChannelApprovalKind; pendingContent: TPendingContent; entry: TPendingEntry; }) => void; }; //#endregion //#region src/infra/approval-view-model.types.d.ts type ApprovalPhase = "pending" | "resolved" | "expired"; /** Button or command action shown with a pending approval prompt. */ type ApprovalActionView = { kind?: "command" | "decision"; decision: ExecApprovalDecision; label: string; style: NonNullable<MessagePresentationButton["style"]>; action?: MessagePresentationAction; /** Copyable command fallback for non-interactive surfaces. */ command: string; }; /** Label/value metadata row rendered with an approval prompt. */ type ApprovalMetadataView = { label: string; value: string; }; type ApprovalViewBase = { approvalId: string; approvalKind: ChannelApprovalKind; phase: ApprovalPhase; title: string; description?: string | null; metadata: ApprovalMetadataView[]; }; /** Shared presentation fields for exec approval views across all phases. */ type ExecApprovalViewBase = ApprovalViewBase & { approvalKind: "exec"; ask?: string | null; agentId?: string | null; warningText?: string | null; commandAnalysis?: CommandExplanationSummary | null; commandText: string; commandPreview?: string | null; cwd?: string | null; envKeys?: readonly string[]; host?: string | null; nodeId?: string | null; scope?: ApprovalScope | null; sessionKey?: string | null; }; /** Pending exec approval view, including executable reply actions. */ type ExecApprovalPendingView = ExecApprovalViewBase & { phase: "pending"; actions: ApprovalActionView[]; expiresAtMs: number; }; /** Resolved exec approval view with the recorded decision. */ type ExecApprovalResolvedView = ExecApprovalViewBase & { phase: "resolved"; decision: ExecApprovalDecision; resolvedBy?: string | null; }; /** Expired exec approval view without reply actions. */ type ExecApprovalExpiredView = ExecApprovalViewBase & { phase: "expired"; }; /** Shared presentation fields for plugin approval views across all phases. */ type PluginApprovalViewBase = ApprovalViewBase & { approvalKind: "plugin"; agentId?: string | null; pluginId?: string | null; scope?: ApprovalScope | null; toolName?: string | null; severity: "info" | "warning" | "critical"; }; /** Pending plugin approval view, including executable reply actions. */ type PluginApprovalPendingView = PluginApprovalViewBase & { phase: "pending"; actions: ApprovalActionView[]; expiresAtMs: number; }; /** Resolved plugin approval view with the recorded decision. */ type PluginApprovalResolvedView = PluginApprovalViewBase & { phase: "resolved"; decision: ExecApprovalDecision; resolvedBy?: string | null; }; /** Expired plugin approval view without reply actions. */ type PluginApprovalExpiredView = PluginApprovalViewBase & { phase: "expired"; }; /** Shared presentation fields for OpenClaw system change approvals. */ type SystemAgentApprovalViewBase = ApprovalViewBase & { approvalKind: "system-agent"; agentId?: string | null; scope?: null; commandText: string; commandPreview?: string | null; ask?: string | null; cwd?: string | null; envKeys?: readonly string[]; host?: string | null; nodeId?: string | null; sessionKey?: string | null; operationSummary: string; }; /** Pending system change approval view, including executable reply actions. */ type SystemAgentApprovalPendingView = SystemAgentApprovalViewBase & { phase: "pending"; actions: ApprovalActionView[]; expiresAtMs: number; }; /** Resolved system change approval view with the recorded decision. */ type SystemAgentApprovalResolvedView = SystemAgentApprovalViewBase & { phase: "resolved"; decision: ExecApprovalDecision; resolvedBy?: string | null; applicationStatus?: SystemAgentApprovalApplicationStatus; terminalStatus?: "expired" | "cancelled"; }; /** Expired system change approval view without reply actions. */ type SystemAgentApprovalExpiredView = SystemAgentApprovalViewBase & { phase: "expired"; }; /** Any pending approval view that still accepts a user decision. */ type PendingApprovalView = ExecApprovalPendingView | PluginApprovalPendingView | SystemAgentApprovalPendingView; /** Any approval view after a decision was recorded. */ type ResolvedApprovalView = ExecApprovalResolvedView | PluginApprovalResolvedView | SystemAgentApprovalResolvedView; /** Any approval view after it can no longer be acted on. */ type ExpiredApprovalView = ExecApprovalExpiredView | PluginApprovalExpiredView | SystemAgentApprovalExpiredView; /** Discriminated approval presentation model consumed by channel/UI renderers. */ type ApprovalViewModel = PendingApprovalView | ResolvedApprovalView | ExpiredApprovalView; //#endregion //#region src/infra/approval-handler-runtime-types.d.ts /** Backward-compatible approval request accepted by public plugin callbacks. */ type ApprovalRequest = ApprovalRequestInput; /** Union of approval resolution events a native approval handler can finalize. */ type ApprovalResolved = ExecApprovalResolved | PluginApprovalResolved | SystemAgentApprovalResolved; /** Shared context passed to channel-native approval hooks. */ type ChannelApprovalCapabilityHandlerContext = { cfg: OpenClawConfig; accountId?: string | null; gatewayUrl?: string; context?: unknown; }; /** Result instruction for updating, deleting, clearing, or leaving a delivered approval entry. */ type ChannelApprovalNativeFinalAction<TPayload> = { kind: "update"; payload: TPayload; } | { kind: "delete"; } | { kind: "clear-actions"; } | { kind: "leave"; }; /** Availability gate for deciding whether a channel-native approval runtime can handle work. */ type ChannelApprovalNativeAvailabilityAdapter = { isConfigured: (params: ChannelApprovalCapabilityHandlerContext) => boolean; shouldHandle: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; /** Payload-derived owner; channel adapters must not infer ownership from the id. */ approvalKind: ChannelApprovalKind; }) => boolean; }; /** Builds channel-native payloads for pending, resolved, and expired approval views. */ type ChannelApprovalNativePresentationAdapter<TPendingPayload = unknown, TFinalPayload = unknown> = { buildPendingPayload: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; approvalKind: ChannelApprovalKind; nowMs: number; view: PendingApprovalView; }) => TPendingPayload | Promise<TPendingPayload>; buildResolvedResult: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; resolved: ApprovalResolved; view: ResolvedApprovalView; entry: unknown; }) => ChannelApprovalNativeFinalAction<TFinalPayload> | Promise<ChannelApprovalNativeFinalAction<TFinalPayload>>; buildExpiredResult: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; view: ExpiredApprovalView; entry: unknown; }) => ChannelApprovalNativeFinalAction<TFinalPayload> | Promise<ChannelApprovalNativeFinalAction<TFinalPayload>>; }; type ChannelApprovalNativeTransportAdapterForView<TPreparedTarget = unknown, TPendingEntry = unknown, TPendingPayload = unknown, TFinalPayload = unknown, TPendingView extends PendingApprovalView = PendingApprovalView> = { prepareTarget: (params: ChannelApprovalCapabilityHandlerContext & { plannedTarget: ChannelApprovalNativePlannedTarget; request: ApprovalRequest; approvalKind: ChannelApprovalKind; view: TPendingView; pendingPayload: TPendingPayload; }) => PreparedChannelNativeApprovalTarget<TPreparedTarget> | null | Promise<PreparedChannelNativeApprovalTarget<TPreparedTarget> | null>; deliverPending: (params: ChannelApprovalCapabilityHandlerContext & { plannedTarget: ChannelApprovalNativePlannedTarget; preparedTarget: TPreparedTarget; request: ApprovalRequest; approvalKind: ChannelApprovalKind; view: TPendingView; pendingPayload: TPendingPayload; }) => TPendingEntry | null | Promise<TPendingEntry | null>; updateEntry?: (params: ChannelApprovalCapabilityHandlerContext & { entry: TPendingEntry; request: ApprovalRequest; approvalKind: ChannelApprovalKind; payload: TFinalPayload; phase: "resolved" | "expired"; }) => Promise<void>; deleteEntry?: (params: ChannelApprovalCapabilityHandlerContext & { entry: TPendingEntry; phase: "resolved" | "expired"; }) => Promise<void>; }; /** Transport hooks for preparing, delivering, updating, and deleting native approval entries. */ type ChannelApprovalNativeTransportAdapter<TPreparedTarget = unknown, TPendingEntry = unknown, TPendingPayload = unknown, TFinalPayload = unknown> = ChannelApprovalNativeTransportAdapterForView<TPreparedTarget, TPendingEntry, TPendingPayload, TFinalPayload>; type ChannelApprovalNativeInteractionAdapterForView<TPendingEntry = unknown, TBinding = unknown, TPendingPayload = unknown, TPendingView extends PendingApprovalView = PendingApprovalView> = { bindPending?: (params: ChannelApprovalCapabilityHandlerContext & { entry: TPendingEntry; request: ApprovalRequest; approvalKind: ChannelApprovalKind; view: TPendingView; pendingPayload: TPendingPayload; }) => TBinding | null | Promise<TBinding | null>; unbindPending?: (params: ChannelApprovalCapabilityHandlerContext & { entry: TPendingEntry; binding: TBinding; request: ApprovalRequest; approvalKind: ChannelApprovalKind; }) => Promise<void> | void; clearPendingActions?: (params: ChannelApprovalCapabilityHandlerContext & { entry: TPendingEntry; phase: "resolved" | "expired"; }) => Promise<void>; cancelDelivered?: (params: ChannelApprovalCapabilityHandlerContext & { entry: TPendingEntry; request: ApprovalRequest; approvalKind: ChannelApprovalKind; }) => Promise<void> | void; }; /** Optional hooks for binding and clearing interactive approval controls. */ type ChannelApprovalNativeInteractionAdapter<TPendingEntry = unknown, TBinding = unknown> = ChannelApprovalNativeInteractionAdapterForView<TPendingEntry, TBinding>; type ChannelApprovalNativeObserveAdapterForView<TPreparedTarget = unknown, TPendingPayload = unknown, TPendingEntry = unknown, TPendingView extends PendingApprovalView = PendingApprovalView> = { onDeliveryError?: (params: ChannelApprovalCapabilityHandlerContext & { error: unknown; plannedTarget: ChannelApprovalNativePlannedTarget; request: ApprovalRequest; approvalKind: ChannelApprovalKind; view: TPendingView; pendingPayload: TPendingPayload; }) => void; onDuplicateSkipped?: (params: ChannelApprovalCapabilityHandlerContext & { plannedTarget: ChannelApprovalNativePlannedTarget; preparedTarget: PreparedChannelNativeApprovalTarget<TPreparedTarget>; request: ApprovalRequest; approvalKind: ChannelApprovalKind; view: TPendingView; pendingPayload: TPendingPayload; }) => void; onDelivered?: (params: ChannelApprovalCapabilityHandlerContext & { plannedTarget: ChannelApprovalNativePlannedTarget; preparedTarget: PreparedChannelNativeApprovalTarget<TPreparedTarget>; request: ApprovalRequest; approvalKind: ChannelApprovalKind; view: TPendingView; pendingPayload: TPendingPayload; entry: TPendingEntry; }) => void; /** Runs after every terminal entry for one approval has been finalized. */ onFinalized?: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; approvalKind: ChannelApprovalKind; phase: "resolved" | "expired"; }) => void; }; /** Optional observer hooks for delivery errors, duplicates, and successful deliveries. */ type ChannelApprovalNativeObserveAdapter<TPreparedTarget = unknown, TPendingPayload = unknown, TPendingEntry = unknown> = ChannelApprovalNativeObserveAdapterForView<TPreparedTarget, TPendingPayload, TPendingEntry>; /** Runtime adapter consumed by core after a plugin's strongly typed spec has been erased. */ type ChannelApprovalNativeRuntimeAdapter<TPendingPayload = unknown, TPreparedTarget = unknown, TPendingEntry = unknown, TBinding = unknown, TFinalPayload = unknown> = { eventKinds?: readonly ChannelApprovalKind[]; /** * Trusted legacy ownership override retained for compatibility. * @deprecated Omit this so core derives approval ownership from the request payload. */ resolveApprovalKind?: (request: ApprovalRequest) => ChannelApprovalKind; availability: ChannelApprovalNativeAvailabilityAdapter; presentation: ChannelApprovalNativePresentationAdapter<TPendingPayload, TFinalPayload>; transport: ChannelApprovalNativeTransportAdapter<TPreparedTarget, TPendingEntry, TPendingPayload, TFinalPayload>; interactions?: ChannelApprovalNativeInteractionAdapter<TPendingEntry, TBinding>; observe?: ChannelApprovalNativeObserveAdapter; }; /** Strongly typed plugin spec used to build a channel-native approval runtime adapter. */ type ChannelApprovalNativeRuntimeSpec<TPendingPayload, TPreparedTarget, TPendingEntry, TBinding = unknown, TFinalPayload = unknown, TPendingView extends PendingApprovalView = PendingApprovalView, TResolvedView extends ResolvedApprovalView = ResolvedApprovalView, TExpiredView extends ExpiredApprovalView = ExpiredApprovalView> = { eventKinds?: readonly ChannelApprovalKind[]; /** * Trusted legacy ownership override retained for compatibility. * @deprecated Omit this so core derives approval ownership from the request payload. */ resolveApprovalKind?: (request: ApprovalRequest) => ChannelApprovalKind; availability: ChannelApprovalNativeAvailabilityAdapter; presentation: { buildPendingPayload: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; approvalKind: ChannelApprovalKind; nowMs: number; view: TPendingView; }) => TPendingPayload | Promise<TPendingPayload>; buildResolvedResult: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; resolved: ApprovalResolved; view: TResolvedView; entry: TPendingEntry; }) => ChannelApprovalNativeFinalAction<TFinalPayload> | Promise<ChannelApprovalNativeFinalAction<TFinalPayload>>; buildExpiredResult: (params: ChannelApprovalCapabilityHandlerContext & { request: ApprovalRequest; view: TExpiredView; entry: TPendingEntry; }) => ChannelApprovalNativeFinalAction<TFinalPayload> | Promise<ChannelApprovalNativeFinalAction<TFinalPayload>>; }; transport: ChannelApprovalNativeTransportAdapterForView<TPreparedTarget, TPendingEntry, TPendingPayload, TFinalPayload, TPendingView>; interactions?: ChannelApprovalNativeInteractionAdapterForView<TPendingEntry, TBinding, TPendingPayload, TPendingView>; observe?: ChannelApprovalNativeObserveAdapterForView<TPreparedTarget, TPendingPayload, TPendingEntry, TPendingView>; }; //#endregion export { ChannelApprovalNativeAdapter as A, ResolvedApprovalView as C, ChannelApprovalNativeDeliveryPlan as D, PreparedChannelNativeApprovalTarget as E, ChannelApprovalNativePlannedTarget as O, PluginApprovalResolvedView as S, ChannelNativeApprovalTransportSpec as T, ExecApprovalResolvedView as _, ChannelApprovalNativeFinalAction as a, PluginApprovalExpiredView as b, ChannelApprovalNativePresentationAdapter as c, ChannelApprovalNativeTransportAdapter as d, ApprovalActionView as f, ExecApprovalPendingView as g, ExecApprovalExpiredView as h, ChannelApprovalNativeAvailabilityAdapter as i, ChannelApprovalNativeTarget as j, resolveChannelNativeApprovalDeliveryPlan as k, ChannelApprovalNativeRuntimeAdapter as l, ApprovalViewModel as m, ApprovalResolved as n, ChannelApprovalNativeInteractionAdapter as o, ApprovalMetadataView as p, ChannelApprovalCapabilityHandlerContext as r, ChannelApprovalNativeObserveAdapter as s, ApprovalRequest as t, ChannelApprovalNativeRuntimeSpec as u, ExpiredApprovalView as v, ChannelNativeApprovalDeliveryCallbacks as w, PluginApprovalPendingView as x, PendingApprovalView as y };