--- package/package.json (excerpt) ---
{
"type": "module",
"name": "@yuechou/pi-ai",
"version": "15.8.3-patched.6",
"description": "Unified LLM API with automatic model discovery and provider configuration",
"homepage": "https://omp.sh",
"author": "Can Boluk",
"contributors": [
"Mario Zechner"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/can1357/oh-my-pi.git",
"directory": "packages/ai"
},
"bugs": {
"url": "https://github.com/can1357/oh-my-pi/issues"
},
"keywords": [
"ai",
"llm",
"openai",
"anthropic",
"gemini",
"unified",
"api"
],
"main": "./src/index.ts",
"types": "./src/index.ts",
"scripts": {
"check": "biome check . && bun run check:types",
"check:types": "tsgo -p tsconfig.json --noEmit",
"lint": "biome lint .",
"test": "bun test --parallel",
"fix": "biome check --write --unsafe .",
"fmt": "biome format --write .",
"generate-models": "bun scripts/generate-models.ts"
},
"dependencies": {
"@bufbuild/protobuf": "^2.12.0",
"@yuechou/pi-utils": "15.8.3-patched.6",
"openai": "^6.39.0",
"partial-json": "^0.1.7",
"zod": "4.4.3"
},
"devDependencies": {
"@types/bun": "^1.3.14"
},
"engines": {
"bun": ">=1.3.14"
},
"files": [
"src",
"README.md",
"CHANGELOG.md"
],
"exports": {
".": {
"types": "./src/index.ts",
"import": "./src/index.ts"
},
"./*": {
"types": "./src/*.ts",
"import": "./src/*.ts"
},
"./auth-broker": {
"types": "./src/auth-broker/index.ts",
"import": "./src/aut
--- package/src/auth-storage.ts (excerpt) ---
/**
* Credential storage for API keys and OAuth tokens.
* Handles loading, saving, refreshing credentials, and usage tracking.
*
* This module defines:
* - `AuthCredentialStore` interface: persistence abstraction (SQLite, remote vault, …)
* - `AuthStorage` class: credential management with round-robin, usage limits, OAuth refresh
* - `SqliteAuthCredentialStore`: concrete SQLite-backed implementation
*/
import { Database, type Statement } from "bun:sqlite";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { getAgentDbPath, logger } from "@yuechou/pi-utils";
import { getEnvApiKey } from "./stream";
import type { Provider } from "./types";
import type {
CredentialRankingStrategy,
UsageCredential,
UsageFetchContext,
UsageFetchParams,
UsageLimit,
UsageLogger,
UsageProvider,
UsageReport,
} from "./usage";
import { claudeRankingStrategy, claudeUsageProvider } from "./usage/claude";
import { googleGeminiCliUsageProvider } from "./usage/gemini";
import { githubCopilotUsageProvider } from "./usage/github-copilot";
import { antigravityUsageProvider } from "./usage/google-antigravity";
import { kimiUsageProvider } from "./usage/kimi";
import { codexRankingStrategy, openaiCodexUsageProvider } from "./usage/openai-codex";
import { zaiUsageProvider } from "./usage/zai";
import { getOAuthApiKey, getOAuthProvider, refreshOAuthToken } from "./utils/oauth";
import { loginDeepSeek } from "./utils/oauth/deepseek";
import { loginOpenAICodexDevice }
--- package/src/model-thinking.ts (excerpt) ---
import { resolveOpenAICompat } from "./providers/openai-completions-compat";
import type { Api, Model as ApiModel, ThinkingConfig } from "./types";
/** User-facing thinking levels, ordered least to most intensive. */
export const enum Effort {
Minimal = "minimal",
Low = "low",
Medium = "medium",
High = "high",
XHigh = "xhigh",
}
export const THINKING_EFFORTS: readonly Effort[] = [
Effort.Minimal,
Effort.Low,
Effort.Medium,
Effort.High,
Effort.XHigh,
];
const DEFAULT_REASONING_EFFORTS: readonly Effort[] = [Effort.Minimal, Effort.Low, Effort.Medium, Effort.High];
const DEFAULT_REASONING_EFFORTS_WITH_XHIGH: readonly Effort[] = [
Effort.Minimal,
Effort.Low,
Effort.Medium,
Effort.High,
Effort.XHigh,
];
const GEMINI_3_PRO_EFFORTS: readonly Effort[] = [Effort.Low, Effort.High];
const GEMINI_3_FLASH_EFFORTS: readonly Effort[] = [Effort.Minimal, Effort.Low, Effort.Medium, Effort.High];
const GPT_5_2_PLUS_EFFORTS: readonly Effort[] = [Effort.Low, Effort.Medium, Effort.High, Effort.XHigh];
const GPT_5_1_CODEX_MINI_EFFORTS: readonly Effort[] = [Effort.Medium, Effort.High];
const CLOUDFLARE_AI_GATEWAY_BASE_URL = "https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/anthropic";
type SemVer = {
major: number;
minor: number;
patch: number;
};
type GeminiKind = "pro" | "flash";
type AnthropicKind = "opus" | "sonnet";
type OpenAIVariant = "base" | "codex" | "codex-max" | "codex-mini" | "codex-spark" | "mini" | "max" | "nano";
const CODEX_GPT_5_4_PRIORITY_BY_VARIANT: