(
params: {
action: ClientAction<'prompt'>
onResponseChunk: (chunk: string | PrintModeEvent) => void
localAgentTemplates: Record<string, AgentTemplate>
requestToolCall: RequestToolCallFn
logger: Logger
} & ParamsExcluding<
typeof loopAgentSteps,
| 'userInputId'
| 'spawnParams'
| 'agentState'
| 'prompt'
| 'content'
| 'agentType'
| 'fingerprintId'
| 'fileContext'
| 'ancestorRunIds'
> &
ParamsExcluding<typeof getAgentTemplate, 'agentId'>,
)
| 25 | } from '@codebuff/common/types/session-state' |
| 26 | |
| 27 | export async function mainPrompt( |
| 28 | params: { |
| 29 | action: ClientAction<'prompt'> |
| 30 | |
| 31 | onResponseChunk: (chunk: string | PrintModeEvent) => void |
| 32 | localAgentTemplates: Record<string, AgentTemplate> |
| 33 | |
| 34 | requestToolCall: RequestToolCallFn |
| 35 | logger: Logger |
| 36 | } & ParamsExcluding< |
| 37 | typeof loopAgentSteps, |
| 38 | | 'userInputId' |
| 39 | | 'spawnParams' |
| 40 | | 'agentState' |
| 41 | | 'prompt' |
| 42 | | 'content' |
| 43 | | 'agentType' |
| 44 | | 'fingerprintId' |
| 45 | | 'fileContext' |
| 46 | | 'ancestorRunIds' |
| 47 | > & |
| 48 | ParamsExcluding<typeof getAgentTemplate, 'agentId'>, |
| 49 | ): Promise<{ |
| 50 | sessionState: SessionState |
| 51 | output: AgentOutput |
| 52 | }> { |
| 53 | const { action, localAgentTemplates, logger } = params |
| 54 | |
| 55 | const { |
| 56 | prompt, |
| 57 | content, |
| 58 | sessionState: sessionState, |
| 59 | fingerprintId, |
| 60 | costMode, |
| 61 | promptId, |
| 62 | agentId, |
| 63 | promptParams, |
| 64 | } = action |
| 65 | const { fileContext, mainAgentState } = sessionState |
| 66 | |
| 67 | // Track user input analytics event |
| 68 | // userId comes from params (passed through from loopAgentSteps) |
| 69 | const userId = (params as { userId?: string }).userId |
| 70 | if (typeof userId === 'string' && userId.trim() !== '') { |
| 71 | trackEvent({ |
| 72 | event: AnalyticsEvent.USER_INPUT, |
| 73 | userId, |
| 74 | properties: { |
| 75 | promptId, |
| 76 | agentId, |
| 77 | costMode, |
| 78 | hasPrompt: !!prompt, |
| 79 | hasContent: !!content, |
| 80 | hasPromptParams: !!promptParams && Object.keys(promptParams).length > 0, |
| 81 | promptParamsCount: promptParams ? Object.keys(promptParams).length : 0, |
| 82 | fingerprintId, |
| 83 | promptLength: prompt?.length ?? 0, |
| 84 | contentLength: content?.length ?? 0, |
no test coverage detected