@mcowger/pi-plexus 1.10.0 → 1.12.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 CHANGED
@@ -139,19 +139,6 @@ Inspect the effective URL, authentication availability, and catalog source witho
139
139
  /plexus status
140
140
  ```
141
141
 
142
- Choose the per-session service tier for eligible Plexus models:
143
-
144
- ```
145
- /service-tier fast
146
- ```
147
-
148
- Tiers are `default` (aliases `off`, `none`), `fast` (alias `priority`), `flex`, and `ultrafast`; `/service-tier status` reports the active tier and whether the current model supports it. The tier is applied per API:
149
-
150
- - **OpenAI Responses** models get a `service_tier` field. `priority` covers OpenAI's Fast-mode set (GPT-5 and newer, GPT-4.1+, GPT-4o, and o3/o4-mini); `flex` and `ultrafast` are limited to their documented models.
151
- - **Anthropic Messages** models use Claude Fast mode (`speed: "fast"` plus the `anthropic-beta: fast-mode-2026-02-01` flag) for `priority`, on `claude-opus-5` and `claude-opus-4-8`; `flex` and `ultrafast` are unsupported. This is a first-party research-preview feature, so it only works when the upstream allows it.
152
-
153
- The tier resets to `default` on every session start. `/plexus-service-tier` is an alias for the same command.
154
-
155
142
  Select a Plexus model in `/model`. Save its startup default with the host's normal model-picker action; Plexus does not maintain a separate default-model setting.
156
143
 
157
144
  Use `/login plexus` for setup and `/logout plexus` to remove stored credentials.
@@ -0,0 +1,64 @@
1
+ # Context-policy event API
2
+
3
+ `plexus-pi` publishes the model context limits available through the configured Plexus route on Pi's cross-extension event bus. The API is versioned in its channel names and payloads.
4
+
5
+ ## Channels
6
+
7
+ Request a snapshot on `plexus:context-policy:request:v1`:
8
+
9
+ ```ts
10
+ { version: 1, requestId: string }
11
+ ```
12
+
13
+ Listen for snapshots on `plexus:context-policy:snapshot:v1`:
14
+
15
+ ```ts
16
+ interface ContextPolicy {
17
+ provider: string;
18
+ modelId: string;
19
+ maxContextTokens: number;
20
+ shortContextBudgetTokens: number;
21
+ pricingThresholdInputTokens?: number;
22
+ }
23
+
24
+ interface ContextPolicySnapshot {
25
+ version: 1;
26
+ publisherId: string;
27
+ revision: number;
28
+ requestId?: string;
29
+ status: "ready" | "loading" | "unavailable";
30
+ policies: ContextPolicy[];
31
+ fetchedAt?: number;
32
+ cached?: boolean;
33
+ reason?: string;
34
+ }
35
+ ```
36
+
37
+ The extension validates incoming requests and outgoing snapshots with Zod. Invalid requests are ignored. A valid request gets the current in-memory snapshot immediately, within the request event's `emit()` call. That reply echoes `requestId`; it does not increment the revision or fetch models. Broadcasts have no `requestId`.
38
+
39
+ ## Policy values
40
+
41
+ - `provider` and `modelId` are the exact identifiers registered with Pi. For this adapter, the provider is `plexus` and the model ID is the Plexus model ID, not its display name.
42
+ - `maxContextTokens` comes from the raw model's `context_length`, the total context capacity advertised for that Plexus route. The adapter does not calculate it by adding input and output limits.
43
+ - `shortContextBudgetTokens` comes from the first `pricing.tiers[].input_tokens_above` value. Plexus tiering uses that boundary as the intended smaller context budget as well as the pricing transition point.
44
+ - `pricingThresholdInputTokens`, when present, reports that same input-pricing boundary. It remains a pricing threshold in its own right; it is not used as the maximum context capacity.
45
+ - A model is omitted unless both values are present, positive safe integers, and the tier boundary is no greater than the context capacity. Models without pricing tiers have no known short-context budget and are omitted. A boundary equal to the maximum is valid.
46
+ - A pair of policies cannot repeat the same `(provider, modelId)`.
47
+
48
+ Only raw API models represented in the committed Pi catalog are eligible. Suppressed models and models removed by a refresh disappear from the next complete snapshot. The extension stores the policy metadata and original fetch timestamp with the committed catalog entry so cached catalogs can publish the same values.
49
+
50
+ ## Snapshot status and lifecycle
51
+
52
+ - At extension initialization, the publisher creates a UUID `publisherId` and starts at revision `1`.
53
+ - `loading` has no policies and is used before the catalog state is known.
54
+ - `ready` means the catalog loaded successfully. It can contain policies or an empty list if no catalog models qualify.
55
+ - `unavailable` has no policies and includes a safe explanation when policy metadata cannot be supplied.
56
+ - The publisher increments `revision` when the published state changes. A request/reply alone does not change it.
57
+ - `fetchedAt` is the Unix-millisecond time of the last successful `/v1/models` fetch, not publication time. A cached snapshot sets `cached: true` and preserves the original fetch timestamp.
58
+ - A failed refresh keeps the last committed snapshot. A stale refresh cannot replace a newer catalog because publication uses Pi's generation-checked `context.publish()` transaction.
59
+ - Snapshots are immutable complete replacements, never deltas. Serialized snapshots are capped at 1 MiB. Invalid or oversized state is replaced with a small `unavailable` snapshot, not truncated.
60
+ - The request listener is registered during extension initialization and removed on `session_shutdown` using the unsubscribe function returned by `pi.events.on()`.
61
+
62
+ Snapshots contain policy metadata only. They do not include credentials, URLs, request headers, or raw backend errors.
63
+
64
+ A control command can select which advertised budget applies for the active session and model; see [policy-control.md](./policy-control.md).