ToolServersModal.svelte 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <script lang="ts">
  2. import { getContext, onMount } from 'svelte';
  3. import { models, config, toolServers, tools } from '$lib/stores';
  4. import { toast } from 'svelte-sonner';
  5. import { deleteSharedChatById, getChatById, shareChatById } from '$lib/apis/chats';
  6. import { copyToClipboard } from '$lib/utils';
  7. import Modal from '../common/Modal.svelte';
  8. import Link from '../icons/Link.svelte';
  9. import Collapsible from '../common/Collapsible.svelte';
  10. import XMark from '$lib/components/icons/XMark.svelte';
  11. export let show = false;
  12. export let selectedToolIds = [];
  13. let selectedTools = [];
  14. $: selectedTools = ($tools ?? []).filter((tool) => selectedToolIds.includes(tool.id));
  15. const i18n = getContext('i18n');
  16. </script>
  17. <Modal bind:show size="md">
  18. <div>
  19. <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-0.5">
  20. <div class=" text-lg font-medium self-center">{$i18n.t('Available Tools')}</div>
  21. <button
  22. class="self-center"
  23. on:click={() => {
  24. show = false;
  25. }}
  26. >
  27. <XMark className={'size-5'} />
  28. </button>
  29. </div>
  30. {#if selectedTools.length > 0}
  31. {#if $toolServers.length > 0}
  32. <div class=" flex justify-between dark:text-gray-300 px-5 pb-1">
  33. <div class=" text-base font-medium self-center">{$i18n.t('Tools')}</div>
  34. </div>
  35. {/if}
  36. <div class="px-5 pb-3 w-full flex flex-col justify-center">
  37. <div class=" text-sm dark:text-gray-300 mb-1">
  38. {#each selectedTools as tool}
  39. <Collapsible buttonClassName="w-full mb-0.5">
  40. <div class="truncate">
  41. <div class="text-sm font-medium dark:text-gray-100 text-gray-800 truncate">
  42. {tool?.name}
  43. </div>
  44. {#if tool?.meta?.description}
  45. <div class="text-xs text-gray-500">
  46. {tool?.meta?.description}
  47. </div>
  48. {/if}
  49. </div>
  50. <!-- <div slot="content">
  51. {JSON.stringify(tool, null, 2)}
  52. </div> -->
  53. </Collapsible>
  54. {/each}
  55. </div>
  56. </div>
  57. {/if}
  58. {#if $toolServers.length > 0}
  59. <div class=" flex justify-between dark:text-gray-300 px-5 pb-0.5">
  60. <div class=" text-base font-medium self-center">{$i18n.t('Tool Servers')}</div>
  61. </div>
  62. <div class="px-5 pb-5 w-full flex flex-col justify-center">
  63. <div class=" text-xs text-gray-600 dark:text-gray-300 mb-2">
  64. {$i18n.t('Open WebUI can use tools provided by any OpenAPI server.')} <br /><a
  65. class="underline"
  66. href="https://github.com/open-webui/openapi-servers"
  67. target="_blank">{$i18n.t('Learn more about OpenAPI tool servers.')}</a
  68. >
  69. </div>
  70. <div class=" text-sm dark:text-gray-300 mb-1">
  71. {#each $toolServers as toolServer}
  72. <Collapsible buttonClassName="w-full" chevron>
  73. <div>
  74. <div class="text-sm font-medium dark:text-gray-100 text-gray-800">
  75. {toolServer?.openapi?.info?.title} - v{toolServer?.openapi?.info?.version}
  76. </div>
  77. <div class="text-xs text-gray-500">
  78. {toolServer?.openapi?.info?.description}
  79. </div>
  80. <div class="text-xs text-gray-500">
  81. {toolServer?.url}
  82. </div>
  83. </div>
  84. <div slot="content">
  85. {#each toolServer?.specs ?? [] as tool_spec}
  86. <div class="my-1">
  87. <div class="font-medium text-gray-800 dark:text-gray-100">
  88. {tool_spec?.name}
  89. </div>
  90. <div>
  91. {tool_spec?.description}
  92. </div>
  93. </div>
  94. {/each}
  95. </div>
  96. </Collapsible>
  97. {/each}
  98. </div>
  99. </div>
  100. {/if}
  101. </div>
  102. </Modal>