Browse Source

fix: applying agent to orignal pointer is required during Unmarshaling JSON

Yeuoly 7 months ago
parent
commit
9be865f868

+ 9 - 0
internal/core/plugin_manager/media_manager/assets.go

@@ -104,6 +104,15 @@ func (m *MediaBucket) RemapAssets(declaration *plugin_entities.PluginDeclaration
 		}
 	}
 
+	if declaration.Agent != nil {
+		if declaration.Agent.Identity.Icon != "" {
+			declaration.Agent.Identity.Icon, err = remap(declaration.Agent.Identity.Icon)
+			if err != nil {
+				return nil, errors.Join(err, fmt.Errorf("failed to remap agent icon"))
+			}
+		}
+	}
+
 	if declaration.Icon != "" {
 		declaration.Icon, err = remap(declaration.Icon)
 		if err != nil {

+ 1 - 0
internal/db/init.go

@@ -87,6 +87,7 @@ func autoMigrate() error {
 		models.AIModelInstallation{},
 		models.InstallTask{},
 		models.TenantStorage{},
+		models.AgentInstallation{},
 	)
 }
 

+ 8 - 0
internal/types/entities/plugin_entities/plugin_declaration.go

@@ -201,6 +201,7 @@ func (p *PluginDeclaration) UnmarshalJSON(data []byte) error {
 		Endpoint *EndpointProviderDeclaration `json:"endpoint,omitempty"`
 		Model    *ModelProviderDeclaration    `json:"model,omitempty"`
 		Tool     *ToolProviderDeclaration     `json:"tool,omitempty"`
+		Agent    *AgentProviderDeclaration    `json:"agent,omitempty"`
 	}
 
 	var extra PluginExtra
@@ -212,6 +213,7 @@ func (p *PluginDeclaration) UnmarshalJSON(data []byte) error {
 	p.Endpoint = extra.Endpoint
 	p.Model = extra.Model
 	p.Tool = extra.Tool
+	p.Agent = extra.Agent
 
 	return nil
 }
@@ -251,6 +253,12 @@ func (p *PluginDeclaration) ManifestValidate() error {
 		return fmt.Errorf("model and endpoint cannot be provided at the same time")
 	}
 
+	if p.Agent != nil {
+		if p.Tool != nil || p.Model != nil || p.Endpoint != nil {
+			return fmt.Errorf("agent and tool, model, or endpoint cannot be provided at the same time")
+		}
+	}
+
 	return nil
 }
 

+ 1 - 1
internal/types/models/agent.go

@@ -8,5 +8,5 @@ type AgentInstallation struct {
 	Provider               string                                   `json:"provider" gorm:"column:provider;size:127;index;not null"`
 	PluginUniqueIdentifier string                                   `json:"plugin_unique_identifier" gorm:"index;size:255"`
 	PluginID               string                                   `json:"plugin_id" gorm:"index;size:255"`
-	Declaration            plugin_entities.AgentProviderDeclaration `json:"declaration" gorm:"serializer:json;type:text;size:65535;not null"`
+	Declaration            plugin_entities.AgentProviderDeclaration `json:"declaration,inline" gorm:"serializer:json;type:text;size:65535;not null"`
 }