panel-fixture.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { createStore } from "solid-js/store"
  2. import { PaasRunPanel } from "../../src/pages/paas/run-panel"
  3. import type { PaasPlatform } from "../../src/paas"
  4. // Deliberately delayed snapshots exercise stale-response handling, not model quality.
  5. export function PanelFixture() {
  6. const [state, setState] = createStore({ runID: "run_1" })
  7. const runs: Record<string, Record<string, unknown>> = {
  8. run_1: {
  9. run_id: "run_1",
  10. agent_id: "research",
  11. status: "running",
  12. output: "第一项任务",
  13. usage: { duration_ms: 5000, cost_usd: 0.0012 },
  14. },
  15. run_2: { run_id: "run_2", agent_id: "research", status: "completed", output: "第二项任务" },
  16. }
  17. const control = {
  18. holdNext: false,
  19. held: false,
  20. failPause: false,
  21. failRead: false,
  22. readError: "HTTP 503",
  23. failFiles: false,
  24. files: [] as { name: string; path: string }[],
  25. cancelDownload: false,
  26. release: () => {},
  27. switchRun: () => setState("runID", "run_2"),
  28. update: (value: Record<string, unknown>) => {
  29. runs[state.runID] = { ...value, run_id: state.runID, agent_id: "research" }
  30. },
  31. }
  32. Object.assign(window, { paasPanelTest: control })
  33. const api: PaasPlatform = {
  34. connect: async () => ({ url: "https://example.test" }),
  35. disconnect: async () => {},
  36. request: async (request) => {
  37. if (request.action === "run") {
  38. if (control.failRead) throw new Error(control.readError)
  39. const snapshot = structuredClone(runs[request.runID])
  40. if (control.holdNext) {
  41. control.holdNext = false
  42. control.held = true
  43. await new Promise<void>((resolve) => {
  44. control.release = resolve
  45. })
  46. control.held = false
  47. }
  48. return snapshot
  49. }
  50. if (request.action === "run-files") {
  51. if (control.failFiles) throw new Error("HTTP 503:文件服务暂时不可用")
  52. return { files: control.files }
  53. }
  54. if (request.action === "run-events")
  55. return {
  56. run_id: request.runID,
  57. stages: [
  58. {
  59. stage_id: "collect",
  60. status: "completed",
  61. details: { round: 1 },
  62. started_at: "2026-11-30T10:00:00Z",
  63. completed_at: "2026-11-30T10:00:05Z",
  64. },
  65. ],
  66. events: [
  67. {
  68. sequence: 1,
  69. event_type: "tool_call",
  70. stage_id: "collect",
  71. data: { tool: "Bash", content: "pwd" },
  72. created_at: "2026-11-30T10:00:01Z",
  73. },
  74. ],
  75. }
  76. if (request.action === "download") return { saved: !control.cancelDownload }
  77. if (request.action === "pause") {
  78. if (control.failPause) throw new Error("暂时无法暂停,请稍后再试。")
  79. runs[request.runID] = { ...runs[request.runID], status: "paused", checkpoint_id: "checkpoint_1" }
  80. return runs[request.runID]
  81. }
  82. return {}
  83. },
  84. }
  85. return <PaasRunPanel api={api} agentID="research" runID={state.runID} />
  86. }