Skip to content

Commit faea7c6

Browse files
committed
Add the ability to initialize chats without immediately sending the prompt
1 parent 50350f9 commit faea7c6

23 files changed

Lines changed: 238 additions & 32 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Available in <a href="https://marketplace.visualstudio.com/items?itemName=robert
1515

1616
**The workflow**
1717

18-
Select folders and files you want to attach in message as context, type instructions, and pick your favorite chatbot—to continue in the browser, or call a model provider of choice—to stay in the editor.
18+
Select folders and files for context, type instructions, and pick your favorite chatbot—to continue in the browser, or call a model provider of choice—to stay in the editor.
1919

20-
Once the response is ready, all changes can be applied to the codebase before being reviewed in a transparent and safe way.
20+
Once the response is ready, all changes can be applied to the codebase after you review them in a transparent and safe way.
2121

2222
**Guiding principles**
2323

@@ -60,7 +60,7 @@ Install the Connector browser extension and never copy&paste again.
6060
6161
## <span style="background-color: #fbb100; color: black; padding: 0.2em 0.6em; border-radius: 999px">API Tools</span>
6262

63-
CWC is not limited to chatbot initializations. To use built-in API tools, bring your own keys (BYOK) for any OpenAI-API compatible model provider for usage-based billing.
63+
CWC is not limited to chatbot initializations. To use built-in API tools, bring your own keys (BYOK) for any OpenAI-API compatible model provider.
6464

6565
**🛠️ Edit Context** \
6666
Modify files based on natural language instructions.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ const process_next_chat = async () => {
9696
[`chat-init:${batch_id}`]: {
9797
text: current_queue_item.message.text,
9898
current_chat: current_chat,
99-
client_id: current_queue_item.message.client_id
99+
client_id: current_queue_item.message.client_id,
100+
without_submission: current_queue_item.message.without_submission
100101
}
101102
})
102103

@@ -177,7 +178,8 @@ const handle_initialize_chat_message = async (
177178
action: 'initialize-chats',
178179
text: message.text,
179180
chats: [chat_config],
180-
client_id: message.client_id
181+
client_id: message.client_id,
182+
without_submission: message.without_submission
181183
}
182184

183185
handle_initialize_chats_message(chats_message)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ export const ai_studio: Chatbot = {
365365
top_p_element.value = top_p.toString()
366366
top_p_element.dispatchEvent(new Event('change', { bubbles: true }))
367367
},
368-
enter_message_and_send: async (message: string) => {
368+
enter_message_and_send: async (
369+
message: string,
370+
without_submission?: boolean
371+
) => {
369372
const input_element = document.querySelector(
370373
'textarea'
371374
) as HTMLTextAreaElement
@@ -395,7 +398,11 @@ export const ai_studio: Chatbot = {
395398
}
396399
check()
397400
})
401+
398402
await close_panel()
403+
404+
if (without_submission) return
405+
399406
const send_button = document.querySelector(
400407
'ms-run-button > button'
401408
) as HTMLElement

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/claude.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ export const claude: Chatbot = {
111111
}
112112
}
113113
},
114-
enter_message_and_send: async (message: string) => {
114+
enter_message_and_send: async (
115+
message: string,
116+
without_submission?: boolean
117+
) => {
115118
const input_element = document.querySelector(
116119
'div[contenteditable=true]'
117120
) as HTMLElement
@@ -129,6 +132,9 @@ export const claude: Chatbot = {
129132
input_element.dispatchEvent(new Event('input', { bubbles: true }))
130133
input_element.dispatchEvent(new Event('change', { bubbles: true }))
131134
await new Promise((r) => setTimeout(r, 500))
135+
136+
if (without_submission) return
137+
132138
const submit_button = Array.from(
133139
document.querySelectorAll('fieldset button')
134140
).find((button) =>

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/kimi.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export const kimi: Chatbot = {
2121
check_for_element()
2222
})
2323
},
24-
enter_message_and_send: async (message: string) => {
24+
enter_message_and_send: async (
25+
message: string,
26+
without_submission?: boolean
27+
) => {
2528
const input_element = document.querySelector(
2629
'div[contenteditable=true]'
2730
) as HTMLElement
@@ -43,6 +46,8 @@ export const kimi: Chatbot = {
4346
})
4447
)
4548

49+
if (without_submission) return
50+
4651
await new Promise<void>((resolve) => {
4752
const check_button_state = () => {
4853
const send_button_container = document.querySelector(

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/meta.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export const meta: Chatbot = {
2828
check_for_element()
2929
})
3030
},
31-
enter_message_and_send: async (message: string) => {
31+
enter_message_and_send: async (
32+
message: string,
33+
without_submission?: boolean
34+
) => {
3235
const input_element = document.querySelector(
3336
'div[contenteditable=true]'
3437
) as HTMLElement
@@ -51,6 +54,8 @@ export const meta: Chatbot = {
5154
})
5255
)
5356

57+
if (without_submission) return
58+
5459
try {
5560
await new Promise<void>((resolve, reject) => {
5661
const timeout = 5000 // 5 seconds

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/openrouter.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export const openrouter: Chatbot = {
9393
return
9494
}
9595
const custom_system_instructions_button =
96-
textarea.parentElement?.querySelector('div > button:last-child')
96+
textarea.parentElement?.parentElement?.querySelector(
97+
'div > button:last-child'
98+
)
9799
if (!custom_system_instructions_button) {
98100
report_initialization_error({
99101
function_name: 'enter_system_instructions',

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/perplexity.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export const perplexity: Chatbot = {
2525
check_for_element()
2626
})
2727
},
28-
enter_message_and_send: async (message: string) => {
28+
enter_message_and_send: async (
29+
message: string,
30+
without_submission?: boolean
31+
) => {
2932
let instructions = message
3033
if (message.includes('<files>')) {
3134
instructions = message.split('<files>')[0].trim()
@@ -85,6 +88,8 @@ export const perplexity: Chatbot = {
8588

8689
await new Promise((r) => requestAnimationFrame(r))
8790

91+
if (without_submission) return
92+
8893
const submit_button = document.querySelector(
8994
'button[data-testid="submit-button"]'
9095
) as HTMLButtonElement

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/qwen.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ export const qwen: Chatbot = {
144144
}
145145
}
146146
},
147-
enter_message_and_send: async (message: string) => {
147+
enter_message_and_send: async (
148+
message: string,
149+
without_submission?: boolean
150+
) => {
148151
let instructions = message
149152
if (message.includes('<files>')) {
150153
instructions = message.split('<files>')[0].trim()
@@ -198,6 +201,8 @@ export const qwen: Chatbot = {
198201
input_element.dispatchEvent(new Event('change', { bubbles: true }))
199202
await new Promise((r) => requestAnimationFrame(r))
200203

204+
if (without_submission) return
205+
201206
// Submit
202207
const submit_button = document.querySelector(
203208
'button#send-message-button'

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,16 @@ export const get_textarea_element = () => {
153153
const enter_message_and_send = async (params: {
154154
input_element: HTMLElement | null
155155
message: string
156+
without_submission?: boolean
156157
}) => {
157158
if (params.input_element && params.input_element.isContentEditable) {
158159
params.input_element.innerText = params.message
159160
params.input_element.dispatchEvent(new Event('input', { bubbles: true }))
160161
params.input_element.dispatchEvent(new Event('change', { bubbles: true }))
161162
await new Promise((r) => requestAnimationFrame(r))
163+
164+
if (params.without_submission) return
165+
162166
const form = params.input_element.closest('form')
163167
if (form) {
164168
form.requestSubmit()
@@ -180,6 +184,9 @@ const enter_message_and_send = async (params: {
180184
params.input_element.dispatchEvent(new Event('input', { bubbles: true }))
181185
params.input_element.dispatchEvent(new Event('change', { bubbles: true }))
182186
await new Promise((r) => requestAnimationFrame(r))
187+
188+
if (params.without_submission) return
189+
183190
const form = params.input_element.closest('form')
184191
if (form) {
185192
form.requestSubmit()
@@ -196,7 +203,11 @@ const enter_message_and_send = async (params: {
196203
}
197204
}
198205

199-
const initialize_chat = async (params: { message: string; chat: Chat }) => {
206+
const initialize_chat = async (params: {
207+
message: string
208+
chat: Chat
209+
without_submission?: boolean
210+
}) => {
200211
if (chatbot?.set_model) {
201212
await chatbot.set_model(params.chat.model)
202213
}
@@ -219,11 +230,15 @@ const initialize_chat = async (params: { message: string; chat: Chat }) => {
219230
await chatbot.set_options(params.chat.options || [])
220231
}
221232
if (chatbot?.enter_message_and_send) {
222-
await chatbot.enter_message_and_send(params.message)
233+
await chatbot.enter_message_and_send(
234+
params.message,
235+
params.without_submission
236+
)
223237
} else {
224238
await enter_message_and_send({
225239
input_element: get_textarea_element(),
226-
message: params.message
240+
message: params.message,
241+
without_submission: params.without_submission
227242
})
228243
}
229244

@@ -250,6 +265,7 @@ const main = async () => {
250265
text: string
251266
current_chat: Chat
252267
client_id: number
268+
without_submission?: boolean
253269
}
254270

255271
if (!stored_data) {
@@ -272,7 +288,8 @@ const main = async () => {
272288

273289
await initialize_chat({
274290
message: message_text,
275-
chat: current_chat
291+
chat: current_chat,
292+
without_submission: stored_data.without_submission
276293
})
277294

278295
// Clean up the storage entry after using it

0 commit comments

Comments
 (0)