feat: add stateful responses API
This commit is contained in:
@@ -424,6 +424,52 @@ class RealtimeApiKey(Base):
|
||||
)
|
||||
|
||||
|
||||
class OpenAIResponse(Base):
|
||||
"""Persisted state for one public Responses API generation."""
|
||||
|
||||
__tablename__ = "openai_responses"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(40), primary_key=True)
|
||||
api_key_id: Mapped[str] = mapped_column(
|
||||
String(40),
|
||||
ForeignKey("realtime_api_keys.id", ondelete="CASCADE"),
|
||||
index=True,
|
||||
)
|
||||
assistant_id: Mapped[str | None] = mapped_column(
|
||||
String(40),
|
||||
ForeignKey("assistants.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
index=True,
|
||||
)
|
||||
conversation_id: Mapped[str] = mapped_column(
|
||||
String(40),
|
||||
ForeignKey("conversation_sessions.id", ondelete="CASCADE"),
|
||||
index=True,
|
||||
)
|
||||
previous_response_id: Mapped[str | None] = mapped_column(
|
||||
String(40),
|
||||
ForeignKey("openai_responses.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
index=True,
|
||||
)
|
||||
status: Mapped[str] = mapped_column(String(16), index=True, default="in_progress")
|
||||
input_items: Mapped[list] = mapped_column(JSONB, default=list)
|
||||
output_items: Mapped[list] = mapped_column(JSONB, default=list)
|
||||
context_messages: Mapped[list] = mapped_column(JSONB, default=list)
|
||||
runtime_state: Mapped[dict] = mapped_column(JSONB, default=dict)
|
||||
error: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
|
||||
dynamic_variables: Mapped[dict] = mapped_column(JSONB, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
completed_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
|
||||
class WebhookDelivery(Base):
|
||||
"""Immutable event snapshot plus its asynchronous delivery state."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user