mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-10-13 16:57:24 +08:00
* feat(plugin): add plugin manifest, registry and builtin catalog * feat(plugin): add config schemas with unified secret handling * feat(frontend): render config schemas with SchemaForm * feat(datasource): serve connector credential forms from the backend * feat(im): describe IM platforms and credentials from the backend * feat(frontend): render model vendor extra fields from the config schema * feat(frontend): build the settings modal from an extension registry * refactor(agent): register builtin tools and their chat views * feat(plugin): let workspaces enable and disable plugins * feat(plugin): add the runtime driver interface and gather builtins
40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/Tencent/WeKnora/internal/plugin/manifest"
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
|
)
|
|
|
|
// pluginGated gives an integration handler the tenant's plugin switches.
|
|
// It is set after construction (SetPluginGate) so the many handler tests that
|
|
// build handlers directly need no gate; without one everything is enabled.
|
|
type pluginGated struct {
|
|
gate interfaces.PluginGate
|
|
}
|
|
|
|
// SetPluginGate installs the tenant plugin switches.
|
|
func (g *pluginGated) SetPluginGate(gate interfaces.PluginGate) { g.gate = gate }
|
|
|
|
// pluginFilter returns whether a contribution is enabled for the caller's
|
|
// tenant. A disabled plugin's contributions are left out of type listings
|
|
// and cannot back new instances; existing instances keep working.
|
|
func (g *pluginGated) pluginFilter(c *gin.Context) func(manifest.Point, string) bool {
|
|
tenantID := c.GetUint64(types.TenantIDContextKey.String())
|
|
if tenantID == 0 {
|
|
if v, ok := c.Request.Context().Value(types.TenantIDContextKey).(uint64); ok {
|
|
tenantID = v
|
|
}
|
|
}
|
|
if g.gate == nil || tenantID == 0 {
|
|
return func(manifest.Point, string) bool { return true }
|
|
}
|
|
return g.gate.EnabledFilter(c.Request.Context(), tenantID)
|
|
}
|
|
|
|
// disabledIntegrationError is the message for creating an instance of a
|
|
// contribution whose plugin the workspace has disabled.
|
|
const disabledIntegrationError = "this integration is disabled for the workspace; enable its plugin first"
|