Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(keys): search a custom row's endpoint URL on the keys page (#1368)

tashdroidc57803a31693
diff --git a/client/src/components/keys/provider-list.tsx b/client/src/components/keys/provider-list.tsx
index 361572d0..64429775 100644
--- a/client/src/components/keys/provider-list.tsx
+++ b/client/src/components/keys/provider-list.tsx
@@ -22,6 +22,7 @@ import type { ApiKey, ApiKeyModel } from '../../../../shared/types'
import { formatSqliteUtcToLocalTime } from '@/lib/utils'
import { useI18n } from '@/i18n'
import { toast } from '@/lib/toast'
+import { keyMatchesQuery } from '@/lib/key-search'
import {
PLATFORMS,
CUSTOM_GROUP,
@@ -278,15 +279,15 @@ export function ProviderList({ onAddKey }: { onAddKey: () => void }) {
}
// Search narrows either whole groups (label match) or the keys within them
- // (label / masked-key match); the status filter then trims the result set.
+ // (label / masked-key / endpoint-URL match); the status filter then trims
+ // the result set. The baseUrl term is #1056's lesson applied here: a custom
+ // row renders "api.unorouter.com" on screen, so searching that host must
+ // find the row the same way the fallback table's search does.
const visibleGroups = grouped
.map(group => {
if (!q) return group
if (group.label.toLowerCase().includes(q)) return group
- const matchingKeys = group.keys.filter(k =>
- (k.label ?? '').toLowerCase().includes(q) ||
- (k.maskedKey ?? '').toLowerCase().includes(q),
- )
+ const matchingKeys = group.keys.filter(k => keyMatchesQuery(k, q))
return { ...group, keys: matchingKeys }
})
.filter(group => group.keys.length > 0 && matchStatus(group))
diff --git a/client/src/lib/key-search.test.ts b/client/src/lib/key-search.test.ts
new file mode 100644
index 00000000..521e8390
--- /dev/null
+++ b/client/src/lib/key-search.test.ts
@@ -0,0 +1,33 @@
+import { describe, expect, it } from 'vitest'
+import type { ApiKey } from '../../../shared/types'
+import { keyMatchesQuery } from './key-search'
+
+// The keys-page search box must be able to reach every string the row
+// renders. A custom endpoint row prints its baseUrl; before this the filter
+// only knew label and masked key, so searching a relay's host — the one
+// identifier visible for a keyless relay with no label — found nothing,
+// which is exactly what #1056 fixed for the fallback table.
+
+const key = (over: Partial<ApiKey> = {}) =>
+ ({ id: 1, platform: 'custom', label: null, maskedKey: '****abcd', baseUrl: 'https://api.unorouter.com/v1', ...over }) as ApiKey
+
+describe('keyMatchesQuery (#1056 applied to /keys)', () => {
+ it('matches the endpoint host the row displays', () => {
+ expect(keyMatchesQuery(key(), 'unorouter')).toBe(true)
+ expect(keyMatchesQuery(key(), 'API.UnoRouter.com')).toBe(true)
+ })
+
+ it('still matches the label and masked key', () => {
+ expect(keyMatchesQuery(key({ label: 'Work relay' }), 'work')).toBe(true)
+ expect(keyMatchesQuery(key(), 'abcd')).toBe(true)
+ })
+
+ it('misses an unrelated query', () => {
+ expect(keyMatchesQuery(key(), 'groq')).toBe(false)
+ })
+
+ it('tolerates a missing label and baseUrl', () => {
+ expect(() => keyMatchesQuery(key({ label: undefined, baseUrl: undefined }), 'groq')).not.toThrow()
+ expect(keyMatchesQuery(key({ label: undefined, baseUrl: undefined }), 'groq')).toBe(false)
+ })
+})
diff --git a/client/src/lib/key-search.ts b/client/src/lib/key-search.ts
new file mode 100644
index 00000000..740f9df1
--- /dev/null
+++ b/client/src/lib/key-search.ts
@@ -0,0 +1,16 @@
+import type { ApiKey } from '../../../shared/types'
+
+/** What the keys-page search box matches per row (#1056 applied to /keys).
+ * The row RENDERS the endpoint URL for custom rows, so the query must reach
+ * it: until now a relay at api.unorouter.com was invisible to a host search
+ * even though the fallback table had carried its endpoint in the hay since
+ * #1056 fixed exactly this there. Extracted as a pure function so the
+ * contract is testable without mounting the page. */
+export function keyMatchesQuery(k: ApiKey, query: string): boolean {
+ const q = query.toLowerCase()
+ return (
+ (k.label ?? '').toLowerCase().includes(q) ||
+ (k.maskedKey ?? '').toLowerCase().includes(q) ||
+ (k.baseUrl ?? '').toLowerCase().includes(q)
+ )
+}