StructuredResponse.fromActionResult constructor
StructuredResponse.fromActionResult(
- ActionResult r, {
- bool detail = false,
Builds a response from an ActionResult. The envelope already carries
summary/warnings/nextSteps at the top level, so those are dropped
from data rather than duplicated. Geometry (painted, hittable,
logicalCenter) is omitted unless detail is true; the agent only needs
ok + the changed-signal to continue. The failure reason is routed to the
shared detail key so it surfaces in prose and the action log.
Implementation
factory StructuredResponse.fromActionResult(
ActionResult r, {
bool detail = false,
}) {
const dup = {'summary', 'warnings', 'nextSteps', 'error'};
const geometry = {'painted', 'hittable', 'physicalCenter', 'logicalCenter'};
final data = <String, Object?>{
for (final e in r.toJson().entries)
if (!dup.contains(e.key) && (detail || !geometry.contains(e.key))) e.key: e.value,
};
if (r.error != null) data['detail'] = r.error;
return StructuredResponse(
summary: r.summary,
warnings: r.warnings,
nextSteps: r.nextSteps,
isError: !r.ok,
data: data,
);
}