From 11226ee2ef32ea34e526f141e4b00c149a30cf11 Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Sun, 23 Mar 2025 10:26:18 -0400 Subject: [PATCH 1/3] fix: jsr API for cloudflare worker env Without this header will get html format instead of json in cf worker --- packages/package-registry/src/jsr/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/package-registry/src/jsr/index.ts b/packages/package-registry/src/jsr/index.ts index 41bfbc1..66d12bb 100644 --- a/packages/package-registry/src/jsr/index.ts +++ b/packages/package-registry/src/jsr/index.ts @@ -119,7 +119,11 @@ export function getJsrPackageSrcFile( file: string ): Promise { const url = `https://jsr.io/@${scope}/${name}/${version}/${file}` - return fetch(url).then((res) => res.text()) + return fetch(url, { + headers: { + Accept: "application/json" + } + }).then((res) => res.text()) } /** From 9fe51f6260e4778406b0c64a1271a1f3f2a7fe0f Mon Sep 17 00:00:00 2001 From: Huakun Date: Wed, 26 Mar 2025 01:08:16 -0400 Subject: [PATCH 2/3] Feat: gitea mirror (#262) * Update component props and add GitLab link - Made `ref` prop optional in TauriLink component - Added GitLab mirror URL to GitHubProvenanceCard - Included a link to the GitLab mirror in the card layout - Adjusted layout for StoreExtDetail component for better responsiveness - Imported Tooltip component for potential future use * chore: add parse-github-url dependency and update GitHub parsing logic - Added `parse-github-url` package as a dependency in `package.json`. - Updated `parseGitHubRepoFromUri` function to utilize `parse-github-url` for improved URI parsing. - Introduced `getGitHubRepoMetadata` function to fetch repository metadata using Octokit. - Updated validation data structure to include optional `repoId`. - Enhanced tests to cover new functionality and error handling for invalid URIs. * fix typo * refactor: update validation data structure and improve function documentation - Removed optional `repoId` from `ExtensionPublishValidationData` and adjusted related function to reflect this change. - Added a note in the `validateJsrPackageAsKunkunExtension` function documentation to clarify frontend/backend verification logic. - Updated `ExtPublishMetadata` to rename `repoId` to `repoNodeId` for clarity. * refactor: remove GitLab mirror link from GitHubProvenanceCard - Removed the GitLab mirror URL and its associated link from the GitHubProvenanceCard component. - Commented out the layout for the GitLab mirror instead of deleting it, preserving the structure for potential future use. * refactor: simplify GitHub repository URI parsing - Removed dependency on `parse-github-url` and implemented a regex-based approach for parsing GitHub repository URIs in the `parseGitHubRepoFromUri` function. - Enhanced error handling for invalid URIs while maintaining the function's output structure. * feat: add Gitea mirror link to GitHubProvenanceCard - Introduced a new link to the Gitea mirror repository in the GitHubProvenanceCard component. - Updated the layout to reflect the new mirror link while removing the commented-out GitLab mirror section. * refactor: enhance Globe component's location handling - Updated the Globe component to conditionally render markers based on the provided locations prop. - Simplified the destructuring of props for better readability. - Retained default marker locations for cases where no locations are provided. * pnpm lock --- .../src/__tests__/github.test.ts | 12 ++++-- packages/package-registry/src/github.ts | 18 +++++++++ packages/package-registry/src/jsr/index.ts | 8 +++- packages/package-registry/src/npm/index.ts | 2 + packages/supabase/src/models.ts | 5 ++- .../ui/src/components/animation/Globe.svelte | 40 +++++++++---------- .../ui/src/components/common/TauriLink.svelte | 2 +- .../extension/GitHubProvenanceCard.svelte | 7 ++++ .../extension/StoreExtDetail.svelte | 6 +-- pnpm-lock.yaml | 12 +----- 10 files changed, 72 insertions(+), 40 deletions(-) diff --git a/packages/package-registry/src/__tests__/github.test.ts b/packages/package-registry/src/__tests__/github.test.ts index 2e91c1e..69636a4 100644 --- a/packages/package-registry/src/__tests__/github.test.ts +++ b/packages/package-registry/src/__tests__/github.test.ts @@ -1,9 +1,15 @@ import { expect, test } from "bun:test" -import { parseGitHubRepoFromUri } from "../github" +import { getGitHubRepoMetadata, parseGitHubRepoFromUri } from "../github" test("parse github repo from uri", () => { - expect(parseGitHubRepoFromUri("https://github.com/huakunshen/kunkun-ext-ossinsight")).toEqual({ - owner: "huakunshen", + expect(parseGitHubRepoFromUri("https://github.com/kunkunsh/kunkun-ext-ossinsight")).toEqual({ + owner: "kunkunsh", repo: "kunkun-ext-ossinsight" }) + expect(() => parseGitHubRepoFromUri("invalid-uri")).toThrow("Invalid GitHub repository URI") +}) + +test("get github repo metadata", async () => { + const metadata = await getGitHubRepoMetadata("kunkunsh", "kunkun-ext-ossinsight") + expect(metadata).toBeDefined() }) diff --git a/packages/package-registry/src/github.ts b/packages/package-registry/src/github.ts index d07577f..6f94e0a 100644 --- a/packages/package-registry/src/github.ts +++ b/packages/package-registry/src/github.ts @@ -33,6 +33,12 @@ export function authenticatedUserIsMemberOfGitHubOrg( }) } +/** + * Parse a GitHub repository URI into owner and repo + * If not a valid GitHub repository URI, throw an error + * @param uri + * @returns owner and repo + */ export function parseGitHubRepoFromUri(uri: string): { owner: string repo: string @@ -46,3 +52,15 @@ export function parseGitHubRepoFromUri(uri: string): { const [, owner, repo] = match return { owner, repo } } + +/** + * Get GitHub repository metadata + * @param owner + * @param repo + * @param githubToken - Optional GitHub token to prevent rate limiting + * @returns repository metadata + */ +export function getGitHubRepoMetadata(owner: string, repo: string, githubToken?: string) { + const octokit = new Octokit({ auth: githubToken }) + return octokit.rest.repos.get({ owner, repo }).then((res) => res.data) +} diff --git a/packages/package-registry/src/jsr/index.ts b/packages/package-registry/src/jsr/index.ts index 66d12bb..e22bcdc 100644 --- a/packages/package-registry/src/jsr/index.ts +++ b/packages/package-registry/src/jsr/index.ts @@ -7,7 +7,11 @@ import { } from "@huakunshen/jsr-client/hey-api-client" import { ExtPackageJson, License } from "@kksh/api/models" import * as v from "valibot" -import { authenticatedUserIsMemberOfGitHubOrg, userIsPublicMemberOfGitHubOrg } from "../github" +import { + authenticatedUserIsMemberOfGitHubOrg, + getGitHubRepoMetadata, + userIsPublicMemberOfGitHubOrg +} from "../github" import type { ExtensionPublishValidationData } from "../models" import type { NpmPkgMetadata } from "../npm/models" import { getInfoFromRekorLog } from "../sigstore" @@ -205,6 +209,7 @@ export function jsrPackageExists(scope: string, name: string, version?: string): /** * Validate a Jsr package as a Kunkun extension + * !This function will also run in frontend, so if there is any verification logic that must be run in backend, do not add it here * - check if jsr pkg is linked to a github repo * - check if jsr pkg is signed with github action * - check if user's github username is the same as repo's owner name @@ -368,6 +373,7 @@ export async function validateJsrPackageAsKunkunExtension(payload: { } } const rekorInfo = await getInfoFromRekorLog(rekorLogId) + return { data: { pkgJson: parseResult.output, diff --git a/packages/package-registry/src/npm/index.ts b/packages/package-registry/src/npm/index.ts index 2624d49..3e29864 100644 --- a/packages/package-registry/src/npm/index.ts +++ b/packages/package-registry/src/npm/index.ts @@ -2,6 +2,7 @@ import { ExtPackageJson, License } from "@kksh/api/models" import * as v from "valibot" import { authenticatedUserIsMemberOfGitHubOrg, + getGitHubRepoMetadata, parseGitHubRepoFromUri, userIsPublicMemberOfGitHubOrg } from "../github" @@ -237,6 +238,7 @@ export async function validateNpmPackageAsKunkunExtension(payload: { provenance.summary.sourceRepositoryDigest, parseResult.output.readme ?? "README.md" ) + return { data: { pkgJson: parseResult.output, diff --git a/packages/supabase/src/models.ts b/packages/supabase/src/models.ts index 85535a7..8f8a6cc 100644 --- a/packages/supabase/src/models.ts +++ b/packages/supabase/src/models.ts @@ -20,7 +20,10 @@ export const ExtPublishMetadata = v.object({ repo: v.string("GitHub repo of the extension"), owner: v.string("GitHub owner of the extension"), commit: v.string("Commit hash of the extension"), - workflowPath: v.string("Workflow path of the extension") + workflowPath: v.string("Workflow path of the extension"), + repoNodeId: v.optional( + v.string("GitHub repo node ID of the extension (a string, not the number id)") + ) }) ) }) diff --git a/packages/ui/src/components/animation/Globe.svelte b/packages/ui/src/components/animation/Globe.svelte index 97991d6..4fc1cd8 100644 --- a/packages/ui/src/components/animation/Globe.svelte +++ b/packages/ui/src/components/animation/Globe.svelte @@ -12,8 +12,7 @@ // let className = "" // export { className as class } - let { locations = [], class: className }: { class?: string; locations?: [number, number][] } = - $props() + let { locations, class: className }: { class?: string; locations?: [number, number][] } = $props() let pointerInteracting: number | null = null let pointerInteractionMovement = 0 let canvas: HTMLCanvasElement @@ -54,24 +53,25 @@ baseColor: [0.3, 0.3, 0.3], markerColor: [251 / 255, 100 / 255, 21 / 255], glowColor: [1, 1, 1], - markers: locations.map((location) => { - return { - location: location, - size: 0.03 - } - }), - // [ - // { location: [14.5995, 120.9842], size: 0.03 }, - // { location: [19.076, 72.8777], size: 0.03 }, - // { location: [23.8103, 90.4125], size: 0.05 }, - // { location: [30.0444, 31.2357], size: 0.07 }, - // { location: [39.9042, 116.4074], size: 0.08 }, - // { location: [-23.5505, -46.6333], size: 0.05 }, - // { location: [19.4326, -99.1332], size: 0.04 }, - // { location: [40.7128, -74.006], size: 0.1 }, - // { location: [34.6937, 135.5022], size: 0.05 }, - // { location: [41.0082, 28.9784], size: 0.06 } - // ], + markers: locations + ? locations.map((location) => { + return { + location: location, + size: 0.03 + } + }) + : [ + { location: [14.5995, 120.9842], size: 0.03 }, + { location: [19.076, 72.8777], size: 0.03 }, + { location: [23.8103, 90.4125], size: 0.05 }, + { location: [30.0444, 31.2357], size: 0.07 }, + { location: [39.9042, 116.4074], size: 0.08 }, + { location: [-23.5505, -46.6333], size: 0.05 }, + { location: [19.4326, -99.1332], size: 0.04 }, + { location: [40.7128, -74.006], size: 0.1 }, + { location: [34.6937, 135.5022], size: 0.05 }, + { location: [41.0082, 28.9784], size: 0.06 } + ], // onRender: (state) => { // if (!pointerInteracting) { // // Called on every animation frame. diff --git a/packages/ui/src/components/common/TauriLink.svelte b/packages/ui/src/components/common/TauriLink.svelte index ce064d4..8a6bfa8 100644 --- a/packages/ui/src/components/common/TauriLink.svelte +++ b/packages/ui/src/components/common/TauriLink.svelte @@ -16,7 +16,7 @@ style?: HTMLAttributes["style"] class?: HTMLAttributes["class"] children: Snippet - ref: HTMLAnchorElement | HTMLButtonElement | null + ref?: HTMLAnchorElement | HTMLButtonElement | null } = $props() // @ts-expect-error window.__TAURI_INTERNALS__ is not defined in the browser diff --git a/packages/ui/src/components/extension/GitHubProvenanceCard.svelte b/packages/ui/src/components/extension/GitHubProvenanceCard.svelte index 8fd00c7..92e29e2 100644 --- a/packages/ui/src/components/extension/GitHubProvenanceCard.svelte +++ b/packages/ui/src/components/extension/GitHubProvenanceCard.svelte @@ -19,6 +19,7 @@ } = $props() const workflowRunId = githubActionInvocationId.split("/").at(-3) const workflowRunUrl = `https://github.com/${repoOwner}/${repoName}/actions/runs/${workflowRunId}/workflow` + const giteaMirrorUrl = `https://gitea.kunkun.sh/kunkun-extensions-mirror/${repoOwner}-${repoName}` @@ -60,6 +61,12 @@ class="underline">Transparentcy log entry

+

+ Mirror + + Mirror Repo + +

diff --git a/packages/ui/src/components/extension/StoreExtDetail.svelte b/packages/ui/src/components/extension/StoreExtDetail.svelte index 3b31517..2addcc4 100644 --- a/packages/ui/src/components/extension/StoreExtDetail.svelte +++ b/packages/ui/src/components/extension/StoreExtDetail.svelte @@ -4,7 +4,7 @@ import { ExtPackageJson, IconEnum, KunkunExtManifest } from "@kksh/api/models" import { ExtPublishMetadata, ExtPublishSourceTypeEnum } from "@kksh/supabase/models" import { type Tables } from "@kksh/supabase/types" - import { Badge, Button, ScrollArea, Separator } from "@kksh/svelte5" + import { Badge, Button, ScrollArea, Separator, Tooltip } from "@kksh/svelte5" import { Constants, IconMultiplexer } from "@kksh/ui" import { cn } from "@kksh/ui/utils" import { CircleCheckBigIcon, MoveRightIcon, Trash2Icon } from "lucide-svelte" @@ -186,7 +186,7 @@ {/if} -
+
{#if metadata && metadata.sourceType === ExtPublishSourceTypeEnum.jsr} @@ -201,7 +201,7 @@ href={`https://github.com/${metadata.git.owner}/${metadata.git.repo}/tree/${metadata.git.commit}`} target="_blank" > - + {metadata.git.owner}/{metadata.git.repo} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5ad64db..6f39340 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -338,7 +338,7 @@ importers: version: 8.25.0(eslint@9.21.0(jiti@2.4.0))(typescript@5.6.3) autoprefixer: specifier: ^10.4.20 - version: 10.4.20(postcss@8.5.3) + version: 10.4.20(postcss@8.4.49) bits-ui: specifier: 1.0.0-next.86 version: 1.0.0-next.86(svelte@5.20.5) @@ -18883,16 +18883,6 @@ snapshots: postcss: 8.5.1 postcss-value-parser: 4.2.0 - autoprefixer@10.4.20(postcss@8.5.3): - dependencies: - browserslist: 4.24.2 - caniuse-lite: 1.0.30001676 - fraction.js: 4.3.7 - normalize-range: 0.1.2 - picocolors: 1.1.1 - postcss: 8.5.3 - postcss-value-parser: 4.2.0 - available-typed-arrays@1.0.7: dependencies: possible-typed-array-names: 1.0.0 From 48e2e47f9697a040dc71c9e97fb486e2dbcae1b3 Mon Sep 17 00:00:00 2001 From: Huakun Date: Wed, 26 Mar 2025 08:50:55 -0400 Subject: [PATCH 3/3] Remove supabase (#263) * remove supabase package * upgrade valibot * removed supabase package Migration not complete yet * update submodule * fixed some supabase errors * Add new fields to extension models - Added `id` field to `ExtPublish` - Expanded `DBExtension` with multiple new properties: - `api_version`, `author_id`, `created_at`, - `downloads`, `icon`, `identifier`, - `long_description`, `name`, - `readme`, `short_description`, - and `tarball_size` * Refactor: clean up unused Supabase imports - Removed commented-out Supabase imports from various files to streamline the codebase. - Updated `created_at` type in `ExtPublish` model from `date` to `string` for consistency. * update icon enum to union * fix type errors after removing supabase * format * more types fixed * feat: enhance command handling and update SDK version --- .changeset/config.json | 2 - apps/cli/package.json | 2 +- apps/create-kunkun/package.json | 2 +- apps/desktop/dev.ts | 13 + apps/desktop/package.json | 1 - apps/desktop/src/lib/cmds/index.ts | 2 +- apps/desktop/src/lib/context/appConfig.ts | 6 +- apps/desktop/src/lib/context/appState.ts | 2 +- apps/desktop/src/lib/stores/apps.ts | 2 +- apps/desktop/src/lib/stores/quick-links.ts | 2 +- apps/desktop/src/lib/supabase.ts | 16 +- apps/desktop/src/lib/utils/updater.ts | 27 +- .../routes/app/extension/store/+page.svelte | 71 ++-- .../src/routes/app/extension/store/+page.ts | 32 +- .../extension/store/[identifier]/+page.svelte | 43 +-- .../app/extension/store/[identifier]/+page.ts | 62 ++-- .../extension/store/[identifier]/helper.ts | 18 +- apps/desktop/tsconfig.json | 3 +- package.json | 4 +- packages/api/package.json | 2 +- packages/api/src/models/extension.ts | 127 +++---- packages/api/src/models/icon.ts | 21 +- packages/api/src/models/index.ts | 1 + packages/api/src/models/manifest.ts | 41 +-- packages/api/src/models/server.ts | 91 +++++ packages/extension/package.json | 8 +- packages/extension/src/install.ts | 5 +- packages/extension/src/window.ts | 6 +- packages/schema/package.json | 6 +- .../scripts/upload-schema-to-supabase.ts | 3 +- packages/supabase/.gitignore | 175 --------- packages/supabase/README.md | 4 - packages/supabase/package.json | 24 -- packages/supabase/setup.ts | 0 packages/supabase/src/api.ts | 107 ------ packages/supabase/src/database.types.ts | 335 ------------------ packages/supabase/src/index.ts | 10 - packages/supabase/src/models.ts | 47 --- packages/supabase/tsconfig.json | 27 -- packages/tauri-plugins/jarvis/package.json | 1 - packages/tauri-plugins/jarvis/setup.ts | 3 +- packages/typescript-config/path-alias.json | 2 - packages/ui/package.json | 3 +- .../components/common/PlatformsIcons.svelte | 4 +- .../components/extension/ExtListItem.svelte | 5 +- .../extension/PermissionInspector.svelte | 8 +- .../extension/StoreExtDetail.svelte | 23 +- pnpm-lock.yaml | 230 +++++------- vendors/tauri-plugin-network | 2 +- vendors/tauri-plugin-user-input | 2 +- 50 files changed, 472 insertions(+), 1161 deletions(-) create mode 100644 apps/desktop/dev.ts create mode 100644 packages/api/src/models/server.ts delete mode 100644 packages/supabase/.gitignore delete mode 100644 packages/supabase/README.md delete mode 100644 packages/supabase/package.json delete mode 100644 packages/supabase/setup.ts delete mode 100644 packages/supabase/src/api.ts delete mode 100644 packages/supabase/src/database.types.ts delete mode 100644 packages/supabase/src/index.ts delete mode 100644 packages/supabase/src/models.ts delete mode 100644 packages/supabase/tsconfig.json 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()}