Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor timeout handling in ChatController #691

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading