Skip to content

Commit a2e6b67

Browse files
committed
Improve reported conversation view.
Signed-off-by: Katharine Berry <[email protected]>
1 parent 79e61a3 commit a2e6b67

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

service/assistant/feedback/report.html

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@
3131
}
3232
pre {
3333
margin: 0;
34+
white-space: pre-wrap;
3435
}
3536
.widget {
3637
font-family: monospace;
3738
}
39+
.response-text {
40+
white-space: pre-wrap;
41+
}
42+
summary {
43+
font-weight: bold;
44+
font-size: large;
45+
cursor: pointer;
46+
}
3847
</style>
3948
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
4049
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
4150
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/lua.min.js"></script>
51+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/json.min.js"></script>
4252
</head>
4353
<body>
4454
<h1>Reported thread</h1>
@@ -52,16 +62,16 @@ <h1>Reported thread</h1>
5262
<div class="context-storage">
5363
<h2>Context Storage</h2>
5464
{{if .ContextStorage.POIs}}
55-
<h3>POIs</h3>
56-
<ol>
57-
{{range .ContextStorage.POIs}}
58-
<li><code>{{.}}</code></li>
59-
{{end}}
60-
</ol>
65+
<details>
66+
<summary>POIs</summary>
67+
<pre>{{jsonify .ContextStorage.POIs}}</pre>
68+
</details>
6169
{{end}}
6270
{{if .ContextStorage.LastRoute}}
63-
<h3>Last Route</h3>
64-
<p><code>{{.ContextStorage.LastRoute}}</code></p>
71+
<details>
72+
<summary>Last Route</summary>
73+
<pre>{{jsonify .ContextStorage.LastRoute}}</pre>
74+
</details>
6575
{{end}}
6676
</div>
6777
{{end}}
@@ -101,21 +111,7 @@ <h3>Last Route</h3>
101111
{{else if .FunctionResponse}}
102112
<div class="turn function">
103113
<p class="speaker">Function: <code>{{.FunctionResponse.Name}}</code></p>
104-
<div class="function_args">
105-
<table>
106-
<tr>
107-
<th>Key</th>
108-
<th>Value</th>
109-
</tr>
110-
{{$fn:=.FunctionResponse.Name}}
111-
{{range $key, $value := .FunctionResponse.Response}}
112-
<tr>
113-
<td><code>{{$key}}</code></td>
114-
<td><pre class="arg-{{$fn}}-{{$key}}">{{$value}}</pre></td>
115-
</tr>
116-
{{end}}
117-
</table>
118-
</div>
114+
<pre class="language-json">{{jsonify .FunctionResponse.Response}}</pre></td>
119115
</div>
120116
{{end}}
121117
{{end}}
@@ -131,6 +127,14 @@ <h3>Last Route</h3>
131127
for (let code of luaCode) {
132128
hljs.highlightElement(code);
133129
}
130+
let nonLuaCode = document.querySelectorAll('.turn.function pre');
131+
for (let code of nonLuaCode) {
132+
hljs.highlightElement(code);
133+
}
134+
var storedContext = document.querySelectorAll('.context-storage pre');
135+
for (let code of storedContext) {
136+
hljs.highlightElement(code);
137+
}
134138
</script>
135139
</body>
136140
</html>

service/assistant/feedback/show_report.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package feedback
1616

1717
import (
1818
_ "embed"
19+
"encoding/json"
1920
"github.com/pebble-dev/bobby-assistant/service/assistant/util/storage"
2021
"html/template"
2122
"log"
@@ -25,7 +26,16 @@ import (
2526

2627
//go:embed report.html
2728
var reportTemplateString string
28-
var reportTemplate = template.Must(template.New("report").Parse(reportTemplateString))
29+
var funcMap = template.FuncMap{"jsonify": jsonify}
30+
var reportTemplate = template.Must(template.New("report").Funcs(funcMap).Parse(reportTemplateString))
31+
32+
func jsonify(v interface{}) interface{} {
33+
b, err := json.MarshalIndent(v, "", " ")
34+
if err != nil {
35+
return v
36+
}
37+
return string(b)
38+
}
2939

3040
func HandleShowReport(rw http.ResponseWriter, r *http.Request) {
3141
ctx := r.Context()
@@ -40,5 +50,9 @@ func HandleShowReport(rw http.ResponseWriter, r *http.Request) {
4050
return
4151
}
4252

43-
reportTemplate.ExecuteTemplate(rw, "report", reportedThread)
53+
if err := reportTemplate.ExecuteTemplate(rw, "report", reportedThread); err != nil {
54+
log.Printf("Error executing template: %v", err)
55+
http.Error(rw, err.Error(), http.StatusInternalServerError)
56+
return
57+
}
4458
}

0 commit comments

Comments
 (0)