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 (*Service) AskDetailed ¶
func (s *Service) AskDetailed(ctx context.Context, opts QuestionOptions) (*QuestionResult, error)
AskDetailed 返回完整提问结果(含多选下标)。
func (*Service) SetProvider ¶
SetProvider 运行时切换 provider(SDK 注入真实实现)。
type StubProvider ¶
type StubProvider struct {
// DefaultIndex 默认返回的选项下标。
DefaultIndex int
}
StubProvider 是同步阻塞的测试 provider:总是返回默认选项。
func (*StubProvider) Ask ¶
func (s *StubProvider) Ask(ctx context.Context, opts QuestionOptions) (*QuestionResult, error)
Ask 实现 Provider:返回默认选中项(custom 为空)。
Click to show internal directories.
Click to hide internal directories.