@jini-ai/http-kit 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +107 -0
- package/dist/active-context.d.ts +99 -0
- package/dist/active-context.d.ts.map +1 -0
- package/dist/active-context.js +77 -0
- package/dist/active-context.js.map +1 -0
- package/dist/adapter.d.ts +36 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +92 -0
- package/dist/adapter.js.map +1 -0
- package/dist/agents.d.ts +55 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +23 -0
- package/dist/agents.js.map +1 -0
- package/dist/api-security-middleware.d.ts +146 -0
- package/dist/api-security-middleware.d.ts.map +1 -0
- package/dist/api-security-middleware.js +276 -0
- package/dist/api-security-middleware.js.map +1 -0
- package/dist/attachments.d.ts +317 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/attachments.js +664 -0
- package/dist/attachments.js.map +1 -0
- package/dist/cancel-owned-runs.d.ts +44 -0
- package/dist/cancel-owned-runs.d.ts.map +1 -0
- package/dist/cancel-owned-runs.js +35 -0
- package/dist/cancel-owned-runs.js.map +1 -0
- package/dist/compat.d.ts +22 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +17 -0
- package/dist/compat.js.map +1 -0
- package/dist/component-catalog.d.ts +74 -0
- package/dist/component-catalog.d.ts.map +1 -0
- package/dist/component-catalog.js +74 -0
- package/dist/component-catalog.js.map +1 -0
- package/dist/connectors.d.ts +165 -0
- package/dist/connectors.d.ts.map +1 -0
- package/dist/connectors.js +474 -0
- package/dist/connectors.js.map +1 -0
- package/dist/daemon-status.d.ts +72 -0
- package/dist/daemon-status.d.ts.map +1 -0
- package/dist/daemon-status.js +60 -0
- package/dist/daemon-status.js.map +1 -0
- package/dist/db-ops.d.ts +116 -0
- package/dist/db-ops.d.ts.map +1 -0
- package/dist/db-ops.js +191 -0
- package/dist/db-ops.js.map +1 -0
- package/dist/delegated-tools.d.ts +46 -0
- package/dist/delegated-tools.d.ts.map +1 -0
- package/dist/delegated-tools.js +155 -0
- package/dist/delegated-tools.js.map +1 -0
- package/dist/express/run-stream.d.ts +15 -0
- package/dist/express/run-stream.d.ts.map +1 -0
- package/dist/express/run-stream.js +11 -0
- package/dist/express/run-stream.js.map +1 -0
- package/dist/express-index.d.ts +32 -0
- package/dist/express-index.d.ts.map +1 -0
- package/dist/express-index.js +14 -0
- package/dist/express-index.js.map +1 -0
- package/dist/fastify/adapter.d.ts +31 -0
- package/dist/fastify/adapter.d.ts.map +1 -0
- package/dist/fastify/adapter.js +64 -0
- package/dist/fastify/adapter.js.map +1 -0
- package/dist/fastify/agents.d.ts +13 -0
- package/dist/fastify/agents.d.ts.map +1 -0
- package/dist/fastify/agents.js +7 -0
- package/dist/fastify/agents.js.map +1 -0
- package/dist/fastify/api-security-middleware.d.ts +64 -0
- package/dist/fastify/api-security-middleware.d.ts.map +1 -0
- package/dist/fastify/api-security-middleware.js +139 -0
- package/dist/fastify/api-security-middleware.js.map +1 -0
- package/dist/fastify/compat.d.ts +22 -0
- package/dist/fastify/compat.d.ts.map +1 -0
- package/dist/fastify/compat.js +16 -0
- package/dist/fastify/compat.js.map +1 -0
- package/dist/fastify/daemon-status.d.ts +22 -0
- package/dist/fastify/daemon-status.d.ts.map +1 -0
- package/dist/fastify/daemon-status.js +9 -0
- package/dist/fastify/daemon-status.js.map +1 -0
- package/dist/fastify/host-tools.d.ts +13 -0
- package/dist/fastify/host-tools.d.ts.map +1 -0
- package/dist/fastify/host-tools.js +8 -0
- package/dist/fastify/host-tools.js.map +1 -0
- package/dist/fastify/index.d.ts +36 -0
- package/dist/fastify/index.d.ts.map +1 -0
- package/dist/fastify/index.js +18 -0
- package/dist/fastify/index.js.map +1 -0
- package/dist/fastify/local-daemon-request.d.ts +43 -0
- package/dist/fastify/local-daemon-request.d.ts.map +1 -0
- package/dist/fastify/local-daemon-request.js +155 -0
- package/dist/fastify/local-daemon-request.js.map +1 -0
- package/dist/fastify/origin.d.ts +21 -0
- package/dist/fastify/origin.d.ts.map +1 -0
- package/dist/fastify/origin.js +14 -0
- package/dist/fastify/origin.js.map +1 -0
- package/dist/fastify/request.d.ts +20 -0
- package/dist/fastify/request.d.ts.map +1 -0
- package/dist/fastify/request.js +25 -0
- package/dist/fastify/request.js.map +1 -0
- package/dist/fastify/response.d.ts +20 -0
- package/dist/fastify/response.d.ts.map +1 -0
- package/dist/fastify/response.js +41 -0
- package/dist/fastify/response.js.map +1 -0
- package/dist/fastify/route-registration-guard.d.ts +70 -0
- package/dist/fastify/route-registration-guard.d.ts.map +1 -0
- package/dist/fastify/route-registration-guard.js +69 -0
- package/dist/fastify/route-registration-guard.js.map +1 -0
- package/dist/fastify/run-stream.d.ts +18 -0
- package/dist/fastify/run-stream.d.ts.map +1 -0
- package/dist/fastify/run-stream.js +10 -0
- package/dist/fastify/run-stream.js.map +1 -0
- package/dist/fastify/runs.d.ts +17 -0
- package/dist/fastify/runs.d.ts.map +1 -0
- package/dist/fastify/runs.js +33 -0
- package/dist/fastify/runs.js.map +1 -0
- package/dist/frontend-control.d.ts +131 -0
- package/dist/frontend-control.d.ts.map +1 -0
- package/dist/frontend-control.js +77 -0
- package/dist/frontend-control.js.map +1 -0
- package/dist/frontend-sessions.d.ts +100 -0
- package/dist/frontend-sessions.d.ts.map +1 -0
- package/dist/frontend-sessions.js +180 -0
- package/dist/frontend-sessions.js.map +1 -0
- package/dist/health.d.ts +91 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +53 -0
- package/dist/health.js.map +1 -0
- package/dist/host-tools.d.ts +174 -0
- package/dist/host-tools.d.ts.map +1 -0
- package/dist/host-tools.js +338 -0
- package/dist/host-tools.js.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/local-daemon-request.d.ts +44 -0
- package/dist/local-daemon-request.d.ts.map +1 -0
- package/dist/local-daemon-request.js +145 -0
- package/dist/local-daemon-request.js.map +1 -0
- package/dist/media.d.ts +131 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +352 -0
- package/dist/media.js.map +1 -0
- package/dist/memory.d.ts +230 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +331 -0
- package/dist/memory.js.map +1 -0
- package/dist/model-proxy.d.ts +45 -0
- package/dist/model-proxy.d.ts.map +1 -0
- package/dist/model-proxy.js +619 -0
- package/dist/model-proxy.js.map +1 -0
- package/dist/origin-validation.d.ts +64 -0
- package/dist/origin-validation.d.ts.map +1 -0
- package/dist/origin-validation.js +226 -0
- package/dist/origin-validation.js.map +1 -0
- package/dist/origin.d.ts +32 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +14 -0
- package/dist/origin.js.map +1 -0
- package/dist/pack-http.d.ts +30 -0
- package/dist/pack-http.d.ts.map +1 -0
- package/dist/pack-http.js +12 -0
- package/dist/pack-http.js.map +1 -0
- package/dist/raw-sse.d.ts +44 -0
- package/dist/raw-sse.d.ts.map +1 -0
- package/dist/raw-sse.js +93 -0
- package/dist/raw-sse.js.map +1 -0
- package/dist/remote-run-events.d.ts +66 -0
- package/dist/remote-run-events.d.ts.map +1 -0
- package/dist/remote-run-events.js +230 -0
- package/dist/remote-run-events.js.map +1 -0
- package/dist/request.d.ts +19 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +25 -0
- package/dist/request.js.map +1 -0
- package/dist/research.d.ts +42 -0
- package/dist/research.d.ts.map +1 -0
- package/dist/research.js +316 -0
- package/dist/research.js.map +1 -0
- package/dist/response.d.ts +14 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +45 -0
- package/dist/response.js.map +1 -0
- package/dist/route-manifest.d.ts +31 -0
- package/dist/route-manifest.d.ts.map +1 -0
- package/dist/route-manifest.js +103 -0
- package/dist/route-manifest.js.map +1 -0
- package/dist/route-registration-guard.d.ts +65 -0
- package/dist/route-registration-guard.d.ts.map +1 -0
- package/dist/route-registration-guard.js +71 -0
- package/dist/route-registration-guard.js.map +1 -0
- package/dist/routines.d.ts +114 -0
- package/dist/routines.d.ts.map +1 -0
- package/dist/routines.js +320 -0
- package/dist/routines.js.map +1 -0
- package/dist/run-stream.d.ts +60 -0
- package/dist/run-stream.d.ts.map +1 -0
- package/dist/run-stream.js +108 -0
- package/dist/run-stream.js.map +1 -0
- package/dist/runs.d.ts +79 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +232 -0
- package/dist/runs.js.map +1 -0
- package/dist/sse.d.ts +139 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +157 -0
- package/dist/sse.js.map +1 -0
- package/dist/terminals.d.ts +125 -0
- package/dist/terminals.d.ts.map +1 -0
- package/dist/terminals.js +349 -0
- package/dist/terminals.js.map +1 -0
- package/dist/tool-catalog.d.ts +68 -0
- package/dist/tool-catalog.d.ts.map +1 -0
- package/dist/tool-catalog.js +68 -0
- package/dist/tool-catalog.js.map +1 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/workspace-root.d.ts +69 -0
- package/dist/workspace-root.d.ts.map +1 -0
- package/dist/workspace-root.js +63 -0
- package/dist/workspace-root.js.map +1 -0
- package/dist/xai.d.ts +86 -0
- package/dist/xai.d.ts.map +1 -0
- package/dist/xai.js +668 -0
- package/dist/xai.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Open Design contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @jini-ai/http-kit
|
|
2
|
+
|
|
3
|
+
A toolkit of composable Express route packs and a JSON-route transport for a `@jini-ai/core`
|
|
4
|
+
daemon composition: request parsing, response serialization, a same-origin guard, SSE streaming,
|
|
5
|
+
and a ready-to-mount set of kernel route packs (runs, agents, memory, routines, terminals, and
|
|
6
|
+
more). This package does **not** open a listener itself — a host (your own Express app, or
|
|
7
|
+
`@jini-ai/server`'s `createLocalNodeDaemon`, which is the one assembled preset that does bind a
|
|
8
|
+
port) mounts these route-registrars onto its own `app`.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @jini-ai/http-kit express
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`express` is a regular dependency (`^4.21.0`) pulled in automatically; you still need it installed
|
|
17
|
+
in your own app if you're calling its types directly. `@jini-ai/agent-runtime`, `@jini-ai/core`,
|
|
18
|
+
`@jini-ai/daemon`, `@jini-ai/platform`, and `@jini-ai/protocol` are also regular dependencies — no
|
|
19
|
+
optional peers.
|
|
20
|
+
|
|
21
|
+
## What you get
|
|
22
|
+
|
|
23
|
+
- **Route-spec primitives** — `JsonRouteSpec`/`InputParser`/`Handler`/`HttpMethod`/
|
|
24
|
+
`RouteInputContext`, the `Result<T, E>` envelope (`ok`/`err`), and `defineJsonRoute`/
|
|
25
|
+
`mountJsonRoute` (the Adapter — the only code here that touches Express `req`/`res` directly).
|
|
26
|
+
- **Origin and auth guards** — `origin-validation`'s host/origin classifiers
|
|
27
|
+
(`isLocalSameOrigin`, `isAllowedBrowserOrigin`, `parseHostHeader`, `isPrivateIpv4`, ...),
|
|
28
|
+
`registerApiBearerAuthMiddleware`/`registerApiOriginGuardMiddleware`, and
|
|
29
|
+
`requireLocalDaemonRequest`/`validateLocalDaemonRequest` for daemon-local-only routes.
|
|
30
|
+
- **Streaming** — `createSseChannel` (cursor-replayable SSE with a bounded queue) and
|
|
31
|
+
`createSseResponse` (raw, unbuffered SSE, used by the frontend-session stream).
|
|
32
|
+
- **Pack composition glue** — `mountPackHttp(app, packs, daemon)` calls every composed
|
|
33
|
+
`@jini-ai/core` pack's own `http(app, services)` registrar with the services `createDaemon`
|
|
34
|
+
already resolved for it; `cancelRunsOwnedBy` and `installRouteRegistrationGuard`/
|
|
35
|
+
`getRouteRegistrationInventory` (duplicate-route detection) support that composition.
|
|
36
|
+
- **Daemon lifecycle routes** — `registerDaemonStatusRoutes` (`daemonStatusRoute`,
|
|
37
|
+
`daemonShutdownRoute`) and `registerHealthRoutes` (`/health`, `/ready`, `/version` and their
|
|
38
|
+
`/api`-prefixed twins — deliberately open, unauthenticated probes).
|
|
39
|
+
- **Kernel route packs, ready to mount** — one `register*Routes` function per concern: runs
|
|
40
|
+
(`registerRunRoutes`), agents (`registerAgentRoutes`), memory (`registerMemoryRoutes`),
|
|
41
|
+
routines (`registerRoutineRoutes`), terminals (`registerTerminalRoutes`), db-ops
|
|
42
|
+
(`registerDaemonDbRoutes` + tool registrations), tool catalog (`registerToolCatalogRoutes`),
|
|
43
|
+
delegated tools (`registerDelegatedToolRoutes`), remote run events
|
|
44
|
+
(`registerRemoteRunEventRoutes`), frontend sessions (`registerFrontendSessionRoutes`), active
|
|
45
|
+
context (`registerActiveContextRoutes`), host tools (`registerHostToolsRoutes`), model proxy
|
|
46
|
+
(`registerModelProxyRoutes`), connectors — auth/db/payments/storage/realtime provider seams
|
|
47
|
+
(`registerConnectorsRoutes`), research (`registerResearchRoutes`), media
|
|
48
|
+
(`registerMediaRoutes`), and xai (`registerXaiRoutes`). Each exports its own `*HttpDeps` type so
|
|
49
|
+
you inject exactly the backing services it needs.
|
|
50
|
+
- **Workspace root resolution** — `resolveWorkspaceRoot`/`denyAllWorkspaceRoots`/
|
|
51
|
+
`WorkspaceRootDeniedError`.
|
|
52
|
+
- **Legacy-shaped compat errors** — `createCompatApiError`/`createCompatApiErrorResponse`/
|
|
53
|
+
`sendCompatApiError`, a `(code, message, init)` call shape kept alongside the main `ApiError`
|
|
54
|
+
envelope for call sites generated against the older shape.
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import express from 'express';
|
|
60
|
+
import {
|
|
61
|
+
defineJsonRoute,
|
|
62
|
+
mountJsonRoute,
|
|
63
|
+
registerHealthRoutes,
|
|
64
|
+
ok,
|
|
65
|
+
type AdapterContext,
|
|
66
|
+
} from '@jini-ai/http-kit';
|
|
67
|
+
|
|
68
|
+
const app = express();
|
|
69
|
+
app.use(express.json());
|
|
70
|
+
|
|
71
|
+
const adapter: AdapterContext = { resolvedPortRef: { current: 4000 } };
|
|
72
|
+
|
|
73
|
+
// Ready-to-mount kernel routes: GET /health, /ready, /version (+ /api-prefixed twins).
|
|
74
|
+
registerHealthRoutes(app, { getVersion: () => '1.0.0' }, adapter);
|
|
75
|
+
|
|
76
|
+
// A custom route built on the same Result/JsonRouteSpec pipeline.
|
|
77
|
+
const echoRoute = defineJsonRoute<{ msg: string }, { echoed: string }, void>({
|
|
78
|
+
method: 'post',
|
|
79
|
+
path: '/echo',
|
|
80
|
+
parse: (raw) => ok({ msg: String((raw.body as { msg?: unknown })?.msg ?? '') }),
|
|
81
|
+
handle: (input) => ok({ echoed: input.msg }),
|
|
82
|
+
});
|
|
83
|
+
mountJsonRoute(app, echoRoute, undefined, adapter);
|
|
84
|
+
|
|
85
|
+
app.listen(4000);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## What's swappable
|
|
89
|
+
|
|
90
|
+
Every route pack takes its backing services as an injected `*HttpDeps` object (e.g.
|
|
91
|
+
`HealthHttpDeps.getVersion`/`checkReadiness`, `RunHttpDeps`, `MemoryHttpDeps`) rather than reaching
|
|
92
|
+
for a global — swap in whatever implementation your host provides. `JsonRouteSpec.parse`/`handle`
|
|
93
|
+
are themselves the seam for a fully custom route. Fixed and not meant to be replaced: the Express
|
|
94
|
+
mounting mechanics in `adapter.ts` (this package does not support a non-Express framework — a
|
|
95
|
+
prior switchable Fastify transport was removed on 2026-07-22; see `source-map.md` and
|
|
96
|
+
`FASTIFY-TRANSPORT-PARKED.md` on the `future/fastify-transport` branch if reviving it), and the
|
|
97
|
+
`Result`/`ApiError` error-handling pipeline every route folds into.
|
|
98
|
+
|
|
99
|
+
## Runtime
|
|
100
|
+
|
|
101
|
+
`jini.runtime: "node"` — mounts onto a real Express `app`, uses Node's `express` types throughout.
|
|
102
|
+
ESM only — ships `"type": "module"` with no CommonJS `require` build.
|
|
103
|
+
|
|
104
|
+
## Provenance
|
|
105
|
+
|
|
106
|
+
See [source-map.md](./source-map.md) for per-file provenance and scope decisions. Apache-2.0,
|
|
107
|
+
inherited from Open Design — see the repo `NOTICE`.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module active-context
|
|
3
|
+
*
|
|
4
|
+
* Generic "what resource is the caller currently focused on?" channel: an
|
|
5
|
+
* in-memory, TTL-scoped pointer a client POSTs to record its current focus
|
|
6
|
+
* and GETs to read back (resolved against a real display name via an
|
|
7
|
+
* injected lookup). Ported from the routes-classification table's
|
|
8
|
+
* `active-context.ts` MIXED row (see `source-map.md`) — the origin's only
|
|
9
|
+
* real coupling was `handleGetActive` calling into an OD project store to
|
|
10
|
+
* resolve a display name; the TTL store and both handlers were already
|
|
11
|
+
* product-neutral, and all handlers are synchronous (no async risk).
|
|
12
|
+
*
|
|
13
|
+
* The origin's `projectId`/`fileName` fields are generalized here to a
|
|
14
|
+
* single opaque `resourceRef` (was `projectId`) plus an optional `detail`
|
|
15
|
+
* string (was `fileName` — a sub-locator within that resource), matching
|
|
16
|
+
* the source-map's own "renaming to a generic resource ref" note. The
|
|
17
|
+
* origin's `deps.getProject` lookup becomes an injected `resolveResource`
|
|
18
|
+
* dependency, matching this branch's DI convention (see
|
|
19
|
+
* `daemon-status.ts`/`host-tools.ts`: real collaborators supplied by the
|
|
20
|
+
* caller rather than read from a global store).
|
|
21
|
+
*/
|
|
22
|
+
import type { Express } from 'express';
|
|
23
|
+
import { type AdapterContext } from './adapter.js';
|
|
24
|
+
/** How long a recorded focus stays valid before a GET treats it as stale and clears it. */
|
|
25
|
+
export declare const ACTIVE_CONTEXT_TTL_MS: number;
|
|
26
|
+
interface ActiveContext {
|
|
27
|
+
resourceRef: string;
|
|
28
|
+
detail: string | null;
|
|
29
|
+
ts: number;
|
|
30
|
+
}
|
|
31
|
+
interface ActiveContextStore {
|
|
32
|
+
current: ActiveContext | null;
|
|
33
|
+
}
|
|
34
|
+
type SetActiveInput = {
|
|
35
|
+
kind: 'clear';
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'set';
|
|
38
|
+
resourceRef: string;
|
|
39
|
+
detail: string | null;
|
|
40
|
+
};
|
|
41
|
+
type SetActiveOutput = {
|
|
42
|
+
active: false;
|
|
43
|
+
} | {
|
|
44
|
+
active: true;
|
|
45
|
+
resourceRef: string;
|
|
46
|
+
detail: string | null;
|
|
47
|
+
ts: number;
|
|
48
|
+
};
|
|
49
|
+
type GetActiveOutput = {
|
|
50
|
+
active: false;
|
|
51
|
+
} | {
|
|
52
|
+
active: true;
|
|
53
|
+
resourceRef: string;
|
|
54
|
+
resourceName: string | null;
|
|
55
|
+
detail: string | null;
|
|
56
|
+
ts: number;
|
|
57
|
+
ageMs: number;
|
|
58
|
+
};
|
|
59
|
+
/** A resolved resource's display name. `resolveResource` itself may return `null`/`undefined` (not this type) when the caller has no entry at all for a given resource ref (e.g. unknown or deleted). */
|
|
60
|
+
export interface ActiveContextResource {
|
|
61
|
+
readonly name?: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** What a caller must supply to mount the active-context routes. */
|
|
64
|
+
export interface ActiveContextDeps {
|
|
65
|
+
/**
|
|
66
|
+
* Resolves a display name for a resource ref (was OD's project store's
|
|
67
|
+
* `getProject`). Injected so this module has no dependency on any
|
|
68
|
+
* particular resource store; may return `null`/`undefined` if the ref is
|
|
69
|
+
* unknown.
|
|
70
|
+
*/
|
|
71
|
+
resolveResource: (resourceRef: string) => ActiveContextResource | null | undefined;
|
|
72
|
+
/** Returns the current time in epoch ms. Defaults to `Date.now` when omitted. */
|
|
73
|
+
now?: () => number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Internal deps threaded to both handlers: the caller-supplied
|
|
77
|
+
* {@link ActiveContextDeps} plus the shared in-memory store built once per
|
|
78
|
+
* `registerActiveContextRoutes` call, so the two routes see the same state.
|
|
79
|
+
*/
|
|
80
|
+
interface ActiveContextRouteDeps {
|
|
81
|
+
store: ActiveContextStore;
|
|
82
|
+
resolveResource: ActiveContextDeps['resolveResource'];
|
|
83
|
+
now: () => number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `POST /api/active` — records (or, with `{active: false}`, clears) the
|
|
87
|
+
* caller's current resource focus.
|
|
88
|
+
*/
|
|
89
|
+
export declare const setActiveRoute: import("./types.js").JsonRouteSpec<SetActiveInput, SetActiveOutput, ActiveContextRouteDeps>;
|
|
90
|
+
/**
|
|
91
|
+
* `GET /api/active` — reads back the current resource focus, resolving a
|
|
92
|
+
* display name for it, or `{active: false}` if nothing is set or the
|
|
93
|
+
* recorded focus has aged past {@link ACTIVE_CONTEXT_TTL_MS}.
|
|
94
|
+
*/
|
|
95
|
+
export declare const getActiveRoute: import("./types.js").JsonRouteSpec<void, GetActiveOutput, ActiveContextRouteDeps>;
|
|
96
|
+
/** Mounts both active-context routes on `app`, sharing one in-memory store between them. A pack's `http(app, services)` calls this directly. */
|
|
97
|
+
export declare function registerActiveContextRoutes(app: Express, deps: ActiveContextDeps, adapter: AdapterContext): void;
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=active-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-context.d.ts","sourceRoot":"","sources":["../src/active-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,OAAO,EAA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AI,GAAG,SAAS,CAAC;IACnF,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,UAAU,sBAAsB;IAC9B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,eAAe,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,GAAG,EAAE,MAAM,MAAM,CAAC;CACnB;AA0CD;;;GAGG;AACH,eAAO,MAAM,cAAc,6FAMzB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,mFAMzB,CAAC;AAEH,gJAAgJ;AAChJ,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAShH"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createApiError } from '@jini-ai/protocol';
|
|
2
|
+
import { defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
3
|
+
import { err, ok } from './types.js';
|
|
4
|
+
/** How long a recorded focus stays valid before a GET treats it as stale and clears it. */
|
|
5
|
+
export const ACTIVE_CONTEXT_TTL_MS = 5 * 60 * 1000;
|
|
6
|
+
function parseSetActive(raw) {
|
|
7
|
+
const body = (raw.body ?? {});
|
|
8
|
+
if (body.active === false) {
|
|
9
|
+
return ok({ kind: 'clear' });
|
|
10
|
+
}
|
|
11
|
+
const resourceRef = typeof body.resourceRef === 'string' ? body.resourceRef : '';
|
|
12
|
+
if (!resourceRef) {
|
|
13
|
+
return err(createApiError('BAD_REQUEST', 'resourceRef is required'));
|
|
14
|
+
}
|
|
15
|
+
const detail = typeof body.detail === 'string' && body.detail.length > 0 ? body.detail : null;
|
|
16
|
+
return ok({ kind: 'set', resourceRef, detail });
|
|
17
|
+
}
|
|
18
|
+
function handleSetActive(input, deps) {
|
|
19
|
+
if (input.kind === 'clear') {
|
|
20
|
+
deps.store.current = null;
|
|
21
|
+
return ok({ active: false });
|
|
22
|
+
}
|
|
23
|
+
const next = { resourceRef: input.resourceRef, detail: input.detail, ts: deps.now() };
|
|
24
|
+
deps.store.current = next;
|
|
25
|
+
return ok({ active: true, ...next });
|
|
26
|
+
}
|
|
27
|
+
function handleGetActive(_input, deps) {
|
|
28
|
+
const current = deps.store.current;
|
|
29
|
+
if (!current || deps.now() - current.ts > ACTIVE_CONTEXT_TTL_MS) {
|
|
30
|
+
deps.store.current = null;
|
|
31
|
+
return ok({ active: false });
|
|
32
|
+
}
|
|
33
|
+
const resource = deps.resolveResource(current.resourceRef);
|
|
34
|
+
return ok({
|
|
35
|
+
active: true,
|
|
36
|
+
resourceRef: current.resourceRef,
|
|
37
|
+
resourceName: resource?.name ?? null,
|
|
38
|
+
detail: current.detail,
|
|
39
|
+
ts: current.ts,
|
|
40
|
+
ageMs: deps.now() - current.ts,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `POST /api/active` — records (or, with `{active: false}`, clears) the
|
|
45
|
+
* caller's current resource focus.
|
|
46
|
+
*/
|
|
47
|
+
export const setActiveRoute = defineJsonRoute({
|
|
48
|
+
method: 'post',
|
|
49
|
+
path: '/api/active',
|
|
50
|
+
requireSameOrigin: true,
|
|
51
|
+
parse: parseSetActive,
|
|
52
|
+
handle: handleSetActive,
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* `GET /api/active` — reads back the current resource focus, resolving a
|
|
56
|
+
* display name for it, or `{active: false}` if nothing is set or the
|
|
57
|
+
* recorded focus has aged past {@link ACTIVE_CONTEXT_TTL_MS}.
|
|
58
|
+
*/
|
|
59
|
+
export const getActiveRoute = defineJsonRoute({
|
|
60
|
+
method: 'get',
|
|
61
|
+
path: '/api/active',
|
|
62
|
+
requireSameOrigin: true,
|
|
63
|
+
parse: () => ok(undefined),
|
|
64
|
+
handle: handleGetActive,
|
|
65
|
+
});
|
|
66
|
+
/** Mounts both active-context routes on `app`, sharing one in-memory store between them. A pack's `http(app, services)` calls this directly. */
|
|
67
|
+
export function registerActiveContextRoutes(app, deps, adapter) {
|
|
68
|
+
const store = { current: null };
|
|
69
|
+
const routeDeps = {
|
|
70
|
+
store,
|
|
71
|
+
resolveResource: deps.resolveResource,
|
|
72
|
+
now: deps.now ?? (() => Date.now()),
|
|
73
|
+
};
|
|
74
|
+
mountJsonRoute(app, setActiveRoute, routeDeps, adapter);
|
|
75
|
+
mountJsonRoute(app, getActiveRoute, routeDeps, adapter);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=active-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-context.js","sourceRoot":"","sources":["../src/active-context.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAuB,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,YAAY,CAAC;AAElD,2FAA2F;AAC3F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AA0DnD,SAAS,cAAc,CAAC,GAAsB;IAC5C,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAC;IACzD,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACjF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,cAAc,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,MAAM,KAAK,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
2
|
+
import { type OriginContext } from './origin.js';
|
|
3
|
+
import type { JsonRouteSpec } from './types.js';
|
|
4
|
+
export interface AdapterInternalErrorContext {
|
|
5
|
+
/** HTTP method of the route whose handler threw. */
|
|
6
|
+
readonly method: string;
|
|
7
|
+
/** Registered path of the route whose handler threw. */
|
|
8
|
+
readonly path: string;
|
|
9
|
+
/** Echoed back to the caller as the response's `requestId`, so an operator can tie a user's report to this log line. */
|
|
10
|
+
readonly correlationId: string;
|
|
11
|
+
/** The exception exactly as thrown — never sent to the caller. */
|
|
12
|
+
readonly error: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** Server startup state a mounted route needs to evaluate its same-origin guard. */
|
|
15
|
+
export interface AdapterContext extends OriginContext {
|
|
16
|
+
/**
|
|
17
|
+
* Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005).
|
|
18
|
+
* Defaults to `console.error`. Mirrors the per-module `onInternalError` seams (`connectors.ts`,
|
|
19
|
+
* `delegated-tools.ts`, …); this one is the catch-all for a route that throws outside its own
|
|
20
|
+
* guarded path.
|
|
21
|
+
*/
|
|
22
|
+
readonly onInternalError?: (context: AdapterInternalErrorContext) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Identity function that pins a route spec's generic parameters at the definition site so
|
|
26
|
+
* callers do not have to repeat them. The returned spec is consumed by `mountJsonRoute` (live)
|
|
27
|
+
* and by tests (direct invocation of `route.parse` / `route.handle`).
|
|
28
|
+
*/
|
|
29
|
+
export declare function defineJsonRoute<Input, Output, Deps>(spec: JsonRouteSpec<Input, Output, Deps>): JsonRouteSpec<Input, Output, Deps>;
|
|
30
|
+
/**
|
|
31
|
+
* Mounts one JsonRouteSpec on an Express app. The Adapter is the only code here that knows
|
|
32
|
+
* about req/res; the route's parse and handle functions operate on `RouteInputContext` and
|
|
33
|
+
* `Deps` respectively, so they are unit testable without Express.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mountJsonRoute<Input, Output, Deps>(app: Express, spec: JsonRouteSpec<Input, Output, Deps>, deps: Deps, adapter: AdapterContext): void;
|
|
36
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAI1D,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,2BAA2B;IAC1C,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wHAAwH;IACxH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,oFAAoF;AACpF,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,IAAI,CAAC;CAC3E;AAOD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EACjD,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,GACvC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAEpC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAChD,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EACxC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,IAAI,CA4DN"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The module's top orchestration layer: wires request parsing, the same-origin guard, a route's
|
|
3
|
+
* `handle`, and response serialization into a single Express route handler. This is the only
|
|
4
|
+
* file in the module that knows about Express `req`/`res` on the mounting side.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { createApiError } from '@jini-ai/protocol';
|
|
8
|
+
import { rawInput } from './request.js';
|
|
9
|
+
import { sendApiError, sendJson, statusForError } from './response.js';
|
|
10
|
+
import { guardSameOrigin } from './origin.js';
|
|
11
|
+
function defaultInternalErrorSink(context) {
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.error(`[@jini-ai/http-kit] internal error (${context.method.toUpperCase()} ${context.path}, correlationId=${context.correlationId})`, context.error);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Identity function that pins a route spec's generic parameters at the definition site so
|
|
17
|
+
* callers do not have to repeat them. The returned spec is consumed by `mountJsonRoute` (live)
|
|
18
|
+
* and by tests (direct invocation of `route.parse` / `route.handle`).
|
|
19
|
+
*/
|
|
20
|
+
export function defineJsonRoute(spec) {
|
|
21
|
+
return spec;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Mounts one JsonRouteSpec on an Express app. The Adapter is the only code here that knows
|
|
25
|
+
* about req/res; the route's parse and handle functions operate on `RouteInputContext` and
|
|
26
|
+
* `Deps` respectively, so they are unit testable without Express.
|
|
27
|
+
*/
|
|
28
|
+
export function mountJsonRoute(app, spec, deps, adapter) {
|
|
29
|
+
app[spec.method](spec.path, async (req, res) => {
|
|
30
|
+
// The client-disconnect signal a `handle` can opt into via its 3rd param. Observed on `res`,
|
|
31
|
+
// not `req` — `sse.ts` already established why for this exact "detect a disconnect before
|
|
32
|
+
// ever writing a response" shape (its own doc: safe to register "before `open` is ever
|
|
33
|
+
// called"). `req`'s own `'close'` was tried first here and reverted: on a REAL socket, a
|
|
34
|
+
// POST's body is fully read by Express's body parser before this handler ever runs, and that
|
|
35
|
+
// finishes the *request* stream — firing `req`'s `'close'` immediately, long before any
|
|
36
|
+
// response is sent, with no disconnect having happened at all. `res`'s `'close'` isn't
|
|
37
|
+
// entangled with the request body's lifecycle, only with the response's own connection, so it
|
|
38
|
+
// doesn't share that false positive. Registered before anything awaits and unconditionally
|
|
39
|
+
// detached in `finally` below, so it never outlives one request.
|
|
40
|
+
const abortController = new AbortController();
|
|
41
|
+
const onResponseClose = () => abortController.abort();
|
|
42
|
+
// Optional-called rather than assumed present: a real Express `Response` always has `.on`, but
|
|
43
|
+
// several existing unit tests drive `mountJsonRoute` against a minimal `{status,json}` double
|
|
44
|
+
// that doesn't implement `EventEmitter` at all. Those callers simply never observe an abort,
|
|
45
|
+
// which is the correct behavior for a double that never fires `close` anyway.
|
|
46
|
+
res.on?.('close', onResponseClose);
|
|
47
|
+
try {
|
|
48
|
+
if (spec.requireSameOrigin) {
|
|
49
|
+
const origin = guardSameOrigin(req, adapter);
|
|
50
|
+
if (!origin.ok) {
|
|
51
|
+
sendApiError(res, statusForError(origin.error), origin.error);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const parsed = spec.parse(rawInput(req));
|
|
56
|
+
if (!parsed.ok) {
|
|
57
|
+
sendApiError(res, statusForError(parsed.error), parsed.error);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const result = await spec.handle(parsed.value, deps, abortController.signal);
|
|
61
|
+
// `abortController.signal` can only have been aborted by `onResponseClose` firing while the
|
|
62
|
+
// `await` above was pending — nothing here runs concurrently with it — so this unambiguously
|
|
63
|
+
// means the client was already gone before any response was sent. Writing one now would be
|
|
64
|
+
// wasted work at best and, worse, would route a benign disconnect into the SEC-005 catch
|
|
65
|
+
// below as a false internal error if the socket rejects the write.
|
|
66
|
+
if (abortController.signal.aborted)
|
|
67
|
+
return;
|
|
68
|
+
if (!result.ok) {
|
|
69
|
+
sendApiError(res, statusForError(result.error), result.error);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
sendJson(res, spec.successStatus ?? 200, result.value);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// SEC-005. This catch exists for exceptions no route anticipated, which makes it precisely
|
|
76
|
+
// the path most likely to be holding something private: a driver error naming a database
|
|
77
|
+
// file, a connection string, a credential a provider echoed back. Serializing `e.message`
|
|
78
|
+
// into the response handed all of that to the caller — and because `health.ts`'s probes are
|
|
79
|
+
// mounted ahead of the security middleware and exempted from the bearer gate, an unauthorized
|
|
80
|
+
// caller could read it too, simply by getting a readiness dependency to fail. The real error
|
|
81
|
+
// still reaches the operator through the sink, correlated to what the caller was told.
|
|
82
|
+
const correlationId = randomUUID();
|
|
83
|
+
const sink = adapter.onInternalError ?? defaultInternalErrorSink;
|
|
84
|
+
sink({ method: spec.method, path: spec.path, correlationId, error: e });
|
|
85
|
+
sendApiError(res, 500, createApiError('INTERNAL_ERROR', 'an internal error occurred', { requestId: correlationId }));
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
res.off?.('close', onResponseClose);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,eAAe,EAAsB,MAAM,aAAa,CAAC;AAyBlE,SAAS,wBAAwB,CAAC,OAAoC;IACpE,sCAAsC;IACtC,OAAO,CAAC,KAAK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