mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe qqbot config record helper
This commit is contained in:
13
extensions/qqbot/src/config-record-shared.ts
Normal file
13
extensions/qqbot/src/config-record-shared.ts
Normal 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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user