[{"data":1,"prerenderedAt":2988,"buildId":2989},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserver-sent-events":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":2987,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserver-sent-events.md",{},"Server-sent events",{"type":8,"value":9,"toc":2964},"minimark",[10,14,22,27,30,117,129,140,750,770,774,889,916,919,991,995,1446,1465,1481,1537,1541,1565,1580,1593,1657,1678,2007,2022,2032,2036,2149,2260,2270,2273,2306,2441,2445,2462,2603,2620,2635,2646,2650,2658,2675,2679,2685,2749,2755,2759,2768,2820,2823,2826,2854,2857,2864,2904,2908,2922,2926,2931],[11,12,13],"p",{},"Consume typed server-sent events and JSON Lines with the generated Ky 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.",[23,771,773],{"id":772},"the-generated-function","The generated function",[144,775,778],{"language":776,"code":777,"class":149},"typescript","export function streamChat\u003CThrowOnError extends boolean = true>(\n options: StreamOptions\u003CStreamChatOptions, ThrowOnError> = {},\n): Unwrappable\u003CStreamResult\u003CStreamChatResponses, ThrowOnError, TypedEvent\u003CSuccessOf\u003CStreamChatResponses>>>>",[18,779,781,166,816,166,848],{"class":780},"language-typescript",[154,782,783,786,789,792,795,798,801,804,807,810,813],{"class":156,"style":157},[154,784,785],{"style":164},"export ",[154,787,788],{"style":164},"function ",[154,790,191],{"style":791},"color:#6f42c1;--hls-dark:#b392f0",[154,793,794],{"style":164},"\u003C",[154,796,797],{"style":791},"ThrowOnError ",[154,799,800],{"style":164},"extends ",[154,802,803],{"style":791},"boolean ",[154,805,806],{"style":164},"= ",[154,808,809],{"style":160},"true",[154,811,812],{"style":164},">",[154,814,815],{"style":160},"(",[154,817,818,820,824,826,829,831,834,836,839,842,845],{"class":156,"style":157},[154,819,171],{"style":160},[154,821,823],{"style":822},"color:#24292e;--hls-dark:#e1e4e8","options",[154,825,187],{"style":822},[154,827,828],{"style":791},"StreamOptions",[154,830,794],{"style":164},[154,832,833],{"style":791},"StreamChatOptions",[154,835,100],{"style":164},[154,837,838],{"style":791},"ThrowOnError",[154,840,841],{"style":164},"> = ",[154,843,844],{"style":160},"{}",[154,846,847],{"style":164},",",[154,849,850,853,855,858,860,863,865,868,870,872,874,877,879,882,884,886],{"class":156,"style":157},[154,851,852],{"style":160},")",[154,854,187],{"style":822},[154,856,857],{"style":791},"Unwrappable",[154,859,794],{"style":164},[154,861,862],{"style":791},"StreamResult",[154,864,794],{"style":164},[154,866,867],{"style":791},"StreamChatResponses",[154,869,100],{"style":164},[154,871,838],{"style":791},[154,873,100],{"style":164},[154,875,876],{"style":791},"TypedEvent",[154,878,794],{"style":164},[154,880,881],{"style":791},"SuccessOf",[154,883,794],{"style":164},[154,885,867],{"style":791},[154,887,888],{"style":164},">>>>",[11,890,891,892,894,895,898,899,902,903,906,907,902,909,911,912,915],{},"A ",[18,893,862],{}," has the fields of a ",[18,896,897],{},"RequestResult"," for the first connection, plus ",[18,900,901],{},"stream"," and ",[18,904,905],{},"lastEventId",". The result iterates its items, which are also in ",[18,908,901],{},[18,910,64],{},". With ",[18,913,914],{},"returnType: 'data'",", the call resolves to the items.",[11,917,918],{},"Pass these stream options next to the request params:",[31,920,921,931],{},[34,922,923],{},[37,924,925,928],{},[40,926,927],{},"Option",[40,929,930],{},"What it does",[47,932,933,949,959,977],{},[37,934,935,940],{},[52,936,937],{},[18,938,939],{},"terminator",[52,941,942,943,945,946,128],{},"Ends the stream when an event's ",[18,944,64],{},", or a JSON line, equals this value, such as ",[18,947,948],{},"[DONE]",[37,950,951,956],{},[52,952,953],{},[18,954,955],{},"transform",[52,957,958],{},"Maps each Server-Sent Event before validation, for example to camelCase its keys.",[37,960,961,966],{},[52,962,963],{},[18,964,965],{},"maxEventSize",[52,967,968,969,972,973,976],{},"The most characters in one event or line. Default ",[18,970,971],{},"16 * 1024 * 1024",". ",[18,974,975],{},"Infinity"," turns it off.",[37,978,979,984],{},[52,980,981],{},[18,982,983],{},"signal",[52,985,986,987,990],{},"An ",[18,988,989],{},"AbortSignal"," that ends the request and the loop.",[23,992,994],{"id":993},"consume-items","Consume items",[141,996,997,1164,1295,1368],{},[144,998,1000],{"language":776,"filename":147,"code":999,"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,1001,1002,166,1020,166,1022,166,1075,166,1093,166,1105,166,1131,166,1138,166,1148,166,1154,166,1160],{"class":780},[154,1003,1004,1007,1009,1012,1014,1017],{"class":156,"style":157},[154,1005,1006],{"style":164},"import ",[154,1008,301],{"style":160},[154,1010,1011],{"style":822},"streamChat ",[154,1013,632],{"style":160},[154,1015,1016],{"style":164},"from ",[154,1018,1019],{"style":190},"'.\u002Fgen\u002Fclients\u002FstreamChat'",[154,1021],{"class":156,"style":157},[154,1023,1024,1027,1029,1032,1035,1038,1041,1043,1046,1049,1051,1053,1056,1058,1061,1063,1065,1067,1069,1072],{"class":156,"style":157},[154,1025,1026],{"style":164},"for await ",[154,1028,815],{"style":160},[154,1030,1031],{"style":164},"const ",[154,1033,1034],{"style":822},"event ",[154,1036,1037],{"style":164},"of ",[154,1039,1040],{"style":164},"await ",[154,1042,191],{"style":791},[154,1044,1045],{"style":160},"({ ",[154,1047,1048],{"style":160},"body",[154,1050,187],{"style":164},[154,1052,301],{"style":160},[154,1054,1055],{"style":160},"prompt",[154,1057,187],{"style":164},[154,1059,1060],{"style":190},"'Hi' ",[154,1062,311],{"style":160},[154,1064,100],{"style":164},[154,1066,939],{"style":160},[154,1068,187],{"style":164},[154,1070,1071],{"style":190},"'[DONE]' ",[154,1073,1074],{"style":160},"})) {",[154,1076,1077,1079,1082,1084,1086,1088,1090],{"class":156,"style":157},[154,1078,171],{"style":160},[154,1080,1081],{"style":164},"switch ",[154,1083,815],{"style":160},[154,1085,60],{"style":822},[154,1087,128],{"style":164},[154,1089,60],{"style":160},[154,1091,1092],{"style":160},") {",[154,1094,1095,1097,1100,1103],{"class":156,"style":157},[154,1096,181],{"style":160},[154,1098,1099],{"style":164},"case ",[154,1101,1102],{"style":190},"'message_delta'",[154,1104,165],{"style":164},[154,1106,1107,1109,1112,1114,1116,1118,1120,1122,1125,1128],{"class":156,"style":157},[154,1108,205],{"style":164},[154,1110,1111],{"style":791},"render",[154,1113,815],{"style":160},[154,1115,60],{"style":822},[154,1117,128],{"style":164},[154,1119,64],{"style":160},[154,1121,128],{"style":164},[154,1123,1124],{"style":160},"text",[154,1126,1127],{"style":160},") ",[154,1129,1130],{"style":635},"\u002F\u002F MessageDelta",[154,1132,1133,1135],{"class":156,"style":157},[154,1134,205],{"style":635},[154,1136,1137],{"style":164},"break",[154,1139,1140,1143,1146],{"class":156,"style":157},[154,1141,1142],{"style":164}," case ",[154,1144,1145],{"style":190},"'ping'",[154,1147,165],{"style":164},[154,1149,1150,1152],{"class":156,"style":157},[154,1151,205],{"style":164},[154,1153,1137],{"style":164},[154,1155,1156,1158],{"class":156,"style":157},[154,1157,171],{"style":164},[154,1159,311],{"style":160},[154,1161,1162],{"class":156,"style":157},[154,1163,311],{"style":160},[144,1165,1167],{"language":776,"filename":540,"code":1166,"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,1168,1169,166,1185,166,1187,166,1228,166,1253,166,1255],{"class":780},[154,1170,1171,1173,1175,1178,1180,1182],{"class":156,"style":157},[154,1172,1006],{"style":164},[154,1174,301],{"style":160},[154,1176,1177],{"style":822},"streamPetEvents ",[154,1179,632],{"style":160},[154,1181,1016],{"style":164},[154,1183,1184],{"style":190},"'.\u002Fgen\u002Fclients\u002FstreamPetEvents'",[154,1186],{"class":156,"style":157},[154,1188,1189,1191,1193,1195,1197,1200,1202,1204,1206,1208,1210,1213,1215,1217,1220,1222,1225],{"class":156,"style":157},[154,1190,1031],{"style":164},[154,1192,301],{"style":160},[154,1194,901],{"style":822},[154,1196,100],{"style":164},[154,1198,1199],{"style":822},"response ",[154,1201,632],{"style":160},[154,1203,806],{"style":164},[154,1205,1040],{"style":164},[154,1207,570],{"style":791},[154,1209,1045],{"style":160},[154,1211,1212],{"style":160},"path",[154,1214,187],{"style":164},[154,1216,301],{"style":160},[154,1218,1219],{"style":160},"petId",[154,1221,187],{"style":164},[154,1223,1224],{"style":160},"1 ",[154,1226,1227],{"style":160},"} })",[154,1229,1230,1233,1235,1238,1240,1243,1245,1248,1250],{"class":156,"style":157},[154,1231,1232],{"style":822},"console",[154,1234,128],{"style":164},[154,1236,1237],{"style":791},"info",[154,1239,815],{"style":160},[154,1241,1242],{"style":822},"response",[154,1244,128],{"style":164},[154,1246,1247],{"style":160},"status",[154,1249,1127],{"style":160},[154,1251,1252],{"style":635},"\u002F\u002F 200",[154,1254],{"class":156,"style":157},[154,1256,1257,1259,1261,1263,1265,1268,1270,1272,1274,1276,1278,1280,1282,1284,1286,1288,1290,1292],{"class":156,"style":157},[154,1258,1026],{"style":164},[154,1260,815],{"style":160},[154,1262,1031],{"style":164},[154,1264,301],{"style":160},[154,1266,1267],{"style":822},"data ",[154,1269,632],{"style":160},[154,1271,1037],{"style":164},[154,1273,901],{"style":822},[154,1275,1127],{"style":160},[154,1277,1232],{"style":822},[154,1279,128],{"style":164},[154,1281,1237],{"style":791},[154,1283,815],{"style":160},[154,1285,64],{"style":822},[154,1287,128],{"style":164},[154,1289,258],{"style":160},[154,1291,1127],{"style":160},[154,1293,1294],{"style":635},"\u002F\u002F PetEvent",[144,1296,1298],{"language":776,"filename":658,"code":1297,"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,1299,1300,166,1316,166,1318],{"class":780},[154,1301,1302,1304,1306,1309,1311,1313],{"class":156,"style":157},[154,1303,1006],{"style":164},[154,1305,301],{"style":160},[154,1307,1308],{"style":822},"streamLogs ",[154,1310,632],{"style":160},[154,1312,1016],{"style":164},[154,1314,1315],{"style":190},"'.\u002Fgen\u002Fclients\u002FstreamLogs'",[154,1317],{"class":156,"style":157},[154,1319,1320,1322,1324,1326,1329,1331,1333,1335,1338,1340,1342,1344,1346,1349,1351,1354,1356,1358,1360,1363,1365],{"class":156,"style":157},[154,1321,1026],{"style":164},[154,1323,815],{"style":160},[154,1325,1031],{"style":164},[154,1327,1328],{"style":822},"entry ",[154,1330,1037],{"style":164},[154,1332,1040],{"style":164},[154,1334,687],{"style":791},[154,1336,1337],{"style":160},"()) ",[154,1339,1232],{"style":822},[154,1341,128],{"style":164},[154,1343,1237],{"style":791},[154,1345,815],{"style":160},[154,1347,1348],{"style":822},"entry",[154,1350,128],{"style":164},[154,1352,1353],{"style":160},"level",[154,1355,100],{"style":164},[154,1357,1348],{"style":822},[154,1359,128],{"style":164},[154,1361,1362],{"style":160},"message",[154,1364,1127],{"style":160},[154,1366,1367],{"style":635},"\u002F\u002F LogEntry",[144,1369,1371],{"language":776,"filename":914,"code":1370,"class":149},"\u002F\u002F with pluginKy({ returnType: 'data' })\nconst events = await streamPetEvents({ path: { petId: 1 } })\n\nfor await (const { data } of events) console.info(data.type)",[18,1372,1373,166,1378,166,1407,166,1409],{"class":780},[154,1374,1375],{"class":156,"style":157},[154,1376,1377],{"style":635},"\u002F\u002F with pluginKy({ returnType: 'data' })",[154,1379,1380,1382,1385,1387,1389,1391,1393,1395,1397,1399,1401,1403,1405],{"class":156,"style":157},[154,1381,1031],{"style":164},[154,1383,1384],{"style":822},"events ",[154,1386,806],{"style":164},[154,1388,1040],{"style":164},[154,1390,570],{"style":791},[154,1392,1045],{"style":160},[154,1394,1212],{"style":160},[154,1396,187],{"style":164},[154,1398,301],{"style":160},[154,1400,1219],{"style":160},[154,1402,187],{"style":164},[154,1404,1224],{"style":160},[154,1406,1227],{"style":160},[154,1408],{"class":156,"style":157},[154,1410,1411,1413,1415,1417,1419,1421,1423,1425,1428,1430,1432,1434,1436,1438,1440,1442,1444],{"class":156,"style":157},[154,1412,1026],{"style":164},[154,1414,815],{"style":160},[154,1416,1031],{"style":164},[154,1418,301],{"style":160},[154,1420,1267],{"style":822},[154,1422,632],{"style":160},[154,1424,1037],{"style":164},[154,1426,1427],{"style":822},"events",[154,1429,1127],{"style":160},[154,1431,1232],{"style":822},[154,1433,128],{"style":164},[154,1435,1237],{"style":791},[154,1437,815],{"style":160},[154,1439,64],{"style":822},[154,1441,128],{"style":164},[154,1443,258],{"style":160},[154,1445,852],{"style":160},[11,1447,1448,1449,1452,1453,1456,1457,1460,1461,128],{},"An event the document does not declare reaches the ",[18,1450,1451],{},"default"," of your ",[18,1454,1455],{},"switch",", so declare heartbeat and ",[18,1458,1459],{},"error"," events too. For event names, IDs, and JSON Lines limits, see ",[124,1462,1464],{"href":1463},"#event-names-ids-and-json-lines","Event names, IDs, and JSON Lines",[11,1466,119,1467,1470,1471,1473,1474,1477,1478,165],{},[18,1468,1469],{},"validator: 'zod'",", the validator checks each item: the whole event for typed events, ",[18,1472,64],{}," for a payload, and each line for JSON Lines. To keep going past a failing item, return ",[18,1475,1476],{},"{ value }"," from ",[18,1479,1480],{},"onValidationError",[144,1482,1484],{"language":776,"code":1483,"class":149},"const { stream } = await streamChat({ body, onValidationError: (error, { value }) => ({ value }) })",[18,1485,1486],{"class":780},[154,1487,1488,1490,1492,1495,1497,1499,1501,1503,1505,1507,1509,1511,1513,1515,1517,1519,1521,1524,1527,1530,1532,1534],{"class":156,"style":157},[154,1489,1031],{"style":164},[154,1491,301],{"style":160},[154,1493,1494],{"style":822},"stream ",[154,1496,632],{"style":160},[154,1498,806],{"style":164},[154,1500,1040],{"style":164},[154,1502,191],{"style":791},[154,1504,1045],{"style":160},[154,1506,1048],{"style":822},[154,1508,100],{"style":164},[154,1510,1480],{"style":160},[154,1512,187],{"style":164},[154,1514,815],{"style":160},[154,1516,1459],{"style":822},[154,1518,100],{"style":164},[154,1520,301],{"style":160},[154,1522,1523],{"style":822},"value ",[154,1525,1526],{"style":160},"}) ",[154,1528,1529],{"style":164},"=> ",[154,1531,1045],{"style":160},[154,1533,1523],{"style":822},[154,1535,1536],{"style":160},"}) })",[23,1538,1540],{"id":1539},"stop-abort-and-resume","Stop, abort, and resume",[1542,1543,1544,1550,1556],"ul",{},[1545,1546,1547,1549],"li",{},[18,1548,1137],{}," out of the loop to stop. The runtime cancels the reader and releases the connection.",[1545,1551,1552,1553,1555],{},"Pass ",[18,1554,983],{}," to stop from outside. The call or the loop rejects with the signal's reason.",[1545,1557,1558,1559,1564],{},"A dropped connection ends the loop with the transport's error, unless ",[124,1560,1562],{"href":1561},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fconfigure-requests#retry-a-failed-call",[18,1563,337],{}," is set.",[11,1566,119,1567,1569,1570,762,1572,1575,1576,1579],{},[18,1568,337],{},", the runtime retries a failed connect and reopens a dropped ",[18,1571,56],{},[18,1573,1574],{},"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,1577,1578],{},"throwOnError: false",". A stream that ends and a JSON Lines stream are not reopened.",[11,1581,1582,1584,1585,1588,1589,1592],{},[18,1583,191],{}," is a ",[18,1586,1587],{},"POST",", so ",[18,1590,1591],{},"retry.methods"," has to name it:",[144,1594,1596],{"language":776,"code":1595,"class":149},"for await (const event of await streamChat({ body, retry: { limit: 3, methods: ['POST'] } })) render(event)",[18,1597,1598],{"class":780},[154,1599,1600,1602,1604,1606,1608,1610,1612,1614,1616,1618,1620,1622,1624,1626,1629,1631,1634,1636,1639,1641,1643,1646,1649,1651,1653,1655],{"class":156,"style":157},[154,1601,1026],{"style":164},[154,1603,815],{"style":160},[154,1605,1031],{"style":164},[154,1607,1034],{"style":822},[154,1609,1037],{"style":164},[154,1611,1040],{"style":164},[154,1613,191],{"style":791},[154,1615,1045],{"style":160},[154,1617,1048],{"style":822},[154,1619,100],{"style":164},[154,1621,337],{"style":160},[154,1623,187],{"style":164},[154,1625,301],{"style":160},[154,1627,1628],{"style":160},"limit",[154,1630,187],{"style":164},[154,1632,1633],{"style":160},"3",[154,1635,100],{"style":164},[154,1637,1638],{"style":160},"methods",[154,1640,187],{"style":164},[154,1642,275],{"style":160},[154,1644,1645],{"style":190},"'POST'",[154,1647,1648],{"style":160},"] } })) ",[154,1650,1111],{"style":791},[154,1652,815],{"style":160},[154,1654,60],{"style":822},[154,1656,852],{"style":160},[11,1658,1659,1660,1662,1663,1665,1666,1668,1669,1671,1672,1674,1675,165],{},"To resume by hand, leave ",[18,1661,337],{}," off and send a new call with a ",[18,1664,1574],{}," header. ",[18,1667,905],{}," is the ",[18,1670,318],{}," of the last event the server completed. Declare ",[18,1673,1574],{}," as a header parameter, so the call accepts it in ",[18,1676,1677],{},"headers",[144,1679,1681],{"language":776,"code":1680,"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,1682,1683,166,1699,166,1715,166,1717,166,1742,166,1757,166,1759,166,1789,166,1799,166,1845,166,1864,166,1878,166,1887,166,1893,166,1900,166,1915,166,1966,166,1972,166,1977,166,1981,166,1983],{"class":780},[154,1684,1685,1687,1689,1692,1694,1696],{"class":156,"style":157},[154,1686,1006],{"style":164},[154,1688,301],{"style":160},[154,1690,1691],{"style":791},"ResponseError ",[154,1693,632],{"style":160},[154,1695,1016],{"style":164},[154,1697,1698],{"style":190},"'.\u002Fgen\u002F.kubb\u002Fclient'",[154,1700,1701,1703,1705,1708,1710,1712],{"class":156,"style":157},[154,1702,1006],{"style":164},[154,1704,301],{"style":160},[154,1706,1707],{"style":791},"ValidationError ",[154,1709,632],{"style":160},[154,1711,1016],{"style":164},[154,1713,1714],{"style":190},"'.\u002Fgen\u002F.kubb\u002FstandardSchema'",[154,1716],{"class":156,"style":157},[154,1718,1719,1722,1725,1728,1731,1733,1736,1738,1740],{"class":156,"style":157},[154,1720,1721],{"style":164},"async ",[154,1723,1724],{"style":164},"function",[154,1726,1727],{"style":164},"* ",[154,1729,1730],{"style":791},"resumeChat",[154,1732,815],{"style":160},[154,1734,1735],{"style":822},"attempts ",[154,1737,806],{"style":164},[154,1739,1633],{"style":160},[154,1741,1092],{"style":160},[154,1743,1744,1746,1749,1752,1754],{"class":156,"style":157},[154,1745,171],{"style":160},[154,1747,1748],{"style":164},"let ",[154,1750,1751],{"style":822},"lastEventId ",[154,1753,806],{"style":164},[154,1755,1756],{"style":190},"''",[154,1758],{"class":156,"style":157},[154,1760,1761,1763,1766,1768,1770,1773,1775,1778,1781,1784,1787],{"class":156,"style":157},[154,1762,171],{"style":190},[154,1764,1765],{"style":164},"for ",[154,1767,815],{"style":160},[154,1769,1748],{"style":164},[154,1771,1772],{"style":822},"attempt ",[154,1774,806],{"style":164},[154,1776,1777],{"style":160},"1",[154,1779,1780],{"style":164},"; ; ",[154,1782,1783],{"style":822},"attempt",[154,1785,1786],{"style":164},"++",[154,1788,1092],{"style":160},[154,1790,1791,1793,1796],{"class":156,"style":157},[154,1792,181],{"style":160},[154,1794,1795],{"style":164},"try ",[154,1797,1798],{"style":160},"{",[154,1800,1801,1803,1805,1808,1810,1812,1814,1816,1818,1820,1822,1824,1826,1829,1831,1834,1836,1838,1840,1842],{"class":156,"style":157},[154,1802,205],{"style":160},[154,1804,1031],{"style":164},[154,1806,1807],{"style":822},"result ",[154,1809,806],{"style":164},[154,1811,1040],{"style":164},[154,1813,191],{"style":791},[154,1815,1045],{"style":160},[154,1817,1048],{"style":822},[154,1819,100],{"style":164},[154,1821,1677],{"style":160},[154,1823,187],{"style":164},[154,1825,1751],{"style":822},[154,1827,1828],{"style":164},"? ",[154,1830,301],{"style":160},[154,1832,1833],{"style":190},"'Last-Event-ID'",[154,1835,187],{"style":164},[154,1837,1751],{"style":822},[154,1839,632],{"style":160},[154,1841,187],{"style":164},[154,1843,1844],{"style":160},"{} })",[154,1846,1847,1849,1851,1853,1855,1857,1859,1862],{"class":156,"style":157},[154,1848,205],{"style":160},[154,1850,1026],{"style":164},[154,1852,815],{"style":160},[154,1854,1031],{"style":164},[154,1856,1034],{"style":822},[154,1858,1037],{"style":164},[154,1860,1861],{"style":822},"result",[154,1863,1092],{"style":160},[154,1865,1866,1868,1870,1872,1874,1876],{"class":156,"style":157},[154,1867,215],{"style":160},[154,1869,1751],{"style":822},[154,1871,806],{"style":164},[154,1873,1861],{"style":822},[154,1875,128],{"style":164},[154,1877,905],{"style":160},[154,1879,1880,1882,1885],{"class":156,"style":157},[154,1881,215],{"style":160},[154,1883,1884],{"style":164},"yield ",[154,1886,60],{"style":822},[154,1888,1889,1891],{"class":156,"style":157},[154,1890,205],{"style":822},[154,1892,311],{"style":160},[154,1894,1895,1897],{"class":156,"style":157},[154,1896,205],{"style":160},[154,1898,1899],{"style":164},"return",[154,1901,1902,1904,1906,1909,1911,1913],{"class":156,"style":157},[154,1903,181],{"style":164},[154,1905,632],{"style":160},[154,1907,1908],{"style":164},"catch ",[154,1910,815],{"style":160},[154,1912,1459],{"style":822},[154,1914,1092],{"style":160},[154,1916,1917,1919,1922,1924,1926,1929,1931,1934,1937,1939,1942,1944,1946,1948,1950,1953,1956,1959,1961,1964],{"class":156,"style":157},[154,1918,205],{"style":160},[154,1920,1921],{"style":164},"if ",[154,1923,815],{"style":160},[154,1925,1772],{"style":822},[154,1927,1928],{"style":164},"=== ",[154,1930,1735],{"style":822},[154,1932,1933],{"style":164},"|| ",[154,1935,1936],{"style":791},"ResponseError",[154,1938,128],{"style":164},[154,1940,1941],{"style":791},"is",[154,1943,815],{"style":160},[154,1945,1459],{"style":822},[154,1947,1127],{"style":160},[154,1949,1933],{"style":164},[154,1951,1952],{"style":822},"error ",[154,1954,1955],{"style":164},"instanceof ",[154,1957,1958],{"style":791},"ValidationError",[154,1960,1127],{"style":160},[154,1962,1963],{"style":164},"throw ",[154,1965,1459],{"style":822},[154,1967,1968,1970],{"class":156,"style":157},[154,1969,181],{"style":822},[154,1971,311],{"style":160},[154,1973,1974],{"class":156,"style":157},[154,1975,1976],{"style":160}," }",[154,1978,1979],{"class":156,"style":157},[154,1980,311],{"style":160},[154,1982],{"class":156,"style":157},[154,1984,1985,1987,1989,1991,1993,1995,1997,1999,2001,2003,2005],{"class":156,"style":157},[154,1986,1026],{"style":164},[154,1988,815],{"style":160},[154,1990,1031],{"style":164},[154,1992,1034],{"style":822},[154,1994,1037],{"style":164},[154,1996,1730],{"style":791},[154,1998,1337],{"style":160},[154,2000,1111],{"style":791},[154,2002,815],{"style":160},[154,2004,60],{"style":822},[154,2006,852],{"style":160},[11,2008,2009,2010,2012,2013,2015,2016,2018,2019,2021],{},"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,2011,1936],{}," and a ",[18,2014,1958],{}," 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,2017,983],{},". An error from ",[18,2020,1111],{}," is thrown outside the generator, so it is never retried.",[11,2023,2024,2025,2027,2028,128],{},"For cleared IDs and resuming with ",[18,2026,914],{},", see ",[124,2029,2031],{"href":2030},"#event-ids-when-you-resume","Event IDs when you resume",[23,2033,2035],{"id":2034},"handle-errors","Handle errors",[31,2037,2038,2048],{},[34,2039,2040],{},[37,2041,2042,2045],{},[40,2043,2044],{},"What happens",[40,2046,2047],{},"Where it fails",[47,2049,2050,2060,2081,2095,2103,2111,2127,2139],{},[37,2051,2052,2055],{},[52,2053,2054],{},"Non-2xx response",[52,2056,2057,2058,128],{},"The call throws a ",[18,2059,1936],{},[37,2061,2062,2067],{},[52,2063,2064,2065],{},"Non-2xx response with ",[18,2066,1578],{},[52,2068,2069,2070,902,2072,972,2074,2076,2077,2080],{},"The call resolves with ",[18,2071,1247],{},[18,2073,1459],{},[18,2075,64],{}," is ",[18,2078,2079],{},"undefined",", and the stream yields nothing.",[37,2082,2083,2086],{},[52,2084,2085],{},"2xx response whose body is not a stream, such as JSON",[52,2087,2057,2088,2091,2092,128],{},[18,2089,2090],{},"TypeError"," with the body as its ",[18,2093,2094],{},"cause",[37,2096,2097,2100],{},[52,2098,2099],{},"2xx response with an empty body",[52,2101,2102],{},"No error. The stream is empty.",[37,2104,2105,2108],{},[52,2106,2107],{},"Dropped connection or abort",[52,2109,2110],{},"The loop throws.",[37,2112,2113,2116],{},[52,2114,2115],{},"An item fails its schema",[52,2117,2118,2119,2121,2122,2124,2125,128],{},"The loop throws a ",[18,2120,1958],{},", unless ",[18,2123,1480],{}," returns ",[18,2126,1476],{},[37,2128,2129,2134],{},[52,2130,2131,2132],{},"An event is larger than ",[18,2133,965],{},[52,2135,2118,2136,128],{},[18,2137,2138],{},"RangeError",[37,2140,2141,2144],{},[52,2142,2143],{},"A JSON line is not valid JSON",[52,2145,2118,2146,128],{},[18,2147,2148],{},"SyntaxError",[144,2150,2152],{"language":776,"code":2151,"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,2153,2154,166,2183,166,2185,166,2231],{"class":780},[154,2155,2156,2158,2160,2162,2164,2166,2168,2170,2172,2175,2177,2180],{"class":156,"style":157},[154,2157,1031],{"style":164},[154,2159,1807],{"style":822},[154,2161,806],{"style":164},[154,2163,1040],{"style":164},[154,2165,191],{"style":791},[154,2167,1045],{"style":160},[154,2169,1048],{"style":822},[154,2171,100],{"style":164},[154,2173,2174],{"style":160},"throwOnError",[154,2176,187],{"style":164},[154,2178,2179],{"style":160},"false ",[154,2181,2182],{"style":160},"})",[154,2184],{"class":156,"style":157},[154,2186,2187,2189,2191,2194,2196,2198,2200,2202,2204,2206,2208,2210,2213,2215,2217,2219,2221,2223,2225,2227,2229],{"class":156,"style":157},[154,2188,1921],{"style":164},[154,2190,815],{"style":160},[154,2192,2193],{"style":164},"!",[154,2195,1861],{"style":822},[154,2197,128],{"style":164},[154,2199,64],{"style":160},[154,2201,1127],{"style":160},[154,2203,1232],{"style":822},[154,2205,128],{"style":164},[154,2207,1459],{"style":791},[154,2209,815],{"style":160},[154,2211,2212],{"style":190},"'stream rejected'",[154,2214,100],{"style":164},[154,2216,1861],{"style":822},[154,2218,128],{"style":164},[154,2220,1247],{"style":160},[154,2222,100],{"style":164},[154,2224,1861],{"style":822},[154,2226,128],{"style":164},[154,2228,1459],{"style":160},[154,2230,852],{"style":160},[154,2232,2233,2236,2238,2240,2242,2244,2246,2248,2250,2252,2254,2256,2258],{"class":156,"style":157},[154,2234,2235],{"style":164},"else for await ",[154,2237,815],{"style":160},[154,2239,1031],{"style":164},[154,2241,1034],{"style":822},[154,2243,1037],{"style":164},[154,2245,1861],{"style":822},[154,2247,128],{"style":164},[154,2249,64],{"style":160},[154,2251,1127],{"style":160},[154,2253,1111],{"style":791},[154,2255,815],{"style":160},[154,2257,60],{"style":822},[154,2259,852],{"style":160},[11,2261,2262,2263,972,2266,2269],{},"An error thrown from the loop skips ",[18,2264,2265],{},"client.interceptors.error",[18,2267,2268],{},".unwrap()"," resolves to the items, as on a regular call.",[23,2271,127],{"id":2272},"json-or-an-event-stream",[11,2274,2275,2276,2278,2279,2282,2283,2286,2287,2290,2291,2293,2294,2297,2298,2301,2302,2305],{},"When the success response declares ",[18,2277,56],{}," next to another type, such as ",[18,2280,2281],{},"application\u002Fjson",", Kubb generates a normal call that sends ",[18,2284,2285],{},"Accept: text\u002Fevent-stream",". Pass ",[18,2288,2289],{},"contentType: { response: 'application\u002Fjson' }"," to ask for JSON. When the server streams, ",[18,2292,64],{}," is the raw ",[18,2295,2296],{},"ReadableStream\u003CUint8Array>",", so read it with ",[18,2299,2300],{},"parseEventStream",", or ",[18,2303,2304],{},"parseJsonLines({ stream })"," for JSON Lines:",[144,2307,2309],{"language":776,"code":2308,"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,2310,2311,166,2326,166,2328,166,2348,166,2350,166,2370,166,2409,166,2418,166,2437],{"class":780},[154,2312,2313,2315,2317,2320,2322,2324],{"class":156,"style":157},[154,2314,1006],{"style":164},[154,2316,301],{"style":160},[154,2318,2319],{"style":822},"parseEventStream ",[154,2321,632],{"style":160},[154,2323,1016],{"style":164},[154,2325,1698],{"style":190},[154,2327],{"class":156,"style":157},[154,2329,2330,2332,2334,2336,2338,2341,2343,2346],{"class":156,"style":157},[154,2331,1031],{"style":164},[154,2333,1807],{"style":822},[154,2335,806],{"style":164},[154,2337,1040],{"style":164},[154,2339,2340],{"style":791},"getRecentChanges",[154,2342,1045],{"style":160},[154,2344,2345],{"style":822},"signal ",[154,2347,2182],{"style":160},[154,2349],{"class":156,"style":157},[154,2351,2352,2354,2356,2358,2360,2363,2365,2368],{"class":156,"style":157},[154,2353,1921],{"style":164},[154,2355,815],{"style":160},[154,2357,1861],{"style":822},[154,2359,128],{"style":164},[154,2361,2362],{"style":160},"contentType ",[154,2364,1928],{"style":164},[154,2366,2367],{"style":190},"'text\u002Fevent-stream'",[154,2369,1092],{"style":160},[154,2371,2372,2374,2376,2378,2380,2382,2384,2386,2388,2390,2392,2394,2396,2398,2401,2403,2405,2407],{"class":156,"style":157},[154,2373,171],{"style":160},[154,2375,1026],{"style":164},[154,2377,815],{"style":160},[154,2379,1031],{"style":164},[154,2381,301],{"style":160},[154,2383,1267],{"style":822},[154,2385,632],{"style":160},[154,2387,1037],{"style":164},[154,2389,2300],{"style":791},[154,2391,815],{"style":160},[154,2393,1861],{"style":822},[154,2395,128],{"style":164},[154,2397,64],{"style":160},[154,2399,2400],{"style":160},")) ",[154,2402,1111],{"style":791},[154,2404,815],{"style":160},[154,2406,64],{"style":822},[154,2408,852],{"style":160},[154,2410,2411,2413,2416],{"class":156,"style":157},[154,2412,632],{"style":160},[154,2414,2415],{"style":164},"else ",[154,2417,1798],{"style":160},[154,2419,2420,2422,2424,2426,2428,2430,2432,2434],{"class":156,"style":157},[154,2421,171],{"style":160},[154,2423,1111],{"style":791},[154,2425,815],{"style":160},[154,2427,1861],{"style":822},[154,2429,128],{"style":164},[154,2431,64],{"style":160},[154,2433,1127],{"style":160},[154,2435,2436],{"style":635},"\u002F\u002F the JSON body",[154,2438,2439],{"class":156,"style":157},[154,2440,311],{"style":160},[23,2442,2444],{"id":2443},"stream-with-the-client","Stream with the client",[11,2446,2447,2450,2451,2454,2455,2458,2459,2461],{},[18,2448,2449],{},"client.stream(config)"," sends a stream request by hand. It runs the same interceptors and transport as ",[18,2452,2453],{},"client(config)",", and validates each item with ",[18,2456,2457],{},"validator.response",". Type it with the responses record, ",[18,2460,838],{},", and the item type:",[144,2463,2465],{"language":776,"code":2464,"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,2466,2467,166,2490,166,2508,166,2510,166,2549,166,2563,166,2577,166,2599],{"class":780},[154,2468,2469,2471,2473,2476,2478,2481,2484,2486,2488],{"class":156,"style":157},[154,2470,1006],{"style":164},[154,2472,301],{"style":160},[154,2474,2475],{"style":822},"client",[154,2477,100],{"style":164},[154,2479,2480],{"style":164},"type ",[154,2482,2483],{"style":791},"SuccessOf ",[154,2485,632],{"style":160},[154,2487,1016],{"style":164},[154,2489,1698],{"style":190},[154,2491,2492,2494,2496,2498,2501,2503,2505],{"class":156,"style":157},[154,2493,1006],{"style":164},[154,2495,2480],{"style":822},[154,2497,301],{"style":160},[154,2499,2500],{"style":791},"StreamLogsResponses ",[154,2502,632],{"style":160},[154,2504,1016],{"style":164},[154,2506,2507],{"style":190},"'.\u002Fgen\u002Ftypes\u002FStreamLogs'",[154,2509],{"class":156,"style":157},[154,2511,2512,2514,2516,2518,2520,2522,2524,2526,2528,2531,2533,2535,2537,2539,2541,2543,2546],{"class":156,"style":157},[154,2513,1031],{"style":164},[154,2515,1807],{"style":822},[154,2517,806],{"style":164},[154,2519,1040],{"style":164},[154,2521,2475],{"style":822},[154,2523,128],{"style":164},[154,2525,901],{"style":160},[154,2527,794],{"style":164},[154,2529,2530],{"style":791},"StreamLogsResponses",[154,2532,100],{"style":164},[154,2534,809],{"style":160},[154,2536,100],{"style":164},[154,2538,881],{"style":791},[154,2540,794],{"style":164},[154,2542,2530],{"style":791},[154,2544,2545],{"style":164},">>",[154,2547,2548],{"style":160},"({",[154,2550,2551,2553,2556,2558,2561],{"class":156,"style":157},[154,2552,171],{"style":160},[154,2554,2555],{"style":160},"method",[154,2557,187],{"style":164},[154,2559,2560],{"style":190},"'GET'",[154,2562,847],{"style":164},[154,2564,2565,2567,2570,2572,2575],{"class":156,"style":157},[154,2566,171],{"style":164},[154,2568,2569],{"style":160},"url",[154,2571,187],{"style":164},[154,2573,2574],{"style":190},"'\u002Flogs'",[154,2576,847],{"style":164},[154,2578,2579,2581,2584,2586,2588,2590,2592,2595,2597],{"class":156,"style":157},[154,2580,171],{"style":164},[154,2582,2583],{"style":160},"contentType",[154,2585,187],{"style":164},[154,2587,301],{"style":160},[154,2589,1242],{"style":160},[154,2591,187],{"style":164},[154,2593,2594],{"style":190},"'application\u002Fjsonl' ",[154,2596,311],{"style":160},[154,2598,847],{"style":164},[154,2600,2601],{"class":156,"style":157},[154,2602,2182],{"style":160},[11,2604,2605,2606,2609,2610,2613,2614,2617,2618,128],{},"Without ",[18,2607,2608],{},"contentType.response"," or an ",[18,2611,2612],{},"Accept"," header, ",[18,2615,2616],{},"client.stream"," sends ",[18,2619,2285],{},[11,2621,2622,2623,2626,2627,2629,2630,2634],{},"The item type defaults to ",[18,2624,2625],{},"ServerSentEvent"," around the success body. To stream another format, register a ",[18,2628,901],{}," handler, as ",[124,2631,2633],{"href":2632},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserialization#add-a-media-type","Add a media type"," shows.",[11,2636,2637,2638,2641,2642,2645],{},"Import the stream helpers and types from ",[18,2639,2640],{},".kubb\u002Fclient",", and do not edit the ",[18,2643,2644],{},".kubb\u002F"," files: Kubb rewrites them on each run.",[23,2647,2649],{"id":2648},"less-common-cases","Less common cases",[2651,2652,2654,2655,2657],"h3",{"id":2653},"json-in-a-data-string","JSON in a ",[18,2656,64],{}," string",[11,2659,2660,2661,2663,2664,2012,2667,2670,2671,2674],{},"When an event's ",[18,2662,64],{}," is a string with ",[18,2665,2666],{},"contentMediaType: application\u002Fjson",[18,2668,2669],{},"contentSchema",", Kubb types and parses it as that schema. See ",[124,2672,26],{"href":2673},"#how-kubb-detects-a-stream"," for the item schemas.",[2651,2676,2678],{"id":2677},"stream-result-types","Stream result types",[11,2680,2681,2682,165],{},"When you type a variable that holds a stream result, the type depends on the response and on ",[18,2683,2684],{},"returnType",[31,2686,2687,2697],{},[34,2688,2689],{},[37,2690,2691,2694],{},[40,2692,2693],{},"Setting",[40,2695,2696],{},"The call returns",[47,2698,2699,2709,2723,2737],{},[37,2700,2701,2704],{},[52,2702,2703],{},"Default",[52,2705,2706],{},[18,2707,2708],{},"Unwrappable\u003CStreamResult\u003C…>>",[37,2710,2711,2714],{},[52,2712,2713],{},"The response declares headers",[52,2715,2716,1588,2719,2722],{},[18,2717,2718],{},"Unwrappable\u003CStreamResultWithHeaders\u003C…>>",[18,2720,2721],{},"headers.get"," suggests their names",[37,2724,2725,2729],{},[52,2726,2727],{},[18,2728,914],{},[52,2730,2731,2734,2735],{},[18,2732,2733],{},"Promise\u003CUnwrappedStreamResult\u003C…>>",": the items, or the full result with ",[18,2736,1578],{},[37,2738,2739,2744],{},[52,2740,2741,2743],{},[18,2742,914],{},", and the response declares headers",[52,2745,2746],{},[18,2747,2748],{},"Promise\u003CUnwrappedStreamResultWithHeaders\u003C…>>",[11,2750,2751,2754],{},[124,2752,773],{"href":2753},"#the-generated-function"," shows the default signature.",[2651,2756,2758],{"id":2757},"stream-options-kubb-sets","Stream options Kubb sets",[11,2760,2761,2762,2767],{},"When you call ",[124,2763,2765],{"href":2764},"#stream-with-the-client",[18,2766,2616],{}," yourself, pass the options a generated stream call gets from the document:",[31,2769,2770,2778],{},[34,2771,2772],{},[37,2773,2774,2776],{},[40,2775,927],{},[40,2777,930],{},[47,2779,2780,2801],{},[37,2781,2782,2787],{},[52,2783,2784],{},[18,2785,2786],{},"eventShape",[52,2788,2789,2790,2793,2794,2796,2797,2800],{},"Whether the validator checks the whole event (",[18,2791,2792],{},"'event'",") or its ",[18,2795,64],{}," (",[18,2798,2799],{},"'data'",").",[37,2802,2803,2808],{},[52,2804,2805],{},[18,2806,2807],{},"rawData",[52,2809,2810,2811,2813,2814,2816,2817,2819],{},"Keeps ",[18,2812,64],{}," as text, for every event or for a list of event names. Kubb sets it when the document types ",[18,2815,64],{}," as a string. Otherwise ",[18,2818,64],{}," is parsed as JSON when it parses.",[2651,2821,1464],{"id":2822},"event-names-ids-and-json-lines",[11,2824,2825],{},"When the server leaves a field out of an event, or sends JSON Lines:",[1542,2827,2828,2834,2843,2849],{},[1545,2829,2830,2831,2833],{},"An event takes ",[18,2832,1362],{}," as its name when the server sends none.",[1545,2835,2836,2837,2839,2840,2842],{},"The ",[18,2838,318],{}," carries over to later events, and ",[18,2841,337],{}," holds the server's reconnect hint.",[1545,2844,2845,2846,2848],{},"A JSON Lines stream has no event IDs, and ",[18,2847,955],{}," does not apply to it.",[1545,2850,986,2851,2853],{},[18,2852,106],{}," record must fit on one line.",[2651,2855,2031],{"id":2856},"event-ids-when-you-resume",[11,2858,2859,2860,165],{},"When you ",[124,2861,2863],{"href":2862},"#stop-abort-and-resume","resume a stream",[1542,2865,2866,2872,2884,2893],{},[1545,2867,2868,2869,2871],{},"The runtime reconnects only when ",[18,2870,337],{}," is set, because many streams end on purpose.",[1545,2873,2874,2876,2877,2879,2880,2883],{},[18,2875,905],{}," is empty until the server sends an ",[18,2878,318],{},", and an empty ",[18,2881,2882],{},"id:"," clears it.",[1545,2885,2886,2887,2889,2890,2892],{},"The resume loop copies ",[18,2888,905],{}," after each event, so after a clear it sends no ",[18,2891,1574],{},". A connection that drops before its first event keeps the ID from the connection before.",[1545,2894,119,2895,2897,2898,2900,2901,2903],{},[18,2896,914],{},", the items alone carry no ",[18,2899,905],{},", so pass ",[18,2902,1578],{}," to get the full result.",[2651,2905,2907],{"id":2906},"interceptors-on-a-stream-call","Interceptors on a stream call",[11,2909,2910,2911,2913,2914,2917,2918,128],{},"When a response interceptor runs on a stream call, ",[18,2912,64],{}," in its ",[18,2915,2916],{},"DecodedResponse"," is the raw body stream. See ",[124,2919,2921],{"href":2920},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fconfigure-requests#add-interceptors","Add interceptors",[2651,2923,2925],{"id":2924},"stream-runtime-files","Stream runtime files",[11,2927,2928,2929,165],{},"When you look for a stream helper or type, import it from ",[18,2930,2640],{},[1542,2932,2933,2948],{},[1545,2934,2935,2937,2938,100,2940,2943,2944,2947],{},[18,2936,20],{}," holds ",[18,2939,2300],{},[18,2941,2942],{},"parseJsonLines",", and the stream media types, and ",[18,2945,2946],{},".kubb\u002Fclient.ts"," re-exports it.",[1545,2949,2950,2951,100,2953,100,2955,2957,2958,2960,2961,128],{},"The stream types, such as ",[18,2952,2625],{},[18,2954,876],{},[18,2956,828],{},", and ",[18,2959,862],{},", live in ",[18,2962,2963],{},".kubb\u002Fcore.ts",{"title":2965,"searchDepth":2966,"depth":2966,"links":2967},"",5,[2968,2970,2971,2972,2973,2974,2975,2976],{"id":25,"depth":2969,"text":26},2,{"id":772,"depth":2969,"text":773},{"id":993,"depth":2969,"text":994},{"id":1539,"depth":2969,"text":1540},{"id":2034,"depth":2969,"text":2035},{"id":2272,"depth":2969,"text":127},{"id":2443,"depth":2969,"text":2444},{"id":2648,"depth":2969,"text":2649,"children":2977},[2978,2981,2982,2983,2984,2985,2986],{"id":2653,"depth":2979,"text":2980},3,"JSON in a data string",{"id":2677,"depth":2979,"text":2678},{"id":2757,"depth":2979,"text":2758},{"id":2822,"depth":2979,"text":1464},{"id":2856,"depth":2979,"text":2031},{"id":2906,"depth":2979,"text":2907},{"id":2924,"depth":2979,"text":2925},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserver-sent-events",1795727685778,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]