@dudousxd/nestjs-agent 1.30.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.
- package/dist/a2ui/index.cjs +207 -11
- package/dist/a2ui/index.cjs.map +1 -1
- package/dist/a2ui/index.d.cts +3 -3
- package/dist/a2ui/index.d.ts +3 -3
- package/dist/a2ui/index.js +203 -12
- package/dist/a2ui/index.js.map +1 -1
- package/dist/agent-genui.module-D0X3YnzO.d.cts +147 -0
- package/dist/agent-genui.module-D0X3YnzO.d.ts +147 -0
- package/dist/{chat-queue.service-B-fVOJGf.d.ts → chat-queue.service-Bdz43pAC.d.ts} +1 -1
- package/dist/{chat-queue.service-Bk7DCKGV.d.cts → chat-queue.service-ZwQ9p-Ps.d.cts} +1 -1
- package/dist/durable/index.cjs +249 -32
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +2 -2
- package/dist/durable/index.d.ts +2 -2
- package/dist/durable/index.js +240 -28
- package/dist/durable/index.js.map +1 -1
- package/dist/genui/index.cjs +211 -11
- package/dist/genui/index.cjs.map +1 -1
- package/dist/genui/index.d.cts +27 -102
- package/dist/genui/index.d.ts +27 -102
- package/dist/genui/index.js +205 -12
- package/dist/genui/index.js.map +1 -1
- package/dist/{index-APh8WN3z.d.ts → index-BGevU_Ih.d.ts} +8 -1
- package/dist/{index-D9EM7ivO.d.cts → index-DoCdfNrO.d.cts} +8 -1
- package/dist/index.cjs +240 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +236 -27
- package/dist/index.js.map +1 -1
- package/dist/vite/index.cjs +48 -0
- package/dist/vite/index.cjs.map +1 -0
- package/dist/vite/index.d.cts +32 -0
- package/dist/vite/index.d.ts +32 -0
- package/dist/vite/index.js +21 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +17 -3
package/dist/genui/index.d.ts
CHANGED
|
@@ -1,110 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
export { A as AgentGenuiModule, a as AgentGenuiModuleAsyncOptions, b as AgentGenuiModuleOptions, c as AgentGenuiOptions, d as AgentGenuiSandboxKitOptions, e as GENUI_CATALOG, f as GENUI_OPTIONS, G as GenuiCatalogResolver, I as InjectGenuiCatalog } from '../agent-genui.module-D0X3YnzO.js';
|
|
2
|
+
import { Catalog, GenuiCatalogScope, GenuiChannels, GenuiChannelBase, SandboxClientConfig } from '@dudousxd/nestjs-agent-core/genui';
|
|
3
3
|
export * from '@dudousxd/nestjs-agent-core/genui';
|
|
4
|
-
import
|
|
4
|
+
import '@dudousxd/nestjs-agent-core';
|
|
5
|
+
import '@nestjs/common';
|
|
5
6
|
|
|
6
|
-
/** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */
|
|
7
|
-
declare const GENUI_CATALOG: unique symbol;
|
|
8
|
-
/** The resolved {@link AgentGenuiOptions} (without the resolver). */
|
|
9
|
-
declare const GENUI_OPTIONS: unique symbol;
|
|
10
|
-
/** Inject the app's genui catalog ({@link GENUI_CATALOG}). */
|
|
11
|
-
declare const InjectGenuiCatalog: () => ParameterDecorator & PropertyDecorator;
|
|
12
7
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* once per turn per genui tool, and once per call.
|
|
17
|
-
*
|
|
18
|
-
* Provide it through `AgentGenuiModule.forRoot({ resolver })` (a class, resolved with DI, or an
|
|
19
|
-
* instance); it is then injectable, and replaceable in a test with
|
|
20
|
-
* `overrideProvider(GenuiCatalogResolver)`.
|
|
8
|
+
* The app's genui setup ({@link AgentGenui}): the catalog, the per-channel options and what the
|
|
9
|
+
* sandbox renderer is told — what the text channels (`@dudousxd/nestjs-agent-channels`) and
|
|
10
|
+
* `GET <base>/config` read.
|
|
21
11
|
*/
|
|
22
|
-
declare
|
|
23
|
-
abstract resolve(scope: GenuiCatalogScope): Catalog | Promise<Catalog>;
|
|
24
|
-
}
|
|
25
|
-
/** What {@link AgentGenuiModule} builds tools from. */
|
|
26
|
-
interface AgentGenuiOptions {
|
|
27
|
-
/**
|
|
28
|
-
* The catalog. With a {@link GenuiCatalogResolver} it is the boot-time one — it names the
|
|
29
|
-
* per-component tools — and may be empty. Default: an empty catalog.
|
|
30
|
-
*/
|
|
31
|
-
catalog?: Catalog;
|
|
32
|
-
/**
|
|
33
|
-
* `tree` (default): one `ui__render` tool taking a composed tree (a single node is pushed as that
|
|
34
|
-
* component). `per-component`: one `ui__show_<snake>` tool per component.
|
|
35
|
-
*/
|
|
36
|
-
mode?: 'per-component' | 'tree';
|
|
37
|
-
/** `ui__render`'s input schema: `'strict'` (default, a `$defs` union per component) or `'loose'`. */
|
|
38
|
-
treeSchema?: TreeSchemaMode;
|
|
39
|
-
/**
|
|
40
|
-
* Tree mode: `'complete'` (default) draws the tree once the call has run; `'partial'` streams it
|
|
41
|
-
* as `partial` ui frames while the model writes it. A component's own `streaming` overrides it.
|
|
42
|
-
*/
|
|
43
|
-
streaming?: GenuiStreaming;
|
|
44
|
-
/** Least time between two partial tree frames of one call, in ms. Default 100. */
|
|
45
|
-
streamingThrottleMs?: number;
|
|
46
|
-
/** End the model's turn once a genui call succeeds (no narrating follow-up call). */
|
|
47
|
-
terminal?: boolean;
|
|
48
|
-
/** Tool name in `tree` mode. Default `ui__render`. */
|
|
49
|
-
treeToolName?: string;
|
|
50
|
-
/** Text prepended to the tree tool's description. */
|
|
51
|
-
treeInstructions?: string;
|
|
52
|
-
treeLimits?: TreeLimits;
|
|
53
|
-
/**
|
|
54
|
-
* Tree mode: components that ALSO get a flat tool whose input IS their props —
|
|
55
|
-
* `componentTools: ['Sandbox']` adds `ui__sandbox`, so a model writing a big component on its own
|
|
56
|
-
* has no `{ type, props }` envelope to leave out.
|
|
57
|
-
*/
|
|
58
|
-
componentTools?: readonly string[];
|
|
59
|
-
/** Tool-name prefix for `componentTools`. Default `ui__` (`Sandbox` → `ui__sandbox`). */
|
|
60
|
-
componentToolPrefix?: string;
|
|
61
|
-
/** Tool-name prefix in `per-component` mode. Default `ui__show_`. */
|
|
62
|
-
namePrefix?: string;
|
|
63
|
-
/**
|
|
64
|
-
* Also register ONE generic tool taking `{ component, props }`, validated against the request's
|
|
65
|
-
* catalog — how a model reaches a tenant's own components, which no boot-time tool names. `true`
|
|
66
|
-
* names it `ui__show`.
|
|
67
|
-
*/
|
|
68
|
-
showTool?: boolean | string;
|
|
69
|
-
/** Text prepended to the show tool's description. */
|
|
70
|
-
showInstructions?: string;
|
|
71
|
-
/** Roles allowed to call the tools. Undefined → the roles policy default. */
|
|
72
|
-
roles?: string[];
|
|
73
|
-
/** Override the generated presentation per component (or per tree / show tool name). */
|
|
74
|
-
presentation?: (component: string) => ToolPresentation | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* Add the sandbox component (`Sandbox`): the model may write HTML, CSS and JS for a one-off
|
|
77
|
-
* interactive answer when no catalog component fits. `true` for the defaults (no network), or
|
|
78
|
-
* the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.
|
|
79
|
-
* The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared
|
|
80
|
-
* catalog file) so the renderer enforces the same policy.
|
|
81
|
-
*/
|
|
82
|
-
sandbox?: boolean | DefineSandboxOptions;
|
|
83
|
-
}
|
|
84
|
-
type ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;
|
|
85
|
-
interface AgentGenuiModuleOptions extends AgentGenuiOptions {
|
|
86
|
-
/** Per-request catalogs. A class is instantiated with DI (its dependencies must be global or exported to the root). */
|
|
87
|
-
resolver?: ResolverOption;
|
|
88
|
-
}
|
|
89
|
-
interface AgentGenuiModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
90
|
-
inject?: FactoryProvider['inject'];
|
|
91
|
-
useFactory: (...deps: any[]) => AgentGenuiOptions | Promise<AgentGenuiOptions>;
|
|
92
|
-
/** Per-request catalogs. A class resolves its dependencies from `imports`. */
|
|
93
|
-
resolver?: ResolverOption;
|
|
94
|
-
}
|
|
12
|
+
declare const AGENT_GENUI: unique symbol;
|
|
95
13
|
/**
|
|
96
|
-
*
|
|
97
|
-
* (
|
|
98
|
-
* `ui__show`), and makes the catalog
|
|
99
|
-
* injectable. Global, like `AgentModule`; import it once, next to it.
|
|
100
|
-
*
|
|
101
|
-
* ```ts
|
|
102
|
-
* AgentGenuiModule.forRoot({ catalog, mode: 'tree', terminal: true })
|
|
103
|
-
* ```
|
|
14
|
+
* The app's genui setup, bound to {@link AGENT_GENUI}: what a text channel draws with
|
|
15
|
+
* (`catalog`, `channels`, `base`) and what the sandbox renderer is told (`sandboxClient`).
|
|
104
16
|
*/
|
|
105
|
-
declare class
|
|
106
|
-
|
|
107
|
-
|
|
17
|
+
declare class AgentGenui {
|
|
18
|
+
readonly catalog: Catalog;
|
|
19
|
+
readonly resolveCatalog?: ((scope: GenuiCatalogScope) => Catalog | Promise<Catalog>) | undefined;
|
|
20
|
+
/** `AgentGenuiModule.forRoot({ channels })`, when configured. */
|
|
21
|
+
readonly channels?: GenuiChannels | undefined;
|
|
22
|
+
/** The top-level options a channel falls back to. */
|
|
23
|
+
readonly base: GenuiChannelBase;
|
|
24
|
+
/** What the sandbox renderer is told, when a sandbox is configured. */
|
|
25
|
+
readonly sandboxClient?: (() => SandboxClientConfig) | undefined;
|
|
26
|
+
constructor(catalog: Catalog, resolveCatalog?: ((scope: GenuiCatalogScope) => Catalog | Promise<Catalog>) | undefined,
|
|
27
|
+
/** `AgentGenuiModule.forRoot({ channels })`, when configured. */
|
|
28
|
+
channels?: GenuiChannels | undefined,
|
|
29
|
+
/** The top-level options a channel falls back to. */
|
|
30
|
+
base?: GenuiChannelBase,
|
|
31
|
+
/** What the sandbox renderer is told, when a sandbox is configured. */
|
|
32
|
+
sandboxClient?: (() => SandboxClientConfig) | undefined);
|
|
108
33
|
}
|
|
109
34
|
|
|
110
|
-
export {
|
|
35
|
+
export { AGENT_GENUI, AgentGenui };
|
package/dist/genui/index.js
CHANGED
|
@@ -1,8 +1,66 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/vite/index.ts
|
|
13
|
+
import { SANDBOX_KIT_DEV_PREFIX, SANDBOX_KIT_MANIFEST_KEYS, SANDBOX_KIT_UPDATE_EVENT, createGenuiSandboxKitPlugin } from "@dudousxd/nestjs-agent-core/genui/kit";
|
|
14
|
+
var NEST_SANDBOX_KIT_DESCRIPTOR;
|
|
15
|
+
var init_vite = __esm({
|
|
16
|
+
"src/vite/index.ts"() {
|
|
17
|
+
"use strict";
|
|
18
|
+
NEST_SANDBOX_KIT_DESCRIPTOR = ".genui/sandbox-kit.json";
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/genui/kit.ts
|
|
23
|
+
var kit_exports = {};
|
|
24
|
+
__export(kit_exports, {
|
|
25
|
+
NEST_SANDBOX_KIT_MANIFEST: () => NEST_SANDBOX_KIT_MANIFEST,
|
|
26
|
+
nestSandboxKitDiscovery: () => nestSandboxKitDiscovery
|
|
27
|
+
});
|
|
28
|
+
import { resolve } from "path";
|
|
29
|
+
import { sandboxKitDiscovery } from "@dudousxd/nestjs-agent-core/genui/kit";
|
|
30
|
+
function nestSandboxKitDiscovery(options = {}) {
|
|
31
|
+
const manifest = options.manifest ?? NEST_SANDBOX_KIT_MANIFEST;
|
|
32
|
+
return sandboxKitDiscovery({
|
|
33
|
+
root: resolve(options.root ?? process.cwd()),
|
|
34
|
+
descriptor: options.descriptor ?? NEST_SANDBOX_KIT_DESCRIPTOR,
|
|
35
|
+
...manifest !== false ? {
|
|
36
|
+
manifest: {
|
|
37
|
+
file: manifest.file,
|
|
38
|
+
outDir: manifest.outDir
|
|
39
|
+
}
|
|
40
|
+
} : {},
|
|
41
|
+
...options.kitUrl !== void 0 ? {
|
|
42
|
+
kitUrl: options.kitUrl
|
|
43
|
+
} : {},
|
|
44
|
+
...options.production !== void 0 ? {
|
|
45
|
+
production: options.production
|
|
46
|
+
} : {}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
var NEST_SANDBOX_KIT_MANIFEST;
|
|
50
|
+
var init_kit = __esm({
|
|
51
|
+
"src/genui/kit.ts"() {
|
|
52
|
+
"use strict";
|
|
53
|
+
init_vite();
|
|
54
|
+
NEST_SANDBOX_KIT_MANIFEST = Object.freeze({
|
|
55
|
+
file: "public/.vite/manifest.json",
|
|
56
|
+
outDir: "public"
|
|
57
|
+
});
|
|
58
|
+
__name(nestSandboxKitDiscovery, "nestSandboxKitDiscovery");
|
|
59
|
+
}
|
|
60
|
+
});
|
|
3
61
|
|
|
4
62
|
// src/genui/agent-genui.module.ts
|
|
5
|
-
import { defineCatalog, defineSandbox, genuiTools } from "@dudousxd/nestjs-agent-core/genui";
|
|
63
|
+
import { assertGenuiChannels, defineCatalog, defineSandbox, genuiTools, sandboxPolicyOf } from "@dudousxd/nestjs-agent-core/genui";
|
|
6
64
|
import { Inject, Module } from "@nestjs/common";
|
|
7
65
|
|
|
8
66
|
// src/functional-tool.ts
|
|
@@ -25,6 +83,26 @@ function provideAgentTools(factory, inject) {
|
|
|
25
83
|
}
|
|
26
84
|
__name(provideAgentTools, "provideAgentTools");
|
|
27
85
|
|
|
86
|
+
// src/genui/agent-genui.token.ts
|
|
87
|
+
var AGENT_GENUI = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui");
|
|
88
|
+
var AgentGenui = class {
|
|
89
|
+
static {
|
|
90
|
+
__name(this, "AgentGenui");
|
|
91
|
+
}
|
|
92
|
+
catalog;
|
|
93
|
+
resolveCatalog;
|
|
94
|
+
channels;
|
|
95
|
+
base;
|
|
96
|
+
sandboxClient;
|
|
97
|
+
constructor(catalog, resolveCatalog, channels, base = {}, sandboxClient) {
|
|
98
|
+
this.catalog = catalog;
|
|
99
|
+
this.resolveCatalog = resolveCatalog;
|
|
100
|
+
this.channels = channels;
|
|
101
|
+
this.base = base;
|
|
102
|
+
this.sandboxClient = sandboxClient;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
28
106
|
// src/genui/agent-genui.module.ts
|
|
29
107
|
function _ts_decorate(decorators, target, key, desc) {
|
|
30
108
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -42,6 +120,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
42
120
|
__name(_ts_decorate, "_ts_decorate");
|
|
43
121
|
var GENUI_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-catalog");
|
|
44
122
|
var GENUI_OPTIONS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-options");
|
|
123
|
+
var GENUI_RESOLVED = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-resolved");
|
|
45
124
|
var InjectGenuiCatalog = /* @__PURE__ */ __name(() => Inject(GENUI_CATALOG), "InjectGenuiCatalog");
|
|
46
125
|
var GenuiCatalogResolver = class {
|
|
47
126
|
static {
|
|
@@ -61,20 +140,99 @@ function resolverProviders(resolver) {
|
|
|
61
140
|
];
|
|
62
141
|
}
|
|
63
142
|
__name(resolverProviders, "resolverProviders");
|
|
64
|
-
function
|
|
65
|
-
const
|
|
143
|
+
function mergeSandboxClients(clients) {
|
|
144
|
+
const merged = {
|
|
145
|
+
theme: false
|
|
146
|
+
};
|
|
147
|
+
for (const client of clients) {
|
|
148
|
+
const one = client();
|
|
149
|
+
merged.theme ||= one.theme;
|
|
150
|
+
if (one.tailwind !== void 0) merged.tailwind ??= one.tailwind;
|
|
151
|
+
if (one.kit !== void 0) merged.kit ??= one.kit;
|
|
152
|
+
}
|
|
153
|
+
return merged;
|
|
154
|
+
}
|
|
155
|
+
__name(mergeSandboxClients, "mergeSandboxClients");
|
|
156
|
+
async function resolveGenui(options) {
|
|
157
|
+
const { sandbox: asked, channels: askedChannels } = options;
|
|
158
|
+
assertGenuiChannels(askedChannels);
|
|
159
|
+
const clients = [];
|
|
160
|
+
let discovery;
|
|
161
|
+
const resolveSandbox = /* @__PURE__ */ __name(async (value) => {
|
|
162
|
+
if (value === void 0 || value === false) return value;
|
|
163
|
+
const [{ nestSandboxKitDiscovery: nestSandboxKitDiscovery2 }, { resolveSandboxServer }] = await Promise.all([
|
|
164
|
+
Promise.resolve().then(() => (init_kit(), kit_exports)),
|
|
165
|
+
import("@dudousxd/nestjs-agent-core/genui/kit")
|
|
166
|
+
]);
|
|
167
|
+
discovery ??= nestSandboxKitDiscovery2(options.sandboxKit);
|
|
168
|
+
const resolved = resolveSandboxServer(value, discovery);
|
|
169
|
+
clients.push(resolved.client);
|
|
170
|
+
return resolved.define;
|
|
171
|
+
}, "resolveSandbox");
|
|
172
|
+
const sandbox = await resolveSandbox(asked);
|
|
173
|
+
const own = options.catalog?.components.find((each) => sandboxPolicyOf(each) !== void 0);
|
|
174
|
+
const ownOptions = asked === void 0 && own?.sandboxOptions !== void 0 && (own.sandboxView?.kit === true || own.sandboxView?.tailwind === true) ? await resolveSandbox({
|
|
175
|
+
...own.sandboxOptions,
|
|
176
|
+
name: own.name
|
|
177
|
+
}) : void 0;
|
|
178
|
+
let channels;
|
|
179
|
+
if (askedChannels !== void 0) {
|
|
180
|
+
channels = {};
|
|
181
|
+
for (const [name, entry] of Object.entries(askedChannels)) {
|
|
182
|
+
if (entry === void 0) continue;
|
|
183
|
+
const own2 = await resolveSandbox(entry.sandbox);
|
|
184
|
+
channels[name] = {
|
|
185
|
+
...entry,
|
|
186
|
+
...own2 !== void 0 ? {
|
|
187
|
+
sandbox: own2
|
|
188
|
+
} : {}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...sandbox !== void 0 ? {
|
|
194
|
+
sandbox
|
|
195
|
+
} : {},
|
|
196
|
+
...typeof ownOptions === "object" ? {
|
|
197
|
+
catalogSandbox: ownOptions
|
|
198
|
+
} : {},
|
|
199
|
+
...channels !== void 0 ? {
|
|
200
|
+
channels
|
|
201
|
+
} : {},
|
|
202
|
+
...clients.length > 0 ? {
|
|
203
|
+
sandboxClient: /* @__PURE__ */ __name(() => mergeSandboxClients(clients), "sandboxClient")
|
|
204
|
+
} : {}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
__name(resolveGenui, "resolveGenui");
|
|
208
|
+
function perRequest(resolver) {
|
|
209
|
+
return resolver === void 0 ? void 0 : (scope) => resolver.resolve(scope);
|
|
210
|
+
}
|
|
211
|
+
__name(perRequest, "perRequest");
|
|
212
|
+
function toolOptions(options, resolved, resolver) {
|
|
213
|
+
const { catalog: _catalog, sandbox: _sandbox, channels: _channels, sandboxKit: _sandboxKit, ...rest } = options;
|
|
214
|
+
const resolveCatalog = perRequest(resolver);
|
|
66
215
|
return {
|
|
67
216
|
...rest,
|
|
68
|
-
...
|
|
69
|
-
|
|
217
|
+
...resolved.channels !== void 0 ? {
|
|
218
|
+
channels: resolved.channels
|
|
219
|
+
} : {},
|
|
220
|
+
...resolved.sandbox !== void 0 ? {
|
|
221
|
+
sandbox: resolved.sandbox
|
|
222
|
+
} : {},
|
|
223
|
+
...resolveCatalog !== void 0 ? {
|
|
224
|
+
resolveCatalog
|
|
70
225
|
} : {}
|
|
71
226
|
};
|
|
72
227
|
}
|
|
73
228
|
__name(toolOptions, "toolOptions");
|
|
74
|
-
function withSandbox(options) {
|
|
229
|
+
function withSandbox(options, resolved) {
|
|
75
230
|
const base = options.catalog ?? defineCatalog([]);
|
|
76
|
-
const { sandbox } =
|
|
77
|
-
|
|
231
|
+
const { sandbox, catalogSandbox } = resolved;
|
|
232
|
+
if (sandbox === void 0 || sandbox === false) return catalogSandbox !== void 0 ? base.extend([
|
|
233
|
+
defineSandbox(catalogSandbox)
|
|
234
|
+
]) : base;
|
|
235
|
+
return base.extend([
|
|
78
236
|
defineSandbox(sandbox === true ? {} : sandbox)
|
|
79
237
|
]);
|
|
80
238
|
}
|
|
@@ -82,18 +240,50 @@ __name(withSandbox, "withSandbox");
|
|
|
82
240
|
function coreProviders(resolver) {
|
|
83
241
|
return [
|
|
84
242
|
{
|
|
85
|
-
provide:
|
|
86
|
-
useFactory: /* @__PURE__ */ __name((options) =>
|
|
243
|
+
provide: GENUI_RESOLVED,
|
|
244
|
+
useFactory: /* @__PURE__ */ __name((options) => resolveGenui(options), "useFactory"),
|
|
87
245
|
inject: [
|
|
88
246
|
GENUI_OPTIONS
|
|
89
247
|
]
|
|
90
248
|
},
|
|
249
|
+
{
|
|
250
|
+
provide: GENUI_CATALOG,
|
|
251
|
+
useFactory: /* @__PURE__ */ __name((options, resolved) => withSandbox(options, resolved), "useFactory"),
|
|
252
|
+
inject: [
|
|
253
|
+
GENUI_OPTIONS,
|
|
254
|
+
GENUI_RESOLVED
|
|
255
|
+
]
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
provide: AGENT_GENUI,
|
|
259
|
+
useFactory: /* @__PURE__ */ __name((options, catalog, resolved, resolverInstance) => new AgentGenui(catalog, perRequest(resolverInstance), resolved.channels, {
|
|
260
|
+
...options.mode !== void 0 ? {
|
|
261
|
+
mode: options.mode
|
|
262
|
+
} : {},
|
|
263
|
+
...options.streaming !== void 0 ? {
|
|
264
|
+
streaming: options.streaming
|
|
265
|
+
} : {},
|
|
266
|
+
...resolved.sandbox !== void 0 ? {
|
|
267
|
+
sandbox: resolved.sandbox
|
|
268
|
+
} : {}
|
|
269
|
+
}, resolved.sandboxClient), "useFactory"),
|
|
270
|
+
inject: [
|
|
271
|
+
GENUI_OPTIONS,
|
|
272
|
+
GENUI_CATALOG,
|
|
273
|
+
GENUI_RESOLVED,
|
|
274
|
+
{
|
|
275
|
+
token: GenuiCatalogResolver,
|
|
276
|
+
optional: true
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
},
|
|
91
280
|
...resolverProviders(resolver),
|
|
92
281
|
// The generated tools, registered by the agent module's discovery like any `provideAgentTool`.
|
|
93
282
|
// Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.
|
|
94
|
-
provideAgentTools((options, catalog,
|
|
283
|
+
provideAgentTools((options, catalog, resolved, perRequestResolver) => genuiTools(catalog, toolOptions(options, resolved, perRequestResolver)), [
|
|
95
284
|
GENUI_OPTIONS,
|
|
96
285
|
GENUI_CATALOG,
|
|
286
|
+
GENUI_RESOLVED,
|
|
97
287
|
{
|
|
98
288
|
token: GenuiCatalogResolver,
|
|
99
289
|
optional: true
|
|
@@ -104,7 +294,8 @@ function coreProviders(resolver) {
|
|
|
104
294
|
__name(coreProviders, "coreProviders");
|
|
105
295
|
var EXPORTS = [
|
|
106
296
|
GENUI_CATALOG,
|
|
107
|
-
GENUI_OPTIONS
|
|
297
|
+
GENUI_OPTIONS,
|
|
298
|
+
AGENT_GENUI
|
|
108
299
|
];
|
|
109
300
|
var AgentGenuiModule = class _AgentGenuiModule {
|
|
110
301
|
static {
|
|
@@ -155,6 +346,8 @@ AgentGenuiModule = _ts_decorate([
|
|
|
155
346
|
// src/genui/index.ts
|
|
156
347
|
export * from "@dudousxd/nestjs-agent-core/genui";
|
|
157
348
|
export {
|
|
349
|
+
AGENT_GENUI,
|
|
350
|
+
AgentGenui,
|
|
158
351
|
AgentGenuiModule,
|
|
159
352
|
GENUI_CATALOG,
|
|
160
353
|
GENUI_OPTIONS,
|
package/dist/genui/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/genui/agent-genui.module.ts","../../src/functional-tool.ts","../../src/genui/index.ts"],"sourcesContent":["import type { ToolPresentation } from '@dudousxd/nestjs-agent-core';\nimport type {\n Catalog,\n GenuiCatalogScope,\n GenuiStreaming,\n GenuiToolsOptions,\n TreeLimits,\n TreeSchemaMode,\n} from '@dudousxd/nestjs-agent-core/genui';\nimport {\n type DefineSandboxOptions,\n defineCatalog,\n defineSandbox,\n genuiTools,\n} from '@dudousxd/nestjs-agent-core/genui';\nimport {\n type DynamicModule,\n type FactoryProvider,\n Inject,\n Module,\n type ModuleMetadata,\n type Provider,\n type Type,\n} from '@nestjs/common';\nimport { provideAgentTools } from '../functional-tool.js';\n\n/** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */\nexport const GENUI_CATALOG = Symbol.for('@dudousxd/nestjs-agent:genui-catalog');\n\n/** The resolved {@link AgentGenuiOptions} (without the resolver). */\nexport const GENUI_OPTIONS = Symbol.for('@dudousxd/nestjs-agent:genui-options');\n\n/** Inject the app's genui catalog ({@link GENUI_CATALOG}). */\nexport const InjectGenuiCatalog = (): ParameterDecorator & PropertyDecorator =>\n Inject(GENUI_CATALOG);\n\n/**\n * Picks the catalog for ONE request — a tenant's own, versioned components. Consulted when a genui\n * call is validated and when the turn's tool list is described to the model, so components can\n * change without rebuilding tools at boot. Cache in here if resolving costs a round trip: it runs\n * once per turn per genui tool, and once per call.\n *\n * Provide it through `AgentGenuiModule.forRoot({ resolver })` (a class, resolved with DI, or an\n * instance); it is then injectable, and replaceable in a test with\n * `overrideProvider(GenuiCatalogResolver)`.\n */\nexport abstract class GenuiCatalogResolver {\n abstract resolve(scope: GenuiCatalogScope): Catalog | Promise<Catalog>;\n}\n\n/** What {@link AgentGenuiModule} builds tools from. */\nexport interface AgentGenuiOptions {\n /**\n * The catalog. With a {@link GenuiCatalogResolver} it is the boot-time one — it names the\n * per-component tools — and may be empty. Default: an empty catalog.\n */\n catalog?: Catalog;\n /**\n * `tree` (default): one `ui__render` tool taking a composed tree (a single node is pushed as that\n * component). `per-component`: one `ui__show_<snake>` tool per component.\n */\n mode?: 'per-component' | 'tree';\n /** `ui__render`'s input schema: `'strict'` (default, a `$defs` union per component) or `'loose'`. */\n treeSchema?: TreeSchemaMode;\n /**\n * Tree mode: `'complete'` (default) draws the tree once the call has run; `'partial'` streams it\n * as `partial` ui frames while the model writes it. A component's own `streaming` overrides it.\n */\n streaming?: GenuiStreaming;\n /** Least time between two partial tree frames of one call, in ms. Default 100. */\n streamingThrottleMs?: number;\n /** End the model's turn once a genui call succeeds (no narrating follow-up call). */\n terminal?: boolean;\n /** Tool name in `tree` mode. Default `ui__render`. */\n treeToolName?: string;\n /** Text prepended to the tree tool's description. */\n treeInstructions?: string;\n treeLimits?: TreeLimits;\n /**\n * Tree mode: components that ALSO get a flat tool whose input IS their props —\n * `componentTools: ['Sandbox']` adds `ui__sandbox`, so a model writing a big component on its own\n * has no `{ type, props }` envelope to leave out.\n */\n componentTools?: readonly string[];\n /** Tool-name prefix for `componentTools`. Default `ui__` (`Sandbox` → `ui__sandbox`). */\n componentToolPrefix?: string;\n /** Tool-name prefix in `per-component` mode. Default `ui__show_`. */\n namePrefix?: string;\n /**\n * Also register ONE generic tool taking `{ component, props }`, validated against the request's\n * catalog — how a model reaches a tenant's own components, which no boot-time tool names. `true`\n * names it `ui__show`.\n */\n showTool?: boolean | string;\n /** Text prepended to the show tool's description. */\n showInstructions?: string;\n /** Roles allowed to call the tools. Undefined → the roles policy default. */\n roles?: string[];\n /** Override the generated presentation per component (or per tree / show tool name). */\n presentation?: (component: string) => ToolPresentation | undefined;\n /**\n * Add the sandbox component (`Sandbox`): the model may write HTML, CSS and JS for a one-off\n * interactive answer when no catalog component fits. `true` for the defaults (no network), or\n * the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.\n * The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared\n * catalog file) so the renderer enforces the same policy.\n */\n sandbox?: boolean | DefineSandboxOptions;\n}\n\ntype ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;\n\nexport interface AgentGenuiModuleOptions extends AgentGenuiOptions {\n /** Per-request catalogs. A class is instantiated with DI (its dependencies must be global or exported to the root). */\n resolver?: ResolverOption;\n}\n\nexport interface AgentGenuiModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {\n inject?: FactoryProvider['inject'];\n useFactory: (...deps: any[]) => AgentGenuiOptions | Promise<AgentGenuiOptions>;\n /** Per-request catalogs. A class resolves its dependencies from `imports`. */\n resolver?: ResolverOption;\n}\n\nfunction resolverProviders(resolver: ResolverOption | undefined): Provider[] {\n if (resolver === undefined) return [];\n return [\n typeof resolver === 'function'\n ? { provide: GenuiCatalogResolver, useClass: resolver }\n : { provide: GenuiCatalogResolver, useValue: resolver },\n ];\n}\n\nfunction toolOptions(\n options: AgentGenuiOptions,\n resolver: GenuiCatalogResolver | undefined,\n): GenuiToolsOptions {\n const { catalog: _catalog, sandbox: _sandbox, ...rest } = options;\n return {\n ...rest,\n ...(resolver !== undefined\n ? { resolveCatalog: (scope: GenuiCatalogScope) => resolver.resolve(scope) }\n : {}),\n };\n}\n\n/** The configured catalog, with the sandbox component added when `sandbox` asks for it. */\nfunction withSandbox(options: AgentGenuiOptions): Catalog {\n const base = options.catalog ?? defineCatalog([]);\n const { sandbox } = options;\n return sandbox === undefined || sandbox === false\n ? base\n : base.extend([defineSandbox(sandbox === true ? {} : sandbox)]);\n}\n\nfunction coreProviders(resolver: ResolverOption | undefined): Provider[] {\n return [\n {\n provide: GENUI_CATALOG,\n useFactory: (options: AgentGenuiOptions) => withSandbox(options),\n inject: [GENUI_OPTIONS],\n },\n ...resolverProviders(resolver),\n // The generated tools, registered by the agent module's discovery like any `provideAgentTool`.\n // Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.\n provideAgentTools(\n (options: AgentGenuiOptions, catalog: Catalog, perRequest?: GenuiCatalogResolver) =>\n genuiTools(catalog, toolOptions(options, perRequest)),\n [GENUI_OPTIONS, GENUI_CATALOG, { token: GenuiCatalogResolver, optional: true }],\n ),\n ];\n}\n\nconst EXPORTS = [GENUI_CATALOG, GENUI_OPTIONS];\n\n/**\n * Generative UI for the agent: registers the tools that let the model push catalog components\n * (one `ui__render` tree tool, or `ui__show_<component>` per component, and/or the generic\n * `ui__show`), and makes the catalog\n * injectable. Global, like `AgentModule`; import it once, next to it.\n *\n * ```ts\n * AgentGenuiModule.forRoot({ catalog, mode: 'tree', terminal: true })\n * ```\n */\n@Module({})\nexport class AgentGenuiModule {\n static forRoot(options: AgentGenuiModuleOptions = {}): DynamicModule {\n const { resolver, ...rest } = options;\n return {\n module: AgentGenuiModule,\n global: true,\n providers: [{ provide: GENUI_OPTIONS, useValue: rest }, ...coreProviders(resolver)],\n exports: resolver === undefined ? EXPORTS : [...EXPORTS, GenuiCatalogResolver],\n };\n }\n\n static forRootAsync(options: AgentGenuiModuleAsyncOptions): DynamicModule {\n return {\n module: AgentGenuiModule,\n global: true,\n imports: options.imports ?? [],\n providers: [\n { provide: GENUI_OPTIONS, useFactory: options.useFactory, inject: options.inject ?? [] },\n ...coreProviders(options.resolver),\n ],\n exports: options.resolver === undefined ? EXPORTS : [...EXPORTS, GenuiCatalogResolver],\n };\n }\n}\n","import {\n type FunctionalToolDefinition,\n type ToolHandler,\n type ToolSpec,\n createFunctionalTool,\n} from '@dudousxd/nestjs-agent-core';\nimport type { FactoryProvider, Provider } from '@nestjs/common';\n\n/**\n * Brand stamped onto a functional-tool provider instance so `AiToolDiscoveryService` picks it up\n * when it walks every provider at boot — the declarative alternative to a manual `registry.register`.\n */\nexport const AGENT_TOOL_BRAND = Symbol.for('@dudousxd/nestjs-agent:functional-tool');\n\n/** A tool expressed as data + handler (e.g. from `createExecuteSqlTool`), not an `@AiTool` class. */\nexport interface FunctionalTool {\n spec: ToolSpec;\n handler: ToolHandler;\n}\n\n/** A {@link FunctionalTool} carrying {@link AGENT_TOOL_BRAND} — what a provider resolves to. */\nexport interface BrandedFunctionalTool extends FunctionalTool {\n readonly [AGENT_TOOL_BRAND]: true;\n}\n\nfunction brand(tool: FunctionalTool): BrandedFunctionalTool {\n return { [AGENT_TOOL_BRAND]: true, spec: tool.spec, handler: tool.handler };\n}\n\n/** Narrows a provider instance to a branded functional tool for boot-time registration. */\nexport function isBrandedFunctionalTool(value: object): value is BrandedFunctionalTool {\n return AGENT_TOOL_BRAND in value && 'spec' in value && 'handler' in value;\n}\n\n/**\n * Registers a functional tool declaratively — drop the returned provider in a module's `providers`\n * and `AiToolDiscoveryService` auto-registers it at boot. Each call uses a fresh, unique provide\n * token so the same tool can be provided many times without collisions.\n *\n * Two forms: a static tool (`useValue`) or a factory with `inject` for DI-resolved dependencies\n * (`useFactory`). Either way the resolved instance is branded with {@link AGENT_TOOL_BRAND}.\n */\nexport function provideAgentTool(tool: FunctionalTool): Provider;\nexport function provideAgentTool(\n factory: (...deps: never[]) => FunctionalTool,\n inject?: FactoryProvider['inject'],\n): Provider;\nexport function provideAgentTool(\n factoryOrTool: FunctionalTool | ((...deps: never[]) => FunctionalTool),\n inject?: FactoryProvider['inject'],\n): Provider {\n const provide = Symbol('nestjs-agent:functional-tool-instance');\n if (typeof factoryOrTool === 'function') {\n return {\n provide,\n useFactory: (...deps: never[]) => brand(factoryOrTool(...deps)),\n inject: inject ?? [],\n };\n }\n return { provide, useValue: brand(factoryOrTool) };\n}\n\n/**\n * Registers a LIST of functional tools from one factory — for a producer whose tool count is only\n * known once its dependencies resolve (a catalog loaded from config, one tool per entry). The\n * factory's result is branded element by element; `AiToolDiscoveryService` registers each.\n */\nexport function provideAgentTools(\n factory: (...deps: never[]) => readonly FunctionalTool[] | Promise<readonly FunctionalTool[]>,\n inject?: FactoryProvider['inject'],\n): Provider {\n return {\n provide: Symbol('nestjs-agent:functional-tool-list'),\n useFactory: async (...deps: never[]) => (await factory(...deps)).map(brand),\n inject: inject ?? [],\n };\n}\n\n/** Author a functional tool with inferred Standard Schema input and domain output. */\nexport const defineTool = createFunctionalTool;\nexport type { FunctionalToolDefinition };\n","/**\n * `@dudousxd/nestjs-agent/genui` — generative UI for NestJS: {@link AgentGenuiModule} registers the\n * tools that push catalog components, `GENUI_CATALOG` / `@InjectGenuiCatalog()` expose the catalog,\n * and {@link GenuiCatalogResolver} serves per-request (per-tenant) catalogs. The catalog itself —\n * `defineComponent`, `defineCatalog`, validation, text fallbacks — is re-exported from\n * `@dudousxd/nestjs-agent-core/genui`, the isomorphic entry a browser imports too.\n */\nexport {\n AgentGenuiModule,\n type AgentGenuiModuleAsyncOptions,\n type AgentGenuiModuleOptions,\n type AgentGenuiOptions,\n GENUI_CATALOG,\n GENUI_OPTIONS,\n GenuiCatalogResolver,\n InjectGenuiCatalog,\n} from './agent-genui.module.js';\nexport * from '@dudousxd/nestjs-agent-core/genui';\n"],"mappings":";;;;AASA,SAEEA,eACAC,eACAC,kBACK;AACP,SAGEC,QACAC,cAIK;;;ACvBP,SAIEC,4BACK;AAOA,IAAMC,mBAAmBC,uBAAOC,IAAI,wCAAA;AAa3C,SAASC,MAAMC,MAAoB;AACjC,SAAO;IAAE,CAACJ,gBAAAA,GAAmB;IAAMK,MAAMD,KAAKC;IAAMC,SAASF,KAAKE;EAAQ;AAC5E;AAFSH;AA0CF,SAASI,kBACdC,SACAC,QAAkC;AAElC,SAAO;IACLC,SAASC,uBAAO,mCAAA;IAChBC,YAAY,iCAAUC,UAAmB,MAAML,QAAAA,GAAWK,IAAAA,GAAOC,IAAIC,KAAAA,GAAzD;IACZN,QAAQA,UAAU,CAAA;EACpB;AACF;AATgBF;;;;;;;;;;;;;;;;;ADxCT,IAAMS,gBAAgBC,uBAAOC,IAAI,sCAAA;AAGjC,IAAMC,gBAAgBF,uBAAOC,IAAI,sCAAA;AAGjC,IAAME,qBAAqB,6BAChCC,OAAOL,aAAAA,GADyB;AAa3B,IAAeM,uBAAf,MAAeA;SAAAA;;;AAEtB;AA4EA,SAASC,kBAAkBC,UAAoC;AAC7D,MAAIA,aAAaC,OAAW,QAAO,CAAA;AACnC,SAAO;IACL,OA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SAASlC,aAAaC,SAAY2B,UAAU;WAAIA;QAAS9B;;IAC3D;EACF;EAEA,OAAOqC,aAAa7B,SAAsD;AACxE,WAAO;MACLyB,QAAQF;MACRG,QAAQ;MACRI,SAAS9B,QAAQ8B,WAAW,CAAA;MAC5BH,WAAW;QACT;UAAE/B,SAASP;UAAe0B,YAAYf,QAAQe;UAAYC,QAAQhB,QAAQgB,UAAU,CAAA;QAAG;WACpFF,cAAcd,QAAQN,QAAQ;;MAEnCkC,SAAS5B,QAAQN,aAAaC,SAAY2B,UAAU;WAAIA;QAAS9B;;IACnE;EACF;AACF;;;;;;AEhMA,cAAc;","names":["defineCatalog","defineSandbox","genuiTools","Inject","Module","createFunctionalTool","AGENT_TOOL_BRAND","Symbol","for","brand","tool","spec","handler","provideAgentTools","factory","inject","provide","Symbol","useFactory","deps","map","brand","GENUI_CATALOG","Symbol","for","GENUI_OPTIONS","InjectGenuiCatalog","Inject","GenuiCatalogResolver","resolverProviders","resolver","undefined","provide","useClass","useValue","toolOptions","options","catalog","_catalog","sandbox","_sandbox","rest","resolveCatalog","scope","resolve","withSandbox","base","defineCatalog","extend","defineSandbox","coreProviders","useFactory","inject","provideAgentTools","perRequest","genuiTools","token","optional","EXPORTS","AgentGenuiModule","forRoot","module","global","providers","exports","forRootAsync","imports"]}
|
|
1
|
+
{"version":3,"sources":["../../src/vite/index.ts","../../src/genui/kit.ts","../../src/genui/agent-genui.module.ts","../../src/functional-tool.ts","../../src/genui/agent-genui.token.ts","../../src/genui/index.ts"],"sourcesContent":["/**\n * `@dudousxd/nestjs-agent/vite` — `genuiSandboxKit()`, the Vite plugin that puts the app's design\n * system (its components, its theme, Tailwind) inside the sandbox:\n *\n * ```ts\n * // vite.config.ts (the SPA that talks to the agent)\n * import { genuiSandboxKit } from '@dudousxd/nestjs-agent/vite'\n * export default defineConfig({ plugins: [react(), genuiSandboxKit({ include: 'src/components/ui/*.tsx' })] })\n * ```\n *\n * Then `AgentGenuiModule.forRoot({ sandbox: { kit: true, tailwind: true } })` finds the bundle and\n * the docs: the descriptor the dev server writes (`.genui/sandbox-kit.json`) in dev, the Vite\n * manifest in production (see `AgentGenuiOptions.sandboxKit`).\n */\nimport {\n type GenuiSandboxKitApi,\n type GenuiSandboxKitOptions,\n type GenuiSandboxKitPlugin,\n SANDBOX_KIT_DEV_PREFIX,\n SANDBOX_KIT_MANIFEST_KEYS,\n SANDBOX_KIT_UPDATE_EVENT,\n createGenuiSandboxKitPlugin,\n} from '@dudousxd/nestjs-agent-core/genui/kit';\n\n/**\n * Where the dev descriptor is written, relative to the Vite root — and where the server reads it,\n * relative to its working directory (run both from the project root, or point\n * `sandboxKit.descriptor` at it). Add `.genui/` to `.gitignore`.\n */\nexport const NEST_SANDBOX_KIT_DESCRIPTOR = '.genui/sandbox-kit.json';\n\n/**\n * The sandbox kit plugin. `entry` (a module exporting the kit) or `include` (a glob of component\n * files); neither → the first `components/ui` folder (`src/components/ui`…). See\n * {@link GenuiSandboxKitOptions}.\n */\nexport function genuiSandboxKit(options: GenuiSandboxKitOptions = {}): GenuiSandboxKitPlugin {\n return createGenuiSandboxKitPlugin(options, {\n descriptor: NEST_SANDBOX_KIT_DESCRIPTOR,\n rendererImport: /@dudousxd\\/nestjs-agent-react/,\n });\n}\n\nexport {\n type GenuiSandboxKitApi,\n type GenuiSandboxKitOptions,\n type GenuiSandboxKitPlugin,\n SANDBOX_KIT_DEV_PREFIX,\n SANDBOX_KIT_MANIFEST_KEYS,\n SANDBOX_KIT_UPDATE_EVENT,\n};\n","/**\n * The sandbox kit in a Nest app. No Vite runs in the Nest process, so the kit is found in files:\n * the descriptor `genuiSandboxKit()` (`@dudousxd/nestjs-agent/vite`) writes while the dev server\n * runs, and in production the Vite manifest the build wrote (`genui-sandbox-kit.json` and the assets\n * it names). Node-only: loaded by {@link AgentGenuiModule} only when a sandbox is configured.\n */\nimport { resolve } from 'node:path';\nimport {\n type SandboxKitDiscovery,\n sandboxKitDiscovery,\n} from '@dudousxd/nestjs-agent-core/genui/kit';\nimport { NEST_SANDBOX_KIT_DESCRIPTOR } from '../vite/index.js';\nimport type { AgentGenuiSandboxKitOptions } from './agent-genui.module.js';\n\n/** Where the production Vite manifest is looked for by default, and the directory it is relative to. */\nexport const NEST_SANDBOX_KIT_MANIFEST = Object.freeze({\n file: 'public/.vite/manifest.json',\n outDir: 'public',\n});\n\n/** Find the kit for `AgentGenuiModule.forRoot({ sandbox: { kit: true } })`. */\nexport function nestSandboxKitDiscovery(\n options: AgentGenuiSandboxKitOptions = {},\n): SandboxKitDiscovery {\n const manifest = options.manifest ?? NEST_SANDBOX_KIT_MANIFEST;\n return sandboxKitDiscovery({\n root: resolve(options.root ?? process.cwd()),\n descriptor: options.descriptor ?? NEST_SANDBOX_KIT_DESCRIPTOR,\n ...(manifest !== false ? { manifest: { file: manifest.file, outDir: manifest.outDir } } : {}),\n ...(options.kitUrl !== undefined ? { kitUrl: options.kitUrl } : {}),\n ...(options.production !== undefined ? { production: options.production } : {}),\n });\n}\n","import type { ToolPresentation } from '@dudousxd/nestjs-agent-core';\nimport type {\n Catalog,\n GenuiCatalogScope,\n GenuiChannels,\n GenuiStreaming,\n GenuiToolsOptions,\n SandboxClientConfig,\n TreeLimits,\n TreeSchemaMode,\n} from '@dudousxd/nestjs-agent-core/genui';\nimport {\n type DefineSandboxOptions,\n type SandboxDefinition,\n assertGenuiChannels,\n defineCatalog,\n defineSandbox,\n genuiTools,\n sandboxPolicyOf,\n} from '@dudousxd/nestjs-agent-core/genui';\nimport {\n type DynamicModule,\n type FactoryProvider,\n Inject,\n Module,\n type ModuleMetadata,\n type Provider,\n type Type,\n} from '@nestjs/common';\nimport { provideAgentTools } from '../functional-tool.js';\nimport { AGENT_GENUI, AgentGenui } from './agent-genui.token.js';\n\nexport { AGENT_GENUI, AgentGenui } from './agent-genui.token.js';\n\n/** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */\nexport const GENUI_CATALOG = Symbol.for('@dudousxd/nestjs-agent:genui-catalog');\n\n/** The resolved {@link AgentGenuiOptions} (without the resolver). */\nexport const GENUI_OPTIONS = Symbol.for('@dudousxd/nestjs-agent:genui-options');\n\n/** The sandbox and channels as boot resolved them (kit, Tailwind and theme found). Internal. */\nconst GENUI_RESOLVED = Symbol.for('@dudousxd/nestjs-agent:genui-resolved');\n\n/** Inject the app's genui catalog ({@link GENUI_CATALOG}). */\nexport const InjectGenuiCatalog = (): ParameterDecorator & PropertyDecorator =>\n Inject(GENUI_CATALOG);\n\n/**\n * Picks the catalog for ONE request — a tenant's own, versioned components. Consulted when a genui\n * call is validated and when the turn's tool list is described to the model, so components can\n * change without rebuilding tools at boot. Cache in here if resolving costs a round trip: it runs\n * once per turn per genui tool, and once per call.\n *\n * Provide it through `AgentGenuiModule.forRoot({ resolver })` (a class, resolved with DI, or an\n * instance); it is then injectable, and replaceable in a test with\n * `overrideProvider(GenuiCatalogResolver)`.\n */\nexport abstract class GenuiCatalogResolver {\n abstract resolve(scope: GenuiCatalogScope): Catalog | Promise<Catalog>;\n}\n\n/** What {@link AgentGenuiModule} builds tools from. */\nexport interface AgentGenuiOptions {\n /**\n * The catalog. With a {@link GenuiCatalogResolver} it is the boot-time one — it names the\n * per-component tools — and may be empty. Default: an empty catalog.\n */\n catalog?: Catalog;\n /**\n * `tree` (default): one `ui__render` tool taking a composed tree (a single node is pushed as that\n * component). `per-component`: one `ui__show_<snake>` tool per component.\n */\n mode?: 'per-component' | 'tree';\n /** `ui__render`'s input schema: `'strict'` (default, a `$defs` union per component) or `'loose'`. */\n treeSchema?: TreeSchemaMode;\n /**\n * Tree mode: `'complete'` (default) draws the tree once the call has run; `'partial'` streams it\n * as `partial` ui frames while the model writes it. A component's own `streaming` overrides it.\n */\n streaming?: GenuiStreaming;\n /** Least time between two partial tree frames of one call, in ms. Default 100. */\n streamingThrottleMs?: number;\n /** End the model's turn once a genui call succeeds (no narrating follow-up call). */\n terminal?: boolean;\n /** Tool name in `tree` mode. Default `ui__render`. */\n treeToolName?: string;\n /** Text prepended to the tree tool's description. */\n treeInstructions?: string;\n treeLimits?: TreeLimits;\n /**\n * Tree mode: components that ALSO get a flat tool whose input IS their props —\n * `componentTools: ['Sandbox']` adds `ui__sandbox`, so a model writing a big component on its own\n * has no `{ type, props }` envelope to leave out.\n */\n componentTools?: readonly string[];\n /** Tool-name prefix for `componentTools`. Default `ui__` (`Sandbox` → `ui__sandbox`). */\n componentToolPrefix?: string;\n /** Tool-name prefix in `per-component` mode. Default `ui__show_`. */\n namePrefix?: string;\n /**\n * Also register ONE generic tool taking `{ component, props }`, validated against the request's\n * catalog — how a model reaches a tenant's own components, which no boot-time tool names. `true`\n * names it `ui__show`.\n */\n showTool?: boolean | string;\n /** Text prepended to the show tool's description. */\n showInstructions?: string;\n /** Roles allowed to call the tools. Undefined → the roles policy default. */\n roles?: string[];\n /** Override the generated presentation per component (or per tree / show tool name). */\n presentation?: (component: string) => ToolPresentation | undefined;\n /**\n * Add the sandbox component (`Sandbox`): the model may write HTML, CSS and JS for a one-off\n * interactive answer when no catalog component fits. `true` for the defaults (no network), or\n * the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.\n * The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared\n * catalog file) so the renderer enforces the same policy.\n *\n * `theme` (default on), `tailwind` and `kit` put the app's design system in the frame. `kit: true`\n * (and the theme's variable names) are found through `sandboxKit`: the descriptor\n * `genuiSandboxKit()` (`@dudousxd/nestjs-agent/vite`) writes in dev, the Vite manifest in\n * production — and `GET <base>/config` tells the renderer where the assets are.\n */\n sandbox?: boolean | DefineSandboxOptions;\n /**\n * Per-channel generative UI: each entry sets the mode, streaming, sandbox and rendering of one\n * channel (`web`, `mobile`, `whatsapp`, `telegram`, `email`, or `default` for the rest), over the\n * top-level options. A text channel (`@dudousxd/nestjs-agent-channels`) configured here draws the\n * components natively (reply buttons, lists, images). Omitted → every channel is served by the\n * top-level options, as before.\n */\n channels?: GenuiChannels;\n /**\n * Where the sandbox kit is found (with `sandbox: { kit: true }`, `tailwind: true` or the theme's\n * names). No Vite runs in the Nest process, so: the descriptor the dev plugin writes, else the\n * production Vite manifest (read first when `NODE_ENV=production`).\n */\n sandboxKit?: AgentGenuiSandboxKitOptions;\n}\n\n/** {@link AgentGenuiOptions.sandboxKit}. Relative paths resolve against `root`. */\nexport interface AgentGenuiSandboxKitOptions {\n /** Default `process.cwd()`. */\n root?: string;\n /** The dev descriptor `genuiSandboxKit()` writes. Default `.genui/sandbox-kit.json`. */\n descriptor?: string;\n /**\n * The production Vite manifest, and the directory its `file`s are relative to. Default\n * `{ file: 'public/.vite/manifest.json', outDir: 'public' }`; `false` → none.\n */\n manifest?: { file: string; outDir: string } | false;\n /** An explicit kit url (an SPA served from elsewhere), over what is found. */\n kitUrl?: string;\n /** Read the manifest first. Default: `NODE_ENV === 'production'`. */\n production?: boolean;\n}\n\ntype ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;\n\nexport interface AgentGenuiModuleOptions extends AgentGenuiOptions {\n /** Per-request catalogs. A class is instantiated with DI (its dependencies must be global or exported to the root). */\n resolver?: ResolverOption;\n}\n\nexport interface AgentGenuiModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {\n inject?: FactoryProvider['inject'];\n useFactory: (...deps: any[]) => AgentGenuiOptions | Promise<AgentGenuiOptions>;\n /** Per-request catalogs. A class resolves its dependencies from `imports`. */\n resolver?: ResolverOption;\n}\n\nfunction resolverProviders(resolver: ResolverOption | undefined): Provider[] {\n if (resolver === undefined) return [];\n return [\n typeof resolver === 'function'\n ? { provide: GenuiCatalogResolver, useClass: resolver }\n : { provide: GenuiCatalogResolver, useValue: resolver },\n ];\n}\n\n/** The sandbox and channels with the kit, Tailwind and theme names found ({@link GENUI_RESOLVED}). */\ninterface ResolvedGenui {\n sandbox?: boolean | DefineSandboxOptions;\n /** A kit or Tailwind sandbox the catalog itself defines, resolved (under its own name). */\n catalogSandbox?: DefineSandboxOptions;\n channels?: GenuiChannels;\n sandboxClient?: () => SandboxClientConfig;\n}\n\n/** What every configured sandbox (top level and channels) needs from the browser, together. */\nfunction mergeSandboxClients(clients: Array<() => SandboxClientConfig>): SandboxClientConfig {\n const merged: SandboxClientConfig = { theme: false };\n for (const client of clients) {\n const one = client();\n merged.theme ||= one.theme;\n if (one.tailwind !== undefined) merged.tailwind ??= one.tailwind;\n if (one.kit !== undefined) merged.kit ??= one.kit;\n }\n return merged;\n}\n\n/** Resolve the sandbox (top level and per channel) against the kit discovery. */\nasync function resolveGenui(options: AgentGenuiOptions): Promise<ResolvedGenui> {\n const { sandbox: asked, channels: askedChannels } = options;\n assertGenuiChannels(askedChannels);\n // A sandbox's kit, Tailwind and theme names are found through the app's Vite output.\n const clients: Array<() => SandboxClientConfig> = [];\n let discovery: import('@dudousxd/nestjs-agent-core/genui/kit').SandboxKitDiscovery | undefined;\n const resolveSandbox = async (\n value: boolean | DefineSandboxOptions | undefined,\n ): Promise<boolean | DefineSandboxOptions | undefined> => {\n if (value === undefined || value === false) return value;\n // Node-only, and only with a sandbox: loaded when one is configured.\n const [{ nestSandboxKitDiscovery }, { resolveSandboxServer }] = await Promise.all([\n import('./kit.js'),\n import('@dudousxd/nestjs-agent-core/genui/kit'),\n ]);\n discovery ??= nestSandboxKitDiscovery(options.sandboxKit);\n const resolved = resolveSandboxServer(value, discovery);\n clients.push(resolved.client);\n return resolved.define;\n };\n const sandbox = await resolveSandbox(asked);\n // A kit or Tailwind sandbox defined in the (shared) catalog itself: found the same way, and put\n // back under its own name, so the browser's copy of the catalog validates what the model writes.\n const own = options.catalog?.components.find((each) => sandboxPolicyOf(each) !== undefined) as\n | SandboxDefinition\n | undefined;\n const ownOptions =\n asked === undefined &&\n own?.sandboxOptions !== undefined &&\n (own.sandboxView?.kit === true || own.sandboxView?.tailwind === true)\n ? await resolveSandbox({ ...own.sandboxOptions, name: own.name })\n : undefined;\n let channels: GenuiChannels | undefined;\n if (askedChannels !== undefined) {\n channels = {};\n for (const [name, entry] of Object.entries(askedChannels)) {\n if (entry === undefined) continue;\n const own = await resolveSandbox(entry.sandbox);\n channels[name] = { ...entry, ...(own !== undefined ? { sandbox: own } : {}) };\n }\n }\n return {\n ...(sandbox !== undefined ? { sandbox } : {}),\n ...(typeof ownOptions === 'object' ? { catalogSandbox: ownOptions } : {}),\n ...(channels !== undefined ? { channels } : {}),\n ...(clients.length > 0 ? { sandboxClient: () => mergeSandboxClients(clients) } : {}),\n };\n}\n\nfunction perRequest(\n resolver: GenuiCatalogResolver | undefined,\n): GenuiToolsOptions['resolveCatalog'] | undefined {\n return resolver === undefined ? undefined : (scope: GenuiCatalogScope) => resolver.resolve(scope);\n}\n\nfunction toolOptions(\n options: AgentGenuiOptions,\n resolved: ResolvedGenui,\n resolver: GenuiCatalogResolver | undefined,\n): GenuiToolsOptions {\n const {\n catalog: _catalog,\n sandbox: _sandbox,\n channels: _channels,\n sandboxKit: _sandboxKit,\n ...rest\n } = options;\n const resolveCatalog = perRequest(resolver);\n return {\n ...rest,\n ...(resolved.channels !== undefined ? { channels: resolved.channels } : {}),\n ...(resolved.sandbox !== undefined ? { sandbox: resolved.sandbox } : {}),\n ...(resolveCatalog !== undefined ? { resolveCatalog } : {}),\n };\n}\n\n/** The configured catalog, with the sandbox component added when `sandbox` asks for it. */\nfunction withSandbox(options: AgentGenuiOptions, resolved: ResolvedGenui): Catalog {\n const base = options.catalog ?? defineCatalog([]);\n const { sandbox, catalogSandbox } = resolved;\n if (sandbox === undefined || sandbox === false)\n return catalogSandbox !== undefined ? base.extend([defineSandbox(catalogSandbox)]) : base;\n return base.extend([defineSandbox(sandbox === true ? {} : sandbox)]);\n}\n\nfunction coreProviders(resolver: ResolverOption | undefined): Provider[] {\n return [\n {\n provide: GENUI_RESOLVED,\n useFactory: (options: AgentGenuiOptions) => resolveGenui(options),\n inject: [GENUI_OPTIONS],\n },\n {\n provide: GENUI_CATALOG,\n useFactory: (options: AgentGenuiOptions, resolved: ResolvedGenui) =>\n withSandbox(options, resolved),\n inject: [GENUI_OPTIONS, GENUI_RESOLVED],\n },\n {\n provide: AGENT_GENUI,\n useFactory: (\n options: AgentGenuiOptions,\n catalog: Catalog,\n resolved: ResolvedGenui,\n resolverInstance?: GenuiCatalogResolver,\n ) =>\n new AgentGenui(\n catalog,\n perRequest(resolverInstance),\n resolved.channels,\n {\n ...(options.mode !== undefined ? { mode: options.mode } : {}),\n ...(options.streaming !== undefined ? { streaming: options.streaming } : {}),\n ...(resolved.sandbox !== undefined ? { sandbox: resolved.sandbox } : {}),\n },\n resolved.sandboxClient,\n ),\n inject: [\n GENUI_OPTIONS,\n GENUI_CATALOG,\n GENUI_RESOLVED,\n { token: GenuiCatalogResolver, optional: true },\n ],\n },\n ...resolverProviders(resolver),\n // The generated tools, registered by the agent module's discovery like any `provideAgentTool`.\n // Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.\n provideAgentTools(\n (\n options: AgentGenuiOptions,\n catalog: Catalog,\n resolved: ResolvedGenui,\n perRequestResolver?: GenuiCatalogResolver,\n ) => genuiTools(catalog, toolOptions(options, resolved, perRequestResolver)),\n [\n GENUI_OPTIONS,\n GENUI_CATALOG,\n GENUI_RESOLVED,\n { token: GenuiCatalogResolver, optional: true },\n ],\n ),\n ];\n}\n\nconst EXPORTS = [GENUI_CATALOG, GENUI_OPTIONS, AGENT_GENUI];\n\n/**\n * Generative UI for the agent: registers the tools that let the model push catalog components\n * (one `ui__render` tree tool, or `ui__show_<component>` per component, and/or the generic\n * `ui__show`), and makes the catalog\n * injectable. Global, like `AgentModule`; import it once, next to it.\n *\n * ```ts\n * AgentGenuiModule.forRoot({ catalog, mode: 'tree', terminal: true })\n * ```\n */\n@Module({})\nexport class AgentGenuiModule {\n static forRoot(options: AgentGenuiModuleOptions = {}): DynamicModule {\n const { resolver, ...rest } = options;\n return {\n module: AgentGenuiModule,\n global: true,\n providers: [{ provide: GENUI_OPTIONS, useValue: rest }, ...coreProviders(resolver)],\n exports: resolver === undefined ? EXPORTS : [...EXPORTS, GenuiCatalogResolver],\n };\n }\n\n static forRootAsync(options: AgentGenuiModuleAsyncOptions): DynamicModule {\n return {\n module: AgentGenuiModule,\n global: true,\n imports: options.imports ?? [],\n providers: [\n { provide: GENUI_OPTIONS, useFactory: options.useFactory, inject: options.inject ?? [] },\n ...coreProviders(options.resolver),\n ],\n exports: options.resolver === undefined ? EXPORTS : [...EXPORTS, GenuiCatalogResolver],\n };\n }\n}\n","import {\n type FunctionalToolDefinition,\n type ToolHandler,\n type ToolSpec,\n createFunctionalTool,\n} from '@dudousxd/nestjs-agent-core';\nimport type { FactoryProvider, Provider } from '@nestjs/common';\n\n/**\n * Brand stamped onto a functional-tool provider instance so `AiToolDiscoveryService` picks it up\n * when it walks every provider at boot — the declarative alternative to a manual `registry.register`.\n */\nexport const AGENT_TOOL_BRAND = Symbol.for('@dudousxd/nestjs-agent:functional-tool');\n\n/** A tool expressed as data + handler (e.g. from `createExecuteSqlTool`), not an `@AiTool` class. */\nexport interface FunctionalTool {\n spec: ToolSpec;\n handler: ToolHandler;\n}\n\n/** A {@link FunctionalTool} carrying {@link AGENT_TOOL_BRAND} — what a provider resolves to. */\nexport interface BrandedFunctionalTool extends FunctionalTool {\n readonly [AGENT_TOOL_BRAND]: true;\n}\n\nfunction brand(tool: FunctionalTool): BrandedFunctionalTool {\n return { [AGENT_TOOL_BRAND]: true, spec: tool.spec, handler: tool.handler };\n}\n\n/** Narrows a provider instance to a branded functional tool for boot-time registration. */\nexport function isBrandedFunctionalTool(value: object): value is BrandedFunctionalTool {\n return AGENT_TOOL_BRAND in value && 'spec' in value && 'handler' in value;\n}\n\n/**\n * Registers a functional tool declaratively — drop the returned provider in a module's `providers`\n * and `AiToolDiscoveryService` auto-registers it at boot. Each call uses a fresh, unique provide\n * token so the same tool can be provided many times without collisions.\n *\n * Two forms: a static tool (`useValue`) or a factory with `inject` for DI-resolved dependencies\n * (`useFactory`). Either way the resolved instance is branded with {@link AGENT_TOOL_BRAND}.\n */\nexport function provideAgentTool(tool: FunctionalTool): Provider;\nexport function provideAgentTool(\n factory: (...deps: never[]) => FunctionalTool,\n inject?: FactoryProvider['inject'],\n): Provider;\nexport function provideAgentTool(\n factoryOrTool: FunctionalTool | ((...deps: never[]) => FunctionalTool),\n inject?: FactoryProvider['inject'],\n): Provider {\n const provide = Symbol('nestjs-agent:functional-tool-instance');\n if (typeof factoryOrTool === 'function') {\n return {\n provide,\n useFactory: (...deps: never[]) => brand(factoryOrTool(...deps)),\n inject: inject ?? [],\n };\n }\n return { provide, useValue: brand(factoryOrTool) };\n}\n\n/**\n * Registers a LIST of functional tools from one factory — for a producer whose tool count is only\n * known once its dependencies resolve (a catalog loaded from config, one tool per entry). The\n * factory's result is branded element by element; `AiToolDiscoveryService` registers each.\n */\nexport function provideAgentTools(\n factory: (...deps: never[]) => readonly FunctionalTool[] | Promise<readonly FunctionalTool[]>,\n inject?: FactoryProvider['inject'],\n): Provider {\n return {\n provide: Symbol('nestjs-agent:functional-tool-list'),\n useFactory: async (...deps: never[]) => (await factory(...deps)).map(brand),\n inject: inject ?? [],\n };\n}\n\n/** Author a functional tool with inferred Standard Schema input and domain output. */\nexport const defineTool = createFunctionalTool;\nexport type { FunctionalToolDefinition };\n","import type {\n Catalog,\n GenuiCatalogScope,\n GenuiChannelBase,\n GenuiChannels,\n SandboxClientConfig,\n} from '@dudousxd/nestjs-agent-core/genui';\n\n/**\n * The app's genui setup ({@link AgentGenui}): the catalog, the per-channel options and what the\n * sandbox renderer is told — what the text channels (`@dudousxd/nestjs-agent-channels`) and\n * `GET <base>/config` read.\n */\nexport const AGENT_GENUI = Symbol.for('@dudousxd/nestjs-agent:genui');\n\n/**\n * The app's genui setup, bound to {@link AGENT_GENUI}: what a text channel draws with\n * (`catalog`, `channels`, `base`) and what the sandbox renderer is told (`sandboxClient`).\n */\nexport class AgentGenui {\n constructor(\n readonly catalog: Catalog,\n readonly resolveCatalog?: (scope: GenuiCatalogScope) => Catalog | Promise<Catalog>,\n /** `AgentGenuiModule.forRoot({ channels })`, when configured. */\n readonly channels?: GenuiChannels,\n /** The top-level options a channel falls back to. */\n readonly base: GenuiChannelBase = {},\n /** What the sandbox renderer is told, when a sandbox is configured. */\n readonly sandboxClient?: () => SandboxClientConfig,\n ) {}\n}\n","/**\n * `@dudousxd/nestjs-agent/genui` — generative UI for NestJS: {@link AgentGenuiModule} registers the\n * tools that push catalog components, `GENUI_CATALOG` / `@InjectGenuiCatalog()` expose the catalog,\n * and {@link GenuiCatalogResolver} serves per-request (per-tenant) catalogs. The catalog itself —\n * `defineComponent`, `defineCatalog`, validation, text fallbacks — is re-exported from\n * `@dudousxd/nestjs-agent-core/genui`, the isomorphic entry a browser imports too.\n */\nexport {\n AGENT_GENUI,\n AgentGenui,\n AgentGenuiModule,\n type AgentGenuiModuleAsyncOptions,\n type AgentGenuiModuleOptions,\n type AgentGenuiOptions,\n type AgentGenuiSandboxKitOptions,\n GENUI_CATALOG,\n GENUI_OPTIONS,\n GenuiCatalogResolver,\n InjectGenuiCatalog,\n} from './agent-genui.module.js';\nexport * from '@dudousxd/nestjs-agent-core/genui';\n"],"mappings":";;;;;;;;;;;;AAcA,SAIEA,wBACAC,2BACAC,0BACAC,mCACK;AAtBP,IA6BaC;AA7Bb;;;AA6BO,IAAMA,8BAA8B;;;;;AC7B3C;;;;;AAMA,SAASC,eAAe;AACxB,SAEEC,2BACK;AAWA,SAASC,wBACdC,UAAuC,CAAC,GAAC;AAEzC,QAAMC,WAAWD,QAAQC,YAAYC;AACrC,SAAOJ,oBAAoB;IACzBK,MAAMN,QAAQG,QAAQG,QAAQC,QAAQC,IAAG,CAAA;IACzCC,YAAYN,QAAQM,cAAcC;IAClC,GAAIN,aAAa,QAAQ;MAAEA,UAAU;QAAEO,MAAMP,SAASO;QAAMC,QAAQR,SAASQ;MAAO;IAAE,IAAI,CAAC;IAC3F,GAAIT,QAAQU,WAAWC,SAAY;MAAED,QAAQV,QAAQU;IAAO,IAAI,CAAC;IACjE,GAAIV,QAAQY,eAAeD,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2E,OAAOxE;QAAsByE,UAAU;MAAK;KAC/C;;AAGP;AAzDST;AA2DT,IAAMa,UAAU;EAACpF;EAAeG;EAAeuE;;AAaxC,IAAMW,mBAAN,MAAMA,kBAAAA;SAAAA;;;EACX,OAAOC,QAAQ/D,UAAmC,CAAC,GAAkB;AACnE,UAAM,EAAEd,UAAU,GAAGuD,KAAAA,IAASzC;AAC9B,WAAO;MACLgE,QAAQF;MACRG,QAAQ;MACRC,WAAW;QAAC;UAAE9E,SAASR;UAAeU,UAAUmD;QAAK;WAAMO,cAAc9D,QAAAA;;MACzEiF,SAASjF,aAAaC,SAAY0E,UAAU;WAAIA;QAAS7E;;IAC3D;EACF;EAEA,OAAOoF,aAAapE,SAAsD;AACxE,WAAO;MACLgE,QAAQF;MACRG,QAAQ;MACRI,SAASrE,QAAQqE,WAAW,CAAA;MAC5BH,WAAW;QACT;UAAE9E,SAASR;UAAeqE,YAAYjD,QAAQiD;UAAYC,QAAQlD,QAAQkD,UAAU,CAAA;QAAG;WACpFF,cAAchD,QAAQd,QAAQ;;MAEnCiF,SAASnE,QAAQd,aAAaC,SAAY0E,UAAU;WAAIA;QAAS7E;;IACnE;EACF;AACF;;;;;;AG1WA,cAAc;","names":["SANDBOX_KIT_DEV_PREFIX","SANDBOX_KIT_MANIFEST_KEYS","SANDBOX_KIT_UPDATE_EVENT","createGenuiSandboxKitPlugin","NEST_SANDBOX_KIT_DESCRIPTOR","resolve","sandboxKitDiscovery","nestSandboxKitDiscovery","options","manifest","NEST_SANDBOX_KIT_MANIFEST","root","process","cwd","descriptor","NEST_SANDBOX_KIT_DESCRIPTOR","file","outDir","kitUrl","undefined","production","Object","freeze","assertGenuiChannels","defineCatalog","defineSandbox","genuiTools","sandboxPolicyOf","Inject","Module","createFunctionalTool","AGENT_TOOL_BRAND","Symbol","for","brand","tool","spec","handler","provideAgentTools","factory","inject","provide","Symbol","useFactory","deps","map","brand","AGENT_GENUI","Symbol","for","AgentGenui","catalog","resolveCatalog","channels","base","sandboxClient","GENUI_CATALOG","Symbol","for","GENUI_OPTIONS","GENUI_RESOLVED","InjectGenuiCatalog","Inject","GenuiCatalogResolver","resolverProviders","resolver","undefined","provide","useClass","useValue","mergeSandboxClients","clients","merged","theme","client","one","tailwind","kit","resolveGenui","options","sandbox","asked","channels","askedChannels","assertGenuiChannels","discovery","resolveSandbox","value","nestSandboxKitDiscovery","resolveSandboxServer","Promise","all","sandboxKit","resolved","push","define","own","catalog","components","find","each","sandboxPolicyOf","ownOptions","sandboxOptions","sandboxView","name","entry","Object","entries","catalogSandbox","length","sandboxClient","perRequest","scope","resolve","toolOptions","_catalog","_sandbox","_channels","_sandboxKit","rest","resolveCatalog","withSandbox","base","defineCatalog","extend","defineSandbox","coreProviders","useFactory","inject","AGENT_GENUI","resolverInstance","AgentGenui","mode","streaming","token","optional","provideAgentTools","perRequestResolver","genuiTools","EXPORTS","AgentGenuiModule","forRoot","module","global","providers","exports","forRootAsync","imports"]}
|
|
@@ -2,7 +2,7 @@ import { A2uiStreamOptions, a2uiThreadReplay } from '@dudousxd/nestjs-agent-core
|
|
|
2
2
|
import { AgentAttachmentConfig, AttachmentStagingStore, AgentStore, Actor, ListActionProposals, ActionProposalView, ActionProposalMutationView, TextActionProposalVocabulary, AgentRunner, ModelCatalog, QuotaProvider, ActionApprovalMode, MessageAttachment, QuotaReport, ModelCatalogView, AgentHostContext, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver } from '@dudousxd/nestjs-agent-core';
|
|
3
3
|
import { Request, Response } from 'express';
|
|
4
4
|
import { UiCapabilities } from '@dudousxd/nestjs-agent-core/genui';
|
|
5
|
-
import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-
|
|
5
|
+
import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-Bdz43pAC.js';
|
|
6
6
|
|
|
7
7
|
/** Default per-file size cap (20 MiB). */
|
|
8
8
|
declare const DEFAULT_MAX_ATTACHMENT_BYTES: number;
|
|
@@ -129,6 +129,13 @@ interface ChatParams {
|
|
|
129
129
|
*/
|
|
130
130
|
attachments?: AttachmentRef[];
|
|
131
131
|
pageContext?: PageContext;
|
|
132
|
+
/**
|
|
133
|
+
* The channel this turn runs on — `web`, `mobile`, `whatsapp`… — over whatever its page context
|
|
134
|
+
* says. Stamped as `pageContext.channel`, which is what decides (`turnChannel`) which genui tools
|
|
135
|
+
* the turn is offered (`AgentGenuiModule.forRoot({ channels })`). Omitted → the page context's,
|
|
136
|
+
* else `web`.
|
|
137
|
+
*/
|
|
138
|
+
channel?: string;
|
|
132
139
|
/** Re-run the last exchange instead of adding a new message. Requires an existing `threadId`. */
|
|
133
140
|
regenerate?: boolean;
|
|
134
141
|
/**
|
|
@@ -2,7 +2,7 @@ import { A2uiStreamOptions, a2uiThreadReplay } from '@dudousxd/nestjs-agent-core
|
|
|
2
2
|
import { AgentAttachmentConfig, AttachmentStagingStore, AgentStore, Actor, ListActionProposals, ActionProposalView, ActionProposalMutationView, TextActionProposalVocabulary, AgentRunner, ModelCatalog, QuotaProvider, ActionApprovalMode, MessageAttachment, QuotaReport, ModelCatalogView, AgentHostContext, AttachmentRef, PageContext, ChatQueueState, HumanReply, ThreadSummary, ThreadDetail, UpdateThreadInput, MessageFeedbackValue, MessageFeedback, StagedAttachment, ActorResolver } from '@dudousxd/nestjs-agent-core';
|
|
3
3
|
import { Request, Response } from 'express';
|
|
4
4
|
import { UiCapabilities } from '@dudousxd/nestjs-agent-core/genui';
|
|
5
|
-
import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-
|
|
5
|
+
import { b as AgentModuleOptions, A as AgentDepsFactory, C as ChatQueueService, d as AgentProtocolAdapter } from './chat-queue.service-ZwQ9p-Ps.cjs';
|
|
6
6
|
|
|
7
7
|
/** Default per-file size cap (20 MiB). */
|
|
8
8
|
declare const DEFAULT_MAX_ATTACHMENT_BYTES: number;
|
|
@@ -129,6 +129,13 @@ interface ChatParams {
|
|
|
129
129
|
*/
|
|
130
130
|
attachments?: AttachmentRef[];
|
|
131
131
|
pageContext?: PageContext;
|
|
132
|
+
/**
|
|
133
|
+
* The channel this turn runs on — `web`, `mobile`, `whatsapp`… — over whatever its page context
|
|
134
|
+
* says. Stamped as `pageContext.channel`, which is what decides (`turnChannel`) which genui tools
|
|
135
|
+
* the turn is offered (`AgentGenuiModule.forRoot({ channels })`). Omitted → the page context's,
|
|
136
|
+
* else `web`.
|
|
137
|
+
*/
|
|
138
|
+
channel?: string;
|
|
132
139
|
/** Re-run the last exchange instead of adding a new message. Requires an existing `threadId`. */
|
|
133
140
|
regenerate?: boolean;
|
|
134
141
|
/**
|