open-index/open-npm huggingface dataset:
npm package: @sojen/client
Description: Client SDK for Sojen AI endpoints — chat, streaming, React hooks
Latest version: 0.1.4

# @sojen/client

Client SDK for Sojen AI endpoints. Use in Next.js or React apps to call the Sojen agent API. Published as a public npm package.

## Install

```bash
npm install @sojen/client
# or
pnpm add @sojen/client
```

## Publish (from repo root)

After changing this package, build and publish so the client can install the new version:

```bash
npm run publish:sojen-client
```

Requires npm auth for the scope that owns `@sojen` (e.g. `npm login`).

## Quick start

### React / Next.js (with hooks)

```tsx
import { SojenProvider, useChatStream } from '@sojen/client/react';

function App() {
  return (
    <SojenProvider config={{ baseUrl: process.env.NEXT_PUBLIC_SOJEN_URL! }}>
      <Chat />
    </SojenProvider>
  );
}

function Chat() {
  const { streamText, phase, streamReply } = useChatStream({
    worldId: 'world-123',
    userId: 'user-456',
    onComplete: (text) => console.log('Done:', text),
  });

  return (
    <div>
      <button onClick={() => streamReply('Hello')}>Send</button>
      {phase === 'streaming' && <p>{streamText}</p>}
    </div>
  );
}
```

### Core (framework-agnostic)

```ts
import { SojenClient } from '@sojen/client';

const client = new SojenClient({
  baseUrl: 'https://your-sojen-server.com',
  apiKey: 'optional-api-key',
});

// Streaming
for await (const chunk of client.chatStream({
  worldId: 'w1',
  userId: 'u1',
  message: 'Hello',
})) {
  if (chunk.type === 'text') console.log(chunk.data?.chunk);
}

// Non-streaming
const { text, toolResults } = await client.chat({
  worldId: 'w1',
  userId: 'u1',
  message: 'Hello',
});

// Task status (poll for job completion)
const status = await client.getTaskStatus('job-id'); // null if not found

// Health check
const health = await client.getHealth(); // { status, version, uptime, timestamp }

// Comic page grid (SSE)
for await (const ev of client.generateComicPageGrid({ userId: 'u1', worldId: 'w1', frameIds: ['f1','f2'], visualPrompts: ['p1','p2'] })) {
  if (ev.event === 'complete') console.log('JobId:', ev.data.jobId);
}
```

## Exports

- `@sojen/client` — SojenClient, chat, chatStream, getTaskStatus, getHealth, generateComicPageGrid, types, config helpers
- `@sojen/client/react` — SojenProvider, useSojenClient, useChatStream