Makelore 2.0 initial clean snapshot

This commit is contained in:
inman
2026-07-29 17:22:35 +08:00
commit b8ca3f8eea
694 changed files with 139782 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/**
* Per-million-token rates expected by `@mariozechner/pi-ai` `calculateCost`.
* Custom / synced catalog rows often omit pricing; zeros keep accounting stable
* and avoid `Cannot read properties of undefined (reading 'input')` when usage
* chunks arrive during openai-completions streaming.
*/
export const PI_AI_MODEL_ZERO_COST = {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
} as const;
export type PiAiModelCostRates = {
input: number;
output: number;
cacheRead: number;
cacheWrite: number;
};
export function normalizePiAiModelCost(existing: unknown): PiAiModelCostRates {
if (!existing || typeof existing !== 'object') {
return { ...PI_AI_MODEL_ZERO_COST };
}
const record = existing as Record<string, unknown>;
const num = (value: unknown) =>
typeof value === 'number' && Number.isFinite(value) ? value : 0;
return {
input: num(record.input),
output: num(record.output),
cacheRead: num(record.cacheRead),
cacheWrite: num(record.cacheWrite),
};
}
/** Entry shape suitable for local runtime provider model metadata. */
export function piAiModelsJsonModelEntry(
id: string,
name: string = id,
): { id: string; name: string; cost: PiAiModelCostRates } {
return { id, name, cost: normalizePiAiModelCost(undefined) };
}

View File

