allow to set configs for actions too
This commit is contained in:
@@ -18,7 +18,10 @@ type ConnectorConfig struct {
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
||||
type ActionsConfig string
|
||||
type ActionsConfig struct {
|
||||
Name string `json:"name"` // e.g. search
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
||||
type AgentConfig struct {
|
||||
Connector []ConnectorConfig `json:"connectors" form:"connectors" `
|
||||
@@ -123,15 +126,19 @@ var AvailableActions = []string{ActionSearch}
|
||||
func (a *AgentConfig) availableActions() []Action {
|
||||
actions := []Action{}
|
||||
|
||||
if len(a.Actions) == 0 {
|
||||
// Return search as default
|
||||
return []Action{external.NewSearch(3)}
|
||||
}
|
||||
for _, action := range a.Actions {
|
||||
fmt.Println("Set Action", action)
|
||||
switch action {
|
||||
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(action.Config), &config); err != nil {
|
||||
fmt.Println("Error unmarshalling connector config", err)
|
||||
continue
|
||||
}
|
||||
fmt.Println("Config", config)
|
||||
|
||||
switch action.Name {
|
||||
case ActionSearch:
|
||||
actions = append(actions, external.NewSearch(3))
|
||||
actions = append(actions, external.NewSearch(config))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,14 +158,16 @@ func (a *AgentConfig) availableConnectors() []Connector {
|
||||
|
||||
for _, c := range a.Connector {
|
||||
fmt.Println("Set Connector", c)
|
||||
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
||||
fmt.Println("Error unmarshalling connector config", err)
|
||||
continue
|
||||
}
|
||||
fmt.Println("Config", config)
|
||||
|
||||
switch c.Type {
|
||||
case ConnectorTelegram:
|
||||
var config map[string]string
|
||||
if err := json.Unmarshal([]byte(c.Config), &config); err != nil {
|
||||
fmt.Println("Error unmarshalling connector config", err)
|
||||
continue
|
||||
}
|
||||
fmt.Println("Config", config)
|
||||
cc, err := connector.NewTelegramConnector(config)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating telegram connector", err)
|
||||
|
||||
@@ -53,15 +53,33 @@
|
||||
</script>
|
||||
|
||||
<div class="mb-4" id="action_box">
|
||||
<label for="actions" class="block text-sm font-medium text-gray-400">Agent Actions</label>
|
||||
<select style="display: none" name="actions" id="actions" class="mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-700 text-white">
|
||||
{{ range .Actions }}
|
||||
<option value="{{.}}">{{.}}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<div class="action mb-4">
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-500 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" hx-on:click="let actionbox=document.getElementById('actions'); let clone=actionbox.cloneNode(true); clone.style.display ='block'; actionbox.after(clone)">Add action</button>
|
||||
|
||||
<button id="action_button" type="button" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-500 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">Add action</button>
|
||||
<script>
|
||||
document.getElementById('action_button').addEventListener('click', function() {
|
||||
const actionsSection = document.getElementById('action_box');
|
||||
const ii = actionsSection.getElementsByClassName('connector').length;
|
||||
|
||||
const newConnectorHTML = `
|
||||
<div class="action mb-4">
|
||||
<label for="actionsName${ii}" class="block text-sm font-medium text-gray-400">Connector Type</label>
|
||||
<select name="actions[${ii}].name" id="actionsName${ii}" class="mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-700 text-white">
|
||||
{{ range .Actions }}
|
||||
<option value="{{.}}">{{.}}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<div class="mb-4">
|
||||
<label for="actionsConfig${ii}" class="block text-sm font-medium text-gray-400">Connector Config (JSON)</label>
|
||||
<textarea id="actionsConfig${ii}" name="actions[${ii}].config" class="mt-1 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-700 text-white" placeholder='{"token":"..."}'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
actionsSection.insertAdjacentHTML('beforeend', newConnectorHTML);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<div class="mb-4">
|
||||
|
||||
Reference in New Issue
Block a user