PlaygroundController constructor
PlaygroundController({
- LlmConfig? initialLlmConfig,
- List<
LlmConfig> ? initialLlmConfigs, - List<
McpServerConfig> ? initialServers, - List<
McpLocalTool> ? customLocalTools, - McpPlaygroundStorageDelegate? storageDelegate,
- bool enableLogging = false,
- bool progressiveMcpDiscovery = false,
- String toolDeliveryStrategy = 'auto',
- bool injectToolCallingRules = true,
- String toolFilteringLlmSource = 'llm1',
- List<
SystemPromptTemplate> ? systemPromptTemplates, - 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();
}