Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.5 KB
Raw Blame
use crate::{
    OpensearchClient, Result, delete,
    retry::resend_on_lost_connection,
    upsert::{self, chat_message::UpsertChatMessageArgs, properties::IndexedProperty},
};

impl OpensearchClient {
    #[tracing::instrument(skip(self))]
    pub async fn upsert_chat_message(
        &self,
        upsert_chat_message_args: &UpsertChatMessageArgs,
        index_override: Option<&str>,
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::chat_message::upsert_chat_message(
                &self.inner,
                upsert_chat_message_args,
                index_override,
            )
        })
        .await
    }

    /// Deletes a chat from the opensearch chat index
    /// This will remove all messages for a given chat
    #[tracing::instrument(skip(self))]
    pub async fn delete_chat(&self, chat_id: &str, index_override: Option<&str>) -> Result<()> {
        resend_on_lost_connection(|| {
            delete::chat::delete_chat_by_id(&self.inner, chat_id, index_override)
        })
        .await
    }

    /// Deletes a chat message from the opensearch chat index
    /// This removes a specific message from a chat
    #[tracing::instrument(skip(self))]
    pub async fn delete_chat_message(
        &self,
        chat_id: &str,
        chat_message_id: &str,
        index_override: Option<&str>,
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            delete::chat::delete_chat_message_by_id(
                &self.inner,
                chat_id,
                chat_message_id,
                index_override,
            )
        })
        .await
    }

    pub async fn update_chat_metadata(&self, chat_id: &str, title: &str) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::chat_message::update_chat_metadata(&self.inner, chat_id, title)
        })
        .await
    }

    /// Refresh only the denormalized `properties` on an existing parent chat doc.
    #[tracing::instrument(skip(self, properties), err)]
    pub async fn update_chat_properties(
        &self,
        chat_id: &str,
        properties: &[IndexedProperty],
    ) -> Result<()> {
        resend_on_lost_connection(|| {
            upsert::chat_message::update_chat_properties(&self.inner, chat_id, properties)
        })
        .await
    }

    pub async fn delete_chat_by_user_id(&self, user_id: &str) -> Result<()> {
        resend_on_lost_connection(|| delete::chat::delete_chat_by_user_id(&self.inner, user_id))
            .await
    }
}