|
| 1 | +import * as React from "react"; |
| 2 | +import { MuxPreviewShell } from "../preview-harness"; |
| 3 | +import { HeartbeatToolCall } from "@/browser/features/Tools/HeartbeatToolCall"; |
| 4 | + |
| 5 | +// Isolated previews of the heartbeat tool-call card — one cell per story in |
| 6 | +// HeartbeatToolCall.stories.tsx, named to match the story exports so compare pairs them, |
| 7 | +// rendered with the same inline args/result/status. Hand-authored (not generated) because |
| 8 | +// the stories import meta.tsx → the whole app graph, which is over the bundle cap (see |
| 9 | +// .design-sync/NOTES.md "UI primitives / previews"). |
| 10 | + |
| 11 | +const TASK_PROMPT = |
| 12 | + "Check the CI run for the auth refactor. If it's green, open the PR; if it's red, " + |
| 13 | + "summarize the first failure and stop."; |
| 14 | +const DEFAULT_BODY = |
| 15 | + "Check in on the current state of this workspace — review any pending work, check for stale " + |
| 16 | + "context, and determine if any action is needed. If everything looks good, briefly confirm the " + |
| 17 | + "workspace status."; |
| 18 | + |
| 19 | +// Mirrors the stories' decorator chain (theme + tooltip provider, dark background, max-w-2xl). |
| 20 | +// `width` reproduces a story-level narrow wrapper (CustomMessageWrapping renders at 375px). |
| 21 | +const Shell = (props: { width?: string; children: React.ReactNode }) => ( |
| 22 | + <MuxPreviewShell> |
| 23 | + <div className="bg-background p-6"> |
| 24 | + <div className="w-full max-w-2xl"> |
| 25 | + {props.width ? <div style={{ width: props.width }}>{props.children}</div> : props.children} |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + </MuxPreviewShell> |
| 29 | +); |
| 30 | + |
| 31 | +export const ScheduledEnabled = () => ( |
| 32 | + <Shell> |
| 33 | + <HeartbeatToolCall |
| 34 | + args={{ |
| 35 | + action: "set", |
| 36 | + enabled: true, |
| 37 | + intervalMs: 30 * 60_000, |
| 38 | + contextMode: "normal", |
| 39 | + message: TASK_PROMPT, |
| 40 | + }} |
| 41 | + status="completed" |
| 42 | + defaultExpanded |
| 43 | + result={{ |
| 44 | + success: true, |
| 45 | + action: "set", |
| 46 | + configured: true, |
| 47 | + settings: { |
| 48 | + enabled: true, |
| 49 | + intervalMs: 30 * 60_000, |
| 50 | + contextMode: "normal", |
| 51 | + message: TASK_PROMPT, |
| 52 | + }, |
| 53 | + summary: "Heartbeat is enabled for this workspace at 30 minutes.", |
| 54 | + }} |
| 55 | + /> |
| 56 | + </Shell> |
| 57 | +); |
| 58 | + |
| 59 | +export const CustomMessageWrapping = () => ( |
| 60 | + <Shell width="375px"> |
| 61 | + <HeartbeatToolCall |
| 62 | + args={{ action: "set", enabled: true, intervalMs: 1_800_000 }} |
| 63 | + status="completed" |
| 64 | + defaultExpanded |
| 65 | + result={{ |
| 66 | + success: true, |
| 67 | + action: "set", |
| 68 | + configured: true, |
| 69 | + settings: { |
| 70 | + enabled: true, |
| 71 | + intervalMs: 1_800_000, |
| 72 | + contextMode: "normal", |
| 73 | + message: |
| 74 | + "Poll the deploy and report status.\n" + |
| 75 | + "Logs: https://ci.example.com/runs/0123456789abcdef0123456789abcdef/jobs/deploy-prod-us-east-1/raw?download=true\n" + |
| 76 | + "If it failed, summarize the first error and stop.", |
| 77 | + }, |
| 78 | + summary: "Heartbeat is enabled for this workspace at 30 minutes.", |
| 79 | + }} |
| 80 | + /> |
| 81 | + </Shell> |
| 82 | +); |
| 83 | + |
| 84 | +export const LongCadenceCompact = () => ( |
| 85 | + <Shell> |
| 86 | + <HeartbeatToolCall |
| 87 | + args={{ action: "set", enabled: true, intervalMs: 2 * 3_600_000, contextMode: "compact" }} |
| 88 | + status="completed" |
| 89 | + defaultExpanded |
| 90 | + result={{ |
| 91 | + success: true, |
| 92 | + action: "set", |
| 93 | + configured: true, |
| 94 | + settings: { enabled: true, intervalMs: 2 * 3_600_000, contextMode: "compact" }, |
| 95 | + summary: "Heartbeat is enabled for this workspace at 2 hours.", |
| 96 | + }} |
| 97 | + /> |
| 98 | + </Shell> |
| 99 | +); |
| 100 | + |
| 101 | +export const ReadReset = () => ( |
| 102 | + <Shell> |
| 103 | + <HeartbeatToolCall |
| 104 | + args={{ action: "get" }} |
| 105 | + status="completed" |
| 106 | + defaultExpanded |
| 107 | + result={{ |
| 108 | + success: true, |
| 109 | + action: "get", |
| 110 | + configured: true, |
| 111 | + settings: { |
| 112 | + enabled: true, |
| 113 | + intervalMs: 3_600_000, |
| 114 | + contextMode: "reset", |
| 115 | + message: DEFAULT_BODY, |
| 116 | + }, |
| 117 | + summary: "Heartbeat is enabled for this workspace at 1 hour.", |
| 118 | + }} |
| 119 | + /> |
| 120 | + </Shell> |
| 121 | +); |
| 122 | + |
| 123 | +export const Paused = () => ( |
| 124 | + <Shell> |
| 125 | + <HeartbeatToolCall |
| 126 | + args={{ action: "set", enabled: false }} |
| 127 | + status="completed" |
| 128 | + defaultExpanded |
| 129 | + result={{ |
| 130 | + success: true, |
| 131 | + action: "set", |
| 132 | + configured: true, |
| 133 | + settings: { |
| 134 | + enabled: false, |
| 135 | + intervalMs: 30 * 60_000, |
| 136 | + contextMode: "normal", |
| 137 | + message: DEFAULT_BODY, |
| 138 | + }, |
| 139 | + summary: "Heartbeat is disabled for this workspace at 30 minutes.", |
| 140 | + }} |
| 141 | + /> |
| 142 | + </Shell> |
| 143 | +); |
| 144 | + |
| 145 | +export const ReadNotConfigured = () => ( |
| 146 | + <Shell> |
| 147 | + <HeartbeatToolCall |
| 148 | + args={{ action: "get" }} |
| 149 | + status="completed" |
| 150 | + defaultExpanded |
| 151 | + result={{ |
| 152 | + success: true, |
| 153 | + action: "get", |
| 154 | + configured: false, |
| 155 | + settings: null, |
| 156 | + summary: "No heartbeat settings are configured for this workspace.", |
| 157 | + }} |
| 158 | + /> |
| 159 | + </Shell> |
| 160 | +); |
| 161 | + |
| 162 | +export const Cleared = () => ( |
| 163 | + <Shell> |
| 164 | + <HeartbeatToolCall |
| 165 | + args={{ action: "unset" }} |
| 166 | + status="completed" |
| 167 | + defaultExpanded |
| 168 | + result={{ |
| 169 | + success: true, |
| 170 | + action: "unset", |
| 171 | + configured: false, |
| 172 | + settings: null, |
| 173 | + summary: "Heartbeat settings removed for this workspace.", |
| 174 | + }} |
| 175 | + /> |
| 176 | + </Shell> |
| 177 | +); |
| 178 | + |
| 179 | +export const Executing = () => ( |
| 180 | + <Shell> |
| 181 | + <HeartbeatToolCall |
| 182 | + args={{ action: "set", enabled: true, intervalMs: 30 * 60_000 }} |
| 183 | + status="executing" |
| 184 | + defaultExpanded |
| 185 | + /> |
| 186 | + </Shell> |
| 187 | +); |
| 188 | + |
| 189 | +export const ErrorResult = () => ( |
| 190 | + <Shell> |
| 191 | + <HeartbeatToolCall |
| 192 | + args={{ action: "set", enabled: true, intervalMs: 30 * 60_000 }} |
| 193 | + status="failed" |
| 194 | + defaultExpanded |
| 195 | + result={{ |
| 196 | + success: false, |
| 197 | + error: "Failed to update heartbeat settings: workspace configuration is unavailable.", |
| 198 | + }} |
| 199 | + /> |
| 200 | + </Shell> |
| 201 | +); |
| 202 | + |
| 203 | +export const Interrupted = () => ( |
| 204 | + <Shell> |
| 205 | + <HeartbeatToolCall |
| 206 | + args={{ |
| 207 | + action: "set", |
| 208 | + enabled: true, |
| 209 | + intervalMs: 2 * 3_600_000, |
| 210 | + contextMode: "compact", |
| 211 | + message: "Watch the long-running migration and report when it finishes.", |
| 212 | + }} |
| 213 | + status="interrupted" |
| 214 | + defaultExpanded |
| 215 | + /> |
| 216 | + </Shell> |
| 217 | +); |
0 commit comments