Skip to content

coyotiv/raison-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raison SDK

Official JavaScript/TypeScript SDK for Raison - prompt management for AI applications.

Installation

npm install raison

Quick Start

import { Raison } from 'raison'

const raison = new Raison({
  apiKey: 'rsn_dev_your_api_key',
})

// Render a prompt with variables
const text = await raison.render('prompt-id', {
  company: 'Acme Inc',
  userName: 'Alice',
})

// Find prompts by agent
const prompts = await raison.find({ agentId: 'agent-id' })

// Get a specific prompt
const prompt = await raison.findOne({ agentId: 'agent-id', name: 'System Prompt' })

API

Constructor

const raison = new Raison({
  apiKey: string,    // Required. Starts with 'rsn_'
  baseUrl?: string,  // Optional. Defaults to Raison.BASE_URL
})

render(promptId, variables?)

Render a prompt by ID. Returns empty string if not found.

const text = await raison.render('prompt-id', { userName: 'Alice' })

// Without variables returns raw template
const raw = await raison.render('prompt-id')

find(query?): Promise<Prompt[]>

Search prompts by any field.

const prompts = await raison.find({ agentId: 'agent-id' })

findOne(query): Promise<Prompt | null>

Get a single prompt.

const prompt = await raison.findOne({ agentId: 'agent-id', name: 'System Prompt' })

if (prompt) {
  const text = await raison.render(prompt.id, { userName: 'Alice' })
}

Prompt fields: id, name, agentId, version, content

disconnect()

Close the WebSocket connection.

raison.disconnect()

Raison.registerHelper(name, fn)

Register a custom Handlebars helper for use in prompt templates.

// Register helpers before rendering
Raison.registerHelper('uppercase', (str: string) => str.toUpperCase())
Raison.registerHelper('json', (value: unknown) => JSON.stringify(value, null, 2))

// Now usable in templates: {{uppercase userName}}, {{json data}}
const text = await raison.render('prompt-id', { userName: 'Alice', data: { foo: 1 } })

Template Syntax

Prompts use Handlebars:

Hello {{userName}}!

{{#if isPremium}}Premium user.{{/if}}

{{#each features}}- {{this}}
{{/each}}

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors