11import {
2+ buildChannelApprovalExpiredText ,
3+ buildChannelApprovalResolvedText ,
24 createChannelApprovalNativeRuntimeAdapter ,
3- type ExpiredApprovalView ,
45 type PendingApprovalView ,
5- type ResolvedApprovalView ,
6+ resolvePreparedApprovalAccountId ,
67} from "openclaw/plugin-sdk/approval-handler-runtime" ;
78import { buildChannelApprovalNativeTargetKey } from "openclaw/plugin-sdk/approval-native-runtime" ;
89import { buildApprovalReactionPendingContent } from "openclaw/plugin-sdk/approval-reaction-runtime" ;
910import type { ExecApprovalReplyDecision } from "openclaw/plugin-sdk/approval-reply-runtime" ;
1011import {
11- buildApprovalResolvedReplyPayload ,
12- buildPluginApprovalExpiredMessage ,
13- buildPluginApprovalResolvedMessage ,
1412 type ExecApprovalRequest ,
15- type ExecApprovalResolved ,
1613 type PluginApprovalRequest ,
17- type PluginApprovalResolved ,
1814} from "openclaw/plugin-sdk/approval-runtime" ;
1915import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env" ;
20- import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime" ;
2116import {
2217 registerIMessageApprovalReactionTarget ,
2318 unregisterIMessageApprovalReactionTarget ,
@@ -30,7 +25,6 @@ import { normalizeIMessageHandle, parseIMessageTarget } from "./targets.js";
3025const log = createSubsystemLogger ( "imessage/approvals" ) ;
3126
3227type ApprovalRequest = ExecApprovalRequest | PluginApprovalRequest ;
33- type ApprovalResolved = ExecApprovalResolved | PluginApprovalResolved ;
3428type IMessagePendingDelivery = {
3529 text : string ;
3630 allowedDecisions : readonly ExecApprovalReplyDecision [ ] ;
@@ -66,42 +60,6 @@ function buildPendingPayload(params: {
6660 } ;
6761}
6862
69- function buildResolvedText ( params : {
70- request : ApprovalRequest ;
71- resolved : ApprovalResolved ;
72- view : ResolvedApprovalView ;
73- } ) : string {
74- if ( params . view . approvalKind === "plugin" ) {
75- return buildPluginApprovalResolvedMessage ( params . resolved as PluginApprovalResolved ) ;
76- }
77- const resolvedByText = params . resolved . resolvedBy
78- ? ` Resolved by ${ params . resolved . resolvedBy } .`
79- : "" ;
80- const payload = buildApprovalResolvedReplyPayload ( {
81- approvalId : params . request . id ,
82- approvalSlug : params . request . id . slice ( 0 , 8 ) ,
83- text : `✅ Exec approval ${ params . resolved . decision } .${ resolvedByText } ID: ${ params . request . id } ` ,
84- } ) ;
85- return payload . text ?? "" ;
86- }
87-
88- function buildExpiredText ( params : { request : ApprovalRequest ; view : ExpiredApprovalView } ) : string {
89- if ( params . view . approvalKind === "plugin" ) {
90- return buildPluginApprovalExpiredMessage ( params . request as PluginApprovalRequest ) ;
91- }
92- return `⏱️ Exec approval expired. ID: ${ params . request . id } ` ;
93- }
94-
95- function resolvePreparedAccountId ( params : {
96- plannedAccountId ?: string | null ;
97- contextAccountId ?: string | null ;
98- } ) : string | undefined {
99- return (
100- normalizeOptionalString ( params . plannedAccountId ) ??
101- normalizeOptionalString ( params . contextAccountId )
102- ) ;
103- }
104-
10563function buildConversationKeyForTarget ( to : string ) : IMessageApprovalConversationKey | null {
10664 try {
10765 const parsed = parseIMessageTarget ( to ) ;
@@ -138,11 +96,11 @@ export const imessageApprovalNativeRuntime = createChannelApprovalNativeRuntimeA
13896 buildPendingPayload ( { request, approvalKind, nowMs, view } ) ,
13997 buildResolvedResult : ( { request, resolved, view } ) => ( {
14098 kind : "update" ,
141- payload : { text : buildResolvedText ( { request, resolved, view } ) } ,
99+ payload : { text : buildChannelApprovalResolvedText ( { request, resolved, view } ) } ,
142100 } ) ,
143101 buildExpiredResult : ( { request, view } ) => ( {
144102 kind : "update" ,
145- payload : { text : buildExpiredText ( { request, view } ) } ,
103+ payload : { text : buildChannelApprovalExpiredText ( { request, view } ) } ,
146104 } ) ,
147105 } ,
148106 transport : {
@@ -153,7 +111,7 @@ export const imessageApprovalNativeRuntime = createChannelApprovalNativeRuntimeA
153111 }
154112 const prepared : PreparedIMessageApprovalTarget = {
155113 to,
156- accountId : resolvePreparedAccountId ( {
114+ accountId : resolvePreparedApprovalAccountId ( {
157115 plannedAccountId : ( plannedTarget . target as { accountId ?: string | null } ) . accountId ,
158116 contextAccountId : accountId ,
159117 } ) ,
0 commit comments