跳转到内容

API Reference

Complete API reference for Feima Copilot extension.

Sign in to your Feima account using OAuth2.

Signature:

function signIn(): Promise<void>

Usage:

import * as vscode from 'vscode';
const signInCommand = vscode.commands.registerCommand('feima.signIn', async () => {
// Signs the user in via OAuth2
});

Throws:

  • Error - If authentication fails

Display current account information.

Signature:

function showAccount(): Promise<void>

Usage:

const showAccountCommand = vscode.commands.registerCommand('feima.showAccount', async () => {
// Shows email and account ID
});

Throws:

  • Error - If not signed in

Sign out from Feima account.

Signature:

function signOut(): Promise<void>

Usage:

const signOutCommand = vscode.commands.registerCommand('feima.signOut', async () => {
// Clears all stored tokens
});

Main provider for Feima language models.

Interface:

interface LanguageModelProvider {
readonly models: LanguageModel[];
getModel(id: string): LanguageModel | undefined;
refreshModels(): Promise<void>;
}

Represents a single AI model.

Interface:

interface LanguageModel {
readonly id: string;
readonly name: string;
readonly description: string;
readonly provider: string;
readonly contextLength: number;
readonly maxOutputTokens: number;
readonly capabilities: ModelCapabilities;
}

Properties:

PropertyTypeDescription
idstringUnique model identifier
namestringDisplay name
descriptionstringModel description
providerstringProvider name
contextLengthnumberMaximum context tokens
maxOutputTokensnumberMaximum output tokens
capabilitiesModelCapabilitiesSupported capabilities

Capabilities of a language model.

Interface:

interface ModelCapabilities {
readonly codeGeneration: boolean;
readonly codeReview: boolean;
readonly reasoning: boolean;
readonly supportsImages?: boolean;
readonly supportsTools?: boolean;
}

Handles OAuth2 authentication with Feima IDP.

Interface:

interface OAuth2Service {
signIn(): Promise<Session>;
signOut(): Promise<void>;
getCurrentSession(): Session | null;
refreshAccessToken(): Promise<void>;
}

Represents an authenticated session.

Interface:

interface Session {
readonly accessToken: string;
readonly refreshToken: string;
readonly expiresAt: Date;
readonly user: UserInfo;
}

User information from Feima IDP.

Interface:

interface UserInfo {
readonly email: string;
readonly sub: string;
readonly provider: 'wechat' | 'weibo';
}

Extension configuration options.

Interface:

interface ConfigurationOptions {
readonly defaultModel: string;
readonly showStatusBar: boolean;
readonly autoRefreshToken: boolean;
readonly enableDebugLogging: boolean;
readonly requestTimeout: number;
readonly maxRetries: number;
}

Get current extension configuration.

Signature:

function getConfiguration(): ConfigurationOptions

Usage:

const config = getConfiguration();
console.log(config.defaultModel);

Fired when the user session changes.

Type:

type SessionChangedEvent = Session | null;

Usage:

authService.onSessionChanged((session) => {
if (session) {
console.log('User signed in:', session.user.email);
} else {
console.log('User signed out');
}
});

Fired when available models are updated.

Type:

type ModelsUpdatedEvent = LanguageModel[];

Usage:

provider.onModelsUpdated((models) => {
console.log('Available models:', models.length);
});

HTTP client for Feima API.

Interface:

interface FeimaApiClient {
completions(request: CompletionRequest): Promise<CompletionResponse>;
chat(request: ChatRequest): Promise<ChatResponse>;
models(): Promise<LanguageModel[]>;
}

Request for text completion.

Interface:

interface CompletionRequest {
readonly model: string;
readonly prompt: string;
readonly maxTokens?: number;
readonly temperature?: number;
readonly stop?: string[];
}

Response from completion API.

Interface:

interface CompletionResponse {
readonly id: string;
readonly model: string;
readonly choices: CompletionChoice[];
readonly usage: Usage;
}

Request for chat completion.

Interface:

interface ChatRequest {
readonly model: string;
readonly messages: ChatMessage[];
readonly maxTokens?: number;
readonly temperature?: number;
readonly stream?: boolean;
}

Single message in a chat conversation.

Interface:

interface ChatMessage {
readonly role: 'user' | 'assistant' | 'system';
readonly content: string;
}

Token usage information.

Interface:

interface Usage {
readonly promptTokens: number;
readonly completionTokens: number;
readonly totalTokens: number;
}

Thrown when authentication fails.

class AuthenticationError extends Error {
readonly code: string;
constructor(message: string, code: string);
}

Thrown when API request fails.

class ApiError extends Error {
readonly statusCode: number;
readonly requestId: string;
constructor(message: string, statusCode: number, requestId: string);
}

Thrown when rate limit is exceeded.

class RateLimitError extends Error {
readonly retryAfter: number;
constructor(message: string, retryAfter: number);
}

Main extension activation function.

Signature:

export function activate(context: vscode.ExtensionContext): void

Parameters:

  • context - VS Code extension context

Extension deactivation function.

Signature:

export function deactivate(): void | Promise<void>

import * as vscode from 'vscode';
import { OAuth2Service } from './auth/oauthService';
const authService = new OAuth2Service(context);
async function signInExample() {
try {
const session = await authService.signIn();
vscode.window.showInformationMessage(
`Signed in as ${session.user.email}`
);
} catch (error) {
vscode.window.showErrorMessage(
`Sign in failed: ${error.message}`
);
}
}

import { LanguageModelProvider } from './models/languageModelProvider';
const provider = new LanguageModelProvider(context);
function getModelExample() {
const model = provider.getModel('deepseek-coder-v2');
if (model) {
console.log(`Model: ${model.name}`);
console.log(`Provider: ${model.provider}`);
console.log(`Context: ${model.contextLength} tokens`);
}
}

import { FeimaApiClient } from './services/feimaApiClient';
const api = new FeimaApiClient(authService);
async function chatExample() {
const response = await api.chat({
model: 'deepseek-coder-v2',
messages: [
{
role: 'user',
content: 'Write a hello world function in TypeScript'
}
],
maxTokens: 500
});
console.log(response.choices[0].message.content);
}

Log level enum.

enum LogLevel {
Debug = 'debug',
Info = 'info',
Warn = 'warn',
Error = 'error'
}

Model provider enum.

enum ModelProvider {
DeepSeek = 'deepseek',
Alibaba = 'alibaba',
Tencent = 'tencent',
OpenAI = 'openai',
Anthropic = 'anthropic',
Google = 'google'
}

export const MODEL_IDS = {
DEEPSEEK_CODER_V2: 'deepseek-coder-v2',
TONGYI_QIANWEN_3_CODER: 'tongyi-qianwen-3-coder',
TENCENT_HUNYUAN: 'tencent-hunyuan',
GPT_4O: 'gpt-4o',
CLAUDE_3_5_SONNET: 'claude-3.5-sonnet',
GEMINI_1_5_PRO: 'gemini-1.5-pro'
} as const;

export const CONFIG_KEYS = {
DEFAULT_MODEL: 'feima.defaultModel',
SHOW_STATUS_BAR: 'feima.showStatusBar',
AUTO_REFRESH_TOKEN: 'feima.autoRefreshToken',
ENABLE_DEBUG_LOGGING: 'feima.enableDebugLogging',
REQUEST_TIMEOUT: 'feima.requestTimeout',
MAX_RETRIES: 'feima.maxRetries'
} as const;