Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * @internal |
| 3 | * This service is used to get the SDK realtime credentials. |
| 4 | * It is used to get the Pusher key and project ID for the SDK realtime credentials. |
| 5 | * These are the endpoints which are not exposed to the public via the client SDKs. |
| 6 | */ |
| 7 | import ComposioClitent from '@composio/client'; |
| 8 | import { |
| 9 | ComposioSDKRealtimeCredentialsResponse, |
| 10 | SDKRealtimeCredentialsResponse, |
| 11 | SDKRealtimeCredentialsResponseSchema, |
| 12 | } from './InternalService.types'; |
| 13 | import { ValidationError } from '../../errors'; |
| 14 | import logger from '../../utils/logger'; |
| 15 | const SDK_REALTIME_CREDENTIALS_ENDPOINT = '/api/v3/internal/sdk/realtime/credentials'; |
| 16 | |
| 17 | export class InternalService { |
| 18 | constructor(private readonly client: ComposioClitent) { |
| 19 | this.client = client; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Get the SDK realtime credentials |
| 24 | * @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials |
| 25 | */ |
| 26 | async getSDKRealtimeCredentials(): Promise<SDKRealtimeCredentialsResponse> { |
| 27 | const response = await this.client.get<ComposioSDKRealtimeCredentialsResponse>( |
| 28 | SDK_REALTIME_CREDENTIALS_ENDPOINT |
| 29 | ); |
| 30 | |
| 31 | const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({ |
| 32 | pusherKey: response.pusher_key, |
| 33 | projectId: response.project_id, |
| 34 | pusherCluster: response.pusher_cluster, |
| 35 | }); |
| 36 | |
| 37 | logger.debug( |
| 38 | `[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}` |
| 39 | ); |
| 40 | |
| 41 | if (!parsedResponse.success) { |
| 42 | throw new ValidationError(`Failed to parse SDK realtime credentials`, { |
| 43 | cause: parsedResponse.error, |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | return parsedResponse.data; |
| 48 | } |
| 49 | } |