Compare commits
3 Commits
action-pla
...
chore/ubun
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfa3728867 | ||
|
|
15efd2d527 | ||
|
|
5e3bc0f89b |
@@ -20,10 +20,10 @@ COPY . .
|
|||||||
RUN CGO_ENABLED=0 GOOS=linux go build -o mcpbox ./cmd/mcpbox
|
RUN CGO_ENABLED=0 GOOS=linux go build -o mcpbox ./cmd/mcpbox
|
||||||
|
|
||||||
# Final stage
|
# Final stage
|
||||||
FROM alpine:3.19
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
# Install runtime dependencies
|
# Install runtime dependencies
|
||||||
RUN apk add --no-cache ca-certificates tzdata docker
|
RUN apt-get update && apt-get install -y ca-certificates tzdata docker.io bash
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
#RUN adduser -D -g '' appuser
|
#RUN adduser -D -g '' appuser
|
||||||
|
|||||||
@@ -95,11 +95,6 @@ func (a *CustomAction) Run(ctx context.Context, params types.ActionParams) (type
|
|||||||
|
|
||||||
func (a *CustomAction) Definition() types.ActionDefinition {
|
func (a *CustomAction) Definition() types.ActionDefinition {
|
||||||
|
|
||||||
if a.i == nil {
|
|
||||||
xlog.Error("Interpreter is not initialized for custom action", "action", a.config["name"])
|
|
||||||
return types.ActionDefinition{}
|
|
||||||
}
|
|
||||||
|
|
||||||
v, err := a.i.Eval(fmt.Sprintf("%s.Definition", a.config["name"]))
|
v, err := a.i.Eval(fmt.Sprintf("%s.Definition", a.config["name"]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xlog.Error("Error getting custom action definition", "error", err)
|
xlog.Error("Error getting custom action definition", "error", err)
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ services:
|
|||||||
- /dev/dri/card1
|
- /dev/dri/card1
|
||||||
- /dev/dri/renderD129
|
- /dev/dri/renderD129
|
||||||
|
|
||||||
|
mcpbox:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: mcpbox
|
||||||
|
|
||||||
localrecall:
|
localrecall:
|
||||||
extends:
|
extends:
|
||||||
file: docker-compose.yaml
|
file: docker-compose.yaml
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ services:
|
|||||||
count: 1
|
count: 1
|
||||||
capabilities: [gpu]
|
capabilities: [gpu]
|
||||||
|
|
||||||
|
mcpbox:
|
||||||
|
extends:
|
||||||
|
file: docker-compose.yaml
|
||||||
|
service: mcpbox
|
||||||
|
|
||||||
localrecall:
|
localrecall:
|
||||||
extends:
|
extends:
|
||||||
file: docker-compose.yaml
|
file: docker-compose.yaml
|
||||||
|
|||||||
@@ -30,9 +30,15 @@ func NewDiscord(config map[string]string) *Discord {
|
|||||||
duration = 5 * time.Minute
|
duration = 5 * time.Minute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token := config["token"]
|
||||||
|
|
||||||
|
if !strings.HasPrefix(token, "Bot ") {
|
||||||
|
token = "Bot " + token
|
||||||
|
}
|
||||||
|
|
||||||
return &Discord{
|
return &Discord{
|
||||||
conversationTracker: NewConversationTracker[string](duration),
|
conversationTracker: NewConversationTracker[string](duration),
|
||||||
token: config["token"],
|
token: token,
|
||||||
defaultChannel: config["defaultChannel"],
|
defaultChannel: config["defaultChannel"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
webui/app.go
24
webui/app.go
@@ -419,30 +419,6 @@ func (a *App) Chat(pool *state.AgentPool) func(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetActionDefinition(pool *state.AgentPool) func(c *fiber.Ctx) error {
|
|
||||||
return func(c *fiber.Ctx) error {
|
|
||||||
payload := struct {
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if err := c.BodyParser(&payload); err != nil {
|
|
||||||
xlog.Error("Error parsing action payload", "error", err)
|
|
||||||
return errorJSONMessage(c, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
actionName := c.Params("name")
|
|
||||||
|
|
||||||
xlog.Debug("Executing action", "action", actionName, "config", payload.Config)
|
|
||||||
a, err := services.Action(actionName, "", payload.Config, pool, map[string]string{})
|
|
||||||
if err != nil {
|
|
||||||
xlog.Error("Error creating action", "error", err)
|
|
||||||
return errorJSONMessage(c, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(a.Definition())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) ExecuteAction(pool *state.AgentPool) func(c *fiber.Ctx) error {
|
func (a *App) ExecuteAction(pool *state.AgentPool) func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
payload := struct {
|
payload := struct {
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useOutletContext, useNavigate } from 'react-router-dom';
|
import { useOutletContext, useNavigate } from 'react-router-dom';
|
||||||
import { actionApi, agentApi } from '../utils/api';
|
import { actionApi } from '../utils/api';
|
||||||
import FormFieldDefinition from '../components/common/FormFieldDefinition';
|
|
||||||
import hljs from 'highlight.js/lib/core';
|
|
||||||
import json from 'highlight.js/lib/languages/json';
|
|
||||||
import 'highlight.js/styles/monokai.css';
|
|
||||||
hljs.registerLanguage('json', json);
|
|
||||||
|
|
||||||
function ActionsPlayground() {
|
function ActionsPlayground() {
|
||||||
const { showToast } = useOutletContext();
|
const { showToast } = useOutletContext();
|
||||||
@@ -17,10 +12,6 @@ function ActionsPlayground() {
|
|||||||
const [result, setResult] = useState(null);
|
const [result, setResult] = useState(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [loadingActions, setLoadingActions] = useState(true);
|
const [loadingActions, setLoadingActions] = useState(true);
|
||||||
const [actionMetadata, setActionMetadata] = useState(null);
|
|
||||||
const [agentMetadata, setAgentMetadata] = useState(null);
|
|
||||||
const [configFields, setConfigFields] = useState([]);
|
|
||||||
const [paramFields, setParamFields] = useState([]);
|
|
||||||
|
|
||||||
// Update document title
|
// Update document title
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -45,106 +36,21 @@ function ActionsPlayground() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchActions();
|
fetchActions();
|
||||||
}, []);
|
}, [showToast]);
|
||||||
|
|
||||||
// Fetch agent metadata on mount
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchAgentMetadata = async () => {
|
|
||||||
try {
|
|
||||||
const metadata = await agentApi.getAgentConfigMetadata();
|
|
||||||
setAgentMetadata(metadata);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching agent metadata:', err);
|
|
||||||
showToast('Failed to load agent metadata', 'error');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchAgentMetadata();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Fetch action definition when action is selected or config changes
|
|
||||||
useEffect(() => {
|
|
||||||
if (!selectedAction) return;
|
|
||||||
|
|
||||||
const fetchActionDefinition = async () => {
|
|
||||||
try {
|
|
||||||
// Get config fields from agent metadata
|
|
||||||
const actionMeta = agentMetadata?.actions?.find(action => action.name === selectedAction);
|
|
||||||
const configFields = actionMeta?.fields || [];
|
|
||||||
console.debug('Config fields:', configFields);
|
|
||||||
setConfigFields(configFields);
|
|
||||||
|
|
||||||
// Parse current config to pass to action definition
|
|
||||||
let currentConfig = {};
|
|
||||||
try {
|
|
||||||
currentConfig = JSON.parse(configJson);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error parsing current config:', err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get parameter fields from action definition
|
|
||||||
const paramFields = await actionApi.getActionDefinition(selectedAction, currentConfig);
|
|
||||||
console.debug('Parameter fields:', paramFields);
|
|
||||||
setParamFields(paramFields);
|
|
||||||
|
|
||||||
// Reset JSON to match the new fields
|
|
||||||
setConfigJson(JSON.stringify(currentConfig, null, 2));
|
|
||||||
setParamsJson(JSON.stringify({}, null, 2));
|
|
||||||
setResult(null);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching action definition:', err);
|
|
||||||
showToast('Failed to load action definition', 'error');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchActionDefinition();
|
|
||||||
}, [selectedAction, agentMetadata]);
|
|
||||||
|
|
||||||
// Handle action selection
|
// Handle action selection
|
||||||
const handleActionChange = (e) => {
|
const handleActionChange = (e) => {
|
||||||
setSelectedAction(e.target.value);
|
setSelectedAction(e.target.value);
|
||||||
setConfigJson('{}');
|
|
||||||
setParamsJson('{}');
|
|
||||||
setResult(null);
|
setResult(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper to generate onChange handlers for form fields
|
// Handle JSON input changes
|
||||||
const makeFieldChangeHandler = (fields, updateFn) => (e) => {
|
const handleConfigChange = (e) => {
|
||||||
let value;
|
setConfigJson(e.target.value);
|
||||||
if (e && e.target) {
|
|
||||||
const fieldName = e.target.name;
|
|
||||||
const fieldDef = fields.find(f => f.name === fieldName);
|
|
||||||
const fieldType = fieldDef ? fieldDef.type : undefined;
|
|
||||||
if (fieldType === 'checkbox') {
|
|
||||||
value = e.target.checked;
|
|
||||||
} else if (fieldType === 'number') {
|
|
||||||
value = e.target.value === '' ? '' : Number(e.target.value);
|
|
||||||
} else {
|
|
||||||
value = e.target.value;
|
|
||||||
}
|
|
||||||
updateFn(fieldName, value);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle form field changes
|
const handleParamsChange = (e) => {
|
||||||
const handleConfigChange = (field, value) => {
|
setParamsJson(e.target.value);
|
||||||
try {
|
|
||||||
const config = JSON.parse(configJson);
|
|
||||||
config[field] = value;
|
|
||||||
setConfigJson(JSON.stringify(config, null, 2));
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error updating config:', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleParamsChange = (field, value) => {
|
|
||||||
try {
|
|
||||||
const params = JSON.parse(paramsJson);
|
|
||||||
params[field] = value;
|
|
||||||
setParamsJson(JSON.stringify(params, null, 2));
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error updating params:', err);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute the selected action
|
// Execute the selected action
|
||||||
@@ -229,31 +135,34 @@ function ActionsPlayground() {
|
|||||||
|
|
||||||
{selectedAction && (
|
{selectedAction && (
|
||||||
<div className="section-box">
|
<div className="section-box">
|
||||||
|
<h2>Action Configuration</h2>
|
||||||
|
|
||||||
<form onSubmit={handleExecuteAction}>
|
<form onSubmit={handleExecuteAction}>
|
||||||
{configFields.length > 0 && (
|
<div className="form-group mb-6">
|
||||||
<>
|
<label htmlFor="config-json">Configuration (JSON):</label>
|
||||||
<h2>Configuration</h2>
|
<textarea
|
||||||
<FormFieldDefinition
|
id="config-json"
|
||||||
fields={configFields}
|
value={configJson}
|
||||||
values={JSON.parse(configJson)}
|
onChange={handleConfigChange}
|
||||||
onChange={makeFieldChangeHandler(configFields, handleConfigChange)}
|
className="form-control"
|
||||||
idPrefix="config_"
|
rows="5"
|
||||||
|
placeholder='{"key": "value"}'
|
||||||
/>
|
/>
|
||||||
</>
|
<p className="text-xs text-gray-400 mt-1">Enter JSON configuration for the action</p>
|
||||||
)}
|
</div>
|
||||||
|
|
||||||
{paramFields.length > 0 && (
|
<div className="form-group mb-6">
|
||||||
<>
|
<label htmlFor="params-json">Parameters (JSON):</label>
|
||||||
<h2>Parameters</h2>
|
<textarea
|
||||||
<FormFieldDefinition
|
id="params-json"
|
||||||
fields={paramFields}
|
value={paramsJson}
|
||||||
values={JSON.parse(paramsJson)}
|
onChange={handleParamsChange}
|
||||||
onChange={makeFieldChangeHandler(paramFields, handleParamsChange)}
|
className="form-control"
|
||||||
idPrefix="param_"
|
rows="5"
|
||||||
|
placeholder='{"key": "value"}'
|
||||||
/>
|
/>
|
||||||
</>
|
<p className="text-xs text-gray-400 mt-1">Enter JSON parameters for the action</p>
|
||||||
)}
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<button
|
<button
|
||||||
@@ -285,9 +194,9 @@ function ActionsPlayground() {
|
|||||||
backgroundColor: 'rgba(30, 30, 30, 0.7)'
|
backgroundColor: 'rgba(30, 30, 30, 0.7)'
|
||||||
}}>
|
}}>
|
||||||
{typeof result === 'object' ? (
|
{typeof result === 'object' ? (
|
||||||
<pre className="hljs"><code>
|
<pre style={{ margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
||||||
<div dangerouslySetInnerHTML={{ __html: hljs.highlight(JSON.stringify(result, null, 2), { language: 'json' }).value }}></div>
|
{JSON.stringify(result, null, 2)}
|
||||||
</code></pre>
|
</pre>
|
||||||
) : (
|
) : (
|
||||||
<pre style={{ margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
<pre style={{ margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
||||||
{result}
|
{result}
|
||||||
|
|||||||
55
webui/react-ui/src/utils/api.js
vendored
55
webui/react-ui/src/utils/api.js
vendored
@@ -24,50 +24,6 @@ const buildUrl = (endpoint) => {
|
|||||||
return `${API_CONFIG.baseUrl}${endpoint.startsWith('/') ? endpoint.substring(1) : endpoint}`;
|
return `${API_CONFIG.baseUrl}${endpoint.startsWith('/') ? endpoint.substring(1) : endpoint}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to convert ActionDefinition to FormFieldDefinition format
|
|
||||||
const convertActionDefinitionToFields = (definition) => {
|
|
||||||
if (!definition || !definition.Properties) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const fields = [];
|
|
||||||
const required = definition.Required || [];
|
|
||||||
|
|
||||||
console.debug('Action definition:', definition);
|
|
||||||
|
|
||||||
Object.entries(definition.Properties).forEach(([name, property]) => {
|
|
||||||
const field = {
|
|
||||||
name,
|
|
||||||
label: name.charAt(0).toUpperCase() + name.slice(1),
|
|
||||||
type: 'text', // Default to text, we'll enhance this later
|
|
||||||
required: required.includes(name),
|
|
||||||
helpText: property.Description || '',
|
|
||||||
defaultValue: property.Default,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (property.enum && property.enum.length > 0) {
|
|
||||||
field.type = 'select';
|
|
||||||
field.options = property.enum;
|
|
||||||
} else {
|
|
||||||
switch (property.type) {
|
|
||||||
case 'integer':
|
|
||||||
field.type = 'number';
|
|
||||||
field.min = property.Minimum;
|
|
||||||
field.max = property.Maximum;
|
|
||||||
break;
|
|
||||||
case 'boolean':
|
|
||||||
field.type = 'checkbox';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// TODO: Handle Object and Array types which require nested fields
|
|
||||||
}
|
|
||||||
|
|
||||||
fields.push(field);
|
|
||||||
});
|
|
||||||
|
|
||||||
return fields;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Agent-related API calls
|
// Agent-related API calls
|
||||||
export const agentApi = {
|
export const agentApi = {
|
||||||
// Get list of all agents
|
// Get list of all agents
|
||||||
@@ -260,17 +216,6 @@ export const actionApi = {
|
|||||||
return handleResponse(response);
|
return handleResponse(response);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get action definition
|
|
||||||
getActionDefinition: async (name, config = {}) => {
|
|
||||||
const response = await fetch(buildUrl(API_CONFIG.endpoints.actionDefinition(name)), {
|
|
||||||
method: 'POST',
|
|
||||||
headers: API_CONFIG.headers,
|
|
||||||
body: JSON.stringify(config),
|
|
||||||
});
|
|
||||||
const definition = await handleResponse(response);
|
|
||||||
return convertActionDefinitionToFields(definition);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Execute an action for an agent
|
// Execute an action for an agent
|
||||||
executeAction: async (name, actionData) => {
|
executeAction: async (name, actionData) => {
|
||||||
const response = await fetch(buildUrl(API_CONFIG.endpoints.executeAction(name)), {
|
const response = await fetch(buildUrl(API_CONFIG.endpoints.executeAction(name)), {
|
||||||
|
|||||||
1
webui/react-ui/src/utils/config.js
vendored
1
webui/react-ui/src/utils/config.js
vendored
@@ -43,7 +43,6 @@ export const API_CONFIG = {
|
|||||||
|
|
||||||
// Action endpoints
|
// Action endpoints
|
||||||
listActions: '/api/actions',
|
listActions: '/api/actions',
|
||||||
actionDefinition: (name) => `/api/action/${name}/definition`,
|
|
||||||
executeAction: (name) => `/api/action/${name}/run`,
|
executeAction: (name) => `/api/action/${name}/run`,
|
||||||
|
|
||||||
// Status endpoint
|
// Status endpoint
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ func (app *App) registerRoutes(pool *state.AgentPool, webapp *fiber.App) {
|
|||||||
// Add endpoint for getting agent config metadata
|
// Add endpoint for getting agent config metadata
|
||||||
webapp.Get("/api/meta/agent/config", app.GetAgentConfigMeta())
|
webapp.Get("/api/meta/agent/config", app.GetAgentConfigMeta())
|
||||||
|
|
||||||
webapp.Post("/api/action/:name/definition", app.GetActionDefinition(pool))
|
|
||||||
webapp.Post("/api/action/:name/run", app.ExecuteAction(pool))
|
webapp.Post("/api/action/:name/run", app.ExecuteAction(pool))
|
||||||
webapp.Get("/api/actions", app.ListActions())
|
webapp.Get("/api/actions", app.ListActions())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user