Aller au contenu principal
SDK TYPESCRIPT • @BOUNDRY/SENSOR

SDK Node.js & TypeScript (@boundry/sensor)

Client TypeScript typé pour Vercel AI SDK, LangChain.js et API Routes Next.js / Express avec empreinte mémoire minimale.

SDK Node.js & TypeScript (@boundry/sensor)

SDK Node.js & TypeScript (@boundry/sensor)

Pour les backends développés en JavaScript ou TypeScript (Next.js App Router, Express, Fastify, NestJS, NestJS, Vercel AI SDK), le package @boundry/sensor fournit une couche d'interception asynchrone ultra-rapide.


1. Installation​

npm install @boundry/sensor

2. Initialisation du Client TypeScript​

lib/boundry.ts
import { BoundryClient } from '@boundry/sensor';

export const boundry = new BoundryClient({
apiKey: process.env.BOUNDRY_API_KEY!,
agentId: 'support-nextjs-agent',
gatewayUrl: process.env.BOUNDRY_GATEWAY_URL || 'https://api.boundry.cloud',
failSecure: true, // Bloque si la passerelle est inaccessible
timeoutMs: 2500,
});

3. Sécurisation des Fonctions d'Outils (Higher-Order Function)​

Utilisez boundry.protect() pour envelopper vos outils applicatifs :

tools/database.ts
import { boundry } from '../lib/boundry';

// 1. Définition d'un outil sensible
async function deleteUserAccountUnsafe(userId: string, reason: string): Promise<{ success: boolean }> {
// Logique d'effacement en base de données
return { success: true };
}

// 2. Exportation de la fonction protégée
export const deleteUserAccount = boundry.protect(
'delete_user_account',
deleteUserAccountUnsafe
);

4. Exemple avec Vercel AI SDK (ai/core)​

app/api/chat/route.ts
import { openai } from '@ai-sdk/openai';
import { streamText, tool } from 'ai';
import { z } from 'zod';
import { boundry } from '@/lib/boundry';

export async function POST(req: Request) {
const { messages } = await req.json();

const result = await streamText({
model: openai('gpt-4o'),
messages,
tools: {
sendRefund: tool({
description: 'Émet un remboursement vers un client.',
parameters: z.object({
customerId: z.string(),
amountEur: z.number().positive(),
}),
execute: async ({ customerId, amountEur }) => {
// Validation de sécurité en amont par Boundry
const decision = await boundry.inspectToolCall({
toolName: 'send_refund',
arguments: { customerId, amountEur },
});

if (!decision.allowed) {
throw new Error(`Action refusée par Boundry : ${decision.reason}`);
}

return { status: 'refund_processed', customerId, amountEur, hash: decision.hash };
},
}),
},
});

return result.toDataStreamResponse();
}

5. Types TypeScript et Définitions​

export interface BoundryConfig {
apiKey: string;
agentId: string;
gatewayUrl?: string;
failSecure?: boolean;
timeoutMs?: number;
batchSize?: number;
}

export interface ToolDecision {
allowed: boolean;
status: 'allowed' | 'blocked' | 'quarantined';
eventId: string;
hash: string;
riskScore: number;
reason?: string;
matchedRules?: string[];
}