openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
336 lines • 13.3 kB
TypeScript
import { a as ApprovalScope$1, o as ApprovalScopeSchema } from "./approvals-B-zk4kd_.js";
import { Static } from "typebox";
//#region src/infra/command-analysis/explain.d.ts
/** Compact command explanation summary shown in approval UI. */
type CommandExplanationSummary = {
commandCount: number;
nestedCommandCount: number;
riskKinds: string[];
warningLines: string[];
};
//#endregion
//#region src/infra/exec-approval-policy-snapshot.d.ts
type ExecApprovalPolicyRule = {
pattern: string;
argPattern?: string;
source?: "allow-always";
};
type ExecApprovalPolicySnapshot = {
security: "deny" | "allowlist" | "full";
ask: "off" | "on-miss" | "always";
askFallback: "deny" | "allowlist" | "full";
autoAllowSkills: boolean;
allowlistRules: readonly ExecApprovalPolicyRule[];
};
//#endregion
//#region src/infra/exec-approvals.types.d.ts
type McpToolGrant = {
server: string;
tool: string;
source: "allow-always";
addedAt: number;
lastUsedAt?: number;
};
type ExecAllowlistEntry = {
id?: string;
pattern: string;
source?: "allow-always";
commandText?: string;
argPattern?: string;
lastUsedAt?: number;
lastUsedCommand?: string;
lastResolvedPath?: string;
};
//#endregion
//#region src/infra/exec-approvals-core.d.ts
type ExecHost = "sandbox" | "gateway" | "node";
type ExecTarget = "auto" | ExecHost;
type ExecSecurity = "deny" | "allowlist" | "full";
type ExecAsk = "off" | "on-miss" | "always";
type ExecMode = "deny" | "allowlist" | "ask" | "auto" | "full";
type ExecApprovalDecision = "allow-once" | "allow-always" | "deny";
type ExecApprovalUnavailableDecision = "allow-always";
declare const EXEC_TARGET_VALUES: readonly ExecTarget[];
declare function normalizeExecHost(value?: string | null): ExecHost | null;
declare function normalizeExecTarget(value?: string | null): ExecTarget | null;
declare function requireValidExecTarget(value?: unknown): ExecTarget | null;
declare function normalizeExecSecurity(value?: unknown): ExecSecurity | null;
declare function normalizeExecAsk(value?: unknown): ExecAsk | null;
declare function normalizeExecMode(value?: string | null): ExecMode | null;
declare function resolveExecModePolicy(params: {
mode?: ExecMode | null;
security: ExecSecurity;
ask: ExecAsk;
}): {
mode: ExecMode;
security: ExecSecurity;
ask: ExecAsk;
autoReview: boolean;
};
type SystemRunApprovalBinding = {
argv: string[];
cwd: string | null;
agentId: string | null;
sessionKey: string | null;
envHash: string | null;
};
type SystemRunApprovalFileOperand = {
argvIndex: number;
path: string;
sha256: string;
};
type SystemRunApprovalPlan = {
argv: string[];
cwd: string | null;
commandText: string;
commandPreview?: string | null;
agentId: string | null;
sessionKey: string | null;
policySnapshot?: ExecApprovalPolicySnapshot;
mutableFileOperand?: SystemRunApprovalFileOperand | null;
};
type ExecApprovalCommandSpan = {
startIndex: number;
endIndex: number;
};
/** Cron job identity recorded at approval creation for a cron isolated run. */
type ExecApprovalCronExecutionSource = {
jobId: string;
jobConfigRevision: string;
};
type ExecApprovalRequestPayload = {
command: string;
commandPreview?: string | null;
commandArgv?: string[];
envKeys?: string[];
systemRunBinding?: SystemRunApprovalBinding | null;
systemRunPlan?: SystemRunApprovalPlan | null;
cwd?: string | null;
nodeId?: string | null;
host?: string | null;
security?: string | null;
ask?: string | null;
warningText?: string | null;
/** Owner-declared blast-radius facts; display-only, never authorization. */
scope?: ApprovalScope$1 | null;
commandAnalysis?: CommandExplanationSummary | null;
commandSpans?: ExecApprovalCommandSpan[];
unavailableDecisions?: readonly ExecApprovalUnavailableDecision[];
allowedDecisions?: readonly ExecApprovalDecision[];
agentId?: string | null;
resolvedPath?: string | null;
sessionKey?: string | null;
sessionId?: string | null;
runId?: string | null;
toolCallId?: string | null;
turnSourceChannel?: string | null;
turnSourceTo?: string | null;
turnSourceAccountId?: string | null;
turnSourceThreadId?: string | number | null;
/** Gateway-recorded cron source; never taken from client request params. */
cronExecutionSource?: ExecApprovalCronExecutionSource | null;
/** Exact operation binding prepared at creation for standing-grant minting. */
cronOperationBinding?: string | null;
};
type ExecApprovalRequest = {
/** Descriptive wire metadata; readers derive it from the payload when absent. */
approvalKind?: "exec";
id: string;
request: ExecApprovalRequestPayload;
createdAtMs: number;
expiresAtMs: number;
};
type ExecApprovalResolved = {
id: string;
decision: ExecApprovalDecision;
resolvedBy?: string | null;
ts: number;
request?: ExecApprovalRequest["request"];
};
type ExecApprovalsDefaults = {
security?: ExecSecurity;
ask?: ExecAsk;
askFallback?: ExecSecurity;
autoAllowSkills?: boolean;
};
type ExecApprovalsAgent = ExecApprovalsDefaults & {
allowlist?: ExecAllowlistEntry[];
mcpTools?: McpToolGrant[];
};
type ExecApprovalsFile = {
version: 1;
socket?: {
path?: string;
token?: string;
};
defaults?: ExecApprovalsDefaults;
agents?: Record<string, ExecApprovalsAgent>;
};
type ExecApprovalsSnapshot = {
path: string;
exists: boolean;
raw: string | null;
file: ExecApprovalsFile;
hash: string;
};
type ExecApprovalsResolved = {
path: string;
socketPath: string;
token: string;
defaults: Required<ExecApprovalsDefaults>;
agent: Required<ExecApprovalsDefaults>;
agentSources: {
security: string | null;
ask: string | null;
askFallback: string | null;
};
allowlist: ExecAllowlistEntry[];
file: ExecApprovalsFile;
};
declare const DEFAULT_EXEC_APPROVAL_TIMEOUT_MS = 1800000;
//#endregion
//#region src/infra/approval-scope.d.ts
type ApprovalScope = Static<typeof ApprovalScopeSchema>;
//#endregion
//#region src/infra/plugin-approvals.d.ts
type PluginApprovalActionView = {
kind?: "command" | "decision";
label: string;
command: string;
decision?: ExecApprovalDecision;
style?: "primary" | "secondary" | "success" | "danger";
};
/** Gateway-minted placement identity; plugin and RPC callers never supply this authority. */
type PluginApprovalPlacementGrantBinding = {
pluginId: string;
command: string;
approvalScope: string;
agentId: string;
sessionKey: string;
sessionId: string;
nodeId: string;
pairingGeneration: string;
environmentId: string;
ownerEpoch: number;
placementGeneration: number;
cwd: string;
};
type PluginApprovalRequestPayload = {
pluginId?: string | null;
title: string;
description: string;
detail?: string | null;
severity?: "info" | "warning" | "critical" | null;
/** Owner-declared blast-radius facts; display-only, never authorization. */
scope?: ApprovalScope | null;
toolName?: string | null;
toolCallId?: string | null;
/** Trusted harness-selected policy subject; distinct from display-only toolName. */
policySubject?: {
pluginKey: string;
tool?: string;
};
/** Exact MCP persistence intent; the host separately binds live tool-call proof. */
mcpTool?: {
server: string;
tool: string;
};
allowedDecisions?: readonly ExecApprovalDecision[] | null;
/** Trusted in-process metadata; public Gateway callers cannot submit this field. */
externalResolution?: {
label: string;
decisions?: readonly ("allow-once" | "allow-always")[];
} | null;
actions?: readonly PluginApprovalActionView[] | null;
agentId?: string | null;
sessionKey?: string | null;
/** Host-derived source run; never accepted from plugin approval RPC params. */
runId?: string | null;
/** Host-derived grant binding; never accepted from plugin approval RPC params. */
placementGrant?: PluginApprovalPlacementGrantBinding | null;
turnSourceChannel?: string | null;
turnSourceTo?: string | null;
turnSourceAccountId?: string | null;
turnSourceThreadId?: string | number | null;
};
/** Timed plugin approval request persisted while awaiting a decision. */
type PluginApprovalRequest = {
/** Descriptive wire metadata; readers derive it from the payload when absent. */
approvalKind?: "plugin";
id: string;
request: PluginApprovalRequestPayload;
createdAtMs: number;
expiresAtMs: number;
};
type PluginApprovalResolved = {
id: string;
decision: ExecApprovalDecision;
resolvedBy?: string | null;
ts: number;
request?: PluginApprovalRequestPayload;
};
declare const DEFAULT_PLUGIN_APPROVAL_TIMEOUT_MS = 120000;
declare const MAX_PLUGIN_APPROVAL_TIMEOUT_MS = 600000;
declare const PLUGIN_APPROVAL_TITLE_MAX_LENGTH = 80;
declare const PLUGIN_APPROVAL_DESCRIPTION_MAX_LENGTH = 512;
declare const PLUGIN_APPROVAL_DETAIL_MAX_LENGTH = 16384;
declare const DEFAULT_PLUGIN_APPROVAL_DECISIONS: readonly ["allow-once", "allow-always", "deny"];
/** Caps reviewer-only plugin detail by Unicode code point without splitting surrogate pairs. */
declare function truncatePluginApprovalDetail(value: string): string;
declare function resolvePluginApprovalTimeoutMs(value: unknown): number;
declare function approvalDecisionLabel(decision: ExecApprovalDecision): string;
declare function resolvePluginApprovalRequestAllowedDecisions(params?: {
allowedDecisions?: readonly ExecApprovalDecision[] | readonly string[] | null;
}): readonly ExecApprovalDecision[];
declare function buildPluginApprovalRequestMessage(request: PluginApprovalRequest, nowMsValue: number): string;
declare function buildPluginApprovalResolvedMessage(resolved: PluginApprovalResolved): string;
declare function buildPluginApprovalExpiredMessage(request: PluginApprovalRequest): string;
//#endregion
//#region src/infra/system-agent-approvals.d.ts
type SystemAgentApprovalRequestPayload = {
title: string;
description: string;
command: string;
proposalHash: string;
allowedDecisions: readonly ExecApprovalDecision[];
agentId?: string | null;
sessionKey?: string | null;
sessionId: string;
runId?: string | null;
turnSourceChannel?: string | null;
turnSourceTo?: string | null;
turnSourceAccountId?: string | null;
turnSourceThreadId?: string | number | null;
};
type SystemAgentApprovalRequest = {
approvalKind?: "system-agent";
id: string;
request: SystemAgentApprovalRequestPayload;
createdAtMs: number;
expiresAtMs: number;
};
type SystemAgentApprovalApplicationStatus = "applied" | "not-applied";
type SystemAgentApprovalResolved = {
id: string;
decision: ExecApprovalDecision;
resolvedBy?: string | null;
ts: number;
request?: SystemAgentApprovalRequestPayload;
applicationStatus?: SystemAgentApprovalApplicationStatus;
terminalStatus?: "expired" | "cancelled";
};
//#endregion
//#region src/infra/approval-types.d.ts
type ChannelApprovalKind = "exec" | "plugin" | "system-agent";
/** Backward-compatible request shape accepted from Gateway events and replay. */
type ApprovalRequestInput = ExecApprovalRequest | PluginApprovalRequest | SystemAgentApprovalRequest;
type ApprovalResolved = ExecApprovalResolved | PluginApprovalResolved | SystemAgentApprovalResolved;
type NormalizedApprovalRequest<TRequest extends ApprovalRequestInput> = TRequest extends ExecApprovalRequest ? TRequest & {
approvalKind: "exec";
} : TRequest extends PluginApprovalRequest ? TRequest & {
approvalKind: "plugin";
} : TRequest extends SystemAgentApprovalRequest ? TRequest & {
approvalKind: "system-agent";
} : never;
//#endregion
export { requireValidExecTarget as $, ExecApprovalDecision as A, ExecAsk as B, resolvePluginApprovalRequestAllowedDecisions as C, DEFAULT_EXEC_APPROVAL_TIMEOUT_MS as D, ApprovalScope as E, ExecApprovalsAgent as F, SystemRunApprovalBinding as G, ExecMode as H, ExecApprovalsDefaults as I, normalizeExecAsk as J, SystemRunApprovalFileOperand as K, ExecApprovalsFile as L, ExecApprovalRequestPayload as M, ExecApprovalResolved as N, EXEC_TARGET_VALUES as O, ExecApprovalUnavailableDecision as P, normalizeExecTarget as Q, ExecApprovalsResolved as R, buildPluginApprovalResolvedMessage as S, truncatePluginApprovalDetail as T, ExecSecurity as U, ExecHost as V, ExecTarget as W, normalizeExecMode as X, normalizeExecHost as Y, normalizeExecSecurity as Z, PluginApprovalRequestPayload as _, SystemAgentApprovalApplicationStatus as a, buildPluginApprovalExpiredMessage as b, SystemAgentApprovalResolved as c, MAX_PLUGIN_APPROVAL_TIMEOUT_MS as d, resolveExecModePolicy as et, PLUGIN_APPROVAL_DESCRIPTION_MAX_LENGTH as f, PluginApprovalRequest as g, PluginApprovalActionView as h, NormalizedApprovalRequest as i, ExecApprovalRequest as j, ExecApprovalCommandSpan as k, DEFAULT_PLUGIN_APPROVAL_DECISIONS as l, PLUGIN_APPROVAL_TITLE_MAX_LENGTH as m, ApprovalResolved as n, ExecApprovalPolicySnapshot as nt, SystemAgentApprovalRequest as o, PLUGIN_APPROVAL_DETAIL_MAX_LENGTH as p, SystemRunApprovalPlan as q, ChannelApprovalKind as r, CommandExplanationSummary as rt, SystemAgentApprovalRequestPayload as s, ApprovalRequestInput as t, ExecAllowlistEntry as tt, DEFAULT_PLUGIN_APPROVAL_TIMEOUT_MS as u, PluginApprovalResolved as v, resolvePluginApprovalTimeoutMs as w, buildPluginApprovalRequestMessage as x, approvalDecisionLabel as y, ExecApprovalsSnapshot as z };