@benvargas/pi-openai-fast 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -26,6 +26,7 @@ pi -e npm:@benvargas/pi-openai-fast
26
26
  - `/fast status` reports the current fast-mode state.
27
27
  - `--fast` starts the session with fast mode enabled.
28
28
  - By default, fast mode persists across new pi sessions via a JSON config file.
29
+ - Startup state comes from the selected config file, not from resumed session/thread history.
29
30
 
30
31
  Example:
31
32
 
@@ -58,15 +59,15 @@ Default config:
58
59
  Settings:
59
60
 
60
61
  - `persistState`: when `true`, `/fast` writes the current on/off state to config so it resumes in new pi sessions. Default: `true`.
61
- - `active`: persisted fast-mode state used when `persistState` is enabled.
62
+ - `active`: persisted fast-mode state used on startup when `persistState` is enabled.
62
63
  - `supportedModels`: list of `provider/model-id` strings that should receive `service_tier=priority`.
63
64
 
64
- Project config overrides global config. If fast mode is enabled on a model that is not in `supportedModels`, the setting stays on but requests are left unchanged until you switch back to a configured model.
65
+ Project config overrides global config. `/fast on` and `/fast off` write to the selected config file, so if a project config exists the remembered state is project-specific. If fast mode is enabled on a model that is not in `supportedModels`, the setting stays on but requests are left unchanged until you switch back to a configured model.
65
66
 
66
67
  ## Notes
67
68
 
68
- - Fast mode still stores session state in the current session branch.
69
69
  - When `persistState` is enabled, the last `/fast` setting also carries across brand-new pi sessions.
70
+ - Resumed sessions do not override the config-backed startup state.
70
71
  - On configured models, fast mode maps to OpenAI `service_tier=priority`.
71
72
 
72
73
  ## Uninstall
@@ -1,3 +1,15 @@
1
+ /**
2
+ * OpenAI fast mode for pi.
3
+ *
4
+ * `/fast` and `--fast` toggle `service_tier=priority` for configured models.
5
+ * This extension does not change the selected model, thinking level, tools, or prompts.
6
+ *
7
+ * Startup state comes from `pi-openai-fast.json`, not resumed session history.
8
+ * Config precedence is project `.pi/extensions/pi-openai-fast.json` over
9
+ * global `~/.pi/agent/extensions/pi-openai-fast.json`.
10
+ *
11
+ * `supportedModels` controls which `provider/model-id` pairs receive the flag.
12
+ */
1
13
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
14
  import { homedir } from "node:os";
3
15
  import { dirname, join } from "node:path";
@@ -5,7 +17,6 @@ import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-age
5
17
 
6
18
  const FAST_COMMAND = "fast";
7
19
  const FAST_FLAG = "fast";
8
- const FAST_STATE_ENTRY = "pi-openai-fast.state";
9
20
  const FAST_CONFIG_BASENAME = "pi-openai-fast.json";
10
21
  const FAST_COMMAND_ARGS = ["on", "off", "status"] as const;
11
22
  const FAST_SERVICE_TIER = "priority";
@@ -121,24 +132,6 @@ function parseSupportedModels(value: unknown): FastSupportedModel[] | undefined
121
132
  return models;
122
133
  }
123
134
 
