@silkweave/nestjs 1.9.0 → 1.10.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/build/index.mjs CHANGED
@@ -1,84 +1,73 @@
1
- import { createMcpExpressHandler } from "@silkweave/mcp";
1
+ import { authMiddleware, mcpCors, mcpTransport, oauthRoutes, protectedResourceMetadata, sideloadResource } from "@silkweave/mcp";
2
+ import express from "express";
2
3
  import { ForbiddenException, HttpException, Inject, Injectable, Module, SetMetadata } from "@nestjs/common";
3
4
  import { validateToken } from "@silkweave/auth";
4
- import { SilkweaveError, createAction, silkweave } from "@silkweave/core";
5
+ import { SilkweaveError, createAction, createContext } from "@silkweave/core";
5
6
  import { buildLogLevels } from "@silkweave/logger";
6
7
  import { z } from "zod/v4";
7
8
  import { buildRouter, createActionLogger, resolveAuth } from "@silkweave/trpc";
8
9
  import { createExpressMiddleware } from "@trpc/server/adapters/express";
10
+ import { renderTypegen } from "@silkweave/typegen";
11
+ import { mkdir, writeFile } from "node:fs/promises";
12
+ import { dirname, resolve } from "node:path";
9
13
  import { DiscoveryModule, DiscoveryService, HttpAdapterHost, MetadataScanner, ModuleRef, Reflector } from "@nestjs/core";
10
14
  import { kebabCase } from "change-case";
11
15
  import { GUARDS_METADATA } from "@nestjs/common/constants.js";
12
16
  //#region \0rolldown/runtime.js
13
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
14
- //#endregion
15
- //#region src/lib/slot.ts
16
- function createMiddlewareSlot(label) {
17
- let handler = (_req, res) => {
18
- res.statusCode = 503;
19
- res.setHeader("Content-Type", "application/json");
20
- res.end(JSON.stringify({
21
- error: "not_ready",
22
- message: `${label} adapter has not started yet`
23
- }));
24
- };
25
- return {
26
- middleware: (req, res, next) => handler(req, res, next),
27
- set: (h) => {
28
- handler = h;
29
- }
30
- };
31
- }
32
- /**
33
- * Mount a middleware slot at the given base path on Nest's HTTP adapter and
34
- * return the slot's `set()` callback. The slot middleware is installed
35
- * synchronously so it sits in the Express stack before Nest's later-installed
36
- * 404 catch-all.
37
- */
38
- function reserveSlot(httpAdapter, basePath, label) {
39
- const slot = createMiddlewareSlot(label);
40
- httpAdapter.use(basePath, slot.middleware);
41
- return slot.set;
42
- }
17
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
43
18
  //#endregion
44
19
  //#region src/adapter/mcp.ts
