Aviary
Packages

@dudousxd/nestjs-agent-codegen

A @dudousxd/nestjs-codegen extension that injects a typed api.agent.* client for the agent's JSON REST routes into your generated api.ts.

The agent's controllers live in node_modules, where @dudousxd/nestjs-codegen's static AST discovery can't see them. This extension injects the JSON REST routes directly — the agents catalog, threads (incl. rename/promote/fork/truncate), tool-call approve/reject, quota, cancel — so they show up in your unified generated client.

pnpm add -D @dudousxd/nestjs-agent-codegen @dudousxd/nestjs-codegen
npm install -D @dudousxd/nestjs-agent-codegen @dudousxd/nestjs-codegen

Minimal example

// codegen.config.ts
import { defineConfig } from '@dudousxd/nestjs-codegen';
import { nestjsAgentCodegen } from '@dudousxd/nestjs-agent-codegen';

export default defineConfig({
  extensions: [nestjsAgentCodegen({ basePath: '/api' })],
});
// generated client usage — plain fetch always works:
import { api } from '../lib/api';

const threads = await api.agent.threads.list();
await api.agent.toolCall.approve({ body: { toolCallId } });

With the @dudousxd/nestjs-codegen-tanstack extension registered, each call also returns a handle with .queryOptions() / .mutationOptions():

import { useQuery, useMutation } from '@tanstack/react-query';

const threads = useQuery(api.agent.threads.list().queryOptions());
const approve = useMutation(api.agent.toolCall.approve().mutationOptions());

Streaming endpoints are deliberately omitted

POST /agent/chat and GET /agent/chat/:runId/stream are SSE, not JSON, so they're excluded from the generated client. Use @dudousxd/nestjs-agent-react's useAgentChat (a Vercel AI SDK transport) for those — see Frontend.

Exports

ExportKindPurpose
nestjsAgentCodegen(options?)function → CodegenExtensionInjects the agent's JSON REST routes (agents catalog, threads incl. rename/promote/fork/truncate, tool-call approve/reject, quota, cancel) into the codegen route set
AgentCodegenOptionstype{ basePath?: string; name?: string } — the mount prefix (default '') and the client namespace (default 'agent', i.e. api.agent.*)

Routes it injects

Method & pathGenerated name
GET /agent/agentsagent.agents.list
GET /agent/threadsagent.threads.list
GET /agent/threads/:idagent.threads.get
DELETE /agent/threads/:idagent.threads.remove
POST /agent/threads/:id/fork-from/:messageIdagent.threads.fork
PATCH /agent/threads/:idagent.threads.rename
POST /agent/threads/:id/promoteagent.threads.promote
DELETE /agent/threads/:id/from/:messageIdagent.threads.truncate
POST /agent/tool-call/approveagent.toolCall.approve
POST /agent/tool-call/rejectagent.toolCall.reject
GET /agent/quota/todayagent.quota
POST /agent/chat/:runId/cancelagent.chat.cancel

Peer dependencies

@dudousxd/nestjs-codegen (>=0.2.0).

When to use it

Add this extension once your frontend already consumes a @dudousxd/nestjs-codegen-generated client and you want the agent's thread/quota/approval surface typed the same way as the rest of your API — rather than hand-writing a client against those routes.

  • FrontenduseAgentChat, the streaming transport, and where the generated client fits alongside it
  • Codegen docs — the extension mechanism and the unified api.ts output

On this page