pi-service-tier 0.6.0 → 0.7.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/README.md +52 -14
- package/config.ts +41 -0
- package/domain.ts +21 -3
- package/package.json +1 -1
- package/service-tier.ts +74 -8
package/README.md
CHANGED
|
@@ -21,26 +21,28 @@ pi install npm:pi-service-tier
|
|
|
21
21
|
|
|
22
22
|
## 🚀 Commands
|
|
23
23
|
|
|
24
|
-
- `/fast`: toggles the current model provider between its fast tier and off
|
|
24
|
+
- `/fast`: toggles the current model's provider between its fast tier and off
|
|
25
25
|
**in this session**, without changing other sessions or your global defaults.
|
|
26
26
|
The supported providers all use `priority` as the fast tier.
|
|
27
27
|
|
|
28
28
|
- `/ultrafast`: toggles between `ultrafast` and off **in this session** for
|
|
29
|
-
`openai` and `openai-codex
|
|
30
|
-
|
|
29
|
+
`openai` and `openai-codex` (including additional accounts on their official
|
|
30
|
+
endpoints). It uses the same provider override as `/fast`, so selecting a
|
|
31
|
+
different speed replaces the active tier.
|
|
31
32
|
|
|
32
33
|
- `/service-tier`: opens an interactive editor for **global defaults**. The
|
|
33
|
-
current model provider appears first, followed by the remaining supported
|
|
34
|
+
current model's provider appears first, followed by the remaining supported
|
|
34
35
|
providers. Press Enter or Space to cycle through `off` and the provider-specific
|
|
35
36
|
tiers. Session overrides take precedence over these defaults.
|
|
36
37
|
|
|
37
38
|
### Session scope
|
|
38
39
|
|
|
39
40
|
To speed up a session, run `/fast` or `/ultrafast`. Run the same command again to
|
|
40
|
-
turn that mode off. Each provider has
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
turn that mode off. Each supported provider has one override (shared with any
|
|
42
|
+
additional accounts for that provider), so switching models preserves your
|
|
43
|
+
choices. Turning either mode off disables this extension's tier injection, even
|
|
44
|
+
if a global tier is configured. The command leaves other request parameters
|
|
45
|
+
unchanged.
|
|
44
46
|
|
|
45
47
|
| Current tier | `/fast` | `/ultrafast` |
|
|
46
48
|
| ------------- | ---------- | ------------ |
|
|
@@ -48,14 +50,15 @@ parameters unchanged.
|
|
|
48
50
|
| `priority` | Off | `ultrafast` |
|
|
49
51
|
| `ultrafast` | `priority` | Off |
|
|
50
52
|
|
|
51
|
-
Both commands remain listed on all providers.
|
|
52
|
-
produces a warning without changing settings.
|
|
53
|
+
Both commands remain listed on all providers. Running them on an unsupported
|
|
54
|
+
model produces a warning without changing settings.
|
|
53
55
|
|
|
54
56
|
Overrides are saved with the session and restored on resume or extension reload.
|
|
55
57
|
They follow the active conversation branch: `/tree` restores the choices at the
|
|
56
58
|
selected point, and `/fork` or `/clone` inherits the choices on the copied branch.
|
|
57
59
|
Later toggles in a fork do not affect its parent. `/new` starts without overrides
|
|
58
|
-
and uses your
|
|
60
|
+
and uses your process defaults (`--service-tier` if passed, otherwise your global
|
|
61
|
+
defaults).
|
|
59
62
|
|
|
60
63
|
### Ultrafast availability
|
|
61
64
|
|
|
@@ -76,7 +79,8 @@ With [pi-agents](https://github.com/mavam/pi-agents) 0.36.0 or later, which
|
|
|
76
79
|
provides [agent extension hooks](https://github.com/mavam/pi-agents/blob/main/docs/hooks.md),
|
|
77
80
|
new agents capture your effective service-tier settings, including session
|
|
78
81
|
`/fast` and `/ultrafast` overrides. Each child applies the settings for its own
|
|
79
|
-
provider
|
|
82
|
+
provider, even when it uses a different model or additional account from the
|
|
83
|
+
parent.
|
|
80
84
|
|
|
81
85
|
For example, enable `/fast`, then ask Pi to spawn an agent. That agent keeps
|
|
82
86
|
its captured settings if you toggle `/fast` again. Graph nodes capture when
|
|
@@ -102,6 +106,24 @@ Run `/service-tier` or create `~/.pi/agent/service-tier.json` to set global defa
|
|
|
102
106
|
}
|
|
103
107
|
```
|
|
104
108
|
|
|
109
|
+
### Per-process defaults
|
|
110
|
+
|
|
111
|
+
`--service-tier` replaces `~/.pi/agent/service-tier.json` for one Pi process,
|
|
112
|
+
for example in a scripted `pi -p` run or a subprocess launcher:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
pi --service-tier=off
|
|
116
|
+
pi --service-tier=openai-codex:priority,anthropic:standard
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`off` disables every provider. Otherwise, list `provider:tier` pairs; any
|
|
120
|
+
omitted provider stays off instead of inheriting from `service-tier.json`.
|
|
121
|
+
Session `/fast` and `/ultrafast` overrides still take precedence and are saved
|
|
122
|
+
without the flag's values, so reopening the session without `--service-tier`
|
|
123
|
+
uses `service-tier.json` again. Agents created with `pi-agents` capture these
|
|
124
|
+
process defaults too. An invalid value warns once, disables all tiers for the
|
|
125
|
+
process, and blocks `/fast` and `/ultrafast` toggles.
|
|
126
|
+
|
|
105
127
|
### Supported providers
|
|
106
128
|
|
|
107
129
|
| Provider | Tiers | Fast tier |
|
|
@@ -113,14 +135,30 @@ Run `/service-tier` or create `~/.pi/agent/service-tier.json` to set global defa
|
|
|
113
135
|
| `google-vertex` | `flex`, `priority` | `priority` |
|
|
114
136
|
|
|
115
137
|
To turn a provider off by default, omit its key. Only the values listed above are
|
|
116
|
-
accepted. Providers without a session override continue to pick up global changes
|
|
138
|
+
accepted. Providers without a session override continue to pick up global changes
|
|
139
|
+
unless the process was started with `--service-tier`.
|
|
117
140
|
Batch APIs are separate asynchronous APIs and are not configured by this
|
|
118
141
|
extension.
|
|
119
142
|
|
|
143
|
+
### Additional accounts
|
|
144
|
+
|
|
145
|
+
Accounts registered under another provider name, such as
|
|
146
|
+
[pi-multi-pass](https://github.com/hjanuschka/pi-multi-pass)'s `anthropic-2` or
|
|
147
|
+
`openai-codex-2`, share the service-tier settings of the built-in provider whose
|
|
148
|
+
API and official endpoint they use. `/fast`, `/ultrafast`, `/service-tier`,
|
|
149
|
+
child agents, and the footer widget all share that provider's setting rather
|
|
150
|
+
than storing a separate entry per account.
|
|
151
|
+
|
|
152
|
+
Account matching requires the exact API and `baseUrl` of Pi's built-in provider
|
|
153
|
+
(for example `https://api.anthropic.com` with no trailing slash or port, or
|
|
154
|
+
`https://{location}-aiplatform.googleapis.com` for `google-vertex`). Other
|
|
155
|
+
spellings and third-party proxies speaking a supported API are not matched and
|
|
156
|
+
receive no service tier.
|
|
157
|
+
|
|
120
158
|
## 🧩 Footer widget
|
|
121
159
|
|
|
122
160
|
When [pi-fancy-footer](https://github.com/mavam/pi-fancy-footer) is installed,
|
|
123
|
-
the widget appears only when the active model
|
|
161
|
+
the widget appears only when the active model resolves to a supported provider
|
|
124
162
|
and that provider has an effective tier after applying session overrides. It shows
|
|
125
163
|
`⚡⚡` for ultrafast or a single `⚡` for another active tier, without the tier
|
|
126
164
|
name. The bolts indicate the requested tier; they do not confirm which tier the
|
package/config.ts
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
SERVICE_TIER_PROVIDERS,
|
|
10
10
|
SERVICE_TIER_PROVIDER_DEFINITIONS,
|
|
11
11
|
isRecord,
|
|
12
|
+
isServiceTierName,
|
|
13
|
+
isServiceTierProvider,
|
|
12
14
|
type ServiceTierConfigSnapshot,
|
|
13
15
|
type ServiceTierName,
|
|
14
16
|
type ServiceTierProvider,
|
|
@@ -109,3 +111,42 @@ export function writeServiceTierConfigSnapshot(
|
|
|
109
111
|
mkdirSync(dirname(configPath), { recursive: true });
|
|
110
112
|
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
111
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parse `--service-tier`: `off` leaves every provider off; otherwise a
|
|
117
|
+
* comma-separated list of `provider:tier` pairs replacing global defaults.
|
|
118
|
+
*/
|
|
119
|
+
export function parseServiceTierFlag(value: string): ServiceTierConfigSnapshot {
|
|
120
|
+
const trimmed = value.trim();
|
|
121
|
+
if (trimmed === "off") return { ...DEFAULT_SERVICE_TIER_CONFIG };
|
|
122
|
+
|
|
123
|
+
const config: ServiceTierConfigSnapshot = {};
|
|
124
|
+
for (const rawItem of trimmed.split(",")) {
|
|
125
|
+
const item = rawItem.trim();
|
|
126
|
+
const parts = item.split(":");
|
|
127
|
+
if (parts.length !== 2) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`--service-tier: expected off or provider:tier pairs, got "${item}"`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
const provider = parts[0].trim();
|
|
133
|
+
const serviceTier = parts[1].trim();
|
|
134
|
+
if (!isServiceTierProvider(provider)) {
|
|
135
|
+
throw new Error(`--service-tier: unknown provider "${provider}"`);
|
|
136
|
+
}
|
|
137
|
+
if (provider in config) {
|
|
138
|
+
throw new Error(`--service-tier: ${provider} is set more than once`);
|
|
139
|
+
}
|
|
140
|
+
if (!isServiceTierName(provider, serviceTier)) {
|
|
141
|
+
const hint =
|
|
142
|
+
serviceTier === "off"
|
|
143
|
+
? " (omit providers to leave them off, or use --service-tier=off)"
|
|
144
|
+
: "";
|
|
145
|
+
throw new Error(
|
|
146
|
+
`--service-tier: ${provider} has no service tier "${serviceTier}"${hint}`,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
config[provider] = serviceTier;
|
|
150
|
+
}
|
|
151
|
+
return config;
|
|
152
|
+
}
|
package/domain.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type ServiceTierSettings = Readonly<
|
|
|
25
25
|
export interface ServiceTierModel {
|
|
26
26
|
readonly provider?: unknown;
|
|
27
27
|
readonly api?: unknown;
|
|
28
|
+
readonly baseUrl?: unknown;
|
|
28
29
|
readonly id?: unknown;
|
|
29
30
|
readonly name?: unknown;
|
|
30
31
|
}
|
|
@@ -39,6 +40,8 @@ export const DEFAULT_SERVICE_TIER_CONFIG: ServiceTierConfigSnapshot = {};
|
|
|
39
40
|
export interface ServiceTierProviderDefinition {
|
|
40
41
|
label: string;
|
|
41
42
|
api: string;
|
|
43
|
+
/** Exact built-in endpoint; matched literally with `api` for account aliases. */
|
|
44
|
+
baseUrl: string;
|
|
42
45
|
tiers: readonly ServiceTier[];
|
|
43
46
|
fastTier?: ServiceTierName;
|
|
44
47
|
ultrafastTier?: ServiceTierName;
|
|
@@ -55,6 +58,7 @@ export const SERVICE_TIER_PROVIDER_DEFINITIONS: Record<
|
|
|
55
58
|
openai: {
|
|
56
59
|
label: "OpenAI",
|
|
57
60
|
api: "openai-responses",
|
|
61
|
+
baseUrl: "https://api.openai.com/v1",
|
|
58
62
|
tiers: [tier("flex"), tier("priority"), tier("ultrafast")],
|
|
59
63
|
fastTier: "priority",
|
|
60
64
|
ultrafastTier: "ultrafast",
|
|
@@ -62,6 +66,7 @@ export const SERVICE_TIER_PROVIDER_DEFINITIONS: Record<
|
|
|
62
66
|
"openai-codex": {
|
|
63
67
|
label: "OpenAI Codex",
|
|
64
68
|
api: "openai-codex-responses",
|
|
69
|
+
baseUrl: "https://chatgpt.com/backend-api",
|
|
65
70
|
tiers: [tier("flex"), tier("priority"), tier("ultrafast")],
|
|
66
71
|
fastTier: "priority",
|
|
67
72
|
ultrafastTier: "ultrafast",
|
|
@@ -69,18 +74,21 @@ export const SERVICE_TIER_PROVIDER_DEFINITIONS: Record<
|
|
|
69
74
|
anthropic: {
|
|
70
75
|
label: "Anthropic",
|
|
71
76
|
api: "anthropic-messages",
|
|
77
|
+
baseUrl: "https://api.anthropic.com",
|
|
72
78
|
tiers: [tier("priority", "auto"), tier("standard", "standard_only")],
|
|
73
79
|
fastTier: "priority",
|
|
74
80
|
},
|
|
75
81
|
google: {
|
|
76
82
|
label: "Google Gemini",
|
|
77
83
|
api: "google-generative-ai",
|
|
84
|
+
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
|
|
78
85
|
tiers: [tier("flex"), tier("priority")],
|
|
79
86
|
fastTier: "priority",
|
|
80
87
|
},
|
|
81
88
|
"google-vertex": {
|
|
82
89
|
label: "Google Vertex AI",
|
|
83
90
|
api: "google-vertex",
|
|
91
|
+
baseUrl: "https://{location}-aiplatform.googleapis.com",
|
|
84
92
|
tiers: [tier("flex"), tier("priority")],
|
|
85
93
|
fastTier: "priority",
|
|
86
94
|
},
|
|
@@ -117,9 +125,19 @@ export function modelSupportsServiceTier(
|
|
|
117
125
|
export function getServiceTierProviderForModel(
|
|
118
126
|
model: ServiceTierModel | undefined,
|
|
119
127
|
): ServiceTierProvider | undefined {
|
|
120
|
-
if (!model
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
if (!model) return undefined;
|
|
129
|
+
if (isServiceTierProvider(model.provider)) {
|
|
130
|
+
const definition = SERVICE_TIER_PROVIDER_DEFINITIONS[model.provider];
|
|
131
|
+
return model.api === definition.api ? model.provider : undefined;
|
|
132
|
+
}
|
|
133
|
+
// Match additional accounts (e.g. `anthropic-2`) by exact API and built-in endpoint.
|
|
134
|
+
return SERVICE_TIER_PROVIDERS.find((provider) => {
|
|
135
|
+
const definition = SERVICE_TIER_PROVIDER_DEFINITIONS[provider];
|
|
136
|
+
return (
|
|
137
|
+
model.api === definition.api &&
|
|
138
|
+
model.baseUrl === definition.baseUrl
|
|
139
|
+
);
|
|
140
|
+
});
|
|
123
141
|
}
|
|
124
142
|
|
|
125
143
|
export function getConfiguredServiceTier(
|
package/package.json
CHANGED
package/service-tier.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
getServiceTierConfigPath,
|
|
28
28
|
loadServiceTierConfig,
|
|
29
|
+
parseServiceTierFlag,
|
|
29
30
|
writeServiceTierConfigSnapshot,
|
|
30
31
|
} from "./config.ts";
|
|
31
32
|
import { createServiceTierSections } from "./settings.ts";
|
|
@@ -136,8 +137,55 @@ export default function (pi: ExtensionAPI) {
|
|
|
136
137
|
}
|
|
137
138
|
};
|
|
138
139
|
|
|
140
|
+
pi.registerFlag("service-tier", {
|
|
141
|
+
type: "string",
|
|
142
|
+
description:
|
|
143
|
+
"Replace global service tier defaults for this process: off, or provider:tier pairs such as openai-codex:priority,anthropic:standard.",
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
type ProcessDefaultsFlag =
|
|
147
|
+
| { active: false }
|
|
148
|
+
| { active: true; config: ServiceTierConfigSnapshot }
|
|
149
|
+
| { active: true; error: string };
|
|
150
|
+
|
|
151
|
+
// Flag values arrive after extension loading; resolve once on first use.
|
|
152
|
+
let processFlag: ProcessDefaultsFlag | undefined;
|
|
153
|
+
let flagWarned = false;
|
|
154
|
+
const getProcessFlag = (): ProcessDefaultsFlag => {
|
|
155
|
+
if (processFlag) return processFlag;
|
|
156
|
+
const value = pi.getFlag("service-tier");
|
|
157
|
+
if (typeof value !== "string") {
|
|
158
|
+
processFlag = { active: false };
|
|
159
|
+
return processFlag;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
processFlag = { active: true, config: parseServiceTierFlag(value) };
|
|
163
|
+
} catch (error) {
|
|
164
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
165
|
+
processFlag = { active: true, error: message };
|
|
166
|
+
}
|
|
167
|
+
return processFlag;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const warnInvalidFlagOnce = (message: string): void => {
|
|
171
|
+
if (flagWarned) return;
|
|
172
|
+
console.warn(`pi-service-tier: ${message}`);
|
|
173
|
+
flagWarned = true;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/** Process defaults: `--service-tier` when set, otherwise `service-tier.json`. */
|
|
177
|
+
const loadProcessDefaults = (): ServiceTierConfigSnapshot => {
|
|
178
|
+
const flag = getProcessFlag();
|
|
179
|
+
if (!flag.active) return loadConfigOrDefault();
|
|
180
|
+
if ("error" in flag) {
|
|
181
|
+
warnInvalidFlagOnce(flag.error);
|
|
182
|
+
return { ...DEFAULT_SERVICE_TIER_CONFIG };
|
|
183
|
+
}
|
|
184
|
+
return flag.config;
|
|
185
|
+
};
|
|
186
|
+
|
|
139
187
|
// Register during loading, before either extension starts its session.
|
|
140
|
-
registerAgentHooks(pi.events,
|
|
188
|
+
registerAgentHooks(pi.events, loadProcessDefaults);
|
|
141
189
|
|
|
142
190
|
const loadConfigForCommand = (
|
|
143
191
|
ctx: ExtensionCommandContext,
|
|
@@ -154,8 +202,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
154
202
|
}
|
|
155
203
|
};
|
|
156
204
|
|
|
205
|
+
const loadDefaultsForToggle = (
|
|
206
|
+
ctx: ExtensionCommandContext,
|
|
207
|
+
): ServiceTierConfigSnapshot | undefined => {
|
|
208
|
+
const flag = getProcessFlag();
|
|
209
|
+
if (!flag.active) return loadConfigForCommand(ctx);
|
|
210
|
+
if ("error" in flag) {
|
|
211
|
+
warnInvalidFlagOnce(flag.error);
|
|
212
|
+
ctx.ui.notify(`Invalid service tier flag: ${flag.error}`, "error");
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
return flag.config;
|
|
216
|
+
};
|
|
217
|
+
|
|
157
218
|
const effectiveSettings = (
|
|
158
|
-
defaults =
|
|
219
|
+
defaults = loadProcessDefaults(),
|
|
159
220
|
): ServiceTierSettings => mergeServiceTierSettings(defaults, sessionOverrides);
|
|
160
221
|
|
|
161
222
|
const refreshServiceTier = (
|
|
@@ -179,7 +240,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
179
240
|
): boolean => {
|
|
180
241
|
try {
|
|
181
242
|
writeServiceTierConfigSnapshot(config);
|
|
182
|
-
|
|
243
|
+
const defaults = getProcessFlag().active ? loadProcessDefaults() : config;
|
|
244
|
+
refreshServiceTier(ctx, effectiveSettings(defaults), true);
|
|
183
245
|
return true;
|
|
184
246
|
} catch (error) {
|
|
185
247
|
notifyConfigWriteError(ctx, error);
|
|
@@ -191,10 +253,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
191
253
|
pi.registerCommand(speed, {
|
|
192
254
|
description: `Toggle ${speed} service tier for the current provider in this session.`,
|
|
193
255
|
handler: async (_args, ctx) => {
|
|
194
|
-
const
|
|
195
|
-
if (!
|
|
256
|
+
const defaults = loadDefaultsForToggle(ctx);
|
|
257
|
+
if (!defaults) return;
|
|
196
258
|
|
|
197
|
-
const result = toggleServiceTierSpeed(effectiveSettings(
|
|
259
|
+
const result = toggleServiceTierSpeed(effectiveSettings(defaults), ctx.model, speed);
|
|
198
260
|
if (!result) {
|
|
199
261
|
const label = speed === "ultrafast" ? "Ultrafast service tier" : "Service tier";
|
|
200
262
|
ctx.ui.notify(
|
|
@@ -216,7 +278,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
216
278
|
return;
|
|
217
279
|
}
|
|
218
280
|
sessionOverrides = state.overrides;
|
|
219
|
-
refreshServiceTier(ctx, effectiveSettings(
|
|
281
|
+
refreshServiceTier(ctx, effectiveSettings(defaults), true);
|
|
220
282
|
|
|
221
283
|
const providerLabel =
|
|
222
284
|
SERVICE_TIER_PROVIDER_DEFINITIONS[result.provider].label;
|
|
@@ -239,6 +301,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
239
301
|
const config = loadConfigForCommand(ctx);
|
|
240
302
|
if (!config) return;
|
|
241
303
|
|
|
304
|
+
const subtitle = getProcessFlag().active
|
|
305
|
+
? `${getServiceTierConfigPath()}\n--service-tier replaces global defaults in this process.\nSession /fast and /ultrafast overrides take precedence.`
|
|
306
|
+
: `${getServiceTierConfigPath()}\nSession /fast and /ultrafast overrides take precedence.`;
|
|
307
|
+
|
|
242
308
|
await ctx.ui.custom((tui, theme, _keybindings, done) => {
|
|
243
309
|
let currentConfig = config;
|
|
244
310
|
const items = createServiceTierSettingItems(currentConfig, ctx.model);
|
|
@@ -247,7 +313,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
247
313
|
new Text(
|
|
248
314
|
`${theme.fg("accent", theme.bold("Global service tier defaults"))}\n${theme.fg(
|
|
249
315
|
"dim",
|
|
250
|
-
|
|
316
|
+
subtitle,
|
|
251
317
|
)}`,
|
|
252
318
|
0,
|
|
253
319
|
0,
|