send method

Future<String> send(
  1. String prompt, {
  2. List<Attachment> attachments = const [],
  3. MessageDeliveryMode? mode,
})

Sends a message to the session. Returns the message ID.

Implementation

Future<String> send(
  String prompt, {
  List<Attachment> attachments = const [],
  MessageDeliveryMode? mode,
}) async {
  _ensureAlive();

  final params = <String, dynamic>{
    'sessionId': sessionId,
    'prompt': prompt,
    if (attachments.isNotEmpty)
      'attachments': attachments.map((a) => a.toJson()).toList(),
    if (mode != null) 'mode': mode.toJsonValue(),
  };

  final result = await _connection.sendRequest(
    'session.send',
    params,
    const Duration(seconds: 30),
  ) as Map<String, dynamic>;

  return result['messageId'] as String;
}