Visitar URL original
GitHub - mitkury/aiwrapper: A Universal AI Wrapper for JavaScript & TypeScript · GitHub
Skip to content
mitkuryPublic

About

A Universal AI Wrapper for JavaScript & TypeScript

Resources

Stars

18 stars

Watchers

3 watching

Forks

Repository files navigation

AIWrapper

A small, npm-first AI wrapper for JavaScript and TypeScript. One message and tool-calling API across language providers, with separate interfaces for native live models, speech, and agents.

npm install aiwrapper

Requires Node.js 20+ or a modern browser. The package is ESM; browser requests also depend on provider CORS support. Keep long-lived API keys on your server. The API is evolving and may change between releases.

The first native Rust library supports backend embedding, streaming inference, tool agents, optional context compression and live voice. Run npm run sandbox:native to use it from the browser chat playground.

Generate text

import { Lang } from "aiwrapper";

const lang = Lang.openai({ apiKey: process.env.OPENAI_API_KEY! });
const result = await lang.ask("Explain closures in one sentence.");
console.log(result.answer);

result.addUserMessage("Show a JavaScript example.");
const followUp = await lang.chat(result);
console.log(followUp.answer);

See language providers for provider selection, streaming, structured output, images, custom endpoints, and AWS Bedrock.

Run an agent with tools

import { ChatAgent, Lang, LangMessage } from "aiwrapper";

const agent = new ChatAgent(
  Lang.openai({ apiKey: process.env.OPENAI_API_KEY! }),
  { tools: [{
    name: "get_time",
    description: "Get the current UTC time",
    parameters: { type: "object", properties: {} },
    handler: () => ({ now: new Date().toISOString() }),
  }] },
);

const result = await agent.run([new LangMessage("user", "What time is it?")]);
console.log(result.answer);

ChatAgent keeps history and handles the model/tool loop. See agents and tools for cancellation, events, and tool results.

Connect to a live model

import { LiveLang } from "aiwrapper";

const session = await LiveLang.openai({
  apiKey: process.env.OPENAI_API_KEY!,
}).connect({
  instructions: "Keep spoken answers brief.",
  onEvent: event => console.log(event),
});

// Supply PCM frames from your application's microphone transport.
await session.appendAudio(microphoneFrame);
await session.close();

See live sessions for Gemini and other native voice providers, speech for transcription and synthesis, or realtime agents for an STT → LLM → TTS pipeline.

Try it and contribute

The browser playground includes chat, speech, realtime agents, and native live voice. Start with the documentation index for setup, tests, and development rules.

Contributors and coding agents use shared guidance with local development rules. Initialize the docs submodule with git submodule update --init docs/airul after cloning.

About

A Universal AI Wrapper for JavaScript & TypeScript

Resources

Stars

18 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages