@dudousxd/nestjs-agent-dashboard 0.18.0 → 0.19.1

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.
@@ -2,401 +2,13 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/server/agent-api.controller.ts
5
- import { Body, Controller, Get, HttpCode, Inject as Inject3, Optional as Optional3, Param, Post, Query, Req, Sse, UseGuards } from "@nestjs/common";
6
-
7
- // src/server/auth/dashboard-auth.guard.ts
8
- import { Inject, Injectable, Optional, UnauthorizedException } from "@nestjs/common";
9
-
10
- // src/server/tokens.ts
11
- var AGENT_GOVERNANCE_QUERIES = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:governance-queries");
12
- var AGENT_ACTOR_DIRECTORY = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:actor-directory");
13
- var AGENT_PRICING_STORE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:pricing-store");
14
- var AGENT_APPROVAL_PORT = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:approval-port");
15
- var AGENT_ACTOR_RESOLVER = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:actor-resolver");
16
- var DASHBOARD_BASE_PATH = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:base-path");
17
- var DASHBOARD_API_PATH = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:api-path");
18
- var DASHBOARD_APPROVAL_ACTOR_REF = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:approval-actor-ref");
19
- var DASHBOARD_AUTH = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:dashboard-auth");
20
-
21
- // src/server/auth/cookie-header.ts
22
- function parseCookieHeader(header) {
23
- const cookies = {};
24
- if (typeof header !== "string" || header === "") return cookies;
25
- for (const segment of header.split(";")) {
26
- const eq = segment.indexOf("=");
27
- if (eq <= 0) continue;
28
- const name = segment.slice(0, eq).trim();
29
- if (name === "") continue;
30
- let rawValue = segment.slice(eq + 1).trim();
31
- if (rawValue.length >= 2 && rawValue.startsWith('"') && rawValue.endsWith('"')) {
32
- rawValue = rawValue.slice(1, -1);
33
- }
34
- if (name in cookies) continue;
35
- try {
36
- cookies[name] = decodeURIComponent(rawValue);
37
- } catch {
38
- cookies[name] = rawValue;
39
- }
40
- }
41
- return cookies;
42
- }
43
- __name(parseCookieHeader, "parseCookieHeader");
44
- function serializeSetCookie(name, value, options) {
45
- const parts = [
46
- `${name}=${options.clear ? "" : encodeURIComponent(value)}`
47
- ];
48
- parts.push(`Path=${options.path}`);
49
- parts.push("HttpOnly");
50
- parts.push("SameSite=Lax");
51
- if (options.secure) parts.push("Secure");
52
- if (options.clear) {
53
- parts.push("Max-Age=0");
54
- parts.push("Expires=Thu, 01 Jan 1970 00:00:00 GMT");
55
- } else {
56
- parts.push(`Max-Age=${options.maxAgeSeconds}`);
57
- }
58
- return parts.join("; ");
59
- }
60
- __name(serializeSetCookie, "serializeSetCookie");
61
-
62
- // src/server/auth/http-request.ts
63
- function isRecord(value) {
64
- return typeof value === "object" && value !== null;
65
- }
66
- __name(isRecord, "isRecord");
67
- function readHeaders(request) {
68
- if (!isRecord(request)) return {};
69
- const headers = request.headers;
70
- return isRecord(headers) ? headers : {};
71
- }
72
- __name(readHeaders, "readHeaders");
73
- function headerToString(value) {
74
- if (typeof value === "string") return value;
75
- if (Array.isArray(value) && value.every((part) => typeof part === "string")) {
76
- return value.join(",");
77
- }
78
- return void 0;
79
- }
80
- __name(headerToString, "headerToString");
81
- function readCookieHeader(request) {
82
- return headerToString(readHeaders(request).cookie);
83
- }
84
- __name(readCookieHeader, "readCookieHeader");
85
- function isHttpsRequest(request) {
86
- if (isRecord(request) && request.protocol === "https") return true;
87
- const forwarded = headerToString(readHeaders(request)["x-forwarded-proto"]);
88
- if (forwarded === void 0) return false;
89
- return forwarded.split(",").map((proto) => proto.trim().toLowerCase()).includes("https");
90
- }
91
- __name(isHttpsRequest, "isHttpsRequest");
92
- function readOriginalUrl(request) {
93
- if (!isRecord(request)) return "/";
94
- const originalUrl = request.originalUrl;
95
- if (typeof originalUrl === "string" && originalUrl !== "") return originalUrl;
96
- const url = request.url;
97
- return typeof url === "string" && url !== "" ? url : "/";
98
- }
99
- __name(readOriginalUrl, "readOriginalUrl");
100
- function attachSession(request, session) {
101
- if (!isRecord(request)) return;
102
- const target = request;
103
- target.dashboardSession = session;
104
- }
105
- __name(attachSession, "attachSession");
106
-
107
- // src/server/auth/response.ts
108
- function isRecord2(value) {
109
- return typeof value === "object" && value !== null;
110
- }
111
- __name(isRecord2, "isRecord");
112
- function isHeaderCapableResponse(value) {
113
- return isRecord2(value) && typeof value.getHeader === "function" && typeof value.setHeader === "function";
114
- }
115
- __name(isHeaderCapableResponse, "isHeaderCapableResponse");
116
- function resolveHeaderCapableResponse(response) {
117
- if (isHeaderCapableResponse(response)) return response;
118
- if (isRecord2(response) && isHeaderCapableResponse(response.raw)) return response.raw;
119
- return null;
120
- }
121
- __name(resolveHeaderCapableResponse, "resolveHeaderCapableResponse");
122
- function existingSetCookies(response) {
123
- const current = response.getHeader("set-cookie");
124
- if (Array.isArray(current)) return current;
125
- if (typeof current === "string") return [
126
- current
127
- ];
128
- return [];
129
- }
130
- __name(existingSetCookies, "existingSetCookies");
131
- function appendSetCookie(response, cookie) {
132
- const raw = resolveHeaderCapableResponse(response);
133
- if (!raw) return;
134
- raw.setHeader("set-cookie", [
135
- ...existingSetCookies(raw),
136
- cookie
137
- ]);
138
- }
139
- __name(appendSetCookie, "appendSetCookie");
140
- function isRawNodeResponse(value) {
141
- return isRecord2(value) && typeof value.getHeader === "function" && typeof value.setHeader === "function" && typeof value.end === "function";
142
- }
143
- __name(isRawNodeResponse, "isRawNodeResponse");
144
- function resolveRawResponse(response) {
145
- if (isRawNodeResponse(response)) return response;
146
- if (isRecord2(response) && isRawNodeResponse(response.raw)) return response.raw;
147
- return null;
148
- }
149
- __name(resolveRawResponse, "resolveRawResponse");
150
- function responseAlreadyWritten(response) {
151
- const raw = resolveRawResponse(response);
152
- return raw?.headersSent === true;
153
- }
154
- __name(responseAlreadyWritten, "responseAlreadyWritten");
155
- function sendHtml(response, status, html) {
156
- const raw = resolveRawResponse(response);
157
- if (!raw) return;
158
- raw.statusCode = status;
159
- raw.setHeader("content-type", "text/html; charset=utf-8");
160
- raw.setHeader("cache-control", "no-store, must-revalidate");
161
- raw.end(html);
162
- }
163
- __name(sendHtml, "sendHtml");
164
- function sendRedirect(response, status, location) {
165
- const raw = resolveRawResponse(response);
166
- if (!raw) return;
167
- raw.statusCode = status;
168
- raw.setHeader("location", location);
169
- raw.end();
170
- }
171
- __name(sendRedirect, "sendRedirect");
172
-
173
- // src/server/auth/session-cookie.ts
174
- import { createHmac, timingSafeEqual } from "crypto";
175
- var EXP_GRACE_MS = 3e4;
176
- function base64urlEncode(value) {
177
- return Buffer.from(value, "utf8").toString("base64url");
178
- }
179
- __name(base64urlEncode, "base64urlEncode");
180
- function base64urlDecode(value) {
181
- return Buffer.from(value, "base64url").toString("utf8");
182
- }
183
- __name(base64urlDecode, "base64urlDecode");
184
- function hmac(secret, payload) {
185
- return createHmac("sha256", secret).update(payload).digest("base64url");
186
- }
187
- __name(hmac, "hmac");
188
- function signSessionCookie(user, options) {
189
- const issuedAt = options.now ?? Date.now();
190
- const session = {
191
- sub: user.id,
192
- ...user.name !== void 0 ? {
193
- name: user.name
194
- } : {},
195
- roles: user.roles ?? [],
196
- iat: issuedAt,
197
- exp: issuedAt + options.ttlMs
198
- };
199
- const encodedPayload = base64urlEncode(JSON.stringify(session));
200
- const signature = hmac(options.secret, encodedPayload);
201
- return `${encodedPayload}.${signature}`;
202
- }
203
- __name(signSessionCookie, "signSessionCookie");
204
- function isSessionPayload(value) {
205
- if (typeof value !== "object" || value === null) return false;
206
- const record = {
207
- ...value
208
- };
209
- if (typeof record.sub !== "string") return false;
210
- if (record.name !== void 0 && typeof record.name !== "string") return false;
211
- if (!Array.isArray(record.roles)) return false;
212
- if (!record.roles.every((role) => typeof role === "string")) return false;
213
- if (typeof record.iat !== "number" || !Number.isFinite(record.iat)) return false;
214
- if (typeof record.exp !== "number" || !Number.isFinite(record.exp)) return false;
215
- return true;
216
- }
217
- __name(isSessionPayload, "isSessionPayload");
218
- function verifySessionCookie(value, options) {
219
- try {
220
- const dot = value.indexOf(".");
221
- if (dot <= 0 || dot === value.length - 1) return null;
222
- const encodedPayload = value.slice(0, dot);
223
- const providedSignature = value.slice(dot + 1);
224
- const expectedSignature = hmac(options.secret, encodedPayload);
225
- const provided = Buffer.from(providedSignature, "base64url");
226
- const expected = Buffer.from(expectedSignature, "base64url");
227
- if (provided.length !== expected.length) return null;
228
- if (!timingSafeEqual(provided, expected)) return null;
229
- const decoded = JSON.parse(base64urlDecode(encodedPayload));
230
- if (!isSessionPayload(decoded)) return null;
231
- const now = options.now ?? Date.now();
232
- if (now > decoded.exp + EXP_GRACE_MS) return null;
233
- const session = {
234
- sub: decoded.sub,
235
- ...decoded.name !== void 0 ? {
236
- name: decoded.name
237
- } : {},
238
- roles: decoded.roles,
239
- iat: decoded.iat,
240
- exp: decoded.exp
241
- };
242
- return session;
243
- } catch {
244
- return null;
245
- }
246
- }
247
- __name(verifySessionCookie, "verifySessionCookie");
248
-
249
- // src/server/auth/session-cookie-io.ts
250
- var SESSION_COOKIE_NAME = "agent_dashboard_session";
251
- var COOKIE_PATH = "/";
252
- function issueSessionCookie(user, context) {
253
- const value = signSessionCookie(user, {
254
- secret: context.auth.secret,
255
- ttlMs: context.auth.ttlMs,
256
- ...context.now !== void 0 ? {
257
- now: context.now
258
- } : {}
259
- });
260
- const cookie = serializeSetCookie(SESSION_COOKIE_NAME, value, {
261
- path: COOKIE_PATH,
262
- maxAgeSeconds: Math.floor(context.auth.ttlMs / 1e3),
263
- secure: isHttpsRequest(context.request)
264
- });
265
- appendSetCookie(context.response, cookie);
266
- }
267
- __name(issueSessionCookie, "issueSessionCookie");
268
- function clearSessionCookie(context) {
269
- const cookie = serializeSetCookie(SESSION_COOKIE_NAME, "", {
270
- path: COOKIE_PATH,
271
- maxAgeSeconds: 0,
272
- secure: isHttpsRequest(context.request),
273
- clear: true
274
- });
275
- appendSetCookie(context.response, cookie);
276
- }
277
- __name(clearSessionCookie, "clearSessionCookie");
278
- var inFlightRevalidations = /* @__PURE__ */ new Map();
279
- function revalidationKey(session) {
280
- return `${session.sub}:${session.iat}`;
281
- }
282
- __name(revalidationKey, "revalidationKey");
283
- function getOrStartRevalidation(auth, session, user) {
284
- const hook = auth.revalidate;
285
- if (!hook) return Promise.resolve(true);
286
- const key = revalidationKey(session);
287
- const inFlight = inFlightRevalidations.get(key);
288
- if (inFlight) return inFlight;
289
- const outcome = (async () => {
290
- try {
291
- return await hook(user);
292
- } catch {
293
- return false;
294
- }
295
- })().finally(() => {
296
- inFlightRevalidations.delete(key);
297
- });
298
- inFlightRevalidations.set(key, outcome);
299
- return outcome;
300
- }
301
- __name(getOrStartRevalidation, "getOrStartRevalidation");
302
- async function maybeRenewSession(auth, session, request, response, now = Date.now()) {
303
- if (now - session.iat <= auth.ttlMs / 2) return true;
304
- const user = {
305
- id: session.sub,
306
- ...session.name !== void 0 ? {
307
- name: session.name
308
- } : {},
309
- roles: session.roles
310
- };
311
- const allowed = await getOrStartRevalidation(auth, session, user);
312
- if (!allowed) {
313
- clearSessionCookie({
314
- request,
315
- response
316
- });
317
- return false;
318
- }
319
- issueSessionCookie(user, {
320
- auth,
321
- request,
322
- response,
323
- now
324
- });
325
- return true;
326
- }
327
- __name(maybeRenewSession, "maybeRenewSession");
328
-
329
- // src/server/auth/dashboard-auth.guard.ts
330
- function _ts_decorate(decorators, target, key, desc) {
331
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
332
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
333
- r = Reflect.decorate(decorators, target, key, desc);
334
- } else {
335
- for (var i = decorators.length - 1; i >= 0; i--) {
336
- if (d = decorators[i]) {
337
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
338
- }
339
- }
340
- }
341
- return c > 3 && r && Object.defineProperty(target, key, r), r;
342
- }
343
- __name(_ts_decorate, "_ts_decorate");
344
- function _ts_metadata(metadataKey, metadataValue) {
345
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
346
- return Reflect.metadata(metadataKey, metadataValue);
347
- }
348
- }
349
- __name(_ts_metadata, "_ts_metadata");
350
- function _ts_param(paramIndex, decorator) {
351
- return function(target, key) {
352
- decorator(target, key, paramIndex);
353
- };
354
- }
355
- __name(_ts_param, "_ts_param");
356
- var DashboardAuthGuard = class {
357
- static {
358
- __name(this, "DashboardAuthGuard");
359
- }
360
- auth;
361
- constructor(auth) {
362
- this.auth = auth;
363
- }
364
- async canActivate(context) {
365
- if (!this.auth) return true;
366
- const http = context.switchToHttp();
367
- const request = http.getRequest();
368
- const session = this.verifyRequestSession(request);
369
- if (!session) throw new UnauthorizedException();
370
- attachSession(request, session);
371
- if (!await maybeRenewSession(this.auth, session, request, http.getResponse())) {
372
- throw new UnauthorizedException();
373
- }
374
- return true;
375
- }
376
- verifyRequestSession(request) {
377
- const auth = this.auth;
378
- if (!auth) return null;
379
- const cookieValue = parseCookieHeader(readCookieHeader(request))[SESSION_COOKIE_NAME];
380
- if (cookieValue === void 0) return null;
381
- return verifySessionCookie(cookieValue, {
382
- secret: auth.secret
383
- });
384
- }
385
- };
386
- DashboardAuthGuard = _ts_decorate([
387
- Injectable(),
388
- _ts_param(0, Optional()),
389
- _ts_param(0, Inject(DASHBOARD_AUTH)),
390
- _ts_metadata("design:type", Function),
391
- _ts_metadata("design:paramtypes", [
392
- Object
393
- ])
394
- ], DashboardAuthGuard);
5
+ import { CanAnyone } from "@dudousxd/nestjs-agent-core";
6
+ import { Body, Controller, Get, HttpCode, Inject as Inject2, Optional as Optional2, Param, Post, Query, Req, Sse } from "@nestjs/common";
395
7
 
