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.
Files changed (53) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +83 -83
  3. package/README.md +4 -11
  4. package/README.zh.md +4 -11
  5. package/config.schema.json +264 -278
  6. package/docs/configuration.md +304 -298
  7. package/docs/internals.md +98 -181
  8. package/package.json +123 -135
  9. package/src/compact-client.ts +412 -412
  10. package/src/compaction-projection.ts +35 -35
  11. package/src/config/legacy.ts +12 -62
  12. package/src/config/migration.ts +115 -103
  13. package/src/config/notifications.ts +10 -4
  14. package/src/config/policy.ts +9 -10
  15. package/src/config/v2.ts +12 -51
  16. package/src/config.ts +320 -310
  17. package/src/debug.ts +238 -238
  18. package/src/deferred-tool-carryover.ts +282 -282
  19. package/src/details-store.ts +151 -151
  20. package/src/extension-runtime.ts +1095 -1986
  21. package/src/image-generation/extension.ts +189 -189
  22. package/src/image-generation/protocol.ts +579 -579
  23. package/src/image-generation/types.ts +300 -300
  24. package/src/native-fallback.ts +14 -23
  25. package/src/payload-rewrite.ts +515 -515
  26. package/src/pi-context-hook.ts +117 -117
  27. package/src/remote-v2-client.ts +811 -811
  28. package/src/request-context-cache.ts +155 -155
  29. package/src/responses-headers.ts +180 -180
  30. package/src/retired-remote-windows.ts +35 -0
  31. package/src/runtime.ts +875 -865
  32. package/src/serializer.ts +882 -882
  33. package/src/supported-environment.ts +27 -27
  34. package/src/types.ts +541 -565
  35. package/src/web-search/alpha-client.ts +876 -876
  36. package/src/web-search/extension.ts +530 -530
  37. package/src/web-search/payload.ts +299 -299
  38. package/src/web-search/prompt.ts +60 -60
  39. package/src/web-search/types.ts +166 -166
  40. package/tsconfig.check.json +50 -50
  41. package/src/context-management/codex-provider.ts +0 -270
  42. package/src/context-management/history-notes.ts +0 -357
  43. package/src/context-management/manual-compact.ts +0 -599
  44. package/src/context-management/messages.ts +0 -238
  45. package/src/context-management/namespace-tools.ts +0 -426
  46. package/src/context-management/responses-tools.ts +0 -238
  47. package/src/context-management/tool-contract.ts +0 -62
  48. package/src/context-management/tools.ts +0 -371
  49. package/src/context-management/types.ts +0 -168
  50. package/src/context-management/window-budget.ts +0 -83
  51. package/src/context-management/window-bulk.ts +0 -155
  52. package/src/context-management/window-manager.ts +0 -905
  53. package/src/context-management/window-request.ts +0 -125
@@ -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
- * Only the "resolved model differs from the current one" case is handled here: when the feature
65
- * is disabled, nothing is resolved, or it equals the current model, the caller returns undefined
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 (event.signal.aborted) {
122
+ if (!isCurrent()) {
132
123
  return { ok: false, reason: "aborted", modelSpec: spec };
133
124
  }
134
125
  if (!result.summary || result.summary.trim().length === 0) {