({
response,
rawResponse,
}: {
response: Response;
rawResponse?: boolean;
})
| 49 | * @returns {Record<string, string>} return.rawResponse.headers - The headers from the raw response. |
| 50 | */ |
| 51 | export function handleResponseStream({ |
| 52 | response, |
| 53 | rawResponse, |
| 54 | }: { |
| 55 | response: Response; |
| 56 | rawResponse?: boolean; |
| 57 | }): { |
| 58 | stream: any; |
| 59 | threadId: string | null; |
| 60 | rawResponse?: { |
| 61 | headers: Record<string, string>; |
| 62 | }; |
| 63 | } { |
| 64 | const controller = new AbortController(); |
| 65 | const streamSSE = Stream.fromSSEResponse(response, controller); |
| 66 | const stream = streamSSE.toReadableStream(); |
| 67 | |
| 68 | const result: { |
| 69 | stream: ReadableStream<any>; |
| 70 | threadId: string | null; |
| 71 | rawResponse?: { |
| 72 | headers: Record<string, string>; |
| 73 | }; |
| 74 | } = { |
| 75 | stream, |
| 76 | threadId: response.headers.get('lb-thread-id'), |
| 77 | }; |
| 78 | if (rawResponse) { |
| 79 | result.rawResponse = { |
| 80 | headers: Object.fromEntries(response.headers.entries()), |
| 81 | }; |
| 82 | } |
| 83 | return result; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Retrieves tool calls from a given readable stream. |
no test coverage detected