[{"data":1,"prerenderedAt":2888},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserver-sent-events":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":2887,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserver-sent-events.md",{},"Server-sent events",{"type":8,"value":9,"toc":2864},"minimark",[10,14,22,27,30,117,129,140,750,770,774,889,916,919,991,995,1446,1465,1481,1537,1541,1559,1578,1908,1923,1933,1937,2051,2162,2172,2175,2208,2343,2347,2364,2505,2522,2537,2548,2552,2560,2577,2581,2587,2652,2658,2662,2671,2723,2726,2729,2757,2760,2767,2804,2808,2822,2826,2831],[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],{},"A dropped connection ends the loop with the transport's error. The runtime does not reconnect, so the retry policy is up to your app.",[11,1560,1561,1562,1565,1566,1568,1569,1571,1572,1574,1575,165],{},"To resume, send a new call with a ",[18,1563,1564],{},"Last-Event-ID"," header. ",[18,1567,905],{}," is the ",[18,1570,318],{}," of the last event the server completed. Declare ",[18,1573,1564],{}," as a header parameter, so the call accepts it in ",[18,1576,1577],{},"headers",[144,1579,1581],{"language":776,"code":1580,"class":149},"import { ResponseError } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport { ParseError } 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 ParseError) throw error\n    }\n  }\n}\n\nfor await (const event of resumeChat()) render(event)",[18,1582,1583,166,1599,166,1615,166,1617,166,1643,166,1658,166,1660,166,1690,166,1700,166,1746,166,1765,166,1779,166,1788,166,1794,166,1801,166,1816,166,1867,166,1873,166,1878,166,1882,166,1884],{"class":780},[154,1584,1585,1587,1589,1592,1594,1596],{"class":156,"style":157},[154,1586,1006],{"style":164},[154,1588,301],{"style":160},[154,1590,1591],{"style":791},"ResponseError ",[154,1593,632],{"style":160},[154,1595,1016],{"style":164},[154,1597,1598],{"style":190},"'.\u002Fgen\u002F.kubb\u002Fclient'",[154,1600,1601,1603,1605,1608,1610,1612],{"class":156,"style":157},[154,1602,1006],{"style":164},[154,1604,301],{"style":160},[154,1606,1607],{"style":791},"ParseError ",[154,1609,632],{"style":160},[154,1611,1016],{"style":164},[154,1613,1614],{"style":190},"'.\u002Fgen\u002F.kubb\u002FstandardSchema'",[154,1616],{"class":156,"style":157},[154,1618,1619,1622,1625,1628,1631,1633,1636,1638,1641],{"class":156,"style":157},[154,1620,1621],{"style":164},"async ",[154,1623,1624],{"style":164},"function",[154,1626,1627],{"style":164},"* ",[154,1629,1630],{"style":791},"resumeChat",[154,1632,815],{"style":160},[154,1634,1635],{"style":822},"attempts ",[154,1637,806],{"style":164},[154,1639,1640],{"style":160},"3",[154,1642,1092],{"style":160},[154,1644,1645,1647,1650,1653,1655],{"class":156,"style":157},[154,1646,171],{"style":160},[154,1648,1649],{"style":164},"let ",[154,1651,1652],{"style":822},"lastEventId ",[154,1654,806],{"style":164},[154,1656,1657],{"style":190},"''",[154,1659],{"class":156,"style":157},[154,1661,1662,1664,1667,1669,1671,1674,1676,1679,1682,1685,1688],{"class":156,"style":157},[154,1663,171],{"style":190},[154,1665,1666],{"style":164},"for ",[154,1668,815],{"style":160},[154,1670,1649],{"style":164},[154,1672,1673],{"style":822},"attempt ",[154,1675,806],{"style":164},[154,1677,1678],{"style":160},"1",[154,1680,1681],{"style":164},"; ; ",[154,1683,1684],{"style":822},"attempt",[154,1686,1687],{"style":164},"++",[154,1689,1092],{"style":160},[154,1691,1692,1694,1697],{"class":156,"style":157},[154,1693,181],{"style":160},[154,1695,1696],{"style":164},"try ",[154,1698,1699],{"style":160},"{",[154,1701,1702,1704,1706,1709,1711,1713,1715,1717,1719,1721,1723,1725,1727,1730,1732,1735,1737,1739,1741,1743],{"class":156,"style":157},[154,1703,205],{"style":160},[154,1705,1031],{"style":164},[154,1707,1708],{"style":822},"result ",[154,1710,806],{"style":164},[154,1712,1040],{"style":164},[154,1714,191],{"style":791},[154,1716,1045],{"style":160},[154,1718,1048],{"style":822},[154,1720,100],{"style":164},[154,1722,1577],{"style":160},[154,1724,187],{"style":164},[154,1726,1652],{"style":822},[154,1728,1729],{"style":164},"? ",[154,1731,301],{"style":160},[154,1733,1734],{"style":190},"'Last-Event-ID'",[154,1736,187],{"style":164},[154,1738,1652],{"style":822},[154,1740,632],{"style":160},[154,1742,187],{"style":164},[154,1744,1745],{"style":160},"{} })",[154,1747,1748,1750,1752,1754,1756,1758,1760,1763],{"class":156,"style":157},[154,1749,205],{"style":160},[154,1751,1026],{"style":164},[154,1753,815],{"style":160},[154,1755,1031],{"style":164},[154,1757,1034],{"style":822},[154,1759,1037],{"style":164},[154,1761,1762],{"style":822},"result",[154,1764,1092],{"style":160},[154,1766,1767,1769,1771,1773,1775,1777],{"class":156,"style":157},[154,1768,215],{"style":160},[154,1770,1652],{"style":822},[154,1772,806],{"style":164},[154,1774,1762],{"style":822},[154,1776,128],{"style":164},[154,1778,905],{"style":160},[154,1780,1781,1783,1786],{"class":156,"style":157},[154,1782,215],{"style":160},[154,1784,1785],{"style":164},"yield ",[154,1787,60],{"style":822},[154,1789,1790,1792],{"class":156,"style":157},[154,1791,205],{"style":822},[154,1793,311],{"style":160},[154,1795,1796,1798],{"class":156,"style":157},[154,1797,205],{"style":160},[154,1799,1800],{"style":164},"return",[154,1802,1803,1805,1807,1810,1812,1814],{"class":156,"style":157},[154,1804,181],{"style":164},[154,1806,632],{"style":160},[154,1808,1809],{"style":164},"catch ",[154,1811,815],{"style":160},[154,1813,1459],{"style":822},[154,1815,1092],{"style":160},[154,1817,1818,1820,1823,1825,1827,1830,1832,1835,1838,1840,1843,1845,1847,1849,1851,1854,1857,1860,1862,1865],{"class":156,"style":157},[154,1819,205],{"style":160},[154,1821,1822],{"style":164},"if ",[154,1824,815],{"style":160},[154,1826,1673],{"style":822},[154,1828,1829],{"style":164},"=== ",[154,1831,1635],{"style":822},[154,1833,1834],{"style":164},"|| ",[154,1836,1837],{"style":791},"ResponseError",[154,1839,128],{"style":164},[154,1841,1842],{"style":791},"is",[154,1844,815],{"style":160},[154,1846,1459],{"style":822},[154,1848,1127],{"style":160},[154,1850,1834],{"style":164},[154,1852,1853],{"style":822},"error ",[154,1855,1856],{"style":164},"instanceof ",[154,1858,1859],{"style":791},"ParseError",[154,1861,1127],{"style":160},[154,1863,1864],{"style":164},"throw ",[154,1866,1459],{"style":822},[154,1868,1869,1871],{"class":156,"style":157},[154,1870,181],{"style":822},[154,1872,311],{"style":160},[154,1874,1875],{"class":156,"style":157},[154,1876,1877],{"style":160},"  }",[154,1879,1880],{"class":156,"style":157},[154,1881,311],{"style":160},[154,1883],{"class":156,"style":157},[154,1885,1886,1888,1890,1892,1894,1896,1898,1900,1902,1904,1906],{"class":156,"style":157},[154,1887,1026],{"style":164},[154,1889,815],{"style":160},[154,1891,1031],{"style":164},[154,1893,1034],{"style":822},[154,1895,1037],{"style":164},[154,1897,1630],{"style":791},[154,1899,1337],{"style":160},[154,1901,1111],{"style":791},[154,1903,815],{"style":160},[154,1905,60],{"style":822},[154,1907,852],{"style":160},[11,1909,1910,1911,1913,1914,1916,1917,1919,1920,1922],{},"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,1912,1837],{}," and a ",[18,1915,1859],{}," 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,1918,983],{},". An error from ",[18,1921,1111],{}," is thrown outside the generator, so it is never retried.",[11,1924,1925,1926,1928,1929,128],{},"For cleared IDs and resuming with ",[18,1927,914],{},", see ",[124,1930,1932],{"href":1931},"#event-ids-when-you-resume","Event IDs when you resume",[23,1934,1936],{"id":1935},"handle-errors","Handle errors",[31,1938,1939,1949],{},[34,1940,1941],{},[37,1942,1943,1946],{},[40,1944,1945],{},"What happens",[40,1947,1948],{},"Where it fails",[47,1950,1951,1961,1983,1997,2005,2013,2029,2041],{},[37,1952,1953,1956],{},[52,1954,1955],{},"Non-2xx response",[52,1957,1958,1959,128],{},"The call throws a ",[18,1960,1837],{},[37,1962,1963,1969],{},[52,1964,1965,1966],{},"Non-2xx response with ",[18,1967,1968],{},"throwOnError: false",[52,1970,1971,1972,902,1974,972,1976,1978,1979,1982],{},"The call resolves with ",[18,1973,1247],{},[18,1975,1459],{},[18,1977,64],{}," is ",[18,1980,1981],{},"undefined",", and the stream yields nothing.",[37,1984,1985,1988],{},[52,1986,1987],{},"2xx response whose body is not a stream, such as JSON",[52,1989,1958,1990,1993,1994,128],{},[18,1991,1992],{},"TypeError"," with the body as its ",[18,1995,1996],{},"cause",[37,1998,1999,2002],{},[52,2000,2001],{},"2xx response with an empty body",[52,2003,2004],{},"No error. The stream is empty.",[37,2006,2007,2010],{},[52,2008,2009],{},"Dropped connection or abort",[52,2011,2012],{},"The loop throws.",[37,2014,2015,2018],{},[52,2016,2017],{},"An item fails its schema",[52,2019,2020,2021,2023,2024,2026,2027,128],{},"The loop throws a ",[18,2022,1859],{},", unless ",[18,2025,1480],{}," returns ",[18,2028,1476],{},[37,2030,2031,2036],{},[52,2032,2033,2034],{},"An event is larger than ",[18,2035,965],{},[52,2037,2020,2038,128],{},[18,2039,2040],{},"RangeError",[37,2042,2043,2046],{},[52,2044,2045],{},"A JSON line is not valid JSON",[52,2047,2020,2048,128],{},[18,2049,2050],{},"SyntaxError",[144,2052,2054],{"language":776,"code":2053,"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,2055,2056,166,2085,166,2087,166,2133],{"class":780},[154,2057,2058,2060,2062,2064,2066,2068,2070,2072,2074,2077,2079,2082],{"class":156,"style":157},[154,2059,1031],{"style":164},[154,2061,1708],{"style":822},[154,2063,806],{"style":164},[154,2065,1040],{"style":164},[154,2067,191],{"style":791},[154,2069,1045],{"style":160},[154,2071,1048],{"style":822},[154,2073,100],{"style":164},[154,2075,2076],{"style":160},"throwOnError",[154,2078,187],{"style":164},[154,2080,2081],{"style":160},"false ",[154,2083,2084],{"style":160},"})",[154,2086],{"class":156,"style":157},[154,2088,2089,2091,2093,2096,2098,2100,2102,2104,2106,2108,2110,2112,2115,2117,2119,2121,2123,2125,2127,2129,2131],{"class":156,"style":157},[154,2090,1822],{"style":164},[154,2092,815],{"style":160},[154,2094,2095],{"style":164},"!",[154,2097,1762],{"style":822},[154,2099,128],{"style":164},[154,2101,64],{"style":160},[154,2103,1127],{"style":160},[154,2105,1232],{"style":822},[154,2107,128],{"style":164},[154,2109,1459],{"style":791},[154,2111,815],{"style":160},[154,2113,2114],{"style":190},"'stream rejected'",[154,2116,100],{"style":164},[154,2118,1762],{"style":822},[154,2120,128],{"style":164},[154,2122,1247],{"style":160},[154,2124,100],{"style":164},[154,2126,1762],{"style":822},[154,2128,128],{"style":164},[154,2130,1459],{"style":160},[154,2132,852],{"style":160},[154,2134,2135,2138,2140,2142,2144,2146,2148,2150,2152,2154,2156,2158,2160],{"class":156,"style":157},[154,2136,2137],{"style":164},"else for await ",[154,2139,815],{"style":160},[154,2141,1031],{"style":164},[154,2143,1034],{"style":822},[154,2145,1037],{"style":164},[154,2147,1762],{"style":822},[154,2149,128],{"style":164},[154,2151,64],{"style":160},[154,2153,1127],{"style":160},[154,2155,1111],{"style":791},[154,2157,815],{"style":160},[154,2159,60],{"style":822},[154,2161,852],{"style":160},[11,2163,2164,2165,972,2168,2171],{},"An error thrown from the loop skips ",[18,2166,2167],{},"client.interceptors.error",[18,2169,2170],{},".unwrap()"," resolves to the items, as on a regular call.",[23,2173,127],{"id":2174},"json-or-an-event-stream",[11,2176,2177,2178,2180,2181,2184,2185,2188,2189,2192,2193,2195,2196,2199,2200,2203,2204,2207],{},"When the success response declares ",[18,2179,56],{}," next to another type, such as ",[18,2182,2183],{},"application\u002Fjson",", Kubb generates a normal call that sends ",[18,2186,2187],{},"Accept: text\u002Fevent-stream",". Pass ",[18,2190,2191],{},"contentType: { response: 'application\u002Fjson' }"," to ask for JSON. When the server streams, ",[18,2194,64],{}," is the raw ",[18,2197,2198],{},"ReadableStream\u003CUint8Array>",", so read it with ",[18,2201,2202],{},"parseEventStream",", or ",[18,2205,2206],{},"parseJsonLines({ stream })"," for JSON Lines:",[144,2209,2211],{"language":776,"code":2210,"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,2212,2213,166,2228,166,2230,166,2250,166,2252,166,2272,166,2311,166,2320,166,2339],{"class":780},[154,2214,2215,2217,2219,2222,2224,2226],{"class":156,"style":157},[154,2216,1006],{"style":164},[154,2218,301],{"style":160},[154,2220,2221],{"style":822},"parseEventStream ",[154,2223,632],{"style":160},[154,2225,1016],{"style":164},[154,2227,1598],{"style":190},[154,2229],{"class":156,"style":157},[154,2231,2232,2234,2236,2238,2240,2243,2245,2248],{"class":156,"style":157},[154,2233,1031],{"style":164},[154,2235,1708],{"style":822},[154,2237,806],{"style":164},[154,2239,1040],{"style":164},[154,2241,2242],{"style":791},"getRecentChanges",[154,2244,1045],{"style":160},[154,2246,2247],{"style":822},"signal ",[154,2249,2084],{"style":160},[154,2251],{"class":156,"style":157},[154,2253,2254,2256,2258,2260,2262,2265,2267,2270],{"class":156,"style":157},[154,2255,1822],{"style":164},[154,2257,815],{"style":160},[154,2259,1762],{"style":822},[154,2261,128],{"style":164},[154,2263,2264],{"style":160},"contentType ",[154,2266,1829],{"style":164},[154,2268,2269],{"style":190},"'text\u002Fevent-stream'",[154,2271,1092],{"style":160},[154,2273,2274,2276,2278,2280,2282,2284,2286,2288,2290,2292,2294,2296,2298,2300,2303,2305,2307,2309],{"class":156,"style":157},[154,2275,171],{"style":160},[154,2277,1026],{"style":164},[154,2279,815],{"style":160},[154,2281,1031],{"style":164},[154,2283,301],{"style":160},[154,2285,1267],{"style":822},[154,2287,632],{"style":160},[154,2289,1037],{"style":164},[154,2291,2202],{"style":791},[154,2293,815],{"style":160},[154,2295,1762],{"style":822},[154,2297,128],{"style":164},[154,2299,64],{"style":160},[154,2301,2302],{"style":160},")) ",[154,2304,1111],{"style":791},[154,2306,815],{"style":160},[154,2308,64],{"style":822},[154,2310,852],{"style":160},[154,2312,2313,2315,2318],{"class":156,"style":157},[154,2314,632],{"style":160},[154,2316,2317],{"style":164},"else ",[154,2319,1699],{"style":160},[154,2321,2322,2324,2326,2328,2330,2332,2334,2336],{"class":156,"style":157},[154,2323,171],{"style":160},[154,2325,1111],{"style":791},[154,2327,815],{"style":160},[154,2329,1762],{"style":822},[154,2331,128],{"style":164},[154,2333,64],{"style":160},[154,2335,1127],{"style":160},[154,2337,2338],{"style":635},"\u002F\u002F the JSON body",[154,2340,2341],{"class":156,"style":157},[154,2342,311],{"style":160},[23,2344,2346],{"id":2345},"stream-with-the-client","Stream with the client",[11,2348,2349,2352,2353,2356,2357,2360,2361,2363],{},[18,2350,2351],{},"client.stream(config)"," sends a stream request by hand. It runs the same interceptors and transport as ",[18,2354,2355],{},"client(config)",", and validates each item with ",[18,2358,2359],{},"validator.response",". Type it with the responses record, ",[18,2362,838],{},", and the item type:",[144,2365,2367],{"language":776,"code":2366,"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,2368,2369,166,2392,166,2410,166,2412,166,2451,166,2465,166,2479,166,2501],{"class":780},[154,2370,2371,2373,2375,2378,2380,2383,2386,2388,2390],{"class":156,"style":157},[154,2372,1006],{"style":164},[154,2374,301],{"style":160},[154,2376,2377],{"style":822},"client",[154,2379,100],{"style":164},[154,2381,2382],{"style":164},"type ",[154,2384,2385],{"style":791},"SuccessOf ",[154,2387,632],{"style":160},[154,2389,1016],{"style":164},[154,2391,1598],{"style":190},[154,2393,2394,2396,2398,2400,2403,2405,2407],{"class":156,"style":157},[154,2395,1006],{"style":164},[154,2397,2382],{"style":822},[154,2399,301],{"style":160},[154,2401,2402],{"style":791},"StreamLogsResponses ",[154,2404,632],{"style":160},[154,2406,1016],{"style":164},[154,2408,2409],{"style":190},"'.\u002Fgen\u002Ftypes\u002FStreamLogs'",[154,2411],{"class":156,"style":157},[154,2413,2414,2416,2418,2420,2422,2424,2426,2428,2430,2433,2435,2437,2439,2441,2443,2445,2448],{"class":156,"style":157},[154,2415,1031],{"style":164},[154,2417,1708],{"style":822},[154,2419,806],{"style":164},[154,2421,1040],{"style":164},[154,2423,2377],{"style":822},[154,2425,128],{"style":164},[154,2427,901],{"style":160},[154,2429,794],{"style":164},[154,2431,2432],{"style":791},"StreamLogsResponses",[154,2434,100],{"style":164},[154,2436,809],{"style":160},[154,2438,100],{"style":164},[154,2440,881],{"style":791},[154,2442,794],{"style":164},[154,2444,2432],{"style":791},[154,2446,2447],{"style":164},">>",[154,2449,2450],{"style":160},"({",[154,2452,2453,2455,2458,2460,2463],{"class":156,"style":157},[154,2454,171],{"style":160},[154,2456,2457],{"style":160},"method",[154,2459,187],{"style":164},[154,2461,2462],{"style":190},"'GET'",[154,2464,847],{"style":164},[154,2466,2467,2469,2472,2474,2477],{"class":156,"style":157},[154,2468,171],{"style":164},[154,2470,2471],{"style":160},"url",[154,2473,187],{"style":164},[154,2475,2476],{"style":190},"'\u002Flogs'",[154,2478,847],{"style":164},[154,2480,2481,2483,2486,2488,2490,2492,2494,2497,2499],{"class":156,"style":157},[154,2482,171],{"style":164},[154,2484,2485],{"style":160},"contentType",[154,2487,187],{"style":164},[154,2489,301],{"style":160},[154,2491,1242],{"style":160},[154,2493,187],{"style":164},[154,2495,2496],{"style":190},"'application\u002Fjsonl' ",[154,2498,311],{"style":160},[154,2500,847],{"style":164},[154,2502,2503],{"class":156,"style":157},[154,2504,2084],{"style":160},[11,2506,2507,2508,2511,2512,2515,2516,2519,2520,128],{},"Without ",[18,2509,2510],{},"contentType.response"," or an ",[18,2513,2514],{},"Accept"," header, ",[18,2517,2518],{},"client.stream"," sends ",[18,2521,2187],{},[11,2523,2524,2525,2528,2529,2531,2532,2536],{},"The item type defaults to ",[18,2526,2527],{},"ServerSentEvent"," around the success body. To stream another format, register a ",[18,2530,901],{}," handler, as ",[124,2533,2535],{"href":2534},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserialization#add-a-media-type","Add a media type"," shows.",[11,2538,2539,2540,2543,2544,2547],{},"Import the stream helpers and types from ",[18,2541,2542],{},".kubb\u002Fclient",", and do not edit the ",[18,2545,2546],{},".kubb\u002F"," files: Kubb rewrites them on each run.",[23,2549,2551],{"id":2550},"less-common-cases","Less common cases",[2553,2554,2556,2557,2559],"h3",{"id":2555},"json-in-a-data-string","JSON in a ",[18,2558,64],{}," string",[11,2561,2562,2563,2565,2566,1913,2569,2572,2573,2576],{},"When an event's ",[18,2564,64],{}," is a string with ",[18,2567,2568],{},"contentMediaType: application\u002Fjson",[18,2570,2571],{},"contentSchema",", Kubb types and parses it as that schema. See ",[124,2574,26],{"href":2575},"#how-kubb-detects-a-stream"," for the item schemas.",[2553,2578,2580],{"id":2579},"stream-result-types","Stream result types",[11,2582,2583,2584,165],{},"When you type a variable that holds a stream result, the type depends on the response and on ",[18,2585,2586],{},"returnType",[31,2588,2589,2599],{},[34,2590,2591],{},[37,2592,2593,2596],{},[40,2594,2595],{},"Setting",[40,2597,2598],{},"The call returns",[47,2600,2601,2611,2626,2640],{},[37,2602,2603,2606],{},[52,2604,2605],{},"Default",[52,2607,2608],{},[18,2609,2610],{},"Unwrappable\u003CStreamResult\u003C…>>",[37,2612,2613,2616],{},[52,2614,2615],{},"The response declares headers",[52,2617,2618,2621,2622,2625],{},[18,2619,2620],{},"Unwrappable\u003CStreamResultWithHeaders\u003C…>>",", so ",[18,2623,2624],{},"headers.get"," suggests their names",[37,2627,2628,2632],{},[52,2629,2630],{},[18,2631,914],{},[52,2633,2634,2637,2638],{},[18,2635,2636],{},"Promise\u003CUnwrappedStreamResult\u003C…>>",": the items, or the full result with ",[18,2639,1968],{},[37,2641,2642,2647],{},[52,2643,2644,2646],{},[18,2645,914],{},", and the response declares headers",[52,2648,2649],{},[18,2650,2651],{},"Promise\u003CUnwrappedStreamResultWithHeaders\u003C…>>",[11,2653,2654,2657],{},[124,2655,773],{"href":2656},"#the-generated-function"," shows the default signature.",[2553,2659,2661],{"id":2660},"stream-options-kubb-sets","Stream options Kubb sets",[11,2663,2664,2665,2670],{},"When you call ",[124,2666,2668],{"href":2667},"#stream-with-the-client",[18,2669,2518],{}," yourself, pass the options a generated stream call gets from the document:",[31,2672,2673,2681],{},[34,2674,2675],{},[37,2676,2677,2679],{},[40,2678,927],{},[40,2680,930],{},[47,2682,2683,2704],{},[37,2684,2685,2690],{},[52,2686,2687],{},[18,2688,2689],{},"eventShape",[52,2691,2692,2693,2696,2697,2699,2700,2703],{},"Whether the validator checks the whole event (",[18,2694,2695],{},"'event'",") or its ",[18,2698,64],{}," (",[18,2701,2702],{},"'data'",").",[37,2705,2706,2711],{},[52,2707,2708],{},[18,2709,2710],{},"rawData",[52,2712,2713,2714,2716,2717,2719,2720,2722],{},"Keeps ",[18,2715,64],{}," as text, for every event or for a list of event names. Kubb sets it when the document types ",[18,2718,64],{}," as a string. Otherwise ",[18,2721,64],{}," is parsed as JSON when it parses.",[2553,2724,1464],{"id":2725},"event-names-ids-and-json-lines",[11,2727,2728],{},"When the server leaves a field out of an event, or sends JSON Lines:",[1542,2730,2731,2737,2746,2752],{},[1545,2732,2733,2734,2736],{},"An event takes ",[18,2735,1362],{}," as its name when the server sends none.",[1545,2738,2739,2740,2742,2743,2745],{},"The ",[18,2741,318],{}," carries over to later events, and ",[18,2744,337],{}," holds the server's reconnect hint.",[1545,2747,2748,2749,2751],{},"A JSON Lines stream has no event IDs, and ",[18,2750,955],{}," does not apply to it.",[1545,2753,986,2754,2756],{},[18,2755,106],{}," record must fit on one line.",[2553,2758,1932],{"id":2759},"event-ids-when-you-resume",[11,2761,2762,2763,165],{},"When you ",[124,2764,2766],{"href":2765},"#stop-abort-and-resume","resume a stream",[1542,2768,2769,2772,2784,2793],{},[1545,2770,2771],{},"The runtime does not reconnect, because many streams end on purpose and the retry policy belongs to your app.",[1545,2773,2774,2776,2777,2779,2780,2783],{},[18,2775,905],{}," is empty until the server sends an ",[18,2778,318],{},", and an empty ",[18,2781,2782],{},"id:"," clears it.",[1545,2785,2786,2787,2789,2790,2792],{},"The resume loop copies ",[18,2788,905],{}," after each event, so after a clear it sends no ",[18,2791,1564],{},". A connection that drops before its first event keeps the ID from the connection before.",[1545,2794,119,2795,2797,2798,2800,2801,2803],{},[18,2796,914],{},", the items alone carry no ",[18,2799,905],{},", so pass ",[18,2802,1968],{}," to get the full result.",[2553,2805,2807],{"id":2806},"interceptors-on-a-stream-call","Interceptors on a stream call",[11,2809,2810,2811,2813,2814,2817,2818,128],{},"When a response interceptor runs on a stream call, ",[18,2812,64],{}," in its ",[18,2815,2816],{},"DecodedResponse"," is the raw body stream. See ",[124,2819,2821],{"href":2820},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fconfigure-requests#add-interceptors","Add interceptors",[2553,2823,2825],{"id":2824},"stream-runtime-files","Stream runtime files",[11,2827,2828,2829,165],{},"When you look for a stream helper or type, import it from ",[18,2830,2542],{},[1542,2832,2833,2848],{},[1545,2834,2835,2837,2838,100,2840,2843,2844,2847],{},[18,2836,20],{}," holds ",[18,2839,2202],{},[18,2841,2842],{},"parseJsonLines",", and the stream media types, and ",[18,2845,2846],{},".kubb\u002Fclient.ts"," re-exports it.",[1545,2849,2850,2851,100,2853,100,2855,2857,2858,2860,2861,128],{},"The stream types, such as ",[18,2852,2527],{},[18,2854,876],{},[18,2856,828],{},", and ",[18,2859,862],{},", live in ",[18,2862,2863],{},".kubb\u002Fcore.ts",{"title":2865,"searchDepth":2866,"depth":2866,"links":2867},"",5,[2868,2870,2871,2872,2873,2874,2875,2876],{"id":25,"depth":2869,"text":26},2,{"id":772,"depth":2869,"text":773},{"id":993,"depth":2869,"text":994},{"id":1539,"depth":2869,"text":1540},{"id":1935,"depth":2869,"text":1936},{"id":2174,"depth":2869,"text":127},{"id":2345,"depth":2869,"text":2346},{"id":2550,"depth":2869,"text":2551,"children":2877},[2878,2881,2882,2883,2884,2885,2886],{"id":2555,"depth":2879,"text":2880},3,"JSON in a data string",{"id":2579,"depth":2879,"text":2580},{"id":2660,"depth":2879,"text":2661},{"id":2725,"depth":2879,"text":1464},{"id":2759,"depth":2879,"text":1932},{"id":2806,"depth":2879,"text":2807},{"id":2824,"depth":2879,"text":2825},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-ky\u002Fguides\u002Fserver-sent-events",1795015653968]