npm package: @ideascol/agents-generator-sdk
Description: agents-generator-sdk
Author: Jairo Fernandez
Latest version: 0.7.4

# @ideascol/agents-generator-sdk

agents-generator-sdk

## Usage as library

### Basic Usage - Get Agents

```ts
import { useEffect, useState } from 'react';
import {
  AgentClient,
  MessageCreate,
} from '@ideascol/agents-generator-sdk';

export function Agents() {
  const [agents, setAgents] = useState<AgentRequest[]>([]);

  useEffect(() => {
    const client = new AgentClient({
      apiUrl: 'https://api.agentsgenerator.dev',
      apiToken: 'YOUR_API_TOKEN',
    })

    client
      .agent.getAgents(0, 100, "anonymus")
      .then((result: AgentRequest[]) => {
        setAgents(result);
      });

  }, []);

  return (
    <div>
      <h1>Agents</h1>
      {agents.map((agent) => (
        <div key={agent.name}>{agent.name}</div>
      ))}
    </div>
  );
}
```

### Send Message with Transfer Detection (Synchronous)

The `sendMessage` method now uses streaming internally to detect agent transfers (handoffs). It returns a promise with the complete response including any transfers that occurred.

```ts
import { AgentClient, SendMessageResponse } from '@ideascol/agents-generator-sdk';

const client = new AgentClient({
  apiUrl: 'https://api.agentsgenerator.dev',
  apiToken: 'YOUR_API_TOKEN',
});

// Send a message and get the complete response with transfers
const response: SendMessageResponse = await client.sendMessage(
  'conversation-id',
  { content: 'Hello, I need help with billing' }
);

console.log('Message:', response.message);
console.log('Message ID:', response.message_id);

// Check if there were any transfers
if (response.transfers && response.transfers.length > 0) {
  console.log('Transfers detected:');
  response.transfers.forEach(transfer => {
    console.log(`  From: ${transfer.from_agent}`);
    console.log(`  To: ${transfer.to_agent}`);
    console.log(`  Reason: ${transfer.reason}`);
  });
}
```

### Send Message with Streaming (Real-time updates)

For real-time updates and custom handling of events, use `sendMessageWithStreaming`:

```ts
import { AgentClient, TransferEvent } from '@ideascol/agents-generator-sdk';

const client = new AgentClient({
  apiUrl: 'https://api.agentsgenerator.dev',
  apiToken: 'YOUR_API_TOKEN',
});

const abort = client.sendMessageWithStreaming(
  'conversation-id',
  { content: 'Hello!' },
  {
    onMessage: (content: string) => {
      console.log('Message update:', content);
    },
    onDone: (messageId: string) => {
      console.log('Message completed:', messageId);
    },
    onTransfer: (transfer: TransferEvent) => {
      console.log('Transfer detected!');
      console.log(`  From: ${transfer.from_agent}`);
      console.log(`  To: ${transfer.to_agent}`);
      console.log(`  Reason: ${transfer.reason}`);
    },
    onError: (error: Error) => {
      console.error('Error:', error);
    }
  }
);

// To abort the stream:
// abort();
```

### TypeScript Types

```ts
interface SendMessageResponse {
  status: string;
  message: string;
  message_id?: string;
  transfers?: TransferEvent[];
}

interface TransferEvent {
  from_agent?: string;
  to_agent?: string;
  reason?: string;
}

interface StreamCallbacks {
  onMessage?: (content: string) => void;
  onDone?: (messageId: string) => void;
  onError?: (error: Error) => void;
  onTransfer?: (transfer: TransferEvent) => void;
}
```

## Quick start
```bash
# Using npm
npx @ideascol/agents-generator-sdk@latest

# Using bun
bunx @ideascol/agents-generator-sdk@latest
```

## Installation

```bash
# Using npm
npm install -g @ideascol/agents-generator-sdk@latest

# Using bun
bun install -g @ideascol/agents-generator-sdk@latest
```

## Usage as cli
```bash
npx @ideascol/agents-generator-sdk@latest version --apiToken=1232 --URL=https://api.agentsgenerator.dev
```

```json
{
  "status": "ok",
  "api_version": "dbd7d9ca8a6b1e4622ef409e26cd8addb650e95f",
  "api_branch": "main",
  "api_date": "2025-04-25 17:21:01"
}
```

### Update lib client

```bash
npx openapi-typescript-codegen \
  --input https://api.agentsgenerator.dev/openapi.json \
  --output src/lib/clients/agents-generator \
  --client fetch
```

```bash
npx openapi-typescript-codegen \
  --input http://localhost:8000/openapi.json \
  --output src/lib/clients/agents-generator \
  --client fetch
```

```bash
curl -s http://localhost:8000/openapi.json -o openapi.json
```