UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

45 lines (44 loc) 1.4 kB
import { jsx as u } from "react/jsx-runtime"; import { SynapseChatInteraction as h } from "./SynapseChatInteraction.js"; import m from "../../synapse-queries/asynchronous/usePollAsynchronousJob.js"; import { useGetChatAgentTraceEvents as f } from "../../synapse-queries/chat/useChat.js"; import { useState as T, useCallback as l, useEffect as E } from "react"; function d(o, s) { const [a, e] = T([]), n = l((c) => { e((p) => [...p, ...c]); }, []), r = a.at(a.length - 1), { data: t } = f( { jobId: o, newerThanTimestamp: r?.timestamp }, { enabled: s, refetchInterval: 1e3, // Re-fetch every second if enabled refetchIntervalInBackground: !0 // Continue polling even when the tab is not active } ); return E(() => { t && t.page.length > 0 && (n(t.page), console.debug(t.page)); }, [n, t]), { traceEvents: a }; } function I(o) { const { chatJobId: s, onSendChat: a } = o, { data: e } = m(s), n = e?.requestBody, r = e?.responseBody, t = e?.errorMessage, c = !!s && (!e?.jobState || e.jobState == "PROCESSING"), { traceEvents: p } = d(s, c); return /* @__PURE__ */ u( h, { userMessage: n?.chatText, chatResponseText: r?.responseText, chatResponseTrace: p, chatErrorReason: t, onSendChat: a } ); } export { I as default }; //# sourceMappingURL=SynapseChatMessage.js.map