feat(web): add reusable admin form dialog
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import type {
|
||||
AuthResponse,
|
||||
BaseModelCatalogItem,
|
||||
BaseModelUpsertRequest,
|
||||
CatalogProvider,
|
||||
CatalogProviderUpsertRequest,
|
||||
CreatedGatewayApiKey,
|
||||
GatewayApiKey,
|
||||
GatewayTenant,
|
||||
@@ -11,6 +13,8 @@ import type {
|
||||
ListResponse,
|
||||
PlatformModel,
|
||||
PricingRule,
|
||||
PricingRuleSet,
|
||||
PricingRuleSetUpsertRequest,
|
||||
RateLimitWindow,
|
||||
UserGroup,
|
||||
} from '@easyai-ai-gateway/contracts';
|
||||
@@ -58,18 +62,117 @@ export async function listModels(token: string): Promise<ListResponse<PlatformMo
|
||||
return request<ListResponse<PlatformModel>>('/api/v1/models', { token });
|
||||
}
|
||||
|
||||
export async function listPublicCatalogProviders(): Promise<ListResponse<CatalogProvider>> {
|
||||
return request<ListResponse<CatalogProvider>>('/api/v1/public/catalog/providers', { auth: false });
|
||||
}
|
||||
|
||||
export async function listCatalogProviders(token: string): Promise<ListResponse<CatalogProvider>> {
|
||||
return request<ListResponse<CatalogProvider>>('/api/v1/catalog/providers', { token });
|
||||
}
|
||||
|
||||
export async function createCatalogProvider(
|
||||
token: string,
|
||||
input: CatalogProviderUpsertRequest,
|
||||
): Promise<CatalogProvider> {
|
||||
return request<CatalogProvider>('/api/v1/catalog/providers', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateCatalogProvider(
|
||||
token: string,
|
||||
providerId: string,
|
||||
input: CatalogProviderUpsertRequest,
|
||||
): Promise<CatalogProvider> {
|
||||
return request<CatalogProvider>(`/api/v1/catalog/providers/${providerId}`, {
|
||||
body: input,
|
||||
method: 'PATCH',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteCatalogProvider(token: string, providerId: string): Promise<void> {
|
||||
await request<void>(`/api/v1/catalog/providers/${providerId}`, {
|
||||
method: 'DELETE',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function listPublicBaseModels(): Promise<ListResponse<BaseModelCatalogItem>> {
|
||||
return request<ListResponse<BaseModelCatalogItem>>('/api/v1/public/catalog/base-models', { auth: false });
|
||||
}
|
||||
|
||||
export async function listBaseModels(token: string): Promise<ListResponse<BaseModelCatalogItem>> {
|
||||
return request<ListResponse<BaseModelCatalogItem>>('/api/v1/catalog/base-models', { token });
|
||||
}
|
||||
|
||||
export async function createBaseModel(token: string, input: BaseModelUpsertRequest): Promise<BaseModelCatalogItem> {
|
||||
return request<BaseModelCatalogItem>('/api/v1/catalog/base-models', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateBaseModel(
|
||||
token: string,
|
||||
baseModelId: string,
|
||||
input: BaseModelUpsertRequest,
|
||||
): Promise<BaseModelCatalogItem> {
|
||||
return request<BaseModelCatalogItem>(`/api/v1/catalog/base-models/${baseModelId}`, {
|
||||
body: input,
|
||||
method: 'PATCH',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteBaseModel(token: string, baseModelId: string): Promise<void> {
|
||||
await request<void>(`/api/v1/catalog/base-models/${baseModelId}`, {
|
||||
method: 'DELETE',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function listPricingRules(token: string): Promise<ListResponse<PricingRule>> {
|
||||
return request<ListResponse<PricingRule>>('/api/v1/pricing/rules', { token });
|
||||
}
|
||||
|
||||
export async function listPricingRuleSets(token: string): Promise<ListResponse<PricingRuleSet>> {
|
||||
return request<ListResponse<PricingRuleSet>>('/api/v1/pricing/rule-sets', { token });
|
||||
}
|
||||
|
||||
export async function createPricingRuleSet(
|
||||
token: string,
|
||||
input: PricingRuleSetUpsertRequest,
|
||||
): Promise<PricingRuleSet> {
|
||||
return request<PricingRuleSet>('/api/v1/pricing/rule-sets', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updatePricingRuleSet(
|
||||
token: string,
|
||||
ruleSetId: string,
|
||||
input: PricingRuleSetUpsertRequest,
|
||||
): Promise<PricingRuleSet> {
|
||||
return request<PricingRuleSet>(`/api/v1/pricing/rule-sets/${ruleSetId}`, {
|
||||
body: input,
|
||||
method: 'PATCH',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deletePricingRuleSet(token: string, ruleSetId: string): Promise<void> {
|
||||
await request<void>(`/api/v1/pricing/rule-sets/${ruleSetId}`, {
|
||||
method: 'DELETE',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function listTenants(token: string): Promise<ListResponse<GatewayTenant>> {
|
||||
return request<ListResponse<GatewayTenant>>('/api/v1/tenants', { token });
|
||||
}
|
||||
@@ -109,6 +212,7 @@ export async function createPlatform(
|
||||
config?: Record<string, unknown>;
|
||||
defaultPricingMode?: string;
|
||||
defaultDiscountFactor?: number;
|
||||
pricingRuleSetId?: string;
|
||||
priority?: number;
|
||||
},
|
||||
): Promise<IntegrationPlatform> {
|
||||
@@ -119,6 +223,29 @@ export async function createPlatform(
|
||||
});
|
||||
}
|
||||
|
||||
export async function createPlatformModel(
|
||||
token: string,
|
||||
platformId: string,
|
||||
input: {
|
||||
canonicalModelKey?: string;
|
||||
baseModelId?: string;
|
||||
modelName: string;
|
||||
modelAlias?: string;
|
||||
modelType: string;
|
||||
displayName?: string;
|
||||
retryPolicy?: Record<string, unknown>;
|
||||
rateLimitPolicy?: Record<string, unknown>;
|
||||
pricingRuleSetId?: string;
|
||||
discountFactor?: number;
|
||||
},
|
||||
): Promise<PlatformModel> {
|
||||
return request<PlatformModel>(`/api/v1/platforms/${platformId}/models`, {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createChatTask(
|
||||
token: string,
|
||||
input: { model: string; messages: Array<Record<string, unknown>>; runMode?: string; simulation?: boolean },
|
||||
@@ -130,6 +257,39 @@ export async function createChatTask(
|
||||
});
|
||||
}
|
||||
|
||||
export async function createImageGenerationTask(
|
||||
token: string,
|
||||
input: { model: string; prompt: string; size?: string; quality?: string; runMode?: string; simulation?: boolean },
|
||||
): Promise<{ task: GatewayTask; next: Record<string, string> }> {
|
||||
return request<{ task: GatewayTask; next: Record<string, string> }>('/api/v1/images/generations', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createImageEditTask(
|
||||
token: string,
|
||||
input: { model: string; prompt: string; image?: string; mask?: string; runMode?: string; simulation?: boolean },
|
||||
): Promise<{ task: GatewayTask; next: Record<string, string> }> {
|
||||
return request<{ task: GatewayTask; next: Record<string, string> }>('/api/v1/images/edits', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function estimatePricing(
|
||||
token: string,
|
||||
input: Record<string, unknown>,
|
||||
): Promise<{ items: unknown[]; resolver: string }> {
|
||||
return request<{ items: unknown[]; resolver: string }>('/api/v1/pricing/estimate', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getTask(token: string, taskId: string): Promise<GatewayTask> {
|
||||
return request<GatewayTask>(`/api/v1/tasks/${taskId}`, { token });
|
||||
}
|
||||
@@ -158,6 +318,9 @@ async function request<T>(
|
||||
const body = await response.text();
|
||||
throw new Error(parseErrorMessage(body) || `Request failed: ${response.status}`);
|
||||
}
|
||||
if (response.status === 204) {
|
||||
return undefined as T;
|
||||
}
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user