Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778package daemon
import ( "albedo/cli/internal/daemon/protocol" "errors" "time")
// The daemon alone reads and writes creds.json. A client changes a profile's// api key or an MCP server's secrets through these routes and only ever learns// which secrets are saved, never what they are.
// Credentials names the saved secrets.type Credentials struct { MCP map[string]MCPSecretNames `json:"mcp"` // Providers are the profiles with a saved api key. Providers []string `json:"providers"`}
// MCPSecretNames is what an MCP server has saved, by name only, and where// its OAuth sign-in stands.type MCPSecretNames struct { Headers []string `json:"headers"` Env []string `json:"env"` BearerToken bool `json:"bearerToken"` Auth MCPAuth `json:"auth"`}
// MCPAuth is an HTTP server's OAuth sign-in as the daemon reports it. State// is "none" until the server asks for a sign-in, then "needs_sign_in",// "signed_in" or "signed_out"; StepUp names a wider scope a signed-in// server asked for. Tokens never reach the client.type MCPAuth struct { State, Account, Scope, StepUp, Reason, Client string ExpiresAt time.Time}
// SignInNeeded reports whether the server asks the user to sign in, or to// sign in again for more access.func (a MCPAuth) SignInNeeded() bool { return a.State == "needs_sign_in" || a.State == "signed_out" || a.StepUp != ""}
// Any reports whether the server has any secret saved.func (n MCPSecretNames) Any() bool { return n.BearerToken || len(n.Headers) > 0 || len(n.Env) > 0}
// MCPSecretsPatch keeps fields whose pointers or maps are nil. RemoveBearerToken// and the Clear flags remove whole fields; a nil map entry removes that name.type MCPSecretsPatch struct { BearerToken *string RemoveBearerToken bool Headers map[string]*string ClearHeaders bool Env map[string]*string ClearEnv bool}
func (patch MCPSecretsPatch) wire() (protocol.MCPSecretsPatch, error) { var fields protocol.MCPSecretsPatch if patch.BearerToken != nil && patch.RemoveBearerToken || patch.Headers != nil && patch.ClearHeaders || patch.Env != nil && patch.ClearEnv { return fields, errors.New("secret patch cannot replace and clear the same field") } if patch.BearerToken != nil { fields.BearerToken = protocol.SetNullablePatch(*patch.BearerToken) } else if patch.RemoveBearerToken { fields.BearerToken = protocol.ClearPatch[string]() } if patch.Headers != nil { fields.Headers = protocol.SetPatch(patch.Headers) } if patch.Env != nil { fields.Environment = protocol.SetPatch(patch.Env) } return fields, nil}