File size: 10,037 Bytes
5871090
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import { config } from "./config";

export type AdapterId =
  | "anthropic"
  | "openai"
  | "gemini"
  | "deepseek"
  | "kimi"
  | "zhipu"
  | "minimax"
  | "qwen"
  | "codex-cli";

/**
 * Provider source bucket — every model declares which call paths can
 * serve it. Availability is now a per-source check rather than a global
 * profile gate, so e.g. MiniMax/Kimi work whether or not the hosted
 * Replit integrations are configured. `DOATLAS_PROFILE` is downgraded
 * to a *preference filter* in `listModels` (it controls ordering /
 * default model picking, not whether a configured key works).
 */
export type ModelSource =
  | "replit-integration"
  | "byok-direct"
  | "china-direct";

export interface ModelInfo {
  id: string;
  name: string;
  provider: string;
  description: string;
  context_length: number;
  capabilities: Array<"text" | "vision" | "tools" | "streaming">;
  pricing: { input_per_1k: number; output_per_1k: number };
  default: boolean;
  available: boolean;
  // Internal routing hints (not exposed to client).
  tier: "S" | "A";
  adapter: AdapterId;
  upstreamModel: string;
  /**
   * Source buckets this model can be served from. The first matching
   * bucket with credentials wins; we never try to fall through to a
   * different source mid-call.
   */
  sources: ModelSource[];
}

