Files
supermarket/internal/web/templates/agent.html
T
davidandClaude Opus 5.5 311d2e815b Phase 11, part 3: approvals for what agents send out
Agents can now ask to publish or schedule a post, send an email, add
someone to a mailing list, or apply an SEO change. Each waits on the
Approvals page (with a count in the sidebar) for an admin or a member with
edit on its module, who can edit it first, approve or refuse it, and let
the agent take that class of action on its own with a cap per day. A
rotation after a leak revokes the old keys and withdraws everything
allowed. All of it is in the audit log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 10:54:53 -07:00

64 lines
4.8 KiB
HTML

{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$d := .}}{{$a := .Row}}
<p><a href="/settings/agents">← Agents</a></p>
<h2>{{$a.Name}}{{if $a.BuiltIn}} <span class="pill">built in</span>{{end}}{{if eq $a.Status "disabled"}} <span class="pill">turned off</span>{{end}}</h2>
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
<form class="card" method="post" action="/settings/agents/{{$a.ID}}/save">
<label>Name <input name="name" value="{{$a.Name}}" required></label>
<label>What it's for <textarea name="description" rows="2">{{$a.Description}}</textarea></label>
{{template "agent-scopes" (dict "Scopes" $a.Modules "Grants" .Grants)}}
<button type="submit">Save</button>
</form>
<section class="card" id="keys">
<h2>Keys</h2>
<table class="list">
<thead><tr><th>Key</th><th>Made</th><th>Expires</th><th>Last used</th><th></th></tr></thead>
<tbody>
{{range $a.Keys}}<tr>
<td><code>{{.Prefix}}…</code>
{{if not .Revoked.IsZero}} <span class="pill">revoked {{ago .Revoked}}</span>
{{else if not (.Working $d.Now)}} <span class="pill">stopped</span>
{{else if not .Retires.IsZero}} <span class="pill warn">replaced: works until {{.Retires.Local.Format "2 Jan 15:04"}}</span>
{{else}} <span class="pill ok">working</span>{{end}}</td>
<td>{{.Created.Local.Format "2 Jan 2006"}}</td>
<td>{{if .Expires.IsZero}}<span class="muted">never</span>{{else}}{{.Expires.Local.Format "2 Jan 2006"}}{{end}}</td>
<td>{{if .Used.IsZero}}<span class="muted">never</span>{{else}}{{ago .Used}}{{with .UsedFrom}} <span class="muted small">from {{.}}</span>{{end}}{{end}}</td>
<td>{{if .Working $d.Now}}<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/revoke" data-confirm="Revoke this key? Whatever uses it stops at once."><input type="hidden" name="key" value="{{.ID}}"><button type="submit" class="secondary small danger">Revoke</button></form>{{end}}</td>
</tr>{{else}}<tr><td colspan="5" class="muted">No keys.</td></tr>{{end}}
</tbody>
</table>
<div class="actions">
<form class="inline row" method="post" action="/settings/agents/{{$a.ID}}/rotate"><button type="submit" class="secondary">Rotate the key</button>
<label class="check small"><input type="checkbox" name="leaked"> It leaked: stop the old keys now, and withdraw what it may do on its own</label></form>
<form class="inline row" method="post" action="/settings/agents/{{$a.ID}}/new-key"><label class="small">Expires <input type="date" name="expires"></label><button type="submit" class="secondary">Add a key</button></form>
</div>
<p class="help"><strong>Rotate</strong> makes a new key; the old one keeps working for a day, so whatever uses it can be switched over. After a leak, <strong>revoke</strong> it instead: it stops at once.</p>
</section>
<section class="card" id="allowed">
<h2>On its own</h2>
{{if .Allowed}}
<p class="help">What {{$a.Name}} may do without asking, approved on the Approvals page. Everything else it asks for waits there for a person.</p>
<table class="list"><tbody>{{range .Allowed}}<tr>
<td>{{.Label}}</td><td>{{if .DailyCap}}up to {{.DailyCap}} a day{{else}}no cap{{end}}</td><td>{{ago .Granted}}{{with by .GrantedBy}} {{.}}{{end}}</td>
<td><form class="inline" method="post" action="/approvals/allowed/withdraw"><input type="hidden" name="agent" value="{{.Agent}}"><input type="hidden" name="class" value="{{.Class}}"><button type="submit" class="secondary small">Withdraw</button></form></td>
</tr>{{end}}</tbody></table>
{{else}}<p class="help">Nothing: everything it asks to send out (posts, emails, mailing-list adds, changes to the sites) waits on <a href="/approvals">Approvals</a> for a person.</p>{{end}}
{{if .Asked}}<h3>Lately</h3>
<ul class="small">{{range .Asked}}<li>{{.Summary}}: {{if eq .Status "waiting"}}waiting{{else if eq .Status "refused"}}refused{{else if eq .Status "failed"}}failed{{else if .OnItsOwn}}done on its own{{else}}approved{{end}}, {{ago .Created}}</li>{{end}}</ul>{{end}}
</section>
<section class="card">
<div class="actions">
{{if eq $a.Status "disabled"}}
<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/enable"><button type="submit" class="secondary">Turn it back on</button></form>
{{else}}
<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/disable"><button type="submit" class="secondary danger">Turn it off</button></form>
{{end}}
{{if not $a.BuiltIn}}<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/remove" data-confirm="Remove {{$a.Name}} and its keys for good?"><button type="submit" class="danger">Remove</button></form>{{end}}
</div>
<p class="help">Turned off, none of its keys work, until it's turned back on.</p>
</section>
{{end}}{{template "settings-end"}}{{end}}