@langchain/google-common 0.2.17 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +6 -6
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/auth.cjs +82 -116
  5. package/dist/auth.cjs.map +1 -0
  6. package/dist/auth.d.cts +46 -0
  7. package/dist/auth.d.cts.map +1 -0
  8. package/dist/auth.d.ts +41 -36
  9. package/dist/auth.d.ts.map +1 -0
  10. package/dist/auth.js +80 -110
  11. package/dist/auth.js.map +1 -0
  12. package/dist/chat_models.cjs +251 -466
  13. package/dist/chat_models.cjs.map +1 -0
  14. package/dist/chat_models.d.cts +98 -0
  15. package/dist/chat_models.d.cts.map +1 -0
  16. package/dist/chat_models.d.ts +87 -73
  17. package/dist/chat_models.d.ts.map +1 -0
  18. package/dist/chat_models.js +245 -457
  19. package/dist/chat_models.js.map +1 -0
  20. package/dist/connection.cjs +321 -466
  21. package/dist/connection.cjs.map +1 -0
  22. package/dist/connection.d.cts +109 -0
  23. package/dist/connection.d.cts.map +1 -0
  24. package/dist/connection.d.ts +98 -91
  25. package/dist/connection.d.ts.map +1 -0
  26. package/dist/connection.js +317 -459
  27. package/dist/connection.js.map +1 -0
  28. package/dist/embeddings.cjs +135 -186
  29. package/dist/embeddings.cjs.map +1 -0
  30. package/dist/embeddings.d.cts +44 -0
  31. package/dist/embeddings.d.cts.map +1 -0
  32. package/dist/embeddings.d.ts +38 -32
  33. package/dist/embeddings.d.ts.map +1 -0
  34. package/dist/embeddings.js +133 -181
  35. package/dist/embeddings.js.map +1 -0
  36. package/dist/experimental/media.cjs +380 -482
  37. package/dist/experimental/media.cjs.map +1 -0
  38. package/dist/experimental/media.d.cts +198 -0
  39. package/dist/experimental/media.d.cts.map +1 -0
  40. package/dist/experimental/media.d.ts +190 -202
  41. package/dist/experimental/media.d.ts.map +1 -0
  42. package/dist/experimental/media.js +369 -468
  43. package/dist/experimental/media.js.map +1 -0
  44. package/dist/experimental/utils/media_core.cjs +403 -517
  45. package/dist/experimental/utils/media_core.cjs.map +1 -0
  46. package/dist/experimental/utils/media_core.d.cts +215 -0
  47. package/dist/experimental/utils/media_core.d.cts.map +1 -0
  48. package/dist/experimental/utils/media_core.d.ts +171 -165
  49. package/dist/experimental/utils/media_core.d.ts.map +1 -0
  50. package/dist/experimental/utils/media_core.js +395 -506
  51. package/dist/experimental/utils/media_core.js.map +1 -0
  52. package/dist/index.cjs +58 -27
  53. package/dist/index.d.cts +13 -0
  54. package/dist/index.d.ts +13 -11
  55. package/dist/index.js +13 -11
  56. package/dist/llms.cjs +157 -244
  57. package/dist/llms.cjs.map +1 -0
  58. package/dist/llms.d.cts +72 -0
  59. package/dist/llms.d.cts.map +1 -0
  60. package/dist/llms.d.ts +64 -54
  61. package/dist/llms.d.ts.map +1 -0
  62. package/dist/llms.js +154 -238
  63. package/dist/llms.js.map +1 -0
  64. package/dist/output_parsers.cjs +148 -173
  65. package/dist/output_parsers.cjs.map +1 -0
  66. package/dist/output_parsers.d.cts +53 -0
  67. package/dist/output_parsers.d.cts.map +1 -0
  68. package/dist/output_parsers.d.ts +46 -42
  69. package/dist/output_parsers.d.ts.map +1 -0
  70. package/dist/output_parsers.js +146 -168
  71. package/dist/output_parsers.js.map +1 -0
  72. package/dist/types-anthropic.d.cts +229 -0
  73. package/dist/types-anthropic.d.cts.map +1 -0
  74. package/dist/types-anthropic.d.ts +221 -215
  75. package/dist/types-anthropic.d.ts.map +1 -0
  76. package/dist/types.cjs +51 -62
  77. package/dist/types.cjs.map +1 -0
  78. package/dist/types.d.cts +748 -0
  79. package/dist/types.d.cts.map +1 -0
  80. package/dist/types.d.ts +669 -656
  81. package/dist/types.d.ts.map +1 -0
  82. package/dist/types.js +46 -45
  83. package/dist/types.js.map +1 -0
  84. package/dist/utils/anthropic.cjs +598 -821
  85. package/dist/utils/anthropic.cjs.map +1 -0
  86. package/dist/utils/anthropic.js +597 -818
  87. package/dist/utils/anthropic.js.map +1 -0
  88. package/dist/utils/common.cjs +130 -211
  89. package/dist/utils/common.cjs.map +1 -0
  90. package/dist/utils/common.d.cts +13 -0
  91. package/dist/utils/common.d.cts.map +1 -0
  92. package/dist/utils/common.d.ts +12 -7
  93. package/dist/utils/common.d.ts.map +1 -0
  94. package/dist/utils/common.js +128 -207
  95. package/dist/utils/common.js.map +1 -0
  96. package/dist/utils/failed_handler.cjs +28 -30
  97. package/dist/utils/failed_handler.cjs.map +1 -0
  98. package/dist/utils/failed_handler.d.cts +9 -0
  99. package/dist/utils/failed_handler.d.cts.map +1 -0
  100. package/dist/utils/failed_handler.d.ts +8 -2
  101. package/dist/utils/failed_handler.d.ts.map +1 -0
  102. package/dist/utils/failed_handler.js +28 -28
  103. package/dist/utils/failed_handler.js.map +1 -0
  104. package/dist/utils/gemini.cjs +1020 -1488
  105. package/dist/utils/gemini.cjs.map +1 -0
  106. package/dist/utils/gemini.d.cts +51 -0
  107. package/dist/utils/gemini.d.cts.map +1 -0
  108. package/dist/utils/gemini.d.ts +51 -48
  109. package/dist/utils/gemini.d.ts.map +1 -0
  110. package/dist/utils/gemini.js +1015 -1479
  111. package/dist/utils/gemini.js.map +1 -0
  112. package/dist/utils/index.cjs +38 -23
  113. package/dist/utils/index.d.cts +8 -0
  114. package/dist/utils/index.d.ts +8 -7
  115. package/dist/utils/index.js +8 -7
  116. package/dist/utils/palm.d.cts +11 -0
  117. package/dist/utils/palm.d.cts.map +1 -0
  118. package/dist/utils/palm.d.ts +9 -4
  119. package/dist/utils/palm.d.ts.map +1 -0
  120. package/dist/utils/safety.cjs +13 -22
  121. package/dist/utils/safety.cjs.map +1 -0
  122. package/dist/utils/safety.d.cts +12 -0
  123. package/dist/utils/safety.d.cts.map +1 -0
  124. package/dist/utils/safety.d.ts +10 -4
  125. package/dist/utils/safety.d.ts.map +1 -0
  126. package/dist/utils/safety.js +13 -19
  127. package/dist/utils/safety.js.map +1 -0
  128. package/dist/utils/stream.cjs +296 -475
  129. package/dist/utils/stream.cjs.map +1 -0
  130. package/dist/utils/stream.d.cts +165 -0
  131. package/dist/utils/stream.d.cts.map +1 -0
  132. package/dist/utils/stream.d.ts +156 -131
  133. package/dist/utils/stream.d.ts.map +1 -0
  134. package/dist/utils/stream.js +293 -469
  135. package/dist/utils/stream.js.map +1 -0
  136. package/dist/utils/zod_to_gemini_parameters.cjs +43 -81
  137. package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -0
  138. package/dist/utils/zod_to_gemini_parameters.d.cts +22 -0
  139. package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -0
  140. package/dist/utils/zod_to_gemini_parameters.d.ts +21 -6
  141. package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -0
  142. package/dist/utils/zod_to_gemini_parameters.js +40 -76
  143. package/dist/utils/zod_to_gemini_parameters.js.map +1 -0
  144. package/package.json +69 -85
  145. package/dist/types-anthropic.cjs +0 -2
  146. package/dist/types-anthropic.js +0 -1
  147. package/dist/utils/anthropic.d.ts +0 -4
  148. package/dist/utils/palm.cjs +0 -2
  149. package/dist/utils/palm.js +0 -1
  150. package/experimental/media.cjs +0 -1
  151. package/experimental/media.d.cts +0 -1
  152. package/experimental/media.d.ts +0 -1
  153. package/experimental/media.js +0 -1
  154. package/experimental/utils/media_core.cjs +0 -1
  155. package/experimental/utils/media_core.d.cts +0 -1
  156. package/experimental/utils/media_core.d.ts +0 -1
  157. package/experimental/utils/media_core.js +0 -1
  158. package/index.cjs +0 -1
  159. package/index.d.cts +0 -1
  160. package/index.d.ts +0 -1
  161. package/index.js +0 -1
  162. package/types.cjs +0 -1
  163. package/types.d.cts +0 -1
  164. package/types.d.ts +0 -1
  165. package/types.js +0 -1
  166. package/utils.cjs +0 -1
  167. package/utils.d.cts +0 -1
  168. package/utils.d.ts +0 -1
  169. package/utils.js +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.cjs","names":["value: unknown","ret: Record<string, unknown>","v: Record<string, any>","val: unknown","data: string","start: string","ret: object | null","obj: unknown","chunk: any","baseStream: AbstractStream","body: ReadableStream | null","body: any","event: string | null","ret: Record<string, string>","jsonAttribute?: string"],"sources":["../../src/utils/stream.ts"],"sourcesContent":["import { GenerationChunk } from \"@langchain/core/outputs\";\n\nexport interface AbstractStream {\n /**\n * Add more text to the buffer\n * @param data\n */\n appendBuffer(data: string): void;\n\n /**\n * Indicate that there is no more text to be added to the buffer\n * (ie - our source material is done)\n */\n closeBuffer(): void;\n /**\n * Get the next chunk that is coming from the stream.\n * This chunk may be null, usually indicating the last chunk in the stream.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n\n /**\n * Is the stream done?\n * A stream is only done if all of the following are true:\n * - There is no more data to be added to the text buffer\n * - There is no more data in the text buffer\n * - There are no chunks that are waiting to be consumed\n */\n get streamDone(): boolean;\n}\n\nexport function complexValue(value: unknown): unknown {\n if (value === null || typeof value === \"undefined\") {\n // I dunno what to put here. An error, probably\n return undefined;\n } else if (typeof value === \"object\") {\n if (Array.isArray(value)) {\n return {\n list_val: value.map((avalue) => complexValue(avalue)),\n };\n } else {\n const ret: Record<string, unknown> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const v: Record<string, any> = value;\n Object.keys(v).forEach((key) => {\n ret[key] = complexValue(v[key]);\n });\n return { struct_val: ret };\n }\n } else if (typeof value === \"number\") {\n if (Number.isInteger(value)) {\n return { int_val: value };\n } else {\n return { float_val: value };\n }\n } else {\n return {\n string_val: [value],\n };\n }\n}\n\nexport function simpleValue(val: unknown): unknown {\n if (val && typeof val === \"object\" && !Array.isArray(val)) {\n // eslint-disable-next-line no-prototype-builtins\n if (val.hasOwnProperty(\"stringVal\")) {\n return (val as { stringVal: string[] }).stringVal[0];\n\n // eslint-disable-next-line no-prototype-builtins\n } else if (val.hasOwnProperty(\"boolVal\")) {\n return (val as { boolVal: boolean[] }).boolVal[0];\n\n // eslint-disable-next-line no-prototype-builtins\n } else if (val.hasOwnProperty(\"listVal\")) {\n const { listVal } = val as { listVal: unknown[] };\n return listVal.map((aval) => simpleValue(aval));\n\n // eslint-disable-next-line no-prototype-builtins\n } else if (val.hasOwnProperty(\"structVal\")) {\n const ret: Record<string, unknown> = {};\n const struct = (val as { structVal: Record<string, unknown> }).structVal;\n Object.keys(struct).forEach((key) => {\n ret[key] = simpleValue(struct[key]);\n });\n return ret;\n } else {\n const ret: Record<string, unknown> = {};\n const struct = val as Record<string, unknown>;\n Object.keys(struct).forEach((key) => {\n ret[key] = simpleValue(struct[key]);\n });\n return ret;\n }\n } else if (Array.isArray(val)) {\n return val.map((aval) => simpleValue(aval));\n } else {\n return val;\n }\n}\nexport class JsonStream implements AbstractStream {\n _buffer = \"\";\n\n _bufferOpen = true;\n\n _firstRun = true;\n\n /**\n * Add data to the buffer. This may cause chunks to be generated, if available.\n * @param data\n */\n appendBuffer(data: string): void {\n this._buffer += data;\n // Our first time, skip to the opening of the array\n if (this._firstRun) {\n this._skipTo(\"[\");\n this._firstRun = false;\n }\n\n this._parseBuffer();\n }\n\n /**\n * Indicate there is no more data that will be added to the text buffer.\n * This should be called when all the data has been read and added to indicate\n * that we should process everything remaining in the buffer.\n */\n closeBuffer(): void {\n this._bufferOpen = false;\n this._parseBuffer();\n }\n\n /**\n * Skip characters in the buffer till we get to the start of an object.\n * Then attempt to read a full object.\n * If we do read a full object, turn it into a chunk and send it to the chunk handler.\n * Repeat this for as much as we can.\n */\n _parseBuffer(): void {\n let obj = null;\n do {\n this._skipTo(\"{\");\n obj = this._getFullObject();\n if (obj !== null) {\n const chunk = this._simplifyObject(obj);\n this._handleChunk(chunk);\n }\n } while (obj !== null);\n\n if (!this._bufferOpen) {\n // No more data will be added, and we have parsed everything we could,\n // so everything else is garbage.\n this._handleChunk(null);\n this._buffer = \"\";\n }\n }\n\n /**\n * If the string is present, move the start of the buffer to the first occurrence\n * of that string. This is useful for skipping over elements or parts that we're not\n * really interested in parsing. (ie - the opening characters, comma separators, etc.)\n * @param start The string to start the buffer with\n */\n _skipTo(start: string): void {\n const index = this._buffer.indexOf(start);\n if (index > 0) {\n this._buffer = this._buffer.slice(index);\n }\n }\n\n /**\n * Given what is in the buffer, parse a single object out of it.\n * If a complete object isn't available, return null.\n * Assumes that we are at the start of an object to parse.\n */\n _getFullObject(): object | null {\n let ret: object | null = null;\n\n // Loop while we don't have something to return AND we have something in the buffer\n let index = 0;\n while (ret === null && this._buffer.length > index) {\n // Advance to the next close bracket after our current index\n index = this._buffer.indexOf(\"}\", index + 1);\n\n // If we don't find one, exit with null\n if (index === -1) {\n return null;\n }\n\n // If we have one, try to turn it into an object to return\n try {\n const objStr = this._buffer.substring(0, index + 1);\n ret = JSON.parse(objStr);\n\n // We only get here if it parsed it ok\n // If we did turn it into an object, remove it from the buffer\n this._buffer = this._buffer.slice(index + 1);\n } catch {\n // It didn't parse it correctly, so we swallow the exception and continue\n }\n }\n\n return ret;\n }\n\n _simplifyObject(obj: unknown): object {\n return obj as object;\n }\n\n // Set up a potential Promise that the handler can resolve.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkResolution: (chunk: any) => void;\n\n // If there is no Promise (it is null), the handler must add it to the queue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkPending: Promise<any> | null = null;\n\n // A queue that will collect chunks while there is no Promise\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkQueue: any[] = [];\n\n /**\n * Register that we have another chunk available for consumption.\n * If we are waiting for a chunk, resolve the promise waiting for it immediately.\n * If not, then add it to the queue.\n * @param chunk\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _handleChunk(chunk: any): void {\n if (this._chunkPending) {\n this._chunkResolution(chunk);\n this._chunkPending = null;\n } else {\n this._chunkQueue.push(chunk);\n }\n }\n\n /**\n * Get the next chunk that is coming from the stream.\n * This chunk may be null, usually indicating the last chunk in the stream.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async nextChunk(): Promise<any> {\n if (this._chunkQueue.length > 0) {\n // If there is data in the queue, return the next queue chunk\n return this._chunkQueue.shift() as GenerationChunk;\n } else {\n // Otherwise, set up a promise that handleChunk will cause to be resolved\n this._chunkPending = new Promise((resolve) => {\n this._chunkResolution = resolve;\n });\n return this._chunkPending;\n }\n }\n\n /**\n * Is the stream done?\n * A stream is only done if all of the following are true:\n * - There is no more data to be added to the text buffer\n * - There is no more data in the text buffer\n * - There are no chunks that are waiting to be consumed\n */\n get streamDone(): boolean {\n return (\n !this._bufferOpen &&\n this._buffer.length === 0 &&\n this._chunkQueue.length === 0 &&\n this._chunkPending === null\n );\n }\n}\n\nexport class ComplexJsonStream extends JsonStream {\n _simplifyObject(obj: unknown): object {\n return simpleValue(obj) as object;\n }\n}\n\nexport class ReadableAbstractStream implements AbstractStream {\n private baseStream: AbstractStream;\n\n decoder: TextDecoder;\n\n constructor(baseStream: AbstractStream, body: ReadableStream | null) {\n this.baseStream = baseStream;\n this.decoder = new TextDecoder(\"utf-8\");\n if (body) {\n // eslint-disable-next-line no-void\n void this.run(body);\n } else {\n console.error(\"Unexpected empty body while streaming\");\n }\n }\n\n appendBuffer(data: string): void {\n return this.baseStream.appendBuffer(data);\n }\n\n closeBuffer(): void {\n return this.baseStream.closeBuffer();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any> {\n return this.baseStream.nextChunk();\n }\n\n get streamDone(): boolean {\n return this.baseStream.streamDone;\n }\n\n // Should be a ReadableStream, but the Gaxios Readable stream isn't.\n // But both should support async iterators, so make sure of that.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async run(body: any) {\n if (typeof body[Symbol.asyncIterator] === \"function\") {\n for await (const value of body) {\n const svalue = this.decoder.decode(value, { stream: true });\n this.appendBuffer(svalue);\n }\n this.closeBuffer();\n } else {\n throw Error(\"Stream must implement async iterator.\");\n }\n }\n}\n\nexport class ReadableJsonStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null) {\n super(new JsonStream(), body);\n }\n}\n\nexport class SseStream implements AbstractStream {\n _buffer = \"\";\n\n _bufferOpen = true;\n\n appendBuffer(data: string): void {\n this._buffer += data;\n this._parseBuffer();\n }\n\n closeBuffer(): void {\n this._bufferOpen = false;\n this._parseBuffer();\n }\n\n /**\n * Attempt to load an entire event.\n * For each entire event we load,\n * send them to be handled.\n */\n _parseBuffer(): void {\n const events = this._buffer.split(/\\n\\n/);\n this._buffer = events.pop() ?? \"\";\n events.forEach((event) => this._handleEvent(event.trim()));\n\n if (!this._bufferOpen) {\n // No more data will be added, and we have parsed\n // everything. So dump the rest.\n this._handleEvent(null);\n this._buffer = \"\";\n }\n }\n\n /**\n * Given an event string, get all the fields\n * in the event. It is assumed there is one field\n * per line, but that field names can be duplicated,\n * indicating to append the new value to the previous value\n * @param event\n */\n _parseEvent(event: string | null): Record<string, string> | null {\n if (!event || event.trim() === \"\") {\n return null;\n }\n const ret: Record<string, string> = {};\n\n const lines = event.split(/\\n/);\n lines.forEach((line) => {\n const match = line.match(/^([^:]+): \\s*(.+)\\n*$/);\n if (match && match.length === 3) {\n const key = match[1];\n const val = match[2];\n const cur = ret[key] ?? \"\";\n ret[key] = `${cur}${val}`;\n }\n });\n\n return ret;\n }\n\n // Set up a potential Promise that the handler can resolve.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkResolution: (chunk: any) => void;\n\n // If there is no Promise (it is null), the handler must add it to the queue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkPending: Promise<any> | null = null;\n\n // A queue that will collect chunks while there is no Promise\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkQueue: any[] = [];\n\n _handleEvent(event: string | null): void {\n const chunk = this._parseEvent(event);\n if (this._chunkPending) {\n this._chunkResolution(chunk);\n this._chunkPending = null;\n } else {\n this._chunkQueue.push(chunk);\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async nextChunk(): Promise<any> {\n if (this._chunkQueue.length > 0) {\n // If there is data in the queue, return the next queue chunk\n return this._chunkQueue.shift() as Record<string, string>;\n } else {\n // Otherwise, set up a promise that handleChunk will cause to be resolved\n this._chunkPending = new Promise((resolve) => {\n this._chunkResolution = resolve;\n });\n return this._chunkPending;\n }\n }\n\n get streamDone(): boolean {\n return (\n !this._bufferOpen &&\n this._buffer.length === 0 &&\n this._chunkQueue.length === 0 &&\n this._chunkPending === null\n );\n }\n}\n\nexport class ReadableSseStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null) {\n super(new SseStream(), body);\n }\n}\n\nexport class SseJsonStream extends SseStream {\n _jsonAttribute: string = \"data\";\n\n constructor(jsonAttribute?: string) {\n super();\n this._jsonAttribute = jsonAttribute ?? this._jsonAttribute;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async nextChunk(): Promise<any> {\n const eventRecord = (await super.nextChunk()) as Record<string, string>;\n const json = eventRecord?.[this._jsonAttribute];\n if (!json) {\n return null;\n } else {\n return JSON.parse(json);\n }\n }\n}\n\nexport class ReadableSseJsonStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null) {\n super(new SseJsonStream(), body);\n }\n}\n"],"mappings":";;AA+BA,SAAgB,aAAaA,OAAyB;AACpD,KAAI,UAAU,QAAQ,OAAO,UAAU,YAErC,QAAO;UACE,OAAO,UAAU,SAC1B,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,EACL,UAAU,MAAM,IAAI,CAAC,WAAW,aAAa,OAAO,CAAC,CACtD;MACI;EACL,MAAMC,MAA+B,CAAE;EAEvC,MAAMC,IAAyB;EAC/B,OAAO,KAAK,EAAE,CAAC,QAAQ,CAAC,QAAQ;GAC9B,IAAI,OAAO,aAAa,EAAE,KAAK;EAChC,EAAC;AACF,SAAO,EAAE,YAAY,IAAK;CAC3B;UACQ,OAAO,UAAU,SAC1B,KAAI,OAAO,UAAU,MAAM,CACzB,QAAO,EAAE,SAAS,MAAO;KAEzB,QAAO,EAAE,WAAW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EAC9B,MAAM,cAAe,MAAM,MAAM,WAAW;EAC5C,MAAM,OAAO,cAAc,KAAK;AAChC,MAAI,CAAC,KACH,QAAO;MAEP,QAAO,KAAK,MAAM,KAAK;CAE1B;AACF;AAED,IAAa,wBAAb,cAA2C,uBAAuB;CAChE,YAAYJ,MAA6B;EACvC,MAAM,IAAI,iBAAiB,KAAK;CACjC;AACF"}
