fix: repair model compat + editor ctor
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type { Api, Model } from "@mariozechner/pi-ai";
|
import type { Api, Model, OpenAICompletionsCompat } from "@mariozechner/pi-ai";
|
||||||
|
|
||||||
function isOpenAiCompletionsModel(model: Model<Api>): model is Model<"openai-completions"> {
|
function isOpenAiCompletionsModel(model: Model<Api>): model is Model<"openai-completions"> {
|
||||||
return model.api === "openai-completions";
|
return model.api === "openai-completions";
|
||||||
@@ -9,11 +9,12 @@ 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 as { supportsDeveloperRole?: boolean } | undefined;
|
const openaiModel = model as Model<"openai-completions">;
|
||||||
|
const compat = openaiModel.compat as OpenAICompletionsCompat | undefined;
|
||||||
if (compat?.supportsDeveloperRole === false) return model;
|
if (compat?.supportsDeveloperRole === false) return model;
|
||||||
|
|
||||||
model.compat = compat
|
openaiModel.compat = compat
|
||||||
? { ...compat, supportsDeveloperRole: false }
|
? { ...compat, supportsDeveloperRole: false }
|
||||||
: { supportsDeveloperRole: false };
|
: { supportsDeveloperRole: false };
|
||||||
return model;
|
return openaiModel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import { Editor, type EditorTheme, Key, matchesKey, type TUI } from "@mariozechner/pi-tui";
|
import {
|
||||||
|
Editor,
|
||||||
|
type EditorOptions,
|
||||||
|
type EditorTheme,
|
||||||
|
Key,
|
||||||
|
matchesKey,
|
||||||
|
type TUI,
|
||||||
|
} from "@mariozechner/pi-tui";
|
||||||
|
|
||||||
export class CustomEditor extends Editor {
|
export class CustomEditor extends Editor {
|
||||||
onEscape?: () => void;
|
onEscape?: () => void;
|
||||||
@@ -12,11 +19,8 @@ export class CustomEditor extends Editor {
|
|||||||
onShiftTab?: () => void;
|
onShiftTab?: () => void;
|
||||||
onAltEnter?: () => void;
|
onAltEnter?: () => void;
|
||||||
|
|
||||||
constructor(tuiOrTheme: TUI | EditorTheme, themeMaybe?: EditorTheme) {
|
constructor(tui: TUI, theme: EditorTheme, options?: EditorOptions) {
|
||||||
const useLegacyCtor = typeof themeMaybe !== "undefined" && Editor.length >= 2;
|
super(tui, theme, options);
|
||||||
const args = (useLegacyCtor ? [tuiOrTheme, themeMaybe] : [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) {
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ export async function runTui(opts: TuiOptions) {
|
|||||||
const statusContainer = new Container();
|
const statusContainer = new Container();
|
||||||
const footer = new Text("", 1, 0);
|
const footer = new Text("", 1, 0);
|
||||||
const chatLog = new ChatLog();
|
const chatLog = new ChatLog();
|
||||||
const editor = new CustomEditor(editorTheme);
|
const editor = new CustomEditor(tui, editorTheme);
|
||||||
const root = new Container();
|
const root = new Container();
|
||||||
root.addChild(header);
|
root.addChild(header);
|
||||||
root.addChild(chatLog);
|
root.addChild(chatLog);
|
||||||
|
|||||||
Reference in New Issue
Block a user