SessionContext.fromJson constructor

SessionContext.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory SessionContext.fromJson(Map<String, dynamic> json) {
  final sources = <SessionContextSource>[];
  for (final s in (json['sources'] as List?) ?? []) {
    final src = s as Map<String, dynamic>;
    if (src['type'] == 'git_repository') {
      sources.add(GitSource.fromJson(src));
    } else if (src['type'] == 'knowledge_base') {
      sources.add(KnowledgeBaseSource.fromJson(src));
    }
  }
  final outcomes = <GitRepositoryOutcome>[];
  for (final o in (json['outcomes'] as List?) ?? []) {
    final out = o as Map<String, dynamic>;
    if (out['type'] == 'git_repository') {
      outcomes.add(GitRepositoryOutcome.fromJson(out));
    }
  }
  return SessionContext(
    sources: sources,
    cwd: json['cwd'] as String? ?? '/home/user',
    outcomes: outcomes.isEmpty ? null : outcomes,
    customSystemPrompt: json['custom_system_prompt'] as String?,
    appendSystemPrompt: json['append_system_prompt'] as String?,
    model: json['model'] as String?,
    seedBundleFileId: json['seed_bundle_file_id'] as String?,
  );
}