Compare commits
2
Commits
hlh
...
gzy_iframedf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
004853f030 | ||
|
|
37be59b0dd |
No files matched your search
Generated
+10540
File diff suppressed because it is too large.
Load diff
@@ -17,6 +17,7 @@ import {
|
|||||||
} from "@/components/workspace/messages";
|
} from "@/components/workspace/messages";
|
||||||
import { ThreadContext } from "@/components/workspace/messages/context";
|
import { ThreadContext } from "@/components/workspace/messages/context";
|
||||||
import { TodoList } from "@/components/workspace/todo-list";
|
import { TodoList } from "@/components/workspace/todo-list";
|
||||||
|
import { getAccessToken } from "@/core/auth";
|
||||||
import { useI18n } from "@/core/i18n/hooks";
|
import { useI18n } from "@/core/i18n/hooks";
|
||||||
import { useModels } from "@/core/models/hooks";
|
import { useModels } from "@/core/models/hooks";
|
||||||
import { useNotification } from "@/core/notification/hooks";
|
import { useNotification } from "@/core/notification/hooks";
|
||||||
@@ -33,6 +34,13 @@ import {
|
|||||||
} from "./iframe-chat-submit";
|
} from "./iframe-chat-submit";
|
||||||
|
|
||||||
type BrainyChatStatus = "started" | "finished";
|
type BrainyChatStatus = "started" | "finished";
|
||||||
|
type BrainyAuthTokenMessage = {
|
||||||
|
source: "brainy-iframe";
|
||||||
|
type: "brainy:auth-token";
|
||||||
|
payload: {
|
||||||
|
accessToken: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
type BrainyChatInterruptMessage = {
|
type BrainyChatInterruptMessage = {
|
||||||
source?: string;
|
source?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
@@ -57,6 +65,18 @@ function postBrainyChatStatus(status: BrainyChatStatus, requestId: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postBrainyAuthToken(accessToken: string) {
|
||||||
|
const message: BrainyAuthTokenMessage = {
|
||||||
|
source: "brainy-iframe",
|
||||||
|
type: "brainy:auth-token",
|
||||||
|
payload: {
|
||||||
|
accessToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
window.parent?.postMessage(message, "*");
|
||||||
|
}
|
||||||
|
|
||||||
export default function IframeChatPage() {
|
export default function IframeChatPage() {
|
||||||
const routeBase = useRouteBase();
|
const routeBase = useRouteBase();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -79,6 +99,28 @@ export default function IframeChatPage() {
|
|||||||
setMounted(true);
|
setMounted(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let lastToken: string | undefined;
|
||||||
|
|
||||||
|
const emitAccessToken = () => {
|
||||||
|
const accessToken = getAccessToken();
|
||||||
|
if (!accessToken || accessToken === lastToken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastToken = accessToken;
|
||||||
|
postBrainyAuthToken(accessToken);
|
||||||
|
};
|
||||||
|
|
||||||
|
emitAccessToken();
|
||||||
|
window.addEventListener("focus", emitAccessToken);
|
||||||
|
window.addEventListener("storage", emitAccessToken);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("focus", emitAccessToken);
|
||||||
|
window.removeEventListener("storage", emitAccessToken);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isNewThread) {
|
if (isNewThread) {
|
||||||
setHasStartedConversation(false);
|
setHasStartedConversation(false);
|
||||||
|
|||||||
Reference in new issue
Block a user