@xeplr/ui-actions 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +30 -0
- package/src/ActionExplorer.jsx +74 -0
- package/src/ActionRunner.jsx +108 -0
- package/src/index.js +4 -0
- package/src/styles.css +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xeplr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xeplr/ui-actions",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React components for @xeplr/actions — ActionExplorer + ActionRunner (builds on @xeplr/ui-schema-handler)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"src/"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"actions",
|
|
12
|
+
"action-explorer",
|
|
13
|
+
"runner",
|
|
14
|
+
"react"
|
|
15
|
+
],
|
|
16
|
+
"author": "xeplr",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/Xeplr/xeplr-ui-actions"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
27
|
+
"@xeplr/actions": "^1.0.0",
|
|
28
|
+
"@xeplr/ui-schema-handler": "^1.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* List actions from the registry. Click one to expand its input/output schema.
|
|
5
|
+
*
|
|
6
|
+
* Props:
|
|
7
|
+
* actions — [{name, description, inputSchema, outputSchema}] (e.g. from actions.list())
|
|
8
|
+
* onSelect(name) — optional callback when an action is clicked
|
|
9
|
+
* selected — name of currently-selected action (for highlighting)
|
|
10
|
+
*/
|
|
11
|
+
export function ActionExplorer({ actions = [], onSelect, selected }) {
|
|
12
|
+
return (
|
|
13
|
+
<div className="xeplr-ax-explorer">
|
|
14
|
+
{actions.length === 0 && (
|
|
15
|
+
<div className="xeplr-ax-empty">No actions registered.</div>
|
|
16
|
+
)}
|
|
17
|
+
{actions.map(a => (
|
|
18
|
+
<ActionCard
|
|
19
|
+
key={a.name}
|
|
20
|
+
action={a}
|
|
21
|
+
selected={selected === a.name}
|
|
22
|
+
onClick={() => onSelect && onSelect(a.name)}
|
|
23
|
+
/>
|
|
24
|
+
))}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function ActionCard({ action, selected, onClick }) {
|
|
30
|
+
const [open, setOpen] = React.useState(false);
|
|
31
|
+
return (
|
|
32
|
+
<div className={`xeplr-ax-card${selected ? ' xeplr-ax-card--selected' : ''}`}>
|
|
33
|
+
<div className="xeplr-ax-card-hd" onClick={() => { setOpen(!open); onClick && onClick(); }}>
|
|
34
|
+
<span className="xeplr-ax-name">{action.name}</span>
|
|
35
|
+
<span className="xeplr-ax-hint">{open ? '▾' : '▸'}</span>
|
|
36
|
+
</div>
|
|
37
|
+
{action.description && <div className="xeplr-ax-desc">{action.description}</div>}
|
|
38
|
+
{open && (
|
|
39
|
+
<div className="xeplr-ax-body">
|
|
40
|
+
<SchemaTable title="Inputs" fields={action.inputSchema} />
|
|
41
|
+
{action.outputSchema && <SchemaTable title="Outputs" fields={action.outputSchema} />}
|
|
42
|
+
</div>
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function SchemaTable({ title, fields }) {
|
|
49
|
+
if (!Array.isArray(fields) || fields.length === 0) {
|
|
50
|
+
return <div className="xeplr-ax-schema-empty">{title}: <em>none</em></div>;
|
|
51
|
+
}
|
|
52
|
+
const sorted = [...fields].sort((a, b) => (a.order ?? 999) - (b.order ?? 999));
|
|
53
|
+
return (
|
|
54
|
+
<div>
|
|
55
|
+
<div className="xeplr-ax-schema-title">{title}</div>
|
|
56
|
+
<table className="xeplr-ax-schema-tbl">
|
|
57
|
+
<thead>
|
|
58
|
+
<tr><th>Name</th><th>Type</th><th>Req</th><th>Default</th><th>Description</th></tr>
|
|
59
|
+
</thead>
|
|
60
|
+
<tbody>
|
|
61
|
+
{sorted.map(f => (
|
|
62
|
+
<tr key={f.name}>
|
|
63
|
+
<td><code>{f.name}</code></td>
|
|
64
|
+
<td>{f.type || 'string'}</td>
|
|
65
|
+
<td>{f.required ? '●' : ''}</td>
|
|
66
|
+
<td>{f.default === undefined ? '' : JSON.stringify(f.default)}</td>
|
|
67
|
+
<td>{f.description || ''}</td>
|
|
68
|
+
</tr>
|
|
69
|
+
))}
|
|
70
|
+
</tbody>
|
|
71
|
+
</table>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DynamicForm } from '@xeplr/ui-schema-handler';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* "Try this action" playground. Pick an action, fill inputs, invoke, see result.
|
|
6
|
+
*
|
|
7
|
+
* Props:
|
|
8
|
+
* actions — [{name, description, inputSchema, outputSchema}]
|
|
9
|
+
* onRun(name, input) => Promise<{status, output, error, durationMs}>
|
|
10
|
+
* Typically bound to actions.runAction from @xeplr/actions,
|
|
11
|
+
* or a network call if invoking on a remote scheduler.
|
|
12
|
+
* initialAction — optional action name to preselect
|
|
13
|
+
*/
|
|
14
|
+
export function ActionRunner({ actions = [], onRun, initialAction = null }) {
|
|
15
|
+
const [name, setName] = React.useState(initialAction || (actions[0] && actions[0].name) || '');
|
|
16
|
+
const [input, setInput] = React.useState({});
|
|
17
|
+
const [busy, setBusy] = React.useState(false);
|
|
18
|
+
const [result, setResult] = React.useState(null);
|
|
19
|
+
|
|
20
|
+
// Reset input when switching actions.
|
|
21
|
+
React.useEffect(() => { setInput({}); setResult(null); }, [name]);
|
|
22
|
+
|
|
23
|
+
const action = actions.find(a => a.name === name);
|
|
24
|
+
|
|
25
|
+
const run = async () => {
|
|
26
|
+
if (!onRun) return;
|
|
27
|
+
setBusy(true); setResult(null);
|
|
28
|
+
try {
|
|
29
|
+
const r = await onRun(name, input);
|
|
30
|
+
setResult(r);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
setResult({ status: 'failed', error: { name: err.name, message: err.message }, durationMs: 0 });
|
|
33
|
+
} finally { setBusy(false); }
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="xeplr-ax-runner">
|
|
38
|
+
<div className="xeplr-ax-runner-row">
|
|
39
|
+
<label>
|
|
40
|
+
<span className="xeplr-ax-runner-lbl">Action</span>
|
|
41
|
+
<select
|
|
42
|
+
className="xeplr-ax-runner-select"
|
|
43
|
+
value={name}
|
|
44
|
+
onChange={(e) => setName(e.target.value)}
|
|
45
|
+
>
|
|
46
|
+
{actions.map(a => <option key={a.name} value={a.name}>{a.name}</option>)}
|
|
47
|
+
</select>
|
|
48
|
+
</label>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
{action && (
|
|
52
|
+
<>
|
|
53
|
+
{action.description && <div className="xeplr-ax-runner-desc">{action.description}</div>}
|
|
54
|
+
|
|
55
|
+
<div className="xeplr-ax-runner-form">
|
|
56
|
+
<div className="xeplr-ax-runner-lbl">Inputs</div>
|
|
57
|
+
<DynamicForm
|
|
58
|
+
schema={action.inputSchema || []}
|
|
59
|
+
value={input}
|
|
60
|
+
onChange={setInput}
|
|
61
|
+
disabled={busy}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div className="xeplr-ax-runner-actions">
|
|
66
|
+
<button className="xeplr-ax-primary" onClick={run} disabled={busy}>
|
|
67
|
+
{busy ? 'Running…' : 'Run'}
|
|
68
|
+
</button>
|
|
69
|
+
<button onClick={() => { setInput({}); setResult(null); }} disabled={busy}>Reset</button>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
{result && <ResultPanel result={result} />}
|
|
73
|
+
</>
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function ResultPanel({ result }) {
|
|
80
|
+
const cls = 'xeplr-ax-result xeplr-ax-result--' + result.status;
|
|
81
|
+
return (
|
|
82
|
+
<div className={cls}>
|
|
83
|
+
<div className="xeplr-ax-result-hd">
|
|
84
|
+
<span>{result.status === 'success' ? '✓' : '✗'} {result.status}</span>
|
|
85
|
+
{typeof result.durationMs === 'number' && (
|
|
86
|
+
<span className="xeplr-ax-result-dur">{result.durationMs}ms</span>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
{result.status === 'success' && (
|
|
90
|
+
<pre className="xeplr-ax-result-body">{safeJson(result.output)}</pre>
|
|
91
|
+
)}
|
|
92
|
+
{result.status !== 'success' && result.error && (
|
|
93
|
+
<>
|
|
94
|
+
<div className="xeplr-ax-result-err-title">{result.error.name || 'Error'}: {result.error.message}</div>
|
|
95
|
+
{Array.isArray(result.error.details) && result.error.details.length > 0 && (
|
|
96
|
+
<ul className="xeplr-ax-result-err-details">
|
|
97
|
+
{result.error.details.map((d, i) => <li key={i}>{d}</li>)}
|
|
98
|
+
</ul>
|
|
99
|
+
)}
|
|
100
|
+
</>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function safeJson(v) {
|
|
107
|
+
try { return JSON.stringify(v, null, 2); } catch { return String(v); }
|
|
108
|
+
}
|
package/src/index.js
ADDED
package/src/styles.css
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* Prefix: xeplr-ax-* (Actions). All rules easy to override. */
|
|
2
|
+
|
|
3
|
+
.xeplr-ax-explorer { display: flex; flex-direction: column; gap: 8px; }
|
|
4
|
+
.xeplr-ax-empty { color: #999; font-style: italic; padding: 8px 0; }
|
|
5
|
+
|
|
6
|
+
.xeplr-ax-card {
|
|
7
|
+
border: 1px solid #e0e0e0; border-radius: 6px; background: #fff;
|
|
8
|
+
}
|
|
9
|
+
.xeplr-ax-card--selected { border-color: #646cff; box-shadow: 0 0 0 2px rgba(100,108,255,0.15); }
|
|
10
|
+
.xeplr-ax-card-hd {
|
|
11
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
12
|
+
padding: 10px 12px; cursor: pointer; user-select: none;
|
|
13
|
+
font-family: system-ui, sans-serif;
|
|
14
|
+
}
|
|
15
|
+
.xeplr-ax-card-hd:hover { background: #f7f7f8; }
|
|
16
|
+
.xeplr-ax-name { font-weight: 600; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
|
|
17
|
+
.xeplr-ax-hint { color: #888; font-size: 12px; }
|
|
18
|
+
.xeplr-ax-desc { padding: 0 12px 8px; color: #666; font-size: 12px; }
|
|
19
|
+
.xeplr-ax-body { padding: 10px 12px 12px; border-top: 1px solid #eee; }
|
|
20
|
+
|
|
21
|
+
.xeplr-ax-schema-title { font-size: 12px; font-weight: 600; color: #555; margin: 6px 0 4px; }
|
|
22
|
+
.xeplr-ax-schema-empty { font-size: 12px; color: #999; margin: 4px 0; }
|
|
23
|
+
.xeplr-ax-schema-tbl {
|
|
24
|
+
width: 100%; border-collapse: collapse; font-size: 12px; font-family: system-ui, sans-serif;
|
|
25
|
+
}
|
|
26
|
+
.xeplr-ax-schema-tbl th, .xeplr-ax-schema-tbl td {
|
|
27
|
+
border-bottom: 1px solid #f0f0f0; padding: 4px 6px; text-align: left; vertical-align: top;
|
|
28
|
+
}
|
|
29
|
+
.xeplr-ax-schema-tbl th { color: #666; font-weight: 600; }
|
|
30
|
+
.xeplr-ax-schema-tbl code { background: #f4f4f6; padding: 1px 4px; border-radius: 3px; }
|
|
31
|
+
|
|
32
|
+
/* Runner */
|
|
33
|
+
.xeplr-ax-runner { display: flex; flex-direction: column; gap: 14px; font-family: system-ui, sans-serif; }
|
|
34
|
+
.xeplr-ax-runner-lbl { font-size: 12px; font-weight: 600; color: #555; display: block; margin-bottom: 4px; }
|
|
35
|
+
.xeplr-ax-runner-select {
|
|
36
|
+
padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font: inherit; min-width: 240px;
|
|
37
|
+
}
|
|
38
|
+
.xeplr-ax-runner-desc { color: #666; font-size: 12px; }
|
|
39
|
+
.xeplr-ax-runner-form { }
|
|
40
|
+
.xeplr-ax-runner-actions { display: flex; gap: 8px; }
|
|
41
|
+
.xeplr-ax-runner-actions button {
|
|
42
|
+
padding: 8px 14px; border: 1px solid #ccc; background: #fff; border-radius: 4px; cursor: pointer; font: inherit;
|
|
43
|
+
}
|
|
44
|
+
.xeplr-ax-primary { background: #646cff; color: #fff; border-color: #646cff; }
|
|
45
|
+
.xeplr-ax-primary:hover:not(:disabled) { background: #535bf2; }
|
|
46
|
+
.xeplr-ax-primary:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
47
|
+
|
|
48
|
+
.xeplr-ax-result {
|
|
49
|
+
padding: 10px 12px; border-radius: 6px; margin-top: 4px;
|
|
50
|
+
font-family: system-ui, sans-serif; font-size: 13px;
|
|
51
|
+
}
|
|
52
|
+
.xeplr-ax-result--success { background: #e8f5e8; border: 1px solid #b6dfb6; color: #2d7d2d; }
|
|
53
|
+
.xeplr-ax-result--failed { background: #ffecec; border: 1px solid #f5c6c6; color: #c00; }
|
|
54
|
+
.xeplr-ax-result--skipped { background: #fff4d6; border: 1px solid #e6c17d; color: #8a5a00; }
|
|
55
|
+
.xeplr-ax-result-hd { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
|
|
56
|
+
.xeplr-ax-result-dur { font-weight: 400; opacity: 0.7; }
|
|
57
|
+
.xeplr-ax-result-body {
|
|
58
|
+
background: rgba(255,255,255,0.7); padding: 8px; border-radius: 4px;
|
|
59
|
+
font-family: ui-monospace, Consolas, monospace; font-size: 12px;
|
|
60
|
+
margin: 0; overflow: auto; color: #222;
|
|
61
|
+
}
|
|
62
|
+
.xeplr-ax-result-err-title { font-weight: 600; }
|
|
63
|
+
.xeplr-ax-result-err-details { margin: 4px 0 0 20px; padding: 0; }
|