Add experimental thread prediction protocol types (#49480)

## What changed

Define `thread/prediction/request` with `threadId` and `sourceTurnId`, and `thread/prediction/updated` with a `completed` result containing optional text or a `failed` result.

Update generated JSON schemas, TypeScript types, and Python notification models. Route prediction notifications to their thread in the TUI and ignore them in the chat widget.

The request remains unimplemented and returns a method-not-found error.

GitOrigin-RevId: 09922f583d5c56f808d018121c651dcd92734515
This commit is contained in:
Keyan Zhang
2026-09-30 04:48:50 +00:00
committed by copyberry
parent 15fd656ddb
commit 90abcfac02
20 changed files with 439 additions and 2 deletions
@@ -61,6 +61,7 @@ from .v2_all import ThreadDeletedNotification
from .v2_all import ThreadGoalClearedNotification
from .v2_all import ThreadGoalUpdatedNotification
from .v2_all import ThreadNameUpdatedNotification
from .v2_all import ThreadPredictionUpdatedNotification
from .v2_all import ThreadProjectUpdatedNotification
from .v2_all import ThreadQueueChangedNotification
from .v2_all import ThreadRealtimeClosedNotification
@@ -144,6 +145,7 @@ KnownNotificationPayload: TypeAlias = (
| ThreadGoalClearedNotification
| ThreadGoalUpdatedNotification
| ThreadNameUpdatedNotification
| ThreadPredictionUpdatedNotification
| ThreadProjectUpdatedNotification
| ThreadQueueChangedNotification
| ThreadRealtimeClosedNotification
@@ -230,6 +232,7 @@ NOTIFICATION_MODELS: dict[str, type[KnownNotificationPayload]] = {
"thread/goal/cleared": ThreadGoalClearedNotification,
"thread/goal/updated": ThreadGoalUpdatedNotification,
"thread/name/updated": ThreadNameUpdatedNotification,
"thread/prediction/updated": ThreadPredictionUpdatedNotification,
"thread/project/updated": ThreadProjectUpdatedNotification,
"thread/queue/changed": ThreadQueueChangedNotification,
"thread/realtime/closed": ThreadRealtimeClosedNotification,
@@ -5613,6 +5613,39 @@ class ThreadNameUpdatedNotification(BaseModel):
thread_name: Annotated[str | None, Field(alias="threadName")] = None
class CompletedThreadPredictionResult(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
text: str | None = None
type: Annotated[Literal["completed"], Field(title="CompletedThreadPredictionResultType")]
class FailedThreadPredictionResult(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
type: Annotated[Literal["failed"], Field(title="FailedThreadPredictionResultType")]
class ThreadPredictionResult(
RootModel[CompletedThreadPredictionResult | FailedThreadPredictionResult]
):
model_config = ConfigDict(
populate_by_name=True,
)
root: CompletedThreadPredictionResult | FailedThreadPredictionResult
class ThreadPredictionUpdatedNotification(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
result: ThreadPredictionResult
source_turn_id: Annotated[str, Field(alias="sourceTurnId")]
thread_id: Annotated[str, Field(alias="threadId")]
class ThreadProjectUpdatedNotification(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -9178,6 +9211,24 @@ class ThreadAttachmentUpdatedServerNotification(BaseModel):
params: ThreadAttachmentUpdatedNotification
class ThreadPredictionUpdatedServerNotification(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
emitted_at_ms: Annotated[
int | None,
Field(
alias="emittedAtMs",
description="Unix timestamp (in milliseconds) when app-server emitted this notification.",
),
] = None
method: Annotated[
Literal["thread/prediction/updated"],
Field(title="Thread/prediction/updatedNotificationMethod"),
]
params: ThreadPredictionUpdatedNotification
class ThreadGoalClearedServerNotification(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
@@ -12859,6 +12910,7 @@ class ServerNotification(
| ThreadNameUpdatedServerNotification
| ThreadAttachmentUpdatedServerNotification
| ThreadGoalUpdatedServerNotification
| ThreadPredictionUpdatedServerNotification
| ThreadGoalClearedServerNotification
| ThreadQueueChangedServerNotification
| ProjectChangedServerNotification
@@ -12948,6 +13000,7 @@ class ServerNotification(
| ThreadNameUpdatedServerNotification
| ThreadAttachmentUpdatedServerNotification
| ThreadGoalUpdatedServerNotification
| ThreadPredictionUpdatedServerNotification
| ThreadGoalClearedServerNotification
| ThreadQueueChangedServerNotification
| ProjectChangedServerNotification