@nodefony/ai 0.0.0-stage → 10.0.0-beta.3
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/LICENSE +202 -0
- package/README.md +115 -2
- package/dist/_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.js +6 -0
- package/dist/index.js +30 -0
- package/dist/nodefony/config/config.js +48 -0
- package/dist/nodefony/config/configSchema.js +19 -0
- package/dist/nodefony/config/defineModuleConfig.js +52 -0
- package/dist/nodefony/interfaces/IAiService.js +1 -0
- package/dist/nodefony/interfaces/index.js +1 -0
- package/dist/nodefony/service/AiService.js +96 -0
- package/dist/nodefony/src/errors/AiError.js +21 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/nodefony/config/config.d.ts +48 -0
- package/dist/types/nodefony/config/configSchema.d.ts +12 -0
- package/dist/types/nodefony/config/defineModuleConfig.d.ts +43 -0
- package/dist/types/nodefony/interfaces/IAiService.d.ts +15 -0
- package/dist/types/nodefony/interfaces/index.d.ts +1 -0
- package/dist/types/nodefony/service/AiService.d.ts +80 -0
- package/dist/types/nodefony/src/errors/AiError.d.ts +14 -0
- package/package.json +81 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nodefony/ai
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> La boîte à outils IA de Nodefony : exposer les outils de votre application à n'importe quel
|
|
4
|
+
> agent (serveur MCP), consommer des serveurs MCP, puis bâtir les services d'une couche
|
|
5
|
+
> agentique — accès modèle, index vectoriel, mémoire, orchestration d'agents, gouvernance.
|
|
6
|
+
|
|
7
|
+
## Pourquoi ce paquet
|
|
8
|
+
|
|
9
|
+
Un agent d'intelligence artificielle qui n'a ni terminal ni accès à votre code — Claude.ai,
|
|
10
|
+
ChatGPT, Copilot, l'agent d'un de vos clients — ne peut atteindre votre application que par une
|
|
11
|
+
porte standard. Cette porte, c'est le **Model Context Protocol** (MCP) : l'agent demande à votre
|
|
12
|
+
application quels outils elle offre, reçoit pour chacun un nom, une description et un schéma
|
|
13
|
+
d'entrée, puis les appelle. MCP est aux agents ce que REST a été aux applications.
|
|
14
|
+
|
|
15
|
+
`@nodefony/ai` vous donne cette porte, et tout ce qui va autour, dans le style du framework :
|
|
16
|
+
injectable, configuré par un schéma validé au démarrage, sans coût pour ce que vous n'utilisez pas.
|
|
17
|
+
|
|
18
|
+
## Deux usages de l'IA, deux paquets
|
|
19
|
+
|
|
20
|
+
| Vous voulez… | Paquet |
|
|
21
|
+
| ------------------------------------------------------------------------------------------ | ------------------ |
|
|
22
|
+
| que **votre application** offre des outils à des agents, ou embarque ses propres agents | **`@nodefony/ai`** |
|
|
23
|
+
| qu'un **agent de code** (Claude Code, Codex, Gemini…) vous aide à développer l'application | `@nodefony/devkit` |
|
|
24
|
+
|
|
25
|
+
Le serveur MCP de développement de Nodefony — celui qui répond `nodefony_inspect`,
|
|
26
|
+
`nodefony_card`, `nodefony_check` à votre agent de code — est bâti avec ce paquet, exactement
|
|
27
|
+
comme le vôtre le sera.
|
|
28
|
+
|
|
29
|
+
## Un socle, pas une option
|
|
30
|
+
|
|
31
|
+
`@nodefony/ai` se charge comme `@nodefony/http` ou `@nodefony/framework` : toujours, dans
|
|
32
|
+
tous les environnements. Les autres modules s'y appuient pour déclarer leurs outils. Il ne coûte
|
|
33
|
+
rien tant qu'aucune capacité n'est configurée, et n'ouvre aucune porte en production sans
|
|
34
|
+
autorisation.
|
|
35
|
+
|
|
36
|
+
## Ce qui est fait, ce qui vient
|
|
37
|
+
|
|
38
|
+
Une capacité n'est **livrée** que lorsque son ticket est fermé ; les versions visées sont celles
|
|
39
|
+
de la feuille de route, et peuvent glisser. Ce qui est effectivement publié, version par version,
|
|
40
|
+
se lit dans le
|
|
41
|
+
[journal des changements](https://github.com/nodefony/nodefony-core/blob/main/CHANGELOG.md).
|
|
42
|
+
|
|
43
|
+
### Livré
|
|
44
|
+
|
|
45
|
+
| Capacité | Ce qu'elle apporte |
|
|
46
|
+
| ---------------- | ---------------------------------------------------------------------------------------- |
|
|
47
|
+
| **Module socle** | chargé partout comme `@nodefony/http`, configuration validée au démarrage (faute nommée) |
|
|
48
|
+
|
|
49
|
+
### En cours — `10.0.0`
|
|
50
|
+
|
|
51
|
+
| Capacité | Ce qu'elle apporte | Suivi |
|
|
52
|
+
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
53
|
+
| **Serveur MCP** | protocole, porte HTTP en flux, garde d'origine et d'adresse, autorisation OAuth par outil, outils déclarés par chaque module | [#565](https://github.com/nodefony/nodefony-core/issues/565) |
|
|
54
|
+
|
|
55
|
+
Chaque outil y annonce s'il ne fait que lire ou s'il modifie (indices `ToolAnnotations` de la
|
|
56
|
+
spec, [#540](https://github.com/nodefony/nodefony-core/issues/540)), pour que l'agent sache quand
|
|
57
|
+
demander confirmation. La boîte à outils MCP fonctionne déjà : elle sert aujourd'hui depuis le paquet `nodefony` (et la
|
|
58
|
+
porte de développement de `@nodefony/devkit`). Elle rejoint ce paquet pour la `10.0.0`, qui en
|
|
59
|
+
devient la seule adresse.
|
|
60
|
+
|
|
61
|
+
### Prévu
|
|
62
|
+
|
|
63
|
+
| Capacité | Ce qu'elle apporte | Version visée | Suivi |
|
|
64
|
+
| ----------------------------- | ---------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------ |
|
|
65
|
+
| **MCP par l'entrée standard** | les agents qui lancent eux-mêmes leur serveur (stdio) | `10.1` | [#462](https://github.com/nodefony/nodefony-core/issues/462) |
|
|
66
|
+
| **Route annotée → outil** | exposer une route existante à un agent, par le même pare-feu que la requête HTTP | `12.0` | [#503](https://github.com/nodefony/nodefony-core/issues/503) |
|
|
67
|
+
| **Registre MCP officiel** | une porte de production publiable et trouvable dans l'annuaire des serveurs MCP | `12.0` | [#550](https://github.com/nodefony/nodefony-core/issues/550) |
|
|
68
|
+
| **Client MCP** | consommer les serveurs MCP existants au lieu d'écrire chaque intégration | `12.0` | couche agentique |
|
|
69
|
+
| **Accès modèle** | une interface, plusieurs fournisseurs (Anthropic, OpenAI, Mistral, Ollama) | `12.0` | [#246](https://github.com/nodefony/nodefony-core/issues/246) |
|
|
70
|
+
| **Recherche augmentée** | index vectoriel adossé à l'ORM, recherche appelée par l'agent comme un outil | `12.0` | [#248](https://github.com/nodefony/nodefony-core/issues/248) |
|
|
71
|
+
| **Mémoire** | court terme, long terme, épisodique | `12.0` | [#249](https://github.com/nodefony/nodefony-core/issues/249) |
|
|
72
|
+
| **Orchestration d'agents** | boucle, outils, annulation, reprise ; un agent peut tourner seul dans un conteneur | `12.0` | [#250](https://github.com/nodefony/nodefony-core/issues/250) |
|
|
73
|
+
| **Gouvernance** | bornes d'exécution, validation humaine, audit | `12.0` | [#252](https://github.com/nodefony/nodefony-core/issues/252) |
|
|
74
|
+
|
|
75
|
+
La couche agentique (`12.0`) s'ouvre par un état de l'art
|
|
76
|
+
([#245](https://github.com/nodefony/nodefony-core/issues/245)) : son périmètre exact sera arrêté
|
|
77
|
+
à ce moment-là.
|
|
78
|
+
|
|
79
|
+
## Principes
|
|
80
|
+
|
|
81
|
+
- **Rien n'est payé sans être utilisé.** Une capacité sans fournisseur configuré n'alloue rien et
|
|
82
|
+
n'importe rien. Les fournisseurs lourds (SDK d'un modèle, client d'une base vectorielle) sont
|
|
83
|
+
des dépendances optionnelles, chargées au premier usage.
|
|
84
|
+
- **Le modèle ne tourne jamais dans votre serveur.** Nodefony orchestre un modèle servi ailleurs ;
|
|
85
|
+
il ne l'exécute pas dans le process qui sert vos requêtes.
|
|
86
|
+
- **Prêt pour la production.** Une porte MCP exposée hors du développement exige une
|
|
87
|
+
autorisation : chaque outil déclare ce qu'il exige, et un appelant ne voit que ce qu'il peut
|
|
88
|
+
appeler.
|
|
89
|
+
- **Conforme à la spécification MCP** (révision `2026-07-28`, anciens clients acceptés).
|
|
90
|
+
|
|
91
|
+
## Installer et activer
|
|
92
|
+
|
|
93
|
+
Le paquet s'installe à côté du framework, puis s'active dans le manifeste de l'application :
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
// nodefony.config.ts
|
|
97
|
+
modules: [
|
|
98
|
+
// …
|
|
99
|
+
use("@nodefony/ai", {}, { policy: "mandatory" }),
|
|
100
|
+
],
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
La clé de configuration est validée au démarrage : une faute de frappe arrête l'application en
|
|
104
|
+
nommant le champ, au lieu d'être ignorée en silence.
|
|
105
|
+
|
|
106
|
+
## Pour aller plus loin
|
|
107
|
+
|
|
108
|
+
- La vision de la couche IA :
|
|
109
|
+
[livre blanc](https://github.com/nodefony/nodefony-core/blob/main/docs/ia/livre-blanc-couche-ia.md)
|
|
110
|
+
- Les décisions d'architecture :
|
|
111
|
+
[ADR](https://github.com/nodefony/nodefony-core/tree/main/docs/adr)
|
|
112
|
+
- La documentation du module : [`docs/`](./docs/index.md)
|
|
113
|
+
|
|
114
|
+
## Licence
|
|
115
|
+
|
|
116
|
+
Apache-2.0 — © Christophe CAMENSULI.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { __decorate as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.154.0/helpers/esm/decorateMetadata.js
|
|
2
|
+
function __decorateMetadata(k, v) {
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { __decorateMetadata as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import defaults from "./nodefony/config/config.js";
|
|
2
|
+
import { defineAiConfig } from "./nodefony/config/defineModuleConfig.js";
|
|
3
|
+
import __decorateMetadata from "./_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.js";
|
|
4
|
+
import __decorate from "./_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.js";
|
|
5
|
+
import AiService_default from "./nodefony/service/AiService.js";
|
|
6
|
+
import { Kernel, Module, services } from "nodefony";
|
|
7
|
+
import { controllers } from "@nodefony/framework";
|
|
8
|
+
//#region index.ts
|
|
9
|
+
let AiModule = class AiModule extends Module {
|
|
10
|
+
constructor(kernel) {
|
|
11
|
+
super("ai", kernel, import.meta.url, defaults);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Valide la config au boot — défauts du schéma fusionnés avec ce que l'app
|
|
15
|
+
* passe dans `use()`. Une clé inconnue ou mal typée plante ICI, avec le champ
|
|
16
|
+
* fautif nommé, plutôt qu'en `undefined.x` au premier appel en production.
|
|
17
|
+
*/
|
|
18
|
+
async onKernelRegister() {
|
|
19
|
+
this.options = defineAiConfig(this.options);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
AiModule = __decorate([
|
|
24
|
+
controllers([]),
|
|
25
|
+
services([AiService_default]),
|
|
26
|
+
__decorateMetadata("design:paramtypes", [typeof Kernel === "undefined" ? Object : Kernel])
|
|
27
|
+
], AiModule);
|
|
28
|
+
var ai_default = AiModule;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ai_default as default };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region nodefony/config/config.ts
|
|
3
|
+
/**
|
|
4
|
+
* @nodefony/ai — CONFIGURATION DU MODULE (schéma Zod = source unique).
|
|
5
|
+
*
|
|
6
|
+
* ⭐ TL;DR : CE SCHÉMA EST LA CONFIG. Chaque `.default(...)` est la valeur d'usine ;
|
|
7
|
+
* changer un défaut du module = ÉDITER ICI (et nulle part ailleurs). L'app, elle,
|
|
8
|
+
* ne surcharge que ses écarts, via `use("@nodefony/ai", { … })`.
|
|
9
|
+
*
|
|
10
|
+
* RÈGLE D'OR (ADR-0006) : ce fichier porte le schéma commenté (type + validation +
|
|
11
|
+
* défaut + doc) ET matérialise les défauts par `parse({})`. Le builder
|
|
12
|
+
* (`defineAiConfig`) importe le schéma d'ici et ne retape aucune valeur —
|
|
13
|
+
* un défaut écrit à deux endroits finit toujours par diverger.
|
|
14
|
+
*
|
|
15
|
+
* SURCHARGE (précédence croissante) :
|
|
16
|
+
* • défauts du schéma (ce fichier) ;
|
|
17
|
+
* • app : `use("@nodefony/ai", { … })` dans `nodefony.config.ts` ;
|
|
18
|
+
* • déploiement : un NOM COURT, si le champ en déclare un — `.meta({ env: "NF_AI_HOTE" })`
|
|
19
|
+
* sur le champ suffit : le Kernel l'applique, `nodefony env` et `.env.example`
|
|
20
|
+
* le montrent. C'est le contrat de PRODUCTION (nom stable, documenté) ;
|
|
21
|
+
* • banc, dépannage : `NF__AI__<CHEMIN>=valeur` (override générique, `__` = niveau).
|
|
22
|
+
*
|
|
23
|
+
* Le schéma reste **PUR** : aucune lecture de `process.env`, aucun accès au kernel
|
|
24
|
+
* (il est évalué à l'import — le kernel n'existe pas encore).
|
|
25
|
+
*
|
|
26
|
+
* Champ sensible (clé, mot de passe) → `.meta({ secret: true })` EN DERNIER de la
|
|
27
|
+
* chaîne : chaque méthode zod clone, une `.default()` posée après `.meta()` perdrait
|
|
28
|
+
* la métadonnée. Ces flags ressortent dans le JSON Schema lu par Studio.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* ⚠️ `strictObject`, et non `object` : une clé INCONNUE doit être REFUSÉE, pas
|
|
32
|
+
* retirée en silence. C'est le défaut par défaut de Zod, et il coûte cher —
|
|
33
|
+
* `use("@nodefony/ai", { gretting: "…" })` produisait une application qui
|
|
34
|
+
* démarre en IGNORANT ce que l'utilisateur a écrit, sans un mot. Le typage du
|
|
35
|
+
* registre `NodefonyModuleConfig` attrape la faute de frappe à la COMPILATION ;
|
|
36
|
+
* ceci l'attrape au DÉMARRAGE, pour tout ce qui contourne le compilateur — une
|
|
37
|
+
* config chargée d'un fichier, un `as never`, un override d'environnement.
|
|
38
|
+
*/
|
|
39
|
+
const aiConfigSchema = z.strictObject({
|
|
40
|
+
/** Interrupteur du module — l'app peut le charger sans l'activer. */
|
|
41
|
+
enabled: z.boolean().default(true).describe("Active les fonctionnalités du module ai"),
|
|
42
|
+
/** Exemple : à remplacer par la vraie config du module. */
|
|
43
|
+
greeting: z.string().min(1).default("Bonjour de ai").describe("Message renvoyé par le service (exemple de champ configurable)")
|
|
44
|
+
});
|
|
45
|
+
/** Défauts matérialisés (passés au `super()` du Module). */
|
|
46
|
+
const defaults = aiConfigSchema.parse({});
|
|
47
|
+
//#endregion
|
|
48
|
+
export { aiConfigSchema, defaults as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { aiConfigSchema } from "./config.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region nodefony/config/configSchema.ts
|
|
4
|
+
/**
|
|
5
|
+
* JSON Schema de la configuration de @nodefony/ai — lu SANS démarrer
|
|
6
|
+
* l'application, par `nodefony env` et la notice `.env.example`, qui y
|
|
7
|
+
* trouvent les noms courts (`.meta({ env })`).
|
|
8
|
+
*
|
|
9
|
+
* Déclaré dans `package.json` → `nodefony.configSchema` ; le nom de l'export
|
|
10
|
+
* est FIXE. Fichier FEUILLE : il n'importe que zod et le schéma, et n'ouvre
|
|
11
|
+
* rien à l'import — une commande qui ne démarre pas l'application l'exécute.
|
|
12
|
+
*
|
|
13
|
+
* @returns le JSON Schema, métadonnées Nodefony comprises.
|
|
14
|
+
*/
|
|
15
|
+
function configJsonSchema() {
|
|
16
|
+
return z.toJSONSchema(aiConfigSchema);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { configJsonSchema };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { aiConfigSchema } from "./config.js";
|
|
2
|
+
import { configJsonSchema } from "./configSchema.js";
|
|
3
|
+
import { parseModuleConfig } from "nodefony";
|
|
4
|
+
//#region nodefony/config/defineModuleConfig.ts
|
|
5
|
+
/**
|
|
6
|
+
* @nodefony/ai — LE COMMENT : builder PUR de la config.
|
|
7
|
+
*
|
|
8
|
+
* ⭐ TL;DR : ce fichier VALIDE et GÈLE. Il ne porte AUCUNE valeur — les défauts
|
|
9
|
+
* vivent dans le schéma de `./config.ts` (règle d'or ADR-0006). Pour changer un
|
|
10
|
+
* défaut, c'est là-bas ; ici, on ne fait que le faire respecter.
|
|
11
|
+
*
|
|
12
|
+
* Le nom du FICHIER est le même dans tous les modules Nodefony
|
|
13
|
+
* (`defineModuleConfig.ts`) ; la FONCTION, elle, est préfixée par le module —
|
|
14
|
+
* deux modules importés côte à côte ne se marchent pas dessus.
|
|
15
|
+
*
|
|
16
|
+
* L'environnement ne se lit JAMAIS ici. La surcharge générique
|
|
17
|
+
* (`NF__AI__<CHEMIN>`) comme un nom court (`NF_AI_<RÉGLAGE>`) sont
|
|
18
|
+
* posés par le Kernel avant cette validation. Un nom court se DÉCLARE sur son
|
|
19
|
+
* champ, dans `./config.ts` : `.meta({ env: "NF_AI_<RÉGLAGE>" })`.
|
|
20
|
+
*
|
|
21
|
+
* 🔴 **La validation passe par `parseModuleConfig`, du cœur** — un seul endroit
|
|
22
|
+
* pour une seule règle. Il lève une `BootConfigurationError`, et pas une `Error`
|
|
23
|
+
* ordinaire : le kernel distingue les deux. Un hook de cycle de vie qui lève une
|
|
24
|
+
* erreur QUELCONQUE est absorbé en développement (fail-soft — il protège la DX
|
|
25
|
+
* d'un module optionnel cassé), tandis qu'une erreur de CONFIGURATION interrompt
|
|
26
|
+
* le boot dans TOUS les environnements. Mesuré sur un module généré : avec une
|
|
27
|
+
* `Error`, `use("@nodefony/ai", { gretting: "…" })` laissait l'application
|
|
28
|
+
* démarrer, servir, et rendre 0 — la faute de frappe n'atteignait personne. Une
|
|
29
|
+
* configuration explicite qu'on ne peut pas honorer ne se répare pas en
|
|
30
|
+
* continuant.
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ Ne PAS réécrire ce bloc à la main : les dix modules du framework portaient
|
|
33
|
+
* chacun leur copie du `try`/`catch`, et elles avaient divergé sur les deux
|
|
34
|
+
* points qui comptent — le type de l'erreur levée et la langue du message.
|
|
35
|
+
*
|
|
36
|
+
* @param config - config brute venue de `use("@nodefony/ai", { … })`.
|
|
37
|
+
* @returns config validée et gelée.
|
|
38
|
+
* @throws BootConfigurationError si un champ est invalide ou inconnu (toutes les
|
|
39
|
+
* erreurs Zod agrégées, par champ) — le boot s'interrompt, en dev comme en prod.
|
|
40
|
+
*/
|
|
41
|
+
function defineAiConfig(config = {}) {
|
|
42
|
+
return Object.freeze(parseModuleConfig(aiConfigSchema, config, "@nodefony/ai"));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* JSON Schema de la config — Studio en dérive son formulaire d'édition
|
|
46
|
+
* (libellés, types, défauts, descriptions), sans une ligne d'UI écrite à la main.
|
|
47
|
+
*/
|
|
48
|
+
function aiConfigJsonSchema() {
|
|
49
|
+
return configJsonSchema();
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { aiConfigJsonSchema, defineAiConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { defineAiConfig } from "../config/defineModuleConfig.js";
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/decorate.js";
|
|
4
|
+
import { Module, Service, injectable } from "nodefony";
|
|
5
|
+
//#region nodefony/service/AiService.ts
|
|
6
|
+
/**
|
|
7
|
+
* Service principal du module — la logique vit ici, pas dans les controllers
|
|
8
|
+
* (un controller traduit du HTTP/WS ; un service, lui, est réutilisable par la
|
|
9
|
+
* CLI, un job, un autre module).
|
|
10
|
+
*
|
|
11
|
+
* ⚡ **Tu veux un service ? Ne recopie pas ce fichier — génère-le :**
|
|
12
|
+
*
|
|
13
|
+
* ```bash
|
|
14
|
+
* npx nodefony create service <Nom> # la classe + sa déclaration
|
|
15
|
+
* npx nodefony create service <Nom> --inject <Autre> # + la dépendance écrite
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Le générateur écrit la version COURANTE du framework et déclare le service sur
|
|
19
|
+
* le module ; recopié à la main, il naît déjà décalé et personne ne le signale.
|
|
20
|
+
* Ce fichier reste là pour se LIRE — comprendre ce qu'est un service — pas pour
|
|
21
|
+
* se dupliquer.
|
|
22
|
+
*
|
|
23
|
+
* Cycle : `constructor` (fusion défauts + config de l'app) → `init`
|
|
24
|
+
* (branchements kernel) → méthodes métier.
|
|
25
|
+
*
|
|
26
|
+
* Un service porte DEUX noms, et c'est normal :
|
|
27
|
+
* `@injectable()` → nomme la CLASSE (`AiService`),
|
|
28
|
+
* c'est ce qu'on écrit dans `@inject("…")`
|
|
29
|
+
* `super("ai", …)` → nomme l'INSTANCE, sa clé dans le conteneur,
|
|
30
|
+
* c'est ce qu'on écrit dans `kernel.get("…")`
|
|
31
|
+
* Les deux mènent à la MÊME instance : le conteneur les réconcilie via la classe.
|
|
32
|
+
* (Le décorateur ne peut pas deviner la clé — il s'exécute au chargement de la
|
|
33
|
+
* classe, le `super()` seulement à la construction.)
|
|
34
|
+
*
|
|
35
|
+
* ⚠️ Ne JAMAIS redéclarer `options` comme propriété : la classe `Service` parente
|
|
36
|
+
* l'assigne déjà via le 4ᵉ argument du `super()`. On garde une référence typée
|
|
37
|
+
* `cfg` pour lire la config sans se battre avec TypeScript.
|
|
38
|
+
*
|
|
39
|
+
* POUR L'UTILISER AILLEURS, deux voies, toutes deux légales :
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* // 1. INJECTION par le constructeur — la dépendance est DÉCLARÉE, donc le
|
|
43
|
+
* // conteneur l'ordonnance et elle se voit dans la signature (nom de CLASSE).
|
|
44
|
+
* import { inject, injectable, Service, Module } from "nodefony";
|
|
45
|
+
*
|
|
46
|
+
* @injectable()
|
|
47
|
+
* class ReportService extends Service {
|
|
48
|
+
* constructor(
|
|
49
|
+
* module: Module,
|
|
50
|
+
* @inject("AiService") private ai: AiService,
|
|
51
|
+
* ) {
|
|
52
|
+
* super("report", module.container, module.notificationsCenter);
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* // 2. RÉSOLUTION par le conteneur, pour une dépendance tardive ou optionnelle
|
|
57
|
+
* // (nom d'INSTANCE).
|
|
58
|
+
* const ai = this.container.get("ai");
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
let AiService = class AiService extends Service {
|
|
62
|
+
module;
|
|
63
|
+
cfg;
|
|
64
|
+
constructor(module) {
|
|
65
|
+
const merged = defineAiConfig(module.options);
|
|
66
|
+
super("ai", module.container ?? void 0, module.notificationsCenter, merged);
|
|
67
|
+
this.module = module;
|
|
68
|
+
this.cfg = merged;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Hook de démarrage d'un service : appelé UNE fois par le kernel, après la
|
|
72
|
+
* construction. C'est ici qu'on s'abonne aux événements du kernel — jamais
|
|
73
|
+
* dans le constructeur, où le kernel n'est pas encore prêt.
|
|
74
|
+
*
|
|
75
|
+
* ⚠️ Il s'appelle `init`, pas `initialize`. Le kernel ne cherche que `init`
|
|
76
|
+
* (`guardServiceInitialize`) : une méthode nommée `initialize` sur un service
|
|
77
|
+
* n'est JAMAIS appelée, et rien ne le signale — le code y dort en silence.
|
|
78
|
+
* (`initialize` existe bien, mais sur un CONTROLLER, où il tourne à CHAQUE
|
|
79
|
+
* requête : deux cycles de vie distincts, d'où deux noms.)
|
|
80
|
+
*/
|
|
81
|
+
async init() {
|
|
82
|
+
this.log("service ai initialisé", "DEBUG");
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/** Exemple de méthode métier — à remplacer par la vôtre. */
|
|
86
|
+
greet(who = "monde") {
|
|
87
|
+
return `${this.cfg.greeting}, ${who} !`;
|
|
88
|
+
}
|
|
89
|
+
status() {
|
|
90
|
+
return { ready: this.cfg.enabled };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
AiService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [typeof Module === "undefined" ? Object : Module])], AiService);
|
|
94
|
+
var AiService_default = AiService;
|
|
95
|
+
//#endregion
|
|
96
|
+
export { AiService_default as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region nodefony/src/errors/AiError.ts
|
|
2
|
+
/**
|
|
3
|
+
* Erreur du module ai.
|
|
4
|
+
*
|
|
5
|
+
* Deux champs qui font la différence en production :
|
|
6
|
+
* - `code` : identifiant MACHINE (stable, grep-able, consommé par Studio et
|
|
7
|
+
* l'audit) — le message, lui, peut changer sans rien casser ;
|
|
8
|
+
* - `context` : payload structuré joint au log (jamais de secret ici).
|
|
9
|
+
*/
|
|
10
|
+
var AiError = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
context;
|
|
13
|
+
constructor(message, code = "AI_ERROR", context) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.context = context;
|
|
17
|
+
this.name = "AiError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { AiError, AiError as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Kernel, Module } from "nodefony";
|
|
2
|
+
import { type IAiConfigInput } from "./nodefony/config/config.js";
|
|
3
|
+
/**
|
|
4
|
+
* @nodefony/ai — La boîte à outils IA de Nodefony : serveur MCP, puis les services de la couche agentique.
|
|
5
|
+
*
|
|
6
|
+
* Module applicatif : un workspace npm à part entière
|
|
7
|
+
* (`src/packages/@nodefony/ai/`), chargé par le manifeste `modules` de
|
|
8
|
+
* `nodefony.config.ts`. Le Kernel l'importe PAR SON NOM (`@nodefony/ai`) —
|
|
9
|
+
* d'où le workspace, qui le rend résolvable.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Rend la config du module typée à l'appel : `use("@nodefony/ai", { … })`
|
|
13
|
+
* dans `nodefony.config.ts` propose les clés du schéma et refuse les fautes de
|
|
14
|
+
* frappe, au lieu d'avaler un `Record<string, unknown>`.
|
|
15
|
+
*/
|
|
16
|
+
declare module "nodefony" {
|
|
17
|
+
interface NodefonyModuleConfig {
|
|
18
|
+
"@nodefony/ai": IAiConfigInput;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
declare class AiModule extends Module {
|
|
22
|
+
constructor(kernel: Kernel);
|
|
23
|
+
/**
|
|
24
|
+
* Valide la config au boot — défauts du schéma fusionnés avec ce que l'app
|
|
25
|
+
* passe dans `use()`. Une clé inconnue ou mal typée plante ICI, avec le champ
|
|
26
|
+
* fautif nommé, plutôt qu'en `undefined.x` au premier appel en production.
|
|
27
|
+
*/
|
|
28
|
+
onKernelRegister(): Promise<this>;
|
|
29
|
+
}
|
|
30
|
+
export default AiModule;
|
|
31
|
+
export type { IAiConfigInput } from "./nodefony/config/config.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* @nodefony/ai — CONFIGURATION DU MODULE (schéma Zod = source unique).
|
|
4
|
+
*
|
|
5
|
+
* ⭐ TL;DR : CE SCHÉMA EST LA CONFIG. Chaque `.default(...)` est la valeur d'usine ;
|
|
6
|
+
* changer un défaut du module = ÉDITER ICI (et nulle part ailleurs). L'app, elle,
|
|
7
|
+
* ne surcharge que ses écarts, via `use("@nodefony/ai", { … })`.
|
|
8
|
+
*
|
|
9
|
+
* RÈGLE D'OR (ADR-0006) : ce fichier porte le schéma commenté (type + validation +
|
|
10
|
+
* défaut + doc) ET matérialise les défauts par `parse({})`. Le builder
|
|
11
|
+
* (`defineAiConfig`) importe le schéma d'ici et ne retape aucune valeur —
|
|
12
|
+
* un défaut écrit à deux endroits finit toujours par diverger.
|
|
13
|
+
*
|
|
14
|
+
* SURCHARGE (précédence croissante) :
|
|
15
|
+
* • défauts du schéma (ce fichier) ;
|
|
16
|
+
* • app : `use("@nodefony/ai", { … })` dans `nodefony.config.ts` ;
|
|
17
|
+
* • déploiement : un NOM COURT, si le champ en déclare un — `.meta({ env: "NF_AI_HOTE" })`
|
|
18
|
+
* sur le champ suffit : le Kernel l'applique, `nodefony env` et `.env.example`
|
|
19
|
+
* le montrent. C'est le contrat de PRODUCTION (nom stable, documenté) ;
|
|
20
|
+
* • banc, dépannage : `NF__AI__<CHEMIN>=valeur` (override générique, `__` = niveau).
|
|
21
|
+
*
|
|
22
|
+
* Le schéma reste **PUR** : aucune lecture de `process.env`, aucun accès au kernel
|
|
23
|
+
* (il est évalué à l'import — le kernel n'existe pas encore).
|
|
24
|
+
*
|
|
25
|
+
* Champ sensible (clé, mot de passe) → `.meta({ secret: true })` EN DERNIER de la
|
|
26
|
+
* chaîne : chaque méthode zod clone, une `.default()` posée après `.meta()` perdrait
|
|
27
|
+
* la métadonnée. Ces flags ressortent dans le JSON Schema lu par Studio.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* ⚠️ `strictObject`, et non `object` : une clé INCONNUE doit être REFUSÉE, pas
|
|
31
|
+
* retirée en silence. C'est le défaut par défaut de Zod, et il coûte cher —
|
|
32
|
+
* `use("@nodefony/ai", { gretting: "…" })` produisait une application qui
|
|
33
|
+
* démarre en IGNORANT ce que l'utilisateur a écrit, sans un mot. Le typage du
|
|
34
|
+
* registre `NodefonyModuleConfig` attrape la faute de frappe à la COMPILATION ;
|
|
35
|
+
* ceci l'attrape au DÉMARRAGE, pour tout ce qui contourne le compilateur — une
|
|
36
|
+
* config chargée d'un fichier, un `as never`, un override d'environnement.
|
|
37
|
+
*/
|
|
38
|
+
export declare const aiConfigSchema: z.ZodObject<{
|
|
39
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
40
|
+
greeting: z.ZodDefault<z.ZodString>;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
/** Config telle que l'APP l'écrit dans `use()` — tous les champs optionnels. */
|
|
43
|
+
export type IAiConfigInput = z.input<typeof aiConfigSchema>;
|
|
44
|
+
/** Config telle que le CODE la lit — défauts appliqués, rien d'optionnel. */
|
|
45
|
+
export type IAiConfig = z.output<typeof aiConfigSchema>;
|
|
46
|
+
/** Défauts matérialisés (passés au `super()` du Module). */
|
|
47
|
+
declare const defaults: IAiConfig;
|
|
48
|
+
export default defaults;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema de la configuration de @nodefony/ai — lu SANS démarrer
|
|
3
|
+
* l'application, par `nodefony env` et la notice `.env.example`, qui y
|
|
4
|
+
* trouvent les noms courts (`.meta({ env })`).
|
|
5
|
+
*
|
|
6
|
+
* Déclaré dans `package.json` → `nodefony.configSchema` ; le nom de l'export
|
|
7
|
+
* est FIXE. Fichier FEUILLE : il n'importe que zod et le schéma, et n'ouvre
|
|
8
|
+
* rien à l'import — une commande qui ne démarre pas l'application l'exécute.
|
|
9
|
+
*
|
|
10
|
+
* @returns le JSON Schema, métadonnées Nodefony comprises.
|
|
11
|
+
*/
|
|
12
|
+
export declare function configJsonSchema(): unknown;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { IAiConfig } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* @nodefony/ai — LE COMMENT : builder PUR de la config.
|
|
4
|
+
*
|
|
5
|
+
* ⭐ TL;DR : ce fichier VALIDE et GÈLE. Il ne porte AUCUNE valeur — les défauts
|
|
6
|
+
* vivent dans le schéma de `./config.ts` (règle d'or ADR-0006). Pour changer un
|
|
7
|
+
* défaut, c'est là-bas ; ici, on ne fait que le faire respecter.
|
|
8
|
+
*
|
|
9
|
+
* Le nom du FICHIER est le même dans tous les modules Nodefony
|
|
10
|
+
* (`defineModuleConfig.ts`) ; la FONCTION, elle, est préfixée par le module —
|
|
11
|
+
* deux modules importés côte à côte ne se marchent pas dessus.
|
|
12
|
+
*
|
|
13
|
+
* L'environnement ne se lit JAMAIS ici. La surcharge générique
|
|
14
|
+
* (`NF__AI__<CHEMIN>`) comme un nom court (`NF_AI_<RÉGLAGE>`) sont
|
|
15
|
+
* posés par le Kernel avant cette validation. Un nom court se DÉCLARE sur son
|
|
16
|
+
* champ, dans `./config.ts` : `.meta({ env: "NF_AI_<RÉGLAGE>" })`.
|
|
17
|
+
*
|
|
18
|
+
* 🔴 **La validation passe par `parseModuleConfig`, du cœur** — un seul endroit
|
|
19
|
+
* pour une seule règle. Il lève une `BootConfigurationError`, et pas une `Error`
|
|
20
|
+
* ordinaire : le kernel distingue les deux. Un hook de cycle de vie qui lève une
|
|
21
|
+
* erreur QUELCONQUE est absorbé en développement (fail-soft — il protège la DX
|
|
22
|
+
* d'un module optionnel cassé), tandis qu'une erreur de CONFIGURATION interrompt
|
|
23
|
+
* le boot dans TOUS les environnements. Mesuré sur un module généré : avec une
|
|
24
|
+
* `Error`, `use("@nodefony/ai", { gretting: "…" })` laissait l'application
|
|
25
|
+
* démarrer, servir, et rendre 0 — la faute de frappe n'atteignait personne. Une
|
|
26
|
+
* configuration explicite qu'on ne peut pas honorer ne se répare pas en
|
|
27
|
+
* continuant.
|
|
28
|
+
*
|
|
29
|
+
* ⚠️ Ne PAS réécrire ce bloc à la main : les dix modules du framework portaient
|
|
30
|
+
* chacun leur copie du `try`/`catch`, et elles avaient divergé sur les deux
|
|
31
|
+
* points qui comptent — le type de l'erreur levée et la langue du message.
|
|
32
|
+
*
|
|
33
|
+
* @param config - config brute venue de `use("@nodefony/ai", { … })`.
|
|
34
|
+
* @returns config validée et gelée.
|
|
35
|
+
* @throws BootConfigurationError si un champ est invalide ou inconnu (toutes les
|
|
36
|
+
* erreurs Zod agrégées, par champ) — le boot s'interrompt, en dev comme en prod.
|
|
37
|
+
*/
|
|
38
|
+
export declare function defineAiConfig(config?: unknown): IAiConfig;
|
|
39
|
+
/**
|
|
40
|
+
* JSON Schema de la config — Studio en dérive son formulaire d'édition
|
|
41
|
+
* (libellés, types, défauts, descriptions), sans une ligne d'UI écrite à la main.
|
|
42
|
+
*/
|
|
43
|
+
export declare function aiConfigJsonSchema(): unknown;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API publique de `AiService` (injectable, nom `ai`).
|
|
3
|
+
*
|
|
4
|
+
* L'interface est le CONTRAT : ce que les autres modules (et Studio) peuvent
|
|
5
|
+
* appeler. Tout ce qui n'est pas ici est un détail d'implémentation, libre de
|
|
6
|
+
* changer.
|
|
7
|
+
*/
|
|
8
|
+
export interface IAiService {
|
|
9
|
+
/** Snapshot de lecture — état courant du service. */
|
|
10
|
+
status(): {
|
|
11
|
+
ready: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Exemple de méthode métier — à remplacer par la vôtre. */
|
|
14
|
+
greet(who?: string): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { IAiService } from "./IAiService.js";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Service, Module } from "nodefony";
|
|
2
|
+
import type { IAiService } from "../interfaces/IAiService.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service principal du module — la logique vit ici, pas dans les controllers
|
|
5
|
+
* (un controller traduit du HTTP/WS ; un service, lui, est réutilisable par la
|
|
6
|
+
* CLI, un job, un autre module).
|
|
7
|
+
*
|
|
8
|
+
* ⚡ **Tu veux un service ? Ne recopie pas ce fichier — génère-le :**
|
|
9
|
+
*
|
|
10
|
+
* ```bash
|
|
11
|
+
* npx nodefony create service <Nom> # la classe + sa déclaration
|
|
12
|
+
* npx nodefony create service <Nom> --inject <Autre> # + la dépendance écrite
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Le générateur écrit la version COURANTE du framework et déclare le service sur
|
|
16
|
+
* le module ; recopié à la main, il naît déjà décalé et personne ne le signale.
|
|
17
|
+
* Ce fichier reste là pour se LIRE — comprendre ce qu'est un service — pas pour
|
|
18
|
+
* se dupliquer.
|
|
19
|
+
*
|
|
20
|
+
* Cycle : `constructor` (fusion défauts + config de l'app) → `init`
|
|
21
|
+
* (branchements kernel) → méthodes métier.
|
|
22
|
+
*
|
|
23
|
+
* Un service porte DEUX noms, et c'est normal :
|
|
24
|
+
* `@injectable()` → nomme la CLASSE (`AiService`),
|
|
25
|
+
* c'est ce qu'on écrit dans `@inject("…")`
|
|
26
|
+
* `super("ai", …)` → nomme l'INSTANCE, sa clé dans le conteneur,
|
|
27
|
+
* c'est ce qu'on écrit dans `kernel.get("…")`
|
|
28
|
+
* Les deux mènent à la MÊME instance : le conteneur les réconcilie via la classe.
|
|
29
|
+
* (Le décorateur ne peut pas deviner la clé — il s'exécute au chargement de la
|
|
30
|
+
* classe, le `super()` seulement à la construction.)
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ Ne JAMAIS redéclarer `options` comme propriété : la classe `Service` parente
|
|
33
|
+
* l'assigne déjà via le 4ᵉ argument du `super()`. On garde une référence typée
|
|
34
|
+
* `cfg` pour lire la config sans se battre avec TypeScript.
|
|
35
|
+
*
|
|
36
|
+
* POUR L'UTILISER AILLEURS, deux voies, toutes deux légales :
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* // 1. INJECTION par le constructeur — la dépendance est DÉCLARÉE, donc le
|
|
40
|
+
* // conteneur l'ordonnance et elle se voit dans la signature (nom de CLASSE).
|
|
41
|
+
* import { inject, injectable, Service, Module } from "nodefony";
|
|
42
|
+
*
|
|
43
|
+
* @injectable()
|
|
44
|
+
* class ReportService extends Service {
|
|
45
|
+
* constructor(
|
|
46
|
+
* module: Module,
|
|
47
|
+
* @inject("AiService") private ai: AiService,
|
|
48
|
+
* ) {
|
|
49
|
+
* super("report", module.container, module.notificationsCenter);
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* // 2. RÉSOLUTION par le conteneur, pour une dépendance tardive ou optionnelle
|
|
54
|
+
* // (nom d'INSTANCE).
|
|
55
|
+
* const ai = this.container.get("ai");
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare class AiService extends Service implements IAiService {
|
|
59
|
+
module: Module;
|
|
60
|
+
private readonly cfg;
|
|
61
|
+
constructor(module: Module);
|
|
62
|
+
/**
|
|
63
|
+
* Hook de démarrage d'un service : appelé UNE fois par le kernel, après la
|
|
64
|
+
* construction. C'est ici qu'on s'abonne aux événements du kernel — jamais
|
|
65
|
+
* dans le constructeur, où le kernel n'est pas encore prêt.
|
|
66
|
+
*
|
|
67
|
+
* ⚠️ Il s'appelle `init`, pas `initialize`. Le kernel ne cherche que `init`
|
|
68
|
+
* (`guardServiceInitialize`) : une méthode nommée `initialize` sur un service
|
|
69
|
+
* n'est JAMAIS appelée, et rien ne le signale — le code y dort en silence.
|
|
70
|
+
* (`initialize` existe bien, mais sur un CONTROLLER, où il tourne à CHAQUE
|
|
71
|
+
* requête : deux cycles de vie distincts, d'où deux noms.)
|
|
72
|
+
*/
|
|
73
|
+
init(): Promise<this>;
|
|
74
|
+
/** Exemple de méthode métier — à remplacer par la vôtre. */
|
|
75
|
+
greet(who?: string): string;
|
|
76
|
+
status(): {
|
|
77
|
+
ready: boolean;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export default AiService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Erreur du module ai.
|
|
3
|
+
*
|
|
4
|
+
* Deux champs qui font la différence en production :
|
|
5
|
+
* - `code` : identifiant MACHINE (stable, grep-able, consommé par Studio et
|
|
6
|
+
* l'audit) — le message, lui, peut changer sans rien casser ;
|
|
7
|
+
* - `context` : payload structuré joint au log (jamais de secret ici).
|
|
8
|
+
*/
|
|
9
|
+
export declare class AiError extends Error {
|
|
10
|
+
readonly code: string;
|
|
11
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
12
|
+
constructor(message: string, code?: string, context?: Record<string, unknown> | undefined);
|
|
13
|
+
}
|
|
14
|
+
export default AiError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodefony/ai",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "10.0.0-beta.3",
|
|
4
|
+
"description": "La boîte à outils IA de Nodefony : serveur MCP, puis les services de la couche agentique",
|
|
5
|
+
"contributors": [],
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"nodefony-source": "./index.ts",
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rolldown -c rolldown.config.ts && tsgo -p tsconfig.declarations.json",
|
|
20
|
+
"typecheck": "tsgo --noEmit -p tsconfig.json && tsgo --noEmit -p tsconfig.tests.json",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"clean": "node --eval \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
23
|
+
"coverage": "vitest run --coverage"
|
|
24
|
+
},
|
|
25
|
+
"private": false,
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=24.0.0"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"nodefony",
|
|
31
|
+
"ai",
|
|
32
|
+
"mcp",
|
|
33
|
+
"model-context-protocol",
|
|
34
|
+
"agents",
|
|
35
|
+
"llm",
|
|
36
|
+
"typescript",
|
|
37
|
+
"esm"
|
|
38
|
+
],
|
|
39
|
+
"nodefony": {
|
|
40
|
+
"configSchema": "./dist/nodefony/config/configSchema.js"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"nodefony": "^10.0.0-beta.3",
|
|
44
|
+
"@nodefony/framework": "^10.0.0-beta.3",
|
|
45
|
+
"zod": "^4.6.7",
|
|
46
|
+
"@nodefony/http": "^10.0.0-beta.3"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"tslib": "2.8.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"nodefony": "^10.0.0-beta.3",
|
|
53
|
+
"@nodefony/framework": "^10.0.0-beta.3",
|
|
54
|
+
"@nodefony/http": "^10.0.0-beta.3",
|
|
55
|
+
"@types/node": "26.6.5",
|
|
56
|
+
"vitest": "5.0.4"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/nodefony/nodefony-core.git",
|
|
61
|
+
"directory": "src/packages/@nodefony/ai"
|
|
62
|
+
},
|
|
63
|
+
"license": "Apache-2.0",
|
|
64
|
+
"licenses": [
|
|
65
|
+
{
|
|
66
|
+
"type": "Apache-2.0",
|
|
67
|
+
"url": "https://www.apache.org/licenses/LICENSE-2.0"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"author": "Christophe CAMENSULI <ccamensuli@gmail.com>",
|
|
71
|
+
"readmeFilename": "README.md",
|
|
72
|
+
"files": [
|
|
73
|
+
"dist",
|
|
74
|
+
"docs"
|
|
75
|
+
],
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
},
|
|
79
|
+
"homepage": "https://nodefony.github.io/nodefony-core/",
|
|
80
|
+
"bugs": {
|
|
81
|
+
"url": "https://github.com/nodefony/nodefony-core/issues"
|
|
82
|
+
}
|
|
83
|
+
}
|