mirror of
https://github.com/langgenius/dify.git
synced 2026-08-29 03:45:08 +08:00
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
|
|
import type { UsagePlanInfo } from '@/app/components/billing/type'
|
|
import type { ProviderContextState } from '@/context/provider-context'
|
|
import { merge } from 'es-toolkit/compat'
|
|
import { noop } from 'es-toolkit/function'
|
|
import { defaultPlan } from '@/app/components/billing/config'
|
|
|
|
// Avoid being mocked in tests
|
|
export const baseProviderContextValue: ProviderContextState = {
|
|
modelProviders: [],
|
|
modelProviderPlugins: {},
|
|
refreshModelProviders: async () => {},
|
|
isLoadingModelProviders: false,
|
|
isSuccessModelProviders: false,
|
|
textGenerationModelList: [],
|
|
supportRetrievalMethods: [],
|
|
isAPIKeySet: true,
|
|
plan: defaultPlan,
|
|
isFetchedPlan: false,
|
|
isFetchedPlanInfo: false,
|
|
enableBilling: false,
|
|
enableSkill: false,
|
|
onPlanInfoChanged: noop,
|
|
enableReplaceWebAppLogo: false,
|
|
modelLoadBalancingEnabled: false,
|
|
enableEducationPlan: false,
|
|
webappCopyrightEnabled: false,
|
|
isAllowTransferWorkspace: false,
|
|
isAllowPublishAsCustomKnowledgePipelineTemplate: false,
|
|
humanInputEmailDeliveryEnabled: false,
|
|
}
|
|
|
|
export const createMockProviderContextValue = (
|
|
overrides: Partial<ProviderContextState> = {},
|
|
): ProviderContextState => {
|
|
const merged = merge({}, baseProviderContextValue, overrides)
|
|
|
|
return {
|
|
...merged,
|
|
refreshModelProviders: merged.refreshModelProviders ?? noop,
|
|
onPlanInfoChanged: merged.onPlanInfoChanged ?? noop,
|
|
}
|
|
}
|
|
|
|
export const createMockPlan = (plan: CloudPlan): ProviderContextState =>
|
|
createMockProviderContextValue({
|
|
plan: merge({}, defaultPlan, {
|
|
type: plan,
|
|
}),
|
|
})
|
|
|
|
export const createMockPlanUsage = (
|
|
usage: UsagePlanInfo,
|
|
ctx: Partial<ProviderContextState>,
|
|
): ProviderContextState =>
|
|
createMockProviderContextValue({
|
|
...ctx,
|
|
plan: merge(ctx.plan, {
|
|
usage,
|
|
}),
|
|
})
|
|
|
|
export const createMockPlanTotal = (
|
|
total: UsagePlanInfo,
|
|
ctx: Partial<ProviderContextState>,
|
|
): ProviderContextState =>
|
|
createMockProviderContextValue({
|
|
...ctx,
|
|
plan: merge(ctx.plan, {
|
|
total,
|
|
}),
|
|
})
|
|
|
|
export const createMockPlanReset = (
|
|
reset: Partial<ProviderContextState['plan']['reset']>,
|
|
ctx: Partial<ProviderContextState>,
|
|
): ProviderContextState =>
|
|
createMockProviderContextValue({
|
|
...ctx,
|
|
plan: merge(ctx?.plan, {
|
|
reset,
|
|
}),
|
|
})
|