openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 10.8 kB
JavaScript
import{t as closedObject}from"./closed-object-CP71yugl.mjs";import{t as stringLiteralUnion}from"./string-literal-union-BSVDXlo3.mjs";import{a as NonEmptyString}from"./primitives-CYTMtVCE.mjs";import{t as withSince}from"./since-n498mWyv.mjs";import{S as isApprovalResolveResult,_ as isApprovalGetResult,b as isApprovalPresentation,t as createProtocolValidator,y as isApprovalHistoryResult}from"./protocol-validator-C8aQQyMV.mjs";import{t as APPROVAL_ID_WELL_FORMED_UNICODE_PATTERN}from"./approval-id-Bjlr6lXj.mjs";import{Type}from"typebox";
//!packages/gateway-protocol/src/schema/approvals.ts
const ApprovalIdSchema=Type.String({minLength:1,pattern:APPROVAL_ID_WELL_FORMED_UNICODE_PATTERN,description:`Exact full approval id encoded safely in deep-link paths.`});const ApprovalKindSchema=stringLiteralUnion([`exec`,`plugin`,`system-agent`]);const ApprovalDecisionSchema=stringLiteralUnion([`allow-once`,`allow-always`,`deny`]);const ApprovalAllowDecisionSchema=stringLiteralUnion([`allow-once`,`allow-always`]);const ApprovalTerminalReasonSchema=stringLiteralUnion([`user`,`timeout`,`malformed-verdict`,`no-route`,`run-aborted`,`gateway-restart`,`storage-corrupt`]);const ApprovalAllowedReasonSchema=Type.Union([Type.Literal(`user`)]);const ApprovalDeniedReasonSchema=stringLiteralUnion([`user`,`malformed-verdict`,`no-route`,`storage-corrupt`]);const ApprovalExpiredReasonSchema=Type.Union([Type.Literal(`timeout`)]);const ApprovalCancelledReasonSchema=stringLiteralUnion([`run-aborted`,`gateway-restart`]);const PluginApprovalSeveritySchema=stringLiteralUnion([`info`,`warning`,`critical`]);const MessageSendApprovalScopeSchema=closedObject({kind:Type.Literal(`message-send`),target:Type.String({minLength:1,maxLength:128}),recipientCount:Type.Integer({minimum:1,maximum:1e6}),recipients:Type.Optional(Type.Array(Type.String({minLength:1,maxLength:128}),{maxItems:5})),audience:Type.Optional(stringLiteralUnion([`internal`,`external`]))});const PaymentApprovalScopeSchema=closedObject({kind:Type.Literal(`payment`),amount:Type.String({minLength:1,maxLength:40}),currency:Type.String({minLength:1,maxLength:12}),target:Type.String({minLength:1,maxLength:128})});const ExternalPostApprovalScopeSchema=closedObject({kind:Type.Literal(`external-post`),target:Type.String({minLength:1,maxLength:128}),visibility:stringLiteralUnion([`public`,`restricted`])});const StandingGrantApprovalScopeSchema=closedObject({kind:Type.Literal(`standing-grant`),automation:Type.String({minLength:1,maxLength:128}),command:Type.String({minLength:1,maxLength:256}),expiresInDays:Type.Optional(Type.Integer({minimum:1,maximum:3650}))});const ApprovalScopeSchema=Type.Union([MessageSendApprovalScopeSchema,PaymentApprovalScopeSchema,ExternalPostApprovalScopeSchema,StandingGrantApprovalScopeSchema]);const PluginApprovalExternalResolutionSchema=closedObject({label:Type.String({minLength:1,maxLength:80}),decisions:Type.Array(ApprovalAllowDecisionSchema,{minItems:1,maxItems:2,uniqueItems:true})});const ApprovalAllowedDecisionsSchema=Type.Array(ApprovalDecisionSchema,{minItems:1,maxItems:3,uniqueItems:true,contains:Type.Literal(`deny`),description:`Available reviewer decisions. Deny is always available so malformed or unsafe input can be rejected.`});const SystemAgentApprovalAllowedDecisionsSchema=Type.Tuple([Type.Literal(`allow-once`),Type.Literal(`deny`)]);const StreamApprovalProposalSchema=closedObject({jobId:NonEmptyString,name:NonEmptyString,operation:Type.Union([Type.Literal(`add`),Type.Literal(`update`)])});const ExecApprovalPresentationSchema=Type.Object({kind:Type.Literal(`exec`),commandText:NonEmptyString,commandPreview:Type.Optional(Type.Union([Type.String(),Type.Null()])),warningText:Type.Optional(Type.Union([Type.String(),Type.Null()])),streamProposal:Type.Optional(StreamApprovalProposalSchema),host:Type.Optional(Type.Union([Type.String(),Type.Null()])),nodeId:Type.Optional(Type.Union([NonEmptyString,Type.Null()])),agentId:Type.Optional(Type.Union([NonEmptyString,Type.Null()])),scope:Type.Optional(ApprovalScopeSchema),allowedDecisions:ApprovalAllowedDecisionsSchema},{additionalProperties:false,description:`Reviewer-safe exec presentation. Runtime cwd, environment, system-run binding, and execution plan are intentionally excluded.`});const PluginApprovalPresentationSchema=closedObject({kind:Type.Literal(`plugin`),title:Type.String({minLength:1,maxLength:80}),description:Type.String({minLength:1,maxLength:512}),detail:Type.Optional(Type.String({minLength:1,maxLength:16384})),severity:PluginApprovalSeveritySchema,pluginId:Type.Optional(Type.Union([NonEmptyString,Type.Null()])),toolName:Type.Optional(Type.Union([NonEmptyString,Type.Null()])),agentId:Type.Optional(Type.Union([NonEmptyString,Type.Null()])),scope:Type.Optional(ApprovalScopeSchema),allowedDecisions:ApprovalAllowedDecisionsSchema,externalResolution:Type.Optional(PluginApprovalExternalResolutionSchema)});const SystemAgentApprovalPresentationSchema=closedObject({kind:Type.Literal(`system-agent`),title:Type.String({minLength:1,maxLength:80}),description:Type.String({minLength:1,maxLength:512}),proposalHash:Type.String({pattern:`^[a-f0-9]{64}$`}),agentId:Type.Optional(Type.Union([NonEmptyString,Type.Null()])),allowedDecisions:SystemAgentApprovalAllowedDecisionsSchema});const ApprovalPresentationSchema=Type.Union([ExecApprovalPresentationSchema,PluginApprovalPresentationSchema,SystemAgentApprovalPresentationSchema]);const ApprovalRecordCommonFields={id:ApprovalIdSchema,urlPath:NonEmptyString,createdAtMs:Type.Integer({minimum:0}),expiresAtMs:Type.Integer({minimum:0}),presentation:ApprovalPresentationSchema};const ApprovalHistorySourceAttributionSchema=closedObject({agentId:Type.Optional(NonEmptyString),sessionKey:Type.Optional(NonEmptyString)});const ApprovalHistoryResolverAttributionSchema=closedObject({kind:stringLiteralUnion([`device`,`channel`,`runtime`,`system`]),id:Type.Optional(NonEmptyString)});const ApprovalResolutionFields={resolvedAtMs:Type.Integer({minimum:0}),source:Type.Optional(ApprovalHistorySourceAttributionSchema),resolver:Type.Optional(ApprovalHistoryResolverAttributionSchema)};const PendingApprovalSnapshotSchema=closedObject({...ApprovalRecordCommonFields,status:Type.Literal(`pending`),sourceSessionKey:Type.Optional(NonEmptyString)});const AllowedApprovalSnapshotSchema=closedObject({...ApprovalRecordCommonFields,...ApprovalResolutionFields,status:Type.Literal(`allowed`),decision:ApprovalAllowDecisionSchema,reason:ApprovalAllowedReasonSchema});const DeniedApprovalSnapshotSchema=closedObject({...ApprovalRecordCommonFields,...ApprovalResolutionFields,status:Type.Literal(`denied`),decision:Type.Literal(`deny`),reason:ApprovalDeniedReasonSchema});const ExpiredApprovalSnapshotSchema=closedObject({...ApprovalRecordCommonFields,...ApprovalResolutionFields,status:Type.Literal(`expired`),reason:ApprovalExpiredReasonSchema});const CancelledApprovalSnapshotSchema=closedObject({...ApprovalRecordCommonFields,...ApprovalResolutionFields,status:Type.Literal(`cancelled`),reason:ApprovalCancelledReasonSchema});const ApprovalSnapshotSchema=Type.Union([PendingApprovalSnapshotSchema,AllowedApprovalSnapshotSchema,DeniedApprovalSnapshotSchema,ExpiredApprovalSnapshotSchema,CancelledApprovalSnapshotSchema]);const TerminalApprovalSnapshotSchema=Type.Union([AllowedApprovalSnapshotSchema,DeniedApprovalSnapshotSchema,ExpiredApprovalSnapshotSchema,CancelledApprovalSnapshotSchema]);const ApprovalGetParamsSchema=closedObject({id:ApprovalRecordCommonFields.id});const ApprovalGetResultSchema=closedObject({approval:ApprovalSnapshotSchema});const ApprovalHistoryParamsSchema=closedObject({cursor:Type.Optional(Type.String({minLength:1,maxLength:512})),limit:Type.Optional(Type.Integer({minimum:1,maximum:100})),kind:Type.Optional(ApprovalKindSchema)});const ApprovalHistoryResultSchema=closedObject({items:Type.Array(TerminalApprovalSnapshotSchema),nextCursor:Type.Optional(Type.String({minLength:1,maxLength:512}))});const ApprovalChannelReviewerSchema=closedObject({channel:NonEmptyString,accountId:NonEmptyString,senderId:NonEmptyString});const ApprovalResolveParamsSchema=closedObject({id:ApprovalRecordCommonFields.id,kind:ApprovalKindSchema,decision:ApprovalDecisionSchema,reviewer:Type.Optional(ApprovalChannelReviewerSchema),grantExpiresInDays:Type.Optional(Type.Integer({minimum:1,maximum:3650}))});const ApprovalResolveResultSchema=closedObject({applied:Type.Boolean(),approval:TerminalApprovalSnapshotSchema});const SessionApprovalEventCommonFields={sessionKey:NonEmptyString,sourceSessionKey:Type.Optional(NonEmptyString),updatedAtMs:Type.Integer({minimum:0})};const PendingSessionApprovalEventSchema=withSince(`2026.7`,closedObject({...SessionApprovalEventCommonFields,phase:Type.Literal(`pending`),approval:PendingApprovalSnapshotSchema}));const TerminalSessionApprovalEventSchema=withSince(`2026.7`,closedObject({...SessionApprovalEventCommonFields,phase:Type.Literal(`terminal`),approval:TerminalApprovalSnapshotSchema}));const SessionApprovalEventSchema=withSince(`2026.7`,Type.Union([PendingSessionApprovalEventSchema,TerminalSessionApprovalEventSchema]));const SessionApprovalReplaySchema=withSince(`2026.7`,closedObject({sessionKey:NonEmptyString,updatedAtMs:Type.Integer({minimum:0}),approvals:Type.Array(PendingApprovalSnapshotSchema),truncated:Type.Boolean()}));
//!packages/gateway-protocol/src/approval-result-validators.ts
const validateApprovalGetResult=/* @__PURE__ */ createProtocolValidator(ApprovalGetResultSchema,isApprovalGetResult);const validateApprovalHistoryResult=/* @__PURE__ */ createProtocolValidator(ApprovalHistoryResultSchema,isApprovalHistoryResult);const validateApprovalResolveResult=/* @__PURE__ */ createProtocolValidator(ApprovalResolveResultSchema,isApprovalResolveResult);const validateApprovalPresentation=/* @__PURE__ */ createProtocolValidator(ApprovalPresentationSchema,isApprovalPresentation);export{ExpiredApprovalSnapshotSchema as C,SessionApprovalEventSchema as D,PluginApprovalSeveritySchema as E,SessionApprovalReplaySchema as O,ExecApprovalPresentationSchema as S,PluginApprovalPresentationSchema as T,ApprovalScopeSchema as _,AllowedApprovalSnapshotSchema as a,CancelledApprovalSnapshotSchema as b,ApprovalDecisionSchema as c,ApprovalHistoryParamsSchema as d,ApprovalHistoryResultSchema as f,ApprovalResolveResultSchema as g,ApprovalResolveParamsSchema as h,validateApprovalResolveResult as i,TerminalApprovalSnapshotSchema as k,ApprovalGetParamsSchema as l,ApprovalPresentationSchema as m,validateApprovalHistoryResult as n,ApprovalAllowDecisionSchema as o,ApprovalKindSchema as p,validateApprovalPresentation as r,ApprovalChannelReviewerSchema as s,validateApprovalGetResult as t,ApprovalGetResultSchema as u,ApprovalSnapshotSchema as v,PendingApprovalSnapshotSchema as w,DeniedApprovalSnapshotSchema as x,ApprovalTerminalReasonSchema as y};