mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-14 03:20:49 +00:00
* feat: per-channel responsePrefix override
Add responsePrefix field to all channel config types and Zod schemas,
enabling per-channel and per-account outbound response prefix overrides.
Resolution cascade (most specific wins):
L1: channels.<ch>.accounts.<id>.responsePrefix
L2: channels.<ch>.responsePrefix
L3: (reserved for channels.defaults)
L4: messages.responsePrefix (existing global)
Semantics:
- undefined -> inherit from parent level
- empty string -> explicitly no prefix (stops cascade)
- "auto" -> derive [identity.name] from routed agent
Changes:
- Core logic: resolveResponsePrefix() in identity.ts accepts
optional channel/accountId and walks the cascade
- resolveEffectiveMessagesConfig() passes channel context through
- Types: responsePrefix added to WhatsApp, Telegram, Discord, Slack,
Signal, iMessage, Google Chat, MS Teams, Feishu, BlueBubbles configs
- Zod schemas: responsePrefix added for config validation
- All channel handlers wired: telegram, discord, slack, signal,
imessage, line, heartbeat runner, route-reply, native commands
- 23 new tests covering backward compat, channel/account levels,
full cascade, auto keyword, empty string stops, unknown fallthrough
Fully backward compatible - no existing config is affected.
Fixes #8857
* fix: address CI lint + review feedback
- Replace Record<string, any> with proper typed helpers (no-explicit-any)
- Add curly braces to single-line if returns (eslint curly)
- Fix JSDoc: 'Per-channel' → 'channel/account' on shared config types
- Extract getChannelConfig() helper for type-safe dynamic key access
* fix: finish responsePrefix overrides (#9001) (thanks @mudrii)
* fix: normalize prefix wiring and types (#9001) (thanks @mudrii)
---------
Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import {
|
|
BlockStreamingCoalesceSchema,
|
|
DmConfigSchema,
|
|
DmPolicySchema,
|
|
GroupPolicySchema,
|
|
MarkdownConfigSchema,
|
|
ToolPolicySchema,
|
|
requireOpenAllowFrom,
|
|
} from "openclaw/plugin-sdk";
|
|
import { z } from "zod";
|
|
|
|
export const NextcloudTalkRoomSchema = z
|
|
.object({
|
|
requireMention: z.boolean().optional(),
|
|
tools: ToolPolicySchema,
|
|
skills: z.array(z.string()).optional(),
|
|
enabled: z.boolean().optional(),
|
|
allowFrom: z.array(z.string()).optional(),
|
|
systemPrompt: z.string().optional(),
|
|
})
|
|
.strict();
|
|
|
|
export const NextcloudTalkAccountSchemaBase = z
|
|
.object({
|
|
name: z.string().optional(),
|
|
enabled: z.boolean().optional(),
|
|
markdown: MarkdownConfigSchema,
|
|
baseUrl: z.string().optional(),
|
|
botSecret: z.string().optional(),
|
|
botSecretFile: z.string().optional(),
|
|
apiUser: z.string().optional(),
|
|
apiPassword: z.string().optional(),
|
|
apiPasswordFile: z.string().optional(),
|
|
dmPolicy: DmPolicySchema.optional().default("pairing"),
|
|
webhookPort: z.number().int().positive().optional(),
|
|
webhookHost: z.string().optional(),
|
|
webhookPath: z.string().optional(),
|
|
webhookPublicUrl: z.string().optional(),
|
|
allowFrom: z.array(z.string()).optional(),
|
|
groupAllowFrom: z.array(z.string()).optional(),
|
|
groupPolicy: GroupPolicySchema.optional().default("allowlist"),
|
|
rooms: z.record(z.string(), NextcloudTalkRoomSchema.optional()).optional(),
|
|
historyLimit: z.number().int().min(0).optional(),
|
|
dmHistoryLimit: z.number().int().min(0).optional(),
|
|
dms: z.record(z.string(), DmConfigSchema.optional()).optional(),
|
|
textChunkLimit: z.number().int().positive().optional(),
|
|
chunkMode: z.enum(["length", "newline"]).optional(),
|
|
blockStreaming: z.boolean().optional(),
|
|
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
|
|
responsePrefix: z.string().optional(),
|
|
mediaMaxMb: z.number().positive().optional(),
|
|
})
|
|
.strict();
|
|
|
|
export const NextcloudTalkAccountSchema = NextcloudTalkAccountSchemaBase.superRefine(
|
|
(value, ctx) => {
|
|
requireOpenAllowFrom({
|
|
policy: value.dmPolicy,
|
|
allowFrom: value.allowFrom,
|
|
ctx,
|
|
path: ["allowFrom"],
|
|
message:
|
|
'channels.nextcloud-talk.dmPolicy="open" requires channels.nextcloud-talk.allowFrom to include "*"',
|
|
});
|
|
},
|
|
);
|
|
|
|
export const NextcloudTalkConfigSchema = NextcloudTalkAccountSchemaBase.extend({
|
|
accounts: z.record(z.string(), NextcloudTalkAccountSchema.optional()).optional(),
|
|
}).superRefine((value, ctx) => {
|
|
requireOpenAllowFrom({
|
|
policy: value.dmPolicy,
|
|
allowFrom: value.allowFrom,
|
|
ctx,
|
|
path: ["allowFrom"],
|
|
message:
|
|
'channels.nextcloud-talk.dmPolicy="open" requires channels.nextcloud-talk.allowFrom to include "*"',
|
|
});
|
|
});
|