mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-14 13:22:37 +00:00
* Extract client SDK package * Polish SDK client identity defaults * Build client before dependent CI jobs * Restore daemon client server export * Extract protocol and client SDK packages * Fix provider override schema validation * Fix app test daemon client imports * Simplify workspace build targets * Fix CLI test server build bootstrap * Run SDK package tests in CI * Fix rebase package split drift * Restore lockfile registry metadata * Update SDK config test for prompt default * Move terminal stream router test to client package * Fix rebase drift for protocol imports * Fix SDK agent capability fixture * Restore legacy server client exports * Fix server export compatibility test * Advertise custom mode icon client capability * Remove server daemon-client exports * Format rebased mode control import * Fix rebase drift for protocol imports Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split shared/ paths that this branch moves into @getpaseo/protocol. Redirect those imports to the protocol package so typecheck stays green after the rebase.
167 lines
4.7 KiB
TypeScript
167 lines
4.7 KiB
TypeScript
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useEffect } from "react";
|
|
import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
|
import type { CheckoutPrStatusResponse } from "@getpaseo/protocol/messages";
|
|
import { checkoutPrStatusQueryKey } from "@/git/query-keys";
|
|
|
|
interface UseCheckoutPrStatusQueryOptions {
|
|
serverId: string;
|
|
cwd: string;
|
|
enabled?: boolean;
|
|
}
|
|
|
|
export type CheckoutPrStatusPayload = CheckoutPrStatusResponse["payload"];
|
|
|
|
export interface PrHint {
|
|
url: string;
|
|
number: number;
|
|
state: "open" | "merged" | "closed";
|
|
checks?: Array<{ name: string; status: string; url: string | null }>;
|
|
checksStatus?: "none" | "pending" | "success" | "failure";
|
|
reviewDecision?: "approved" | "changes_requested" | "pending" | null;
|
|
}
|
|
|
|
interface PrStatusLike {
|
|
url: string;
|
|
state: string;
|
|
isMerged: boolean;
|
|
checks?: Array<{ name: string; status: string; url: string | null }>;
|
|
checksStatus?: string;
|
|
reviewDecision?: string | null;
|
|
}
|
|
|
|
function parsePullRequestNumber(url: string): number | null {
|
|
try {
|
|
const pathname = new URL(url).pathname;
|
|
const match = pathname.match(/\/pull\/(\d+)(?:\/|$)/);
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
|
|
const number = Number.parseInt(match[1], 10);
|
|
return Number.isFinite(number) ? number : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function selectPrHintFromStatus(status: PrStatusLike | null | undefined): PrHint | null {
|
|
if (!status?.url) {
|
|
return null;
|
|
}
|
|
|
|
const number = parsePullRequestNumber(status.url);
|
|
if (number === null) {
|
|
return null;
|
|
}
|
|
|
|
let state: "merged" | "open" | "closed";
|
|
if (status.isMerged || status.state === "merged") state = "merged";
|
|
else if (status.state === "open") state = "open";
|
|
else state = "closed";
|
|
|
|
return {
|
|
url: status.url,
|
|
number,
|
|
state,
|
|
checks: status.checks,
|
|
checksStatus: status.checksStatus as PrHint["checksStatus"],
|
|
reviewDecision: status.reviewDecision as PrHint["reviewDecision"],
|
|
};
|
|
}
|
|
|
|
function selectWorkspacePrHint(payload: CheckoutPrStatusPayload): PrHint | null {
|
|
return selectPrHintFromStatus(payload.status);
|
|
}
|
|
|
|
export function useCheckoutPrStatusQuery({
|
|
serverId,
|
|
cwd,
|
|
enabled = true,
|
|
}: UseCheckoutPrStatusQueryOptions) {
|
|
const queryClient = useQueryClient();
|
|
const client = useHostRuntimeClient(serverId);
|
|
const isConnected = useHostRuntimeIsConnected(serverId);
|
|
|
|
useEffect(() => {
|
|
if (!client || !isConnected || !cwd) {
|
|
return;
|
|
}
|
|
|
|
return client.on("checkout_status_update", (message) => {
|
|
const prStatus = message.payload.prStatus;
|
|
if (!prStatus || prStatus.cwd !== cwd) {
|
|
return;
|
|
}
|
|
queryClient.setQueryData(checkoutPrStatusQueryKey(serverId, cwd), prStatus);
|
|
});
|
|
}, [client, isConnected, cwd, queryClient, serverId]);
|
|
|
|
const query = useQuery({
|
|
queryKey: checkoutPrStatusQueryKey(serverId, cwd),
|
|
queryFn: async () => {
|
|
if (!client) {
|
|
throw new Error("Daemon client not available");
|
|
}
|
|
return await client.checkoutPrStatus(cwd);
|
|
},
|
|
enabled: !!client && isConnected && !!cwd && enabled,
|
|
staleTime: Infinity,
|
|
refetchOnMount: false,
|
|
refetchOnReconnect: false,
|
|
refetchOnWindowFocus: false,
|
|
});
|
|
|
|
return {
|
|
status: query.data?.status ?? null,
|
|
githubFeaturesEnabled: query.data?.githubFeaturesEnabled ?? true,
|
|
payloadError: query.data?.error ?? null,
|
|
isLoading: query.isLoading,
|
|
isFetching: query.isFetching,
|
|
isError: query.isError,
|
|
error: query.error,
|
|
};
|
|
}
|
|
|
|
export function useWorkspacePrHint({
|
|
serverId,
|
|
cwd,
|
|
enabled = true,
|
|
}: UseCheckoutPrStatusQueryOptions): PrHint | null {
|
|
const queryClient = useQueryClient();
|
|
const client = useHostRuntimeClient(serverId);
|
|
const isConnected = useHostRuntimeIsConnected(serverId);
|
|
|
|
useEffect(() => {
|
|
if (!client || !isConnected || !cwd) {
|
|
return;
|
|
}
|
|
|
|
return client.on("checkout_status_update", (message) => {
|
|
const prStatus = message.payload.prStatus;
|
|
if (!prStatus || prStatus.cwd !== cwd) {
|
|
return;
|
|
}
|
|
queryClient.setQueryData(checkoutPrStatusQueryKey(serverId, cwd), prStatus);
|
|
});
|
|
}, [client, isConnected, cwd, queryClient, serverId]);
|
|
|
|
const query = useQuery<CheckoutPrStatusPayload, Error, PrHint | null>({
|
|
queryKey: checkoutPrStatusQueryKey(serverId, cwd),
|
|
queryFn: async () => {
|
|
if (!client) {
|
|
throw new Error("Daemon client not available");
|
|
}
|
|
return await client.checkoutPrStatus(cwd);
|
|
},
|
|
enabled: !!client && isConnected && !!cwd && enabled,
|
|
staleTime: Infinity,
|
|
refetchOnMount: false,
|
|
refetchOnReconnect: false,
|
|
refetchOnWindowFocus: false,
|
|
select: selectWorkspacePrHint,
|
|
});
|
|
|
|
return query.data ?? null;
|
|
}
|