Skip to content

Commit 3e219d0

Browse files
committed
Bump extension version to 1.83.0 and implement request chaining for KV cache optimization
1 parent a5bdcdc commit 3e219d0

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎packages/browser/src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Code Web Chat Connector",
55
"short_name": "CWC",
66
"description": "Connect your editor with free chatbots. Parse websites for context.",
7-
"version": "1.82.0",
7+
"version": "1.83.0",
88
"homepage_url": "https://github.com/robertpiosik/CodeWebChat",
99
"icons": {
1010
"16": "icons/icon-16.png",

‎packages/vscode/src/services/api-manager.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { Logger } from '@shared/utils/logger'
77
export class ApiManager {
88
private cancel_token_sources: Map<string, CancelTokenSource> = new Map()
99
private next_allowed_finish_time = 0
10+
// Waiting pipeline to utilize KV cache for the same endpoint urls
11+
private waiting_chain: Map<string, Promise<void>> = new Map()
1012

1113
constructor(private panel_provider: PanelProvider) {}
1214

@@ -20,26 +22,39 @@ export class ApiManager {
2022
const cancel_token_source = axios.CancelToken.source()
2123
this.cancel_token_sources.set(request_id, cancel_token_source)
2224

25+
const previous_waiting_promise = this.waiting_chain.get(params.endpoint_url)
26+
let resolve_waiting: () => void = () => {}
27+
const waiting_promise = new Promise<void>((resolve) => {
28+
resolve_waiting = resolve
29+
})
30+
this.waiting_chain.set(params.endpoint_url, waiting_promise)
31+
2332
try {
2433
this.panel_provider.send_message({
2534
command: 'SHOW_API_MANAGER_PROGRESS',
2635
id: request_id,
2736
title: 'Waiting...'
2837
})
2938

39+
if (previous_waiting_promise) {
40+
await previous_waiting_promise
41+
}
42+
3043
const result = await make_api_request({
3144
endpoint_url: params.endpoint_url,
3245
api_key: params.api_key,
3346
body: params.body,
3447
cancellation_token: cancel_token_source.token,
3548
on_thinking_chunk: () => {
49+
resolve_waiting()
3650
this.panel_provider.send_message({
3751
command: 'SHOW_API_MANAGER_PROGRESS',
3852
id: request_id,
3953
title: 'Thinking...'
4054
})
4155
},
4256
on_chunk: (tokens_per_second, total_tokens) => {
57+
resolve_waiting()
4358
this.panel_provider.send_message({
4459
command: 'SHOW_API_MANAGER_PROGRESS',
4560
id: request_id,
@@ -56,7 +71,7 @@ export class ApiManager {
5671
function_name: 'get',
5772
message: 'API call cancelled by user'
5873
})
59-
throw error // Re-throw cancellation error to be handled by caller
74+
throw error
6075
}
6176

6277
Logger.error({
@@ -66,6 +81,7 @@ export class ApiManager {
6681
})
6782
return null
6883
} finally {
84+
resolve_waiting()
6985
this.panel_provider.send_message({
7086
command: 'HIDE_API_MANAGER_PROGRESS',
7187
id: request_id

0 commit comments

Comments
 (0)