UNPKG

openai-plugins

Version:

A TypeScript library that provides an OpenAI-compatible client for the Model Context Protocol (MCP).

53 lines (52 loc) 1.5 kB
import OriginalOpenAI from "openai"; declare global { var EventSource: typeof EventSource; } interface ChatCompletionRole { role: "system" | "user" | "assistant" | "tool" | "function"; content: string; tool_calls?: any[]; tool_call_id?: string; name?: string; } interface ChatCompletionParams { model: string; messages: ChatCompletionRole[]; max_tokens?: number; temperature?: number; stream?: boolean; tools?: any[]; tool_choice?: string | object; response_format?: { type: string; }; [key: string]: any; } declare const LVL: { readonly debug: 0; readonly info: 1; readonly warn: 2; readonly error: 3; }; export type MCP_LogLevel = keyof typeof LVL; type LogLevelValue = (typeof LVL)[MCP_LogLevel]; export declare let MCP_LOG_LVL: LogLevelValue; export declare const setMcpLogLevel: (level: MCP_LogLevel) => void; export declare const log: (lvl: number, msg: string) => void; type PluginHandler = (params: ChatCompletionParams, next: (p: ChatCompletionParams, context?: any) => Promise<any>) => Promise<any>; interface Plugin { name: string; handle: PluginHandler; } interface OpenAIOptions { pluginConfig?: Record<string, any>; plugins?: string | string[] | Plugin[] | null; apiKey?: string; baseURL?: string; mcpLogLevel?: MCP_LogLevel; } declare class OpenAI extends OriginalOpenAI { #private; constructor(opts: OpenAIOptions); } export { OpenAI as default, OpenAI };