const ALL_MODELS: ModelInfo[] = [
  // -- S tier (旗舰) --
  {
    id: "mdl_claude-sonnet-4-6",
    name: "DoAtlas Pro",
    provider: "DoAtlas",
    description:
      "旗舰研究模型,深度推理与代码能力最强,适合复杂文献综述、机制推理与多步分析。",
    context_length: 200_000,
    capabilities: ["text", "vision", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "S",
    adapter: "anthropic",
    upstreamModel: "claude-sonnet-4-6",
    sources: ["replit-integration", "byok-direct"],
  },
  {
    id: "mdl_gpt-5_2",
    name: "DoAtlas Pro X",
    provider: "DoAtlas",
    description:
      "多模态旗舰模型,视觉与文本兼顾,适合图表解读、影像分析与通用研究问答。",
    context_length: 128_000,
    capabilities: ["text", "vision", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "S",
    adapter: "openai",
    upstreamModel: "gpt-5.2",
    sources: ["replit-integration", "byok-direct"],
  },
  {
    id: "mdl_gemini-2_5-pro",
    name: "DoAtlas Vision",
    provider: "DoAtlas",
    description:
      "Gemini 2.5 Pro 多模态旗舰,超长上下文与图表理解,适合长文档解析与多模态研究问答。",
    context_length: 1_000_000,
    capabilities: ["text", "vision", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "S",
    adapter: "gemini",
    upstreamModel: "gemini-2.5-pro",
    sources: ["replit-integration", "byok-direct"],
  },
  {
    id: "mdl_deepseek-r1",
    name: "DoAtlas Reason Pro",
    provider: "DoAtlas",
    description:
      "DeepSeek R1 推理模型,专注链式推理与数学/科学论证,适合机制假设与复杂证据综合。",
    context_length: 128_000,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "S",
    adapter: "deepseek",
    upstreamModel: "deepseek-reasoner",
    sources: ["china-direct"],
  },
  {
    id: "mdl_codex-cli",
    name: "DoAtlas Code",
    provider: "DoAtlas Local",
    description:
      "本地代码助手,运行在你自己的机器上,可读写本地文件与执行命令;需在本地部署中配置。",
    context_length: 200_000,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "S",
    adapter: "codex-cli",
    upstreamModel: "codex-cli",
    sources: ["byok-direct"],
  },

  // -- A tier (通用) --
  {
    id: "mdl_glm-4_6",
    name: "DoAtlas Air",
    provider: "DoAtlas",
    description:
      "智谱 GLM-4 系列,长上下文 128k,响应快速,适合日常问答与长文本处理。",
    context_length: 131_072,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "A",
    adapter: "zhipu",
    upstreamModel: "glm-4-plus",
    sources: ["china-direct"],
  },
  {
    id: "mdl_minimax-m2",
    name: "DoAtlas Search",
    provider: "DoAtlas",
    description:
      "MiniMax M2 智能体模型,配合统一 web_search 工具实现实时联网检索,适合需要最新资料的研究问答。",
    context_length: 200_000,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "A",
    adapter: "minimax",
    upstreamModel: "MiniMax-M2.7-highspeed",
    sources: ["china-direct"],
  },
  {
    id: "mdl_deepseek-v3",
    name: "DoAtlas Chat",
    provider: "DoAtlas",
    description:
      "DeepSeek V3 通用对话模型,性价比高,适合日常问答与代码补全。",
    context_length: 128_000,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "A",
    adapter: "deepseek",
    upstreamModel: "deepseek-chat",
    sources: ["china-direct"],
  },
  {
    id: "mdl_kimi-k2",
    name: "DoAtlas Long",
    provider: "DoAtlas",
    description:
      "Kimi 长文本模型,超长上下文与文档检索能力强,适合大文档/多 PDF 阅读。",
    context_length: 256_000,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "A",
    adapter: "kimi",
    upstreamModel: "kimi-k2-0905-preview",
    sources: ["china-direct"],
  },
  {
    id: "mdl_qwen-max",
    name: "DoAtlas Bilingual",
    provider: "DoAtlas",
    description:
      "通义千问 Max 双语通用模型,中英推理与工具调用稳定,适合中文研究场景。",
    context_length: 131_072,
    capabilities: ["text", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "A",
    adapter: "qwen",
    upstreamModel: "qwen-max",
    sources: ["china-direct"],
  },
  {
    id: "mdl_gemini-2_5-flash",
    name: "DoAtlas Vision Lite",
    provider: "DoAtlas",
    description:
      "Gemini 2.5 Flash 轻量多模态模型,速度快、成本低,适合实时问答与轻量视觉任务。",
    context_length: 1_000_000,
    capabilities: ["text", "vision", "tools", "streaming"],
    pricing: { input_per_1k: 0, output_per_1k: 0 },
    default: false,
    available: false,
    tier: "A",
    adapter: "gemini",
    upstreamModel: "gemini-2.5-flash",
    sources: ["replit-integration", "byok-direct"],
  },
];

/**
 * Adapter-by-source availability table. A model is available when at
 * least one of its declared sources has credentials configured.
 */
function sourceAvailable(adapter: AdapterId, source: ModelSource): boolean {
  switch (adapter) {
    case "anthropic":
      if (source === "replit-integration") return config.hasAnthropicCloud;
      if (source === "byok-direct") return config.hasAnthropicDirect;
      return false;
    case "openai":
      if (source === "replit-integration") return config.hasOpenAICloud;
      if (source === "byok-direct") return config.hasOpenAIDirect;
      return false;
    case "gemini":
      if (source === "replit-integration") return config.hasGeminiCloud;
      if (source === "byok-direct") return config.hasGeminiDirect;
      return false;
    case "deepseek":
      return source === "china-direct" && config.hasDeepseek;
    case "kimi":
      return source === "china-direct" && config.hasKimi;
    case "zhipu":
      return source === "china-direct" && config.hasZhipu;
    case "minimax":
      return source === "china-direct" && config.hasMinimax;
    case "qwen":
      return source === "china-direct" && config.hasQwen;
    case "codex-cli":
      return source === "byok-direct" && config.hasCodexCli;
    default:
      return false;
  }
}

function isAvailable(m: ModelInfo): boolean {
  return m.sources.some((s) => sourceAvailable(m.adapter, s));
}

/**
 * Return the source actually used to call this model. The first
 * configured source from the model's `sources` list wins.
 */
export function resolveSource(m: ModelInfo): ModelSource | null {
  for (const s of m.sources) {
    if (sourceAvailable(m.adapter, s)) return s;
  }
  return null;
}

export function listModels(): ModelInfo[] {
  const profile = config.profile;
  const out = ALL_MODELS.map((m) => ({
    ...m,
    available: isAvailable(m),
  }));
  // Profile is now a preference filter for default selection only.
  // "cloud" prefers replit-integration/byok-direct models; "local"
  // accepts everything that's available.
  const preferCloud = profile === "cloud";
  const candidates = preferCloud
    ? out.filter(
        (m) =>
          m.available &&
          m.sources.some((s) => s === "replit-integration" || s === "byok-direct"),
      )
    : out.filter((m) => m.available);
  const first = candidates[0] ?? out.find((m) => m.available);
  if (first) {
    const target = out.find((m) => m.id === first.id);
    if (target) target.default = true;
  }
  return out;
}

export function findModel(id: string | null | undefined): ModelInfo | null {
  if (!id) return null;
  return listModels().find((m) => m.id === id) ?? null;
}

export function pickDefaultModel(): ModelInfo | null {
  return listModels().find((m) => m.default) ?? null;
}

export function publicModel(m: ModelInfo) {
  // Strip internal routing fields.
  const { tier: _t, adapter: _a, upstreamModel: _u, sources: _s, ...pub } = m;
  return pub;
}