nestjs-apcore 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +304 -0
  2. package/dist/bridge/binding-loader.d.ts +33 -0
  3. package/dist/bridge/binding-loader.d.ts.map +1 -0
  4. package/dist/bridge/binding-loader.js +118 -0
  5. package/dist/bridge/binding-loader.js.map +1 -0
  6. package/dist/bridge/index.d.ts +3 -0
  7. package/dist/bridge/index.d.ts.map +1 -0
  8. package/dist/bridge/index.js +2 -0
  9. package/dist/bridge/index.js.map +1 -0
  10. package/dist/constants.d.ts +6 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +8 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/core/apcore-executor.service.d.ts +42 -0
  15. package/dist/core/apcore-executor.service.d.ts.map +1 -0
  16. package/dist/core/apcore-executor.service.js +68 -0
  17. package/dist/core/apcore-executor.service.js.map +1 -0
  18. package/dist/core/apcore-registry.service.d.ts +52 -0
  19. package/dist/core/apcore-registry.service.d.ts.map +1 -0
  20. package/dist/core/apcore-registry.service.js +181 -0
  21. package/dist/core/apcore-registry.service.js.map +1 -0
  22. package/dist/core/apcore.module.d.ts +27 -0
  23. package/dist/core/apcore.module.d.ts.map +1 -0
  24. package/dist/core/apcore.module.js +105 -0
  25. package/dist/core/apcore.module.js.map +1 -0
  26. package/dist/decorators/ap-context.decorator.d.ts +2 -0
  27. package/dist/decorators/ap-context.decorator.d.ts.map +1 -0
  28. package/dist/decorators/ap-context.decorator.js +9 -0
  29. package/dist/decorators/ap-context.decorator.js.map +1 -0
  30. package/dist/decorators/ap-module.decorator.d.ts +3 -0
  31. package/dist/decorators/ap-module.decorator.d.ts.map +1 -0
  32. package/dist/decorators/ap-module.decorator.js +7 -0
  33. package/dist/decorators/ap-module.decorator.js.map +1 -0
  34. package/dist/decorators/ap-tool-scanner.service.d.ts +28 -0
  35. package/dist/decorators/ap-tool-scanner.service.d.ts.map +1 -0
  36. package/dist/decorators/ap-tool-scanner.service.js +166 -0
  37. package/dist/decorators/ap-tool-scanner.service.js.map +1 -0
  38. package/dist/decorators/ap-tool.decorator.d.ts +3 -0
  39. package/dist/decorators/ap-tool.decorator.d.ts.map +1 -0
  40. package/dist/decorators/ap-tool.decorator.js +7 -0
  41. package/dist/decorators/ap-tool.decorator.js.map +1 -0
  42. package/dist/decorators/index.d.ts +4 -0
  43. package/dist/decorators/index.d.ts.map +1 -0
  44. package/dist/decorators/index.js +4 -0
  45. package/dist/decorators/index.js.map +1 -0
  46. package/dist/index.d.ts +23 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +41 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/mcp/apcore-mcp.module.d.ts +28 -0
  51. package/dist/mcp/apcore-mcp.module.d.ts.map +1 -0
  52. package/dist/mcp/apcore-mcp.module.js +77 -0
  53. package/dist/mcp/apcore-mcp.module.js.map +1 -0
  54. package/dist/mcp/apcore-mcp.service.d.ts +53 -0
  55. package/dist/mcp/apcore-mcp.service.d.ts.map +1 -0
  56. package/dist/mcp/apcore-mcp.service.js +148 -0
  57. package/dist/mcp/apcore-mcp.service.js.map +1 -0
  58. package/dist/schema/adapters/dto.adapter.d.ts +44 -0
  59. package/dist/schema/adapters/dto.adapter.d.ts.map +1 -0
  60. package/dist/schema/adapters/dto.adapter.js +191 -0
  61. package/dist/schema/adapters/dto.adapter.js.map +1 -0
  62. package/dist/schema/adapters/json-schema.adapter.d.ts +30 -0
  63. package/dist/schema/adapters/json-schema.adapter.d.ts.map +1 -0
  64. package/dist/schema/adapters/json-schema.adapter.js +48 -0
  65. package/dist/schema/adapters/json-schema.adapter.js.map +1 -0
  66. package/dist/schema/adapters/schema-adapter.interface.d.ts +21 -0
  67. package/dist/schema/adapters/schema-adapter.interface.d.ts.map +1 -0
  68. package/dist/schema/adapters/schema-adapter.interface.js +2 -0
  69. package/dist/schema/adapters/schema-adapter.interface.js.map +1 -0
  70. package/dist/schema/adapters/typebox.adapter.d.ts +32 -0
  71. package/dist/schema/adapters/typebox.adapter.d.ts.map +1 -0
  72. package/dist/schema/adapters/typebox.adapter.js +46 -0
  73. package/dist/schema/adapters/typebox.adapter.js.map +1 -0
  74. package/dist/schema/adapters/zod.adapter.d.ts +16 -0
  75. package/dist/schema/adapters/zod.adapter.d.ts.map +1 -0
  76. package/dist/schema/adapters/zod.adapter.js +184 -0
  77. package/dist/schema/adapters/zod.adapter.js.map +1 -0
  78. package/dist/schema/schema-extractor.service.d.ts +58 -0
  79. package/dist/schema/schema-extractor.service.d.ts.map +1 -0
  80. package/dist/schema/schema-extractor.service.js +100 -0
  81. package/dist/schema/schema-extractor.service.js.map +1 -0
  82. package/dist/types.d.ts +106 -0
  83. package/dist/types.d.ts.map +1 -0
  84. package/dist/types.js +2 -0
  85. package/dist/types.js.map +1 -0
  86. package/dist/utils/id-generator.d.ts +41 -0
  87. package/dist/utils/id-generator.d.ts.map +1 -0
  88. package/dist/utils/id-generator.js +87 -0
  89. package/dist/utils/id-generator.js.map +1 -0
  90. package/package.json +100 -0
