Skip to main content

zeph_common/
policy.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Policy LLM client trait and minimal message types.
5//!
6//! Defines the interface used by `zeph-tools` adversarial policy validation,
7//! moved here to keep `zeph-tools` decoupled from `zeph-llm`.
8
9use std::future::Future;
10use std::pin::Pin;
11
12/// Minimal message type for policy LLM calls.
13///
14/// Uses a dedicated type rather than importing `zeph-llm::Message` to keep
15/// `zeph-common` free of `zeph-*` dependencies.
16#[derive(Debug, Clone)]
17pub struct PolicyMessage {
18    /// Role of the message sender.
19    pub role: PolicyRole,
20    /// Message content.
21    pub content: String,
22}
23
24/// Role for a [`PolicyMessage`].
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26#[non_exhaustive]
27pub enum PolicyRole {
28    /// System-level instruction.
29    System,
30    /// User-level prompt.
31    User,
32}
33
34/// Trait for sending chat messages to the policy LLM.
35///
36/// Implemented externally (e.g. in `runner.rs` on a newtype wrapping `Arc<AnyProvider>`).
37/// `zeph-tools` defines the usage; `zeph-common` defines the contract, keeping both
38/// crates decoupled from `zeph-llm`.
39pub trait PolicyLlmClient: Send + Sync {
40    /// Send a sequence of messages and return the assistant's text response.
41    ///
42    /// # Errors
43    ///
44    /// Returns `Err(String)` if the LLM call fails (network error, timeout, etc.).
45    fn chat<'a>(
46        &'a self,
47        messages: &'a [PolicyMessage],
48    ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send + 'a>>;
49}