124
- function parseFastModeState(value: unknown): FastModeState | undefined {
125
- if (!isRecord(value) || typeof value.active !== "boolean") {
126
- return undefined;
127
- }
128
- return { active: value.active };
129
- }
130
-
131
- function getSavedFastModeState(ctx: ExtensionContext): FastModeState | undefined {
132
- const entries = ctx.sessionManager.getBranch();
133
- for (let i = entries.length - 1; i >= 0; i--) {
134
- const entry = entries[i];
135
- if (entry.type === "custom" && entry.customType === FAST_STATE_ENTRY) {
136
- return parseFastModeState(entry.data);
137
- }
138
- }
139
- return undefined;
140
- }
141
-
142
135
  function readConfigFile(filePath: string): FastConfigFile | null {
143
136
  if (!existsSync(filePath)) {
144
137
  return null;
@@ -251,9 +244,19 @@ function applyFastServiceTier(payload: unknown): unknown {
251
244
 
252
245
  export default function piOpenAIFast(pi: ExtensionAPI): void {
253
246
  let state: FastModeState = { active: false };
247
+ let cachedConfig: ResolvedFastConfig | undefined;
248
+
249
+ function refreshConfig(ctx: ExtensionContext): ResolvedFastConfig {
250
+ cachedConfig = resolveFastConfig(getConfigCwd(ctx));
251
+ return cachedConfig;
252
+ }
253
+
254
+ function getConfig(ctx: ExtensionContext): ResolvedFastConfig {
255
+ return cachedConfig ?? refreshConfig(ctx);
256
+ }
254
257
 
255
258
  function persistState(config: ResolvedFastConfig): void {
256
- pi.appendEntry(FAST_STATE_ENTRY, state);
259
+ cachedConfig = { ...config, active: state.active };
257
260
  if (!config.persistState) {
258
261
  return;
259
262
  }
@@ -262,7 +265,7 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
262
265
  }
263
266
 
264
267
  async function enableFastMode(ctx: ExtensionContext, options?: { notify?: boolean }): Promise<void> {
265
- const config = resolveFastConfig(getConfigCwd(ctx));
268
+ const config = refreshConfig(ctx);
266
269
  if (state.active) {
267
270
  if (options?.notify !== false) {
268
271
  ctx.ui.notify("Fast mode is already on.", "info");
@@ -279,7 +282,7 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
279
282
  }
280
283
 
281
284
  async function disableFastMode(ctx: ExtensionContext, options?: { notify?: boolean }): Promise<void> {
282
- const config = resolveFastConfig(getConfigCwd(ctx));
285
+ const config = refreshConfig(ctx);
283
286
  if (!state.active) {
284
287
  if (options?.notify !== false) {
285
288
  ctx.ui.notify("Fast mode is already off.", "info");
@@ -334,10 +337,7 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
334
337
  await disableFastMode(ctx);
335
338
  return;
336
339
  case "status":
337
- ctx.ui.notify(
338
- describeCurrentState(ctx, state.active, resolveFastConfig(getConfigCwd(ctx)).supportedModels),
339
- "info",
340
- );
340
+ ctx.ui.notify(describeCurrentState(ctx, state.active, refreshConfig(ctx).supportedModels), "info");
341
341
  return;
342
342
  default:
343
343
  ctx.ui.notify("Usage: /fast [on|off|status]", "error");
@@ -346,7 +346,7 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
346
346
  });
347
347
 
348
348
  pi.on("before_provider_request", (event, ctx) => {
349
- const config = resolveFastConfig(getConfigCwd(ctx));
349
+ const config = getConfig(ctx);
350
350
  if (!state.active || !isFastSupportedModel(ctx.model, config.supportedModels)) {
351
351
  return;
352
352
  }
@@ -354,11 +354,8 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
354
354
  });
355
355
 
356
356
  pi.on("session_start", async (_event, ctx) => {
357
- const config = resolveFastConfig(getConfigCwd(ctx));
358
- const savedState = getSavedFastModeState(ctx);
359
- const persistedState =
360
- config.persistState && typeof config.active === "boolean" ? { active: config.active } : undefined;
361
- state = savedState ?? persistedState ?? { active: false };
357
+ const config = refreshConfig(ctx);
358
+ state = config.persistState && typeof config.active === "boolean" ? { active: config.active } : { active: false };
362
359
 
363
360
  if (pi.getFlag(FAST_FLAG) === true) {
364
361
  if (!state.active) {
@@ -369,7 +366,7 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
369
366
  return;
370
367
  }
371
368
 
372
- if (!savedState && state.active) {
369
+ if (state.active) {
373
370
  ctx.ui.notify(describeCurrentState(ctx, state.active, config.supportedModels), "info");
374
371
  }
375
372
  });
@@ -378,14 +375,12 @@ export default function piOpenAIFast(pi: ExtensionAPI): void {
378
375
  export const _test = {
379
376
  FAST_COMMAND,
380
377
  FAST_FLAG,
381
- FAST_STATE_ENTRY,
382
378
  FAST_CONFIG_BASENAME,
383
379
  FAST_COMMAND_ARGS,
384
380
  FAST_SERVICE_TIER,
385
381
  DEFAULT_SUPPORTED_MODEL_KEYS,
386
382
  DEFAULT_CONFIG_FILE,
387
383
  getConfigPaths,
388
- parseFastModeState,
389
384
  parseSupportedModelKey,
390
385
  parseSupportedModels,
391
386
  readConfigFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benvargas/pi-openai-fast",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "OpenAI fast mode toggle for pi - Enables priority service tier on supported GPT-5.4 models",
5
5
  "keywords": [
6
6
  "pi",