Last active
April 3, 2023 15:12
-
-
Save elliottsj/48d3cc02b57c2db7b9df650d61e0305a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'chat', | |
initial: 'initial', | |
context: { | |
messages: [], | |
currentMessage: 'x', | |
model: '' | |
}, | |
states: { | |
initial: { | |
on: { | |
FETCH: 'loadingChatHistory' | |
} | |
}, | |
loadingChatHistory: { | |
on: { | |
CHAT_HISTORY_RESOLVE: 'idle', | |
CHAT_HISTORY_REJECT: 'error' | |
} | |
}, | |
idle: { | |
on: { | |
INPUT_CHANGE: [ | |
{ target: 'idle', cond: 'isInputEmpty' }, | |
{ target: 'pendingUserMessage', cond: 'isInputNotEmpty' }, | |
], | |
TEMPERATURE_CHANGE: [ | |
{ target: 'idle', cond: 'isInputEmpty' }, | |
{ target: 'pendingUserMessage', cond: 'isInputNotEmpty' }, | |
] | |
} | |
}, | |
pendingUserMessage: { | |
on: { | |
INPUT_CHANGE: [ | |
{ target: 'idle', cond: 'isInputEmpty' }, | |
{ target: 'pendingUserMessage', cond: 'isInputNotEmpty' }, | |
], | |
TEMPERATURE_CHANGE: [ | |
{ target: 'idle', cond: 'isInputEmpty' }, | |
{ target: 'pendingUserMessage', cond: 'isInputNotEmpty' }, | |
], | |
SEND: 'streamingBotResponse', | |
} | |
}, | |
streamingBotResponse: { | |
on: { | |
RECEIVE_BOT_TEXT: 'streamingBotResponse', | |
COMPLETE_BOT_RESPONSE: 'idle', | |
} | |
}, | |
error: { | |
on: { | |
RETRY: 'loadingChatHistory' | |
} | |
} | |
} | |
}, { | |
guards: { | |
isInputEmpty: (context, event) => { | |
return context.currentMessage === ''; | |
}, | |
isInputNotEmpty: (context, event) => { | |
return context.currentMessage !== ''; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment