administrate-mcp 0.4.0 → 0.6.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -1
- data/README.md +12 -0
- data/app/lib/administrate/mcp/action_result.rb +36 -0
- data/app/lib/administrate/mcp/actions/result_data.rb +96 -0
- data/app/lib/administrate/mcp/actions.rb +24 -7
- data/app/lib/administrate/mcp/base_tool.rb +32 -4
- data/app/lib/administrate/mcp/feedback_categories.rb +2 -1
- data/app/lib/administrate/mcp/server_builder.rb +10 -1
- data/app/lib/administrate/mcp/tool_view.rb +125 -0
- data/app/lib/administrate/mcp/tool_views/field_hints.rb +78 -0
- data/app/lib/administrate/mcp/tool_views/resource_view.rb +17 -0
- data/app/lib/administrate/mcp/tool_views/sidekiq_view.rb +17 -0
- data/app/lib/administrate/mcp/tools/admin_resource_list.rb +4 -1
- data/app/lib/administrate/mcp/tools/admin_resource_show.rb +11 -4
- data/app/lib/administrate/mcp/tools/report_improvement.rb +2 -1
- data/app/lib/administrate/mcp/tools/sidekiq_retries.rb +1 -0
- data/app/lib/administrate/mcp/tools/sidekiq_stats.rb +1 -0
- data/docs/configuration.md +5 -0
- data/docs/dashboards.md +60 -1
- data/docs/tool-views.md +135 -0
- data/lib/administrate/mcp/configuration.rb +6 -0
- data/lib/administrate/mcp/tool_views/resource.css +25 -0
- data/lib/administrate/mcp/tool_views/resource.js +384 -0
- data/lib/administrate/mcp/tool_views/runtime.css +112 -0
- data/lib/administrate/mcp/tool_views/runtime.js +296 -0
- data/lib/administrate/mcp/tool_views/sidekiq.css +6 -0
- data/lib/administrate/mcp/tool_views/sidekiq.js +108 -0
- data/lib/administrate/mcp/version.rb +1 -1
- metadata +14 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// The resource view: renders admin_resource_list and admin_resource_show results, and, when the
|
|
2
|
+
// host proxies tool calls, pages, sorts, searches and follows associations in place.
|
|
3
|
+
(function () {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
var A = window.AdministrateMCP;
|
|
7
|
+
var h = A.h;
|
|
8
|
+
var HINTS_KEY = 'administrate-mcp/view';
|
|
9
|
+
var LIST_TOOL = 'admin_resource_list';
|
|
10
|
+
var SHOW_TOOL = 'admin_resource_show';
|
|
11
|
+
var IMAGE_PATH = /\.(png|jpe?g|gif|webp|avif|svg)(\?|#|$)/i;
|
|
12
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
|
|
13
|
+
|
|
14
|
+
var stack = [];
|
|
15
|
+
var input = {};
|
|
16
|
+
|
|
17
|
+
function current() {
|
|
18
|
+
return stack[stack.length - 1];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function humanize(name) {
|
|
22
|
+
var text = String(name).replace(/_id$/, '').replace(/[_/]+/g, ' ').trim();
|
|
23
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function resourceForType(type) {
|
|
27
|
+
return String(type)
|
|
28
|
+
.replace(/::/g, '/')
|
|
29
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
30
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
|
31
|
+
.toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function screenFrom(result, args) {
|
|
35
|
+
var hints = A.resultMeta(result, HINTS_KEY) || {};
|
|
36
|
+
var screen = {
|
|
37
|
+
args: Object.assign({}, args),
|
|
38
|
+
resource: hints.resource || args.resource,
|
|
39
|
+
fields: hints.fields || {},
|
|
40
|
+
error: A.resultError(result)
|
|
41
|
+
};
|
|
42
|
+
if (screen.error) return Object.assign(screen, { kind: 'error' });
|
|
43
|
+
|
|
44
|
+
var data = A.resultData(result);
|
|
45
|
+
screen.data = data;
|
|
46
|
+
if (data && data.status === 'ok' && data.action && data.model) {
|
|
47
|
+
screen.kind = 'action';
|
|
48
|
+
screen.resource = data.model;
|
|
49
|
+
} else if (data && Array.isArray(data.columns) && Array.isArray(data.rows)) {
|
|
50
|
+
screen.kind = data.meta && data.meta.page ? 'list' : 'batch';
|
|
51
|
+
} else if (data && typeof data === 'object') {
|
|
52
|
+
screen.kind = 'show';
|
|
53
|
+
} else {
|
|
54
|
+
screen.kind = 'error';
|
|
55
|
+
screen.error = typeof data === 'string' ? data : 'Nothing to show.';
|
|
56
|
+
}
|
|
57
|
+
return screen;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function describe(screen) {
|
|
61
|
+
if (screen.kind === 'action') return 'the result of ' + screen.data.action + ' on ' + screen.resource;
|
|
62
|
+
if (screen.kind === 'show') return 'the ' + screen.resource + ' record with id ' + JSON.stringify(String(screen.data.id));
|
|
63
|
+
if (screen.kind === 'list') {
|
|
64
|
+
var meta = screen.data.meta;
|
|
65
|
+
return 'page ' + meta.page + ' of ' + meta.total_pages + ' of the ' + screen.resource + ' list (' +
|
|
66
|
+
meta.total_count + ' records' + (screen.args.query ? ', filtered by a search' : '') + ')';
|
|
67
|
+
}
|
|
68
|
+
return 'the ' + screen.resource + ' records';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function load(tool, args, mode) {
|
|
72
|
+
var previous = current();
|
|
73
|
+
if (previous) previous.loading = true;
|
|
74
|
+
render();
|
|
75
|
+
return A.callTool(tool, args).then(function (result) {
|
|
76
|
+
var screen = screenFrom(result, args);
|
|
77
|
+
if (mode === 'replace') stack[stack.length - 1] = screen;
|
|
78
|
+
else stack.push(screen);
|
|
79
|
+
render();
|
|
80
|
+
A.updateModelContext('The user is viewing ' + describe(screen) + ' in the admin view.');
|
|
81
|
+
}).catch(function (error) {
|
|
82
|
+
if (previous) {
|
|
83
|
+
previous.loading = false;
|
|
84
|
+
previous.notice = error.message;
|
|
85
|
+
}
|
|
86
|
+
render();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function openShow(resource, id) {
|
|
91
|
+
load(SHOW_TOOL, { resource: resource, id: String(id) }, 'push');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function openList(resource, filters) {
|
|
95
|
+
load(LIST_TOOL, { resource: resource, filters: filters }, 'push');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function relist(changes) {
|
|
99
|
+
var args = Object.assign({}, current().args, changes);
|
|
100
|
+
load(LIST_TOOL, args, 'replace');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function recordLabel(screen) {
|
|
104
|
+
var data = screen.data || {};
|
|
105
|
+
return data.name || data.title || data.display_name || data.label || data.email || data.slug ||
|
|
106
|
+
(data.id !== undefined ? '#' + data.id : '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function empty() {
|
|
110
|
+
return h('span', { className: 'am-muted' }, '—');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function json(value, compact) {
|
|
114
|
+
var size = Array.isArray(value) ? value.length + ' items' : Object.keys(value).length + ' keys';
|
|
115
|
+
if (compact) return h('span', { className: 'am-muted' }, size);
|
|
116
|
+
return h('details', { className: 'am-json' }, h('summary', null, size), h('pre', null, JSON.stringify(value, null, 2)));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function attachment(url, compact) {
|
|
120
|
+
if (!A.isSafeUrl(url)) return document.createTextNode(String(url));
|
|
121
|
+
if (!IMAGE_PATH.test(url)) return A.link(url, compact ? 'File' : url);
|
|
122
|
+
var image = h('img', { src: url, alt: '', className: compact ? 'am-thumb' : 'am-image', loading: 'lazy' });
|
|
123
|
+
image.addEventListener('error', function () {
|
|
124
|
+
image.replaceWith(A.link(url, compact ? 'Image' : url));
|
|
125
|
+
});
|
|
126
|
+
return h('a', {
|
|
127
|
+
href: url,
|
|
128
|
+
onClick: function (event) {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
A.openLink(url);
|
|
131
|
+
}
|
|
132
|
+
}, image);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function related(value, hint) {
|
|
136
|
+
var label = value.display || value.slug || '#' + value.id;
|
|
137
|
+
var resource = (hint && hint.resource) || (value.type && resourceForType(value.type));
|
|
138
|
+
if (!resource || !A.canCallTools()) return document.createTextNode(label);
|
|
139
|
+
return h('button', {
|
|
140
|
+
className: 'am-link',
|
|
141
|
+
title: 'Open ' + resource + ' ' + value.id,
|
|
142
|
+
onClick: function (event) {
|
|
143
|
+
event.stopPropagation();
|
|
144
|
+
openShow(resource, value.id);
|
|
145
|
+
}
|
|
146
|
+
}, label);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function hasMany(value, hint, name, owner, compact) {
|
|
150
|
+
var count = value.count;
|
|
151
|
+
var label = count + ' ' + humanize(name).toLowerCase();
|
|
152
|
+
var canFollow = hint && hint.resource && hint.foreign_key && owner && owner.id !== undefined && A.canCallTools();
|
|
153
|
+
var summary = canFollow && count > 0
|
|
154
|
+
? h('button', {
|
|
155
|
+
className: 'am-link',
|
|
156
|
+
onClick: function (event) {
|
|
157
|
+
event.stopPropagation();
|
|
158
|
+
var filters = {};
|
|
159
|
+
filters[hint.foreign_key] = owner.id;
|
|
160
|
+
openList(hint.resource, filters);
|
|
161
|
+
}
|
|
162
|
+
}, label)
|
|
163
|
+
: h('span', null, label);
|
|
164
|
+
if (compact || !Array.isArray(value.items) || value.items.length === 0) return summary;
|
|
165
|
+
|
|
166
|
+
var columns = Object.keys(value.items[0]).filter(function (key) { return key !== 'url'; });
|
|
167
|
+
var rows = value.items.map(function (item) { return columns.map(function (key) { return item[key]; }); });
|
|
168
|
+
var shown = value.items.length < count ? h('p', { className: 'am-muted' }, 'Showing ' + value.items.length + ' of ' + count + '.') : null;
|
|
169
|
+
return h('div', null, summary, table(columns, rows, {}, {
|
|
170
|
+
resource: hint && hint.resource,
|
|
171
|
+
urls: value.items.map(function (item) { return item.url; })
|
|
172
|
+
}), shown);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function isRelated(value) {
|
|
176
|
+
return Object.keys(value).every(function (key) { return ['id', 'display', 'slug', 'type'].indexOf(key) >= 0; });
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function renderValue(value, hint, name, owner, compact) {
|
|
180
|
+
var kind = hint && hint.kind;
|
|
181
|
+
if (value === null || value === undefined || value === '') return empty();
|
|
182
|
+
if (typeof value === 'boolean') return h('span', { className: 'am-badge am-' + value }, value ? 'Yes' : 'No');
|
|
183
|
+
if (typeof value === 'number') return document.createTextNode(value.toLocaleString());
|
|
184
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
185
|
+
if (kind === 'has_many' || (value.count !== undefined && Object.keys(value).every(function (key) { return key === 'count' || key === 'items'; }))) {
|
|
186
|
+
return hasMany(value, hint, name, owner, compact);
|
|
187
|
+
}
|
|
188
|
+
if (value.id !== undefined && (kind === 'belongs_to' || kind === 'polymorphic' || isRelated(value))) {
|
|
189
|
+
return related(value, hint);
|
|
190
|
+
}
|
|
191
|
+
return json(value, compact);
|
|
192
|
+
}
|
|
193
|
+
if (Array.isArray(value)) return json(value, compact);
|
|
194
|
+
if (typeof value === 'string' && kind === 'attachment') return attachment(value, compact);
|
|
195
|
+
if (typeof value === 'string' && (kind === 'datetime' || ISO_DATE.test(value))) {
|
|
196
|
+
return h('time', { datetime: value, title: value }, A.formatDate(value));
|
|
197
|
+
}
|
|
198
|
+
if (kind === 'enum') return h('span', { className: 'am-badge' }, String(value));
|
|
199
|
+
if (typeof value === 'string' && kind === 'url' && A.isSafeUrl(value)) return A.link(value, value);
|
|
200
|
+
return document.createTextNode(String(value));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function table(columns, rows, fields, options) {
|
|
204
|
+
var idIndex = columns.indexOf('id');
|
|
205
|
+
var sort = options.sort;
|
|
206
|
+
var head = h('tr', null, columns.map(function (column) {
|
|
207
|
+
var label = humanize(column);
|
|
208
|
+
if (!options.onSort) return h('th', { scope: 'col' }, label);
|
|
209
|
+
var arrow = sort && sort.field === column ? (sort.direction === 'asc' ? ' ▲' : ' ▼') : '';
|
|
210
|
+
return h('th', { scope: 'col' }, h('button', {
|
|
211
|
+
className: 'am-link',
|
|
212
|
+
title: 'Sort by ' + label,
|
|
213
|
+
onClick: function () { options.onSort(column); }
|
|
214
|
+
}, label + arrow));
|
|
215
|
+
}));
|
|
216
|
+
|
|
217
|
+
var body = rows.map(function (row, index) {
|
|
218
|
+
if (!Array.isArray(row)) {
|
|
219
|
+
return h('tr', null, h('td', { colspan: columns.length, className: 'am-error' }, (row && row.error) || 'Not found'));
|
|
220
|
+
}
|
|
221
|
+
var owner = idIndex >= 0 ? { id: row[idIndex] } : null;
|
|
222
|
+
var url = options.urls && options.urls[index];
|
|
223
|
+
var target = options.resource && owner && A.canCallTools()
|
|
224
|
+
? function () { openShow(options.resource, owner.id); }
|
|
225
|
+
: (A.isSafeUrl(url) ? function () { A.openLink(url); } : null);
|
|
226
|
+
return h('tr', { className: target ? 'am-clickable' : null, onClick: target },
|
|
227
|
+
row.map(function (value, column) {
|
|
228
|
+
return h('td', null, renderValue(value, fields[columns[column]], columns[column], owner, true));
|
|
229
|
+
}));
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
return h('div', { className: 'am-table-wrap' },
|
|
233
|
+
h('table', { className: 'am-table' }, h('thead', null, head), h('tbody', null, body)));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function backButton() {
|
|
237
|
+
if (stack.length < 2) return null;
|
|
238
|
+
return h('button', {
|
|
239
|
+
title: 'Back',
|
|
240
|
+
onClick: function () {
|
|
241
|
+
stack.pop();
|
|
242
|
+
render();
|
|
243
|
+
A.updateModelContext('The user is viewing ' + describe(current()) + ' in the admin view.');
|
|
244
|
+
}
|
|
245
|
+
}, '←');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function toolbar(screen, title, extra, kicker) {
|
|
249
|
+
return h('div', { className: 'am-toolbar' },
|
|
250
|
+
backButton(),
|
|
251
|
+
kicker ? h('span', { className: 'am-badge' }, kicker) : null,
|
|
252
|
+
h('h1', null, title),
|
|
253
|
+
extra,
|
|
254
|
+
screen.loading ? h('span', { className: 'am-muted' }, 'Loading…') : null);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function splitRows(data) {
|
|
258
|
+
var urlIndex = data.columns.indexOf('url');
|
|
259
|
+
var columns = data.columns.filter(function (_, index) { return index !== urlIndex; });
|
|
260
|
+
var urls = [];
|
|
261
|
+
var rows = data.rows.map(function (row) {
|
|
262
|
+
if (!Array.isArray(row)) return row;
|
|
263
|
+
urls.push(urlIndex >= 0 ? row[urlIndex] : null);
|
|
264
|
+
return row.filter(function (_, index) { return index !== urlIndex; });
|
|
265
|
+
});
|
|
266
|
+
return { columns: columns, rows: rows, urls: urls };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function renderList(screen) {
|
|
270
|
+
var data = screen.data;
|
|
271
|
+
var meta = data.meta || {};
|
|
272
|
+
var split = splitRows(data);
|
|
273
|
+
var interactive = screen.kind === 'list' && A.canCallTools();
|
|
274
|
+
var sort = screen.args.sort ? { field: screen.args.sort, direction: screen.args.sort_direction || 'desc' } : null;
|
|
275
|
+
|
|
276
|
+
var search = interactive ? h('form', {
|
|
277
|
+
onSubmit: function (event) {
|
|
278
|
+
event.preventDefault();
|
|
279
|
+
relist({ query: event.target.elements.query.value || undefined, page: 1 });
|
|
280
|
+
}
|
|
281
|
+
}, h('input', { type: 'search', name: 'query', placeholder: 'Search', value: screen.args.query || '' })) : null;
|
|
282
|
+
|
|
283
|
+
var count = screen.kind === 'list'
|
|
284
|
+
? h('span', { className: 'am-muted' }, meta.total_count + ' record' + (meta.total_count === 1 ? '' : 's'))
|
|
285
|
+
: null;
|
|
286
|
+
|
|
287
|
+
var pager = screen.kind === 'list' && meta.total_pages > 1 ? h('div', { className: 'am-toolbar am-pager' },
|
|
288
|
+
h('button', { disabled: !interactive || meta.page <= 1, onClick: function () { relist({ page: meta.page - 1 }); } }, 'Previous'),
|
|
289
|
+
h('span', { className: 'am-muted' }, 'Page ' + meta.page + ' of ' + meta.total_pages),
|
|
290
|
+
h('button', { disabled: !interactive || meta.page >= meta.total_pages, onClick: function () { relist({ page: meta.page + 1 }); } }, 'Next')
|
|
291
|
+
) : null;
|
|
292
|
+
|
|
293
|
+
var body = split.rows.length === 0
|
|
294
|
+
? A.message('No records match.')
|
|
295
|
+
: table(split.columns, split.rows, screen.fields, {
|
|
296
|
+
resource: screen.resource,
|
|
297
|
+
urls: split.urls,
|
|
298
|
+
sort: sort,
|
|
299
|
+
onSort: interactive ? function (field) {
|
|
300
|
+
var direction = sort && sort.field === field && sort.direction === 'desc' ? 'asc' : 'desc';
|
|
301
|
+
relist({ sort: field, sort_direction: direction, page: 1 });
|
|
302
|
+
} : null
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return h('div', null, toolbar(screen, humanize(screen.resource || 'Records'), [count, h('span', { className: 'am-spacer' }), search]), body, pager);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function renderShow(screen) {
|
|
309
|
+
var data = screen.data;
|
|
310
|
+
var open = A.isSafeUrl(data.url) ? h('button', { onClick: function () { A.openLink(data.url); } }, 'Open in admin') : null;
|
|
311
|
+
var keys = Object.keys(data).filter(function (key) { return key !== 'url'; });
|
|
312
|
+
var fields = h('dl', { className: 'am-fields' }, keys.map(function (key) {
|
|
313
|
+
return [
|
|
314
|
+
h('dt', null, humanize(key)),
|
|
315
|
+
h('dd', null, renderValue(data[key], screen.fields[key], key, data, false))
|
|
316
|
+
];
|
|
317
|
+
}));
|
|
318
|
+
var resource = humanize(screen.resource || 'Record');
|
|
319
|
+
return h('div', null, toolbar(screen, recordLabel(screen) || resource, [h('span', { className: 'am-spacer' }), open], resource), fields);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function loadActionRecord(screen) {
|
|
323
|
+
screen.recordRequested = true;
|
|
324
|
+
A.callTool(SHOW_TOOL, { resource: screen.resource, id: String(screen.data.id) }).then(function (result) {
|
|
325
|
+
screen.record = screenFrom(result, { resource: screen.resource, id: String(screen.data.id) });
|
|
326
|
+
render();
|
|
327
|
+
}).catch(function () {
|
|
328
|
+
screen.record = null;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function renderAction(screen) {
|
|
333
|
+
var data = screen.data;
|
|
334
|
+
var extra = data.data && typeof data.data === 'object' && Object.keys(data.data).length
|
|
335
|
+
? h('div', { className: 'am-action-data' }, h('h2', null, 'Returned data'), json(data.data, false))
|
|
336
|
+
: null;
|
|
337
|
+
var title = humanize(data.action) + ' — done';
|
|
338
|
+
var view = h('div', null, toolbar(screen, title, [h('span', { className: 'am-spacer' }), h('span', { className: 'am-badge am-true' }, 'OK')], humanize(screen.resource)), extra);
|
|
339
|
+
if (data.id !== undefined && A.canCallTools() && !screen.recordRequested) loadActionRecord(screen);
|
|
340
|
+
if (screen.record && screen.record.kind === 'show') {
|
|
341
|
+
var record = renderShow(screen.record);
|
|
342
|
+
record.classList.add('am-action-record');
|
|
343
|
+
view.appendChild(record);
|
|
344
|
+
} else if (data.id !== undefined && !A.canCallTools()) {
|
|
345
|
+
view.appendChild(A.message(humanize(screen.resource) + ' ' + data.id));
|
|
346
|
+
}
|
|
347
|
+
return view;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function render() {
|
|
351
|
+
var screen = current();
|
|
352
|
+
if (!screen) return;
|
|
353
|
+
var view;
|
|
354
|
+
if (screen.kind === 'action') {
|
|
355
|
+
view = renderAction(screen);
|
|
356
|
+
} else if (screen.kind === 'error') {
|
|
357
|
+
view = h('div', null, toolbar(screen, humanize(screen.resource || A.toolName() || 'Admin'), null), A.message(screen.error, 'am-error'));
|
|
358
|
+
} else if (screen.kind === 'show') {
|
|
359
|
+
view = renderShow(screen);
|
|
360
|
+
} else {
|
|
361
|
+
view = renderList(screen);
|
|
362
|
+
}
|
|
363
|
+
if (screen.notice) view.appendChild(A.message(screen.notice, 'am-error'));
|
|
364
|
+
screen.notice = null;
|
|
365
|
+
A.mount(view);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
A.on('input', function (args) {
|
|
369
|
+
input = args || {};
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
A.on('result', function (result) {
|
|
373
|
+
stack = [screenFrom(result, input)];
|
|
374
|
+
render();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
A.on('cancelled', function () {
|
|
378
|
+
if (!stack.length) A.mount(A.message('The tool call was cancelled.'));
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
A.connect().catch(function (error) {
|
|
382
|
+
A.mount(A.message('Could not connect to the host: ' + error.message, 'am-error'));
|
|
383
|
+
});
|
|
384
|
+
})();
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: light dark;
|
|
3
|
+
--am-bg: var(--color-background-primary, light-dark(#ffffff, #1b1b1b));
|
|
4
|
+
--am-bg-alt: var(--color-background-secondary, light-dark(#f6f7f9, #242424));
|
|
5
|
+
--am-bg-hover: var(--color-background-tertiary, light-dark(#eef0f3, #2e2e2e));
|
|
6
|
+
--am-text: var(--color-text-primary, light-dark(#1d2025, #ececec));
|
|
7
|
+
--am-text-muted: var(--color-text-secondary, light-dark(#5d6470, #a3a3a3));
|
|
8
|
+
--am-border: var(--color-border-primary, light-dark(#dde1e6, #3a3a3a));
|
|
9
|
+
--am-accent: var(--color-text-info, light-dark(#1f5fbf, #7aaaf0));
|
|
10
|
+
--am-danger: var(--color-text-danger, light-dark(#b42318, #f08a80));
|
|
11
|
+
--am-success: var(--color-text-success, light-dark(#1a7f37, #6fcf8a));
|
|
12
|
+
--am-warning: var(--color-text-warning, light-dark(#9a6700, #e3b341));
|
|
13
|
+
--am-radius: var(--border-radius-md, 8px);
|
|
14
|
+
--am-font: var(--font-sans, system-ui, -apple-system, 'Segoe UI', sans-serif);
|
|
15
|
+
--am-mono: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:root[data-theme='light'] { color-scheme: light; }
|
|
19
|
+
:root[data-theme='dark'] { color-scheme: dark; }
|
|
20
|
+
|
|
21
|
+
* { box-sizing: border-box; }
|
|
22
|
+
|
|
23
|
+
html, body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
background: var(--am-bg);
|
|
26
|
+
color: var(--am-text);
|
|
27
|
+
font: 14px/1.45 var(--am-font);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main { padding: 12px 14px; overflow: auto; }
|
|
31
|
+
|
|
32
|
+
a { color: var(--am-accent); text-decoration: none; cursor: pointer; }
|
|
33
|
+
a:hover { text-decoration: underline; }
|
|
34
|
+
|
|
35
|
+
button {
|
|
36
|
+
font: inherit;
|
|
37
|
+
color: inherit;
|
|
38
|
+
background: var(--am-bg-alt);
|
|
39
|
+
border: 1px solid var(--am-border);
|
|
40
|
+
border-radius: var(--am-radius);
|
|
41
|
+
padding: 4px 10px;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
}
|
|
44
|
+
button:hover:not(:disabled) { background: var(--am-bg-hover); }
|
|
45
|
+
button:disabled { opacity: 0.5; cursor: default; }
|
|
46
|
+
button.am-link { background: none; border: 0; padding: 0; color: var(--am-accent); text-align: left; }
|
|
47
|
+
button.am-link:hover { text-decoration: underline; background: none; }
|
|
48
|
+
|
|
49
|
+
input[type='search'] {
|
|
50
|
+
font: inherit;
|
|
51
|
+
color: inherit;
|
|
52
|
+
background: var(--am-bg);
|
|
53
|
+
border: 1px solid var(--am-border);
|
|
54
|
+
border-radius: var(--am-radius);
|
|
55
|
+
padding: 4px 8px;
|
|
56
|
+
min-width: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.am-muted { color: var(--am-text-muted); }
|
|
60
|
+
.am-error { color: var(--am-danger); white-space: pre-wrap; }
|
|
61
|
+
.am-mono { font-family: var(--am-mono); font-size: 12.5px; }
|
|
62
|
+
|
|
63
|
+
.am-toolbar {
|
|
64
|
+
display: flex;
|
|
65
|
+
flex-wrap: wrap;
|
|
66
|
+
align-items: center;
|
|
67
|
+
gap: 8px;
|
|
68
|
+
margin-bottom: 10px;
|
|
69
|
+
}
|
|
70
|
+
.am-toolbar h1 { font-size: 15px; font-weight: 600; margin: 0; }
|
|
71
|
+
h2 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
|
|
72
|
+
.am-spacer { flex: 1; }
|
|
73
|
+
|
|
74
|
+
.am-badge {
|
|
75
|
+
display: inline-block;
|
|
76
|
+
padding: 0 7px;
|
|
77
|
+
border-radius: 999px;
|
|
78
|
+
font-size: 12px;
|
|
79
|
+
border: 1px solid var(--am-border);
|
|
80
|
+
background: var(--am-bg-alt);
|
|
81
|
+
white-space: nowrap;
|
|
82
|
+
}
|
|
83
|
+
.am-badge.am-true { color: var(--am-success); }
|
|
84
|
+
.am-badge.am-false { color: var(--am-text-muted); }
|
|
85
|
+
|
|
86
|
+
.am-table-wrap { overflow-x: auto; border: 1px solid var(--am-border); border-radius: var(--am-radius); }
|
|
87
|
+
table.am-table { border-collapse: collapse; width: 100%; }
|
|
88
|
+
.am-table th, .am-table td {
|
|
89
|
+
text-align: left;
|
|
90
|
+
vertical-align: top;
|
|
91
|
+
padding: 6px 10px;
|
|
92
|
+
border-bottom: 1px solid var(--am-border);
|
|
93
|
+
max-width: 320px;
|
|
94
|
+
overflow: hidden;
|
|
95
|
+
text-overflow: ellipsis;
|
|
96
|
+
white-space: nowrap;
|
|
97
|
+
}
|
|
98
|
+
.am-table th { background: var(--am-bg-alt); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
|
|
99
|
+
.am-table tr:last-child td { border-bottom: 0; }
|
|
100
|
+
.am-table tbody tr.am-clickable { cursor: pointer; }
|
|
101
|
+
.am-table tbody tr.am-clickable:hover { background: var(--am-bg-hover); }
|
|
102
|
+
|
|
103
|
+
details.am-json summary { cursor: pointer; color: var(--am-text-muted); }
|
|
104
|
+
details.am-json pre {
|
|
105
|
+
margin: 4px 0 0;
|
|
106
|
+
padding: 8px;
|
|
107
|
+
background: var(--am-bg-alt);
|
|
108
|
+
border-radius: var(--am-radius);
|
|
109
|
+
overflow: auto;
|
|
110
|
+
max-height: 280px;
|
|
111
|
+
font: 12px/1.4 var(--am-mono);
|
|
112
|
+
}
|