Skip to content

🙌 OpenHands: AI-Driven Development

feat(automations): reflect the built-in integration's connection state in the setup choice modal (OHE-3612) (#18566)

Hiep Leb70dd46bd041
diff --git a/src/api/cloud/settings-service.api.ts b/src/api/cloud/settings-service.api.ts
index 04d5abd5b3..818ab4abcd 100644
--- a/src/api/cloud/settings-service.api.ts
+++ b/src/api/cloud/settings-service.api.ts
@@ -1,3 +1,4 @@
+import { HttpError } from "@openhands/typescript-client";
import {
type Provider,
type Settings,
@@ -237,6 +238,8 @@ export interface CloudIntegrationsConfig {
isJiraEnabled: boolean;
/** Whether the built-in Linear integration is enabled. */
isLinearEnabled: boolean;
+ /** Whether the built-in Slack integration is enabled. */
+ isSlackEnabled: boolean;
/**
* How the instance is deployed: `cloud` for OpenHands Cloud, `self_hosted`
* for an OpenHands Enterprise install, or null when it reports neither.
@@ -248,6 +251,7 @@ export async function fetchCloudIntegrationsConfig(): Promise<CloudIntegrationsC
const backend = getActiveCloudBackend();
const config = await callCloudProxy<{
providers_configured?: Provider[];
+ slack_enabled?: boolean;
feature_flags?: {
enable_jira?: boolean;
enable_linear?: boolean;
@@ -262,6 +266,38 @@ export async function fetchCloudIntegrationsConfig(): Promise<CloudIntegrationsC
providersConfigured: config.providers_configured ?? [],
isJiraEnabled: config.feature_flags?.enable_jira === true,
isLinearEnabled: config.feature_flags?.enable_linear === true,
+ isSlackEnabled: config.slack_enabled === true,
deploymentMode: config.feature_flags?.deployment_mode ?? null,
};
}
+
+/** Whether the current user has linked their Slack account on the instance. */
+export async function fetchCloudSlackStatus(): Promise<boolean> {
+ const backend = getActiveCloudBackend();
+ const status = await callCloudProxy<{ connected?: boolean }>({
+ backend,
+ method: "GET",
+ path: "/slack/status",
+ });
+ return status.connected === true;
+}
+
+/**
+ * Whether the current user has linked a Jira Cloud workspace. The instance
+ * answers 404 for a user without a link, which is the "not connected" case
+ * rather than an error.
+ */
+export async function fetchCloudJiraLinkStatus(): Promise<boolean> {
+ const backend = getActiveCloudBackend();
+ try {
+ await callCloudProxy<unknown>({
+ backend,
+ method: "GET",
+ path: "/integration/jira/workspaces/link",
+ });
+ return true;
+ } catch (e) {
+ if (e instanceof HttpError && e.status === 404) return false;
+ throw e;
+ }
+}
diff --git a/src/components/features/automations/built-in-integration-choice-modal.tsx b/src/components/features/automations/built-in-integration-choice-modal.tsx
index 8c7ade8bef..c0d3b8addc 100644
--- a/src/components/features/automations/built-in-integration-choice-modal.tsx
+++ b/src/components/features/automations/built-in-integration-choice-modal.tsx
@@ -12,34 +12,52 @@ import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";
import { ModalCloseButton } from "#/components/shared/modals/modal-close-button";
import { BrandButton } from "#/components/features/settings/brand-button";
import { McpLogoBadge } from "#/components/features/mcp-logo-badge";
-import { BrandBadge } from "#/components/shared/badge";
import { I18nKey } from "#/i18n/declaration";
import { cn } from "#/utils/utils";
+import { extensionModuleCardPillClassName } from "#/utils/extension-module-card-classes";
import { modalTitleLgClassName } from "#/utils/modal-classes";
+/**
+ * Whether the current user has already connected the built-in integration
+ * (`connected`) or still has to (`connect`).
+ */
+export type BuiltInIntegrationState = "connected" | "connect";
+
+/**
+ * How a connected user asks OpenHands for work from inside the integration.
+ * An instruction to the agent rather than UI copy, so it is intentionally in
+ * English and not localized.
+ */
+const USAGE_EXAMPLE = "@openhands Please complete this task!";
+
interface BuiltInIntegrationChoiceModalProps {
/** The built-in integration that already covers the selected automation. */
integration: IntegrationCatalogEntry;
+ state: BuiltInIntegrationState;
onClose: () => void;
- /** Fired for the "Use the integration" action. */
+ /** Fired for the "Connect to the integration" action. */
onUseBuiltIn: () => void;
/** Fired for the "Continue with polling setup" action. */
onContinuePolling: () => void;
}
/**
- * Shown before an 'Issue to PR' automation is set up on a cloud instance whose
- * built-in integration (Settings > Integrations) provides the same workflow:
- * the user picks between that integration and the polling automation.
+ * Shown before an automation is set up on a cloud instance whose built-in
+ * integration (Settings > Integrations) provides the same workflow. A user
+ * who has connected that integration is shown how to use it; one who has not
+ * is offered to connect it. The polling automation is the alternative either
+ * way.
*/
export function BuiltInIntegrationChoiceModal({
integration,
+ state,
onClose,
onUseBuiltIn,
onContinuePolling,
}: BuiltInIntegrationChoiceModalProps) {
const { t } = useTranslation("openhands");
const { name } = integration;
+ const isConnected = state === "connected";
const builtInFeatures = [
t(I18nKey.AUTOMATION_SETUP_CHOICE$BUILT_IN_FEATURE_READY),
@@ -79,19 +97,24 @@ export function BuiltInIntegrationChoiceModal({
{t(I18nKey.AUTOMATION_SETUP_CHOICE$TITLE)}
</h2>
<p className="mt-2 text-sm text-muted">
- {t(I18nKey.AUTOMATION_SETUP_CHOICE$DESCRIPTION, { name })}
+ {t(
+ isConnected
+ ? I18nKey.AUTOMATION_SETUP_CHOICE$CONNECTED_DESCRIPTION
+ : I18nKey.AUTOMATION_SETUP_CHOICE$DESCRIPTION,
+ { name },
+ )}
</p>
</header>
<div className="flex flex-col gap-3 px-6 pb-6 sm:flex-row">
<div
data-testid="built-in-integration-choice-option-built-in"
- className="flex flex-1 flex-col gap-3 rounded-xl border border-primary bg-surface-raised p-4"
+ className="flex flex-1 flex-col gap-3 rounded-xl border border-border bg-surface-raised p-4"
>
<div className="flex items-start justify-between gap-2">
<McpLogoBadge entry={integration} />
- <BrandBadge className="shrink-0 whitespace-nowrap px-2.5 py-1 text-xs">
+ <span className={extensionModuleCardPillClassName}>
{t(I18nKey.SETTINGS$SKILLS_RECOMMENDED)}
- </BrandBadge>
+ </span>
</div>
<div className="flex flex-col gap-1">
<h3 className="text-sm font-semibold text-contrast">
@@ -103,29 +126,42 @@ export function BuiltInIntegrationChoiceModal({
})}
</p>
</div>
- <ul className="flex flex-col gap-2">
- {builtInFeatures.map((feature) => (
- <li
- key={feature}
- className="flex items-center gap-2 text-sm text-contrast"
- >
- <CircleCheck
- className="size-4 shrink-0 text-primary"
- aria-hidden
- />
- {feature}
- </li>
- ))}
- </ul>
+ {isConnected ? (
+ <code
+ data-testid="built-in-integration-choice-example"
+ className="block rounded-md border border-border-subtle bg-base-secondary px-3 py-2 font-mono text-xs text-contrast"
+ >
+ {USAGE_EXAMPLE}
+ </code>
+ ) : (
+ <ul className="flex flex-col gap-2">
+ {builtInFeatures.map((feature) => (
+ <li
+ key={feature}
+ className="flex items-center gap-2 text-sm text-contrast"
+ >
+ <CircleCheck
+ className="size-4 shrink-0 text-tertiary-light"
+ aria-hidden
+ />
+ {feature}
+ </li>
+ ))}
+ </ul>
+ )}
<BrandButton
type="button"
variant="primary"
- className="mt-auto flex items-center justify-center gap-2"
+ className="mt-auto flex items-center justify-center gap-2 bg-contrast text-contrast-foreground"
testId="built-in-integration-choice-use-built-in"
- onClick={onUseBuiltIn}
+ onClick={isConnected ? onClose : onUseBuiltIn}
>
- {t(I18nKey.AUTOMATION_SETUP_CHOICE$BUILT_IN_ACTION, { name })}
- <ArrowRight className="size-4 shrink-0" aria-hidden />
+ {isConnected
+ ? t(I18nKey.CHAT_INTERFACE$BTW_GOT_IT)
+ : t(I18nKey.AUTOMATION_SETUP_CHOICE$CONNECT_ACTION, { name })}
+ {!isConnected && (
+ <ArrowRight className="size-4 shrink-0" aria-hidden />
+ )}
</BrandButton>
</div>
diff --git a/src/components/features/automations/dashboard/automations-filtered-empty-state.tsx b/src/components/features/automations/dashboard/automations-filtered-empty-state.tsx
index 6b0227318a..4f5bc660b4 100644
--- a/src/components/features/automations/dashboard/automations-filtered-empty-state.tsx
+++ b/src/components/features/automations/dashboard/automations-filtered-empty-state.tsx
@@ -3,6 +3,8 @@ import { I18nKey } from "#/i18n/declaration";
interface AutomationsFilteredEmptyStateProps {
onClear: () => void;
+ /** Replaces the default "no automations match" message. */
+ message?: string;
}
/**
@@ -11,6 +13,7 @@ interface AutomationsFilteredEmptyStateProps {
*/
export function AutomationsFilteredEmptyState({
onClear,
+ message,
}: AutomationsFilteredEmptyStateProps) {
const { t } = useTranslation("openhands");
return (
@@ -19,7 +22,7 @@ export function AutomationsFilteredEmptyState({
className="rounded-xl border border-dashed border-border p-8 text-center"
>
<p className="text-sm text-muted">
- {t(I18nKey.AUTOMATIONS$NO_FILTER_MATCHES)}
+ {message ?? t(I18nKey.AUTOMATIONS$NO_FILTER_MATCHES)}
</p>
<button
type="button"
diff --git a/src/components/features/automations/recommended-automations-launcher.tsx b/src/components/features/automations/recommended-automations-launcher.tsx
index 6e8308b2bf..0e375dd909 100644
--- a/src/components/features/automations/recommended-automations-launcher.tsx
+++ b/src/components/features/automations/recommended-automations-launcher.tsx
@@ -37,15 +37,25 @@ import {
import { isResponderAutomation } from "#/utils/responder-deployment";
import { useAutomationHealth } from "#/hooks/query/use-automation-health";
import { useAutomations } from "#/hooks/query/use-automations";
+import { useBuiltInIntegrationConnections } from "#/hooks/query/use-built-in-integration-connections";
import { useNativeGitIntegrations } from "#/hooks/query/use-native-git-integrations";
import { cloudIntegrationsUrl } from "#/utils/cloud-integrations-url";
-import { BuiltInIntegrationChoiceModal } from "./built-in-integration-choice-modal";
+import {
+ BuiltInIntegrationChoiceModal,
+ type BuiltInIntegrationState,
+} from "./built-in-integration-choice-modal";
import { RecommendedAutomationsRail } from "./recommended-automations-rail";
import { RecommendedAutomationsSection } from "./recommended-automations-section";
import { ResponderDeploymentModal } from "./responder-deployment-modal";
+import type { TemplateFilters } from "./template-filter-chips";
interface RecommendedAutomationsLauncherProps {
query?: string;
+ /** Resets the search from the catalog's no-match state. */
+ onClearQuery?: () => void;
+ /** The templates page's integration and trigger filters. */
+ filters?: TemplateFilters;
+ onFiltersChange?: (next: TemplateFilters) => void;
onLaunched?: () => void;
/** When true, only the automation card grid scrolls inside its section. */
scrollableGrid?: boolean;
@@ -71,11 +81,12 @@ function getRequiredEntries(automation: RecommendedAutomation) {
}
/**
- * The 'Issue to PR' automations a built-in integration (Settings >
- * Integrations) already provides out of the box, keyed to that integration's
- * catalog entry.
+ * The automations a built-in integration (Settings > Integrations) already
+ * provides out of the box — the 'Issue to PR' workflows and the Slack
+ * responder — keyed to that integration's catalog entry.
*/
const BUILT_IN_INTEGRATION_ID_BY_AUTOMATION_ID: Record<string, string> = {
+ "slack-channel-monitor": "slack",
"github-issue-to-pr": "github",
"gitlab-issue-to-mr": "gitlab",
"jira-issue-to-pr": "jira",
@@ -88,6 +99,9 @@ const BUILT_IN_INTEGRATION_ID_BY_AUTOMATION_ID: Record<string, string> = {
export function RecommendedAutomationsLauncher({
query,
+ onClearQuery,
+ filters,
+ onFiltersChange,
onLaunched,
scrollableGrid = false,
variant = "catalog",
@@ -112,6 +126,7 @@ export function RecommendedAutomationsLauncher({
const [builtInChoice, setBuiltInChoice] = useState<{
automation: RecommendedAutomation;
integration: MarketplaceEntry;
+ state: BuiltInIntegrationState;
} | null>(null);
const [installQueue, setInstallQueue] = useState<MarketplaceEntry[]>([]);
const completedInstallRef = useRef(false);
@@ -129,10 +144,16 @@ export function RecommendedAutomationsLauncher({
getNativeIntegration,
isJiraEnabled,
isLinearEnabled,
+ isSlackEnabled,
deploymentMode,
isLoading: isNativeIntegrationsLoading,
} = useNativeGitIntegrations();
const hiddenAutomationIds = getHiddenAutomationIds(deploymentMode);
+ const { isSlackConnected, isJiraConnected } =
+ useBuiltInIntegrationConnections({
+ slackEnabled: isSlackEnabled,
+ jiraEnabled: isJiraEnabled,
+ });
const installedMcpConfig = useMemo(
() =>
@@ -232,11 +253,22 @@ export function RecommendedAutomationsLauncher({
};
const isBuiltInIntegrationEnabled = (entryId: string) => {
+ if (entryId === "slack") return isSlackEnabled;
if (entryId === "jira") return isJiraEnabled;
if (entryId === "linear") return isLinearEnabled;
return getNativeIntegration(entryId) !== null;
};
+ // Whether the current user has connected the built-in integration. Linear
+ // has no connection lookup on the cloud backend, so it is never known to be
+ // connected and the modal keeps offering to connect it.
+ const isBuiltInIntegrationConnected = (entryId: string) => {
+ if (entryId === "slack") return isSlackConnected;
+ if (entryId === "jira") return isJiraConnected;
+ if (entryId === "linear") return false;
+ return getNativeIntegration(entryId)?.isConnected === true;
+ };
+
// The built-in integration that already gives the user this automation's
// 'Issue to PR' workflow, when the cloud instance has it enabled.
const getBuiltInIntegration = (automation: RecommendedAutomation) => {
@@ -268,11 +300,18 @@ export function RecommendedAutomationsLauncher({
return;
}
- // A built-in integration already covers this workflow; let the user choose
- // between connecting it and setting up the polling automation.
+ // A built-in integration already covers this workflow: show how to use it
+ // when the user has connected it, or offer to connect it, with the polling
+ // automation as the alternative either way.
const builtInIntegration = getBuiltInIntegration(automation);
if (builtInIntegration) {
- setBuiltInChoice({ automation, integration: builtInIntegration });
+ setBuiltInChoice({
+ automation,
+ integration: builtInIntegration,
+ state: isBuiltInIntegrationConnected(builtInIntegration.id)
+ ? "connected"
+ : "connect",
+ });
return;
}
@@ -384,6 +423,9 @@ export function RecommendedAutomationsLauncher({
hiddenAutomationIds={hiddenAutomationIds}
getNativeIntegration={getNativeIntegration}
query={query}
+ onClearQuery={onClearQuery}
+ filters={filters}
+ onFiltersChange={onFiltersChange}
onSelect={handleSelectAutomation}
scrollableGrid={scrollableGrid}
/>
@@ -403,6 +445,7 @@ export function RecommendedAutomationsLauncher({
{builtInChoice && (
<BuiltInIntegrationChoiceModal
integration={builtInChoice.integration}
+ state={builtInChoice.state}
onClose={handleBuiltInChoiceClose}
onUseBuiltIn={handleUseBuiltInIntegration}
onContinuePolling={handleContinuePollingSetup}
diff --git a/src/components/features/automations/recommended-automations-section.tsx b/src/components/features/automations/recommended-automations-section.tsx
index 43a2bb19f6..6a880ba462 100644
--- a/src/components/features/automations/recommended-automations-section.tsx
+++ b/src/components/features/automations/recommended-automations-section.tsx
@@ -17,6 +17,7 @@ import {
type SkillCardPill,
} from "#/components/features/skills/skill-card-pill-row";
import { CirclePlusBadge } from "#/components/shared/buttons/circle-plus-check-toggle";
+import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
import { MCPServerConfig } from "#/types/mcp-server";
import type { NativeGitIntegration } from "#/hooks/query/use-native-git-integrations";
import {
@@ -29,6 +30,9 @@ import {
getAutomationIcon,
getAutomationLaunchPrompt,
getIntegrationIds,
+ getTemplateIntegrationIds,
+ getTemplateTriggerKinds,
+ type TemplateTriggerKind,
} from "#/utils/automation-catalog";
import { getAutomationsByPopularity } from "#/utils/recommended-automation-rail";
import { cn } from "#/utils/utils";
@@ -39,7 +43,16 @@ import {
extensionModuleCardPillClassName,
extensionModuleCardSurfaceClassName,
} from "#/utils/extension-module-card-classes";
+import { AutomationsFilteredEmptyState } from "./dashboard/automations-filtered-empty-state";
import { StatusBadge } from "./status-badge";
+import {
+ EMPTY_TEMPLATE_FILTERS,
+ hasActiveTemplateFilter,
+ TemplateFilterChips,
+ TRIGGER_KIND_ICON,
+ TRIGGER_KIND_LABEL_KEY,
+ type TemplateFilters,
+} from "./template-filter-chips";
type GetNativeIntegration = (entryId: string) => NativeGitIntegration | null;
@@ -51,6 +64,11 @@ interface RecommendedAutomationsSectionProps {
/** Resolves an integration's native (cloud) connection; none by default. */
getNativeIntegration?: GetNativeIntegration;
query?: string;
+ /** Resets the search; with it, a no-match state offers a way back. */
+ onClearQuery?: () => void;
+ /** The integration and trigger filters, when the page offers them. */
+ filters?: TemplateFilters;
+ onFiltersChange?: (next: TemplateFilters) => void;
onSelect: (automation: RecommendedAutomation) => void;
/** When true, title, description, and cards share one scroll area. */
scrollableGrid?: boolean;
@@ -97,6 +115,33 @@ function getIntegrationEntries(
});
}
+function automationMatchesFilters(
+ automation: RecommendedAutomation,
+ filters: TemplateFilters,
+) {
+ if (
+ filters.integrationId &&
+ !getTemplateIntegrationIds(automation).includes(filters.integrationId)
+ ) {
+ return false;
+ }
+ return (
+ !filters.trigger ||
+ getTemplateTriggerKinds(automation).includes(filters.trigger)
+ );
+}
+
+/** The integrations the templates are about, in first-appearance order. */
+function collectIntegrationIds(automations: RecommendedAutomation[]) {
+ const ids: string[] = [];
+ for (const automation of automations) {
+ for (const id of getTemplateIntegrationIds(automation)) {
+ if (!ids.includes(id)) ids.push(id);
+ }
+ }
+ return ids;
+}
+
function automationMatchesQuery(
automation: RecommendedAutomation,
integrations: AutomationIntegration[],
@@ -218,6 +263,32 @@ function AutomationCardIcon({
);
}
+/** The card's trigger-kind mark: the glyph, with the kind's name on hover. */
+function TriggerKindBadge({
+ kind,
+ automationId,
+ translate,
+}: {
+ kind: TemplateTriggerKind;
+ automationId: string;
+ translate: TFunction;
+}) {
+ const label = translate(TRIGGER_KIND_LABEL_KEY[kind]);
+ const Icon = TRIGGER_KIND_ICON[kind];
+ return (
+ <StyledTooltip content={label} placement="top">
+ <span
+ role="img"
+ aria-label={label}
+ data-testid={`recommended-automation-trigger-${automationId}-${kind}`}
+ className="inline-flex size-6 shrink-0 items-center justify-center rounded-md bg-base-secondary text-tertiary-alt"
+ >
+ <Icon className="size-3.5" aria-hidden />
+ </span>
+ </StyledTooltip>
+ );
+}
+
interface AutomationCardGridProps {
automations: RecommendedAutomation[];
installedServers: MCPServerConfig[];
@@ -279,9 +350,19 @@ function AutomationCardGrid({
{automation.category}
</p>
</div>
- <CirclePlusBadge
- testId={`recommended-automation-plus-${automation.id}`}
- />
+ <div className="flex shrink-0 items-center gap-1.5">
+ {getTemplateTriggerKinds(automation).map((kind) => (
+ <TriggerKindBadge
+ key={kind}
+ kind={kind}
+ automationId={automation.id}
+ translate={translate}
+ />
+ ))}
+ <CirclePlusBadge
+ testId={`recommended-automation-plus-${automation.id}`}
+ />
+ </div>
</header>
<p className="line-clamp-2 text-xs leading-relaxed text-tertiary-light">
{automation.description}
@@ -312,18 +393,24 @@ export function RecommendedAutomationsSection({
hiddenAutomationIds,
getNativeIntegration = () => null,
query = "",
+ onClearQuery,
+ filters,
+ onFiltersChange,
onSelect,
scrollableGrid = false,
}: RecommendedAutomationsSectionProps) {
const { t } = useTranslation("openhands");
- // Only the deployment's hide list and the query narrow the grid. An
- // automation that declares no integration needs nothing connected, and one
- // naming an integration this host cannot resolve is shown with that gap on
- // its pill, so neither is a reason to hide a card the catalog ships.
- const visibleAutomations = RECOMMENDED_AUTOMATIONS.filter(
+ // Only the deployment's hide list, the filters and the query narrow the
+ // grid. An automation that declares no integration needs nothing connected,
+ // and one naming an integration this host cannot resolve is shown with that
+ // gap on its pill, so neither is a reason to hide a card the catalog ships.
+ const offeredAutomations = RECOMMENDED_AUTOMATIONS.filter(
+ (automation) => !hiddenAutomationIds?.has(automation.id),
+ );
+ const visibleAutomations = offeredAutomations.filter(
(automation) =>
- !hiddenAutomationIds?.has(automation.id) &&
+ (!filters || automationMatchesFilters(automation, filters)) &&
automationMatchesQuery(
automation,
getIntegrationEntries(automation),
@@ -331,7 +418,39 @@ export function RecommendedAutomationsSection({
),
);
- if (visibleAutomations.length === 0) return null;
+ const filterChips =
+ filters && onFiltersChange ? (
+ <TemplateFilterChips
+ integrationIds={collectIntegrationIds(offeredAutomations)}
+ filters={filters}
+ onChange={onFiltersChange}
+ />
+ ) : null;
+
+ if (visibleAutomations.length === 0) {
+ // A search or filter that matches nothing says so, with a way back. A
+ // surface without either control keeps rendering nothing.
+ const canClear = !!onClearQuery || !!onFiltersChange;
+ const isNarrowed =
+ query.trim().length > 0 ||
+ (!!filters && hasActiveTemplateFilter(filters));
+ if (!canClear || !isNarrowed) return null;
+ return (
+ <section
+ data-testid="recommended-automations-section"
+ className="mt-3 flex flex-col gap-4"
+ >
+ {filterChips}
+ <AutomationsFilteredEmptyState
+ message={t(I18nKey.RECOMMENDED_AUTOMATIONS$NO_MATCHING_TEMPLATES)}
+ onClear={() => {
+ onClearQuery?.();
+ onFiltersChange?.(EMPTY_TEMPLATE_FILTERS);
+ }}
+ />
+ </section>
+ );
+ }
const provenAutomations = visibleAutomations.filter(isProvenAutomation);
const betaAutomations = visibleAutomations.filter(
@@ -354,6 +473,8 @@ export function RecommendedAutomationsSection({
"min-h-0 flex-1 overflow-y-auto custom-scrollbar-always",
)}
>
+ {filterChips && <div className="mb-4">{filterChips}</div>}
+
{provenAutomations.length > 0 && (
<>
<div className="flex items-center">
diff --git a/src/components/features/automations/template-filter-chips.tsx b/src/components/features/automations/template-filter-chips.tsx
new file mode 100644
index 0000000000..8e19d9e417
--- /dev/null
+++ b/src/components/features/automations/template-filter-chips.tsx
@@ -0,0 +1,138 @@
+import type { ReactNode } from "react";
+import { Clock, LayoutGrid, Zap, type LucideIcon } from "lucide-react";
+import { useTranslation } from "react-i18next";
+import { INTEGRATION_CATALOG as MCP_MARKETPLACE } from "@openhands/extensions/integrations";
+import { McpLogoBadge } from "#/components/features/mcp-logo-badge";
+import { I18nKey } from "#/i18n/declaration";
+import type { TemplateTriggerKind } from "#/utils/automation-catalog";
+import { dropdownFilterTriggerClassName } from "#/utils/dropdown-classes";
+import { getMarketplaceEntryById } from "#/utils/mcp-marketplace-utils";
+import { cn } from "#/utils/utils";
+
+/** The Templates page filters: one integration and one trigger kind, combined. */
+export interface TemplateFilters {
+ integrationId: string | null;
+ trigger: TemplateTriggerKind | null;
+}
+
+export const EMPTY_TEMPLATE_FILTERS: TemplateFilters = {
+ integrationId: null,
+ trigger: null,
+};
+
+export function hasActiveTemplateFilter(filters: TemplateFilters): boolean {
+ return filters.integrationId !== null || filters.trigger !== null;
+}
+
+/** The chip and card-badge presentation of each trigger kind. */
+export const TRIGGER_KIND_ICON: Record<TemplateTriggerKind, LucideIcon> = {
+ cron: Clock,
+ event: Zap,
+};
+
+export const TRIGGER_KIND_LABEL_KEY: Record<TemplateTriggerKind, I18nKey> = {
+ cron: I18nKey.RECOMMENDED_AUTOMATIONS$TRIGGER_CRON,
+ event: I18nKey.RECOMMENDED_AUTOMATIONS$TRIGGER_EVENT,
+};
+
+const TRIGGER_KINDS: readonly TemplateTriggerKind[] = ["cron", "event"];
+
+function FilterChip({
+ active,
+ testId,
+ onClick,
+ children,
+}: {
+ active: boolean;
+ testId: string;
+ onClick: () => void;
+ children: ReactNode;
+}) {
+ return (
+ <button
+ type="button"
+ data-testid={testId}
+ aria-pressed={active}
+ onClick={onClick}
+ className={cn(
+ dropdownFilterTriggerClassName,
+ "h-8 py-0 text-xs",
+ active && "border-contrast/60 bg-contrast/10",
+ )}
+ >
+ {children}
+ </button>
+ );
+}
+
+interface TemplateFilterChipsProps {
+ /** The integrations the offered templates are about, in display order. */
+ integrationIds: readonly string[];
+ filters: TemplateFilters;
+ onChange: (next: TemplateFilters) => void;
+}
+
+/**
+ * Toggle chips above the templates grid: every template, one chip per
+ * integration, and one per trigger kind. One integration and one trigger kind
+ * can be active at once and combine; clicking an active chip clears it.
+ */
+export function TemplateFilterChips({
+ integrationIds,
+ filters,
+ onChange,
+}: TemplateFilterChipsProps) {
+ const { t } = useTranslation("openhands");
+
+ return (
+ <div
+ role="group"
+ aria-label={t(I18nKey.RECOMMENDED_AUTOMATIONS$FILTERS_LABEL)}
+ data-testid="template-filters"
+ className="flex flex-wrap items-center gap-2"
+ >
+ <FilterChip
+ testId="template-filter-all"
+ active={!hasActiveTemplateFilter(filters)}
+ onClick={() => onChange(EMPTY_TEMPLATE_FILTERS)}
+ >
+ <LayoutGrid className="size-3.5 shrink-0" aria-hidden />
+ {t(I18nKey.RECOMMENDED_AUTOMATIONS$FILTER_ALL)}
+ </FilterChip>
+ {integrationIds.map((id) => {
+ const entry = getMarketplaceEntryById(id, MCP_MARKETPLACE);
+ const active = filters.integrationId === id;
+ return (
+ <FilterChip
+ key={id}
+ testId={`template-filter-integration-${id}`}
+ active={active}
+ onClick={() =>
+ onChange({ ...filters, integrationId: active ? null : id })
+ }
+ >
+ <McpLogoBadge entry={entry} size="xs" />
+ {entry?.name ?? id}
+ </FilterChip>
+ );
+ })}
+ {TRIGGER_KINDS.map((kind) => {
+ const Icon = TRIGGER_KIND_ICON[kind];
+ const active = filters.trigger === kind;
+ return (
+ <FilterChip
+ key={kind}
+ testId={`template-filter-trigger-${kind}`}
+ active={active}
+ onClick={() =>
+ onChange({ ...filters, trigger: active ? null : kind })
+ }
+ >
+ <Icon className="size-3.5 shrink-0" aria-hidden />
+ {t(TRIGGER_KIND_LABEL_KEY[kind])}
+ </FilterChip>
+ );
+ })}
+ </div>
+ );
+}
diff --git a/src/hooks/query/use-built-in-integration-connections.ts b/src/hooks/query/use-built-in-integration-connections.ts
new file mode 100644
index 0000000000..9632111bf1
--- /dev/null
+++ b/src/hooks/query/use-built-in-integration-connections.ts
@@ -0,0 +1,52 @@
+import { useQuery } from "@tanstack/react-query";
+import {
+ fetchCloudJiraLinkStatus,
+ fetchCloudSlackStatus,
+} from "#/api/cloud/settings-service.api";
+import { useActiveBackend } from "#/contexts/active-backend-context";
+
+interface BuiltInIntegrationConnectionsOptions {
+ /** Whether the instance offers the built-in Slack integration. */
+ slackEnabled: boolean;
+ /** Whether the instance offers the built-in Jira Cloud integration. */
+ jiraEnabled: boolean;
+}
+
+/**
+ * Whether the current user has connected the cloud instance's built-in Slack
+ * and Jira Cloud integrations. Git providers are read from the settings'
+ * `provider_tokens_set` instead (see `useNativeGitIntegrations`); these two
+ * have lookups of their own on the cloud backend. Each query runs only on a
+ * cloud backend whose instance offers the integration, and an answer that is
+ * not known yet reads as "not connected".
+ */
+export function useBuiltInIntegrationConnections({
+ slackEnabled,
+ jiraEnabled,
+}: BuiltInIntegrationConnectionsOptions) {
+ const { backend } = useActiveBackend();
+ const isCloud = backend.kind === "cloud";
+ const revision = backend.connectionRevision ?? 0;
+
+ const { data: isSlackConnected } = useQuery({
+ queryKey: ["cloud-slack-status", backend.id, revision],
+ queryFn: fetchCloudSlackStatus,
+ enabled: isCloud && slackEnabled,
+ staleTime: 1000 * 60 * 5,
+ retry: false,
+ meta: { disableToast: true },
+ });
+ const { data: isJiraConnected } = useQuery({
+ queryKey: ["cloud-jira-link", backend.id, revision],
+ queryFn: fetchCloudJiraLinkStatus,
+ enabled: isCloud && jiraEnabled,
+ staleTime: 1000 * 60 * 5,
+ retry: false,
+ meta: { disableToast: true },
+ });
+
+ return {
+ isSlackConnected: isSlackConnected === true,
+ isJiraConnected: isJiraConnected === true,
+ };
+}
diff --git a/src/hooks/query/use-native-git-integrations.ts b/src/hooks/query/use-native-git-integrations.ts
index d290fda7ea..50aa9a337e 100644
--- a/src/hooks/query/use-native-git-integrations.ts
+++ b/src/hooks/query/use-native-git-integrations.ts
@@ -29,9 +29,10 @@ export function isNativeGitCandidate(entryId: string): boolean {
* option — on local backends, for non-git entries, and for providers the
* instance has not enabled. While `isLoading`, the instance's providers are
* not known yet and null means nothing: wait rather than decide on it.
- * `isJiraEnabled` and `isLinearEnabled` are whether the instance offers the
- * built-in Jira Cloud and Linear integrations there; they are not git
- * connections, so they never satisfy an integration requirement.
+ * `isJiraEnabled`, `isLinearEnabled` and `isSlackEnabled` are whether the
+ * instance offers the built-in Jira Cloud, Linear and Slack integrations
+ * there; they are not git connections, so they never satisfy an integration
+ * requirement.
* `deploymentMode` is the instance's reported deployment mode (`cloud` or
* `self_hosted`), null on local backends and on instances that report none.
*/
@@ -69,6 +70,7 @@ export function useNativeGitIntegrations() {
getNativeIntegration,
isJiraEnabled: isCloud && config?.isJiraEnabled === true,
isLinearEnabled: isCloud && config?.isLinearEnabled === true,
+ isSlackEnabled: isCloud && config?.isSlackEnabled === true,
deploymentMode: isCloud ? (config?.deploymentMode ?? null) : null,
isLoading,
};
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 3d52eda96c..e5c56ed00f 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -38987,6 +38987,96 @@
"uk": "Рекомендовані автоматизації",
"id": "Otomatisasi yang disarankan"
},
+ "RECOMMENDED_AUTOMATIONS$FILTER_ALL": {
+ "ar": "الكل",
+ "ca": "Tot",
+ "de": "Alle",
+ "en": "All",
+ "es": "Todos",
+ "fr": "Tout",
+ "it": "Tutti",
+ "ja": "すべて",
+ "ko-KR": "전체",
+ "no": "Alle",
+ "pt": "Todos",
+ "tr": "Tümü",
+ "uk": "Усі",
+ "zh-CN": "全部",
+ "zh-TW": "全部",
+ "id": "Semua"
+ },
+ "RECOMMENDED_AUTOMATIONS$FILTERS_LABEL": {
+ "ar": "تصفية القوالب",
+ "ca": "Filtra les plantilles",
+ "de": "Vorlagen filtern",
+ "en": "Filter templates",
+ "es": "Filtrar plantillas",
+ "fr": "Filtrer les modèles",
+ "it": "Filtra i modelli",
+ "ja": "テンプレートを絞り込む",
+ "ko-KR": "템플릿 필터",
+ "no": "Filtrer maler",
+ "pt": "Filtrar modelos",
+ "tr": "Şablonları filtrele",
+ "uk": "Фільтрувати шаблони",
+ "zh-CN": "筛选模板",
+ "zh-TW": "篩選範本",
+ "id": "Filter templat"
+ },
+ "RECOMMENDED_AUTOMATIONS$TRIGGER_CRON": {
+ "ar": "Cron (مجدول)",
+ "ca": "Cron",
+ "de": "Cron",
+ "en": "Cron",
+ "es": "Cron",
+ "fr": "Cron",
+ "it": "Cron",
+ "ja": "Cron(定期実行)",
+ "ko-KR": "Cron(예약 실행)",
+ "no": "Cron",
+ "pt": "Cron",
+ "tr": "Cron",
+ "uk": "Cron (за розкладом)",
+ "zh-CN": "Cron(定时)",
+ "zh-TW": "Cron(定時)",
+ "id": "Cron"
+ },
+ "RECOMMENDED_AUTOMATIONS$TRIGGER_EVENT": {
+ "ar": "مدفوع بالأحداث",
+ "ca": "Basat en esdeveniments",
+ "de": "Ereignisgesteuert",
+ "en": "Event driven",
+ "es": "Basado en eventos",
+ "fr": "Événementiel",
+ "it": "Basato su eventi",
+ "ja": "イベント駆動",
+ "ko-KR": "이벤트 기반",
+ "no": "Hendelsesdrevet",
+ "pt": "Orientado a eventos",
+ "tr": "Olay tabanlı",
+ "uk": "За подіями",
+ "zh-CN": "事件驱动",
+ "zh-TW": "事件驅動",
+ "id": "Berbasis peristiwa"
+ },
+ "RECOMMENDED_AUTOMATIONS$NO_MATCHING_TEMPLATES": {
+ "ar": "لم يتم العثور على قوالب مطابقة — عد للتحقق قريبًا.",
+ "ca": "No s'han trobat plantilles coincidents — torna a comprovar-ho aviat.",
+ "de": "Keine passenden Vorlagen gefunden — schauen Sie bald wieder vorbei.",
+ "en": "No matching templates found — check back again soon.",
+ "es": "No se encontraron plantillas coincidentes — vuelve a consultar pronto.",
+ "fr": "Aucun modèle correspondant — revenez bientôt.",
+ "it": "Nessun modello corrispondente — ricontrolla presto.",
+ "ja": "一致するテンプレートが見つかりません。また後ほどご確認ください。",
+ "ko-KR": "일치하는 템플릿이 없습니다 — 곧 다시 확인해 주세요.",
+ "no": "Fant ingen passende maler — sjekk igjen snart.",
+ "pt": "Nenhum modelo correspondente encontrado — volte a verificar em breve.",
+ "tr": "Eşleşen şablon bulunamadı — yakında tekrar kontrol edin.",
+ "uk": "Відповідних шаблонів не знайдено — перевірте згодом.",
+ "zh-CN": "未找到匹配的模板 — 请稍后再来查看。",
+ "zh-TW": "找不到符合的範本 — 請稍後再回來查看。",
+ "id": "Tidak ada templat yang cocok — periksa kembali nanti."
+ },
"RECOMMENDED_AUTOMATIONS$DISMISS_LABEL": {
"en": "Hide Recommended automations",
"ja": "おすすめの自動化を非表示",
@@ -41075,23 +41165,41 @@
"zh-TW": "開箱即用的工作流程",
"id": "Alur kerja siap pakai"
},
- "AUTOMATION_SETUP_CHOICE$BUILT_IN_ACTION": {
- "ar": "استخدم تكامل {{name}}",
- "ca": "Utilitza la integració de {{name}}",
- "de": "{{name}}-Integration verwenden",
- "en": "Use {{name}} Integration",
- "es": "Usar la integración de {{name}}",
- "fr": "Utiliser l'intégration {{name}}",
- "it": "Usa l'integrazione {{name}}",
- "ja": "{{name}}連携を使用",
- "ko-KR": "{{name}} 통합 사용",
- "no": "Bruk {{name}}-integrasjonen",
- "pt": "Usar a integração do {{name}}",
- "tr": "{{name}} entegrasyonunu kullan",
- "uk": "Використати інтеграцію {{name}}",
- "zh-CN": "使用 {{name}} 集成",
- "zh-TW": "使用 {{name}} 整合",
- "id": "Gunakan Integrasi {{name}}"
+ "AUTOMATION_SETUP_CHOICE$CONNECT_ACTION": {
+ "ar": "الاتصال بـ {{name}}",
+ "ca": "Connecta a {{name}}",
+ "de": "Mit {{name}} verbinden",
+ "en": "Connect to {{name}}",
+ "es": "Conectar con {{name}}",
+ "fr": "Se connecter à {{name}}",
+ "it": "Connetti a {{name}}",
+ "ja": "{{name}}に接続",
+ "ko-KR": "{{name}}에 연결",
+ "no": "Koble til {{name}}",
+ "pt": "Conectar ao {{name}}",
+ "tr": "{{name}} ile bağlan",
+ "uk": "Підключитися до {{name}}",
+ "zh-CN": "连接到 {{name}}",
+ "zh-TW": "連接到 {{name}}",
+ "id": "Hubungkan ke {{name}}"
+ },
+ "AUTOMATION_SETUP_CHOICE$CONNECTED_DESCRIPTION": {
+ "ar": "يمكنك استخدام OpenHands في {{name}} اليوم — إليك مثالاً:",
+ "ca": "Ja pots utilitzar OpenHands a {{name}} — aquí tens un exemple:",
+ "de": "Sie können OpenHands schon heute in {{name}} verwenden — hier ein Beispiel:",
+ "en": "You can use OpenHands in {{name}} today — here's an example:",
+ "es": "Ya puedes usar OpenHands en {{name}} — aquí tienes un ejemplo:",
+ "fr": "Vous pouvez utiliser OpenHands dans {{name}} dès aujourd'hui — voici un exemple :",
+ "it": "Puoi già usare OpenHands in {{name}} — ecco un esempio:",
+ "ja": "{{name}}で今すぐOpenHandsを使えます。例:",
+ "ko-KR": "지금 바로 {{name}}에서 OpenHands를 사용할 수 있습니다 — 예시:",
+ "no": "Du kan bruke OpenHands i {{name}} i dag — her er et eksempel:",
+ "pt": "Você já pode usar o OpenHands no {{name}} — veja um exemplo:",
+ "tr": "OpenHands'i bugün {{name}} içinde kullanabilirsiniz — işte bir örnek:",
+ "uk": "Ви вже можете використовувати OpenHands у {{name}} — ось приклад:",
+ "zh-CN": "你现在就可以在 {{name}} 中使用 OpenHands — 示例:",
+ "zh-TW": "你現在就可以在 {{name}} 中使用 OpenHands — 範例:",
+ "id": "Anda sudah bisa menggunakan OpenHands di {{name}} — berikut contohnya:"
},
"AUTOMATION_SETUP_CHOICE$POLLING_TITLE": {
"ar": "إعداد أتمتة الاستطلاع",
diff --git a/src/mocks/settings-handlers.ts b/src/mocks/settings-handlers.ts
index 89825715ce..7c9fb9b744 100644
--- a/src/mocks/settings-handlers.ts
+++ b/src/mocks/settings-handlers.ts
@@ -927,6 +927,16 @@ export const SETTINGS_HANDLERS = [
return HttpResponse.json(config);
}),
+ // Built-in integration connection lookups of a cloud instance; the default
+ // user has linked neither Slack nor a Jira Cloud workspace (Jira answers
+ // 404 for "no link").
+ http.get("*/slack/status", () => HttpResponse.json({ connected: false })),
+
+ http.get(
+ "*/integration/jira/workspaces/link",
+ () => new HttpResponse(null, { status: 404 }),
+ ),
+
http.get("*/api/settings/conversation-schema", async () => {
await delay();
return HttpResponse.json(MOCK_CONVERSATION_SETTINGS_SCHEMA);
diff --git a/src/routes/automation-templates.tsx b/src/routes/automation-templates.tsx
index c80312f096..5cf5a536eb 100644
--- a/src/routes/automation-templates.tsx
+++ b/src/routes/automation-templates.tsx
@@ -2,6 +2,10 @@ import { useState } from "react";
import { useAutomationSubPageNav } from "#/components/features/automations/dashboard/use-automation-sub-page-nav";
import { RecommendedAutomationsLauncher } from "#/components/features/automations/recommended-automations-launcher";
import { SearchInput } from "#/components/features/automations/search-input";
+import {
+ EMPTY_TEMPLATE_FILTERS,
+ type TemplateFilters,
+} from "#/components/features/automations/template-filter-chips";
import { ManifestSubpageLayout } from "#/components/features/manifest/manifest-subpage-layout";
import { getTemplatesPageSpec } from "#/manifests/automation-interface";
@@ -19,6 +23,9 @@ export const clientLoader = () => {
export default function AutomationTemplates() {
const [searchQuery, setSearchQuery] = useState("");
+ const [filters, setFilters] = useState<TemplateFilters>(
+ EMPTY_TEMPLATE_FILTERS,
+ );
const spec = getTemplatesPageSpec();
const nav = useAutomationSubPageNav();
@@ -37,7 +44,12 @@ export default function AutomationTemplates() {
<div className="w-full">
<SearchInput value={searchQuery} onChange={setSearchQuery} />
</div>
- <RecommendedAutomationsLauncher query={searchQuery} />
+ <RecommendedAutomationsLauncher
+ query={searchQuery}
+ onClearQuery={() => setSearchQuery("")}
+ filters={filters}
+ onFiltersChange={setFilters}
+ />
</ManifestSubpageLayout>
);
}
diff --git a/src/utils/automation-catalog.ts b/src/utils/automation-catalog.ts
index a39e6f1b0d..5f382f46ee 100644
--- a/src/utils/automation-catalog.ts
+++ b/src/utils/automation-catalog.ts
@@ -1,5 +1,6 @@
import {
AUTOMATION_CATALOG,
+ type AutomationTriggerKind,
type RecommendedAutomation,
} from "@openhands/extensions/automations";
import {
@@ -64,6 +65,57 @@ export function getRequiredIntegrationIds(
.map(([id]) => id);
}
+/**
+ * Every integration a template is about, for filtering: the ones it declares
+ * plus the git provider of any repository picker in its setup form. Several
+ * GitHub templates declare no integration (their worker uses the connected
+ * account's token) and are GitHub only by that picker.
+ */
+export function getTemplateIntegrationIds(
+ automation: RecommendedAutomation,
+): string[] {
+ const ids = getIntegrationIds(automation);
+ for (const field of Object.values(automation.setup?.form.args ?? {})) {
+ if (
+ field.type === "repo-picker" &&
+ field.provider &&
+ !ids.includes(field.provider)
+ ) {
+ ids.push(field.provider);
+ }
+ }
+ return ids;
+}
+
+export type TemplateTriggerKind = AutomationTriggerKind;
+
+const TEMPLATE_TRIGGER_KINDS: readonly TemplateTriggerKind[] = [
+ "cron",
+ "event",
+];
+
+function isTemplateTriggerKind(value: unknown): value is TemplateTriggerKind {
+ return TEMPLATE_TRIGGER_KINDS.includes(value as TemplateTriggerKind);
+}
+
+/**
+ * How a template runs once created. A setup form states it as the keys of
+ * `setup.form.triggers`; an entry without one may state it as a top-level
+ * `triggers` list, read off the raw entry because the pinned package may
+ * predate the field. Empty when the catalog says nothing, so the card shows
+ * no badge and only a trigger filter leaves it out.
+ */
+export function getTemplateTriggerKinds(
+ automation: RecommendedAutomation,
+): TemplateTriggerKind[] {
+ const formTriggers = automation.setup?.form.triggers;
+ if (formTriggers) {
+ return Object.keys(formTriggers).filter(isTemplateTriggerKind);
+ }
+ const { triggers } = automation as unknown as Record<string, unknown>;
+ return Array.isArray(triggers) ? triggers.filter(isTemplateTriggerKind) : [];
+}
+
/**
* Catalog entries an OpenHands Enterprise install does not offer: each one
* overlaps a built-in integration, depends on a user-managed secret, or is