@mcowger/pi-plexus 1.13.1 → 1.14.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/dist/extension.js CHANGED
@@ -94,6 +94,7 @@ function resolvePricingTiers(model) {
94
94
  function convertToDescriptor(raw, baseUrl) {
95
95
  const preferredApi = mapPreferredApi(raw.preferred_api);
96
96
  const adjustedBaseUrl = adjustBaseUrl(baseUrl, preferredApi);
97
+ const shortName = typeof raw.short_name === "string" ? raw.short_name.trim() : "";
97
98
  const contextWindow = resolveContextWindow(raw);
98
99
  const maxTokens = resolveMaxTokens(raw);
99
100
  const tiers = resolvePricingTiers(raw);
@@ -115,6 +116,8 @@ function convertToDescriptor(raw, baseUrl) {
115
116
  contextWindow,
116
117
  maxTokens
117
118
  };
119
+ if (shortName)
120
+ descriptor.shortName = shortName;
118
121
  if (raw.pi_provider)
119
122
  descriptor.piProvider = raw.pi_provider;
120
123
  if (raw.pi_model)
@@ -6294,6 +6297,7 @@ function descriptorToPiModel(descriptor) {
6294
6297
  return {
6295
6298
  id: descriptor.id,
6296
6299
  name: descriptor.name,
6300
+ ...descriptor.shortName !== undefined ? { plexusShortName: descriptor.shortName } : {},
6297
6301
  api: descriptor.preferredApi,
6298
6302
  provider: descriptor.provider,
6299
6303
  baseUrl: descriptor.baseUrl,
@@ -6871,6 +6875,140 @@ class ServiceTiersPublisher {
6871
6875
  }
6872
6876
  }
6873
6877
 
6878
+ // src/short-names.ts
6879
+ import { randomUUID as randomUUID5 } from "crypto";
6880
+ var SHORT_NAMES_REQUEST_CHANNEL = "plexus:short-names:request:v1";
6881
+ var SHORT_NAMES_SNAPSHOT_CHANNEL = "plexus:short-names:snapshot:v1";
6882
+ var ShortNameEntrySchema = object({
6883
+ provider: string2().min(1),
6884
+ modelId: string2().min(1),
6885
+ shortName: string2().min(1).max(200)
6886
+ }).strict();
6887
+ var ShortNamesRequestSchema = object({
6888
+ version: literal(1),
6889
+ requestId: string2().min(1).max(1024)
6890
+ }).strict();
6891
+ var ShortNamesSnapshotSchema = object({
6892
+ version: literal(1),
6893
+ publisherId: string2().uuid(),
6894
+ revision: number2().int().positive().safe(),
6895
+ requestId: string2().min(1).max(1024).optional(),
6896
+ status: _enum(["ready", "loading", "unavailable"]),
6897
+ names: array(ShortNameEntrySchema),
6898
+ fetchedAt: number2().int().nonnegative().safe().optional(),
6899
+ cached: boolean2().optional(),
6900
+ reason: string2().max(500).optional()
6901
+ }).strict().superRefine((snapshot, ctx) => {
6902
+ const pairs = new Set;
6903
+ for (const entry of snapshot.names) {
6904
+ const pair = `${entry.provider}\x00${entry.modelId}`;
6905
+ if (pairs.has(pair))
6906
+ ctx.addIssue({
6907
+ code: "custom",
6908
+ message: "Duplicate provider/modelId short-name entry"
6909
+ });
6910
+ pairs.add(pair);
6911
+ }
6912
+ if (snapshot.status !== "ready" && snapshot.names.length !== 0) {
6913
+ ctx.addIssue({
6914
+ code: "custom",
6915
+ message: "Non-ready snapshots must have no names"
6916
+ });
6917
+ }
6918
+ });
6919
+ var MAX_SNAPSHOT_BYTES3 = 1024 * 1024;
6920
+ class ShortNamesPublisher {
6921
+ publisherId = randomUUID5();
6922
+ revision = 1;
6923
+ state = Object.freeze({
6924
+ version: 1,
6925
+ publisherId: this.publisherId,
6926
+ revision: 1,
6927
+ status: "loading",
6928
+ names: Object.freeze([])
6929
+ });
6930
+ emit;
6931
+ unsubscribe;
6932
+ constructor(events) {
6933
+ this.emit = events.emit.bind(events);
6934
+ this.unsubscribe = events.on(SHORT_NAMES_REQUEST_CHANNEL, (data) => {
6935
+ const request = ShortNamesRequestSchema.safeParse(data);
6936
+ if (request.success)
6937
+ this.send(request.data.requestId);
6938
+ });
6939
+ }
6940
+ getSnapshot() {
6941
+ return this.state;
6942
+ }
6943
+ setCatalog(status, names, metadata) {
6944
+ const candidate = ShortNamesSnapshotSchema.safeParse({
6945
+ version: 1,
6946
+ publisherId: this.publisherId,
6947
+ revision: this.revision,
6948
+ status,
6949
+ names: [...names],
6950
+ ...metadata
6951
+ });
6952
+ const oversized = candidate.success && new TextEncoder().encode(JSON.stringify(candidate.data)).byteLength > MAX_SNAPSHOT_BYTES3;
6953
+ let next = candidate.success && !oversized ? candidate.data : {
6954
+ version: 1,
6955
+ publisherId: this.publisherId,
6956
+ revision: this.revision,
6957
+ status: "unavailable",
6958
+ names: [],
6959
+ reason: oversized ? "Short-name snapshot exceeds the 1 MiB publication limit." : "Short-name snapshot could not be validated."
6960
+ };
6961
+ if (status !== "ready" && names.length > 0) {
6962
+ next = {
6963
+ ...next,
6964
+ status: "unavailable",
6965
+ names: [],
6966
+ reason: "Short-name metadata is unavailable."
6967
+ };
6968
+ }
6969
+ const { revision: _revision, ...stateWithoutRevision } = this.state;
6970
+ const { revision: _candidateRevision, ...nextWithoutRevision } = next;
6971
+ if (JSON.stringify(stateWithoutRevision) === JSON.stringify(nextWithoutRevision))
6972
+ return false;
6973
+ this.revision++;
6974
+ this.state = Object.freeze({
6975
+ ...next,
6976
+ revision: this.revision,
6977
+ names: Object.freeze(next.names.map((entry) => Object.freeze({ ...entry })))
6978
+ });
6979
+ this.send();
6980
+ return true;
6981
+ }
6982
+ send(requestId) {
6983
+ const snapshot = {
6984
+ ...this.state,
6985
+ ...requestId === undefined ? {} : { requestId }
6986
+ };
6987
+ let valid = ShortNamesSnapshotSchema.safeParse(snapshot);
6988
+ if (!valid.success || new TextEncoder().encode(JSON.stringify(snapshot)).byteLength > MAX_SNAPSHOT_BYTES3) {
6989
+ valid = ShortNamesSnapshotSchema.safeParse({
6990
+ version: 1,
6991
+ publisherId: this.publisherId,
6992
+ revision: this.revision,
6993
+ status: "unavailable",
6994
+ names: [],
6995
+ reason: "Short-name snapshot exceeds publication limits or is invalid.",
6996
+ ...requestId === undefined ? {} : { requestId }
6997
+ });
6998
+ }
6999
+ if (valid.success) {
7000
+ const immutable = Object.freeze({
7001
+ ...valid.data,
7002
+ names: Object.freeze(valid.data.names.map((entry) => Object.freeze({ ...entry })))
7003
+ });
7004
+ this.emit(SHORT_NAMES_SNAPSHOT_CHANNEL, immutable);
7005
+ }
7006
+ }
7007
+ dispose() {
7008
+ this.unsubscribe();
7009
+ }
7010
+ }
7011
+
6874
7012
  // src/extension.ts
6875
7013
  var PROVIDER_NAME = "plexus";
6876
7014
  var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
@@ -7128,12 +7266,14 @@ function createPolicyHost(deps) {
7128
7266
  function plexusExtension(pi) {
7129
7267
  const contextPolicies = new ContextPolicyPublisher(pi.events);
7130
7268
  const serviceTiers = new ServiceTiersPublisher(pi.events);
7269
+ const shortNames = new ShortNamesPublisher(pi.events);
7131
7270
  const state = {
7132
7271
  models: [],
7133
7272
  catalogSource: "none",
7134
7273
  refreshSequence: 0,
7135
7274
  contextPolicies,
7136
7275
  serviceTiers,
7276
+ shortNames,
7137
7277
  policy: undefined,
7138
7278
  activeModel: undefined,
7139
7279
  registry: undefined
@@ -7173,12 +7313,15 @@ function plexusExtension(pi) {
7173
7313
  pi.on("session_shutdown", () => {
7174
7314
  contextPolicies.dispose();
7175
7315
  serviceTiers.dispose();
7316
+ shortNames.dispose();
7176
7317
  policy.dispose();
7177
7318
  modelsControl.dispose();
7178
7319
  if (state.contextPolicies === contextPolicies)
7179
7320
  state.contextPolicies = undefined;
7180
7321
  if (state.serviceTiers === serviceTiers)
7181
7322
  state.serviceTiers = undefined;
7323
+ if (state.shortNames === shortNames)
7324
+ state.shortNames = undefined;
7182
7325
  if (state.policy === policy)
7183
7326
  state.policy = undefined;
7184
7327
  });
@@ -7200,6 +7343,10 @@ function plexusExtension(pi) {
7200
7343
  cached: true,
7201
7344
  ...cachedTiers.fetchedAt === undefined ? {} : { fetchedAt: cachedTiers.fetchedAt }
7202
7345
  } : { cached: true, reason: SERVICE_TIERS_METADATA_UNAVAILABLE_REASON });
7346
+ shortNames.setCatalog("ready", collectStoredShortNames(startupModels), {
7347
+ cached: true,
7348
+ ...storedCatalog.checkedAt ? { fetchedAt: storedCatalog.checkedAt } : {}
7349
+ });
7203
7350
  }
7204
7351
  policy.reconcile();
7205
7352
  pi.on("session_start", (_event, ctx) => {
@@ -7308,6 +7455,7 @@ async function refreshPlexusModels(state, context) {
7308
7455
  cached: true,
7309
7456
  reason: CONTEXT_POLICY_METADATA_UNAVAILABLE_REASON
7310
7457
  });
7458
+ state.shortNames?.setCatalog("ready", collectStoredShortNames(filteredCurrent), { cached: true });
7311
7459
  state.policy?.reconcile();
7312
7460
  }
7313
7461
  });
@@ -7321,6 +7469,11 @@ async function refreshPlexusModels(state, context) {
7321
7469
  reason: "Plexus model metadata is not configured."
7322
7470
  });
7323
7471
  }
7472
+ if (refreshId === state.refreshSequence && state.shortNames?.getSnapshot().status === "loading") {
7473
+ state.shortNames.setCatalog("unavailable", [], {
7474
+ reason: "Plexus model metadata is not configured."
7475
+ });
7476
+ }
7324
7477
  throw new Error(!modelsUrl || !baseUrl ? "Plexus base URL not configured. Run /login plexus first." : "No Plexus API key configured. Run /login plexus first.");
7325
7478
  }
