Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Merge pull request #691 from openchatai/falta/fix-widget
Browse files Browse the repository at this point in the history
Refactor timeout handling in ChatController
  • Loading branch information
faltawy authored Mar 12, 2024
2 parents ce4c47f + bca8030 commit 8844c1f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion copilot-widget/.release-it.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"github": {
"requireBranch": "main",
"release": true,
"release": false,
"push": true,
"commitMessage": "chore: release ${version}",
"hooks": {
Expand Down
16 changes: 10 additions & 6 deletions copilot-widget/lib/contexts/messageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ChatController {
// 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; // 10 seconds
private timeoutDuration = 1000 * 3;
listeners = new Set<Listener>();
components: ComponentRegistery | undefined;

Expand Down Expand Up @@ -266,15 +266,16 @@ export class ChatController {
}

const handle = (content: string) => {
if (content === "|im_end|") {
this.settle();
return;
}

if (this.select("conversationInfo")) {
this.setValueImmer((d) => {
d.conversationInfo = null;
});
}
if (content === "|im_end|") {
this.settle();
return;
}

this.startTimeout(() => {
this.settle();
Expand Down Expand Up @@ -366,9 +367,12 @@ export class ChatController {
};

private startTimeout = (callback: () => void) => {
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
callback();
this.timeout = null;
callback();
}, this.timeoutDuration);
};
}
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.2",
"version": "2.8.3",
"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.2",
"@openchatai/copilot-widget": "^2.8.3",
"@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.

2 changes: 1 addition & 1 deletion dashboard/public/pilot.js

Large diffs are not rendered by default.

0 comments on commit 8844c1f

Please sign in to comment.