| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   IOnCompleted, | 
					
						
							|  |  |  |   IOnData, | 
					
						
							|  |  |  |   IOnError, | 
					
						
							|  |  |  |   IOnFile, | 
					
						
							|  |  |  |   IOnIterationFinished, | 
					
						
							|  |  |  |   IOnIterationNext, | 
					
						
							|  |  |  |   IOnIterationStarted, | 
					
						
							|  |  |  |   IOnLoopFinished, | 
					
						
							|  |  |  |   IOnLoopNext, | 
					
						
							|  |  |  |   IOnLoopStarted, | 
					
						
							|  |  |  |   IOnMessageEnd, | 
					
						
							|  |  |  |   IOnMessageReplace, | 
					
						
							|  |  |  |   IOnNodeFinished, | 
					
						
							|  |  |  |   IOnNodeStarted, | 
					
						
							|  |  |  |   IOnTTSChunk, | 
					
						
							|  |  |  |   IOnTTSEnd, | 
					
						
							|  |  |  |   IOnTextChunk, | 
					
						
							|  |  |  |   IOnTextReplace, | 
					
						
							|  |  |  |   IOnThought, | 
					
						
							|  |  |  |   IOnWorkflowFinished, | 
					
						
							|  |  |  |   IOnWorkflowStarted, | 
					
						
							|  |  |  | } from './base' | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2023-06-28 11:16:54 +08:00
										 |  |  |   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, | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | } from './base' | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  | import type { FeedbackType } from '@/app/components/base/chat/chat/type' | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   AppConversationData, | 
					
						
							|  |  |  |   AppData, | 
					
						
							|  |  |  |   AppMeta, | 
					
						
							|  |  |  |   ConversationItem, | 
					
						
							|  |  |  | } from '@/models/share' | 
					
						
							|  |  |  | import type { ChatConfig } from '@/app/components/base/chat/types' | 
					
						
							| 
									
										
										
										
											2025-05-20 12:07:50 +08:00
										 |  |  | import type { AccessMode } from '@/models/access-control' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 11:16:54 +08:00
										 |  |  | function getAction(action: 'get' | 'post' | 'del' | 'patch', isInstalledApp: boolean) { | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  |   switch (action) { | 
					
						
							|  |  |  |     case 'get': | 
					
						
							|  |  |  |       return isInstalledApp ? consoleGet : get | 
					
						
							|  |  |  |     case 'post': | 
					
						
							|  |  |  |       return isInstalledApp ? consolePost : post | 
					
						
							| 
									
										
										
										
											2023-06-28 11:16:54 +08:00
										 |  |  |     case 'patch': | 
					
						
							|  |  |  |       return isInstalledApp ? consolePatch : patch | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  |     case 'del': | 
					
						
							|  |  |  |       return isInstalledApp ? consoleDel : del | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | export function getUrl(url: string, isInstalledApp: boolean, installedAppId: string) { | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  |   return isInstalledApp ? `installed-apps/${installedAppId}/${url.startsWith('/') ? url.slice(1) : url}` : url | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-09 11:33:58 +08:00
										 |  |  | export const sendChatMessage = async (body: Record<string, any>, { onData, onCompleted, onThought, onFile, onError, getAbortController, onMessageEnd, onMessageReplace, onTTSChunk, onTTSEnd }: { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   onData: IOnData | 
					
						
							|  |  |  |   onCompleted: IOnCompleted | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   onFile: IOnFile | 
					
						
							|  |  |  |   onThought: IOnThought | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |   onError: IOnError | 
					
						
							| 
									
										
										
										
											2023-09-09 19:17:12 +08:00
										 |  |  |   onMessageEnd?: IOnMessageEnd | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   onMessageReplace?: IOnMessageReplace | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   getAbortController?: (abortController: AbortController) => void | 
					
						
							| 
									
										
										
										
											2024-07-09 11:33:58 +08:00
										 |  |  |   onTTSChunk?: IOnTTSChunk | 
					
						
							|  |  |  |   onTTSEnd?: IOnTTSEnd | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | }, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return ssePost(getUrl('chat-messages', isInstalledApp, installedAppId), { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     body: { | 
					
						
							|  |  |  |       ...body, | 
					
						
							|  |  |  |       response_mode: 'streaming', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2024-07-09 11:33:58 +08:00
										 |  |  |   }, { onData, onCompleted, onThought, onFile, isPublicAPI: !isInstalledApp, onError, getAbortController, onMessageEnd, onMessageReplace, onTTSChunk, onTTSEnd }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-12 16:37:03 +08:00
										 |  |  | export const stopChatMessageResponding = async (appId: string, taskId: string, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return getAction('post', isInstalledApp)(getUrl(`chat-messages/${taskId}/stop`, isInstalledApp, installedAppId)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  | export const sendCompletionMessage = async (body: Record<string, any>, { onData, onCompleted, onError, onMessageReplace }: { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   onData: IOnData | 
					
						
							|  |  |  |   onCompleted: IOnCompleted | 
					
						
							|  |  |  |   onError: IOnError | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   onMessageReplace: IOnMessageReplace | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | }, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return ssePost(getUrl('completion-messages', isInstalledApp, installedAppId), { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     body: { | 
					
						
							|  |  |  |       ...body, | 
					
						
							|  |  |  |       response_mode: 'streaming', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-11-06 19:36:32 +08:00
										 |  |  |   }, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError, onMessageReplace }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | export const sendWorkflowMessage = async ( | 
					
						
							|  |  |  |   body: Record<string, any>, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     onWorkflowStarted, | 
					
						
							|  |  |  |     onNodeStarted, | 
					
						
							|  |  |  |     onNodeFinished, | 
					
						
							|  |  |  |     onWorkflowFinished, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     onIterationStart, | 
					
						
							|  |  |  |     onIterationNext, | 
					
						
							|  |  |  |     onIterationFinish, | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |     onLoopStart, | 
					
						
							|  |  |  |     onLoopNext, | 
					
						
							|  |  |  |     onLoopFinish, | 
					
						
							| 
									
										
										
										
											2024-04-28 17:37:00 +08:00
										 |  |  |     onTextChunk, | 
					
						
							|  |  |  |     onTextReplace, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   }: { | 
					
						
							|  |  |  |     onWorkflowStarted: IOnWorkflowStarted | 
					
						
							|  |  |  |     onNodeStarted: IOnNodeStarted | 
					
						
							|  |  |  |     onNodeFinished: IOnNodeFinished | 
					
						
							|  |  |  |     onWorkflowFinished: IOnWorkflowFinished | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     onIterationStart: IOnIterationStarted | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |     onIterationNext: IOnIterationNext | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     onIterationFinish: IOnIterationFinished | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |     onLoopStart: IOnLoopStarted | 
					
						
							|  |  |  |     onLoopNext: IOnLoopNext | 
					
						
							|  |  |  |     onLoopFinish: IOnLoopFinished | 
					
						
							| 
									
										
										
										
											2024-04-28 17:37:00 +08:00
										 |  |  |     onTextChunk: IOnTextChunk | 
					
						
							|  |  |  |     onTextReplace: IOnTextReplace | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   }, | 
					
						
							|  |  |  |   isInstalledApp: boolean, | 
					
						
							|  |  |  |   installedAppId = '', | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  |   return ssePost(getUrl('workflows/run', isInstalledApp, installedAppId), { | 
					
						
							|  |  |  |     body: { | 
					
						
							|  |  |  |       ...body, | 
					
						
							|  |  |  |       response_mode: 'streaming', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |   }, { | 
					
						
							|  |  |  |     onNodeStarted, | 
					
						
							|  |  |  |     onWorkflowStarted, | 
					
						
							|  |  |  |     onWorkflowFinished, | 
					
						
							|  |  |  |     isPublicAPI: !isInstalledApp, | 
					
						
							|  |  |  |     onNodeFinished, | 
					
						
							|  |  |  |     onIterationStart, | 
					
						
							|  |  |  |     onIterationNext, | 
					
						
							|  |  |  |     onIterationFinish, | 
					
						
							|  |  |  |     onLoopStart, | 
					
						
							|  |  |  |     onLoopNext, | 
					
						
							|  |  |  |     onLoopFinish, | 
					
						
							|  |  |  |     onTextChunk, | 
					
						
							|  |  |  |     onTextReplace, | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export const fetchAppInfo = async () => { | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   return get('/site') as Promise<AppData> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 11:16:54 +08:00
										 |  |  | export const fetchConversations = async (isInstalledApp: boolean, installedAppId = '', last_id?: string, pinned?: boolean, limit?: number) => { | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   return getAction('get', isInstalledApp)(getUrl('conversations', isInstalledApp, installedAppId), { params: { ...{ limit: limit || 20 }, ...(last_id ? { last_id } : {}), ...(pinned !== undefined ? { pinned } : {}) } }) as Promise<AppConversationData> | 
					
						
							| 
									
										
										
										
											2023-06-28 11:16:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const pinConversation = async (isInstalledApp: boolean, installedAppId = '', id: string) => { | 
					
						
							|  |  |  |   return getAction('patch', isInstalledApp)(getUrl(`conversations/${id}/pin`, isInstalledApp, installedAppId)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const unpinConversation = async (isInstalledApp: boolean, installedAppId = '', id: string) => { | 
					
						
							|  |  |  |   return getAction('patch', isInstalledApp)(getUrl(`conversations/${id}/unpin`, isInstalledApp, installedAppId)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const delConversation = async (isInstalledApp: boolean, installedAppId = '', id: string) => { | 
					
						
							|  |  |  |   return getAction('del', isInstalledApp)(getUrl(`conversations/${id}`, isInstalledApp, installedAppId)) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-30 17:32:32 +08:00
										 |  |  | export const renameConversation = async (isInstalledApp: boolean, installedAppId = '', id: string, name: string) => { | 
					
						
							|  |  |  |   return getAction('post', isInstalledApp)(getUrl(`conversations/${id}/name`, isInstalledApp, installedAppId), { body: { name } }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-13 22:32:39 +08:00
										 |  |  | export const generationConversationName = async (isInstalledApp: boolean, installedAppId = '', id: string) => { | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   return getAction('post', isInstalledApp)(getUrl(`conversations/${id}/name`, isInstalledApp, installedAppId), { body: { auto_generate: true } }) as Promise<ConversationItem> | 
					
						
							| 
									
										
										
										
											2023-11-13 22:32:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  | export const fetchChatList = async (conversationId: string, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   return getAction('get', isInstalledApp)(getUrl('messages', isInstalledApp, installedAppId), { params: { conversation_id: conversationId, limit: 20, last_id: '' } }) as any | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Abandoned API interface
 | 
					
						
							|  |  |  | // export const fetchAppVariables = async () => {
 | 
					
						
							|  |  |  | //   return get(`variables`)
 | 
					
						
							|  |  |  | // }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // init value. wait for server update
 | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | export const fetchAppParams = async (isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   return (getAction('get', isInstalledApp))(getUrl('parameters', isInstalledApp, installedAppId)) as Promise<ChatConfig> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-15 16:14:49 +08:00
										 |  |  | export const fetchWebSAMLSSOUrl = async (appCode: string, redirectUrl: string) => { | 
					
						
							|  |  |  |   return (getAction('get', false))(getUrl('/enterprise/sso/saml/login', false, ''), { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       app_code: appCode, | 
					
						
							|  |  |  |       redirect_url: redirectUrl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) as Promise<{ url: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchWebOIDCSSOUrl = async (appCode: string, redirectUrl: string) => { | 
					
						
							|  |  |  |   return (getAction('get', false))(getUrl('/enterprise/sso/oidc/login', false, ''), { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       app_code: appCode, | 
					
						
							|  |  |  |       redirect_url: redirectUrl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }) as Promise<{ url: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-21 17:52:41 +08:00
										 |  |  | export const fetchWebOAuth2SSOUrl = async (appCode: string, redirectUrl: string) => { | 
					
						
							|  |  |  |   return (getAction('get', false))(getUrl('/enterprise/sso/oauth2/login', false, ''), { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       app_code: appCode, | 
					
						
							|  |  |  |       redirect_url: redirectUrl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) as Promise<{ url: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  | export const fetchMembersSAMLSSOUrl = async (appCode: string, redirectUrl: string) => { | 
					
						
							|  |  |  |   return (getAction('get', false))(getUrl('/enterprise/sso/members/saml/login', false, ''), { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       app_code: appCode, | 
					
						
							|  |  |  |       redirect_url: redirectUrl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) as Promise<{ url: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchMembersOIDCSSOUrl = async (appCode: string, redirectUrl: string) => { | 
					
						
							|  |  |  |   return (getAction('get', false))(getUrl('/enterprise/sso/members/oidc/login', false, ''), { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       app_code: appCode, | 
					
						
							|  |  |  |       redirect_url: redirectUrl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }) as Promise<{ url: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchMembersOAuth2SSOUrl = async (appCode: string, redirectUrl: string) => { | 
					
						
							|  |  |  |   return (getAction('get', false))(getUrl('/enterprise/sso/members/oauth2/login', false, ''), { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       app_code: appCode, | 
					
						
							|  |  |  |       redirect_url: redirectUrl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) as Promise<{ url: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | export const fetchAppMeta = async (isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   return (getAction('get', isInstalledApp))(getUrl('meta', isInstalledApp, installedAppId)) as Promise<AppMeta> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  | export const updateFeedback = async ({ url, body }: { url: string; body: FeedbackType }, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  |   return (getAction('post', isInstalledApp))(getUrl(url, isInstalledApp, installedAppId), { body }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | export const fetchMoreLikeThis = async (messageId: string, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return (getAction('get', isInstalledApp))(getUrl(`/messages/${messageId}/more-like-this`, isInstalledApp, installedAppId), { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     params: { | 
					
						
							|  |  |  |       response_mode: 'blocking', | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | export const saveMessage = (messageId: string, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return (getAction('post', isInstalledApp))(getUrl('/saved-messages', isInstalledApp, installedAppId), { body: { message_id: messageId } }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | export const fetchSavedMessage = async (isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |   return (getAction('get', isInstalledApp))(getUrl('/saved-messages', isInstalledApp, installedAppId)) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | export const removeMessage = (messageId: string, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return (getAction('del', isInstalledApp))(getUrl(`/saved-messages/${messageId}`, isInstalledApp, installedAppId)) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 16:59:47 +08:00
										 |  |  | export const fetchSuggestedQuestions = (messageId: string, isInstalledApp: boolean, installedAppId = '') => { | 
					
						
							|  |  |  |   return (getAction('get', isInstalledApp))(getUrl(`/messages/${messageId}/suggested-questions`, isInstalledApp, installedAppId)) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-07-07 17:50:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const audioToText = (url: string, isPublicAPI: boolean, body: FormData) => { | 
					
						
							|  |  |  |   return (getAction('post', !isPublicAPI))(url, { body }, { bodyStringify: false, deleteContentType: true }) as Promise<{ text: string }> | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-07-11 15:21:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 01:05:37 +08:00
										 |  |  | export const textToAudio = (url: string, isPublicAPI: boolean, body: FormData) => { | 
					
						
							|  |  |  |   return (getAction('post', !isPublicAPI))(url, { body }, { bodyStringify: false, deleteContentType: true }) as Promise<{ data: string }> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-09 11:33:58 +08:00
										 |  |  | export const textToAudioStream = (url: string, isPublicAPI: boolean, header: { content_type: string }, body: { streaming: boolean; voice?: string; message_id?: string; text?: string | null | undefined }) => { | 
					
						
							|  |  |  |   return (getAction('post', !isPublicAPI))(url, { body, header }, { needAllResponseContent: true }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  | export const fetchAccessToken = async ({ appCode, userId, webAppAccessToken }: { appCode: string, userId?: string, webAppAccessToken?: string | null }) => { | 
					
						
							| 
									
										
										
										
											2023-07-11 15:21:20 +08:00
										 |  |  |   const headers = new Headers() | 
					
						
							|  |  |  |   headers.append('X-App-Code', appCode) | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  |   const params = new URLSearchParams() | 
					
						
							|  |  |  |   webAppAccessToken && params.append('web_app_access_token', webAppAccessToken) | 
					
						
							|  |  |  |   userId && params.append('user_id', userId) | 
					
						
							|  |  |  |   const url = `/passport?${params.toString()}` | 
					
						
							| 
									
										
										
										
											2025-03-31 18:55:42 +08:00
										 |  |  |   return get(url, { headers }) as Promise<{ access_token: string }> | 
					
						
							| 
									
										
										
										
											2023-07-11 15:21:20 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-05-20 12:07:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getAppAccessMode = (appId: string, isInstalledApp: boolean) => { | 
					
						
							|  |  |  |   if (isInstalledApp) | 
					
						
							|  |  |  |     return consoleGet<{ accessMode: AccessMode }>(`/enterprise/webapp/app/access-mode?appId=${appId}`) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return get<{ accessMode: AccessMode }>(`/webapp/access-mode?appId=${appId}`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getUserCanAccess = (appId: string, isInstalledApp: boolean) => { | 
					
						
							|  |  |  |   if (isInstalledApp) | 
					
						
							|  |  |  |     return consoleGet<{ result: boolean }>(`/enterprise/webapp/permission?appId=${appId}`) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return get<{ result: boolean }>(`/webapp/permission?appId=${appId}`) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-06-05 10:55:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getAppAccessModeByAppCode = (appCode: string) => { | 
					
						
							|  |  |  |   return get<{ accessMode: AccessMode }>(`/webapp/access-mode?appCode=${appCode}`) | 
					
						
							|  |  |  | } |