0.7.5 • Published 4 months ago

humanlayer v0.7.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

HumanLayer TypeScript SDK

The official TypeScript SDK for HumanLayer, providing human oversight for AI applications.

Installation

npm install humanlayer

Key Features

  • Human approval workflows for sensitive operations
  • Structured feedback collection from humans
  • Multiple contact channels (Slack, Email, etc.)
  • Full TypeScript support
  • Async/await API
  • Framework integrations

Basic Usage

import { humanlayer } from 'humanlayer'

const hl = humanlayer({
  runId: 'my-agent',
  contactChannel: {
    slack: {
      channelOrUserId: 'C123456',
      contextAboutChannelOrUser: 'the compliance team',
    },
  },
})

// Require approval for sensitive functions
const sendEmail = hl.requireApproval(async (to: string, subject: string) => {
  // Email sending logic here
})

// Get human input during execution
const support = hl.humanAsTool({
  responseOptions: [
    { name: 'approve', title: 'Approve' },
    { name: 'deny', title: 'Deny' },
  ],
})

Framework Support

  • OpenAI function calling
  • LangChain.js
  • Vercel AI SDK

Contact Channels

Configure how humans are contacted:

// Slack
const slackChannel = {
  slack: {
    channelOrUserId: 'C123456',
    contextAboutChannelOrUser: 'the support team',
  },
}

// Email
const emailChannel = {
  email: {
    address: 'support@company.com',
    contextAboutUser: 'the support team',
  },
}

Response Options

Structure human responses:

const options = [
  {
    name: 'approve',
    title: 'Approve',
    description: 'Approve the action',
  },
  {
    name: 'deny',
    title: 'Deny',
    description: 'Deny with feedback',
    promptFill: 'Denied because...',
  },
]

const approval = await hl.requireApproval(myFunction, {
  responseOptions: options,
})

Error Handling

The SDK provides detailed error types:

try {
  await hl.requireApproval(myFunction)()
} catch (error) {
  if (error instanceof HumanLayerException) {
    // Handle HumanLayer-specific errors
    console.error('HumanLayer error:', error.message)
  } else {
    // Handle other errors
    console.error('Unexpected error:', error)
  }
}

Environment Variables

Required:

  • HUMANLAYER_API_KEY: Your HumanLayer API key

Optional:

Examples

See the examples directory for complete working examples:

Development

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

# Type check
npm run check

License

Apache 2.0 - see LICENSE

0.6.2-rc1

5 months ago

0.7.4-alpha.1

5 months ago

0.7.4-alpha.2

5 months ago

0.5.8

8 months ago

0.7.5

4 months ago

0.7.0-rc1

5 months ago

0.6.1-rc2

6 months ago

0.6.1-rc1

6 months ago

0.7.5-alpha.1

4 months ago

0.7.1-rc2

5 months ago

0.7.2

5 months ago

0.7.2-rc1

5 months ago

0.7.2-rc2

5 months ago

0.7.1

5 months ago

0.7.1-rc1

5 months ago

0.7.4

5 months ago

0.7.3

5 months ago

0.7.0

5 months ago

0.6.1

6 months ago

0.6.0

7 months ago

0.5.7

8 months ago

0.5.6

8 months ago

0.5.3

9 months ago

0.5.4-rc1

9 months ago