pi-cliproxyapi-provider 0.15.58 → 0.16.0
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.md +30 -7
- package/data/models-dev-fallback.json +1 -1
- package/extensions/index.ts +10 -9
- package/package.json +7 -7
- package/src/commands.ts +1 -1
- package/src/gateway-telemetry.ts +3 -1
- package/src/matching.ts +42 -8
- package/src/model-api.ts +60 -5
- package/src/model-capabilities.ts +90 -8
- package/src/model-ui.ts +5 -5
- package/src/provider.ts +9 -13
- package/src/registration.ts +6 -8
- package/src/types.ts +10 -4
package/extensions/index.ts
CHANGED
|
@@ -18,28 +18,29 @@ const bundledModelsDevPath = join(packageRoot, "data", "models-dev-fallback.json
|
|
|
18
18
|
|
|
19
19
|
export default async function (pi: ExtensionAPI) {
|
|
20
20
|
let config = DEFAULT_CONFIG;
|
|
21
|
+
let runtime: ProviderRuntime | undefined;
|
|
22
|
+
let catalog: ProviderCatalog | undefined;
|
|
21
23
|
try {
|
|
22
24
|
const cwd = process.cwd();
|
|
23
25
|
config = loadConfig(cwd);
|
|
24
26
|
const settings = loadProviderSettings(cwd);
|
|
25
|
-
const
|
|
27
|
+
const nextCatalog = new ProviderCatalog({
|
|
26
28
|
config,
|
|
27
29
|
gpt56ContextWindow: settings.gpt56ContextWindow,
|
|
28
30
|
bundledModelsDevPath,
|
|
29
31
|
getApiKey: () => getDiscoveryApiKey(config.providerName),
|
|
30
32
|
});
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
await runtime.start();
|
|
33
|
+
const nextRuntime = new ProviderRuntime({ pi, config, catalog: nextCatalog });
|
|
34
|
+
await nextRuntime.start();
|
|
35
|
+
catalog = nextCatalog;
|
|
36
|
+
runtime = nextRuntime;
|
|
36
37
|
} catch (error) {
|
|
37
|
-
registerCodexCompatiblePayloadAdapter(pi, config.providerName);
|
|
38
|
-
registerCliproxyapiCommand(pi);
|
|
39
|
-
registerGatewayTelemetry(pi as never);
|
|
40
38
|
pi.registerProvider(config.providerName, buildProviderRegistration(config, buildUnavailableProviderModels()).config);
|
|
41
39
|
console.warn(`[pi-cliproxyapi-provider] registered placeholder provider after startup failure: ${error instanceof Error ? error.message : String(error)}`);
|
|
42
40
|
}
|
|
41
|
+
registerCodexCompatiblePayloadAdapter(pi, config.providerName);
|
|
42
|
+
registerCliproxyapiCommand(pi, runtime, catalog);
|
|
43
|
+
registerGatewayTelemetry(pi as never);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cliproxyapi-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Pi provider package for CLIProxyAPI with automatic model discovery and models.dev enrichment.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"update:models-dev": "node scripts/update-models-dev-fallback.mjs"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@earendil-works/pi-ai": ">=0.
|
|
45
|
-
"@earendil-works/pi-coding-agent": ">=0.
|
|
46
|
-
"@earendil-works/pi-tui": ">=0.
|
|
44
|
+
"@earendil-works/pi-ai": ">=0.87.0",
|
|
45
|
+
"@earendil-works/pi-coding-agent": ">=0.87.0",
|
|
46
|
+
"@earendil-works/pi-tui": ">=0.87.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@earendil-works/pi-coding-agent": {
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@earendil-works/pi-ai": "
|
|
61
|
-
"@earendil-works/pi-coding-agent": "
|
|
62
|
-
"@earendil-works/pi-tui": "
|
|
60
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
61
|
+
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
62
|
+
"@earendil-works/pi-tui": "1.5.0",
|
|
63
63
|
"typescript": "^5.9.3"
|
|
64
64
|
}
|
|
65
65
|
}
|
package/src/commands.ts
CHANGED
|
@@ -103,7 +103,7 @@ function statusText(config: ReturnType<typeof loadConfig>, snapshot: CatalogSnap
|
|
|
103
103
|
`Image-capable models: ${capabilityCount(snapshot, "image")}`,
|
|
104
104
|
`CPA snapshot: ${age(snapshot.cpaUpdatedAt)}`,
|
|
105
105
|
`models.dev metadata: ${snapshot.metadataSource}${snapshot.metadataUpdatedAt ? `, ${age(snapshot.metadataUpdatedAt)}` : ""}`,
|
|
106
|
-
`GPT
|
|
106
|
+
`Codex GPT context window: ${snapshot.gpt56ContextWindow === "full" ? "full models.dev limit" : "canonical family defaults"}`,
|
|
107
107
|
].join("\n");
|
|
108
108
|
}
|
|
109
109
|
|
package/src/gateway-telemetry.ts
CHANGED
|
@@ -53,7 +53,9 @@ export function registerGatewayTelemetry(pi: {
|
|
|
53
53
|
install();
|
|
54
54
|
}) as (...args: never[]) => unknown);
|
|
55
55
|
pi.on("agent_settled", ((_event: unknown, ctx: { ui?: { notify?: (message: string, type?: string) => void } }) => {
|
|
56
|
-
|
|
56
|
+
if (captured !== undefined) {
|
|
57
|
+
ctx.ui?.notify?.(`TPS ${formatGatewayTokensPerSecond(captured)} tok/s`, "info");
|
|
58
|
+
}
|
|
57
59
|
captured = undefined;
|
|
58
60
|
}) as (...args: never[]) => unknown);
|
|
59
61
|
pi.on("session_shutdown", (() => {
|
package/src/matching.ts
CHANGED
|
@@ -37,6 +37,44 @@ function oneMatch(candidates: string[]): string | undefined {
|
|
|
37
37
|
return unique.length === 1 ? unique[0] : undefined;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
interface CatalogIndex {
|
|
41
|
+
idToKeys: Map<string, string[]>;
|
|
42
|
+
nameToKeys: Map<string, string[]>;
|
|
43
|
+
normNameToKeys: Map<string, string[]>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const catalogIndexes = new WeakMap<object, CatalogIndex>();
|
|
47
|
+
|
|
48
|
+
function appendKey(index: Map<string, string[]>, value: string, key: string): void {
|
|
49
|
+
const keys = index.get(value);
|
|
50
|
+
if (keys) keys.push(key);
|
|
51
|
+
else index.set(value, [key]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildCatalogIndex(catalog: ModelsDevCatalog): CatalogIndex {
|
|
55
|
+
const index: CatalogIndex = {
|
|
56
|
+
idToKeys: new Map(),
|
|
57
|
+
nameToKeys: new Map(),
|
|
58
|
+
normNameToKeys: new Map(),
|
|
59
|
+
};
|
|
60
|
+
for (const key of Object.keys(catalog)) {
|
|
61
|
+
const metadata = catalog[key];
|
|
62
|
+
appendKey(index.idToKeys, metadata.id, key);
|
|
63
|
+
const name = metadataModelName(key, metadata);
|
|
64
|
+
appendKey(index.nameToKeys, name, key);
|
|
65
|
+
appendKey(index.normNameToKeys, normalizeModelName(name), key);
|
|
66
|
+
}
|
|
67
|
+
return index;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getCatalogIndex(catalog: ModelsDevCatalog): CatalogIndex {
|
|
71
|
+
const cached = catalogIndexes.get(catalog);
|
|
72
|
+
if (cached) return cached;
|
|
73
|
+
const index = buildCatalogIndex(catalog);
|
|
74
|
+
catalogIndexes.set(catalog, index);
|
|
75
|
+
return index;
|
|
76
|
+
}
|
|
77
|
+
|
|
40
78
|
function identifierTokens(value: string): string[] {
|
|
41
79
|
return value.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
42
80
|
}
|
|
@@ -97,20 +135,16 @@ export function findMetadataMatch(
|
|
|
97
135
|
return { metadataId: cpaModel.id, metadata: catalog[cpaModel.id], method: "exact" };
|
|
98
136
|
}
|
|
99
137
|
|
|
100
|
-
const
|
|
101
|
-
const exactMetadataCandidates =
|
|
138
|
+
const index = getCatalogIndex(catalog);
|
|
139
|
+
const exactMetadataCandidates = index.idToKeys.get(cpaModel.id) ?? [];
|
|
102
140
|
const exactMetadataKey = oneMatch(exactMetadataCandidates);
|
|
103
141
|
if (exactMetadataKey) {
|
|
104
142
|
return { metadataId: exactMetadataKey, metadata: catalog[exactMetadataKey], method: "exact" };
|
|
105
143
|
}
|
|
106
144
|
|
|
107
|
-
const suffixCandidates =
|
|
108
|
-
metadataModelName(key, catalog[key]) === cpaModel.id
|
|
109
|
-
);
|
|
145
|
+
const suffixCandidates = index.nameToKeys.get(cpaModel.id) ?? [];
|
|
110
146
|
const normalizedId = normalizeModelName(cpaModel.id);
|
|
111
|
-
const normalizedSuffixCandidates =
|
|
112
|
-
(key) => normalizeModelName(metadataModelName(key, catalog[key])) === normalizedId,
|
|
113
|
-
);
|
|
147
|
+
const normalizedSuffixCandidates = index.normNameToKeys.get(normalizedId) ?? [];
|
|
114
148
|
const owner = cpaModel.owned_by?.trim().toLowerCase();
|
|
115
149
|
const canonicalOwner = owner ? CANONICAL_OWNER_PREFIXES[owner] : undefined;
|
|
116
150
|
if (canonicalOwner) {
|
package/src/model-api.ts
CHANGED
|
@@ -5,10 +5,36 @@ export interface ModelApiContext {
|
|
|
5
5
|
metadataModelId?: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
const GPT_5_3_CODEX_MODEL = /^gpt-5\.3-codex(?:-|$)/;
|
|
9
|
+
const GPT_5_3_CODEX_SPARK_MODEL = /^gpt-5\.3-codex-spark$/;
|
|
10
|
+
const GPT_5_4_PLUS_MODEL = /^gpt-5\.[4-9](?:\.\d+)?(?:-|$)/;
|
|
11
|
+
const GPT_5_4_MODEL = /^gpt-5\.4$/;
|
|
12
|
+
const GPT_5_4_OR_GPT_5_5_MODEL = /^gpt-5\.[45](?:-|$)/;
|
|
13
|
+
const GPT_5_5_MODEL = /^gpt-5\.5$/;
|
|
14
|
+
const PRO_MODEL = /-pro$/;
|
|
15
|
+
const GPT_5_6_CYBER_MODEL = /^gpt-5\.6-cyber$/;
|
|
8
16
|
const GPT_5_6_MODEL = /^gpt-5\.6(?:-|$)/;
|
|
17
|
+
const GPT_6_1_MODEL = /^gpt-6\.1(?:-|$)/;
|
|
9
18
|
const GPT_6_MODEL = /^gpt-6(?:\.\d+)?(?:-|$)/;
|
|
10
19
|
const CLAUDE_MODEL = /^claude(?:-|$)/;
|
|
11
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Pi's conservative context windows for the Codex Responses families, taken
|
|
23
|
+
* from its native `openai` and `openai-codex` catalogs. models.dev advertises
|
|
24
|
+
* up to 1050000 for most of them, but a CLIProxyAPI route only allows that
|
|
25
|
+
* when its `max-context-length` override is set, so the
|
|
26
|
+
* `gpt56ContextWindow` setting must opt in explicitly.
|
|
27
|
+
*/
|
|
28
|
+
const CODEX_CONTEXT_WINDOWS: ReadonlyArray<{ pattern: RegExp; contextWindow: number }> = [
|
|
29
|
+
{ pattern: GPT_5_3_CODEX_SPARK_MODEL, contextWindow: 128000 },
|
|
30
|
+
{ pattern: GPT_5_4_MODEL, contextWindow: 272000 },
|
|
31
|
+
{ pattern: GPT_5_5_MODEL, contextWindow: 272000 },
|
|
32
|
+
{ pattern: GPT_5_6_CYBER_MODEL, contextWindow: 400000 },
|
|
33
|
+
{ pattern: GPT_5_6_MODEL, contextWindow: 272000 },
|
|
34
|
+
{ pattern: GPT_6_1_MODEL, contextWindow: 500000 },
|
|
35
|
+
{ pattern: GPT_6_MODEL, contextWindow: 272000 },
|
|
36
|
+
];
|
|
37
|
+
|
|
12
38
|
function modelName(id: string): string {
|
|
13
39
|
return id.slice(id.lastIndexOf("/") + 1);
|
|
14
40
|
}
|
|
@@ -18,6 +44,22 @@ function matchesModelId(context: ModelApiContext, pattern: RegExp): boolean {
|
|
|
18
44
|
return ids.some((id) => pattern.test(modelName(id)));
|
|
19
45
|
}
|
|
20
46
|
|
|
47
|
+
export function isGpt53CodexModel(context: ModelApiContext): boolean {
|
|
48
|
+
return matchesModelId(context, GPT_5_3_CODEX_MODEL);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isGpt53CodexSparkModel(context: ModelApiContext): boolean {
|
|
52
|
+
return matchesModelId(context, GPT_5_3_CODEX_SPARK_MODEL);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isGpt54OrGpt55Model(context: ModelApiContext): boolean {
|
|
56
|
+
return matchesModelId(context, GPT_5_4_OR_GPT_5_5_MODEL);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isProModel(context: ModelApiContext): boolean {
|
|
60
|
+
return matchesModelId(context, PRO_MODEL);
|
|
61
|
+
}
|
|
62
|
+
|
|
21
63
|
export function isGpt56Model(context: ModelApiContext): boolean {
|
|
22
64
|
return matchesModelId(context, GPT_5_6_MODEL);
|
|
23
65
|
}
|
|
@@ -30,11 +72,24 @@ export function isGpt6Model(context: ModelApiContext): boolean {
|
|
|
30
72
|
/**
|
|
31
73
|
* The Codex Responses family: every GPT model CLIProxyAPI serves from a Codex
|
|
32
74
|
* OAuth credential rather than a plain OpenAI API key. They share the same
|
|
33
|
-
* Responses-only upstream
|
|
34
|
-
* 272000 context window unless the CPA route is
|
|
75
|
+
* Responses-only upstream and the same usage shape. The Codex-served base
|
|
76
|
+
* models use a conservative 272000 context window unless the CPA route is
|
|
77
|
+
* known to allow more.
|
|
35
78
|
*/
|
|
36
79
|
export function isCodexResponsesModel(context: ModelApiContext): boolean {
|
|
37
|
-
return
|
|
80
|
+
return isGpt53CodexModel(context)
|
|
81
|
+
|| matchesModelId(context, GPT_5_4_PLUS_MODEL)
|
|
82
|
+
|| isGpt6Model(context);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function codexContextWindow(context: ModelApiContext): number | undefined {
|
|
86
|
+
for (const id of [context.availableModelId, context.metadataModelId]) {
|
|
87
|
+
if (id === undefined) continue;
|
|
88
|
+
const name = modelName(id);
|
|
89
|
+
const entry = CODEX_CONTEXT_WINDOWS.find((candidate) => candidate.pattern.test(name));
|
|
90
|
+
if (entry !== undefined) return entry.contextWindow;
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
38
93
|
}
|
|
39
94
|
|
|
40
95
|
export function isClaudeModel(context: ModelApiContext): boolean {
|
|
@@ -45,8 +100,8 @@ export function isClaudeModel(context: ModelApiContext): boolean {
|
|
|
45
100
|
* Select a model-level API when a mixed CLIProxyAPI catalog cannot share the
|
|
46
101
|
* provider default.
|
|
47
102
|
*
|
|
48
|
-
* - GPT-5.
|
|
49
|
-
* Responses API so Pi receives the Responses usage shape needed for
|
|
103
|
+
* - Codex GPT models (`gpt-5.3-codex`, `gpt-5.4` and later, `gpt-6-astra`)
|
|
104
|
+
* use the Responses API so Pi receives the Responses usage shape needed for
|
|
50
105
|
* token-cost accounting. CLIProxyAPI serves these from Codex OAuth
|
|
51
106
|
* credentials, whose upstream is Responses-only.
|
|
52
107
|
* - Claude models use the Anthropic Messages API, which CLIProxyAPI serves
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
2
|
-
import { isGpt6Model } from "./model-api.ts";
|
|
1
|
+
import type { ThinkingLevel, ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
2
|
+
import { getModelApiOverride, isGpt53CodexModel, isGpt53CodexSparkModel, isGpt54OrGpt55Model, isGpt6Model, isProModel } from "./model-api.ts";
|
|
3
|
+
import type { ModelsDevCatalog, ModelsDevMetadata } from "./types.ts";
|
|
3
4
|
|
|
4
5
|
export interface ModelCapabilityContext {
|
|
5
6
|
availableModelId: string;
|
|
6
7
|
metadataModelId?: string;
|
|
8
|
+
metadata?: ModelsDevMetadata;
|
|
9
|
+
catalog?: ModelsDevCatalog;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export interface ModelCapabilityOverrides {
|
|
@@ -13,7 +16,7 @@ export interface ModelCapabilityOverrides {
|
|
|
13
16
|
|
|
14
17
|
interface ModelCapabilityRule {
|
|
15
18
|
matches: (context: ModelCapabilityContext) => boolean;
|
|
16
|
-
overrides: ModelCapabilityOverrides;
|
|
19
|
+
overrides: (context: ModelCapabilityContext) => ModelCapabilityOverrides;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
const GPT_5_6_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
@@ -42,25 +45,103 @@ const GPT_6_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
|
42
45
|
max: "max",
|
|
43
46
|
};
|
|
44
47
|
|
|
48
|
+
const GPT_5_X_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
49
|
+
off: "none",
|
|
50
|
+
minimal: null,
|
|
51
|
+
low: "low",
|
|
52
|
+
medium: "medium",
|
|
53
|
+
high: "high",
|
|
54
|
+
xhigh: "xhigh",
|
|
55
|
+
max: null,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const GPT_5_X_PRO_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
59
|
+
off: null,
|
|
60
|
+
minimal: null,
|
|
61
|
+
low: null,
|
|
62
|
+
medium: "medium",
|
|
63
|
+
high: "high",
|
|
64
|
+
xhigh: "xhigh",
|
|
65
|
+
max: null,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const GPT_5_3_CODEX_SPARK_THINKING_LEVEL_MAP: ThinkingLevelMap = {
|
|
69
|
+
off: null,
|
|
70
|
+
minimal: null,
|
|
71
|
+
low: "low",
|
|
72
|
+
medium: "medium",
|
|
73
|
+
high: "high",
|
|
74
|
+
xhigh: "xhigh",
|
|
75
|
+
max: null,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const PI_EFFORT_LEVELS: readonly ThinkingLevel[] = ["minimal", "low", "medium", "high", "xhigh", "max"];
|
|
79
|
+
|
|
45
80
|
function includesModelFamily(context: ModelCapabilityContext, family: string): boolean {
|
|
46
81
|
return [context.availableModelId, context.metadataModelId]
|
|
47
82
|
.filter((id): id is string => id !== undefined)
|
|
48
83
|
.some((id) => id.includes(family));
|
|
49
84
|
}
|
|
50
85
|
|
|
86
|
+
function reasoningMetadata(context: ModelCapabilityContext): ModelsDevMetadata | undefined {
|
|
87
|
+
const metadata = context.metadata;
|
|
88
|
+
if (!metadata) return undefined;
|
|
89
|
+
const canonicalId = metadata.canonical_model_id;
|
|
90
|
+
return (canonicalId ? context.catalog?.[canonicalId] : undefined) ?? metadata;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function thinkingLevelMapFromReasoningOptions(metadata: ModelsDevMetadata | undefined): ThinkingLevelMap | undefined {
|
|
94
|
+
const options = metadata?.reasoning_options;
|
|
95
|
+
if (!Array.isArray(options)) return undefined;
|
|
96
|
+
const effort = options.find((option) => option?.type === "effort" && Array.isArray(option.values));
|
|
97
|
+
if (!effort?.values) return undefined;
|
|
98
|
+
const accepted = new Set(effort.values);
|
|
99
|
+
const map: ThinkingLevelMap = {};
|
|
100
|
+
for (const level of PI_EFFORT_LEVELS) map[level] = accepted.has(level) ? level : null;
|
|
101
|
+
if (accepted.has("none")) map.off = "none";
|
|
102
|
+
else if (options.every((option) => option?.type === "effort")) map.off = null;
|
|
103
|
+
return map;
|
|
104
|
+
}
|
|
105
|
+
|
|
51
106
|
const MODEL_CAPABILITY_RULES: readonly ModelCapabilityRule[] = [
|
|
52
107
|
{
|
|
53
108
|
matches: (context) => includesModelFamily(context, "gpt-5.6"),
|
|
54
|
-
overrides: {
|
|
109
|
+
overrides: () => ({
|
|
55
110
|
reasoning: true,
|
|
56
111
|
thinkingLevelMap: GPT_5_6_THINKING_LEVEL_MAP,
|
|
57
|
-
},
|
|
112
|
+
}),
|
|
58
113
|
},
|
|
59
114
|
{
|
|
60
115
|
matches: (context) => isGpt6Model(context),
|
|
61
|
-
overrides: {
|
|
116
|
+
overrides: () => ({
|
|
62
117
|
reasoning: true,
|
|
63
118
|
thinkingLevelMap: GPT_6_THINKING_LEVEL_MAP,
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
matches: (context) => isGpt53CodexModel(context) || isGpt54OrGpt55Model(context),
|
|
123
|
+
overrides: () => ({
|
|
124
|
+
reasoning: true,
|
|
125
|
+
thinkingLevelMap: GPT_5_X_THINKING_LEVEL_MAP,
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
matches: (context) => isGpt53CodexSparkModel(context),
|
|
130
|
+
overrides: () => ({
|
|
131
|
+
thinkingLevelMap: GPT_5_3_CODEX_SPARK_THINKING_LEVEL_MAP,
|
|
132
|
+
}),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
matches: (context) => isGpt54OrGpt55Model(context) && isProModel(context),
|
|
136
|
+
overrides: () => ({
|
|
137
|
+
thinkingLevelMap: GPT_5_X_PRO_THINKING_LEVEL_MAP,
|
|
138
|
+
}),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
matches: (context) => getModelApiOverride(context) === "anthropic-messages",
|
|
142
|
+
overrides: (context) => {
|
|
143
|
+
const thinkingLevelMap = thinkingLevelMapFromReasoningOptions(reasoningMetadata(context));
|
|
144
|
+
return thinkingLevelMap ? { thinkingLevelMap } : {};
|
|
64
145
|
},
|
|
65
146
|
},
|
|
66
147
|
];
|
|
@@ -70,8 +151,9 @@ export function getModelCapabilityOverrides(context: ModelCapabilityContext): Mo
|
|
|
70
151
|
|
|
71
152
|
for (const rule of MODEL_CAPABILITY_RULES) {
|
|
72
153
|
if (!rule.matches(context)) continue;
|
|
73
|
-
|
|
74
|
-
if (
|
|
154
|
+
const overrides = rule.overrides(context);
|
|
155
|
+
if (overrides.reasoning !== undefined) resolved.reasoning = overrides.reasoning;
|
|
156
|
+
if (overrides.thinkingLevelMap) resolved.thinkingLevelMap = { ...overrides.thinkingLevelMap };
|
|
75
157
|
}
|
|
76
158
|
|
|
77
159
|
return resolved;
|
package/src/model-ui.ts
CHANGED
|
@@ -20,8 +20,8 @@ function modelOverride(model: ProviderModelConfigLike, overrides: Record<string,
|
|
|
20
20
|
return overrides[model.id] ?? {};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function valuesFor(
|
|
24
|
-
return ["auto", ...
|
|
23
|
+
function valuesFor(presets: readonly number[]): string[] {
|
|
24
|
+
return ["auto", ...presets.map(String)];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function effectiveReasoning(model: ProviderModelConfigLike, override: ProviderModelOverrideLayer): boolean {
|
|
@@ -63,14 +63,14 @@ function detailItems(model: ProviderModelConfigLike, override: ProviderModelOver
|
|
|
63
63
|
label: "Context window",
|
|
64
64
|
description: `Effective: ${contextWindow} tokens. ${override.contextWindow === undefined ? "Derived default." : "User override."}`,
|
|
65
65
|
currentValue: typeof override.contextWindow !== "number" ? "auto" : String(override.contextWindow),
|
|
66
|
-
values: valuesFor(
|
|
66
|
+
values: valuesFor(CONTEXT_WINDOW_PRESETS),
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
id: "maxTokens",
|
|
70
70
|
label: "Max output tokens",
|
|
71
71
|
description: `Effective: ${maxTokens} tokens. ${override.maxTokens === undefined ? "Derived default." : "User override."}`,
|
|
72
72
|
currentValue: typeof override.maxTokens !== "number" ? "auto" : String(override.maxTokens),
|
|
73
|
-
values: valuesFor(
|
|
73
|
+
values: valuesFor(MAX_TOKEN_PRESETS),
|
|
74
74
|
},
|
|
75
75
|
];
|
|
76
76
|
}
|
|
@@ -142,7 +142,7 @@ function providerSettingsItems(
|
|
|
142
142
|
if (tab === "Models") return [
|
|
143
143
|
{
|
|
144
144
|
id: "gpt56ContextWindow",
|
|
145
|
-
label: "GPT
|
|
145
|
+
label: "Codex GPT context window",
|
|
146
146
|
description: "canonical advertises 272000 tokens; full uses the models.dev limit.",
|
|
147
147
|
currentValue: settings.gpt56ContextWindow,
|
|
148
148
|
values: ["canonical", "full"],
|
package/src/provider.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CpaModel } from "./cpa.ts";
|
|
2
2
|
import { findMetadataMatch, type MetadataMatchMethod } from "./matching.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { codexContextWindow, getModelApiOverride, type ModelApiContext } from "./model-api.ts";
|
|
4
4
|
import { getModelCapabilityOverrides } from "./model-capabilities.ts";
|
|
5
5
|
import type { Gpt56ContextWindowMode } from "./settings.ts";
|
|
6
6
|
import type {
|
|
@@ -11,14 +11,6 @@ import type {
|
|
|
11
11
|
ProviderModelOverrides,
|
|
12
12
|
} from "./types.ts";
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Pi's conservative context window for the Codex Responses family (GPT-5.6
|
|
16
|
-
* and GPT-6). models.dev advertises up to 1050000 for these models, but a
|
|
17
|
-
* CLIProxyAPI route only allows that when its `max-context-length` override is
|
|
18
|
-
* set, so the `gpt56ContextWindow` setting must opt in explicitly.
|
|
19
|
-
*/
|
|
20
|
-
export const GPT_5_6_CANONICAL_CONTEXT_WINDOW = 272000;
|
|
21
|
-
|
|
22
14
|
export const PI_MODEL_DEFAULTS = {
|
|
23
15
|
reasoning: false,
|
|
24
16
|
input: ["text"] as InputModality[],
|
|
@@ -72,19 +64,23 @@ function contextWindowForModel(
|
|
|
72
64
|
metadataContextWindow: number | undefined,
|
|
73
65
|
mode: Gpt56ContextWindowMode,
|
|
74
66
|
): number {
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
67
|
+
const canonical = codexContextWindow(context);
|
|
68
|
+
if (canonical === undefined) return metadataContextWindow ?? PI_MODEL_DEFAULTS.contextWindow;
|
|
69
|
+
if (mode === "full") return metadataContextWindow ?? canonical;
|
|
70
|
+
return canonical;
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
function modelFromMetadata(
|
|
81
74
|
cpaModel: CpaModel,
|
|
82
75
|
metadata: ModelsDevMetadata,
|
|
76
|
+
catalog: ModelsDevCatalog,
|
|
83
77
|
gpt56ContextWindow: Gpt56ContextWindowMode,
|
|
84
78
|
): ProviderModelConfigLike {
|
|
85
79
|
const capabilityContext = {
|
|
86
80
|
availableModelId: cpaModel.id,
|
|
87
81
|
metadataModelId: metadata.id,
|
|
82
|
+
metadata,
|
|
83
|
+
catalog,
|
|
88
84
|
};
|
|
89
85
|
const capabilityOverrides = getModelCapabilityOverrides(capabilityContext);
|
|
90
86
|
const api = getModelApiOverride(capabilityContext);
|
|
@@ -179,7 +175,7 @@ export function buildProviderModels(
|
|
|
179
175
|
enriched += 1;
|
|
180
176
|
matchMethods[match.method] += 1;
|
|
181
177
|
return applyModelOverride(
|
|
182
|
-
modelFromMetadata(cpaModel, match.metadata, gpt56ContextWindow),
|
|
178
|
+
modelFromMetadata(cpaModel, match.metadata, catalog, gpt56ContextWindow),
|
|
183
179
|
overrides,
|
|
184
180
|
);
|
|
185
181
|
});
|
package/src/registration.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { RefreshModelsContext } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { ProviderConfig, ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { isClaudeModel } from "./model-api.ts";
|
|
4
3
|
import type { CpaProviderConfig } from "./types.ts";
|
|
5
4
|
import type { ProviderModelConfigLike } from "./types.ts";
|
|
6
5
|
|
|
@@ -25,7 +24,7 @@ export function anthropicBaseUrl(providerBaseUrl: string): string {
|
|
|
25
24
|
export function normalizeProviderModels(
|
|
26
25
|
models: ProviderModelConfigLike[],
|
|
27
26
|
providerBaseUrl?: string,
|
|
28
|
-
):
|
|
27
|
+
): ProviderModelConfigLike[] {
|
|
29
28
|
return models.map((model) => ({
|
|
30
29
|
...model,
|
|
31
30
|
// CLIProxyAPI accepts OpenAI-compatible function tools for both Chat
|
|
@@ -35,9 +34,8 @@ export function normalizeProviderModels(
|
|
|
35
34
|
compat: {
|
|
36
35
|
...model.compat,
|
|
37
36
|
supportsStrictMode: false,
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
// effort rides on a top-level `output_config`.
|
|
37
|
+
// Anthropic Messages models use the same adaptive thinking path pi uses
|
|
38
|
+
// for anthropic/* models, so effort rides on a top-level `output_config`.
|
|
41
39
|
//
|
|
42
40
|
// `supportsMidConvoEffort` is deliberately NOT set. It makes pi attach a
|
|
43
41
|
// per-message `output_config` to synthesized system messages behind the
|
|
@@ -45,14 +43,14 @@ export function normalizeProviderModels(
|
|
|
45
43
|
// beta and rejects the request with
|
|
46
44
|
// `messages.N.output_config: Extra inputs are not permitted`. Top-level
|
|
47
45
|
// `output_config` is accepted, so adaptive thinking still works.
|
|
48
|
-
...(
|
|
46
|
+
...(model.api === "anthropic-messages"
|
|
49
47
|
? { forceAdaptiveThinking: true }
|
|
50
48
|
: {}),
|
|
51
49
|
},
|
|
52
|
-
...(providerBaseUrl &&
|
|
50
|
+
...(providerBaseUrl && model.api === "anthropic-messages"
|
|
53
51
|
? { baseUrl: anthropicBaseUrl(providerBaseUrl) }
|
|
54
52
|
: {}),
|
|
55
|
-
}))
|
|
53
|
+
}));
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
export function buildProviderRegistration(
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
2
|
-
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { Api, Model, ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
3
2
|
|
|
4
3
|
export type InputModality = "text" | "image";
|
|
5
4
|
|
|
@@ -30,12 +29,19 @@ export interface CpaProviderConfig {
|
|
|
30
29
|
modelOverrides: ProviderModelOverrides;
|
|
31
30
|
}
|
|
32
31
|
|
|
32
|
+
export interface ModelsDevReasoningOption {
|
|
33
|
+
type?: string;
|
|
34
|
+
values?: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
export interface ModelsDevMetadata {
|
|
34
38
|
id: string;
|
|
35
39
|
/** models.dev provider key retained for owner-hint matching. */
|
|
36
40
|
sourceProvider?: string;
|
|
37
41
|
name?: string;
|
|
38
42
|
reasoning?: boolean;
|
|
43
|
+
reasoning_options?: ModelsDevReasoningOption[];
|
|
44
|
+
canonical_model_id?: string;
|
|
39
45
|
modalities?: {
|
|
40
46
|
input?: string[];
|
|
41
47
|
output?: string[];
|
|
@@ -68,9 +74,9 @@ export interface ProviderModelConfigLike {
|
|
|
68
74
|
id: string;
|
|
69
75
|
name: string;
|
|
70
76
|
reasoning: boolean;
|
|
71
|
-
api?:
|
|
77
|
+
api?: Api;
|
|
72
78
|
baseUrl?: string;
|
|
73
|
-
compat?:
|
|
79
|
+
compat?: Model<Api>["compat"];
|
|
74
80
|
thinkingLevelMap?: ThinkingLevelMap;
|
|
75
81
|
input: InputModality[];
|
|
76
82
|
cost: {
|