Keep tool group keys unique across transcript
This commit is contained in:
1 parent
f00a178cf0
commit
947ea8ecf2
2 files changed
+35
-12
No files matched your search
@@ -113,24 +113,27 @@ private fun groupRuns(
|
||||
): List<TranscriptRow> {
|
||||
val rows = mutableListOf<TranscriptRow>()
|
||||
var run = mutableListOf<TranscriptItem.ToolRun>()
|
||||
// The run being walked, and how many rows it has produced so far -- which is what decides the
|
||||
// keys below.
|
||||
// A run can occupy more than one non-adjacent piece, so claimed keys span the whole transcript
|
||||
// rather than resetting at each piece.
|
||||
var runId: String? = null
|
||||
var emitted = 0
|
||||
val claimedKeys = mutableSetOf<String>()
|
||||
|
||||
fun flush() {
|
||||
val first = run.firstOrNull() ?: return
|
||||
// The first row a run produces keeps the run's name, which is the name that survives a page
|
||||
// of history landing in front of it ([adoptRun]); losing it is the transcript stepping
|
||||
// under whoever is reading. The pieces a call standing on its own cuts off the back of the
|
||||
// run have no such name, so each takes its own first call's id, which is unique because a
|
||||
// call id is. The run's name goes in front of it because the two can otherwise be the same
|
||||
// string: the call a run was named after can itself be the one standing on its own.
|
||||
val key = if (emitted == 0) first.runId else "${first.runId}/${first.id}"
|
||||
// The first piece keeps the run's name, which survives a page landing in front of it
|
||||
// ([adoptRun]). Later pieces qualify that name with their first call; the suffix is the
|
||||
// final guard because a duplicate LazyColumn key takes down the whole screen.
|
||||
var key = first.runId
|
||||
if (!claimedKeys.add(key)) {
|
||||
key = "${first.runId}/${first.id}"
|
||||
var suffix = 2
|
||||
while (!claimedKeys.add(key)) {
|
||||
key = "${first.runId}/${first.id}/${suffix++}"
|
||||
}
|
||||
}
|
||||
rows +=
|
||||
if (run.size == 1) TranscriptRow.Single(first, key)
|
||||
else TranscriptRow.Tools(run.toList(), key)
|
||||
emitted++
|
||||
run = mutableListOf()
|
||||
}
|
||||
|
||||
@@ -143,7 +146,6 @@ private fun groupRuns(
|
||||
if (call == null || call.runId != runId) {
|
||||
flush()
|
||||
runId = call?.runId
|
||||
emitted = 0
|
||||
}
|
||||
when {
|
||||
call == null -> rows += TranscriptRow.Single(item)
|
||||
|
||||
Reference in new issue
Block a user