pi-openai-toolkit 0.23.1 → 0.24.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 +4 -11
- package/README.zh.md +4 -11
- package/config.schema.json +264 -278
- package/docs/configuration.md +304 -298
- package/docs/internals.md +98 -181
- package/package.json +123 -135
- package/src/compact-client.ts +412 -412
- package/src/compaction-projection.ts +35 -35
- package/src/config/legacy.ts +12 -62
- package/src/config/migration.ts +115 -103
- package/src/config/notifications.ts +10 -4
- package/src/config/policy.ts +9 -10
- package/src/config/v2.ts +12 -51
- package/src/config.ts +320 -310
- 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 +1095 -1986
- 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/native-fallback.ts +14 -23
- 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/retired-remote-windows.ts +35 -0
- package/src/runtime.ts +875 -865
- package/src/serializer.ts +882 -882
- package/src/supported-environment.ts +27 -27
- package/src/types.ts +541 -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
- package/src/context-management/codex-provider.ts +0 -270
- package/src/context-management/history-notes.ts +0 -357
- package/src/context-management/manual-compact.ts +0 -599
- package/src/context-management/messages.ts +0 -238
- package/src/context-management/namespace-tools.ts +0 -426
- package/src/context-management/responses-tools.ts +0 -238
- package/src/context-management/tool-contract.ts +0 -62
- package/src/context-management/tools.ts +0 -371
- package/src/context-management/types.ts +0 -168
- package/src/context-management/window-budget.ts +0 -83
- package/src/context-management/window-bulk.ts +0 -155
- package/src/context-management/window-manager.ts +0 -905
- package/src/context-management/window-request.ts +0 -125
package/src/native-fallback.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type NativeFallbackResult =
|
|
|
39
39
|
export type NativeCompactFn = typeof compact;
|
|
40
40
|
|
|
41
41
|
type ResolvedAuth =
|
|
42
|
-
| { ok: true; apiKey?: string; headers?: ProviderHeaders; env?: Record<string, string> }
|
|
42
|
+
| { ok: true; apiKey?: string; headers?: ProviderHeaders; baseUrl?: string; env?: Record<string, string> }
|
|
43
43
|
| { ok: false; error: string };
|
|
44
44
|
|
|
45
45
|
function isAbortError(error: unknown): boolean {
|
|
@@ -61,10 +61,8 @@ function toErrorMessage(error: unknown): string {
|
|
|
61
61
|
* active model cannot use remote v2 at all. This function never inspects `remoteCompactModel`
|
|
62
62
|
* itself, so a model that cannot compact remotely can never inherit the remote producer.
|
|
63
63
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* from session_before_compact so pi runs the same native path itself, keeping its internal
|
|
67
|
-
* streamFn/thinkingLevel wiring.
|
|
64
|
+
* Unset or same-current-model defaults stay with Pi. This helper does not
|
|
65
|
+
* select a session model or take ownership of Pi's scheduler.
|
|
68
66
|
*/
|
|
69
67
|
export async function runNativeFallbackCompaction(args: {
|
|
70
68
|
ctx: ExtensionContext;
|
|
@@ -73,30 +71,22 @@ export async function runNativeFallbackCompaction(args: {
|
|
|
73
71
|
/** Model spec supplied by the caller for this specific fallback reason. */
|
|
74
72
|
modelSpec?: string;
|
|
75
73
|
compactFn?: NativeCompactFn;
|
|
74
|
+
/** Reject results if the originating session/branch/selection changed. */
|
|
75
|
+
isCurrent?: () => boolean;
|
|
76
76
|
}): Promise<NativeFallbackResult> {
|
|
77
77
|
const { ctx, event, config } = args;
|
|
78
78
|
const compactFn = args.compactFn ?? compact;
|
|
79
79
|
const nativeFallback = config.nativeFallback;
|
|
80
|
+
const isCurrent = () => !event.signal.aborted && (args.isCurrent?.() ?? true);
|
|
81
|
+
if (!isCurrent()) return { ok: false, reason: "aborted" };
|
|
80
82
|
|
|
81
|
-
if (!nativeFallback.enabled) {
|
|
82
|
-
return { ok: false, reason: "disabled" };
|
|
83
|
-
}
|
|
84
|
-
|
|
83
|
+
if (!nativeFallback.enabled) return { ok: false, reason: "disabled" };
|
|
85
84
|
const spec = args.modelSpec?.trim() ?? "";
|
|
86
|
-
if (!spec) {
|
|
87
|
-
return { ok: false, reason: "no-model-configured" };
|
|
88
|
-
}
|
|
89
|
-
|
|
85
|
+
if (!spec) return { ok: false, reason: "no-model-configured" };
|
|
90
86
|
const parsed = parseModelSpec(spec);
|
|
91
|
-
if (!parsed) {
|
|
92
|
-
return { ok: false, reason: "invalid-model-spec", modelSpec: spec };
|
|
93
|
-
}
|
|
94
|
-
|
|
87
|
+
if (!parsed) return { ok: false, reason: "invalid-model-spec", modelSpec: spec };
|
|
95
88
|
const model = ctx.modelRegistry.find(parsed.provider, parsed.modelId);
|
|
96
|
-
if (!model) {
|
|
97
|
-
return { ok: false, reason: "model-not-found", modelSpec: spec };
|
|
98
|
-
}
|
|
99
|
-
|
|
89
|
+
if (!model) return { ok: false, reason: "model-not-found", modelSpec: spec };
|
|
100
90
|
if (ctx.model && ctx.model.provider === model.provider && ctx.model.id === model.id) {
|
|
101
91
|
return { ok: false, reason: "same-as-current-model", modelSpec: spec };
|
|
102
92
|
}
|
|
@@ -115,10 +105,11 @@ export async function runNativeFallbackCompaction(args: {
|
|
|
115
105
|
return { ok: false, reason: "auth-failed", modelSpec: spec, errorMessage: auth.error };
|
|
116
106
|
}
|
|
117
107
|
|
|
108
|
+
if (!isCurrent()) return { ok: false, reason: "aborted", modelSpec: spec };
|
|
118
109
|
try {
|
|
119
110
|
const result = await compactFn(
|
|
120
111
|
event.preparation,
|
|
121
|
-
model,
|
|
112
|
+
auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model,
|
|
122
113
|
auth.apiKey,
|
|
123
114
|
mergeProviderHeaders(auth.headers),
|
|
124
115
|
event.customInstructions,
|
|
@@ -128,7 +119,7 @@ export async function runNativeFallbackCompaction(args: {
|
|
|
128
119
|
auth.env,
|
|
129
120
|
);
|
|
130
121
|
|
|
131
|
-
if (
|
|
122
|
+
if (!isCurrent()) {
|
|
132
123
|
return { ok: false, reason: "aborted", modelSpec: spec };
|
|
133
124
|
}
|
|
134
125
|
if (!result.summary || result.summary.trim().length === 0) {
|