import { SessionManager } from '@stack-spot/auth-react' import { NetworkRequest } from '@stack-spot/portal-extension-commons' import { accountClient, agentClient, agentToolsClient, aiClient, apiManagementClient, cloudAccountClient, cloudPlatformClient, cloudRuntimesClient, codeShiftClient, contentClient, dataIntegrationClient, discoverClient, eventBusClient, genAiInferenceClient, insightsClient, notificationClient, runtimeManagerClient, secretsClient, workflowClient, workspaceAiClient, workspaceClient, workspaceManagerClient, workspaceSearchClient, } from '@stack-spot/portal-network' const clients: Record = { accountClient, agentToolsClient, agentClient, aiClient, apiManagementClient, cloudAccountClient, cloudPlatformClient, cloudRuntimesClient, codeShiftClient, contentClient, dataIntegrationClient, discoverClient, eventBusClient, genAiInferenceClient, insightsClient, notificationClient, runtimeManagerClient, secretsClient, workflowClient, workspaceAiClient, workspaceManagerClient, workspaceSearchClient, workspaceClient, } export function handleNetworkOperation({ arguments: args, client, method, resource }: NetworkRequest) { const fn = (...args: any[]) => clients[client]?.[resource]?.[method]?.(...args) if (!fn) throw new Error(`Invalid network request from extension: ${client}.${resource}.${method}.`) if (!SessionManager.instance?.hasSession()) { throw new Error("You can't make a request to the Stackspot API because you're not authenticated.") } return fn(...args) }