web app support workflow

This commit is contained in:
JzoNg
2024-03-14 21:01:58 +08:00
parent 58922ba40b
commit bcce53a929
5 changed files with 149 additions and 69 deletions

View File

@ -1,4 +1,4 @@
import type { IOnCompleted, IOnData, IOnError, IOnFile, IOnMessageEnd, IOnMessageReplace, IOnThought } from './base'
import type { IOnCompleted, IOnData, IOnError, IOnFile, IOnMessageEnd, IOnMessageReplace, IOnTextChunk, IOnTextReplace, IOnThought, IOnWorkflowFinished, IOnWorkflowStarted } from './base'
import {
del as consoleDel, get as consoleGet, patch as consolePatch, post as consolePost,
delPublic as del, getPublic as get, patchPublic as patch, postPublic as post, ssePost,
@ -65,6 +65,32 @@ export const sendCompletionMessage = async (body: Record<string, any>, { onData,
}, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError, onMessageReplace })
}
export const sendWorkflowMessage = async (
body: Record<string, any>,
{
onTextChunk,
onWorkflowStarted,
onTextReplace,
onWorkflowFinished,
onError,
}: {
onTextChunk: IOnTextChunk
onWorkflowStarted: IOnWorkflowStarted
onWorkflowFinished: IOnWorkflowFinished
onTextReplace: IOnTextReplace
onError: IOnError
},
isInstalledApp: boolean,
installedAppId = '',
) => {
return ssePost(getUrl('workflows/run', isInstalledApp, installedAppId), {
body: {
...body,
response_mode: 'streaming',
},
}, { onTextChunk, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onError, onTextReplace })
}
export const fetchAppInfo = async () => {
return get('/site') as Promise<AppData>
}