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.

chore(web): strong typing (#2339)

Rhon Joeb521aafd26ee
diff --git a/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx b/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx
index b4684428472..55b554bfcba 100644
--- a/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx
+++ b/web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx
@@ -52,7 +52,7 @@ const SettingBuiltInTool: FC<Props> = ({
(async () => {
setIsLoading(true)
try {
- const list = await fetchBuiltInToolList(collection.name) as Tool[]
+ const list = await fetchBuiltInToolList(collection.name)
setTools(list)
const currTool = list.find(tool => tool.name === toolName)
if (currTool) {
diff --git a/web/app/components/app/configuration/index.tsx b/web/app/components/app/configuration/index.tsx
index 8b2c33e1481..01b3c312c29 100644
--- a/web/app/components/app/configuration/index.tsx
+++ b/web/app/components/app/configuration/index.tsx
@@ -381,7 +381,7 @@ const Configuration: FC = () => {
useEffect(() => {
(async () => {
- const collectionList = await fetchCollectionList() as Collection[]
+ const collectionList = await fetchCollectionList()
setCollectionList(collectionList)
fetchAppDetail({ url: '/apps', id: appId }).then(async (res: any) => {
setMode(res.mode)
diff --git a/web/app/components/tools/edit-custom-collection-modal/index.tsx b/web/app/components/tools/edit-custom-collection-modal/index.tsx
index 7f05e5ed8ae..3919dbf1d62 100644
--- a/web/app/components/tools/edit-custom-collection-modal/index.tsx
+++ b/web/app/components/tools/edit-custom-collection-modal/index.tsx
@@ -83,7 +83,7 @@ const EditCustomCollectionModal: FC<Props> = ({
(async () => {
const customCollection = getCustomCollection()
try {
- const { parameters_schema, schema_type } = await parseParamsSchema(debouncedSchema) as any
+ const { parameters_schema, schema_type } = await parseParamsSchema(debouncedSchema)
const newCollection = produce(customCollection, (draft) => {
draft.schema_type = schema_type
})
diff --git a/web/app/components/tools/index.tsx b/web/app/components/tools/index.tsx
index 0c9cedf6bd5..d540cfb2b47 100644
--- a/web/app/components/tools/index.tsx
+++ b/web/app/components/tools/index.tsx
@@ -43,7 +43,7 @@ const Tools: FC<Props> = ({
const [isDetailLoading, setIsDetailLoading] = useState(false)
const fetchCollectionList = async () => {
- const list = await doFetchCollectionList() as Collection[]
+ const list = await doFetchCollectionList()
setCollectionList(list)
if (list.length > 0 && currCollectionIndex === null) {
let index = 0
@@ -103,11 +103,11 @@ const Tools: FC<Props> = ({
setIsDetailLoading(true)
try {
if (currCollection.type === CollectionType.builtIn) {
- const list = await fetchBuiltInToolList(currCollection.name) as Tool[]
+ const list = await fetchBuiltInToolList(currCollection.name)
setCurrentTools(list)
}
else {
- const list = await fetchCustomToolList(currCollection.name) as Tool[]
+ const list = await fetchCustomToolList(currCollection.name)
setCurrentTools(list)
}
}
diff --git a/web/app/components/tools/setting/build-in/config-credentials.tsx b/web/app/components/tools/setting/build-in/config-credentials.tsx
index 9922200afe2..fdca7abb070 100644
--- a/web/app/components/tools/setting/build-in/config-credentials.tsx
+++ b/web/app/components/tools/setting/build-in/config-credentials.tsx
@@ -29,7 +29,7 @@ const ConfigCredential: FC<Props> = ({
const { team_credentials: credentialValue, name: collectionName } = collection
useEffect(() => {
fetchBuiltInToolCredentialSchema(collectionName).then((res) => {
- setCredentialSchema(toolCredentialToFormSchemas(res as any))
+ setCredentialSchema(toolCredentialToFormSchemas(res))
})
}, [])
const [tempCredential, setTempCredential] = React.useState<any>(credentialValue)
diff --git a/web/app/components/tools/tool-list/index.tsx b/web/app/components/tools/tool-list/index.tsx
index c5a49b76345..58fcf5613b8 100644
--- a/web/app/components/tools/tool-list/index.tsx
+++ b/web/app/components/tools/tool-list/index.tsx
@@ -52,11 +52,11 @@ const ToolList: FC<Props> = ({
return
(async () => {
if (collection.type === CollectionType.custom) {
- const res = await fetchCustomCollection(collection.name) as any
+ const res = await fetchCustomCollection(collection.name)
setCustomCollection({
...res,
provider: collection.name,
- } as CustomCollectionBackend)
+ })
}
})()
}, [collection])
diff --git a/web/service/billing.ts b/web/service/billing.ts
index e7f0ce8ee7b..7dfe5ac0a7c 100644
--- a/web/service/billing.ts
+++ b/web/service/billing.ts
@@ -2,13 +2,13 @@ import { get } from './base'
import type { CurrentPlanInfoBackend, SubscriptionUrlsBackend } from '@/app/components/billing/type'
export const fetchCurrentPlanInfo = () => {
- return get<Promise<CurrentPlanInfoBackend>>('/features')
+ return get<CurrentPlanInfoBackend>('/features')
}
export const fetchSubscriptionUrls = (plan: string, interval: string) => {
- return get<Promise<SubscriptionUrlsBackend>>(`/billing/subscription?plan=${plan}&interval=${interval}`)
+ return get<SubscriptionUrlsBackend>(`/billing/subscription?plan=${plan}&interval=${interval}`)
}
export const fetchBillingUrl = () => {
- return get<Promise<{ url: string }>>('/billing/invoices')
+ return get<{ url: string }>('/billing/invoices')
}
diff --git a/web/service/tools.ts b/web/service/tools.ts
index b87a64ab7c7..008de4a5573 100644
--- a/web/service/tools.ts
+++ b/web/service/tools.ts
@@ -1,19 +1,19 @@
import { get, post } from './base'
-import type { CustomCollectionBackend } from '@/app/components/tools/types'
+import type { Collection, CustomCollectionBackend, CustomParamSchema, Tool, ToolCredential } from '@/app/components/tools/types'
export const fetchCollectionList = () => {
- return get('/workspaces/current/tool-providers')
+ return get<Collection[]>('/workspaces/current/tool-providers')
}
export const fetchBuiltInToolList = (collectionName: string) => {
- return get(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
+ return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
}
export const fetchCustomToolList = (collectionName: string) => {
- return get(`/workspaces/current/tool-provider/api/tools?provider=${collectionName}`)
+ return get<Tool[]>(`/workspaces/current/tool-provider/api/tools?provider=${collectionName}`)
}
export const fetchBuiltInToolCredentialSchema = (collectionName: string) => {
- return get(`/workspaces/current/tool-provider/builtin/${collectionName}/credentials_schema`)
+ return get<ToolCredential[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/credentials_schema`)
}
export const updateBuiltInToolCredential = (collectionName: string, credential: Record<string, any>) => {
@@ -31,7 +31,7 @@ export const removeBuiltInToolCredential = (collectionName: string) => {
}
export const parseParamsSchema = (schema: string) => {
- return post('/workspaces/current/tool-provider/api/schema', {
+ return post<{ parameters_schema: CustomParamSchema[]; schema_type: string }>('/workspaces/current/tool-provider/api/schema', {
body: {
schema,
},
@@ -39,7 +39,7 @@ export const parseParamsSchema = (schema: string) => {
}
export const fetchCustomCollection = (collectionName: string) => {
- return get(`/workspaces/current/tool-provider/api/get?provider=${collectionName}`)
+ return get<CustomCollectionBackend>(`/workspaces/current/tool-provider/api/get?provider=${collectionName}`)
}
export const createCustomCollection = (collection: CustomCollectionBackend) => {