Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/x/chatd/turn_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ func (p *Server) appendRootChatTools(
p.publishChatPubsubEvent(updatedChat, codersdk.ChatWatchEventKindStatusChange, nil)
}

if p.previewAppHostname != "" {
if p.previewAppHostname != "" && p.experiments.Enabled(codersdk.ExperimentOpenPreview) {
tools = append(tools, chattool.OpenPreview(chattool.OpenPreviewOptions{
AppHostname: p.previewAppHostname,
GetPreviewWorkspace: opts.workspaceCtx.getPreviewWorkspace,
Expand Down
25 changes: 23 additions & 2 deletions coderd/x/chatd/turn_environment_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,15 +855,23 @@ func TestBuildTurnEnvironmentToolPolicy(t *testing.T) {

server := newInternalTestServer(t, db, ps, chatprovider.ProviderAPIKeys{},
withInternalTestServerTransportFactory(&aibridgeTestFactory{}),
withInternalTestServerExperiments(codersdk.Experiments{codersdk.ExperimentChatInlineMCPServers, codersdk.ExperimentChatACPSubagents}),
withInternalTestServerExperiments(codersdk.Experiments{codersdk.ExperimentChatInlineMCPServers, codersdk.ExperimentChatACPSubagents, codersdk.ExperimentOpenPreview}),
)
server.previewAppHostname = "*.apps.example.com"
server.mcpHTTPClient = mcpclient.NewHTTPClient(nil, safedial.WithAllowedPrefixes(netip.MustParsePrefix("127.0.0.0/8")))
noPreviewsServer := newInternalTestServer(t, db, ps, chatprovider.ProviderAPIKeys{},
withInternalTestServerTransportFactory(&aibridgeTestFactory{}),
withInternalTestServerExperiments(codersdk.Experiments{codersdk.ExperimentChatInlineMCPServers, codersdk.ExperimentChatACPSubagents}),
withInternalTestServerExperiments(codersdk.Experiments{codersdk.ExperimentChatInlineMCPServers, codersdk.ExperimentChatACPSubagents, codersdk.ExperimentOpenPreview}),
)
noPreviewsServer.mcpHTTPClient = server.mcpHTTPClient
// Same as server, but without the open-preview experiment: the tool stays
// unoffered even with a preview app hostname.
noExperimentServer := newInternalTestServer(t, db, ps, chatprovider.ProviderAPIKeys{},
withInternalTestServerTransportFactory(&aibridgeTestFactory{}),
withInternalTestServerExperiments(codersdk.Experiments{codersdk.ExperimentChatInlineMCPServers, codersdk.ExperimentChatACPSubagents}),
)
noExperimentServer.previewAppHostname = "*.apps.example.com"
noExperimentServer.mcpHTTPClient = server.mcpHTTPClient

explore := database.NullChatMode{ChatMode: database.ChatModeExplore, Valid: true}
plan := database.NullChatPlanMode{ChatPlanMode: database.ChatPlanModePlan, Valid: true}
Expand Down Expand Up @@ -891,6 +899,9 @@ func TestBuildTurnEnvironmentToolPolicy(t *testing.T) {
replaceMCP bool
// noPreviews builds the turn on a server without a preview app hostname.
noPreviews bool
// noExperiment builds the turn on a server without the open-preview
// experiment, so the tool stays unoffered.
noExperiment bool
// prompt lists the instructions the system prompt must contain;
// the others in the set must be absent.
prompt []string
Expand All @@ -914,6 +925,13 @@ func TestBuildTurnEnvironmentToolPolicy(t *testing.T) {
want: []string{"create_workspace", chatadvisor.ToolName},
dontWant: []string{"open_preview"},
},
{
name: "RootWithoutExperiment",
noExperiment: true,
prompt: []string{advisorGuidance, acpSubagentPromptBlock},
want: []string{"create_workspace", chatadvisor.ToolName},
dontWant: []string{"open_preview"},
},
{
name: "GeneralChild",
child: true,
Expand Down Expand Up @@ -1050,6 +1068,9 @@ func TestBuildTurnEnvironmentToolPolicy(t *testing.T) {
if tt.noPreviews {
turnServer = noPreviewsServer
}
if tt.noExperiment {
turnServer = noExperimentServer
}
env, err := turnServer.buildTurnEnvironment(ctx, generationPrepareInput{
Chat: chat,
Messages: messages,
Expand Down
4 changes: 4 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5543,6 +5543,7 @@ const (
ExperimentChatACPSubagents Experiment = "chat-acp-subagents" // Enables workspace-local ACP subagent tools in root chats.
ExperimentChatAutomations Experiment = "chat-automations" // Enables webhook and scheduled automations that deliver prompts to agent chats.
ExperimentAgentPlugins Experiment = "agent-plugins" // Enables skills and MCP servers from Agent Plugins (agent-plugins.org) in workspaces.
ExperimentOpenPreview Experiment = "open-preview" // Enables the open_preview tool and preview tab for agent chats.
)

func (e Experiment) DisplayName() string {
Expand Down Expand Up @@ -5581,6 +5582,8 @@ func (e Experiment) DisplayName() string {
return "Chat Automations"
case ExperimentAgentPlugins:
return "Agent Plugins"
case ExperimentOpenPreview:
return "Open Preview"
default:
// Split on hyphen and convert to title case
// e.g. "mcp-server-http" -> "Mcp Server Http"
Expand Down Expand Up @@ -5609,6 +5612,7 @@ var ExperimentsKnown = Experiments{
ExperimentChatACPSubagents,
ExperimentChatAutomations,
ExperimentAgentPlugins,
ExperimentOpenPreview,
}

// ExperimentsSafe should include all experiments that are safe for
Expand Down
1 change: 1 addition & 0 deletions codersdk/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestExperimentDisplayNames(t *testing.T) {
codersdk.ExperimentChatACPSubagents: "Chat ACP Subagents",
codersdk.ExperimentChatAutomations: "Chat Automations",
codersdk.ExperimentAgentPlugins: "Agent Plugins",
codersdk.ExperimentOpenPreview: "Open Preview",
}

require.Len(t, expected, len(codersdk.ExperimentsKnown))
Expand Down
11 changes: 10 additions & 1 deletion docs/coder-agents/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ Workspace MCP tools are unavailable in plan mode, and plan-mode sub-agents recei

### Embedded previews

> Embedded previews are an experimental feature.
> The feature requires the `open-preview` experiment, and the `open_preview` tool, the preview tab, and the previews API might change or be removed in any release without a compatibility guarantee.

The agent can call `open_preview` to show a running app, HyperText Markup Language (HTML) files, or a workspace app in the chat's right panel.
It gives each preview a short title and supplies exactly one of `port`, `path`, or `app`:

Expand All @@ -303,7 +306,13 @@ It gives each preview a short title and supplies exactly one of `port`, `path`,
To let the agent open an app, set `subdomain = true` on the `coder_app`, or on the module that defines it if the module has a `subdomain` input, then update the workspace to the new template version.
The app opens when you select **Open app** on the tool result while the workspace is running.

`open_preview` is only available when the deployment has a [wildcard access URL](../admin/networking/wildcard-access-url.md).
`open_preview` is only available when the deployment has a [wildcard access URL](../admin/networking/wildcard-access-url.md) and an administrator has enabled the `open-preview` experiment:

```env
CODER_EXPERIMENTS=open-preview
```

The experiment list is read at startup, so enabling or disabling it requires a `coder server` restart.
Previews also need the selected workspace proxy, including one the dashboard selects automatically, to have a wildcard access URL and run the deployment's Coder version.
If the **Preview** tab is missing, a tool result asks you to select a workspace proxy, or a preview doesn't load, go to another dashboard page, such as **Workspaces**, and [select](../admin/networking/workspace-proxies.md#select-a-proxy) the primary proxy, named **Default** unless an administrator renamed it, or a proxy that meets both requirements.
The Agents page uses the proxy you select there.
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ChatMessagePart } from "#/api/typesGenerated";
import { ErrorAlert } from "#/components/Alert/ErrorAlert";
import { useProxy } from "#/contexts/ProxyContext";
import { useAuthenticated } from "#/hooks/useAuthenticated";
import { useDashboard } from "#/modules/dashboard/useDashboard";
import type { ModelSelectorOption } from "#/modules/aiModels/ModelSelector";
import { getAgentBrowserApp } from "#/modules/apps/apps";
import { generateConnectionSessionId, generateUUID } from "#/utils/random";
Expand Down Expand Up @@ -231,6 +232,7 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
}) => {
const { proxy } = useProxy();
const { user: currentUser } = useAuthenticated();
const { experiments } = useDashboard();
const wildcardHostname = proxy.preferredWildcardHostname;
const agentId = chat.id;
const organizationId = chat.organization_id;
Expand Down Expand Up @@ -343,7 +345,10 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
browser: availableBrowserApp !== undefined,
desktop: availableDesktopChatId !== undefined,
debug: debugLoggingEnabled === true,
preview: workspace !== undefined && wildcardHostname !== "",
preview:
workspace !== undefined &&
wildcardHostname !== "" &&
experiments.includes("open-preview"),
};
const supportedSingletonTabs = singletonRightPanelTabIds.filter(
(tabId) => singletonTabSupport[tabId],
Expand Down
Loading