-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Expand file tree
/
Copy pathtypes.core.ts
More file actions
828 lines (783 loc) · 26.5 KB
/
Copy pathtypes.core.ts
File metadata and controls
828 lines (783 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/**
* Core channel plugin public types.
*
* Defines channel metadata, capabilities, action discovery, setup, status, and runtime contexts.
*/
import type { TSchema } from "typebox";
import type {
GatewayClientMode,
GatewayClientName,
} from "../../../packages/gateway-protocol/src/client-info.js";
import type { AgentTool, AgentToolResult } from "../../agents/runtime/index.js";
import type { ReplyDeliveryContext, ReplyPayload } from "../../auto-reply/reply-payload.js";
import type { MsgContext } from "../../auto-reply/templating.js";
import type { MarkdownTableMode } from "../../config/types.base.js";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import type { MessagePresentation } from "../../interactive/payload.js";
import type { OutboundMediaAccess } from "../../media/load-options.js";
import type { PollInput } from "../../polls.js";
import type { ChatType } from "../chat-type.js";
import type { InboundEventKind } from "../inbound-event/kind.js";
import type { ChannelId } from "./channel-id.types.js";
import type { ChannelMessageActionName as ChannelMessageActionNameFromList } from "./message-action-names.js";
import type { ChannelMessageCapability } from "./message-capabilities.js";
export type { ChannelId } from "./channel-id.types.js";
export type { ChannelLegacyStateMigrationPlan } from "./legacy-state-migration.types.js";
export type ChannelExposure = {
configured?: boolean;
setup?: boolean;
docs?: boolean;
};
export type ChannelOutboundTargetMode = "explicit" | "implicit" | "heartbeat";
/** Agent tool registered by a channel plugin. */
export type ChannelAgentTool = AgentTool;
/** Lazy agent-tool factory used when tool availability depends on config. */
export type ChannelAgentToolFactory = (params: { cfg?: OpenClawConfig }) => ChannelAgentTool[];
/**
* Discovery-time inputs passed to channel action adapters when the core is
* asking what an agent should be allowed to see. This is intentionally
* smaller than execution context: it carries routing/account scope, but no
* tool params or runtime handles.
*/
export type ChannelMessageActionDiscoveryContext = {
cfg: OpenClawConfig;
currentChannelId?: string | null;
currentChannelProvider?: string | null;
currentThreadTs?: string | null;
currentMessageId?: string | number | null;
accountId?: string | null;
sessionKey?: string | null;
sessionId?: string | null;
agentId?: string | null;
requesterSenderId?: string | null;
senderIsOwner?: boolean;
};
/**
* Plugin-owned schema fragments for the shared `message` tool.
* `current-channel` means expose the fields only when that provider is the
* active runtime channel. `all-configured` keeps the fields visible even while
* another configured channel is active, which is useful for cross-channel
* sends from cron or isolated agents.
*/
export type ChannelMessageToolSchemaContribution = {
properties: Record<string, TSchema>;
/**
* Actions whose validation depends on this schema fragment. Cross-channel
* discovery can hide only these actions when the fragment is current-channel
* scoped. Omit to keep the legacy conservative behavior.
*/
actions?: readonly ChannelMessageActionName[] | null;
visibility?: "current-channel" | "all-configured";
};
type ChannelMessageToolMediaSourceParams =
| readonly string[]
| Partial<Record<ChannelMessageActionName, readonly string[]>>;
export type ChannelMessageToolDiscovery = {
actions?: readonly ChannelMessageActionName[] | null;
capabilities?: readonly ChannelMessageCapability[] | null;
schema?: ChannelMessageToolSchemaContribution | ChannelMessageToolSchemaContribution[] | null;
/**
* Plugin-owned message-tool params that carry media sources.
* Core uses this to derive sandbox path normalization and host media-access
* hints without hardcoding plugin-specific param names. Prefer scoping keys
* by action so unrelated actions do not inherit another action's media args.
*/
mediaSourceParams?: ChannelMessageToolMediaSourceParams | null;
};
/** Shared setup input bag used by CLI, onboarding, and setup adapters. */
export type ChannelSetupInput = {
name?: string;
token?: string;
privateKey?: string;
tokenFile?: string;
secret?: string;
secretFile?: string;
botToken?: string;
appToken?: string;
signalNumber?: string;
cliPath?: string;
dbPath?: string;
service?: "imessage" | "sms" | "auto";
region?: string;
authDir?: string;
httpUrl?: string;
httpHost?: string;
httpPort?: string;
webhookPath?: string;
webhookUrl?: string;
audienceType?: string;
audience?: string;
useEnv?: boolean;
homeserver?: string;
dangerouslyAllowPrivateNetwork?: boolean;
/** @deprecated Compatibility alias; prefer dangerouslyAllowPrivateNetwork. */
allowPrivateNetwork?: boolean;
proxy?: string;
userId?: string;
accessToken?: string;
password?: string;
deviceName?: string;
avatarUrl?: string;
initialSyncLimit?: number;
profile?: string;
ship?: string;
url?: string;
baseUrl?: string;
relayUrls?: string;
code?: string;
groupChannels?: string[];
dmAllowlist?: string[];
autoDiscoverChannels?: boolean;
};
export type ChannelStatusIssue = {
channel: ChannelId;
accountId: string;
kind: "intent" | "permissions" | "config" | "auth" | "runtime";
message: string;
fix?: string;
};
export type ChannelAccountState =
| "linked"
| "not linked"
| "configured"
| "not configured"
| "enabled"
| "disabled";
export type ChannelHeartbeatDeps = {
webAuthExists?: () => Promise<boolean>;
hasActiveWebListener?: (accountId?: string) => boolean;
};
/** User-facing metadata used in docs, pickers, and setup surfaces. */
export type ChannelMeta = {
id: ChannelId;
label: string;
selectionLabel: string;
docsPath: string;
docsLabel?: string;
blurb: string;
order?: number;
aliases?: readonly string[];
selectionDocsPrefix?: string;
selectionDocsOmitLabel?: boolean;
selectionExtras?: readonly string[];
detailLabel?: string;
systemImage?: string;
markdownCapable?: boolean;
exposure?: ChannelExposure;
showConfigured?: boolean;
showInSetup?: boolean;
quickstartAllowFrom?: boolean;
forceAccountBinding?: boolean;
preferSessionLookupForAnnounceTarget?: boolean;
preferOver?: readonly string[];
};
/** Snapshot row returned by channel status and lifecycle surfaces. */
export type ChannelAccountSnapshot = {
accountId: string;
name?: string;
enabled?: boolean;
configured?: boolean;
statusState?: string;
linked?: boolean;
running?: boolean;
connected?: boolean;
restartPending?: boolean;
reconnectAttempts?: number;
lastConnectedAt?: number | null;
lastDisconnect?:
| string
| {
at: number;
status?: number;
error?: string;
loggedOut?: boolean;
}
| null;
lastMessageAt?: number | null;
lastEventAt?: number | null;
lastTransportActivityAt?: number | null;
lastError?: string | null;
healthState?: string;
lastStartAt?: number | null;
lastStopAt?: number | null;
lastInboundAt?: number | null;
lastOutboundAt?: number | null;
busy?: boolean;
activeRuns?: number;
lastRunActivityAt?: number | null;
mode?: string;
dmPolicy?: string;
allowFrom?: string[];
tokenSource?: string;
botTokenSource?: string;
appTokenSource?: string;
signingSecretSource?: string;
tokenStatus?: string;
botTokenStatus?: string;
appTokenStatus?: string;
signingSecretStatus?: string;
userTokenStatus?: string;
credentialSource?: string;
secretSource?: string;
audienceType?: string;
audience?: string;
webhookPath?: string;
webhookUrl?: string;
baseUrl?: string;
allowUnmentionedGroups?: boolean;
cliPath?: string | null;
dbPath?: string | null;
port?: number | null;
probe?: unknown;
lastProbeAt?: number | null;
audit?: unknown;
application?: unknown;
bot?: unknown;
publicKey?: string | null;
profile?: unknown;
channelAccessToken?: string;
channelSecret?: string;
};
export type ChannelLogSink = {
info: (msg: string) => void;
warn: (msg: string) => void;
error: (msg: string) => void;
debug?: (msg: string) => void;
};
export type ChannelGroupContext = {
cfg: OpenClawConfig;
groupId?: string | null;
/** Human label for channel-like group conversations (e.g. #general). */
groupChannel?: string | null;
groupSpace?: string | null;
accountId?: string | null;
senderId?: string | null;
senderName?: string | null;
senderUsername?: string | null;
senderE164?: string | null;
};
/** TTS voice delivery behavior advertised by a channel plugin. */
/**
* Container tokens (file-extension shape, no leading dot) that the host
* speech-core pipeline knows how to pre-transcode synthesized audio into.
* Channels that benefit from a specific container — currently only
* iMessage, which needs Apple's native voice-memo CAF descriptor — name
* one here. Adding a new entry requires extending the host transcoder
* recipe table in lockstep so a typed declaration cannot silently no-op.
*/
export type PreferredAudioFileFormat = "caf";
export type ChannelTtsVoiceDeliveryCapabilities = {
synthesisTarget: "audio-file" | "voice-note";
transcodesAudio?: boolean;
audioFileFormats?: readonly string[];
/**
* Optional preferred audio container the channel wants for voice-memo
* delivery. When set and the host can transcode (e.g. `afconvert` on
* macOS), the TTS pipeline pre-encodes synthesized audio to this format
* before handing it to the channel. Useful for channels (such as
* iMessage) whose downstream attempts its own container conversion
* that races against the upload write and fails.
*/
preferAudioFileFormat?: PreferredAudioFileFormat;
};
/** Static capability flags advertised by a channel plugin. */
export type ChannelCapabilities = {
chatTypes: Array<ChatType | "thread">;
polls?: boolean;
reactions?: boolean;
edit?: boolean;
unsend?: boolean;
reply?: boolean;
effects?: boolean;
groupManagement?: boolean;
threads?: boolean;
media?: boolean;
tts?: {
voice?: ChannelTtsVoiceDeliveryCapabilities;
};
nativeCommands?: boolean;
blockStreaming?: boolean;
};
export type ChannelSecurityDmPolicy = {
policy: string;
allowFrom?: Array<string | number> | null;
policyPath?: string;
allowFromPath: string;
approveHint: string;
normalizeEntry?: (raw: string) => string;
};
export type ChannelSecurityContext<ResolvedAccount = unknown> = {
cfg: OpenClawConfig;
accountId?: string | null;
account: ResolvedAccount;
};
export type ChannelMentionAdapter = {
stripRegexes?: (params: {
ctx: MsgContext;
cfg: OpenClawConfig | undefined;
agentId?: string;
}) => RegExp[];
stripPatterns?: (params: {
ctx: MsgContext;
cfg: OpenClawConfig | undefined;
agentId?: string;
}) => string[];
stripMentions?: (params: {
text: string;
ctx: MsgContext;
cfg: OpenClawConfig | undefined;
agentId?: string;
}) => string;
};
export type ChannelStreamingAdapter = {
blockStreamingCoalesceDefaults?: {
minChars: number;
idleMs: number;
};
};
// Keep core transport-agnostic. Plugins can carry richer component types on
// their side and cast at the boundary.
export type ChannelStructuredComponents = unknown[];
export type ChannelCrossContextPresentationFactory = (params: {
originLabel: string;
message: string;
cfg: OpenClawConfig;
accountId?: string | null;
}) => MessagePresentation;
export type ChannelReplyTransport = {
replyToId?: string | null;
threadId?: string | number | null;
};
export type ChannelFocusedBindingContext = {
conversationId: string;
parentConversationId?: string;
placement: "current" | "child";
labelNoun: string;
};
export type ChannelOutboundSessionRoute = {
sessionKey: string;
baseSessionKey: string;
peer: {
kind: ChatType;
id: string;
};
chatType: "direct" | "group" | "channel";
from: string;
to: string;
threadId?: string | number;
};
export type ChannelThreadingAdapter = {
matchesToolContextTarget?: (params: {
target: string;
toolContext: ChannelThreadingToolContext;
}) => boolean;
resolveReplyToMode?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
chatType?: string | null;
}) => "off" | "first" | "all" | "batched";
/**
* When replyToMode is "off", allow explicit reply tags/directives to keep replyToId.
*
* Default in shared reply flow: true for known providers; per-channel opt-out supported.
*/
allowExplicitReplyTagsWhenOff?: boolean;
/**
* @deprecated Use allowExplicitReplyTagsWhenOff.
*
* Deprecated alias for allowExplicitReplyTagsWhenOff.
* Kept for compatibility with older plugin surfaces.
*/
allowTagsWhenOff?: boolean;
buildToolContext?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
context: ChannelThreadingContext;
hasRepliedRef?: { value: boolean };
}) => ChannelThreadingToolContext | undefined;
resolveAutoThreadId?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
to: string;
toolContext?: ChannelThreadingToolContext;
replyToId?: string | null;
}) => string | undefined;
resolveCurrentChannelId?: (params: {
to: string;
threadId?: string | number | null;
}) => string | undefined;
resolveReplyTransport?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
threadId?: string | number | null;
replyToId?: string | null;
/** True when replyToId came from an explicit payload target or reply tag. */
replyToIsExplicit?: boolean;
replyDelivery?: ReplyDeliveryContext;
}) => ChannelReplyTransport | null;
resolveFocusedBinding?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
context: ChannelThreadingContext;
}) => ChannelFocusedBindingContext | null;
};
export type ChannelThreadingContext = {
Channel?: string;
From?: string;
To?: string;
ChatType?: string;
CurrentMessageId?: string | number;
ReplyToId?: string;
ReplyToIdFull?: string;
ThreadLabel?: string;
MessageThreadId?: string | number;
TransportThreadId?: string | number;
/** Platform-native channel/conversation id (e.g. Slack DM channel "D…" id). */
NativeChannelId?: string;
};
export type ChannelThreadingToolContext = {
currentChannelId?: string;
/** Routable messaging target when it differs from the platform-native channel id. */
currentMessagingTarget?: string;
currentGraphChannelId?: string;
currentChannelProvider?: ChannelId;
currentThreadTs?: string;
currentMessageId?: string | number;
replyToMode?: "off" | "first" | "all" | "batched";
hasRepliedRef?: { value: boolean };
/** True when posting at the parent conversation root would leak a thread-originated reply. */
sameChannelThreadRequired?: boolean;
/**
* When true, skip cross-context decoration (e.g., "[from X]" prefix).
* Use this for direct tool invocations where the agent is composing a new message,
* not forwarding/relaying a message from another conversation.
*/
skipCrossContextDecoration?: boolean;
};
/** Channel-owned messaging helpers for target parsing, routing, and payload shaping. */
export type ChannelMessagingAdapter = {
/**
* Provider prefixes accepted in explicit targets, including aliases not used
* as channel-selection aliases. Core uses these to reject cross-channel
* targets before plugin-specific normalization.
*/
targetPrefixes?: readonly string[];
normalizeTarget?: (raw: string) => string | undefined;
defaultMarkdownTableMode?: MarkdownTableMode;
normalizeExplicitSessionKey?: (params: {
sessionKey: string;
ctx: MsgContext;
}) => string | undefined;
deriveLegacySessionChatType?: (sessionKey: string) => "direct" | "group" | "channel" | undefined;
isLegacyGroupSessionKey?: (key: string) => boolean;
canonicalizeLegacySessionKey?: (params: {
key: string;
agentId: string;
}) => string | null | undefined;
resolveLegacyGroupSessionKey?: (ctx: MsgContext) => {
key: string;
channel: string;
id: string;
chatType: "group" | "channel";
} | null;
resolveInboundAttachmentRoots?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
}) => string[];
resolveRemoteInboundAttachmentRoots?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
}) => string[];
/**
* Bundled plugins that need inbound conversation resolution before runtime
* bootstrap can mirror it through a top-level `thread-binding-api.ts` surface.
*/
resolveInboundConversation?: (params: {
from?: string;
to?: string;
conversationId?: string;
threadId?: string | number;
threadParentId?: string | number;
isGroup: boolean;
}) => {
conversationId?: string;
parentConversationId?: string;
} | null;
resolveDeliveryTarget?: (params: { conversationId: string; parentConversationId?: string }) => {
to?: string;
threadId?: string;
} | null;
/**
* Canonical plugin-owned session conversation grammar.
* Use this when the provider encodes thread or scoped-conversation semantics
* inside `rawId` (for example Telegram topics or Feishu sender scopes).
* Return `baseConversationId` and `parentConversationCandidates` here when
* you can so parsing and inheritance stay in one place.
* `parentConversationCandidates`, when present, should be ordered from the
* narrowest parent to the broadest/base conversation.
* Bundled plugins that need the same grammar before runtime bootstrap can
* mirror this contract through a top-level `session-key-api.ts` surface.
*/
resolveSessionConversation?: (params: { kind: "group" | "channel"; rawId: string }) => {
id: string;
threadId?: string | null;
baseConversationId?: string | null;
parentConversationCandidates?: string[];
} | null;
/**
* @deprecated Return parentConversationCandidates from resolveSessionConversation.
*
* Legacy compatibility hook for parent fallbacks when a plugin does not need
* to customize `id` or `threadId`. Core only uses this when
* `resolveSessionConversation(...)` does not return
* `parentConversationCandidates`.
*/
resolveParentConversationCandidates?: (params: {
kind: "group" | "channel";
rawId: string;
}) => string[] | null;
resolveSessionTarget?: (params: {
kind: "group" | "channel";
id: string;
threadId?: string | null;
}) => string | undefined;
/**
* @deprecated Use `targetResolver` for target id normalization and
* `resolveOutboundSessionRoute` for session/thread identity. This remains for
* compatibility with older route parsing helpers.
*/
parseExplicitTarget?: (params: { raw: string }) => {
to: string;
threadId?: string | number;
chatType?: ChatType;
} | null;
/**
* Lightweight chat-type inference used before directory lookup so plugins can
* steer peer-vs-group resolution without reimplementing host search flow.
*/
inferTargetChatType?: (params: { to: string }) => ChatType | undefined;
/**
* Preserve the session thread/topic id for heartbeat replies when that thread
* is part of the destination identity, not a transient reply thread.
*/
preserveHeartbeatThreadIdForGroupRoute?: boolean;
buildCrossContextPresentation?: ChannelCrossContextPresentationFactory;
transformReplyPayload?: (params: {
payload: ReplyPayload;
cfg: OpenClawConfig;
accountId?: string | null;
}) => ReplyPayload | null;
enableInteractiveReplies?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
}) => boolean;
hasStructuredReplyPayload?: (params: { payload: ReplyPayload }) => boolean;
targetResolver?: {
looksLikeId?: (raw: string, normalized?: string) => boolean;
hint?: string;
/** Bare words that are command/session references for this channel, not literal destinations. */
reservedLiterals?: readonly string[];
/**
* Plugin-owned fallback for explicit/native targets or post-directory-miss
* resolution. This should complement directory lookup, not duplicate it.
*/
resolveTarget?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
input: string;
normalized: string;
preferredKind?: ChannelDirectoryEntryKind | "channel";
}) => Promise<{
to: string;
kind: ChannelDirectoryEntryKind | "channel";
display?: string;
source?: "normalized" | "directory";
} | null>;
};
formatTargetDisplay?: (params: {
target: string;
display?: string;
kind?: ChannelDirectoryEntryKind;
}) => string;
/**
* Provider-specific session-route builder used after target resolution.
* Keep session-key orchestration in core and channel-native routing rules here.
*/
resolveOutboundSessionRoute?: (params: {
cfg: OpenClawConfig;
agentId: string;
accountId?: string | null;
target: string;
currentSessionKey?: string;
resolvedTarget?: {
to: string;
kind: ChannelDirectoryEntryKind | "channel";
display?: string;
source: "normalized" | "directory";
};
replyToId?: string | null;
threadId?: string | number | null;
}) => ChannelOutboundSessionRoute | Promise<ChannelOutboundSessionRoute | null> | null;
};
export type ChannelAgentPromptAdapter = {
messageToolHints?: (params: { cfg: OpenClawConfig; accountId?: string | null }) => string[];
messageToolCapabilities?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
}) => string[] | undefined;
inboundFormattingHints?: (params: { accountId?: string | null }) =>
| {
text_markup: string;
rules: string[];
}
| undefined;
reactionGuidance?: (params: {
cfg: OpenClawConfig;
accountId?: string | null;
}) => { level: "minimal" | "extensive"; channelLabel?: string } | undefined;
};
export type ChannelDirectoryEntryKind = "user" | "group" | "channel";
export type ChannelDirectoryEntry = {
kind: ChannelDirectoryEntryKind;
id: string;
name?: string;
handle?: string;
avatarUrl?: string;
rank?: number;
raw?: unknown;
};
export type ChannelMessageActionName = ChannelMessageActionNameFromList;
/** Execution context passed to channel-owned actions on the shared `message` tool. */
export type ChannelMessageActionContext = {
channel: ChannelId;
action: ChannelMessageActionName;
cfg: OpenClawConfig;
params: Record<string, unknown>;
mediaAccess?: OutboundMediaAccess;
mediaLocalRoots?: readonly string[];
mediaReadFile?: (filePath: string) => Promise<Buffer>;
accountId?: string | null;
/** Trusted originating account id paired with requesterSenderId. */
requesterAccountId?: string | null;
/**
* Trusted sender id from inbound context. This is server-injected and must
* never be sourced from tool/model-controlled params.
*/
requesterSenderId?: string | null;
/** Trusted owner identity bit from command/channel-action auth. */
senderIsOwner?: boolean;
sessionKey?: string | null;
sessionId?: string | null;
inboundEventKind?: InboundEventKind;
agentId?: string | null;
gateway?: {
url?: string;
token?: string;
timeoutMs?: number;
clientName: GatewayClientName;
clientDisplayName?: string;
mode: GatewayClientMode;
};
toolContext?: ChannelThreadingToolContext;
dryRun?: boolean;
gatewayClientScopes?: readonly string[];
};
export type ChannelToolSend = {
to: string;
accountId?: string | null;
threadId?: string | null;
/** True when the native provider send may inherit the active conversation thread. */
threadImplicit?: boolean;
threadSuppressed?: boolean;
};
export type ChannelMessagePreparedSendPayloadContext = {
ctx: ChannelMessageActionContext;
to: string;
payload: ReplyPayload;
replyToId?: string | null;
threadId?: string | number | null;
};
/** Channel-owned action surface for the shared `message` tool. */
export type ChannelMessageActionAdapter = {
/**
* Unified discovery surface for the shared `message` tool.
* This returns the scoped actions,
* capabilities, schema fragments, and any plugin-owned media-source params
* together so they cannot drift.
*/
describeMessageTool: (
params: ChannelMessageActionDiscoveryContext,
) => ChannelMessageToolDiscovery | null | undefined;
supportsAction?: (params: { action: ChannelMessageActionName }) => boolean;
resolveExecutionMode?: (params: { action: ChannelMessageActionName }) => "local" | "gateway";
resolveCliActionRequest?: (params: {
action: ChannelMessageActionName;
args: Record<string, unknown>;
}) => {
action: ChannelMessageActionName;
args: Record<string, unknown>;
};
messageActionTargetAliases?: Partial<
Record<
ChannelMessageActionName,
{
aliases: string[];
/** Alias fields that identify the destination conversation, not an existing message. */
deliveryTargetAliases?: string[];
}
>
>;
requiresTrustedRequesterSender?: (params: {
action: ChannelMessageActionName;
toolContext?: ChannelThreadingToolContext;
}) => boolean;
/** Return true when a provider-native tool invocation has a visible or destructive side effect. */
isToolDeliveryAction?: (params: { args: Record<string, unknown> }) => boolean;
extractToolSend?: (params: { args: Record<string, unknown> }) => ChannelToolSend | null;
/** Recover the actual resolved send route from a successful action result. */
extractToolSendResult?: (params: {
result: unknown;
send: ChannelToolSend;
}) => ChannelToolSend | null;
/**
* Translate generic `message(action=send)` arguments into the payload core
* should persist, retry, recover, and ack. Return null to keep the legacy
* plugin-owned action path for sends that cannot be represented durably.
*/
prepareSendPayload?: (
params: ChannelMessagePreparedSendPayloadContext,
) => ReplyPayload | null | undefined | Promise<ReplyPayload | null | undefined>;
/**
* Prefer this for channel-specific poll semantics or extra poll parameters.
* Core only parses the shared poll model when falling back to `outbound.sendPoll`.
*/
handleAction?: (ctx: ChannelMessageActionContext) => Promise<AgentToolResult<unknown>>;
};
export type ChannelPollResult = {
messageId: string;
toJid?: string;
channelId?: string;
conversationId?: string;
pollId?: string;
};
/** Shared poll input after core has normalized the common poll model. */
export type ChannelPollContext = {
cfg: OpenClawConfig;
to: string;
poll: PollInput;
accountId?: string | null;
threadId?: string | null;
silent?: boolean;
isAnonymous?: boolean;
gatewayClientScopes?: readonly string[];
};
/** Minimal base for all channel probe results. Channel-specific probes extend this. */
export type BaseProbeResult<TError = string | null> = {
ok: boolean;
error?: TError;
};
/** Minimal base for token resolution results. */
export type BaseTokenResolution = {
token: string;
source: string;
};