@@ -2,7 +2,7 @@ import { parseSSEResponse } from '~utils/sse'
22import { AbstractBot , SendMessageParams } from '../abstract-bot'
33import { requestHostPermission } from '~app/utils/permissions'
44import { ChatError , ErrorCode } from '~utils/errors'
5- import { createConversation } from './api'
5+ import { createConversation , getCsrfToken } from './api'
66import { uuid } from '~utils'
77
88function generateMessageId ( ) {
@@ -11,6 +11,7 @@ function generateMessageId() {
1111
1212interface ConversationContext {
1313 conversationId : string
14+ csrfToken : string
1415 lastMessageId ?: string
1516}
1617
@@ -23,16 +24,17 @@ export class QianwenWebBot extends AbstractBot {
2324 }
2425
2526 if ( ! this . conversationContext ) {
26- const conversationId = await createConversation ( params . prompt )
27- this . conversationContext = { conversationId }
27+ const csrfToken = await getCsrfToken ( )
28+ const conversationId = await createConversation ( params . prompt , csrfToken )
29+ this . conversationContext = { conversationId, csrfToken }
2830 }
2931
3032 const resp = await fetch ( 'https://qianwen.aliyun.com/conversation' , {
3133 method : 'POST' ,
3234 signal : params . signal ,
3335 headers : {
3436 'Content-Type' : 'application/json' ,
35- 'X-Xsrf-Token' : '7a3dae93-1d29-4eb6-9940-34efad5a2b78' ,
37+ 'X-Xsrf-Token' : this . conversationContext . csrfToken ,
3638 } ,
3739 body : JSON . stringify ( {
3840 action : 'next' ,
0 commit comments