diff --git a/package-lock.json b/package-lock.json index 8d9ea5edb..a6f5a948f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "posthog-node": "^5.6.0", "react": "^19.1.0", "readline-sync": "^1.4.10", + "swr": "^2.3.4", "turndown": "^7.2.0", "typescript": "^5.8.3", "uuid": "^9.0.1", @@ -17838,6 +17839,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swr": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.3.4.tgz", + "integrity": "sha512-bYd2lrhc+VarcpkgWclcUi92wYCpOgMws9Sd1hG1ntAu0NEy+14CbotuFjshBU2kt9rYj9TSmDcybpxpeTU1fg==", + "license": "MIT", + "dependencies": { + "dequal": "^2.0.3", + "use-sync-external-store": "^1.4.0" + }, + "peerDependencies": { + "react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", @@ -18537,6 +18551,15 @@ "node": "^12.20.0 || ^14.13.1 || >=16.0.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.5.0.tgz", + "integrity": "sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index f8f3bf564..30d89d27f 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "posthog-node": "^5.6.0", "react": "^19.1.0", "readline-sync": "^1.4.10", + "swr": "^2.3.4", "turndown": "^7.2.0", "typescript": "^5.8.3", "uuid": "^9.0.1", diff --git a/src/ui/FreeTrialTransitionUI.tsx b/src/ui/FreeTrialTransitionUI.tsx index 5ed0fb185..9aea9eedd 100644 --- a/src/ui/FreeTrialTransitionUI.tsx +++ b/src/ui/FreeTrialTransitionUI.tsx @@ -5,7 +5,9 @@ import * as path from "path"; import { Box, Text, useInput } from "ink"; import open from "open"; import React, { useState } from "react"; +import useSWR from "swr"; +import { listUserOrganizations } from "../auth/workos.js"; import { env } from "../env.js"; import { isValidAnthropicApiKey, getApiKeyValidationError } from "../util/apiKeyValidation.js"; import { updateAnthropicModelInYaml } from "../util/yamlConfigUpdater.js"; @@ -18,7 +20,6 @@ interface FreeTrialTransitionUIProps { onFullReload?: () => void; onShowConfigSelector?: () => void; onShowOrgSelector?: () => void; - hasOrganizations?: boolean; } /** @@ -45,7 +46,6 @@ const FreeTrialTransitionUI: React.FC = ({ onFullReload, onShowConfigSelector, onShowOrgSelector, - hasOrganizations = false, }) => { const [currentStep, setCurrentStep] = useState< "choice" | "enterApiKey" | "processing" | "success" | "error" @@ -55,6 +55,19 @@ const FreeTrialTransitionUI: React.FC = ({ const [errorMessage, setErrorMessage] = useState(""); const [successMessage, setSuccessMessage] = useState(""); const [wasModelsSetup, setWasModelsSetup] = useState(false); + + // Fetch organizations using SWR + const { data: organizations } = useSWR( + "organizations", + listUserOrganizations, + { + revalidateOnFocus: false, + revalidateOnReconnect: false, + shouldRetryOnError: false, + } + ); + + const hasOrganizations = organizations && organizations.length > 0; useInput((input, key) => { if (currentStep === "choice") { diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index b26d813d0..2c99fa6fc 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -378,7 +378,6 @@ const TUIChat: React.FC = ({ onFullReload={handleFreeTrialFullReload} onShowConfigSelector={handleFreeTrialShowConfigSelector} onShowOrgSelector={handleFreeTrialShowOrgSelector} - hasOrganizations={services?.auth?.hasOrganizations || false} /> )}