updateAgent method
Implementation
Future<void> updateAgent(Agent agent) async {
final url = Uri.parse('$baseUrl/saveHaivaAgentConfig?agent-id=${agent.id}');
final response = await http.post(
url,
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
},
body: json.encode({
// 'name': agent.name,
// 'description': agent.description,
// 'type': agent.type,
// 'agent_id': agent.id,
'agent_configs': {
'image': agent.agentConfigs?.image,
'display_name': agent.agentConfigs?.displayName,
'is_speech2text': agent.agentConfigs?.isSpeech2text,
'languages': agent.agentConfigs?.languages,
'colors': agent.agentConfigs?.colors ?? {},
'description': agent.agentConfigs?.description,
'voice_code': agent.agentConfigs?.voice_code,
'is_api': true,
},
// 'is_deployed': agent.isDeployed,
// 'is_active': agent.isActive,
// 'updated_at': DateTime.now().toUtc().toIso8601String(),
//'workspace_id': agent.workspaceId,
// 'org_id': agent.orgId,
}),
);
print("response update agent body = ${response.body}");
print("response update agent = ${response.statusCode}");
if (response.statusCode == 200 || response.statusCode == 201) {
print('Agent updated successfully');
} else {
// Handle error
throw Exception('Failed to update agent${response.body}');
}
}