Skip to content

Commit 33b0814

Browse files
authored
refactor(types): remove any usages and strengthen typings across web and base (langgenius#26677)
1 parent 45ae511 commit 33b0814

File tree

6 files changed

+45
-28
lines changed

6 files changed

+45
-28
lines changed

‎web/app/components/share/text-generation/result/index.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ const Result: FC<IResultProps> = ({
7878
setRespondingFalse()
7979
}, [controlStopResponding])
8080

81-
const [completionRes, doSetCompletionRes] = useState<any>('')
82-
const completionResRef = useRef<any>()
83-
const setCompletionRes = (res: any) => {
81+
const [completionRes, doSetCompletionRes] = useState<string>('')
82+
const completionResRef = useRef<string>('')
83+
const setCompletionRes = (res: string) => {
8484
completionResRef.current = res
8585
doSetCompletionRes(res)
8686
}
8787
const getCompletionRes = () => completionResRef.current
8888
const [workflowProcessData, doSetWorkflowProcessData] = useState<WorkflowProcess>()
89-
const workflowProcessDataRef = useRef<WorkflowProcess>()
89+
const workflowProcessDataRef = useRef<WorkflowProcess | undefined>(undefined)
9090
const setWorkflowProcessData = (data: WorkflowProcess) => {
9191
workflowProcessDataRef.current = data
9292
doSetWorkflowProcessData(data)

‎web/app/components/workflow/hooks/use-workflow-history.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ export const useWorkflowHistory = () => {
4141
const { store: workflowHistoryStore } = useWorkflowHistoryStore()
4242
const { t } = useTranslation()
4343

44-
const [undoCallbacks, setUndoCallbacks] = useState<any[]>([])
45-
const [redoCallbacks, setRedoCallbacks] = useState<any[]>([])
44+
const [undoCallbacks, setUndoCallbacks] = useState<(() => void)[]>([])
45+
const [redoCallbacks, setRedoCallbacks] = useState<(() => void)[]>([])
4646

47-
const onUndo = useCallback((callback: unknown) => {
48-
setUndoCallbacks((prev: any) => [...prev, callback])
47+
const onUndo = useCallback((callback: () => void) => {
48+
setUndoCallbacks(prev => [...prev, callback])
4949
return () => setUndoCallbacks(prev => prev.filter(cb => cb !== callback))
5050
}, [])
5151

52-
const onRedo = useCallback((callback: unknown) => {
53-
setRedoCallbacks((prev: any) => [...prev, callback])
52+
const onRedo = useCallback((callback: () => void) => {
53+
setRedoCallbacks(prev => [...prev, callback])
5454
return () => setRedoCallbacks(prev => prev.filter(cb => cb !== callback))
5555
}, [])
5656

‎web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const VarReferencePicker: FC<Props> = ({
127127

128128
const reactflow = useReactFlow()
129129

130-
const startNode = availableNodes.find((node: any) => {
130+
const startNode = availableNodes.find((node: Node) => {
131131
return node.data.type === BlockEnum.Start
132132
})
133133

‎web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-config.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const JsonSchemaConfig: FC<JsonSchemaConfigProps> = ({
120120
setJson(JSON.stringify(schema, null, 2))
121121
}, [currentTab])
122122

123-
const handleSubmit = useCallback((schema: any) => {
123+
const handleSubmit = useCallback((schema: Record<string, unknown>) => {
124124
const jsonSchema = jsonToSchema(schema) as SchemaRoot
125125
if (currentTab === SchemaView.VisualEditor)
126126
setJsonSchema(jsonSchema)

‎web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/edit-card/index.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,16 @@ const EditCard: FC<EditCardProps> = ({
152152
}, [isAdvancedEditing, emitPropertyOptionsChange, currentFields])
153153

154154
const handleAdvancedOptionsChange = useCallback((options: AdvancedOptionsType) => {
155-
let enumValue: any = options.enum
156-
if (enumValue === '') {
155+
let enumValue: SchemaEnumType | undefined
156+
if (options.enum === '') {
157157
enumValue = undefined
158158
}
159159
else {
160-
enumValue = options.enum.replace(/\s/g, '').split(',')
160+
const stringArray = options.enum.replace(/\s/g, '').split(',')
161161
if (currentFields.type === Type.number)
162-
enumValue = (enumValue as SchemaEnumType).map(value => Number(value)).filter(num => !Number.isNaN(num))
162+
enumValue = stringArray.map(value => Number(value)).filter(num => !Number.isNaN(num))
163+
else
164+
enumValue = stringArray
163165
}
164166
setCurrentFields(prev => ({ ...prev, enum: enumValue }))
165167
if (isAdvancedEditing) return

‎web/service/base.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const handleStream = (
180180
let isFirstMessage = true
181181
function read() {
182182
let hasError = false
183-
reader?.read().then((result: any) => {
183+
reader?.read().then((result: ReadableStreamReadResult<Uint8Array>) => {
184184
if (result.done) {
185185
onCompleted?.()
186186
return
@@ -322,7 +322,21 @@ const handleStream = (
322322

323323
const baseFetch = base
324324

325-
export const upload = async (options: any, isPublicAPI?: boolean, url?: string, searchParams?: string): Promise<any> => {
325+
type UploadOptions = {
326+
xhr: XMLHttpRequest
327+
method: string
328+
url?: string
329+
headers?: Record<string, string>
330+
data: FormData
331+
onprogress?: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => void
332+
}
333+
334+
type UploadResponse = {
335+
id: string
336+
[key: string]: unknown
337+
}
338+
339+
export const upload = async (options: UploadOptions, isPublicAPI?: boolean, url?: string, searchParams?: string): Promise<UploadResponse> => {
326340
const urlPrefix = isPublicAPI ? PUBLIC_API_PREFIX : API_PREFIX
327341
const token = await getAccessToken(isPublicAPI)
328342
const defaultOptions = {
@@ -331,18 +345,18 @@ export const upload = async (options: any, isPublicAPI?: boolean, url?: string,
331345
headers: {
332346
Authorization: `Bearer ${token}`,
333347
},
334-
data: {},
335348
}
336-
options = {
349+
const mergedOptions = {
337350
...defaultOptions,
338351
...options,
339-
headers: { ...defaultOptions.headers, ...options.headers },
352+
url: options.url || defaultOptions.url,
353+
headers: { ...defaultOptions.headers, ...options.headers } as Record<string, string>,
340354
}
341355
return new Promise((resolve, reject) => {
342-
const xhr = options.xhr
343-
xhr.open(options.method, options.url)
344-
for (const key in options.headers)
345-
xhr.setRequestHeader(key, options.headers[key])
356+
const xhr = mergedOptions.xhr
357+
xhr.open(mergedOptions.method, mergedOptions.url)
358+
for (const key in mergedOptions.headers)
359+
xhr.setRequestHeader(key, mergedOptions.headers[key])
346360

347361
xhr.withCredentials = true
348362
xhr.responseType = 'json'
@@ -354,8 +368,9 @@ export const upload = async (options: any, isPublicAPI?: boolean, url?: string,
354368
reject(xhr)
355369
}
356370
}
357-
xhr.upload.onprogress = options.onprogress
358-
xhr.send(options.data)
371+
if (mergedOptions.onprogress)
372+
xhr.upload.onprogress = mergedOptions.onprogress
373+
xhr.send(mergedOptions.data)
359374
})
360375
}
361376

@@ -432,7 +447,7 @@ export const ssePost = async (
432447
if (!/^[23]\d{2}$/.test(String(res.status))) {
433448
if (res.status === 401) {
434449
if (isPublicAPI) {
435-
res.json().then((data: any) => {
450+
res.json().then((data: { code?: string; message?: string }) => {
436451
if (isPublicAPI) {
437452
if (data.code === 'web_app_access_denied')
438453
requiredWebSSOLogin(data.message, 403)

0 commit comments

Comments
 (0)