Skip to content

Commit c24fd10

Browse files
bug: fix file loading 500 error when write is in progress (#2037)
1 parent 82fa032 commit c24fd10

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

ui/user/src/lib/components/navbar/Clone.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
async function copy() {
1616
dialog?.close();
1717
const newProject = await ChatService.copyProject(project.assistantID, project.id);
18-
console.log('old', project.id, 'new', newProject.id);
1918
await goto(`/o/${newProject.id}`);
2019
}
2120
</script>

ui/user/src/lib/services/chat/messages.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ function toMessageFromInput(s: string): string {
1717
return s;
1818
}
1919

20-
function setFileContent(items: EditorItem[], name: string, content: string, full: boolean = false) {
21-
const existing = items.find((f) => f.id === name);
20+
function setFileContent(
21+
items: EditorItem[],
22+
name: string,
23+
content: string,
24+
full: boolean = false,
25+
opts: {
26+
threadID?: string;
27+
taskID?: string;
28+
runID?: string;
29+
} = {}
30+
) {
31+
const id = opts.runID ? `${opts.taskID}/${opts.runID}/${name}` : `${opts.threadID}/${name}`;
32+
const existing = items.find((f) => f.id === id);
2233
if (existing && existing.file) {
2334
if (full) {
2435
existing.file.contents = content;
@@ -29,7 +40,7 @@ function setFileContent(items: EditorItem[], name: string, content: string, full
2940
}
3041
} else {
3142
items.push({
32-
id: name,
43+
id: id,
3344
name: name,
3445
file: {
3546
contents: content,
@@ -107,7 +118,16 @@ function getFilenameAndContent(content: string) {
107118
};
108119
}
109120

110-
function reformatWriteMessage(items: EditorItem[], msg: Message, last: boolean) {
121+
function reformatWriteMessage(
122+
items: EditorItem[],
123+
msg: Message,
124+
last: boolean,
125+
opts: {
126+
threadID?: string;
127+
taskID?: string;
128+
runID?: string;
129+
} = {}
130+
) {
111131
msg.icon = 'Pencil';
112132
msg.done = !last || msg.toolCall !== undefined;
113133
msg.sourceName = msg.done ? 'Wrote to Workspace' : 'Writing to Workspace';
@@ -129,17 +149,25 @@ function reformatWriteMessage(items: EditorItem[], msg: Message, last: boolean)
129149
}
130150

131151
if (last && msg.file?.filename && msg.file?.content) {
132-
setFileContent(items, msg.file.filename, msg.file.content, msg.toolCall !== undefined);
152+
setFileContent(items, msg.file.filename, msg.file.content, msg.toolCall !== undefined, opts);
133153
}
134154
}
135155

136-
export function buildMessagesFromProgress(items: EditorItem[], progresses: Progress[]): Messages {
156+
export function buildMessagesFromProgress(
157+
items: EditorItem[],
158+
progresses: Progress[],
159+
opts: {
160+
threadID?: string;
161+
taskID?: string;
162+
runID?: string;
163+
}
164+
): Messages {
137165
const messages = toMessages(progresses);
138166

139167
// Post Process for much more better-ness
140168
messages.messages.forEach((item, i) => {
141169
if (item.tool && item.sourceName == 'workspace_write') {
142-
reformatWriteMessage(items, item, i == messages.messages.length - 1);
170+
reformatWriteMessage(items, item, i == messages.messages.length - 1, opts);
143171
return;
144172
} else if (item.sent) {
145173
reformatInputMessage(item);

ui/user/src/lib/services/chat/thread.svelte.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,27 @@ export class Thread {
154154
}
155155

156156
for (const [stepID, msgs] of newMessages) {
157-
this.onStepMessages(stepID, buildMessagesFromProgress(this.#items, msgs));
157+
this.onStepMessages(
158+
stepID,
159+
buildMessagesFromProgress(this.#items, msgs, {
160+
taskID: this.#task?.id,
161+
runID: this.#runID,
162+
threadID: this.threadID
163+
})
164+
);
158165
}
159166
}
160167

161168
#onProgress(progress: Progress) {
162169
this.#progresses.push(progress);
163170
if (this.replayComplete) {
164-
this.onMessages(buildMessagesFromProgress(this.#items, this.#progresses));
171+
this.onMessages(
172+
buildMessagesFromProgress(this.#items, this.#progresses, {
173+
taskID: this.#task?.id,
174+
runID: this.#runID,
175+
threadID: this.threadID
176+
})
177+
);
165178
this.#handleSteps();
166179
}
167180
}

ui/user/src/lib/services/editor/index.svelte.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ async function loadFile(
118118
let fileID = file;
119119
if (opts?.taskID && opts?.runID) {
120120
fileID = `${opts.taskID}/${opts.runID}/${file}`;
121+
} else if (opts?.threadID) {
122+
fileID = `${opts.threadID}/${file}`;
121123
}
122124
const targetFile: EditorItem = {
123125
id: fileID,

0 commit comments

Comments
 (0)