import express from 'express';
import { Agent } from '@svantic/sdk';
import { MeshConnector } from '@svantic/sdk/mesh';
const app = express();
app.use(express.json());
// Your existing business logic
async function check_stock(product_id: string, warehouse?: string) {
// ... your existing database query ...
return { product_id, available: 42, warehouse: warehouse ?? 'all' };
}
// The thin agent layer
const agent = new Agent({
name: 'inventory-service',
description: 'Product inventory management',
public_url: 'https://inventory.example.com',
version: '1.0.0',
});
agent.define_capability({
name: 'check_stock',
description: 'Check current stock level for a product',
parameters: {
type: 'object',
properties: {
product_id: { type: 'string', description: 'Product SKU' },
warehouse: { type: 'string', description: 'Warehouse ID (optional)' },
},
required: ['product_id'],
},
handler: async (args) => check_stock(args.product_id as string, args.warehouse as string),
});
agent.expose(app);
app.listen(4200, async () => {
const mesh = new MeshConnector(agent, {
svantic_url: process.env.SVANTIC_URL ?? 'https://api.svantic.com',
client_id: process.env.SVANTIC_CLIENT_ID!,
client_secret: process.env.SVANTIC_CLIENT_SECRET!,
deployment_mode: 'hosted',
});
await mesh.connect();
});