diff --git a/ai-service-admin/src/api/mid-platform.ts b/ai-service-admin/src/api/mid-platform.ts index c9a87b5..9ec7f80 100644 --- a/ai-service-admin/src/api/mid-platform.ts +++ b/ai-service-admin/src/api/mid-platform.ts @@ -146,6 +146,20 @@ export interface SharedSessionInfo { history: DialogueMessage[] } +export interface CreatePublicShareTokenRequest { + tenant_id?: string + api_key?: string + session_id: string + user_id?: string + expires_in_minutes?: number +} + +export interface CreatePublicShareTokenResponse { + share_token: string + share_url: string + expires_at: string +} + export function createShare(sessionId: string, data: CreateShareRequest = {}): Promise { return request({ url: `/mid/sessions/${sessionId}/share`, @@ -154,6 +168,14 @@ export function createShare(sessionId: string, data: CreateShareRequest = {}): P }) } +export function createPublicShareToken(data: CreatePublicShareTokenRequest): Promise { + return request({ + url: '/openapi/v1/share/token', + method: 'post', + data + }) +} + export function getSharedSession(shareToken: string): Promise { return request({ url: `/mid/share/${shareToken}`, diff --git a/ai-service/app/api/mid/share.py b/ai-service/app/api/mid/share.py index 3e1f329..26221c6 100644 --- a/ai-service/app/api/mid/share.py +++ b/ai-service/app/api/mid/share.py @@ -33,8 +33,15 @@ settings = get_settings() def _utcnow() -> datetime: - """Get current UTC time with timezone info.""" - return datetime.now(timezone.utc) + """Get current UTC time without timezone info (for DB compatibility).""" + return datetime.utcnow() + + +def _normalize_datetime(dt: datetime) -> datetime: + """Normalize datetime to offset-naive UTC for comparison.""" + if dt.tzinfo is not None: + return dt.replace(tzinfo=None) + return dt def _generate_share_url(share_token: str) -> str: @@ -136,7 +143,7 @@ async def get_shared_session( if not shared.is_active: raise HTTPException(status_code=410, detail="Share is inactive") - if shared.expires_at < _utcnow(): + if _normalize_datetime(shared.expires_at) < _utcnow(): raise HTTPException(status_code=410, detail="Share has expired") if shared.current_users >= shared.max_concurrent_users: @@ -216,7 +223,7 @@ async def list_shares( title=s.title, description=s.description, expires_at=s.expires_at.isoformat(), - is_active=s.is_active and s.expires_at > now, + is_active=s.is_active and _normalize_datetime(s.expires_at) > now, max_concurrent_users=s.max_concurrent_users, current_users=s.current_users, created_at=s.created_at.isoformat(), @@ -303,7 +310,7 @@ async def join_shared_session( if not shared.is_active: raise HTTPException(status_code=410, detail="Share is inactive") - if shared.expires_at < _utcnow(): + if _normalize_datetime(shared.expires_at) < _utcnow(): raise HTTPException(status_code=410, detail="Share has expired") if shared.current_users >= shared.max_concurrent_users: @@ -410,7 +417,7 @@ async def send_shared_message( if not shared.is_active: raise HTTPException(status_code=410, detail="Share is inactive") - if shared.expires_at < _utcnow(): + if _normalize_datetime(shared.expires_at) < _utcnow(): raise HTTPException(status_code=410, detail="Share has expired") user_message = ChatMessage(