396
8
  // src/server/dashboard.service.ts
397
9
  import { subscribe, unsubscribe } from "diagnostics_channel";
398
10
  import { channelName } from "@dudousxd/nestjs-diagnostics";
399
- import { Inject as Inject2, Injectable as Injectable2, NotFoundException, NotImplementedException, Optional as Optional2 } from "@nestjs/common";
11
+ import { Inject, Injectable, NotFoundException, NotImplementedException, Optional } from "@nestjs/common";
400
12
  import { Observable as Observable2 } from "rxjs";
401
13
 
402
14
  // src/server/parse-approval-decision.ts
@@ -461,8 +73,18 @@ function isFiniteNonNegative(value) {
461
73
  }
462
74
  __name(isFiniteNonNegative, "isFiniteNonNegative");
463
75
 
76
+ // src/server/tokens.ts
77
+ var AGENT_GOVERNANCE_QUERIES = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:governance-queries");
78
+ var AGENT_ACTOR_DIRECTORY = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:actor-directory");
79
+ var AGENT_PRICING_STORE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:pricing-store");
80
+ var AGENT_APPROVAL_PORT = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:approval-port");
81
+ var AGENT_ACTOR_RESOLVER = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:actor-resolver");
82
+ var DASHBOARD_BASE_PATH = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:base-path");
83
+ var DASHBOARD_API_PATH = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:api-path");
84
+ var DASHBOARD_APPROVAL_ACTOR_REF = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent-dashboard:approval-actor-ref");
85
+
464
86
  // src/server/dashboard.service.ts
465
- function _ts_decorate2(decorators, target, key, desc) {
87
+ function _ts_decorate(decorators, target, key, desc) {
466
88
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
467
89
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
468
90
  r = Reflect.decorate(decorators, target, key, desc);
@@ -475,19 +97,19 @@ function _ts_decorate2(decorators, target, key, desc) {
475
97
  }
476
98
  return c > 3 && r && Object.defineProperty(target, key, r), r;
477
99
  }
478
- __name(_ts_decorate2, "_ts_decorate");
479
- function _ts_metadata2(metadataKey, metadataValue) {
100
+ __name(_ts_decorate, "_ts_decorate");
101
+ function _ts_metadata(metadataKey, metadataValue) {
480
102
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
481
103
  return Reflect.metadata(metadataKey, metadataValue);
482
104
  }
483
105
  }
484
- __name(_ts_metadata2, "_ts_metadata");
485
- function _ts_param2(paramIndex, decorator) {
106
+ __name(_ts_metadata, "_ts_metadata");
107
+ function _ts_param(paramIndex, decorator) {
486
108
  return function(target, key) {
487
109
  decorator(target, key, paramIndex);
488
110
  };
489
111
  }
490
- __name(_ts_param2, "_ts_param");
112
+ __name(_ts_param, "_ts_param");
491
113
  var PRICING_STORE_UNBOUND_MESSAGE = "Pricing CRUD is unavailable: no AGENT_PRICING_STORE is bound. Bind a pricing store (e.g. MikroOrmPricingStore from @dudousxd/nestjs-agent-store-mikro-orm) to enable it.";
492
114
  var APPROVAL_PORT_UNBOUND_MESSAGE = "Approve/reject is unavailable: no AGENT_APPROVAL_PORT is bound. Import AgentModule from @dudousxd/nestjs-agent alongside this dashboard to enable it \u2014 the approvals inbox stays read-only until then.";
493
115
  var GENUI_STATS_UNSUPPORTED_MESSAGE = "Generative UI telemetry is unavailable: the bound AGENT_GOVERNANCE_QUERIES store does not implement genuiStats. Use a store adapter that records generative-UI calls (recordGenuiCalls) to enable it.";
@@ -756,17 +378,17 @@ var DashboardService = class {
756
378
  });
757
379
  }
758
380
  };
