Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 2b4221a

Browse files
authored
Merge pull request #692 from openchatai/falta/widget-fix
falta/widget fix
2 parents 8844c1f + 251834b commit 2b4221a

File tree

7 files changed

+101
-84
lines changed

7 files changed

+101
-84
lines changed

copilot-widget/lib/components/Avatar.tsx

Whitespace-only changes.

copilot-widget/lib/contexts/messageHandler.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ export type State = {
3838
};
3939

4040
type Listener<T = State> = (value: T) => void;
41+
4142
type UpdaterFunction<T = State> = (oldValue: T) => T;
43+
44+
// sometimes the im_end message is not received from the bot, so we have to set a timeout to end the current message
45+
// this is the timeout
46+
let timeout: NodeJS.Timeout | null = null;
47+
const timeoutDuration = 1000 * 3;
48+
4249
export class ChatController {
4350
sessionId: string | null = null;
44-
// sometimes the im_end message is not received from the bot, so we have to set a timeout to end the current message
45-
// this is the timeout id
46-
private timeout: NodeJS.Timeout | null = null;
47-
private timeoutDuration = 1000 * 3;
4851
listeners = new Set<Listener>();
4952
components: ComponentRegistery | undefined;
5053

@@ -367,12 +370,17 @@ export class ChatController {
367370
};
368371

369372
private startTimeout = (callback: () => void) => {
370-
if (this.timeout) {
371-
clearTimeout(this.timeout);
372-
}
373-
this.timeout = setTimeout(() => {
374-
this.timeout = null;
373+
this.clearTimeout();
374+
timeout = setTimeout(() => {
375375
callback();
376-
}, this.timeoutDuration);
376+
timeout = null;
377+
}, timeoutDuration);
378+
};
379+
380+
private clearTimeout = () => {
381+
if (timeout) {
382+
clearTimeout(timeout);
383+
timeout = null;
384+
}
377385
};
378386
}

copilot-widget/lib/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ export { CopilotWidget } from "./CopilotWidget";
33
export type { ComponentType } from "./contexts/componentRegistery";
44
export type { Options } from "./types/options";
55
export type { ComponentProps } from "./contexts/componentRegistery";
6+
export {
7+
useChatState,
8+
useChatLoading,
9+
useSendMessage,
10+
} from "./contexts/statefulMessageHandler";
11+
export { useConfigData } from "./contexts/ConfigData";
12+
export { useWidgetState } from "./contexts/WidgetState";
13+
export { useSocket } from "./contexts/SocketProvider";
14+
export { useLang } from "./contexts/LocalesProvider";

copilot-widget/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openchatai/copilot-widget",
33
"private": false,
4-
"version": "2.8.3",
4+
"version": "2.8.4",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"@hookform/resolvers": "^3.3.1",
1515
"@kbox-labs/react-echarts": "^1.0.3",
16-
"@openchatai/copilot-widget": "^2.8.3",
16+
"@openchatai/copilot-widget": "^2.8.4",
1717
"@radix-ui/react-accordion": "^1.1.2",
1818
"@radix-ui/react-alert-dialog": "^1.0.5",
1919
"@radix-ui/react-avatar": "^1.0.4",

dashboard/pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashboard/public/pilot.js

Lines changed: 68 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)