@@ -0,0 +1,369 @@
import type {
ProviderBackendConfig,
ProviderDefinition,
ProviderType,
ProviderTypeInfo,
} from './types';
export const PROVIDER_DEFINITIONS: ProviderDefinition[] = [
{
id: 'anthropic',
name: 'Anthropic',
icon: '🤖',
placeholder: 'sk-ant-api03-...',
model: 'Claude',
requiresApiKey: true,
category: 'official',
envVar: 'ANTHROPIC_API_KEY',
defaultModelId: 'claude-opus-4-6',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
},
{
id: 'openai',
name: 'OpenAI',
icon: '💚',
placeholder: 'sk-proj-...',
model: 'GPT',
requiresApiKey: true,
category: 'official',
envVar: 'OPENAI_API_KEY',
defaultModelId: 'gpt-5.4',
isOAuth: true,
supportsApiKey: true,
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'gpt-5.4',
supportedAuthModes: ['api_key', 'oauth_browser'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.openai.com/v1',
api: 'openai-responses',
apiKeyEnv: 'OPENAI_API_KEY',
},
},
{
id: 'google',
name: 'Google',
icon: '🔷',
placeholder: 'AIza...',
model: 'Gemini',
requiresApiKey: true,
category: 'official',
envVar: 'GEMINI_API_KEY',
defaultModelId: 'gemini-3-pro-preview',
isOAuth: true,
supportsApiKey: true,
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'gemini-3-pro-preview',
supportedAuthModes: ['api_key', 'oauth_browser'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
},
{
id: 'openrouter',
name: 'OpenRouter',
icon: '🌐',
placeholder: 'sk-or-v1-...',
model: 'Multi-Model',
requiresApiKey: true,
showModelId: true,
modelIdPlaceholder: 'anthropic/claude-opus-4.6',
defaultModelId: 'anthropic/claude-opus-4.6',
category: 'compatible',
envVar: 'OPENROUTER_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://openrouter.ai/api/v1',
api: 'openrouter',
apiKeyEnv: 'OPENROUTER_API_KEY',
headers: {
'HTTP-Referer': 'https://claw-x.com',
'X-OpenRouter-Title': 'Makelore',
},
},
},
{
id: 'ark',
name: 'ByteDance Ark',
icon: 'A',
placeholder: 'your-ark-api-key',
model: 'Doubao',
requiresApiKey: true,
defaultBaseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
showBaseUrl: true,
showModelId: true,
modelIdPlaceholder: 'ep-20260228000000-xxxxx',
category: 'official',
envVar: 'ARK_API_KEY',
codePlanPresetBaseUrl: 'https://ark.cn-beijing.volces.com/api/coding/v3',
codePlanPresetModelId: 'ark-code-latest',
codePlanDocsUrl: 'https://www.volcengine.com/docs/82379/1928261?lang=zh',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
api: 'openai-completions',
apiKeyEnv: 'ARK_API_KEY',
},
},
{
id: 'moonshot',
name: 'Moonshot (CN)',
icon: '🌙',
placeholder: 'sk-...',
model: 'Kimi',
requiresApiKey: true,
defaultBaseUrl: 'https://api.moonshot.cn/v1',
defaultModelId: 'kimi-k2.6',
category: 'official',
envVar: 'MOONSHOT_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.moonshot.cn/v1',
api: 'openai-completions',
apiKeyEnv: 'MOONSHOT_API_KEY',
models: [
{
id: 'kimi-k2.6',
name: 'Kimi K2.6',
reasoning: false,
input: ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
],
},
},
{
id: 'moonshot-global',
name: 'Moonshot (Global)',
icon: '🌙',
placeholder: 'sk-...',
model: 'Kimi',
requiresApiKey: true,
defaultBaseUrl: 'https://api.moonshot.ai/v1',
defaultModelId: 'kimi-k2.6',
category: 'official',
envVar: 'MOONSHOT_GLOBAL_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.moonshot.ai/v1',
api: 'openai-completions',
apiKeyEnv: 'MOONSHOT_GLOBAL_API_KEY',
models: [
{
id: 'kimi-k2.6',
name: 'Kimi K2.6',
reasoning: false,
input: ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
],
},
},
{
id: 'siliconflow',
name: 'SiliconFlow (CN)',
icon: '🌊',
placeholder: 'sk-...',
model: 'Multi-Model',
requiresApiKey: true,
defaultBaseUrl: 'https://api.siliconflow.cn/v1',
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'deepseek-ai/DeepSeek-V3',
defaultModelId: 'deepseek-ai/DeepSeek-V3',
category: 'compatible',
envVar: 'SILICONFLOW_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.siliconflow.cn/v1',
api: 'openai-completions',
apiKeyEnv: 'SILICONFLOW_API_KEY',
},
},
{
id: 'deepseek',
name: 'DeepSeek',
icon: '🐋',
placeholder: 'sk-...',
model: 'DeepSeek',
requiresApiKey: true,
defaultBaseUrl: 'https://api.deepseek.com/v1',
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'deepseek-v4-pro',
defaultModelId: 'deepseek-v4-pro',
apiKeyUrl: 'https://platform.deepseek.com/api_keys',
category: 'official',
envVar: 'DEEPSEEK_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.deepseek.com/v1',
api: 'openai-completions',
apiKeyEnv: 'DEEPSEEK_API_KEY',
},
},
{
id: 'minimax-portal',
name: 'MiniMax (Global)',
icon: '☁️',
placeholder: 'sk-...',
model: 'MiniMax',
requiresApiKey: false,
isOAuth: true,
supportsApiKey: true,
defaultModelId: 'MiniMax-M2.7',
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'MiniMax-M2.7',
apiKeyUrl: 'https://platform.minimax.io',
category: 'official',
envVar: 'MINIMAX_API_KEY',
supportedAuthModes: ['oauth_device', 'api_key'],
defaultAuthMode: 'oauth_device',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.minimax.io/anthropic',
api: 'anthropic-messages',
apiKeyEnv: 'MINIMAX_API_KEY',
},
},
{
id: 'minimax-portal-cn',
name: 'MiniMax (CN)',
icon: '☁️',
placeholder: 'sk-...',
model: 'MiniMax',
requiresApiKey: false,
isOAuth: true,
supportsApiKey: true,
defaultModelId: 'MiniMax-M2.7',
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'MiniMax-M2.7',
apiKeyUrl: 'https://platform.minimaxi.com/',
category: 'official',
envVar: 'MINIMAX_CN_API_KEY',
supportedAuthModes: ['oauth_device', 'api_key'],
defaultAuthMode: 'oauth_device',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.minimaxi.com/anthropic',
api: 'anthropic-messages',
apiKeyEnv: 'MINIMAX_CN_API_KEY',
},
},
{
id: 'modelstudio',
name: 'Model Studio',
icon: '☁️',
placeholder: 'sk-...',
model: 'Qwen',
requiresApiKey: true,
defaultBaseUrl: 'https://coding.dashscope.aliyuncs.com/v1',
showBaseUrl: true,
defaultModelId: 'qwen3.5-plus',
showModelId: true,
showModelIdInDevModeOnly: true,
modelIdPlaceholder: 'qwen3.5-plus',
category: 'official',
envVar: 'MODELSTUDIO_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://coding.dashscope.aliyuncs.com/v1',
api: 'openai-completions',
apiKeyEnv: 'MODELSTUDIO_API_KEY',
},
},
{
id: 'ollama',
name: 'Ollama',
icon: '🦙',
placeholder: 'Not required',
requiresApiKey: false,
defaultBaseUrl: 'http://localhost:11434/v1',
showBaseUrl: true,
showModelId: true,
modelIdPlaceholder: 'qwen3:latest',
category: 'local',
supportedAuthModes: ['local'],
defaultAuthMode: 'local',
supportsMultipleAccounts: true,
},
{
id: 'custom',
name: 'Custom',
icon: '⚙️',
placeholder: 'API key...',
requiresApiKey: true,
showBaseUrl: true,
showModelId: true,
modelIdPlaceholder: 'your-provider/model-id',
category: 'custom',
envVar: 'CUSTOM_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
},
];
const PROVIDER_DEFINITION_MAP = new Map(
PROVIDER_DEFINITIONS.map((definition) => [definition.id, definition]),
);
export function getProviderDefinition(
type: ProviderType | string,
): ProviderDefinition | undefined {
return PROVIDER_DEFINITION_MAP.get(type as ProviderType);
}
export function getProviderTypeInfo(
type: ProviderType,
): ProviderTypeInfo | undefined {
return getProviderDefinition(type);
}
export function getProviderEnvVar(type: string): string | undefined {
return getProviderDefinition(type)?.envVar;
}
export function getProviderDefaultModel(type: string): string | undefined {
return getProviderDefinition(type)?.defaultModelId;
}
export function getProviderBackendConfig(
type: string,
): ProviderBackendConfig | undefined {
return getProviderDefinition(type)?.providerConfig;
}
export function getProviderUiInfoList(): ProviderTypeInfo[] {
return PROVIDER_DEFINITIONS;
}
export function getKeyableProviderTypes(): string[] {
return PROVIDER_DEFINITIONS.filter((definition) => definition.envVar).map(
(definition) => definition.id,
);
}

