JSPM

@workstudio/ai

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q26343F
  • License MIT

Unified interface for AI agents supporting OpenAI, Gemini, Anthropic, and xAI with multimodal and tool-calling support.

Package Exports

  • @workstudio/ai
  • @workstudio/ai/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@workstudio/ai) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@workstudio/ai

A unified, type-safe interface for building agentic AI applications. Support for OpenAI, Google Gemini, Anthropic Claude, and xAI Grok with a single, consistent API.

Features

  • Unified API: Switch between providers (OpenAI, Gemini, Anthropic, xAI) with minimal code changes.
  • Multimodal Support: Easily handle text and image inputs (base64) across all supported models.
  • Tool Calling: Standardized interface for function/tool calling for agentic workflows.
  • JSON Schema Enforcement: Native support for structured outputs using JSON schemas.
  • TypeScript First: Full type safety for messages, data parts, and provider configurations.

Installation

pnpm add @workstudio/ai
# or
npm install @workstudio/ai

Quick Start

Basic Text Prompt

import { OpenAIProvider } from "@workstudio/ai";

const ai = new OpenAIProvider("gpt-4o");

const messages = [
  { role: "user", parts: [{ text: "Hello, how are you?" }] }
];

const struct = {
  instructions: ["You are a helpful assistant."],
  context: [],
  responseSchema: {
    type: "object",
    properties: {
      reply: { type: "string" }
    },
    required: ["reply"]
  }
};

const response = await ai.prompt(messages, struct);
console.log(response.reply);

Multimodal (Image + Text)

import { GeminiProvider } from "@workstudio/ai";

const ai = new GeminiProvider(process.env.GEMINI_API_KEY);

const messages = [
  {
    role: "user",
    parts: [
      { text: "What is in this image?" },
      { 
        inlineData: { 
          data: "base64_encoded_image_data", 
          mimeType: "image/jpeg" 
        } 
      }
    ]
  }
];

const response = await ai.prompt(messages, {
  instructions: [],
  context: [],
  responseSchema: null
});

console.log(response.message);

Tool Calling

const struct = {
  instructions: ["Help the user with weather and time."],
  context: [],
  responseSchema: null,
  tools: [
    {
      name: "get_weather",
      description: "Get current weather for a location",
      parameters: {
        type: "object",
        properties: {
          location: { type: "string" }
        },
        required: ["location"]
      }
    }
  ]
};

const response = await ai.prompt(messages, struct);
if (response.tool_calls) {
    // Handle tool calling
}

Supported Providers

Provider Class Default Model
OpenAI OpenAIProvider gpt-4o
Gemini GeminiProvider gemini-2.0-flash
Anthropic AnthropicProvider claude-3-5-sonnet-latest
xAI XAIProvider grok-2-1218

Contributing

Please see CONTRIBUTING.md for details on how to get involved.

License

MIT © Workstudio