返回 DeepSeek-Reasonix
tool-recovery-fixture.tsx
根目录 / desktop / frontend / bench / tool-recovery-fixture.tsx
1 import React from "react";
2 import { createRoot } from "react-dom/client";
3 import { ToolRecoveryPanel } from "../src/components/ToolRecoveryPanel";
4 import { LocaleProvider } from "../src/lib/i18n";
5 import type { ToolRecoveryBindings, ToolRecoverySnapshot } from "../src/lib/toolRecovery";
6 import "../src/styles.css";
7
8 const initial: ToolRecoverySnapshot = {
9 sessionPath: "fixture", runtimeEpoch: "epoch", revision: "one", retryEnabled: true,
10 calls: [{ identity: { attempt_id: "attempt", canonical_tool: "write_file", resource_scope: "fixture.txt", argument_digest: "digest" }, state: "unknown", read_only: false }],
11 };
12 let view = structuredClone(initial);
13 const actions: string[] = [];
14 let release: ((view: ToolRecoverySnapshot) => void) | undefined;
15 const bindings: ToolRecoveryBindings = {
16 async GetToolRecoveryForTab(tab) { return tab === "new-tab" ? { ...initial, calls: [] } : structuredClone(view); },
17 async ResolveToolRecoveryForTab(_, req) {
18 actions.push(req.action);
19 if (req.action === "inspect") {
20 if ((window as any).holdRecovery) return new Promise(resolve => { release = resolve; });
21 view = { ...view, revision: "two", calls: view.calls.map(c => ({ ...c, inspection_id: "proof", inspection_state: "unknown", arguments: { path: "fixture.txt", content: "local receipt" } })) };
22 } else if (req.action === "confirm") view = { ...view, revision: "three", calls: [] };
23 else if (req.action === "reject") view = { ...view, revision: "three", calls: view.calls.map(c => ({ ...c, resolution: "reject" })) };
24 return structuredClone(view);
25 },
26 };
27 const root = createRoot(document.getElementById("root")!);
28 function render(tab = "fixture-tab") {
29 root.render(<LocaleProvider><main className="transcript-shell" style={{ maxWidth: 720, margin: 32, height: 600 }}><div className="transcript"><p>Existing transcript</p></div><ToolRecoveryPanel tabId={tab} sessionKey={tab} running={false} refreshKey={1} bindings={bindings} onResume={() => actions.push("resume")} /></main></LocaleProvider>);
30 }
31 Object.assign(window, { recoveryFixture: { actions, render, reset() { view = structuredClone(initial); render(); }, release() { release?.({ ...initial, calls: initial.calls.map(c => ({ ...c, identity: { ...c.identity, canonical_tool: "STALE_RESULT" } })) }); } } });
32 render();
33
33 lines Plain Text