npm.io
0.8.0 • Published yesterday

@skein-js/nestjs

Licence
Apache-2.0
Version
0.8.0
Deps
0
Vulns
0
Weekly
0
Stars
2

@skein-js/nestjs

NestJS adapter for skein-js — serve the Agent Protocol from a Nest module.

Part of skein-js — a TypeScript Agent Protocol server for LangGraph.js, and a drop-in replacement for the LangGraph CLI.

A thin transport shim over the framework-agnostic @skein-js/agent-protocol handler table — it adds no protocol logic, exactly like @skein-js/express. SkeinModule mounts the protocol as middleware: it claims skein's paths and passes every other request through to your own controllers, so it composes cleanly with an existing app.

Platform: targets NestJS's default Express platform (@nestjs/platform-express).

Install

npm i @skein-js/nestjs @nestjs/common @nestjs/core @nestjs/platform-express @langchain/langgraph

Embedded in an existing app

import { Module } from "@nestjs/common";
import { SkeinModule } from "@skein-js/nestjs";

@Module({
  imports: [SkeinModule.forRoot({ config: "./langgraph.json" })],
  controllers: [/* your own controllers */],
})
export class AppModule {}

The Agent Protocol is now served (/threads, /assistants, /runs, /store, …) alongside your routes. Pass { deps } instead of { config } to bring your own persistent drivers (Postgres + Redis) via @skein-js/runtime's buildRuntime. Call app.enableCors(...) as usual if browser clients run on another origin. Enable shutdown hooks (app.enableShutdownHooks()) so the background run worker drains on exit.

Standalone server

A dedicated server whose only job is to serve your graphs:

import { createNestServer } from "@skein-js/nestjs";

const server = await createNestServer({ config: "./langgraph.json" });
await server.listen(2024);
// on shutdown: await server.close();  // stops the run worker

Streaming

SSE responses write directly to the raw Node response and stream the pre-serialized frames the engine produced, tearing the run's subscription down on client disconnect.

API

  • SkeinModule.forRoot(options): DynamicModule — the primary entry point; imports: [...] it to mount the protocol as middleware alongside your controllers. options is SkeinRuntimeOptions.
  • SkeinMiddleware — the underlying Nest middleware, for callers wiring their own module.
  • createNestServer(options): Promise<SkeinNestServer> — a standalone server; SkeinNestServer = { app, runtime, listen(port?, host?), close() }. close() closes the Nest app, which stops the run worker via the module's shutdown hook.
  • SKEIN_RUNTIME / SKEIN_LOGGER / SKEIN_CORS — DI tokens; inject SKEIN_RUNTIME to reach the ResolvedProtocolRuntime from your own providers — its .runtime is the ProtocolRuntime (assistants, handlers, worker), plus .cors.
  • SkeinRuntimeOptions — the shared seam every adapter accepts: common { logger?, cors?, warm? } plus either { config, importModule? } (in-memory runtime from a langgraph.json) or { deps } (bring-your-own ProtocolDeps, e.g. from @skein-js/runtime's buildRuntime).
  • Low-level mappers: toProtocolRequest, plus sendNodeResponse / sendNodeError (re-exported from @skein-js/server-kit).

Learn more

License

Apache-2.0

Keywords