SDK

SDK: installation and quick start

The official TypeScript/JavaScript client. Isomorphic (Node 18+ and the browser), zero runtime dependencies, built on native fetch.

Installation

npm
npm install @aist-packages/aist-agent-sdk

Quick start

index.ts
import { AistAgentClient, textInput } from '@aist-packages/aist-agent-sdk';

const client = new AistAgentClient({
  baseUrl: 'https://agent.aist-ai.com',
  token: process.env.AIST_AGENT_TOKEN!,   // JWT (RS256)
});

const { uuid } = await client.createTask({
  assistant_id: 1,
  input: [textInput('Hi! Who are you?')],
});

// poll until a terminal status
const task = await client.waitForTask(uuid, { stopOn: ['completed', 'failed'] });
console.log(task.turn?.output);

What’s going on

  1. new AistAgentClient stores the baseUrl and the JWT — the token is sent as Authorization: Bearer with every request.
  2. createTask queues the task and returns its uuid right away.
  3. waitForTask polls the status until it lands in stopOn and returns the final Task.

The textInput, fileInput and voiceInput helpers build input items with the right type.

Which assistants are available

No need to ask anyone for assistant_id and llm_model_id — the API returns them itself (since 0.4.0):

const assistants = await client.listAssistants();   // [{ id, slug, title, … }]
const writer = await client.getAssistant('writer');  // { …, models: [{ id, label, is_default }] }
const me = await client.getMe();                    // token expiry, limits, active tasks

The list matches the catalog on the website: hidden assistants aren’t in it — their IDs come from your administrator. More in Assistants.

Features

  • Strict typing of the wire format: Task, Turn, InputItem and so on.
  • Isomorphic — the same code for Node 18+ and the browser, native fetch/FormData.
  • Client tools — runTask walks through the interrupt cycle for you.
  • Typed errors — a subclass for every HTTP status.