async function getAgentForUser(userId: string) {
// Get user's account IDs from your database
const accountIds = await db.getUserAccountIds(userId);
const toolset = new StackOneToolSet();
const tools = await toolset.fetchTools({ accountIds });
return tools.toAISDK();
}
// Usage in API endpoint
app.post('/api/chat', async (req, res) => {
const { message, userId } = req.body;
const tools = await getAgentForUser(userId);
const result = await generateText({
model: openai('gpt-5'),
tools,
prompt: message,
});
res.json({ response: result.text });
});