pi-openmodel-provider 0.2.15 → 0.2.17
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/.agents/skills/pi-openmodel-info/SKILL.md +13 -0
- package/AGENTS.md +2 -0
- package/CHANGELOG.md +30 -0
- package/README.md +44 -1
- package/index.ts +29 -15
- package/package.json +1 -1
- package/src/{models.ts → api/models.ts} +59 -48
- package/src/api/stability.ts +184 -0
- package/src/auth/login.ts +132 -0
- package/src/auth/validate.ts +33 -0
- package/src/cache.ts +61 -0
- package/src/formatters/stability.ts +48 -0
- package/src/providers/compat.ts +50 -0
- package/src/providers/pricing.ts +12 -0
- package/src/providers/protocols.ts +53 -0
- package/src/auth.ts +0 -179
- package/src/stability.ts +0 -201
package/src/stability.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenModel.ai Model Stability API.
|
|
3
|
-
*
|
|
4
|
-
* Fetches real-time stability metrics (success rate, latency, throughput)
|
|
5
|
-
* for all models. Publicly accessible without authentication.
|
|
6
|
-
*
|
|
7
|
-
* Reference:
|
|
8
|
-
* GET https://api.openmodel.ai/web/v1/model-stability/summary
|
|
9
|
-
* GET https://api.openmodel.ai/web/v1/model-stability/:modelKey
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { parseWebError, friendlyMessage } from "./errors.ts"
|
|
13
|
-
|
|
14
|
-
export const STABILITY_SUMMARY_URL =
|
|
15
|
-
"https://api.openmodel.ai/web/v1/model-stability/summary";
|
|
16
|
-
|
|
17
|
-
/** Health status derived from success rate */
|
|
18
|
-
export type HealthStatus =
|
|
19
|
-
| "operational"
|
|
20
|
-
| "healthy"
|
|
21
|
-
| "degraded"
|
|
22
|
-
| "unstable"
|
|
23
|
-
| "no_data";
|
|
24
|
-
|
|
25
|
-
/** Confidence level based on sample size */
|
|
26
|
-
export type ConfidenceLevel = "high" | "medium" | "low";
|
|
27
|
-
|
|
28
|
-
/** Stability summary for a single model */
|
|
29
|
-
export interface ModelStability {
|
|
30
|
-
model_name: string;
|
|
31
|
-
success_rate: number;
|
|
32
|
-
avg_latency_ms: number;
|
|
33
|
-
avg_tps: number;
|
|
34
|
-
confidence: ConfidenceLevel;
|
|
35
|
-
health_status: HealthStatus;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Stability summary for a single model with time series */
|
|
39
|
-
export interface ModelStabilityDetail {
|
|
40
|
-
model_name: string;
|
|
41
|
-
confidence: ConfidenceLevel;
|
|
42
|
-
summary: {
|
|
43
|
-
success_rate: number;
|
|
44
|
-
avg_latency_ms: number;
|
|
45
|
-
avg_ttft_ms: number;
|
|
46
|
-
avg_tps: number;
|
|
47
|
-
};
|
|
48
|
-
series: Array<{
|
|
49
|
-
ts: number;
|
|
50
|
-
success_rate: number;
|
|
51
|
-
avg_latency_ms: number;
|
|
52
|
-
avg_ttft_ms: number;
|
|
53
|
-
avg_tps: number;
|
|
54
|
-
confidence: ConfidenceLevel;
|
|
55
|
-
}>;
|
|
56
|
-
updated_at: number;
|
|
57
|
-
health_status: HealthStatus;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Determine health status from success rate */
|
|
61
|
-
function determineHealth(
|
|
62
|
-
successRate: number,
|
|
63
|
-
confidence: ConfidenceLevel,
|
|
64
|
-
): HealthStatus {
|
|
65
|
-
if (confidence === "low") return "no_data";
|
|
66
|
-
if (successRate >= 99.9) return "operational";
|
|
67
|
-
if (successRate >= 99) return "healthy";
|
|
68
|
-
if (successRate >= 95) return "degraded";
|
|
69
|
-
return "unstable";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Fetch stability summary for all models */
|
|
73
|
-
export async function fetchModelStabilitySummary(options?: {
|
|
74
|
-
url?: string;
|
|
75
|
-
fetchImpl?: typeof fetch;
|
|
76
|
-
hours?: number;
|
|
77
|
-
}): Promise<ModelStability[]> {
|
|
78
|
-
const url = options?.url ?? STABILITY_SUMMARY_URL;
|
|
79
|
-
const fetchImpl = options?.fetchImpl ?? fetch;
|
|
80
|
-
const hours = options?.hours ?? 24;
|
|
81
|
-
|
|
82
|
-
const params = new URLSearchParams({ hours: String(hours) });
|
|
83
|
-
const response = await fetchImpl(`${url}?${params}`, {
|
|
84
|
-
headers: { accept: "application/json" },
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (!response.ok) {
|
|
88
|
-
let errBody: any
|
|
89
|
-
try { errBody = await response.json() } catch {}
|
|
90
|
-
const err = parseWebError(errBody)
|
|
91
|
-
throw new Error(`stability — ${friendlyMessage(err.code, err.message)}`)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const body = (await response.json()) as {
|
|
95
|
-
success: boolean;
|
|
96
|
-
data: Array<{
|
|
97
|
-
model_name: string;
|
|
98
|
-
success_rate: number;
|
|
99
|
-
avg_latency_ms: number;
|
|
100
|
-
avg_tps: number;
|
|
101
|
-
confidence: ConfidenceLevel;
|
|
102
|
-
}>;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (!body.success) {
|
|
106
|
-
throw new Error(`stability — ${friendlyMessage("INTERNAL_ERROR", "Summary request failed")}`)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return body.data.map((item) => ({
|
|
110
|
-
...item,
|
|
111
|
-
health_status: determineHealth(item.success_rate, item.confidence),
|
|
112
|
-
}));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Fetch stability detail for a specific model */
|
|
116
|
-
export async function fetchModelStabilityDetail(
|
|
117
|
-
modelKey: string,
|
|
118
|
-
options?: {
|
|
119
|
-
fetchImpl?: typeof fetch;
|
|
120
|
-
hours?: number;
|
|
121
|
-
},
|
|
122
|
-
): Promise<ModelStabilityDetail> {
|
|
123
|
-
const fetchImpl = options?.fetchImpl ?? fetch;
|
|
124
|
-
const hours = options?.hours ?? 24;
|
|
125
|
-
|
|
126
|
-
const params = new URLSearchParams({ hours: String(hours) });
|
|
127
|
-
const response = await fetchImpl(
|
|
128
|
-
`https://api.openmodel.ai/web/v1/model-stability/${encodeURIComponent(modelKey)}?${params}`,
|
|
129
|
-
{ headers: { accept: "application/json" } },
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
if (!response.ok) {
|
|
133
|
-
let errBody: any
|
|
134
|
-
try { errBody = await response.json() } catch {}
|
|
135
|
-
const err = parseWebError(errBody)
|
|
136
|
-
throw new Error(`stability — ${friendlyMessage(err.code, err.message)}`)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const body = (await response.json()) as {
|
|
140
|
-
success: boolean;
|
|
141
|
-
data: {
|
|
142
|
-
model_name: string;
|
|
143
|
-
confidence: ConfidenceLevel;
|
|
144
|
-
summary: {
|
|
145
|
-
success_rate: number;
|
|
146
|
-
avg_latency_ms: number;
|
|
147
|
-
avg_ttft_ms: number;
|
|
148
|
-
avg_tps: number;
|
|
149
|
-
};
|
|
150
|
-
series: Array<{
|
|
151
|
-
ts: number;
|
|
152
|
-
success_rate: number;
|
|
153
|
-
avg_latency_ms: number;
|
|
154
|
-
avg_ttft_ms: number;
|
|
155
|
-
avg_tps: number;
|
|
156
|
-
confidence: ConfidenceLevel;
|
|
157
|
-
}>;
|
|
158
|
-
updated_at: number;
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
if (!body.success) {
|
|
163
|
-
throw new Error(`stability — ${friendlyMessage("NOT_FOUND", `Model "${modelKey}" not found`)}`)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
...body.data,
|
|
168
|
-
health_status: determineHealth(
|
|
169
|
-
body.data.summary.success_rate,
|
|
170
|
-
body.data.confidence,
|
|
171
|
-
),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Format health status with emoji */
|
|
176
|
-
export function formatHealthStatus(status: HealthStatus): string {
|
|
177
|
-
switch (status) {
|
|
178
|
-
case "operational":
|
|
179
|
-
return "✅ Operational";
|
|
180
|
-
case "healthy":
|
|
181
|
-
return "🟢 Healthy";
|
|
182
|
-
case "degraded":
|
|
183
|
-
return "🟡 Degraded";
|
|
184
|
-
case "unstable":
|
|
185
|
-
return "🔴 Unstable";
|
|
186
|
-
case "no_data":
|
|
187
|
-
return "⚪ No Data";
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** Format confidence level */
|
|
192
|
-
export function formatConfidence(level: ConfidenceLevel): string {
|
|
193
|
-
switch (level) {
|
|
194
|
-
case "high":
|
|
195
|
-
return "🟢 High";
|
|
196
|
-
case "medium":
|
|
197
|
-
return "🟡 Medium";
|
|
198
|
-
case "low":
|
|
199
|
-
return "⚪ Low";
|
|
200
|
-
}
|
|
201
|
-
}
|