Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.9 KB
Raw Blame
import type { PluginsSearchParams } from '@dify/contracts/marketplace'
import { infiniteQueryOptions, keepPreviousData } from '@tanstack/react-query'
import { marketplaceQuery } from '@/service/marketplace'
import { getMarketplacePlugins } from './utils'

export const getMarketplacePluginsInfiniteQueryOptions = (
  queryParams: PluginsSearchParams | undefined,
) =>
  infiniteQueryOptions({
    queryKey: marketplaceQuery.searchAdvanced.queryKey({
      input: {
        body: queryParams ?? { query: '' },
        params: { kind: queryParams?.type === 'bundle' ? 'bundles' : 'plugins' },
      },
    }),
    queryFn: ({ pageParam = 1, signal }) => getMarketplacePlugins(queryParams, pageParam, signal),
    getNextPageParam: (lastPage) => {
      const nextPage = lastPage.page + 1
      const loaded = lastPage.page * lastPage.page_size
      return loaded < (lastPage.total || 0) ? nextPage : undefined
    },
    initialPageParam: 1,
    enabled: queryParams !== undefined,
    // Hold the previous term's results while the new query is in flight. Without
    // this, `data` goes undefined on every keystroke that survives the debounce,
    // the grid unmounts, the container collapses, and the scroll position jumps —
    // the "jitter" the Marketplace search is reported for. Consumers show a
    // quiet pending state off `isPlaceholderData` instead.
    // Returning to collections disables search; keeping its placeholder then
    // leaves the last category visible and permanently marked as refreshing.
    placeholderData: queryParams === undefined ? undefined : keepPreviousData,
    // Matches the autocomplete queries. Now that the fetcher propagates
    // failures, react-query's default of 3 retries would hold isFetching true
    // through ~7s of backoff — indistinguishable from a hang. Failing fast and
    // offering an explicit Retry is both honest and fewer requests to abort.
    retry: false,
  })