adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
145 lines (144 loc) • 4.66 kB
TypeScript
import { Event, SessionInterface as Session, SessionsList, SessionService } from './types';
/**
* Optional configuration for getting a session
*/
export interface GetSessionConfig {
numRecentEvents?: number;
afterTimestamp?: number;
}
/**
* Response for listing events in a session
*/
export interface ListEventsResponse {
events: Event[];
nextPageToken?: string;
}
/**
* Interface for session services with simple method signatures.
* This interface defines the basic contract for session operations.
*/
export interface IBaseSessionService {
/**
* Gets a session by ID.
*/
getSession(appName: string, userId: string, sessionId: string): Promise<Session | undefined>;
/**
* Creates a new session.
*
* @param appName The application name
* @param userId The user ID
* @param initialState The initial state of the session
* @returns The created session
*/
createSession(appName: string, userId: string, initialState?: Record<string, any>): Promise<Session>;
/**
* Updates a session's state.
*
* @param appName The application name
* @param userId The user ID
* @param sessionId The session ID
* @param stateDelta The changes to apply to the session state
* @returns The updated session
*/
updateSessionState(appName: string, userId: string, sessionId: string, stateDelta: Record<string, any>): Promise<Session>;
}
/**
* Base abstract class for session services.
* Provides common functionality and defines the interface that concrete implementations must follow.
*/
export declare abstract class BaseSessionService implements SessionService {
/**
* Creates a new session.
*
* @param options.appName - The name of the app
* @param options.userId - The ID of the user
* @param options.sessionId - Optional client-provided session ID
* @param options.state - Optional initial state
* @returns A new Session instance
*/
abstract createSession(options: {
appName: string;
userId: string;
sessionId?: string;
state?: Record<string, any>;
}): Promise<Session> | Session;
/**
* Gets a session by its ID.
*
* @param options.appName - The name of the app
* @param options.userId - The ID of the user
* @param options.sessionId - The ID of the session to get
* @returns The requested Session or null if not found
*/
abstract getSession(options: {
appName: string;
userId: string;
sessionId: string;
}): Promise<Session | null> | Session | null;
/**
* Lists all sessions for a user in an app.
*
* @param options.appName - The name of the app
* @param options.userId - The ID of the user
* @returns A list of sessions
*/
abstract listSessions(options: {
appName: string;
userId: string;
}): Promise<SessionsList> | SessionsList;
/**
* Deletes a session.
*
* @param options.appName - The name of the app
* @param options.userId - The ID of the user
* @param options.sessionId - The ID of the session to delete
*/
abstract deleteSession(options: {
appName: string;
userId: string;
sessionId: string;
}): Promise<void> | void;
/**
* Lists events in a session.
*
* @param options.appName - The name of the app
* @param options.userId - The ID of the user
* @param options.sessionId - The ID of the session
* @returns A list of events in the session
*/
abstract listEvents(options: {
appName: string;
userId: string;
sessionId: string;
}): Promise<ListEventsResponse> | ListEventsResponse;
/**
* Updates a session's state.
*/
abstract updateSessionState(appName: string, userId: string, sessionId: string, stateDelta: Record<string, any>): Promise<Session>;
/**
* Closes a session.
*
* @param options.session - The session to close
*/
closeSession(options: {
session: Session;
}): Promise<void> | void;
/**
* Appends an event to a session.
*
* @param options.session - The session to append to
* @param options.event - The event to append
* @returns The event that was appended
*/
appendEvent(options: {
session: Session;
event: Event;
}): Promise<void> | void;
/**
* Updates the session state based on the event.
*
* @param session - The session to update
* @param event - The event to update from
*/
private _updateSessionStateFromEvent;
}