diff --git a/package-lock.json b/package-lock.json index 5f969e59d..93a3ec664 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "katex": "^0.16.9", "marked": "^9.1.0", "pyodide": "^0.26.0-alpha.4", + "sortablejs": "^1.15.2", "svelte-sonner": "^0.3.19", "tippy.js": "^6.3.7", "uuid": "^9.0.1" @@ -6913,6 +6914,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/sortablejs": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.15.2.tgz", + "integrity": "sha512-FJF5jgdfvoKn1MAKSdGs33bIqLi3LmsgVTliuX6iITj834F+JRQZN90Z93yql8h0K2t0RwDPBmxwlbZfDcxNZA==" + }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", diff --git a/package.json b/package.json index 3f5b5cb6d..b1a6ecd33 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "katex": "^0.16.9", "marked": "^9.1.0", "pyodide": "^0.26.0-alpha.4", + "sortablejs": "^1.15.2", "svelte-sonner": "^0.3.19", "tippy.js": "^6.3.7", "uuid": "^9.0.1" diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 63a0c21b9..f6b2de4d0 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -29,8 +29,24 @@ export const getModels = async (token: string = '') => { models = models .filter((models) => models) + // Sort the models .sort((a, b) => { - // Compare case-insensitively + // Check if models have position property + const aHasPosition = a.info?.meta?.position !== undefined; + const bHasPosition = b.info?.meta?.position !== undefined; + + // If both a and b have the position property + if (aHasPosition && bHasPosition) { + return a.info.meta.position - b.info.meta.position; + } + + // If only a has the position property, it should come first + if (aHasPosition) return -1; + + // If only b has the position property, it should come first + if (bHasPosition) return 1; + + // Compare case-insensitively by name for models without position property const lowerA = a.name.toLowerCase(); const lowerB = b.name.toLowerCase(); @@ -39,8 +55,8 @@ export const getModels = async (token: string = '') => { // If same case-insensitively, sort by original strings, // lowercase will come before uppercase due to ASCII values - if (a < b) return -1; - if (a > b) return 1; + if (a.name < b.name) return -1; + if (a.name > b.name) return 1; return 0; // They are equal }); diff --git a/src/lib/components/workspace/Models.svelte b/src/lib/components/workspace/Models.svelte index 8151df887..43f0cad67 100644 --- a/src/lib/components/workspace/Models.svelte +++ b/src/lib/components/workspace/Models.svelte @@ -1,9 +1,11 @@ @@ -202,12 +255,13 @@
-
- {#each $models.filter((m) => searchValue === '' || m.name +
+ {#each _models.filter((m) => searchValue === '' || m.name .toLowerCase() .includes(searchValue.toLowerCase())) as model}