pi-cache-optimizer 2.5.6 → 2.5.7
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/index.ts +59 -17
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -775,6 +775,19 @@ function isOpenAICompatibleApi(api: unknown): boolean {
|
|
|
775
775
|
return value === "openai-completions" || value === "openai-responses";
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
+
function isOpenAICompatibleProxyApi(api: unknown): boolean {
|
|
779
|
+
return lower(api) === "openai-completions";
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function isResponsesPromptRewriteBypassApi(api: unknown): boolean {
|
|
783
|
+
const value = lower(api);
|
|
784
|
+
return value === "openai-codex-responses" || value === "openai-responses" || value === "azure-openai-responses";
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function isMistralConversationsApi(api: unknown): boolean {
|
|
788
|
+
return lower(api) === "mistral-conversations";
|
|
789
|
+
}
|
|
790
|
+
|
|
778
791
|
function isOpenAIFamilyToken(token: string): boolean {
|
|
779
792
|
return token.includes("gpt-") || token.includes("chatgpt") || OPENAI_REASONING_MODEL_PATTERN.test(token);
|
|
780
793
|
}
|
|
@@ -1492,7 +1505,7 @@ function describeMissingOpenAIFamilyProxyCompat(model: PiModel): string[] {
|
|
|
1492
1505
|
const missing: string[] = [];
|
|
1493
1506
|
|
|
1494
1507
|
if (!isOpenAIFamilyModel(model)) return missing;
|
|
1495
|
-
if (
|
|
1508
|
+
if (!isOpenAICompatibleProxyApi(model.api)) return missing;
|
|
1496
1509
|
if (isOfficialOpenAIBaseUrl(model)) return missing;
|
|
1497
1510
|
|
|
1498
1511
|
if (compat.supportsLongCacheRetention !== true) {
|
|
@@ -1515,7 +1528,7 @@ function describeMissingOpenAICompatibleProxyCompat(model: PiModel): string[] {
|
|
|
1515
1528
|
const compat = getCompat(model);
|
|
1516
1529
|
const missing: string[] = [];
|
|
1517
1530
|
|
|
1518
|
-
if (
|
|
1531
|
+
if (!isOpenAICompatibleProxyApi(model.api)) return missing;
|
|
1519
1532
|
if (isOfficialOpenAIBaseUrl(model)) return missing;
|
|
1520
1533
|
|
|
1521
1534
|
if (compat.supportsLongCacheRetention !== true) {
|
|
@@ -3228,7 +3241,7 @@ async function writePersistedCacheStats(state: CacheStatsState, currentSessionHa
|
|
|
3228
3241
|
|
|
3229
3242
|
|
|
3230
3243
|
function isCompatCheckApplicable(model: PiModel): boolean {
|
|
3231
|
-
return
|
|
3244
|
+
return isOpenAICompatibleProxyApi(model.api) && !isOfficialOpenAIBaseUrl(model);
|
|
3232
3245
|
}
|
|
3233
3246
|
|
|
3234
3247
|
function isPromptCacheRetention400Applicable(model: PiModel): boolean {
|
|
@@ -3263,10 +3276,10 @@ function describeRouterChannelDiagnostics(model: PiModel): string[] {
|
|
|
3263
3276
|
const baseUrl = lower(model.baseUrl || "");
|
|
3264
3277
|
const provider = lower(model.provider);
|
|
3265
3278
|
|
|
3266
|
-
//
|
|
3267
|
-
//
|
|
3268
|
-
// or
|
|
3269
|
-
if (api
|
|
3279
|
+
// Router/channel diagnostics only apply to OpenAI-compatible proxy APIs.
|
|
3280
|
+
// Native APIs like mistral-conversations, azure-openai-responses,
|
|
3281
|
+
// anthropic-messages, or bedrock-converse-stream are intentionally excluded.
|
|
3282
|
+
if (api === "azure-openai-responses" || isMistralConversationsApi(api) || !isOpenAICompatibleApi(api)) {
|
|
3270
3283
|
return notes;
|
|
3271
3284
|
}
|
|
3272
3285
|
|
|
@@ -3405,6 +3418,33 @@ function describeRouterChannelDiagnostics(model: PiModel): string[] {
|
|
|
3405
3418
|
return notes;
|
|
3406
3419
|
}
|
|
3407
3420
|
|
|
3421
|
+
function getCompatCheckNotApplicableLines(model: PiModel): string[] {
|
|
3422
|
+
const api = lower(model.api);
|
|
3423
|
+
|
|
3424
|
+
if (isMistralConversationsApi(api)) {
|
|
3425
|
+
return [
|
|
3426
|
+
"ℹ️ Compat check not applicable for this model.",
|
|
3427
|
+
" Native Mistral `mistral-conversations` uses provider-native transport; OpenAI-compatible proxy compat flags do not apply.",
|
|
3428
|
+
];
|
|
3429
|
+
}
|
|
3430
|
+
|
|
3431
|
+
if (api === "azure-openai-responses") {
|
|
3432
|
+
return [
|
|
3433
|
+
"ℹ️ Compat check not applicable for this model.",
|
|
3434
|
+
" Native Azure OpenAI Responses uses the Responses transport; OpenAI-compatible proxy compat flags do not apply.",
|
|
3435
|
+
];
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
if (api === "openai-codex-responses" || (api === "openai-responses" && isOfficialOpenAIBaseUrl(model))) {
|
|
3439
|
+
return [
|
|
3440
|
+
"ℹ️ Compat check not applicable for this model.",
|
|
3441
|
+
" Native Responses transports already use Pi core request handling; OpenAI-compatible proxy compat flags do not apply.",
|
|
3442
|
+
];
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
return ["ℹ️ Compat check not applicable for this model."];
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3408
3448
|
function buildDoctorDiagnosis(model: PiModel, options: { promptCacheRetention400?: boolean } = {}): string {
|
|
3409
3449
|
const lines: string[] = [];
|
|
3410
3450
|
lines.push(`Provider: ${model.provider}`);
|
|
@@ -3433,7 +3473,7 @@ function buildDoctorDiagnosis(model: PiModel, options: { promptCacheRetention400
|
|
|
3433
3473
|
} else if (deepSeekCompatApplicable || isCompatCheckApplicable(model)) {
|
|
3434
3474
|
lines.push("✅ Compat fully configured.");
|
|
3435
3475
|
} else {
|
|
3436
|
-
lines.push(
|
|
3476
|
+
lines.push(...getCompatCheckNotApplicableLines(model));
|
|
3437
3477
|
}
|
|
3438
3478
|
|
|
3439
3479
|
if (isPromptCacheRetention400Applicable(model)) {
|
|
@@ -3621,7 +3661,7 @@ function buildCompatDiagnosis(model: PiModel): string | undefined {
|
|
|
3621
3661
|
lines.push(getPromptCacheRetentionUnsupportedHint());
|
|
3622
3662
|
}
|
|
3623
3663
|
} else {
|
|
3624
|
-
lines.push(
|
|
3664
|
+
lines.push(...getCompatCheckNotApplicableLines(model));
|
|
3625
3665
|
}
|
|
3626
3666
|
lines.push("");
|
|
3627
3667
|
}
|
|
@@ -3658,6 +3698,9 @@ export const __internals_for_tests = {
|
|
|
3658
3698
|
isNonEmptyString,
|
|
3659
3699
|
shouldInjectOpenAIPromptCacheKey,
|
|
3660
3700
|
isOpenAICompatibleApi,
|
|
3701
|
+
isOpenAICompatibleProxyApi,
|
|
3702
|
+
isResponsesPromptRewriteBypassApi,
|
|
3703
|
+
isMistralConversationsApi,
|
|
3661
3704
|
isOpenAIFamilyModel,
|
|
3662
3705
|
isOpenAIFamilyAssistantMessage,
|
|
3663
3706
|
isOpenAIFamilyToken,
|
|
@@ -4130,7 +4173,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
4130
4173
|
|
|
4131
4174
|
pi.on("before_agent_start", async (event, _ctx) => {
|
|
4132
4175
|
// ────────────────────────────────────────────────────────────────
|
|
4133
|
-
// OpenAI Responses
|
|
4176
|
+
// OpenAI Responses-family bypass (codex-responses + responses + azure responses)
|
|
4134
4177
|
//
|
|
4135
4178
|
// OpenAI's Responses API endpoints — both the Codex backend
|
|
4136
4179
|
// (openai-codex-responses, chatgpt.com) and the public
|
|
@@ -4156,11 +4199,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
4156
4199
|
// that use openai-completions are unaffected.
|
|
4157
4200
|
// ────────────────────────────────────────────────────────────────
|
|
4158
4201
|
const model = _ctx.model;
|
|
4159
|
-
if (model) {
|
|
4160
|
-
|
|
4161
|
-
if (api === "openai-codex-responses" || api === "openai-responses") {
|
|
4162
|
-
return {};
|
|
4163
|
-
}
|
|
4202
|
+
if (model && isResponsesPromptRewriteBypassApi(model.api)) {
|
|
4203
|
+
return {};
|
|
4164
4204
|
}
|
|
4165
4205
|
|
|
4166
4206
|
if (!runtimeOptimizerEnabled) return {};
|
|
@@ -4342,7 +4382,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
4342
4382
|
cmdCtx.ui.notify(
|
|
4343
4383
|
isDeepSeekCompatCheckApplicable(model) || isCompatCheckApplicable(model)
|
|
4344
4384
|
? "✅ Compat fully configured."
|
|
4345
|
-
:
|
|
4385
|
+
: getCompatCheckNotApplicableLines(model).join("\n"),
|
|
4346
4386
|
"info",
|
|
4347
4387
|
);
|
|
4348
4388
|
}
|
|
@@ -4440,7 +4480,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
4440
4480
|
cmdCtx.ui.notify(
|
|
4441
4481
|
isDeepSeekCompatCheckApplicable(model) || isCompatCheckApplicable(model)
|
|
4442
4482
|
? "✅ Compat fully configured."
|
|
4443
|
-
:
|
|
4483
|
+
: getCompatCheckNotApplicableLines(model).join("\n"),
|
|
4444
4484
|
"info",
|
|
4445
4485
|
);
|
|
4446
4486
|
}
|
|
@@ -4493,6 +4533,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
4493
4533
|
diagnosis.push(`✅ Active model "${displayKey}": compat fully configured.`);
|
|
4494
4534
|
} else {
|
|
4495
4535
|
diagnosis.push(`ℹ️ Active model "${displayKey}": compat check not applicable.`);
|
|
4536
|
+
const detailLines = getCompatCheckNotApplicableLines(model).slice(1);
|
|
4537
|
+
for (const line of detailLines) diagnosis.push(line);
|
|
4496
4538
|
}
|
|
4497
4539
|
} else {
|
|
4498
4540
|
diagnosis.push("No active model selected.");
|
package/package.json
CHANGED