@nodefony/ai 0.0.0-stage → 10.0.0-beta.4
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 +123 -2
- package/dist/_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js +8 -0
- package/dist/index.js +37 -0
- package/dist/nodefony/command/StdioCommand.js +75 -0
- package/dist/nodefony/config/config.js +181 -0
- package/dist/nodefony/config/configSchema.js +18 -0
- package/dist/nodefony/config/defineModuleConfig.js +51 -0
- package/dist/nodefony/mcp/caller.js +38 -0
- package/dist/nodefony/mcp/gate.js +628 -0
- package/dist/nodefony/mcp/guard.js +82 -0
- package/dist/nodefony/mcp/progress.js +74 -0
- package/dist/nodefony/mcp/protocol.js +76 -0
- package/dist/nodefony/mcp/server.js +302 -0
- package/dist/nodefony/mcp/sessionTicket.js +89 -0
- package/dist/nodefony/mcp/stdio.js +64 -0
- package/dist/nodefony/mcp/stream.js +80 -0
- package/dist/nodefony/mcp/ticketSession.js +177 -0
- package/dist/nodefony/mcp/tools.js +485 -0
- package/dist/nodefony/src/errors/AiError.js +20 -0
- package/dist/types/index.d.ts +56 -0
- package/dist/types/nodefony/command/StdioCommand.d.ts +28 -0
- package/dist/types/nodefony/config/config.d.ts +44 -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/mcp/caller.d.ts +54 -0
- package/dist/types/nodefony/mcp/gate.d.ts +235 -0
- package/dist/types/nodefony/mcp/guard.d.ts +89 -0
- package/dist/types/nodefony/mcp/progress.d.ts +48 -0
- package/dist/types/nodefony/mcp/protocol.d.ts +107 -0
- package/dist/types/nodefony/mcp/server.d.ts +156 -0
- package/dist/types/nodefony/mcp/sessionTicket.d.ts +60 -0
- package/dist/types/nodefony/mcp/stdio.d.ts +38 -0
- package/dist/types/nodefony/mcp/stream.d.ts +76 -0
- package/dist/types/nodefony/mcp/ticketSession.d.ts +174 -0
- package/dist/types/nodefony/mcp/tools.d.ts +232 -0
- package/dist/types/nodefony/src/errors/AiError.d.ts +14 -0
- package/docs/index.md +56 -0
- package/docs/mcp.md +754 -0
- package/package.json +83 -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,124 @@
|
|
|
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 ne monte **aucune route** : une porte MCP,
|
|
34
|
+
c'est vous qui la déclarez — une porte `defineMcpGate()` servie par un controller, en développement ou en
|
|
35
|
+
production selon vos besoins.
|
|
36
|
+
|
|
37
|
+
## Ce qui est fait, ce qui vient
|
|
38
|
+
|
|
39
|
+
Une capacité n'est **livrée** que lorsque son ticket est fermé ; les versions visées sont celles
|
|
40
|
+
de la feuille de route, et peuvent glisser. Ce qui est effectivement publié, version par version,
|
|
41
|
+
se lit dans le
|
|
42
|
+
[journal des changements](https://github.com/nodefony/nodefony-core/blob/main/CHANGELOG.md).
|
|
43
|
+
|
|
44
|
+
### Livré
|
|
45
|
+
|
|
46
|
+
| Capacité | Ce qu'elle apporte |
|
|
47
|
+
| ---------------- | ---------------------------------------------------------------------------------------- |
|
|
48
|
+
| **Module socle** | chargé partout comme `@nodefony/http`, configuration validée au démarrage (faute nommée) |
|
|
49
|
+
|
|
50
|
+
### En cours — `10.0.0`
|
|
51
|
+
|
|
52
|
+
| Capacité | Ce qu'elle apporte | Suivi |
|
|
53
|
+
| --------------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
54
|
+
| **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) |
|
|
55
|
+
|
|
56
|
+
Chaque outil y annonce s'il ne fait que lire ou s'il modifie (indices `ToolAnnotations` de la
|
|
57
|
+
spec, [#540](https://github.com/nodefony/nodefony-core/issues/540)), pour que l'agent sache quand
|
|
58
|
+
demander confirmation. La boîte à outils MCP vit dans ce paquet, qui en est la seule adresse. La porte de développement
|
|
59
|
+
de `@nodefony/devkit` (`/nodefony/mcp`) est bâtie sur la même mécanique que celle que vous
|
|
60
|
+
ouvrirez pour vos propres outils.
|
|
61
|
+
|
|
62
|
+
Un outil peut **agir au nom de l'utilisateur** qui l'appelle (`actsForUser`) : la porte retrouve
|
|
63
|
+
son compte avant le handler, et les services qu'il appelle le voient comme sous une route
|
|
64
|
+
protégée ([#648](https://github.com/nodefony/nodefony-core/issues/648)). Un paramètre qui élargit ce
|
|
65
|
+
que fait un outil exige son scope à l'appel (`scopesFor`) : l'outil reste visible, et l'agent
|
|
66
|
+
reçoit un défi `insufficient_scope` qui lui dit quel jeton demander
|
|
67
|
+
([#650](https://github.com/nodefony/nodefony-core/issues/650)). Le détail :
|
|
68
|
+
[la boîte à outils MCP](./docs/mcp.md).
|
|
69
|
+
|
|
70
|
+
### Prévu
|
|
71
|
+
|
|
72
|
+
| Capacité | Ce qu'elle apporte | Version visée | Suivi |
|
|
73
|
+
| ----------------------------- | ---------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------ |
|
|
74
|
+
| **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) |
|
|
75
|
+
| **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) |
|
|
76
|
+
| **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) |
|
|
77
|
+
| **Client MCP** | consommer les serveurs MCP existants au lieu d'écrire chaque intégration | `12.0` | couche agentique |
|
|
78
|
+
| **Accès modèle** | une interface, plusieurs fournisseurs (Anthropic, OpenAI, Mistral, Ollama) | `12.0` | [#246](https://github.com/nodefony/nodefony-core/issues/246) |
|
|
79
|
+
| **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) |
|
|
80
|
+
| **Mémoire** | court terme, long terme, épisodique | `12.0` | [#249](https://github.com/nodefony/nodefony-core/issues/249) |
|
|
81
|
+
| **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) |
|
|
82
|
+
| **Gouvernance** | bornes d'exécution, validation humaine, audit | `12.0` | [#252](https://github.com/nodefony/nodefony-core/issues/252) |
|
|
83
|
+
|
|
84
|
+
La couche agentique (`12.0`) s'ouvre par un état de l'art
|
|
85
|
+
([#245](https://github.com/nodefony/nodefony-core/issues/245)) : son périmètre exact sera arrêté
|
|
86
|
+
à ce moment-là.
|
|
87
|
+
|
|
88
|
+
## Principes
|
|
89
|
+
|
|
90
|
+
- **Rien n'est payé sans être utilisé.** Une capacité sans fournisseur configuré n'alloue rien et
|
|
91
|
+
n'importe rien. Les fournisseurs lourds (SDK d'un modèle, client d'une base vectorielle) sont
|
|
92
|
+
des dépendances optionnelles, chargées au premier usage.
|
|
93
|
+
- **Le modèle ne tourne jamais dans votre serveur.** Nodefony orchestre un modèle servi ailleurs ;
|
|
94
|
+
il ne l'exécute pas dans le process qui sert vos requêtes.
|
|
95
|
+
- **Prêt pour la production.** Une porte MCP exposée hors du développement exige une
|
|
96
|
+
autorisation : chaque outil déclare ce qu'il exige, et un appelant ne voit que ce qu'il peut
|
|
97
|
+
appeler.
|
|
98
|
+
- **Conforme à la spécification MCP** (révision `2026-07-28`, anciens clients acceptés).
|
|
99
|
+
|
|
100
|
+
## Installer et activer
|
|
101
|
+
|
|
102
|
+
Le paquet s'installe à côté du framework, puis s'active dans le manifeste de l'application :
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// nodefony.config.ts
|
|
106
|
+
modules: [
|
|
107
|
+
// …
|
|
108
|
+
use("@nodefony/ai", {}, { policy: "mandatory" }),
|
|
109
|
+
],
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
La clé de configuration est validée au démarrage : une faute de frappe arrête l'application en
|
|
113
|
+
nommant le champ, au lieu d'être ignorée en silence.
|
|
114
|
+
|
|
115
|
+
## Pour aller plus loin
|
|
116
|
+
|
|
117
|
+
- La vision de la couche IA :
|
|
118
|
+
[livre blanc](https://github.com/nodefony/nodefony-core/blob/main/docs/ia/livre-blanc-couche-ia.md)
|
|
119
|
+
- Les décisions d'architecture :
|
|
120
|
+
[ADR](https://github.com/nodefony/nodefony-core/tree/main/docs/adr)
|
|
121
|
+
|
|
122
|
+
## Licence
|
|
123
|
+
|
|
124
|
+
Apache-2.0 — © Christophe CAMENSULI.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// \0@oxc-project+runtime@0.155.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
|
+
export { __decorate as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import defaults, { aiConfigSchema, mcpConfigSchema } from "./nodefony/config/config.js";
|
|
2
|
+
import { aiConfigJsonSchema, defineAiConfig } from "./nodefony/config/defineModuleConfig.js";
|
|
3
|
+
import { mcpCallerRoles } from "./nodefony/mcp/caller.js";
|
|
4
|
+
import { RELAY_HEADERS, checkMcpAccess, isLocalAddress, isRelayedRequest } from "./nodefony/mcp/guard.js";
|
|
5
|
+
import { JsonRpcError, MCP_DEFAULT_NEGOTIATED_VERSION, MCP_PROTOCOL_VERSION, MCP_SUPPORTED_VERSIONS, META_PROTOCOL_VERSION, META_SERVER_INFO, McpProtocolError, isNotification, jsonRpcFailure, jsonRpcSuccess } from "./nodefony/mcp/protocol.js";
|
|
6
|
+
import { MCP_PROGRESS_MESSAGE_MAX, MCP_PROGRESS_MIN_INTERVAL_MS, createProgressReporter, readProgressToken } from "./nodefony/mcp/progress.js";
|
|
7
|
+
import { MCP_RESERVED_PREFIX, MCP_TEXT_MAX_CHARS, callMcpTool, collectMcpTools, declareMcpTools, insufficientScopeMessage, mcpCallScopes, mcpDeclaredScopes, mcpText, publishMcpTools } from "./nodefony/mcp/tools.js";
|
|
8
|
+
import { handleMcpMessage } from "./nodefony/mcp/server.js";
|
|
9
|
+
import { MCP_STREAM_GRACE_MS, createMcpResponseStream } from "./nodefony/mcp/stream.js";
|
|
10
|
+
import { MCP_STREAM_MAX_EVENT_BYTES, defineMcpGate, mcpGateSchema } from "./nodefony/mcp/gate.js";
|
|
11
|
+
import { serveMcpStdio } from "./nodefony/mcp/stdio.js";
|
|
12
|
+
import StdioCommand from "./nodefony/command/StdioCommand.js";
|
|
13
|
+
import __decorate from "./_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";
|
|
14
|
+
import { SESSION_TICKET_HEADER, SESSION_TICKET_LENGTH, SESSION_TICKET_MAX_PENDING, SESSION_TICKET_TTL_MS, SessionTicketStore, fingerprintSessionTicket } from "./nodefony/mcp/sessionTicket.js";
|
|
15
|
+
import { TICKET_SESSION_REFUSED, defineTicketSessionGate, isSessionFlowView, isSessionServiceView, openTicketSession, readTicketSessionVerdict, ticketSessionGateSchema, toTicketSessionUser } from "./nodefony/mcp/ticketSession.js";
|
|
16
|
+
import { AiError } from "./nodefony/src/errors/AiError.js";
|
|
17
|
+
import { Module } from "nodefony";
|
|
18
|
+
import { controllers } from "@nodefony/framework";
|
|
19
|
+
// index.ts
|
|
20
|
+
let AiModule = class AiModule extends Module {
|
|
21
|
+
constructor(kernel) {
|
|
22
|
+
super("ai", kernel, import.meta.url, defaults);
|
|
23
|
+
this.addCommand(StdioCommand);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Valide la config au boot — défauts du schéma fusionnés avec ce que l'app
|
|
27
|
+
* passe dans `use()`. Une clé inconnue ou mal typée plante ICI, avec le champ
|
|
28
|
+
* fautif nommé, plutôt qu'en `undefined.x` au premier appel en production.
|
|
29
|
+
*/
|
|
30
|
+
async onKernelRegister() {
|
|
31
|
+
this.options = defineAiConfig(this.options);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
AiModule = __decorate([controllers([])], AiModule);
|
|
36
|
+
var ai_default = AiModule;
|
|
37
|
+
export { AiError, JsonRpcError, MCP_DEFAULT_NEGOTIATED_VERSION, MCP_PROGRESS_MESSAGE_MAX, MCP_PROGRESS_MIN_INTERVAL_MS, MCP_PROTOCOL_VERSION, MCP_RESERVED_PREFIX, MCP_STREAM_GRACE_MS, MCP_STREAM_MAX_EVENT_BYTES, MCP_SUPPORTED_VERSIONS, MCP_TEXT_MAX_CHARS, META_PROTOCOL_VERSION, META_SERVER_INFO, McpProtocolError, RELAY_HEADERS, SESSION_TICKET_HEADER, SESSION_TICKET_LENGTH, SESSION_TICKET_MAX_PENDING, SESSION_TICKET_TTL_MS, SessionTicketStore, TICKET_SESSION_REFUSED, aiConfigJsonSchema, aiConfigSchema, callMcpTool, checkMcpAccess, collectMcpTools, createMcpResponseStream, createProgressReporter, declareMcpTools, ai_default as default, defineAiConfig, defineMcpGate, defineTicketSessionGate, fingerprintSessionTicket, handleMcpMessage, insufficientScopeMessage, isLocalAddress, isNotification, isRelayedRequest, isSessionFlowView, isSessionServiceView, jsonRpcFailure, jsonRpcSuccess, mcpCallScopes, mcpCallerRoles, mcpConfigSchema, mcpDeclaredScopes, mcpGateSchema, mcpText, openTicketSession, publishMcpTools, readProgressToken, readTicketSessionVerdict, serveMcpStdio, ticketSessionGateSchema, toTicketSessionUser };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineMcpGate } from "../mcp/gate.js";
|
|
2
|
+
import { serveMcpStdio } from "../mcp/stdio.js";
|
|
3
|
+
import { Command, STDERR_LOG_SINK, Syslog, localOperatorCaller } from "nodefony";
|
|
4
|
+
// nodefony/command/StdioCommand.ts
|
|
5
|
+
const options = {
|
|
6
|
+
helpGroup: "AGENTS ET OUTILLAGE",
|
|
7
|
+
showBanner: false,
|
|
8
|
+
kernelEvent: "onPostReady",
|
|
9
|
+
quietBoot: true,
|
|
10
|
+
examples: ["nodefony ai:stdio", "nodefony ai:stdio 2> mcp-stdio.log"]
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Ce que l'agent lit en arrivant : ce process n'est PAS le serveur de
|
|
14
|
+
* l'application, et ce qui en découle.
|
|
15
|
+
*/
|
|
16
|
+
const STDIO_INSTRUCTIONS = "Outils de cette application Nodefony, servis par un process lancé pour toi (transport stdio). Ils répondent depuis le code tel qu'il a démarré — sans rechargement à chaud — et ce process ne sert aucune requête : ce qui mesure le trafic réel exige l'application démarrée et sa porte HTTP.";
|
|
17
|
+
/**
|
|
18
|
+
* Sert le MCP de l'application sur l'entrée et la sortie standard —
|
|
19
|
+
* `nodefony ai:stdio`.
|
|
20
|
+
*
|
|
21
|
+
* Pour le client qui lance lui-même son serveur MCP et lui parle par stdio
|
|
22
|
+
* (agent de CI, interface en ligne de commande, agent cloud `"type": "local"`) :
|
|
23
|
+
* rien n'y écoute sur `localhost`, la route `/nodefony/mcp` lui est hors
|
|
24
|
+
* d'atteinte.
|
|
25
|
+
*
|
|
26
|
+
* Servi dans TOUS les environnements : les outils des modules chargés, avec la
|
|
27
|
+
* posture de l'OPÉRATEUR LOCAL — celle de toute commande du CLI
|
|
28
|
+
* (`localOperatorCaller`, qui dit pourquoi). Qui lance la commande a déjà un
|
|
29
|
+
* terminal dans l'application : `nodefony inspect` lui rend les mêmes données.
|
|
30
|
+
* Ce rôle n'ouvre que l'administration du framework (`admin:read`/`admin:write`
|
|
31
|
+
* se traduisent en lui, `rolesFromScopes`) ; un outil à scope APPLICATIF, un
|
|
32
|
+
* outil `requiresAuth` ou `actsForUser` reste retenu — il exige un jeton, donc
|
|
33
|
+
* une porte HTTP protégée. Les outils `nodefony_*` n'y paraissent que lorsque
|
|
34
|
+
* `@nodefony/devkit` est chargé (développement).
|
|
35
|
+
*
|
|
36
|
+
* Limite : le code servi est celui du boot, sans rechargement à chaud — la
|
|
37
|
+
* porte HTTP de développement reste celle qui suit les sources.
|
|
38
|
+
*/
|
|
39
|
+
var StdioCommand = class extends Command {
|
|
40
|
+
constructor(cli) {
|
|
41
|
+
super("ai:stdio", "sert le MCP de l'app en stdio, sans serveur", cli, options);
|
|
42
|
+
}
|
|
43
|
+
async generate() {
|
|
44
|
+
const stdout = process.stdout;
|
|
45
|
+
const original = stdout.write.bind(stdout);
|
|
46
|
+
const protocolWrite = original;
|
|
47
|
+
Syslog.setLogSink(STDERR_LOG_SINK);
|
|
48
|
+
stdout.write = process.stderr.write.bind(process.stderr);
|
|
49
|
+
const onOutputError = (error) => {
|
|
50
|
+
if (error.code !== "EPIPE") this.log(`MCP stdio — sortie standard : ${error.message}`, "ERROR");
|
|
51
|
+
};
|
|
52
|
+
stdout.on("error", onOutputError);
|
|
53
|
+
try {
|
|
54
|
+
await serveMcpStdio(defineMcpGate({
|
|
55
|
+
tools: "modules",
|
|
56
|
+
instructions: STDIO_INSTRUCTIONS,
|
|
57
|
+
unprotectedRoles: [...localOperatorCaller().roles]
|
|
58
|
+
}), {
|
|
59
|
+
input: process.stdin,
|
|
60
|
+
write: (line) => {
|
|
61
|
+
protocolWrite(line);
|
|
62
|
+
},
|
|
63
|
+
runtime: {
|
|
64
|
+
modules: this.kernel?.modules,
|
|
65
|
+
log: (message, severity) => this.log(message, severity)
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} finally {
|
|
69
|
+
stdout.write = original;
|
|
70
|
+
stdout.removeListener("error", onOutputError);
|
|
71
|
+
}
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export { StdioCommand as default };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { canonicalResourceUri } from "nodefony";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// nodefony/config/config.ts
|
|
4
|
+
/**
|
|
5
|
+
* @nodefony/ai — CONFIGURATION DU MODULE (schéma Zod = source unique).
|
|
6
|
+
*
|
|
7
|
+
* ⭐ TL;DR : CE SCHÉMA EST LA CONFIG. Chaque `.default(...)` est la valeur d'usine ;
|
|
8
|
+
* changer un défaut du module = ÉDITER ICI (et nulle part ailleurs). L'app, elle,
|
|
9
|
+
* ne surcharge que ses écarts, via `use("@nodefony/ai", { … })`.
|
|
10
|
+
*
|
|
11
|
+
* RÈGLE D'OR (ADR-0006) : ce fichier porte le schéma commenté (type + validation +
|
|
12
|
+
* défaut + doc) ET matérialise les défauts par `parse({})`. Le builder
|
|
13
|
+
* (`defineAiConfig`) importe le schéma d'ici et ne retape aucune valeur —
|
|
14
|
+
* un défaut écrit à deux endroits finit toujours par diverger.
|
|
15
|
+
*
|
|
16
|
+
* SURCHARGE (précédence croissante) :
|
|
17
|
+
* • défauts du schéma (ce fichier) ;
|
|
18
|
+
* • app : `use("@nodefony/ai", { … })` dans `nodefony.config.ts` ;
|
|
19
|
+
* • déploiement : un NOM COURT, si le champ en déclare un — `.meta({ env: "NF_AI_HOTE" })`
|
|
20
|
+
* sur le champ suffit : le Kernel l'applique, `nodefony env` et `.env.example`
|
|
21
|
+
* le montrent. C'est le contrat de PRODUCTION (nom stable, documenté) ;
|
|
22
|
+
* • banc, dépannage : `NF__AI__<CHEMIN>=valeur` (override générique, `__` = niveau).
|
|
23
|
+
*
|
|
24
|
+
* Le schéma reste **PUR** : aucune lecture de `process.env`, aucun accès au kernel
|
|
25
|
+
* (il est évalué à l'import — le kernel n'existe pas encore).
|
|
26
|
+
*
|
|
27
|
+
* Champ sensible (clé, mot de passe) → `.meta({ secret: true })` EN DERNIER de la
|
|
28
|
+
* chaîne : chaque méthode zod clone, une `.default()` posée après `.meta()` perdrait
|
|
29
|
+
* la métadonnée. Ces flags ressortent dans le JSON Schema lu par Studio.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* ⚠️ `strictObject`, et non `object` : une clé INCONNUE doit être REFUSÉE, pas
|
|
33
|
+
* retirée en silence. C'est le défaut par défaut de Zod, et il coûte cher —
|
|
34
|
+
* `use("@nodefony/ai", { gretting: "…" })` produisait une application qui
|
|
35
|
+
* démarre en IGNORANT ce que l'utilisateur a écrit, sans un mot. Le typage du
|
|
36
|
+
* registre `NodefonyModuleConfig` attrape la faute de frappe à la COMPILATION ;
|
|
37
|
+
* ceci l'attrape au DÉMARRAGE, pour tout ce qui contourne le compilateur — une
|
|
38
|
+
* config chargée d'un fichier, un `as never`, un override d'environnement.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Rôle **serveur de ressource OAuth 2.1** de la porte MCP — éteint par défaut.
|
|
42
|
+
*
|
|
43
|
+
* ⭐ **Un seul réglage commande : {@link authorizationServers}.** Vide, la porte
|
|
44
|
+
* reste anonyme — aucune métadonnée publiée, aucun `401`. Non vide, le rôle
|
|
45
|
+
* s'allume ENTIÈREMENT. Un interrupteur séparé aurait permis deux états qui se
|
|
46
|
+
* contredisent (« protégé mais sans serveur d'autorisation », « métadonnées
|
|
47
|
+
* publiées mais jetons ignorés »), et c'est précisément ce genre d'état que
|
|
48
|
+
* personne ne diagnostique.
|
|
49
|
+
*
|
|
50
|
+
* ⚠️ **Allumer ce rôle ne suffit pas à protéger quoi que ce soit** : il faut
|
|
51
|
+
* aussi qu'un service du conteneur sache VÉRIFIER un jeton. S'il n'y en a pas,
|
|
52
|
+
* la porte refuse de servir (et le dit fort) plutôt que d'accepter n'importe
|
|
53
|
+
* quel porteur.
|
|
54
|
+
*/
|
|
55
|
+
const mcpAuthorizationSchema = z.strictObject({
|
|
56
|
+
/**
|
|
57
|
+
* Serveurs d'autorisation capables d'émettre un jeton pour cette porte.
|
|
58
|
+
*
|
|
59
|
+
* Vide (défaut) = rôle éteint. Non vide, la spécification MCP impose que le
|
|
60
|
+
* document de métadonnées les publie (« MUST include the
|
|
61
|
+
* `authorization_servers` field containing at least one authorization
|
|
62
|
+
* server ») : sans eux, un client apprendrait qu'un jeton est nécessaire
|
|
63
|
+
* sans jamais pouvoir en obtenir un.
|
|
64
|
+
*/
|
|
65
|
+
authorizationServers: z.array(z.string()).default([]).describe("Émetteurs de jetons acceptés (issuer OAuth) ; vide = aucune autorisation"),
|
|
66
|
+
/**
|
|
67
|
+
* URI canonique publique de cette porte — l'audience que les jetons doivent
|
|
68
|
+
* porter (RFC 8707).
|
|
69
|
+
*
|
|
70
|
+
* 🔴 **Elle s'écrit, elle ne se devine pas depuis l'en-tête `Host`.** Si
|
|
71
|
+
* l'URI publiée et l'audience attendue venaient toutes deux de la requête,
|
|
72
|
+
* un `Host` forgé obtiendrait un jeton d'audience arbitraire *et* passerait
|
|
73
|
+
* la vérification : la liaison d'audience, dont c'est l'unique raison
|
|
74
|
+
* d'être, ne protégerait plus rien.
|
|
75
|
+
*
|
|
76
|
+
* Ex. `https://mon-app.example/nodefony/mcp`.
|
|
77
|
+
*/
|
|
78
|
+
resource: z.string().default("").describe("URI publique de la porte MCP (audience attendue des jetons)"),
|
|
79
|
+
/**
|
|
80
|
+
* Autres adresses de CETTE MÊME porte, dont les jetons sont aussi acceptés.
|
|
81
|
+
*
|
|
82
|
+
* Le cas courant : l'application sert la porte en clair sur un port et en
|
|
83
|
+
* TLS sur un autre. Un jeton émis pour l'une était alors refusé sur l'autre
|
|
84
|
+
* — la liaison d'audience (RFC 8707) faisant son travail. Nommer la seconde
|
|
85
|
+
* adresse est la bonne réponse ; relâcher la liaison n'en serait pas une.
|
|
86
|
+
*
|
|
87
|
+
* 🔴 Ces valeurs s'ÉCRIVENT. Dérivées du `Host`, un en-tête forgé
|
|
88
|
+
* obtiendrait un jeton d'audience arbitraire ET passerait la vérification.
|
|
89
|
+
* Seule `resource` est publiée en RFC 9728 : le document n'admet qu'une
|
|
90
|
+
* valeur, et un client n'a besoin que d'une adresse.
|
|
91
|
+
*
|
|
92
|
+
* ⚠️ L'ÉMETTEUR doit servir ces audiences (`security.jwt.audiences`), sinon
|
|
93
|
+
* il refuse de les émettre — `invalid_target`, et à juste titre.
|
|
94
|
+
*/
|
|
95
|
+
additionalResources: z.array(z.string()).default([]).describe("Autres URI de la même porte dont les jetons sont acceptés (jamais dérivées du Host)"),
|
|
96
|
+
/** Nom lisible, affiché pendant le consentement. */
|
|
97
|
+
resourceName: z.string().optional().describe("Nom affiché au consentement"),
|
|
98
|
+
/** Page de documentation destinée à un humain. */
|
|
99
|
+
resourceDocumentation: z.string().optional().describe("URL de documentation de la ressource"),
|
|
100
|
+
/**
|
|
101
|
+
* Servir une requête SANS jeton comme anonyme, au lieu de la refuser.
|
|
102
|
+
*
|
|
103
|
+
* `false` (défaut) : sans jeton, `401` + `WWW-Authenticate` — c'est ce qui
|
|
104
|
+
* apprend au client qu'une autorisation existe et où l'obtenir.
|
|
105
|
+
* `true` : la porte reste ouverte aux outils publics, et les outils
|
|
106
|
+
* réservés restent retenus. Utile en développement ; c'est un choix qui
|
|
107
|
+
* s'écrit, jamais un comportement dont on hérite.
|
|
108
|
+
*/
|
|
109
|
+
anonymous: z.boolean().default(false).describe("Tolérer les requêtes sans jeton (outils publics seulement)")
|
|
110
|
+
}).superRefine((value, ctx) => {
|
|
111
|
+
if (value.authorizationServers.length === 0) return;
|
|
112
|
+
if (value.resource.length === 0) {
|
|
113
|
+
ctx.addIssue({
|
|
114
|
+
code: "custom",
|
|
115
|
+
path: ["resource"],
|
|
116
|
+
message: "`authorization.resource` est requis dès qu'un serveur d'autorisation est déclaré : c'est l'URI publique de la porte, et l'audience que les jetons doivent porter (RFC 8707)."
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
canonicalResourceUri(value.resource);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
ctx.addIssue({
|
|
124
|
+
code: "custom",
|
|
125
|
+
path: ["resource"],
|
|
126
|
+
message: error instanceof Error ? error.message : String(error)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Réglages de la porte MCP (`POST /nodefony/mcp`) — la SOURCE UNIQUE du schéma
|
|
132
|
+
* `mcp.*`, que tout module qui sert ou configure la porte importe d'ici.
|
|
133
|
+
*
|
|
134
|
+
* Les outils exposés ne se règlent PAS ici : chaque module déclare les siens
|
|
135
|
+
* (`getMcpTools()`), et un module qui veut filtrer son propre catalogue porte ce
|
|
136
|
+
* réglage dans SA config.
|
|
137
|
+
*
|
|
138
|
+
* Tant qu'aucun serveur d'autorisation n'est déclaré, la porte n'est protégée
|
|
139
|
+
* que par les deux gardes que la spec impose au transport ({@link allowedOrigins},
|
|
140
|
+
* {@link allowRemote}) — qui visent le risque réel d'une porte locale : une page
|
|
141
|
+
* web ouverte dans le navigateur du développeur.
|
|
142
|
+
*
|
|
143
|
+
* ⚠️ **Piège Zod 4** : un `.default({})` posé à plat sur un sous-objet NE
|
|
144
|
+
* ré-applique PAS les défauts de ses champs. Le pattern du dépôt est donc
|
|
145
|
+
* `sous.default(() => sous.parse({}))` — le callback force la ré-évaluation, et
|
|
146
|
+
* une application qui n'écrit rien obtient bien les valeurs d'usine.
|
|
147
|
+
*/
|
|
148
|
+
const mcpConfigSchema = z.strictObject({
|
|
149
|
+
/** Répond-on aux requêtes MCP ? Coupé, la route rend `404`. */
|
|
150
|
+
enabled: z.boolean().default(true).describe("Active la porte MCP ; coupée, elle répond 404"),
|
|
151
|
+
/**
|
|
152
|
+
* Origines acceptées quand l'en-tête `Origin` est PRÉSENT.
|
|
153
|
+
*
|
|
154
|
+
* ⭐ La subtilité qui fait toute la sécurité : un client MCP natif est un
|
|
155
|
+
* process, pas un navigateur — **il n'envoie pas d'`Origin`**. Une page web
|
|
156
|
+
* malveillante, elle, en envoie toujours un vers `localhost`. La règle est
|
|
157
|
+
* donc : *absent → on passe* ; *présent et hors de cette liste → `403`*.
|
|
158
|
+
* C'est ce que la spec exige (`transports/streamable-http` §Security :
|
|
159
|
+
* « Servers MUST validate the `Origin` header […] MUST respond with HTTP 403
|
|
160
|
+
* Forbidden »), et c'est ce qui ferme le DNS rebinding.
|
|
161
|
+
*
|
|
162
|
+
* Vide (défaut) = aucune origine de navigateur n'est admise.
|
|
163
|
+
*/
|
|
164
|
+
allowedOrigins: z.array(z.string()).default([]).describe("Origines navigateur admises ; vide = aucune"),
|
|
165
|
+
/**
|
|
166
|
+
* Accepter un appel dont l'adresse distante n'est pas locale.
|
|
167
|
+
*
|
|
168
|
+
* La spec recommande de n'écouter que sur la boucle locale ; le serveur de
|
|
169
|
+
* l'application, lui, écoute pour tout le monde. La garde est donc portée
|
|
170
|
+
* par la route : toute adresse non locale reçoit `403`.
|
|
171
|
+
*/
|
|
172
|
+
allowRemote: z.boolean().default(false).describe("Autorise les appels depuis une adresse non locale"),
|
|
173
|
+
/** Rôle serveur de ressource OAuth 2.1 — **éteint par défaut**. */
|
|
174
|
+
authorization: mcpAuthorizationSchema.default(() => mcpAuthorizationSchema.parse({})).describe("Serveur de ressource OAuth 2.1 (RFC 9728/6750/8707)")
|
|
175
|
+
});
|
|
176
|
+
const aiConfigSchema = z.strictObject({
|
|
177
|
+
/** Interrupteur du module — l'app peut le charger sans l'activer. */
|
|
178
|
+
enabled: z.boolean().default(true).describe("Active les fonctionnalités du module ai") });
|
|
179
|
+
/** Défauts matérialisés (passés au `super()` du Module). */
|
|
180
|
+
const defaults = aiConfigSchema.parse({});
|
|
181
|
+
export { aiConfigSchema, defaults as default, mcpConfigSchema };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { aiConfigSchema } from "./config.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// 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
|
+
export { configJsonSchema };
|