refactor: dedupe qqbot config record helper

This commit is contained in:
Peter Steinberger
2026-04-07 00:01:34 +01:00
parent ad8341676e
commit 13d1fc077b
3 changed files with 15 additions and 22 deletions

View File

@@ -0,0 +1,13 @@
export function asRecord(value: unknown): Record<string, unknown> | undefined {
return typeof value === "object" && value !== null
? (value as Record<string, unknown>)
: undefined;
}
export function readString(
record: Record<string, unknown> | undefined,
key: string,
): string | undefined {
const value = record?.[key];
return typeof value === "string" ? value : undefined;
}

View File

@@ -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<string, unknown> | undefined {
return typeof value === "object" && value !== null
? (value as Record<string, unknown>)
: undefined;
}
function readString(record: Record<string, unknown> | undefined, key: string): string | undefined {
const value = record?.[key];
return typeof value === "string" ? value : undefined;
}
export function resolveSTTConfig(cfg: Record<string, unknown>): STTConfig | null {
const channels = asRecord(cfg.channels);
const qqbot = asRecord(channels?.qqbot);

View File

@@ -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<string, unknown> | undefined {
return typeof value === "object" && value !== null
? (value as Record<string, unknown>)
: undefined;
}
function readString(record: Record<string, unknown> | undefined, key: string): string | undefined {
const value = record?.[key];
return typeof value === "string" ? value : undefined;
}
function readNumber(record: Record<string, unknown> | undefined, key: string): number | undefined {
const value = record?.[key];
return typeof value === "number" ? value : undefined;