InputMenu.svelte 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <script lang="ts">
  2. import { DropdownMenu } from 'bits-ui';
  3. import { flyAndScale } from '$lib/utils/transitions';
  4. import { getContext } from 'svelte';
  5. import Dropdown from '$lib/components/common/Dropdown.svelte';
  6. import Tooltip from '$lib/components/common/Tooltip.svelte';
  7. import DocumentArrowUpSolid from '$lib/components/icons/DocumentArrowUpSolid.svelte';
  8. import Switch from '$lib/components/common/Switch.svelte';
  9. import GlobeAltSolid from '$lib/components/icons/GlobeAltSolid.svelte';
  10. import { config } from '$lib/stores';
  11. import WrenchSolid from '$lib/components/icons/WrenchSolid.svelte';
  12. const i18n = getContext('i18n');
  13. export let uploadFilesHandler: Function;
  14. export let selectedToolIds: string[] = [];
  15. export let webSearchEnabled: boolean;
  16. export let tools = {};
  17. export let onClose: Function;
  18. $: tools = Object.fromEntries(
  19. Object.keys(tools).map((toolId) => [
  20. toolId,
  21. {
  22. ...tools[toolId],
  23. enabled: selectedToolIds.includes(toolId)
  24. }
  25. ])
  26. );
  27. let show = false;
  28. </script>
  29. <Dropdown
  30. bind:show
  31. on:change={(e) => {
  32. if (e.detail === false) {
  33. onClose();
  34. }
  35. }}
  36. >
  37. <Tooltip content={$i18n.t('More')}>
  38. <slot />
  39. </Tooltip>
  40. <div slot="content">
  41. <DropdownMenu.Content
  42. class="w-full max-w-[200px] rounded-xl px-1 py-1 border-gray-300/30 dark:border-gray-700/50 z-50 bg-white dark:bg-gray-850 dark:text-white shadow"
  43. sideOffset={15}
  44. alignOffset={-8}
  45. side="top"
  46. align="start"
  47. transition={flyAndScale}
  48. >
  49. {#if Object.keys(tools).length > 0}
  50. <div class=" max-h-28 overflow-y-auto scrollbar-hidden">
  51. {#each Object.keys(tools) as toolId}
  52. <div
  53. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer rounded-xl"
  54. >
  55. <div class="flex-1">
  56. <Tooltip
  57. content={tools[toolId]?.description ?? ''}
  58. placement="top-start"
  59. className="flex flex-1 gap-2 items-center"
  60. >
  61. <WrenchSolid />
  62. <div class=" line-clamp-1">{tools[toolId].name}</div>
  63. </Tooltip>
  64. </div>
  65. <Switch
  66. bind:state={tools[toolId].enabled}
  67. on:change={(e) => {
  68. selectedToolIds = e.detail
  69. ? [...selectedToolIds, toolId]
  70. : selectedToolIds.filter((id) => id !== toolId);
  71. }}
  72. />
  73. </div>
  74. {/each}
  75. </div>
  76. <hr class="border-gray-100 dark:border-gray-800 my-1" />
  77. {/if}
  78. {#if $config?.features?.enable_web_search}
  79. <div
  80. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer rounded-xl"
  81. >
  82. <div class="flex-1 flex items-center gap-2">
  83. <GlobeAltSolid />
  84. <div class=" line-clamp-1">{$i18n.t('Web Search')}</div>
  85. </div>
  86. <Switch bind:state={webSearchEnabled} />
  87. </div>
  88. <hr class="border-gray-100 dark:border-gray-800 my-1" />
  89. {/if}
  90. <DropdownMenu.Item
  91. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
  92. on:click={() => {
  93. uploadFilesHandler();
  94. }}
  95. >
  96. <DocumentArrowUpSolid />
  97. <div class=" line-clamp-1">{$i18n.t('Upload Files')}</div>
  98. </DropdownMenu.Item>
  99. </DropdownMenu.Content>
  100. </div>
  101. </Dropdown>