Refactor provider around fixed regions and friendly model ids

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-08-31 17:11:18 +00:00
co-authored by Simon Shi
parent 63c517002e
commit 9d88e995ee
27 changed files with 400 additions and 488 deletions
+10 -7
View File
@@ -17,12 +17,16 @@
import { readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { buildAuthHeaders, getQoderChatURL, getQoderMode } from "../src/cosy.js";
import { qoderEncodeBody } from "../src/qoder-encoding.js";
import { transformMessagesForQoder, transformTools } from "../src/transform.js";
import { getCachedModelConfig } from "../src/catalog.js";
import { buildAuthHeaders } from "../src/cosy.js";
import { qoderEncodeBody } from "../src/protocol/encoding.js";
import { transformMessagesForQoder, transformTools } from "../src/protocol/transform.js";
import { getQoderChatURL } from "../src/region.js";
const AUTH_FILE = join(homedir(), ".pi", "agent", "auth.json");
const MODEL = process.argv[2] || "lite";
const MODEL_ID = process.argv[2] || "Lite";
const MODEL = getCachedModelConfig(MODEL_ID, "global")?.key;
if (!MODEL) throw new Error(`Unknown friendly Qoder model id: ${MODEL_ID}`);
interface QoderCreds {
access: string;
@@ -89,8 +93,7 @@ interface TestResult {
/** Send a request, decode the SSE envelope stream, return a verdict. */
async function sendRequest(label: string, body: Record<string, unknown>): Promise<TestResult> {
const mode = getQoderMode();
const url = getQoderChatURL(mode);
const url = getQoderChatURL("global");
const creds = loadCreds();
// CRITICAL: body must be encoded with qoderEncodeBody, and auth headers
@@ -172,7 +175,7 @@ function fmt(r: TestResult) {
async function main() {
const creds = loadCreds();
console.log(`Loaded credentials: userID=${creds.userID} email=${creds.email} mode=${getQoderMode()}`);
console.log(`Loaded credentials: userID=${creds.userID} email=${creds.email} mode=global`);
const piTools = [
{
+12 -9
View File
@@ -10,24 +10,28 @@
* 3. For comparison, that the OLD parser logic leaks `</thinking>` into text
* on the same stream.
*
* Usage: npx tsx scripts/live-thinking-leak-test.ts [model] [prompt]
* model defaults to "efficient" (the model that leaked historically)
* Usage: npx tsx scripts/live-thinking-leak-test.ts [friendly-model-id] [prompt]
* model defaults to "Efficient" (the model that leaked historically)
*/
import { readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import type { AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream } from "@earendil-works/pi-ai";
import { buildAuthHeaders, getQoderChatURL, getQoderMode } from "../src/cosy.js";
import { qoderEncodeBody } from "../src/qoder-encoding.js";
import { transformMessagesForQoder } from "../src/transform.js";
import { getCachedModelConfig } from "../src/catalog.js";
import { buildAuthHeaders } from "../src/cosy.js";
import { qoderEncodeBody } from "../src/protocol/encoding.js";
import { transformMessagesForQoder } from "../src/protocol/transform.js";
import {
THINKING_TAG_VARIANTS,
ThinkingTagParser,
stripThinkingTags,
} from "../src/thinking-parser.js";
} from "../src/protocol/thinking.js";
import { getQoderChatURL } from "../src/region.js";
const AUTH_FILE = join(homedir(), ".pi", "agent", "auth.json");
const MODEL = process.argv[2] || "efficient";
const MODEL_ID = process.argv[2] || "Efficient";
const MODEL = getCachedModelConfig(MODEL_ID, "global")?.key;
if (!MODEL) throw new Error(`Unknown friendly Qoder model id: ${MODEL_ID}`);
const PROMPT =
process.argv[3] ||
"A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost? Reason carefully step by step before answering.";
@@ -95,8 +99,7 @@ interface RawStream {
/** POST and collect every raw delta.reasoning_content / delta.content chunk. */
async function captureRawStream(model: string, isReasoning: boolean): Promise<RawStream> {
const mode = getQoderMode();
const url = getQoderChatURL(mode);
const url = getQoderChatURL("global");
const creds = loadCreds();
const messages = transformMessagesForQoder([{ role: "user", content: PROMPT } as never]);
const body = buildRequestBody(model, messages, isReasoning);
+3 -3
View File
@@ -136,9 +136,9 @@ async function recordRegion(region: Region, pat: string): Promise<void> {
return response;
}) as typeof fetch;
const { credentialsFromPat } = await import("../src/pat.js");
const { getCachedModelConfig, getCachedModels, updateQoderModelsCache } = await import("../src/models.js");
const { streamQoder } = await import("../src/stream.js");
const { credentialsFromPat } = await import("../src/auth/pat.js");
const { getCachedModelConfig, getCachedModels, updateQoderModelsCache } = await import("../src/catalog.js");
const { streamQoder } = await import("../src/protocol/stream.js");
const credentials = (await credentialsFromPat(pat, region)) as unknown as {
access: string;