fix: resolve file conflicts

This commit is contained in:
yassinedorbozgithub 2025-01-31 22:32:38 +01:00
commit 734838660a
23 changed files with 533 additions and 71 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -11,6 +11,7 @@ import {
Body, Body,
Controller, Controller,
Get, Get,
Inject,
InternalServerErrorException, InternalServerErrorException,
Param, Param,
Post, Post,
@ -21,6 +22,7 @@ import {
UseGuards, UseGuards,
UseInterceptors, UseInterceptors,
} from '@nestjs/common'; } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { CsrfCheck, CsrfGen, CsrfGenAuth } from '@tekuconcept/nestjs-csrf'; import { CsrfCheck, CsrfGen, CsrfGenAuth } from '@tekuconcept/nestjs-csrf';
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { Session as ExpressSession } from 'express-session'; import { Session as ExpressSession } from 'express-session';
@ -38,6 +40,9 @@ import { UserService } from '../services/user.service';
import { ValidateAccountService } from '../services/validate-account.service'; import { ValidateAccountService } from '../services/validate-account.service';
export class BaseAuthController { export class BaseAuthController {
@Inject(EventEmitter2)
private readonly eventEmitter: EventEmitter2;
constructor(protected readonly logger: LoggerService) {} constructor(protected readonly logger: LoggerService) {}
/** /**
@ -67,6 +72,7 @@ export class BaseAuthController {
@Session() session: ExpressSession, @Session() session: ExpressSession,
@Res({ passthrough: true }) res: Response, @Res({ passthrough: true }) res: Response,
) { ) {
this.eventEmitter.emit('hook:user:logout', session);
res.clearCookie(config.session.name); res.clearCookie(config.session.name);
session.destroy((error) => { session.destroy((error) => {

View File

@ -1,12 +1,12 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { EventEmitter2 } from '@nestjs/event-emitter'; import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { import {
ConnectedSocket, ConnectedSocket,
MessageBody, MessageBody,
@ -20,7 +20,7 @@ import {
import cookie from 'cookie'; import cookie from 'cookie';
import * as cookieParser from 'cookie-parser'; import * as cookieParser from 'cookie-parser';
import signature from 'cookie-signature'; import signature from 'cookie-signature';
import { SessionData } from 'express-session'; import { Session as ExpressSession, SessionData } from 'express-session';
import { Server, Socket } from 'socket.io'; import { Server, Socket } from 'socket.io';
import { sync as uid } from 'uid-safe'; import { sync as uid } from 'uid-safe';
@ -258,6 +258,15 @@ export class WebsocketGateway
this.eventEmitter.emit(`hook:websocket:connection`, client); this.eventEmitter.emit(`hook:websocket:connection`, client);
} }
@OnEvent('hook:user:logout')
disconnectSockets({ id }: ExpressSession) {
for (const [, socket] of this.io.sockets.sockets) {
if (socket.data['sessionID'] === id) {
socket.disconnect(true);
}
}
}
async handleDisconnect(client: Socket): Promise<void> { async handleDisconnect(client: Socket): Promise<void> {
this.logger.log(`Client id:${client.id} disconnected`); this.logger.log(`Client id:${client.id} disconnected`);
// Configurable custom afterDisconnect logic here // Configurable custom afterDisconnect logic here

View File

@ -1,11 +1,12 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { type Session as ExpressSession } from 'express-session';
import type { Document, Query } from 'mongoose'; import type { Document, Query } from 'mongoose';
import { type Socket } from 'socket.io'; import { type Socket } from 'socket.io';
@ -162,7 +163,7 @@ declare module '@nestjs/event-emitter' {
model: TDefinition<Model>; model: TDefinition<Model>;
permission: TDefinition<Permission>; permission: TDefinition<Permission>;
role: TDefinition<Role>; role: TDefinition<Role>;
user: TDefinition<User, { lastvisit: Subscriber }>; user: TDefinition<User, { lastvisit: Subscriber; logout: ExpressSession }>;
} }
/* entities hooks having schemas */ /* entities hooks having schemas */

View File

@ -1,11 +1,12 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import UploadIcon from "@mui/icons-material/Upload"; import UploadIcon from "@mui/icons-material/Upload";
import { Button, CircularProgress } from "@mui/material"; import { Button, CircularProgress } from "@mui/material";
import { ChangeEvent, forwardRef } from "react"; import { ChangeEvent, forwardRef } from "react";
@ -71,6 +72,7 @@ const FileUploadButton = forwardRef<HTMLLabelElement, FileUploadButtonProps>(
value="" // to trigger an automatic reset to allow the same file to be selected multiple times value="" // to trigger an automatic reset to allow the same file to be selected multiple times
sx={{ display: "none" }} sx={{ display: "none" }}
onChange={handleImportChange} onChange={handleImportChange}
inputProps={{ accept }}
/> />
</> </>
); );

View File

@ -1,18 +1,18 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { css, keyframes } from "@emotion/react"; import { css, keyframes } from "@emotion/react";
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { import {
DefaultLinkFactory, DefaultLinkFactory,
DefaultLinkWidget, DefaultLinkWidget,
} from "@projectstorm/react-diagrams"; } from "@projectstorm/react-diagrams";
import React from "react";
import { AdvancedLinkModel } from "./AdvancedLinkModel"; import { AdvancedLinkModel } from "./AdvancedLinkModel";

View File

@ -0,0 +1,62 @@
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import { css } from "@emotion/react";
import styled from "@emotion/styled";
import { CanvasModel } from "@projectstorm/react-canvas-core";
import * as React from "react";
import { CSSProperties } from "react";
export interface BackgroundLayerWidgetProps {
model: CanvasModel;
}
namespace S {
const shared = css`
top: 0;
left: 0;
right: 0;
bottom: 0;
position: absolute;
pointer-events: none;
transform-origin: 0 0;
width: 200%;
height: 200%;
overflow: visible;
background-color: #f2f4f7;
background-image: radial-gradient(
circle,
rgba(0, 0, 0, 0.075) 8%,
transparent 10%
);
background-size: 16px 16px;
`;
export const DivLayer = styled.div`
${shared}
`;
}
export class BackgroundLayerWidget extends React.Component<
React.PropsWithChildren<BackgroundLayerWidgetProps>
> {
constructor(props: BackgroundLayerWidgetProps) {
super(props);
this.state = {};
}
getTransformStyle(): CSSProperties {
return {
backgroundPosition: `${this.props.model.getOffsetX()}px ${this.props.model.getOffsetY()}px`,
};
}
render() {
return <S.DivLayer style={this.getTransformStyle()} />;
}
}

View File

@ -1,11 +1,12 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { import {
CanvasEngine, CanvasEngine,
@ -14,6 +15,8 @@ import {
} from "@projectstorm/react-diagrams"; } from "@projectstorm/react-diagrams";
import * as React from "react"; import * as React from "react";
import { BackgroundLayerWidget } from "./BackgroundLayerWidget";
export interface DiagramProps { export interface DiagramProps {
engine: CanvasEngine; engine: CanvasEngine;
className?: string; className?: string;
@ -115,6 +118,7 @@ export class CustomCanvasWidget extends React.Component<DiagramProps> {
this.props.engine.getActionEventBus().fireAction({ event }); this.props.engine.getActionEventBus().fireAction({ event });
}} }}
> >
<BackgroundLayerWidget model={model} />;
{model.getLayers().map((layer) => { {model.getLayers().map((layer) => {
return ( return (
<TransformLayerWidget layer={layer} key={layer.getID()}> <TransformLayerWidget layer={layer} key={layer.getID()}>

View File

@ -1,11 +1,12 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import BrokenImageOutlinedIcon from "@mui/icons-material/BrokenImageOutlined"; import BrokenImageOutlinedIcon from "@mui/icons-material/BrokenImageOutlined";
import ChatBubbleOutlineOutlinedIcon from "@mui/icons-material/ChatBubbleOutlineOutlined"; import ChatBubbleOutlineOutlinedIcon from "@mui/icons-material/ChatBubbleOutlineOutlined";
import ExtensionOutlinedIcon from "@mui/icons-material/ExtensionOutlined"; import ExtensionOutlinedIcon from "@mui/icons-material/ExtensionOutlined";
@ -76,7 +77,7 @@ class NodeAbstractWidget extends React.Component<
> >
<IconContainer <IconContainer
style={{ style={{
borderWidth: "3px", borderWidth: "1px",
borderColor: this.props.color, borderColor: this.props.color,
borderStyle: "solid", borderStyle: "solid",
}} }}
@ -117,7 +118,7 @@ class NodeAbstractWidget extends React.Component<
> >
<IconContainer <IconContainer
style={{ style={{
borderWidth: "3px", borderWidth: "1px",
borderColor: this.props.color, borderColor: this.props.color,
borderStyle: "solid", borderStyle: "solid",
}} }}
@ -263,12 +264,12 @@ class NodeWidget extends React.Component<
this.props.node.isSelected() ? "selected" : "", this.props.node.isSelected() ? "selected" : "",
)} )}
style={{ style={{
border: `6px solid ${this.config.color}`, border: `1px solid ${this.config.color}`,
}} }}
> >
{this.props.node.starts_conversation ? ( {this.props.node.starts_conversation ? (
<div className="start-point-container"> <div className="start-point-container">
<div className="start-point" /> <PlayArrowRoundedIcon className="start-point" />
</div> </div>
) : null} ) : null}
<div <div

View File

@ -21,6 +21,7 @@ import { Progress } from "@/app-components/displays/Progress";
import { useLogout } from "@/hooks/entities/auth-hooks"; import { useLogout } from "@/hooks/entities/auth-hooks";
import { useApiClient } from "@/hooks/useApiClient"; import { useApiClient } from "@/hooks/useApiClient";
import { CURRENT_USER_KEY, PUBLIC_PATHS } from "@/hooks/useAuth"; import { CURRENT_USER_KEY, PUBLIC_PATHS } from "@/hooks/useAuth";
import { useSubscribeBroadcastChannel } from "@/hooks/useSubscribeBroadcastChannel";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { RouterType } from "@/services/types"; import { RouterType } from "@/services/types";
import { IUser } from "@/types/user.types"; import { IUser } from "@/types/user.types";
@ -100,6 +101,14 @@ export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => {
}; };
const isAuthenticated = !!user; const isAuthenticated = !!user;
useSubscribeBroadcastChannel("login", () => {
router.reload();
});
useSubscribeBroadcastChannel("logout", () => {
router.reload();
});
useEffect(() => { useEffect(() => {
const search = location.search; const search = location.search;

View File

@ -0,0 +1,115 @@
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import {
createContext,
FC,
ReactNode,
useContext,
useEffect,
useRef,
} from "react";
export enum EBCEvent {
LOGIN = "login",
LOGOUT = "logout",
}
type BroadcastChannelMessage = {
event: `${EBCEvent}`;
data?: string | number | boolean | Record<string, unknown> | undefined | null;
};
interface IBroadcastChannelProps {
channelName: string;
children: ReactNode;
}
interface IBroadcastChannelContext {
subscribe: (
event: `${EBCEvent}`,
callback: (message: BroadcastChannelMessage) => void,
) => void;
postMessage: (message: BroadcastChannelMessage) => void;
}
export const BroadcastChannelContext = createContext<
IBroadcastChannelContext | undefined
>(undefined);
export const BroadcastChannelProvider: FC<IBroadcastChannelProps> = ({
children,
channelName,
}) => {
const channelRef = useRef<BroadcastChannel>(
new BroadcastChannel(channelName),
);
const subscribersRef = useRef<
Record<
string,
Array<Parameters<IBroadcastChannelContext["subscribe"]>["1"]>
>
>({});
useEffect(() => {
const handleMessage = ({ data }: MessageEvent<BroadcastChannelMessage>) => {
subscribersRef.current[data.event].forEach((callback) => callback(data));
};
channelRef.current.addEventListener("message", handleMessage);
return () => {
channelRef.current.removeEventListener("message", handleMessage);
channelRef.current.close();
};
}, []);
const subscribe: IBroadcastChannelContext["subscribe"] = (
event,
callback,
) => {
subscribersRef.current[event] ??= [];
subscribersRef.current[event].push(callback);
return () => {
const index = subscribersRef.current[event].indexOf(callback);
if (index !== -1) {
subscribersRef.current[event].splice(index, 1);
}
};
};
const postMessage: IBroadcastChannelContext["postMessage"] = (message) => {
channelRef.current.postMessage(message);
};
return (
<BroadcastChannelContext.Provider
value={{
subscribe,
postMessage,
}}
>
{children}
</BroadcastChannelContext.Provider>
);
};
export const useBroadcastChannel = () => {
const context = useContext(BroadcastChannelContext);
if (context === undefined) {
throw new Error(
"useBroadcastChannel must be used within a BroadcastChannelProvider",
);
}
return context;
};
export default BroadcastChannelProvider;

View File

@ -9,6 +9,7 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { useMutation, useQuery, useQueryClient } from "react-query"; import { useMutation, useQuery, useQueryClient } from "react-query";
import { useBroadcastChannel } from "@/contexts/broadcast-channel.context";
import { EntityType, TMutationOptions } from "@/services/types"; import { EntityType, TMutationOptions } from "@/services/types";
import { ILoginAttributes } from "@/types/auth/login.types"; import { ILoginAttributes } from "@/types/auth/login.types";
import { import {
@ -32,12 +33,17 @@ export const useLogin = (
>, >,
) => { ) => {
const { apiClient } = useApiClient(); const { apiClient } = useApiClient();
const { postMessage } = useBroadcastChannel();
return useMutation({ return useMutation({
...options, ...options,
async mutationFn(credentials) { async mutationFn(credentials) {
return await apiClient.login(credentials); return await apiClient.login(credentials);
}, },
onSuccess: (data, variables, context) => {
options?.onSuccess?.(data, variables, context);
postMessage({ event: "login" });
},
}); });
}; };
@ -58,6 +64,7 @@ export const useLogout = (
const { logoutRedirection } = useLogoutRedirection(); const { logoutRedirection } = useLogoutRedirection();
const { toast } = useToast(); const { toast } = useToast();
const { t } = useTranslate(); const { t } = useTranslate();
const { postMessage } = useBroadcastChannel();
return useMutation({ return useMutation({
...options, ...options,
@ -68,6 +75,7 @@ export const useLogout = (
}, },
onSuccess: async () => { onSuccess: async () => {
queryClient.removeQueries([CURRENT_USER_KEY]); queryClient.removeQueries([CURRENT_USER_KEY]);
postMessage({ event: "logout" });
await logoutRedirection(); await logoutRedirection();
toast.success(t("message.logout_success")); toast.success(t("message.logout_success"));
}, },

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import { useEffect } from "react";
import { useBroadcastChannel } from "@/contexts/broadcast-channel.context";
export const useSubscribeBroadcastChannel: ReturnType<
typeof useBroadcastChannel
>["subscribe"] = (...props) => {
const { subscribe } = useBroadcastChannel();
useEffect(() => {
subscribe(...props);
}, [subscribe, ...props]);
};

View File

@ -19,6 +19,7 @@ import { ReactQueryDevtools } from "react-query/devtools";
import { SnackbarCloseButton } from "@/app-components/displays/Toast/CloseButton"; import { SnackbarCloseButton } from "@/app-components/displays/Toast/CloseButton";
import { ApiClientProvider } from "@/contexts/apiClient.context"; import { ApiClientProvider } from "@/contexts/apiClient.context";
import { AuthProvider } from "@/contexts/auth.context"; import { AuthProvider } from "@/contexts/auth.context";
import BroadcastChannelProvider from "@/contexts/broadcast-channel.context";
import { ConfigProvider } from "@/contexts/config.context"; import { ConfigProvider } from "@/contexts/config.context";
import { DialogsProvider } from "@/contexts/dialogs.context"; import { DialogsProvider } from "@/contexts/dialogs.context";
import { PermissionProvider } from "@/contexts/permission.context"; import { PermissionProvider } from "@/contexts/permission.context";
@ -85,15 +86,17 @@ const App = ({ Component, pageProps }: TAppPropsWithLayout) => {
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<CssBaseline /> <CssBaseline />
<ApiClientProvider> <ApiClientProvider>
<AuthProvider> <BroadcastChannelProvider channelName="main-channel">
<PermissionProvider> <AuthProvider>
<SettingsProvider> <PermissionProvider>
<SocketProvider> <SettingsProvider>
{getLayout(<Component {...pageProps} />)} <SocketProvider>
</SocketProvider> {getLayout(<Component {...pageProps} />)}
</SettingsProvider> </SocketProvider>
</PermissionProvider> </SettingsProvider>
</AuthProvider> </PermissionProvider>
</AuthProvider>
</BroadcastChannelProvider>
</ApiClientProvider> </ApiClientProvider>
<ReactQueryDevtools initialIsOpen={false} /> <ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider> </QueryClientProvider>

View File

@ -18,20 +18,14 @@
.diagram-container { .diagram-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
background: #e8eff2;
background-image: linear-gradient(to right, #fff9 1px, transparent 1px),
linear-gradient(to bottom, #fff9 1px, transparent 1px);
background-size: 20px 20px;
background-position: -1px -1px;
background-attachment: fixed;
z-index: 2; z-index: 2;
} }
.start-point-container { .start-point-container {
top: -11px; top: -11px;
left: -11px; left: -11px;
width: 22px; width: 20px;
height: 22px; height: 20px;
transform: scale(140%); transform: scale(140%);
border: 1px solid #fff; border: 1px solid #fff;
position: absolute; position: absolute;
@ -40,12 +34,12 @@
} }
.start-point { .start-point {
margin: 5px 7px; color: #FFF;
width: 0; position: absolute;
height: 0; top: 50%;
border-top: 5px solid transparent; left: 50%;
border-bottom: 5px solid transparent; transform: translate(-50%, -50%);
border-left: 9px solid #fff; font-size: 18px;
} }
.node { .node {
@ -58,7 +52,7 @@
z-index: -1; z-index: -1;
} }
.node:has(.selected) { .node:has(.selected) {
outline: 6px solid #1dc7fc; outline: 2px solid #1dc7fc;
z-index: 0; z-index: 0;
cursor: grab; cursor: grab;
transform: scale(1.02); transform: scale(1.02);
@ -76,7 +70,8 @@
min-height: 130px; min-height: 130px;
background-color: #fff; background-color: #fff;
padding: 0px; padding: 0px;
border-radius: 17.5px; border-radius: 12px;
box-shadow: 0 0 8px #c4c4c4;
} }
.custom-node-header { .custom-node-header {
@ -116,7 +111,7 @@
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
gap: 15px; gap: 15px;
padding: 20px 24px 24px; padding: 16px 28px;
position: relative; position: relative;
} }
@ -127,7 +122,7 @@
justify-items: flex-start; justify-items: flex-start;
align-items: center; align-items: center;
gap: 8px; gap: 8px;
border-radius: 10px 10px 0 0px; border-radius: 12px 12px 0 0;
width: auto; width: auto;
margin-top: -1px; margin-top: -1px;
margin-left: -1px; margin-left: -1px;
@ -186,6 +181,9 @@
.circle-porter { .circle-porter {
top: 50%; top: 50%;
margin-top: 5px; margin-top: 5px;
border-radius: 100%;
box-shadow: 0 0 8px #0003;
transition: all .4s ease 0s;
} }
.circle-out-porters { .circle-out-porters {
position: absolute; position: absolute;
@ -196,9 +194,20 @@
.circle-porter-in { .circle-porter-in {
position: absolute; position: absolute;
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%) scale(.75);
left: -12px; left: -12px;
} }
.circle-porter-out { .circle-porter-out {
right: -30px; transform: scale(.75);
right: -12px;
}
.circle-porter-out:hover {
cursor: grab;
transform: scale(1.1);
}
.circle-porter-in:hover {
cursor: grab;
transform: translateY(-50%) scale(1.1);
} }

View File

@ -6,24 +6,46 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { IAttachment } from "@/types/attachment.types"; import { IAttachment } from "@/types/attachment.types";
import { FileType, TAttachmentForeignKey } from "@/types/message.types"; import { FileType, TAttachmentForeignKey } from "@/types/message.types";
import { buildURL } from "./URL"; import { buildURL } from "./URL";
export const MIME_TYPES = { export const MIME_TYPES = {
images: ["image/jpeg", "image/png", "image/gif", "image/webp"], images: ["image/jpeg", "image/png", "image/webp", "image/bmp"],
videos: ["video/mp4", "video/webm", "video/ogg"], videos: [
audios: ["audio/mpeg", "audio/ogg", "audio/wav"], "video/mp4",
"video/webm",
"video/ogg",
"video/quicktime", // common in apple devices
"video/x-msvideo", // AVI
"video/x-matroska", // MKV
],
audios: [
"audio/mpeg", // MP3
"audio/mp3", // Explicit MP3 type
"audio/ogg",
"audio/wav",
"audio/aac", // common in apple devices
"audio/x-wav",
],
documents: [ documents: [
"application/pdf", "application/pdf",
"application/msword", "application/msword", // older ms Word format
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", // newer ms word format
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel", "application/vnd.ms-excel", // older excel format
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // newer excel format
"application/vnd.ms-powerpoint", "application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.openxmlformats-officedocument.presentationml.presentation",
"text/plain",
"application/rtf",
"application/epub", // do we want to support epub?
"application/x-7z-compressed", // do we want to support 7z?
"application/zip", // do we want to support zip?
"application/x-rar-compressed", // do we want to support winrar?
"application/json",
"text/csv",
], ],
}; };

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "hexabot", "name": "hexabot",
"version": "2.2.2", "version": "2.2.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "hexabot", "name": "hexabot",
"version": "2.2.2", "version": "2.2.3",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"workspaces": [ "workspaces": [
"frontend", "frontend",

View File

@ -3,5 +3,5 @@
right: 25px !important; right: 25px !important;
bottom: 25px !important; bottom: 25px !important;
z-index: 999 !important; z-index: 999 !important;
box-shadow: 0 0 8px #0003 !important; box-shadow: 0 0 8px #c4c4c4 !important;
} }

View File

@ -1,15 +1,17 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { PropsWithChildren } from "react"; import { PropsWithChildren } from "react";
import Launcher from "./components/Launcher"; import Launcher from "./components/Launcher";
import UserSubscription from "./components/UserSubscription"; import UserSubscription from "./components/UserSubscription";
import BroadcastChannelProvider from "./providers/BroadcastChannelProvider";
import ChatProvider from "./providers/ChatProvider"; import ChatProvider from "./providers/ChatProvider";
import { ColorProvider } from "./providers/ColorProvider"; import { ColorProvider } from "./providers/ColorProvider";
import { ConfigProvider } from "./providers/ConfigProvider"; import { ConfigProvider } from "./providers/ConfigProvider";
@ -41,17 +43,19 @@ function UiChatWidget({
<SocketProvider> <SocketProvider>
<SettingsProvider> <SettingsProvider>
<ColorProvider> <ColorProvider>
<WidgetProvider defaultScreen="chat"> <BroadcastChannelProvider channelName="main-channel">
<ChatProvider <WidgetProvider defaultScreen="chat">
defaultConnectionState={ConnectionState.connected} <ChatProvider
> defaultConnectionState={ConnectionState.connected}
<Launcher >
CustomHeader={CustomHeader} <Launcher
CustomAvatar={CustomAvatar} CustomHeader={CustomHeader}
PreChat={UserSubscription} CustomAvatar={CustomAvatar}
/> PreChat={UserSubscription}
</ChatProvider> />
</WidgetProvider> </ChatProvider>
</WidgetProvider>
</BroadcastChannelProvider>
</ColorProvider> </ColorProvider>
</SettingsProvider> </SettingsProvider>
</SocketProvider> </SocketProvider>

View File

@ -1,14 +1,15 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import React, { ChangeEvent } from "react"; import React, { ChangeEvent, useMemo } from "react";
import { useChat } from "../../providers/ChatProvider"; import { useChat } from "../../providers/ChatProvider";
import { MIME_TYPES } from "../../utils/attachment";
import FileInputIcon from "../icons/FileInputIcon"; import FileInputIcon from "../icons/FileInputIcon";
import "./FileButton.scss"; import "./FileButton.scss";
@ -23,12 +24,17 @@ const FileButton: React.FC = () => {
setFile && setFile(e.target.files[0]); setFile && setFile(e.target.files[0]);
} }
}; };
const acceptedMimeTypes = useMemo(
() => Object.values(MIME_TYPES).flat().join(","),
[],
);
return ( return (
<div className="sc-user-input--file-wrapper"> <div className="sc-user-input--file-wrapper">
<button className="sc-user-input--file-icon-wrapper" type="button"> <button className="sc-user-input--file-icon-wrapper" type="button">
<FileInputIcon /> <FileInputIcon />
<input <input
accept={acceptedMimeTypes}
type="file" type="file"
id="file-input" id="file-input"
onChange={handleChange} onChange={handleChange}

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import { useEffect } from "react";
import { useBroadcastChannel } from "../providers/BroadcastChannelProvider";
export const useSubscribeBroadcastChannel: ReturnType<
typeof useBroadcastChannel
>["subscribe"] = (...props) => {
const { subscribe } = useBroadcastChannel();
useEffect(() => {
subscribe(...props);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [subscribe, ...props]);
};

View File

@ -0,0 +1,115 @@
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import {
createContext,
FC,
ReactNode,
useContext,
useEffect,
useRef,
} from "react";
export enum EBCEvent {
LOGOUT = "logout",
}
type BroadcastChannelMessage = {
event: `${EBCEvent}`;
data?: string | number | boolean | Record<string, unknown> | undefined | null;
};
interface IBroadcastChannelProps {
channelName: string;
children: ReactNode;
}
interface IBroadcastChannelContext {
subscribe: (
event: `${EBCEvent}`,
callback: (message: BroadcastChannelMessage) => void,
) => void;
postMessage: (message: BroadcastChannelMessage) => void;
}
export const BroadcastChannelContext = createContext<
IBroadcastChannelContext | undefined
>(undefined);
export const BroadcastChannelProvider: FC<IBroadcastChannelProps> = ({
children,
channelName,
}) => {
const channelRef = useRef<BroadcastChannel>(
new BroadcastChannel(channelName),
);
const subscribersRef = useRef<
Record<
string,
Array<Parameters<IBroadcastChannelContext["subscribe"]>["1"]>
>
>({});
useEffect(() => {
const handleMessage = ({ data }: MessageEvent<BroadcastChannelMessage>) => {
subscribersRef.current[data.event].forEach((callback) => callback(data));
};
channelRef.current.addEventListener("message", handleMessage);
return () => {
channelRef.current.removeEventListener("message", handleMessage);
// eslint-disable-next-line react-hooks/exhaustive-deps
channelRef.current.close();
};
}, []);
const subscribe: IBroadcastChannelContext["subscribe"] = (
event,
callback,
) => {
subscribersRef.current[event] ??= [];
subscribersRef.current[event].push(callback);
return () => {
const index = subscribersRef.current[event].indexOf(callback);
if (index !== -1) {
subscribersRef.current[event].splice(index, 1);
}
};
};
const postMessage: IBroadcastChannelContext["postMessage"] = (message) => {
channelRef.current.postMessage(message);
};
return (
<BroadcastChannelContext.Provider
value={{
subscribe,
postMessage,
}}
>
{children}
</BroadcastChannelContext.Provider>
);
};
export const useBroadcastChannel = () => {
const context = useContext(BroadcastChannelContext);
if (!context) {
throw new Error(
"useBroadcastChannel must be used within a BroadcastChannelProvider",
);
}
return context;
};
export default BroadcastChannelProvider;

View File

@ -6,7 +6,6 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import React, { import React, {
createContext, createContext,
ReactNode, ReactNode,
@ -17,6 +16,7 @@ import React, {
useState, useState,
} from "react"; } from "react";
import { useSubscribeBroadcastChannel } from "../hooks/useSubscribeBroadcastChannel";
import { StdEventType } from "../types/chat-io-messages.types"; import { StdEventType } from "../types/chat-io-messages.types";
import { import {
Direction, Direction,
@ -385,6 +385,10 @@ const ChatProvider: React.FC<{
} }
}, [syncState, isOpen]); }, [syncState, isOpen]);
useSubscribeBroadcastChannel("logout", () => {
socketCtx.socket.disconnect();
});
useEffect(() => { useEffect(() => {
if (screen === "chat" && connectionState === ConnectionState.connected) { if (screen === "chat" && connectionState === ConnectionState.connected) {
handleSubscription(); handleSubscription();

View File

@ -1,11 +1,12 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { FileType } from "../types/message.types"; import { FileType } from "../types/message.types";
export function getFileType(mimeType: string): FileType { export function getFileType(mimeType: string): FileType {
@ -19,3 +20,41 @@ export function getFileType(mimeType: string): FileType {
return FileType.file; return FileType.file;
} }
} }
export const MIME_TYPES = {
images: ["image/jpeg", "image/png", "image/webp", "image/bmp"],
videos: [
"video/mp4",
"video/webm",
"video/ogg",
"video/quicktime", // common in apple devices
"video/x-msvideo", // AVI
"video/x-matroska", // MKV
],
audios: [
"audio/mpeg", // MP3
"audio/mp3", // Explicit MP3 type
"audio/ogg",
"audio/wav",
"audio/aac", // common in apple devices
"audio/x-wav",
],
documents: [
"application/pdf",
"application/msword", // older ms Word format
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", // newer ms word format
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-excel", // older excel format
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // newer excel format
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"text/plain",
"application/rtf",
"application/epub+zip",
"application/x-7z-compressed",
"application/zip",
"application/x-rar-compressed",
"application/json",
"text/csv",
],
};