fix: org switching
This commit is contained in:
parent
09439f3a39
commit
05006c00cd
2 changed files with 28 additions and 48 deletions
|
|
@ -199,8 +199,6 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
const { renderMessage } = useMessageRenderer();
|
||||
|
||||
const { handleOrganizationSelect } = useOrganizationSelector({
|
||||
configPath,
|
||||
onAssistantChange: () => {},
|
||||
onMessage: (message) => {
|
||||
setMessages((prev) => [...prev, message]);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,23 +1,11 @@
|
|||
import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
||||
import { BaseLlmApi } from "@continuedev/openai-adapters";
|
||||
|
||||
import {
|
||||
isAuthenticatedConfig,
|
||||
loadAuthConfig,
|
||||
saveAuthConfig,
|
||||
} from "../../auth/workos.js";
|
||||
import { initialize } from "../../config.js";
|
||||
import { MCPService } from "../../mcp.js";
|
||||
import { services, reloadService } from "../../services/index.js";
|
||||
import { SERVICE_NAMES } from "../../services/types.js";
|
||||
import { useNavigation } from "../context/NavigationContext.js";
|
||||
|
||||
interface UseOrganizationSelectorProps {
|
||||
configPath?: string;
|
||||
onAssistantChange: (
|
||||
assistant: AssistantUnrolled,
|
||||
model: ModelConfig,
|
||||
llmApi: BaseLlmApi,
|
||||
mcpService: MCPService
|
||||
) => void;
|
||||
onMessage: (message: {
|
||||
role: string;
|
||||
content: string;
|
||||
|
|
@ -27,8 +15,6 @@ interface UseOrganizationSelectorProps {
|
|||
}
|
||||
|
||||
export function useOrganizationSelector({
|
||||
configPath,
|
||||
onAssistantChange,
|
||||
onMessage,
|
||||
onChatReset,
|
||||
}: UseOrganizationSelectorProps) {
|
||||
|
|
@ -38,28 +24,29 @@ export function useOrganizationSelector({
|
|||
organizationId: string | null,
|
||||
organizationName: string
|
||||
) => {
|
||||
|
||||
// Update auth config
|
||||
const authConfig = loadAuthConfig();
|
||||
|
||||
// Only allow organization switching for authenticated users
|
||||
if (!isAuthenticatedConfig(authConfig)) {
|
||||
onMessage({
|
||||
role: "system",
|
||||
content:
|
||||
"Organization switching not available for environment variable auth",
|
||||
messageType: "system" as const,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedConfig = {
|
||||
...authConfig,
|
||||
organizationId,
|
||||
};
|
||||
saveAuthConfig(updatedConfig);
|
||||
|
||||
try {
|
||||
// Check if user is authenticated
|
||||
const authState = services.auth.getState();
|
||||
if (!authState.isAuthenticated || !authState.authConfig) {
|
||||
onMessage({
|
||||
role: "system",
|
||||
content:
|
||||
"Organization switching not available - not authenticated",
|
||||
messageType: "system" as const,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAuthenticatedConfig(authState.authConfig)) {
|
||||
onMessage({
|
||||
role: "system",
|
||||
content:
|
||||
"Organization switching not available for environment variable auth",
|
||||
messageType: "system" as const,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading message
|
||||
onMessage({
|
||||
role: "system",
|
||||
|
|
@ -67,16 +54,11 @@ export function useOrganizationSelector({
|
|||
messageType: "system" as const,
|
||||
});
|
||||
|
||||
// Reinitialize assistant with new organization
|
||||
const {
|
||||
config,
|
||||
llmApi: newLlmApi,
|
||||
model: newModel,
|
||||
mcpService: newMcpService,
|
||||
} = await initialize(updatedConfig, configPath);
|
||||
// Switch organization through the auth service
|
||||
await services.auth.switchOrganization(organizationId);
|
||||
|
||||
// Update assistant configuration
|
||||
onAssistantChange(config, newModel, newLlmApi, newMcpService);
|
||||
// Reload all dependent services (API_CLIENT -> CONFIG -> MODEL/MCP)
|
||||
await reloadService(SERVICE_NAMES.AUTH);
|
||||
|
||||
// Reset chat history
|
||||
onChatReset();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue