resolveToolProtocol.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { ToolProtocol, TOOL_PROTOCOL } from "@roo-code/types"
  2. import type { ProviderSettings, ModelInfo } from "@roo-code/types"
  3. /**
  4. * Resolve the effective tool protocol based on the precedence hierarchy:
  5. *
  6. * 1. User Preference - Per-Profile (explicit profile setting)
  7. * 2. Model Default (defaultToolProtocol in ModelInfo)
  8. * 3. Native Fallback (final fallback)
  9. *
  10. * Then check support: if protocol is "native" but model doesn't support it, use XML.
  11. *
  12. * @param providerSettings - The provider settings for the current profile
  13. * @param modelInfo - Optional model information containing capabilities
  14. * @returns The resolved tool protocol (either "xml" or "native")
  15. */
  16. export function resolveToolProtocol(providerSettings: ProviderSettings, modelInfo?: ModelInfo): ToolProtocol {
  17. // If model doesn't support native tools, return XML immediately
  18. // Treat undefined as unsupported (only allow native when explicitly true)
  19. if (modelInfo?.supportsNativeTools !== true) {
  20. return TOOL_PROTOCOL.XML
  21. }
  22. // 1. User Preference - Per-Profile (explicit profile setting, highest priority)
  23. if (providerSettings.toolProtocol) {
  24. return providerSettings.toolProtocol
  25. }
  26. // 2. Model Default - model's preferred protocol
  27. if (modelInfo?.defaultToolProtocol) {
  28. return modelInfo.defaultToolProtocol
  29. }
  30. // 3. Native Fallback
  31. return TOOL_PROTOCOL.NATIVE
  32. }