compose method
Returns the patch that applies this patch first and then next.
The result satisfies the composition law
apply(x) == next.apply(apply(x)).
Implementation
@override
AgentSessionDocumentPatch compose(ZorphyPatch<AgentSessionDocument> next) {
if (next.isEmpty) return this;
if (next is! AgentSessionDocumentPatch) {
throw ArgumentError.value(
next,
'next',
'AgentSessionDocumentPatch cannot compose ${next.runtimeType}',
);
}
if (isEmpty) return next;
return AgentSessionDocumentPatch(
id: next.id.isUnchanged ? this.id : next.id,
status: next.status.isUnchanged ? this.status : next.status,
messages: next.messages.isUnchanged ? this.messages : next.messages,
toolCalls: next.toolCalls.isUnchanged ? this.toolCalls : next.toolCalls,
activeTool: next.activeTool.isUnchanged
? this.activeTool
: next.activeTool,
turns: next.turns.isUnchanged ? this.turns : next.turns,
);
}