Update plugin documentation and types to support ReadableStream in provider results
This commit is contained in:
@@ -305,7 +305,7 @@ type EditFunction = (content:string) => string|null|undefined|Promise<string|nul
|
||||
type ReplacerFunction = (content:OpenAIChat[], type:string) => OpenAIChat[]|Promise<OpenAIChat[]>
|
||||
|
||||
export const pluginV2 = {
|
||||
providers: new Map<string, (arg:PluginV2ProviderArgument) => Promise<{success:boolean,content:string}> >(),
|
||||
providers: new Map<string, (arg:PluginV2ProviderArgument) => Promise<{success:boolean,content:string|ReadableStream<string>}> >(),
|
||||
editdisplay: new Set<EditFunction>(),
|
||||
editoutput: new Set<EditFunction>(),
|
||||
editprocess: new Set<EditFunction>(),
|
||||
|
||||
@@ -1420,7 +1420,24 @@ async function requestPlugin(arg:RequestDataArgumentExtended):Promise<requestDat
|
||||
else if(!d.success){
|
||||
return {
|
||||
type: 'fail',
|
||||
result: d.content
|
||||
result: d.content instanceof ReadableStream ? await (new Response(d.content)).text() : d.content
|
||||
}
|
||||
}
|
||||
else if(d.content instanceof ReadableStream){
|
||||
|
||||
let fullText = ''
|
||||
const piper = new TransformStream<string, StreamResponseChunk>( {
|
||||
transform(chunk, control) {
|
||||
fullText += chunk
|
||||
control.enqueue({
|
||||
"0": fullText
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
type: 'streaming',
|
||||
result: d.content.pipeThrough(piper)
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
Reference in New Issue
Block a user