Skip to content

Commit 01fdc8c

Browse files
committed
refactor: rebase
1 parent 033e60d commit 01fdc8c

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/core/task/Task.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { CloudService, BridgeOrchestrator } from "@roo-code/cloud"
4444
import { ApiHandler, ApiHandlerCreateMessageMetadata, buildApiHandler } from "../../api"
4545
import { ApiStream, GroundingSource } from "../../api/transform/stream"
4646
import { maybeRemoveImageBlocks } from "../../api/transform/image-cleaning"
47+
import { VirtualQuotaFallbackHandler } from "../../api/providers/virtual-quota-fallback" // kilocode_change: Import VirtualQuotaFallbackHandler for model change notifications
4748

4849
// shared
4950
import { findLastIndex } from "../../shared/array"
@@ -378,6 +379,13 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
378379

379380
this.apiConfiguration = apiConfiguration
380381
this.api = buildApiHandler(apiConfiguration)
382+
// kilocode_change start: Listen for model changes in virtual quota fallback
383+
if (this.api instanceof VirtualQuotaFallbackHandler) {
384+
this.api.on("handlerChanged", () => {
385+
this.emit("modelChanged")
386+
})
387+
}
388+
// kilocode_change end
381389
this.autoApprovalHandler = new AutoApprovalHandler()
382390

383391
this.urlContentFetcher = new UrlContentFetcher(provider.context)
@@ -416,6 +424,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
416424
this.messageQueueStateChangedHandler = () => {
417425
this.emit(RooCodeEventName.TaskUserMessage, this.taskId)
418426
this.providerRef.deref()?.postStateToWebview()
427+
this.emit("modelChanged") // kilocode_change: Emit modelChanged for virtual quota fallback UI updates
419428
}
420429

421430
this.messageQueueService.on("stateChanged", this.messageQueueStateChangedHandler)
@@ -2758,6 +2767,11 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
27582767
const { profileThresholds = {} } = state ?? {}
27592768

27602769
const { contextTokens } = this.getTokenUsage()
2770+
// kilocode_change start: Initialize virtual quota fallback handler
2771+
if (this.api instanceof VirtualQuotaFallbackHandler) {
2772+
await this.api.initialize()
2773+
}
2774+
// kilocode_change end
27612775
const modelInfo = this.api.getModel().info
27622776

27632777
const maxTokens = getModelMaxOutputTokens({
@@ -2766,7 +2780,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
27662780
settings: this.apiConfiguration,
27672781
})
27682782

2769-
const contextWindow = modelInfo.contextWindow
2783+
const contextWindow = this.api.contextWindow ?? modelInfo.contextWindow // kilocode_change: Use contextWindow from API handler if available
27702784

27712785
// Get the current profile ID using the helper method
27722786
const currentProfileId = this.getCurrentProfileId(state)
@@ -2890,6 +2904,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
28902904
const { contextTokens } = this.getTokenUsage()
28912905

28922906
if (contextTokens) {
2907+
// kilocode_change start: Initialize and adjust virtual quota fallback handler
2908+
if (this.api instanceof VirtualQuotaFallbackHandler) {
2909+
await this.api.initialize()
2910+
await this.api.adjustActiveHandler("Pre-Request Adjustment")
2911+
}
2912+
// kilocode_change end
28932913
const modelInfo = this.api.getModel().info
28942914

28952915
const maxTokens = getModelMaxOutputTokens({
@@ -2898,7 +2918,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
28982918
settings: this.apiConfiguration,
28992919
})
29002920

2901-
const contextWindow = modelInfo.contextWindow
2921+
const contextWindow = this.api.contextWindow ?? modelInfo.contextWindow // kilocode_change
29022922

29032923
// Get the current profile ID using the helper method
29042924
const currentProfileId = this.getCurrentProfileId(state)
@@ -3010,17 +3030,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
30103030
if (getActiveToolUseStyle(apiConfiguration) === "json" && mode) {
30113031
try {
30123032
const provider = this.providerRef.deref()
3013-
const providerState = await provider?.getState()
3014-
3015-
const allowedTools = getAllowedJSONToolsForMode(
3033+
metadata.allowedTools = await getAllowedJSONToolsForMode(
30163034
mode,
3017-
undefined, // codeIndexManager is private, not accessible here
3018-
providerState,
3035+
provider,
30193036
this.diffEnabled,
30203037
this.api?.getModel(),
30213038
)
3022-
3023-
metadata.allowedTools = allowedTools
30243039
} catch (error) {
30253040
console.error("[Task] Error getting allowed tools for mode:", error)
30263041
// Continue without allowedTools - will fall back to default behavior

0 commit comments

Comments
 (0)