@dudousxd/nestjs-agent-dashboard 0.20.0 → 0.21.0

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.
@@ -1,7 +1,7 @@
1
1
  import { ActorSpendRow, AgentGovernanceQueries, ActorDirectory, AgentPricingStore, AgentApprovalPort, GovernanceRange, ModelSpendRow, UsageTrendPoint, FeatureSpendRow, ThreadSpendRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, ToolCallActivityRow, GovernancePageQuery, ToolCallWhere, GovernancePage, RunWhere, PendingApprovalRow, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, ThreadActivityRow, ToolStatRow, GenuiStats, ThreadWhere, CurrentModelPrice, ActorResolver, ModelPriceInput } from '@dudousxd/nestjs-agent-core';
2
2
  export { ActorDirectory } from '@dudousxd/nestjs-agent-core';
3
3
  import { Observable } from 'rxjs';
4
- import { ExecutionContext, Type, Logger, DynamicModule, StreamableFile, HttpException, ExceptionFilter, ArgumentsHost, CanActivate, OnModuleInit } from '@nestjs/common';
4
+ import { ExecutionContext, Type, Logger, DynamicModule, StreamableFile, OnModuleInit, HttpException, ExceptionFilter, ArgumentsHost, CanActivate, OnModuleDestroy } from '@nestjs/common';
5
5
  import { ModuleRef, HttpAdapterHost } from '@nestjs/core';
6
6
 
7
7
  /** An actor-scoped row decorated with its resolved display label — `null` when unbound or unresolved. */
