@dudousxd/nestjs-agent 1.29.0 → 1.31.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.
Files changed (37) hide show
  1. package/dist/a2ui/index.cjs +207 -11
  2. package/dist/a2ui/index.cjs.map +1 -1
  3. package/dist/a2ui/index.d.cts +3 -3
  4. package/dist/a2ui/index.d.ts +3 -3
  5. package/dist/a2ui/index.js +203 -12
  6. package/dist/a2ui/index.js.map +1 -1
  7. package/dist/agent-genui.module-D0X3YnzO.d.cts +147 -0
  8. package/dist/agent-genui.module-D0X3YnzO.d.ts +147 -0
  9. package/dist/{chat-queue.service-B-fVOJGf.d.ts → chat-queue.service-Bdz43pAC.d.ts} +1 -1
  10. package/dist/{chat-queue.service-Bk7DCKGV.d.cts → chat-queue.service-ZwQ9p-Ps.d.cts} +1 -1
  11. package/dist/durable/index.cjs +249 -32
  12. package/dist/durable/index.cjs.map +1 -1
  13. package/dist/durable/index.d.cts +2 -2
  14. package/dist/durable/index.d.ts +2 -2
  15. package/dist/durable/index.js +240 -28
  16. package/dist/durable/index.js.map +1 -1
  17. package/dist/genui/index.cjs +211 -11
  18. package/dist/genui/index.cjs.map +1 -1
  19. package/dist/genui/index.d.cts +27 -94
  20. package/dist/genui/index.d.ts +27 -94
  21. package/dist/genui/index.js +205 -12
  22. package/dist/genui/index.js.map +1 -1
  23. package/dist/{index-APh8WN3z.d.ts → index-BGevU_Ih.d.ts} +8 -1
  24. package/dist/{index-D9EM7ivO.d.cts → index-DoCdfNrO.d.cts} +8 -1
  25. package/dist/index.cjs +240 -26
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +8 -6
  28. package/dist/index.d.ts +8 -6
  29. package/dist/index.js +236 -27
  30. package/dist/index.js.map +1 -1
  31. package/dist/vite/index.cjs +48 -0
  32. package/dist/vite/index.cjs.map +1 -0
  33. package/dist/vite/index.d.cts +32 -0
  34. package/dist/vite/index.d.ts +32 -0
  35. package/dist/vite/index.js +21 -0
  36. package/dist/vite/index.js.map +1 -0
  37. package/package.json +17 -3
