Add `acp_wait_agent` to stream ACP transcripts, including reasoning and nested tool activity, to users while returning the subagent's text response to the parent model. Reconnect dropped streams from their transcript cursor, preserve running sessions on wait timeout or cancellation, and persist separate user-visible and model-visible results. Depends on #31022. Generated with Codex, carefully reviewed by Hugo.
34 lines
945 B
Go
34 lines
945 B
Go
package chattool
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"charm.land/fantasy"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
// WithUserResult attaches a user-visible result without adding it to the
|
|
// model's tool response. The persistence layer stores both projections.
|
|
func WithUserResult(response fantasy.ToolResponse, result any) fantasy.ToolResponse {
|
|
return fantasy.WithResponseMetadata(response, struct {
|
|
UserResult any `json:"user_result"`
|
|
}{UserResult: result})
|
|
}
|
|
|
|
// UserResultFromMetadata reads an optional user-visible tool projection.
|
|
func UserResultFromMetadata(metadata string) (json.RawMessage, error) {
|
|
if metadata == "" {
|
|
return nil, nil
|
|
}
|
|
var decoded struct {
|
|
UserResult json.RawMessage `json:"user_result"`
|
|
}
|
|
if err := json.Unmarshal([]byte(metadata), &decoded); err != nil {
|
|
return nil, xerrors.Errorf("decode user tool result: %w", err)
|
|
}
|
|
if string(decoded.UserResult) == "null" {
|
|
return nil, nil
|
|
}
|
|
return decoded.UserResult, nil
|
|
}
|