Socket
Book a DemoInstallSign in
Socket

ai.matey.middleware

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai.matey.middleware

Middleware components for AI Matey - Universal AI Adapter System

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

ai.matey.middleware

Middleware components for AI Matey - Universal AI Adapter System.

Part of the ai.matey monorepo.

Installation

npm install ai.matey.middleware

Overview

This package provides middleware components that can be composed into a middleware stack for request/response processing in AI Matey bridges.

Included Middleware

  • Retry - Automatic retry with exponential backoff
  • Caching - Response caching with configurable storage
  • Logging - Request/response logging
  • Telemetry - Metrics and telemetry collection
  • OpenTelemetry - OpenTelemetry integration
  • Validation - Request validation and sanitization
  • Transform - Request/response transformation
  • Security - Security headers and validation
  • Cost Tracking - Token usage and cost tracking
  • Conversation History - Conversation state management

Usage

import { Bridge } from 'ai.matey.core';
import {
  createRetryMiddleware,
  createCachingMiddleware,
  createLoggingMiddleware,
  InMemoryCacheStorage,
} from 'ai.matey.middleware';

const bridge = new Bridge({
  frontend,
  backend,
  middleware: [
    createLoggingMiddleware({ level: 'info' }),
    createRetryMiddleware({ maxAttempts: 3 }),
    createCachingMiddleware({ storage: new InMemoryCacheStorage() }),
  ],
});

Retry Middleware

import { createRetryMiddleware } from 'ai.matey.middleware';

const retry = createRetryMiddleware({
  maxAttempts: 3,
  initialDelayMs: 1000,
  maxDelayMs: 10000,
  backoffMultiplier: 2,
});

Caching Middleware

import { createCachingMiddleware, InMemoryCacheStorage } from 'ai.matey.middleware';

const cache = createCachingMiddleware({
  storage: new InMemoryCacheStorage(),
  ttlMs: 60000, // 1 minute
});

Validation Middleware

import { createValidationMiddleware } from 'ai.matey.middleware';

const validation = createValidationMiddleware({
  detectPII: true,
  detectPromptInjection: true,
});

Cost Tracking Middleware

import { createCostTrackingMiddleware, InMemoryCostStorage } from 'ai.matey.middleware';

const costTracking = createCostTrackingMiddleware({
  storage: new InMemoryCostStorage(),
});

API Reference

See the TypeScript definitions for detailed API documentation.

License

MIT - see LICENSE for details.

Keywords

ai

FAQs

Package last updated on 29 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts