Skip to content

Commit f010c12

Browse files
committed
send finish event from backend
1 parent f2c10c5 commit f010c12

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

backend/src/websockets/websocket-action.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { calculateUsageAndBalance } from '@codebuff/billing'
22
import { trackEvent } from '@codebuff/common/analytics'
3+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
4+
import db from '@codebuff/common/db/index'
5+
import * as schema from '@codebuff/common/db/schema'
36
import {
47
ASYNC_AGENTS_ENABLED,
58
toOptionalFile,
69
} from '@codebuff/common/old-constants'
7-
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
8-
import db from '@codebuff/common/db/index'
9-
import * as schema from '@codebuff/common/db/schema'
1010
import { getErrorObject } from '@codebuff/common/util/error'
1111
import { ensureEndsWithNewline } from '@codebuff/common/util/file'
1212
import { generateCompactId } from '@codebuff/common/util/string'
@@ -234,6 +234,16 @@ export const callMainPrompt = async (
234234

235235
const { sessionState, output } = result
236236

237+
sendAction(ws, {
238+
type: 'response-chunk',
239+
userInputId: promptId,
240+
chunk: {
241+
type: 'finish',
242+
agentId: sessionState.mainAgentState.agentType ?? undefined,
243+
totalCost: sessionState.mainAgentState.creditsUsed,
244+
},
245+
})
246+
237247
// Send prompt data back
238248
sendAction(ws, {
239249
type: 'prompt-response',

npm-app/src/cli.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { homedir } from 'os'
44
import path, { basename, dirname, isAbsolute, parse } from 'path'
55
import * as readline from 'readline'
66

7+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
78
import {
89
API_KEY_ENV_VAR,
910
ASYNC_AGENTS_ENABLED,
1011
} from '@codebuff/common/old-constants'
11-
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
1212
import {
1313
getAllAgents,
1414
getAgentDisplayName,
@@ -109,7 +109,6 @@ import { withHangDetection } from './utils/with-hang-detection'
109109
import type { CliOptions, GitCommand } from './types'
110110
import type { ApiKeyType } from '@codebuff/common/api-keys/constants'
111111
import type { CostMode } from '@codebuff/common/old-constants'
112-
import type { PrintModeFinish } from '@codebuff/common/types/print-mode'
113112
import type { ProjectFileContext } from '@codebuff/common/util/file'
114113

115114
// Cache for local agent info to avoid async issues in sync methods
@@ -1372,17 +1371,6 @@ export class CLI {
13721371
.flat()
13731372
.reduce((sum, credits) => sum + credits, 0)
13741373

1375-
if (printModeIsEnabled()) {
1376-
const finishObj: PrintModeFinish = {
1377-
type: 'finish',
1378-
totalCost: totalCreditsUsedThisSession,
1379-
}
1380-
const agentId = CLI.getInstance().agent
1381-
if (agentId) {
1382-
finishObj.agentId = agentId
1383-
}
1384-
printModeLog(finishObj)
1385-
}
13861374
let exitUsageMessage = `${pluralize(totalCreditsUsedThisSession, 'credit')} used this session`
13871375
if (client.usageData.remainingBalance !== null) {
13881376
exitUsageMessage += `, ${client.usageData.remainingBalance.toLocaleString()} credits left.`

0 commit comments

Comments
 (0)