@hyav/pi-provider 0.1.3 → 0.1.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/CHANGELOG.md +24 -0
- package/README.md +8 -1
- package/README.zh-CN.md +8 -1
- package/core/adapter-validation.ts +23 -6
- package/core/catalog-preflight.ts +142 -0
- package/core/credential-type.ts +13 -0
- package/core/diagnostic-auth.ts +103 -0
- package/core/host.ts +26 -4
- package/core/live-check-manager.ts +2 -1
- package/core/official-pricing.ts +39 -17
- package/core/preflight-manager.ts +40 -8
- package/core/provider-registration.ts +105 -6
- package/core/public-adapters.ts +10 -0
- package/core/ratelimit-headers.ts +72 -0
- package/core/runtime-config.ts +3 -0
- package/core/runtime.ts +55 -34
- package/core/status-manager.ts +34 -9
- package/core/types.ts +22 -2
- package/index.ts +12 -1
- package/package.json +1 -1
- package/preflight/anthropic.ts +42 -0
- package/preflight/cerebras.ts +27 -0
- package/preflight/charm-hyper.ts +2 -1
- package/preflight/deepseek.ts +2 -1
- package/preflight/github-copilot.ts +87 -0
- package/preflight/google.ts +2 -1
- package/preflight/groq.ts +73 -0
- package/preflight/huggingface.ts +27 -0
- package/preflight/mistral.ts +27 -0
- package/preflight/moonshotai-cn.ts +27 -0
- package/preflight/moonshotai.ts +37 -0
- package/preflight/nvidia.ts +27 -0
- package/preflight/openai-codex.ts +2 -1
- package/preflight/openai.ts +27 -0
- package/preflight/openrouter.ts +112 -0
- package/preflight/vercel-ai-gateway.ts +81 -0
- package/preflight/xai.ts +71 -0
- package/providers/charm-hyper.ts +4 -1
- package/status/anthropic.ts +262 -0
- package/status/charm-hyper.ts +3 -2
- package/status/deepseek.ts +2 -1
- package/status/github-copilot.ts +189 -0
- package/status/groq.ts +89 -0
- package/status/huggingface.ts +95 -0
- package/status/moonshotai-cn.ts +26 -0
- package/status/moonshotai.ts +151 -0
- package/status/openai-codex.ts +2 -1
- package/status/opencode-go.ts +2 -1
- package/status/openrouter.ts +173 -0
- package/status/vercel-ai-gateway/constants.ts +3 -0
- package/status/vercel-ai-gateway.ts +95 -0
- package/status/xai.ts +74 -0
package/status/xai.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { StatusAdapter, StatusEntry, StatusSnapshot } from "@hyav/pi-provider";
|
|
2
|
+
import { defineStatusExtension, hasBaseUrlOrigin, ProviderDataError, parseRetryAfter } from "@hyav/pi-provider";
|
|
3
|
+
import { parseRateLimitWindows } from "../core/ratelimit-headers.ts";
|
|
4
|
+
|
|
5
|
+
export const XAI_MODELS_URL = "https://api.x.ai/v1/models";
|
|
6
|
+
|
|
7
|
+
function windowEntry(id: string, label: string, limit: number, remaining: number, resetAt?: number): StatusEntry {
|
|
8
|
+
const percent = (remaining / limit) * 100;
|
|
9
|
+
return {
|
|
10
|
+
kind: "window",
|
|
11
|
+
id,
|
|
12
|
+
label,
|
|
13
|
+
remainingPercent: Math.max(0, Math.min(100, percent)),
|
|
14
|
+
...(resetAt !== undefined ? { resetAt } : {}),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const xaiStatusAdapter: StatusAdapter = {
|
|
19
|
+
id: "xai-status",
|
|
20
|
+
providerId: "xai",
|
|
21
|
+
name: "xAI",
|
|
22
|
+
cacheTtlMs: 60_000,
|
|
23
|
+
requestTimeoutMs: 8_000,
|
|
24
|
+
supportsModel: (model) => hasBaseUrlOrigin(model.baseUrl, XAI_MODELS_URL),
|
|
25
|
+
async fetch(context): Promise<StatusSnapshot> {
|
|
26
|
+
const key = await context.getApiKey();
|
|
27
|
+
if (!key || key === "proxy-managed") {
|
|
28
|
+
throw new ProviderDataError("xAI status requires Grok OAuth or an API key", "auth");
|
|
29
|
+
}
|
|
30
|
+
const response = await context.fetch(XAI_MODELS_URL, {
|
|
31
|
+
headers: {
|
|
32
|
+
Accept: "application/json",
|
|
33
|
+
"Accept-Encoding": "identity",
|
|
34
|
+
Authorization: `Bearer ${key}`,
|
|
35
|
+
"User-Agent": "@hyav/pi-provider",
|
|
36
|
+
},
|
|
37
|
+
signal: context.signal,
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new ProviderDataError(
|
|
41
|
+
`xAI status failed: HTTP ${response.status}`,
|
|
42
|
+
`http${response.status}`,
|
|
43
|
+
parseRetryAfter(response.headers.get("retry-after"), context.now()),
|
|
44
|
+
response.status,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const now = context.now();
|
|
49
|
+
const { requests, tokens } = parseRateLimitWindows(response.headers, now);
|
|
50
|
+
const entries: StatusEntry[] = [];
|
|
51
|
+
if (requests) {
|
|
52
|
+
entries.push(windowEntry("requests-window", "Requests", requests.limit, requests.remaining, requests.resetAt));
|
|
53
|
+
}
|
|
54
|
+
if (tokens) {
|
|
55
|
+
entries.push(windowEntry("tokens-window", "Tokens", tokens.limit, tokens.remaining, tokens.resetAt));
|
|
56
|
+
}
|
|
57
|
+
if (entries.length === 0) {
|
|
58
|
+
entries.push({ kind: "text", id: "limits", label: "Limits", value: "not available" });
|
|
59
|
+
}
|
|
60
|
+
return { entries, updatedAt: now };
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function createXaiStatusAdapter(requestTimeoutMs: number): StatusAdapter {
|
|
65
|
+
return { ...xaiStatusAdapter, requestTimeoutMs };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const xaiStatusExtension = defineStatusExtension({
|
|
69
|
+
id: "xai-status",
|
|
70
|
+
providerId: "xai",
|
|
71
|
+
create: ({ statusRequestTimeoutMs }) => createXaiStatusAdapter(statusRequestTimeoutMs),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export default xaiStatusExtension;
|