pi-openai-toolkit 0.11.1 → 0.13.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/package.json CHANGED
@@ -1,114 +1,126 @@
1
- {
2
- "name": "pi-openai-toolkit",
3
- "version": "0.11.1",
4
- "private": false,
5
- "type": "module",
6
- "description": "OpenAI-focused Pi toolkit providing remote Responses compaction, native Web Search, native image generation, and model-reviewed auto mode.",
7
- "author": "awoaCrim and contributors",
8
- "license": "MIT",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/awoaCrim/pi-openai-toolkit.git"
12
- },
13
- "bugs": {
14
- "url": "https://github.com/awoaCrim/pi-openai-toolkit/issues"
15
- },
16
- "homepage": "https://github.com/awoaCrim/pi-openai-toolkit#readme",
17
- "publishConfig": {
18
- "access": "public",
19
- "registry": "https://registry.npmjs.org/"
20
- },
21
- "keywords": [
22
- "pi-package",
23
- "pi-extension",
24
- "openai",
25
- "compaction",
26
- "web-search",
27
- "image-generation",
28
- "auto-mode",
29
- "codex",
30
- "responses"
31
- ],
32
- "pi": {
33
- "extensions": [
34
- "./extensions/compaction.ts",
35
- "./extensions/web-search.ts",
36
- "./extensions/image-generation.ts",
37
- "./extensions/auto-mode.ts",
38
- "./extensions/codex-astra.ts"
39
- ]
40
- },
41
- "files": [
42
- "extensions/compaction.ts",
43
- "extensions/web-search.ts",
44
- "extensions/image-generation.ts",
45
- "extensions/auto-mode.ts",
46
- "src/compact-client.ts",
47
- "src/config.ts",
48
- "src/debug.ts",
49
- "src/details-store.ts",
50
- "src/deferred-tool-carryover.ts",
51
- "src/inline-compaction.ts",
52
- "src/extension-runtime.ts",
53
- "src/image-generation/artifacts.ts",
54
- "src/image-generation/client.ts",
55
- "src/image-generation/eligibility.ts",
56
- "src/image-generation/extension.ts",
57
- "src/image-generation/protocol.ts",
58
- "src/image-generation/references.ts",
59
- "src/image-generation/render.ts",
60
- "src/image-generation/service.ts",
61
- "src/image-generation/types.ts",
62
- "src/auto-mode/extension.ts",
63
- "src/auto-mode/policy.ts",
64
- "src/auto-mode/prompt.ts",
65
- "src/auto-mode/transcript.ts",
66
- "src/auto-mode/reviewer.ts",
67
- "src/auto-mode/classifier.ts",
68
- "src/auto-mode/types.ts",
69
- "extensions/codex-astra.ts",
70
- "src/codex-astra/effort-planner.ts",
71
- "src/codex-astra/extension.ts",
72
- "src/model-scope.ts",
73
- "src/native-fallback.ts",
74
- "src/payload-rewrite.ts",
75
- "src/provider-headers.ts",
76
- "src/responses-headers.ts",
77
- "src/remote-v2-client.ts",
78
- "src/request-context-cache.ts",
79
- "src/runtime.ts",
80
- "src/serializer.ts",
81
- "src/supported-environment.ts",
82
- "src/types.ts",
83
- "src/web-search/extension.ts",
84
- "src/web-search/payload.ts",
85
- "src/web-search/prompt.ts",
86
- "src/web-search/types.ts",
87
- "README.md",
88
- "README_zh.md",
89
- "LICENSE",
90
- "NOTICE",
91
- "tsconfig.check.json"
92
- ],
93
- "scripts": {
94
- "test": "bun test",
95
- "test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov && node ./scripts/check-lcov.mjs ./coverage/lcov.info",
96
- "test:pi": "bun test ./test/pi-smoke.test.ts",
97
- "typecheck": "tsc -p tsconfig.check.json"
98
- },
99
- "peerDependencies": {
100
- "@earendil-works/pi-agent-core": "*",
101
- "@earendil-works/pi-ai": "*",
102
- "@earendil-works/pi-coding-agent": ">=0.80.0",
103
- "@earendil-works/pi-tui": ">=0.80.0"
104
- },
105
- "devDependencies": {
106
- "@earendil-works/pi-agent-core": "0.84.3",
107
- "@earendil-works/pi-ai": "0.84.3",
108
- "@earendil-works/pi-coding-agent": "0.84.3",
109
- "@earendil-works/pi-tui": "0.84.3",
110
- "@types/node": "24.12.4",
111
- "bun": "1.2.23",
112
- "typescript": "5.9.3"
113
- }
114
- }
1
+ {
2
+ "name": "pi-openai-toolkit",
3
+ "version": "0.13.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=22.19.0"
8
+ },
9
+ "description": "OpenAI-focused Pi toolkit providing remote Responses compaction, native Web Search, native image generation, and model-reviewed auto mode.",
10
+ "author": "awoaCrim and contributors",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/awoaCrim/pi-openai-toolkit.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/awoaCrim/pi-openai-toolkit/issues"
18
+ },
19
+ "homepage": "https://github.com/awoaCrim/pi-openai-toolkit#readme",
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "registry": "https://registry.npmjs.org/"
23
+ },
24
+ "keywords": [
25
+ "pi-package",
26
+ "pi-extension",
27
+ "openai",
28
+ "compaction",
29
+ "web-search",
30
+ "image-generation",
31
+ "auto-mode",
32
+ "codex",
33
+ "responses"
34
+ ],
35
+ "pi": {
36
+ "extensions": [
37
+ "./extensions/compaction.ts",
38
+ "./extensions/web-search.ts",
39
+ "./extensions/image-generation.ts",
40
+ "./extensions/auto-mode.ts",
41
+ "./extensions/codex-astra.ts"
42
+ ]
43
+ },
44
+ "files": [
45
+ "extensions/compaction.ts",
46
+ "extensions/web-search.ts",
47
+ "extensions/image-generation.ts",
48
+ "extensions/auto-mode.ts",
49
+ "src/compact-client.ts",
50
+ "src/config.ts",
51
+ "src/debug.ts",
52
+ "src/details-store.ts",
53
+ "src/deferred-tool-carryover.ts",
54
+ "src/extension-runtime.ts",
55
+ "src/context-management/types.ts",
56
+ "src/context-management/messages.ts",
57
+ "src/context-management/window-budget.ts",
58
+ "src/context-management/window-request.ts",
59
+ "src/context-management/window-manager.ts",
60
+ "src/context-management/codex-provider.ts",
61
+ "src/context-management/history-notes.ts",
62
+ "src/context-management/tools.ts",
63
+ "src/context-management/namespace-tools.ts",
64
+ "src/context-management/tool-contract.ts",
65
+ "src/image-generation/artifacts.ts",
66
+ "src/image-generation/client.ts",
67
+ "src/image-generation/eligibility.ts",
68
+ "src/image-generation/extension.ts",
69
+ "src/image-generation/protocol.ts",
70
+ "src/image-generation/references.ts",
71
+ "src/image-generation/render.ts",
72
+ "src/image-generation/service.ts",
73
+ "src/image-generation/types.ts",
74
+ "src/auto-mode/extension.ts",
75
+ "src/auto-mode/policy.ts",
76
+ "src/auto-mode/prompt.ts",
77
+ "src/auto-mode/transcript.ts",
78
+ "src/auto-mode/reviewer.ts",
79
+ "src/auto-mode/classifier.ts",
80
+ "src/auto-mode/types.ts",
81
+ "extensions/codex-astra.ts",
82
+ "src/codex-astra/effort-planner.ts",
83
+ "src/codex-astra/extension.ts",
84
+ "src/model-scope.ts",
85
+ "src/native-fallback.ts",
86
+ "src/payload-rewrite.ts",
87
+ "src/provider-headers.ts",
88
+ "src/responses-headers.ts",
89
+ "src/remote-v2-client.ts",
90
+ "src/request-context-cache.ts",
91
+ "src/runtime.ts",
92
+ "src/serializer.ts",
93
+ "src/supported-environment.ts",
94
+ "src/types.ts",
95
+ "src/web-search/extension.ts",
96
+ "src/web-search/payload.ts",
97
+ "src/web-search/prompt.ts",
98
+ "src/web-search/types.ts",
99
+ "README.md",
100
+ "README_zh.md",
101
+ "LICENSE",
102
+ "NOTICE",
103
+ "tsconfig.check.json"
104
+ ],
105
+ "scripts": {
106
+ "test": "bun test",
107
+ "test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov && node ./scripts/check-lcov.mjs ./coverage/lcov.info",
108
+ "test:pi": "bun test ./test/pi-smoke.test.ts",
109
+ "typecheck": "tsc -p tsconfig.check.json"
110
+ },
111
+ "peerDependencies": {
112
+ "@earendil-works/pi-agent-core": ">=0.85.1",
113
+ "@earendil-works/pi-ai": ">=0.85.1",
114
+ "@earendil-works/pi-coding-agent": ">=0.85.1",
115
+ "@earendil-works/pi-tui": ">=0.85.1"
116
+ },
117
+ "devDependencies": {
118
+ "@earendil-works/pi-agent-core": "0.85.1",
119
+ "@earendil-works/pi-ai": "0.85.1",
120
+ "@earendil-works/pi-coding-agent": "0.85.1",
121
+ "@earendil-works/pi-tui": "0.85.1",
122
+ "@types/node": "24.12.4",
123
+ "bun": "1.2.23",
124
+ "typescript": "5.9.3"
125
+ }
126
+ }
package/src/config.ts CHANGED
@@ -5,7 +5,6 @@ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
5
5
  import {
6
6
  DEFAULT_COMPACTION_CONFIG,
7
7
  DEFAULT_TOOLKIT_CONFIG,
8
- DEFAULT_AUTO_COMPACTION_CONFIG,
9
8
  DEFAULT_AUTO_MODE_CONFIG,
10
9
  DEFAULT_IMAGE_GENERATION_CONFIG,
11
10
  DEFAULT_CODEX_ASTRA_CONFIG,
@@ -31,6 +30,7 @@ import {
31
30
  type AutoModeGate,
32
31
  type CodexAstraConfig,
33
32
  type CompactionConfig,
33
+ type ContextManagementMode,
34
34
  type ImageGenerationConfig,
35
35
  type LoadedToolkitConfig,
36
36
  type NativeFallbackConfig,
@@ -44,11 +44,13 @@ export const CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
44
44
  const TOP_LEVEL_FIELDS = new Set(["compaction", "webSearch", "imageGeneration", "autoMode", "codexAstra"]);
45
45
  const COMPACTION_FIELDS = new Set([
46
46
  "enabled",
47
+ "contextManagement",
48
+ "codexGatewayModels",
47
49
  "allowCompactionContinuityBreak",
48
50
  "remoteCompactModel",
49
51
  "nativeFallback",
50
- "autoCompaction",
51
52
  "responsesApis",
53
+ "contextReminderThresholdPercent",
52
54
  "notifyOnLoad",
53
55
  "debug",
54
56
  "logProviderPayloads",
@@ -57,7 +59,6 @@ const COMPACTION_FIELDS = new Set([
57
59
  "artifactRoot",
58
60
  ]);
59
61
  const NATIVE_FALLBACK_FIELDS = new Set(["enabled", "model", "thinkingLevel"]);
60
- const AUTO_COMPACTION_FIELDS = new Set(["enabled", "continuation", "unsupportedFallback", "reserveTokens"]);
61
62
  const WEB_SEARCH_FIELDS = new Set(["enabled", "models"]);
62
63
  const IMAGE_GENERATION_FIELDS = new Set(["enabled"]);
63
64
  const CODEX_ASTRA_FIELDS = new Set(["enabled", "models"]);
@@ -134,6 +135,20 @@ function toBoolean(value: unknown, fieldPath: string, warnings: string[]): boole
134
135
  return undefined;
135
136
  }
136
137
 
138
+ function toContextManagementMode(
139
+ value: unknown,
140
+ fieldPath: string,
141
+ warnings: string[],
142
+ ): ContextManagementMode | undefined {
143
+ if (value === undefined) return undefined;
144
+ if (typeof value === "string") {
145
+ const normalized = value.trim();
146
+ if (normalized === "off" || normalized === "remote") return normalized;
147
+ }
148
+ warnings.push(`Ignoring ${fieldPath}: expected one of off, remote.`);
149
+ return undefined;
150
+ }
151
+
137
152
  function toModelSpec(value: unknown, fieldPath: string, warnings: string[]): string | null | undefined {
138
153
  if (value === undefined) return undefined;
139
154
  if (value === null) return null;
@@ -153,37 +168,6 @@ function toThinkingLevel(value: unknown, fieldPath: string, warnings: string[]):
153
168
  return undefined;
154
169
  }
155
170
 
156
- function toCompactionContinuation(
157
- value: unknown,
158
- fieldPath: string,
159
- warnings: string[],
160
- ): "inline" | "followUp" | "off" | undefined {
161
- if (value === undefined) return undefined;
162
- if (value === "inline" || value === "followUp" || value === "off") return value;
163
- warnings.push(`Ignoring ${fieldPath}: expected one of inline, followUp, off.`);
164
- return undefined;
165
- }
166
-
167
- function toUnsupportedFallback(
168
- value: unknown,
169
- fieldPath: string,
170
- warnings: string[],
171
- ): "followUp" | "off" | undefined {
172
- if (value === undefined) return undefined;
173
- if (value === "followUp" || value === "off") return value;
174
- warnings.push(`Ignoring ${fieldPath}: expected one of followUp, off.`);
175
- return undefined;
176
- }
177
-
178
- function toNonNegativeInteger(value: unknown, fieldPath: string, warnings: string[]): number | undefined {
179
- if (value === undefined) return undefined;
180
- if (typeof value === "number" && Number.isInteger(value) && Number.isFinite(value) && value >= 0) {
181
- return value;
182
- }
183
- warnings.push(`Ignoring ${fieldPath}: expected a non-negative integer.`);
184
- return undefined;
185
- }
186
-
187
171
  function toBoundedInteger(
188
172
  value: unknown,
189
173
  fieldPath: string,
@@ -264,7 +248,6 @@ function cloneDefaults(): ToolkitConfig {
264
248
  compaction: {
265
249
  ...DEFAULT_COMPACTION_CONFIG,
266
250
  nativeFallback: { ...DEFAULT_NATIVE_FALLBACK_CONFIG },
267
- autoCompaction: { ...DEFAULT_AUTO_COMPACTION_CONFIG },
268
251
  responsesApis: [...DEFAULT_COMPACTION_CONFIG.responsesApis],
269
252
  },
270
253
  webSearch: {
@@ -305,32 +288,6 @@ function applyNativeFallbackConfig(
305
288
  resolved.thinkingLevel;
306
289
  }
307
290
 
308
- function applyAutoCompactionConfig(
309
- raw: Record<string, unknown>,
310
- resolved: CompactionConfig["autoCompaction"],
311
- warnings: string[],
312
- ): void {
313
- warnUnknownFields(raw, AUTO_COMPACTION_FIELDS, "compaction.autoCompaction", warnings);
314
- resolved.enabled = toBoolean(raw.enabled, "compaction.autoCompaction.enabled", warnings) ?? resolved.enabled;
315
- resolved.continuation =
316
- toCompactionContinuation(raw.continuation, "compaction.autoCompaction.continuation", warnings) ??
317
- resolved.continuation;
318
- resolved.unsupportedFallback =
319
- toUnsupportedFallback(
320
- raw.unsupportedFallback,
321
- "compaction.autoCompaction.unsupportedFallback",
322
- warnings,
323
- ) ?? resolved.unsupportedFallback;
324
- const reserveTokens = toNonNegativeInteger(
325
- raw.reserveTokens,
326
- "compaction.autoCompaction.reserveTokens",
327
- warnings,
328
- );
329
- if (reserveTokens !== undefined) {
330
- resolved.reserveTokens = reserveTokens;
331
- }
332
- }
333
-
334
291
  function applyCompactionConfig(
335
292
  raw: Record<string, unknown>,
336
293
  resolved: CompactionConfig,
@@ -339,6 +296,17 @@ function applyCompactionConfig(
339
296
  warnUnknownFields(raw, COMPACTION_FIELDS, "compaction", warnings);
340
297
 
341
298
  resolved.enabled = toBoolean(raw.enabled, "compaction.enabled", warnings) ?? resolved.enabled;
299
+ resolved.contextManagement =
300
+ toContextManagementMode(raw.contextManagement, "compaction.contextManagement", warnings) ??
301
+ resolved.contextManagement;
302
+ const codexGatewayModels = toStringList(
303
+ raw.codexGatewayModels,
304
+ "compaction.codexGatewayModels",
305
+ warnings,
306
+ );
307
+ if (codexGatewayModels !== undefined) {
308
+ resolved.codexGatewayModels = codexGatewayModels;
309
+ }
342
310
  resolved.allowCompactionContinuityBreak =
343
311
  toBoolean(
344
312
  raw.allowCompactionContinuityBreak,
@@ -347,6 +315,16 @@ function applyCompactionConfig(
347
315
  ) ?? resolved.allowCompactionContinuityBreak;
348
316
  resolved.notifyOnLoad =
349
317
  toBoolean(raw.notifyOnLoad, "compaction.notifyOnLoad", warnings) ?? resolved.notifyOnLoad;
318
+ const reminderPercent = toBoundedInteger(
319
+ raw.contextReminderThresholdPercent,
320
+ "compaction.contextReminderThresholdPercent",
321
+ warnings,
322
+ 0,
323
+ 100,
324
+ );
325
+ if (reminderPercent !== undefined) {
326
+ resolved.contextReminderThresholdPercent = reminderPercent;
327
+ }
350
328
  resolved.debug = toBoolean(raw.debug, "compaction.debug", warnings) ?? resolved.debug;
351
329
  resolved.logProviderPayloads =
352
330
  toBoolean(raw.logProviderPayloads, "compaction.logProviderPayloads", warnings) ??
@@ -375,14 +353,6 @@ function applyCompactionConfig(
375
353
  }
376
354
  }
377
355
 
378
- if (raw.autoCompaction !== undefined) {
379
- if (isRecord(raw.autoCompaction)) {
380
- applyAutoCompactionConfig(raw.autoCompaction, resolved.autoCompaction, warnings);
381
- } else {
382
- warnings.push("Ignoring compaction.autoCompaction: expected a JSON object.");
383
- }
384
- }
385
-
386
356
  const apis = toSupportedApis(
387
357
  raw.responsesApis,
388
358
  "compaction.responsesApis",