pi-service-tier 0.4.0 → 0.5.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 +18 -2
- package/agent-hooks.ts +75 -0
- package/domain.ts +9 -0
- package/package.json +4 -4
- package/service-tier.ts +5 -0
- package/shared.ts +0 -4
package/README.md
CHANGED
|
@@ -44,6 +44,24 @@ selected point, and `/fork` or `/clone` inherits the choices on the copied branc
|
|
|
44
44
|
Later toggles in a fork do not affect its parent. `/new` starts without overrides
|
|
45
45
|
and uses your global defaults.
|
|
46
46
|
|
|
47
|
+
### Child agents
|
|
48
|
+
|
|
49
|
+
With [pi-agents](https://github.com/mavam/pi-agents) 0.36.0 or later, which
|
|
50
|
+
provides [agent extension hooks](https://github.com/mavam/pi-agents/blob/main/docs/hooks.md),
|
|
51
|
+
new agents capture your effective service-tier settings, including session
|
|
52
|
+
`/fast` overrides. Each child applies the settings for its own provider, even
|
|
53
|
+
when it uses a different model from the parent.
|
|
54
|
+
|
|
55
|
+
For example, enable `/fast`, then ask Pi to spawn an agent. That agent keeps
|
|
56
|
+
its captured settings if you toggle `/fast` again. Graph nodes capture when
|
|
57
|
+
the graph is created; helpers inherit their creating agent's settings.
|
|
58
|
+
Follow-ups, child compaction, and resumed work retain the snapshot.
|
|
59
|
+
|
|
60
|
+
This integration is optional and adds no package dependency. A snapshot from a
|
|
61
|
+
newer version of pi-service-tier applies the providers and tiers this version
|
|
62
|
+
supports. If pi-service-tier is removed, stored snapshots remain but stop
|
|
63
|
+
affecting requests; loading it again applies them. Parent compaction and usage-cost limitations are unchanged.
|
|
64
|
+
|
|
47
65
|
## ⚙️ Configuration
|
|
48
66
|
|
|
49
67
|
Run `/service-tier` or create `~/.pi/agent/service-tier.json` to set global defaults:
|
|
@@ -70,8 +88,6 @@ Run `/service-tier` or create `~/.pi/agent/service-tier.json` to set global defa
|
|
|
70
88
|
|
|
71
89
|
To turn a provider off by default, omit its key. Only the values listed above are
|
|
72
90
|
accepted. Providers without a session override continue to pick up global changes.
|
|
73
|
-
Existing global settings, including those saved by earlier versions of `/fast`,
|
|
74
|
-
remain in effect. Use `/service-tier` to change them.
|
|
75
91
|
Batch APIs are separate asynchronous APIs and are not configured by this
|
|
76
92
|
extension.
|
|
77
93
|
|
package/agent-hooks.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ExtensionAPI, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
applyServiceTierToPayload,
|
|
4
|
+
isRecord,
|
|
5
|
+
isServiceTierName,
|
|
6
|
+
isServiceTierProvider,
|
|
7
|
+
type ServiceTierConfigSnapshot,
|
|
8
|
+
type ServiceTierModel,
|
|
9
|
+
type ServiceTierProvider,
|
|
10
|
+
type ServiceTierSelection,
|
|
11
|
+
type ServiceTierSettings,
|
|
12
|
+
} from "./domain.ts";
|
|
13
|
+
import {
|
|
14
|
+
mergeServiceTierSettings,
|
|
15
|
+
restoreServiceTierOverrides,
|
|
16
|
+
} from "./session-state.ts";
|
|
17
|
+
|
|
18
|
+
/** Structural implementation of pi-agents/hooks protocol 1; no dependency. */
|
|
19
|
+
export function createAgentHooks(loadDefaults: () => ServiceTierConfigSnapshot) {
|
|
20
|
+
return {
|
|
21
|
+
namespace: "pi-service-tier",
|
|
22
|
+
onAgentCreate(ctx: { parent: { branch: readonly SessionEntry[] } }) {
|
|
23
|
+
return {
|
|
24
|
+
version: 1,
|
|
25
|
+
settings: mergeServiceTierSettings(
|
|
26
|
+
loadDefaults(),
|
|
27
|
+
restoreServiceTierOverrides(ctx.parent.branch),
|
|
28
|
+
),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
onAgentRequest(
|
|
32
|
+
ctx: { state: unknown; model: ServiceTierModel },
|
|
33
|
+
payload: unknown,
|
|
34
|
+
) {
|
|
35
|
+
if (ctx.state === undefined) return undefined;
|
|
36
|
+
return applyServiceTierToPayload(payload, readSettings(ctx.state), ctx.model);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Stored settings are authoritative; never merge today's defaults on resume.
|
|
43
|
+
* Snapshots never change, so read every version 1 snapshot, also one a newer
|
|
44
|
+
* version wrote: providers and tiers this version doesn't know apply nothing.
|
|
45
|
+
*/
|
|
46
|
+
function readSettings(state: unknown): ServiceTierSettings {
|
|
47
|
+
if (!isRecord(state) || state.version !== 1 || !isRecord(state.settings)) {
|
|
48
|
+
throw new Error("Unsupported or invalid pi-service-tier agent state");
|
|
49
|
+
}
|
|
50
|
+
const settings: Partial<Record<ServiceTierProvider, ServiceTierSelection>> = {};
|
|
51
|
+
for (const [provider, value] of Object.entries(state.settings)) {
|
|
52
|
+
if (typeof value !== "string") {
|
|
53
|
+
throw new Error("Invalid service tier in pi-service-tier agent state");
|
|
54
|
+
}
|
|
55
|
+
if (!isServiceTierProvider(provider)) continue;
|
|
56
|
+
// An empty value explicitly disables injection and must survive too.
|
|
57
|
+
if (value === "" || isServiceTierName(provider, value)) {
|
|
58
|
+
settings[provider] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return settings;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function registerAgentHooks(
|
|
65
|
+
events: ExtensionAPI["events"],
|
|
66
|
+
loadDefaults: () => ServiceTierConfigSnapshot,
|
|
67
|
+
): void {
|
|
68
|
+
const hooks = createAgentHooks(loadDefaults);
|
|
69
|
+
events.on("pi-agents:hooks:discover", (request) => {
|
|
70
|
+
if (!isRecord(request) || request.protocol !== 1 || typeof request.register !== "function") {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
request.register(hooks);
|
|
74
|
+
});
|
|
75
|
+
}
|
package/domain.ts
CHANGED
|
@@ -95,6 +95,15 @@ export function isServiceTierProvider(
|
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
export function isServiceTierName(
|
|
99
|
+
provider: ServiceTierProvider,
|
|
100
|
+
value: unknown,
|
|
101
|
+
): value is ServiceTierName {
|
|
102
|
+
return SERVICE_TIER_PROVIDER_DEFINITIONS[provider].tiers.some(
|
|
103
|
+
(tier) => tier.name === value,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
98
107
|
export function modelSupportsServiceTier(
|
|
99
108
|
model: ServiceTierModel | undefined,
|
|
100
109
|
): boolean {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-service-tier",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Fast mode and provider service-tier controls for pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@earendil-works/pi-coding-agent": "
|
|
8
|
-
"@earendil-works/pi-tui": "
|
|
7
|
+
"@earendil-works/pi-coding-agent": "^1.3.0",
|
|
8
|
+
"@earendil-works/pi-tui": "^1.3.0",
|
|
9
9
|
"typebox": "*"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"service-tier.ts",
|
|
13
|
-
"
|
|
13
|
+
"agent-hooks.ts",
|
|
14
14
|
"domain.ts",
|
|
15
15
|
"config.ts",
|
|
16
16
|
"settings.ts",
|
package/service-tier.ts
CHANGED
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
type SessionServiceTierOverrides,
|
|
38
38
|
} from "./session-state.ts";
|
|
39
39
|
|
|
40
|
+
import { registerAgentHooks } from "./agent-hooks.ts";
|
|
41
|
+
|
|
40
42
|
export const SERVICE_TIER_WIDGET_ID = "pi-service-tier.service-tier";
|
|
41
43
|
|
|
42
44
|
const FANCY_FOOTER_PROTOCOL = 1;
|
|
@@ -129,6 +131,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
129
131
|
}
|
|
130
132
|
};
|
|
131
133
|
|
|
134
|
+
// Register during loading, before either extension starts its session.
|
|
135
|
+
registerAgentHooks(pi.events, loadConfigOrDefault);
|
|
136
|
+
|
|
132
137
|
const loadConfigForCommand = (
|
|
133
138
|
ctx: ExtensionCommandContext,
|
|
134
139
|
): ServiceTierConfigSnapshot | undefined => {
|
package/shared.ts
DELETED