pi-model-manager 0.3.4 → 0.3.6
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/README.en.md +28 -9
- package/README.md +28 -9
- package/atomic-write.ts +2 -2
- package/configuration-persistence.ts +32 -1
- package/i18n.ts +25 -1
- package/index.ts +9 -2
- package/local-proxy-service.ts +3 -2
- package/models-json-sync.ts +30 -3
- package/openai-responses-payload.ts +6 -8
- package/package.json +4 -2
- package/presets/builtin-client-headers.ts +3 -3
- package/presets/client-headers.ts +10 -13
- package/presets/providers.ts +1 -1
- package/provider-registrar.ts +36 -117
- package/provider-transport.ts +178 -0
- package/request-pipeline.ts +22 -17
- package/runtime-base-url.ts +45 -65
- package/state-document.ts +32 -10
- package/state-metadata-store.ts +43 -7
- package/state-store.ts +24 -4
- package/tui/editor-provider.ts +57 -1
- package/tui/model-list-fetch.ts +22 -70
- package/types.ts +5 -0
package/state-document.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { joinLocalizedList, t } from "./i18n.ts";
|
|
|
19
19
|
import { findPresetForApi } from "./presets/providers.ts";
|
|
20
20
|
import { normalizeThinkingLevelMap } from "./presets/thinking.ts";
|
|
21
21
|
import { isSensitiveHeaderName } from "./sensitive-redaction.ts";
|
|
22
|
-
import { resolveRuntimeBaseUrl } from "./runtime-base-url.ts";
|
|
22
|
+
import { fromNativeBaseUrl, resolveRuntimeBaseUrl, validateRequestBaseUrl } from "./runtime-base-url.ts";
|
|
23
23
|
import type {
|
|
24
24
|
ApiKind,
|
|
25
25
|
CompatSettings,
|
|
@@ -90,6 +90,7 @@ export function createProviderDraft(api: ApiKind = "openai-responses"): Provider
|
|
|
90
90
|
customClientHeaders: {},
|
|
91
91
|
httpProxyEnabled: false,
|
|
92
92
|
httpProxyUrl: DEFAULT_PROVIDER_HTTP_PROXY_URL,
|
|
93
|
+
openAIResponsesStreamCompletionMode: "standard",
|
|
93
94
|
selectedIndex: 0,
|
|
94
95
|
};
|
|
95
96
|
}
|
|
@@ -102,7 +103,7 @@ export function createProviderDraftFromStored(providerId: string, stored: Stored
|
|
|
102
103
|
providerName: stored.name ?? (providerId.replace(/^custom-/, "") || preset.defaultProviderName),
|
|
103
104
|
api,
|
|
104
105
|
openAIChatCompatibilityMode: getOpenAIChatCompatibilityMode(stored.compat),
|
|
105
|
-
baseUrl: stored.baseUrl
|
|
106
|
+
baseUrl: stored.managed ? stored.baseUrl : fromNativeBaseUrl(api, stored.baseUrl),
|
|
106
107
|
apiKey: stored.apiKey ?? "",
|
|
107
108
|
authHeader: stored.authHeader ?? preset.authHeader,
|
|
108
109
|
clientHeaderProfile: stored.clientHeaderProfile ?? "recommended",
|
|
@@ -110,6 +111,7 @@ export function createProviderDraftFromStored(providerId: string, stored: Stored
|
|
|
110
111
|
customClientHeaders: cloneStringRecord(stored.customClientHeaders),
|
|
111
112
|
httpProxyEnabled: stored.httpProxyEnabled ?? false,
|
|
112
113
|
httpProxyUrl: stored.httpProxyUrl?.trim() || DEFAULT_PROVIDER_HTTP_PROXY_URL,
|
|
114
|
+
openAIResponsesStreamCompletionMode: stored.openAIResponsesStreamCompletionMode ?? "standard",
|
|
113
115
|
selectedIndex: 0,
|
|
114
116
|
};
|
|
115
117
|
}
|
|
@@ -128,6 +130,7 @@ function createModelDraftFromProvider(providerDraft: ProviderDraft): ModelDraft
|
|
|
128
130
|
customClientHeaders: cloneStringRecord(providerDraft.customClientHeaders),
|
|
129
131
|
httpProxyEnabled: providerDraft.httpProxyEnabled,
|
|
130
132
|
httpProxyUrl: providerDraft.httpProxyUrl,
|
|
133
|
+
|
|
131
134
|
modelId: "",
|
|
132
135
|
modelName: "",
|
|
133
136
|
// 新建模型默认开启视觉输入;不支持图片的模型可在编辑器里关闭。
|
|
@@ -161,7 +164,9 @@ export function createModelDraftFromStoredModel(
|
|
|
161
164
|
providerId,
|
|
162
165
|
providerName: stored.name ?? (providerId.replace(/^custom-/, "") || preset.defaultProviderName),
|
|
163
166
|
api: effectiveApi,
|
|
164
|
-
baseUrl:
|
|
167
|
+
baseUrl: stored.managed
|
|
168
|
+
? model.baseUrl ?? stored.baseUrl
|
|
169
|
+
: fromNativeBaseUrl(effectiveApi, model.baseUrl ?? stored.baseUrl),
|
|
165
170
|
apiKey: stored.apiKey ?? "",
|
|
166
171
|
authHeader: stored.authHeader ?? preset.authHeader,
|
|
167
172
|
clientHeaderProfile: stored.clientHeaderProfile ?? "recommended",
|
|
@@ -169,6 +174,7 @@ export function createModelDraftFromStoredModel(
|
|
|
169
174
|
customClientHeaders: cloneStringRecord(stored.customClientHeaders),
|
|
170
175
|
httpProxyEnabled: stored.httpProxyEnabled ?? false,
|
|
171
176
|
httpProxyUrl: stored.httpProxyUrl?.trim() || DEFAULT_PROVIDER_HTTP_PROXY_URL,
|
|
177
|
+
|
|
172
178
|
modelId: model.id,
|
|
173
179
|
modelName: model.name ?? "",
|
|
174
180
|
inputKinds: [...(model.input ?? preset.inputKinds)],
|
|
@@ -187,12 +193,9 @@ export function createModelDraftFromStoredModel(
|
|
|
187
193
|
|
|
188
194
|
function validateUrl(url: string, label: string, errors: string[]): void {
|
|
189
195
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
} catch {
|
|
195
|
-
errors.push(t("{label} 不是有效 URL", { label }));
|
|
196
|
+
validateRequestBaseUrl(url);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
errors.push(error instanceof TypeError ? t("{label} 不是有效 URL", { label }) : (error as Error).message);
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
|
|
@@ -288,6 +291,10 @@ export function getProviderChangeWarnings(
|
|
|
288
291
|
&& getOpenAIChatCompatibilityMode(current.compat) !== (draft.openAIChatCompatibilityMode ?? "standard")) {
|
|
289
292
|
changes.push(t("协议兼容"));
|
|
290
293
|
}
|
|
294
|
+
if (draft.api === "openai-responses"
|
|
295
|
+
&& (current.openAIResponsesStreamCompletionMode ?? "standard") !== (draft.openAIResponsesStreamCompletionMode ?? "standard")) {
|
|
296
|
+
changes.push(t("流结束兼容"));
|
|
297
|
+
}
|
|
291
298
|
if ((current.clientHeaderProfile ?? "recommended") !== draft.clientHeaderProfile
|
|
292
299
|
|| (current.requestHeaderProfileId ?? "") !== (draft.requestHeaderProfileId ?? ""))
|
|
293
300
|
changes.push(t("请求头"));
|
|
@@ -343,7 +350,17 @@ function buildProviderFromDraft(
|
|
|
343
350
|
managed: true,
|
|
344
351
|
authHeader: draft.authHeader,
|
|
345
352
|
clientHeaderProfile: draft.clientHeaderProfile,
|
|
346
|
-
models: (current?.models ?? []).map((model) =>
|
|
353
|
+
models: (current?.models ?? []).map((model) => {
|
|
354
|
+
const nextModel = keepModelFieldsSupportedByApi(model, draft.api, apiChanged);
|
|
355
|
+
if (current && !current.managed && (model.baseUrl
|
|
356
|
+
|| (!apiChanged && draft.baseUrl === fromNativeBaseUrl(current.api, current.baseUrl)))) {
|
|
357
|
+
const api = model.api ?? current.api;
|
|
358
|
+
const baseUrl = fromNativeBaseUrl(api, model.baseUrl ?? current.baseUrl);
|
|
359
|
+
if (baseUrl !== draft.baseUrl) nextModel.baseUrl = baseUrl;
|
|
360
|
+
else delete nextModel.baseUrl;
|
|
361
|
+
}
|
|
362
|
+
return nextModel;
|
|
363
|
+
}),
|
|
347
364
|
};
|
|
348
365
|
const apiKey = draft.apiKey.trim();
|
|
349
366
|
if (apiKey) next.apiKey = apiKey;
|
|
@@ -353,6 +370,11 @@ function buildProviderFromDraft(
|
|
|
353
370
|
else delete next.httpProxyEnabled;
|
|
354
371
|
if (draft.httpProxyEnabled || httpProxyUrl !== DEFAULT_PROVIDER_HTTP_PROXY_URL) next.httpProxyUrl = httpProxyUrl;
|
|
355
372
|
else delete next.httpProxyUrl;
|
|
373
|
+
if (draft.api === "openai-responses" && draft.openAIResponsesStreamCompletionMode === "terminal-event") {
|
|
374
|
+
next.openAIResponsesStreamCompletionMode = "terminal-event";
|
|
375
|
+
} else {
|
|
376
|
+
delete next.openAIResponsesStreamCompletionMode;
|
|
377
|
+
}
|
|
356
378
|
if (draft.clientHeaderProfile === "custom" && draft.requestHeaderProfileId?.trim()) {
|
|
357
379
|
next.requestHeaderProfileId = draft.requestHeaderProfileId.trim();
|
|
358
380
|
} else {
|
package/state-metadata-store.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { join } from "node:path";
|
|
|
9
9
|
import { cloneJson, isObjectRecord, stringifyJson, stripJsonNoise } from "./common.ts";
|
|
10
10
|
import { readStableTextFileSnapshot, type FileSignature } from "./file-snapshot.ts";
|
|
11
11
|
import { t } from "./i18n.ts";
|
|
12
|
+
import { fromNativeBaseUrl, toNativeBaseUrl } from "./runtime-base-url.ts";
|
|
12
13
|
import type {
|
|
13
14
|
ApiKind,
|
|
14
15
|
BuiltInClientHeaderProfileId,
|
|
@@ -21,6 +22,7 @@ import type {
|
|
|
21
22
|
StoredModel,
|
|
22
23
|
StoredProvider,
|
|
23
24
|
StoredRequestHeaderProfile,
|
|
25
|
+
OpenAIResponsesStreamCompletionMode,
|
|
24
26
|
ThinkingLevelMap,
|
|
25
27
|
TokenCost,
|
|
26
28
|
} from "./types.ts";
|
|
@@ -43,14 +45,17 @@ interface ProviderMetadata {
|
|
|
43
45
|
customClientHeaders?: Record<string, string>;
|
|
44
46
|
httpProxyEnabled?: boolean;
|
|
45
47
|
httpProxyUrl?: string;
|
|
48
|
+
openAIResponsesStreamCompletionMode?: OpenAIResponsesStreamCompletionMode;
|
|
49
|
+
anthropicApiRoot?: boolean;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
interface ModelMetadata {
|
|
49
53
|
openAIServiceTier?: OpenAIServiceTier;
|
|
54
|
+
anthropicApiRoot?: boolean;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
export interface MetadataDocument {
|
|
53
|
-
version: 4;
|
|
58
|
+
version: 4 | 5;
|
|
54
59
|
/** 明确由插件创建或接管的 Provider ID。 */
|
|
55
60
|
managedProviderIds: string[];
|
|
56
61
|
providers: Record<string, ProviderMetadata>;
|
|
@@ -72,7 +77,7 @@ export interface MetadataStateSnapshot extends ParsedMetadataStateFile {
|
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
export function createEmptyMetadata(): MetadataDocument {
|
|
75
|
-
return { version:
|
|
80
|
+
return { version: 5, managedProviderIds: [], providers: {}, models: {}, requestHeaderProfiles: {}, clientHeaderCaptures: {} };
|
|
76
81
|
}
|
|
77
82
|
function fail(path: string, message: string): never {
|
|
78
83
|
throw new Error(t("state.json {path}: {message}", { path, message }));
|
|
@@ -155,6 +160,19 @@ function readOptionalOpenAIServiceTier(record: Record<string, unknown>, key: str
|
|
|
155
160
|
return value as OpenAIServiceTier;
|
|
156
161
|
}
|
|
157
162
|
|
|
163
|
+
function readOptionalOpenAIResponsesStreamCompletionMode(
|
|
164
|
+
record: Record<string, unknown>,
|
|
165
|
+
key: string,
|
|
166
|
+
path: string,
|
|
167
|
+
): OpenAIResponsesStreamCompletionMode | undefined {
|
|
168
|
+
const value = readOptionalString(record, key, path);
|
|
169
|
+
if (value === undefined) return undefined;
|
|
170
|
+
if (value !== "standard" && value !== "terminal-event") {
|
|
171
|
+
fail(`${path}.${key}`, t("未知 Responses 流结束模式:{value}", { value }));
|
|
172
|
+
}
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
|
|
158
176
|
function readInputKinds(record: Record<string, unknown>, key: string, path: string): ModelInputKind[] {
|
|
159
177
|
const value = record[key];
|
|
160
178
|
if (!Array.isArray(value) || value.length === 0) fail(`${path}.${key}`, t("必须是非空数组"));
|
|
@@ -224,6 +242,8 @@ function readStoredModel(raw: unknown, path: string): StoredModel {
|
|
|
224
242
|
function readProviderMetadata(raw: unknown, path: string): ProviderMetadata {
|
|
225
243
|
if (!isObjectRecord(raw)) fail(path, t("必须是对象"));
|
|
226
244
|
const metadata: ProviderMetadata = {};
|
|
245
|
+
const anthropicApiRoot = readOptionalBoolean(raw, "anthropicApiRoot", path);
|
|
246
|
+
if (anthropicApiRoot) metadata.anthropicApiRoot = true;
|
|
227
247
|
const clientHeaderProfile = readOptionalClientHeaderProfile(raw, "clientHeaderProfile", path);
|
|
228
248
|
if (clientHeaderProfile) metadata.clientHeaderProfile = clientHeaderProfile;
|
|
229
249
|
const requestHeaderProfileId = readOptionalString(raw, "requestHeaderProfileId", path);
|
|
@@ -234,12 +254,16 @@ function readProviderMetadata(raw: unknown, path: string): ProviderMetadata {
|
|
|
234
254
|
if (httpProxyEnabled !== undefined) metadata.httpProxyEnabled = httpProxyEnabled;
|
|
235
255
|
const httpProxyUrl = readOptionalString(raw, "httpProxyUrl", path);
|
|
236
256
|
if (httpProxyUrl !== undefined) metadata.httpProxyUrl = httpProxyUrl;
|
|
257
|
+
const streamCompletionMode = readOptionalOpenAIResponsesStreamCompletionMode(raw, "openAIResponsesStreamCompletionMode", path);
|
|
258
|
+
if (streamCompletionMode !== undefined) metadata.openAIResponsesStreamCompletionMode = streamCompletionMode;
|
|
237
259
|
return metadata;
|
|
238
260
|
}
|
|
239
261
|
|
|
240
262
|
function readModelMetadata(raw: unknown, path: string): ModelMetadata {
|
|
241
263
|
if (!isObjectRecord(raw)) fail(path, t("必须是对象"));
|
|
242
264
|
const metadata: ModelMetadata = {};
|
|
265
|
+
const anthropicApiRoot = readOptionalBoolean(raw, "anthropicApiRoot", path);
|
|
266
|
+
if (anthropicApiRoot) metadata.anthropicApiRoot = true;
|
|
243
267
|
const openAIServiceTier = readOptionalOpenAIServiceTier(raw, "openAIServiceTier", path);
|
|
244
268
|
if (openAIServiceTier) metadata.openAIServiceTier = openAIServiceTier;
|
|
245
269
|
return metadata;
|
|
@@ -301,6 +325,8 @@ function readStoredProvider(raw: unknown, path: string, managed: boolean): Store
|
|
|
301
325
|
if (httpProxyEnabled !== undefined) provider.httpProxyEnabled = httpProxyEnabled;
|
|
302
326
|
const httpProxyUrl = readOptionalString(raw, "httpProxyUrl", path);
|
|
303
327
|
if (httpProxyUrl !== undefined) provider.httpProxyUrl = httpProxyUrl;
|
|
328
|
+
const streamCompletionMode = readOptionalOpenAIResponsesStreamCompletionMode(raw, "openAIResponsesStreamCompletionMode", path);
|
|
329
|
+
if (streamCompletionMode !== undefined) provider.openAIResponsesStreamCompletionMode = streamCompletionMode;
|
|
304
330
|
return provider;
|
|
305
331
|
}
|
|
306
332
|
|
|
@@ -361,6 +387,7 @@ function getFullModelId(providerId: string, modelId: string): string {
|
|
|
361
387
|
|
|
362
388
|
function extractProviderMetadata(provider: StoredProvider): ProviderMetadata {
|
|
363
389
|
const metadata: ProviderMetadata = {};
|
|
390
|
+
if (toNativeBaseUrl(provider.api, provider.baseUrl).anthropicApiRoot) metadata.anthropicApiRoot = true;
|
|
364
391
|
if (provider.clientHeaderProfile !== "recommended") metadata.clientHeaderProfile = provider.clientHeaderProfile;
|
|
365
392
|
if (provider.clientHeaderProfile === "custom" && provider.requestHeaderProfileId) {
|
|
366
393
|
metadata.clientHeaderProfile = "custom";
|
|
@@ -373,24 +400,29 @@ function extractProviderMetadata(provider: StoredProvider): ProviderMetadata {
|
|
|
373
400
|
if (provider.httpProxyEnabled) metadata.httpProxyEnabled = true;
|
|
374
401
|
const httpProxyUrl = provider.httpProxyUrl?.trim();
|
|
375
402
|
if (httpProxyUrl) metadata.httpProxyUrl = httpProxyUrl;
|
|
403
|
+
if (provider.openAIResponsesStreamCompletionMode === "terminal-event") {
|
|
404
|
+
metadata.openAIResponsesStreamCompletionMode = "terminal-event";
|
|
405
|
+
}
|
|
376
406
|
return metadata;
|
|
377
407
|
}
|
|
378
408
|
|
|
379
|
-
function extractModelMetadata(model: StoredModel): ModelMetadata {
|
|
409
|
+
function extractModelMetadata(model: StoredModel, provider: StoredProvider): ModelMetadata {
|
|
380
410
|
const metadata: ModelMetadata = {};
|
|
411
|
+
if (toNativeBaseUrl(model.api ?? provider.api, model.baseUrl ?? provider.baseUrl).anthropicApiRoot) metadata.anthropicApiRoot = true;
|
|
381
412
|
if (model.openAIServiceTier) metadata.openAIServiceTier = model.openAIServiceTier;
|
|
382
413
|
return metadata;
|
|
383
414
|
}
|
|
384
415
|
|
|
385
416
|
function extractMetadataFromLegacyState(legacy: StateDocument): MetadataDocument {
|
|
386
417
|
const metadata = createEmptyMetadata();
|
|
418
|
+
metadata.version = 4;
|
|
387
419
|
metadata.managedProviderIds = Object.keys(legacy.providers);
|
|
388
420
|
metadata.requestHeaderProfiles = cloneJson(legacy.requestHeaderProfiles);
|
|
389
421
|
metadata.clientHeaderCaptures = cloneJson(legacy.clientHeaderCaptures);
|
|
390
422
|
for (const [providerId, provider] of Object.entries(legacy.providers)) {
|
|
391
423
|
metadata.providers[providerId] = extractProviderMetadata(provider);
|
|
392
424
|
for (const model of provider.models) {
|
|
393
|
-
const modelMetadata = extractModelMetadata(model);
|
|
425
|
+
const modelMetadata = extractModelMetadata(model, provider);
|
|
394
426
|
if (Object.keys(modelMetadata).length > 0) metadata.models[getFullModelId(providerId, model.id)] = modelMetadata;
|
|
395
427
|
}
|
|
396
428
|
}
|
|
@@ -408,6 +440,9 @@ function parseLegacyState(parsed: Record<string, unknown>): ParsedMetadataStateF
|
|
|
408
440
|
}
|
|
409
441
|
const common = readCommonMetadataFields(parsed, createEmptyMetadata());
|
|
410
442
|
const legacy = { version: 2, providers, managedProviderIds: Object.keys(providers), requestHeaderProfiles: common.requestHeaderProfiles, clientHeaderCaptures: common.clientHeaderCaptures } satisfies StateDocument;
|
|
443
|
+
for (const provider of Object.values(providers)) {
|
|
444
|
+
provider.baseUrl = fromNativeBaseUrl(provider.api, provider.baseUrl, false, true);
|
|
445
|
+
}
|
|
411
446
|
return {
|
|
412
447
|
metadata: extractMetadataFromLegacyState(legacy),
|
|
413
448
|
legacyProviders: providers,
|
|
@@ -417,6 +452,7 @@ function parseLegacyState(parsed: Record<string, unknown>): ParsedMetadataStateF
|
|
|
417
452
|
|
|
418
453
|
function parseMetadataState(parsed: Record<string, unknown>): ParsedMetadataStateFile {
|
|
419
454
|
const metadata = readCommonMetadataFields(parsed, createEmptyMetadata());
|
|
455
|
+
metadata.version = parsed.version === 5 ? 5 : 4;
|
|
420
456
|
const rawProviders = parsed.providers;
|
|
421
457
|
if (rawProviders !== undefined) {
|
|
422
458
|
if (!isObjectRecord(rawProviders)) fail(".providers", t("必须是对象"));
|
|
@@ -443,14 +479,14 @@ function parseMetadataState(parsed: Record<string, unknown>): ParsedMetadataStat
|
|
|
443
479
|
return {
|
|
444
480
|
metadata,
|
|
445
481
|
legacyProviders: {},
|
|
446
|
-
requirePluginManagedProviderMarker: parsed.version === 4,
|
|
482
|
+
requirePluginManagedProviderMarker: parsed.version === 4 || parsed.version === 5,
|
|
447
483
|
};
|
|
448
484
|
}
|
|
449
485
|
|
|
450
486
|
function parseStateFile(source: string): ParsedMetadataStateFile {
|
|
451
487
|
const parsed = JSON.parse(stripJsonNoise(source));
|
|
452
488
|
if (!isObjectRecord(parsed)) fail("", t("根节点必须是对象"));
|
|
453
|
-
if (parsed.version === 4 || parsed.version === 3 || parsed.version === 2) return parseMetadataState(parsed);
|
|
489
|
+
if (parsed.version === 5 || parsed.version === 4 || parsed.version === 3 || parsed.version === 2) return parseMetadataState(parsed);
|
|
454
490
|
if (parsed.version === undefined || parsed.version === 1) return parseLegacyState(parsed);
|
|
455
491
|
fail(".version", t("不支持的版本:{version}", { version: String(parsed.version) }));
|
|
456
492
|
}
|
|
@@ -475,7 +511,7 @@ function extractMetadata(state: StateDocument): MetadataDocument {
|
|
|
475
511
|
const providerMetadata = extractProviderMetadata(provider);
|
|
476
512
|
if (Object.keys(providerMetadata).length > 0) metadata.providers[providerId] = providerMetadata;
|
|
477
513
|
for (const model of provider.models) {
|
|
478
|
-
const modelMetadata = extractModelMetadata(model);
|
|
514
|
+
const modelMetadata = extractModelMetadata(model, provider);
|
|
479
515
|
if (Object.keys(modelMetadata).length > 0) metadata.models[getFullModelId(providerId, model.id)] = modelMetadata;
|
|
480
516
|
}
|
|
481
517
|
}
|
package/state-store.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
stripManagedClientHeaders,
|
|
23
23
|
} from "./presets/client-headers.ts";
|
|
24
24
|
import { normalizeThinkingLevelMap } from "./presets/thinking.ts";
|
|
25
|
+
import { fromNativeBaseUrl, resolveRuntimeBaseUrl, toNativeBaseUrl } from "./runtime-base-url.ts";
|
|
25
26
|
import {
|
|
26
27
|
CONFIGURATION_TRANSACTION_PATH,
|
|
27
28
|
getStatePath as getMetadataStatePath,
|
|
@@ -106,6 +107,7 @@ function buildStoredModelFromModelsJson(
|
|
|
106
107
|
providerId: string,
|
|
107
108
|
providerApi: ApiKind,
|
|
108
109
|
providerBaseUrl: string,
|
|
110
|
+
providerNativeBaseUrl: string,
|
|
109
111
|
providerCompat: CompatSettings | undefined,
|
|
110
112
|
managed: boolean,
|
|
111
113
|
clientHeaderProfile: StoredProvider["clientHeaderProfile"],
|
|
@@ -139,14 +141,25 @@ function buildStoredModelFromModelsJson(
|
|
|
139
141
|
cost: readModelCost(model),
|
|
140
142
|
};
|
|
141
143
|
if (explicitApi && explicitApi !== providerApi) stored.api = explicitApi;
|
|
142
|
-
|
|
144
|
+
const modelMetadata = metadata.models[getFullModelId(providerId, model.id)];
|
|
145
|
+
let modelBaseUrl = model.baseUrl ?? providerBaseUrl;
|
|
146
|
+
if (managed && model.baseUrl) {
|
|
147
|
+
modelBaseUrl = fromNativeBaseUrl(effectiveApi, model.baseUrl, modelMetadata?.anthropicApiRoot, metadata.version < 5);
|
|
148
|
+
} else if (managed && effectiveApi !== providerApi) {
|
|
149
|
+
const inheritedBaseUrl = metadata.version < 5
|
|
150
|
+
? (providerApi === "anthropic-messages"
|
|
151
|
+
? toNativeBaseUrl(providerApi, providerBaseUrl).baseUrl
|
|
152
|
+
: resolveRuntimeBaseUrl(providerApi, providerNativeBaseUrl))
|
|
153
|
+
: providerNativeBaseUrl;
|
|
154
|
+
modelBaseUrl = fromNativeBaseUrl(effectiveApi, inheritedBaseUrl, modelMetadata?.anthropicApiRoot);
|
|
155
|
+
}
|
|
156
|
+
if (modelBaseUrl !== providerBaseUrl) stored.baseUrl = modelBaseUrl;
|
|
143
157
|
if (nativeHeaders) stored.headers = nativeHeaders;
|
|
144
158
|
if (model.name) stored.name = model.name;
|
|
145
159
|
const storedThinkingLevelMap = model.thinkingLevelMap ? cloneJson(model.thinkingLevelMap) as ThinkingLevelMap : undefined;
|
|
146
160
|
const thinkingLevelMap = normalizeThinkingLevelMap(effectiveApi, stored.reasoning, storedThinkingLevelMap);
|
|
147
161
|
if (thinkingLevelMap) stored.thinkingLevelMap = thinkingLevelMap;
|
|
148
162
|
if (modelCompat) stored.compat = modelCompat;
|
|
149
|
-
const modelMetadata = metadata.models[getFullModelId(providerId, model.id)];
|
|
150
163
|
if (effectiveApi === "openai-responses" && modelMetadata?.openAIServiceTier) {
|
|
151
164
|
stored.openAIServiceTier = modelMetadata.openAIServiceTier;
|
|
152
165
|
}
|
|
@@ -165,12 +178,15 @@ async function buildStoredProviderFromModelsJson(
|
|
|
165
178
|
const firstModel = rawModels[0];
|
|
166
179
|
const builtInDefaults = await getBuiltinProviderDefaults(providerId);
|
|
167
180
|
const api = asApiKind(entry.api) ?? asApiKind(firstModel?.api) ?? asApiKind(builtInDefaults?.api);
|
|
168
|
-
const
|
|
169
|
-
if (!api || !
|
|
181
|
+
const nativeBaseUrl = entry.baseUrl ?? firstModel?.baseUrl ?? builtInDefaults?.baseUrl;
|
|
182
|
+
if (!api || !nativeBaseUrl) return undefined;
|
|
170
183
|
|
|
171
184
|
const providerMetadata = metadata.providers[providerId];
|
|
172
185
|
const managed = metadata.managedProviderIds.includes(providerId)
|
|
173
186
|
&& (!requirePluginManagedProviderMarker || hasPluginManagedProviderMarker(entry));
|
|
187
|
+
const baseUrl = managed
|
|
188
|
+
? fromNativeBaseUrl(api, nativeBaseUrl, providerMetadata?.anthropicApiRoot, metadata.version < 5)
|
|
189
|
+
: nativeBaseUrl;
|
|
174
190
|
const clientHeaderProfile = managed ? providerMetadata?.clientHeaderProfile ?? "recommended" : "disabled";
|
|
175
191
|
const customClientHeaders = managed && clientHeaderProfile === "custom"
|
|
176
192
|
? resolveProviderCustomHeaders(providerMetadata, metadata)
|
|
@@ -181,6 +197,7 @@ async function buildStoredProviderFromModelsJson(
|
|
|
181
197
|
providerId,
|
|
182
198
|
api,
|
|
183
199
|
baseUrl,
|
|
200
|
+
nativeBaseUrl,
|
|
184
201
|
providerCompat,
|
|
185
202
|
managed,
|
|
186
203
|
clientHeaderProfile,
|
|
@@ -212,6 +229,9 @@ async function buildStoredProviderFromModelsJson(
|
|
|
212
229
|
}
|
|
213
230
|
if (managed && providerMetadata?.httpProxyEnabled !== undefined) provider.httpProxyEnabled = providerMetadata.httpProxyEnabled;
|
|
214
231
|
if (managed && providerMetadata?.httpProxyUrl !== undefined) provider.httpProxyUrl = providerMetadata.httpProxyUrl;
|
|
232
|
+
if (managed && providerMetadata?.openAIResponsesStreamCompletionMode !== undefined) {
|
|
233
|
+
provider.openAIResponsesStreamCompletionMode = providerMetadata.openAIResponsesStreamCompletionMode;
|
|
234
|
+
}
|
|
215
235
|
return provider;
|
|
216
236
|
}
|
|
217
237
|
|
package/tui/editor-provider.ts
CHANGED
|
@@ -9,7 +9,11 @@ import { t } from "../i18n.ts";
|
|
|
9
9
|
import { switchProviderDraftApiPreset } from "../presets/providers.ts";
|
|
10
10
|
import { redactUrlForDisplay } from "../sensitive-redaction.ts";
|
|
11
11
|
import { resolveRuntimeBaseUrl } from "../runtime-base-url.ts";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_PROVIDER_HTTP_PROXY_URL,
|
|
14
|
+
type OpenAIChatCompatibilityMode,
|
|
15
|
+
type OpenAIResponsesStreamCompletionMode,
|
|
16
|
+
} from "../types.ts";
|
|
13
17
|
import { showOptionPicker, showPersistentFormMenu, padLabel, type HorizontalDirection, type MenuCursor } from "./persistent-menu.ts";
|
|
14
18
|
import {
|
|
15
19
|
describeProfile,
|
|
@@ -29,6 +33,7 @@ interface FieldRow {
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
const OPENAI_CHAT_COMPATIBILITY_MODE_ORDER: readonly OpenAIChatCompatibilityMode[] = ["standard", "compatible"];
|
|
36
|
+
const OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER: readonly OpenAIResponsesStreamCompletionMode[] = ["standard", "terminal-event"];
|
|
32
37
|
|
|
33
38
|
function getOpenAIChatCompatibilityMode(draft: ProviderDraft): OpenAIChatCompatibilityMode {
|
|
34
39
|
return draft.openAIChatCompatibilityMode ?? "standard";
|
|
@@ -53,6 +58,29 @@ function cycleOpenAIChatCompatibilityMode(
|
|
|
53
58
|
return OPENAI_CHAT_COMPATIBILITY_MODE_ORDER[(index + offset + OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.length) % OPENAI_CHAT_COMPATIBILITY_MODE_ORDER.length]!;
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
function getOpenAIResponsesStreamCompletionMode(draft: ProviderDraft): OpenAIResponsesStreamCompletionMode {
|
|
62
|
+
return draft.openAIResponsesStreamCompletionMode ?? "standard";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function describeOpenAIResponsesStreamCompletionMode(mode: OpenAIResponsesStreamCompletionMode): string {
|
|
66
|
+
if (mode === "terminal-event") return t("兼容 · 终态即结束");
|
|
67
|
+
return t("标准 · 等待连接关闭");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getOpenAIResponsesStreamCompletionModeHint(mode: OpenAIResponsesStreamCompletionMode): string {
|
|
71
|
+
if (mode === "terminal-event") return t("兼容模式:正式终态事件已转交后主动结束,不等待上游关闭连接。");
|
|
72
|
+
return t("标准模式:等待上游正常结束流。若回复完成后长期卡住,可启用兼容模式。");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function cycleOpenAIResponsesStreamCompletionMode(
|
|
76
|
+
mode: OpenAIResponsesStreamCompletionMode,
|
|
77
|
+
direction: HorizontalDirection,
|
|
78
|
+
): OpenAIResponsesStreamCompletionMode {
|
|
79
|
+
const index = OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER.indexOf(mode);
|
|
80
|
+
const offset = direction === "right" ? 1 : -1;
|
|
81
|
+
return OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER[(index + offset + OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER.length) % OPENAI_RESPONSES_STREAM_COMPLETION_MODE_ORDER.length]!;
|
|
82
|
+
}
|
|
83
|
+
|
|
56
84
|
function buildRows(
|
|
57
85
|
draft: ProviderDraft,
|
|
58
86
|
requestHeaderProfiles: Record<string, StoredRequestHeaderProfile>,
|
|
@@ -77,6 +105,14 @@ function buildRows(
|
|
|
77
105
|
adjustable: true,
|
|
78
106
|
});
|
|
79
107
|
}
|
|
108
|
+
if (draft.api === "openai-responses") {
|
|
109
|
+
rows.push({
|
|
110
|
+
id: "openAIResponsesStreamCompletionMode",
|
|
111
|
+
label: t("流结束兼容"),
|
|
112
|
+
value: describeOpenAIResponsesStreamCompletionMode(getOpenAIResponsesStreamCompletionMode(draft)),
|
|
113
|
+
adjustable: true,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
80
116
|
rows.push(
|
|
81
117
|
{ id: "httpProxyEnabled", label: t("本机代理"), value: draft.httpProxyEnabled ? t("开启") : t("关闭"), adjustable: true },
|
|
82
118
|
{ id: "httpProxyUrl", label: t("代理地址"), value: draft.httpProxyEnabled ? redactUrlForDisplay(draft.httpProxyUrl || DEFAULT_PROVIDER_HTTP_PROXY_URL) : t("关闭时不使用") },
|
|
@@ -95,6 +131,10 @@ function applyHorizontalToggle(draft: ProviderDraft, fieldId: string, direction:
|
|
|
95
131
|
draft.openAIChatCompatibilityMode = cycleOpenAIChatCompatibilityMode(getOpenAIChatCompatibilityMode(draft), direction);
|
|
96
132
|
return true;
|
|
97
133
|
}
|
|
134
|
+
if (fieldId === "openAIResponsesStreamCompletionMode") {
|
|
135
|
+
draft.openAIResponsesStreamCompletionMode = cycleOpenAIResponsesStreamCompletionMode(getOpenAIResponsesStreamCompletionMode(draft), direction);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
98
138
|
if (fieldId !== "httpProxyEnabled") return false;
|
|
99
139
|
draft.httpProxyEnabled = !draft.httpProxyEnabled;
|
|
100
140
|
if (draft.httpProxyEnabled && !draft.httpProxyUrl.trim()) draft.httpProxyUrl = DEFAULT_PROVIDER_HTTP_PROXY_URL;
|
|
@@ -153,6 +193,19 @@ async function editField(
|
|
|
153
193
|
if (choice) draft.openAIChatCompatibilityMode = choice.id as OpenAIChatCompatibilityMode;
|
|
154
194
|
return;
|
|
155
195
|
}
|
|
196
|
+
if (fieldId === "openAIResponsesStreamCompletionMode") {
|
|
197
|
+
const choice = await showOptionPicker(
|
|
198
|
+
ctx,
|
|
199
|
+
t("选择流结束兼容"),
|
|
200
|
+
[
|
|
201
|
+
{ id: "standard", label: t("标准 — 等待上游正常关闭连接") },
|
|
202
|
+
{ id: "terminal-event", label: t("兼容 — 收到正式终态事件后主动结束") },
|
|
203
|
+
],
|
|
204
|
+
getOpenAIResponsesStreamCompletionMode(draft),
|
|
205
|
+
);
|
|
206
|
+
if (choice) draft.openAIResponsesStreamCompletionMode = choice.id as OpenAIResponsesStreamCompletionMode;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
156
209
|
if (fieldId === "authHeader") {
|
|
157
210
|
const choice = await showOptionPicker(
|
|
158
211
|
ctx,
|
|
@@ -251,6 +304,9 @@ export async function editProvider(
|
|
|
251
304
|
if (draft.api === "openai-completions") {
|
|
252
305
|
summaryLines.push(getOpenAIChatCompatibilityModeHint(getOpenAIChatCompatibilityMode(draft)));
|
|
253
306
|
}
|
|
307
|
+
if (draft.api === "openai-responses") {
|
|
308
|
+
summaryLines.push(getOpenAIResponsesStreamCompletionModeHint(getOpenAIResponsesStreamCompletionMode(draft)));
|
|
309
|
+
}
|
|
254
310
|
return summaryLines;
|
|
255
311
|
};
|
|
256
312
|
const action = await showPersistentFormMenu(
|
package/tui/model-list-fetch.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { ModelRuntime, type ProviderConfig } from "@earendil-works/pi-coding-age
|
|
|
5
5
|
import { formatUnknownError } from "../common.ts";
|
|
6
6
|
import { t } from "../i18n.ts";
|
|
7
7
|
import { openTemporaryLocalProxyRoute, type TemporaryLocalProxyRoute } from "../local-proxy-service.ts";
|
|
8
|
-
import { getClientHeadersForProfile } from "../presets/client-headers.ts";
|
|
9
|
-
import { appendUrlPath, resolveRuntimeBaseUrl } from "../runtime-base-url.ts";
|
|
8
|
+
import { getClientHeadersForProfile, mergeModelRequestHeaders } from "../presets/client-headers.ts";
|
|
9
|
+
import { appendUrlPath, resolveRuntimeBaseUrl, validateRequestBaseUrl } from "../runtime-base-url.ts";
|
|
10
10
|
import { isSensitiveHeaderName, redactSensitiveText } from "../sensitive-redaction.ts";
|
|
11
11
|
import type { ApiKind, BuiltInClientHeaderProfileId, ClientHeaderProfileId, ModelListFetchOutcome, StoredClientHeaderCapture } from "../types.ts";
|
|
12
12
|
import { extractValidatedModelIds, readBoundedResponseText } from "./model-list-validation.ts";
|
|
@@ -31,37 +31,6 @@ const emptyCredentialStore = {
|
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
function hasRootPath(baseUrl: string): boolean {
|
|
35
|
-
try {
|
|
36
|
-
const pathname = new URL(baseUrl.trim()).pathname.replace(/\/+$/, "");
|
|
37
|
-
return pathname === "";
|
|
38
|
-
} catch {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function buildOpenAIUrl(baseUrl: string, api: Extract<ApiKind, "openai-completions" | "openai-responses">): string {
|
|
44
|
-
return appendUrlPath(resolveRuntimeBaseUrl(api, baseUrl), "models");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function buildAnthropicUrl(baseUrl: string): string {
|
|
48
|
-
return hasRootPath(baseUrl)
|
|
49
|
-
? appendUrlPath(baseUrl, "v1", "models")
|
|
50
|
-
: appendUrlPath(baseUrl, "models");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function buildOriginOpenAIUrl(baseUrl: string): string {
|
|
54
|
-
const parsed = new URL(baseUrl.trim());
|
|
55
|
-
parsed.pathname = "/v1/models";
|
|
56
|
-
parsed.hash = "";
|
|
57
|
-
return parsed.toString();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function buildGoogleUrl(baseUrl: string, apiKey: string): string {
|
|
61
|
-
const url = new URL(appendUrlPath(baseUrl, "models"));
|
|
62
|
-
url.searchParams.set("key", apiKey);
|
|
63
|
-
return url.toString();
|
|
64
|
-
}
|
|
65
34
|
|
|
66
35
|
function throwIfAborted(signal: AbortSignal): void {
|
|
67
36
|
if (!signal.aborted) return;
|
|
@@ -118,6 +87,7 @@ async function resolveFetchAuth(
|
|
|
118
87
|
credentials: emptyCredentialStore,
|
|
119
88
|
modelsPath: null,
|
|
120
89
|
allowModelNetwork: false,
|
|
90
|
+
refreshOnCreate: false,
|
|
121
91
|
}), signal);
|
|
122
92
|
runtime.registerProvider(TEMP_PROVIDER_ID, providerConfig);
|
|
123
93
|
const model = runtime.getModel(TEMP_PROVIDER_ID, TEMP_MODEL_ID);
|
|
@@ -172,7 +142,13 @@ async function requestModelIds(
|
|
|
172
142
|
: undefined;
|
|
173
143
|
const response = await fetch(temporaryProxyRoute?.url ?? url, { headers, signal });
|
|
174
144
|
const text = await readBoundedResponseText(response, signal);
|
|
175
|
-
if (!response.ok)
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
const reason = response.status === 401 || response.status === 403 ? t("认证失败,请检查 API key 和认证头")
|
|
147
|
+
: response.status === 404 ? t("模型列表接口不存在,可继续手动添加模型")
|
|
148
|
+
: response.status === 429 ? t("模型列表请求被限流,请稍后重试")
|
|
149
|
+
: response.status >= 500 ? t("模型列表上游服务异常") : t("模型列表请求失败");
|
|
150
|
+
throw new Error(`${reason} (HTTP ${response.status}): ${text.slice(0, 240)}`);
|
|
151
|
+
}
|
|
176
152
|
return extractValidatedModelIds(JSON.parse(text), api);
|
|
177
153
|
} finally {
|
|
178
154
|
temporaryProxyRoute?.close();
|
|
@@ -197,6 +173,8 @@ async function fetchModelIdsWithSignal(
|
|
|
197
173
|
signal: AbortSignal,
|
|
198
174
|
redactionSecrets: string[],
|
|
199
175
|
): Promise<ModelListFetchOutcome> {
|
|
176
|
+
throwIfAborted(signal);
|
|
177
|
+
validateRequestBaseUrl(params.baseUrl);
|
|
200
178
|
const profileHeaders = getClientHeadersForProfile(
|
|
201
179
|
params.clientHeaderProfile,
|
|
202
180
|
params.api,
|
|
@@ -205,47 +183,21 @@ async function fetchModelIdsWithSignal(
|
|
|
205
183
|
);
|
|
206
184
|
const auth = await resolveFetchAuth(params, profileHeaders, signal);
|
|
207
185
|
redactionSecrets.push(...auth.redactionSecrets);
|
|
208
|
-
const
|
|
186
|
+
const defaults: Record<string, string> = { accept: "application/json" };
|
|
187
|
+
if (params.api === "anthropic-messages") {
|
|
188
|
+
defaults["x-api-key"] = auth.apiKey;
|
|
189
|
+
defaults["anthropic-version"] = "2023-06-01";
|
|
190
|
+
} else if (params.api === "google-generative-ai") defaults["x-goog-api-key"] = auth.apiKey;
|
|
191
|
+
else defaults.authorization = `Bearer ${auth.apiKey}`;
|
|
192
|
+
const headers = mergeModelRequestHeaders(defaults, auth.headers)!;
|
|
209
193
|
const proxyConfig = params.httpProxyEnabled
|
|
210
194
|
? { providerId: params.providerId, proxyUrl: params.httpProxyUrl }
|
|
211
195
|
: undefined;
|
|
212
196
|
|
|
213
|
-
|
|
214
|
-
const modelIds = await requestModelIds(
|
|
215
|
-
buildGoogleUrl(resolveRuntimeBaseUrl(params.api, params.baseUrl), auth.apiKey),
|
|
216
|
-
headers,
|
|
217
|
-
params.api,
|
|
218
|
-
proxyConfig,
|
|
219
|
-
signal,
|
|
220
|
-
);
|
|
221
|
-
return { status: "loaded", modelIds };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (params.api === "anthropic-messages") {
|
|
225
|
-
const anthropicVersion = headers["anthropic-version"] ?? "2023-06-01";
|
|
226
|
-
const apiKeyHeaders = { ...headers, "x-api-key": auth.apiKey, "anthropic-version": anthropicVersion };
|
|
227
|
-
try {
|
|
228
|
-
const modelIds = await requestModelIds(buildAnthropicUrl(params.baseUrl), apiKeyHeaders, params.api, proxyConfig, signal);
|
|
229
|
-
return { status: "loaded", modelIds };
|
|
230
|
-
} catch {
|
|
231
|
-
throwIfAborted(signal);
|
|
232
|
-
}
|
|
233
|
-
const bearerHeaders: Record<string, string> = { ...headers, Authorization: `Bearer ${auth.apiKey}`, "anthropic-version": anthropicVersion };
|
|
234
|
-
delete bearerHeaders["x-api-key"];
|
|
235
|
-
try {
|
|
236
|
-
const modelIds = await requestModelIds(buildAnthropicUrl(params.baseUrl), bearerHeaders, params.api, proxyConfig, signal);
|
|
237
|
-
return { status: "loaded", modelIds };
|
|
238
|
-
} catch {
|
|
239
|
-
throwIfAborted(signal);
|
|
240
|
-
}
|
|
241
|
-
const fallbackHeaders = { ...headers, Authorization: `Bearer ${auth.apiKey}` };
|
|
242
|
-
const modelIds = await requestModelIds(buildOriginOpenAIUrl(params.baseUrl), fallbackHeaders, params.api, proxyConfig, signal);
|
|
243
|
-
return { status: "loaded", modelIds };
|
|
244
|
-
}
|
|
245
|
-
|
|
197
|
+
// [喵喵喵]: 列表与聊天共享 API 根地址;错误不触发跨路径或跨认证形式的探测。
|
|
246
198
|
const modelIds = await requestModelIds(
|
|
247
|
-
|
|
248
|
-
|
|
199
|
+
appendUrlPath(resolveRuntimeBaseUrl(params.api, params.baseUrl), "models"),
|
|
200
|
+
headers,
|
|
249
201
|
params.api,
|
|
250
202
|
proxyConfig,
|
|
251
203
|
signal,
|
package/types.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type ThinkingLevelMap = Partial<Record<ThinkingLevel, string | null>>;
|
|
|
13
13
|
export type ReasoningMode = "enabled" | "disabled";
|
|
14
14
|
export type AnthropicThinkingProtocol = "adaptive" | "legacy";
|
|
15
15
|
export type OpenAIChatCompatibilityMode = "standard" | "compatible";
|
|
16
|
+
export type OpenAIResponsesStreamCompletionMode = "standard" | "terminal-event";
|
|
16
17
|
export type BuiltInClientHeaderProfileId = "claude-code" | "codex-cli";
|
|
17
18
|
export type ClientHeaderProfileId = "recommended" | "disabled" | BuiltInClientHeaderProfileId | "custom";
|
|
18
19
|
export type CompatSettings = Record<string, unknown>;
|
|
@@ -88,6 +89,8 @@ export interface StoredProvider {
|
|
|
88
89
|
customClientHeaders?: Record<string, string>;
|
|
89
90
|
httpProxyEnabled?: boolean;
|
|
90
91
|
httpProxyUrl?: string;
|
|
92
|
+
/** Responses 终态事件已完整转交后,是否主动结束本地 SSE 流。 */
|
|
93
|
+
openAIResponsesStreamCompletionMode?: OpenAIResponsesStreamCompletionMode;
|
|
91
94
|
models: StoredModel[];
|
|
92
95
|
}
|
|
93
96
|
|
|
@@ -108,6 +111,8 @@ export interface ProviderDraft {
|
|
|
108
111
|
api: ApiKind;
|
|
109
112
|
/** Chat Completions 系统提示词兼容模式;standard 保持 Pi 默认判断。 */
|
|
110
113
|
openAIChatCompatibilityMode?: OpenAIChatCompatibilityMode;
|
|
114
|
+
/** Responses 流结束模式;terminal-event 不等待上游关闭连接。 */
|
|
115
|
+
openAIResponsesStreamCompletionMode?: OpenAIResponsesStreamCompletionMode;
|
|
111
116
|
baseUrl: string;
|
|
112
117
|
apiKey: string;
|
|
113
118
|
authHeader: boolean;
|