fix(ui): load task debug reliably and copy JSON output
This commit is contained in:
1 parent
fe30a02072
commit
70322bd5fb
3 files changed
+37
-22
No files matched your search
@@ -4,17 +4,38 @@
|
||||
* and the debug view), and both must show exactly what the daemon stored --
|
||||
* no projection, no prettifying beyond indentation.
|
||||
*/
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { Check, Copy } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import HighlightedJson from "@/base/HighlightedJson.vue";
|
||||
|
||||
defineProps<{ value: unknown }>();
|
||||
const props = defineProps<{ value: unknown }>();
|
||||
const text = computed(() => JSON.stringify(props.value ?? {}, null, 2));
|
||||
const copied = ref(false);
|
||||
const copyError = ref(false);
|
||||
watch(text, () => { copied.value = false; copyError.value = false; });
|
||||
async function copy(): Promise<void> {
|
||||
copyError.value = false;
|
||||
try {
|
||||
await navigator.clipboard.writeText(text.value);
|
||||
copied.value = true;
|
||||
} catch {
|
||||
copied.value = false;
|
||||
copyError.value = true;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mb-2 flex items-center justify-end gap-2">
|
||||
<p v-if="copyError" role="alert" class="text-xs text-danger">Could not copy output.</p>
|
||||
<Button type="button" variant="outline" size="sm" @click="copy"><Check v-if="copied" /><Copy v-else />{{ copied ? "Copied" : "Copy output" }}</Button>
|
||||
</div>
|
||||
<!--
|
||||
pre-wrap keeps the indentation the JSON is printed with while letting a
|
||||
long value wrap instead of forcing the panel to scroll sideways.
|
||||
-->
|
||||
<pre
|
||||
class="max-h-[60vh] overflow-auto rounded-sm border border-border bg-muted p-3 font-mono text-xs leading-normal whitespace-pre-wrap break-words"
|
||||
><HighlightedJson :text="JSON.stringify(value ?? {}, null, 2)" /></pre>
|
||||
><HighlightedJson :text="text" /></pre>
|
||||
</template>
|
||||
@@ -110,7 +110,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
const retryBusy = ref(false);
|
||||
const retryError = ref<RetryError | null>(null);
|
||||
const refreshToken = ref(0);
|
||||
const started = new Set<string>();
|
||||
|
||||
const task = computed<TaskRecord | null>(() =>
|
||||
Array.isArray(taskList.value)
|
||||
@@ -171,16 +170,13 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
cache: Ref<Cache<T>>,
|
||||
{ force = false }: { force?: boolean } = {},
|
||||
): void {
|
||||
if (started.has(cacheKey) && !force) return;
|
||||
started.add(cacheKey);
|
||||
if (cache.value.has(cacheKey) && cache.value.get(cacheKey) !== null && !force) return;
|
||||
cache.value = new Map(cache.value).set(cacheKey, undefined);
|
||||
// A read that never settles would pin the panel's loading line forever:
|
||||
// after a quiet minute the read is declared broken so the retry button
|
||||
// can appear. A late response after the timeout is discarded by the race.
|
||||
let timedOut = false;
|
||||
const timeout = new Promise<never>((_, reject) => {
|
||||
setTimeout(() => {
|
||||
timedOut = true;
|
||||
reject(new Error("read timed out"));
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -189,7 +185,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
cache.value = new Map(cache.value).set(cacheKey, res);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!timedOut) started.delete(cacheKey);
|
||||
cache.value = new Map(cache.value).set(cacheKey, null);
|
||||
});
|
||||
}
|
||||
@@ -275,7 +270,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
/** Drop every cache so a manual refresh cannot show a stale capture or log
|
||||
* beside fresh attempt history. */
|
||||
function dropCaches(): void {
|
||||
started.clear();
|
||||
logs.value = new Map();
|
||||
changes.value = new Map();
|
||||
debug.value = new Map();
|
||||
@@ -342,7 +336,7 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
if (tab.value === "log") loadLogs(attempt);
|
||||
else if (tab.value === "changes") loadChanges(attempt);
|
||||
else if (tab.value === "debug") loadDebug(attempt);
|
||||
});
|
||||
}, { immediate: true });
|
||||
|
||||
watch([tab, attemptNumber], () => {
|
||||
if (id.value == null) return;
|
||||
|
||||
Reference in new issue
Block a user