20
+ function compose(...handlers) {
21
+ return (req, res, next) => {
22
+ let i = 0;
23
+ const dispatch = () => {
24
+ const h = handlers[i++];
25
+ if (!h) return next();
26
+ h(req, res, (err) => err ? next(err) : dispatch());
27
+ };
28
+ dispatch();
29
+ };
30
+ }
45
31
  /**
46
- * MCP Streamable HTTP adapter for `@silkweave/nestjs`. Builds the same Express
47
- * sub-app that `@silkweave/mcp`'s `http()` adapter uses internally (via
48
- * `createMcpExpressHandler`) and mounts it on Nest's running HTTP server at
49
- * the configured base path.
32
+ * MCP adapter for `@silkweave/nestjs`. Registers the MCP Streamable HTTP
33
+ * transport, sideload, well-known and OAuth routes individually on Nest's
34
+ * HTTP adapter at the configured `basePath` (default `/mcp`):
50
35
  *
51
- * Routes provided by the mounted sub-app:
52
- * - `POST /mcp`, `GET /mcp`, `DELETE /mcp` — MCP Streamable HTTP transport
53
- * - `GET /resource/:id` sideload resources (large MCP responses)
54
- * - `GET /.well-known/oauth-protected-resource` (when `auth.resourceUrl`/`auth.authorizationServers` set)
55
- * - `GET /authorize`, `POST /token`, `POST /register`, `GET /auth/callback` (when `auth.provider` set)
36
+ * - `POST/GET/DELETE ${basePath}` - Streamable HTTP transport
37
+ * - `GET ${basePath}/resource/:id` - sideload (`sideloadResources` opt-out)
38
+ * - `GET ${basePath}/.well-known/oauth-protected-resource` - RFC 9728 metadata (when `auth.resourceUrl`/`auth.authorizationServers` set)
39
+ * - `GET ${basePath}/authorize`, `POST ${basePath}/token`, `POST ${basePath}/register`, `GET ${basePath}${callbackPath}` (when `auth.provider` set)
56
40
  *
57
- * Note: this adapter mounts an Express sub-app. On `@nestjs/platform-fastify`,
58
- * register `@fastify/express` before this adapter so Nest can serve Express
59
- * middleware.
41
+ * Each route is a real Nest-level route - they show up in
42
+ * `RoutesResolver`'s log and there is no sub-app or middleware-slot
43
+ * indirection.
60
44
  */
61
45
  function mcp(options = {}) {
62
46
  return {
63
47
  name: "mcp",
64
- install: (host) => {
65
- const httpAdapter = host.httpAdapter;
66
- if (!httpAdapter) throw new Error("@silkweave/nestjs mcp(): HttpAdapterHost.httpAdapter is not available.");
67
- const { basePath = "/", auth, ...handlerOptions } = options;
68
- const setHandler = reserveSlot(httpAdapter, basePath === "/" ? "/" : basePath.replace(/\/$/, ""), "MCP");
69
- return (silkweaveOptions, baseContext) => {
70
- const context = baseContext.fork({ adapter: "mcp" });
71
- return {
72
- context,
73
- start: async (actions) => {
74
- setHandler(createMcpExpressHandler(silkweaveOptions, context, actions, {
75
- ...handlerOptions,
76
- auth
77
- }));
78
- },
79
- stop: async () => {}
80
- };
81
- };
48
+ register({ httpAdapter, silkweaveOptions, baseContext, actions }) {
49
+ const basePath = (options.basePath ?? "/mcp").replace(/\/$/, "");
50
+ if (!basePath) throw new Error("@silkweave/nestjs mcp(): basePath cannot be empty or \"/\" - pick a path like \"/mcp\".");
51
+ const adapter = httpAdapter;
52
+ const corsHandler = mcpCors(options.cors ?? true);
53
+ const auth = options.auth;
54
+ const guard = auth ? authMiddleware(auth, baseContext) : null;
55
+ const prefix = (...handlers) => handlers.filter((h) => Boolean(h));
56
+ if (auth?.authorizationServers?.length && auth.resourceUrl) adapter.get(`${basePath}/.well-known/oauth-protected-resource`, ...prefix(corsHandler, protectedResourceMetadata(auth)));
57
+ if (auth?.provider) {
58
+ const oauth = oauthRoutes(auth);
59
+ adapter.get(`${basePath}/.well-known/oauth-authorization-server`, ...prefix(corsHandler, oauth.wellKnownAuthServer));
60
+ adapter.get(`${basePath}/authorize`, ...prefix(corsHandler, oauth.authorize));
61
+ adapter.get(`${basePath}${oauth.callbackPath}`, ...prefix(corsHandler, oauth.callback));
62
+ adapter.post(`${basePath}/token`, ...prefix(corsHandler, ...oauth.token));
63
+ adapter.post(`${basePath}/register`, ...prefix(corsHandler, ...oauth.register));
64
+ }
65
+ const protect = guard ? (h) => compose(guard, h) : (h) => h;
66
+ if (options.sideloadResources !== false) adapter.get(`${basePath}/resource/:id`, ...prefix(corsHandler, protect(sideloadResource({ resourceDir: options.resourceDir }))));
67
+ const transport = mcpTransport(silkweaveOptions, baseContext, actions);
68
+ adapter.post(basePath, ...prefix(corsHandler, express.json(), protect(transport.post)));
69
+ adapter.get(basePath, ...prefix(corsHandler, protect(transport.stream)));
70
+ adapter.delete(basePath, ...prefix(corsHandler, protect(transport.stream)));
82
71
  }
83
72
  };
84
73
  }
@@ -114,7 +103,7 @@ async function readJsonBody(req) {
114
103
  try {
115
104
  resolve(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
116
105
  } catch (err) {
117
- reject(err);
106
+ reject(err instanceof Error ? err : /* @__PURE__ */ new Error("Unable to parse JSON body"));
118
107
  }
119
108
  });
120
109
  req.on("error", reject);
@@ -164,25 +153,8 @@ function handleRestError(err, res) {
164
153
  message: "Internal error"
165
154
  }, 500);
