|
1 | 1 | import axios from "axios" |
2 | 2 | import { v7 as uuidv7 } from "uuid" |
3 | 3 | import { COSTRICT_DEFAULT_HEADERS } from "../../../shared/headers" |
4 | | -import type { IZgsmModelResponseData } from "@roo-code/types" |
| 4 | +import type { IZgsmModelResponseData, QuotaInfo } from "@roo-code/types" |
5 | 5 | import { readModels } from "./modelCache" |
6 | 6 |
|
7 | 7 | // let modelsCache = new WeakRef<string[]>([]) |
@@ -44,3 +44,36 @@ export async function getZgsmModels(baseUrl?: string, apiKey?: string, openAiHea |
44 | 44 | return Object.keys(modelCache).map((key) => modelCache[key]) |
45 | 45 | } |
46 | 46 | } |
| 47 | + |
| 48 | +export async function fetchZgsmQuotaInfo(baseUrl?: string, apiKey?: string): Promise<QuotaInfo | null> { |
| 49 | + try { |
| 50 | + if (!baseUrl || !apiKey) { |
| 51 | + return null |
| 52 | + } |
| 53 | + |
| 54 | + // Trim whitespace from baseUrl to handle cases where users accidentally include spaces |
| 55 | + const trimmedBaseUrl = baseUrl.trim() |
| 56 | + |
| 57 | + if (!URL.canParse(trimmedBaseUrl)) { |
| 58 | + return null |
| 59 | + } |
| 60 | + |
| 61 | + const config: Record<string, any> = {} |
| 62 | + const headers: Record<string, string> = { |
| 63 | + ...COSTRICT_DEFAULT_HEADERS, |
| 64 | + "X-Request-ID": uuidv7(), |
| 65 | + Authorization: `Bearer ${apiKey}`, |
| 66 | + "Content-Type": "application/json", |
| 67 | + } |
| 68 | + |
| 69 | + if (Object.keys(headers).length > 0) { |
| 70 | + config["headers"] = headers |
| 71 | + } |
| 72 | + const response = await axios.get(`${baseUrl}/quota-manager/api/v1/quota`, config) |
| 73 | + |
| 74 | + return response?.data?.data as QuotaInfo |
| 75 | + } catch (error) { |
| 76 | + console.warn(`Error fetching zgsmModels from [${baseUrl}/quota-manager/api/v1/quota]:`, error.message) |
| 77 | + return null |
| 78 | + } |
| 79 | +} |
0 commit comments