mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix return type of fireSessionStartEvent to defaultHookOutput (#16833)
This commit is contained in:
@@ -648,18 +648,22 @@ export async function main() {
|
||||
const sessionStartSource = resumedSessionData
|
||||
? SessionStartSource.Resume
|
||||
: SessionStartSource.Startup;
|
||||
const result = await config
|
||||
.getHookSystem()
|
||||
?.fireSessionStartEvent(sessionStartSource);
|
||||
|
||||
if (result?.finalOutput) {
|
||||
if (result.finalOutput.systemMessage) {
|
||||
writeToStderr(result.finalOutput.systemMessage + '\n');
|
||||
}
|
||||
const additionalContext = result.finalOutput.getAdditionalContext();
|
||||
if (additionalContext) {
|
||||
// Prepend context to input (System Context -> Stdin -> Question)
|
||||
input = input ? `${additionalContext}\n\n${input}` : additionalContext;
|
||||
const hookSystem = config?.getHookSystem();
|
||||
if (hookSystem) {
|
||||
const result = await hookSystem.fireSessionStartEvent(sessionStartSource);
|
||||
|
||||
if (result) {
|
||||
if (result.systemMessage) {
|
||||
writeToStderr(result.systemMessage + '\n');
|
||||
}
|
||||
const additionalContext = result.getAdditionalContext();
|
||||
if (additionalContext) {
|
||||
// Prepend context to input (System Context -> Stdin -> Question)
|
||||
input = input
|
||||
? `${additionalContext}\n\n${input}`
|
||||
: additionalContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -300,18 +300,18 @@ export const AppContainer = (props: AppContainerProps) => {
|
||||
.getHookSystem()
|
||||
?.fireSessionStartEvent(sessionStartSource);
|
||||
|
||||
if (result?.finalOutput) {
|
||||
if (result.finalOutput?.systemMessage) {
|
||||
if (result) {
|
||||
if (result.systemMessage) {
|
||||
historyManager.addItem(
|
||||
{
|
||||
type: MessageType.INFO,
|
||||
text: result.finalOutput.systemMessage,
|
||||
text: result.systemMessage,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
}
|
||||
|
||||
const additionalContext = result.finalOutput.getAdditionalContext();
|
||||
const additionalContext = result.getAdditionalContext();
|
||||
const geminiClient = config.getGeminiClient();
|
||||
if (additionalContext && geminiClient) {
|
||||
await geminiClient.addHistory({
|
||||
|
||||
@@ -29,7 +29,10 @@ export const clearCommand: SlashCommand = {
|
||||
.getChatRecordingService();
|
||||
|
||||
// Fire SessionEnd hook before clearing
|
||||
await config?.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Clear);
|
||||
const hookSystem = config?.getHookSystem();
|
||||
if (hookSystem) {
|
||||
await hookSystem.fireSessionEndEvent(SessionEndReason.Clear);
|
||||
}
|
||||
|
||||
if (geminiClient) {
|
||||
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
|
||||
@@ -48,9 +51,10 @@ export const clearCommand: SlashCommand = {
|
||||
}
|
||||
|
||||
// Fire SessionStart hook after clearing
|
||||
const result = await config
|
||||
?.getHookSystem()
|
||||
?.fireSessionStartEvent(SessionStartSource.Clear);
|
||||
let result;
|
||||
if (hookSystem) {
|
||||
result = await hookSystem.fireSessionStartEvent(SessionStartSource.Clear);
|
||||
}
|
||||
|
||||
// Give the event loop a chance to process any pending telemetry operations
|
||||
// This ensures logger.emit() calls have fully propagated to the BatchLogRecordProcessor
|
||||
@@ -65,11 +69,11 @@ export const clearCommand: SlashCommand = {
|
||||
uiTelemetryService.setLastPromptTokenCount(0);
|
||||
context.ui.clear();
|
||||
|
||||
if (result?.finalOutput?.systemMessage) {
|
||||
if (result?.systemMessage) {
|
||||
context.ui.addItem(
|
||||
{
|
||||
type: MessageType.INFO,
|
||||
text: result.finalOutput.systemMessage,
|
||||
text: result.systemMessage,
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
|
||||
@@ -94,11 +94,12 @@ export class HookSystem {
|
||||
*/
|
||||
async fireSessionStartEvent(
|
||||
source: SessionStartSource,
|
||||
): Promise<AggregatedHookResult | undefined> {
|
||||
): Promise<DefaultHookOutput | undefined> {
|
||||
if (!this.config.getEnableHooks()) {
|
||||
return undefined;
|
||||
}
|
||||
return this.hookEventHandler.fireSessionStartEvent(source);
|
||||
const result = await this.hookEventHandler.fireSessionStartEvent(source);
|
||||
return result.finalOutput;
|
||||
}
|
||||
|
||||
async fireSessionEndEvent(
|
||||
|
||||
Reference in New Issue
Block a user