diff --git a/.changeset/config.json b/.changeset/config.json index ee081b1..7fb5f45 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -11,11 +11,9 @@ "jarvis", "form-view", "@kksh/desktop", - "@kksh/supabase", "@kksh/utils", "@kksh/extension", "@kksh/schema", - "@kksh/supabase", "@kksh/ui" ] } diff --git a/apps/cli/package.json b/apps/cli/package.json index f7311f5..4dd050b 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -31,7 +31,7 @@ "debug": "^4.4.0", "fs-extra": "^11.2.0", "inquirer": "^10.1.2", - "valibot": "^1.0.0-rc.4" + "valibot": "^1.0.0" }, "files": [ "dist" diff --git a/apps/create-kunkun/package.json b/apps/create-kunkun/package.json index 7c1a90d..473e6de 100644 --- a/apps/create-kunkun/package.json +++ b/apps/create-kunkun/package.json @@ -27,7 +27,7 @@ "commander": "^12.1.0", "fs-extra": "^11.2.0", "handlebars": "^4.7.8", - "valibot": "^1.0.0-rc.4" + "valibot": "^1.0.0" }, "files": [ "dist" diff --git a/apps/desktop/dev.ts b/apps/desktop/dev.ts new file mode 100644 index 0000000..174ad49 --- /dev/null +++ b/apps/desktop/dev.ts @@ -0,0 +1,13 @@ +import { IconType } from "@kksh/api/models" +import { getExtensionsLatestPublishByIdentifier } from "@kksh/sdk" + +const latestPublish = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: "RAG1" + } +}) +console.log(latestPublish) +// latestPublish + +// console.log(typeof IconEnum.Iconify) +console.log(IconType.options) diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 5e2ed15..982388a 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -18,7 +18,6 @@ "@formkit/auto-animate": "^0.8.2", "@inlang/paraglide-sveltekit": "0.16.0", "@kksh/extension": "workspace:*", - "@kksh/supabase": "workspace:*", "@kksh/svelte5": "^0.1.15", "@kksh/ui": "workspace:*", "@kksh/utils": "workspace:*", diff --git a/apps/desktop/src/lib/cmds/index.ts b/apps/desktop/src/lib/cmds/index.ts index 8e43019..3a77a98 100644 --- a/apps/desktop/src/lib/cmds/index.ts +++ b/apps/desktop/src/lib/cmds/index.ts @@ -12,7 +12,7 @@ import { onQuickLinkSelect } from "./quick-links" const onExtCmdSelect: OnExtCmdSelect = ( ext: ExtPackageJsonExtra, - cmd: CustomUiCmd | TemplateUiCmd, + cmd: CustomUiCmd | TemplateUiCmd | HeadlessCmd, { isDev, hmr }: { isDev: boolean; hmr: boolean } ) => { switch (cmd.type) { diff --git a/apps/desktop/src/lib/context/appConfig.ts b/apps/desktop/src/lib/context/appConfig.ts index 4537631..5f99a7e 100644 --- a/apps/desktop/src/lib/context/appConfig.ts +++ b/apps/desktop/src/lib/context/appConfig.ts @@ -3,16 +3,16 @@ * It's designed to allow all components to access a shared state. * With context, we can avoid prop drilling, and avoid using stores which makes components hard to encapsulate. */ -import type { AppConfig } from "@/types/appConfig" +import type { AppConfigState } from "@kksh/types" import { getContext, setContext } from "svelte" import type { Writable } from "svelte/store" export const APP_CONFIG_CONTEXT_KEY = Symbol("appConfig") -export function getAppConfigContext(): Writable { +export function getAppConfigContext(): Writable { return getContext(APP_CONFIG_CONTEXT_KEY) } -export function setAppConfigContext(appConfig: Writable) { +export function setAppConfigContext(appConfig: Writable) { setContext(APP_CONFIG_CONTEXT_KEY, appConfig) } diff --git a/apps/desktop/src/lib/context/appState.ts b/apps/desktop/src/lib/context/appState.ts index 12aa792..02acf83 100644 --- a/apps/desktop/src/lib/context/appState.ts +++ b/apps/desktop/src/lib/context/appState.ts @@ -1,4 +1,4 @@ -import type { AppState } from "@/types/appState" +import type { AppState } from "@kksh/types" import { getContext, setContext } from "svelte" import type { Writable } from "svelte/store" diff --git a/apps/desktop/src/lib/stores/apps.ts b/apps/desktop/src/lib/stores/apps.ts index 700b7c7..5f39267 100644 --- a/apps/desktop/src/lib/stores/apps.ts +++ b/apps/desktop/src/lib/stores/apps.ts @@ -7,7 +7,7 @@ import Fuse from "fuse.js" import { derived, get, writable } from "svelte/store" import { appState } from "./appState" -export const fuse = new Fuse([], { +const fuse = new Fuse([], { includeScore: true, threshold: 0.2, keys: ["name"] diff --git a/apps/desktop/src/lib/stores/quick-links.ts b/apps/desktop/src/lib/stores/quick-links.ts index 120ea98..bd263b9 100644 --- a/apps/desktop/src/lib/stores/quick-links.ts +++ b/apps/desktop/src/lib/stores/quick-links.ts @@ -6,7 +6,7 @@ import Fuse from "fuse.js" import { derived, get, writable, type Writable } from "svelte/store" import { appState } from "./appState" -export const fuse = new Fuse([], { +const fuse = new Fuse([], { includeScore: true, threshold: 0.2, keys: ["name"] diff --git a/apps/desktop/src/lib/supabase.ts b/apps/desktop/src/lib/supabase.ts index 19c62d4..539f443 100644 --- a/apps/desktop/src/lib/supabase.ts +++ b/apps/desktop/src/lib/supabase.ts @@ -1,19 +1,13 @@ -import { SupabaseAPI } from "@kksh/supabase/api" -import type { Database } from "@kksh/supabase/types" import * as sb from "@supabase/supabase-js" import { SUPABASE_ANON_KEY, SUPABASE_URL } from "./constants" // export const supabase = createSB(SUPABASE_URL, SUPABASE_ANON_KEY) -export const supabase: sb.SupabaseClient = sb.createClient( - SUPABASE_URL, - SUPABASE_ANON_KEY, - { - auth: { - flowType: "pkce" - } +export const supabase: sb.SupabaseClient = sb.createClient(SUPABASE_URL, SUPABASE_ANON_KEY, { + auth: { + flowType: "pkce" } -) +}) export const storage = supabase.storage export const supabaseExtensionsStorage = supabase.storage.from("extensions") -export const supabaseAPI = new SupabaseAPI(supabase) +// export const supabaseAPI = new SupabaseAPI(supabase) diff --git a/apps/desktop/src/lib/utils/updater.ts b/apps/desktop/src/lib/utils/updater.ts index 17705b0..d6b503d 100644 --- a/apps/desktop/src/lib/utils/updater.ts +++ b/apps/desktop/src/lib/utils/updater.ts @@ -1,8 +1,7 @@ import { extensions } from "@/stores" -import { supabaseAPI } from "@/supabase" import { isCompatible } from "@kksh/api" import type { ExtPackageJsonExtra } from "@kksh/api/models" -import { greaterThan } from "@std/semver" +import { getExtensionsLatestPublishByIdentifier } from "@kksh/sdk" import { relaunch } from "@tauri-apps/plugin-process" import { check } from "@tauri-apps/plugin-updater" import { gt } from "semver" @@ -32,11 +31,22 @@ export async function checkSingleExtensionUpdate( installedExt: ExtPackageJsonExtra, autoupgrade: boolean ) { - const { data: sbExt, error } = await supabaseAPI.getLatestExtPublish( - installedExt.kunkun.identifier - ) + const { + data: sbExt, + error, + response + } = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: "RAG" + } + }) + // const { data: sbExt, error } = await supabaseAPI.getLatestExtPublish( + // installedExt.kunkun.identifier + // ) if (error) { - return toast.error(`Failed to check update for ${installedExt.kunkun.identifier}: ${error}`) + return toast.error( + `Failed to check update for ${installedExt.kunkun.identifier}: ${error} (${response.status})` + ) } if (!sbExt) { @@ -49,10 +59,7 @@ export async function checkSingleExtensionUpdate( ) { if (autoupgrade) { await extensions - .upgradeStoreExtension( - sbExt.identifier, - supabaseAPI.translateExtensionFilePathToUrl(sbExt.tarball_path) - ) + .upgradeStoreExtension(sbExt.identifier, sbExt.tarball_path) .then(() => { toast.success(`${sbExt.name} upgraded`, { description: `From ${installedExt.version} to ${sbExt.version}` diff --git a/apps/desktop/src/routes/app/extension/store/+page.svelte b/apps/desktop/src/routes/app/extension/store/+page.svelte index 115d426..d684bb9 100644 --- a/apps/desktop/src/routes/app/extension/store/+page.svelte +++ b/apps/desktop/src/routes/app/extension/store/+page.svelte @@ -2,14 +2,13 @@ import { getExtensionsFolder } from "@/constants" import { appState, extensions } from "@/stores" import { keys } from "@/stores/keys" - import { supabaseAPI } from "@/supabase" - import { goBackOnEscapeClearSearchTerm, goHomeOnEscapeClearSearchTerm } from "@/utils/key" import { goBack, goHome } from "@/utils/route" - import { Action as ActionSchema } from "@kksh/api/models" + import { Action as ActionSchema, ExtensionStoreListItem, ExtPublish } from "@kksh/api/models" import { Action } from "@kksh/api/ui" - import { SBExt } from "@kksh/supabase/models" - import type { ExtPublishMetadata } from "@kksh/supabase/models" - import { type Tables } from "@kksh/supabase/types" + import { + getExtensionsLatestPublishByIdentifier, + postExtensionsIncrementDownloads + } from "@kksh/sdk" import { Button, Command } from "@kksh/svelte5" import { Constants } from "@kksh/ui" import { ExtListItem } from "@kksh/ui/extension" @@ -71,51 +70,57 @@ } }) - function onExtItemSelected(ext: SBExt) { + function onExtItemSelected(ext: ExtensionStoreListItem) { goto(`./store/${ext.identifier}`) } - async function onExtItemUpgrade(ext: SBExt) { - const res = await supabaseAPI.getLatestExtPublish(ext.identifier) - if (res.error) + async function onExtItemUpgrade(ext: ExtensionStoreListItem) { + const { data, error, response } = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: ext.identifier + } + }) + if (error) return toast.error("Fail to get latest extension", { - description: res.error.message + description: error.error }) - const tarballUrl = res.data.tarball_path.startsWith("http") - ? res.data.tarball_path - : supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path) - const installExtras = await getInstallExtras( - res.data as Tables<"ext_publish"> & { metadata: ExtPublishMetadata } - ) + const installExtras = await getInstallExtras(data?.metadata) return extensions - .upgradeStoreExtension(ext.identifier, tarballUrl, installExtras) + .upgradeStoreExtension(ext.identifier, data.tarball_path, installExtras) .then((newExt) => { toast.success(`${ext.name} Upgraded to ${newExt.version}`) }) } - async function onExtItemInstall(ext: SBExt) { - const res = await supabaseAPI.getLatestExtPublish(ext.identifier) - if (res.error) + async function onExtItemInstall(ext: ExtensionStoreListItem) { + const { data, error, response } = await getExtensionsLatestPublishByIdentifier({ + path: { + identifier: ext.identifier + } + }) + if (error) return toast.error("Fail to get latest extension", { - description: res.error.message + description: error.error }) - const tarballUrl = res.data.tarball_path.startsWith("http") - ? res.data.tarball_path - : supabaseAPI.translateExtensionFilePathToUrl(res.data.tarball_path) - const installExtras = await getInstallExtras( - res.data as Tables<"ext_publish"> & { metadata: ExtPublishMetadata } - ) + const installExtras = await getInstallExtras(data?.metadata) const installDir = await getExtensionsFolder() return extensions - .installFromTarballUrl(tarballUrl, installDir, installExtras) + .installFromTarballUrl(data.tarball_path, installDir, installExtras) .then(() => toast.success(`Plugin ${ext.name} Installed`)) .then(() => - supabaseAPI.incrementDownloads({ - identifier: ext.identifier, - version: ext.version + postExtensionsIncrementDownloads({ + body: { + identifier: ext.identifier, + version: ext.version + } }) + .then(({ error }) => { + if (error) { + console.error(error) + } + }) + .catch(console.error) ) } @@ -159,7 +164,7 @@ }) - + {#snippet leftSlot()}