@@ -0,0 +1,52 @@
1
+ import type { Registry } from 'apcore-js';
2
+ import type { ModuleDescriptor } from 'apcore-js';
3
+ import type { RegisterMethodOptions, RegisterServiceOptions } from '../types.js';
4
+ /**
5
+ * NestJS-injectable service that wraps an upstream apcore-js Registry,
6
+ * delegating core operations and adding convenience methods for
7
+ * registering NestJS service methods as FunctionModules.
8
+ */
9
+ export declare class ApcoreRegistryService {
10
+ private readonly registry;
11
+ constructor(registry: Registry);
12
+ /** Return the underlying apcore-js Registry instance. */
13
+ get raw(): Registry;
14
+ register(moduleId: string, module: unknown): void;
15
+ unregister(moduleId: string): boolean;
16
+ get(moduleId: string): unknown | null;
17
+ has(moduleId: string): boolean;
18
+ list(options?: {
19
+ tags?: string[];
20
+ prefix?: string;
21
+ }): string[];
22
+ getDefinition(moduleId: string): ModuleDescriptor | null;
23
+ on(event: string, callback: (moduleId: string, module: unknown) => void): void;
24
+ discover(): Promise<number>;
25
+ get count(): number;
26
+ /**
27
+ * Register a single method from a service instance as a FunctionModule.
28
+ *
29
+ * Generates a module ID from the class name + method name when no
30
+ * explicit id is provided (e.g. EmailService.sendEmail -> email.send_email).
31
+ *
32
+ * The execute function calls the method on the bound instance and
33
+ * normalizes the return value:
34
+ * - null / undefined -> {}
35
+ * - non-object -> { result: value }
36
+ * - object -> returned as-is
37
+ *
38
+ * @returns The module ID under which the method was registered.
39
+ */
40
+ registerMethod(options: RegisterMethodOptions): string;
41
+ /**
42
+ * Register multiple methods from a service instance as FunctionModules.
43
+ *
44
+ * When `methods` is `'*'`, all public methods are discovered via
45
+ * prototype inspection (excluding 'constructor' and any names in the
46
+ * `exclude` array).
47
+ *
48
+ * @returns An array of module IDs that were registered.
49
+ */
50
+ registerService(options: RegisterServiceOptions): string[];
51
+ }
52
+ //# sourceMappingURL=apcore-registry.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apcore-registry.service.d.ts","sourceRoot":"","sources":["../../src/core/apcore-registry.service.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AA+CjF;;;;GAIG;AACH,qBACa,qBAAqB;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAI/C,yDAAyD;IACzD,IAAI,GAAG,IAAI,QAAQ,CAElB;IAID,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAIjD,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIrC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAIrC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI9B,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAI9D,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAIxD,EAAE,CACA,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GACpD,IAAI;IAIP,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3B,IAAI,KAAK,IAAI,MAAM,CAElB;IAID;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM;IA4CtD;;;;;;;;OAQG;IACH,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,EAAE;CAwD3D"}
@@ -0,0 +1,181 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Injectable } from '@nestjs/common';
11
+ import { Type as t } from '@sinclair/typebox';
12
+ import { FunctionModule } from 'apcore-js';
13
+ import { normalizeClassName, normalizeMethodName, generateModuleId, } from '../utils/id-generator.js';
14
+ /**
15
+ * Normalize a method return value to a Record<string, unknown>.
16
+ *
17
+ * - null / undefined -> {}
18
+ * - non-object (string, number, boolean) -> { result: value }
19
+ * - object -> returned as-is
20
+ */
21
+ function normalizeReturnValue(value) {
22
+ if (value == null) {
23
+ return {};
24
+ }
25
+ if (typeof value !== 'object' || Array.isArray(value)) {
26
+ return { result: value };
27
+ }
28
+ return value;
29
+ }
30
+ /**
31
+ * Collect all own method names from a prototype chain up to (but not
32
+ * including) Object.prototype. Excludes 'constructor'.
33
+ */
34
+ function getAllMethodNames(instance) {
35
+ const methods = new Set();
36
+ let proto = Object.getPrototypeOf(instance);
37
+ while (proto && proto !== Object.prototype) {
38
+ for (const name of Object.getOwnPropertyNames(proto)) {
39
+ if (name !== 'constructor' &&
40
+ typeof proto[name] === 'function') {
41
+ methods.add(name);
42
+ }
43
+ }
44
+ proto = Object.getPrototypeOf(proto);
45
+ }
46
+ return [...methods];
47
+ }
48
+ /**
49
+ * NestJS-injectable service that wraps an upstream apcore-js Registry,
50
+ * delegating core operations and adding convenience methods for
51
+ * registering NestJS service methods as FunctionModules.
52
+ */
53
+ let ApcoreRegistryService = class ApcoreRegistryService {
54
+ registry;
55
+ constructor(registry) {
56
+ this.registry = registry;
57
+ }
58
+ // ---- raw access ----
59
+ /** Return the underlying apcore-js Registry instance. */
60
+ get raw() {
61
+ return this.registry;
62
+ }
63
+ // ---- delegated methods ----
64
+ register(moduleId, module) {
65
+ this.registry.register(moduleId, module);
66
+ }
67
+ unregister(moduleId) {
68
+ return this.registry.unregister(moduleId);
69
+ }
70
+ get(moduleId) {
71
+ return this.registry.get(moduleId);
72
+ }
73
+ has(moduleId) {
74
+ return this.registry.has(moduleId);
75
+ }
76
+ list(options) {
77
+ return this.registry.list(options);
78
+ }
79
+ getDefinition(moduleId) {
80
+ return this.registry.getDefinition(moduleId);
81
+ }
82
+ on(event, callback) {
83
+ this.registry.on(event, callback);
84
+ }
85
+ discover() {
86
+ return this.registry.discover();
87
+ }
88
+ get count() {
89
+ return this.registry.count;
90
+ }
91
+ // ---- NestJS convenience methods ----
92
+ /**
93
+ * Register a single method from a service instance as a FunctionModule.
94
+ *
95
+ * Generates a module ID from the class name + method name when no
96
+ * explicit id is provided (e.g. EmailService.sendEmail -> email.send_email).
97
+ *
98
+ * The execute function calls the method on the bound instance and
99
+ * normalizes the return value:
100
+ * - null / undefined -> {}
101
+ * - non-object -> { result: value }
102
+ * - object -> returned as-is
103
+ *
104
+ * @returns The module ID under which the method was registered.
105
+ */
106
+ registerMethod(options) {
107
+ const { instance, method, description, id, inputSchema, outputSchema, annotations, tags, documentation, examples, } = options;
108
+ // Validate the method exists on the instance
109
+ const fn = instance[method];
110
+ if (typeof fn !== 'function') {
111
+ throw new Error(`Method "${method}" does not exist on ${instance.constructor.name}`);
112
+ }
113
+ const className = instance.constructor.name;
114
+ const moduleId = generateModuleId(className, method, true, id);
115
+ const funcModule = new FunctionModule({
116
+ moduleId,
117
+ description,
118
+ inputSchema: inputSchema ?? t.Object({}),
119
+ outputSchema: outputSchema ?? t.Object({}),
120
+ tags: tags ?? null,
121
+ annotations: annotations,
122
+ documentation: documentation ?? null,
123
+ examples: examples ?? null,
124
+ execute: async (inputs) => {
125
+ const raw = await fn.call(instance, inputs);
126
+ return normalizeReturnValue(raw);
127
+ },
128
+ });
129
+ this.registry.register(moduleId, funcModule);
130
+ return moduleId;
131
+ }
132
+ /**
133
+ * Register multiple methods from a service instance as FunctionModules.
134
+ *
135
+ * When `methods` is `'*'`, all public methods are discovered via
136
+ * prototype inspection (excluding 'constructor' and any names in the
137
+ * `exclude` array).
138
+ *
139
+ * @returns An array of module IDs that were registered.
140
+ */
141
+ registerService(options) {
142
+ const { instance, description, methods, exclude = [], namespace, annotations, tags, methodOptions = {}, } = options;
143
+ // Determine which methods to register
144
+ let methodNames;
145
+ if (methods === '*') {
146
+ methodNames = getAllMethodNames(instance).filter((name) => !exclude.includes(name));
147
+ }
148
+ else {
149
+ methodNames = methods.filter((name) => !exclude.includes(name));
150
+ }
151
+ const registeredIds = [];
152
+ for (const methodName of methodNames) {
153
+ const perMethodOpts = methodOptions[methodName] ?? {};
154
+ // Build the namespace: explicit namespace > normalized class name
155
+ const ns = namespace ?? normalizeClassName(instance.constructor.name);
156
+ const normalizedMethod = normalizeMethodName(methodName);
157
+ const methodDesc = perMethodOpts.description ?? description ?? `${methodName}`;
158
+ const moduleId = perMethodOpts.id ?? `${ns}.${normalizedMethod}`;
159
+ const id = this.registerMethod({
160
+ instance,
161
+ method: methodName,
162
+ description: methodDesc,
163
+ id: moduleId,
164
+ inputSchema: perMethodOpts.inputSchema,
165
+ outputSchema: perMethodOpts.outputSchema,
166
+ annotations: perMethodOpts.annotations ?? annotations,
167
+ tags: perMethodOpts.tags ?? tags,
168
+ documentation: perMethodOpts.documentation,
169
+ examples: perMethodOpts.examples,
170
+ });
171
+ registeredIds.push(id);
172
+ }
173
+ return registeredIds;
174
+ }
175
+ };
176
+ ApcoreRegistryService = __decorate([
177
+ Injectable(),
178
+ __metadata("design:paramtypes", [Function])
179
+ ], ApcoreRegistryService);
180
+ export { ApcoreRegistryService };
181
+ //# sourceMappingURL=apcore-registry.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apcore-registry.service.js","sourceRoot":"","sources":["../../src/core/apcore-registry.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAI3C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,K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/**
4
+ * Main NestJS dynamic module for the apcore ecosystem.
5
+ *
6
+ * Marked `@Global()` so that {@link ApcoreRegistryService} and
7
+ * {@link ApcoreExecutorService} are available application-wide without
8
+ * importing this module into every feature module.
9
+ */
10
+ export declare class ApcoreModule {
11
+ /**
12
+ * Synchronous configuration.
13
+ *
14
+ * Creates an upstream `Registry` and `Executor` from the supplied options,
15
+ * wraps them in NestJS-injectable services, and exports them together with
16
+ * the raw options token.
17
+ */
18
+ static forRoot(options: ApcoreModuleOptions): DynamicModule;
19
+ /**
20
+ * Asynchronous configuration using the `useFactory` / `inject` pattern.
21
+ *
22
+ * Supports an `imports` array so that injected dependencies (e.g. a
23
+ * ConfigService) are available to the factory function.
24
+ */
25
+ static forRootAsync(options: ApcoreModuleAsyncOptions): DynamicModule;
26
+ }
27
+ //# sourceMappingURL=apcore.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apcore.module.d.ts","sourceRoot":"","sources":["../../src/core/apcore.module.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAMpE,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,qBAEa,YAAY;IACvB;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;IA6B3D;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;CA2CtE"}
@@ -0,0 +1,105 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var ApcoreModule_1;
8
+ import { Global, Module } from '@nestjs/common';
9
+ import { Registry, Executor } from 'apcore-js';
10
+ import { ApcoreRegistryService } from './apcore-registry.service.js';
11
+ import { ApcoreExecutorService } from './apcore-executor.service.js';
12
+ import { APCORE_MODULE_OPTIONS } from '../constants.js';
13
+ /**
14
+ * Main NestJS dynamic module for the apcore ecosystem.
15
+ *
16
+ * Marked `@Global()` so that {@link ApcoreRegistryService} and
17
+ * {@link ApcoreExecutorService} are available application-wide without
18
+ * importing this module into every feature module.
19
+ */
20
+ let ApcoreModule = ApcoreModule_1 = class ApcoreModule {
21
+ /**
22
+ * Synchronous configuration.
23
+ *
24
+ * Creates an upstream `Registry` and `Executor` from the supplied options,
25
+ * wraps them in NestJS-injectable services, and exports them together with
26
+ * the raw options token.
27
+ */
28
+ static forRoot(options) {
29
+ const registry = new Registry({
30
+ extensionsDir: options.extensionsDir ?? null,
31
+ });
32
+ const executor = new Executor({
33
+ registry,
34
+ acl: options.acl ?? null,
35
+ middlewares: options.middleware ?? null,
36
+ });
37
+ const registryService = new ApcoreRegistryService(registry);
38
+ const executorService = new ApcoreExecutorService(executor);
39
+ return {
40
+ module: ApcoreModule_1,
41
+ providers: [
42
+ { provide: APCORE_MODULE_OPTIONS, useValue: options },
43
+ { provide: ApcoreRegistryService, useValue: registryService },
44
+ { provide: ApcoreExecutorService, useValue: executorService },
45
+ ],
46
+ exports: [
47
+ APCORE_MODULE_OPTIONS,
48
+ ApcoreRegistryService,
49
+ ApcoreExecutorService,
50
+ ],
51
+ };
52
+ }
53
+ /**
54
+ * Asynchronous configuration using the `useFactory` / `inject` pattern.
55
+ *
56
+ * Supports an `imports` array so that injected dependencies (e.g. a
57
+ * ConfigService) are available to the factory function.
58
+ */
59
+ static forRootAsync(options) {
60
+ return {
61
+ module: ApcoreModule_1,
62
+ imports: (options.imports ?? []),
63
+ providers: [
64
+ {
65
+ provide: APCORE_MODULE_OPTIONS,
66
+ useFactory: options.useFactory,
67
+ inject: (options.inject ?? []),
68
+ },
69
+ {
70
+ provide: ApcoreRegistryService,
71
+ useFactory: (opts) => {
72
+ const registry = new Registry({
73
+ extensionsDir: opts.extensionsDir ?? null,
74
+ });
75
+ return new ApcoreRegistryService(registry);
76
+ },
77
+ inject: [APCORE_MODULE_OPTIONS],
78
+ },
79
+ {
80
+ provide: ApcoreExecutorService,
81
+ useFactory: (opts, registryService) => {
82
+ const executor = new Executor({
83
+ registry: registryService.raw,
84
+ acl: opts.acl ?? null,
85
+ middlewares: opts.middleware ?? null,
86
+ });
87
+ return new ApcoreExecutorService(executor);
88
+ },
89
+ inject: [APCORE_MODULE_OPTIONS, ApcoreRegistryService],
90
+ },
91
+ ],
92
+ exports: [
93
+ APCORE_MODULE_OPTIONS,
94
+ ApcoreRegistryService,
95
+ ApcoreExecutorService,
96
+ ],
97
+ };
98
+ }
99
+ };
100
+ ApcoreModule = ApcoreModule_1 = __decorate([
101
+ Global(),
102
+ Module({})
103
+ ], ApcoreModule);
104
+ export { ApcoreModule };
105
+ //# sourceMappingURL=apcore.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apcore.module.js","sourceRoot":"","sources":["../../src/core/apcore.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAMxD;;;;;;GAMG;AAGI,IAAM,YAAY,oBAAlB,MAAM,YAAY;IACvB;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,OAA4B;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Aa,IAAI,IAAI;yBAC1C,CAAC,CAAC;wBACH,OAAO,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAAC;oBAC7C,CAAC;oBACD,MAAM,EAAE,CAAC,qBAAqB,CAAC;iBAChC;gBACD;oBACE,OAAO,EAAE,qBAAqB;oBAC9B,UAAU,EAAE,CACV,IAAyB,EACzB,eAAsC,EACtC,EAAE;wBACF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;4BAC5B,QAAQ,EAAE,eAAe,CAAC,GAAG;4BAC7B,GAAG,EAAG,IAAI,CAAC,GAAkB,IAAI,IAAI;4BACrC,WAAW,EAAG,IAAI,CAAC,UAA2B,IAAI,IAAI;yBACvD,CAAC,CAAC;wBACH,OAAO,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAAC;oBAC7C,CAAC;oBACD,MAAM,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;iBACvD;aACF;YACD,OAAO,EAAE;gBACP,qBAAqB;gBACrB,qBAAqB;gBACrB,qBAAqB;aACtB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAtFY,YAAY;IAFxB,MAAM,EAAE;IACR,MAAM,CAAC,EAAE,CAAC;GACE,YAAY,CAsFxB"}
@@ -0,0 +1,2 @@
1
+ export declare function ApContext(): ParameterDecorator;
2
+ //# sourceMappingURL=ap-context.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-context.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ap-context.decorator.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,IAAI,kBAAkB,CAM9C"}
@@ -0,0 +1,9 @@
1
+ import { AP_CONTEXT_METADATA_KEY } from '../constants.js';
2
+ export function ApContext() {
3
+ return (target, propertyKey, parameterIndex) => {
4
+ if (propertyKey !== undefined) {
5
+ Reflect.defineMetadata(AP_CONTEXT_METADATA_KEY, parameterIndex, target, propertyKey);
6
+ }
7
+ };
8
+ }
9
+ //# sourceMappingURL=ap-context.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-context.decorator.js","sourceRoot":"","sources":["../../src/decorators/ap-context.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,UAAU,SAAS;IACvB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;QAC7C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,CAAC,cAAc,CAAC,uBAAuB,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACvF,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ApModuleOptions } from '../types.js';
2
+ export declare function ApModule(options: ApModuleOptions): ClassDecorator;
3
+ //# sourceMappingURL=ap-module.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-module.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ap-module.decorator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAIjE"}
@@ -0,0 +1,7 @@
1
+ import { AP_MODULE_METADATA_KEY } from '../constants.js';
2
+ export function ApModule(options) {
3
+ return (target) => {
4
+ Reflect.defineMetadata(AP_MODULE_METADATA_KEY, options, target);
5
+ };
6
+ }
7
+ //# sourceMappingURL=ap-module.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-module.decorator.js","sourceRoot":"","sources":["../../src/decorators/ap-module.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,UAAU,QAAQ,CAAC,OAAwB;IAC/C,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,CAAC,cAAc,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type OnModuleInit } from '@nestjs/common';
2
+ import { ModulesContainer } from '@nestjs/core';
3
+ import { ApcoreRegistryService } from '../core/apcore-registry.service.js';
4
+ /**
5
+ * NestJS service that auto-discovers and registers `@ApTool` decorated
6
+ * methods at module initialization time.
7
+ *
8
+ * Iterates all providers in all NestJS modules via `ModulesContainer`,
9
+ * reads decorator metadata, and registers each decorated method as a
10
+ * module in the `ApcoreRegistryService`.
11
+ */
12
+ export declare class ApToolScannerService implements OnModuleInit {
13
+ private readonly registry;
14
+ private readonly modulesContainer;
15
+ private readonly schemaExtractor;
16
+ constructor(registry: ApcoreRegistryService, modulesContainer: ModulesContainer);
17
+ onModuleInit(): void;
18
+ /**
19
+ * Scan all NestJS providers for @ApTool decorated methods and register
20
+ * them in the apcore registry.
21
+ */
22
+ private scan;
23
+ /**
24
+ * Scan a single provider instance for @ApTool decorated methods.
25
+ */
26
+ private scanProvider;
27
+ }
28
+ //# sourceMappingURL=ap-tool-scanner.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-tool-scanner.service.d.ts","sourceRoot":"","sources":["../../src/decorators/ap-tool-scanner.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AA8C3E;;;;;;;GAOG;AACH,qBACa,oBAAqB,YAAW,YAAY;IAKrD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAEzB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IANnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAyB;gBAItC,QAAQ,EAAE,qBAAqB,EAE/B,gBAAgB,EAAE,gBAAgB;IAGrD,YAAY,IAAI,IAAI;IAIpB;;;OAGG;IACH,OAAO,CAAC,IAAI;IAgBZ;;OAEG;IACH,OAAO,CAAC,YAAY;CAyGrB"}
@@ -0,0 +1,166 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Inject, Injectable } from '@nestjs/common';
14
+ import { ModulesContainer } from '@nestjs/core';
15
+ import { Type as t } from '@sinclair/typebox';
16
+ import { FunctionModule } from 'apcore-js';
17
+ import { ApcoreRegistryService } from '../core/apcore-registry.service.js';
18
+ import { SchemaExtractor } from '../schema/schema-extractor.service.js';
19
+ import { AP_TOOL_METADATA_KEY, AP_MODULE_METADATA_KEY, AP_CONTEXT_METADATA_KEY, } from '../constants.js';
20
+ import { normalizeClassName, normalizeMethodName, generateModuleId, } from '../utils/id-generator.js';
21
+ /**
22
+ * Normalize a method return value to a Record<string, unknown>.
23
+ *
24
+ * - null / undefined -> {}
25
+ * - non-object (string, number, boolean, array) -> { result: value }
26
+ * - object -> returned as-is
27
+ */
28
+ function normalizeReturnValue(value) {
29
+ if (value == null) {
30
+ return {};
31
+ }
32
+ if (typeof value !== 'object' || Array.isArray(value)) {
33
+ return { result: value };
34
+ }
35
+ return value;
36
+ }
37
+ /**
38
+ * Try to extract a TSchema from the given input using SchemaExtractor.
39
+ * Falls back to the raw value if extraction fails.
40
+ */
41
+ function tryExtractSchema(extractor, input) {
42
+ try {
43
+ return extractor.extract(input);
44
+ }
45
+ catch {
46
+ return input;
47
+ }
48
+ }
49
+ /**
50
+ * NestJS service that auto-discovers and registers `@ApTool` decorated
51
+ * methods at module initialization time.
52
+ *
53
+ * Iterates all providers in all NestJS modules via `ModulesContainer`,
54
+ * reads decorator metadata, and registers each decorated method as a
55
+ * module in the `ApcoreRegistryService`.
56
+ */
57
+ let ApToolScannerService = class ApToolScannerService {
58
+ registry;
59
+ modulesContainer;
60
+ schemaExtractor = new SchemaExtractor();
61
+ constructor(registry, modulesContainer) {
62
+ this.registry = registry;
63
+ this.modulesContainer = modulesContainer;
64
+ }
65
+ onModuleInit() {
66
+ this.scan();
67
+ }
68
+ /**
69
+ * Scan all NestJS providers for @ApTool decorated methods and register
70
+ * them in the apcore registry.
71
+ */
72
+ scan() {
73
+ for (const nestModule of this.modulesContainer.values()) {
74
+ for (const wrapper of nestModule.providers.values()) {
75
+ const instance = wrapper.instance;
76
+ const metatype = wrapper.metatype;
77
+ // Skip providers without a real instance or metatype (e.g. value providers)
78
+ if (!instance || !metatype || typeof metatype !== 'function') {
79
+ continue;
80
+ }
81
+ this.scanProvider(instance, metatype);
82
+ }
83
+ }
84
+ }
85
+ /**
86
+ * Scan a single provider instance for @ApTool decorated methods.
87
+ */
88
+ scanProvider(instance, metatype) {
89
+ // Read @ApModule metadata from the class (if any) to get namespace
90
+ const moduleOptions = Reflect.getMetadata(AP_MODULE_METADATA_KEY, metatype);
91
+ const namespace = moduleOptions?.namespace ?? normalizeClassName(metatype.name);
92
+ // Iterate all methods on the prototype
93
+ const prototype = Object.getPrototypeOf(instance);
94
+ if (!prototype)
95
+ return;
96
+ const methodNames = Object.getOwnPropertyNames(prototype).filter((name) => {
97
+ if (name === 'constructor')
98
+ return false;
99
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
100
+ // Only include actual methods (not getters/setters)
101
+ return descriptor !== undefined && typeof descriptor.value === 'function';
102
+ });
103
+ for (const methodName of methodNames) {
104
+ // Check for @ApTool metadata on this method
105
+ const toolOptions = Reflect.getMetadata(AP_TOOL_METADATA_KEY, prototype, methodName);
106
+ if (!toolOptions)
107
+ continue;
108
+ // Read @ApContext metadata (parameter index) if present
109
+ const contextIndex = Reflect.getMetadata(AP_CONTEXT_METADATA_KEY, prototype, methodName);
110
+ // Generate module ID
111
+ const normalizedMethod = normalizeMethodName(methodName);
112
+ const moduleId = toolOptions.id ?? generateModuleId(namespace, normalizedMethod);
113
+ // Extract schemas via SchemaExtractor (try/catch, use raw on failure)
114
+ let inputSchema = t.Object({});
115
+ let outputSchema = t.Object({});
116
+ if (toolOptions.inputSchema != null) {
117
+ inputSchema = tryExtractSchema(this.schemaExtractor, toolOptions.inputSchema);
118
+ }
119
+ if (toolOptions.outputSchema != null) {
120
+ outputSchema = tryExtractSchema(this.schemaExtractor, toolOptions.outputSchema);
121
+ }
122
+ // Build the execute function
123
+ const fn = instance[methodName];
124
+ const execute = async (inputs, context) => {
125
+ let raw;
126
+ if (contextIndex != null) {
127
+ const args = [];
128
+ if (contextIndex === 0) {
129
+ args[0] = context;
130
+ args[1] = inputs;
131
+ }
132
+ else {
133
+ args[0] = inputs;
134
+ args[contextIndex] = context;
135
+ }
136
+ raw = await fn.call(instance, ...args);
137
+ }
138
+ else {
139
+ raw = await fn.call(instance, inputs);
140
+ }
141
+ return normalizeReturnValue(raw);
142
+ };
143
+ const funcModule = new FunctionModule({
144
+ moduleId,
145
+ description: toolOptions.description,
146
+ inputSchema,
147
+ outputSchema,
148
+ tags: toolOptions.tags ?? null,
149
+ annotations: toolOptions.annotations ?? null,
150
+ documentation: toolOptions.documentation ?? null,
151
+ examples: toolOptions.examples ?? null,
152
+ execute,
153
+ });
154
+ this.registry.register(moduleId, funcModule);
155
+ }
156
+ }
157
+ };
158
+ ApToolScannerService = __decorate([
159
+ Injectable(),
160
+ __param(0, Inject(ApcoreRegistryService)),
161
+ __param(1, Inject(ModulesContainer)),
162
+ __metadata("design:paramtypes", [ApcoreRegistryService,
163
+ ModulesContainer])
164
+ ], ApToolScannerService);
165
+ export { ApToolScannerService };
166
+ //# sourceMappingURL=ap-tool-scanner.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-tool-scanner.service.js","sourceRoot":"","sources":["../../src/decorators/ap-tool-scanner.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAqB,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAGlC;;;;;;GAMG;AACH,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC3B,CAAC;IACD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACvB,SAA0B,EAC1B,KAAc;IAEd,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IA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QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF,CAAA;AA9IY,oBAAoB;IADhC,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAE7B,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;qCADE,qBAAqB;QAEb,gBAAgB;GAP1C,oBAAoB,CA8IhC"}
@@ -0,0 +1,3 @@
1
+ import type { ApToolOptions } from '../types.js';
2
+ export declare function ApTool(options: ApToolOptions): MethodDecorator;
3
+ //# sourceMappingURL=ap-tool.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ap-tool.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ap-tool.decorator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,eAAe,CAI9D"}