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

cocoon-ai-provider

v0.1.0

Published

AI SDK v6 provider for Cocoon models

Readme

cocoon-ai-provider

AI SDK v6 provider for Cocoon.

Install

pnpm add cocoon-ai-provider ai

Quick Start

import { cocoon } from 'cocoon-ai-provider';
import { generateText } from 'ai';

const result = await generateText({
  model: cocoon('Qwen/Qwen3-32B'),
  prompt: 'Write a one-line welcome message.',
});

console.log(result.text);
await cocoon.close();

Streaming

import { cocoon } from 'cocoon-ai-provider';
import { streamText } from 'ai';

const result = streamText({
  model: cocoon('Qwen/Qwen3-32B'),
  prompt: 'Write a short product tagline.',
});

for await (const textPart of result.textStream) {
  process.stdout.write(textPart);
}

await cocoon.close();

Runnable Example

This repository includes a runnable end-to-end example at examples/basic.mjs.

COCOON_WALLET="your 24-word mnemonic" pnpm example:basic

Optional:

  • COCOON_MODEL_ID to override the model (default: Qwen/Qwen3-32B)
  • Any other Cocoon env vars described below

Custom Provider Instance

You can pass an existing Cocoon client or let the provider build one from clientOptions.

import { createCocoon } from 'cocoon-ai-provider';

const provider = createCocoon({
  clientOptions: {
    wallet: process.env.MNEMONIC!,
    secretString: process.env.SECRET,
    proxyUrl: process.env.PROXY_URL,
  },
  defaults: {
    maxCoefficient: 1.2,
    timeout: 30_000,
  },
});

Provider Options

Use call-level Cocoon options with providerOptions.cocoon:

import { generateText } from 'ai';
import { cocoon } from 'cocoon-ai-provider';

const result = await generateText({
  model: cocoon('Qwen/Qwen3-32B'),
  prompt: 'Summarize this in one sentence.',
  providerOptions: {
    cocoon: {
      maxCoefficient: 1.1,
      timeout: 20_000,
    },
  },
});

Call-level providerOptions.cocoon override provider-level defaults.

Environment Variables

When createCocoon() is called without client and without clientOptions, the provider builds a Cocoon client from env values.

  • wallet: COCOON_WALLET or MNEMONIC (required)
  • secretString: COCOON_SECRET_STRING or SECRET
  • proxyUrl: COCOON_PROXY_URL or PROXY_URL
  • tonEndpoint: COCOON_TON_ENDPOINT or TON_ENDPOINT
  • tonV4Endpoint: COCOON_TON_V4_ENDPOINT or TON_V4_ENDPOINT
  • network: COCOON_NETWORK (mainnet or testnet)
  • timeout: COCOON_TIMEOUT (positive number)
  • useTls: COCOON_USE_TLS (true/false or 1/0)
  • autoRegisterOnLongAuth: COCOON_AUTO_REGISTER_ON_LONG_AUTH (true/false or 1/0, default false)
  • longAuthRegisterAmountTon: COCOON_LONG_AUTH_REGISTER_AMOUNT_TON
  • TLS credential values: COCOON_TLS_CERT + COCOON_TLS_KEY
  • TLS credential files: COCOON_TLS_CERT_PATH + COCOON_TLS_KEY_PATH

Runtime and Limitations

  • Node.js >=18 only.
  • v1 supports language-model generation and streaming only.
  • Tool calling is not supported.
  • Multimodal file input is not supported.
  • Embedding and image model methods intentionally throw NoSuchModelError.
  • Abort behavior is best-effort. Cocoon cancellation is limited by the underlying SDK.

Testing

pnpm test

Optional real-network integration tests:

pnpm test:integration