@@ -0,0 +1,165 @@
1
+ //#region src/utils/stream.d.ts
2
+ interface AbstractStream {
3
+ /**
4
+ * Add more text to the buffer
5
+ * @param data
6
+ */
7
+ appendBuffer(data: string): void;
8
+ /**
9
+ * Indicate that there is no more text to be added to the buffer
10
+ * (ie - our source material is done)
11
+ */
12
+ closeBuffer(): void;
13
+ /**
14
+ * Get the next chunk that is coming from the stream.
15
+ * This chunk may be null, usually indicating the last chunk in the stream.
16
+ */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ nextChunk(): Promise<any>;
19
+ /**
20
+ * Is the stream done?
21
+ * A stream is only done if all of the following are true:
22
+ * - There is no more data to be added to the text buffer
23
+ * - There is no more data in the text buffer
24
+ * - There are no chunks that are waiting to be consumed
25
+ */
26
+ get streamDone(): boolean;
27
+ }
28
+ declare function complexValue(value: unknown): unknown;
29
+ declare function simpleValue(val: unknown): unknown;
30
+ declare class JsonStream implements AbstractStream {
31
+ _buffer: string;
32
+ _bufferOpen: boolean;
33
+ _firstRun: boolean;
34
+ /**
35
+ * Add data to the buffer. This may cause chunks to be generated, if available.
36
+ * @param data
37
+ */
38
+ appendBuffer(data: string): void;
39
+ /**
40
+ * Indicate there is no more data that will be added to the text buffer.
41
+ * This should be called when all the data has been read and added to indicate
42
+ * that we should process everything remaining in the buffer.
43
+ */
44
+ closeBuffer(): void;
45
+ /**
46
+ * Skip characters in the buffer till we get to the start of an object.
47
+ * Then attempt to read a full object.
48
+ * If we do read a full object, turn it into a chunk and send it to the chunk handler.
49
+ * Repeat this for as much as we can.
50
+ */
51
+ _parseBuffer(): void;
52
+ /**
53
+ * If the string is present, move the start of the buffer to the first occurrence
54
+ * of that string. This is useful for skipping over elements or parts that we're not
55
+ * really interested in parsing. (ie - the opening characters, comma separators, etc.)
56
+ * @param start The string to start the buffer with
57
+ */
58
+ _skipTo(start: string): void;
59
+ /**
60
+ * Given what is in the buffer, parse a single object out of it.
61
+ * If a complete object isn't available, return null.
62
+ * Assumes that we are at the start of an object to parse.
63
+ */
64
+ _getFullObject(): object | null;
65
+ _simplifyObject(obj: unknown): object;
66
+ // Set up a potential Promise that the handler can resolve.
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ _chunkResolution: (chunk: any) => void;
69
+ // If there is no Promise (it is null), the handler must add it to the queue
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ _chunkPending: Promise<any> | null;
72
+ // A queue that will collect chunks while there is no Promise
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ _chunkQueue: any[];
75
+ /**
76
+ * Register that we have another chunk available for consumption.
77
+ * If we are waiting for a chunk, resolve the promise waiting for it immediately.
78
+ * If not, then add it to the queue.
79
+ * @param chunk
80
+ */
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ _handleChunk(chunk: any): void;
83
+ /**
84
+ * Get the next chunk that is coming from the stream.
85
+ * This chunk may be null, usually indicating the last chunk in the stream.
86
+ */
87
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
+ nextChunk(): Promise<any>;
89
+ /**
90
+ * Is the stream done?
91
+ * A stream is only done if all of the following are true:
92
+ * - There is no more data to be added to the text buffer
93
+ * - There is no more data in the text buffer
94
+ * - There are no chunks that are waiting to be consumed
95
+ */
96
+ get streamDone(): boolean;
97
+ }
98
+ declare class ComplexJsonStream extends JsonStream {
99
+ _simplifyObject(obj: unknown): object;
100
+ }
101
+ declare class ReadableAbstractStream implements AbstractStream {
102
+ private baseStream;
103
+ decoder: TextDecoder;
104
+ constructor(baseStream: AbstractStream, body: ReadableStream | null);
105
+ appendBuffer(data: string): void;
106
+ closeBuffer(): void;
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
+ nextChunk(): Promise<any>;
109
+ get streamDone(): boolean;
110
+ // Should be a ReadableStream, but the Gaxios Readable stream isn't.
111
+ // But both should support async iterators, so make sure of that.
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ run(body: any): Promise<void>;
114
+ }
115
+ declare class ReadableJsonStream extends ReadableAbstractStream {
116
+ constructor(body: ReadableStream | null);
117
+ }
118
+ declare class SseStream implements AbstractStream {
119
+ _buffer: string;
120
+ _bufferOpen: boolean;
121
+ appendBuffer(data: string): void;
122
+ closeBuffer(): void;
123
+ /**
124
+ * Attempt to load an entire event.
125
+ * For each entire event we load,
126
+ * send them to be handled.
127
+ */
128
+ _parseBuffer(): void;
129
+ /**
130
+ * Given an event string, get all the fields
131
+ * in the event. It is assumed there is one field
132
+ * per line, but that field names can be duplicated,
133
+ * indicating to append the new value to the previous value
134
+ * @param event
135
+ */
136
+ _parseEvent(event: string | null): Record<string, string> | null;
137
+ // Set up a potential Promise that the handler can resolve.
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ _chunkResolution: (chunk: any) => void;
140
+ // If there is no Promise (it is null), the handler must add it to the queue
141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+ _chunkPending: Promise<any> | null;
143
+ // A queue that will collect chunks while there is no Promise
144
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
+ _chunkQueue: any[];
146
+ _handleEvent(event: string | null): void;
147
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
+ nextChunk(): Promise<any>;
149
+ get streamDone(): boolean;
150
+ }
151
+ declare class ReadableSseStream extends ReadableAbstractStream {
152
+ constructor(body: ReadableStream | null);
153
+ }
154
+ declare class SseJsonStream extends SseStream {
155
+ _jsonAttribute: string;
156
+ constructor(jsonAttribute?: string);
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ nextChunk(): Promise<any>;
159
+ }
160
+ declare class ReadableSseJsonStream extends ReadableAbstractStream {
161
+ constructor(body: ReadableStream | null);
162
+ }
163
+ //#endregion
164
+ export { AbstractStream, ComplexJsonStream, JsonStream, ReadableAbstractStream, ReadableJsonStream, ReadableSseJsonStream, ReadableSseStream, SseJsonStream, SseStream, complexValue, simpleValue };
165
+ //# sourceMappingURL=stream.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.cts","names":["AbstractStream","Promise","complexValue","simpleValue","JsonStream","ComplexJsonStream","ReadableAbstractStream","TextDecoder","ReadableStream","ReadableJsonStream","SseStream","Record","ReadableSseStream","SseJsonStream","ReadableSseJsonStream"],"sources":["../../src/utils/stream.d.ts"],"sourcesContent":["export interface AbstractStream {\n /**\n * Add more text to the buffer\n * @param data\n */\n appendBuffer(data: string): void;\n /**\n * Indicate that there is no more text to be added to the buffer\n * (ie - our source material is done)\n */\n closeBuffer(): void;\n /**\n * Get the next chunk that is coming from the stream.\n * This chunk may be null, usually indicating the last chunk in the stream.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n /**\n * Is the stream done?\n * A stream is only done if all of the following are true:\n * - There is no more data to be added to the text buffer\n * - There is no more data in the text buffer\n * - There are no chunks that are waiting to be consumed\n */\n get streamDone(): boolean;\n}\nexport declare function complexValue(value: unknown): unknown;\nexport declare function simpleValue(val: unknown): unknown;\nexport declare class JsonStream implements AbstractStream {\n _buffer: string;\n _bufferOpen: boolean;\n _firstRun: boolean;\n /**\n * Add data to the buffer. This may cause chunks to be generated, if available.\n * @param data\n */\n appendBuffer(data: string): void;\n /**\n * Indicate there is no more data that will be added to the text buffer.\n * This should be called when all the data has been read and added to indicate\n * that we should process everything remaining in the buffer.\n */\n closeBuffer(): void;\n /**\n * Skip characters in the buffer till we get to the start of an object.\n * Then attempt to read a full object.\n * If we do read a full object, turn it into a chunk and send it to the chunk handler.\n * Repeat this for as much as we can.\n */\n _parseBuffer(): void;\n /**\n * If the string is present, move the start of the buffer to the first occurrence\n * of that string. This is useful for skipping over elements or parts that we're not\n * really interested in parsing. (ie - the opening characters, comma separators, etc.)\n * @param start The string to start the buffer with\n */\n _skipTo(start: string): void;\n /**\n * Given what is in the buffer, parse a single object out of it.\n * If a complete object isn't available, return null.\n * Assumes that we are at the start of an object to parse.\n */\n _getFullObject(): object | null;\n _simplifyObject(obj: unknown): object;\n // Set up a potential Promise that the handler can resolve.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkResolution: (chunk: any) => void;\n // If there is no Promise (it is null), the handler must add it to the queue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkPending: Promise<any> | null;\n // A queue that will collect chunks while there is no Promise\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkQueue: any[];\n /**\n * Register that we have another chunk available for consumption.\n * If we are waiting for a chunk, resolve the promise waiting for it immediately.\n * If not, then add it to the queue.\n * @param chunk\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _handleChunk(chunk: any): void;\n /**\n * Get the next chunk that is coming from the stream.\n * This chunk may be null, usually indicating the last chunk in the stream.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n /**\n * Is the stream done?\n * A stream is only done if all of the following are true:\n * - There is no more data to be added to the text buffer\n * - There is no more data in the text buffer\n * - There are no chunks that are waiting to be consumed\n */\n get streamDone(): boolean;\n}\nexport declare class ComplexJsonStream extends JsonStream {\n _simplifyObject(obj: unknown): object;\n}\nexport declare class ReadableAbstractStream implements AbstractStream {\n private baseStream;\n decoder: TextDecoder;\n constructor(baseStream: AbstractStream, body: ReadableStream | null);\n appendBuffer(data: string): void;\n closeBuffer(): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n get streamDone(): boolean;\n // Should be a ReadableStream, but the Gaxios Readable stream isn't.\n // But both should support async iterators, so make sure of that.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n run(body: any): Promise<void>;\n}\nexport declare class ReadableJsonStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null);\n}\nexport declare class SseStream implements AbstractStream {\n _buffer: string;\n _bufferOpen: boolean;\n appendBuffer(data: string): void;\n closeBuffer(): void;\n /**\n * Attempt to load an entire event.\n * For each entire event we load,\n * send them to be handled.\n */\n _parseBuffer(): void;\n /**\n * Given an event string, get all the fields\n * in the event. It is assumed there is one field\n * per line, but that field names can be duplicated,\n * indicating to append the new value to the previous value\n * @param event\n */\n _parseEvent(event: string | null): Record<string, string> | null;\n // Set up a potential Promise that the handler can resolve.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkResolution: (chunk: any) => void;\n // If there is no Promise (it is null), the handler must add it to the queue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkPending: Promise<any> | null;\n // A queue that will collect chunks while there is no Promise\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkQueue: any[];\n _handleEvent(event: string | null): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n get streamDone(): boolean;\n}\nexport declare class ReadableSseStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null);\n}\nexport declare class SseJsonStream extends SseStream {\n _jsonAttribute: string;\n constructor(jsonAttribute?: string);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n}\nexport declare class ReadableSseJsonStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null);\n}\n"],"mappings":";UAAiBA,cAAAA;EAAAA;AA0BjB;AACA;AACA;EAA+B,YAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAA;;;AAA0B;EAoEpCK,WAAAA,EAAAA,EAAAA,IAAAA;EAGAC;;;;EAGqB;EAAsB,SAI/CL,EAAAA,EA1FAA,OA0FAA,CAAAA,GAAAA,CAAAA;EAAO;;AAP6C;AAcrE;;;;EAAsE,IAAA,UAAA,EAAA,EAAA,OAAA;AAGtE;AAA8B,iBA1FNC,YAAAA,CA0FM,KAAA,EAAA,OAAA,CAAA,EAAA,OAAA;AAkBSS,iBA3GfR,WAAAA,CA2GeQ,GAAAA,EAAAA,OAAAA,CAAAA,EAAAA,OAAAA;AAMpBV,cAhHEG,UAAAA,YAAsBJ,cAgHxBC,CAAAA;EAAO,OAMTA,EAAAA,MAAAA;EAAO,WA9BkBD,EAAAA,OAAAA;EAAc,SAAA,EAAA,OAAA;EAiCnCY;;;;EAAgD,YAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAGhDC;;;;AAA+B;EAM/BC,WAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAAqB;;;AAA+B;;;;;;;;;;;;;;;;;;;;;;;iBAzFtDb;;;;;;;;;;;;;;;;;eAiBFA;;;;;;;;;;cAUII,iBAAAA,SAA0BD,UAAU;;;cAGpCE,sBAAAA,YAAkCN;;WAE1CO;0BACeP,sBAAsBQ;;;;eAIjCP;;;;;kBAKGA;;cAECQ,kBAAAA,SAA2BH,sBAAAA;oBAC1BE;;cAEDE,SAAAA,YAAqBV;;;;;;;;;;;;;;;;;;qCAkBHW;;;;;;iBAMpBV;;;;;;eAMFA;;;cAGIW,iBAAAA,SAA0BN,sBAAAA;oBACzBE;;cAEDK,aAAAA,SAAsBH,SAAAA;;;;eAI1BT;;cAEIa,qBAAAA,SAA8BR,sBAAAA;oBAC7BE"}
@@ -1,140 +1,165 @@
1
- export interface AbstractStream {
2
- /**
3
- * Add more text to the buffer
4
- * @param data
5
- */
6
- appendBuffer(data: string): void;
7
- /**
8
- * Indicate that there is no more text to be added to the buffer
9
- * (ie - our source material is done)
10
- */
11
- closeBuffer(): void;
12
- /**
13
- * Get the next chunk that is coming from the stream.
14
- * This chunk may be null, usually indicating the last chunk in the stream.
15
- */
16
- nextChunk(): Promise<any>;
17
- /**
18
- * Is the stream done?
19
- * A stream is only done if all of the following are true:
20
- * - There is no more data to be added to the text buffer
21
- * - There is no more data in the text buffer
22
- * - There are no chunks that are waiting to be consumed
23
- */
24
- get streamDone(): boolean;
1
+ //#region src/utils/stream.d.ts
2
+ interface AbstractStream {
3
+ /**
4
+ * Add more text to the buffer
5
+ * @param data
6
+ */
7
+ appendBuffer(data: string): void;
8
+ /**
9
+ * Indicate that there is no more text to be added to the buffer
10
+ * (ie - our source material is done)
11
+ */
12
+ closeBuffer(): void;
13
+ /**
14
+ * Get the next chunk that is coming from the stream.
15
+ * This chunk may be null, usually indicating the last chunk in the stream.
16
+ */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ nextChunk(): Promise<any>;
19
+ /**
20
+ * Is the stream done?
21
+ * A stream is only done if all of the following are true:
22
+ * - There is no more data to be added to the text buffer
23
+ * - There is no more data in the text buffer
24
+ * - There are no chunks that are waiting to be consumed
25
+ */
26
+ get streamDone(): boolean;
25
27
  }
26
- export declare function complexValue(value: unknown): unknown;
27
- export declare function simpleValue(val: unknown): unknown;
28
- export declare class JsonStream implements AbstractStream {
29
- _buffer: string;
30
- _bufferOpen: boolean;
31
- _firstRun: boolean;
32
- /**
33
- * Add data to the buffer. This may cause chunks to be generated, if available.
34
- * @param data
35
- */
36
- appendBuffer(data: string): void;
37
- /**
38
- * Indicate there is no more data that will be added to the text buffer.
39
- * This should be called when all the data has been read and added to indicate
40
- * that we should process everything remaining in the buffer.
41
- */
42
- closeBuffer(): void;
43
- /**
44
- * Skip characters in the buffer till we get to the start of an object.
45
- * Then attempt to read a full object.
46
- * If we do read a full object, turn it into a chunk and send it to the chunk handler.
47
- * Repeat this for as much as we can.
48
- */
49
- _parseBuffer(): void;
50
- /**
51
- * If the string is present, move the start of the buffer to the first occurrence
52
- * of that string. This is useful for skipping over elements or parts that we're not
53
- * really interested in parsing. (ie - the opening characters, comma separators, etc.)
54
- * @param start The string to start the buffer with
55
- */
56
- _skipTo(start: string): void;
57
- /**
58
- * Given what is in the buffer, parse a single object out of it.
59
- * If a complete object isn't available, return null.
60
- * Assumes that we are at the start of an object to parse.
61
- */
62
- _getFullObject(): object | null;
63
- _simplifyObject(obj: unknown): object;
64
- _chunkResolution: (chunk: any) => void;
65
- _chunkPending: Promise<any> | null;
66
- _chunkQueue: any[];
67
- /**
68
- * Register that we have another chunk available for consumption.
69
- * If we are waiting for a chunk, resolve the promise waiting for it immediately.
70
- * If not, then add it to the queue.
71
- * @param chunk
72
- */
73
- _handleChunk(chunk: any): void;
74
- /**
75
- * Get the next chunk that is coming from the stream.
76
- * This chunk may be null, usually indicating the last chunk in the stream.
77
- */
78
- nextChunk(): Promise<any>;
79
- /**
80
- * Is the stream done?
81
- * A stream is only done if all of the following are true:
82
- * - There is no more data to be added to the text buffer
83
- * - There is no more data in the text buffer
84
- * - There are no chunks that are waiting to be consumed
85
- */
86
- get streamDone(): boolean;
28
+ declare function complexValue(value: unknown): unknown;
29
+ declare function simpleValue(val: unknown): unknown;
30
+ declare class JsonStream implements AbstractStream {
31
+ _buffer: string;
32
+ _bufferOpen: boolean;
33
+ _firstRun: boolean;
34
+ /**
35
+ * Add data to the buffer. This may cause chunks to be generated, if available.
36
+ * @param data
37
+ */
38
+ appendBuffer(data: string): void;
39
+ /**
40
+ * Indicate there is no more data that will be added to the text buffer.
41
+ * This should be called when all the data has been read and added to indicate
42
+ * that we should process everything remaining in the buffer.
43
+ */
44
+ closeBuffer(): void;
45
+ /**
46
+ * Skip characters in the buffer till we get to the start of an object.
47
+ * Then attempt to read a full object.
48
+ * If we do read a full object, turn it into a chunk and send it to the chunk handler.
49
+ * Repeat this for as much as we can.
50
+ */
51
+ _parseBuffer(): void;
52
+ /**
53
+ * If the string is present, move the start of the buffer to the first occurrence
54
+ * of that string. This is useful for skipping over elements or parts that we're not
55
+ * really interested in parsing. (ie - the opening characters, comma separators, etc.)
56
+ * @param start The string to start the buffer with
57
+ */
58
+ _skipTo(start: string): void;
59
+ /**
60
+ * Given what is in the buffer, parse a single object out of it.
61
+ * If a complete object isn't available, return null.
62
+ * Assumes that we are at the start of an object to parse.
63
+ */
64
+ _getFullObject(): object | null;
65
+ _simplifyObject(obj: unknown): object;
66
+ // Set up a potential Promise that the handler can resolve.
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ _chunkResolution: (chunk: any) => void;
69
+ // If there is no Promise (it is null), the handler must add it to the queue
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ _chunkPending: Promise<any> | null;
72
+ // A queue that will collect chunks while there is no Promise
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ _chunkQueue: any[];
75
+ /**
76
+ * Register that we have another chunk available for consumption.
77
+ * If we are waiting for a chunk, resolve the promise waiting for it immediately.
78
+ * If not, then add it to the queue.
79
+ * @param chunk
80
+ */
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ _handleChunk(chunk: any): void;
83
+ /**
84
+ * Get the next chunk that is coming from the stream.
85
+ * This chunk may be null, usually indicating the last chunk in the stream.
86
+ */
87
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
+ nextChunk(): Promise<any>;
89
+ /**
90
+ * Is the stream done?
91
+ * A stream is only done if all of the following are true:
92
+ * - There is no more data to be added to the text buffer
93
+ * - There is no more data in the text buffer
94
+ * - There are no chunks that are waiting to be consumed
95
+ */
96
+ get streamDone(): boolean;
87
97
  }
88
- export declare class ComplexJsonStream extends JsonStream {
89
- _simplifyObject(obj: unknown): object;
98
+ declare class ComplexJsonStream extends JsonStream {
99
+ _simplifyObject(obj: unknown): object;
90
100
  }
91
- export declare class ReadableAbstractStream implements AbstractStream {
92
- private baseStream;
93
- decoder: TextDecoder;
94
- constructor(baseStream: AbstractStream, body: ReadableStream | null);
95
- appendBuffer(data: string): void;
96
- closeBuffer(): void;
97
- nextChunk(): Promise<any>;
98
- get streamDone(): boolean;
99
- run(body: any): Promise<void>;
101
+ declare class ReadableAbstractStream implements AbstractStream {
102
+ private baseStream;
103
+ decoder: TextDecoder;
104
+ constructor(baseStream: AbstractStream, body: ReadableStream | null);
105
+ appendBuffer(data: string): void;
106
+ closeBuffer(): void;
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
+ nextChunk(): Promise<any>;
109
+ get streamDone(): boolean;
110
+ // Should be a ReadableStream, but the Gaxios Readable stream isn't.
111
+ // But both should support async iterators, so make sure of that.
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ run(body: any): Promise<void>;
100
114
  }
101
- export declare class ReadableJsonStream extends ReadableAbstractStream {
102
- constructor(body: ReadableStream | null);
115
+ declare class ReadableJsonStream extends ReadableAbstractStream {
116
+ constructor(body: ReadableStream | null);
103
117
  }
104
- export declare class SseStream implements AbstractStream {
105
- _buffer: string;
106
- _bufferOpen: boolean;
107
- appendBuffer(data: string): void;
108
- closeBuffer(): void;
109
- /**
110
- * Attempt to load an entire event.
111
- * For each entire event we load,
112
- * send them to be handled.
113
- */
114
- _parseBuffer(): void;
115
- /**
116
- * Given an event string, get all the fields
117
- * in the event. It is assumed there is one field
118
- * per line, but that field names can be duplicated,
119
- * indicating to append the new value to the previous value
120
- * @param event
121
- */
122
- _parseEvent(event: string | null): Record<string, string> | null;
123
- _chunkResolution: (chunk: any) => void;
124
- _chunkPending: Promise<any> | null;
125
- _chunkQueue: any[];
126
- _handleEvent(event: string | null): void;
127
- nextChunk(): Promise<any>;
128
- get streamDone(): boolean;
118
+ declare class SseStream implements AbstractStream {
119
+ _buffer: string;
120
+ _bufferOpen: boolean;
121
+ appendBuffer(data: string): void;
122
+ closeBuffer(): void;
123
+ /**
124
+ * Attempt to load an entire event.
125
+ * For each entire event we load,
126
+ * send them to be handled.
127
+ */
128
+ _parseBuffer(): void;
129
+ /**
130
+ * Given an event string, get all the fields
131
+ * in the event. It is assumed there is one field
132
+ * per line, but that field names can be duplicated,
133
+ * indicating to append the new value to the previous value
134
+ * @param event
135
+ */
136
+ _parseEvent(event: string | null): Record<string, string> | null;
137
+ // Set up a potential Promise that the handler can resolve.
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ _chunkResolution: (chunk: any) => void;
140
+ // If there is no Promise (it is null), the handler must add it to the queue
141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+ _chunkPending: Promise<any> | null;
143
+ // A queue that will collect chunks while there is no Promise
144
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
+ _chunkQueue: any[];
146
+ _handleEvent(event: string | null): void;
147
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
+ nextChunk(): Promise<any>;
149
+ get streamDone(): boolean;
129
150
  }
130
- export declare class ReadableSseStream extends ReadableAbstractStream {
131
- constructor(body: ReadableStream | null);
151
+ declare class ReadableSseStream extends ReadableAbstractStream {
152
+ constructor(body: ReadableStream | null);
132
153
  }
133
- export declare class SseJsonStream extends SseStream {
134
- _jsonAttribute: string;
135
- constructor(jsonAttribute?: string);
136
- nextChunk(): Promise<any>;
154
+ declare class SseJsonStream extends SseStream {
155
+ _jsonAttribute: string;
156
+ constructor(jsonAttribute?: string);
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ nextChunk(): Promise<any>;
137
159
  }
138
- export declare class ReadableSseJsonStream extends ReadableAbstractStream {
139
- constructor(body: ReadableStream | null);
160
+ declare class ReadableSseJsonStream extends ReadableAbstractStream {
161
+ constructor(body: ReadableStream | null);
140
162
  }
163
+ //#endregion
164
+ export { AbstractStream, ComplexJsonStream, JsonStream, ReadableAbstractStream, ReadableJsonStream, ReadableSseJsonStream, ReadableSseStream, SseJsonStream, SseStream, complexValue, simpleValue };
165
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","names":["AbstractStream","Promise","complexValue","simpleValue","JsonStream","ComplexJsonStream","ReadableAbstractStream","TextDecoder","ReadableStream","ReadableJsonStream","SseStream","Record","ReadableSseStream","SseJsonStream","ReadableSseJsonStream"],"sources":["../../src/utils/stream.d.ts"],"sourcesContent":["export interface AbstractStream {\n /**\n * Add more text to the buffer\n * @param data\n */\n appendBuffer(data: string): void;\n /**\n * Indicate that there is no more text to be added to the buffer\n * (ie - our source material is done)\n */\n closeBuffer(): void;\n /**\n * Get the next chunk that is coming from the stream.\n * This chunk may be null, usually indicating the last chunk in the stream.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n /**\n * Is the stream done?\n * A stream is only done if all of the following are true:\n * - There is no more data to be added to the text buffer\n * - There is no more data in the text buffer\n * - There are no chunks that are waiting to be consumed\n */\n get streamDone(): boolean;\n}\nexport declare function complexValue(value: unknown): unknown;\nexport declare function simpleValue(val: unknown): unknown;\nexport declare class JsonStream implements AbstractStream {\n _buffer: string;\n _bufferOpen: boolean;\n _firstRun: boolean;\n /**\n * Add data to the buffer. This may cause chunks to be generated, if available.\n * @param data\n */\n appendBuffer(data: string): void;\n /**\n * Indicate there is no more data that will be added to the text buffer.\n * This should be called when all the data has been read and added to indicate\n * that we should process everything remaining in the buffer.\n */\n closeBuffer(): void;\n /**\n * Skip characters in the buffer till we get to the start of an object.\n * Then attempt to read a full object.\n * If we do read a full object, turn it into a chunk and send it to the chunk handler.\n * Repeat this for as much as we can.\n */\n _parseBuffer(): void;\n /**\n * If the string is present, move the start of the buffer to the first occurrence\n * of that string. This is useful for skipping over elements or parts that we're not\n * really interested in parsing. (ie - the opening characters, comma separators, etc.)\n * @param start The string to start the buffer with\n */\n _skipTo(start: string): void;\n /**\n * Given what is in the buffer, parse a single object out of it.\n * If a complete object isn't available, return null.\n * Assumes that we are at the start of an object to parse.\n */\n _getFullObject(): object | null;\n _simplifyObject(obj: unknown): object;\n // Set up a potential Promise that the handler can resolve.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkResolution: (chunk: any) => void;\n // If there is no Promise (it is null), the handler must add it to the queue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkPending: Promise<any> | null;\n // A queue that will collect chunks while there is no Promise\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkQueue: any[];\n /**\n * Register that we have another chunk available for consumption.\n * If we are waiting for a chunk, resolve the promise waiting for it immediately.\n * If not, then add it to the queue.\n * @param chunk\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _handleChunk(chunk: any): void;\n /**\n * Get the next chunk that is coming from the stream.\n * This chunk may be null, usually indicating the last chunk in the stream.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n /**\n * Is the stream done?\n * A stream is only done if all of the following are true:\n * - There is no more data to be added to the text buffer\n * - There is no more data in the text buffer\n * - There are no chunks that are waiting to be consumed\n */\n get streamDone(): boolean;\n}\nexport declare class ComplexJsonStream extends JsonStream {\n _simplifyObject(obj: unknown): object;\n}\nexport declare class ReadableAbstractStream implements AbstractStream {\n private baseStream;\n decoder: TextDecoder;\n constructor(baseStream: AbstractStream, body: ReadableStream | null);\n appendBuffer(data: string): void;\n closeBuffer(): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n get streamDone(): boolean;\n // Should be a ReadableStream, but the Gaxios Readable stream isn't.\n // But both should support async iterators, so make sure of that.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n run(body: any): Promise<void>;\n}\nexport declare class ReadableJsonStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null);\n}\nexport declare class SseStream implements AbstractStream {\n _buffer: string;\n _bufferOpen: boolean;\n appendBuffer(data: string): void;\n closeBuffer(): void;\n /**\n * Attempt to load an entire event.\n * For each entire event we load,\n * send them to be handled.\n */\n _parseBuffer(): void;\n /**\n * Given an event string, get all the fields\n * in the event. It is assumed there is one field\n * per line, but that field names can be duplicated,\n * indicating to append the new value to the previous value\n * @param event\n */\n _parseEvent(event: string | null): Record<string, string> | null;\n // Set up a potential Promise that the handler can resolve.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkResolution: (chunk: any) => void;\n // If there is no Promise (it is null), the handler must add it to the queue\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkPending: Promise<any> | null;\n // A queue that will collect chunks while there is no Promise\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _chunkQueue: any[];\n _handleEvent(event: string | null): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n get streamDone(): boolean;\n}\nexport declare class ReadableSseStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null);\n}\nexport declare class SseJsonStream extends SseStream {\n _jsonAttribute: string;\n constructor(jsonAttribute?: string);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nextChunk(): Promise<any>;\n}\nexport declare class ReadableSseJsonStream extends ReadableAbstractStream {\n constructor(body: ReadableStream | null);\n}\n"],"mappings":";UAAiBA,cAAAA;EAAAA;AA0BjB;AACA;AACA;EAA+B,YAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAA;;;AAA0B;EAoEpCK,WAAAA,EAAAA,EAAAA,IAAAA;EAGAC;;;;EAGqB;EAAsB,SAI/CL,EAAAA,EA1FAA,OA0FAA,CAAAA,GAAAA,CAAAA;EAAO;;AAP6C;AAcrE;;;;EAAsE,IAAA,UAAA,EAAA,EAAA,OAAA;AAGtE;AAA8B,iBA1FNC,YAAAA,CA0FM,KAAA,EAAA,OAAA,CAAA,EAAA,OAAA;AAkBSS,iBA3GfR,WAAAA,CA2GeQ,GAAAA,EAAAA,OAAAA,CAAAA,EAAAA,OAAAA;AAMpBV,cAhHEG,UAAAA,YAAsBJ,cAgHxBC,CAAAA;EAAO,OAMTA,EAAAA,MAAAA;EAAO,WA9BkBD,EAAAA,OAAAA;EAAc,SAAA,EAAA,OAAA;EAiCnCY;;;;EAAgD,YAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAGhDC;;;;AAA+B;EAM/BC,WAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAAqB;;;AAA+B;;;;;;;;;;;;;;;;;;;;;;;iBAzFtDb;;;;;;;;;;;;;;;;;eAiBFA;;;;;;;;;;cAUII,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