Skip to main content

turnframe_runtime/
conversation.rs

1//! The conversation as a turn loads it: earlier messages, and what cannot be started.
2
3use serde::{Deserialize, Serialize};
4use turnframe_core::ids::WorkflowKey;
5
6/// Who wrote a message of the transcript.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum TranscriptRole {
10    /// The user.
11    User,
12    /// The assistant.
13    Assistant,
14}
15
16/// One earlier message of the conversation.
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18pub struct RecentMessage {
19    /// Who wrote it.
20    pub role: TranscriptRole,
21    /// What it said.
22    pub text: String,
23}
24
25impl RecentMessage {
26    /// A message the user wrote.
27    #[must_use]
28    pub fn user(text: impl Into<String>) -> Self {
29        Self {
30            role: TranscriptRole::User,
31            text: text.into(),
32        }
33    }
34
35    /// A message the assistant wrote.
36    #[must_use]
37    pub fn assistant(text: impl Into<String>) -> Self {
38        Self {
39            role: TranscriptRole::Assistant,
40            text: text.into(),
41        }
42    }
43}
44
45/// A workflow this turn cannot start, and the reason it declared.
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
47pub struct UnavailableWorkflow {
48    /// The workflow.
49    pub workflow: WorkflowKey,
50    /// Why, resolved to the turn's locale, in the workflow's own words.
51    pub reason: String,
52}