Skip to content

Sign-in prompt

ui.AuthPrompt is a component that asks to sign in, for an agent or a service that needs it. It shows a title, an optional detail and one button per way to sign in: methods are dicts with id, name and optional description (shown as a tooltip) and icon, and the first one is the main button. Picking one reports on_pick with its id. While waiting holds that id it shows a spinner and what is happening (waiting_text, or “Waiting for the browser…”), the code to type with a copy button when there is one, Open the page again when url is set, and Cancel. error shows a message in red.

ui.AuthPrompt · Category: AI agents · Full reference →

Sign-in promptSign-in prompt
  • Where an agent or a connected service needs the user to sign in before it can work.
  • For a device sign-in: show the code the user types on the page that opened.
import pyzed as pz
from pyzed import ui
class Agent(pz.App):
def __init__(self):
self.waiting, self.code = "", ""
def sign_in(self, method):
self.waiting = method
self.code = start_device_login() # opens the browser and returns the code to type
def view(self):
return ui.AuthPrompt(title="Sign in to use the agent", waiting=self.waiting, code=self.code,
methods=[{"id": "browser", "name": "Log in with the browser"}],
on_pick=lambda e: self.sign_in(e.value),
on_cancel=lambda e: setattr(self, "waiting", ""),
on_copy=lambda e: pz.Command.copy(e.value))

The first method is the main (solid) button.

Sign-in prompt: One methodSign-in prompt: One method
One method
Code
pz.container(ui.AuthPrompt(title="Sign in to continue",
methods=[{"id": "browser", "name": "Log in with the browser"}]),
width=380)
Sign-in prompt: methods=[...]Sign-in prompt: methods=[...]
methods=[...]
Code
pz.container(ui.AuthPrompt(title="Sign in to continue", methods=[
{"id": "browser", "name": "Log in with the browser", "icon": "globe"},
{"id": "key", "name": "Use an API key", "icon": "key-round"},
]), width=380)
Sign-in prompt: detail=Sign-in prompt: detail=
detail=
Code
pz.container(ui.AuthPrompt(title="Sign in to continue", detail="The agent needs your account.",
methods=[{"id": "browser", "name": "Log in with the browser"}]),
width=380)
Sign-in prompt: error=Sign-in prompt: error=
error=
Code
pz.container(ui.AuthPrompt(title="Sign in to continue", error="The sign-in was cancelled.",
methods=[{"id": "browser", "name": "Try again"}]),
width=380)
Sign-in prompt: waiting="browser"Sign-in prompt: waiting="browser"
waiting="browser"
Code
pz.container(ui.AuthPrompt(title="Sign in to continue", waiting="browser"), width=380)
Sign-in prompt: waiting_text=Sign-in prompt: waiting_text=
waiting_text=
Code
pz.container(ui.AuthPrompt(title="Sign in to continue", waiting="cli",
waiting_text="Finish signing in in the terminal."),
width=380)
Sign-in prompt: code=, url=Sign-in prompt: code=, url=
code=, url=
Code
pz.container(ui.AuthPrompt(title="Sign in to continue", waiting="device", code="WDJB-MJHT",
url="https://example.com/device"), width=380)

Sign-in prompt has 4 events of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

It is a pz.Component, so it also raises on_mount and on_unmount, and its handlers get a pz.Event whose value holds the data.

Event Handler gets When
on_pick (event) A method was picked (event.value is its id).
on_cancel (event) Cancel.
on_open_url (event) Open the page again.
on_copy (event) The code was copied.

Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().

The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.

class Agent(pz.App):
def __init__(self):
self.waiting, self.code = "", ""
def sign_in(self, method): # on_pick: event.value is the method's id
self.waiting, self.code = method, "ABCD-1234"
def view(self):
return ui.AuthPrompt(title="Sign in to use the agent", waiting=self.waiting, code=self.code,
methods=[{"id": "browser", "name": "Log in with the browser"}],
on_pick=lambda e: self.sign_in(e.value),
on_cancel=lambda e: setattr(self, "waiting", ""),
on_copy=lambda e: pz.Command.copy(e.value)) # the code
class AuthPrompt

A component that asks to sign in, like Zed when an agent needs it: one button per way to sign in, then, while one runs, what is happening (the browser or a terminal is open), a code to type when there is one, Open the page again and Cancel.

Property Default Description
title "" The heading.
detail "" A line under it.
methods None Dicts with id, name, optional description and icon; the first is the main one.
waiting "" The id of the method in progress ("" when none).
waiting_text "" What to show while waiting.
code "" A code to type (device sign-in).
url "" The page that was opened.
error "" An error to show.
icon_name "key-round" The icon.
theme None Theme.

Events: on_pick, on_cancel, on_open_url, on_copy (events).

Full reference →