Skip to content

Commit 056ee0d

Browse files
committed
Move Anthropic extended cache configuration from global settings to individual model provider settings
- remove configuration setting 'extended cache duration for anthropic', instead, 'ModelProvider' should have 'exetended cache' key, that can be set when 'base url' is 'https://api.anthropic.com/v1'
1 parent 9582118 commit 056ee0d

21 files changed

Lines changed: 52 additions & 153 deletions

‎apps/editor/package.json‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,6 @@
820820
"type": "boolean",
821821
"scope": "resource"
822822
},
823-
"codeWebChat.extendedCacheDurationForAnthropic": {
824-
"type": "boolean",
825-
"scope": "resource"
826-
},
827823
"codeWebChat.contextSizeWarningThreshold": {
828824
"type": "number",
829825
"scope": "resource"
@@ -1063,6 +1059,9 @@
10631059
},
10641060
"baseUrl": {
10651061
"type": "string"
1062+
},
1063+
"extendedCache": {
1064+
"type": "boolean"
10661065
}
10671066
},
10681067
"required": [

‎apps/editor/src/commands/code-at-cursor-command/utils/perform-code-at-cursor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const perform_code_at_cursor = async (params: {
139139
}${text_after_cursor}\n]]>\n</file>\n</files>\n${code_at_cursor_instructions}`
140140

141141
const user_content = build_user_content({
142-
model_provider_name: model_provider.name,
142+
model_provider,
143143
part1,
144144
part2
145145
})

‎apps/editor/src/commands/search-files-command/utils/fetch-relevant-files-from-api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const fetch_relevant_files_from_api = async (
2929
const system_instructions_xml = `${find_relevant_files_format}\n${find_relevant_files_instructions}`
3030
const part2 = `${system_instructions_xml}\n${instructions}`
3131
const user_content = build_user_content({
32-
model_provider_name: model_provider.name,
32+
model_provider,
3333
part1: xml_files,
3434
part2,
3535
disable_cache: true

‎apps/editor/src/services/model-providers-manager.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type ModelProvider = {
55
name: string
66
base_url: string
77
api_key: string
8+
extended_cache?: boolean
89
}
910

1011
export type ApiConfiguration = {
@@ -43,6 +44,7 @@ export class ModelProvidersManager {
4344
{
4445
name: string
4546
baseUrl: string
47+
extendedCache?: boolean
4648
}[]
4749
>('modelProviders', [])
4850

@@ -60,7 +62,8 @@ export class ModelProvidersManager {
6062
const model_provider: ModelProvider = {
6163
name: provider_config.name,
6264
api_key: model_provider_with_key?.api_key || '',
63-
base_url: provider_config.baseUrl || ''
65+
base_url: provider_config.baseUrl || '',
66+
extended_cache: provider_config.extendedCache
6467
}
6568
return model_provider
6669
})
@@ -80,7 +83,11 @@ export class ModelProvidersManager {
8083

8184
// Save provider config to settings
8285
const model_provider_configs = model_providers.map((p) => {
83-
return { name: p.name, baseUrl: p.base_url }
86+
return {
87+
name: p.name,
88+
baseUrl: p.base_url,
89+
extendedCache: p.extended_cache
90+
}
8491
})
8592
const config = vscode.workspace.getConfiguration('codeWebChat')
8693
await config.update(

‎apps/editor/src/utils/build-user-content.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as vscode from 'vscode'
1+
import { ModelProvider } from '@/services/model-providers-manager'
22

33
export const build_user_content = (params: {
4-
model_provider_name: string
4+
model_provider: ModelProvider
55
part1: string
66
part2: string
77
disable_cache?: boolean
@@ -30,10 +30,12 @@ export const build_user_content = (params: {
3030
return parsed
3131
}
3232

33-
if (params.model_provider_name == 'Anthropic') {
33+
if (
34+
params.model_provider.name == 'Anthropic' ||
35+
params.model_provider.base_url.includes('api.anthropic.com')
36+
) {
3437
const cache_control: any = { type: 'ephemeral' }
35-
const config = vscode.workspace.getConfiguration('codeWebChat')
36-
if (config.get('extendedCacheDurationForAnthropic')) {
38+
if (params.model_provider.extended_cache) {
3739
cache_control.ttl = '1h'
3840
}
3941

‎apps/editor/src/views/panel/backend/message-handlers/handle-code-at-cursor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export const handle_code_at_cursor = async (
339339
}${text_after_cursor}\n]]>\n</file>\n</files>\n${skill_definitions}${main_instructions}`
340340

341341
const user_content = build_user_content({
342-
model_provider_name: model_provider.name,
342+
model_provider,
343343
part1,
344344
part2
345345
})

‎apps/editor/src/views/panel/backend/message-handlers/handle-edit-files.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export const handle_edit_files = async (
396396
}${processed_instructions}`
397397

398398
const user_content = build_user_content({
399-
model_provider_name: model_provider.name,
399+
model_provider,
400400
part1,
401401
part2
402402
})

‎apps/editor/src/views/panel/backend/message-handlers/handle-find-relevant-files.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export const handle_find_relevant_files = async (
361361
const part2 = `${collected.recent_files}</files>\n${skill_definitions}${system_instructions_xml}\n${processed_instructions}`
362362

363363
const user_content = build_user_content({
364-
model_provider_name: model_provider.name,
364+
model_provider,
365365
part1,
366366
part2,
367367
disable_cache: true

‎apps/editor/src/views/settings/backend/message-handlers/handle-add-model-provider.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export const handle_add_model_provider = async (
7878
provider: {
7979
name: new_name,
8080
base_url: new_base_url,
81-
api_key_mask: ''
81+
api_key_mask: '',
82+
extended_cache: undefined
8283
},
8384
insertion_index: message.insertion_index,
8485
create_on_top: message.create_on_top

‎apps/editor/src/views/settings/backend/message-handlers/handle-get-extended-cache-duration-for-anthropic.ts‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)