mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
* refactor(google): share oauth token helpers * refactor(xai): share tool auth fallback helpers * refactor(xai): share tool auth resolution * refactor(xai): share tool config helpers * refactor(xai): share fallback auth helpers * refactor(xai): share responses tool helpers * refactor(google): share http request config helper * fix(xai): re-export shared web search extractor * fix(xai): import plugin config type * fix(providers): preserve default google network guard
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { normalizeXaiModelId } from "../model-id.js";
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
}
|
|
|
|
export function coerceXaiToolConfig<TConfig extends Record<string, unknown>>(
|
|
config: Record<string, unknown> | undefined,
|
|
): TConfig {
|
|
return isRecord(config) ? (config as TConfig) : ({} as TConfig);
|
|
}
|
|
|
|
export function resolveNormalizedXaiToolModel(params: {
|
|
config?: Record<string, unknown>;
|
|
defaultModel: string;
|
|
}): string {
|
|
const value = coerceXaiToolConfig<{ model?: unknown }>(params.config).model;
|
|
return typeof value === "string" && value.trim()
|
|
? normalizeXaiModelId(value.trim())
|
|
: params.defaultModel;
|
|
}
|
|
|
|
export function resolvePositiveIntegerToolConfig(
|
|
config: Record<string, unknown> | undefined,
|
|
key: string,
|
|
): number | undefined {
|
|
const raw = coerceXaiToolConfig<Record<string, unknown>>(config)[key];
|
|
if (typeof raw !== "number" || !Number.isFinite(raw)) {
|
|
return undefined;
|
|
}
|
|
const normalized = Math.trunc(raw);
|
|
return normalized > 0 ? normalized : undefined;
|
|
}
|