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

Is there a way to delete states by identifier? #19

Open
rcheetah opened this issue Jun 4, 2024 · 5 comments
Open

Is there a way to delete states by identifier? #19

rcheetah opened this issue Jun 4, 2024 · 5 comments

Comments

@rcheetah
Copy link

rcheetah commented Jun 4, 2024

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

@icebaker
Copy link
Owner

icebaker commented Jun 4, 2024

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

@rcheetah
Copy link
Author

rcheetah commented Jun 4, 2024

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.

@icebaker
Copy link
Owner

@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.

@icebaker
Copy link
Owner

@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

@palladius
Copy link

Can we add a functionality like:

nb - ABC delete-state

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants