| 771 | // question.* → manage the question queue, drive footer view |
| 772 | // session.error → emit error scrollback entry |
| 773 | export function reduceSessionData(input: SessionDataInput): SessionDataOutput { |
| 774 | const commits: SessionCommit[] = [] |
| 775 | const data = input.data |
| 776 | const event = input.event |
| 777 | |
| 778 | if (event.type === "session.next.shell.started") { |
| 779 | if (event.properties.sessionID !== input.sessionID) { |
| 780 | return out(data, commits) |
| 781 | } |
| 782 | |
| 783 | const shell = claimShell(data, event.properties.callID, "shell", event.properties.command) |
| 784 | if (shell.source !== "shell") { |
| 785 | return out(data, commits) |
| 786 | } |
| 787 | |
| 788 | const partID = shellPartID(event.properties.callID) |
| 789 | if (data.ids.has(partID) || data.tools.has(partID)) { |
| 790 | return out(data, commits, patch({ status: "running shell" })) |
| 791 | } |
| 792 | |
| 793 | data.tools.add(partID) |
| 794 | commits.push(startShell(event.properties.callID, shell.command ?? event.properties.command)) |
| 795 | return out(data, commits, patch({ status: "running shell" })) |
| 796 | } |
| 797 | |
| 798 | if (event.type === "session.next.shell.ended") { |
| 799 | if (event.properties.sessionID !== input.sessionID) { |
| 800 | return out(data, commits) |
| 801 | } |
| 802 | |
| 803 | const shell = claimShell(data, event.properties.callID, "shell") |
| 804 | if (shell.source !== "shell") { |
| 805 | return out(data, commits) |
| 806 | } |
| 807 | |
| 808 | const partID = shellPartID(event.properties.callID) |
| 809 | const seen = data.tools.has(partID) |
| 810 | const command = shell.command ?? "" |
| 811 | data.tools.delete(partID) |
| 812 | if (data.ids.has(partID)) { |
| 813 | return out(data, commits) |
| 814 | } |
| 815 | |
| 816 | if (!seen && command) { |
| 817 | commits.push(startShell(event.properties.callID, command)) |
| 818 | } |
| 819 | |
| 820 | data.ids.add(partID) |
| 821 | commits.push(doneShell(event.properties.callID, command, event.properties.output)) |
| 822 | return out(data, commits) |
| 823 | } |
| 824 | |
| 825 | if (event.type === "message.updated") { |
| 826 | if (event.properties.sessionID !== input.sessionID) { |
| 827 | return out(data, commits) |
| 828 | } |
| 829 | |
| 830 | const info = event.properties.info |