userq

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package userq 提供 User Questions(用户提问)接缝。

对齐上游:packages/interaction/user-questions

设计要点:

  • UQ 服务接口 Ask(ctx, options) → (idx, custom, err):向用户提问并收集选择/自定义输入;
  • provider_stub 实现同步阻塞返回默认选项(测试用);生产由 SDK 注入真实 UI/回调实现;
  • 支持多选(multiSelect)与意图标签(intent),决策逻辑只与接口耦合,可无缝替换 provider。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	// Ask 阻塞直到获得用户回答,返回 (result, error)。
	Ask(ctx context.Context, opts QuestionOptions) (*QuestionResult, error)
}

Provider 是用户提问的后端接口。

type QuestionOptions

type QuestionOptions struct {
	// Prompt 向用户展示的问题文本。
	Prompt string
	// Choices 候选选项列表。
	Choices []string
	// DefaultIndex 默认选中项下标(-1 表示无默认)。
	DefaultIndex int
	// MultiSelect 是否允许多选(此时返回逗号分隔的选项下标)。
	MultiSelect bool
	// Intent 意图标签(如 "approval" / "plan-exit" / "goal-blocker")。
	Intent string
}

QuestionOptions 描述一次提问的选项。

type QuestionResult

type QuestionResult struct {
	// SelectedIndex 选中的选项下标(多选时为第一个)。
	SelectedIndex int
	// Custom 用户自定义输入(选择"other/custom"时)。
	Custom string
	// SelectedIndices 多选时的全部下标。
	SelectedIndices []int
}

QuestionResult 是提问结果。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 是用户提问服务(可切换 provider)。

func New

func New(p Provider) *Service

New 创建提问服务。

func (*Service) Ask

func (s *Service) Ask(ctx context.Context, opts QuestionOptions) (int, string, error)

Ask 向用户提问,返回 (idx, custom, err)。 兼容上游签名:selection index + custom string。

func (*Service) AskDetailed

func (s *Service) AskDetailed(ctx context.Context, opts QuestionOptions) (*QuestionResult, error)

AskDetailed 返回完整提问结果(含多选下标)。

func (*Service) Provider

func (s *Service) Provider() Provider

Provider 返回当前 provider(供测试断言)。

func (*Service) SetProvider

func (s *Service) SetProvider(p Provider)

SetProvider 运行时切换 provider(SDK 注入真实实现)。

type StubProvider

type StubProvider struct {
	// DefaultIndex 默认返回的选项下标。
	DefaultIndex int
}

StubProvider 是同步阻塞的测试 provider:总是返回默认选项。

func NewStub

func NewStub() *StubProvider

NewStub 创建默认返回第 0 项的 stub。

func (*StubProvider) Ask

Ask 实现 Provider:返回默认选中项(custom 为空)。

Jump to

Keyboard shortcuts

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