This commit is contained in:
@@ -66,7 +66,8 @@ func main() {
|
||||
}
|
||||
|
||||
func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||
prompt := internal.GetProjectConfig().UI.UserPrefix
|
||||
basePrompt := internal.GetProjectConfig().UI.UserPrefix
|
||||
prompt := internal.GetTTSPrompt(basePrompt)
|
||||
|
||||
rl, err := internal.NewReadline(prompt)
|
||||
if err != nil {
|
||||
@@ -77,6 +78,11 @@ func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||
}
|
||||
defer rl.Close()
|
||||
|
||||
ttsCfg := internal.GetProjectConfig().TTS
|
||||
if ttsCfg.Enabled {
|
||||
internal.SetTTSEnabled(true)
|
||||
}
|
||||
|
||||
for {
|
||||
line, err := rl.Readline()
|
||||
if err != nil {
|
||||
@@ -98,14 +104,37 @@ func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||
return
|
||||
}
|
||||
|
||||
runWithStreaming(agentLoop, input, sessionKey)
|
||||
isTempTTS := false
|
||||
if len(input) > 0 && input[0] == 'T' && (len(input) == 1 || input[1] == ' ') {
|
||||
input = strings.TrimPrefix(input, "T")
|
||||
input = strings.TrimPrefix(input, " ")
|
||||
isTempTTS = true
|
||||
}
|
||||
|
||||
if strings.HasPrefix(input, "/tts") {
|
||||
handleTTSCommand(input, rl, basePrompt)
|
||||
continue
|
||||
}
|
||||
|
||||
if isTempTTS {
|
||||
enabled := internal.ToggleTTS()
|
||||
if enabled {
|
||||
rl.SetPrompt(internal.GetTTSPrompt(basePrompt))
|
||||
}
|
||||
}
|
||||
|
||||
runWithStreaming(agentLoop, input, sessionKey, isTempTTS)
|
||||
}
|
||||
}
|
||||
|
||||
func simpleInteractiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||
reader := internal.NewSimpleReader()
|
||||
ttsCfg := internal.GetProjectConfig().TTS
|
||||
if ttsCfg.Enabled {
|
||||
internal.SetTTSEnabled(true)
|
||||
}
|
||||
for {
|
||||
fmt.Print(internal.GetProjectConfig().UI.UserPrefix)
|
||||
fmt.Print(internal.GetTTSPrompt(internal.GetProjectConfig().UI.UserPrefix))
|
||||
line, err := reader.ReadString()
|
||||
if err != nil {
|
||||
if err == internal.ErrEOF {
|
||||
@@ -126,12 +155,28 @@ func simpleInteractiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
|
||||
return
|
||||
}
|
||||
|
||||
runWithStreaming(agentLoop, input, sessionKey)
|
||||
isTempTTS := false
|
||||
if len(input) > 0 && input[0] == 'T' && (len(input) == 1 || input[1] == ' ') {
|
||||
input = strings.TrimPrefix(input, "T")
|
||||
input = strings.TrimPrefix(input, " ")
|
||||
isTempTTS = true
|
||||
}
|
||||
|
||||
if strings.HasPrefix(input, "/tts") {
|
||||
handleTTSCommandSimple(input)
|
||||
continue
|
||||
}
|
||||
|
||||
if isTempTTS {
|
||||
internal.ToggleTTS()
|
||||
}
|
||||
|
||||
runWithStreaming(agentLoop, input, sessionKey, isTempTTS)
|
||||
}
|
||||
}
|
||||
|
||||
// runWithStreaming 使用 ProcessDirect 处理请求,支持工具调用和结果显示
|
||||
func runWithStreaming(agentLoop *agent.AgentLoop, input, sessionKey string) {
|
||||
func runWithStreaming(agentLoop *agent.AgentLoop, input, sessionKey string, tempTTS bool) {
|
||||
startTime := time.Now()
|
||||
|
||||
spinner := internal.NewSpinner("思考中...")
|
||||
@@ -150,6 +195,11 @@ func runWithStreaming(agentLoop *agent.AgentLoop, input, sessionKey string) {
|
||||
clearSpinnerLine()
|
||||
outputLineByLine(rendered)
|
||||
|
||||
ttsCfg := internal.GetProjectConfig().TTS
|
||||
if ttsCfg.Enabled || tempTTS || internal.IsTTSEnabled() {
|
||||
go internal.SpeakText(resp)
|
||||
}
|
||||
|
||||
elapsed := time.Since(startTime)
|
||||
printElapsed(elapsed)
|
||||
}
|
||||
@@ -218,3 +268,66 @@ func formatDuration(s float64) string {
|
||||
}
|
||||
return fmt.Sprintf("%.1fs", s)
|
||||
}
|
||||
|
||||
func handleTTSCommand(input string, rl *internal.Readline, basePrompt string) {
|
||||
args := strings.Fields(input)
|
||||
if len(args) == 1 {
|
||||
enabled := internal.ToggleTTS()
|
||||
rl.SetPrompt(internal.GetTTSPrompt(basePrompt))
|
||||
status := "关闭"
|
||||
if enabled {
|
||||
status = "开启"
|
||||
}
|
||||
fmt.Printf("TTS 已%s\n", status)
|
||||
return
|
||||
}
|
||||
|
||||
switch args[1] {
|
||||
case "on":
|
||||
internal.SetTTSEnabled(true)
|
||||
rl.SetPrompt(internal.GetTTSPrompt(basePrompt))
|
||||
fmt.Println("TTS 已开启")
|
||||
case "off":
|
||||
internal.SetTTSEnabled(false)
|
||||
rl.SetPrompt(internal.GetTTSPrompt(basePrompt))
|
||||
fmt.Println("TTS 已关闭")
|
||||
case "status":
|
||||
status := "关闭"
|
||||
if internal.IsTTSEnabled() {
|
||||
status = "开启"
|
||||
}
|
||||
fmt.Printf("TTS 状态: %s\n", status)
|
||||
default:
|
||||
fmt.Println("用法: /tts [on|off|status]")
|
||||
}
|
||||
}
|
||||
|
||||
func handleTTSCommandSimple(input string) {
|
||||
args := strings.Fields(input)
|
||||
if len(args) == 1 {
|
||||
internal.ToggleTTS()
|
||||
status := "关闭"
|
||||
if internal.IsTTSEnabled() {
|
||||
status = "开启"
|
||||
}
|
||||
fmt.Printf("TTS 已%s\n", status)
|
||||
return
|
||||
}
|
||||
|
||||
switch args[1] {
|
||||
case "on":
|
||||
internal.SetTTSEnabled(true)
|
||||
fmt.Println("TTS 已开启")
|
||||
case "off":
|
||||
internal.SetTTSEnabled(false)
|
||||
fmt.Println("TTS 已关闭")
|
||||
case "status":
|
||||
status := "关闭"
|
||||
if internal.IsTTSEnabled() {
|
||||
status = "开启"
|
||||
}
|
||||
fmt.Printf("TTS 状态: %s\n", status)
|
||||
default:
|
||||
fmt.Println("用法: /tts [on|off|status]")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user