MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / aggregateResponsesApiPayloads

Function aggregateResponsesApiPayloads

ai/ai.ts:2104–2180  ·  view source on GitHub ↗
(
  payloads: any[],
)

Source from the content-addressed store, hash-verified

2102
2103const aggregateResponsesApiPayloads = (
2104 payloads: any[],
2105): {
2106 text: string;
2107 images: AIImage[];
2108 sources: Array<{ url: string; title?: string }>;
2109} => {
2110 const deltaTexts: string[] = [];
2111 let fallbackText = "";
2112 let fallbackImages: AIImage[] = [];
2113 const sources: Array<{ url: string; title?: string }> = [];
2114 const seenSources = new Set<string>();
2115
2116 const appendSources = (entries: Array<{ url: string; title?: string }>) => {
2117 for (const entry of entries) {
2118 if (seenSources.has(entry.url)) continue;
2119 seenSources.add(entry.url);
2120 sources.push(entry);
2121 }
2122 };
2123
2124 const appendItem = (item: any) => {
2125 const parsed = parseResponsesOutputContent(item);
2126 if (parsed.text) fallbackText = parsed.text;
2127 if (parsed.images.length > 0) fallbackImages = parsed.images;
2128 appendSources(parsed.sources);
2129 };
2130
2131 for (const payload of payloads) {
2132 if (
2133 payload?.type === "response.output_text.delta" &&
2134 typeof payload.delta === "string"
2135 ) {
2136 deltaTexts.push(payload.delta);
2137 }
2138
2139 if (
2140 payload?.type === "response.output_text.done" &&
2141 typeof payload.text === "string" &&
2142 deltaTexts.length === 0
2143 ) {
2144 fallbackText = payload.text.trim();
2145 }
2146
2147 if (payload?.type === "response.content_part.done") {
2148 appendSources(
2149 collectResponsesSources({
2150 type: "message",
2151 content: [payload.part],
2152 }),
2153 );
2154 }
2155
2156 if (payload?.item) appendItem(payload.item);
2157
2158 const response =
2159 payload?.response?.object === "response"
2160 ? payload.response
2161 : payload?.object === "response"

Callers 1

parseOpenAIResponseDataFunction · 0.85

Calls 3

appendSourcesFunction · 0.85
collectResponsesSourcesFunction · 0.85
appendItemFunction · 0.85

Tested by

no test coverage detected