pi-openai-toolkit 0.21.1 → 0.22.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/LICENSE +21 -21
- package/NOTICE +83 -83
- package/README.md +8 -0
- package/README.zh.md +8 -0
- package/config.schema.json +278 -278
- package/docs/configuration.md +298 -298
- package/docs/internals.md +181 -166
- package/package.json +5 -1
- package/src/codex-fast/extension.ts +119 -0
- package/src/codex-fast/payload.ts +36 -0
- package/src/codex-fast/state.ts +25 -0
- package/src/compact-client.ts +412 -412
- package/src/compaction-projection.ts +35 -35
- package/src/config/migration.ts +103 -103
- package/src/config.ts +310 -310
- package/src/context-management/codex-provider.ts +270 -270
- package/src/context-management/history-notes.ts +357 -357
- package/src/context-management/tools.ts +371 -371
- package/src/context-management/types.ts +168 -168
- package/src/context-management/window-manager.ts +801 -801
- package/src/debug.ts +238 -238
- package/src/deferred-tool-carryover.ts +282 -282
- package/src/details-store.ts +151 -151
- package/src/extension-runtime.ts +1662 -1662
- package/src/image-generation/extension.ts +189 -189
- package/src/image-generation/protocol.ts +579 -579
- package/src/image-generation/types.ts +300 -300
- package/src/payload-rewrite.ts +515 -515
- package/src/pi-context-hook.ts +117 -117
- package/src/remote-v2-client.ts +811 -811
- package/src/request-context-cache.ts +155 -155
- package/src/responses-headers.ts +180 -180
- package/src/runtime.ts +865 -865
- package/src/serializer.ts +882 -882
- package/src/supported-environment.ts +27 -27
- package/src/types.ts +565 -565
- package/src/web-search/alpha-client.ts +876 -876
- package/src/web-search/extension.ts +530 -530
- package/src/web-search/payload.ts +299 -299
- package/src/web-search/prompt.ts +60 -60
- package/src/web-search/types.ts +166 -166
- package/tsconfig.check.json +50 -50
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { isExactModelAllowed } from "../model-scope";
|
|
3
|
+
|
|
4
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
5
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** This checks route identity, never backend entitlement or actual speed. */
|
|
9
|
+
export function isCodexFastModel(
|
|
10
|
+
model: ExtensionContext["model"],
|
|
11
|
+
gatewayModels: readonly string[] = [],
|
|
12
|
+
logicalModel?: ExtensionContext["model"],
|
|
13
|
+
): boolean {
|
|
14
|
+
if (!model || typeof model.id !== "string" || !model.id.trim()) return false;
|
|
15
|
+
if (model.api === "openai-codex-responses") return true;
|
|
16
|
+
if (model.api !== "openai-responses") return false;
|
|
17
|
+
try {
|
|
18
|
+
const url = new URL(model.baseUrl);
|
|
19
|
+
if (!["http:", "https:"].includes(url.protocol) || url.hostname.toLowerCase() === "api.openai.com") return false;
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return /^(?:gpt|codex)(?:-|$)/iu.test(model.id)
|
|
24
|
+
|| isExactModelAllowed(model, gatewayModels)
|
|
25
|
+
|| (logicalModel?.api === "pi-virtual" && isExactModelAllowed(logicalModel, gatewayModels));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Only ordinary matching conversation payloads are owned by the session switch. */
|
|
29
|
+
export function rewriteCodexFastPayload(payload: unknown, modelId: string, enabled: boolean): Record<string, unknown> | undefined {
|
|
30
|
+
if (!isRecord(payload) || payload.model !== modelId || !Array.isArray(payload.input)) return undefined;
|
|
31
|
+
if (!payload.input.every(isRecord)) return undefined;
|
|
32
|
+
if (payload.input.some((item) => item.type === "compaction_trigger")) return undefined;
|
|
33
|
+
if (Array.isArray(payload.tools) && payload.tools.some((tool) => isRecord(tool) && tool.type === "remote_compaction_v2")) return undefined;
|
|
34
|
+
const tier = enabled ? "priority" : "default";
|
|
35
|
+
return payload.service_tier === tier ? undefined : { ...payload, service_tier: tier };
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const CODEX_FAST_ENTRY_TYPE = "pi-openai-toolkit:codex-fast";
|
|
2
|
+
|
|
3
|
+
export type CodexFastState = {
|
|
4
|
+
version: 1;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
10
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Session metadata, not model input. Foreign fork/copy entries never apply. */
|
|
14
|
+
export function readCodexFastState(entries: readonly unknown[], sessionId: string | undefined): boolean {
|
|
15
|
+
if (!sessionId) return false;
|
|
16
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
17
|
+
const entry = entries[index];
|
|
18
|
+
if (!isRecord(entry) || entry.type !== "custom" || entry.customType !== CODEX_FAST_ENTRY_TYPE) continue;
|
|
19
|
+
const data = entry.data;
|
|
20
|
+
// A malformed latest preference must not resurrect an older ON.
|
|
21
|
+
if (!isRecord(data) || data.version !== 1 || typeof data.sessionId !== "string" || typeof data.enabled !== "boolean") return false;
|
|
22
|
+
if (data.sessionId === sessionId) return data.enabled;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|