publishAgent method

Future<void> publishAgent(
  1. bool isTest
)

Implementation

Future<void> publishAgent(bool isTest) async {
  wtLog.startSpinner('Fetching agent configuration...');
  final projectDirectory = PathUtils.currentPath;
  try {
    final pubSpecData = await PubspecParser.forPath(projectDirectory);

    final agentJson = await IsolateFunction.getAgentJson(projectDirectory);

    final agentId = pubSpecData.packageName;
    final agentDescription = pubSpecData.packageDescription;
    final agentVersion = pubSpecData.packageVersion;

    agentJson['name'] = agentId;
    agentJson['metadata']['description'] = agentDescription;
    agentJson['version'] = agentVersion;
    agentJson['testing'] = isTest;

    final metadata = agentJson['metadata'] as Map;
    final avatarPath = metadata['avatar_path'];
    if (avatarPath != null) {
      metadata['avatar'] = _fetchAvatar(avatarPath);
    }
    metadata.remove('avatar_path');

    wtLog.log('✔︎ Agent configuration fetched');
    wtLog.updateSpinnerMessage('Publishing agent...');
    final status = await _agentRepository.publishAgent(agentJson);

    wtLog.log('✔︎ Published agent');
    wtLog.stopSpinner();
    wtLog.info(status);
    return;
  } catch (error) {
    wtLog.stopSpinner();
    wtLog.error(error.toString());
    return;
  }
}