buildSideQuestionFallbackParams function

Future<CacheSafeParams> buildSideQuestionFallbackParams({
  1. required List<Map<String, dynamic>> tools,
  2. required List<Map<String, dynamic>> commands,
  3. required List<Map<String, dynamic>> mcpClients,
  4. required List<Map<String, dynamic>> messages,
  5. required FileStateCache readFileState,
  6. required Map<String, dynamic> getAppState(),
  7. required void setAppState(
    1. void (
      1. Map<String, dynamic>
      )
    ),
  8. String? customSystemPrompt,
  9. String? appendSystemPrompt,
  10. Map<String, dynamic>? thinkingConfig,
  11. required List<Map<String, dynamic>> agents,
  12. required GetSystemPromptFn getSystemPrompt,
  13. required GetUserContextFn getUserContext,
  14. required GetSystemContextFn getSystemContext,
})

Build CacheSafeParams for a side question fallback.

Implementation

Future<CacheSafeParams> buildSideQuestionFallbackParams({
  required List<Map<String, dynamic>> tools,
  required List<Map<String, dynamic>> commands,
  required List<Map<String, dynamic>> mcpClients,
  required List<Map<String, dynamic>> messages,
  required FileStateCache readFileState,
  required Map<String, dynamic> Function() getAppState,
  required void Function(void Function(Map<String, dynamic>)) setAppState,
  String? customSystemPrompt,
  String? appendSystemPrompt,
  Map<String, dynamic>? thinkingConfig,
  required List<Map<String, dynamic>> agents,
  required GetSystemPromptFn getSystemPrompt,
  required GetUserContextFn getUserContext,
  required GetSystemContextFn getSystemContext,
}) async {
  final parts = await fetchSystemPromptParts(
    getSystemPrompt: getSystemPrompt,
    getUserContext: getUserContext,
    getSystemContext: getSystemContext,
    customSystemPrompt: customSystemPrompt,
  );

  final systemPrompt = <String>[
    if (customSystemPrompt != null)
      customSystemPrompt
    else
      ...parts.defaultSystemPrompt,
    ?appendSystemPrompt,
  ];

  // Strip in-progress assistant message.
  final last = messages.isNotEmpty ? messages.last : null;
  final forkContextMessages =
      (last != null &&
          last['type'] == 'assistant' &&
          last['message']?['stop_reason'] == null)
      ? messages.sublist(0, messages.length - 1)
      : messages;

  final toolUseContext = <String, dynamic>{
    'options': {
      'commands': commands,
      'debug': false,
      'tools': tools,
      'verbose': false,
      'thinkingConfig': thinkingConfig,
      'mcpClients': mcpClients,
      'isNonInteractiveSession': true,
      'agentDefinitions': {'activeAgents': agents, 'allAgents': []},
      'customSystemPrompt': customSystemPrompt,
      'appendSystemPrompt': appendSystemPrompt,
    },
    'readFileState': readFileState,
    'messages': forkContextMessages,
  };

  return CacheSafeParams(
    systemPrompt: systemPrompt,
    userContext: parts.userContext,
    systemContext: parts.systemContext,
    toolUseContext: toolUseContext,
    forkContextMessages: forkContextMessages,
  );
}