Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions packages/telemetry/src/TelemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,11 @@ export class TelemetryService {
this.captureEvent(TelemetryEventName.CHECKPOINT_RESTORED, { taskId })
}

public captureContextCondensed(
taskId: string,
isAutomaticTrigger: boolean,
usedCustomPrompt?: boolean,
usedCustomApiHandler?: boolean,
): void {
public captureContextCondensed(taskId: string, isAutomaticTrigger: boolean, usedCustomPrompt?: boolean): void {
this.captureEvent(TelemetryEventName.CONTEXT_CONDENSED, {
taskId,
isAutomaticTrigger,
...(usedCustomPrompt !== undefined && { usedCustomPrompt }),
...(usedCustomApiHandler !== undefined && { usedCustomApiHandler }),
})
}

Expand Down
1 change: 0 additions & 1 deletion packages/types/src/global-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const globalSettingsSchema = z.object({
openRouterImageApiKey: z.string().optional(),
openRouterImageGenerationSelectedModel: z.string().optional(),

condensingApiConfigId: z.string().optional(),
customCondensingPrompt: z.string().optional(),

autoApprovalEnabled: z.boolean().optional(),
Expand Down
1 change: 0 additions & 1 deletion packages/types/src/vscode-extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ export type ExtensionState = Pick<
| "customModePrompts"
| "customSupportPrompts"
| "enhancementApiConfigId"
| "condensingApiConfigId"
| "customCondensingPrompt"
| "codebaseIndexConfig"
| "codebaseIndexModels"
Expand Down
180 changes: 10 additions & 170 deletions src/core/condense/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ describe("summarizeConversation", () => {
expect(mockApiHandler.createMessage).not.toHaveBeenCalled()
})

it("should return error when both condensing and main API handlers are invalid", async () => {
it("should return error when API handler is invalid", async () => {
const messages: ApiMessage[] = [
{ role: "user", content: "Hello", ts: 1 },
{ role: "assistant", content: "Hi there", ts: 2 },
Expand All @@ -1066,14 +1066,8 @@ describe("summarizeConversation", () => {
{ role: "user", content: "Tell me more", ts: 7 },
]

// Create invalid handlers (missing createMessage)
const invalidMainHandler = {
countTokens: vi.fn(),
getModel: vi.fn(),
// createMessage is missing
} as unknown as ApiHandler

const invalidCondensingHandler = {
// Create invalid handler (missing createMessage)
const invalidHandler = {
countTokens: vi.fn(),
getModel: vi.fn(),
// createMessage is missing
Expand All @@ -1086,26 +1080,21 @@ describe("summarizeConversation", () => {

const result = await summarizeConversation(
messages,
invalidMainHandler,
invalidHandler,
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
invalidCondensingHandler,
)

// Should return original messages when both handlers are invalid
// Should return original messages when handler is invalid
expect(result.messages).toEqual(messages)
expect(result.cost).toBe(0)
expect(result.summary).toBe("")
expect(result.error).toBeTruthy() // Error should be set
expect(result.newContextTokens).toBeUndefined()

// Verify error was logged
expect(mockError).toHaveBeenCalledWith(
expect.stringContaining("Main API handler is also invalid for condensing"),
)
expect(mockError).toHaveBeenCalledWith(expect.stringContaining("API handler is invalid for condensing"))

// Restore console.error
console.error = originalError
Expand Down Expand Up @@ -1157,10 +1146,6 @@ describe("summarizeConversation", () => {
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false, // isAutomaticTrigger
undefined, // customCondensingPrompt
undefined, // condensingApiHandler
true, // useNativeTools - required for tool_use block preservation
)

// Find the summary message
Expand Down Expand Up @@ -1236,10 +1221,6 @@ describe("summarizeConversation", () => {
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
undefined,
true,
)

expect(result.error).toBeUndefined()
Expand Down Expand Up @@ -1315,10 +1296,6 @@ describe("summarizeConversation", () => {
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
undefined,
true,
)

// Find the summary message (it has isSummary: true)
Expand Down Expand Up @@ -1389,10 +1366,6 @@ describe("summarizeConversation", () => {
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false, // isAutomaticTrigger
undefined, // customCondensingPrompt
undefined, // condensingApiHandler
true, // useNativeTools - required for tool_use block preservation
)

// Find the summary message
Expand Down Expand Up @@ -1458,10 +1431,6 @@ describe("summarizeConversation", () => {
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false, // isAutomaticTrigger
undefined, // customCondensingPrompt
undefined, // condensingApiHandler
false, // useNativeTools - not using tools in this test
)

// Find the summary message
Expand Down Expand Up @@ -1489,7 +1458,6 @@ describe("summarizeConversation", () => {
describe("summarizeConversation with custom settings", () => {
// Mock necessary dependencies
let mockMainApiHandler: ApiHandler
let mockCondensingApiHandler: ApiHandler
const defaultSystemPrompt = "Default prompt"
const taskId = "test-task"

Expand All @@ -1511,7 +1479,7 @@ describe("summarizeConversation with custom settings", () => {
// Reset telemetry mock
;(TelemetryService.instance.captureContextCondensed as Mock).mockClear()

// Setup mock API handlers
// Setup mock API handler
mockMainApiHandler = {
createMessage: vi.fn().mockImplementation(() => {
return (async function* () {
Expand All @@ -1534,29 +1502,6 @@ describe("summarizeConversation with custom settings", () => {
},
}),
} as unknown as ApiHandler

mockCondensingApiHandler = {
createMessage: vi.fn().mockImplementation(() => {
return (async function* () {
yield { type: "text" as const, text: "Summary from condensing handler" }
yield { type: "usage" as const, totalCost: 0.03, outputTokens: 80 }
})()
}),
countTokens: vi.fn().mockImplementation(() => Promise.resolve(40)),
getModel: vi.fn().mockReturnValue({
id: "condensing-model",
info: {
contextWindow: 4000,
supportsImages: true,
supportsVision: false,
maxTokens: 2000,
supportsPromptCache: false,
maxCachePoints: 0,
minTokensPerCachePoint: 0,
cachableFields: [],
},
}),
} as unknown as ApiHandler
})

/**
Expand Down Expand Up @@ -1619,84 +1564,6 @@ describe("summarizeConversation with custom settings", () => {
expect(createMessageCalls[0][0]).toContain("Your task is to create a detailed summary")
})

/**
* Test that condensing API handler is used when provided and valid
*/
it("should use condensingApiHandler when provided and valid", async () => {
await summarizeConversation(
sampleMessages,
mockMainApiHandler,
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
mockCondensingApiHandler,
)

// Verify the condensing handler was used
expect((mockCondensingApiHandler.createMessage as Mock).mock.calls.length).toBe(1)
expect((mockMainApiHandler.createMessage as Mock).mock.calls.length).toBe(0)
})

/**
* Test fallback to main API handler when condensing handler is not provided
*/
it("should fall back to mainApiHandler if condensingApiHandler is not provided", async () => {
await summarizeConversation(
sampleMessages,
mockMainApiHandler,
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
undefined,
)

// Verify the main handler was used
expect((mockMainApiHandler.createMessage as Mock).mock.calls.length).toBe(1)
})

/**
* Test fallback to main API handler when condensing handler is invalid
*/
it("should fall back to mainApiHandler if condensingApiHandler is invalid", async () => {
// Create an invalid handler (missing createMessage)
const invalidHandler = {
countTokens: vi.fn(),
getModel: vi.fn(),
// createMessage is missing
} as unknown as ApiHandler

// Mock console.warn to verify warning message
const originalWarn = console.warn
const mockWarn = vi.fn()
console.warn = mockWarn

await summarizeConversation(
sampleMessages,
mockMainApiHandler,
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
invalidHandler,
)

// Verify the main handler was used as fallback
expect((mockMainApiHandler.createMessage as Mock).mock.calls.length).toBe(1)

// Verify warning was logged
expect(mockWarn).toHaveBeenCalledWith(
expect.stringContaining("Chosen API handler for condensing does not support message creation"),
)

// Restore console.warn
console.warn = originalWarn
})

/**
* Test that telemetry is called for custom prompt usage
*/
Expand All @@ -1716,38 +1583,13 @@ describe("summarizeConversation with custom settings", () => {
taskId,
false,
true, // usedCustomPrompt
false, // usedCustomApiHandler
)
})

/**
* Test that telemetry is called for custom API handler usage
*/
it("should capture telemetry when using custom API handler", async () => {
await summarizeConversation(
sampleMessages,
mockMainApiHandler,
defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
undefined,
mockCondensingApiHandler,
)

// Verify telemetry was called with custom API handler flag
expect(TelemetryService.instance.captureContextCondensed).toHaveBeenCalledWith(
taskId,
false,
false, // usedCustomPrompt
true, // usedCustomApiHandler
)
})

/**
* Test that telemetry is called with both custom prompt and API handler
* Test that telemetry is called with isAutomaticTrigger flag
*/
it("should capture telemetry when using both custom prompt and API handler", async () => {
it("should capture telemetry with isAutomaticTrigger flag", async () => {
await summarizeConversation(
sampleMessages,
mockMainApiHandler,
Expand All @@ -1756,15 +1598,13 @@ describe("summarizeConversation with custom settings", () => {
DEFAULT_PREV_CONTEXT_TOKENS,
true, // isAutomaticTrigger
"Custom prompt",
mockCondensingApiHandler,
)

// Verify telemetry was called with both flags
// Verify telemetry was called with isAutomaticTrigger flag
expect(TelemetryService.instance.captureContextCondensed).toHaveBeenCalledWith(
taskId,
true, // isAutomaticTrigger
true, // usedCustomPrompt
true, // usedCustomApiHandler
)
})
})
Loading
Loading