ModelEditor.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <script lang="ts">
  2. import { onMount, getContext, tick } from 'svelte';
  3. import { models, tools, functions, knowledge as knowledgeCollections, user } from '$lib/stores';
  4. import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
  5. import Tags from '$lib/components/common/Tags.svelte';
  6. import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
  7. import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
  8. import FiltersSelector from '$lib/components/workspace/Models/FiltersSelector.svelte';
  9. import ActionsSelector from '$lib/components/workspace/Models/ActionsSelector.svelte';
  10. import Capabilities from '$lib/components/workspace/Models/Capabilities.svelte';
  11. import Textarea from '$lib/components/common/Textarea.svelte';
  12. import { getTools } from '$lib/apis/tools';
  13. import { getFunctions } from '$lib/apis/functions';
  14. import { getKnowledgeBases } from '$lib/apis/knowledge';
  15. import AccessControl from '../common/AccessControl.svelte';
  16. import { stringify } from 'postcss';
  17. const i18n = getContext('i18n');
  18. export let onSubmit: Function;
  19. export let onBack: null | Function = null;
  20. export let model = null;
  21. export let edit = false;
  22. export let preset = true;
  23. let loading = false;
  24. let success = false;
  25. let filesInputElement;
  26. let inputFiles;
  27. let showAdvanced = false;
  28. let showPreview = false;
  29. let loaded = false;
  30. // ///////////
  31. // model
  32. // ///////////
  33. let id = '';
  34. let name = '';
  35. $: if (!edit) {
  36. if (name) {
  37. id = name
  38. .replace(/\s+/g, '-')
  39. .replace(/[^a-zA-Z0-9-]/g, '')
  40. .toLowerCase();
  41. }
  42. }
  43. let info = {
  44. id: '',
  45. base_model_id: null,
  46. name: '',
  47. meta: {
  48. profile_image_url: '/static/favicon.png',
  49. description: '',
  50. suggestion_prompts: null,
  51. tags: []
  52. },
  53. params: {
  54. system: ''
  55. }
  56. };
  57. let params = {};
  58. let capabilities = {
  59. vision: true,
  60. usage: undefined,
  61. citations: true
  62. };
  63. let knowledge = [];
  64. let toolIds = [];
  65. let filterIds = [];
  66. let actionIds = [];
  67. let accessControl = {};
  68. const addUsage = (base_model_id) => {
  69. const baseModel = $models.find((m) => m.id === base_model_id);
  70. if (baseModel) {
  71. if (baseModel.owned_by === 'openai') {
  72. capabilities.usage = baseModel?.meta?.capabilities?.usage ?? false;
  73. } else {
  74. delete capabilities.usage;
  75. }
  76. capabilities = capabilities;
  77. }
  78. };
  79. const submitHandler = async () => {
  80. loading = true;
  81. info.id = id;
  82. info.name = name;
  83. info.access_control = accessControl;
  84. info.meta.capabilities = capabilities;
  85. if (knowledge.length > 0) {
  86. info.meta.knowledge = knowledge;
  87. } else {
  88. if (info.meta.knowledge) {
  89. delete info.meta.knowledge;
  90. }
  91. }
  92. if (toolIds.length > 0) {
  93. info.meta.toolIds = toolIds;
  94. } else {
  95. if (info.meta.toolIds) {
  96. delete info.meta.toolIds;
  97. }
  98. }
  99. if (filterIds.length > 0) {
  100. info.meta.filterIds = filterIds;
  101. } else {
  102. if (info.meta.filterIds) {
  103. delete info.meta.filterIds;
  104. }
  105. }
  106. if (actionIds.length > 0) {
  107. info.meta.actionIds = actionIds;
  108. } else {
  109. if (info.meta.actionIds) {
  110. delete info.meta.actionIds;
  111. }
  112. }
  113. info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
  114. Object.keys(info.params).forEach((key) => {
  115. if (info.params[key] === '' || info.params[key] === null) {
  116. delete info.params[key];
  117. }
  118. });
  119. await onSubmit(info);
  120. loading = false;
  121. success = false;
  122. };
  123. onMount(async () => {
  124. await tools.set(await getTools(localStorage.token));
  125. await functions.set(await getFunctions(localStorage.token));
  126. await knowledgeCollections.set(await getKnowledgeBases(localStorage.token));
  127. // Scroll to top 'workspace-container' element
  128. const workspaceContainer = document.getElementById('workspace-container');
  129. if (workspaceContainer) {
  130. workspaceContainer.scrollTop = 0;
  131. }
  132. if (model) {
  133. console.log(model);
  134. name = model.name;
  135. await tick();
  136. id = model.id;
  137. if (model.base_model_id) {
  138. const base_model = $models
  139. .filter((m) => !m?.preset && !(m?.arena ?? false))
  140. .find((m) => [model.base_model_id, `${model.base_model_id}:latest`].includes(m.id));
  141. console.log('base_model', base_model);
  142. if (base_model) {
  143. model.base_model_id = base_model.id;
  144. } else {
  145. model.base_model_id = null;
  146. }
  147. }
  148. params = { ...params, ...model?.params };
  149. params.stop = params?.stop
  150. ? (typeof params.stop === 'string' ? params.stop.split(',') : (params?.stop ?? [])).join(
  151. ','
  152. )
  153. : null;
  154. toolIds = model?.meta?.toolIds ?? [];
  155. filterIds = model?.meta?.filterIds ?? [];
  156. actionIds = model?.meta?.actionIds ?? [];
  157. knowledge = (model?.meta?.knowledge ?? []).map((item) => {
  158. if (item?.collection_name) {
  159. return {
  160. id: item.collection_name,
  161. name: item.name,
  162. legacy: true
  163. };
  164. } else if (item?.collection_names) {
  165. return {
  166. name: item.name,
  167. type: 'collection',
  168. collection_names: item.collection_names,
  169. legacy: true
  170. };
  171. } else {
  172. return item;
  173. }
  174. });
  175. capabilities = { ...capabilities, ...(model?.meta?.capabilities ?? {}) };
  176. if ('access_control' in model) {
  177. accessControl = model.access_control;
  178. } else {
  179. accessControl = {};
  180. }
  181. console.log(model?.access_control);
  182. console.log(accessControl);
  183. info = {
  184. ...info,
  185. ...JSON.parse(
  186. JSON.stringify(
  187. model
  188. ? model
  189. : {
  190. id: model.id,
  191. name: model.name
  192. }
  193. )
  194. )
  195. };
  196. console.log(model);
  197. }
  198. loaded = true;
  199. });
  200. </script>
  201. {#if loaded}
  202. {#if onBack}
  203. <button
  204. class="flex space-x-1"
  205. on:click={() => {
  206. onBack();
  207. }}
  208. >
  209. <div class=" self-center">
  210. <svg
  211. xmlns="http://www.w3.org/2000/svg"
  212. viewBox="0 0 20 20"
  213. fill="currentColor"
  214. class="h-4 w-4"
  215. >
  216. <path
  217. fill-rule="evenodd"
  218. d="M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z"
  219. clip-rule="evenodd"
  220. />
  221. </svg>
  222. </div>
  223. <div class=" self-center text-sm font-medium">{'Back'}</div>
  224. </button>
  225. {/if}
  226. <div class="w-full max-h-full flex justify-center">
  227. <input
  228. bind:this={filesInputElement}
  229. bind:files={inputFiles}
  230. type="file"
  231. hidden
  232. accept="image/*"
  233. on:change={() => {
  234. let reader = new FileReader();
  235. reader.onload = (event) => {
  236. let originalImageUrl = `${event.target.result}`;
  237. const img = new Image();
  238. img.src = originalImageUrl;
  239. img.onload = function () {
  240. const canvas = document.createElement('canvas');
  241. const ctx = canvas.getContext('2d');
  242. // Calculate the aspect ratio of the image
  243. const aspectRatio = img.width / img.height;
  244. // Calculate the new width and height to fit within 100x100
  245. let newWidth, newHeight;
  246. if (aspectRatio > 1) {
  247. newWidth = 250 * aspectRatio;
  248. newHeight = 250;
  249. } else {
  250. newWidth = 250;
  251. newHeight = 250 / aspectRatio;
  252. }
  253. // Set the canvas size
  254. canvas.width = 250;
  255. canvas.height = 250;
  256. // Calculate the position to center the image
  257. const offsetX = (250 - newWidth) / 2;
  258. const offsetY = (250 - newHeight) / 2;
  259. // Draw the image on the canvas
  260. ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight);
  261. // Get the base64 representation of the compressed image
  262. const compressedSrc = canvas.toDataURL();
  263. // Display the compressed image
  264. info.meta.profile_image_url = compressedSrc;
  265. inputFiles = null;
  266. };
  267. };
  268. if (
  269. inputFiles &&
  270. inputFiles.length > 0 &&
  271. ['image/gif', 'image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'].includes(
  272. inputFiles[0]['type']
  273. )
  274. ) {
  275. reader.readAsDataURL(inputFiles[0]);
  276. } else {
  277. console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`);
  278. inputFiles = null;
  279. }
  280. }}
  281. />
  282. {#if !edit || (edit && model)}
  283. <form
  284. class="flex flex-col md:flex-row w-full gap-3 md:gap-6"
  285. on:submit|preventDefault={() => {
  286. submitHandler();
  287. }}
  288. >
  289. <div class="self-center md:self-start flex justify-center my-2 flex-shrink-0">
  290. <div class="self-center">
  291. <button
  292. class="rounded-2xl flex flex-shrink-0 items-center {info.meta.profile_image_url !==
  293. '/static/favicon.png'
  294. ? 'bg-transparent'
  295. : 'bg-white'} shadow-xl group relative"
  296. type="button"
  297. on:click={() => {
  298. filesInputElement.click();
  299. }}
  300. >
  301. {#if info.meta.profile_image_url}
  302. <img
  303. src={info.meta.profile_image_url}
  304. alt="model profile"
  305. class="rounded-lg size-72 md:size-60 object-cover shrink-0"
  306. />
  307. {:else}
  308. <img
  309. src="/static/favicon.png"
  310. alt="model profile"
  311. class=" rounded-lg size-72 md:size-60 object-cover shrink-0"
  312. />
  313. {/if}
  314. <div class="absolute bottom-0 right-0 z-10">
  315. <div class="m-1.5">
  316. <div
  317. class="shadow-xl p-1 rounded-full border-2 border-white bg-gray-800 text-white group-hover:bg-gray-600 transition dark:border-black dark:bg-white dark:group-hover:bg-gray-200 dark:text-black"
  318. >
  319. <svg
  320. xmlns="http://www.w3.org/2000/svg"
  321. viewBox="0 0 16 16"
  322. fill="currentColor"
  323. class="size-5"
  324. >
  325. <path
  326. fill-rule="evenodd"
  327. d="M2 4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4Zm10.5 5.707a.5.5 0 0 0-.146-.353l-1-1a.5.5 0 0 0-.708 0L9.354 9.646a.5.5 0 0 1-.708 0L6.354 7.354a.5.5 0 0 0-.708 0l-2 2a.5.5 0 0 0-.146.353V12a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5V9.707ZM12 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
  328. clip-rule="evenodd"
  329. />
  330. </svg>
  331. </div>
  332. </div>
  333. </div>
  334. <div
  335. class="absolute top-0 bottom-0 left-0 right-0 bg-white dark:bg-black rounded-lg opacity-0 group-hover:opacity-20 transition"
  336. ></div>
  337. </button>
  338. </div>
  339. </div>
  340. <div class="w-full">
  341. <div class="mt-2 my-2 flex flex-col">
  342. <div class="flex-1">
  343. <div>
  344. <input
  345. class="text-3xl font-semibold w-full bg-transparent outline-none"
  346. placeholder={$i18n.t('Model Name')}
  347. bind:value={name}
  348. required
  349. />
  350. </div>
  351. </div>
  352. <div class="flex-1">
  353. <!-- <div class=" text-sm font-semibold">{$i18n.t('Model ID')}*</div> -->
  354. <div>
  355. <input
  356. class="text-xs w-full bg-transparent text-gray-500 outline-none"
  357. placeholder={$i18n.t('Model ID')}
  358. value={id}
  359. disabled={edit}
  360. required
  361. />
  362. </div>
  363. </div>
  364. </div>
  365. {#if preset}
  366. <div class="my-1">
  367. <div class=" text-sm font-semibold mb-1">{$i18n.t('Base Model (From)')}</div>
  368. <div>
  369. <select
  370. class="text-sm w-full bg-transparent outline-none"
  371. placeholder="Select a base model (e.g. llama3, gpt-4o)"
  372. bind:value={info.base_model_id}
  373. on:change={(e) => {
  374. addUsage(e.target.value);
  375. }}
  376. required
  377. >
  378. <option value={null} class=" text-gray-900"
  379. >{$i18n.t('Select a base model')}</option
  380. >
  381. {#each $models.filter((m) => (model ? m.id !== model.id : true) && !m?.preset && m?.owned_by !== 'arena') as model}
  382. <option value={model.id} class=" text-gray-900">{model.name}</option>
  383. {/each}
  384. </select>
  385. </div>
  386. </div>
  387. {/if}
  388. <div class="my-1">
  389. <div class="mb-1 flex w-full justify-between items-center">
  390. <div class=" self-center text-sm font-semibold">{$i18n.t('Description')}</div>
  391. <button
  392. class="p-1 text-xs flex rounded transition"
  393. type="button"
  394. on:click={() => {
  395. if (info.meta.description === null) {
  396. info.meta.description = '';
  397. } else {
  398. info.meta.description = null;
  399. }
  400. }}
  401. >
  402. {#if info.meta.description === null}
  403. <span class="ml-2 self-center">{$i18n.t('Default')}</span>
  404. {:else}
  405. <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
  406. {/if}
  407. </button>
  408. </div>
  409. {#if info.meta.description !== null}
  410. <Textarea
  411. className=" text-sm w-full bg-transparent outline-none resize-none overflow-y-hidden "
  412. placeholder={$i18n.t('Add a short description about what this model does')}
  413. rows={3}
  414. bind:value={info.meta.description}
  415. />
  416. {/if}
  417. </div>
  418. <div class="my-1">
  419. <div class="">
  420. <Tags
  421. tags={info?.meta?.tags ?? []}
  422. on:delete={(e) => {
  423. const tagName = e.detail;
  424. info.meta.tags = info.meta.tags.filter((tag) => tag.name !== tagName);
  425. }}
  426. on:add={(e) => {
  427. const tagName = e.detail;
  428. if (!(info?.meta?.tags ?? null)) {
  429. info.meta.tags = [{ name: tagName }];
  430. } else {
  431. info.meta.tags = [...info.meta.tags, { name: tagName }];
  432. }
  433. }}
  434. />
  435. </div>
  436. </div>
  437. <div class="my-2">
  438. <div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
  439. <AccessControl bind:accessControl />
  440. </div>
  441. </div>
  442. <hr class=" border-gray-50 dark:border-gray-850 my-1.5" />
  443. <div class="my-2">
  444. <div class="flex w-full justify-between">
  445. <div class=" self-center text-sm font-semibold">{$i18n.t('Model Params')}</div>
  446. </div>
  447. <div class="mt-2">
  448. <div class="my-1">
  449. <div class=" text-xs font-semibold mb-2">{$i18n.t('System Prompt')}</div>
  450. <div>
  451. <Textarea
  452. className=" text-sm w-full bg-transparent outline-none resize-none overflow-y-hidden "
  453. placeholder={`Write your model system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.`}
  454. rows={4}
  455. bind:value={info.params.system}
  456. />
  457. </div>
  458. </div>
  459. <div class="flex w-full justify-between">
  460. <div class=" self-center text-xs font-semibold">
  461. {$i18n.t('Advanced Params')}
  462. </div>
  463. <button
  464. class="p-1 px-3 text-xs flex rounded transition"
  465. type="button"
  466. on:click={() => {
  467. showAdvanced = !showAdvanced;
  468. }}
  469. >
  470. {#if showAdvanced}
  471. <span class="ml-2 self-center">{$i18n.t('Hide')}</span>
  472. {:else}
  473. <span class="ml-2 self-center">{$i18n.t('Show')}</span>
  474. {/if}
  475. </button>
  476. </div>
  477. {#if showAdvanced}
  478. <div class="my-2">
  479. <AdvancedParams
  480. admin={true}
  481. bind:params
  482. on:change={(e) => {
  483. info.params = { ...info.params, ...params };
  484. }}
  485. />
  486. </div>
  487. {/if}
  488. </div>
  489. </div>
  490. <hr class=" border-gray-50 dark:border-gray-850 my-1" />
  491. <div class="my-2">
  492. <div class="flex w-full justify-between items-center">
  493. <div class="flex w-full justify-between items-center">
  494. <div class=" self-center text-sm font-semibold">
  495. {$i18n.t('Prompt suggestions')}
  496. </div>
  497. <button
  498. class="p-1 text-xs flex rounded transition"
  499. type="button"
  500. on:click={() => {
  501. if ((info?.meta?.suggestion_prompts ?? null) === null) {
  502. info.meta.suggestion_prompts = [{ content: '' }];
  503. } else {
  504. info.meta.suggestion_prompts = null;
  505. }
  506. }}
  507. >
  508. {#if (info?.meta?.suggestion_prompts ?? null) === null}
  509. <span class="ml-2 self-center">{$i18n.t('Default')}</span>
  510. {:else}
  511. <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
  512. {/if}
  513. </button>
  514. </div>
  515. {#if (info?.meta?.suggestion_prompts ?? null) !== null}
  516. <button
  517. class="p-1 px-2 text-xs flex rounded transition"
  518. type="button"
  519. on:click={() => {
  520. if (
  521. info.meta.suggestion_prompts.length === 0 ||
  522. info.meta.suggestion_prompts.at(-1).content !== ''
  523. ) {
  524. info.meta.suggestion_prompts = [
  525. ...info.meta.suggestion_prompts,
  526. { content: '' }
  527. ];
  528. }
  529. }}
  530. >
  531. <svg
  532. xmlns="http://www.w3.org/2000/svg"
  533. viewBox="0 0 20 20"
  534. fill="currentColor"
  535. class="w-4 h-4"
  536. >
  537. <path
  538. d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z"
  539. />
  540. </svg>
  541. </button>
  542. {/if}
  543. </div>
  544. {#if info?.meta?.suggestion_prompts}
  545. <div class="flex flex-col space-y-1 mt-1 mb-3">
  546. {#if info.meta.suggestion_prompts.length > 0}
  547. {#each info.meta.suggestion_prompts as prompt, promptIdx}
  548. <div class=" flex rounded-lg">
  549. <input
  550. class=" text-sm w-full bg-transparent outline-none border-r border-gray-50 dark:border-gray-850"
  551. placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
  552. bind:value={prompt.content}
  553. />
  554. <button
  555. class="px-2"
  556. type="button"
  557. on:click={() => {
  558. info.meta.suggestion_prompts.splice(promptIdx, 1);
  559. info.meta.suggestion_prompts = info.meta.suggestion_prompts;
  560. }}
  561. >
  562. <svg
  563. xmlns="http://www.w3.org/2000/svg"
  564. viewBox="0 0 20 20"
  565. fill="currentColor"
  566. class="w-4 h-4"
  567. >
  568. <path
  569. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  570. />
  571. </svg>
  572. </button>
  573. </div>
  574. {/each}
  575. {:else}
  576. <div class="text-xs text-center">No suggestion prompts</div>
  577. {/if}
  578. </div>
  579. {/if}
  580. </div>
  581. <hr class=" border-gray-50 dark:border-gray-850 my-1.5" />
  582. <div class="my-2">
  583. <Knowledge bind:selectedKnowledge={knowledge} collections={$knowledgeCollections} />
  584. </div>
  585. <div class="my-2">
  586. <ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
  587. </div>
  588. <div class="my-2">
  589. <FiltersSelector
  590. bind:selectedFilterIds={filterIds}
  591. filters={$functions.filter((func) => func.type === 'filter')}
  592. />
  593. </div>
  594. <div class="my-2">
  595. <ActionsSelector
  596. bind:selectedActionIds={actionIds}
  597. actions={$functions.filter((func) => func.type === 'action')}
  598. />
  599. </div>
  600. <div class="my-2">
  601. <Capabilities bind:capabilities />
  602. </div>
  603. <div class="my-2 text-gray-300 dark:text-gray-700">
  604. <div class="flex w-full justify-between mb-2">
  605. <div class=" self-center text-sm font-semibold">{$i18n.t('JSON Preview')}</div>
  606. <button
  607. class="p-1 px-3 text-xs flex rounded transition"
  608. type="button"
  609. on:click={() => {
  610. showPreview = !showPreview;
  611. }}
  612. >
  613. {#if showPreview}
  614. <span class="ml-2 self-center">{$i18n.t('Hide')}</span>
  615. {:else}
  616. <span class="ml-2 self-center">{$i18n.t('Show')}</span>
  617. {/if}
  618. </button>
  619. </div>
  620. {#if showPreview}
  621. <div>
  622. <textarea
  623. class="text-sm w-full bg-transparent outline-none resize-none"
  624. rows="10"
  625. value={JSON.stringify(info, null, 2)}
  626. disabled
  627. readonly
  628. />
  629. </div>
  630. {/if}
  631. </div>
  632. <div class="my-2 flex justify-end pb-20">
  633. <button
  634. class=" text-sm px-3 py-2 transition rounded-lg {loading
  635. ? ' cursor-not-allowed bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'
  636. : 'bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'} flex w-full justify-center"
  637. type="submit"
  638. disabled={loading}
  639. >
  640. <div class=" self-center font-medium">
  641. {#if edit}
  642. {$i18n.t('Save & Update')}
  643. {:else}
  644. {$i18n.t('Save & Create')}
  645. {/if}
  646. </div>
  647. {#if loading}
  648. <div class="ml-1.5 self-center">
  649. <svg
  650. class=" w-4 h-4"
  651. viewBox="0 0 24 24"
  652. fill="currentColor"
  653. xmlns="http://www.w3.org/2000/svg"
  654. ><style>
  655. .spinner_ajPY {
  656. transform-origin: center;
  657. animation: spinner_AtaB 0.75s infinite linear;
  658. }
  659. @keyframes spinner_AtaB {
  660. 100% {
  661. transform: rotate(360deg);
  662. }
  663. }
  664. </style><path
  665. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  666. opacity=".25"
  667. /><path
  668. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  669. class="spinner_ajPY"
  670. /></svg
  671. >
  672. </div>
  673. {/if}
  674. </button>
  675. </div>
  676. </div>
  677. </form>
  678. {/if}
  679. </div>
  680. {/if}