PlaygroundController constructor

PlaygroundController({
  1. LlmConfig? initialLlmConfig,
  2. List<LlmConfig>? initialLlmConfigs,
  3. List<McpServerConfig>? initialServers,
  4. List<McpLocalTool>? customLocalTools,
  5. McpPlaygroundStorageDelegate? storageDelegate,
  6. bool enableLogging = false,
  7. bool progressiveMcpDiscovery = false,
  8. String toolDeliveryStrategy = 'auto',
  9. bool injectToolCallingRules = true,
  10. String toolFilteringLlmSource = 'llm1',
  11. List<SystemPromptTemplate>? systemPromptTemplates,
  12. bool showSystemPromptTemplates = true,
})

Creates a new PlaygroundController instance.

Implementation

PlaygroundController({
  LlmConfig? initialLlmConfig,
  List<LlmConfig>? initialLlmConfigs,
  List<McpServerConfig>? initialServers,
  List<McpLocalTool>? customLocalTools,
  McpPlaygroundStorageDelegate? storageDelegate,
  this.enableLogging = false,
  bool progressiveMcpDiscovery = false,
  String toolDeliveryStrategy = 'auto',
  this._injectToolCallingRules = true,
  this._toolFilteringLlmSource = 'llm1',
  this.systemPromptTemplates,
  this.showSystemPromptTemplates = true,
}) : _llmConfig = _sanitizeInitialLlmConfig(
       (initialLlmConfigs != null && initialLlmConfigs.isNotEmpty)
           ? initialLlmConfigs.first
           : initialLlmConfig,
     ),
     _toolDeliveryStrategy = toolDeliveryStrategy,
     // ignore: prefer_initializing_formals
     _progressiveMcpDiscovery =
         progressiveMcpDiscovery || toolDeliveryStrategy == 'progressive',
     _storage = storageDelegate ?? SharedPreferencesStorageDelegate() {
  if (initialLlmConfigs != null) {
    for (final c in initialLlmConfigs) {
      final sanitized = _sanitizeInitialLlmConfig(c);
      _llmConfigs.add(sanitized);
    }
    if (_llmConfigs.isNotEmpty) {
      _selectedLlmId = _llmConfigs.first.profileId;
      _llmConfig = _llmConfigs.first;
    }
  } else if (initialLlmConfig != null) {
    final sanitized = _sanitizeInitialLlmConfig(initialLlmConfig);
    if (sanitized.isConfigured ||
        sanitized.model.isNotEmpty ||
        sanitized.provider != LlmProvider.none) {
      _llmConfigs.add(sanitized);
      _selectedLlmId = sanitized.profileId;
    }
  }
  if (initialServers != null) {
    _servers.addAll(initialServers);
  }
  // Register custom local tools (if any) passed via constructor
  if (customLocalTools != null) {
    _localTools.addAll(customLocalTools);
  }
  _registerEmbeddedLlmHandlers();
  GenerateImageTool.imageGenConfigProvider = () => _imageGenConfig;
  GenerateImageTool.activeConfigProvider = () => _llmConfig;
  GenerateImageTool.configuredProfilesProvider = () => List.unmodifiable(_llmConfigs);
  _mcpManager.addListener(notifyListeners);
  _initAndLoad();
  _loadImageGenConfig();
}