fix: route PAT login through pi LoginDialog callbacks

The custom ctx.ui.custom login menu stole focus from pi's built-in
LoginDialog, so onPrompt never received keystrokes and PAT login
silently failed with 'No API key found'. Drive login via the provided
onPrompt/onAuth/onProgress callbacks instead, and drop login-ui.ts and
the now-unused pi-tui dependency. Also clears remaining lint warnings
by removing any-casts in models/oauth/stream/transform.
This commit is contained in:
Simon Shi
2026-06-16 13:39:16 +08:00
parent 842bec6eb2
commit bcaa66091e
10 changed files with 139 additions and 303 deletions
+37 -8
View File
@@ -9,6 +9,35 @@ import type {
ToolResultMessage,
} from "@earendil-works/pi-ai";
/** OpenAI-style tool definition sent to the Qoder API. */
interface QoderTool {
type: "function";
function: {
name: string;
description?: string;
parameters?: unknown;
};
}
/** OpenAI-style tool call within an assistant message. */
interface QoderToolCall {
id?: string;
type: "function";
function: { name?: string; arguments: string };
}
type QoderTextPart = { type: "text"; text: string };
type QoderImagePart = { type: "image_url"; image_url: { url: string } };
type QoderContent = string | Array<QoderTextPart | QoderImagePart>;
/** OpenAI-style message sent to the Qoder API. */
interface QoderMessage {
role: "user" | "assistant" | "tool";
content: QoderContent | null;
tool_calls?: QoderToolCall[];
tool_call_id?: string;
}
export function getContentText(msg: Message): string {
if (typeof msg.content === "string") return msg.content;
if (Array.isArray(msg.content)) {
@@ -23,7 +52,7 @@ export function getContentText(msg: Message): string {
return "";
}
export function transformTools(tools: Tool[]): any[] {
export function transformTools(tools: Tool[]): QoderTool[] {
return tools.map((t) => ({
type: "function",
function: {
@@ -34,8 +63,8 @@ export function transformTools(tools: Tool[]): any[] {
}));
}
export function transformMessagesForQoder(messages: Message[]): any[] {
const normalizedMessages: any[] = [];
export function transformMessagesForQoder(messages: Message[]): QoderMessage[] {
const normalizedMessages: QoderMessage[] = [];
for (const msg of messages) {
// Skip error or aborted messages
@@ -47,14 +76,14 @@ export function transformMessagesForQoder(messages: Message[]): any[] {
}
if (msg.role === "user") {
let content: any = "";
let content: QoderContent = "";
if (typeof msg.content === "string") {
content = msg.content;
} else if (Array.isArray(msg.content)) {
const hasImage = msg.content.some((c) => c.type === "image");
if (hasImage) {
content = msg.content
.map((c) => {
.map((c): QoderTextPart | QoderImagePart | null => {
if (c.type === "text") {
return { type: "text", text: (c as TextContent).text };
}
@@ -69,7 +98,7 @@ export function transformMessagesForQoder(messages: Message[]): any[] {
}
return null;
})
.filter(Boolean);
.filter((p): p is QoderTextPart | QoderImagePart => p !== null);
} else {
content = getContentText(msg);
}
@@ -81,7 +110,7 @@ export function transformMessagesForQoder(messages: Message[]): any[] {
} else if (msg.role === "assistant") {
const am = msg as AssistantMessage;
let content = "";
const toolCalls: any[] = [];
const toolCalls: QoderToolCall[] = [];
if (Array.isArray(am.content)) {
for (const block of am.content) {
@@ -106,7 +135,7 @@ export function transformMessagesForQoder(messages: Message[]): any[] {
content = am.content || "";
}
const mapped: any = {
const mapped: QoderMessage = {
role: "assistant",
content: content || null,
};