1.0.4 • Published 6 months ago

@bluefly/api-client v1.0.4

Weekly downloads
-
License
-
Repository
gitlab
Last release
6 months ago

Bluefly API Client Library

TypeScript client library for the Bluefly AI Platform API.

Current Status

Status: Core functionality working, recently cleaned up
Focus: API client generation and management for Drupal modules

What Works

  • Basic TypeScript client framework
  • OpenAPI 3.1.0 specification support
  • Type definitions for API responses
  • Basic authentication (API Key, Bearer Token)
  • Error handling for common HTTP status codes
  • Rate limiting implementation

What's In Development

  • Advanced retry mechanisms
  • Circuit breaker pattern
  • Comprehensive caching
  • OAuth2 flow implementation
  • Advanced validation

Installation

npm install @bluefly/api-client

Basic Usage

import { Configuration, AgentApi } from '@bluefly/api-client';

// Configure the client
const config = new Configuration({
  basePath: 'https://api.bluefly.ai',
  apiKey: 'your-api-key',
});

// Create an API instance
const agentApi = new AgentApi(config);

// Use the API
async function createAgent() {
  try {
    const agent = await agentApi.createAgent({
      agent: {
        name: 'My Agent',
        description: 'A test agent',
        model: 'gpt-4',
        parameters: {
          temperature: 0.7,
          max_tokens: 1000,
        },
      },
    });
    console.log('Created agent:', agent);
  } catch (error) {
    console.error('Error creating agent:', error);
  }
}

Development

Prerequisites

  • Node.js 20+
  • npm 9+

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install

Building

npm run build

Testing

# Run all tests
npm run test:all

# Run unit tests
npm run test:unit

# Run integration tests
npm run test:integration

Generating Client

The client is generated from the OpenAPI specification:

npm run generate:client

Validation

Validate the OpenAPI specification:

npm run validate:spec

Authentication

Currently supports:

  • API Keys
  • Bearer tokens (JWT)
const config = new Configuration({
  // API Key
  apiKey: 'your-api-key',

  // JWT Bearer token
  bearerToken: 'your-jwt-token',
});

Error Handling

Basic error handling is implemented:

try {
  await agentApi.runAgent({
    /* ... */
  });
} catch (error) {
  if (error.status === 429) {
    console.log('Rate limit exceeded');
  } else if (error.status === 401) {
    console.log('Authentication required');
  } else {
    console.log('Unexpected error:', error.message);
  }
}

Project Structure

bfapiclient/
├── src/
│   ├── core/           # Core client functionality
│   ├── models/         # TypeScript type definitions
│   ├── services/       # API service classes
│   └── utils/          # Utility functions
├── openapi/            # OpenAPI specifications
├── __tests__/          # Test files
└── docs/              # Documentation

Contributing

  1. Follow TypeScript best practices
  2. Write tests for new features
  3. Update OpenAPI specifications
  4. Use conventional commit messages
  5. Ensure all tests pass before pushing

Known Limitations

  • OAuth2 flow not fully implemented
  • Advanced caching not yet available
  • Circuit breaker pattern in development
  • Some edge cases in error handling need refinement

Troubleshooting

Common Issues

  1. Build errors: Clear node_modules and reinstall
  2. Type errors: Regenerate client from OpenAPI spec
  3. Authentication fails: Check token format and permissions

Debug Mode

Run with debug output:

DEBUG=bfapiclient:* npm run test

License

MIT


Last Updated: June 2025


📚 Platform Documentation

This project is part of the Bluefly AI Platform - Private LLM enterprise solution with complete data sovereignty.

Last Updated: June 09, 2025