MCPcopy Create free account
hub / github.com/QuantumNous/new-api / ListTaskPlugins

Function ListTaskPlugins

controller/task_plugin.go:130–224  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

128}
129
130func ListTaskPlugins(c *gin.Context) {
131 databasePlugins, err := model.ListTaskPlugins()
132 if err != nil {
133 common.ApiError(c, err)
134 return
135 }
136 snapshot := jsplugin.DefaultRegistry.Snapshot()
137 factory := make(map[string]jsplugin.Meta, len(snapshot.Factory))
138 override := make(map[string]jsplugin.Meta, len(snapshot.Override))
139 for _, meta := range snapshot.Factory {
140 factory[meta.Key] = meta
141 }
142 for _, meta := range snapshot.Override {
143 override[meta.Key] = meta
144 }
145 activeRows := make(map[string]model.TaskPlugin)
146 keys := make(map[string]struct{}, len(factory)+len(databasePlugins))
147 for key := range factory {
148 keys[key] = struct{}{}
149 }
150 for _, plugin := range databasePlugins {
151 keys[plugin.Key] = struct{}{}
152 if plugin.Active {
153 activeRows[plugin.Key] = plugin
154 }
155 }
156
157 runtimeErrors := jsplugin.DefaultRegistry.RoutingErrors()
158 taskPluginSyncState.Lock()
159 for key, message := range taskPluginSyncState.errors {
160 runtimeErrors[key] = message
161 }
162 taskPluginSyncState.Unlock()
163
164 items := make([]taskPluginListItem, 0, len(keys))
165 for key := range keys {
166 factoryMeta, hasFactory := factory[key]
167 row, hasOverride := activeRows[key]
168 item := taskPluginListItem{Enabled: true, Active: true, RuntimeStatus: "registered"}
169 if hasOverride {
170 item.Source = "override"
171 if hasFactory {
172 item.Source = "override_over_factory"
173 factoryCopy := factoryMeta
174 item.FactoryMeta = &factoryCopy
175 }
176 item.Meta = jsplugin.Meta{Key: row.Key, Version: row.Version, APIVersion: row.APIVersion}
177 if compiled, compileErr := jsplugin.NewRegistry().Register(row.Source, jsplugin.Options{Key: row.Key, Version: row.Version}); compileErr == nil {
178 item.Meta = compiled.Meta
179 }
180 item.Enabled = row.Enabled
181 item.Active = row.Active
182 item.SourceHash = row.SourceHash
183 item.Remark = row.Remark
184 if !constant.TaskPluginOverrideEnabled {
185 item.RuntimeStatus = "disabled_fallback"
186 } else if message := runtimeErrors[key]; message != "" {
187 item.RuntimeStatus = "compile_failed"

Calls 11

ListTaskPluginsFunction · 0.92
ApiErrorFunction · 0.92
NewRegistryFunction · 0.92
SourceFunction · 0.92
GetTaskPluginUsageFunction · 0.92
ApiSuccessFunction · 0.92
RoutingErrorsMethod · 0.80
UnlockMethod · 0.80
SnapshotMethod · 0.45
RegisterMethod · 0.45