View File

@@ -0,0 +1,181 @@
export const PROVIDER_TYPES = [
'anthropic',
'openai',
'google',
'openrouter',
'ark',
'moonshot',
'siliconflow',
'deepseek',
'minimax-portal',
'minimax-portal-cn',
'modelstudio',
'ollama',
'custom',
] as const;
export const BUILTIN_PROVIDER_TYPES = [
'anthropic',
'openai',
'google',
'openrouter',
'ark',
'moonshot',
'siliconflow',
'deepseek',
'minimax-portal',
'minimax-portal-cn',
'modelstudio',
'ollama',
] as const;
export type ProviderType = (typeof PROVIDER_TYPES)[number];
export type BuiltinProviderType = (typeof BUILTIN_PROVIDER_TYPES)[number];
export const OLLAMA_PLACEHOLDER_API_KEY = 'ollama-local';
export type ProviderProtocol =
| 'openai-completions'
| 'openai-responses'
| 'anthropic-messages'
| 'openrouter';
export type ProviderAuthMode =
| 'api_key'
| 'oauth_device'
| 'oauth_browser'
| 'local';
export type ProviderVendorCategory =
| 'official'
| 'compatible'
| 'local'
| 'custom';
export interface ProviderConfig {
id: string;
name: string;
type: ProviderType;
baseUrl?: string;
apiProtocol?: ProviderProtocol;
headers?: Record<string, string>;
model?: string;
fallbackModels?: string[];
fallbackProviderIds?: string[];
enabled: boolean;
createdAt: string;
updatedAt: string;
}
export interface ProviderWithKeyInfo extends ProviderConfig {
hasKey: boolean;
keyMasked: string | null;
}
export interface ProviderTypeInfo {
id: ProviderType;
name: string;
icon: string;
placeholder: string;
model?: string;
requiresApiKey: boolean;
defaultBaseUrl?: string;
showBaseUrl?: boolean;
showModelId?: boolean;
showModelIdInDevModeOnly?: boolean;
modelIdPlaceholder?: string;
defaultModelId?: string;
isOAuth?: boolean;
supportsApiKey?: boolean;
apiKeyUrl?: string;
codePlanPresetBaseUrl?: string;
codePlanPresetModelId?: string;
codePlanDocsUrl?: string;
}
export interface ProviderModelEntry extends Record<string, unknown> {
id: string;
name: string;
}
export interface ProviderBackendConfig {
baseUrl: string;
api: ProviderProtocol;
apiKeyEnv: string;
models?: ProviderModelEntry[];
headers?: Record<string, string>;
}
export interface ProviderDefinition extends ProviderTypeInfo {
category: ProviderVendorCategory;
envVar?: string;
providerConfig?: ProviderBackendConfig;
supportedAuthModes: ProviderAuthMode[];
defaultAuthMode: ProviderAuthMode;
supportsMultipleAccounts: boolean;
}
export interface ProviderAccount {
id: string;
vendorId: ProviderType;
label: string;
authMode: ProviderAuthMode;
baseUrl?: string;
apiProtocol?: ProviderProtocol;
headers?: Record<string, string>;
model?: string;
fallbackModels?: string[];
fallbackAccountIds?: string[];
enabled: boolean;
isDefault: boolean;
metadata?: {
region?: string;
email?: string;
resourceUrl?: string;
customModels?: string[];
worksSquareCredentialMode?: string;
worksSquareCredentialExpiresAt?: string;
worksSquareOneApiBaseUrl?: string;
};
createdAt: string;
updatedAt: string;
}
export type ProviderSecret =
| {
type: 'api_key';
accountId: string;
apiKey: string;
}
| {
type: 'oauth';
accountId: string;
accessToken: string;
refreshToken: string;
expiresAt: number;
scopes?: string[];
email?: string;
subject?: string;
}
| {
type: 'local';
accountId: string;
apiKey?: string;
};
export interface ModelSummary {
id: string;
name: string;
vendorId: string;
accountId?: string;
supportsVision?: boolean;
supportsReasoning?: boolean;
contextWindow?: number;
pricing?: {
input?: number;
output?: number;
cacheRead?: number;
cacheWrite?: number;
};
source: 'builtin' | 'remote' | 'runtime' | 'custom';
}