@@ -295,9 +295,14 @@ interface AgentDashboardMountPathsOptions {
295
295
  */
296
296
  declare function agentDashboardMountPaths(options?: AgentDashboardMountPathsOptions): string[];
297
297
 
298
- /** What an `authorize` check answers. */
298
+ /**
299
+ * What an `authorize` check answers. An allow may name who it let in (`caller`, for example
300
+ * `'user:42'`): the dev MCP endpoint logs it as the caller of a developer tool. Never put a secret
301
+ * in it.
302
+ */
299
303
  type ConsoleAuthorizeResult = boolean | {
300
304
  allowed: true;
305
+ caller?: string;
301
306
  } | {
302
307
  allowed: false;
303
308
  reason?: 'unauthenticated' | 'forbidden';
@@ -321,6 +326,7 @@ type ConsoleAuthorize = ((context: ExecutionContext) => ConsoleAuthorizeResult |
321
326
  /** A normalized `authorize` answer. */
322
327
  type ConsoleDecision = {
323
328
  allowed: true;
329
+ caller?: string;
324
330
  } | {
325
331
  allowed: false;
326
332
  reason: 'unauthenticated' | 'forbidden';
@@ -356,10 +362,22 @@ declare function resolveConsoleAuthorize(authorize: ConsoleAuthorize | undefined
356
362
  /**
357
363
  * `authorize` by a bearer token: allows when `Authorization: Bearer <token>` matches (compared in
358
364
  * constant time), else `unauthenticated`. Header only. An empty token throws here, at config time.
365
+ * The allow names its caller `token:<first 12 hex of sha256(token)>`, never the token.
359
366
  */
360
367
  declare function authorizeByToken(options: {
361
368
  token: string | undefined;
362
369
  }): (context: ExecutionContext) => ConsoleAuthorizeResult;
370
+ /**
371
+ * One `authorize` from several: allowed when any form allows (checked in order, stopping at the
372
+ * first that does, whose `caller` it keeps); otherwise `unauthenticated` when any form said so (keeping the first
373
+ * `redirectTo`), else `forbidden`. Each form is any `authorize` value: a function, a class, a lazy
374
+ * import, `{ policy, ability }` or a gate name.
375
+ *
376
+ * ```ts
377
+ * authorize: anyAuthorize(authorizeByToken({ token: process.env.CONSOLE_TOKEN }), AdminSessionAuthorizer)
378
+ * ```
379
+ */
380
+ declare function anyAuthorize(...forms: ConsoleAuthorize[]): ConsoleAuthorizerClass;
363
381
 
364
382
  /**
365
383
  * `TReq` mirrors core's `ActorResolver<TReq>` convention: the transport request type
@@ -415,6 +433,12 @@ interface AgentDashboardOptions<TReq = unknown> {
415
433
  * `executedByRef` unset — the explicit override wins outright, with no resolver fallback.
416
434
  */
417
435
  approvalActorRef?: (req: TReq) => string | undefined;
436
+ /**
437
+ * Register the console's reads as developer tools on the agent MCP server's dev endpoint
438
+ * (`/mcp/aviary`), gated by this console's `authorize`. Default: on when the console's routes are
439
+ * mounted, off with `routes: false`.
440
+ */
441
+ devTools?: boolean;
418
442
  }
419
443
  /** Holds the JSON API + SSE controller and its read service, mounted on its own path. */
420
444
  declare class AgentApiModule {
@@ -424,6 +448,7 @@ declare class AgentApiModule {
424
448
  routes?: boolean;
425
449
  approvalActorRef?: (req: TReq) => string | undefined;
426
450
  authorize?: ConsoleAuthorize;
451
+ devTools?: boolean;
427
452
  }): DynamicModule;
428
453
  }
429
454
  /**
@@ -522,6 +547,49 @@ declare class ConsoleAuthorizeFilter implements ExceptionFilter<ConsoleAccessDen
522
547
  */
523
548
  declare function UseConsoleAuthorize(): ClassDecorator & MethodDecorator;
524
549
 
550
+ interface DevToolInputProperty {
551
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
552
+ description?: string;
553
+ enum?: readonly string[];
554
+ items?: {
555
+ type: 'string';
556
+ };
557
+ minimum?: number;
558
+ maximum?: number;
559
+ }
560
+ interface DevToolInputSchema {
561
+ type: 'object';
562
+ properties: Record<string, DevToolInputProperty>;
563
+ required?: string[];
564
+ }
565
+ /** One developer tool, as the dev-tools slot takes it. */
566
+ interface AgentDevTool {
567
+ name: string;
568
+ kind: 'read' | 'action';
569
+ description: string;
570
+ input: DevToolInputSchema;
571
+ run(input: Record<string, unknown>): Promise<unknown>;
572
+ }
573
+ /**
574
+ * The agent's developer tools (lib `agent`): the governance console's reads, through the same
575
+ * {@link DashboardService} methods its API serves. No actions: approving a tool call over MCP would
576
+ * bypass the human approval it exists for.
577
+ */
578
+ declare function agentDevTools(dashboard: DashboardService): AgentDevTool[];
579
+ /**
580
+ * Registers the agent's tools into the dev-tools slot, gated by the console's own resolved
581
+ * `authorize`, when the console is mounted (or `devTools: true`). Removed again on shutdown.
582
+ */
583
+ declare class AgentDevToolsRegistration implements OnModuleInit, OnModuleDestroy {
584
+ #private;
585
+ private readonly enabled;
586
+ private readonly dashboard;
587
+ private readonly access;
588
+ constructor(enabled: boolean, dashboard: DashboardService, access: DashboardConsoleAccess);
589
+ onModuleInit(): void;
590
+ onModuleDestroy(): void;
591
+ }
592
+
525
593
  /**
526
594
  * Minimal shape guard for a `POST <api>/pricing` body — rejects junk before it reaches
527
595
  * `AgentPricingStore.upsertModelPrice`. Not a full schema validator (the store adapter owns real
@@ -587,5 +655,7 @@ declare const DASHBOARD_API_PATH: unique symbol;
587
655
  declare const DASHBOARD_APPROVAL_ACTOR_REF: unique symbol;
588
656
  /** DI token carrying the console's `authorize` (and whether to warn when it is omitted). */
589
657
  declare const DASHBOARD_CONSOLE_OPTIONS: unique symbol;
658
+ /** DI token: whether the agent's dev tools register into the dev-tools slot. */
659
+ declare const DASHBOARD_DEV_TOOLS: unique symbol;
590
660
 
591
- export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, type ActorSpendRowWithLabel, AgentApiController, AgentApiModule, AgentDashboardModule, type AgentDashboardMountPathsOptions, type AgentDashboardOptions, AgentUiController, CONSOLE_AUTHORIZE_MISSING_WARNING, CONSOLE_GATE, CONSOLE_PAGE_METADATA, ConsoleAccessDenied, type ConsoleAuthorize, ConsoleAuthorizeFilter, ConsoleAuthorizeGuard, type ConsoleAuthorizeResult, type ConsoleAuthorizer, type ConsoleAuthorizerClass, type ConsoleDecide, type ConsoleDecision, type ConsoleGate, ConsolePage, type ConsolePolicyCheck, DASHBOARD_API_PATH, DASHBOARD_APPROVAL_ACTOR_REF, DASHBOARD_BASE_PATH, DASHBOARD_CONSOLE_OPTIONS, DashboardConsoleAccess, DashboardService, type LiveAgentEvent, type ReliabilityOverview, type RunDetailWithLabel, type SpendOverview, type ThreadActivityRowWithLabel, type ThreadDetailWithLabel, type ThreadSpendRowWithLabel, UseConsoleAuthorize, type WithActorLabel, agentDashboardMountPaths, authorizeByToken, normalizeConsoleResult, parsePriceInput, resolveConsoleAuthorize };
661
+ export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, type ActorSpendRowWithLabel, AgentApiController, AgentApiModule, AgentDashboardModule, type AgentDashboardMountPathsOptions, type AgentDashboardOptions, type AgentDevTool, AgentDevToolsRegistration, AgentUiController, CONSOLE_AUTHORIZE_MISSING_WARNING, CONSOLE_GATE, CONSOLE_PAGE_METADATA, ConsoleAccessDenied, type ConsoleAuthorize, ConsoleAuthorizeFilter, ConsoleAuthorizeGuard, type ConsoleAuthorizeResult, type ConsoleAuthorizer, type ConsoleAuthorizerClass, type ConsoleDecide, type ConsoleDecision, type ConsoleGate, ConsolePage, type ConsolePolicyCheck, DASHBOARD_API_PATH, DASHBOARD_APPROVAL_ACTOR_REF, DASHBOARD_BASE_PATH, DASHBOARD_CONSOLE_OPTIONS, DASHBOARD_DEV_TOOLS, DashboardConsoleAccess, DashboardService, type LiveAgentEvent, type ReliabilityOverview, type RunDetailWithLabel, type SpendOverview, type ThreadActivityRowWithLabel, type ThreadDetailWithLabel, type ThreadSpendRowWithLabel, UseConsoleAuthorize, type WithActorLabel, agentDashboardMountPaths, agentDevTools, anyAuthorize, authorizeByToken, normalizeConsoleResult, parsePriceInput, resolveConsoleAuthorize };
@@ -1,7 +1,7 @@
1
1
  import { ActorSpendRow, AgentGovernanceQueries, ActorDirectory, AgentPricingStore, AgentApprovalPort, GovernanceRange, ModelSpendRow, UsageTrendPoint, FeatureSpendRow, ThreadSpendRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, ToolCallActivityRow, GovernancePageQuery, ToolCallWhere, GovernancePage, RunWhere, PendingApprovalRow, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, ThreadActivityRow, ToolStatRow, GenuiStats, ThreadWhere, CurrentModelPrice, ActorResolver, ModelPriceInput } from '@dudousxd/nestjs-agent-core';
2
2
  export { ActorDirectory } from '@dudousxd/nestjs-agent-core';
3
3
  import { Observable } from 'rxjs';
4
- import { ExecutionContext, Type, Logger, DynamicModule, StreamableFile, HttpException, ExceptionFilter, ArgumentsHost, CanActivate, OnModuleInit } from '@nestjs/common';
4
+ import { ExecutionContext, Type, Logger, DynamicModule, StreamableFile, OnModuleInit, HttpException, ExceptionFilter, ArgumentsHost, CanActivate, OnModuleDestroy } from '@nestjs/common';
5
5
  import { ModuleRef, HttpAdapterHost } from '@nestjs/core';
6
6
 
7
7
  /** An actor-scoped row decorated with its resolved display label — `null` when unbound or unresolved. */
@@ -295,9 +295,14 @@ interface AgentDashboardMountPathsOptions {
295
295
  */
296
296
  declare function agentDashboardMountPaths(options?: AgentDashboardMountPathsOptions): string[];
297
297
 
298
- /** What an `authorize` check answers. */
298
+ /**
299
+ * What an `authorize` check answers. An allow may name who it let in (`caller`, for example
300
+ * `'user:42'`): the dev MCP endpoint logs it as the caller of a developer tool. Never put a secret
301
+ * in it.
302
+ */
299
303
  type ConsoleAuthorizeResult = boolean | {
300
304
  allowed: true;
305
+ caller?: string;
301
306
  } | {
302
307
  allowed: false;
303
308
  reason?: 'unauthenticated' | 'forbidden';
@@ -321,6 +326,7 @@ type ConsoleAuthorize = ((context: ExecutionContext) => ConsoleAuthorizeResult |
321
326
  /** A normalized `authorize` answer. */
322
327
  type ConsoleDecision = {
323
328
  allowed: true;
329
+ caller?: string;
324
330
  } | {
325
331
  allowed: false;
326
332
  reason: 'unauthenticated' | 'forbidden';
@@ -356,10 +362,22 @@ declare function resolveConsoleAuthorize(authorize: ConsoleAuthorize | undefined
356
362
  /**
357
363
  * `authorize` by a bearer token: allows when `Authorization: Bearer <token>` matches (compared in
358
364
  * constant time), else `unauthenticated`. Header only. An empty token throws here, at config time.
365
+ * The allow names its caller `token:<first 12 hex of sha256(token)>`, never the token.
359
366
  */
360
367
  declare function authorizeByToken(options: {
361
368
  token: string | undefined;
362
369
  }): (context: ExecutionContext) => ConsoleAuthorizeResult;
370
+ /**
371
+ * One `authorize` from several: allowed when any form allows (checked in order, stopping at the
372
+ * first that does, whose `caller` it keeps); otherwise `unauthenticated` when any form said so (keeping the first
373
+ * `redirectTo`), else `forbidden`. Each form is any `authorize` value: a function, a class, a lazy
374
+ * import, `{ policy, ability }` or a gate name.
375
+ *
376
+ * ```ts
377
+ * authorize: anyAuthorize(authorizeByToken({ token: process.env.CONSOLE_TOKEN }), AdminSessionAuthorizer)
378
+ * ```
379
+ */
380
+ declare function anyAuthorize(...forms: ConsoleAuthorize[]): ConsoleAuthorizerClass;
363
381
 
364
382
  /**
365
383
  * `TReq` mirrors core's `ActorResolver<TReq>` convention: the transport request type
@@ -415,6 +433,12 @@ interface AgentDashboardOptions<TReq = unknown> {
415
433
  * `executedByRef` unset — the explicit override wins outright, with no resolver fallback.
416
434
  */
417
435
  approvalActorRef?: (req: TReq) => string | undefined;
436
+ /**
437
+ * Register the console's reads as developer tools on the agent MCP server's dev endpoint
438
+ * (`/mcp/aviary`), gated by this console's `authorize`. Default: on when the console's routes are
439
+ * mounted, off with `routes: false`.
440
+ */
441
+ devTools?: boolean;
418
442
  }
419
443
  /** Holds the JSON API + SSE controller and its read service, mounted on its own path. */
420
444
  declare class AgentApiModule {
@@ -424,6 +448,7 @@ declare class AgentApiModule {
424
448
  routes?: boolean;
425
449
  approvalActorRef?: (req: TReq) => string | undefined;
426
450
  authorize?: ConsoleAuthorize;
451
+ devTools?: boolean;
427
452
  }): DynamicModule;
428
453
  }
429
454
  /**
@@ -522,6 +547,49 @@ declare class ConsoleAuthorizeFilter implements ExceptionFilter<ConsoleAccessDen
522
547
  */
523
548
  declare function UseConsoleAuthorize(): ClassDecorator & MethodDecorator;
524
549
 
550
+ interface DevToolInputProperty {
551
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
552
+ description?: string;
553
+ enum?: readonly string[];
554
+ items?: {
555
+ type: 'string';
556
+ };
557
+ minimum?: number;
558
+ maximum?: number;
559
+ }
560
+ interface DevToolInputSchema {
561
+ type: 'object';
562
+ properties: Record<string, DevToolInputProperty>;
563
+ required?: string[];
564
+ }
565
+ /** One developer tool, as the dev-tools slot takes it. */
566
+ interface AgentDevTool {
567
+ name: string;
568
+ kind: 'read' | 'action';
569
+ description: string;
570
+ input: DevToolInputSchema;
571
+ run(input: Record<string, unknown>): Promise<unknown>;
572
+ }
573
+ /**
574
+ * The agent's developer tools (lib `agent`): the governance console's reads, through the same
575
+ * {@link DashboardService} methods its API serves. No actions: approving a tool call over MCP would
576
+ * bypass the human approval it exists for.
577
+ */
578
+ declare function agentDevTools(dashboard: DashboardService): AgentDevTool[];
579
+ /**
580
+ * Registers the agent's tools into the dev-tools slot, gated by the console's own resolved
581
+ * `authorize`, when the console is mounted (or `devTools: true`). Removed again on shutdown.
582
+ */
583
+ declare class AgentDevToolsRegistration implements OnModuleInit, OnModuleDestroy {
584
+ #private;
585
+ private readonly enabled;
586
+ private readonly dashboard;
587
+ private readonly access;
588
+ constructor(enabled: boolean, dashboard: DashboardService, access: DashboardConsoleAccess);
589
+ onModuleInit(): void;
590
+ onModuleDestroy(): void;
591
+ }
592
+
525
593
  /**
526
594
  * Minimal shape guard for a `POST <api>/pricing` body — rejects junk before it reaches
527
595
  * `AgentPricingStore.upsertModelPrice`. Not a full schema validator (the store adapter owns real
@@ -587,5 +655,7 @@ declare const DASHBOARD_API_PATH: unique symbol;
587
655
  declare const DASHBOARD_APPROVAL_ACTOR_REF: unique symbol;
588
656
  /** DI token carrying the console's `authorize` (and whether to warn when it is omitted). */
589
657
  declare const DASHBOARD_CONSOLE_OPTIONS: unique symbol;
658
+ /** DI token: whether the agent's dev tools register into the dev-tools slot. */
659
+ declare const DASHBOARD_DEV_TOOLS: unique symbol;
590
660
 
591
- export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, type ActorSpendRowWithLabel, AgentApiController, AgentApiModule, AgentDashboardModule, type AgentDashboardMountPathsOptions, type AgentDashboardOptions, AgentUiController, CONSOLE_AUTHORIZE_MISSING_WARNING, CONSOLE_GATE, CONSOLE_PAGE_METADATA, ConsoleAccessDenied, type ConsoleAuthorize, ConsoleAuthorizeFilter, ConsoleAuthorizeGuard, type ConsoleAuthorizeResult, type ConsoleAuthorizer, type ConsoleAuthorizerClass, type ConsoleDecide, type ConsoleDecision, type ConsoleGate, ConsolePage, type ConsolePolicyCheck, DASHBOARD_API_PATH, DASHBOARD_APPROVAL_ACTOR_REF, DASHBOARD_BASE_PATH, DASHBOARD_CONSOLE_OPTIONS, DashboardConsoleAccess, DashboardService, type LiveAgentEvent, type ReliabilityOverview, type RunDetailWithLabel, type SpendOverview, type ThreadActivityRowWithLabel, type ThreadDetailWithLabel, type ThreadSpendRowWithLabel, UseConsoleAuthorize, type WithActorLabel, agentDashboardMountPaths, authorizeByToken, normalizeConsoleResult, parsePriceInput, resolveConsoleAuthorize };
661
+ export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, type ActorSpendRowWithLabel, AgentApiController, AgentApiModule, AgentDashboardModule, type AgentDashboardMountPathsOptions, type AgentDashboardOptions, type AgentDevTool, AgentDevToolsRegistration, AgentUiController, CONSOLE_AUTHORIZE_MISSING_WARNING, CONSOLE_GATE, CONSOLE_PAGE_METADATA, ConsoleAccessDenied, type ConsoleAuthorize, ConsoleAuthorizeFilter, ConsoleAuthorizeGuard, type ConsoleAuthorizeResult, type ConsoleAuthorizer, type ConsoleAuthorizerClass, type ConsoleDecide, type ConsoleDecision, type ConsoleGate, ConsolePage, type ConsolePolicyCheck, DASHBOARD_API_PATH, DASHBOARD_APPROVAL_ACTOR_REF, DASHBOARD_BASE_PATH, DASHBOARD_CONSOLE_OPTIONS, DASHBOARD_DEV_TOOLS, DashboardConsoleAccess, DashboardService, type LiveAgentEvent, type ReliabilityOverview, type RunDetailWithLabel, type SpendOverview, type ThreadActivityRowWithLabel, type ThreadDetailWithLabel, type ThreadSpendRowWithLabel, UseConsoleAuthorize, type WithActorLabel, agentDashboardMountPaths, agentDevTools, anyAuthorize, authorizeByToken, normalizeConsoleResult, parsePriceInput, resolveConsoleAuthorize };