@@ -25,7 +25,7 @@ import { SYSTEM_PROMPT_CACHE_BOUNDARY } from "./system-prompt-cache-boundary.js"
2525type OpenAICompletionsOutput = Parameters < typeof testing . processOpenAICompletionsStream > [ 1 ] ;
2626type OpenAIResponsesOutput = Parameters < typeof testing . processResponsesStream > [ 1 ] ;
2727
28- type CapturedStreamEvent = { type ?: string ; delta ?: string } ;
28+ type CapturedStreamEvent = { type ?: string ; delta ?: string ; partial ?: unknown } ;
2929
3030function createDeepSeekCompletionsModel ( ) : Model < "openai-completions" > {
3131 return {
@@ -1859,6 +1859,64 @@ describe("openai transport stream", () => {
18591859 expect ( stream . push . mock . calls . length ) . toBeLessThan ( 512 ) ;
18601860 } ) ;
18611861
1862+ it ( "omits accumulated partial snapshots from OpenAI-compatible text deltas" , async ( ) => {
1863+ const model = {
1864+ id : "dense-local" ,
1865+ name : "Dense Local" ,
1866+ api : "openai-completions" ,
1867+ provider : "local" ,
1868+ baseUrl : "http://127.0.0.1:18065/v1" ,
1869+ reasoning : false ,
1870+ input : [ "text" ] ,
1871+ cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 } ,
1872+ contextWindow : 128000 ,
1873+ maxTokens : 4096 ,
1874+ } satisfies Model < "openai-completions" > ;
1875+ const output = createAssistantOutput ( model ) ;
1876+ const events : CapturedStreamEvent [ ] = [ ] ;
1877+
1878+ await testing . processOpenAICompletionsStream (
1879+ streamChunks ( [
1880+ {
1881+ id : "chatcmpl-dense" ,
1882+ object : "chat.completion.chunk" as const ,
1883+ created : 1775425651 ,
1884+ model : model . id ,
1885+ choices : [
1886+ {
1887+ index : 0 ,
1888+ delta : { role : "assistant" as const , content : "a" } ,
1889+ logprobs : null ,
1890+ finish_reason : null ,
1891+ } ,
1892+ ] ,
1893+ } ,
1894+ {
1895+ id : "chatcmpl-dense" ,
1896+ object : "chat.completion.chunk" as const ,
1897+ created : 1775425651 ,
1898+ model : model . id ,
1899+ choices : [
1900+ {
1901+ index : 0 ,
1902+ delta : { content : "b" } ,
1903+ logprobs : null ,
1904+ finish_reason : null ,
1905+ } ,
1906+ ] ,
1907+ } ,
1908+ ] ) ,
1909+ output ,
1910+ model ,
1911+ { push : ( event ) => events . push ( event as CapturedStreamEvent ) } ,
1912+ ) ;
1913+
1914+ const textDeltas = events . filter ( ( event ) => event . type === "text_delta" ) ;
1915+ expect ( textDeltas ) . toHaveLength ( 2 ) ;
1916+ expect ( textDeltas . every ( ( event ) => ! ( "partial" in event ) ) ) . toBe ( true ) ;
1917+ expect ( output . content ) . toEqual ( [ { type : "text" , text : "ab" } ] ) ;
1918+ } ) ;
1919+
18621920 it ( "yields to aborts during bursty Responses streams" , async ( ) => {
18631921 const model = createAzureResponsesModel ( ) ;
18641922 const output = createResponsesAssistantOutput ( model ) ;
@@ -1887,6 +1945,28 @@ describe("openai transport stream", () => {
18871945 expect ( stream . push . mock . calls . length ) . toBeLessThan ( 512 ) ;
18881946 } ) ;
18891947
1948+ it ( "omits accumulated partial snapshots from Responses text deltas" , async ( ) => {
1949+ const model = createAzureResponsesModel ( ) ;
1950+ const output = createResponsesAssistantOutput ( model ) ;
1951+ const events : CapturedStreamEvent [ ] = [ ] ;
1952+
1953+ await testing . processResponsesStream (
1954+ streamChunks ( [
1955+ { type : "response.output_item.added" , item : { type : "message" } } ,
1956+ { type : "response.output_text.delta" , delta : "a" } ,
1957+ { type : "response.output_text.delta" , delta : "b" } ,
1958+ ] ) ,
1959+ output ,
1960+ { push : ( event ) => events . push ( event as CapturedStreamEvent ) } ,
1961+ model ,
1962+ ) ;
1963+
1964+ const textDeltas = events . filter ( ( event ) => event . type === "text_delta" ) ;
1965+ expect ( textDeltas ) . toHaveLength ( 2 ) ;
1966+ expect ( textDeltas . every ( ( event ) => ! ( "partial" in event ) ) ) . toBe ( true ) ;
1967+ expect ( output . content ) . toEqual ( [ { type : "text" , text : "ab" } ] ) ;
1968+ } ) ;
1969+
18901970 it ( "skips null and non-object OpenAI-compatible stream chunks" , async ( ) => {
18911971 const model = {
18921972 id : "glm-5" ,
0 commit comments