import { Metorial } from 'metorial';
import { metorialAnthropic } from '@metorial/anthropic';
let metorial = new Metorial({
apiKey: process.env.METORIAL_API_KEY
});
// 1. Create OAuth sessions for each service
let slackOAuth = await metorial.oauth.sessions.create({
serverDeploymentId: 'your-slack-deployment-id',
callbackUrl: 'https://yourapp.com/oauth/callback'
});
let calendarOAuth = await metorial.oauth.sessions.create({
serverDeploymentId: 'your-google-cal-deployment-id',
callbackUrl: 'https://yourapp.com/oauth/callback'
});
// 2. Send OAuth URLs to your user
console.log('Authorize Slack:', slackOAuth.url);
console.log('Authorize Calendar:', calendarOAuth.url);
// 3. Wait for user to complete OAuth
await metorial.oauth.waitForCompletion([slackOAuth.id, calendarOAuth.id]);
// 4. Use authenticated sessions
await metorial.withProviderSession(
metorialAnthropic,
{
serverDeployments: [
{
serverDeploymentId: 'your-slack-deployment-id',
oauthSessionId: slackOAuth.id
},
{
serverDeploymentId: 'your-google-cal-deployment-id',
oauthSessionId: calendarOAuth.id
},
{
serverDeploymentId: 'your-exa-deployment-id' // No OAuth needed
}
]
},
async ({ tools, closeSession }) => {
// Use tools from all three services
await closeSession();
}
);