Spaces:
Paused
Paused
File size: 6,114 Bytes
bd0c393 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | import apiClient from './client'
// Types for credentials API
export interface Credential {
id: string
name: string
provider: string
modalities: string[]
base_url?: string | null
endpoint?: string | null
api_version?: string | null
endpoint_llm?: string | null
endpoint_embedding?: string | null
endpoint_stt?: string | null
endpoint_tts?: string | null
project?: string | null
location?: string | null
credentials_path?: string | null
num_ctx?: number | null
has_api_key: boolean
created: string
updated: string
model_count: number
decryption_error?: string | null
}
export interface CreateCredentialRequest {
name: string
provider: string
modalities: string[]
api_key?: string
base_url?: string
endpoint?: string
api_version?: string
endpoint_llm?: string
endpoint_embedding?: string
endpoint_stt?: string
endpoint_tts?: string
project?: string
location?: string
credentials_path?: string
num_ctx?: number | null
}
export interface UpdateCredentialRequest {
name?: string
modalities?: string[]
api_key?: string
base_url?: string
endpoint?: string
api_version?: string
endpoint_llm?: string
endpoint_embedding?: string
endpoint_stt?: string
endpoint_tts?: string
project?: string
location?: string
credentials_path?: string
num_ctx?: number | null
}
export interface DiscoveredModel {
name: string
provider: string
model_type?: string
description?: string
}
export interface RegisterModelData {
name: string
provider: string
model_type: string
}
export interface DiscoverModelsResponse {
credential_id: string
provider: string
discovered: DiscoveredModel[]
}
export interface RegisterModelsRequest {
models: RegisterModelData[]
}
export interface RegisterModelsResponse {
created: number
existing: number
}
export interface TestConnectionResult {
provider: string
success: boolean
message: string
}
export interface CredentialDeleteResponse {
message: string
deleted_models: number
}
export interface MigrationResult {
message: string
migrated: string[]
skipped: string[]
not_configured?: string[]
errors: string[]
}
export interface CredentialStatus {
configured: Record<string, boolean>
source: Record<string, string>
encryption_configured: boolean
}
export type EnvStatus = Record<string, boolean>
export const credentialsApi = {
/**
* Get configuration status for all providers
*/
getStatus: async (): Promise<CredentialStatus> => {
const response = await apiClient.get<CredentialStatus>('/credentials/status')
return response.data
},
/**
* Get environment variable status for all providers
*/
getEnvStatus: async (): Promise<EnvStatus> => {
const response = await apiClient.get<EnvStatus>('/credentials/env-status')
return response.data
},
/**
* List all credentials, optionally filtered by provider
*/
list: async (provider?: string): Promise<Credential[]> => {
const params = provider ? { provider } : {}
const response = await apiClient.get<Credential[]>('/credentials', { params })
return response.data
},
/**
* List credentials for a specific provider
*/
listByProvider: async (provider: string): Promise<Credential[]> => {
const response = await apiClient.get<Credential[]>(`/credentials/by-provider/${provider}`)
return response.data
},
/**
* Get a specific credential by ID
*/
get: async (credentialId: string): Promise<Credential> => {
const response = await apiClient.get<Credential>(`/credentials/${credentialId}`)
return response.data
},
/**
* Create a new credential
*/
create: async (data: CreateCredentialRequest): Promise<Credential> => {
const response = await apiClient.post<Credential>('/credentials', data)
return response.data
},
/**
* Update an existing credential
*/
update: async (credentialId: string, data: UpdateCredentialRequest): Promise<Credential> => {
const response = await apiClient.put<Credential>(`/credentials/${credentialId}`, data)
return response.data
},
/**
* Delete a credential
*/
delete: async (
credentialId: string,
options?: { delete_models?: boolean; migrate_to?: string }
): Promise<CredentialDeleteResponse> => {
const params: Record<string, string | boolean> = {}
if (options?.delete_models) params.delete_models = true
if (options?.migrate_to) params.migrate_to = options.migrate_to
const response = await apiClient.delete<CredentialDeleteResponse>(
`/credentials/${credentialId}`,
{ params }
)
return response.data
},
/**
* Test connection for a credential
*/
test: async (credentialId: string): Promise<TestConnectionResult> => {
const response = await apiClient.post<TestConnectionResult>(
`/credentials/${credentialId}/test`
)
return response.data
},
/**
* Discover models using a credential's API key
*/
discover: async (credentialId: string): Promise<DiscoverModelsResponse> => {
const response = await apiClient.post<DiscoverModelsResponse>(
`/credentials/${credentialId}/discover`
)
return response.data
},
/**
* Register discovered models and link them to a credential
*/
registerModels: async (
credentialId: string,
data: RegisterModelsRequest
): Promise<RegisterModelsResponse> => {
const response = await apiClient.post<RegisterModelsResponse>(
`/credentials/${credentialId}/register-models`,
data
)
return response.data
},
/**
* Migrate from ProviderConfig to individual credentials
*/
migrateFromProviderConfig: async (): Promise<MigrationResult> => {
const response = await apiClient.post<MigrationResult>(
'/credentials/migrate-from-provider-config'
)
return response.data
},
/**
* Migrate from environment variables to credentials
*/
migrateFromEnv: async (): Promise<MigrationResult> => {
const response = await apiClient.post<MigrationResult>('/credentials/migrate-from-env')
return response.data
},
}
|