759
- DashboardService = _ts_decorate2([
760
- Injectable2(),
761
- _ts_param2(0, Inject2(AGENT_GOVERNANCE_QUERIES)),
762
- _ts_param2(1, Optional2()),
763
- _ts_param2(1, Inject2(AGENT_ACTOR_DIRECTORY)),
764
- _ts_param2(2, Optional2()),
765
- _ts_param2(2, Inject2(AGENT_PRICING_STORE)),
766
- _ts_param2(3, Optional2()),
767
- _ts_param2(3, Inject2(AGENT_APPROVAL_PORT)),
768
- _ts_metadata2("design:type", Function),
769
- _ts_metadata2("design:paramtypes", [
381
+ DashboardService = _ts_decorate([
382
+ Injectable(),
383
+ _ts_param(0, Inject(AGENT_GOVERNANCE_QUERIES)),
384
+ _ts_param(1, Optional()),
385
+ _ts_param(1, Inject(AGENT_ACTOR_DIRECTORY)),
386
+ _ts_param(2, Optional()),
387
+ _ts_param(2, Inject(AGENT_PRICING_STORE)),
388
+ _ts_param(3, Optional()),
389
+ _ts_param(3, Inject(AGENT_APPROVAL_PORT)),
390
+ _ts_metadata("design:type", Function),
391
+ _ts_metadata("design:paramtypes", [
770
392
  typeof AgentGovernanceQueries === "undefined" ? Object : AgentGovernanceQueries,
771
393
  typeof ActorDirectory === "undefined" ? Object : ActorDirectory,
772
394
  typeof AgentPricingStore === "undefined" ? Object : AgentPricingStore,
@@ -934,7 +556,7 @@ function parseApprovalWhere(raw) {
934
556
  __name(parseApprovalWhere, "parseApprovalWhere");
935
557
 
936
558
  // src/server/agent-api.controller.ts
937
- function _ts_decorate3(decorators, target, key, desc) {
559
+ function _ts_decorate2(decorators, target, key, desc) {
938
560
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
939
561
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
940
562
  r = Reflect.decorate(decorators, target, key, desc);
@@ -947,19 +569,19 @@ function _ts_decorate3(decorators, target, key, desc) {
947
569
  }
948
570
  return c > 3 && r && Object.defineProperty(target, key, r), r;
949
571
  }
950
- __name(_ts_decorate3, "_ts_decorate");
951
- function _ts_metadata3(metadataKey, metadataValue) {
572
+ __name(_ts_decorate2, "_ts_decorate");
573
+ function _ts_metadata2(metadataKey, metadataValue) {
952
574
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
953
575
  return Reflect.metadata(metadataKey, metadataValue);
954
576
  }
955
577
  }
956
- __name(_ts_metadata3, "_ts_metadata");
957
- function _ts_param3(paramIndex, decorator) {
578
+ __name(_ts_metadata2, "_ts_metadata");
579
+ function _ts_param2(paramIndex, decorator) {
958
580
  return function(target, key) {
959
581
  decorator(target, key, paramIndex);
960
582
  };
961
583
  }
962
- __name(_ts_param3, "_ts_param");
584
+ __name(_ts_param2, "_ts_param");
963
585
  var DAY_MS = 864e5;
964
586
  var ISO_DAY2 = /^\d{4}-\d{2}-\d{2}$/;
965
587
  function utcDay(daysAgo) {
@@ -1177,620 +799,222 @@ var AgentApiController = class {
1177
799
  return this.dashboard.streamEvents();
1178
800
  }
1179
801
  };
1180
- _ts_decorate3([
802
+ _ts_decorate2([
1181
803
  Get("spend"),
1182
- _ts_param3(0, Query("from")),
1183
- _ts_param3(1, Query("to")),
1184
- _ts_metadata3("design:type", Function),
1185
- _ts_metadata3("design:paramtypes", [
804
+ _ts_param2(0, Query("from")),
805
+ _ts_param2(1, Query("to")),
806
+ _ts_metadata2("design:type", Function),
807
+ _ts_metadata2("design:paramtypes", [
1186
808
  String,
1187
809
  String
1188
810
  ]),
1189
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
811
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1190
812
  ], AgentApiController.prototype, "spend", null);
1191
- _ts_decorate3([
813
+ _ts_decorate2([
1192
814
  Get("top-threads"),
1193
- _ts_param3(0, Query("from")),
1194
- _ts_param3(1, Query("to")),
1195
- _ts_param3(2, Query("limit")),
1196
- _ts_metadata3("design:type", Function),
1197
- _ts_metadata3("design:paramtypes", [
815
+ _ts_param2(0, Query("from")),
816
+ _ts_param2(1, Query("to")),
817
+ _ts_param2(2, Query("limit")),
818
+ _ts_metadata2("design:type", Function),
819
+ _ts_metadata2("design:paramtypes", [
1198
820
  String,
1199
821
  String,
1200
822
  String
1201
823
  ]),
1202
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
824
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1203
825
  ], AgentApiController.prototype, "topThreads", null);
1204
- _ts_decorate3([
826
+ _ts_decorate2([
1205
827
  Get("reliability"),
1206
- _ts_param3(0, Query("from")),
1207
- _ts_param3(1, Query("to")),
1208
- _ts_metadata3("design:type", Function),
1209
- _ts_metadata3("design:paramtypes", [
828
+ _ts_param2(0, Query("from")),
829
+ _ts_param2(1, Query("to")),
830
+ _ts_metadata2("design:type", Function),
831
+ _ts_metadata2("design:paramtypes", [
1210
832
  String,
1211
833
  String
1212
834
  ]),
1213
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
835
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1214
836
  ], AgentApiController.prototype, "reliability", null);
1215
- _ts_decorate3([
837
+ _ts_decorate2([
1216
838
  Get("runs"),
1217
- _ts_param3(0, Query("limit")),
1218
- _ts_metadata3("design:type", Function),
1219
- _ts_metadata3("design:paramtypes", [
839
+ _ts_param2(0, Query("limit")),
840
+ _ts_metadata2("design:type", Function),
841
+ _ts_metadata2("design:paramtypes", [
1220
842
  String
1221
843
  ]),
1222
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
844
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1223
845
  ], AgentApiController.prototype, "runs", null);
1224
- _ts_decorate3([
846
+ _ts_decorate2([
1225
847
  Get("runs-page"),
1226
- _ts_param3(0, Query("page")),
1227
- _ts_param3(1, Query("limit")),
1228
- _ts_param3(2, Query("where")),
1229
- _ts_metadata3("design:type", Function),
1230
- _ts_metadata3("design:paramtypes", [
848
+ _ts_param2(0, Query("page")),
849
+ _ts_param2(1, Query("limit")),
850
+ _ts_param2(2, Query("where")),
851
+ _ts_metadata2("design:type", Function),
852
+ _ts_metadata2("design:paramtypes", [
1231
853
  String,
1232
854
  String,
1233
855
  typeof Record === "undefined" ? Object : Record
1234
856
  ]),
1235
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
857
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1236
858
  ], AgentApiController.prototype, "runsPage", null);
1237
- _ts_decorate3([
859
+ _ts_decorate2([
1238
860
  Get("runs/:runId"),
1239
- _ts_param3(0, Param("runId")),
1240
- _ts_metadata3("design:type", Function),
1241
- _ts_metadata3("design:paramtypes", [
861
+ _ts_param2(0, Param("runId")),
862
+ _ts_metadata2("design:type", Function),
863
+ _ts_metadata2("design:paramtypes", [
1242
864
  String
1243
865
  ]),
1244
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
866
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1245
867
  ], AgentApiController.prototype, "runDetail", null);
1246
- _ts_decorate3([
868
+ _ts_decorate2([
1247
869
  Get("tool-calls"),
1248
- _ts_param3(0, Query("limit")),
1249
- _ts_metadata3("design:type", Function),
1250
- _ts_metadata3("design:paramtypes", [
870
+ _ts_param2(0, Query("limit")),
871
+ _ts_metadata2("design:type", Function),
872
+ _ts_metadata2("design:paramtypes", [
1251
873
  String
1252
874
  ]),
1253
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
875
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1254
876
  ], AgentApiController.prototype, "toolCalls", null);
1255
- _ts_decorate3([
877
+ _ts_decorate2([
1256
878
  Get("tool-calls-page"),
1257
- _ts_param3(0, Query("page")),
1258
- _ts_param3(1, Query("limit")),
1259
- _ts_param3(2, Query("where")),
1260
- _ts_metadata3("design:type", Function),
1261
- _ts_metadata3("design:paramtypes", [
879
+ _ts_param2(0, Query("page")),
880
+ _ts_param2(1, Query("limit")),
881
+ _ts_param2(2, Query("where")),
882
+ _ts_metadata2("design:type", Function),
883
+ _ts_metadata2("design:paramtypes", [
1262
884
  String,
1263
885
  String,
1264
886
  typeof Record === "undefined" ? Object : Record
1265
887
  ]),
1266
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
888
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1267
889
  ], AgentApiController.prototype, "toolCallsPage", null);
1268
- _ts_decorate3([
890
+ _ts_decorate2([
1269
891
  Get("approvals"),
1270
- _ts_param3(0, Query("limit")),
1271
- _ts_metadata3("design:type", Function),
1272
- _ts_metadata3("design:paramtypes", [
892
+ _ts_param2(0, Query("limit")),
893
+ _ts_metadata2("design:type", Function),
894
+ _ts_metadata2("design:paramtypes", [
1273
895
  String
1274
896
  ]),
1275
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
897
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1276
898
  ], AgentApiController.prototype, "approvals", null);
1277
- _ts_decorate3([
899
+ _ts_decorate2([
1278
900
  Get("approvals-page"),
1279
- _ts_param3(0, Query("page")),
1280
- _ts_param3(1, Query("limit")),
1281
- _ts_param3(2, Query("where")),
1282
- _ts_metadata3("design:type", Function),
1283
- _ts_metadata3("design:paramtypes", [
901
+ _ts_param2(0, Query("page")),
902
+ _ts_param2(1, Query("limit")),
903
+ _ts_param2(2, Query("where")),
904
+ _ts_metadata2("design:type", Function),
905
+ _ts_metadata2("design:paramtypes", [
1284
906
  String,
1285
907
  String,
1286
908
  typeof Record === "undefined" ? Object : Record
1287
909
  ]),
1288
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
910
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1289
911
  ], AgentApiController.prototype, "approvalsPage", null);
1290
- _ts_decorate3([
912
+ _ts_decorate2([
1291
913
  Post("approvals/:toolCallId"),
1292
914
  HttpCode(204),
1293
- _ts_param3(0, Param("toolCallId")),
1294
- _ts_param3(1, Body()),
1295
- _ts_param3(2, Req()),
1296
- _ts_metadata3("design:type", Function),
1297
- _ts_metadata3("design:paramtypes", [
915
+ _ts_param2(0, Param("toolCallId")),
916
+ _ts_param2(1, Body()),
917
+ _ts_param2(2, Req()),
918
+ _ts_metadata2("design:type", Function),
919
+ _ts_metadata2("design:paramtypes", [
1298
920
  String,
1299
921
  Object,
1300
922
  Object
1301
923
  ]),
1302
- _ts_metadata3("design:returntype", Promise)
924
+ _ts_metadata2("design:returntype", Promise)
1303
925
  ], AgentApiController.prototype, "decideApproval", null);
1304
- _ts_decorate3([
926
+ _ts_decorate2([
1305
927
  Get("tools"),
1306
- _ts_param3(0, Query("from")),
1307
- _ts_param3(1, Query("to")),
1308
- _ts_metadata3("design:type", Function),
1309
- _ts_metadata3("design:paramtypes", [
928
+ _ts_param2(0, Query("from")),
929
+ _ts_param2(1, Query("to")),
930
+ _ts_metadata2("design:type", Function),
931
+ _ts_metadata2("design:paramtypes", [
1310
932
  String,
1311
933
  String
1312
934
  ]),
1313
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
935
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1314
936
  ], AgentApiController.prototype, "tools", null);
1315
- _ts_decorate3([
937
+ _ts_decorate2([
1316
938
  Get("genui"),
1317
- _ts_param3(0, Query("from")),
1318
- _ts_param3(1, Query("to")),
1319
- _ts_metadata3("design:type", Function),
1320
- _ts_metadata3("design:paramtypes", [
939
+ _ts_param2(0, Query("from")),
940
+ _ts_param2(1, Query("to")),
941
+ _ts_metadata2("design:type", Function),
942
+ _ts_metadata2("design:paramtypes", [
1321
943
  String,
1322
944
  String
1323
945
  ]),
1324
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
946
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1325
947
  ], AgentApiController.prototype, "genui", null);
1326
- _ts_decorate3([
948
+ _ts_decorate2([
1327
949
  Get("threads"),
1328
- _ts_param3(0, Query("limit")),
1329
- _ts_metadata3("design:type", Function),
1330
- _ts_metadata3("design:paramtypes", [
950
+ _ts_param2(0, Query("limit")),
951
+ _ts_metadata2("design:type", Function),
952
+ _ts_metadata2("design:paramtypes", [
1331
953
  String
1332
954
  ]),
1333
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
955
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1334
956
  ], AgentApiController.prototype, "threads", null);
1335
- _ts_decorate3([
957
+ _ts_decorate2([
1336
958
  Get("threads-page"),
1337
- _ts_param3(0, Query("page")),
1338
- _ts_param3(1, Query("limit")),
1339
- _ts_param3(2, Query("where")),
1340
- _ts_metadata3("design:type", Function),
1341
- _ts_metadata3("design:paramtypes", [
959
+ _ts_param2(0, Query("page")),
960
+ _ts_param2(1, Query("limit")),
961
+ _ts_param2(2, Query("where")),
962
+ _ts_metadata2("design:type", Function),
963
+ _ts_metadata2("design:paramtypes", [
1342
964
  String,
1343
965
  String,
1344
966
  typeof Record === "undefined" ? Object : Record
1345
967
  ]),
1346
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
968
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1347
969
  ], AgentApiController.prototype, "threadsPage", null);
1348
- _ts_decorate3([
970
+ _ts_decorate2([
1349
971
  Get("threads/:threadId"),
1350
- _ts_param3(0, Param("threadId")),
1351
- _ts_param3(1, Query("messages")),
1352
- _ts_param3(2, Query("runs")),
1353
- _ts_metadata3("design:type", Function),
1354
- _ts_metadata3("design:paramtypes", [
972
+ _ts_param2(0, Param("threadId")),
973
+ _ts_param2(1, Query("messages")),
974
+ _ts_param2(2, Query("runs")),
975
+ _ts_metadata2("design:type", Function),
976
+ _ts_metadata2("design:paramtypes", [
1355
977
  String,
1356
978
  String,
1357
979
  String
1358
980
  ]),
1359
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
981
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1360
982
  ], AgentApiController.prototype, "threadDetail", null);
1361
- _ts_decorate3([
983
+ _ts_decorate2([
1362
984
  Get("pricing"),
1363
- _ts_metadata3("design:type", Function),
1364
- _ts_metadata3("design:paramtypes", []),
1365
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
985
+ _ts_metadata2("design:type", Function),
986
+ _ts_metadata2("design:paramtypes", []),
987
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1366
988
  ], AgentApiController.prototype, "listPrices", null);
1367
- _ts_decorate3([
989
+ _ts_decorate2([
1368
990
  Post("pricing"),
1369
- _ts_param3(0, Body()),
1370
- _ts_metadata3("design:type", Function),
1371
- _ts_metadata3("design:paramtypes", [
991
+ _ts_param2(0, Body()),
992
+ _ts_metadata2("design:type", Function),
993
+ _ts_metadata2("design:paramtypes", [
1372
994
  Object
1373
995
  ]),
1374
- _ts_metadata3("design:returntype", typeof Promise === "undefined" ? Object : Promise)
996
+ _ts_metadata2("design:returntype", typeof Promise === "undefined" ? Object : Promise)
1375
997
  ], AgentApiController.prototype, "upsertPrice", null);
1376
- _ts_decorate3([
998
+ _ts_decorate2([
1377
999
  Sse("stream"),
1378
- _ts_metadata3("design:type", Function),
1379
- _ts_metadata3("design:paramtypes", []),
1380
- _ts_metadata3("design:returntype", typeof Observable === "undefined" ? Object : Observable)
1000
+ _ts_metadata2("design:type", Function),
1001
+ _ts_metadata2("design:paramtypes", []),
1002
+ _ts_metadata2("design:returntype", typeof Observable === "undefined" ? Object : Observable)
1381
1003
  ], AgentApiController.prototype, "stream", null);
1382
- AgentApiController = _ts_decorate3([
1004
+ AgentApiController = _ts_decorate2([
1005
+ CanAnyone(),
1383
1006
  Controller(),
1384
- UseGuards(DashboardAuthGuard),
1385
- _ts_param3(1, Inject3(DASHBOARD_APPROVAL_ACTOR_REF)),
1386
- _ts_param3(2, Optional3()),
1387
- _ts_param3(2, Inject3(AGENT_ACTOR_RESOLVER)),
1388
- _ts_metadata3("design:type", Function),
1389
- _ts_metadata3("design:paramtypes", [
1007
+ _ts_param2(1, Inject2(DASHBOARD_APPROVAL_ACTOR_REF)),
1008
+ _ts_param2(2, Optional2()),
1009
+ _ts_param2(2, Inject2(AGENT_ACTOR_RESOLVER)),
1010
+ _ts_metadata2("design:type", Function),
1011
+ _ts_metadata2("design:paramtypes", [
1390
1012
  typeof DashboardService === "undefined" ? Object : DashboardService,
1391
1013
  Object,
1392
1014
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1393
1015
  ])
1394
1016
  ], AgentApiController);
1395
1017
 
1396
- // src/server/agent-dashboard-auth.controller.ts
1397
- import { Body as Body2, Controller as Controller2, Get as Get2, Header, HttpCode as HttpCode2, Inject as Inject4, Logger, NotFoundException as NotFoundException2, Optional as Optional4, Post as Post2, Query as Query2, Req as Req2, Res, UnauthorizedException as UnauthorizedException2 } from "@nestjs/common";
1398
-
1399
- // src/server/auth/login-page.ts
1400
- function escapeHtml(value) {
1401
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1402
- }
1403
- __name(escapeHtml, "escapeHtml");
1404
- function pageShell(content, title) {
1405
- return `<!doctype html>
1406
- <html lang="en">
1407
- <head>
1408
- <meta charset="utf-8" />
1409
- <meta name="viewport" content="width=device-width, initial-scale=1" />
1410
- <meta name="robots" content="noindex, nofollow" />
1411
- <title>${title}</title>
1412
- <style>
1413
- :root { color-scheme: dark; }
1414
- * { box-sizing: border-box; }
1415
- body {
1416
- margin: 0;
1417
- min-height: 100vh;
1418
- display: flex;
1419
- align-items: center;
1420
- justify-content: center;
1421
- background: #09090b;
1422
- color: #e4e4e7;
1423
- font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1424
- padding: 16px;
1425
- }
1426
- .card {
1427
- width: 100%;
1428
- max-width: 384px;
1429
- border: 1px solid #27272a;
1430
- background: #18181b;
1431
- border-radius: 8px;
1432
- padding: 32px;
1433
- box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
1434
- }
1435
- .brand {
1436
- margin: 0 0 24px;
1437
- text-align: center;
1438
- font-size: 18px;
1439
- font-weight: 600;
1440
- color: #34d399;
1441
- }
1442
- h1 {
1443
- margin: 0 0 12px;
1444
- font-size: 16px;
1445
- font-weight: 600;
1446
- color: #f4f4f5;
1447
- }
1448
- p { margin: 0 0 16px; color: #a1a1aa; }
1449
- form { display: flex; flex-direction: column; gap: 16px; }
1450
- label { display: flex; flex-direction: column; gap: 6px; }
1451
- .field-label {
1452
- font-size: 11px;
1453
- text-transform: uppercase;
1454
- letter-spacing: 0.05em;
1455
- color: #71717a;
1456
- }
1457
- input {
1458
- border-radius: 4px;
1459
- border: 1px solid #3f3f46;
1460
- background: #09090b;
1461
- color: #f4f4f5;
1462
- padding: 8px 12px;
1463
- font: inherit;
1464
- outline: none;
1465
- }
1466
- input:focus { border-color: rgb(52 211 153 / 0.6); }
1467
- .error { margin: 0; font-size: 12px; color: #fb7185; }
1468
- button {
1469
- margin-top: 8px;
1470
- border-radius: 4px;
1471
- border: 1px solid rgb(52 211 153 / 0.4);
1472
- background: rgb(52 211 153 / 0.1);
1473
- color: #6ee7b7;
1474
- padding: 8px 12px;
1475
- font: inherit;
1476
- font-size: 12px;
1477
- font-weight: 500;
1478
- text-transform: uppercase;
1479
- letter-spacing: 0.05em;
1480
- cursor: pointer;
1481
- }
1482
- button:hover { background: rgb(52 211 153 / 0.2); }
1483
- </style>
1484
- </head>
1485
- <body>
1486
- <div class="card">
1487
- ${content}
1488
- </div>
1489
- </body>
1490
- </html>`;
1491
- }
1492
- __name(pageShell, "pageShell");
1493
- function renderLoginPage(options) {
1494
- const action = escapeHtml(options.actionUrl);
1495
- const returnTo = escapeHtml(options.returnTo);
1496
- const errorBanner = options.error === true ? '<p role="alert" class="error">Invalid username or password.</p>' : "";
1497
- return pageShell(`<p class="brand">AI Gateway</p>
1498
- <form method="post" action="${action}">
1499
- <input type="hidden" name="returnTo" value="${returnTo}" />
1500
- <label>
1501
- <span class="field-label">Username</span>
1502
- <input type="text" name="username" autocomplete="username" autofocus />
1503
- </label>
1504
- <label>
1505
- <span class="field-label">Password</span>
1506
- <input type="password" name="password" autocomplete="current-password" />
1507
- </label>
1508
- ${errorBanner}
1509
- <button type="submit">Sign in</button>
1510
- </form>`, "Sign in \u2014 AI Gateway");
1511
- }
1512
- __name(renderLoginPage, "renderLoginPage");
1513
- function renderSessionRequiredPage() {
1514
- return pageShell(`<p class="brand">AI Gateway</p>
1515
- <h1>Open this console from your application</h1>
1516
- <p>Your session is minted by the host app. Use its console launcher to sign in, then reload.</p>`, "Sign in \u2014 AI Gateway");
1517
- }
1518
- __name(renderSessionRequiredPage, "renderSessionRequiredPage");
1519
-
1520
- // src/server/auth/sanitize-return-to.ts
1521
- function sanitizeReturnTo(basePath, returnTo) {
1522
- if (typeof returnTo !== "string" || returnTo === "") return basePath;
1523
- if (!returnTo.startsWith("/") || returnTo.startsWith("//")) return basePath;
1524
- if (returnTo !== basePath && !returnTo.startsWith(`${basePath}/`) && !returnTo.startsWith(`${basePath}?`)) {
1525
- return basePath;
1526
- }
1527
- return returnTo;
1528
- }
1529
- __name(sanitizeReturnTo, "sanitizeReturnTo");
1530
-
1531
- // src/server/agent-dashboard-auth.controller.ts
1532
- function _ts_decorate4(decorators, target, key, desc) {
1533
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1534
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1535
- r = Reflect.decorate(decorators, target, key, desc);
1536
- } else {
1537
- for (var i = decorators.length - 1; i >= 0; i--) {
1538
- if (d = decorators[i]) {
1539
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1540
- }
1541
- }
1542
- }
1543
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1544
- }
1545
- __name(_ts_decorate4, "_ts_decorate");
1546
- function _ts_metadata4(metadataKey, metadataValue) {
1547
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1548
- return Reflect.metadata(metadataKey, metadataValue);
1549
- }
1550
- }
1551
- __name(_ts_metadata4, "_ts_metadata");
1552
- function _ts_param4(paramIndex, decorator) {
1553
- return function(target, key) {
1554
- decorator(target, key, paramIndex);
1555
- };
1556
- }
1557
- __name(_ts_param4, "_ts_param");
1558
- function isNonEmptyString(value) {
1559
- return typeof value === "string" && value.trim() !== "";
1560
- }
1561
- __name(isNonEmptyString, "isNonEmptyString");
1562
- function isString(value) {
1563
- return typeof value === "string";
1564
- }
1565
- __name(isString, "isString");
1566
- var AgentDashboardAuthController = class _AgentDashboardAuthController {
1567
- static {
1568
- __name(this, "AgentDashboardAuthController");
1569
- }
1570
- auth;
1571
- basePath;
1572
- logger = new Logger(_AgentDashboardAuthController.name);
1573
- /** Warn once PER HOOK KIND (not per request) so a broken hook can't be used to flood the logs. */
1574
- warnedHooks = /* @__PURE__ */ new Set();
1575
- constructor(auth, basePath) {
1576
- this.auth = auth;
1577
- this.basePath = basePath;
1578
- }
1579
- loginPage(req, res, returnToQuery, error) {
1580
- const auth = this.requireAuth();
1581
- if (!auth.modes.includes("login")) throw new NotFoundException2();
1582
- const returnTo = sanitizeReturnTo(this.basePath, returnToQuery);
1583
- if (this.currentSession(req)) {
1584
- res.status(302);
1585
- res.setHeader("Location", returnTo);
1586
- return "";
1587
- }
1588
- return renderLoginPage({
1589
- actionUrl: `${this.basePath}/auth/login`,
1590
- returnTo,
1591
- error: error !== void 0
1592
- });
1593
- }
1594
- async login(body, req, res) {
1595
- const auth = this.requireAuth();
1596
- if (!auth.modes.includes("login")) throw new NotFoundException2();
1597
- const returnTo = sanitizeReturnTo(this.basePath, body?.returnTo);
1598
- const username = body?.username;
1599
- const password = body?.password;
1600
- if (!isNonEmptyString(username) || password !== void 0 && !isString(password)) {
1601
- this.redirectToLoginError(res, returnTo);
1602
- return "";
1603
- }
1604
- const user = await this.runHook("login", () => auth.login?.(username.trim(), isString(password) ? password : "") ?? null);
1605
- if (!user) {
1606
- this.redirectToLoginError(res, returnTo);
1607
- return "";
1608
- }
1609
- issueSessionCookie(user, {
1610
- auth,
1611
- request: req,
1612
- response: res
1613
- });
1614
- res.status(302);
1615
- res.setHeader("Location", returnTo);
1616
- return "";
1617
- }
1618
- logout(req, res) {
1619
- clearSessionCookie({
1620
- request: req,
1621
- response: res
1622
- });
1623
- res.status(302);
1624
- res.setHeader("Location", this.auth && !this.auth.modes.includes("login") ? `${this.basePath}/auth/session-required` : `${this.basePath}/auth/login`);
1625
- return "";
1626
- }
1627
- // Mode A: the host frontend (carrying its own auth) POSTs here; the host hook validates the raw
1628
- // request and returns the session user, or `null` to deny. No credential reaches this library.
1629
- async session(request, response) {
1630
- const auth = this.requireAuth();
1631
- if (!auth.modes.includes("session")) throw new NotFoundException2();
1632
- const user = await this.runHook("session", () => auth.session?.(request) ?? null);
1633
- if (!user) throw new UnauthorizedException2();
1634
- issueSessionCookie(user, {
1635
- auth,
1636
- request,
1637
- response
1638
- });
1639
- }
1640
- // Mode-A-only landing: the host mints the session, so there is nothing to submit here. Serves
1641
- // as the redirect target `DashboardAuthPageGuard` bounces to instead of `/auth/login`, which
1642
- // 404s under Mode A (see `loginPage` above).
1643
- //
1644
- // Non-passthrough `@Res()` (unlike its sibling routes) because `dashboardAuth.unauthenticatedPage`
1645
- // hands the response to the HOST, which writes and ends it itself — there is no return value for
1646
- // Nest to send, and letting Nest also send one would double-write. The `Content-Type` /
1647
- // `Cache-Control` this route used to carry as decorators move into `sendHtml` for the built-in
1648
- // path; the host owns its own headers on the hook path.
1649
- async sessionRequiredPage(req, res) {
1650
- const auth = this.requireAuth();
1651
- if (auth.modes.includes("login")) throw new NotFoundException2();
1652
- const hook = auth.unauthenticatedPage;
1653
- if (hook) {
1654
- try {
1655
- await hook({
1656
- request: req,
1657
- response: res,
1658
- basePath: this.basePath
1659
- });
1660
- if (responseAlreadyWritten(res)) return;
1661
- this.warnHookOnce("unauthenticatedPage", "dashboardAuth.unauthenticatedPage returned without writing a response; falling back to the built-in page. The hook must write AND end the response it is given.");
1662
- } catch (error) {
1663
- this.warnHookOnce("unauthenticatedPage", `dashboardAuth.unauthenticatedPage threw; falling back to the built-in page. ${String(error)}`);
1664
- if (responseAlreadyWritten(res)) return;
1665
- }
1666
- }
1667
- sendHtml(res, 200, renderSessionRequiredPage());
1668
- }
1669
- /** Uniform failure: same redirect (generic error flag) whether the user is unknown or the password is wrong. */
1670
- redirectToLoginError(res, returnTo) {
1671
- res.status(303);
1672
- res.setHeader("Location", `${this.basePath}/auth/login?error=1&returnTo=${encodeURIComponent(returnTo)}`);
1673
- }
1674
- currentSession(req) {
1675
- const auth = this.auth;
1676
- if (!auth) return false;
1677
- const cookieValue = parseCookieHeader(readCookieHeader(req))[SESSION_COOKIE_NAME];
1678
- if (cookieValue === void 0) return false;
1679
- return verifySessionCookie(cookieValue, {
1680
- secret: auth.secret
1681
- }) !== null;
1682
- }
1683
- /**
1684
- * Run a host hook (`login` or `session`) defensively: a throw (sync or async) is treated as a
1685
- * denial (`null`) and warn-logged ONCE PER KIND, so a buggy/unreachable hook never 500s the
1686
- * endpoint into a stack-trace leak nor floods the logs on repeated bad attempts.
1687
- */
1688
- async runHook(kind, run) {
1689
- try {
1690
- return await run() ?? null;
1691
- } catch (error) {
1692
- this.warnHookOnce(kind, `AgentDashboardModule dashboardAuth ${kind} hook threw; treating as denial. ${error instanceof Error ? error.message : String(error)}`);
1693
- return null;
1694
- }
1695
- }
1696
- /**
1697
- * Warn once per hook kind for the life of the process, not once per request: a broken hook fires
1698
- * on every denied navigation and would otherwise flood the logs.
1699
- */
1700
- warnHookOnce(kind, message) {
1701
- if (this.warnedHooks.has(kind)) return;
1702
- this.warnedHooks.add(kind);
1703
- this.logger.warn(message);
1704
- }
1705
- requireAuth() {
1706
- if (!this.auth) throw new NotFoundException2();
1707
- return this.auth;
1708
- }
1709
- };
1710
- _ts_decorate4([
1711
- Get2("login"),
1712
- Header("Content-Type", "text/html; charset=utf-8"),
1713
- Header("Cache-Control", "no-store"),
1714
- _ts_param4(0, Req2()),
1715
- _ts_param4(1, Res({
1716
- passthrough: true
1717
- })),
1718
- _ts_param4(2, Query2("returnTo")),
1719
- _ts_param4(3, Query2("error")),
1720
- _ts_metadata4("design:type", Function),
1721
- _ts_metadata4("design:paramtypes", [
1722
- typeof AuthPageRequest === "undefined" ? Object : AuthPageRequest,
1723
- typeof AuthPageResponse === "undefined" ? Object : AuthPageResponse,
1724
- String,
1725
- String
1726
- ]),
1727
- _ts_metadata4("design:returntype", String)
1728
- ], AgentDashboardAuthController.prototype, "loginPage", null);
1729
- _ts_decorate4([
1730
- Post2("login"),
1731
- _ts_param4(0, Body2()),
1732
- _ts_param4(1, Req2()),
1733
- _ts_param4(2, Res({
1734
- passthrough: true
1735
- })),
1736
- _ts_metadata4("design:type", Function),
1737
- _ts_metadata4("design:paramtypes", [
1738
- typeof LoginFormBody === "undefined" ? Object : LoginFormBody,
1739
- Object,
1740
- typeof AuthPageResponse === "undefined" ? Object : AuthPageResponse
1741
- ]),
1742
- _ts_metadata4("design:returntype", Promise)
1743
- ], AgentDashboardAuthController.prototype, "login", null);
1744
- _ts_decorate4([
1745
- Post2("logout"),
1746
- _ts_param4(0, Req2()),
1747
- _ts_param4(1, Res({
1748
- passthrough: true
1749
- })),
1750
- _ts_metadata4("design:type", Function),
1751
- _ts_metadata4("design:paramtypes", [
1752
- Object,
1753
- typeof AuthPageResponse === "undefined" ? Object : AuthPageResponse
1754
- ]),
1755
- _ts_metadata4("design:returntype", String)
1756
- ], AgentDashboardAuthController.prototype, "logout", null);
1757
- _ts_decorate4([
1758
- Post2("session"),
1759
- HttpCode2(204),
1760
- _ts_param4(0, Req2()),
1761
- _ts_param4(1, Res({
1762
- passthrough: true
1763
- })),
1764
- _ts_metadata4("design:type", Function),
1765
- _ts_metadata4("design:paramtypes", [
1766
- Object,
1767
- Object
1768
- ]),
1769
- _ts_metadata4("design:returntype", Promise)
1770
- ], AgentDashboardAuthController.prototype, "session", null);
1771
- _ts_decorate4([
1772
- Get2("session-required"),
1773
- _ts_param4(0, Req2()),
1774
- _ts_param4(1, Res()),
1775
- _ts_metadata4("design:type", Function),
1776
- _ts_metadata4("design:paramtypes", [
1777
- typeof AuthPageRequest === "undefined" ? Object : AuthPageRequest,
1778
- Object
1779
- ]),
1780
- _ts_metadata4("design:returntype", Promise)
1781
- ], AgentDashboardAuthController.prototype, "sessionRequiredPage", null);
1782
- AgentDashboardAuthController = _ts_decorate4([
1783
- Controller2("auth"),
1784
- _ts_param4(0, Optional4()),
1785
- _ts_param4(0, Inject4(DASHBOARD_AUTH)),
1786
- _ts_param4(1, Inject4(DASHBOARD_BASE_PATH)),
1787
- _ts_metadata4("design:type", Function),
1788
- _ts_metadata4("design:paramtypes", [
1789
- Object,
1790
- String
1791
- ])
1792
- ], AgentDashboardAuthController);
1793
-
1794
1018
  // src/server/normalize-path.ts
1795
1019
  function normalizeDashboardPath(path) {
1796
1020
  return `/${path.replace(/^\/+|\/+$/g, "")}`;
@@ -1817,6 +1041,7 @@ function agentDashboardMountPaths(options) {
1817
1041
  __name(agentDashboardMountPaths, "agentDashboardMountPaths");
1818
1042
 
1819
1043
  // src/server/agent-dashboard.module.ts
1044
+ import { withControllerDecorators } from "@dudousxd/nestjs-agent-core";
1820
1045
  import "reflect-metadata";
1821
1046
  import { Module } from "@nestjs/common";
1822
1047
  import { RouterModule } from "@nestjs/core";
@@ -1825,145 +1050,9 @@ import { RouterModule } from "@nestjs/core";
1825
1050
  import { existsSync, readFileSync } from "fs";
1826
1051
  import { basename, extname, join, resolve, sep } from "path";
1827
1052
  import { fileURLToPath } from "url";
1828
- import { Controller as Controller3, Get as Get3, Header as Header2, Inject as Inject6, NotFoundException as NotFoundException3, Param as Param2, Req as Req3, Res as Res2, StreamableFile, UseFilters, UseGuards as UseGuards2 } from "@nestjs/common";
1829
-
1830
- // src/server/auth/dashboard-auth-page.guard.ts
1831
- import { Inject as Inject5, Injectable as Injectable4, Optional as Optional5 } from "@nestjs/common";
1832
-
1833
- // src/server/auth/dashboard-auth-redirect.ts
1834
- import { Catch, Injectable as Injectable3 } from "@nestjs/common";
1835
- function _ts_decorate5(decorators, target, key, desc) {
1836
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1837
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1838
- r = Reflect.decorate(decorators, target, key, desc);
1839
- } else {
1840
- for (var i = decorators.length - 1; i >= 0; i--) {
1841
- if (d = decorators[i]) {
1842
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1843
- }
1844
- }
1845
- }
1846
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1847
- }
1848
- __name(_ts_decorate5, "_ts_decorate");
1849
- var DashboardAuthRedirect = class extends Error {
1850
- static {
1851
- __name(this, "DashboardAuthRedirect");
1852
- }
1853
- redirectTo;
1854
- constructor(redirectTo) {
1855
- super(`Redirect to ${redirectTo}`), this.redirectTo = redirectTo;
1856
- this.name = "DashboardAuthRedirect";
1857
- }
1858
- };
1859
- var DashboardAuthRedirectFilter = class {
1860
- static {
1861
- __name(this, "DashboardAuthRedirectFilter");
1862
- }
1863
- catch(exception, host) {
1864
- const response = host.switchToHttp().getResponse();
1865
- sendRedirect(response, 302, exception.redirectTo);
1866
- }
1867
- };
1868
- DashboardAuthRedirectFilter = _ts_decorate5([
1869
- Injectable3(),
1870
- Catch(DashboardAuthRedirect)
1871
- ], DashboardAuthRedirectFilter);
1872
-
1873
- // src/server/auth/dashboard-auth-page.guard.ts
1874
- function _ts_decorate6(decorators, target, key, desc) {
1875
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1876
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1877
- r = Reflect.decorate(decorators, target, key, desc);
1878
- } else {
1879
- for (var i = decorators.length - 1; i >= 0; i--) {
1880
- if (d = decorators[i]) {
1881
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1882
- }
1883
- }
1884
- }
1885
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1886
- }
1887
- __name(_ts_decorate6, "_ts_decorate");
1888
- function _ts_metadata5(metadataKey, metadataValue) {
1889
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1890
- return Reflect.metadata(metadataKey, metadataValue);
1891
- }
1892
- }
1893
- __name(_ts_metadata5, "_ts_metadata");
1894
- function _ts_param5(paramIndex, decorator) {
1895
- return function(target, key) {
1896
- decorator(target, key, paramIndex);
1897
- };
1898
- }
1899
- __name(_ts_param5, "_ts_param");
1900
- var DashboardAuthPageGuard = class {
1901
- static {
1902
- __name(this, "DashboardAuthPageGuard");
1903
- }
1904
- auth;
1905
- basePath;
1906
- constructor(auth, basePath) {
1907
- this.auth = auth;
1908
- this.basePath = basePath;
1909
- }
1910
- async canActivate(context) {
1911
- if (!this.auth) return true;
1912
- const auth = this.auth;
1913
- const http = context.switchToHttp();
1914
- const request = http.getRequest();
1915
- const session = this.verifyRequestSession(request);
1916
- if (!session) this.deny(auth, request);
1917
- attachSession(request, session);
1918
- if (!await maybeRenewSession(auth, session, request, http.getResponse())) {
1919
- this.deny(auth, request);
1920
- }
1921
- return true;
1922
- }
1923
- /**
1924
- * No valid session: bounce the browser navigation onward. Under Mode B (`login` configured)
1925
- * that's the built-in login screen, carrying `returnTo` back to the page that was requested.
1926
- * Under Mode-A-only there is no login screen to redirect to — the host mints the session
1927
- * itself — so this instead serves the instruction page rather than redirecting into a 404.
1928
- * Pulled out of `canActivate` so both the "no session at all" and the "revalidate revoked a
1929
- * renewable session" paths reuse the exact same mode-aware deny logic.
1930
- *
1931
- * Takes `auth` explicitly rather than reading `this.auth`: `canActivate`'s `!this.auth` early
1932
- * return narrows the field within that method only — TS doesn't carry it across a method call —
1933
- * so the caller passes the already-narrowed value instead of this method re-deriving (or
1934
- * asserting away) the nullability.
1935
- */
1936
- deny(auth, request) {
1937
- if (!auth.modes.includes("login")) {
1938
- throw new DashboardAuthRedirect(`${this.basePath}/auth/session-required`);
1939
- }
1940
- const returnTo = readOriginalUrl(request);
1941
- throw new DashboardAuthRedirect(`${this.basePath}/auth/login?returnTo=${encodeURIComponent(returnTo)}`);
1942
- }
1943
- verifyRequestSession(request) {
1944
- const auth = this.auth;
1945
- if (!auth) return null;
1946
- const cookieValue = parseCookieHeader(readCookieHeader(request))[SESSION_COOKIE_NAME];
1947
- if (cookieValue === void 0) return null;
1948
- return verifySessionCookie(cookieValue, {
1949
- secret: auth.secret
1950
- });
1951
- }
1952
- };
1953
- DashboardAuthPageGuard = _ts_decorate6([
1954
- Injectable4(),
1955
- _ts_param5(0, Optional5()),
1956
- _ts_param5(0, Inject5(DASHBOARD_AUTH)),
1957
- _ts_param5(1, Inject5(DASHBOARD_BASE_PATH)),
1958
- _ts_metadata5("design:type", Function),
1959
- _ts_metadata5("design:paramtypes", [
1960
- Object,
1961
- String
1962
- ])
1963
- ], DashboardAuthPageGuard);
1964
-
1965
- // src/server/agent-ui.controller.ts
1966
- function _ts_decorate7(decorators, target, key, desc) {
1053
+ import { CanAnyone as CanAnyone2 } from "@dudousxd/nestjs-agent-core";
1054
+ import { Controller as Controller2, Get as Get2, Header, Inject as Inject3, NotFoundException as NotFoundException2, Param as Param2, Req as Req2, Res, StreamableFile } from "@nestjs/common";
1055
+ function _ts_decorate3(decorators, target, key, desc) {
1967
1056
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1968
1057
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1969
1058
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1976,19 +1065,19 @@ function _ts_decorate7(decorators, target, key, desc) {
1976
1065
  }
1977
1066
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1978
1067
  }
1979
- __name(_ts_decorate7, "_ts_decorate");
1980
- function _ts_metadata6(metadataKey, metadataValue) {
1068
+ __name(_ts_decorate3, "_ts_decorate");
1069
+ function _ts_metadata3(metadataKey, metadataValue) {
1981
1070
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1982
1071
  return Reflect.metadata(metadataKey, metadataValue);
1983
1072
  }
1984
1073
  }
1985
- __name(_ts_metadata6, "_ts_metadata");
1986
- function _ts_param6(paramIndex, decorator) {
1074
+ __name(_ts_metadata3, "_ts_metadata");
1075
+ function _ts_param3(paramIndex, decorator) {
1987
1076
  return function(target, key) {
1988
1077
  decorator(target, key, paramIndex);
1989
1078
  };
1990
1079
  }
1991
- __name(_ts_param6, "_ts_param");
1080
+ __name(_ts_param3, "_ts_param");
1992
1081
  var BUILD_BASE = "/ai-gateway";
1993
1082
  function spaDir() {
1994
1083
  return fileURLToPath(new URL("../spa", import.meta.url));
@@ -2024,7 +1113,7 @@ var AgentUiController = class {
2024
1113
  }
2025
1114
  const indexPath = join(this.dir, "index.html");
2026
1115
  if (!existsSync(indexPath)) {
2027
- throw new NotFoundException3("Dashboard is not built. Run the package build.");
1116
+ throw new NotFoundException2("Dashboard is not built. Run the package build.");
2028
1117
  }
2029
1118
  const html = readFileSync(indexPath, "utf8").replaceAll(`="${BUILD_BASE}/`, `="${this.basePath}/`);
2030
1119
  const inject = `<script>window.__AGENT_BASE__='${this.basePath}';window.__AGENT_API__='${this.apiBasePath}';</script>`;
@@ -2032,11 +1121,11 @@ var AgentUiController = class {
2032
1121
  }
2033
1122
  asset(file) {
2034
1123
  const safe = basename(file);
2035
- if (safe !== file) throw new NotFoundException3();
1124
+ if (safe !== file) throw new NotFoundException2();
2036
1125
  const root = resolve(this.dir, "assets");
2037
1126
  const assetPath = resolve(root, safe);
2038
1127
  if (!assetPath.startsWith(root + sep) || !existsSync(assetPath)) {
2039
- throw new NotFoundException3();
1128
+ throw new NotFoundException2();
2040
1129
  }
2041
1130
  const type = CONTENT_TYPES[extname(safe)] ?? "application/octet-stream";
2042
1131
  return new StreamableFile(readFileSync(assetPath), {
@@ -2044,143 +1133,45 @@ var AgentUiController = class {
2044
1133
  });
2045
1134
  }
2046
1135
  };
2047
- _ts_decorate7([
2048
- Get3(),
2049
- Header2("Content-Type", "text/html; charset=utf-8"),
2050
- Header2("Cache-Control", "no-store, must-revalidate"),
2051
- _ts_param6(0, Req3()),
2052
- _ts_param6(1, Res2({
1136
+ _ts_decorate3([
1137
+ Get2(),
1138
+ Header("Content-Type", "text/html; charset=utf-8"),
1139
+ Header("Cache-Control", "no-store, must-revalidate"),
1140
+ _ts_param3(0, Req2()),
1141
+ _ts_param3(1, Res({
2053
1142
  passthrough: true
2054
1143
  })),
2055
- _ts_metadata6("design:type", Function),
2056
- _ts_metadata6("design:paramtypes", [
1144
+ _ts_metadata3("design:type", Function),
1145
+ _ts_metadata3("design:paramtypes", [
2057
1146
  typeof UiPageRequest === "undefined" ? Object : UiPageRequest,
2058
1147
  typeof UiPageResponse === "undefined" ? Object : UiPageResponse
2059
1148
  ]),
2060
- _ts_metadata6("design:returntype", String)
1149
+ _ts_metadata3("design:returntype", String)
2061
1150
  ], AgentUiController.prototype, "index", null);
2062
- _ts_decorate7([
2063
- Get3("assets/:file"),
2064
- Header2("Cache-Control", "public, max-age=31536000, immutable"),
2065
- _ts_param6(0, Param2("file")),
2066
- _ts_metadata6("design:type", Function),
2067
- _ts_metadata6("design:paramtypes", [
1151
+ _ts_decorate3([
1152
+ Get2("assets/:file"),
1153
+ Header("Cache-Control", "public, max-age=31536000, immutable"),
1154
+ _ts_param3(0, Param2("file")),
1155
+ _ts_metadata3("design:type", Function),
1156
+ _ts_metadata3("design:paramtypes", [
2068
1157
  String
2069
1158
  ]),
2070
- _ts_metadata6("design:returntype", typeof StreamableFile === "undefined" ? Object : StreamableFile)
1159
+ _ts_metadata3("design:returntype", typeof StreamableFile === "undefined" ? Object : StreamableFile)
2071
1160
  ], AgentUiController.prototype, "asset", null);
2072
- AgentUiController = _ts_decorate7([
2073
- Controller3(),
2074
- UseGuards2(DashboardAuthPageGuard),
2075
- UseFilters(new DashboardAuthRedirectFilter()),
2076
- _ts_param6(0, Inject6(DASHBOARD_BASE_PATH)),
2077
- _ts_param6(1, Inject6(DASHBOARD_API_PATH)),
2078
- _ts_metadata6("design:type", Function),
2079
- _ts_metadata6("design:paramtypes", [
1161
+ AgentUiController = _ts_decorate3([
1162
+ CanAnyone2(),
1163
+ Controller2(),
1164
+ _ts_param3(0, Inject3(DASHBOARD_BASE_PATH)),
1165
+ _ts_param3(1, Inject3(DASHBOARD_API_PATH)),
1166
+ _ts_metadata3("design:type", Function),
1167
+ _ts_metadata3("design:paramtypes", [
2080
1168
  String,
2081
1169
  String
2082
1170
  ])
2083
1171
  ], AgentUiController);
2084
1172
 
2085
- // src/server/auth/dashboard-auth-config.ts
2086
- var DEFAULT_TTL = "8h";
2087
- function unitToMs(unit) {
2088
- switch (unit) {
2089
- case "ms":
2090
- return 1;
2091
- case "s":
2092
- return 1e3;
2093
- case "m":
2094
- return 6e4;
2095
- case "h":
2096
- return 36e5;
2097
- case "d":
2098
- return 864e5;
2099
- default:
2100
- return void 0;
2101
- }
2102
- }
2103
- __name(unitToMs, "unitToMs");
2104
- function durationToMs(duration) {
2105
- const match = /^(\d+)(ms|s|m|h|d)$/.exec(duration.trim());
2106
- const amount = match?.[1];
2107
- const unit = match?.[2] !== void 0 ? unitToMs(match[2]) : void 0;
2108
- if (amount === void 0 || unit === void 0) {
2109
- throw new Error(`AgentDashboardModule dashboardAuth: invalid \`ttl\` duration: ${duration}`);
2110
- }
2111
- return Number(amount) * unit;
2112
- }
2113
- __name(durationToMs, "durationToMs");
2114
- function resolveDashboardAuth(options) {
2115
- if (options === void 0) return null;
2116
- if (typeof options.secret !== "string" || options.secret === "") {
2117
- throw new Error("AgentDashboardModule dashboardAuth: `secret` is required and must be a non-empty string (HMAC-SHA256 signing key, 32+ bytes recommended). Failing closed.");
2118
- }
2119
- const modes = [];
2120
- if (options.session !== void 0) {
2121
- if (typeof options.session !== "function") {
2122
- throw new Error("AgentDashboardModule dashboardAuth: `session` must be a function.");
2123
- }
2124
- modes.push("session");
2125
- }
2126
- if (options.login !== void 0) {
2127
- if (typeof options.login !== "function") {
2128
- throw new Error("AgentDashboardModule dashboardAuth: `login` must be a function.");
2129
- }
2130
- modes.push("login");
2131
- }
2132
- if (options.revalidate !== void 0 && typeof options.revalidate !== "function") {
2133
- throw new Error("AgentDashboardModule dashboardAuth: `revalidate` must be a function.");
2134
- }
2135
- if (options.unauthenticatedPage !== void 0 && typeof options.unauthenticatedPage !== "function") {
2136
- throw new Error("AgentDashboardModule dashboardAuth: `unauthenticatedPage` must be a function.");
2137
- }
2138
- if (modes.length === 0) {
2139
- throw new Error("AgentDashboardModule dashboardAuth: at least one of `session` (the host mints the session from its own auth) or `login` (the built-in login screen) is required \u2014 otherwise the cookie can never be minted. Failing closed.");
2140
- }
2141
- return {
2142
- secret: options.secret,
2143
- ttlMs: durationToMs(options.ttl ?? DEFAULT_TTL),
2144
- modes,
2145
- ...options.session !== void 0 ? {
2146
- session: options.session
2147
- } : {},
2148
- ...options.login !== void 0 ? {
2149
- login: options.login
2150
- } : {},
2151
- ...options.revalidate !== void 0 ? {
2152
- revalidate: options.revalidate
2153
- } : {},
2154
- ...options.unauthenticatedPage !== void 0 ? {
2155
- unauthenticatedPage: options.unauthenticatedPage
2156
- } : {}
2157
- };
2158
- }
2159
- __name(resolveDashboardAuth, "resolveDashboardAuth");
2160
-
2161
- // src/server/guards.ts
2162
- import "reflect-metadata";
2163
- var GUARDS_METADATA = "__guards__";
2164
- function isGuardClass(guard) {
2165
- return typeof guard === "function";
2166
- }
2167
- __name(isGuardClass, "isGuardClass");
2168
- function baseGuards(controller) {
2169
- return Reflect.getOwnMetadata(GUARDS_METADATA, controller) ?? [];
2170
- }
2171
- __name(baseGuards, "baseGuards");
2172
- function stampGuards(guards, entries) {
2173
- for (const [controller, base] of entries) {
2174
- Reflect.defineMetadata(GUARDS_METADATA, [
2175
- ...base,
2176
- ...guards ?? []
2177
- ], controller);
2178
- }
2179
- }
2180
- __name(stampGuards, "stampGuards");
2181
-
2182
1173
  // src/server/agent-dashboard.module.ts
2183
- function _ts_decorate8(decorators, target, key, desc) {
1174
+ function _ts_decorate4(decorators, target, key, desc) {
2184
1175
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2185
1176
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2186
1177
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2193,37 +1184,33 @@ function _ts_decorate8(decorators, target, key, desc) {
2193
1184
  }
2194
1185
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2195
1186
  }
2196
- __name(_ts_decorate8, "_ts_decorate");
2197
- var API_BASE_GUARDS = baseGuards(AgentApiController);
2198
- var UI_BASE_GUARDS = baseGuards(AgentUiController);
1187
+ __name(_ts_decorate4, "_ts_decorate");
2199
1188
  function normalize(path) {
2200
1189
  return normalizeDashboardPath(path);
2201
1190
  }
2202
1191
  __name(normalize, "normalize");
1192
+ function assertProtected(options) {
1193
+ if (process.env.NODE_ENV !== "production") return;
1194
+ if (options.routes === false) return;
1195
+ if ((options.decorators ?? []).length > 0) return;
1196
+ throw new Error("AgentDashboardModule: the AI-gateway console would be served open in production. Say who reaches it, with `decorators: [UseGuards(AuthenticationGuard), Can(ConsolePolicy, 'view')]`, or mount its routes yourself with `routes: false` and extend `AgentApiController` / `AgentUiController` under your own guards.");
1197
+ }
1198
+ __name(assertProtected, "assertProtected");
2203
1199
  var AgentApiModule = class _AgentApiModule {
2204
1200
  static {
2205
1201
  __name(this, "AgentApiModule");
2206
1202
  }
2207
1203
  static register(options) {
2208
- stampGuards(options.guards, [
2209
- [
2210
- AgentApiController,
2211
- API_BASE_GUARDS
2212
- ]
2213
- ]);
2214
1204
  return {
2215
1205
  module: _AgentApiModule,
2216
1206
  imports: [
2217
1207
  ...options.imports ?? []
2218
1208
  ],
2219
- controllers: [
1209
+ controllers: options.routes === false ? [] : withControllerDecorators([
2220
1210
  AgentApiController
2221
- ],
1211
+ ], options.decorators),
2222
1212
  providers: [
2223
1213
  DashboardService,
2224
- DashboardAuthGuard,
2225
- options.dashboardAuth,
2226
- ...(options.guards ?? []).filter(isGuardClass),
2227
1214
  // `useValue` even when `options.approvalActorRef` is `undefined` — AgentApiController
2228
1215
  // injects this WITHOUT `@Optional()`.
2229
1216
  {
@@ -2231,17 +1218,15 @@ var AgentApiModule = class _AgentApiModule {
2231
1218
  useValue: options.approvalActorRef
2232
1219
  }
2233
1220
  ],
2234
- // DASHBOARD_AUTH re-exported so AgentUiController/AgentDashboardAuthController (hosted
2235
- // directly by AgentDashboardModule, which imports this module) resolve the SAME instance
2236
- // instead of re-running a host's async factory a second time.
1221
+ // What a self-mounted `AgentApiController` subclass injects, too (`routes: false`).
2237
1222
  exports: [
2238
1223
  DashboardService,
2239
- DASHBOARD_AUTH
1224
+ DASHBOARD_APPROVAL_ACTOR_REF
2240
1225
  ]
2241
1226
  };
2242
1227
  }
2243
1228
  };
2244
- AgentApiModule = _ts_decorate8([
1229
+ AgentApiModule = _ts_decorate4([
2245
1230
  Module({})
2246
1231
  ], AgentApiModule);
2247
1232
  var AgentDashboardModule = class _AgentDashboardModule {
@@ -2249,116 +1234,44 @@ var AgentDashboardModule = class _AgentDashboardModule {
2249
1234
  __name(this, "AgentDashboardModule");
2250
1235
  }
2251
1236
  static forRoot(options = {}) {
1237
+ assertProtected(options);
2252
1238
  const basePath = normalize(options.basePath ?? "/ai-gateway");
2253
1239
  const apiBasePath = normalize(options.apiBasePath ?? `${basePath}/api`);
2254
- stampGuards(options.guards, [
2255
- [
2256
- AgentUiController,
2257
- UI_BASE_GUARDS
2258
- ]
2259
- ]);
2260
- const dashboardAuthProvider = {
2261
- provide: DASHBOARD_AUTH,
2262
- useValue: resolveDashboardAuth(options.dashboardAuth)
2263
- };
2264
1240
  return {
2265
1241
  module: _AgentDashboardModule,
2266
1242
  imports: [
2267
1243
  ...options.imports ?? [],
2268
- // Guards + host imports must reach the API controller's HOST module — enhancers resolve
2269
- // from their controller's own module, never from a parent (see AgentApiModule.register).
2270
1244
  // Spread-only-when-set: exactOptionalPropertyTypes rejects an explicit `undefined`.
2271
1245
  AgentApiModule.register({
2272
1246
  ...options.imports ? {
2273
1247
  imports: options.imports
2274
1248
  } : {},
2275
- ...options.guards ? {
2276
- guards: options.guards
1249
+ ...options.decorators ? {
1250
+ decorators: options.decorators
2277
1251
  } : {},
2278
- ...options.approvalActorRef ? {
2279
- approvalActorRef: options.approvalActorRef
2280
- } : {},
2281
- dashboardAuth: dashboardAuthProvider
2282
- }),
2283
- RouterModule.register([
2284
- {
2285
- path: basePath,
2286
- module: _AgentDashboardModule
2287
- },
2288
- {
2289
- path: apiBasePath,
2290
- module: AgentApiModule
2291
- }
2292
- ])
2293
- ],
2294
- controllers: [
2295
- AgentUiController,
2296
- AgentDashboardAuthController
2297
- ],
2298
- providers: [
2299
- {
2300
- provide: DASHBOARD_BASE_PATH,
2301
- useValue: basePath
2302
- },
2303
- {
2304
- provide: DASHBOARD_API_PATH,
2305
- useValue: apiBasePath
2306
- },
2307
- DashboardAuthPageGuard,
2308
- // AgentUiController is hosted HERE, so its guards DI-instantiate from this module.
2309
- ...(options.guards ?? []).filter(isGuardClass)
2310
- ],
2311
- // Re-export the API module so its DashboardService reaches importers (e.g. the host's own controllers).
2312
- exports: [
2313
- AgentApiModule
2314
- ]
2315
- };
2316
- }
2317
- static forRootAsync(options) {
2318
- const basePath = normalize(options.basePath ?? "/ai-gateway");
2319
- const apiBasePath = normalize(options.apiBasePath ?? `${basePath}/api`);
2320
- stampGuards(options.guards, [
2321
- [
2322
- AgentUiController,
2323
- UI_BASE_GUARDS
2324
- ]
2325
- ]);
2326
- const dashboardAuthProvider = {
2327
- provide: DASHBOARD_AUTH,
2328
- inject: options.inject ?? [],
2329
- useFactory: /* @__PURE__ */ __name(async (...deps) => resolveDashboardAuth(await options.useDashboardAuth(...deps)), "useFactory")
2330
- };
2331
- return {
2332
- module: _AgentDashboardModule,
2333
- imports: [
2334
- ...options.imports ?? [],
2335
- AgentApiModule.register({
2336
- ...options.imports ? {
2337
- imports: options.imports
2338
- } : {},
2339
- ...options.guards ? {
2340
- guards: options.guards
1252
+ ...options.routes === false ? {
1253
+ routes: false
2341
1254
  } : {},
2342
1255
  ...options.approvalActorRef ? {
2343
1256
  approvalActorRef: options.approvalActorRef
2344
- } : {},
2345
- dashboardAuth: dashboardAuthProvider
1257
+ } : {}
2346
1258
  }),
2347
- RouterModule.register([
2348
- {
2349
- path: basePath,
2350
- module: _AgentDashboardModule
2351
- },
2352
- {
2353
- path: apiBasePath,
2354
- module: AgentApiModule
2355
- }
2356
- ])
2357
- ],
2358
- controllers: [
2359
- AgentUiController,
2360
- AgentDashboardAuthController
1259
+ ...options.routes === false ? [] : [
1260
+ RouterModule.register([
1261
+ {
1262
+ path: basePath,
1263
+ module: _AgentDashboardModule
1264
+ },
1265
+ {
1266
+ path: apiBasePath,
1267
+ module: AgentApiModule
1268
+ }
1269
+ ])
1270
+ ]
2361
1271
  ],
1272
+ controllers: options.routes === false ? [] : withControllerDecorators([
1273
+ AgentUiController
1274
+ ], options.decorators),
2362
1275
  providers: [
2363
1276
  {
2364
1277
  provide: DASHBOARD_BASE_PATH,
@@ -2367,17 +1280,19 @@ var AgentDashboardModule = class _AgentDashboardModule {
2367
1280
  {
2368
1281
  provide: DASHBOARD_API_PATH,
2369
1282
  useValue: apiBasePath
2370
- },
2371
- DashboardAuthPageGuard,
2372
- ...(options.guards ?? []).filter(isGuardClass)
1283
+ }
2373
1284
  ],
1285
+ // Re-export the API module so its DashboardService reaches importers (e.g. the host's own
1286
+ // controllers), and the paths a self-mounted `AgentUiController` subclass injects.
2374
1287
  exports: [
2375
- AgentApiModule
1288
+ AgentApiModule,
1289
+ DASHBOARD_BASE_PATH,
1290
+ DASHBOARD_API_PATH
2376
1291
  ]
2377
1292
  };
2378
1293
  }
2379
1294
  };
2380
- AgentDashboardModule = _ts_decorate8([
1295
+ AgentDashboardModule = _ts_decorate4([
2381
1296
  Module({})
2382
1297
  ], AgentDashboardModule);
2383
1298
  export {
@@ -2388,16 +1303,13 @@ export {
2388
1303
  AGENT_PRICING_STORE,
2389
1304
  AgentApiController,
2390
1305
  AgentApiModule,
2391
- AgentDashboardAuthController,
2392
1306
  AgentDashboardModule,
2393
1307
  AgentUiController,
2394
1308
  DASHBOARD_API_PATH,
2395
1309
  DASHBOARD_APPROVAL_ACTOR_REF,
2396
- DASHBOARD_AUTH,
2397
1310
  DASHBOARD_BASE_PATH,
2398
1311
  DashboardService,
2399
1312
  agentDashboardMountPaths,
2400
- parsePriceInput,
2401
- resolveDashboardAuth
1313
+ parsePriceInput
2402
1314
  };
2403
1315
  //# sourceMappingURL=index.js.map