UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

179 lines (178 loc) 7.89 kB
//#region src/plugin-sdk/channel-config-ui-hints.ts function createChannelDmPolicyUiHints(params) { const hint = { label: `${params.channelLabel} DM Policy`, help: `Direct message access control ("pairing" recommended). "open" requires channels.${params.channelKey}.allowFrom=["*"].` }; const legacyHint = { "dm.policy": { label: hint.label, help: `${hint.help.slice(0, -1)} (legacy: channels.${params.channelKey}.dm.allowFrom).` } }; if (!params.includeLegacyNestedPolicy) return { dmPolicy: hint }; return params.legacyNestedPolicyOrder === "after" ? { dmPolicy: hint, ...legacyHint } : { ...legacyHint, dmPolicy: hint }; } function createChannelConfigWritesUiHint(channelLabel) { return { configWrites: { label: `${channelLabel} Config Writes`, help: `Allow ${channelLabel} to write config in response to channel events/commands (default: true).` } }; } function createChannelMentionPatternUiHints(params) { const policySuffix = params.policyNote ? ` ${params.policyNote}` : ""; const denySuffix = params.denyNote ? ` ${params.denyNote}` : ""; return { mentionPatterns: { label: `${params.channelLabel} Mention Pattern Policy`, help: `Scopes configured groupChat mentionPatterns to selected ${params.policyTargetDescription ?? params.targetDescription}.${policySuffix}` }, "mentionPatterns.mode": { label: `${params.channelLabel} Mention Pattern Mode`, help: "\"allow\" enables configured regex mention patterns unless denyIn matches; \"deny\" disables them unless allowIn matches." }, "mentionPatterns.allowIn": { label: `${params.channelLabel} Mention Pattern Allowlist`, help: `${params.targetDescription} where configured regex mention patterns are enabled when mode is deny.` }, "mentionPatterns.denyIn": { label: `${params.channelLabel} Mention Pattern Denylist`, help: `${params.targetDescription} where configured regex mention patterns are disabled.${denySuffix}` } }; } function createChannelNativeCommandUiHints(channelLabel) { return { "commands.native": { label: `${channelLabel} Native Commands`, help: `Override native commands for ${channelLabel} (bool or "auto").` }, "commands.nativeSkills": { label: `${channelLabel} Native Skill Commands`, help: `Override native skill commands for ${channelLabel} (bool or "auto").` } }; } function createChannelImplicitMentionsUiHints(channelLabel) { return { implicitMentions: { label: `${channelLabel} Implicit Mentions`, help: `Control which ${channelLabel} reply, quote, and thread-participation signals count as mentions. Unset flags preserve the channel defaults.` }, "implicitMentions.replyToBot": { label: `${channelLabel} Replies to Bot`, help: "Treat replies to the bot's own messages as implicit mentions when the channel reports that signal." }, "implicitMentions.quotedBot": { label: `${channelLabel} Quoted Bot Messages`, help: "Treat messages quoting the bot as implicit mentions when the channel reports that signal." }, "implicitMentions.threadParticipation": { label: `${channelLabel} Thread Participation`, help: "Treat follow-ups in threads where the bot participated as implicit mentions when the channel reports that signal." } }; } function createChannelProgressUiHints(params) { const channelLabel = params.channelLabel; const commentaryHint = { "streaming.progress.commentary": { label: `${channelLabel} Progress Commentary`, help: "Show assistant commentary/preamble text in the temporary progress draft. Final answer delivery is unchanged." } }; return { "streaming.progress.label": { label: `${channelLabel} Progress Label`, help: `Initial progress ${params.titleWording ? "title" : "draft title"}. Use "auto" for built-in single-word labels, a custom string, or false to hide the title.` }, "streaming.progress.labels": { label: `${channelLabel} Progress Label Pool`, help: params.labels === "openclaw" ? "Candidate labels for streaming.progress.label=\"auto\". Leave unset to use OpenClaw built-in progress labels." : "Candidate labels for streaming.progress.label=\"auto\". Leave unset to use the built-in \"Working\" label." }, "streaming.progress.maxLines": { label: `${channelLabel} Progress Max Lines`, help: `Maximum number of compact progress lines to keep below the ${params.titleWording ? "progress title" : "draft label"} (default: 8).` }, "streaming.progress.maxLineChars": { label: `${channelLabel} Progress Max Line Chars`, help: "Maximum characters per compact progress line before truncation (default: 120). Prose cuts at word boundaries; commands and paths keep useful suffixes." }, "streaming.progress.toolProgress": { label: `${channelLabel} Progress Tool Lines`, help: "Show individual tool activity in progress drafts (default: false). Quiet drafts retain plans, approval requests, failures, and authored progress text." }, ...params.includeCommentary && params.commentaryOrder !== "after-command" ? commentaryHint : {}, "streaming.progress.commandText": { label: `${channelLabel} Progress Command Text`, help: `Command/exec detail in progress${params.titleWording ? "" : " draft"} lines: "status" is the safe default; "raw" opts into command text.` }, ...params.includeCommentary && params.commentaryOrder === "after-command" ? commentaryHint : {} }; } const STREAMING_HINT_LABELS = { "": "Streaming Mode", mode: "Streaming Mode", chunkMode: "Chunk Mode", "block.enabled": "Block Streaming Enabled", "block.coalesce": "Block Streaming Coalesce", nativeTransport: "Native Streaming", "preview.chunk.minChars": "Draft Chunk Min Chars", "preview.chunk.maxChars": "Draft Chunk Max Chars", "preview.chunk.breakPreference": "Draft Chunk Break Preference", "preview.toolProgress": "Draft Tool Progress", "preview.commandText": "Draft Command Text", "progress.style": "Progress Style", "progress.nativeTaskCards": "Native Progress Task Cards" }; function createChannelStreamingUiHints(channelLabel, entries) { return Object.fromEntries(Object.entries(entries).map(([key, value]) => [key ? `streaming.${key}` : "streaming", typeof value === "string" ? { label: `${channelLabel} ${STREAMING_HINT_LABELS[key]}`, help: value } : value])); } function createChannelRetryUiHints(channelLabel) { return { "retry.attempts": { label: `${channelLabel} Retry Attempts`, help: `Max retry attempts for outbound ${channelLabel} API calls (default: 3).` }, "retry.minDelayMs": { label: `${channelLabel} Retry Min Delay (ms)`, help: `Minimum retry delay in ms for ${channelLabel} outbound calls.` }, "retry.maxDelayMs": { label: `${channelLabel} Retry Max Delay (ms)`, help: `Maximum retry delay cap in ms for ${channelLabel} outbound calls.` }, "retry.jitter": { label: `${channelLabel} Retry Jitter`, help: `Jitter factor (0-1) applied to ${channelLabel} retry delays.` } }; } function createChannelConfigUiHints(params) { return { ...params.dmPolicy ? createChannelDmPolicyUiHints({ channelLabel: params.channelLabel, ...params.dmPolicy }) : {}, ...params.configWrites ? createChannelConfigWritesUiHint(params.channelLabel) : {}, ...params.mentionPatterns ? createChannelMentionPatternUiHints({ channelLabel: params.channelLabel, ...params.mentionPatterns }) : {}, ...params.nativeCommands ? createChannelNativeCommandUiHints(params.channelLabel) : {}, ...params.implicitMentions ? createChannelImplicitMentionsUiHints(params.channelLabel) : {}, ...params.streaming ? createChannelStreamingUiHints(params.channelLabel, params.streaming) : {}, ...params.progress ? createChannelProgressUiHints({ channelLabel: params.channelLabel, ...params.progress }) : {}, ...params.retry ? createChannelRetryUiHints(params.channelLabel) : {} }; } //#endregion export { createChannelConfigUiHints as t };