npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rcrsr/rill-ext-openai

v0.8.6

Published

rill extension for OpenAI API integration

Readme

@rcrsr/rill-ext-openai

rill extension for OpenAI API integration. Provides message, messages, embed, embed_batch, and tool_loop host functions. Compatible with any OpenAI-compatible server (LM Studio, Ollama, vLLM).

Experimental. Breaking changes will occur before stabilization.

Install

npm install @rcrsr/rill-ext-openai

Peer dependencies: @rcrsr/rill

Quick Start

import { parse, execute, createRuntimeContext, prefixFunctions } from '@rcrsr/rill';
import { createOpenAIExtension } from '@rcrsr/rill-ext-openai';

const ext = createOpenAIExtension({
  api_key: process.env.OPENAI_API_KEY!,
  model: 'gpt-4-turbo',
});
const prefixed = prefixFunctions('openai', ext);
const { dispose, ...functions } = prefixed;

const ctx = createRuntimeContext({
  functions,
  callbacks: { onLog: (v) => console.log(v) },
});

const script = `openai::message("Explain TCP handshakes")`;
const result = await execute(parse(script), ctx);

dispose?.();

Host Functions

All functions return a dict with content, model, usage, stop_reason, id, and messages.

openai::message(text, options?)

Send a single message to OpenAI.

openai::message("Analyze this code for security issues") => $response
$response.content -> log
$response.usage.output -> log

openai::messages(messages, options?)

Send a multi-turn conversation.

openai::messages([
  [role: "user", content: "What is rill?"],
  [role: "assistant", content: "A scripting language for AI agents."],
  [role: "user", content: "Show me an example."]
]) => $response
$response.content -> log

openai::embed(text)

Generate an embedding vector for text. Requires embed_model in config.

openai::embed("Hello world") => $vector

openai::embed_batch(texts)

Generate embedding vectors for multiple texts in a single API call.

openai::embed_batch(["Hello", "World"]) => $vectors

openai::tool_loop(prompt, options)

Execute a tool-use loop where the model calls rill functions iteratively.

openai::tool_loop("Find the weather", [tools: $my_tools]) => $result
$result.content -> log
$result.turns -> log

Configuration

const ext = createOpenAIExtension({
  api_key: process.env.OPENAI_API_KEY!,
  model: 'gpt-4-turbo',
  temperature: 0.7,
  base_url: 'http://localhost:1234/v1', // OpenAI-compatible server
  max_tokens: 4096,
  max_retries: 3,
  timeout: 30000,
  system: 'You are a helpful assistant.',
  embed_model: 'text-embedding-3-small',
});

| Option | Type | Default | Description | |--------|------|---------|-------------| | api_key | string | required | OpenAI API key | | model | string | required | Model identifier | | temperature | number | undefined | Temperature (0.0-2.0) | | base_url | string | undefined | Custom API endpoint URL | | max_tokens | number | 4096 | Max tokens in response | | max_retries | number | undefined | Max retry attempts | | timeout | number | undefined | Request timeout in ms | | system | string | undefined | Default system prompt | | embed_model | string | undefined | Embedding model identifier |

Result Shape

interface OpenAIResult {
  content: string;     // response text
  model: string;       // model used
  usage: {
    input: number;     // prompt tokens
    output: number;    // completion tokens
  };
  stop_reason: string; // finish reason
  id: string;          // request ID
  messages: Array<{    // full conversation history
    role: string;
    content: string;
  }>;
}

Lifecycle

Call dispose() on the extension to cancel pending requests:

const ext = createOpenAIExtension({ ... });
// ... use extension ...
await ext.dispose?.();

Test Host

A runnable example at examples/test-host.ts wires up the extension with the rill runtime:

pnpm exec tsx examples/test-host.ts
pnpm exec tsx examples/test-host.ts -e 'openai::message("Tell me a joke") -> log'
pnpm exec tsx examples/test-host.ts script.rill

Requires OPENAI_API_KEY environment variable (or --base-url for local servers).

Documentation

| Document | Description | |----------|-------------| | Extensions Guide | Extension contract and patterns | | Host API Reference | Runtime context and host functions |

License

MIT