katanakit-js 6.2.0 → 6.6.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.
Files changed (116) hide show
  1. package/README.md +11 -3
  2. package/dist/adapters/better-auth/better-auth.service.d.ts +83 -0
  3. package/dist/adapters/better-auth/better-auth.service.d.ts.map +1 -0
  4. package/dist/adapters/better-auth/better-auth.service.js +110 -0
  5. package/dist/adapters/better-auth/better-auth.service.js.map +1 -0
  6. package/dist/adapters/better-auth/client.d.ts +51 -0
  7. package/dist/adapters/better-auth/client.d.ts.map +1 -0
  8. package/dist/adapters/better-auth/client.js +67 -0
  9. package/dist/adapters/better-auth/client.js.map +1 -0
  10. package/dist/adapters/better-auth/index.d.ts +3 -0
  11. package/dist/adapters/better-auth/index.d.ts.map +1 -0
  12. package/dist/adapters/better-auth/index.js +3 -0
  13. package/dist/adapters/better-auth/index.js.map +1 -0
  14. package/dist/adapters/express/server.d.ts +133 -1
  15. package/dist/adapters/express/server.d.ts.map +1 -1
  16. package/dist/adapters/express/server.js +199 -97
  17. package/dist/adapters/express/server.js.map +1 -1
  18. package/dist/adapters/index.d.ts +2 -0
  19. package/dist/adapters/index.d.ts.map +1 -1
  20. package/dist/adapters/index.js +2 -0
  21. package/dist/adapters/index.js.map +1 -1
  22. package/dist/adapters/insforge/insforge.service.d.ts +139 -4
  23. package/dist/adapters/insforge/insforge.service.d.ts.map +1 -1
  24. package/dist/adapters/insforge/insforge.service.js +383 -213
  25. package/dist/adapters/insforge/insforge.service.js.map +1 -1
  26. package/dist/adapters/notion/notion.service.d.ts +130 -144
  27. package/dist/adapters/notion/notion.service.d.ts.map +1 -1
  28. package/dist/adapters/notion/notion.service.js +330 -341
  29. package/dist/adapters/notion/notion.service.js.map +1 -1
  30. package/dist/adapters/photoswipe/index.d.ts +2 -0
  31. package/dist/adapters/photoswipe/index.d.ts.map +1 -0
  32. package/dist/adapters/photoswipe/index.js +2 -0
  33. package/dist/adapters/photoswipe/index.js.map +1 -0
  34. package/dist/adapters/photoswipe/photoswipe.service.d.ts +99 -0
  35. package/dist/adapters/photoswipe/photoswipe.service.d.ts.map +1 -0
  36. package/dist/adapters/photoswipe/photoswipe.service.js +150 -0
  37. package/dist/adapters/photoswipe/photoswipe.service.js.map +1 -0
  38. package/dist/adapters/telegram/telegram.service.d.ts +82 -13
  39. package/dist/adapters/telegram/telegram.service.d.ts.map +1 -1
  40. package/dist/adapters/telegram/telegram.service.js +133 -55
  41. package/dist/adapters/telegram/telegram.service.js.map +1 -1
  42. package/dist/adapters/wordpress/wordpress.service.d.ts +181 -110
  43. package/dist/adapters/wordpress/wordpress.service.d.ts.map +1 -1
  44. package/dist/adapters/wordpress/wordpress.service.js +556 -465
  45. package/dist/adapters/wordpress/wordpress.service.js.map +1 -1
  46. package/dist/config/seo.service.d.ts +1 -1
  47. package/dist/config/seo.service.d.ts.map +1 -1
  48. package/dist/config/seo.service.js +1 -1
  49. package/dist/config/seo.service.js.map +1 -1
  50. package/dist/core/services/access.service.d.ts +167 -4
  51. package/dist/core/services/access.service.d.ts.map +1 -1
  52. package/dist/core/services/access.service.js +241 -31
  53. package/dist/core/services/access.service.js.map +1 -1
  54. package/dist/core/services/agent.service.d.ts +182 -27
  55. package/dist/core/services/agent.service.d.ts.map +1 -1
  56. package/dist/core/services/agent.service.js +296 -164
  57. package/dist/core/services/agent.service.js.map +1 -1
  58. package/dist/core/services/assistant.service.d.ts +96 -5
  59. package/dist/core/services/assistant.service.d.ts.map +1 -1
  60. package/dist/core/services/assistant.service.js +171 -66
  61. package/dist/core/services/assistant.service.js.map +1 -1
  62. package/dist/core/services/dates.service.d.ts +183 -11
  63. package/dist/core/services/dates.service.d.ts.map +1 -1
  64. package/dist/core/services/dates.service.js +256 -57
  65. package/dist/core/services/dates.service.js.map +1 -1
  66. package/dist/core/services/http.service.d.ts +172 -133
  67. package/dist/core/services/http.service.d.ts.map +1 -1
  68. package/dist/core/services/http.service.js +367 -310
  69. package/dist/core/services/http.service.js.map +1 -1
  70. package/dist/core/services/logger.service.d.ts +96 -34
  71. package/dist/core/services/logger.service.d.ts.map +1 -1
  72. package/dist/core/services/logger.service.js +128 -41
  73. package/dist/core/services/logger.service.js.map +1 -1
  74. package/dist/core/services/query.service.d.ts +101 -0
  75. package/dist/core/services/query.service.d.ts.map +1 -1
  76. package/dist/core/services/query.service.js +131 -14
  77. package/dist/core/services/query.service.js.map +1 -1
  78. package/dist/core/services/utils.service.d.ts +286 -131
  79. package/dist/core/services/utils.service.d.ts.map +1 -1
  80. package/dist/core/services/utils.service.js +417 -227
  81. package/dist/core/services/utils.service.js.map +1 -1
  82. package/dist/core/services/validation.service.d.ts +48 -3
  83. package/dist/core/services/validation.service.d.ts.map +1 -1
  84. package/dist/core/services/validation.service.js +75 -23
  85. package/dist/core/services/validation.service.js.map +1 -1
  86. package/dist/infrastructure/decorators/cache.decorator.d.ts +53 -0
  87. package/dist/infrastructure/decorators/cache.decorator.d.ts.map +1 -0
  88. package/dist/infrastructure/decorators/cache.decorator.js +47 -0
  89. package/dist/infrastructure/decorators/cache.decorator.js.map +1 -0
  90. package/dist/infrastructure/decorators/index.d.ts +4 -0
  91. package/dist/infrastructure/decorators/index.d.ts.map +1 -0
  92. package/dist/infrastructure/decorators/index.js +4 -0
  93. package/dist/infrastructure/decorators/index.js.map +1 -0
  94. package/dist/infrastructure/decorators/logger.decorator.d.ts +38 -0
  95. package/dist/infrastructure/decorators/logger.decorator.d.ts.map +1 -0
  96. package/dist/infrastructure/decorators/logger.decorator.js +66 -0
  97. package/dist/infrastructure/decorators/logger.decorator.js.map +1 -0
  98. package/dist/infrastructure/decorators/retry.decorator.d.ts +37 -0
  99. package/dist/infrastructure/decorators/retry.decorator.d.ts.map +1 -0
  100. package/dist/infrastructure/decorators/retry.decorator.js +54 -0
  101. package/dist/infrastructure/decorators/retry.decorator.js.map +1 -0
  102. package/dist/infrastructure/index.d.ts +1 -0
  103. package/dist/infrastructure/index.d.ts.map +1 -1
  104. package/dist/infrastructure/index.js +1 -0
  105. package/dist/infrastructure/index.js.map +1 -1
  106. package/dist/styles.css +2 -0
  107. package/package.json +49 -14
  108. package/scss/_flags.scss +179 -0
  109. package/scss/_functions.scss +168 -0
  110. package/scss/_mixins.scss +658 -0
  111. package/scss/_reset.scss +275 -0
  112. package/scss/_utilities.scss +449 -0
  113. package/scss/_variables.scss +539 -0
  114. package/scss/components/_index.scss +50 -0
  115. package/scss/demo.scss +12 -0
  116. package/scss/main.scss +56 -0
