From 13d1fc077bfd6451eb1682e7b36b2f938b82f797 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 00:01:34 +0100 Subject: [PATCH] refactor: dedupe qqbot config record helper --- extensions/qqbot/src/config-record-shared.ts | 13 +++++++++++++ extensions/qqbot/src/stt.ts | 12 +----------- extensions/qqbot/src/utils/audio-convert.ts | 12 +----------- 3 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 extensions/qqbot/src/config-record-shared.ts diff --git a/extensions/qqbot/src/config-record-shared.ts b/extensions/qqbot/src/config-record-shared.ts new file mode 100644 index 00000000000..1c0f1951fe2 --- /dev/null +++ b/extensions/qqbot/src/config-record-shared.ts @@ -0,0 +1,13 @@ +export function asRecord(value: unknown): Record | undefined { + return typeof value === "object" && value !== null + ? (value as Record) + : undefined; +} + +export function readString( + record: Record | undefined, + key: string, +): string | undefined { + const value = record?.[key]; + return typeof value === "string" ? value : undefined; +} diff --git a/extensions/qqbot/src/stt.ts b/extensions/qqbot/src/stt.ts index 529b3d13e26..e8988f8ce28 100644 --- a/extensions/qqbot/src/stt.ts +++ b/extensions/qqbot/src/stt.ts @@ -6,6 +6,7 @@ import * as fs from "node:fs"; import path from "node:path"; +import { asRecord, readString } from "./config-record-shared.js"; import { sanitizeFileName } from "./utils/platform.js"; export interface STTConfig { @@ -14,17 +15,6 @@ export interface STTConfig { model: string; } -function asRecord(value: unknown): Record | undefined { - return typeof value === "object" && value !== null - ? (value as Record) - : undefined; -} - -function readString(record: Record | undefined, key: string): string | undefined { - const value = record?.[key]; - return typeof value === "string" ? value : undefined; -} - export function resolveSTTConfig(cfg: Record): STTConfig | null { const channels = asRecord(cfg.channels); const qqbot = asRecord(channels?.qqbot); diff --git a/extensions/qqbot/src/utils/audio-convert.ts b/extensions/qqbot/src/utils/audio-convert.ts index d3e66cca42a..0bf8838fdc3 100644 --- a/extensions/qqbot/src/utils/audio-convert.ts +++ b/extensions/qqbot/src/utils/audio-convert.ts @@ -2,6 +2,7 @@ import { execFile } from "node:child_process"; import * as fs from "node:fs"; import * as path from "node:path"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; +import { asRecord, readString } from "../config-record-shared.js"; import { debugLog, debugError, debugWarn } from "./debug-log.js"; import { detectFfmpeg, isWindows } from "./platform.js"; @@ -207,17 +208,6 @@ type QQBotTtsBlock = QQBotTtsProviderConfig & { speed?: number; }; -function asRecord(value: unknown): Record | undefined { - return typeof value === "object" && value !== null - ? (value as Record) - : undefined; -} - -function readString(record: Record | undefined, key: string): string | undefined { - const value = record?.[key]; - return typeof value === "string" ? value : undefined; -} - function readNumber(record: Record | undefined, key: string): number | undefined { const value = record?.[key]; return typeof value === "number" ? value : undefined;