pi-cliproxyapi-provider 0.4.11 → 0.4.12
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 +26 -2
- package/data/models-dev-fallback.json +1 -1
- package/extensions/index.ts +8 -1
- package/package.json +1 -1
- package/src/catalog.ts +10 -1
- package/src/codex-compat.ts +43 -0
- package/src/commands.ts +1 -0
- package/src/discovery.ts +3 -1
- package/src/matching.ts +2 -1
- package/src/model-api.ts +26 -0
- package/src/models-dev.ts +1 -1
- package/src/provider.ts +47 -8
- package/src/registration.ts +15 -1
- package/src/runtime.ts +11 -5
- package/src/settings.ts +40 -0
- package/src/types.ts +20 -0
package/extensions/index.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { buildProviderRegistration } from "../src/registration.ts";
|
|
|
8
8
|
import { buildUnavailableProviderModels } from "../src/provider.ts";
|
|
9
9
|
import { registerCliproxyapiCommand } from "../src/commands.ts";
|
|
10
10
|
import { getDiscoveryApiKey } from "../src/auth.ts";
|
|
11
|
+
import { loadProviderSettings } from "../src/settings.ts";
|
|
12
|
+
import { registerCodexCompatiblePayloadAdapter } from "../src/codex-compat.ts";
|
|
11
13
|
|
|
12
14
|
const extensionDir = dirname(fileURLToPath(import.meta.url));
|
|
13
15
|
const packageRoot = dirname(extensionDir);
|
|
@@ -16,16 +18,21 @@ const bundledModelsDevPath = join(packageRoot, "data", "models-dev-fallback.json
|
|
|
16
18
|
export default async function (pi: ExtensionAPI) {
|
|
17
19
|
let config = DEFAULT_CONFIG;
|
|
18
20
|
try {
|
|
19
|
-
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
config = loadConfig(cwd);
|
|
23
|
+
const settings = loadProviderSettings(cwd);
|
|
20
24
|
const catalog = new ProviderCatalog({
|
|
21
25
|
config,
|
|
26
|
+
gpt56ContextWindow: settings.gpt56ContextWindow,
|
|
22
27
|
bundledModelsDevPath,
|
|
23
28
|
getApiKey: () => getDiscoveryApiKey(config.providerName),
|
|
24
29
|
});
|
|
25
30
|
const runtime = new ProviderRuntime({ pi, config, catalog });
|
|
31
|
+
registerCodexCompatiblePayloadAdapter(pi, config.providerName);
|
|
26
32
|
registerCliproxyapiCommand(pi, runtime, catalog);
|
|
27
33
|
await runtime.start();
|
|
28
34
|
} catch (error) {
|
|
35
|
+
registerCodexCompatiblePayloadAdapter(pi, config.providerName);
|
|
29
36
|
registerCliproxyapiCommand(pi);
|
|
30
37
|
pi.registerProvider(config.providerName, buildProviderRegistration(config, buildUnavailableProviderModels()).config);
|
|
31
38
|
console.warn(`[pi-cliproxyapi-provider] registered placeholder provider after startup failure: ${error instanceof Error ? error.message : String(error)}`);
|
package/package.json
CHANGED
package/src/catalog.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { readCache, writeCache, type CacheEnvelope } from "./cache.ts";
|
|
|
3
3
|
import { fetchCpaModels, parseCpaModelsCache, type CpaModel } from "./cpa.ts";
|
|
4
4
|
import { fetchModelsDevCatalog, parseModelsDevCatalog, readBundledModelsDevFallback } from "./models-dev.ts";
|
|
5
5
|
import { buildProviderModels, type BuildProviderModelsResult } from "./provider.ts";
|
|
6
|
+
import type { Gpt56ContextWindowMode } from "./settings.ts";
|
|
6
7
|
import type { CpaProviderConfig, ModelsDevCatalog } from "./types.ts";
|
|
7
8
|
|
|
8
9
|
export type MetadataSource = "cache" | "bundled" | "disabled";
|
|
@@ -14,6 +15,7 @@ export interface CatalogSnapshot {
|
|
|
14
15
|
metadata: ModelsDevCatalog;
|
|
15
16
|
metadataUpdatedAt?: number;
|
|
16
17
|
metadataSource: MetadataSource;
|
|
18
|
+
gpt56ContextWindow: Gpt56ContextWindowMode;
|
|
17
19
|
built: BuildProviderModelsResult;
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -32,6 +34,7 @@ export interface CatalogRefreshResult {
|
|
|
32
34
|
|
|
33
35
|
export interface ProviderCatalogOptions {
|
|
34
36
|
config: CpaProviderConfig;
|
|
37
|
+
gpt56ContextWindow: Gpt56ContextWindowMode;
|
|
35
38
|
bundledModelsDevPath: string;
|
|
36
39
|
getApiKey: () => Promise<string | undefined>;
|
|
37
40
|
backgroundTimeoutMs?: number;
|
|
@@ -219,7 +222,13 @@ export class ProviderCatalog {
|
|
|
219
222
|
metadata,
|
|
220
223
|
metadataUpdatedAt,
|
|
221
224
|
metadataSource,
|
|
222
|
-
|
|
225
|
+
gpt56ContextWindow: this.options.gpt56ContextWindow,
|
|
226
|
+
built: buildProviderModels(
|
|
227
|
+
cpaModels,
|
|
228
|
+
metadata,
|
|
229
|
+
this.options.config.modelAliases,
|
|
230
|
+
this.options.gpt56ContextWindow,
|
|
231
|
+
),
|
|
223
232
|
};
|
|
224
233
|
return this.snapshot;
|
|
225
234
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isResponsesModel(
|
|
8
|
+
model: Pick<NonNullable<ExtensionContext["model"]>, "provider" | "api"> | null | undefined,
|
|
9
|
+
providerName: string,
|
|
10
|
+
): boolean {
|
|
11
|
+
return model?.provider.trim().toLowerCase() === providerName.trim().toLowerCase()
|
|
12
|
+
&& model.api.toLowerCase().includes("responses");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Match the Codex-compatible Responses wire contract used by
|
|
17
|
+
* pi-codex-conversion: function tools explicitly publish `strict: null`.
|
|
18
|
+
* Generic OpenAI Responses omits the field when strict mode is unsupported,
|
|
19
|
+
* which does not preserve optional argument behavior for Codex-like models.
|
|
20
|
+
*/
|
|
21
|
+
export function rewriteCodexCompatibleToolPayload(
|
|
22
|
+
payload: unknown,
|
|
23
|
+
model: Pick<NonNullable<ExtensionContext["model"]>, "provider" | "api"> | null | undefined,
|
|
24
|
+
providerName: string,
|
|
25
|
+
): unknown | undefined {
|
|
26
|
+
if (!isResponsesModel(model, providerName) || !isRecord(payload) || !Array.isArray(payload.tools)) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let changed = false;
|
|
31
|
+
const tools = payload.tools.map((tool) => {
|
|
32
|
+
if (!isRecord(tool) || tool.type !== "function" || tool.strict === null) return tool;
|
|
33
|
+
changed = true;
|
|
34
|
+
return { ...tool, strict: null };
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return changed ? { ...payload, tools } : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function registerCodexCompatiblePayloadAdapter(pi: ExtensionAPI, providerName: string): void {
|
|
41
|
+
pi.on("before_provider_request", (event, ctx) =>
|
|
42
|
+
rewriteCodexCompatibleToolPayload(event.payload, ctx.model, providerName));
|
|
43
|
+
}
|
package/src/commands.ts
CHANGED
|
@@ -100,6 +100,7 @@ function statusText(config: ReturnType<typeof loadConfig>, snapshot: CatalogSnap
|
|
|
100
100
|
`Image-capable models: ${capabilityCount(snapshot, "image")}`,
|
|
101
101
|
`CPA snapshot: ${age(snapshot.cpaUpdatedAt)}`,
|
|
102
102
|
`models.dev metadata: ${snapshot.metadataSource}${snapshot.metadataUpdatedAt ? `, ${age(snapshot.metadataUpdatedAt)}` : ""}`,
|
|
103
|
+
`GPT-5.6 context window: ${snapshot.gpt56ContextWindow === "full" ? "full models.dev limit" : "canonical 272000"}`,
|
|
103
104
|
].join("\n");
|
|
104
105
|
}
|
|
105
106
|
|
package/src/discovery.ts
CHANGED
|
@@ -7,7 +7,9 @@ export function cpaModelsCachePath(config: CpaProviderConfig): string {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function modelsDevCachePath(): string {
|
|
10
|
-
|
|
10
|
+
// Keep provider-catalog metadata separate from the former lab-level
|
|
11
|
+
// models.json cache, which omitted provider pricing.
|
|
12
|
+
return join(cacheDir(), "models-dev-api.json");
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export function discoveryHeaders(config: CpaProviderConfig, apiKey?: string): Record<string, string> {
|
package/src/matching.ts
CHANGED
|
@@ -47,6 +47,7 @@ export function findMetadataMatch(
|
|
|
47
47
|
return { metadataId: cpaModel.id, metadata: catalog[cpaModel.id], method: "exact" };
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const suffixCandidates = Object.keys(catalog).filter((key) => key.endsWith(`/${cpaModel.id}`));
|
|
50
51
|
const owner = cpaModel.owned_by?.trim().toLowerCase();
|
|
51
52
|
const canonicalOwner = owner ? CANONICAL_OWNER_PREFIXES[owner] : undefined;
|
|
52
53
|
if (canonicalOwner) {
|
|
@@ -56,7 +57,7 @@ export function findMetadataMatch(
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
const suffixKey = oneMatch(
|
|
60
|
+
const suffixKey = oneMatch(suffixCandidates);
|
|
60
61
|
if (suffixKey) {
|
|
61
62
|
return { metadataId: suffixKey, metadata: catalog[suffixKey], method: "suffix" };
|
|
62
63
|
}
|
package/src/model-api.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProviderModelConfigLike } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
export interface ModelApiContext {
|
|
4
|
+
availableModelId: string;
|
|
5
|
+
metadataModelId?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const GPT_5_6_MODEL = /^gpt-5\.6(?:-|$)/;
|
|
9
|
+
|
|
10
|
+
function modelName(id: string): string {
|
|
11
|
+
return id.slice(id.lastIndexOf("/") + 1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isGpt56Model(context: ModelApiContext): boolean {
|
|
15
|
+
const ids = [context.availableModelId, context.metadataModelId].filter((id): id is string => id !== undefined);
|
|
16
|
+
return ids.some((id) => GPT_5_6_MODEL.test(modelName(id)));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Select a model-level API when a mixed CLIProxyAPI catalog cannot share the
|
|
21
|
+
* provider default. GPT-5.6, including Codex variants, uses the Responses API
|
|
22
|
+
* so Pi receives the Responses usage shape needed for token-cost accounting.
|
|
23
|
+
*/
|
|
24
|
+
export function getModelApiOverride(context: ModelApiContext): ProviderModelConfigLike["api"] | undefined {
|
|
25
|
+
return isGpt56Model(context) ? "openai-responses" : undefined;
|
|
26
|
+
}
|
package/src/models-dev.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import type { ModelsDevCatalog, ModelsDevMetadata } from "./types.ts";
|
|
3
3
|
import { withNetworkTimeout } from "./network.ts";
|
|
4
4
|
|
|
5
|
-
export const MODELS_DEV_URL = "https://models.dev/
|
|
5
|
+
export const MODELS_DEV_URL = "https://models.dev/api.json";
|
|
6
6
|
|
|
7
7
|
function isMetadata(value: unknown): value is ModelsDevMetadata {
|
|
8
8
|
return !!value && typeof value === "object" && typeof (value as { id?: unknown }).id === "string";
|
package/src/provider.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { CpaModel } from "./cpa.ts";
|
|
2
2
|
import { findMetadataMatch, type MetadataMatchMethod } from "./matching.ts";
|
|
3
|
+
import { getModelApiOverride, isGpt56Model, type ModelApiContext } from "./model-api.ts";
|
|
3
4
|
import { getModelCapabilityOverrides } from "./model-capabilities.ts";
|
|
5
|
+
import type { Gpt56ContextWindowMode } from "./settings.ts";
|
|
4
6
|
import type { InputModality, ModelsDevCatalog, ModelsDevMetadata, ProviderModelConfigLike } from "./types.ts";
|
|
5
7
|
|
|
8
|
+
export const GPT_5_6_CANONICAL_CONTEXT_WINDOW = 272000;
|
|
9
|
+
|
|
6
10
|
export const PI_MODEL_DEFAULTS = {
|
|
7
11
|
reasoning: false,
|
|
8
12
|
input: ["text"] as InputModality[],
|
|
@@ -30,30 +34,60 @@ function inputFromMetadata(metadata: ModelsDevMetadata): InputModality[] {
|
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
function costFromMetadata(metadata: ModelsDevMetadata): ProviderModelConfigLike["cost"] {
|
|
37
|
+
const tiers = metadata.cost?.tiers?.flatMap((tier) => {
|
|
38
|
+
const threshold = tier.tier?.size;
|
|
39
|
+
if (tier.tier?.type !== "context" || typeof threshold !== "number") return [];
|
|
40
|
+
return [{
|
|
41
|
+
inputTokensAbove: threshold,
|
|
42
|
+
input: tier.input ?? 0,
|
|
43
|
+
output: tier.output ?? 0,
|
|
44
|
+
cacheRead: tier.cache_read ?? 0,
|
|
45
|
+
cacheWrite: tier.cache_write ?? 0,
|
|
46
|
+
}];
|
|
47
|
+
});
|
|
48
|
+
|
|
33
49
|
return {
|
|
34
50
|
input: metadata.cost?.input ?? 0,
|
|
35
51
|
output: metadata.cost?.output ?? 0,
|
|
36
52
|
cacheRead: metadata.cost?.cache_read ?? 0,
|
|
37
53
|
cacheWrite: metadata.cost?.cache_write ?? 0,
|
|
54
|
+
...(tiers && tiers.length > 0 ? { tiers } : {}),
|
|
38
55
|
};
|
|
39
56
|
}
|
|
40
57
|
|
|
41
|
-
function
|
|
42
|
-
|
|
58
|
+
function contextWindowForModel(
|
|
59
|
+
context: ModelApiContext,
|
|
60
|
+
metadataContextWindow: number | undefined,
|
|
61
|
+
mode: Gpt56ContextWindowMode,
|
|
62
|
+
): number {
|
|
63
|
+
if (!isGpt56Model(context)) return metadataContextWindow ?? PI_MODEL_DEFAULTS.contextWindow;
|
|
64
|
+
if (mode === "full") return metadataContextWindow ?? GPT_5_6_CANONICAL_CONTEXT_WINDOW;
|
|
65
|
+
return GPT_5_6_CANONICAL_CONTEXT_WINDOW;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function modelFromMetadata(
|
|
69
|
+
cpaModel: CpaModel,
|
|
70
|
+
metadata: ModelsDevMetadata,
|
|
71
|
+
gpt56ContextWindow: Gpt56ContextWindowMode,
|
|
72
|
+
): ProviderModelConfigLike {
|
|
73
|
+
const capabilityContext = {
|
|
43
74
|
availableModelId: cpaModel.id,
|
|
44
75
|
metadataModelId: metadata.id,
|
|
45
|
-
}
|
|
76
|
+
};
|
|
77
|
+
const capabilityOverrides = getModelCapabilityOverrides(capabilityContext);
|
|
78
|
+
const api = getModelApiOverride(capabilityContext);
|
|
46
79
|
|
|
47
80
|
return {
|
|
48
81
|
id: cpaModel.id,
|
|
49
82
|
name: metadata.name ?? cpaModel.id,
|
|
50
83
|
reasoning: capabilityOverrides.reasoning ?? metadata.reasoning ?? PI_MODEL_DEFAULTS.reasoning,
|
|
84
|
+
...(api ? { api } : {}),
|
|
51
85
|
...(capabilityOverrides.thinkingLevelMap
|
|
52
86
|
? { thinkingLevelMap: capabilityOverrides.thinkingLevelMap }
|
|
53
87
|
: {}),
|
|
54
88
|
input: inputFromMetadata(metadata),
|
|
55
89
|
cost: costFromMetadata(metadata),
|
|
56
|
-
contextWindow: metadata.limit?.context
|
|
90
|
+
contextWindow: contextWindowForModel(capabilityContext, metadata.limit?.context, gpt56ContextWindow),
|
|
57
91
|
maxTokens: metadata.limit?.output ?? PI_MODEL_DEFAULTS.maxTokens,
|
|
58
92
|
};
|
|
59
93
|
}
|
|
@@ -66,14 +100,18 @@ function cloneModelDefaults(): typeof PI_MODEL_DEFAULTS {
|
|
|
66
100
|
};
|
|
67
101
|
}
|
|
68
102
|
|
|
69
|
-
function defaultModel(cpaModel: CpaModel): ProviderModelConfigLike {
|
|
70
|
-
const
|
|
103
|
+
function defaultModel(cpaModel: CpaModel, gpt56ContextWindow: Gpt56ContextWindowMode): ProviderModelConfigLike {
|
|
104
|
+
const modelContext = { availableModelId: cpaModel.id };
|
|
105
|
+
const capabilityOverrides = getModelCapabilityOverrides(modelContext);
|
|
106
|
+
const api = getModelApiOverride(modelContext);
|
|
71
107
|
|
|
72
108
|
return {
|
|
73
109
|
id: cpaModel.id,
|
|
74
110
|
name: cpaModel.id,
|
|
75
111
|
...cloneModelDefaults(),
|
|
76
112
|
...capabilityOverrides,
|
|
113
|
+
...(api ? { api } : {}),
|
|
114
|
+
contextWindow: contextWindowForModel(modelContext, undefined, gpt56ContextWindow),
|
|
77
115
|
};
|
|
78
116
|
}
|
|
79
117
|
|
|
@@ -95,6 +133,7 @@ export function buildProviderModels(
|
|
|
95
133
|
cpaModels: CpaModel[],
|
|
96
134
|
catalog: ModelsDevCatalog,
|
|
97
135
|
aliases: Record<string, string>,
|
|
136
|
+
gpt56ContextWindow: Gpt56ContextWindowMode = "canonical",
|
|
98
137
|
): BuildProviderModelsResult {
|
|
99
138
|
const matchMethods = emptyMatchMethods();
|
|
100
139
|
const unmatchedModelIds: string[] = [];
|
|
@@ -104,12 +143,12 @@ export function buildProviderModels(
|
|
|
104
143
|
const match = findMetadataMatch(cpaModel, catalog, aliases);
|
|
105
144
|
if (!match) {
|
|
106
145
|
unmatchedModelIds.push(cpaModel.id);
|
|
107
|
-
return defaultModel(cpaModel);
|
|
146
|
+
return defaultModel(cpaModel, gpt56ContextWindow);
|
|
108
147
|
}
|
|
109
148
|
|
|
110
149
|
enriched += 1;
|
|
111
150
|
matchMethods[match.method] += 1;
|
|
112
|
-
return modelFromMetadata(cpaModel, match.metadata);
|
|
151
|
+
return modelFromMetadata(cpaModel, match.metadata, gpt56ContextWindow);
|
|
113
152
|
});
|
|
114
153
|
|
|
115
154
|
return {
|
package/src/registration.ts
CHANGED
|
@@ -8,6 +8,20 @@ export interface ProviderRegistration {
|
|
|
8
8
|
config: ProviderConfig;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export function normalizeProviderModels(models: ProviderModelConfigLike[]): ProviderModelConfig[] {
|
|
12
|
+
return models.map((model) => ({
|
|
13
|
+
...model,
|
|
14
|
+
// CLIProxyAPI accepts OpenAI-compatible function tools for both Chat
|
|
15
|
+
// Completions and Responses models, but Pi's strict all-properties-required
|
|
16
|
+
// rewrite destroys optional argument semantics for multi-mode extension
|
|
17
|
+
// tools. Keep each model's API selection and disable only that rewrite.
|
|
18
|
+
compat: {
|
|
19
|
+
...model.compat,
|
|
20
|
+
supportsStrictMode: false,
|
|
21
|
+
},
|
|
22
|
+
})) as ProviderModelConfig[];
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
export function buildProviderRegistration(
|
|
12
26
|
config: CpaProviderConfig,
|
|
13
27
|
models: ProviderModelConfigLike[],
|
|
@@ -22,7 +36,7 @@ export function buildProviderRegistration(
|
|
|
22
36
|
apiKey: config.authRequired ? "$CLIPROXYAPI_API_KEY" : "cliproxyapi-no-auth",
|
|
23
37
|
authHeader: config.authRequired && config.authHeader,
|
|
24
38
|
headers: Object.keys(config.headers).length > 0 ? config.headers : undefined,
|
|
25
|
-
models: models
|
|
39
|
+
models: normalizeProviderModels(models),
|
|
26
40
|
refreshModels,
|
|
27
41
|
},
|
|
28
42
|
};
|
package/src/runtime.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ExtensionAPI, ProviderModelConfig } from "@earendil-works/pi-codin
|
|
|
3
3
|
import { getDiscoveryApiKey } from "./auth.ts";
|
|
4
4
|
import { ProviderCatalog, type CatalogRefreshResult, type CatalogSnapshot, type RefreshTarget } from "./catalog.ts";
|
|
5
5
|
import { buildUnavailableProviderModels } from "./provider.ts";
|
|
6
|
-
import { buildProviderRegistration } from "./registration.ts";
|
|
6
|
+
import { buildProviderRegistration, normalizeProviderModels } from "./registration.ts";
|
|
7
7
|
import type { CpaProviderConfig } from "./types.ts";
|
|
8
8
|
|
|
9
9
|
export interface ProviderRuntimeOptions {
|
|
@@ -39,7 +39,9 @@ export class ProviderRuntime {
|
|
|
39
39
|
async refreshModels(context: RefreshModelsContext): Promise<ProviderModelConfig[]> {
|
|
40
40
|
if (!context.allowNetwork) {
|
|
41
41
|
const snapshot = await this.options.catalog.load();
|
|
42
|
-
return (
|
|
42
|
+
return normalizeProviderModels(
|
|
43
|
+
snapshot.built.models.length > 0 ? snapshot.built.models : buildUnavailableProviderModels(),
|
|
44
|
+
);
|
|
43
45
|
}
|
|
44
46
|
const mode = context.force ? "manual" : "background";
|
|
45
47
|
const credential = context.credential;
|
|
@@ -47,9 +49,13 @@ export class ProviderRuntime {
|
|
|
47
49
|
? async () => credential.key
|
|
48
50
|
: () => getDiscoveryApiKey(this.options.config.providerName);
|
|
49
51
|
const result = await this.options.catalog.refresh("models", mode, keyFn, context.signal);
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
// Pi publishes refreshModels' return value synchronously. Registering here as
|
|
53
|
+
// well would create a second, competing catalog publication.
|
|
54
|
+
return normalizeProviderModels(
|
|
55
|
+
result.snapshot.built.models.length > 0
|
|
56
|
+
? result.snapshot.built.models
|
|
57
|
+
: buildUnavailableProviderModels(),
|
|
58
|
+
);
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
private register(snapshot: CatalogSnapshot, force: boolean): void {
|
package/src/settings.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export const PROVIDER_SETTINGS_NAMESPACE = "pi-cliproxyapi-provider";
|
|
4
|
+
|
|
5
|
+
export type Gpt56ContextWindowMode = "canonical" | "full";
|
|
6
|
+
|
|
7
|
+
export interface ProviderSettings {
|
|
8
|
+
gpt56ContextWindow: Gpt56ContextWindowMode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_PROVIDER_SETTINGS: ProviderSettings = {
|
|
12
|
+
gpt56ContextWindow: "canonical",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function parseSettingsLayer(settings: unknown, scope: string): Partial<ProviderSettings> {
|
|
16
|
+
if (!settings || typeof settings !== "object" || Array.isArray(settings)) return {};
|
|
17
|
+
const namespace = (settings as Record<string, unknown>)[PROVIDER_SETTINGS_NAMESPACE];
|
|
18
|
+
if (namespace === undefined) return {};
|
|
19
|
+
if (!namespace || typeof namespace !== "object" || Array.isArray(namespace)) {
|
|
20
|
+
throw new Error(`${PROVIDER_SETTINGS_NAMESPACE} must be an object in ${scope} settings.json`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const value = (namespace as Record<string, unknown>).gpt56ContextWindow;
|
|
24
|
+
if (value === undefined) return {};
|
|
25
|
+
if (value !== "canonical" && value !== "full") {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`${PROVIDER_SETTINGS_NAMESPACE}.gpt56ContextWindow must be "canonical" or "full" in ${scope} settings.json`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return { gpt56ContextWindow: value };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function loadProviderSettings(cwd: string, agentDir?: string): ProviderSettings {
|
|
34
|
+
const manager = SettingsManager.create(cwd, agentDir);
|
|
35
|
+
return {
|
|
36
|
+
...DEFAULT_PROVIDER_SETTINGS,
|
|
37
|
+
...parseSettingsLayer(manager.getGlobalSettings(), "global"),
|
|
38
|
+
...parseSettingsLayer(manager.getProjectSettings(), "project"),
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
|
|
3
4
|
export type InputModality = "text" | "image";
|
|
4
5
|
|
|
@@ -29,6 +30,16 @@ export interface ModelsDevMetadata {
|
|
|
29
30
|
output?: number;
|
|
30
31
|
cache_read?: number;
|
|
31
32
|
cache_write?: number;
|
|
33
|
+
tiers?: Array<{
|
|
34
|
+
input?: number;
|
|
35
|
+
output?: number;
|
|
36
|
+
cache_read?: number;
|
|
37
|
+
cache_write?: number;
|
|
38
|
+
tier?: {
|
|
39
|
+
type?: string;
|
|
40
|
+
size?: number;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
|
|
@@ -38,6 +49,8 @@ export interface ProviderModelConfigLike {
|
|
|
38
49
|
id: string;
|
|
39
50
|
name: string;
|
|
40
51
|
reasoning: boolean;
|
|
52
|
+
api?: ProviderModelConfig["api"];
|
|
53
|
+
compat?: ProviderModelConfig["compat"];
|
|
41
54
|
thinkingLevelMap?: ThinkingLevelMap;
|
|
42
55
|
input: InputModality[];
|
|
43
56
|
cost: {
|
|
@@ -45,6 +58,13 @@ export interface ProviderModelConfigLike {
|
|
|
45
58
|
output: number;
|
|
46
59
|
cacheRead: number;
|
|
47
60
|
cacheWrite: number;
|
|
61
|
+
tiers?: Array<{
|
|
62
|
+
inputTokensAbove: number;
|
|
63
|
+
input: number;
|
|
64
|
+
output: number;
|
|
65
|
+
cacheRead: number;
|
|
66
|
+
cacheWrite: number;
|
|
67
|
+
}>;
|
|
48
68
|
};
|
|
49
69
|
contextWindow: number;
|
|
50
70
|
maxTokens: number;
|