* add platform guards * add service management * fix types * move to zustand for servicehub * update App Updater * update tauri missing move * update app updater * refactor: move PlatformFeatures to separate const file 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * change tauri fetch name * update implementation * update extension fetch * make web version run properly * disabled unused web settings * fix all tests * fix lint * fix tests * add mock for extension * fix build * update make and mise * fix tsconfig for web-extensions * fix loader type * cleanup * fix test * update error handling + mcp should be working * Update mcp init * use separate is_web_app build property * Remove fixed model catalog url * fix additional tests * fix download issue (event emitter not implemented correctly) * Update Title html * fix app logs * update root tsx render timing --------- Co-authored-by: Claude <noreply@anthropic.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { create } from 'zustand'
|
|
import { localStorageKey } from '@/constants/localStorage'
|
|
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
import { getServiceHub } from '@/hooks/useServiceHub'
|
|
import type { CatalogModel } from '@/services/models/types'
|
|
import { sanitizeModelId } from '@/lib/utils'
|
|
|
|
// Zustand store for model sources
|
|
type ModelSourcesState = {
|
|
sources: CatalogModel[]
|
|
error: Error | null
|
|
loading: boolean
|
|
fetchSources: () => Promise<void>
|
|
}
|
|
|
|
export const useModelSources = create<ModelSourcesState>()(
|
|
persist(
|
|
(set, get) => ({
|
|
sources: [],
|
|
error: null,
|
|
loading: false,
|
|
fetchSources: async () => {
|
|
set({ loading: true, error: null })
|
|
try {
|
|
const newSources = await getServiceHub().models().fetchModelCatalog().then((catalogs) =>
|
|
catalogs.map((catalog) => ({
|
|
...catalog,
|
|
quants: catalog.quants.map((quant) => ({
|
|
...quant,
|
|
model_id: sanitizeModelId(quant.model_id),
|
|
})),
|
|
}))
|
|
)
|
|
|
|
set({
|
|
sources: newSources.length ? newSources : get().sources,
|
|
loading: false,
|
|
})
|
|
} catch (error) {
|
|
set({ error: error as Error, loading: false })
|
|
}
|
|
},
|
|
}),
|
|
{
|
|
name: localStorageKey.modelSources,
|
|
storage: createJSONStorage(() => localStorage),
|
|
}
|
|
)
|
|
)
|