mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-18 14:00:27 -07:00
refactor(core): unify InjectionService API to single onInjection interface
Remove legacy onUserHint/offUserHint/addUserHint methods. All callers now use addInjection(text, source) and onInjection/offInjection with source-based filtering where needed.
This commit is contained in:
@@ -20,9 +20,8 @@ export type InjectionListener = (text: string, source: InjectionSource) => void;
|
||||
* Service for managing injections into the model conversation.
|
||||
*
|
||||
* Multiple sources (user steering, background execution completions, etc.)
|
||||
* can feed into this service. Consumers register typed listeners via
|
||||
* {@link onInjection} to receive injections with source information, or use the
|
||||
* legacy {@link onUserHint} API for backward compatibility.
|
||||
* can feed into this service. Consumers register listeners via
|
||||
* {@link onInjection} to receive injections with source information.
|
||||
*/
|
||||
export class InjectionService {
|
||||
private readonly injections: Array<{
|
||||
@@ -31,7 +30,6 @@ export class InjectionService {
|
||||
timestamp: number;
|
||||
}> = [];
|
||||
private readonly injectionListeners: Set<InjectionListener> = new Set();
|
||||
private readonly userHintListeners: Set<(hint: string) => void> = new Set();
|
||||
|
||||
constructor(private readonly isEnabled: () => boolean) {}
|
||||
|
||||
@@ -51,55 +49,25 @@ export class InjectionService {
|
||||
}
|
||||
this.injections.push({ text: trimmed, source, timestamp: Date.now() });
|
||||
|
||||
// Fire typed listeners (new API)
|
||||
for (const listener of this.injectionListeners) {
|
||||
listener(trimmed, source);
|
||||
}
|
||||
|
||||
// Fire legacy listeners (user_steering only)
|
||||
if (source === 'user_steering') {
|
||||
for (const listener of this.userHintListeners) {
|
||||
listener(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new steering hint from the user.
|
||||
* Convenience wrapper around {@link addInjection} with `user_steering` source.
|
||||
*/
|
||||
addUserHint(hint: string): void {
|
||||
this.addInjection(hint, 'user_steering');
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a typed listener for injections from any source.
|
||||
* Registers a listener for injections from any source.
|
||||
*/
|
||||
onInjection(listener: InjectionListener): void {
|
||||
this.injectionListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a typed injection listener.
|
||||
* Unregisters an injection listener.
|
||||
*/
|
||||
offInjection(listener: InjectionListener): void {
|
||||
this.injectionListeners.delete(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener for user steering hints only.
|
||||
*/
|
||||
onUserHint(listener: (hint: string) => void): void {
|
||||
this.userHintListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a user steering hint listener.
|
||||
*/
|
||||
offUserHint(listener: (hint: string) => void): void {
|
||||
this.userHintListeners.delete(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all collected injection texts (all sources).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user