mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-22 06:08:13 +00:00
Consolidate shared plugin runtime MIME/schema helpers, preserve canonical runtime behavior, and guard QQBot STT fetches.
34 lines
962 B
TypeScript
34 lines
962 B
TypeScript
import { Type } from "typebox";
|
|
|
|
type StringEnumOptions<T extends readonly string[]> = {
|
|
description?: string;
|
|
title?: string;
|
|
default?: T[number];
|
|
deprecated?: boolean;
|
|
};
|
|
|
|
// Avoid Type.Union([Type.Literal(...)]) which compiles to anyOf.
|
|
// Some providers reject anyOf in tool schemas; a flat string enum is safer.
|
|
export function stringEnum<T extends readonly string[]>(
|
|
values: T,
|
|
options: StringEnumOptions<T> = {},
|
|
) {
|
|
const enumValues = Array.isArray(values)
|
|
? values
|
|
: values && typeof values === "object"
|
|
? Object.values(values).filter((value): value is T[number] => typeof value === "string")
|
|
: [];
|
|
return Type.Unsafe<T[number]>({
|
|
type: "string",
|
|
...(enumValues.length > 0 ? { enum: [...enumValues] } : {}),
|
|
...options,
|
|
});
|
|
}
|
|
|
|
export function optionalStringEnum<T extends readonly string[]>(
|
|
values: T,
|
|
options: StringEnumOptions<T> = {},
|
|
) {
|
|
return Type.Optional(stringEnum(values, options));
|
|
}
|