pi-provider-litellm 4.7.0 → 4.7.1
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 +1 -1
- package/package.json +1 -1
- package/src/discover.ts +31 -18
- package/src/index.ts +3 -0
- package/src/provider.ts +5 -1
package/README.md
CHANGED
|
@@ -494,7 +494,7 @@ routes.
|
|
|
494
494
|
|
|
495
495
|
The `LiteLLM Smoke` GitHub Actions workflow starts VidaiMock and a real LiteLLM proxy on the runner. LiteLLM exposes route-distinct Chat, Responses, native Messages, and mixed-deployment models whose upstreams are served by VidaiMock. The smoke runner discovers those models through LiteLLM, asserts each model's expected API, exercises `/v1/chat/completions`, `/v1/responses`, and `/v1/messages`, verifies the expected `x-litellm-response-cost` behavior, and proves endpoint coverage from captured LiteLLM request logs rather than response text.
|
|
496
496
|
|
|
497
|
-
This keeps the LiteLLM integration path under test but does not call real LLM APIs. No provider API keys or GitHub Models permission are required. The smoke runner also asserts that discovery came from `/model/info` (`LITELLM_SMOKE_EXPECT_SOURCE`) so a silent fallback to `/v1/models` fails the run. The workflow also runs auth checks plus optional Postgres-backed auth checks when `LITELLM_LICENSE` is configured for virtual-key and admin-route behavior, then runs a non-interactive Pi CLI smoke with `--list-models` and `-p` against both the OpenAI-compatible and Anthropic-backed routes, so extension loading, model discovery, and real completion paths are covered without opening the TUI. It also runs an interactive Pi TUI smoke covering `/login litellm` and Pi's native `/model` refresh. VidaiMock returns fixed responses, so the real-proxy smoke does not exercise a model-originated tool call or thinking block; the native Messages compatibility suite covers thinking, tool use, tool results, and replay across turns.
|
|
497
|
+
This keeps the LiteLLM integration path under test but does not call real LLM APIs. No provider API keys or GitHub Models permission are required. The manual `LiteLLM Live Smoke` workflow (`.github/workflows/litellm-live-smoke.yml`) runs the same proxy and smoke runner with a real Anthropic Console key from the repository secret named in that file, publishing cheap Claude backends as native Messages, Chat Completions, and Responses routes; each run spends a few hundred tokens of real credits. The smoke runner also asserts that discovery came from `/model/info` (`LITELLM_SMOKE_EXPECT_SOURCE`) so a silent fallback to `/v1/models` fails the run. The workflow also runs auth checks plus optional Postgres-backed auth checks when `LITELLM_LICENSE` is configured for virtual-key and admin-route behavior, then runs a non-interactive Pi CLI smoke with `--list-models` and `-p` against both the OpenAI-compatible and Anthropic-backed routes, so extension loading, model discovery, and real completion paths are covered without opening the TUI. It also runs an interactive Pi TUI smoke covering `/login litellm` and Pi's native `/model` refresh. VidaiMock returns fixed responses, so the real-proxy smoke does not exercise a model-originated tool call or thinking block; the native Messages compatibility suite covers thinking, tool use, tool results, and replay across turns.
|
|
498
498
|
|
|
499
499
|
## Development
|
|
500
500
|
|
package/package.json
CHANGED
package/src/discover.ts
CHANGED
|
@@ -650,7 +650,12 @@ export async function fetchJson<T>(
|
|
|
650
650
|
|
|
651
651
|
const DIAGNOSTIC_ROUTE_SAMPLE = 3;
|
|
652
652
|
|
|
653
|
+
type Report = (message: string) => void;
|
|
654
|
+
|
|
655
|
+
const writeStderr: Report = (message) => process.stderr.write(`${message}\n`);
|
|
656
|
+
|
|
653
657
|
function reportBoundedRoutes(
|
|
658
|
+
report: Report,
|
|
654
659
|
reported: Set<string>,
|
|
655
660
|
routes: readonly string[],
|
|
656
661
|
describe: (count: number) => string,
|
|
@@ -660,7 +665,7 @@ function reportBoundedRoutes(
|
|
|
660
665
|
for (const route of unreported) reported.add(route);
|
|
661
666
|
const hidden = unreported.length - DIAGNOSTIC_ROUTE_SAMPLE;
|
|
662
667
|
const sample = unreported.slice(0, DIAGNOSTIC_ROUTE_SAMPLE).join(", ");
|
|
663
|
-
|
|
668
|
+
report(`${describe(unreported.length)}: ${sample}${hidden > 0 ? ` (+${hidden} more)` : ""}`);
|
|
664
669
|
}
|
|
665
670
|
|
|
666
671
|
// Reported routes, so a persistent misconfiguration is announced once rather than on
|
|
@@ -673,8 +678,9 @@ const reportedAmbiguousRoutes = new Set<string>();
|
|
|
673
678
|
// supplies complete prices; limits and other catalog-derived metadata may still use
|
|
674
679
|
// conservative defaults. Report that degradation regardless of
|
|
675
680
|
// LITELLM_VERBOSE_DISCOVERY, carrying only a count and bounded public route ids.
|
|
676
|
-
function reportAmbiguousCatalogAuthority(routes: readonly string[]): void {
|
|
681
|
+
function reportAmbiguousCatalogAuthority(report: Report, routes: readonly string[]): void {
|
|
677
682
|
reportBoundedRoutes(
|
|
683
|
+
report,
|
|
678
684
|
reportedAmbiguousRoutes,
|
|
679
685
|
routes,
|
|
680
686
|
(count) =>
|
|
@@ -685,8 +691,9 @@ function reportAmbiguousCatalogAuthority(routes: readonly string[]): void {
|
|
|
685
691
|
|
|
686
692
|
const reportedIncompatibleModeRoutes = new Set<string>();
|
|
687
693
|
|
|
688
|
-
function reportIncompatibleDeploymentModes(routes: readonly string[]): void {
|
|
694
|
+
function reportIncompatibleDeploymentModes(report: Report, routes: readonly string[]): void {
|
|
689
695
|
reportBoundedRoutes(
|
|
696
|
+
report,
|
|
690
697
|
reportedIncompatibleModeRoutes,
|
|
691
698
|
routes,
|
|
692
699
|
(count) =>
|
|
@@ -893,9 +900,10 @@ function mapFromModelsList(entry: ModelsListEntry): DiscoveredModel | undefined
|
|
|
893
900
|
async function discoverFromHealth(
|
|
894
901
|
base: string,
|
|
895
902
|
apiKey: string,
|
|
896
|
-
options: DiscoveryOptions & { onProgress?: (message: string) => void; silent?: boolean },
|
|
903
|
+
options: DiscoveryOptions & { onProgress?: (message: string) => void; report?: Report; silent?: boolean },
|
|
897
904
|
): Promise<DiscoveredModel[]> {
|
|
898
905
|
const progress = options.silent ? undefined : options.onProgress;
|
|
906
|
+
const report = options.report ?? writeStderr;
|
|
899
907
|
progress?.("Querying /health endpoint...");
|
|
900
908
|
const healthResult = await fetchJson<HealthResponse>(`${base}/health`, apiKey, options);
|
|
901
909
|
if (!healthResult.ok) return [];
|
|
@@ -971,11 +979,11 @@ async function discoverFromHealth(
|
|
|
971
979
|
});
|
|
972
980
|
})
|
|
973
981
|
.filter((model): model is DiscoveredModel => model !== undefined);
|
|
974
|
-
reportIncompatibleDeploymentModes(incompatibleModeRoutes);
|
|
975
|
-
reportAmbiguousCatalogAuthority(ambiguousRoutes);
|
|
976
|
-
reportConflictingFamilyEvidence(conflictingFamilyRoutes);
|
|
977
|
-
reportWithheldToolRepair(withheldRepairRoutes);
|
|
978
|
-
reportWithheldToolRepairForModels(discovered);
|
|
982
|
+
reportIncompatibleDeploymentModes(report, incompatibleModeRoutes);
|
|
983
|
+
reportAmbiguousCatalogAuthority(report, ambiguousRoutes);
|
|
984
|
+
reportConflictingFamilyEvidence(report, conflictingFamilyRoutes);
|
|
985
|
+
reportWithheldToolRepair(report, withheldRepairRoutes);
|
|
986
|
+
reportWithheldToolRepairForModels(report, discovered);
|
|
979
987
|
return discovered;
|
|
980
988
|
}
|
|
981
989
|
|
|
@@ -1210,10 +1218,11 @@ function mapFromWildcardExpansion(
|
|
|
1210
1218
|
export async function discoverModels(
|
|
1211
1219
|
baseUrl: string,
|
|
1212
1220
|
apiKey: string,
|
|
1213
|
-
options: DiscoveryOptions & { onProgress?: (message: string) => void; silent?: boolean } = {},
|
|
1221
|
+
options: DiscoveryOptions & { onProgress?: (message: string) => void; report?: Report; silent?: boolean } = {},
|
|
1214
1222
|
): Promise<DiscoveryResult> {
|
|
1215
1223
|
const base = normalizeBaseUrl(baseUrl, options.allowInsecureHttp);
|
|
1216
1224
|
const progress = options.silent ? undefined : options.onProgress;
|
|
1225
|
+
const report = options.report ?? writeStderr;
|
|
1217
1226
|
progress?.("Querying /model/info endpoint...");
|
|
1218
1227
|
const infoResult = await fetchJson<ModelInfoResponse>(`${base}/model/info`, apiKey, options);
|
|
1219
1228
|
// An empty `/model/info` list is treated like an unavailable endpoint: some proxies
|
|
@@ -1265,10 +1274,10 @@ export async function discoverModels(
|
|
|
1265
1274
|
let models = reducedGroups
|
|
1266
1275
|
.map(({ model }) => model)
|
|
1267
1276
|
.filter((model): model is DiscoveredModel => model !== undefined);
|
|
1268
|
-
reportIncompatibleDeploymentModes(incompatibleModeRoutes);
|
|
1269
|
-
reportAmbiguousCatalogAuthority(ambiguousRoutes);
|
|
1270
|
-
reportConflictingFamilyEvidence(conflictingFamilyRoutes);
|
|
1271
|
-
reportWithheldToolRepair(withheldRepairRoutes);
|
|
1277
|
+
reportIncompatibleDeploymentModes(report, incompatibleModeRoutes);
|
|
1278
|
+
reportAmbiguousCatalogAuthority(report, ambiguousRoutes);
|
|
1279
|
+
reportConflictingFamilyEvidence(report, conflictingFamilyRoutes);
|
|
1280
|
+
reportWithheldToolRepair(report, withheldRepairRoutes);
|
|
1272
1281
|
// LiteLLM's /model/info does NOT expand wildcard model_name entries (e.g.
|
|
1273
1282
|
// "lemonade/*" backed by model: openai/* + check_provider_endpoint: true)
|
|
1274
1283
|
// — it returns the literal wildcard only. The discovered ids live in
|
|
@@ -1338,7 +1347,7 @@ export async function discoverModels(
|
|
|
1338
1347
|
models = [...models, ...expanded];
|
|
1339
1348
|
}
|
|
1340
1349
|
}
|
|
1341
|
-
reportWithheldToolRepair(withheldRepairRoutes);
|
|
1350
|
+
reportWithheldToolRepair(report, withheldRepairRoutes);
|
|
1342
1351
|
models = deduplicateModels(models);
|
|
1343
1352
|
if (process.env.LITELLM_VERBOSE_DISCOVERY === "1") {
|
|
1344
1353
|
const defaultedWildcards = wildcardRoutes.filter(({ route }) => defaultedContextRoutes.has(route));
|
|
@@ -1352,6 +1361,7 @@ export async function discoverModels(
|
|
|
1352
1361
|
),
|
|
1353
1362
|
);
|
|
1354
1363
|
reportBoundedRoutes(
|
|
1364
|
+
report,
|
|
1355
1365
|
reportedDefaultedContextRoutes,
|
|
1356
1366
|
defaulted.map((model) => JSON.stringify(model.id)),
|
|
1357
1367
|
(count) =>
|
|
@@ -1536,8 +1546,9 @@ function deploymentFamily(entry: ModelInfoEntry): CatalogResolution["semanticFam
|
|
|
1536
1546
|
return adapterFamily === identityFamily ? identityFamily : "conflicting";
|
|
1537
1547
|
}
|
|
1538
1548
|
|
|
1539
|
-
function reportConflictingFamilyEvidence(routes: readonly string[]): void {
|
|
1549
|
+
function reportConflictingFamilyEvidence(report: Report, routes: readonly string[]): void {
|
|
1540
1550
|
reportBoundedRoutes(
|
|
1551
|
+
report,
|
|
1541
1552
|
reportedConflictingFamilyRoutes,
|
|
1542
1553
|
routes,
|
|
1543
1554
|
(count) =>
|
|
@@ -1546,8 +1557,9 @@ function reportConflictingFamilyEvidence(routes: readonly string[]): void {
|
|
|
1546
1557
|
);
|
|
1547
1558
|
}
|
|
1548
1559
|
|
|
1549
|
-
function reportWithheldToolRepair(routes: readonly string[]): void {
|
|
1560
|
+
function reportWithheldToolRepair(report: Report, routes: readonly string[]): void {
|
|
1550
1561
|
reportBoundedRoutes(
|
|
1562
|
+
report,
|
|
1551
1563
|
reportedWithheldRepairRoutes,
|
|
1552
1564
|
routes,
|
|
1553
1565
|
(count) =>
|
|
@@ -1558,8 +1570,9 @@ function reportWithheldToolRepair(routes: readonly string[]): void {
|
|
|
1558
1570
|
);
|
|
1559
1571
|
}
|
|
1560
1572
|
|
|
1561
|
-
function reportWithheldToolRepairForModels(models: readonly DiscoveredModel[]): void {
|
|
1573
|
+
function reportWithheldToolRepairForModels(report: Report, models: readonly DiscoveredModel[]): void {
|
|
1562
1574
|
reportWithheldToolRepair(
|
|
1575
|
+
report,
|
|
1563
1576
|
models
|
|
1564
1577
|
.filter(
|
|
1565
1578
|
(model) =>
|
package/src/index.ts
CHANGED
|
@@ -2449,6 +2449,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
2449
2449
|
let sessionStarted = false;
|
|
2450
2450
|
const pendingMcpMessages = new Map<string, "info" | "warning">();
|
|
2451
2451
|
|
|
2452
|
+
// Also carries provider and discovery diagnostics: raw stderr would paint over the running TUI.
|
|
2452
2453
|
function notifyMcp(message: string, level: "info" | "warning" = "warning"): void {
|
|
2453
2454
|
const text = message.trimEnd();
|
|
2454
2455
|
if (mcpUI) mcpUI.notify(text, level);
|
|
@@ -2701,6 +2702,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
2701
2702
|
modelOverrides: await readModelLimitOverrides(),
|
|
2702
2703
|
silent: !isVerboseDiscovery(),
|
|
2703
2704
|
onProgress: isVerboseDiscovery() ? (message) => process.stderr.write(`LiteLLM: ${message}\n`) : undefined,
|
|
2705
|
+
report: (message) => notifyMcp(message),
|
|
2704
2706
|
});
|
|
2705
2707
|
signal?.throwIfAborted();
|
|
2706
2708
|
return { ...result, baseUrl: normalizeBaseUrl(auth.baseUrl, auth.allowInsecureHttp) };
|
|
@@ -2824,6 +2826,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
2824
2826
|
if (disabledReason) throw new Error(`discovery disabled (${disabledReason})`);
|
|
2825
2827
|
return runDiscovery(await authForCredential(definition, credential), signal);
|
|
2826
2828
|
},
|
|
2829
|
+
report: (message) => notifyMcp(message),
|
|
2827
2830
|
});
|
|
2828
2831
|
Object.assign(provider, { headers: resolveHeaders(definition) });
|
|
2829
2832
|
const refreshModels = provider.refreshModels!;
|
package/src/provider.ts
CHANGED
|
@@ -48,6 +48,8 @@ export type LiteLLMProviderOptions = {
|
|
|
48
48
|
allowInsecureHttp?: boolean;
|
|
49
49
|
resolveCredentialRoot: (credential?: Credential, requestBaseUrl?: string, apiKey?: string) => string | undefined;
|
|
50
50
|
discover(credential: Credential, signal?: AbortSignal): Promise<DiscoveryResult & { baseUrl?: string }>;
|
|
51
|
+
/** Shows a diagnostic line. Defaults to stderr, which paints over Pi's TUI once it is running. */
|
|
52
|
+
report?: (message: string) => void;
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
// Chat models may omit `type`.
|
|
@@ -220,7 +222,9 @@ export function createLiteLLMProvider(options: LiteLLMProviderOptions): Provider
|
|
|
220
222
|
const reportUnavailable = (message: string): void => {
|
|
221
223
|
if (reportedAvailabilityDiagnostics.has(message)) return;
|
|
222
224
|
reportedAvailabilityDiagnostics.add(message);
|
|
223
|
-
|
|
225
|
+
const line = `LiteLLM (${options.id}): ${message}`;
|
|
226
|
+
if (options.report) options.report(line);
|
|
227
|
+
else process.stderr.write(`${line}\n`);
|
|
224
228
|
};
|
|
225
229
|
type ActiveRoot = { root: string; canonical: string; hostname: string };
|
|
226
230
|
const resolveActiveRoot = (credential: Credential | undefined, hiddenCount: number): ActiveRoot | undefined => {
|