mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
Add item anchors to thread/items/list pagination (#48151)
## What changed
Allow `cursor` to accept an item anchor such as `{"type":"item","itemId":"item-123"}` with a non-empty `turnId`. Ascending pagination returns items after the anchor; descending pagination returns items before it. The anchor itself is excluded, and subsequent pages use the returned opaque string cursor.
Resolve anchors within the requested turn's visible history, including inherited fork history. Reject missing turn IDs and empty, unknown, or out-of-scope item IDs with invalid params (`-32602`). Preserve existing string and null cursor behavior, and update the protocol schemas, TypeScript and Python types, and API documentation.
## Testing
Add protocol round-trip and invalid-shape tests, app-server coverage for anchored pagination and errors, and thread-store coverage for growing turns, reverse pagination, page boundaries, fork visibility, and anchor scope validation.
GitOrigin-RevId: a74cea190d3ff1b44865429f8b0650b793eb688d
This commit is contained in:
@@ -5455,14 +5455,42 @@ class ContextCompactionThreadItem(BaseModel):
|
||||
type: Annotated[Literal["contextCompaction"], Field(title="ContextCompactionThreadItemType")]
|
||||
|
||||
|
||||
class ItemThreadItemsListAnchor(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
item_id: Annotated[str, Field(alias="itemId")]
|
||||
type: Annotated[Literal["item"], Field(title="ItemThreadItemsListAnchorType")]
|
||||
|
||||
|
||||
class ThreadItemsListAnchor(RootModel[ItemThreadItemsListAnchor]):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
root: Annotated[
|
||||
ItemThreadItemsListAnchor,
|
||||
Field(description="An exclusive item position within the requested visible turn."),
|
||||
]
|
||||
|
||||
|
||||
class ThreadItemsListCursor(RootModel[str | ThreadItemsListAnchor]):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
root: Annotated[
|
||||
str | ThreadItemsListAnchor,
|
||||
Field(description="Starting position for an item-history page."),
|
||||
]
|
||||
|
||||
|
||||
class ThreadItemsListParams(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
cursor: Annotated[
|
||||
str | None,
|
||||
ThreadItemsListCursor | None,
|
||||
Field(
|
||||
description="Opaque cursor to pass to the next call to continue after the last item."
|
||||
description="Opaque continuation cursor or an exclusive item anchor in the requested visible turn. An item anchor requires a non-empty `turnId`; ascending (the default) returns items after it, and descending returns items before it. Continue with the returned string cursor."
|
||||
),
|
||||
] = None
|
||||
limit: Annotated[int | None, Field(description="Optional item page size.", ge=0)] = None
|
||||
|
||||
Reference in New Issue
Block a user