-
Notifications
You must be signed in to change notification settings - Fork 497
feat(web): browse official Marketplace apps before connecting #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bd883d4
feat(web): show official Marketplace apps before connecting
Cheerego7 bbe3c07
refactor(web): load default Marketplace catalog in the browser
Cheerego7 b27b470
fix(web): scope default Marketplace content to its source
Cheerego7 f758702
fix(web): simplify OOMOL API key link copy
Cheerego7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export const defaultMarketplaceDiscoveryUrl = "https://connector.oomol.com/.well-known/oomol-connector-marketplace"; | ||
|
|
||
| /** Identifies the default source by URL, never by a remote name or provider ID. */ | ||
| export function isDefaultMarketplace(discoveryUrl: string): boolean { | ||
| try { | ||
| const url = new URL(discoveryUrl.trim()); | ||
| return ( | ||
| !url.username && | ||
| !url.password && | ||
| !url.search && | ||
| !url.hash && | ||
| url.href.replace(/\/$/, "") === defaultMarketplaceDiscoveryUrl | ||
| ); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import type { DefaultMarketplaceDiscovery } from "./default-marketplace-discovery"; | ||
| import type { ProviderDefinition } from "./model"; | ||
| import type { ReactNode } from "react"; | ||
|
|
||
| import { useTranslate } from "@embra/i18n/react"; | ||
| import { Loader2, Store } from "lucide-react"; | ||
| import { useEffect, useState } from "react"; | ||
| import { Link } from "react-router"; | ||
| import { Button } from "./components/ui/button"; | ||
| import { loadDefaultMarketplaceCatalog } from "./default-marketplace-discovery"; | ||
| import { Badge, EmptyState, ProviderIcon } from "./shared-ui"; | ||
|
|
||
| interface DefaultMarketplaceCatalogProps { | ||
| providers: ProviderDefinition[]; | ||
| discoveryUrl: string; | ||
| } | ||
|
|
||
| // Default promotions apply only to the named models, never to custom marketplaces. | ||
| const promotedModels: Record<string, string[]> = { | ||
| kling: ["Kling 3.0"], | ||
| minimax: ["MiniMax H3"], | ||
| seedance: ["Seedance 2.0", "Seedance 2.5"], | ||
| }; | ||
| const promotedServices = Object.keys(promotedModels); | ||
|
|
||
| export function DefaultMarketplaceCatalog({ providers, discoveryUrl }: DefaultMarketplaceCatalogProps): ReactNode { | ||
| const t = useTranslate(); | ||
| const [catalog, setCatalog] = useState<DefaultMarketplaceDiscovery>(); | ||
| const [failure, setFailure] = useState<Error>(); | ||
| const [attempt, setAttempt] = useState(0); | ||
|
|
||
| useEffect(() => { | ||
| let active = true; | ||
| setFailure(undefined); | ||
| const controller = new AbortController(); | ||
| void loadDefaultMarketplaceCatalog(discoveryUrl, controller.signal).then( | ||
| (value) => { | ||
| if (active) setCatalog(value); | ||
| }, | ||
| (error: unknown) => { | ||
| if (active) { | ||
| setFailure(error instanceof Error ? error : new Error()); | ||
| } | ||
| }, | ||
| ); | ||
| return () => { | ||
| active = false; | ||
| controller.abort(); | ||
| }; | ||
| }, [attempt, discoveryUrl]); | ||
|
|
||
| const available = new Set(catalog?.actions); | ||
| const rows = providers | ||
| .filter((provider) => provider.actions.some((action) => available.has(action.id))) | ||
| .sort((a, b) => { | ||
| const aRank = promotedServices.indexOf(a.service); | ||
| const bRank = promotedServices.indexOf(b.service); | ||
| return ( | ||
| (aRank < 0 ? promotedServices.length : aRank) - (bRank < 0 ? promotedServices.length : bRank) || | ||
| a.displayName.localeCompare(b.displayName) | ||
| ); | ||
| }); | ||
|
|
||
| return ( | ||
| <section className="marketplace-panel"> | ||
| <header className="marketplace-panel-header"> | ||
| <div> | ||
| <h2>{t("marketplace.default.title")}</h2> | ||
| <p>{t("marketplace.default.description")}</p> | ||
| </div> | ||
| {catalog ? <Badge>{t("marketplace.providers.count", { count: rows.length })}</Badge> : null} | ||
| </header> | ||
| {failure ? ( | ||
| <div className="marketplace-catalog-feedback" role="status"> | ||
| <p>{t("marketplace.default.failed")}</p> | ||
| {failure.message ? <p className="marketplace-catalog-error">{failure.message}</p> : null} | ||
| <Button variant="outline" size="sm" onClick={() => setAttempt((value) => value + 1)}> | ||
| {t("marketplace.default.retry")} | ||
| </Button> | ||
| </div> | ||
| ) : !catalog ? ( | ||
| <div className="marketplace-catalog-feedback" role="status"> | ||
| <Loader2 className="spin" size={16} aria-hidden="true" /> | ||
| {t("marketplace.default.loading")} | ||
| </div> | ||
| ) : rows.length === 0 ? ( | ||
| <EmptyState | ||
| icon={<Store size={20} />} | ||
| title={t("marketplace.default.empty")} | ||
| description={t("marketplace.default.description")} | ||
| density="compact" | ||
| /> | ||
| ) : ( | ||
| <div className="marketplace-provider-list"> | ||
| {rows.map((provider) => { | ||
| const promoted = promotedServices.includes(provider.service); | ||
| const path = `/providers/${encodeURIComponent(provider.service)}`; | ||
| return ( | ||
| <div className="marketplace-provider-row marketplace-default-row" key={provider.service}> | ||
| <ProviderIcon provider={provider} /> | ||
| <div className="marketplace-default-copy"> | ||
| <Link className="marketplace-provider-copy" to={path}> | ||
| <strong>{provider.displayName}</strong> | ||
| <span> | ||
| {promoted | ||
| ? t(`marketplace.default.descriptions.${provider.service}`) | ||
| : provider.description || t("marketplace.default.browseDescription")} | ||
| </span> | ||
| </Link> | ||
| {promoted ? ( | ||
| <div className="marketplace-default-tags"> | ||
| {promotedModels[provider.service].map((model) => ( | ||
| <span className="marketplace-model-tag" key={model}> | ||
| {model} | ||
| </span> | ||
| ))} | ||
| <Badge tone="success">{t(`marketplace.default.offers.${provider.service}`)}</Badge> | ||
| </div> | ||
| ) : null} | ||
| </div> | ||
| <Button asChild variant="outline" size="sm"> | ||
| <Link to={path}>{t("marketplace.default.view")}</Link> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| )} | ||
| {catalog ? ( | ||
| <footer className="marketplace-catalog-footer"> | ||
| {catalog.name} · {t("marketplace.default.disconnected")} | ||
| </footer> | ||
| ) : null} | ||
| </section> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { afterEach, expect, it, vi } from "vitest"; | ||
| import { loadDefaultMarketplaceCatalog } from "./default-marketplace-discovery"; | ||
|
|
||
| afterEach(() => vi.unstubAllGlobals()); | ||
|
|
||
| it("reads public discovery directly without credentials", async () => { | ||
| const fetcher = vi | ||
| .fn() | ||
| .mockResolvedValue(new Response(JSON.stringify({ version: 1, name: "Default", actions: ["kling.generate"] }))); | ||
| vi.stubGlobal("fetch", fetcher); | ||
| await expect( | ||
| loadDefaultMarketplaceCatalog("https://example.com/discovery", new AbortController().signal), | ||
| ).resolves.toEqual({ name: "Default", actions: ["kling.generate"] }); | ||
| expect(fetcher).toHaveBeenCalledWith( | ||
| "https://example.com/discovery", | ||
| expect.objectContaining({ credentials: "omit", redirect: "error" }), | ||
| ); | ||
| }); | ||
|
|
||
| it.each([ | ||
| new Response("offline", { status: 503 }), | ||
| new Response(JSON.stringify({ version: 1, name: "Default", actions: [42] })), | ||
| ])("rejects failed or malformed catalogs", async (response) => { | ||
| vi.stubGlobal("fetch", vi.fn().mockResolvedValue(response)); | ||
| await expect( | ||
| loadDefaultMarketplaceCatalog("https://example.com/discovery", new AbortController().signal), | ||
| ).rejects.toThrow(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| export interface DefaultMarketplaceDiscovery { | ||
| name: string; | ||
| actions: string[]; | ||
| } | ||
|
|
||
| /** Reads the public browsing catalog without sending credentials or activating a connection. */ | ||
| export async function loadDefaultMarketplaceCatalog( | ||
| url: string, | ||
| signal: AbortSignal, | ||
| ): Promise<DefaultMarketplaceDiscovery> { | ||
| const response = await fetch(url, { | ||
| credentials: "omit", | ||
| redirect: "error", | ||
| signal: AbortSignal.any([signal, AbortSignal.timeout(15_000)]), | ||
| headers: { accept: "application/json" }, | ||
| }); | ||
| if (!response.ok) throw new Error(`Default Marketplace returned HTTP ${response.status}.`); | ||
| const value: unknown = await response.json(); | ||
| if ( | ||
| !value || | ||
| typeof value !== "object" || | ||
| !("version" in value) || | ||
| value.version !== 1 || | ||
| !("name" in value) || | ||
| typeof value.name !== "string" || | ||
| !("actions" in value) || | ||
| !Array.isArray(value.actions) || | ||
| !value.actions.every((action: unknown) => typeof action === "string") | ||
| ) { | ||
| throw new Error("Default Marketplace returned an invalid discovery document."); | ||
| } | ||
| return { name: value.name, actions: value.actions }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.