({
parentAgent,
subAgents,
devcontainer,
workspace,
template,
wildcardHostname,
})
| 58 | }; |
| 59 | |
| 60 | export const AgentDevcontainerCard: FC<AgentDevcontainerCardProps> = ({ |
| 61 | parentAgent, |
| 62 | subAgents, |
| 63 | devcontainer, |
| 64 | workspace, |
| 65 | template, |
| 66 | wildcardHostname, |
| 67 | }) => { |
| 68 | const { browser_only } = useFeatureVisibility(); |
| 69 | const { proxy } = useProxy(); |
| 70 | const queryClient = useQueryClient(); |
| 71 | |
| 72 | // The sub agent comes from the workspace response whereas the devcontainer |
| 73 | // comes from the agent containers endpoint. We need alignment between the |
| 74 | // two, so if the sub agent is not present or the IDs do not match, we |
| 75 | // assume it has been removed. |
| 76 | const subAgent = subAgents.find((sub) => sub.id === devcontainer.agent?.id); |
| 77 | |
| 78 | const appSections = (subAgent && organizeAgentApps(subAgent.apps)) || []; |
| 79 | const displayApps = |
| 80 | subAgent?.display_apps.filter((app) => { |
| 81 | if (browser_only) { |
| 82 | return ["web_terminal", "port_forwarding_helper"].includes(app); |
| 83 | } |
| 84 | return true; |
| 85 | }) || []; |
| 86 | const showVSCode = |
| 87 | devcontainer.container && |
| 88 | (displayApps.includes("vscode") || displayApps.includes("vscode_insiders")); |
| 89 | const hasAppsToDisplay = |
| 90 | displayApps.includes("web_terminal") || |
| 91 | showVSCode || |
| 92 | appSections.some((it) => it.apps.length > 0); |
| 93 | |
| 94 | const queryKey = workspaceAgentContainersKey(parentAgent.id); |
| 95 | |
| 96 | const deleteDevcontainerMutation = useMutation({ |
| 97 | ...deleteWorkspaceAgentDevcontainer(parentAgent, devcontainer, queryClient), |
| 98 | }); |
| 99 | |
| 100 | const rebuildDevcontainerMutation = useMutation({ |
| 101 | mutationFn: async () => { |
| 102 | await API.recreateDevContainer({ |
| 103 | parentAgentId: parentAgent.id, |
| 104 | devcontainerId: devcontainer.id, |
| 105 | }); |
| 106 | }, |
| 107 | onMutate: async () => { |
| 108 | await queryClient.cancelQueries({ queryKey }); |
| 109 | |
| 110 | // Snapshot the previous data for rollback in case of error. |
| 111 | const previousData = queryClient.getQueryData(queryKey); |
| 112 | |
| 113 | // Optimistically update the devcontainer status to |
| 114 | // "starting" and zero the agent and container to mimic what |
| 115 | // the API does. |
| 116 | queryClient.setQueryData( |
| 117 | queryKey, |
nothing calls this directly
no test coverage detected