mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-02 05:31:02 +00:00
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:
parent
2985201317
commit
615ccd08f2
3 changed files with 67 additions and 14 deletions
|
|
@ -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})...`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue