interactive

package
v1.233.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package interactive prepares an AI client for a terminal session.

It connects the pieces that make a one-shot request feel alive: a spinner that follows the provider's tool activity, and an approval prompt (backed by the Atmos permission system) for providers that run their own tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Continue

func Continue(history []types.Message, turn TurnFunc) error

Continue offers follow-up questions after an answer, using terminal detection and a text prompt. Follow-ups are offered only when both stdin and stdout are terminals outside CI, so scripts and pipelines never wait for input.

Types

type Conversation

type Conversation struct {
	// Enabled reports whether follow-up questions can be asked at all.
	Enabled func() bool
	// Prompt asks for the next question. An empty answer ends the conversation.
	Prompt func() (string, error)
}

Conversation continues a one-shot question as a conversation: after each answer it asks whether there is a follow-up and runs another turn with the earlier turns as context.

func (Conversation) Continue

func (c Conversation) Continue(history []types.Message, turn TurnFunc) error

Continue runs follow-up turns until the user finishes or a turn fails. Pressing ctrl+c or Esc at the prompt finishes the conversation without an error.

type Session

type Session struct {
	// Progress is the spinner for the request. Start it before sending and Stop it afterwards.
	Progress *progress.Progress
	// TimeoutManaged is true when the provider enforces the timeout itself, excluding time
	// spent at approval prompts. The caller then needs a cancel-only context.
	TimeoutManaged bool
}

Session is the interactive state for one request.

func Attach

func Attach(atmosConfig *schema.AtmosConfiguration, client any, message string, timeout time.Duration) (*Session, error)

Attach wires client for interactive use and returns the session.

Providers opt in through the interfaces in the approval package; a client that implements none of them gets only the spinner. The timeout is handed to providers that enforce it themselves.

func (*Session) NewContext

func (s *Session) NewContext(timeout time.Duration) (context.Context, context.CancelFunc)

NewContext returns the context for the request. Providers that enforce the timeout themselves get a context without a deadline, so time spent waiting at an approval prompt does not count against it; every other provider gets a deadline.

type TurnFunc

type TurnFunc func(question string, history []types.Message) (string, error)

TurnFunc runs one conversation turn and returns the answer text. The history argument holds every earlier question and answer, oldest first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL