Expose version/build metadata and improve provider error messaging
This commit is contained in:
@@ -27,16 +27,19 @@ type App struct {
|
||||
input io.Reader
|
||||
output io.Writer
|
||||
status string
|
||||
version string
|
||||
build string
|
||||
streamBuffer strings.Builder
|
||||
}
|
||||
|
||||
// New constructs a new App instance.
|
||||
func New(logger *slog.Logger, cfg *config.Config, opts ...Option) *App {
|
||||
app := &App{
|
||||
logger: logger,
|
||||
config: cfg,
|
||||
input: os.Stdin,
|
||||
output: os.Stdout,
|
||||
logger: logger,
|
||||
config: cfg,
|
||||
input: os.Stdin,
|
||||
output: os.Stdout,
|
||||
version: "dev",
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
@@ -64,6 +67,20 @@ func WithIO(in io.Reader, out io.Writer) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithVersion sets the application version string presented in the UI header.
|
||||
func WithVersion(version string) Option {
|
||||
return func(a *App) {
|
||||
a.version = strings.TrimSpace(version)
|
||||
}
|
||||
}
|
||||
|
||||
// WithBuild sets the application build identifier presented in the UI header.
|
||||
func WithBuild(build string) Option {
|
||||
return func(a *App) {
|
||||
a.build = strings.TrimSpace(build)
|
||||
}
|
||||
}
|
||||
|
||||
// Run starts the application lifecycle.
|
||||
func (a *App) Run(ctx context.Context) error {
|
||||
if a == nil {
|
||||
@@ -201,7 +218,15 @@ func (a *App) runCLILoop(ctx context.Context) error {
|
||||
}
|
||||
a.clearStreamingContent()
|
||||
|
||||
a.setStatus("")
|
||||
notice := ""
|
||||
if a.chat != nil {
|
||||
notice = a.chat.ConsumeStreamingNotice()
|
||||
}
|
||||
if strings.TrimSpace(notice) != "" {
|
||||
a.setStatus("%s", notice)
|
||||
} else {
|
||||
a.setStatus("")
|
||||
}
|
||||
|
||||
if err := a.maybeSuggestSessionName(ctx); err != nil {
|
||||
a.logger.WarnContext(ctx, "session name suggestion failed", "error", err)
|
||||
@@ -386,7 +411,15 @@ func (a *App) renderUI() error {
|
||||
sessionName = a.chat.SessionName()
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("goaichat - %s", sessionName)
|
||||
name := "goaichat"
|
||||
if v := strings.TrimSpace(a.version); v != "" {
|
||||
name = fmt.Sprintf("%s v%s", name, v)
|
||||
}
|
||||
if b := strings.TrimSpace(a.build); b != "" {
|
||||
name = fmt.Sprintf("%s (build %s)", name, b)
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("%s - %s", name, sessionName)
|
||||
underline := strings.Repeat("=", len(title))
|
||||
if _, err := fmt.Fprintf(a.output, "%s\n%s\n\n", title, underline); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user