Skip to content

Commit 7e5a59d

Browse files
committed
fix: removing contextLimit and token management related code
- due to the decision in: #3717
1 parent 645b2fc commit 7e5a59d

File tree

25 files changed

+25
-957
lines changed

25 files changed

+25
-957
lines changed

packages/types/src/provider-settings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ const geminiSchema = apiModelIdProviderModelSchema.extend({
162162
maxOutputTokens: z.number().optional(),
163163
enableUrlContext: z.boolean().optional(),
164164
enableGrounding: z.boolean().optional(),
165-
contextLimit: z.number().optional(),
166165
})
167166

168167
const geminiCliSchema = apiModelIdProviderModelSchema.extend({

src/api/providers/gemini.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
6565
): ApiStream {
6666
const { id: model, info, reasoning: thinkingConfig, maxTokens } = this.getModel()
6767

68-
const limitedMessages = this.options.contextLimit ? messages.slice(-this.options.contextLimit) : messages
69-
const contents = limitedMessages.map(convertAnthropicMessageToGemini)
68+
const contents = messages.map(convertAnthropicMessageToGemini)
7069

7170
const tools: Array<Record<string, object>> = []
7271
if (this.options.enableUrlContext) {
@@ -147,13 +146,6 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
147146
let info: ModelInfo = geminiModels[id]
148147
const params = getModelParams({ format: "gemini", modelId: id, model: info, settings: this.options })
149148

150-
if (this.options.contextLimit) {
151-
info = {
152-
...info,
153-
contextWindow: this.options.contextLimit,
154-
}
155-
}
156-
157149
// The `:thinking` suffix indicates that the model is a "Hybrid"
158150
// reasoning model and that reasoning is required to be enabled.
159151
// The actual model ID honored by Gemini's API does not have this

src/core/sliding-window/__tests__/sliding-window.spec.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -250,31 +250,6 @@ describe("Sliding Window", () => {
250250
{ role: "assistant", content: "Fourth message" },
251251
{ role: "user", content: "Fifth message" },
252252
]
253-
it("should use contextLimit as contextWindow when apiProvider is gemini", async () => {
254-
const contextLimit = 2
255-
const messages: ApiMessage[] = [
256-
{ role: "user", content: "First message" },
257-
{ role: "assistant", content: "Second message" },
258-
{ role: "user", content: "Third message" },
259-
{ role: "assistant", content: "Fourth message" },
260-
{ role: "user", content: "" },
261-
]
262-
const result = await truncateConversationIfNeeded({
263-
messages,
264-
totalTokens: 2,
265-
contextWindow: contextLimit,
266-
maxTokens: null,
267-
apiHandler: mockApiHandler,
268-
autoCondenseContext: false,
269-
autoCondenseContextPercent: 100,
270-
systemPrompt: "",
271-
taskId,
272-
profileThresholds: {},
273-
currentProfileId: "default",
274-
})
275-
expect(result.messages).toEqual([messages[0], messages[3], messages[4]])
276-
})
277-
278253
it("should not truncate if tokens are below max tokens threshold", async () => {
279254
const modelInfo = createModelInfo(100000, 30000)
280255
const dynamicBuffer = modelInfo.contextWindow * TOKEN_BUFFER_PERCENTAGE // 10000

src/core/task/Task.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,12 +1714,11 @@ export class Task extends EventEmitter<ClineEvents> {
17141714
? this.apiConfiguration.modelMaxTokens || DEFAULT_THINKING_MODEL_MAX_TOKENS
17151715
: modelInfo.maxTokens
17161716

1717-
const contextWindow =
1718-
this.apiConfiguration.apiProvider === "gemini" && this.apiConfiguration.contextLimit
1719-
? this.apiConfiguration.contextLimit
1720-
: modelInfo.contextWindow
1717+
const contextWindow = modelInfo.contextWindow
17211718

1722-
const currentProfileId = state?.listApiConfigMeta.find((profile) => profile.name === state?.currentApiConfigName)?.id ?? "default";
1719+
const currentProfileId =
1720+
state?.listApiConfigMeta.find((profile) => profile.name === state?.currentApiConfigName)?.id ??
1721+
"default"
17231722

17241723
const truncateResult = await truncateConversationIfNeeded({
17251724
messages: this.apiConversationHistory,

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ export interface ApiOptionsProps {
7474
fromWelcomeView?: boolean
7575
errorMessage: string | undefined
7676
setErrorMessage: React.Dispatch<React.SetStateAction<string | undefined>>
77-
currentProfileId?: string
78-
profileThresholds?: Record<string, number>
79-
autoCondenseContextPercent?: number
80-
setProfileThreshold?: (profileId: string, threshold: number) => void
8177
}
8278

8379
const ApiOptions = ({
@@ -87,10 +83,6 @@ const ApiOptions = ({
8783
fromWelcomeView,
8884
errorMessage,
8985
setErrorMessage,
90-
currentProfileId,
91-
profileThresholds,
92-
autoCondenseContextPercent,
93-
setProfileThreshold,
9486
}: ApiOptionsProps) => {
9587
const { t } = useAppTranslation()
9688
const { organizationAllowList } = useExtensionState()
@@ -423,10 +415,6 @@ const ApiOptions = ({
423415
apiConfiguration={apiConfiguration}
424416
setApiConfigurationField={setApiConfigurationField}
425417
currentModelId={selectedModelId}
426-
currentProfileId={currentProfileId}
427-
profileThresholds={profileThresholds}
428-
autoCondenseContextPercent={autoCondenseContextPercent}
429-
setProfileThreshold={setProfileThreshold}
430418
/>
431419
)}
432420

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
180180

181181
const apiConfiguration = useMemo(() => cachedState.apiConfiguration ?? {}, [cachedState.apiConfiguration])
182182

183-
const getCurrentProfileId = useCallback(() => {
184-
if (!currentApiConfigName || !listApiConfigMeta) {
185-
return currentApiConfigName
186-
}
187-
188-
const profile = listApiConfigMeta.find((p) => p.name === currentApiConfigName)
189-
return profile ? profile.id : currentApiConfigName
190-
}, [currentApiConfigName, listApiConfigMeta])
191-
192183
useEffect(() => {
193184
// Update only when currentApiConfigName is changed.
194185
// Expected to be triggered by loadApiConfiguration/upsertApiConfiguration.
@@ -245,16 +236,6 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
245236
})
246237
}, [])
247238

248-
const setProfileThreshold = useCallback(
249-
(profileId: string, threshold: number) => {
250-
setCachedStateField("profileThresholds", {
251-
...profileThresholds,
252-
[profileId]: threshold,
253-
})
254-
},
255-
[profileThresholds, setCachedStateField],
256-
)
257-
258239
const setTelemetrySetting = useCallback((setting: TelemetrySetting) => {
259240
setCachedState((prevState) => {
260241
if (prevState.telemetrySetting === setting) {
@@ -601,10 +582,6 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
601582
setApiConfigurationField={setApiConfigurationField}
602583
errorMessage={errorMessage}
603584
setErrorMessage={setErrorMessage}
604-
currentProfileId={getCurrentProfileId()}
605-
profileThresholds={profileThresholds || {}}
606-
autoCondenseContextPercent={autoCondenseContextPercent || 75}
607-
setProfileThreshold={setProfileThreshold}
608585
/>
609586
</Section>
610587
</div>

0 commit comments

Comments
 (0)