MCPcopy Index your code
hub / github.com/anomalyco/opencode / splitTurn

Function splitTurn

packages/opencode/src/session/compaction.ts:105–128  ·  view source on GitHub ↗
(input: {
  messages: SessionV1.WithParts[]
  turn: Turn
  model: Provider.Model
  budget: number
  estimate: (input: { messages: SessionV1.WithParts[]; model: Provider.Model }) => Effect.Effect<number>
})

Source from the content-addressed store, hash-verified

103}
104
105function 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
130export interface Interface {
131 readonly isOverflow: (input: {

Callers 1

compaction.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected