chore(vendor): import pi 1.3.0

Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
alexion committed 2026-10-15 17:58:48 -04:00
1 parent 719370c8f7
commit 6081e3e325
1743 files changed
+205459 -131704

No files matched your search

+14 -6
View File
@@ -2,6 +2,8 @@ import { piMessagesApi } from "../api/pi-messages.lazy.ts";
import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.ts";
import { loadRadiusOAuth } from "../auth/oauth/load.ts";
import type { Provider } from "../models.ts";
import type { Model } from "../types.ts";
import { RADIUS_MODELS } from "./radius.models.ts";
import {
DEFAULT_RADIUS_GATEWAY,
getRadiusModels,
@@ -21,7 +23,13 @@ export function radiusProvider(options: RadiusProviderOptions = {}): Provider<"p
const id = options.id ?? "radius";
const name = options.name ?? "Radius";
const gateway = normalizeRadiusGatewayUrl(options.gateway ?? DEFAULT_RADIUS_GATEWAY);
let models = getRadiusModels(id, undefined);
const baselineModels: Model<"pi-messages">[] =
gateway === normalizeRadiusGatewayUrl(DEFAULT_RADIUS_GATEWAY)
? Object.values(RADIUS_MODELS).map((model) => ({ ...model, provider: id }))
: [];
// Gateway catalog for this account. Radius org owners can disable models, so once known it replaces
// the shipped baseline instead of overlaying it. The baseline only covers the time before any catalog exists.
let dynamicModels: Model<"pi-messages">[] | undefined;
const streams = piMessagesApi();
return {
@@ -31,15 +39,15 @@ export function radiusProvider(options: RadiusProviderOptions = {}): Provider<"p
apiKey: envApiKeyAuth("Radius API key", ["RADIUS_API_KEY"]),
oauth: lazyOAuth({ name, load: () => loadRadiusOAuth({ name, gateway }) }),
},
getModels: () => models,
getModels: () => dynamicModels ?? baselineModels,
refreshModels: async (context) => {
const stored = context.stored;
if (stored) {
const restored = stored.models.filter((model) => model.provider === id) as typeof models;
const restored = stored.models.filter((model) => model.provider === id) as Model<"pi-messages">[];
if (
!(await context.publish({
update: () => {
models = restored;
dynamicModels = restored;
},
}))
) {
@@ -55,7 +63,7 @@ export function radiusProvider(options: RadiusProviderOptions = {}): Provider<"p
!(await context.publish({
persist: { models: legacy, checkedAt: Date.now() },
update: () => {
models = legacy;
dynamicModels = legacy;
},
}))
) {
@@ -72,7 +80,7 @@ export function radiusProvider(options: RadiusProviderOptions = {}): Provider<"p
await context.publish({
persist: { models: refreshed, checkedAt: Date.now() },
update: () => {
models = refreshed;
dynamicModels = refreshed;
},
});
},