From 2dac0d330ca4e551e18126da4eeae0f06435a596 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Wed, 23 Sep 2026 17:40:23 +0800 Subject: [PATCH] refactor(linear): keep workspace API types inside channel --- nanobot/channels/linear/webui/LinearPanel.tsx | 13 ++++++----- nanobot/channels/linear/webui/api.ts | 10 +++++++++ nanobot/channels/linear/webui/types.ts | 17 ++++++++++++++ webui/src/lib/api.ts | 6 ++--- webui/src/lib/types.ts | 22 +------------------ 5 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 nanobot/channels/linear/webui/api.ts create mode 100644 nanobot/channels/linear/webui/types.ts diff --git a/nanobot/channels/linear/webui/LinearPanel.tsx b/nanobot/channels/linear/webui/LinearPanel.tsx index 15b66c53e..a9f4a8171 100644 --- a/nanobot/channels/linear/webui/LinearPanel.tsx +++ b/nanobot/channels/linear/webui/LinearPanel.tsx @@ -29,11 +29,12 @@ import { } from "@/components/ui/alert-dialog"; import { channelValidationStatusClass } from "@/components/settings/channels/ChannelValidationProgress"; import { useAutoSave } from "@/components/settings/shared/useAutoSave"; -import { configureChannel, disableNanobotFeature, startChannelConnect } from "@/lib/api"; -import type { ChannelInstallationSummary } from "@/lib/types"; +import { configureChannel, disableNanobotFeature } from "@/lib/api"; import { cn } from "@/lib/utils"; import { useClient } from "@/providers/ClientProvider"; +import { manageLinearWorkspace } from "./api"; +import type { LinearInstallationSummary } from "./types"; import { LinearConnectFlow } from "./LinearConnectFlow"; import { linearManifestUrl } from "./manifest"; @@ -75,7 +76,7 @@ export function LinearPanel({ const [notice, setNotice] = useState(null); const [saved, setSaved] = useState(false); const [publicUrlPromptOpen, setPublicUrlPromptOpen] = useState(false); - const [installations, setInstallations] = useState([]); + const [installations, setInstallations] = useState([]); const [loadingInstallations, setLoadingInstallations] = useState(false); const [disconnectingId, setDisconnectingId] = useState(null); const [disconnectConfirmId, setDisconnectConfirmId] = useState(null); @@ -122,7 +123,7 @@ export function LinearPanel({ setWorkspaceNotice(null); setWorkspaceError(null); try { - const payload = await startChannelConnect(client, "linear", { operation: "inspect" }); + const payload = await manageLinearWorkspace(client, { operation: "inspect" }); setInstallations(payload.installations ?? []); } catch (err) { setWorkspaceError((err as Error).message); @@ -135,12 +136,12 @@ export function LinearPanel({ if (feature.runtime_status === "running") void loadInstallations(); }, [feature.runtime_status, loadInstallations]); - const disconnectWorkspace = async (installation: ChannelInstallationSummary) => { + const disconnectWorkspace = async (installation: LinearInstallationSummary) => { setDisconnectingId(installation.organization_id); setWorkspaceNotice(null); setWorkspaceError(null); try { - const payload = await startChannelConnect(client, "linear", { + const payload = await manageLinearWorkspace(client, { operation: "disconnect", organization_id: installation.organization_id, }); diff --git a/nanobot/channels/linear/webui/api.ts b/nanobot/channels/linear/webui/api.ts new file mode 100644 index 000000000..c448cfe42 --- /dev/null +++ b/nanobot/channels/linear/webui/api.ts @@ -0,0 +1,10 @@ +import { startChannelConnect, type WebUIMutationTransport } from "@/lib/api"; + +import type { LinearWorkspacePayload } from "./types"; + +export function manageLinearWorkspace( + transport: WebUIMutationTransport, + params: { operation: "inspect" } | { operation: "disconnect"; organization_id: string }, +): Promise { + return startChannelConnect(transport, "linear", params); +} diff --git a/nanobot/channels/linear/webui/types.ts b/nanobot/channels/linear/webui/types.ts new file mode 100644 index 000000000..492bb9ad6 --- /dev/null +++ b/nanobot/channels/linear/webui/types.ts @@ -0,0 +1,17 @@ +export interface LinearInstallationSummary { + organization_id: string; + organization_name?: string; + scopes?: string[]; + authorization_status?: "authorized" | "refresh_required" | "missing_scopes"; + missing_scopes?: string[]; +} + +export interface LinearWorkspacePayload { + session_id: string; + status: "inspected" | "disconnected"; + message?: string; + organization_id?: string; + installations: LinearInstallationSummary[]; + webhook_url?: string; + redirect_uri?: string; +} diff --git a/webui/src/lib/api.ts b/webui/src/lib/api.ts index 6f136900e..eedb201f8 100644 --- a/webui/src/lib/api.ts +++ b/webui/src/lib/api.ts @@ -815,12 +815,12 @@ export async function runPairingAction( return mutation(transport, `settings.pairing.${action}`, { code }); } -export async function startChannelConnect( +export async function startChannelConnect( transport: WebUIMutationTransport, channel: string, params: Readonly> = {}, -): Promise { - return mutation( +): Promise { + return mutation( transport, "settings.channel.connect.start", { diff --git a/webui/src/lib/types.ts b/webui/src/lib/types.ts index 7266c126d..912f2725e 100644 --- a/webui/src/lib/types.ts +++ b/webui/src/lib/types.ts @@ -1212,22 +1212,7 @@ export interface McpPresetsPayload { }; } -type ChannelConnectStatus = - | "pending" - | "succeeded" - | "expired" - | "cancelled" - | "failed" - | "inspected" - | "disconnected"; - -export interface ChannelInstallationSummary { - organization_id: string; - organization_name?: string; - scopes?: string[]; - authorization_status?: "authorized" | "refresh_required" | "missing_scopes"; - missing_scopes?: string[]; -} +type ChannelConnectStatus = "pending" | "succeeded" | "expired" | "cancelled" | "failed"; export interface ChannelConnectPayload { session_id: string; @@ -1237,11 +1222,6 @@ export interface ChannelConnectPayload { qr_url?: string; interval_ms?: number; expires_at_ms?: number; - organization_id?: string; - organization_name?: string; - installations?: ChannelInstallationSummary[]; - webhook_url?: string; - redirect_uri?: string; nanobot_features?: NanobotFeaturesPayload; }