5759c1862e
M0-M7 已完成:核心网关(身份/RBAC/TOTP/OIDC/SAML/Provider/配额/路由/内容策略/审计/定价)+ 资源市场(MCP/Skills/数字员工)。 含 22 个 PostgreSQL 迁移、管理端/门户端前端源码、OpenAPI 契约、部署 compose。 Co-Authored-By: Claude <noreply@anthropic.com>
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
type Capability string
|
|
|
|
const (
|
|
CapabilityChat Capability = "chat"
|
|
CapabilityResponses Capability = "responses"
|
|
CapabilityEmbeddings Capability = "embeddings"
|
|
CapabilityMessages Capability = "messages"
|
|
CapabilityModels Capability = "models"
|
|
)
|
|
|
|
type Adapter interface {
|
|
Name() string
|
|
Target() *url.URL
|
|
Capabilities() []Capability
|
|
Prepare(*http.Request)
|
|
}
|
|
|
|
type Credentials struct {
|
|
APIKey string `json:"api_key"`
|
|
}
|
|
|
|
type ConnectionTestResult struct {
|
|
Connected bool `json:"connected"`
|
|
StatusCode int `json:"status_code,omitempty"`
|
|
LatencyMS int64 `json:"latency_ms"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type Model struct {
|
|
ID string `json:"id"`
|
|
ProviderID string `json:"provider_id"`
|
|
ProviderModelID string `json:"provider_model_id"`
|
|
OwnedBy string `json:"owned_by,omitempty"`
|
|
Metadata json.RawMessage `json:"metadata"`
|
|
Enabled bool `json:"enabled"`
|
|
DiscoveredAt time.Time `json:"discovered_at"`
|
|
LastSeenAt time.Time `json:"last_seen_at"`
|
|
}
|
|
|
|
type DiscoveredModel struct {
|
|
ProviderModelID string
|
|
OwnedBy string
|
|
Metadata json.RawMessage
|
|
}
|
|
|
|
type ModelSyncResult struct {
|
|
Discovered int `json:"discovered"`
|
|
Active int `json:"active"`
|
|
Disabled int `json:"disabled"`
|
|
SyncedAt time.Time `json:"synced_at"`
|
|
}
|
|
|
|
type CredentialRotation struct {
|
|
ProviderID string
|
|
FromVersion int
|
|
ToVersion int
|
|
Ciphertext []byte
|
|
}
|
|
|
|
type CredentialRotationResult struct {
|
|
ActiveVersion int `json:"active_version"`
|
|
LoadedVersions []int `json:"loaded_versions"`
|
|
Rotated int `json:"rotated"`
|
|
Skipped int `json:"skipped"`
|
|
}
|
|
|
|
type AdminOperations interface {
|
|
TestConnection(context.Context, string) (ConnectionTestResult, error)
|
|
SyncModels(context.Context, string, string) (ModelSyncResult, error)
|
|
ListModels(context.Context, string) ([]Model, error)
|
|
RotateCredentials(context.Context, string) (CredentialRotationResult, error)
|
|
}
|