openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
400 lines • 19.8 kB
TypeScript
import { r as OpenClawConfig } from "./types.openclaw-DWWUw8hA.js";
import { _ as ApprovalScope, a as SystemAgentApprovalApplicationStatus, b as ExecApprovalRequest, d as PluginApprovalRequest, j as CommandExplanationSummary, n as ApprovalResolved, o as SystemAgentApprovalRequest, r as ChannelApprovalKind, t as ApprovalRequestInput, y as ExecApprovalDecision } from "./approval-types-DOLowId2.js";
import { h as MessagePresentationButton, p as MessagePresentationAction } from "./payload-DbVrIDaU.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;
};
type ChannelApprovalNativeContext = {
cfg: OpenClawConfig;
accountId?: string | null;
approvalKind: ChannelApprovalKind;
request: ChannelApprovalNativeRequest;
};
/**
* Adapter implemented by channel plugins that support native approval delivery.
*/
type ChannelApprovalNativeAdapter = {
describeDeliveryCapabilities: (params: ChannelApprovalNativeContext) => ChannelApprovalNativeDeliveryCapabilities;
resolveOriginTarget?: (params: ChannelApprovalNativeContext) => ChannelApprovalNativeTarget | null | Promise<ChannelApprovalNativeTarget | null>;
resolveApproverDmTargets?: (params: ChannelApprovalNativeContext) => ChannelApprovalNativeTarget[] | Promise<ChannelApprovalNativeTarget[]>;
};
//#endregion
//#region src/infra/approval-native-delivery.d.ts
/** One native approval delivery target selected by the channel adapter plan. */
type ChannelApprovalNativePlannedTarget = {
surface: ChannelApprovalNativeSurface;
target: ChannelApprovalNativeTarget;
reason: "preferred" | "fallback";
};
//#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;
/** 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;
};
type ChannelApprovalNativePresentationAdapterForView<TPendingPayload = unknown, TFinalPayload = unknown, TPendingEntry = unknown, TPendingView extends PendingApprovalView = PendingApprovalView, TResolvedView extends ResolvedApprovalView = ResolvedApprovalView, TExpiredView extends ExpiredApprovalView = ExpiredApprovalView> = {
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>>;
};
/** Builds channel-native payloads for pending, resolved, and expired approval views. */
type ChannelApprovalNativePresentationAdapter<TPendingPayload = unknown, TFinalPayload = unknown> = ChannelApprovalNativePresentationAdapterForView<TPendingPayload, 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: ChannelApprovalNativePresentationAdapterForView<TPendingPayload, TFinalPayload, TPendingEntry, TPendingView, TResolvedView, TExpiredView>;
transport: ChannelApprovalNativeTransportAdapterForView<TPreparedTarget, TPendingEntry, TPendingPayload, TFinalPayload, TPendingView>;
interactions?: ChannelApprovalNativeInteractionAdapterForView<TPendingEntry, TBinding, TPendingPayload, TPendingView>;
observe?: ChannelApprovalNativeObserveAdapterForView<TPreparedTarget, TPendingPayload, TPendingEntry, TPendingView>;
};
//#endregion
export { ChannelNativeApprovalDeliveryCallbacks as C, ChannelApprovalNativeTarget as E, ResolvedApprovalView as S, ChannelApprovalNativeAdapter as T, ExpiredApprovalView as _, ChannelApprovalNativeInteractionAdapter as a, PluginApprovalPendingView as b, ChannelApprovalNativeRuntimeAdapter as c, ApprovalActionView as d, ApprovalMetadataView as f, ExecApprovalResolvedView as g, ExecApprovalPendingView as h, ChannelApprovalNativeFinalAction as i, ChannelApprovalNativeRuntimeSpec as l, ExecApprovalExpiredView as m, ChannelApprovalCapabilityHandlerContext as n, ChannelApprovalNativeObserveAdapter as o, ApprovalViewModel as p, ChannelApprovalNativeAvailabilityAdapter as r, ChannelApprovalNativePresentationAdapter as s, ApprovalRequest as t, ChannelApprovalNativeTransportAdapter as u, PendingApprovalView as v, ChannelNativeApprovalTransportSpec as w, PluginApprovalResolvedView as x, PluginApprovalExpiredView as y };