@lakimi/nestjs-external-schema is a library that integrates
@lakimi/external-schema
with NestJS using decorators and modules, making it easy to define and register external schema tools within a NestJS application.
- Seamless integration with NestJS using decorators and dependency injection.
- Automatic discovery and registration of external schema functions.
- Easy-to-define tools with input validation using
JSONSchema
. - Supports both synchronous and asynchronous configuration for the module.
npm install @lakimi/nestjs-external-schema
Or with Yarn:
yarn add @lakimi/nestjs-external-schema
You can register the LakimiExternalSchemaModule
in two ways: statically with predefined options or asynchronously using a factory function.
import { Module } from '@nestjs/common';
import { LakimiExternalSchemaModule } from '@lakimi/nestjs-external-schema';
@Module({
imports: [
LakimiExternalSchemaModule.forRoot({
client: {
clientId: 'your-client-id',
secretKey: 'your-secret-key',
environment: 'production',
name: 'MyApp',
},
}),
],
})
export class AppModule {}
import { Module } from '@nestjs/common';
import { LakimiExternalSchemaModule } from '@lakimi/nestjs-external-schema';
@Module({
imports: [
LakimiExternalSchemaModule.forRootAsync({
useFactory: async () => ({
client: {
clientId: 'your-client-id',
secretKey: 'your-secret-key',
environment: 'development',
name: 'MyApp',
},
}),
}),
],
})
export class AppModule {}
You can use the @LakimiFunction
decorator to define external schema tools. Each function must specify a name, description, input schema, and an optional set of constraints.
import { LakimiFunction } from '@lakimi/nestjs-external-schema';
import { JSONSchema7 } from 'json-schema';
export class MyService {
@LakimiFunction({
name: 'add_numbers',
description: 'Adds two numbers and returns the result.',
input_schema: {
type: 'object',
properties: {
a: { type: 'number' },
b: { type: 'number' },
},
required: ['a', 'b'],
},
constraints: {
auth: true,
},
})
async addNumbers(input: { a: number; b: number }): Promise<{ result: number }> {
return { result: input.a + input.b };
}
}
Once your module is configured and your functions are defined, start your NestJS application. The service will automatically discover and register all the external schema functions defined with the @LakimiFunction
decorator.
-
forRoot(options: LakimiExternalSchemaOptions): DynamicModule
: Registers the module with static options. -
forRootAsync(options: { useFactory: Function, inject?: any[] }): DynamicModule
: Registers the module with asynchronous options.
Decorator to define an external schema function.
ISC © 2025 Lakimi Solutions S.L.