@@ -0,0 +1,147 @@
1
+ import { ToolPresentation } from '@dudousxd/nestjs-agent-core';
2
+ import { GenuiCatalogScope, Catalog, TreeSchemaMode, GenuiStreaming, TreeLimits, DefineSandboxOptions, GenuiChannels } from '@dudousxd/nestjs-agent-core/genui';
3
+ import { Type, DynamicModule, ModuleMetadata, FactoryProvider } from '@nestjs/common';
4
+
5
+ /** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */
6
+ declare const GENUI_CATALOG: unique symbol;
7
+ /** The resolved {@link AgentGenuiOptions} (without the resolver). */
8
+ declare const GENUI_OPTIONS: unique symbol;
9
+ /** Inject the app's genui catalog ({@link GENUI_CATALOG}). */
10
+ declare const InjectGenuiCatalog: () => ParameterDecorator & PropertyDecorator;
11
+ /**
12
+ * Picks the catalog for ONE request — a tenant's own, versioned components. Consulted when a genui
13
+ * call is validated and when the turn's tool list is described to the model, so components can
14
+ * change without rebuilding tools at boot. Cache in here if resolving costs a round trip: it runs
15
+ * once per turn per genui tool, and once per call.
16
+ *
17
+ * Provide it through `AgentGenuiModule.forRoot({ resolver })` (a class, resolved with DI, or an
18
+ * instance); it is then injectable, and replaceable in a test with
19
+ * `overrideProvider(GenuiCatalogResolver)`.
20
+ */
21
+ declare abstract class GenuiCatalogResolver {
22
+ abstract resolve(scope: GenuiCatalogScope): Catalog | Promise<Catalog>;
23
+ }
24
+ /** What {@link AgentGenuiModule} builds tools from. */
25
+ interface AgentGenuiOptions {
26
+ /**
27
+ * The catalog. With a {@link GenuiCatalogResolver} it is the boot-time one — it names the
28
+ * per-component tools — and may be empty. Default: an empty catalog.
29
+ */
30
+ catalog?: Catalog;
31
+ /**
32
+ * `tree` (default): one `ui__render` tool taking a composed tree (a single node is pushed as that
33
+ * component). `per-component`: one `ui__show_<snake>` tool per component.
34
+ */
35
+ mode?: 'per-component' | 'tree';
36
+ /** `ui__render`'s input schema: `'strict'` (default, a `$defs` union per component) or `'loose'`. */
37
+ treeSchema?: TreeSchemaMode;
38
+ /**
39
+ * Tree mode: `'complete'` (default) draws the tree once the call has run; `'partial'` streams it
40
+ * as `partial` ui frames while the model writes it. A component's own `streaming` overrides it.
41
+ */
42
+ streaming?: GenuiStreaming;
43
+ /** Least time between two partial tree frames of one call, in ms. Default 100. */
44
+ streamingThrottleMs?: number;
45
+ /** End the model's turn once a genui call succeeds (no narrating follow-up call). */
46
+ terminal?: boolean;
47
+ /** Tool name in `tree` mode. Default `ui__render`. */
48
+ treeToolName?: string;
49
+ /** Text prepended to the tree tool's description. */
50
+ treeInstructions?: string;
51
+ treeLimits?: TreeLimits;
52
+ /**
53
+ * Tree mode: components that ALSO get a flat tool whose input IS their props —
54
+ * `componentTools: ['Sandbox']` adds `ui__sandbox`, so a model writing a big component on its own
55
+ * has no `{ type, props }` envelope to leave out.
56
+ */
57
+ componentTools?: readonly string[];
58
+ /** Tool-name prefix for `componentTools`. Default `ui__` (`Sandbox` → `ui__sandbox`). */
59
+ componentToolPrefix?: string;
60
+ /** Tool-name prefix in `per-component` mode. Default `ui__show_`. */
61
+ namePrefix?: string;
62
+ /**
63
+ * Also register ONE generic tool taking `{ component, props }`, validated against the request's
64
+ * catalog — how a model reaches a tenant's own components, which no boot-time tool names. `true`
65
+ * names it `ui__show`.
66
+ */
67
+ showTool?: boolean | string;
68
+ /** Text prepended to the show tool's description. */
69
+ showInstructions?: string;
70
+ /** Roles allowed to call the tools. Undefined → the roles policy default. */
71
+ roles?: string[];
72
+ /** Override the generated presentation per component (or per tree / show tool name). */
73
+ presentation?: (component: string) => ToolPresentation | undefined;
74
+ /**
75
+ * Add the sandbox component (`Sandbox`): the model may write HTML, CSS and JS for a one-off
76
+ * interactive answer when no catalog component fits. `true` for the defaults (no network), or
77
+ * the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.
78
+ * The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared
79
+ * catalog file) so the renderer enforces the same policy.
80
+ *
81
+ * `theme` (default on), `tailwind` and `kit` put the app's design system in the frame. `kit: true`
82
+ * (and the theme's variable names) are found through `sandboxKit`: the descriptor
83
+ * `genuiSandboxKit()` (`@dudousxd/nestjs-agent/vite`) writes in dev, the Vite manifest in
84
+ * production — and `GET <base>/config` tells the renderer where the assets are.
85
+ */
86
+ sandbox?: boolean | DefineSandboxOptions;
87
+ /**
88
+ * Per-channel generative UI: each entry sets the mode, streaming, sandbox and rendering of one
89
+ * channel (`web`, `mobile`, `whatsapp`, `telegram`, `email`, or `default` for the rest), over the
90
+ * top-level options. A text channel (`@dudousxd/nestjs-agent-channels`) configured here draws the
91
+ * components natively (reply buttons, lists, images). Omitted → every channel is served by the
92
+ * top-level options, as before.
93
+ */
94
+ channels?: GenuiChannels;
95
+ /**
96
+ * Where the sandbox kit is found (with `sandbox: { kit: true }`, `tailwind: true` or the theme's
97
+ * names). No Vite runs in the Nest process, so: the descriptor the dev plugin writes, else the
98
+ * production Vite manifest (read first when `NODE_ENV=production`).
99
+ */
100
+ sandboxKit?: AgentGenuiSandboxKitOptions;
101
+ }
102
+ /** {@link AgentGenuiOptions.sandboxKit}. Relative paths resolve against `root`. */
103
+ interface AgentGenuiSandboxKitOptions {
104
+ /** Default `process.cwd()`. */
105
+ root?: string;
106
+ /** The dev descriptor `genuiSandboxKit()` writes. Default `.genui/sandbox-kit.json`. */
107
+ descriptor?: string;
108
+ /**
109
+ * The production Vite manifest, and the directory its `file`s are relative to. Default
110
+ * `{ file: 'public/.vite/manifest.json', outDir: 'public' }`; `false` → none.
111
+ */
112
+ manifest?: {
113
+ file: string;
114
+ outDir: string;
115
+ } | false;
116
+ /** An explicit kit url (an SPA served from elsewhere), over what is found. */
117
+ kitUrl?: string;
118
+ /** Read the manifest first. Default: `NODE_ENV === 'production'`. */
119
+ production?: boolean;
120
+ }
121
+ type ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;
122
+ interface AgentGenuiModuleOptions extends AgentGenuiOptions {
123
+ /** Per-request catalogs. A class is instantiated with DI (its dependencies must be global or exported to the root). */
124
+ resolver?: ResolverOption;
125
+ }
126
+ interface AgentGenuiModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
127
+ inject?: FactoryProvider['inject'];
128
+ useFactory: (...deps: any[]) => AgentGenuiOptions | Promise<AgentGenuiOptions>;
129
+ /** Per-request catalogs. A class resolves its dependencies from `imports`. */
130
+ resolver?: ResolverOption;
131
+ }
132
+ /**
133
+ * Generative UI for the agent: registers the tools that let the model push catalog components
134
+ * (one `ui__render` tree tool, or `ui__show_<component>` per component, and/or the generic
135
+ * `ui__show`), and makes the catalog
136
+ * injectable. Global, like `AgentModule`; import it once, next to it.
137
+ *
138
+ * ```ts
139
+ * AgentGenuiModule.forRoot({ catalog, mode: 'tree', terminal: true })
140
+ * ```
141
+ */
142
+ declare class AgentGenuiModule {
143
+ static forRoot(options?: AgentGenuiModuleOptions): DynamicModule;
144
+ static forRootAsync(options: AgentGenuiModuleAsyncOptions): DynamicModule;
145
+ }
146
+
147
+ export { AgentGenuiModule as A, GenuiCatalogResolver as G, InjectGenuiCatalog as I, type AgentGenuiModuleAsyncOptions as a, type AgentGenuiModuleOptions as b, type AgentGenuiOptions as c, type AgentGenuiSandboxKitOptions as d, GENUI_CATALOG as e, GENUI_OPTIONS as f };
@@ -0,0 +1,147 @@
1
+ import { ToolPresentation } from '@dudousxd/nestjs-agent-core';
2
+ import { GenuiCatalogScope, Catalog, TreeSchemaMode, GenuiStreaming, TreeLimits, DefineSandboxOptions, GenuiChannels } from '@dudousxd/nestjs-agent-core/genui';
3
+ import { Type, DynamicModule, ModuleMetadata, FactoryProvider } from '@nestjs/common';
4
+
5
+ /** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */
6
+ declare const GENUI_CATALOG: unique symbol;
7
+ /** The resolved {@link AgentGenuiOptions} (without the resolver). */
8
+ declare const GENUI_OPTIONS: unique symbol;
9
+ /** Inject the app's genui catalog ({@link GENUI_CATALOG}). */
10
+ declare const InjectGenuiCatalog: () => ParameterDecorator & PropertyDecorator;
11
+ /**
12
+ * Picks the catalog for ONE request — a tenant's own, versioned components. Consulted when a genui
13
+ * call is validated and when the turn's tool list is described to the model, so components can
14
+ * change without rebuilding tools at boot. Cache in here if resolving costs a round trip: it runs
15
+ * once per turn per genui tool, and once per call.
16
+ *
17
+ * Provide it through `AgentGenuiModule.forRoot({ resolver })` (a class, resolved with DI, or an
18
+ * instance); it is then injectable, and replaceable in a test with
19
+ * `overrideProvider(GenuiCatalogResolver)`.
20
+ */
21
+ declare abstract class GenuiCatalogResolver {
22
+ abstract resolve(scope: GenuiCatalogScope): Catalog | Promise<Catalog>;
23
+ }
24
+ /** What {@link AgentGenuiModule} builds tools from. */
25
+ interface AgentGenuiOptions {
26
+ /**
27
+ * The catalog. With a {@link GenuiCatalogResolver} it is the boot-time one — it names the
28
+ * per-component tools — and may be empty. Default: an empty catalog.
29
+ */
30
+ catalog?: Catalog;
31
+ /**
32
+ * `tree` (default): one `ui__render` tool taking a composed tree (a single node is pushed as that
33
+ * component). `per-component`: one `ui__show_<snake>` tool per component.
34
+ */
35
+ mode?: 'per-component' | 'tree';
36
+ /** `ui__render`'s input schema: `'strict'` (default, a `$defs` union per component) or `'loose'`. */
37
+ treeSchema?: TreeSchemaMode;
38
+ /**
39
+ * Tree mode: `'complete'` (default) draws the tree once the call has run; `'partial'` streams it
40
+ * as `partial` ui frames while the model writes it. A component's own `streaming` overrides it.
41
+ */
42
+ streaming?: GenuiStreaming;
43
+ /** Least time between two partial tree frames of one call, in ms. Default 100. */
44
+ streamingThrottleMs?: number;
45
+ /** End the model's turn once a genui call succeeds (no narrating follow-up call). */
46
+ terminal?: boolean;
47
+ /** Tool name in `tree` mode. Default `ui__render`. */
48
+ treeToolName?: string;
49
+ /** Text prepended to the tree tool's description. */
50
+ treeInstructions?: string;
51
+ treeLimits?: TreeLimits;
52
+ /**
53
+ * Tree mode: components that ALSO get a flat tool whose input IS their props —
54
+ * `componentTools: ['Sandbox']` adds `ui__sandbox`, so a model writing a big component on its own
55
+ * has no `{ type, props }` envelope to leave out.
56
+ */
57
+ componentTools?: readonly string[];
58
+ /** Tool-name prefix for `componentTools`. Default `ui__` (`Sandbox` → `ui__sandbox`). */
59
+ componentToolPrefix?: string;
60
+ /** Tool-name prefix in `per-component` mode. Default `ui__show_`. */
61
+ namePrefix?: string;
62
+ /**
63
+ * Also register ONE generic tool taking `{ component, props }`, validated against the request's
64
+ * catalog — how a model reaches a tenant's own components, which no boot-time tool names. `true`
65
+ * names it `ui__show`.
66
+ */
67
+ showTool?: boolean | string;
68
+ /** Text prepended to the show tool's description. */
69
+ showInstructions?: string;
70
+ /** Roles allowed to call the tools. Undefined → the roles policy default. */
71
+ roles?: string[];
72
+ /** Override the generated presentation per component (or per tree / show tool name). */
73
+ presentation?: (component: string) => ToolPresentation | undefined;
74
+ /**
75
+ * Add the sandbox component (`Sandbox`): the model may write HTML, CSS and JS for a one-off
76
+ * interactive answer when no catalog component fits. `true` for the defaults (no network), or
77
+ * the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.
78
+ * The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared
79
+ * catalog file) so the renderer enforces the same policy.
80
+ *
81
+ * `theme` (default on), `tailwind` and `kit` put the app's design system in the frame. `kit: true`
82
+ * (and the theme's variable names) are found through `sandboxKit`: the descriptor
83
+ * `genuiSandboxKit()` (`@dudousxd/nestjs-agent/vite`) writes in dev, the Vite manifest in
84
+ * production — and `GET <base>/config` tells the renderer where the assets are.
85
+ */
86
+ sandbox?: boolean | DefineSandboxOptions;
87
+ /**
88
+ * Per-channel generative UI: each entry sets the mode, streaming, sandbox and rendering of one
89
+ * channel (`web`, `mobile`, `whatsapp`, `telegram`, `email`, or `default` for the rest), over the
90
+ * top-level options. A text channel (`@dudousxd/nestjs-agent-channels`) configured here draws the
91
+ * components natively (reply buttons, lists, images). Omitted → every channel is served by the
92
+ * top-level options, as before.
93
+ */
94
+ channels?: GenuiChannels;
95
+ /**
96
+ * Where the sandbox kit is found (with `sandbox: { kit: true }`, `tailwind: true` or the theme's
97
+ * names). No Vite runs in the Nest process, so: the descriptor the dev plugin writes, else the
98
+ * production Vite manifest (read first when `NODE_ENV=production`).
99
+ */
100
+ sandboxKit?: AgentGenuiSandboxKitOptions;
101
+ }
102
+ /** {@link AgentGenuiOptions.sandboxKit}. Relative paths resolve against `root`. */
103
+ interface AgentGenuiSandboxKitOptions {
104
+ /** Default `process.cwd()`. */
105
+ root?: string;
106
+ /** The dev descriptor `genuiSandboxKit()` writes. Default `.genui/sandbox-kit.json`. */
107
+ descriptor?: string;
108
+ /**
109
+ * The production Vite manifest, and the directory its `file`s are relative to. Default
110
+ * `{ file: 'public/.vite/manifest.json', outDir: 'public' }`; `false` → none.
111
+ */
112
+ manifest?: {
113
+ file: string;
114
+ outDir: string;
115
+ } | false;
116
+ /** An explicit kit url (an SPA served from elsewhere), over what is found. */
117
+ kitUrl?: string;
118
+ /** Read the manifest first. Default: `NODE_ENV === 'production'`. */
119
+ production?: boolean;
120
+ }
121
+ type ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;
122
+ interface AgentGenuiModuleOptions extends AgentGenuiOptions {
123
+ /** Per-request catalogs. A class is instantiated with DI (its dependencies must be global or exported to the root). */
124
+ resolver?: ResolverOption;
125
+ }
126
+ interface AgentGenuiModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
127
+ inject?: FactoryProvider['inject'];
128
+ useFactory: (...deps: any[]) => AgentGenuiOptions | Promise<AgentGenuiOptions>;
129
+ /** Per-request catalogs. A class resolves its dependencies from `imports`. */
130
+ resolver?: ResolverOption;
131
+ }
132
+ /**
133
+ * Generative UI for the agent: registers the tools that let the model push catalog components
134
+ * (one `ui__render` tree tool, or `ui__show_<component>` per component, and/or the generic
135
+ * `ui__show`), and makes the catalog
136
+ * injectable. Global, like `AgentModule`; import it once, next to it.
137
+ *
138
+ * ```ts
139
+ * AgentGenuiModule.forRoot({ catalog, mode: 'tree', terminal: true })
140
+ * ```
141
+ */
142
+ declare class AgentGenuiModule {
143
+ static forRoot(options?: AgentGenuiModuleOptions): DynamicModule;
144
+ static forRootAsync(options: AgentGenuiModuleAsyncOptions): DynamicModule;
145
+ }
146
+
147
+ export { AgentGenuiModule as A, GenuiCatalogResolver as G, InjectGenuiCatalog as I, type AgentGenuiModuleAsyncOptions as a, type AgentGenuiModuleOptions as b, type AgentGenuiOptions as c, type AgentGenuiSandboxKitOptions as d, GENUI_CATALOG as e, GENUI_OPTIONS as f };
@@ -2,7 +2,7 @@ import { ResolveToolUiCatalog, ModelProvider, AgentStore, ToolRegistry, RolesPol
2
2
  import { Catalog } from '@dudousxd/nestjs-agent-core/genui';
3
3
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  import { Provider, InjectionToken, Type, FactoryProvider, CanActivate, ModuleMetadata, OptionalFactoryDependency } from '@nestjs/common';
5
- import { GenuiCatalogResolver } from './genui/index.js';
5
+ import { G as GenuiCatalogResolver } from './agent-genui.module-D0X3YnzO.js';
6
6
 
7
7
  /** Everything `runAgentLoop` needs, minus the per-run `day` the runner stamps. */
8
8
  interface AgentDeps {
@@ -2,7 +2,7 @@ import { ResolveToolUiCatalog, ModelProvider, AgentStore, ToolRegistry, RolesPol
2
2
  import { Catalog } from '@dudousxd/nestjs-agent-core/genui';
3
3
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  import { Provider, InjectionToken, Type, FactoryProvider, CanActivate, ModuleMetadata, OptionalFactoryDependency } from '@nestjs/common';
5
- import { GenuiCatalogResolver } from './genui/index.cjs';
5
+ import { G as GenuiCatalogResolver } from './agent-genui.module-D0X3YnzO.cjs';
6
6
 
7
7
  /** Everything `runAgentLoop` needs, minus the per-run `day` the runner stamps. */
8
8
  interface AgentDeps {