From 0b0d8b24069c75e5c56163a8f189030f8ba6e7fd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 20 Jan 2026 16:19:46 +0000 Subject: [PATCH] fix: repair model compat + editor ctor --- src/agents/model-compat.ts | 9 +++++---- src/tui/components/custom-editor.ts | 16 ++++++++++------ src/tui/tui.ts | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/agents/model-compat.ts b/src/agents/model-compat.ts index 228ba3bfd..f4e39c8e9 100644 --- a/src/agents/model-compat.ts +++ b/src/agents/model-compat.ts @@ -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): model is Model<"openai-completions"> { return model.api === "openai-completions"; @@ -9,11 +9,12 @@ export function normalizeModelCompat(model: Model): Model { const isZai = model.provider === "zai" || baseUrl.includes("api.z.ai"); 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; - model.compat = compat + openaiModel.compat = compat ? { ...compat, supportsDeveloperRole: false } : { supportsDeveloperRole: false }; - return model; + return openaiModel; } diff --git a/src/tui/components/custom-editor.ts b/src/tui/components/custom-editor.ts index ad631f0e6..50f810c1c 100644 --- a/src/tui/components/custom-editor.ts +++ b/src/tui/components/custom-editor.ts @@ -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 { onEscape?: () => void; @@ -12,11 +19,8 @@ export class CustomEditor extends Editor { onShiftTab?: () => void; onAltEnter?: () => void; - constructor(tuiOrTheme: TUI | EditorTheme, themeMaybe?: EditorTheme) { - const useLegacyCtor = typeof themeMaybe !== "undefined" && Editor.length >= 2; - const args = (useLegacyCtor ? [tuiOrTheme, themeMaybe] : [themeMaybe ?? tuiOrTheme]) as - ConstructorParameters; - super(...args); + constructor(tui: TUI, theme: EditorTheme, options?: EditorOptions) { + super(tui, theme, options); } handleInput(data: string): void { if (matchesKey(data, Key.alt("enter")) && this.onAltEnter) { diff --git a/src/tui/tui.ts b/src/tui/tui.ts index 753f5511f..a5e6e34d7 100644 --- a/src/tui/tui.ts +++ b/src/tui/tui.ts @@ -193,7 +193,7 @@ export async function runTui(opts: TuiOptions) { const statusContainer = new Container(); const footer = new Text("", 1, 0); const chatLog = new ChatLog(); - const editor = new CustomEditor(editorTheme); + const editor = new CustomEditor(tui, editorTheme); const root = new Container(); root.addChild(header); root.addChild(chatLog);