npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@distri/core

v0.2.7

Published

Core API client for Distri Framework

Readme

@distri/core

Core API client for Distri Framework with support for DistriMessage and DistriPart types.

Features

  • DistriMessage: Enhanced message structure with typed parts
  • DistriPart: Typed message parts supporting text, code observations, tool calls, and more
  • A2A Protocol Integration: Seamless conversion between A2A and Distri message formats
  • Enhanced Message Rendering: Rich display of different message part types

DistriMessage Structure

interface DistriMessage {
  id: string;
  role: 'user' | 'assistant';
  parts: DistriPart[];
  created_at?: string;
  metadata?: any;
}

DistriPart Types

type DistriPart =
  | { type: 'text'; text: string }
  | { type: 'code_observation'; code_observation: CodeObservation }
  | { type: 'image'; image: FileType }
  | { type: 'data'; data: any }
  | { type: 'tool_call'; tool_call: ToolCall }
  | { type: 'tool_result'; tool_result: ToolResponse }
  | { type: 'plan'; plan: string };

Usage

Creating DistriMessages

import { DistriClient, DistriMessage } from '@distri/core';

// Create a simple text message
const textMessage = DistriClient.initDistriMessage('Hello, world!', 'user');

// Create a message with multiple parts
const complexMessage = DistriClient.initDistriMessage([
  { type: 'text', text: 'Here is my analysis:' },
  { 
    type: 'code_observation', 
    code_observation: {
      thought: 'I need to analyze this data',
      code: 'const result = data.map(x => x * 2);'
    }
  },
  {
    type: 'tool_call',
    tool_call: {
      tool_call_id: 'call_123',
      tool_name: 'calculate',
      input: { numbers: [1, 2, 3] }
    }
  }
], 'assistant');

Converting Between Formats

import { 
  convertA2AMessageToDistri, 
  convertDistriMessageToA2A 
} from '@distri/core';

// Convert A2A Message to DistriMessage
const a2aMessage = /* A2A message from protocol */;
const distriMessage = convertA2AMessageToDistri(a2aMessage);

// Convert DistriMessage to A2A Message
const a2aMessage = convertDistriMessageToA2A(distriMessage);

Extracting Content

import { 
  extractTextFromDistriMessage,
  extractToolCallsFromDistriMessage,
  extractToolResultsFromDistriMessage 
} from '@distri/core';

// Extract text content
const text = extractTextFromDistriMessage(message);

// Extract tool calls
const toolCalls = extractToolCallsFromDistriMessage(message);

// Extract tool results
const toolResults = extractToolResultsFromDistriMessage(message);

Message Rendering

The React package includes enhanced message rendering components that can display all DistriPart types:

  • Text: Standard text rendering with markdown support
  • Code Observations: Thought process and code with syntax highlighting
  • Tool Calls: Tool execution details with input/output display
  • Tool Results: Success/failure status with result data
  • Plans: Structured plan display
  • Images: Base64 image rendering
  • Data: JSON data display

Migration from A2A Messages

The framework provides backward compatibility while encouraging the use of DistriMessage:

// Old way (still supported)
const oldMessage = DistriClient.initMessage('Hello', 'user');

// New way (recommended)
const newMessage = DistriClient.initDistriMessage('Hello', 'user');

Type Safety

All DistriPart types are fully typed, providing compile-time safety and better IDE support:

// TypeScript will ensure correct structure
const part: DistriPart = {
  type: 'code_observation',
  code_observation: {
    thought: 'My analysis',
    code: 'console.log("Hello");'
  }
};

Session Store API

The DistriClient provides a comprehensive session store API for managing thread-scoped key-value storage.

Basic Operations

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

const client = DistriClient.create();
const sessionId = 'thread-123';

// Set a session value
await client.setSessionValue(sessionId, 'key', { data: 'value' });

// Get a session value
const value = await client.getSessionValue(sessionId, 'key');

// Get all session values (returns a map)
const allValues = await client.getSessionValues(sessionId);

// Delete a session value
await client.deleteSessionValue(sessionId, 'key');

// Clear all session values
await client.clearSession(sessionId);

API Endpoints

All session methods use the following endpoints (mounted at /v1/sessions/):

  • POST /sessions/{sessionId}/values - Set a session value
  • GET /sessions/{sessionId}/values - Get all session values (returns map)
  • GET /sessions/{sessionId}/values/{key} - Get a specific session value
  • DELETE /sessions/{sessionId}/values/{key} - Delete a session value
  • DELETE /sessions/{sessionId} - Clear all session values

Integration with Agent Definitions

Session values can be referenced in agent definitions using UserMessageOverrides:

# Agent definition
user_message_overrides:
  parts:
    - type: session_key
      key: "observation"  # References session value with key "observation"
    - type: template
      template: "custom_user_template"
  include_artifacts: true

When the agent processes a message, it will automatically:

  1. Load all session values as a map
  2. Resolve PartDefinition::SessionKey references from the map
  3. Merge override parts with the default message parts
  4. Include the merged message in the LLM prompt