mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 22:49:57 +00:00
feat(task): replace built-in task adaptors with a sandboxed JS plugin system (#7076)
This commit is contained in:
@@ -58,6 +58,7 @@ const (
|
||||
ChannelTypeAdvancedCustom = 58
|
||||
ChannelTypeSub2API = 59
|
||||
ChannelTypeNewAPI = 60
|
||||
ChannelTypeTaskPlugin = 61
|
||||
ChannelTypeDummy // this one is only for count, do not add any channel after this
|
||||
|
||||
)
|
||||
@@ -124,6 +125,14 @@ var ChannelBaseURLs = []string{
|
||||
"", //58
|
||||
"", //59
|
||||
"", //60
|
||||
"", //61
|
||||
}
|
||||
|
||||
func GetChannelBaseURL(channelType int) string {
|
||||
if channelType < 0 || channelType >= len(ChannelBaseURLs) {
|
||||
return ""
|
||||
}
|
||||
return ChannelBaseURLs[channelType]
|
||||
}
|
||||
|
||||
var ChannelTypeNames = map[int]string{
|
||||
@@ -184,6 +193,7 @@ var ChannelTypeNames = map[int]string{
|
||||
ChannelTypeAdvancedCustom: "Advanced Custom",
|
||||
ChannelTypeSub2API: "Sub2API",
|
||||
ChannelTypeNewAPI: "New API",
|
||||
ChannelTypeTaskPlugin: "Task Plugin",
|
||||
}
|
||||
|
||||
func GetChannelTypeName(channelType int) string {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetChannelBaseURLIsBoundsSafe(t *testing.T) {
|
||||
assert.Empty(t, GetChannelBaseURL(ChannelTypeTaskPlugin))
|
||||
assert.Empty(t, GetChannelBaseURL(9999))
|
||||
}
|
||||
@@ -15,7 +15,8 @@ const (
|
||||
ContextKeyTokenKey ContextKey = "token_key"
|
||||
ContextKeyTokenId ContextKey = "token_id"
|
||||
ContextKeyTokenGroup ContextKey = "token_group"
|
||||
ContextKeyTokenSpecificChannelId ContextKey = "specific_channel_id"
|
||||
ContextKeyOriginTasks ContextKey = "origin_tasks"
|
||||
ContextKeyChannelConstraints ContextKey = "channel_constraints"
|
||||
ContextKeyTokenModelLimitEnabled ContextKey = "token_model_limit_enabled"
|
||||
ContextKeyTokenModelLimit ContextKey = "token_model_limit"
|
||||
ContextKeyTokenCrossGroupRetry ContextKey = "token_cross_group_retry"
|
||||
|
||||
@@ -18,6 +18,10 @@ var GenerateDefaultToken bool
|
||||
var ErrorLogEnabled bool
|
||||
var TaskQueryLimit int
|
||||
var TaskTimeoutMinutes int
|
||||
var TaskPluginProtocolTimeoutSeconds int
|
||||
var TaskPluginProtocolTickMilliseconds int
|
||||
var TaskPluginProtocolTickJitterMilliseconds int
|
||||
var TaskPluginProtocolHeartbeatSeconds int
|
||||
|
||||
// temporary variable for sora patch, will be removed in future
|
||||
var TaskPricePatches []string
|
||||
|
||||
+29
-11
@@ -8,17 +8,35 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
SunoActionMusic = "MUSIC"
|
||||
SunoActionLyrics = "LYRICS"
|
||||
|
||||
TaskActionGenerate = "generate"
|
||||
TaskActionTextGenerate = "textGenerate"
|
||||
TaskActionFirstTailGenerate = "firstTailGenerate"
|
||||
TaskActionReferenceGenerate = "referenceGenerate"
|
||||
TaskActionRemix = "remixGenerate"
|
||||
TaskActionImageToVideo = "image_to_video"
|
||||
TaskActionTextToVideo = "text_to_video"
|
||||
TaskActionFirstTailToVideo = "first_tail_to_video"
|
||||
TaskActionReferenceToVideo = "reference_to_video"
|
||||
TaskActionRemix = "remix"
|
||||
)
|
||||
|
||||
var SunoModel2Action = map[string]string{
|
||||
"suno_music": SunoActionMusic,
|
||||
"suno_lyrics": SunoActionLyrics,
|
||||
var legacyTaskActionAliases = map[string]string{
|
||||
"generate": TaskActionImageToVideo,
|
||||
"textGenerate": TaskActionTextToVideo,
|
||||
"firstTailGenerate": TaskActionFirstTailToVideo,
|
||||
"referenceGenerate": TaskActionReferenceToVideo,
|
||||
"remixGenerate": TaskActionRemix,
|
||||
}
|
||||
|
||||
// TaskPluginEnabled is the master switch for the whole task-plugin system.
|
||||
// When disabled, factory and override plugins both stop serving.
|
||||
var TaskPluginEnabled = true
|
||||
|
||||
// TaskPluginOverrideEnabled controls whether the database override layer is
|
||||
// active. When disabled, uploaded plugins are ignored and factory plugins are
|
||||
// used instead; the factory layer is unaffected.
|
||||
var TaskPluginOverrideEnabled = true
|
||||
|
||||
// NormalizeTaskAction maps persisted legacy action names to the canonical task
|
||||
// action vocabulary. Unknown platform-specific actions pass through unchanged.
|
||||
func NormalizeTaskAction(action string) string {
|
||||
if canonical, ok := legacyTaskActionAliases[action]; ok {
|
||||
return canonical
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNormalizeTaskAction(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
"generate": TaskActionImageToVideo,
|
||||
"textGenerate": TaskActionTextToVideo,
|
||||
"firstTailGenerate": TaskActionFirstTailToVideo,
|
||||
"referenceGenerate": TaskActionReferenceToVideo,
|
||||
"remixGenerate": TaskActionRemix,
|
||||
TaskActionTextToVideo: TaskActionTextToVideo,
|
||||
"MUSIC": "MUSIC",
|
||||
"custom_action": "custom_action",
|
||||
"": "",
|
||||
}
|
||||
|
||||
for input, expected := range tests {
|
||||
t.Run(input, func(t *testing.T) {
|
||||
assert.Equal(t, expected, NormalizeTaskAction(input))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user