pi-cliproxyapi-provider 0.3.4 → 0.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cliproxyapi-provider",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Pi provider package for CLIProxyAPI with automatic model discovery and models.dev enrichment.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/catalog.ts CHANGED
@@ -75,15 +75,19 @@ export class ProviderCatalog {
75
75
  return this.setSnapshot(cpaCache?.data ?? [], cpaCache?.fetchedAt, metadataSnapshot.data, metadataSnapshot.fetchedAt, metadataSnapshot.source);
76
76
  }
77
77
 
78
- async refresh(target: RefreshTarget = "all", mode: "background" | "manual" = "manual"): Promise<CatalogRefreshResult> {
78
+ async refresh(
79
+ target: RefreshTarget = "all",
80
+ mode: "background" | "manual" = "manual",
81
+ getDiscoveryApiKey?: () => Promise<string | undefined>,
82
+ ): Promise<CatalogRefreshResult> {
79
83
  if (this.activeRefresh) {
80
- if (this.activeRefreshTarget === target && this.activeRefreshMode === mode) return this.activeRefresh;
84
+ if (this.activeRefreshTarget === target && this.activeRefreshMode === mode && getDiscoveryApiKey === undefined) return this.activeRefresh;
81
85
  await this.activeRefresh;
82
86
  }
83
87
 
84
88
  this.activeRefreshTarget = target;
85
89
  this.activeRefreshMode = mode;
86
- this.activeRefresh = this.performRefresh(target, mode).finally(() => {
90
+ this.activeRefresh = this.performRefresh(target, mode, getDiscoveryApiKey).finally(() => {
87
91
  this.activeRefresh = undefined;
88
92
  this.activeRefreshTarget = undefined;
89
93
  this.activeRefreshMode = undefined;
@@ -95,7 +99,11 @@ export class ProviderCatalog {
95
99
  return this.snapshot;
96
100
  }
97
101
 
98
- private async performRefresh(target: RefreshTarget, mode: "background" | "manual"): Promise<CatalogRefreshResult> {
102
+ private async performRefresh(
103
+ target: RefreshTarget,
104
+ mode: "background" | "manual",
105
+ getDiscoveryApiKey?: () => Promise<string | undefined>,
106
+ ): Promise<CatalogRefreshResult> {
99
107
  const current = this.snapshot ?? await this.load();
100
108
  let cpaModels = current.cpaModels;
101
109
  let cpaUpdatedAt = current.cpaUpdatedAt;
@@ -108,7 +116,7 @@ export class ProviderCatalog {
108
116
 
109
117
  if (models.attempted) {
110
118
  try {
111
- const apiKey = await this.options.getApiKey();
119
+ const apiKey = await (getDiscoveryApiKey ?? this.options.getApiKey)();
112
120
  const fresh = await fetchCpaModels(
113
121
  this.options.config.baseUrl,
114
122
  discoveryHeaders(this.options.config, apiKey),
package/src/commands.ts CHANGED
@@ -147,7 +147,10 @@ export function registerCliproxyapiCommand(pi: ExtensionAPI, runtime?: ProviderR
147
147
  ctx.ui.notify("Usage: /cliproxyapi refresh [models|metadata]", "warning");
148
148
  return;
149
149
  }
150
- const result = await runtime.refresh(target, "manual");
150
+ const getDiscoveryApiKey = target === "metadata"
151
+ ? undefined
152
+ : () => ctx.modelRegistry.getApiKeyForProvider(config.providerName);
153
+ const result = await runtime.refresh(target, "manual", getDiscoveryApiKey);
151
154
  const level = result.models.error || result.metadata.error ? "warning" : "info";
152
155
  ctx.ui.notify([
153
156
  "CLIProxyAPI provider refresh complete.",
package/src/runtime.ts CHANGED
@@ -24,8 +24,12 @@ export class ProviderRuntime {
24
24
  return snapshot;
25
25
  }
26
26
 
27
- async refresh(target: RefreshTarget = "all", mode: "background" | "manual" = "manual"): Promise<CatalogRefreshResult> {
28
- const result = await this.options.catalog.refresh(target, mode);
27
+ async refresh(
28
+ target: RefreshTarget = "all",
29
+ mode: "background" | "manual" = "manual",
30
+ getDiscoveryApiKey?: () => Promise<string | undefined>,
31
+ ): Promise<CatalogRefreshResult> {
32
+ const result = await this.options.catalog.refresh(target, mode, getDiscoveryApiKey);
29
33
  if (result.models.updated || result.metadata.updated) this.register(result.snapshot, false);
30
34
  return result;
31
35
  }