166
155
  }
167
- function buildHandler(actions, context, auth) {
168
- const routes = /* @__PURE__ */ new Map();
169
- for (const action of actions) {
170
- const method = action.kind === "query" ? "GET" : "POST";
171
- routes.set(`${method} ${actionNameToPath(action.name)}`, action);
172
- }
173
- const logger = createRestLogger();
174
- return async (req, res, next) => {
175
- const pathOnly = (req.url ?? "/").split("?")[0];
176
- const key = `${req.method ?? ""} ${pathOnly}`;
177
- const action = routes.get(key);
178
- if (!action) {
179
- if (next) return next();
180
- sendJson(res, {
181
- error: "not_found",
182
- message: `No route for ${req.method} ${pathOnly}`
183
- }, 404);
184
- return;
185
- }
156
+ function createActionHandler(action, context, auth, logger) {
157
+ return async (req, res) => {
186
158
  try {
187
159
  const reqLike = req;
188
160
  let authInfo;
@@ -209,33 +181,28 @@ function buildHandler(actions, context, auth) {
209
181
  };
210
182
  }
211
183
  /**
212
- * REST adapter for `@silkweave/nestjs`. Mounts each discovered `@Action` as a
213
- * route on Nest's running HTTP server:
184
+ * REST adapter for `@silkweave/nestjs`. Registers each discovered `@Action`
185
+ * as an individual route on Nest's HTTP adapter:
214
186
  *
215
- * - `kind: 'query'` → `GET ${basePath}/${actionName-with-slashes}` (input read from query string)
216
- * - `kind: 'mutation'` → `POST ${basePath}/${actionName-with-slashes}` (input read from JSON body)
187
+ * - `kind: 'query'` → `GET ${basePath}/${actionName-with-slashes}` (input from query string)
188
+ * - `kind: 'mutation'` → `POST ${basePath}/${actionName-with-slashes}` (input from JSON body)
217
189
  *
218
- * Works on `@nestjs/platform-express` out of the box. For
219
- * `@nestjs/platform-fastify`, register `@fastify/express` before this adapter
220
- * so Nest can serve Express-style middleware.
190
+ * Routes show up in Nest's `RoutesResolver` logger and are eligible for
191
+ * `@nestjs/swagger` scanning. Works on `@nestjs/platform-express` out of the
192
+ * box. For `@nestjs/platform-fastify`, register `@fastify/express` first.
221
193
  */
222
194
  function rest(options = {}) {
223
195
  return {
224
196
  name: "rest",
225
- install: (host) => {
226
- const httpAdapter = host.httpAdapter;
227
- if (!httpAdapter) throw new Error("@silkweave/nestjs rest(): HttpAdapterHost.httpAdapter is not available.");
228
- const setHandler = reserveSlot(httpAdapter, (options.basePath ?? "").replace(/\/$/, "") || "/", "REST");
229
- return (_silkweaveOptions, baseContext) => {
230
- const context = baseContext.fork({ adapter: "rest" });
231
- return {
232
- context,
233
- start: async (actions) => {
234
- setHandler(buildHandler(actions, context, options.auth));
235
- },
236
- stop: async () => {}
237
- };
238
- };
197
+ register({ httpAdapter, baseContext, actions }) {
198
+ const basePath = (options.basePath ?? "/api").replace(/\/$/, "");
199
+ const logger = createRestLogger();
200
+ for (const action of actions) {
201
+ const path = `${basePath}${actionNameToPath(action.name)}`;
202
+ const method = action.kind === "query" ? "get" : "post";
203
+ const handler = createActionHandler(action, baseContext, options.auth, logger);
204
+ httpAdapter[method](path, handler);
205
+ }
239
206
  }
240
207
  };
241
208
  }
@@ -243,54 +210,75 @@ function rest(options = {}) {
243
210
  //#region src/adapter/trpc.ts
244
211
  /**
245
212
  * tRPC adapter for `@silkweave/nestjs`. Builds a tRPC router from discovered
246
- * `@Action` methods via `@silkweave/trpc`'s `buildRouter` and mounts the
247
- * resulting `createExpressMiddleware()` at the configured base path on Nest's
248
- * underlying HTTP server.
213
+ * `@Action` methods and mounts the resulting express middleware at
214
+ * `basePath` on Nest's HTTP adapter.
249
215
  *
250
216
  * Action names with dots (e.g. `users.list` from `@Actions('users')`) collapse
251
- * to camelCase procedure keys (`usersList`) for v1 — flat router only.
217
+ * to camelCase procedure keys (`usersList`).
252
218
  *
253
219
  * Works on `@nestjs/platform-express`. On `@nestjs/platform-fastify`, register
254
- * `@fastify/express` first so Nest can mount Express-style middleware.
220
+ * `@fastify/express` first so Nest can serve Express-style middleware.
255
221
  */
256
222
  function trpc(options = {}) {
257
223
  return {
258
224
  name: "trpc",
259
- install: (host) => {
260
- const httpAdapter = host.httpAdapter;
261
- if (!httpAdapter) throw new Error("@silkweave/nestjs trpc(): HttpAdapterHost.httpAdapter is not available.");
262
- const setHandler = reserveSlot(httpAdapter, (options.basePath ?? "/trpc").replace(/\/$/, "") || "/", "tRPC");
263
- return (_silkweaveOptions, baseContext) => {
264
- const context = baseContext.fork({ adapter: "trpc" });
265
- return {
266
- context,
267
- start: async (actions) => {
268
- const router = buildRouter(actions);
269
- const logger = createActionLogger();
270
- const createContext = async (opts) => {
271
- const resolved = await resolveAuth(options.auth, opts.req.headers.authorization, context.fork({ request: opts.req }));
272
- if (resolved.kind === "error") {
273
- for (const [key, value] of Object.entries(resolved.error.headers)) opts.res.setHeader(key, value);
274
- opts.res.statusCode = resolved.error.statusCode;
275
- opts.res.setHeader("Content-Type", "application/json");
276
- opts.res.end(JSON.stringify(resolved.error.body));
277
- throw new Error("Unauthorized");
278
- }
279
- return { silkweaveContext: context.fork({
280
- logger,
281
- request: opts.req,
282
- response: opts.res,
283
- ...resolved.authInfo ? { auth: resolved.authInfo } : {}
284
- }) };
285
- };
286
- setHandler(createExpressMiddleware({
287
- router,
288
- createContext
289
- }));
290
- },
291
- stop: async () => {}
292
- };
225
+ register({ httpAdapter, baseContext, actions }) {
226
+ const basePath = (options.basePath ?? "/trpc").replace(/\/$/, "") || "/";
227
+ const router = buildRouter(actions);
228
+ const logger = createActionLogger();
229
+ const createContext = async (opts) => {
230
+ const resolved = await resolveAuth(options.auth, opts.req.headers.authorization, baseContext.fork({ request: opts.req }));
231
+ if (resolved.kind === "error") {
232
+ for (const [key, value] of Object.entries(resolved.error.headers)) opts.res.setHeader(key, value);
233
+ opts.res.statusCode = resolved.error.statusCode;
234
+ opts.res.setHeader("Content-Type", "application/json");
235
+ opts.res.end(JSON.stringify(resolved.error.body));
236
+ throw new Error("Unauthorized");
237
+ }
238
+ return { silkweaveContext: baseContext.fork({
239
+ logger,
240
+ request: opts.req,
241
+ response: opts.res,
242
+ ...resolved.authInfo ? { auth: resolved.authInfo } : {}
243
+ }) };
293
244
  };
245
+ const middleware = createExpressMiddleware({
246
+ router,
247
+ createContext
248
+ });
249
+ httpAdapter.use(basePath, middleware);
250
+ }
251
+ };
252
+ }
253
+ //#endregion
254
+ //#region src/adapter/typegen.ts
255
+ /**
256
+ * Typegen adapter for `@silkweave/nestjs`. Discovers every `@Action`-decorated
257
+ * method (regardless of `transports` filtering) and writes a single `.d.ts`
258
+ * file with REST input/output interfaces and/or a tRPC `AppRouter` type alias.
259
+ *
260
+ * Designed for the monorepo pattern where the server (this app) is the source
261
+ * of truth for types and consumer apps import from `path` - e.g.
262
+ * `path: '../app/src/types/silkweave.ts'`.
263
+ */
264
+ function typegen(options) {
265
+ const enabled = options.enabled ?? process.env["NODE_ENV"] !== "production";
266
+ return {
267
+ name: "typegen",
268
+ allActions: true,
269
+ register({ actions }) {
270
+ if (!enabled) return;
271
+ const output = renderTypegen(actions, options.format ?? "all");
272
+ const target = resolve(options.path);
273
+ (async () => {
274
+ try {
275
+ await mkdir(dirname(target), { recursive: true });
276
+ await writeFile(target, output, "utf-8");
277
+ console.info(`@silkweave/nestjs typegen: wrote ${actions.length} action types to ${target}`);
278
+ } catch (err) {
279
+ console.error("@silkweave/nestjs typegen:", err);
280
+ }
281
+ })();
294
282
  }
295
283
  };
296
284
  }
@@ -341,7 +329,7 @@ function Action(options) {
341
329
  * prefix. The prefix is joined to each method's action name with a dot
342
330
  * (e.g. `@Actions('users')` + method `list` → action name `users.list`).
343
331
  *
344
- * The class itself remains a normal Nest provider add `@Injectable()`
332
+ * The class itself remains a normal Nest provider - add `@Injectable()`
345
333
  * separately so it can be resolved by the DI container.
346
334
  *
347
335
  * Accepts either a prefix string (shorthand) or a full options object:
@@ -9040,7 +9028,7 @@ function collectGuards(reflector, classRef, handler) {
9040
9028
  }
9041
9029
  async function resolveGuard(ref, moduleRef) {
9042
9030
  if (typeof ref === "function") try {
9043
- return moduleRef.get(ref, { strict: false });
9031
+ return await moduleRef.get(ref, { strict: false });
9044
9032
  } catch {
9045
9033
  return moduleRef.create(ref);
9046
9034
  }
@@ -9063,12 +9051,12 @@ async function runGuards(guards, moduleRef, reflector, classRef, handler, reques
9063
9051
  }
9064
9052
  }
9065
9053
  //#endregion
9066
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateMetadata.js
9054
+ //#region \0@oxc-project+runtime@0.127.0/helpers/decorateMetadata.js
9067
9055
  function __decorateMetadata(k, v) {
9068
9056
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9069
9057
  }
9070
9058
  //#endregion
9071
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
9059
+ //#region \0@oxc-project+runtime@0.127.0/helpers/decorate.js
9072
9060
  function __decorate(decorators, target, key, desc) {
9073
9061
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9074
9062
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -9128,6 +9116,31 @@ let ActionDiscovery = class ActionDiscovery {
9128
9116
  const guards = collectGuards(this.reflector, d.classRef, d.method);
9129
9117
  const moduleRef = this.moduleRef;
9130
9118
  const reflector = this.reflector;
9119
+ const applyGuards = async (context) => {
9120
+ if (guards.length === 0) return;
9121
+ const request = context.getOptional("request");
9122
+ const response = context.getOptional("response");
9123
+ await runGuards(guards, moduleRef, reflector, d.classRef, d.method, request, response);
9124
+ };
9125
+ if (d.method.constructor?.name === "AsyncGeneratorFunction") {
9126
+ if (!d.meta.chunk) throw new Error(`@Action "${name}" is an async generator but has no \`chunk\` schema`);
9127
+ const method = d.method;
9128
+ const instance = d.instance;
9129
+ return createAction({
9130
+ name,
9131
+ description: d.meta.description,
9132
+ input: d.meta.input,
9133
+ chunk: d.meta.chunk,
9134
+ kind: d.meta.kind ?? "mutation",
9135
+ args: d.meta.args,
9136
+ isEnabled,
9137
+ toolResult: d.meta.toolResult,
9138
+ run: async function* (input, context) {
9139
+ await applyGuards(context);
9140
+ yield* method.call(instance, input, context);
9141
+ }
9142
+ });
9143
+ }
9131
9144
  return createAction({
9132
9145
  name,
9133
9146
  description: d.meta.description,
@@ -9138,11 +9151,7 @@ let ActionDiscovery = class ActionDiscovery {
9138
9151
  isEnabled,
9139
9152
  toolResult: d.meta.toolResult,
9140
9153
  run: async (input, context) => {
9141
- if (guards.length > 0) {
9142
- const request = context.getOptional("request");
9143
- const response = context.getOptional("response");
9144
- await runGuards(guards, moduleRef, reflector, d.classRef, d.method, request, response);
9145
- }
9154
+ await applyGuards(context);
9146
9155
  return await d.method.call(d.instance, input, context);
9147
9156
  }
9148
9157
  });
@@ -9158,74 +9167,62 @@ ActionDiscovery = __decorate([Injectable(), __decorateMetadata("design:paramtype
9158
9167
  //#region src/lib/types.ts
9159
9168
  const SILKWEAVE_MODULE_OPTIONS = "__silkweave_module_options__";
9160
9169
  //#endregion
9161
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
9170
+ //#region \0@oxc-project+runtime@0.127.0/helpers/decorateParam.js
9162
9171
  function __decorateParam(paramIndex, decorator) {
9163
9172
  return function(target, key) {
9164
9173
  decorator(target, key, paramIndex);
9165
9174
  };
9166
9175
  }
9167
9176
  //#endregion
9168
- //#region src/lib/silkweave.service.ts
9169
- var _ref, _ref2;
9170
- let SilkweaveService = class SilkweaveService {
9177
+ //#region src/lib/silkweave.module.ts
9178
+ var _ref, _ref2, _SilkweaveModule;
9179
+ let SilkweaveModule = _SilkweaveModule = class SilkweaveModule {
9171
9180
  constructor(options, discovery, httpAdapterHost) {
9172
9181
  this.options = options;
9173
9182
  this.discovery = discovery;
9174
9183
  this.httpAdapterHost = httpAdapterHost;
9175
- this.generators = [];
9176
- }
9177
- onModuleInit() {
9178
- for (const adapter of this.options.adapters) this.generators.push(adapter.install(this.httpAdapterHost));
9179
9184
  }
9180
- async onApplicationBootstrap() {
9181
- const actions = this.discovery.discover();
9182
- const builder = silkweave(this.options.silkweave);
9183
- for (const [key, value] of Object.entries(this.options.context ?? {})) builder.set(key, value);
9184
- for (const gen of this.generators) builder.adapter(gen);
9185
- builder.actions(actions);
9186
- await builder.start();
9187
- this.builder = builder;
9188
- }
9189
- async onApplicationShutdown() {
9190
- this.builder = void 0;
9191
- }
9192
- /** Access the underlying silkweave builder once bootstrap has completed. */
9193
- getBuilder() {
9194
- return this.builder;
9185
+ static forRoot(options) {
9186
+ return {
9187
+ module: _SilkweaveModule,
9188
+ global: true,
9189
+ imports: [DiscoveryModule],
9190
+ providers: [{
9191
+ provide: SILKWEAVE_MODULE_OPTIONS,
9192
+ useValue: options
9193
+ }, ActionDiscovery],
9194
+ exports: []
9195
+ };
9196
+ }
9197
+ configure(_consumer) {
9198
+ const httpAdapter = this.httpAdapterHost.httpAdapter;
9199
+ if (!httpAdapter) throw new Error("@silkweave/nestjs: HttpAdapterHost.httpAdapter is not available.");
9200
+ const allActions = this.discovery.discover();
9201
+ for (const adapter of this.options.adapters) {
9202
+ const baseContext = createContext({
9203
+ ...this.options.context ?? {},
9204
+ adapter: adapter.name
9205
+ });
9206
+ const actions = adapter.allActions ? allActions : allActions.filter((a) => !a.isEnabled || a.isEnabled(baseContext));
9207
+ adapter.register({
9208
+ httpAdapter,
9209
+ silkweaveOptions: this.options.silkweave,
9210
+ baseContext,
9211
+ actions
9212
+ });
9213
+ }
9195
9214
  }
9196
9215
  };
9197
- SilkweaveService = __decorate([
9198
- Injectable(),
9216
+ SilkweaveModule = _SilkweaveModule = __decorate([
9217
+ Module({}),
9199
9218
  __decorateParam(0, Inject(SILKWEAVE_MODULE_OPTIONS)),
9200
9219
  __decorateMetadata("design:paramtypes", [
9201
9220
  Object,
9202
9221
  typeof (_ref = typeof ActionDiscovery !== "undefined" && ActionDiscovery) === "function" ? _ref : Object,
9203
9222
  typeof (_ref2 = typeof HttpAdapterHost !== "undefined" && HttpAdapterHost) === "function" ? _ref2 : Object
9204
9223
  ])
9205
- ], SilkweaveService);
9206
- //#endregion
9207
- //#region src/lib/silkweave.module.ts
9208
- var _SilkweaveModule;
9209
- let SilkweaveModule = _SilkweaveModule = class SilkweaveModule {
9210
- static forRoot(options) {
9211
- return {
9212
- module: _SilkweaveModule,
9213
- global: true,
9214
- imports: [DiscoveryModule],
9215
- providers: [
9216
- {
9217
- provide: SILKWEAVE_MODULE_OPTIONS,
9218
- useValue: options
9219
- },
9220
- ActionDiscovery,
9221
- SilkweaveService
9222
- ],
9223
- exports: [SilkweaveService]
9224
- };
9225
- }
9226
- };
9227
- SilkweaveModule = _SilkweaveModule = __decorate([Module({})], SilkweaveModule);
9224
+ ], SilkweaveModule);
9228
9225
  //#endregion
9229
- export { ACTIONS_METADATA, ACTION_METADATA, ACTION_RESPONSE_KEY, Action, ActionDiscovery, Actions, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule, SilkweaveService, buildIsEnabled, collectGuards, mcp, rest, runGuards, trpc };
9226
+ export { ACTIONS_METADATA, ACTION_METADATA, ACTION_RESPONSE_KEY, Action, ActionDiscovery, Actions, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule, buildIsEnabled, collectGuards, mcp, rest, runGuards, trpc, typegen };
9230
9227
 
9231
9228
  //# sourceMappingURL=index.mjs.map