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

@langecs/ai-sdk

v0.2.0

Published

Vercel AI SDK model adapter for LangECS — every provider via one dependency

Readme

@langecs/ai-sdk

Vercel AI SDK model adapter for LangECS: wrap any AI SDK v6 language model as a core Model — one dependency, every provider (OpenAI, Anthropic, Google, Ollama, …), tool calling, and streaming included. This is the adapter the examples use.

Install

npm i @langecs/ai-sdk @langecs/core ai

ai is a peer dependency (>= 5; developed and tested against v6).

ESM only, Node >= 20.

fromAiSdk(model: LanguageModel): Model

import { openai } from '@ai-sdk/openai';
import { fromAiSdk } from '@langecs/ai-sdk';
import { createWorld, defineResource, type Model } from '@langecs/core';
import { reactAgent } from '@langecs/stdlib';

const Gpt = defineResource<Model>('model:main');   // a typed resource name

const world = createWorld({ id: 'react-agent-demo' });
world.register(Gpt, fromAiSdk(openai('gpt-4o-mini')));
const assistant = reactAgent({ name: 'assistant', model: Gpt });

That registry line is the entire provider integration. The agent definition references the model by resource name (Gpt is just 'model:main' carrying the Model type; the plain string works everywhere a ref does), so swapping providers is a one-liner — change the registration, touch nothing else:

import { anthropic } from '@ai-sdk/anthropic';
world.register(Gpt, fromAiSdk(anthropic('claude-sonnet-4-6')));

fromAiSdk also accepts a gateway model id string, since AI SDK v6's LanguageModel type includes those.

What it maps

  • generate()generateText. Msg[] converts to AI SDK ModelMessage[] (system/user/assistant-with-tool-call-parts/tool-result), ToolSpec[] converts to an AI SDK ToolSet via jsonSchema(). The tools carry no execute function — a single model step returns tool calls to the engine unexecuted, because tool execution belongs to the world (stdlib executeTools), not the SDK. Sampling controls pass through when set — temperature, maxTokens (→ maxOutputTokens), topP, topK, frequencyPenalty, presencePenalty, seed, stopSequences; signal is forwarded as the SDK's abortSignal (R49); usage and finishReason map back; raw carries the original SDK result. Reasoning models' thinking is captured into Msg.thinking (from the SDK's reasoning output).
  • stream()streamText. Text deltas are forwarded to onChunk as they arrive; reasoning deltas are accumulated into Msg.thinking (not forwarded as answer text); tool calls and usage are collected from the full stream; the resolved ModelResult has the same shape as generate(). Stream errors are re-thrown (they surface as a failing system in the world, i.e. a SystemError record — not a crash).

Cancellation applies to both entry points, and the adapter checks req.signal itself before handing the call to the SDK: a signal that has already aborted rejects at the adapter boundary, without calling the provider at all. The SDK's own abort handling lives in its HTTP layer, which a request that never goes out never reaches.

Streaming

Used directly (adapted from this package's integration test):

const model = fromAiSdk(openai('gpt-4o-mini'));
const chunks: string[] = [];
const result = await model.stream?.(
  { messages, system, tools: [addTool], temperature: 0 },
  (d) => { if (d.text) chunks.push(d.text); },
);
// chunks.join('') === result.message.content

Inside a world you normally don't call this yourself: the stdlib callLLM system detects stream support and pipes tokens into the live run event stream via ctx.emit({ kind: 'token', text }) — see the react-agent example for printing them as they arrive.

Conversion utilities

The mapping functions are exported for reuse and testing — pure functions, no I/O:

| Export | Direction | |---|---| | toModelMessages(msgs) / toModelMessage(msg) | core Msg → AI SDK ModelMessage | | toAiSdkTools(specs) | core ToolSpec[] → AI SDK ToolSet (via jsonSchema()) | | toAssistantMsg(text, toolCalls) | AI SDK output → core assistant Msg | | toUsage(usage) | AI SDK usage → ModelResult['usage'] | | AiSdkToolCall, AiSdkUsage | shared shape types |

Tests

  • Unit tests run against the AI SDK's MockLanguageModelV3 — deterministic, zero network: pnpm -C packages/ai-sdk test.
  • One integration test does a real ReAct round trip (tool call → tool result → streamed final answer) against OpenAI. It is gated on OPENAI_API_KEY: put the key in the repo-root .env.local (gitignored; a tiny built-in loader reads it — no dotenv dependency) and the same test command runs it; without the key it is skipped entirely.

See also