From 97b886abf0ba2ab74deb9a0dff0beca3db00b3a9 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Thu, 12 Dec 2024 03:13:52 +0530 Subject: [PATCH 1/7] fix: added more controlled rate for code streaming --- app/lib/stores/workbench.ts | 17 ++++++++++--- app/utils/sampler.ts | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 app/utils/sampler.ts diff --git a/app/lib/stores/workbench.ts b/app/lib/stores/workbench.ts index 15482c2..0d46057 100644 --- a/app/lib/stores/workbench.ts +++ b/app/lib/stores/workbench.ts @@ -16,6 +16,7 @@ import * as nodePath from 'node:path'; import { extractRelativePath } from '~/utils/diff'; import { description } from '~/lib/persistence'; import Cookies from 'js-cookie'; +import { createSampler } from '~/utils/sampler'; export interface ArtifactState { id: string; @@ -262,9 +263,9 @@ export class WorkbenchStore { this.artifacts.setKey(messageId, { ...artifact, ...state }); } addAction(data: ActionCallbackData) { - this._addAction(data); + // this._addAction(data); - // this.addToExecutionQueue(()=>this._addAction(data)) + this.addToExecutionQueue(() => this._addAction(data)); } async _addAction(data: ActionCallbackData) { const { messageId } = data; @@ -280,7 +281,7 @@ export class WorkbenchStore { runAction(data: ActionCallbackData, isStreaming: boolean = false) { if (isStreaming) { - this._runAction(data, isStreaming); + this.actionStreamSampler(data, isStreaming); } else { this.addToExecutionQueue(() => this._runAction(data, isStreaming)); } @@ -294,6 +295,12 @@ export class WorkbenchStore { unreachable('Artifact not found'); } + const action = artifact.runner.actions.get()[data.actionId]; + + if (!action || action.executed) { + return; + } + if (data.action.type === 'file') { const wc = await webcontainer; const fullPath = nodePath.join(wc.workdir, data.action.filePath); @@ -323,6 +330,10 @@ export class WorkbenchStore { } } + actionStreamSampler = createSampler(async (data: ActionCallbackData, isStreaming: boolean = false) => { + return await this._runAction(data, isStreaming); + }, 100); // TODO: remove this magic number to have it configurable + #getArtifact(id: string) { const artifacts = this.artifacts.get(); return artifacts[id]; diff --git a/app/utils/sampler.ts b/app/utils/sampler.ts new file mode 100644 index 0000000..9639909 --- /dev/null +++ b/app/utils/sampler.ts @@ -0,0 +1,49 @@ +/** + * Creates a function that samples calls at regular intervals and captures trailing calls. + * - Drops calls that occur between sampling intervals + * - Takes one call per sampling interval if available + * - Captures the last call if no call was made during the interval + * + * @param fn The function to sample + * @param sampleInterval How often to sample calls (in ms) + * @returns The sampled function + */ +export function createSampler any>(fn: T, sampleInterval: number): T { + let lastArgs: Parameters | null = null; + let lastTime = 0; + let timeout: NodeJS.Timeout | null = null; + + // Create a function with the same type as the input function + const sampled = function (this: any, ...args: Parameters) { + const now = Date.now(); + lastArgs = args; + + // If we're within the sample interval, just store the args + if (now - lastTime < sampleInterval) { + // Set up trailing call if not already set + if (!timeout) { + timeout = setTimeout( + () => { + timeout = null; + lastTime = Date.now(); + + if (lastArgs) { + fn.apply(this, lastArgs); + lastArgs = null; + } + }, + sampleInterval - (now - lastTime), + ); + } + + return; + } + + // If we're outside the interval, execute immediately + lastTime = now; + fn.apply(this, args); + lastArgs = null; + } as T; + + return sampled; +} From 3bc8c5f85668cc83bbefe5bf251c9a6a2adf9b50 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Fri, 13 Dec 2024 01:23:56 +0530 Subject: [PATCH 2/7] added support for private github repo through github connections --- app/components/settings/connections/ConnectionsTab.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/components/settings/connections/ConnectionsTab.tsx b/app/components/settings/connections/ConnectionsTab.tsx index 32d0fa0..6049482 100644 --- a/app/components/settings/connections/ConnectionsTab.tsx +++ b/app/components/settings/connections/ConnectionsTab.tsx @@ -10,6 +10,7 @@ export default function ConnectionsTab() { Cookies.set('githubUsername', githubUsername); Cookies.set('githubToken', githubToken); toast.success('GitHub credentials saved successfully!'); + Cookies.set('git:github.com', JSON.stringify({ username: githubToken, password: 'x-oauth-basic' })); }; return ( From b0ca49d65ea770065e66508d9bafcec7ab21ddad Mon Sep 17 00:00:00 2001 From: Dlouxgit <470490778@qq.com> Date: Fri, 13 Dec 2024 12:16:57 +0800 Subject: [PATCH 3/7] fix: handle conflicts between input method engine and enter key --- app/components/chat/BaseChat.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index a77932c..3b5c9ad 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -431,7 +431,9 @@ export const BaseChat = React.forwardRef( return; } - handleSendMessage?.(event); + if (!event.nativeEvent.isComposing) { + handleSendMessage?.(event); + } } }} value={input} From 81d2c01442bae9b67e14f2d9883e0e3f3f24c3c9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 14 Dec 2024 07:25:13 +0000 Subject: [PATCH 4/7] chore: update commit hash to 6a5ed21c0fed92a8c842b683bf9a430901e6bb05 --- app/commit.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/commit.json b/app/commit.json index beebd2b..365b4ae 100644 --- a/app/commit.json +++ b/app/commit.json @@ -1 +1 @@ -{ "commit": "55094392cf4c5bc607aff796680ad50236a4cf20" } +{ "commit": "6a5ed21c0fed92a8c842b683bf9a430901e6bb05" } From a71cfba660f04a8440960ab772670b192e2d066f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 14 Dec 2024 07:27:29 +0000 Subject: [PATCH 5/7] chore: update commit hash to 4af18c069f2429ffaf410d92702a1e1294af2628 --- app/commit.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/commit.json b/app/commit.json index 365b4ae..aa11cbf 100644 --- a/app/commit.json +++ b/app/commit.json @@ -1 +1 @@ -{ "commit": "6a5ed21c0fed92a8c842b683bf9a430901e6bb05" } +{ "commit": "4af18c069f2429ffaf410d92702a1e1294af2628" } From 3db40046428f68d6f290523a5e83f9c6bd0fca9c Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sat, 14 Dec 2024 14:15:27 +0530 Subject: [PATCH 6/7] Update BaseChat.tsx --- app/components/chat/BaseChat.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 3b5c9ad..e894de2 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -425,15 +425,16 @@ export const BaseChat = React.forwardRef( } event.preventDefault(); - + if (isStreaming) { handleStop?.(); return; } - - if (!event.nativeEvent.isComposing) { - handleSendMessage?.(event); + // ignore if using input method engine + if (event.nativeEvent.isComposing) { + return } + handleSendMessage?.(event); } }} value={input} From f27f7bba5132346db18e70e514a6a6202d6ab634 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 14 Dec 2024 08:46:42 +0000 Subject: [PATCH 7/7] chore: update commit hash to 4f02887565e13eeaabbfb6f699cbe089e802338f --- app/commit.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/commit.json b/app/commit.json index aa11cbf..4f74a3b 100644 --- a/app/commit.json +++ b/app/commit.json @@ -1 +1 @@ -{ "commit": "4af18c069f2429ffaf410d92702a1e1294af2628" } +{ "commit": "4f02887565e13eeaabbfb6f699cbe089e802338f" }