@nestjs/authentication 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,9 @@ export declare class AuthenticationScope {
36
36
  * GraphQL resolver whose context carries `req` (and `res`), or an
37
37
  * `@nestjs/mcp` call that arrived over HTTP (its context, the second of
38
38
  * its arguments, carries `request`). An MCP call has no response of its own
39
- * to set cookies on: the MCP SDK writes the HTTP response.
39
+ * to set cookies on: the MCP SDK writes the HTTP response. An `@nestjs/ai`
40
+ * agent function called in an HTTP request carries it the same way, and has
41
+ * no response either: the route that runs the agent owns it.
40
42
  */
41
43
  exchange(): HttpExchange | undefined;
42
44
  }
@@ -43,7 +43,9 @@ let AuthenticationScope = class AuthenticationScope {
43
43
  * GraphQL resolver whose context carries `req` (and `res`), or an
44
44
  * `@nestjs/mcp` call that arrived over HTTP (its context, the second of
45
45
  * its arguments, carries `request`). An MCP call has no response of its own
46
- * to set cookies on: the MCP SDK writes the HTTP response.
46
+ * to set cookies on: the MCP SDK writes the HTTP response. An `@nestjs/ai`
47
+ * agent function called in an HTTP request carries it the same way, and has
48
+ * no response either: the route that runs the agent owns it.
47
49
  */
48
50
  exchange() {
49
51
  const context = this.current?.context;
@@ -56,7 +58,8 @@ let AuthenticationScope = class AuthenticationScope {
56
58
  const gql = context.getArgByIndex(2);
57
59
  return gql?.req ? { request: gql.req, response: gql.res } : undefined;
58
60
  }
59
- case 'mcp': {
61
+ case 'mcp':
62
+ case 'ai': {
60
63
  const request = context.getArgByIndex(1)?.request;
61
64
  return request?.headers ? { request } : undefined;
62
65
  }
@@ -45,9 +45,9 @@ export declare function getRawResult(context: ExecutionContext): State | undefin
45
45
  export declare function getRequestHeaders(context: ExecutionContext): Headers | undefined;
46
46
  /**
47
47
  * The request behind a call, as far as authentication needs it: headers,
48
- * and the method for HTTP, GraphQL and MCP (a WebSocket handshake has none,
49
- * so it counts as a safe request). `undefined` for RPC, and for MCP over
50
- * stdio.
48
+ * and the method for HTTP, GraphQL, MCP and agent functions (a WebSocket
49
+ * handshake has none, so it counts as a safe request). `undefined` for RPC,
50
+ * for MCP over stdio, and for an agent function called in a job.
51
51
  */
52
52
  export declare function requestOf(context: ExecutionContext): {
53
53
  headers: Headers;
@@ -29,13 +29,14 @@ function callKeys(context) {
29
29
  return keys;
30
30
  }
31
31
  /**
32
- * The context of an `@nestjs/mcp` call (a tool, resource or prompt), read from
33
- * its arguments, `[input, context]`, so this package needs no `@nestjs/mcp`
34
- * dependency. Its `request` is the HTTP platform's request (a plain
32
+ * The context of an `@nestjs/mcp` call (a tool, resource or prompt) or of an
33
+ * `@nestjs/ai` agent function call, read from its arguments, `[input,
34
+ * context]`, so this package needs neither dependency. Its `request` is the
35
+ * HTTP platform's request: the one an MCP call arrived in (a plain
35
36
  * `{ method, url, headers }` object for `@nestjs/mcp/testing`'s in-memory
36
- * client), absent over stdio.
37
+ * client), or the one the agent runs in. Absent over stdio, and in a job.
37
38
  */
38
- function mcpCallOf(context) {
39
+ function callContextOf(context) {
39
40
  const call = context.getArgByIndex(1);
40
41
  return typeof call === 'object' && call !== null ? call : undefined;
41
42
  }
@@ -48,7 +49,9 @@ function mcpCallOf(context) {
48
49
  * request it arrived in, else (over stdio) its own context object. Each MCP
49
50
  * request travels in an HTTP request of its own, so the request is per call,
50
51
  * and it is the one the endpoint's route was authenticated on: a guard there
51
- * and on the call authenticate once.
52
+ * and on the call authenticate once. An agent function call (`ai`) is carried
53
+ * the same way: the HTTP request the agent runs in, which the route that runs
54
+ * it authenticated, else (in a job) its own context object.
52
55
  */
53
56
  function carrierOf(context) {
54
57
  switch (context.getType()) {
@@ -62,8 +65,9 @@ function carrierOf(context) {
62
65
  }
63
66
  case 'graphql':
64
67
  return context.getArgByIndex(2)?.req;
65
- case 'mcp': {
66
- const call = mcpCallOf(context);
68
+ case 'mcp':
69
+ case 'ai': {
70
+ const call = callContextOf(context);
67
71
  return call?.request ?? call;
68
72
  }
69
73
  default:
@@ -206,9 +210,9 @@ export function getRequestHeaders(context) {
206
210
  }
207
211
  /**
208
212
  * The request behind a call, as far as authentication needs it: headers,
209
- * and the method for HTTP, GraphQL and MCP (a WebSocket handshake has none,
210
- * so it counts as a safe request). `undefined` for RPC, and for MCP over
211
- * stdio.
213
+ * and the method for HTTP, GraphQL, MCP and agent functions (a WebSocket
214
+ * handshake has none, so it counts as a safe request). `undefined` for RPC,
215
+ * for MCP over stdio, and for an agent function called in a job.
212
216
  */
213
217
  export function requestOf(context) {
214
218
  switch (context.getType()) {
@@ -221,8 +225,9 @@ export function requestOf(context) {
221
225
  }
222
226
  case 'graphql':
223
227
  return context.getArgByIndex(2)?.req;
224
- case 'mcp': {
225
- const request = mcpCallOf(context)?.request;
228
+ case 'mcp':
229
+ case 'ai': {
230
+ const request = callContextOf(context)?.request;
226
231
  return request?.headers ? request : undefined;
227
232
  }
228
233
  default:
@@ -74,6 +74,10 @@ export async function refusal(context, { status = 401, message, code, details, c
74
74
  // MCP SDK writes the HTTP response, so no challenge goes with it: an MCP client learns where to sign in from
75
75
  // the endpoint's own 401 (`@nestjs/mcp`'s `auth` option).
76
76
  break;
77
+ case 'ai':
78
+ // Nest's own exception too, which `@nestjs/ai` gives the model as the function's error. The route that runs
79
+ // the agent owns the HTTP response, so no challenge goes with it.
80
+ break;
77
81
  }
78
82
  const Exception = status === 409 ? ConflictException : status === 403 ? ForbiddenException : UnauthorizedException;
79
83
  // Nest builds the body: `error` is the code (the description) or the status phrase, then `errorCode`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/authentication",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@authentication)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -46,21 +46,21 @@
46
46
  "@electric-sql/pglite": "0.5.8",
47
47
  "@electric-sql/pglite-socket": "0.2.11",
48
48
  "@nestjs/apollo": "14.0.1",
49
- "@nestjs/authorization": "0.1.0",
50
- "@nestjs/common": "12.3.2",
51
- "@nestjs/core": "12.3.2",
49
+ "@nestjs/authorization": "0.1.1",
50
+ "@nestjs/common": "12.3.3",
51
+ "@nestjs/core": "12.3.3",
52
52
  "@nestjs/drizzle": "0.0.2",
53
53
  "@nestjs/graphql": "14.0.1",
54
54
  "@nestjs/idempotency": "0.0.3",
55
55
  "@nestjs/mail": "0.0.1",
56
- "@nestjs/microservices": "12.3.2",
57
- "@nestjs/platform-express": "12.3.2",
58
- "@nestjs/platform-fastify": "12.3.2",
59
- "@nestjs/platform-ws": "12.3.2",
56
+ "@nestjs/microservices": "12.3.3",
57
+ "@nestjs/platform-express": "12.3.3",
58
+ "@nestjs/platform-fastify": "12.3.3",
59
+ "@nestjs/platform-ws": "12.3.3",
60
60
  "@nestjs/resilience": "0.0.3",
61
- "@nestjs/testing": "12.3.2",
61
+ "@nestjs/testing": "12.3.3",
62
62
  "@nestjs/throttler": "6.7.1",
63
- "@nestjs/websockets": "12.3.2",
63
+ "@nestjs/websockets": "12.3.3",
64
64
  "@types/node": "24.19.2",
65
65
  "@types/pg": "8.23.1",
66
66
  "@types/supertest": "7.2.1",