1- import type { OpenClawApp } from "./app.ts" ;
21import {
32 loadChannels ,
43 logoutWhatsApp ,
54 startWhatsAppLogin ,
65 waitWhatsAppLogin ,
6+ type ChannelsState ,
77} from "./controllers/channels.ts" ;
8- import { loadConfig , saveConfig } from "./controllers/config.ts" ;
8+ import { loadConfig , saveConfig , type ConfigState } from "./controllers/config.ts" ;
99import { normalizeOptionalString } from "./string-coerce.ts" ;
1010import type { NostrProfile } from "./types.ts" ;
1111import { createNostrProfileFormState } from "./views/channels.nostr-profile-form.ts" ;
1212
13- export async function handleWhatsAppStart ( host : OpenClawApp , force : boolean ) {
14- await startWhatsAppLogin ( host , force ) ;
15- await loadChannels ( host , true ) ;
13+ type NostrProfileFormState = ReturnType < typeof createNostrProfileFormState > | null ;
14+
15+ type ChannelsActionHost = ChannelsState &
16+ ConfigState & {
17+ hello ?: { auth ?: { deviceToken ?: string | null } | null } | null ;
18+ password ?: string ;
19+ settings : { token ?: string } ;
20+ nostrProfileFormState : NostrProfileFormState ;
21+ nostrProfileAccountId : string | null ;
22+ } ;
23+
24+ export async function handleWhatsAppStart ( host : ChannelsActionHost , force : boolean ) {
25+ await startWhatsAppLogin ( host as ChannelsState , force ) ;
26+ await loadChannels ( host as ChannelsState , true ) ;
1627}
1728
18- export async function handleWhatsAppWait ( host : OpenClawApp ) {
19- await waitWhatsAppLogin ( host ) ;
20- await loadChannels ( host , true ) ;
29+ export async function handleWhatsAppWait ( host : ChannelsActionHost ) {
30+ await waitWhatsAppLogin ( host as ChannelsState ) ;
31+ await loadChannels ( host as ChannelsState , true ) ;
2132}
2233
23- export async function handleWhatsAppLogout ( host : OpenClawApp ) {
24- await logoutWhatsApp ( host ) ;
25- await loadChannels ( host , true ) ;
34+ export async function handleWhatsAppLogout ( host : ChannelsActionHost ) {
35+ await logoutWhatsApp ( host as ChannelsState ) ;
36+ await loadChannels ( host as ChannelsState , true ) ;
2637}
2738
28- export async function handleChannelConfigSave ( host : OpenClawApp ) {
29- await saveConfig ( host ) ;
30- await loadConfig ( host ) ;
31- await loadChannels ( host , true ) ;
39+ export async function handleChannelConfigSave ( host : ChannelsActionHost ) {
40+ await saveConfig ( host as ConfigState ) ;
41+ await loadConfig ( host as ConfigState ) ;
42+ await loadChannels ( host as ChannelsState , true ) ;
3243}
3344
34- export async function handleChannelConfigReload ( host : OpenClawApp ) {
35- await loadConfig ( host ) ;
36- await loadChannels ( host , true ) ;
45+ export async function handleChannelConfigReload ( host : ChannelsActionHost ) {
46+ await loadConfig ( host as ConfigState ) ;
47+ await loadChannels ( host as ChannelsState , true ) ;
3748}
3849
3950function parseValidationErrors ( details : unknown ) : Record < string , string > {
@@ -58,7 +69,7 @@ function parseValidationErrors(details: unknown): Record<string, string> {
5869 return errors ;
5970}
6071
61- function resolveNostrAccountId ( host : OpenClawApp ) : string {
72+ function resolveNostrAccountId ( host : ChannelsActionHost ) : string {
6273 const accounts = host . channelsSnapshot ?. channelAccounts ?. nostr ?? [ ] ;
6374 return accounts [ 0 ] ?. accountId ?? host . nostrProfileAccountId ?? "default" ;
6475}
@@ -67,7 +78,7 @@ function buildNostrProfileUrl(accountId: string, suffix = ""): string {
6778 return `/api/channels/nostr/${ encodeURIComponent ( accountId ) } /profile${ suffix } ` ;
6879}
6980
70- function resolveGatewayHttpAuthHeader ( host : OpenClawApp ) : string | null {
81+ function resolveGatewayHttpAuthHeader ( host : ChannelsActionHost ) : string | null {
7182 const deviceToken = normalizeOptionalString ( host . hello ?. auth ?. deviceToken ) ;
7283 if ( deviceToken ) {
7384 return `Bearer ${ deviceToken } ` ;
@@ -83,27 +94,27 @@ function resolveGatewayHttpAuthHeader(host: OpenClawApp): string | null {
8394 return null ;
8495}
8596
86- function buildGatewayHttpHeaders ( host : OpenClawApp ) : Record < string , string > {
97+ function buildGatewayHttpHeaders ( host : ChannelsActionHost ) : Record < string , string > {
8798 const authorization = resolveGatewayHttpAuthHeader ( host ) ;
8899 return authorization ? { Authorization : authorization } : { } ;
89100}
90101
91102export function handleNostrProfileEdit (
92- host : OpenClawApp ,
103+ host : ChannelsActionHost ,
93104 accountId : string ,
94105 profile : NostrProfile | null ,
95106) {
96107 host . nostrProfileAccountId = accountId ;
97108 host . nostrProfileFormState = createNostrProfileFormState ( profile ?? undefined ) ;
98109}
99110
100- export function handleNostrProfileCancel ( host : OpenClawApp ) {
111+ export function handleNostrProfileCancel ( host : ChannelsActionHost ) {
101112 host . nostrProfileFormState = null ;
102113 host . nostrProfileAccountId = null ;
103114}
104115
105116export function handleNostrProfileFieldChange (
106- host : OpenClawApp ,
117+ host : ChannelsActionHost ,
107118 field : keyof NostrProfile ,
108119 value : string ,
109120) {
@@ -124,7 +135,7 @@ export function handleNostrProfileFieldChange(
124135 } ;
125136}
126137
127- export function handleNostrProfileToggleAdvanced ( host : OpenClawApp ) {
138+ export function handleNostrProfileToggleAdvanced ( host : ChannelsActionHost ) {
128139 const state = host . nostrProfileFormState ;
129140 if ( ! state ) {
130141 return ;
@@ -135,7 +146,7 @@ export function handleNostrProfileToggleAdvanced(host: OpenClawApp) {
135146 } ;
136147}
137148
138- export async function handleNostrProfileSave ( host : OpenClawApp ) {
149+ export async function handleNostrProfileSave ( host : ChannelsActionHost ) {
139150 const state = host . nostrProfileFormState ;
140151 if ( ! state || state . saving ) {
141152 return ;
@@ -196,7 +207,7 @@ export async function handleNostrProfileSave(host: OpenClawApp) {
196207 fieldErrors : { } ,
197208 original : { ...state . values } ,
198209 } ;
199- await loadChannels ( host , true ) ;
210+ await loadChannels ( host as ChannelsState , true ) ;
200211 } catch ( err ) {
201212 host . nostrProfileFormState = {
202213 ...state ,
@@ -207,7 +218,7 @@ export async function handleNostrProfileSave(host: OpenClawApp) {
207218 }
208219}
209220
210- export async function handleNostrProfileImport ( host : OpenClawApp ) {
221+ export async function handleNostrProfileImport ( host : ChannelsActionHost ) {
211222 const state = host . nostrProfileFormState ;
212223 if ( ! state || state . importing ) {
213224 return ;
0 commit comments