Skip to content

Commit

Permalink
fix(js/ai): make updateState patch state instead of replace it
Browse files Browse the repository at this point in the history
  • Loading branch information
cabljac committed Dec 23, 2024
1 parent e52a0d7 commit 0c52130
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions js/ai/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,22 @@ export class Session<S = any> {
}

/**
* Update session state data.
* Update session state data by patching the existing state.
* @param data Partial state update that will be merged with existing state
*/
async updateState(data: S): Promise<void> {
async updateState(data: Partial<S>): Promise<void> {
let sessionData = this.sessionData;
if (!sessionData) {
sessionData = {} as SessionData<S>;
}
sessionData.state = data;
this.sessionData = sessionData;

// Merge the new data with existing state
sessionData.state = {
...sessionData.state,
...data,
} as S;

this.sessionData = sessionData;
await this.store.save(this.id, sessionData);
}

Expand Down

0 comments on commit 0c52130

Please sign in to comment.