mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 08:36:35 +00:00
feat(api): use enum for API protocol in provider config
This commit is contained in:
@@ -306,7 +306,7 @@ describe('Agent Database Activities Integration', () => {
|
||||
teamId: team.id,
|
||||
name: 'openai',
|
||||
config: {
|
||||
api: 'openai',
|
||||
api: 'openai-completions',
|
||||
apiKey: 'mock-key',
|
||||
},
|
||||
},
|
||||
|
||||
@@ -315,7 +315,7 @@ describe('AuthzService', () => {
|
||||
|
||||
// Provider
|
||||
const provider = await prisma.provider.create({
|
||||
data: { name: 'Prov 1', teamId: team.id, config: { api: 'openai' } },
|
||||
data: { name: 'Prov 1', teamId: team.id, config: { api: 'openai-completions' } },
|
||||
})
|
||||
|
||||
// Invite
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
import { z } from 'zod'
|
||||
export { z }
|
||||
|
||||
export const KNOWN_APIS = [
|
||||
'openai-completions',
|
||||
'mistral-conversations',
|
||||
'openai-responses',
|
||||
'azure-openai-responses',
|
||||
'openai-codex-responses',
|
||||
'anthropic-messages',
|
||||
'bedrock-converse-stream',
|
||||
'google-generative-ai',
|
||||
'google-vertex',
|
||||
] as const
|
||||
|
||||
// We define a serializable version of ProviderConfig for our API and DB
|
||||
// as the original ProviderConfig interface includes non-serializable fields (functions)
|
||||
export const providerModelConfigSchema = z.object({
|
||||
api: z.string().optional(),
|
||||
api: z.enum(KNOWN_APIS).optional(),
|
||||
reasoning: z.boolean().default(false),
|
||||
input: z.array(z.enum(['text', 'image'])).default(['text']),
|
||||
contextWindow: z.number().int().positive().default(128000),
|
||||
@@ -27,7 +39,7 @@ export const providerModelSchema = z.object({
|
||||
export const providerConfigSchema = z.object({
|
||||
baseUrl: z.string().url('Must be a valid URL').optional().or(z.literal('')),
|
||||
apiKey: z.string().optional().or(z.literal('')),
|
||||
api: z.string().min(1, 'API Protocol is required'),
|
||||
api: z.enum(KNOWN_APIS),
|
||||
headers: z.record(z.string(), z.string()).optional(),
|
||||
authHeader: z.boolean().optional(),
|
||||
})
|
||||
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
SelectValue,
|
||||
} from '@/ui/components/ui/select'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { providerConfigSchema, providerModelSchema } from '@shumai/dtos'
|
||||
import { providerConfigSchema, providerModelSchema, KNOWN_APIS } from '@shumai/dtos'
|
||||
import { useForm } from '@tanstack/react-form'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { InferResponseType } from 'hono/client'
|
||||
@@ -60,6 +60,18 @@ import { useEffect, useMemo, useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { z } from 'zod'
|
||||
|
||||
const API_PROTOCOL_LABELS: Record<(typeof KNOWN_APIS)[number], string> = {
|
||||
'openai-completions': 'OpenAI Completions',
|
||||
'mistral-conversations': 'Mistral Conversations',
|
||||
'openai-responses': 'OpenAI Responses',
|
||||
'azure-openai-responses': 'Azure OpenAI Responses',
|
||||
'openai-codex-responses': 'OpenAI Codex Responses',
|
||||
'anthropic-messages': 'Anthropic Messages',
|
||||
'bedrock-converse-stream': 'AWS Bedrock',
|
||||
'google-generative-ai': 'Google Generative AI',
|
||||
'google-vertex': 'Google Vertex',
|
||||
}
|
||||
|
||||
const providerFormSchemaBase = z.object({
|
||||
name: z.string().min(1, 'Provider name is required'),
|
||||
config: providerConfigSchema,
|
||||
@@ -541,7 +553,7 @@ function ProviderFormDialog({
|
||||
<Field data-invalid={isInvalid}>
|
||||
<FieldLabel htmlFor={field.name}>Global API Protocol</FieldLabel>
|
||||
<Select
|
||||
onValueChange={field.handleChange}
|
||||
onValueChange={field.handleChange as (value: string) => void}
|
||||
value={field.state.value}
|
||||
disabled={isBuiltin}
|
||||
>
|
||||
@@ -549,10 +561,11 @@ function ProviderFormDialog({
|
||||
<SelectValue placeholder="Select API Protocol" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="openai-completions">OpenAI Completions</SelectItem>
|
||||
<SelectItem value="anthropic-messages">Anthropic Messages</SelectItem>
|
||||
<SelectItem value="google-genai">Google GenAI</SelectItem>
|
||||
<SelectItem value="bedrock-converse-stream">AWS Bedrock</SelectItem>
|
||||
{KNOWN_APIS.map((api) => (
|
||||
<SelectItem key={api} value={api}>
|
||||
{API_PROTOCOL_LABELS[api]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{isInvalid && <FieldError errors={mapErrors(field.state.meta.errors)} />}
|
||||
|
||||
Reference in New Issue
Block a user