@@ -126,21 +126,41 @@ declare namespace Bob {
126126 'yua' = '尤卡坦玛雅语' ,
127127 'zu' = '祖鲁语' ,
128128 }
129+
129130 type Languages = Array < keyof typeof LanguagesEnum > ;
130131 type supportLanguages = Languages ;
131132 type Language = keyof typeof LanguagesEnum ;
132133
134+
135+ interface DataPayload {
136+ message : string ;
137+ }
138+
139+ interface Disposable {
140+ dispose : ( ) => void ;
141+ }
142+
143+ interface Signal {
144+ send : ( data ?: DataPayload ) => void ;
145+ subscribe : ( callback : ( data ?: DataPayload ) => void ) => Disposable ;
146+ removeAllSubscriber : ( ) => void ;
147+ }
148+
133149 // https://ripperhe.gitee.io/bob/#/plugin/quickstart/translate
134150 type Translate = ( query : TranslateQuery , completion : Completion ) => void ;
135151 type completionResult = { result : Result } ;
136- type CompletionResult = { error : ServiceError } ;
137- type Completion = ( args : completionResult | CompletionResult ) => void ;
152+ type CompletionError = { error : ServiceError } ;
153+ type Completion = ( args : completionResult | CompletionError ) => void ;
154+ type HandleStream = ( args : completionResult ) => void ;
138155 interface TranslateQuery {
139156 text : string ; // 需要翻译的文本
140157 from : Language ; // 用户选中的源语种标准码
141158 to : Language ; // 用户选中的目标语种标准码
142159 detectFrom : Exclude < Language , 'auto' > ; // 检测过后的源语种
143160 detectTo : Exclude < Language , 'auto' > ; // 检测过后的目标语种
161+ cancelSignal : Signal ,
162+ onStream : HandleStream ,
163+ onCompletion : Completion ; // 用于回调翻译结果的函数
144164 }
145165 interface OcrQuery {
146166 from : Language ; // 目前用户选中的源语言
@@ -164,7 +184,7 @@ declare namespace Bob {
164184 author ?: string ; // 插件作者。
165185 homepage ?: string ; // 插件主页网址。
166186 appcast ?: string ; // 插件发布信息 URL。
167- minBobVersion ?: string ; // 最低支持本插件的 Bob 版本,建议填写您开发插件时候的调试插件的 Bob 版本,目前应该是 0.5 .0。
187+ minBobVersion ?: string ; // 最低支持本插件的 Bob 版本,建议填写您开发插件时候的调试插件的 Bob 版本,目前应该是 1.8 .0。
168188 options ?: OptionObject [ ] ;
169189 }
170190 interface MenuObject {
@@ -208,6 +228,7 @@ declare namespace Bob {
208228 request < T = any , R = HttpResponsePromise < T > > ( config : HttpRequestConfig ) : Promise < R > ;
209229 get < T = any , R = HttpResponsePromise < T > > ( config : HttpRequestConfig ) : Promise < R > ;
210230 post < T = any , R = HttpResponsePromise < T > > ( config : HttpRequestConfig ) : Promise < R > ;
231+ streamRequest < T = any , R = HttpResponsePromise < T > > ( config : HttpStreamRequestConfig ) : Promise < R > ;
211232 }
212233 type HttpMethod =
213234 | 'get'
@@ -233,6 +254,19 @@ declare namespace Bob {
233254 handler ?: ( resp : HttpResponse ) => void ;
234255 timeout ?: number ;
235256 }
257+
258+ interface HttpStreamRequestConfig {
259+ url : string ;
260+ method ?: HttpMethod ;
261+ header ?: any ;
262+ params ?: any ;
263+ body ?: any ;
264+ files ?: HttpRequestFiles ;
265+ handler ?: ( resp : HttpResponse ) => void ;
266+ streamHandler ?: ( stream : { text : string , rawData : Data } ) => void
267+ timeout ?: number ;
268+ }
269+
236270 interface HttpRequestFiles {
237271 data : DataObject ; // 二进制数据
238272 name : string ; // 上传表单中的名称
@@ -384,8 +418,12 @@ declare var $option: Bob.Option;
384418declare var $log : Bob . Log ;
385419declare var $data : Bob . Data ;
386420declare var $file : Bob . File ;
421+ declare var $signal : {
422+ new : ( ) => Bob . Signal ;
423+ } ;
424+
387425
388426declare function supportLanguages ( ) : Bob . supportLanguages ;
389- declare function translate ( query : Bob . TranslateQuery , completion : Bob . Completion ) : void ;
427+ declare function translate ( query : Bob . TranslateQuery ) : void ;
390428declare function ocr ( query : Bob . OcrQuery , completion : Bob . Completion ) : void ;
391429declare function tts ( query : Bob . TTSQuery , completion : Bob . Completion ) : void ;
0 commit comments