@@ -25,7 +25,10 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"
25
25
import { darcula } from "react-syntax-highlighter/dist/cjs/styles/prism"
26
26
import AutoSizer from "react-virtualized-auto-sizer"
27
27
import { FixedSizeList as List , ListOnScrollProps } from "react-window"
28
- import { workspaceAgentLogsMachine } from "xServices/workspaceAgentLogs/workspaceAgentLogsXService"
28
+ import {
29
+ LineWithID ,
30
+ workspaceAgentLogsMachine ,
31
+ } from "xServices/workspaceAgentLogs/workspaceAgentLogsXService"
29
32
import { Workspace , WorkspaceAgent } from "../../api/typesGenerated"
30
33
import { AppLink } from "../AppLink/AppLink"
31
34
import { SSHButton } from "../SSHButton/SSHButton"
@@ -44,6 +47,8 @@ export interface AgentRowProps {
44
47
hideVSCodeDesktopButton ?: boolean
45
48
serverVersion : string
46
49
onUpdateAgent : ( ) => void
50
+
51
+ storybookStartupLogs ?: LineWithID [ ]
47
52
}
48
53
49
54
export const AgentRow : FC < AgentRowProps > = ( {
@@ -55,15 +60,28 @@ export const AgentRow: FC<AgentRowProps> = ({
55
60
hideVSCodeDesktopButton,
56
61
serverVersion,
57
62
onUpdateAgent,
63
+ storybookStartupLogs,
58
64
} ) => {
59
65
const styles = useStyles ( )
60
66
const { t } = useTranslation ( "agent" )
67
+
61
68
const [ logsMachine , sendLogsEvent ] = useMachine ( workspaceAgentLogsMachine , {
62
69
context : { agentID : agent . id } ,
70
+ services : process . env . STORYBOOK
71
+ ? {
72
+ getStartupLogs : async ( ) => {
73
+ return storybookStartupLogs || [ ]
74
+ } ,
75
+ streamStartupLogs : ( ) => async ( ) => {
76
+ // noop
77
+ } ,
78
+ }
79
+ : undefined ,
63
80
} )
64
81
const theme = useTheme ( )
65
82
const startupScriptAnchorRef = useRef < HTMLLinkElement > ( null )
66
83
const [ startupScriptOpen , setStartupScriptOpen ] = useState ( false )
84
+
67
85
const hasStartupFeatures =
68
86
Boolean ( agent . startup_script ) ||
69
87
Boolean ( logsMachine . context . startupLogs ?. length )
@@ -73,6 +91,14 @@ export const AgentRow: FC<AgentRowProps> = ({
73
91
useEffect ( ( ) => {
74
92
setShowStartupLogs ( agent . lifecycle_state !== "ready" && hasStartupFeatures )
75
93
} , [ agent . lifecycle_state , hasStartupFeatures ] )
94
+ // External applications can provide startup logs for an agent during it's spawn.
95
+ // These could be Kubernetes logs, or other logs that are useful to the user.
96
+ // For this reason, we want to fetch these logs when the agent is starting.
97
+ useEffect ( ( ) => {
98
+ if ( agent . lifecycle_state === "starting" ) {
99
+ sendLogsEvent ( "FETCH_STARTUP_LOGS" )
100
+ }
101
+ } , [ sendLogsEvent , agent . lifecycle_state ] )
76
102
useEffect ( ( ) => {
77
103
// We only want to fetch logs when they are actually shown,
78
104
// otherwise we can make a lot of requests that aren't necessary.
0 commit comments