| 103 | } |
| 104 | |
| 105 | function splitTurn(input: { |
| 106 | messages: SessionV1.WithParts[] |
| 107 | turn: Turn |
| 108 | model: Provider.Model |
| 109 | budget: number |
| 110 | estimate: (input: { messages: SessionV1.WithParts[]; model: Provider.Model }) => Effect.Effect<number> |
| 111 | }) { |
| 112 | return Effect.gen(function* () { |
| 113 | if (input.budget <= 0) return undefined |
| 114 | if (input.turn.end - input.turn.start <= 1) return undefined |
| 115 | for (let start = input.turn.start + 1; start < input.turn.end; start++) { |
| 116 | const size = yield* input.estimate({ |
| 117 | messages: input.messages.slice(start, input.turn.end), |
| 118 | model: input.model, |
| 119 | }) |
| 120 | if (size > input.budget) continue |
| 121 | return { |
| 122 | start, |
| 123 | id: input.messages[start]!.info.id, |
| 124 | } satisfies Tail |
| 125 | } |
| 126 | return undefined |
| 127 | }) |
| 128 | } |
| 129 | |
| 130 | export interface Interface { |
| 131 | readonly isOverflow: (input: { |