first commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import type { AiProviderKind, AiProviderResponse, AiProviderStatus, AiRelayMode } from "../api/types";
|
||||
|
||||
export type AiProviderFilter = AiProviderStatus | "all";
|
||||
export type AiProviderViewState = "api" | "local" | "saving" | "error";
|
||||
|
||||
export interface AiProviderFormState {
|
||||
id: string;
|
||||
name: string;
|
||||
kind: AiProviderKind;
|
||||
baseUrl: string;
|
||||
apiKeyRef: string;
|
||||
modelsText: string;
|
||||
defaultModel: string;
|
||||
relayMode: AiRelayMode;
|
||||
timeoutMs: string;
|
||||
redactionPolicy: string;
|
||||
}
|
||||
|
||||
export interface AiProviderMetrics {
|
||||
total: number;
|
||||
active: number;
|
||||
disabled: number;
|
||||
models: number;
|
||||
}
|
||||
|
||||
export interface AiProviderActionState {
|
||||
providerId: string;
|
||||
label: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function emptyAiProviderForm(): AiProviderFormState {
|
||||
return {
|
||||
id: "",
|
||||
name: "",
|
||||
kind: "openai-compatible",
|
||||
baseUrl: "https://api.example.test/v1",
|
||||
apiKeyRef: "secret://providers/",
|
||||
modelsText: "gpt-4.1-mini",
|
||||
defaultModel: "gpt-4.1-mini",
|
||||
relayMode: "direct",
|
||||
timeoutMs: "30000",
|
||||
redactionPolicy: "default"
|
||||
};
|
||||
}
|
||||
|
||||
export function aiProviderToForm(provider: AiProviderResponse): AiProviderFormState {
|
||||
return {
|
||||
id: provider.id,
|
||||
name: provider.name,
|
||||
kind: provider.kind,
|
||||
baseUrl: provider.baseUrl,
|
||||
apiKeyRef: provider.apiKeyRef,
|
||||
modelsText: provider.models.join(", "),
|
||||
defaultModel: provider.defaultModel ?? "",
|
||||
relayMode: provider.relayMode,
|
||||
timeoutMs: String(provider.timeoutMs),
|
||||
redactionPolicy: provider.redactionPolicy
|
||||
};
|
||||
}
|
||||
|
||||
export function summarizeAiProviders(providers: AiProviderResponse[]): AiProviderMetrics {
|
||||
return providers.reduce<AiProviderMetrics>(
|
||||
(metrics, provider) => ({
|
||||
total: metrics.total + 1,
|
||||
active: metrics.active + (provider.status === "active" ? 1 : 0),
|
||||
disabled: metrics.disabled + (provider.status === "disabled" ? 1 : 0),
|
||||
models: metrics.models + provider.models.length
|
||||
}),
|
||||
{ total: 0, active: 0, disabled: 0, models: 0 }
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user