@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-codegennpm install -D @dudousxd/nestjs-agent-codegen @dudousxd/nestjs-codegenMinimal 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
| Export | Kind | Purpose |
|---|---|---|
nestjsAgentCodegen(options?) | function → CodegenExtension | Injects 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 |
AgentCodegenOptions | type | { basePath?: string; name?: string } — the mount prefix (default '') and the client namespace (default 'agent', i.e. api.agent.*) |
Routes it injects
| Method & path | Generated name |
|---|---|
GET /agent/agents | agent.agents.list |
GET /agent/threads | agent.threads.list |
GET /agent/threads/:id | agent.threads.get |
DELETE /agent/threads/:id | agent.threads.remove |
POST /agent/threads/:id/fork-from/:messageId | agent.threads.fork |
PATCH /agent/threads/:id | agent.threads.rename |
POST /agent/threads/:id/promote | agent.threads.promote |
DELETE /agent/threads/:id/from/:messageId | agent.threads.truncate |
POST /agent/tool-call/approve | agent.toolCall.approve |
POST /agent/tool-call/reject | agent.toolCall.reject |
GET /agent/quota/today | agent.quota |
POST /agent/chat/:runId/cancel | agent.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.
Related
- Frontend —
useAgentChat, the streaming transport, and where the generated client fits alongside it - Codegen docs — the extension mechanism and the unified
api.tsoutput
@dudousxd/nestjs-agent-authz
Adapts a @dudousxd/nestjs-authz Gate to the agent's RolesPolicy SPI, so ability-gated tools run through your app's real authz policies.
@dudousxd/nestjs-agent-testing
In-memory store, governance queries, quota, token sink, and a deterministic fake model — the whole agent loop, offline.