mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-13 07:46:54 +08:00
change v1
This commit is contained in:
@@ -89,7 +89,7 @@ func slotDisplayName(slot, lang string) string {
|
||||
case "exchange_type":
|
||||
return "交易所类型"
|
||||
case "provider":
|
||||
return "provider"
|
||||
return "模型提供商"
|
||||
default:
|
||||
return slot
|
||||
}
|
||||
@@ -115,6 +115,39 @@ func formatAwaitConfirmationMessage(lang, action, targetLabel string) string {
|
||||
return fmt.Sprintf("You are about to %s %q. Please reply 'confirm' to continue or 'cancel' to stop.", actionLabel, targetLabel)
|
||||
}
|
||||
|
||||
func formatTargetConfirmationLabel(lang string, session *skillSession, targetLabel string) string {
|
||||
targetLabel = strings.TrimSpace(targetLabel)
|
||||
if session == nil || session.TargetRef == nil || targetLabel == "" {
|
||||
return targetLabel
|
||||
}
|
||||
source := strings.TrimSpace(session.TargetRef.Source)
|
||||
if source == "" {
|
||||
return targetLabel
|
||||
}
|
||||
if lang == "zh" {
|
||||
sourceLabel := "系统上下文"
|
||||
switch source {
|
||||
case "user_mention":
|
||||
sourceLabel = "你刚才点名的对象"
|
||||
case "tool_output":
|
||||
sourceLabel = "刚刚工具返回的对象"
|
||||
case "inferred_from_context":
|
||||
sourceLabel = "上下文推断对象"
|
||||
}
|
||||
return fmt.Sprintf("%s(当前识别来源:%s)", targetLabel, sourceLabel)
|
||||
}
|
||||
sourceLabel := "context"
|
||||
switch source {
|
||||
case "user_mention":
|
||||
sourceLabel = "your explicit mention"
|
||||
case "tool_output":
|
||||
sourceLabel = "recent tool output"
|
||||
case "inferred_from_context":
|
||||
sourceLabel = "context inference"
|
||||
}
|
||||
return fmt.Sprintf("%s (current reference source: %s)", targetLabel, sourceLabel)
|
||||
}
|
||||
|
||||
func formatStillWaitingConfirmationMessage(lang string) string {
|
||||
if lang == "zh" {
|
||||
return "当前流程仍在等待你确认。回复“确认”继续,或“取消”终止。"
|
||||
@@ -122,13 +155,80 @@ func formatStillWaitingConfirmationMessage(lang string) string {
|
||||
return "This flow is still waiting for your confirmation."
|
||||
}
|
||||
|
||||
func beginConfirmationIfNeeded(userID int64, lang string, session *skillSession, targetLabel string) (string, bool) {
|
||||
func referenceKindForSkill(skillName string) string {
|
||||
switch strings.TrimSpace(skillName) {
|
||||
case "strategy_management":
|
||||
return "strategy"
|
||||
case "trader_management":
|
||||
return "trader"
|
||||
case "model_management":
|
||||
return "model"
|
||||
case "exchange_management":
|
||||
return "exchange"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func referenceKindDisplayName(lang, kind string) string {
|
||||
if lang == "zh" {
|
||||
switch kind {
|
||||
case "strategy":
|
||||
return "策略"
|
||||
case "trader":
|
||||
return "交易员"
|
||||
case "model":
|
||||
return "模型"
|
||||
case "exchange":
|
||||
return "交易所"
|
||||
}
|
||||
return "对象"
|
||||
}
|
||||
return kind
|
||||
}
|
||||
|
||||
func (a *Agent) formatConfirmationTargetLabel(userID int64, lang string, session *skillSession, targetLabel string) string {
|
||||
label := formatTargetConfirmationLabel(lang, session, targetLabel)
|
||||
if session == nil || session.TargetRef == nil {
|
||||
return label
|
||||
}
|
||||
kind := referenceKindForSkill(session.Name)
|
||||
if kind == "" {
|
||||
return label
|
||||
}
|
||||
state := a.getExecutionState(userID)
|
||||
recentNames := map[string]struct{}{}
|
||||
for _, item := range state.ReferenceHistory {
|
||||
if item.Kind != kind {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSpace(defaultIfEmpty(item.Name, item.ID))
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
recentNames[name] = struct{}{}
|
||||
}
|
||||
targetName := strings.TrimSpace(defaultIfEmpty(session.TargetRef.Name, session.TargetRef.ID))
|
||||
_, inferred := recentNames[targetName]
|
||||
if targetName == "" {
|
||||
return label
|
||||
}
|
||||
if len(recentNames) <= 1 && strings.TrimSpace(session.TargetRef.Source) != "inferred_from_context" && inferred {
|
||||
return label
|
||||
}
|
||||
if lang == "zh" {
|
||||
return fmt.Sprintf("%s。系统当前理解你要操作的%s是“%s”。", label, referenceKindDisplayName(lang, kind), targetName)
|
||||
}
|
||||
return fmt.Sprintf("%s. The current %s I'm about to operate on is %q.", label, referenceKindDisplayName(lang, kind), targetName)
|
||||
}
|
||||
|
||||
func (a *Agent) beginConfirmationIfNeeded(userID int64, lang string, session *skillSession, targetLabel string) (string, bool) {
|
||||
if session == nil || !actionNeedsConfirmation(session.Name, session.Action) {
|
||||
return "", false
|
||||
}
|
||||
if session.Phase != "await_confirmation" {
|
||||
session.Phase = "await_confirmation"
|
||||
return formatAwaitConfirmationMessage(lang, session.Action, targetLabel), true
|
||||
return formatAwaitConfirmationMessage(lang, session.Action, a.formatConfirmationTargetLabel(userID, lang, session, targetLabel)), true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user