[{"data":1,"prerenderedAt":3012,"buildId":3013},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Fserver-sent-events":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":3011,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Fserver-sent-events.md",{},"Server-sent events",{"type":8,"value":9,"toc":2987},"minimark",[10,14,22,27,30,117,129,140,750,770,783,787,902,929,932,1004,1008,1459,1478,1494,1550,1554,1578,1593,1606,1670,1691,2020,2035,2045,2049,2162,2273,2283,2286,2319,2454,2458,2475,2616,2633,2648,2659,2663,2671,2688,2692,2695,2699,2705,2769,2778,2782,2791,2843,2846,2849,2877,2880,2887,2927,2931,2945,2949,2954],[11,12,13],"p",{},"Consume typed server-sent events and JSON Lines with the generated Axios client. Stop, resume, and handle streaming errors.",[11,15,16,17,21],{},"Kubb types the items from the OpenAPI document, and ",[18,19,20],"code",{},".kubb\u002Fsse.ts"," parses events as the WHATWG event stream specification does.",[23,24,26],"h2",{"id":25},"how-kubb-detects-a-stream","How Kubb detects a stream",[11,28,29],{},"Kubb generates a stream call when the success response declares only a stream content type:",[31,32,33,46],"table",{},[34,35,36],"thead",{},[37,38,39,43],"tr",{},[40,41,42],"th",{},"The success response declares",[40,44,45],{},"Each item",[47,48,49,74,93],"tbody",{},[37,50,51,65],{},[52,53,54,57,58,61,62],"td",{},[18,55,56],{},"text\u002Fevent-stream",", and the item schema declares ",[18,59,60],{},"event"," or ",[18,63,64],{},"data",[52,66,67,70,71],{},[18,68,69],{},"TypedEvent\u003CItem>",", narrowed by ",[18,72,73],{},"event.event",[37,75,76,81],{},[52,77,78,80],{},[18,79,56],{},", with any other item schema",[52,82,83,86,87,90,91],{},[18,84,85],{},"ServerSentEvent\u003CItem>",", with ",[18,88,89],{},"Item"," in ",[18,92,64],{},[37,94,95,112],{},[52,96,97,100,101,100,104,107,108,111],{},[18,98,99],{},"application\u002Fjsonl",", ",[18,102,103],{},"application\u002Fx-ndjson",[18,105,106],{},"application\u002Fjson-seq",", or a ",[18,109,110],{},"+json-seq"," type",[52,113,114,116],{},[18,115,89],{},", one per line",[11,118,119,120,122,123,128],{},"With ",[18,121,56],{}," next to another content type, Kubb generates a normal call instead. See ",[124,125,127],"a",{"href":126},"#json-or-an-event-stream","JSON or an event stream",".",[11,130,131,132,135,136,139],{},"The item schema is ",[18,133,134],{},"itemSchema"," in OpenAPI 3.2. In OpenAPI 3.0 and 3.1, ",[18,137,138],{},"schema"," describes one event or one line:",[141,142,143,538,656],"code-group",{},[144,145,150],"pre",{"language":146,"filename":147,"code":148,"class":149},"yaml","Typed events","\u002Fchat:\n post:\n operationId: streamChat\n responses:\n '200':\n description: One event per oneOf member\n content:\n text\u002Fevent-stream:\n itemSchema:\n type: object\n required: [event]\n properties:\n event: { type: string }\n id: { type: string }\n retry: { type: integer, minimum: 0 }\n oneOf:\n - type: object\n required: [event, data]\n properties:\n event: { type: string, const: message_delta }\n data: { $ref: '#\u002Fcomponents\u002Fschemas\u002FMessageDelta' }\n - type: object\n required: [event]\n properties:\n event: { type: string, const: ping }\n data: { type: string }","highlights",[18,151,153,166,167,166,177,166,192,166,201,166,211,166,224,166,233,166,242,166,251,166,264,166,281,166,290,166,312,166,331,166,361,166,370,166,381,166,400,166,408,166,438,166,458,166,471,166,485,166,493,166,520],{"class":152},"language-yaml",[154,155,158,162],"span",{"class":156,"style":157},"line","display: inline",[154,159,161],{"style":160},"color:#005cc5;--hls-dark:#79b8ff","\u002Fchat",[154,163,165],{"style":164},"color:#d73a49;--hls-dark:#f97583",":","\n",[154,168,169,172,175],{"class":156,"style":157},[154,170,171],{"style":164}," ",[154,173,174],{"style":160},"post",[154,176,165],{"style":164},[154,178,179,182,185,188],{"class":156,"style":157},[154,180,181],{"style":164}," ",[154,183,184],{"style":160},"operationId",[154,186,187],{"style":164},": ",[154,189,191],{"style":190},"color:#032f62;--hls-dark:#9ecbff","streamChat",[154,193,194,196,199],{"class":156,"style":157},[154,195,181],{"style":190},[154,197,198],{"style":160},"responses",[154,200,165],{"style":164},[154,202,203,206,209],{"class":156,"style":157},[154,204,205],{"style":164}," ",[154,207,208],{"style":160},"'200'",[154,210,165],{"style":164},[154,212,213,216,219,221],{"class":156,"style":157},[154,214,215],{"style":164}," ",[154,217,218],{"style":160},"description",[154,220,187],{"style":164},[154,222,223],{"style":190},"One event per oneOf member",[154,225,226,228,231],{"class":156,"style":157},[154,227,215],{"style":190},[154,229,230],{"style":160},"content",[154,232,165],{"style":164},[154,234,235,238,240],{"class":156,"style":157},[154,236,237],{"style":164}," ",[154,239,56],{"style":160},[154,241,165],{"style":164},[154,243,244,247,249],{"class":156,"style":157},[154,245,246],{"style":164}," ",[154,248,134],{"style":160},[154,250,165],{"style":164},[154,252,253,256,259,261],{"class":156,"style":157},[154,254,255],{"style":164}," ",[154,257,258],{"style":160},"type",[154,260,187],{"style":164},[154,262,263],{"style":190},"object",[154,265,266,268,271,273,276,278],{"class":156,"style":157},[154,267,255],{"style":190},[154,269,270],{"style":160},"required",[154,272,187],{"style":164},[154,274,275],{"style":160},"[",[154,277,60],{"style":190},[154,279,280],{"style":160},"]",[154,282,283,285,288],{"class":156,"style":157},[154,284,255],{"style":160},[154,286,287],{"style":160},"properties",[154,289,165],{"style":164},[154,291,292,295,297,299,302,304,306,309],{"class":156,"style":157},[154,293,294],{"style":164}," ",[154,296,60],{"style":160},[154,298,187],{"style":164},[154,300,301],{"style":160},"{ ",[154,303,258],{"style":160},[154,305,187],{"style":164},[154,307,308],{"style":190},"string ",[154,310,311],{"style":160},"}",[154,313,314,316,319,321,323,325,327,329],{"class":156,"style":157},[154,315,294],{"style":160},[154,317,318],{"style":160},"id",[154,320,187],{"style":164},[154,322,301],{"style":160},[154,324,258],{"style":160},[154,326,187],{"style":164},[154,328,308],{"style":190},[154,330,311],{"style":160},[154,332,333,335,338,340,342,344,346,349,351,354,356,359],{"class":156,"style":157},[154,334,294],{"style":160},[154,336,337],{"style":160},"retry",[154,339,187],{"style":164},[154,341,301],{"style":160},[154,343,258],{"style":160},[154,345,187],{"style":164},[154,347,348],{"style":190},"integer",[154,350,100],{"style":164},[154,352,353],{"style":160},"minimum",[154,355,187],{"style":164},[154,357,358],{"style":160},"0 ",[154,360,311],{"style":160},[154,362,363,365,368],{"class":156,"style":157},[154,364,255],{"style":160},[154,366,367],{"style":160},"oneOf",[154,369,165],{"style":164},[154,371,372,375,377,379],{"class":156,"style":157},[154,373,374],{"style":164}," - ",[154,376,258],{"style":160},[154,378,187],{"style":164},[154,380,263],{"style":190},[154,382,383,386,388,390,392,394,396,398],{"class":156,"style":157},[154,384,385],{"style":190}," ",[154,387,270],{"style":160},[154,389,187],{"style":164},[154,391,275],{"style":160},[154,393,60],{"style":190},[154,395,100],{"style":164},[154,397,64],{"style":190},[154,399,280],{"style":160},[154,401,402,404,406],{"class":156,"style":157},[154,403,385],{"style":160},[154,405,287],{"style":160},[154,407,165],{"style":164},[154,409,410,413,415,417,419,421,423,426,428,431,433,436],{"class":156,"style":157},[154,411,412],{"style":164}," ",[154,414,60],{"style":160},[154,416,187],{"style":164},[154,418,301],{"style":160},[154,420,258],{"style":160},[154,422,187],{"style":164},[154,424,425],{"style":190},"string",[154,427,100],{"style":164},[154,429,430],{"style":160},"const",[154,432,187],{"style":164},[154,434,435],{"style":190},"message_delta ",[154,437,311],{"style":160},[154,439,440,442,444,446,448,451,453,456],{"class":156,"style":157},[154,441,412],{"style":160},[154,443,64],{"style":160},[154,445,187],{"style":164},[154,447,301],{"style":160},[154,449,450],{"style":160},"$ref",[154,452,187],{"style":164},[154,454,455],{"style":190},"'#\u002Fcomponents\u002Fschemas\u002FMessageDelta' ",[154,457,311],{"style":160},[154,459,460,462,465,467,469],{"class":156,"style":157},[154,461,294],{"style":160},[154,463,464],{"style":164},"- ",[154,466,258],{"style":160},[154,468,187],{"style":164},[154,470,263],{"style":190},[154,472,473,475,477,479,481,483],{"class":156,"style":157},[154,474,385],{"style":190},[154,476,270],{"style":160},[154,478,187],{"style":164},[154,480,275],{"style":160},[154,482,60],{"style":190},[154,484,280],{"style":160},[154,486,487,489,491],{"class":156,"style":157},[154,488,385],{"style":160},[154,490,287],{"style":160},[154,492,165],{"style":164},[154,494,495,497,499,501,503,505,507,509,511,513,515,518],{"class":156,"style":157},[154,496,412],{"style":164},[154,498,60],{"style":160},[154,500,187],{"style":164},[154,502,301],{"style":160},[154,504,258],{"style":160},[154,506,187],{"style":164},[154,508,425],{"style":190},[154,510,100],{"style":164},[154,512,430],{"style":160},[154,514,187],{"style":164},[154,516,517],{"style":190},"ping ",[154,519,311],{"style":160},[154,521,522,524,526,528,530,532,534,536],{"class":156,"style":157},[154,523,412],{"style":160},[154,525,64],{"style":160},[154,527,187],{"style":164},[154,529,301],{"style":160},[154,531,258],{"style":160},[154,533,187],{"style":164},[154,535,308],{"style":190},[154,537,311],{"style":160},[144,539,542],{"language":146,"filename":540,"code":541,"class":149},"Payload only","\u002Fpet\u002F{petId}\u002Fevents:\n get:\n operationId: streamPetEvents\n responses:\n '200':\n description: One PetEvent per event\n content:\n text\u002Fevent-stream:\n schema: { type: string } # the whole stream, for tools that do not read itemSchema\n itemSchema: { $ref: '#\u002Fcomponents\u002Fschemas\u002FPetEvent' }",[18,543,544,166,551,166,560,166,571,166,579,166,587,166,598,166,606,166,614,166,637],{"class":152},[154,545,546,549],{"class":156,"style":157},[154,547,548],{"style":160},"\u002Fpet\u002F{petId}\u002Fevents",[154,550,165],{"style":164},[154,552,553,555,558],{"class":156,"style":157},[154,554,171],{"style":164},[154,556,557],{"style":160},"get",[154,559,165],{"style":164},[154,561,562,564,566,568],{"class":156,"style":157},[154,563,181],{"style":164},[154,565,184],{"style":160},[154,567,187],{"style":164},[154,569,570],{"style":190},"streamPetEvents",[154,572,573,575,577],{"class":156,"style":157},[154,574,181],{"style":190},[154,576,198],{"style":160},[154,578,165],{"style":164},[154,580,581,583,585],{"class":156,"style":157},[154,582,205],{"style":164},[154,584,208],{"style":160},[154,586,165],{"style":164},[154,588,589,591,593,595],{"class":156,"style":157},[154,590,215],{"style":164},[154,592,218],{"style":160},[154,594,187],{"style":164},[154,596,597],{"style":190},"One PetEvent per event",[154,599,600,602,604],{"class":156,"style":157},[154,601,215],{"style":190},[154,603,230],{"style":160},[154,605,165],{"style":164},[154,607,608,610,612],{"class":156,"style":157},[154,609,237],{"style":164},[154,611,56],{"style":160},[154,613,165],{"style":164},[154,615,616,618,620,622,624,626,628,630,633],{"class":156,"style":157},[154,617,246],{"style":164},[154,619,138],{"style":160},[154,621,187],{"style":164},[154,623,301],{"style":160},[154,625,258],{"style":160},[154,627,187],{"style":164},[154,629,308],{"style":190},[154,631,632],{"style":160},"} ",[154,634,636],{"style":635},"color:#6a737d;--hls-dark:#6a737d","# the whole stream, for tools that do not read itemSchema",[154,638,639,641,643,645,647,649,651,654],{"class":156,"style":157},[154,640,246],{"style":635},[154,642,134],{"style":160},[154,644,187],{"style":164},[154,646,301],{"style":160},[154,648,450],{"style":160},[154,650,187],{"style":164},[154,652,653],{"style":190},"'#\u002Fcomponents\u002Fschemas\u002FPetEvent' ",[154,655,311],{"style":160},[144,657,660],{"language":146,"filename":658,"code":659,"class":149},"JSON Lines","\u002Flogs:\n get:\n operationId: streamLogs\n responses:\n '200':\n description: One LogEntry per line\n content:\n application\u002Fjsonl:\n itemSchema: { $ref: '#\u002Fcomponents\u002Fschemas\u002FLogEntry' }",[18,661,662,166,669,166,677,166,688,166,696,166,704,166,715,166,723,166,731],{"class":152},[154,663,664,667],{"class":156,"style":157},[154,665,666],{"style":160},"\u002Flogs",[154,668,165],{"style":164},[154,670,671,673,675],{"class":156,"style":157},[154,672,171],{"style":164},[154,674,557],{"style":160},[154,676,165],{"style":164},[154,678,679,681,683,685],{"class":156,"style":157},[154,680,181],{"style":164},[154,682,184],{"style":160},[154,684,187],{"style":164},[154,686,687],{"style":190},"streamLogs",[154,689,690,692,694],{"class":156,"style":157},[154,691,181],{"style":190},[154,693,198],{"style":160},[154,695,165],{"style":164},[154,697,698,700,702],{"class":156,"style":157},[154,699,205],{"style":164},[154,701,208],{"style":160},[154,703,165],{"style":164},[154,705,706,708,710,712],{"class":156,"style":157},[154,707,215],{"style":164},[154,709,218],{"style":160},[154,711,187],{"style":164},[154,713,714],{"style":190},"One LogEntry per line",[154,716,717,719,721],{"class":156,"style":157},[154,718,215],{"style":190},[154,720,230],{"style":160},[154,722,165],{"style":164},[154,724,725,727,729],{"class":156,"style":157},[154,726,237],{"style":164},[154,728,99],{"style":160},[154,730,165],{"style":164},[154,732,733,735,737,739,741,743,745,748],{"class":156,"style":157},[154,734,246],{"style":164},[154,736,134],{"style":160},[154,738,187],{"style":164},[154,740,301],{"style":160},[154,742,450],{"style":160},[154,744,187],{"style":164},[154,746,747],{"style":190},"'#\u002Fcomponents\u002Fschemas\u002FLogEntry' ",[154,749,311],{"style":160},[11,751,752,753,755,756,759,760,762,763,766,767,769],{},"In OpenAPI 3.0 and 3.1, put the item schema on ",[18,754,138],{}," instead: the ",[18,757,758],{},"PetEvent"," reference for a payload, or the same ",[18,761,367],{}," with a ",[18,764,765],{},"discriminator"," on ",[18,768,60],{}," for typed events.",[771,772,774,775,778,779,782],"blockquote",{"as":773},"note","In the browser, a stream call switches to the axios fetch adapter, because the default XHR adapter buffers the whole body. An ",[18,776,777],{},"adapter"," you set on the call or on ",[18,780,781],{},"getAxiosInstance()"," is kept.",[23,784,786],{"id":785},"the-generated-function","The generated function",[144,788,791],{"language":789,"code":790,"class":149},"typescript","export function streamChat\u003CThrowOnError extends boolean = true>(\n options: StreamOptions\u003CStreamChatOptions, ThrowOnError> = {},\n): Unwrappable\u003CStreamResult\u003CStreamChatResponses, ThrowOnError, TypedEvent\u003CSuccessOf\u003CStreamChatResponses>>>>",[18,792,794,166,829,166,861],{"class":793},"language-typescript",[154,795,796,799,802,805,808,811,814,817,820,823,826],{"class":156,"style":157},[154,797,798],{"style":164},"export ",[154,800,801],{"style":164},"function ",[154,803,191],{"style":804},"color:#6f42c1;--hls-dark:#b392f0",[154,806,807],{"style":164},"\u003C",[154,809,810],{"style":804},"ThrowOnError ",[154,812,813],{"style":164},"extends ",[154,815,816],{"style":804},"boolean ",[154,818,819],{"style":164},"= ",[154,821,822],{"style":160},"true",[154,824,825],{"style":164},">",[154,827,828],{"style":160},"(",[154,830,831,833,837,839,842,844,847,849,852,855,858],{"class":156,"style":157},[154,832,171],{"style":160},[154,834,836],{"style":835},"color:#24292e;--hls-dark:#e1e4e8","options",[154,838,187],{"style":835},[154,840,841],{"style":804},"StreamOptions",[154,843,807],{"style":164},[154,845,846],{"style":804},"StreamChatOptions",[154,848,100],{"style":164},[154,850,851],{"style":804},"ThrowOnError",[154,853,854],{"style":164},"> = ",[154,856,857],{"style":160},"{}",[154,859,860],{"style":164},",",[154,862,863,866,868,871,873,876,878,881,883,885,887,890,892,895,897,899],{"class":156,"style":157},[154,864,865],{"style":160},")",[154,867,187],{"style":835},[154,869,870],{"style":804},"Unwrappable",[154,872,807],{"style":164},[154,874,875],{"style":804},"StreamResult",[154,877,807],{"style":164},[154,879,880],{"style":804},"StreamChatResponses",[154,882,100],{"style":164},[154,884,851],{"style":804},[154,886,100],{"style":164},[154,888,889],{"style":804},"TypedEvent",[154,891,807],{"style":164},[154,893,894],{"style":804},"SuccessOf",[154,896,807],{"style":164},[154,898,880],{"style":804},[154,900,901],{"style":164},">>>>",[11,903,904,905,907,908,911,912,915,916,919,920,915,922,924,925,928],{},"A ",[18,906,875],{}," has the fields of a ",[18,909,910],{},"RequestResult"," for the first connection, plus ",[18,913,914],{},"stream"," and ",[18,917,918],{},"lastEventId",". The result iterates its items, which are also in ",[18,921,914],{},[18,923,64],{},". With ",[18,926,927],{},"returnType: 'data'",", the call resolves to the items.",[11,930,931],{},"Pass these stream options next to the request params:",[31,933,934,944],{},[34,935,936],{},[37,937,938,941],{},[40,939,940],{},"Option",[40,942,943],{},"What it does",[47,945,946,962,972,990],{},[37,947,948,953],{},[52,949,950],{},[18,951,952],{},"terminator",[52,954,955,956,958,959,128],{},"Ends the stream when an event's ",[18,957,64],{},", or a JSON line, equals this value, such as ",[18,960,961],{},"[DONE]",[37,963,964,969],{},[52,965,966],{},[18,967,968],{},"transform",[52,970,971],{},"Maps each Server-Sent Event before validation, for example to camelCase its keys.",[37,973,974,979],{},[52,975,976],{},[18,977,978],{},"maxEventSize",[52,980,981,982,985,986,989],{},"The most characters in one event or line. Default ",[18,983,984],{},"16 * 1024 * 1024",". ",[18,987,988],{},"Infinity"," turns it off.",[37,991,992,997],{},[52,993,994],{},[18,995,996],{},"signal",[52,998,999,1000,1003],{},"An ",[18,1001,1002],{},"AbortSignal"," that ends the request and the loop.",[23,1005,1007],{"id":1006},"consume-items","Consume items",[141,1009,1010,1177,1308,1381],{},[144,1011,1013],{"language":789,"filename":147,"code":1012,"class":149},"import { streamChat } from '.\u002Fgen\u002Fclients\u002FstreamChat'\n\nfor await (const event of await streamChat({ body: { prompt: 'Hi' }, terminator: '[DONE]' })) {\n switch (event.event) {\n case 'message_delta':\n render(event.data.text) \u002F\u002F MessageDelta\n break\n case 'ping':\n break\n }\n}",[18,1014,1015,166,1033,166,1035,166,1088,166,1106,166,1118,166,1144,166,1151,166,1161,166,1167,166,1173],{"class":793},[154,1016,1017,1020,1022,1025,1027,1030],{"class":156,"style":157},[154,1018,1019],{"style":164},"import ",[154,1021,301],{"style":160},[154,1023,1024],{"style":835},"streamChat ",[154,1026,632],{"style":160},[154,1028,1029],{"style":164},"from ",[154,1031,1032],{"style":190},"'.\u002Fgen\u002Fclients\u002FstreamChat'",[154,1034],{"class":156,"style":157},[154,1036,1037,1040,1042,1045,1048,1051,1054,1056,1059,1062,1064,1066,1069,1071,1074,1076,1078,1080,1082,1085],{"class":156,"style":157},[154,1038,1039],{"style":164},"for await ",[154,1041,828],{"style":160},[154,1043,1044],{"style":164},"const ",[154,1046,1047],{"style":835},"event ",[154,1049,1050],{"style":164},"of ",[154,1052,1053],{"style":164},"await ",[154,1055,191],{"style":804},[154,1057,1058],{"style":160},"({ ",[154,1060,1061],{"style":160},"body",[154,1063,187],{"style":164},[154,1065,301],{"style":160},[154,1067,1068],{"style":160},"prompt",[154,1070,187],{"style":164},[154,1072,1073],{"style":190},"'Hi' ",[154,1075,311],{"style":160},[154,1077,100],{"style":164},[154,1079,952],{"style":160},[154,1081,187],{"style":164},[154,1083,1084],{"style":190},"'[DONE]' ",[154,1086,1087],{"style":160},"})) {",[154,1089,1090,1092,1095,1097,1099,1101,1103],{"class":156,"style":157},[154,1091,171],{"style":160},[154,1093,1094],{"style":164},"switch ",[154,1096,828],{"style":160},[154,1098,60],{"style":835},[154,1100,128],{"style":164},[154,1102,60],{"style":160},[154,1104,1105],{"style":160},") {",[154,1107,1108,1110,1113,1116],{"class":156,"style":157},[154,1109,181],{"style":160},[154,1111,1112],{"style":164},"case ",[154,1114,1115],{"style":190},"'message_delta'",[154,1117,165],{"style":164},[154,1119,1120,1122,1125,1127,1129,1131,1133,1135,1138,1141],{"class":156,"style":157},[154,1121,205],{"style":164},[154,1123,1124],{"style":804},"render",[154,1126,828],{"style":160},[154,1128,60],{"style":835},[154,1130,128],{"style":164},[154,1132,64],{"style":160},[154,1134,128],{"style":164},[154,1136,1137],{"style":160},"text",[154,1139,1140],{"style":160},") ",[154,1142,1143],{"style":635},"\u002F\u002F MessageDelta",[154,1145,1146,1148],{"class":156,"style":157},[154,1147,205],{"style":635},[154,1149,1150],{"style":164},"break",[154,1152,1153,1156,1159],{"class":156,"style":157},[154,1154,1155],{"style":164}," case ",[154,1157,1158],{"style":190},"'ping'",[154,1160,165],{"style":164},[154,1162,1163,1165],{"class":156,"style":157},[154,1164,205],{"style":164},[154,1166,1150],{"style":164},[154,1168,1169,1171],{"class":156,"style":157},[154,1170,171],{"style":164},[154,1172,311],{"style":160},[154,1174,1175],{"class":156,"style":157},[154,1176,311],{"style":160},[144,1178,1180],{"language":789,"filename":540,"code":1179,"class":149},"import { streamPetEvents } from '.\u002Fgen\u002Fclients\u002FstreamPetEvents'\n\nconst { stream, response } = await streamPetEvents({ path: { petId: 1 } })\nconsole.info(response.status) \u002F\u002F 200\n\nfor await (const { data } of stream) console.info(data.type) \u002F\u002F PetEvent",[18,1181,1182,166,1198,166,1200,166,1241,166,1266,166,1268],{"class":793},[154,1183,1184,1186,1188,1191,1193,1195],{"class":156,"style":157},[154,1185,1019],{"style":164},[154,1187,301],{"style":160},[154,1189,1190],{"style":835},"streamPetEvents ",[154,1192,632],{"style":160},[154,1194,1029],{"style":164},[154,1196,1197],{"style":190},"'.\u002Fgen\u002Fclients\u002FstreamPetEvents'",[154,1199],{"class":156,"style":157},[154,1201,1202,1204,1206,1208,1210,1213,1215,1217,1219,1221,1223,1226,1228,1230,1233,1235,1238],{"class":156,"style":157},[154,1203,1044],{"style":164},[154,1205,301],{"style":160},[154,1207,914],{"style":835},[154,1209,100],{"style":164},[154,1211,1212],{"style":835},"response ",[154,1214,632],{"style":160},[154,1216,819],{"style":164},[154,1218,1053],{"style":164},[154,1220,570],{"style":804},[154,1222,1058],{"style":160},[154,1224,1225],{"style":160},"path",[154,1227,187],{"style":164},[154,1229,301],{"style":160},[154,1231,1232],{"style":160},"petId",[154,1234,187],{"style":164},[154,1236,1237],{"style":160},"1 ",[154,1239,1240],{"style":160},"} })",[154,1242,1243,1246,1248,1251,1253,1256,1258,1261,1263],{"class":156,"style":157},[154,1244,1245],{"style":835},"console",[154,1247,128],{"style":164},[154,1249,1250],{"style":804},"info",[154,1252,828],{"style":160},[154,1254,1255],{"style":835},"response",[154,1257,128],{"style":164},[154,1259,1260],{"style":160},"status",[154,1262,1140],{"style":160},[154,1264,1265],{"style":635},"\u002F\u002F 200",[154,1267],{"class":156,"style":157},[154,1269,1270,1272,1274,1276,1278,1281,1283,1285,1287,1289,1291,1293,1295,1297,1299,1301,1303,1305],{"class":156,"style":157},[154,1271,1039],{"style":164},[154,1273,828],{"style":160},[154,1275,1044],{"style":164},[154,1277,301],{"style":160},[154,1279,1280],{"style":835},"data ",[154,1282,632],{"style":160},[154,1284,1050],{"style":164},[154,1286,914],{"style":835},[154,1288,1140],{"style":160},[154,1290,1245],{"style":835},[154,1292,128],{"style":164},[154,1294,1250],{"style":804},[154,1296,828],{"style":160},[154,1298,64],{"style":835},[154,1300,128],{"style":164},[154,1302,258],{"style":160},[154,1304,1140],{"style":160},[154,1306,1307],{"style":635},"\u002F\u002F PetEvent",[144,1309,1311],{"language":789,"filename":658,"code":1310,"class":149},"import { streamLogs } from '.\u002Fgen\u002Fclients\u002FstreamLogs'\n\nfor await (const entry of await streamLogs()) console.info(entry.level, entry.message) \u002F\u002F LogEntry",[18,1312,1313,166,1329,166,1331],{"class":793},[154,1314,1315,1317,1319,1322,1324,1326],{"class":156,"style":157},[154,1316,1019],{"style":164},[154,1318,301],{"style":160},[154,1320,1321],{"style":835},"streamLogs ",[154,1323,632],{"style":160},[154,1325,1029],{"style":164},[154,1327,1328],{"style":190},"'.\u002Fgen\u002Fclients\u002FstreamLogs'",[154,1330],{"class":156,"style":157},[154,1332,1333,1335,1337,1339,1342,1344,1346,1348,1351,1353,1355,1357,1359,1362,1364,1367,1369,1371,1373,1376,1378],{"class":156,"style":157},[154,1334,1039],{"style":164},[154,1336,828],{"style":160},[154,1338,1044],{"style":164},[154,1340,1341],{"style":835},"entry ",[154,1343,1050],{"style":164},[154,1345,1053],{"style":164},[154,1347,687],{"style":804},[154,1349,1350],{"style":160},"()) ",[154,1352,1245],{"style":835},[154,1354,128],{"style":164},[154,1356,1250],{"style":804},[154,1358,828],{"style":160},[154,1360,1361],{"style":835},"entry",[154,1363,128],{"style":164},[154,1365,1366],{"style":160},"level",[154,1368,100],{"style":164},[154,1370,1361],{"style":835},[154,1372,128],{"style":164},[154,1374,1375],{"style":160},"message",[154,1377,1140],{"style":160},[154,1379,1380],{"style":635},"\u002F\u002F LogEntry",[144,1382,1384],{"language":789,"filename":927,"code":1383,"class":149},"\u002F\u002F with pluginAxios({ returnType: 'data' })\nconst events = await streamPetEvents({ path: { petId: 1 } })\n\nfor await (const { data } of events) console.info(data.type)",[18,1385,1386,166,1391,166,1420,166,1422],{"class":793},[154,1387,1388],{"class":156,"style":157},[154,1389,1390],{"style":635},"\u002F\u002F with pluginAxios({ returnType: 'data' })",[154,1392,1393,1395,1398,1400,1402,1404,1406,1408,1410,1412,1414,1416,1418],{"class":156,"style":157},[154,1394,1044],{"style":164},[154,1396,1397],{"style":835},"events ",[154,1399,819],{"style":164},[154,1401,1053],{"style":164},[154,1403,570],{"style":804},[154,1405,1058],{"style":160},[154,1407,1225],{"style":160},[154,1409,187],{"style":164},[154,1411,301],{"style":160},[154,1413,1232],{"style":160},[154,1415,187],{"style":164},[154,1417,1237],{"style":160},[154,1419,1240],{"style":160},[154,1421],{"class":156,"style":157},[154,1423,1424,1426,1428,1430,1432,1434,1436,1438,1441,1443,1445,1447,1449,1451,1453,1455,1457],{"class":156,"style":157},[154,1425,1039],{"style":164},[154,1427,828],{"style":160},[154,1429,1044],{"style":164},[154,1431,301],{"style":160},[154,1433,1280],{"style":835},[154,1435,632],{"style":160},[154,1437,1050],{"style":164},[154,1439,1440],{"style":835},"events",[154,1442,1140],{"style":160},[154,1444,1245],{"style":835},[154,1446,128],{"style":164},[154,1448,1250],{"style":804},[154,1450,828],{"style":160},[154,1452,64],{"style":835},[154,1454,128],{"style":164},[154,1456,258],{"style":160},[154,1458,865],{"style":160},[11,1460,1461,1462,1465,1466,1469,1470,1473,1474,128],{},"An event the document does not declare reaches the ",[18,1463,1464],{},"default"," of your ",[18,1467,1468],{},"switch",", so declare heartbeat and ",[18,1471,1472],{},"error"," events too. For event names, IDs, and JSON Lines limits, see ",[124,1475,1477],{"href":1476},"#event-names-ids-and-json-lines","Event names, IDs, and JSON Lines",[11,1479,119,1480,1483,1484,1486,1487,1490,1491,165],{},[18,1481,1482],{},"validator: 'zod'",", the validator checks each item: the whole event for typed events, ",[18,1485,64],{}," for a payload, and each line for JSON Lines. To keep going past a failing item, return ",[18,1488,1489],{},"{ value }"," from ",[18,1492,1493],{},"onValidationError",[144,1495,1497],{"language":789,"code":1496,"class":149},"const { stream } = await streamChat({ body, onValidationError: (error, { value }) => ({ value }) })",[18,1498,1499],{"class":793},[154,1500,1501,1503,1505,1508,1510,1512,1514,1516,1518,1520,1522,1524,1526,1528,1530,1532,1534,1537,1540,1543,1545,1547],{"class":156,"style":157},[154,1502,1044],{"style":164},[154,1504,301],{"style":160},[154,1506,1507],{"style":835},"stream ",[154,1509,632],{"style":160},[154,1511,819],{"style":164},[154,1513,1053],{"style":164},[154,1515,191],{"style":804},[154,1517,1058],{"style":160},[154,1519,1061],{"style":835},[154,1521,100],{"style":164},[154,1523,1493],{"style":160},[154,1525,187],{"style":164},[154,1527,828],{"style":160},[154,1529,1472],{"style":835},[154,1531,100],{"style":164},[154,1533,301],{"style":160},[154,1535,1536],{"style":835},"value ",[154,1538,1539],{"style":160},"}) ",[154,1541,1542],{"style":164},"=> ",[154,1544,1058],{"style":160},[154,1546,1536],{"style":835},[154,1548,1549],{"style":160},"}) })",[23,1551,1553],{"id":1552},"stop-abort-and-resume","Stop, abort, and resume",[1555,1556,1557,1563,1569],"ul",{},[1558,1559,1560,1562],"li",{},[18,1561,1150],{}," out of the loop to stop. The runtime cancels the reader and releases the connection.",[1558,1564,1565,1566,1568],{},"Pass ",[18,1567,996],{}," to stop from outside. The call or the loop rejects with the signal's reason.",[1558,1570,1571,1572,1577],{},"A dropped connection ends the loop with the transport's error, unless ",[124,1573,1575],{"href":1574},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Fconfigure-requests#retry-a-failed-call",[18,1576,337],{}," is set.",[11,1579,119,1580,1582,1583,762,1585,1588,1589,1592],{},[18,1581,337],{},", the runtime retries a failed connect and reopens a dropped ",[18,1584,56],{},[18,1586,1587],{},"Last-Event-ID"," header. The limit counts failures in a row and starts over once the stream delivers an event. A reopen that fails throws from the loop, also with ",[18,1590,1591],{},"throwOnError: false",". A stream that ends and a JSON Lines stream are not reopened.",[11,1594,1595,1597,1598,1601,1602,1605],{},[18,1596,191],{}," is a ",[18,1599,1600],{},"POST",", so ",[18,1603,1604],{},"retry.methods"," has to name it:",[144,1607,1609],{"language":789,"code":1608,"class":149},"for await (const event of await streamChat({ body, retry: { limit: 3, methods: ['POST'] } })) render(event)",[18,1610,1611],{"class":793},[154,1612,1613,1615,1617,1619,1621,1623,1625,1627,1629,1631,1633,1635,1637,1639,1642,1644,1647,1649,1652,1654,1656,1659,1662,1664,1666,1668],{"class":156,"style":157},[154,1614,1039],{"style":164},[154,1616,828],{"style":160},[154,1618,1044],{"style":164},[154,1620,1047],{"style":835},[154,1622,1050],{"style":164},[154,1624,1053],{"style":164},[154,1626,191],{"style":804},[154,1628,1058],{"style":160},[154,1630,1061],{"style":835},[154,1632,100],{"style":164},[154,1634,337],{"style":160},[154,1636,187],{"style":164},[154,1638,301],{"style":160},[154,1640,1641],{"style":160},"limit",[154,1643,187],{"style":164},[154,1645,1646],{"style":160},"3",[154,1648,100],{"style":164},[154,1650,1651],{"style":160},"methods",[154,1653,187],{"style":164},[154,1655,275],{"style":160},[154,1657,1658],{"style":190},"'POST'",[154,1660,1661],{"style":160},"] } })) ",[154,1663,1124],{"style":804},[154,1665,828],{"style":160},[154,1667,60],{"style":835},[154,1669,865],{"style":160},[11,1671,1672,1673,1675,1676,1678,1679,1681,1682,1684,1685,1687,1688,165],{},"To resume by hand, leave ",[18,1674,337],{}," off and send a new call with a ",[18,1677,1587],{}," header. ",[18,1680,918],{}," is the ",[18,1683,318],{}," of the last event the server completed. Declare ",[18,1686,1587],{}," as a header parameter, so the call accepts it in ",[18,1689,1690],{},"headers",[144,1692,1694],{"language":789,"code":1693,"class":149},"import { ResponseError } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport { ValidationError } from '.\u002Fgen\u002F.kubb\u002FstandardSchema'\n\nasync function* resumeChat(attempts = 3) {\n let lastEventId = ''\n\n for (let attempt = 1; ; attempt++) {\n try {\n const result = await streamChat({ body, headers: lastEventId ? { 'Last-Event-ID': lastEventId } : {} })\n for await (const event of result) {\n lastEventId = result.lastEventId\n yield event\n }\n return\n } catch (error) {\n if (attempt === attempts || ResponseError.is(error) || error instanceof ValidationError) throw error\n }\n }\n}\n\nfor await (const event of resumeChat()) render(event)",[18,1695,1696,166,1712,166,1728,166,1730,166,1755,166,1770,166,1772,166,1802,166,1812,166,1858,166,1877,166,1891,166,1900,166,1906,166,1913,166,1928,166,1979,166,1985,166,1990,166,1994,166,1996],{"class":793},[154,1697,1698,1700,1702,1705,1707,1709],{"class":156,"style":157},[154,1699,1019],{"style":164},[154,1701,301],{"style":160},[154,1703,1704],{"style":804},"ResponseError ",[154,1706,632],{"style":160},[154,1708,1029],{"style":164},[154,1710,1711],{"style":190},"'.\u002Fgen\u002F.kubb\u002Fclient'",[154,1713,1714,1716,1718,1721,1723,1725],{"class":156,"style":157},[154,1715,1019],{"style":164},[154,1717,301],{"style":160},[154,1719,1720],{"style":804},"ValidationError ",[154,1722,632],{"style":160},[154,1724,1029],{"style":164},[154,1726,1727],{"style":190},"'.\u002Fgen\u002F.kubb\u002FstandardSchema'",[154,1729],{"class":156,"style":157},[154,1731,1732,1735,1738,1741,1744,1746,1749,1751,1753],{"class":156,"style":157},[154,1733,1734],{"style":164},"async ",[154,1736,1737],{"style":164},"function",[154,1739,1740],{"style":164},"* ",[154,1742,1743],{"style":804},"resumeChat",[154,1745,828],{"style":160},[154,1747,1748],{"style":835},"attempts ",[154,1750,819],{"style":164},[154,1752,1646],{"style":160},[154,1754,1105],{"style":160},[154,1756,1757,1759,1762,1765,1767],{"class":156,"style":157},[154,1758,171],{"style":160},[154,1760,1761],{"style":164},"let ",[154,1763,1764],{"style":835},"lastEventId ",[154,1766,819],{"style":164},[154,1768,1769],{"style":190},"''",[154,1771],{"class":156,"style":157},[154,1773,1774,1776,1779,1781,1783,1786,1788,1791,1794,1797,1800],{"class":156,"style":157},[154,1775,171],{"style":190},[154,1777,1778],{"style":164},"for ",[154,1780,828],{"style":160},[154,1782,1761],{"style":164},[154,1784,1785],{"style":835},"attempt ",[154,1787,819],{"style":164},[154,1789,1790],{"style":160},"1",[154,1792,1793],{"style":164},"; ; ",[154,1795,1796],{"style":835},"attempt",[154,1798,1799],{"style":164},"++",[154,1801,1105],{"style":160},[154,1803,1804,1806,1809],{"class":156,"style":157},[154,1805,181],{"style":160},[154,1807,1808],{"style":164},"try ",[154,1810,1811],{"style":160},"{",[154,1813,1814,1816,1818,1821,1823,1825,1827,1829,1831,1833,1835,1837,1839,1842,1844,1847,1849,1851,1853,1855],{"class":156,"style":157},[154,1815,205],{"style":160},[154,1817,1044],{"style":164},[154,1819,1820],{"style":835},"result ",[154,1822,819],{"style":164},[154,1824,1053],{"style":164},[154,1826,191],{"style":804},[154,1828,1058],{"style":160},[154,1830,1061],{"style":835},[154,1832,100],{"style":164},[154,1834,1690],{"style":160},[154,1836,187],{"style":164},[154,1838,1764],{"style":835},[154,1840,1841],{"style":164},"? ",[154,1843,301],{"style":160},[154,1845,1846],{"style":190},"'Last-Event-ID'",[154,1848,187],{"style":164},[154,1850,1764],{"style":835},[154,1852,632],{"style":160},[154,1854,187],{"style":164},[154,1856,1857],{"style":160},"{} })",[154,1859,1860,1862,1864,1866,1868,1870,1872,1875],{"class":156,"style":157},[154,1861,205],{"style":160},[154,1863,1039],{"style":164},[154,1865,828],{"style":160},[154,1867,1044],{"style":164},[154,1869,1047],{"style":835},[154,1871,1050],{"style":164},[154,1873,1874],{"style":835},"result",[154,1876,1105],{"style":160},[154,1878,1879,1881,1883,1885,1887,1889],{"class":156,"style":157},[154,1880,215],{"style":160},[154,1882,1764],{"style":835},[154,1884,819],{"style":164},[154,1886,1874],{"style":835},[154,1888,128],{"style":164},[154,1890,918],{"style":160},[154,1892,1893,1895,1898],{"class":156,"style":157},[154,1894,215],{"style":160},[154,1896,1897],{"style":164},"yield ",[154,1899,60],{"style":835},[154,1901,1902,1904],{"class":156,"style":157},[154,1903,205],{"style":835},[154,1905,311],{"style":160},[154,1907,1908,1910],{"class":156,"style":157},[154,1909,205],{"style":160},[154,1911,1912],{"style":164},"return",[154,1914,1915,1917,1919,1922,1924,1926],{"class":156,"style":157},[154,1916,181],{"style":164},[154,1918,632],{"style":160},[154,1920,1921],{"style":164},"catch ",[154,1923,828],{"style":160},[154,1925,1472],{"style":835},[154,1927,1105],{"style":160},[154,1929,1930,1932,1935,1937,1939,1942,1944,1947,1950,1952,1955,1957,1959,1961,1963,1966,1969,1972,1974,1977],{"class":156,"style":157},[154,1931,205],{"style":160},[154,1933,1934],{"style":164},"if ",[154,1936,828],{"style":160},[154,1938,1785],{"style":835},[154,1940,1941],{"style":164},"=== ",[154,1943,1748],{"style":835},[154,1945,1946],{"style":164},"|| ",[154,1948,1949],{"style":804},"ResponseError",[154,1951,128],{"style":164},[154,1953,1954],{"style":804},"is",[154,1956,828],{"style":160},[154,1958,1472],{"style":835},[154,1960,1140],{"style":160},[154,1962,1946],{"style":164},[154,1964,1965],{"style":835},"error ",[154,1967,1968],{"style":164},"instanceof ",[154,1970,1971],{"style":804},"ValidationError",[154,1973,1140],{"style":160},[154,1975,1976],{"style":164},"throw ",[154,1978,1472],{"style":835},[154,1980,1981,1983],{"class":156,"style":157},[154,1982,181],{"style":835},[154,1984,311],{"style":160},[154,1986,1987],{"class":156,"style":157},[154,1988,1989],{"style":160}," }",[154,1991,1992],{"class":156,"style":157},[154,1993,311],{"style":160},[154,1995],{"class":156,"style":157},[154,1997,1998,2000,2002,2004,2006,2008,2010,2012,2014,2016,2018],{"class":156,"style":157},[154,1999,1039],{"style":164},[154,2001,828],{"style":160},[154,2003,1044],{"style":164},[154,2005,1047],{"style":835},[154,2007,1050],{"style":164},[154,2009,1743],{"style":804},[154,2011,1350],{"style":160},[154,2013,1124],{"style":804},[154,2015,828],{"style":160},[154,2017,60],{"style":835},[154,2019,865],{"style":160},[11,2021,2022,2023,2025,2026,2028,2029,2031,2032,2034],{},"The loop retries a failed connect and a dropped connection. It rethrows the last failure, so a cut stream never looks complete. It also rethrows a ",[18,2024,1949],{}," and a ",[18,2027,1971],{}," at once, because a retry cannot fix them and would skip the failing event. Rethrow your abort reason the same way when you pass ",[18,2030,996],{},". An error from ",[18,2033,1124],{}," is thrown outside the generator, so it is never retried.",[11,2036,2037,2038,2040,2041,128],{},"For cleared IDs and resuming with ",[18,2039,927],{},", see ",[124,2042,2044],{"href":2043},"#event-ids-when-you-resume","Event IDs when you resume",[23,2046,2048],{"id":2047},"handle-errors","Handle errors",[31,2050,2051,2061],{},[34,2052,2053],{},[37,2054,2055,2058],{},[40,2056,2057],{},"What happens",[40,2059,2060],{},"Where it fails",[47,2062,2063,2073,2094,2108,2116,2124,2140,2152],{},[37,2064,2065,2068],{},[52,2066,2067],{},"Non-2xx response",[52,2069,2070,2071,128],{},"The call throws a ",[18,2072,1949],{},[37,2074,2075,2080],{},[52,2076,2077,2078],{},"Non-2xx response with ",[18,2079,1591],{},[52,2081,2082,2083,915,2085,985,2087,2089,2090,2093],{},"The call resolves with ",[18,2084,1260],{},[18,2086,1472],{},[18,2088,64],{}," is ",[18,2091,2092],{},"undefined",", and the stream yields nothing.",[37,2095,2096,2099],{},[52,2097,2098],{},"2xx response whose body is not a stream, such as JSON",[52,2100,2070,2101,2104,2105,128],{},[18,2102,2103],{},"TypeError"," with the body as its ",[18,2106,2107],{},"cause",[37,2109,2110,2113],{},[52,2111,2112],{},"2xx response with an empty body",[52,2114,2115],{},"No error. The stream is empty.",[37,2117,2118,2121],{},[52,2119,2120],{},"Dropped connection or abort",[52,2122,2123],{},"The loop throws.",[37,2125,2126,2129],{},[52,2127,2128],{},"An item fails its schema",[52,2130,2131,2132,2134,2135,2137,2138,128],{},"The loop throws a ",[18,2133,1971],{},", unless ",[18,2136,1493],{}," returns ",[18,2139,1489],{},[37,2141,2142,2147],{},[52,2143,2144,2145],{},"An event is larger than ",[18,2146,978],{},[52,2148,2131,2149,128],{},[18,2150,2151],{},"RangeError",[37,2153,2154,2157],{},[52,2155,2156],{},"A JSON line is not valid JSON",[52,2158,2131,2159,128],{},[18,2160,2161],{},"SyntaxError",[144,2163,2165],{"language":789,"code":2164,"class":149},"const result = await streamChat({ body, throwOnError: false })\n\nif (!result.data) console.error('stream rejected', result.status, result.error)\nelse for await (const event of result.data) render(event)",[18,2166,2167,166,2196,166,2198,166,2244],{"class":793},[154,2168,2169,2171,2173,2175,2177,2179,2181,2183,2185,2188,2190,2193],{"class":156,"style":157},[154,2170,1044],{"style":164},[154,2172,1820],{"style":835},[154,2174,819],{"style":164},[154,2176,1053],{"style":164},[154,2178,191],{"style":804},[154,2180,1058],{"style":160},[154,2182,1061],{"style":835},[154,2184,100],{"style":164},[154,2186,2187],{"style":160},"throwOnError",[154,2189,187],{"style":164},[154,2191,2192],{"style":160},"false ",[154,2194,2195],{"style":160},"})",[154,2197],{"class":156,"style":157},[154,2199,2200,2202,2204,2207,2209,2211,2213,2215,2217,2219,2221,2223,2226,2228,2230,2232,2234,2236,2238,2240,2242],{"class":156,"style":157},[154,2201,1934],{"style":164},[154,2203,828],{"style":160},[154,2205,2206],{"style":164},"!",[154,2208,1874],{"style":835},[154,2210,128],{"style":164},[154,2212,64],{"style":160},[154,2214,1140],{"style":160},[154,2216,1245],{"style":835},[154,2218,128],{"style":164},[154,2220,1472],{"style":804},[154,2222,828],{"style":160},[154,2224,2225],{"style":190},"'stream rejected'",[154,2227,100],{"style":164},[154,2229,1874],{"style":835},[154,2231,128],{"style":164},[154,2233,1260],{"style":160},[154,2235,100],{"style":164},[154,2237,1874],{"style":835},[154,2239,128],{"style":164},[154,2241,1472],{"style":160},[154,2243,865],{"style":160},[154,2245,2246,2249,2251,2253,2255,2257,2259,2261,2263,2265,2267,2269,2271],{"class":156,"style":157},[154,2247,2248],{"style":164},"else for await ",[154,2250,828],{"style":160},[154,2252,1044],{"style":164},[154,2254,1047],{"style":835},[154,2256,1050],{"style":164},[154,2258,1874],{"style":835},[154,2260,128],{"style":164},[154,2262,64],{"style":160},[154,2264,1140],{"style":160},[154,2266,1124],{"style":804},[154,2268,828],{"style":160},[154,2270,60],{"style":835},[154,2272,865],{"style":160},[11,2274,2275,2276,985,2279,2282],{},"An error thrown from the loop skips ",[18,2277,2278],{},"client.interceptors.error",[18,2280,2281],{},".unwrap()"," resolves to the items, as on a regular call.",[23,2284,127],{"id":2285},"json-or-an-event-stream",[11,2287,2288,2289,2291,2292,2295,2296,2299,2300,2303,2304,2306,2307,2310,2311,2314,2315,2318],{},"When the success response declares ",[18,2290,56],{}," next to another type, such as ",[18,2293,2294],{},"application\u002Fjson",", Kubb generates a normal call that sends ",[18,2297,2298],{},"Accept: text\u002Fevent-stream",". Pass ",[18,2301,2302],{},"contentType: { response: 'application\u002Fjson' }"," to ask for JSON. When the server streams, ",[18,2305,64],{}," is the raw ",[18,2308,2309],{},"ReadableStream\u003CUint8Array>",", so read it with ",[18,2312,2313],{},"parseEventStream",", or ",[18,2316,2317],{},"parseJsonLines({ stream })"," for JSON Lines:",[144,2320,2322],{"language":789,"code":2321,"class":149},"import { parseEventStream } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nconst result = await getRecentChanges({ signal })\n\nif (result.contentType === 'text\u002Fevent-stream') {\n for await (const { data } of parseEventStream(result.data)) render(data)\n} else {\n render(result.data) \u002F\u002F the JSON body\n}",[18,2323,2324,166,2339,166,2341,166,2361,166,2363,166,2383,166,2422,166,2431,166,2450],{"class":793},[154,2325,2326,2328,2330,2333,2335,2337],{"class":156,"style":157},[154,2327,1019],{"style":164},[154,2329,301],{"style":160},[154,2331,2332],{"style":835},"parseEventStream ",[154,2334,632],{"style":160},[154,2336,1029],{"style":164},[154,2338,1711],{"style":190},[154,2340],{"class":156,"style":157},[154,2342,2343,2345,2347,2349,2351,2354,2356,2359],{"class":156,"style":157},[154,2344,1044],{"style":164},[154,2346,1820],{"style":835},[154,2348,819],{"style":164},[154,2350,1053],{"style":164},[154,2352,2353],{"style":804},"getRecentChanges",[154,2355,1058],{"style":160},[154,2357,2358],{"style":835},"signal ",[154,2360,2195],{"style":160},[154,2362],{"class":156,"style":157},[154,2364,2365,2367,2369,2371,2373,2376,2378,2381],{"class":156,"style":157},[154,2366,1934],{"style":164},[154,2368,828],{"style":160},[154,2370,1874],{"style":835},[154,2372,128],{"style":164},[154,2374,2375],{"style":160},"contentType ",[154,2377,1941],{"style":164},[154,2379,2380],{"style":190},"'text\u002Fevent-stream'",[154,2382,1105],{"style":160},[154,2384,2385,2387,2389,2391,2393,2395,2397,2399,2401,2403,2405,2407,2409,2411,2414,2416,2418,2420],{"class":156,"style":157},[154,2386,171],{"style":160},[154,2388,1039],{"style":164},[154,2390,828],{"style":160},[154,2392,1044],{"style":164},[154,2394,301],{"style":160},[154,2396,1280],{"style":835},[154,2398,632],{"style":160},[154,2400,1050],{"style":164},[154,2402,2313],{"style":804},[154,2404,828],{"style":160},[154,2406,1874],{"style":835},[154,2408,128],{"style":164},[154,2410,64],{"style":160},[154,2412,2413],{"style":160},")) ",[154,2415,1124],{"style":804},[154,2417,828],{"style":160},[154,2419,64],{"style":835},[154,2421,865],{"style":160},[154,2423,2424,2426,2429],{"class":156,"style":157},[154,2425,632],{"style":160},[154,2427,2428],{"style":164},"else ",[154,2430,1811],{"style":160},[154,2432,2433,2435,2437,2439,2441,2443,2445,2447],{"class":156,"style":157},[154,2434,171],{"style":160},[154,2436,1124],{"style":804},[154,2438,828],{"style":160},[154,2440,1874],{"style":835},[154,2442,128],{"style":164},[154,2444,64],{"style":160},[154,2446,1140],{"style":160},[154,2448,2449],{"style":635},"\u002F\u002F the JSON body",[154,2451,2452],{"class":156,"style":157},[154,2453,311],{"style":160},[23,2455,2457],{"id":2456},"stream-with-the-client","Stream with the client",[11,2459,2460,2463,2464,2467,2468,2471,2472,2474],{},[18,2461,2462],{},"client.stream(config)"," sends a stream request by hand. It runs the same interceptors and transport as ",[18,2465,2466],{},"client(config)",", and validates each item with ",[18,2469,2470],{},"validator.response",". Type it with the responses record, ",[18,2473,851],{},", and the item type:",[144,2476,2478],{"language":789,"code":2477,"class":149},"import { client, type SuccessOf } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport type { StreamLogsResponses } from '.\u002Fgen\u002Ftypes\u002FStreamLogs'\n\nconst result = await client.stream\u003CStreamLogsResponses, true, SuccessOf\u003CStreamLogsResponses>>({\n method: 'GET',\n url: '\u002Flogs',\n contentType: { response: 'application\u002Fjsonl' },\n})",[18,2479,2480,166,2503,166,2521,166,2523,166,2562,166,2576,166,2590,166,2612],{"class":793},[154,2481,2482,2484,2486,2489,2491,2494,2497,2499,2501],{"class":156,"style":157},[154,2483,1019],{"style":164},[154,2485,301],{"style":160},[154,2487,2488],{"style":835},"client",[154,2490,100],{"style":164},[154,2492,2493],{"style":164},"type ",[154,2495,2496],{"style":804},"SuccessOf ",[154,2498,632],{"style":160},[154,2500,1029],{"style":164},[154,2502,1711],{"style":190},[154,2504,2505,2507,2509,2511,2514,2516,2518],{"class":156,"style":157},[154,2506,1019],{"style":164},[154,2508,2493],{"style":835},[154,2510,301],{"style":160},[154,2512,2513],{"style":804},"StreamLogsResponses ",[154,2515,632],{"style":160},[154,2517,1029],{"style":164},[154,2519,2520],{"style":190},"'.\u002Fgen\u002Ftypes\u002FStreamLogs'",[154,2522],{"class":156,"style":157},[154,2524,2525,2527,2529,2531,2533,2535,2537,2539,2541,2544,2546,2548,2550,2552,2554,2556,2559],{"class":156,"style":157},[154,2526,1044],{"style":164},[154,2528,1820],{"style":835},[154,2530,819],{"style":164},[154,2532,1053],{"style":164},[154,2534,2488],{"style":835},[154,2536,128],{"style":164},[154,2538,914],{"style":160},[154,2540,807],{"style":164},[154,2542,2543],{"style":804},"StreamLogsResponses",[154,2545,100],{"style":164},[154,2547,822],{"style":160},[154,2549,100],{"style":164},[154,2551,894],{"style":804},[154,2553,807],{"style":164},[154,2555,2543],{"style":804},[154,2557,2558],{"style":164},">>",[154,2560,2561],{"style":160},"({",[154,2563,2564,2566,2569,2571,2574],{"class":156,"style":157},[154,2565,171],{"style":160},[154,2567,2568],{"style":160},"method",[154,2570,187],{"style":164},[154,2572,2573],{"style":190},"'GET'",[154,2575,860],{"style":164},[154,2577,2578,2580,2583,2585,2588],{"class":156,"style":157},[154,2579,171],{"style":164},[154,2581,2582],{"style":160},"url",[154,2584,187],{"style":164},[154,2586,2587],{"style":190},"'\u002Flogs'",[154,2589,860],{"style":164},[154,2591,2592,2594,2597,2599,2601,2603,2605,2608,2610],{"class":156,"style":157},[154,2593,171],{"style":164},[154,2595,2596],{"style":160},"contentType",[154,2598,187],{"style":164},[154,2600,301],{"style":160},[154,2602,1255],{"style":160},[154,2604,187],{"style":164},[154,2606,2607],{"style":190},"'application\u002Fjsonl' ",[154,2609,311],{"style":160},[154,2611,860],{"style":164},[154,2613,2614],{"class":156,"style":157},[154,2615,2195],{"style":160},[11,2617,2618,2619,2622,2623,2626,2627,2630,2631,128],{},"Without ",[18,2620,2621],{},"contentType.response"," or an ",[18,2624,2625],{},"Accept"," header, ",[18,2628,2629],{},"client.stream"," sends ",[18,2632,2298],{},[11,2634,2635,2636,2639,2640,2642,2643,2647],{},"The item type defaults to ",[18,2637,2638],{},"ServerSentEvent"," around the success body. To stream another format, register a ",[18,2641,914],{}," handler, as ",[124,2644,2646],{"href":2645},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Fserialization#add-a-media-type","Add a media type"," shows.",[11,2649,2650,2651,2654,2655,2658],{},"Import the stream helpers and types from ",[18,2652,2653],{},".kubb\u002Fclient",", and do not edit the ",[18,2656,2657],{},".kubb\u002F"," files: Kubb rewrites them on each run.",[23,2660,2662],{"id":2661},"less-common-cases","Less common cases",[2664,2665,2667,2668,2670],"h3",{"id":2666},"json-in-a-data-string","JSON in a ",[18,2669,64],{}," string",[11,2672,2673,2674,2676,2677,2025,2680,2683,2684,2687],{},"When an event's ",[18,2675,64],{}," is a string with ",[18,2678,2679],{},"contentMediaType: application\u002Fjson",[18,2681,2682],{},"contentSchema",", Kubb types and parses it as that schema. See ",[124,2685,26],{"href":2686},"#how-kubb-detects-a-stream"," for the item schemas.",[2664,2689,2691],{"id":2690},"stream-calls-in-nodejs","Stream calls in Node.js",[11,2693,2694],{},"When a stream call runs in Node.js, the axios http adapter streams the body, with its proxy and agent settings. Only a browser call with the default adapters switches to the fetch adapter.",[2664,2696,2698],{"id":2697},"stream-result-types","Stream result types",[11,2700,2701,2702,165],{},"When you type a variable that holds a stream result, the type depends on the response and on ",[18,2703,2704],{},"returnType",[31,2706,2707,2717],{},[34,2708,2709],{},[37,2710,2711,2714],{},[40,2712,2713],{},"Setting",[40,2715,2716],{},"The call returns",[47,2718,2719,2729,2743,2757],{},[37,2720,2721,2724],{},[52,2722,2723],{},"Default",[52,2725,2726],{},[18,2727,2728],{},"Unwrappable\u003CStreamResult\u003C…>>",[37,2730,2731,2734],{},[52,2732,2733],{},"The response declares headers",[52,2735,2736,1601,2739,2742],{},[18,2737,2738],{},"Unwrappable\u003CStreamResultWithHeaders\u003C…>>",[18,2740,2741],{},"headers.get"," suggests their names",[37,2744,2745,2749],{},[52,2746,2747],{},[18,2748,927],{},[52,2750,2751,2754,2755],{},[18,2752,2753],{},"Promise\u003CUnwrappedStreamResult\u003C…>>",": the items, or the full result with ",[18,2756,1591],{},[37,2758,2759,2764],{},[52,2760,2761,2763],{},[18,2762,927],{},", and the response declares headers",[52,2765,2766],{},[18,2767,2768],{},"Promise\u003CUnwrappedStreamResultWithHeaders\u003C…>>",[11,2770,2771,2772,985,2774,2777],{},"In v5, a stream response that declared headers returned a plain ",[18,2773,875],{},[124,2775,786],{"href":2776},"#the-generated-function"," shows the default signature.",[2664,2779,2781],{"id":2780},"stream-options-kubb-sets","Stream options Kubb sets",[11,2783,2784,2785,2790],{},"When you call ",[124,2786,2788],{"href":2787},"#stream-with-the-client",[18,2789,2629],{}," yourself, pass the options a generated stream call gets from the document:",[31,2792,2793,2801],{},[34,2794,2795],{},[37,2796,2797,2799],{},[40,2798,940],{},[40,2800,943],{},[47,2802,2803,2824],{},[37,2804,2805,2810],{},[52,2806,2807],{},[18,2808,2809],{},"eventShape",[52,2811,2812,2813,2816,2817,2819,2820,2823],{},"Whether the validator checks the whole event (",[18,2814,2815],{},"'event'",") or its ",[18,2818,64],{}," (",[18,2821,2822],{},"'data'",").",[37,2825,2826,2831],{},[52,2827,2828],{},[18,2829,2830],{},"rawData",[52,2832,2833,2834,2836,2837,2839,2840,2842],{},"Keeps ",[18,2835,64],{}," as text, for every event or for a list of event names. Kubb sets it when the document types ",[18,2838,64],{}," as a string. Otherwise ",[18,2841,64],{}," is parsed as JSON when it parses.",[2664,2844,1477],{"id":2845},"event-names-ids-and-json-lines",[11,2847,2848],{},"When the server leaves a field out of an event, or sends JSON Lines:",[1555,2850,2851,2857,2866,2872],{},[1558,2852,2853,2854,2856],{},"An event takes ",[18,2855,1375],{}," as its name when the server sends none.",[1558,2858,2859,2860,2862,2863,2865],{},"The ",[18,2861,318],{}," carries over to later events, and ",[18,2864,337],{}," holds the server's reconnect hint.",[1558,2867,2868,2869,2871],{},"A JSON Lines stream has no event IDs, and ",[18,2870,968],{}," does not apply to it.",[1558,2873,999,2874,2876],{},[18,2875,106],{}," record must fit on one line.",[2664,2878,2044],{"id":2879},"event-ids-when-you-resume",[11,2881,2882,2883,165],{},"When you ",[124,2884,2886],{"href":2885},"#stop-abort-and-resume","resume a stream",[1555,2888,2889,2895,2907,2916],{},[1558,2890,2891,2892,2894],{},"The runtime reconnects only when ",[18,2893,337],{}," is set, because many streams end on purpose.",[1558,2896,2897,2899,2900,2902,2903,2906],{},[18,2898,918],{}," is empty until the server sends an ",[18,2901,318],{},", and an empty ",[18,2904,2905],{},"id:"," clears it.",[1558,2908,2909,2910,2912,2913,2915],{},"The resume loop copies ",[18,2911,918],{}," after each event, so after a clear it sends no ",[18,2914,1587],{},". A connection that drops before its first event keeps the ID from the connection before.",[1558,2917,119,2918,2920,2921,2923,2924,2926],{},[18,2919,927],{},", the items alone carry no ",[18,2922,918],{},", so pass ",[18,2925,1591],{}," to get the full result.",[2664,2928,2930],{"id":2929},"interceptors-on-a-stream-call","Interceptors on a stream call",[11,2932,2933,2934,2936,2937,2940,2941,128],{},"When a response interceptor runs on a stream call, ",[18,2935,64],{}," in its ",[18,2938,2939],{},"DecodedResponse"," is the raw body stream. See ",[124,2942,2944],{"href":2943},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Fconfigure-requests#add-interceptors","Add interceptors",[2664,2946,2948],{"id":2947},"stream-runtime-files","Stream runtime files",[11,2950,2951,2952,165],{},"When you look for a stream helper or type, import it from ",[18,2953,2653],{},[1555,2955,2956,2971],{},[1558,2957,2958,2960,2961,100,2963,2966,2967,2970],{},[18,2959,20],{}," holds ",[18,2962,2313],{},[18,2964,2965],{},"parseJsonLines",", and the stream media types, and ",[18,2968,2969],{},".kubb\u002Fclient.ts"," re-exports it.",[1558,2972,2973,2974,100,2976,100,2978,2980,2981,2983,2984,128],{},"The stream types, such as ",[18,2975,2638],{},[18,2977,889],{},[18,2979,841],{},", and ",[18,2982,875],{},", live in ",[18,2985,2986],{},".kubb\u002Fcore.ts",{"title":2988,"searchDepth":2989,"depth":2989,"links":2990},"",5,[2991,2993,2994,2995,2996,2997,2998,2999],{"id":25,"depth":2992,"text":26},2,{"id":785,"depth":2992,"text":786},{"id":1006,"depth":2992,"text":1007},{"id":1552,"depth":2992,"text":1553},{"id":2047,"depth":2992,"text":2048},{"id":2285,"depth":2992,"text":127},{"id":2456,"depth":2992,"text":2457},{"id":2661,"depth":2992,"text":2662,"children":3000},[3001,3004,3005,3006,3007,3008,3009,3010],{"id":2666,"depth":3002,"text":3003},3,"JSON in a data string",{"id":2690,"depth":3002,"text":2691},{"id":2697,"depth":3002,"text":2698},{"id":2780,"depth":3002,"text":2781},{"id":2845,"depth":3002,"text":1477},{"id":2879,"depth":3002,"text":2044},{"id":2929,"depth":3002,"text":2930},{"id":2947,"depth":3002,"text":2948},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Fserver-sent-events",1795727683703,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]