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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@think-new/sdk

v1.0.0

Published

Official TypeScript SDK for the Think Agent API

Downloads

3

Readme

@think-new/sdk

Official TypeScript SDK for the Think Agent API.

Installation

npm install @think-new/sdk
# or
yarn add @think-new/sdk
# or
pnpm add @think-new/sdk

Usage

Creating a New Agent

import { Think } from '@think-new/sdk';

const agent = new Think('MyAgent', {
  systemPrompt: 'You are a helpful assistant',
  tools: [
    // Array of SCP endpoint URLs
    'https://api.example.com/scp/calculator',
    'https://api.example.com/scp/weather'
  ]
});

// Send a message and wait for the assistant's response
const response = await agent.sendMessage('What is the weather like today?');
console.log('Assistant:', response.content);

// You can also customize the polling interval (in milliseconds)
const response2 = await agent.sendMessage('Calculate 2 + 2', {}, 500);
console.log('Assistant:', response2.content);

// Get conversation history
const messages = await agent.getMessages();
console.log(messages);

Loading an Existing Agent

import { Think } from '@think-new/sdk';

const agent = await Think.fromId('your-agent-id');

// Send a message and wait for the complete response
const response = await agent.sendMessage('Continue our conversation...');
console.log('Assistant:', response.content);

// Get full conversation history
const messages = await agent.getMessages();

SCP Tool Validation

The SDK supports the Structured Completion Protocol (SCP) v1.0.0 for tools. Each tool URL must point to a discovery endpoint that returns a JSON Schema describing its inputs and outputs.

When creating an agent, the SDK will:

  1. Validate each tool's SCP endpoint
  2. Ensure compatibility with SCP v1.0.0
  3. Validate the schema structure
  4. Handle errors according to RFC 7807 Problem Details

Tool Configuration

Simply provide an array of SCP endpoint URLs:

const tools = [
  'https://api.example.com/scp/calculator',
  'https://api.example.com/scp/weather',
  'https://api.example.com/scp/search'
];

const agent = new Think('MyAgent', { tools });

The SDK will automatically:

  1. Validate each tool's SCP endpoint
  2. Ensure version compatibility (v1.x.x)
  3. Validate schema structure
  4. Handle errors according to RFC 7807 Problem Details

Error Handling

The SDK provides typed errors for better error handling:

import { Think, ThinkNotFoundError, ThinkAPIError, ThinkValidationError } from '@think-new/sdk';

try {
  const agent = new Think('MyAgent', {
    tools: [
      'https://api.example.com/scp/calculator',
      'https://api.example.com/scp/weather'
    ]
  });
} catch (error) {
  if (error instanceof ThinkValidationError) {
    console.log('SCP Validation Error:', error.errors);
  } else if (error instanceof ThinkNotFoundError) {
    console.log('Agent not found');
  } else if (error instanceof ThinkAPIError) {
    console.log('API Error:', error.statusCode, error.response);
  }
}

API Reference

Think Class

Constructor

new Think(name: string, options?: ThinkOptions)

Options:

  • tools?: string[] - Array of SCP endpoint URLs
  • systemPrompt?: string - Initial system prompt
  • baseUrl?: string - Custom API URL (defaults to https://api.think.new/api)

Methods

  • static async fromId(id: string, options?: ThinkOptions): Promise<Think>

    • Load an existing agent by ID
  • async sendMessage(message: string, meta?: Record<string, any>, pollInterval?: number): Promise<Message>

    • Send a message to the agent and wait for the assistant's response
    • Returns the assistant's response message
    • pollInterval (optional): Interval in milliseconds to check for response (default: 1000)
    • Note: This method will wait until the assistant has finished processing, including any tool calls
  • async getMessages(): Promise<Message[]>

    • Get all messages in the conversation
  • get agentId(): string | null

    • Get the current agent ID

Error Types

  • ThinkError - Base error class
  • ThinkAPIError - API-related errors with status code and response data
  • ThinkNotFoundError - 404 Not Found errors
  • ThinkValidationError - SCP validation errors with detailed error information

SCP Compatibility

This SDK implements the Structured Completion Protocol (SCP) v1.0.0:

  • Automatic schema validation during agent creation
  • Support for RFC 7807 Problem Details
  • Version compatibility checking (v1.x.x)
  • Zod-based schema validation

License

MIT