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

Function collectResponsesSources

ai/ai.ts:2018–2065  ·  view source on GitHub ↗
(
  item: any,
)

Source from the content-addressed store, hash-verified

2016
2017const collectResponsesSources = (
2018 item: any,
2019): Array<{ url: string; title?: string }> => {
2020 const sources: Array<{ url: string; title?: string }> = [];
2021 const seen = new Set<string>();
2022
2023 const appendSource = (url?: string, title?: string) => {
2024 if (!url || seen.has(url)) return;
2025 seen.add(url);
2026 sources.push({ url, title });
2027 };
2028
2029 const appendAnnotations = (annotations: any[] | undefined) => {
2030 if (!Array.isArray(annotations)) return;
2031 for (const entry of annotations) {
2032 if (entry?.type !== "url_citation") continue;
2033 appendSource(entry?.url, entry?.title);
2034 }
2035 };
2036
2037 const appendActionSources = (action: any) => {
2038 const sourceList = Array.isArray(action?.sources)
2039 ? action.sources
2040 : Array.isArray(action)
2041 ? action
2042 : [];
2043 for (const entry of sourceList) {
2044 if (typeof entry?.url !== "string") continue;
2045 appendSource(entry.url, entry.title);
2046 }
2047 };
2048
2049 if (item?.type === "message") {
2050 for (const part of item.content || []) {
2051 appendAnnotations(part?.annotations);
2052 }
2053 }
2054
2055 if (item?.type === "web_search_call") {
2056 if (Array.isArray(item?.action)) {
2057 for (const action of item.action) appendActionSources(action);
2058 } else {
2059 appendActionSources(item?.action);
2060 }
2061 }
2062
2063 return sources;
2064};
2065
2066const parseResponsesOutputContent = (
2067 item: any,
2068): {

Callers 2

Calls 2

appendAnnotationsFunction · 0.85
appendActionSourcesFunction · 0.85

Tested by

no test coverage detected