connect method

Future<LiveSession> connect({
  1. SessionResumptionConfig? sessionResumption,
})

Establishes a connection to a live generation service.

This function handles the WebSocket connection setup and returns an LiveSession object that can be used to communicate with the service. sessionResumption (optional): The configuration for session resumption, such as the handle to the previous session state to restore.

Returns a Future that resolves to an LiveSession object upon successful connection.

Implementation

Future<LiveSession> connect(
    {SessionResumptionConfig? sessionResumption}) async {
  final uri = _useAgentPlatform ? _agentPlatformUri() : _googleAIUri();
  final modelString = _useAgentPlatform
      ? _agentPlatformModelString()
      : _googleAIModelString();

  final headers = await BaseModel.firebaseTokens(
    _appCheck,
    _auth,
    _app,
    _useLimitedUseAppCheckTokens,
  )();

  return LiveSession.create(
    uri: uri,
    headers: headers,
    modelString: modelString,
    systemInstruction: _systemInstruction,
    tools: _tools,
    sessionResumption: sessionResumption,
    liveGenerationConfig: _liveGenerationConfig,
  );
}