Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
1de48f33
Unverified
Commit
1de48f33
authored
Sep 15, 2023
by
Rhon Joe
Committed by
GitHub
Sep 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(web): service request return generics type (#1157)
parent
6b41a959
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
190 additions
and
181 deletions
+190
-181
index.tsx
web/app/components/datasets/create/step-two/index.tsx
+5
-3
use-breakpoints.ts
web/hooks/use-breakpoints.ts
+13
-11
apps.ts
web/service/apps.ts
+22
-22
base.ts
web/service/base.ts
+60
-55
common.ts
web/service/common.ts
+43
-43
datasets.ts
web/service/datasets.ts
+38
-38
log.ts
web/service/log.ts
+9
-9
No files found.
web/app/components/datasets/create/step-two/index.tsx
View file @
1de48f33
...
@@ -487,8 +487,10 @@ const StepTwo = ({
...
@@ -487,8 +487,10 @@ const StepTwo = ({
<
input
<
input
type=
"number"
type=
"number"
className=
{
s
.
input
}
className=
{
s
.
input
}
placeholder=
{
t
(
'datasetCreation.stepTwo.separatorPlaceholder'
)
||
''
}
value=
{
max
}
placeholder=
{
t
(
'datasetCreation.stepTwo.separatorPlaceholder'
)
||
''
}
onChange=
{
e
=>
setMax
(
Number
(
e
.
target
.
value
))
}
value=
{
max
}
min=
{
1
}
onChange=
{
e
=>
setMax
(
parseInt
(
e
.
target
.
value
.
replace
(
/^0+/
,
''
),
10
))
}
/>
/>
</
div
>
</
div
>
</
div
>
</
div
>
...
@@ -497,7 +499,7 @@ const StepTwo = ({
...
@@ -497,7 +499,7 @@ const StepTwo = ({
<
div
className=
{
s
.
label
}
>
{
t
(
'datasetCreation.stepTwo.rules'
)
}
</
div
>
<
div
className=
{
s
.
label
}
>
{
t
(
'datasetCreation.stepTwo.rules'
)
}
</
div
>
{
rules
.
map
(
rule
=>
(
{
rules
.
map
(
rule
=>
(
<
div
key=
{
rule
.
id
}
className=
{
s
.
ruleItem
}
>
<
div
key=
{
rule
.
id
}
className=
{
s
.
ruleItem
}
>
<
input
id=
{
rule
.
id
}
type=
"checkbox"
defaultC
hecked=
{
rule
.
enabled
}
onChange=
{
()
=>
ruleChangeHandle
(
rule
.
id
)
}
className=
"w-4 h-4 rounded border-gray-300 text-blue-700 focus:ring-blue-700"
/>
<
input
id=
{
rule
.
id
}
type=
"checkbox"
c
hecked=
{
rule
.
enabled
}
onChange=
{
()
=>
ruleChangeHandle
(
rule
.
id
)
}
className=
"w-4 h-4 rounded border-gray-300 text-blue-700 focus:ring-blue-700"
/>
<
label
htmlFor=
{
rule
.
id
}
className=
"ml-2 text-sm font-normal cursor-pointer text-gray-800"
>
{
getRuleName
(
rule
.
id
)
}
</
label
>
<
label
htmlFor=
{
rule
.
id
}
className=
"ml-2 text-sm font-normal cursor-pointer text-gray-800"
>
{
getRuleName
(
rule
.
id
)
}
</
label
>
</
div
>
</
div
>
))
}
))
}
...
...
web/hooks/use-breakpoints.ts
View file @
1de48f33
...
@@ -8,20 +8,22 @@ export enum MediaType {
...
@@ -8,20 +8,22 @@ export enum MediaType {
}
}
const
useBreakpoints
=
()
=>
{
const
useBreakpoints
=
()
=>
{
const
[
width
,
setWidth
]
=
React
.
useState
(
globalThis
.
innerWidth
)
;
const
[
width
,
setWidth
]
=
React
.
useState
(
globalThis
.
innerWidth
)
const
media
=
(()
=>
{
const
media
=
(()
=>
{
if
(
width
<=
640
)
return
MediaType
.
mobile
;
if
(
width
<=
640
)
if
(
width
<=
768
)
return
MediaType
.
tablet
;
return
MediaType
.
mobile
return
MediaType
.
pc
;
if
(
width
<=
768
)
})();
return
MediaType
.
tablet
return
MediaType
.
pc
})()
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
const
handleWindowResize
=
()
=>
setWidth
(
window
.
innerWidth
)
;
const
handleWindowResize
=
()
=>
setWidth
(
window
.
innerWidth
)
window
.
addEventListener
(
"resize"
,
handleWindowResize
);
window
.
addEventListener
(
'resize'
,
handleWindowResize
)
return
()
=>
window
.
removeEventListener
(
"resize"
,
handleWindowResize
);
return
()
=>
window
.
removeEventListener
(
'resize'
,
handleWindowResize
)
},
[])
;
},
[])
return
media
;
return
media
}
}
export
default
useBreakpoints
export
default
useBreakpoints
web/service/apps.ts
View file @
1de48f33
...
@@ -5,91 +5,91 @@ import type { CommonResponse } from '@/models/common'
...
@@ -5,91 +5,91 @@ import type { CommonResponse } from '@/models/common'
import
type
{
AppMode
,
ModelConfig
}
from
'@/types/app'
import
type
{
AppMode
,
ModelConfig
}
from
'@/types/app'
export
const
fetchAppList
:
Fetcher
<
AppListResponse
,
{
url
:
string
;
params
?:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchAppList
:
Fetcher
<
AppListResponse
,
{
url
:
string
;
params
?:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
AppListResponse
>
return
get
<
AppListResponse
>
(
url
,
{
params
})
}
}
export
const
fetchAppDetail
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
id
:
string
}
>
=
({
url
,
id
})
=>
{
export
const
fetchAppDetail
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
id
:
string
}
>
=
({
url
,
id
})
=>
{
return
get
(
`
${
url
}
/
${
id
}
`
)
as
Promise
<
AppDetailResponse
>
return
get
<
AppDetailResponse
>
(
`
${
url
}
/
${
id
}
`
)
}
}
export
const
fetchAppTemplates
:
Fetcher
<
AppTemplatesResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchAppTemplates
:
Fetcher
<
AppTemplatesResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
)
as
Promise
<
AppTemplatesResponse
>
return
get
<
AppTemplatesResponse
>
(
url
)
}
}
export
const
createApp
:
Fetcher
<
AppDetailResponse
,
{
name
:
string
;
icon
:
string
;
icon_background
:
string
;
mode
:
AppMode
;
config
?:
ModelConfig
}
>
=
({
name
,
icon
,
icon_background
,
mode
,
config
})
=>
{
export
const
createApp
:
Fetcher
<
AppDetailResponse
,
{
name
:
string
;
icon
:
string
;
icon_background
:
string
;
mode
:
AppMode
;
config
?:
ModelConfig
}
>
=
({
name
,
icon
,
icon_background
,
mode
,
config
})
=>
{
return
post
(
'apps'
,
{
body
:
{
name
,
icon
,
icon_background
,
mode
,
model_config
:
config
}
})
as
Promise
<
AppDetailResponse
>
return
post
<
AppDetailResponse
>
(
'apps'
,
{
body
:
{
name
,
icon
,
icon_background
,
mode
,
model_config
:
config
}
})
}
}
export
const
deleteApp
:
Fetcher
<
CommonResponse
,
string
>
=
(
appID
)
=>
{
export
const
deleteApp
:
Fetcher
<
CommonResponse
,
string
>
=
(
appID
)
=>
{
return
del
(
`apps/
${
appID
}
`
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
`apps/
${
appID
}
`
)
}
}
export
const
updateAppSiteStatus
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateAppSiteStatus
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
AppDetailResponse
>
return
post
<
AppDetailResponse
>
(
url
,
{
body
})
}
}
export
const
updateAppApiStatus
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateAppApiStatus
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
AppDetailResponse
>
return
post
<
AppDetailResponse
>
(
url
,
{
body
})
}
}
// path: /apps/{appId}/rate-limit
// path: /apps/{appId}/rate-limit
export
const
updateAppRateLimit
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateAppRateLimit
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
AppDetailResponse
>
return
post
<
AppDetailResponse
>
(
url
,
{
body
})
}
}
export
const
updateAppSiteAccessToken
:
Fetcher
<
UpdateAppSiteCodeResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
updateAppSiteAccessToken
:
Fetcher
<
UpdateAppSiteCodeResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
post
(
url
)
as
Promise
<
UpdateAppSiteCodeResponse
>
return
post
<
UpdateAppSiteCodeResponse
>
(
url
)
}
}
export
const
updateAppSiteConfig
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateAppSiteConfig
:
Fetcher
<
AppDetailResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
AppDetailResponse
>
return
post
<
AppDetailResponse
>
(
url
,
{
body
})
}
}
export
const
getAppDailyConversations
:
Fetcher
<
AppDailyConversationsResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
getAppDailyConversations
:
Fetcher
<
AppDailyConversationsResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
AppDailyConversationsResponse
>
return
get
<
AppDailyConversationsResponse
>
(
url
,
{
params
})
}
}
export
const
getAppStatistics
:
Fetcher
<
AppStatisticsResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
getAppStatistics
:
Fetcher
<
AppStatisticsResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
AppStatisticsResponse
>
return
get
<
AppStatisticsResponse
>
(
url
,
{
params
})
}
}
export
const
getAppDailyEndUsers
:
Fetcher
<
AppDailyEndUsersResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
getAppDailyEndUsers
:
Fetcher
<
AppDailyEndUsersResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
AppDailyEndUsersResponse
>
return
get
<
AppDailyEndUsersResponse
>
(
url
,
{
params
})
}
}
export
const
getAppTokenCosts
:
Fetcher
<
AppTokenCostsResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
getAppTokenCosts
:
Fetcher
<
AppTokenCostsResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
AppTokenCostsResponse
>
return
get
<
AppTokenCostsResponse
>
(
url
,
{
params
})
}
}
export
const
updateAppModelConfig
:
Fetcher
<
UpdateAppModelConfigResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateAppModelConfig
:
Fetcher
<
UpdateAppModelConfigResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
UpdateAppModelConfigResponse
>
return
post
<
UpdateAppModelConfigResponse
>
(
url
,
{
body
})
}
}
// For temp testing
// For temp testing
export
const
fetchAppListNoMock
:
Fetcher
<
AppListResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchAppListNoMock
:
Fetcher
<
AppListResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
params
)
as
Promise
<
AppListResponse
>
return
get
<
AppListResponse
>
(
url
,
params
)
}
}
export
const
fetchApiKeysList
:
Fetcher
<
ApikeysListResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchApiKeysList
:
Fetcher
<
ApikeysListResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
params
)
as
Promise
<
ApikeysListResponse
>
return
get
<
ApikeysListResponse
>
(
url
,
params
)
}
}
export
const
delApikey
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
delApikey
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
del
(
url
,
params
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
url
,
params
)
}
}
export
const
createApikey
:
Fetcher
<
CreateApiKeyResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
createApikey
:
Fetcher
<
CreateApiKeyResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
body
)
as
Promise
<
CreateApiKeyResponse
>
return
post
<
CreateApiKeyResponse
>
(
url
,
body
)
}
}
export
const
validateOpenAIKey
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
}
}
>
=
({
url
,
body
})
=>
{
export
const
validateOpenAIKey
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
ValidateOpenAIKeyResponse
>
return
post
<
ValidateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
updateOpenAIKey
:
Fetcher
<
UpdateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
}
}
>
=
({
url
,
body
})
=>
{
export
const
updateOpenAIKey
:
Fetcher
<
UpdateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
UpdateOpenAIKeyResponse
>
return
post
<
UpdateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
generationIntroduction
:
Fetcher
<
GenerationIntroductionResponse
,
{
url
:
string
;
body
:
{
prompt_template
:
string
}
}
>
=
({
url
,
body
})
=>
{
export
const
generationIntroduction
:
Fetcher
<
GenerationIntroductionResponse
,
{
url
:
string
;
body
:
{
prompt_template
:
string
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
GenerationIntroductionResponse
>
return
post
<
GenerationIntroductionResponse
>
(
url
,
{
body
})
}
}
web/service/base.ts
View file @
1de48f33
/* eslint-disable no-new, prefer-promise-reject-errors */
import
{
API_PREFIX
,
IS_CE_EDITION
,
PUBLIC_API_PREFIX
}
from
'@/config'
import
{
API_PREFIX
,
IS_CE_EDITION
,
PUBLIC_API_PREFIX
}
from
'@/config'
import
Toast
from
'@/app/components/base/toast'
import
Toast
from
'@/app/components/base/toast'
import
type
{
MessageEnd
,
ThoughtItem
}
from
'@/app/components/app/chat/type'
import
type
{
MessageEnd
,
ThoughtItem
}
from
'@/app/components/app/chat/type'
...
@@ -50,6 +49,17 @@ type IOtherOptions = {
...
@@ -50,6 +49,17 @@ type IOtherOptions = {
getAbortController
?:
(
abortController
:
AbortController
)
=>
void
getAbortController
?:
(
abortController
:
AbortController
)
=>
void
}
}
type
ResponseError
=
{
code
:
string
message
:
string
status
:
number
}
type
FetchOptionType
=
Omit
<
RequestInit
,
'body'
>
&
{
params
?:
Record
<
string
,
any
>
body
?:
BodyInit
|
Record
<
string
,
any
>
|
null
}
function
unicodeToChar
(
text
:
string
)
{
function
unicodeToChar
(
text
:
string
)
{
if
(
!
text
)
if
(
!
text
)
return
''
return
''
...
@@ -146,17 +156,17 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
...
@@ -146,17 +156,17 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
read
()
read
()
}
}
const
baseFetch
=
(
const
baseFetch
=
<
T
>
(
url
:
string
,
url
:
string
,
fetchOptions
:
any
,
fetchOptions
:
FetchOptionType
,
{
{
isPublicAPI
=
false
,
isPublicAPI
=
false
,
bodyStringify
=
true
,
bodyStringify
=
true
,
needAllResponseContent
,
needAllResponseContent
,
deleteContentType
,
deleteContentType
,
}:
IOtherOptions
,
}:
IOtherOptions
,
)
=>
{
)
:
Promise
<
T
>
=>
{
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
const
options
:
typeof
baseOptions
&
FetchOptionType
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
if
(
isPublicAPI
)
{
if
(
isPublicAPI
)
{
const
sharedToken
=
globalThis
.
location
.
pathname
.
split
(
'/'
).
slice
(
-
1
)[
0
]
const
sharedToken
=
globalThis
.
location
.
pathname
.
split
(
'/'
).
slice
(
-
1
)[
0
]
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
...
@@ -209,27 +219,27 @@ const baseFetch = (
...
@@ -209,27 +219,27 @@ const baseFetch = (
},
TIME_OUT
)
},
TIME_OUT
)
}),
}),
new
Promise
((
resolve
,
reject
)
=>
{
new
Promise
((
resolve
,
reject
)
=>
{
globalThis
.
fetch
(
urlWithPrefix
,
options
)
globalThis
.
fetch
(
urlWithPrefix
,
options
as
RequestInit
)
.
then
((
res
:
any
)
=>
{
.
then
((
res
)
=>
{
const
resClone
=
res
.
clone
()
const
resClone
=
res
.
clone
()
// Error handler
// Error handler
if
(
!
/^
(
2|3
)\d{2}
$/
.
test
(
res
.
status
))
{
if
(
!
/^
(
2|3
)\d{2}
$/
.
test
(
String
(
res
.
status
)
))
{
const
bodyJson
=
res
.
json
()
const
bodyJson
=
res
.
json
()
switch
(
res
.
status
)
{
switch
(
res
.
status
)
{
case
401
:
{
case
401
:
{
if
(
isPublicAPI
)
{
if
(
isPublicAPI
)
{
Toast
.
notify
({
type
:
'error'
,
message
:
'Invalid token'
})
Toast
.
notify
({
type
:
'error'
,
message
:
'Invalid token'
})
return
bodyJson
.
then
((
data
:
any
)
=>
Promise
.
reject
(
data
))
return
bodyJson
.
then
((
data
:
T
)
=>
Promise
.
reject
(
data
))
}
}
const
loginUrl
=
`
${
globalThis
.
location
.
origin
}
/signin`
const
loginUrl
=
`
${
globalThis
.
location
.
origin
}
/signin`
if
(
IS_CE_EDITION
)
{
if
(
IS_CE_EDITION
)
{
bodyJson
.
then
((
data
:
any
)
=>
{
bodyJson
.
then
((
data
:
ResponseError
)
=>
{
if
(
data
.
code
===
'not_setup'
)
{
if
(
data
.
code
===
'not_setup'
)
{
globalThis
.
location
.
href
=
`
${
globalThis
.
location
.
origin
}
/install`
globalThis
.
location
.
href
=
`
${
globalThis
.
location
.
origin
}
/install`
}
}
else
{
else
{
if
(
location
.
pathname
===
'/signin'
)
{
if
(
location
.
pathname
===
'/signin'
)
{
bodyJson
.
then
((
data
:
any
)
=>
{
bodyJson
.
then
((
data
:
ResponseError
)
=>
{
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
})
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
})
})
})
}
}
...
@@ -238,27 +248,23 @@ const baseFetch = (
...
@@ -238,27 +248,23 @@ const baseFetch = (
}
}
}
}
})
})
return
Promise
.
reject
()
return
Promise
.
reject
(
Error
(
'Unauthorized'
)
)
}
}
globalThis
.
location
.
href
=
loginUrl
globalThis
.
location
.
href
=
loginUrl
break
break
}
}
case
403
:
case
403
:
new
Promise
(()
=>
{
bodyJson
.
then
((
data
:
ResponseError
)
=>
{
bodyJson
.
then
((
data
:
any
)
=>
{
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
})
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
})
if
(
data
.
code
===
'already_setup'
)
if
(
data
.
code
===
'already_setup'
)
globalThis
.
location
.
href
=
`
${
globalThis
.
location
.
origin
}
/signin`
globalThis
.
location
.
href
=
`
${
globalThis
.
location
.
origin
}
/signin`
})
})
})
break
break
// fall through
// fall through
default
:
default
:
new
Promise
(()
=>
{
bodyJson
.
then
((
data
:
ResponseError
)
=>
{
bodyJson
.
then
((
data
:
any
)
=>
{
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
})
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
})
})
})
})
}
}
return
Promise
.
reject
(
resClone
)
return
Promise
.
reject
(
resClone
)
}
}
...
@@ -270,7 +276,7 @@ const baseFetch = (
...
@@ -270,7 +276,7 @@ const baseFetch = (
}
}
// return data
// return data
const
data
=
options
.
headers
.
get
(
'Content-type'
)
===
ContentType
.
download
?
res
.
blob
()
:
res
.
json
()
const
data
:
Promise
<
T
>
=
options
.
headers
.
get
(
'Content-type'
)
===
ContentType
.
download
?
res
.
blob
()
:
res
.
json
()
resolve
(
needAllResponseContent
?
resClone
:
data
)
resolve
(
needAllResponseContent
?
resClone
:
data
)
})
})
...
@@ -279,7 +285,7 @@ const baseFetch = (
...
@@ -279,7 +285,7 @@ const baseFetch = (
reject
(
err
)
reject
(
err
)
})
})
}),
}),
])
])
as
Promise
<
T
>
}
}
export
const
upload
=
(
options
:
any
):
Promise
<
any
>
=>
{
export
const
upload
=
(
options
:
any
):
Promise
<
any
>
=>
{
...
@@ -315,7 +321,7 @@ export const upload = (options: any): Promise<any> => {
...
@@ -315,7 +321,7 @@ export const upload = (options: any): Promise<any> => {
})
})
}
}
export
const
ssePost
=
(
url
:
string
,
fetchOptions
:
any
,
{
isPublicAPI
=
false
,
onData
,
onCompleted
,
onThought
,
onMessageEnd
,
onError
,
getAbortController
}:
IOtherOptions
)
=>
{
export
const
ssePost
=
(
url
:
string
,
fetchOptions
:
FetchOptionType
,
{
isPublicAPI
=
false
,
onData
,
onCompleted
,
onThought
,
onMessageEnd
,
onError
,
getAbortController
}:
IOtherOptions
)
=>
{
const
abortController
=
new
AbortController
()
const
abortController
=
new
AbortController
()
const
options
=
Object
.
assign
({},
baseOptions
,
{
const
options
=
Object
.
assign
({},
baseOptions
,
{
...
@@ -336,15 +342,12 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
...
@@ -336,15 +342,12 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
if
(
body
)
if
(
body
)
options
.
body
=
JSON
.
stringify
(
body
)
options
.
body
=
JSON
.
stringify
(
body
)
globalThis
.
fetch
(
urlWithPrefix
,
options
)
globalThis
.
fetch
(
urlWithPrefix
,
options
as
RequestInit
)
.
then
((
res
:
any
)
=>
{
.
then
((
res
)
=>
{
// debugger
if
(
!
/^
(
2|3
)\d{2}
$/
.
test
(
String
(
res
.
status
)))
{
if
(
!
/^
(
2|3
)\d{2}
$/
.
test
(
res
.
status
))
{
new
Promise
(()
=>
{
res
.
json
().
then
((
data
:
any
)
=>
{
res
.
json
().
then
((
data
:
any
)
=>
{
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
||
'Server Error'
})
Toast
.
notify
({
type
:
'error'
,
message
:
data
.
message
||
'Server Error'
})
})
})
})
onError
?.(
'Server Error'
)
onError
?.(
'Server Error'
)
return
return
}
}
...
@@ -365,47 +368,49 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
...
@@ -365,47 +368,49 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
})
})
}
}
export
const
request
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
// base request
return
baseFetch
(
url
,
options
,
otherOptions
||
{})
export
const
request
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
baseFetch
<
T
>
(
url
,
options
,
otherOptions
||
{})
}
}
export
const
get
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
// request methods
return
request
(
url
,
Object
.
assign
({},
options
,
{
method
:
'GET'
}),
otherOptions
)
export
const
get
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
request
<
T
>
(
url
,
Object
.
assign
({},
options
,
{
method
:
'GET'
}),
otherOptions
)
}
}
// For public API
// For public API
export
const
getPublic
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
getPublic
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
get
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
return
get
<
T
>
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
}
}
export
const
post
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
post
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
request
(
url
,
Object
.
assign
({},
options
,
{
method
:
'POST'
}),
otherOptions
)
return
request
<
T
>
(
url
,
Object
.
assign
({},
options
,
{
method
:
'POST'
}),
otherOptions
)
}
}
export
const
postPublic
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
postPublic
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
post
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
return
post
<
T
>
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
}
}
export
const
put
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
put
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
request
(
url
,
Object
.
assign
({},
options
,
{
method
:
'PUT'
}),
otherOptions
)
return
request
<
T
>
(
url
,
Object
.
assign
({},
options
,
{
method
:
'PUT'
}),
otherOptions
)
}
}
export
const
putPublic
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
putPublic
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
put
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
return
put
<
T
>
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
}
}
export
const
del
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
del
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
request
(
url
,
Object
.
assign
({},
options
,
{
method
:
'DELETE'
}),
otherOptions
)
return
request
<
T
>
(
url
,
Object
.
assign
({},
options
,
{
method
:
'DELETE'
}),
otherOptions
)
}
}
export
const
delPublic
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
delPublic
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
del
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
return
del
<
T
>
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
}
}
export
const
patch
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
patch
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
request
(
url
,
Object
.
assign
({},
options
,
{
method
:
'PATCH'
}),
otherOptions
)
return
request
<
T
>
(
url
,
Object
.
assign
({},
options
,
{
method
:
'PATCH'
}),
otherOptions
)
}
}
export
const
patchPublic
=
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
export
const
patchPublic
=
<
T
>
(
url
:
string
,
options
=
{},
otherOptions
?:
IOtherOptions
)
=>
{
return
patch
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
return
patch
<
T
>
(
url
,
options
,
{
...
otherOptions
,
isPublicAPI
:
true
})
}
}
web/service/common.ts
View file @
1de48f33
...
@@ -16,173 +16,173 @@ import type {
...
@@ -16,173 +16,173 @@ import type {
import
type
{
BackendModel
,
ProviderMap
}
from
'@/app/components/header/account-setting/model-page/declarations'
import
type
{
BackendModel
,
ProviderMap
}
from
'@/app/components/header/account-setting/model-page/declarations'
export
const
login
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
login
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
setup
:
Fetcher
<
CommonResponse
,
{
body
:
Record
<
string
,
any
>
}
>
=
({
body
})
=>
{
export
const
setup
:
Fetcher
<
CommonResponse
,
{
body
:
Record
<
string
,
any
>
}
>
=
({
body
})
=>
{
return
post
(
'/setup'
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
'/setup'
,
{
body
})
}
}
export
const
fetchSetupStatus
=
()
=>
{
export
const
fetchSetupStatus
=
()
=>
{
return
get
(
'/setup'
)
as
Promise
<
SetupStatusResponse
>
return
get
<
SetupStatusResponse
>
(
'/setup'
)
}
}
export
const
fetchUserProfile
:
Fetcher
<
UserProfileOriginResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchUserProfile
:
Fetcher
<
UserProfileOriginResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
params
,
{
needAllResponseContent
:
true
})
as
Promise
<
UserProfileOriginResponse
>
return
get
<
UserProfileOriginResponse
>
(
url
,
params
,
{
needAllResponseContent
:
true
})
}
}
export
const
updateUserProfile
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateUserProfile
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
logout
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
logout
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
params
)
as
Promise
<
CommonResponse
>
return
get
<
CommonResponse
>
(
url
,
params
)
}
}
export
const
fetchLanggeniusVersion
:
Fetcher
<
LangGeniusVersionResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchLanggeniusVersion
:
Fetcher
<
LangGeniusVersionResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
LangGeniusVersionResponse
>
return
get
<
LangGeniusVersionResponse
>
(
url
,
{
params
})
}
}
export
const
oauth
:
Fetcher
<
OauthResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
oauth
:
Fetcher
<
OauthResponse
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
OauthResponse
>
return
get
<
OauthResponse
>
(
url
,
{
params
})
}
}
export
const
oneMoreStep
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
oneMoreStep
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
fetchMembers
:
Fetcher
<
{
accounts
:
Member
[]
|
null
},
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchMembers
:
Fetcher
<
{
accounts
:
Member
[]
|
null
},
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
{
accounts
:
Member
[]
|
null
}
>
return
get
<
{
accounts
:
Member
[]
|
null
}
>
(
url
,
{
params
})
}
}
export
const
fetchProviders
:
Fetcher
<
Provider
[]
|
null
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchProviders
:
Fetcher
<
Provider
[]
|
null
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
Provider
[]
|
null
>
return
get
<
Provider
[]
|
null
>
(
url
,
{
params
})
}
}
export
const
validateProviderKey
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
}
}
>
=
({
url
,
body
})
=>
{
export
const
validateProviderKey
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
ValidateOpenAIKeyResponse
>
return
post
<
ValidateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
updateProviderAIKey
:
Fetcher
<
UpdateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
|
ProviderAzureToken
|
ProviderAnthropicToken
}
}
>
=
({
url
,
body
})
=>
{
export
const
updateProviderAIKey
:
Fetcher
<
UpdateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
token
:
string
|
ProviderAzureToken
|
ProviderAnthropicToken
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
UpdateOpenAIKeyResponse
>
return
post
<
UpdateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
fetchAccountIntegrates
:
Fetcher
<
{
data
:
AccountIntegrate
[]
|
null
},
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchAccountIntegrates
:
Fetcher
<
{
data
:
AccountIntegrate
[]
|
null
},
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
{
data
:
AccountIntegrate
[]
|
null
}
>
return
get
<
{
data
:
AccountIntegrate
[]
|
null
}
>
(
url
,
{
params
})
}
}
export
const
inviteMember
:
Fetcher
<
InvitationResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
inviteMember
:
Fetcher
<
InvitationResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
InvitationResponse
>
return
post
<
InvitationResponse
>
(
url
,
{
body
})
}
}
export
const
updateMemberRole
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
updateMemberRole
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
put
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
put
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
deleteMemberOrCancelInvitation
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
deleteMemberOrCancelInvitation
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
del
(
url
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
url
)
}
}
export
const
fetchFilePreview
:
Fetcher
<
{
content
:
string
},
{
fileID
:
string
}
>
=
({
fileID
})
=>
{
export
const
fetchFilePreview
:
Fetcher
<
{
content
:
string
},
{
fileID
:
string
}
>
=
({
fileID
})
=>
{
return
get
(
`/files/
${
fileID
}
/preview`
)
as
Promise
<
{
content
:
string
}
>
return
get
<
{
content
:
string
}
>
(
`/files/
${
fileID
}
/preview`
)
}
}
export
const
fetchCurrentWorkspace
:
Fetcher
<
ICurrentWorkspace
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchCurrentWorkspace
:
Fetcher
<
ICurrentWorkspace
,
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
ICurrentWorkspace
>
return
get
<
ICurrentWorkspace
>
(
url
,
{
params
})
}
}
export
const
fetchWorkspaces
:
Fetcher
<
{
workspaces
:
IWorkspace
[]
},
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
export
const
fetchWorkspaces
:
Fetcher
<
{
workspaces
:
IWorkspace
[]
},
{
url
:
string
;
params
:
Record
<
string
,
any
>
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
{
workspaces
:
IWorkspace
[]
}
>
return
get
<
{
workspaces
:
IWorkspace
[]
}
>
(
url
,
{
params
})
}
}
export
const
switchWorkspace
:
Fetcher
<
CommonResponse
&
{
new_tenant
:
IWorkspace
},
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
export
const
switchWorkspace
:
Fetcher
<
CommonResponse
&
{
new_tenant
:
IWorkspace
},
{
url
:
string
;
body
:
Record
<
string
,
any
>
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
&
{
new_tenant
:
IWorkspace
}
>
return
post
<
CommonResponse
&
{
new_tenant
:
IWorkspace
}
>
(
url
,
{
body
})
}
}
export
const
fetchDataSource
:
Fetcher
<
{
data
:
DataSourceNotion
[]
},
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchDataSource
:
Fetcher
<
{
data
:
DataSourceNotion
[]
},
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
)
as
Promise
<
{
data
:
DataSourceNotion
[]
}
>
return
get
<
{
data
:
DataSourceNotion
[]
}
>
(
url
)
}
}
export
const
syncDataSourceNotion
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
syncDataSourceNotion
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
)
as
Promise
<
CommonResponse
>
return
get
<
CommonResponse
>
(
url
)
}
}
export
const
updateDataSourceNotionAction
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
updateDataSourceNotionAction
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
patch
(
url
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
url
)
}
}
export
const
fetchPluginProviders
:
Fetcher
<
PluginProvider
[]
|
null
,
string
>
=
(
url
)
=>
{
export
const
fetchPluginProviders
:
Fetcher
<
PluginProvider
[]
|
null
,
string
>
=
(
url
)
=>
{
return
get
(
url
)
as
Promise
<
PluginProvider
[]
|
null
>
return
get
<
PluginProvider
[]
|
null
>
(
url
)
}
}
export
const
validatePluginProviderKey
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
credentials
:
any
}
}
>
=
({
url
,
body
})
=>
{
export
const
validatePluginProviderKey
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
credentials
:
any
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
ValidateOpenAIKeyResponse
>
return
post
<
ValidateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
updatePluginProviderAIKey
:
Fetcher
<
UpdateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
credentials
:
any
}
}
>
=
({
url
,
body
})
=>
{
export
const
updatePluginProviderAIKey
:
Fetcher
<
UpdateOpenAIKeyResponse
,
{
url
:
string
;
body
:
{
credentials
:
any
}
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
UpdateOpenAIKeyResponse
>
return
post
<
UpdateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
invitationCheck
:
Fetcher
<
CommonResponse
&
{
is_valid
:
boolean
;
workspace_name
:
string
},
{
url
:
string
;
params
:
{
workspace_id
:
string
;
email
:
string
;
token
:
string
}
}
>
=
({
url
,
params
})
=>
{
export
const
invitationCheck
:
Fetcher
<
CommonResponse
&
{
is_valid
:
boolean
;
workspace_name
:
string
},
{
url
:
string
;
params
:
{
workspace_id
:
string
;
email
:
string
;
token
:
string
}
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
CommonResponse
&
{
is_valid
:
boolean
;
workspace_name
:
string
}
>
return
get
<
CommonResponse
&
{
is_valid
:
boolean
;
workspace_name
:
string
}
>
(
url
,
{
params
})
}
}
export
const
activateMember
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
export
const
activateMember
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
fetchModelProviders
:
Fetcher
<
ProviderMap
,
string
>
=
(
url
)
=>
{
export
const
fetchModelProviders
:
Fetcher
<
ProviderMap
,
string
>
=
(
url
)
=>
{
return
get
(
url
)
as
Promise
<
ProviderMap
>
return
get
<
ProviderMap
>
(
url
)
}
}
export
const
fetchModelList
:
Fetcher
<
BackendModel
[],
string
>
=
(
url
)
=>
{
export
const
fetchModelList
:
Fetcher
<
BackendModel
[],
string
>
=
(
url
)
=>
{
return
get
(
url
)
as
Promise
<
BackendModel
[]
>
return
get
<
BackendModel
[]
>
(
url
)
}
}
export
const
validateModelProvider
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
export
const
validateModelProvider
:
Fetcher
<
ValidateOpenAIKeyResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
ValidateOpenAIKeyResponse
>
return
post
<
ValidateOpenAIKeyResponse
>
(
url
,
{
body
})
}
}
export
const
setModelProvider
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
export
const
setModelProvider
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
deleteModelProvider
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
deleteModelProvider
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
del
(
url
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
url
)
}
}
export
const
changeModelProviderPriority
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
export
const
changeModelProviderPriority
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
setModelProviderModel
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
export
const
setModelProviderModel
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
deleteModelProviderModel
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
deleteModelProviderModel
:
Fetcher
<
CommonResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
del
(
url
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
url
)
}
}
export
const
getPayUrl
:
Fetcher
<
{
url
:
string
},
string
>
=
(
url
)
=>
{
export
const
getPayUrl
:
Fetcher
<
{
url
:
string
},
string
>
=
(
url
)
=>
{
return
get
(
url
)
as
Promise
<
{
url
:
string
}
>
return
get
<
{
url
:
string
}
>
(
url
)
}
}
export
const
fetchDefaultModal
:
Fetcher
<
BackendModel
,
string
>
=
(
url
)
=>
{
export
const
fetchDefaultModal
:
Fetcher
<
BackendModel
,
string
>
=
(
url
)
=>
{
return
get
(
url
)
as
Promise
<
BackendModel
>
return
get
<
BackendModel
>
(
url
)
}
}
export
const
updateDefaultModel
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
export
const
updateDefaultModel
:
Fetcher
<
CommonResponse
,
{
url
:
string
;
body
:
any
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
CommonResponse
>
return
post
<
CommonResponse
>
(
url
,
{
body
})
}
}
export
const
submitFreeQuota
:
Fetcher
<
{
type
:
string
;
redirect_url
?:
string
;
result
?:
string
},
string
>
=
(
url
)
=>
{
export
const
submitFreeQuota
:
Fetcher
<
{
type
:
string
;
redirect_url
?:
string
;
result
?:
string
},
string
>
=
(
url
)
=>
{
return
post
(
url
)
as
Promise
<
{
type
:
string
;
redirect_url
?:
string
;
result
?:
string
}
>
return
post
<
{
type
:
string
;
redirect_url
?:
string
;
result
?:
string
}
>
(
url
)
}
}
export
const
fetchFileUploadConfig
:
Fetcher
<
FileUploadConfigResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchFileUploadConfig
:
Fetcher
<
FileUploadConfigResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
)
as
Promise
<
FileUploadConfigResponse
>
return
get
<
FileUploadConfigResponse
>
(
url
)
}
}
export
const
fetchDocumentsLimit
:
Fetcher
<
DocumentsLimitResponse
,
string
>
=
(
url
)
=>
{
export
const
fetchDocumentsLimit
:
Fetcher
<
DocumentsLimitResponse
,
string
>
=
(
url
)
=>
{
return
get
(
url
)
as
Promise
<
DocumentsLimitResponse
>
return
get
<
DocumentsLimitResponse
>
(
url
)
}
}
export
const
fetchSparkFreeQuotaVerify
:
Fetcher
<
{
result
:
string
;
flag
:
boolean
;
reason
:
string
},
string
>
=
(
url
)
=>
{
export
const
fetchSparkFreeQuotaVerify
:
Fetcher
<
{
result
:
string
;
flag
:
boolean
;
reason
:
string
},
string
>
=
(
url
)
=>
{
...
...
web/service/datasets.ts
View file @
1de48f33
...
@@ -40,155 +40,155 @@ export type SortType = 'created_at' | 'hit_count' | '-created_at' | '-hit_count'
...
@@ -40,155 +40,155 @@ export type SortType = 'created_at' | 'hit_count' | '-created_at' | '-hit_count'
export
type
MetadataType
=
'all'
|
'only'
|
'without'
export
type
MetadataType
=
'all'
|
'only'
|
'without'
export
const
fetchDataDetail
:
Fetcher
<
DataSet
,
string
>
=
(
datasetId
:
string
)
=>
{
export
const
fetchDataDetail
:
Fetcher
<
DataSet
,
string
>
=
(
datasetId
:
string
)
=>
{
return
get
(
`/datasets/
${
datasetId
}
`
)
as
Promise
<
DataSet
>
return
get
<
DataSet
>
(
`/datasets/
${
datasetId
}
`
)
}
}
export
const
updateDatasetSetting
:
Fetcher
<
DataSet
,
{
datasetId
:
string
;
body
:
Partial
<
Pick
<
DataSet
,
'name'
|
'description'
|
'permission'
|
'indexing_technique'
>>
}
>
=
({
datasetId
,
body
})
=>
{
export
const
updateDatasetSetting
:
Fetcher
<
DataSet
,
{
datasetId
:
string
;
body
:
Partial
<
Pick
<
DataSet
,
'name'
|
'description'
|
'permission'
|
'indexing_technique'
>>
}
>
=
({
datasetId
,
body
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
`
,
{
body
})
as
Promise
<
DataSet
>
return
patch
<
DataSet
>
(
`/datasets/
${
datasetId
}
`
,
{
body
})
}
}
export
const
fetchDatasetRelatedApps
:
Fetcher
<
RelatedAppResponse
,
string
>
=
(
datasetId
:
string
)
=>
{
export
const
fetchDatasetRelatedApps
:
Fetcher
<
RelatedAppResponse
,
string
>
=
(
datasetId
:
string
)
=>
{
return
get
(
`/datasets/
${
datasetId
}
/related-apps`
)
as
Promise
<
RelatedAppResponse
>
return
get
<
RelatedAppResponse
>
(
`/datasets/
${
datasetId
}
/related-apps`
)
}
}
export
const
fetchDatasets
:
Fetcher
<
DataSetListResponse
,
{
url
:
string
;
params
:
{
page
:
number
;
ids
?:
string
[];
limit
?:
number
}
}
>
=
({
url
,
params
})
=>
{
export
const
fetchDatasets
:
Fetcher
<
DataSetListResponse
,
{
url
:
string
;
params
:
{
page
:
number
;
ids
?:
string
[];
limit
?:
number
}
}
>
=
({
url
,
params
})
=>
{
const
urlParams
=
qs
.
stringify
(
params
,
{
indices
:
false
})
const
urlParams
=
qs
.
stringify
(
params
,
{
indices
:
false
})
return
get
(
`
${
url
}
?
${
urlParams
}
`
)
as
Promise
<
DataSetListResponse
>
return
get
<
DataSetListResponse
>
(
`
${
url
}
?
${
urlParams
}
`
)
}
}
export
const
createEmptyDataset
:
Fetcher
<
DataSet
,
{
name
:
string
}
>
=
({
name
})
=>
{
export
const
createEmptyDataset
:
Fetcher
<
DataSet
,
{
name
:
string
}
>
=
({
name
})
=>
{
return
post
(
'/datasets'
,
{
body
:
{
name
}
})
as
Promise
<
DataSet
>
return
post
<
DataSet
>
(
'/datasets'
,
{
body
:
{
name
}
})
}
}
export
const
deleteDataset
:
Fetcher
<
DataSet
,
string
>
=
(
datasetID
)
=>
{
export
const
deleteDataset
:
Fetcher
<
DataSet
,
string
>
=
(
datasetID
)
=>
{
return
del
(
`/datasets/
${
datasetID
}
`
)
as
Promise
<
DataSet
>
return
del
<
DataSet
>
(
`/datasets/
${
datasetID
}
`
)
}
}
export
const
fetchDefaultProcessRule
:
Fetcher
<
ProcessRuleResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchDefaultProcessRule
:
Fetcher
<
ProcessRuleResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
)
as
Promise
<
ProcessRuleResponse
>
return
get
<
ProcessRuleResponse
>
(
url
)
}
}
export
const
fetchProcessRule
:
Fetcher
<
ProcessRuleResponse
,
{
params
:
{
documentId
:
string
}
}
>
=
({
params
:
{
documentId
}
})
=>
{
export
const
fetchProcessRule
:
Fetcher
<
ProcessRuleResponse
,
{
params
:
{
documentId
:
string
}
}
>
=
({
params
:
{
documentId
}
})
=>
{
return
get
(
'/datasets/process-rule'
,
{
params
:
{
document_id
:
documentId
}
})
as
Promise
<
ProcessRuleResponse
>
return
get
<
ProcessRuleResponse
>
(
'/datasets/process-rule'
,
{
params
:
{
document_id
:
documentId
}
})
}
}
export
const
fetchDocuments
:
Fetcher
<
DocumentListResponse
,
{
datasetId
:
string
;
params
:
{
keyword
:
string
;
page
:
number
;
limit
:
number
;
sort
?:
SortType
}
}
>
=
({
datasetId
,
params
})
=>
{
export
const
fetchDocuments
:
Fetcher
<
DocumentListResponse
,
{
datasetId
:
string
;
params
:
{
keyword
:
string
;
page
:
number
;
limit
:
number
;
sort
?:
SortType
}
}
>
=
({
datasetId
,
params
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/documents`
,
{
params
})
as
Promise
<
DocumentListResponse
>
return
get
<
DocumentListResponse
>
(
`/datasets/
${
datasetId
}
/documents`
,
{
params
})
}
}
export
const
createFirstDocument
:
Fetcher
<
createDocumentResponse
,
{
body
:
CreateDocumentReq
}
>
=
({
body
})
=>
{
export
const
createFirstDocument
:
Fetcher
<
createDocumentResponse
,
{
body
:
CreateDocumentReq
}
>
=
({
body
})
=>
{
return
post
(
'/datasets/init'
,
{
body
})
as
Promise
<
createDocumentResponse
>
return
post
<
createDocumentResponse
>
(
'/datasets/init'
,
{
body
})
}
}
export
const
createDocument
:
Fetcher
<
createDocumentResponse
,
{
datasetId
:
string
;
body
:
CreateDocumentReq
}
>
=
({
datasetId
,
body
})
=>
{
export
const
createDocument
:
Fetcher
<
createDocumentResponse
,
{
datasetId
:
string
;
body
:
CreateDocumentReq
}
>
=
({
datasetId
,
body
})
=>
{
return
post
(
`/datasets/
${
datasetId
}
/documents`
,
{
body
})
as
Promise
<
createDocumentResponse
>
return
post
<
createDocumentResponse
>
(
`/datasets/
${
datasetId
}
/documents`
,
{
body
})
}
}
export
const
fetchIndexingEstimate
:
Fetcher
<
IndexingEstimateResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
fetchIndexingEstimate
:
Fetcher
<
IndexingEstimateResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/indexing-estimate`
,
{})
as
Promise
<
IndexingEstimateResponse
>
return
get
<
IndexingEstimateResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/indexing-estimate`
,
{})
}
}
export
const
fetchIndexingEstimateBatch
:
Fetcher
<
IndexingEstimateResponse
,
BatchReq
>
=
({
datasetId
,
batchId
})
=>
{
export
const
fetchIndexingEstimateBatch
:
Fetcher
<
IndexingEstimateResponse
,
BatchReq
>
=
({
datasetId
,
batchId
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/batch/
${
batchId
}
/indexing-estimate`
,
{})
as
Promise
<
IndexingEstimateResponse
>
return
get
<
IndexingEstimateResponse
>
(
`/datasets/
${
datasetId
}
/batch/
${
batchId
}
/indexing-estimate`
,
{})
}
}
export
const
fetchIndexingStatus
:
Fetcher
<
IndexingStatusResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
fetchIndexingStatus
:
Fetcher
<
IndexingStatusResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/indexing-status`
,
{})
as
Promise
<
IndexingStatusResponse
>
return
get
<
IndexingStatusResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/indexing-status`
,
{})
}
}
export
const
fetchIndexingStatusBatch
:
Fetcher
<
IndexingStatusBatchResponse
,
BatchReq
>
=
({
datasetId
,
batchId
})
=>
{
export
const
fetchIndexingStatusBatch
:
Fetcher
<
IndexingStatusBatchResponse
,
BatchReq
>
=
({
datasetId
,
batchId
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/batch/
${
batchId
}
/indexing-status`
,
{})
as
Promise
<
IndexingStatusBatchResponse
>
return
get
<
IndexingStatusBatchResponse
>
(
`/datasets/
${
datasetId
}
/batch/
${
batchId
}
/indexing-status`
,
{})
}
}
export
const
fetchDocumentDetail
:
Fetcher
<
DocumentDetailResponse
,
CommonDocReq
&
{
params
:
{
metadata
?:
MetadataType
}
}
>
=
({
datasetId
,
documentId
,
params
})
=>
{
export
const
fetchDocumentDetail
:
Fetcher
<
DocumentDetailResponse
,
CommonDocReq
&
{
params
:
{
metadata
?:
MetadataType
}
}
>
=
({
datasetId
,
documentId
,
params
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
`
,
{
params
})
as
Promise
<
DocumentDetailResponse
>
return
get
<
DocumentDetailResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
`
,
{
params
})
}
}
export
const
pauseDocIndexing
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
pauseDocIndexing
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/processing/pause`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/processing/pause`
)
}
}
export
const
resumeDocIndexing
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
resumeDocIndexing
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/processing/resume`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/processing/resume`
)
}
}
export
const
deleteDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
deleteDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
del
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
`
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
`
)
}
}
export
const
archiveDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
archiveDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/archive`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/archive`
)
}
}
export
const
unArchiveDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
unArchiveDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/un_archive`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/un_archive`
)
}
}
export
const
enableDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
enableDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/enable`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/enable`
)
}
}
export
const
disableDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
disableDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/disable`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/status/disable`
)
}
}
export
const
syncDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
export
const
syncDocument
:
Fetcher
<
CommonResponse
,
CommonDocReq
>
=
({
datasetId
,
documentId
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/notion/sync`
)
as
Promise
<
CommonResponse
>
return
get
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/notion/sync`
)
}
}
export
const
preImportNotionPages
:
Fetcher
<
{
notion_info
:
DataSourceNotionWorkspace
[]
},
{
url
:
string
;
datasetId
?:
string
}
>
=
({
url
,
datasetId
})
=>
{
export
const
preImportNotionPages
:
Fetcher
<
{
notion_info
:
DataSourceNotionWorkspace
[]
},
{
url
:
string
;
datasetId
?:
string
}
>
=
({
url
,
datasetId
})
=>
{
return
get
(
url
,
{
params
:
{
dataset_id
:
datasetId
}
})
as
Promise
<
{
notion_info
:
DataSourceNotionWorkspace
[]
}
>
return
get
<
{
notion_info
:
DataSourceNotionWorkspace
[]
}
>
(
url
,
{
params
:
{
dataset_id
:
datasetId
}
})
}
}
export
const
modifyDocMetadata
:
Fetcher
<
CommonResponse
,
CommonDocReq
&
{
body
:
{
doc_type
:
string
;
doc_metadata
:
Record
<
string
,
any
>
}
}
>
=
({
datasetId
,
documentId
,
body
})
=>
{
export
const
modifyDocMetadata
:
Fetcher
<
CommonResponse
,
CommonDocReq
&
{
body
:
{
doc_type
:
string
;
doc_metadata
:
Record
<
string
,
any
>
}
}
>
=
({
datasetId
,
documentId
,
body
})
=>
{
return
put
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/metadata`
,
{
body
})
as
Promise
<
CommonResponse
>
return
put
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/metadata`
,
{
body
})
}
}
// apis for segments in a document
// apis for segments in a document
export
const
fetchSegments
:
Fetcher
<
SegmentsResponse
,
CommonDocReq
&
{
params
:
SegmentsQuery
}
>
=
({
datasetId
,
documentId
,
params
})
=>
{
export
const
fetchSegments
:
Fetcher
<
SegmentsResponse
,
CommonDocReq
&
{
params
:
SegmentsQuery
}
>
=
({
datasetId
,
documentId
,
params
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segments`
,
{
params
})
as
Promise
<
SegmentsResponse
>
return
get
<
SegmentsResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segments`
,
{
params
})
}
}
export
const
enableSegment
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
segmentId
:
string
}
>
=
({
datasetId
,
segmentId
})
=>
{
export
const
enableSegment
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
segmentId
:
string
}
>
=
({
datasetId
,
segmentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/segments/
${
segmentId
}
/enable`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/segments/
${
segmentId
}
/enable`
)
}
}
export
const
disableSegment
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
segmentId
:
string
}
>
=
({
datasetId
,
segmentId
})
=>
{
export
const
disableSegment
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
segmentId
:
string
}
>
=
({
datasetId
,
segmentId
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/segments/
${
segmentId
}
/disable`
)
as
Promise
<
CommonResponse
>
return
patch
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/segments/
${
segmentId
}
/disable`
)
}
}
export
const
updateSegment
:
Fetcher
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
},
{
datasetId
:
string
;
documentId
:
string
;
segmentId
:
string
;
body
:
SegmentUpdator
}
>
=
({
datasetId
,
documentId
,
segmentId
,
body
})
=>
{
export
const
updateSegment
:
Fetcher
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
},
{
datasetId
:
string
;
documentId
:
string
;
segmentId
:
string
;
body
:
SegmentUpdator
}
>
=
({
datasetId
,
documentId
,
segmentId
,
body
})
=>
{
return
patch
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segments/
${
segmentId
}
`
,
{
body
})
as
Promise
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
}
>
return
patch
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
}
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segments/
${
segmentId
}
`
,
{
body
})
}
}
export
const
addSegment
:
Fetcher
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
},
{
datasetId
:
string
;
documentId
:
string
;
body
:
SegmentUpdator
}
>
=
({
datasetId
,
documentId
,
body
})
=>
{
export
const
addSegment
:
Fetcher
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
},
{
datasetId
:
string
;
documentId
:
string
;
body
:
SegmentUpdator
}
>
=
({
datasetId
,
documentId
,
body
})
=>
{
return
post
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segment`
,
{
body
})
as
Promise
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
}
>
return
post
<
{
data
:
SegmentDetailModel
;
doc_form
:
string
}
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segment`
,
{
body
})
}
}
export
const
deleteSegment
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
documentId
:
string
;
segmentId
:
string
}
>
=
({
datasetId
,
documentId
,
segmentId
})
=>
{
export
const
deleteSegment
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
documentId
:
string
;
segmentId
:
string
}
>
=
({
datasetId
,
documentId
,
segmentId
})
=>
{
return
del
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segments/
${
segmentId
}
`
)
as
Promise
<
CommonResponse
>
return
del
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/documents/
${
documentId
}
/segments/
${
segmentId
}
`
)
}
}
export
const
segmentBatchImport
:
Fetcher
<
{
job_id
:
string
;
job_status
:
string
},
{
url
:
string
;
body
:
FormData
}
>
=
({
url
,
body
})
=>
{
export
const
segmentBatchImport
:
Fetcher
<
{
job_id
:
string
;
job_status
:
string
},
{
url
:
string
;
body
:
FormData
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
},
{
bodyStringify
:
false
,
deleteContentType
:
true
})
as
Promise
<
{
job_id
:
string
;
job_status
:
string
}
>
return
post
<
{
job_id
:
string
;
job_status
:
string
}
>
(
url
,
{
body
},
{
bodyStringify
:
false
,
deleteContentType
:
true
})
}
}
export
const
checkSegmentBatchImportProgress
:
Fetcher
<
{
job_id
:
string
;
job_status
:
string
},
{
jobID
:
string
}
>
=
({
jobID
})
=>
{
export
const
checkSegmentBatchImportProgress
:
Fetcher
<
{
job_id
:
string
;
job_status
:
string
},
{
jobID
:
string
}
>
=
({
jobID
})
=>
{
return
get
(
`/datasets/batch_import_status/
${
jobID
}
`
)
as
Promise
<
{
job_id
:
string
;
job_status
:
string
}
>
return
get
<
{
job_id
:
string
;
job_status
:
string
}
>
(
`/datasets/batch_import_status/
${
jobID
}
`
)
}
}
// hit testing
// hit testing
export
const
hitTesting
:
Fetcher
<
HitTestingResponse
,
{
datasetId
:
string
;
queryText
:
string
}
>
=
({
datasetId
,
queryText
})
=>
{
export
const
hitTesting
:
Fetcher
<
HitTestingResponse
,
{
datasetId
:
string
;
queryText
:
string
}
>
=
({
datasetId
,
queryText
})
=>
{
return
post
(
`/datasets/
${
datasetId
}
/hit-testing`
,
{
body
:
{
query
:
queryText
}
})
as
Promise
<
HitTestingResponse
>
return
post
<
HitTestingResponse
>
(
`/datasets/
${
datasetId
}
/hit-testing`
,
{
body
:
{
query
:
queryText
}
})
}
}
export
const
fetchTestingRecords
:
Fetcher
<
HitTestingRecordsResponse
,
{
datasetId
:
string
;
params
:
{
page
:
number
;
limit
:
number
}
}
>
=
({
datasetId
,
params
})
=>
{
export
const
fetchTestingRecords
:
Fetcher
<
HitTestingRecordsResponse
,
{
datasetId
:
string
;
params
:
{
page
:
number
;
limit
:
number
}
}
>
=
({
datasetId
,
params
})
=>
{
return
get
(
`/datasets/
${
datasetId
}
/queries`
,
{
params
})
as
Promise
<
HitTestingRecordsResponse
>
return
get
<
HitTestingRecordsResponse
>
(
`/datasets/
${
datasetId
}
/queries`
,
{
params
})
}
}
export
const
fetchFileIndexingEstimate
:
Fetcher
<
FileIndexingEstimateResponse
,
any
>
=
(
body
:
any
)
=>
{
export
const
fetchFileIndexingEstimate
:
Fetcher
<
FileIndexingEstimateResponse
,
any
>
=
(
body
:
any
)
=>
{
return
post
(
'/datasets/indexing-estimate'
,
{
body
})
as
Promise
<
FileIndexingEstimateResponse
>
return
post
<
FileIndexingEstimateResponse
>
(
'/datasets/indexing-estimate'
,
{
body
})
}
}
export
const
fetchNotionPagePreview
:
Fetcher
<
{
content
:
string
},
{
workspaceID
:
string
;
pageID
:
string
;
pageType
:
string
}
>
=
({
workspaceID
,
pageID
,
pageType
})
=>
{
export
const
fetchNotionPagePreview
:
Fetcher
<
{
content
:
string
},
{
workspaceID
:
string
;
pageID
:
string
;
pageType
:
string
}
>
=
({
workspaceID
,
pageID
,
pageType
})
=>
{
return
get
(
`notion/workspaces/
${
workspaceID
}
/pages/
${
pageID
}
/
${
pageType
}
/preview`
)
as
Promise
<
{
content
:
string
}
>
return
get
<
{
content
:
string
}
>
(
`notion/workspaces/
${
workspaceID
}
/pages/
${
pageID
}
/
${
pageType
}
/preview`
)
}
}
web/service/log.ts
View file @
1de48f33
...
@@ -18,42 +18,42 @@ import type {
...
@@ -18,42 +18,42 @@ import type {
}
from
'@/models/log'
}
from
'@/models/log'
export
const
fetchConversationList
:
Fetcher
<
ConversationListResponse
,
{
name
:
string
;
appId
:
string
;
params
?:
Record
<
string
,
any
>
}
>
=
({
appId
,
params
})
=>
{
export
const
fetchConversationList
:
Fetcher
<
ConversationListResponse
,
{
name
:
string
;
appId
:
string
;
params
?:
Record
<
string
,
any
>
}
>
=
({
appId
,
params
})
=>
{
return
get
(
`/console/api/apps/
${
appId
}
/messages`
,
params
)
as
Promise
<
ConversationListResponse
>
return
get
<
ConversationListResponse
>
(
`/console/api/apps/
${
appId
}
/messages`
,
params
)
}
}
// (Text Generation Application) Session List
// (Text Generation Application) Session List
export
const
fetchCompletionConversations
:
Fetcher
<
CompletionConversationsResponse
,
{
url
:
string
;
params
?:
CompletionConversationsRequest
}
>
=
({
url
,
params
})
=>
{
export
const
fetchCompletionConversations
:
Fetcher
<
CompletionConversationsResponse
,
{
url
:
string
;
params
?:
CompletionConversationsRequest
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
CompletionConversationsResponse
>
return
get
<
CompletionConversationsResponse
>
(
url
,
{
params
})
}
}
// (Text Generation Application) Session Detail
// (Text Generation Application) Session Detail
export
const
fetchCompletionConversationDetail
:
Fetcher
<
CompletionConversationFullDetailResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchCompletionConversationDetail
:
Fetcher
<
CompletionConversationFullDetailResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
,
{})
as
Promise
<
CompletionConversationFullDetailResponse
>
return
get
<
CompletionConversationFullDetailResponse
>
(
url
,
{})
}
}
// (Chat Application) Session List
// (Chat Application) Session List
export
const
fetchChatConversations
:
Fetcher
<
ChatConversationsResponse
,
{
url
:
string
;
params
?:
ChatConversationsRequest
}
>
=
({
url
,
params
})
=>
{
export
const
fetchChatConversations
:
Fetcher
<
ChatConversationsResponse
,
{
url
:
string
;
params
?:
ChatConversationsRequest
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
ChatConversationsResponse
>
return
get
<
ChatConversationsResponse
>
(
url
,
{
params
})
}
}
// (Chat Application) Session Detail
// (Chat Application) Session Detail
export
const
fetchChatConversationDetail
:
Fetcher
<
ChatConversationFullDetailResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchChatConversationDetail
:
Fetcher
<
ChatConversationFullDetailResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
,
{})
as
Promise
<
ChatConversationFullDetailResponse
>
return
get
<
ChatConversationFullDetailResponse
>
(
url
,
{})
}
}
// (Chat Application) Message list in one session
// (Chat Application) Message list in one session
export
const
fetchChatMessages
:
Fetcher
<
ChatMessagesResponse
,
{
url
:
string
;
params
:
ChatMessagesRequest
}
>
=
({
url
,
params
})
=>
{
export
const
fetchChatMessages
:
Fetcher
<
ChatMessagesResponse
,
{
url
:
string
;
params
:
ChatMessagesRequest
}
>
=
({
url
,
params
})
=>
{
return
get
(
url
,
{
params
})
as
Promise
<
ChatMessagesResponse
>
return
get
<
ChatMessagesResponse
>
(
url
,
{
params
})
}
}
export
const
updateLogMessageFeedbacks
:
Fetcher
<
LogMessageFeedbacksResponse
,
{
url
:
string
;
body
:
LogMessageFeedbacksRequest
}
>
=
({
url
,
body
})
=>
{
export
const
updateLogMessageFeedbacks
:
Fetcher
<
LogMessageFeedbacksResponse
,
{
url
:
string
;
body
:
LogMessageFeedbacksRequest
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
LogMessageFeedbacksResponse
>
return
post
<
LogMessageFeedbacksResponse
>
(
url
,
{
body
})
}
}
export
const
updateLogMessageAnnotations
:
Fetcher
<
LogMessageAnnotationsResponse
,
{
url
:
string
;
body
:
LogMessageAnnotationsRequest
}
>
=
({
url
,
body
})
=>
{
export
const
updateLogMessageAnnotations
:
Fetcher
<
LogMessageAnnotationsResponse
,
{
url
:
string
;
body
:
LogMessageAnnotationsRequest
}
>
=
({
url
,
body
})
=>
{
return
post
(
url
,
{
body
})
as
Promise
<
LogMessageAnnotationsResponse
>
return
post
<
LogMessageAnnotationsResponse
>
(
url
,
{
body
})
}
}
export
const
fetchAnnotationsCount
:
Fetcher
<
AnnotationsCountResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
export
const
fetchAnnotationsCount
:
Fetcher
<
AnnotationsCountResponse
,
{
url
:
string
}
>
=
({
url
})
=>
{
return
get
(
url
)
as
Promise
<
AnnotationsCountResponse
>
return
get
<
AnnotationsCountResponse
>
(
url
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment