pi-tsgw 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/extensions/index.test.ts +509 -0
- package/extensions/index.ts +185 -0
- package/extensions/models/_tools.ts +139 -0
- package/extensions/models/catalog.test.ts +137 -0
- package/extensions/models/catalog.ts +100 -0
- package/extensions/models/operations.test.ts +428 -0
- package/extensions/models/operations.ts +54 -0
- package/extensions/models/vendors/_protocols.ts +24 -0
- package/extensions/models/vendors/anthropic.ts +211 -0
- package/extensions/models/vendors/deepseek.ts +82 -0
- package/extensions/models/vendors/gemini.ts +148 -0
- package/extensions/models/vendors/glm.ts +157 -0
- package/extensions/models/vendors/kimi.ts +124 -0
- package/extensions/models/vendors/longcat.ts +30 -0
- package/extensions/models/vendors/mimo.ts +47 -0
- package/extensions/models/vendors/minimax.ts +84 -0
- package/extensions/models/vendors/openai.ts +249 -0
- package/extensions/models/vendors/qwen.ts +102 -0
- package/extensions/web-search/web-search.test.ts +111 -0
- package/extensions/web-search/web-search.ts +73 -0
- package/package.json +36 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { deepStrictEqual, equal, strictEqual } from "node:assert";
|
|
2
|
+
import { applyModelOperations } from "./operations.ts";
|
|
3
|
+
import {
|
|
4
|
+
isPlainObject,
|
|
5
|
+
type ModelOperationContext,
|
|
6
|
+
type ThinkingLevel,
|
|
7
|
+
} from "./_tools.ts";
|
|
8
|
+
|
|
9
|
+
type Payload = Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
const levels = [
|
|
12
|
+
"off",
|
|
13
|
+
"high",
|
|
14
|
+
"xhigh",
|
|
15
|
+
"max",
|
|
16
|
+
] as const satisfies readonly ThinkingLevel[];
|
|
17
|
+
|
|
18
|
+
function deepFreeze(value: unknown): void {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
for (const item of value) deepFreeze(item);
|
|
21
|
+
Object.freeze(value);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (isPlainObject(value)) {
|
|
25
|
+
for (const item of Object.values(value)) deepFreeze(item);
|
|
26
|
+
Object.freeze(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function context(
|
|
31
|
+
modelId: string,
|
|
32
|
+
api = "openai-completions",
|
|
33
|
+
thinkingLevel: ThinkingLevel = "high",
|
|
34
|
+
): ModelOperationContext {
|
|
35
|
+
return { provider: "tsgw", modelId, api, thinkingLevel };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function apply(
|
|
39
|
+
payload: Payload,
|
|
40
|
+
modelId: string,
|
|
41
|
+
api: string,
|
|
42
|
+
thinkingLevel: ThinkingLevel,
|
|
43
|
+
): Payload {
|
|
44
|
+
deepFreeze(payload);
|
|
45
|
+
const result = applyModelOperations(
|
|
46
|
+
payload,
|
|
47
|
+
context(modelId, api, thinkingLevel),
|
|
48
|
+
);
|
|
49
|
+
if (!isPlainObject(result)) throw new Error("expected a plain object result");
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function completionBase(): Payload {
|
|
54
|
+
return {
|
|
55
|
+
stream: true,
|
|
56
|
+
reasoning_effort: "medium",
|
|
57
|
+
thinking: { type: "legacy", retained: true },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function testCompletionProfiles(): void {
|
|
62
|
+
for (const modelId of ["deepseek-v4-flash", "deepseek-v4-pro"]) {
|
|
63
|
+
for (const level of levels) {
|
|
64
|
+
const result = apply(
|
|
65
|
+
completionBase(),
|
|
66
|
+
modelId,
|
|
67
|
+
"openai-completions",
|
|
68
|
+
level,
|
|
69
|
+
);
|
|
70
|
+
const effort =
|
|
71
|
+
level === "off"
|
|
72
|
+
? undefined
|
|
73
|
+
: level === "xhigh" || level === "max"
|
|
74
|
+
? "max"
|
|
75
|
+
: "high";
|
|
76
|
+
deepStrictEqual(
|
|
77
|
+
result,
|
|
78
|
+
effort === undefined
|
|
79
|
+
? { stream: true, thinking: { type: "disabled", retained: true } }
|
|
80
|
+
: {
|
|
81
|
+
stream: true,
|
|
82
|
+
reasoning_effort: effort,
|
|
83
|
+
thinking: { type: "enabled", retained: true },
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
deepStrictEqual(
|
|
89
|
+
apply(
|
|
90
|
+
completionBase(),
|
|
91
|
+
"deepseek-v4-flash",
|
|
92
|
+
"openai-completions",
|
|
93
|
+
"minimal",
|
|
94
|
+
),
|
|
95
|
+
{
|
|
96
|
+
stream: true,
|
|
97
|
+
reasoning_effort: "high",
|
|
98
|
+
thinking: { type: "enabled", retained: true },
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
for (const modelId of ["glm-5.2", "glm-5.1"]) {
|
|
103
|
+
for (const level of levels) {
|
|
104
|
+
const result = apply(
|
|
105
|
+
completionBase(),
|
|
106
|
+
modelId,
|
|
107
|
+
"openai-completions",
|
|
108
|
+
level,
|
|
109
|
+
);
|
|
110
|
+
const effort =
|
|
111
|
+
level === "off"
|
|
112
|
+
? "none"
|
|
113
|
+
: level === "xhigh" || level === "max"
|
|
114
|
+
? "max"
|
|
115
|
+
: "high";
|
|
116
|
+
deepStrictEqual(result, {
|
|
117
|
+
stream: true,
|
|
118
|
+
tool_stream: true,
|
|
119
|
+
reasoning_effort: effort,
|
|
120
|
+
thinking:
|
|
121
|
+
level === "off"
|
|
122
|
+
? { type: "disabled", retained: true }
|
|
123
|
+
: { type: "enabled", retained: true, clear_thinking: false },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const glmNotStreaming = apply(
|
|
128
|
+
{ stream: false, reasoning_effort: "medium", thinking: { type: "legacy" } },
|
|
129
|
+
"glm-5.2",
|
|
130
|
+
"openai-completions",
|
|
131
|
+
"high",
|
|
132
|
+
);
|
|
133
|
+
equal(Object.hasOwn(glmNotStreaming, "tool_stream"), false);
|
|
134
|
+
|
|
135
|
+
for (const modelId of [
|
|
136
|
+
"mimo-v2.5",
|
|
137
|
+
"mimo-v2.5-pro",
|
|
138
|
+
"kimi-for-coding",
|
|
139
|
+
"longcat-2.0",
|
|
140
|
+
]) {
|
|
141
|
+
for (const level of levels) {
|
|
142
|
+
const result = apply(
|
|
143
|
+
completionBase(),
|
|
144
|
+
modelId,
|
|
145
|
+
"openai-completions",
|
|
146
|
+
level,
|
|
147
|
+
);
|
|
148
|
+
deepStrictEqual(result, {
|
|
149
|
+
stream: true,
|
|
150
|
+
thinking: {
|
|
151
|
+
type: level === "off" ? "disabled" : "enabled",
|
|
152
|
+
retained: true,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (const level of levels) {
|
|
159
|
+
const result = apply(
|
|
160
|
+
completionBase(),
|
|
161
|
+
"minimax-m3",
|
|
162
|
+
"openai-completions",
|
|
163
|
+
level,
|
|
164
|
+
);
|
|
165
|
+
deepStrictEqual(result, {
|
|
166
|
+
stream: true,
|
|
167
|
+
reasoning_split: true,
|
|
168
|
+
thinking: {
|
|
169
|
+
type: level === "off" ? "disabled" : "adaptive",
|
|
170
|
+
retained: true,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
for (const level of [
|
|
176
|
+
"off",
|
|
177
|
+
"minimal",
|
|
178
|
+
"low",
|
|
179
|
+
"medium",
|
|
180
|
+
"high",
|
|
181
|
+
"xhigh",
|
|
182
|
+
"max",
|
|
183
|
+
] as const satisfies readonly ThinkingLevel[]) {
|
|
184
|
+
const result = apply(
|
|
185
|
+
completionBase(),
|
|
186
|
+
"kimi-k3",
|
|
187
|
+
"openai-completions",
|
|
188
|
+
level,
|
|
189
|
+
);
|
|
190
|
+
const effort =
|
|
191
|
+
level === "off"
|
|
192
|
+
? undefined
|
|
193
|
+
: level === "minimal" || level === "low"
|
|
194
|
+
? "low"
|
|
195
|
+
: level === "max"
|
|
196
|
+
? "max"
|
|
197
|
+
: "high";
|
|
198
|
+
deepStrictEqual(
|
|
199
|
+
result,
|
|
200
|
+
effort === undefined
|
|
201
|
+
? { stream: true }
|
|
202
|
+
: { stream: true, reasoning_effort: effort },
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
for (const modelId of ["qwen3.7-plus", "qwen3.7-max"]) {
|
|
207
|
+
for (const level of levels) {
|
|
208
|
+
const result = apply(
|
|
209
|
+
{
|
|
210
|
+
...completionBase(),
|
|
211
|
+
thinking_budget: 1,
|
|
212
|
+
search_options: { old: true },
|
|
213
|
+
enable_code_interpreter: false,
|
|
214
|
+
},
|
|
215
|
+
modelId,
|
|
216
|
+
"openai-completions",
|
|
217
|
+
level,
|
|
218
|
+
);
|
|
219
|
+
const expected: Payload = {
|
|
220
|
+
stream: true,
|
|
221
|
+
enable_search: true,
|
|
222
|
+
parallel_tool_calls: true,
|
|
223
|
+
enable_thinking: level !== "off",
|
|
224
|
+
preserve_thinking: level !== "off",
|
|
225
|
+
thinking: { type: "legacy", retained: true },
|
|
226
|
+
};
|
|
227
|
+
if (level !== "off") {
|
|
228
|
+
expected.thinking_budget = 6000;
|
|
229
|
+
expected.search_options = { search_strategy: "agent_max" };
|
|
230
|
+
expected.enable_code_interpreter = true;
|
|
231
|
+
}
|
|
232
|
+
deepStrictEqual(result, expected);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const qwenLow = apply(
|
|
236
|
+
{
|
|
237
|
+
...completionBase(),
|
|
238
|
+
thinking_budget: 1,
|
|
239
|
+
search_options: { old: true },
|
|
240
|
+
enable_code_interpreter: false,
|
|
241
|
+
},
|
|
242
|
+
"qwen3.7-plus",
|
|
243
|
+
"openai-completions",
|
|
244
|
+
"low",
|
|
245
|
+
);
|
|
246
|
+
deepStrictEqual(qwenLow, {
|
|
247
|
+
stream: true,
|
|
248
|
+
thinking: { type: "legacy", retained: true },
|
|
249
|
+
enable_search: true,
|
|
250
|
+
parallel_tool_calls: true,
|
|
251
|
+
enable_thinking: true,
|
|
252
|
+
preserve_thinking: true,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function testGeminiProfiles(): void {
|
|
257
|
+
for (const level of levels) {
|
|
258
|
+
const tools = [{ functionDeclarations: [{ name: "keep" }] }];
|
|
259
|
+
const signal = new AbortController().signal;
|
|
260
|
+
const input = {
|
|
261
|
+
reasoning_effort: "medium",
|
|
262
|
+
config: {
|
|
263
|
+
tools,
|
|
264
|
+
abortSignal: signal,
|
|
265
|
+
thinkingConfig: { retained: true, thinkingLevel: "HIGH" },
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
const result = apply(input, "gemini-flash", "google-generative-ai", level);
|
|
269
|
+
const budget = level === "max" ? 24576 : level === "off" ? 0 : 16000;
|
|
270
|
+
deepStrictEqual(result, {
|
|
271
|
+
config: {
|
|
272
|
+
tools,
|
|
273
|
+
abortSignal: signal,
|
|
274
|
+
thinkingConfig: {
|
|
275
|
+
retained: true,
|
|
276
|
+
includeThoughts: level !== "off",
|
|
277
|
+
thinkingBudget: budget,
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
strictEqual((result.config as Payload).tools, tools);
|
|
282
|
+
strictEqual((result.config as Payload).abortSignal, signal);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const proLevels: readonly ThinkingLevel[] = [
|
|
286
|
+
"off",
|
|
287
|
+
"minimal",
|
|
288
|
+
"low",
|
|
289
|
+
"medium",
|
|
290
|
+
"high",
|
|
291
|
+
"xhigh",
|
|
292
|
+
"max",
|
|
293
|
+
];
|
|
294
|
+
for (const level of proLevels) {
|
|
295
|
+
const tools = [{ functionDeclarations: [{ name: "keep" }] }];
|
|
296
|
+
const signal = new AbortController().signal;
|
|
297
|
+
const input = {
|
|
298
|
+
reasoning_effort: "medium",
|
|
299
|
+
config: {
|
|
300
|
+
tools,
|
|
301
|
+
abortSignal: signal,
|
|
302
|
+
thinkingConfig: { retained: true, thinkingBudget: 42 },
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
const result = apply(input, "gemini-pro", "google-generative-ai", level);
|
|
306
|
+
const thinkingLevel =
|
|
307
|
+
level === "off" || level === "minimal" || level === "low"
|
|
308
|
+
? "LOW"
|
|
309
|
+
: level === "medium"
|
|
310
|
+
? "MEDIUM"
|
|
311
|
+
: "HIGH";
|
|
312
|
+
deepStrictEqual(result, {
|
|
313
|
+
config: {
|
|
314
|
+
tools,
|
|
315
|
+
abortSignal: signal,
|
|
316
|
+
thinkingConfig: {
|
|
317
|
+
retained: true,
|
|
318
|
+
includeThoughts: level !== "off",
|
|
319
|
+
thinkingLevel,
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
strictEqual((result.config as Payload).tools, tools);
|
|
324
|
+
strictEqual((result.config as Payload).abortSignal, signal);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function testOpenAIResponsesProfiles(): void {
|
|
329
|
+
const verbosityByModel: Record<string, "low" | "medium"> = {
|
|
330
|
+
"gpt-5.6-sol": "low",
|
|
331
|
+
"gpt-5.6-terra": "medium",
|
|
332
|
+
"gpt-5.6-luna": "low",
|
|
333
|
+
"gpt-5.5": "low",
|
|
334
|
+
"gpt-5.3-codex-spark": "low",
|
|
335
|
+
};
|
|
336
|
+
for (const [modelId, verbosity] of Object.entries(verbosityByModel)) {
|
|
337
|
+
for (const level of levels) {
|
|
338
|
+
const reasoning = { effort: "high", summary: "auto", retained: true };
|
|
339
|
+
const input = {
|
|
340
|
+
reasoning,
|
|
341
|
+
text: { format: "text" },
|
|
342
|
+
include: ["reasoning.encrypted_content"],
|
|
343
|
+
store: false,
|
|
344
|
+
parallel_tool_calls: false,
|
|
345
|
+
};
|
|
346
|
+
const result = apply(input, modelId, "openai-responses", level);
|
|
347
|
+
deepStrictEqual(result, {
|
|
348
|
+
reasoning,
|
|
349
|
+
text: { format: "text", verbosity },
|
|
350
|
+
include: ["reasoning.encrypted_content"],
|
|
351
|
+
store: false,
|
|
352
|
+
parallel_tool_calls: false,
|
|
353
|
+
service_tier: "flex",
|
|
354
|
+
});
|
|
355
|
+
strictEqual(result.reasoning, reasoning);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function testNoOpsAndProtectedFields(): void {
|
|
361
|
+
const nonPlain = [null, [], new Date()] as const;
|
|
362
|
+
for (const payload of nonPlain)
|
|
363
|
+
strictEqual(
|
|
364
|
+
applyModelOperations(payload, context("deepseek-v4-flash")),
|
|
365
|
+
payload,
|
|
366
|
+
);
|
|
367
|
+
const claude = { model: "keep" };
|
|
368
|
+
strictEqual(
|
|
369
|
+
applyModelOperations(
|
|
370
|
+
claude,
|
|
371
|
+
context("claude-fable-5", "anthropic-messages"),
|
|
372
|
+
),
|
|
373
|
+
claude,
|
|
374
|
+
);
|
|
375
|
+
strictEqual(
|
|
376
|
+
applyModelOperations(claude, {
|
|
377
|
+
...context("gpt-5.6-sol", "openai-responses"),
|
|
378
|
+
provider: "other",
|
|
379
|
+
}),
|
|
380
|
+
claude,
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
const input: Payload = {
|
|
384
|
+
model: "keep",
|
|
385
|
+
messages: [{ role: "user", content: "keep" }],
|
|
386
|
+
input: ["keep"],
|
|
387
|
+
contents: ["keep"],
|
|
388
|
+
system: "keep",
|
|
389
|
+
tools: [{ type: "function", name: "keep" }],
|
|
390
|
+
tool_choice: "auto",
|
|
391
|
+
headers: { keep: "yes" },
|
|
392
|
+
stream: true,
|
|
393
|
+
include: ["keep"],
|
|
394
|
+
store: false,
|
|
395
|
+
prompt_cache_key: "keep",
|
|
396
|
+
max_output_tokens: 9,
|
|
397
|
+
reasoning_effort: "keep",
|
|
398
|
+
reasoning: { effort: "high", summary: "auto" },
|
|
399
|
+
parallel_tool_calls: false,
|
|
400
|
+
};
|
|
401
|
+
const result = apply(input, "gpt-5.6-terra", "openai-responses", "high");
|
|
402
|
+
for (const key of [
|
|
403
|
+
"model",
|
|
404
|
+
"messages",
|
|
405
|
+
"input",
|
|
406
|
+
"contents",
|
|
407
|
+
"system",
|
|
408
|
+
"tools",
|
|
409
|
+
"tool_choice",
|
|
410
|
+
"headers",
|
|
411
|
+
"stream",
|
|
412
|
+
"include",
|
|
413
|
+
"store",
|
|
414
|
+
"prompt_cache_key",
|
|
415
|
+
"max_output_tokens",
|
|
416
|
+
"reasoning_effort",
|
|
417
|
+
"reasoning",
|
|
418
|
+
"parallel_tool_calls",
|
|
419
|
+
]) {
|
|
420
|
+
deepStrictEqual(result[key], input[key]);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
testCompletionProfiles();
|
|
425
|
+
testGeminiProfiles();
|
|
426
|
+
testOpenAIResponsesProfiles();
|
|
427
|
+
testNoOpsAndProtectedFields();
|
|
428
|
+
console.log("operations.test.ts: all assertions passed");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 请求体改写调度:按模型 id 查各厂商的思维链策略并应用。
|
|
3
|
+
*
|
|
4
|
+
* 各厂商的 thinking 策略定义在 `vendors/*.ts`(厂商文件自包含其思维链
|
|
5
|
+
* 要求),本模块只做汇总与调度,不再硬编码模型族 switch。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isPlainObject,
|
|
10
|
+
PayloadWriter,
|
|
11
|
+
type ModelOperationContext,
|
|
12
|
+
type ThinkingApplier,
|
|
13
|
+
} from "./_tools.ts";
|
|
14
|
+
import { deepseekThinking } from "./vendors/deepseek.ts";
|
|
15
|
+
import { geminiThinking } from "./vendors/gemini.ts";
|
|
16
|
+
import { glmThinking } from "./vendors/glm.ts";
|
|
17
|
+
import { kimiThinking } from "./vendors/kimi.ts";
|
|
18
|
+
import { longcatThinking } from "./vendors/longcat.ts";
|
|
19
|
+
import { mimoThinking } from "./vendors/mimo.ts";
|
|
20
|
+
import { minimaxThinking } from "./vendors/minimax.ts";
|
|
21
|
+
import { openaiThinking } from "./vendors/openai.ts";
|
|
22
|
+
import { qwenThinking } from "./vendors/qwen.ts";
|
|
23
|
+
|
|
24
|
+
// 与 catalog.ts 的 PROVIDER_ID 保持一致;此处不 import catalog,避免循环依赖。
|
|
25
|
+
const TSGW_PROVIDER = "tsgw";
|
|
26
|
+
|
|
27
|
+
const THINKING_STRATEGIES: Record<string, ThinkingApplier> = {
|
|
28
|
+
...deepseekThinking,
|
|
29
|
+
...glmThinking,
|
|
30
|
+
...mimoThinking,
|
|
31
|
+
...minimaxThinking,
|
|
32
|
+
...kimiThinking,
|
|
33
|
+
...longcatThinking,
|
|
34
|
+
...qwenThinking,
|
|
35
|
+
...openaiThinking,
|
|
36
|
+
...geminiThinking,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Apply the closed set of per-vendor thinking operations without mutating
|
|
41
|
+
* `payload`. Non-plain payloads and all non-TSGW requests are returned
|
|
42
|
+
* unchanged. Models without a registered strategy pass through untouched.
|
|
43
|
+
*/
|
|
44
|
+
export function applyModelOperations(
|
|
45
|
+
payload: unknown,
|
|
46
|
+
context: ModelOperationContext,
|
|
47
|
+
): unknown {
|
|
48
|
+
if (!isPlainObject(payload) || context.provider !== TSGW_PROVIDER)
|
|
49
|
+
return payload;
|
|
50
|
+
const writer = new PayloadWriter(payload);
|
|
51
|
+
const applier = THINKING_STRATEGIES[context.modelId];
|
|
52
|
+
if (applier) applier(writer, context);
|
|
53
|
+
return writer.result();
|
|
54
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wire 协议公共配置。
|
|
5
|
+
*
|
|
6
|
+
* 网关上的模型虽然很多,底层协议就这四类:openai-completions、
|
|
7
|
+
* openai-responses、anthropic-messages、google-generative-ai。
|
|
8
|
+
* 供应商分片从这里引用对应协议的公共 compat,避免各自重复定义。
|
|
9
|
+
*
|
|
10
|
+
* 目前只维护这四种主流协议;其他(非主流或未来新增)协议暂不纳入,
|
|
11
|
+
* 有适配需要时再在此扩展。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** openai-completions:网关接受 `system` role,但不接受 OpenAI 新的 `developer` role。 */
|
|
15
|
+
export const OPENAI_COMPLETIONS_COMPAT: ProviderModelConfig["compat"] = {
|
|
16
|
+
supportsDeveloperRole: false,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** anthropic-messages:Claude 系列使用 Pi 原生 adaptive thinking。 */
|
|
20
|
+
export const ANTHROPIC_COMPAT: ProviderModelConfig["compat"] = {
|
|
21
|
+
forceAdaptiveThinking: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// openai-responses、google-generative-ai:当前无公共 compat,协议字段保持默认。
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { ANTHROPIC_COMPAT } from "./_protocols.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Anthropic Claude 系列(anthropic-messages 协议)。
|
|
6
|
+
* 官方文档:https://docs.claude.com/en/docs/about-claude/models/
|
|
7
|
+
*/
|
|
8
|
+
export function anthropicModels(root: string): ProviderModelConfig[] {
|
|
9
|
+
const anthropic = `${root}/anthropic`;
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
id: "claude-fable-5",
|
|
13
|
+
name: "Claude Fable 5",
|
|
14
|
+
api: "anthropic-messages",
|
|
15
|
+
baseUrl: anthropic,
|
|
16
|
+
reasoning: true,
|
|
17
|
+
thinkingLevelMap: {
|
|
18
|
+
low: "low",
|
|
19
|
+
medium: "medium",
|
|
20
|
+
high: "high",
|
|
21
|
+
max: "max",
|
|
22
|
+
},
|
|
23
|
+
input: ["text", "image"],
|
|
24
|
+
cost: { input: 10, output: 50, cacheRead: 1, cacheWrite: 12.3 },
|
|
25
|
+
contextWindow: 1000000,
|
|
26
|
+
maxTokens: 128000,
|
|
27
|
+
compat: ANTHROPIC_COMPAT,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "claude-opus-4-8",
|
|
31
|
+
name: "Claude Opus 4.8",
|
|
32
|
+
api: "anthropic-messages",
|
|
33
|
+
baseUrl: anthropic,
|
|
34
|
+
reasoning: true,
|
|
35
|
+
thinkingLevelMap: {
|
|
36
|
+
low: "low",
|
|
37
|
+
medium: "medium",
|
|
38
|
+
high: "high",
|
|
39
|
+
max: "max",
|
|
40
|
+
},
|
|
41
|
+
input: ["text", "image"],
|
|
42
|
+
cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
43
|
+
contextWindow: 200000,
|
|
44
|
+
maxTokens: 128000,
|
|
45
|
+
compat: ANTHROPIC_COMPAT,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "claude-sonnet",
|
|
49
|
+
name: "Claude Sonnet 4.6",
|
|
50
|
+
api: "anthropic-messages",
|
|
51
|
+
baseUrl: anthropic,
|
|
52
|
+
reasoning: true,
|
|
53
|
+
thinkingLevelMap: {
|
|
54
|
+
low: "low",
|
|
55
|
+
medium: "medium",
|
|
56
|
+
high: "high",
|
|
57
|
+
max: "max",
|
|
58
|
+
},
|
|
59
|
+
input: ["text", "image"],
|
|
60
|
+
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
61
|
+
contextWindow: 200000,
|
|
62
|
+
maxTokens: 64000,
|
|
63
|
+
compat: ANTHROPIC_COMPAT,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "claude-opus-4",
|
|
67
|
+
name: "Claude Opus 4",
|
|
68
|
+
api: "anthropic-messages",
|
|
69
|
+
baseUrl: anthropic,
|
|
70
|
+
reasoning: true,
|
|
71
|
+
thinkingLevelMap: {
|
|
72
|
+
low: "low",
|
|
73
|
+
medium: "medium",
|
|
74
|
+
high: "high",
|
|
75
|
+
max: "max",
|
|
76
|
+
},
|
|
77
|
+
input: ["text", "image"],
|
|
78
|
+
cost: { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
79
|
+
contextWindow: 200000,
|
|
80
|
+
maxTokens: 32000,
|
|
81
|
+
compat: ANTHROPIC_COMPAT,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "claude-opus-4.1",
|
|
85
|
+
name: "Claude Opus 4.1",
|
|
86
|
+
api: "anthropic-messages",
|
|
87
|
+
baseUrl: anthropic,
|
|
88
|
+
reasoning: true,
|
|
89
|
+
thinkingLevelMap: {
|
|
90
|
+
low: "low",
|
|
91
|
+
medium: "medium",
|
|
92
|
+
high: "high",
|
|
93
|
+
max: "max",
|
|
94
|
+
},
|
|
95
|
+
input: ["text", "image"],
|
|
96
|
+
cost: { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
97
|
+
contextWindow: 200000,
|
|
98
|
+
maxTokens: 32000,
|
|
99
|
+
compat: ANTHROPIC_COMPAT,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "claude-opus-4.5",
|
|
103
|
+
name: "Claude Opus 4.5",
|
|
104
|
+
api: "anthropic-messages",
|
|
105
|
+
baseUrl: anthropic,
|
|
106
|
+
reasoning: true,
|
|
107
|
+
thinkingLevelMap: {
|
|
108
|
+
low: "low",
|
|
109
|
+
medium: "medium",
|
|
110
|
+
high: "high",
|
|
111
|
+
max: "max",
|
|
112
|
+
},
|
|
113
|
+
input: ["text", "image"],
|
|
114
|
+
cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
115
|
+
contextWindow: 200000,
|
|
116
|
+
maxTokens: 64000,
|
|
117
|
+
compat: ANTHROPIC_COMPAT,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "claude-opus-4.6",
|
|
121
|
+
name: "Claude Opus 4.6",
|
|
122
|
+
api: "anthropic-messages",
|
|
123
|
+
baseUrl: anthropic,
|
|
124
|
+
reasoning: true,
|
|
125
|
+
thinkingLevelMap: {
|
|
126
|
+
low: "low",
|
|
127
|
+
medium: "medium",
|
|
128
|
+
high: "high",
|
|
129
|
+
max: "max",
|
|
130
|
+
},
|
|
131
|
+
input: ["text", "image"],
|
|
132
|
+
cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
133
|
+
contextWindow: 1000000,
|
|
134
|
+
maxTokens: 128000,
|
|
135
|
+
compat: ANTHROPIC_COMPAT,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "claude-opus-4.7",
|
|
139
|
+
name: "Claude Opus 4.7",
|
|
140
|
+
api: "anthropic-messages",
|
|
141
|
+
baseUrl: anthropic,
|
|
142
|
+
reasoning: true,
|
|
143
|
+
thinkingLevelMap: {
|
|
144
|
+
low: "low",
|
|
145
|
+
medium: "medium",
|
|
146
|
+
high: "high",
|
|
147
|
+
max: "max",
|
|
148
|
+
},
|
|
149
|
+
input: ["text", "image"],
|
|
150
|
+
cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
|
|
151
|
+
contextWindow: 1000000,
|
|
152
|
+
maxTokens: 128000,
|
|
153
|
+
compat: ANTHROPIC_COMPAT,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "claude-sonnet-4",
|
|
157
|
+
name: "Claude Sonnet 4",
|
|
158
|
+
api: "anthropic-messages",
|
|
159
|
+
baseUrl: anthropic,
|
|
160
|
+
reasoning: true,
|
|
161
|
+
thinkingLevelMap: {
|
|
162
|
+
low: "low",
|
|
163
|
+
medium: "medium",
|
|
164
|
+
high: "high",
|
|
165
|
+
max: "max",
|
|
166
|
+
},
|
|
167
|
+
input: ["text", "image"],
|
|
168
|
+
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
169
|
+
contextWindow: 200000,
|
|
170
|
+
maxTokens: 64000,
|
|
171
|
+
compat: ANTHROPIC_COMPAT,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: "claude-sonnet-4.5",
|
|
175
|
+
name: "Claude Sonnet 4.5",
|
|
176
|
+
api: "anthropic-messages",
|
|
177
|
+
baseUrl: anthropic,
|
|
178
|
+
reasoning: true,
|
|
179
|
+
thinkingLevelMap: {
|
|
180
|
+
low: "low",
|
|
181
|
+
medium: "medium",
|
|
182
|
+
high: "high",
|
|
183
|
+
max: "max",
|
|
184
|
+
},
|
|
185
|
+
input: ["text", "image"],
|
|
186
|
+
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
187
|
+
contextWindow: 200000,
|
|
188
|
+
maxTokens: 64000,
|
|
189
|
+
compat: ANTHROPIC_COMPAT,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
id: "claude-sonnet-5",
|
|
193
|
+
name: "Claude Sonnet 5",
|
|
194
|
+
api: "anthropic-messages",
|
|
195
|
+
baseUrl: anthropic,
|
|
196
|
+
reasoning: true,
|
|
197
|
+
thinkingLevelMap: {
|
|
198
|
+
low: "low",
|
|
199
|
+
medium: "medium",
|
|
200
|
+
high: "high",
|
|
201
|
+
max: "max",
|
|
202
|
+
},
|
|
203
|
+
input: ["text", "image"],
|
|
204
|
+
// 官方 introductory 定价(至 2026-08-31),其后为 $3/$15。
|
|
205
|
+
cost: { input: 2, output: 10, cacheRead: 0.2, cacheWrite: 2.5 },
|
|
206
|
+
contextWindow: 1000000,
|
|
207
|
+
maxTokens: 128000,
|
|
208
|
+
compat: ANTHROPIC_COMPAT,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
}
|