toJson method
Converts to JSON for the session.create RPC call.
Implementation
Map<String, dynamic> toJson() {
return {
if (sessionId != null) 'sessionId': sessionId,
if (clientName != null) 'clientName': clientName,
if (model != null) 'model': model,
if (systemMessage != null) 'systemMessage': systemMessage!.toJson(),
if (infiniteSessions != null)
'infiniteSessions': infiniteSessions!.toJson(),
'streaming': streaming,
if (tools.isNotEmpty)
'tools': tools.map((t) => t.toRegistrationJson()).toList(),
if (availableTools != null) 'availableTools': availableTools,
if (excludedTools != null) 'excludedTools': excludedTools,
if (mcpServers.isNotEmpty)
'mcpServers': mcpServers.map(
(key, value) => MapEntry(key, value.toJson()),
),
if (customAgents.isNotEmpty)
'customAgents': customAgents.map((a) => a.toJson()).toList(),
if (skillDirectories.isNotEmpty) 'skillDirectories': skillDirectories,
if (disabledSkills.isNotEmpty) 'disabledSkills': disabledSkills,
if (provider != null) 'provider': provider!.toJson(),
if (reasoningEffort != null)
'reasoningEffort': reasoningEffort!.toJsonValue(),
if (mode != null) 'mode': mode!.toJsonValue(),
if (attachments.isNotEmpty)
'attachments': attachments.map((a) => a.toJson()).toList(),
if (configDir != null) 'configDir': configDir,
if (workingDirectory != null) 'workingDirectory': workingDirectory,
// Capability flags — required for CLI to know we handle these.
'requestPermission': true,
'requestUserInput': onUserInputRequest != null,
'hooks': hooks?.hasHooks ?? false,
'envValueMode': 'direct',
};
}