Skip to content

Commit 84e344d

Browse files
committed
Remove redundant comments and add URL tracking for chat responses
1 parent 67c71bc commit 84e344d

23 files changed

Lines changed: 72 additions & 57 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const CONFIG = {
22
// WebSocket configuration
3-
RECONNECT_DELAY: 5000 // 5 seconds
3+
RECONNECT_DELAY: 5000
44
}

‎apps/browser/src/background/keep-alive.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const setup_keep_alive = () => {
66
try {
77
chrome.alarms.create('keep-alive', {
88
when: Date.now() + 1000 * 30
9-
}) // 30 seconds interval
9+
})
1010
} catch (error) {
1111
console.error('Error creating KeepAlive alarm:', error)
1212
}

‎apps/browser/src/background/message-handler.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface ChatQueueItem {
1212
timeout_id?: number
1313
}
1414

15-
// Global queue of chat initialization requests
1615
const chat_queue: ChatQueueItem[] = []
1716
let is_processing = false
1817

@@ -112,7 +111,6 @@ const process_next_chat = async () => {
112111
browser.tabs.create(create_tab_options)
113112
}
114113

115-
// Set a timeout to automatically proceed if no confirmation is received
116114
current_queue_item.timeout_id = setTimeout(() => {
117115
console.warn(
118116
`Chat initialization timeout for ${current_chat_message.url}. Moving to next chat.`
@@ -157,7 +155,8 @@ export const setup_message_listeners = () => {
157155
action: 'apply-chat-response',
158156
client_id: message.client_id,
159157
raw_instructions: message.raw_instructions,
160-
edit_format: message.edit_format
158+
edit_format: message.edit_format,
159+
url: message.url
161160
} as ApplyChatResponseMessage)
162161
}
163162
}

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/ai-studio.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export const ai_studio: Chatbot = {
456456

457457
const open_panel = async () => {
458458
if (window.innerWidth <= 960) {
459-
if (document.querySelector('ms-right-side-panel > div')) return // Already opened
459+
if (document.querySelector('ms-right-side-panel > div')) return
460460

461461
const tune_button = document.querySelector(
462462
'button.runsettings-toggle-button'
@@ -475,7 +475,8 @@ const open_panel = async () => {
475475

476476
const close_panel = async () => {
477477
if (window.innerWidth <= 960) {
478-
if (!document.querySelector('ms-right-side-panel > div')) return // Already closed
478+
if (!document.querySelector('ms-right-side-panel > div')) return
479+
479480
const close_button = document.querySelector(
480481
'ms-run-settings button[iconname="close"]'
481482
) as HTMLButtonElement

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/deepseek.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const deepseek: Chatbot = {
3636
return
3737
}
3838

39-
// Uncheck deep think
4039
const deep_think_button_style = window.getComputedStyle(deep_think_button)
4140
if (
4241
deep_think_button_style.getPropertyValue('color') != 'rgb(15, 17, 21)' &&
@@ -45,7 +44,6 @@ export const deepseek: Chatbot = {
4544
deep_think_button.click()
4645
}
4746

48-
// Uncheck search
4947
const search_button_style = window.getComputedStyle(search_button)
5048
if (
5149
search_button_style.getPropertyValue('color') != 'rgb(15, 17, 21)' &&

‎apps/browser/src/content-scripts/send-prompt-content-script/send-prompt-content-script.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ const initialize_chat = async (params: { message: string; chat: Chat }) => {
159159
})
160160
}
161161

162-
// User may send by pressing enter
163162
await new Promise<void>((resolve) => {
164163
const handle_key_press = (e: KeyboardEvent) => {
165164
if (e.key == 'Enter') {
@@ -170,7 +169,6 @@ const initialize_chat = async (params: { message: string; chat: Chat }) => {
170169
document.addEventListener('keydown', handle_key_press)
171170
setTimeout(resolve, 2000)
172171
})
173-
// Process next chat from the queue
174172
browser.runtime.sendMessage<Message>({
175173
action: 'chat-initialized'
176174
})
@@ -180,14 +178,12 @@ const main = async () => {
180178
const session_data_key = 'cwc-session-data'
181179

182180
if (is_cwc_hash) {
183-
// Remove the hash from the URL to avoid reloading the content script if the page is refreshed
184181
history.replaceState(
185182
null,
186183
'',
187184
window.location.pathname + window.location.search
188185
)
189186

190-
// Get the message using the batch ID from the hash
191187
const storage_key = `chat-init:${batch_id}`
192188
const storage = await browser.storage.local.get(storage_key)
193189
const stored_data = storage[storage_key] as {
@@ -212,7 +208,6 @@ const main = async () => {
212208
return
213209
}
214210

215-
// Now directly use the current_chat instead of searching for it
216211
const message_text = stored_data.text
217212
const current_chat = stored_data.current_chat
218213

@@ -230,7 +225,6 @@ const main = async () => {
230225
chat: current_chat
231226
})
232227

233-
// Clean up the storage entry after using it
234228
await browser.storage.local.remove(storage_key)
235229

236230
if (

‎apps/browser/src/content-scripts/send-prompt-content-script/utils/add-apply-response-button.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export function add_apply_response_button(params: {
5151
action: 'apply-chat-response',
5252
client_id: params.client_id,
5353
raw_instructions: params.raw_instructions,
54-
edit_format: params.edit_format
54+
edit_format: params.edit_format,
55+
url: window.location.href
5556
})
5657
})
5758

‎apps/browser/src/types/messages.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type ApplyChatResponseMessage = {
77
client_id: number
88
raw_instructions?: string
99
edit_format?: string
10+
url?: string
1011
}
1112

1213
export type Message = ChatInitializedMessage | ApplyChatResponseMessage

‎apps/editor/src/commands/apply-chat-response-command/apply-chat-response-command.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export const apply_chat_response_command = (params: {
7979
const new_item: ResponseHistoryItem = {
8080
response: chat_response,
8181
raw_instructions: args?.raw_instructions,
82-
created_at: Date.now()
82+
created_at: Date.now(),
83+
url: args?.url
8384
}
8485

8586
history.push(new_item)
@@ -316,7 +317,8 @@ export const apply_chat_response_command = (params: {
316317
created_at: created_at_for_preview,
317318
lines_added: total_lines_added,
318319
lines_removed: total_lines_removed,
319-
files: files_for_history
320+
files: files_for_history,
321+
url: args?.url
320322
}
321323

322324
history.push(new_item)
@@ -339,7 +341,8 @@ export const apply_chat_response_command = (params: {
339341
context: params.context,
340342
original_editor_state: args?.original_editor_state,
341343
raw_instructions: args?.raw_instructions,
342-
created_at: created_at_for_preview
344+
created_at: created_at_for_preview,
345+
url: args?.url
343346
})
344347

345348
if (changes_accepted) {

‎apps/editor/src/commands/apply-chat-response-command/response-processor.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export type CommandArgs = {
4646
}
4747
files_with_content?: FileInPreview[]
4848
created_at?: number
49+
url?: string
4950
}
5051

5152
export const process_chat_response = async (

0 commit comments

Comments
 (0)