feat(channels): add config validation, instructions, and sessionScope support

- Validate required fields (type, token) with clear error messages
- Prepend channel instructions to first prompt of each session
- SessionRouter respects sessionScope (user/thread/single) for routing keys
This commit is contained in:
tanzhenxin 2026-03-24 06:20:16 +00:00
parent 2985201317
commit 615ccd08f2
3 changed files with 67 additions and 14 deletions

View file

@ -54,9 +54,42 @@ export const startCommand: CommandModule<object, { name: string }> = {
}
const rawConfig = channels[name] as Record<string, unknown>;
// Validate required fields
if (!rawConfig['type']) {
writeStderrLine(
`Error: Channel "${name}" is missing required field "type".`,
);
process.exit(1);
}
if (!rawConfig['token']) {
writeStderrLine(
`Error: Channel "${name}" is missing required field "token".`,
);
process.exit(1);
}
const channelType = rawConfig['type'] as string;
if (channelType !== 'telegram') {
writeStderrLine(
`Error: Channel type "${channelType}" is not yet supported. Only "telegram" is available.`,
);
process.exit(1);
}
let token: string;
try {
token = resolveEnvVars(rawConfig['token'] as string);
} catch (err) {
writeStderrLine(
`Error: ${err instanceof Error ? err.message : String(err)}`,
);
process.exit(1);
}
const config: ChannelConfig = {
type: rawConfig['type'] as ChannelConfig['type'],
token: resolveEnvVars(rawConfig['token'] as string),
type: channelType as ChannelConfig['type'],
token,
senderPolicy:
(rawConfig['senderPolicy'] as ChannelConfig['senderPolicy']) ||
'allowlist',
@ -68,13 +101,6 @@ export const startCommand: CommandModule<object, { name: string }> = {
instructions: rawConfig['instructions'] as string | undefined,
};
if (config.type !== 'telegram') {
writeStderrLine(
`Error: Channel type "${config.type}" is not yet supported. Only "telegram" is available.`,
);
process.exit(1);
}
const cliEntryPath = findCliEntryPath();
writeStdoutLine(`[Channel] CLI entry: ${cliEntryPath}`);
writeStdoutLine(`[Channel] Starting "${name}" (type=${config.type})...`);