- Notifications
You must be signed in to change notification settings - Fork1k
feat(site): add support for external agents in the UI and extend CodeExample#19288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a0be6c2
ceec966
1245e0b
f7ac4c0
73049f3
29e2625
044076a
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { chromatic } from "testHelpers/chromatic"; | ||
import { MockWorkspace, MockWorkspaceAgent } from "testHelpers/entities"; | ||
import { withDashboardProvider } from "testHelpers/storybook"; | ||
import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
import { AgentExternal } from "./AgentExternal"; | ||
const meta: Meta<typeof AgentExternal> = { | ||
title: "modules/resources/AgentExternal", | ||
component: AgentExternal, | ||
args: { | ||
agent: { | ||
...MockWorkspaceAgent, | ||
status: "connecting", | ||
operating_system: "linux", | ||
architecture: "amd64", | ||
}, | ||
workspace: MockWorkspace, | ||
}, | ||
decorators: [withDashboardProvider], | ||
parameters: { | ||
chromatic, | ||
}, | ||
}; | ||
export default meta; | ||
type Story = StoryObj<typeof AgentExternal>; | ||
export const Connecting: Story = { | ||
args: { | ||
agent: { | ||
...MockWorkspaceAgent, | ||
status: "connecting", | ||
operating_system: "linux", | ||
architecture: "amd64", | ||
}, | ||
}, | ||
}; | ||
export const Timeout: Story = { | ||
args: { | ||
agent: { | ||
...MockWorkspaceAgent, | ||
status: "timeout", | ||
operating_system: "linux", | ||
architecture: "amd64", | ||
}, | ||
}, | ||
}; | ||
export const DifferentOS: Story = { | ||
args: { | ||
agent: { | ||
...MockWorkspaceAgent, | ||
status: "connecting", | ||
operating_system: "darwin", | ||
architecture: "arm64", | ||
}, | ||
}, | ||
}; | ||
export const NotExternalAgent: Story = { | ||
args: { | ||
agent: { | ||
...MockWorkspaceAgent, | ||
status: "connecting", | ||
operating_system: "linux", | ||
architecture: "amd64", | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { workspaceAgentCredentials } from "api/queries/workspaces"; | ||
import type { Workspace, WorkspaceAgent } from "api/typesGenerated"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { CodeExample } from "components/CodeExample/CodeExample"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import type { FC } from "react"; | ||
import { useQuery } from "react-query"; | ||
interface AgentExternalProps { | ||
agent: WorkspaceAgent; | ||
workspace: Workspace; | ||
} | ||
export const AgentExternal: FC<AgentExternalProps> = ({ agent, workspace }) => { | ||
const { | ||
data: credentials, | ||
error, | ||
isLoading, | ||
isError, | ||
} = useQuery(workspaceAgentCredentials(workspace.id, agent.name)); | ||
if (isLoading) { | ||
return <Loader />; | ||
} | ||
if (isError) { | ||
return <ErrorAlert error={error} />; | ||
} | ||
return ( | ||
<section className="text-base text-muted-foreground pb-2 leading-relaxed"> | ||
<p> | ||
Please run the following command to attach an agent to the{" "} | ||
{workspace.name} workspace: | ||
</p> | ||
<CodeExample | ||
code={credentials?.command ?? ""} | ||
secret={false} | ||
redactPattern={/CODER_AGENT_TOKEN="([^"]+)"/g} | ||
redactReplacement={`CODER_AGENT_TOKEN="********"`} | ||
showRevealButton={true} | ||
/> | ||
</section> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -27,6 +27,7 @@ import AutoSizer from "react-virtualized-auto-sizer"; | ||
import type { FixedSizeList as List, ListOnScrollProps } from "react-window"; | ||
import { AgentApps, organizeAgentApps } from "./AgentApps/AgentApps"; | ||
import { AgentDevcontainerCard } from "./AgentDevcontainerCard"; | ||
import { AgentExternal } from "./AgentExternal"; | ||
import { AgentLatency } from "./AgentLatency"; | ||
import { AGENT_LOG_LINE_HEIGHT } from "./AgentLogs/AgentLogLine"; | ||
import { AgentLogs } from "./AgentLogs/AgentLogs"; | ||
@@ -58,13 +59,14 @@ export const AgentRow: FC<AgentRowProps> = ({ | ||
onUpdateAgent, | ||
initialMetadata, | ||
}) => { | ||
const { browser_only, workspace_external_agent } = useFeatureVisibility(); | ||
const appSections = organizeAgentApps(agent.apps); | ||
const hasAppsToDisplay = | ||
!browser_only || appSections.some((it) => it.apps.length > 0); | ||
const isExternalAgent = workspace.latest_build.has_external_agent; | ||
const shouldDisplayAgentApps = | ||
(agent.status === "connected" && hasAppsToDisplay) || | ||
(agent.status === "connecting" && !isExternalAgent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. why do we only hide them while connecting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. | ||
const hasVSCodeApp = | ||
agent.display_apps.includes("vscode") || | ||
agent.display_apps.includes("vscode_insiders"); | ||
@@ -258,7 +260,7 @@ export const AgentRow: FC<AgentRowProps> = ({ | ||
</section> | ||
)} | ||
{agent.status === "connecting" &&!isExternalAgent &&( | ||
<section css={styles.apps}> | ||
<Skeleton | ||
width={80} | ||
@@ -293,6 +295,12 @@ export const AgentRow: FC<AgentRowProps> = ({ | ||
</section> | ||
)} | ||
{isExternalAgent && | ||
(agent.status === "timeout" || agent.status === "connecting") && | ||
workspace_external_agent && ( | ||
<AgentExternal agent={agent} workspace={workspace} /> | ||
)} | ||
<AgentMetadata initialMetadata={initialMetadata} agent={agent} /> | ||
</div> | ||
Uh oh!
There was an error while loading.Please reload this page.