@@ -1,3 +1,6 @@
1
+ /* -------------------------------------------------------------------------- */
2
+ /* Role hierarchy (shared between strategies) */
3
+ /* -------------------------------------------------------------------------- */
1
4
  /**
2
5
  * Role ranks: lower number = more privileged. Higher-privilege roles inherit
3
6
  * the capabilities of every role below them (e.g. `admin` can do everything
@@ -13,7 +16,7 @@ const ROLE_RANK = {
13
16
  };
14
17
  /**
15
18
  * Default role registry: each role lists only the capabilities it adds on top
16
- * of the roles below it. `guest` adds none — read access is public by default.
19
+ * of the roles below it. `guest` adds none - read access is public by default.
17
20
  */
18
21
  const DEFAULT_ROLES = [
19
22
  { slug: "owner", label: "Owner", capabilities: ["roles:assign", "system:admin"] },
@@ -40,58 +43,265 @@ const DEFAULT_ROLES = [
40
43
  function useCopy(definition) {
41
44
  return { ...definition, capabilities: [...definition.capabilities] };
42
45
  }
43
- /** Active registry, keyed by role slug. Starts as the default set. */
44
- const registry = new Map(DEFAULT_ROLES.map((role) => [role.slug, role]));
45
- function useDefinitionFor(role) {
46
- const definition = registry.get(role);
47
- if (!definition) {
48
- throw new Error(`Unknown access role: ${role}`);
49
- }
50
- return definition;
46
+ /* -------------------------------------------------------------------------- */
47
+ /* Concrete strategies */
48
+ /* -------------------------------------------------------------------------- */
49
+ /**
50
+ * Estrategia por defecto: control de acceso jerárquico basado en roles
51
+ * registrados. Es la estrategia estándar del servicio.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const strategy = new HierarchicalAccessStrategy();
56
+ * strategy.useCan({ id: 1, roles: ["editor"] }, "content:create"); // true
57
+ * ```
58
+ */
59
+ export class HierarchicalAccessStrategy {
60
+ /** Active registry, keyed by role slug. Starts as the default set. */
61
+ registry;
62
+ constructor() {
63
+ this.registry = new Map(DEFAULT_ROLES.map((role) => [role.slug, role]));
64
+ }
65
+ useDefinitionFor(role) {
66
+ const definition = this.registry.get(role);
67
+ if (!definition) {
68
+ throw new Error(`Unknown access role: ${role}`);
69
+ }
70
+ return definition;
71
+ }
72
+ /**
73
+ * Effective capabilities of a role: its own plus every less-privileged role's.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * useCapabilitiesFor("author"); // content:create, content:edit:own, ..., conversations:use
78
+ * useCapabilitiesFor("guest"); // []
79
+ * ```
80
+ */
81
+ useCapabilitiesFor(role) {
82
+ const rank = ROLE_RANK[this.useDefinitionFor(role).slug];
83
+ const capabilities = new Set();
84
+ for (const definition of this.registry.values()) {
85
+ if (ROLE_RANK[definition.slug] >= rank) {
86
+ for (const capability of definition.capabilities) {
87
+ capabilities.add(capability);
88
+ }
89
+ }
90
+ }
91
+ return [...capabilities];
92
+ }
93
+ /**
94
+ * Registers (or replaces) a role definition. Use it to extend a built-in
95
+ * role's capabilities, e.g. grant `content:create` to `member`. The definition
96
+ * is copied, so mutating the caller's object afterwards has no effect.
97
+ */
98
+ useRegisterRole(definition) {
99
+ this.registry.set(definition.slug, Object.freeze(useCopy(definition)));
100
+ }
101
+ /** Restores the built-in role registry (mainly for tests). */
102
+ useResetRoles() {
103
+ this.registry.clear();
104
+ for (const role of DEFAULT_ROLES) {
105
+ this.registry.set(role.slug, role);
106
+ }
107
+ }
108
+ /** Lists every registered role definition. Returns copies, not live state. */
109
+ useRoles() {
110
+ return [...this.registry.values()]
111
+ .sort((a, b) => ROLE_RANK[a.slug] - ROLE_RANK[b.slug])
112
+ .map(useCopy);
113
+ }
114
+ /** Exact role membership - no hierarchy involved. */
115
+ useHasRole(subject, role) {
116
+ return subject.roles.includes(role);
117
+ }
118
+ /**
119
+ * Whether the subject may perform a capability. Any of the subject's roles
120
+ * granting the capability (directly or by inheritance) is enough.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * useCan({ id: 1, roles: ["author"] }, "content:publish"); // false
125
+ * useCan({ id: 1, roles: ["author"] }, "content:create"); // true
126
+ * useCan({ id: 2, roles: ["editor"] }, "content:create"); // true (inherits author)
127
+ * useCan({ id: 3, roles: [] }, "conversations:use"); // false
128
+ * ```
129
+ */
130
+ useCan(subject, capability) {
131
+ return subject.roles.some((role) => this.useCapabilitiesFor(role).includes(capability));
132
+ }
133
+ }
134
+ /**
135
+ * Estrategia estricta: sólo verifica capacidades declaradas explícitamente
136
+ * en el rol del sujeto, sin her jerarquía. Útil cuando cada rol debe
137
+ * declarar todo lo que puede hacer.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const access = new AccessService(new FlatAccessStrategy());
142
+ * // "editor" ya NO hereda las capacidades de "author"
143
+ * access.useCan({ id: 1, roles: ["editor"] }, "content:create"); // false
144
+ * ```
145
+ */
146
+ export class FlatAccessStrategy {
147
+ registry;
148
+ constructor() {
149
+ this.registry = new Map(DEFAULT_ROLES.map((role) => [role.slug, role]));
150
+ }
151
+ useCapabilitiesFor(role) {
152
+ const definition = this.registry.get(role);
153
+ return definition ? [...definition.capabilities] : [];
154
+ }
155
+ useRegisterRole(definition) {
156
+ this.registry.set(definition.slug, Object.freeze(useCopy(definition)));
157
+ }
158
+ useResetRoles() {
159
+ this.registry.clear();
160
+ for (const role of DEFAULT_ROLES) {
161
+ this.registry.set(role.slug, role);
162
+ }
163
+ }
164
+ useRoles() {
165
+ return [...this.registry.values()].map(useCopy);
166
+ }
167
+ useHasRole(subject, role) {
168
+ return subject.roles.includes(role);
169
+ }
170
+ useCan(subject, capability) {
171
+ return subject.roles.some((role) => this.useCapabilitiesFor(role).includes(capability));
172
+ }
51
173
  }
174
+ /* -------------------------------------------------------------------------- */
175
+ /* Context (Singleton facade) */
176
+ /* -------------------------------------------------------------------------- */
177
+ /**
178
+ * AccessService - Singleton facade con Strategy Pattern.
179
+ *
180
+ * Centraliza el control de acceso (roles y capacidades) delegando el
181
+ * algoritmo concreto en una {@link IAccessStrategy} intercambiable.
182
+ * Por defecto usa {@link HierarchicalAccessStrategy}.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * // Uso con la estrategia por defecto (jerárquica)
187
+ * AccessService.getInstance().useCan({ id: 1, roles: ["admin"] }, "members:manage");
188
+ *
189
+ * // Cambiar a estrategia plana en runtime
190
+ * AccessService.getInstance().useSetStrategy(new FlatAccessStrategy());
191
+ * ```
192
+ */
193
+ export class AccessService {
194
+ static instance;
195
+ strategy;
196
+ /**
197
+ * Constructor privado - enforce singleton.
198
+ * @param strategy - Estrategia a inyectar (opcional).
199
+ */
200
+ constructor(strategy) {
201
+ this.strategy = strategy ?? new HierarchicalAccessStrategy();
202
+ }
203
+ /**
204
+ * Obtiene la instancia única del AccessService (Singleton).
205
+ *
206
+ * @returns La instancia única de {@link AccessService}.
207
+ */
208
+ static getInstance() {
209
+ if (!AccessService.instance) {
210
+ AccessService.instance = new AccessService();
211
+ }
212
+ return AccessService.instance;
213
+ }
214
+ /**
215
+ * Crea una instancia NO-singleton con una estrategia específica.
216
+ * Útil para tests o para aislar varios contextos de acceso.
217
+ *
218
+ * @param strategy - Estrategia a inyectar.
219
+ * @returns Una nueva instancia de {@link AccessService}.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * const flatAccess = AccessService.create(new FlatAccessStrategy());
224
+ * ```
225
+ */
226
+ static create(strategy) {
227
+ return new AccessService(strategy);
228
+ }
229
+ /**
230
+ * Intercambia la estrategia de acceso en runtime (Strategy Pattern).
231
+ *
232
+ * @param strategy - La nueva estrategia a utilizar.
233
+ */
234
+ useSetStrategy(strategy) {
235
+ this.strategy = strategy;
236
+ }
237
+ /** Returns the currently active strategy. */
238
+ useGetStrategy() {
239
+ return this.strategy;
240
+ }
241
+ /**
242
+ * Effective capabilities of a role (delegado a la estrategia activa).
243
+ */
244
+ useCapabilitiesFor(role) {
245
+ return this.strategy.useCapabilitiesFor(role);
246
+ }
247
+ /**
248
+ * Registers (or replaces) a role definition (delegado a la estrategia activa).
249
+ */
250
+ useRegisterRole(definition) {
251
+ this.strategy.useRegisterRole(definition);
252
+ }
253
+ /** Restores the built-in role registry (delegado a la estrategia activa). */
254
+ useResetRoles() {
255
+ this.strategy.useResetRoles();
256
+ }
257
+ /** Lists every registered role definition (delegado a la estrategia activa). */
258
+ useRoles() {
259
+ return this.strategy.useRoles();
260
+ }
261
+ /** Exact role membership - no hierarchy involved. */
262
+ useHasRole(subject, role) {
263
+ return this.strategy.useHasRole(subject, role);
264
+ }
265
+ /**
266
+ * Whether the subject may perform a capability (delegado a la estrategia activa).
267
+ */
268
+ useCan(subject, capability) {
269
+ return this.strategy.useCan(subject, capability);
270
+ }
271
+ }
272
+ /* -------------------------------------------------------------------------- */
273
+ /* Wrappers (backward compatibility) */
274
+ /* -------------------------------------------------------------------------- */
52
275
  /**
53
276
  * Effective capabilities of a role: its own plus every less-privileged role's.
54
277
  *
55
278
  * @example
56
279
  * ```ts
57
- * useCapabilitiesFor("author"); // content:create, content:edit:own, …, conversations:use
280
+ * useCapabilitiesFor("author"); // content:create, content:edit:own, ..., conversations:use
58
281
  * useCapabilitiesFor("guest"); // []
59
282
  * ```
60
283
  */
61
284
  export function useCapabilitiesFor(role) {
62
- const rank = ROLE_RANK[useDefinitionFor(role).slug];
63
- const capabilities = new Set();
64
- for (const definition of registry.values()) {
65
- if (ROLE_RANK[definition.slug] >= rank) {
66
- for (const capability of definition.capabilities) {
67
- capabilities.add(capability);
68
- }
69
- }
70
- }
71
- return [...capabilities];
285
+ return AccessService.getInstance().useCapabilitiesFor(role);
72
286
  }
73
287
  /**
74
288
  * Registers (or replaces) a role definition. Use it to extend a built-in
75
- * role's capabilities, e.g. grant `content:create` to `member`. The definition
76
- * is copied, so mutating the caller's object afterwards has no effect.
289
+ * role's capabilities, e.g. grant `content:create` to `member`.
77
290
  */
78
291
  export function useRegisterRole(definition) {
79
- registry.set(definition.slug, Object.freeze(useCopy(definition)));
292
+ AccessService.getInstance().useRegisterRole(definition);
80
293
  }
81
294
  /** Restores the built-in role registry (mainly for tests). */
82
295
  export function useResetRoles() {
83
- registry.clear();
84
- for (const role of DEFAULT_ROLES) {
85
- registry.set(role.slug, role);
86
- }
296
+ AccessService.getInstance().useResetRoles();
87
297
  }
88
298
  /** Lists every registered role definition. Returns copies, not live state. */
89
299
  export function useRoles() {
90
- return [...registry.values()].sort((a, b) => ROLE_RANK[a.slug] - ROLE_RANK[b.slug]).map(useCopy);
300
+ return AccessService.getInstance().useRoles();
91
301
  }
92
- /** Exact role membership — no hierarchy involved. */
302
+ /** Exact role membership - no hierarchy involved. */
93
303
  export function useHasRole(subject, role) {
94
- return subject.roles.includes(role);
304
+ return AccessService.getInstance().useHasRole(subject, role);
95
305
  }
96
306
  /**
97
307
  * Whether the subject may perform a capability. Any of the subject's roles
@@ -106,6 +316,6 @@ export function useHasRole(subject, role) {
106
316
  * ```
107
317
  */
108
318
  export function useCan(subject, capability) {
109
- return subject.roles.some((role) => useCapabilitiesFor(role).includes(capability));
319
+ return AccessService.getInstance().useCan(subject, capability);
110
320
  }
111
321
  //# sourceMappingURL=access.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"access.service.js","sourceRoot":"","sources":["../../../src/core/services/access.service.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,SAAS,GAA+B;IAC7C,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACR,CAAC;AAEF;;;GAGG;AACH,MAAM,aAAa,GAClB;IACC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE;IACjF,EAAE,IAAI,EAAE,OAAO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AAM,UAAU,UAAU,CAAC,OAAsB,EAAE,IAAgB;IAClE,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,OAAsB,EAAE,UAA4B;IAC1E,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;AACpF,CAAC"}
1
+ {"version":3,"file":"access.service.js","sourceRoot":"","sources":["../../../src/core/services/access.service.ts"],"names":[],"mappings":"AAiCA,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,SAAS,GAA+B;IAC7C,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACR,CAAC;AAEF;;;GAGG;AACH,MAAM,aAAa,GAClB;IACC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE;IACjF,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,gBAAgB,CAAC,EAAE;IACnE;QACC,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;QACf,YAAY,EAAE;YACb,iBAAiB;YACjB,kBAAkB;YAClB,oBAAoB;YACpB,wBAAwB;SACxB;KACD;IACD;QACC,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;QACf,YAAY,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,CAAC;KAC1E;IACD,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,E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AAa,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAChE,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AgentResult, AgentRunOptions, AiChatOptions, AiMessage, AiProviderConfig, AiResult } from "../../types/index.js";
1
+ import type { AgentResult, AgentRunOptions, AiChatOptions, AiMessage, AiProviderConfig, AiResult, AiTool, AiToolCall } from "../../types/index.js";
2
2
  /** Default endpoint for Alibaba Cloud Model Studio (DashScope) compatible mode. */
3
3
  export declare const KITT_BASE_URL = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
4
4
  /** Default model for the Kitt assistant preset. */
@@ -7,11 +7,183 @@ export declare const KITT_DEFAULT_MODEL = "qwen3.8-max";
7
7
  export declare const KITT_SYSTEM_PROMPT = "You are Kitt, a helpful assistant. Answer clearly and concisely.";
8
8
  /** Reusable preset (base URL + model) for the Kitt assistant. */
9
9
  export declare const kittPreset: Pick<AiProviderConfig, "baseUrl" | "model">;
10
+ /** Shape of a `/chat/completions` response. */
11
+ interface ChatCompletionResponse {
12
+ choices?: Array<{
13
+ message?: {
14
+ content?: string | null;
15
+ tool_calls?: AiToolCall[];
16
+ };
17
+ finish_reason?: string | null;
18
+ }>;
19
+ error?: {
20
+ message?: string;
21
+ };
22
+ }
23
+ /** Request options shared by chat and agent calls. */
24
+ interface RequestOptions {
25
+ temperature?: number;
26
+ maxTokens?: number;
27
+ topP?: number;
28
+ signal?: AbortSignal;
29
+ tools?: AiTool[];
30
+ }
10
31
  /**
11
- * Registers the AI provider for the Kitt assistant.
32
+ * Estrategia de proveedor AI - Strategy Pattern.
33
+ *
34
+ * Define el contrato que toda implementación de proveedor de completions debe
35
+ * cumplir. El {@link AgentService} delega la llamada HTTP en una estrategia
36
+ * concreta, permitiendo intercambiar proveedores (DashScope, OpenAI,
37
+ * self-hosted, mock en tests) sin tocar el bucle del agente.
38
+ */
39
+ export interface IAiProviderStrategy {
40
+ /**
41
+ * Performs a single `chat/completions` request against the provider.
42
+ *
43
+ * @param config - Provider configuration (baseUrl, model, apiKey).
44
+ * @param messages - Conversation messages.
45
+ * @param options - Sampling options, tools and abort signal.
46
+ * @returns The parsed provider response.
47
+ * @throws On non-2xx responses or transport failures.
48
+ */
49
+ requestCompletion(config: AiProviderConfig, messages: AiMessage[], options: RequestOptions): Promise<ChatCompletionResponse>;
50
+ }
51
+ /**
52
+ * Estrategia por defecto: proveedor compatible con OpenAI
53
+ * (`POST /chat/completions` con Bearer token). Cubre DashScope en modo
54
+ * compatible, OpenAI, Azure OpenAI y la mayoría de endpoints self-hosted.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const strategy = new OpenAiCompatibleStrategy();
59
+ * const response = await strategy.requestCompletion(config, messages, {});
60
+ * ```
61
+ */
62
+ export declare class OpenAiCompatibleStrategy implements IAiProviderStrategy {
63
+ /**
64
+ * Performs a raw `chat/completions` request against the provider.
65
+ * Throws {@link AiHttpError} on non-2xx responses.
66
+ */
67
+ requestCompletion(config: AiProviderConfig, messages: AiMessage[], options: RequestOptions): Promise<ChatCompletionResponse>;
68
+ }
69
+ /**
70
+ * AgentService - Singleton facade con Strategy Pattern.
12
71
  *
13
- * `apiKey` falls back to `process.env.DASHSCOPE_API_KEY`; `baseUrl`, `model`
14
- * and `systemPrompt` fall back to the {@link kittPreset} defaults.
72
+ * Centraliza el registro del proveedor AI y el bucle de completions,
73
+ * delegando la llamada HTTP en una {@link IAiProviderStrategy}
74
+ * intercambiable. Por defecto usa {@link OpenAiCompatibleStrategy}.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * // Configurar el proveedor
79
+ * AgentService.getInstance().useInitAgent({ apiKey: process.env.DASHSCOPE_API_KEY });
80
+ *
81
+ * // Cambiar de estrategia en runtime (p. ej. un mock en tests)
82
+ * AgentService.getInstance().useSetStrategy(new OpenAiCompatibleStrategy());
83
+ * ```
84
+ */
85
+ export declare class AgentService {
86
+ private static instance;
87
+ private provider;
88
+ private strategy;
89
+ /**
90
+ * Constructor privado - enforce singleton.
91
+ * @param strategy - Estrategia de proveedor a inyectar (opcional).
92
+ */
93
+ private constructor();
94
+ /**
95
+ * Obtiene la instancia única del AgentService (Singleton).
96
+ *
97
+ * @returns La instancia única de {@link AgentService}.
98
+ */
99
+ static getInstance(): AgentService;
100
+ /**
101
+ * Crea una instancia NO-singleton con una estrategia específica.
102
+ * Útil para tests o para aislar varios proveedores.
103
+ *
104
+ * @param strategy - Estrategia a inyectar.
105
+ * @returns Una nueva instancia de {@link AgentService}.
106
+ */
107
+ static create(strategy?: IAiProviderStrategy): AgentService;
108
+ /**
109
+ * Intercambia la estrategia de proveedor en runtime (Strategy Pattern).
110
+ *
111
+ * @param strategy - La nueva estrategia a utilizar.
112
+ */
113
+ useSetStrategy(strategy: IAiProviderStrategy): void;
114
+ /** Returns the currently active provider strategy. */
115
+ useGetStrategy(): IAiProviderStrategy;
116
+ /** Retrieves the configured provider or throws. */
117
+ private useGetProvider;
118
+ /**
119
+ * Registers the AI provider for the Kitt assistant.
120
+ *
121
+ * `apiKey` falls back to `process.env.DASHSCOPE_API_KEY`; `baseUrl`, `model`
122
+ * and `systemPrompt` fall back to the {@link kittPreset} defaults.
123
+ *
124
+ * @param config - Partial provider configuration.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import { useInitAgent } from "katanakit-js";
129
+ *
130
+ * useInitAgent({
131
+ * apiKey: process.env.DASHSCOPE_API_KEY,
132
+ * model: "qwen3.8-max",
133
+ * });
134
+ * ```
135
+ */
136
+ useInitAgent(config?: Partial<AiProviderConfig>): void;
137
+ /**
138
+ * Sends a single chat completion and returns the assistant text as a Safe Result.
139
+ *
140
+ * Use this for review / questioning (single-shot). For autonomous multi-step
141
+ * work with tools, use {@link useRunAgent}.
142
+ *
143
+ * @param messages - Conversation messages (a system prompt is prepended if absent).
144
+ * @param options - Optional completion options.
145
+ * @returns A `AiResult` with the assistant text.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { useChat } from "katanakit-js";
150
+ *
151
+ * const result = await useChat([
152
+ * { role: "user", content: "Summarize the benefits of solar energy in three bullet points." },
153
+ * ]);
154
+ * if (result.ok) console.log(result.data);
155
+ * ```
156
+ */
157
+ useChat(messages: AiMessage[], options?: AiChatOptions): Promise<AiResult<string>>;
158
+ /**
159
+ * Runs the tool-calling agent loop against a goal until it emits a final
160
+ * answer or exhausts `maxSteps`.
161
+ *
162
+ * @param goal - The natural-language objective.
163
+ * @param options - Tools, step budget and completion options.
164
+ * @returns An `AgentResult` with the final message and executed steps.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * import { useRunAgent } from "katanakit-js";
169
+ *
170
+ * const result = await useRunAgent("Fix the type errors reported by tsc", {
171
+ * tools: [
172
+ * {
173
+ * name: "runCommand",
174
+ * description: "Runs a shell command and returns its output",
175
+ * parameters: { type: "object", properties: { command: { type: "string" } } },
176
+ * execute: (input) => shell.run(input.command),
177
+ * },
178
+ * ],
179
+ * maxSteps: 12,
180
+ * });
181
+ * ```
182
+ */
183
+ useRunAgent(goal: string, options?: AgentRunOptions): Promise<AgentResult>;
184
+ }
185
+ /**
186
+ * Registers the AI provider for the Kitt assistant.
15
187
  *
16
188
  * @param config - Partial provider configuration.
17
189
  *
@@ -19,30 +191,22 @@ export declare const kittPreset: Pick<AiProviderConfig, "baseUrl" | "model">;
19
191
  * ```ts
20
192
  * import { useInitAgent } from "katanakit-js";
21
193
  *
22
- * useInitAgent({
23
- * apiKey: process.env.DASHSCOPE_API_KEY,
24
- * model: "qwen3.8-max",
25
- * });
194
+ * useInitAgent({ apiKey: process.env.DASHSCOPE_API_KEY });
26
195
  * ```
27
196
  */
28
197
  export declare function useInitAgent(config?: Partial<AiProviderConfig>): void;
29
198
  /**
30
199
  * Sends a single chat completion and returns the assistant text as a Safe Result.
31
200
  *
32
- * Use this for review / questioning (single-shot). For autonomous multi-step
33
- * work with tools, use {@link useRunAgent}.
34
- *
35
201
  * @param messages - Conversation messages (a system prompt is prepended if absent).
36
202
  * @param options - Optional completion options.
37
- * @returns A {@link AiResult} with the assistant text.
203
+ * @returns An `AiResult` with the assistant text.
38
204
  *
39
205
  * @example
40
206
  * ```ts
41
207
  * import { useChat } from "katanakit-js";
42
208
  *
43
- * const result = await useChat([
44
- * { role: "user", content: "Summarize the benefits of solar energy in three bullet points." },
45
- * ]);
209
+ * const result = await useChat([{ role: "user", content: "Hello" }]);
46
210
  * if (result.ok) console.log(result.data);
47
211
  * ```
48
212
  */
@@ -53,24 +217,15 @@ export declare function useChat(messages: AiMessage[], options?: AiChatOptions):
53
217
  *
54
218
  * @param goal - The natural-language objective.
55
219
  * @param options - Tools, step budget and completion options.
56
- * @returns An {@link AgentResult} with the final message and executed steps.
220
+ * @returns An `AgentResult` with the final message and executed steps.
57
221
  *
58
222
  * @example
59
223
  * ```ts
60
224
  * import { useRunAgent } from "katanakit-js";
61
225
  *
62
- * const result = await useRunAgent("Fix the type errors reported by tsc", {
63
- * tools: [
64
- * {
65
- * name: "runCommand",
66
- * description: "Runs a shell command and returns its output",
67
- * parameters: { type: "object", properties: { command: { type: "string" } } },
68
- * execute: (input) => shell.run(input.command),
69
- * },
70
- * ],
71
- * maxSteps: 12,
72
- * });
226
+ * const result = await useRunAgent("Fix the type errors reported by tsc");
73
227
  * ```
74
228
  */
75
229
  export declare function useRunAgent(goal: string, options?: AgentRunOptions): Promise<AgentResult>;
230
+ export {};
76
231
  //# sourceMappingURL=agent.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/agent.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,eAAe,EAEf,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,QAAQ,EAGR,MAAM,sBAAsB,CAAC;AAE9B,mFAAmF;AACnF,eAAO,MAAM,aAAa,2DAA2D,CAAC;AAEtF,mDAAmD;AACnD,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD,+EAA+E;AAC/E,eAAO,MAAM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