mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-08 01:16:47 +08:00
feat(pluginhost): add OAuthProvider field to plugin metadata and update related functionality
This commit is contained in:
@@ -32,6 +32,7 @@ type pluginListEntry struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
EffectiveEnabled bool `json:"effective_enabled"`
|
||||
SupportsOAuth bool `json:"supports_oauth"`
|
||||
OAuthProvider string `json:"oauth_provider"`
|
||||
Logo string `json:"logo"`
|
||||
ConfigFields []pluginConfigFieldInfo `json:"config_fields"`
|
||||
Menus []pluginMenuInfo `json:"menus"`
|
||||
@@ -114,6 +115,7 @@ func (h *Handler) ListPlugins(c *gin.Context) {
|
||||
entry.ID = htmlsanitize.String(info.ID)
|
||||
entry.Registered = true
|
||||
entry.SupportsOAuth = info.SupportsOAuth
|
||||
entry.OAuthProvider = htmlsanitize.String(info.OAuthProvider)
|
||||
entry.Logo = htmlsanitize.String(info.Metadata.Logo)
|
||||
entry.ConfigFields = pluginConfigFields(info.Metadata.ConfigFields)
|
||||
entry.Menus = pluginMenus(info.Menus)
|
||||
|
||||
@@ -122,6 +122,7 @@ func TestListPluginsIncludesScannedAndConfiguredPlugins(t *testing.T) {
|
||||
Enabled bool `json:"enabled"`
|
||||
EffectiveEnabled bool `json:"effective_enabled"`
|
||||
SupportsOAuth bool `json:"supports_oauth"`
|
||||
OAuthProvider string `json:"oauth_provider"`
|
||||
Logo string `json:"logo"`
|
||||
ConfigFields []any `json:"config_fields"`
|
||||
Menus []any `json:"menus"`
|
||||
@@ -154,7 +155,12 @@ func TestListPluginsIncludesScannedAndConfiguredPlugins(t *testing.T) {
|
||||
EffectiveEnabled: item.EffectiveEnabled,
|
||||
Path: item.Path,
|
||||
}
|
||||
if item.Registered || item.SupportsOAuth || item.Logo != "" || len(item.ConfigFields) != 0 || len(item.Menus) != 0 {
|
||||
if item.Registered ||
|
||||
item.SupportsOAuth ||
|
||||
item.OAuthProvider != "" ||
|
||||
item.Logo != "" ||
|
||||
len(item.ConfigFields) != 0 ||
|
||||
len(item.Menus) != 0 {
|
||||
t.Fatalf("unregistered plugin entry has runtime fields: %#v", item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,6 +585,9 @@ func TestRegisteredPluginsIncludesMetadataAndOAuthCapability(t *testing.T) {
|
||||
if !infos[0].SupportsOAuth {
|
||||
t.Fatalf("RegisteredPlugins()[0].SupportsOAuth = false, want true; infos=%#v", infos)
|
||||
}
|
||||
if infos[0].OAuthProvider != "alpha" {
|
||||
t.Fatalf("RegisteredPlugins()[0].OAuthProvider = %q, want alpha; infos=%#v", infos[0].OAuthProvider, infos)
|
||||
}
|
||||
if infos[0].Metadata.Logo == "" || len(infos[0].Metadata.ConfigFields) != 1 {
|
||||
t.Fatalf("RegisteredPlugins()[0].Metadata = %#v, want logo and config fields", infos[0].Metadata)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ type RegisteredPluginInfo struct {
|
||||
Priority int
|
||||
Metadata pluginapi.Metadata
|
||||
SupportsOAuth bool
|
||||
OAuthProvider string
|
||||
Menus []RegisteredPluginMenu
|
||||
}
|
||||
|
||||
@@ -67,11 +68,19 @@ func (h *Host) RegisteredPlugins() []RegisteredPluginInfo {
|
||||
menusByPlugin := h.registeredPluginMenus()
|
||||
out := make([]RegisteredPluginInfo, 0, len(records))
|
||||
for _, record := range records {
|
||||
authProvider := record.plugin.Capabilities.AuthProvider
|
||||
oauthProvider := ""
|
||||
if authProvider != nil && !h.isPluginFused(record.id) {
|
||||
if identifier, okIdentifier := h.callAuthProviderIdentifier(record.id, authProvider); okIdentifier {
|
||||
oauthProvider = identifier
|
||||
}
|
||||
}
|
||||
out = append(out, RegisteredPluginInfo{
|
||||
ID: record.id,
|
||||
Priority: record.priority,
|
||||
Metadata: clonePluginMetadata(record.meta),
|
||||
SupportsOAuth: record.plugin.Capabilities.AuthProvider != nil,
|
||||
SupportsOAuth: authProvider != nil,
|
||||
OAuthProvider: oauthProvider,
|
||||
Menus: menusByPlugin[record.id],
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user