diff --git a/src/auto-reply/commands-args.ts b/src/auto-reply/commands-args.ts index 63f73c468..7122d5457 100644 --- a/src/auto-reply/commands-args.ts +++ b/src/auto-reply/commands-args.ts @@ -4,14 +4,20 @@ export type CommandArgsFormatter = (values: CommandArgValues) => string | undefi function normalizeArgValue(value: unknown): string | undefined { if (value == null) return undefined; + let text: string; if (typeof value === "string") { - const trimmed = value.trim(); - return trimmed ? trimmed : undefined; + text = value.trim(); + } else if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") { + text = String(value).trim(); + } else if (typeof value === "symbol") { + text = value.toString().trim(); + } else if (typeof value === "function") { + text = value.toString().trim(); + } else { + // Objects and arrays + text = JSON.stringify(value); } - if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") { - return String(value); - } - return undefined; + return text ? text : undefined; } const formatConfigArgs: CommandArgsFormatter = (values) => { diff --git a/src/auto-reply/commands-registry.ts b/src/auto-reply/commands-registry.ts index 5edc677d2..4da2f9869 100644 --- a/src/auto-reply/commands-registry.ts +++ b/src/auto-reply/commands-registry.ts @@ -137,13 +137,25 @@ function formatPositionalArgs( for (const definition of definitions) { const value = values[definition.name]; if (value == null) continue; + let rendered: string; if (typeof value === "string") { - const trimmed = value.trim(); - if (!trimmed) continue; - parts.push(trimmed); - } else if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") { - parts.push(String(value)); + rendered = value.trim(); + } else if ( + typeof value === "number" || + typeof value === "boolean" || + typeof value === "bigint" + ) { + rendered = String(value); + } else if (typeof value === "symbol") { + rendered = value.toString(); + } else if (typeof value === "function") { + rendered = value.toString(); + } else { + // Objects and arrays + rendered = JSON.stringify(value); } + if (!rendered) continue; + parts.push(rendered); if (definition.captureRemaining) break; } return parts.length > 0 ? parts.join(" ") : undefined; diff --git a/src/auto-reply/templating.ts b/src/auto-reply/templating.ts index e110e5a9b..647088460 100644 --- a/src/auto-reply/templating.ts +++ b/src/auto-reply/templating.ts @@ -84,6 +84,9 @@ function formatTemplateValue(value: unknown): string { if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") { return String(value); } + if (typeof value === "symbol" || typeof value === "function") { + return value.toString(); + } if (Array.isArray(value)) { return value .flatMap((entry) => { @@ -96,6 +99,9 @@ function formatTemplateValue(value: unknown): string { }) .join(","); } + if (typeof value === "object") { + return JSON.stringify(value); + } return ""; }