Open rcheetah opened 1 month ago
Hi! Not through the command line, but what you can do is get details about the state:
nb - ABC state
It will return something like:
{:state=>
{:path=>
"/home/user/.local/state/nano-bots/ruby-nano-bots/none/unknown/0-0-0/XPTO/state.json",
:content=>
{:key=>"ABC",
:history=>
[{:at=>"2024-06-04 17:05:58 -0300", :who=>"user", :mode=>"eval", :input=>"hi", :message=>"hi"},
{:who=>"AI", :message=>"Hello! How can I assist you today?", :mode=>"eval", :output=>"Hello! How can I assist you today?\n", :at=>"2024-06-04 17:06:01 -0300"}]}}}
Then you can delete the file:
/home/user/.local/state/nano-bots/ruby-nano-bots/none/unknown/0-0-0/XPTO/state.json
Perfect, thank you very much! This works for my cause. I didn't see the debugging part in the readme (mostly because I was searching for 'delete' or 'state').
The only thing that bothers me: Debugging a non-existing state will create it. So if I want to check if a state with a given name exists, I will always create it, and therefore it will exists. Is this intended behaviour? Seems like debugging a non-existing state should throw an error.
@rcheetah Yeah, you would need to check the state file, and if it's empty (history
array empty), it means it "doesn't exist." This wasn't intentionally built that way. The reason it happens is:
When CLI is used through nb
and it's a command related to a "bot," it will create the bot before executing the command.
In this process of creating the bot, it will call build_path_and_ensure_state_file!
, thereby creating the file. The goal was to ensure that before the bot executes, if it should have a state, the state file is writable and ready to be filled.
The unintended collateral effect is creating a new state file with an empty history for the ones that don't exist when just checking/debugging.
@rcheetah I'm not sure about throwing an error, but in version 3.3.0 and beyond, it will no longer create a file if the state does not exist and will return nil
instead:
nb - XPTO state
nil
The state names in the storage folder are encrypted, as well as the contents. I wonder if it is possible to delete a given state by providing the state string? Something like
nb delete state123