All files / examples ai-sdk-integration.ts

0% Statements 0/12
0% Branches 0/4
0% Functions 0/1
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
/**
 * This example shows how to use StackOne tools with the AI SDK.
 */
 
import assert from 'node:assert';
import process from 'node:process';
import { openai } from '@ai-sdk/openai';
import { StackOneToolSet } from '@stackone/ai';
import { generateText, stepCountIs } from 'ai';
 
const apiKey = process.env.STACKONE_API_KEY;
if (!apiKey) {
	console.error('STACKONE_API_KEY environment variable is required');
	process.exit(1);
}
 
// Replace with your actual account ID from StackOne dashboard
const accountId = 'your-hris-account-id';
 
const aiSdkIntegration = async (): Promise<void> => {
	// Initialise StackOne
	const toolset = new StackOneToolSet({
		accountId,
		baseUrl: process.env.STACKONE_BASE_URL ?? 'https://api.stackone.com',
	});
 
	// Fetch HRIS tools via MCP
	const tools = await toolset.fetchTools({
		actions: ['hris_get_*'],
	});
 
	// Convert to AI SDK tools
	const aiSdkTools = await tools.toAISDK();
 
	// The AI SDK will automatically call the tool if needed
	const { text } = await generateText({
		model: openai('gpt-5.1'),
		tools: aiSdkTools,
		prompt: 'Get all details about employee with id: c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA',
		stopWhen: stepCountIs(3),
	});
 
	assert(text.includes('Michael'), 'Expected employee name to be included in the response');
};
 
await aiSdkIntegration();