uarp-sdk 0.5.7

Async Rust client for the UARP (Snaga) Universal Agent Runtime Platform API
Documentation
// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
//!
//! OpenAI-compatible ChatCompletion endpoint

#![allow(unused_imports, clippy::too_many_arguments)]

use reqwest::Method;
use serde::{Deserialize, Serialize};

use crate::client::{Client, Request, NO_BODY, NO_QUERY};
use crate::error::Result;
use crate::generated::models;
use crate::multipart::{field_text, FilePart};
use crate::util::encode_path;

/// OpenAI-compatible ChatCompletion endpoint
#[derive(Debug, Clone)]
pub struct OpenAiCompatApi {
    pub(crate) client: Client,
}

impl Client {
    /// OpenAI-compatible ChatCompletion endpoint
    pub fn open_ai_compat(&self) -> OpenAiCompatApi {
        OpenAiCompatApi { client: self.clone() }
    }
}

impl OpenAiCompatApi {
    /// OpenAI-compatible chat completion
    ///
    /// Maps OpenAI ChatCompletion requests to UARP agent runs. The 'model' field maps to
    /// 'agent/\<agent_id\>' or a plain agent_id.
    ///
    /// `POST /v1/chat/completions`
    ///
    /// Required scopes: `runs:create`.
    pub async fn chat_completion(&self, body: &models::ChatCompletionRequest) -> Result<serde_json::Value> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: "/v1/chat/completions".to_string(),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Create response (OpenAI Responses API)
    ///
    /// OpenAI-compatible Responses API. `model` and `input` required; `previous_response_id` chains
    /// to a prior response; `instructions` overrides the agent's system prompt for this call.
    ///
    /// `POST /v1/responses`
    ///
    /// Required scopes: `runs:create`.
    pub async fn create_response(&self, body: &models::CreateResponseRequest) -> Result<models::CreateResponseResponse> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: "/v1/responses".to_string(),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// OpenAI-compatible embeddings
    ///
    /// Generate embedding vectors for input text. Per Standats-Protocols ยง6.1. Uses
    /// platform-configured model (text-embedding-3-small).
    ///
    /// `POST /v1/embeddings`
    ///
    /// Required scopes: `runs:create`.
    pub async fn embeddings(&self, body: &models::EmbeddingsRequest) -> Result<models::EmbeddingsResponse> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: "/v1/embeddings".to_string(),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Get response by ID (OpenAI Responses API)
    ///
    /// `GET /v1/responses/{responseId}`
    pub async fn get_response(&self, response_id: &str) -> Result<serde_json::Value> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: format!("/v1/responses/{}", encode_path(response_id)),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// List available models (OpenAI-compatible)
    ///
    /// Returns agents as models in OpenAI model list format.
    ///
    /// `GET /v1/models`
    pub async fn list_models(&self) -> Result<models::ListModelsResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/v1/models".to_string(),
                query: NO_QUERY,
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }
}