MCPcopy
hub / github.com/openai/openai-agents-python / _apply_chunks

Function _apply_chunks

src/agents/apply_diff.py:320–344  ·  view source on GitHub ↗
(input: str, chunks: list[Chunk], newline: str)

Source from the content-addressed store, hash-verified

318
319
320def _apply_chunks(input: str, chunks: list[Chunk], newline: str) -> str:
321 orig_lines = input.split("\n")
322 dest_lines: list[str] = []
323 cursor = 0
324
325 for chunk in chunks:
326 if chunk.orig_index > len(orig_lines):
327 raise ValueError(
328 f"applyDiff: chunk.origIndex {chunk.orig_index} > input length {len(orig_lines)}"
329 )
330 if cursor > chunk.orig_index:
331 raise ValueError(
332 f"applyDiff: overlapping chunk at {chunk.orig_index} (cursor {cursor})"
333 )
334
335 dest_lines.extend(orig_lines[cursor : chunk.orig_index])
336 cursor = chunk.orig_index
337
338 if chunk.ins_lines:
339 dest_lines.extend(chunk.ins_lines)
340
341 cursor += len(chunk.del_lines)
342
343 dest_lines.extend(orig_lines[cursor:])
344 return newline.join(dest_lines)
345
346
347__all__ = ["apply_diff"]

Callers 2

apply_diffFunction · 0.85

Calls

no outgoing calls

Tested by 1