6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
"""External chat binding helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.db import (
|
|
ChatVisibility,
|
|
ExternalChatBinding,
|
|
ExternalChatBindingState,
|
|
NewChatThread,
|
|
)
|
|
|
|
|
|
async def get_or_create_thread_for_binding(
|
|
session: AsyncSession,
|
|
binding: ExternalChatBinding,
|
|
) -> NewChatThread:
|
|
if binding.new_chat_thread_id is not None:
|
|
result = await session.execute(
|
|
select(NewChatThread).where(NewChatThread.id == binding.new_chat_thread_id)
|
|
)
|
|
thread = result.scalars().first()
|
|
if thread is not None and not thread.archived:
|
|
return thread
|
|
|
|
source = str((binding.external_metadata or {}).get("platform") or "").strip()
|
|
if not source:
|
|
kind = str((binding.external_metadata or {}).get("kind") or "")
|
|
source = "slack" if kind.startswith("slack_") else "telegram"
|
|
|
|
thread = NewChatThread(
|
|
title=f"{source.title()} chat",
|
|
workspace_id=binding.workspace_id,
|
|
created_by_id=binding.user_id,
|
|
visibility=ChatVisibility.PRIVATE,
|
|
source=source,
|
|
external_chat_binding_id=binding.id,
|
|
)
|
|
session.add(thread)
|
|
await session.flush()
|
|
binding.new_chat_thread_id = thread.id
|
|
return thread
|
|
|
|
|
|
def suspend_binding(binding: ExternalChatBinding, reason: str) -> None:
|
|
now = datetime.now(UTC)
|
|
binding.state = ExternalChatBindingState.SUSPENDED
|
|
binding.suspended_at = now
|
|
binding.suspended_reason = reason
|
|
|
|
|
|
def revoke_binding(binding: ExternalChatBinding) -> None:
|
|
now = datetime.now(UTC)
|
|
binding.state = ExternalChatBindingState.REVOKED
|
|
binding.revoked_at = now
|
|
binding.new_chat_thread_id = None
|
|
|
|
|
|
def resume_binding(binding: ExternalChatBinding) -> None:
|
|
binding.state = ExternalChatBindingState.BOUND
|
|
binding.suspended_at = None
|
|
binding.suspended_reason = None
|