11// Defines plugin approval request/resolution payloads and actions.
22import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice" ;
3- import type { PluginExternalResolution } from "../plugins/external-verification-approval-types.js" ;
4- import { sanitizeExecApprovalDisplayText } from "./exec-approval-command-display.js" ;
53import type { ExecApprovalDecision } from "./exec-approvals.js" ;
64
75// Plugin approval types and renderers mirror exec approval decisions while
@@ -26,12 +24,13 @@ export type PluginApprovalRequestPayload = {
2624 toolCallId ?: string | null ;
2725 allowedDecisions ?: readonly ExecApprovalDecision [ ] | null ;
2826 /** Trusted in-process metadata; public Gateway callers cannot submit this field. */
29- externalResolution ?: PluginExternalResolution | null ;
27+ externalResolution ?: {
28+ label : string ;
29+ decisions ?: readonly ( "allow-once" | "allow-always" ) [ ] ;
30+ } | null ;
3031 actions ?: readonly PluginApprovalActionView [ ] | null ;
3132 agentId ?: string | null ;
3233 sessionKey ?: string | null ;
33- sessionId ?: string | null ;
34- runId ?: string | null ;
3534 turnSourceChannel ?: string | null ;
3635 turnSourceTo ?: string | null ;
3736 turnSourceAccountId ?: string | null ;
@@ -60,7 +59,6 @@ export const MAX_PLUGIN_APPROVAL_TIMEOUT_MS = 600_000;
6059export const PLUGIN_APPROVAL_TITLE_MAX_LENGTH = 80 ;
6160export const PLUGIN_APPROVAL_DESCRIPTION_MAX_LENGTH = 512 ;
6261export const PLUGIN_APPROVAL_DETAIL_MAX_LENGTH = 16_384 ;
63- export const PLUGIN_EXTERNAL_RESOLUTION_LABEL_MAX_LENGTH = 80 ;
6462const PLUGIN_APPROVAL_DETAIL_TRUNCATION_SUFFIX = "…[truncated]" ;
6563export const DEFAULT_PLUGIN_APPROVAL_DECISIONS = [
6664 "allow-once" ,
@@ -124,34 +122,6 @@ export function resolvePluginApprovalRequestAllowedDecisions(params?: {
124122 return explicit . length > 0 ? explicit : DEFAULT_PLUGIN_APPROVAL_DECISIONS ;
125123}
126124
127- /** Validate and normalize the plugin-owned allow path before it crosses into Gateway state. */
128- export function normalizePluginExternalResolution (
129- value : PluginExternalResolution | null | undefined ,
130- ) : PluginExternalResolution | null {
131- if ( ! value ) {
132- return null ;
133- }
134- const rawLabel = value . label ?. trim ( ) ;
135- const label = rawLabel ? sanitizeExecApprovalDisplayText ( rawLabel ) : "" ;
136- if ( ! label || Array . from ( label ) . length > PLUGIN_EXTERNAL_RESOLUTION_LABEL_MAX_LENGTH ) {
137- throw new Error (
138- `external approval label must be 1-${ PLUGIN_EXTERNAL_RESOLUTION_LABEL_MAX_LENGTH } characters` ,
139- ) ;
140- }
141- const decisions = value . decisions ?? [ "allow-once" ] ;
142- if (
143- decisions . length < 1 ||
144- decisions . length > 2 ||
145- decisions . some ( ( decision ) => decision !== "allow-once" && decision !== "allow-always" ) ||
146- new Set ( decisions ) . size !== decisions . length
147- ) {
148- throw new Error (
149- "external approval decisions must contain unique allow-once/allow-always values" ,
150- ) ;
151- }
152- return { label, decisions : [ ...decisions ] } ;
153- }
154-
155125/** Build the pending plugin approval message. */
156126export function buildPluginApprovalRequestMessage (
157127 request : PluginApprovalRequest ,
0 commit comments