@dudousxd/nestjs-agent 1.30.0 → 1.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2ui/index.cjs +207 -11
- package/dist/a2ui/index.cjs.map +1 -1
- package/dist/a2ui/index.d.cts +2 -2
- package/dist/a2ui/index.d.ts +2 -2
- package/dist/a2ui/index.js +203 -12
- package/dist/a2ui/index.js.map +1 -1
- package/dist/{chat-queue.service-Bk7DCKGV.d.cts → chat-queue.service-QIuTS-5c.d.cts} +11 -3
- package/dist/{chat-queue.service-B-fVOJGf.d.ts → chat-queue.service-wNWaoUN8.d.ts} +11 -3
- package/dist/durable/index.cjs +286 -44
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +1 -1
- package/dist/durable/index.d.ts +1 -1
- package/dist/durable/index.js +279 -42
- 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 +68 -2
- package/dist/genui/index.d.ts +68 -2
- package/dist/genui/index.js +205 -12
- package/dist/genui/index.js.map +1 -1
- package/dist/{index-APh8WN3z.d.ts → index-DFKUTFfZ.d.ts} +8 -1
- package/dist/{index-D9EM7ivO.d.cts → index-DIFUEKPr.d.cts} +8 -1
- package/dist/index.cjs +276 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +273 -40
- 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.cjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
7
12
|
var __export = (target, all) => {
|
|
8
13
|
for (var name in all)
|
|
9
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,11 +22,71 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
22
|
return to;
|
|
18
23
|
};
|
|
19
24
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
20
33
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
34
|
|
|
35
|
+
// src/vite/index.ts
|
|
36
|
+
var import_kit, NEST_SANDBOX_KIT_DESCRIPTOR;
|
|
37
|
+
var init_vite = __esm({
|
|
38
|
+
"src/vite/index.ts"() {
|
|
39
|
+
"use strict";
|
|
40
|
+
import_kit = require("@dudousxd/nestjs-agent-core/genui/kit");
|
|
41
|
+
NEST_SANDBOX_KIT_DESCRIPTOR = ".genui/sandbox-kit.json";
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// src/genui/kit.ts
|
|
46
|
+
var kit_exports = {};
|
|
47
|
+
__export(kit_exports, {
|
|
48
|
+
NEST_SANDBOX_KIT_MANIFEST: () => NEST_SANDBOX_KIT_MANIFEST,
|
|
49
|
+
nestSandboxKitDiscovery: () => nestSandboxKitDiscovery
|
|
50
|
+
});
|
|
51
|
+
function nestSandboxKitDiscovery(options = {}) {
|
|
52
|
+
const manifest = options.manifest ?? NEST_SANDBOX_KIT_MANIFEST;
|
|
53
|
+
return (0, import_kit2.sandboxKitDiscovery)({
|
|
54
|
+
root: (0, import_node_path.resolve)(options.root ?? process.cwd()),
|
|
55
|
+
descriptor: options.descriptor ?? NEST_SANDBOX_KIT_DESCRIPTOR,
|
|
56
|
+
...manifest !== false ? {
|
|
57
|
+
manifest: {
|
|
58
|
+
file: manifest.file,
|
|
59
|
+
outDir: manifest.outDir
|
|
60
|
+
}
|
|
61
|
+
} : {},
|
|
62
|
+
...options.kitUrl !== void 0 ? {
|
|
63
|
+
kitUrl: options.kitUrl
|
|
64
|
+
} : {},
|
|
65
|
+
...options.production !== void 0 ? {
|
|
66
|
+
production: options.production
|
|
67
|
+
} : {}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
var import_node_path, import_kit2, NEST_SANDBOX_KIT_MANIFEST;
|
|
71
|
+
var init_kit = __esm({
|
|
72
|
+
"src/genui/kit.ts"() {
|
|
73
|
+
"use strict";
|
|
74
|
+
import_node_path = require("path");
|
|
75
|
+
import_kit2 = require("@dudousxd/nestjs-agent-core/genui/kit");
|
|
76
|
+
init_vite();
|
|
77
|
+
NEST_SANDBOX_KIT_MANIFEST = Object.freeze({
|
|
78
|
+
file: "public/.vite/manifest.json",
|
|
79
|
+
outDir: "public"
|
|
80
|
+
});
|
|
81
|
+
__name(nestSandboxKitDiscovery, "nestSandboxKitDiscovery");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
22
85
|
// src/genui/index.ts
|
|
23
86
|
var genui_exports = {};
|
|
24
87
|
__export(genui_exports, {
|
|
88
|
+
AGENT_GENUI: () => AGENT_GENUI,
|
|
89
|
+
AgentGenui: () => AgentGenui,
|
|
25
90
|
AgentGenuiModule: () => AgentGenuiModule,
|
|
26
91
|
GENUI_CATALOG: () => GENUI_CATALOG,
|
|
27
92
|
GENUI_OPTIONS: () => GENUI_OPTIONS,
|
|
@@ -54,6 +119,26 @@ function provideAgentTools(factory, inject) {
|
|
|
54
119
|
}
|
|
55
120
|
__name(provideAgentTools, "provideAgentTools");
|
|
56
121
|
|
|
122
|
+
// src/genui/agent-genui.token.ts
|
|
123
|
+
var AGENT_GENUI = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui");
|
|
124
|
+
var AgentGenui = class {
|
|
125
|
+
static {
|
|
126
|
+
__name(this, "AgentGenui");
|
|
127
|
+
}
|
|
128
|
+
catalog;
|
|
129
|
+
resolveCatalog;
|
|
130
|
+
channels;
|
|
131
|
+
base;
|
|
132
|
+
sandboxClient;
|
|
133
|
+
constructor(catalog, resolveCatalog, channels, base = {}, sandboxClient) {
|
|
134
|
+
this.catalog = catalog;
|
|
135
|
+
this.resolveCatalog = resolveCatalog;
|
|
136
|
+
this.channels = channels;
|
|
137
|
+
this.base = base;
|
|
138
|
+
this.sandboxClient = sandboxClient;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
57
142
|
// src/genui/agent-genui.module.ts
|
|
58
143
|
function _ts_decorate(decorators, target, key, desc) {
|
|
59
144
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -71,6 +156,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
71
156
|
__name(_ts_decorate, "_ts_decorate");
|
|
72
157
|
var GENUI_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-catalog");
|
|
73
158
|
var GENUI_OPTIONS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-options");
|
|
159
|
+
var GENUI_RESOLVED = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-resolved");
|
|
74
160
|
var InjectGenuiCatalog = /* @__PURE__ */ __name(() => (0, import_common.Inject)(GENUI_CATALOG), "InjectGenuiCatalog");
|
|
75
161
|
var GenuiCatalogResolver = class {
|
|
76
162
|
static {
|
|
@@ -90,20 +176,99 @@ function resolverProviders(resolver) {
|
|
|
90
176
|
];
|
|
91
177
|
}
|
|
92
178
|
__name(resolverProviders, "resolverProviders");
|
|
93
|
-
function
|
|
94
|
-
const
|
|
179
|
+
function mergeSandboxClients(clients) {
|
|
180
|
+
const merged = {
|
|
181
|
+
theme: false
|
|
182
|
+
};
|
|
183
|
+
for (const client of clients) {
|
|
184
|
+
const one = client();
|
|
185
|
+
merged.theme ||= one.theme;
|
|
186
|
+
if (one.tailwind !== void 0) merged.tailwind ??= one.tailwind;
|
|
187
|
+
if (one.kit !== void 0) merged.kit ??= one.kit;
|
|
188
|
+
}
|
|
189
|
+
return merged;
|
|
190
|
+
}
|
|
191
|
+
__name(mergeSandboxClients, "mergeSandboxClients");
|
|
192
|
+
async function resolveGenui(options) {
|
|
193
|
+
const { sandbox: asked, channels: askedChannels } = options;
|
|
194
|
+
(0, import_genui.assertGenuiChannels)(askedChannels);
|
|
195
|
+
const clients = [];
|
|
196
|
+
let discovery;
|
|
197
|
+
const resolveSandbox = /* @__PURE__ */ __name(async (value) => {
|
|
198
|
+
if (value === void 0 || value === false) return value;
|
|
199
|
+
const [{ nestSandboxKitDiscovery: nestSandboxKitDiscovery2 }, { resolveSandboxServer }] = await Promise.all([
|
|
200
|
+
Promise.resolve().then(() => (init_kit(), kit_exports)),
|
|
201
|
+
import("@dudousxd/nestjs-agent-core/genui/kit")
|
|
202
|
+
]);
|
|
203
|
+
discovery ??= nestSandboxKitDiscovery2(options.sandboxKit);
|
|
204
|
+
const resolved = resolveSandboxServer(value, discovery);
|
|
205
|
+
clients.push(resolved.client);
|
|
206
|
+
return resolved.define;
|
|
207
|
+
}, "resolveSandbox");
|
|
208
|
+
const sandbox = await resolveSandbox(asked);
|
|
209
|
+
const own = options.catalog?.components.find((each) => (0, import_genui.sandboxPolicyOf)(each) !== void 0);
|
|
210
|
+
const ownOptions = asked === void 0 && own?.sandboxOptions !== void 0 && (own.sandboxView?.kit === true || own.sandboxView?.tailwind === true) ? await resolveSandbox({
|
|
211
|
+
...own.sandboxOptions,
|
|
212
|
+
name: own.name
|
|
213
|
+
}) : void 0;
|
|
214
|
+
let channels;
|
|
215
|
+
if (askedChannels !== void 0) {
|
|
216
|
+
channels = {};
|
|
217
|
+
for (const [name, entry] of Object.entries(askedChannels)) {
|
|
218
|
+
if (entry === void 0) continue;
|
|
219
|
+
const own2 = await resolveSandbox(entry.sandbox);
|
|
220
|
+
channels[name] = {
|
|
221
|
+
...entry,
|
|
222
|
+
...own2 !== void 0 ? {
|
|
223
|
+
sandbox: own2
|
|
224
|
+
} : {}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
...sandbox !== void 0 ? {
|
|
230
|
+
sandbox
|
|
231
|
+
} : {},
|
|
232
|
+
...typeof ownOptions === "object" ? {
|
|
233
|
+
catalogSandbox: ownOptions
|
|
234
|
+
} : {},
|
|
235
|
+
...channels !== void 0 ? {
|
|
236
|
+
channels
|
|
237
|
+
} : {},
|
|
238
|
+
...clients.length > 0 ? {
|
|
239
|
+
sandboxClient: /* @__PURE__ */ __name(() => mergeSandboxClients(clients), "sandboxClient")
|
|
240
|
+
} : {}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
__name(resolveGenui, "resolveGenui");
|
|
244
|
+
function perRequest(resolver) {
|
|
245
|
+
return resolver === void 0 ? void 0 : (scope) => resolver.resolve(scope);
|
|
246
|
+
}
|
|
247
|
+
__name(perRequest, "perRequest");
|
|
248
|
+
function toolOptions(options, resolved, resolver) {
|
|
249
|
+
const { catalog: _catalog, sandbox: _sandbox, channels: _channels, sandboxKit: _sandboxKit, ...rest } = options;
|
|
250
|
+
const resolveCatalog = perRequest(resolver);
|
|
95
251
|
return {
|
|
96
252
|
...rest,
|
|
97
|
-
...
|
|
98
|
-
|
|
253
|
+
...resolved.channels !== void 0 ? {
|
|
254
|
+
channels: resolved.channels
|
|
255
|
+
} : {},
|
|
256
|
+
...resolved.sandbox !== void 0 ? {
|
|
257
|
+
sandbox: resolved.sandbox
|
|
258
|
+
} : {},
|
|
259
|
+
...resolveCatalog !== void 0 ? {
|
|
260
|
+
resolveCatalog
|
|
99
261
|
} : {}
|
|
100
262
|
};
|
|
101
263
|
}
|
|
102
264
|
__name(toolOptions, "toolOptions");
|
|
103
|
-
function withSandbox(options) {
|
|
265
|
+
function withSandbox(options, resolved) {
|
|
104
266
|
const base = options.catalog ?? (0, import_genui.defineCatalog)([]);
|
|
105
|
-
const { sandbox } =
|
|
106
|
-
|
|
267
|
+
const { sandbox, catalogSandbox } = resolved;
|
|
268
|
+
if (sandbox === void 0 || sandbox === false) return catalogSandbox !== void 0 ? base.extend([
|
|
269
|
+
(0, import_genui.defineSandbox)(catalogSandbox)
|
|
270
|
+
]) : base;
|
|
271
|
+
return base.extend([
|
|
107
272
|
(0, import_genui.defineSandbox)(sandbox === true ? {} : sandbox)
|
|
108
273
|
]);
|
|
109
274
|
}
|
|
@@ -111,18 +276,50 @@ __name(withSandbox, "withSandbox");
|
|
|
111
276
|
function coreProviders(resolver) {
|
|
112
277
|
return [
|
|
113
278
|
{
|
|
114
|
-
provide:
|
|
115
|
-
useFactory: /* @__PURE__ */ __name((options) =>
|
|
279
|
+
provide: GENUI_RESOLVED,
|
|
280
|
+
useFactory: /* @__PURE__ */ __name((options) => resolveGenui(options), "useFactory"),
|
|
116
281
|
inject: [
|
|
117
282
|
GENUI_OPTIONS
|
|
118
283
|
]
|
|
119
284
|
},
|
|
285
|
+
{
|
|
286
|
+
provide: GENUI_CATALOG,
|
|
287
|
+
useFactory: /* @__PURE__ */ __name((options, resolved) => withSandbox(options, resolved), "useFactory"),
|
|
288
|
+
inject: [
|
|
289
|
+
GENUI_OPTIONS,
|
|
290
|
+
GENUI_RESOLVED
|
|
291
|
+
]
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
provide: AGENT_GENUI,
|
|
295
|
+
useFactory: /* @__PURE__ */ __name((options, catalog, resolved, resolverInstance) => new AgentGenui(catalog, perRequest(resolverInstance), resolved.channels, {
|
|
296
|
+
...options.mode !== void 0 ? {
|
|
297
|
+
mode: options.mode
|
|
298
|
+
} : {},
|
|
299
|
+
...options.streaming !== void 0 ? {
|
|
300
|
+
streaming: options.streaming
|
|
301
|
+
} : {},
|
|
302
|
+
...resolved.sandbox !== void 0 ? {
|
|
303
|
+
sandbox: resolved.sandbox
|
|
304
|
+
} : {}
|
|
305
|
+
}, resolved.sandboxClient), "useFactory"),
|
|
306
|
+
inject: [
|
|
307
|
+
GENUI_OPTIONS,
|
|
308
|
+
GENUI_CATALOG,
|
|
309
|
+
GENUI_RESOLVED,
|
|
310
|
+
{
|
|
311
|
+
token: GenuiCatalogResolver,
|
|
312
|
+
optional: true
|
|
313
|
+
}
|
|
314
|
+
]
|
|
315
|
+
},
|
|
120
316
|
...resolverProviders(resolver),
|
|
121
317
|
// The generated tools, registered by the agent module's discovery like any `provideAgentTool`.
|
|
122
318
|
// Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.
|
|
123
|
-
provideAgentTools((options, catalog,
|
|
319
|
+
provideAgentTools((options, catalog, resolved, perRequestResolver) => (0, import_genui.genuiTools)(catalog, toolOptions(options, resolved, perRequestResolver)), [
|
|
124
320
|
GENUI_OPTIONS,
|
|
125
321
|
GENUI_CATALOG,
|
|
322
|
+
GENUI_RESOLVED,
|
|
126
323
|
{
|
|
127
324
|
token: GenuiCatalogResolver,
|
|
128
325
|
optional: true
|
|
@@ -133,7 +330,8 @@ function coreProviders(resolver) {
|
|
|
133
330
|
__name(coreProviders, "coreProviders");
|
|
134
331
|
var EXPORTS = [
|
|
135
332
|
GENUI_CATALOG,
|
|
136
|
-
GENUI_OPTIONS
|
|
333
|
+
GENUI_OPTIONS,
|
|
334
|
+
AGENT_GENUI
|
|
137
335
|
];
|
|
138
336
|
var AgentGenuiModule = class _AgentGenuiModule {
|
|
139
337
|
static {
|
|
@@ -185,6 +383,8 @@ AgentGenuiModule = _ts_decorate([
|
|
|
185
383
|
__reExport(genui_exports, require("@dudousxd/nestjs-agent-core/genui"), module.exports);
|
|
186
384
|
// Annotate the CommonJS export names for ESM import in node:
|
|
187
385
|
0 && (module.exports = {
|
|
386
|
+
AGENT_GENUI,
|
|
387
|
+
AgentGenui,
|
|
188
388
|
AgentGenuiModule,
|
|
189
389
|
GENUI_CATALOG,
|
|
190
390
|
GENUI_OPTIONS,
|
package/dist/genui/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/genui/index.ts","../../src/genui/agent-genui.module.ts","../../src/functional-tool.ts"],"sourcesContent":["/**\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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;ACSA,mBAKO;AACP,oBAQO;;;ACvBP,+BAKO;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AC,IAAIA,OAAAA;GAAS;AAClE;AANSM;AAQT,SAASK,cAAcpB,UAAoC;AACzD,SAAO;IACL;MACEE,SAASV;MACT6B,YAAY,wBAACf,YAA+BS,YAAYT,OAAAA,GAA5C;MACZgB,QAAQ;QAAC3B;;IACX;OACGI,kBAAkBC,QAAAA;;;IAGrBuB,kBACE,CAACjB,SAA4BC,SAAkBiB,mBAC7CC,yBAAWlB,SAASF,YAAYC,SAASkB,UAAAA,CAAAA,GAC3C;MAAC7B;MAAeH;MAAe;QAAEkC,OAAO5B;QAAsB6B,UAAU;MAAK;KAAE;;AAGrF;AAhBSP;AAkBT,IAAMQ,UAAU;EAACpC;EAAeG;;AAazB,IAAMkC,mBAAN,MAAMA,kBAAAA;SAAAA;;;EACX,OAAOC,QAAQxB,UAAmC,CAAC,GAAkB;AACnE,UAAM,EAAEN,UAAU,GAAGW,KAAAA,IAASL;AAC9B,WAAO;MACLyB,QAAQF;MACRG,QAAQ;MACRC,WAAW;QAAC;UAAE/B,SAASP;UAAeS,UAAUO;QAAK;WAAMS,cAAcpB,QAAAA;;MACzEkC,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;;;;;;ADhMA,0BAAc,8CAjBd;","names":["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/index.ts","../../src/genui/agent-genui.module.ts","../../src/functional-tool.ts","../../src/genui/agent-genui.token.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","/**\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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAcA,YAeaA;AA7Bb;;;AAcA,iBAQO;AAOA,IAAMA,8BAA8B;;;;;AC7B3C;;;;;AAqBO,SAASC,wBACdC,UAAuC,CAAC,GAAC;AAEzC,QAAMC,WAAWD,QAAQC,YAAYC;AACrC,aAAOC,iCAAoB;IACzBC,UAAMC,0BAAQL,QAAQI,QAAQE,QAAQC,IAAG,CAAA;IACzCC,YAAYR,QAAQQ,cAAcC;IAClC,GAAIR,aAAa,QAAQ;MAAEA,UAAU;QAAES,MAAMT,SAASS;QAAMC,QAAQV,SAASU;MAAO;IAAE,IAAI,CAAC;IAC3F,GAAIX,QAAQY,WAAWC,SAAY;MAAED,QAAQZ,QAAQY;IAAO,IAAI,CAAC;IACjE,GAAIZ,QAAQc,eAAeD,SAAY;MAAEC,YAAYd,QAAQc;IAAW,IAAI,CAAC;EAC/E,CAAA;AACF;AAhCA,IAMA,kBACAC,aAQab;AAfb;;;AAMA,uBAAwB;AACxB,IAAAa,cAGO;AACP;AAIO,IAAMb,4BAA4Bc,OAAOC,OAAO;MACrDP,MAAM;MACNC,QAAQ;IACV,CAAA;AAGgBZ;;;;;ACrBhB;;;;;;;;;;;;;ACWA,mBAQO;AACP,oBAQO;;;AC5BP,+BAKO;AAOA,IAAMmB,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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lD,QAAQkD,UAAU,CAAA;QAAG;WACpFF,cAAchD,QAAQd,QAAQ;;MAEnCiF,SAASnE,QAAQd,aAAaC,SAAY0E,UAAU;WAAIA;QAAS7E;;IACnE;EACF;AACF;;;;;;AD1WA,0BAAc,8CApBd;","names":["NEST_SANDBOX_KIT_DESCRIPTOR","nestSandboxKitDiscovery","options","manifest","NEST_SANDBOX_KIT_MANIFEST","sandboxKitDiscovery","root","resolve","process","cwd","descriptor","NEST_SANDBOX_KIT_DESCRIPTOR","file","outDir","kitUrl","undefined","production","import_kit","Object","freeze","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"]}
|
package/dist/genui/index.d.cts
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import { ToolPresentation } from '@dudousxd/nestjs-agent-core';
|
|
2
|
-
import { GenuiCatalogScope,
|
|
2
|
+
import { Catalog, GenuiCatalogScope, GenuiChannels, GenuiChannelBase, SandboxClientConfig, TreeSchemaMode, GenuiStreaming, TreeLimits, DefineSandboxOptions } from '@dudousxd/nestjs-agent-core/genui';
|
|
3
3
|
export * from '@dudousxd/nestjs-agent-core/genui';
|
|
4
4
|
import { Type, DynamicModule, ModuleMetadata, FactoryProvider } from '@nestjs/common';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The app's genui setup ({@link AgentGenui}): the catalog, the per-channel options and what the
|
|
8
|
+
* sandbox renderer is told — what the text channels (`@dudousxd/nestjs-agent-channels`) and
|
|
9
|
+
* `GET <base>/config` read.
|
|
10
|
+
*/
|
|
11
|
+
declare const AGENT_GENUI: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* The app's genui setup, bound to {@link AGENT_GENUI}: what a text channel draws with
|
|
14
|
+
* (`catalog`, `channels`, `base`) and what the sandbox renderer is told (`sandboxClient`).
|
|
15
|
+
*/
|
|
16
|
+
declare class AgentGenui {
|
|
17
|
+
readonly catalog: Catalog;
|
|
18
|
+
readonly resolveCatalog?: ((scope: GenuiCatalogScope) => Catalog | Promise<Catalog>) | undefined;
|
|
19
|
+
/** `AgentGenuiModule.forRoot({ channels })`, when configured. */
|
|
20
|
+
readonly channels?: GenuiChannels | undefined;
|
|
21
|
+
/** The top-level options a channel falls back to. */
|
|
22
|
+
readonly base: GenuiChannelBase;
|
|
23
|
+
/** What the sandbox renderer is told, when a sandbox is configured. */
|
|
24
|
+
readonly sandboxClient?: (() => SandboxClientConfig) | undefined;
|
|
25
|
+
constructor(catalog: Catalog, resolveCatalog?: ((scope: GenuiCatalogScope) => Catalog | Promise<Catalog>) | undefined,
|
|
26
|
+
/** `AgentGenuiModule.forRoot({ channels })`, when configured. */
|
|
27
|
+
channels?: GenuiChannels | undefined,
|
|
28
|
+
/** The top-level options a channel falls back to. */
|
|
29
|
+
base?: GenuiChannelBase,
|
|
30
|
+
/** What the sandbox renderer is told, when a sandbox is configured. */
|
|
31
|
+
sandboxClient?: (() => SandboxClientConfig) | undefined);
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
/** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */
|
|
7
35
|
declare const GENUI_CATALOG: unique symbol;
|
|
8
36
|
/** The resolved {@link AgentGenuiOptions} (without the resolver). */
|
|
@@ -78,8 +106,46 @@ interface AgentGenuiOptions {
|
|
|
78
106
|
* the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.
|
|
79
107
|
* The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared
|
|
80
108
|
* catalog file) so the renderer enforces the same policy.
|
|
109
|
+
*
|
|
110
|
+
* `theme` (default on), `tailwind` and `kit` put the app's design system in the frame. `kit: true`
|
|
111
|
+
* (and the theme's variable names) are found through `sandboxKit`: the descriptor
|
|
112
|
+
* `genuiSandboxKit()` (`@dudousxd/nestjs-agent/vite`) writes in dev, the Vite manifest in
|
|
113
|
+
* production — and `GET <base>/config` tells the renderer where the assets are.
|
|
81
114
|
*/
|
|
82
115
|
sandbox?: boolean | DefineSandboxOptions;
|
|
116
|
+
/**
|
|
117
|
+
* Per-channel generative UI: each entry sets the mode, streaming, sandbox and rendering of one
|
|
118
|
+
* channel (`web`, `mobile`, `whatsapp`, `telegram`, `email`, or `default` for the rest), over the
|
|
119
|
+
* top-level options. A text channel (`@dudousxd/nestjs-agent-channels`) configured here draws the
|
|
120
|
+
* components natively (reply buttons, lists, images). Omitted → every channel is served by the
|
|
121
|
+
* top-level options, as before.
|
|
122
|
+
*/
|
|
123
|
+
channels?: GenuiChannels;
|
|
124
|
+
/**
|
|
125
|
+
* Where the sandbox kit is found (with `sandbox: { kit: true }`, `tailwind: true` or the theme's
|
|
126
|
+
* names). No Vite runs in the Nest process, so: the descriptor the dev plugin writes, else the
|
|
127
|
+
* production Vite manifest (read first when `NODE_ENV=production`).
|
|
128
|
+
*/
|
|
129
|
+
sandboxKit?: AgentGenuiSandboxKitOptions;
|
|
130
|
+
}
|
|
131
|
+
/** {@link AgentGenuiOptions.sandboxKit}. Relative paths resolve against `root`. */
|
|
132
|
+
interface AgentGenuiSandboxKitOptions {
|
|
133
|
+
/** Default `process.cwd()`. */
|
|
134
|
+
root?: string;
|
|
135
|
+
/** The dev descriptor `genuiSandboxKit()` writes. Default `.genui/sandbox-kit.json`. */
|
|
136
|
+
descriptor?: string;
|
|
137
|
+
/**
|
|
138
|
+
* The production Vite manifest, and the directory its `file`s are relative to. Default
|
|
139
|
+
* `{ file: 'public/.vite/manifest.json', outDir: 'public' }`; `false` → none.
|
|
140
|
+
*/
|
|
141
|
+
manifest?: {
|
|
142
|
+
file: string;
|
|
143
|
+
outDir: string;
|
|
144
|
+
} | false;
|
|
145
|
+
/** An explicit kit url (an SPA served from elsewhere), over what is found. */
|
|
146
|
+
kitUrl?: string;
|
|
147
|
+
/** Read the manifest first. Default: `NODE_ENV === 'production'`. */
|
|
148
|
+
production?: boolean;
|
|
83
149
|
}
|
|
84
150
|
type ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;
|
|
85
151
|
interface AgentGenuiModuleOptions extends AgentGenuiOptions {
|
|
@@ -107,4 +173,4 @@ declare class AgentGenuiModule {
|
|
|
107
173
|
static forRootAsync(options: AgentGenuiModuleAsyncOptions): DynamicModule;
|
|
108
174
|
}
|
|
109
175
|
|
|
110
|
-
export { AgentGenuiModule, type AgentGenuiModuleAsyncOptions, type AgentGenuiModuleOptions, type AgentGenuiOptions, GENUI_CATALOG, GENUI_OPTIONS, GenuiCatalogResolver, InjectGenuiCatalog };
|
|
176
|
+
export { AGENT_GENUI, AgentGenui, AgentGenuiModule, type AgentGenuiModuleAsyncOptions, type AgentGenuiModuleOptions, type AgentGenuiOptions, type AgentGenuiSandboxKitOptions, GENUI_CATALOG, GENUI_OPTIONS, GenuiCatalogResolver, InjectGenuiCatalog };
|
package/dist/genui/index.d.ts
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import { ToolPresentation } from '@dudousxd/nestjs-agent-core';
|
|
2
|
-
import { GenuiCatalogScope,
|
|
2
|
+
import { Catalog, GenuiCatalogScope, GenuiChannels, GenuiChannelBase, SandboxClientConfig, TreeSchemaMode, GenuiStreaming, TreeLimits, DefineSandboxOptions } from '@dudousxd/nestjs-agent-core/genui';
|
|
3
3
|
export * from '@dudousxd/nestjs-agent-core/genui';
|
|
4
4
|
import { Type, DynamicModule, ModuleMetadata, FactoryProvider } from '@nestjs/common';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The app's genui setup ({@link AgentGenui}): the catalog, the per-channel options and what the
|
|
8
|
+
* sandbox renderer is told — what the text channels (`@dudousxd/nestjs-agent-channels`) and
|
|
9
|
+
* `GET <base>/config` read.
|
|
10
|
+
*/
|
|
11
|
+
declare const AGENT_GENUI: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* The app's genui setup, bound to {@link AGENT_GENUI}: what a text channel draws with
|
|
14
|
+
* (`catalog`, `channels`, `base`) and what the sandbox renderer is told (`sandboxClient`).
|
|
15
|
+
*/
|
|
16
|
+
declare class AgentGenui {
|
|
17
|
+
readonly catalog: Catalog;
|
|
18
|
+
readonly resolveCatalog?: ((scope: GenuiCatalogScope) => Catalog | Promise<Catalog>) | undefined;
|
|
19
|
+
/** `AgentGenuiModule.forRoot({ channels })`, when configured. */
|
|
20
|
+
readonly channels?: GenuiChannels | undefined;
|
|
21
|
+
/** The top-level options a channel falls back to. */
|
|
22
|
+
readonly base: GenuiChannelBase;
|
|
23
|
+
/** What the sandbox renderer is told, when a sandbox is configured. */
|
|
24
|
+
readonly sandboxClient?: (() => SandboxClientConfig) | undefined;
|
|
25
|
+
constructor(catalog: Catalog, resolveCatalog?: ((scope: GenuiCatalogScope) => Catalog | Promise<Catalog>) | undefined,
|
|
26
|
+
/** `AgentGenuiModule.forRoot({ channels })`, when configured. */
|
|
27
|
+
channels?: GenuiChannels | undefined,
|
|
28
|
+
/** The top-level options a channel falls back to. */
|
|
29
|
+
base?: GenuiChannelBase,
|
|
30
|
+
/** What the sandbox renderer is told, when a sandbox is configured. */
|
|
31
|
+
sandboxClient?: (() => SandboxClientConfig) | undefined);
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
/** The app's genui catalog — `@InjectGenuiCatalog()` it anywhere; `overrideProvider` it in tests. */
|
|
7
35
|
declare const GENUI_CATALOG: unique symbol;
|
|
8
36
|
/** The resolved {@link AgentGenuiOptions} (without the resolver). */
|
|
@@ -78,8 +106,46 @@ interface AgentGenuiOptions {
|
|
|
78
106
|
* the {@link DefineSandboxOptions} (a policy listing origins, extra instructions). Off by default.
|
|
79
107
|
* The browser's catalog should carry the same definition (`defineSandbox(...)` in the shared
|
|
80
108
|
* catalog file) so the renderer enforces the same policy.
|
|
109
|
+
*
|
|
110
|
+
* `theme` (default on), `tailwind` and `kit` put the app's design system in the frame. `kit: true`
|
|
111
|
+
* (and the theme's variable names) are found through `sandboxKit`: the descriptor
|
|
112
|
+
* `genuiSandboxKit()` (`@dudousxd/nestjs-agent/vite`) writes in dev, the Vite manifest in
|
|
113
|
+
* production — and `GET <base>/config` tells the renderer where the assets are.
|
|
81
114
|
*/
|
|
82
115
|
sandbox?: boolean | DefineSandboxOptions;
|
|
116
|
+
/**
|
|
117
|
+
* Per-channel generative UI: each entry sets the mode, streaming, sandbox and rendering of one
|
|
118
|
+
* channel (`web`, `mobile`, `whatsapp`, `telegram`, `email`, or `default` for the rest), over the
|
|
119
|
+
* top-level options. A text channel (`@dudousxd/nestjs-agent-channels`) configured here draws the
|
|
120
|
+
* components natively (reply buttons, lists, images). Omitted → every channel is served by the
|
|
121
|
+
* top-level options, as before.
|
|
122
|
+
*/
|
|
123
|
+
channels?: GenuiChannels;
|
|
124
|
+
/**
|
|
125
|
+
* Where the sandbox kit is found (with `sandbox: { kit: true }`, `tailwind: true` or the theme's
|
|
126
|
+
* names). No Vite runs in the Nest process, so: the descriptor the dev plugin writes, else the
|
|
127
|
+
* production Vite manifest (read first when `NODE_ENV=production`).
|
|
128
|
+
*/
|
|
129
|
+
sandboxKit?: AgentGenuiSandboxKitOptions;
|
|
130
|
+
}
|
|
131
|
+
/** {@link AgentGenuiOptions.sandboxKit}. Relative paths resolve against `root`. */
|
|
132
|
+
interface AgentGenuiSandboxKitOptions {
|
|
133
|
+
/** Default `process.cwd()`. */
|
|
134
|
+
root?: string;
|
|
135
|
+
/** The dev descriptor `genuiSandboxKit()` writes. Default `.genui/sandbox-kit.json`. */
|
|
136
|
+
descriptor?: string;
|
|
137
|
+
/**
|
|
138
|
+
* The production Vite manifest, and the directory its `file`s are relative to. Default
|
|
139
|
+
* `{ file: 'public/.vite/manifest.json', outDir: 'public' }`; `false` → none.
|
|
140
|
+
*/
|
|
141
|
+
manifest?: {
|
|
142
|
+
file: string;
|
|
143
|
+
outDir: string;
|
|
144
|
+
} | false;
|
|
145
|
+
/** An explicit kit url (an SPA served from elsewhere), over what is found. */
|
|
146
|
+
kitUrl?: string;
|
|
147
|
+
/** Read the manifest first. Default: `NODE_ENV === 'production'`. */
|
|
148
|
+
production?: boolean;
|
|
83
149
|
}
|
|
84
150
|
type ResolverOption = Type<GenuiCatalogResolver> | GenuiCatalogResolver;
|
|
85
151
|
interface AgentGenuiModuleOptions extends AgentGenuiOptions {
|
|
@@ -107,4 +173,4 @@ declare class AgentGenuiModule {
|
|
|
107
173
|
static forRootAsync(options: AgentGenuiModuleAsyncOptions): DynamicModule;
|
|
108
174
|
}
|
|
109
175
|
|
|
110
|
-
export { AgentGenuiModule, type AgentGenuiModuleAsyncOptions, type AgentGenuiModuleOptions, type AgentGenuiOptions, GENUI_CATALOG, GENUI_OPTIONS, GenuiCatalogResolver, InjectGenuiCatalog };
|
|
176
|
+
export { AGENT_GENUI, AgentGenui, AgentGenuiModule, type AgentGenuiModuleAsyncOptions, type AgentGenuiModuleOptions, type AgentGenuiOptions, type AgentGenuiSandboxKitOptions, GENUI_CATALOG, GENUI_OPTIONS, GenuiCatalogResolver, InjectGenuiCatalog };
|