7326
7479
  try {
@@ -7342,9 +7495,15 @@ async function refreshPlexusModels(state, context) {
7342
7495
  policy: serviceTierPolicyFromApiModel(model),
7343
7496
  fetchedAt
7344
7497
  };
7498
+ const shortName = shortNameEntryFromApiModel(model);
7499
+ if (shortName)
7500
+ piModel.plexusShortName = shortName.shortName;
7501
+ else
7502
+ delete piModel.plexusShortName;
7345
7503
  }
7346
7504
  const committedPolicies = collectStoredContextPolicies(piModels);
7347
7505
  const committedServiceTiers = collectStoredServiceTiers(piModels).policies;
7506
+ const committedShortNames = collectStoredShortNames(piModels);
7348
7507
  const published = await context.publish({
7349
7508
  persist: {
7350
7509
  models: piModels,
@@ -7356,6 +7515,9 @@ async function refreshPlexusModels(state, context) {
7356
7515
  state.serviceTiers?.setCatalog("ready", committedServiceTiers, {
7357
7516
  fetchedAt
7358
7517
  });
7518
+ state.shortNames?.setCatalog("ready", committedShortNames, {
7519
+ fetchedAt
7520
+ });
7359
7521
  state.contextPolicies?.setCatalog(committedPolicies.length > 0 ? "ready" : "unavailable", committedPolicies.map((entry) => entry.policy), committedPolicies.length > 0 ? { fetchedAt } : { fetchedAt, reason: CONTEXT_POLICY_METADATA_UNAVAILABLE_REASON });
7360
7522
  state.policy?.reconcile();
7361
7523
  }
@@ -7376,6 +7538,11 @@ async function refreshPlexusModels(state, context) {
7376
7538
  reason: "Plexus model metadata could not be loaded."
7377
7539
  });
7378
7540
  }
7541
+ if (refreshId === state.refreshSequence && state.shortNames?.getSnapshot().status === "loading") {
7542
+ state.shortNames.setCatalog("unavailable", [], {
7543
+ reason: "Plexus model metadata could not be loaded."
7544
+ });
7545
+ }
7379
7546
  log("refreshModels: fetch failed", { error: String(error) });
7380
7547
  throw error;
7381
7548
  }
