Files
codex/sdk/python/src/openai_codex/models.py
Ahmed Ibrahim 45134c0463 Generate Python SDK types from repository app-server schemas (#44032)
## Why

Keep Python protocol models aligned with the checked-in app-server schemas and preserve reviewed generated artifacts when staging SDK releases.

## What changed

- Generate SDK types from the schema directory configured in `pyproject.toml`, with a `--schema-dir` override, instead of invoking the pinned runtime binary.
- Refresh Python artifacts through `just write-app-server-schema` for standard repository exports. Skip SDK updates for scratch and experimental exports.
- Regenerate protocol models and notification dispatch, deriving the known payload union from the registry so `Notification.payload` covers every registered event.
- Explicitly allowlist convenience API parameters so new protocol fields do not silently expand method signatures. Preserve existing approval path wrappers.
- Stage SDK releases using checked-in generated files without regenerating them.

## Testing

Add coverage for schema selection, refresh gating and failure handling, release artifact preservation, notification payload typing, and approval path compatibility. Update the generation drift test to use repository schemas.

GitOrigin-RevId: fab350b07cf170258b91fbafa8da384aeb2e3bd7
2026-09-09 03:27:31 +00:00

77 lines
3.3 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from typing import TypeAlias
from pydantic import BaseModel
from .generated.notification_registry import KnownNotificationPayload as _KnownNotificationPayload
# Preserve the notification names previously importable from this module.
from .generated.v2_all import (
AccountLoginCompletedNotification as AccountLoginCompletedNotification,
AccountRateLimitsUpdatedNotification as AccountRateLimitsUpdatedNotification,
AccountUpdatedNotification as AccountUpdatedNotification,
AgentMessageDeltaNotification as AgentMessageDeltaNotification,
AppListUpdatedNotification as AppListUpdatedNotification,
CommandExecutionOutputDeltaNotification as CommandExecutionOutputDeltaNotification,
ConfigWarningNotification as ConfigWarningNotification,
ContextCompactedNotification as ContextCompactedNotification,
DeprecationNoticeNotification as DeprecationNoticeNotification,
ErrorNotification as ErrorNotification,
FileChangeOutputDeltaNotification as FileChangeOutputDeltaNotification,
ItemCompletedNotification as ItemCompletedNotification,
ItemStartedNotification as ItemStartedNotification,
McpServerOauthLoginCompletedNotification as McpServerOauthLoginCompletedNotification,
McpToolCallProgressNotification as McpToolCallProgressNotification,
PlanDeltaNotification as PlanDeltaNotification,
RawResponseItemCompletedNotification as RawResponseItemCompletedNotification,
ReasoningSummaryPartAddedNotification as ReasoningSummaryPartAddedNotification,
ReasoningSummaryTextDeltaNotification as ReasoningSummaryTextDeltaNotification,
ReasoningTextDeltaNotification as ReasoningTextDeltaNotification,
TerminalInteractionNotification as TerminalInteractionNotification,
ThreadGoalClearedNotification as ThreadGoalClearedNotification,
ThreadGoalUpdatedNotification as ThreadGoalUpdatedNotification,
ThreadNameUpdatedNotification as ThreadNameUpdatedNotification,
ThreadStartedNotification as ThreadStartedNotification,
ThreadTokenUsageUpdatedNotification as ThreadTokenUsageUpdatedNotification,
TurnCompletedNotification as TurnCompletedNotification,
TurnDiffUpdatedNotification as TurnDiffUpdatedNotification,
TurnPlanUpdatedNotification as TurnPlanUpdatedNotification,
TurnStartedNotification as TurnStartedNotification,
WindowsWorldWritableWarningNotification as WindowsWorldWritableWarningNotification,
)
JsonScalar: TypeAlias = str | int | float | bool | None
JsonValue: TypeAlias = JsonScalar | dict[str, "JsonValue"] | list["JsonValue"]
JsonObject: TypeAlias = dict[str, JsonValue]
@dataclass(slots=True)
class UnknownNotification:
params: JsonObject
# Preserve the existing raw-item type, which app-server omits from its notification schema.
NotificationPayload: TypeAlias = (
_KnownNotificationPayload | RawResponseItemCompletedNotification | UnknownNotification
)
@dataclass(slots=True)
class Notification:
method: str
payload: NotificationPayload
class ServerInfo(BaseModel):
name: str | None = None
version: str | None = None
class InitializeResponse(BaseModel):
serverInfo: ServerInfo | None = None
userAgent: str | None = None
platformFamily: str | None = None
platformOs: str | None = None