MCPcopy Index your code
hub / github.com/CommandCodeAI/BaseAI / handleResponseStream

Function handleResponseStream

packages/core/src/helpers/stream.ts:51–84  ·  view source on GitHub ↗
({
	response,
	rawResponse,
}: {
	response: Response;
	rawResponse?: boolean;
})

Source from the content-addressed store, hash-verified

49 * @returns {Record<string, string>} return.rawResponse.headers - The headers from the raw response.
50 */
51export 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.

Callers 1

sendMethod · 0.90

Calls 3

getMethod · 0.80
fromSSEResponseMethod · 0.45
toReadableStreamMethod · 0.45

Tested by

no test coverage detected