@@ -7400,6 +7567,9 @@ async function restoreStoredModels(state, context) {
7400
7567
  cached: true,
7401
7568
  reason: CONTEXT_POLICY_METADATA_UNAVAILABLE_REASON
7402
7569
  });
7570
+ state.shortNames?.setCatalog("ready", collectStoredShortNames(models), {
7571
+ cached: true
7572
+ });
7403
7573
  state.policy?.reconcile();
7404
7574
  }
7405
7575
  });
@@ -7437,6 +7607,30 @@ function serviceTierPolicyFromApiModel(model) {
7437
7607
  const parsed = ServiceTierPolicySchema.safeParse(candidate);
7438
7608
  return parsed.success ? parsed.data : undefined;
7439
7609
  }
7610
+ function shortNameEntryFromApiModel(model) {
7611
+ const shortName = typeof model.short_name === "string" ? model.short_name.trim() : "";
7612
+ if (!shortName)
7613
+ return;
7614
+ const parsed = ShortNameEntrySchema.safeParse({
7615
+ provider: PROVIDER_NAME,
7616
+ modelId: model.id,
7617
+ shortName
7618
+ });
7619
+ return parsed.success ? parsed.data : undefined;
7620
+ }
7621
+ function collectStoredShortNames(models) {
7622
+ return models.flatMap((model) => {
7623
+ const shortName = model.plexusShortName;
7624
+ if (typeof shortName !== "string" || !shortName.trim())
7625
+ return [];
7626
+ const parsed = ShortNameEntrySchema.safeParse({
7627
+ provider: PROVIDER_NAME,
7628
+ modelId: model.id,
7629
+ shortName: shortName.trim()
7630
+ });
7631
+ return parsed.success ? [parsed.data] : [];
7632
+ });
7633
+ }
7440
7634
  function collectStoredServiceTiers(models) {
7441
7635
  const metadata = models.map((model) => model.plexusServiceTiers);
7442
7636
  const complete = models.length === 0 || metadata.every((entry) => entry !== undefined);
@@ -7542,6 +7736,7 @@ export {
7542
7736
  enforceMinimumOutputTokens,
7543
7737
  normalizeGoogleThinkingConfig,
7544
7738
  serviceTierPolicyFromApiModel,
7739
+ shortNameEntryFromApiModel,
7545
7740
  usesGoogleThinkingLevel,
7546
7741
  withAuthoritativeApiKeyEnv
7547
7742
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.13.1",
3
+ "version": "1.14.0",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [
@@ -9,6 +9,7 @@
9
9
  "README.md",
10
10
  "context-policy.md",
11
11
  "service-tiers.md",
12
+ "short-names.md",
12
13
  "policy-control.md",
13
14
  "models-control.md"
14
15
  ],
package/short-names.md ADDED
@@ -0,0 +1,59 @@
1
+ # Short-name event API
2
+
3
+ `plexus-pi` publishes the server-advertised abbreviated display names for models in the committed Plexus catalog over Pi's cross-extension event bus.
4
+
5
+ ## Channels and payloads
6
+
7
+ Request a snapshot on `plexus:short-names:request:v1`:
8
+
9
+ ```ts
10
+ { version: 1, requestId: string }
11
+ ```
12
+
13
+ Listen for a reply or broadcast on `plexus:short-names:snapshot:v1`:
14
+
15
+ ```ts
16
+ interface ShortNameEntry {
17
+ provider: string;
18
+ modelId: string;
19
+ shortName: string;
20
+ }
21
+
22
+ interface ShortNamesSnapshot {
23
+ version: 1;
24
+ publisherId: string;
25
+ revision: number;
26
+ requestId?: string;
27
+ status: "ready" | "loading" | "unavailable";
28
+ names: ShortNameEntry[];
29
+ fetchedAt?: number;
30
+ cached?: boolean;
31
+ reason?: string;
32
+ }
33
+ ```
34
+
35
+ Incoming requests and outgoing snapshots are validated with Zod. Invalid requests are ignored without logging their payload. A valid request receives the current in-memory snapshot synchronously during `pi.events.emit()` and echoes `requestId`; it never starts or waits for a network request. Replies do not advance the revision. Broadcasts omit `requestId` and replace the full previous snapshot.
36
+
37
+ ## Name semantics
38
+
39
+ - `provider` and `modelId` are the IDs registered with Pi. For Plexus, the provider is `plexus` and `modelId` is the raw model ID, not its display name.
40
+ - `shortName` is copied from the model's `short_name` field, trimmed. Missing, blank, or overlong (>200 character) values are not advertised.
41
+ - Entries are emitted only for models included in the committed Pi catalog. Suppressed or removed models disappear from the next snapshot.
42
+ - A successful catalog where no model advertises a short name has `status: "ready"` and `names: []`. Absence of short names is catalog data, not a failure.
43
+ - Each committed model carries its short name as the `plexusShortName` extra prop, alongside `plexusContextPolicy` and `plexusServiceTiers`. It persists in Pi's `models-store.json` with the rest of the catalog.
44
+
45
+ ## Why a separate channel
46
+
47
+ Short names are not part of the context-policy snapshot on purpose. Every snapshot schema here and there is strict on both ends, so adding a field to the context-policy snapshot in a one-sided rollout would fail validation and kill the whole snapshot for mismatched peers. A dedicated channel lets consumers adopt short names independently.
48
+
49
+ ## Lifecycle
50
+
51
+ - Each extension load creates a UUID `publisherId` and starts at revision `1`.
52
+ - `loading` is used while no usable catalog state is available. `unavailable` has no names and includes a safe reason when metadata cannot be supplied. Both states have empty name arrays.
53
+ - The revision advances only when the published state changes. Request/reply alone does not increment it.
54
+ - `fetchedAt` is the successful `/v1/models` fetch time, in Unix milliseconds. Cached snapshots set `cached: true` and preserve the original timestamp when known.
55
+ - A failed refresh retains the last committed snapshot. Catalog state changes are applied only inside Pi's generation-checked `context.publish()` transaction, so stale refreshes cannot replace a newer committed catalog.
56
+ - Snapshots are immutable complete replacements, validated before emission, and capped at 1 MiB. Oversized or invalid state becomes a small `unavailable` snapshot; names are never truncated.
57
+ - The request listener is installed during extension initialization and removed on `session_shutdown` with the unsubscribe function from `pi.events.on()`.
58
+
59
+ Snapshots contain display-name metadata only. They never include credentials, URLs, request headers, or raw backend errors.