@mcowger/pi-plexus 1.13.0 → 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 +340 -8
- package/package.json +2 -1
- package/short-names.md +59 -0
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;
|
|
@@ -6891,19 +7029,153 @@ function enforceMinimumOutputTokens(payload) {
|
|
|
6891
7029
|
changed = true;
|
|
6892
7030
|
}
|
|
6893
7031
|
}
|
|
6894
|
-
const generationConfig
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
7032
|
+
for (const configKey of ["generationConfig", "config"]) {
|
|
7033
|
+
const generationConfig = next[configKey];
|
|
7034
|
+
if (generationConfig && typeof generationConfig === "object" && !Array.isArray(generationConfig)) {
|
|
7035
|
+
const maxOutputTokens = generationConfig.maxOutputTokens;
|
|
7036
|
+
if (typeof maxOutputTokens === "number" && Number.isFinite(maxOutputTokens) && maxOutputTokens < MINIMUM_OUTPUT_TOKENS) {
|
|
7037
|
+
next[configKey] = {
|
|
7038
|
+
...generationConfig,
|
|
7039
|
+
maxOutputTokens: MINIMUM_OUTPUT_TOKENS
|
|
7040
|
+
};
|
|
7041
|
+
changed = true;
|
|
7042
|
+
}
|
|
7043
|
+
}
|
|
7044
|
+
}
|
|
7045
|
+
return changed ? next : payload;
|
|
7046
|
+
}
|
|
7047
|
+
var EXTENDED_THINKING_LEVELS = [
|
|
7048
|
+
"off",
|
|
7049
|
+
"minimal",
|
|
7050
|
+
"low",
|
|
7051
|
+
"medium",
|
|
7052
|
+
"high",
|
|
7053
|
+
"xhigh",
|
|
7054
|
+
"max"
|
|
7055
|
+
];
|
|
7056
|
+
var GOOGLE_THINKING_LEVELS = {
|
|
7057
|
+
minimal: "MINIMAL",
|
|
7058
|
+
low: "LOW",
|
|
7059
|
+
medium: "MEDIUM",
|
|
7060
|
+
high: "HIGH"
|
|
7061
|
+
};
|
|
7062
|
+
function getGeminiMajorVersion(modelId) {
|
|
7063
|
+
const match = modelId.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);
|
|
7064
|
+
if (!match?.[1])
|
|
7065
|
+
return;
|
|
7066
|
+
return Number.parseInt(match[1], 10);
|
|
7067
|
+
}
|
|
7068
|
+
function usesGoogleThinkingLevel(model) {
|
|
7069
|
+
if (model.thinkingLevelMap && EXTENDED_THINKING_LEVELS.some((level) => level !== "off" && typeof model.thinkingLevelMap?.[level] === "string")) {
|
|
7070
|
+
return true;
|
|
7071
|
+
}
|
|
7072
|
+
const id = model.id.toLowerCase();
|
|
7073
|
+
const majorVersion = getGeminiMajorVersion(id);
|
|
7074
|
+
return majorVersion !== undefined && majorVersion >= 3 || id === "gemini-flash-latest" || id === "gemini-flash-lite-latest" || /gemma-?4/.test(id);
|
|
7075
|
+
}
|
|
7076
|
+
function getSupportedThinkingLevelsForModel(model) {
|
|
7077
|
+
if (!model.reasoning)
|
|
7078
|
+
return ["off"];
|
|
7079
|
+
return EXTENDED_THINKING_LEVELS.filter((level) => {
|
|
7080
|
+
const mapped = model.thinkingLevelMap?.[level];
|
|
7081
|
+
if (mapped === null)
|
|
7082
|
+
return false;
|
|
7083
|
+
if (level === "xhigh" || level === "max")
|
|
7084
|
+
return mapped !== undefined;
|
|
7085
|
+
return true;
|
|
7086
|
+
});
|
|
7087
|
+
}
|
|
7088
|
+
function clampModelThinkingLevel(model, level) {
|
|
7089
|
+
const availableLevels = getSupportedThinkingLevelsForModel(model);
|
|
7090
|
+
if (availableLevels.includes(level))
|
|
7091
|
+
return level;
|
|
7092
|
+
const requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);
|
|
7093
|
+
if (requestedIndex === -1)
|
|
7094
|
+
return availableLevels[0] ?? "off";
|
|
7095
|
+
for (let i = requestedIndex;i < EXTENDED_THINKING_LEVELS.length; i++) {
|
|
7096
|
+
const candidate = EXTENDED_THINKING_LEVELS[i];
|
|
7097
|
+
if (candidate && availableLevels.includes(candidate))
|
|
7098
|
+
return candidate;
|
|
7099
|
+
}
|
|
7100
|
+
for (let i = requestedIndex - 1;i >= 0; i--) {
|
|
7101
|
+
const candidate = EXTENDED_THINKING_LEVELS[i];
|
|
7102
|
+
if (candidate && availableLevels.includes(candidate))
|
|
7103
|
+
return candidate;
|
|
7104
|
+
}
|
|
7105
|
+
return availableLevels[0] ?? "off";
|
|
7106
|
+
}
|
|
7107
|
+
function toGoogleThinkingLevel(model, level) {
|
|
7108
|
+
const clamped = clampModelThinkingLevel(model, level);
|
|
7109
|
+
if (clamped === "off")
|
|
7110
|
+
return;
|
|
7111
|
+
const mapped = model.thinkingLevelMap?.[clamped];
|
|
7112
|
+
const resolved = (typeof mapped === "string" ? mapped : clamped).trim().toLowerCase();
|
|
7113
|
+
return GOOGLE_THINKING_LEVELS[resolved];
|
|
7114
|
+
}
|
|
7115
|
+
function normalizeThinkingConfigObject(thinkingConfig, model, thinkingLevel) {
|
|
7116
|
+
if (thinkingConfig.thinkingLevel !== undefined)
|
|
7117
|
+
return thinkingConfig;
|
|
7118
|
+
if (thinkingConfig.thinkingBudget === -1) {
|
|
7119
|
+
const effectiveLevel = thinkingLevel && thinkingLevel !== "off" ? thinkingLevel : "high";
|
|
7120
|
+
const googleLevel = toGoogleThinkingLevel(model, effectiveLevel);
|
|
7121
|
+
if (!googleLevel)
|
|
7122
|
+
return thinkingConfig;
|
|
7123
|
+
const { thinkingBudget: _thinkingBudget, ...rest } = thinkingConfig;
|
|
7124
|
+
return {
|
|
7125
|
+
...rest,
|
|
7126
|
+
thinkingLevel: googleLevel
|
|
7127
|
+
};
|
|
7128
|
+
}
|
|
7129
|
+
if (thinkingConfig.thinkingBudget === 0) {
|
|
7130
|
+
const googleLevel = toGoogleThinkingLevel(model, "off");
|
|
7131
|
+
if (!googleLevel)
|
|
7132
|
+
return thinkingConfig;
|
|
7133
|
+
const { thinkingBudget: _thinkingBudget, ...rest } = thinkingConfig;
|
|
7134
|
+
return {
|
|
7135
|
+
...rest,
|
|
7136
|
+
thinkingLevel: googleLevel
|
|
7137
|
+
};
|
|
7138
|
+
}
|
|
7139
|
+
return thinkingConfig;
|
|
7140
|
+
}
|
|
7141
|
+
function normalizeGoogleThinkingConfig(payload, model, thinkingLevel) {
|
|
7142
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
7143
|
+
return payload;
|
|
7144
|
+
if (!model?.reasoning)
|
|
7145
|
+
return payload;
|
|
7146
|
+
if (model.api !== "google-generative-ai" && model.api !== "google-vertex")
|
|
7147
|
+
return payload;
|
|
7148
|
+
if (!usesGoogleThinkingLevel(model))
|
|
7149
|
+
return payload;
|
|
7150
|
+
const next = { ...payload };
|
|
7151
|
+
let changed = false;
|
|
7152
|
+
for (const configKey of ["config", "generationConfig"]) {
|
|
7153
|
+
const container = next[configKey];
|
|
7154
|
+
if (!container || typeof container !== "object" || Array.isArray(container))
|
|
7155
|
+
continue;
|
|
7156
|
+
const containerRecord = container;
|
|
7157
|
+
const thinkingConfig = containerRecord.thinkingConfig;
|
|
7158
|
+
if (!thinkingConfig || typeof thinkingConfig !== "object" || Array.isArray(thinkingConfig)) {
|
|
7159
|
+
continue;
|
|
7160
|
+
}
|
|
7161
|
+
const normalized = normalizeThinkingConfigObject(thinkingConfig, model, thinkingLevel);
|
|
7162
|
+
if (normalized !== thinkingConfig) {
|
|
7163
|
+
next[configKey] = {
|
|
7164
|
+
...containerRecord,
|
|
7165
|
+
thinkingConfig: normalized
|
|
6901
7166
|
};
|
|
6902
7167
|
changed = true;
|
|
6903
7168
|
}
|
|
6904
7169
|
}
|
|
6905
7170
|
return changed ? next : payload;
|
|
6906
7171
|
}
|
|
7172
|
+
function getSessionThinkingLevel(pi) {
|
|
7173
|
+
try {
|
|
7174
|
+
return pi.getThinkingLevel?.();
|
|
7175
|
+
} catch {
|
|
7176
|
+
return;
|
|
7177
|
+
}
|
|
7178
|
+
}
|
|
6907
7179
|
function withAuthoritativeApiKeyEnv(provider, envName, getHeaderModels = () => []) {
|
|
6908
7180
|
const apiKey = provider.auth.apiKey;
|
|
6909
7181
|
if (!apiKey)
|
|
@@ -6994,12 +7266,14 @@ function createPolicyHost(deps) {
|
|
|
6994
7266
|
function plexusExtension(pi) {
|
|
6995
7267
|
const contextPolicies = new ContextPolicyPublisher(pi.events);
|
|
6996
7268
|
const serviceTiers = new ServiceTiersPublisher(pi.events);
|
|
7269
|
+
const shortNames = new ShortNamesPublisher(pi.events);
|
|
6997
7270
|
const state = {
|
|
6998
7271
|
models: [],
|
|
6999
7272
|
catalogSource: "none",
|
|
7000
7273
|
refreshSequence: 0,
|
|
7001
7274
|
contextPolicies,
|
|
7002
7275
|
serviceTiers,
|
|
7276
|
+
shortNames,
|
|
7003
7277
|
policy: undefined,
|
|
7004
7278
|
activeModel: undefined,
|
|
7005
7279
|
registry: undefined
|
|
@@ -7039,12 +7313,15 @@ function plexusExtension(pi) {
|
|
|
7039
7313
|
pi.on("session_shutdown", () => {
|
|
7040
7314
|
contextPolicies.dispose();
|
|
7041
7315
|
serviceTiers.dispose();
|
|
7316
|
+
shortNames.dispose();
|
|
7042
7317
|
policy.dispose();
|
|
7043
7318
|
modelsControl.dispose();
|
|
7044
7319
|
if (state.contextPolicies === contextPolicies)
|
|
7045
7320
|
state.contextPolicies = undefined;
|
|
7046
7321
|
if (state.serviceTiers === serviceTiers)
|
|
7047
7322
|
state.serviceTiers = undefined;
|
|
7323
|
+
if (state.shortNames === shortNames)
|
|
7324
|
+
state.shortNames = undefined;
|
|
7048
7325
|
if (state.policy === policy)
|
|
7049
7326
|
state.policy = undefined;
|
|
7050
7327
|
});
|
|
@@ -7066,6 +7343,10 @@ function plexusExtension(pi) {
|
|
|
7066
7343
|
cached: true,
|
|
7067
7344
|
...cachedTiers.fetchedAt === undefined ? {} : { fetchedAt: cachedTiers.fetchedAt }
|
|
7068
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
|
+
});
|
|
7069
7350
|
}
|
|
7070
7351
|
policy.reconcile();
|
|
7071
7352
|
pi.on("session_start", (_event, ctx) => {
|
|
@@ -7083,7 +7364,8 @@ function plexusExtension(pi) {
|
|
|
7083
7364
|
return;
|
|
7084
7365
|
state.activeModel = ctx.model;
|
|
7085
7366
|
const withTier = injectServiceTier(event.payload, state.policy?.serviceTierFor(ctx.model));
|
|
7086
|
-
const
|
|
7367
|
+
const withThinking = normalizeGoogleThinkingConfig(withTier, ctx.model, ctx.thinkingLevel ?? getSessionThinkingLevel(pi));
|
|
7368
|
+
const next = enforceMinimumOutputTokens(withThinking);
|
|
7087
7369
|
return next === event.payload ? undefined : next;
|
|
7088
7370
|
});
|
|
7089
7371
|
log("startup", {
|
|
@@ -7173,6 +7455,7 @@ async function refreshPlexusModels(state, context) {
|
|
|
7173
7455
|
cached: true,
|
|
7174
7456
|
reason: CONTEXT_POLICY_METADATA_UNAVAILABLE_REASON
|
|
7175
7457
|
});
|
|
7458
|
+
state.shortNames?.setCatalog("ready", collectStoredShortNames(filteredCurrent), { cached: true });
|
|
7176
7459
|
state.policy?.reconcile();
|
|
7177
7460
|
}
|
|
7178
7461
|
});
|
|
@@ -7186,6 +7469,11 @@ async function refreshPlexusModels(state, context) {
|
|
|
7186
7469
|
reason: "Plexus model metadata is not configured."
|
|
7187
7470
|
});
|
|
7188
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
|
+
}
|
|
7189
7477
|
throw new Error(!modelsUrl || !baseUrl ? "Plexus base URL not configured. Run /login plexus first." : "No Plexus API key configured. Run /login plexus first.");
|
|
7190
7478
|
}
|
|
7191
7479
|
try {
|
|
@@ -7207,9 +7495,15 @@ async function refreshPlexusModels(state, context) {
|
|
|
7207
7495
|
policy: serviceTierPolicyFromApiModel(model),
|
|
7208
7496
|
fetchedAt
|
|
7209
7497
|
};
|
|
7498
|
+
const shortName = shortNameEntryFromApiModel(model);
|
|
7499
|
+
if (shortName)
|
|
7500
|
+
piModel.plexusShortName = shortName.shortName;
|
|
7501
|
+
else
|
|
7502
|
+
delete piModel.plexusShortName;
|
|
7210
7503
|
}
|
|
7211
7504
|
const committedPolicies = collectStoredContextPolicies(piModels);
|
|
7212
7505
|
const committedServiceTiers = collectStoredServiceTiers(piModels).policies;
|
|
7506
|
+
const committedShortNames = collectStoredShortNames(piModels);
|
|
7213
7507
|
const published = await context.publish({
|
|
7214
7508
|
persist: {
|
|
7215
7509
|
models: piModels,
|
|
@@ -7221,6 +7515,9 @@ async function refreshPlexusModels(state, context) {
|
|
|
7221
7515
|
state.serviceTiers?.setCatalog("ready", committedServiceTiers, {
|
|
7222
7516
|
fetchedAt
|
|
7223
7517
|
});
|
|
7518
|
+
state.shortNames?.setCatalog("ready", committedShortNames, {
|
|
7519
|
+
fetchedAt
|
|
7520
|
+
});
|
|
7224
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 });
|
|
7225
7522
|
state.policy?.reconcile();
|
|
7226
7523
|
}
|
|
@@ -7241,6 +7538,11 @@ async function refreshPlexusModels(state, context) {
|
|
|
7241
7538
|
reason: "Plexus model metadata could not be loaded."
|
|
7242
7539
|
});
|
|
7243
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
|
+
}
|
|
7244
7546
|
log("refreshModels: fetch failed", { error: String(error) });
|
|
7245
7547
|
throw error;
|
|
7246
7548
|
}
|
|
@@ -7265,6 +7567,9 @@ async function restoreStoredModels(state, context) {
|
|
|
7265
7567
|
cached: true,
|
|
7266
7568
|
reason: CONTEXT_POLICY_METADATA_UNAVAILABLE_REASON
|
|
7267
7569
|
});
|
|
7570
|
+
state.shortNames?.setCatalog("ready", collectStoredShortNames(models), {
|
|
7571
|
+
cached: true
|
|
7572
|
+
});
|
|
7268
7573
|
state.policy?.reconcile();
|
|
7269
7574
|
}
|
|
7270
7575
|
});
|
|
@@ -7302,6 +7607,30 @@ function serviceTierPolicyFromApiModel(model) {
|
|
|
7302
7607
|
const parsed = ServiceTierPolicySchema.safeParse(candidate);
|
|
7303
7608
|
return parsed.success ? parsed.data : undefined;
|
|
7304
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
|
+
}
|
|
7305
7634
|
function collectStoredServiceTiers(models) {
|
|
7306
7635
|
const metadata = models.map((model) => model.plexusServiceTiers);
|
|
7307
7636
|
const complete = models.length === 0 || metadata.every((entry) => entry !== undefined);
|
|
@@ -7405,6 +7734,9 @@ export {
|
|
|
7405
7734
|
createPolicyHost,
|
|
7406
7735
|
plexusExtension as default,
|
|
7407
7736
|
enforceMinimumOutputTokens,
|
|
7737
|
+
normalizeGoogleThinkingConfig,
|
|
7408
7738
|
serviceTierPolicyFromApiModel,
|
|
7739
|
+
shortNameEntryFromApiModel,
|
|
7740
|
+
usesGoogleThinkingLevel,
|
|
7409
7741
|
withAuthoritativeApiKeyEnv
|
|
7410
7742
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcowger/pi-plexus",
|
|
3
|
-
"version": "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.
|