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.6 KB
Raw Blame
import type { GetAppsData } from '@dify/contracts/api/console/apps/types.gen'
import type { inferParserType } from 'nuqs'
import { zGetAppsQuery } from '@dify/contracts/api/console/apps/zod.gen'
import {
  createParser,
  createSerializer,
  debounce,
  parseAsArrayOf,
  parseAsString,
  parseAsStringLiteral,
} from 'nuqs'
import { APP_TYPES } from './app-type'
import { APP_LIST_SEARCH_DEBOUNCE_MS } from './constants'

type AppListMode = NonNullable<NonNullable<GetAppsData['query']>['mode']>

export const studioAppListCategories = [
  'all',
  ...APP_TYPES,
] as const satisfies readonly AppListMode[]

const studioAppListCategorySchema = zGetAppsQuery.shape.mode
  .unwrap()
  .unwrap()
  .extract(studioAppListCategories)

const parseAsAppListCategory = createParser({
  parse: (value) => {
    const result = studioAppListCategorySchema.safeParse(value)
    return result.success ? result.data : null
  },
  serialize: String,
})
  .withDefault('all')
  .withOptions({ history: 'push' })

export const appListQueryParsers = {
  category: parseAsAppListCategory,
  creatorIDs: parseAsArrayOf(parseAsString, ';').withDefault([]),
  tagIDs: parseAsArrayOf(parseAsString, ';').withDefault([]),
  sort_by: parseAsStringLiteral(zGetAppsQuery.shape.sort_by.unwrap().unwrap().options).withDefault(
    zGetAppsQuery.shape.sort_by.parse(undefined),
  ),
  keywords: parseAsString.withDefault('').withOptions({
    limitUrlUpdates: debounce(APP_LIST_SEARCH_DEBOUNCE_MS),
  }),
}

export const serializeAppListQuery = createSerializer(appListQueryParsers)

export type AppListUrlQuery = inferParserType<typeof appListQueryParsers>