Skip to main content

Client Libraries

Distri provides official client libraries for JavaScript/TypeScript and Rust, both fully synchronized with the Distri API. These libraries handle authentication, request formatting, streaming, and error handling.

distrijs

The official JavaScript/TypeScript client library for Distri, available as a monorepo with multiple packages.

Installation

npm install @distri/core @distri/react
# or
pnpm add @distri/core @distri/react
# or
yarn add @distri/core @distri/react

Package Registry

Packages

@distri/core

Core TypeScript client for Distri API. Provides:

  • Agent operations and message streaming
  • Session store API
  • Thread management
  • Tool execution
  • Direct LLM calls

Usage:

import { Distri } from '@distri/core';

const client = new Distri({
baseUrl: 'http://localhost:8787/api/v1',
});

const response = await client.sendMessage({
agentId: 'my_agent',
threadId: 'thread-123',
message: {
role: 'user',
parts: [{ part_type: 'text', data: 'Hello!' }],
},
});

@distri/react

React integration layer with hooks and components:

  • useAgent - Agent management hook
  • useChat - Chat UI hook
  • Chat component - Pre-built chat interface
  • DistriProvider - Context provider for configuration
  • Tool registration utilities

Usage:

import { DistriProvider, Chat, useAgent } from '@distri/react';

function App() {
return (
<DistriProvider config={{ baseUrl: 'http://localhost:8787/api/v1' }}>
<ChatComponent />
</DistriProvider>
);
}

function ChatComponent() {
const { agent } = useAgent({ agentIdOrDef: 'my_agent' });
return <Chat agent={agent} threadId="thread-123" />;
}

API Synchronization

The distrijs packages are kept in sync with the Distri API through:

  • Automated Testing: Continuous integration tests against the latest API
  • Type Safety: TypeScript definitions match API schemas
  • Version Alignment: Package versions align with Distri server releases
  • Documentation: API changes are reflected in package documentation

Source Code

  • Repository: distri/distrijs
  • Monorepo Structure: Uses Turbo and PNPM workspaces

distri

The official Rust client library for Distri, providing async/await support and full API coverage.

Installation

Add to your Cargo.toml:

[dependencies]
distri = "0.2.4"

Package Registry

Features

  • Agent invocation and streaming
  • Session store API
  • Thread and message management
  • Tool call handling
  • External tool registry
  • Configuration via environment variables or config files

Usage:

use distri::Distri;
use distri_types::Message;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Uses DISTRI_BASE_URL and DISTRI_API_KEY if set
let client = Distri::from_env();

let messages = vec![Message::user("Hello!".into(), None)];
let replies = client.invoke("my_agent", &messages).await?;

for reply in replies {
if let Some(text) = reply.as_text() {
println!("{text}");
}
}

Ok(())
}

Streaming Support

use distri::Distri;
use distri_types::Message;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Distri::new();
let messages = vec![Message::user("Stream the response.".into(), None)];

client
.invoke_stream("my_agent", &messages, |item| async move {
if let Some(message) = item.message {
if let Some(text) = message.as_text() {
println!("{text}");
}
}
})
.await?;

Ok(())
}

API Synchronization

The distri Rust crate is kept in sync with the Distri API through:

  • Shared Types: Uses distri-types crate that matches server schemas
  • A2A Protocol: Implements A2A protocol primitives via distri-a2a crate
  • Version Alignment: Crate versions align with Distri server releases
  • CI/CD: Automated testing ensures compatibility

Source Code

  • Repository: distri/distri
  • Related Crates:
    • distri-types - Message, tool, and config types
    • distri-a2a - A2A protocol primitives
    • distri-filesystem - Tool implementations

API Compatibility

Both client libraries:

  • Support all Distri API endpoints
  • Handle authentication (API keys, tokens)
  • Implement streaming via Server-Sent Events (SSE)
  • Provide session store operations
  • Support A2A protocol compatibility
  • Include comprehensive error handling

Choosing a Library

  • JavaScript/TypeScript Projects: Use @distri/core for programmatic access or @distri/react for React applications
  • Rust Projects: Use the distri crate for native Rust integration
  • Other Languages: Use the REST API directly (see Running as a standalone server)

Getting Help