Skip to content

Commit

Permalink
Merge pull request #692 from openchatai/falta/widget-fix
Browse files Browse the repository at this point in the history
falta/widget fix
  • Loading branch information
faltawy authored Mar 12, 2024
2 parents 8844c1f + 251834b commit 2b4221a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 84 deletions.
Empty file.
28 changes: 18 additions & 10 deletions copilot-widget/lib/contexts/messageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ export type State = {
};

type Listener<T = State> = (value: T) => void;

type UpdaterFunction<T = State> = (oldValue: T) => T;

// sometimes the im_end message is not received from the bot, so we have to set a timeout to end the current message
// this is the timeout
let timeout: NodeJS.Timeout | null = null;
const timeoutDuration = 1000 * 3;

export class ChatController {
sessionId: string | null = null;
// sometimes the im_end message is not received from the bot, so we have to set a timeout to end the current message
// this is the timeout id
private timeout: NodeJS.Timeout | null = null;
private timeoutDuration = 1000 * 3;
listeners = new Set<Listener>();
components: ComponentRegistery | undefined;

Expand Down Expand Up @@ -367,12 +370,17 @@ export class ChatController {
};

private startTimeout = (callback: () => void) => {
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
this.timeout = null;
this.clearTimeout();
timeout = setTimeout(() => {
callback();
}, this.timeoutDuration);
timeout = null;
}, timeoutDuration);
};

private clearTimeout = () => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
};
}
9 changes: 9 additions & 0 deletions copilot-widget/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ export { CopilotWidget } from "./CopilotWidget";
export type { ComponentType } from "./contexts/componentRegistery";
export type { Options } from "./types/options";
export type { ComponentProps } from "./contexts/componentRegistery";
export {
useChatState,
useChatLoading,
useSendMessage,
} from "./contexts/statefulMessageHandler";
export { useConfigData } from "./contexts/ConfigData";
export { useWidgetState } from "./contexts/WidgetState";
export { useSocket } from "./contexts/SocketProvider";
export { useLang } from "./contexts/LocalesProvider";
2 changes: 1 addition & 1 deletion copilot-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openchatai/copilot-widget",
"private": false,
"version": "2.8.3",
"version": "2.8.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@hookform/resolvers": "^3.3.1",
"@kbox-labs/react-echarts": "^1.0.3",
"@openchatai/copilot-widget": "^2.8.3",
"@openchatai/copilot-widget": "^2.8.4",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
Expand Down
8 changes: 4 additions & 4 deletions dashboard/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 68 additions & 68 deletions dashboard/public/pilot.js

Large diffs are not rendered by default.

0 comments on commit 2b4221a

Please sign in to comment.