1{{define "chatActivity"}}<chat-activity id="chat-activity" endpoint="{{.Endpoint}}" room="{{.Room}}" actor="{{.Actor}}" fx-action="{{.Endpoint}}" fx-trigger="tiny:activity-refresh" fx-target="#chat-activity-cards" fx-swap="morph">{{if .Ask}}<details id="chat-ask"><summary>Ask an agent</summary><chat-request room="{{.Room}}" actor="{{.Actor}}"{{with .Root}} root="{{.}}"{{end}}><label>Agent {{if .Agents}}<select name="agent" required>{{range .Agents}}<option value="{{.PubKey}}">{{shortID .PubKey}}{{if .Operator}} ({{shortID .Operator}}'s agent){{else}} (agent){{end}}</option>{{end}}</select>{{else}}<input name="agent" required pattern="[0-9a-f]{64}" maxlength="64" placeholder="agent public key, 64 hex characters" spellcheck="false" autocomplete="off">{{end}}</label><label>Subject <input name="subject" maxlength="200" placeholder="optional"></label><label>Task <textarea name="content" required maxlength="8000" rows="3" placeholder="What should the agent do?"></textarea></label><button type="submit" data-primary>Ask</button></chat-request><noscript><p>Publishing needs JavaScript and a connected signer.</p></noscript></details>{{end}}<div id="chat-activity-cards">{{template "chatActivityCards" .}}</div></chat-activity>{{end}}2{{define "chatActivityResponse"}}<div id="chat-activity-cards">{{template "chatActivityCards" .}}</div>{{end}}3{{define "chatActivityCards"}}{{if .Error}}<p role="status">{{.Error}}</p>{{else}}{{range .Items}}<article id="activity-{{.ID}}" data-activity="{{.Type}}" data-state="{{.State}}" data-event="{{.ID}}">4{{if eq .Type "approval"}}{{if ne .State "open"}}<details data-task="{{.ID}}"><summary><strong>{{.Title}}</strong> <small>{{if .Decision}}{{.Decision}}{{else}}{{.State}}{{end}}</small></summary>{{end}}<header><strong>{{if eq .Interaction "approval"}}Approval request{{else if eq .Interaction "confirmation"}}Confirmation{{else if .Question}}Question{{else}}Approval request{{end}}</strong> <small>{{if .Decision}}{{.Decision}}{{else}}{{.State}}{{end}}</small></header><p>{{.Title}}</p>{{if ne .Title .Content}}<details><summary>Details</summary><p>{{.Content}}</p></details>{{end}}5<p><small>from {{template "nostrName" .Author}}</small> <a href="/approvals/{{.ID}}">Open request</a></p>6{{with .Answer}}<blockquote>{{.}}</blockquote>{{end}}{{if .CanDecide}}<chat-decision event="{{.ID}}" pubkey="{{.Author}}" kind="{{.Kind}}" room="{{.Room}}" actor="{{$.Actor}}" expires="{{.Expires}}" interaction="{{.Interaction}}" selection="{{if .Multiple}}multiple{{else if .Native}}{{if .Options}}single{{else}}text{{end}}{{end}}"{{if .Freeform}} freeform{{end}}{{if .Question}} question{{end}}{{if .Native}} native{{end}}{{if .Multiple}} multiple{{end}}>{{if .Native}}{{$multiple := .Multiple}}{{$freeform := .Freeform}}{{if .Options}}<fieldset><legend>{{if $multiple}}Choose one or more options{{else}}Choose an option{{end}}</legend>{{range .Options}}<label><input type="{{if $multiple}}checkbox{{else}}radio{{end}}" name="option" value="{{.ID}}"> {{.Label}}</label>{{end}}</fieldset>{{end}}{{if $freeform}}<label>{{if .Options}}Add details or write your own answer{{else}}Your answer{{end}} <textarea name="custom-answer" maxlength="8000" rows="2"></textarea></label>{{end}}<button type="submit" data-primary>Submit</button>{{else if .Question}}<label>Your answer <textarea name="content" required maxlength="8000" rows="2"></textarea></label><button type="submit" data-primary>Reply</button>{{else}}<button type="submit" name="reaction" value="+" data-primary>Approve</button><button type="submit" name="reaction" value="-" data-danger>Deny</button>{{end}}</chat-decision><noscript><p>Answering requires JavaScript and a connected signer.</p></noscript>{{end}}{{if ne .State "open"}}</details>{{end}}7{{else}}<details id="activity-details-{{.ID}}" data-task="{{.ID}}"><summary><strong>{{.Title}}</strong> <small data-status="{{.Status}}">{{.Status}}</small></summary><p><small>from {{template "nostrName" .Author}}{{if .Assignees}} for {{range $i, $p := .Assignees}}{{if $i}}, {{end}}{{template "nostrName" $p}}{{end}}{{end}}</small></p>{{if ne .Title .Content}}{{with .Content}}<div>{{chatMarkdown .}}</div>{{end}}{{end}}{{if eq .State "open"}}{{with .Progress}}<p data-progress>{{.}}</p>{{end}}{{end}}{{with .Result}}<h4>Result</h4>{{if .Content}}<div>{{chatMarkdown .Content}}</div>{{end}}{{if .Artifacts}}<ul>{{range .Artifacts}}<li><a href="{{.Href}}">{{.Label}}</a></li>{{end}}</ul>{{end}}<p><a href="/e/{{.ID}}">Open result</a></p>{{end}}{{with .Error}}<h4>Error</h4><p data-error>{{.Content}}</p>{{end}}{{if eq .State "cancelled"}}<p>Cancelled by the requester.</p>{{end}}<p><a href="/e/{{.ID}}">Open task</a></p>{{if .CanCancel}}<chat-cancel event="{{.ID}}" room="{{.Room}}" actor="{{$.Actor}}" assignees="{{range $i, $p := .Assignees}}{{if $i}} {{end}}{{$p}}{{end}}"><button type="submit" data-danger>Cancel task</button></chat-cancel>{{end}}</details>{{end}}8</article>{{end}}{{end}}{{end}}