Tooly
Tooly

Examples

Real-world examples of using Tooly packages

This page contains practical examples of using Tooly packages in real-world scenarios. Each example includes complete code and explanations.

Email Examples

Welcome Email Automation

Automatically send welcome emails to new users using the Resend package.

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/resend'

const tools = createAITools(process.env.RESEND_API_KEY!)

async function sendWelcomeEmail(userEmail: string, userName: string) {
  const result = await generateText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Send a welcome email to ${userEmail} for user ${userName}. Make it friendly and professional.`,
      },
    ],
    tools,
  })

  console.log('Email sent:', result.text)
  return result
}

// Usage
await sendWelcomeEmail('user@example.com', 'John Doe')

Newsletter Campaign

Create and send newsletter campaigns with AI-generated content.

import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/resend'

const tools = createAITools(process.env.RESEND_API_KEY!)

async function sendNewsletter(topic: string, subscriberEmails: string[]) {
  const { textStream } = await streamText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Create and send a newsletter about ${topic} to the following emails: ${subscriberEmails.join(', ')}. Include current trends and actionable insights.`,
      },
    ],
    tools,
  })

  for await (const chunk of textStream) {
    process.stdout.write(chunk)
  }
}

// Usage
await sendNewsletter('AI Development', ['user1@example.com', 'user2@example.com'])

Project Management Examples

Bug Report Automation

Automatically create bug reports in Linear based on user feedback.

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/linear'

const tools = createAITools(process.env.LINEAR_API_KEY!)

async function createBugReport(userFeedback: string, priority: 'low' | 'medium' | 'high' = 'medium') {
  const result = await generateText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Create a bug report with ${priority} priority based on this user feedback: "${userFeedback}". Include steps to reproduce and expected vs actual behavior.`,
      },
    ],
    tools,
  })

  console.log('Bug report created:', result.text)
  return result
}

// Usage
await createBugReport("The login button doesn't work on mobile devices", 'high')

Feature Request Processing

Convert user feature requests into properly formatted Linear issues.

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/linear'

const tools = createAITools(process.env.LINEAR_API_KEY!)

async function processFeatureRequest(request: string, requesterEmail: string) {
  const result = await generateText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Process this feature request from ${requesterEmail}: "${request}". Create a detailed Linear issue with user story format, acceptance criteria, and technical considerations.`,
      },
    ],
    tools,
  })

  console.log('Feature request processed:', result.text)
  return result
}

// Usage
await processFeatureRequest('I would like to be able to export my data as PDF', 'user@example.com')

Multi-Package Integration

Customer Support Automation

Combine multiple packages for comprehensive customer support automation.

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools as createResendTools } from '@tooly/resend'
import { createAITools as createLinearTools } from '@tooly/linear'

// Combine tools from multiple packages
const emailTools = createResendTools(process.env.RESEND_API_KEY!)
const projectTools = createLinearTools(process.env.LINEAR_API_KEY!)

const allTools = {
  ...emailTools,
  ...projectTools,
}

async function handleCustomerIssue(
  customerEmail: string,
  issueDescription: string,
  severity: 'low' | 'medium' | 'high',
) {
  const result = await generateText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Handle this ${severity} severity customer issue from ${customerEmail}: "${issueDescription}". 
        1. Send an acknowledgment email to the customer
        2. Create a tracking issue in our project management system
        3. If it's high severity, also send an alert to the support team`,
      },
    ],
    tools: allTools,
  })

  console.log('Customer issue handled:', result.text)
  return result
}

// Usage
await handleCustomerIssue('customer@example.com', 'Payment processing is failing for premium subscriptions', 'high')

Advanced Examples

AI-Powered Sprint Planning

Use AI to help organize and plan development sprints.

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/linear'

const tools = createAITools(process.env.LINEAR_API_KEY!)

async function planSprint(teamVelocity: number, backlogItems: string[], sprintGoal: string) {
  const result = await generateText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Plan a 2-week sprint for a team with velocity ${teamVelocity} story points. 
        Sprint goal: "${sprintGoal}"
        Backlog items: ${backlogItems.join(', ')}
        
        Create appropriately sized and prioritized issues in Linear, ensuring we don't overcommit.`,
      },
    ],
    tools,
  })

  console.log('Sprint planned:', result.text)
  return result
}

// Usage
await planSprint(
  25,
  ['User authentication system', 'Dashboard redesign', 'API rate limiting', 'Mobile responsiveness'],
  'Improve user onboarding experience',
)

Automated Release Notes

Generate and distribute release notes automatically.

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools as createResendTools } from '@tooly/resend'
import { createAITools as createLinearTools } from '@tooly/linear'

const emailTools = createResendTools(process.env.RESEND_API_KEY!)
const projectTools = createLinearTools(process.env.LINEAR_API_KEY!)

async function generateReleaseNotes(version: string, completedIssues: string[]) {
  const result = await generateText({
    model: openai('gpt-4.1-nano'),
    messages: [
      {
        role: 'user',
        content: `Generate release notes for version ${version} and send them to our user mailing list.
        
        Completed items: ${completedIssues.join(', ')}
        
        Format the notes with:
        1. New features
        2. Bug fixes  
        3. Improvements
        4. Breaking changes (if any)
        
        Make it user-friendly and highlight the value to customers.`,
      },
    ],
    tools: { ...emailTools, ...projectTools },
  })

  console.log('Release notes generated and sent:', result.text)
  return result
}

// Usage
await generateReleaseNotes('v2.1.0', [
  'Added dark mode support',
  'Fixed login redirect issue',
  'Improved search performance',
  'Added export functionality',
])

Error Handling

Robust Error Handling Example

import { generateText } from 'ai'
import { openai } from '@ai-sdk/openai'
import { createAITools } from '@tooly/resend'
import { ZodError } from 'zod'

const tools = createAITools(process.env.RESEND_API_KEY!)

async function robustEmailSending(to: string, subject: string, content: string) {
  try {
    const result = await generateText({
      model: openai('gpt-4.1-nano'),
      messages: [
        {
          role: 'user',
          content: `Send an email to ${to} with subject "${subject}" and content: ${content}`,
        },
      ],
      tools,
      maxRetries: 3,
    })

    return { success: true, result: result.text }
  } catch (error) {
    if (error instanceof ZodError) {
      console.error('Validation error:', error.errors)
      return { success: false, error: 'Invalid parameters provided' }
    } else if (error.message.includes('rate limit')) {
      console.error('Rate limit exceeded, retrying later...')
      return { success: false, error: 'Rate limit exceeded' }
    } else {
      console.error('Unexpected error:', error)
      return { success: false, error: 'An unexpected error occurred' }
    }
  }
}

// Usage with error handling
const result = await robustEmailSending('user@example.com', 'Welcome!', 'Thank you for signing up')

if (result.success) {
  console.log('Email sent successfully:', result.result)
} else {
  console.error('Failed to send email:', result.error)
}

Next Steps