openSession method

  1. @override
Future<String> openSession(
  1. String instructions
)
override

Implementation

@override
Future<String> openSession(String instructions) async {
  if (instructions.trim().isEmpty) {
    throw AppleFoundationException(
      'Instructions cannot be empty',
      code: 'INVALID_INSTRUCTIONS',
    );
  }

  try {
    final String? sessionId = await _invokeMethodWithTimeout<String>(
      'openSession',
      {'instructions': instructions},
    );

    if (sessionId == null || sessionId.isEmpty) {
      throw AppleFoundationException(
        'Failed to create session - received empty session ID',
        code: 'SESSION_CREATION_FAILED',
      );
    }

    return sessionId;
  } catch (e) {
    _logError('openSession', e);
    throw AppleFoundationException(
      'Failed to open session: ${e.toString()}',
      code: 'OPEN_SESSION_FAILED',
      details: {'instructions': instructions},
    );
  }
}