Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: session updateState should patch the state instead of replace #1437

Open
pavelgj opened this issue Dec 2, 2024 · 0 comments · May be fixed by #1573
Open

Feature request: session updateState should patch the state instead of replace #1437

pavelgj opened this issue Dec 2, 2024 · 0 comments · May be fixed by #1573
Assignees

Comments

@pavelgj
Copy link
Collaborator

pavelgj commented Dec 2, 2024

Description

Currently there's inconsistent behavior when using updateState(). When updating a single property, it appears to replace the entire state object rather than patching it:

console.log(session.state) 
// { userName: 'God', colour: 'Green' }

async (input) => {
  ai.currentSession().updateState({ 
    colour: input.colour,
  });
  return `colour updated to ${input.colour}`;
}

console.log(session.state)
// { colour: 'Green' }  // userName was cleared

The current workaround is to manually spread the existing state:

async (input) => {
  ai.currentSession().updateState({
    ...ai.currentSession().state,
    userName: input.userName,
  });
}

It should be changed to patch

@pavelgj pavelgj changed the title [js/core/session] session updateState should patch the state instead of replace Feature request: session updateState should patch the state instead of replace Dec 2, 2024
@cabljac cabljac linked a pull request Dec 23, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants