MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / SetState

Method SetState

internal/appstate/store.go:206–224  ·  view source on GitHub ↗

SetState stores arbitrary future app state as JSON.

(ctx context.Context, key string, value any)

Source from the content-addressed store, hash-verified

204
205// SetState stores arbitrary future app state as JSON.
206func (s Store) SetState(ctx context.Context, key string, value any) error {
207 if err := s.Init(ctx); err != nil {
208 return err
209 }
210 data, err := json.Marshal(value)
211 if err != nil {
212 return fmt.Errorf("appstate: marshal state: %w", err)
213 }
214 db, err := s.open()
215 if err != nil {
216 return err
217 }
218 defer db.Close()
219 _, err = db.ExecContext(ctx, `INSERT INTO app_state(key, value_json, updated_at) VALUES(?, ?, ?) ON CONFLICT(key) DO UPDATE SET value_json = excluded.value_json, updated_at = excluded.updated_at`, key, string(data), time.Now().UTC().Format(time.RFC3339Nano))
220 if err != nil {
221 return fmt.Errorf("appstate: set state: %w", err)
222 }
223 return nil
224}
225
226// GetState loads arbitrary future app state from JSON.
227func (s Store) GetState(ctx context.Context, key string, value any) (bool, error) {

Calls 3

InitMethod · 0.95
openMethod · 0.95
FormatMethod · 0.65