mirror of
https://github.com/hanzoai/opencode-openai-codex-auth.git
synced 2026-09-24 17:01:02 +00:00
172 lines
3.0 KiB
TypeScript
172 lines
3.0 KiB
TypeScript
import type { Auth, Provider, Model } from "@opencode-ai/sdk";
|
|
|
|
/**
|
|
* Plugin configuration from ~/.opencode/openai-codex-auth-config.json
|
|
*/
|
|
export interface PluginConfig {
|
|
/**
|
|
* Enable CODEX_MODE (Codex-OpenCode bridge prompt instead of tool remap)
|
|
* @default true
|
|
*/
|
|
codexMode?: boolean;
|
|
}
|
|
|
|
/**
|
|
* User configuration structure from opencode.json
|
|
*/
|
|
export interface UserConfig {
|
|
global: ConfigOptions;
|
|
models: {
|
|
[modelName: string]: {
|
|
options?: ConfigOptions;
|
|
};
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Configuration options for reasoning and text settings
|
|
*/
|
|
export interface ConfigOptions {
|
|
reasoningEffort?: "minimal" | "low" | "medium" | "high";
|
|
reasoningSummary?: "auto" | "concise" | "detailed";
|
|
textVerbosity?: "low" | "medium" | "high";
|
|
include?: string[];
|
|
}
|
|
|
|
/**
|
|
* Reasoning configuration for requests
|
|
*/
|
|
export interface ReasoningConfig {
|
|
effort: "minimal" | "low" | "medium" | "high";
|
|
summary: "auto" | "concise" | "detailed";
|
|
}
|
|
|
|
/**
|
|
* OAuth server information
|
|
*/
|
|
export interface OAuthServerInfo {
|
|
port: number;
|
|
close: () => void;
|
|
waitForCode: (state: string) => Promise<{ code: string } | null>;
|
|
}
|
|
|
|
/**
|
|
* PKCE challenge and verifier
|
|
*/
|
|
export interface PKCEPair {
|
|
challenge: string;
|
|
verifier: string;
|
|
}
|
|
|
|
/**
|
|
* Authorization flow result
|
|
*/
|
|
export interface AuthorizationFlow {
|
|
pkce: PKCEPair;
|
|
state: string;
|
|
url: string;
|
|
}
|
|
|
|
/**
|
|
* Token exchange success result
|
|
*/
|
|
export interface TokenSuccess {
|
|
type: "success";
|
|
access: string;
|
|
refresh: string;
|
|
expires: number;
|
|
}
|
|
|
|
/**
|
|
* Token exchange failure result
|
|
*/
|
|
export interface TokenFailure {
|
|
type: "failed";
|
|
}
|
|
|
|
/**
|
|
* Token exchange result
|
|
*/
|
|
export type TokenResult = TokenSuccess | TokenFailure;
|
|
|
|
/**
|
|
* Parsed authorization input
|
|
*/
|
|
export interface ParsedAuthInput {
|
|
code?: string;
|
|
state?: string;
|
|
}
|
|
|
|
/**
|
|
* JWT payload with ChatGPT account info
|
|
*/
|
|
export interface JWTPayload {
|
|
"https://api.openai.com/auth"?: {
|
|
chatgpt_account_id?: string;
|
|
};
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
/**
|
|
* Message input item
|
|
*/
|
|
export interface InputItem {
|
|
id?: string;
|
|
type: string;
|
|
role: string;
|
|
content?: unknown;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
/**
|
|
* Request body structure
|
|
*/
|
|
export interface RequestBody {
|
|
model: string;
|
|
store?: boolean;
|
|
stream?: boolean;
|
|
instructions?: string;
|
|
input?: InputItem[];
|
|
tools?: unknown;
|
|
reasoning?: Partial<ReasoningConfig>;
|
|
text?: {
|
|
verbosity?: "low" | "medium" | "high";
|
|
};
|
|
include?: string[];
|
|
/** Stable key to enable prompt-token caching on Codex backend */
|
|
prompt_cache_key?: string;
|
|
max_output_tokens?: number;
|
|
max_completion_tokens?: number;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
/**
|
|
* SSE event data structure
|
|
*/
|
|
export interface SSEEventData {
|
|
type: string;
|
|
response?: unknown;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
/**
|
|
* Cache metadata for Codex instructions
|
|
*/
|
|
export interface CacheMetadata {
|
|
etag: string | null;
|
|
tag: string;
|
|
lastChecked: number;
|
|
url: string;
|
|
}
|
|
|
|
/**
|
|
* GitHub release data
|
|
*/
|
|
export interface GitHubRelease {
|
|
tag_name: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
// Re-export SDK types for convenience
|
|
export type { Auth, Provider, Model };
|