import type { Db } from "@rudderhq/db";
import { type ChatStreamTranscriptEntry } from "@rudderhq/shared";
import { approvals, chatConversations } from "@rudderhq/db";
type ApprovalRow = typeof approvals.$inferSelect;
export declare function chatService(db: Db): {
    list: (orgId: string, options?: {
        status?: "active" | "resolved" | "archived" | "all";
        q?: string;
    }, userId?: string | null) => Promise<{
        primaryIssue: {
            id: string;
            identifier: string | null;
            title: string;
            status: string;
            priority: string;
        } | null;
        latestReplyPreview: string | null;
        contextLinks: {
            entity: {
                type: "issue" | "project" | "agent";
                id: string;
                label: string;
                subtitle: string | null;
                identifier: string | null;
                status: string | null;
                description?: string | null;
                priority?: string | null;
                href: string;
            } | null;
            createdAt: Date;
            metadata: Record<string, unknown> | null;
            id: string;
            updatedAt: Date;
            orgId: string;
            entityType: string;
            entityId: string;
            conversationId: string;
        }[];
        lastReadAt: Date | null;
        isPinned: boolean;
        unreadCount: number;
        isUnread: boolean;
        needsAttention: boolean;
        createdAt: Date;
        status: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        title: string;
        summary: string | null;
        createdByUserId: string | null;
        preferredAgentId: string | null;
        routedAgentId: string | null;
        primaryIssueId: string | null;
        issueCreationMode: string;
        planMode: boolean;
        lastMessageAt: Date | null;
        resolvedAt: Date | null;
    }[]>;
    getById: (id: string, userId?: string | null) => Promise<{
        primaryIssue: {
            id: string;
            identifier: string | null;
            title: string;
            status: string;
            priority: string;
        } | null;
        latestReplyPreview: string | null;
        contextLinks: {
            entity: {
                type: "issue" | "project" | "agent";
                id: string;
                label: string;
                subtitle: string | null;
                identifier: string | null;
                status: string | null;
                description?: string | null;
                priority?: string | null;
                href: string;
            } | null;
            createdAt: Date;
            metadata: Record<string, unknown> | null;
            id: string;
            updatedAt: Date;
            orgId: string;
            entityType: string;
            entityId: string;
            conversationId: string;
        }[];
        lastReadAt: Date | null;
        isPinned: boolean;
        unreadCount: number;
        isUnread: boolean;
        needsAttention: boolean;
        createdAt: Date;
        status: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        title: string;
        summary: string | null;
        createdByUserId: string | null;
        preferredAgentId: string | null;
        routedAgentId: string | null;
        primaryIssueId: string | null;
        issueCreationMode: string;
        planMode: boolean;
        lastMessageAt: Date | null;
        resolvedAt: Date | null;
    } | null>;
    create: (orgId: string, data: {
        title?: string;
        summary?: string | null;
        preferredAgentId?: string | null;
        issueCreationMode: "manual_approval" | "auto_create";
        planMode: boolean;
        createdByUserId: string | null;
        contextLinks?: Array<{
            entityType: "issue" | "project" | "agent";
            entityId: string;
            metadata?: Record<string, unknown> | null;
        }>;
    }) => Promise<{
        primaryIssue: {
            id: string;
            identifier: string | null;
            title: string;
            status: string;
            priority: string;
        } | null;
        latestReplyPreview: string | null;
        contextLinks: {
            entity: {
                type: "issue" | "project" | "agent";
                id: string;
                label: string;
                subtitle: string | null;
                identifier: string | null;
                status: string | null;
                description?: string | null;
                priority?: string | null;
                href: string;
            } | null;
            createdAt: Date;
            metadata: Record<string, unknown> | null;
            id: string;
            updatedAt: Date;
            orgId: string;
            entityType: string;
            entityId: string;
            conversationId: string;
        }[];
        lastReadAt: Date | null;
        isPinned: boolean;
        unreadCount: number;
        isUnread: boolean;
        needsAttention: boolean;
        createdAt: Date;
        status: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        title: string;
        summary: string | null;
        createdByUserId: string | null;
        preferredAgentId: string | null;
        routedAgentId: string | null;
        primaryIssueId: string | null;
        issueCreationMode: string;
        planMode: boolean;
        lastMessageAt: Date | null;
        resolvedAt: Date | null;
    } | null>;
    update: (id: string, patch: Partial<typeof chatConversations.$inferInsert>) => Promise<{
        primaryIssue: {
            id: string;
            identifier: string | null;
            title: string;
            status: string;
            priority: string;
        } | null;
        latestReplyPreview: string | null;
        contextLinks: {
            entity: {
                type: "issue" | "project" | "agent";
                id: string;
                label: string;
                subtitle: string | null;
                identifier: string | null;
                status: string | null;
                description?: string | null;
                priority?: string | null;
                href: string;
            } | null;
            createdAt: Date;
            metadata: Record<string, unknown> | null;
            id: string;
            updatedAt: Date;
            orgId: string;
            entityType: string;
            entityId: string;
            conversationId: string;
        }[];
        lastReadAt: Date | null;
        isPinned: boolean;
        unreadCount: number;
        isUnread: boolean;
        needsAttention: boolean;
        createdAt: Date;
        status: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        title: string;
        summary: string | null;
        createdByUserId: string | null;
        preferredAgentId: string | null;
        routedAgentId: string | null;
        primaryIssueId: string | null;
        issueCreationMode: string;
        planMode: boolean;
        lastMessageAt: Date | null;
        resolvedAt: Date | null;
    } | null>;
    resolve: (id: string) => Promise<{
        primaryIssue: {
            id: string;
            identifier: string | null;
            title: string;
            status: string;
            priority: string;
        } | null;
        latestReplyPreview: string | null;
        contextLinks: {
            entity: {
                type: "issue" | "project" | "agent";
                id: string;
                label: string;
                subtitle: string | null;
                identifier: string | null;
                status: string | null;
                description?: string | null;
                priority?: string | null;
                href: string;
            } | null;
            createdAt: Date;
            metadata: Record<string, unknown> | null;
            id: string;
            updatedAt: Date;
            orgId: string;
            entityType: string;
            entityId: string;
            conversationId: string;
        }[];
        lastReadAt: Date | null;
        isPinned: boolean;
        unreadCount: number;
        isUnread: boolean;
        needsAttention: boolean;
        createdAt: Date;
        status: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        title: string;
        summary: string | null;
        createdByUserId: string | null;
        preferredAgentId: string | null;
        routedAgentId: string | null;
        primaryIssueId: string | null;
        issueCreationMode: string;
        planMode: boolean;
        lastMessageAt: Date | null;
        resolvedAt: Date | null;
    } | null>;
    markRead: (conversationId: string, orgId: string, userId: string, readAt?: Date) => Promise<{
        createdAt: Date;
        id: string;
        userId: string;
        updatedAt: Date;
        orgId: string;
        lastReadAt: Date;
        conversationId: string;
        pinnedAt: Date | null;
    }>;
    markUnread: (conversationId: string, orgId: string, userId: string) => Promise<{
        createdAt: Date;
        id: string;
        userId: string;
        updatedAt: Date;
        orgId: string;
        lastReadAt: Date;
        conversationId: string;
        pinnedAt: Date | null;
    }>;
    setPinned: (conversationId: string, orgId: string, userId: string, pinned: boolean) => Promise<{
        createdAt: Date;
        id: string;
        userId: string;
        updatedAt: Date;
        orgId: string;
        lastReadAt: Date;
        conversationId: string;
        pinnedAt: Date | null;
    }>;
    listMessages: (conversationId: string) => Promise<{
        structuredPayload: Record<string, unknown> | null;
        transcript: ChatStreamTranscriptEntry[];
        approval: {
            createdAt: Date;
            status: string;
            id: string;
            type: string;
            updatedAt: Date;
            orgId: string;
            payload: Record<string, unknown>;
            requestedByAgentId: string | null;
            requestedByUserId: string | null;
            decisionNote: string | null;
            decidedByUserId: string | null;
            decidedAt: Date | null;
        } | null;
        attachments: any[];
        createdAt: Date;
        status: string;
        kind: string;
        body: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        approvalId: string | null;
        conversationId: string;
        replyingAgentId: string | null;
        chatTurnId: string | null;
        turnVariant: number;
        supersededAt: Date | null;
    }[]>;
    addMessage: (conversationId: string, input: {
        orgId: string;
        role: "user" | "assistant" | "system";
        kind: "message" | "ask_user" | "issue_proposal" | "operation_proposal" | "system_event";
        status?: "streaming" | "completed" | "stopped" | "failed" | "interrupted";
        body: string;
        structuredPayload?: Record<string, unknown> | null;
        transcript?: ChatStreamTranscriptEntry[];
        approvalId?: string | null;
        replyingAgentId?: string | null;
        chatTurnId?: string | null;
        turnVariant?: number;
    }) => Promise<{
        structuredPayload: Record<string, unknown> | null;
        transcript: ChatStreamTranscriptEntry[];
        approval: {
            createdAt: Date;
            status: string;
            id: string;
            type: string;
            updatedAt: Date;
            orgId: string;
            payload: Record<string, unknown>;
            requestedByAgentId: string | null;
            requestedByUserId: string | null;
            decisionNote: string | null;
            decidedByUserId: string | null;
            decidedAt: Date | null;
        } | null;
        attachments: any[];
        createdAt: Date;
        status: string;
        kind: string;
        body: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        approvalId: string | null;
        conversationId: string;
        replyingAgentId: string | null;
        chatTurnId: string | null;
        turnVariant: number;
        supersededAt: Date | null;
    }>;
    updateMessage: (conversationId: string, messageId: string, input: {
        kind?: "message" | "ask_user" | "issue_proposal" | "operation_proposal" | "system_event";
        status?: "streaming" | "completed" | "stopped" | "failed" | "interrupted";
        body?: string;
        structuredPayload?: Record<string, unknown> | null;
        transcript?: ChatStreamTranscriptEntry[];
        approvalId?: string | null;
        replyingAgentId?: string | null;
    }) => Promise<{
        structuredPayload: Record<string, unknown> | null;
        transcript: ChatStreamTranscriptEntry[];
        approval: {
            createdAt: Date;
            status: string;
            id: string;
            type: string;
            updatedAt: Date;
            orgId: string;
            payload: Record<string, unknown>;
            requestedByAgentId: string | null;
            requestedByUserId: string | null;
            decisionNote: string | null;
            decidedByUserId: string | null;
            decidedAt: Date | null;
        } | null;
        attachments: any[];
        createdAt: Date;
        status: string;
        kind: string;
        body: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        approvalId: string | null;
        conversationId: string;
        replyingAgentId: string | null;
        chatTurnId: string | null;
        turnVariant: number;
        supersededAt: Date | null;
    } | null>;
    markInterruptedStreamingMessages: (conversationId: string) => Promise<{
        structuredPayload: Record<string, unknown> | null;
        transcript: ChatStreamTranscriptEntry[];
        approval: {
            createdAt: Date;
            status: string;
            id: string;
            type: string;
            updatedAt: Date;
            orgId: string;
            payload: Record<string, unknown>;
            requestedByAgentId: string | null;
            requestedByUserId: string | null;
            decisionNote: string | null;
            decidedByUserId: string | null;
            decidedAt: Date | null;
        } | null;
        attachments: any[];
        createdAt: Date;
        status: string;
        kind: string;
        body: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        approvalId: string | null;
        conversationId: string;
        replyingAgentId: string | null;
        chatTurnId: string | null;
        turnVariant: number;
        supersededAt: Date | null;
    }[]>;
    addUserChatMessage: (conversationId: string, orgId: string, body: string, editUserMessageId?: string | null) => Promise<{
        structuredPayload: Record<string, unknown> | null;
        transcript: ChatStreamTranscriptEntry[];
        approval: {
            createdAt: Date;
            status: string;
            id: string;
            type: string;
            updatedAt: Date;
            orgId: string;
            payload: Record<string, unknown>;
            requestedByAgentId: string | null;
            requestedByUserId: string | null;
            decisionNote: string | null;
            decidedByUserId: string | null;
            decidedAt: Date | null;
        } | null;
        attachments: any[];
        createdAt: Date;
        status: string;
        kind: string;
        body: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        approvalId: string | null;
        conversationId: string;
        replyingAgentId: string | null;
        chatTurnId: string | null;
        turnVariant: number;
        supersededAt: Date | null;
    }>;
    addContextLink: (conversationId: string, orgId: string, input: {
        entityType: "issue" | "project" | "agent";
        entityId: string;
        metadata?: Record<string, unknown> | null;
    }) => Promise<{
        entity: {
            type: "issue" | "project" | "agent";
            id: string;
            label: string;
            subtitle: string | null;
            identifier: string | null;
            status: string | null;
            description?: string | null;
            priority?: string | null;
            href: string;
        } | null;
        createdAt: Date;
        metadata: Record<string, unknown> | null;
        id: string;
        updatedAt: Date;
        orgId: string;
        entityType: string;
        entityId: string;
        conversationId: string;
    } | null>;
    setProjectContextLink: (conversationId: string, orgId: string, projectId: string | null) => Promise<{
        primaryIssue: {
            id: string;
            identifier: string | null;
            title: string;
            status: string;
            priority: string;
        } | null;
        latestReplyPreview: string | null;
        contextLinks: {
            entity: {
                type: "issue" | "project" | "agent";
                id: string;
                label: string;
                subtitle: string | null;
                identifier: string | null;
                status: string | null;
                description?: string | null;
                priority?: string | null;
                href: string;
            } | null;
            createdAt: Date;
            metadata: Record<string, unknown> | null;
            id: string;
            updatedAt: Date;
            orgId: string;
            entityType: string;
            entityId: string;
            conversationId: string;
        }[];
        lastReadAt: Date | null;
        isPinned: boolean;
        unreadCount: number;
        isUnread: boolean;
        needsAttention: boolean;
        createdAt: Date;
        status: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        title: string;
        summary: string | null;
        createdByUserId: string | null;
        preferredAgentId: string | null;
        routedAgentId: string | null;
        primaryIssueId: string | null;
        issueCreationMode: string;
        planMode: boolean;
        lastMessageAt: Date | null;
        resolvedAt: Date | null;
    } | null>;
    createAttachment: (input: {
        orgId: string;
        conversationId: string;
        messageId: string;
        provider: string;
        objectKey: string;
        contentType: string;
        byteSize: number;
        sha256: string;
        originalFilename: string | null;
        createdByAgentId: string | null;
        createdByUserId: string | null;
    }) => Promise<{
        provider: string;
        objectKey: string;
        contentType: string;
        byteSize: number;
        sha256: string;
        originalFilename: string | null;
        createdByAgentId: string | null;
        createdByUserId: string | null;
        contentPath: string;
        createdAt: Date;
        id: string;
        updatedAt: Date;
        orgId: string;
        assetId: string;
        conversationId: string;
        messageId: string;
    }>;
    convertToIssue: (conversationId: string, input: {
        actorUserId: string | null;
        createdByAgentId?: string | null;
        messageId?: string | null;
        proposal?: Record<string, unknown> | null;
    }) => Promise<import("./issues.helpers.js").IssueWithLabels>;
    getMessage: (conversationId: string, messageId: string) => Promise<{
        structuredPayload: Record<string, unknown> | null;
        transcript: ChatStreamTranscriptEntry[];
        approval: {
            createdAt: Date;
            status: string;
            id: string;
            type: string;
            updatedAt: Date;
            orgId: string;
            payload: Record<string, unknown>;
            requestedByAgentId: string | null;
            requestedByUserId: string | null;
            decisionNote: string | null;
            decidedByUserId: string | null;
            decidedAt: Date | null;
        } | null;
        attachments: any[];
        createdAt: Date;
        status: string;
        kind: string;
        body: string;
        id: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        approvalId: string | null;
        conversationId: string;
        replyingAgentId: string | null;
        chatTurnId: string | null;
        turnVariant: number;
        supersededAt: Date | null;
    } | null>;
    applyApprovedApproval: (approval: ApprovalRow, actorUserId: string | null) => Promise<Omit<{
        permissions: import("./agent-permissions.js").NormalizedAgentPermissions;
        createdAt: Date;
        status: string;
        metadata: Record<string, unknown> | null;
        id: string;
        name: string;
        updatedAt: Date;
        orgId: string;
        role: string;
        pauseReason: string | null;
        pausedAt: Date | null;
        budgetMonthlyCents: number;
        spentMonthlyCents: number;
        workspaceKey: string | null;
        title: string | null;
        icon: string | null;
        reportsTo: string | null;
        capabilities: string | null;
        agentRuntimeType: string;
        agentRuntimeConfig: Record<string, unknown>;
        runtimeConfig: Record<string, unknown>;
        lastHeartbeatAt: Date | null;
    } & {
        urlKey: string;
    }, "workspaceKey"> | ({
        logoAssetId: string | null;
        id: string;
        urlKey: string;
        name: string;
        description: string | null;
        status: string;
        pauseReason: string | null;
        pausedAt: Date | null;
        issuePrefix: string;
        issueCounter: number;
        budgetMonthlyCents: number;
        spentMonthlyCents: number;
        requireBoardApprovalForNewAgents: boolean;
        defaultChatIssueCreationMode: string;
        workspaceConfig: Record<string, unknown> | null;
        brandColor: string | null;
        createdAt: Date;
        updatedAt: Date;
    } & {
        spentMonthlyCents: number;
    } & {
        workspace: null;
        logoUrl: string | null;
    }) | import("./issues.helpers.js").IssueWithLabels | null>;
    createProposalApproval: (orgId: string, input: {
        type: "chat_issue_creation" | "chat_operation";
        requestedByUserId: string | null;
        payload: Record<string, unknown>;
    }) => Promise<{
        createdAt: Date;
        status: string;
        id: string;
        type: string;
        updatedAt: Date;
        orgId: string;
        payload: Record<string, unknown>;
        requestedByAgentId: string | null;
        requestedByUserId: string | null;
        decisionNote: string | null;
        decidedByUserId: string | null;
        decidedAt: Date | null;
    }>;
    resolveOperationProposal: (conversationId: string, messageId: string, input: {
        action: "approve" | "reject" | "requestRevision";
        actorUserId: string | null;
        decisionNote?: string | null;
    }) => Promise<{
        message: {
            structuredPayload: Record<string, unknown> | null;
            transcript: ChatStreamTranscriptEntry[];
            approval: {
                createdAt: Date;
                status: string;
                id: string;
                type: string;
                updatedAt: Date;
                orgId: string;
                payload: Record<string, unknown>;
                requestedByAgentId: string | null;
                requestedByUserId: string | null;
                decisionNote: string | null;
                decidedByUserId: string | null;
                decidedAt: Date | null;
            } | null;
            attachments: any[];
            createdAt: Date;
            status: string;
            kind: string;
            body: string;
            id: string;
            updatedAt: Date;
            orgId: string;
            role: string;
            approvalId: string | null;
            conversationId: string;
            replyingAgentId: string | null;
            chatTurnId: string | null;
            turnVariant: number;
            supersededAt: Date | null;
        };
        systemMessage: {
            structuredPayload: Record<string, unknown> | null;
            transcript: ChatStreamTranscriptEntry[];
            approval: {
                createdAt: Date;
                status: string;
                id: string;
                type: string;
                updatedAt: Date;
                orgId: string;
                payload: Record<string, unknown>;
                requestedByAgentId: string | null;
                requestedByUserId: string | null;
                decisionNote: string | null;
                decidedByUserId: string | null;
                decidedAt: Date | null;
            } | null;
            attachments: any[];
            createdAt: Date;
            status: string;
            kind: string;
            body: string;
            id: string;
            updatedAt: Date;
            orgId: string;
            role: string;
            approvalId: string | null;
            conversationId: string;
            replyingAgentId: string | null;
            chatTurnId: string | null;
            turnVariant: number;
            supersededAt: Date | null;
        };
    }>;
};
export {};
//# sourceMappingURL=chats.d.ts.map