fix: scope useWorkspace to panel and add FLY_TOKEN env fallbacks

This commit is contained in:
nandi committed 2026-11-18 16:39:17 -08:00
1 parent b8f5b77931
commit d399919690
3 files changed
+33 -16

No files matched your search

+15 -10
View File
@@ -2,7 +2,6 @@ import {
type PluginHostProps, type PluginHostProps,
useRpc, useRpc,
useSubscription, useSubscription,
useWorkspace,
} from "@getpaseo/plugin/client"; } from "@getpaseo/plugin/client";
import { ScrollView, TextInput, copyText, useToast } from "@getpaseo/plugin/client/ui"; import { ScrollView, TextInput, copyText, useToast } from "@getpaseo/plugin/client/ui";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
@@ -25,11 +24,17 @@ import {
} from "../shared/contracts"; } from "../shared/contracts";
interface WorkersScreenProps extends PluginHostProps { interface WorkersScreenProps extends PluginHostProps {
workspaceId?: string; workspaceName?: string;
workspaceDirectory?: string;
} }
export function FlySpritesWorkersScreen({ theme, layout, host, workspaceId }: WorkersScreenProps) { export function FlySpritesWorkersScreen({
const workspace = useWorkspace(workspaceId ?? ""); theme,
layout,
host,
workspaceName,
workspaceDirectory,
}: WorkersScreenProps) {
const toast = useToast(); const toast = useToast();
const fetchStatus = useRpc(statusRpc); const fetchStatus = useRpc(statusRpc);
@@ -53,8 +58,8 @@ export function FlySpritesWorkersScreen({ theme, layout, host, workspaceId }: Wo
const [spriteNameInput, setSpriteNameInput] = useState(""); const [spriteNameInput, setSpriteNameInput] = useState("");
const [commandInput, setCommandInput] = useState(""); const [commandInput, setCommandInput] = useState("");
const [syncPathInput, setSyncPathInput] = useState(workspace?.directory ?? ""); const [syncPathInput, setSyncPathInput] = useState(workspaceDirectory ?? "");
const [syncBeforeSpawn, setSyncBeforeSpawn] = useState(Boolean(workspace?.directory)); const [syncBeforeSpawn, setSyncBeforeSpawn] = useState(Boolean(workspaceDirectory));
const [selectedWorkerId, setSelectedWorkerId] = useState<string | null>(null); const [selectedWorkerId, setSelectedWorkerId] = useState<string | null>(null);
const [fullLogs, setFullLogs] = useState<string>(""); const [fullLogs, setFullLogs] = useState<string>("");
@@ -62,11 +67,11 @@ export function FlySpritesWorkersScreen({ theme, layout, host, workspaceId }: Wo
const [checkpoints, setCheckpoints] = useState<CheckpointSummary[]>([]); const [checkpoints, setCheckpoints] = useState<CheckpointSummary[]>([]);
useEffect(() => { useEffect(() => {
if (workspace?.directory && !syncPathInput) { if (workspaceDirectory && !syncPathInput) {
setSyncPathInput(workspace.directory); setSyncPathInput(workspaceDirectory);
setSyncBeforeSpawn(true); setSyncBeforeSpawn(true);
} }
}, [workspace?.directory, syncPathInput]); }, [workspaceDirectory, syncPathInput]);
const watchInput = useMemo(() => ({}), []); const watchInput = useMemo(() => ({}), []);
useSubscription(watchWorkersSub, watchInput, (event) => { useSubscription(watchWorkersSub, watchInput, (event) => {
@@ -341,7 +346,7 @@ export function FlySpritesWorkersScreen({ theme, layout, host, workspaceId }: Wo
<Text style={styles.title}>Fly Sprites Workers</Text> <Text style={styles.title}>Fly Sprites Workers</Text>
<Text style={styles.muted}> <Text style={styles.muted}>
Host: {host.label} · Token: {tokenSource} Host: {host.label} · Token: {tokenSource}
{workspace ? ` · Workspace: ${workspace.name}` : ""} {workspaceName ? ` · Workspace: ${workspaceName}` : ""}
</Text> </Text>
</View> </View>
<Pressable style={styles.btnSecondary} onPress={() => void refresh()} disabled={loading}> <Pressable style={styles.btnSecondary} onPress={() => void refresh()} disabled={loading}>
+13 -5
View File
@@ -1,7 +1,8 @@
import type { import {
PluginClientContext, type PluginClientContext,
PluginSidebarItemProps, type PluginSidebarItemProps,
PluginWorkspacePanelProps, type PluginWorkspacePanelProps,
useWorkspace,
} from "@getpaseo/plugin/client"; } from "@getpaseo/plugin/client";
import { SidebarRow } from "@getpaseo/plugin/client/ui"; import { SidebarRow } from "@getpaseo/plugin/client/ui";
import { FlySpritesSettingsScreen } from "./client/settings-screen"; import { FlySpritesSettingsScreen } from "./client/settings-screen";
@@ -18,7 +19,14 @@ function WorkersSidebarItem({ currentScreen, openScreen }: PluginSidebarItemProp
} }
function WorkspaceWorkersPanel({ workspaceId, ...hostProps }: PluginWorkspacePanelProps) { function WorkspaceWorkersPanel({ workspaceId, ...hostProps }: PluginWorkspacePanelProps) {
return <FlySpritesWorkersScreen {...hostProps} workspaceId={workspaceId} />; const workspace = useWorkspace(workspaceId);
return (
<FlySpritesWorkersScreen
{...hostProps}
workspaceName={workspace?.name}
workspaceDirectory={workspace?.directory}
/>
);
} }
export default function contribute(client: PluginClientContext) { export default function contribute(client: PluginClientContext) {
+5 -1
View File
@@ -109,7 +109,11 @@ export class SpritesManager {
if (fromSettings) { if (fromSettings) {
return { token: fromSettings, source: "settings", baseUrl }; return { token: fromSettings, source: "settings", baseUrl };
} }
const fromEnv = process.env.SPRITES_TOKEN?.trim() ?? ""; const fromEnv =
process.env.SPRITES_TOKEN?.trim() ||
process.env.FLY_TOKEN?.trim() ||
process.env.FLY_API_TOKEN?.trim() ||
"";
if (fromEnv) { if (fromEnv) {
return { token: fromEnv, source: "env", baseUrl }; return { token: fromEnv, source: "env", baseUrl };
} }