mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-20 02:07:29 +08:00
normalize-policy phase-9: preserve raw task/model/content in nodes/sessions tools
This commit is contained in:
@@ -113,7 +113,7 @@ func (t *NodesTool) Execute(ctx context.Context, args map[string]interface{}) (s
|
|||||||
return "", fmt.Errorf("invalid_args: canvas_action requires args.action")
|
return "", fmt.Errorf("invalid_args: canvas_action requires args.action")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req := nodes.Request{Action: action, Node: nodeID, Task: strings.TrimSpace(task), Model: strings.TrimSpace(model), Args: reqArgs}
|
req := nodes.Request{Action: action, Node: nodeID, Task: task, Model: model, Args: reqArgs}
|
||||||
started := time.Now()
|
started := time.Now()
|
||||||
resp, err := t.router.Dispatch(ctx, req, mode)
|
resp, err := t.router.Dispatch(ctx, req, mode)
|
||||||
durationMs := int(time.Since(started).Milliseconds())
|
durationMs := int(time.Since(started).Milliseconds())
|
||||||
@@ -134,7 +134,7 @@ func (t *NodesTool) writeAudit(req nodes.Request, resp nodes.Response, mode stri
|
|||||||
_ = os.MkdirAll(filepath.Dir(t.auditPath), 0755)
|
_ = os.MkdirAll(filepath.Dir(t.auditPath), 0755)
|
||||||
row := map[string]interface{}{
|
row := map[string]interface{}{
|
||||||
"time": time.Now().UTC().Format(time.RFC3339),
|
"time": time.Now().UTC().Format(time.RFC3339),
|
||||||
"mode": strings.TrimSpace(mode),
|
"mode": mode,
|
||||||
"action": req.Action,
|
"action": req.Action,
|
||||||
"node": req.Node,
|
"node": req.Node,
|
||||||
"task": req.Task,
|
"task": req.Task,
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
if query != "" {
|
if query != "" {
|
||||||
filtered := make([]SessionInfo, 0, len(items))
|
filtered := make([]SessionInfo, 0, len(items))
|
||||||
for _, s := range items {
|
for _, s := range items {
|
||||||
blob := strings.ToLower(strings.TrimSpace(s.Key + "\n" + s.Kind + "\n" + s.Summary))
|
blob := strings.ToLower(s.Key + "\n" + s.Kind + "\n" + s.Summary)
|
||||||
if strings.Contains(blob, query) {
|
if strings.Contains(blob, query) {
|
||||||
filtered = append(filtered, s)
|
filtered = append(filtered, s)
|
||||||
}
|
}
|
||||||
@@ -157,13 +157,13 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
for _, s := range items {
|
for _, s := range items {
|
||||||
sb.WriteString(fmt.Sprintf("- %s kind=%s compactions=%d updated=%s\n", s.Key, s.Kind, s.CompactionCount, s.UpdatedAt.Format(time.RFC3339)))
|
sb.WriteString(fmt.Sprintf("- %s kind=%s compactions=%d updated=%s\n", s.Key, s.Kind, s.CompactionCount, s.UpdatedAt.Format(time.RFC3339)))
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(sb.String()), nil
|
return sb.String(), nil
|
||||||
case "history":
|
case "history":
|
||||||
if t.historyFn == nil {
|
if t.historyFn == nil {
|
||||||
return "sessions history unavailable", nil
|
return "sessions history unavailable", nil
|
||||||
}
|
}
|
||||||
key, _ := args["key"].(string)
|
key, _ := args["key"].(string)
|
||||||
key = strings.TrimSpace(key)
|
key = key
|
||||||
if key == "" {
|
if key == "" {
|
||||||
return "key is required for history", nil
|
return "key is required for history", nil
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
if !includeTools {
|
if !includeTools {
|
||||||
filtered := make([]indexedMsg, 0, len(window))
|
filtered := make([]indexedMsg, 0, len(window))
|
||||||
for _, m := range window {
|
for _, m := range window {
|
||||||
if strings.TrimSpace(strings.ToLower(m.msg.Role)) == "tool" {
|
if strings.ToLower(m.msg.Role) == "tool" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
filtered = append(filtered, m)
|
filtered = append(filtered, m)
|
||||||
@@ -239,7 +239,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
if roleFilter != "" {
|
if roleFilter != "" {
|
||||||
filtered := make([]indexedMsg, 0, len(window))
|
filtered := make([]indexedMsg, 0, len(window))
|
||||||
for _, m := range window {
|
for _, m := range window {
|
||||||
if strings.ToLower(strings.TrimSpace(m.msg.Role)) == roleFilter {
|
if strings.ToLower(m.msg.Role) == roleFilter {
|
||||||
filtered = append(filtered, m)
|
filtered = append(filtered, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +252,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
}
|
}
|
||||||
filtered := make([]indexedMsg, 0, len(window))
|
filtered := make([]indexedMsg, 0, len(window))
|
||||||
for _, m := range window {
|
for _, m := range window {
|
||||||
if strings.ToLower(strings.TrimSpace(m.msg.Role)) == targetRole {
|
if strings.ToLower(m.msg.Role) == targetRole {
|
||||||
filtered = append(filtered, m)
|
filtered = append(filtered, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
if query != "" {
|
if query != "" {
|
||||||
filtered := make([]indexedMsg, 0, len(window))
|
filtered := make([]indexedMsg, 0, len(window))
|
||||||
for _, m := range window {
|
for _, m := range window {
|
||||||
blob := strings.ToLower(strings.TrimSpace(m.msg.Role + "\n" + m.msg.Content))
|
blob := strings.ToLower(m.msg.Role + "\n" + m.msg.Content)
|
||||||
if strings.Contains(blob, query) {
|
if strings.Contains(blob, query) {
|
||||||
filtered = append(filtered, m)
|
filtered = append(filtered, m)
|
||||||
}
|
}
|
||||||
@@ -283,14 +283,14 @@ func (t *SessionsTool) Execute(ctx context.Context, args map[string]interface{})
|
|||||||
}
|
}
|
||||||
sb.WriteString(fmt.Sprintf("- [#%d][%s] %s\n", item.idx, item.msg.Role, content))
|
sb.WriteString(fmt.Sprintf("- [#%d][%s] %s\n", item.idx, item.msg.Role, content))
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(sb.String()), nil
|
return sb.String(), nil
|
||||||
default:
|
default:
|
||||||
return firstNonEmpty(t.unsupportedAction, "unsupported action"), nil
|
return firstNonEmpty(t.unsupportedAction, "unsupported action"), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func firstNonEmpty(v, fallback string) string {
|
func firstNonEmpty(v, fallback string) string {
|
||||||
if strings.TrimSpace(v) != "" {
|
if v != "" {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
return fallback
|
return fallback
|
||||||
|
|||||||
Reference in New Issue
Block a user