fix: harden compat and editor ctor
This commit is contained in:
@@ -9,9 +9,11 @@ export function normalizeModelCompat(model: Model<Api>): Model<Api> {
|
|||||||
const isZai = model.provider === "zai" || baseUrl.includes("api.z.ai");
|
const isZai = model.provider === "zai" || baseUrl.includes("api.z.ai");
|
||||||
if (!isZai || !isOpenAiCompletionsModel(model)) return model;
|
if (!isZai || !isOpenAiCompletionsModel(model)) return model;
|
||||||
|
|
||||||
const compat = model.compat ?? {};
|
const compat = model.compat as { supportsDeveloperRole?: boolean } | undefined;
|
||||||
if (compat.supportsDeveloperRole === false) return model;
|
if (compat?.supportsDeveloperRole === false) return model;
|
||||||
|
|
||||||
model.compat = { ...compat, supportsDeveloperRole: false };
|
model.compat = compat
|
||||||
|
? { ...compat, supportsDeveloperRole: false }
|
||||||
|
: { supportsDeveloperRole: false };
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,12 @@ export class CustomEditor extends Editor {
|
|||||||
onShiftTab?: () => void;
|
onShiftTab?: () => void;
|
||||||
onAltEnter?: () => void;
|
onAltEnter?: () => void;
|
||||||
|
|
||||||
constructor(tui: TUI, theme: EditorTheme) {
|
constructor(tuiOrTheme: TUI | EditorTheme, themeMaybe?: EditorTheme) {
|
||||||
super(tui, theme);
|
const useTui = typeof themeMaybe !== "undefined" && Editor.length >= 2;
|
||||||
|
const args = (useTui ? [tuiOrTheme, themeMaybe] : [tuiOrTheme]) as ConstructorParameters<
|
||||||
|
typeof Editor
|
||||||
|
>;
|
||||||
|
super(...args);
|
||||||
}
|
}
|
||||||
handleInput(data: string): void {
|
handleInput(data: string): void {
|
||||||
if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) {
|
if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user